Bazaar developer reference

CvPlayer::getAdvancedStartCityCost(bool, CvPlot *)

Defined in
CvPlayer.cpp, line 22934
Class
CvPlayer
Hook name
CivHooks::CvPlayer_getAdvancedStartCityCost

Hooks

static bool BeforeCvPlayer_getAdvancedStartCityCost(CvPlayer* self, bool bAdd, CvPlot* pPlot, int& result);static void AfterCvPlayer_getAdvancedStartCityCost(CvPlayer* self, bool bAdd, CvPlot* pPlot, int& result);static int ReplaceCvPlayer_getAdvancedStartCityCost(int (*original)(CvPlayer*, bool, CvPlot*), CvPlayer* self, bool bAdd, CvPlot* pPlot);CivRegisterBefore<CivHooks::CvPlayer_getAdvancedStartCityCost>(host, &BeforeCvPlayer_getAdvancedStartCityCost);CivRegisterAfter<CivHooks::CvPlayer_getAdvancedStartCityCost>(host, &AfterCvPlayer_getAdvancedStartCityCost);CivRegisterReplace<CivHooks::CvPlayer_getAdvancedStartCityCost>(host, &ReplaceCvPlayer_getAdvancedStartCityCost);

Code

22934int CvPlayer::getAdvancedStartCityCost(bool bAdd, CvPlot* pPlot)22935{22936	int iNumCities = getNumCities();2293722938	int iCost = getNewCityProductionValue();2293922940	if(iCost < 0)22941	{22942		return -1;22943	}2294422945	// Valid plot?22946	if(pPlot != NULL)22947	{22948		// Need valid plot to found on if adding22949		if(bAdd)22950		{22951			if(!canFound(pPlot->getX(), pPlot->getY(), false))22952			{22953				return -1;22954			}22955		}22956		// Need your own city present to remove22957		else22958		{22959			if(pPlot->isCity())22960			{22961				if(pPlot->getPlotCity()->getOwner() != GetID())22962				{22963					return -1;22964				}22965			}22966			else22967			{22968				return -1;22969			}22970		}2297122972		// Is there a distance limit on how far a city can be placed from a player's start/another city?22973		if(GC.getADVANCED_START_CITY_PLACEMENT_MAX_RANGE() > 0)22974		{22975			PlayerTypes eClosestPlayer = NO_PLAYER;22976			int iClosestDistance = INT_MAX;2297722978			for(int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; ++iPlayer)22979			{22980				CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iPlayer);2298122982				if(kPlayer.isAlive())22983				{22984					CvPlot* pStartingPlot = kPlayer.getStartingPlot();2298522986					if(NULL != pStartingPlot)22987					{22988						int iDistance = ::plotDistance(pPlot->getX(), pPlot->getY(), pStartingPlot->getX(), pStartingPlot->getY());22989						if(iDistance <= GC.getADVANCED_START_CITY_PLACEMENT_MAX_RANGE())22990						{22991							if(iDistance < iClosestDistance || (iDistance == iClosestDistance && getTeam() != kPlayer.getTeam()))22992							{22993								iClosestDistance = iDistance;22994								eClosestPlayer = kPlayer.GetID();22995							}22996						}22997					}22998				}22999			}2300023001			if(NO_PLAYER == eClosestPlayer || GET_PLAYER(eClosestPlayer).getTeam() != getTeam())23002			{23003				return -1;23004			}23005			//Only allow founding a city at someone elses start point if23006			//We have no cities and they have no cities.23007			if((GetID() != eClosestPlayer) && ((getNumCities() > 0) || (GET_PLAYER(eClosestPlayer).getNumCities() > 0)))23008			{23009				return -1;23010			}23011		}23012	}2301323014	// Increase cost if the XML defines that additional units will cost more23015	if(0 != GC.getADVANCED_START_CITY_COST_INCREASE())23016	{23017		if(!bAdd)23018		{23019			--iNumCities;23020		}2302123022		if(iNumCities > 0)23023		{23024			iCost *= 100 + GC.getADVANCED_START_CITY_COST_INCREASE() * iNumCities;23025			iCost /= 100;23026		}23027	}2302823029	return iCost;23030}

Calls

Called by