Bazaar developer reference

CvPlayer::acquireCity(CvCity *, bool, bool, bool)

Defined in
CvPlayer.cpp, line 1938
Class
CvPlayer
Hook name
CivHooks::CvPlayer_acquireCity
Changed in
0.5.0 (added hand-placed hook CityReplaced)
Lua events
GameEvents.CapitalChanged, GameEvents.CityCaptureComplete

Hand-placed hooks inside

A replacement for this function that does not call original stops these hooks from running.

Hooks

static bool BeforeCvPlayer_acquireCity(CvPlayer* self, CvCity* pOldCity, bool bConquest, bool bGift, bool bKeepResources, CvCity*& result);static void AfterCvPlayer_acquireCity(CvPlayer* self, CvCity* pOldCity, bool bConquest, bool bGift, bool bKeepResources, CvCity*& result);static CvCity* ReplaceCvPlayer_acquireCity(CvCity* (*original)(CvPlayer*, CvCity*, bool, bool, bool), CvPlayer* self, CvCity* pOldCity, bool bConquest, bool bGift, bool bKeepResources);CivRegisterBefore<CivHooks::CvPlayer_acquireCity>(host, &BeforeCvPlayer_acquireCity);CivRegisterAfter<CivHooks::CvPlayer_acquireCity>(host, &AfterCvPlayer_acquireCity);CivRegisterReplace<CivHooks::CvPlayer_acquireCity>(host, &ReplaceCvPlayer_acquireCity);

Code

1935// NOTE: bGift set to true if the city is given as a gift, as in the case for trades and Austria UA of annexing city-states1936#if defined(MOD_API_EXTENSIONS)1937#if defined(MOD_GLOBAL_VENICE_KEEPS_RESOURCES) || defined(MOD_GLOBAL_CS_MARRIAGE_KEEPS_RESOURCES)1938CvCity* CvPlayer::acquireCity(CvCity* pOldCity, bool bConquest, bool bGift, bool bKeepResources)1939#else1940CvCity* CvPlayer::acquireCity(CvCity* pOldCity, bool bConquest, bool bGift)1941#endif1942#else1943#if defined(MOD_GLOBAL_VENICE_KEEPS_RESOURCES) || defined(MOD_GLOBAL_CS_MARRIAGE_KEEPS_RESOURCES)1944void CvPlayer::acquireCity(CvCity* pOldCity, bool bConquest, bool bGift, bool bKeepResources)1945#else1946void CvPlayer::acquireCity(CvCity* pOldCity, bool bConquest, bool bGift)1947#endif1948#endif1949{1950	if(pOldCity == NULL)1951#if defined(MOD_API_EXTENSIONS)1952		return NULL;1953#else1954		return;1955#endif19561957	IDInfo* pUnitNode;1958	CvCity* pNewCity;1959	CvUnit* pLoopUnit;1960	CvPlot* pCityPlot;19611962	CvString strBuffer;1963	CvString strName;1964	bool abEverOwned[MAX_PLAYERS];1965	PlayerTypes eOldOwner;1966	PlayerTypes eOriginalOwner;1967	BuildingTypes eBuilding;1968	bool bRecapture;1969	int iCaptureGold;1970	int iCaptureCulture;1971	int iCaptureGreatWorks;1972	int iGameTurnFounded;1973	int iPopulation;1974	int iHighestPopulation;1975	int iOldPopulation;1976	int iBattleDamage;1977	int iI;1978	FFastSmallFixedList<IDInfo, 25, true, c_eCiv5GameplayDLL > oldUnits;1979	CvCityReligions tempReligions;1980	bool bIsMinorCivBuyout = (pOldCity->GetPlayer()->isMinorCiv() && bGift && (IsAbleToAnnexCityStates() || GetPlayerTraits()->IsNoAnnexing())); // Austria and Venice UA19811982	pCityPlot = pOldCity->plot();19831984	pUnitNode = pCityPlot->headUnitNode();19851986	while(pUnitNode != NULL)1987	{1988		oldUnits.insertAtEnd(pUnitNode);1989		pUnitNode = pCityPlot->nextUnitNode((IDInfo*)pUnitNode);1990	}19911992	pUnitNode = oldUnits.head();19931994	while(pUnitNode != NULL)1995	{1996		pLoopUnit = ::getUnit(*pUnitNode);1997		pUnitNode = oldUnits.next(pUnitNode);19981999		if(pLoopUnit && pLoopUnit->getTeam() != getTeam())2000		{2001			if(pLoopUnit->IsImmobile())2002			{2003				pLoopUnit->kill(false, GetID());2004#if defined(MOD_API_EXTENSIONS)2005				DoUnitKilledCombat(NULL, pLoopUnit->getOwner(), pLoopUnit->getUnitType());2006#else2007				DoUnitKilledCombat(pLoopUnit->getOwner(), pLoopUnit->getUnitType());2008#endif2009			}2010		}2011	}20122013	if(bConquest)2014	{2015		CvNotifications* pNotifications = GET_PLAYER(pOldCity->getOwner()).GetNotifications();2016		if(pNotifications)2017		{2018			Localization::String locString = Localization::Lookup("TXT_KEY_NOTIFICATION_CITY_LOST");2019			locString << pOldCity->getNameKey() << getNameKey();2020			Localization::String locSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_CITY_LOST");2021			locSummary << pOldCity->getNameKey();2022			pNotifications->Add(NOTIFICATION_CITY_LOST, locString.toUTF8(), locSummary.toUTF8(), pOldCity->getX(), pOldCity->getY(), -1);2023		}20242025		if(!isBarbarian() && !pOldCity->isBarbarian())2026		{2027			int iDefaultCityValue = /*150*/ GC.getWAR_DAMAGE_LEVEL_CITY_WEIGHT();20282029			// Notify Diplo AI that damage has been done2030			int iValue = iDefaultCityValue;2031			iValue += pOldCity->getPopulation() * /*100*/ GC.getWAR_DAMAGE_LEVEL_INVOLVED_CITY_POP_MULTIPLIER();2032			if (pOldCity->IsOriginalCapital())2033			{2034				iValue *= 3;2035				iValue /= 2;2036			}20372038			// My viewpoint2039			GetDiplomacyAI()->ChangeOtherPlayerWarValueLost(pOldCity->getOwner(), GetID(), iValue);2040			// Bad guy's viewpoint2041			GET_PLAYER(pOldCity->getOwner()).GetDiplomacyAI()->ChangeWarValueLost(GetID(), iValue);20422043			// zero out any liberation credit since we just captured a city from them2044			PlayerTypes ePlayer;2045			CvDiplomacyAI* pOldOwnerDiploAI = GET_PLAYER(pOldCity->getOwner()).GetDiplomacyAI();2046			int iNumLiberatedCities = pOldOwnerDiploAI->GetNumCitiesLiberated(GetID());2047			pOldOwnerDiploAI->ChangeNumCitiesLiberated(GetID(), -iNumLiberatedCities);20482049			iValue = iDefaultCityValue;2050			iValue += pOldCity->getPopulation() * /*120*/ GC.getWAR_DAMAGE_LEVEL_UNINVOLVED_CITY_POP_MULTIPLIER();20512052			// Now update everyone else in the world, but use a different multiplier (since they don't have complete info on the situation - they don't know when Units are killed)2053			for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)2054			{2055				ePlayer = (PlayerTypes) iPlayerLoop;20562057				// Not us and not the player we acquired City from2058				if(ePlayer != GetID() && ePlayer != pOldCity->getOwner())2059				{2060					GET_PLAYER(ePlayer).GetDiplomacyAI()->ChangeOtherPlayerWarValueLost(pOldCity->getOwner(), GetID(), iValue);2061				}2062			}2063		}20642065		GetMilitaryAI()->LogCityCaptured(pOldCity, pOldCity->getOwner());2066	}20672068	if(pOldCity->getOriginalOwner() == pOldCity->getOwner())2069	{2070		GET_PLAYER(pOldCity->getOriginalOwner()).changeCitiesLost(1);2071	}2072	else if(pOldCity->getOriginalOwner() == GetID())2073	{2074		GET_PLAYER(pOldCity->getOriginalOwner()).changeCitiesLost(-1);2075	}20762077	if(bConquest)2078	{2079		if(GetID() == GC.getGame().getActivePlayer())2080		{2081			strBuffer = GetLocalizedText("TXT_KEY_MISC_CAPTURED_CITY", pOldCity->getNameKey()).GetCString();2082			GC.GetEngineUserInterface()->AddCityMessage(0, pOldCity->GetIDInfo(), GetID(), true, GC.getEVENT_MESSAGE_TIME(), strBuffer/*, "AS2D_CITYCAPTURE", MESSAGE_TYPE_MAJOR_EVENT, NULL, (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), pOldCity->getX(), pOldCity->getY(), true, true*/);2083			MILITARYLOG(GetID(), strBuffer.c_str(), pOldCity->plot(), pOldCity->getOwner());2084		}20852086		strName.Format("%s (%s)", pOldCity->getName().GetCString(), GET_PLAYER(pOldCity->getOwner()).getName());20872088		for(iI = 0; iI < MAX_PLAYERS; iI++)2089		{2090			if((PlayerTypes)iI == GC.getGame().getActivePlayer())2091			{2092				if(GET_PLAYER((PlayerTypes)iI).isAlive())2093				{2094					if(iI != GetID())2095					{2096						if(pOldCity->isRevealed(GET_PLAYER((PlayerTypes)iI).getTeam(), false))2097						{2098							strBuffer = GetLocalizedText("TXT_KEY_MISC_CITY_CAPTURED_BY", strName.GetCString(), getCivilizationShortDescriptionKey());2099							GC.GetEngineUserInterface()->AddCityMessage(0, pOldCity->GetIDInfo(), ((PlayerTypes)iI), false, GC.getEVENT_MESSAGE_TIME(), strBuffer/*, "AS2D_CITYCAPTURED", MESSAGE_TYPE_MAJOR_EVENT, NULL, (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), pOldCity->getX(), pOldCity->getY(), true, true*/);2100						}2101					}2102				}2103			}2104		}21052106		strBuffer = GetLocalizedText("TXT_KEY_MISC_CITY_WAS_CAPTURED_BY", strName.GetCString(), getCivilizationShortDescriptionKey());2107		GC.getGame().addReplayMessage(REPLAY_MESSAGE_MAJOR_EVENT, GetID(), strBuffer, pOldCity->getX(), pOldCity->getY());21082109#ifndef FINAL_RELEASE2110		OutputDebugString("\n"); OutputDebugString(strBuffer); OutputDebugString("\n\n");2111#endif2112	}21132114	iCaptureGold = 0;2115	iCaptureCulture = 0;2116	iCaptureGreatWorks = 0;21172118	if(bConquest)2119	{2120		iCaptureGold = 0;21212122		iCaptureGold += GC.getBASE_CAPTURE_GOLD();2123		iCaptureGold += (pOldCity->getPopulation() * GC.getCAPTURE_GOLD_PER_POPULATION());2124		iCaptureGold += GC.getGame().getJonRandNum(GC.getCAPTURE_GOLD_RAND1(), "Capture Gold 1");2125		iCaptureGold += GC.getGame().getJonRandNum(GC.getCAPTURE_GOLD_RAND2(), "Capture Gold 2");21262127		if(GC.getCAPTURE_GOLD_MAX_TURNS() > 0)2128		{2129			iCaptureGold *= range((GC.getGame().getGameTurn() - pOldCity->getGameTurnAcquired()), 0, GC.getCAPTURE_GOLD_MAX_TURNS());2130			iCaptureGold /= GC.getCAPTURE_GOLD_MAX_TURNS();2131		}21322133		iCaptureGold *= (100 + pOldCity->getCapturePlunderModifier()) / 100;2134		iCaptureGold *= (100 + GetPlayerTraits()->GetPlunderModifier()) / 100;2135	}21362137	GetTreasury()->ChangeGold(iCaptureGold);21382139	if(bConquest)2140	{2141		iCaptureCulture = pOldCity->getJONSCulturePerTurn();2142		iCaptureCulture *= GetPlayerPolicies()->GetNumericModifier(POLICYMOD_CULTURAL_PLUNDER_MULTIPLIER);21432144		if(iCaptureCulture > 0)2145		{2146			changeJONSCulture(iCaptureCulture);2147		}2148	}21492150	if(bConquest)2151	{2152		if (GetPlayerTraits()->IsTechFromCityConquer())2153		{2154			// Will this be the first time we have owned this city?2155			if (!pOldCity->isEverOwned(GetID()))2156			{2157				DoTechFromCityConquer(pOldCity);2158			}2159		}2160	}21612162	// slewis - warmonger calculations2163	if (bConquest)2164	{2165		if(!isMinorCiv())2166		{2167			bool bDoWarmonger = true;21682169			// Don't award warmongering if you're conquering a city you owned back2170			if (pOldCity->getOriginalOwner() == GetID())2171			{2172				bDoWarmonger = false;2173			}21742175			if (bDoWarmonger)2176			{2177				CvDiplomacyAIHelpers::ApplyWarmongerPenalties(GetID(), pOldCity->getOwner(), pOldCity->isCapital());2178			}2179		}2180	}21812182	int iNumBuildingInfos = GC.getNumBuildingInfos();2183	std::vector<int> paiNumRealBuilding(iNumBuildingInfos, 0);2184	std::vector<int> paiBuildingOriginalOwner(iNumBuildingInfos, 0);2185	std::vector<int> paiBuildingOriginalTime(iNumBuildingInfos, 0);2186	struct CopyGreatWorkData2187	{2188		int m_iGreatWork;2189		BuildingTypes m_eBuildingType;2190		int m_iSlot;2191		bool m_bTransferred;2192	};2193	std::vector<CopyGreatWorkData> paGreatWorkData;2194	int iOldCityX = pOldCity->getX();2195	int iOldCityY = pOldCity->getY();2196	eOldOwner = pOldCity->getOwner();2197	eOriginalOwner = pOldCity->getOriginalOwner();2198	iGameTurnFounded = pOldCity->getGameTurnFounded();2199	iPopulation = pOldCity->getPopulation();2200	iOldPopulation = iPopulation;2201	iHighestPopulation = pOldCity->getHighestPopulation();2202	bool bEverCapital = pOldCity->IsEverCapital();2203	strName = pOldCity->getNameKey();2204	int iOldCultureLevel = pOldCity->GetJONSCultureLevel();2205	bool bHasMadeAttack = pOldCity->isMadeAttack();22062207	tempReligions.Init(pOldCity);2208	tempReligions.Copy(pOldCity->GetCityReligions());22092210	iBattleDamage = pOldCity->getDamage();22112212	// Traded cities between humans don't heal (an exploit would be to trade a city back and forth between teammates to get an instant heal.)2213	if(!bGift || !isHuman() || !GET_PLAYER(pOldCity->getOwner()).isHuman())2214	{2215		int iBattleDamgeThreshold = pOldCity->GetMaxHitPoints() * /*50*/ GC.getCITY_CAPTURE_DAMAGE_PERCENT();2216		iBattleDamgeThreshold /= 100;22172218		if(iBattleDamage > iBattleDamgeThreshold)2219		{2220			iBattleDamage = iBattleDamgeThreshold;2221		}2222	}22232224	for(iI = 0; iI < MAX_PLAYERS; iI++)2225	{2226		abEverOwned[iI] = pOldCity->isEverOwned((PlayerTypes)iI);2227	}22282229	abEverOwned[GetID()] = true;22302231	for(iI = 0; iI < GC.getNumBuildingInfos(); iI++)2232	{2233		paiNumRealBuilding[iI] = pOldCity->GetCityBuildings()->GetNumRealBuilding((BuildingTypes)iI);2234		paiBuildingOriginalOwner[iI] = pOldCity->GetCityBuildings()->GetBuildingOriginalOwner((BuildingTypes)iI);2235		paiBuildingOriginalTime[iI] = pOldCity->GetCityBuildings()->GetBuildingOriginalTime((BuildingTypes)iI);22362237		if (pOldCity->GetCityBuildings()->GetNumBuilding((BuildingTypes)iI) > 0)2238		{2239			CvBuildingEntry *pkBuilding = GC.getBuildingInfo((BuildingTypes)iI);2240			if (pkBuilding)2241			{2242				for (int jJ = 0; jJ < pkBuilding->GetGreatWorkCount(); jJ++)2243				{2244					int iGreatWork = pOldCity->GetCityBuildings()->GetBuildingGreatWork((BuildingClassTypes)pkBuilding->GetBuildingClassType(), jJ);2245					if (iGreatWork != NO_GREAT_WORK)2246					{2247						CopyGreatWorkData kData;2248						kData.m_iGreatWork = iGreatWork;2249						kData.m_eBuildingType = (BuildingTypes)iI;2250						kData.m_iSlot = jJ;2251						kData.m_bTransferred = false;2252						paGreatWorkData.push_back(kData);22532254						CvPlayer &kOldCityPlayer = GET_PLAYER(pOldCity->getOriginalOwner());2255						if (kOldCityPlayer.GetCulture()->GetSwappableWritingIndex() == iGreatWork)2256						{2257							kOldCityPlayer.GetCulture()->SetSwappableWritingIndex(-1);2258						}2259						if (kOldCityPlayer.GetCulture()->GetSwappableArtifactIndex() == iGreatWork)2260						{2261							kOldCityPlayer.GetCulture()->SetSwappableArtifactIndex(-1);2262						}2263						if (kOldCityPlayer.GetCulture()->GetSwappableArtIndex() == iGreatWork)2264						{2265							kOldCityPlayer.GetCulture()->SetSwappableArtIndex(-1);2266						}2267						if (kOldCityPlayer.GetCulture()->GetSwappableMusicIndex() == iGreatWork)2268						{2269							kOldCityPlayer.GetCulture()->SetSwappableMusicIndex(-1);2270						}2271					}2272				}2273			}2274		}2275	}22762277	std::vector<BuildingYieldChange> aBuildingYieldChange;2278	for(iI = 0; iI < GC.getNumBuildingClassInfos(); ++iI)2279	{2280		CvBuildingClassInfo* pkBuildingClassInfo = GC.getBuildingClassInfo((BuildingClassTypes)iI);2281		if(!pkBuildingClassInfo)2282		{2283			continue;2284		}22852286		for(int iYield = 0; iYield < NUM_YIELD_TYPES; ++iYield)2287		{2288			BuildingYieldChange kChange;2289			kChange.eBuildingClass = (BuildingClassTypes)iI;2290			kChange.eYield = (YieldTypes)iYield;2291			kChange.iChange = pOldCity->GetCityBuildings()->GetBuildingYieldChange((BuildingClassTypes)iI, (YieldTypes)iYield);2292			if(0 != kChange.iChange)2293			{2294				aBuildingYieldChange.push_back(kChange);2295			}2296		}2297	}22982299	bRecapture = false; //((eHighestCulturePlayer != NO_PLAYER) ? (GET_PLAYER(eHighestCulturePlayer).getTeam() == getTeam()) : false);23002301	// Returning spies back to pool2302	CvCityEspionage* pOldCityEspionage = pOldCity->GetCityEspionage();2303	if(pOldCityEspionage)2304	{2305		for(int i = 0; i < MAX_MAJOR_CIVS; i++)2306		{2307			int iAssignedSpy = pOldCityEspionage->m_aiSpyAssignment[i];2308			// if there is a spy in the city2309			if(iAssignedSpy != -1)2310			{2311				CvNotifications* pNotifications = GET_PLAYER((PlayerTypes)i).GetNotifications();2312				if(pNotifications)2313				{2314					CvPlayerEspionage* pEspionage = GET_PLAYER((PlayerTypes)i).GetEspionage();2315					CvEspionageSpy* pSpy = &(pEspionage->m_aSpyList[iAssignedSpy]);23162317					Localization::String strSummary;2318					Localization::String strNotification;2319					if(bConquest)2320					{2321						strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SPY_EVICTED_CONQUEST_S");2322						if(((PlayerTypes)i) == GetID())2323						{2324							strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_EVICTED_CONQUEST_YOU");2325							strNotification << pEspionage->GetSpyRankName(pSpy->m_eRank);2326#if defined(MOD_BUGFIX_SPY_NAMES)2327							strNotification << pSpy->GetSpyName(&GET_PLAYER((PlayerTypes)i));2328#else2329							strNotification << GET_PLAYER((PlayerTypes)i).getCivilizationInfo().getSpyNames(pSpy->m_iName);2330#endif2331							strNotification << pOldCity->getNameKey();2332						}2333						else2334						{2335							strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_EVICTED_CONQUEST");2336							strNotification << pEspionage->GetSpyRankName(pSpy->m_eRank);2337#if defined(MOD_BUGFIX_SPY_NAMES)2338							strNotification << pSpy->GetSpyName(&GET_PLAYER((PlayerTypes)i));2339#else2340							strNotification << GET_PLAYER((PlayerTypes)i).getCivilizationInfo().getSpyNames(pSpy->m_iName);2341#endif2342							strNotification << pOldCity->getNameKey();2343							strNotification << getCivilizationInfo().getShortDescriptionKey();2344						}2345					}2346					else2347					{2348						strSummary = GetLocalizedText("TXT_KEY_NOTIFICATION_SPY_EVICTED_TRADE_S");2349						if(((PlayerTypes)i) == GetID())2350						{2351							strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_EVICTED_TRADE_YOU");2352							strNotification << pEspionage->GetSpyRankName(pSpy->m_eRank);2353#if defined(MOD_BUGFIX_SPY_NAMES)2354							strNotification << pSpy->GetSpyName(&GET_PLAYER((PlayerTypes)i));2355#else2356							strNotification << GET_PLAYER((PlayerTypes)i).getCivilizationInfo().getSpyNames(pSpy->m_iName);2357#endif2358							strNotification << pOldCity->getNameKey();2359						}2360						else2361						{2362							strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_EVICTED_TRADE");2363							strNotification << pEspionage->GetSpyRankName(pSpy->m_eRank);2364#if defined(MOD_BUGFIX_SPY_NAMES)2365							strNotification << pSpy->GetSpyName(&GET_PLAYER((PlayerTypes)i));2366#else2367							strNotification << GET_PLAYER((PlayerTypes)i).getCivilizationInfo().getSpyNames(pSpy->m_iName);2368#endif2369							strNotification << pOldCity->getNameKey();2370							strNotification << getCivilizationInfo().getShortDescriptionKey();2371						}2372					}23732374					pNotifications->Add(NOTIFICATION_SPY_EVICTED, strNotification.toUTF8(), strSummary.toUTF8(), -1, -1, pOldCity->getOwner());2375				}23762377				GET_PLAYER((PlayerTypes)i).GetEspionage()->ExtractSpyFromCity(iAssignedSpy);2378				// create notifications indicating what has happened with the spy2379			}2380		}2381	}23822383	GC.getGame().GetGameTrade()->ClearAllCityTradeRoutes(pCityPlot);23842385	bool bCapital = pOldCity->isCapital();23862387	// find the plot2388	FStaticVector<int, 121, true, c_eCiv5GameplayDLL, 0> aiPurchasedPlotX;2389	FStaticVector<int, 121, true, c_eCiv5GameplayDLL, 0> aiPurchasedPlotY;2390	const int iMaxRange = /*5*/ GC.getMAXIMUM_ACQUIRE_PLOT_DISTANCE();23912392	for(int iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++)2393	{2394		CvPlot* pLoopPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop);2395		if(pLoopPlot && pLoopPlot->GetCityPurchaseOwner() == eOldOwner && pLoopPlot->GetCityPurchaseID() == pOldCity->GetID())2396		{2397			aiPurchasedPlotX.push_back(pLoopPlot->getX());2398			aiPurchasedPlotY.push_back(pLoopPlot->getY());2399			pLoopPlot->ClearCityPurchaseInfo();2400		}2401	}24022403#if defined(MOD_GLOBAL_CITY_WORKING)2404	int iOldCityRings = pOldCity->getWorkPlotDistance();2405#endif24062407#if defined(MOD_GLOBAL_VENICE_KEEPS_RESOURCES) || defined(MOD_GLOBAL_CS_MARRIAGE_KEEPS_RESOURCES)2408	pOldCity->PreKill(bKeepResources);2409#else2410	pOldCity->PreKill();2411#endif24122413	{2414		auto_ptr<ICvCity1> pkDllOldCity(new CvDllCity(pOldCity));2415		gDLL->GameplayCityCaptured(pkDllOldCity.get(), GetID());2416	}24172418#if defined(CIV_HOST_API)2419	const int iCivHostOldCityID = pOldCity->GetID();2420#endif2421	GET_PLAYER(eOldOwner).deleteCity(pOldCity->GetID());2422	// adapted from PostKill()24232424	GC.getGame().addReplayMessage(REPLAY_MESSAGE_CITY_CAPTURED, m_eID, "", pCityPlot->getX(), pCityPlot->getY());24252426	PlayerTypes ePlayer;2427	// Update Proximity between this Player and all others2428	for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)2429	{2430		ePlayer = (PlayerTypes) iPlayerLoop;24312432		if(ePlayer != m_eID)2433		{2434			if(GET_PLAYER(ePlayer).isAlive())2435			{2436				GET_PLAYER(m_eID).DoUpdateProximityToPlayer(ePlayer);2437				GET_PLAYER(ePlayer).DoUpdateProximityToPlayer(m_eID);2438			}2439		}2440	}24412442#if defined(MOD_GLOBAL_CITY_WORKING)2443	GC.getMap().updateWorkingCity(pCityPlot,iOldCityRings*2);2444#else	2445	GC.getMap().updateWorkingCity(pCityPlot,NUM_CITY_RINGS*2);2446#endif24472448	// Lost the capital!2449	if(bCapital)2450	{2451#if defined(MOD_GLOBAL_NO_CONQUERED_SPACESHIPS)2452		GET_PLAYER(eOldOwner).disassembleSpaceship(pCityPlot);2453#endif2454		GET_PLAYER(eOldOwner).findNewCapital();2455		GET_TEAM(getTeam()).resetVictoryProgress();2456	}24572458	GC.GetEngineUserInterface()->setDirty(NationalBorders_DIRTY_BIT, true);2459	// end adapted from PostKill()24602461#if defined(MOD_API_EXTENSIONS)2462	pNewCity = initCity(pCityPlot->getX(), pCityPlot->getY(), !bConquest, (!bConquest && !bGift), NO_RELIGION, strName.c_str());2463#else2464	pNewCity = initCity(pCityPlot->getX(), pCityPlot->getY(), !bConquest, (!bConquest && !bGift));2465#endif24662467	CvAssertMsg(pNewCity != NULL, "NewCity is not assigned a valid value");24682469#ifdef _MSC_VER2470#pragma warning ( push )2471#pragma warning ( disable : 6011 ) 2472#endif24732474	// For buyouts, set it up like a new city founded by this player, to avoid liberation later on etc.2475	if(bIsMinorCivBuyout)2476	{2477#if defined(MOD_GLOBAL_CS_LIBERATE_AFTER_BUYOUT)2478		if (MOD_GLOBAL_CS_LIBERATE_AFTER_BUYOUT) {2479			pNewCity->setPreviousOwner(eOldOwner);2480			pNewCity->setOriginalOwner(eOriginalOwner);2481			pNewCity->setGameTurnFounded(iGameTurnFounded);2482			pNewCity->SetEverCapital(bEverCapital);2483		} else {2484#endif2485			pNewCity->setPreviousOwner(NO_PLAYER);2486			pNewCity->setOriginalOwner(m_eID);2487			pNewCity->setGameTurnFounded(GC.getGame().getGameTurn());2488			pNewCity->SetEverCapital(false);2489#if defined(MOD_GLOBAL_CS_LIBERATE_AFTER_BUYOUT)2490		}2491#endif24922493		AwardFreeBuildings(pNewCity);2494	}2495	// Otherwise, set it up using the data from the old city2496	else2497	{2498		pNewCity->setPreviousOwner(eOldOwner);2499		pNewCity->setOriginalOwner(eOriginalOwner);2500		pNewCity->setGameTurnFounded(iGameTurnFounded);2501		pNewCity->SetEverCapital(bEverCapital);2502	}25032504	// Population change for capturing a city2505	if(!bRecapture && bConquest)	// Don't drop it if we're recapturing our own City2506	{2507		int iPercentPopulationRetained = /*50*/ GC.getCITY_CAPTURE_POPULATION_PERCENT();2508		int iInfluenceReduction = GetCulture()->GetInfluenceCityConquestReduction(eOldOwner);2509		iPercentPopulationRetained += (iInfluenceReduction * (100 - iPercentPopulationRetained) / 100);25102511		iPopulation = max(1, iPopulation * iPercentPopulationRetained / 100);2512	}25132514	pNewCity->setPopulation(iPopulation);2515	pNewCity->setHighestPopulation(iHighestPopulation);2516	pNewCity->setName(strName);2517	pNewCity->setNeverLost(false);2518	pNewCity->setDamage(iBattleDamage,true);2519	pNewCity->setMadeAttack(bHasMadeAttack);25202521	for(iI = 0; iI < MAX_PLAYERS; iI++)2522	{2523		pNewCity->setEverOwned(((PlayerTypes)iI), abEverOwned[iI]);2524	}25252526	pNewCity->SetJONSCultureLevel(iOldCultureLevel);2527	pNewCity->GetCityReligions()->Copy(&tempReligions);2528	pNewCity->GetCityReligions()->RemoveFormerPantheon();25292530	if(bCapital)2531	{2532		GET_PLAYER(eOldOwner).SetHasLostCapital(true, m_eID);2533	}25342535	CvCivilizationInfo& playerCivilizationInfo = getCivilizationInfo();25362537#if !defined(NO_ACHIEVEMENTS)2538	if(bConquest && !GC.getGame().isGameMultiPlayer() && isHuman())2539	{2540		const char* szCivKey = getCivilizationTypeKey();25412542		// Check for Kris Swordsman achievement2543		if(strcmp(szCivKey, "CIVILIZATION_INDONESIA") == 0)2544		{2545			CvUnit *pConqueringUnit = pCityPlot->getUnitByIndex(0);2546			if (pConqueringUnit->getUnitType() == (UnitTypes)GC.getInfoTypeForString("UNIT_KRIS_SWORDSMAN", true))2547			{2548				PromotionTypes ePromotion = (PromotionTypes)GC.getInfoTypeForString("PROMOTION_ENEMY_BLADE", true);2549				if (pConqueringUnit->isHasPromotion(ePromotion))2550				{2551					gDLL->UnlockAchievement(ACHIEVEMENT_XP2_21);2552				}2553			}2554		}25552556		// Check for Rome conquering Statue of Zeus Achievement2557		bool bUsingXP1Scenario1 = gDLL->IsModActivated(CIV5_XP1_SCENARIO1_MODID);2558		bool bUsingXP1Scenario2 = gDLL->IsModActivated(CIV5_XP1_SCENARIO2_MODID);2559		bool bUsingXP2Scenario1 = gDLL->IsModActivated(CIV5_XP2_SCENARIO1_MODID);25602561		const char* szNameKey = pNewCity->getNameKey();2562		if(bUsingXP2Scenario1)2563		{2564			if(strcmp(szCivKey, "CIVILIZATION_ENGLAND") == 0)2565			{2566				if(strcmp(szNameKey, "TXT_KEY_CIVIL_WAR_SCENARIO_CITY_NAME_GETTYSBURG") == 0)2567				{2568					CvUnit *pConqueringUnit = pCityPlot->getUnitByIndex(0);2569					PromotionTypes ePromotion = (PromotionTypes)GC.getInfoTypeForString("PROMOTION_PICKETT", true);2570					if (pConqueringUnit->isHasPromotion(ePromotion))2571					{2572						gDLL->UnlockAchievement(ACHIEVEMENT_XP2_59);2573					}2574				}2575			}2576		}25772578		if(bUsingXP1Scenario1)2579		{2580			const HandicapTypes eCurrentHandicap = GC.getGame().getHandicapType();2581			HandicapTypes eEmporerHandicap = NO_HANDICAP;2582			HandicapTypes eDeityHandicap = NO_HANDICAP;25832584			const int numHandicapInfos = GC.getNumHandicapInfos();2585			for(int i = 0; i < numHandicapInfos; ++i)2586			{2587				const HandicapTypes eHandicap = static_cast<HandicapTypes>(i);2588				CvHandicapInfo* pkInfo = GC.getHandicapInfo(eHandicap);2589				if(pkInfo != NULL)2590				{2591					if(strcmp(pkInfo->GetType(), "HANDICAP_EMPEROR") == 0)2592					{2593						eEmporerHandicap = eHandicap;2594					}2595					else if(strcmp(pkInfo->GetType(), "HANDICAP_DEITY") == 0)2596					{2597						eDeityHandicap = eHandicap;2598					}2599				}2600			}26012602			if(szCivKey && szNameKey)2603			{2604				if(strcmp(szCivKey, "CIVILIZATION_ENGLAND") == 0)2605				{2606					if(strcmp(szNameKey, "TXT_KEY_CITYSTATE_JERUSALEM") == 0)2607					{2608						if(eCurrentHandicap >= eEmporerHandicap)2609						{2610							gDLL->UnlockAchievement(ACHIEVEMENT_XP1_39);2611						}2612					}2613				}2614				else if(strcmp(szCivKey, "CIVILIZATION_OTTOMAN") == 0)2615				{2616					if(strcmp(szNameKey, "TXT_KEY_CITY_NAME_CONSTANTINOPLE") == 0)2617					{2618						if(eCurrentHandicap >= eDeityHandicap)2619						{2620							gDLL->UnlockAchievement(ACHIEVEMENT_XP1_40);2621						}2622					}2623				}2624			}	2625		}26262627		if(bUsingXP1Scenario2)2628		{2629			bool bHasConstantinople = false;2630			bool bHasRome = false;26312632			if(strcmp(szNameKey, "TXT_KEY_CITY_NAME_CONSTANTINOPLE") == 0)2633			{2634				bHasConstantinople = true;26352636				if(pNewCity->getOriginalOwner() != GetID())2637				{2638					gDLL->UnlockAchievement(ACHIEVEMENT_XP1_47);2639				}2640			}2641			else if(strcmp(szNameKey, "TXT_KEY_CITY_NAME_ROME") == 0)2642			{2643				bHasRome = true;2644			}26452646			if(bHasConstantinople || bHasRome)2647			{2648				int iLoop = 0;2649				for(CvCity* pCity = firstCity(&iLoop); pCity != NULL; pCity = nextCity(&iLoop))2650				{2651					const char* szOtherNameKey = pCity->getNameKey();2652					if(strcmp(szOtherNameKey, "TXT_KEY_CITY_NAME_CONSTANTINOPLE") == 0)2653					{2654						bHasConstantinople = true;2655					}2656					else if(strcmp(szOtherNameKey, "TXT_KEY_CITY_NAME_ROME") == 0)2657					{2658						bHasRome = true;2659					}2660				}2661			}26622663			if(bHasRome && bHasConstantinople)2664			{2665				gDLL->UnlockAchievement(ACHIEVEMENT_XP1_48);2666			}26672668			if(strcmp(getCivilizationTypeKey(), "CIVILIZATION_CELTS") == 0)2669			{2670				//Did we cap what was originally a sassinid city?2671				typedef std::pair<int,int> Location;2672				typedef std::tr1::array<Location, 7> SassanidCityArray;2673				SassanidCityArray SassanidCities = {2674					Location(87,17), //Ctesiphon2675					Location(85,20), //Singara2676					Location(81,21), //Nisibis2677					Location(79,24), //Amida2678					Location(82,28), //Thospia2679					Location(81,33), //Anium2680					Location(87,33), //Artaxata2681				};2682				2683				int iNewPlotX = pNewCity->getX();2684				int iNewPlotY = pNewCity->getY();26852686				//Test if we still own each city.2687				for(SassanidCityArray::iterator it = SassanidCities.begin(); it != SassanidCities.end(); ++it)2688				{2689					if(it->first == iNewPlotX && it->second == iNewPlotY)2690					{2691						gDLL->UnlockAchievement(ACHIEVEMENT_XP1_51);26922693					}2694				}2695			}26962697		}2698	}2699#endif27002701	std::vector<BuildingTypes> freeConquestBuildings = m_pPlayerPolicies->GetFreeBuildingsOnConquest();2702	for(iI = 0; iI < (int)freeConquestBuildings.size(); iI++)2703	{2704		const BuildingTypes eLoopBuilding = freeConquestBuildings[iI];2705		if (eLoopBuilding != NO_BUILDING)2706		{2707			CvBuildingEntry* pkLoopBuildingInfo = GC.getBuildingInfo(eLoopBuilding);2708			if(pkLoopBuildingInfo)2709			{2710				if (eLoopBuilding == pkLoopBuildingInfo->GetID())2711				{2712#if defined(MOD_BUGFIX_BUILDINGCLASS_NOT_BUILDING)2713					BuildingTypes eFreeBuilding = (BuildingTypes)getCivilizationInfo().getCivilizationBuildings(pkLoopBuildingInfo->GetBuildingClassType());2714					pNewCity->GetCityBuildings()->SetNumFreeBuilding(eFreeBuilding, 1);2715#else2716					pNewCity->GetCityBuildings()->SetNumFreeBuilding(eLoopBuilding, 1);2717#endif2718				}2719			}2720		}2721	}27222723	BuildingTypes eTraitFreeBuilding = GetPlayerTraits()->GetFreeBuildingOnConquest();2724	for(iI = 0; iI < GC.getNumBuildingInfos(); iI++)2725	{2726		const BuildingTypes eLoopBuilding = static_cast<BuildingTypes>(iI);2727		CvBuildingEntry* pkLoopBuildingInfo = GC.getBuildingInfo(eLoopBuilding);2728		if(pkLoopBuildingInfo)2729		{2730			const CvBuildingClassInfo& kLoopBuildingClassInfo = pkLoopBuildingInfo->GetBuildingClassInfo();27312732			int iNum = 0;27332734			if(eTraitFreeBuilding == pkLoopBuildingInfo->GetID())2735			{2736				pNewCity->GetCityBuildings()->SetNumFreeBuilding(eTraitFreeBuilding, 1);2737			}27382739			else if(paiNumRealBuilding[iI] > 0)2740			{2741				const BuildingClassTypes eBuildingClass = (BuildingClassTypes)pkLoopBuildingInfo->GetBuildingClassType();2742				if(::isWorldWonderClass(kLoopBuildingClassInfo))2743				{2744					eBuilding = eLoopBuilding;2745				}2746				else2747				{2748					eBuilding = (BuildingTypes)playerCivilizationInfo.getCivilizationBuildings(eBuildingClass);2749				}27502751				if(eBuilding != NO_BUILDING)2752				{2753					CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBuilding);2754					if(pkBuildingInfo)2755					{2756						if(!pkLoopBuildingInfo->IsNeverCapture())2757						{2758							if(!isProductionMaxedBuildingClass(((BuildingClassTypes)(pkBuildingInfo->GetBuildingClassType())), true))2759							{2760								// here would be a good place to put additional checks (for example, influence)2761								if(!bConquest || bRecapture || (GC.getGame().getJonRandNum(100, "Capture Probability") < pkLoopBuildingInfo->GetConquestProbability()))2762								{2763									iNum += paiNumRealBuilding[iI];2764								}2765							}2766						}27672768#if !defined(NO_ACHIEVEMENTS)2769						// Check for Tomb Raider Achievement2770						if(bConquest && !GC.getGame().isGameMultiPlayer() && pkLoopBuildingInfo->GetType() && _stricmp(pkLoopBuildingInfo->GetType(), "BUILDING_BURIAL_TOMB") == 0 && isHuman())2771						{2772							if(iCaptureGold > 0)  //Need to actually pillage something from the 'tomb'2773							{2774								gDLL->UnlockAchievement(ACHIEVEMENT_SPECIAL_TOMBRAIDER);2775							}2776						}2777#endif27782779#if !defined(NO_ACHIEVEMENTS)2780						// Check for Rome conquering Statue of Zeus Achievement2781						if(bConquest && !GC.getGame().isGameMultiPlayer() && pkLoopBuildingInfo->GetType() && _stricmp(pkLoopBuildingInfo->GetType(), "BUILDING_STATUE_ZEUS") == 0 && isHuman())2782						{2783							const char* pkCivKey = getCivilizationTypeKey();2784							if(pkCivKey && strcmp(pkCivKey, "CIVILIZATION_ROME") == 0)2785							{2786								gDLL->UnlockAchievement(ACHIEVEMENT_SPECIAL_ROME_GETS_ZEUS);2787							}2788						}2789#endif27902791						pNewCity->GetCityBuildings()->SetNumRealBuildingTimed(eBuilding, iNum, false, ((PlayerTypes)(paiBuildingOriginalOwner[iI])), paiBuildingOriginalTime[iI]);27922793						if (iNum > 0)2794						{2795							if (pkBuildingInfo->GetGreatWorkCount() > 0)2796							{2797								for (unsigned int jJ=0; jJ < paGreatWorkData.size(); jJ++)2798								{2799									if (paGreatWorkData[jJ].m_eBuildingType == iI)2800									{2801										pNewCity->GetCityBuildings()->SetBuildingGreatWork(eBuildingClass, paGreatWorkData[jJ].m_iSlot, paGreatWorkData[jJ].m_iGreatWork);2802										paGreatWorkData[jJ].m_bTransferred = true;2803										iCaptureGreatWorks++;2804									}2805								}2806							}2807						}2808					}2809				}2810			}2811		}2812	}28132814	for(std::vector<BuildingYieldChange>::iterator it = aBuildingYieldChange.begin(); it != aBuildingYieldChange.end(); ++it)2815	{2816		pNewCity->GetCityBuildings()->SetBuildingYieldChange((*it).eBuildingClass, (*it).eYield, (*it).iChange);2817	}28182819	// Distribute any remaining Great Works to other buildings2820	for (unsigned int jJ=0; jJ < paGreatWorkData.size(); jJ++)2821	{2822		if (!paGreatWorkData[jJ].m_bTransferred)2823		{2824			BuildingClassTypes eBuildingClass = NO_BUILDINGCLASS; // Passed by reference below2825			int iSlot = -1; // Passed by reference below2826			GreatWorkType eType = GC.getGame().GetGameCulture()->m_CurrentGreatWorks[paGreatWorkData[jJ].m_iGreatWork].m_eType;2827			GreatWorkSlotType eGreatWorkSlot = CultureHelpers::GetGreatWorkSlot(eType);2828			if (pNewCity->GetCityBuildings()->GetNextAvailableGreatWorkSlot(eGreatWorkSlot, &eBuildingClass, &iSlot))2829			{2830				pNewCity->GetCityBuildings()->SetBuildingGreatWork(eBuildingClass, iSlot, paGreatWorkData[jJ].m_iGreatWork);2831				paGreatWorkData[jJ].m_bTransferred = true;2832				iCaptureGreatWorks++;2833			}2834			else2835			{2836				BuildingClassTypes eGWBuildingClass;2837				int iGWSlot;2838				CvCity *pGWCity = GetCulture()->GetClosestAvailableGreatWorkSlot(pCityPlot->getX(), pCityPlot->getY(), eGreatWorkSlot, &eGWBuildingClass, &iGWSlot);2839				if (pGWCity)2840				{2841					pGWCity->GetCityBuildings()->SetBuildingGreatWork(eGWBuildingClass, iGWSlot, paGreatWorkData[jJ].m_iGreatWork);2842					paGreatWorkData[jJ].m_bTransferred = true;2843					iCaptureGreatWorks++;2844				}2845			}2846		}2847	}28482849	// Did we re-acquire our Capital?2850	if(pCityPlot->getX() == GetOriginalCapitalX() && pCityPlot->getY() == GetOriginalCapitalY())2851	{2852		SetHasLostCapital(false, NO_PLAYER);28532854		const BuildingTypes eCapitalBuilding = (BuildingTypes)(getCivilizationInfo().getCivilizationBuildings(GC.getCAPITAL_BUILDINGCLASS()));2855		if(eCapitalBuilding != NO_BUILDING)2856		{2857#if defined(MOD_EVENTS_CITY_CAPITAL)2858			CvCity* pOldCapital = getCapitalCity();2859			if (pOldCapital != NULL)2860#else2861			if (getCapitalCity() != NULL)2862#endif2863			{2864				getCapitalCity()->GetCityBuildings()->SetNumRealBuilding(eCapitalBuilding, 0);2865			}2866			CvAssertMsg(!(pNewCity->GetCityBuildings()->GetNumRealBuilding(eCapitalBuilding)), "(pBestCity->getNumRealBuilding(eCapitalBuilding)) did not return false as expected");2867			pNewCity->GetCityBuildings()->SetNumRealBuilding(eCapitalBuilding, 1);28682869#if defined(MOD_EVENTS_CITY_CAPITAL)2870			if (MOD_EVENTS_CITY_CAPITAL) {2871				GAMEEVENTINVOKE_HOOK(GAMEEVENT_CapitalChanged, GetID(), pNewCity->GetID(), (pOldCapital ? pOldCapital->GetID() : -1));2872			}2873#endif2874		}2875	}28762877	// slewis - moved this here so that conquest victory is tested with each city capture2878	GC.getGame().DoTestConquestVictory();28792880#if defined(MOD_GLOBAL_CITY_WORKING)2881	GC.getMap().updateWorkingCity(pCityPlot,pNewCity->getWorkPlotDistance()*2);2882#else	2883	GC.getMap().updateWorkingCity(pCityPlot,NUM_CITY_RINGS*2);2884#endif28852886	if(bConquest)2887	{2888		for(int iDX = -iMaxRange; iDX <= iMaxRange; iDX++)2889		{2890			for(int iDY = -iMaxRange; iDY <= iMaxRange; iDY++)2891			{2892				CvPlot* pLoopPlot = plotXYWithRangeCheck(iOldCityX, iOldCityY, iDX, iDY, iMaxRange);2893				if(pLoopPlot)2894				{2895					pLoopPlot->verifyUnitValidPlot();2896				}2897			}2898		}28992900#if !defined(NO_ACHIEVEMENTS)2901		// Check for Askia Achievement2902		if(isHuman() && !CvPreGame::isNetworkMultiplayerGame())2903		{2904			const char* pkLeaderKey = getLeaderTypeKey();2905			if(pkLeaderKey && strcmp(pkLeaderKey, "LEADER_ASKIA") == 0)2906			{2907				CvCity* pkCaptialCity = getCapitalCity();2908				if(pkCaptialCity != NULL)	// Shouldn't be NULL, but...2909				{2910					CvPlot* pkCapitalPlot = pkCaptialCity->plot();2911					CvPlot* pkNewCityPlot = pNewCity->plot();2912					if(pkCapitalPlot && pkNewCityPlot)2913					{2914						// Get the area each plot is located in.2915						CvArea* pkCapitalArea = pkCapitalPlot->area();2916						CvArea* pkNewCityArea = pkNewCityPlot->area();29172918						if(pkCapitalArea && pkNewCityArea)2919						{2920							// The area the new city is locate on has to be of a certain size to qualify so that tiny islands are not included2921#define ACHIEVEMENT_MIN_CONTINENT_SIZE	82922							if(pkNewCityArea->GetID() != pkCapitalArea->GetID() && pkNewCityArea->getNumTiles() >= ACHIEVEMENT_MIN_CONTINENT_SIZE)2923							{2924								gDLL->UnlockAchievement(ACHIEVEMENT_SPECIAL_WARCANOE);2925							}2926						}2927					}2928				}2929			}2930		}2931#endif2932	}29332934	pCityPlot->setRevealed(GET_PLAYER(eOldOwner).getTeam(), true);29352936	// If the old owner is "killed," then notify everyone's Grand Strategy AI2937	if(GET_PLAYER(eOldOwner).getNumCities() == 0 && !GET_PLAYER(eOldOwner).GetPlayerTraits()->IsStaysAliveZeroCities() && !bIsMinorCivBuyout)2938	{2939		if(!isMinorCiv() && !isBarbarian())2940		{2941			for(int iMajorLoop = 0; iMajorLoop < MAX_MAJOR_CIVS; iMajorLoop++)2942			{2943				if(GetID() != iMajorLoop && GET_PLAYER((PlayerTypes) iMajorLoop).isAlive())2944				{2945					// Have I met the player who killed the guy?2946					if(GET_TEAM(GET_PLAYER((PlayerTypes) iMajorLoop).getTeam()).isHasMet(getTeam()))2947					{2948						GET_PLAYER((PlayerTypes) iMajorLoop).GetDiplomacyAI()->DoPlayerKilledSomeone(GetID(), eOldOwner);2949					}2950				}2951			}29522953		}2954	}29552956	// If not, old owner should look at city specializations2957	else2958	{2959		GET_PLAYER(eOldOwner).GetCitySpecializationAI()->SetSpecializationsDirty(SPECIALIZATION_UPDATE_MY_CITY_CAPTURED);2960	}29612962	// Do the same for the new owner2963	GetCitySpecializationAI()->SetSpecializationsDirty(SPECIALIZATION_UPDATE_ENEMY_CITY_CAPTURED);29642965	bool bDisbanded = false;29662967	// In OCC games, all captured cities are toast2968	if(GC.getGame().isOption(GAMEOPTION_ONE_CITY_CHALLENGE) && isHuman())2969	{2970		bDisbanded = true;2971		disband(pNewCity);2972		// disband will delete the city2973		pNewCity = NULL;29742975		// Set the plots to no owner2976		for(uint ui = 0; ui < aiPurchasedPlotX.size(); ui++)2977		{2978			CvPlot* pPlot = GC.getMap().plot(aiPurchasedPlotX[ui], aiPurchasedPlotY[ui]);2979			pPlot->setOwner(NO_PLAYER, -1, /*bCheckUnits*/ true, /*bUpdateResources*/ true);2980		}29812982	}2983	else //if (bConquest)2984	{2985		// Set the plots to the new owner, now, we may be flipping it to a liberated player and we need to pass on the information.2986		for(uint ui = 0; ui < aiPurchasedPlotX.size(); ui++)2987		{2988			CvPlot* pPlot = GC.getMap().plot(aiPurchasedPlotX[ui], aiPurchasedPlotY[ui]);2989			if(pPlot->getOwner() != pNewCity->getOwner())2990				pPlot->setOwner(pNewCity->getOwner(), /*iAcquireCityID*/ pNewCity->GetID(), /*bCheckUnits*/ true, /*bUpdateResources*/ true);2991		}29922993		// Is this City being Occupied?2994		if(pNewCity->getOriginalOwner() != GetID())2995		{2996			pNewCity->SetOccupied(true);29972998			int iInfluenceReduction = GetCulture()->GetInfluenceCityConquestReduction(eOldOwner);2999			int iResistanceTurns = pNewCity->getPopulation() * (100 - iInfluenceReduction) / 100;30003001			if (iResistanceTurns > 0)3002			{3003				pNewCity->ChangeResistanceTurns(iResistanceTurns);3004			}3005		}3006#if defined(CIV_HOST_API)3007		CivHandCityReplaced(eOldOwner, iCivHostOldCityID, pNewCity);hand-placed hook: CityReplaced3008#endif30093010		long lResult = 0;30113012		if(lResult == 0)3013		{3014			PlayerTypes eLiberatedPlayer = NO_PLAYER;30153016			// Captured someone's city that didn't originally belong to us - Liberate a player?3017			if(pNewCity->getOriginalOwner() != eOldOwner && pNewCity->getOriginalOwner() != GetID())3018			{3019				eLiberatedPlayer = pNewCity->getOriginalOwner();3020				if(!CanLiberatePlayerCity(eLiberatedPlayer))3021				{3022					eLiberatedPlayer = NO_PLAYER;3023				}3024			}30253026#if defined(MOD_BUGFIX_VENICE_PUPPETS_CAPITAL)3027			// Venice MUST liberate their own capital3028			if (GetPlayerTraits()->IsNoAnnexing() && pNewCity->getX() == GetOriginalCapitalX() && pNewCity->getY() == GetOriginalCapitalY())3029			{3030				if (iCaptureGold > 0 || iCaptureCulture > 0 || iCaptureGreatWorks > 0) {3031					if (iCaptureCulture == 0 && iCaptureGreatWorks == 0) {3032						strBuffer = GetLocalizedText("TXT_KEY_POPUP_GOLD_CITY_CAPTURE", iCaptureGold, pNewCity->getNameKey());3033					} else {3034						strBuffer = GetLocalizedText("TXT_KEY_POPUP_GOLD_AND_CULTURE_CITY_CAPTURE", iCaptureGold, iCaptureCulture, iCaptureGreatWorks, pNewCity->getNameKey());3035					}3036					GC.GetEngineUserInterface()->AddCityMessage(0, pNewCity->GetIDInfo(), GetID(), true, GC.getEVENT_MESSAGE_TIME(), strBuffer);3037					MILITARYLOG(GetID(), strBuffer.c_str(), pNewCity->plot(), pOldCity->getOwner());3038				}3039			}3040			else3041#endif3042			// AI decides what to do with a City3043			if(!isHuman())3044			{3045				AI_conquerCity(pNewCity, eOldOwner); // could delete the pointer...3046				// So we will check to see if the plot still contains the city.3047				CvCity* pkCurrentCity = pCityPlot->getPlotCity();3048				if (pkCurrentCity == NULL || pNewCity != pkCurrentCity || pkCurrentCity->getOwner() != GetID())3049				{3050					// The city is gone or is not ours anymore (we gave it away)3051					pNewCity = NULL;3052				}3053			}30543055			// Human decides what to do with a City3056			else if(!GC.getGame().isOption(GAMEOPTION_NO_HAPPINESS))3057			{3058				// Used to display info for annex/puppet/raze popup - turned off in DoPuppet and DoAnnex3059				pNewCity->SetIgnoreCityForHappiness(true);3060				if (GetPlayerTraits()->IsNoAnnexing() && bIsMinorCivBuyout)3061				{3062					pNewCity->DoCreatePuppet();3063				}3064				else if (pNewCity->getOriginalOwner() != GetID() || GetPlayerTraits()->IsNoAnnexing() || bIsMinorCivBuyout)3065				{3066#if defined(CIV_HOST_API)3067					CivHandPopupRaised(GetID(), BUTTONPOPUP_CITY_CAPTURED, pNewCity->GetID(), iCaptureGold, iCaptureCulture, bIsMinorCivBuyout, bConquest, "");hand-placed hook: PopupRaised3068#endif3069					if(GC.getGame().getActivePlayer() == GetID())3070					{3071						int iTemp[5] = { pNewCity->GetID(), iCaptureGold, iCaptureCulture, iCaptureGreatWorks, eLiberatedPlayer };3072						bool bTemp[2] = { bIsMinorCivBuyout, bConquest };3073						GC.GetEngineUserInterface()->AddPopup(BUTTONPOPUP_CITY_CAPTURED, POPUP_PARAM_INT_ARRAY(iTemp), POPUP_PARAM_BOOL_ARRAY(bTemp));3074						// We are adding a popup that the player must make a choice in, make sure they are not in the end-turn phase.3075						CancelActivePlayerEndTurn();3076					}3077				}3078				else3079				{3080					pNewCity->SetIgnoreCityForHappiness(false);3081				}3082			}30833084			// No choice but to capture it, tell about pillage gold (if any)3085			else if(iCaptureGold > 0 || iCaptureCulture > 0 || iCaptureGreatWorks > 0)3086			{3087				if (iCaptureCulture == 0 && iCaptureGreatWorks == 0)3088				{3089					strBuffer = GetLocalizedText("TXT_KEY_POPUP_GOLD_CITY_CAPTURE", iCaptureGold, pNewCity->getNameKey());3090					GC.GetEngineUserInterface()->AddCityMessage(0, pNewCity->GetIDInfo(), GetID(), true, GC.getEVENT_MESSAGE_TIME(), strBuffer);3091					MILITARYLOG(GetID(), strBuffer.c_str(), pNewCity->plot(), pOldCity->getOwner());3092				}3093				else3094				{3095					strBuffer = GetLocalizedText("TXT_KEY_POPUP_GOLD_AND_CULTURE_CITY_CAPTURE", iCaptureGold, iCaptureCulture, iCaptureGreatWorks, pNewCity->getNameKey());3096					GC.GetEngineUserInterface()->AddCityMessage(0, pNewCity->GetIDInfo(), GetID(), true, GC.getEVENT_MESSAGE_TIME(), strBuffer);3097					MILITARYLOG(GetID(), strBuffer.c_str(), pNewCity->plot(), pOldCity->getOwner());3098				}3099			}3100		}3101	}31023103	// Be careful below here, pNewCity can be NULL.3104	CheckForMurder(eOldOwner);31053106	if(GC.getGame().getActiveTeam() == GET_PLAYER(eOldOwner).getTeam())3107	{3108		CvMap& theMap = GC.getMap();3109		theMap.updateDeferredFog();3110	}31113112	ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();3113	if(pkScriptSystem && pNewCity != NULL)3114	{3115		CvLuaArgsHandle args;3116		args->Push(eOldOwner);3117		args->Push(bCapital);3118		args->Push(pNewCity->getX());3119		args->Push(pNewCity->getY());3120		args->Push(GetID());3121		args->Push(iOldPopulation);3122		args->Push(bConquest);3123		args->Push((int)paGreatWorkData.size());3124		args->Push(iCaptureGreatWorks);31253126		bool bResult;3127		LuaSupport::CallHook(pkScriptSystem, "CityCaptureComplete", args.get(), bResult);3128	}31293130#if defined(MOD_API_EXTENSIONS)3131		return pNewCity;3132#endif3133#ifdef _MSC_VER3134#pragma warning ( pop ) // restore warning level suppressed for pNewCity null check3135#endif// _MSC_VER3136}

Calls

Called by