Limiter.h 4.4 KB

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