Limiter.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. /// Hero has creatures other than those requested in 'creatures' field
  41. /// In other words, it is possible to take requested creatures from hero
  42. bool hasExtraCreatures;
  43. /// resources player needs to have in order to trigger reward
  44. TResources resources;
  45. /// skills hero needs to have
  46. std::vector<si32> primary;
  47. std::map<SecondarySkill, si32> secondary;
  48. /// artifacts that hero needs to have (equipped or in backpack) to trigger this
  49. /// checks for artifacts copies if same artifact id is included multiple times
  50. std::vector<ArtifactID> artifacts;
  51. /// artifact slots that hero needs to have available (not locked and without any artifact) to pass the limiter
  52. std::vector<ArtifactPosition> availableSlots;
  53. /// Spell scrolls that hero must have in inventory (equipped or in backpack)
  54. std::vector<SpellID> scrolls;
  55. /// Spells that hero must have in the spellbook
  56. std::vector<SpellID> spells;
  57. /// Spells that hero must be able to learn
  58. std::vector<SpellID> canLearnSpells;
  59. /// creatures that hero needs to have
  60. std::vector<CStackBasicDescriptor> creatures;
  61. /// creatures that hero needs to have
  62. std::vector<CStackBasicDescriptor> canReceiveCreatures;
  63. /// only heroes/hero classes from list could pass limiter
  64. std::vector<HeroTypeID> heroes;
  65. std::vector<HeroClassID> heroClasses;
  66. /// only player colors can pass limiter
  67. std::vector<PlayerColor> players;
  68. /// sub-limiters, all must pass for this limiter to pass
  69. LimitersList allOf;
  70. /// sub-limiters, at least one should pass for this limiter to pass
  71. LimitersList anyOf;
  72. /// sub-limiters, none should pass for this limiter to pass
  73. LimitersList noneOf;
  74. Limiter();
  75. ~Limiter();
  76. bool heroAllowed(const CGHeroInstance * hero) const;
  77. /// Generates list of components that describes reward for a specific hero
  78. void loadComponents(std::vector<Component> & comps,
  79. const CGHeroInstance * h) const;
  80. template <typename Handler> void serialize(Handler &h)
  81. {
  82. h & dayOfWeek;
  83. h & daysPassed;
  84. h & heroExperience;
  85. h & heroLevel;
  86. h & manaPoints;
  87. h & manaPercentage;
  88. h & canLearnSkills;
  89. if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS)
  90. {
  91. h & commanderAlive;
  92. h & hasExtraCreatures;
  93. }
  94. h & resources;
  95. h & primary;
  96. h & secondary;
  97. h & artifacts;
  98. if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS)
  99. {
  100. h & availableSlots;
  101. h & scrolls;
  102. }
  103. h & spells;
  104. h & canLearnSpells;
  105. h & creatures;
  106. if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS)
  107. {
  108. h & canReceiveCreatures;
  109. }
  110. h & heroes;
  111. h & heroClasses;
  112. h & players;
  113. h & allOf;
  114. h & anyOf;
  115. h & noneOf;
  116. }
  117. void serializeJson(JsonSerializeFormat & handler);
  118. };
  119. }
  120. bool DLL_LINKAGE operator== (const Rewardable::Limiter & l, const Rewardable::Limiter & r);
  121. bool DLL_LINKAGE operator!= (const Rewardable::Limiter & l, const Rewardable::Limiter & r);
  122. VCMI_LIB_NAMESPACE_END