Merge pull request #687 from Azgaar/mfcg-population

MFCG population
This commit is contained in:
Azgaar 2021-10-17 12:06:01 +03:00 committed by GitHub
commit 8bf2dd25b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 3 deletions

View file

@ -3214,6 +3214,12 @@
<input id="urbanizationOutput" data-stored="urbanization" type="range" min=.01 max=5 step=.01 value=1 > <input id="urbanizationOutput" data-stored="urbanization" type="range" min=.01 max=5 step=.01 value=1 >
<input id="urbanizationInput" data-stored="urbanization" type="number" min=.01 max=5 step=.01 value=1 > <input id="urbanizationInput" data-stored="urbanization" type="number" min=.01 max=5 step=.01 value=1 >
</div> </div>
<div data-tip="Set urban density: average population per building in Medieval Fantasy City Generator">
<div>Urban density:</div>
<input id="urbanDensityOutput" data-stored="urbanDensity" type="range" min=1 max=200 step=1 value=10 >
<input id="urbanDensityInput" data-stored="urbanDensity" type="number" min=1 max=200 step=1 value=10 >
</div>
</div> </div>
<div id="unitsBottom"> <div id="unitsBottom">

View file

@ -155,6 +155,7 @@ let options = {
let mapCoordinates = {}; // map coordinates on globe let mapCoordinates = {}; // map coordinates on globe
let populationRate = +document.getElementById("populationRateInput").value; let populationRate = +document.getElementById("populationRateInput").value;
let urbanization = +document.getElementById("urbanizationInput").value; let urbanization = +document.getElementById("urbanizationInput").value;
let urbanDensity = +document.getElementById("urbanDensityInput").value;
applyStoredOptions(); applyStoredOptions();

View file

@ -231,6 +231,7 @@ function parseLoadedData(data) {
if (settings[21]) hideLabels.checked = +settings[21]; if (settings[21]) hideLabels.checked = +settings[21];
if (settings[22]) stylePreset.value = settings[22]; if (settings[22]) stylePreset.value = settings[22];
if (settings[23]) rescaleLabels.checked = +settings[23]; if (settings[23]) rescaleLabels.checked = +settings[23];
if (settings[24]) urbanDensity = urbanDensity.value = urbanDensityOutput.value = +settings[24];
})(); })();
void (function parseConfiguration() { void (function parseConfiguration() {

View file

@ -33,7 +33,8 @@ function getMapData() {
mapName.value, mapName.value,
+hideLabels.checked, +hideLabels.checked,
stylePreset.value, stylePreset.value,
+rescaleLabels.checked +rescaleLabels.checked,
urbanDensity
].join("|"); ].join("|");
const coords = JSON.stringify(mapCoordinates); const coords = JSON.stringify(mapCoordinates);
const biomes = [biomesData.color, biomesData.habitability, biomesData.name].join("|"); const biomes = [biomesData.color, biomesData.habitability, biomesData.name].join("|");

View file

@ -408,7 +408,6 @@ function editBurg(id) {
document.getElementById("mfcgPreview").setAttribute("src", mfcgURL); document.getElementById("mfcgPreview").setAttribute("src", mfcgURL);
document.getElementById("mfcgLink").setAttribute("href", mfcgURL); document.getElementById("mfcgLink").setAttribute("href", mfcgURL);
} }
function getBurgSeed(burg) { function getBurgSeed(burg) {
return burg.MFCG || Number(`${seed}${String(burg.i).padStart(4, 0)}`); return burg.MFCG || Number(`${seed}${String(burg.i).padStart(4, 0)}`);
} }
@ -417,7 +416,8 @@ function editBurg(id) {
const {cells} = pack; const {cells} = pack;
const {name, population, cell} = burg; const {name, population, cell} = burg;
const burgSeed = getBurgSeed(burg); const burgSeed = getBurgSeed(burg);
const size = minmax(rn(population), 6, 100); const sizeRaw = 2.13 * Math.pow((population * populationRate) / urbanDensity, 0.385);
const size = minmax(Math.ceil(sizeRaw), 6, 100);
const people = rn(population * populationRate * urbanization); const people = rn(population * populationRate * urbanization);
const hub = +cells.road[cell] > 50; const hub = +cells.road[cell] > 50;

View file

@ -31,6 +31,8 @@ function editUnits() {
document.getElementById("populationRateInput").addEventListener("change", changePopulationRate); document.getElementById("populationRateInput").addEventListener("change", changePopulationRate);
document.getElementById("urbanizationOutput").addEventListener("input", changeUrbanizationRate); document.getElementById("urbanizationOutput").addEventListener("input", changeUrbanizationRate);
document.getElementById("urbanizationInput").addEventListener("change", changeUrbanizationRate); document.getElementById("urbanizationInput").addEventListener("change", changeUrbanizationRate);
document.getElementById("urbanDensityOutput").addEventListener("input", changeUrbanDensity);
document.getElementById("urbanDensityInput").addEventListener("change", changeUrbanDensity);
document.getElementById("addLinearRuler").addEventListener("click", addRuler); document.getElementById("addLinearRuler").addEventListener("click", addRuler);
document.getElementById("addOpisometer").addEventListener("click", toggleOpisometerMode); document.getElementById("addOpisometer").addEventListener("click", toggleOpisometerMode);
@ -93,6 +95,10 @@ function editUnits() {
urbanization = +this.value; urbanization = +this.value;
} }
function changeUrbanDensity() {
urbanDensity = +this.value;
}
function restoreDefaultUnits() { function restoreDefaultUnits() {
// distanceScale // distanceScale
document.getElementById("distanceScaleOutput").value = 3; document.getElementById("distanceScaleOutput").value = 3;
@ -135,8 +141,10 @@ function editUnits() {
// population // population
populationRate = populationRateOutput.value = populationRateInput.value = 1000; populationRate = populationRateOutput.value = populationRateInput.value = 1000;
urbanization = urbanizationOutput.value = urbanizationInput.value = 1; urbanization = urbanizationOutput.value = urbanizationInput.value = 1;
urbanDensity = urbanDensityOutput.value = urbanDensityInput.value = 10;
localStorage.removeItem("populationRate"); localStorage.removeItem("populationRate");
localStorage.removeItem("urbanization"); localStorage.removeItem("urbanization");
localStorage.removeItem("urbanDensity");
} }
function addRuler() { function addRuler() {