BattleSpellMechanics.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * BattleSpellMechanics.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 "ISpellMechanics.h"
  12. #include "effects/Effects.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. struct BattleSpellCast;
  15. namespace battle
  16. {
  17. using Units = boost::container::small_vector<const Unit *, 4>;
  18. }
  19. namespace spells
  20. {
  21. class BattleSpellMechanics : public BaseMechanics
  22. {
  23. public:
  24. BattleSpellMechanics(const IBattleCast * event, std::shared_ptr<effects::Effects> effects_, std::shared_ptr<IReceptiveCheck> targetCondition_);
  25. virtual ~BattleSpellMechanics();
  26. // TODO: ??? (what's the difference compared to cast?)
  27. void applyEffects(ServerCallback * server, const Target & targets, bool indirect, bool ignoreImmunity) const override;
  28. /// Returns false if spell can not be cast at all, e.g. due to not having any possible target on battlefield
  29. bool canBeCast(Problem & problem) const override;
  30. /// Returns false if spell can not be cast at specified target
  31. bool canBeCastAt(const Target & target, Problem & problem) const override;
  32. // TODO: ??? (what's the difference compared to applyEffects?)
  33. void cast(ServerCallback * server, const Target & target) override final;
  34. // TODO: ??? (what's the difference compared to cast?)
  35. void castEval(ServerCallback * server, const Target & target) override final;
  36. /// Returns list of affected stack using currently configured target
  37. std::vector<const CStack *> getAffectedStacks(const Target & target) const override final;
  38. /// Returns list of target types that can be targeted by spell
  39. std::vector<AimType> getTargetTypes() const override final;
  40. /// Returns vector of all possible destinations for specified aim type
  41. /// index - ???
  42. /// current - ???
  43. std::vector<Destination> getPossibleDestinations(size_t index, AimType aimType, const Target & current, bool fast) const override final;
  44. /// Returns true if spell can be cast on unit
  45. bool isReceptive(const battle::Unit * target) const override;
  46. /// Returns list of hexes that are affected by spell assuming cast at centralHex
  47. BattleHexArray rangeInHexes(BattleHex centralHex) const override;
  48. const Spell * getSpell() const override;
  49. bool counteringSelector(const Bonus * bonus) const;
  50. private:
  51. std::shared_ptr<effects::Effects> effects;
  52. std::shared_ptr<IReceptiveCheck> targetCondition;
  53. battle::Units affectedUnits;
  54. effects::Effects::EffectsToApply effectsToApply;
  55. void beforeCast(BattleSpellCast & sc, vstd::RNG & rng, const Target & target);
  56. std::set<const battle::Unit *> collectTargets() const;
  57. void doRemoveEffects(ServerCallback * server, const battle::Units & targets, const CSelector & selector);
  58. BattleHexArray spellRangeInHexes(BattleHex centralHex) const;
  59. Target transformSpellTarget(const Target & aimPoint) const;
  60. };
  61. }
  62. VCMI_LIB_NAMESPACE_END