From 6d27837766efaac7bbe75a2328449b9f9c2630e9 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 22 Jul 2018 17:21:07 -0500 Subject: [PATCH] Standard upgrades (prod/prod-all) are now automatically generated. --- constants.js | 349 ++++++++++++++++++++------------------------------- gorge.js | 77 ++++++++---- 2 files changed, 191 insertions(+), 235 deletions(-) diff --git a/constants.js b/constants.js index 5b561dc..cfb48fa 100644 --- a/constants.js +++ b/constants.js @@ -24,91 +24,91 @@ const buildings = { "name": "Car", "plural": "Cars", "desc": "Crunchy shell, tasty center.", - "cost": 1e3, + "cost": 1.2e3, "prod": 1e1/1.2 }, "bus": { "name": "Bus", "plural": "Buses", "desc": "Probably the worst place to be when a macro is aroud.", - "cost": 1e4, + "cost": 1.4e4, "prod": 1e2/1.3 }, "house": { "name": "House", "plural": "Houses", "desc": "Home sweet home - but it doesn't taste sweet?", - "cost": 1e5, + "cost": 1.6e5, "prod": 1e3/1.4 }, "apartment": { "name": "Apartment", "plural": "Apartments", "desc": "More snacks, less packaging.", - "cost": 1e6, + "cost": 1.8e6, "prod": 1e4/1.5 }, "block": { "name": "Block", "plural": "Blocks", "desc": "A whole pile of buildings.", - "cost": 1e7, + "cost": 2e7, "prod": 1e5/1.6 }, "town": { "name": "Town", "plural": "Towns", "desc": "'Tourist trap' has never been this literal.", - "cost": 1e8, + "cost": 2.2e8, "prod": 1e6/1.7 }, "city": { "name": "City", "plural": "Cities", "desc": "Please no sitty on our city.", - "cost": 1e9, + "cost": 2.4e9, "prod": 1e7/1.8 }, "metro": { "name": "Metropolis", "plural": "Metropolises", "desc": "A big ol' city. Tasty, too.", - "cost": 1e10, + "cost": 2.6e10, "prod": 1e8/1.9 }, "county": { "name": "County", "plural": "Counties", "desc": "Why salt the land when you can slurp it?", - "cost": 1e11, + "cost": 2.8e11, "prod": 1e9/2 }, "state": { "name": "State", "plural": "States", "desc": "The United States is made up of...43 states - no, 42...", - "cost": 1e12, + "cost": 3e12, "prod": 1e10/2.1 }, "country": { "name": "Country", "plural": "Countries", "desc": "One nation, under paw.", - "cost": 1e13, + "cost": 3.2e13, "prod": 1e11/2.2 }, "continent": { "name": "Continent", "plural": "Continents", "desc": "Earth-shattering appetite!", - "cost": 1e14, + "cost": 3.4e14, "prod": 1e12/2.3 }, "planet": { "name": "Planet", "plural": "Planets", "desc": "Earth appetite!", - "cost": 1e15, + "cost": 3.6e15, "prod": 1e13/2.4 } } @@ -140,83 +140,23 @@ const effect_types = { } } -const upgrades = { - "micro-prod-1": { - "name": "Bigger Micros", - "desc": "A macro micro? Certainly more filling.", +let upgrades = { + "car-prod-1": { + "name": "High Occupancy Vehicles", + "desc": "Think of the environment! Think of the gigantic monster's hunger!", "cost": { - "food": buildings.micro.cost * 10 + "food": buildings.car.cost * 5 }, "effects": [ { "type": "prod", - "target": "micro", + "target": "car", "amount": 2, } ], "prereqs": { "buildings": { - "micro": 1 - } - } - }, - "micro-prod-2": { - "name": "Beefy Micros", - "desc": "25% more protein, 10% fewer carbs.", - "cost": { - "food": buildings.micro.cost * 50 - }, - "effects": [ - { - "type": "prod", - "target": "micro", - "amount": 2.25, - } - ], - "prereqs": { - "buildings": { - "micro": 5 - }, - "upgrades": [ - "micro-prod-1" - ] - } - }, - "anthro-prod-1": { - "name": "Willing Prey", - "desc": "Why bother chasing it down?", - "cost": { - "food": buildings.anthro.cost * 5 - }, - "effects": [ - { - "type": "prod", - "target": "anthro", - "amount": 2, - } - ], - "prereqs": { - "buildings": { - "anthro": 1 - } - } - }, - "anthro-prod-2": { - "name": "Mesmerized Prey", - "desc": "Why bother walking over to it?", - "cost": { - "food": buildings.anthro.cost * 50 - }, - "effects": [ - { - "type": "prod", - "target": "anthro", - "amount": 2.25, - } - ], - "prereqs": { - "buildings": { - "anthro": 10 + "car": 10 }, "upgrades": [ "anthro-prod-1" @@ -245,149 +185,136 @@ const upgrades = { "anthro-prod-1" ] } - }, - "prod-1": { - "name": "Sloth Metabolism", - "desc": "Burn those calories. Eventually.", - "cost": { - "food": 5e2 - }, - "effects": [ - { - "type": "prod-all", - "amount": 1.05 + } + +} + +function createTemplateUpgrades() { + console.log("qwewq"); + createProdUpgrades(); + createProdAllUpgrades(); +} + +function createProdUpgrades() { + for (const [key, value] of Object.entries(prodUpgradeText)) { + let counter = 1; + let prefix = key + "-prod-"; + for (let contents of value) { + upgrades[prefix + counter] = { + "name": contents.name, + "desc": contents.desc, + "cost": { + "food": buildings[key].cost * 5 * Math.pow(10,counter) + }, + "effects": [ + { + "type": "prod", + "amount": 2 + (counter - 1) * 0.25, + "target": key + } + ] + }; + + if (counter > 1) { + upgrades[prefix + counter]["prereqs"] = { + "upgrades": [ + prefix + (counter - 1) + ] + }; } - ], - "prereqs": { - "productivity": { - "food": 1e1 + + counter += 1; + } + } +} + +function createProdAllUpgrades() { + let prefix = "prod-all-" + + let counter = 1; + + for (let contents of prodAllUpgradeText) { + upgrades[prefix + counter] = { + "name": contents.name, + "desc": contents.desc, + "cost": { + "food": 5 * Math.pow(10, counter+1) + }, + "effects": [ + { + "type": "prod-all", + "amount": 1.05 + } + ], + "prereqs": { + "productivity": { + "food": Math.pow(10, counter) + } } + }; + + if (counter > 1) { + upgrades[prefix + counter]["prereqs"].upgrades = [ + prefix + (counter - 1) + ]; + } + } +} + +let prodUpgradeText = { + "micro": [ + { + "name": "Bigger Micros", + "desc": "A macro micro? It's more filling, for sure.", }, - }, - "prod-2": { - "name": "Decent Metabolism", - "desc": "Picking up the pace.", - "cost": { - "food": 5e3 + { + "name": "Beefy Micros", + "desc": "25% more protein, 10% fewer carbs." }, - "effects": [ - { - "type": "prod-all", - "amount": 1.05 - } - ], - "prereqs": { - "productivity": { - "food": 1e2 - }, - "upgrades": [ - "prod-1" - ] + { + "name": "Delicious Micros", + "desc": "Betcha' can't eat just one." + } + ], + "anthro": [ + { + "name": "Willing Prey", + "desc": "Why bother chasing down your meal?" }, + { + "name": "Mesmerized Prey", + "desc": "Why bother walking to your meal?" + } + ], +} + +let prodAllUpgradeText = [ + { + "name": "Sloth Metabolism", + "desc": "Burn those calories. Eventually." + }, + { + "name": "Decent Metabolism", + "desc": "Picking up the pace." }, - "prod-3": { + { "name": "Perky Metabolism", - "desc": "Sweat a little.", - "cost": { - "food": 5e4 - }, - "effects": [ - { - "type": "prod-all", - "amount": 1.05 - } - ], - "prereqs": { - "productivity": { - "food": 1e3 - }, - "upgrades": [ - "prod-2" - ] - }, + "desc": "Sweat a little." }, - "prod-4": { + { "name": "Quick Metabolism", - "desc": "Burn those calories.", - "cost": { - "food": 5e5 - }, - "effects": [ - { - "type": "prod-all", - "amount": 1.05 - } - ], - "prereqs": { - "productivity": { - "food": 1e4 - }, - "upgrades": [ - "prod-3" - ] - }, + "desc": "Burn those calories." }, - "prod-5": { + { "name": "Speedy Metabolism", - "desc": "More prey, more power.", - "cost": { - "food": 5e6 - }, - "effects": [ - { - "type": "prod-all", - "amount": 1.05 - } - ], - "prereqs": { - "productivity": { - "food": 1e5 - }, - "upgrades": [ - "prod-4" - ] - }, + "desc": "More prey, more power." }, - "prod-6": { + { "name": "Fast Metabolism", - "desc": "You're a furnace.", - "cost": { - "food": 5e7 - }, - "effects": [ - { - "type": "prod-all", - "amount": 1.05 - } - ], - "prereqs": { - "productivity": { - "food": 1e6 - }, - "upgrades": [ - "prod-5" - ] - }, + "desc": "You're a furnace. Fueled by people." }, - "prod-7": { + { "name": "Powerful Metabolism", - "desc": "Digest them all.", - "cost": { - "food": 5e8 - }, - "effects": [ - { - "type": "prod-all", - "amount": 1.05 - } - ], - "prereqs": { - "productivity": { - "food": 1e7 - }, - "upgrades": [ - "prod-6" - ] - }, - }, -} + "desc": "Digest them all." + } +] diff --git a/gorge.js b/gorge.js index abb7c87..ad9f531 100644 --- a/gorge.js +++ b/gorge.js @@ -227,6 +227,13 @@ function eatMicro() { // we'll initialize the dict of buildings we can own function setup() { + + // create static data + + createTemplateUpgrades(); + + // prepare dynamic stuff + initializeData(); createButtons(); createDisplays(); @@ -339,23 +346,26 @@ function upgradeReachable(id) { return false; } - for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) { - if (type == "buildings") { - for (const [building, amount] of Object.entries(reqs)) { - if (belongings[building].count == 0) { - return false; + if (upgrades[id].prereqs !== undefined ){ + for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) { + if (type == "buildings") { + for (const [building, amount] of Object.entries(reqs)) { + if (belongings[building].count == 0) { + return false; + } } } - } - else if (type == "upgrades") { - for (let upgrade of reqs) { - if (!ownedUpgrades[upgrade]) { - return false; + else if (type == "upgrades") { + for (let upgrade of reqs) { + if (!ownedUpgrades[upgrade]) { + return false; + } } } } } + return true; } function upgradeAvailable(id) { @@ -367,22 +377,25 @@ function upgradeAvailable(id) { return false; } - for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) { - if (type == "buildings") { - for (const [building, amount] of Object.entries(upgrades[id].prereqs[type])) { - if (belongings[building].count < amount) { - return false; + if (upgrades[id].prereqs !== undefined) { + for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) { + if (type == "buildings") { + for (const [building, amount] of Object.entries(upgrades[id].prereqs[type])) { + if (belongings[building].count < amount) { + return false; + } } - } - } else if (type == "productivity") { - for (const [key, value] of Object.entries(reqs)) { - if (currentProductivity[key] < value) { - return false; + } else if (type == "productivity") { + for (const [key, value] of Object.entries(reqs)) { + if (currentProductivity[key] < value) { + return false; + } } } } } + return true; } @@ -465,6 +478,10 @@ function renderCost(cost) { function renderPrereqs(prereqs) { let list = []; + if (prereqs === undefined) { + return renderLines(list); + } + list.push({ "text": "Own:" }); @@ -562,7 +579,7 @@ function buildingTooltip(id, event) { fillTooltip("building", "name", buildings[id].name); fillTooltip("building", "desc", buildings[id].desc); - fillTooltip("building", "cost", costOfBuilding(id) + " food"); + fillTooltip("building", "cost", render(costOfBuilding(id)) + " food"); fillTooltip("building", "prod", prodSummary(id)); let yOffset = tooltip.parentElement.getBoundingClientRect().y; @@ -606,11 +623,23 @@ function load() { return; } - ownedUpgrades = JSON.parse(storage.getItem("ownedUpgrades")); + let newOwnedUpgrades = JSON.parse(storage.getItem("ownedUpgrades")); + + for (const [key, value] of Object.entries(newOwnedUpgrades)) { + ownedUpgrades[key] = value; + } - resources = JSON.parse(storage.getItem("resources")); + let newResources = JSON.parse(storage.getItem("resources")); - belongings = JSON.parse(storage.getItem("belongings")); + for (const [key, value] of Object.entries(newResources)) { + resources[key] = value; + } + + let newBelongings = JSON.parse(storage.getItem("belongings")); + + for (const [key, value] of Object.entries(newBelongings)) { + belongings[key] = value; + } } function reset() {