BattleSpellMechanics.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. bool isSmart() const override;
  47. /// Returns list of hexes that are affected by spell assuming cast at centralHex
  48. BattleHexArray rangeInHexes(const BattleHex & centralHex) const override;
  49. const Spell * getSpell() const override;
  50. bool counteringSelector(const Bonus * bonus) const;
  51. private:
  52. std::shared_ptr<effects::Effects> effects;
  53. std::shared_ptr<IReceptiveCheck> targetCondition;
  54. battle::Units affectedUnits;
  55. effects::Effects::EffectsToApply effectsToApply;
  56. void beforeCast(BattleSpellCast & sc, vstd::RNG & rng, const Target & target);
  57. bool isReflected(const battle::Unit * unit, vstd::RNG & rng);
  58. void reflect(BattleSpellCast & sc, vstd::RNG & rng, const battle::Unit * unit);
  59. const battle::Unit * getRandomUnit(vstd::RNG & rng, const BattleSide & side);
  60. std::set<const battle::Unit *> collectTargets() const;
  61. void doRemoveEffects(ServerCallback * server, const battle::Units & targets, const CSelector & selector);
  62. BattleHexArray spellRangeInHexes(const BattleHex & centralHex) const;
  63. Target transformSpellTarget(const Target & aimPoint) const;
  64. bool canCastAtTarget(const battle::Unit * target) const;
  65. };
  66. }
  67. VCMI_LIB_NAMESPACE_END