CObstacleInstance.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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, ABSOLUTE_OBSTACLE, QUICKSAND, LAND_MINE, FORCE_FIELD, FIRE_WALL, MOAT
  23. };
  24. //used only for spell-created obstacles
  25. CObstacleInstance();
  26. virtual ~CObstacleInstance();
  27. //bool spellGenerated() const;
  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. bool blocksTiles() const;
  34. bool stopsMovement() const; //if unit stepping onto obstacle, can't continue movement (in general, doesn't checks for the side)
  35. virtual std::vector<BattleHex> getAffectedTiles() const;
  36. virtual bool visibleForSide(ui8 side, bool hasNativeStack) const; //0 attacker
  37. virtual void battleTurnPassed(){};
  38. template <typename Handler> void serialize(Handler &h, const int version)
  39. {
  40. h & ID;
  41. h & pos;
  42. h & obstacleType;
  43. h & uniqueID;
  44. }
  45. };
  46. struct DLL_LINKAGE MoatObstacle : CObstacleInstance
  47. {
  48. virtual std::vector<BattleHex> getAffectedTiles() const override; //for special effects (not blocking)
  49. };
  50. struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
  51. {
  52. si8 turnsRemaining;
  53. si8 casterSpellPower;
  54. si8 spellLevel;
  55. si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
  56. si8 visibleForAnotherSide;
  57. SpellCreatedObstacle();
  58. virtual std::vector<BattleHex> getAffectedTiles() const override; //for special effects (not blocking)
  59. virtual bool visibleForSide(ui8 side, bool hasNativeStack) const override; //0 attacker
  60. virtual void battleTurnPassed() override;
  61. template <typename Handler> void serialize(Handler &h, const int version)
  62. {
  63. h & static_cast<CObstacleInstance&>(*this);
  64. h & turnsRemaining;
  65. h & casterSpellPower;
  66. h & spellLevel;
  67. h & casterSide;
  68. h & visibleForAnotherSide;
  69. }
  70. };