BattleAction.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * BattleAction.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 "Destination.h"
  12. #include "../GameConstants.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CBattleInfoCallback;
  15. namespace battle
  16. {
  17. class Unit;
  18. }
  19. /// A struct which handles battle actions like defending, walking,... - represents a creature stack in a battle
  20. class DLL_LINKAGE BattleAction
  21. {
  22. public:
  23. ui8 side; //who made this action
  24. ui32 stackNumber; //stack ID, -1 left hero, -2 right hero,
  25. EActionType actionType; //use ActionType enum for values
  26. SpellID spell;
  27. BattleAction();
  28. static BattleAction makeHeal(const battle::Unit * healer, const battle::Unit * healed);
  29. static BattleAction makeDefend(const battle::Unit * stack);
  30. static BattleAction makeWait(const battle::Unit * stack);
  31. static BattleAction makeMeleeAttack(const battle::Unit * stack, BattleHex destination, BattleHex attackFrom, bool returnAfterAttack = true);
  32. static BattleAction makeShotAttack(const battle::Unit * shooter, const battle::Unit * target);
  33. static BattleAction makeCreatureSpellcast(const battle::Unit * stack, const battle::Target & target, const SpellID & spellID);
  34. static BattleAction makeMove(const battle::Unit * stack, BattleHex dest);
  35. static BattleAction makeEndOFTacticPhase(ui8 side);
  36. static BattleAction makeRetreat(ui8 side);
  37. static BattleAction makeSurrender(ui8 side);
  38. bool isTacticsAction() const;
  39. bool isUnitAction() const;
  40. bool isSpellAction() const;
  41. std::string toString() const;
  42. void aimToHex(const BattleHex & destination);
  43. void aimToUnit(const battle::Unit * destination);
  44. battle::Target getTarget(const CBattleInfoCallback * cb) const;
  45. void setTarget(const battle::Target & target_);
  46. template <typename Handler> void serialize(Handler & h, const int version)
  47. {
  48. h & side;
  49. h & stackNumber;
  50. h & actionType;
  51. h & spell;
  52. h & target;
  53. }
  54. private:
  55. struct DestinationInfo
  56. {
  57. int32_t unitValue;
  58. BattleHex hexValue;
  59. template <typename Handler> void serialize(Handler & h, const int version)
  60. {
  61. h & unitValue;
  62. h & hexValue;
  63. }
  64. };
  65. std::vector<DestinationInfo> target;
  66. };
  67. DLL_EXPORT std::ostream & operator<<(std::ostream & os, const BattleAction & ba); //todo: remove
  68. VCMI_LIB_NAMESPACE_END