From ffb9d2e5c3e936ab6347bf23eff0483c3faedc58 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Thu, 25 Feb 2021 14:38:00 +0300 Subject: [PATCH] v1.5.60 - fix for burg assigned to not-existant state --- modules/save-and-load.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/save-and-load.js b/modules/save-and-load.js index eed28881..35d1bab5 100644 --- a/modules/save-and-load.js +++ b/modules/save-and-load.js @@ -1147,11 +1147,18 @@ function parseLoadedData(data) { pack.burgs.forEach(b => { if (!b.i || b.removed) return; if (b.port < 0) {ERROR && console.error("Data Integrity Check. Burg", b.i, "has invalid port value", b.port); b.port = 0;} - if (b.cell < cells.i.length) return; - ERROR && console.error("Data Integrity Check. Burg", b.i, "is linked to invalid cell", b.cell); - b.cell = findCell(b.x, b.y); - cells.i.filter(i => cells.burg[i] === b.i).forEach(i => cells.burg[i] = 0); - cells.burg[b.cell] = b.i; + + if (b.cell >= cells.i.length) { + ERROR && console.error("Data Integrity Check. Burg", b.i, "is linked to invalid cell", b.cell); + b.cell = findCell(b.x, b.y); + cells.i.filter(i => cells.burg[i] === b.i).forEach(i => cells.burg[i] = 0); + cells.burg[b.cell] = b.i; + } + + if (b.state && !pack.states[b.state]) { + ERROR && console.error("Data Integrity Check. Burg", b.i, "is linked to invalid state", b.state); + b.state = 0; + } }); pack.provinces.forEach(p => {