diff --git a/modules/cultures-generator.js b/modules/cultures-generator.js
index a2a9dd09..6925bfdc 100644
--- a/modules/cultures-generator.js
+++ b/modules/cultures-generator.js
@@ -128,12 +128,13 @@ window.Cultures = (function () {
if (culture.lock) cultures.push(culture);
});
- if (pack.religions?.length) {
+ if (cultures.length && pack.religions?.length > 1) {
const religions = pack.religions;
const religMap = [];
religions.forEach(r => religMap.push(r.type === "Folk" ? 0 : r.i)); // remove folk religions in general
- for (const j = 0; j < cultures.length; j++) { // locked cultures save their folk religions, at the new id
+ for (let j = 0; j < cultures.length; j++) {
+ // locked cultures bring their folk religions along to the new id
const newId = j + 1;
religMap[cultures[j].i] = newId;
};
@@ -142,15 +143,15 @@ window.Cultures = (function () {
cells.religion[i] = religMap[cells.religion[i]];
}
- for (const i = 0; i < religMap.length; i++) {
+ religions.forEach(r => {
+ if (r.i === 0) return;
+ // queue for movement to newId, or removal
+ if (religMap[r.i]) r.i = religMap[r.i];
+ else r.removed = !r.locked;
+
// update origin heirarchy to the new ids
- religions[i].origins = religions[i].origins.map(i => religMap[i]).filter(i => i);
- if (religMap[i] !== i) {
- if (religMap[i]) religions[religMap[i]] = religions[i];
- // unlocked folk religions for unlocked cultures are removed pending regeneration
- if (!religions[i].locked) religions[i].removed = true;
- }
- }
+ r.origins = r.origins.map(i => religMap[i]).filter(i => i);
+ });
}
for (let culture, rnd, i = 0; cultures.length < count && i < 200; i++) {
diff --git a/modules/dynamic/editors/religions-editor.js b/modules/dynamic/editors/religions-editor.js
index b13dd12d..f4e8c086 100644
--- a/modules/dynamic/editors/religions-editor.js
+++ b/modules/dynamic/editors/religions-editor.js
@@ -240,10 +240,10 @@ function religionsEditorAddLines() {
${getExtentOptions(r.expansion)}
`
}
-
+
-
+
`;
}
$body.innerHTML = lines;
diff --git a/modules/religions-generator.js b/modules/religions-generator.js
index 3a80926c..35c8247d 100644
--- a/modules/religions-generator.js
+++ b/modules/religions-generator.js
@@ -381,25 +381,10 @@ window.Religions = (function () {
return;
}
}
-
- 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 code = abbreviate(name, codes);
- codes.push(code);
- religions.push({
- i: newId,
- name,
- color,
- culture: newId,
- type: "Folk",
- form,
- deity,
- center: c.center,
- origins: [0],
- code
- });
+
+ const newFolk = createFolk(c, codes);
+ codes.push(newFolk.code);
+ religions.push(newFolk);
});
if (religionsInput.value == 0 || pack.cultures.length < 2) {
@@ -515,7 +500,7 @@ window.Religions = (function () {
const name = getCultName(form, center);
const expansionism = gauss(1.1, 0.5, 0, 5);
const color = getMixedColor(cultures[culture].color, 0.5, 0); // "url(#hatch7)";
- code = abbreviate(name, codes);
+ const code = abbreviate(name, codes);
codes.push(code);
religions.push({
i: religions.length,
@@ -582,6 +567,27 @@ window.Religions = (function () {
TIME && console.timeEnd("generateReligions");
};
+
+ function createFolk(c, codes) {
+
+ 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);
+ const code = abbreviate(name, codes);
+ return {
+ i: c.i,
+ name,
+ color,
+ culture: c.i,
+ type: "Folk",
+ form,
+ deity,
+ center: c.center,
+ origins: [0],
+ code
+ };
+ }
// growth algorithm to assign cells to religions
function expandReligions() {
@@ -749,35 +755,13 @@ window.Religions = (function () {
const {cultures, religions, cells} = pack;
const c = cultures.find(c => !c.removed && c.center === center);
- const color = getMixedColor(c.color, 0.1, 0);
- const form = rw(forms.Folk);
- const deity = form === "Animism" ? null : getDeityName(c.i);
- const name = c.name + " " + rw(types[form]);
- const code = abbreviate(
- name,
- religions.map(r => r.code)
- );
- const newFolk = {
- i: c.i,
- name,
- color,
- culture: c.i,
- type: "Folk",
- form,
- deity,
- center: center,
- cells: 0,
- area: 0,
- rural: 0,
- urban: 0,
- origins: [0],
- code
- };
+ const codes = religions.map(r => r.code);
+ const newFolk = createFolk(c, codes);
if(c.i < religions.length){
// move an existing organized religion to the end of the array
const rCargo = religions[c.i];
- if(!rCargo.removed) {
+ if(!rCargo.removed && rCargo.type != "Folk") {
const newId = religions.length;
rCargo.i = newId;
@@ -787,9 +771,10 @@ window.Religions = (function () {
}
}
religions.forEach(r => {
+ if (r.i === 0) return;
for(let j = 0; j < r.origins.length; j++) {
if(r.origins[j] === c.i) {
- r.origins[j] === newid;
+ r.origins[j] === newId;
return;
}
}
@@ -806,17 +791,38 @@ window.Religions = (function () {
function updateCultures() {
TIME && console.time("updateCulturesForReligions");
+ const religions = [];
+ for (let i=0; i < pack.religions.length; i++) {
+ const faith = pack.religions.find(r => r.i === i);
+ if (faith) {
+ if (faith.type === "Folk" && faith.removed && !pack.cultures[i].removed) {
+ const codes = religions.map(r => r.code);
+ religions.push(createFolk(c, codes));
+ }
+ else religions.push(faith);
+ }
+ else religions.push({
+ i,
+ name: "removed index",
+ origins: [null],
+ removed: true
+ });
+ }
+
+ pack.religions = religions;
+
pack.religions.forEach(r => {
if(r.i === 0) return;
- if(!r.origins.length) r.origins = [0];
+ if(r.origins?.length < 1) r.origins = [0];
if(r.type === "Folk"){
- if(r.removed) addFolk(pack.cultures[r.i].center); // regnerate folk religions for the regenerated cultures
- else r.center = pack.cultures[r.i].center;
+ r.center = pack.cultures[r.i].center;
+ }
+ else {
+ r.culture = pack.cells.culture[r.center];
+ if (r.i < pack.cultures.length) addFolk(pack.cultures[r.i].center);
}
- // set new namebase culture
- else r.culture = pack.cells.culture[r.center];
});
TIME && console.timeEnd("updateCulturesForReligions");
}