CBattleStacksController.h 3.4 KB

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