CObstacleInstance.h 4.0 KB

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