From eb5d924cbd960abb7a36c72ee7a635f1b7cec4b0 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 5 Feb 2023 00:49:05 +0400 Subject: [PATCH] fix: state expansion to reset on re-generation --- index.html | 6 ++--- main.js | 1 - modules/burgs-and-states.js | 32 ++++++++++++++++-------- modules/dynamic/editors/states-editor.js | 1 - modules/ui/editors.js | 2 +- versioning.js | 2 +- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index 1fb860ab..baa5562b 100644 --- a/index.html +++ b/index.html @@ -7846,7 +7846,7 @@ - + @@ -7863,11 +7863,11 @@ - + - + diff --git a/main.js b/main.js index 69323e92..5cf0edc3 100644 --- a/main.js +++ b/main.js @@ -191,7 +191,6 @@ let populationRate = +document.getElementById("populationRateInput").value; let distanceScale = +document.getElementById("distanceScaleInput").value; let urbanization = +document.getElementById("urbanizationInput").value; let urbanDensity = +document.getElementById("urbanDensityInput").value; -let statesNeutral = 1; // statesEditor growth parameter applyStoredOptions(); diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js index e9069e83..f0b13a05 100644 --- a/modules/burgs-and-states.js +++ b/modules/burgs-and-states.js @@ -367,18 +367,28 @@ window.BurgsAndStates = (function () { 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 - states - .filter(s => s.i && !s.removed) - .forEach(s => { - const capitalCell = burgs[s.capital].cell; - cells.state[capitalCell] = s.i; - const cultureCenter = cultures[s.culture].center; - const b = cells.biome[cultureCenter]; // state native biome - queue.queue({e: s.center, p: 0, s: s.i, b}); - cost[s.center] = 1; - }); + const globalNeutralRate = byId("neutralInput")?.value || 1; + const statesNeutralRate = byId("statesNeutral")?.value || 1; + const neutral = (cells.i.length / 2) * globalNeutralRate * statesNeutralRate; // limit cost for state growth + + // remove state from all cells except of locked + for (const cellId of cells.i) { + const state = states[cells.state[cellId]]; + if (state.lock) continue; + cells.state[cellId] = 0; + } + + for (const state of states) { + if (!state.i || state.removed) continue; + + const capitalCell = burgs[state.capital].cell; + cells.state[capitalCell] = state.i; + const cultureCenter = cultures[state.culture].center; + const b = cells.biome[cultureCenter]; // state native biome + queue.queue({e: state.center, p: 0, s: state.i, b}); + cost[state.center] = 1; + } while (queue.length) { const next = queue.dequeue(); diff --git a/modules/dynamic/editors/states-editor.js b/modules/dynamic/editors/states-editor.js index 87592706..41241340 100644 --- a/modules/dynamic/editors/states-editor.js +++ b/modules/dynamic/editors/states-editor.js @@ -883,7 +883,6 @@ function changeStatesGrowthRate() { const growthRate = +this.value; byId("statesNeutral").value = growthRate; byId("statesNeutralNumber").value = growthRate; - statesNeutral = growthRate; tip("Growth rate: " + growthRate); recalculateStates(false); } diff --git a/modules/ui/editors.js b/modules/ui/editors.js index 2d40c916..54ab8300 100644 --- a/modules/ui/editors.js +++ b/modules/ui/editors.js @@ -1176,7 +1176,7 @@ function refreshAllEditors() { // dynamically loaded editors async function editStates() { if (customization) return; - const Editor = await import("../dynamic/editors/states-editor.js?v=1.89.02"); + const Editor = await import("../dynamic/editors/states-editor.js?v=1.89.05"); Editor.open(); } diff --git a/versioning.js b/versioning.js index 734e3886..ff5c3ef3 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.89.04"; // generator version, update each time +const version = "1.89.05"; // generator version, update each time { document.title += " v" + version;