mirror of
https://github.com/theFox6/microexpansion.git
synced 2024-09-12 07:58:30 +02:00
Wire up the rest for power.
This commit is contained in:
parent
8d84f7d77f
commit
53ab3c350f
@ -55,18 +55,24 @@ me.register_node("ctrl", {
|
||||
--HV_EU_supply = 144,
|
||||
--HV_EU_demand = 44,
|
||||
technic_run = function(pos, node)
|
||||
--local meta = minetest.get_meta(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
-- quick cheat sheet for how to wire:
|
||||
--meta:set_int("HV_EU_input", 23)
|
||||
--meta:set_int("HV_EU_demand", 45)
|
||||
--meta:set_int("HV_EU_supply", 1045)
|
||||
local net = me.get_network(pos)
|
||||
if not net then
|
||||
-- This is impossible, delete?
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("HV_EU_input", 0)
|
||||
return
|
||||
end
|
||||
net:update_demand()
|
||||
if net.input ~= meta:get_int("HV_EU_input") then
|
||||
net.input = meta:get_int("HV_EU_input")
|
||||
me.log("EU: input changed to "..net.input, "error")
|
||||
-- This only needs to see changes to inbound power levels.
|
||||
me.send_event(pos, "power")
|
||||
end
|
||||
end,
|
||||
connect_sides = "nobottom",
|
||||
me_update = function(pos,_,ev)
|
||||
@ -80,12 +86,14 @@ me.register_node("ctrl", {
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
local net = me.get_network(pos)
|
||||
--me.log("SWITCH: on", "error")
|
||||
-- turn OFF on mese power
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("enabled", 0)
|
||||
net:update_demand()
|
||||
end,
|
||||
action_off = function (pos, node)
|
||||
--me.log("SWITCH: off", "error")
|
||||
local net = me.get_network(pos)
|
||||
-- turn ON without mesepower
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -199,12 +207,14 @@ me.register_machine("cable", {
|
||||
if ev.type ~= "disconnect" then return end
|
||||
end
|
||||
--maybe this shouldn't be called on every update
|
||||
if false then
|
||||
local meta = minetest.get_meta(pos)
|
||||
if me.get_connected_network(pos) then
|
||||
meta:set_string("infotext", "Network connected")
|
||||
else
|
||||
meta:set_string("infotext", "No Network")
|
||||
end
|
||||
end
|
||||
end,
|
||||
machine = {
|
||||
type = "conductor",
|
||||
|
@ -529,48 +529,59 @@ end
|
||||
|
||||
-- Helper to check to see if the controller is on and powered.
|
||||
function network:powered(name)
|
||||
if not name and minetest.localplayer then
|
||||
-- this works for the client side only
|
||||
name = minetest.localplayer:get_name()
|
||||
-- todo: on the server side, how do we get the player name?
|
||||
end
|
||||
local net = self
|
||||
local meta = minetest.get_meta(net.controller_pos)
|
||||
local run = meta:get_int("enabled") == 1
|
||||
if not run then
|
||||
minetest.chat_send_player(name, "Please enable by turning controller switch.")
|
||||
if name then minetest.chat_send_player(name, "Please enable by turning controller switch.") end
|
||||
return false
|
||||
end
|
||||
--me.log("REMOTE: power level input is "..meta:get_int("HV_EU_input").." and demand is "..meta:get_int("HV_EU_demand"), "error")
|
||||
me.log("NETWORK: powered power level input is "..meta:get_int("HV_EU_input").." and demand is "..meta:get_int("HV_EU_demand"), "error")
|
||||
run = not technic or (meta:get_int("HV_EU_input") >= meta:get_int("HV_EU_demand") and meta:get_int("HV_EU_input") > 0)
|
||||
if not run then
|
||||
minetest.chat_send_player(name, "Please provide HV power to ME controller.")
|
||||
if name then minetest.chat_send_player(name, "Please provide HV power to ME controller.") end
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function network:update_demand()
|
||||
local demand = 60
|
||||
local pos = self.controller_pos
|
||||
local meta = minetest.get_meta(pos)
|
||||
local net = self
|
||||
if meta:get_int("enabled") == 0 then
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
meta:set_string("infotext", "Disabled")
|
||||
if meta:get_int("HV_EU_demand") ~= 0 then
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
meta:set_string("infotext", "Disabled")
|
||||
me.send_event(pos, "power")
|
||||
end
|
||||
return
|
||||
end
|
||||
local demand = 60 -- controller is 60
|
||||
for ipos in me.connected_nodes(pos) do
|
||||
local name = me.get_node(ipos).name
|
||||
if name == "microexpansion:cable" then
|
||||
demand = demand + 1
|
||||
demand = demand + 1 -- cables are 1
|
||||
elseif name == "microexpansion:interface" then
|
||||
local meta = minetest.get_meta(ipos)
|
||||
local inventories = minetest.deserialize(meta:get_string("connected"))
|
||||
demand = demand + #inventories * 10 + 20
|
||||
demand = demand + #inventories * 10 + 20 -- interfaces are 20 and 10 for each machine or inventory
|
||||
else
|
||||
demand = demand + 10
|
||||
demand = demand + 10 -- everything else is 10
|
||||
end
|
||||
end
|
||||
if meta:get_int("HV_EU_demand") ~= demand then
|
||||
local name = meta:get_string("owner")
|
||||
meta:set_string("infotext", "Network Controller (owned by "..name..")")
|
||||
me.log("NET: demand changed to "..demand, "error")
|
||||
meta:set_int("HV_EU_demand", demand)
|
||||
me.send_event(pos, "power")
|
||||
end
|
||||
--me.log("NET: demand is "..demand, "error")
|
||||
meta:set_int("HV_EU_demand", demand)
|
||||
end
|
||||
|
||||
-- We don't save this data, rather we rewalk upon first use. If 1% of
|
||||
|
@ -63,6 +63,12 @@ local function chest_formspec(pos, start_id, listname, page_max, q)
|
||||
"/" .. page_max .."]"
|
||||
end
|
||||
|
||||
if net and not net:powered() then
|
||||
list = "label[3,2;" .. minetest.colorize("red", "No power!") .. "]"
|
||||
buttons = ""
|
||||
page_number = ""
|
||||
end
|
||||
|
||||
return [[
|
||||
size[9,12.5]
|
||||
]]..
|
||||
@ -126,13 +132,13 @@ me.register_node("cmonitor", {
|
||||
local own_inv = meta:get_inventory()
|
||||
|
||||
local net = me.get_connected_network(pos)
|
||||
me.send_event(pos,"connect",{net=net})
|
||||
me.send_event(pos, "connect", {net=net})
|
||||
if net then
|
||||
update_chest(pos)
|
||||
end
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
me.send_event(pos,"disconnect")
|
||||
me.send_event(pos, "disconnect")
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
return true
|
||||
|
@ -89,6 +89,12 @@ local function chest_formspec(pos, start_id, listname, page_max, q, c)
|
||||
"/" .. page_max .."]"
|
||||
end
|
||||
|
||||
if net and not net:powered() then
|
||||
list = "label[3,2;" .. minetest.colorize("red", "No power!") .. "]"
|
||||
buttons = ""
|
||||
page_number = ""
|
||||
end
|
||||
|
||||
return [[
|
||||
size[9,12.5]
|
||||
]]..
|
||||
@ -105,6 +111,7 @@ local function chest_formspec(pos, start_id, listname, page_max, q, c)
|
||||
end
|
||||
|
||||
local function update_chest(pos,_,ev)
|
||||
--me.log("CTERM: got event "..((ev and ev.type) or "<null>"), "error")
|
||||
--for now all events matter
|
||||
|
||||
local net = me.get_connected_network(pos)
|
||||
@ -259,7 +266,7 @@ end
|
||||
|
||||
|
||||
function me.register_output_to_inputs(output, inputs)
|
||||
me.log("REG: output "..output.." from inputs "..dump(inputs))
|
||||
--me.log("REG: output "..output.." from inputs "..dump(inputs))
|
||||
me.map_output_to_inputs[output] = inputs
|
||||
end
|
||||
|
||||
@ -455,7 +462,6 @@ me.register_node("cterminal", {
|
||||
me_update = update_chest,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", chest_formspec(pos, 1))
|
||||
meta:set_string("inv_name", "none")
|
||||
meta:set_int("page", 1)
|
||||
|
||||
@ -465,13 +471,11 @@ me.register_node("cterminal", {
|
||||
own_inv:set_size("output", 1)
|
||||
|
||||
local net = me.get_connected_network(pos)
|
||||
me.send_event(pos,"connect",{net=net})
|
||||
if net then
|
||||
update_chest(pos)
|
||||
end
|
||||
me.send_event(pos, "connect", {net=net})
|
||||
update_chest(pos)
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
me.send_event(pos,"disconnect")
|
||||
me.send_event(pos, "disconnect")
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -727,8 +731,8 @@ me.register_node("cterminal", {
|
||||
meta:set_string("formspec", chest_formspec(pos, page - 32, inv_name, page_max, fields.filter, crafts))
|
||||
elseif fields.crafts then
|
||||
meta:set_int("page", 1)
|
||||
-- me.log("CRAFT: craftables: "..dump(net and net.process), "error")
|
||||
me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||
--me.log("CRAFT: craftables: "..dump(net and net.process), "error")
|
||||
--me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||
inv_name = "main"
|
||||
if fields.crafts == "true" then
|
||||
crafts = true
|
||||
@ -783,7 +787,7 @@ me.register_node("cterminal", {
|
||||
end
|
||||
elseif fields.search or fields.key_enter_field == "filter" then
|
||||
own_inv:set_size("search", 0)
|
||||
me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||
--me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||
meta:set_int("page", 1)
|
||||
inv_name = "main"
|
||||
inv = ctrl_inv
|
||||
@ -809,7 +813,7 @@ me.register_node("cterminal", {
|
||||
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.filter, crafts))
|
||||
end
|
||||
elseif fields.clear then
|
||||
me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||
--me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||
own_inv:set_size("search", 0)
|
||||
own_inv:set_size("crafts", 0)
|
||||
meta:set_int("page", 1)
|
||||
|
@ -230,7 +230,7 @@ local function take_all(pos,net)
|
||||
end
|
||||
|
||||
net:update()
|
||||
me.send_event(pos,"items")
|
||||
me.send_event(pos, "items")
|
||||
end
|
||||
|
||||
local function add_all(pos,net)
|
||||
@ -256,7 +256,7 @@ local function add_all(pos,net)
|
||||
end
|
||||
|
||||
net:update()
|
||||
me.send_event(pos,"items",{net = net})
|
||||
me.send_event(pos, "items", {net = net})
|
||||
end
|
||||
|
||||
function me.disconnect_drive(pos,ncpos)
|
||||
@ -354,7 +354,7 @@ microexpansion.register_node("drive", {
|
||||
]])
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 10)
|
||||
me.send_event(pos,"connect")
|
||||
me.send_event(pos, "connect")
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
if minetest.is_protected(pos, player) then
|
||||
@ -365,7 +365,7 @@ microexpansion.register_node("drive", {
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
me.send_event(pos,"disconnect")
|
||||
me.send_event(pos, "disconnect")
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, _, _, stack, player)
|
||||
if minetest.is_protected(pos, player)
|
||||
@ -375,7 +375,7 @@ microexpansion.register_node("drive", {
|
||||
return 1
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, _, _, stack)
|
||||
me.send_event(pos,"item_cap")
|
||||
me.send_event(pos, "item_cap")
|
||||
local network = me.get_connected_network(pos)
|
||||
if network == nil then
|
||||
return
|
||||
@ -384,7 +384,7 @@ microexpansion.register_node("drive", {
|
||||
local items = minetest.deserialize(stack:get_meta():get_string("items"))
|
||||
if items == nil then
|
||||
print("no items")
|
||||
me.send_event(pos,"items",{net=network})
|
||||
me.send_event(pos, "items", {net=network})
|
||||
return
|
||||
end
|
||||
-- network:set_storage_space(#items)
|
||||
@ -393,7 +393,7 @@ microexpansion.register_node("drive", {
|
||||
me.insert_item(stack, network, ctrl_inv, "main")
|
||||
end
|
||||
network:set_storage_space(true)
|
||||
me.send_event(pos,"items",{net=network})
|
||||
me.send_event(pos, "items", {net=network})
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos,_,_,stack, player) --args: pos, listname, index, stack, player
|
||||
if minetest.is_protected(pos, player) then
|
||||
@ -408,7 +408,7 @@ microexpansion.register_node("drive", {
|
||||
if network == nil then
|
||||
return
|
||||
end
|
||||
me.send_event(pos,"item_cap",{net=network})
|
||||
me.send_event(pos, "item_cap", {net=network})
|
||||
local ctrl_inv = network:get_inventory()
|
||||
local items = minetest.deserialize(stack:get_meta():get_string("items"))
|
||||
if items == nil then
|
||||
@ -427,6 +427,6 @@ microexpansion.register_node("drive", {
|
||||
--print(stack:to_string())
|
||||
|
||||
network:update()
|
||||
me.send_event(pos,"items",{net=network})
|
||||
me.send_event(pos, "items", {net=network})
|
||||
end,
|
||||
})
|
||||
|
@ -56,11 +56,40 @@ function me.walk_connected(pos)
|
||||
return nodes
|
||||
end
|
||||
|
||||
local function chest_formspec(pos)
|
||||
local net = me.get_connected_network(pos)
|
||||
local list
|
||||
list = [[
|
||||
list[context;import;0,0.3;9,1]
|
||||
list[context;export;0,0.3;9,1]
|
||||
list[current_player;main;0,3.5;8,1;]
|
||||
list[current_player;main;0,4.73;8,3;8]
|
||||
listring[current_name;import]
|
||||
listring[current_player;main]
|
||||
]]
|
||||
|
||||
if net and not net:powered() then
|
||||
list = "label[3,2;" .. minetest.colorize("red", "No power!") .. "]"
|
||||
end
|
||||
|
||||
local formspec =
|
||||
"size[9,7.5]"..
|
||||
microexpansion.gui_bg ..
|
||||
microexpansion.gui_slots ..
|
||||
"label[0,-0.23;ME Interface]" ..
|
||||
list
|
||||
return formspec
|
||||
end
|
||||
|
||||
local function update(pos,_,ev)
|
||||
--me.log("INTERFACE: got event "..((ev and ev.type) or "<null>"), "error")
|
||||
if ev.type == "connect" then
|
||||
-- net.update_counts()
|
||||
elseif ev.type == "disconnect" then
|
||||
--
|
||||
elseif ev.type == "power" then
|
||||
local int_meta = minetest.get_meta(pos)
|
||||
int_meta:set_string("formspec", chest_formspec(pos))
|
||||
end
|
||||
end
|
||||
|
||||
@ -95,7 +124,7 @@ function me.reload_interface(net, pos, doinventories)
|
||||
local inv = int_meta:get_inventory()
|
||||
local inventories = minetest.deserialize(int_meta:get_string("connected"))
|
||||
-- not appropriate
|
||||
-- me.send_event(pos,"connect")
|
||||
-- me.send_event(pos, "connect")
|
||||
int_meta:set_string("infotext", "chests: "..#inventories)
|
||||
if not net.counts then
|
||||
net.counts = {}
|
||||
@ -156,20 +185,7 @@ me.register_node("interface", {
|
||||
me_update = update,
|
||||
on_construct = function(pos)
|
||||
local int_meta = minetest.get_meta(pos)
|
||||
int_meta:set_string("formspec",
|
||||
"size[9,7.5]"..
|
||||
microexpansion.gui_bg ..
|
||||
microexpansion.gui_slots ..
|
||||
[[
|
||||
label[0,-0.23;ME Interface]
|
||||
list[context;import;0,0.3;9,1]
|
||||
list[context;export;0,0.3;9,1]
|
||||
list[current_player;main;0,3.5;8,1;]
|
||||
list[current_player;main;0,4.73;8,3;8]
|
||||
listring[current_name;import]
|
||||
listring[current_player;main]
|
||||
field_close_on_enter[filter;false]
|
||||
]])
|
||||
int_meta:set_string("formspec", chest_formspec(pos))
|
||||
local inv = int_meta:get_inventory()
|
||||
inv:set_size("export", 3)
|
||||
inv:set_size("import", 3)
|
||||
@ -182,6 +198,7 @@ me.register_node("interface", {
|
||||
return
|
||||
end
|
||||
me.reload_interface(net, pos, true)
|
||||
net:update_demand()
|
||||
end,
|
||||
can_dig = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -267,9 +284,10 @@ me.register_node("interface", {
|
||||
end
|
||||
end
|
||||
end
|
||||
net:update_demand()
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
me.send_event(pos,"disconnect")
|
||||
me.send_event(pos, "disconnect")
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack)
|
||||
return stack:get_count()
|
||||
|
@ -59,6 +59,12 @@ local function chest_formspec(pos, start_id, listname, page_max, q)
|
||||
"/" .. page_max .."]"
|
||||
end
|
||||
|
||||
if net and not net:powered() then
|
||||
list = "label[3,2;" .. minetest.colorize("red", "No power!") .. "]"
|
||||
buttons = ""
|
||||
page_number = ""
|
||||
end
|
||||
|
||||
return [[
|
||||
size[9,9.5]
|
||||
]]..
|
||||
@ -117,7 +123,6 @@ me.register_node("term", {
|
||||
me_update = update_chest,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("formspec", chest_formspec(pos, 1))
|
||||
meta:set_string("inv_name", "none")
|
||||
meta:set_int("page", 1)
|
||||
|
||||
@ -125,13 +130,11 @@ me.register_node("term", {
|
||||
own_inv:set_size("src", 1)
|
||||
|
||||
local net = me.get_connected_network(pos)
|
||||
me.send_event(pos,"connect",{net=net})
|
||||
if net then
|
||||
update_chest(pos)
|
||||
end
|
||||
me.send_event(pos, "connect", {net=net})
|
||||
update_chest(pos)
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
me.send_event(pos,"disconnect")
|
||||
me.send_event(pos, "disconnect")
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
-- TODO: Check capacity, only allow if room
|
||||
|
Loading…
Reference in New Issue
Block a user