Hooks
static bool BeforeCvCityAI_AI_chooseProduction(CvCityAI* self, bool bInterruptWonders);static void AfterCvCityAI_AI_chooseProduction(CvCityAI* self, bool bInterruptWonders);static void ReplaceCvCityAI_AI_chooseProduction(void (*original)(CvCityAI*, bool), CvCityAI* self, bool bInterruptWonders);CivRegisterBefore<CivHooks::CvCityAI_AI_chooseProduction>(host, &BeforeCvCityAI_AI_chooseProduction);CivRegisterAfter<CivHooks::CvCityAI_AI_chooseProduction>(host, &AfterCvCityAI_AI_chooseProduction);CivRegisterReplace<CivHooks::CvCityAI_AI_chooseProduction>(host, &ReplaceCvCityAI_AI_chooseProduction);
Code
83void CvCityAI::AI_chooseProduction(bool bInterruptWonders)84{85 VALIDATE_OBJECT86 CvPlayerAI& kOwner = GET_PLAYER(getOwner());87 CvCitySpecializationAI* pSpecializationAI = kOwner.GetCitySpecializationAI();88 bool bBuildWonder = false;8990 // See if this is the one AI city that is supposed to be building wonders91 if(pSpecializationAI->GetWonderBuildCity() == this)92 {93 // Is it still working on that wonder and we don't want to interrupt it?94 if(!bInterruptWonders)95 {96 const BuildingTypes eBuilding = getProductionBuilding();97 CvBuildingEntry* pkBuilding = (eBuilding != NO_BUILDING)? GC.getBuildingInfo(eBuilding) : NULL;98 if(pkBuilding && kOwner.GetWonderProductionAI()->IsWonder(*pkBuilding))99 {100 return; // Stay the course101 }102 }103104 // So we're the wonder building city but it is not underway yet...105106 // Has the designated wonder been poached by another civ?107 BuildingTypes eNextWonder = pSpecializationAI->GetNextWonderDesired();108 if(!canConstruct(eNextWonder))109 {110 // Reset city specialization111 kOwner.GetCitySpecializationAI()->SetSpecializationsDirty(SPECIALIZATION_UPDATE_WONDER_BUILT_BY_RIVAL);112 }113 else114 {115#if defined(MOD_AI_SMART_V3)116 bool checkBuildWonder = true;117 118 // All of this only has sense if the AI is able to expand...119 if (MOD_AI_SMART_V3 && !GC.getGame().isOption(GAMEOPTION_ONE_CITY_CHALLENGE))120 {121 int cityExpansionFlavor = m_pCityStrategyAI->GetLatestFlavorValue((FlavorTypes)GC.getInfoTypeForString("FLAVOR_EXPANSION"));122 int cityWonderFlavor = m_pCityStrategyAI->GetLatestFlavorValue((FlavorTypes)GC.getInfoTypeForString("FLAVOR_WONDER"));123 // Check if at city, the player has more desire to expand than to build wonders.124 if ((cityExpansionFlavor - cityWonderFlavor) > 0)125 {126 int currentCityProd = 0;127 int allOthercitiesProd = 0;128 CvCity* pLoopCity = NULL;129 int iLoop = 0;130 // Lets check production of wonder city vs production in all cities.131 for(pLoopCity = kOwner.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kOwner.nextCity(&iLoop))132 {133 int cityProd = pLoopCity->getCurrentProductionDifference(true, false);134 if (pLoopCity == this)135 {136 currentCityProd = cityProd;137 }138 else139 {140 allOthercitiesProd += cityProd;141 }142 }143 bool bMostProductionInCity = (currentCityProd - (allOthercitiesProd * 2)) > 0;144 // If the production of city equals 66% all empire production, lets stop wonder choose.145 checkBuildWonder = !bMostProductionInCity;146 } 147 }148 149 if (checkBuildWonder)150 {151#endif152 // to prevent us from continuously locking into building wonders in one city when there are other high priority items to build153 int iFlavorWonder = kOwner.GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes)GC.getInfoTypeForString("FLAVOR_WONDER"));154 int iFlavorGP = kOwner.GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes)GC.getInfoTypeForString("FLAVOR_GREAT_PEOPLE"));155 int iFlavor = (iFlavorWonder > iFlavorGP ) ? iFlavorWonder : iFlavorGP;156 if (GC.getGame().getJonRandNum(11, "Random roll for whether to continue building wonders") <= iFlavor)157 bBuildWonder = true;158#if defined(MOD_AI_SMART_V3)159 }160#endif161 }162 }163164 if(bBuildWonder)165 {166 CvCityBuildable buildable;167 buildable.m_eBuildableType = CITY_BUILDABLE_BUILDING;168 buildable.m_iIndex = pSpecializationAI->GetNextWonderDesired();169 buildable.m_iTurnsToConstruct = getProductionTurnsLeft((BuildingTypes)buildable.m_eBuildableType, 0);170 pushOrder(ORDER_CONSTRUCT, buildable.m_iIndex, -1, false, false, false, false);171172 if(GC.getLogging() && GC.getAILogging())173 {174 CvString playerName;175 FILogFile* pLog;176 CvString strBaseString;177 CvString strOutBuf;178179 m_pCityStrategyAI->LogCityProduction(buildable, false);180181 playerName = kOwner.getCivilizationShortDescription();182 pLog = LOGFILEMGR.GetLog(kOwner.GetCitySpecializationAI()->GetLogFileName(playerName), FILogFile::kDontTimeStamp);183 strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());184 strBaseString += playerName + ", ";185 strOutBuf.Format("%s, WONDER - Started %s, Turns: %d", getName().GetCString(), GC.getBuildingInfo((BuildingTypes)buildable.m_iIndex)->GetDescription(), buildable.m_iTurnsToConstruct);186 strBaseString += strOutBuf;187 pLog->Msg(strBaseString);188 }189 }190191 else192 {193 m_pCityStrategyAI->ChooseProduction(false);194 AI_setChooseProductionDirty(false);195 }196197 return;198}