data-util

This commit is contained in:
Simon Brodtmann 2025-10-11 00:50:35 +02:00
parent 11474b74dd
commit 6498ce9276
2 changed files with 18 additions and 28 deletions

View file

@ -56,16 +56,16 @@ function util.se_matter(params)
energy_required = params.energy_required, energy_required = params.energy_required,
enabled = false, enabled = false,
ingredients = { ingredients = {
{sedata, 1}, {type = "item", name = sedata, amount=1},
{type="fluid", name="se-particle-stream", amount=50}, {type="fluid", name="se-particle-stream", amount=50},
{type="fluid", name="se-space-coolant-supercooled", amount=25}, {type="fluid", name="se-space-coolant-supercooled", amount=25},
}, },
results = { results = {
{type = "item", name = params.ore, amount = params.quant_out}, {type = "item", name = params.ore, amount = params.quant_out},
{type="item", name="se-contaminated-scrap", amount=1}, {type="item", name="se-contaminated-scrap", amount=1},
{type=item, name=sedata, amount=1, probability=.99}, {type="item", name=sedata, amount=1, probability=.99},
{type=item, name=sejunk, amount=1, probability=.01}, {type="item", name=sejunk, amount=1, probability=.01},
{type="fluid", name="se-space-coolant-hot", amount=25, catalyst_amount=25}, {type="fluid", name="se-space-coolant-hot", amount=25, ignored_by_productivity = 25, ignored_by_stats = 25},
} }
} }
}) })
@ -100,9 +100,9 @@ function util.se_matter(params)
{type="fluid", name="se-particle-stream", amount=50}, {type="fluid", name="se-particle-stream", amount=50},
}, },
results = { results = {
{type=item, name="se-kr-matter-liberation-data", amount=1, probability=.99}, {type="item", name="se-kr-matter-liberation-data", amount=1, probability=.99},
{type=item, name=sejunk, amount=1, probability=.01}, {type="item", name=sejunk, amount=1, probability=.01},
{type="fluid", name="se-particle-stream", amount=params.stream_out, catalyst_amount=50}, {type="fluid", name="se-particle-stream", amount=params.stream_out, ignored_by_productivity = 50, ignored_by_stats = 50},
} }
} }
}) })
@ -309,10 +309,7 @@ end
function add_ingredient_raw(recipe, ingredient) function add_ingredient_raw(recipe, ingredient)
if recipe ~= nil and recipe.ingredients ~= nil then if recipe ~= nil and recipe.ingredients ~= nil then
for i, existing in pairs(recipe.ingredients) do for i, existing in pairs(recipe.ingredients) do
if ( if (existing.name and existing.name == ingredient.name) then
(existing[1] and (existing[1] == ingredient[1] or existing[1] == ingredient.name)) or
(existing.name and (existing.name == ingredient[1] or existing.name == ingredient.name))
) then
return return
end end
end end
@ -330,10 +327,7 @@ end
function set_ingredient(recipe, ingredient, quantity) function set_ingredient(recipe, ingredient, quantity)
if recipe ~= nil and recipe.ingredients ~= nil then if recipe ~= nil and recipe.ingredients ~= nil then
for i, existing in pairs(recipe.ingredients) do for i, existing in pairs(recipe.ingredients) do
if existing[1] == ingredient then if existing.name == ingredient then
existing[2] = quantity
return
elseif existing.name == ingredient then
existing.amount = quantity existing.amount = quantity
existing.amount_min = nil existing.amount_min = nil
existing.amount_max = nil existing.amount_max = nil
@ -343,22 +337,21 @@ function set_ingredient(recipe, ingredient, quantity)
table.insert(recipe.ingredients, {ingredient, quantity}) table.insert(recipe.ingredients, {ingredient, quantity})
end end
end end
-- Add a given quantity of product to a given recipe. -- Add a given quantity of product to a given recipe.
-- Only works for recipes with multiple products -- Only works for recipes with multiple products
function util.add_product(recipe_name, product) function util.add_product(recipe_name, product)
if data.raw.recipe[recipe_name] and if data.raw.recipe[recipe_name] and
(data.raw.item[product.name] or data.raw.fluid[product.name]) then (data.raw.item[product.name] or data.raw.fluid[product.name]) then
local is_fluid = data.raw.fluid[product.name] add_product(data.raw.recipe[recipe_name], product)
add_product(data.raw.recipe[recipe_name], product, is_fluid)
end end
end end
function add_product(recipe, product, is_fluid) function add_product(recipe, product)
if recipe ~= nil then if recipe ~= nil then
if recipe.results == nil then if recipe.results == nil then
recipe.results = {} recipe.results = {}
end end
table.insert(recipe.results, {type = is_fluid and "fluid" or "item", name = product.result, amount = product.result_count and product.result_count or 1}) table.insert(recipe.results, product)
end end
end end
@ -395,7 +388,7 @@ end
-- Use amount to set an amount. If that amount is a multiplier instead of an exact amount, set multiply true. -- Use amount to set an amount. If that amount is a multiplier instead of an exact amount, set multiply true.
function util.replace_ingredient(recipe_name, old, new, amount, multiply) function util.replace_ingredient(recipe_name, old, new, amount, multiply)
if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) then if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) then
replace_ingredient(data.raw.recipe[recipe_name], old, new, amount, multiply) replace_ingredient(data.raw.recipe[recipe_name], old, new, amount or 1, multiply)
end end
end end
@ -452,23 +445,20 @@ end
function replace_some_ingredient(recipe, old, old_amount, new, new_amount, is_fluid) function replace_some_ingredient(recipe, old, old_amount, new, new_amount, is_fluid)
if recipe ~= nil and recipe.ingredients ~= nil then if recipe ~= nil and recipe.ingredients ~= nil then
for i, existing in pairs(recipe.ingredients) do for i, existing in pairs(recipe.ingredients) do
if existing[1] == new or existing.name == new then if existing.name == new then
return return
end end
end end
for i, ingredient in pairs(recipe.ingredients) do for i, ingredient in pairs(recipe.ingredients) do
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
if ingredient[1] == old then
ingredient[2] = math.max(1, ingredient[2] - old_amount)
end end
end end
add_ingredient(recipe, new, new_amount, is_fluid) add_ingredient(recipe, new, new_amount, is_fluid)
end end
end end
-- set the amount of a product. -- set the amount of a product.
function util.set_product_amount(recipe_name, product, amount) function util.set_product_amount(recipe_name, product, amount)
if data.raw.recipe[recipe_name] then 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], product, amount)
@ -912,7 +902,7 @@ function util.add_unlock_force(technology_name, recipe)
util.add_unlock(technology_name, recipe) util.add_unlock(technology_name, recipe)
end end
-- sum the products of a recipe -- sum the products of a recipe
function util.sum_products(recipe_name) function util.sum_products(recipe_name)
-- this is going to end up approximate in some cases, integer division is probs fine -- this is going to end up approximate in some cases, integer division is probs fine
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then

View file

@ -68,6 +68,6 @@ data:extend({
weight = 20*kg, weight = 20*kg,
inventory_move_sound = item_sounds.resource_inventory_move, inventory_move_sound = item_sounds.resource_inventory_move,
pick_sound = item_sounds.resource_inventory_pickup, pick_sound = item_sounds.resource_inventory_pickup,
drop_sound = item_sounds.resource_inventory_move, drop_sound = item_sounds.resource_inventory_move
}, },
}) })