Bazaar developer reference

CvPlayer::GetBestSettlePlot(CvUnit *, bool, int) const

Defined in
CvPlayer.cpp, line 26963
Class
CvPlayer
Hook name
CivHooks::CvPlayer_GetBestSettlePlot

Hooks

static bool BeforeCvPlayer_GetBestSettlePlot(const CvPlayer* self, CvUnit* pUnit, bool bEscorted, int iArea, CvPlot*& result);static void AfterCvPlayer_GetBestSettlePlot(const CvPlayer* self, CvUnit* pUnit, bool bEscorted, int iArea, CvPlot*& result);static CvPlot* ReplaceCvPlayer_GetBestSettlePlot(CvPlot* (*original)(const CvPlayer*, CvUnit*, bool, int), const CvPlayer* self, CvUnit* pUnit, bool bEscorted, int iArea);CivRegisterBefore<CivHooks::CvPlayer_GetBestSettlePlot>(host, &BeforeCvPlayer_GetBestSettlePlot);CivRegisterAfter<CivHooks::CvPlayer_GetBestSettlePlot>(host, &AfterCvPlayer_GetBestSettlePlot);CivRegisterReplace<CivHooks::CvPlayer_GetBestSettlePlot>(host, &ReplaceCvPlayer_GetBestSettlePlot);

Code

26962/// Find the best spot in the entire world for this unit to settle26963CvPlot* CvPlayer::GetBestSettlePlot(CvUnit* pUnit, bool bEscorted, int iArea) const26964{26965	if(!pUnit)26966		return NULL;2696726968	int iSettlerX = pUnit->getX();26969	int iSettlerY = pUnit->getY();26970	int iUnitArea = pUnit->getArea();26971	PlayerTypes eOwner = pUnit->getOwner();26972	TeamTypes eTeam = pUnit->getTeam();2697326974	int iBestFoundValue = 0;26975	CvPlot* pBestFoundPlot = NULL;2697626977	int iEvalDistance = /*12*/ GC.getSETTLER_EVALUATION_DISTANCE();26978	int iDistanceDropoffMod = /*99*/ GC.getSETTLER_DISTANCE_DROPOFF_MODIFIER();2697926980	iEvalDistance += (GC.getGame().getGameTurn() * 5) / 100;2698126982	// scale this based on world size26983	const int iDefaultNumTiles = 80*52;26984	int iDefaultEvalDistance = iEvalDistance;26985	iEvalDistance = (iEvalDistance * GC.getMap().numPlots()) / iDefaultNumTiles;26986	iEvalDistance = max(iDefaultEvalDistance,iEvalDistance);2698726988	if(bEscorted && GC.getMap().GetAIMapHint() & 5)  // this is primarily a naval map or at the very least an offshore expansion map26989	{26990		iEvalDistance *= 3;26991		iEvalDistance /= 2;26992	}26993	// Stay close to home if don't have an escort (unless we were going offshore which doesn't use escorts anymore)26994	else if(!bEscorted)26995	{26996		iEvalDistance *= 2;26997		iEvalDistance /= 3;26998	}2699927000	CvMap& kMap = GC.getMap();27001	int iNumPlots = kMap.numPlots();27002	for(int iPlotLoop = 0; iPlotLoop < iNumPlots; iPlotLoop++)27003	{27004		CvPlot* pPlot = kMap.plotByIndexUnchecked(iPlotLoop);2700527006		if(!pPlot)27007		{27008			continue;27009		}2701027011		if(pPlot->getOwner() != NO_PLAYER && pPlot->getOwner() != eOwner)27012		{27013			continue;27014		}2701527016		if(!pPlot->isRevealed(getTeam()))27017		{27018			continue;27019		}2702027021		if(!pUnit->canFound(pPlot))27022		{27023			continue;27024		}2702527026		if(iArea != -1 && pPlot->getArea() != iArea)27027		{27028			continue;27029		}2703027031		if(pPlot->IsAdjacentOwnedByOtherTeam(eTeam))27032		{27033			continue;27034		}2703527036		if (IsPlotTargetedForCity(pPlot))27037		{27038			continue;27039		}2704027041		// Do we have to check if this is a safe place to go?27042		if(bEscorted || (!pPlot->isVisibleEnemyUnit(eOwner)))27043		{27044			int iValue = pPlot->getFoundValue(eOwner);27045			if(iValue > 5000)27046			{27047				int iSettlerDistance = ::plotDistance(pPlot->getX(), pPlot->getY(), iSettlerX, iSettlerY);27048				int iDistanceDropoff = min(99,(iDistanceDropoffMod * iSettlerDistance) / iEvalDistance);27049				iDistanceDropoff = max(0,iDistanceDropoff);27050				iValue = iValue * (100 - iDistanceDropoff) / 100;27051				if(pPlot->getArea() != iUnitArea)27052				{27053					if(GC.getMap().GetAIMapHint() & 5)  // this is primarily a naval map (or an offshore map like terra)27054					{27055						iValue *= 3;27056						iValue /= 2;27057					}27058					else27059					{27060						iValue *= 2;27061						iValue /= 3;27062					}27063				}27064				if(iValue > iBestFoundValue)27065				{27066					iBestFoundValue = iValue;27067					pBestFoundPlot = pPlot;27068				}27069			}27070		}27071	}27072	return pBestFoundPlot;27073}

Calls

Called by