CObstacleInstance.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. struct CObstacleInfo;
  13. class ObstacleChanges;
  14. class JsonSerializeFormat;
  15. struct DLL_LINKAGE CObstacleInstance
  16. {
  17. BattleHex pos; //position on battlefield, typically left bottom corner
  18. ui8 obstacleType; //if true, then position is meaningless
  19. si32 uniqueID;
  20. si32 ID; //ID of obstacle (defines type of it)
  21. enum EObstacleType
  22. {
  23. //ABSOLUTE needs an underscore because it's a Win
  24. USUAL, ABSOLUTE_OBSTACLE, SPELL_CREATED, MOAT
  25. };
  26. CObstacleInstance();
  27. virtual ~CObstacleInstance();
  28. const CObstacleInfo &getInfo() const; //allowed only when not generated by spell (usual or absolute)
  29. std::vector<BattleHex> getBlockedTiles() const;
  30. std::vector<BattleHex> getStoppingTile() const; //hexes that will stop stack move
  31. //The two functions below describe how the obstacle affects affected tiles
  32. //additional effects (like hurting stack or disappearing) are hardcoded for appropriate obstacleTypes
  33. virtual bool blocksTiles() const;
  34. virtual bool stopsMovement() const; //if unit stepping onto obstacle, can't continue movement (in general, doesn't checks for the side)
  35. virtual bool triggersEffects() const;
  36. virtual std::vector<BattleHex> getAffectedTiles() const;
  37. virtual bool visibleForSide(ui8 side, bool hasNativeStack) const; //0 attacker
  38. virtual void battleTurnPassed(){};
  39. virtual int getAnimationYOffset(int imageHeight) const;
  40. template <typename Handler> void serialize(Handler &h, const int version)
  41. {
  42. h & ID;
  43. h & pos;
  44. h & obstacleType;
  45. h & uniqueID;
  46. }
  47. };
  48. struct DLL_LINKAGE MoatObstacle : CObstacleInstance
  49. {
  50. std::vector<BattleHex> getAffectedTiles() const override; //for special effects (not blocking)
  51. };
  52. struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
  53. {
  54. int32_t turnsRemaining;
  55. int32_t casterSpellPower;
  56. int32_t spellLevel;
  57. si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
  58. bool hidden;
  59. bool passable;
  60. bool trigger;
  61. bool trap;
  62. bool removeOnTrigger;
  63. bool revealed;
  64. std::string appearAnimation;
  65. std::string animation;
  66. int animationYOffset;
  67. std::vector<BattleHex> customSize;
  68. SpellCreatedObstacle();
  69. std::vector<BattleHex> getAffectedTiles() const override;
  70. bool visibleForSide(ui8 side, bool hasNativeStack) const override;
  71. bool blocksTiles() const override;
  72. bool stopsMovement() const override;
  73. bool triggersEffects() const override;
  74. void battleTurnPassed() override;
  75. int getAnimationYOffset(int imageHeight) const override;
  76. void toInfo(ObstacleChanges & info);
  77. void fromInfo(const ObstacleChanges & info);
  78. void serializeJson(JsonSerializeFormat & handler);
  79. template <typename Handler> void serialize(Handler &h, const int version)
  80. {
  81. h & static_cast<CObstacleInstance&>(*this);
  82. h & turnsRemaining;
  83. h & casterSpellPower;
  84. h & spellLevel;
  85. h & casterSide;
  86. h & hidden;
  87. h & passable;
  88. h & trigger;
  89. h & trap;
  90. h & customSize;
  91. }
  92. };