CBattleStacksController.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * CBattleStacksController.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. struct BattleObjectsByHex;
  12. struct SDL_Surface;
  13. struct BattleHex;
  14. struct StackAttackedInfo;
  15. struct BattleAction;
  16. class CCanvas;
  17. class SpellID;
  18. class CBattleInterface;
  19. class CBattleAnimation;
  20. class CCreatureAnimation;
  21. class CStack;
  22. class CBattleAnimation;
  23. class IImage;
  24. class CBattleStacksController
  25. {
  26. CBattleInterface * owner;
  27. std::shared_ptr<IImage> amountNormal;
  28. std::shared_ptr<IImage> amountNegative;
  29. std::shared_ptr<IImage> amountPositive;
  30. std::shared_ptr<IImage> amountEffNeutral;
  31. std::list<std::pair<CBattleAnimation *, bool>> pendingAnims; //currently displayed animations <anim, initialized>
  32. std::map<int32_t, std::shared_ptr<CCreatureAnimation>> creAnims; //animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
  33. std::map<int, bool> creDir; // <creatureID, if false reverse creature's animation> //TODO: move it to battle callback
  34. const CStack *activeStack; //number of active stack; nullptr - no one
  35. const CStack *mouseHoveredStack; // stack below mouse pointer, used for border animation
  36. const CStack *stackToActivate; //when animation is playing, we should wait till the end to make the next stack active; nullptr of none
  37. const CStack *selectedStack; //for Teleport / Sacrifice
  38. bool stackCanCastSpell; //if true, active stack could possibly cast some target spell
  39. si32 creatureSpellToCast;
  40. ui32 animIDhelper; //for giving IDs for animations
  41. bool stackNeedsAmountBox(const CStack * stack);
  42. void showStackAmountBox(std::shared_ptr<CCanvas> canvas, const CStack * stack);
  43. std::shared_ptr<IImage> getStackAmountBox(const CStack * stack);
  44. public:
  45. CBattleStacksController(CBattleInterface * owner);
  46. bool shouldRotate(const CStack * stack, const BattleHex & oldPos, const BattleHex & nextHex);
  47. bool facingRight(const CStack * stack);
  48. void stackReset(const CStack * stack);
  49. void stackAdded(const CStack * stack); //new stack appeared on battlefield
  50. void stackRemoved(uint32_t stackID); //stack disappeared from batlefiled
  51. void stackActivated(const CStack *stack); //active stack has been changed
  52. void stackMoved(const CStack *stack, std::vector<BattleHex> destHex, int distance); //stack with id number moved to destHex
  53. void stacksAreAttacked(std::vector<StackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
  54. void stackAttacking(const CStack *attacker, BattleHex dest, const CStack *attacked, bool shooting); //called when stack with id ID is attacking something on hex dest
  55. void startAction(const BattleAction* action);
  56. void endAction(const BattleAction* action);
  57. bool activeStackSpellcaster();
  58. SpellID activeStackSpellToCast();
  59. void activateStack(); //sets activeStack to stackToActivate etc. //FIXME: No, it's not clear at all
  60. void setActiveStack(const CStack *stack);
  61. void setHoveredStack(const CStack *stack);
  62. void setSelectedStack(const CStack *stack);
  63. void showAliveStack(std::shared_ptr<CCanvas> canvas, const CStack * stack);
  64. void showStack(std::shared_ptr<CCanvas> canvas, const CStack * stack);
  65. void showBattlefieldObjects(std::shared_ptr<CCanvas> canvas, const BattleHex & location );
  66. void addNewAnim(CBattleAnimation *anim); //adds new anim to pendingAnims
  67. void updateBattleAnimations();
  68. const CStack* getActiveStack();
  69. const CStack* getSelectedStack();
  70. friend class CBattleAnimation; // for exposing pendingAnims/creAnims/creDir to animations
  71. };