CvTacticalAI::FindTacticalTargets()
- Defined in
- CvTacticalAI.cpp, line 1307
- Class
- CvTacticalAI
- Hook name
CivHooks::CvTacticalAI_FindTacticalTargets
Hooks
static bool BeforeCvTacticalAI_FindTacticalTargets(CvTacticalAI* self);static void AfterCvTacticalAI_FindTacticalTargets(CvTacticalAI* self);static void ReplaceCvTacticalAI_FindTacticalTargets(void (*original)(CvTacticalAI*), CvTacticalAI* self);CivRegisterBefore<CivHooks::CvTacticalAI_FindTacticalTargets>(host, &BeforeCvTacticalAI_FindTacticalTargets);CivRegisterAfter<CivHooks::CvTacticalAI_FindTacticalTargets>(host, &AfterCvTacticalAI_FindTacticalTargets);CivRegisterReplace<CivHooks::CvTacticalAI_FindTacticalTargets>(host, &ReplaceCvTacticalAI_FindTacticalTargets);
Code
1306/// Make lists of everything we might want to target with the tactical AI this turn1307void CvTacticalAI::FindTacticalTargets()1308{1309 int iI;1310 CvPlot* pLoopPlot;1311 CvTacticalTarget newTarget;1312 bool bValidPlot;1313 bool bEnemyDominatedPlot;1314 CvPlayerTrade* pPlayerTrade = m_pPlayer->GetTrade();13151316 // Clear out target list since we rebuild it each turn1317 m_AllTargets.clear();13181319 bool bBarbsAllowedYet = GC.getGame().getGameTurn() >= GC.getGame().GetBarbarianReleaseTurn();13201321 // Look at every tile on map1322 for(iI = 0; iI < GC.getMap().numPlots(); iI++)1323 {1324 pLoopPlot = GC.getMap().plotByIndexUnchecked(iI);1325 bValidPlot = false;13261327 if(pLoopPlot->isVisible(m_pPlayer->getTeam()))1328 {1329 // Make sure I am not a barbarian who can not move into owned territory this early in the game1330 if(!m_pPlayer->isBarbarian() || bBarbsAllowedYet)1331 {1332 bValidPlot = true;1333 }1334 else1335 {1336 if(!pLoopPlot->isOwned())1337 {1338 bValidPlot = true;1339 }1340 }1341 if(bValidPlot)1342 {1343 if(PlotAlreadyTargeted(pLoopPlot) != -1)1344 {1345 bValidPlot = false;1346 }1347 }1348 }13491350 if(bValidPlot)1351 {1352 newTarget.Clear();1353 newTarget.SetTargetX(pLoopPlot->getX());1354 newTarget.SetTargetY(pLoopPlot->getY());1355 newTarget.SetDominanceZone(GC.getGame().GetTacticalAnalysisMap()->GetCell(iI)->GetDominanceZone());13561357 bEnemyDominatedPlot = GC.getGame().GetTacticalAnalysisMap()->IsInEnemyDominatedZone(pLoopPlot);13581359 // Have a ...1360 // ... friendly city?1361 CvCity* pCity = pLoopPlot->getPlotCity();1362 if(pCity != NULL)1363 {1364 if(m_pPlayer->GetID() == pCity->getOwner())1365 {1366 newTarget.SetTargetType(AI_TACTICAL_TARGET_CITY_TO_DEFEND);1367 newTarget.SetAuxData((void*)pCity);1368 newTarget.SetAuxIntData(pCity->getThreatValue());1369 m_AllTargets.push_back(newTarget);1370 }13711372 // ... enemy city1373 else if(atWar(m_pPlayer->getTeam(), pCity->getTeam()))1374 {1375 newTarget.SetTargetType(AI_TACTICAL_TARGET_CITY);1376 newTarget.SetTargetPlayer(pCity->getOwner());1377 newTarget.SetAuxData((void*)pCity);1378 m_AllTargets.push_back(newTarget);1379 }1380 }1381 else1382 {1383 // ... enemy unit?1384 CvUnit* pUnit = pLoopPlot->getVisibleEnemyDefender(m_pPlayer->GetID());1385 if(pUnit != NULL)1386 {1387 newTarget.SetTargetType(AI_TACTICAL_TARGET_LOW_PRIORITY_UNIT);1388 newTarget.SetTargetPlayer(pUnit->getOwner());1389 newTarget.SetAuxData((void*)pUnit);1390 newTarget.SetAuxIntData(pUnit->getDamage());1391 m_AllTargets.push_back(newTarget);1392 }13931394 // ... undefended camp?1395 else if(pLoopPlot->getImprovementType() == GC.getBARBARIAN_CAMP_IMPROVEMENT())1396 {1397 newTarget.SetTargetType(AI_TACTICAL_TARGET_BARBARIAN_CAMP);1398 newTarget.SetTargetPlayer(BARBARIAN_PLAYER);1399 newTarget.SetAuxData((void*)pLoopPlot);1400 m_AllTargets.push_back(newTarget);1401 }14021403 // ... goody hut?1404 else if(!m_pPlayer->isMinorCiv() && pLoopPlot->isGoody())1405 {1406 newTarget.SetTargetType(AI_TACTICAL_TARGET_ANCIENT_RUINS);1407 newTarget.SetAuxData((void*)pLoopPlot);1408 m_AllTargets.push_back(newTarget);1409 }14101411 // Or citadels!1412 else if(atWar(m_pPlayer->getTeam(), pLoopPlot->getTeam()) &&1413 pLoopPlot->getImprovementType() != NO_IMPROVEMENT &&1414 GC.getImprovementInfo(pLoopPlot->getImprovementType())->GetNearbyEnemyDamage() > 0)1415 {1416 newTarget.SetTargetType(AI_TACTICAL_TARGET_CITADEL);1417 newTarget.SetTargetPlayer(pLoopPlot->getOwner());1418 newTarget.SetAuxData((void*)pLoopPlot);1419 m_AllTargets.push_back(newTarget);1420 }14211422 // ... enemy improvement?1423 else if(atWar(m_pPlayer->getTeam(), pLoopPlot->getTeam()) &&1424 pLoopPlot->getImprovementType() != NO_IMPROVEMENT &&1425 !pLoopPlot->IsImprovementPillaged())1426 {1427 ResourceUsageTypes eRUT = (ResourceUsageTypes)-1;1428 ResourceTypes eResource = pLoopPlot->getResourceType();1429 if (eResource != NO_RESOURCE)1430 {1431 eRUT = GC.getResourceInfo(eResource)->getResourceUsage();1432 }14331434 // On land, civs prioritize improvements built on resources1435 if (eRUT == RESOURCEUSAGE_STRATEGIC || eRUT == RESOURCEUSAGE_LUXURY || pLoopPlot->isWater() || m_pPlayer->isBarbarian())1436 {1437 // Barbarians can't target naval improvements1438 if(m_pPlayer->isBarbarian() && pLoopPlot->isWater())1439 {1440 continue;1441 }1442 else1443 {1444 newTarget.SetTargetType(AI_TACTICAL_TARGET_IMPROVEMENT_RESOURCE);1445 newTarget.SetTargetPlayer(pLoopPlot->getOwner());1446 newTarget.SetAuxData((void*)pLoopPlot);1447 m_AllTargets.push_back(newTarget);1448 }1449 }1450 else1451 {1452 newTarget.SetTargetType(AI_TACTICAL_TARGET_IMPROVEMENT);1453 newTarget.SetTargetPlayer(pLoopPlot->getOwner());1454 newTarget.SetAuxData((void*)pLoopPlot);1455 m_AllTargets.push_back(newTarget);1456 }1457 }14581459 // ... enemy trade route?1460 else if(atWar(m_pPlayer->getTeam(), pLoopPlot->getTeam()) &&1461 pLoopPlot->getRouteType() != NO_ROUTE && !pLoopPlot->IsRoutePillaged() && pLoopPlot->IsTradeRoute()/* && !bEnemyDominatedPlot*/)1462 {1463 newTarget.SetTargetType(AI_TACTICAL_TARGET_IMPROVEMENT);1464 newTarget.SetTargetPlayer(pLoopPlot->getOwner());1465 newTarget.SetAuxData((void*)pLoopPlot);1466 m_AllTargets.push_back(newTarget);1467 }14681469 // ... enemy civilian (or embarked) unit?1470 else if(pLoopPlot->isVisibleOtherUnit(m_pPlayer->GetID()))1471 {1472 CvUnit* pTargetUnit = pLoopPlot->getUnitByIndex(0);1473 if(!pTargetUnit->isDelayedDeath() && atWar(m_pPlayer->getTeam(), pTargetUnit->getTeam()) && !pTargetUnit->IsCanDefend())1474 {1475 newTarget.SetTargetType(AI_TACTICAL_TARGET_LOW_PRIORITY_CIVILIAN);1476 newTarget.SetTargetPlayer(pTargetUnit->getOwner());1477 newTarget.SetAuxData((void*)pTargetUnit);14781479 if(pTargetUnit->isEmbarked())1480 {1481 if(pTargetUnit->IsCombatUnit())1482 {1483 newTarget.SetTargetType(AI_TACTICAL_TARGET_EMBARKED_MILITARY_UNIT);1484 }1485 else1486 {1487 newTarget.SetTargetType(AI_TACTICAL_TARGET_EMBARKED_CIVILIAN);1488 }1489 }1490 else1491 {1492 if(IsVeryHighPriorityCivilianTarget(&newTarget))1493 {1494 newTarget.SetTargetType(AI_TACTICAL_TARGET_VERY_HIGH_PRIORITY_CIVILIAN);1495 }1496 else if(IsHighPriorityCivilianTarget(&newTarget))1497 {1498 newTarget.SetTargetType(AI_TACTICAL_TARGET_HIGH_PRIORITY_CIVILIAN);1499 }1500 else if(IsMediumPriorityCivilianTarget(&newTarget))1501 {1502 newTarget.SetTargetType(AI_TACTICAL_TARGET_MEDIUM_PRIORITY_CIVILIAN);1503 }1504 }1505 m_AllTargets.push_back(newTarget);1506 }1507 }15081509 // ... trade unit1510 else if (pPlayerTrade->ContainsEnemyTradeUnit(pLoopPlot))1511 {1512 if (pLoopPlot->isWater())1513 {1514 newTarget.SetTargetType(AI_TACTICAL_TARGET_TRADE_UNIT_SEA);1515 }1516 else1517 {1518 newTarget.SetTargetType(AI_TACTICAL_TARGET_TRADE_UNIT_LAND);1519 }15201521 newTarget.SetAuxData((void*)pLoopPlot);1522 m_AllTargets.push_back(newTarget);1523 }15241525 // ... defensive bastion?1526 else if(m_pPlayer->GetID() == pLoopPlot->getOwner() &&1527 pLoopPlot->defenseModifier(m_pPlayer->getTeam(), true) > 0 &&1528 m_pPlayer->GetPlotDanger(*pLoopPlot) > 0)1529 {1530 CvCity* pDefenseCity = pLoopPlot->GetAdjacentFriendlyCity(m_pPlayer->getTeam(), true/*bLandOnly*/);1531 if(pDefenseCity)1532 {1533 newTarget.SetTargetType(AI_TACTICAL_TARGET_DEFENSIVE_BASTION);1534 newTarget.SetAuxData((void*)pLoopPlot);1535 newTarget.SetAuxIntData(pDefenseCity->getThreatValue() + m_pPlayer->GetPlotDanger(*pLoopPlot));1536 m_AllTargets.push_back(newTarget);1537 }1538 }15391540 // ... friendly improvement?1541 else if(m_pPlayer->GetID() == pLoopPlot->getOwner() &&1542 pLoopPlot->getImprovementType() != NO_IMPROVEMENT &&1543 !pLoopPlot->IsImprovementPillaged() && !pLoopPlot->isGoody())1544 {1545 newTarget.SetTargetType(AI_TACTICAL_TARGET_IMPROVEMENT_TO_DEFEND);1546 newTarget.SetAuxData((void*)pLoopPlot);1547 m_AllTargets.push_back(newTarget);1548 }15491550 // ... trade plot (for getting units to park on trade routes to try to get them to plunder enemy trade routes)1551 else if (pLoopPlot->isVisible(m_pPlayer->getTeam()) && 1552 pPlayerTrade->ContainsEnemyTradePlot(pLoopPlot))1553 {1554 if (pLoopPlot->isWater())1555 {1556 newTarget.SetTargetType(AI_TACTICAL_TARGET_TRADE_UNIT_SEA_PLOT);1557 }1558 else1559 {1560 newTarget.SetTargetType(AI_TACTICAL_TARGET_TRADE_UNIT_LAND_PLOT);1561 }15621563 newTarget.SetAuxData((void*)pLoopPlot);1564 m_AllTargets.push_back(newTarget);1565 }1566 }1567 }1568 }15691570 // POST-PROCESSING ON TARGETS15711572 // Mark enemy units threatening our cities (or camps) as priority targets1573 if(m_pPlayer->isBarbarian())1574 {1575 IdentifyPriorityBarbarianTargets();1576 }1577 else1578 {1579 IdentifyPriorityTargets();1580 }15811582 // Also add some priority targets that we'd like to hit just because of their unit type (e.g. catapults)1583 IdentifyPriorityTargetsByType();15841585 // Remove extra targets1586 EliminateNearbyBlockadePoints();15871588 // Sort remaining targets by aux data (if used for that target type)1589 std::stable_sort(m_AllTargets.begin(), m_AllTargets.end());1590}
Calls
- atWar(TeamTypes, TeamTypes)
BaseVector::beginBaseVector::clearBaseVector::end- CvCity::getOwner() const
- CvCity::getTeam() const
- CvCity::getThreatValue()
- CvGame::GetBarbarianReleaseTurn() const
- CvGame::getGameTurn()
- CvGame::GetTacticalAnalysisMap()
- CvGlobals::getBARBARIAN_CAMP_IMPROVEMENT()
- CvGlobals::getGame()
- CvGlobals::getImprovementInfo(ImprovementTypes)
- CvGlobals::getMap()
- CvGlobals::getResourceInfo(ResourceTypes)
- CvImprovementEntry::GetNearbyEnemyDamage() const
- CvMap::numPlots() const
- CvMap::plotByIndexUnchecked(int) const
- CvPlayer::GetID() const
- CvPlayer::GetPlotDanger(CvPlot &) const
- CvPlayer::getTeam() const
- CvPlayer::GetTrade() const
- CvPlayer::isBarbarian() const
- CvPlayer::isMinorCiv() const
- CvPlayerTrade::ContainsEnemyTradePlot(const CvPlot *)
- CvPlayerTrade::ContainsEnemyTradeUnit(const CvPlot *)
- CvPlot::defenseModifier(TeamTypes, bool, bool) const
- CvPlot::GetAdjacentFriendlyCity(TeamTypes, bool) const
- CvPlot::getImprovementType() const
- CvPlot::getOwner() const
- CvPlot::getPlotCity() const
- CvPlot::getResourceType(TeamTypes) const
- CvPlot::getRouteType() const
- CvPlot::getTeam() const
- CvPlot::getUnitByIndex(int) const
- CvPlot::getVisibleEnemyDefender(PlayerTypes)
- CvPlot::getX() const
- CvPlot::getY() const
- CvPlot::isGoody(TeamTypes) const
- CvPlot::IsImprovementPillaged() const
- CvPlot::isOwned() const
- CvPlot::IsRoutePillaged() const
- CvPlot::IsTradeRoute(PlayerTypes) const
- CvPlot::isVisible(TeamTypes) const
- CvPlot::isVisibleOtherUnit(PlayerTypes) const
- CvPlot::isWater() const
- CvResourceInfo::getResourceUsage() const
- CvTacticalAI::EliminateNearbyBlockadePoints()
- CvTacticalAI::IdentifyPriorityBarbarianTargets()
- CvTacticalAI::IdentifyPriorityTargets()
- CvTacticalAI::IdentifyPriorityTargetsByType()
- CvTacticalAI::IsHighPriorityCivilianTarget(CvTacticalTarget *)
- CvTacticalAI::IsMediumPriorityCivilianTarget(CvTacticalTarget *)
- CvTacticalAI::IsVeryHighPriorityCivilianTarget(CvTacticalTarget *)
- CvTacticalAI::PlotAlreadyTargeted(CvPlot *)
- CvTacticalAnalysisCell::GetDominanceZone() const
- CvTacticalAnalysisMap::GetCell(int)
- CvTacticalAnalysisMap::IsInEnemyDominatedZone(CvPlot *)
- CvTacticalTarget::Clear()
- CvTacticalTarget::CvTacticalTarget()
- CvTacticalTarget::SetAuxData(void *)
- CvTacticalTarget::SetAuxIntData(int)
- CvTacticalTarget::SetDominanceZone(int)
- CvTacticalTarget::SetTargetPlayer(PlayerTypes)
- CvTacticalTarget::SetTargetType(AITacticalTargetType)
- CvTacticalTarget::SetTargetX(int)
- CvTacticalTarget::SetTargetY(int)
- CvUnit::getDamage() const
- CvUnit::getOwner() const
- CvUnit::getTeam() const
- CvUnit::IsCanDefend(const CvPlot *) const
- CvUnit::IsCombatUnit() const
- CvUnit::isDelayedDeath() const
- CvUnit::isEmbarked() const
FStaticVector::push_backstd::stable_sort