CObstacleInstance.h 3.9 KB

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