From: Someone Date: Fri, 26 Jun 2026 22:22:15 +0000 (+0200) Subject: RELEASE 2.1.1 - Sort search results by strategy. Random=Alphabetical search results... X-Git-Url: https://git.somenet.org/factorio/some-autoresearch.git/commitdiff_plain?ds=sidebyside RELEASE 2.1.1 - Sort search results by strategy. Random=Alphabetical search results and random research order. Thanks to durandal42 --- diff --git a/changelog.txt b/changelog.txt index 5894744..cad9e8d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/control.lua b/control.lua index f9900f3..2d2128e 100644 --- a/control.lua +++ b/control.lua @@ -154,6 +154,47 @@ function canResearch(force, tech, config) 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 @@ -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 - -- 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 @@ -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 - 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 @@ -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 - 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 @@ -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") + + 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 @@ -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 techs = {} 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 diff --git a/info.json b/info.json index efe7b87..135bbda 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "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",