Configuration.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 "../networkPacks/EInfoWindowMode.h"
  14. #include "../texts/MetaString.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 matching 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. EVENT_GUARDED
  42. };
  43. constexpr std::array<std::string_view, 4> SelectModeString{"selectFirst", "selectPlayer", "selectRandom", "selectAll"};
  44. constexpr std::array<std::string_view, 6> VisitModeString{"unlimited", "once", "hero", "bonus", "limiter", "player"};
  45. struct DLL_LINKAGE ResetInfo
  46. {
  47. ResetInfo()
  48. : period(0)
  49. , visitors(false)
  50. , rewards(false)
  51. {}
  52. /// if above zero, object state will be reset each resetDuration days
  53. ui32 period;
  54. /// if true - reset list of visitors (heroes & players) on reset
  55. bool visitors;
  56. /// if true - re-randomize rewards on a new week
  57. bool rewards;
  58. void serializeJson(JsonSerializeFormat & handler);
  59. template <typename Handler> void serialize(Handler &h)
  60. {
  61. h & period;
  62. h & visitors;
  63. h & rewards;
  64. }
  65. };
  66. struct DLL_LINKAGE VisitInfo
  67. {
  68. Limiter limiter;
  69. Reward reward;
  70. /// Message that will be displayed on granting of this reward, if not empty
  71. MetaString message;
  72. /// Object description that will be shown on right-click, after object name
  73. /// Used only after player have "scouted" object and knows internal state of an object
  74. MetaString description;
  75. /// Event to which this reward is assigned
  76. EEventType visitType;
  77. void serializeJson(JsonSerializeFormat & handler);
  78. template <typename Handler> void serialize(Handler &h)
  79. {
  80. h & limiter;
  81. h & reward;
  82. h & message;
  83. h & description;
  84. h & visitType;
  85. }
  86. };
  87. struct DLL_LINKAGE Variables
  88. {
  89. /// List of variables used by this object in their current values
  90. std::map<std::string, int> values;
  91. /// List of per-instance preconfigured variables, e.g. from map
  92. std::map<std::string, JsonNode> preset;
  93. void serializeJson(JsonSerializeFormat & handler);
  94. template <typename Handler> void serialize(Handler &h)
  95. {
  96. h & values;
  97. h & preset;
  98. }
  99. };
  100. /// Base class that can handle granting rewards to visiting heroes.
  101. struct DLL_LINKAGE Configuration
  102. {
  103. /// Message that will be shown if player needs to select one of multiple rewards
  104. MetaString onSelect;
  105. /// Object description that will be shown on right-click, after object name
  106. /// Used only if player is not aware of object internal state, e.g. have never visited it
  107. MetaString description;
  108. /// Text that will be shown if hero has not visited this object
  109. MetaString notVisitedTooltip;
  110. /// Text that will be shown after hero has visited this object
  111. MetaString visitedTooltip;
  112. /// Rewards that can be applied by an object
  113. std::vector<Rewardable::VisitInfo> info;
  114. /// how reward will be selected, uses ESelectMode enum
  115. ui8 selectMode = Rewardable::SELECT_FIRST;
  116. /// controls who can visit an object, uses EVisitMode enum
  117. ui8 visitMode = Rewardable::VISIT_UNLIMITED;
  118. /// how and when should the object be reset
  119. Rewardable::ResetInfo resetParameters;
  120. /// List of variables shoread between all limiters and rewards
  121. Rewardable::Variables variables;
  122. /// Limiter that will be used to determine that object is visited. Only if visit mode is set to "limiter"
  123. Rewardable::Limiter visitLimiter;
  124. std::string guardsLayout;
  125. /// if true - player can refuse visiting an object (e.g. Tomb)
  126. bool canRefuse = false;
  127. /// if true - right-clicking object will show preview of object rewards
  128. bool showScoutedPreview = false;
  129. bool coastVisitable = false;
  130. /// if true - object info will shown in infobox (like resource pickup)
  131. EInfoWindowMode infoWindowType = EInfoWindowMode::AUTO;
  132. EVisitMode getVisitMode() const;
  133. ui16 getResetDuration() const;
  134. std::optional<int> getVariable(const std::string & category, const std::string & name) const;
  135. const JsonNode & getPresetVariable(const std::string & category, const std::string & name) const;
  136. void presetVariable(const std::string & category, const std::string & name, const JsonNode & value);
  137. void initVariable(const std::string & category, const std::string & name, int value);
  138. void serializeJson(JsonSerializeFormat & handler);
  139. template <typename Handler> void serialize(Handler &h)
  140. {
  141. h & onSelect;
  142. h & description;
  143. h & notVisitedTooltip;
  144. h & visitedTooltip;
  145. h & info;
  146. h & selectMode;
  147. h & visitMode;
  148. h & resetParameters;
  149. h & variables;
  150. h & visitLimiter;
  151. h & canRefuse;
  152. h & showScoutedPreview;
  153. h & infoWindowType;
  154. h & coastVisitable;
  155. h & guardsLayout;
  156. }
  157. };
  158. }
  159. VCMI_LIB_NAMESPACE_END