bypass setting

This commit is contained in:
Brevven 2021-06-15 01:49:00 -07:00
parent ce9cb905d0
commit 54d6241679
5 changed files with 106 additions and 10 deletions

View file

@ -1,12 +1,6 @@
local util = {}
function util.get_setting(name)
if settings.startup[name] == nil then
return nil
end
return settings.startup[name].value
end
util.name = "bzzirconium"
function util.fe_plus(sub)
if mods["FactorioExtended-Plus-"..sub] then
@ -18,6 +12,20 @@ function util.use_cermet()
return util.get_setting("bzzirconium-enable-intermediates") == "yes"
end
function util.get_setting(name)
if settings.startup[name] == nil then
return nil
end
return settings.startup[name].value
end
local bypass = {}
if util.get_setting(util.name.."-recipe-bypass") then
for recipe in string.gmatch(util.get_setting(util.name.."-recipe-bypass"), '[^",%s]+') do
bypass[recipe] = true
end
end
function util.get_stack_size(default)
if mods["Krastorio2"] then
size = tonumber(krastorio.general.getSafeSettingValue("kr-stack-size"))
@ -83,6 +91,7 @@ end
-- Add a given quantity of ingredient to a given recipe
function util.add_ingredient(recipe_name, ingredient, quantity)
if bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] then
add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
@ -92,6 +101,12 @@ end
function add_ingredient(recipe, ingredient, quantity)
if recipe ~= nil and recipe.ingredients ~= nil then
for i, existing in pairs(recipe.ingredients) do
if existing[1] == ingredient or existing.name == ingredient then
log("Not adding "..ingredient.." -- duplicate")
return
end
end
table.insert(recipe.ingredients, {ingredient, quantity})
end
end
@ -114,6 +129,7 @@ end
-- Replace one ingredient with another in a recipe
function util.replace_ingredient(recipe_name, old, new)
if bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] then
replace_ingredient(data.raw.recipe[recipe_name], old, new)
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new)
@ -123,6 +139,12 @@ end
function replace_ingredient(recipe, old, new)
if recipe ~= nil and recipe.ingredients ~= nil then
for i, existing in pairs(recipe.ingredients) do
if existing[1] == new or existing.name == new then
log("Not adding "..new.." -- duplicate")
return
end
end
for i, ingredient in pairs(recipe.ingredients) do
if ingredient.name == old then ingredient.name = new end
if ingredient[1] == old then ingredient[1] = new end
@ -132,6 +154,7 @@ end
-- Remove an ingredient from a recipe
function util.remove_ingredient(recipe_name, old)
if bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] then
remove_ingredient(data.raw.recipe[recipe_name], old)
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
@ -157,6 +180,7 @@ end
-- Replace an amount of an ingredient in a recipe. Keep at least 1 of old.
function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount)
if bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] then
replace_some_ingredient(data.raw.recipe[recipe_name], old, old_amount, new, new_amount)
replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount)
@ -166,6 +190,12 @@ end
function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
if recipe ~= nil and recipe.ingredients ~= nil then
for i, existing in pairs(recipe.ingredients) do
if existing[1] == new or existing.name == new then
log("Not adding "..new.." -- duplicate")
return
end
end
for i, ingredient in pairs(recipe.ingredients) do
-- For final fixes
if ingredient.name == old then
@ -180,5 +210,58 @@ function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
end
end
-- multiply the cost, energy, and results of a recipe by a multiple
function util.multiply_recipe(recipe_name, multiple)
if bypass[recipe_name] then return end
if data.raw.recipe[recipe_name] then
multiply_recipe(data.raw.recipe[recipe_name], multiple)
multiply_recipe(data.raw.recipe[recipe_name].normal, multiple)
multiply_recipe(data.raw.recipe[recipe_name].expensive, multiple)
end
end
function multiply_recipe(recipe, multiple)
if recipe then
if recipe.energy_required then
recipe.energy_required = recipe.energy_required * multiple
end
if recipe.result_count then
recipe.result_count = recipe.result_count * multiple
end
if recipe.results then
for i, result in pairs(recipe.results) do
if result.name then
if result.amount then
result.amount = result.amount * multiple
end
if result.amount_min ~= nil then
result.amount_min = result.amount_min * multiple
result.amount_max = result.amount_max * multiple
end
if result.catalyst_amount then
result.catalyst_amount = result.catalyst_amount * multiple
end
end
if result[1] then
result[2] = result[2] * multiple
end
end
end
if not recipe.results and not recipe.result_count then
-- implicit one item result
recipe.result_count = multiple
end
if recipe.ingredients then
for i, ingredient in pairs(recipe.ingredients) do
if ingredient.name then
ingredient.amount = ingredient.amount * multiple
end
if ingredient[1] then
ingredient[2] = ingredient[2] * multiple
end
end
end
end
end
return util