Hooks
static bool BeforeCvTacticalAI_ScoreCloseOnPlots(CvTacticalAI* self, CvPlot* pTarget, bool bLandOnly, int& result);static void AfterCvTacticalAI_ScoreCloseOnPlots(CvTacticalAI* self, CvPlot* pTarget, bool bLandOnly, int& result);static int ReplaceCvTacticalAI_ScoreCloseOnPlots(int (*original)(CvTacticalAI*, CvPlot*, bool), CvTacticalAI* self, CvPlot* pTarget, bool bLandOnly);CivRegisterBefore<CivHooks::CvTacticalAI_ScoreCloseOnPlots>(host, &BeforeCvTacticalAI_ScoreCloseOnPlots);CivRegisterAfter<CivHooks::CvTacticalAI_ScoreCloseOnPlots>(host, &AfterCvTacticalAI_ScoreCloseOnPlots);CivRegisterReplace<CivHooks::CvTacticalAI_ScoreCloseOnPlots>(host, &ReplaceCvTacticalAI_ScoreCloseOnPlots);
Code
11176/// Pick best hexes for closing in on an enemy city. Returns number of ranged unit plots found11177int CvTacticalAI::ScoreCloseOnPlots(CvPlot* pTarget, bool bLandOnly)11178{11179 int iScore;11180 CvPlot* pPlot;11181 CvTacticalAnalysisCell* pCell;11182 bool bChoiceBombardSpot;11183 bool bSafeFromAttack;11184 CvTacticalTarget target;11185 int iRtnValue = 0;1118611187 // We'll store the hexes we've found here11188 m_TempTargets.clear();1118911190#if defined(MOD_GLOBAL_CITY_WORKING)11191 for(int jJ = 0; jJ < AVG_CITY_PLOTS; jJ++)11192#else11193 for(int jJ = 0; jJ < NUM_CITY_PLOTS; jJ++)11194#endif11195 {11196 pPlot = plotCity(pTarget->getX(), pTarget->getY(), jJ);1119711198 if(pPlot != NULL)11199 {11200 bChoiceBombardSpot = false;11201 bSafeFromAttack = true;1120211203 int iPlotDistance = plotDistance(pPlot->getX(), pPlot->getY(), pTarget->getX(), pTarget->getY());11204 int iPlotIndex = GC.getMap().plotNum(pPlot->getX(), pPlot->getY());11205 pCell = m_pMap->GetCell(iPlotIndex);1120611207 if((bLandOnly && pCell->CanUseForOperationGatheringCheckWater(false /*bWater*/)) || (!bLandOnly && pCell->CanUseForOperationGathering()))11208 {11209 bool bCloseEnough = false;11210 for(unsigned int iI = 0; iI < m_OperationUnits.size() && !bCloseEnough; iI++)11211 {11212 UnitHandle pUnit = m_pPlayer->getUnit(m_OperationUnits[iI].GetUnitID());11213 if(pUnit)11214 {11215 if(plotDistance(pPlot->getX(), pPlot->getY(), pUnit->getX(), pUnit->getY()) <= m_iDeployRadius)11216 {11217 bCloseEnough = true;11218 }11219 }11220 }1122111222 if(bCloseEnough)11223 {11224 iScore = 600 - (iPlotDistance * 100);1122511226 // Top priority is hexes to bombard from (within range but not adjacent)11227 if(pCell->IsWithinRangeOfTarget() && iPlotDistance > 1)11228 {11229 bChoiceBombardSpot = true;11230 iRtnValue++;11231 }1123211233 if(pCell->IsSubjectToAttack())11234 {11235 iScore -= 30;11236 bSafeFromAttack = false;11237 }1123811239 if(pCell->IsEnemyCanMovePast())11240 {11241 iScore -= 30;11242 }11243 if(pPlot->isCity() && pPlot->getOwner() == m_pPlayer->GetID())11244 {11245 iScore += 100;11246 }11247 else11248 {11249 iScore += pCell->GetDefenseModifier();11250 }1125111252 pCell->SetSafeForDeployment(bChoiceBombardSpot || bSafeFromAttack);11253 pCell->SetDeploymentScore(iScore);1125411255 // Save this in our list of potential targets11256 target.SetTargetX(pPlot->getX());11257 target.SetTargetY(pPlot->getY());11258 target.SetAuxIntData(iScore);1125911260 // A bit of a hack -- use high priority targets to indicate good plots for ranged units11261 if(bChoiceBombardSpot)11262 {11263 target.SetTargetType(AI_TACTICAL_TARGET_HIGH_PRIORITY_UNIT);11264 }11265 else11266 {11267 target.SetTargetType(AI_TACTICAL_TARGET_LOW_PRIORITY_UNIT);11268 }1126911270 m_TempTargets.push_back(target);11271 }11272 }11273 }11274 }11275 return iRtnValue;11276}