Building require population level?

thecrazyscot

Spiffy
Joined
Dec 27, 2012
Messages
2,460
Is there any way to make a building require a certain population level before it can be built? (through Lua, I'm assuming)...

Second, related question. Is there a way to prevent city growth over a certain population level unless a building is present (like Aquaducts/Sewer Systems from Civ II)?
 
This lua function can be used to set custom building requirements:

http://modiki.civfanatics.com/index.php/GameEvents.CityCanConstruct_(Civ5_API)

A pretty good example is available lower on the page from Civ5. I'm not sure if it still works for BE, but it's your best shot.

As for preventing city growth, it requires a little bit of Lua trickery but it can be done. My mod "Morgan Industries" has a population limit set until the player researches fabrication. You could easily substitute a different condition in.
 
Ok, I've finally gotten around to working on this, and I'm having no luck. :(

I've attempted to essentially modify the code from your Morgan mod, but I think I have a fundamental lack of Lua understanding.

I started with this as a test:
Spoiler :
Code:
function LGF_InhibitGrowth(iPlayer)
	local pPlayer = Players[iPlayer]
	local iRelic = GameInfo.Buildings["BUILDING_RELIC"].ID
	local POPCAP = 6
	for pCity in pPlayer:Cities () do
		if pCity:IsHasBuilding(iRelic) then
		else 
			for pCity in pPlayer:Cities() do
				if pCity:GetPopulation() > POPCAP then
					pCity:SetPopulation(POPCAP, true)
					local foodSet = pCity:GrowthThreshold() - 1
					pCity:SetFood(foodSet)
				end
			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(LGF_InhibitGrowth) -- I added this after the above obviously didn't work
Is that sufficient? Or is a modification of this code necessary as well?
Spoiler :
Code:
function LGF_OnCityFounded(player, x, y)
	local pPlayer = Players[player]
	if pPlayer == nil then
		return
	end

	if pPlayer:GetCivilizationType() == civilisationID then
		for pCity in pPlayer:Cities() do
			if pCity:GetX()==x and pCity:GetY()==y then
				--Do stuff here
				break
			end
		end
	end
end

function LGF_OnSetPopultion(x, y, oldPop, newPop)
	local pPlot = Map.GetPlot(x,y)
	if pPlot == nil then
		return
	end

	local pCity = pPlot:GetPlotCity()
	if pCity == nil then
		return
	end

	local iPlayer = pCity:GetOwner()
	local pPlayer = Players[iPlayer]
	if pPlayer == nil then
		return
	end

	if pPlayer:GetCivilizationType() == civilisationID then
		--Do stuff here
		LGF_InhibitGrowth(iPlayer)
	end
end
I don't want to limit it to a certain player, but rather have a global requirement to build x building before a city can grow beyond y population.

If it matters, when loading the mod I set VFS = true and loaded it as an InGameUIAddin.
 
So my code artificially limits it to a particular sponsor so it functions like a sponsor trait. You'll need to change the second part of the code you posted, namely the "if pPlayer:GetCivilizationType() == civilisationID then" part. That's the part that checks whether the player who's population changed belongs to the custom civ.
 
Top Bottom