CBattleStacksController.h 3.8 KB

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