CvPlot::DoFindCityToLinkResourceTo(CvCity *)
- Defined in
- CvPlot.cpp, line 7495
- Class
- CvPlot
- Hook name
CivHooks::CvPlot_DoFindCityToLinkResourceTo
Hooks
static bool BeforeCvPlot_DoFindCityToLinkResourceTo(CvPlot* self, CvCity* pCityToExclude);static void AfterCvPlot_DoFindCityToLinkResourceTo(CvPlot* self, CvCity* pCityToExclude);static void ReplaceCvPlot_DoFindCityToLinkResourceTo(void (*original)(CvPlot*, CvCity*), CvPlot* self, CvCity* pCityToExclude);CivRegisterBefore<CivHooks::CvPlot_DoFindCityToLinkResourceTo>(host, &BeforeCvPlot_DoFindCityToLinkResourceTo);CivRegisterAfter<CivHooks::CvPlot_DoFindCityToLinkResourceTo>(host, &AfterCvPlot_DoFindCityToLinkResourceTo);CivRegisterReplace<CivHooks::CvPlot_DoFindCityToLinkResourceTo>(host, &ReplaceCvPlot_DoFindCityToLinkResourceTo);
Code
7494/// Find the closest nearby city to link the Resource here to7495void CvPlot::DoFindCityToLinkResourceTo(CvCity* pCityToExclude)7496{7497 // Make sure we can actually use this Resource first74987499 // No resource here period7500 if(getResourceType() == NO_RESOURCE)7501 return;75027503 ResourceTypes eResource = getResourceType(getTeam());75047505 // Owner can't see resource here yet7506 if(eResource == NO_RESOURCE)7507 return;75087509 CvCity* pBestCity = NULL;75107511 // Loop through nearby plots to find the closest city to link to7512 CvPlot* pLoopPlot;7513#if defined(MOD_GLOBAL_CITY_WORKING)7514 for(int iJ = 0; iJ < MAX_CITY_PLOTS; iJ++)7515#else7516 for(int iJ = 0; iJ < NUM_CITY_PLOTS; iJ++)7517#endif7518 {7519 // We're not actually looking around a City but Resources have to be within the RANGE of a City, so we can still use this7520 pLoopPlot = plotCity(getX(), getY(), iJ);75217522 if(pLoopPlot != NULL)7523 {7524 CvCity* pLoopCity = pLoopPlot->getPlotCity();7525 if(pLoopCity)7526 {7527 // Owner of the City must match the owner of the Resource Plot Tile (Don't want to give the Resource to another player!)7528 if(pLoopCity->getOwner() == getOwner())7529 {7530 if(pLoopCity != pCityToExclude)7531 {7532 pBestCity = pLoopCity;75337534 break;7535 }7536 }7537 }7538 }7539 }75407541 if(pBestCity != NULL)7542 {7543 SetResourceLinkedCity(pBestCity);75447545 // Already have a valid improvement here?7546 if(isCity() || getImprovementType() != NO_IMPROVEMENT)7547 {7548 if(isCity() || GC.getImprovementInfo(getImprovementType())->IsImprovementResourceTrade(getResourceType()))7549 {7550 SetResourceLinkedCityActive(true);7551 }7552 }7553 }7554}
Calls
- CvCity::getOwner() const
- CvGlobals::getImprovementInfo(ImprovementTypes)
- CvImprovementEntry::IsImprovementResourceTrade(int) const
- CvPlot::getImprovementType() const
- CvPlot::getOwner() const
- CvPlot::getPlotCity() const
- CvPlot::getResourceType(TeamTypes) const
- CvPlot::getTeam() const
- CvPlot::getX() const
- CvPlot::getY() const
- CvPlot::isCity() const
- CvPlot::SetResourceLinkedCity(const CvCity *)
- CvPlot::SetResourceLinkedCityActive(bool)
- plotCity(int, int, int)