Bazaar developer reference

CvEconomicAI::DisbandLongObsoleteUnits()

Defined in
CvEconomicAI.cpp, line 2421
Class
CvEconomicAI
Hook name
CivHooks::CvEconomicAI_DisbandLongObsoleteUnits

Hooks

static bool BeforeCvEconomicAI_DisbandLongObsoleteUnits(CvEconomicAI* self);static void AfterCvEconomicAI_DisbandLongObsoleteUnits(CvEconomicAI* self);static void ReplaceCvEconomicAI_DisbandLongObsoleteUnits(void (*original)(CvEconomicAI*), CvEconomicAI* self);CivRegisterBefore<CivHooks::CvEconomicAI_DisbandLongObsoleteUnits>(host, &BeforeCvEconomicAI_DisbandLongObsoleteUnits);CivRegisterAfter<CivHooks::CvEconomicAI_DisbandLongObsoleteUnits>(host, &AfterCvEconomicAI_DisbandLongObsoleteUnits);CivRegisterReplace<CivHooks::CvEconomicAI_DisbandLongObsoleteUnits>(host, &ReplaceCvEconomicAI_DisbandLongObsoleteUnits);

Code

2419#if defined(MOD_AI_SMART_V3)2420// Check for very long obsolete units that didn't get an upgrade (usual suspects are wandering triremes and warriors)2421void CvEconomicAI::DisbandLongObsoleteUnits()2422{2423	CvUnit* pUnit;2424	int iLoop;2425	int unitEra;2426	int ArmyId;2427	int playerCurrentEra;2428	bool movingArmy;2429	CvTechEntry* pkTechInfo;2430	CvArmyAI* pThisArmy;2431	playerCurrentEra = m_pPlayer->GetCurrentEra();2432	// Treat information era as atomic for this checking.2433	playerCurrentEra = min(6, playerCurrentEra);24342435	// Loop through our units2436	for(pUnit = m_pPlayer->firstUnit(&iLoop); pUnit != NULL; pUnit = m_pPlayer->nextUnit(&iLoop))2437	{2438		if (pUnit)2439		{2440			movingArmy = false;2441			ArmyId = pUnit->getArmyID();24422443			if (ArmyId != -1)2444			{2445				pThisArmy = m_pPlayer->getArmyAI(ArmyId);24462447				if (pThisArmy)2448				{2449					movingArmy = ((pThisArmy->GetArmyAIState() == ARMYAISTATE_MOVING_TO_DESTINATION) || (pThisArmy->GetArmyAIState() == ARMYAISTATE_AT_DESTINATION));2450				}2451			}24522453			if(!movingArmy)2454			{2455				// The unit must have an upgrade option, if not, then we don't care about this (includes workers, settlers, explorers)2456				UnitTypes eUpgradeUnitType = pUnit->GetUpgradeUnitType();24572458				// Exclude settlers for this disband method, just in case2459				if(eUpgradeUnitType != NO_UNIT && !pUnit->isFound())2460				{2461					// Check out unit era based on the prerequirement tech, defaults at ancient era.2462					unitEra = 0;2463					UnitTypes currentUnitType = pUnit->getUnitType();2464					TechTypes ePrereqTech = (TechTypes)GC.getUnitInfo(currentUnitType)->GetPrereqAndTech();24652466					if (ePrereqTech != NO_TECH)2467					{2468						pkTechInfo = GC.getTechInfo(ePrereqTech);24692470						if (pkTechInfo)2471						{2472							unitEra = pkTechInfo->GetEra();2473						}2474					}24752476					// Too much era difference for that unit, lets scrap it.2477					if ((playerCurrentEra - unitEra) > 3)2478					{2479						if(GC.getLogging() && GC.getAILogging())2480						{2481							CvString strLogString;2482							strLogString.Format("Disbanding long obsolete unit. %s, X: %d, Y: %d", pUnit->getName().GetCString(), pUnit->getX(), pUnit->getY());2483							m_pPlayer->GetHomelandAI()->LogHomelandMessage(strLogString);2484						}24852486						pUnit->scrap();2487						// Only one unit scrap per turn.2488						return;2489					}2490				}2491			}2492		}2493	}2494}

Calls

Called by