diff --git a/LICENSE b/LICENSE index 2e716b7..5a14911 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +# factorio-calc + The MIT License (MIT) Copyright (c) 2014 Ruy Asan @@ -18,4 +20,28 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. + +# lua.vm.js + +The MIT License (MIT) + +Copyright (c) 2013 Alon Zakai (kripken) +Copyright (c) 2014-2016 Daurnimator + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/calc.lua b/calc.lua new file mode 100644 index 0000000..c886046 --- /dev/null +++ b/calc.lua @@ -0,0 +1,79 @@ +local function required_asslvl(ingredient_count) + if ingredient_count > 4 then return 1.25 end + if ingredient_count > 2 then return 0.75 end + return 0.5 +end + +function get_recipe(name, options) + local rdata = data.raw.recipe[name] + local recipe = {} + if not rdata then + return rdata + end + recipe.name = rdata.name + recipe.time = rdata.energy_required or 0.5 + if rdata.category == 'smelting' then + console(options.smeltlvl) + recipe.time = recipe.time / tonumber(options.smeltlvl) + recipe.outputs = rdata.result_count or 1 + elseif rdata.category == 'chemistry' then + recipe.time = recipe.time / 1.25 + if rdata.results then + for i, res in ipairs(rdata.results) do + if res.name == recipe.name then + recipe.outputs = res.amount + end + end + else + recipe.outputs = 1 + end + else + recipe.time = recipe.time / math.max( + tonumber(options.asslvl), + required_asslvl(#rdata.ingredients) + ) + recipe.outputs = rdata.result_count or 1 + end + recipe.ips = recipe.outputs / recipe.time + recipe.inputs = {} + for i, ingr in ipairs(rdata.ingredients) do + local ingredient = {} + if ingr.name then + ingredient.name = ingr.name + ingredient.amount = ingr.amount + else + ingredient.name = ingr[1] + ingredient.amount = ingr[2] + end + table.insert(recipe.inputs, ingredient) + end + return recipe +end + + +function request(name, ips, options) + local recipe = get_recipe(name, options) + if not options then + options = {asslvl = 1, smeltlvl = 1, beltlvl = 14.2} + end + if not recipe then + return {name = name, ips=ips} + end + + local req = {} + req.name = recipe.name + req.ips = ips + req.ipspa = recipe.ips + req.assemblers = req.ips / req.ipspa + req.assembler_max_line = tonumber(options.beltlvl) / recipe.ips + req.lines_required = req.assemblers / math.floor(req.assembler_max_line) + req.cycle_time = recipe.time + req.inputs = {} + for i, input in ipairs(recipe.inputs) do + local ingr_per_cycle = input.amount * req.assemblers + local ingr_required_ips = ingr_per_cycle / req.cycle_time + table.insert(req.inputs, + request(input.name, ingr_required_ips, options)) + end + return req +end \ No newline at end of file diff --git a/calculator.js b/calculator.js index a84be52..c66400c 100644 --- a/calculator.js +++ b/calculator.js @@ -88,6 +88,8 @@ App.Calculator = { return {name: rawIngredient[0], amount: rawIngredient[1]}; } }); + + recipe.minAssemblerLevel = this._getMinAssemblerLevel(recipe); return recipe; }, @@ -137,6 +139,18 @@ App.Calculator = { return finalTotals; }, + _getMinAssemblerLevel: function(recipe) { + + if (recipe.ingredients.length > 4) { + return 1.25; + } else if (recipe.ingredients.length > 2) { + return 0.75; + } else { + return 0.5; + } + + }, + _getAssemblyInfoForRecipe: function(recipe, options) { var assemblyTime; @@ -151,7 +165,7 @@ App.Calculator = { assemblyTime = recipe.baseTime; } else { - assemblyTime = recipe.baseTime / parseFloat(options.asslvl); + assemblyTime = recipe.baseTime / Math.max(recipe.minAssemblerLevel, parseFloat(options.asslvl)); } var oneAssemblerRate = recipe.outputs / assemblyTime; diff --git a/data/core-0-15-02.lua b/data/core-0-15-2.lua similarity index 100% rename from data/core-0-15-02.lua rename to data/core-0-15-2.lua diff --git a/explain.jsx b/explain.jsx index 26df40f..13f4de6 100644 --- a/explain.jsx +++ b/explain.jsx @@ -36,11 +36,7 @@ App.Explain = React.createClass({ var recipe = this.props.recipe; var details = null; if (this.props.recipe.assemblersRequired) { - - var madeBySingular = "assembler"; - var madeByPlural = "assemblers"; - var madeUnits = "items"; - var assemblerPartOne = (Your chosen assembler has a crafting speed of { bmono(this.props.options.asslvl) }. This means it will take {decimalNumber(recipe.assemblyTime)} seconds to create { wholeNumber(recipe.outputs)} { bmono(recipe.name) }.); + var madeBySingular, madeByPlural, madeUnits, assemblerPartOne; if (recipe.category == "ore") { madeBySingular = "drill"; madeByPlural = "drills"; @@ -53,10 +49,15 @@ App.Explain = React.createClass({ madeBySingular = "chemplant"; madeByPlural = "chemplants"; assemblerPartOne = (Chemplants have a crafting speed of { bmono(1.25) }. This means it will take {decimalNumber(recipe.assemblyTime)} seconds to create { wholeNumber(recipe.outputs)} { bmono(recipe.name) }.); + } else { + madeBySingular = "assembler"; + madeByPlural = "assemblers"; + assemblerPartOne = (Your chosen assembler has a crafting speed of { bmono(Math.max(recipe.minAssemblerLevel, this.props.options.asslvl)) }. This means it will take {decimalNumber(recipe.assemblyTime)} seconds to create { wholeNumber(recipe.outputs)} { bmono(recipe.name) }.); } - if (recipe.type == "fluid") - { + if (recipe.type == "fluid") { madeUnits = "units"; + } else { + madeUnits = "items"; } var assemblyLinesExplanation = null; diff --git a/index.html b/index.html index 958c4e7..dbcb4b4 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@