CvWonderProductionAI::ChooseWonderForGreatEngineer(bool, int &, CvCity *&)
- Defined in
- CvWonderProductionAI.cpp, line 361
- Class
- CvWonderProductionAI
- Hook name
CivHooks::CvWonderProductionAI_ChooseWonderForGreatEngineer
Hooks
static bool BeforeCvWonderProductionAI_ChooseWonderForGreatEngineer(CvWonderProductionAI* self, bool bUseAsyncRandom, int& iWonderWeight, CvCity*& pCityToBuildAt, BuildingTypes& result);static void AfterCvWonderProductionAI_ChooseWonderForGreatEngineer(CvWonderProductionAI* self, bool bUseAsyncRandom, int& iWonderWeight, CvCity*& pCityToBuildAt, BuildingTypes& result);static BuildingTypes ReplaceCvWonderProductionAI_ChooseWonderForGreatEngineer(BuildingTypes (*original)(CvWonderProductionAI*, bool, int&, CvCity*&), CvWonderProductionAI* self, bool bUseAsyncRandom, int& iWonderWeight, CvCity*& pCityToBuildAt);CivRegisterBefore<CivHooks::CvWonderProductionAI_ChooseWonderForGreatEngineer>(host, &BeforeCvWonderProductionAI_ChooseWonderForGreatEngineer);CivRegisterAfter<CivHooks::CvWonderProductionAI_ChooseWonderForGreatEngineer>(host, &AfterCvWonderProductionAI_ChooseWonderForGreatEngineer);CivRegisterReplace<CivHooks::CvWonderProductionAI_ChooseWonderForGreatEngineer>(host, &ReplaceCvWonderProductionAI_ChooseWonderForGreatEngineer);
Code
360/// Recommend highest-weighted wonder and what city to build it at361BuildingTypes CvWonderProductionAI::ChooseWonderForGreatEngineer(bool bUseAsyncRandom, int& iWonderWeight, CvCity*& pCityToBuildAt)362{363 int iBldgLoop;364 int iWeight;365 int iCityLoop;366 RandomNumberDelegate fcn;367 BuildingTypes eSelection;368369 pCityToBuildAt = 0;370 iWonderWeight = 0;371372 // Use the asynchronous random number generate if "no random" is set373 if (bUseAsyncRandom)374 {375 fcn = MakeDelegate(&GC.getGame(), &CvGame::getAsyncRandNum);376 }377 else378 {379 fcn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum);380 }381382 // Reset list of all the possible wonders383 m_Buildables.clear();384385 // Guess which city will be producing this386 CvCity* pWonderCity = m_pPlayer->GetCitySpecializationAI()->GetWonderBuildCity();387 if (pWonderCity == NULL)388 {389 pWonderCity = m_pPlayer->firstCity(&iCityLoop);390 }391392 CvAssertMsg(pWonderCity, "Trying to choose the next wonder to build and the player has no cities!");393 if (pWonderCity == NULL)394 return NO_BUILDING;395396 // Loop through adding the available wonders397 for (iBldgLoop = 0; iBldgLoop < GC.GetGameBuildings()->GetNumBuildings(); iBldgLoop++)398 {399 const BuildingTypes eBuilding = static_cast<BuildingTypes>(iBldgLoop);400 CvBuildingEntry* pkBuildingInfo = m_pBuildings->GetEntry(eBuilding);401 if (pkBuildingInfo)402 {403 CvBuildingEntry& kBuilding = *pkBuildingInfo;404 // Make sure this wonder can be built now405 if (IsWonder(kBuilding) && HaveCityToBuild((BuildingTypes)iBldgLoop))406 {407 iWeight = m_WonderAIWeights.GetWeight((UnitTypes)iBldgLoop); // use raw weight since this wonder is essentially free408 // Don't build the UN if you aren't going for the diplo victory and have a chance of winning it409 if(pkBuildingInfo->IsDiplomaticVoting())410 {411 int iVotesNeededToWin = GC.getGame().GetVotesNeededForDiploVictory();412 int iSecuredVotes = 0;413 TeamTypes myTeamID = m_pPlayer->getTeam();414 PlayerTypes myPlayerID = m_pPlayer->GetID();415416 // Loop through Players to see if they'll vote for this player417 PlayerTypes eLoopPlayer;418 TeamTypes eLoopTeam;419 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)420 {421 eLoopPlayer = (PlayerTypes) iPlayerLoop;422423 if(GET_PLAYER(eLoopPlayer).isAlive())424 {425 eLoopTeam = GET_PLAYER(eLoopPlayer).getTeam();426427 // Liberated?428 if(GET_TEAM(eLoopTeam).GetLiberatedByTeam() == myTeamID)429 {430 iSecuredVotes++;431 }432433 // Minor civ?434 else if(GET_PLAYER(eLoopPlayer).isMinorCiv())435 {436 // Best Relations?437 if(GET_PLAYER(eLoopPlayer).GetMinorCivAI()->GetAlly() == myPlayerID)438 {439 iSecuredVotes++;440 }441 }442 }443 }444445 int iNumberOfPlayersWeNeedToBuyOff = MAX(0, iVotesNeededToWin - iSecuredVotes);446447 if(!m_pPlayer->GetDiplomacyAI() || !m_pPlayer->GetDiplomacyAI()->IsGoingForDiploVictory() || m_pPlayer->GetTreasury()->GetGold() < iNumberOfPlayersWeNeedToBuyOff * 500 )448 {449 iWeight = 0;450 }451 }452 // ??? do we want to weight it more for more expensive wonders?453 m_Buildables.push_back(iBldgLoop, iWeight);454 }455 }456 }457458 // Sort items and grab the first one459 if(m_Buildables.size() > 0)460 {461 m_Buildables.SortItems();462 LogPossibleWonders();463464 if(m_Buildables.GetTotalWeight() > 0)465 {466 int iNumChoices = 1;467 eSelection = (BuildingTypes)m_Buildables.ChooseFromTopChoices(iNumChoices, &fcn, "Choosing wonder from Top Choices");468 iWonderWeight = m_Buildables.GetTotalWeight();469470 // first check if the wonder city can build it471 if (pWonderCity->canConstruct(eSelection))472 {473 pCityToBuildAt = pWonderCity;474 }475 // if it can't then check for other cities476 else477 {478 CvCity* pLoopCity;479 int iLoop;480 for(pLoopCity = m_pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoop))481 {482 if(pLoopCity->canConstruct(eSelection))483 {484 pCityToBuildAt = pLoopCity;485 break; // todo: find the best city 486 }487 }488 }489490 return eSelection;491 }492493 // Nothing with any weight494 else495 {496 return NO_BUILDING;497 }498 }499500 // Unless we didn't find any501 else502 {503 return NO_BUILDING;504 }505}
Calls
- CvBuildingEntry::IsDiplomaticVoting() const
- CvBuildingXMLEntries::GetEntry(int)
- CvBuildingXMLEntries::GetNumBuildings()
- CvCity::canConstruct(BuildingTypes, bool, bool, bool, bool, CvString *) const
- CvCitySpecializationAI::GetWonderBuildCity() const
- CvDiplomacyAI::IsGoingForDiploVictory()
- CvGame::getAsyncRandNum(int, const char *)
- CvGame::getJonRandNum(int, const char *)
- CvGame::GetVotesNeededForDiploVictory() const
- CvGlobals::getGame()
- CvGlobals::GetGameBuildings() const
- CvMinorCivAI::GetAlly() const
- CvPlayer::firstCity(int *, bool)
- CvPlayer::GetCitySpecializationAI() const
- CvPlayer::GetDiplomacyAI() const
- CvPlayer::GetID() const
- CvPlayer::GetMinorCivAI() const
- CvPlayer::getTeam() const
- CvPlayer::GetTreasury() const
- CvPlayer::isAlive() const
- CvPlayer::isMinorCiv() const
- CvPlayer::nextCity(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvTeam::GetLiberatedByTeam() const
- CvTeam::getTeam(TeamTypes)
- CvTreasury::GetGold() const
CvWeightedVector::ChooseFromTopChoicesCvWeightedVector::clearCvWeightedVector::GetTotalWeightCvWeightedVector::GetWeightCvWeightedVector::push_backCvWeightedVector::sizeCvWeightedVector::SortItems- CvWonderProductionAI::HaveCityToBuild(BuildingTypes) const
- CvWonderProductionAI::IsWonder(const CvBuildingEntry &) const
- CvWonderProductionAI::LogPossibleWonders()
fastdelegate::FastDelegate2::FastDelegate2fastdelegate::FastDelegate2::operator=fastdelegate::MakeDelegatestd::max