Merge branch 'master' into faith-update

This commit is contained in:
Alexander James 2023-02-23 13:32:19 -07:00 committed by GitHub
commit fc1b99762e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 70 additions and 44 deletions

View file

@ -116,10 +116,10 @@ window.Cultures = (function () {
cultures.forEach(c => (c.base = c.base % nameBases.length));
function selectCultures(c) {
let def = getDefault(c);
function selectCultures(culturesNumber) {
let def = getDefault(culturesNumber);
const cultures = [];
pack.cultures?.forEach(function (culture) {
if (culture.lock) cultures.push(culture);
});
@ -153,8 +153,8 @@ window.Cultures = (function () {
}
}
} else {
if (c === def.length) return def;
if (def.every(d => d.odd === 1)) return def.splice(0, c);
if (culturesNumber === def.length) return def;
if (def.every(d => d.odd === 1)) return def.splice(0, culturesNumber);
if (pack.religions?.length > 2) {
pack.religions.forEach(r => {
if (r.type === "Folk" && !r.lock) r.removed = true;
@ -162,7 +162,7 @@ window.Cultures = (function () {
}
}
for (let culture, rnd, i = 0; cultures.length < c && def.length > 0;) {
for (let culture, rnd, i = 0; cultures.length < culturesNumber && def.length > 0;) {
do {
rnd = rand(def.length - 1);
culture = def[rnd];
@ -542,28 +542,37 @@ window.Cultures = (function () {
// expand cultures across the map (Dijkstra-like algorithm)
const expand = function () {
TIME && console.time("expandCultures");
cells = pack.cells;
const {cells, cultures} = pack;
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
pack.cultures.forEach(function (c) {
if (!c.i || c.removed || c.lock) return;
queue.queue({e: c.center, p: 0, c: c.i});
});
const neutral = (cells.i.length / 5000) * 3000 * neutralInput.value; // limit cost for culture growth
const cost = [];
const neutralRate = byId("neutralRate")?.valueAsNumber || 1;
const neutral = cells.i.length * 0.6 * neutralRate; // limit cost for culture growth
// remove culture from all cells except of locked
for (const cellId of cells.i) {
const culture = cultures[cells.culture[cellId]];
if (culture.lock) continue;
cells.culture[cellId] = 0;
}
for (const culture of cultures) {
if (!culture.i || culture.removed) continue;
queue.queue({e: culture.center, p: 0, c: culture.i});
}
while (queue.length) {
const next = queue.dequeue(),
n = next.e,
p = next.p,
c = next.c;
const type = pack.cultures[c].type;
cells.c[n].forEach(e => {
if (pack.cultures[cells.culture[e]]?.lock) return;
const {e, p, c} = queue.dequeue();
const {type} = pack.cultures[c];
cells.c[e].forEach(e => {
const culture = cells.culture[e];
if (culture?.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[n] ? 0 : 20; // penalty on biome change
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);