/** Load additionnal ig from a continent (ryzom specific)
  * \param parameter a config file that contains the name of the continent containing the zones we are processing
  * \param zone2bbox This will be filled with the name of a zone and the bbox of the village it contains
  * \param a map of shape
  * \param a vector that will be filled with a zone name and the bbox of the village it contains
  */
static void computeIGBBoxFromContinent(NLMISC::CConfigFile &parameter,									   
									   TShapeMap &shapeMap,
									   TString2LightingBBox &zone2BBox									   
							          )
{
		
	try
	{
		CConfigFile::CVar &continent_name_var = parameter.getVar ("continent_name");
		CConfigFile::CVar &level_design_directory = parameter.getVar ("level_design_directory");
		CConfigFile::CVar &level_design_world_directory = parameter.getVar ("level_design_world_directory");						
		CConfigFile::CVar &level_design_dfn_directory = parameter.getVar ("level_design_dfn_directory");
		CPath::addSearchPath(level_design_dfn_directory.asString(), true, false);
		CPath::addSearchPath(level_design_world_directory.asString(), true, false);

		std::string continentName = continent_name_var.asString();
		if (CFile::getExtension(continentName).empty())
			continentName += ".continent";
		// Load the form
		NLGEORGES::UFormLoader *loader = NLGEORGES::UFormLoader::createLoader();
		//
		std::string pathName = level_design_world_directory.asString() + "/" + continentName;
		if (pathName.empty())
		{		
			nlwarning("Can't find continent form : %s", continentName.c_str());
			return;
		}		
		NLGEORGES::UForm *villageForm;
		villageForm = loader->loadForm(pathName.c_str());
		if(villageForm != NULL)
		{
			NLGEORGES::UFormElm &rootItem = villageForm->getRootNode();
			// try to get the village list
			// Load the village list
			NLGEORGES::UFormElm *villagesItem;
			if(!(rootItem.getNodeByName (&villagesItem, "Villages") && villagesItem))
			{
				nlwarning("No villages where found in %s", continentName.c_str());
				return;
			}

			// Get number of village
			uint numVillage;
			nlverify (villagesItem->getArraySize (numVillage));

			// For each village
			for(uint k = 0; k < numVillage; ++k)
			{				
				NLGEORGES::UFormElm *currVillage;
				if (!(villagesItem->getArrayNode (&currVillage, k) && currVillage))
				{
					nlwarning("Couldn't get village %d in continent %s", continentName.c_str(), k);
					continue;
				}
				// check that this village is in the dependency zones
				NLGEORGES::UFormElm *zoneNameItem;
				if (!currVillage->getNodeByName (&zoneNameItem, "Zone") && zoneNameItem)
				{
					nlwarning("Couldn't get zone item of village %d in continent %s", continentName.c_str(), k);
					continue;
				}
				std::string zoneName;
				if (!zoneNameItem->getValue(zoneName))
				{
					nlwarning("Couldn't get zone name of village %d in continent %s", continentName.c_str(), k);
					continue;
				}
				zoneName = NLMISC::toLower(CFile::getFilenameWithoutExtension(zoneName));				
				CLightingBBox result;				
				// ok, it is in the dependant zones
				computeBBoxFromVillage(currVillage, continentName, k, shapeMap, result);
				if (!result.OccludingBox.IsVoid || result.ReceivingBox.IsVoid)
				{
					zone2BBox[zoneName] = result;					
				}										
			}				
		}
		else 
		{
			nlwarning("Can't load continent form : %s", continentName.c_str());
		}				
	}	
	catch (NLMISC::EUnknownVar &e)
	{
		nlinfo(e.what());
	}
}
Example #2
0
//**********************************************************************************************
void CVillageGrid::addVillagesFromContinent(const std::string &continentSheetName)
{
	// Load the form
	NLGEORGES::UFormLoader *loader = NLGEORGES::UFormLoader::createLoader();
	//
	std::string path  = CPath::lookup(continentSheetName, false, false);
	if (path.empty())
	{
		nlwarning("Path not found for %s.", continentSheetName.c_str());
		return;
	}
	NLGEORGES::UForm *villageForm;
	villageForm = loader->loadForm(path.c_str());
	if(villageForm != NULL)
	{
		NLGEORGES::UFormElm &rootItem = villageForm->getRootNode();
		// try to get the village list
		// Load the village list
		NLGEORGES::UFormElm *villagesItem;
		if(!(rootItem.getNodeByName (&villagesItem, "Villages") && villagesItem))
		{
			nlwarning("No villages where found in %s", continentSheetName.c_str());
			return;
		}

		// Get number of village
		uint numVillage;
		nlverify (villagesItem->getArraySize (numVillage));

		// For each village
		for(uint k = 0; k < numVillage; ++k)
		{
			NLGEORGES::UFormElm *currVillage;
			if (!(villagesItem->getArrayNode (&currVillage, k) && currVillage))
			{
				nlwarning("Couldn't get village %d in continent %s", continentSheetName.c_str(), k);
				continue;
			}
			// check that this village is in the dependency zones
			NLGEORGES::UFormElm *zoneNameItem;
			if (!currVillage->getNodeByName (&zoneNameItem, "Zone") && zoneNameItem)
			{
				nlwarning("Couldn't get zone item of village %d in continent %s", continentSheetName.c_str(), k);
				continue;
			}
			std::string zoneName;
			if (!zoneNameItem->getValue(zoneName))
			{
				nlwarning("Couldn't get zone name of village %d in continent %s", continentSheetName.c_str(), k);
				continue;
			}			
			sint zoneX, zoneY;
			if (!getZonePos(zoneName, zoneX, zoneY))
			{
				nlwarning("Zone name of village %d in continent %s is invalid", continentSheetName.c_str(), k);
				continue;
			}			
			sint villageMinX, villageMinY;
			sint villageMaxX, villageMaxY;

			
			// retrieve width & height of covered region
			uint32 regionWidth;
			uint32 regionHeight;
			float  centerX, centerY;
			if (!currVillage->getValueByName(regionWidth,  "Width")   ||
				!currVillage->getValueByName(regionHeight, "Height")  || 
				!currVillage->getValueByName(centerX,	   "CenterX") ||
				!currVillage->getValueByName(centerY,	   "CenterY"))
			{
				nlwarning("Can't retrieve region covered by village %d in continent %s", continentSheetName.c_str(), k);
				continue;
			}
			//
			villageMinX = villageMaxX = zoneX;
			villageMinY = villageMaxY = zoneY;
			// extends with bbox from center to min corner if leveldesigner forgot to enter good width & height			
			villageMaxX = std::max(villageMaxX, (sint) ((zoneX * 160.f + 2.f * centerX) / 160.f));
			villageMaxY = std::max(villageMaxY, (sint) ((zoneY * 160.f + 2.f * centerY) / 160.f));			
			//
			villageMinX -= _ZoneMinX;
			villageMaxX -= _ZoneMinX;
			villageMinY -= _ZoneMinY;
			villageMaxY -= _ZoneMinY;
			//
			CVillage village;
			if (loadVillageSheet(currVillage, continentSheetName, k, village))
			{
				//
				village.FileModificationDate = std::max(village.FileModificationDate, CFile::getFileModificationDate(path));
				//
				Villages.push_back(CVillage());
				Villages.back().swap(village);
				//
				for (sint y = villageMinY; y <= (sint) villageMaxY; ++y)
				{
					if (y < 0) continue;
					if (y >= (sint) VillageGrid.getHeight()) continue;
					for (sint x = villageMinX; x <= (sint) villageMaxX; ++x)
					{
						if (x < 0) continue;
						if (x >= (sint) VillageGrid.getWidth()) continue;
						VillageGrid(x, y).push_back(Villages.size() - 1);
					}
				}
			}
		}				
	}
	else 
	{
		nlwarning("Can't load continent form : %s", continentSheetName.c_str());
	}
}