mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Bonus Source ID now uses metaidentifier
This commit is contained in:
@@ -100,19 +100,19 @@ std::string Bonus::Description(std::optional<si32> customValue) const
|
||||
switch(source)
|
||||
{
|
||||
case BonusSource::ARTIFACT:
|
||||
str << ArtifactID(sid).toArtifact(VLC->artifacts())->getNameTranslated();
|
||||
str << sid.as<ArtifactID>().toArtifact(VLC->artifacts())->getNameTranslated();
|
||||
break;
|
||||
case BonusSource::SPELL_EFFECT:
|
||||
str << SpellID(sid).toSpell(VLC->spells())->getNameTranslated();
|
||||
str << sid.as<SpellID>().toSpell(VLC->spells())->getNameTranslated();
|
||||
break;
|
||||
case BonusSource::CREATURE_ABILITY:
|
||||
str << CreatureID(sid).toCreature(VLC->creatures())->getNamePluralTranslated();
|
||||
str << sid.as<CreatureID>().toCreature(VLC->creatures())->getNamePluralTranslated();
|
||||
break;
|
||||
case BonusSource::SECONDARY_SKILL:
|
||||
str << VLC->skills()->getByIndex(sid)->getNameTranslated();
|
||||
str << VLC->skills()->getById(sid.as<SecondarySkill>())->getNameTranslated();
|
||||
break;
|
||||
case BonusSource::HERO_SPECIAL:
|
||||
str << VLC->heroTypes()->getByIndex(sid)->getNameTranslated();
|
||||
str << VLC->heroTypes()->getById(sid.as<HeroTypeID>())->getNameTranslated();
|
||||
break;
|
||||
default:
|
||||
//todo: handle all possible sources
|
||||
@@ -158,8 +158,8 @@ JsonNode Bonus::toJsonNode() const
|
||||
root["sourceType"].String() = vstd::findKey(bonusSourceMap, source);
|
||||
if(targetSourceType != BonusSource::OTHER)
|
||||
root["targetSourceType"].String() = vstd::findKey(bonusSourceMap, targetSourceType);
|
||||
if(sid != 0)
|
||||
root["sourceID"].Integer() = sid;
|
||||
if(sid != TBonusSourceID::NONE)
|
||||
root["sourceID"].String() = sid.toString();
|
||||
if(val != 0)
|
||||
root["val"].Integer() = val;
|
||||
if(valType != BonusValueType::ADDITIVE_VALUE)
|
||||
@@ -183,19 +183,19 @@ JsonNode Bonus::toJsonNode() const
|
||||
return root;
|
||||
}
|
||||
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID)
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID)
|
||||
: Bonus(Duration, Type, Src, Val, ID, TBonusSubtype::NONE, std::string())
|
||||
{}
|
||||
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc)
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID, std::string Desc)
|
||||
: Bonus(Duration, Type, Src, Val, ID, TBonusSubtype::NONE, Desc)
|
||||
{}
|
||||
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, TBonusSubtype Subtype)
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID, TBonusSubtype Subtype)
|
||||
: Bonus(Duration, Type, Src, Val, ID, Subtype, std::string())
|
||||
{}
|
||||
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, TBonusSubtype Subtype, std::string Desc):
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID, TBonusSubtype Subtype, std::string Desc):
|
||||
duration(Duration),
|
||||
type(Type),
|
||||
subtype(Subtype),
|
||||
@@ -208,7 +208,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, TBonusSubtype Subtype, BonusValueType ValType):
|
||||
Bonus::Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID ID, TBonusSubtype Subtype, BonusValueType ValType):
|
||||
duration(Duration),
|
||||
type(Type),
|
||||
subtype(Subtype),
|
||||
@@ -239,7 +239,7 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus)
|
||||
out << "\tSubtype: " << bonus.subtype.toString() << "\n";
|
||||
printField(duration.to_ulong());
|
||||
printField(source);
|
||||
printField(sid);
|
||||
out << "\tSource ID: " << bonus.sid.toString() << "\n";
|
||||
if(bonus.additionalInfo != CAddInfo::NONE)
|
||||
out << "\taddInfo: " << bonus.additionalInfo.toString() << "\n";
|
||||
printField(turnsRemain);
|
||||
|
||||
@@ -24,6 +24,7 @@ class BonusList;
|
||||
class CSelector;
|
||||
|
||||
using TBonusSubtype = MetaIdentifier;
|
||||
using TBonusSourceID = MetaIdentifier;
|
||||
using TBonusListPtr = std::shared_ptr<BonusList>;
|
||||
using TConstBonusListPtr = std::shared_ptr<const BonusList>;
|
||||
using TLimiterPtr = std::shared_ptr<ILimiter>;
|
||||
@@ -62,7 +63,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
||||
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.
|
||||
si32 val = 0;
|
||||
ui32 sid = 0; //source id: id of object/artifact/spell
|
||||
TBonusSourceID sid; //source id: id of object/artifact/spell
|
||||
BonusValueType valType = BonusValueType::ADDITIVE_VALUE;
|
||||
std::string stacking; // bonuses with the same stacking value don't stack (e.g. Angel/Archangel morale bonus)
|
||||
|
||||
@@ -76,11 +77,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 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(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID, std::string Desc);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID, TBonusSubtype subtype);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID, TBonusSubtype subtype, std::string Desc);
|
||||
Bonus(BonusDuration::Type Duration, BonusType Type, BonusSource Src, si32 Val, TBonusSourceID sourceID, TBonusSubtype subtype, BonusValueType ValType);
|
||||
Bonus() = default;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
@@ -167,20 +168,6 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
|
||||
{
|
||||
val += Val;
|
||||
}
|
||||
STRONG_INLINE static ui32 getSid32(ui32 high, ui32 low)
|
||||
{
|
||||
return (high << 16) + low;
|
||||
}
|
||||
|
||||
STRONG_INLINE static ui32 getHighFromSid32(ui32 sid)
|
||||
{
|
||||
return sid >> 16;
|
||||
}
|
||||
|
||||
STRONG_INLINE static ui32 getLowFromSid32(ui32 sid)
|
||||
{
|
||||
return sid & 0x0000FFFF;
|
||||
}
|
||||
|
||||
std::string Description(std::optional<si32> customValue = {}) const;
|
||||
JsonNode toJsonNode() const;
|
||||
|
||||
@@ -66,10 +66,10 @@ namespace Selector
|
||||
.And(CSelectFieldEqual<CAddInfo>(&Bonus::additionalInfo)(info));
|
||||
}
|
||||
|
||||
CSelector DLL_LINKAGE source(BonusSource source, ui32 sourceID)
|
||||
CSelector DLL_LINKAGE source(BonusSource source, TBonusSourceID sourceID)
|
||||
{
|
||||
return CSelectFieldEqual<BonusSource>(&Bonus::source)(source)
|
||||
.And(CSelectFieldEqual<ui32>(&Bonus::sid)(sourceID));
|
||||
.And(CSelectFieldEqual<TBonusSourceID>(&Bonus::sid)(sourceID));
|
||||
}
|
||||
|
||||
CSelector DLL_LINKAGE sourceTypeSel(BonusSource source)
|
||||
@@ -86,4 +86,4 @@ namespace Selector
|
||||
DLL_LINKAGE CSelector none([](const Bonus * b){return false;});
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Selector
|
||||
|
||||
CSelector DLL_LINKAGE typeSubtype(BonusType Type, TBonusSubtype Subtype);
|
||||
CSelector DLL_LINKAGE typeSubtypeInfo(BonusType type, TBonusSubtype subtype, const CAddInfo & info);
|
||||
CSelector DLL_LINKAGE source(BonusSource source, ui32 sourceID);
|
||||
CSelector DLL_LINKAGE source(BonusSource source, TBonusSourceID sourceID);
|
||||
CSelector DLL_LINKAGE sourceTypeSel(BonusSource source);
|
||||
CSelector DLL_LINKAGE valueType(BonusValueType valType);
|
||||
|
||||
@@ -153,4 +153,4 @@ namespace Selector
|
||||
extern DLL_LINKAGE CSelector none;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -82,10 +82,10 @@ bool IBonusBearer::hasBonusOfType(BonusType type, TBonusSubtype subtype) const
|
||||
return hasBonus(s, cachingStr);
|
||||
}
|
||||
|
||||
bool IBonusBearer::hasBonusFrom(BonusSource source, ui32 sourceID) const
|
||||
bool IBonusBearer::hasBonusFrom(BonusSource source, TBonusSourceID sourceID) const
|
||||
{
|
||||
boost::format fmt("source_%did_%d");
|
||||
fmt % static_cast<int>(source) % sourceID;
|
||||
boost::format fmt("source_%did_%s");
|
||||
fmt % static_cast<int>(source) % sourceID.toString();
|
||||
|
||||
return hasBonus(Selector::source(source,sourceID), fmt.str());
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
bool hasBonusOfType(BonusType type) 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;
|
||||
bool hasBonusFrom(BonusSource source, TBonusSourceID sourceID) const;
|
||||
|
||||
virtual int64_t getTreeVersion() const = 0;
|
||||
};
|
||||
|
||||
@@ -303,10 +303,10 @@ ILimiter::EDecision FactionLimiter::limit(const BonusLimitationContext &context)
|
||||
switch(context.b.source)
|
||||
{
|
||||
case BonusSource::CREATURE_ABILITY:
|
||||
return bearer->getFaction() == CreatureID(context.b.sid).toCreature()->getFaction() ? ILimiter::EDecision::ACCEPT : ILimiter::EDecision::DISCARD;
|
||||
return bearer->getFaction() == context.b.sid.as<CreatureID>().toCreature()->getFaction() ? ILimiter::EDecision::ACCEPT : ILimiter::EDecision::DISCARD;
|
||||
|
||||
case BonusSource::TOWN_STRUCTURE:
|
||||
return bearer->getFaction() == FactionID(Bonus::getHighFromSid32(context.b.sid)) ? ILimiter::EDecision::ACCEPT : ILimiter::EDecision::DISCARD;
|
||||
return bearer->getFaction() == context.b.sid.as<BuildingTypeUniqueID>().getFaction() ? ILimiter::EDecision::ACCEPT : ILimiter::EDecision::DISCARD;
|
||||
|
||||
//TODO: other sources of bonuses
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
BonusType type;
|
||||
TBonusSubtype subtype;
|
||||
BonusSource source;
|
||||
si32 sid;
|
||||
TBonusSourceID sid;
|
||||
bool isSubtypeRelevant; //check for subtype only if this is true
|
||||
bool isSourceRelevant; //check for bonus source only if this is true
|
||||
bool isSourceIDRelevant; //check for bonus source only if this is true
|
||||
|
||||
Reference in New Issue
Block a user