based on suggestions simplified usage of biome usage

This commit is contained in:
ZoltanTheDM 2019-11-10 15:29:50 -08:00
parent d9df7c2f15
commit f6f49fd86b
4 changed files with 32 additions and 31 deletions

View file

@ -292,10 +292,11 @@
burgs.filter(b => b.i && !b.removed).forEach(b => b.state = cells.state[b.cell]); // assign state to burgs
function getBiomeCost(b, biome, type) {
const bio = biomesData.biomeList[biome];
if (b === biome) return 10; // tiny penalty for native biome
if (type === "Hunting") return biomesData.biomeList[biome].cost * 2; // non-native biome penalty for hunters
if (type === "Nomadic" && biome > 4 && biome < 10) return biomesData.biomeList[biome].cost * 3; // forest biome penalty for nomads
return biomesData.biomeList[biome].cost; // general non-native biome penalty
if (type === "Hunting") return bio.cost * 2; // non-native biome penalty for hunters
if (type === "Nomadic" && biome > 4 && biome < 10) return bio.cost * 3; // forest biome penalty for nomads
return bio.cost; // general non-native biome penalty
}
function getHeightCost(f, h, type) {

View file

@ -391,10 +391,11 @@
}
function getBiomeCost(c, biome, type) {
const b = biomesData.biomeList[biome];
if (cells.biome[pack.cultures[c].center] === biome) return 10; // tiny penalty for native biome
if (type === "Hunting") return biomesData.biomeList[biome].cost * 5; // non-native biome penalty for hunters
if (type === "Nomadic" && biome > 4 && biome < 10) return biomesData.biomeList[biome].cost * 10; // forest biome penalty for nomads
return biomesData.biomeList[biome].cost * 2; // general non-native biome penalty
if (type === "Hunting") return b.cost * 5; // non-native biome penalty for hunters
if (type === "Nomadic" && biome > 4 && biome < 10) return b.cost * 10; // forest biome penalty for nomads
return b.cost * 2; // general non-native biome penalty
}
function getHeightCost(i, h, type) {

View file

@ -17,23 +17,23 @@
const height = cells.h[i];
if (height < 20) continue; // no icons on water
if (cells.r[i]) continue; // no icons on rivers
const b = cells.biome[i];
if (height < 50 && biomesData.biomeList[b].icons.density === 0) continue; // no icons for this biome
const b = biomesData.biomeList[cells.biome[i]];
if (height < 50 && b.icons.density === 0) continue; // no icons for this biome
const polygon = getPackPolygon(i);
const x = d3.extent(polygon, p => p[0]), y = d3.extent(polygon, p => p[1]);
const e = [Math.ceil(x[0]), Math.ceil(y[0]), Math.floor(x[1]), Math.floor(y[1])]; // polygon box
if (height < 50) placeBiomeIcons(i, b); else placeReliefIcons(i);
if (height < 50) placeBiomeIcons(); else placeReliefIcons(i);
function placeBiomeIcons() {
const iconsDensity = biomesData.biomeList[b].icons.density / 100;
const iconsDensity = b.icons.density / 100;
const radius = 2 / iconsDensity / density;
if (Math.random() > iconsDensity * 10) return;
for (const [cx, cy] of poissonDiscSampler(e[0], e[1], e[2], e[3], radius)) {
if (!d3.polygonContains(polygon, [cx, cy])) continue;
let h = rn((4 + Math.random()) * size, 2);
const icon = getBiomeIcon(i, biomesData.biomeList[b].icons.probability);
const icon = getBiomeIcon(i, b.icons.probability);
if (icon === "#relief-grass-1") h *= 1.3;
relief.push({i: icon, x: rn(cx-h, 2), y: rn(cy-h, 2), s: h*2});
}

View file

@ -117,45 +117,44 @@ function editBiomes() {
function biomeHighlightOn(event) {
if (customization === 6) return;
const biome = +event.target.dataset.id;
biomes.select("#biome"+biome).raise().transition(animate).attr("stroke-width", 2).attr("stroke", "#cd4c11");
const biome = biomesData.biomeList[+event.target.dataset.id];
biomes.select("#biome"+biome.id).raise().transition(animate).attr("stroke-width", 2).attr("stroke", "#cd4c11");
}
function biomeHighlightOff(event) {
if (customization === 6) return;
const biome = +event.target.dataset.id;
const color = biomesData.biomeList[biome].color;
biomes.select("#biome"+biome).transition().attr("stroke-width", .7).attr("stroke", color);
const biome = biomesData.biomeList[+event.target.dataset.id];
biomes.select("#biome"+biome.id).transition().attr("stroke-width", .7).attr("stroke", biome.color);
}
function biomeChangeColor(el) {
const currentFill = el.getAttribute("fill");
const biome = +el.parentNode.parentNode.dataset.id;
const biome = biomesData.biomeList[+el.parentNode.parentNode.dataset.id];
const callback = function(fill) {
el.setAttribute("fill", fill);
biomesData.biomeList[biome].color = fill;
biomes.select("#biome"+biome).attr("fill", fill).attr("stroke", fill);
biome.color = fill;
biomes.select("#biome"+biome.id).attr("fill", biome.color).attr("stroke", fill);
}
openPicker(currentFill, callback);
}
function biomeChangeName(el) {
const biome = +el.parentNode.dataset.id;
const biome = biomesData.biomeList[+el.parentNode.dataset.id];
el.parentNode.dataset.name = el.value;
biomesData.biomeList[biome].name = el.value;
biome.name = el.value;
}
function biomeChangeHabitability(el) {
const biome = +el.parentNode.dataset.id;
const biome = biomesData.biomeList[+el.parentNode.dataset.id];
const failed = isNaN(+el.value) || +el.value < 0 || +el.value > 9999;
if (failed) {
el.value = biomesData.biomeList[biome].habitability;
el.value = biome.habitability;
tip("Please provide a valid number in range 0-9999", false, "error");
return;
}
biomesData.biomeList[biome].habitability = +el.value;
biome.habitability = +el.value;
el.parentNode.dataset.habitability = el.value;
recalculatePopulation();
refreshBiomesEditor();
@ -237,9 +236,9 @@ function editBiomes() {
}
function removeCustomBiome(el) {
const biome = +el.parentNode.dataset.id;
const biome = biomesData.biomeList[+el.parentNode.dataset.id];
el.parentNode.remove();
biomesData.biomeList[biome].name = "removed";
biome.name = "removed";
biomesFooterBiomes.innerHTML = +biomesFooterBiomes.innerHTML - 1;
}
@ -324,17 +323,17 @@ function editBiomes() {
const temp = biomes.select("#temp");
const selected = body.querySelector("div.selected");
const biomeNew = selected.dataset.id;
const color = biomesData.biomeList[biomeNew].color;
const biomeNew = biomesData.biomeList[+selected.dataset.id];
const color = biomeNew.color;
selection.forEach(function(i) {
const exists = temp.select("polygon[data-cell='"+i+"']");
const biomeOld = exists.size() ? +exists.attr("data-biome") : pack.cells.biome[i];
if (biomeNew === biomeOld) return;
if (biomeNew.id === biomeOld) return;
// change of append new element
if (exists.size()) exists.attr("data-biome", biomeNew).attr("fill", color).attr("stroke", color);
else temp.append("polygon").attr("data-cell", i).attr("data-biome", biomeNew).attr("points", getPackPolygon(i)).attr("fill", color).attr("stroke", color);
if (exists.size()) exists.attr("data-biome", biomeNew.id).attr("fill", color).attr("stroke", color);
else temp.append("polygon").attr("data-cell", i).attr("data-biome", biomeNew.id).attr("points", getPackPolygon(i)).attr("fill", color).attr("stroke", color);
});
}