Bazaar developer reference

CvAIOperation::GetGatherTolerance(CvArmyAI *, CvPlot *) const

Defined in
CvAIOperation.cpp, line 217
Class
CvAIOperation
Hook name
CivHooks::CvAIOperation_GetGatherTolerance

Hooks

static bool BeforeCvAIOperation_GetGatherTolerance(const CvAIOperation* self, CvArmyAI* pArmy, CvPlot* pPlot, int& result);static void AfterCvAIOperation_GetGatherTolerance(const CvAIOperation* self, CvArmyAI* pArmy, CvPlot* pPlot, int& result);static int ReplaceCvAIOperation_GetGatherTolerance(int (*original)(const CvAIOperation*, CvArmyAI*, CvPlot*), const CvAIOperation* self, CvArmyAI* pArmy, CvPlot* pPlot);CivRegisterBefore<CivHooks::CvAIOperation_GetGatherTolerance>(host, &BeforeCvAIOperation_GetGatherTolerance);CivRegisterAfter<CivHooks::CvAIOperation_GetGatherTolerance>(host, &AfterCvAIOperation_GetGatherTolerance);CivRegisterReplace<CivHooks::CvAIOperation_GetGatherTolerance>(host, &ReplaceCvAIOperation_GetGatherTolerance);

Code

217int CvAIOperation::GetGatherTolerance(CvArmyAI* pArmy, CvPlot* pPlot) const218{219	CvTacticalAnalysisCell* pCell;220	CvTacticalAnalysisMap* pMap = GC.getGame().GetTacticalAnalysisMap();221	int iRtnValue = 1;222	int iValidPlotsNearby = 0;223224	// Find out how many units are trying to gather225	int iNumUnits = pArmy->GetNumSlotsFilled();226227	// If not more than 1, zero tolerance is fine (we should get the unit to the gather point)228	if(iNumUnits < 1)229	{230		iRtnValue = 0;231	}232	else233	{234		int iRange = OperationalAIHelpers::GetGatherRangeForXUnits(iNumUnits);235		for(int iX = -iRange; iX <= iRange; iX++)236		{237			for(int iY = -iRange; iY <= iRange; iY++)238			{239				int iPlotIndex = GC.getMap().plotNum(pPlot->getX(), pPlot->getY());240				pCell = pMap->GetCell(iPlotIndex);241242				if((IsMixedLandNavalOperation() || IsAllNavalOperation()) && !pCell->CanUseForOperationGatheringCheckWater(true))243				{244					continue;245				}246247				if((IsMixedLandNavalOperation() || IsAllNavalOperation()) && !pArmy->IsAllOceanGoing() && pCell->IsOcean())248				{249					continue;250				}251252				iValidPlotsNearby++;253			}254		}255256		// Find more valid plots than units?257		if(iValidPlotsNearby > iNumUnits)258		{259			// If so, just use normal range for this many units260			iRtnValue = iRange;261		}262263		// Something constrained here, give ourselves a lot of leeway264		else265		{266			iRtnValue = 3;267		}268	}269270	return iRtnValue;271}

Calls

Called by