CvMinorCivAI::GetBestWonderForQuest(PlayerTypes)
- Defined in
- CvMinorCivAI.cpp, line 5659
- Class
- CvMinorCivAI
- Hook name
CivHooks::CvMinorCivAI_GetBestWonderForQuest
Hooks
static bool BeforeCvMinorCivAI_GetBestWonderForQuest(CvMinorCivAI* self, PlayerTypes ePlayer, BuildingTypes& result);static void AfterCvMinorCivAI_GetBestWonderForQuest(CvMinorCivAI* self, PlayerTypes ePlayer, BuildingTypes& result);static BuildingTypes ReplaceCvMinorCivAI_GetBestWonderForQuest(BuildingTypes (*original)(CvMinorCivAI*, PlayerTypes), CvMinorCivAI* self, PlayerTypes ePlayer);CivRegisterBefore<CivHooks::CvMinorCivAI_GetBestWonderForQuest>(host, &BeforeCvMinorCivAI_GetBestWonderForQuest);CivRegisterAfter<CivHooks::CvMinorCivAI_GetBestWonderForQuest>(host, &AfterCvMinorCivAI_GetBestWonderForQuest);CivRegisterReplace<CivHooks::CvMinorCivAI_GetBestWonderForQuest>(host, &ReplaceCvMinorCivAI_GetBestWonderForQuest);
Code
5658/// Best wonder for a Quest given to ePlayer?5659BuildingTypes CvMinorCivAI::GetBestWonderForQuest(PlayerTypes ePlayer)5660{5661 BuildingTypes eBestWonder;56625663 FStaticVector<BuildingTypes, 50, true, c_eCiv5GameplayDLL, 0> veValidBuildings; // 50 wonders should be overkill56645665 int iWorldPlayerLoop;5666 PlayerTypes eWorldPlayer;5667 CvCity* pLoopCity;5668 int iCityLoop;5669 int iWonderProgress;5670 int iCompletionThreshold = /*25*/ GC.getMINOR_CIV_QUEST_WONDER_COMPLETION_THRESHOLD();5671 bool bFoundWonderTooFarAlong;56725673 // Loop through all Buildings and see if they're useful5674 for(int iBuildingLoop = 0; iBuildingLoop < GC.getNumBuildingInfos(); iBuildingLoop++)5675 {5676 const BuildingTypes eBuilding = static_cast<BuildingTypes>(iBuildingLoop);5677 CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBuilding);56785679 //Skip if NULL5680 if(pkBuildingInfo == NULL)5681 continue;56825683 bFoundWonderTooFarAlong = false;56845685 // Must be a wonder5686 if(!isWorldWonderClass(pkBuildingInfo->GetBuildingClassInfo()))5687 {5688 continue;5689 }56905691 // Must be able to build it5692 if(!GET_PLAYER(ePlayer).canConstruct(eBuilding))5693 {5694 continue;5695 }56965697 // Someone CAN be building this wonder right now, but they can't be more than a certain % of the way done (25% by default)5698 for(iWorldPlayerLoop = 0; iWorldPlayerLoop < MAX_MAJOR_CIVS; iWorldPlayerLoop++)5699 {5700 eWorldPlayer = (PlayerTypes) iWorldPlayerLoop;57015702 for(pLoopCity = GET_PLAYER(eWorldPlayer).firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(eWorldPlayer).nextCity(&iCityLoop))5703 {5704 iWonderProgress = pLoopCity->GetCityBuildings()->GetBuildingProduction(eBuilding);57055706 if(iWonderProgress * 100 / pLoopCity->getProductionNeeded(eBuilding) >= iCompletionThreshold)5707 {5708 bFoundWonderTooFarAlong = true;5709 break;5710 }5711 }5712 if(bFoundWonderTooFarAlong)5713 {5714 break;5715 }5716 }5717 if(bFoundWonderTooFarAlong)5718 {5719 continue;5720 }57215722 veValidBuildings.push_back(eBuilding);5723 }57245725 // Didn't find any valid Wonders5726 if(veValidBuildings.size() == 0)5727 {5728 return NO_BUILDING;5729 }57305731 int iRandIndex = GC.getGame().getJonRandNum(veValidBuildings.size(), "Finding random Wonder for Minor to give out a quest to construct.");5732 eBestWonder = veValidBuildings[iRandIndex];57335734 return eBestWonder;5735}
Calls
BaseVector::operator[]BaseVector::size- CvBuildingEntry::GetBuildingClassInfo() const
- CvCity::GetCityBuildings() const
- CvCity::getProductionNeeded(BuildingTypes) const
- CvCityBuildings::GetBuildingProduction(BuildingTypes) const
- CvGame::getJonRandNum(int, const char *)
- CvGlobals::getBuildingInfo(BuildingTypes)
- CvGlobals::getGame()
- CvGlobals::getMINOR_CIV_QUEST_WONDER_COMPLETION_THRESHOLD()
- CvGlobals::getNumBuildingInfos()
- CvPlayer::canConstruct(BuildingTypes, bool, bool, bool, CvString *) const
- CvPlayer::firstCity(int *, bool)
- CvPlayer::nextCity(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
FStaticVector::FStaticVectorFStaticVector::push_back- isWorldWonderClass(const CvBuildingClassInfo &)