CvAIOperationPillageEnemy::FindBestTarget()
- Defined in
- CvAIOperation.cpp, line 2687
- Class
- CvAIOperationPillageEnemy
- Hook name
CivHooks::CvAIOperationPillageEnemy_FindBestTarget- Overrides
- CvAIEnemyTerritoryOperation::FindBestTarget()
Hooks
static bool BeforeCvAIOperationPillageEnemy_FindBestTarget(CvAIOperationPillageEnemy* self, CvPlot*& result);static void AfterCvAIOperationPillageEnemy_FindBestTarget(CvAIOperationPillageEnemy* self, CvPlot*& result);static CvPlot* ReplaceCvAIOperationPillageEnemy_FindBestTarget(CvPlot* (*original)(CvAIOperationPillageEnemy*), CvAIOperationPillageEnemy* self);CivRegisterBefore<CivHooks::CvAIOperationPillageEnemy_FindBestTarget>(host, &BeforeCvAIOperationPillageEnemy_FindBestTarget);CivRegisterAfter<CivHooks::CvAIOperationPillageEnemy_FindBestTarget>(host, &AfterCvAIOperationPillageEnemy_FindBestTarget);CivRegisterReplace<CivHooks::CvAIOperationPillageEnemy_FindBestTarget>(host, &ReplaceCvAIOperationPillageEnemy_FindBestTarget);
Code
2686/// Find the city that we want to pillage2687CvPlot* CvAIOperationPillageEnemy::FindBestTarget()2688{2689 CvCity* pBestTargetCity = NULL;2690 int iValue;2691 int iBestValue;2692 CvCity* pLoopCity;2693 CvCity* pStartCity;2694 int iDistance;2695 int iLoop;26962697 CvPlayerAI& kEnemyPlayer = GET_PLAYER(m_eEnemy);26982699 if(!kEnemyPlayer.isAlive())2700 {2701 return NULL;2702 }27032704 iBestValue = 0;2705 pStartCity = GetOperationStartCity();2706 if(pStartCity != NULL)2707 {2708 for(pLoopCity = kEnemyPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kEnemyPlayer.nextCity(&iLoop))2709 {2710 // Make sure city is in the same area as our start city2711 if(pLoopCity->getArea() == pStartCity->getArea())2712 {2713 // Initial value of target is the number of improved plots2714 iValue = pLoopCity->countNumImprovedPlots();27152716 // Adjust value based on proximity to our start location2717 iDistance = GC.getStepFinder().GetStepDistanceBetweenPoints(m_eOwner, m_eEnemy, pLoopCity->plot(), pStartCity->plot());2718 if(iDistance > 0)2719 {2720 iValue = iValue * 100 / iDistance;2721 }27222723 if(iValue > iBestValue)2724 {2725 iBestValue = iValue;2726 pBestTargetCity = pLoopCity;2727 }2728 }2729 }2730 }27312732 if(pBestTargetCity == NULL)2733 {2734 return NULL;2735 }2736 else2737 {2738 return pBestTargetCity->plot();2739 }2740}
Calls
- CvAIOperation::GetOperationStartCity() const
- CvCity::countNumImprovedPlots(ImprovementTypes, bool) const
- CvCity::getArea() const
- CvCity::plot() const
- CvGlobals::getStepFinder()
- CvPlayer::firstCity(int *, bool)
- CvPlayer::isAlive() const
- CvPlayer::nextCity(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvStepPathFinder::GetStepDistanceBetweenPoints(PlayerTypes, PlayerTypes, CvPlot *, CvPlot *)