76 lines
2.6 KiB
Lua
76 lines
2.6 KiB
Lua
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 totalSpeed = GetCurrentResearchSpeed()
|
|
|
|
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 GetCurrentResearchSpeed()
|
|
local totalResearch = 0
|
|
local playerForce = game.forces["player"]
|
|
if not playerForce then return end
|
|
for _,surface in pairs(game.surfaces) do
|
|
totalResearch = totalResearch + playerForce.get_item_production_statistics(surface).get_flow_count({name = "science", category = "input",precision_index = defines.flow_precision_index.five_seconds})
|
|
end
|
|
return totalResearch
|
|
end
|
|
|
|
function SendResearchStats()
|
|
if options.enableResearch == true then
|
|
local researchTimeInfo = GetEstimatedResearchTime()
|
|
if researchTimeInfo then
|
|
SendChunked(researchTimeInfo)
|
|
end
|
|
end
|
|
end |