2023-05-01 00:20:01 +02:00
|
|
|
/*
|
|
|
|
* BonusEnum.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "BonusEnum.h"
|
2024-02-11 23:09:01 +02:00
|
|
|
#include "../json/JsonUtils.h"
|
2023-05-05 23:45:09 +02:00
|
|
|
|
2023-05-01 00:20:01 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
#define BONUS_NAME(x) { #x, BonusType::x },
|
|
|
|
const std::map<std::string, BonusType> bonusNameMap = {
|
|
|
|
BONUS_LIST
|
|
|
|
};
|
|
|
|
#undef BONUS_NAME
|
|
|
|
|
|
|
|
#define BONUS_VALUE(x) { #x, BonusValueType::x },
|
|
|
|
const std::map<std::string, BonusValueType> bonusValueMap = { BONUS_VALUE_LIST };
|
|
|
|
#undef BONUS_VALUE
|
|
|
|
|
|
|
|
#define BONUS_SOURCE(x) { #x, BonusSource::x },
|
|
|
|
const std::map<std::string, BonusSource> bonusSourceMap = { BONUS_SOURCE_LIST };
|
|
|
|
#undef BONUS_SOURCE
|
|
|
|
|
|
|
|
#define BONUS_ITEM(x) { #x, BonusDuration::x },
|
2023-05-05 11:56:53 +02:00
|
|
|
const std::map<std::string, BonusDuration::Type> bonusDurationMap =
|
2023-05-01 00:20:01 +02:00
|
|
|
{
|
|
|
|
BONUS_ITEM(PERMANENT)
|
|
|
|
BONUS_ITEM(ONE_BATTLE)
|
|
|
|
BONUS_ITEM(ONE_DAY)
|
|
|
|
BONUS_ITEM(ONE_WEEK)
|
|
|
|
BONUS_ITEM(N_TURNS)
|
|
|
|
BONUS_ITEM(N_DAYS)
|
|
|
|
BONUS_ITEM(UNTIL_BEING_ATTACKED)
|
|
|
|
BONUS_ITEM(UNTIL_ATTACK)
|
|
|
|
BONUS_ITEM(STACK_GETS_TURN)
|
|
|
|
BONUS_ITEM(COMMANDER_KILLED)
|
2023-12-19 20:52:40 +02:00
|
|
|
BONUS_ITEM(UNTIL_OWN_ATTACK)
|
2024-06-24 03:23:26 +02:00
|
|
|
{ "UNTIL_BEING_ATTACKED", BonusDuration::UNTIL_BEING_ATTACKED }//typo, but used in some mods
|
2023-05-01 00:20:01 +02:00
|
|
|
};
|
|
|
|
#undef BONUS_ITEM
|
|
|
|
|
|
|
|
#define BONUS_ITEM(x) { #x, BonusLimitEffect::x },
|
|
|
|
const std::map<std::string, BonusLimitEffect> bonusLimitEffect =
|
|
|
|
{
|
|
|
|
BONUS_ITEM(NO_LIMIT)
|
|
|
|
BONUS_ITEM(ONLY_DISTANCE_FIGHT)
|
|
|
|
BONUS_ITEM(ONLY_MELEE_FIGHT)
|
|
|
|
};
|
|
|
|
#undef BONUS_ITEM
|
|
|
|
|
2023-05-05 11:56:53 +02:00
|
|
|
namespace BonusDuration
|
|
|
|
{
|
|
|
|
JsonNode toJson(const Type & duration)
|
|
|
|
{
|
|
|
|
std::vector<std::string> durationNames;
|
|
|
|
for(auto durBit = 0; durBit < duration.size(); durBit++)
|
|
|
|
{
|
|
|
|
if(duration[durBit])
|
|
|
|
durationNames.push_back(vstd::findKey(bonusDurationMap, duration & Type().set(durBit)));
|
|
|
|
}
|
|
|
|
if(durationNames.size() == 1)
|
|
|
|
{
|
2024-02-13 13:18:10 +02:00
|
|
|
return JsonNode(durationNames[0]);
|
2023-05-05 11:56:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-13 13:18:10 +02:00
|
|
|
JsonNode node;
|
2023-05-05 11:56:53 +02:00
|
|
|
for(const std::string & dur : durationNames)
|
2024-02-13 13:18:10 +02:00
|
|
|
node.Vector().emplace_back(dur);
|
2023-05-05 11:56:53 +02:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|