浏览代码

Explicitly ban 'large' dwellings from random selection

Old code was relying on specific sorting order leading to easy to break
logic
Ivan Savenko 1 年之前
父节点
当前提交
ffec4b9154

+ 5 - 0
config/objects/dwellings.json

@@ -65,6 +65,7 @@
 			},
 			"airConflux": {
 				"index": 7,
+				"bannedForRandomDwelling" : true,
 				"creatures": [["airElemental"]],
 				"sounds": {
 					"ambient": ["LOOPAIR"]
@@ -107,6 +108,7 @@
 			},
 			"earthConflux": {
 				"index": 13,
+				"bannedForRandomDwelling" : true,
 				"creatures": [["earthElemental"]],
 				"sounds": {
 					"ambient": ["LOOPEART"]
@@ -128,6 +130,7 @@
 			},
 			"fireConflux": {
 				"index": 16,
+				"bannedForRandomDwelling" : true,
 				"creatures": [["fireElemental"]],
 				"sounds": {
 					"ambient": ["LOOPFIRE"]
@@ -345,6 +348,7 @@
 			},
 			"waterConflux": {
 				"index": 47,
+				"bannedForRandomDwelling" : true,
 				"creatures": [["waterElemental"]],
 				"sounds": {
 					"ambient": ["LOOPFOUN"]
@@ -538,6 +542,7 @@
 		"types" : {
 			"elementalConflux" : {
 				"index" : 0,
+				"bannedForRandomDwelling" : true,
 				"creatures" : [ // 4 separate "levels" to give them separate growth
 					[ "airElemental" ],
 					[ "waterElemental" ],

+ 6 - 0
lib/mapObjectConstructors/DwellingInstanceConstructor.cpp

@@ -51,6 +51,12 @@ void DwellingInstanceConstructor::initTypeData(const JsonNode & input)
 		assert(!availableCreatures[currentLevel].empty());
 	}
 	guards = input["guards"];
+	bannedForRandomDwelling = input["bannedForRandomDwelling"].Bool();
+}
+
+bool DwellingInstanceConstructor::isBannedForRandomDwelling() const
+{
+	return bannedForRandomDwelling;
 }
 
 bool DwellingInstanceConstructor::objectFilter(const CGObjectInstance * obj, std::shared_ptr<const ObjectTemplate> tmpl) const

+ 2 - 0
lib/mapObjectConstructors/DwellingInstanceConstructor.h

@@ -23,6 +23,7 @@ class DwellingInstanceConstructor : public CDefaultObjectTypeHandler<CGDwelling>
 	std::vector<std::vector<const CCreature *>> availableCreatures;
 
 	JsonNode guards;
+	bool bannedForRandomDwelling = false;
 
 protected:
 	bool objectFilter(const CGObjectInstance * obj, std::shared_ptr<const ObjectTemplate> tmpl) const override;
@@ -34,6 +35,7 @@ public:
 	void initializeObject(CGDwelling * object) const override;
 	void randomizeObject(CGDwelling * object, CRandomGenerator & rng) const override;
 
+	bool isBannedForRandomDwelling() const;
 	bool producesCreature(const CCreature * crea) const;
 	std::vector<const CCreature *> getProducedCreatures() const;
 };

+ 1 - 1
lib/mapObjects/CGDwelling.cpp

@@ -146,7 +146,7 @@ void CGDwelling::pickRandomObject(CRandomGenerator & rand)
 			{
 				const auto * handler = dynamic_cast<const DwellingInstanceConstructor *>(VLC->objtypeh->getHandlerFor(primaryID, entry).get());
 
-				if (handler->producesCreature(cid.toCreature()))
+				if (!handler->isBannedForRandomDwelling() && handler->producesCreature(cid.toCreature()))
 					return MapObjectSubID(entry);
 			}
 			return MapObjectSubID();