This commit is contained in:
Brevven 2023-05-15 22:08:49 -07:00
parent 7c766d2ab4
commit a1527c9924
3 changed files with 171 additions and 24 deletions

View file

@ -20,4 +20,10 @@ function util.get_list()
end end
end end
function util.force_enable_recipe(event, recipe_name)
if game.players[event.player_index].force.recipes[recipe_name] then
game.players[event.player_index].force.recipes[recipe_name].enabled=true
end
end
return util return util

View file

@ -65,9 +65,11 @@ function util.fe_plus(sub)
end end
function util.get_stack_size(default) function util.get_stack_size(default)
if mods["Krastorio2"] then if mods.Krastorio2 then
size = tonumber(krastorio.general.getSafeSettingValue("kr-stack-size")) local size = get_setting("kr-stack-size")
return size or default if size and tonumber(size) then
return tonumber(size)
end
end end
return default return default
end end
@ -117,6 +119,68 @@ function util.se_landfill(params)
end end
end end
-- k2 matter
-- params: {k2matter}, k2baseicon , {icon}
function util.k2matter(params)
local matter = require("__Krastorio2__/lib/public/data-stages/matter-util")
if mods["space-exploration"] then
params.k2matter.need_stabilizer = true
end
if not params.k2matter.minimum_conversion_quantity then
params.k2matter.minimum_conversion_quantity = 10
end
if not data.raw.technology[params.k2matter.unlocked_by_technology] then
local icon = ""
if params.k2baseicon then
icon = util.k2assets().."/technologies/matter-"..params.k2baseicon..".png"
else
icon = util.k2assets().."/technologies/backgrounds/matter.png"
end
data:extend(
{
{
type = "technology",
name = params.k2matter.unlocked_by_technology,
icons =
{
{
icon = icon,
icon_size = 256,
},
params.icon,
},
prerequisites = {"kr-matter-processing"},
unit =
{
count = 350,
ingredients = mods["space-exploration"] and
{
{"automation-science-pack", 1},
{"logistic-science-pack", 1},
{"chemical-science-pack", 1},
{"se-astronomic-science-pack-4", 1},
{"se-energy-science-pack-4", 1},
{"se-material-science-pack-4", 1},
{"se-deep-space-science-pack-2", 1},
{"se-kr-matter-science-pack-2", 1},
} or
{
{"production-science-pack", 1},
{"utility-science-pack", 1},
{"matter-tech-card", 1}
},
time = 45,
},
localised_name = {"technology-name.k2-conversion", {"item-name."..params.k2matter.item_name}},
},
})
end
matter.createMatterRecipe(params.k2matter)
end
-- se matter -- se matter
-- params: ore, energy_required, quant_out, quant_in, icon_size, stream_out -- params: ore, energy_required, quant_out, quant_in, icon_size, stream_out
function util.se_matter(params) function util.se_matter(params)
@ -312,7 +376,7 @@ function util.add_unlock(technology_name, recipe)
end end
-- Check if a tech unlocks a recipe -- Check if a tech unlocks a recipe
function util.check_unlock(technology_name, recipe) function util.check_unlock(technology_name, recipe_name)
local technology = data.raw.technology[technology_name] local technology = data.raw.technology[technology_name]
if technology and technology.effects then if technology and technology.effects then
for i, effect in pairs(technology.effects) do for i, effect in pairs(technology.effects) do
@ -489,6 +553,8 @@ end
function add_product(recipe, product) function add_product(recipe, product)
if recipe ~= nil then if recipe ~= nil then
if (product[1] and data.raw.item[product[1]]) or
(product.name and data.raw[product.type][product.name]) then
if not recipe.normal then if not recipe.normal then
if recipe.results == nil then if recipe.results == nil then
recipe.results = {{recipe.result, recipe.result_count and recipe.result_count or 1}} recipe.results = {{recipe.result, recipe.result_count and recipe.result_count or 1}}
@ -498,6 +564,7 @@ function add_product(recipe, product)
table.insert(recipe.results, product) table.insert(recipe.results, product)
end end
end end
end
end end
-- Get the amount of the ingredient, will check base/normal not expensive -- Get the amount of the ingredient, will check base/normal not expensive
@ -515,7 +582,7 @@ function util.get_ingredient_amount(recipe_name, ingredient_name)
if ingredient.name == ingredient_name then return ingredient.amount end if ingredient.name == ingredient_name then return ingredient.amount end
end end
end end
return 1 return 0
end end
return 0 return 0
end end
@ -630,6 +697,40 @@ function remove_ingredient(recipe, old)
end end
end end
-- Replace an amount of a product, leaving at least 1 of old
function util.replace_some_product(recipe_name, old, old_amount, new, new_amount, options)
if not should_force(options) and bypass(recipe_name) then return end
local is_fluid = not not data.raw.fluid[new] -- NOTE CURRENTLY UNUSUED
if data.raw.recipe[recipe_name] and (data.raw.item[new] or is_fluid) then
me.add_modified(recipe_name)
replace_some_product(data.raw.recipe[recipe_name], old, old_amount, new, new_amount, is_fluid)
replace_some_product(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount, is_fluid)
replace_some_product(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount, is_fluid)
end
end
function replace_some_product(recipe, old, old_amount, new, new_amount)
if recipe ~= nil then
if recipe.result == new then return end
if recipe.results then
for i, existing in pairs(recipe.results) do
if existing[1] == new or existing.name == new then
return
end
end
end
add_product(recipe, {new, new_amount})
for i, product in pairs(recipe.results) do
if product.name == old then
product.amount = math.max(1, product.amount - old_amount)
end
if product[1] == old then
product[2] = math.max(1, product[2] - old_amount)
end
end
end
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, options) function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amount, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
@ -716,6 +817,8 @@ function multiply_recipe(recipe, multiple)
if recipe then if recipe then
if recipe.energy_required then if recipe.energy_required then
recipe.energy_required = recipe.energy_required * multiple recipe.energy_required = recipe.energy_required * multiple
else
recipe.energy_required = 0.5 * multiple -- 0.5 is factorio default
end end
if recipe.result_count then if recipe.result_count then
recipe.result_count = recipe.result_count * multiple recipe.result_count = recipe.result_count * multiple
@ -819,13 +922,13 @@ end
function util.replace_product(recipe_name, old, new, options) function util.replace_product(recipe_name, old, new, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
replace_product(data.raw.recipe[recipe_name], old, new) replace_product(data.raw.recipe[recipe_name], old, new, options)
replace_product(data.raw.recipe[recipe_name].normal, old, new) replace_product(data.raw.recipe[recipe_name].normal, old, new, options)
replace_product(data.raw.recipe[recipe_name].expensive, old, new) replace_product(data.raw.recipe[recipe_name].expensive, old, new, options)
end end
end end
function replace_product(recipe, old, new) function replace_product(recipe, old, new, options)
if recipe then if recipe then
if recipe.main_product == old then if recipe.main_product == old then
recipe.main_product = new recipe.main_product = new
@ -928,7 +1031,7 @@ end
-- Set recipe subgroup -- Set recipe subgroup
function util.set_subgroup(recipe_name, subgroup, options) function util.set_subgroup(recipe_name, subgroup, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] and data.raw["item-subgroup"][subgroup] then
me.add_modified(recipe_name) me.add_modified(recipe_name)
data.raw.recipe[recipe_name].subgroup = subgroup data.raw.recipe[recipe_name].subgroup = subgroup
end end
@ -947,11 +1050,32 @@ function util.add_icon(recipe_name, icon, options)
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name) me.add_modified(recipe_name)
if not (data.raw.recipe[recipe_name].icons and #(data.raw.recipe[recipe_name].icons) > 0) then if not (data.raw.recipe[recipe_name].icons and #(data.raw.recipe[recipe_name].icons) > 0) then
if data.raw.recipe[recipe_name].icon then
data.raw.recipe[recipe_name].icons = {{ data.raw.recipe[recipe_name].icons = {{
icon=data.raw.recipe[recipe_name].icon, icon=data.raw.recipe[recipe_name].icon,
icon_size=data.raw.recipe[recipe_name].icon_size, icon_size=data.raw.recipe[recipe_name].icon_size,
icon_mipmaps=data.raw.recipe[recipe_name].icon_mipmaps, icon_mipmaps=data.raw.recipe[recipe_name].icon_mipmaps,
}} }}
elseif data.raw.item[data.raw.recipe[recipe_name].main_product] then
data.raw.recipe[recipe_name].icons = {{
icon=data.raw.item[data.raw.recipe[recipe_name].main_product].icon,
icon_size=data.raw.item[data.raw.recipe[recipe_name].main_product].icon_size,
icon_mipmaps=data.raw.item[data.raw.recipe[recipe_name].main_product].icon_mipmaps,
}}
elseif data.raw.item[data.raw.recipe[recipe_name].result] then
data.raw.recipe[recipe_name].icons = {{
icon=data.raw.item[data.raw.recipe[recipe_name].result].icon,
icon_size=data.raw.item[data.raw.recipe[recipe_name].result].icon_size,
icon_mipmaps=data.raw.item[data.raw.recipe[recipe_name].result].icon_mipmaps,
}}
elseif data.raw.recipe[recipe_name].normal and
data.raw.item[data.raw.recipe[recipe_name].normal.result] then
data.raw.recipe[recipe_name].icons = {{
icon=data.raw.item[data.raw.recipe[recipe_name].normal.result].icon,
icon_size=data.raw.item[data.raw.recipe[recipe_name].normal.result].icon_size,
icon_mipmaps=data.raw.item[data.raw.recipe[recipe_name].normal.result].icon_mipmaps,
}}
end
data.raw.recipe[recipe_name].icon = nil data.raw.recipe[recipe_name].icon = nil
data.raw.recipe[recipe_name].icon_size = nil data.raw.recipe[recipe_name].icon_size = nil
end end
@ -1161,11 +1285,13 @@ function remove_prior_unlocks(tech, recipe)
util.remove_recipe_effect(tech, recipe) util.remove_recipe_effect(tech, recipe)
if technology.prerequisites then if technology.prerequisites then
for i, prerequisite in pairs(technology.prerequisites) do for i, prerequisite in pairs(technology.prerequisites) do
-- log("BZZZ removing prior unlocks for " .. tech ..", checking " .. prerequisite) -- Handy Debug :| if string.sub(prerequisite, 1, 3) ~= 'ei_' then
-- log("BZZZ removing prior unlocks for " .. recipe .. " from " .. tech ..", checking " .. prerequisite) -- Handy Debug :|
remove_prior_unlocks(prerequisite, recipe) remove_prior_unlocks(prerequisite, recipe)
end end
end end
end end
end
end end
function util.replace_ingredients_prior_to(tech, old, new, multiplier) function util.replace_ingredients_prior_to(tech, old, new, multiplier)
@ -1204,10 +1330,12 @@ function replace_ingredients_prior_to(tech, old, new, multiplier)
if technology.prerequisites then if technology.prerequisites then
for i, prerequisite in pairs(technology.prerequisites) do for i, prerequisite in pairs(technology.prerequisites) do
-- log("BZZZ checking " .. prerequisite) -- Handy Debug :| -- log("BZZZ checking " .. prerequisite) -- Handy Debug :|
if string.sub(prerequisite, 1, 3) ~= 'ei_' then
replace_ingredients_prior_to(prerequisite, old, new, multiplier) replace_ingredients_prior_to(prerequisite, old, new, multiplier)
end end
end end
end end
end
end end
function util.remove_all_recipe_effects(recipe_name) function util.remove_all_recipe_effects(recipe_name)

13
settings-util.lua Normal file
View file

@ -0,0 +1,13 @@
-- WARNING WARNING WARNING
-- This file will be overwritten in mod zipfiles, edit bzlib/settings-util.lua
-- WARNING WARNING WARNING
local util = {}
function util.set_default_value(t, name, default)
if data.raw[t] and data.raw[t][name] then
data.raw[t][name].default_value = default
end
end
return util