BattleAction.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. BattleSide 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, const BattleHex & destination, const 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, const BattleHex & dest);
  35. static BattleAction makeEndOFTacticPhase(BattleSide side);
  36. static BattleAction makeRetreat(BattleSide side);
  37. static BattleAction makeSurrender(BattleSide side);
  38. bool isTacticsAction() const;
  39. bool isUnitAction() const;
  40. bool isSpellAction() const;
  41. bool isBattleEndAction() const;
  42. std::string toString() const;
  43. void aimToHex(const BattleHex & destination);
  44. void aimToUnit(const battle::Unit * destination);
  45. battle::Target getTarget(const CBattleInfoCallback * cb) const;
  46. void setTarget(const battle::Target & target_);
  47. template <typename Handler> void serialize(Handler & h)
  48. {
  49. h & side;
  50. h & stackNumber;
  51. h & actionType;
  52. h & spell;
  53. h & target;
  54. }
  55. private:
  56. struct DestinationInfo
  57. {
  58. int32_t unitValue;
  59. BattleHex hexValue;
  60. template <typename Handler> void serialize(Handler & h)
  61. {
  62. h & unitValue;
  63. h & hexValue;
  64. }
  65. };
  66. std::vector<DestinationInfo> target;
  67. };
  68. DLL_EXPORT std::ostream & operator<<(std::ostream & os, const BattleAction & ba); //todo: remove
  69. VCMI_LIB_NAMESPACE_END