Obstacle.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Obstacle.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 "LocationEffect.h"
  12. #include "../../battle/BattleHex.h"
  13. #include "../../battle/CObstacleInstance.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. namespace spells
  16. {
  17. namespace effects
  18. {
  19. class ObstacleSideOptions
  20. {
  21. public:
  22. using RelativeShape = std::vector<std::vector<BattleHex::EDir>>;
  23. RelativeShape shape; //shape of single obstacle relative to obstacle position
  24. RelativeShape range; //position of obstacles relative to effect destination
  25. std::string appearSound;
  26. std::string appearAnimation;
  27. std::string triggerSound;
  28. std::string triggerAnimation;
  29. std::string animation;
  30. int offsetY = 0;
  31. void serializeJson(JsonSerializeFormat & handler);
  32. };
  33. class Obstacle : public LocationEffect
  34. {
  35. public:
  36. void adjustAffectedHexes(std::set<BattleHex> & hexes, const Mechanics * m, const Target & spellTarget) const override;
  37. bool applicable(Problem & problem, const Mechanics * m) const override;
  38. bool applicable(Problem & problem, const Mechanics * m, const EffectTarget & target) const override;
  39. EffectTarget transformTarget(const Mechanics * m, const Target & aimPoint, const Target & spellTarget) const override;
  40. void apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const override;
  41. protected:
  42. void serializeJsonEffect(JsonSerializeFormat & handler) override;
  43. virtual void placeObstacles(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const;
  44. bool hidden = false;
  45. bool passable = false;
  46. bool trigger = false;
  47. bool trap = false;
  48. bool removeOnTrigger = false;
  49. bool hideNative = false;
  50. private:
  51. int32_t patchCount = 0; //random patches to place, for massive spells should be >= 1, for non-massive ones if >= 1, then place only this number inside a target (like H5 landMine)
  52. int32_t turnsRemaining = -1;
  53. std::array<ObstacleSideOptions, 2> sideOptions;
  54. static bool isHexAvailable(const CBattleInfoCallback * cb, const BattleHex & hex, const bool mustBeClear);
  55. static bool noRoomToPlace(Problem & problem, const Mechanics * m);
  56. };
  57. }
  58. }
  59. VCMI_LIB_NAMESPACE_END