From eb295e473407e90100c4dac5c34a4a41a5cbaf65 Mon Sep 17 00:00:00 2001 From: WeNdKaPL Date: Wed, 17 Dec 2025 01:01:15 +0100 Subject: [PATCH 1/6] Restore py halving tech costs each tier to autotech --- autotech.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/autotech.lua b/autotech.lua index 96c4dd0..6d01865 100644 --- a/autotech.lua +++ b/autotech.lua @@ -368,6 +368,7 @@ function auto_tech:set_tech_unit() local exponent = self.configuration.tech_cost_exponent local victory_node = self.technology_nodes:find_technology_node(self.dependency_graph.victory_node) local max_depth = victory_node.depth - 1 + local depths_of_science_packs = {} if max_depth <= 0 then error("victory technology has a depth of " .. max_depth .. "\n" .. serpent.block(victory_node)) @@ -390,20 +391,79 @@ function auto_tech:set_tech_unit() error() end + --get the depths of all science packs on the tech tree, assuming non-progression military science + self.technology_nodes:for_all_nodes(function(technology_node) + local factorio_tech = technology_node.object_node.object + local science_pack_unlocked_by_this_tech = data.raw.tool[technology_node.object_node.object.name] + if science_pack_unlocked_by_this_tech then + if factorio_tech.name == "military-science-pack" then + if verbose_logging then + log("Depth of a military science pack tech is " .. technology_node.depth) + end + goto continue + end + depths_of_science_packs[#depths_of_science_packs+1]=technology_node.depth + if verbose_logging then + log("Depth of a new science pack tech is " .. technology_node.depth) + end + ::continue:: + end + end) + + --sort the table of depths from lowest to highest + table.sort(depths_of_science_packs) + for i,pack_depth in pairs(depths_of_science_packs) do + if verbose_logging then + log("Depth of a new science pack tech is " .. pack_depth) + end + end + self.technology_nodes:for_all_nodes(function(technology_node) local factorio_tech = technology_node.object_node.object if factorio_tech.research_trigger then return end factorio_tech.unit = factorio_tech.unit or {} - local depth_percent = (technology_node.depth / max_depth) + + --get the relative depth of the technology compared to the science pack, with the first tech using the pack having a relative depth of 1 + local relative_depth_in_science_tier = technology_node.depth + local length_of_science_tier = 1 + for i,pack_depth in pairs(depths_of_science_packs) do + if i == #depths_of_science_packs then + length_of_science_tier = max_depth-depths_of_science_packs[i] + relative_depth_in_science_tier = relative_depth_in_science_tier - depths_of_science_packs[i] + break + else + if depths_of_science_packs[i+1] >= technology_node.depth then + length_of_science_tier = depths_of_science_packs[i+1]-depths_of_science_packs[i] + if i>1 then --skipping automation science + relative_depth_in_science_tier = relative_depth_in_science_tier - depths_of_science_packs[i] + end + break + end + end + + end + + number_of_initial_trigger_techs=depths_of_science_packs[1]+1 + + local depth_percent = ((technology_node.depth - number_of_initial_trigger_techs)/ (max_depth- number_of_initial_trigger_techs)) factorio_tech.unit.count = start + (victory - start) * (depth_percent ^ exponent) if factorio_tech.unit.count == math.huge then error(depth_percent .. "\n" .. serpent.block(factorio_tech) .. serpent.block(self.configuration)) end if verbose_logging then - log("Technology " .. factorio_tech.name .. " has a depth of " .. technology_node.depth .. ". Calculated science pack cost is " .. factorio_tech.unit.count) + log("Technology " .. factorio_tech.name .. " has a depth of " .. technology_node.depth .. " and a relative depth from the last science pack " .. relative_depth_in_science_tier .. ". Calculated science pack cost is " .. factorio_tech.unit.count) + end + if relative_depth_in_science_tier > 0 then + if relative_depth_in_science_tier < technology_node.depth then + x = (relative_depth_in_science_tier-1)/(length_of_science_tier-1) + factorio_tech.unit.count = factorio_tech.unit.count*(0.5*(1.0-x)+x) --linear scaling between 0.5 and full cost across the science tier + end end factorio_tech.unit.count = math.max(cost_rounding(factorio_tech.unit.count), 1) + if verbose_logging then + log("Technology " .. factorio_tech.name .. " has the reduced and rounded cost of " .. factorio_tech.unit.count) + end local final_multiplier = self.configuration.tech_cost_additional_multipliers[factorio_tech.name] if final_multiplier then From a667cab766b80a9f859f4575497ad3a431a92cd6 Mon Sep 17 00:00:00 2001 From: WeNdKaPL Date: Wed, 17 Dec 2025 09:34:44 +0100 Subject: [PATCH 2/6] Fixes with cleaner solutions --- autotech.lua | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/autotech.lua b/autotech.lua index 6d01865..52a0bbc 100644 --- a/autotech.lua +++ b/autotech.lua @@ -398,7 +398,7 @@ function auto_tech:set_tech_unit() if science_pack_unlocked_by_this_tech then if factorio_tech.name == "military-science-pack" then if verbose_logging then - log("Depth of a military science pack tech is " .. technology_node.depth) + log("Depth of a military science pack tech is " .. technology_node.depth .. ". it will be ignored as a non-progression pack.") end goto continue end @@ -412,39 +412,36 @@ function auto_tech:set_tech_unit() --sort the table of depths from lowest to highest table.sort(depths_of_science_packs) - for i,pack_depth in pairs(depths_of_science_packs) do - if verbose_logging then - log("Depth of a new science pack tech is " .. pack_depth) + if verbose_logging then + for _,pack_depth in pairs(depths_of_science_packs) do + log("Depth of a new science pack tech is " .. pack_depth) end end + self.technology_nodes:for_all_nodes(function(technology_node) local factorio_tech = technology_node.object_node.object if factorio_tech.research_trigger then return end factorio_tech.unit = factorio_tech.unit or {} - --get the relative depth of the technology compared to the science pack, with the first tech using the pack having a relative depth of 1 - local relative_depth_in_science_tier = technology_node.depth - local length_of_science_tier = 1 - for i,pack_depth in pairs(depths_of_science_packs) do - if i == #depths_of_science_packs then - length_of_science_tier = max_depth-depths_of_science_packs[i] - relative_depth_in_science_tier = relative_depth_in_science_tier - depths_of_science_packs[i] + --get the relative depth of the technology compared to the science pack, as a percentage + local relative_depth_percent = -1 + local absolute_depth_in_science_tier = technology_node.depth + for i = #depths_of_science_packs, 2, -1 do -- work from largest to smallest, end at 2 as we won't be adjusting automation tech costs + local current_tier_depth = depths_of_science_packs[i] + 1 -- Add one as we want the first tech, not the science pack + if technology_node.depth >= current_tier_depth then + local next_tier_depth = depths_of_science_packs[i + 1] or max_depth + local length_of_science_tier = next_tier_depth - current_tier_depth + absolute_depth_in_science_tier = absolute_depth_in_science_tier - current_tier_depth + relative_depth_percent = (technology_node.depth - current_tier_depth) / length_of_science_tier -- aka relative depth in science tier break - else - if depths_of_science_packs[i+1] >= technology_node.depth then - length_of_science_tier = depths_of_science_packs[i+1]-depths_of_science_packs[i] - if i>1 then --skipping automation science - relative_depth_in_science_tier = relative_depth_in_science_tier - depths_of_science_packs[i] - end - break - end end - end - number_of_initial_trigger_techs=depths_of_science_packs[1]+1 - + number_of_initial_trigger_techs=depths_of_science_packs[1] + 1 + if verbose_logging then + log("There are " .. number_of_initial_trigger_techs .. " trigger techs at the start") + end local depth_percent = ((technology_node.depth - number_of_initial_trigger_techs)/ (max_depth- number_of_initial_trigger_techs)) factorio_tech.unit.count = start + (victory - start) * (depth_percent ^ exponent) @@ -452,12 +449,11 @@ function auto_tech:set_tech_unit() error(depth_percent .. "\n" .. serpent.block(factorio_tech) .. serpent.block(self.configuration)) end if verbose_logging then - log("Technology " .. factorio_tech.name .. " has a depth of " .. technology_node.depth .. " and a relative depth from the last science pack " .. relative_depth_in_science_tier .. ". Calculated science pack cost is " .. factorio_tech.unit.count) + log("Technology " .. factorio_tech.name .. " has a depth of " .. technology_node.depth .. ", absolute depth from last science pack of" .. absolute_depth_in_science_tier .. " and a relative depth in the science tier " .. relative_depth_percent .. ". Calculated science pack cost is " .. factorio_tech.unit.count) end - if relative_depth_in_science_tier > 0 then - if relative_depth_in_science_tier < technology_node.depth then - x = (relative_depth_in_science_tier-1)/(length_of_science_tier-1) - factorio_tech.unit.count = factorio_tech.unit.count*(0.5*(1.0-x)+x) --linear scaling between 0.5 and full cost across the science tier + if relative_depth_percent >= 0 then + if absolute_depth_in_science_tier < technology_node.depth then + factorio_tech.unit.count = factorio_tech.unit.count*(0.5*(1.0-relative_depth_percent)+relative_depth_percent) --linear scaling between 0.5 and full cost across the science tier end end factorio_tech.unit.count = math.max(cost_rounding(factorio_tech.unit.count), 1) From 5913f83f65d7ff2d571d2a0eb76ee45f60a0ea27 Mon Sep 17 00:00:00 2001 From: WeNdKaPL Date: Wed, 17 Dec 2025 19:07:46 +0100 Subject: [PATCH 3/6] Removing goto from military science check and better trigger tech counting --- autotech.lua | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/autotech.lua b/autotech.lua index 52a0bbc..390a5fa 100644 --- a/autotech.lua +++ b/autotech.lua @@ -396,20 +396,21 @@ function auto_tech:set_tech_unit() local factorio_tech = technology_node.object_node.object local science_pack_unlocked_by_this_tech = data.raw.tool[technology_node.object_node.object.name] if science_pack_unlocked_by_this_tech then - if factorio_tech.name == "military-science-pack" then + if factorio_tech.name ~= "military-science-pack" then + depths_of_science_packs[#depths_of_science_packs+1]=technology_node.depth if verbose_logging then - log("Depth of a military science pack tech is " .. technology_node.depth .. ". it will be ignored as a non-progression pack.") + log("Depth of a new science pack tech is " .. technology_node.depth) end - goto continue + return end - depths_of_science_packs[#depths_of_science_packs+1]=technology_node.depth if verbose_logging then - log("Depth of a new science pack tech is " .. technology_node.depth) + log("Depth of a military science pack tech is " .. technology_node.depth .. ". it will be ignored as a non-progression pack.") end - ::continue:: end end) + + --sort the table of depths from lowest to highest table.sort(depths_of_science_packs) if verbose_logging then @@ -417,6 +418,22 @@ function auto_tech:set_tech_unit() log("Depth of a new science pack tech is " .. pack_depth) end end + + local number_of_initial_trigger_techs = 0 + -- count the amount of trigger techs leading to the initial science pack + for i = 1, math.min(#self.technology_nodes_array, depths_of_science_packs[1]+1) do + local node = self.technology_nodes_array[i] + if not node.object_node.object.research_trigger then + break + end + if verbose_logging then + log(node.printable_name .. " is the new latest trigger tech") + end + number_of_initial_trigger_techs = node.depth + 1 + end + if verbose_logging then + log("Number of initial trigger techs is " .. number_of_initial_trigger_techs) + end self.technology_nodes:for_all_nodes(function(technology_node) @@ -438,10 +455,6 @@ function auto_tech:set_tech_unit() end end - number_of_initial_trigger_techs=depths_of_science_packs[1] + 1 - if verbose_logging then - log("There are " .. number_of_initial_trigger_techs .. " trigger techs at the start") - end local depth_percent = ((technology_node.depth - number_of_initial_trigger_techs)/ (max_depth- number_of_initial_trigger_techs)) factorio_tech.unit.count = start + (victory - start) * (depth_percent ^ exponent) From 12d270f54f6a9dbf564483370f64d0c3a73bf045 Mon Sep 17 00:00:00 2001 From: WeNdKaPL Date: Thu, 18 Dec 2025 09:29:47 +0100 Subject: [PATCH 4/6] Making logging more readable --- autotech.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/autotech.lua b/autotech.lua index 390a5fa..e595578 100644 --- a/autotech.lua +++ b/autotech.lua @@ -462,7 +462,18 @@ function auto_tech:set_tech_unit() error(depth_percent .. "\n" .. serpent.block(factorio_tech) .. serpent.block(self.configuration)) end if verbose_logging then - log("Technology " .. factorio_tech.name .. " has a depth of " .. technology_node.depth .. ", absolute depth from last science pack of" .. absolute_depth_in_science_tier .. " and a relative depth in the science tier " .. relative_depth_percent .. ". Calculated science pack cost is " .. factorio_tech.unit.count) + log(table.concat({ + "Technology ", + factorio_tech.name, + " has a depth of ", + technology_node.depth + ", absolute depth from last science pack of " + absolute_depth_in_science_tier + " and a relative depth in the science tier of " + relative_depth_percent, + ". Calculated science pack cost is " + factorio_tech.unit.count + })) end if relative_depth_percent >= 0 then if absolute_depth_in_science_tier < technology_node.depth then From 3d829e923ea1fec82bf3f71d93c742700a697809 Mon Sep 17 00:00:00 2001 From: WeNdKaPL Date: Thu, 18 Dec 2025 09:36:41 +0100 Subject: [PATCH 5/6] Fix for the log fix --- autotech.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/autotech.lua b/autotech.lua index e595578..795056d 100644 --- a/autotech.lua +++ b/autotech.lua @@ -466,12 +466,12 @@ function auto_tech:set_tech_unit() "Technology ", factorio_tech.name, " has a depth of ", - technology_node.depth - ", absolute depth from last science pack of " - absolute_depth_in_science_tier - " and a relative depth in the science tier of " + technology_node.depth, + ", absolute depth from last science pack of ", + absolute_depth_in_science_tier, + " and a relative depth in the science tier of ", relative_depth_percent, - ". Calculated science pack cost is " + ". Calculated science pack cost is ", factorio_tech.unit.count })) end From 1d3b1dabd8c12943d659acaf03bfa82548d3c186 Mon Sep 17 00:00:00 2001 From: oorzkws <65210810+oorzkws@users.noreply.github.com> Date: Sun, 21 Dec 2025 14:37:32 -0700 Subject: [PATCH 6/6] Fix formatting to follow standard --- autotech.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/autotech.lua b/autotech.lua index 795056d..c32d6b6 100644 --- a/autotech.lua +++ b/autotech.lua @@ -391,13 +391,13 @@ function auto_tech:set_tech_unit() error() end - --get the depths of all science packs on the tech tree, assuming non-progression military science + -- get the depths of all science packs on the tech tree, assuming non-progression military science self.technology_nodes:for_all_nodes(function(technology_node) local factorio_tech = technology_node.object_node.object local science_pack_unlocked_by_this_tech = data.raw.tool[technology_node.object_node.object.name] if science_pack_unlocked_by_this_tech then if factorio_tech.name ~= "military-science-pack" then - depths_of_science_packs[#depths_of_science_packs+1]=technology_node.depth + depths_of_science_packs[#depths_of_science_packs + 1] = technology_node.depth if verbose_logging then log("Depth of a new science pack tech is " .. technology_node.depth) end @@ -409,19 +409,19 @@ function auto_tech:set_tech_unit() end end) - - --sort the table of depths from lowest to highest + + -- sort the table of depths from lowest to highest table.sort(depths_of_science_packs) if verbose_logging then - for _,pack_depth in pairs(depths_of_science_packs) do + for _, pack_depth in pairs(depths_of_science_packs) do log("Depth of a new science pack tech is " .. pack_depth) end end local number_of_initial_trigger_techs = 0 -- count the amount of trigger techs leading to the initial science pack - for i = 1, math.min(#self.technology_nodes_array, depths_of_science_packs[1]+1) do + for i = 1, math.min(#self.technology_nodes_array, depths_of_science_packs[1] + 1) do local node = self.technology_nodes_array[i] if not node.object_node.object.research_trigger then break @@ -434,14 +434,14 @@ function auto_tech:set_tech_unit() if verbose_logging then log("Number of initial trigger techs is " .. number_of_initial_trigger_techs) end - + self.technology_nodes:for_all_nodes(function(technology_node) local factorio_tech = technology_node.object_node.object if factorio_tech.research_trigger then return end factorio_tech.unit = factorio_tech.unit or {} - --get the relative depth of the technology compared to the science pack, as a percentage + -- get the relative depth of the technology compared to the science pack, as a percentage local relative_depth_percent = -1 local absolute_depth_in_science_tier = technology_node.depth for i = #depths_of_science_packs, 2, -1 do -- work from largest to smallest, end at 2 as we won't be adjusting automation tech costs @@ -455,14 +455,14 @@ function auto_tech:set_tech_unit() end end - local depth_percent = ((technology_node.depth - number_of_initial_trigger_techs)/ (max_depth- number_of_initial_trigger_techs)) + local depth_percent = ((technology_node.depth - number_of_initial_trigger_techs) / (max_depth - number_of_initial_trigger_techs)) factorio_tech.unit.count = start + (victory - start) * (depth_percent ^ exponent) if factorio_tech.unit.count == math.huge then error(depth_percent .. "\n" .. serpent.block(factorio_tech) .. serpent.block(self.configuration)) end if verbose_logging then - log(table.concat({ + log(table.concat{ "Technology ", factorio_tech.name, " has a depth of ", @@ -473,11 +473,11 @@ function auto_tech:set_tech_unit() relative_depth_percent, ". Calculated science pack cost is ", factorio_tech.unit.count - })) + }) end if relative_depth_percent >= 0 then if absolute_depth_in_science_tier < technology_node.depth then - factorio_tech.unit.count = factorio_tech.unit.count*(0.5*(1.0-relative_depth_percent)+relative_depth_percent) --linear scaling between 0.5 and full cost across the science tier + factorio_tech.unit.count = factorio_tech.unit.count * (0.5 * (1.0 - relative_depth_percent) + relative_depth_percent) -- linear scaling between 0.5 and full cost across the science tier end end factorio_tech.unit.count = math.max(cost_rounding(factorio_tech.unit.count), 1)