BattleSpellMechanics.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. void forEachEffect(const std::function<bool(const spells::effects::Effect &)> & fn) const override final;
  27. // TODO: ??? (what's the difference compared to cast?)
  28. void applyEffects(ServerCallback * server, const Target & targets, bool indirect, bool ignoreImmunity) const override;
  29. /// Returns false if spell can not be cast at all, e.g. due to not having any possible target on battlefield
  30. bool canBeCast(Problem & problem) const override;
  31. /// Returns false if spell can not be cast at specified target
  32. bool canBeCastAt(const Target & target, Problem & problem) const override;
  33. // TODO: ??? (what's the difference compared to applyEffects?)
  34. void cast(ServerCallback * server, const Target & target) override final;
  35. // TODO: ??? (what's the difference compared to cast?)
  36. void castEval(ServerCallback * server, const Target & target) override final;
  37. /// Returns list of affected stack using currently configured target
  38. std::vector<const CStack *> getAffectedStacks(const Target & target) const override final;
  39. /// Returns list of target types that can be targeted by spell
  40. std::vector<AimType> getTargetTypes() const override final;
  41. /// Returns vector of all possible destinations for specified aim type
  42. /// index - ???
  43. /// current - ???
  44. std::vector<Destination> getPossibleDestinations(size_t index, AimType aimType, const Target & current, bool fast) const override final;
  45. /// Returns true if spell can be cast on unit
  46. bool isReceptive(const battle::Unit * target) const override;
  47. bool isSmart() const override;
  48. /// Returns true if unit would resist the spell due to magic resistance
  49. bool wouldResist(const battle::Unit * unit) const override;
  50. /// Returns list of hexes that are affected by spell assuming cast at centralHex
  51. BattleHexArray rangeInHexes(const BattleHex & centralHex) const override;
  52. Target canonicalizeTarget(const Target & aim) const override;
  53. const Spell * getSpell() const override;
  54. bool counteringSelector(const Bonus * bonus) const;
  55. private:
  56. std::shared_ptr<effects::Effects> effects;
  57. std::shared_ptr<IReceptiveCheck> targetCondition;
  58. battle::Units affectedUnits;
  59. std::set<uint32_t> resistantUnitIds; // ids of units that would resist the spell (used in chain lightning computation)
  60. effects::Effects::EffectsToApply effectsToApply;
  61. void beforeCast(BattleSpellCast & sc, vstd::RNG & rng, const Target & target);
  62. bool isReflected(const battle::Unit * unit, vstd::RNG & rng);
  63. void reflect(BattleSpellCast & sc, vstd::RNG & rng, const battle::Unit * unit);
  64. const battle::Unit * getRandomUnit(vstd::RNG & rng, const BattleSide & side);
  65. std::set<const battle::Unit *> collectTargets() const;
  66. void doRemoveEffects(ServerCallback * server, const battle::Units & targets, const CSelector & selector);
  67. BattleHexArray spellRangeInHexes(const BattleHex & centralHex) const;
  68. Target transformSpellTarget(const Target & aimPoint) const;
  69. bool canCastAtTarget(const battle::Unit * target) const;
  70. };
  71. }
  72. VCMI_LIB_NAMESPACE_END