From 207b56418072c5fff70fa79acc544e4258e4e82d Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 16 Jan 2022 14:54:30 +0300 Subject: [PATCH] improve MFCG link generation --- modules/burgs-and-states.js | 7 ++++--- modules/ui/burg-editor.js | 11 ++++++----- modules/ui/editors.js | 38 +++++++++++++++++++++++-------------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js index 142b48c6..a76fa182 100644 --- a/modules/burgs-and-states.js +++ b/modules/burgs-and-states.js @@ -240,7 +240,7 @@ window.BurgsAndStates = (function () { b.citadel = b.capital || (pop > 50 && P(0.75)) || P(0.5) ? 1 : 0; b.plaza = pop > 50 || (pop > 30 && P(0.75)) || (pop > 10 && P(0.5)) || P(0.25) ? 1 : 0; b.walls = b.capital || pop > 30 || (pop > 20 && P(0.75)) || (pop > 10 && P(0.5)) || P(0.2) ? 1 : 0; - b.shanty = pop > 30 || (pop > 20 && P(0.75)) || (b.walls && P(0.75)) ? 1 : 0; + b.shanty = pop > 60 || (pop > 40 && P(0.75)) || (pop > 20 && b.walls && P(0.4)) ? 1 : 0; const religion = cells.religion[b.cell]; const theocracy = pack.states[b.state].form === "Theocracy"; b.temple = (religion && theocracy) || pop > 50 || (pop > 35 && P(0.75)) || (pop > 20 && P(0.5)) ? 1 : 0; @@ -1037,7 +1037,8 @@ window.BurgsAndStates = (function () { if (tier < 2 && P(0.5)) return "Diocese"; if (tier < 2 && P(0.5)) return "Bishopric"; } - if (P(0.9) && [7, 5].includes(base)) { // Greek, Ruthenian + if (P(0.9) && [7, 5].includes(base)) { + // Greek, Ruthenian if (tier < 2) return "Eparchy"; if (tier === 2) return "Exarchate"; if (tier > 2) return "Patriarchate"; @@ -1097,7 +1098,7 @@ window.BurgsAndStates = (function () { const max = percentage == 100 ? 1000 : gauss(20, 5, 5, 100) * percentage ** 0.5; // max growth const forms = { - Monarchy: {County: 22, Earldom: 6, Shire: 2, Landgrave: 2, Margrave: 2, Barony: 2, Captaincy:1, Seneschalty:1}, + Monarchy: {County: 22, Earldom: 6, Shire: 2, Landgrave: 2, Margrave: 2, Barony: 2, Captaincy: 1, Seneschalty: 1}, Republic: {Province: 6, Department: 2, Governorate: 2, District: 1, Canton: 1, Prefecture: 1}, Theocracy: {Parish: 3, Deanery: 1}, Union: {Province: 1, State: 1, Canton: 1, Republic: 1, County: 1, Council: 1}, diff --git a/modules/ui/burg-editor.js b/modules/ui/burg-editor.js index 2b805c56..1a2bef17 100644 --- a/modules/ui/burg-editor.js +++ b/modules/ui/burg-editor.js @@ -354,17 +354,18 @@ function editBurg(id) { function toggleFeature() { const id = +elSelected.attr("data-id"); - const b = pack.burgs[id]; + const burg = pack.burgs[id]; const feature = this.dataset.feature; const turnOn = this.classList.contains("inactive"); if (feature === "port") togglePort(id); else if (feature === "capital") toggleCapital(id); - else b[feature] = +turnOn; - if (b[feature]) this.classList.remove("inactive"); - else if (!b[feature]) this.classList.add("inactive"); + else burg[feature] = +turnOn; + if (burg[feature]) this.classList.remove("inactive"); + else if (!burg[feature]) this.classList.add("inactive"); - if (b.port) document.getElementById("burgEditAnchorStyle").style.display = "inline-block"; + if (burg.port) document.getElementById("burgEditAnchorStyle").style.display = "inline-block"; else document.getElementById("burgEditAnchorStyle").style.display = "none"; + updateMFCGFrame(burg); } function toggleBurgLockButton() { diff --git a/modules/ui/editors.js b/modules/ui/editors.js index 49f9d8c4..3c14c149 100644 --- a/modules/ui/editors.js +++ b/modules/ui/editors.js @@ -268,35 +268,45 @@ function getMFCGlink(burg) { if (burg.link) return burg.link; const {cells} = pack; - const {name, population, cell} = burg; - const burgSeed = getBurgSeed(burg); - const sizeRaw = 2.13 * Math.pow((population * populationRate) / urbanDensity, 0.385); + const {i, name, population: burgPopulation, cell} = burg; + const seed = getBurgSeed(burg); + + const sizeRaw = 2.13 * Math.pow((burgPopulation * populationRate) / urbanDensity, 0.385); const size = minmax(Math.ceil(sizeRaw), 6, 100); - const people = rn(population * populationRate * urbanization); + const population = rn(burgPopulation * populationRate * urbanization); + + const river = cells.r[cell] ? 1 : 0; + const coast = Number(burg.port > 0); + const sea = coast && cells.haven[cell] ? getSeaDirections(cell) : null; + + const biome = cells.biome[cell]; + const arableBiomes = river ? [1, 2, 3, 4, 5, 6, 7, 8] : [5, 6, 7, 8]; + const farms = +arableBiomes.includes(biome); + + const citadel = +burg.citadel; + const urban_castle = +(citadel && each(2)(i)); const hub = +cells.road[cell] > 50; - const river = cells.r[cell] ? 1 : 0; - const coast = +burg.port; - const citadel = +burg.citadel; const walls = +burg.walls; const plaza = +burg.plaza; const temple = +burg.temple; - const shanty = +burg.shanty; + const shantytown = +burg.shanty; - const sea = coast && cells.haven[cell] ? getSeaDirections(cell) : ""; function getSeaDirections(i) { const p1 = cells.p[i]; const p2 = cells.p[cells.haven[i]]; let deg = (Math.atan2(p2[1] - p1[1], p2[0] - p1[0]) * 180) / Math.PI - 90; if (deg < 0) deg += 360; - const norm = rn(normalize(deg, 0, 360) * 2, 2); // 0 = south, 0.5 = west, 1 = north, 1.5 = east - return "&sea=" + norm; + return rn(normalize(deg, 0, 360) * 2, 2); // 0 = south, 0.5 = west, 1 = north, 1.5 = east } - const baseURL = "https://watabou.github.io/city-generator/?random=0&continuous=0"; - const url = `${baseURL}&name=${name}&population=${people}&size=${size}&seed=${burgSeed}&hub=${hub}&river=${river}&coast=${coast}&citadel=${citadel}&plaza=${plaza}&temple=${temple}&walls=${walls}&shantytown=${shanty}${sea}`; - return url; + const parameters = {name, population, size, seed, river, coast, farms, citadel, urban_castle, hub, plaza, temple, walls, shantytown, gates: -1}; + const url = new URL("https://watabou.github.io/city-generator"); + url.search = new URLSearchParams(parameters); + if (sea) url.searchParams.append("sea", sea); + + return url.toString(); } // draw legend box