UnitEffect.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * UnitEffect.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 "Effect.h"
  12. #include "lib/constants/EntityIdentifiers.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. namespace spells
  15. {
  16. namespace effects
  17. {
  18. struct SpellEffectValue
  19. {
  20. int64_t hpDelta = 0; // positive -> healed health points, negative -> damage
  21. int64_t unitsDelta = 0; // positive -> resurrected / summoned (demons) / animated (undeads), negative -> kills
  22. CreatureID unitType = CreatureID::NONE; // type of creatures summoned / resurrected / animated / etc.
  23. SpellEffectValue & operator+=(const SpellEffectValue & rhs) noexcept
  24. {
  25. hpDelta += rhs.hpDelta;
  26. unitsDelta += rhs.unitsDelta;
  27. if(unitType == CreatureID::NONE)
  28. unitType = rhs.unitType;
  29. return *this;
  30. }
  31. };
  32. class UnitEffect : public Effect
  33. {
  34. public:
  35. void adjustTargetTypes(std::vector<TargetType> & types) const override;
  36. void adjustAffectedHexes(BattleHexArray & hexes, const Mechanics * m, const Target & spellTarget) const override;
  37. bool applicable(Problem & problem, const Mechanics * m) const override;
  38. bool applicable(Problem & problem, const Mechanics * m, const EffectTarget & target) const override;
  39. EffectTarget filterTarget(const Mechanics * m, const EffectTarget & target) const override;
  40. EffectTarget transformTarget(const Mechanics * m, const Target & aimPoint, const Target & spellTarget) const override;
  41. bool getStackFilter(const Mechanics * m, bool alwaysSmart, const battle::Unit * s) const;
  42. virtual bool eraseByImmunityFilter(const Mechanics * m, const battle::Unit * s) const;
  43. virtual SpellEffectValue getHealthChange(const Mechanics * m, const EffectTarget & spellTarget) const;
  44. protected:
  45. int32_t chainLength = 0;
  46. double chainFactor = 0.0;
  47. virtual bool isReceptive(const Mechanics * m, const battle::Unit * unit) const;
  48. virtual bool isSmartTarget(const Mechanics * m, const battle::Unit * unit, bool alwaysSmart) const;
  49. virtual bool isValidTarget(const Mechanics * m, const battle::Unit * unit) const;
  50. void serializeJsonEffect(JsonSerializeFormat & handler) override final;
  51. virtual void serializeJsonUnitEffect(JsonSerializeFormat & handler) = 0;
  52. private:
  53. bool ignoreImmunity = false;
  54. EffectTarget transformTargetByRange(const Mechanics * m, const Target & aimPoint, const Target & spellTarget) const;
  55. EffectTarget transformTargetByChain(const Mechanics * m, const Target & aimPoint, const Target & spellTarget) const;
  56. };
  57. }
  58. }
  59. VCMI_LIB_NAMESPACE_END