CObstacleInstance.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. BattleHex pos; //position on battlefield, typically left bottom corner
  19. ui8 obstacleType; //if true, then position is meaningless
  20. si32 uniqueID;
  21. si32 ID; //ID of obstacle (defines type of it)
  22. enum EObstacleType
  23. {
  24. //ABSOLUTE needs an underscore because it's a Win
  25. USUAL, ABSOLUTE_OBSTACLE, SPELL_CREATED, MOAT
  26. };
  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 appearAnimation;
  66. std::string animation;
  67. int animationYOffset;
  68. std::vector<BattleHex> customSize;
  69. SpellCreatedObstacle();
  70. std::vector<BattleHex> getAffectedTiles() const override;
  71. bool visibleForSide(ui8 side, bool hasNativeStack) const override;
  72. bool blocksTiles() const override;
  73. bool stopsMovement() const override;
  74. bool triggersEffects() const override;
  75. void battleTurnPassed() override;
  76. int getAnimationYOffset(int imageHeight) const override;
  77. void toInfo(ObstacleChanges & info);
  78. void fromInfo(const ObstacleChanges & info);
  79. void serializeJson(JsonSerializeFormat & handler);
  80. template <typename Handler> void serialize(Handler &h, const int version)
  81. {
  82. h & static_cast<CObstacleInstance&>(*this);
  83. h & turnsRemaining;
  84. h & casterSpellPower;
  85. h & spellLevel;
  86. h & casterSide;
  87. h & hidden;
  88. h & passable;
  89. h & trigger;
  90. h & trap;
  91. h & customSize;
  92. }
  93. };
  94. VCMI_LIB_NAMESPACE_END