Calculate happiness from Courthouses

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,695
Location
Near Portsmouth, UK
It's a long shot, but does anyone happen to know how to calculate the increase in happiness from

a) buying/building a Courthouse in an annexed city
b) annexing a puppet and immediately buying a Courthouse in it

 
It's all in GlobalDefines.

Without a courthouse, a city's unhappiness is
UNHAPPINESS_PER_CAPTURED_CITY (5) + UNHAPPINESS_PER_OCCUPIED_POPULATION (1.34) * population

With a courthouse, it drops to the normal
UNHAPPINESS_PER_CITY (3) + UNHAPPINESS_PER_POPULATION (1) * population
So unless you've altered these numbers in a mod, a courthouse reduces unhappiness by 2.0 + 0.34*pop on normal difficulties.

Note that only the 1.34 value is stored as a float; everything else is an integer and won't accept a float value. And notice that I said "on normal difficulties"; if you play on a low difficulty (like chieftain, which the AI plays on by default) all unhappiness is multiplied by your handicap's <NumCitiesUnhappinessMod> and <PopulationUnhappinessMod> variables.
Those of us who've changed the unhappiness-per-population have just altered those modifier values; in my own mod, the population unhappiness is 1.2 for normal citizens and 1.6 for occupied cities. But since the "1" value for per-population unhappiness can't take a float value, you have to do this by altering the handicap modifiers to average a 120 instead of a 100.
So if you're using this information for some sort of UI mod, you NEED to be adjusting for these handicap modifiers, because while they'll be 1.0 for the vanilla game at Prince or higher, they could easily be higher or lower for other people.
 
Also unhappiness per city is modified by NumCitiesUnhappinessPercent in Worlds. I don't know if it also affects unhappiness from annexed cities, but it's easy to check.

Unhappiness from various sources can be also modified by Policies and Traits, which complicates things a little...

b) annexing a puppet and immediately buying a Courthouse in it

AFAIK the happiness should remain unchanged if you do so.
 
you NEED to be adjusting for these handicap modifiers

Hence why I asked if anyone knew *how* to calculate it, and not for the issues/problems in calculating it (which I am fully aware of)
 
AFAIK the happiness should remain unchanged if you do so.

It doesn't, as the pop of the city increses it drifts, so around 6 it's 0, around 13 you lose one unhappy citizen, around 20 you lose 2 unhappy people

It could be rounding errors in the game UI, but it does also seem linear
 
I have an idea, but I don't know how feasible it is: perhaps your code can add a Courthouse to the city for a moment, check the happiness, remove it, check the happiness again, and calculate the difference.

It doesn't, as the pop of the city increses it drifts, so around 6 it's 0, around 13 you lose one unhappy citizen, around 20 you lose 2 unhappy people

It could be rounding errors in the game UI, but it does also seem linear

That's interesting, can you check which source of happiness or unhappiness changes in the happiness breakdown tooltip?
 
I have an idea, but I don't know how feasible it is: perhaps your code can add a Courthouse to the city for a moment, check the happiness, remove it, check the happiness again, and calculate the difference.

I tried that and that's probably the way I'll have to go, once I've figured out how to stop the infinite recursion I've created from doing so!
 
That's interesting, can you check which source of happiness or unhappiness changes in the happiness breakdown tooltip?

I have 0.3 of a difference from specialists, 1 from "Global Social Poliicies" (which I think is Aristocracy = +1 per 10 pop) and a tiny fraction (about 0.2) from a difference between Population and Population in puppets (probably rounding errors)

It's a complete ******d to compute
 
I have an idea, but I don't know how feasible it is: perhaps your code can add a Courthouse to the city for a moment, check the happiness, remove it, check the happiness again, and calculate the difference.

I think this is the only feasible way - throw Beliefs into the mix, some of which seem to work in puppets (river happiness) and some of which don't (temple happiness) and it's a complete nightmare!
 
Little bit of handshaking to avoid re-entering code and the Courthouse problem is solved



I'll have to see if I can pull the same trick for puppets with pCity:SetPuppet()
 
I'll have to see if I can pull the same trick for puppets with pCity:SetPuppet()

Now this is just plain weird!

If I get the "happiness level" before and after "annexing the city and immediately building a courthouse" I get happiness changes from -1 to +2 - there is definately something odd in the in-game calculations! What is even more odd is that if you do annex the city and buy a courthouse the actual change is sometimes different to that from the code. Aaarrrrrggggghhhhhhhh! :crazyeye:
 
Top Bottom