BattleStacksController.h 4.2 KB

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