CObstacleInstance.h 3.4 KB

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