]> git.somenet.org - factorio/some-autoresearch.git/commitdiff
RELEASE 2.1.1 - Sort search results by strategy. Random=Alphabetical search results... master
authorSomeone <someone@somenet.org>
Fri, 26 Jun 2026 22:22:15 +0000 (00:22 +0200)
committerSomeone <someone@somenet.org>
Fri, 26 Jun 2026 22:22:15 +0000 (00:22 +0200)
changelog.txt
control.lua
info.json

index 58947449e0240c9723deb0d1ff019972b4ed0189..cad9e8d9ce2adb8d8b3cd7970de9296d689689c2 100644 (file)
@@ -1,3 +1,10 @@
+---------------------------------------------------------------------------------------------------
+Version: 2.1.1
+Date: 2026-06-26
+
+  Changed:
+    - Sort search results by strategy. Random=Alphabetical search results and random research order. Thanks to durandal42
+
 ---------------------------------------------------------------------------------------------------
 Version: 2.1.0
 Date: 2026-06-26
 ---------------------------------------------------------------------------------------------------
 Version: 2.1.0
 Date: 2026-06-26
index f9900f3455051ea69443aad741cbc5e1bc76d27e..2d2128e9321ff142fed200ec9d2d7d4955922626 100644 (file)
@@ -154,6 +154,47 @@ function canResearch(force, tech, config)
     return true
 end
 
     return true
 end
 
+
+
+-- function for calculating tech effort
+function calcEffort(tech, config)
+    local ingredientCount = function(ingredients)
+        local tech_ingredients = 0
+        for _, ingredient in pairs(tech.research_unit_ingredients) do
+            tech_ingredients = tech_ingredients + ingredient.amount
+        end
+        return tech_ingredients
+    end
+    local effort = 0
+    if config.research_strategy == "fast" then
+        effort = math.max(tech.research_unit_energy, 1) * math.max(tech.research_unit_count, 1)
+    elseif config.research_strategy == "slow" then
+        effort = math.max(tech.research_unit_energy, 1) * math.max(tech.research_unit_count, 1) * -1
+    elseif config.research_strategy == "cheap" then
+        effort = math.max(ingredientCount(tech.research_unit_ingredients), 1) * math.max(tech.research_unit_count, 1)
+    elseif config.research_strategy == "expensive" then
+        effort = math.max(ingredientCount(tech.research_unit_ingredients), 1) * math.max(tech.research_unit_count, 1) * -1
+    elseif config.research_strategy == "balanced" then
+        effort = math.max(tech.research_unit_count, 1) * math.max(tech.research_unit_energy, 1) * math.max(ingredientCount(tech.research_unit_ingredients), 1)
+    else
+        effort = math.random(1, 999)
+    end
+    if (config.deprioritize_infinite_tech and config.infinite_research[tech.name]) then
+        return effort * (effort > 0 and 1000 or -1000)
+    else
+        return effort
+    end
+end
+
+function sortTechsByEffort(techs, config)
+    local compare = function(a, b)
+        return calcEffort(a[2], config) < calcEffort(b[2], config)
+    end
+    if config.research_strategy ~= "random" then
+        table.sort(techs, compare)
+    end
+end
+
 function startNextResearch(force, override_spam_detection)
     local config = getConfig(force)
     if not config.enabled or (force.current_research and not config.allow_switching) or (not override_spam_detection and config.last_research_finish_tick == game.tick) then
 function startNextResearch(force, override_spam_detection)
     local config = getConfig(force)
     if not config.enabled or (force.current_research and not config.allow_switching) or (not override_spam_detection and config.last_research_finish_tick == game.tick) then
@@ -161,36 +202,6 @@ function startNextResearch(force, override_spam_detection)
     end
     config.last_research_finish_tick = game.tick -- if multiple research finish same tick for same force, the user probably enabled all techs
 
     end
     config.last_research_finish_tick = game.tick -- if multiple research finish same tick for same force, the user probably enabled all techs
 
-    -- function for calculating tech effort
-    local calcEffort = function(tech)
-        local ingredientCount = function(ingredients)
-            local tech_ingredients = 0
-            for _, ingredient in pairs(tech.research_unit_ingredients) do
-                tech_ingredients = tech_ingredients + ingredient.amount
-            end
-            return tech_ingredients
-        end
-        local effort = 0
-        if config.research_strategy == "fast" then
-            effort = math.max(tech.research_unit_energy, 1) * math.max(tech.research_unit_count, 1)
-        elseif config.research_strategy == "slow" then
-            effort = math.max(tech.research_unit_energy, 1) * math.max(tech.research_unit_count, 1) * -1
-        elseif config.research_strategy == "cheap" then
-            effort = math.max(ingredientCount(tech.research_unit_ingredients), 1) * math.max(tech.research_unit_count, 1)
-        elseif config.research_strategy == "expensive" then
-            effort = math.max(ingredientCount(tech.research_unit_ingredients), 1) * math.max(tech.research_unit_count, 1) * -1
-        elseif config.research_strategy == "balanced" then
-            effort = math.max(tech.research_unit_count, 1) * math.max(tech.research_unit_energy, 1) * math.max(ingredientCount(tech.research_unit_ingredients), 1)
-        else
-            effort = math.random(1, 999)
-        end
-        if (config.deprioritize_infinite_tech and config.infinite_research[tech.name]) then
-            return effort * (effort > 0 and 1000 or -1000)
-        else
-            return effort
-        end
-    end
-
     -- see if there are some techs we should research first
     local next_research = nil
     local least_effort = nil
     -- see if there are some techs we should research first
     local next_research = nil
     local least_effort = nil
@@ -199,7 +210,7 @@ function startNextResearch(force, override_spam_detection)
         if tech and not next_research then
             local pretechs = getPretechs(tech)
             for _, pretech in pairs(pretechs) do
         if tech and not next_research then
             local pretechs = getPretechs(tech)
             for _, pretech in pairs(pretechs) do
-                local effort = calcEffort(pretech)
+                local effort = calcEffort(pretech, config)
                 if (not least_effort or effort < least_effort) and canResearch(force, pretech, config) then
                     next_research = pretech.name
                     least_effort = effort
                 if (not least_effort or effort < least_effort) and canResearch(force, pretech, config) then
                     next_research = pretech.name
                     least_effort = effort
@@ -212,7 +223,7 @@ function startNextResearch(force, override_spam_detection)
     if not config.prioritized_only and not next_research then
         for techname, tech in pairs(force.technologies) do
             if tech.enabled and not tech.researched then
     if not config.prioritized_only and not next_research then
         for techname, tech in pairs(force.technologies) do
             if tech.enabled and not tech.researched then
-                local effort = calcEffort(tech)
+                local effort = calcEffort(tech, config)
                 if (not least_effort or effort < least_effort) and canResearch(force, tech, config) then
                     next_research = techname
                     least_effort = effort
                 if (not least_effort or effort < least_effort) and canResearch(force, tech, config) then
                     next_research = techname
                     least_effort = effort
@@ -458,6 +469,11 @@ gui = {
             player.gui.top.auto_research_gui.flow.research_strategies_outer.auto_research_research_slow.state = (config.research_strategy == "slow")
             player.gui.top.auto_research_gui.flow.research_strategies_outer.auto_research_research_expensive.state = (config.research_strategy == "expensive")
             player.gui.top.auto_research_gui.flow.research_strategies_outer.auto_research_research_random.state = (config.research_strategy == "random")
             player.gui.top.auto_research_gui.flow.research_strategies_outer.auto_research_research_slow.state = (config.research_strategy == "slow")
             player.gui.top.auto_research_gui.flow.research_strategies_outer.auto_research_research_expensive.state = (config.research_strategy == "expensive")
             player.gui.top.auto_research_gui.flow.research_strategies_outer.auto_research_research_random.state = (config.research_strategy == "random")
+
+            gui.updateTechnologyList(player.gui.top.auto_research_gui.flow.prioritized, config.prioritized_techs, player, true)
+            gui.updateTechnologyList(player.gui.top.auto_research_gui.flow.deprioritized, config.deprioritized_techs, player)
+            gui.updateSearchResult(player, player.gui.top.auto_research_gui.flow.searchflow.auto_research_search_text.text)
+
             -- start new research
             startNextResearch(force)
         else
             -- start new research
             startNextResearch(force)
         else
@@ -581,7 +597,14 @@ gui = {
         local shown = 0
         text = string.lower(text)
         -- NOTICE: localised name matching does not work at present, pending unlikely changes to Factorio API
         local shown = 0
         text = string.lower(text)
         -- NOTICE: localised name matching does not work at present, pending unlikely changes to Factorio API
+        local techs = {}
         for name, tech in pairs(player.force.technologies) do
         for name, tech in pairs(player.force.technologies) do
+            table.insert(techs, {name, tech})
+        end
+        sortTechsByEffort(techs, config)
+        for _ , namedTech in pairs(techs) do
+            local name = namedTech[1]
+            local tech = namedTech[2]
             if not tech.researched and tech.enabled and #tech.research_unit_ingredients > 0 then
                 local showtech = false
                 if string.find(string.lower(name), text, 1, true) then
             if not tech.researched and tech.enabled and #tech.research_unit_ingredients > 0 then
                 local showtech = false
                 if string.find(string.lower(name), text, 1, true) then
index efe7b87b2f1308957637c9ca37850e21c4064868..135bbdaa2bb67cd2c185809a1922299a7438fda3 100644 (file)
--- a/info.json
+++ b/info.json
@@ -1,6 +1,6 @@
 {
     "name": "some-autoresearch",
 {
     "name": "some-autoresearch",
-    "version": "2.1.0",
+    "version": "2.1.1",
     "title": "Auto Research (fixed + re-published)",
     "author": "Someone (originally canidae)",
     "homepage": "https://git.somenet.org/factorio/some-autoresearch.git",
     "title": "Auto Research (fixed + re-published)",
     "author": "Someone (originally canidae)",
     "homepage": "https://git.somenet.org/factorio/some-autoresearch.git",