From a3043f932f8a3fa0872e74b7a46e70196fc0000c Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 8 Aug 2021 13:44:50 +0300 Subject: [PATCH] resource units --- data/resources.js | 2 +- index.html | 10 ++++++++++ main.js | 1 + modules/production-generator.js | 21 ++++++++++++++++++++- modules/ui/burg-editor.js | 30 +++++++++++++++++++----------- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/data/resources.js b/data/resources.js index fa29713e..ddbff606 100644 --- a/data/resources.js +++ b/data/resources.js @@ -535,7 +535,7 @@ window.FMG.data.resourceModels = { Marine_and_rivers: 'shore(-1) && (type("ocean", "freshwater", "salt") || (river() && shore(1, 2)))', Pastures_and_temperate_forest: '(biome(3, 4) && !elevation()) || (biome(6) && random(70)) || (biome(5) && nth(5))', Tropical_forests: 'biome(5, 7)', - Arid_land_and_salt_lakes: 'type("salt", "dry") || (biome(1, 2) && random(70)) || (biome(12) && nth(10))', + Arid_land_and_salt_lakes: 'shore(1) && type("salt", "dry") || (biome(1, 2) && random(70)) || (biome(12) && nth(10))', Hot_desert: 'biome(1)', Deserts: 'biome(1, 2)', Grassland_and_cold_desert: 'biome(3) || (biome(2) && nth(4))', diff --git a/index.html b/index.html index 76ac96a0..ea684864 100644 --- a/index.html +++ b/index.html @@ -2036,6 +2036,16 @@ +
+
Import:
+ +
+ +
+
Consumption:
+ +
+
Temperature:
, like in diff --git a/main.js b/main.js index 83ce726e..96d24b8f 100644 --- a/main.js +++ b/main.js @@ -654,6 +654,7 @@ function generate() { BurgsAndStates.defineStateForms(); Production.collectResources(); + Production.defineExport(); BurgsAndStates.generateProvinces(); BurgsAndStates.defineBurgFeatures(); diff --git a/modules/production-generator.js b/modules/production-generator.js index 61c846b8..3fcc3dad 100644 --- a/modules/production-generator.js +++ b/modules/production-generator.js @@ -110,5 +110,24 @@ window.Production = (function () { } }; - return {collectResources}; + const defineExport = () => { + const {cells, burgs} = pack; + + for (const burg of burgs) { + if (!burg.i || burg.removed) continue; + const {population, production: resourcePool} = burg; + const localUsage = Math.ceil(population); + + const surplus = {}; + for (const resourceId in resourcePool) { + const production = resourcePool[resourceId]; + const extraProduction = production - localUsage; + if (extraProduction > 0) surplus[resourceId] = extraProduction; + } + + burg.export = surplus; + } + }; + + return {collectResources, defineExport}; })(); diff --git a/modules/ui/burg-editor.js b/modules/ui/burg-editor.js index b2ebe09f..72d8d31e 100644 --- a/modules/ui/burg-editor.js +++ b/modules/ui/burg-editor.js @@ -98,17 +98,8 @@ function editBurg(id) { else document.getElementById('burgShanty').classList.add('inactive'); // economics block - let productionHTML = ''; - for (const resourceId in b.production) { - const {name, unit, icon} = Resources.get(+resourceId); - const production = b.production[resourceId]; - const unitName = production > 1 ? unit + 's' : unit; - productionHTML += ` - - ${production} - `; - } - document.getElementById('burgProduction').innerHTML = productionHTML; + document.getElementById('burgProduction').innerHTML = getProduction(b.production); + document.getElementById('burgExport').innerHTML = getProduction(b.export); //toggle lock updateBurgLockIcon(); @@ -128,6 +119,23 @@ function editBurg(id) { document.getElementById('burgEmblem').setAttribute('href', '#' + coaID); } + function getProduction(resources) { + let html = ''; + + for (const resourceId in resources) { + const {name, unit, icon} = Resources.get(+resourceId); + const production = resources[resourceId]; + const unitName = production > 1 ? unit + 's' : unit; + + html += ` + + ${production} + `; + } + + return html; + } + // [-1; 31] °C, source: https://en.wikipedia.org/wiki/List_of_cities_by_average_temperature function getTemperatureLikeness(temperature) { if (temperature < -15) return 'nowhere in the real-world';