After doing a bunch of updates, I'll note that it's best to download the file linked above, rather than reference the code in this post. That file will be updated any time I run an upload on my mod kit (about once per day). It's onerous to update the code in this post, as I'm always fixing, improving, and tweaking these functions. But I'll leave the code here so people get an idea of what the library is all about.
I'll probably move a few control phase functions in here, like moving inventories around. But I feel like there should be a luaInventory function to do that.
Code: Select all
-- Freeware modding by Adamo
require("util")
add_recipe_to_tech = function(tech_name,recipe_name)
if type(recipe_name) == "table" then
add_recipes_to_tech(recipe_name)
end
local recipe_name = string_name_or_bust(recipe_name)
local tech = false
if type(tech_name) == "table"
and tech_name.type == "technology" then
tech = tech_name
else
tech = data.raw["technology"][tech_name]
end
if tech then
if not tech.effects then
tech.effects = {{
type="unlock-recipe",
recipe=recipe_name
}}
else
table.insert(tech.effects, {
type="unlock-recipe",
recipe=recipe_name
})
end
end
end
add_recipes_to_tech = function(tech_name,name_table)
if type(name_table) ~= "table" then return nil end
for _,name in pairs(name_table) do
add_recipe_to_tech(tech_name,name)
end
end
find_recipe_techs = function(recipe_name)
local tech_names = {}
local recipe_name = string_name_or_bust(recipe_name)
for k,tech in pairs(data.raw.technology) do
local found_tech = false
if tech.effects then
for l,effect in pairs(tech.effects) do
if effect.type == "unlock-recipe"
and effect.recipe == recipe_name then
table.insert(
tech_names,
tech.name
)
end
end
end
end
return tech_names
end
mirror_recipe_in_techs = function(orig_recipe,new_recipe)
local tech_names = find_recipe_techs(orig_recipe)
for _,tech_name in pairs(tech_names) do
add_recipe_to_tech(tech_name,new_recipe)
end
end
mult_recipe_energy = function(recipe,mult)
local recipe = recipe_or_bust(recipe)
if recipe.normal then
recipe.normal.energy_required =
(recipe.normal.energy_required or 0.5)
* mult
if recipe.expensive then
recipe.expensive.energy_required =
(recipe.expensive.energy_required or 0.5)
* mult
end
else
recipe.energy_required =
(recipe.energy_required or 0.5)
* mult
end
end
get_recipe_energy = function(recipe)
local recipe = recipe_or_bust(recipe)
if not recipe then return nil,0,0 end
local normal_energy_required = 1
local expensive_energy_required = 1
if recipe.normal then
normal_energy_required =
recipe.normal.energy_required
if recipe.expensive then
expensive_energy_required =
recipe.expensive.energy_required
end
else
return (recipe.energy_required or 0.5)
end
return normal_energy_required,expensive_energy_required
end
set_recipe_hidden = function(recipe)
recipe = table_or_bust(recipe)
if not recipe then return nil end
if recipe.normal
and type(recipe.normal) == "table" then
recipe.normal.hidden = true
end
if recipe.expensive
and type(recipe.expensive) == "table" then
recipe.expensive.hidden = true
end
recipe.hidden = true
return true
end
mult_recipe_io = function(
recipe,
amount_mult,
name
)
if name then
replace_recipe_io(recipe,name,name,amount_mult)
else
local ingredients,results = get_io_names(recipe)
for _,name in pairs(ingredients) do
replace_recipe_io(recipe,name,name,amount_mult)
end
for _,name in pairs(results) do
replace_recipe_io(recipe,name,name,amount_mult)
end
end
end
replace_in_recipe_io = function(
recipe,old_name,new_name,amount_mult
)
replace_recipe_io(recipe,old_name,new_name,amount_mult)
end
replace_recipe_io = function(
recipe,old_name,new_name,amount_mult
)
local recipe = recipe_or_bust(recipe)
if not recipe then return false end
if amount_mult == nil
or type(amount_mult) ~= "number" then
amount_mult = 1
end
if recipe.result then
if recipe.result == old_name then
recipe.result = new_name
recipe.result_count = math.floor(
(recipe.result_count or 1)
* amount_mult
)
end
end
if recipe.normal and recipe.normal.result then
if recipe.normal.result == old_name then
recipe.normal.result = new_name
recipe.normal.result_count = math.floor(
(recipe.normal.result_count or 1)
* amount_mult
)
end
end
if recipe.expensive and recipe.expensive.result then
if recipe.expensive.result == old_name then
recipe.expensive.result = new_name
recipe.expensive.result_count = math.floor(
(recipe.expensive.result_count or 1)
* amount_mult
)
end
end
for _,ingredient in pairs(recipe.ingredients or {}) do
if ingredient.name == old_name then
ingredient.name = new_name
ingredient.amount = math.ceil(
(ingredient.amount or ingredient[2] or 1)
* amount_mult
)
ingredient[2] = nil
end
if ingredient[1] == old_name then
ingredient[1] = new_name
ingredient[2] = math.ceil(
(ingredient[2] or ingredient.amount or 1)
* amount_mult
)
ingredient.amount = nil
end
if ingredient.name == nil
and ingredient[1] == nil then
ingredient = nil
end
end
if recipe.normal then
for _,ingredient
in pairs(recipe.normal.ingredients or {}) do
if ingredient.name == old_name then
ingredient.name = new_name
ingredient.amount = math.ceil(
(ingredient.amount or ingredient[2] or 1)
* amount_mult
)
ingredient[2] = nil
end
if ingredient[1] == old_name then
ingredient[1] = new_name
ingredient[2] = math.ceil(
(ingredient[2] or ingredient.amount or 1)
* amount_mult
)
ingredient.amount = nil
end
if ingredient.name == nil
and ingredient[1] == nil then
ingredient = nil
end
end
end
if recipe.expensive then
for _,ingredient
in pairs(recipe.expensive.ingredients or {}) do
if ingredient.name == old_name then
ingredient.name = new_name
ingredient.amount = math.ceil(
(ingredient.amount or ingredient[2] or 1)
* amount_mult
)
ingredient[2] = nil
end
if ingredient[1] == old_name then
ingredient[1] = new_name
ingredient[2] = math.ceil(
(ingredient[2] or ingredient.amount or 1)
* amount_mult
)
ingredient.amount = nil
end
if ingredient.name == nil
and ingredient[1] == nil then
ingredient = nil
end
end
end
for _,result in pairs(recipe.results or {}) do
if result.name == old_name then
result.name = new_name
result.amount = math.floor(
(result.amount or result[2] or 1)
* amount_mult
)
end
if result[1] == old_name then
result[1] = new_name
result[2] = math.floor(
(result[2] or result.amount or 1)
* amount_mult
)
result.amount = nil
end
if result.name == nil
and result[1] == nil then
result = nil
end
end
if recipe.normal then
for _,result in pairs(recipe.normal.results or {}) do
if result.name == old_name then
result.name = new_name
result.amount = math.floor(
(result.amount or result[2] or 1)
* amount_mult
)
end
if result[1] == old_name then
result[1] = new_name
result[2] = math.floor(
(result[2] or result.amount or 1)
* amount_mult
)
result.amount = nil
end
if result.name == nil
and result[1] == nil then
result = nil
end
end
end
if recipe.expensive then
for _,result
in pairs(recipe.expensive.results or {}) do
if result.name == old_name then
result.name = new_name
result.amount = math.floor(
(result.amount or result[2] or 1)
* amount_mult
)
end
if result[1] == old_name then
result[1] = new_name
result[2] = math.floor(
(result[2] or result.amount or 1)
* amount_mult
)
result.amount = nil
end
if result.name == nil
and result[1] == nil then
result = nil
end
end
end
end
add_ingredient = function(recipe,ingred,count,prob)
if type(count) == "number" and count == 0 then
return nil
end
if type(prob) == "number" and count == 0 then
return nil
end
local recipe = recipe_or_bust(recipe)
local ingred = io_prototype_or_bust(ingred,count,prob)
if type(prob) ~= "number" then prob = nil end
if not recipe or not ingred then return nil end
if uses_ingredient(recipe,ingred.name) then
if recipe.normal then
if recipe.expensive then
for _,ingredient
in pairs(recipe.expensive.ingredients or {})
do
if ingredient.name == ingred.name then
ingredient.amount =
math.floor(
ingredient.amount
+ count * (prob or 1)*2
)
end
end
end
for _,ingredient
in pairs(recipe.normal.ingredients or {})
do
if ingredient.name == ingred.name then
ingredient.amount =
math.floor(
ingredient.amount
+ count * (prob or 1)
)
end
end
else
for _,ingredient
in pairs(recipe.ingredients or {})
do
if ingredient.name == ingred.name then
ingredient.amount =
math.floor(
ingredient.amount
+ count * (prob or 1)
)
end
end
end
else
if recipe.normal then
if recipe.expensive then
table.insert(
recipe.expensive.ingredients,
ingred
)
end
table.insert(recipe.normal.ingredients,ingred)
else
table.insert(recipe.ingredients,ingred)
end
end
end
-- might not be working right
blend_io = function(io_base,io_blend)
local io_base = io_prototype_or_bust(io_base)
local io_blend = io_prototype_or_bust(io_blend)
if not io_base or not io_blend then return nil end
count = io_blend.amount or 1
prob = io_blend.probability
if io_base.probability then
io_base.probability =
(
(io_base.amount or 1)
*io_base.probability
+(count or 1)*(prob or 1)
)/(
(io_base.amount or 1)
+ (count or 1)
)
io_base.amount =
math.floor(io_base.amount + count)
else
if prob then
io_base.probability =
(
(io_base.amount or 1)
+(count or 1)*(prob or 1)
)/(
(io_base.amount or 1)
+ (count or 1)
)
io_base.amount =
math.floor(io_base.amount + count)
else
io_base.amount =
math.floor(io_base.amount + count)
end
end
return io_base
end
add_result = function(recipe,product,count,prob)
if type(count) == "number" and count == 0 then
return nil
end
if type(prob) == "number" and count == 0 then
return nil
end
local recipe = recipe_or_bust(recipe)
local product = io_prototype_or_bust(product,count,prob)
if not recipe or not product then return nil end
if type(count) ~= "number" then count = nil end
if type(prob) ~= "number" then prob = nil end
format_results(recipe)
local found_result = false
if recipe.normal then
if recipe.expensive then
for _,result
in pairs(recipe.expensive.results
or {recipe.expensive.result}
) do
if result.name == product.name then
found_result = true
result = blend_io(result,product)
end
end
end
for _,result
in pairs(recipe.normal.results
or {recipe.normal.result}
) do
if result.name == product.name then
found_result = true
result = blend_io(result,product)
end
end
else
for _,result
in pairs(recipe.results
or {recipe.result}
) do
if result.name == product.name then
found_result = true
result = blend_io(result,product)
end
end
end
if not found_result then
if recipe.normal then
local exp_product = util.table.deepcopy(product)
exp_product.amount = (exp_product.amount or 1)*2
if recipe.expensive then
table.insert(
recipe.expensive.results,exp_product
)
end
table.insert(recipe.normal.results,product)
else
table.insert(recipe.results,product)
end
end
end
format_results = function(recipe)
local recipe = recipe_or_bust(recipe)
if not recipe.results then
if recipe.normal then
if recipe.expensive then
if not recipe.expensive.results then
if recipe.expensive.result then
recipe.expensive.results = {{
type = "item",
name = recipe.expensive.result,
amount =
recipe.expensive.result_count
or 1
}}
if not recipe.expensive.main_product then
recipe.expensive.main_product =
recipe.expensive.result
end
recipe.expensive.result = nil
recipe.expensive.result_count = nil
end
else
if not recipe.expensive.main_product then
recipe.expensive.main_product =
recipe.expensive.result
end
recipe.expensive.result = nil
recipe.expensive.result_count = nil
end
end
if not recipe.normal.results then
if recipe.normal.result then
recipe.normal.results = {{
type = "item",
name = recipe.normal.result,
amount =
recipe.normal.result_count
or 1
}}
if not recipe.normal.main_product then
recipe.normal.main_product =
recipe.normal.result
end
recipe.normal.result = nil
recipe.normal.result_count = nil
end
else
if not recipe.normal.main_product then
recipe.normal.main_product =
recipe.normal.result
end
recipe.normal.result = nil
recipe.normal.result_count = nil
end
end
if recipe.result then
recipe.results = {{
type = "item",
name = recipe.result,
amount =
recipe.result_count
or 1
}}
if not recipe.main_product then
recipe.main_product =
recipe.result
end
recipe.result = nil
recipe.result_count = nil
end
else
if not recipe.main_product then
recipe.main_product =
recipe.result
end
recipe.result = nil
recipe.result_count = nil
end
end
get_main_result = function(recipe)
local recipe = recipe_or_bust(recipe)
if type(recipe) ~= "table" then return end
local result_name = nil
local result_count = 0
local expensive_result_count = 0
if recipe.normal then
if recipe.results then
result_name =
recipe.normal.main_product
or recipe.normal.results[1].name
or recipe.normal.results[1][1]
for _,result in pairs(recipe.normal.results) do
if (result.name == result_name)
or (result[1] == result_name) then
result_count =
result.amount
or result[2]
end
end
else
result_name = recipe.normal.result
result_count = recipe.normal.result_count or 1
end
if recipe.expensive then
if recipe.expensive.results then
for _,result
in pairs(recipe.expensive.results) do
if (result.name == result_name)
or (result[1] == result_name) then
result_count =
result.amount
or result[2]
end
end
else
expensive_result_count =
recipe.expensive.result_count or 1
end
end
else
if recipe.results then
result_name =
recipe.main_product
or recipe.results[1].name
or recipe.results[1][1]
for _,result in pairs(recipe.results) do
if (result.name == result_name)
or (result[1] == result_name) then
result_count =
result.amount
or result[2]
end
end
else
result_name = recipe.result
result_count = recipe.result_count or 1
end
end
return result_name,result_count,expensive_result_count
end
has_ingredients = function(recipe)
local recipe = recipe_or_bust(recipe)
if recipe and type(recipe) == "table" then
if recipe.normal then
if recipe.normal.ingredients then
for _,ingredient
in pairs(recipe.normal.ingredients) do
if ingredient.amount
and ingredient.amount > 0 then
return true
end
if ingredient[2]
and ingredient[2] > 0 then
return true
end
end
end
end
if recipe.ingredients then
for _,ingredient in pairs(recipe.ingredients) do
if ingredient.amount
and ingredient.amount > 0 then
return true
end
if ingredient[2]
and ingredient[2] > 0 then
return true
end
end
end
end
return false
end
has_results = function(recipe)
local recipe = recipe_or_bust(recipe)
if not recipe then return false end
if recipe.normal then
if recipe.normal.results then
for _,result
in pairs(recipe.normal.results) do
if result.amount
and result.amount > 0 then
return true
end
if result[2]
and result[2] > 0 then
return true
end
end
end
end
if recipe.results then
for _,result in pairs(recipe.results) do
if result.amount
and result.amount > 0 then
return true
end
if result[2]
and result[2] > 0 then
return true
end
end
end
return false
end
get_io_names = function(recipe)
local recipe = recipe_or_bust(recipe)
if not recipe or recipe.type ~= "recipe" then
return {}
end
local ingredients = {}
local results = {}
if recipe.normal then
if recipe.expensive then
add_strings_to_list(
get_table_names(recipe.expensive.ingredients),
ingredients
)
add_strings_to_list(
get_table_names(recipe.expensive.results),
results
)
add_string_to_list(
recipe.expensive.result,
results
)
end
add_strings_to_list(
get_table_names(recipe.normal.ingredients),
ingredients
)
add_strings_to_list(
get_table_names(recipe.normal.results),
results
)
add_string_to_list(
recipe.normal.result,
results
)
else
add_strings_to_list(
get_table_names(recipe.ingredients),
ingredients
)
add_strings_to_list(
get_table_names(recipe.results),
results
)
add_string_to_list(
recipe.result,
results
)
end
return ingredients,results
end
uses_ingredient = function(recipe,name)
local name = string_name_or_bust(name)
local recipe = recipe_or_bust(recipe)
if not recipe or not name then return false end
local ingredients,results = get_io_names(recipe)
for _,ingredient in pairs(ingredients) do
if ingredient == name then
return true
end
end
return false
end
get_table_names = function(prototable)
local names = {}
local prototable = table_or_bust(prototable)
if not prototable then return end
for _,prototype in pairs(prototable) do
prototype = table_or_bust(prototype)
if prototype then
if prototype.name
and type(prototype.name) == "string" then
table.insert(
names,
prototype.name
)
elseif prototype[1]
and type(prototype[1]) == "string" then
table.insert(
names,
prototype[1]
)
end
end
end
return names
end
get_ingredient = function(recipe,index)
local recipe = recipe_or_bust(recipe)
if type(recipe) ~= "table" then return end
local ingredient_name = index
local ingredient_amount = 0
local expensive_amount = 0
if not has_ingredients(recipe) then return nil,0,0 end
if recipe.normal
and type(recipe.normal.ingredients) == "table" then
if type(ingredient_name) == "string" then
for _,ingredient
in pairs(recipe.normal.ingredients) do
if (ingredient.name == ingredient_name)
or (ingredient[1] == ingredient_name)
then
ingredient_amount =
ingredient.amount
or ingredient[2]
end
end
if ingredient_amount == 0 then
return nil,0,0
end
if recipe.expensive then
for _,ingredient
in pairs(recipe.expensive.ingredients or {}) do
if (ingredient.name == ingredient_name)
or (ingredient[1] == ingredient_name)
then
expensive_amount =
ingredient.amount
or ingredient[2]
end
end
end
else
if type(
recipe.normal.ingredients[ingredient_name]
) == "table" then
ingredient_amount =
recipe.normal
.ingredients[ingredient_name].amount
or recipe.normal
.ingredients[ingredient_name][2]
ingredient_name =
recipe.normal
.ingredients[ingredient_name].name
or recipe.normal
.ingredients[ingredient_name][1]
if recipe.expensive then
for _,ingredient
in pairs(recipe.expensive.ingredients) do
if (
ingredient.name
== ingredient_name
) or (
ingredient[1]
== ingredient_name
) then
expensive_amount =
ingredient.amount
or ingredient[2]
end
end
end
else
return nil,0,0
end
end
else
if type(ingredient_name) == "string" then
for _,ingredient
in pairs(recipe.ingredients or {}) do
if (ingredient.name == ingredient_name)
or (ingredient[1] == ingredient_name)
then
ingredient_amount =
ingredient.amount
or ingredient[2]
end
end
if ingredient_amount == 0 then
return nil,0,0
end
else
if type(recipe.ingredients[ingredient_name])
== "table" then
ingredient_amount =
recipe.ingredients[ingredient_name]
.amount
or recipe.ingredients[ingredient_name][2]
ingredient_name =
recipe.ingredients[ingredient_name].name
or recipe.ingredients[ingredient_name][1]
else
return nil,0,0
end
end
end
return ingredient_name,ingredient_amount,expensive_amount
end
-- Might be broken
get_result = function(recipe,index)
local recipe = recipe_or_bust(recipe)
if not recipe then return end
format_results(recipe)
if not has_results(recipe) then return nil,0,0 end
local result_name = index
local result_amount = 0
local expensive_amount = 0
if recipe.normal
and type(recipe.normal.results) == "table" then
if type(result_name) == "string" then
for _,result in pairs(recipe.normal.results) do
if (result.name == result_name)
or (result[1] == result_name)
then
result_amount =
result.amount or result[2]
end
end
if result_amount == 0 then
return nil,0,0
end
if recipe.expensive then
for _,result
in pairs(recipe.expensive.results or {}) do
if (result.name == result_name)
or (result[1] == result_name)
then
expensive_amount =
result.amount
or result[2]
end
end
end
else
if type(
recipe.normal.results[result_name]
) == "table" then
result_amount =
recipe.normal
.results[result_name].amount
or recipe.normal
.results[result_name][2]
result_name =
recipe.normal
.results[result_name].name
or recipe.normal
.results[result_name][1]
if recipe.expensive then
for _,result
in pairs(recipe.expensive.results) do
if (
result.name
== result_name
) or (
result[1]
== result_name
) then
expensive_amount =
result.amount
or result[2]
end
end
end
else
return nil,0,0
end
end
else
if type(result_name) == "string" then
for _,result
in pairs(recipe.results or {}) do
if (result.name == result_name)
or (result[1] == result_name)
then
result_amount =
result.amount
or result[2]
end
end
if result_amount == 0 then
return nil,0,0
end
else
if type(recipe.results[result_name])
== "table" then
result_amount =
recipe.results[result_name]
.amount
or recipe.results[result_name][2]
result_name =
recipe.results[result_name].name
or recipe.results[result_name][1]
else
return nil,0,0
end
end
end
return result_name,result_amount,expensive_amount
end
set_productivity_recipes = function(recipe_names)
for _,recipe_name in pairs(recipe_names or {}) do
if type(recipe_name) == "table" then
recipe_name = recipe_name.name
end
for k,v in pairs({
data.raw.module["productivity-module"],
data.raw.module["productivity-module-2"],
data.raw.module["productivity-module-3"]
}) do
if v.limitation then
table.insert(v.limitation, recipe_name)
end
end
end
end
set_productivity_recipe = function(recipe_name)
set_productivity_recipes({recipe_name})
end
add_productivity_recipes = function(recipe_names)
set_productivity_recipes(recipe_names)
end
is_productivity_recipe = function(recipe_name)
local recipe_name = string_name_or_bust(recipe_name)
if not data.raw.recipe[recipe_name] then return false end
for k,listed_recipe_name in pairs(
data.raw.module["productivity-module"].limitation
) do
if listed_recipe_name == recipe_name then
return true
end
end
return false
end
find_unused_layer = function()
local unused_layers = {
"layer-11",
"layer-12",
"layer-13",
"layer-14",
"layer-15",
}
for i,data_type in pairs(data.raw) do
for j,data_obj in pairs(data_type) do
for k,layer
in pairs(data_obj.collision_mask or {}) do
for l,unused_layer in pairs(unused_layers) do
if layer == unused_layer then
unused_layers[l] = nil
end
end
end
end
end
for _,layer in pairs(unused_layers) do
return layer
end
return nil
end
set_pipe_distance = function(pipe, dist)
if data.raw["pipe-to-ground"][pipe] then
for _,connection in pairs(
data.raw["pipe-to-ground"][pipe]
.fluid_box.pipe_connections
) do
if connection.max_underground_distance then
data.raw["pipe-to-ground"][pipe]
.fluid_box.pipe_connections[_]
.max_underground_distance = dist
end
end
end
end
set_shift = function(shift, tab)
tab.shift = shift
if tab.hr_version then
tab.hr_version.shift = shift
end
return tab
end
energy_mult = function(energy,mult)
local num = energy:match "[0-9%.]+"
local alpha = energy:match "%a+"
num = num*mult
return (num..alpha)
end
energy_div = function(energy,div)
local num = energy:match "[0-9%.]+"
local alpha = energy:match "%a+"
num = num/div
return (num..alpha)
end
empty_sprite = function()
return {
filename = "__core__/graphics/empty.png",
priority = "extra-high",
width = 1,
height = 1
}
end
bulkypipepictures = function()
local pipe_sprites = pipepictures()
return {
north = set_shift(
{0, 1},
util.table
.deepcopy(pipe_sprites.straight_vertical)
),
south = empty_sprite(),
east = set_shift(
{-1, 0},
util.table
.deepcopy(pipe_sprites.straight_horizontal)
),
west = set_shift(
{1, 0},
util.table
.deepcopy(pipe_sprites.straight_horizontal)
)
}
end
centrifugepipecovers = function()
local covers = pipecoverspictures()
covers.north = empty_sprite()
return covers
end
centrifugepipepictures = function()
local pics = assembler3pipepictures()
pics.north = empty_sprite()
pics.north.hr_version = empty_sprite()
pics.east = empty_sprite()
pics.east.hr_version = empty_sprite()
pics.west = empty_sprite()
pics.west.hr_version = empty_sprite()
return pics
end
apply_sulfur_fuel_stats = function(sulfur)
if type(sulfur) ~= "table"
or sulfur.type ~= "item"
then
log("invalid sulfur item received")
return nil
end
local sulfur_fuel_type = "sulfur"
sulfur.fuel_category = sulfur_fuel_type
sulfur.fuel_emissions_multiplier = 12
sulfur.fuel_value = "600kJ"
sulfur.fuel_acceleration_multiplier = 0.4
sulfur.fuel_glow_color={r=1,g=0.2,b=1,a=1}
activate_basic_burning(sulfur_fuel_type)
return sulfur
end
activate_basic_burning = function(fuel_type)
if not data.raw["fuel-category"][fuel_type] then
data:extend({
{type="fuel-category",name=fuel_type}
})
end
add_fuel_type(data.raw.boiler.boiler,fuel_type)
for _,ent in pairs(data.raw.car) do
if table_incl("chemical",get_fuel_types(ent))
then
add_fuel_type(ent,fuel_type)
end
end
for _,ent in pairs(data.raw.reactor) do
if table_incl("chemical",get_fuel_types(ent))
then
add_fuel_type(ent,fuel_type)
end
end
end
add_fuel_type = function(entity,fuel_type)
entity = table_or_bust(entity)
fuel_type = string_or_bust(fuel_type)
if not entity or not fuel_type then return false end
local energy_source = get_energy_source(entity)
if not energy_source then return false end
if is_burner(energy_source) then
if not energy_source.fuel_categories then
if energy_source.fuel_category then
energy_source
.fuel_categories = {energy_source.fuel_category}
else
energy_source.fuel_categories = {"chemical"}
end
energy_source.fuel_category = nil
end
add_string_to_list(fuel_type,energy_source.fuel_categories)
end
end
get_fuel_types = function(entity)
entity = table_or_bust(entity)
if not entity then return {} end
local energy_source = get_energy_source(entity)
if not energy_source then return {} end
if is_burner(energy_source) then
if energy_source.fuel_categories then
return energy_source.fuel_categories
end
if energy_source.fuel_category then
return {energy_source.fuel_category}
end
return ({"chemical"})
end
return {}
end
is_burner = function(energy_source)
energy_source = table_or_bust(energy_source)
if not energy_source then return false end
if energy_source.type == "burner"
or not energy_source.type then
return true
end
return false
end
get_energy_source = function(entity)
entity = table_or_bust(entity)
if not entity then return nil end
if entity.burner then
return entity.burner
else
return entity.energy_source
end
end
table_or_bust = function(prototype)
if type(prototype) == "table" then
return prototype
end
return nil
end
string_or_bust = function(str)
if type(str) == "string" then
return str
end
return nil
end
io_prototype_or_bust = function(prototype,count,prob)
local prototype = construct_io_prototype(prototype,count,prob)
if type(prototype.name) == "string"
and type(prototype.type) == "string"
and type(prototype.amount) == "number" then
return prototype
end
return nil
end
construct_io_prototype = function(prototype,count,prob)
local new_prototype = {}
if type(count) ~= "number" then count = nil end
if type(prob) ~= "number" then prob = nil end
if type(prototype) == "table" then
new_prototype.name = prototype.name or prototype[1]
new_prototype.type = prototype.type or "item"
new_prototype.amount =
count or prototype.amount
or prototype[2] or 1
new_prototype.probability =
prob or prototype.probability
end
if type(prototype) == "string" then
if data.raw.fluid[prototype] then
new_prototype.name = prototype
new_prototype.type = "fluid"
new_prototype.amount = count or 1
if data.raw.item[prototype] then
new_prototype.type = "item"
new_prototype.probability = prob
end
else
new_prototype.name = prototype
new_prototype.type = "item"
new_prototype.amount = count or 1
new_prototype.probability = prob
end
end
if new_prototype.type == "item" then
if new_prototype.amount < 1 then
new_prototype.amount = 1
new_prototype.probability = new_prototype.amount
end
else
if prob then
new_prototype.amount = new_prototype.amount*prob
end
end
return new_prototype
end
recipe_or_bust = function(prototype)
if type(prototype) == "table"
and prototype.type == "recipe" then
return prototype
end
if type(recipe) == "string" then
return data.raw.recipe[recipe]
end
return nil
end
string_name_or_bust = function(prototype_name)
if type(prototype_name) == "string" then
return prototype_name
end
if type(prototype_name) == "table" then
return prototype_name.name
end
return nil
end
add_strings_to_list = function(new_strings,str_list)
if type(new_strings) ~= "table" then
if type(str_list) == "table" then
return str_list
else
return {}
end
end
for _,str in pairs(new_strings) do
add_string_to_list(str,str_list)
end
if type(str_list) == "table" then
return str_list
else
return {}
end
end
add_string_to_list = function(new_str,str_list)
if type(str_list) ~= "table" then
if type(new_str) == "string" then
return {new_str}
else
return {}
end
end
for _,str in pairs(str_list) do
if str == new_str then
return str_list
end
end
if type(new_str) == "string" then
table.insert(str_list,new_str)
end
return str_list
end
table_incl = function(val,comp)
comp = table_or_bust(comp)
if not val or not comp then return false end
for _,val_comp in pairs(comp) do
if val_comp == val then
return true
end
end
return false
end
-- Reasonable efficiencies.
-- Temps determined to maintain blueprint compatibility.
-- Applied by my physics mod.
boiler_eff = 0.85
gen_eff = 0.5
furnace_eff = 0.65
reactor_eff = 0.80
chem_temp_max = 315
nuke_temp_max = 990
reactor_consump_multi = 2.01
chem_fuel_quotient = boiler_eff*gen_eff
nuke_fuel_quotient = reactor_eff*gen_eff
solar_power_output = "5.1kW"
Code: Select all
require("factsheet")
local energy_normal = 50
--local mintime = energy_normal/25
local use_ore_stack_size = settings.startup["ore"].value
local productivity_recipes = {}
for _,recipe in pairs(data.raw.recipe) do
if recipe.category == "smelting" then
local result_name,orig_result_count,exp_result_count =
get_main_result(recipe)
local product = data.raw.item[result_name]
if product and type(product) == "table"
and has_ingredients(recipe) then
local stack_size = product.stack_size
local input_name,orig_input_count,exp_input_count =
get_ingredient(recipe,1)
local io_multiplier = stack_size/orig_result_count
if use_ore_stack_size then
local ore = data.raw.item[input_name]
if ore then
stack_size = ore.stack_size
io_multiplier = stack_size/orig_input_count
end
end
local energy_multiplier = io_multiplier/energy_normal
local orig_energy = get_recipe_energy(recipe)
--if (orig_energy*energy_multiplier) < mintime then
-- local emult_min = mintime/orig_energy
-- io_multiplier = io_multiplier
-- /energy_multiplier*emult_min
-- energy_multiplier = emult_min
--end
local f,r = math.modf(orig_result_count*io_multiplier)
if r > 0 then
io_multiplier = math.ceil(io_multiplier/r)
energy_multiplier = energy_multiplier/r
end
local stackrecipe = util.table.deepcopy(recipe)
stackrecipe.hidden = false
--stackrecipe.hide_from_player_crafting = true
stackrecipe.category = "stack-smelting"
stackrecipe.name = stackrecipe.name.."-stack"
mult_recipe_energy(stackrecipe,energy_multiplier)
mult_recipe_io(stackrecipe,io_multiplier)
mirror_recipe_in_techs(recipe,stackrecipe)
data:extend({stackrecipe})
if is_productivity_recipe(recipe) then
table.insert(productivity_recipes,stackrecipe)
end
end
end
end
set_productivity_recipes(productivity_recipes)