BattleInterface.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * BattleInterface.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "BattleConstants.h"
  12. #include "../gui/CIntObject.h"
  13. #include "../../lib/spells/CSpellHandler.h" //CSpell::TAnimation
  14. #include "../ConditionalWait.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. class CCreatureSet;
  17. class CGHeroInstance;
  18. class CStack;
  19. struct BattleResult;
  20. struct BattleSpellCast;
  21. struct CObstacleInstance;
  22. struct SetStackEffect;
  23. class BattleAction;
  24. class CGTownInstance;
  25. struct CatapultAttack;
  26. struct BattleTriggerEffect;
  27. struct BattleHex;
  28. struct InfoAboutHero;
  29. class ObstacleChanges;
  30. class CPlayerBattleCallback;
  31. VCMI_LIB_NAMESPACE_END
  32. class BattleHero;
  33. class Canvas;
  34. class BattleResultWindow;
  35. class StackQueue;
  36. class CPlayerInterface;
  37. struct BattleEffect;
  38. class IImage;
  39. class StackQueue;
  40. class BattleProjectileController;
  41. class BattleSiegeController;
  42. class BattleObstacleController;
  43. class BattleFieldController;
  44. class BattleRenderer;
  45. class BattleWindow;
  46. class BattleStacksController;
  47. class BattleActionsController;
  48. class BattleEffectsController;
  49. class BattleConsole;
  50. /// Small struct which contains information about the id of the attacked stack, the damage dealt,...
  51. struct StackAttackedInfo
  52. {
  53. const CStack *defender;
  54. const CStack *attacker;
  55. int64_t damageDealt;
  56. uint32_t amountKilled;
  57. SpellID spellEffect;
  58. bool indirectAttack; //if true, stack was attacked indirectly - spell or ranged attack
  59. bool killed; //if true, stack has been killed
  60. bool rebirth; //if true, play rebirth animation after all
  61. bool cloneKilled;
  62. bool fireShield;
  63. };
  64. struct StackAttackInfo
  65. {
  66. const CStack *attacker;
  67. const CStack *defender;
  68. std::vector< const CStack *> secondaryDefender;
  69. SpellID spellEffect;
  70. BattleHex tile;
  71. bool indirectAttack;
  72. bool lucky;
  73. bool unlucky;
  74. bool deathBlow;
  75. bool lifeDrain;
  76. };
  77. /// Main class for battles, responsible for relaying information from server to various battle entities
  78. class BattleInterface
  79. {
  80. using AwaitingAnimationAction = std::function<void()>;
  81. struct AwaitingAnimationEvents {
  82. AwaitingAnimationAction action;
  83. EAnimationEvents event;
  84. };
  85. /// Conditional variables that are set depending on ongoing animations on the battlefield
  86. ConditionalWait ongoingAnimationsState;
  87. /// List of events that are waiting to be triggered
  88. std::vector<AwaitingAnimationEvents> awaitingEvents;
  89. /// 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
  90. std::shared_ptr<CPlayerInterface> tacticianInterface;
  91. /// attacker interface, not null if attacker is human in our vcmiclient
  92. std::shared_ptr<CPlayerInterface> attackerInt;
  93. /// defender interface, not null if attacker is human in our vcmiclient
  94. std::shared_ptr<CPlayerInterface> defenderInt;
  95. /// if set to true, battle is still starting and waiting for intro sound to end / key press from player
  96. bool battleOpeningDelayActive;
  97. /// ID of ongoing battle
  98. BattleID battleID;
  99. void playIntroSoundAndUnlockInterface();
  100. void onIntroSoundPlayed();
  101. public:
  102. /// copy of initial armies (for result window)
  103. const CCreatureSet *army1;
  104. const CCreatureSet *army2;
  105. std::shared_ptr<BattleWindow> windowObject;
  106. std::shared_ptr<BattleConsole> console;
  107. /// currently active player interface
  108. std::shared_ptr<CPlayerInterface> curInt;
  109. const CGHeroInstance *attackingHeroInstance;
  110. const CGHeroInstance *defendingHeroInstance;
  111. bool tacticsMode;
  112. ui32 round;
  113. std::unique_ptr<BattleProjectileController> projectilesController;
  114. std::unique_ptr<BattleSiegeController> siegeController;
  115. std::unique_ptr<BattleObstacleController> obstacleController;
  116. std::unique_ptr<BattleFieldController> fieldController;
  117. std::unique_ptr<BattleStacksController> stacksController;
  118. std::unique_ptr<BattleActionsController> actionsController;
  119. std::unique_ptr<BattleEffectsController> effectsController;
  120. std::shared_ptr<BattleHero> attackingHero;
  121. std::shared_ptr<BattleHero> defendingHero;
  122. bool openingPlaying() const;
  123. void openingEnd();
  124. bool makingTurn() const;
  125. BattleID getBattleID() const;
  126. std::shared_ptr<CPlayerBattleCallback> getBattle() const;
  127. BattleInterface(const BattleID & battleID, 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);
  128. ~BattleInterface();
  129. void trySetActivePlayer( PlayerColor player ); // if in hotseat, will activate interface of chosen player
  130. void activateStack(); //sets activeStack to stackToActivate etc. //FIXME: No, it's not clear at all
  131. void requestAutofightingAIToTakeAction();
  132. void giveCommand(EActionType action, BattleHex tile = BattleHex(), SpellID spell = SpellID::NONE);
  133. void sendCommand(BattleAction command, const CStack * actor = nullptr);
  134. const CGHeroInstance *getActiveHero(); //returns hero that can currently cast a spell
  135. void showInterface(Canvas & to);
  136. void setHeroAnimation(BattleSide side, EHeroAnimType phase);
  137. void executeSpellCast(); //called when a hero casts a spell
  138. void appendBattleLog(const std::string & newEntry);
  139. void redrawBattlefield(); //refresh GUI after changing stack range / grid settings
  140. CPlayerInterface *getCurrentPlayerInterface() const;
  141. void tacticNextStack(const CStack *current);
  142. void tacticPhaseEnd();
  143. void setBattleQueueVisibility(bool visible);
  144. void setStickyHeroWindowsVisibility(bool visible);
  145. void setStickyQuickSpellWindowVisibility(bool visible);
  146. void endNetwork();
  147. void executeStagedAnimations();
  148. void executeAnimationStage( EAnimationEvents event);
  149. void onAnimationsStarted();
  150. void onAnimationsFinished();
  151. void waitForAnimations();
  152. bool hasAnimations();
  153. void checkForAnimations();
  154. void addToAnimationStage( EAnimationEvents event, const AwaitingAnimationAction & action);
  155. //call-ins
  156. void startAction(const BattleAction & action);
  157. void stackReset(const CStack * stack);
  158. void stackAdded(const CStack * stack); //new stack appeared on battlefield
  159. void stackRemoved(uint32_t stackID); //stack disappeared from batlefiled
  160. void stackActivated(const CStack *stack); //active stack has been changed
  161. void stackMoved(const CStack *stack, std::vector<BattleHex> destHex, int distance, bool teleport); //stack with id number moved to destHex
  162. void stacksAreAttacked(std::vector<StackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
  163. void stackAttacking(const StackAttackInfo & attackInfo); //called when stack with id ID is attacking something on hex dest
  164. void newRoundFirst();
  165. void newRound(); //called when round is ended;
  166. void stackIsCatapulting(const CatapultAttack & ca); //called when a stack is attacking walls
  167. void battleFinished(const BattleResult& br, QueryID queryID); //called when battle is finished - battleresult window should be printed
  168. void spellCast(const BattleSpellCast *sc); //called when a hero casts a spell
  169. void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks
  170. void castThisSpell(SpellID spellID); //called when player has chosen a spell from spellbook
  171. void displayBattleLog(const std::vector<MetaString> & battleLog);
  172. void displaySpellAnimationQueue(const CSpell * spell, const CSpell::TAnimationQueue & q, BattleHex destinationTile, bool isHit);
  173. void displaySpellCast(const CSpell * spell, BattleHex destinationTile); //displays spell`s cast animation
  174. void displaySpellEffect(const CSpell * spell, BattleHex destinationTile); //displays spell`s affected animation
  175. void displaySpellHit(const CSpell * spell, BattleHex destinationTile); //displays spell`s affected animation
  176. void endAction(const BattleAction & action);
  177. void obstaclePlaced(const std::vector<std::shared_ptr<const CObstacleInstance>> oi);
  178. void obstacleRemoved(const std::vector<ObstacleChanges> & obstacles);
  179. void gateStateChanged(const EGateState state);
  180. const CGHeroInstance *currentHero() const;
  181. InfoAboutHero enemyHero() const;
  182. };