CObstacleInstance.h 2.3 KB

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