Obstacle.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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;
  31. ObstacleSideOptions();
  32. void serializeJson(JsonSerializeFormat & handler);
  33. private:
  34. void serializeRelativeShape(JsonSerializeFormat & handler, const std::string & fieldName, RelativeShape & value);
  35. };
  36. class Obstacle : public LocationEffect
  37. {
  38. public:
  39. Obstacle();
  40. virtual ~Obstacle();
  41. void adjustAffectedHexes(std::set<BattleHex> & hexes, const Mechanics * m, const Target & spellTarget) const override;
  42. bool applicable(Problem & problem, const Mechanics * m) const override;
  43. bool applicable(Problem & problem, const Mechanics * m, const EffectTarget & target) const override;
  44. EffectTarget transformTarget(const Mechanics * m, const Target & aimPoint, const Target & spellTarget) const override;
  45. void apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const override;
  46. protected:
  47. void serializeJsonEffect(JsonSerializeFormat & handler) override;
  48. private:
  49. bool hidden;
  50. bool passable;
  51. bool trigger;
  52. bool trap;
  53. bool removeOnTrigger;
  54. int32_t patchCount;//random patches to place, only for massive spells
  55. int32_t turnsRemaining;
  56. std::array<ObstacleSideOptions, 2> sideOptions;
  57. static bool isHexAvailable(const CBattleInfoCallback * cb, const BattleHex & hex, const bool mustBeClear);
  58. static bool noRoomToPlace(Problem & problem, const Mechanics * m);
  59. void placeObstacles(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const;
  60. };
  61. }
  62. }
  63. VCMI_LIB_NAMESPACE_END