when cultures regenerate a different number

This commit is contained in:
Canis Artorus 2023-02-22 22:35:47 -07:00
parent b7bcf96a25
commit e4a7a6ecf2
2 changed files with 93 additions and 30 deletions

View file

@ -139,20 +139,39 @@ window.Cultures = (function () {
religMap[cultures[j].i] = newId; religMap[cultures[j].i] = newId;
}; };
for (const i of cells.i) {
cells.religion[i] = religMap[cells.religion[i]];
}
religions.forEach(r => { religions.forEach(r => {
if (r.i === 0) return; if (r.i === 0) return;
// queue for movement to newId, or removal // queue for movement to newId, or removal
if (religMap[r.i]) r.i = religMap[r.i]; if (religMap[r.i]) r.i = religMap[r.i];
else r.removed = !r.locked; else if (r.locked) {
// locked folk religion getting a new culture
if (religMap.find(r.i) > 0) { // something already there, shift away from conflict
const nextId = religMap.find(0);
if (nextId > 0) {
religMap[r.i] = nextId;
r.i = nextId;
}
else { // none available...
religMap[r.i] = religMap.length;
r.i = religMap.length;
religMap.push(r.i);
}
}
}
else r.removed = true; // the unlocked folk religions that were left behind by unlocked cultures
// update origin heirarchy to the new ids // update origin heirarchy to the new ids
r.origins = r.origins.map(i => religMap[i]).filter(i => i); r.origins = r.origins.map(i => religMap[i]).filter(i => i);
}); });
for (const i of cells.i) {
cells.religion[i] = religMap[cells.religion[i]];
}
} }
pack.religions?.forEach(r => {
if (r.type === "Folk" && !r.locked)
cell.religion = cells.religion.map(ri => ri === r.i ? 0 : ri);
});
for (let culture, rnd, i = 0; cultures.length < count && i < 200; i++) { for (let culture, rnd, i = 0; cultures.length < count && i < 200; i++) {
do { do {

View file

@ -784,44 +784,88 @@ window.Religions = (function () {
} }
religions[c.i] = newFolk; religions[c.i] = newFolk;
} else {
religions.push(newFolk);
} }
else religions.push(newFolk);
}; };
function updateCultures() { function updateCultures() {
TIME && console.time("updateCulturesForReligions"); TIME && console.time("updateCulturesForReligions");
const religions = []; const {religions, cultures, cells} = pack;
for (let i=0; i < pack.religions.length; i++) {
const faith = pack.religions.find(r => r.i === i); const tReligions = [];
if (faith) { const spareCovenants = [];
if (faith.type === "Folk" && faith.removed && !pack.cultures[i].removed) { const codes = religions.filter(r => !r.removed).map(r => r.code);
const codes = religions.map(r => r.code);
religions.push(createFolk(c, codes)); tReligions.push(religions[0]);
for (let i = 1; i < cultures.length; i++) {
const faith = religions.find(r => r.i === i);
if (faith && !faith.removed) {
if (faith.type === "Folk") {
tReligions.push(faith);
continue;
} }
else religions.push(faith); else spareCovenants.push(faith);
} }
else religions.push({ const newFolk = createFolk(cultures[i], codes);
i, tReligions.push(newFolk);
name: "removed index", codes.push(newFolk.code);
origins: [null], }
removed: true for (let i = cultures.length; i < religions.length; i++) {
}); const faith = religions.find(r => r.i === i);
if (faith) {
if (faith.type === "Folk" && !faith.locked)
tReligions.push({...faith, removed: true}));
else tReligions.push(faith);
}
else tReligions.push({
i,
name: "filler index",
origins: [null],
removed: true
});
} }
pack.religions = religions; const updateMap = [];
for (let k = 0; k < spareCovenants.length; k++) {
const sc = spareCovenants[k];
const newId = tReligions.length;
for (const i of cells.i) {
if (cells.religion[i] = sc.i) {
cells.religion[i] = newId;
}
}
updateMap.push({oldId: sc.i, newId});
tReligions.forEach(r => {
if (r.i === 0) return;
for (let i = 0; i < r.origins.length; i++) {
if (r.origins[i] === sc.i) {
r.origins[i] === newId;
return;
}
}
});
// update origins from other spareCovenants
for (let i = 0; i < sc.origins.length; i++) {
const changeRule = updateMap.find(u => u.oldId === sc.origins[i])
if (changeRule) sc.origins[i] = changeRule.newId;
}
tReligions.push({...sc, i: newId});
}
pack.religions = tReligions;
pack.religions.forEach(r => { pack.religions.forEach(r => {
if(r.i === 0) return; if (r.i === 0) return;
if(r.origins?.length < 1) r.origins = [0]; if (r.origins?.length < 1) r.origins = [0];
if(r.type === "Folk"){ if (r.type === "Folk"){
r.center = pack.cultures[r.i].center; r.center = cultures[r.i].center;
} }
else { else {
r.culture = pack.cells.culture[r.center]; r.culture = cells.culture[r.center];
if (r.i < pack.cultures.length) addFolk(pack.cultures[r.i].center);
} }
}); });
TIME && console.timeEnd("updateCulturesForReligions"); TIME && console.timeEnd("updateCulturesForReligions");