Configuration.h 3.2 KB

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