Factorio: add option: random tech ingredients

This commit is contained in:
Fabian Dill
2021-04-24 01:16:49 +02:00
parent 73ed18c11d
commit 569e0e3004
9 changed files with 75 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
function filter_ingredients(ingredients)
function filter_ingredients(ingredients, ingredient_filter)
local new_ingredient_list = {}
for _, ingredient_table in pairs(ingredients) do
if allowed_ingredients[ingredient_table[1]] then -- name of ingredient_table
if ingredient_filter[ingredient_table[1]] then -- name of ingredient_table
table.insert(new_ingredient_list, ingredient_table)
end
end

View File

@@ -5,8 +5,12 @@ local technologies = data.raw["technology"]
local original_tech
local new_tree_copy
allowed_ingredients = {}
{%- for ingredient in allowed_science_packs %}
allowed_ingredients["{{ingredient}}"]= 1
{%- for tech_name, technology in custom_data["custom_technologies"].items() %}
allowed_ingredients["{{ tech_name }}"] = {
{%- for ingredient in technology.ingredients %}
["{{ingredient}}"] = 1,
{%- endfor %}
}
{% endfor %}
local template_tech = table.deepcopy(technologies["automation"])
{#- ensure the copy unlocks nothing #}
@@ -18,7 +22,10 @@ template_tech.prerequisites = {}
function prep_copy(new_copy, old_tech)
old_tech.enabled = false
new_copy.unit = table.deepcopy(old_tech.unit)
new_copy.unit.ingredients = filter_ingredients(new_copy.unit.ingredients)
local ingredient_filter = allowed_ingredients[old_tech.name]
if ingredient_filter ~= nil then
new_copy.unit.ingredients = filter_ingredients(new_copy.unit.ingredients, ingredient_filter)
end
end