Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix rare bug where Citizen Assignment would cycle due to Civ Happiness going above and below the threshold.
Reported originally by Eggy here
https://discord.com/channels/586194543280390151/588357826758574106/1329106526761128058
Sample save file
Babylon - 0 turns.txt
In master, if you press Food Focus, the assignments will cycle. This is because the Civ Happiness stat isn't being updated. So when it tries to assign Pop, it may think the Civ is Happy and not assign to Kailesh. But this will result in Civ at -1 Happy (Unhappy!). Assign again, and the algo thinks we're unhappy, increases weight for Happiness, and assigns to Kailesh. Now the civ is +1 Happy!! Repeat.
![image](https://private-user-images.githubusercontent.com/44038014/408785869-3ca7a28a-2dea-4116-81e0-caa694f4cdb9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMDE3MjksIm5iZiI6MTczOTAwMTQyOSwicGF0aCI6Ii80NDAzODAxNC80MDg3ODU4NjktM2NhN2EyOGEtMmRlYS00MTE2LTgxZTAtY2FhNjk0ZjRjZGI5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDA3NTcwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU5Yzc5N2Q0YjlkZWJjZGRmMWY3YzE3NDhhOGVkZDFkYmJjZTQ5YjFiZmQ4NDhmOWFlMDEzMmYwMDliNzlhZTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.-EEfS3RjS4RUJCLL238Cd2h5GQ2K4Yq8FYq5ekgza8c)
Simple fix is to calculate the civ-wide Happiness stat at the start while all Citizens aren't assigned. An advanced fix would involve recalculating Happiness after every assignment, but that's probably not necessary.