mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +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
|
|
@ -526,39 +526,37 @@ window.Cultures = (function () {
|
|||
|
||||
for (const culture of cultures) {
|
||||
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) {
|
||||
const {e, p, c} = queue.dequeue();
|
||||
const {type} = pack.cultures[c];
|
||||
const {cellId, priority, cultureId} = queue.dequeue();
|
||||
const {type, expansionism} = pack.cultures[cultureId];
|
||||
|
||||
cells.c[e].forEach(e => {
|
||||
const culture = cells.culture[e];
|
||||
if (culture?.lock) return; // do not overwrite cell of locked culture
|
||||
cells.c[cellId].forEach(neibCellId => {
|
||||
const neibCultureId = cells.culture[neibCellId];
|
||||
if (neibCultureId && pack.cultures[neibCultureId].lock) return; // do not overwrite cell of locked culture
|
||||
|
||||
const biome = cells.biome[e];
|
||||
const biomeCost = getBiomeCost(c, biome, type);
|
||||
const biomeChangeCost = biome === cells.biome[e] ? 0 : 20; // penalty on biome change
|
||||
const heightCost = getHeightCost(e, cells.h[e], type);
|
||||
const riverCost = getRiverCost(cells.r[e], e, type);
|
||||
const typeCost = getTypeCost(cells.t[e], type);
|
||||
const totalCost =
|
||||
p + (biomeCost + biomeChangeCost + heightCost + riverCost + typeCost) / pack.cultures[c].expansionism;
|
||||
const biome = cells.biome[neibCellId];
|
||||
const biomeCost = getBiomeCost(cultureId, biome, type);
|
||||
const biomeChangeCost = biome === cells.biome[neibCellId] ? 0 : 20; // penalty on biome change
|
||||
const heightCost = getHeightCost(neibCellId, cells.h[neibCellId], type);
|
||||
const riverCost = getRiverCost(cells.r[neibCellId], neibCellId, type);
|
||||
const typeCost = getTypeCost(cells.t[neibCellId], type);
|
||||
|
||||
const totalCost = priority + (biomeCost + biomeChangeCost + heightCost + riverCost + typeCost) / expansionism;
|
||||
if (Number.isNaN(totalCost)) debugger;
|
||||
|
||||
if (totalCost > neutral) return;
|
||||
|
||||
if (!cost[e] || totalCost < cost[e]) {
|
||||
if (cells.s[e] > 0) cells.culture[e] = c; // assign culture to populated cell
|
||||
cost[e] = totalCost;
|
||||
queue.queue({e, p: totalCost, c});
|
||||
if (!cost[neibCellId] || totalCost < cost[neibCellId]) {
|
||||
if (cells.s[neibCellId] > 0) cells.culture[neibCellId] = cultureId; // assign culture to populated cell
|
||||
cost[neibCellId] = totalCost;
|
||||
queue.queue({cellId: neibCellId, cultureId, priority: totalCost});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TIME && console.timeEnd("expandCultures");
|
||||
};
|
||||
|
||||
function getBiomeCost(c, biome, type) {
|
||||
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
|
||||
|
|
@ -581,10 +579,10 @@ window.Cultures = (function () {
|
|||
return 0;
|
||||
}
|
||||
|
||||
function getRiverCost(r, i, type) {
|
||||
if (type === "River") return r ? 0 : 100; // penalty for river cultures
|
||||
if (!r) 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
|
||||
function getRiverCost(riverId, cellId, type) {
|
||||
if (type === "River") return riverId ? 0 : 100; // penalty for river cultures
|
||||
if (!riverId) return 0; // no penalty for others if there is no river
|
||||
return minmax(cells.fl[cellId] / 10, 20, 100); // river penalty from 20 to 100 based on flux
|
||||
}
|
||||
|
||||
function getTypeCost(t, type) {
|
||||
|
|
@ -594,6 +592,9 @@ window.Cultures = (function () {
|
|||
return 0;
|
||||
}
|
||||
|
||||
TIME && console.timeEnd("expandCultures");
|
||||
};
|
||||
|
||||
const getRandomShield = function () {
|
||||
const type = rw(COA.shields.types);
|
||||
return rw(COA.shields[type]);
|
||||
|
|
|
|||
|
|
@ -670,14 +670,14 @@ async function showHierarchy() {
|
|||
});
|
||||
}
|
||||
|
||||
function recalculateCultures(must) {
|
||||
if (!must && !culturesAutoChange.checked) return;
|
||||
|
||||
function recalculateCultures(force) {
|
||||
if (force || culturesAutoChange.checked) {
|
||||
Cultures.expand();
|
||||
drawCultures();
|
||||
pack.burgs.forEach(b => (b.culture = pack.cells.culture[b.cell]));
|
||||
refreshCulturesEditor();
|
||||
}
|
||||
}
|
||||
|
||||
function enterCultureManualAssignent() {
|
||||
if (!layerIsOn("toggleCultures")) toggleCultures();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue