Code
302// Indicate the plots we might want to move to that the enemy can attack303void CvTacticalAnalysisMap::MarkCellsNearEnemy()304{305 int iDistance;306307 // Look at every cell on the map308 for(int iI = 0; iI < GC.getMap().numPlots(); iI++)309 {310 bool bMarkedIt = false; // Set true once we've found one that enemy can move past (worst case)311312 CvPlot* pPlot = GC.getMap().plotByIndexUnchecked(iI);313 if(m_pPlots[iI].IsRevealed() && !m_pPlots[iI].IsImpassableTerrain() && !m_pPlots[iI].IsImpassableTerritory())314 {315 // Friendly cities always safe316 if(!m_pPlots[iI].IsFriendlyCity())317 {318 if(!pPlot->isVisibleToEnemyTeam(m_pPlayer->getTeam()))319 {320 m_pPlots[iI].SetNotVisibleToEnemy(true);321 }322 else323 {324 for(unsigned int iUnitIndex = 0; iUnitIndex < m_EnemyUnits.size() && !bMarkedIt; iUnitIndex++)325 {326 CvUnit* pUnit = m_EnemyUnits[iUnitIndex];327 if(pUnit->getArea() == pPlot->getArea())328 {329 // Distance check before hitting pathfinder330 iDistance = plotDistance(pUnit->getX(), pUnit->getY(), pPlot->getX(), pPlot->getY());331 if(iDistance == 0)332 {333 m_pPlots[iI].SetSubjectToAttack(true);334 m_pPlots[iI].SetEnemyCanMovePast(true);335 bMarkedIt = true;336 }337338 // TEMPORARY OPTIMIZATION: Assumes can't use roads or RR339 else if(iDistance <= pUnit->baseMoves())340 {341 int iTurnsToReach;342 iTurnsToReach = TurnsToReachTarget(pUnit, pPlot, true /*bReusePaths*/, true /*bIgnoreUnits*/); // Its ok to reuse paths because when ignoring units, we don't use the tactical analysis map (which we are building)343 if(iTurnsToReach <= 1)344 {345 m_pPlots[iI].SetSubjectToAttack(true);346 }347 if(iTurnsToReach == 0)348 {349 m_pPlots[iI].SetEnemyCanMovePast(true);350 bMarkedIt = true;351 }352 }353 }354 }355356 // Check adjacent plots for enemy citadels357 if(!m_pPlots[iI].IsSubjectToAttack())358 {359 CvPlot* pAdjacentPlot;360 for(int jJ = 0; jJ < NUM_DIRECTION_TYPES; jJ++)361 {362 pAdjacentPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)jJ));363 if(pAdjacentPlot != NULL && pAdjacentPlot->getOwner() != NO_PLAYER)364 {365 if(atWar(m_pPlayer->getTeam(), GET_PLAYER(pAdjacentPlot->getOwner()).getTeam()))366 {367 ImprovementTypes eImprovement = pAdjacentPlot->getImprovementType();368 if(eImprovement != NO_IMPROVEMENT && GC.getImprovementInfo(eImprovement)->GetNearbyEnemyDamage() > 0)369 {370 m_pPlots[iI].SetSubjectToAttack(true);371 break;372 }373 }374 }375 }376 }377 }378 }379 }380 }381}