diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js index 58820cc91..a198a2168 100644 --- a/modules/burgs-and-states.js +++ b/modules/burgs-and-states.js @@ -364,7 +364,7 @@ window.BurgsAndStates = (function () { TIME && console.time("expandStates"); const {cells, states, cultures, burgs} = pack; - cells.state = new Uint16Array(cells.i.length); + cells.state = cells.state || new Uint16Array(cells.i.length); const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p}); const cost = []; const neutral = (cells.i.length / 5000) * 2500 * neutralInput.value * statesNeutral; // limit cost for state growth diff --git a/modules/ui/tools.js b/modules/ui/tools.js index 532c0da2b..298072266 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -238,11 +238,6 @@ function recreateStates() { // pack.provinces[id].should_restore = true; }); - for (const i of pack.cells.i) { - const stateId = pack.cells.state[i]; - if (stateId === s.i) pack.cells.state[i] = newId; - } - const {x, y} = validBurgs[s.capital]; capitalsTree.add([x, y]); @@ -250,6 +245,13 @@ function recreateStates() { newStates.push(s); }); + for (const i of pack.cells.i) { + const stateId = pack.cells.state[i]; + const lockedStateIndex = lockedStatesIds.indexOf(stateId) + 1; + // lockedStateIndex is an index of locked state of 0 if state is not locked + pack.cells.state[i] = lockedStateIndex; + } + for (let i = newStates.length; i < count; i++) { let capital = null;