CObstacleInstance.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 triggerSound;
  68. std::string triggerAnimation;
  69. std::string animation;
  70. int animationYOffset;
  71. std::vector<BattleHex> customSize;
  72. SpellCreatedObstacle();
  73. std::vector<BattleHex> getAffectedTiles() const override;
  74. bool visibleForSide(ui8 side, bool hasNativeStack) const override;
  75. bool blocksTiles() const override;
  76. bool stopsMovement() const override;
  77. bool triggersEffects() const override;
  78. void battleTurnPassed() override;
  79. int getAnimationYOffset(int imageHeight) const override;
  80. void toInfo(ObstacleChanges & info);
  81. void fromInfo(const ObstacleChanges & info);
  82. void serializeJson(JsonSerializeFormat & handler);
  83. template <typename Handler> void serialize(Handler &h, const int version)
  84. {
  85. h & static_cast<CObstacleInstance&>(*this);
  86. h & turnsRemaining;
  87. h & casterSpellPower;
  88. h & spellLevel;
  89. h & casterSide;
  90. h & hidden;
  91. h & passable;
  92. h & trigger;
  93. h & trap;
  94. h & customSize;
  95. }
  96. };
  97. VCMI_LIB_NAMESPACE_END