Update to 2.0

This commit is contained in:
Simon Brodtmann 2025-10-02 15:56:15 +02:00
parent c090985a08
commit fbd8f08c5c
78 changed files with 650 additions and 540 deletions

View file

@ -1,11 +1,8 @@
local rusty_locale = require("__rusty-locale__.locale")
local rusty_icons = require("__rusty-locale__.icons")
local rusty_recipes = require("__rusty-locale__.recipes")
local rusty_prototypes = require("__rusty-locale__.prototypes")
local futil = require("util")
local util = require("data-util")
function has_suffix(s, suffix)
return string.sub(s, -string.len(suffix), -1) == suffix
end
@ -23,82 +20,31 @@ function check_name(name)
for i, suffix in pairs(suffixes) do
if has_suffix(name, suffix) then return true end
end
if name == "rare-metals" then return true end
if name == "kr-rare-metals" then return true end
if name == "tungsten-carbide" then return true end
return false
end
function make_recipe(recipe)
local found_result = false
local has_normal = false
local has_exp = false
local new_results = {}
local new_normal_results = {}
local new_exp_results = {}
if recipe.results then -- standard recipes
for i, result in pairs(recipe.results) do
if (result.name and check_name(result.name)) or
(result[1] and check_name(result[1])) then
found_result = result.name and result.name or result[1]
if result.name and check_name(result.name) then
found_result = result.name
new_results = futil.table.deepcopy(recipe.results)
break
end
end
end
if recipe.result and check_name(recipe.result) then
found_result = recipe.result
new_results = {{recipe.result, recipe.result_count or 1}}
end
if recipe.normal then
has_normal = true
if recipe.normal.results then
for i, result in pairs(recipe.normal.results) do
if (result.name and check_name(result.name)) or
(result[1] and check_name(result[1])) then
found_result = result.name and result.name or result[1]
new_normal_results = futil.table.deepcopy(recipe.normal.results)
break
end
end
end
if recipe.normal.result and check_name(recipe.normal.result) then
found_result = recipe.normal.result
new_normal_results = {{recipe.normal.result, recipe.normal.result_count or 1}}
end
end
if recipe.expensive then
has_exp = true
if recipe.expensive.results then
for i, result in pairs(recipe.expensive.results) do
if (result.name and check_name(result.name)) or
(result[1] and check_name(result[1])) then
found_result = result.name and result.name or result[1]
new_exp_results = futil.table.deepcopy(recipe.expensive.results)
break
end
end
end
if recipe.expensive.result and check_name(recipe.expensive.result) then
found_result = recipe.expensive.result
new_exp_results = {{recipe.expensive.result, recipe.expensive.result_count or 1}}
end
end
if found_result then
log("Attempting to make refractory recipe for " .. recipe.name)
local r = futil.table.deepcopy(recipe)
r.name = r.name .. "-refractory"
r.main_product = found_result
r.result = nil
r.result_count = nil
r.results = {}
r.enabled = false
r.category = recipe.category == "casting" and "casting" or "founding"
r.subgroup = data.raw.item[found_result] and data.raw.item[found_result].subgroup or "foundry-intermediate"
@ -123,25 +69,9 @@ function make_recipe(recipe)
r.icons = icons
locale = rusty_locale.of_recipe(data.raw.recipe[recipe.name])
r.localised_name = {"recipe-name.with-refractory", locale.name}
if not has_normal and not has_exp then
r.results = new_results
make_ingredients_and_products(r, r.name)
end
if has_normal then
r.normal.results = new_normal_results
r.normal.result = nil
r.normal.result_count = nil
r.normal.enabled = false
make_ingredients_and_products(r.normal, r.name)
end
if has_exp then
r.expensive.results = new_exp_results
r.expensive.result = nil
r.expensive.result_count = nil
r.expensive.enabled = false
make_ingredients_and_products(r.expensive, r.name)
end
r.results = new_results
make_ingredients_and_products(r, r.name)
r.allow_productivity = true
return r
end
return nil
@ -164,9 +94,6 @@ function make_ingredients_and_products(r, name)
local refractories = get_refractories(r, name)
local max_count = 1
for i, ingredient in pairs(r.ingredients) do
if ingredient[2] and ingredient[2] > max_count then
max_count = ingredient[2]
end
if ingredient.amount and ingredient.amount > max_count then
max_count = ingredient.amount
end
@ -178,20 +105,16 @@ function make_ingredients_and_products(r, name)
end
for i, refractory in pairs(refractories) do
for j, existing in pairs(r.ingredients) do
if existing[1] == refractory or existing.name == refractory then
if existing.name == refractory then
log("Warning: "..name.." refractory recipe recipe unbalanced due to skipped ingredients")
goto skip
end
end
table.insert(r.ingredients, {refractory, refractory_amount})
table.insert(r.ingredients, {type = "item", name = refractory, amount = refractory_amount})
end
::skip::
for i, result in pairs(r.results) do
if result[1] and check_name(result[1]) then
result[2] = result[2]*2
break
end
if result.name and check_name(result.name) then
if result.amount then
result.amount = result.amount * 2
@ -206,8 +129,8 @@ function make_ingredients_and_products(r, name)
end
end
for i, refractory in pairs(refractories) do
table.insert(r.results, {type="item", name=refractory, amount=refractory_amount, catalyst_amount=refractory_amount,
probability=get_probability(#refractories)})
table.insert(r.results, {type="item", name=refractory, amount=refractory_amount, ignored_by_productivity=refractory_amount,
ignored_by_stats=refractory_amount, probability=get_probability(#refractories)})
end
end
@ -240,16 +163,5 @@ if util.me.founding_plates() then
else
util.add_effect("advanced-founding", {type="unlock-recipe", recipe=recipe.name})
end
-- prod modules
for j, module in pairs(data.raw.module) do
if module.effect then
for effect_name, effect in pairs(module.effect) do
if effect_name == "productivity" and effect.bonus > 0 and module.limitation and #module.limitation > 0 then
table.insert(module.limitation, recipe.name)
end
end
end
end
end
end