Add helper function get_relpos
parent
26983f5e88
commit
e8d2062895
13
networks.lua
13
networks.lua
|
@ -27,6 +27,8 @@ local NumNodes = 0 -- Used to determine the number of network nodes
|
||||||
local Flip = tubelib2.Turn180Deg
|
local Flip = tubelib2.Turn180Deg
|
||||||
local get_nodename = networks.get_nodename
|
local get_nodename = networks.get_nodename
|
||||||
local get_node = networks.get_node
|
local get_node = networks.get_node
|
||||||
|
local tubelib2_get_pos = tubelib2.get_pos
|
||||||
|
local tubelib2_side_to_dir = tubelib2.side_to_dir
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Debugging
|
-- Debugging
|
||||||
|
@ -426,6 +428,17 @@ networks.net_def = net_def
|
||||||
-- F |
|
-- F |
|
||||||
-- D
|
-- D
|
||||||
--
|
--
|
||||||
|
|
||||||
|
-- Determine the pos relative to the given 'pos', 'param2'
|
||||||
|
-- and the path based on 'sides' like "FUL"
|
||||||
|
function networks.get_relpos(pos, sides, param2)
|
||||||
|
local pos1 = {x = pos.x, y = pos.y, z = pos.z}
|
||||||
|
for side in sides:gmatch(".") do
|
||||||
|
pos1 = tubelib2_get_pos(pos1, tubelib2_side_to_dir(side, param2))
|
||||||
|
end
|
||||||
|
return pos1
|
||||||
|
end
|
||||||
|
|
||||||
-- networks.side_to_outdir(pos, side)
|
-- networks.side_to_outdir(pos, side)
|
||||||
networks.side_to_outdir = side_to_outdir
|
networks.side_to_outdir = side_to_outdir
|
||||||
|
|
||||||
|
|
|
@ -52,24 +52,22 @@ local function print_sides(pos, api, netw_type)
|
||||||
print("# " .. api .. " - " .. netw_type .. " dirs: " .. table.concat(t, ", "))
|
print("# " .. api .. " - " .. netw_type .. " dirs: " .. table.concat(t, ", "))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function print_power_network_data(pos, api, netw, netw_type)
|
local function print_power_network_data(pos, api, netw_type, outdir)
|
||||||
local tlib2 = networks.registered_networks[api][netw_type]
|
local tlib2 = networks.registered_networks[api][netw_type]
|
||||||
local outdir = netw[netw_type].ntype == "junc" and 0 or nil
|
|
||||||
local data = power.get_network_data(pos, tlib2, outdir)
|
local data = power.get_network_data(pos, tlib2, outdir)
|
||||||
|
local netw = networks.get_network_table(pos, tlib2, outdir)
|
||||||
if netw then
|
if netw then
|
||||||
print("- Number of network nodes: " .. (netw.num_nodes or 0))
|
print(" - Number of network nodes: " .. (netw.num_nodes or 0))
|
||||||
print("- Number of generators: " .. #(netw.gen or {}))
|
print(" - Number of generators: " .. #(netw.gen or {}))
|
||||||
print("- Number of consumers: " .. #(netw.con or {}))
|
print(" - Number of consumers: " .. #(netw.con or {}))
|
||||||
print("- Number of storage systems: " .. #(netw.sto or {}))
|
print(" - Number of storage systems: " .. #(netw.sto or {}))
|
||||||
end
|
end
|
||||||
if data then
|
if data then
|
||||||
local s = string.format("- Netw %u: generated = %u/%u, consumed = %u, storage load = %u/%u",
|
local s = string.format(" - Netw %u: generated = %u/%u, consumed = %u, storage load = %u/%u",
|
||||||
data.netw_num, round(data.provided),
|
data.netw_num, round(data.provided),
|
||||||
data.available, round(data.consumed),
|
data.available, round(data.consumed),
|
||||||
round(data.curr_load), round(data.max_capa))
|
round(data.curr_load), round(data.max_capa))
|
||||||
print(s)
|
print(s)
|
||||||
else
|
|
||||||
print("- Node has no '" .. netw_type .. "' network!!!")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,6 +90,8 @@ local function print_netID(pos, api, netw_type)
|
||||||
print("- " .. s .. ": netwNum for '" .. netw_type .. "': " .. networks.netw_num(netID))
|
print("- " .. s .. ": netwNum for '" .. netw_type .. "': " .. networks.netw_num(netID))
|
||||||
if api == "liquid" then
|
if api == "liquid" then
|
||||||
print_liquid_network_data(pos, api, netw_type, outdir)
|
print_liquid_network_data(pos, api, netw_type, outdir)
|
||||||
|
elseif api == "power" then
|
||||||
|
print_power_network_data(pos, api, netw_type, outdir)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print("- " .. s .. ": Node has no '" .. netw_type .. "' netID!!!")
|
print("- " .. s .. ": Node has no '" .. netw_type .. "' netID!!!")
|
||||||
|
@ -150,9 +150,6 @@ local function debug_print(pos)
|
||||||
for netw_type,api in pairs(NetwTypes) do
|
for netw_type,api in pairs(NetwTypes) do
|
||||||
if ndef.networks[netw_type] then
|
if ndef.networks[netw_type] then
|
||||||
print_sides(pos, api, netw_type)
|
print_sides(pos, api, netw_type)
|
||||||
if api == "power" then
|
|
||||||
print_power_network_data(pos, api, ndef.networks, netw_type)
|
|
||||||
end
|
|
||||||
print_netID(pos, api, netw_type)
|
print_netID(pos, api, netw_type)
|
||||||
print_secondary_node(pos, api, netw_type)
|
print_secondary_node(pos, api, netw_type)
|
||||||
print_valid_sides(node.name, api, netw_type)
|
print_valid_sides(node.name, api, netw_type)
|
||||||
|
|
Loading…
Reference in New Issue