From d40cab2e284217140fd62d7eefb13418e2ee7a0c Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 19 Feb 2023 18:11:07 +0400 Subject: [PATCH] fix: clean cultures on regeneration, v1.89.07 --- index.html | 8 ++--- modules/burgs-and-states.js | 6 ++-- modules/cultures-generator.js | 39 +++++++++++++-------- modules/dynamic/editors/religions-editor.js | 4 +-- modules/religions-generator.js | 15 ++++---- modules/ui/editors.js | 2 +- versioning.js | 2 +- 7 files changed, 41 insertions(+), 35 deletions(-) diff --git a/index.html b/index.html index 90594d0b..84323f43 100644 --- a/index.html +++ b/index.html @@ -7845,10 +7845,10 @@ - - + + - + @@ -7867,7 +7867,7 @@ - + diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js index f0b13a05..e360b45a 100644 --- a/modules/burgs-and-states.js +++ b/modules/burgs-and-states.js @@ -359,7 +359,7 @@ window.BurgsAndStates = (function () { TIME && console.timeEnd("drawBurgs"); }; - // growth algorithm to assign cells to states like we did for cultures + // expand cultures across the map (Dijkstra-like algorithm) const expandStates = function () { TIME && console.time("expandStates"); const {cells, states, cultures, burgs} = pack; @@ -368,8 +368,8 @@ window.BurgsAndStates = (function () { const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p}); const cost = []; - const globalNeutralRate = byId("neutralInput")?.value || 1; - const statesNeutralRate = byId("statesNeutral")?.value || 1; + const globalNeutralRate = byId("neutralInput")?.valueAsNumber || 1; + const statesNeutralRate = byId("statesNeutral")?.valueAsNumber || 1; const neutral = (cells.i.length / 2) * globalNeutralRate * statesNeutralRate; // limit cost for state growth // remove state from all cells except of locked diff --git a/modules/cultures-generator.js b/modules/cultures-generator.js index 48090db3..eeb09407 100644 --- a/modules/cultures-generator.js +++ b/modules/cultures-generator.js @@ -507,28 +507,37 @@ window.Cultures = (function () { // expand cultures across the map (Dijkstra-like algorithm) const expand = function () { TIME && console.time("expandCultures"); - cells = pack.cells; + const {cells, cultures} = pack; const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p}); - pack.cultures.forEach(function (c) { - if (!c.i || c.removed || c.lock) return; - queue.queue({e: c.center, p: 0, c: c.i}); - }); - - const neutral = (cells.i.length / 5000) * 3000 * neutralInput.value; // limit cost for culture growth const cost = []; + + const neutralRate = byId("neutralRate")?.valueAsNumber || 1; + const neutral = cells.i.length * 0.6 * neutralRate; // limit cost for culture growth + + // remove culture from all cells except of locked + for (const cellId of cells.i) { + const culture = cultures[cells.culture[cellId]]; + if (culture.lock) continue; + cells.culture[cellId] = 0; + } + + for (const culture of cultures) { + if (!culture.i || culture.removed) continue; + queue.queue({e: culture.center, p: 0, c: culture.i}); + } + while (queue.length) { - const next = queue.dequeue(), - n = next.e, - p = next.p, - c = next.c; - const type = pack.cultures[c].type; - cells.c[n].forEach(e => { - if (pack.cultures[cells.culture[e]]?.lock) return; + const {e, p, c} = queue.dequeue(); + const {type} = pack.cultures[c]; + + cells.c[e].forEach(e => { + const culture = cells.culture[e]; + if (culture?.lock) return; // do not overwrite cell of locked culture const biome = cells.biome[e]; const biomeCost = getBiomeCost(c, biome, type); - const biomeChangeCost = biome === cells.biome[n] ? 0 : 20; // penalty on biome change + const biomeChangeCost = biome === cells.biome[e] ? 0 : 20; // penalty on biome change const heightCost = getHeightCost(e, cells.h[e], type); const riverCost = getRiverCost(cells.r[e], e, type); const typeCost = getTypeCost(cells.t[e], type); diff --git a/modules/dynamic/editors/religions-editor.js b/modules/dynamic/editors/religions-editor.js index 4cf1903f..8a4abc5e 100644 --- a/modules/dynamic/editors/religions-editor.js +++ b/modules/dynamic/editors/religions-editor.js @@ -3,11 +3,11 @@ addListeners(); export function open() { closeDialogs("#religionsEditor, .stable"); - if (!layerIsOn("toggleReligions")) toggleCultures(); if (layerIsOn("toggleStates")) toggleStates(); if (layerIsOn("toggleBiomes")) toggleBiomes(); if (layerIsOn("toggleCultures")) toggleReligions(); if (layerIsOn("toggleProvinces")) toggleProvinces(); + if (!layerIsOn("toggleReligions")) toggleReligions(); refreshReligionsEditor(); drawReligionCenters(); @@ -214,7 +214,7 @@ function religionsEditorAddLines() {
${si(population)}
`; diff --git a/modules/religions-generator.js b/modules/religions-generator.js index 4d06d327..0ae9be91 100644 --- a/modules/religions-generator.js +++ b/modules/religions-generator.js @@ -350,9 +350,8 @@ window.Religions = (function () { const religions = []; // add folk religions - pack.cultures.forEach(c => { - const newId = c.i; - if (!newId) return religions.push({i: 0, name: "No religion"}); + cultures.forEach(c => { + if (!c.i) return religions.push({i: 0, name: "No religion"}); if (c.removed) { religions.push({ @@ -364,6 +363,8 @@ window.Religions = (function () { return; } + const newId = c.i; + if (pack.religions) { const lockedFolkReligion = pack.religions.find( r => r.culture === c.i && !r.removed && r.lock && r.type === "Folk" @@ -383,7 +384,7 @@ window.Religions = (function () { const form = rw(forms.Folk); const name = c.name + " " + rw(types[form]); const deity = form === "Animism" ? null : getDeityName(c.i); - const color = getMixedColor(c.color, 0.1, 0); // `url(#hatch${rand(8,13)})`; + const color = getMixedColor(c.color, 0.1, 0); religions.push({ i: newId, name, @@ -713,14 +714,10 @@ window.Religions = (function () { }; function updateCultures() { - TIME && console.time("updateCulturesForReligions"); pack.religions = pack.religions.map((religion, index) => { - if (index === 0) { - return religion; - } + if (index === 0) return religion; return {...religion, culture: pack.cells.culture[religion.center]}; }); - TIME && console.timeEnd("updateCulturesForReligions"); } // get supreme deity name diff --git a/modules/ui/editors.js b/modules/ui/editors.js index 54ab8300..23798861 100644 --- a/modules/ui/editors.js +++ b/modules/ui/editors.js @@ -1188,6 +1188,6 @@ async function editCultures() { async function editReligions() { if (customization) return; - const Editor = await import("../dynamic/editors/religions-editor.js?v=1.88.06"); + const Editor = await import("../dynamic/editors/religions-editor.js?v=1.88.07"); Editor.open(); } diff --git a/versioning.js b/versioning.js index e53ca4c2..ec4f6f9d 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.89.06"; // generator version, update each time +const version = "1.89.07"; // generator version, update each time { document.title += " v" + version;