SpellMechanics.h 4.2 KB

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