Fix a crash when the Petrabot region analysis fails

When the region analysis fails, that's usually because the AI doesn't
have any units or CCs at all.
Previously, the whole game crashed when serializing because this.noBase
was still undefined.
This commit is contained in:
Vantha authored and Phosit committed 2025-10-23 22:09:30 +02:00
1 parent ce512e383f
commit a25750f62d
1 file changed
+9 -5
@@ -788,7 +788,8 @@ BasesManager.prototype.Serialize = function()
return {
"properties": properties,
"noBase": this.noBase.Serialize(),
// noBase can be undefined if the region analysis failed and the managers haven't been initialised.
"noBase": this.noBase?.Serialize(),
"baseManagers": baseManagers
};
};
@@ -798,10 +799,13 @@ BasesManager.prototype.Deserialize = function(gameState, data)
for (const key in data.properties)
this[key] = data.properties[key];
this.noBase = new BaseManager(gameState, this);
this.noBase.Deserialize(gameState, data.noBase);
this.noBase.init(gameState, BaseManager.STATE_WITH_ANCHOR);
this.noBase.Deserialize(gameState, data.noBase);
if (data.noBase)
{
this.noBase = new BaseManager(gameState, this);
this.noBase.Deserialize(gameState, data.noBase);
this.noBase.init(gameState, BaseManager.STATE_WITH_ANCHOR);
this.noBase.Deserialize(gameState, data.noBase);
}
this.baseManagers = [];
for (const basedata of data.baseManagers)