Configuration.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. void serializeJson(JsonSerializeFormat & handler);
  61. template <typename Handler> void serialize(Handler &h)
  62. {
  63. h & period;
  64. h & visitors;
  65. h & rewards;
  66. }
  67. };
  68. struct DLL_LINKAGE VisitInfo
  69. {
  70. Limiter limiter;
  71. Reward reward;
  72. /// Message that will be displayed on granting of this reward, if not empty
  73. MetaString message;
  74. /// Object description that will be shown on right-click, after object name
  75. /// Used only after player have "scouted" object and knows internal state of an object
  76. MetaString description;
  77. /// Event to which this reward is assigned
  78. EEventType visitType;
  79. void serializeJson(JsonSerializeFormat & handler);
  80. template <typename Handler> void serialize(Handler &h)
  81. {
  82. h & limiter;
  83. h & reward;
  84. h & message;
  85. h & description;
  86. h & visitType;
  87. }
  88. };
  89. struct DLL_LINKAGE Variables
  90. {
  91. /// List of variables used by this object in their current values
  92. std::map<std::string, int> values;
  93. /// List of per-instance preconfigured variables, e.g. from map
  94. std::map<std::string, JsonNode> preset;
  95. void serializeJson(JsonSerializeFormat & handler);
  96. template <typename Handler> void serialize(Handler &h)
  97. {
  98. h & values;
  99. h & preset;
  100. }
  101. };
  102. /// Base class that can handle granting rewards to visiting heroes.
  103. struct DLL_LINKAGE Configuration
  104. {
  105. /// Message that will be shown if player needs to select one of multiple rewards
  106. MetaString onSelect;
  107. /// Object description that will be shown on right-click, after object name
  108. /// Used only if player is not aware of object internal state, e.g. have never visited it
  109. MetaString description;
  110. /// Text that will be shown if hero has not visited this object
  111. MetaString notVisitedTooltip;
  112. /// Text that will be shown after hero has visited this object
  113. MetaString visitedTooltip;
  114. /// Rewards that can be applied by an object
  115. std::vector<Rewardable::VisitInfo> info;
  116. /// how reward will be selected, uses ESelectMode enum
  117. ESelectMode selectMode = Rewardable::SELECT_FIRST;
  118. /// controls who can visit an object, uses EVisitMode enum
  119. EVisitMode visitMode = Rewardable::VISIT_UNLIMITED;
  120. /// how and when should the object be reset
  121. Rewardable::ResetInfo resetParameters;
  122. /// List of variables shoread between all limiters and rewards
  123. Rewardable::Variables variables;
  124. /// Limiter that will be used to determine that object is visited. Only if visit mode is set to "limiter"
  125. Rewardable::Limiter visitLimiter;
  126. std::string guardsLayout;
  127. /// if true - player can refuse visiting an object (e.g. Tomb)
  128. bool canRefuse = false;
  129. /// if set to true and object is guarded, then hero visit will immediately start combat without confirmation
  130. bool forceCombat = false;
  131. /// if true - right-clicking object will show preview of object rewards
  132. bool showScoutedPreview = false;
  133. bool coastVisitable = false;
  134. /// if true - object info will shown in infobox (like resource pickup)
  135. EInfoWindowMode infoWindowType = EInfoWindowMode::AUTO;
  136. EVisitMode getVisitMode() const;
  137. ui16 getResetDuration() const;
  138. std::optional<int> getVariable(const std::string & category, const std::string & name) const;
  139. const JsonNode & getPresetVariable(const std::string & category, const std::string & name) const;
  140. void presetVariable(const std::string & category, const std::string & name, const JsonNode & value);
  141. void initVariable(const std::string & category, const std::string & name, int value);
  142. void serializeJson(JsonSerializeFormat & handler);
  143. template <typename Handler> void serialize(Handler &h)
  144. {
  145. h & onSelect;
  146. h & description;
  147. h & notVisitedTooltip;
  148. h & visitedTooltip;
  149. h & info;
  150. h & selectMode;
  151. h & visitMode;
  152. h & resetParameters;
  153. h & variables;
  154. h & visitLimiter;
  155. h & canRefuse;
  156. if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS)
  157. h & forceCombat;
  158. h & showScoutedPreview;
  159. h & infoWindowType;
  160. h & coastVisitable;
  161. h & guardsLayout;
  162. }
  163. };
  164. }
  165. VCMI_LIB_NAMESPACE_END