I've decided to move on the 'repeatable project' concept - a 'Public Works' project, if you will, that will reduce the needs modifier of all needs in the city by -5% (WIP). The catch is that the cost scales with era AND the number of times you construct it in a city. So it becomes more and more production-expensive to do, but it will serve as a means by which players can dig out of a hole. If anyone wants to propose a better name and/or an icon, I'm all ears.
Fine. This is a tool. A permanent one, but hopefully it can't be abused. It fits with the proposal of the processes, but instead a panic button, this opens up new strategies. Hope that it does not lead to excessively wide civs.
I'm also moving back to the global median, the difference between the global, player, and 50/50 is negligible, and I can save the memory/process time.
So far, so good.
Also I'm going to do as
@tu_79 requested and make the function proportional, so it will be current/need instead of current-need for calculating unhappiness.
Really glad you saw it. Only a little more thought has to be put on how the modifiers are going to affect the results.
For instance, it is mandatory to avoid divisions by zero. World median efficiency can value zero, especially in the early game. A simple check would say that in this case, there is no unhappiness from this need. Or it could be added a very small quantity to the world median, so it is always positive and non zero. The conditional would lead to more predictable and understandable values, but I'm not sure which one is better performance-wise.
I can think of two ways of doing a proportional comparison:
The relative differences, which I discussed in a previous post, and
the ratio. Boths have merits.
I'll show how it could be with ratios.
If we do a simple division (the ratio): CityEfficiency / MedianEfficiency, we will get values between 0 and probably 10+, but we are only interested in values where CityEfficiency < MedianEfficiency, so we will be working with values between 0 and 1. As is, a capital will always have a value over or equal to 1.
So, how are going to put some unhappiness into capitals? Modifiers.
Right now modifiers are like "City size: +23%, empire size: +51%, capital:+15%". In our current games, pushing wide, we were obtaining modifiers around +100% in the worst cases, around +30% in the best ones.
What would happen if we include Modifiers this way?
CityEfficiency / (MedianEfficiency * Modifiers)
In the case of CityEfficiency = MedianEfficiency (the city happens to be the median one), a +100% modifier will give:
CityEfficiency / (MedianEfficiency + 100%) = 0.5 * CityEfficiency / MedianEfficiency
this is, this function will typically return values 0 and 1 for CityEfficiency values up to the double of MedianEfficiency.
If it does not work well, modifier values can be adapted.
How many citizens should be unhappy? Since the lower the ratio, the bigger the unhappiness, it could be proportional to "1 - EfficiencyRatio", where negative values do nothing. So,
UnhappyPeople = q * CitySize * (1 - EfficiencyRatio), where q is a constant (suggested 0.5).
Also, would you consider to move growth penalties to local unhappiness values and remove unhappiness from starving? Maybe after the changes above?