AdventureSpellMechanics.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * AdventureSpellMechanics.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 "ISpellMechanics.h"
  12. class CGTownInstance;
  13. enum class ESpellCastResult
  14. {
  15. OK,
  16. CANCEL,//cast failed but it is not an error
  17. PENDING,
  18. ERROR//internal error occurred
  19. };
  20. class DLL_LINKAGE AdventureSpellMechanics : public IAdventureSpellMechanics
  21. {
  22. public:
  23. AdventureSpellMechanics(const CSpell * s);
  24. bool adventureCast(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const override final;
  25. protected:
  26. ///actual adventure cast implementation
  27. virtual ESpellCastResult applyAdventureEffects(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const;
  28. virtual ESpellCastResult beginCast(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const;
  29. void performCast(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const;
  30. void endCast(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters, const ESpellCastResult result) const;
  31. };
  32. class DLL_LINKAGE SummonBoatMechanics : public AdventureSpellMechanics
  33. {
  34. public:
  35. SummonBoatMechanics(const CSpell * s);
  36. protected:
  37. ESpellCastResult applyAdventureEffects(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const override;
  38. };
  39. class DLL_LINKAGE ScuttleBoatMechanics : public AdventureSpellMechanics
  40. {
  41. public:
  42. ScuttleBoatMechanics(const CSpell * s);
  43. protected:
  44. ESpellCastResult applyAdventureEffects(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const override;
  45. };
  46. class DLL_LINKAGE DimensionDoorMechanics : public AdventureSpellMechanics
  47. {
  48. public:
  49. DimensionDoorMechanics(const CSpell * s);
  50. protected:
  51. ESpellCastResult applyAdventureEffects(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const override;
  52. };
  53. class DLL_LINKAGE TownPortalMechanics : public AdventureSpellMechanics
  54. {
  55. public:
  56. TownPortalMechanics(const CSpell * s);
  57. protected:
  58. ESpellCastResult applyAdventureEffects(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const override;
  59. ESpellCastResult beginCast(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const override;
  60. private:
  61. const CGTownInstance * findNearestTown(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters, const std::vector <const CGTownInstance*> & pool) const;
  62. int movementCost(const AdventureSpellCastParameters & parameters) const;
  63. std::vector <const CGTownInstance*> getPossibleTowns(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const;
  64. };
  65. class DLL_LINKAGE ViewMechanics : public AdventureSpellMechanics
  66. {
  67. public:
  68. ViewMechanics(const CSpell * s);
  69. protected:
  70. ESpellCastResult applyAdventureEffects(const SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const override;
  71. virtual bool filterObject(const CGObjectInstance * obj, const int spellLevel) const = 0;
  72. };
  73. class DLL_LINKAGE ViewAirMechanics : public ViewMechanics
  74. {
  75. public:
  76. ViewAirMechanics(const CSpell * s);
  77. protected:
  78. bool filterObject(const CGObjectInstance * obj, const int spellLevel) const override;
  79. };
  80. class DLL_LINKAGE ViewEarthMechanics : public ViewMechanics
  81. {
  82. public:
  83. ViewEarthMechanics(const CSpell * s);
  84. protected:
  85. bool filterObject(const CGObjectInstance * obj, const int spellLevel) const override;
  86. };