mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	vcmi: move ServerSpellCastEnvironment in separate file
In theory, it should not know about CGameHandler
This commit is contained in:
		| @@ -42,6 +42,7 @@ | ||||
| #include "../lib/CSoundBase.h" | ||||
| #include "../lib/TerrainHandler.h" | ||||
| #include "CGameHandler.h" | ||||
| #include "ServerSpellCastEnvironment.h" | ||||
| #include "CVCMIServer.h" | ||||
| #include "../lib/CCreatureSet.h" | ||||
| #include "../lib/CThreadHelper.h" | ||||
| @@ -67,36 +68,6 @@ | ||||
| #define COMPLAIN_RET(txt) {complain(txt); return false;} | ||||
| #define COMPLAIN_RETF(txt, FORMAT) {complain(boost::str(boost::format(txt) % FORMAT)); return false;} | ||||
|  | ||||
| class ServerSpellCastEnvironment : public SpellCastEnvironment | ||||
| { | ||||
| public: | ||||
| 	ServerSpellCastEnvironment(CGameHandler * gh); | ||||
| 	~ServerSpellCastEnvironment() = default; | ||||
|  | ||||
| 	void complain(const std::string & problem) override; | ||||
| 	bool describeChanges() const override; | ||||
|  | ||||
| 	vstd::RNG * getRNG() override; | ||||
|  | ||||
| 	void apply(CPackForClient * pack) override; | ||||
|  | ||||
| 	void apply(BattleLogMessage * pack) override; | ||||
| 	void apply(BattleStackMoved * pack) override; | ||||
| 	void apply(BattleUnitsChanged * pack) override; | ||||
| 	void apply(SetStackEffect * pack) override; | ||||
| 	void apply(StacksInjured * pack) override; | ||||
| 	void apply(BattleObstaclesChanged * pack) override; | ||||
| 	void apply(CatapultAttack * pack) override; | ||||
|  | ||||
| 	const CMap * getMap() const override; | ||||
| 	const CGameInfoCallback * getCb() const override; | ||||
| 	bool moveHero(ObjectInstanceID hid, int3 dst, bool teleporting) override; | ||||
| 	void genericQuery(Query * request, PlayerColor color, std::function<void(const JsonNode &)> callback) override; | ||||
| private: | ||||
| 	CGameHandler * gh; | ||||
| }; | ||||
|  | ||||
|  | ||||
| CondSh<bool> battleMadeAction(false); | ||||
| CondSh<BattleResult *> battleResult(nullptr); | ||||
| template <typename T> class CApplyOnGH; | ||||
| @@ -7375,89 +7346,4 @@ const ObjectInstanceID CGameHandler::putNewObject(Obj ID, int subID, int3 pos) | ||||
| 	no.pos = pos; | ||||
| 	sendAndApply(&no); | ||||
| 	return no.id; //id field will be filled during applying on gs | ||||
| } | ||||
|  | ||||
| ///ServerSpellCastEnvironment | ||||
| ServerSpellCastEnvironment::ServerSpellCastEnvironment(CGameHandler * gh) | ||||
| 	: gh(gh) | ||||
| { | ||||
|  | ||||
| } | ||||
|  | ||||
| bool ServerSpellCastEnvironment::describeChanges() const | ||||
| { | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::complain(const std::string & problem) | ||||
| { | ||||
| 	gh->complain(problem); | ||||
| } | ||||
|  | ||||
| vstd::RNG * ServerSpellCastEnvironment::getRNG() | ||||
| { | ||||
| 	return &gh->getRandomGenerator(); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(CPackForClient * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(BattleLogMessage * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(BattleStackMoved * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(BattleUnitsChanged * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(SetStackEffect * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(StacksInjured * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(BattleObstaclesChanged * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(CatapultAttack * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| const CGameInfoCallback * ServerSpellCastEnvironment::getCb() const | ||||
| { | ||||
| 	return gh; | ||||
| } | ||||
|  | ||||
| const CMap * ServerSpellCastEnvironment::getMap() const | ||||
| { | ||||
| 	return gh->gameState()->map; | ||||
| } | ||||
|  | ||||
| bool ServerSpellCastEnvironment::moveHero(ObjectInstanceID hid, int3 dst, bool teleporting) | ||||
| { | ||||
| 	return gh->moveHero(hid, dst, teleporting, false); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::genericQuery(Query * request, PlayerColor color, std::function<void(const JsonNode&)> callback) | ||||
| { | ||||
| 	auto query = std::make_shared<CGenericQuery>(&gh->queries, color, callback); | ||||
| 	request->queryID = query->queryID; | ||||
| 	gh->queries.addQuery(query); | ||||
| 	gh->sendAndApply(request); | ||||
| } | ||||
| } | ||||
| @@ -2,6 +2,7 @@ set(server_SRCS | ||||
| 		StdInc.cpp | ||||
|  | ||||
| 		CGameHandler.cpp | ||||
| 		ServerSpellCastEnvironment.cpp | ||||
| 		CQuery.cpp | ||||
| 		CVCMIServer.cpp | ||||
| 		NetPacksServer.cpp | ||||
| @@ -12,6 +13,7 @@ set(server_HEADERS | ||||
| 		StdInc.h | ||||
|  | ||||
| 		CGameHandler.h | ||||
| 		ServerSpellCastEnvironment.h | ||||
| 		CQuery.h | ||||
| 		CVCMIServer.h | ||||
| 		LobbyNetPackVisitors.h | ||||
|   | ||||
							
								
								
									
										97
									
								
								server/ServerSpellCastEnvironment.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								server/ServerSpellCastEnvironment.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,97 @@ | ||||
| /* | ||||
|  * ServerSpellCastEnvironment.cpp, part of VCMI engine | ||||
|  * | ||||
|  * Authors: listed in file AUTHORS in main folder | ||||
|  * | ||||
|  * License: GNU General Public License v2.0 or later | ||||
|  * Full text of license available in license.txt file, in main folder | ||||
|  * | ||||
|  */ | ||||
| #include "StdInc.h" | ||||
| #include "../lib/CGameState.h" | ||||
| #include "CGameHandler.h" | ||||
| #include "ServerSpellCastEnvironment.h" | ||||
|  | ||||
| ///ServerSpellCastEnvironment | ||||
| ServerSpellCastEnvironment::ServerSpellCastEnvironment(CGameHandler * gh) | ||||
| 	: gh(gh) | ||||
| { | ||||
| } | ||||
|  | ||||
| bool ServerSpellCastEnvironment::describeChanges() const | ||||
| { | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::complain(const std::string & problem) | ||||
| { | ||||
| 	gh->complain(problem); | ||||
| } | ||||
|  | ||||
| vstd::RNG * ServerSpellCastEnvironment::getRNG() | ||||
| { | ||||
| 	return &gh->getRandomGenerator(); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(CPackForClient * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(BattleLogMessage * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(BattleStackMoved * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(BattleUnitsChanged * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(SetStackEffect * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(StacksInjured * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(BattleObstaclesChanged * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::apply(CatapultAttack * pack) | ||||
| { | ||||
| 	gh->sendAndApply(pack); | ||||
| } | ||||
|  | ||||
| const CGameInfoCallback * ServerSpellCastEnvironment::getCb() const | ||||
| { | ||||
| 	return gh; | ||||
| } | ||||
|  | ||||
| const CMap * ServerSpellCastEnvironment::getMap() const | ||||
| { | ||||
| 	return gh->gameState()->map; | ||||
| } | ||||
|  | ||||
| bool ServerSpellCastEnvironment::moveHero(ObjectInstanceID hid, int3 dst, bool teleporting) | ||||
| { | ||||
| 	return gh->moveHero(hid, dst, teleporting, false); | ||||
| } | ||||
|  | ||||
| void ServerSpellCastEnvironment::genericQuery(Query * request, PlayerColor color, std::function<void(const JsonNode&)> callback) | ||||
| { | ||||
| 	auto query = std::make_shared<CGenericQuery>(&gh->queries, color, callback); | ||||
| 	request->queryID = query->queryID; | ||||
| 	gh->queries.addQuery(query); | ||||
| 	gh->sendAndApply(request); | ||||
| } | ||||
							
								
								
									
										42
									
								
								server/ServerSpellCastEnvironment.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								server/ServerSpellCastEnvironment.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| /* | ||||
|  * ServerSpellCastEnvironment.h, part of VCMI engine | ||||
|  * | ||||
|  * Authors: listed in file AUTHORS in main folder | ||||
|  * | ||||
|  * License: GNU General Public License v2.0 or later | ||||
|  * Full text of license available in license.txt file, in main folder | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "../lib/spells/ISpellMechanics.h" | ||||
|  | ||||
| class CGameHandler; | ||||
|  | ||||
| class ServerSpellCastEnvironment : public SpellCastEnvironment | ||||
| { | ||||
| public: | ||||
| 	ServerSpellCastEnvironment(CGameHandler * gh); | ||||
| 	~ServerSpellCastEnvironment() = default; | ||||
|  | ||||
| 	void complain(const std::string & problem) override; | ||||
| 	bool describeChanges() const override; | ||||
|  | ||||
| 	vstd::RNG * getRNG() override; | ||||
|  | ||||
| 	void apply(CPackForClient * pack) override; | ||||
|  | ||||
| 	void apply(BattleLogMessage * pack) override; | ||||
| 	void apply(BattleStackMoved * pack) override; | ||||
| 	void apply(BattleUnitsChanged * pack) override; | ||||
| 	void apply(SetStackEffect * pack) override; | ||||
| 	void apply(StacksInjured * pack) override; | ||||
| 	void apply(BattleObstaclesChanged * pack) override; | ||||
| 	void apply(CatapultAttack * pack) override; | ||||
|  | ||||
| 	const CMap * getMap() const override; | ||||
| 	const CGameInfoCallback * getCb() const override; | ||||
| 	bool moveHero(ObjectInstanceID hid, int3 dst, bool teleporting) override; | ||||
| 	void genericQuery(Query * request, PlayerColor color, std::function<void(const JsonNode &)> callback) override; | ||||
| private: | ||||
| 	CGameHandler * gh; | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user