Bazaar developer reference

CvUnit::GetBestBuildRoute(CvPlot *, BuildTypes *) const

Defined in
CvUnit.cpp, line 22634
Class
CvUnit
Hook name
CivHooks::CvUnit_GetBestBuildRoute

Hooks

static bool BeforeCvUnit_GetBestBuildRoute(const CvUnit* self, CvPlot* pPlot, BuildTypes* peBestBuild, RouteTypes& result);static void AfterCvUnit_GetBestBuildRoute(const CvUnit* self, CvPlot* pPlot, BuildTypes* peBestBuild, RouteTypes& result);static RouteTypes ReplaceCvUnit_GetBestBuildRoute(RouteTypes (*original)(const CvUnit*, CvPlot*, BuildTypes*), const CvUnit* self, CvPlot* pPlot, BuildTypes* peBestBuild);CivRegisterBefore<CivHooks::CvUnit_GetBestBuildRoute>(host, &BeforeCvUnit_GetBestBuildRoute);CivRegisterAfter<CivHooks::CvUnit_GetBestBuildRoute>(host, &AfterCvUnit_GetBestBuildRoute);CivRegisterReplace<CivHooks::CvUnit_GetBestBuildRoute>(host, &ReplaceCvUnit_GetBestBuildRoute);

Code

22634RouteTypes CvUnit::GetBestBuildRoute(CvPlot* pPlot, BuildTypes* peBestBuild) const22635{22636	VALIDATE_OBJECT2263722638	if(peBestBuild != NULL)22639	{22640		*peBestBuild = NO_BUILD;22641	}2264222643	int iBestValue = 0;22644	RouteTypes eBestRoute = NO_ROUTE;22645	22646#if defined(MOD_GLOBAL_QUICK_ROUTES)22647	CvPlayer& kPlayer = GET_PLAYER(getOwner());22648	const MissionQueueNode* pkMissionNode = HeadMissionQueueNode();22649	bool bOnlyRoad = MOD_GLOBAL_QUICK_ROUTES && kPlayer.isHuman() && (pkMissionNode != NULL && pkMissionNode->eMissionType == CvTypes::getMISSION_ROUTE_TO());22650	22651	if (bOnlyRoad) {22652		// If there is no road to the mission end plot, bOnlyRoad is true22653		CvUnit* me = kPlayer.getUnit(m_iID); // God I truely hate "const" - we're in a const method, but LastMissionPlot() isn't so we can't call it!!!22654		bOnlyRoad = !kPlayer.IsPlotConnectedToPlot(pPlot, me->LastMissionPlot(), ROUTE_ROAD);;22655	}22656#endif2265722658	for(int iI = 0; iI < GC.getNumBuildInfos(); iI++)22659	{22660		const BuildTypes eBuild = static_cast<BuildTypes>(iI);22661		CvBuildInfo* pkBuildInfo = GC.getBuildInfo(eBuild);22662		if(pkBuildInfo)22663		{22664			const RouteTypes eRoute = (RouteTypes)pkBuildInfo->getRoute();22665			if(eRoute != NO_ROUTE)22666			{22667				CvRouteInfo* pkRouteInfo = GC.getRouteInfo(eRoute);22668				if(pkRouteInfo)22669				{22670					if(canBuild(pPlot, eBuild))22671					{22672						int iValue = pkRouteInfo->getValue();22673						22674#if defined(MOD_GLOBAL_QUICK_ROUTES)22675						if (bOnlyRoad && eRoute != ROUTE_ROAD) {22676							iValue = 0;22677						}22678#endif2267922680						if(iValue > iBestValue)22681						{22682							iBestValue = iValue;22683							eBestRoute = eRoute;22684							if(peBestBuild != NULL)22685							{22686								*peBestBuild = eBuild;22687							}22688						}22689					}22690				}22691			}22692		}22693	}2269422695	return eBestRoute;22696}

Calls

Called by