Browse Source

Made BattleInterface class less friendly

Ivan Savenko 2 years ago
parent
commit
5a7eed01da
2 changed files with 40 additions and 70 deletions
  1. 2 8
      client/battle/BattleInterface.cpp
  2. 38 62
      client/battle/BattleInterface.h

+ 2 - 8
client/battle/BattleInterface.cpp

@@ -56,7 +56,6 @@ BattleInterface::BattleInterface(const CCreatureSet *army1, const CCreatureSet *
 	, curInt(att)
 	, myTurn(false)
 	, moveSoundHander(-1)
-	, bresult(nullptr)
 {
 	for ( auto & event : animationEvents)
 		event.setn(false);
@@ -306,15 +305,10 @@ void BattleInterface::gateStateChanged(const EGateState state)
 
 void BattleInterface::battleFinished(const BattleResult& br)
 {
-	bresult = &br;
 	assert(getAnimationCondition(EAnimationEvents::ACTION) == false);
 	waitForAnimationCondition(EAnimationEvents::ACTION, false);
 	stacksController->setActiveStack(nullptr);
-	displayBattleFinished();
-}
 
-void BattleInterface::displayBattleFinished()
-{
 	CCS->curh->set(Cursor::Map::POINTER);
 	if(settings["session"]["spectate"].Bool() && settings["session"]["spectate-skip-battle-result"].Bool())
 	{
@@ -322,7 +316,7 @@ void BattleInterface::displayBattleFinished()
 		return;
 	}
 
-	GH.pushInt(std::make_shared<BattleResultWindow>(*bresult, *(this->curInt)));
+	GH.pushInt(std::make_shared<BattleResultWindow>(br, *(this->curInt)));
 	curInt->waitWhileDialog(); // Avoid freeze when AI end turn after battle. Check bug #1897
 	CPlayerInterface::battleInt = nullptr;
 }
@@ -345,7 +339,7 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
 	{
 		auto group = spell->animationInfo.projectile.empty() ?
 					EAnimationEvents::HIT:
-					EAnimationEvents::BEFORE_HIT;//FIXME: should be on projectile spawning
+					EAnimationEvents::BEFORE_HIT;//FIXME: recheck whether this should be on projectile spawning
 
 		executeOnAnimationCondition(group, true, [=]() {
 			CCS->soundh->playSound(castSoundPath);

+ 38 - 62
client/battle/BattleInterface.h

@@ -90,27 +90,6 @@ struct StackAttackInfo
 /// Main class for battles, responsible for relaying information from server to various battle entities
 class BattleInterface
 {
-private:
-	std::shared_ptr<BattleWindow> windowObject;
-	std::shared_ptr<BattleConsole> console;
-
-	std::shared_ptr<CPlayerInterface> tacticianInterface; //used during tactics mode, points to the interface of player with higher tactics (can be either attacker or defender in hot-seat), valid onloy for human players
-
-	std::shared_ptr<CPlayerInterface> attackerInt; // attacker interface, not null if attacker is human in our vcmiclient
-	std::shared_ptr<CPlayerInterface> defenderInt; // defender interface, not null if attacker is human in our vcmiclient
-
-	std::shared_ptr<CPlayerInterface> curInt; //current player interface
-
-	 //copy of initial armies (for result window)
-	const CCreatureSet *army1;
-	const CCreatureSet *army2;
-
-	const CGHeroInstance *attackingHeroInstance;
-	const CGHeroInstance *defendingHeroInstance;
-
-	bool tacticsMode;
-	int battleIntroSoundChannel; //required as variable for disabling it via ESC key
-
 	using AwaitingAnimationAction = std::function<void()>;
 
 	struct AwaitingAnimationEvents {
@@ -125,24 +104,34 @@ private:
 	/// List of events that are waiting to be triggered
 	std::vector<AwaitingAnimationEvents> awaitingEvents;
 
-	void trySetActivePlayer( PlayerColor player ); // if in hotseat, will activate interface of chosen player
-	void activateStack(); //sets activeStack to stackToActivate etc. //FIXME: No, it's not clear at all
-	void requestAutofightingAIToTakeAction();
+	/// used during tactics mode, points to the interface of player with higher tactics (can be either attacker or defender in hot-seat), valid onloy for human players
+	std::shared_ptr<CPlayerInterface> tacticianInterface;
 
-	void giveCommand(EActionType action, BattleHex tile = BattleHex(), si32 additional = -1);
-	void sendCommand(BattleAction *& command, const CStack * actor = nullptr);
+	/// attacker interface, not null if attacker is human in our vcmiclient
+	std::shared_ptr<CPlayerInterface> attackerInt;
 
-	const CGHeroInstance *getActiveHero(); //returns hero that can currently cast a spell
+	/// defender interface, not null if attacker is human in our vcmiclient
+	std::shared_ptr<CPlayerInterface> defenderInt;
 
-	void showInterface(SDL_Surface * to);
+public:
+	/// copy of initial armies (for result window)
+	const CCreatureSet *army1;
+	const CCreatureSet *army2;
 
-	void setHeroAnimation(ui8 side, EHeroAnimType phase);
+	/// ID of channel on which battle opening sound is playing, or -1 if none
+	int battleIntroSoundChannel;
 
-	void executeSpellCast(); //called when a hero casts a spell
+	std::shared_ptr<BattleWindow> windowObject;
+	std::shared_ptr<BattleConsole> console;
 
-	void appendBattleLog(const std::string & newEntry);
+	/// currently active player interface
+	std::shared_ptr<CPlayerInterface> curInt;
+
+	const CGHeroInstance *attackingHeroInstance;
+	const CGHeroInstance *defendingHeroInstance;
+
+	bool tacticsMode;
 
-public:
 	std::unique_ptr<BattleProjectileController> projectilesController;
 	std::unique_ptr<BattleSiegeController> siegeController;
 	std::unique_ptr<BattleObstacleController> obstacleController;
@@ -159,11 +148,26 @@ public:
 	bool myTurn; //if true, interface is active (commands can be ordered)
 	int moveSoundHander; // sound handler used when moving a unit
 
-	const BattleResult *bresult; //result of a battle; if non-zero then display when all animations end
-
 	BattleInterface(const CCreatureSet *army1, const CCreatureSet *army2, const CGHeroInstance *hero1, const CGHeroInstance *hero2, std::shared_ptr<CPlayerInterface> att, std::shared_ptr<CPlayerInterface> defen, std::shared_ptr<CPlayerInterface> spectatorInt = nullptr);
 	~BattleInterface();
 
+	void trySetActivePlayer( PlayerColor player ); // if in hotseat, will activate interface of chosen player
+	void activateStack(); //sets activeStack to stackToActivate etc. //FIXME: No, it's not clear at all
+	void requestAutofightingAIToTakeAction();
+
+	void giveCommand(EActionType action, BattleHex tile = BattleHex(), si32 additional = -1);
+	void sendCommand(BattleAction *& command, const CStack * actor = nullptr);
+
+	const CGHeroInstance *getActiveHero(); //returns hero that can currently cast a spell
+
+	void showInterface(SDL_Surface * to);
+
+	void setHeroAnimation(ui8 side, EHeroAnimType phase);
+
+	void executeSpellCast(); //called when a hero casts a spell
+
+	void appendBattleLog(const std::string & newEntry);
+
 	void setPrintCellBorders(bool set); //if true, cell borders will be printed
 	void setPrintStackRange(bool set); //if true,range of active stack will be printed
 	void setPrintMouseShadow(bool set); //if true, hex under mouse will be shaded
@@ -199,7 +203,6 @@ public:
 	void newRound(int number); //caled when round is ended; number is the number of round
 	void stackIsCatapulting(const CatapultAttack & ca); //called when a stack is attacking walls
 	void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed
-	void displayBattleFinished(); //displays battle result
 	void spellCast(const BattleSpellCast *sc); //called when a hero casts a spell
 	void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks
 	void castThisSpell(SpellID spellID); //called when player has chosen a spell from spellbook
@@ -219,31 +222,4 @@ public:
 
 	const CGHeroInstance *currentHero() const;
 	InfoAboutHero enemyHero() const;
-
-	// TODO: cleanup this list
-	friend class CPlayerInterface;
-	friend class CInGameConsole;
-	friend class StackQueue;
-	friend class BattleResultWindow;
-	friend class BattleHero;
-	friend class CBattleStackAnimation;
-	friend class CReverseAnimation;
-	friend class CDefenceAnimation;
-	friend class CMovementAnimation;
-	friend class CMovementStartAnimation;
-	friend class CAttackAnimation;
-	friend class CMeleeAttackAnimation;
-	friend class CShootingAnimation;
-	friend class CCastAnimation;
-	friend class ClickableHex;
-	friend class BattleProjectileController;
-	friend class BattleSiegeController;
-	friend class BattleObstacleController;
-	friend class BattleFieldController;
-	friend class BattleWindow;
-	friend class BattleStacksController;
-	friend class BattleActionsController;
-	friend class BattleEffectsController;
-	friend class BattleRenderer;
-	friend class CInGameConsole;
 };