mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01: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,17 +118,15 @@ window.Cultures = (function () {
|
||||||
|
|
||||||
function selectCultures(c) {
|
function selectCultures(c) {
|
||||||
let def = getDefault(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 = [];
|
const cultures = [];
|
||||||
|
|
||||||
pack.cultures?.forEach(function (culture) {
|
pack.cultures?.forEach(function (culture) {
|
||||||
if (culture.lock) cultures.push(culture);
|
if (culture.lock) cultures.push(culture);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (cultures.length && pack.religions?.length > 1) {
|
if (cultures.length) {
|
||||||
|
|
||||||
|
if (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
|
||||||
|
|
@ -168,19 +166,27 @@ window.Cultures = (function () {
|
||||||
cells.religion[i] = religMap[cells.religion[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 => {
|
pack.religions?.forEach(r => {
|
||||||
if (r.type === "Folk" && !r.locked)
|
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 {
|
do {
|
||||||
rnd = rand(def.length - 1);
|
rnd = rand(def.length - 1);
|
||||||
culture = def[rnd];
|
culture = def[rnd];
|
||||||
} while (!P(culture.odd));
|
i++;
|
||||||
|
} while (i < 200 && !P(culture.odd));
|
||||||
cultures.push(culture);
|
cultures.push(culture);
|
||||||
def.splice(rnd, 1);
|
def.splice(rnd, 1);
|
||||||
}
|
} while (cultures.length < c && def.length > 0);
|
||||||
return cultures;
|
return cultures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -814,7 +814,7 @@ window.Religions = (function () {
|
||||||
const faith = religions.find(r => r.i === i);
|
const faith = religions.find(r => r.i === i);
|
||||||
if (faith) {
|
if (faith) {
|
||||||
if (faith.type === "Folk" && !faith.locked)
|
if (faith.type === "Folk" && !faith.locked)
|
||||||
tReligions.push({...faith, removed: true}));
|
tReligions.push({...faith, removed: true});
|
||||||
else tReligions.push(faith);
|
else tReligions.push(faith);
|
||||||
}
|
}
|
||||||
else tReligions.push({
|
else tReligions.push({
|
||||||
|
|
@ -861,7 +861,7 @@ window.Religions = (function () {
|
||||||
|
|
||||||
if (r.origins?.length < 1) r.origins = [0];
|
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;
|
r.center = cultures[r.i].center;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue