Code
2317/// Count up barbarian camps and units visible to us2318void CvMilitaryAI::ScanForBarbarians()2319{2320 AI_PERF_FORMAT("Military-AI-perf.csv", ("ScanForBarbarians, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );23212322 int iPlotLoop;2323 CvPlot* pPlot;23242325 m_iBarbarianCampCount = 0;2326 m_iVisibleBarbarianCount = 0;23272328 TeamTypes eTeam = m_pPlayer->getTeam();23292330 // Look at revealed Barbarian camps and visible units2331 for(iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++)2332 {2333 pPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop);23342335 if(pPlot->isRevealed(eTeam))2336 {2337 if(pPlot->getImprovementType() == GC.getBARBARIAN_CAMP_IMPROVEMENT())2338 {2339 m_iBarbarianCampCount++;23402341 // Count it as 10 camps if sitting inside our territory, that is annoying!2342 if(pPlot->getOwner() == m_pPlayer->GetID())2343 {2344 m_iBarbarianCampCount += 9;2345 }23462347 // See how close it is to each of our cities, if less than 10 tiles, treat it as 5 camps2348 else2349 {2350 int iTolerableDistance = 10;2351 int iCityLoop;2352 CvCity *pLoopCity;2353 for(pLoopCity = m_pPlayer->firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iCityLoop))2354 {2355 if (pLoopCity)2356 {2357 int iDist = plotDistance(pLoopCity->getX(), pLoopCity->getY(), pPlot->getX(), pPlot->getY());2358 if (iDist < iTolerableDistance)2359 {2360 m_iBarbarianCampCount += 4;2361 break;2362 }2363 }2364 }2365 }2366 }2367 }23682369 if(pPlot->isVisible(eTeam))2370 {2371 if(pPlot->plotCount(NULL, -1, -1, BARBARIAN_PLAYER, BARBARIAN_TEAM))2372 {2373 m_iVisibleBarbarianCount++;2374 }2375 }2376 }2377}