瀏覽代碼

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).
Konstantin 2 年之前
父節點
當前提交
f8eba58003
共有 7 個文件被更改,包括 23 次插入23 次删除
  1. 2 2
      lib/CTownHandler.cpp
  2. 2 1
      lib/GameConstants.cpp
  3. 1 0
      lib/GameConstants.h
  4. 3 9
      lib/HeroBonus.cpp
  5. 2 3
      lib/HeroBonus.h
  6. 12 2
      lib/JsonNode.cpp
  7. 1 6
      lib/mapObjects/CGTownInstance.cpp

+ 2 - 2
lib/CTownHandler.cpp

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

+ 2 - 1
lib/GameConstants.cpp

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

+ 1 - 0
lib/GameConstants.h

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

+ 3 - 9
lib/HeroBonus.cpp

@@ -88,8 +88,7 @@ const std::map<std::string, TPropagatorPtr> bonusPropagatorMap =
 	{"PLAYER_PROPAGATOR", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::PLAYER)},
 	{"HERO", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::HERO)},
 	{"TEAM_PROPAGATOR", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::TEAM)}, //untested
-	{"GLOBAL_EFFECT", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::GLOBAL_EFFECTS)},
-	{"ALL_CREATURES", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ALL_CREATURES)}
+	{"GLOBAL_EFFECT", std::make_shared<CPropagatorNodeType>(CBonusSystemNode::GLOBAL_EFFECTS)}
 }; //untested
 
 const std::map<std::string, TUpdaterPtr> bonusUpdaterMap =
@@ -2368,20 +2367,15 @@ JsonNode CreatureTerrainLimiter::toJsonNode() const
 	return root;
 }
 
-CreatureFactionLimiter::CreatureFactionLimiter(TFaction creatureFaction)
+CreatureFactionLimiter::CreatureFactionLimiter(FactionID creatureFaction)
 	: faction(creatureFaction)
 {
 }
 
-CreatureFactionLimiter::CreatureFactionLimiter():
-	faction(static_cast<TFaction>(-1))
-{
-}
-
 ILimiter::EDecision CreatureFactionLimiter::limit(const BonusLimitationContext &context) const
 {
 	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
 }
 

+ 2 - 3
lib/HeroBonus.h

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

+ 12 - 2
lib/JsonNode.cpp

@@ -754,7 +754,7 @@ std::shared_ptr<ILimiter> JsonUtils::parseLimiter(const JsonNode & limiter)
 				std::shared_ptr<CreatureFactionLimiter> factionLimiter = std::make_shared<CreatureFactionLimiter>();
 				VLC->modh->identifiers.requestIdentifier("faction", parameters[0], [=](si32 faction)
 				{
-					factionLimiter->faction = faction;
+					factionLimiter->faction = FactionID(faction);
 				});
 				return factionLimiter;
 			}
@@ -1002,7 +1002,17 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
 
 	value = &ability["propagator"];
 	if (!value->isNull())
-		b->propagator = parseByMap(bonusPropagatorMap, value, "propagator type ");
+	{
+		//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 ");
+	}
 
 	value = &ability["updater"];
 	if(!value->isNull())

+ 1 - 6
lib/mapObjects/CGTownInstance.cpp

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