The formula has a few parts. It is in C++, so it isn't exactly 'plain english,' so I'll do my best to explain it.
- The global output of every city is considered for each yield (Gold, Defense, Science, Culture) and added together into a big pool. Then, the global population of all cities divides the value, giving us the global average per citizen (keep in mind this is only for major civ cities - minors are never considered in this formula).
- The value is passed into a median function to find the middle value, and that value is then made gradual (so the global average can only change per turn by a certain % up or down.
- Each city grabs this median value every turn, and compares it to their individual output. This value is modified upwards for each player based on the number of techs they know. Right now, the formula for this is: ((# of techs known * 2.6) - 15) / # of possible techs. So, as the game goes along, the % of techs you know increases the global average by a gradually-increasing %.
- The global average calculated in step 3 is decreased by buildings, wonders, policies, and traits. Buildings and wonders decrease the global average based on the population of the city. So a larger city with a poverty-reducing building will get more benefit from it than a smaller one.
- Once this is calculated, the two values - global median and city average, are compared. If the city average is below the global average at all, 1 unhappiness is made the minimum. For every .4 points of difference between the averages (after the first .4, which is already covered by the minimum of 1 unhappiness), the unhappiness factor increases by 1.
G
Hey, I'd like to chime in a bit here as well. I'm new to the mod, and I admit I haven't read all 5 pages so if I accidentally rehash something that's be said already, I'm sorry!
Alright, so I've been thinking - is it all possible to change the happiness formula in such a way that mostly the national yield rates are taken into account? And that only with advancing eras (and/or tourism?) part of the global average is added to the national rate? Because as it stands, I haven't found a way to found more than 2 expansions (so 3 city total) without descending into madness (-20 happiness or worse) VERY quickly.
Besides, why would my citizens pine away for a mythical far away land that they don't even know exists!
Jokes aside, right now I think you're so at the mercy of your land with close to no way to combat unhappiness if you happen to start with land, which makes you fall behind the global average and little to no chance to come back. This way I could at least try to ICS to my nearest neighbor and rush him with Might units in a desperate bid for more/better land, and at the same time lower the global average!