CBattleInterface.h 8.9 KB

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