CObstacleInstance.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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;
  25. si32 uniqueID;
  26. si32 ID; //ID of obstacle (defines type of it)
  27. CObstacleInstance();
  28. virtual ~CObstacleInstance();
  29. const ObstacleInfo &getInfo() const; //allowed only when not generated by spell (usual or absolute)
  30. std::vector<BattleHex> getBlockedTiles() const;
  31. std::vector<BattleHex> getStoppingTile() const; //hexes that will stop stack move
  32. //The two functions below describe how the obstacle affects affected tiles
  33. //additional effects (like hurting stack or disappearing) are hardcoded for appropriate obstacleTypes
  34. virtual bool blocksTiles() const;
  35. virtual bool stopsMovement() const; //if unit stepping onto obstacle, can't continue movement (in general, doesn't checks for the side)
  36. virtual bool triggersEffects() const;
  37. virtual std::vector<BattleHex> getAffectedTiles() const;
  38. virtual bool visibleForSide(ui8 side, bool hasNativeStack) const; //0 attacker
  39. virtual void battleTurnPassed(){};
  40. virtual int getAnimationYOffset(int imageHeight) const;
  41. template <typename Handler> void serialize(Handler &h, const int version)
  42. {
  43. h & ID;
  44. h & pos;
  45. h & obstacleType;
  46. h & uniqueID;
  47. }
  48. };
  49. struct DLL_LINKAGE MoatObstacle : CObstacleInstance
  50. {
  51. std::vector<BattleHex> getAffectedTiles() const override; //for special effects (not blocking)
  52. };
  53. struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
  54. {
  55. int32_t turnsRemaining;
  56. int32_t casterSpellPower;
  57. int32_t spellLevel;
  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. std::string appearSound;
  66. std::string appearAnimation;
  67. std::string animation;
  68. int animationYOffset;
  69. std::vector<BattleHex> customSize;
  70. SpellCreatedObstacle();
  71. std::vector<BattleHex> getAffectedTiles() const override;
  72. bool visibleForSide(ui8 side, bool hasNativeStack) const override;
  73. bool blocksTiles() const override;
  74. bool stopsMovement() const override;
  75. bool triggersEffects() const override;
  76. void battleTurnPassed() override;
  77. int getAnimationYOffset(int imageHeight) const override;
  78. void toInfo(ObstacleChanges & info);
  79. void fromInfo(const ObstacleChanges & info);
  80. void serializeJson(JsonSerializeFormat & handler);
  81. template <typename Handler> void serialize(Handler &h, const int version)
  82. {
  83. h & static_cast<CObstacleInstance&>(*this);
  84. h & turnsRemaining;
  85. h & casterSpellPower;
  86. h & spellLevel;
  87. h & casterSide;
  88. h & hidden;
  89. h & passable;
  90. h & trigger;
  91. h & trap;
  92. h & customSize;
  93. }
  94. };
  95. VCMI_LIB_NAMESPACE_END