fixes, refactor
This commit is contained in:
parent
d4a8b748f4
commit
dd5770a2e6
11 changed files with 117 additions and 62 deletions
|
|
@ -1,4 +1,17 @@
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
|
Version: 0.0.5
|
||||||
|
Date: 2021-07-21
|
||||||
|
Changes:
|
||||||
|
- Minor refactor
|
||||||
|
---------------------------------------------------------------------------------------------------
|
||||||
|
Version: 0.0.4
|
||||||
|
Date: 2021-07-21
|
||||||
|
Changes:
|
||||||
|
- Both foundry items are more expensive
|
||||||
|
- Both foundry entities use more energy: burner doubled, electric quadrupled
|
||||||
|
Features:
|
||||||
|
- Setting to enable other "assembling machine" entities to do foundry tasks.
|
||||||
|
---------------------------------------------------------------------------------------------------
|
||||||
Version: 0.0.3
|
Version: 0.0.3
|
||||||
Date: 2021-07-19
|
Date: 2021-07-19
|
||||||
Features:
|
Features:
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,7 @@
|
||||||
|
local me = require("me")
|
||||||
local util = {}
|
local util = {}
|
||||||
|
|
||||||
util.name = "bzfoundry"
|
util.me = me
|
||||||
|
|
||||||
function util.smelt()
|
|
||||||
return util.get_setting("bzfoundry-smelt")
|
|
||||||
end
|
|
||||||
|
|
||||||
function util.carbon()
|
|
||||||
return util.get_setting("bzfoundry-hydrocarbon")
|
|
||||||
end
|
|
||||||
|
|
||||||
function util.carbonrecipe()
|
|
||||||
local carbon = util.carbon()
|
|
||||||
if carbon == "coke" then
|
|
||||||
return "coke"
|
|
||||||
elseif carbon == "solid-fuel" then
|
|
||||||
return "solid-fuel-from-coal"
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
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)
|
function util.get_stack_size(default)
|
||||||
if mods["Krastorio2"] then
|
if mods["Krastorio2"] then
|
||||||
|
|
@ -100,7 +68,7 @@ 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 me.bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] 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)
|
||||||
|
|
@ -138,7 +106,7 @@ end
|
||||||
|
|
||||||
-- Replace one ingredient with another in a recipe
|
-- 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 me.bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] and data.raw.item[new] then
|
if data.raw.recipe[recipe_name] and data.raw.item[new] 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)
|
||||||
|
|
@ -163,7 +131,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 me.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)
|
||||||
|
|
@ -189,7 +157,7 @@ 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 me.bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] and data.raw.item[new] then
|
if data.raw.recipe[recipe_name] and data.raw.item[new] 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)
|
||||||
|
|
@ -206,11 +174,9 @@ function replace_some_ingredient(recipe, old, old_amount, new, new_amount)
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
@ -221,7 +187,7 @@ 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 me.bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] then
|
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)
|
||||||
|
|
@ -275,17 +241,19 @@ end
|
||||||
|
|
||||||
-- Remove an element of type t and name from data.raw
|
-- Remove an element of type t and name from data.raw
|
||||||
function util.remove_raw(t, name)
|
function util.remove_raw(t, name)
|
||||||
for i, elem in pairs(data.raw[t]) do
|
if data.raw[t][name] then
|
||||||
if elem.name == name then
|
for i, elem in pairs(data.raw[t]) do
|
||||||
data.raw[t][i] = nil
|
if elem.name == name then
|
||||||
break
|
data.raw[t][i] = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Multiply energy required
|
-- Multiply energy required
|
||||||
function util.multiply_time(recipe, factor)
|
function util.multiply_time(recipe, factor)
|
||||||
if bypass[recipe_name] then return end
|
if me.bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe_name] then
|
if data.raw.recipe[recipe_name] then
|
||||||
multiply_time(data.raw.recipe[recipe_name], factor)
|
multiply_time(data.raw.recipe[recipe_name], factor)
|
||||||
multiply_time(data.raw.recipe[recipe_name].normal, factor)
|
multiply_time(data.raw.recipe[recipe_name].normal, factor)
|
||||||
|
|
@ -303,15 +271,15 @@ end
|
||||||
|
|
||||||
-- Set recipe category
|
-- Set recipe category
|
||||||
function util.set_category(recipe, category)
|
function util.set_category(recipe, category)
|
||||||
if bypass[recipe_name] then return end
|
if me.bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe] then
|
if data.raw.recipe[recipe] then
|
||||||
data.raw.recipe[recipe].category = category
|
data.raw.recipe[recipe].category = category
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set recipe category
|
-- Set recipe subgroup
|
||||||
function util.set_subgroup(recipe, subgroup)
|
function util.set_subgroup(recipe, subgroup)
|
||||||
if bypass[recipe_name] then return end
|
if me.bypass[recipe_name] then return end
|
||||||
if data.raw.recipe[recipe] then
|
if data.raw.recipe[recipe] then
|
||||||
data.raw.recipe[recipe].subgroup = subgroup
|
data.raw.recipe[recipe].subgroup = subgroup
|
||||||
end
|
end
|
||||||
|
|
@ -322,4 +290,17 @@ function util.set_to_founding(recipe)
|
||||||
util.set_subgroup(recipe, "foundry-intermediate")
|
util.set_subgroup(recipe, "foundry-intermediate")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Addc crafting category to an entity
|
||||||
|
function util.add_crafting_category(entity_type, entity, category)
|
||||||
|
if data.raw[entity_type][entity] then
|
||||||
|
for i, existing in pairs(data.raw[entity_type][entity].crafting_categories) do
|
||||||
|
if existing == category then
|
||||||
|
log(entity.." not adding "..new.." -- duplicate")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(data.raw[entity_type][entity].crafting_categories, category)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return util
|
return util
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,20 @@
|
||||||
local util = require("data-util")
|
local util = require("data-util")
|
||||||
|
|
||||||
util.set_to_founding("steel-plate")
|
util.set_to_founding("steel-plate")
|
||||||
util.replace_some_ingredient("steel-plate", "iron-plate", 1, util.carbon(), 1)
|
util.replace_some_ingredient("steel-plate", "iron-plate", 1, util.me.carbon(), 1)
|
||||||
util.multiply_time("stee-plate", 4/5)
|
util.multiply_time("stee-plate", 4/5)
|
||||||
util.add_prerequisite("steel-processing", "foundry")
|
util.add_prerequisite("steel-processing", "foundry")
|
||||||
|
|
||||||
util.set_to_founding("tungsten-carbide")
|
util.set_to_founding("tungsten-carbide")
|
||||||
util.add_ingredient("tungsten-carbide", util.carbon(), 1)
|
util.add_ingredient("tungsten-carbide", util.me.carbon(), 1)
|
||||||
|
|
||||||
util.set_to_founding("silicon")
|
util.set_to_founding("silicon")
|
||||||
util.add_ingredient("silicon", util.carbon(), 1)
|
util.add_ingredient("silicon", util.me.carbon(), 1)
|
||||||
|
|
||||||
util.set_to_founding("cermet")
|
util.set_to_founding("cermet")
|
||||||
|
|
||||||
|
-- K2
|
||||||
|
for i, machine in pairs(util.me.get_other_machines()) do
|
||||||
|
log("BZAdding "..machine)
|
||||||
|
util.add_crafting_category("assembling-machine", machine, "founding")
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bzfoundry",
|
"name": "bzfoundry",
|
||||||
"version": "0.0.3",
|
"version": "0.0.5",
|
||||||
"factorio_version": "1.1",
|
"factorio_version": "1.1",
|
||||||
"title": "Foundry",
|
"title": "Foundry",
|
||||||
"author": "Brevven",
|
"author": "Brevven",
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,10 @@ foundry=Use heat for founding, coking, etc.
|
||||||
bzfoundry-recipe-bypass=Bypass recipes
|
bzfoundry-recipe-bypass=Bypass recipes
|
||||||
bzfoundry-smelt=Foundry can smelt
|
bzfoundry-smelt=Foundry can smelt
|
||||||
bzfoundry-hydrocarbon=Hydrocarbon for founding
|
bzfoundry-hydrocarbon=Hydrocarbon for founding
|
||||||
|
bzfoundry-other-machines=Other machines that can do founding
|
||||||
|
|
||||||
[mod-setting-description]
|
[mod-setting-description]
|
||||||
bzfoundry-recipe-bypass=Skip modifying these recipes (comma-separated list).
|
bzfoundry-recipe-bypass=Skip modifying these recipes (comma-separated list).
|
||||||
bzfoundry-smelt=If true, the foundry building can also handle raw ore smelting.
|
bzfoundry-smelt=If true, the foundry building can also handle raw ore smelting.
|
||||||
bzfoundry-hydrocarbon=Which hydrocarbon to use for founding. The foundry building is also used for coking.\nIf [color=cyan]coke[/color], a coke item and recipe is added, if needed.\nIf [color=cyan]solid fuel[/color], an early but inefficient recipe is added.\nIf [color=cyan]coal[/color], that is used.\nIf [color=cyan]none[/color] no hydrocarbon is used in founding (not recommended).
|
bzfoundry-hydrocarbon=Which hydrocarbon to use for founding. The foundry building is also used for coking.\nIf [color=cyan]coke[/color], a coke item and recipe is added, if needed.\nIf [color=cyan]solid fuel[/color], an early but inefficient recipe is added.\nIf [color=cyan]coal[/color], that is used.\nIf [color=cyan]none[/color], no hydrocarbon is used in founding (not recommended).
|
||||||
|
bzfoundry-other-machines=List of other "assembling-machine" entities that can do "founding" recipes. Eg. Krastorio2's "kr-advanced-furnace", or AAII's "industrial-furnace" (comma-separated list).
|
||||||
|
|
|
||||||
47
me.lua
Normal file
47
me.lua
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
local me = {}
|
||||||
|
|
||||||
|
me.name = "bzfoundry"
|
||||||
|
|
||||||
|
function me.smelt()
|
||||||
|
return me.get_setting("bzfoundry-smelt")
|
||||||
|
end
|
||||||
|
|
||||||
|
function me.carbon()
|
||||||
|
return me.get_setting("bzfoundry-hydrocarbon")
|
||||||
|
end
|
||||||
|
|
||||||
|
function me.carbonrecipe()
|
||||||
|
local carbon = me.carbon()
|
||||||
|
if carbon == "coke" then
|
||||||
|
return "coke"
|
||||||
|
elseif carbon == "solid-fuel" then
|
||||||
|
return "solid-fuel-from-coal"
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function me.get_other_machines()
|
||||||
|
local machines = {}
|
||||||
|
if me.get_setting(me.name.."-other-machines") then
|
||||||
|
for machine in string.gmatch(me.get_setting(me.name.."-other-machines"), '[^",%s]+') do
|
||||||
|
table.insert(machines, machine)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return machines
|
||||||
|
end
|
||||||
|
|
||||||
|
function me.get_setting(name)
|
||||||
|
if settings.startup[name] == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return settings.startup[name].value
|
||||||
|
end
|
||||||
|
|
||||||
|
me.bypass = {}
|
||||||
|
if me.get_setting(me.name.."-recipe-bypass") then
|
||||||
|
for recipe in string.gmatch(me.get_setting(me.name.."-recipe-bypass"), '[^",%s]+') do
|
||||||
|
me.bypass[recipe] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return me
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
local util = require("data-util")
|
local util = require("data-util")
|
||||||
|
|
||||||
|
if util.me.carbon() == "coke" and not data.raw.item["coke"] then
|
||||||
if util.carbon() == "coke" and not data.raw.item["coke"] then
|
|
||||||
data:extend({
|
data:extend({
|
||||||
{
|
{
|
||||||
type = "item",
|
type = "item",
|
||||||
|
|
@ -32,7 +31,7 @@ data:extend({
|
||||||
enabled=false,
|
enabled=false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
elseif util.carbon() == "solid-fuel" then
|
elseif util.me.carbon() == "solid-fuel" then
|
||||||
data:extend({
|
data:extend({
|
||||||
{
|
{
|
||||||
type = "recipe",
|
type = "recipe",
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,9 @@ data:extend({
|
||||||
},
|
},
|
||||||
collision_box = {{-1.7, -1.7}, {1.7, 1.7}},
|
collision_box = {{-1.7, -1.7}, {1.7, 1.7}},
|
||||||
selection_box = {{-2, -2}, {2, 2}},
|
selection_box = {{-2, -2}, {2, 2}},
|
||||||
crafting_categories = {"founding", futil.smelt() and "smelting" or nil},
|
crafting_categories = {"founding", futil.me.smelt() and "smelting" or nil},
|
||||||
energy_usage = "90kW",
|
energy_usage = "360kW",
|
||||||
|
drain = "12kW",
|
||||||
crafting_speed = 4,
|
crafting_speed = 4,
|
||||||
energy_source =
|
energy_source =
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ data:extend({
|
||||||
},
|
},
|
||||||
collision_box = {{-1.7, -1.7}, {1.7, 1.7}},
|
collision_box = {{-1.7, -1.7}, {1.7, 1.7}},
|
||||||
selection_box = {{-2, -2}, {2, 2}},
|
selection_box = {{-2, -2}, {2, 2}},
|
||||||
crafting_categories = {"founding", futil.smelt() and "smelting" or nil},
|
crafting_categories = {"founding", futil.me.smelt() and "smelting" or nil},
|
||||||
energy_usage = "90kW",
|
energy_usage = "180kW",
|
||||||
crafting_speed = 4,
|
crafting_speed = 4,
|
||||||
energy_source =
|
energy_source =
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ data:extend({
|
||||||
prerequisites = {"automation"},
|
prerequisites = {"automation"},
|
||||||
effects = {
|
effects = {
|
||||||
{type = "unlock-recipe", recipe = "foundry"},
|
{type = "unlock-recipe", recipe = "foundry"},
|
||||||
util.carbonrecipe() and {type = "unlock-recipe", recipe = util.carbonrecipe()},
|
util.me.carbonrecipe() and {type = "unlock-recipe", recipe = util.me.carbonrecipe()},
|
||||||
},
|
},
|
||||||
unit = {
|
unit = {
|
||||||
count = 25,
|
count = 25,
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,10 @@ data:extend({
|
||||||
setting_type = "startup",
|
setting_type = "startup",
|
||||||
default_value = false,
|
default_value = false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type = "string-setting",
|
||||||
|
name = "bzfoundry-other-machines",
|
||||||
|
setting_type = "startup",
|
||||||
|
default_value = "kr-advanced-furnace",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue