浏览代码

- Handle new configurable banks
- Handle "all" object banned option

Tomasz Zieliński 1 年之前
父节点
当前提交
ec603f46ae
共有 4 个文件被更改,包括 46 次插入29 次删除
  1. 3 0
      lib/mapObjectConstructors/IObjectInfo.h
  2. 5 0
      lib/rewardable/Info.cpp
  3. 2 0
      lib/rewardable/Info.h
  4. 36 29
      lib/rmg/modificators/TreasurePlacer.cpp

+ 3 - 0
lib/mapObjectConstructors/IObjectInfo.h

@@ -49,7 +49,10 @@ public:
 
 	virtual bool givesBonuses() const { return false; }
 
+	virtual bool hasGuards() const { return false; }
+
 	virtual ~IObjectInfo() = default;
+
 };
 
 VCMI_LIB_NAMESPACE_END

+ 5 - 0
lib/rewardable/Info.cpp

@@ -525,6 +525,11 @@ bool Rewardable::Info::givesBonuses() const
 	return testForKey(parameters, "bonuses");
 }
 
+bool Rewardable::Info::hasGuards() const
+{
+	return testForKey(parameters, "guards");
+}
+
 const JsonNode & Rewardable::Info::getParameters() const
 {
 	return parameters;

+ 2 - 0
lib/rewardable/Info.h

@@ -68,6 +68,8 @@ public:
 
 	bool givesBonuses() const override;
 
+	bool hasGuards() const override;
+
 	void configureObject(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb) const;
 
 	void init(const JsonNode & objectConfig, const std::string & objectTextID);

+ 36 - 29
lib/rmg/modificators/TreasurePlacer.cpp

@@ -1138,38 +1138,41 @@ void TreasurePlacer::ObjectPool::patchWithZoneConfig(const Zone & zone, Treasure
 	auto bannedObjectCategories = zone.getBannedObjectCategories();
 	auto categoriesSet = std::unordered_set<ObjectConfig::EObjectCategory>(bannedObjectCategories.begin(), bannedObjectCategories.end());
 
-	vstd::erase_if(possibleObjects, [this, &categoriesSet](const ObjectInfo & oi) -> bool
+	if (categoriesSet.count(ObjectConfig::EObjectCategory::ALL))
 	{
-		auto category = getObjectCategory(oi.getCompoundID());
-		if (categoriesSet.count(category))
-		{
-			logGlobal->info("Removing object %s from possible objects", oi.templates.front()->stringID);
-			/* FIXME:
-			Removing object normal from possible objects
-			Removing object base from possible objects
-			Removing object default from possible objects
-			*/
-			return true;
-		}
-		return false;
-	});
-
-	auto bannedObjects = zone.getBannedObjects();
-	auto bannedObjectsSet = std::set<CompoundMapObjectID>(bannedObjects.begin(), bannedObjects.end());
-	vstd::erase_if(possibleObjects, [&bannedObjectsSet](const ObjectInfo & object)
+		possibleObjects.clear();
+	}
+	else
 	{
-		for (const auto & templ : object.templates)
+		vstd::erase_if(possibleObjects, [this, &categoriesSet](const ObjectInfo & oi) -> bool
+
 		{
-			CompoundMapObjectID key = object.getCompoundID();
-			if (bannedObjectsSet.count(key))
+			auto category = getObjectCategory(oi.getCompoundID());
+			if (categoriesSet.count(category))
 			{
-				// FIXME: Stopped working, nothing is banned
-				logGlobal->info("Banning object %s from possible objects", templ->stringID);
+				logGlobal->info("Removing object %s from possible objects", oi.templates.front()->stringID);
 				return true;
 			}
-		}
-		return false;
-	});
+			return false;
+		});
+
+		auto bannedObjects = zone.getBannedObjects();
+		auto bannedObjectsSet = std::set<CompoundMapObjectID>(bannedObjects.begin(), bannedObjects.end());
+		vstd::erase_if(possibleObjects, [&bannedObjectsSet](const ObjectInfo & object)
+		{
+			for (const auto & templ : object.templates)
+			{
+				CompoundMapObjectID key = object.getCompoundID();
+				if (bannedObjectsSet.count(key))
+				{
+					// FIXME: Stopped working, nothing is banned
+					logGlobal->info("Banning object %s from possible objects", templ->stringID);
+					return true;
+				}
+			}
+			return false;
+		});
+	}
 
 	auto configuredObjects = zone.getConfiguredObjects();
 
@@ -1219,16 +1222,20 @@ ObjectConfig::EObjectCategory TreasurePlacer::ObjectPool::getObjectCategory(Comp
 
 	if (name == "configurable")
 	{
-		// TODO: Access Rewardable::Info by ID
-
 		auto handler = VLC->objtypeh->getHandlerFor(id.primaryID, id.secondaryID);
 		if (!handler)
 		{
 			return ObjectConfig::EObjectCategory::NONE;
 		}
+
 		auto temp = handler->getTemplates().front();
 		auto info = handler->getObjectInfo(temp);
-		if (info->givesResources())
+
+		if (info->hasGuards())
+		{
+			return ObjectConfig::EObjectCategory::CREATURE_BANK;
+		}
+		else if (info->givesResources())
 		{
 			return ObjectConfig::EObjectCategory::RESOURCE;
 		}