From 2d84245103b1bd618a8bb0f2ca89911b310187a9 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 31 Jul 2021 20:19:05 +0200 Subject: [PATCH] Factorio: fix adjust_energy to hit special cases with implied energy cost --- .../data/mod_template/data-final-fixes.lua | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/worlds/factorio/data/mod_template/data-final-fixes.lua b/worlds/factorio/data/mod_template/data-final-fixes.lua index 81a75ce8..010b0020 100644 --- a/worlds/factorio/data/mod_template/data-final-fixes.lua +++ b/worlds/factorio/data/mod_template/data-final-fixes.lua @@ -51,20 +51,32 @@ function copy_factorio_icon(tech, tech_source) tech.icon_size = table.deepcopy(technologies[tech_source].icon_size) end +{# This got complex, but seems to be required to hit all corner cases #} function adjust_energy(recipe_name, factor) local recipe = data.raw.recipe[recipe_name] local energy = recipe.energy_required - if (energy ~= nil) then - data.raw.recipe[recipe_name].energy_required = energy * factor - end - if (recipe.normal ~= nil and recipe.normal.energy_required ~= nil) then - energy = recipe.normal.energy_required + + if (recipe.normal ~= nil) then + if (recipe.normal.energy_required == nil) then + energy = 0.5 + else + energy = recipe.normal.energy_required + end recipe.normal.energy_required = energy * factor end - if (recipe.expensive ~= nil and recipe.expensive.energy_required ~= nil) then - energy = recipe.expensive.energy_required + if (recipe.expensive ~= nil) then + if (recipe.expensive.energy_required == nil) then + energy = 0.5 + else + energy = recipe.expensive.energy_required + end recipe.expensive.energy_required = energy * factor end + if (energy ~= nil) then + data.raw.recipe[recipe_name].energy_required = energy * factor + elseif (recipe.expensive == nil and recipe.normal == nil) then + data.raw.recipe[recipe_name].energy_required = 0.5 * factor + end end data.raw["assembling-machine"]["assembling-machine-1"].crafting_categories = table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"].crafting_categories)