Limiter.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Limiter.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 "../GameConstants.h"
  12. #include "../ResourceSet.h"
  13. #include "../serializer/Serializeable.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGHeroInstance;
  16. class CStackBasicDescriptor;
  17. struct Component;
  18. namespace Rewardable {
  19. struct Limiter;
  20. using LimitersList = std::vector<std::shared_ptr<Rewardable::Limiter>>;
  21. /// Limiters of rewards. Rewards will be granted to hero only if he satisfies requirements
  22. /// Note: for this is only a test - it won't remove anything from hero (e.g. artifacts or creatures)
  23. struct DLL_LINKAGE Limiter final : public Serializeable
  24. {
  25. /// day of week, unused if 0, 1-7 will test for current day of week
  26. si32 dayOfWeek;
  27. si32 daysPassed;
  28. /// total experience that hero needs to have
  29. si32 heroExperience;
  30. /// level that hero needs to have
  31. si32 heroLevel;
  32. /// mana points that hero needs to have
  33. si32 manaPoints;
  34. /// percentage of mana points that hero needs to have
  35. si32 manaPercentage;
  36. /// Number of free secondary slots that hero needs to have
  37. bool canLearnSkills;
  38. /// Hero has commander, and commander is currently alive
  39. bool commanderAlive;
  40. /// resources player needs to have in order to trigger reward
  41. TResources resources;
  42. /// skills hero needs to have
  43. std::vector<si32> primary;
  44. std::map<SecondarySkill, si32> secondary;
  45. /// artifacts that hero needs to have (equipped or in backpack) to trigger this
  46. /// checks for artifacts copies if same artifact id is included multiple times
  47. std::vector<ArtifactID> artifacts;
  48. /// artifact slots that hero needs to have available (not locked and without any artifact) to pass the limiter
  49. std::vector<ArtifactPosition> availableSlots;
  50. /// Spell scrolls that hero must have in inventory (equipped or in backpack)
  51. std::vector<SpellID> scrolls;
  52. /// Spells that hero must have in the spellbook
  53. std::vector<SpellID> spells;
  54. /// Spells that hero must be able to learn
  55. std::vector<SpellID> canLearnSpells;
  56. /// creatures that hero needs to have
  57. std::vector<CStackBasicDescriptor> creatures;
  58. /// creatures that hero needs to have
  59. std::vector<CStackBasicDescriptor> canLoseCreatures;
  60. /// creatures that hero needs to have
  61. std::vector<CStackBasicDescriptor> canReceiveCreatures;
  62. /// only heroes/hero classes from list could pass limiter
  63. std::vector<HeroTypeID> heroes;
  64. std::vector<HeroClassID> heroClasses;
  65. /// only player colors can pass limiter
  66. std::vector<PlayerColor> players;
  67. /// sub-limiters, all must pass for this limiter to pass
  68. LimitersList allOf;
  69. /// sub-limiters, at least one should pass for this limiter to pass
  70. LimitersList anyOf;
  71. /// sub-limiters, none should pass for this limiter to pass
  72. LimitersList noneOf;
  73. Limiter();
  74. ~Limiter();
  75. bool heroAllowed(const CGHeroInstance * hero) const;
  76. /// Generates list of components that describes reward for a specific hero
  77. void loadComponents(std::vector<Component> & comps,
  78. const CGHeroInstance * h) const;
  79. template <typename Handler> void serialize(Handler &h)
  80. {
  81. h & dayOfWeek;
  82. h & daysPassed;
  83. h & heroExperience;
  84. h & heroLevel;
  85. h & manaPoints;
  86. h & manaPercentage;
  87. h & canLearnSkills;
  88. if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS)
  89. h & commanderAlive;
  90. h & resources;
  91. h & primary;
  92. h & secondary;
  93. h & artifacts;
  94. if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS)
  95. {
  96. h & availableSlots;
  97. h & scrolls;
  98. }
  99. h & spells;
  100. h & canLearnSpells;
  101. h & creatures;
  102. h & heroes;
  103. h & heroClasses;
  104. h & players;
  105. h & allOf;
  106. h & anyOf;
  107. h & noneOf;
  108. }
  109. void serializeJson(JsonSerializeFormat & handler);
  110. };
  111. }
  112. bool DLL_LINKAGE operator== (const Rewardable::Limiter & l, const Rewardable::Limiter & r);
  113. bool DLL_LINKAGE operator!= (const Rewardable::Limiter & l, const Rewardable::Limiter & r);
  114. VCMI_LIB_NAMESPACE_END