Bazaar developer reference

CvCity::IsBuildingLocalResourceValid(BuildingTypes, bool, CvString *) const

Defined in
CvCity.cpp, line 3448
Class
CvCity
Hook name
CivHooks::CvCity_IsBuildingLocalResourceValid

Hooks

static bool BeforeCvCity_IsBuildingLocalResourceValid(const CvCity* self, BuildingTypes eBuilding, bool bTestVisible, CvString* toolTipSink, bool& result);static void AfterCvCity_IsBuildingLocalResourceValid(const CvCity* self, BuildingTypes eBuilding, bool bTestVisible, CvString* toolTipSink, bool& result);static bool ReplaceCvCity_IsBuildingLocalResourceValid(bool (*original)(const CvCity*, BuildingTypes, bool, CvString*), const CvCity* self, BuildingTypes eBuilding, bool bTestVisible, CvString* toolTipSink);CivRegisterBefore<CivHooks::CvCity_IsBuildingLocalResourceValid>(host, &BeforeCvCity_IsBuildingLocalResourceValid);CivRegisterAfter<CivHooks::CvCity_IsBuildingLocalResourceValid>(host, &AfterCvCity_IsBuildingLocalResourceValid);CivRegisterReplace<CivHooks::CvCity_IsBuildingLocalResourceValid>(host, &ReplaceCvCity_IsBuildingLocalResourceValid);

Code

3447/// Does eBuilding pass the local resource requirement test?3448bool CvCity::IsBuildingLocalResourceValid(BuildingTypes eBuilding, bool bTestVisible, CvString* toolTipSink) const3449{3450	VALIDATE_OBJECT34513452	int iResourceLoop;3453	ResourceTypes eResource;34543455	CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBuilding);3456	if(pkBuildingInfo == NULL)3457		return false;34583459	// ANDs: City must have ALL of these nearby3460	for(iResourceLoop = 0; iResourceLoop < GC.getNUM_BUILDING_RESOURCE_PREREQS(); iResourceLoop++)3461	{3462		eResource = (ResourceTypes) pkBuildingInfo->GetLocalResourceAnd(iResourceLoop);34633464		// Doesn't require a resource in this AND slot3465		if(eResource == NO_RESOURCE)3466			continue;34673468		CvResourceInfo* pkResource = GC.getResourceInfo(eResource);3469		if(pkResource == NULL)3470			continue;34713472		// City doesn't have resource locally - return false immediately3473		if(!IsHasResourceLocal(eResource, bTestVisible))3474		{3475			GC.getGame().BuildCannotPerformActionHelpText(toolTipSink, "TXT_KEY_NO_ACTION_BUILDING_LOCAL_RESOURCE", pkResource->GetTextKey(), pkResource->GetIconString());3476			return false;3477		}3478	}34793480	int iOrResources = 0;34813482	// ORs: City must have ONE of these nearby3483	for(iResourceLoop = 0; iResourceLoop < GC.getNUM_BUILDING_RESOURCE_PREREQS(); iResourceLoop++)3484	{3485		eResource = (ResourceTypes) pkBuildingInfo->GetLocalResourceOr(iResourceLoop);34863487		// Doesn't require a resource in this AND slot3488		if(eResource == NO_RESOURCE)3489			continue;34903491		CvResourceInfo* pkResource = GC.getResourceInfo(eResource);3492		if(pkResource == NULL)3493			continue;34943495		// City has resource locally - return true immediately3496		if(IsHasResourceLocal(eResource, bTestVisible))3497			return true;34983499		// If we get here it means we passed the AND tests but not one of the OR tests3500		GC.getGame().BuildCannotPerformActionHelpText(toolTipSink, "TXT_KEY_NO_ACTION_BUILDING_LOCAL_RESOURCE", pkResource->GetTextKey(), pkResource->GetIconString());35013502		// Increment counter for OR we don't have3503		iOrResources++;3504	}35053506	// No OR resource requirements (and passed the AND test above)3507	if(iOrResources == 0)3508		return true;35093510	return false;3511}

Calls

Called by