We-the-People-civ4col-mod / Mod

This is the repository where the mod resides.
89 stars 37 forks source link

[v4.1 Bug] Inconsistent values for law and happiness, depending on if population size was reduced or increased #1019

Open estebanthebad opened 4 months ago

estebanthebad commented 4 months ago

Version

The version played is 4.1 .

Gamesave

civ4col.mod.We The People.v4_1.Bug.inconsistent law and happiness.ColonizationSave.zip The mod name is "We The People".

Bug summary

Values for law and happiness in the same settlement are different at the same population size, depending on whether the population size was reduced or increased.

Steps to reproduce the bug

  1. Load the attached gamesave
  2. Open settlement "Tosswald" in the west.

Observed result With 4 colonists, law is at -1 and happiness is at -2.

  1. Remove a colonist so that the population size is reduced from 4 to 3.

Observed result With 3 colonists, law is at -1 and happiness is at -1.

  1. Remove a colonist so that the population size is reduced from 3 to 2.

Observed result With 2 colonists, law is at -1 and happiness is at -1.

  1. Remove a colonist so that the population size is reduced from 2 to 1.
  2. Add a colonist so that the population size is increased from 1 to 2.

Observed result With 2 colonists, law and happiness both are at 0. Expected result With 2 colonists, law and happiness both are at -1, like before.

  1. Add a colonist so that the population size is increased from 2 to 3.

Observed result With 3 colonists, law and happiness both are at 0. Expected result With 3 colonists, law and happiness both are at -1, like before.

  1. Add a colonist so that the population size is increased from 3 to 4.

Observed result With 4 colonists, law and happiness both are at -1. Expected result With 4 colonists, law is at -1 and happiness is at -2, like before.

Razonatair commented 3 months ago

This is probably a rounding issue or maybe even an issue related to float precision. This bothers me too, so I plan to look at it at some point soon.

Razonatair commented 3 months ago

So this is actually a somewhat complicated issue due to preexisting circular logic in the happiness code. Crime is generated by the presence of net unhappiness in a colony, and unhappiness is generated by the presence of net crime. Thus, you can end up with the situation you have wherein the colony is perpetually at -1 happy and -1 crime until you fall below a certain population threshold.

There's no simple fix for this I can think of that still preserves the circular logic (since it does make sense that crime generates unhappiness and unhappiness generates crime), so I'm considering an alternative happiness behavior code, but that'll take time to design, have it be agreed upon by the others, and then developed. But yeah, I feel your pain, it's annoying. The happiness code has a number of other issues I want to adjust too, besides this, that push me towards a deeper redesign.