freeserf.net icon indicating copy to clipboard operation
freeserf.net copied to clipboard

Serf count does not match

Open athach opened this issue 2 years ago • 1 comments

With only one warehouse, no army buildings. 60 castle defenders. Untitled

athach avatar Feb 16 '22 12:02 athach

The problem is that the serf count is saved/loaded as a player property, each serf if also counted individually, each serf except generic serfs are therefore counted twice. For each save/load the numbers get more corrupt. Ugly fix:

From: for (int i = 0; i < 26; ++i) { state.ResourceCounts[i] = reader.Value("resource_count")[i].ReadUInt(); settings.FlagPriorities[i] = (byte)reader.Value("flag_prio")[i].ReadInt(); state.SerfCounts[i] = reader.Value("serf_count")[i].ReadUInt(); settings.InventoryPriorities[i] = (byte)reader.Value("inventory_prio")[i].ReadInt(); } state.SerfCounts[26] = reader.Value("serf_count")[26].ReadUInt();

To: for (int i = 0; i < Global.NUM_RESOURCE_TYPES; ++i) { state.ResourceCounts[i] = reader.Value("resource_count")[i].ReadUInt(); settings.FlagPriorities[i] = (byte)reader.Value("flag_prio")[i].ReadInt(); settings.InventoryPriorities[i] = (byte)reader.Value("inventory_prio")[i].ReadInt(); }

       // Only read generic serf count, other serfs are count when loaded
       //  TODO improve code quality, handle generic serfs the same way as all other serfs?
        state.SerfCounts[21] = reader.Value("serf_count")[21].ReadUInt();

athach avatar Dec 19 '22 12:12 athach