CvTacticalAI::PlotEmergencyPurchases()
- Defined in
- CvTacticalAI.cpp, line 3393
- Class
- CvTacticalAI
- Hook name
CivHooks::CvTacticalAI_PlotEmergencyPurchases
Hooks
static bool BeforeCvTacticalAI_PlotEmergencyPurchases(CvTacticalAI* self);static void AfterCvTacticalAI_PlotEmergencyPurchases(CvTacticalAI* self);static void ReplaceCvTacticalAI_PlotEmergencyPurchases(void (*original)(CvTacticalAI*), CvTacticalAI* self);CivRegisterBefore<CivHooks::CvTacticalAI_PlotEmergencyPurchases>(host, &BeforeCvTacticalAI_PlotEmergencyPurchases);CivRegisterAfter<CivHooks::CvTacticalAI_PlotEmergencyPurchases>(host, &AfterCvTacticalAI_PlotEmergencyPurchases);CivRegisterReplace<CivHooks::CvTacticalAI_PlotEmergencyPurchases>(host, &ReplaceCvTacticalAI_PlotEmergencyPurchases);
Code
3392/// Spend money to buy defenses3393void CvTacticalAI::PlotEmergencyPurchases()3394{3395 CvCity* pCity;3396 UnitHandle pCityDefender;3397 CvUnit* pUnit;33983399 if(m_pPlayer->isMinorCiv())3400 {3401 return;3402 }34033404 // Is this a dominance zone where we're defending a city?3405 CvTacticalDominanceZone* pZone = GC.getGame().GetTacticalAnalysisMap()->GetZone(m_iCurrentZoneIndex);3406 pCity = pZone->GetClosestCity();3407 if(pCity && pCity->getOwner() == m_pPlayer->GetID() && pZone->GetTerritoryType() == TACTICAL_TERRITORY_FRIENDLY && pZone->GetEnemyUnitCount() > 0)3408 {3409 // Make sure the city isn't about to fall. Test by seeing if there are high priority unit targets3410 for(unsigned int iI = 0; iI < m_ZoneTargets.size() && !pCity->isCapital(); iI++)3411 {3412 if(m_ZoneTargets[iI].GetTargetType() == AI_TACTICAL_TARGET_HIGH_PRIORITY_UNIT)3413 {3414 return; // Abandon hope for this city; save our money to use elsewhere3415 }3416 }34173418 m_pPlayer->GetMilitaryAI()->BuyEmergencyBuilding(pCity);34193420 // If two defenders, assume already have land and sea and skip this city3421 if (pCity->plot()->getNumDefenders(m_pPlayer->GetID()) < 2)3422 {3423 bool bBuyNavalUnit = false;3424 bool bBuyLandUnit = false;34253426 pCityDefender = pCity->plot()->getBestDefender(m_pPlayer->GetID());3427 if (!pCityDefender)3428 {3429 bBuyLandUnit = true;3430 if (pCity->isCoastal())3431 {3432 bBuyNavalUnit = true;3433 }3434 }3435 else3436 {3437 if (pCityDefender->getDomainType() == DOMAIN_LAND)3438 {3439 if (pCity->isCoastal())3440 {3441 bBuyNavalUnit = true;3442 }3443 }3444 else3445 {3446 bBuyLandUnit = true;3447 }3448 }34493450 if (bBuyLandUnit)3451 {3452 pUnit = m_pPlayer->GetMilitaryAI()->BuyEmergencyUnit(UNITAI_CITY_BOMBARD, pCity);3453 if(!pUnit)3454 {3455 pUnit = m_pPlayer->GetMilitaryAI()->BuyEmergencyUnit(UNITAI_RANGED, pCity);3456 }3457 }34583459 if (bBuyNavalUnit)3460 {3461 pUnit = m_pPlayer->GetMilitaryAI()->BuyEmergencyUnit(UNITAI_ASSAULT_SEA, pCity);3462 if (pUnit)3463 {3464 // Bought one, don't need to buy melee naval later3465 bBuyNavalUnit = false;3466 }3467 }34683469 // Always can try to buy air units3470 pUnit = m_pPlayer->GetMilitaryAI()->BuyEmergencyUnit(UNITAI_ATTACK_AIR, pCity);3471 if (!pUnit)3472 {3473 pUnit = m_pPlayer->GetMilitaryAI()->BuyEmergencyUnit(UNITAI_DEFENSE_AIR, pCity);3474 }34753476 // Melee naval if didn't buy Ranged naval, (or not)3477 //if (bBuyNavalUnit)3478 //{3479 // pUnit = m_pPlayer->GetMilitaryAI()->BuyEmergencyUnit(UNITAI_ATTACK_SEA, pCity);3480 //}3481 }3482 }3483}
Calls
BaseVector::operator[]BaseVector::size- CvCity::getOwner() const
- CvCity::isCapital() const
- CvCity::isCoastal(int) const
- CvCity::plot() const
- CvGame::GetTacticalAnalysisMap()
- CvGlobals::getGame()
- CvMilitaryAI::BuyEmergencyBuilding(CvCity *)
- CvMilitaryAI::BuyEmergencyUnit(UnitAITypes, CvCity *)
- CvPlayer::GetID() const
- CvPlayer::GetMilitaryAI() const
- CvPlayer::isMinorCiv() const
- CvPlot::getBestDefender(PlayerTypes, PlayerTypes, const CvUnit *, bool, bool, bool, bool)
- CvPlot::getNumDefenders(PlayerTypes) const
- CvTacticalAnalysisMap::GetZone(int)
- CvTacticalDominanceZone::GetClosestCity() const
- CvTacticalDominanceZone::GetEnemyUnitCount() const
- CvTacticalDominanceZone::GetTerritoryType() const
- CvTacticalTarget::GetTargetType()
- CvUnit::getDomainType() const
FObjectHandle::FObjectHandleFObjectHandle::operator!FObjectHandle::operator->FObjectHandle::operator=