Configuration.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "NetPacksBase.h"
  14. #include "Reward.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_PLAYER // every player can visit object once
  25. };
  26. /// controls selection of reward granted to player
  27. enum ESelectMode
  28. {
  29. SELECT_FIRST, // first reward that matches limiters
  30. SELECT_PLAYER, // player can select from all allowed rewards
  31. SELECT_RANDOM, // one random reward from all mathing limiters
  32. SELECT_ALL, // provides all allowed rewards matching 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, 4> SelectModeString{"selectFirst", "selectPlayer", "selectRandom", "selectAll"};
  42. const std::array<std::string, 5> VisitModeString{"unlimited", "once", "hero", "bonus", "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. /// Event to which this reward is assigned
  71. EEventType visitType;
  72. void serializeJson(JsonSerializeFormat & handler);
  73. template <typename Handler> void serialize(Handler &h, const int version)
  74. {
  75. h & limiter;
  76. h & reward;
  77. h & message;
  78. h & visitType;
  79. }
  80. };
  81. /// Base class that can handle granting rewards to visiting heroes.
  82. struct DLL_LINKAGE Configuration
  83. {
  84. /// Message that will be shown if player needs to select one of multiple rewards
  85. MetaString onSelect;
  86. /// Rewards that can be applied by an object
  87. std::vector<Rewardable::VisitInfo> info;
  88. /// how reward will be selected, uses ESelectMode enum
  89. ui8 selectMode = Rewardable::SELECT_FIRST;
  90. /// contols who can visit an object, uses EVisitMode enum
  91. ui8 visitMode = Rewardable::VISIT_UNLIMITED;
  92. /// how and when should the object be reset
  93. Rewardable::ResetInfo resetParameters;
  94. /// if true - player can refuse visiting an object (e.g. Tomb)
  95. bool canRefuse = false;
  96. /// if true - object info will shown in infobox (like resource pickup)
  97. EInfoWindowMode infoWindowType = EInfoWindowMode::AUTO;
  98. EVisitMode getVisitMode() const;
  99. ui16 getResetDuration() const;
  100. void serializeJson(JsonSerializeFormat & handler);
  101. template <typename Handler> void serialize(Handler &h, const int version)
  102. {
  103. h & info;
  104. h & canRefuse;
  105. h & resetParameters;
  106. h & onSelect;
  107. h & visitMode;
  108. h & selectMode;
  109. h & infoWindowType;
  110. }
  111. };
  112. }
  113. VCMI_LIB_NAMESPACE_END