From 90a060f0733ca077ea6e81a07e4b60f039d1280e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20H=C3=B6llerich?= Date: Mon, 4 Jan 2021 21:23:05 +0100 Subject: [PATCH] Add need unlock conditions. Minor fixes. Rearrange products. --- AnnoCalculator.js | 86 +++++++++++++++++++++++++++++------ README.md | 2 +- i18n.js | 13 ++++-- index.html | 4 +- params.js | 112 ++++++++++++++++++++++++++++++++++------------ 5 files changed, 168 insertions(+), 49 deletions(-) diff --git a/AnnoCalculator.js b/AnnoCalculator.js index 03afe16..24fb6dd 100644 --- a/AnnoCalculator.js +++ b/AnnoCalculator.js @@ -1,4 +1,4 @@ -let versionCalculator = "v1.1"; +let versionCalculator = "v1.2"; let ACCURACY = 0.01; let EPSILON = 0.0000001; let ALL_ISLANDS = "All Islands"; @@ -325,11 +325,19 @@ class Island { this.residenceBuildings.push(b); } + for (var b of this.residenceBuildings) + if (b.upgradedBuilding) + b.upgradedBuilding = assetsMap.get(parseInt(b.upgradedBuilding)); + for (let level of params.populationLevels) { let l = new PopulationLevel(level, assetsMap); assetsMap.set(l.guid, l); this.populationLevels.push(l); + } + + for (let l of this.populationLevels) { + l.initBans(assetsMap); if (localStorage) { { @@ -402,6 +410,8 @@ class Island { } } + + for (var category of params.productFilter) { let c = new ProductCategory(category, assetsMap); assetsMap.set(c.guid, c); @@ -1150,16 +1160,55 @@ class PopulationNeed extends Need { val = parseFloat(val); if (val <= 0) this.percentBoost(1); - }) + }); this.boost = ko.computed(() => parseInt(this.percentBoost()) / 100); this.boost.subscribe(() => this.updateAmount(this.residents)); this.checked = ko.observable(true); + this.optionalAmount = ko.observable(0); + + } + + initBans(level, assetsMap) { + if (this.unlockCondition) { + var config = this.unlockCondition; + this.locked = ko.computed(() => { + if (!config || !view.settings.needUnlockConditions.checked()) + return false; + + var getAmount = l => view.settings.existingBuildingsInput.checked() + ? parseInt(l.existingBuildings()) * l.fullHouse + : parseInt(l.amount()); + + if (config.populationLevel != level.guid) { + var l = assetsMap.get(config.populationLevel); + var amount = getAmount(l); + return amount < config.amount; + } + + var amount = getAmount(level); + if (amount >= config.amount) + return false; + + var residence = level.residence.upgradedBuilding; + while (residence) { + var l = residence.populationLevel; + var amount = getAmount(l); + if (amount > 0) + return false; + + residence = residence.upgradedBuilding; + } + + return true; + }); + } + this.banned = ko.computed(() => { var checked = this.checked(); - return !checked; - }) - this.optionalAmount = ko.observable(0); + return !checked || + this.locked && this.locked(); + }); this.banned.subscribe(banned => { if (banned) @@ -1244,6 +1293,11 @@ class PopulationLevel extends NamedElement { this.needs = []; this.region = assetsMap.get(config.region); + this.propagatedAmount = ko.computed(() => { + var amount = view.settings.existingBuildingsInput.checked() ? parseInt(this.existingBuildings()) * config.fullHouse : parseInt(this.amount()); + this.needs.forEach(n => n.updateAmount(amount)); + }); + config.needs.forEach(n => { if (n.tpmin > 0 && assetsMap.get(n.guid)) this.needs.push(new PopulationNeed(n, assetsMap)); @@ -1252,19 +1306,13 @@ class PopulationLevel extends NamedElement { this.amount.subscribe(val => { if (val < 0) this.amount(0); - else if (!view.settings.existingBuildingsInput.checked()) - this.needs.forEach(n => n.updateAmount(parseInt(val))) - }); - this.existingBuildings.subscribe(val => { - if (view.settings.existingBuildingsInput.checked()) - this.needs.forEach(n => n.updateAmount(parseInt(val * config.fullHouse))) }); view.settings.existingBuildingsInput.checked.subscribe(enabled => { if (enabled) this.existingBuildings(Math.max(this.existingBuildings(), Math.ceil(parseInt(this.amount()) / config.fullHouse))); - else - this.amount(Math.max(this.amount(), parseInt(this.existingBuildings()) / (config.fullHouse - 10))); + else if (!this.amount()) + this.amount(parseInt(this.existingBuildings()) / config.fullHouse); }); if (this.residence) { @@ -1273,6 +1321,11 @@ class PopulationLevel extends NamedElement { } } + initBans(assetsMap) { + for (var n of this.needs) + n.initBans(this, assetsMap); + } + incrementAmount() { this.amount(parseFloat(this.amount()) + 1); } @@ -2436,6 +2489,11 @@ function init() { } } + if (!localStorage || !localStorage.getItem("versionCalculator")) { + view.settings.hideProductionBoost.checked(true); + view.settings.needUnlockConditions.checked(true); + } + view.settings.languages = params.languages; view.settings.serverOptions = []; @@ -2663,7 +2721,7 @@ function createFloatInput(init) { obs.subscribe(val => { var num = parseFloat(val); - if (typeof num == "number" && isFinite(num) && val != num) + if (typeof num == "number" && isFinite(num) && val !== num) obs(num); else if (typeof num != "number" || !isFinite(num)) obs(init); diff --git a/README.md b/README.md index 2d4ed3a..a698839 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ * A calculator for the computer game [Anno 1404](https://store.ubi.com/upc/de/anno-1404-history-edition/5e29c6565cdf9a03ec037ae7.html) to compute the required production depending on the population * [YouTube-Tutorial](https://youtu.be/4ZJYZ5GBc60) * To use the calculator go to the following website: https://nihoel.github.io/Anno1404Calculator/ -* To use it offline, download, unzip and open index.html with a browser: https://github.com/NiHoel/Anno1404Calculator/archive/v1.0.zip +* To use it offline, download, unzip and open index.html with a browser: https://github.com/NiHoel/Anno1404Calculator/archive/v1.2.zip ![Extract population count](PopulationExtraction.jpg) An application to read population and factory count from the game and enter it into the calculator (only works from citizens onwards): https://github.com/NiHoel/Anno1404UXEnhancer diff --git a/i18n.js b/i18n.js index ad95068..3012a97 100644 --- a/i18n.js +++ b/i18n.js @@ -431,12 +431,10 @@ Siehe folgenden Link für weitere Informationen: `, german: "Eine neue Version des Warenrechners ist verfügbar. Klicke auf den Downloadbutton.", korean: "새로운 Anno 1404 계산기 버전이 제공됩니다. 다운로드 버튼을 클릭하십시오." }, - /* newFeature: { - english: "NEU: Zusatzwarenverwaltung, Zeitungseffekt und Handelsrouten. Alles drei muss erst über die Einstellungen aktiviert werden. Über das neue Fabrikkonfigurationsmenü können Routen erstellt, Items ausgerüstet und Zusatzwaren angewendet werden. Siehe die Hilfe für weitere Informationen.", - german: "NEW: Extra goods management, newspaper effects and trade routes. All three features must be activated in the settings. From the new factory configuration dialog one can create routes, equip items, and apply extra goods. See the help for more information.", + english: "Freischaltbedingungen der Bedürfnisse berücksichtigt.", + german: "Unlock conditions of needs considered.", }, - */ helpContent: { german: `
Verwendung und Aufbau
@@ -631,6 +629,13 @@ options = { "korean": "부족한 건물 강조" } }, + "needUnlockConditions": { + "name": "Consider unlock conditions for needs", + "locaText": { + "english": "Consider unlock conditions for needs", + "german": "Freischaltbedingungen der Bedürfnisse berücksichtigen", + } + }, /* "noOptionalNeeds": { "name": "Do not produce luxury goods", diff --git a/index.html b/index.html index 12b5cb7..7a68c7a 100644 --- a/index.html +++ b/index.html @@ -643,11 +643,11 @@

Trade Routes

-
diff --git a/params.js b/params.js index 553a3a8..29576f0 100644 --- a/params.js +++ b/params.js @@ -1875,7 +1875,11 @@ params= }, { "guid": 50012, -"tpmin": 0.0044 +"tpmin": 0.0044, +"unlockCondition": { +"amount": 60, +"populationLevel": 51901 +} } ], "residence": 33010 @@ -1950,7 +1954,11 @@ params= }, { "guid": 50013, -"tpmin": 0.0024 +"tpmin": 0.0024, +"unlockCondition": { +"amount": 510, +"populationLevel": 51903 +} }, { "guid": 50017, @@ -1958,15 +1966,27 @@ params= }, { "guid": 50018, -"tpmin": 0.0028 +"tpmin": 0.0028, +"unlockCondition": { +"amount": 690, +"populationLevel": 51903 +} }, { "guid": 50022, -"tpmin": 0.0016 +"tpmin": 0.0016, +"unlockCondition": { +"amount": 940, +"populationLevel": 51903 +} }, { "guid": 50025, -"tpmin": 0.0008 +"tpmin": 0.0008, +"unlockCondition": { +"amount": 3000, +"populationLevel": 51904 +} } ], "residence": 33030, @@ -2014,7 +2034,11 @@ params= }, { "guid": 50014, -"tpmin": 0.002 +"tpmin": 0.002, +"unlockCondition": { +"amount": 1500, +"populationLevel": 51904 +} }, { "guid": 50017, @@ -2026,11 +2050,19 @@ params= }, { "guid": 50019, -"tpmin": 0.0016 +"tpmin": 0.0016, +"unlockCondition": { +"amount": 950, +"populationLevel": 51904 +} }, { "guid": 50020, -"tpmin": 0.00142 +"tpmin": 0.00142, +"unlockCondition": { +"amount": 4000, +"populationLevel": 51904 +} }, { "guid": 50022, @@ -2038,15 +2070,19 @@ params= }, { "guid": 50023, -"tpmin": 0.00117 -}, -{ -"guid": 50027, -"tpmin": 0.00058 +"tpmin": 0.00117, +"unlockCondition": { +"amount": 2200, +"populationLevel": 51904 +} }, { "guid": 50025, -"tpmin": 0.0006 +"tpmin": 0.0006, +"unlockCondition": { +"amount": 3000, +"populationLevel": 51904 +} } ], "residence": 33040, @@ -2074,11 +2110,19 @@ params= }, { "guid": 50015, -"tpmin": 0.00344 +"tpmin": 0.00344, +"unlockCondition": { +"amount": 145, +"populationLevel": 51909 +} }, { "guid": 50024, -"tpmin": 0.00165 +"tpmin": 0.00165, +"unlockCondition": { +"amount": 295, +"populationLevel": 51909 +} } ], "residence": 33055 @@ -2105,7 +2149,11 @@ params= }, { "guid": 50011, -"tpmin": 0.00163 +"tpmin": 0.00163, +"unlockCondition": { +"amount": 4360, +"populationLevel": 51910 +} }, { "guid": 50015, @@ -2117,11 +2165,19 @@ params= }, { "guid": 50027, -"tpmin": 0.0008 +"tpmin": 0.0008, +"unlockCondition": { +"amount": 2600, +"populationLevel": 51910 +} }, { "guid": 50026, -"tpmin": 0.00133 +"tpmin": 0.00133, +"unlockCondition": { +"amount": 1040, +"populationLevel": 51910 +} }, { "guid": 50024, @@ -2157,23 +2213,23 @@ params= 50012, 50017, 50007, -50022, 50010, 50013, 50018, +50022, 50025, +50009, +50019, 50014, 50023, -50019, -50009, -50015, +50020, 50021, +50015, 50024, 50026, 50016, -50020, -50011, -50027 +50027, +50011 ] }, { @@ -2228,11 +2284,11 @@ params= }, "name": "Raw Materials", "products": [ +50031, 50029, 50030, 50036, 50035, -50031, 50049, 50053, 50044, @@ -2271,8 +2327,8 @@ params= 50043, 50048, 50037, -50045, 50050, +50045, 50057, 50058, 50056,