This commit is contained in:
2025-02-24 18:40:38 +09:00
parent 32723e388b
commit 36c65cbea0

View File

@@ -32,7 +32,6 @@ local vlayer_data = {
items = {}, items = {},
power_items = {}, power_items = {},
energy = 0, energy = 0,
load = 0,
unallocated = {}, unallocated = {},
}, },
surface = table.deep_copy(config.surface), surface = table.deep_copy(config.surface),
@@ -505,12 +504,47 @@ local function handle_unallocated()
end end
end end
--- Calculate the current power load to provide a better view for the user
local function handle_circuit_power_load()
local processed = {}
local pi = 0
local po = 0
for _, v in pairs(spawn_pole) do
local e = game.surfaces[1].find_entity(v[1], { x = v[2], y = v[3] })
if e and e.valid and e.is_connected_to_electric_network() and e.electric_network_id and not processed[e.electric_network_id] then
local ens = e.electric_network_statistics
local ensi = 0
local enso = 0
for _, c in pairs(ens.input_counts) do
ensi = ensi + c
end
for _, c in pairs(ens.output_counts) do
enso = enso + c
end
processed[e.electric_network_id] = { i = ensi, o = enso }
end
end
for _, v in pairs(processed) do
pi = pi + v.i
po = po + v.o
end
return pi * 10000 / po
end
--- Get the statistics for the vlayer --- Get the statistics for the vlayer
function vlayer.get_statistics() function vlayer.get_statistics()
local vdp = vlayer_data.properties.production * mega local vdp = vlayer_data.properties.production * mega
local gdm = get_production_multiplier() local gdm = get_production_multiplier()
local gsm = get_sustained_multiplier() local gsm = get_sustained_multiplier()
local gald = get_actual_land_defecit() local gald = get_actual_land_defecit()
local cl = handle_circuit_power_load()
return { return {
total_surface_area = vlayer_data.properties.total_surface_area, total_surface_area = vlayer_data.properties.total_surface_area,
@@ -518,7 +552,7 @@ function vlayer.get_statistics()
remaining_surface_area = gald, remaining_surface_area = gald,
surface_area = vlayer_data.properties.total_surface_area - gald, surface_area = vlayer_data.properties.total_surface_area - gald,
production_multiplier = gdm, production_multiplier = gdm,
current_load = vlayer_data.storage.load, current_load = cl,
energy_max = vdp, energy_max = vdp,
energy_production = vdp * gdm, energy_production = vdp * gdm,
energy_total_production = vlayer_data.properties.total_production * gsm * mega, energy_total_production = vlayer_data.properties.total_production * gsm * mega,
@@ -588,40 +622,6 @@ function vlayer.create_circuit_interface(surface, position, circuit, last_user)
return interface return interface
end end
--- Calculate the current power load to provide a better view for the user
local function handle_circuit_power_load()
local processed = {}
local pi = 0
local po = 0
for _, v in pairs(spawn_pole) do
local e = game.surfaces[1].find_entity(v[1], { x = v[2], y = v[3] })
if e and e.valid and e.is_connected_to_electric_network() and e.electric_network_id and not processed[e.electric_network_id] then
local ens = e.electric_network_statistics
local ensi = 0
local enso = 0
for _, c in pairs(ens.input_counts) do
ensi = ensi + c
end
for _, c in pairs(ens.output_counts) do
enso = enso + c
end
processed[e.electric_network_id] = { i = ensi, o = enso }
end
end
for _, v in pairs(processed) do
pi = pi + v.i
po = po + v.o
end
vlayer_data.storage.load = pi * 10000 / po
end
--- Handle all circuit interfaces, updating their signals to match the vlayer statistics --- Handle all circuit interfaces, updating their signals to match the vlayer statistics
local function handle_circuit_interfaces() local function handle_circuit_interfaces()
local stats = vlayer.get_statistics() local stats = vlayer.get_statistics()
@@ -830,7 +830,6 @@ Event.on_nth_tick(config.update_tick_storage, function(_)
handle_input_interfaces() handle_input_interfaces()
handle_output_interfaces() handle_output_interfaces()
handle_unallocated() handle_unallocated()
handle_circuit_power_load()
end) end)
--- Handle all energy and circuit updates --- Handle all energy and circuit updates