mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 03:51:23 +01:00
style
This commit is contained in:
parent
81a19337a9
commit
c830bf31ba
3 changed files with 139 additions and 125 deletions
|
|
@ -127,24 +127,28 @@ window.Cultures = (function () {
|
||||||
pack.cultures?.forEach(function (culture) {
|
pack.cultures?.forEach(function (culture) {
|
||||||
if (culture.lock) cultures.push(culture);
|
if (culture.lock) cultures.push(culture);
|
||||||
});
|
});
|
||||||
if(pack.religions?.length){
|
|
||||||
const religMap=[];
|
if (pack.religions?.length) {
|
||||||
pack.religions.forEach(r => religMap.push(r.type === "Folk" ? 0 : r.i)); // remove folk religions in general
|
const religions = pack.religions;
|
||||||
for(const j = 0; j < cultures.length; j++) { // locked cultures save their folk religions, at the new id
|
const religMap = [];
|
||||||
const k = j+1;
|
religions.forEach(r => religMap.push(r.type === "Folk" ? 0 : r.i)); // remove folk religions in general
|
||||||
religMap[cultures[j].i] = k;
|
|
||||||
});
|
for (const j = 0; j < cultures.length; j++) { // locked cultures save their folk religions, at the new id
|
||||||
for(const i of cells.i){
|
const newId = j + 1;
|
||||||
|
religMap[cultures[j].i] = newId;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const i of cells.i) {
|
||||||
cells.religion[i] = religMap[cells.religion[i]];
|
cells.religion[i] = religMap[cells.religion[i]];
|
||||||
}
|
}
|
||||||
for(const i = 0; i < religMap.length; i++){
|
|
||||||
|
for (const i = 0; i < religMap.length; i++) {
|
||||||
// update origin heirarchy to the new ids
|
// update origin heirarchy to the new ids
|
||||||
pack.religions[i].origins = pack.religions[i].origins.map(i => religMap[i]).filter(i => i);
|
religions[i].origins = religions[i].origins.map(i => religMap[i]).filter(i => i);
|
||||||
if(religMap[i] !== i){
|
if (religMap[i] !== i) {
|
||||||
if(religMap[i] !== 0)
|
if (religMap[i]) religions[religMap[i]] = religions[i];
|
||||||
pack.religions[religMap[i]] = pack.religions[i];
|
// unlocked folk religions for unlocked cultures are removed pending regeneration
|
||||||
// folk religions for unlocked cultures are removed pending regeneration
|
if (!religions[i].locked) religions[i].removed = true;
|
||||||
pack.religions[i].removed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ function religionsEditorAddLines() {
|
||||||
<div data-tip="Religion area" class="religionArea hide" style="width: 5em">${si(area) + unit}</div>
|
<div data-tip="Religion area" class="religionArea hide" style="width: 5em">${si(area) + unit}</div>
|
||||||
<span data-tip="${populationTip}" class="icon-male hide"></span>
|
<span data-tip="${populationTip}" class="icon-male hide"></span>
|
||||||
<div data-tip="${populationTip}" class="religionPopulation hide pointer">${si(population)}</div>
|
<div data-tip="${populationTip}" class="religionPopulation hide pointer">${si(population)}</div>
|
||||||
<select data-tip="Potential religion extent" class="religionLimit placeholder hide" style="width: 5em"></select>
|
<select data-tip="Potential religion extent" class="religionExtent placeholder hide" style="width: 5em"></select>
|
||||||
<span class="icon-resize-full placeholder hide"></span>
|
<span class="icon-resize-full placeholder hide"></span>
|
||||||
<input class="religionExpan placeholder hide" type="number" />
|
<input class="religionExpan placeholder hide" type="number" />
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
@ -236,7 +236,7 @@ function religionsEditorAddLines() {
|
||||||
culture
|
culture
|
||||||
</span>`
|
</span>`
|
||||||
:
|
:
|
||||||
`<select data-tip="Potential religion extent" class="religionLimit hide" style="width: 5em">
|
`<select data-tip="Potential religion extent" class="religionExtent hide" style="width: 5em">
|
||||||
${getExtentOptions(r.expansion)}
|
${getExtentOptions(r.expansion)}
|
||||||
</select>`
|
</select>`
|
||||||
}
|
}
|
||||||
|
|
@ -283,7 +283,7 @@ function religionsEditorAddLines() {
|
||||||
$body.querySelectorAll("div > input.religionDeity").forEach(el => el.on("input", religionChangeDeity));
|
$body.querySelectorAll("div > input.religionDeity").forEach(el => el.on("input", religionChangeDeity));
|
||||||
$body.querySelectorAll("div > span.icon-arrows-cw").forEach(el => el.on("click", regenerateDeity));
|
$body.querySelectorAll("div > span.icon-arrows-cw").forEach(el => el.on("click", regenerateDeity));
|
||||||
$body.querySelectorAll("div > div.religionPopulation").forEach(el => el.on("click", changePopulation));
|
$body.querySelectorAll("div > div.religionPopulation").forEach(el => el.on("click", changePopulation));
|
||||||
$body.querySelectorAll("div > select.religionLimit").forEach(el => el.on("change", religionChangeLimit));
|
$body.querySelectorAll("div > select.religionExtent").forEach(el => el.on("change", religionChangeExtent));
|
||||||
$body.querySelectorAll("div > input.religionExpan").forEach(el => el.on("change", religionChangeExpansionism));
|
$body.querySelectorAll("div > input.religionExpan").forEach(el => el.on("change", religionChangeExpansionism));
|
||||||
$body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.on("click", religionRemovePrompt));
|
$body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.on("click", religionRemovePrompt));
|
||||||
$body.querySelectorAll("div > span.icon-lock").forEach($el => $el.on("click", updateLockStatus));
|
$body.querySelectorAll("div > span.icon-lock").forEach($el => $el.on("click", updateLockStatus));
|
||||||
|
|
@ -481,7 +481,7 @@ function changePopulation() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function religionChangeLimit() {
|
function religionChangeExtent() {
|
||||||
const religion = +this.parentNode.dataset.id;
|
const religion = +this.parentNode.dataset.id;
|
||||||
this.parentNode.dataset.expansion = this.value;
|
this.parentNode.dataset.expansion = this.value;
|
||||||
pack.religions[religion].expansion = this.value;
|
pack.religions[religion].expansion = this.value;
|
||||||
|
|
@ -839,10 +839,7 @@ function updateLockStatus() {
|
||||||
function recalculateReligions(must) {
|
function recalculateReligions(must) {
|
||||||
if (!must && !religionsAutoChange.checked) return;
|
if (!must && !religionsAutoChange.checked) return;
|
||||||
|
|
||||||
Religions.resetUnlockedReligions();
|
Religions.recalculate();
|
||||||
Religions.expandReligions();
|
|
||||||
Religions.expandHeresies();
|
|
||||||
Religions.checkReligionCenters();
|
|
||||||
|
|
||||||
drawReligions();
|
drawReligions();
|
||||||
refreshReligionsEditor();
|
refreshReligionsEditor();
|
||||||
|
|
|
||||||
|
|
@ -578,109 +578,125 @@ window.Religions = (function () {
|
||||||
|
|
||||||
expandHeresies();
|
expandHeresies();
|
||||||
|
|
||||||
checkReligionCenters();
|
checkCenters();
|
||||||
|
|
||||||
TIME && console.timeEnd("generateReligions");
|
TIME && console.timeEnd("generateReligions");
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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});
|
||||||
const cost = [];
|
const cost = [];
|
||||||
const religionIds = pack.cells.religion;
|
const religionIds = pack.cells.religion;
|
||||||
const cells = pack.cells;
|
const {cells, religions} = pack;
|
||||||
|
|
||||||
pack.religions
|
religions
|
||||||
.filter(r => !r.lock && (r.type === "Organized" || r.type === "Cult"))
|
.filter(r => !r.lock && (r.type === "Organized" || r.type === "Cult"))
|
||||||
.forEach(r => {
|
.forEach(r => {
|
||||||
religionIds[r.center] = r.i;
|
religionIds[r.center] = r.i;
|
||||||
queue.queue({e: r.center, p: 0, r: r.i, s: cells.state[r.center], c: r.culture});
|
queue.queue({e: r.center, p: 0, r: r.i, s: cells.state[r.center], c: r.culture});
|
||||||
cost[r.center] = 1;
|
cost[r.center] = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
const neutral = (cells.i.length / 5000) * 200 * gauss(1, 0.3, 0.2, 2, 2) * neutralInput.value; // limit cost for organized religions growth
|
const neutral = (cells.i.length / 5000) * 200 * gauss(1, 0.3, 0.2, 2, 2) * neutralInput.value; // limit cost for organized religions growth
|
||||||
const popCost = d3.max(cells.pop) / 3; // enougth population to spered religion without penalty
|
const popCost = d3.max(cells.pop) / 3; // enougth population to spered religion without penalty
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const {e, p, r, c, s} = queue.dequeue();
|
const {e, p, r, c, s} = queue.dequeue();
|
||||||
const expansion = pack.religions[r].expansion;
|
const expansion = religions[r].expansion;
|
||||||
|
|
||||||
cells.c[e].forEach(nextCell => {
|
cells.c[e].forEach(nextCell => {
|
||||||
if (expansion === "culture" && c !== cells.culture[nextCell]) return;
|
if (expansion === "culture" && c !== cells.culture[nextCell]) return;
|
||||||
if (expansion === "state" && s !== cells.state[nextCell]) return;
|
if (expansion === "state" && s !== cells.state[nextCell]) return;
|
||||||
if (pack.religions[religionIds[nextCell]]?.lock) return;
|
if (religions[religionIds[nextCell]]?.lock) return;
|
||||||
|
|
||||||
const cultureCost = c !== cells.culture[nextCell] ? 10 : 0;
|
const cultureCost = c !== cells.culture[nextCell] ? 10 : 0;
|
||||||
const stateCost = s !== cells.state[nextCell] ? 10 : 0;
|
const stateCost = s !== cells.state[nextCell] ? 10 : 0;
|
||||||
const biomeCost = cells.road[nextCell] ? 1 : biomesData.cost[cells.biome[nextCell]];
|
const biomeCost = cells.road[nextCell] ? 1 : biomesData.cost[cells.biome[nextCell]];
|
||||||
const populationCost = Math.max(rn(popCost - cells.pop[nextCell]), 0);
|
const populationCost = Math.max(rn(popCost - cells.pop[nextCell]), 0);
|
||||||
const heightCost = Math.max(cells.h[nextCell], 20) - 20;
|
const heightCost = Math.max(cells.h[nextCell], 20) - 20;
|
||||||
const waterCost = cells.h[nextCell] < 20 ? (cells.road[nextCell] ? 50 : 1000) : 0;
|
const waterCost = cells.h[nextCell] < 20 ? (cells.road[nextCell] ? 50 : 1000) : 0;
|
||||||
const totalCost =
|
const totalCost =
|
||||||
p +
|
p +
|
||||||
(cultureCost + stateCost + biomeCost + populationCost + heightCost + waterCost) / pack.religions[r].expansionism;
|
(cultureCost + stateCost + biomeCost + populationCost + heightCost + waterCost) / religions[r].expansionism;
|
||||||
if (totalCost > neutral) return;
|
if (totalCost > neutral) return;
|
||||||
|
|
||||||
if (!cost[nextCell] || totalCost < cost[nextCell]) {
|
if (!cost[nextCell] || totalCost < cost[nextCell]) {
|
||||||
if (cells.h[nextCell] >= 20 && cells.culture[nextCell]) religionIds[nextCell] = r; // assign religion to cell
|
if (cells.h[nextCell] >= 20 && cells.culture[nextCell]) religionIds[nextCell] = r; // assign religion to cell
|
||||||
cost[nextCell] = totalCost;
|
cost[nextCell] = totalCost;
|
||||||
queue.queue({e: nextCell, p: totalCost, r, c, s});
|
queue.queue({e: nextCell, p: totalCost, r, c, s});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// growth algorithm to assign cells to heresies
|
|
||||||
function expandHeresies() {
|
|
||||||
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
|
|
||||||
const cost = [];
|
|
||||||
const religionIds = pack.cells.religion;
|
|
||||||
const cells = pack.cells;
|
|
||||||
|
|
||||||
pack.religions
|
|
||||||
.filter(r => !r.lock && r.type === "Heresy")
|
|
||||||
.forEach(r => {
|
|
||||||
const b = religionIds[r.center]; // "base" religion id
|
|
||||||
religionIds[r.center] = r.i; // heresy id
|
|
||||||
queue.queue({e: r.center, p: 0, r: r.i, b});
|
|
||||||
cost[r.center] = 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
const neutral = (cells.i.length / 5000) * 500 * neutralInput.value; // limit cost for heresies growth
|
|
||||||
|
|
||||||
while (queue.length) {
|
|
||||||
const {e, p, r, b} = queue.dequeue();
|
|
||||||
|
|
||||||
cells.c[e].forEach(nextCell => {
|
|
||||||
if (pack.religions[religionIds[nextCell]]?.lock) return;
|
|
||||||
const religionCost = religionIds[nextCell] === b ? 0 : 2000;
|
|
||||||
const biomeCost = cells.road[nextCell] ? 0 : biomesData.cost[cells.biome[nextCell]];
|
|
||||||
const heightCost = Math.max(cells.h[nextCell], 20) - 20;
|
|
||||||
const waterCost = cells.h[nextCell] < 20 ? (cells.road[nextCell] ? 50 : 1000) : 0;
|
|
||||||
const totalCost =
|
|
||||||
p + (religionCost + biomeCost + heightCost + waterCost) / Math.max(pack.religions[r].expansionism, 0.1);
|
|
||||||
|
|
||||||
if (totalCost > neutral) return;
|
|
||||||
|
|
||||||
if (!cost[nextCell] || totalCost < cost[nextCell]) {
|
|
||||||
if (cells.h[nextCell] >= 20 && cells.culture[nextCell]) religionIds[nextCell] = r; // assign religion to cell
|
|
||||||
cost[nextCell] = totalCost;
|
|
||||||
queue.queue({e: nextCell, p: totalCost, r});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkReligionCenters() {
|
|
||||||
pack.religions.forEach(r => {
|
|
||||||
if (!r.i) return;
|
|
||||||
// move religion center if it's not within religion area after expansion
|
|
||||||
if (r.type==="Folk" || pack.cells.religion[r.center] === r.i) return; // in area, or non-expanding
|
|
||||||
const firstCell = pack.cells.i.find(i => pack.cells.religion[i] === r.i);
|
|
||||||
if (firstCell) r.center = firstCell; // move center, othervise it's an extinct religion
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// growth algorithm to assign cells to heresies
|
||||||
|
function expandHeresies() {
|
||||||
|
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
|
||||||
|
const cost = [];
|
||||||
|
const religionIds = pack.cells.religion;
|
||||||
|
const {cells, religions} = pack;
|
||||||
|
|
||||||
|
religions
|
||||||
|
.filter(r => !r.lock && r.type === "Heresy")
|
||||||
|
.forEach(r => {
|
||||||
|
const b = religionIds[r.center]; // "base" religion id
|
||||||
|
religionIds[r.center] = r.i; // heresy id
|
||||||
|
queue.queue({e: r.center, p: 0, r: r.i, b});
|
||||||
|
cost[r.center] = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
const neutral = (cells.i.length / 5000) * 500 * neutralInput.value; // limit cost for heresies growth
|
||||||
|
|
||||||
|
while (queue.length) {
|
||||||
|
const {e, p, r, b} = queue.dequeue();
|
||||||
|
|
||||||
|
cells.c[e].forEach(nextCell => {
|
||||||
|
if (religions[religionIds[nextCell]]?.lock) return;
|
||||||
|
const religionCost = religionIds[nextCell] === b ? 0 : 2000;
|
||||||
|
const biomeCost = cells.road[nextCell] ? 0 : biomesData.cost[cells.biome[nextCell]];
|
||||||
|
const heightCost = Math.max(cells.h[nextCell], 20) - 20;
|
||||||
|
const waterCost = cells.h[nextCell] < 20 ? (cells.road[nextCell] ? 50 : 1000) : 0;
|
||||||
|
const totalCost =
|
||||||
|
p + (religionCost + biomeCost + heightCost + waterCost) / Math.max(religions[r].expansionism, 0.1);
|
||||||
|
|
||||||
|
if (totalCost > neutral) return;
|
||||||
|
|
||||||
|
if (!cost[nextCell] || totalCost < cost[nextCell]) {
|
||||||
|
if (cells.h[nextCell] >= 20 && cells.culture[nextCell]) religionIds[nextCell] = r; // assign religion to cell
|
||||||
|
cost[nextCell] = totalCost;
|
||||||
|
queue.queue({e: nextCell, p: totalCost, r});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkCenters() {
|
||||||
|
const cells = pack.cells;
|
||||||
|
pack.religions.forEach(r => {
|
||||||
|
if (!r.i) return;
|
||||||
|
// move religion center if it's not within religion area after expansion
|
||||||
|
if (r.type==="Folk" || cells.religion[r.center] === r.i) return; // in area, or non-expanding
|
||||||
|
const firstCell = cells.i.find(i => cells.religion[i] === r.i);
|
||||||
|
if (firstCell) r.center = firstCell; // move center, othervise it's an extinct religion
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function recalculate() {
|
||||||
|
const {religion, culture} = pack.cells;
|
||||||
|
// start with the culutres map, but also keep locked religions
|
||||||
|
for(const i of pack.cells.i){
|
||||||
|
if( !pack.religions[religion[i]]?.lock ){
|
||||||
|
religion[i] = culture[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expandReligions();
|
||||||
|
expandHeresies();
|
||||||
|
|
||||||
|
checkCenters();
|
||||||
|
}
|
||||||
|
|
||||||
const add = function (center) {
|
const add = function (center) {
|
||||||
const {cells, religions} = pack;
|
const {cells, religions} = pack;
|
||||||
const religionId = cells.religion[center];
|
const religionId = cells.religion[center];
|
||||||
|
|
@ -717,7 +733,7 @@ window.Religions = (function () {
|
||||||
form: formName,
|
form: formName,
|
||||||
deity,
|
deity,
|
||||||
expansion,
|
expansion,
|
||||||
expansionism: 0.01,
|
expansionism: 0,
|
||||||
center,
|
center,
|
||||||
cells: 0,
|
cells: 0,
|
||||||
area: 0,
|
area: 0,
|
||||||
|
|
@ -759,10 +775,12 @@ window.Religions = (function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
if(c.i < religions.length){
|
if(c.i < religions.length){
|
||||||
|
// 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) {
|
||||||
const newId = religions.length;
|
const newId = religions.length;
|
||||||
rCargo.i = newId;
|
rCargo.i = newId;
|
||||||
|
|
||||||
for(const i of cells.i) {
|
for(const i of cells.i) {
|
||||||
if(cells.religion[i] = c.i) {
|
if(cells.religion[i] = c.i) {
|
||||||
cells.religion[i] = newId;
|
cells.religion[i] = newId;
|
||||||
|
|
@ -776,8 +794,10 @@ window.Religions = (function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
religions.push(rCargo);
|
religions.push(rCargo);
|
||||||
}
|
}
|
||||||
|
|
||||||
religions[c.i] = newFolk;
|
religions[c.i] = newFolk;
|
||||||
} else {
|
} else {
|
||||||
religions.push(newFolk);
|
religions.push(newFolk);
|
||||||
|
|
@ -788,11 +808,14 @@ window.Religions = (function () {
|
||||||
TIME && console.time("updateCulturesForReligions");
|
TIME && console.time("updateCulturesForReligions");
|
||||||
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) 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
|
if(r.removed) addFolk(pack.cultures[r.i].center); // regnerate folk religions for the regenerated cultures
|
||||||
else r.center = pack.cultures[r.i].center;
|
else r.center = pack.cultures[r.i].center;
|
||||||
}
|
}
|
||||||
|
// set new namebase culture
|
||||||
else r.culture = pack.cells.culture[r.center];
|
else r.culture = pack.cells.culture[r.center];
|
||||||
});
|
});
|
||||||
TIME && console.timeEnd("updateCulturesForReligions");
|
TIME && console.timeEnd("updateCulturesForReligions");
|
||||||
|
|
@ -874,15 +897,5 @@ window.Religions = (function () {
|
||||||
return type() + " of the " + generateMeaning();
|
return type() + " of the " + generateMeaning();
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetUnlockedReligions = function() {
|
return {generate, add, addFolk, getDeityName, updateCultures, recalculate};
|
||||||
const {religion, culture} = pack.cells;
|
|
||||||
|
|
||||||
for(const i of pack.cells.i){
|
|
||||||
if( !pack.religions[religion[i]]?.lock ){
|
|
||||||
religion[i] = culture[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return {generate, expandReligions, expandHeresies, checkReligionCenters, add, addFolk, getDeityName, updateCultures, resetUnlockedReligions};
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue