Added Reserach Stats, still have to add power and research avg
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
storage.totalLabCount = 0
|
||||
local labBaseSpeed = 1
|
||||
local biolabBaseSpeed = 2
|
||||
|
||||
|
||||
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-playerForce.research_progress
|
||||
local remainingUnits = remainingPercentage*researchTotalCost
|
||||
local estimatedSeconds = remainingUnits/totalSpeed
|
||||
|
||||
local returnSpeed = "---research-speed---\n"..totalSpeed.."\n"
|
||||
local returnTime = "---research-time---\n"..estimatedSeconds.."\n"
|
||||
local returnNameID = "---research-info---\n"..researchName.."\n"
|
||||
|
||||
return returnSpeed..returnTime..returnNameID
|
||||
end
|
||||
|
||||
function UpdateLabInfos()
|
||||
local totalLabs = 0
|
||||
local totalSpeed = 0
|
||||
local totalProd = 0
|
||||
for _, surface in pairs(game.surfaces) do
|
||||
local labs = surface.find_entities_filtered{type="lab"}
|
||||
totalLabs = totalLabs + #labs
|
||||
for _, lab in pairs(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
|
||||
totalSpeed = totalSpeed + (labSpeed* (1+lab.effects.productivity))
|
||||
--local labSpeed = labBaseSpeed * lab.effects.speed
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
storage.totalLabCount = totalLabs
|
||||
storage.totalResearchSpeed = totalSpeed
|
||||
storage.totalReseachProductivity = totalProd
|
||||
end
|
||||
|
||||
function SendResearchStats()
|
||||
UpdateLabInfos()
|
||||
local researchTimeInfo = GetEstimatedResearchTime()
|
||||
if researchTimeInfo then
|
||||
helpers.send_udp(udpAddress, researchTimeInfo, serverIndex)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user