ISpellMechanics.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * ISpellMechanics.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. ///callback to be provided by server
  14. class DLL_LINKAGE SpellCastEnvironment
  15. {
  16. public:
  17. virtual ~SpellCastEnvironment(){};
  18. virtual void sendAndApply(CPackForClient * info) const = 0;
  19. virtual CRandomGenerator & getRandomGenerator() const = 0;
  20. virtual void complain(const std::string & problem) const = 0;
  21. virtual const CMap * getMap() const = 0;
  22. virtual const CGameInfoCallback * getCb() const = 0;
  23. virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker = PlayerColor::NEUTRAL) const =0; //TODO: remove
  24. };
  25. ///all parameters of particular cast event
  26. struct DLL_LINKAGE BattleSpellCastParameters
  27. {
  28. public:
  29. ///Single spell destination.
  30. /// (assumes that anything but battle stack can share same hex)
  31. struct DLL_LINKAGE Destination
  32. {
  33. explicit Destination(const CStack * destination);
  34. explicit Destination(const BattleHex & destination);
  35. const CStack * stackValue;
  36. const BattleHex hexValue;
  37. };
  38. BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell);
  39. void aimToHex(const BattleHex & destination);
  40. void aimToStack(const CStack * destination);
  41. BattleHex getFirstDestinationHex() const;
  42. const BattleInfo * cb;
  43. const ISpellCaster * caster;
  44. const PlayerColor casterColor;
  45. const ui8 casterSide;
  46. std::vector<Destination> destinations;
  47. const CGHeroInstance * casterHero; //deprecated
  48. ECastingMode::ECastingMode mode;
  49. const CStack * casterStack; //deprecated
  50. const CStack * selectedStack;//deprecated
  51. ///spell school level
  52. int spellLvl;
  53. ///spell school level to use for effects
  54. int effectLevel;
  55. ///actual spell-power affecting effect values
  56. int effectPower;
  57. ///actual spell-power affecting effect duration
  58. int enchantPower;
  59. ///for Archangel-like casting
  60. int effectValue;
  61. private:
  62. void prepare(const CSpell * spell);
  63. };
  64. struct DLL_LINKAGE AdventureSpellCastParameters
  65. {
  66. const CGHeroInstance * caster;
  67. int3 pos;
  68. };
  69. class DLL_LINKAGE ISpellMechanics
  70. {
  71. public:
  72. struct DLL_LINKAGE SpellTargetingContext
  73. {
  74. const CBattleInfoCallback * cb;
  75. CSpell::TargetInfo ti;
  76. ECastingMode::ECastingMode mode;
  77. BattleHex destination;
  78. PlayerColor casterColor;
  79. int schoolLvl;
  80. SpellTargetingContext(const CSpell * s, const CBattleInfoCallback * c, ECastingMode::ECastingMode m, PlayerColor cc, int lvl, BattleHex dest)
  81. : cb(c), ti(s,lvl, m), mode(m), destination(dest), casterColor(cc), schoolLvl(lvl)
  82. {};
  83. };
  84. public:
  85. ISpellMechanics(CSpell * s);
  86. virtual ~ISpellMechanics(){};
  87. virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
  88. virtual std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const = 0;
  89. virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, PlayerColor player) const = 0;
  90. virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const = 0;
  91. virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;
  92. virtual bool adventureCast(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const = 0;
  93. virtual void battleCast(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters) const = 0;
  94. virtual void battleLogSingleTarget(std::vector<std::string> & logLines, const BattleSpellCast * packet,
  95. const std::string & casterName, const CStack * attackedStack, bool & displayDamage) const = 0;
  96. static ISpellMechanics * createMechanics(CSpell * s);
  97. protected:
  98. CSpell * owner;
  99. };