local labBaseSpeed = 1 local biolabBaseSpeed = 2 function ScanLabs() storage.labs = {} for _, surface in pairs(game.surfaces) do local labs = surface.find_entities_filtered({type="lab"}) for _, lab in pairs(labs) do storage.labs[lab.unit_number] = lab end end end function UpdateLabs(event) local lab = event.entity if lab and lab.valid then storage.labs[lab.unit_number] = lab end end function RemoveLab(event) local lab = event.entity if lab and lab.valid then storage.labs[lab.unit_number] = nil end end function GetEstimatedResearchTime() -- Base time in seconds for research local playerForce = game.forces["player"] local currentResearch = playerForce.current_research if not currentResearch then return end local researchName = currentResearch.name.."-"..currentResearch.level local researchTotalCost = currentResearch.research_unit_count * (currentResearch.research_unit_energy/60) local totalSpeed = storage.totalResearchSpeed local remainingPercentage = 1-math.min(playerForce.research_progress,1) local remainingUnits = remainingPercentage*researchTotalCost local estimatedSeconds = remainingUnits/totalSpeed log(("Remaining Perc: %d\nCost: %d\nSpeed: %d\nRem Units: %d\n"):format(remainingPercentage,researchTotalCost,totalSpeed,remainingUnits)) local returnSpeed = "---research-speed---\n"..totalSpeed.."\n" local returnTime = "---research-time---\n"..estimatedSeconds.."\n" local returnNameID = "---research-info---\n"..researchName.."\n" local returnProgress = "---research-progress---\n"..playerForce.research_progress.."\n" local returnCost = "---research-cost---\n"..researchTotalCost.."\n" log("Reseach remaining "..returnTime) return returnSpeed..returnTime..returnNameID..returnProgress..returnCost end function UpdateLabInfos() local totalLabs = 0 local totalSpeed = 0 totalLabs = #storage.labs for _, lab in pairs(storage.labs) do if lab.valid then if lab.status == defines.entity_status.working then local labBase if lab.name == "biolab" then labBase = biolabBaseSpeed else labBase = labBaseSpeed end local labSpeed = (labBase + (labBase * game.forces["player"].laboratory_speed_modifier)) * (lab.effects.speed or 1) totalSpeed = totalSpeed + (labSpeed* (1+(lab.effects.productivity or 0))) end end end storage.totalLabCount = totalLabs storage.totalResearchSpeed = totalSpeed end function SendResearchStats() if options.enableResearch == true then UpdateLabInfos() local researchTimeInfo = GetEstimatedResearchTime() if researchTimeInfo then helpers.send_udp(udpAddress, researchTimeInfo, serverIndex) end end end