SpellMechanics.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * SpellMechanics.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 "CSpellHandler.h"
  12. #include "BattleHex.h"
  13. class DLL_LINKAGE ISpellMechanics
  14. {
  15. public:
  16. struct DLL_LINKAGE SpellTargetingContext
  17. {
  18. const CBattleInfoCallback * cb;
  19. CSpell::TargetInfo ti;
  20. ECastingMode::ECastingMode mode;
  21. BattleHex destination;
  22. PlayerColor casterColor;
  23. int schoolLvl;
  24. SpellTargetingContext(const CSpell * s, const CBattleInfoCallback * c, ECastingMode::ECastingMode m, PlayerColor cc, int lvl, BattleHex dest)
  25. : cb(c), ti(s,lvl, m), mode(m), destination(dest), casterColor(cc), schoolLvl(lvl)
  26. {};
  27. };
  28. public:
  29. ISpellMechanics(CSpell * s);
  30. virtual ~ISpellMechanics(){};
  31. virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool *outDroppedHexes = nullptr) const = 0;
  32. virtual std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const = 0;
  33. virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const = 0;
  34. /** \brief
  35. *
  36. * \param
  37. * \return true if no error
  38. *
  39. */
  40. virtual bool adventureCast(const SpellCastContext & context) const = 0;
  41. virtual bool battleCast(const SpellCastContext & context) const = 0;
  42. protected:
  43. CSpell * owner;
  44. };
  45. class DefaultSpellMechanics: public ISpellMechanics
  46. {
  47. public:
  48. DefaultSpellMechanics(CSpell * s): ISpellMechanics(s){};
  49. std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool *outDroppedHexes = nullptr) const override;
  50. std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const override;
  51. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  52. bool adventureCast(const SpellCastContext & context) const override;
  53. bool battleCast(const SpellCastContext & context) const override;
  54. };
  55. class WallMechanics: public DefaultSpellMechanics
  56. {
  57. public:
  58. WallMechanics(CSpell * s): DefaultSpellMechanics(s){};
  59. std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool *outDroppedHexes = nullptr) const override;
  60. };
  61. class ChainLightningMechanics: public DefaultSpellMechanics
  62. {
  63. public:
  64. ChainLightningMechanics(CSpell * s): DefaultSpellMechanics(s){};
  65. std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const override;
  66. };
  67. class CloneMechanics: public DefaultSpellMechanics
  68. {
  69. public:
  70. CloneMechanics(CSpell * s): DefaultSpellMechanics(s){};
  71. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  72. };
  73. class DispellHelpfulMechanics: public DefaultSpellMechanics
  74. {
  75. public:
  76. DispellHelpfulMechanics(CSpell * s): DefaultSpellMechanics(s){};
  77. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  78. };
  79. class HypnotizeMechanics: public DefaultSpellMechanics
  80. {
  81. public:
  82. HypnotizeMechanics(CSpell * s): DefaultSpellMechanics(s){};
  83. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  84. };
  85. ///all rising spells
  86. class RisingSpellMechanics: public DefaultSpellMechanics
  87. {
  88. public:
  89. RisingSpellMechanics(CSpell * s): DefaultSpellMechanics(s){};
  90. };
  91. ///all rising spells but SACRIFICE
  92. class SpecialRisingSpellMechanics: public RisingSpellMechanics
  93. {
  94. public:
  95. SpecialRisingSpellMechanics(CSpell * s): RisingSpellMechanics(s){};
  96. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  97. };
  98. class SacrificeMechanics: public RisingSpellMechanics
  99. {
  100. public:
  101. SacrificeMechanics(CSpell * s): RisingSpellMechanics(s){};
  102. };