Effect.h 2.1 KB

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