CBattleInterface.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * CBattleInterface.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 "../gui/CIntObject.h"
  12. #include "../../lib/spells/CSpellHandler.h" //CSpell::TAnimation
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CCreatureSet;
  15. class CGHeroInstance;
  16. class CStack;
  17. struct BattleResult;
  18. struct BattleSpellCast;
  19. struct CObstacleInstance;
  20. template <typename T> struct CondSh;
  21. struct SetStackEffect;
  22. class BattleAction;
  23. class CGTownInstance;
  24. struct CatapultAttack;
  25. struct BattleTriggerEffect;
  26. struct BattleHex;
  27. struct InfoAboutHero;
  28. //class CBattleGameInterface;
  29. struct CustomEffectInfo;
  30. //class CSpell;
  31. VCMI_LIB_NAMESPACE_END
  32. class CBattleHero;
  33. class CCanvas;
  34. class CBattleResultWindow;
  35. class CStackQueue;
  36. class CPlayerInterface;
  37. class CClickableHex;
  38. class CAnimation;
  39. struct BattleEffect;
  40. class CBattleProjectileController;
  41. class CBattleSiegeController;
  42. class CBattleObstacleController;
  43. class CBattleFieldController;
  44. class CBattleControlPanel;
  45. class CBattleStacksController;
  46. class CBattleActionsController;
  47. class CBattleEffectsController;
  48. /// Small struct which contains information about the id of the attacked stack, the damage dealt,...
  49. struct StackAttackedInfo
  50. {
  51. const CStack *defender; //attacked stack
  52. int64_t dmg; //damage dealt
  53. unsigned int amountKilled; //how many creatures in stack has been killed
  54. const CStack *attacker; //attacking stack
  55. bool indirectAttack; //if true, stack was attacked indirectly - spell or ranged attack
  56. bool killed; //if true, stack has been killed
  57. bool rebirth; //if true, play rebirth animation after all
  58. bool cloneKilled;
  59. };
  60. /// Big class which handles the overall battle interface actions and it is also responsible for
  61. /// drawing everything correctly.
  62. class CBattleInterface : public WindowBase
  63. {
  64. private:
  65. std::shared_ptr<CBattleHero> attackingHero;
  66. std::shared_ptr<CBattleHero> defendingHero;
  67. std::shared_ptr<CStackQueue> queue;
  68. std::shared_ptr<CBattleControlPanel> controlPanel;
  69. 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
  70. std::shared_ptr<CPlayerInterface> attackerInt, defenderInt; //because LOCPLINT is not enough in hotSeat
  71. std::shared_ptr<CPlayerInterface> curInt; //current player interface
  72. const CCreatureSet *army1, *army2; //copy of initial armies (for result window)
  73. const CGHeroInstance *attackingHeroInstance, *defendingHeroInstance;
  74. ui8 animCount;
  75. bool tacticsMode;
  76. bool battleActionsStarted; //used for delaying battle actions until intro sound stops
  77. int battleIntroSoundChannel; //required as variable for disabling it via ESC key
  78. void trySetActivePlayer( PlayerColor player ); // if in hotseat, will activate interface of chosen player
  79. void activateStack(); //sets activeStack to stackToActivate etc. //FIXME: No, it's not clear at all
  80. void requestAutofightingAIToTakeAction();
  81. void giveCommand(EActionType action, BattleHex tile = BattleHex(), si32 additional = -1);
  82. void sendCommand(BattleAction *& command, const CStack * actor = nullptr);
  83. const CGHeroInstance *getActiveHero(); //returns hero that can currently cast a spell
  84. void showInterface(std::shared_ptr<CCanvas> canvas);
  85. void showBattlefieldObjects(std::shared_ptr<CCanvas> canvas);
  86. void showBattlefieldObjects(std::shared_ptr<CCanvas> canvas, const BattleHex & location );
  87. void setHeroAnimation(ui8 side, int phase);
  88. public:
  89. std::unique_ptr<CBattleProjectileController> projectilesController;
  90. std::unique_ptr<CBattleSiegeController> siegeController;
  91. std::unique_ptr<CBattleObstacleController> obstacleController;
  92. std::unique_ptr<CBattleFieldController> fieldController;
  93. std::unique_ptr<CBattleStacksController> stacksController;
  94. std::unique_ptr<CBattleActionsController> actionsController;
  95. std::unique_ptr<CBattleEffectsController> effectsController;
  96. static CondSh<bool> animsAreDisplayed; //for waiting with the end of battle for end of anims
  97. static CondSh<BattleAction *> givenCommand; //data != nullptr if we have i.e. moved current unit
  98. bool myTurn; //if true, interface is active (commands can be ordered)
  99. bool moveStarted; //if true, the creature that is already moving is going to make its first step
  100. int moveSoundHander; // sound handler used when moving a unit
  101. const BattleResult *bresult; //result of a battle; if non-zero then display when all animations end
  102. CBattleInterface(const CCreatureSet *army1, const CCreatureSet *army2, const CGHeroInstance *hero1, const CGHeroInstance *hero2, const SDL_Rect & myRect, std::shared_ptr<CPlayerInterface> att, std::shared_ptr<CPlayerInterface> defen, std::shared_ptr<CPlayerInterface> spectatorInt = nullptr);
  103. virtual ~CBattleInterface();
  104. void setPrintCellBorders(bool set); //if true, cell borders will be printed
  105. void setPrintStackRange(bool set); //if true,range of active stack will be printed
  106. void setPrintMouseShadow(bool set); //if true, hex under mouse will be shaded
  107. void setAnimSpeed(int set); //speed of animation; range 1..100
  108. int getAnimSpeed() const; //speed of animation; range 1..100
  109. CPlayerInterface *getCurrentPlayerInterface() const;
  110. void tacticNextStack(const CStack *current);
  111. void tacticPhaseEnd();
  112. void waitForAnims();
  113. //napisz tu klase odpowiadajaca za wyswietlanie bitwy i obsluge uzytkownika, polecenia ma przekazywac callbackiem
  114. void activate() override;
  115. void deactivate() override;
  116. void keyPressed(const SDL_KeyboardEvent & key) override;
  117. void mouseMoved(const SDL_MouseMotionEvent &sEvent) override;
  118. void clickRight(tribool down, bool previousState) override;
  119. void show(SDL_Surface *to) override;
  120. void showAll(SDL_Surface *to) override;
  121. //call-ins
  122. void startAction(const BattleAction* action);
  123. void stackReset(const CStack * stack);
  124. void stackAdded(const CStack * stack); //new stack appeared on battlefield
  125. void stackRemoved(uint32_t stackID); //stack disappeared from batlefiled
  126. void stackActivated(const CStack *stack); //active stack has been changed
  127. void stackMoved(const CStack *stack, std::vector<BattleHex> destHex, int distance); //stack with id number moved to destHex
  128. void stacksAreAttacked(std::vector<StackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
  129. void stackAttacking(const CStack *attacker, BattleHex dest, const CStack *attacked, bool shooting); //called when stack with id ID is attacking something on hex dest
  130. void newRoundFirst( int round );
  131. void newRound(int number); //caled when round is ended; number is the number of round
  132. void hexLclicked(int whichOne); //hex only call-in
  133. void stackIsCatapulting(const CatapultAttack & ca); //called when a stack is attacking walls
  134. void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed
  135. void displayBattleFinished(); //displays battle result
  136. void spellCast(const BattleSpellCast *sc); //called when a hero casts a spell
  137. void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks
  138. void castThisSpell(SpellID spellID); //called when player has chosen a spell from spellbook
  139. void displayBattleLog(const std::vector<MetaString> & battleLog);
  140. void displaySpellAnimationQueue(const CSpell::TAnimationQueue & q, BattleHex destinationTile);
  141. void displaySpellCast(SpellID spellID, BattleHex destinationTile); //displays spell`s cast animation
  142. void displaySpellEffect(SpellID spellID, BattleHex destinationTile); //displays spell`s affected animation
  143. void displaySpellHit(SpellID spellID, BattleHex destinationTile); //displays spell`s affected animation
  144. void endAction(const BattleAction* action);
  145. void hideQueue();
  146. void showQueue();
  147. void obstaclePlaced(const CObstacleInstance & oi);
  148. void gateStateChanged(const EGateState state);
  149. const CGHeroInstance *currentHero() const;
  150. InfoAboutHero enemyHero() const;
  151. friend class CPlayerInterface;
  152. friend class CInGameConsole;
  153. friend class CBattleResultWindow;
  154. friend class CBattleHero;
  155. friend class CEffectAnimation;
  156. friend class CBattleStackAnimation;
  157. friend class CReverseAnimation;
  158. friend class CDefenceAnimation;
  159. friend class CMovementAnimation;
  160. friend class CMovementStartAnimation;
  161. friend class CAttackAnimation;
  162. friend class CMeleeAttackAnimation;
  163. friend class CShootingAnimation;
  164. friend class CCastAnimation;
  165. friend class CClickableHex;
  166. friend class CBattleProjectileController;
  167. friend class CBattleSiegeController;
  168. friend class CBattleObstacleController;
  169. friend class CBattleFieldController;
  170. friend class CBattleControlPanel;
  171. friend class CBattleStacksController;
  172. friend class CBattleActionsController;
  173. friend class CBattleEffectsController;
  174. };