Hooks
static bool BeforeCvAIOperation_cpp_GetReachablePlot(FObjectHandle<CvUnit> pUnit, CvWeightedVector<CvPlot *, 1, true> & aPlots, int * iTurns, CvPlot *& result);static void AfterCvAIOperation_cpp_GetReachablePlot(FObjectHandle<CvUnit> pUnit, CvWeightedVector<CvPlot *, 1, true> & aPlots, int * iTurns, CvPlot *& result);static CvPlot * ReplaceCvAIOperation_cpp_GetReachablePlot(CvPlot * (*original)(FObjectHandle<CvUnit>, CvWeightedVector<CvPlot *, 1, true> &, int *), FObjectHandle<CvUnit> pUnit, CvWeightedVector<CvPlot *, 1, true> & aPlots, int * iTurns);CivRegisterBefore<CivHooks::CvAIOperation_cpp_GetReachablePlot>(host, &BeforeCvAIOperation_cpp_GetReachablePlot);CivRegisterAfter<CivHooks::CvAIOperation_cpp_GetReachablePlot>(host, &AfterCvAIOperation_cpp_GetReachablePlot);CivRegisterReplace<CivHooks::CvAIOperation_cpp_GetReachablePlot>(host, &ReplaceCvAIOperation_cpp_GetReachablePlot);
Code
4310// Return the first reachable plot in the weighted plot list.4311// It is assumed that the list has yet to be sorted and will do so.4312static CvPlot* GetReachablePlot(UnitHandle pUnit, WeightedPlotVector& aPlots, int *iTurns)4313{4314 CvPlot *pFoundPlot = NULL;4315 int iFoundWeight = 0;4316 int iFoundTurns = 0;4317 uint uiListSize; 4318 if ((uiListSize = aPlots.size()) > 0)4319 {4320 aPlots.SortItems();43214322 // This will check all the plots that have the same weight. It will mean a few more path-finds, but it will4323 // be more accurate.4324 for (uint i = uiListSize; i--; ) // Go backward, the CvWeightedVector sorts highest to lowest4325 {4326 CvPlot* pPlot = aPlots.GetElement(i);4327 int iWeight = aPlots.GetWeight(i);43284329 if (pFoundPlot)4330 {4331 if (iWeight > iFoundWeight)4332 break; // Already found one of a lower weight4333 4334 int iTurnsCalculated = TurnsToReachTarget(pUnit, pPlot, true /*bReusePaths*/, false);4335 if (iTurnsCalculated != MAX_INT)4336 {4337 if (iTurnsCalculated < iFoundTurns)4338 {4339 iFoundWeight = iWeight;4340 pFoundPlot = pPlot;4341 iFoundTurns = iTurnsCalculated;4342 if (iFoundTurns == 1)4343 break; // Not getting better than this4344 }4345 }4346 }4347 else4348 {4349 int iTurnsCalculated = TurnsToReachTarget(pUnit, pPlot, true /*bReusePaths*/, false);4350 if (iTurnsCalculated != MAX_INT)4351 {4352 iFoundWeight = iWeight;4353 pFoundPlot = pPlot;4354 iFoundTurns = iTurnsCalculated;4355 if (iFoundTurns == 1)4356 break; // Not getting better than this4357 }4358 }4359 }4360 }43614362 if (pFoundPlot)4363 {4364 if (iTurns)4365 *iTurns = iFoundTurns;4366 return pFoundPlot;4367 }43684369 return NULL;4370}