bypass setting
This commit is contained in:
parent
8b9eac3ba4
commit
9b9803c94e
5 changed files with 137 additions and 50 deletions
|
|
@ -1,4 +1,9 @@
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
|
Version: 0.7.0
|
||||||
|
Date: 2021-06-16
|
||||||
|
Features:
|
||||||
|
- Recipe bypass setting
|
||||||
|
---------------------------------------------------------------------------------------------------
|
||||||
Version: 0.6.14
|
Version: 0.6.14
|
||||||
Date: 2021-06-02
|
Date: 2021-06-02
|
||||||
Features:
|
Features:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bzsilicon",
|
"name": "bzsilicon",
|
||||||
"version": "0.6.14",
|
"version": "0.7.0",
|
||||||
"factorio_version": "1.1",
|
"factorio_version": "1.1",
|
||||||
"title": "Silica & Silicon",
|
"title": "Silica & Silicon",
|
||||||
"author": "Brevven",
|
"author": "Brevven",
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,11 @@ optical-fiber=__ITEM__optical-fiber__
|
||||||
# Settings
|
# Settings
|
||||||
|
|
||||||
[mod-setting-name]
|
[mod-setting-name]
|
||||||
|
bzsilicon-recipe-bypass=Bypass recipes
|
||||||
bzsilicon-more-intermediates=Enable more intermediate recipes such as silicon wafers.
|
bzsilicon-more-intermediates=Enable more intermediate recipes such as silicon wafers.
|
||||||
bzsilicon-bio-crushed-stone=When using Bio Industries, use crushed stone to make silica.
|
bzsilicon-bio-crushed-stone=When using Bio Industries, use crushed stone to make silica.
|
||||||
|
|
||||||
[mod-setting-description]
|
[mod-setting-description]
|
||||||
|
bzsilicon-recipe-bypass=Skip modifying these recipes (comma-separated list).
|
||||||
bzsilicon-more-intermediates=More complex production chains. Optional in vanilla, Krastorio 2, etc. [color=red]Required for Bio Industries.[/color]
|
bzsilicon-more-intermediates=More complex production chains. Optional in vanilla, Krastorio 2, etc. [color=red]Required for Bio Industries.[/color]
|
||||||
bzsilicon-bio-crushed-stone=This setting is experimental, and may be removed in a future update. It's strongly recommended to keep it enabled. Only disable if your UPS is dropping due to inserter count. Added per user request.
|
bzsilicon-bio-crushed-stone=This setting is experimental, and may be removed in a future update. It's strongly recommended to keep it enabled. Only disable if your UPS is dropping due to inserter count. Added per user request.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
data:extend(
|
data:extend( {
|
||||||
{
|
{
|
||||||
|
type = "string-setting",
|
||||||
|
name = "bzsilicon-recipe-bypass",
|
||||||
|
setting_type = "startup",
|
||||||
|
default_value = "",
|
||||||
|
allow_blank = true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type = "string-setting",
|
type = "string-setting",
|
||||||
name = "bzsilicon-more-intermediates",
|
name = "bzsilicon-more-intermediates",
|
||||||
|
|
|
||||||
146
util.lua
146
util.lua
|
|
@ -1,7 +1,16 @@
|
||||||
local util = {}
|
local util = {}
|
||||||
|
|
||||||
|
util.name = "bzsilicon"
|
||||||
util.silicon_processing = mods["Krastorio2"] and "kr-silicon-processing" or "silicon-processing"
|
util.silicon_processing = mods["Krastorio2"] and "kr-silicon-processing" or "silicon-processing"
|
||||||
|
|
||||||
|
function util.more_intermediates()
|
||||||
|
return mods["Bio_Industries"] or util.get_setting("bzsilicon-more-intermediates") == "yes"
|
||||||
|
end
|
||||||
|
|
||||||
|
function util.use_bio_crushed_stone()
|
||||||
|
return mods["Bio_Industries"] and util.get_setting("bzsilicon-bio-crushed-stone") == true
|
||||||
|
end
|
||||||
|
|
||||||
function util.get_setting(name)
|
function util.get_setting(name)
|
||||||
if settings.startup[name] == nil then
|
if settings.startup[name] == nil then
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -9,12 +18,11 @@ function util.get_setting(name)
|
||||||
return settings.startup[name].value
|
return settings.startup[name].value
|
||||||
end
|
end
|
||||||
|
|
||||||
function util.more_intermediates()
|
local bypass = {}
|
||||||
return mods["Bio_Industries"] or util.get_setting("bzsilicon-more-intermediates") == "yes"
|
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.use_bio_crushed_stone()
|
|
||||||
return mods["Bio_Industries"] and util.get_setting("bzsilicon-bio-crushed-stone") == true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function util.get_stack_size(default)
|
function util.get_stack_size(default)
|
||||||
|
|
@ -25,26 +33,64 @@ function util.get_stack_size(default)
|
||||||
return default
|
return default
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove an element of type t and name from data.raw
|
-- check if a table contains a sought value
|
||||||
function util.remove_raw(t, name)
|
function util.contains(table, sought)
|
||||||
for i, elem in pairs(data.raw[t]) do
|
for i, value in pairs(table) do
|
||||||
if elem.name == name then
|
if value == sought then
|
||||||
data.raw[t][i] = nil
|
return true
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add a prerequisite to a given technology
|
-- Add a prerequisite to a given technology
|
||||||
function util.add_prerequisite(technology_name, prerequisite)
|
function util.add_prerequisite(technology_name, prerequisite)
|
||||||
technology = data.raw.technology[technology_name]
|
technology = data.raw.technology[technology_name]
|
||||||
if technology then
|
if technology and data.raw.technology[prerequisite] then
|
||||||
|
if technology.prerequisites then
|
||||||
table.insert(technology.prerequisites, prerequisite)
|
table.insert(technology.prerequisites, prerequisite)
|
||||||
|
else
|
||||||
|
technology.prerequisites = {prerequisite}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Remove a prerequisite from a given technology
|
||||||
|
function util.remove_prerequisite(technology_name, prerequisite)
|
||||||
|
technology = data.raw.technology[technology_name]
|
||||||
|
local index = -1
|
||||||
|
if technology and data.raw.technology[prerequisite] then
|
||||||
|
for i, prereq in pairs(technology.prerequisites) do
|
||||||
|
if prereq == prerequisite then
|
||||||
|
index = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if index > -1 then
|
||||||
|
table.remove(technology.prerequisites, index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add an effect to a given technology
|
||||||
|
function util.add_effect(technology_name, effect)
|
||||||
|
technology = data.raw.technology[technology_name]
|
||||||
|
if technology then
|
||||||
|
table.insert(technology.effects, effect)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set technology ingredients
|
||||||
|
function util.set_tech_recipe(technology_name, ingredients)
|
||||||
|
technology = data.raw.technology[technology_name]
|
||||||
|
if technology then
|
||||||
|
technology.unit.ingredients = ingredients
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add a given quantity of ingredient to a given recipe
|
-- Add a given quantity of ingredient to a given recipe
|
||||||
function util.add_ingredient(recipe_name, ingredient, quantity)
|
function util.add_ingredient(recipe_name, ingredient, quantity)
|
||||||
|
if bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] then
|
if data.raw.recipe[recipe_name] then
|
||||||
add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
||||||
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
|
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
|
||||||
|
|
@ -54,8 +100,9 @@ end
|
||||||
|
|
||||||
function add_ingredient(recipe, ingredient, quantity)
|
function add_ingredient(recipe, ingredient, quantity)
|
||||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
if recipe ~= nil and recipe.ingredients ~= nil then
|
||||||
for _, existing in ipairs(recipe.ingredients) do
|
for i, existing in pairs(recipe.ingredients) do
|
||||||
if ingredient == existing.name or ingredient == existing[1] then
|
if existing[1] == ingredient or existing.name == ingredient then
|
||||||
|
log("Not adding "..ingredient.." -- duplicate")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -63,8 +110,25 @@ function add_ingredient(recipe, ingredient, quantity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Replace one ingredien with another in a recipe
|
-- Add a given quantity of product to a given recipe.
|
||||||
|
-- Only works for recipes with multiple products
|
||||||
|
function util.add_product(recipe_name, product)
|
||||||
|
if data.raw.recipe[recipe_name] then
|
||||||
|
add_product(data.raw.recipe[recipe_name], product)
|
||||||
|
add_product(data.raw.recipe[recipe_name].normal, product)
|
||||||
|
add_product(data.raw.recipe[recipe_name].expensive, product)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function add_product(recipe, product)
|
||||||
|
if recipe ~= nil and recipe.results ~= nil then
|
||||||
|
table.insert(recipe.results, product)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Replace one ingredient with another in a recipe
|
||||||
function util.replace_ingredient(recipe_name, old, new)
|
function util.replace_ingredient(recipe_name, old, new)
|
||||||
|
if bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] then
|
if data.raw.recipe[recipe_name] then
|
||||||
replace_ingredient(data.raw.recipe[recipe_name], old, new)
|
replace_ingredient(data.raw.recipe[recipe_name], old, new)
|
||||||
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new)
|
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new)
|
||||||
|
|
@ -74,10 +138,14 @@ end
|
||||||
|
|
||||||
function replace_ingredient(recipe, old, new)
|
function replace_ingredient(recipe, old, new)
|
||||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
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 i, ingredient in pairs(recipe.ingredients) do
|
||||||
-- For final fixes
|
|
||||||
if ingredient.name == old then ingredient.name = new end
|
if ingredient.name == old then ingredient.name = new end
|
||||||
-- For updates
|
|
||||||
if ingredient[1] == old then ingredient[1] = new end
|
if ingredient[1] == old then ingredient[1] = new end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -85,6 +153,7 @@ end
|
||||||
|
|
||||||
-- Remove an ingredient from a recipe
|
-- Remove an ingredient from a recipe
|
||||||
function util.remove_ingredient(recipe_name, old)
|
function util.remove_ingredient(recipe_name, old)
|
||||||
|
if bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] then
|
if data.raw.recipe[recipe_name] then
|
||||||
remove_ingredient(data.raw.recipe[recipe_name], old)
|
remove_ingredient(data.raw.recipe[recipe_name], old)
|
||||||
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
|
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
|
||||||
|
|
@ -110,17 +179,28 @@ end
|
||||||
|
|
||||||
-- Replace an amount of an ingredient in a recipe. Keep at least 1 of old.
|
-- 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)
|
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], old, old_amount, new, new_amount)
|
||||||
replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount)
|
replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount)
|
||||||
replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount)
|
replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
|
function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
|
||||||
if recipe ~= nil and recipe.ingredients ~= nil then
|
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 i, ingredient in pairs(recipe.ingredients) do
|
||||||
|
-- For final fixes
|
||||||
if ingredient.name == old then
|
if ingredient.name == old then
|
||||||
ingredient.amount = math.max(1, ingredient.amount - old_amount)
|
ingredient.amount = math.max(1, ingredient.amount - old_amount)
|
||||||
end
|
end
|
||||||
|
-- For updates
|
||||||
if ingredient[1] == old then
|
if ingredient[1] == old then
|
||||||
ingredient[2] = math.max(1, ingredient[2] - old_amount)
|
ingredient[2] = math.max(1, ingredient[2] - old_amount)
|
||||||
end
|
end
|
||||||
|
|
@ -129,31 +209,15 @@ function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add an effect to a given technology
|
|
||||||
function util.add_effect(technology_name, effect)
|
|
||||||
technology = data.raw.technology[technology_name]
|
|
||||||
if technology then
|
|
||||||
table.insert(technology.effects, effect)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if a table contains a sought value
|
|
||||||
function util.contains(table, sought)
|
|
||||||
for i, value in pairs(table) do
|
|
||||||
if value == sought then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- multiply the cost, energy, and results of a recipe by a multiple
|
-- multiply the cost, energy, and results of a recipe by a multiple
|
||||||
function util.multiply_recipe(recipe_name, 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], multiple)
|
||||||
multiply_recipe(data.raw.recipe[recipe_name].normal, multiple)
|
multiply_recipe(data.raw.recipe[recipe_name].normal, multiple)
|
||||||
multiply_recipe(data.raw.recipe[recipe_name].expensive, multiple)
|
multiply_recipe(data.raw.recipe[recipe_name].expensive, multiple)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function multiply_recipe(recipe, multiple)
|
function multiply_recipe(recipe, multiple)
|
||||||
if recipe then
|
if recipe then
|
||||||
|
|
@ -199,4 +263,14 @@ function multiply_recipe(recipe, multiple)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Remove an element of type t and name from data.raw
|
||||||
|
function util.remove_raw(t, name)
|
||||||
|
for i, elem in pairs(data.raw[t]) do
|
||||||
|
if elem.name == name then
|
||||||
|
data.raw[t][i] = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return util
|
return util
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue