Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Evolve
- // @namespace http://tampermonkey.net/
- // @version 1.3
- // @description Edited slightly by CondoSlime
- // @author Fafnir
- // @match https://pmotschmann.github.io/Evolve/
- // @grant GM_log
- // @require https://code.jquery.com/jquery-3.3.1.min.js
- // ==/UserScript==
- (function($) {
- 'use strict';
- var settings = {};
- var jsonSettings = localStorage.getItem('settings');
- if(jsonSettings != null){
- settings = JSON.parse(jsonSettings);
- }
- /***
- *
- * Setup resources informations and settings
- *
- ***/
- // Theoretically used to make sure script clicks don't have the modifier keys
- // However, can just turn off multiplier keys
- var ctrlDown = false;
- var altDown = false;
- var shiftDown = false;
- /*
- document.onkeydown = function(e) {
- if (e.key == "Control") {
- ctrlDown = true;
- }
- if (e.key == "Alt") {
- altDown = true;
- }
- if (e.key == "Shift") {
- shiftDown = true;
- }
- };
- document.onkeyup = function(e) {
- if (e.key == "Control") {
- ctrlDown = false;
- }
- if (e.key == "Alt") {
- altDown = false;
- }
- if (e.key == "Shift") {
- shiftDown = false;
- }
- };*/
- // Used to ensure no modal window conflicts
- let modal = false;
- class Resource {
- constructor(name, id, storePriority, storeMin) {
- this.name = name;
- this.id = id;
- if (!settings.resources.hasOwnProperty(this.id)) {settings.resources[this.id] = {};}
- if (!settings.resources[this.id].hasOwnProperty('storeMin')) {settings.resources[this.id].storeMin = storeMin;}
- if (!settings.resources[this.id].hasOwnProperty('storePriority')) {settings.resources[this.id].storePriority = storePriority;}
- }
- get storeMin() {return settings.resources[this.id].storeMin;}
- set storeMin(storeMin) {settings.resources[this.id].storeMin = storeMin;}
- get storePriority() {return settings.resources[this.id].storePriority};
- set storePriority(storePriority) {settings.resources[this.id].storePriority = storePriority;}
- get amount() {
- try {
- return getRealValue($('#cnt'+this.id)[0].innerHTML.split(' / ')[0]);
- } catch(e) {
- console.log("Error: Resource", this.name, "Amount invalid");
- return null;
- }
- }
- get crateable() {
- try {
- return ($('#con'+this.id)[0] !== undefined);
- } catch(e) {
- console.log("Error:", this.id, "Crateable");
- return null;
- }
- }
- get storage() {
- try {
- return getRealValue($('#cnt'+this.id)[0].innerHTML.split(' / ')[1]);
- } catch(e) {
- console.log("Error: Resource", this.name, "Storage invalid");
- return null;
- }
- }
- get ratio() {
- return this.amount / this.storage;
- }
- get unlocked() {
- try {
- return $('#res'+this.id)[0].style.display != 'none';
- } catch(e) {
- return false;
- }
- }
- get rate() {
- try {
- return getRealValue($('#inc'+this.id)[0].innerText.substr(0, $('#inc'+this.id)[0].innerText.length - 3))
- } catch(e) {
- return null;
- }
- }
- decStoreMin() {
- if (this.storeMin == 0) {return;}
- this.storeMin -= 1;
- updateSettings();
- console.log("Decrementing Store Minimum", this.id, this.storeMin);
- }
- incStoreMin() {
- if (this.storeMin == 99) {return;}
- this.storeMin += 1;
- updateSettings();
- console.log("Incrementing Store Minimum", this.id, this.storeMin);
- }
- decStorePriority() {
- if (this.storePriority == 0) {return;}
- this.storePriority -= 1;
- updateSettings();
- console.log("Decrementing Store Priority", this.id, this.storePriority);
- }
- incStorePriority() {
- if (this.storePriority == 99) {return;}
- this.storePriority += 1;
- updateSettings();
- console.log("Incrementing Store Priority", this.id, this.storePriority);
- }
- }
- class TradeableResource extends Resource {
- constructor(name, id, autoBuy, autoSell, buyRatio, sellRatio, storePriority, storeMin) {
- super(name, id, storePriority, storeMin);
- if (!settings.resources.hasOwnProperty(this.id)) {settings.resources[this.id] = {};}
- if (!settings.resources[this.id].hasOwnProperty('autoSell')) {settings.resources[this.id].autoSell = autoSell;}
- if (!settings.resources[this.id].hasOwnProperty('autoBuy')) {settings.resources[this.id].autoBuy = autoBuy;}
- if (!settings.resources[this.id].hasOwnProperty('buyRatio')) {settings.resources[this.id].buyRatio = buyRatio;}
- if (!settings.resources[this.id].hasOwnProperty('sellRatio')) {settings.resources[this.id].sellRatio = sellRatio;}
- }
- get autoSell() {return settings.resources[this.id].autoSell};
- set autoSell(autoSell) {settings.resources[this.id].autoSell = autoSell;}
- get autoBuy() {return settings.resources[this.id].autoBuy};
- set autoBuy(autoBuy) {settings.resources[this.id].autoBuy = autoBuy;}
- get buyRatio() {return settings.resources[this.id].buyRatio};
- set buyRatio(buyRatio) {settings.resources[this.id].buyRatio = buyRatio;}
- get sellRatio() {return settings.resources[this.id].sellRatio};
- set sellRatio(sellRatio) {settings.resources[this.id].sellRatio = sellRatio;}
- get sellBtn (){ return $('#market-'+this.id+' .order')[1];}
- get buyBtn (){ return $('#market-'+this.id+' .order')[0];}
- buyDec() {
- if (this.buyRatio > 0) {
- this.buyRatio = parseFloat(Number(this.buyRatio - 0.1).toFixed(1));
- updateSettings();
- console.log(this.id, "Decrementing Buy Ratio", this.buyRatio);
- }
- }
- buyInc() {
- if (this.buyRatio < 1) {
- this.buyRatio = parseFloat(Number(this.buyRatio + 0.1).toFixed(1));
- updateSettings();
- console.log(this.id, "Incrementing Buy Ratio", this.buyRatio);
- }
- }
- sellDec() {
- if (this.sellRatio > 0) {
- this.sellRatio = parseFloat(Number(this.sellRatio - 0.1).toFixed(1));
- updateSettings();
- console.log(this.id, "Decrementing Sell Ratio", this.sellRatio);
- }
- }
- sellInc() {
- if (this.sellRatio < 1) {
- this.sellRatio = parseFloat(Number(this.sellRatio + 0.1).toFixed(1));
- console.log(this.id, "Incrementing Sell Ratio", this.sellRatio);
- }
- }
- tradeDec() {
- try {
- $('#market-'+this.id+' > .trade > .is-primary')[1].children[0].click();
- } catch(e) {
- console.log("Error:", this.id, "Trade Decrement");
- return null;
- }
- }
- tradeInc() {
- try {
- $('#market-'+this.id+' > .trade > .is-primary')[0].children[0].click();
- } catch(e) {
- console.log("Error:", this.id, "Trade Increment");
- return null;
- }
- }
- get tradeNum() {
- try {
- return parseInt($('#market-'+this.id+' > .trade > .current')[0].innerText);
- } catch(e) {
- console.log("Error:", this.id, "Trade Num");
- return null;
- }
- }
- get tradeBuyCost() {
- try {
- let dataStr = $('#market-'+this.id+' > .trade > .is-primary')[0].attributes['data-label'].value;
- var reg = /Auto-buy\s([\d\.]+)[\w\s]*\$([\d\.]+)/.exec(dataStr);
- return parseFloat(reg[2]);
- } catch(e) {
- console.log("Error:", this.id, "Trade Buy Cost");
- return null;
- }
- }
- get tradeSellCost() {
- try {
- let dataStr = $('#market-'+this.id+' > .trade > .is-primary')[1].attributes['data-label'].value;
- var reg = /Auto-sell\s([\d\.]+)[\w\s]*\$([\d\.]+)/.exec(dataStr);
- return parseFloat(reg[2]);
- } catch(e) {
- console.log("Error:", this.id, "Trade Sell Cost");
- return null;
- }
- }
- get tradeAmount() {
- try {
- let dataStr = $('#market-'+this.id+' > .trade > .is-primary')[1].attributes['data-label'].value;
- var reg = /Auto-sell\s([\d\.]+)[\w\s]*\$([\d\.]+)/.exec(dataStr);
- return parseFloat(reg[1]);
- } catch(e) {
- console.log("Error:", this.id, "Trade Amount");
- return null;
- }
- }
- openStorage() {
- try {
- let storageBtn = $('#con'+this.id)[0];
- storageBtn.click();
- } catch(e) {
- console.log("Error:", this.id, "OpenStorage");
- }
- }
- }
- var resources = [];
- var resourcesArr = [];
- function loadResources() {
- if (!settings.hasOwnProperty('resources')) {settings.resources = {};}
- resources.Money = new Resource("Money", "Money", 0, 0);
- resources.Knowledge = new Resource("Knowledge", "Knowledge", 0, 0);
- resources.Food = new TradeableResource("Food", "Food", false, false, .5, .9, 0, 0);
- resources.Lumber = new TradeableResource("Lumber", "Lumber", false, false, .5, .9, 3, 0);
- resources.Stone = new TradeableResource("Stone", "Stone", false, false, .5, .9, 3, 0);
- resources.Furs = new TradeableResource("Furs", "Furs", false, false, .5, .9, 2, 0);
- resources.Copper = new TradeableResource("Copper", "Copper", false, false, .5, .9, 2, 0);
- resources.Iron = new TradeableResource("Iron", "Iron", false, false, .5, .9, 2, 0);
- resources.Aluminium = new TradeableResource("Aluminium", "Aluminium", false, false, .5, .9, 2, 0);
- resources.Cement = new TradeableResource("Cement", "Cement", false, false, .5, .9, 2, 0);
- resources.Coal = new TradeableResource("Coal", "Coal", false, false, .5, .9, 0, 0);
- resources.Oil = new TradeableResource("Oil", "Oil", false, false, .5, .9, 0, 0);
- resources.Uranium = new TradeableResource("Uranium", "Uranium", false, false, .5, .9, 0, 0);
- resources.Steel = new TradeableResource("Steel", "Steel", false, false, .5, .9, 3, 10);
- resources.Titanium = new TradeableResource("Titanium", "Titanium", false, false, .5, .9, 3, 10);
- resources.Alloy = new TradeableResource("Alloy", "Alloy", false, false, .5, .9, 3, 10);
- resources.Polymer = new TradeableResource("Polymer", "Polymer", false, false, .5, .9, 3, 10);
- resources.Iridium = new TradeableResource("Iridium", "Iridium", false, false, .5, .9, 3, 10);
- resources.Helium_3 = new TradeableResource("Helium-3", "Helium_3", false, false, .5, .9, 0, 0);
- resources.Infernite = new Resource("Infernite", "Infernite", 3, 0);
- resources.Adamantite = new Resource("Adamantite", "Adamantite", 3, 0);
- resources.Graphene = new Resource("Graphene", "Graphene", 3, 0);
- resources.Stanene = new Resource("Stanene", "Stanene", 3, 0);
- for (let x in resources){
- resourcesArr.push(x);
- }
- }
- class CraftableResource extends Resource {
- constructor(name, id, enabled, sources) {
- const storeMin = 0;
- super(name, id, storeMin);
- this.sources = sources;
- this.craftable = true;
- if (!settings.resources[this.id].hasOwnProperty('enabled')) {settings.resources[this.id].enabled = enabled;}
- }
- get enabled() {return settings.resources[this.id].enabled;}
- set enabled(enabled) {settings.resources[this.id].enabled = enabled;}
- get canCraft() {
- // Crafting if resource is unlocked and enabled
- if (this.unlocked && this.enabled) {
- // Checking if every source can be used
- //console.log("Checking crafting of", this);
- if (this.sources.every(function(element) {
- //console.log("Checking Resource", element.res, element.res.ratio);
- return element.res.ratio > 0.9;
- })) {
- //console.log("Can Craft", this.name);
- // Determining number of crafts
- let total_crafts = 100000000000;
- for (let i = 0;i < this.sources.length;i++) {
- let res = this.sources[i].res;
- let cost = this.sources[i].cost;
- let cur_crafts = Math.round((res.amount - (res.storage * .9)) / cost);
- //console.log("Checking", res.name, "A/S", res.amount, res.storage, cur_crafts);
- if (cur_crafts < total_crafts) {
- total_crafts = cur_crafts;
- }
- }
- return total_crafts;
- }
- }
- return 0;
- }
- get rate() {
- //TODO: Somehow figure out how to find the rate (number of craftsmen can be found, but not how much per craftsman)
- return 0.000001;
- }
- craft(num) {
- try {
- //console.log(this.id, this.unlocked, this.enabled, this.canCraft);
- if (!this.unlocked || !this.enabled) {return;}
- const res = document.getElementById("inc" + this.id + "5");
- if (!res) return;
- let craftBtn = res.getElementsByTagName("a")[0];
- if (craftBtn !== null) {
- for (let j = 0;j < this.canCraft;j++) {
- craftBtn.click();
- }
- }
- return true;
- } catch(e) {
- console.log("Error:", this.id, "Craft", e);
- return false;
- }
- }
- }
- var craftableResources = {};
- function loadCraftableResources() {
- if (!settings.hasOwnProperty('resources')) {settings.resources = {};}
- craftableResources.Plywood = new CraftableResource("Plywood", "Plywood", false, [{res:resources.Lumber,cost:500}]);
- craftableResources.Brick = new CraftableResource("Brick", "Brick", false, [{res:resources.Cement,cost:200}]);
- craftableResources.Wrought_Iron = new CraftableResource("Wrought Iron", "Wrought_Iron", false, [{res:resources.Iron,cost:400}]);
- craftableResources.Sheet_Metal = new CraftableResource("Sheet Metal", "Sheet_Metal", false, [{res:resources.Aluminium,cost:600}]);
- craftableResources.Mythril = new CraftableResource("Mythril", "Mythril", false, [{res:resources.Alloy,cost:500}, {res:resources.Iridium,cost:1250}]);
- craftableResources.Aerogel = new CraftableResource("Aerogel", "Aerogel", false, [{res:resources.Graphene,cost:2500}, {res:resources.Infernite,cost:50}]);
- }
- function priorityScale(value, priority, action) {
- let scale = Math.exp(-0.25 * priority);
- if (action !== null && action !== undefined) {
- if (action instanceof Research) {
- scale / 2;
- }
- }
- return value * scale;
- }
- class Action {
- constructor(id, tags, priority) {
- this.id = id;
- this.tags = tags;
- if (!settings.actions.hasOwnProperty(this.id)) {settings.actions[this.id] = {};}
- if (!settings.actions[this.id].hasOwnProperty('priority')) {settings.actions[this.id].priority = priority;}
- }
- get priority() {return settings.actions[this.id].priority;}
- set priority(priority) {settings.actions[this.id].priority = priority;}
- get unlocked() {
- try {
- let label = $('#'+this.id+' > a > .aTitle')[0];
- return ($('#'+this.id+' > a > .aTitle')[0] !== undefined);
- } catch(e) {
- console.log("Error:", this.id, "Unlocked");
- return false;
- }
- }
- get name() {
- try {
- let label = $('#'+this.id+' > a > .aTitle');
- if (label.length != 0) {
- return label[0].innerText;
- } else {
- return this.id;
- }
- } catch(e) {
- console.log("Error:", this.id, "Name");
- return null;
- }
- }
- decPriority() {
- if (this.priority == -99) {return;}
- this.priority -= 1;
- updateSettings();
- console.log("Decrementing Priority", this.id, this.priority);
- }
- incPriority() {
- if (this.priority == 99) {return;}
- this.priority += 1;
- updateSettings();
- console.log("Incrementing Priority", this.id, this.priority);
- }
- getResDep(resid) {
- try {
- // Loading res
- this.res = {};
- let data = $('#' + this.id + ' > a')[0];
- for (let i = 0;i < data.attributes.length;i++) {
- let name = data.attributes[i].name;
- let cost = data.attributes[i].value;
- if (name.indexOf('data-') >= 0) {
- this.res[name.substr(5, name.length)] = parseInt(cost);
- }
- }
- return this.res[resid.toLowerCase()];
- } catch(e) {
- console.log("Error:", this.id, "getResDep");
- return null;
- }
- }
- click() {
- try {
- let btn = document.getElementById(this.id);
- if (btn.className.indexOf('cna') < 0) {
- btn.getElementsByTagName("a")[0].click();
- return true;
- }
- return false;
- } catch(e) {
- console.log("Error:", this.id, "Click");
- return false;
- }
- return false;
- }
- }
- class Building extends Action {
- constructor(id, tags, enabled, limit, priority) {
- super(id, tags, priority);
- if (!settings.actions[this.id].hasOwnProperty('enabled')) {settings.actions[this.id].enabled = enabled;}
- //if (!settings.actions[this.id].hasOwnProperty('limit')) {settings.actions[this.id].limit = limit;}
- settings.actions[this.id].limit = limit;
- }
- get enabled() {return settings.actions[this.id].enabled;}
- set enabled(enabled) {settings.actions[this.id].enabled = enabled;}
- get limit() {return settings.actions[this.id].limit;}
- set limit(limit) {settings.actions[this.id].limit = limit;}
- get numTotal() {
- try {
- let amountLabel = $('#'+this.id+' > a > .count')[0];
- if (amountLabel !== undefined) {
- return parseInt(amountLabel.innerText);
- } else {
- return null;
- }
- } catch(e) {
- console.log("Error:", this.id, "numTotal");
- return null;
- }
- }
- decLimit() {
- if (this.limit == -1) {return;}
- this.limit -= 1;
- updateSettings();
- console.log("Decrementing Limit", this.id, this.limit);
- }
- incLimit() {
- if (this.limit == 99) {return;}
- this.limit += 1;
- updateSettings();
- console.log("Incrementing Limit", this.id, this.limit);
- }
- }
- class PoweredBuilding extends Building {
- constructor(id, tags, enabled, limit, priority, powerPriority, consume, produce, unlockResearch) {
- super(id, tags, enabled, limit, priority);
- this.produce = produce;
- this.consume = consume;
- if (!settings.actions[this.id].hasOwnProperty('powerPriority')) {settings.actions[this.id].powerPriority = powerPriority;}
- this.unlockResearch = unlockResearch;
- }
- get powerPriority() {return settings.actions[this.id].powerPriority;}
- set powerPriority(powerPriority) {settings.actions[this.id].powerPriority = powerPriority;}
- get powerUnlocked() {
- try {
- if (this.unlockResearch !== undefined) {
- return $('#'+this.id).length > 0 && researched(this.unlockResearch);
- }
- return $('#'+this.id).length > 0;
- } catch(e) {
- console.log("Error:", this.id, "powerUnlocked");
- return false;
- }
- }
- get numOn() {
- try {
- let incBtn = $('#'+this.id+' > .on')[0];
- return parseInt(incBtn.innerText);
- } catch(e) {
- console.log("Error:", this.id, "numOn");
- return null;
- }
- }
- get numOff() {
- try {
- let decBtn = $('#'+this.id+' > .off')[0];
- return parseInt(decBtn.innerText);
- } catch(e) {
- console.log("Error:", this.id, "numOff");
- return null;
- }
- }
- decPowerPriority() {
- if (this.power_priority == 0) {return;}
- this.power_priority -= 1;
- updateSettings();
- console.log("Decrementing Power Priority", this.id, this.power_priority);
- }
- incPowerPriority() {
- if (this.power_priority == 99) {return;}
- this.power_priority += 1;
- updateSettings();
- console.log("Incrementing Priority", this.id, this.power_priority);
- }
- }
- var buildings = {};
- function loadBuildings() {
- if (!settings.hasOwnProperty('actions')) {settings.actions = {};}
- buildings['city-basic_housing'] = new Building('city-basic_housing',
- ['city', 'citizen'],
- false, -1, 2);
- buildings['city-cottage'] = new Building('city-cottage',
- ['city', 'citizen'],
- false, -1, 0);
- buildings['city-apartment'] = new PoweredBuilding('city-apartment',
- ['city', 'citizen', 'power'],
- false, -1, 5,
- 9,
- [{res:'electricity',cost:1}],
- []);
- buildings['city-lodge'] = new Building('city-lodge',
- ['city', 'citizen'],
- false, -1, 1);
- buildings['city-smokehouse'] = new Building('city-smokehouse',
- ['city', 'food'],
- false, -1, 1);
- buildings['city-soul_well'] = new Building('city-soul_well',
- ['city'],
- false, -1, 1);
- buildings['city-slave_pen'] = new Building('city-slave_pen',
- ['city'],
- false, -1, 1);
- buildings['city-farm'] = new Building('city-farm',
- ['city', 'food'],
- false, -1, 1);
- buildings['city-mill'] = new Building('city-mill',
- ['city', 'food'],
- false, -1, 1);
- buildings['city-windmill'] = new PoweredBuilding('city-windmill',
- ['city', 'food', 'power'],
- false, -1, 1,
- 9,
- [{res:resources.Food,cost:0.1}],
- [{res:'electricity',cost:1}]);
- buildings['city-silo'] = new Building('city-silo',
- ['city', 'food'],
- false, -1, 0);
- buildings['city-garrison'] = new Building('city-garrison',
- ['city', 'army'],
- false, -1, 4);
- buildings['city-hospital'] = new Building('city-hospital',
- ['city', 'army'],
- false, -1, 3);
- buildings['city-boot_camp'] = new Building('city-boot_camp',
- ['city', 'army'],
- false, -1, 3);
- buildings['city-shed'] = new Building('city-shed',
- ['city', 'storage'],
- false, -1, 2);
- buildings['city-storage_yard'] = new Building('city-storage_yard',
- ['city', 'storage'],
- false, -1, 0);
- buildings['city-warehouse'] = new Building('city-warehouse',
- ['city', 'storage'],
- false, -1, 0);
- buildings['city-bank'] = new Building('city-bank',
- ['city', 'money'],
- false, -1, 5);
- buildings['city-lumber_yard'] = new Building('city-lumber_yard',
- ['city'],
- false, -1, 1);
- buildings['city-graveyard'] = new Building('city-graveyard',
- ['city'],
- false, -1, 1);
- buildings['city-sawmill'] = new PoweredBuilding('city-sawmill',
- ['city', 'power'],
- false, -1, 1,
- 1,
- [{res:'electricity',cost:1}],
- []);
- buildings['city-rock_quarry'] = new PoweredBuilding('city-rock_quarry',
- ['city', 'power'],
- false, -1, 1,
- 1,
- [{res:'electricity',cost:1}],
- []);
- buildings['city-cement_plant'] = new PoweredBuilding('city-cement_plant',
- ['city', 'power'],
- false, -1, 5,
- 3,
- [{res:'electricity',cost:2}],
- []);
- buildings['city-foundry'] = new Building('city-foundry',
- ['city'],
- false, -1, 5);
- buildings['city-factory'] = new PoweredBuilding('city-factory',
- ['city', 'power'],
- false, -1, 1,
- 9,
- [{res:'electricity',cost:3}],
- []);
- buildings['city-smelter'] = new Building('city-smelter',
- ['city'],
- false, -1, 1);
- buildings['city-metal_refinery'] = new Building('city-metal_refinery',
- ['city'],
- false, -1, 1);
- buildings['city-mine'] = new PoweredBuilding('city-mine',
- ['city', 'power'],
- false, -1, 1,
- 2,
- [{res:'electricity',cost:1}],
- []);
- buildings['city-coal_mine'] = new PoweredBuilding('city-coal_mine',
- ['city', 'power'],
- false, -1, 1,
- 2,
- [{res:'electricity',cost:1}],
- []);
- buildings['city-oil_well'] = new Building('city-oil_well',
- ['city'],
- false, -1, 6);
- buildings['city-oil_depot'] = new Building('city-oil_depot',
- ['city'],
- false, -1, 2);
- buildings['city-trade'] = new Building('city-trade',
- ['city'],
- false, -1, 3);
- buildings['city-wharf'] = new Building('city-wharf',
- ['city'],
- false, -1, 1);
- buildings['city-tourist_center'] = new PoweredBuilding('city-tourist_center',
- ['city', 'power'],
- false, -1, 0,
- 9,
- [{res:resources.Food,cost:50}],
- []);
- buildings['city-amphitheatre'] = new Building('city-amphitheatre',
- ['city'],
- false, -1, 6);
- buildings['city-casino'] = new PoweredBuilding('city-casino',
- ['city'],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:5}],
- []);
- buildings['city-temple'] = new Building('city-temple',
- ['city'],
- false, -1, 5);
- buildings['city-university'] = new Building('city-university',
- ['city', 'knowledge'],
- false, -1, 8);
- buildings['city-library'] = new Building('city-library',
- ['city', 'knowledge'],
- false, -1, 2);
- buildings['city-wardenclyffe'] = new PoweredBuilding('city-wardenclyffe',
- ['city', 'power', 'knowledge'],
- false, -1, 9,
- 9,
- [{res:'electricity',cost:2}],
- []);
- buildings['city-biolab'] = new PoweredBuilding('city-biolab',
- ['city', 'power', 'knowledge'],
- false, -1, 6,
- 9,
- [{res:'electricity',cost:2}],
- []);
- buildings['city-coal_power'] = new PoweredBuilding('city-coal_power',
- ['city', 'power'],
- false, -1, 4,
- 9,
- [{res:resources.Coal,cost:0.35}],
- [{res:'electricity',cost:5}]);
- buildings['city-oil_power'] = new PoweredBuilding('city-oil_power',
- ['city', 'power'],
- false, -1, 4,
- 9,
- [{res:resources.Oil,cost:0.65}],
- [{res:'electricity',cost:6}]);
- buildings['city-fission_power'] = new PoweredBuilding('city-fission_power',
- ['city', 'power'],
- false, -1, 5,
- 9,
- [{res:resources.Uranium,cost:0.1}],
- [{res:'electricity',cost:14}]);
- buildings['city-mass_driver'] = new PoweredBuilding('city-mass_driver',
- ['city', 'power'],
- false, -1, 1,
- 9,
- [{res:'electricity',cost:5}],
- []);
- buildings['space-test_launch'] = new Building('space-test_launch',
- ['space', 'home', 'mission'],
- false, -1, 10);
- buildings['space-satellite'] = new Building('space-satellite',
- ['space', 'home', 'knowledge'],
- false, -1, 1);
- buildings['space-gps'] = new Building('space-gps',
- ['space', 'home', 'trade'],
- false, -1, 0);
- buildings['space-propellant_depot'] = new Building('space-propellant_depot',
- ['space', 'home', 'storage'],
- false, -1, 1);
- buildings['space-nav_beacon'] = new PoweredBuilding('space-nav_beacon',
- ['space', 'home', 'power'],
- false, -1, 2,
- 9,
- [{res:'electricity',cost:2}],
- [{res:'moon_support',cost:1}]);
- buildings['space-moon_mission'] = new Building('space-moon_mission',
- ['space', 'moon', 'mission'],
- false, -1, 10);
- buildings['space-moon_base'] = new PoweredBuilding('space-moon_base',
- ['space', 'moon', 'power'],
- false, -1, 2,
- 9,
- [],
- [{res:'moon_support',cost:2}]);
- buildings['space-iridium_mine'] = new PoweredBuilding('space-iridium_mine',
- ['space', 'moon', 'power'],
- false, -1, 3,
- 9,
- [{res:'moon_support',cost:1}],
- []);
- buildings['space-helium_mine'] = new PoweredBuilding('space-helium_mine',
- ['space', 'moon', 'power'],
- false, -1, 1,
- 9,
- [{res:'moon_support',cost:1}],
- []);
- buildings['space-observatory'] = new PoweredBuilding('space-observatory',
- ['space', 'moon', 'knowledge', 'power'],
- false, -1, 2,
- 9,
- [{res:'moon_support',cost:1}],
- []);
- buildings['space-red_mission'] = new Building('space-red_mission',
- ['space', 'red', 'mission'],
- false, -1, 10);
- buildings['space-spaceport'] = new PoweredBuilding('space-spaceport',
- ['space', 'red', 'power'],
- false, -1, 1,
- 9,
- [],
- [{res:'red_support',cost:3}]);
- buildings['space-red_tower'] = new PoweredBuilding('space-red_tower',
- ['space', 'red', 'power'],
- false, -1, 1,
- 9,
- [{res:'red_support',cost:1}],
- []);
- buildings['space-living_quarters'] = new PoweredBuilding('space-living_quarters',
- ['space', 'red', 'citizen', 'power'],
- false, -1, 1,
- 9,
- [{res:'red_support',cost:1}],
- []);
- buildings['space-garage'] = new Building('space-garage',
- ['space', 'red', 'storage'],
- false, -1, 1);
- buildings['space-red_mine'] = new PoweredBuilding('space-red_mine',
- ['space', 'red', 'power'],
- false, -1, 1,
- 9,
- [{res:'red_support',cost:1}],
- []);
- buildings['space-fabrication'] = new PoweredBuilding('space-fabrication',
- ['space', 'red', 'power'],
- false, -1, 1,
- 9,
- [{res:'red_support',cost:1}],
- []);
- buildings['space-red_factory'] = new PoweredBuilding('space-red_factory',
- ['space', 'red', 'power'],
- false, -1, 1,
- 9,
- [{res:'electricity',cost:3}],
- []);
- buildings['space-biodome'] = new PoweredBuilding('space-biodome',
- ['space', 'red', 'food', 'power'],
- false, -1, 0,
- 9,
- [{res:'red_support',cost:1}],
- []);
- buildings['space-exotic_lab'] = new PoweredBuilding('space-exotic_lab',
- ['space', 'red', 'knowledge', 'power'],
- false, -1, 0,
- 9,
- [{res:'red_support',cost:1}],
- []);
- buildings['space-ziggurat'] = new Building('space-ziggurat',
- ['space', 'red'],
- false, -1, 3);
- buildings['space-space_barracks'] = new Building('space-space_barracks',
- ['space', 'red', 'army'],
- false, -1, 0);
- buildings['space-hell_mission'] = new Building('space-hell_mission',
- ['space', 'hell', 'mission'],
- false, -1, 10);
- buildings['space-geothermal'] = new PoweredBuilding('space-geothermal',
- ['space', 'hell', 'power'],
- false, -1, 0,
- 9,
- [],
- []);
- buildings['space-swarm_plant'] = new Building('space-swarm_plant',
- ['space', 'hell'],
- false, -1, 0);
- buildings['space-sun_mission'] = new Building('space-sun_mission',
- ['space', 'sun', 'mission'],
- false, -1, 10);
- buildings['space-swarm_control'] = new PoweredBuilding('space-swarm_control',
- ['space', 'sun', 'power'],
- false, -1, 1,
- 9,
- [],
- []);
- buildings['space-swarm_satellite'] = new PoweredBuilding('space-swarm_satellite',
- ['space', 'sun', 'power'],
- false, -1, 3,
- 9,
- [],
- []);
- buildings['space-gas_mission'] = new Building('space-gas_mission',
- ['space', 'gas', 'mission'],
- false, -1, 10);
- buildings['space-gas_mining'] = new PoweredBuilding('space-gas_mining',
- ['space', 'gas', 'power'],
- false, -1, 4,
- 9,
- [],
- []);
- buildings['space-gas_storage'] = new Building('space-gas_storage',
- ['space', 'gas', 'storage'],
- false, -1, 2);
- buildings['space-star_dock'] = new Building('space-star_dock',
- ['space', 'gas'],
- false, 1, 6);
- buildings['space-gas_moon_mission'] = new Building('space-gas_moon_mission',
- ['space', 'gas_moon', 'mission'],
- false, -1, 10);
- buildings['space-outpost'] = new PoweredBuilding('space-outpost',
- ['space', 'gas_moon', 'power'],
- false, -1, 1,
- 9,
- [],
- []);
- buildings['space-drone'] = new Building('space-drone',
- ['space', 'gas_moon'],
- false, -1, 0);
- buildings['space-oil_extractor'] = new PoweredBuilding('space-oil_extractor',
- ['space', 'gas_moon', 'power'],
- false, -1, 0,
- 9,
- [],
- []);
- buildings['space-belt_mission'] = new Building('space-belt_mission',
- ['space', 'belt', 'mission'],
- false, -1, 10);
- buildings['space-space_station'] = new PoweredBuilding('space-space_station',
- ['space', 'belt', 'power'],
- false, -1, 1,
- 9,
- [],
- []);
- buildings['space-elerium_ship'] = new PoweredBuilding('space-elerium_ship',
- ['space', 'belt', 'power'],
- false, -1, 1,
- 9,
- [],
- []);
- buildings['space-iridium_ship'] = new PoweredBuilding('space-iridium_ship',
- ['space', 'belt', 'power'],
- false, -1, 2,
- 9,
- [],
- []);
- buildings['space-iron_ship'] = new PoweredBuilding('space-iron_ship',
- ['space', 'belt', 'power'],
- false, -1, 0,
- 9,
- [],
- []);
- buildings['space-dwarf_mission'] = new Building('space-dwarf_mission',
- ['space', 'dwarf', 'mission'],
- false, -1, 10);
- buildings['space-elerium_contain'] = new Building('space-elerium_contain',
- ['space', 'dwarf', 'storage'],
- false, -1, 1);
- buildings['space-e_reactor'] = new PoweredBuilding('space-e_reactor',
- ['space', 'dwarf', 'power'],
- false, -1, 0,
- 9,
- [],
- []);
- buildings['space-world_collider'] = new Building('space-world_collider',
- ['space', 'dwarf'],
- false, 1859, 0);
- buildings['space-world_controller'] = new PoweredBuilding('space-world_controller',
- ['space', 'dwarf', 'power'],
- false, 1, 0,
- 9,
- [{res:'electricity',cost:20}],
- []);
- buildings['space-vr_center'] = new Building('space-vr_center',
- [],
- false, -1, 0);
- buildings['interstellar-starport'] = new PoweredBuilding('interstellar-starport',
- ['interstellar', 'starport'],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:10}],
- []);
- buildings['interstellar-warehouse'] = new Building('interstellar-warehouse',
- [],
- false, -1, 0);
- buildings['interstellar-mining_droid'] = new Building('interstellar-mining_droid',
- [],
- false, -1, 0);
- buildings['interstellar-habitat'] = new PoweredBuilding('interstellar-habitat',
- [],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:2}],
- []);
- buildings['interstellar-laboratory'] = new Building('interstellar-laboratory',
- [],
- false, -1, 0);
- buildings['interstellar-exchange'] = new Building('interstellar-exchange',
- [],
- false, -1, 0);
- buildings['interstellar-xfer_station'] = new PoweredBuilding('interstellar-xfer_station',
- [],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:1}],
- []);
- buildings['interstellar-cargo_yard'] = new Building('interstellar-cargo_yard',
- [],
- false, -1, 0);
- buildings['interstellar-dyson'] = new Building('interstellar-dyson',
- ['interstellar', 'dyson'],
- false, 100, 0);
- buildings['interstellar-processing'] = new PoweredBuilding('interstellar-processing',
- ['interstellar', 'processing'],
- false, -1, 0,
- 9,
- [{res:'int_alpha',cost:1}],
- []);
- buildings['interstellar-stellar_engine'] = new Building('interstellar-stellar_engine',
- ['interstellar', 'stellar_engine'],
- false, 100, 0);
- buildings['interstellar-proxima_mission'] = new Building('interstellar-proxima_mission',
- [],
- false, -1, 0);
- buildings['interstellar-nebula_mission'] = new Building('interstellar-nebula_mission',
- [],
- false, -1, 0);
- buildings['interstellar-harvester'] = new Building('interstellar-harvester',
- [],
- false, -1, 0);
- buildings['interstellar-g_factory'] = new Building('interstellar-g_factory',
- [],
- false, -1, 0);
- buildings['interstellar-fusion'] = new Building('interstellar-fusion',
- [],
- false, -1, 0);
- buildings['interstellar-nexus'] = new PoweredBuilding('interstellar-nexus',
- [],
- false, -1, 0,
- 9,
- [{res:'electricity', cost:8}],
- []);
- buildings['interstellar-neutron_mission'] = new Building('interstellar-neutron_mission',
- [],
- false, -1, 0);
- buildings['interstellar-blackhole_mission'] = new Building('interstellar-blackhole_mission',
- [],
- false, -1, 0);
- buildings['interstellar-cruiser'] = new Building('interstellar-cruiser',
- [],
- false, -1, 0);
- buildings['interstellar-far_reach'] = new PoweredBuilding('interstellar-far_reach',
- [],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:5}],
- []);
- buildings['interstellar-elerium_prospector'] = new Building('interstellar-elerium_prospector',
- [],
- false, -1, 0);
- buildings['interstellar-mass_ejector'] = new PoweredBuilding('interstellar-mass_ejector',
- [],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:2}],
- []);
- buildings['portal-turret'] = new PoweredBuilding('portal-turret',
- ['portal', 'turret', 'power'],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:5}],
- []);
- buildings['portal-carport'] = new PoweredBuilding('portal-carport',
- [],
- false, -1, 0,
- 9,
- [{}],
- []);
- buildings['portal-sensor_drone'] = new PoweredBuilding('portal-sensor_drone',
- ['portal', 'sensor_drone', 'power'],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:3}],
- []);
- buildings['portal-attractor'] = new PoweredBuilding('portal-attractor',
- [],
- false, -1, 0,
- 9,
- [{res:'electricity',cost:3}],
- []);
- }
- class Research extends Action {
- constructor(id, tags, priority) {
- super(id, tags, priority);
- this.done = false;
- }
- get researched() {
- if (this.done) {
- return true;
- }
- let researched = $('#oldTech > div');
- for (let i = 0;i < researched.length;i++) {
- if (this.id == researched[i].id) {
- this.done = true;
- return true;
- }
- }
- return false;
- }
- }
- var researches = [];
- function loadResearches() {
- if (!settings.hasOwnProperty('actions')) {settings.actions = {};}
- researches['tech-club'] = new Research('tech-club',
- ['food'],
- 1);
- researches['tech-bone_tools'] = new Research('tech-bone_tools',
- ['stone'],
- 1);
- researches['tech-sundial'] = new Research('tech-sundial',
- ['knowledge'],
- 5);
- researches['tech-housing'] = new Research('tech-housing',
- ['citizen'],
- 5);
- researches['tech-cottage'] = new Research('tech-cottage',
- ['citizen'],
- 0);
- researches['tech-apartment'] = new Research('tech-apartment',
- ['citzen', 'power'],
- 5);
- researches['tech-steel_beams'] = new Research('tech-steel_beams',
- ['citizen'],
- 1);
- researches['tech-mythril_beams'] = new Research('tech-mythril_beams',
- ['citizen'],
- 1);
- researches['tech-neutronium_walls'] = new Research('tech-neutronium_walls',
- ['citizen'],
- 1);
- researches['tech-aphrodisiac'] = new Research('tech-aphrodisiac',
- ['citizen'],
- 0);
- researches['tech-smokehouse'] = new Research('tech-smokehouse',
- ['food'],
- 1);
- researches['tech-lodge'] = new Research('tech-lodge',
- ['citizen'],
- 1);
- researches['tech-soul_well'] = new Research('tech-soul_well',
- [],
- 1);
- researches['tech-agriculture'] = new Research('tech-agriculture',
- ['food'],
- 0);
- researches['tech-farm_house'] = new Research('tech-farm_house',
- ['food', 'citizen'],
- 5);
- researches['tech-irrigation'] = new Research('tech-irrigation',
- ['food'],
- 1);
- researches['tech-silo'] = new Research('tech-silo',
- ['food'],
- 0);
- researches['tech-mill'] = new Research('tech-mill',
- ['food'],
- 1);
- researches['tech-windmill'] = new Research('tech-windmill',
- ['food'],
- 1);
- researches['tech-windturbine'] = new Research('tech-windturbine',
- ['food', 'power'],
- 5);
- researches['tech-wind_plant'] = new Research('tech-wind_plant',
- ['food'],
- 1);
- researches['tech-evil_wind_plant'] = new Research('tech-evil_wind_plant',
- [],
- 0);
- researches['tech-gmfood'] = new Research('tech-gmfood',
- ['food'],
- 0);
- researches['tech-foundry'] = new Research('tech-foundry',
- ['craft'],
- 7);
- researches['tech-artisans'] = new Research('tech-artisans',
- ['craft'],
- 4);
- researches['tech-apprentices'] = new Research('tech-apprentices',
- ['craft'],
- 4);
- researches['tech-carpentry'] = new Research('tech-carpentry',
- ['craft'],
- 4);
- researches['tech-demonic_craftsman'] = new Research('tech-demonic_craftsman',
- ['craft'],
- 4);
- researches['tech-master_craftsman'] = new Research('tech-master_craftsman',
- ['craft'],
- 4);
- researches['tech-brickworks'] = new Research('tech-brickworks',
- ['craft'],
- 4);
- researches['tech-machinery'] = new Research('tech-machinery',
- ['factory'],
- 4);
- researches['tech-cnc_machine'] = new Research('tech-cnc_machine',
- ['craft'],
- 4);
- researches['tech-vocational_training'] = new Research('tech-vocational_training',
- ['craft'],
- 4);
- researches['tech-assembly_line'] = new Research('tech-assembly_line',
- ['factory'],
- 4);
- researches['tech-automation'] = new Research('tech-automation',
- ['factory'],
- 4);
- researches['tech-laser_cutters'] = new Research('tech-laser_cutters',
- ['craft'],
- 3);
- researches['tech-theatre'] = new Research('tech-theatre',
- ['morale'],
- 7);
- researches['tech-playwright'] = new Research('tech-playwright',
- ['morale'],
- 6);
- researches['tech-magic'] = new Research('tech-magic',
- ['morale'],
- 7);
- researches['tech-radio'] = new Research('tech-radio',
- ['morale'],
- 7);
- researches['tech-tv'] = new Research('tech-tv',
- ['morale'],
- 7);
- researches['tech-casino'] = new Research('tech-casino',
- ['casino', 'power'],
- 0);
- researches['tech-dazzle'] = new Research('tech-dazzle',
- ['casino'],
- 0);
- researches['tech-casino_vault'] = new Research('tech-casino_vault',
- ['casino'],
- 0);
- researches['tech-mining'] = new Research('tech-mining',
- ['mine'],
- 7);
- researches['tech-bayer_process'] = new Research('tech-bayer_process',
- ['aluminum'],
- 10);
- researches['tech-smelting'] = new Research('tech-smelting',
- ['mine'],
- 2);
- researches['tech-steel'] = new Research('tech-steel',
- ['smelter', 'steel'],
- 8);
- researches['tech-blast_furnace'] = new Research('tech-blast_furnace',
- ['smelter', 'iron'],
- 2);
- researches['tech-bessemer_process'] = new Research('tech-bessemer_process',
- ['smelter', 'steel'],
- 2);
- researches['tech-oxygen_converter'] = new Research('tech-oxygen_converter',
- ['smelter', 'steel'],
- 2);
- researches['tech-electric_arc_furnace'] = new Research('tech-electric_arc_furnace',
- ['copper'],
- 2);
- researches['tech-rotary_kiln'] = new Research('tech-rotary_kiln',
- ['copper'],
- 2);
- researches['tech-metal_working'] = new Research('tech-metal_working',
- ['copper'],
- 7);
- researches['tech-iron_mining'] = new Research('tech-iron_mining',
- ['iron'],
- 7);
- researches['tech-coal_mining'] = new Research('tech-coal_mining',
- ['coal'],
- 7);
- researches['tech-storage'] = new Research('tech-storage',
- ['storage'],
- 5);
- researches['tech-reinforced_shed'] = new Research('tech-reinforced_shed',
- ['storage'],
- 5);
- researches['tech-barns'] = new Research('tech-barns',
- ['storage'],
- 5);
- researches['tech-warehouse'] = new Research('tech-warehouse',
- ['storage'],
- 5);
- researches['tech-cameras'] = new Research('tech-cameras',
- ['storage'],
- 5);
- researches['tech-pocket_dimensions'] = new Research('tech-pocket_dimensions',
- ['storage'],
- 5);
- researches['tech-containerization'] = new Research('tech-containerization',
- ['storage', 'crate'],
- 5);
- researches['tech-reinforced_crates'] = new Research('tech-reinforced_crates',
- ['storage', 'crate'],
- 5);
- researches['tech-cranes'] = new Research('tech-cranes',
- ['storage', 'crate'],
- 5);
- researches['tech-titanium_crates'] = new Research('tech-titanium_crates',
- ['storage', 'crate'],
- 5);
- researches['tech-mythril_crates'] = new Research('tech-mythril_crates',
- ['storage', 'crate'],
- 5);
- researches['tech-steel_containers'] = new Research('tech-steel_containers',
- ['storage', 'container'],
- 5);
- researches['tech-gantry_crane'] = new Research('tech-gantry_crane',
- ['storage', 'container'],
- 5);
- researches['tech-alloy_containers'] = new Research('tech-alloy_containers',
- ['storage', 'container'],
- 5);
- researches['tech-mythril_containers'] = new Research('tech-mythril_containers',
- ['storage', 'container'],
- 5);
- researches['tech-currency'] = new Research('tech-currency',
- ['money'],
- 10);
- researches['tech-market'] = new Research('tech-market',
- ['money', 'market'],
- 3);
- researches['tech-tax_rates'] = new Research('tech-tax_rates',
- ['money', 'tax'],
- 1);
- researches['tech-large_trades'] = new Research('tech-large_trades',
- ['money', 'market'],
- 0);
- researches['tech-corruption'] = new Research('tech-corruption',
- ['money', 'tax'],
- 1);
- researches['tech-massive_trades'] = new Research('tech-massive_trades',
- ['money', 'market'],
- 0);
- researches['tech-trade'] = new Research('tech-trade',
- ['trade'],
- 7);
- researches['tech-diplomacy'] = new Research('tech-diplomacy',
- ['trade'],
- 3);
- researches['tech-freight'] = new Research('tech-freight',
- ['trade'],
- 3);
- researches['tech-wharf'] = new Research('tech-wharf',
- ['trade', 'storage', 'crate', 'container'],
- 1);
- researches['tech-banking'] = new Research('tech-banking',
- ['money'],
- 1);
- researches['tech-investing'] = new Research('tech-investing',
- ['money'],
- 5);
- researches['tech-vault'] = new Research('tech-vault',
- ['money'],
- 2);
- researches['tech-bonds'] = new Research('tech-bonds',
- ['money'],
- 0);
- researches['tech-steel_vault'] = new Research('tech-steel_vault',
- ['money'],
- 0);
- researches['tech-eebonds'] = new Research('tech-eebonds',
- ['money'],
- 0);
- researches['tech-swiss_banking'] = new Research('tech-swiss_banking',
- ['money'],
- 0);
- researches['tech-safety_deposit'] = new Research('tech-safety_deposit',
- ['money'],
- 0);
- researches['tech-stock_market'] = new Research('tech-stock_market',
- ['money'],
- 0);
- researches['tech-hedge_funds'] = new Research('tech-hedge_funds',
- ['money'],
- 0);
- researches['tech-four_oh_one'] = new Research('tech-four_oh_one',
- ['money'],
- 0);
- researches['tech-mythril_vault'] = new Research('tech-mythril_vault',
- ['money'],
- 0);
- researches['tech-neutronium_vault'] = new Research('tech-neutronium_vault',
- ['money'],
- 0);
- researches['tech-home_safe'] = new Research('tech-home_safe',
- ['money'],
- 0);
- researches['tech-fire_proof_safe'] = new Research('tech-fire_proof_safe',
- ['money'],
- 0);
- researches['tech-monument'] = new Research('tech-monument',
- ['morale'],
- 0);
- researches['tech-tourism'] = new Research('tech-tourism',
- ['money'],
- 0);
- researches['tech-science'] = new Research('tech-science',
- ['knowledge'],
- 10);
- researches['tech-library'] = new Research('tech-library',
- ['knowledge'],
- 10);
- researches['tech-thesis'] = new Research('tech-thesis',
- ['knowledge'],
- 9);
- researches['tech-research_grant'] = new Research('tech-research_grant',
- ['knowledge'],
- 9);
- researches['tech-scientific_journal'] = new Research('tech-scientific_journal',
- ['knowledge'],
- 9);
- researches['tech-adjunct_professor'] = new Research('tech-adjunct_professor',
- ['knowledge'],
- 10);
- researches['tech-tesla_coil'] = new Research('tech-tesla_coil',
- ['knowledge'],
- 10);
- researches['tech-internet'] = new Research('tech-internet',
- ['knowledge'],
- 10);
- researches['tech-observatory'] = new Research('tech-observatory',
- ['knowledge'],
- 8);
- researches['tech-world_collider'] = new Research('tech-world_collider',
- [],
- 5);
- researches['tech-bioscience'] = new Research('tech-bioscience',
- ['knowledge'],
- 10);
- researches['tech-genetics'] = new Research('tech-genetics',
- ['gene'],
- 0);
- researches['tech-crispr'] = new Research('tech-crispr',
- ['gene'],
- 0);
- researches['tech-shotgun_sequencing'] = new Research('tech-shotgun_sequencing',
- ['gene'],
- 0);
- researches['tech-de_novo_sequencing'] = new Research('tech-de_novo_sequencing',
- ['gene'],
- 0);
- researches['tech-dna_sequencer'] = new Research('tech-dna_sequencer',
- ['gene'],
- 0);
- researches['tech-mad_science'] = new Research('tech-mad_science',
- ['knowledge'],
- 10);
- researches['tech-electricity'] = new Research('tech-electricity',
- ['power'],
- 9);
- researches['tech-industrialization'] = new Research('tech-industrialization',
- [],
- 9);
- researches['tech-electronics'] = new Research('tech-electronics',
- ['power'],
- 9);
- researches['tech-fission'] = new Research('tech-fission',
- ['power', 'uranium'],
- 7);
- researches['tech-arpa'] = new Research('tech-arpa',
- [],
- 5);
- researches['tech-rocketry'] = new Research('tech-rocketry',
- [],
- 9);
- researches['tech-robotics'] = new Research('tech-robotics',
- [],
- 9);
- researches['tech-lasers'] = new Research('tech-lasers',
- [],
- 9);
- researches['tech-artifical_intelligence'] = new Research('tech-artifical_intelligence',
- [],
- 9);
- researches['tech-quantum_computing'] = new Research('tech-quantum_computing',
- [],
- 9);
- researches['tech-thermomechanics'] = new Research('tech-thermomechanics',
- ['factory', 'alloy'],
- 5);
- researches['tech-quantum_manufacturing'] = new Research('tech-quantum_manufacturing',
- ['factory'],
- 5);
- researches['tech-worker_drone'] = new Research('tech-worker_drone',
- ['neutronium'],
- 10);
- researches['tech-uranium'] = new Research('tech-uranium',
- ['uranium'],
- 7);
- researches['tech-uranium_storage'] = new Research('tech-uranium_storage',
- ['uranium'],
- 6);
- researches['tech-uranium_ash'] = new Research('tech-uranium_ash',
- ['uranium'],
- 6);
- researches['tech-breeder_reactor'] = new Research('tech-breeder_reactor',
- ['power'],
- 4);
- researches['tech-mine_conveyor'] = new Research('tech-mine_conveyor',
- ['mine', 'power'],
- 4);
- researches['tech-oil_well'] = new Research('tech-oil_well',
- ['oil'],
- 5);
- researches['tech-oil_depot'] = new Research('tech-oil_depot',
- ['oil'],
- 5);
- researches['tech-oil_power'] = new Research('tech-oil_power',
- ['oil', 'power'],
- 7);
- researches['tech-titanium_drills'] = new Research('tech-titanium_drills',
- ['oil'],
- 5);
- researches['tech-alloy_drills'] = new Research('tech-alloy_drills',
- ['oil'],
- 4);
- researches['tech-fracking'] = new Research('tech-fracking',
- ['oil'],
- 4);
- researches['tech-mythril_drills'] = new Research('tech-mythril_drills',
- ['oil'],
- 2);
- researches['tech-mass_driver'] = new Research('tech-mass_driver',
- ['power'],
- 0);
- researches['tech-polymer'] = new Research('tech-polymer',
- ['factory', 'polymer'],
- 10);
- researches['tech-fluidized_bed_reactor'] = new Research('tech-fluidized_bed_reactor',
- ['factory', 'polymer'],
- 4);
- researches['tech-nano_tubes'] = new Research('tech-nano_tubes',
- ['factory', 'nano_tubes'],
- 5);
- researches['tech-stone_axe'] = new Research('tech-stone_axe',
- ['lumber'],
- 1);
- researches['tech-copper_axes'] = new Research('tech-copper_axes',
- ['lumber'],
- 1);
- researches['tech-iron_saw'] = new Research('tech-iron_saw',
- ['lumber'],
- 1);
- researches['tech-steel_saw'] = new Research('tech-steel_saw',
- ['lumber'],
- 1);
- researches['tech-iron_axes'] = new Research('tech-iron_axes',
- ['lumber'],
- 1);
- researches['tech-steel_axes'] = new Research('tech-steel_axes',
- ['lumber'],
- 1);
- researches['tech-titanium_axes'] = new Research('tech-titanium_axes',
- ['lumber'],
- 1);
- researches['tech-copper_sledgehammer'] = new Research('tech-copper_sledgehammer',
- ['stone'],
- 1);
- researches['tech-iron_sledgehammer'] = new Research('tech-iron_sledgehammer',
- ['stone'],
- 1);
- researches['tech-steel_sledgehammer'] = new Research('tech-steel_sledgehammer',
- ['stone'],
- 1);
- researches['tech-titanium_sledgehammer'] = new Research('tech-titanium_sledgehammer',
- ['stone'],
- 1);
- researches['tech-copper_pickaxe'] = new Research('tech-copper_pickaxe',
- ['mine'],
- 2);
- researches['tech-iron_pickaxe'] = new Research('tech-iron_pickaxe',
- ['mine'],
- 2);
- researches['tech-steel_pickaxe'] = new Research('tech-steel_pickaxe',
- ['mine'],
- 2);
- researches['tech-jackhammer'] = new Research('tech-jackhammer',
- ['mine'],
- 2);
- researches['tech-jackhammer_mk2'] = new Research('tech-jackhammer_mk2',
- ['mine'],
- 2);
- researches['tech-copper_hoe'] = new Research('tech-copper_hoe',
- ['food'],
- 2);
- researches['tech-iron_hoe'] = new Research('tech-iron_hoe',
- ['food'],
- 2);
- researches['tech-steel_hoe'] = new Research('tech-steel_hoe',
- ['food'],
- 2);
- researches['tech-titanium_hoe'] = new Research('tech-titanium_hoe',
- ['food'],
- 2);
- researches['tech-slave_pens'] = new Research('tech-slave_pens',
- ['slave'],
- 5);
- researches['tech-garrison'] = new Research('tech-garrison',
- ['army'],
- 9);
- researches['tech-mercs'] = new Research('tech-mercs',
- ['army', 'money'],
- 0);
- researches['tech-signing_bonus'] = new Research('tech-signing_bonus',
- ['army', 'money'],
- 0);
- researches['tech-hospital'] = new Research('tech-hospital',
- ['army'],
- 9);
- researches['tech-boot_camp'] = new Research('tech-boot_camp',
- ['army'],
- 7);
- researches['tech-bows'] = new Research('tech-bows',
- ['army'],
- 2);
- researches['tech-flintlock_rifle'] = new Research('tech-flintlock_rifle',
- ['army'],
- 2);
- researches['tech-machine_gun'] = new Research('tech-machine_gun',
- ['army'],
- 2);
- researches['tech-bunk_beds'] = new Research('tech-bunk_beds',
- ['army'],
- 10);
- researches['tech-rail_guns'] = new Research('tech-rail_guns',
- ['army'],
- 1);
- researches['tech-laser_rifles'] = new Research('tech-laser_rifles',
- ['army'],
- 1);
- researches['tech-space_marines'] = new Research('tech-space_marines',
- ['army'],
- 0);
- researches['tech-armor'] = new Research('tech-armor',
- ['army'],
- 2);
- researches['tech-plate_armor'] = new Research('tech-plate_armor',
- ['army'],
- 2);
- researches['tech-kevlar'] = new Research('tech-kevlar',
- ['army'],
- 2);
- researches['tech-black_powder'] = new Research('tech-black_powder',
- [],
- 0);
- researches['tech-dynamite'] = new Research('tech-dynamite',
- ['mine'],
- 3);
- researches['tech-anfo'] = new Research('tech-anfo',
- ['mine'],
- 3);
- researches['tech-mad'] = new Research('tech-mad',
- [],
- 10);
- researches['tech-cement'] = new Research('tech-cement',
- ['cement'],
- 5);
- researches['tech-rebar'] = new Research('tech-rebar',
- ['cement'],
- 4);
- researches['tech-steel_rebar'] = new Research('tech-steel_rebar',
- ['cement'],
- 4);
- researches['tech-portland_cement'] = new Research('tech-portland_cement',
- ['cement'],
- 4);
- researches['tech-screw_conveyor'] = new Research('tech-screw_conveyor',
- ['cement', 'power'],
- 4);
- researches['tech-hunter_process'] = new Research('tech-hunter_process',
- ['smelter', 'titanium'],
- 9);
- researches['tech-kroll_process'] = new Research('tech-kroll_process',
- ['smelter', 'titanium'],
- 3);
- researches['tech-cambridge_process'] = new Research('tech-cambridge_process',
- ['smelter', 'titanium'],
- 9);
- researches['tech-pynn_partical'] = new Research('tech-pynn_partical',
- ['storage'],
- 8);
- researches['tech-matter_compression'] = new Research('tech-matter_compression',
- ['storage', 'container'],
- 7);
- researches['tech-higgs_boson'] = new Research('tech-higgs_boson',
- ['storage'],
- 7);
- researches['tech-dimensional_compression'] = new Research('tech-dimensional_compression',
- ['storage', 'garage'],
- 5);
- researches['tech-theology'] = new Research('tech-theology',
- ['religion'],
- 4);
- researches['tech-fanaticism'] = new Research('tech-fanaticism',
- ['religion'],
- 4);
- researches['tech-ancient_theology'] = new Research('tech-ancient_theology',
- ['religion'],
- 4);
- researches['tech-study'] = new Research('tech-study',
- ['religion'],
- 4);
- researches['tech-deify'] = new Research('tech-deify',
- ['religion'],
- 4);
- researches['tech-indoctrination'] = new Research('tech-indoctrination',
- ['religion', 'knowledge'],
- 4);
- researches['tech-missionary'] = new Research('tech-missionary',
- ['religion', 'trade'],
- 4);
- researches['tech-zealotry'] = new Research('tech-zealotry',
- ['religion', 'army'],
- 4);
- researches['tech-anthropology'] = new Research('tech-anthropology',
- ['religion'],
- 4);
- researches['tech-mythology'] = new Research('tech-mythology',
- ['religion', 'knowledge'],
- 4);
- researches['tech-archaeology'] = new Research('tech-archaeology',
- ['religion', 'knowledge'],
- 4);
- researches['tech-merchandising'] = new Research('tech-merchandising',
- ['religion', 'money', 'tax'],
- 0);
- researches['tech-astrophysics'] = new Research('tech-astrophysics',
- ['space'],
- 5);
- researches['tech-rover'] = new Research('tech-rover',
- ['space'],
- 10);
- researches['tech-probes'] = new Research('tech-probes',
- ['space'],
- 10);
- researches['tech-starcharts'] = new Research('tech-starcharts',
- ['space'],
- 5);
- researches['tech-colonization'] = new Research('tech-colonization',
- ['space'],
- 10);
- researches['tech-red_tower'] = new Research('tech-red_tower',
- ['space', 'power'],
- 3);
- researches['tech-space_manufacturing'] = new Research('tech-space_manufacturing',
- ['space', 'factory'],
- 3);
- researches['tech-exotic_lab'] = new Research('tech-exotic_lab',
- ['space', 'knowledge', 'power'],
- 0);
- researches['tech-dyson_sphere'] = new Research('tech-dyson_sphere',
- ['space', 'power', 'swarm'],
- 0);
- researches['tech-dyson_swarm'] = new Research('tech-dyson_swarm',
- ['space', 'power', 'swarm'],
- 0);
- researches['tech-swarm_plant'] = new Research('tech-swarm_plant',
- ['space', 'power', 'swarm'],
- 0);
- researches['tech-space_sourced'] = new Research('tech-space_sourced',
- ['space', 'swarm', 'iron'],
- 0);
- researches['tech-swarm_plant_ai'] = new Research('tech-swarm_plant_ai',
- ['space', 'power', 'swarm'],
- 0);
- researches['tech-swarm_control_ai'] = new Research('tech-swarm_control_ai',
- ['space', 'swarm', 'power'],
- 0);
- researches['tech-quantum_swarm'] = new Research('tech-quantum_swarm',
- ['space', 'swarm', 'power'],
- 0);
- researches['tech-gps'] = new Research('tech-gps',
- ['space',' trade'],
- 0);
- researches['tech-nav_beacon'] = new Research('tech-nav_beacon',
- ['space', 'power'],
- 3);
- researches['tech-atmospheric_mining'] = new Research('tech-atmospheric_mining',
- ['space', 'mine', 'helium_3'],
- 7);
- researches['tech-helium_attractor'] = new Research('tech-helium_attractor',
- ['space', 'helium_3'],
- 7);
- researches['tech-zero_g_mining'] = new Research('tech-zero_g_mining',
- ['space', 'mine'],
- 0);
- researches['tech-elerium_mining'] = new Research('tech-elerium_mining',
- ['space', 'elerium'],
- 10);
- researches['tech-laser_mining'] = new Research('tech-laser_mining',
- ['space', 'mine'],
- 4);
- researches['tech-elerium_tech'] = new Research('tech-elerium_tech',
- ['space', 'elerium'],
- 10);
- researches['tech-elerium_reactor'] = new Research('tech-elerium_reactor',
- ['space', 'elerium', 'power'],
- 0);
- researches['tech-neutronium_housing'] = new Research('tech-neutronium_housing',
- ['space', 'citizen'],
- 0);
- researches['tech-unification'] = new Research('tech-unification',
- ['unification'],
- 10);
- researches['tech-wc_conquest'] = new Research('tech-wc_conquest',
- ['unification'],
- 10);
- researches['tech-wc_morale'] = new Research('tech-wc_morale',
- ['unification'],
- 10);
- researches['tech-wc_money'] = new Research('tech-wc_money',
- ['unification'],
- 10);
- researches['tech-wc_reject'] = new Research('tech-wc_reject',
- ['unification'],
- 10);
- researches['tech-genesis'] = new Research('tech-genesis',
- ['space'],
- 10);
- researches['tech-star_dock'] = new Research('tech-star_dock',
- ['space'],
- 10);
- researches['tech-interstellar'] = new Research('tech-interstellar',
- ['space'],
- 5);
- researches['tech-genesis_ship'] = new Research('tech-genesis_ship',
- ['space'],
- 10);
- researches['tech-genetic_decay'] = new Research('tech-genetic_decay',
- ['gene'],
- 10);
- }
- class ArpaAction extends Action {
- constructor(id, tags, priority, res) {
- super(id, tags, priority);
- this.res = res;
- }
- get unlocked() {
- try {
- let btn = document.querySelector('#arpa'+this.id+' > div.buy > button.button.x10');
- return (btn !== null);
- } catch(e) {
- console.log("Error:", this.id, "Unlocked");
- return false;
- }
- }
- get enabled() {
- return settings.arpa[this.id];
- }
- get rank() {
- try {
- let rankLabel = document.querySelector('#arpa'+this.id+' > .head > .rank');
- let rankStr = rankLabel.innerText;
- let reg = /Level - ([\d]+)/.exec(rankStr);
- return parseInt(reg[1]);
- } catch(e) {
- console.log("Error:", this.id, "Rank");
- return null;
- }
- }
- getResDep(resid) {
- if (this.res === null) {
- return null;
- }
- return this.res[resid.toLowerCase()] * (1.05 ** this.rank) / 10;
- }
- click() {
- try {
- let btn = document.querySelector('#arpa'+this.id+' > div.buy > button.button.x10');
- btn.click();
- return true;
- } catch(e) {
- console.log("Error:", this.id, "Click");
- return false;
- }
- }
- }
- var arpas = {};
- function loadArpas() {
- if (!settings.hasOwnProperty('actions')) {settings.actions = {};}
- arpas.lhc = new ArpaAction('lhc',
- ['arpa'],
- 5,
- {money:2500000,
- knowledge:500000,
- copper:125000,
- cement:250000,
- steel:187500,
- titanium:50000,
- polymer:12000});
- arpas.stock_exchange = new ArpaAction('stock_exchange',
- ['arpa'],
- 5,
- {money:3000000,
- plywood:25000,
- brick:20000,
- wrought_Iron:10000});
- arpas.launch_facility = new ArpaAction('launch_facility',
- ['arpa'],
- 10,
- {money:2000000,
- knowledge:500000,
- cement:150000,
- oil:20000,
- sheet_metal:15000,
- alloy:25000});
- arpas.monument = new ArpaAction('monument', ['arpa'], 5);
- let type = null;
- try {
- type = $('#arpamonument > .head > .desc')[0].innerText;
- } catch(e) {
- //console.log("Error: could not load Monument");
- }
- if (type !== null) {
- switch(type) {
- case "Obelisk":
- {
- arpas.monument.res = {stone:1000000};
- break;
- }
- case "Statue":
- {
- arpas.monument.res = {aluminium:350000};
- break;
- }
- case "Sculpture":
- {
- arpas.monument.res = {steel:300000};
- break;
- }
- case "Monolith":
- {
- arpas.monument.res = {cement:300000};
- break;
- }
- }
- }
- }
- class StorageAction extends Action {
- constructor(id, tags, priority, res) {
- super(id, tags, priority);
- this.res = res;
- }
- get unlocked() {
- if (this.id == 'crate') {
- return researched('tech-containerization');
- } else {
- return researched('tech-steel_containers');
- }
- }
- get name() {
- return this.id.charAt(0).toUpperCase() + this.id.slice(1)
- }
- get full() {
- try {
- let data = $('#cnt'+this.name+'s')[0].innerText.split(' / ');
- return (parseInt(data[0]) == parseInt(data[1]));
- } catch(e) {
- console.log("Error:", this.id, "Full");
- }
- }
- getResDep(resid) {
- if (this.res === null) {
- return null;
- }
- return this.res[resid.toLowerCase()];
- }
- click() {
- // Ensuring no modal conflicts
- console.log(this);
- let addBtn = $('#createHead button');
- if (this.id == 'crate'){
- addBtn = addBtn[0];
- }else{
- addBtn = addBtn[1];
- }
- for (let i = 0; i < 10; i++) {
- addBtn.click();
- //console.log(this.id, i, addBtn, '#modal'+this.name+'s > span:nth-child(2) > button');
- }
- return true;
- }
- }
- var storages = {};
- function loadStorages() {
- if (!settings.hasOwnProperty('actions')) {settings.actions = {};}
- storages.Crate = new StorageAction('crate',
- ['storage'], 0,
- (resources.Lumber.unlocked) ?
- {plywood:100}
- :
- {stone:2000});
- storages.Container = new StorageAction('container',
- ['storage'], 0,
- {steel:1250});
- }
- class SupportProducer {
- constructor(name, id, type, produce, consume, unlock_research) {
- this.name = name;
- this.id = id;
- this.type = type;
- this.produce = produce;
- this.consume = consume;
- this.unlock_research = unlock_research;
- this.numLabel = null;
- this.decBtn = null;
- this.incBtn = null;
- try {
- this.numLabel = $('#'+this.id+' > a > .count')[0];
- this.decBtn = $('#'+this.id+' > .off')[0];
- this.incBtn = $('#'+this.id+' > .on')[0];
- } catch(e) {
- //console.log("Error: Could not load support producer", this.name);
- }
- }
- get unlocked() {
- if (this.unlock_research !== undefined) {
- return $('#'+this.id).length > 0 && researched(this.unlock_research);
- }
- return $('#'+this.id).length > 0;
- }
- get numTotal() {
- return parseInt(this.numLabel.innerText);
- }
- get numOn() {
- return parseInt(this.incBtn.innerText);
- }
- get numOff() {
- return parseInt(this.decBtn.innerText);
- }
- }
- var elecProducers = {}
- function loadElecProducers() {
- elecProducers.Coal = new SupportProducer("Coal Powerplant", "city-coal_power", "electricity", 5, [{res:resources.Coal,cost:0.35}]);
- elecProducers.Oil = new SupportProducer("Oil Powerplant", "city-oil_power", "electricity", 6, [{res:resources.Oil,cost:0.65}]);
- elecProducers.Wind = new SupportProducer("Wind Turbine", "city-mill", "electricity", 1, [{res:resources.Food,cost:0.1}], "tech-windturbine");
- elecProducers.Fission = new SupportProducer("Fission Reactor", "city-fission_power", "electricity",
- researched('tech-breeder_reactor') ? 16 : 14,
- [{res:resources.Uranium, cost:0.1}]);
- }
- class SupportConsumer {
- constructor(name, id, type, consume, priority, unlock_research) {
- this.name = name;
- this.id = id;
- this.type = type;
- this.consume = consume;
- this.unlock_research = unlock_research;
- let skey = 'sup-prio' + this.id;
- if(settings.hasOwnProperty(skey)){
- this.priority = settings[skey];
- } else {
- this.priority = priority;
- settings[skey] = priority;
- }
- this.numLabel = null;
- this.decBtn = null;
- this.incBtn = null;
- try {
- this.numLabel = $('#'+this.id+' > a > .count')[0];
- this.decBtn = $('#'+this.id+' > .off')[0];
- this.incBtn = $('#'+this.id+' > .on')[0];
- } catch(e) {
- //console.log("Error: Could not load support consumer", this.name);
- }
- }
- get unlocked() {
- if (this.unlock_research !== undefined) {
- return $('#'+this.id).length > 0 && researched(this.unlock_research);
- }
- return $('#'+this.id).length > 0;
- }
- get numTotal() {
- return parseInt(this.numLabel.innerText);
- }
- get numOn() {
- return parseInt(this.incBtn.innerText);
- }
- get numOff() {
- return parseInt(this.decBtn.innerText);
- }
- lowerPriority() {
- if (this.priority != 0) {
- this.priority -= 1;
- console.log("Lowering", this.name, "Priority", this.priority);
- settings['sup-prio' + this.id] = this.priority;
- }
- }
- higherPriority() {
- if (this.priority != 99) {
- this.priority += 1;
- console.log("Increasing", this.name, "Priority", this.priority);
- settings['sup-prio' + this.id] = this.priority;
- }
- }
- }
- var elecConsumers = {}
- function loadElecConsumers() {
- elecConsumers["Rock Quarry"] = new SupportConsumer("Rock Quarry", "city-rock_quarry", "electricity", 1, 1, "tech-mine_conveyor");
- elecConsumers.Sawmill = new SupportConsumer("Sawmill", "city-sawmill", "electricity", 1, 1);
- elecConsumers.Mine = new SupportConsumer("Mine", "city-mine", "electricity", 1, 2, "tech-mine_conveyor");
- elecConsumers["Coal Mine"] = new SupportConsumer("Coal Mine", "city-coal_mine", "electricity", 1, 2, "tech-mine_conveyor");
- elecConsumers["Cement Plant"] = new SupportConsumer("Cement Plant", "city-cement_plant", "electricity", 2, 3, "tech-screw_conveyor");
- elecConsumers.Apartment = new SupportConsumer("Apartment", "city-apartment", "electricity", 1, 9);
- elecConsumers.Factory = new SupportConsumer("Factory", "city-factory", "electricity", 3, 9);
- elecConsumers.Wardenclyffe = new SupportConsumer("Wardenclyffe", "city-wardenclyffe", "electricity", 2, 9);
- elecConsumers["Bioscience Lab"] = new SupportConsumer("Bioscience Lab", "city-biolab", "electricity", 2, 9);
- elecConsumers["Moon Base"] = new SupportConsumer("Moon Base", "space-moon_base", "electricity", 4, 9);
- }
- class Job {
- constructor(id, priority) {
- this.id = id;
- if (!settings.jobs.hasOwnProperty(this.id)) {settings.jobs[this.id] = {};}
- if (!settings.jobs[this.id].hasOwnProperty('priority')) {settings.jobs[this.id].priority = priority;}
- }
- get _priority() {return settings.jobs[this.id].priority;}
- set _priority(priority) {settings.jobs[this.id].priority = priority;}
- get name() {
- try {
- let _name = document.querySelector('#civ-'+this.id+' > .job_label > h3').innerText;
- if (_name === null || _name === undefined) {
- return this.id;
- }
- return _name;
- } catch(e) {
- console.log("Error:", this.id, "Name");
- return null;
- }
- }
- get employed() {
- try {
- let employees = document.querySelector('#civ-'+this.id+' > .job_label > .count');
- return parseInt(employees.innerText.split('/')[0]);
- } catch(e) {
- console.log("Error:", this.id, "Employed");
- return null;
- }
- }
- get maxEmployed() {
- try {
- let employees = document.querySelector('#civ-'+this.id+' > .job_label > .count');
- return parseInt((employees.innerText.split('/').length > 1) ? employees.innerText.split('/')[1] : -1);
- } catch(e) {
- console.log("Error:", this.id, "MaxEmployed");
- return null;
- }
- }
- get priority() {
- return this._priority;
- }
- lowerPriority() {
- if (this._priority == 0) {return;}
- this._priority -= 1;
- updateSettings();
- console.log("Lowering", this.id, "Priority", this._priority);
- }
- higherPriority() {
- if (this._priority == 9) {return;}
- this._priority += 1;
- updateSettings();
- console.log("Increasing", this.name, "Priority", this._priority);
- }
- get unlocked() {
- // Finding civicsTab
- try {
- let nav = $('#mainColumn > .content > .b-tabs > .tabs > ul > li > a > span');
- let civicsOn = false;
- for (let i = 0;i < nav.length;i++) {
- if (nav[i].innerText == "Civics") {
- let nth = i+1;
- civicsOn = $('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child('+nth+')')[0].style.display != 'none';
- break;
- }
- }
- return $('#civ-'+this.id)[0].style.display != 'none' && civicsOn;
- } catch(e) {
- console.log("Error:", this.id, "Unlocked");
- return false;
- }
- }
- hire() {
- try {
- let hireBtn = document.querySelector('#civ-'+this.id+' > .controls > .add');
- hireBtn.click();
- return true;
- } catch(e) {
- console.log("Error:", this.id, "Hire");
- return false;
- }
- }
- fire() {
- try {
- let fireBtn = document.querySelector('#civ-'+this.id+' > .controls > .sub');
- fireBtn.click();
- return true;
- } catch(e) {
- console.log("Error:", this.id, "Fire");
- return false;
- }
- }
- }
- class Unemployed extends Job {
- constructor(id, priority) {
- super(id, priority);
- }
- get priority() {
- if (this.name == 'Hunter') {
- return this._priority;
- } else {
- return 0;
- }
- }
- }
- class Craftsman extends Job {
- constructor(id, priority) {
- super(id, priority);
- }
- get name() {
- return "Craftsman";
- }
- get employed() {
- try {
- let employees = document.querySelector('#foundry > .job > .foundry > .count');
- return parseInt(employees.innerText.split('/')[0]);
- } catch(e) {
- console.log("Error:", this.id, "Employed");
- return null;
- }
- }
- get maxEmployed() {
- try {
- let employees = document.querySelector('#foundry > .job > .foundry > .count');
- return parseInt((employees.innerText.split('/').length > 1) ? employees.innerText.split('/')[1] : -1);
- } catch(e) {
- console.log("Error:", this.id, "MaxEmployed");
- return null;
- }
- }
- get unlocked() {
- try {
- // Finding civicsTab
- let nav = $('#mainColumn > .content > .b-tabs > .tabs > ul > li > a > span');
- let civicsOn = false;
- for (let i = 0;i < nav.length;i++) {
- if (nav[i].innerText == "Civics") {
- let nth = i+1;
- civicsOn = $('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child('+nth+')')[0].style.display != 'none';
- break;
- }
- }
- return $('#foundry')[0].style.display != 'none' && civicsOn && $('#foundry')[0].children.length > 0;
- } catch(e) {
- console.log("Error:", this.id, "Unlocked");
- return false;
- }
- }
- hire() {
- try {
- let hireBtn = document.querySelectorAll('#foundry .job')[1].children[1].children[1];
- hireBtn.click();
- return true;
- } catch(e) {
- console.log("Error:", this.id, "Hire");
- return false;
- }
- }
- fire() {
- try {
- let fireBtn = document.querySelectorAll('#foundry .job')[1].children[1].children[0];
- fireBtn.click();
- } catch(e) {
- console.log("Error:", this.id, "Fire");
- return false;
- }
- }
- }
- var jobs = {};
- function loadJobs() {
- if (!settings.hasOwnProperty('jobs')) {settings.jobs = {};}
- jobs.free = new Unemployed("free", 0);
- jobs.farmer = new Job("farmer", 1);
- jobs.lumberjack = new Job("lumberjack", 3);
- jobs.quarry_worker = new Job("quarry_worker", 3);
- jobs.miner = new Job("miner", 4);
- jobs.coal_miner = new Job("coal_miner", 4);
- jobs.cement_worker = new Job("cement_worker", 4);
- jobs.entertainer = new Job("entertainer", 8);
- jobs.professor = new Job("professor", 9);
- jobs.scientist = new Job("scientist", 9);
- jobs.banker = new Job("banker", 9);
- jobs.colonist = new Job("colonist", 7);
- jobs.space_miner = new Job("space_miner", 7);
- jobs.craftsman = new Craftsman("craftsman", 9);
- jobs.hell_surveyor = new Craftsman("hell_surveyor", 9);
- }
- class CraftJob extends Job {
- constructor(id, priority) {
- super(id, priority);
- }
- get hireBtn(){
- if (!this.hireBtnCache){
- let btn = document.getElementById('craft'+this.id);
- if (btn){
- this.hideBtnCache = btn.parentNode.children[1].children[1];
- return this.hideBtnCache;
- }
- return null;
- }
- return this.hideBtnCache;
- }
- get fireBtn() {
- if (!this.fireBtnCache){
- let btn = document.getElementById('craft'+this.id);
- if (btn){
- this.fireBtnCache = btn.parentNode.children[1].children[0];
- return this.fireBtnCache;
- }
- return null;
- }
- return this.fireBtnCache;
- }
- get name() {
- try {
- let _name = document.querySelector('#craft'+this.id+' > h3').innerText;
- if (_name === null || _name === undefined) {
- return this.id;
- }
- return _name;
- } catch(e) {
- console.log("Error:", this.id, "Name");
- return null;
- }
- }
- get employed() {
- try {
- let employees = document.querySelector('#craft'+this.id+' > .count');
- return parseInt(employees.innerText.split('/')[0]);
- } catch(e) {
- console.log("Error:", this.id, "Employed");
- return null;
- }
- }
- get maxEmployed() {
- try {
- let employees = document.querySelector('#craft'+this.id+' > .count');
- return parseInt((employees.innerText.split('/').length > 1) ? employees.innerText.split('/')[1] : -1);
- } catch(e) {
- console.log("Error:", this.id, "MaxEmployed");
- return null;
- }
- }
- get unlocked() {
- // Finding civicsTab
- let nav = $('#mainColumn > .content > .b-tabs > .tabs > ul > li > a > span');
- let civicsOn = false;
- for (let i = 0;i < nav.length;i++) {
- if (nav[i].innerText == "Civics") {
- let nth = i+1;
- civicsOn = $('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child('+nth+')')[0].style.display != 'none';
- break;
- }
- }
- return (typeof $('#craft'+this.id)[0] !== 'undefined') && civicsOn;
- }
- hire() {
- try {
- this.hireBtn.click();
- return true;
- } catch(e) {
- console.log("Error:", this.id, "Hire");
- return false;
- }
- }
- fire() {
- try {
- this.fireBtn.click();
- return true;
- } catch(e) {
- console.log("Error:", this.id, "Fire");
- return false;
- }
- }
- }
- var craftJobs = {};
- function loadCraftJobs() {
- if (!settings.hasOwnProperty('jobs')) {settings.jobs = {};}
- craftJobs.Plywood = new CraftJob("Plywood", 5);
- craftJobs.Brick = new CraftJob("Brick", 5);
- craftJobs.Wrought_Iron = new CraftJob("Wrought_Iron", 5);
- craftJobs.Sheet_Metal = new CraftJob("Sheet_Metal", 5);
- craftJobs.Mythril = new CraftJob("Mythril", 5);
- craftJobs.Aerogel = new CraftJob("Aerogel", 5);
- }
- let foodBtn = null;
- let lumberBtn = null;
- let stoneBtn = null;
- let rnaBtn = null;
- let dnaBtn = null;
- function loadFarm () {
- try {
- foodBtn = document.getElementById("city-food").getElementsByTagName("a")[0];
- } catch(e) {
- //console.log("Error: Food button could not be loaded");
- }
- try {
- lumberBtn = document.getElementById("city-lumber").getElementsByTagName("a")[0];
- } catch(e) {
- //console.log("Error: Lumber button could not be loaded");
- }
- try {
- stoneBtn = document.getElementById("city-stone").getElementsByTagName("a")[0];
- } catch(e) {
- //console.log("Error :Stone button could not be loaded");
- }
- try {
- rnaBtn = document.getElementById("evo-rna").getElementsByTagName("a")[0];
- } catch(e) {
- //console.log("Error: RNA button could not be loaded");
- }
- try {
- dnaBtn = document.getElementById("evo-dna").getElementsByTagName("a")[0];
- } catch(e) {
- //console.log("Error :DNA button could not be loaded");
- }
- }
- /***
- *
- * Settings
- *
- ***/
- function loadSettings() {
- // Farm
- loadFarm();
- // Resources
- loadResources();
- // Storages
- loadStorages();
- // Crafting
- loadCraftableResources();
- // Buildings
- loadBuildings();
- // Support
- loadElecProducers();
- loadElecConsumers();
- // Jobs
- loadJobs();
- loadCraftJobs();
- // Research
- loadResearches();
- // ARPA
- loadArpas();
- if (!settings.hasOwnProperty('autoPrint')) {
- settings.autoPrint = true;
- }
- if (!settings.hasOwnProperty('autoFarm')) {
- settings.autoFarm = false;
- }
- if (!settings.hasOwnProperty('autoEvolution')) {
- settings.autoEvolution = false;
- }
- if (!settings.hasOwnProperty('evolution')) {
- settings.evolution = "antid";
- }
- if (!settings.hasOwnProperty('Plasmid')) {
- settings.Plasmid = false;
- }
- if (!settings.hasOwnProperty('Craft')) {
- settings.Craft = false;
- }
- if (!settings.hasOwnProperty('CRISPR')) {
- settings.CRISPR = false;
- }
- if (!settings.hasOwnProperty('Trade')) {
- settings.Trade = false;
- }
- if (!settings.hasOwnProperty('autoCraft')) {
- settings.autoCraft = false;
- }
- if (!settings.hasOwnProperty('autoBuild')) {
- settings.autoBuild = false;
- }
- if (!settings.hasOwnProperty('autoSmelter')) {
- settings.autoSmelter = false;
- }
- if (!settings.hasOwnProperty('autoFactory')) {
- settings.autoFactory = false;
- }
- if (!settings.hasOwnProperty('autoSupport')) {
- settings.autoSupport = false;
- }
- if (!settings.hasOwnProperty('autoEmploy')) {
- settings.autoEmploy = false;
- }
- if (!settings.hasOwnProperty('autoTax')) {
- settings.autoTax = false;
- }
- if (!settings.hasOwnProperty('defaultMorale')) {
- settings.defaultMorale = 100;
- }
- if (!settings.hasOwnProperty('autoBattle')) {
- settings.autoBattle = false;
- }
- if (!settings.hasOwnProperty('autoResearch')) {
- settings.autoResearch = false;
- }
- if (!settings.hasOwnProperty('fanORanth')) {
- settings.fanORanth = "fanaticism";
- }
- if (!settings.hasOwnProperty('studyORdeify')) {
- settings.studyORdeify = "study";
- }
- if (!settings.hasOwnProperty('autoMarket')) {
- settings.autoMarket = false;
- }
- if (!settings.hasOwnProperty('minimumMoney')) {
- settings.minimumMoney = 0;
- }
- if (!settings.hasOwnProperty('autoARPA')) {
- settings.autoARPA = false;
- }
- if (!settings.hasOwnProperty('autoReset')) {
- settings.autoReset = false;
- }
- if (!settings.hasOwnProperty('arpa')) {
- settings.arpa = {
- lhc: false,
- stock_exchange: false,
- monument: false
- };
- }
- if (!settings.hasOwnProperty('log')) {settings.log = []};
- //console.log("Finished loading settings");
- }
- loadSettings();
- function updateSettings(){
- localStorage.setItem('settings', JSON.stringify(settings));
- }
- function importSettings() {
- console.log("Importing Settings");
- if ($('textarea#settingsImportExport').val().length > 0){
- let settingStr = $('textarea#settingsImportExport').val()
- settings = JSON.parse(settingStr);
- updateSettings();
- resetUI();
- }
- }
- function exportSettings() {
- console.log("Exporting Settings");
- $('textarea#settingsImportExport').val(JSON.stringify(settings));
- $('textarea#settingsImportExport').select();
- }
- /***
- *
- * automation functions
- *
- ***/
- function farm() {
- if(foodBtn!==null){foodBtn.click();}
- if(lumberBtn!==null){lumberBtn.click();}
- if(stoneBtn!==null){stoneBtn.click();}
- if(rnaBtn!==null){rnaBtn.click();}
- if(dnaBtn!==null){dnaBtn.click();}
- }
- let farmInterval = null;
- function autoFarm() {
- if(settings.autoFarm && farmInterval === null) {
- farmInterval = setInterval(farm, 10);
- } else {
- if (!settings.autoFarm && !(farmInterval === null)) {
- clearInterval(farmInterval);
- farmInterval = null;
- }
- }
- }
- let evoFarmActions = ["evo-rna", "evo-dna"];
- let evoRaceActions = ["evo-phagocytosis", "evo-chitin", "evo-chloroplasts",
- "evo-eggshell", "evo-mammals", "evo-athropods",
- "evo-ectothermic", "evo-endothermic",
- "evo-humanoid", "evo-gigantism", "evo-animalism", "evo-dwarfism",
- "evo-aquatic", "evo-demonic",
- "evo-entish", "evo-cacti",
- "evo-sporgar", "evo-shroomi",
- "evo-arraak", "evo-pterodacti", "evo-dracnid",
- "evo-tortoisan", "evo-gecko", "evo-slitheryn",
- "evo-human", "evo-elven", "evo-orc",
- "evo-orge", "evo-cyclops", "evo-troll",
- "evo-kobold", "evo-goblin", "evo-gnome",
- "evo-cath", "evo-wolven", "evo-centuar",
- "evo-mantis", "evo-scorpid", "evo-antid",
- "evo-sharkin", "evo-octigoran", "evo-balorg", "evo-imp"];
- let evoRaceTrees = {
- "entish":["evo-chloroplasts", "evo-entish"],
- "cacti":["evo-chloroplasts", "evo-cacti"],
- "sporgar":["evo-chitin", "evo-sporgar"],
- "shroomi":["evo-chitin", "evo-shroomi"],
- "arraak":["evo-phagocytosis", "evo-eggshell", "evo-endothermic", "evo-arraak"],
- "pterodacti":["evo-phagocytosis", "evo-eggshell", "evo-endothermic", "evo-pterodacti"],
- "dracnid":["evo-phagocytosis", "evo-eggshell", "evo-endothermic", "evo-dracnid"],
- "tortoisan":["evo-phagocytosis", "evo-eggshell", "evo-ectothermic", "evo-tortoisan"],
- "gecko":["evo-phagocytosis", "evo-eggshell", "evo-ectothermic", "evo-gecko"],
- "slitheryn":["evo-phagocytosis", "evo-eggshell", "evo-ectothermic", "evo-slitheryn"],
- "human":["evo-phagocytosis", "evo-mammals", "evo-humanoid", "evo-human"],
- "elven":["evo-phagocytosis", "evo-mammals", "evo-humanoid", "evo-elven"],
- "orc":["evo-phagocytosis", "evo-mammals", "evo-humanoid", "evo-orc"],
- "orge":["evo-phagocytosis", "evo-mammals", "evo-gigantism", "evo-orge"],
- "cyclops":["evo-phagocytosis", "evo-mammals", "evo-gigantism", "evo-cyclops"],
- "troll":["evo-phagocytosis", "evo-mammals", "evo-gigantism", "evo-troll"],
- "kobold":["evo-phagocytosis", "evo-mammals", "evo-dwarfism", "evo-kobold"],
- "goblin":["evo-phagocytosis", "evo-mammals", "evo-dwarfism", "evo-goblin"],
- "gnome":["evo-phagocytosis", "evo-mammals", "evo-dwarfism", "evo-gnome"],
- "cath":["evo-phagocytosis", "evo-mammals", "evo-animalism", "evo-cath"],
- "wolven":["evo-phagocytosis", "evo-mammals", "evo-animalism", "evo-wolven"],
- "centuar":["evo-phagocytosis", "evo-mammals", "evo-animalism", "evo-centuar"],
- "mantis":["evo-phagocytosis", "evo-athropods", "evo-mantis"],
- "scorpid":["evo-phagocytosis", "evo-athropods", "evo-scorpid"],
- "antid":["evo-phagocytosis", "evo-athropods", "evo-antid"],
- "sharkin":["evo-phagocytosis", "evo-aquatic", "evo-sharkin"],
- "octigoran":["evo-phagocytosis", "evo-aquatic", "evo-octigoran"],
- "octigoran":["evo-phagocytosis", "evo-aquatic", "evo-octigoran"],
- "balorg":["evo-phagocytosis", "evo-mammals", "evo-demonic", "evo-balorg"],
- "imp":["evo-phagocytosis", "evo-mammals", "evo-demonic", "evo-imp"]
- };
- let maxEvo = {
- "evo-membrane":5,
- "evo-organelles":1,
- "evo-nucleus":1,
- "evo-eukaryotic_cell":2,
- "evo-mitochondria":4
- };
- function autoEvolution() {
- let actions = document.querySelectorAll('#evolution .action');
- let seenChallenges = false;
- for(let i = 0; i < actions.length; i++){
- // Checking if purchasable
- let action = actions[i];
- if(action.className.indexOf("cna") < 0){
- // Checking if farming button
- if(action.id == "evo-rna" || action.id == "evo-dna") {continue;}
- // Stop buying garbage you idiot
- if(action.id in maxEvo && parseInt($('#'+action.id+' > a > .count')[0].innerText) > maxEvo[action.id]) {continue;}
- // Don't take sentience
- if(action.id == "evo-sentience") {continue;}
- // Check for challenge runs
- if(action.id == "evo-plasmid" && !settings.Plasmid) {continue;}
- if(action.id == "evo-craft" && !settings.Craft) {continue;}
- if(action.id == "evo-crispr" && !settings.CRISPR) {continue;}
- if(action.id == "evo-trade" && !settings.Trade) {continue;}
- if(action.id == "evo-junker" && !settings.Junker) {continue;}
- if(action.id == "evo-decay" && !settings.Decay) {continue;}
- if(action.id == "evo-joyless" && !settings.Joyless) {
- seenChallenges = true;
- continue;
- }
- // Checking for race decision tree
- if(evoRaceActions.includes(action.id) && !evoRaceTrees[settings.evolution].includes(action.id)) {continue;}
- action.children[0].click();
- if(settings.autoPrint){messageQueue("[AUTO-EVOLVE] " + action.children[0].children[0].innerText,'dark');}
- return;
- }
- }
- if(seenChallenges){
- // made our choices, go to next level
- $('#evo-sentience')[0].children[0].click();
- }
- }
- function autoCraft() {
- //console.log("AutoCrafting", craftableResources);
- for (let x in craftableResources) {
- craftableResources[x].craft();
- }
- }
- let storage = {};
- function getMaxCrates() {
- let crateMax = 0;
- // Freight Yards
- if (buildings['city-storage_yard'].unlocked) {
- let size = researched('tech-cranes') ? 20 : 10;
- if (researched('tech-wc_conquest')||researched('tech-wc_morale')||researched('tech-wc_money')||researched('tech-wc_reject')) {
- size += 10;
- }
- if (researched('tech-matter_compression')){
- size *= 2;
- }
- crateMax += (buildings['city-storage_yard'].numTotal * size);
- }
- // Wharfs
- if (buildings['city-wharf'].unlocked) {
- let vol = (researched('tech-wc_conquest')||researched('tech-wc_morale')||researched('tech-wc_money')||researched('tech-wc_reject')) ? 15 : 10
- if (researched('tech-matter_compression')){
- vol *= 2;
- }
- crateMax += (buildings['city-wharf'].numTotal * vol);
- }
- return crateMax;
- }
- function getMaxContainers() {
- let containerMax = 0;
- // Container Ports
- if (buildings['city-warehouse'].unlocked) {
- let size = researched('tech-gantry_crane') ? 20 : 10;
- if (researched('tech-wc_conquest')||researched('tech-wc_morale')||researched('tech-wc_money')||researched('tech-wc_reject')) {
- size += 10;
- }
- if (researched('tech-matter_compression')){
- size *= 2;
- }
- containerMax += (buildings['city-warehouse'].numTotal * size);
- }
- // Wharfs
- if (buildings['city-wharf'].unlocked) {
- let vol = (researched('tech-wc_conquest')||researched('tech-wc_morale')||researched('tech-wc_money')||researched('tech-wc_reject')) ? 15 : 10
- if (researched('tech-matter_compression')){
- vol *= 2;
- }
- containerMax += (buildings['city-wharf'].numTotal * vol);
- }
- // Garages
- if (buildings['space-garage'].unlocked) {
- let g_vol = researched('tech-dimensional_compression') ? 20 + arpas['lhc'].rank : 20;
- if (researched('tech-wc_conquest')||researched('tech-wc_morale')||researched('tech-wc_money')||researched('tech-wc_reject')) {
- g_vol += 10;
- }
- containerMax += (buildings['space-garage'].numTotal * g_vol);
- }
- return containerMax;
- }
- function getCurrentStorageNum(id) {
- //console.log("Getting Current Storage", id);
- storage[id] = {};
- let str = null;
- try {
- str = $('#stack-' + id + ' .current')[0].innerText;
- storage[id].current_crates = parseInt(str);
- } catch(e) {
- console.log("Error in reading crates", id);
- }
- try {
- str = $('#stack-' + id + ' .current')[1].innerText;
- storage[id].current_containers = parseInt(str);
- } catch(e) {
- console.log("Error in reading containers", id);
- }
- console.log(id, storage[id]);
- }
- function getCurrentStorageTotal() {
- storage = {};
- for (var x in resources) {
- if (!resources[x].crateable || !resources[x].unlocked) {
- continue;
- }
- getCurrentStorageNum(x);
- }
- }
- function removeStorage(excessStorage) {
- for (let i = 0;i < excessStorage.length;i++) {
- let id = excessStorage[i];
- console.log("Removing storage", id);
- // Removing unneeded crates
- console.log(id, storage[id].needed_crates, storage[id].needed_containers);
- if (storage[id].needed_crates < 0) {
- let removeBtn = $('#stack-' + id + ' .sub');
- for (let j = 0;j < -storage[id].needed_crates;j++) {
- removeBtn[0].click();
- }
- console.log("Removed", -storage[id].needed_crates, "Crates");
- }
- // Removing unneeded containers
- if (researched('tech-steel_containers') && storage[id].needed_containers < 0) {
- let removeBtn = $('#stack-' + id + ' .sub');
- for (let j = 0; j < -storage[id].needed_containers; j++) {
- removeBtn[1].click();
- }
- console.log("Removed", -storage[id].needed_containers, "Containers");
- }
- }
- return excessStorage.length * 300;
- }
- function addStorage(neededStorage) {
- for (let i = 0;i < neededStorage.length;i++) {
- let id = neededStorage[i];
- console.log("Adding Storage", id);
- // Checking if modal already open
- let addBtn = $('#stack-' + id + ' .add');
- // Adding needed crates
- if (storage[id].needed_crates > 0) {
- console.log("Adding", storage[id].needed_crates, "Crates");
- for (let j = 0; j < storage[id].needed_crates; j++) {
- addBtn[0].click();
- }
- }
- // Adding needed containers
- if (researched('tech-steel_containers') && storage[id].needed_containers > 0) {
- console.log("Adding", storage[id].needed_containers, "Containers");
- for (let j = 0; j < storage[id].needed_containers; j++) {
- addBtn[1].click();
- }
- }
- }
- }
- function autoStorage() {
- // Don't do autoStorage if haven't unlocked storage
- if (!researched('tech-containerization')) {return;}
- let crateBtn = $('#createHead .crate button');
- let containerBtn = $('#createHead .container button');
- [...Array(10)].forEach(() => crateBtn.click());
- if (researched('tech-steel_containers')){
- [...Array(10)].forEach(() => containerBtn.click());
- }
- // Finding
- let crateMax = getMaxCrates();
- let freeCrates = parseInt($('#cntCrates')[0].innerText.split(' / ')[0]);
- let containerMax = getMaxContainers();
- let freeContainers = parseInt($('#cntContainers')[0].innerText.split(' / ')[0]);
- getCurrentStorageTotal();
- // Finding total used crates;
- let curCrateTotal = 0;
- let curContainerTotal = 0;
- let error = false;
- for (var x in storage) {
- //console.log(x, storage[x]);
- // If there was an error in reading the storage values
- if (!storage[x].hasOwnProperty('current_crates')) {error = true;break;}
- curCrateTotal += storage[x].current_crates;
- curContainerTotal += storage[x].current_containers;
- }
- // Checking if error occured
- if (error) {
- console.log("Error in counting storage");
- return;
- }
- console.log("Current Crate Usage", curCrateTotal);
- console.log("Free Crates", freeCrates);
- console.log("Max Crates", crateMax);
- console.log("Current Container Usage", curContainerTotal);
- console.log("Free Containers", freeContainers);
- console.log("Max Containers", containerMax);
- // Getting total number of usable storage
- let totalCrates = curCrateTotal + freeCrates;
- let totalContainers = curContainerTotal + freeContainers;
- // Getting total priority
- let totalPriority = 0;
- for (x in storage) {
- totalPriority += resources[x].storePriority;
- }
- // Calculating crate differentials
- for (x in storage) {
- storage[x].wanted_crates = Math.round(totalCrates * resources[x].storePriority / totalPriority);
- storage[x].wanted_crates = Math.max(storage[x].wanted_crates, resources[x].storeMin);
- storage[x].needed_crates = storage[x].wanted_crates - storage[x].current_crates;
- storage[x].wanted_containers = Math.round(totalContainers * resources[x].storePriority / totalPriority);
- storage[x].needed_containers = storage[x].wanted_containers - storage[x].current_containers;
- console.log(
- x,
- "CR_WANT", storage[x].wanted_crates,
- "CR_NEED", storage[x].needed_crates,
- "CO_WANT", storage[x].wanted_containers,
- "CO_NEED", storage[x].needed_containers);
- }
- // Removing extra storage
- let excessStorage = [];
- for (x in storage) {
- if (storage[x].needed_crates < 0) {
- excessStorage.push(x);
- } else if (researched('tech-steel_containers') && storage[x].needed_containers < 0) {
- excessStorage.push(x);
- }
- }
- // Must wait for removing crates
- console.log("Excess", excessStorage);
- removeStorage(excessStorage);
- // Adding needed storage
- let neededStorage = [];
- for (x in storage) {
- if (storage[x].needed_crates > 0) {
- neededStorage.push(x);
- } else if (researched('tech-steel_containers') && storage[x].needed_containers > 0) {
- neededStorage.push(x);
- }
- }
- neededStorage.sort(function(a, b) {
- if (resources[b].storeMin > resources[a].storeMin) {
- return 1;
- }
- return resources[b].store_priority - resources[a].store_priority;
- });
- //console.log(neededStorage);
- addStorage(neededStorage);
- console.log('Finished Adding Storage');
- }
- class AutoBattler {
- constructor() {
- this.battleButton = document.querySelector('#garrison > div:nth-child(4) > div:nth-child(2) > span > button');
- this.addBattalion = document.querySelector('#battalion > .add');
- this.hireButton = document.querySelector('#garrison .bunk button');
- this.armySize = document.querySelector('#battalion .current');
- this.lowerCampaign = document.querySelector('#tactics > .sub');
- this.higherCampaign = document.querySelector('#tactics > .add');
- this.campaignStrengths = [
- { name: "Ambush", rating: 10 },
- { name: "Raid", rating: 50 },
- { name: "Pillage", rating: 100 },
- { name: "Assault", rating: 200 },
- { name: "Siege", rating: 500 }
- ];
- this.addToFortress = document.querySelectorAll('#fort .add')[0];
- this.addToPatrols = document.querySelectorAll('#fort .add')[1];
- this.attractor = document.querySelector('#portal-attractor');
- if (!this.battleButton){
- return;
- }
- this.advantageSpan = this.battleButton.parentElement;
- if (!this.hireButton){
- return;
- }
- this.hireSpan = this.hireButton.parentElement;
- }
- autoBattle() {
- if(researched('tech-fort')) {
- const fort = $('#fort .current');
- let have = parseInt(fort[0].innerText);
- let patrols = parseInt(fort[1].innerText);
- let size = parseInt(fort[2].innerText);
- if (this.addToFortress){
- this.addToFortress.click();
- }
- let turret = $('#portal-turret');
- let count = parseInt(turret.find('.count')[0].innerText);
- let on = turret.find('.on');
- let onCount = parseInt(on[0].innerText);
- if(patrols == 0){
- // shut off turrets to freeze invasions
- let off = turret.find('.off');
- let offCount = parseInt(off[0].innerText);
- count = count - offCount;
- while(count--){
- off.click();
- }
- }else if(onCount < count){
- // turn turrets back on
- count = count - onCount;
- while(count--){
- on.click();
- }
- }
- if (have >= size && this.addToPatrols){
- this.addToPatrols.click();
- }
- if (this.attractor){
- let danger = parseInt($('#fort span')[1].dataset.label);
- const attractor = $('#portal-attractor');
- let count = parseInt(attractor.find('.count')[0].innerText);
- let on = parseInt(attractor.find('.on')[0].innerText);
- if (danger < 1600){
- count = count - on;
- while(count--){
- attractor.find('.on').click();
- }
- }else if(on > 0){
- while(on--){
- attractor.find('.off').click();
- }
- }
- }
- }
- if (!this.battleButton) {
- return;
- }
- // Don't battle if the garrison hasn't been unlocked
- if (!researched('tech-garrison')) {return;}
- // Don't battle after unification
- if (researched('tech-wc_conquest')||researched('tech-wc_morale')||researched('tech-wc_money')||researched('tech-wc_reject')) {return;}
- // Adding soldiers
- for (let i = 0;i < this.soldierCount[0] - parseInt(this.armySize.innerText);i++) {
- this.addBattalion.click();
- }
- // Mercs
- let label = this.hireSpan.dataset.label;
- if (parseInt(label.match(/\d+/)) < 1000){
- this.hireButton.click();
- }
- // If no wounded and max soldiers, start battle
- if (this.woundedCount == 0 && this.soldierCount[0] / this.soldierCount[1] > .9 && this.soldierCount[0] != 0) {
- //console.log("Wounded: ", this.woundedCount, "Soldiers: ", this.soldierCount);
- // Changing campaign to match current rating
- for (let i = 0;i < 4;i++) {
- this.lowerCampaign.click();
- }
- for (let i = 1;i <= 4;i++) {
- //console.log(this.rating, "VS", this.campaignStrengths[i]);
- if (this.rating < this.campaignStrengths[i].rating) {
- break;
- } else {
- this.higherCampaign.click();
- }
- }
- // Don't battle if army rating lower than lowest campaign
- if (this.rating < this.campaignStrengths[0].rating) {return;}
- // Starting battle
- const battle = () => {
- const label = this.advantageSpan.dataset.label;
- if(label.indexOf('disadvantage') == -1 && parseInt(label) >= 30){
- this.battleButton.click();
- }else {
- clearInterval(timer);
- }
- }
- let timer = setInterval(battle, 1000);
- }
- }
- get soldierCount() {
- return document.querySelector('#garrison .barracks > span:nth-child(2)').innerText.split(' / ');
- }
- get woundedCount() {
- return document.querySelector('#garrison .barracks:nth-child(2) > span:nth-child(2)').innerText;
- }
- get rating() {
- return document.querySelector('#garrison > .header').children[1].children[1].childNodes[0].textContent;
- }
- }
- let autoBattler = new AutoBattler();
- function prioCompare(a, b) {
- return b.priority - a.priority;
- }
- class AutoEmployer {
- autoEmploy() {
- // only run every 10sec
- if (count % 10 != 0){
- return;
- }
- // Sorting based on priority
- let sortedJobs = [];
- let x;
- for (x in jobs) {
- if (jobs[x].unlocked) {
- sortedJobs.push(jobs[x]);
- }
- }
- sortedJobs.sort(prioCompare);
- let free_agents = 0;
- let total_priority = 0;
- // Find total free agents
- for (let i = 0;i < sortedJobs.length;i++) {
- let job = sortedJobs[i];
- // Free agents are determined by the ratio of priority
- // Priority 9 would have a ratio of 9/9, thus will always have no free agents
- // Priority 0 would have a ratio of 0/9, thus always will have free agents
- //console.log("Checking", job.name);
- // If Craftsman, move all workers to Plywood for reassignment
- /*
- if (job.id == "craftsman") {
- for (x in craftJobs) {
- let cjob = craftJobs[x];
- if (!cjob.unlocked) {continue;}
- for (let k = 0;k < cjob.employed;k++) {
- cjob.fireBtn.click();
- craftJobs.Plywood.hireBtn.click();
- }
- }
- }
- */
- total_priority += job.priority;
- // Job has no max employees (Unemployed, Farmer, Lumberjack, Quarry Worker)
- // Use the one more than the current employed
- let maxEmployed = (job.maxEmployed == -1) ? job.employed + 5 : job.maxEmployed;
- job.max_employed = maxEmployed;
- job.wanted = Math.round(maxEmployed /(1+Math.pow(Math.E, -job.priority+4.5)));
- job.need = job.wanted - job.employed;
- job.temp_employed = job.employed;
- //console.log(element.name, element.wanted, element.need);
- // If there is negative need, send to unemployed
- if (job.need < 0) {
- // Removal from craftsman requires additional work
- if (job.id == 'craftsman') {
- let totalRemove = -job.need;
- // Searching through craft jobs to remove
- for (x in craftJobs) {
- if (!craftJobs[x].unlocked) {continue;}
- craftJobs[x].temp_employed = craftJobs[x].employed;
- if (craftJobs[x].employed >= totalRemove) {
- for (let j = 0;j < totalRemove;j++) {
- craftJobs[x].fire();
- }
- craftJobs[x].temp_employed = craftJobs[x].employed - totalRemove;
- free_agents += totalRemove;
- break;
- } else {
- for (let j = 0;j < craftJobs[x].employed;j++) {
- craftJobs[x].fire();
- }
- craftJobs[x].temp_employed = 0;
- free_agents += craftJobs[x].employed;
- totalRemove -= craftJobs[x].employed;
- }
- }
- } else {
- for (let j = 0;j < -job.need;j++) {
- if (job.id != 'free') {
- job.fire();
- }
- job.temp_employed -= 1;
- free_agents += 1;
- }
- }
- }
- }
- //console.log("Finished freeing agents");
- // All free agents should be in unemployed
- // Now send those back that are needed
- for (let i = 0;i < sortedJobs.length;i++) {
- let job = sortedJobs[i];
- for (let i = 0;i < job.need;i++) {
- job.hire();
- job.temp_employed += 1;
- free_agents -= 1;
- }
- }
- //console.log("Finished sending initial agents");
- // Divy up the remaining free agents based on priority
- // The pie is split based on total priority points
- for (let i = 0;i < sortedJobs.length;i++) {
- let job = sortedJobs[i];
- if (job.id == "free") {continue;}
- //console.log("Sending secondary agents", job.name);
- let pie = Math.round(free_agents * job.priority / total_priority);
- for (let j = 0;j < Math.min(pie, job.max_employed - job.temp_employed);j++) {
- job.hire();
- free_agents -= 1;
- }
- total_priority -= job.priority;
- }
- // Divy up Craftsmen
- if (!jobs.craftsman.unlocked) {return;}
- //console.log("Divying up Craftsman");
- // Delay to get new craftman number
- setTimeout(function() {
- let totalCraftsman = 0;
- let total_priority = 0;
- for (x in craftJobs) {
- let cjob = craftJobs[x];
- if (!cjob.unlocked) {continue;}
- total_priority += cjob.priority;
- totalCraftsman += cjob.employed;
- }
- for (x in craftJobs) {
- let cjob = craftJobs[x];
- if (!cjob.unlocked) {continue;}
- cjob.want = Math.ceil(totalCraftsman * cjob.priority / total_priority)
- cjob.need = cjob.want - cjob.employed;
- if (cjob.need < 0) {
- for (let j = 0;j < -cjob.need;j++) {
- cjob.fire();
- }
- }else if(cjob.need > 0){
- for (let j = 0;j < cjob.need;j++) {
- cjob.hire();
- }
- }
- }
- // for (x in craftJobs) {
- // let cjob = craftJobs[x];
- // if (!cjob.unlocked) {continue;}
- // if (cjob.need > 0) {
- // for (let j = 0;j < cjob.need;j++) {
- // cjob.hire();
- // }
- // }
- // }
- }, 25);
- }
- lowerPriority(job) {
- job.lowerPriority();
- this.updateUI();
- }
- higherPriority(job) {
- job.higherPriority();
- this.updateUI();
- }
- updateUI() {
- let x;
- for (x in jobs) {
- let job = jobs[x];
- if (job.id == "free" && job.name != 'Hunter') {continue;}
- if (!job.unlocked) {continue;}
- let count;
- if (job.id == "craftsman") {
- count = $('#foundry > .job > .foundry.controls > .count')[0];
- } else {
- count = $('#civ-'+job.id+' > .ea-employ-settings > .count')[0];
- }
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(job.priority));
- }
- for (x in craftJobs) {
- let cjob = craftJobs[x];
- if (!cjob.unlocked) {continue;}
- let count = $('#craft'+cjob.id).parent().children()[2].children[1];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(cjob.priority));
- }
- }
- }
- let autoEmployer = new AutoEmployer();
- let moraleLabel = $('#morale').children(1)[0];
- let incTaxBtn = $('#tax_rates > .add');
- let decTaxBtn = $('#tax_rates > .sub');
- function autoTax() {
- // Don't start taxes if haven't researched
- if (!researched('tech-tax_rates')) {return;}
- let morale = parseInt(moraleLabel.innerText.substr(0,moraleLabel.innerText.length-1));
- if (morale > settings.defaultMorale) {
- for (let i = 0;i < morale - settings.defaultMorale;i++) {
- incTaxBtn.click();
- }
- } else {
- for (let i = 0;i < settings.defaultMorale - morale;i++) {
- decTaxBtn.click();
- }
- }
- }
- function shuffle(array) {
- array.sort(() => Math.random() - 0.5);
- }
- function autoMarket(bulkSell, ignoreSellRatio) {
- // Don't start autoMarket if haven't unlocked market
- if (!researched('tech-market')) {return;}
- let curMoney = resources.Money.amount;
- let maxMoney = resources.Money.storage;
- let multipliers = $('#market-qty').children();
- // If multipliers don't exist (aka cannot manual buy/sell) don't autoMarket
- if (multipliers === null || multipliers === undefined) {return;}
- let inputs = $(multipliers[2]).find('input');
- // no market challenge
- if(!inputs.length) return;
- if(!$(multipliers[2]).find('input')[0].checked){
- multipliers[2].click();
- }
- let qty = 25;
- setTimeout(function(){ //timeout needed to let the click on multiplier take effect
- if (count % 10 == 0){
- shuffle(resourcesArr);
- }
- resourcesArr.forEach((x) => {
- let resource = resources[x];
- // Continue if resource hasn't been unlocked
- if(!resource.unlocked) {return;}
- //console.log("Auto Market", x);
- let curResource = resource.amount;
- let maxResource = resource.storage;
- // Can sell resource
- //console.log(resource.autoSell, resource.ratio, resource.sellRatio);
- if (resource.autoSell && resource.ratio > resource.sellRatio) {
- //console.log("Autoselling", resource.name);
- let sellValue = getRealValue(resource.sellBtn.innerHTML.substr(1));
- let counter = 0;
- //console.log("CURM:", curMoney, "sellV", sellValue, "MAXM", maxMoney, "CURR", curResource, "MAXR", maxResource);
- while(true) {
- // Break if too much money, not enough resources, or sell ratio reached
- if (curMoney + sellValue >= maxMoney || curResource - qty <= 0 || curResource / maxResource < resource.sellRatio) {
- //console.log("Sold", counter*100);
- break;
- }
- counter += 1;
- resource.sellBtn.click();
- curMoney += sellValue;
- curResource -= qty;
- }
- }
- if(bulkSell === true) {
- return;
- }
- //console.log(resource.autoBuy, resource.ratio, resource.buyRatio);
- if (resource.autoBuy && resource.ratio < resource.buyRatio) {
- let buyValue = getRealValue(resource.buyBtn.innerHTML.substr(1));
- //console.log("CURM:", curMoney, "sellV", buyValue, "MAXM", maxMoney, "CURR", curResource, "MAXR", maxResource, "MINM", getMinMoney());
- while(true) {
- // Break if too little money, too much resources, or buy ratio reached
- if (curMoney - buyValue < getMinMoney() || curResource + qty > resource.storage || curResource / maxResource > resource.buyRatio) {
- break;
- }
- resource.buyBtn.click();
- curMoney -= buyValue;
- curResource += qty;
- }
- }
- });
- }, 25);
- }
- function autoBuild(){
- for (let x in buildings) {
- let building = buildings[x];
- if (!building.unlocked) {
- continue;
- }
- if (building.limit != -1 && building.numTotal >= building.limit) {
- continue;
- }
- let btn = document.getElementById(building.id);
- if (building.enabled && btn.className.indexOf('cna') < 0) {
- btn.getElementsByTagName("a")[0].click();
- if (settings.autoPrint){messageQueue("[AUTO-BUILD] " + btn.getElementsByTagName("a")[0].children[0].innerText, 'dark');}
- return;
- }
- }
- }
- function autoFactory() {
- if (!researched('tech-industrialization')) {return;}
- let factory = unsafeWindow.vars.global.city.factory;
- let res = unsafeWindow.vars.global.resource;
- let div = 0;
- div += researched('tech-industrialization') ? 1 : 0;
- div += researched('tech-polymer') ? 1 : 0;
- div += researched('tech-nano_tubes') ? 1 : 0;
- div += researched('tech-stanene') ? 1 : 0;
- let per = parseInt(factory.count / div);
- let overflow = factory.count % div;
- factory.Alloy = per + overflow;
- if(!researched('tech-polymer')) return;
- factory.Polymer = per;
- if(!researched('tech-nano_tubes')) return;
- factory.Nano = per;
- if(!researched('tech-stanene')) return;
- factory.Stanene = per;
- }
- function autoSmelter(limits) {
- if (!researched('tech-steel')) {return;}
- if(!limits){
- let limits = [];
- limits.Oil = null;
- limits.Coal = null;
- limits.Iron = null;
- limits.Steel = null;
- }
- let smelter = unsafeWindow.vars.global.city.smelter;
- let res = unsafeWindow.vars.global.resource;
- let total = smelter.count;
- smelter.Iron = 0;
- smelter.Steel = total;
- smelter.Wood = 0;
- smelter.Coal = 0;
- smelter.Oil = 0;
- let incrAndCheck = (part, check, diff, max) => {
- if(!max) return 0;
- smelter[part] = 0;
- let currDiff = res[check].diff;
- while(smelter[part] < max){
- if((currDiff - diff) >= 0){
- currDiff -= diff;
- smelter[part] += 1;
- }else{
- break;
- }
- }
- return max - smelter[part];
- }
- let left = total;
- if(researched('tech-oil_well')){
- left = incrAndCheck('Oil', 'Oil', .35, left);
- }
- if(researched('tech-coal_mining')){
- left = incrAndCheck('Coal', 'Coal', .25, left);
- }
- smelter.Wood = left;
- return;
- if(smelter.Steel){
- smelter.Steel = 0;
- while(smelter.Steel < total){
- smelter.Steel += 1;
- if(res.Iron.diff < 0){
- smelter.Steel -= 1;
- break;
- }
- }
- }
- smelter.Iron = total - smelter.Steel;
- if(researched('tech-oil_well')){
- }
- if(researched('tech-coal_mining')){
- }
- // Checking if modal already open
- if ($('.modal').length != 0) {
- // Closing modal
- let closeBtn = $('.modal-close')[0];
- if (closeBtn !== undefined) {closeBtn.click();}
- return;
- }
- // Ensuring no modal conflicts
- if (modal) {return;}
- modal = true;
- resources.Oil.temp_rate = resources.Oil.rate;
- resources.Iron.temp_rate = resources.Iron.rate;
- resources.Lumber.temp_rate = resources.Lumber.rate;
- resources.Coal.temp_rate = resources.Coal.rate;
- resources.Steel.temp_rate = resources.Steel.rate;
- console.log("Auto Smelting");
- // Opening modal
- $('#city-smelter > .special').click();
- // Delaying for modal animation
- setTimeout(function() {
- // Finding relevent elements
- let decBtns = $('#specialModal > div:nth-child(2) > .sub');
- let incBtns = $('#specialModal > div:nth-child(2) > .add');
- let labels = $('#specialModal > div:nth-child(2) > span > .current');
- let lumberInc = null; let lumberDec = null;
- let coalInc = null; let coalDec = null;
- let oilInc = null; let oilDec = null;
- let lumberNum = null; let coalNum = null; let oilNum = null;
- let lumberFuel = null; let coalFuel = null; let oilFuel = null;
- // Determining which fuel types are available
- if (decBtns.length == 2) {
- // Only two buttons. Either Ent type race with Coal/Oil, or haven't unlocked oil yet
- if (!resources.Oil.unlocked) {
- // Oil not unlocked, thus two buttons mean Lumber/Coal
- lumberInc = incBtns[0];
- lumberDec = decBtns[0];
- let temp = labels[0].attributes[0].value;
- lumberFuel = parseFloat(/Consume ([\d\.]+).*/.exec(temp)[1]);
- lumberNum = parseInt(/Lumber ([\d]+)/.exec(labels[0].innerText)[1]);
- coalInc = incBtns[1];
- coalDec = decBtns[1];
- temp = labels[1].attributes[0].value;
- coalFuel = parseFloat(/Burn ([\d\.]+).*/.exec(temp)[1]);
- coalNum = parseInt(/Coal ([\d]+)/.exec(labels[1].innerText)[1]);
- } else {
- // Must be Ent type race with Coal/Oil
- coalInc = incBtns[0];
- coalDec = decBtns[0];
- let temp = labels[0].attributes[0].value;
- coalFuel = parseFloat(/Burn ([\d\.]+).*/.exec(temp)[1]);
- coalNum = parseInt(/Coal ([\d]+)/.exec(labels[0].innerText)[1]);
- oilInc = incBtns[1];
- oilDec = decBtns[1];
- temp = labels[1].attributes[0].value;
- oilFuel = parseFloat(/Burn ([\d\.]+).*/.exec(temp)[1]);
- oilNum = parseInt(/Oil ([\d]+)/.exec(labels[1].innerText)[1]);
- }
- } else {
- // Three buttons means all fuels unlocked
- lumberInc = incBtns[0];
- lumberDec = decBtns[0];
- let temp = labels[0].attributes[0].value;
- lumberFuel = parseFloat(/Consume ([\d\.]+).*/.exec(temp)[1]);
- lumberNum = parseInt(/Lumber ([\d]+)/.exec(labels[0].innerText)[1]);
- coalInc = incBtns[1];
- coalDec = decBtns[1];
- temp = labels[1].attributes[0].value;
- coalFuel = parseFloat(/Burn ([\d\.]+).*/.exec(temp)[1]);
- coalNum = parseInt(/Coal ([\d]+)/.exec(labels[1].innerText)[1]);
- oilInc = incBtns[2];
- oilDec = decBtns[2];
- temp = labels[2].attributes[0].value;
- oilFuel = parseFloat(/Burn ([\d\.]+).*/.exec(temp)[1]);
- oilNum = parseInt(/Oil ([\d]+)/.exec(labels[2].innerText)[1]);
- }
- console.log("L", lumberNum, lumberFuel, "C", coalNum, coalFuel, "O", oilNum, oilFuel);
- if (lumberNum !== null) {resources.Lumber.temp_rate += lumberFuel * lumberNum;}
- if (coalNum !== null) {resources.Coal.temp_rate += coalFuel * coalNum;}
- if (oilNum !== null) {resources.Oil.temp_rate += oilFuel * oilNum;}
- // Finding iron/steel buttons
- let ironBtn = $('#specialModal .smelting button')[0];
- let steelBtn = $('#specialModal .smelting button')[1];
- let ironNum = ironBtn.innerText;
- let steelNum = steelBtn.innerText;
- ironNum = parseInt(/Iron Smelting: ([\d]+)/.exec(ironNum)[1]);
- steelNum = parseInt(/Steel Smelting: ([\d]+)/.exec(steelNum)[1]);
- let ironVal = ironBtn.attributes[0].value;
- let steelVal = steelBtn.attributes[0].value;
- let ironPercent = parseInt(/[^\d]+([\d]+)%/.exec(ironVal)[1]);
- let temp = /[^\d\.]*([\d\.]+)[^\d\.]*([\d\.]+)[^\d\.]*([\d\.]+)[^\d\.]*/.exec(steelVal);
- let steelCoalFuel = parseFloat(temp[1]);
- let steelIronFuel = parseFloat(temp[2]);;
- let steelProduce = parseFloat(temp[3]);;
- console.log("Iron", ironNum, ironPercent, "Steel", steelNum, steelIronFuel, steelCoalFuel, steelProduce);
- resources.Iron.temp_rate += steelIronFuel * steelNum;
- resources.Coal.temp_rate += steelCoalFuel * steelNum;
- resources.Steel.temp_rate -= steelProduce * steelNum;
- resources.Iron.temp_rate /= (1 + ironPercent*ironNum / 100);
- // Calculating changes
- let totalSmelters = buildings['city-smelter'].numTotal;
- let wantedIron = 0;
- let wantedSteel = 0;
- if (!limits || limits.Iron === null) {
- // Does not require iron, max out steel regardless
- wantedSteel = totalSmelters;
- } else {
- if (limits.Steel !== null) {
- // Requires both, find ratio
- wantedIron = Math.floor(limits.Iron.priority / (limits.Iron.priority + limits.Steel.priority));
- wantedSteel = totalSmelters - wantedIron;
- } else {
- // Requires only iron, max out
- wantedIron = totalSmelters;
- }
- }
- // Calculating Fuel
- let wantedLumber = 0;
- let wantedCoal = 0;
- let wantedOil = 0;
- let wantedTotal = totalSmelters;
- // Oil unlocked and not needed
- if (!limits || limits.Oil === null && oilInc !== null) {
- wantedOil = Math.floor(resources.Oil.temp_rate / oilFuel);
- wantedOil = (wantedOil > wantedTotal) ? wantedTotal : wantedOil;
- wantedTotal -= wantedOil;
- }
- console.log(totalSmelters, wantedTotal, wantedOil);
- // Coal unlocked and not needed
- if (!limits || limits.Coal === null && coalInc !== null) {
- // If Ent type race, fill rest with coal
- if (lumberInc === null) {
- wantedCoal = wantedTotal;
- } else {
- wantedCoal = Math.floor(resources.Coal.temp_rate / coalFuel);
- wantedCoal = (wantedCoal > wantedTotal) ? wantedTotal : wantedCoal;
- wantedTotal -= wantedCoal;
- }
- }
- // Fill the rest with lumber
- if (lumberInc !== null) {
- wantedLumber = wantedTotal;
- }
- console.log("L", wantedLumber, "C", wantedCoal, "O", wantedOil, "I", wantedIron,"S", wantedSteel);
- let pos_coal_rate = resources.Coal.temp_rate - wantedCoal*coalFuel - wantedSteel*steelCoalFuel;
- while(pos_coal_rate < 0) {
- console.log("L", wantedLumber, "C", wantedCoal, "O", wantedOil, "I", wantedIron,"S", wantedSteel, "CR", pos_coal_rate);
- // Try getting rid of coal
- if (wantedCoal > 0) {
- wantedCoal -= 1;
- if (lumberInc !== null) {
- // Put into lumber if exists
- wantedLumber += 1;
- } else {
- // Nothing to put into, get rid of one
- if (wantedSteel > 0) {
- wantedSteel -= 1;
- } else {
- wantedIron -= 1;
- }
- }
- } else if (wantedSteel > 0) {
- wantedSteel -= 1;
- wantedIron += 1;
- } else {
- break;
- }
- pos_coal_rate = resources.Coal.temp_rate - wantedCoal*coalFuel - wantedSteel*steelCoalFuel;
- }
- let pos_iron_rate = resources.Iron.temp_rate * (1 + ironPercent*wantedIron / 100) - wantedSteel*steelIronFuel;
- while(pos_iron_rate < 0) {
- console.log("L", wantedLumber, "C", wantedCoal, "O", wantedOil, "I", wantedIron,"S", wantedSteel, "IR", pos_iron_rate);
- // Get rid of some steel
- if (wantedSteel > 0) {
- wantedSteel -= 1;
- wantedIron += 1;
- } else {
- break;
- }
- pos_iron_rate = resources.Iron.temp_rate * (1 + ironPercent*wantedIron / 100) - wantedSteel*steelIronFuel;
- }
- console.log("L", wantedLumber, "C", wantedCoal, "O", wantedOil, "I", wantedIron,"S", wantedSteel);
- smelter.Iron = wantedIron;
- smelter.Steel = wantedSteel;
- smelter.Lumber = wantedLumber || 0;
- smelter.Coal = wantedCoal || 0;
- smelter.Oil = wantedOil || 0;
- // Closing modal
- let closeBtn = $('.modal-close')[0];
- if (closeBtn !== undefined) {closeBtn.click();}
- modal = false;
- }, 100);
- }
- function autoSupport() {
- // Don't start autoSupport if haven't unlocked power
- if (!researched('tech-electricity')) {return;}
- let x;
- // Generating unlocked producers and consumers
- let ps = [];
- let cs = [];
- for (x in elecProducers) {
- if (elecProducers[x].unlocked) {
- ps.push(elecProducers[x]);
- }
- }
- for (x in elecConsumers) {
- if (elecConsumers[x].unlocked) {
- cs.push(elecConsumers[x]);
- }
- }
- cs.sort(prioCompare);
- //console.log(ps, cs);
- // Turn on all possible producers
- for (let i = 0;i < ps.length;i++) {
- let p = ps[i];
- p.delta = 0;
- // Calculate whether to turn off
- let needTurnOff = false;
- for (let j = 0;j < p.consume.length;j++) {
- let res = p.consume[j].res;
- if (res.rate < 0) {
- needTurnOff = true;
- }
- }
- // A resource that this producer needs is decreasing
- if (needTurnOff && p.numOn > 0) {
- p.decBtn.click();
- p.delta = -1;
- continue;
- }
- // Calculate whether to turn on
- let canTurnOn = true;
- for (let j = 0;j < p.consume.length;j++) {
- let res = p.consume[j].res;
- let cost = p.consume[j].cost;
- if (res.rate < cost) {
- canTurnOn = false;
- }
- }
- if (canTurnOn && p.numOn < p.numTotal) {
- p.incBtn.click();
- p.delta = 1;
- }
- }
- // Calculate total possible power
- let totalPower = 0;
- for (let i = 0;i < ps.length;i++) {
- let p = ps[i];
- totalPower += p.produce * (p.numOn + p.delta)
- }
- //console.log("Total Power:", totalPower);
- // Distribute power to needed buildings
- for (let i = 0;i < cs.length;i++) {
- let c = cs[i];
- // Have some power left to give
- if (totalPower > 0) {
- let canTurnOn = (totalPower - (totalPower % c.consume)) / c.consume;
- canTurnOn = Math.min(canTurnOn, c.numTotal);
- if (c.numOn > canTurnOn) {
- for (let j = 0;j < c.numOn - canTurnOn;j++) {
- c.decBtn.click();
- }
- } else {
- for (let j = 0;j < canTurnOn - c.numOn;j++) {
- c.incBtn.click();
- }
- }
- totalPower -= canTurnOn * c.consume;
- //console.log(c, canTurnOn);
- // Run out of power
- } else {
- for (let j = 0;j < c.numOn;j++) {
- c.decBtn.click();
- }
- //console.log(c, 0);
- }
- }
- }
- function autoResearch(){
- let items = document.querySelectorAll('#tech .action');
- for(let i = 0; i < items.length; i++){
- if(items[i].className.indexOf("cna") < 0){
- // Skip blackhole, TODO add to setting choices
- if(items[i].id == "tech-exotic_infusion" || items[i].id == "tech-stabilize_blackhole"){continue;}
- // Checking if fanaticism or anthropology
- if(items[i].id == "tech-fanaticism" && settings.fanORanth == "anthropology") {continue;}
- if(items[i].id == "tech-anthropology" && settings.fanORanth == "fanaticism") {continue;}
- // Checking if study/deify ancients
- if(items[i].id == "tech-study" && settings.studyORdeify == "deify") {continue;}
- if(items[i].id == "tech-deify" && settings.studyORdeify == "study") {continue;}
- // Checking if unification
- if(items[i].id.indexOf("wc") >= 0 && items[i].id != "tech-wc_"+settings.uniChoice) {continue;}
- items[i].children[0].click();
- if(items[i].id.indexOf("wc") >= 0) {continue;}
- if(settings.autoPrint){messageQueue("[AUTO-RESEARCH] " + items[i].children[0].children[0].innerText,'dark');}
- setTimeout(resetUI, 2000);
- return;
- }
- }
- }
- function getAvailableBuildings() {
- let build = [];
- for (let x in buildings) {
- // Don't check buildings that aren't unlocked
- if (!buildings[x].unlocked) {continue;}
- // Don't check buildings that aren't enabled
- if (!buildings[x].enabled) {continue;}
- // Don't check buildings that met their limit
- if (buildings[x].limit != -1 && buildings[x].numTotal >= buildings[x].limit) {continue;}
- // Don't check buildings that can't be bought
- let btn = document.getElementById(buildings[x].id);
- if (btn.className.indexOf('cnam') >= 0) {continue;}
- build.push(buildings[x]);
- }
- //console.log(build);
- return build;
- }
- function getAvailableResearches() {
- let research = [];
- for (let x in researches) {
- // Don't check researches that aren't unlocked
- if (!researches[x].unlocked) {continue;}
- // Don't check researches that have already been researched
- if (researches[x].researched) {continue;}
- // Don't check researches that can't be bought
- let btn = document.getElementById(researches[x].id);
- if (btn.className.indexOf('cnam') >= 0) {continue;}
- // Research filters
- if(researches[x].id == "tech-fanaticism" && settings.fanORanth == "anthropology") {continue;}
- if(researches[x].id == "tech-anthropology" && settings.fanORanth == "fanaticism") {continue;}
- // Checking if study/deify ancients
- if(researches[x].id == "tech-study" && settings.studyORdeify == "deify") {continue;}
- if(researches[x].id == "tech-deify" && settings.studyORdeify == "study") {continue;}
- // Checking if unification
- if(researches[x].id.indexOf("wc") >= 0 && researches[x].id != "tech-wc_"+settings.uniChoice) {continue;}
- research.push(researches[x]);
- }
- //console.log(research);
- return research;
- }
- function getAvailableArpas() {
- let arpa = [];
- for (let x in arpas) {
- // Don't add ARPAs that are not unlocked
- if (!arpas[x].unlocked) {continue;}
- // Don't add ARPAs that are not enabled
- if (!arpas[x].enabled) {continue;}
- arpa.push(arpas[x]);
- }
- return arpa;
- }
- function getAvailableStorages() {
- let store = [];
- for (let x in storages) {
- // Don't add if not unlocked
- if (!storages[x].unlocked) {continue;}
- // Don't add if no more space
- if (storages[x].full) {continue;}
- store.push(storages[x]);
- }
- return store;
- }
- function getAvailableActions() {
- // Getting buildings and researches
- let actions = getAvailableBuildings().concat(getAvailableResearches()).concat(getAvailableArpas()).concat(getAvailableStorages());
- for (let i = 0;i < actions.length;i++) {
- actions[i].completion = {};
- actions[i].completionTime = {};
- actions[i].maxCompletionTime = 0;
- actions[i].limitingRes = null;
- actions[i].keptRes = {};
- }
- return actions;
- }
- function getAvailableResources() {
- let res = [];
- for (let x in resources) {
- // Don't check resources that aren't unlocked
- if (!resources[x].unlocked) {continue;}
- res.push(resources[x]);
- }
- for (let x in craftableResources) {
- // Don't check resources that aren't unlocked
- if (!craftableResources[x].unlocked) {continue;}
- res.push(craftableResources[x]);
- }
- console.log(res);
- return res;
- }
- function autoPrioritize(count) {
- // Finding available actions
- let actions = getAvailableActions();
- //console.log(actions);
- // Removing trade routes (if exists) for accurate rate
- resources.Money.temp_rate = resources.Money.rate;
- let totalTradeRoutes = null;
- if (researched('tech-trade')) {
- let totalTradeRouteStr = $('#tradeTotal').children()[0].innerText;
- totalTradeRoutes = parseInt(/Trade Routes [\d]+ \/ ([\d]+)/.exec(totalTradeRouteStr)[1]);
- // Clearing out trade routes
- for (let x in resources) {
- let resource = resources[x];
- resource.temp_rate = resource.rate;
- if (!(resource instanceof TradeableResource)) {continue;}
- if (resource.tradeNum < 0) {
- for (let i = 0;i < -resource.tradeNum;i++) {
- resource.tradeInc();
- resource.temp_rate += resource.tradeAmount;
- resources.Money.temp_rate -= resource.tradeSellCost;
- }
- } else {
- for (let i = 0;i < resource.tradeNum;i++) {
- resource.tradeDec();
- resource.temp_rate -= resource.tradeAmount;
- resources.Money.temp_rate += resource.tradeBuyCost;
- }
- }
- }
- }
- // Create priority queues for resources
- let res = getAvailableResources();
- let PQs = {}
- let limits = {}
- // Creating priority queues for each resource
- for (let i = 0;i < res.length;i++) {
- let curRes = res[i];
- let pq = [];
- // Checking each action for resource dependence
- for (let j = 0;j < actions.length;j++) {
- let cost = actions[j].getResDep(curRes.id);
- //console.log(actions[j].id, cost);
- if (cost !== null && cost > 0) {
- pq.push(actions[j]);
- // Setting up completion attribute
- actions[j].completion[curRes.id.toLowerCase()] = false;
- }
- }
- // Sorting actions by scaled priority
- pq.sort(function(a,b) {
- let aCost = priorityScale(a.res[curRes.id.toLowerCase()], a.priority, a);
- let bCost = priorityScale(b.res[curRes.id.toLowerCase()], b.priority, b);
- return aCost > bCost;
- });
- // Finding completion time and limiting resource
- for (let j = 0;j < pq.length;j++) {
- let action = pq[j];
- // Already completed with current resources
- // Scaling by 1.01 for rounding error
- if (curRes.amount >= action.getResDep(curRes.id) * 1.01) {
- action.completionTime[curRes.id] = 0;
- } else {
- let time = 0;
- if (researched('tech-trade') && res instanceof TradeableResource) {
- time = (action.getResDep(curRes.id) - curRes.amount) / curRes.temp_rate;
- } else {
- time = (action.getResDep(curRes.id) - curRes.amount) / curRes.rate;
- }
- time = (time < 0) ? 1 : time;
- action.completionTime[curRes.id] = time;
- //console.log(action.id, curRes.id, action.getResDep(curRes.id), curRes.amount, curRes.temp_rate, time);
- if (time > action.maxCompletionTime) {
- action.maxCompletionTime = time;
- action.limitingRes = curRes.id;
- }
- }
- }
- PQs[curRes.id] = pq;
- }
- // Determining completion
- for (let i = 0;i < res.length;i++) {
- let curRes = res[i];
- let pq = PQs[curRes.id];
- limits[curRes.id] = null;
- // Determining resource completion
- // Resource filled, set all to completion
- //console.log(curRes.id, curRes.ratio);
- if (curRes.ratio > 0.99) {
- //console.log(curRes.id, "ratio > 0.99. Set all to complete");
- for (let j = 0;j < pq.length;j++) {
- pq[j].completion[curRes.id.toLowerCase()] = true;
- }
- // Resource not full, allocate until reached action not filled.
- } else {
- let curAmount = curRes.amount;
- //console.log(curRes.id, curAmount);
- for (let j = 0;j < pq.length;j++) {
- let action = pq[j];
- //console.log(pq[j].id, pq[j].getResDep(curRes.id) , curAmount);
- // Scaling by 1.01 for rounding error
- if (action.getResDep(curRes.id) * 1.01 <= curAmount) {
- // Action can be achieved with this resource
- action.completion[curRes.id.toLowerCase()] = true;
- // Determining how much of the resource to save for this action
- if (action.limitingRes == curRes.id) {
- // This resource is the limiting factor, give nothing to the next actions
- curAmount -= action.getResDep(curRes.id);
- action.keptRes[curRes.id] = action.getResDep(curRes.id);
- } else {
- // This resource isn't the limiting factor, give some leeway
- // Higher priority, less leeway given
- // Limiting resource will take a long time to complete, give more leeway
- let priorityFactor = 1 / (1.0 + Math.exp(-0.1 * action.priority));
- let timeFactor = Math.exp(-.005 * action.maxCompletionTime);
- action.keptRes[curRes.id] = priorityFactor * timeFactor * action.getResDep(curRes.id)/2;
- curAmount -= priorityFactor * timeFactor * action.getResDep(curRes.id);
- }
- } else {
- // Action cannot be achieved with this resource
- limits[curRes.id] = action;
- break;
- }
- }
- }
- }
- // Purchasing complete actions
- actions.sort(prioCompare);
- console.log("ACT:", actions);
- for (let i = 0;i < actions.length;i++) {
- let action = actions[i];
- let canBuy = true;
- for (let x in action.completion) {
- if (!action.completion[x]) {
- canBuy = false;
- break;
- }
- }
- if (canBuy) {
- console.log(action.id, "can buy");
- let clicked = action.click();
- if (clicked) {
- if (settings.autoPrint) {
- messageQueue(getTotalGameDays().toString() + " [AUTO-PRIORITY] " + action.name, 'warning');
- }
- break;
- }
- }
- }
- if (settings.autoSmelter && (count % 20 == 0)) {
- autoSmelter(limits);
- }
- // Determining rate priorities
- console.log("LIM:", limits);
- if (researched('tech-trade')) {
- // Finding full resources
- let sellingRes = [];
- for (let x in resources) {
- if (!resources[x].unlocked) {continue;}
- if (!(resources[x] instanceof TradeableResource)) {continue;}
- if (resources[x].ratio < 0.99) {continue;}
- if (x == "Coal" || x == "Oil") {continue;}
- sellingRes.push(resources[x]);
- }
- // Sort by sell cost
- sellingRes.sort(function(a,b) {
- return a.tradeSellCost < b.tradeSellCost;
- });
- // Finding sequence of selling trade routes
- let sellSequence = [];
- for (let i = 0;i < sellingRes.length;i++) {
- let res = sellingRes[i];
- let maxRoutes = Math.floor(res.temp_rate / res.tradeAmount);
- let sellRoutes = (maxRoutes < totalTradeRoutes) ? maxRoutes : totalTradeRoutes;
- for (let j = 0;j < sellRoutes;j++) {sellSequence.push(res.id);}
- }
- console.log("SELL SEQ:", sellSequence);
- // Finding resource to focus on
- let buyRes = null;
- let focusList = [];
- for (let x in limits) {
- // There exists an action that requires this resource
- if (limits[x] === null) {continue;}
- // Excluding craftable resources
- if (!(x in resources)) {continue;}
- // Excluding knowledge
- if (x == 'Knowledge') {continue;}
- // Excluding actions whose resource is already filled
- if (limits[x].completion[x] == true) {continue;}
- if (buyRes === null) {
- buyRes = x;
- } else {
- let curPriority = isFinite(limits[buyRes].completionTime[buyRes]) ? limits[buyRes].completionTime[buyRes] : 10000;
- let nextPriority = isFinite(limits[x].completionTime[x]) ? limits[x].completionTime[x] : 10000;
- curPriority = priorityScale(Math.log(curPriority), limits[buyRes].priority);
- nextPriority = priorityScale(Math.log(nextPriority), limits[x].priority);
- //if (limits[buyRes].priority <= limits[x].priority) {buyRes = x;}
- if (curPriority > nextPriority) {buyRes = x;}
- //if (limits[buyRes].completionTime[buyRes] < limits[x].completionTime[x]) {buyRes = x;}
- }
- focusList.push({action:limits[x], res:x});
- //console.log(x, limits[x].id, limits[x].completionTime, priorityScale(Math.log(limits[x].completionTime[x]), limits[x].priority), limits[x].priority);
- }
- if (buyRes !== null) {console.log("Focusing on", buyRes, "for", limits[buyRes].name);}
- if (focusList.length > 0) {
- focusList.sort(function(a,b) {
- return prioCompare(a.action, b.action);
- });
- }
- let prioMultiplier = {
- Money:2,
- Food:0,
- Lumber:0,
- Stone:0,
- Furs:.5,
- Copper:.75,
- Iron:.75,
- Aluminium:.5,
- Cement:.75,
- Coal:0,
- Oil:3,
- Uranium:3,
- Steel:2,
- Titanium:5,
- Alloy:5
- };
- console.log("FOC LIST:", focusList);
- let focusSequence = [];
- let curNum = {};
- let curRatio = {};
- let wantedRatio = {};
- let totalPriority = 0;
- if (focusList.length > 0) {
- // Creating sequence of trade route allocations to match priority ratios
- let curError = 0;
- for (let i = 0;i < focusList.length;i++) {totalPriority += focusList[i].action.priority;}
- for (let i = 0;i < focusList.length;i++) {
- curNum[focusList[i].res] = 0;
- wantedRatio[focusList[i].res] = prioMultiplier[focusList[i].res] * focusList[i].action.priority / totalPriority;
- }
- for (let i = 0;i < totalTradeRoutes;i++) {
- // Calculating error based on next value choice
- let error = -1;
- let choice = -1;
- for (let j = 0;j < focusList.length;j++) {
- let total = i+1;
- let tempError = 0;
- // Finding new error based on adding this trade route
- for (let k = 0;k < focusList.length;k++) {
- if (j == k) {
- // Currently attempting to add a trade route to this resource
- tempError += (((curNum[focusList[k].res]+1) / total) - wantedRatio[focusList[k].res]) ** 2;
- } else {
- tempError += ((curNum[focusList[k].res] / total) - wantedRatio[focusList[k].res]) ** 2;
- }
- }
- if (error == -1 || tempError < error) {
- error = tempError;
- choice = j;
- }
- }
- focusSequence[i] = focusList[choice].res;
- curNum[focusList[choice].res] += 1;
- }
- console.log("FOC SEQ:", focusSequence);
- } else {
- for (let i = 0;i < totalTradeRoutes;i++) {
- focusSequence.push('Money');
- }
- }
- // Allocating trade routes
- let curFocus = 0;
- let curSell = 0;
- if (focusList.length > 0) {
- // Allocating all possible trade routes with given money
- let curFreeTradeRoutes = totalTradeRoutes;
- // Keeping fraction of base money for money
- if (wantedRatio.Money > 0) {resources.Money.temp_rate *= wantedRatio.Money;}
- while (resources.Money.temp_rate > 0 && curFreeTradeRoutes > 0) {
- //console.log("CUR", curFocus, focusSequence[curFocus]);
- if (focusSequence[curFocus] == 'Money') {
- //console.log("Focusing on Money");
- // Focusing on money, add a sell trade route
- if (curSell == sellSequence.length) {curFocus+=1;continue;}
- resources[sellSequence[curSell]].tradeDec();
- curFreeTradeRoutes -= 1;
- curSell += 1;
- curFocus += 1;
- } else {
- // Focusing on resource
- //console.log("Focusing on", focusSequence[curFocus]);
- if (resources.Money.temp_rate > resources[focusSequence[curFocus]].tradeBuyCost) {
- //console.log("Buying", focusSequence[curFocus], curFocus);
- resources[focusSequence[curFocus]].tradeInc();
- resources.Money.temp_rate -= resources[focusSequence[curFocus]].tradeBuyCost;
- curFreeTradeRoutes -= 1;
- curFocus += 1;
- } else {
- break;
- }
- }
- }
- // Begin allocating algorithm
- while (curFreeTradeRoutes > 0) {
- // Checking if can buy trade route
- if (focusSequence[curFocus] == 'Money') {curFocus += 1; continue;}
- if (resources.Money.temp_rate > resources[focusSequence[curFocus]].tradeBuyCost) {
- // Can buy trade route
- //console.log("Buying", focusSequence[curFocus], curFocus);
- resources[focusSequence[curFocus]].tradeInc();
- resources.Money.temp_rate -= resources[focusSequence[curFocus]].tradeBuyCost;
- curFreeTradeRoutes -= 1;
- curFocus += 1;
- } else {
- // Cannot buy trade route, sell instead
- if (curSell == sellSequence.length) {break;}
- resources[sellSequence[curSell]].tradeDec();
- resources.Money.temp_rate += resources[sellSequence[curSell]].tradeSellCost;
- curFreeTradeRoutes -= 1;
- curSell += 1;
- }
- }
- }
- /*
- // Checking if can fully allocate towards limiting resource
- if (buyRes !== null && buyRes !== undefined && buyRes != "Money") {
- // Limiting resource is not money
- // Allocate as much as you can already
- let curFreeTradeRoutes = totalTradeRoutes;
- let maxBuyRoutes = Math.floor(resources.Money.temp_rate / resources[buyRes].tradeBuyCost);
- while (resources.Money.temp_rate > 0 && curFreeTradeRoutes > 0) {
- if (resources.Money.temp_rate > resources[buyRes].tradeBuyCost) {
- resources[buyRes].tradeInc();
- resources.Money.temp_rate -= resources[buyRes].tradeBuyCost;
- curFreeTradeRoutes -= 1;
- } else {
- break;
- }
- }
- // Begin allocating selling routes
- for (let i = 0;i < sellingRes.length;i++) {
- let res = sellingRes[i];
- let maxRoutes = Math.floor(res.temp_rate / res.tradeAmount);
- let sellRoutes = (maxRoutes < curFreeTradeRoutes) ? maxRoutes : curFreeTradeRoutes;
- for (let j = 0;j < sellRoutes;j++) {
- res.tradeDec();
- resources.Money.temp_rate += res.tradeSellCost;
- curFreeTradeRoutes -= 1;
- if (curFreeTradeRoutes == 0) {break;}
- if (resources.Money.temp_rate > resources[buyRes].tradeBuyCost) {
- resources[buyRes].tradeInc();
- resources.Money.temp_rate -= resources[buyRes].tradeBuyCost;
- curFreeTradeRoutes -= 1;
- if (curFreeTradeRoutes == 0) {break;}
- }
- }
- }
- } else {
- // Limiting resource is money, or doesn't exist. Focus on money
- let curFreeTradeRoutes = totalTradeRoutes;
- for (let i = 0;i < sellingRes.length;i++) {
- let res = sellingRes[i];
- let maxRoutes = Math.floor(res.temp_rate / res.tradeAmount);
- if (maxRoutes < curFreeTradeRoutes) {
- for (let j = 0;j < maxRoutes;j++) {
- res.tradeDec();
- }
- curFreeTradeRoutes -= maxRoutes;
- } else {
- for (let j = 0;j < curFreeTradeRoutes;j++) {
- res.tradeDec();
- }
- break;
- }
- }
- } */
- }
- console.log("PQ:", PQs);
- }
- function autoTrade(limits) {
- //console.log("Beginning auto trade");
- let curMoneyRate = resources.Money.rate;
- let totalTradeRouteStr = $('#tradeTotal').children()[0].innerText;
- let totalTradeRoutes = parseInt(/Trade Routes [\d]+ \/ ([\d]+)/.exec(totalTradeRouteStr)[1]);
- let x;
- // Clearing out trade routes
- for (x in resources) {
- let resource = resources[x];
- if (!(resource instanceof TradeableResource)) {continue;}
- resource.temp_rate = resource.rate;
- if (resource.tradeNum < 0) {
- for (let i = 0;i < -resource.tradeNum;i++) {
- resource.tradeInc();
- resource.temp_rate += resource.tradeAmount;
- curMoneyRate -= resource.tradeSellCost;
- }
- } else {
- for (let i = 0;i < resource.tradeNum;i++) {
- resource.tradeDec();
- resource.temp_rate -= resource.tradeAmount;
- curMoneyRate += resource.tradeBuyCost;
- }
- }
- }
- // Finding full resources
- let sellingRes = [];
- for (x in resources) {
- if (!resources[x].unlocked) {continue;}
- if (!(resources[x] instanceof TradeableResource)) {continue;}
- if (resources[x].ratio < 0.99) {continue;}
- if (x == "Coal" || x == "Oil") {continue;}
- sellingRes.push(resources[x]);
- }
- // Finding resource to focus on
- let buyRes = null;
- for (x in limits) {
- // There exists an action that requires this resource
- if (limits[x] === null) {continue;}
- // Excluding craftable resources
- if (!(x in resources)) {continue;}
- // Excluding knowledge
- if (x == 'Knowledge') {continue;}
- // Excluding actions whose resource is already filled
- if (limits[x].completionTime[x] == 0) {continue;}
- if (buyRes === null) {
- buyRes = x;
- } else {
- let curPriority = isFinite(limits[buyRes].completionTime[buyRes]) ? limits[buyRes].completionTime[buyRes] : 10000;
- let nextPriority = isFinite(limits[x].completionTime[x]) ? limits[x].completionTime[x] : 10000;
- curPriority = priorityScale(Math.log(curPriority), limits[buyRes].priority);
- nextPriority = priorityScale(Math.log(nextPriority), limits[x].priority);
- //if (limits[buyRes].priority <= limits[x].priority) {buyRes = x;}
- if (curPriority > nextPriority) {buyRes = x;}
- }
- console.log(x, limits[x].id, limits[x].completionTime, priorityScale(Math.log(limits[x].completionTime[x]), limits[x].priority), limits[x].priority);
- }
- if (buyRes !== null) {console.log("Focusing on", buyRes, "for", limits[buyRes].name);}
- // Sort by sell cost
- sellingRes.sort(function(a,b) {
- return a.tradeSellCost < b.tradeSellCost;
- });
- // Allocating trade routes
- // Checking if can fully allocate towards limiting resource
- if (buyRes !== null && buyRes !== undefined && buyRes != "Money") {
- // Limiting resource is not money
- // Allocate as much as you can already
- let curFreeTradeRoutes = totalTradeRoutes;
- let maxBuyRoutes = Math.floor(curMoneyRate / resources[buyRes].tradeBuyCost);
- for (let j = 0;j < Math.min(maxBuyRoutes, totalTradeRoutes);j++) {
- resources[buyRes].tradeInc();
- curMoneyRate -= resources[buyRes].tradeBuyCost;
- curFreeTradeRoutes -= 1;
- }
- // Begin allocating selling routes
- for (let i = 0;i < sellingRes.length;i++) {
- let res = sellingRes[i];
- let maxRoutes = Math.floor(res.temp_rate / res.tradeAmount);
- let sellRoutes = (maxRoutes < curFreeTradeRoutes) ? maxRoutes : curFreeTradeRoutes;
- for (let j = 0;j < sellRoutes;j++) {
- res.tradeDec();
- curMoneyRate += res.tradeSellCost;
- curFreeTradeRoutes -= 1;
- if (curFreeTradeRoutes == 0) {break;}
- if (curMoneyRate > resources[buyRes].tradeBuyCost) {
- resources[buyRes].tradeInc();
- curMoneyRate -= resources[buyRes].tradeBuyCost;
- curFreeTradeRoutes -= 1;
- if (curFreeTradeRoutes == 0) {break;}
- }
- }
- }
- } else {
- // Limiting resource is money, or doesn't exist. Focus on money
- let curFreeTradeRoutes = totalTradeRoutes;
- for (let i = 0;i < sellingRes.length;i++) {
- let res = sellingRes[i];
- let maxRoutes = Math.floor(res.temp_rate / res.tradeAmount);
- if (maxRoutes < curFreeTradeRoutes) {
- for (let j = 0;j < maxRoutes;j++) {
- res.tradeDec();
- }
- curFreeTradeRoutes -= maxRoutes;
- } else {
- for (let j = 0;j < curFreeTradeRoutes;j++) {
- res.tradeDec();
- }
- break;
- }
- }
- }
- }
- function autoArpa(){
- // If haven't unlocked ARPA, don't autoArpa
- if (!researched('tech-arpa')) {return;}
- if(settings.arpa.lhc){
- let btn = document.querySelector("#arpalhc > div.buy > button.button.x1");
- if(btn != null && !wouldBreakMoneyFloor(26500)){
- btn.click();
- }
- }
- if(settings.arpa.stock_exchange){
- let btn = document.querySelector("#arpastock_exchange > div.buy > button.button.x1");
- if(btn != null && !wouldBreakMoneyFloor(30000)){
- btn.click();
- }
- }
- if(settings.arpa.monument){
- let btn = document.querySelector("#arpamonument > div.buy > button.button.x1");
- if(btn != null){
- btn.click();
- }
- }
- if(settings.arpa.launch_facility){
- let btn = document.querySelector("#arpalaunch_facility > div.buy > button.button.x1");
- if(btn != null && !wouldBreakMoneyFloor(20000)){
- btn.click();
- }
- }
- // speed up gene creation
- if(resources.Knowledge.amount == resources.Knowledge.storage){
- let btn = document.querySelectorAll('#arpaGenetics button')[2];
- if(btn) {
- let count = parseInt(resources.Knowledge.amount / 200000);
- while(count--){
- btn.click();
- }
- }
- }
- }
- function autoReset(){
- if (!researched('tech-mad')) {return;}
- const buttons = $('#mad button');
- if(buttons.length != 2){
- console.error('Wrong reset buttons', buttons);
- return;
- }
- const arm = buttons[0];
- const launch = buttons[1];
- if(arm.innerText.indexOf('Arm') == 0){
- arm.click();
- return; // skip a cycle for chance to stop
- }
- launch.click();
- }
- let count = 0;
- function fastAutomate() {
- //console.clear();
- //console.log(count);
- updateUI();
- loadSettings();
- updateSettings();
- autoFarm();
- let noKeys = !ctrlDown && !altDown && !shiftDown;
- if ($('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child(1)')[0].style.display != 'none') {
- // Evolution Automation
- if(settings.autoEvolution) {
- autoEvolution();
- }
- } else {
- // Civilization Automation
- if(settings.autoCraft && noKeys){
- autoCraft();
- }
- if(settings.autoBuild && !settings.autoPrioritize){
- autoBuild();
- }
- if(settings.autoSupport && noKeys) {
- autoSupport();
- }
- if(settings.autoEmploy && noKeys){
- autoEmployer.autoEmploy();
- }
- if(settings.autoTax && noKeys) {
- autoTax();
- }
- if(settings.autoBattle){
- autoBattler.autoBattle();
- }
- if(settings.autoResearch && !settings.autoPrioritize){
- autoResearch();
- }
- if(settings.autoMarket && noKeys){
- autoMarket();
- }
- if(settings.autoARPA && !settings.autoPrioritize){
- autoArpa();
- }
- if(settings.autoPrioritize) {
- autoPrioritize(count);
- }
- }
- count += 1;
- }
- setInterval(fastAutomate, 1000);
- function midAutomate() {
- let noKeys = !ctrlDown && !altDown && !shiftDown;
- if ($('#resStorage')[0] && settings.autoStorage) {
- autoStorage();
- }
- if(settings.autoReset && noKeys){
- autoReset();
- }
- if (settings.autoSmelter && noKeys) {
- autoSmelter();
- }
- if (settings.autoFactory && noKeys) {
- autoFactory();
- }
- }
- setInterval(midAutomate, 100000);
- //Temporary
- let stardockBtn = $('#space-star_dock > .special');
- function temp() {
- stardockBtn.click();
- setTimeout(function() {
- let seederBtn = $('#spcdock-seeder > .button')[0];
- let probeBtn = $('#spcdock-probes > .button')[0];
- seederBtn.click();
- probeBtn.click();
- setTimeout(function() {
- let exitBtn = $('.modal > .modal-close').click();
- }, 1000);
- }, 1000);
- }
- //setInterval(temp, 4000);
- function temp2() {
- if (resources.Knowledge.amount > 200000) {
- $('#arpaSequence > span > button')[1].click();
- }
- //resetUI();
- }
- //setInterval(temp2, 20000);
- // Refreshing page every 20min to update data-values in elements
- //HOW ABOUT not reloading the page for someone who plays ocasionally in a train with no wifi.
- //setInterval(function() {
- //location.reload();
- //}, 20 * 60 * 1000)
- // import vars.js
- var body = unsafeWindow.document.body;
- var script = unsafeWindow.document.createElement('script');
- script.type = 'module';
- const stuff = "import('./vars.js').then((module) => {window.vars = module;});" +
- "import('./main.js').then((module) => {window.main = module;});"
- script.innerHTML = stuff;
- body.appendChild(script);
- //worker
- var worker = new unsafeWindow.Worker('evolve.js');
- /***
- *
- * Setup UI
- *
- ***/
- function createSettingToggle(name, title, enabledCallBack, disabledCallBack){
- let parent = $('#resources');
- let toggle = $('<label tabindex="0" class="switch" id="'+name+'_toggle" style="" title="'+title+'"><input type="checkbox" value=false> <span class="check"></span><span>'+name+'</span></label>');
- let divLeft = $('<div id="'+name+'_left" style="float:left">').append(toggle).append($('</div>'));
- let divRight = $('<div id="'+name+'_right" style="float:right"></div>');
- let mainDiv = $('<div id="'+name+'" style="overflow:auto">').append(divLeft).append(divRight).append($('</div>'));
- parent.append(mainDiv);
- if(settings[name]){
- toggle.click();
- toggle.children('input').attr('value', true);
- if(enabledCallBack !== undefined){
- enabledCallBack();
- }
- }
- toggle.on('mouseup', function(e){
- if (e.which != 1) {return;}
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- settings[name] = state;
- console.log("Setting", name, "to", state);
- updateSettings();
- if(state && enabledCallBack !== undefined){
- enabledCallBack();
- } else if(disabledCallBack !== undefined){
- disabledCallBack()
- }
- });
- }
- function updateUI(){
- if ($('#autoPrint').length == 0) {
- createSettingToggle('autoPrint', 'Turns on print statements for autoscript messages');
- }
- if ($('.ea-autolog').length == 0) {
- createAutoLog();
- }
- if ($('#reload').length == 0) {
- let reloadBtn = $('<a class="button is-dark is-small" id="reload" title="Resets UI and internal data"><span>Reload</span></a>');
- reloadBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- resetUI();
- updateSettings();
- loadSettings();
- });
- $('#autoPrint_right').append(reloadBtn);
- }
- if ($('#autoFarm').length == 0){
- createSettingToggle('autoFarm', 'Turns on autofarming of resources');
- }
- // If not currently in the evolution stage (thus civilization stage
- if($('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child(1)')[0].style.display == 'none') {
- // These toggles only appear after the evolution stage is over
- // Creating Buildings Tab
- if ($('.ea-buildings-tab').length == 0) {
- createBuildingsTab();
- }
- // Create Research Tab
- if ($('.ea-research-tab').length == 0) {
- createResearchTab();
- }
- // Crafting requires foundries
- if ($('#autoStorage').length == 0 && researched('tech-containerization')) {
- createSettingToggle('autoStorage', 'Automatically assigns crates and containers to resources', createStorageSettings, removeStorageSettings);
- } else if (settings.autoStorage && $('.ea-storage-settings').length == 0 && researched('tech-containerization')) {
- createStorageSettings();
- }
- if ($('#autoCraft').length == 0 && researched('tech-foundry')) {
- createSettingToggle('autoCraft', 'Automatically crafts craftable resources when resource ratio is above 0.9', createCraftSettings, removeCraftSettings);
- } else if (settings.autoCraft && $('.ea-craft-settings').length == 0 && researched('tech-foundry')) {
- createCraftSettings();
- }
- if ($('#autoBuild').length == 0) {
- createSettingToggle('autoBuild', 'Automatically builds buildings when available. Can disable specific buildings with unique toggles', createBuildingSettings, removeBuildingSettings);
- } else if (settings.autoBuild && $('.ea-building-settings').length == 0) {
- createBuildingSettings();
- }
- if ($('#autoSmelter').length == 0 && researched('tech-smelting')) {
- createSettingToggle('autoSmelter', 'Automatically allocates resources in the smelter. See Buildings tab for more settings', createSmelterSettings, removeSmelterSettings);
- } else if (settings.autoSmelter && $('.ea-smelter-settings').length == 0 && researched('tech-smelting')) {
- createSmelterSettings();
- }
- if ($('#autoFactory').length == 0 && researched('tech-industrialization')) {
- createSettingToggle('autoFactory', 'Automatically allocates resources in the factory. See Buildings tab for more settings', createFactorySettings, removeFactorySettings);
- } else if (settings.autoFactory && $('.ea-factory-settings').length == 0 && researched('tech-factory')) {
- createFactorySettings();
- }
- // Support requires electricity
- if ($('#autoSupport').length == 0 && researched("tech-electricity")) {
- createSettingToggle('autoSupport', 'Automatically powers buildings and supports space buildings. See the Support Tab for more settings', createSupportSettings, removeSupportSettings);
- } else if (settings.autoSupport && $('.ea-support-settings').length == 0 && researched("tech-electricity")) {
- createSupportSettings();
- }
- if ($('#autoEmploy').length == 0) {
- createSettingToggle('autoEmploy', 'Autoemploys workers. See Civics page for job priorities', createEmploySettings, removeEmploySettings);
- } else if(settings.autoEmploy && ($('.ea-employ-settings').length == 0 || $('.ea-employ-craft-settings').length == 0)) {
- createEmploySettings();
- }
- // Tax requires tax rates researched
- if ($('#autoTax').length == 0 && researched('tech-tax_rates')) {
- createSettingToggle('autoTax', 'Automatically changes tax rate to match desired morale level', createTaxSettings, removeTaxSettings);
- }
- // Battles require garrisions
- if (
- $('#autoBattle').length == 0 &&
- (
- researched('tech-garrison') && !(researched('tech-wc_conquest')||researched('tech-wc_morale')||researched('tech-wc_money')||researched('tech-wc_reject')) ||
- researched('tech-fort')
- )
- ) {
- createSettingToggle('autoBattle', 'Automatically battles when all soldiers are ready. Changes the campaign type to match army rating');
- }
- if ($('#autoResearch').length == 0) {
- createSettingToggle('autoResearch', 'Automatically researches. See Research > Auto Settings tab for more settings');
- }
- // Markets require market researched
- if ($('#autoMarket').length == 0 && researched('tech-market')) {
- createSettingToggle('autoMarket', 'Auto buys/sells resources at certain ratios. See Market tab for more settings', createMarketSettings, removeMarketSettings);
- } else if (settings.autoMarket > 0 && $('.ea-market-settings').length == 0 && researched('tech-market')) {
- createMarketSettings()
- }
- if ($('#ea-settings').length == 0) {
- let settingsDiv = $('<div id="ea-settings" style="overflow:auto;" title="Sets the minimum amount of money to keep. Can input real money value or ratio"></div>');
- let minMoneyTxt = $('<div style="float:left;">Minimum money to keep :</div>')
- let minMoneyInput = $('<input type="text" class="input is-small" style="width:20%;float:right;"/>');
- minMoneyInput.val(settings.minimumMoney);
- let setBtn = $('<a class="button is-dark is-small" id="set-min-money" style="float:right;"><span>set</span></a>');
- settingsDiv.append(minMoneyTxt).append(setBtn).append(minMoneyInput);
- $('#resources').append(settingsDiv);
- setBtn.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- let val = minMoneyInput.val();
- let minMoney = getRealValue(val);
- if(!isNaN(minMoney)){
- console.log("Setting minimum Money", minMoney);
- settings.minimumMoney = minMoney;
- updateSettings();
- }
- });
- }
- if ($('#autoARPA').length == 0 && researched('tech-arpa')){
- createSettingToggle('autoARPA', 'Automatically funds A.R.P.A. research projects. See the A.R.P.A. tab for more settings', createArpaToggles, removeArpaToggles);
- }else if(settings.autoArpa && $('.ea-arpa-toggle').length == 0) {
- createArpaToggles();
- }
- if ($('#autoPrioritize').length == 0) {
- createSettingToggle('autoPrioritize', 'Complex priority system to control purchasing buildings and research');
- }
- if ($('#autoReset').length == 0) {
- createSettingToggle('autoReset', 'When Mutually Assured Destruction is researched, use it.');
- }
- }else{
- // Currently in the evolution stage, reset civilization settings
- if ($('#autoEvolution').length == 0) {
- createSettingToggle("autoEvolution", "Automatically plays the evolution stage", createEvolutionSettings, removeEvolutionSettings);
- } else if (settings.autoEvolution && $('.ea-evolution-settings').length == 0) {
- createEvolutionSettings();
- }
- }
- if ($('#autoSettings').length == 0) {
- createAutoSettings();
- }
- }
- function resetUI() {
- console.log("Resetting UI");
- ctrlDown = false;
- altDown = false;
- shiftDown = false;
- removeEvolutionSettings();
- removeStorageSettings();
- removeCraftSettings();
- removeBuildingSettings();
- removeSmelterSettings();
- removeFactorySettings();
- removeSupportSettings();
- removeMarketSettings();
- removeEmploySettings();
- removeTaxSettings();
- removeArpaToggles();
- $('.ea-buildings-tab').remove();
- $('.ea-research-tab').remove();
- $('.ea-autolog').remove();
- $('#reload').remove();
- $('#autoPrint').remove();
- $('#autoFarm').remove();
- $('#autoEvolution').remove();
- $('#autoStorage').remove();
- $('#autoCraft').remove();
- $('#autoBuild').remove();
- $('#autoSmelter').remove();
- $('#autoFactory').remove();
- $('#autoSupport').remove();
- $('#autoPrioritize').remove();
- $('#autoEmploy').remove();
- $('#autoTax').remove();
- $('#autoBattle').remove();
- $('#autoResearch').remove();
- $('#autoMarket').remove();
- $('#ea-settings').remove();
- $('#autoARPA').remove();
- $('#autoReset').remove();
- $('#autoSettings').remove();
- }
- function createAutoSettings() {
- let parent = $('#settings');
- parent.append($('<br></br>'));
- let mainDiv = $('<div id="autoSettings"></div>');
- let label = $('<label class="label">Import/Export Auto Settings</label>');
- let ctrlDiv = $('<div class="control is-clearfix"></div>');
- let textArea = $('<textarea id="settingsImportExport" class="textarea"></textarea>');
- ctrlDiv.append(textArea);
- let control = $('<div class="field"></div>');
- control.append(label).append(ctrlDiv);
- let importBtn = $('<button class="button">Import Settings</button><text> </text>');
- importBtn.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- importSettings();
- });
- let exportBtn = $('<button class="button">Export Settings</button>');
- exportBtn.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- exportSettings();
- });
- mainDiv.append(control).append(importBtn).append(exportBtn);
- parent.append(mainDiv);
- }
- function createEvolutionToggle(name) {
- let parent = $('#resources');
- let toggle = $('<label tabindex="0" class="switch" id="'+name+'_toggle" style=""><input type="checkbox" value=false> <span class="check"></span><span>'+name+'</span></label>');
- let box = $('<div id="'+name+'" class="ea-evolution-settings" style="padding-left:20px;"></div>');
- box.append(toggle);
- parent.append(box);
- if(settings[name]){
- toggle.click();
- toggle.children('input').attr('value', true);
- }
- toggle.on('mouseup', function(e){
- if (e.which != 1) {return;}
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- settings[name] = state;
- updateSettings();
- });
- }
- function createEvolutionSettings() {
- removeEvolutionSettings();
- let evoDecision = $(`<select class="ea-evolution-settings" style="width:150px;">
- <option value="elven">Elven</option>
- <option value="orc">Orc</option>
- <option value="human">Human</option>
- <option value="troll">Troll</option>
- <option value="orge">Ogre</option>
- <option value="cylops">Cyclops</option>
- <option value="kobold">Kobold</option>
- <option value="goblin">Goblin</option>
- <option value="gnome">Gnome</option>
- <option value="cath">Cath</option>
- <option value="wolven">Wolven</option>
- <option value="centuar">Centuar</option>
- <option value="tortoisan">Tortoisan</option>
- <option value="gecko">Gecko</option>
- <option value="slitheryn">Slitheryn</option>
- <option value="arraak">Arraak</option>
- <option value="pterodacti">Pterodacti</option>
- <option value="dracnid">Dracnid</option>
- <option value="sporgar">Sporgar</option>
- <option value="shroomi">Shroomi</option>
- <option value="mantis">Mantis</option>
- <option value="scorpid">Scorpid</option>
- <option value="antid">Antid</option>
- <option value="entish">Entish</option>
- <option value="cacti">Cacti</option>
- <option value="sharkin">Sharkin</option>
- <option value="octigoran">Octigoran</option>
- <option value="balorg">Balorg</option>
- <option value="imp">Imp</option>
- </select>`);
- evoDecision[0].value = settings.evolution;
- evoDecision[0].onchange = function(){
- settings.evolution = evoDecision[0].value;
- console.log("Changing target to ", settings.evolution);
- updateSettings();
- };
- $('#autoEvolution_right').append(evoDecision);
- createEvolutionToggle('Plasmid');
- createEvolutionToggle('Craft');
- createEvolutionToggle('CRISPR');
- createEvolutionToggle('Trade');
- createEvolutionToggle('Junker');
- createEvolutionToggle('Joyless');
- createEvolutionToggle('Decay');
- }
- function removeEvolutionSettings() {
- $('.ea-evolution-settings').remove();
- }
- function createStorageSetting(id) {
- if (!resources[id].unlocked) {return;}
- if (!resources[id].crateable) {return;}
- let resourceSpan = $('#res'+resources[id].id);
- let prioritySub = $('<span role="button" aria-label="Decrease '+resources[id].name+' Priority" class="sub ea-storage-settings" style="width:25%">«</span>');
- prioritySub.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- resources[id].decStorePriority();
- priorityLabel[0].removeChild(priorityLabel[0].firstChild);
- priorityLabel[0].appendChild(document.createTextNode(resources[id].storePriority));
- });
- let priorityAdd = $('<span role="button" aria-label="Increase '+resources[id].name+' Priority" class="add ea-storage-settings" style="width:25%">»</span>');
- priorityAdd.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- resources[id].incStorePriority();
- priorityLabel[0].removeChild(priorityLabel[0].firstChild);
- priorityLabel[0].appendChild(document.createTextNode(resources[id].storePriority));
- });
- let priorityLabel = $('<span class="count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:30%;text-align:center;">'+resources[id].storePriority+'</span>');
- let priorityControls = $('<div class="controls ea-storage-settings" style="position:absolute;left:5.5%;">').append(prioritySub).append(priorityLabel).append(priorityAdd).append('</div>');
- resourceSpan.append(priorityControls)
- let minSub = $('<span role="button" aria-label="Decrease '+resources[id].name+' Minimum" class="sub ea-storage-settings" style="width:25%">«</span>');
- minSub.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- resources[id].decStoreMin();
- minLabel[0].removeChild(minLabel[0].firstChild);
- minLabel[0].appendChild(document.createTextNode(resources[id].storeMin));
- });
- let minAdd = $('<span role="button" aria-label="Increase '+resources[id].name+' Minimum" class="add ea-storage-settings" style="width:25%">»</span>');
- minAdd.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- resources[id].incStoreMin();
- minLabel[0].removeChild(minLabel[0].firstChild);
- minLabel[0].appendChild(document.createTextNode(resources[id].storeMin));
- });
- let minLabel = $('<span class="count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:30%;text-align:center;">'+resources[id].storeMin+'</span>');
- let minControls = $('<div class="controls ea-storage-settings" style="position:absolute;left:9%;">').append(minSub).append(minLabel).append(minAdd).append('</div>');
- resourceSpan.append(minControls)
- }
- function createStorageSettings() {
- removeStorageSettings();
- // Creating labels
- let labelSpan = $('#resContainers');
- let prioLabel = $('<div class="ea-storage-settings" style="position:absolute;left:6%;"><span class="has-text-warning">Priority</span></div>');
- let minLabel = $('<div class="ea-storage-settings" style="position:absolute;left:10%;"><span class="has-text-warning">Min</span></div>');
- labelSpan.append(prioLabel).append(minLabel);
- // Creating individual counters
- for (let x in resources) {
- createStorageSetting(x);
- }
- // Creating manual button
- let autoStorageBtn = $('<a class="button is-dark is-small ea-storage-settings" id="manualStorage" title="Manual trigger for autoStorage (instead of waiting for automatic check)"><span>Manual</span></a>');
- autoStorageBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- autoStorage();
- });
- $('#autoStorage_right').append(autoStorageBtn);
- }
- function removeStorageSettings() {
- $('.ea-storage-settings').remove();
- }
- function createCraftToggle(resource){
- let resourceSpan = $('#res'+resource.id);
- let toggle = $('<label tabindex="0" class="switch ea-craft-settings" style="position:absolute; max-width:75px;margin-top: 4px;left:8%;"><input type="checkbox" value=false> <span class="check" style="height:5px;"></span></label>');
- resourceSpan.append(toggle);
- if(resource.enabled){
- toggle.click();
- toggle.children('input').attr('value', true);
- }
- toggle.on('mouseup', function(e){
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- craftableResources[resource.id].enabled = state;
- });
- }
- function createCraftSettings(){
- removeCraftSettings();
- for (let x in craftableResources) {
- createCraftToggle(craftableResources[x]);
- }
- }
- function removeCraftSettings(){
- $('.ea-craft-settings').remove();
- }
- function createBuildingsTab() {
- let buildingsTabLabel = $('<li class="ea-buildings-tab"><a><span>Buildings</span></a></li>');
- let buildingsTab = $('<div id="buildingsTab" class="tab-item ea-buildings-tab" style="display:none"><h2 class="is-sr-only">Buildings Settings</h2></div>');
- // Creating click functions for other tabs
- for (let i = 1;i <= $('#mainColumn > .content > .b-tabs > .tabs > ul').children().length;i++) {
- let tabLabel = $('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child('+i+')');
- let tabItem = $('#mainColumn > .content > .b-tabs > .tab-content').children()[i-1];
- tabLabel.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- if (buildingsTabLabel.hasClass("is-active")) {
- buildingsTabLabel.removeClass("is-active");
- tabItem.style.display = '';
- }
- buildingsTab[0].style.display = 'none';
- if (!tabLabel.hasClass("is-active")) {tabLabel.addClass("is-active");}
- });
- }
- // Inserting Buildings tab after Space tab
- let navTab = $('#mainColumn > .content > .b-tabs > .tabs > ul')[0];
- let conTab = $('#mainColumn > .content > .b-tabs > .tab-content')[0];
- navTab.insertBefore(buildingsTabLabel[0], navTab.children[8]);
- conTab.insertBefore(buildingsTab[0], conTab.children[8]);
- // Creating click function for Buildings tab
- buildingsTabLabel.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- // For every other tab
- for (let i = 1;i <= $('#mainColumn > .content > .b-tabs > .tabs > ul').children().length;i++) {
- let tabLabel = $('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child('+i+')');
- let tabItem = $('#mainColumn > .content > .b-tabs > .tab-content').children()[i-1];
- // Ignore Building tab
- if (tabLabel[0].class !== undefined) {
- continue;
- }
- tabLabel.removeClass("is-active");
- tabItem.style.display = 'none';
- }
- buildingsTabLabel.addClass("is-active");
- buildingsTab[0].style.display = '';
- });
- // Creating Smelter Settings
- let smelterLabel = $('<div><h3 class="name has-text-warning" title="Set the smelter settings">Smelter:</h3></div></br>');
- buildingsTab.append(smelterLabel);
- // Creating Factory Settings
- let factoryLabel = $('<div><h3 class="name has-text-warning" title="Set the factory settings">Factory:</h3></div></br>');
- buildingsTab.append(factoryLabel);
- // Creating Building Settings
- let buildingLabel = $('<div><h3 class="name has-text-warning" title="Set the building settings">Buildings:</h3></div></br>');
- buildingsTab.append(buildingLabel);
- let buildSettingsDiv = $('<div id="buildSettingsDiv" style="overflow:auto"></div>');
- let buildSettingsLeft = $('<div id="buildSettingsLeft" style="float:left"></div>');
- let buildSettingsRight = $('<div id="buildSettingsRight" style="float:right"></div>');
- let topLeft = $('<div id="buildSettingsTopLeft"></div>');
- let bottomLeft = $('<div id="buildSettingsBottomLeft"></div>');
- let topRight = $('<div id="buildSettingsTopRight" style="float:right"></div>');
- let bottomRight = $('<div id="buildSettingsBottomRight"></div>');
- let search = $('<input type="text" id="buildingInput" placeholder="Search for buildings (ex: \'iron tag:city res:money\')" style="width:400px;">');
- search.on('input', populateBuildingList);
- let sortLabel = $('<span style="padding-left:20px;padding-right:20px;">Sort:</span>');
- let sort = $('<select style="width:110px;" id="buildingSort"><option value="none">None</option><option value="name">Name</option><option value="priority">Priority</option><option value="power_priority">Power Priority</option></select>');
- sort.on('change', populateBuildingList);
- topLeft.append(search).append(sortLabel).append(sort);
- let showToggle = $('<label tabindex="0" class="switch" id="show_toggle" style=""><input type="checkbox" value=false> <span class="check"></span><span>Show All</span></label>');
- showToggle.on('change', populateBuildingList);
- showToggle.on('mouseup', function(e){
- if (e.which != 1) {return;}
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- });
- bottomLeft.append(showToggle);
- let enableLabel = $('<span style="padding-right:10px;">Enable:</span>');
- let enableAllBtn = $('<a class="button is-dark is-small" id="enable-all-btn"><span>All</span></a>');
- enableAllBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- for (let x in buildings) {
- buildings[x].enabled = true;
- }
- populateBuildingList();
- createBuildingSettings();
- });
- let enableVisBtn = $('<a class="button is-dark is-small" id="enable-vis-btn"><span>Visible</span></a>');
- enableVisBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- for (let i = 0;i < shownBuildings.length;i++) {
- buildings[shownBuildings[i].id].enabled = true;
- }
- populateBuildingList();
- createBuildingSettings();
- });
- topRight.append(enableLabel).append(enableAllBtn).append(enableVisBtn);
- let disableLabel = $('<span style="padding-right:10px;">Disable:</span>');
- let disableAllBtn = $('<a class="button is-dark is-small" id="disable-all-btn"><span>All</span></a>');
- disableAllBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- for (let x in buildings) {
- buildings[x].enabled = false;
- }
- populateBuildingList();
- createBuildingSettings();
- });
- let disableVisBtn = $('<a class="button is-dark is-small" id="disable-vis-btn"><span>Visible</span></a>');
- disableVisBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- for (let i = 0;i < shownBuildings.length;i++) {
- buildings[shownBuildings[i].id].enabled = false;
- }
- populateBuildingList();
- createBuildingSettings();
- });
- bottomRight.append(disableLabel).append(disableAllBtn).append(disableVisBtn);
- buildSettingsLeft.append(topLeft).append(bottomLeft);
- buildSettingsRight.append(topRight).append(bottomRight);
- buildSettingsDiv.append(buildSettingsLeft).append(buildSettingsRight);
- buildingsTab.append(buildSettingsDiv);
- let buildingList = $('<div id="buildingList"></div>');
- let buildingListLabel = $(`
- <div style="display:flex;">
- <span class="name has-text-warning" style="width:30%;" title="Building Name. Can be lowercase id if not currently available">Building</span>
- <span class="name has-text-warning" style="width:20%;text-align:center;" title="Will stop building this building after reaching this limit">Limit</span>
- <span class="name has-text-warning" style="width:10%;" title="Enables this building for being automatically built">Enabled</span>
- <span class="name has-text-warning" style="width:20%;text-align:center;" title="Sets the priority of this building to be built">Priority</span>
- <span class="name has-text-warning" style="width:20%;text-align:center;" title="Sets the priority for powering this building">Power Priority</span>
- </div>`);
- buildingList.append(buildingListLabel);
- buildingsTab.append(buildingList);
- populateBuildingList();
- }
- function nameCompare(a, b) {
- return b.id.split('-')[1] < a.id.split('-')[1];
- }
- function priorityCompare(a, b) {
- return b.priority - a.priority;
- }
- function powerCompare(a, b) {
- return b.priority - a.priority;
- }
- let shownBuildings = [];
- function populateBuildingList() {
- let search = $('#buildingInput')[0];
- let sort = $('#buildingSort')[0];
- let showToggle = $('#show_toggle')[0];
- let buildingList = $('#buildingList')[0];
- while(buildingList.childNodes.length != 1) {
- buildingList.removeChild(buildingList.lastChild);
- }
- //console.log("Populating Building List");
- let terms = search.value.split(' ');
- let names = [];
- let tags = [];
- let res = [];
- for (let i = 0;i < terms.length;i++) {
- let tagCheck = /tag:(.+)/.exec(terms[i]);
- let resCheck = /res:(.+)/.exec(terms[i]);
- //console.log(terms[i], tagCheck, resCheck);
- if (tagCheck !== null) {
- tags.push(tagCheck[1]);
- } else if (resCheck !== null) {
- res.push(resCheck[1]);
- } else {
- names.push(terms[i]);
- }
- }
- //console.log(names, tags, res);
- shownBuildings = [];
- for (let x in buildings) {
- let building = buildings[x];
- // Checking if available
- if (showToggle.children[0].value == 'false' && !building.unlocked) {
- continue;
- }
- // Searching for if any names appear in building name
- if (names.length != 0) {
- let pass = false;
- for (let i = 0;i < names.length;i++) {
- let name;
- if (building.name !== null) {
- name = building.name;
- } else {
- name = building.id.split('-')[1];
- }
- if (name.toLowerCase().indexOf(names[i]) >= 0) {
- pass = true;
- break;
- }
- }
- if (!pass) {
- continue;
- }
- }
- // Searching for if any tags appear in building name
- if (tags.length != 0) {
- let pass = false;
- for (let i = 0;i < tags.length;i++) {
- if (building.tags.includes(tags[i])) {
- pass = true;
- break;
- }
- }
- if (!pass) {
- continue;
- }
- }
- // Searching for if any resources appear in building requirements
- if (res.length != 0 && building.res !== null) {
- let pass = false;
- for (let i = 0;i < res.length;i++) {
- if (building.getResDep(res[i]) !== null && building.getResDep(res[i]) > 0) {
- pass = true;
- break;
- }
- }
- if (!pass) {
- continue;
- }
- }
- shownBuildings.push(building);
- }
- //console.log(shownBuildings);
- // Sorting if necessary
- if (sort.value == 'name') {
- shownBuildings.sort(nameCompare);
- } else if (sort.value == 'priority') {
- shownBuildings.sort(priorityCompare);
- } else if (sort.value == 'power_priority') {
- shownBuildings.sort(powerCompare);
- }
- // Drawing buildings into list
- for (let i = 0;i < shownBuildings.length;i++) {
- let building = shownBuildings[i];
- let buildingDiv;
- if (i % 2) {
- buildingDiv = $('<div style="display:flex"></div>');
- } else {
- buildingDiv = $('<div style="display:flex" class="resource alt"></div>');
- }
- buildingList.appendChild(buildingDiv[0]);
- // Name Label
- let name = building.name || building.id.split('-')[1];
- buildingDiv.append($('<span style="width:30%;">'+name+'</span>'));
- // Building Limit
- let limSub = $('<span role="button" aria-label="Decrease Build Limit" class="sub ea-buildings-tab">«</span>');
- limSub.on('mouseup', function(e) {
- buildings[building.id].decLimit();
- let count = $('#'+building.id+'-limit')[0];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(buildings[building.id].limit));
- });
- let limAdd = $('<span role="button" aria-label="Increase Build Limit" class="add ea-buildings-tab">»</span>');
- limAdd.on('mouseup', function(e) {
- buildings[building.id].incLimit();
- let count = $('#'+building.id+'-limit')[0];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(buildings[building.id].limit));
- });
- let limLabel = $('<span class="count current" id="'+building.id+'-limit" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:2rem;">'+buildings[building.id].limit+'</span>');
- let limControls = $('<div class="controls ea-buildings-tab" style="width:20%;text-align:center;">').append(limSub).append(limLabel).append(limAdd).append('</div>');
- buildingDiv.append(limControls);
- // Building Toggle
- let toggle = $('<label tabindex="0" class="switch ea-buildings-tab" style="margin-top: 4px;width:10%;"><input type="checkbox" value=false> <span class="check" style="height:5px;"></span></label>');
- buildingDiv.append(toggle);
- if(buildings[building.id].enabled){
- toggle.click();
- toggle.children('input').attr('value', true);
- }
- toggle.on('mouseup', function(e){
- if (e.which != 1) {return;}
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- console.log("Updated build state", building.id, state);
- input.setAttribute('value', state);
- buildings[building.id].enabled = state;
- createBuildingSettings();
- });
- // Building Priority
- let prioSub = $('<span role="button" aria-label="Decrease Build Priority" class="sub ea-buildings-tab">«</span>');
- prioSub.on('mouseup', function(e) {
- buildings[building.id].decPriority();
- let count = $('#'+building.id+'-prio')[0];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(buildings[building.id].priority));
- });
- let prioAdd = $('<span role="button" aria-label="Increase Build Priority" class="add ea-buildings-tab">»</span>');
- prioAdd.on('mouseup', function(e) {
- buildings[building.id].incPriority();
- let count = $('#'+building.id+'-prio')[0];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(buildings[building.id].priority));
- });
- let prioLabel = $('<span class="count current" id="'+building.id+'-prio" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:2rem;">'+buildings[building.id].priority+'</span>');
- let prioControls = $('<div class="controls ea-buildings-tab" style="width:20%;text-align:center;">').append(prioSub).append(prioLabel).append(prioAdd).append('</div>');
- buildingDiv.append(prioControls);
- // Power Priority
- if (building.hasOwnProperty('power_priority')) {
- let powerSub = $('<span role="button" aria-label="Decrease Power Priority" class="sub ea-buildings-tab">«</span>');
- powerSub.on('mouseup', function(e) {
- buildings[building.id].decPowerPriority();
- let count = $('#'+building.id+'-power-prio')[0];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(buildings[building.id].powerPriority));
- });
- let powerAdd = $('<span role="button" aria-label="Increase Power Priority" class="add ea-buildings-tab">»</span>');
- powerAdd.on('mouseup', function(e) {
- buildings[building.id].incPowerPriority();
- let count = $('#'+building.id+'-power-prio')[0];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(buildings[building.id].powerPriority));
- });
- let powerLabel = $('<span class="count current" id="'+building.id+'-power-prio" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:2rem;">'+buildings[building.id].powerPriority+'</span>');
- let powerControls = $('<div class="controls ea-buildings-tab" style="width:20%;text-align:center;">').append(powerSub).append(powerLabel).append(powerAdd).append('</div>');
- buildingDiv.append(powerControls);
- }
- }
- // Set focus back on search
- search.focus();
- }
- function createBuildingToggle(building){
- return;
- var key;
- let batElmt = $('#'+building.id);
- let toggle = $('<label tabindex="0" class="switch ea-building-settings" style="position:absolute; margin-top: 30px;left:13%;top:-13%;"><input type="checkbox" value=false> <span class="check" style="height:5px; max-width:15px"></span></label>');
- batElmt.append(toggle);
- if(buildings[building.id].enabled){
- toggle.click();
- toggle.children('input').attr('value', true);
- }
- toggle.on('mouseup', function(e){
- if (e.which != 1) {return;}
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- buildings[building.id].enabled = state;
- });
- }
- function createBuildingSettings(){
- removeBuildingSettings();
- // Creating building toggles for Village and Space tabs
- for (let x in buildings) {
- if (buildings[x].unlocked) {
- createBuildingToggle(buildings[x]);
- }
- }
- // Create generic Build All button for main settings div
- let buildAllBtn = $('<a class="button is-dark is-small ea-building-settings" id="build-all"><span>Set All</span></a>');
- buildAllBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- for (let x in buildings) {
- buildings[x].enabled = true;
- }
- populateBuildingList();
- createBuildingSettings();
- });
- // Create generic Build None button for main settings div
- let buildNoneBtn = $('<a class="button is-dark is-small ea-building-settings" id="build-all"><span>Set None</span></a>');
- buildNoneBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- for (let x in buildings) {
- buildings[x].enabled = false;
- }
- populateBuildingList();
- createBuildingSettings();
- });
- $('#autoBuild_right').append(buildAllBtn).append(buildNoneBtn);
- }
- function removeBuildingSettings(){
- $('.ea-building-settings').remove();
- }
- function createSmelterSettings() {
- removeSmelterSettings();
- // Create manual button for Auto Smelting
- let autoSmelterBtn = $('<a class="button is-dark is-small ea-smelter-settings" id="smelter-manual"><span>Manual</span></a>');
- autoSmelterBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- autoSmelter();
- });
- $('#autoSmelter_right').append(autoSmelterBtn);
- }
- function removeSmelterSettings() {
- $('.ea-smelter-settings').remove();
- }
- function createFactorySettings() {
- removeSmelterSettings();
- // Create manual button for Auto Smelting
- let autoBtn = $('<a class="button is-dark is-small ea-factory-settings" id="factory-manual"><span>Manual</span></a>');
- autoBtn.on('mouseup', function(e){
- if (e.which != 1) {return;}
- autoFactory();
- });
- $('#autoFactory_right').append(autoBtn);
- }
- function removeFactorySettings() {
- $('.ea-factory-settings').remove();
- }
- function createSupportSettings() {
- let supportTabLabel = $('<li class="ea-support-settings"><a><span>Support</span></a></li>');
- let supportTab = $('<div id="supportSettings" class="tab-item ea-support-settings" style="display:none"><h2 class="is-sr-only">Auto Support Settings</h2></div>');
- // Creating click functions for other tabs
- for (let i = 1;i <= $('#mainColumn > .content > .b-tabs > .tabs > ul').children().length;i++) {
- let tabLabel = $('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child('+i+')');
- let tabItem = $('#mainColumn > .content > .b-tabs > .tab-content').children()[i-1];
- tabLabel.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- if (supportTabLabel.hasClass("is-active")) {
- supportTabLabel.removeClass("is-active");
- tabItem.style.display = '';
- }
- supportTab[0].style.display = 'none';
- if (!tabLabel.hasClass("is-active")) {tabLabel.addClass("is-active");}
- });
- }
- $('#mainColumn > .content > .b-tabs > .tabs > ul').append(supportTabLabel);
- $('#mainColumn > .content > .b-tabs > .tab-content').append(supportTab);
- supportTabLabel.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- // For every other tab
- for (let i = 1;i <= $('#mainColumn > .content > .b-tabs > .tabs > ul').children().length-1;i++) {
- let tabLabel = $('#mainColumn > .content > .b-tabs > .tabs > ul > li:nth-child('+i+')');
- let tabItem = $('#mainColumn > .content > .b-tabs > .tab-content').children()[i-1];
- tabLabel.removeClass("is-active");
- tabItem.style.display = 'none';
- }
- supportTabLabel.addClass("is-active");
- supportTab[0].style.display = '';
- });
- // Filling support tab
- if(researched('tech-electricity')) {
- let label = $('<div><h3 class="name has-text-warning" title="Set the priority of buildings that require electricity">Electricity:</h3></div>');
- supportTab.append(label);
- for (let x in elecConsumers) {
- let c = elecConsumers[x];
- if (!c.unlocked) {continue;}
- let btnDiv = $('<div class="action cna"></div>');
- let btnLabel = $('<a class="button is-dark"><span class="aTitle">'+c.name+'</span><span class="count" title="'+c.name+' Priority">'+c.priority+'</span></a>');
- let btnInc = $('<span role="button" title="Increase '+c.name+' Priority" class="on">+</span>');
- let btnDec = $('<span role="button" title="Decrease '+c.name+' Priority" class="off">-</span>');
- btnDec.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- elecConsumers[c.name].lowerPriority();
- btnLabel[0].children[1].innerText = elecConsumers[c.name].priority;
- updateSettings();
- });
- btnInc.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- elecConsumers[c.name].higherPriority();
- btnLabel[0].children[1].innerText = elecConsumers[c.name].priority;
- updateSettings();
- });
- btnDiv.append(btnLabel).append(btnDec).append(btnInc);
- supportTab.append(btnDiv);
- }
- }
- }
- function removeSupportSettings() {
- $('.ea-support-settings').remove();
- }
- function createMarketSetting(resource){
- let marketRow = $('#market-'+resource.id);
- let toggleBuy = $('<label tabindex="0" class="switch ea-market-settings" style=""><input type="checkbox" value=false> <span class="check" style="height:5px;"></span><span class="control-label" style="font-size: small;">auto buy</span><span class="state"></span></label>');
- let buyRatioLabel = $('<span class="ea-market-settings count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:2.5rem;font-size:.8rem">(<'+resource.buyRatio+')</span>');
- let buyRatioSub = $('<span role="button" aria-label="Decrease '+resource.name+' Buy Ratio" class="sub ea-market-settings">«</span>');
- buyRatioSub.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- resource.buyDec();
- buyRatioLabel[0].removeChild(buyRatioLabel[0].firstChild);
- buyRatioLabel[0].appendChild(document.createTextNode('(<'+resource.buyRatio+')'));
- });
- let buyRatioAdd = $('<span role="button" aria-label="Increase '+resource.name+' Buy Ratio" class="add ea-market-settings">»</span>');
- buyRatioAdd.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- resource.buyInc();
- buyRatioLabel[0].removeChild(buyRatioLabel[0].firstChild);
- buyRatioLabel[0].appendChild(document.createTextNode('(<'+resource.buyRatio+')'));
- });
- marketRow.append(toggleBuy);
- marketRow.append(buyRatioSub).append(buyRatioLabel).append(buyRatioAdd);
- let toggleSell = $('<label tabindex="0" class="switch ea-market-settings" style=""><input type="checkbox" value=false> <span class="check" style="height:5px;"></span><span class="control-label" style="font-size: small;">auto sell</span><span class="state"></span></label>');
- let sellRatioLabel = $('<span class="ea-market-settings count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:2.5rem;font-size:.8rem">(>'+resource.sellRatio+')</span>');
- let sellRatioSub = $('<span role="button" aria-label="Decrease '+resource.name+' Sell Ratio" class="sub ea-market-settings">«</span>');
- sellRatioSub.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- resource.sellDec();
- sellRatioLabel[0].removeChild(sellRatioLabel[0].firstChild);
- sellRatioLabel[0].appendChild(document.createTextNode('(>'+resource.sellRatio+')'));
- });
- let sellRatioAdd = $('<span role="button" aria-label="Increase '+resource.name+' Sell Ratio" class="add ea-market-settings">»</span>');
- sellRatioAdd.on('mouseup', function(e) {
- if (e.which != 1) {return;}
- resource.sellInc();
- sellRatioLabel[0].removeChild(sellRatioLabel[0].firstChild);
- sellRatioLabel[0].appendChild(document.createTextNode('(>'+resource.sellRatio+')'));
- });
- marketRow.append(toggleSell);
- marketRow.append(sellRatioSub).append(sellRatioLabel).append(sellRatioAdd);
- if(resource.autoBuy){
- toggleBuy.click();
- toggleBuy.children('input').attr('value', true);
- }
- if(resource.autoSell){
- toggleSell.click();
- toggleSell.children('input').attr('value', true);
- }
- toggleBuy.on('mouseup', function(e){
- if (e.which != 1) {return;}
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- resources[resource.id].autoBuy = state;
- let otherState = toggleSell.children('input').attr('value') === 'true';
- if(state && otherState){
- toggleSell.click();
- console.log("Turning off toggleSell");
- resources[resource.id].autoSell = false;
- toggleSell.children('input')[0].setAttribute('value',false);
- }
- resources[resource.id].autoBuy = state;
- updateSettings();
- });
- toggleSell.on('mouseup', function(e){
- if (e.which != 1) {return;}
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- resources[resource.id].autoSell = state;
- let otherState = toggleBuy.children('input').attr('value') === 'true';
- if(state && otherState){
- toggleBuy.click();
- console.log("Turning off toggleBuy");
- resources[resource.id].autoBuy = false;
- toggleBuy.children('input')[0].setAttribute('value',false);
- }
- updateSettings();
- });
- if($('#bulk-sell').length == 0 && researched('tech-market')){
- let bulkSell = $('<a class="ea-market-settings button is-dark is-small" id="bulk-sell"><span>Bulk Sell</span></a>');
- $('#autoMarket_right').append(bulkSell);
- bulkSell.on('mouseup', function(e){
- if (e.which != 1) {return;}
- autoMarket(true, true);
- });
- }
- }
- function createMarketSettings(){
- removeMarketSettings();
- for (let x in resources) {
- createMarketSetting(resources[x]);
- }
- }
- function removeMarketSettings(){
- $('.ea-market-settings').remove();
- }
- function createEmploySettings() {
- removeEmploySettings();
- for (let x in jobs) {
- let job = jobs[x];
- if (!job.unlocked) {continue;}
- if (job.id != "free" || job.name == 'Hunter') {
- if (job.id == "craftsman") {
- let prioritySub = $('<span role="button" aria-label="Decrease '+job.name+' Priority" class="sub ea-employ-craft-settings">«</span>');
- prioritySub.on('mouseup', function(e) {
- autoEmployer.lowerPriority(jobs[job.id]);
- });
- let priorityAdd = $('<span role="button" aria-label="Increase '+job.name+' Priority" class="add ea-employ-craft-settings">»</span>');
- priorityAdd.on('mouseup', function(e) {
- autoEmployer.higherPriority(jobs[job.id]);
- });
- let priorityLabel = $('<span class="count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:1.5rem;">'+job.priority+'</span>');
- let priorityControls = $('<div class="foundry controls ea-employ-craft-settings" style="text-align:right;min-width:9.25rem;">').append(prioritySub).append(priorityLabel).append(priorityAdd).append('</div>');
- let parent = $('#foundry > .job > .foundry').parent();
- parent.append(priorityControls);
- } else if (job.id == 'free') {
- let prioritySub = $('<span role="button" aria-label="Decrease '+job.name+' Priority" class="sub ea-employ-settings">«</span>');
- prioritySub.on('mouseup', function(e) {
- autoEmployer.lowerPriority(jobs[job.id]);
- });
- let priorityAdd = $('<span role="button" aria-label="Increase '+job.name+' Priority" class="add ea-employ-settings">»</span>');
- priorityAdd.on('mouseup', function(e) {
- autoEmployer.higherPriority(jobs[job.id]);
- });
- let priorityLabel = $('<span class="count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:1.5rem;">'+job.priority+'</span>');
- let priorityControls = $('<div class="controls ea-employ-settings" style="text-align:right;min-width:9.25rem;">').append(prioritySub).append(priorityLabel).append(priorityAdd).append('</div>');
- $('#civ-'+job.id).append(priorityControls)
- }else {
- let prioritySub = $('<span role="button" aria-label="Decrease '+job.name+' Priority" class="sub ea-employ-settings">«</span>');
- prioritySub.on('mouseup', function(e) {
- autoEmployer.lowerPriority(jobs[job.id]);
- });
- let priorityAdd = $('<span role="button" aria-label="Increase '+job.name+' Priority" class="add ea-employ-settings">»</span>');
- priorityAdd.on('mouseup', function(e) {
- autoEmployer.higherPriority(jobs[job.id]);
- });
- let priorityLabel = $('<span class="count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:1.5rem;">'+job.priority+'</span>');
- let priorityControls = $('<div class="controls ea-employ-settings" style="text-align:right;min-width:6rem;">').append(prioritySub).append(priorityLabel).append(priorityAdd).append('</div>');
- $('#civ-'+job.id).append(priorityControls)
- }
- } else {
- let parent = document.getElementById("civ-"+job.id);
- let priorityLabel = $('<span class="has-text-warning ea-employ-settings" style="text-align:right;min-width:9.25rem">Priority</span>');
- $('#civ-'+job.id).append(priorityLabel);
- }
- }
- for (let x in craftJobs) {
- let cjob = craftJobs[x];
- if (!cjob.unlocked) {continue;}
- let prioritySub = $('<span role="button" aria-label="Decrease '+cjob.name+' Priority" class="sub ea-employ-craft-settings">«</span>');
- prioritySub.on('mouseup', function(e) {
- autoEmployer.lowerPriority(craftJobs[cjob.id]);
- });
- let priorityAdd = $('<span role="button" aria-label="Increase '+cjob.name+' Priority" class="add ea-employ-craft-settings">»</span>');
- priorityAdd.on('mouseup', function(e) {
- autoEmployer.higherPriority(craftJobs[cjob.id]);
- });
- let priorityLabel = $('<span class="count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:1.5rem;">'+cjob.priority+'</span>');
- let priorityControls = $('<div class="controls ea-employ-craft-settings" style="text-align:right;min-width:6rem;">').append(prioritySub).append(priorityLabel).append(priorityAdd).append('</div>');
- $('#craft'+cjob.id).parent().append(priorityControls)
- }
- }
- function removeEmploySettings() {
- $('.ea-employ-settings').remove();
- $('.ea-employ-craft-settings').remove();
- }
- function createTaxSettings() {
- let moraleText = $('<span>Set Default Morale:</span>');
- let moraleSub = $('<span role="button" aria-label="Decrease Morale" class="sub ea-tax-settings">«</span>');
- moraleSub.on('mouseup', function(e) {
- settings.defaultMorale -= 1;
- let count = $('#autoTax > div > .ea-tax-settings > .count')[0];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(settings.defaultMorale));
- updateSettings();
- });
- let moraleAdd = $('<span role="button" aria-label="Increase Morale" class="add ea-tax-settings">»</span>');
- moraleAdd.on('mouseup', function(e) {
- settings.defaultMorale += 1;
- let count = $('#autoTax > div > .ea-tax-settings > .count')[0];
- count.removeChild(count.firstChild);
- count.appendChild(document.createTextNode(settings.defaultMorale));
- updateSettings();
- });
- let moraleLabel = $('<span class="count current" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:3rem;">'+settings.defaultMorale+'</span>');
- let moraleControls = $('<div class="controls ea-tax-settings" style="text-align:right;min-width:6rem;">').append(moraleText).append(moraleSub).append(moraleLabel).append(moraleAdd).append('</div>');
- $('#autoTax_right').append(moraleControls);
- }
- function removeTaxSettings() {
- $('.ea-tax-settings').remove();
- }
- function createResearchTab() {
- // Creating Auto Research Tab
- let researchSettingTabLabel = $('<li class="ea-research-tab"><a><span>Auto Settings</span></a></li>');
- let newTab = $('.resTabs > .tabs > ul > li:nth-child(1)');
- let completeTab = $('.resTabs > .tabs > ul > li:nth-child(2)');
- let newTabItem = $('#tech');
- let completeTabItem = $('#oldTech');
- let resTabs = $($('.resTabs')[1]);
- resTabs.find('> .tabs > ul').append(researchSettingTabLabel);
- let researchSettingTab = $('<div id="researchSettings" class="tab-item ea-research-tab" style="display:none"><h2 class="is-sr-only">Auto Research Settings</h2></div>');
- resTabs.find('> .tab-content').append(researchSettingTab);
- newTab.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- if (researchSettingTabLabel.hasClass("is-active")) {
- researchSettingTabLabel.removeClass("is-active");
- newTabItem[0].style.display = '';
- }
- researchSettingTab[0].style.display = 'none';
- if (!newTab.hasClass("is-active")) {newTab.addClass("is-active");}
- });
- completeTab.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- if (researchSettingTabLabel.hasClass("is-active")) {
- researchSettingTabLabel.removeClass("is-active");
- completeTabItem[0].style.display = '';
- }
- researchSettingTab[0].style.display = 'none';
- if (!completeTab.hasClass("is-active")) {completeTab.addClass("is-active");}
- });
- researchSettingTabLabel.on('mouseup',function(e) {
- if (e.which != 1) {return;}
- newTab.removeClass("is-active");
- completeTab.removeClass("is-active");
- newTabItem[0].style.display = 'none';
- completeTabItem[0].style.display = 'none';
- researchSettingTabLabel.addClass("is-active");
- researchSettingTab[0].style.display = '';
- });
- // Creating Fanaticism/Anthropology choice
- let label = $('<div><h3 class="name has-text-warning" title="Research choices that give different effects based on the previous runs">Theology:</h3></div></br>');
- let fanORanth = $('<select style="width:150px;"><option value="fanaticism">Fanaticism</option><option value="anthropology">Anthropology</option></select>');
- let fanDesc = "Gain a dominant trait from your progenitor race. If same race, gain a random minor trait. Gives bonuses to combat and trade. Better for long runs.";
- let anthDesc = "Gives bonuses to science and tax income. Better for short runs.";
- let target1 = $('<div style="padding-left:5%;display:flex;"><span style="width:4rem">Target 1:</span></div>');
- target1.append(fanORanth);
- fanORanth[0].value = settings.fanORanth;
- if (settings.fanORanth == "anthropology") {
- fanORanth[0].title = anthDesc;
- } else {
- fanORanth[0].title = fanDesc;
- }
- fanORanth[0].onchange = function(){
- settings.fanORanth = fanORanth[0].value;
- if (settings.fanORanth == "anthropology") {
- fanORanth[0].title = anthDesc;
- } else {
- fanORanth[0].title = fanDesc;
- }
- console.log("Changing target to ", settings.fanORanth);
- updateSettings();
- };
- // Creating Study/Deify choice
- let studyORdeify = $('<select style="width:150px;"><option value="study">Study</option><option value="deify">Deify</option></select>');
- let deifyDesc = "Gain a dominant trait from your progenitor's progenitor race. If same race, gain a random minor trait. Gives bonuses to combat and trade. Better for long runs.";
- let studyDesc = "Gives bonuses to science and tax income. Better for short runs.";
- let target2 = $('<div style="padding-left:5%;display:flex;"><span style="width:4rem">Target 2:</span></div>');
- target2.append(studyORdeify);
- studyORdeify[0].value = settings.studyORdeify;
- if (settings.studyORdeify == "study") {
- studyORdeify[0].title = studyDesc;
- } else {
- studyORdeify[0].title = deifyDesc;
- }
- studyORdeify[0].onchange = function(){
- settings.studyORdeify = studyORdeify[0].value;
- if (settings.studyORdeify == "study") {
- studyORdeify[0].title = studyDesc;
- } else {
- studyORdeify[0].title = deifyDesc;
- }
- console.log("Changing target to ", settings.studyORdeify);
- updateSettings();
- };
- researchSettingTab.append(label).append(target1).append(target2);
- let label2 = $('<div><h3 class="name has-text-warning" title="Research choice that either gives morale boost or production increase">Unification:</h3></div></br>');
- let uniChoice = $('<select style="width:150px;"><option value="conquest">Conquest</option><option value="morale">Morale</option><option value="money">Money</option><option value="reject">Reject</option></select>');
- let target3 = $('<div style="padding-left:5%;display:flex;"><span style="width:4rem;">Choice: </span></div>');
- target3.append(uniChoice);
- uniChoice[0].value = settings.uniChoice;
- uniChoice[0].onchange = function(){
- settings.uniChoice = uniChoice[0].value;
- console.log("Changing target to ", settings.uniChoice);
- updateSettings();
- };
- researchSettingTab.append(label2).append(target3);
- // Creating research list
- let label3 = $('<div><h3 class="name has-text-warning" title="Research list and priorities">Research List:</h3></div></br>');
- researchSettingTab.append(label3);
- let listParamDiv = $('<div id="listParamDiv" style="overflow:auto"></div>');
- let listParamLeft = $('<div id="listParamLeft" style="float:left"></div>');
- let listParamRight = $('<div id="listParamRight" style="float:right"></div>');
- let topLeft = $('<div id="listParamTopLeft"></div>');
- let bottomLeft = $('<div id="listParamBottomLeft"></div>');
- let topRight = $('<div id="listParamTopRight" style="float:right"></div>');
- let bottomRight = $('<div id="listParamBottomRight"></div>');
- let search = $('<input type="text" id="researchInput" placeholder="Search for research (ex: \'crate tag:mine res:knowledge\')" style="width:400px;">');
- search.on('input', populateResearchList);
- let sortLabel = $('<span style="padding-left:20px;padding-right:20px;">Sort:</span>');
- let sort = $('<select style="width:110px;" id="researchSort"><option value="none">None</option><option value="name">Name</option><option value="priority">Priority</option></select>');
- sort.on('change', populateResearchList);
- topLeft.append(search).append(sortLabel).append(sort);
- let showToggle = $('<label tabindex="0" class="switch" id="show_research_toggle" style=""><input type="checkbox" value=false> <span class="check"></span><span>Show All</span></label>');
- showToggle.on('change', populateResearchList);
- showToggle.on('mouseup', function(e){
- if (e.which != 1) {return;}
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- });
- bottomLeft.append(showToggle);
- listParamLeft.append(topLeft).append(bottomLeft);
- listParamRight.append(topRight).append(bottomRight);
- listParamDiv.append(listParamLeft).append(listParamRight);
- researchSettingTab.append(listParamDiv);
- let researchList = $('<div id="researchList"></div>');
- let researchListLabel = $(`
- <div style="display:flex;">
- <span class="name has-text-warning" style="width:30%;" title="Research Name. Can be lowercase id if not currently available">Research</span>
- <span class="name has-text-warning" style="width:20%;text-align:center;" title="Sets the priority of this building to be built">Priority</span>
- </div>`);
- researchList.append(researchListLabel);
- researchSettingTab.append(researchList);
- populateResearchList();
- }
- let shownResearches = [];
- function populateResearchList() {
- return //IMPORTANT. 1.0.21 broke this function in some way. No auto-research possible (not that I used it anyways though)
- let search = $('#researchInput')[0];
- let sort = $('#researchSort')[0];
- let showToggle = $('#show_research_toggle')[0];
- let researchList = $('#researchList')[0];
- while(researchList && researchList.childNodes.length != 1) {
- researchList.removeChild(researchList.lastChild);
- }
- //console.log("Populating Research List");
- let terms = search.value.split(' ');
- let names = [];
- let tags = [];
- let res = [];
- for (let i = 0;i < terms.length;i++) {
- let tagCheck = /tag:(.+)/.exec(terms[i]);
- let resCheck = /res:(.+)/.exec(terms[i]);
- //console.log(terms[i], tagCheck, resCheck);
- if (tagCheck !== null) {
- tags.push(tagCheck[1]);
- } else if (resCheck !== null) {
- res.push(resCheck[1]);
- } else {
- names.push(terms[i]);
- }
- }
- //console.log(names, tags, res);
- shownResearches = [];
- let temp_r = [];
- for (var x in researches) {temp_r.push(researches[x])}
- for (x in arpas) {temp_r.push(arpas[x]);}
- for (let i = 0;i < temp_r.length;i++) {
- let research = temp_r[i];
- // Checking if available
- if (showToggle.children[0].value == 'false' &&!research.unlocked) {
- continue;
- }
- // Searching for if any names appear in building name
- if (names.length != 0) {
- let pass = false;
- for (let i = 0;i < names.length;i++) {
- var name;
- if (research.name !== null) {
- name = research.name;
- } else {
- name = research.id.split('-')[1];
- }
- if (name.toLowerCase().indexOf(names[i]) >= 0) {
- pass = true;
- break;
- }
- }
- if (!pass) {
- continue;
- }
- }
- // Searching for if any tags appear in research name
- if (tags.length != 0) {
- let pass = false;
- for (let i = 0;i < tags.length;i++) {
- if (research.tags.includes(tags[i])) {
- pass = true;
- break;
- }
- }
- if (!pass) {
- continue;
- }
- }
- // Searching for if any resources appear in research requirements
- if (res.length != 0 && research.res !== null) {
- let pass = false;
- for (let i = 0;i < res.length;i++) {
- if (research.getResDep(res[i]) !== null && research.getResDep(res[i]) > 0) {
- pass = true;
- break;
- }
- }
- if (!pass) {
- continue;
- }
- }
- shownResearches.push(research);
- }
- // Sorting if necessary
- if (sort.value == 'name') {
- shownResearches.sort(nameCompare);
- } else if (sort.value == 'priority') {
- shownResearches.sort(priorityCompare);
- }
- // Drawing buildings into list
- for (let i = 0;i < shownResearches.length;i++) {
- let research = shownResearches[i];
- var researchDiv;
- if (i % 2) {
- researchDiv = $('<div style="display:flex"></div>');
- } else {
- researchDiv = $('<div style="display:flex" class="resource alt"></div>');
- }
- researchList.appendChild(researchDiv[0]);
- // Name Label
- if (research.name === null) {
- name = research.id.split('-')[1];
- } else {
- name = research.name;
- }
- researchDiv.append($('<span style="width:30%;">'+name+'</span>'));
- // Research Priority
- let prioSub = $('<span role="button" aria-label="Decrease Research Priority" class="sub ea-research-tab">«</span>');
- prioSub.on('mouseup', function(e) {
- if (research.tags.includes('arpa')) {
- arpas[research.id].decPriority();
- } else {
- researches[research.id].decPriority();
- }
- let count = $('#'+research.id+'-prio')[0];
- count.removeChild(count.firstChild);
- if (research.tags.includes('arpa')) {
- count.appendChild(document.createTextNode(arpas[research.id].priority));
- } else {
- count.appendChild(document.createTextNode(researches[research.id].priority));
- }
- });
- let prioAdd = $('<span role="button" aria-label="Increase Research Priority" class="add ea-research-tab">»</span>');
- prioAdd.on('mouseup', function(e) {
- if (research.tags.includes('arpa')) {
- arpas[research.id].incPriority();
- } else {
- researches[research.id].incPriority();
- }
- let count = $('#'+research.id+'-prio')[0];
- count.removeChild(count.firstChild);
- if (research.tags.includes('arpa')) {
- count.appendChild(document.createTextNode(arpas[research.id].priority));
- } else {
- count.appendChild(document.createTextNode(researches[research.id].priority));
- }
- });
- let temp = (research.tags.includes('arpa')) ? arpas[research.id].priority : researches[research.id].priority;
- let prioLabel = $('<span class="count current" id="'+research.id+'-prio" style="padding-right:5px;padding-left:5px;vertical-align:bottom;width:2rem;">'+temp+'</span>');
- let prioControls = $('<div class="controls ea-research-tab" style="width:20%;text-align:center;">').append(prioSub).append(prioLabel).append(prioAdd).append('</div>');
- researchDiv.append(prioControls);
- }
- // Set focus back on search
- search.focus();
- }
- function createArpaToggle(name){
- let arpaDiv = $('#arpa'+name +' .head');
- let toggle = $('<label tabindex="0" class="switch ea-arpa-toggle" style="position:relative; max-width:75px;margin-top: -36px;left:45%;float:left;"><input type="checkbox" value=false> <span class="check" style="height:5px;"></span></label>');
- arpaDiv.append(toggle);
- if(settings.arpa[name]){
- toggle.click();
- toggle.children('input').attr('value', true);
- }
- toggle.on('mouseup', function(e){
- let input = e.currentTarget.children[0];
- let state = !(input.getAttribute('value') === "true");
- input.setAttribute('value', state);
- settings.arpa[name] = state;
- updateSettings();
- });
- }
- function createArpaToggles(){
- removeArpaToggles();
- createArpaToggle('lhc');
- createArpaToggle('stock_exchange');
- createArpaToggle('monument');
- createArpaToggle('launch_facility');
- }
- function removeArpaToggles(){
- $('.ea-arpa-toggle').remove();
- }
- function createAutoLog() {
- let autolog = $('<div id="autolog" class="msgQueue right resource alt ea-autolog" style="display:none;"></div>');
- $('#queueColumn').append(autolog);
- }
- /***
- *
- * Utilities
- *
- ***/
- function messageQueue(msg,color){
- color = color || 'warning';
- var new_message = $('<p class="has-text-'+color+'">'+msg+'</p>');
- $('#autolog').prepend(new_message);
- if ($('#autolog').children().length > 30){
- $('#autolog').children().last().remove();
- }
- }
- function getTotalGameDays() {
- try {
- let str = $('#statsPanel')[0].children[$('#statsPanel')[0].children.length-1].innerText;
- let reg = /Game Days Played: ([\d]+)/.exec(str);
- return parseInt(reg[1]);
- } catch(e) {
- console.log('Error in getting total game days');
- return null;
- }
- }
- function getYear() {
- try {
- return parseInt($('.year > .has-text-warning')[0].innerText);
- } catch(e) {
- console.log('Error in getting current year');
- return null;
- }
- }
- function getDay() {
- try {
- return parseInt($('.day > .has-text-warning')[0].innerText);
- } catch(e) {
- console.log('Error in getting current day');
- return null;
- }
- }
- function getLunarPhase() {
- try {
- return $('.calendar > .is-primary')[0].attributes['data-label'].value;
- } catch(e) {
- console.log('Error in getting current lunar phase');
- return null;
- }
- }
- function getRace() {
- try {
- return $('#race > .column > span')[0].innerText;
- } catch(e) {
- console.log('Error in getting current race');
- return null;
- }
- }
- function getRealValue(num){
- var suffix = {
- K:1000,
- M:1000000
- }
- var currSuff = /([-]?)([\.0-9]+)([^\d\.])/.exec(num);
- if(currSuff !== null && currSuff.length == 4){
- var sign = (currSuff[1] == "-") ? -1 : 1;
- var n = parseFloat(currSuff[2]);
- var suff = currSuff[3];
- if (suffix[suff] !== null) {n *= suffix[suff];}
- n *= sign;
- return n;
- }
- return parseFloat(num);
- }
- function researched(id) {
- let researched = $('#oldTech > div');
- for (let i = 0;i < researched.length;i++) {
- if (id == researched[i].id) {
- return true;
- }
- }
- return false;
- }
- function getMinMoney() {
- if (settings.minimumMoney < 1) {
- return settings.minimumMoney * resources.Money.storage;
- } else {
- return settings.minimumMoney;
- }
- }
- function wouldBreakMoneyFloor(buyValue){
- return resources.Money.amount - buyValue < getMinMoney();
- }
- })($);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement