mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fix(#932): expand cultures to get scoped cells data
This commit is contained in:
parent
1ce379dfb0
commit
fb4d3a4019
2 changed files with 64 additions and 63 deletions
|
|
@ -129,7 +129,7 @@ window.Cultures = (function () {
|
||||||
if (def.every(d => d.odd === 1)) return def.splice(0, culturesNumber);
|
if (def.every(d => d.odd === 1)) return def.splice(0, culturesNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let culture, rnd, i = 0; cultures.length < culturesNumber && def.length > 0;) {
|
for (let culture, rnd, i = 0; cultures.length < culturesNumber && def.length > 0; ) {
|
||||||
do {
|
do {
|
||||||
rnd = rand(def.length - 1);
|
rnd = rand(def.length - 1);
|
||||||
culture = def[rnd];
|
culture = def[rnd];
|
||||||
|
|
@ -526,39 +526,37 @@ window.Cultures = (function () {
|
||||||
|
|
||||||
for (const culture of cultures) {
|
for (const culture of cultures) {
|
||||||
if (!culture.i || culture.removed) continue;
|
if (!culture.i || culture.removed) continue;
|
||||||
queue.queue({e: culture.center, p: 0, c: culture.i});
|
queue.queue({cellId: culture.center, cultureId: culture.i, priority: 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const {e, p, c} = queue.dequeue();
|
const {cellId, priority, cultureId} = queue.dequeue();
|
||||||
const {type} = pack.cultures[c];
|
const {type, expansionism} = pack.cultures[cultureId];
|
||||||
|
|
||||||
cells.c[e].forEach(e => {
|
cells.c[cellId].forEach(neibCellId => {
|
||||||
const culture = cells.culture[e];
|
const neibCultureId = cells.culture[neibCellId];
|
||||||
if (culture?.lock) return; // do not overwrite cell of locked culture
|
if (neibCultureId && pack.cultures[neibCultureId].lock) return; // do not overwrite cell of locked culture
|
||||||
|
|
||||||
const biome = cells.biome[e];
|
const biome = cells.biome[neibCellId];
|
||||||
const biomeCost = getBiomeCost(c, biome, type);
|
const biomeCost = getBiomeCost(cultureId, biome, type);
|
||||||
const biomeChangeCost = biome === cells.biome[e] ? 0 : 20; // penalty on biome change
|
const biomeChangeCost = biome === cells.biome[neibCellId] ? 0 : 20; // penalty on biome change
|
||||||
const heightCost = getHeightCost(e, cells.h[e], type);
|
const heightCost = getHeightCost(neibCellId, cells.h[neibCellId], type);
|
||||||
const riverCost = getRiverCost(cells.r[e], e, type);
|
const riverCost = getRiverCost(cells.r[neibCellId], neibCellId, type);
|
||||||
const typeCost = getTypeCost(cells.t[e], type);
|
const typeCost = getTypeCost(cells.t[neibCellId], type);
|
||||||
const totalCost =
|
|
||||||
p + (biomeCost + biomeChangeCost + heightCost + riverCost + typeCost) / pack.cultures[c].expansionism;
|
const totalCost = priority + (biomeCost + biomeChangeCost + heightCost + riverCost + typeCost) / expansionism;
|
||||||
|
if (Number.isNaN(totalCost)) debugger;
|
||||||
|
|
||||||
if (totalCost > neutral) return;
|
if (totalCost > neutral) return;
|
||||||
|
|
||||||
if (!cost[e] || totalCost < cost[e]) {
|
if (!cost[neibCellId] || totalCost < cost[neibCellId]) {
|
||||||
if (cells.s[e] > 0) cells.culture[e] = c; // assign culture to populated cell
|
if (cells.s[neibCellId] > 0) cells.culture[neibCellId] = cultureId; // assign culture to populated cell
|
||||||
cost[e] = totalCost;
|
cost[neibCellId] = totalCost;
|
||||||
queue.queue({e, p: totalCost, c});
|
queue.queue({cellId: neibCellId, cultureId, priority: totalCost});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TIME && console.timeEnd("expandCultures");
|
|
||||||
};
|
|
||||||
|
|
||||||
function getBiomeCost(c, biome, type) {
|
function getBiomeCost(c, biome, type) {
|
||||||
if (cells.biome[pack.cultures[c].center] === biome) return 10; // tiny penalty for native biome
|
if (cells.biome[pack.cultures[c].center] === biome) return 10; // tiny penalty for native biome
|
||||||
if (type === "Hunting") return biomesData.cost[biome] * 5; // non-native biome penalty for hunters
|
if (type === "Hunting") return biomesData.cost[biome] * 5; // non-native biome penalty for hunters
|
||||||
|
|
@ -581,10 +579,10 @@ window.Cultures = (function () {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRiverCost(r, i, type) {
|
function getRiverCost(riverId, cellId, type) {
|
||||||
if (type === "River") return r ? 0 : 100; // penalty for river cultures
|
if (type === "River") return riverId ? 0 : 100; // penalty for river cultures
|
||||||
if (!r) return 0; // no penalty for others if there is no river
|
if (!riverId) return 0; // no penalty for others if there is no river
|
||||||
return minmax(cells.fl[i] / 10, 20, 100); // river penalty from 20 to 100 based on flux
|
return minmax(cells.fl[cellId] / 10, 20, 100); // river penalty from 20 to 100 based on flux
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTypeCost(t, type) {
|
function getTypeCost(t, type) {
|
||||||
|
|
@ -594,6 +592,9 @@ window.Cultures = (function () {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TIME && console.timeEnd("expandCultures");
|
||||||
|
};
|
||||||
|
|
||||||
const getRandomShield = function () {
|
const getRandomShield = function () {
|
||||||
const type = rw(COA.shields.types);
|
const type = rw(COA.shields.types);
|
||||||
return rw(COA.shields[type]);
|
return rw(COA.shields[type]);
|
||||||
|
|
|
||||||
|
|
@ -670,13 +670,13 @@ async function showHierarchy() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function recalculateCultures(must) {
|
function recalculateCultures(force) {
|
||||||
if (!must && !culturesAutoChange.checked) return;
|
if (force || culturesAutoChange.checked) {
|
||||||
|
|
||||||
Cultures.expand();
|
Cultures.expand();
|
||||||
drawCultures();
|
drawCultures();
|
||||||
pack.burgs.forEach(b => (b.culture = pack.cells.culture[b.cell]));
|
pack.burgs.forEach(b => (b.culture = pack.cells.culture[b.cell]));
|
||||||
refreshCulturesEditor();
|
refreshCulturesEditor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterCultureManualAssignent() {
|
function enterCultureManualAssignent() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue