Generators: Show network overload

This commit is contained in:
Joachim Stolberg 2020-12-04 17:52:27 +01:00
parent 81852ec210
commit dd462aa220
15 changed files with 44 additions and 20 deletions

View File

@ -35,7 +35,7 @@ local function formspec(self, pos, nvm)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
"image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
end end

View File

@ -32,7 +32,7 @@ local function formspec(self, pos, nvm)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
"image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
end end

View File

@ -49,7 +49,7 @@ local function formspec(self, pos, nvm)
default.gui_slots.. default.gui_slots..
"box[0,-0.1;4.8,0.5;#c6e8ff]".. "box[0,-0.1;4.8,0.5;#c6e8ff]"..
"label[1,-0.1;"..minetest.colorize("#000000", S("Digtron Battery")).."]".. "label[1,-0.1;"..minetest.colorize("#000000", S("Digtron Battery")).."]"..
power.formspec_label_bar(0, 0.8, S("Load"), TOTAL_MAX, total, S("Coal Equivalents")).. power.formspec_label_bar(pos, 0, 0.8, S("Load"), TOTAL_MAX, total, S("Coal Equivalents"))..
"image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.6,2;1,1;"..self:get_state_tooltip(nvm).."]".. "tooltip[2.6,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"image[3.75,2;1,1;"..techage.get_power_image(pos, nvm).."]" "image[3.75,2;1,1;"..techage.get_power_image(pos, nvm).."]"

View File

@ -32,7 +32,7 @@ local function formspec(self, pos, nvm)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
power.formspec_label_bar(0, 0.8, S("Electricity"), PWR_CAPA, nvm.provided).. power.formspec_label_bar(pos, 0, 0.8, S("Electricity"), PWR_CAPA, nvm.provided)..
"image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
end end

View File

@ -44,8 +44,8 @@ local function formspec(self, pos, nvm)
default.gui_slots.. default.gui_slots..
"box[0,-0.1;5.8,0.5;#c6e8ff]".. "box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[2,-0.1;"..minetest.colorize( "#000000", S("Heat Exchanger")).."]".. "label[2,-0.1;"..minetest.colorize( "#000000", S("Heat Exchanger")).."]"..
power.formspec_label_bar(0, 0.8, S("Electricity"), needed_max, needed).. power.formspec_label_bar(pos, 0, 0.8, S("Electricity"), needed_max, needed)..
power.formspec_label_bar(3.5, 0.8, S("Thermal"), capa_max, capa, "").. power.formspec_label_bar(pos, 3.5, 0.8, S("Thermal"), capa_max, capa, "")..
arrow.. arrow..
"image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]" "tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]"

View File

@ -111,7 +111,7 @@ local function process(inv, recipe, output)
if recipe.waste then if recipe.waste then
local leftover = inv:add_item("dst", ItemStack(recipe.waste)) local leftover = inv:add_item("dst", ItemStack(recipe.waste))
if leftover:get_count() > 0 then if leftover:get_count() > 0 then
inv:set_list("src", leftover) inv:add_item("src", leftover)
return techage.BLOCKED return techage.BLOCKED
end end
end end

View File

@ -44,7 +44,7 @@ local function formspec(self, pos, nvm)
default.gui_slots.. default.gui_slots..
"box[0,-0.1;5.8,0.5;#c6e8ff]".. "box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Electrolyzer")).."]".. "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Electrolyzer")).."]"..
techage.power.formspec_label_bar(0.1, 0.8, S("Electricity"), PWR_NEEDED, nvm.taken).. techage.power.formspec_label_bar(pos, 0.1, 0.8, S("Electricity"), PWR_NEEDED, nvm.taken)..
arrow.. arrow..
"image_button[3,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[3,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3,2.5;1,1;"..self:get_state_tooltip(nvm).."]".. "tooltip[3,2.5;1,1;"..self:get_state_tooltip(nvm).."]"..

View File

@ -48,7 +48,7 @@ local function formspec(self, pos, nvm)
arrow.. arrow..
"image_button[2,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2,2.5;1,1;"..self:get_state_tooltip(nvm).."]".. "tooltip[2,2.5;1,1;"..self:get_state_tooltip(nvm).."]"..
techage.power.formspec_label_bar(3.5, 0.8, S("Electricity"), PWR_CAPA, nvm.given) techage.power.formspec_label_bar(pos, 3.5, 0.8, S("Electricity"), PWR_CAPA, nvm.given)
end end
local function start_node(pos, nvm, state) local function start_node(pos, nvm, state)

View File

@ -48,11 +48,24 @@ function techage.power.formspec_power_bar(max_power, current_power)
return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png" return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png"
end end
function techage.power.formspec_label_bar(x, y, label, max_power, current_power, unit) function techage.power.formspec_label_bar(pos, x, y, label, max_power, current_power, unit)
local percent, ypos local percent, ypos
current_power = current_power or 0
max_power = max_power or 1 max_power = max_power or 1
unit = unit or "ku" unit = unit or "ku"
if current_power == 0 then
-- check if power network is overloaded
if techage.power.network_overloaded(pos, techage.ElectricCable) then
return "container["..x..","..y.."]"..
"box[0,0;2.3,3.3;#395c74]"..
"label[0.2,0;"..label.."]"..
"label[0.7,0.4;"..max_power.." "..unit.."]"..
"image[0,0.5;1,3;techage_form_level_red_fg.png]"..
"container_end[]"
end
end
current_power = current_power or 0
if current_power == 0 then if current_power == 0 then
percent = 0 percent = 0
ypos = 2.8 ypos = 2.8

View File

@ -148,6 +148,17 @@ function techage.power.power_available(pos, Cable)
return netw and netw.on and netw.alive and netw.alive > 0 return netw and netw.on and netw.alive and netw.alive > 0
end end
function techage.power.network_overloaded(pos, Cable)
local nvm = techage.get_nvm(pos)
local tlib_type = Cable.tube_type
local netID = nvm[Cable.tube_type] and nvm[Cable.tube_type]["netID"]
local netw = networks.has_network(tlib_type, netID)
if netw then
local sum = (netw.available1 or 0) + (netw.available2 or 0)
return sum > 0 and sum < (netw.needed1 or 0)
end
end
-- this is more a try to start, the start will be performed by on_power() -- this is more a try to start, the start will be performed by on_power()
function techage.power.consumer_start(pos, Cable, cycle_time) function techage.power.consumer_start(pos, Cable, cycle_time)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)

View File

@ -129,10 +129,10 @@ local function formspec(pos, nvm)
"box[0,-0.1;9.8,0.5;#c6e8ff]".. "box[0,-0.1;9.8,0.5;#c6e8ff]"..
"label[4,-0.1;"..minetest.colorize( "#000000", S("Network Data")).."]".. "label[4,-0.1;"..minetest.colorize( "#000000", S("Network Data")).."]"..
"label[9.5,-0.1;"..minetest.colorize( "#000000", star).."]".. "label[9.5,-0.1;"..minetest.colorize( "#000000", star).."]"..
power.formspec_label_bar(0, 0.7, S("Genera. 1"), gen1.pow_act, gen1.pow_used).. power.formspec_label_bar(pos, 0, 0.7, S("Genera. 1"), gen1.pow_act, gen1.pow_used)..
power.formspec_label_bar(2.5, 0.7, S("Genera. 2"), gen2.pow_act, gen2.pow_used).. power.formspec_label_bar(pos, 2.5, 0.7, S("Genera. 2"), gen2.pow_act, gen2.pow_used)..
power.formspec_label_bar(5, 0.7, S("Consum. 2"), con2.pow_act, con2.pow_used).. power.formspec_label_bar(pos, 5, 0.7, S("Consum. 2"), con2.pow_act, con2.pow_used)..
power.formspec_label_bar(7.5, 0.7, S("Consum. 1"), con1.pow_act, con1.pow_used).. power.formspec_label_bar(pos, 7.5, 0.7, S("Consum. 1"), con1.pow_act, con1.pow_used)..
"box[0,4.3;9.8,0.4;#c6e8ff]".. "box[0,4.3;9.8,0.4;#c6e8ff]"..
"box[0,4.85;9.8,0.4;#395c74]".. "box[0,4.85;9.8,0.4;#395c74]"..
"box[0,5.35;9.8,0.4;#395c74]".. "box[0,5.35;9.8,0.4;#395c74]"..

View File

@ -67,8 +67,8 @@ local function formspec(self, pos, nvm)
default.gui_slots.. default.gui_slots..
"box[0,-0.1;5.8,0.5;#c6e8ff]".. "box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Inverter")).."]".. "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Inverter")).."]"..
power.formspec_label_bar(0, 0.8, S("Power DC"), PWR_PERF, max_power).. power.formspec_label_bar(pos, 0, 0.8, S("Power DC"), PWR_PERF, max_power)..
power.formspec_label_bar(3.5, 0.8, S("Power AC"), max_power, delivered).. power.formspec_label_bar(pos, 3.5, 0.8, S("Power AC"), max_power, delivered)..
arrow.. arrow..
"image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]" "tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]"

View File

@ -38,7 +38,7 @@ local function formspec(self, pos, nvm)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
"image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
end end

View File

@ -36,7 +36,7 @@ local function formspec(self, pos, nvm)
default.gui_slots.. default.gui_slots..
"box[0,-0.1;4.8,0.5;#c6e8ff]".. "box[0,-0.1;4.8,0.5;#c6e8ff]"..
"label[1,-0.1;"..minetest.colorize( "#000000", S("TA3 Akku Box")).."]".. "label[1,-0.1;"..minetest.colorize( "#000000", S("TA3 Akku Box")).."]"..
power.formspec_label_bar(0, 0.8, S("Load"), PWR_CAPA, capa).. power.formspec_label_bar(pos, 0, 0.8, S("Load"), PWR_CAPA, capa)..
"image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3,2;1,1;"..self:get_state_tooltip(nvm).."]".. "tooltip[3,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"label[3.7,1.2;"..S("Electricity").."]".. "label[3.7,1.2;"..S("Electricity").."]"..

View File

@ -39,7 +39,7 @@ local function formspec(self, pos, nvm)
"image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]".. "image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]"..
"image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]".. "tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]"..
power.formspec_label_bar(2.5, 0.8, S("Electricity"), PWR_CAPA, nvm.provided) power.formspec_label_bar(pos, 2.5, 0.8, S("Electricity"), PWR_CAPA, nvm.provided)
end end
local function play_sound(pos) local function play_sound(pos)