mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 03:51:23 +01:00
ability to lock culture in a easy-defined set
fixes uncaught error in commit dada419 from PR #910
This commit is contained in:
parent
e4a7a6ecf2
commit
2ea53d2688
2 changed files with 50 additions and 44 deletions
|
|
@ -118,69 +118,75 @@ window.Cultures = (function () {
|
|||
|
||||
function selectCultures(c) {
|
||||
let def = getDefault(c);
|
||||
if (c === def.length) return def;
|
||||
if (def.every(d => d.odd === 1)) return def.splice(0, c);
|
||||
|
||||
const count = Math.min(c, def.length);
|
||||
const cultures = [];
|
||||
|
||||
pack.cultures?.forEach(function (culture) {
|
||||
if (culture.lock) cultures.push(culture);
|
||||
});
|
||||
|
||||
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
|
||||
if (cultures.length) {
|
||||
|
||||
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;
|
||||
};
|
||||
if (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 (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;
|
||||
};
|
||||
|
||||
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 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);
|
||||
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 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
|
||||
else r.removed = true; // the unlocked folk religions that were left behind by unlocked cultures
|
||||
|
||||
// update origin heirarchy to the new ids
|
||||
r.origins = r.origins.map(i => religMap[i]).filter(i => i);
|
||||
});
|
||||
|
||||
// update origin heirarchy to the new ids
|
||||
r.origins = r.origins.map(i => religMap[i]).filter(i => i);
|
||||
});
|
||||
|
||||
for (const i of cells.i) {
|
||||
cells.religion[i] = religMap[cells.religion[i]];
|
||||
}
|
||||
for (const i of cells.i) {
|
||||
cells.religion[i] = religMap[cells.religion[i]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (c === def.length) return def;
|
||||
if (def.every(d => d.odd === 1)) return def.splice(0, c);
|
||||
}
|
||||
|
||||
pack.religions?.forEach(r => {
|
||||
if (r.type === "Folk" && !r.locked)
|
||||
cell.religion = cells.religion.map(ri => ri === r.i ? 0 : ri);
|
||||
cells.religion = cells.religion.map(ri => ri === r.i ? 0 : ri);
|
||||
});
|
||||
|
||||
for (let culture, rnd, i = 0; cultures.length < count && i < 200; i++) {
|
||||
let culture, rnd;
|
||||
let i = 0;
|
||||
do {
|
||||
do {
|
||||
rnd = rand(def.length - 1);
|
||||
culture = def[rnd];
|
||||
} while (!P(culture.odd));
|
||||
i++;
|
||||
} while (i < 200 && !P(culture.odd));
|
||||
cultures.push(culture);
|
||||
def.splice(rnd, 1);
|
||||
}
|
||||
} while (cultures.length < c && def.length > 0);
|
||||
return cultures;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -814,7 +814,7 @@ window.Religions = (function () {
|
|||
const faith = religions.find(r => r.i === i);
|
||||
if (faith) {
|
||||
if (faith.type === "Folk" && !faith.locked)
|
||||
tReligions.push({...faith, removed: true}));
|
||||
tReligions.push({...faith, removed: true});
|
||||
else tReligions.push(faith);
|
||||
}
|
||||
else tReligions.push({
|
||||
|
|
@ -861,7 +861,7 @@ window.Religions = (function () {
|
|||
|
||||
if (r.origins?.length < 1) r.origins = [0];
|
||||
|
||||
if (r.type === "Folk"){
|
||||
if (r.type === "Folk" && cultures[r.i]) {
|
||||
r.center = cultures[r.i].center;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue