Hooks
static bool BeforeCvPreGame_setCustomWorldSize(int iWidth, int iHeight, int iPlayers, int iMinorCivs);static void AfterCvPreGame_setCustomWorldSize(int iWidth, int iHeight, int iPlayers, int iMinorCivs);static void ReplaceCvPreGame_setCustomWorldSize(void (*original)(int, int, int, int), int iWidth, int iHeight, int iPlayers, int iMinorCivs);CivRegisterBefore<CivHooks::CvPreGame_setCustomWorldSize>(host, &BeforeCvPreGame_setCustomWorldSize);CivRegisterAfter<CivHooks::CvPreGame_setCustomWorldSize>(host, &AfterCvPreGame_setCustomWorldSize);CivRegisterReplace<CivHooks::CvPreGame_setCustomWorldSize>(host, &ReplaceCvPreGame_setCustomWorldSize);
Code
2398void setCustomWorldSize(int iWidth, int iHeight, int iPlayers, int iMinorCivs)2399{2400 FAssertMsg(iWidth >= 20 && iHeight >= 20, "Cannot have a map that small!");24012402 const int iArea = iWidth * iHeight;24032404 CvWorldInfo kClosestSizeType;2405 int iSmallestAreaDifference = 64000; // Arbitrarily large at start24062407 Database::Results kWorldSizes;2408 DB.SelectAll(kWorldSizes, "Worlds");2409 while(kWorldSizes.Step())2410 {2411 CvWorldInfo kInfo;2412 kInfo.CacheResult(kWorldSizes);24132414 int iSizeTypeArea = kInfo.getGridWidth() * kInfo.getGridHeight();2415 int iAreaDifference = abs(iArea - iSizeTypeArea);2416 if(iAreaDifference < iSmallestAreaDifference)2417 {2418 iSmallestAreaDifference = iAreaDifference;2419 kClosestSizeType = kInfo;2420 }2421 }24222423 s_worldSize = (WorldSizeTypes)kClosestSizeType.GetID();2424 if(iPlayers > 0 || !CvPreGame::mapNoPlayers())2425 s_worldInfo = CvWorldInfo::CreateCustomWorldSize(kClosestSizeType, iWidth, iHeight, iPlayers, iMinorCivs);2426 else2427 s_worldInfo = CvWorldInfo::CreateCustomWorldSize(kClosestSizeType, iWidth, iHeight);2428}