Effect.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Effect.cpp, 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. #include "StdInc.h"
  11. #include "Effect.h"
  12. #include "Registry.h"
  13. #include "../../serializer/JsonSerializeFormat.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. namespace spells
  16. {
  17. namespace effects
  18. {
  19. Effect::Effect()
  20. : indirect(false),
  21. optional(false)
  22. {
  23. }
  24. Effect::~Effect() = default;
  25. bool Effect::applicable(Problem & problem, const Mechanics * m) const
  26. {
  27. return true;
  28. }
  29. bool Effect::applicable(Problem & problem, const Mechanics * m, const EffectTarget & target) const
  30. {
  31. return true;
  32. }
  33. void Effect::serializeJson(JsonSerializeFormat & handler)
  34. {
  35. handler.serializeBool("indirect", indirect, false);
  36. handler.serializeBool("optional", optional, false);
  37. serializeJsonEffect(handler);
  38. }
  39. std::shared_ptr<Effect> Effect::create(const Registry * registry, const std::string & type)
  40. {
  41. auto factory = registry->find(type);
  42. if(factory)
  43. {
  44. std::shared_ptr<Effect> ret;
  45. ret.reset(factory->create());
  46. return ret;
  47. }
  48. else
  49. {
  50. logGlobal->error("Unknown effect type '%s'", type);
  51. return std::shared_ptr<Effect>();
  52. }
  53. }
  54. }
  55. }
  56. VCMI_LIB_NAMESPACE_END