Hooks
static bool BeforeCvPlayerAI_AI_conquerCity(CvPlayerAI* self, CvCity* pCity, PlayerTypes eOldOwner);static void AfterCvPlayerAI_AI_conquerCity(CvPlayerAI* self, CvCity* pCity, PlayerTypes eOldOwner);static void ReplaceCvPlayerAI_AI_conquerCity(void (*original)(CvPlayerAI*, CvCity*, PlayerTypes), CvPlayerAI* self, CvCity* pCity, PlayerTypes eOldOwner);CivRegisterBefore<CivHooks::CvPlayerAI_AI_conquerCity>(host, &BeforeCvPlayerAI_AI_conquerCity);CivRegisterAfter<CivHooks::CvPlayerAI_AI_conquerCity>(host, &AfterCvPlayerAI_AI_conquerCity);CivRegisterReplace<CivHooks::CvPlayerAI_AI_conquerCity>(host, &ReplaceCvPlayerAI_AI_conquerCity);
Code
285void CvPlayerAI::AI_conquerCity(CvCity* pCity, PlayerTypes eOldOwner)286{287 PlayerTypes eOriginalOwner = pCity->getOriginalOwner();288 TeamTypes eOldOwnerTeam = GET_PLAYER(eOldOwner).getTeam();289290 // Liberate a city?291 if(eOriginalOwner != eOldOwner && eOriginalOwner != GetID() && CanLiberatePlayerCity(eOriginalOwner))292 {293 // minor civ294 if(GET_PLAYER(eOriginalOwner).isMinorCiv())295 {296 if(GetDiplomacyAI()->DoPossibleMinorLiberation(eOriginalOwner, pCity->GetID()))297 return;298 }299 else // major civ300 {301 bool bLiberate = false;302 if (GET_PLAYER(eOriginalOwner).isAlive())303 {304 // If the original owner and this player have a defensive pact305 // and both the original owner and the player are at war with the old owner of this city306 // give the city back to the original owner307 TeamTypes eOriginalOwnerTeam = GET_PLAYER(eOriginalOwner).getTeam();308 if (GET_TEAM(getTeam()).IsHasDefensivePact(eOriginalOwnerTeam) && GET_TEAM(getTeam()).isAtWar(eOldOwnerTeam) && GET_TEAM(eOriginalOwnerTeam).isAtWar(eOldOwnerTeam))309 {310 bLiberate = true;311 }312 // if the player is a friend and we're going for diplo victory, then liberate to score some friend points313 else if (GetDiplomacyAI()->IsDoFAccepted(eOriginalOwner) && GetDiplomacyAI()->IsGoingForDiploVictory())314 {315 bLiberate = true;316 }317 }318 // if the player isn't human and we're going for diplo victory, resurrect players to get super diplo bonuses319 else if (!GET_PLAYER(eOriginalOwner).isHuman() && GetDiplomacyAI()->IsGoingForDiploVictory())320 {321 bLiberate = true;322 }323324 if (bLiberate)325 {326 DoLiberatePlayer(eOriginalOwner, pCity->GetID());327 return;328 }329 }330 }331332 // Do we want to burn this city down?333 if(canRaze(pCity))334 {335 // Burn the city if the empire is unhappy - keeping the city will only make things worse or if map hint dictates336 // Huns will burn down everything possible once they have a core of a few cities (was 3, but this put Attila out of the running long term as a conqueror)337#if defined(MOD_GLOBAL_CS_RAZE_RARELY)338 CUSTOMLOG("AI_conquerCity: City=%s, Player=%d, ExcessHappiness=%d", pCity->getName().GetCString(), GetID(), GetExcessHappiness());339 bool bUnhappy = isMinorCiv() ? IsEmpireVeryUnhappy() : IsEmpireUnhappy();340 if (bUnhappy || (GC.getMap().GetAIMapHint() & 2) || (GetPlayerTraits()->GetRazeSpeedModifier() > 0 && getNumCities() >= 3 + (GC.getGame().getGameTurn() / 100)) )341#else342 if (IsEmpireUnhappy() || (GC.getMap().GetAIMapHint() & 2) || (GetPlayerTraits()->GetRazeSpeedModifier() > 0 && getNumCities() >= 3 + (GC.getGame().getGameTurn() / 100)) )343#endif344 {345 pCity->doTask(TASK_RAZE);346 return;347 }348 }349350 // Puppet the city351 if(pCity->getOriginalOwner() != GetID() || GET_PLAYER(m_eID).GetPlayerTraits()->IsNoAnnexing())352 {353 pCity->DoCreatePuppet();354 }355}