Configuration.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. };
  33. enum class EEventType
  34. {
  35. EVENT_INVALID = 0,
  36. EVENT_FIRST_VISIT,
  37. EVENT_ALREADY_VISITED,
  38. EVENT_NOT_AVAILABLE
  39. };
  40. const std::array<std::string, 3> SelectModeString{"selectFirst", "selectPlayer", "selectRandom"};
  41. const std::array<std::string, 5> VisitModeString{"unlimited", "once", "hero", "bonus", "player"};
  42. struct DLL_LINKAGE ResetInfo
  43. {
  44. ResetInfo()
  45. : period(0)
  46. , visitors(false)
  47. , rewards(false)
  48. {}
  49. /// if above zero, object state will be reset each resetDuration days
  50. ui32 period;
  51. /// if true - reset list of visitors (heroes & players) on reset
  52. bool visitors;
  53. /// if true - re-randomize rewards on a new week
  54. bool rewards;
  55. template <typename Handler> void serialize(Handler &h, const int version)
  56. {
  57. h & period;
  58. h & visitors;
  59. h & rewards;
  60. }
  61. };
  62. struct DLL_LINKAGE VisitInfo
  63. {
  64. Limiter limiter;
  65. Reward reward;
  66. /// Message that will be displayed on granting of this reward, if not empty
  67. MetaString message;
  68. /// Event to which this reward is assigned
  69. EEventType visitType;
  70. template <typename Handler> void serialize(Handler &h, const int version)
  71. {
  72. h & limiter;
  73. h & reward;
  74. h & message;
  75. h & visitType;
  76. }
  77. };
  78. /// Base class that can handle granting rewards to visiting heroes.
  79. struct DLL_LINKAGE Configuration
  80. {
  81. /// Message that will be shown if player needs to select one of multiple rewards
  82. MetaString onSelect;
  83. /// Rewards that can be applied by an object
  84. std::vector<Rewardable::VisitInfo> info;
  85. /// how reward will be selected, uses ESelectMode enum
  86. ui8 selectMode = Rewardable::SELECT_FIRST;
  87. /// contols who can visit an object, uses EVisitMode enum
  88. ui8 visitMode = Rewardable::VISIT_UNLIMITED;
  89. /// how and when should the object be reset
  90. Rewardable::ResetInfo resetParameters;
  91. /// if true - player can refuse visiting an object (e.g. Tomb)
  92. bool canRefuse = false;
  93. /// if true - object info will shown in infobox (like resource pickup)
  94. EInfoWindowMode infoWindowType = EInfoWindowMode::AUTO;
  95. EVisitMode getVisitMode() const;
  96. ui16 getResetDuration() const;
  97. template <typename Handler> void serialize(Handler &h, const int version)
  98. {
  99. h & info;
  100. h & canRefuse;
  101. h & resetParameters;
  102. h & onSelect;
  103. h & visitMode;
  104. h & selectMode;
  105. h & infoWindowType;
  106. }
  107. };
  108. }
  109. VCMI_LIB_NAMESPACE_END