Save standings by faction, not by list position

RunSave.Capture wrote Factions in HomeZones key order and Relationships in
galaxy.Factions order; Galaxy's save constructor paired them by index, so a
galaxy whose two orders differed resumed with standings on the wrong factions.
SavedGame.Standings (Key 16) now carries each standing with its faction ref.
A save without it still reads Relationships by index, the only record it holds.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Nibu 2026-11-07 11:55:50 +00:00
commit 65a6297aee
3 changed files with 76 additions and 9 deletions

View file

@ -58,10 +58,14 @@ public class Galaxy
Seed = savedGame.Seed;
Factions = savedGame.Factions.Select(faction => cultCache.Get(faction)).ToArray();
for (var i = 0; i < Factions.Length; i++)
{
FactionRelationships[Factions[i]] = savedGame.Relationships[i];
}
if (savedGame.Standings != null)
foreach (var standing in savedGame.Standings)
FactionRelationships[cultCache.Get(standing.Faction)] = standing.Relationship;
else
// A save before Standings wrote Relationships in an order it did not record; it is right only for a
// galaxy that never reordered, and is all that save holds.
for (var i = 0; i < Factions.Length; i++)
FactionRelationships[Factions[i]] = savedGame.Relationships[i];
var savedZones = savedGame.Zones.Select(zone => cultCache.Get(zone)).ToArray();
Zones = savedZones.Select(zone =>

View file

@ -45,6 +45,8 @@ public class SavedGame
[Key(11)]
public bool IsTutorial;
// Read only by a save written before Standings: its entries follow galaxy.Factions order, not Factions order, so
// Galaxy trusts it only when the two orders cannot differ (see Galaxy's save constructor).
[Key(12)]
public FactionRelationship[] Relationships;
@ -61,6 +63,21 @@ public class SavedGame
// gets Regions, Partition and Deal from its saved graph, boss zones, Exit and seed.
[Key(15)]
public List<SavedProvince> Provinces;
// Each faction's standing, keyed by the faction itself so no list order can misplace it. Written by RunSave.Capture;
// null in a save written before it, which then reads Relationships.
[Key(16)]
public List<SavedStanding> Standings;
}
[MessagePackObject]
public class SavedStanding
{
[Key(0)]
public CultRecordRef<Faction> Faction;
[Key(1)]
public FactionRelationship Relationship;
}
[MessagePackObject]
@ -87,7 +104,8 @@ public static class RunSave
DiscoveredZones = galaxy.DiscoveredZones.Select(dz => Array.IndexOf(galaxy.Zones, dz)).ToArray(),
Background = galaxy.Background,
Factions = factions.Select(f => cache.RefOf(f)).ToArray(),
Relationships = galaxy.Factions.Select(f => galaxy.FactionRelationships[f]).ToArray(),
Standings = galaxy.Factions.Select(f => new SavedStanding
{Faction = cache.RefOf(f), Relationship = galaxy.FactionRelationships[f]}).ToList(),
HomeZones = galaxy.HomeZones.ToDictionary(
x => Array.IndexOf(factions, x.Key),
x => Array.IndexOf(galaxy.Zones, x.Value)),