BattleStacksController.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * BattleStacksController.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/Geometries.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. struct BattleHex;
  14. class BattleAction;
  15. class CStack;
  16. class SpellID;
  17. VCMI_LIB_NAMESPACE_END
  18. struct StackAttackedInfo;
  19. class Canvas;
  20. class BattleInterface;
  21. class CBattleAnimation;
  22. class CreatureAnimation;
  23. class CBattleAnimation;
  24. class BattleRenderer;
  25. class IImage;
  26. /// Class responsible for handling stacks in battle
  27. /// Handles ordering of stacks animation
  28. /// As well as rendering of stacks, their amount boxes
  29. /// And any other effect applied to stacks
  30. class BattleStacksController
  31. {
  32. BattleInterface & owner;
  33. std::shared_ptr<IImage> amountNormal;
  34. std::shared_ptr<IImage> amountNegative;
  35. std::shared_ptr<IImage> amountPositive;
  36. std::shared_ptr<IImage> amountEffNeutral;
  37. /// currently displayed animations <anim, initialized>
  38. std::vector<CBattleAnimation *> currentAnimations;
  39. /// animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
  40. std::map<int32_t, std::shared_ptr<CreatureAnimation>> stackAnimation;
  41. /// <creatureID, if false reverse creature's animation> //TODO: move it to battle callback
  42. std::map<int, bool> stackFacingRight;
  43. /// number of active stack; nullptr - no one
  44. const CStack *activeStack;
  45. /// stack below mouse pointer, used for border animation
  46. const CStack *mouseHoveredStack;
  47. ///when animation is playing, we should wait till the end to make the next stack active; nullptr of none
  48. const CStack *stackToActivate;
  49. /// stack that was selected for multi-target spells - Teleport / Sacrifice
  50. const CStack *selectedStack;
  51. /// if true, active stack could possibly cast some target spell
  52. bool stackCanCastSpell;
  53. si32 creatureSpellToCast;
  54. /// for giving IDs for animations
  55. ui32 animIDhelper;
  56. bool stackNeedsAmountBox(const CStack * stack) const;
  57. void showStackAmountBox(Canvas & canvas, const CStack * stack);
  58. BattleHex getStackCurrentPosition(const CStack * stack) const;
  59. std::shared_ptr<IImage> getStackAmountBox(const CStack * stack);
  60. public:
  61. BattleStacksController(BattleInterface & owner);
  62. bool shouldRotate(const CStack * stack, const BattleHex & oldPos, const BattleHex & nextHex) const;
  63. bool facingRight(const CStack * stack) const;
  64. void stackReset(const CStack * stack);
  65. void stackAdded(const CStack * stack); //new stack appeared on battlefield
  66. void stackRemoved(uint32_t stackID); //stack disappeared from batlefiled
  67. void stackActivated(const CStack *stack); //active stack has been changed
  68. void stackMoved(const CStack *stack, std::vector<BattleHex> destHex, int distance); //stack with id number moved to destHex
  69. void stacksAreAttacked(std::vector<StackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked
  70. void stackAttacking(const CStack *attacker, BattleHex dest, const CStack *attacked, bool shooting); //called when stack with id ID is attacking something on hex dest
  71. void startAction(const BattleAction* action);
  72. void endAction(const BattleAction* action);
  73. bool activeStackSpellcaster();
  74. SpellID activeStackSpellToCast();
  75. void activateStack(); //sets activeStack to stackToActivate etc. //FIXME: No, it's not clear at all
  76. void setActiveStack(const CStack *stack);
  77. void setHoveredStack(const CStack *stack);
  78. void setSelectedStack(const CStack *stack);
  79. void showAliveStack(Canvas & canvas, const CStack * stack);
  80. void showStack(Canvas & canvas, const CStack * stack);
  81. void collectRenderableObjects(BattleRenderer & renderer);
  82. void addNewAnim(CBattleAnimation *anim); //adds new anim to pendingAnims
  83. void updateBattleAnimations();
  84. const CStack* getActiveStack() const;
  85. const CStack* getSelectedStack() const;
  86. /// returns position of animation needed to place stack in specific hex
  87. Point getStackPositionAtHex(BattleHex hexNum, const CStack * creature) const;
  88. friend class CBattleAnimation; // for exposing pendingAnims/creAnims/creDir to animations
  89. };