1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

vcmi: remove ALL_CREATURES propagator

Now unneded, because it handled by GLOBAL_EFFECT with
CREATURE_LEVEL_LIMITER (when range set to UINT_MIN and UINT_MAX).
This commit is contained in:
Konstantin 2023-04-06 20:03:17 +03:00
parent 9f8dcfc736
commit f8eba58003
7 changed files with 23 additions and 23 deletions

View File

@ -571,8 +571,8 @@ void CTownHandler::loadSpecialBuildingBonuses(const JsonNode & source, BonusList
{ {
auto * limPtr = dynamic_cast<CreatureFactionLimiter *>(bonus->limiter.get()); auto * limPtr = dynamic_cast<CreatureFactionLimiter *>(bonus->limiter.get());
if(limPtr != nullptr && limPtr->faction == static_cast<TFaction>(-1)) if(limPtr != nullptr && limPtr->faction == FactionID::ANY)
limPtr->faction = building->town->faction->getIndex(); limPtr->faction = building->town->faction->getId();
} }
//JsonUtils::parseBuildingBonus produces UNKNOWN type propagator instead of empty. //JsonUtils::parseBuildingBonus produces UNKNOWN type propagator instead of empty.
if(bonus->propagator != nullptr if(bonus->propagator != nullptr

View File

@ -187,6 +187,7 @@ std::string PlayerColor::getStrCap(bool L10n) const
return ret; return ret;
} }
const FactionID FactionID::NONE = FactionID(-2);
const FactionID FactionID::ANY = FactionID(-1); const FactionID FactionID::ANY = FactionID(-1);
const FactionID FactionID::CASTLE = FactionID(0); const FactionID FactionID::CASTLE = FactionID(0);
const FactionID FactionID::RAMPART = FactionID(1); const FactionID FactionID::RAMPART = FactionID(1);
@ -205,7 +206,7 @@ si32 FactionID::decode(const std::string & identifier)
if(rawId) if(rawId)
return rawId.get(); return rawId.get();
else else
return -1; return FactionID::ANY;
} }
std::string FactionID::encode(const si32 index) std::string FactionID::encode(const si32 index)

View File

@ -442,6 +442,7 @@ class FactionID : public BaseForID<FactionID, int32_t>
{ {
INSTID_LIKE_CLASS_COMMON(FactionID, si32) INSTID_LIKE_CLASS_COMMON(FactionID, si32)
DLL_LINKAGE static const FactionID NONE;
DLL_LINKAGE static const FactionID ANY; DLL_LINKAGE static const FactionID ANY;
DLL_LINKAGE static const FactionID CASTLE; DLL_LINKAGE static const FactionID CASTLE;
DLL_LINKAGE static const FactionID RAMPART; DLL_LINKAGE static const FactionID RAMPART;

View File

@ -88,8 +88,7 @@ const std::map<std::string, TPropagatorPtr> bonusPropagatorMap =
{"PLAYER_PROPAGATOR", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::PLAYER)}, {"PLAYER_PROPAGATOR", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::PLAYER)},
{"HERO", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::HERO)}, {"HERO", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::HERO)},
{"TEAM_PROPAGATOR", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::TEAM)}, //untested {"TEAM_PROPAGATOR", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::TEAM)}, //untested
{"GLOBAL_EFFECT", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::GLOBAL_EFFECTS)}, {"GLOBAL_EFFECT", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::GLOBAL_EFFECTS)}
{"ALL_CREATURES", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ALL_CREATURES)}
}; //untested }; //untested
const std::map<std::string, TUpdaterPtr> bonusUpdaterMap = const std::map<std::string, TUpdaterPtr> bonusUpdaterMap =
@ -2368,20 +2367,15 @@ JsonNode CreatureTerrainLimiter::toJsonNode() const
return root; return root;
} }
CreatureFactionLimiter::CreatureFactionLimiter(TFaction creatureFaction) CreatureFactionLimiter::CreatureFactionLimiter(FactionID creatureFaction)
: faction(creatureFaction) : faction(creatureFaction)
{ {
} }
CreatureFactionLimiter::CreatureFactionLimiter():
faction(static_cast<TFaction>(-1))
{
}
ILimiter::EDecision CreatureFactionLimiter::limit(const BonusLimitationContext &context) const ILimiter::EDecision CreatureFactionLimiter::limit(const BonusLimitationContext &context) const
{ {
const CCreature *c = retrieveCreature(&context.node); const CCreature *c = retrieveCreature(&context.node);
auto accept = c && c->getFactionIndex() == faction; auto accept = c && (c->getFactionIndex() == faction || faction == FactionID::ANY);
return accept ? ILimiter::EDecision::ACCEPT : ILimiter::EDecision::DISCARD; //drop bonus for non-creatures or non-native residents return accept ? ILimiter::EDecision::ACCEPT : ILimiter::EDecision::DISCARD; //drop bonus for non-creatures or non-native residents
} }

View File

@ -1130,9 +1130,8 @@ public:
class DLL_LINKAGE CreatureFactionLimiter : public ILimiter //applies only to creatures of given faction class DLL_LINKAGE CreatureFactionLimiter : public ILimiter //applies only to creatures of given faction
{ {
public: public:
TFaction faction; FactionID faction;
CreatureFactionLimiter(); CreatureFactionLimiter(FactionID faction = FactionID::ANY);
CreatureFactionLimiter(TFaction faction);
EDecision limit(const BonusLimitationContext &context) const override; EDecision limit(const BonusLimitationContext &context) const override;
std::string toString() const override; std::string toString() const override;

View File

@ -754,7 +754,7 @@ std::shared_ptr<ILimiter> JsonUtils::parseLimiter(const JsonNode & limiter)
std::shared_ptr<CreatureFactionLimiter> factionLimiter = std::make_shared<CreatureFactionLimiter>(); std::shared_ptr<CreatureFactionLimiter> factionLimiter = std::make_shared<CreatureFactionLimiter>();
VLC->modh->identifiers.requestIdentifier("faction", parameters[0], [=](si32 faction) VLC->modh->identifiers.requestIdentifier("faction", parameters[0], [=](si32 faction)
{ {
factionLimiter->faction = faction; factionLimiter->faction = FactionID(faction);
}); });
return factionLimiter; return factionLimiter;
} }
@ -1002,7 +1002,17 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
value = &ability["propagator"]; value = &ability["propagator"];
if (!value->isNull()) if (!value->isNull())
{
//ALL_CREATURES old propagator compatibility
if(value->String() == "ALL_CREATURES")
{
logMod->warn("ALL_CREATURES propagator is deprecated. Use GLOBAL_EFFECT propagator with CREATURES_ONLY limiter");
b->addLimiter(std::make_shared<CreatureLevelLimiter>());
b->propagator = bonusPropagatorMap.at("GLOBAL_EFFECT");
}
else
b->propagator = parseByMap(bonusPropagatorMap, value, "propagator type "); b->propagator = parseByMap(bonusPropagatorMap, value, "propagator type ");
}
value = &ability["updater"]; value = &ability["updater"];
if(!value->isNull()) if(!value->isNull())

View File

@ -1232,13 +1232,8 @@ void CGTownInstance::recreateBuildingsBonuses()
continue; continue;
for(auto & bonus : building->buildingBonuses) for(auto & bonus : building->buildingBonuses)
{
if(bonus->propagator != nullptr && bonus->propagator->getPropagatorType() == ALL_CREATURES)
VLC->creh->addBonusForAllCreatures(bonus);
else
addNewBonus(bonus); addNewBonus(bonus);
} }
}
} }
void CGTownInstance::setVisitingHero(CGHeroInstance *h) void CGTownInstance::setVisitingHero(CGHeroInstance *h)