CObstacleInstance.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. struct DLL_LINKAGE CObstacleInstance
  14. {
  15. BattleHex pos; //position on battlefield, typically left bottom corner
  16. ui8 obstacleType; //if true, then position is meaningless
  17. si32 uniqueID;
  18. si32 ID; //ID of obstacle (defines type of it)
  19. enum EObstacleType
  20. {
  21. //ABSOLUTE needs an underscore because it's a Win
  22. USUAL,
  23. ABSOLUTE_OBSTACLE,
  24. QUICKSAND,
  25. LAND_MINE,
  26. FORCE_FIELD,
  27. FIRE_WALL,
  28. MOAT
  29. };
  30. //used only for spell-created obstacles
  31. CObstacleInstance();
  32. virtual ~CObstacleInstance();
  33. //bool spellGenerated() const;
  34. const CObstacleInfo & getInfo() const; //allowed only when not generated by spell (usual or absolute)
  35. std::vector<BattleHex> getBlockedTiles() const;
  36. std::vector<BattleHex> getStoppingTile() const; //hexes that will stop stack move
  37. //The two functions below describe how the obstacle affects affected tiles
  38. //additional effects (like hurting stack or disappearing) are hardcoded for appropriate obstacleTypes
  39. bool blocksTiles() const;
  40. bool stopsMovement() const; //if unit stepping onto obstacle, can't continue movement (in general, doesn't checks for the side)
  41. virtual std::vector<BattleHex> getAffectedTiles() const;
  42. virtual bool visibleForSide(ui8 side, bool hasNativeStack) const; //0 attacker
  43. virtual void battleTurnPassed(){};
  44. template<typename Handler> void serialize(Handler & h, const int version)
  45. {
  46. h & ID & pos & obstacleType & uniqueID;
  47. }
  48. };
  49. struct DLL_LINKAGE MoatObstacle : CObstacleInstance
  50. {
  51. virtual std::vector<BattleHex> getAffectedTiles() const override; //for special effects (not blocking)
  52. };
  53. struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
  54. {
  55. si8 turnsRemaining;
  56. si8 casterSpellPower;
  57. si8 spellLevel;
  58. si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
  59. si8 visibleForAnotherSide;
  60. SpellCreatedObstacle();
  61. virtual std::vector<BattleHex> getAffectedTiles() const override; //for special effects (not blocking)
  62. virtual bool visibleForSide(ui8 side, bool hasNativeStack) const override; //0 attacker
  63. virtual void battleTurnPassed() override;
  64. template<typename Handler> void serialize(Handler & h, const int version)
  65. {
  66. h & static_cast<CObstacleInstance &>(*this);
  67. h & turnsRemaining & casterSpellPower & spellLevel & casterSide & visibleForAnotherSide;
  68. }
  69. };