Obstacle.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 appearAnimation;
  26. std::string animation;
  27. int offsetY;
  28. ObstacleSideOptions();
  29. void serializeJson(JsonSerializeFormat & handler);
  30. private:
  31. void serializeRelativeShape(JsonSerializeFormat & handler, const std::string & fieldName, RelativeShape & value);
  32. };
  33. class Obstacle : public LocationEffect
  34. {
  35. public:
  36. Obstacle();
  37. virtual ~Obstacle();
  38. void adjustAffectedHexes(std::set<BattleHex> & hexes, const Mechanics * m, const Target & spellTarget) const override;
  39. bool applicable(Problem & problem, const Mechanics * m) const override;
  40. bool applicable(Problem & problem, const Mechanics * m, const EffectTarget & target) const override;
  41. EffectTarget transformTarget(const Mechanics * m, const Target & aimPoint, const Target & spellTarget) const override;
  42. void apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const override;
  43. protected:
  44. void serializeJsonEffect(JsonSerializeFormat & handler) override;
  45. private:
  46. bool hidden;
  47. bool passable;
  48. bool trigger;
  49. bool trap;
  50. bool removeOnTrigger;
  51. int32_t patchCount;//random patches to place, only for massive spells
  52. int32_t turnsRemaining;
  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. void placeObstacles(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const;
  57. };
  58. }
  59. }
  60. VCMI_LIB_NAMESPACE_END