Configuration.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Configuration.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 "Limiter.h"
  12. #include "MetaString.h"
  13. #include "Reward.h"
  14. #include "../networkPacks/EInfoWindowMode.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. namespace Rewardable
  17. {
  18. enum EVisitMode
  19. {
  20. VISIT_UNLIMITED, // any number of times. Side effect - object hover text won't contain visited/not visited text
  21. VISIT_ONCE, // only once, first to visit get all the rewards
  22. VISIT_HERO, // every hero can visit object once
  23. VISIT_BONUS, // can be visited by any hero that don't have bonus from this object
  24. VISIT_LIMITER, // can be visited by heroes that don't fulfill provided limiter
  25. VISIT_PLAYER // every player can visit object once
  26. };
  27. /// controls selection of reward granted to player
  28. enum ESelectMode
  29. {
  30. SELECT_FIRST, // first reward that matches limiters
  31. SELECT_PLAYER, // player can select from all allowed rewards
  32. SELECT_RANDOM, // one random reward from all mathing limiters
  33. SELECT_ALL // grant all rewards that match limiters
  34. };
  35. enum class EEventType
  36. {
  37. EVENT_INVALID = 0,
  38. EVENT_FIRST_VISIT,
  39. EVENT_ALREADY_VISITED,
  40. EVENT_NOT_AVAILABLE
  41. };
  42. constexpr std::array<std::string_view, 4> SelectModeString{"selectFirst", "selectPlayer", "selectRandom", "selectAll"};
  43. constexpr std::array<std::string_view, 6> VisitModeString{"unlimited", "once", "hero", "bonus", "limiter", "player"};
  44. struct DLL_LINKAGE ResetInfo
  45. {
  46. ResetInfo()
  47. : period(0)
  48. , visitors(false)
  49. , rewards(false)
  50. {}
  51. /// if above zero, object state will be reset each resetDuration days
  52. ui32 period;
  53. /// if true - reset list of visitors (heroes & players) on reset
  54. bool visitors;
  55. /// if true - re-randomize rewards on a new week
  56. bool rewards;
  57. void serializeJson(JsonSerializeFormat & handler);
  58. template <typename Handler> void serialize(Handler &h)
  59. {
  60. h & period;
  61. h & visitors;
  62. h & rewards;
  63. }
  64. };
  65. struct DLL_LINKAGE VisitInfo
  66. {
  67. Limiter limiter;
  68. Reward reward;
  69. /// Message that will be displayed on granting of this reward, if not empty
  70. MetaString message;
  71. /// Object description that will be shown on right-click, after object name
  72. /// Used only after player have "scouted" object and knows internal state of an object
  73. MetaString description;
  74. /// Event to which this reward is assigned
  75. EEventType visitType;
  76. void serializeJson(JsonSerializeFormat & handler);
  77. template <typename Handler> void serialize(Handler &h)
  78. {
  79. h & limiter;
  80. h & reward;
  81. h & message;
  82. h & description;
  83. h & visitType;
  84. }
  85. };
  86. struct DLL_LINKAGE Variables
  87. {
  88. /// List of variables used by this object in their current values
  89. std::map<std::string, int> values;
  90. /// List of per-instance preconfigured variables, e.g. from map
  91. std::map<std::string, JsonNode> preset;
  92. void serializeJson(JsonSerializeFormat & handler);
  93. template <typename Handler> void serialize(Handler &h)
  94. {
  95. h & values;
  96. h & preset;
  97. }
  98. };
  99. /// Base class that can handle granting rewards to visiting heroes.
  100. struct DLL_LINKAGE Configuration
  101. {
  102. /// Message that will be shown if player needs to select one of multiple rewards
  103. MetaString onSelect;
  104. /// Object description that will be shown on right-click, after object name
  105. /// Used only if player is not aware of object internal state, e.g. have never visited it
  106. MetaString description;
  107. /// Text that will be shown if hero has not visited this object
  108. MetaString notVisitedTooltip;
  109. /// Text that will be shown after hero has visited this object
  110. MetaString visitedTooltip;
  111. /// Rewards that can be applied by an object
  112. std::vector<Rewardable::VisitInfo> info;
  113. /// how reward will be selected, uses ESelectMode enum
  114. ui8 selectMode = Rewardable::SELECT_FIRST;
  115. /// contols who can visit an object, uses EVisitMode enum
  116. ui8 visitMode = Rewardable::VISIT_UNLIMITED;
  117. /// how and when should the object be reset
  118. Rewardable::ResetInfo resetParameters;
  119. /// List of variables shoread between all limiters and rewards
  120. Rewardable::Variables variables;
  121. /// Limiter that will be used to determine that object is visited. Only if visit mode is set to "limiter"
  122. Rewardable::Limiter visitLimiter;
  123. /// if true - player can refuse visiting an object (e.g. Tomb)
  124. bool canRefuse = false;
  125. /// if true - right-clicking object will show preview of object rewards
  126. bool showScoutedPreview = false;
  127. /// if true - object info will shown in infobox (like resource pickup)
  128. EInfoWindowMode infoWindowType = EInfoWindowMode::AUTO;
  129. EVisitMode getVisitMode() const;
  130. ui16 getResetDuration() const;
  131. std::optional<int> getVariable(const std::string & category, const std::string & name) const;
  132. const JsonNode & getPresetVariable(const std::string & category, const std::string & name) const;
  133. void presetVariable(const std::string & category, const std::string & name, const JsonNode & value);
  134. void initVariable(const std::string & category, const std::string & name, int value);
  135. void serializeJson(JsonSerializeFormat & handler);
  136. template <typename Handler> void serialize(Handler &h)
  137. {
  138. h & onSelect;
  139. h & description;
  140. h & notVisitedTooltip;
  141. h & visitedTooltip;
  142. h & info;
  143. h & selectMode;
  144. h & visitMode;
  145. h & resetParameters;
  146. h & variables;
  147. h & visitLimiter;
  148. h & canRefuse;
  149. h & showScoutedPreview;
  150. h & infoWindowType;
  151. }
  152. };
  153. }
  154. VCMI_LIB_NAMESPACE_END