• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days. For more updates please see here.

Is it possible to have an improvement yield happiness?

DistantRainbow

Chieftain
Joined
Apr 16, 2015
Messages
81
More specifically, let's say I wanted to make a new building which, among other effects, grants +1 Happiness to all Trading Posts worked by its city.

Could it be done simply with XML? Or do I have to dabble in LUA for it?

Right now, my guess is it won't be simple since Happiness isn't a proper 'yield', but I'd like confirmation.
 
Happiness isn't a yield. So you'll need Lua, and probably more than a "dabble" ;)
 
Some natural wonders provide happiness if they are in your borders. Perhaps you could look at the code behinid that
 
Some natural wonders provide happiness if they are in your borders. Perhaps you could look at the code behinid that

That's <InBorderHappiness> from Features (as Natural Wonders are Features), so not compatible with Improvements. Mind you, there is a way to use that to your advantage, but as whoward mentioned, it would require some fancy XML and Lua work.
 
Depending on how sophisticated you wanted to make it, the Lua code wouldn't be that hard, I think. The Ecosanctuary in my Future Worlds mod does something very similar, adding Happiness to the city for each Nature Preserve the city is working. The code for it looks like this:

Code:
local iImprovementPreserve = GameInfoTypes.IMPROVEMENT_FW_PRESERVE
local iBuildingSanctuary = GameInfoTypes.BUILDING_FW_SANCTUARY

function SanctuaryBonus(iPlayer)
	local pPlayer = Players[iPlayer];
	for pCity in pPlayer:Cities() do
		if pCity:IsHasBuilding(iBuildingSanctuary) then
			local iNumPreserves = 0
			local i;
			for i = 0, pCity:GetNumCityPlots() - 1, 1 do
				local pPlot = pCity:GetCityIndexPlot( i );
				if (pPlot ~= nil) then
					if (pPlot:GetOwner() == pCity:GetOwner()) and (pCity:IsWorkingPlot(pPlot)) then
						local iImprovement = pPlot:GetImprovementType()
						if (iImprovement == iImprovementPreserve) then
							iNumPreserves = iNumPreserves + 1
						end
					end
				end
			end
			pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FW_SANCTUARY_DUMMY"], iNumPreserves)
		else
			pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_FW_SANCTUARY_DUMMY"], 0)
		end
	end
end
GameEvents.PlayerDoTurn.Add(SanctuaryBonus)

At the start of each player's turn, it goes through their cities, and if a city has an Ecosanctuary, it goes through the city's tiles, finds out how many of the worked tiles have Nature Preserves, and then spawns that many copies of a happiness-generating dummy building in the city.

The Happiness yield won't show up on the map, and you'd pretty much have to say "this building adds +1 Happiness for each Trading Post worked by the city" in the tooltip, but it's one way to make the effect work.
 
Back
Top Bottom