BattleAction.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. si32 actionSubtype;
  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. std::string toString() const;
  39. void aimToHex(const BattleHex & destination);
  40. void aimToUnit(const battle::Unit * destination);
  41. battle::Target getTarget(const CBattleInfoCallback * cb) const;
  42. void setTarget(const battle::Target & target_);
  43. template <typename Handler> void serialize(Handler & h, const int version)
  44. {
  45. h & side;
  46. h & stackNumber;
  47. h & actionType;
  48. h & actionSubtype;
  49. h & target;
  50. }
  51. private:
  52. struct DestinationInfo
  53. {
  54. int32_t unitValue;
  55. BattleHex hexValue;
  56. template <typename Handler> void serialize(Handler & h, const int version)
  57. {
  58. h & unitValue;
  59. h & hexValue;
  60. }
  61. };
  62. std::vector<DestinationInfo> target;
  63. };
  64. DLL_EXPORT std::ostream & operator<<(std::ostream & os, const BattleAction & ba); //todo: remove
  65. VCMI_LIB_NAMESPACE_END