Configuration.h 6.1 KB

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