BattleAction.h 2.1 KB

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