From 475182efd0a118d54d6a78e891e50fcb0d207a80 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 20 Feb 2023 04:22:59 +0100 Subject: [PATCH] Ignore techonolgy enabled status for sync Technologies that were disabled were ignored completely by research sync due to a missunderstanding of what disabled means. Disabled does not mean the tech is somehow inaccessible and completely out of play, it only means it can't be selected in the technology screen. Ignore the enabled status of technologies in research_sync to fix a crash that happened when a mod enables a disabled by default technology and the player attempts to research it. --- plugins/research_sync/module/sync.lua | 34 ++++++++++++--------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/plugins/research_sync/module/sync.lua b/plugins/research_sync/module/sync.lua index 5bd9b938..0fdceec9 100644 --- a/plugins/research_sync/module/sync.lua +++ b/plugins/research_sync/module/sync.lua @@ -32,14 +32,12 @@ sync.events[clusterio_api.events.on_server_startup] = function(event) local force = game.forces["player"] for _, tech in pairs(force.technologies) do - if tech.enabled then - local progress = get_technology_progress(tech) - global.research_sync.technologies[tech.name] = { - level = tech.level, - researched = tech.researched, - progress = progress, - } - end + local progress = get_technology_progress(tech) + global.research_sync.technologies[tech.name] = { + level = tech.level, + researched = tech.researched, + progress = progress, + } end end @@ -112,14 +110,12 @@ function research_sync.dump_technologies() local techs = {} for _, tech in pairs(force.technologies) do - if tech.enabled then - table.insert(techs, { - name = tech.name, - level = tech.level, - progress = get_technology_progress(tech), - researched = tech.researched, - }) - end + table.insert(techs, { + name = tech.name, + level = tech.level, + progress = get_technology_progress(tech), + researched = tech.researched, + }) end if #techs == 0 then @@ -140,7 +136,7 @@ function research_sync.sync_technologies(data) global.research_sync.ignore_research_finished = true for _, tech_data in pairs(game.json_to_table(data)) do local tech = force.technologies[tech_data[nameIndex]] - if tech and tech.enabled and tech.level <= tech_data[levelIndex] then + if tech and tech.level <= tech_data[levelIndex] then tech.level = math.min(tech_data[levelIndex], tech.prototype.max_level) local progress @@ -171,7 +167,7 @@ function research_sync.update_progress(data) for _, masterTech in ipairs(techs) do local tech = force.technologies[masterTech.name] - if tech and tech.enabled and tech.level == masterTech.level then + if tech and tech.level == masterTech.level then send_contribution(tech) set_technology_progress(tech, masterTech.progress) global.research_sync.technologies[tech.name] = { @@ -185,7 +181,7 @@ end function research_sync.research_technology(name, level) local force = game.forces["player"] local tech = force.technologies[name] - if not tech or not tech.enabled or tech.level > level then + if not tech or tech.level > level then return end