Configuration.h 5.3 KB

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