Code
3392/// Spend money on units/buildings to supply units that can fuel future military operations3393void CvMilitaryAI::MakeOffensivePurchases()3394{3395 AI_PERF_FORMAT("Military-AI-perf.csv", ("MakeOffensivePurchases, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );33963397 CvUnit *pUnit;33983399 if (m_pPlayer->isMinorCiv())3400 {3401 return;3402 }34033404 // Are we winning all the wars we are in?3405 MilitaryAIStrategyTypes eStrategyAtWar = (MilitaryAIStrategyTypes) GC.getInfoTypeForString("MILITARYAISTRATEGY_AT_WAR");3406 if(!IsUsingStrategy(eStrategyAtWar) || m_pPlayer->GetDiplomacyAI()->GetStateAllWars() == STATE_ALL_WARS_WINNING)3407 {3408 // Do we have a high offensive personality flavor and our military could be larger?3409 if (m_pPlayer->GetFlavorManager()->GetPersonalityIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_OFFENSE")) >= 7 &&3410 (GetPercentOfRecommendedMilitarySize() < 100 || m_eNavalDefenseState > DEFENSE_STATE_ENOUGH))3411 {3412 // Do we have operations running (if so let them recruit the units)?3413 if (GetArmyBeingBuilt() == NO_ARMY_TYPE)3414 {3415 CvCity *pCity = m_pPlayer->getCapitalCity();3416 if (pCity == NULL)3417 {3418 return;3419 }34203421 // Do we need naval units most?3422 bool bNeedNaval = m_eNavalDefenseState > m_eLandDefenseState;3423 if (bNeedNaval)3424 {3425 // Get a different city if capital is not coastal3426 if (!pCity->isCoastal())3427 {3428 CvCity* pLoopCity;3429 int iCityLoop;3430 bNeedNaval = false;3431 for(pLoopCity = m_pPlayer->firstCity(&iCityLoop); pLoopCity != NULL && !bNeedNaval; pLoopCity = m_pPlayer->nextCity(&iCityLoop))3432 {3433 if(pLoopCity->isCoastal())3434 {3435 bNeedNaval = true;3436 pCity = pLoopCity;3437 }3438 }3439 }3440 }34413442 if (bNeedNaval)3443 {3444 pUnit = BuyEmergencyUnit(UNITAI_ASSAULT_SEA, pCity);3445 if (!pUnit)3446 {3447 pUnit = BuyEmergencyUnit(UNITAI_ATTACK_SEA, pCity);3448 }3449 }3450 else3451 {3452 if (m_iNumMeleeLandUnits <= m_iNumRangedLandUnits)3453 {3454 pUnit = BuyEmergencyUnit(UNITAI_FAST_ATTACK, pCity);3455 if (!pUnit)3456 {3457 pUnit = BuyEmergencyUnit(UNITAI_ATTACK, pCity);3458 if (!pUnit)3459 {3460 pUnit = BuyEmergencyUnit(UNITAI_DEFENSE, pCity);3461 }3462 }3463 }3464 else3465 {3466 pUnit = BuyEmergencyUnit(UNITAI_CITY_BOMBARD, pCity);3467 if (!pUnit)3468 {3469 pUnit = BuyEmergencyUnit(UNITAI_RANGED, pCity);3470 }3471 }3472 }3473 }3474 }3475 }3476}