Code
3217/// Set fighters to intercept3218void CvTacticalAI::PlotAirInterceptMoves()3219{3220 list<int>::iterator it;3221 m_CurrentMoveUnits.clear();3222 CvTacticalUnit unit;3223#if defined(MOD_AI_SMART_V3)3224 std::vector<CvPlot*> checkedPlotList;3225#endif3226 CvTacticalDominanceZone *pZone;32273228 // Loop through all recruited units3229 for(it = m_CurrentTurnUnits.begin(); it != m_CurrentTurnUnits.end(); it++)3230 {3231 UnitHandle pUnit = m_pPlayer->getUnit(*it);3232 if(pUnit)3233 {3234 // Am I eligible to intercept?3235#if defined(MOD_AI_SMART_V3)3236 if (MOD_AI_SMART_V3)3237 {3238 // we only commandeered units which won't be rebased3239 if(pUnit->canAirPatrol(NULL) && !m_pPlayer->GetMilitaryAI()->WillAirUnitRebase(pUnit.pointer()))3240 {3241 CvPlot* pUnitPlot = pUnit->plot();3242 int iNumNearbyBombers = m_pPlayer->GetMilitaryAI()->GetNumEnemyAirUnitsInRange(pUnitPlot, pUnit->GetRange(), false/*bCountFighters*/, true/*bCountBombers*/);3243 int iNumNearbyFighters = m_pPlayer->GetMilitaryAI()->GetNumEnemyAirUnitsInRange(pUnitPlot, pUnit->GetRange(), true/*bCountFighters*/, false/*bCountBombers*/);3244 int iNumPlotNumAlreadySet = SamePlotFound(checkedPlotList, pUnitPlot);32453246 if (iNumNearbyBombers == 1)3247 {3248 // To at least intercept once if only one bomber found.3249 iNumNearbyBombers++;3250 }3251 int maxInterceptorsWanted = ((iNumNearbyBombers / 2) + (iNumNearbyFighters / 4));32523253 if (iNumPlotNumAlreadySet < maxInterceptorsWanted)3254 {3255 checkedPlotList.push_back(pUnitPlot);3256 unit.SetID(pUnit->GetID());3257 m_CurrentMoveUnits.push_back(unit);32583259 if(GC.getLogging() && GC.getAILogging())3260 {3261 CvString strLogString;3262 strLogString.Format("Ready to intercept enemy air units at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3263 LogTacticalMessage(strLogString);3264 }3265 }3266 else3267 {3268 CvCity* pCity = pUnitPlot->getPlotCity();3269 pZone = NULL;32703271 if (pCity)3272 {3273 pZone = m_pMap->GetZoneByCity(pCity, false);3274 }3275 int iNumNearbyBombers = m_pPlayer->GetMilitaryAI()->GetNumEnemyAirUnitsInRange(pUnitPlot, m_iRecruitRange, false/*bCountFighters*/, true/*bCountBombers*/);32763277 // On a carrier or in a city where we are not dominant and near some enemy bombers?3278 if (!pCity || !pZone || pZone->GetDominanceFlag() != TACTICAL_DOMINANCE_FRIENDLY)3279 {3280 if (iNumNearbyBombers > 0)3281 {3282 unit.SetID(pUnit->GetID());3283 m_CurrentMoveUnits.push_back(unit);32843285 if(GC.getLogging() && GC.getAILogging())3286 {3287 CvString strLogString;3288 strLogString.Format("Ready to intercept enemy air units at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3289 LogTacticalMessage(strLogString);3290 }3291 }3292 }3293 }3294 }3295 }3296 else3297 {3298#endif3299 if(pUnit->canAirPatrol(NULL) && !m_pPlayer->GetMilitaryAI()->WillAirUnitRebase(pUnit.pointer()))3300 {3301 CvPlot* pUnitPlot = pUnit->plot();3302 CvCity* pCity = pUnitPlot->getPlotCity();3303 pZone = NULL;33043305 if (pCity)3306 {3307 pZone = m_pMap->GetZoneByCity(pCity, false);3308 }3309 int iNumNearbyBombers = m_pPlayer->GetMilitaryAI()->GetNumEnemyAirUnitsInRange(pUnitPlot, m_iRecruitRange, false/*bCountFighters*/, true/*bCountBombers*/);33103311 // On a carrier or in a city where we are not dominant and near some enemy bombers?3312 if (!pCity || !pZone || pZone->GetDominanceFlag() != TACTICAL_DOMINANCE_FRIENDLY)3313 {3314 if (iNumNearbyBombers > 0)3315 {3316 unit.SetID(pUnit->GetID());3317 m_CurrentMoveUnits.push_back(unit);33183319 if(GC.getLogging() && GC.getAILogging())3320 {3321 CvString strLogString;3322 strLogString.Format("Ready to intercept enemy air units at, X: %d, Y: %d", pUnit->getX(), pUnit->getY());3323 LogTacticalMessage(strLogString);3324 }3325 }3326 }3327 }3328#if defined(MOD_AI_SMART_V3)3329 }3330#endif3331 }3332 }33333334 if(m_CurrentMoveUnits.size() > 0)3335 {3336 ExecuteAirInterceptMoves();3337 }3338}