Update to 2.0

This commit is contained in:
Simon Brodtmann 2025-10-04 21:42:12 +02:00
parent 98ea14df52
commit c2b65301fb
21 changed files with 349 additions and 665 deletions

View file

@ -64,17 +64,7 @@ function util.fe_plus(sub)
end
end
function util.get_stack_size(default)
if mods.Krastorio2 then
local size = get_setting("kr-stack-size")
if size and tonumber(size) then
return tonumber(size)
end
end
return default
end
function util.k2assets()
function util.k2assets()
if mods["Krastorio2Assets"] then
return "__Krastorio2Assets__"
end
@ -111,8 +101,8 @@ function util.se_landfill(params)
category = "hard-recycling",
order = "z-b-"..params.ore,
subgroup = "terrain",
result = "landfill",
ingredients = {{params.ore, 50}},
results = {{type="item", name="landfill", amount=1}},
ingredients = {{type="item", name=params.ore, amount=50}},
}
})
util.add_unlock("se-recycling-facility", lname)
@ -123,7 +113,7 @@ end
-- k2 matter
-- params: {k2matter}, k2baseicon , {icon}
function util.k2matter(params)
local matter = require("__Krastorio2__/lib/public/data-stages/matter-util")
local matter = require("__Krastorio2__/prototypes/libraries/matter")
if mods["space-exploration"] then
params.k2matter.need_stabilizer = true
end
@ -169,15 +159,15 @@ function util.k2matter(params)
{
{"production-science-pack", 1},
{"utility-science-pack", 1},
{"matter-tech-card", 1}
{"kr-matter-tech-card", 1}
},
time = 45,
},
-- (ignore for now) localised_name = {"technology-name.k2-conversion", {"item-name."..params.k2matter.item_name}},
localised_name = {"technology-name.k2-conversion", {"item-name."..params.k2matter.item_name}},
},
})
end
matter.createMatterRecipe(params.k2matter)
matter.make_recipes(params.k2matter)
end
@ -211,16 +201,16 @@ function util.se_matter(params)
energy_required = params.energy_required,
enabled = false,
ingredients = {
{sedata, 1},
{type="item", name=sedata, amount=1},
{type="fluid", name="se-particle-stream", amount=50},
{type="fluid", name="se-space-coolant-supercooled", amount=25},
},
results = {
{params.ore, params.quant_out},
{"se-contaminated-scrap", 1},
{type=item, name=sedata, amount=1, probability=.99},
{type=item, name=sejunk, amount=1, probability=.01},
{type="fluid", name="se-space-coolant-hot", amount=25, catalyst_amount=25},
{type="item", name=params.ore, amount=params.quant_out},
{type="item", name="se-contaminated-scrap", amount=1},
{type="item", name=sedata, amount=1, probability=.99},
{type="item", name=sejunk, amount=1, probability=.01},
{type="fluid", name="se-space-coolant-hot", amount=25, ignored_by_productivity=25},
}
}
})
@ -250,14 +240,14 @@ function util.se_matter(params)
energy_required = 30,
enabled = false,
ingredients = {
{"se-kr-matter-liberation-data", 1},
{params.ore, params.quant_in},
{type="item", name="se-kr-matter-liberation-data", amount=1},
{type="item", name=params.ore, amount=params.quant_in},
{type="fluid", name="se-particle-stream", amount=50},
},
results = {
{type=item, name="se-kr-matter-liberation-data", amount=1, probability=.99},
{type=item, name=sejunk, amount=1, probability=.01},
{type="fluid", name="se-particle-stream", amount=params.stream_out, catalyst_amount=50},
{type="item", name="se-kr-matter-liberation-data", amount=1, probability=.99},
{type="item", name=sejunk, amount=1, probability=.01},
{type="fluid", name="se-particle-stream", amount=params.stream_out, ignored_by_productivity=50},
}
}
})
@ -284,7 +274,7 @@ function util.se_matter(params)
{"se-astronomic-science-pack-4", 1},
{"se-energy-science-pack-4", 1},
{"se-material-science-pack-4", 1},
{"matter-tech-card", 1},
{"kr-matter-tech-card", 1},
{"se-deep-space-science-pack-1", 1},
}
@ -298,18 +288,6 @@ function util.se_matter(params)
end
end
-- Get the normal prototype for a recipe -- either .normal or the recipe itself
function util.get_normal(recipe_name)
if data.raw.recipe[recipe_name] then
recipe = data.raw.recipe[recipe_name]
if recipe.normal and recipe.normal.ingredients then
return recipe.normal
elseif recipe.ingredients then
return recipe
end
end
end
-- Set/override a technology's prerequisites
function util.set_prerequisite(technology_name, prerequisites)
local technology = data.raw.technology[technology_name]
@ -376,7 +354,7 @@ function util.add_unlock(technology_name, recipe)
end
-- Check if a tech unlocks a recipe
function util.check_unlock(technology_name, recipe_name)
function util.check_unlock(technology_name, recipe)
local technology = data.raw.technology[technology_name]
if technology and technology.effects then
for i, effect in pairs(technology.effects) do
@ -421,17 +399,13 @@ end
function util.set_enabled(recipe_name, enabled)
if data.raw.recipe[recipe_name] then
if data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].normal.enabled = enabled end
if data.raw.recipe[recipe_name].expensive then data.raw.recipe[recipe_name].expensive.enabled = enabled end
if not data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].enabled = enabled end
data.raw.recipe[recipe_name].enabled = enabled
end
end
function util.set_hidden(recipe_name)
if data.raw.recipe[recipe_name] then
if data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].normal.hidden = true end
if data.raw.recipe[recipe_name].expensive then data.raw.recipe[recipe_name].expensive.hidden = true end
if not data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].hidden = true end
data.raw.recipe[recipe_name].hidden = true
end
end
@ -441,8 +415,6 @@ function util.add_or_add_to_ingredient(recipe_name, ingredient, quantity, option
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
me.add_modified(recipe_name)
add_or_add_to_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
add_or_add_to_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
add_or_add_to_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity)
end
end
@ -465,8 +437,6 @@ function util.add_ingredient(recipe_name, ingredient, quantity, options)
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient] or is_fluid) then
me.add_modified(recipe_name)
add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity, is_fluid)
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity, is_fluid)
add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity, is_fluid)
end
end
@ -480,7 +450,7 @@ function add_ingredient(recipe, ingredient, quantity, is_fluid)
if is_fluid then
table.insert(recipe.ingredients, {type="fluid", name=ingredient, amount=quantity})
else
table.insert(recipe.ingredients, {ingredient, quantity})
table.insert(recipe.ingredients, {type="item", name=ingredient, amount=quantity})
end
end
end
@ -491,8 +461,6 @@ function util.add_ingredient_raw(recipe_name, ingredient, options)
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient.name] or data.raw.item[ingredient[1]]) then
me.add_modified(recipe_name)
add_ingredient_raw(data.raw.recipe[recipe_name], ingredient)
add_ingredient_raw(data.raw.recipe[recipe_name].normal, ingredient)
add_ingredient_raw(data.raw.recipe[recipe_name].expensive, ingredient)
end
end
@ -516,8 +484,6 @@ function util.set_ingredient(recipe_name, ingredient, quantity, options)
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
me.add_modified(recipe_name)
set_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
set_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
set_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity)
end
end
@ -541,29 +507,18 @@ end
-- Only works for recipes with multiple products
function util.add_product(recipe_name, product, options)
if not should_force(options) and bypass(recipe_name) then return end
if data.raw.recipe[recipe_name] and
(data.raw.item[product[1]] or data.raw.item[product.name] or
data.raw.fluid[product[1]] or data.raw.fluid[product.name]
) then
if data.raw.recipe[recipe_name] and
(data.raw.item[product.name] or data.raw.fluid[product.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 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 recipe.results == nil then
recipe.results = {{recipe.result, recipe.result_count and recipe.result_count or 1}}
end
recipe.result = nil
recipe.result_count = nil
table.insert(recipe.results, product)
if recipe.results == nil then
recipe.results = {}
end
end
table.insert(recipe.results, product)
end
end
@ -571,18 +526,13 @@ end
function util.get_ingredient_amount(recipe_name, ingredient_name)
local recipe = data.raw.recipe[recipe_name]
if recipe then
if recipe.normal and recipe.normal.ingredients then
for i, ingredient in pairs(recipe.normal.ingredients) do
if ingredient[1] == ingredient_name then return ingredient[2] end
if ingredient.name == ingredient_name then return ingredient.amount end
end
elseif recipe.ingredients then
if recipe.ingredients then
for i, ingredient in pairs(recipe.ingredients) do
if ingredient[1] == ingredient_name then return ingredient[2] end
if ingredient.name == ingredient_name then return ingredient.amount end
end
end
return 0
return 1
end
return 0
end
@ -592,14 +542,7 @@ function util.get_amount(recipe_name, product)
if not product then product = recipe_name end
local recipe = data.raw.recipe[recipe_name]
if recipe then
if recipe.normal and recipe.normal.results then
for i, result in pairs(recipe.normal.results) do
if result[1] == product then return result[2] end
if result.name == product then return result.amount end
end
elseif recipe.normal and recipe.normal.result_count then
return recipe.normal.result_count
elseif recipe.results then
if recipe.results then
for i, result in pairs(recipe.results) do
if result[1] == product then return result[2] end
if result.name == product then return result.amount end
@ -617,9 +560,7 @@ function util.get_result_count(recipe_name, product)
if not product then product = recipe_name end
local recipe = data.raw.recipe[recipe_name]
if recipe then
if recipe.normal and recipe.normal.results then
return #(recipe.normal.results)
elseif recipe.results then
if recipe.results then
return #(recipe.results)
end
return 1
@ -634,8 +575,6 @@ function util.replace_ingredient(recipe_name, old, new, amount, multiply, option
if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) then
me.add_modified(recipe_name)
replace_ingredient(data.raw.recipe[recipe_name], old, new, amount, multiply)
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new, amount, multiply)
replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new, amount, multiply)
end
end
@ -677,8 +616,6 @@ function util.remove_ingredient(recipe_name, old, options)
if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
remove_ingredient(data.raw.recipe[recipe_name], old)
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
remove_ingredient(data.raw.recipe[recipe_name].expensive, old)
end
end
@ -704,28 +641,23 @@ function util.replace_some_product(recipe_name, old, old_amount, new, new_amount
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)
function replace_some_product(recipe, old, old_amount, new, new_amount, is_fluid)
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
if existing.name == new then
return
end
end
end
add_product(recipe, {new, new_amount})
add_product(recipe, {type=is_fluid and "fluid" or "item", name=new, amount=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
@ -738,8 +670,6 @@ function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amo
if data.raw.recipe[recipe_name] and (data.raw.item[new] or is_fluid) then
me.add_modified(recipe_name)
replace_some_ingredient(data.raw.recipe[recipe_name], old, old_amount, new, new_amount, is_fluid)
replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount, is_fluid)
replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount, is_fluid)
end
end
@ -768,8 +698,6 @@ function util.set_product_amount(recipe_name, product, amount, options)
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
set_product_amount(data.raw.recipe[recipe_name], product, amount)
set_product_amount(data.raw.recipe[recipe_name].normal, product, amount)
set_product_amount(data.raw.recipe[recipe_name].expensive, product, amount)
end
end
@ -808,8 +736,6 @@ function util.multiply_recipe(recipe_name, multiple, options)
me.add_modified(recipe_name)
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
@ -817,8 +743,6 @@ function multiply_recipe(recipe, multiple)
if recipe then
if recipe.energy_required then
recipe.energy_required = recipe.energy_required * multiple
else
recipe.energy_required = 0.5 * multiple -- 0.5 is factorio default
end
if recipe.result_count then
recipe.result_count = recipe.result_count * multiple
@ -833,8 +757,8 @@ function multiply_recipe(recipe, multiple)
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
if result.ignored_by_productivity then
result.ignored_by_productivity = result.ignored_by_productivity * multiple
end
end
if result[1] then
@ -861,9 +785,8 @@ end
-- Returns true if a recipe has an ingredient
function util.has_ingredient(recipe_name, ingredient)
return data.raw.recipe[recipe_name] and (
has_ingredient(data.raw.recipe[recipe_name], ingredient) or
has_ingredient(data.raw.recipe[recipe_name].normal, ingredient))
return data.raw.recipe[recipe_name] and
has_ingredient(data.raw.recipe[recipe_name], ingredient)
end
function has_ingredient(recipe, ingredient)
@ -883,8 +806,6 @@ function util.remove_product(recipe_name, old, options)
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
remove_product(data.raw.recipe[recipe_name], old)
remove_product(data.raw.recipe[recipe_name].normal, old)
remove_product(data.raw.recipe[recipe_name].expensive, old)
end
end
@ -907,8 +828,6 @@ function util.set_main_product(recipe_name, product, options)
if not should_force(options) and bypass(recipe_name) then return end
if data.raw.recipe[recipe_name] then
set_main_product(data.raw.recipe[recipe_name], product)
set_main_product(data.raw.recipe[recipe_name].normal, product)
set_main_product(data.raw.recipe[recipe_name].expensive, product)
end
end
@ -922,13 +841,11 @@ end
function util.replace_product(recipe_name, old, new, options)
if not should_force(options) and bypass(recipe_name) then return end
if data.raw.recipe[recipe_name] then
replace_product(data.raw.recipe[recipe_name], old, new, options)
replace_product(data.raw.recipe[recipe_name].normal, old, new, options)
replace_product(data.raw.recipe[recipe_name].expensive, old, new, options)
replace_product(data.raw.recipe[recipe_name], old, new)
end
end
function replace_product(recipe, old, new, options)
function replace_product(recipe, old, new)
if recipe then
if recipe.main_product == old then
recipe.main_product = new
@ -968,8 +885,6 @@ function util.set_recipe_time(recipe_name, time, options)
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
set_recipe_time(data.raw.recipe[recipe_name], time)
set_recipe_time(data.raw.recipe[recipe_name].normal, time)
set_recipe_time(data.raw.recipe[recipe_name].expensive, time)
end
end
@ -987,8 +902,6 @@ function util.multiply_time(recipe_name, factor, options)
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
multiply_time(data.raw.recipe[recipe_name], factor)
multiply_time(data.raw.recipe[recipe_name].normal, factor)
multiply_time(data.raw.recipe[recipe_name].expensive, factor)
end
end
@ -1006,8 +919,6 @@ function util.add_time(recipe_name, amount, options)
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then
add_time(data.raw.recipe[recipe_name], amount)
add_time(data.raw.recipe[recipe_name].normal, amount)
add_time(data.raw.recipe[recipe_name].expensive, amount)
end
end
@ -1031,7 +942,7 @@ end
-- Set recipe subgroup
function util.set_subgroup(recipe_name, subgroup, options)
if not should_force(options) and bypass(recipe_name) then return end
if data.raw.recipe[recipe_name] and data.raw["item-subgroup"][subgroup] then
if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
data.raw.recipe[recipe_name].subgroup = subgroup
end
@ -1050,34 +961,16 @@ function util.add_icon(recipe_name, icon, options)
if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
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 = {{
icon=data.raw.recipe[recipe_name].icon,
icon_size=data.raw.recipe[recipe_name].icon_size,
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_size = nil
data.raw.recipe[recipe_name].icons = {}
if data.raw.recipe[recipe_name].icon then
data.raw.recipe[recipe_name].icons = {{
icon=data.raw.recipe[recipe_name].icon,
icon_size=data.raw.recipe[recipe_name].icon_size,
icon_mipmaps=data.raw.recipe[recipe_name].icon_mipmaps,
}}
data.raw.recipe[recipe_name].icon = nil
data.raw.recipe[recipe_name].icon_size = nil
end
end
table.insert(data.raw.recipe[recipe_name].icons, icon)
end
@ -1137,8 +1030,6 @@ function util.add_to_ingredient(recipe, ingredient, amount, options)
if not should_force(options) and bypass(recipe_name) then return end
if data.raw.recipe[recipe] then
add_to_ingredient(data.raw.recipe[recipe], ingredient, amount)
add_to_ingredient(data.raw.recipe[recipe].normal, ingredient, amount)
add_to_ingredient(data.raw.recipe[recipe].expensive, ingredient, amount)
end
end
@ -1161,8 +1052,6 @@ function util.add_to_product(recipe_name, product, amount, options)
if not should_force(options) and bypass(recipe_name) then return end
if data.raw.recipe[recipe_name] then
add_to_product(data.raw.recipe[recipe_name], product, amount)
add_to_product(data.raw.recipe[recipe_name].normal, product, amount)
add_to_product(data.raw.recipe[recipe_name].expensive, product, amount)
end
end
@ -1285,10 +1174,8 @@ function remove_prior_unlocks(tech, recipe)
util.remove_recipe_effect(tech, recipe)
if technology.prerequisites then
for i, prerequisite in pairs(technology.prerequisites) do
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)
end
-- log("BZZZ removing prior unlocks for " .. tech ..", checking " .. prerequisite) -- Handy Debug :|
remove_prior_unlocks(prerequisite, recipe)
end
end
end
@ -1330,9 +1217,7 @@ function replace_ingredients_prior_to(tech, old, new, multiplier)
if technology.prerequisites then
for i, prerequisite in pairs(technology.prerequisites) do
-- log("BZZZ checking " .. prerequisite) -- Handy Debug :|
if string.sub(prerequisite, 1, 3) ~= 'ei_' then
replace_ingredients_prior_to(prerequisite, old, new, multiplier)
end
replace_ingredients_prior_to(prerequisite, old, new, multiplier)
end
end
end