SpellMechanics.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) 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 SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) const override;
  54. };
  55. class ObstacleMechanics: public DefaultSpellMechanics
  56. {
  57. public:
  58. ObstacleMechanics(CSpell * s): DefaultSpellMechanics(s){};
  59. };
  60. class WallMechanics: public ObstacleMechanics
  61. {
  62. public:
  63. WallMechanics(CSpell * s): ObstacleMechanics(s){};
  64. std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool *outDroppedHexes = nullptr) const override;
  65. };
  66. class ChainLightningMechanics: public DefaultSpellMechanics
  67. {
  68. public:
  69. ChainLightningMechanics(CSpell * s): DefaultSpellMechanics(s){};
  70. std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const override;
  71. };
  72. class CloneMechanics: public DefaultSpellMechanics
  73. {
  74. public:
  75. CloneMechanics(CSpell * s): DefaultSpellMechanics(s){};
  76. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  77. };
  78. class DispellHelpfulMechanics: public DefaultSpellMechanics
  79. {
  80. public:
  81. DispellHelpfulMechanics(CSpell * s): DefaultSpellMechanics(s){};
  82. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  83. };
  84. class HypnotizeMechanics: public DefaultSpellMechanics
  85. {
  86. public:
  87. HypnotizeMechanics(CSpell * s): DefaultSpellMechanics(s){};
  88. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  89. };
  90. ///all rising spells
  91. class RisingSpellMechanics: public DefaultSpellMechanics
  92. {
  93. public:
  94. RisingSpellMechanics(CSpell * s): DefaultSpellMechanics(s){};
  95. };
  96. ///all rising spells but SACRIFICE
  97. class SpecialRisingSpellMechanics: public RisingSpellMechanics
  98. {
  99. public:
  100. SpecialRisingSpellMechanics(CSpell * s): RisingSpellMechanics(s){};
  101. ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
  102. };
  103. class SacrificeMechanics: public RisingSpellMechanics
  104. {
  105. public:
  106. SacrificeMechanics(CSpell * s): RisingSpellMechanics(s){};
  107. };