Bazaar developer reference

CvMap::findCity(int, int, PlayerTypes, TeamTypes, bool, bool, TeamTypes, DirectionTypes, const CvCity *)

Defined in
CvMap.cpp, line 849
Class
CvMap
Hook name
CivHooks::CvMap_findCity

Hooks

static bool BeforeCvMap_findCity(CvMap* self, int iX, int iY, PlayerTypes eOwner, TeamTypes eTeam, bool bSameArea, bool bCoastalOnly, TeamTypes eTeamAtWarWith, DirectionTypes eDirection, const CvCity* pSkipCity, CvCity*& result);static void AfterCvMap_findCity(CvMap* self, int iX, int iY, PlayerTypes eOwner, TeamTypes eTeam, bool bSameArea, bool bCoastalOnly, TeamTypes eTeamAtWarWith, DirectionTypes eDirection, const CvCity* pSkipCity, CvCity*& result);static CvCity* ReplaceCvMap_findCity(CvCity* (*original)(CvMap*, int, int, PlayerTypes, TeamTypes, bool, bool, TeamTypes, DirectionTypes, const CvCity*), CvMap* self, int iX, int iY, PlayerTypes eOwner, TeamTypes eTeam, bool bSameArea, bool bCoastalOnly, TeamTypes eTeamAtWarWith, DirectionTypes eDirection, const CvCity* pSkipCity);CivRegisterBefore<CivHooks::CvMap_findCity>(host, &BeforeCvMap_findCity);CivRegisterAfter<CivHooks::CvMap_findCity>(host, &AfterCvMap_findCity);CivRegisterReplace<CivHooks::CvMap_findCity>(host, &ReplaceCvMap_findCity);

Code

849CvCity* CvMap::findCity(int iX, int iY, PlayerTypes eOwner, TeamTypes eTeam, bool bSameArea, bool bCoastalOnly, TeamTypes eTeamAtWarWith, DirectionTypes eDirection, const CvCity* pSkipCity)850{851	CvCity* pLoopCity;852	CvCity* pBestCity;853	int iValue;854	int iBestValue;855	int iLoop;856	int iI;857	CvPlot* pCheckPlot = plot(iX, iY);858859	CvAssertMsg(pCheckPlot != NULL, "Passed in an invalid plot to findCity");860	if (pCheckPlot == NULL)861		return NULL;862863	// XXX look for barbarian cities???864865	iBestValue = MAXINT;866	pBestCity = NULL;867868	for(iI = 0; iI < MAX_PLAYERS; iI++)869	{870		CvPlayer& thisPlayer = GET_PLAYER((PlayerTypes)iI);871		if(thisPlayer.isAlive())872		{873			if((eOwner == NO_PLAYER) || (iI == eOwner))874			{875				if((eTeam == NO_TEAM) || (thisPlayer.getTeam() == eTeam))876				{877					for(pLoopCity = thisPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = thisPlayer.nextCity(&iLoop))878					{879						if(!bSameArea || (pLoopCity->area() == pCheckPlot->area()) || (bCoastalOnly && (pLoopCity->waterArea() == pCheckPlot->area())))880						{881							if(!bCoastalOnly || pLoopCity->isCoastal())882							{883								if((eTeamAtWarWith == NO_TEAM) || atWar(thisPlayer.getTeam(), eTeamAtWarWith))884								{885									if((eDirection == NO_DIRECTION) || (estimateDirection(dxWrap(pLoopCity->getX() - iX), dyWrap(pLoopCity->getY() - iY)) == eDirection))886									{887										if((pSkipCity == NULL) || (pLoopCity != pSkipCity))888										{889											iValue = plotDistance(iX, iY, pLoopCity->getX(), pLoopCity->getY());890891											if(iValue < iBestValue)892											{893												iBestValue = iValue;894												pBestCity = pLoopCity;895											}896										}897									}898								}899							}900						}901					}902				}903			}904		}905	}906907	return pBestCity;908}

Calls

Called by