CvAIOperationDestroyBarbarianCamp::FindBestTarget()
- Defined in
- CvAIOperation.cpp, line 2495
- Class
- CvAIOperationDestroyBarbarianCamp
- Hook name
CivHooks::CvAIOperationDestroyBarbarianCamp_FindBestTarget- Overrides
- CvAIEnemyTerritoryOperation::FindBestTarget()
Hooks
static bool BeforeCvAIOperationDestroyBarbarianCamp_FindBestTarget(CvAIOperationDestroyBarbarianCamp* self, CvPlot*& result);static void AfterCvAIOperationDestroyBarbarianCamp_FindBestTarget(CvAIOperationDestroyBarbarianCamp* self, CvPlot*& result);static CvPlot* ReplaceCvAIOperationDestroyBarbarianCamp_FindBestTarget(CvPlot* (*original)(CvAIOperationDestroyBarbarianCamp*), CvAIOperationDestroyBarbarianCamp* self);CivRegisterBefore<CivHooks::CvAIOperationDestroyBarbarianCamp_FindBestTarget>(host, &BeforeCvAIOperationDestroyBarbarianCamp_FindBestTarget);CivRegisterAfter<CivHooks::CvAIOperationDestroyBarbarianCamp_FindBestTarget>(host, &AfterCvAIOperationDestroyBarbarianCamp_FindBestTarget);CivRegisterReplace<CivHooks::CvAIOperationDestroyBarbarianCamp_FindBestTarget>(host, &ReplaceCvAIOperationDestroyBarbarianCamp_FindBestTarget);
Code
2494/// Find the barbarian camp we want to eliminate2495CvPlot* CvAIOperationDestroyBarbarianCamp::FindBestTarget()2496{2497 int iPlotLoop;2498 CvPlot* pBestPlot = NULL;2499 CvPlot* pPlot;2500 int iBestPlotDistance = MAX_INT;2501 int iCurPlotDistance;25022503 m_bCivilianRescue = false;25042505 TeamTypes eTeam = GET_PLAYER(m_eOwner).getTeam();2506 ImprovementTypes eBarbCamp = (ImprovementTypes) GC.getBARBARIAN_CAMP_IMPROVEMENT();25072508 CvCity* pStartCity;2509 pStartCity = GetOperationStartCity();2510 if(pStartCity != NULL)2511 {25122513 // look for good captured civilians of ours (settlers and workers, not missionaries) 2514 // these will be even more important than just a camp2515 // btw - the AI will cheat here - as a human I would use a combination of memory and intuition to find these, since our current AI has neither of these...2516 CvPlayerAI& BarbPlayer = GET_PLAYER(BARBARIAN_PLAYER);25172518 CvUnit* pLoopUnit = NULL;2519 int iLoop;2520 for (pLoopUnit = BarbPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = BarbPlayer.nextUnit(&iLoop))2521 {2522 if (pLoopUnit->GetOriginalOwner() == m_eOwner && (pLoopUnit->AI_getUnitAIType() == UNITAI_SETTLE || pLoopUnit->AI_getUnitAIType() == UNITAI_WORKER || pLoopUnit->AI_getUnitAIType() == UNITAI_ARCHAEOLOGIST))2523 {2524 iCurPlotDistance = GC.getStepFinder().GetStepDistanceBetweenPoints(m_eOwner, m_eEnemy, pLoopUnit->plot(), pStartCity->plot());2525 if (iCurPlotDistance < iBestPlotDistance)2526 {2527 pBestPlot = pLoopUnit->plot();2528 iBestPlotDistance = iCurPlotDistance;2529 m_bCivilianRescue = true;2530 m_iUnitToRescue = pLoopUnit->GetID();2531 }2532 }2533 }25342535 if (!pBestPlot)2536 {2537 // Look at map for Barbarian camps2538 for (iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++)2539 {2540 pPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop);25412542 if (pPlot->isRevealed(eTeam))2543 {2544 if (pPlot->getRevealedImprovementType(eTeam) == eBarbCamp)2545 {2546 // Make sure camp is in the same area as our start city2547 //if (pPlot->getArea() == pStartCity->getArea())2548 {2549 iCurPlotDistance = GC.getStepFinder().GetStepDistanceBetweenPoints(m_eOwner, m_eEnemy, pPlot, pStartCity->plot());25502551 if (iCurPlotDistance < iBestPlotDistance)2552 {2553 pBestPlot = pPlot;2554 iBestPlotDistance = iCurPlotDistance;2555 }2556 }2557 }2558 }2559 }2560 }25612562 }25632564 return pBestPlot;2565}
Calls
- CvAIOperation::GetOperationStartCity() const
- CvCity::plot() const
- CvGlobals::getBARBARIAN_CAMP_IMPROVEMENT()
- CvGlobals::getMap()
- CvGlobals::getStepFinder()
- CvMap::numPlots() const
- CvMap::plotByIndexUnchecked(int) const
- CvPlayer::firstUnit(int *, bool)
- CvPlayer::getTeam() const
- CvPlayer::nextUnit(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlot::getRevealedImprovementType(TeamTypes) const
- CvPlot::isRevealed(TeamTypes) const
- CvStepPathFinder::GetStepDistanceBetweenPoints(PlayerTypes, PlayerTypes, CvPlot *, CvPlot *)
- CvUnit::AI_getUnitAIType() const
- CvUnit::GetID() const
- CvUnit::GetOriginalOwner() const
- CvUnit::plot() const