CObstacleInstance.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include "BattleHex.h"
  3. /*
  4. * CObstacleInstance.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  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 & pos & obstacleType & uniqueID;
  41. }
  42. };
  43. struct DLL_LINKAGE MoatObstacle : CObstacleInstance
  44. {
  45. virtual std::vector<BattleHex> getAffectedTiles() const OVERRIDE; //for special effects (not blocking)
  46. };
  47. struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
  48. {
  49. si8 turnsRemaining;
  50. si8 casterSpellPower;
  51. si8 spellLevel;
  52. si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
  53. si8 visibleForAnotherSide;
  54. SpellCreatedObstacle();
  55. virtual std::vector<BattleHex> getAffectedTiles() const OVERRIDE; //for special effects (not blocking)
  56. virtual bool visibleForSide(ui8 side, bool hasNativeStack) const OVERRIDE; //0 attacker
  57. virtual void battleTurnPassed() OVERRIDE;
  58. template <typename Handler> void serialize(Handler &h, const int version)
  59. {
  60. h & static_cast<CObstacleInstance&>(*this);
  61. h & turnsRemaining & casterSpellPower & spellLevel & casterSide & visibleForAnotherSide;
  62. }
  63. };