浏览代码

Simplify code

Ivan Savenko 1 年之前
父节点
当前提交
a99d5e6fa1

+ 2 - 7
server/battles/BattleActionProcessor.cpp

@@ -29,17 +29,12 @@
 #include "../../lib/spells/ISpellMechanics.h"
 #include "../../lib/spells/Problem.h"
 
-BattleActionProcessor::BattleActionProcessor(BattleProcessor * owner)
+BattleActionProcessor::BattleActionProcessor(BattleProcessor * owner, CGameHandler * newGameHandler)
 	: owner(owner)
-	, gameHandler(nullptr)
+	, gameHandler(newGameHandler)
 {
 }
 
-void BattleActionProcessor::setGameHandler(CGameHandler * newGameHandler)
-{
-	gameHandler = newGameHandler;
-}
-
 bool BattleActionProcessor::doEmptyAction(const CBattleInfoCallback & battle, const BattleAction & ba)
 {
 	return true;

+ 1 - 2
server/battles/BattleActionProcessor.h

@@ -78,8 +78,7 @@ class BattleActionProcessor : boost::noncopyable
 	bool makeBattleActionImpl(const CBattleInfoCallback & battle, const BattleAction & ba);
 
 public:
-	explicit BattleActionProcessor(BattleProcessor * owner);
-	void setGameHandler(CGameHandler * newGameHandler);
+	explicit BattleActionProcessor(BattleProcessor * owner, CGameHandler * newGameHandler);
 
 	bool makeAutomaticBattleAction(const CBattleInfoCallback & battle, const BattleAction & ba);
 	bool makePlayerBattleAction(const CBattleInfoCallback & battle, PlayerColor player, const BattleAction & ba);

+ 2 - 7
server/battles/BattleFlowProcessor.cpp

@@ -25,17 +25,12 @@
 #include "../../lib/spells/ISpellMechanics.h"
 #include "../../lib/spells/ObstacleCasterProxy.h"
 
-BattleFlowProcessor::BattleFlowProcessor(BattleProcessor * owner)
+BattleFlowProcessor::BattleFlowProcessor(BattleProcessor * owner, CGameHandler * newGameHandler)
 	: owner(owner)
-	, gameHandler(nullptr)
+	, gameHandler(newGameHandler)
 {
 }
 
-void BattleFlowProcessor::setGameHandler(CGameHandler * newGameHandler)
-{
-	gameHandler = newGameHandler;
-}
-
 void BattleFlowProcessor::summonGuardiansHelper(const CBattleInfoCallback & battle, std::vector<BattleHex> & output, const BattleHex & targetPosition, ui8 side, bool targetIsTwoHex) //return hexes for summoning two hex monsters in output, target = unit to guard
 {
 	int x = targetPosition.getX();

+ 1 - 2
server/battles/BattleFlowProcessor.h

@@ -51,8 +51,7 @@ class BattleFlowProcessor : boost::noncopyable
 	bool makeAutomaticAction(const CBattleInfoCallback & battle, const CStack * stack, BattleAction & ba); //used when action is taken by stack without volition of player (eg. unguided catapult attack)
 
 public:
-	explicit BattleFlowProcessor(BattleProcessor * owner);
-	void setGameHandler(CGameHandler * newGameHandler);
+	explicit BattleFlowProcessor(BattleProcessor * owner, CGameHandler * newGameHandler);
 
 	void onBattleStarted(const CBattleInfoCallback & battle);
 	void onTacticsEnded(const CBattleInfoCallback & battle);

+ 3 - 18
server/battles/BattleProcessor.cpp

@@ -33,15 +33,9 @@
 
 BattleProcessor::BattleProcessor(CGameHandler * gameHandler)
 	: gameHandler(gameHandler)
-	, flowProcessor(std::make_unique<BattleFlowProcessor>(this))
-	, actionsProcessor(std::make_unique<BattleActionProcessor>(this))
-	, resultProcessor(std::make_unique<BattleResultProcessor>(this))
-{
-	setGameHandler(gameHandler);
-}
-
-BattleProcessor::BattleProcessor():
-	BattleProcessor(nullptr)
+	, flowProcessor(std::make_unique<BattleFlowProcessor>(this, gameHandler))
+	, actionsProcessor(std::make_unique<BattleActionProcessor>(this, gameHandler))
+	, resultProcessor(std::make_unique<BattleResultProcessor>(this, gameHandler))
 {
 }
 
@@ -316,12 +310,3 @@ void BattleProcessor::battleAfterLevelUp(const BattleID & battleID, const Battle
 {
 	resultProcessor->battleAfterLevelUp(battleID, result);
 }
-
-void BattleProcessor::setGameHandler(CGameHandler * newGameHandler)
-{
-	gameHandler = newGameHandler;
-
-	actionsProcessor->setGameHandler(newGameHandler);
-	flowProcessor->setGameHandler(newGameHandler);
-	resultProcessor->setGameHandler(newGameHandler);
-}

+ 0 - 4
server/battles/BattleProcessor.h

@@ -52,11 +52,8 @@ class BattleProcessor : boost::noncopyable
 
 public:
 	explicit BattleProcessor(CGameHandler * gameHandler);
-	BattleProcessor();
 	~BattleProcessor();
 
-	void setGameHandler(CGameHandler * gameHandler);
-
 	/// Starts battle with specified parameters
 	void startBattlePrimary(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, const CGTownInstance *town = nullptr);
 	/// Starts battle between two armies (which can also be heroes) at specified tile
@@ -78,6 +75,5 @@ public:
 	{
 
 	}
-
 };
 

+ 2 - 7
server/battles/BattleResultProcessor.cpp

@@ -29,17 +29,12 @@
 #include "../../lib/serializer/Cast.h"
 #include "../../lib/spells/CSpellHandler.h"
 
-BattleResultProcessor::BattleResultProcessor(BattleProcessor * owner)
+BattleResultProcessor::BattleResultProcessor(BattleProcessor * owner, CGameHandler * newGameHandler)
 //	: owner(owner)
-	: gameHandler(nullptr)
+	: gameHandler(newGameHandler)
 {
 }
 
-void BattleResultProcessor::setGameHandler(CGameHandler * newGameHandler)
-{
-	gameHandler = newGameHandler;
-}
-
 CasualtiesAfterBattle::CasualtiesAfterBattle(const CBattleInfoCallback & battle, uint8_t sideInBattle):
 	army(battle.battleGetArmyObject(sideInBattle))
 {

+ 1 - 2
server/battles/BattleResultProcessor.h

@@ -70,8 +70,7 @@ class BattleResultProcessor : boost::noncopyable
 	std::map<BattleID, std::unique_ptr<FinishingBattleHelper>> finishingBattles;
 
 public:
-	explicit BattleResultProcessor(BattleProcessor * owner);
-	void setGameHandler(CGameHandler * newGameHandler);
+	explicit BattleResultProcessor(BattleProcessor * owner, CGameHandler * newGameHandler);
 
 	bool battleIsEnding(const CBattleInfoCallback & battle) const;
 

+ 0 - 5
server/processors/HeroPoolProcessor.cpp

@@ -25,11 +25,6 @@
 #include "../../lib/gameState/TavernSlot.h"
 #include "../../lib/GameSettings.h"
 
-HeroPoolProcessor::HeroPoolProcessor()
-	: gameHandler(nullptr)
-{
-}
-
 HeroPoolProcessor::HeroPoolProcessor(CGameHandler * gameHandler)
 	: gameHandler(gameHandler)
 {

+ 2 - 4
server/processors/HeroPoolProcessor.h

@@ -28,6 +28,8 @@ class CGameHandler;
 
 class HeroPoolProcessor : boost::noncopyable
 {
+	CGameHandler * gameHandler;
+
 	/// per-player random generators
 	std::map<PlayerColor, std::unique_ptr<CRandomGenerator>> playerSeed;
 
@@ -49,9 +51,6 @@ class HeroPoolProcessor : boost::noncopyable
 	TavernHeroSlot selectSlotForRole(const PlayerColor & player, TavernSlotRole roleID);
 
 public:
-	CGameHandler * gameHandler;
-
-	HeroPoolProcessor();
 	HeroPoolProcessor(CGameHandler * gameHandler);
 
 	void onHeroSurrendered(const PlayerColor & color, const CGHeroInstance * hero);
@@ -66,7 +65,6 @@ public:
 
 	template <typename Handler> void serialize(Handler &h)
 	{
-		// h & gameHandler; // FIXME: make this work instead of using deserializationFix in gameHandler
 		h & playerSeed;
 		h & heroSeed;
 	}

+ 0 - 5
server/processors/PlayerMessageProcessor.cpp

@@ -29,11 +29,6 @@
 #include "../../lib/networkPacks/StackLocation.h"
 #include "../../lib/serializer/Connection.h"
 
-PlayerMessageProcessor::PlayerMessageProcessor()
-	:gameHandler(nullptr)
-{
-}
-
 PlayerMessageProcessor::PlayerMessageProcessor(CGameHandler * gameHandler)
 	:gameHandler(gameHandler)
 {

+ 2 - 3
server/processors/PlayerMessageProcessor.h

@@ -21,6 +21,8 @@ class CGameHandler;
 
 class PlayerMessageProcessor
 {
+	CGameHandler * gameHandler;
+
 	void executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & arguments );
 	bool handleCheatCode(const std::string & cheatFullCommand, PlayerColor player, ObjectInstanceID currObj);
 	bool handleHostCommand(PlayerColor player, const std::string & message);
@@ -43,9 +45,6 @@ class PlayerMessageProcessor
 	void cheatFly(PlayerColor player, const CGHeroInstance * hero);
 
 public:
-	CGameHandler * gameHandler;
-
-	PlayerMessageProcessor();
 	PlayerMessageProcessor(CGameHandler * gameHandler);
 
 	/// incoming NetPack handling