regenerate bugs fixing

This commit is contained in:
Canis Artorus 2023-02-21 21:32:55 -07:00
parent c830bf31ba
commit b7bcf96a25
3 changed files with 71 additions and 64 deletions

View file

@ -128,12 +128,13 @@ window.Cultures = (function () {
if (culture.lock) cultures.push(culture); if (culture.lock) cultures.push(culture);
}); });
if (pack.religions?.length) { if (cultures.length && pack.religions?.length > 1) {
const religions = pack.religions; const religions = pack.religions;
const religMap = []; const religMap = [];
religions.forEach(r => religMap.push(r.type === "Folk" ? 0 : r.i)); // remove folk religions in general 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; const newId = j + 1;
religMap[cultures[j].i] = newId; religMap[cultures[j].i] = newId;
}; };
@ -142,15 +143,15 @@ window.Cultures = (function () {
cells.religion[i] = religMap[cells.religion[i]]; 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 // update origin heirarchy to the new ids
religions[i].origins = religions[i].origins.map(i => religMap[i]).filter(i => i); r.origins = r.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;
}
}
} }
for (let culture, rnd, i = 0; cultures.length < count && i < 200; i++) { for (let culture, rnd, i = 0; cultures.length < count && i < 200; i++) {

View file

@ -240,10 +240,10 @@ function religionsEditorAddLines() {
${getExtentOptions(r.expansion)} ${getExtentOptions(r.expansion)}
</select>` </select>`
} }
<span data-tip="Religion expansionism. Defines competitive size" class="icon-resize-full ${r.type === "Folk" ? "placeholder "}hide"></span> <span data-tip="Religion expansionism. Defines competitive size" class="icon-resize-full ${r.type === "Folk" ? "placeholder " : ""}hide"></span>
<input <input
data-tip="Religion expansionism. Defines competitive size. Click to change, then click Recalculate to apply change" data-tip="Religion expansionism. Defines competitive size. Click to change, then click Recalculate to apply change"
class="religionExpan ${r.type === "Folk" ? "placeholder "}hide" class="religionExpan ${r.type === "Folk" ? "placeholder " : ""}hide"
type="number" type="number"
min="0" min="0"
max="99" max="99"
@ -254,7 +254,7 @@ function religionsEditorAddLines() {
data-tip="Lock religion, will regenerate the origin folk and organized religion if they are not also locked" data-tip="Lock religion, will regenerate the origin folk and organized religion if they are not also locked"
class="icon-lock${r.lock ? '' : '-open'} hide" class="icon-lock${r.lock ? '' : '-open'} hide"
></span> ></span>
<span data-tip="Remove religion" class="icon-trash-empty ${r.type === "Folk" ? "placeholder "}hide"></span> <span data-tip="Remove religion" class="icon-trash-empty ${r.type === "Folk" ? "placeholder " : ""}hide"></span>
</div>`; </div>`;
} }
$body.innerHTML = lines; $body.innerHTML = lines;

View file

@ -382,24 +382,9 @@ window.Religions = (function () {
} }
} }
const form = rw(forms.Folk); const newFolk = createFolk(c, codes);
const name = c.name + " " + rw(types[form]); codes.push(newFolk.code);
const deity = form === "Animism" ? null : getDeityName(c.i); religions.push(newFolk);
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
});
}); });
if (religionsInput.value == 0 || pack.cultures.length < 2) { if (religionsInput.value == 0 || pack.cultures.length < 2) {
@ -515,7 +500,7 @@ window.Religions = (function () {
const name = getCultName(form, center); const name = getCultName(form, center);
const expansionism = gauss(1.1, 0.5, 0, 5); const expansionism = gauss(1.1, 0.5, 0, 5);
const color = getMixedColor(cultures[culture].color, 0.5, 0); // "url(#hatch7)"; const color = getMixedColor(cultures[culture].color, 0.5, 0); // "url(#hatch7)";
code = abbreviate(name, codes); const code = abbreviate(name, codes);
codes.push(code); codes.push(code);
religions.push({ religions.push({
i: religions.length, i: religions.length,
@ -583,6 +568,27 @@ window.Religions = (function () {
TIME && console.timeEnd("generateReligions"); 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 // growth algorithm to assign cells to religions
function expandReligions() { function expandReligions() {
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p}); const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
@ -749,35 +755,13 @@ window.Religions = (function () {
const {cultures, religions, cells} = pack; const {cultures, religions, cells} = pack;
const c = cultures.find(c => !c.removed && c.center === center); const c = cultures.find(c => !c.removed && c.center === center);
const color = getMixedColor(c.color, 0.1, 0); const codes = religions.map(r => r.code);
const form = rw(forms.Folk); const newFolk = createFolk(c, codes);
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
};
if(c.i < religions.length){ if(c.i < religions.length){
// move an existing organized religion to the end of the array // move an existing organized religion to the end of the array
const rCargo = religions[c.i]; const rCargo = religions[c.i];
if(!rCargo.removed) { if(!rCargo.removed && rCargo.type != "Folk") {
const newId = religions.length; const newId = religions.length;
rCargo.i = newId; rCargo.i = newId;
@ -787,9 +771,10 @@ window.Religions = (function () {
} }
} }
religions.forEach(r => { religions.forEach(r => {
if (r.i === 0) return;
for(let j = 0; j < r.origins.length; j++) { for(let j = 0; j < r.origins.length; j++) {
if(r.origins[j] === c.i) { if(r.origins[j] === c.i) {
r.origins[j] === newid; r.origins[j] === newId;
return; return;
} }
} }
@ -806,17 +791,38 @@ window.Religions = (function () {
function updateCultures() { function updateCultures() {
TIME && console.time("updateCulturesForReligions"); 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 => { pack.religions.forEach(r => {
if(r.i === 0) return; 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.type === "Folk"){
if(r.removed) addFolk(pack.cultures[r.i].center); // regnerate folk religions for the regenerated cultures r.center = pack.cultures[r.i].center;
else 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"); TIME && console.timeEnd("updateCulturesForReligions");
} }