43 lines
1.3 KiB
Lua
43 lines
1.3 KiB
Lua
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))
|
|
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]))
|
|
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))
|
|
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
|
|
end
|
|
|
|
end
|
|
end
|
|
PowerGridScanned = true
|
|
end
|
|
|
|
|