BattleAction.h 2.2 KB

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