Code
3483/// Delete older units no longer needed by military AI3484void CvMilitaryAI::DisbandObsoleteUnits()3485{3486 AI_PERF_FORMAT("Military-AI-perf.csv", ("DisbandObsoleteUnits, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );34873488 bool bInDeficit = false;3489 bool bConquestGrandStrategy = false;3490 UnitHandle pNavalUnit;3491 UnitHandle pLandUnit;3492 int iNavalScore = MAX_INT;3493 int iLandScore = MAX_INT;34943495 // Don't do this if at war3496 if(GetNumberCivsAtWarWith() > 0)3497 {3498 return;3499 }35003501 // Don't do this if we're a minor civ3502 if(m_pPlayer->isMinorCiv())3503 {3504 return;3505 }35063507 // Are we running at a deficit?3508 EconomicAIStrategyTypes eStrategyLosingMoney = (EconomicAIStrategyTypes) GC.getInfoTypeForString("ECONOMICAISTRATEGY_LOSING_MONEY");3509 bInDeficit = m_pPlayer->GetEconomicAI()->IsUsingStrategy(eStrategyLosingMoney);35103511 int iGoldSpentOnUnits = m_pPlayer->GetTreasury()->GetExpensePerTurnUnitMaintenance();3512 int iAverageGoldPerUnit = iGoldSpentOnUnits / (max(1,m_pPlayer->getNumUnits()));35133514 // if our units maintenance cost is high we may want to scrap some obsolete stuff3515 bInDeficit = bInDeficit || iAverageGoldPerUnit > 5;35163517 // Are we running anything other than the Conquest Grand Strategy?3518 AIGrandStrategyTypes eConquestGrandStrategy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CONQUEST");3519 if(eConquestGrandStrategy != NO_AIGRANDSTRATEGY)3520 {3521 if(m_pPlayer->GetGrandStrategyAI()->GetActiveGrandStrategy() == eConquestGrandStrategy)3522 {3523 bConquestGrandStrategy = true;3524 }3525 }35263527 // Look for obsolete land units if in deficit or have sufficient units3528 if(bInDeficit || (m_eLandDefenseState <= DEFENSE_STATE_NEUTRAL && !bConquestGrandStrategy))3529 {3530 pLandUnit = FindBestUnitToScrap(true /*bLand*/, false /*bDeficitForcedDisband*/, iLandScore);3531 }35323533 // Look for obsolete naval units if in deficit or have sufficient units3534 if(bInDeficit || (m_eNavalDefenseState <= DEFENSE_STATE_NEUTRAL && !bConquestGrandStrategy))3535 {3536 pNavalUnit = FindBestUnitToScrap(false/*bNaval*/, false /*bDeficitForcedDisband*/, iNavalScore);3537 }35383539 if(iLandScore < MAX_INT && (m_eLandDefenseState <= m_eNavalDefenseState || iLandScore <= iNavalScore))3540 {3541 if(pLandUnit)3542 {3543 pLandUnit->scrap();3544 LogScrapUnit(pLandUnit, bInDeficit, bConquestGrandStrategy);3545 }3546 }3547 else if(iNavalScore < MAX_INT)3548 {3549 if(pNavalUnit)3550 {3551 pNavalUnit->scrap();3552 LogScrapUnit(pNavalUnit, bInDeficit, bConquestGrandStrategy);3553 }3554 }3555}