Hooks
static bool BeforeCvReligionAI_ChooseProphetTargetPlot(CvReligionAI* self, UnitHandle pUnit, int* piTurns, CvPlot*& result);static void AfterCvReligionAI_ChooseProphetTargetPlot(CvReligionAI* self, UnitHandle pUnit, int* piTurns, CvPlot*& result);static CvPlot* ReplaceCvReligionAI_ChooseProphetTargetPlot(CvPlot* (*original)(CvReligionAI*, UnitHandle, int*), CvReligionAI* self, UnitHandle pUnit, int* piTurns);CivRegisterBefore<CivHooks::CvReligionAI_ChooseProphetTargetPlot>(host, &BeforeCvReligionAI_ChooseProphetTargetPlot);CivRegisterAfter<CivHooks::CvReligionAI_ChooseProphetTargetPlot>(host, &AfterCvReligionAI_ChooseProphetTargetPlot);CivRegisterReplace<CivHooks::CvReligionAI_ChooseProphetTargetPlot>(host, &ReplaceCvReligionAI_ChooseProphetTargetPlot);
Code
5686/// Choose a plot next to the target city for the prophet to maneuver to5687CvPlot* CvReligionAI::ChooseProphetTargetPlot(UnitHandle pUnit, int* piTurns)5688{5689 CvCity* pCity = ChooseProphetConversionCity(false/*bOnlyBetterThanEnhancingReligion*/);5690 int iBestNumTurns = MAX_INT;5691 int iTurns;5692 int iBestDistance = MAX_INT;5693 int iDistance;5694 CvPlot* pBestTarget = NULL;56955696 if(pCity == NULL)5697 {5698 return NULL;5699 }57005701 // Our city with no civilian units? If so go right in there5702 if(pCity->getOwner() == m_pPlayer->GetID())5703 {5704 CvUnit* pFirstUnit = pCity->plot()->getUnitByIndex(0);5705 if(!pFirstUnit || pFirstUnit->IsCombatUnit())5706 {5707 iTurns = TurnsToReachTarget(pUnit, pCity->plot(), true /* bReusePaths */);5708 if(iTurns < MAX_INT)5709 {5710 *piTurns = iTurns;5711 return pCity->plot();5712 }5713 }5714 }57155716#pragma warning ( push )5717#pragma warning ( disable : 6011 ) // Dereferencing NULL pointer5718 AI_PERF_FORMAT("AI-perf-tact.csv", ("ChooseProphetTargetPlot: %s %d; %s, Turn %03d, %s", pUnit->getName().c_str(), pUnit->GetID(), pCity->getName().c_str(), GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );5719#pragma warning ( pop )57205721 // Find adjacent plot with no units (that aren't our own)5722 CvPlot* pLoopPlot;5723 for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)5724 {5725 pLoopPlot = plotDirection(pCity->getX(), pCity->getY(), ((DirectionTypes)iI));57265727 if(pLoopPlot != NULL)5728 {5729 CvUnit* pFirstUnit = pLoopPlot->getUnitByIndex(0);5730 if(pFirstUnit && pFirstUnit->getOwner() != m_pPlayer->GetID())5731 {5732 continue;5733 }57345735 if(pUnit->CanSpreadReligion(pLoopPlot))5736 {5737 iTurns = TurnsToReachTarget(pUnit, pLoopPlot, true /* bReusePaths */);5738 if(iTurns < MAX_INT)5739 {5740 iDistance = plotDistance(pUnit->getX(), pUnit->getY(), pLoopPlot->getX(), pLoopPlot->getY());57415742 // Consider it to be twice as far if a water plot (those are dangerous!)5743 if(pLoopPlot->isWater())5744 {5745 iDistance *= 2;5746 }57475748 if(iTurns < iBestNumTurns || (iTurns == iBestNumTurns && iDistance < iBestDistance))5749 {5750 iBestNumTurns = iTurns;5751 iBestDistance = iDistance;5752 pBestTarget = pLoopPlot;5753 }5754 }5755 }5756 }5757 }57585759 if(piTurns)5760 *piTurns = iBestNumTurns;5761 return pBestTarget;5762}