CObstacleInstance.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * CObstacleInstance.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 "BattleHex.h"
  12. #include "NetPacksBase.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class ObstacleInfo;
  15. class ObstacleChanges;
  16. class JsonSerializeFormat;
  17. class SpellID;
  18. struct DLL_LINKAGE CObstacleInstance
  19. {
  20. enum EObstacleType : ui8
  21. {
  22. //ABSOLUTE needs an underscore because it's a Win
  23. USUAL, ABSOLUTE_OBSTACLE, SPELL_CREATED, MOAT
  24. };
  25. BattleHex pos; //position on battlefield, typically left bottom corner
  26. EObstacleType obstacleType = USUAL;
  27. si32 uniqueID = -1;
  28. si32 ID = -1; //ID of obstacle (defines type of it)
  29. virtual ~CObstacleInstance() = default;
  30. const ObstacleInfo &getInfo() const; //allowed only when not generated by spell (usual or absolute)
  31. std::vector<BattleHex> getBlockedTiles() const;
  32. std::vector<BattleHex> getStoppingTile() const; //hexes that will stop stack move
  33. //The two functions below describe how the obstacle affects affected tiles
  34. //additional effects (like hurting stack or disappearing) are hardcoded for appropriate obstacleTypes
  35. virtual bool blocksTiles() const;
  36. virtual bool stopsMovement() const; //if unit stepping onto obstacle, can't continue movement (in general, doesn't checks for the side)
  37. virtual bool triggersEffects() const;
  38. virtual SpellID getTrigger() const;
  39. virtual std::vector<BattleHex> getAffectedTiles() const;
  40. virtual bool visibleForSide(ui8 side, bool hasNativeStack) const; //0 attacker
  41. virtual void battleTurnPassed(){};
  42. //Client helper functions, make it easier to render animations
  43. virtual const std::string & getAnimation() const;
  44. virtual const std::string & getAppearAnimation() const;
  45. virtual const std::string & getAppearSound() const;
  46. virtual int getAnimationYOffset(int imageHeight) const;
  47. void toInfo(ObstacleChanges & info, BattleChanges::EOperation operation = BattleChanges::EOperation::ADD);
  48. virtual void serializeJson(JsonSerializeFormat & handler);
  49. template <typename Handler> void serialize(Handler &h, const int version)
  50. {
  51. h & ID;
  52. h & pos;
  53. h & obstacleType;
  54. h & uniqueID;
  55. }
  56. };
  57. struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
  58. {
  59. int32_t turnsRemaining;
  60. int32_t casterSpellPower;
  61. int32_t spellLevel;
  62. int32_t minimalDamage; //How many damage should it do regardless of power and level of caster
  63. si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
  64. SpellID trigger;
  65. bool hidden;
  66. bool passable;
  67. bool trap;
  68. bool removeOnTrigger;
  69. bool revealed;
  70. bool nativeVisible; //Should native terrain creatures reveal obstacle
  71. std::string appearSound;
  72. std::string appearAnimation;
  73. std::string animation;
  74. int animationYOffset;
  75. std::vector<BattleHex> customSize;
  76. SpellCreatedObstacle();
  77. std::vector<BattleHex> getAffectedTiles() const override;
  78. bool visibleForSide(ui8 side, bool hasNativeStack) const override;
  79. bool blocksTiles() const override;
  80. bool stopsMovement() const override;
  81. SpellID getTrigger() const override;
  82. void battleTurnPassed() override;
  83. //Client helper functions, make it easier to render animations
  84. const std::string & getAnimation() const override;
  85. const std::string & getAppearAnimation() const override;
  86. const std::string & getAppearSound() const override;
  87. int getAnimationYOffset(int imageHeight) const override;
  88. void fromInfo(const ObstacleChanges & info);
  89. void serializeJson(JsonSerializeFormat & handler) override;
  90. template <typename Handler> void serialize(Handler &h, const int version)
  91. {
  92. h & static_cast<CObstacleInstance&>(*this);
  93. h & turnsRemaining;
  94. h & casterSpellPower;
  95. h & spellLevel;
  96. h & casterSide;
  97. h & hidden;
  98. h & nativeVisible;
  99. h & passable;
  100. h & trigger;
  101. h & minimalDamage;
  102. h & trap;
  103. h & customSize;
  104. }
  105. };
  106. VCMI_LIB_NAMESPACE_END