ISpellMechanics.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "../BattleState.h"
  14. #include "../NetPacks.h"
  15. ///callback to be provided by server
  16. class DLL_LINKAGE SpellCastEnvironment
  17. {
  18. public:
  19. virtual ~SpellCastEnvironment(){};
  20. virtual void sendAndApply(CPackForClient * info) const = 0;
  21. virtual CRandomGenerator & getRandomGenerator() const = 0;
  22. virtual void complain(const std::string & problem) const = 0;
  23. virtual const CMap * getMap() const = 0;
  24. virtual const CGameInfoCallback * getCb() const = 0;
  25. virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker = PlayerColor::NEUTRAL) const =0; //TODO: remove
  26. };
  27. ///helper struct
  28. struct DLL_LINKAGE BattleSpellCastParameters
  29. {
  30. public:
  31. BattleSpellCastParameters(const BattleInfo * cb);
  32. int spellLvl;
  33. BattleHex destination;
  34. ui8 casterSide;
  35. PlayerColor casterColor;
  36. const CGHeroInstance * casterHero; //deprecated
  37. int usedSpellPower;
  38. ECastingMode::ECastingMode mode;
  39. const CStack * casterStack;
  40. const CStack * selectedStack;
  41. const BattleInfo * cb;
  42. };
  43. struct DLL_LINKAGE AdventureSpellCastParameters
  44. {
  45. const CGHeroInstance * caster;
  46. int3 pos;
  47. };
  48. class DLL_LINKAGE ISpellMechanics
  49. {
  50. public:
  51. struct DLL_LINKAGE SpellTargetingContext
  52. {
  53. const CBattleInfoCallback * cb;
  54. CSpell::TargetInfo ti;
  55. ECastingMode::ECastingMode mode;
  56. BattleHex destination;
  57. PlayerColor casterColor;
  58. int schoolLvl;
  59. SpellTargetingContext(const CSpell * s, const CBattleInfoCallback * c, ECastingMode::ECastingMode m, PlayerColor cc, int lvl, BattleHex dest)
  60. : cb(c), ti(s,lvl, m), mode(m), destination(dest), casterColor(cc), schoolLvl(lvl)
  61. {};
  62. };
  63. public:
  64. ISpellMechanics(CSpell * s);
  65. virtual ~ISpellMechanics(){};
  66. virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
  67. virtual std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const = 0;
  68. virtual ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const = 0;
  69. virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const = 0;
  70. virtual void applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const = 0;
  71. virtual bool adventureCast(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const = 0;
  72. virtual void battleCast(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters) const = 0;
  73. virtual void battleLogSingleTarget(std::vector<std::string> & logLines, const BattleSpellCast * packet,
  74. const std::string & casterName, const CStack * attackedStack, bool & displayDamage) const = 0;
  75. static ISpellMechanics * createMechanics(CSpell * s);
  76. protected:
  77. CSpell * owner;
  78. };