Skip to content

Commit

Permalink
Add need unlock conditions.
Browse files Browse the repository at this point in the history
Minor fixes.
Rearrange products.
  • Loading branch information
NiHoel committed Jan 4, 2021
1 parent ad86732 commit 90a060f
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 49 deletions.
86 changes: 72 additions & 14 deletions AnnoCalculator.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) {
{
Expand Down Expand Up @@ -402,6 +410,8 @@ class Island {
}
}



for (var category of params.productFilter) {
let c = new ProductCategory(category, assetsMap);
assetsMap.set(c.guid, c);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
`<h5>Verwendung und Aufbau</h5>
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,11 @@ <h4 data-bind="text: $root.settings.tradeRoutes.name">Trade Routes</h4>
<button type="button" class="btn" data-bind="if: false" style="display: none">
<img data-toggle="modal" data-target="#good-consumption-island-upgrade-dialog" class="icon-navbar" src="icon_newspaper.png" />
</button>
<button data-toggle="modal" data-target="#factory-choose-dialog" class="btn text-light" style="height: 2.25rem;">
<button data-toggle="modal" data-target="#factory-choose-dialog" class="btn text-light">
<span class="fa fa-cogs"> </span>
</button>
<button type="button" class="btn" data-bind="if: false" style="display: none">
<img data-toggle="modal" data-target="#item-equipment-dialog" class="icon-navbar" src="icon_itemsockets2.png" />
<img data-toggle="modal" data-target="#item-equipment-dialog" class="icon-navbar" src="icon_add_goods_socket_white.png" />
</button>
</div>
<div class="input-group input-group-sm" data-bind="visible: $root.islands().length > 1" style="width: unset;">
Expand Down
Loading

0 comments on commit 90a060f

Please sign in to comment.