Hooks
static bool BeforeCvCity_PreKill(CvCity* self, bool bKeepResources);static void AfterCvCity_PreKill(CvCity* self, bool bKeepResources);static void ReplaceCvCity_PreKill(void (*original)(CvCity*, bool), CvCity* self, bool bKeepResources);CivRegisterBefore<CivHooks::CvCity_PreKill>(host, &BeforeCvCity_PreKill);CivRegisterAfter<CivHooks::CvCity_PreKill>(host, &AfterCvCity_PreKill);CivRegisterReplace<CivHooks::CvCity_PreKill>(host, &ReplaceCvCity_PreKill);
Code
1424#if defined(MOD_GLOBAL_VENICE_KEEPS_RESOURCES) || defined(MOD_GLOBAL_CS_MARRIAGE_KEEPS_RESOURCES)1425void CvCity::PreKill(bool bKeepResources)1426#else1427void CvCity::PreKill()1428#endif1429{1430 VALIDATE_OBJECT14311432 PlayerTypes eOwner;1433 if(isCitySelected())1434 {1435 DLLUI->clearSelectedCities();1436 }14371438#if defined(MOD_GLOBAL_CITY_AUTOMATON_WORKERS)1439 setAutomatons(0);1440#endif1441 setPopulation(0);14421443 CvPlot* pPlot = plot();14441445#if defined(MOD_BUGFIX_MINOR)1446 GC.getGame().GetGameTrade()->ClearAllCityTradeRoutes(pPlot, true);1447#else1448 GC.getGame().GetGameTrade()->ClearAllCityTradeRoutes(pPlot);1449#endif14501451 // Update resources linked to this city1452#if defined(MOD_GLOBAL_CITY_WORKING)1453 for(int iI = 0; iI < GetNumWorkablePlots(); iI++)1454#else1455 for(int iI = 0; iI < NUM_CITY_PLOTS; iI++)1456#endif1457 {1458 CvPlot* pLoopPlot;1459 pLoopPlot = GetCityCitizens()->GetCityPlotFromIndex(iI);14601461 if(pLoopPlot != NULL)1462 {1463 if(pLoopPlot->getWorkingCityOverride() == this)1464 {1465 pLoopPlot->setWorkingCityOverride(NULL);1466 }14671468 // Unlink Resources from this City1469 if(pLoopPlot->getOwner() == getOwner())1470 {1471 if(pLoopPlot->getResourceType() != NO_RESOURCE)1472 {1473 if(pLoopPlot->GetResourceLinkedCity() == this)1474 {1475 pLoopPlot->SetResourceLinkedCity(NULL);1476 pLoopPlot->DoFindCityToLinkResourceTo(this);1477 }1478 }1479 }1480 }1481 }14821483 // If this city was built on a Resource, remove its Quantity from total1484 if(pPlot->getResourceType() != NO_RESOURCE)1485 {1486 if(GET_TEAM(getTeam()).GetTeamTechs()->HasTech((TechTypes) GC.getResourceInfo(pPlot->getResourceType())->getTechCityTrade()))1487 {1488 GET_PLAYER(getOwner()).changeNumResourceTotal(pPlot->getResourceType(), -pPlot->getNumResourceForPlayer(getOwner()));1489 }1490 }14911492#if defined(MOD_GLOBAL_VENICE_KEEPS_RESOURCES) || defined(MOD_GLOBAL_CS_MARRIAGE_KEEPS_RESOURCES)1493 plot()->removeMinorResources(bKeepResources);1494#else1495 if(GET_PLAYER(getOwner()).isMinorCiv())1496 {1497 GET_PLAYER(getOwner()).GetMinorCivAI()->DoRemoveStartingResources(plot());1498 }1499#endif15001501 for(int iI = 0; iI < GC.getNumBuildingInfos(); iI++)1502 {1503 CvBuildingEntry* pkBuilding = GC.getBuildingInfo((BuildingTypes)iI);1504 if(pkBuilding)1505 {1506 m_pCityBuildings->SetNumRealBuilding(((BuildingTypes)iI), 0);1507 m_pCityBuildings->SetNumFreeBuilding(((BuildingTypes)iI), 0);1508 }1509 }15101511 clearOrderQueue();15121513 // Killing a city while in combat is not something we really expect to happen.1514 // It is *mostly* safe for it to happen, but combat systems must be able to gracefully handle the disapperance of a city.1515 CvAssertMsg_Debug(!isFighting(), "isFighting did not return false as expected");15161517 clearCombat();15181519 // Could also be non-garrisoned units here that we need to show1520 CvUnit* pLoopUnit;1521 for(int iUnitLoop = 0; iUnitLoop < pPlot->getNumUnits(); iUnitLoop++)1522 {1523 pLoopUnit = pPlot->getUnitByIndex(iUnitLoop);15241525 // Only show units that belong to this city's owner - that way we don't show units on EVERY city capture (since the old city is deleted in this case)1526 if(getOwner() == pLoopUnit->getOwner())1527 {1528 auto_ptr<ICvUnit1> pDllUnit(new CvDllUnit(pLoopUnit));1529 gDLL->GameplayUnitVisibility(pDllUnit.get(), !pLoopUnit->isInvisible(GC.getGame().getActiveTeam(),true) /*bVisible*/);1530 }1531 }15321533 for(int iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++)1534 {1535 CvPlot* pLoopPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop);1536 if(NULL != pLoopPlot && pLoopPlot->GetCityPurchaseOwner() == getOwner() && pLoopPlot->GetCityPurchaseID() == GetID())1537 {1538 pLoopPlot->ClearCityPurchaseInfo();1539 pLoopPlot->setOwner(NO_PLAYER, NO_PLAYER, /*bCheckUnits*/ true, /*bUpdateResources*/ true);1540 }1541 }15421543 pPlot->setPlotCity(NULL);15441545 area()->changeCitiesPerPlayer(getOwner(), -1);15461547 GET_TEAM(getTeam()).changeNumCities(-1);15481549 GC.getGame().changeNumCities(-1);15501551 CvAssertMsg(getNumGreatPeople() == 0, "getNumGreatPeople is expected to be 0");1552 CvAssertMsg(!isProduction(), "isProduction is expected to be false");15531554 eOwner = getOwner();15551556 GET_PLAYER(getOwner()).GetFlavorManager()->RemoveFlavorRecipient(m_pCityStrategyAI);15571558 if(m_unitBeingBuiltForOperation.IsValid())1559 {1560 GET_PLAYER(getOwner()).CityUncommitToBuildUnitForOperationSlot(m_unitBeingBuiltForOperation);1561 m_unitBeingBuiltForOperation.Invalidate();1562 }1563}