1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/*
* Configuration.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "Limiter.h"
#include "Reward.h"
#include "../networkPacks/EInfoWindowMode.h"
#include "../texts/MetaString.h"
VCMI_LIB_NAMESPACE_BEGIN
namespace Rewardable
{
enum EVisitMode
{
VISIT_UNLIMITED, // any number of times. Side effect - object hover text won't contain visited/not visited text
VISIT_ONCE, // only once, first to visit get all the rewards
VISIT_HERO, // every hero can visit object once
VISIT_BONUS, // can be visited by any hero that don't have bonus from this object
VISIT_LIMITER, // can be visited by heroes that don't fulfill provided limiter
VISIT_PLAYER // every player can visit object once
};
/// controls selection of reward granted to player
enum ESelectMode
{
SELECT_FIRST, // first reward that matches limiters
SELECT_PLAYER, // player can select from all allowed rewards
SELECT_RANDOM, // one random reward from all matching limiters
SELECT_ALL // grant all rewards that match limiters
};
enum class EEventType
{
EVENT_INVALID = 0,
EVENT_FIRST_VISIT,
EVENT_ALREADY_VISITED,
EVENT_NOT_AVAILABLE,
EVENT_GUARDED
};
constexpr std::array<std::string_view, 4> SelectModeString{"selectFirst", "selectPlayer", "selectRandom", "selectAll"};
constexpr std::array<std::string_view, 6> VisitModeString{"unlimited", "once", "hero", "bonus", "limiter", "player"};
struct DLL_LINKAGE ResetInfo
{
ResetInfo()
: period(0)
, visitors(false)
, rewards(false)
{}
/// if above zero, object state will be reset each resetDuration days
ui32 period;
/// if true - reset list of visitors (heroes & players) on reset
bool visitors;
/// if true - re-randomize rewards on a new week
bool rewards;
void serializeJson(JsonSerializeFormat & handler);
template <typename Handler> void serialize(Handler &h)
{
h & period;
h & visitors;
h & rewards;
}
};
struct DLL_LINKAGE VisitInfo
{
Limiter limiter;
Reward reward;
/// Message that will be displayed on granting of this reward, if not empty
MetaString message;
/// Object description that will be shown on right-click, after object name
/// Used only after player have "scouted" object and knows internal state of an object
MetaString description;
/// Event to which this reward is assigned
EEventType visitType;
void serializeJson(JsonSerializeFormat & handler);
template <typename Handler> void serialize(Handler &h)
{
h & limiter;
h & reward;
h & message;
h & description;
h & visitType;
}
};
struct DLL_LINKAGE Variables
{
/// List of variables used by this object in their current values
std::map<std::string, int> values;
/// List of per-instance preconfigured variables, e.g. from map
std::map<std::string, JsonNode> preset;
void serializeJson(JsonSerializeFormat & handler);
template <typename Handler> void serialize(Handler &h)
{
h & values;
h & preset;
}
};
/// Base class that can handle granting rewards to visiting heroes.
struct DLL_LINKAGE Configuration
{
/// Message that will be shown if player needs to select one of multiple rewards
MetaString onSelect;
/// Object description that will be shown on right-click, after object name
/// Used only if player is not aware of object internal state, e.g. have never visited it
MetaString description;
/// Text that will be shown if hero has not visited this object
MetaString notVisitedTooltip;
/// Text that will be shown after hero has visited this object
MetaString visitedTooltip;
/// Rewards that can be applied by an object
std::vector<Rewardable::VisitInfo> info;
/// how reward will be selected, uses ESelectMode enum
ui8 selectMode = Rewardable::SELECT_FIRST;
/// controls who can visit an object, uses EVisitMode enum
ui8 visitMode = Rewardable::VISIT_UNLIMITED;
/// how and when should the object be reset
Rewardable::ResetInfo resetParameters;
/// List of variables shoread between all limiters and rewards
Rewardable::Variables variables;
/// Limiter that will be used to determine that object is visited. Only if visit mode is set to "limiter"
Rewardable::Limiter visitLimiter;
std::string guardsLayout;
/// if true - player can refuse visiting an object (e.g. Tomb)
bool canRefuse = false;
/// if true - right-clicking object will show preview of object rewards
bool showScoutedPreview = false;
bool coastVisitable = false;
/// if true - object info will shown in infobox (like resource pickup)
EInfoWindowMode infoWindowType = EInfoWindowMode::AUTO;
EVisitMode getVisitMode() const;
ui16 getResetDuration() const;
std::optional<int> getVariable(const std::string & category, const std::string & name) const;
const JsonNode & getPresetVariable(const std::string & category, const std::string & name) const;
void presetVariable(const std::string & category, const std::string & name, const JsonNode & value);
void initVariable(const std::string & category, const std::string & name, int value);
void serializeJson(JsonSerializeFormat & handler);
template <typename Handler> void serialize(Handler &h)
{
h & onSelect;
h & description;
h & notVisitedTooltip;
h & visitedTooltip;
h & info;
h & selectMode;
h & visitMode;
h & resetParameters;
h & variables;
h & visitLimiter;
h & canRefuse;
h & showScoutedPreview;
h & infoWindowType;
if (h.version >= Handler::Version::REWARDABLE_BANKS)
{
h & coastVisitable;
h & guardsLayout;
}
else
coastVisitable = false;
}
};
}
VCMI_LIB_NAMESPACE_END
|