Bazaar developer reference

CvPlayer::GetGreatAdmiralSpawnPlot(CvUnit *)

Defined in
CvPlayer.cpp, line 4019
Class
CvPlayer
Hook name
CivHooks::CvPlayer_GetGreatAdmiralSpawnPlot

Hooks

static bool BeforeCvPlayer_GetGreatAdmiralSpawnPlot(CvPlayer* self, CvUnit * pUnit, CvPlot *& result);static void AfterCvPlayer_GetGreatAdmiralSpawnPlot(CvPlayer* self, CvUnit * pUnit, CvPlot *& result);static CvPlot * ReplaceCvPlayer_GetGreatAdmiralSpawnPlot(CvPlot * (*original)(CvPlayer*, CvUnit *), CvPlayer* self, CvUnit * pUnit);CivRegisterBefore<CivHooks::CvPlayer_GetGreatAdmiralSpawnPlot>(host, &BeforeCvPlayer_GetGreatAdmiralSpawnPlot);CivRegisterAfter<CivHooks::CvPlayer_GetGreatAdmiralSpawnPlot>(host, &AfterCvPlayer_GetGreatAdmiralSpawnPlot);CivRegisterReplace<CivHooks::CvPlayer_GetGreatAdmiralSpawnPlot>(host, &ReplaceCvPlayer_GetGreatAdmiralSpawnPlot);

Code

4019CvPlot *CvPlayer::GetGreatAdmiralSpawnPlot (CvUnit *pUnit)4020{4021	CvPlot *pInitialPlot = pUnit->plot();40224023	// Is this a friendly coastal city, if so we'll go with that4024	CvCity *pInitialCity = pInitialPlot->getPlotCity();4025	if (pInitialCity && pInitialCity->isCoastal(GC.getLAKE_MAX_AREA_SIZE()))4026	{4027		// Equal okay checking this plot because this is where the unit is right now4028#if defined(MOD_GLOBAL_STACKING_RULES)4029		if (pInitialPlot->getNumFriendlyUnitsOfType(pUnit) <= pInitialPlot->getUnitLimit())4030#else4031		if (pInitialPlot->getNumFriendlyUnitsOfType(pUnit) <= GC.getPLOT_UNIT_LIMIT())4032#endif4033		{4034			return pInitialPlot;4035		}4036	}40374038	// Otherwise let's look at all our other cities4039	CvCity *pLoopCity;4040	int iLoop;4041	for(pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))4042	{4043		if (pLoopCity != pInitialCity)4044		{4045			if (pLoopCity->isCoastal(GC.getLAKE_MAX_AREA_SIZE()))4046			{4047#if defined(MOD_GLOBAL_STACKING_RULES)4048				if (pLoopCity->plot()->getNumFriendlyUnitsOfType(pUnit) < pLoopCity->plot()->getUnitLimit())4049#else4050				if (pLoopCity->plot()->getNumFriendlyUnitsOfType(pUnit) < GC.getPLOT_UNIT_LIMIT())4051#endif4052				{4053					return pLoopCity->plot();4054				}4055			}4056		}4057	}40584059	// Don't have a coastal city, look for water plot THAT ISN'T A LAKE closest to our capital that isn't owned by an enemy4060	int iCapitalX;4061	int iCapitalY;4062	CvCity *pCapital = getCapitalCity();4063	if (pCapital)4064	{4065		iCapitalX = pCapital->getX();4066		iCapitalY = pCapital->getY();40674068		CvPlot *pBestPlot = NULL;4069		int iBestDistance = MAX_INT;40704071		for (int iI = 0; iI < GC.getMap().numPlots(); iI++)4072		{4073			CvPlot *pPlot = GC.getMap().plotByIndexUnchecked(iI);4074			if (pPlot != NULL)4075			{4076				if (pPlot->isWater() && !pPlot->isLake())4077				{4078					if (pPlot->IsFriendlyTerritory(GetID()) || !pPlot->isOwned())4079					{4080#if defined(MOD_GLOBAL_STACKING_RULES)4081						if (pPlot->getNumFriendlyUnitsOfType(pUnit) < pPlot->getUnitLimit())4082#else4083						if (pPlot->getNumFriendlyUnitsOfType(pUnit) < GC.getPLOT_UNIT_LIMIT())4084#endif4085						{4086							int iDistance = plotDistance(iCapitalX, iCapitalY, pPlot->getX(), pPlot->getY());4087							if (iDistance < iBestDistance)4088							{4089								pBestPlot = pPlot;4090								iBestDistance = iDistance;4091							}4092						}4093					}4094				}4095			}4096		}40974098		if (pBestPlot)4099		{4100			return pBestPlot;4101		}41024103		// Now we'll even accept a lake4104		for (int iI = 0; iI < GC.getMap().numPlots(); iI++)4105		{4106			CvPlot *pPlot = GC.getMap().plotByIndexUnchecked(iI);4107			if (pPlot != NULL)4108			{4109				if (pPlot->isWater())4110				{4111					if (pPlot->IsFriendlyTerritory(GetID()) || !pPlot->isOwned())4112					{4113#if defined(MOD_GLOBAL_STACKING_RULES)4114						if (pPlot->getNumFriendlyUnitsOfType(pUnit) < pPlot->getUnitLimit())4115#else4116						if (pPlot->getNumFriendlyUnitsOfType(pUnit) < GC.getPLOT_UNIT_LIMIT())4117#endif4118						{4119							int iDistance = plotDistance(iCapitalX, iCapitalY, pPlot->getX(), pPlot->getY());4120							if (iDistance < iBestDistance)4121							{4122								pBestPlot = pPlot;4123								iBestDistance = iDistance;4124							}4125						}4126					}4127				}4128			}4129		}4130		if (pBestPlot)4131		{4132			return pBestPlot;4133		}4134	}41354136	CvAssertMsg (false, "Could not find valid plot for Great Admiral - placing on land");41374138	return pInitialPlot;4139}

Calls

Called by