CBattleStacksController.h 3.9 KB

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