Hooks
static bool BeforeCvWorldBuilderMapLoader_Save(const wchar_t* wszFilename, const char* szMapName, bool& result);static void AfterCvWorldBuilderMapLoader_Save(const wchar_t* wszFilename, const char* szMapName, bool& result);static bool ReplaceCvWorldBuilderMapLoader_Save(bool (*original)(const wchar_t*, const char*), const wchar_t* wszFilename, const char* szMapName);CivRegisterBefore<CivHooks::CvWorldBuilderMapLoader_Save>(host, &BeforeCvWorldBuilderMapLoader_Save);CivRegisterAfter<CivHooks::CvWorldBuilderMapLoader_Save>(host, &AfterCvWorldBuilderMapLoader_Save);CivRegisterReplace<CivHooks::CvWorldBuilderMapLoader_Save>(host, &ReplaceCvWorldBuilderMapLoader_Save);
Code
1291bool CvWorldBuilderMapLoader::Save(const wchar_t* wszFilename, const char* szMapName)1292{1293 InitTypeDesc();12941295 CvMap& kMap = GC.getMap();1296 sg_kSave.Resize(kMap.getGridWidth(), kMap.getGridHeight());1297 sg_kSave.ClearScenarioData();12981299 // Set map name1300 if(szMapName == NULL)1301 {1302 FStringFixedBufferW(sFilename, MAX_PATH);1303 FStringFixedBufferW(sFileTitle, MAX_PATH);13041305 sFilename = wszFilename;1306 sFilename.ExtractFileTitle(sFileTitle);1307 sFileTitle.CopyToUTF8(&sg_kSave.m_sMapName);1308 }1309 else1310 {1311 sg_kSave.m_sMapName = szMapName;1312 }13131314 sg_kSave.m_sMapDescription = "";13151316 sg_kSave.m_uiFlags = 0;1317 sg_kSave.SetFlag(CvWorldBuilderMap::FLAG_WORLD_WRAP, kMap.isWrapX());13181319 sg_kSave.SetWorldType(kMap.getWorldInfo().GetType());13201321 uint uiPlotCount = sg_kSave.GetWidth() * sg_kSave.GetHeight();1322 for(uint i = 0; i < uiPlotCount; ++i)1323 {1324 CvWorldBuilderMap::PlotMapData& kPlotData = sg_kSave.GetPlotData(i);1325 CvPlot* pkPlot = kMap.plotByIndex(i);1326 FAssertMsg(pkPlot, "Missing CvPlot for this location");1327 if(pkPlot == NULL) continue;13281329 kPlotData.SetTerrainType((byte)pkPlot->getTerrainType());13301331 PlotTypes ePlotType = pkPlot->getPlotType();1332 if(ePlotType == PLOT_HILLS)1333 kPlotData.SetPlotHeight(CvWorldBuilderMap::PlotMapData::HILLS);1334 else if(ePlotType == PLOT_MOUNTAIN)1335 kPlotData.SetPlotHeight(CvWorldBuilderMap::PlotMapData::MOUNTAINS);1336 else1337 kPlotData.SetPlotHeight(CvWorldBuilderMap::1338 PlotMapData::FLAT_TERRAIN);13391340 ResourceTypes eResourceType = pkPlot->getResourceType();1341 if(eResourceType == NO_RESOURCE)1342 {1343 kPlotData.SetResourceType(CvWorldBuilderMap::PlotMapData::InvalidResource);1344 }1345 else1346 {1347 kPlotData.SetResourceType((byte)eResourceType);1348 kPlotData.SetResourceAmount((byte)pkPlot->getNumResource());1349 }13501351 FeatureTypes eFeatureType = pkPlot->getFeatureType();1352 if(eFeatureType == NO_FEATURE)1353 {1354 kPlotData.SetFeatureType(CvWorldBuilderMap::PlotMapData::InvalidFeature);1355 kPlotData.SetNaturalWonderType(CvWorldBuilderMap::PlotMapData::InvalidNaturalWonder);1356 }1357 else1358 {1359 CvFeatureInfo* pkFeatureInfo = GC.getFeatureInfo(eFeatureType);1360 if(pkFeatureInfo != NULL && pkFeatureInfo->IsNaturalWonder())1361 {1362 kPlotData.SetFeatureType(CvWorldBuilderMap::PlotMapData::InvalidFeature);1363 kPlotData.SetNaturalWonderType((byte)eFeatureType);1364 }1365 else1366 {1367 kPlotData.SetFeatureType((byte)eFeatureType);1368 kPlotData.SetNaturalWonderType(CvWorldBuilderMap::PlotMapData::InvalidNaturalWonder);1369 }1370 }13711372 if(pkPlot->isWOfRiver())1373 {1374 kPlotData.SetFlag(CvWorldBuilderMap::PlotMapData::W_OF_RIVER);1375 if(pkPlot->getRiverEFlowDirection() == FLOWDIRECTION_SOUTH)1376 kPlotData.SetFlag(CvWorldBuilderMap::PlotMapData::RIVER_FLOW_S);1377 else1378 kPlotData.ClearFlag(CvWorldBuilderMap::PlotMapData::RIVER_FLOW_S);1379 }1380 else1381 {1382 kPlotData.ClearFlag(CvWorldBuilderMap::PlotMapData::W_OF_RIVER);1383 }13841385 if(pkPlot->isNWOfRiver())1386 {1387 kPlotData.SetFlag(CvWorldBuilderMap::PlotMapData::NW_OF_RIVER);1388 if(pkPlot->getRiverSEFlowDirection() == FLOWDIRECTION_NORTHEAST)1389 kPlotData.SetFlag(CvWorldBuilderMap::PlotMapData::RIVER_FLOW_NE);1390 else1391 kPlotData.ClearFlag(CvWorldBuilderMap::PlotMapData::RIVER_FLOW_NE);1392 }1393 else1394 {1395 kPlotData.ClearFlag(CvWorldBuilderMap::PlotMapData::NW_OF_RIVER);1396 }13971398 if(pkPlot->isNEOfRiver())1399 {1400 kPlotData.SetFlag(CvWorldBuilderMap::PlotMapData::NE_OF_RIVER);1401 if(pkPlot->getRiverSWFlowDirection() == FLOWDIRECTION_NORTHWEST)1402 kPlotData.SetFlag(CvWorldBuilderMap::PlotMapData::RIVER_FLOW_NW);1403 else1404 kPlotData.ClearFlag(CvWorldBuilderMap::PlotMapData::RIVER_FLOW_NW);1405 }1406 else1407 {1408 kPlotData.ClearFlag(CvWorldBuilderMap::PlotMapData::NE_OF_RIVER);1409 }14101411 kPlotData.SetContinentType(pkPlot->GetContinentType());1412 }14131414 return sg_kSave.Save(wszFilename, sg_kMapTypeDesc, false);1415}