mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
(lib) Bonus subtype is now stored as metaidentifier that can store any
other identifier inside it
This commit is contained in:
@@ -134,29 +134,6 @@ std::string Bonus::Description(std::optional<si32> customValue) const
|
||||
return str.str();
|
||||
}
|
||||
|
||||
static JsonNode subtypeToJson(BonusType type, int subtype)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case BonusType::PRIMARY_SKILL:
|
||||
return JsonUtils::stringNode("primSkill." + NPrimarySkill::names[subtype]);
|
||||
case BonusType::SPECIAL_SPELL_LEV:
|
||||
case BonusType::SPECIFIC_SPELL_DAMAGE:
|
||||
case BonusType::SPELL:
|
||||
case BonusType::SPECIAL_PECULIAR_ENCHANT:
|
||||
case BonusType::SPECIAL_ADD_VALUE_ENCHANT:
|
||||
case BonusType::SPECIAL_FIXED_VALUE_ENCHANT:
|
||||
return JsonUtils::stringNode(ModUtility::makeFullIdentifier("", "spell", SpellID::encode(subtype)));
|
||||
case BonusType::IMPROVED_NECROMANCY:
|
||||
case BonusType::SPECIAL_UPGRADE:
|
||||
return JsonUtils::stringNode(ModUtility::makeFullIdentifier("", "creature", CreatureID::encode(subtype)));
|
||||
case BonusType::GENERATE_RESOURCE:
|
||||
return JsonUtils::stringNode("resource." + GameConstants::RESOURCE_NAMES[subtype]);
|
||||
default:
|
||||
return JsonUtils::intNode(subtype);
|
||||
}
|
||||
}
|
||||
|
||||
static JsonNode additionalInfoToJson(BonusType type, CAddInfo addInfo)
|
||||
{
|
||||
switch(type)
|
||||
@@ -173,8 +150,8 @@ JsonNode Bonus::toJsonNode() const
|
||||
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
|
||||
// only add values that might reasonably be found in config files
|
||||
root["type"].String() = vstd::findKey(bonusNameMap, type);
|
||||
if(subtype != -1)
|
||||
root["subtype"] = subtypeToJson(type, subtype);
|
||||
if(subtype != TBonusSubtype::NONE)
|
||||
root["subtype"].String() = subtype.toString();
|
||||
if(additionalInfo != CAddInfo::NONE)
|
||||
root["addInfo"] = additionalInfoToJson(type, additionalInfo);
|
||||
if(source != BonusSource::OTHER)
|
||||
@@ -206,7 +183,7 @@ JsonNode Bonus::toJsonNode() const
|
||||
return root;
|
||||
}
|
||||
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype):
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, TBonusSubtype Subtype, std::string Desc):
|
||||
duration(Duration),
|
||||
type(Type),
|
||||
subtype(Subtype),
|
||||
@@ -219,7 +196,7 @@ Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32
|
||||
targetSourceType = BonusSource::OTHER;
|
||||
}
|
||||
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype, BonusValueType ValType):
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, TBonusSubtype Subtype, BonusValueType ValType):
|
||||
duration(Duration),
|
||||
type(Type),
|
||||
subtype(Subtype),
|
||||
@@ -247,7 +224,7 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus)
|
||||
|
||||
#define printField(field) out << "\t" #field ": " << (int)bonus.field << "\n"
|
||||
printField(val);
|
||||
printField(subtype);
|
||||
out << "\tSubtype: " << bonus.subtype.toString() << "\n";
|
||||
printField(duration.to_ulong());
|
||||
printField(source);
|
||||
printField(sid);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "BonusEnum.h"
|
||||
#include "../constants/EntityIdentifiers.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@@ -22,13 +23,48 @@ class IUpdater;
|
||||
class BonusList;
|
||||
class CSelector;
|
||||
|
||||
using TBonusSubtype = int32_t;
|
||||
using TBonusSubtype = MetaIdentifier;
|
||||
using TBonusListPtr = std::shared_ptr<BonusList>;
|
||||
using TConstBonusListPtr = std::shared_ptr<const BonusList>;
|
||||
using TLimiterPtr = std::shared_ptr<ILimiter>;
|
||||
using TPropagatorPtr = std::shared_ptr<IPropagator>;
|
||||
using TUpdaterPtr = std::shared_ptr<IUpdater>;
|
||||
|
||||
namespace BonusSubtypes
|
||||
{
|
||||
|
||||
static const TBonusSubtype creatureDamageBoth; // 0
|
||||
static const TBonusSubtype creatureDamageMin; // 1
|
||||
static const TBonusSubtype creatureDamageMax; // 2
|
||||
|
||||
static const TBonusSubtype damageTypeAll; // -1
|
||||
static const TBonusSubtype damageTypeMelee; // 0
|
||||
static const TBonusSubtype damageTypeRanged; // 1
|
||||
|
||||
static const TBonusSubtype heroMovementLand; // 1
|
||||
static const TBonusSubtype heroMovementSea; // 0
|
||||
|
||||
static const TBonusSubtype heroMovementPenalty; // 2
|
||||
static const TBonusSubtype heroMovementFull; // 1
|
||||
|
||||
static const TBonusSubtype deathStareGorgon; // 0
|
||||
static const TBonusSubtype deathStareCommander;
|
||||
|
||||
static const TBonusSubtype rebirthRegular; // 0
|
||||
static const TBonusSubtype rebirthSpecial; // 1
|
||||
|
||||
static const TBonusSubtype visionsMonsters; // 0
|
||||
static const TBonusSubtype visionsHeroes; // 1
|
||||
static const TBonusSubtype visionsTowns; // 2
|
||||
|
||||
static const TBonusSubtype immunityBattleWide; // 0
|
||||
static const TBonusSubtype immunityEnemyHero; // 1
|
||||
|
||||
TBonusSubtype spellLevel(int level);
|
||||
TBonusSubtype creatureLevel(int level);
|
||||
|
||||
}
|
||||
|
||||
class DLL_LINKAGE CAddInfo : public std::vector<si32>
|
||||
{
|
||||
public:
|
||||
@@ -56,7 +92,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
||||
si16 turnsRemain = 0; //used if duration is N_TURNS, N_DAYS or ONE_WEEK
|
||||
|
||||
BonusType type = BonusType::NONE; //uses BonusType values - says to what is this bonus - 1 byte
|
||||
TBonusSubtype subtype = -1; //-1 if not applicable - 4 bytes
|
||||
TBonusSubtype subtype;
|
||||
|
||||
BonusSource source = BonusSource::OTHER; //source type" uses BonusSource values - what gave that bonus
|
||||
BonusSource targetSourceType;//Bonuses of what origin this amplifies, uses BonusSource values. Needed for PERCENT_TO_TARGET_TYPE.
|
||||
@@ -75,8 +111,11 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
||||
|
||||
std::string description;
|
||||
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype=-1, BonusValueType ValType = BonusValueType::ADDITIVE_VALUE);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 sourceID);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 sourceID, std::string Desc);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 sourceID, TBonusSubtype subtype);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 sourceID, TBonusSubtype subtype, std::string Desc);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 sourceID, TBonusSubtype subtype, BonusValueType ValType);
|
||||
Bonus() = default;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
|
||||
@@ -81,76 +81,76 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
|
||||
else if(deprecatedSubtype == SecondarySkill::SORCERY || deprecatedSubtypeStr == "skill.sorcery")
|
||||
{
|
||||
type = BonusType::SPELL_DAMAGE;
|
||||
subtype = SpellSchool(ESpellSchool::ANY);
|
||||
subtype = TBonusSubtype(ESpellSchool::ANY);
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::SCHOLAR || deprecatedSubtypeStr == "skill.scholar")
|
||||
type = BonusType::LEARN_MEETING_SPELL_LIMIT;
|
||||
else if(deprecatedSubtype == SecondarySkill::ARCHERY|| deprecatedSubtypeStr == "skill.archery")
|
||||
{
|
||||
subtype = 1;
|
||||
subtype = BonusSubtypes::damageTypeRanged;
|
||||
type = BonusType::PERCENTAGE_DAMAGE_BOOST;
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::OFFENCE || deprecatedSubtypeStr == "skill.offence")
|
||||
{
|
||||
subtype = 0;
|
||||
subtype = BonusSubtypes::damageTypeMelee;
|
||||
type = BonusType::PERCENTAGE_DAMAGE_BOOST;
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::ARMORER || deprecatedSubtypeStr == "skill.armorer")
|
||||
{
|
||||
subtype = -1;
|
||||
subtype = BonusSubtypes::damageTypeAll;
|
||||
type = BonusType::GENERAL_DAMAGE_REDUCTION;
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::NAVIGATION || deprecatedSubtypeStr == "skill.navigation")
|
||||
{
|
||||
subtype = 0;
|
||||
subtype = BonusSubtypes::heroMovementSea;
|
||||
valueType = BonusValueType::PERCENT_TO_BASE;
|
||||
type = BonusType::MOVEMENT;
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::LOGISTICS || deprecatedSubtypeStr == "skill.logistics")
|
||||
{
|
||||
subtype = 1;
|
||||
subtype = BonusSubtypes::heroMovementLand;
|
||||
valueType = BonusValueType::PERCENT_TO_BASE;
|
||||
type = BonusType::MOVEMENT;
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::ESTATES || deprecatedSubtypeStr == "skill.estates")
|
||||
{
|
||||
type = BonusType::GENERATE_RESOURCE;
|
||||
subtype = GameResID(EGameResID::GOLD);
|
||||
subtype = TBonusSubtype(GameResID(EGameResID::GOLD));
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::AIR_MAGIC || deprecatedSubtypeStr == "skill.airMagic")
|
||||
{
|
||||
type = BonusType::MAGIC_SCHOOL_SKILL;
|
||||
subtype = SpellSchool(ESpellSchool::AIR);
|
||||
subtype = TBonusSubtype(ESpellSchool::AIR);
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::WATER_MAGIC || deprecatedSubtypeStr == "skill.waterMagic")
|
||||
{
|
||||
type = BonusType::MAGIC_SCHOOL_SKILL;
|
||||
subtype = SpellSchool(ESpellSchool::WATER);
|
||||
subtype = TBonusSubtype(ESpellSchool::WATER);
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::FIRE_MAGIC || deprecatedSubtypeStr == "skill.fireMagic")
|
||||
{
|
||||
type = BonusType::MAGIC_SCHOOL_SKILL;
|
||||
subtype = SpellSchool(ESpellSchool::FIRE);
|
||||
subtype = TBonusSubtype(ESpellSchool::FIRE);
|
||||
}
|
||||
else if(deprecatedSubtype == SecondarySkill::EARTH_MAGIC || deprecatedSubtypeStr == "skill.earthMagic")
|
||||
{
|
||||
type = BonusType::MAGIC_SCHOOL_SKILL;
|
||||
subtype = SpellSchool(ESpellSchool::EARTH);
|
||||
subtype = TBonusSubtype(ESpellSchool::EARTH);
|
||||
}
|
||||
else if (deprecatedSubtype == SecondarySkill::ARTILLERY || deprecatedSubtypeStr == "skill.artillery")
|
||||
{
|
||||
type = BonusType::BONUS_DAMAGE_CHANCE;
|
||||
subtypeStr = "core:creature.ballista";
|
||||
subtype = TBonusSubtype(CreatureID(CreatureID::BALLISTA));
|
||||
}
|
||||
else if (deprecatedSubtype == SecondarySkill::FIRST_AID || deprecatedSubtypeStr == "skill.firstAid")
|
||||
{
|
||||
type = BonusType::SPECIFIC_SPELL_POWER;
|
||||
subtypeStr = "core:spell.firstAid";
|
||||
subtype = TBonusSubtype("spell", "firstAid");
|
||||
}
|
||||
else if (deprecatedSubtype == SecondarySkill::BALLISTICS || deprecatedSubtypeStr == "skill.ballistics")
|
||||
{
|
||||
type = BonusType::CATAPULT_EXTRA_SHOTS;
|
||||
subtypeStr = "core:spell.catapultShot";
|
||||
subtype = TBonusSubtype("spell", "catapultShot");
|
||||
}
|
||||
else
|
||||
isConverted = false;
|
||||
@@ -162,27 +162,27 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
|
||||
else if (deprecatedSubtype == SecondarySkill::ARTILLERY || deprecatedSubtypeStr == "skill.artillery")
|
||||
{
|
||||
type = BonusType::HERO_GRANTS_ATTACKS;
|
||||
subtypeStr = "core:creature.ballista";
|
||||
subtype = TBonusSubtype(CreatureID(CreatureID::BALLISTA));
|
||||
}
|
||||
else
|
||||
isConverted = false;
|
||||
}
|
||||
else if (deprecatedTypeStr == "SEA_MOVEMENT")
|
||||
{
|
||||
subtype = 0;
|
||||
subtype = BonusSubtypes::heroMovementSea;
|
||||
valueType = BonusValueType::ADDITIVE_VALUE;
|
||||
type = BonusType::MOVEMENT;
|
||||
}
|
||||
else if (deprecatedTypeStr == "LAND_MOVEMENT")
|
||||
{
|
||||
subtype = 1;
|
||||
subtype = BonusSubtypes::heroMovementLand;
|
||||
valueType = BonusValueType::ADDITIVE_VALUE;
|
||||
type = BonusType::MOVEMENT;
|
||||
}
|
||||
else if (deprecatedTypeStr == "MAXED_SPELL")
|
||||
{
|
||||
type = BonusType::SPELL;
|
||||
subtypeStr = deprecatedSubtypeStr;
|
||||
subtype = TBonusSubtype("spell", deprecatedSubtypeStr);
|
||||
valueType = BonusValueType::INDEPENDENT_MAX;
|
||||
val = 3;
|
||||
}
|
||||
@@ -223,52 +223,52 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
|
||||
else if (deprecatedTypeStr == "DIRECT_DAMAGE_IMMUNITY")
|
||||
{
|
||||
type = BonusType::SPELL_DAMAGE_REDUCTION;
|
||||
subtype = SpellSchool(ESpellSchool::ANY);
|
||||
subtype = MetaIdentifier(SpellSchool::ANY);
|
||||
val = 100;
|
||||
}
|
||||
else if (deprecatedTypeStr == "AIR_SPELL_DMG_PREMY")
|
||||
{
|
||||
type = BonusType::SPELL_DAMAGE;
|
||||
subtype = SpellSchool(ESpellSchool::AIR);
|
||||
subtype = MetaIdentifier(SpellSchool::AIR);
|
||||
}
|
||||
else if (deprecatedTypeStr == "FIRE_SPELL_DMG_PREMY")
|
||||
{
|
||||
type = BonusType::SPELL_DAMAGE;
|
||||
subtype = SpellSchool(ESpellSchool::FIRE);
|
||||
subtype = MetaIdentifier(SpellSchool::FIRE);
|
||||
}
|
||||
else if (deprecatedTypeStr == "WATER_SPELL_DMG_PREMY")
|
||||
{
|
||||
type = BonusType::SPELL_DAMAGE;
|
||||
subtype = SpellSchool(ESpellSchool::WATER);
|
||||
subtype = MetaIdentifier(SpellSchool::WATER);
|
||||
}
|
||||
else if (deprecatedTypeStr == "EARTH_SPELL_DMG_PREMY")
|
||||
{
|
||||
type = BonusType::SPELL_DAMAGE;
|
||||
subtype = SpellSchool(ESpellSchool::EARTH);
|
||||
subtype = MetaIdentifier(SpellSchool::EARTH);
|
||||
}
|
||||
else if (deprecatedTypeStr == "AIR_SPELLS")
|
||||
{
|
||||
type = BonusType::SPELLS_OF_SCHOOL;
|
||||
subtype = SpellSchool(ESpellSchool::AIR);
|
||||
subtype = MetaIdentifier(SpellSchool::AIR);
|
||||
}
|
||||
else if (deprecatedTypeStr == "FIRE_SPELLS")
|
||||
{
|
||||
type = BonusType::SPELLS_OF_SCHOOL;
|
||||
subtype = SpellSchool(ESpellSchool::FIRE);
|
||||
subtype = MetaIdentifier(SpellSchool::FIRE);
|
||||
}
|
||||
else if (deprecatedTypeStr == "WATER_SPELLS")
|
||||
{
|
||||
type = BonusType::SPELLS_OF_SCHOOL;
|
||||
subtype = SpellSchool(ESpellSchool::WATER);
|
||||
subtype = MetaIdentifier(SpellSchool::WATER);
|
||||
}
|
||||
else if (deprecatedTypeStr == "EARTH_SPELLS")
|
||||
{
|
||||
type = BonusType::SPELLS_OF_SCHOOL;
|
||||
subtype = SpellSchool(ESpellSchool::EARTH);
|
||||
subtype = MetaIdentifier(SpellSchool::EARTH);
|
||||
}
|
||||
else if (deprecatedTypeStr == "AIR_IMMUNITY")
|
||||
{
|
||||
subtype = SpellSchool(ESpellSchool::AIR);
|
||||
subtype = MetaIdentifier(SpellSchool::AIR);
|
||||
switch(deprecatedSubtype)
|
||||
{
|
||||
case 0:
|
||||
@@ -284,7 +284,7 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
|
||||
}
|
||||
else if (deprecatedTypeStr == "FIRE_IMMUNITY")
|
||||
{
|
||||
subtype = SpellSchool(ESpellSchool::FIRE);
|
||||
subtype = MetaIdentifier(SpellSchool::FIRE);
|
||||
switch(deprecatedSubtype)
|
||||
{
|
||||
case 0:
|
||||
@@ -300,7 +300,7 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
|
||||
}
|
||||
else if (deprecatedTypeStr == "WATER_IMMUNITY")
|
||||
{
|
||||
subtype = SpellSchool(ESpellSchool::WATER);
|
||||
subtype = MetaIdentifier(SpellSchool::WATER);
|
||||
switch(deprecatedSubtype)
|
||||
{
|
||||
case 0:
|
||||
@@ -316,7 +316,7 @@ BonusParams::BonusParams(std::string deprecatedTypeStr, std::string deprecatedSu
|
||||
}
|
||||
else if (deprecatedTypeStr == "EARTH_IMMUNITY")
|
||||
{
|
||||
subtype = SpellSchool(ESpellSchool::EARTH);
|
||||
subtype = MetaIdentifier(SpellSchool::EARTH);
|
||||
switch(deprecatedSubtype)
|
||||
{
|
||||
case 0:
|
||||
@@ -340,10 +340,8 @@ const JsonNode & BonusParams::toJson()
|
||||
if(ret.isNull())
|
||||
{
|
||||
ret["type"].String() = vstd::findKey(bonusNameMap, type);
|
||||
if(subtypeStr)
|
||||
ret["subtype"].String() = *subtypeStr;
|
||||
else if(subtype)
|
||||
ret["subtype"].Integer() = *subtype;
|
||||
if(subtype)
|
||||
ret["subtype"].String() = subtype->toString();
|
||||
if(valueType)
|
||||
ret["valueType"].String() = vstd::findKey(bonusValueMap, *valueType);
|
||||
if(val)
|
||||
@@ -358,11 +356,6 @@ const JsonNode & BonusParams::toJson()
|
||||
CSelector BonusParams::toSelector()
|
||||
{
|
||||
assert(isConverted);
|
||||
if(subtypeStr)
|
||||
{
|
||||
subtype = -1;
|
||||
JsonUtils::resolveIdentifier(*subtype, toJson(), "subtype");
|
||||
}
|
||||
|
||||
auto ret = Selector::type()(type);
|
||||
if(subtype)
|
||||
@@ -374,4 +367,4 @@ CSelector BonusParams::toSelector()
|
||||
return ret;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -20,7 +20,6 @@ struct DLL_LINKAGE BonusParams {
|
||||
bool isConverted;
|
||||
BonusType type = BonusType::NONE;
|
||||
std::optional<TBonusSubtype> subtype = std::nullopt;
|
||||
std::optional<std::string> subtypeStr = std::nullopt;
|
||||
std::optional<BonusValueType> valueType = std::nullopt;
|
||||
std::optional<si32> val = std::nullopt;
|
||||
std::optional<BonusSource> targetType = std::nullopt;
|
||||
@@ -36,4 +35,4 @@ private:
|
||||
|
||||
extern DLL_LINKAGE const std::set<std::string> deprecatedBonusSet;
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -62,20 +62,20 @@ bool IBonusBearer::hasBonusOfType(BonusType type) const
|
||||
return hasBonus(s, cachingStr);
|
||||
}
|
||||
|
||||
int IBonusBearer::valOfBonuses(BonusType type, int subtype) const
|
||||
int IBonusBearer::valOfBonuses(BonusType type, TBonusSubtype subtype) const
|
||||
{
|
||||
//This part is performance-critical
|
||||
std::string cachingStr = "type_" + std::to_string(static_cast<int>(type)) + "_" + std::to_string(subtype);
|
||||
std::string cachingStr = "type_" + std::to_string(static_cast<int>(type)) + "_" + subtype.toString();
|
||||
|
||||
CSelector s = Selector::typeSubtype(type, subtype);
|
||||
|
||||
return valOfBonuses(s, cachingStr);
|
||||
}
|
||||
|
||||
bool IBonusBearer::hasBonusOfType(BonusType type, int subtype) const
|
||||
bool IBonusBearer::hasBonusOfType(BonusType type, TBonusSubtype subtype) const
|
||||
{
|
||||
//This part is performance-critical
|
||||
std::string cachingStr = "type_" + std::to_string(static_cast<int>(type)) + "_" + std::to_string(subtype);
|
||||
std::string cachingStr = "type_" + std::to_string(static_cast<int>(type)) + "_" + subtype.toString();
|
||||
|
||||
CSelector s = Selector::typeSubtype(type, subtype);
|
||||
|
||||
@@ -95,4 +95,4 @@ std::shared_ptr<const Bonus> IBonusBearer::getBonus(const CSelector &selector) c
|
||||
return bonuses->getFirst(Selector::all);
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -35,11 +35,11 @@ public:
|
||||
//Optimized interface (with auto-caching)
|
||||
int valOfBonuses(BonusType type) const; //subtype -> subtype of bonus;
|
||||
bool hasBonusOfType(BonusType type) const;//determines if hero has a bonus of given type (and optionally subtype)
|
||||
int valOfBonuses(BonusType type, int subtype) const; //subtype -> subtype of bonus;
|
||||
bool hasBonusOfType(BonusType type, int subtype) const;//determines if hero has a bonus of given type (and optionally subtype)
|
||||
int valOfBonuses(BonusType type, TBonusSubtype subtype) const; //subtype -> subtype of bonus;
|
||||
bool hasBonusOfType(BonusType type, TBonusSubtype subtype) const;//determines if hero has a bonus of given type (and optionally subtype)
|
||||
bool hasBonusFrom(BonusSource source, ui32 sourceID) const;
|
||||
|
||||
virtual int64_t getTreeVersion() const = 0;
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -136,7 +136,7 @@ JsonNode CCreatureTypeLimiter::toJsonNode() const
|
||||
}
|
||||
|
||||
HasAnotherBonusLimiter::HasAnotherBonusLimiter( BonusType bonus )
|
||||
: type(bonus), subtype(0), isSubtypeRelevant(false), isSourceRelevant(false), isSourceIDRelevant(false)
|
||||
: type(bonus), isSubtypeRelevant(false), isSourceRelevant(false), isSourceIDRelevant(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -184,8 +184,8 @@ std::string HasAnotherBonusLimiter::toString() const
|
||||
std::string typeName = vstd::findKey(bonusNameMap, type);
|
||||
if(isSubtypeRelevant)
|
||||
{
|
||||
boost::format fmt("HasAnotherBonusLimiter(type=%s, subtype=%d)");
|
||||
fmt % typeName % subtype;
|
||||
boost::format fmt("HasAnotherBonusLimiter(type=%s, subtype=%s)");
|
||||
fmt % typeName % subtype.toString();
|
||||
return fmt.str();
|
||||
}
|
||||
else
|
||||
@@ -205,7 +205,7 @@ JsonNode HasAnotherBonusLimiter::toJsonNode() const
|
||||
root["type"].String() = "HAS_ANOTHER_BONUS_LIMITER";
|
||||
root["parameters"].Vector().push_back(JsonUtils::stringNode(typeName));
|
||||
if(isSubtypeRelevant)
|
||||
root["parameters"].Vector().push_back(JsonUtils::intNode(subtype));
|
||||
root["parameters"].Vector().push_back(JsonUtils::stringNode(subtype.toString()));
|
||||
if(isSourceRelevant)
|
||||
root["parameters"].Vector().push_back(JsonUtils::stringNode(sourceTypeName));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user