Bazaar developer reference

CvLuaPlayer::lGetUnimprovedAvailableLuxuryResource(lua_State *)

Defined in
Lua/CvLuaPlayer.cpp, line 9473
Class
CvLuaPlayer
Hook name
CivHooks::CvLuaPlayer_lGetUnimprovedAvailableLuxuryResource

Hooks

static bool BeforeCvLuaPlayer_lGetUnimprovedAvailableLuxuryResource(lua_State* L, int& result);static void AfterCvLuaPlayer_lGetUnimprovedAvailableLuxuryResource(lua_State* L, int& result);static int ReplaceCvLuaPlayer_lGetUnimprovedAvailableLuxuryResource(int (*original)(lua_State*), lua_State* L);CivRegisterBefore<CivHooks::CvLuaPlayer_lGetUnimprovedAvailableLuxuryResource>(host, &BeforeCvLuaPlayer_lGetUnimprovedAvailableLuxuryResource);CivRegisterAfter<CivHooks::CvLuaPlayer_lGetUnimprovedAvailableLuxuryResource>(host, &AfterCvLuaPlayer_lGetUnimprovedAvailableLuxuryResource);CivRegisterReplace<CivHooks::CvLuaPlayer_lGetUnimprovedAvailableLuxuryResource>(host, &ReplaceCvLuaPlayer_lGetUnimprovedAvailableLuxuryResource);

Code

9473int CvLuaPlayer::lGetUnimprovedAvailableLuxuryResource(lua_State* L)9474{9475	CvPlayerAI* pkPlayer = GetInstance(L);94769477	CvPlot* pResultPlot = NULL;94789479	const CvPlotsVector& aiPlots = pkPlayer->GetPlots();9480	// go through all the plots the player has under their control9481	for(uint uiPlotIndex = 0; uiPlotIndex < aiPlots.size(); uiPlotIndex++)9482	{9483		// when we encounter the first plot that is invalid, the rest of the list will be invalid9484		if(aiPlots[uiPlotIndex] == -1)9485		{9486			break;9487		}94889489		CvPlot* pPlot = GC.getMap().plotByIndex(aiPlots[uiPlotIndex]);94909491		// check to see if a resource is here. If not, bail out!9492		ResourceTypes eResource = pPlot->getResourceType(pkPlayer->getTeam());9493		if(eResource == NO_RESOURCE)9494		{9495			continue;9496		}94979498		CvResourceInfo* pkResource = GC.getResourceInfo(eResource);9499		if(pkResource == NULL)9500		{9501			continue;9502		}95039504		// Is this a Luxury Resource?9505		if(pkResource->getResourceUsage() != RESOURCEUSAGE_LUXURY)9506		{9507			continue;9508		}95099510		if(pkPlayer->getNumResourceTotal(eResource) > 0)9511		{9512			continue;9513		}95149515		// if the resource is already improved9516		ImprovementTypes eExistingPlotImprovement = pPlot->getImprovementType();9517		if(eExistingPlotImprovement != NO_IMPROVEMENT)9518		{9519			CvImprovementEntry* pkImprovement = GC.getImprovementInfo(eExistingPlotImprovement);9520			if(pkImprovement != NULL)9521			{9522				if(pkImprovement->IsImprovementResourceTrade(eResource))9523				{9524					continue;9525				}9526			}9527		}95289529		// see if we can improve the resource9530		for(int iBuildIndex = 0; iBuildIndex < GC.getNumBuildInfos(); iBuildIndex++)9531		{9532			BuildTypes eBuild = (BuildTypes)iBuildIndex;9533			CvBuildInfo* buildInfo = GC.getBuildInfo(eBuild);9534			if(buildInfo == NULL)9535				continue;95369537			ImprovementTypes eImprovement = (ImprovementTypes)buildInfo->getImprovement();9538			if(eImprovement == NO_IMPROVEMENT)9539			{9540				continue;9541			}95429543			CvImprovementEntry* pkImprovementInfo = GC.getImprovementInfo(eImprovement);9544			if(pkImprovementInfo == NULL)9545			{9546				continue;9547			}95489549			if(!pkImprovementInfo->IsImprovementResourceTrade(eResource))9550			{9551				continue;9552			}95539554			if(!pkPlayer->canBuild(pPlot, eBuild, false, true /*bTestVisible*/, false /*bTestGold*/))9555			{9556				continue;9557			}95589559			int iBuildTurnsLeft = pPlot->getBuildTurnsLeft(eBuild, pkPlayer->GetID(), 0, 0);9560			if(iBuildTurnsLeft > 0 && iBuildTurnsLeft < 4000)9561			{9562				continue;9563			}95649565			pResultPlot = pPlot;9566			break;9567		}95689569		if(pResultPlot != NULL)9570		{9571			break;9572		}9573	}95749575	if(pResultPlot)9576	{9577		CvLuaPlot::Push(L, pResultPlot);9578	}9579	else9580	{9581		lua_pushnil(L);9582	}95839584	return 1;9585}

Calls

Called by