Effect.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Effect.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 <vcmi/spells/Magic.h>
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. struct BattleHex;
  14. class CBattleInfoCallback;
  15. class JsonSerializeFormat;
  16. class ServerCallback;
  17. namespace vstd
  18. {
  19. class RNG;
  20. }
  21. namespace spells
  22. {
  23. using EffectTarget = Target;
  24. namespace effects
  25. {
  26. using RNG = vstd::RNG;
  27. class Effects;
  28. class Effect;
  29. class Registry;
  30. template<typename F>
  31. class RegisterEffect;
  32. using TargetType = spells::AimType;
  33. class DLL_LINKAGE Effect
  34. {
  35. public:
  36. bool indirect = false;
  37. bool optional = false;
  38. std::string name;
  39. virtual ~Effect() = default; //Required for child classes
  40. // TODO: document me
  41. virtual void adjustTargetTypes(std::vector<TargetType> & types) const = 0;
  42. /// Generates list of hexes affected by spell, if spell were to cast at specified target
  43. virtual void adjustAffectedHexes(std::set<BattleHex> & hexes, const Mechanics * m, const Target & spellTarget) const = 0;
  44. /// Returns whether effect has any valid targets on the battlefield
  45. virtual bool applicable(Problem & problem, const Mechanics * m) const;
  46. /// Returns whether effect is valid and can be applied onto selected target
  47. virtual bool applicable(Problem & problem, const Mechanics * m, const EffectTarget & target) const;
  48. virtual void apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const = 0;
  49. /// Processes input target and generates subset-result that contains only valid targets
  50. virtual EffectTarget filterTarget(const Mechanics * m, const EffectTarget & target) const = 0;
  51. // TODO: document me
  52. virtual EffectTarget transformTarget(const Mechanics * m, const Target & aimPoint, const Target & spellTarget) const = 0;
  53. /// Serializes (or deserializes) parameters of Effect
  54. void serializeJson(JsonSerializeFormat & handler);
  55. static std::shared_ptr<Effect> create(const Registry * registry, const std::string & type);
  56. protected:
  57. virtual void serializeJsonEffect(JsonSerializeFormat & handler) = 0;
  58. };
  59. }
  60. }
  61. VCMI_LIB_NAMESPACE_END