freeserf.net
freeserf.net copied to clipboard
Serf count does not match
With only one warehouse, no army buildings. 60 castle defenders.
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();