Limiter.h 3.0 KB

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