1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/lib/rewardable/Configuration.h

210 lines
5.5 KiB
C++
Raw Normal View History

2023-04-30 15:13:07 +02:00
/*
* 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"
2023-06-17 22:52:42 +02:00
#include "Reward.h"
#include "../networkPacks/EInfoWindowMode.h"
#include "../texts/MetaString.h"
2023-04-30 15:13:07 +02:00
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
2023-04-30 15:13:07 +02:00
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
2023-10-31 19:21:50 +02:00
SELECT_ALL // grant all rewards that match limiters
2023-04-30 15:13:07 +02:00
};
enum class EEventType
{
EVENT_INVALID = 0,
EVENT_FIRST_VISIT,
EVENT_ALREADY_VISITED,
EVENT_NOT_AVAILABLE,
EVENT_GUARDED
2023-04-30 15:13:07 +02:00
};
2024-03-09 12:02:43 +02:00
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"};
2023-04-30 15:13:07 +02:00
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;
2023-09-15 10:06:06 +02:00
void serializeJson(JsonSerializeFormat & handler);
template <typename Handler> void serialize(Handler &h)
2023-04-30 15:13:07 +02:00
{
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;
2023-04-30 15:13:07 +02:00
/// Event to which this reward is assigned
EEventType visitType;
2023-09-15 10:06:06 +02:00
void serializeJson(JsonSerializeFormat & handler);
2023-04-30 15:13:07 +02:00
template <typename Handler> void serialize(Handler &h)
2023-04-30 15:13:07 +02:00
{
h & limiter;
h & reward;
h & message;
h & description;
2023-04-30 15:13:07 +02:00
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;
}
};
2023-04-30 15:13:07 +02:00
/// 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;
2023-04-30 15:13:07 +02:00
/// 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
2023-04-30 15:13:07 +02:00
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;
2023-04-30 15:13:07 +02:00
/// 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;
2023-04-30 15:13:07 +02:00
/// 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);
2023-04-30 15:13:07 +02:00
2023-09-15 10:06:06 +02:00
void serializeJson(JsonSerializeFormat & handler);
template <typename Handler> void serialize(Handler &h)
2023-04-30 15:13:07 +02:00
{
h & onSelect;
h & description;
h & notVisitedTooltip;
h & visitedTooltip;
h & info;
2023-04-30 15:13:07 +02:00
h & selectMode;
h & visitMode;
h & resetParameters;
h & variables;
h & visitLimiter;
h & canRefuse;
h & showScoutedPreview;
2023-04-30 15:13:07 +02:00
h & infoWindowType;
if (h.version >= Handler::Version::REWARDABLE_BANKS)
{
h & coastVisitable;
h & guardsLayout;
}
else
coastVisitable = false;
2023-04-30 15:13:07 +02:00
}
};
}
VCMI_LIB_NAMESPACE_END