CvCityCitizens::DoAddBestCitizenFromUnassigned()
- Defined in
- CvCityCitizens.cpp, line 1333
- Class
- CvCityCitizens
- Hook name
CivHooks::CvCityCitizens_DoAddBestCitizenFromUnassigned
Hooks
static bool BeforeCvCityCitizens_DoAddBestCitizenFromUnassigned(CvCityCitizens* self, bool& result);static void AfterCvCityCitizens_DoAddBestCitizenFromUnassigned(CvCityCitizens* self, bool& result);static bool ReplaceCvCityCitizens_DoAddBestCitizenFromUnassigned(bool (*original)(CvCityCitizens*), CvCityCitizens* self);CivRegisterBefore<CivHooks::CvCityCitizens_DoAddBestCitizenFromUnassigned>(host, &BeforeCvCityCitizens_DoAddBestCitizenFromUnassigned);CivRegisterAfter<CivHooks::CvCityCitizens_DoAddBestCitizenFromUnassigned>(host, &AfterCvCityCitizens_DoAddBestCitizenFromUnassigned);CivRegisterReplace<CivHooks::CvCityCitizens_DoAddBestCitizenFromUnassigned>(host, &ReplaceCvCityCitizens_DoAddBestCitizenFromUnassigned);
Code
1332/// Pick the best Plot to work from one of our unassigned pool1333bool CvCityCitizens::DoAddBestCitizenFromUnassigned()1334{1335 // We only assign the unassigned here, folks1336 if (GetNumUnassignedCitizens() == 0)1337 {1338 return false;1339 }13401341 // First Specialist Pass1342 int iSpecialistValue = 0;1343 BuildingTypes eBestSpecialistBuilding = NO_BUILDING;1344 if (!IsNoAutoAssignSpecialists())1345 {1346 eBestSpecialistBuilding = GetAIBestSpecialistBuilding(iSpecialistValue);1347 }13481349 bool bBetterThanSlacker = false;1350 if (eBestSpecialistBuilding != NO_BUILDING)1351 {1352 CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBestSpecialistBuilding);1353 if(pkBuildingInfo)1354 {1355 SpecialistTypes eSpecialist = (SpecialistTypes) pkBuildingInfo->GetSpecialistType();1356 // Must not be worse than a default Specialist for our focus!1357 if (IsBetterThanDefaultSpecialist(eSpecialist))1358 {1359 bBetterThanSlacker = true;1360 }1361 }1362 }13631364 int iBestPlotValue = 0;1365 CvPlot* pBestPlot = GetBestCityPlotWithValue(iBestPlotValue, /*bBest*/ true, /*bWorked*/ false);13661367 bool bSpecialistBetterThanPlot = (eBestSpecialistBuilding != NO_BUILDING && iSpecialistValue >= iBestPlotValue);13681369 // Is there a Specialist we can assign?1370 if (bSpecialistBetterThanPlot && bBetterThanSlacker)1371 {1372 DoAddSpecialistToBuilding(eBestSpecialistBuilding, /*bForced*/ false);1373 return true;1374 }1375 // Found a Valid Plot to place a guy?1376 else if (!bSpecialistBetterThanPlot && pBestPlot != NULL)1377 {1378 // Now assign the guy to the best possible Plot1379 SetWorkingPlot(pBestPlot, true);1380 return true;1381 }1382 // No Valid Plots left - and no good specialists1383 else1384 {1385 CvPlayer* pOwner = &GET_PLAYER(GetOwner());1386 CvAssertMsg(pOwner, "Could not find owner of city when assigning citizens. Please send Anton your save file and version.");13871388 // Assign a cool Specialist! Only do this for AI players, or humans who do not have manual specialist control set1389 if (pOwner)1390 {1391 if (!GET_PLAYER(GetOwner()).isHuman() || !IsNoAutoAssignSpecialists())1392 {1393 BuildingTypes eBestBuilding = GetAIBestSpecialistBuilding(iSpecialistValue);1394 if(eBestBuilding != NO_BUILDING)1395 {1396 CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBestBuilding);1397 if(pkBuildingInfo)1398 {1399 SpecialistTypes eSpecialist = (SpecialistTypes) pkBuildingInfo->GetSpecialistType();1400 // Must not be worse than a default Specialist for our focus!1401 if (IsBetterThanDefaultSpecialist(eSpecialist))1402 {1403 DoAddSpecialistToBuilding(eBestBuilding, false);1404 return true;1405 }1406 }1407 }1408 }1409 }14101411 // Default Specialist if we can't do anything else1412 ChangeNumDefaultSpecialists(1);1413 }14141415 return false;1416}
Calls
- CvBuildingEntry::GetSpecialistType() const
- CvCityCitizens::ChangeNumDefaultSpecialists(int)
- CvCityCitizens::DoAddSpecialistToBuilding(BuildingTypes, bool)
- CvCityCitizens::GetAIBestSpecialistBuilding(int &)
- CvCityCitizens::GetBestCityPlotWithValue(int &, bool, bool)
- CvCityCitizens::GetNumUnassignedCitizens() const
- CvCityCitizens::GetOwner() const
- CvCityCitizens::IsBetterThanDefaultSpecialist(SpecialistTypes)
- CvCityCitizens::IsNoAutoAssignSpecialists() const
- CvCityCitizens::SetWorkingPlot(CvPlot *, bool, bool)
- CvGlobals::getBuildingInfo(BuildingTypes)
- CvPlayer::isHuman() const
- CvPlayerAI::getPlayer(PlayerTypes)