Private
Public Access
1
0

Bump version to 0.1.6, add player kill tracking, and enhance power/lab stats handling

This commit is contained in:
Jan Grießhaber
2026-01-02 18:40:24 +01:00
parent 265f74814d
commit 0660a7642b
6 changed files with 143 additions and 53 deletions

View File

@@ -1,42 +1,63 @@
PowerGridScanned = false
function GetGlobalGridSurfaces()
local globalGrids = {}
for _,surface in pairs(game.surfaces) do
if(surface.has_global_electric_network) then
globalGrids[#globalGrids+1] = surface
end
--log("Surface: "..surface.name.." has global electric network: "..tostring(grids))
function AddPowerPole(event)
local e = event.entity
if e and e.valid and e.type == "electric-pole" then
storage.representativePoles[e.unit_number] = e
end
end
function UpdateGrids(event)
local entity = event.entity
local gridID = entity.electric_network_id
if gridID == nil then return end
storage.electricGrids[gridID] = (storage.electricGrids[gridID] or 0) + 1
log(("Network %d has counter of %d"):format(gridID,storage.electricGrids[gridID]))
function RemovePowerPole(event)
local e = event.entity
if e then
storage.representativePoles[e.unit_number] = nil
end
end
function PurgeNetworks()
for ID, Counter in pairs(storage.electricGrids) do
if Counter <= 0 then
table.remove(storage.electricGrids, ID)
log(("Removed electric network with id %d from list"):format(ID))
function GetNetworks()
local networks = {}
for _, pole in pairs(storage.representativePoles) do
if pole.valid then
local net = pole.electric_network_id
if net then
networks[net] = pole
end
end
end
return networks
end
function ScanNetworks()
storage.representative_poles = {}
for _, surface in pairs(game.surfaces) do
for _, pole in pairs(surface.find_entities_filtered{type = "electric-pole"}) do
if pole.valid and pole.electric_network_id then
storage.representativePoles[pole.unit_number] = pole
end
end
end
end
function GenerateNetworks()
if PowerGridScanned==false then
for _,surface in pairs(game.surfaces) do
for _, powerPole in pairs(surface.find_entities_filtered({filter = "type",type = "electric-pole"})) do
storage.electricGrids[powerPole.electric_network_id] = (storage.electricGrids[powerPole.electric_network_id] or 0) + 1
function SendPowerStats()
if options.enablePower then
local powerPart = {}
powerPart[#powerPart+1] = "---power-stats---\n"
for _, pole in pairs(GetNetworks()) do
if pole.valid and pole.type == "electric-pole" then
local input = pole.electric_network_statistics.input_counts
local output = pole.electric_network_statistics.output_counts
local surfaceName = pole.surface.name
for item,value in pairs(input) do
powerPart[#powerPart+1] = ("%s:%d:in:%s:%d"):format(surfaceName, pole.electric_network_id, item, value)
end
for item, value in pairs(output) do
powerPart[#powerPart+1] = ("%s:%d:out:%s:%d"):format(surfaceName,pole.electric_network_id, item, value)
end
end
end
helpers.send_udp(udpAddress,table.concat(powerPart,"\n"),serverIndex)
end
end
PowerGridScanned = true
end