How Do I Add Unhappiness?

Mr. Spiffy

Chieftain
Joined
Mar 5, 2016
Messages
20
Location
Tennessee
I would like to know how to add unhappiness to my custom civilization with LUA. This is for my unique ability that gives severe unhappiness when the empire is not in a golden age. Checking to see if the empire was in golden age is easy enough, but when it comes to subtracting happiness, it seems impossible.

When I use SetHappiness() with a negative value, that value is only added at the very end of the turn. This means that there really isn't any change. Right now I'm using GameEvents.PlayerDoTurn.Add() to call my function. Is there a better GameEvent?

Really, I'm looking for any way to add unhappiness. It doesn't have to even be lua. I'm open to hacky work-arounds of any kind.
 
Is it possible to add negative happiness via dummy building? Like having a dummy building only appear in the capital during golden ages then have it be removed after the golden age ends?

I have tried doing this. This would work if my goal was to add happiness during golden ages, but when I added a happiness of -100 to my building, it just said that the building had +-100 happiness and my happiness stayed the same.

I was thinking of perhaps adding severe unhappiness in my trait XML via India's population unhappiness modifier, but is there any way this trait can trigger only in a golden age?
 
Without a modded DLL, buildings can only give positive happiness (as you've discovered)

Units can give unhappiness (a la nukes), and IIRC you can use the pPlayer:ChangeUnhappinessFromUnits() method to add/remove arbitrary unhappiness without the need to create and station an unhappiness giving unit.

However, you need to make sure that you're never trying to add more unhappiness than the empire has happy (ie try don't try and take it negative) otherwise, again without an unmodded DLL, the Firaxis maths goes screwy.
 
Without a modded DLL, buildings can only give positive happiness (as you've discovered)

Units can give unhappiness (a la nukes), and IIRC you can use the pPlayer:ChangeUnhappinessFromUnits() method to add/remove arbitrary unhappiness without the need to create and station an unhappiness giving unit.

However, you need to make sure that you're never trying to add more unhappiness than the empire has happy (ie try don't try and take it negative) otherwise, again without an unmodded DLL, the Firaxis maths goes screwy.

This seems to work very well even without any units, which is what I want. Going into the negative didn't seem to break it as far as I've seen.

The last hurdle I have to get over is calculating how many turns the empire was not in a golden age and returning the proper amount of negative Unhappiness From Units once the another golden ages arises. If I don't do that, then when another "dark age" rolls around, it could still be in the positive. This should all be simple if I make use of GetUnhappinessFromUnits() though.

Thanks a ton, Whoward. And not just for answering this question either. You've been a huge help in answering other people's questions that I've been viewing to help with my troubleshooting problems. Keep being great.
 
Back
Top Bottom