function get_ingredients(recipe)
local ingredients = {}
for i,ingredient in pairs(recipe.ingredients) do
if (ingredient.name) then
table.insert(ingredients, ingredient.name)
elseif (ingredient[1]) then
table.insert(ingredients, ingredient[1])
end
end
return ingredients
end
function get_recipes(item)
local recipes = {}
for i,recipe in pairs(data.raw.recipe) do
if (recipe.results) then
for i,product in pairs(recipe.results) do
if (product.name == item) then
table.insert(recipes, recipe)
end
end
elseif (recipe.result == item) then
table.insert(recipes, recipe)
end
end
return recipes
end
local prereq_cache = {}
function get_prereqs(tech)
if (prereq_cache[tech.name]) then return prereq_cache[tech.name] end
prereq_cache[tech.name] = {}
if (tech.prerequisites) then
for _, prereq in pairs(tech.prerequisites) do
prereq_cache[tech.name][prereq] = true
for prereq2,_ in pairs(get_prereqs(data.raw.technology[prereq])) do
prereq_cache[tech.name][prereq2] = true
end
end
end
return prereq_cache[tech.name]
end
function find_missing_ingredients(recipe, techs)
local missing_ingredients = {}
for _, ingredient in pairs(get_ingredients(recipe)) do
local ingredient_recipes = get_recipes(ingredient)
-- Ignore ingredient loops like crude oil barrel
for i = #ingredient_recipes, 1, -1 do
local loop = false
for _, ingredient2 in pairs(get_ingredients(ingredient_recipes[i])) do
for _, recipe2 in pairs(get_recipes(ingredient2)) do
for _, ingredient3 in pairs(get_ingredients(recipe2)) do
if (ingredient == ingredient2 or ingredient == ingredient3) then
loop = true
end
end
end
end
if (loop) then
table.remove(ingredient_recipes, i)
end
end
local missing = true
if (#ingredient_recipes == 0) then
missing = false
end
for _, ingredient_recipe in pairs(ingredient_recipes) do
if (ingredient_recipe.enabled == false) then
for tech,_ in pairs(techs) do
local effects = data.raw.technology[tech].effects
if (effects) then
for _, effect in pairs(effects) do
if (effect.type == "unlock-recipe" and effect.recipe == ingredient_recipe.name) then
missing = false
end
end
end
end
else
missing = false
end
end
if (missing) then
table.insert(missing_ingredients, ingredient)
end
end
return missing_ingredients
end
for _, tech in pairs(data.raw.technology) do
if (tech.effects) then
for _, effect in pairs(tech.effects) do
if (effect.type == "unlock-recipe") then
local recipe = data.raw.recipe[effect.recipe]
local techs = get_prereqs(tech)
techs[tech.name] = true
local missing_ingredients = find_missing_ingredients(recipe, techs)
for _, ingredient in pairs(missing_ingredients) do
log("Recipe "..recipe.name.." requires "..ingredient..", but technology "..tech.name.." does not.");
end
end
end
end
end
Results when running it in 0.14.21:
Recipe filter-inserter requires fast-inserter, but technology electronics does not.
Recipe flamethrower-turret requires engine-unit, but technology flame-thrower does not.
Recipe processing-unit requires sulfuric-acid, but technology advanced-electronics does not.
Recipe rocket-silo requires concrete, but technology rocket-silo does not.
Recipe rocket-silo requires electric-engine-unit, but technology rocket-silo does not.
Recipe satellite requires solar-panel, but technology rocket-silo does not.
Recipe satellite requires accumulator, but technology rocket-silo does not.
Recipe substation requires advanced-circuit, but technology electric-energy-distribution-2 does not.
Recipe science-pack-3 requires advanced-circuit, but technology battery does not.
Recipe science-pack-3 requires filter-inserter, but technology battery does not.
Recipe solar-panel-equipment requires solar-panel, but technology solar-panel-equipment does not.
Recipe small-pump requires electric-engine-unit, but technology fluid-handling does not.
Re: [0.14.21] Technology and recipe prerequisites
Posted: Sun Jan 29, 2017 12:10 pm
by Rseding91
None of these are bugs.
For instance your 2nd item: "Recipe flamethrower-turret requires engine-unit, but technology flame-thrower does not." The technology unlocks more than the turret - you can make the flamethrower handheld before researching engines to make the turrets.
Re: [0.14.21] Technology and recipe prerequisites
Posted: Sun Jan 29, 2017 12:32 pm
by DaveMcW
Then flamethrower-turret should have its own technology that requires electric-engine.
Re: [0.14.21] Technology and recipe prerequisites
Posted: Sun Jan 29, 2017 1:16 pm
by Klonan
DaveMcW wrote:Then flamethrower-turret should have its own technology that requires electric-engine.