mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Use the most suitable template for object
This commit is contained in:
		| @@ -107,6 +107,11 @@ public: | ||||
| 		return anyTerrain; | ||||
| 	}; | ||||
|  | ||||
| 	const std::set<TerrainId>& getAllowedTerrains() const | ||||
| 	{ | ||||
| 		return allowedTerrains; | ||||
| 	} | ||||
|  | ||||
| 	// Checks if object can be placed on specific terrain | ||||
| 	bool canBePlacedAt(TerrainId terrain) const; | ||||
|  | ||||
|   | ||||
| @@ -79,7 +79,15 @@ void ObjectDistributor::distributeLimitedObjects() | ||||
|  | ||||
| 					for (auto& zone : matchingZones) | ||||
| 					{ | ||||
| 						auto temp = handler->getTemplates(zone->getTerrainType()).front(); | ||||
| 						//We already know there are some templates | ||||
| 						auto templates = handler->getTemplates(zone->getTerrainType()); | ||||
|  | ||||
| 						//Assume the template with fewest terrains is the most suitable | ||||
| 						auto temp = *boost::min_element(templates, [](std::shared_ptr<const ObjectTemplate> lhs, std::shared_ptr<const ObjectTemplate> rhs) -> bool | ||||
| 						{ | ||||
| 							return lhs->getAllowedTerrains().size() < rhs->getAllowedTerrains().size(); | ||||
| 						}); | ||||
|  | ||||
| 						oi.generateObject = [temp]() -> CGObjectInstance * | ||||
| 						{ | ||||
| 							return VLC->objtypeh->getHandlerFor(temp->id, temp->subid)->create(temp); | ||||
|   | ||||
| @@ -71,10 +71,16 @@ void TreasurePlacer::addAllPossibleObjects() | ||||
| 					continue; | ||||
| 				} | ||||
|  | ||||
| 				for(const auto & temp : handler->getTemplates()) | ||||
| 				{ | ||||
| 					if(temp->canBePlacedAt(zone.getTerrainType())) | ||||
| 				auto templates = handler->getTemplates(zone.getTerrainType()); | ||||
| 				if (templates.empty()) | ||||
| 					continue; | ||||
|  | ||||
| 				//Assume the template with fewest terrains is the most suitable | ||||
| 				auto temp = *boost::min_element(templates, [](std::shared_ptr<const ObjectTemplate> lhs, std::shared_ptr<const ObjectTemplate> rhs) -> bool | ||||
| 				{ | ||||
| 					return lhs->getAllowedTerrains().size() < rhs->getAllowedTerrains().size(); | ||||
| 				}); | ||||
|  | ||||
| 				oi.generateObject = [temp]() -> CGObjectInstance * | ||||
| 				{ | ||||
| 					return VLC->objtypeh->getHandlerFor(temp->id, temp->subid)->create(temp); | ||||
| @@ -84,10 +90,6 @@ void TreasurePlacer::addAllPossibleObjects() | ||||
| 				oi.templ = temp; | ||||
| 				oi.maxPerZone = rmgInfo.zoneLimit; | ||||
| 				addObjectToRandomPool(oi); | ||||
|  | ||||
| 						break; | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user