diff --git a/constants.js b/constants.js index c0bbb6a..8c6e14a 100644 --- a/constants.js +++ b/constants.js @@ -317,7 +317,7 @@ function createProdUpgrades() { "desc": contents.desc, "icon": buildings[key].icon, "cost": { - "food": buildings[key].cost * 5 * Math.pow(10, counter - 1) + "food": buildings[key].cost.food * 5 * Math.pow(10, counter - 1) }, "effects": [ { diff --git a/gorge.js b/gorge.js index 4d95b37..1f4f991 100644 --- a/gorge.js +++ b/gorge.js @@ -116,27 +116,26 @@ function productivityMultiplierOf(type) { function productivityOf(type) { let baseProd = makeCost(buildings[type].prod); - baseProd.food *= productivityMultiplierOf(type); + baseProd = scaleCost(baseProd, productivityMultiplierOf(type)); - baseProd.food *= getGlobalProdBonus(); + baseProd = scaleCost(baseProd, productivityMultiplierOf(type)); - baseProd.food *= belongings[type].count; + baseProd = scaleCost(baseProd, belongings[type].count); return baseProd; } function makeCost(source) { const empty = mapObject(resourceTypes, () => 0); - Object.preventExtensions(empty); - return {...empty, ...source}; + return deepFreeze({...empty, ...source}); } function addCost(cost1, cost2) { - return Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost1[k] + cost2[k]}), {}); + return deepFreeze(Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost1[k] + cost2[k]}), {})); } function scaleCost(cost, scale) { - return Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost[k] * scale}), {}); + return deepFreeze(Object.keys(resourceTypes).reduce((o, k) => ({ ...o, [k]: cost[k] * scale}), {})); } function costOfBuilding(type, count = 1) { @@ -144,7 +143,7 @@ function costOfBuilding(type, count = 1) { while (count > 0) { let baseCost = makeCost(buildings[type].cost); - baseCost.food *= Math.pow(1.15, belongings[type].count + count - 1); + baseCost = scaleCost(baseCost, Math.pow(1.15, belongings[type].count + count - 1)); total = addCost(total, baseCost); count--; } diff --git a/util.js b/util.js index c9b90aa..be32c59 100644 --- a/util.js +++ b/util.js @@ -20,7 +20,7 @@ function round(val, places = 0) { } function mapObject(obj, func) { - return Object.keys(obj).reduce((o, k) => ({ ...o, [k]: func(obj[k])}), {}); + return deepFreeze(Object.keys(obj).reduce((o, k) => ({ ...o, [k]: func(obj[k])}), {})); } function deepFreeze(object) {