AdventureSpellMechanics.h 3.7 KB

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