Hooks
static bool BeforeCvReligionAI_ChooseInquisitorTargetPlot(CvReligionAI* self, UnitHandle pUnit, int* piTurns, CvPlot*& result);static void AfterCvReligionAI_ChooseInquisitorTargetPlot(CvReligionAI* self, UnitHandle pUnit, int* piTurns, CvPlot*& result);static CvPlot* ReplaceCvReligionAI_ChooseInquisitorTargetPlot(CvPlot* (*original)(CvReligionAI*, UnitHandle, int*), CvReligionAI* self, UnitHandle pUnit, int* piTurns);CivRegisterBefore<CivHooks::CvReligionAI_ChooseInquisitorTargetPlot>(host, &BeforeCvReligionAI_ChooseInquisitorTargetPlot);CivRegisterAfter<CivHooks::CvReligionAI_ChooseInquisitorTargetPlot>(host, &AfterCvReligionAI_ChooseInquisitorTargetPlot);CivRegisterReplace<CivHooks::CvReligionAI_ChooseInquisitorTargetPlot>(host, &ReplaceCvReligionAI_ChooseInquisitorTargetPlot);
Code
5491/// Choose a plot next to the target city for the inquisitor to maneuver to5492CvPlot* CvReligionAI::ChooseInquisitorTargetPlot(UnitHandle pUnit, int* piTurns)5493{5494 CvCity* pCity = ChooseInquisitorTargetCity(pUnit);5495 int iBestNumTurns = MAX_INT;5496 int iTurns;5497 int iBestDistance = MAX_INT;5498 int iDistance;5499 CvPlot* pBestTarget = NULL;55005501 if(pCity == NULL)5502 {5503 return NULL;5504 }55055506 // Our city with no civilian units? If so go right in there5507 if(pCity->getOwner() == m_pPlayer->GetID())5508 {5509 CvUnit* pFirstUnit = pCity->plot()->getUnitByIndex(0);5510 if(!pFirstUnit || pFirstUnit->IsCombatUnit())5511 {5512 iTurns = TurnsToReachTarget(pUnit, pCity->plot(), true /* bReusePaths */);5513 if(iTurns < MAX_INT)5514 {5515 *piTurns = iTurns;5516 return pCity->plot();5517 }5518 }5519 }55205521#pragma warning ( push )5522#pragma warning ( disable : 6011 ) // Dereferencing NULL pointer5523 AI_PERF_FORMAT("AI-perf-tact.csv", ("ChooseInquisitorTargetPlot: %s %d; %s, Turn %03d, %s", pUnit->getName().c_str(), pUnit->GetID(), pCity->getName().c_str(), GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );5524#pragma warning ( pop )55255526 // Find adjacent plot with no units (that aren't our own)5527 CvPlot* pLoopPlot;5528 for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)5529 {5530 pLoopPlot = plotDirection(pCity->getX(), pCity->getY(), ((DirectionTypes)iI));55315532 if(pLoopPlot != NULL)5533 {5534 CvUnit* pFirstUnit = pLoopPlot->getUnitByIndex(0);5535 if(pFirstUnit && pFirstUnit->getOwner() != m_pPlayer->GetID())5536 {5537 continue;5538 }55395540 if(pUnit->CanRemoveHeresy(pLoopPlot))5541 {5542 iTurns = TurnsToReachTarget(pUnit, pLoopPlot, true /* bReusePaths */);5543 if(iTurns < MAX_INT)5544 {5545 iDistance = plotDistance(pUnit->getX(), pUnit->getY(), pLoopPlot->getX(), pLoopPlot->getY());55465547 // Consider it to be twice as far if a water plot (those are dangerous!)5548 if(pLoopPlot->isWater())5549 {5550 iDistance *= 2;5551 }55525553 if(iTurns < iBestNumTurns || (iTurns == iBestNumTurns && iDistance < iBestDistance))5554 {5555 iBestNumTurns = iTurns;5556 iBestDistance = iDistance;5557 pBestTarget = pLoopPlot;5558 }5559 }5560 }5561 }5562 }55635564 if(piTurns)5565 *piTurns = iBestNumTurns;5566 return pBestTarget;5567}