Jump to content

Petra: rejoining a game on Wall Demo goes out of sync (extra noBase after load)


wasname321
 Share

Recommended Posts

On random/wall_demo with Petra AIs, a client that rejoins goes out of sync, because a loaded AI has a base manager that the running AI never created.

On Wall Demo neither player starts with a civic centre or a unit in an accessible land region, so Petra's region analysis fails at game start (the "does not know how to interpret this map" case from #3110). gameAnalysis then returns before basesManager.init, so noBase stays undefined. BasesManager.Serialize already handles that (noBase?.Serialize()). But on load, HQ.Deserialize calls this.basesManager.init(gameState, true) unconditionally, which creates noBase, and BasesManager.Deserialize keeps it even though the save has none. So every loaded or rejoined AI has one more base manager than the AI in the running game.

AI state is part of the full state hash, so a rejoin goes out of sync. I tested it with two peers: a host playing Wall Demo with two Petra AIs (seed 31), and an observer that rejoined and got the state of turn 600. Both peers wrote OOS dumps at turn 880. With the fix below there was no OOS up to turn 1,099.

To reproduce:
1. Host a game on random/wall_demo with two Petra AIs.
2. Let an observer join after turn 500.
3. The joiner goes out of sync a few hundred turns later (turn 880 in my test).

Single player is affected too: loading a save gives the AI the extra noBase. In my headless runs every restore from turns 500, 1,000 and 1,500 differed from the running game at the first comparison.

Fix: in BasesManager.Deserialize, leave noBase undefined when the save doesn't have one. With that, loads from turns 500, 1,000 and 1,500 matched the running game at every compared turn up to 2,000. I tested it as a small mod; the change is just clearing this.noBase when the saved data has no noBase entry:

```
--- a/binaries/data/mods/public/simulation/ai/petra/basesManager.js
+++ b/binaries/data/mods/public/simulation/ai/petra/basesManager.js
@@ -796,6 +796,10 @@
             this.noBase.init(gameState, BaseManager.STATE_WITH_ANCHOR);
             this.noBase.Deserialize(gameState, data.noBase);
         }
+        else
+            // init() (called by HQ.Deserialize) created a noBase that the saved game never had:
+            // the region analysis failed at game start, so basesManager.init was never called.
+            this.noBase = undefined;
 
         this.baseManagers = [];
         for (const basedata of data.baseManagers)
```

Tested on main 47f5fb4f.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...