Question: Possible to make Unhappiness good?


Master Kekkler
Apr 5, 2015
The Imperial Puppet of Canada

I'm currently working on a mod idea that I've been toying with for a while (Bet you've heard that before) and while I've dipped my toes into setting up a shell of the Civ and Leader, I wanted to know if the game play idea I had was programmable into the current structure of Civ V.

I'm trying to recreate The Final Empire from the novel Mistborn, in which the prophesied hero fails against a dark presence. For 1000 years since an immortal God has ruled over a land of Ash and Steel.

Rebellion, fighting, and genocide is a key part of The Final Empire, and so I was wondering if it would be possible to program in military and production buffs the more unhappiness you have; The game play idea is that the more unhappy your empire is, the better your military will perform, and as such rebels will begin to appear in the Empire to go along with events in the book.

I realize this might go against the point of unhappiness, but I thought it might provide with an interesting game play style; There's no way to really know if it's fun until I test, and as such I wanted to know if it could even be programmed properly first.

(I do have some experience in C++)



Nov 15, 2014
Naples (Italy)
Hi. If your idea is to increase the combat strenght of your military units as unhappiness increases, then it is possible through lua.
I'm relatively new to it and i don't know C++ at all, but the first solution coming in my mind is to give a free promotion to your units and then specify:

function StrenghtFromUnhappiness(iPlayer)
        local civID		= GameInfoTypes["CIVILIZATION_YOURCIV"]
	if (player:GetCivilizationType() == civID and player:IsAlive()) then [B]-- Unnecessary row if you're not creating a civ[/B]
	for pUnit in player:Units() do
		if pUnit:IsHasPromotion(GameInfoTypes["PROMOTION_STRONG_UNHAPPY") then
			local iTotalUnhappiness = player:GetUnhappiness()
			local iStrength = GameInfo.Units[pUnit:GetUnitType()].Combat
			if iTotalUnhappiness > 0 then
			pUnit:SetBaseCombatStrength( [B][COLOR="Blue"]f( iStrenght,  iTotalUnhappiness)[/COLOR][/B])


Where instead of f( iStrenght, iTotalUnhappiness) you put your strenght-unhappiness function: for example "iStrenght + 0.5 * (iTotalUnhappiness)" means that a number equal to the half the unhappiness is added to the base combat strenght of the military unit.

Regarding the production buff:

function BuffProdFromUnhappiness(iPlayer)
	local civID		= GameInfoTypes["CIVILIZATION_YOURCIV"]
if (player:GetCivilizationType() == civID and player:IsAlive()) then  [B]-- Unnecessary row if you're not creating a civ[/B]
	for pCity in player:Cities() do
			local iTotalUnhappiness = player:GetUnhappiness()


Where function stands for one of the following:

ChangeBuildingProduction(BuildingType index, int change) <--- it should add production integer (e.g. +3 production) or percentage points (e.g. +10%) when building a specific type of building (i think it's more a percentage modifier but i'm not sure)
ChangeUnitProduction (UnitType index, int change) <--- for units
ChangeWonderProductionModifier(int change) <--- this is quite clear, it gives a percentage buff
ChangeProduction(int change) <--- it increase the city production output

Obviously you specify the change as a function of iTotalUnhappiness and if the outcome is not an integer you can round it thanks to math.ceil() and math.floor() functions.

I think there are other methods involving also dummy policies (which have the entries MilitaryProductionModifier , WonderProductionModifier and BuildingProductionModifier ) and buildings, but i have no idea how to write in them a change being a function of the unhappiness through lua.

I hope this is of some help to you.


Jul 23, 2013
Illinois, USA
player:GetUnhappiness() will give you the sum total unhappiness being generated in the empire from all causes rather than the end result of player:GetHappiness() - player:GetUnhappiness()

Using Player:GetExcessHappiness() will give you the same value as is showing for the empire's current happiness "score". When this number on the top panel is green and showing as a positive value Player:GetExcessHappiness() will be that positive number, and when the "score" turns red and negative, Player:GetExcessHappiness() will be that negative number. When your empire happiness "score" is zero, Player:GetExcessHappiness() will be zero.
Top Bottom