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
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
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 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
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
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