CObstacleInstance.h 3.9 KB

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