BattleAction.h 2.2 KB

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