Configuration.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. VCMI_LIB_NAMESPACE_BEGIN
  14. namespace Rewardable
  15. {
  16. enum EVisitMode
  17. {
  18. VISIT_UNLIMITED, // any number of times. Side effect - object hover text won't contain visited/not visited text
  19. VISIT_ONCE, // only once, first to visit get all the rewards
  20. VISIT_HERO, // every hero can visit object once
  21. VISIT_BONUS, // can be visited by any hero that don't have bonus from this object
  22. VISIT_PLAYER // every player can visit object once
  23. };
  24. /// controls selection of reward granted to player
  25. enum ESelectMode
  26. {
  27. SELECT_FIRST, // first reward that matches limiters
  28. SELECT_PLAYER, // player can select from all allowed rewards
  29. SELECT_RANDOM, // one random reward from all mathing limiters
  30. };
  31. enum class EEventType
  32. {
  33. EVENT_INVALID = 0,
  34. EVENT_FIRST_VISIT,
  35. EVENT_ALREADY_VISITED,
  36. EVENT_NOT_AVAILABLE
  37. };
  38. const std::array<std::string, 3> SelectModeString{"selectFirst", "selectPlayer", "selectRandom"};
  39. const std::array<std::string, 5> VisitModeString{"unlimited", "once", "hero", "bonus", "player"};
  40. struct DLL_LINKAGE ResetInfo
  41. {
  42. ResetInfo()
  43. : period(0)
  44. , visitors(false)
  45. , rewards(false)
  46. {}
  47. /// if above zero, object state will be reset each resetDuration days
  48. ui32 period;
  49. /// if true - reset list of visitors (heroes & players) on reset
  50. bool visitors;
  51. /// if true - re-randomize rewards on a new week
  52. bool rewards;
  53. template <typename Handler> void serialize(Handler &h, const int version)
  54. {
  55. h & period;
  56. h & visitors;
  57. h & rewards;
  58. }
  59. };
  60. struct DLL_LINKAGE VisitInfo
  61. {
  62. Limiter limiter;
  63. Reward reward;
  64. /// Message that will be displayed on granting of this reward, if not empty
  65. MetaString message;
  66. /// Event to which this reward is assigned
  67. EEventType visitType;
  68. template <typename Handler> void serialize(Handler &h, const int version)
  69. {
  70. h & limiter;
  71. h & reward;
  72. h & message;
  73. h & visitType;
  74. }
  75. };
  76. /// Base class that can handle granting rewards to visiting heroes.
  77. struct DLL_LINKAGE Configuration
  78. {
  79. /// Message that will be shown if player needs to select one of multiple rewards
  80. MetaString onSelect;
  81. /// Rewards that can be applied by an object
  82. std::vector<Rewardable::VisitInfo> info;
  83. /// how reward will be selected, uses ESelectMode enum
  84. ui8 selectMode = Rewardable::SELECT_FIRST;
  85. /// contols who can visit an object, uses EVisitMode enum
  86. ui8 visitMode = Rewardable::VISIT_UNLIMITED;
  87. /// how and when should the object be reset
  88. Rewardable::ResetInfo resetParameters;
  89. /// if true - player can refuse visiting an object (e.g. Tomb)
  90. bool canRefuse = false;
  91. /// if true - object info will shown in infobox (like resource pickup)
  92. EInfoWindowMode infoWindowType = EInfoWindowMode::AUTO;
  93. EVisitMode getVisitMode() const;
  94. ui16 getResetDuration() const;
  95. template <typename Handler> void serialize(Handler &h, const int version)
  96. {
  97. h & info;
  98. h & canRefuse;
  99. h & resetParameters;
  100. h & onSelect;
  101. h & visitMode;
  102. h & selectMode;
  103. h & infoWindowType;
  104. }
  105. };
  106. }
  107. VCMI_LIB_NAMESPACE_END