Prepare for lib 'networks'
This commit is contained in:
parent
288472d20d
commit
282f52d77e
@ -21,7 +21,8 @@ local PWR_NEEDED = 5
|
|||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
--local Cable = techage.Axle
|
||||||
|
local power = networks.power
|
||||||
|
|
||||||
local function swap_node(pos, name)
|
local function swap_node(pos, name)
|
||||||
local node = techage.get_node_lvm(pos)
|
local node = techage.get_node_lvm(pos)
|
||||||
@ -32,39 +33,18 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_power(pos)
|
|
||||||
--print("on_power sink "..P2S(pos))
|
|
||||||
swap_node(pos, "techage:sink_on")
|
|
||||||
M(pos):set_string("infotext", "on")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_nopower(pos)
|
|
||||||
--print("on_nopower sink "..P2S(pos))
|
|
||||||
swap_node(pos, "techage:sink")
|
|
||||||
M(pos):set_string("infotext", "off")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
|
||||||
--print("node_timer sink "..P2S(pos))
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_rightclick(pos, node, clicker)
|
local function on_rightclick(pos, node, clicker)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
if not nvm.running and power.power_available(pos, Cable) then
|
if not nvm.running and power.power_available(pos, Cable) then
|
||||||
nvm.running = true
|
nvm.running = true
|
||||||
-- swap will be performed via on_power()
|
swap_node(pos, "techage:sink_on")
|
||||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
M(pos):set_string("infotext", "on")
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
M(pos):set_string("infotext", "...")
|
|
||||||
else
|
else
|
||||||
nvm.running = false
|
nvm.running = false
|
||||||
swap_node(pos, "techage:sink")
|
swap_node(pos, "techage:sink")
|
||||||
power.consumer_stop(pos, Cable)
|
|
||||||
minetest.get_node_timer(pos):stop()
|
|
||||||
M(pos):set_string("infotext", "off")
|
M(pos):set_string("infotext", "off")
|
||||||
|
minetest.get_node_timer(pos):stop()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -79,30 +59,21 @@ local function after_dig_node(pos, oldnode)
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
|
||||||
power.update_network(pos, outdir, tlib2)
|
|
||||||
end
|
|
||||||
|
|
||||||
local net_def = {
|
|
||||||
ele1 = {
|
|
||||||
sides = techage.networks.AllSides, -- Cable connection sides
|
|
||||||
ntype = "con1",
|
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
nominal = PWR_NEEDED,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:sink", {
|
minetest.register_node("techage:sink", {
|
||||||
description = "Sink",
|
description = "Sink",
|
||||||
tiles = {'techage_electric_button.png'},
|
tiles = {'techage_electric_button.png'},
|
||||||
|
|
||||||
on_timer = node_timer,
|
on_timer = function(pos, elapsed)
|
||||||
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
|
if consumed == PWR_NEEDED then
|
||||||
|
swap_node(pos, "techage:sink_on")
|
||||||
|
M(pos):set_string("infotext", "on")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
networks = net_def,
|
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
light_source = 0,
|
light_source = 0,
|
||||||
@ -116,12 +87,17 @@ minetest.register_node("techage:sink_on", {
|
|||||||
description = "Sink",
|
description = "Sink",
|
||||||
tiles = {'techage_electric_button.png'},
|
tiles = {'techage_electric_button.png'},
|
||||||
|
|
||||||
on_timer = node_timer,
|
on_timer = function(pos, elapsed)
|
||||||
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
|
if consumed < PWR_NEEDED then
|
||||||
|
swap_node(pos, "techage:sink")
|
||||||
|
M(pos):set_string("infotext", "off")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
on_rightclick = on_rightclick,
|
on_rightclick = on_rightclick,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
networks = net_def,
|
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
light_source = minetest.LIGHT_MAX,
|
light_source = minetest.LIGHT_MAX,
|
||||||
@ -133,5 +109,4 @@ minetest.register_node("techage:sink_on", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"techage:sink", "techage:sink_on"})
|
power.register_nodes({"techage:sink", "techage:sink_on"}, Cable, "con")
|
||||||
|
|
||||||
|
@ -27,10 +27,17 @@ local M = minetest.get_meta
|
|||||||
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
||||||
local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end
|
local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end
|
||||||
|
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
local networks = techage.networks
|
local liquid = networks.liquid
|
||||||
local Pipe = techage.LiquidPipe
|
local CYCLE_TIME = 2
|
||||||
local liquid = techage.liquid
|
|
||||||
|
local function get_keys(tbl)
|
||||||
|
local keys = {}
|
||||||
|
for k,v in pairs(tbl) do
|
||||||
|
keys[#keys + 1] = k
|
||||||
|
end
|
||||||
|
return keys
|
||||||
|
end
|
||||||
|
|
||||||
local function has_power(pos, nvm, state)
|
local function has_power(pos, nvm, state)
|
||||||
local crd = CRD(pos)
|
local crd = CRD(pos)
|
||||||
@ -38,37 +45,44 @@ local function has_power(pos, nvm, state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function start_node(pos, nvm, state)
|
local function start_node(pos, nvm, state)
|
||||||
local crd = CRD(pos)
|
|
||||||
power.consumer_start(pos, crd.power_netw, crd.cycle_time)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_node(pos, nvm, state)
|
local function stop_node(pos, nvm, state)
|
||||||
local crd = CRD(pos)
|
|
||||||
power.consumer_stop(pos, crd.power_netw)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_power(pos)
|
local function node_timer_pas(pos, elapsed)
|
||||||
local crd = CRD(pos)
|
local crd = CRD(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
|
||||||
|
-- handle power consumption
|
||||||
|
if crd.power_netw and techage.needs_power(nvm) then
|
||||||
|
local consumed = power.consume_power(pos, crd.power_netw, nil, crd.power_consumption)
|
||||||
|
if consumed == crd.power_consumption then
|
||||||
crd.State:start(pos, nvm)
|
crd.State:start(pos, nvm)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
return crd.State:is_active(nvm)
|
||||||
|
end
|
||||||
|
|
||||||
local function on_nopower(pos)
|
local function node_timer_act(pos, elapsed)
|
||||||
local crd = CRD(pos)
|
local crd = CRD(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
|
||||||
|
-- handle power consumption
|
||||||
|
if crd.power_netw and techage.needs_power(nvm) then
|
||||||
|
local consumed = power.consume_power(pos, crd.power_netw, nil, crd.power_consumption)
|
||||||
|
if consumed < crd.power_consumption then
|
||||||
crd.State:nopower(pos, nvm)
|
crd.State:nopower(pos, nvm)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
|
||||||
local crd = CRD(pos)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
if crd.power_netw and techage.needs_power(nvm) then
|
|
||||||
power.consumer_alive(pos, crd.power_netw, crd.cycle_time)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- call the node timer routine
|
-- call the node timer routine
|
||||||
if techage.is_operational(nvm) then
|
if techage.is_operational(nvm) then
|
||||||
|
nvm.node_timer_call_cyle = (nvm.node_timer_call_cyle or 0) + 1
|
||||||
|
if nvm.node_timer_call_cyle >= crd.call_cycle then
|
||||||
crd.node_timer(pos, crd.cycle_time)
|
crd.node_timer(pos, crd.cycle_time)
|
||||||
|
nvm.node_timer_call_cyle = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return crd.State:is_active(nvm)
|
return crd.State:is_active(nvm)
|
||||||
end
|
end
|
||||||
@ -105,37 +119,17 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||||||
local power_network
|
local power_network
|
||||||
local power_png = 'techage_axle_clutch.png'
|
local power_png = 'techage_axle_clutch.png'
|
||||||
local power_used = tNode.power_consumption ~= nil
|
local power_used = tNode.power_consumption ~= nil
|
||||||
local tNetworks
|
local sides
|
||||||
-- power needed?
|
-- power needed?
|
||||||
if power_used then
|
if power_used then
|
||||||
if stage > 2 then
|
if stage > 2 then
|
||||||
power_network = techage.ElectricCable
|
power_network = techage.ElectricCable
|
||||||
power_png = 'techage_appl_hole_electric.png'
|
power_png = 'techage_appl_hole_electric.png'
|
||||||
tNetworks = {
|
sides = get_keys(tNode.power_sides or {F=1, B=1, U=1, D=1})
|
||||||
ele1 = {
|
|
||||||
sides = tNode.power_sides or {F=1, B=1, U=1, D=1},
|
|
||||||
ntype = "con1",
|
|
||||||
nominal = tNode.power_consumption[stage],
|
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
is_running = function(pos, nvm) return techage.is_running(nvm) end,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if tNode.networks and tNode.networks.pipe2 then
|
|
||||||
tNetworks.pipe2 = tNode.networks.pipe2
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
power_network = techage.Axle
|
power_network = techage.Axle
|
||||||
power_png = 'techage_axle_clutch.png'
|
power_png = 'techage_axle_clutch.png'
|
||||||
tNetworks = {
|
sides = get_keys(tNode.power_sides or {F=1, B=1, U=1, D=1})
|
||||||
axle = {
|
|
||||||
sides = tNode.power_sides or {F=1, B=1, U=1, D=1},
|
|
||||||
ntype = "con1",
|
|
||||||
nominal = tNode.power_consumption[stage],
|
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -143,7 +137,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||||||
node_name_passive = name_pas,
|
node_name_passive = name_pas,
|
||||||
node_name_active = name_act,
|
node_name_active = name_act,
|
||||||
infotext_name = name_inv,
|
infotext_name = name_inv,
|
||||||
cycle_time = tNode.cycle_time,
|
cycle_time = CYCLE_TIME,
|
||||||
standby_ticks = tNode.standby_ticks,
|
standby_ticks = tNode.standby_ticks,
|
||||||
formspec_func = tNode.formspec,
|
formspec_func = tNode.formspec,
|
||||||
on_state_change = tNode.on_state_change,
|
on_state_change = tNode.on_state_change,
|
||||||
@ -162,6 +156,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||||||
tNode.power_consumption[stage] or 0,
|
tNode.power_consumption[stage] or 0,
|
||||||
node_timer = tNode.node_timer,
|
node_timer = tNode.node_timer,
|
||||||
cycle_time = tNode.cycle_time,
|
cycle_time = tNode.cycle_time,
|
||||||
|
call_cycle = tNode.cycle_time / 2,
|
||||||
power_netw = power_network,
|
power_netw = power_network,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,17 +193,6 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
||||||
if tNode.tubelib2_on_update2 then
|
|
||||||
tNode.tubelib2_on_update2(pos, outdir, tlib2, node)
|
|
||||||
end
|
|
||||||
if tlib2.tube_type == "pipe2" then
|
|
||||||
liquid.update_network(pos, outdir, tlib2)
|
|
||||||
else
|
|
||||||
power.update_network(pos, outdir, tlib2)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
tNode.groups.not_in_creative_inventory = 0
|
tNode.groups.not_in_creative_inventory = 0
|
||||||
|
|
||||||
local def_pas = {
|
local def_pas = {
|
||||||
@ -221,20 +205,18 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||||||
|
|
||||||
can_dig = tNode.can_dig,
|
can_dig = tNode.can_dig,
|
||||||
on_rotate = tNode.on_rotate or screwdriver.disallow,
|
on_rotate = tNode.on_rotate or screwdriver.disallow,
|
||||||
on_timer = node_timer,
|
on_timer = node_timer_pas,
|
||||||
on_receive_fields = tNode.on_receive_fields,
|
on_receive_fields = tNode.on_receive_fields,
|
||||||
on_rightclick = tNode.on_rightclick,
|
on_rightclick = tNode.on_rightclick,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
preserve_metadata = tNode.preserve_metadata,
|
preserve_metadata = tNode.preserve_metadata,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
||||||
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
|
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
|
||||||
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
|
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
|
||||||
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
|
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
|
||||||
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
|
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
|
||||||
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
|
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
|
||||||
networks = tNetworks and table.copy(tNetworks),
|
|
||||||
|
|
||||||
paramtype = tNode.paramtype,
|
paramtype = tNode.paramtype,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -264,19 +246,17 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||||||
selection_box = tNode.selection_box,
|
selection_box = tNode.selection_box,
|
||||||
|
|
||||||
on_rotate = tNode.on_rotate or screwdriver.disallow,
|
on_rotate = tNode.on_rotate or screwdriver.disallow,
|
||||||
on_timer = node_timer,
|
on_timer = node_timer_act,
|
||||||
on_receive_fields = tNode.on_receive_fields,
|
on_receive_fields = tNode.on_receive_fields,
|
||||||
on_rightclick = tNode.on_rightclick,
|
on_rightclick = tNode.on_rightclick,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
|
||||||
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
||||||
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
|
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
|
||||||
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
|
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
|
||||||
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
|
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
|
||||||
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
|
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
|
||||||
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
|
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
|
||||||
networks = tNetworks and table.copy(tNetworks),
|
|
||||||
|
|
||||||
paramtype = tNode.paramtype,
|
paramtype = tNode.paramtype,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -297,7 +277,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
|||||||
minetest.register_node(name_act, def_act)
|
minetest.register_node(name_act, def_act)
|
||||||
|
|
||||||
if power_used then
|
if power_used then
|
||||||
power_network:add_secondary_node_names({name_pas, name_act})
|
power.register_nodes({name_pas, name_act}, power_network, "con", sides)
|
||||||
end
|
end
|
||||||
techage.register_node({name_pas, name_act}, tNode.tubing)
|
techage.register_node({name_pas, name_act}, tNode.tubing)
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -253,23 +253,23 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
--minetest.register_craft({
|
||||||
output = node_name_ta3,
|
-- output = node_name_ta3,
|
||||||
recipe = {
|
-- recipe = {
|
||||||
{"", "default:mese_crystal", ""},
|
-- {"", "default:mese_crystal", ""},
|
||||||
{"", node_name_ta2, ""},
|
-- {"", node_name_ta2, ""},
|
||||||
{"", "techage:vacuum_tube", ""},
|
-- {"", "techage:vacuum_tube", ""},
|
||||||
},
|
-- },
|
||||||
})
|
--})
|
||||||
|
|
||||||
minetest.register_craft({
|
--minetest.register_craft({
|
||||||
output = node_name_ta4,
|
-- output = node_name_ta4,
|
||||||
recipe = {
|
-- recipe = {
|
||||||
{"", "default:mese_crystal", ""},
|
-- {"", "default:mese_crystal", ""},
|
||||||
{"", node_name_ta3, ""},
|
-- {"", node_name_ta3, ""},
|
||||||
{"", "techage:ta4_wlanchip", ""},
|
-- {"", "techage:ta4_wlanchip", ""},
|
||||||
},
|
-- },
|
||||||
})
|
--})
|
||||||
|
|
||||||
if minetest.global_exists("unified_inventory") then
|
if minetest.global_exists("unified_inventory") then
|
||||||
unified_inventory.register_craft_type("grinding", {
|
unified_inventory.register_craft_type("grinding", {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -18,24 +18,36 @@ local M = minetest.get_meta
|
|||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local Axle = techage.Axle
|
local Axle = techage.Axle
|
||||||
local Pipe = techage.SteamPipe
|
--local Pipe = techage.SteamPipe
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
local networks = techage.networks
|
--local networks = techage.networks
|
||||||
|
|
||||||
local STANDBY_TICKS = 4
|
local STANDBY_TICKS = 4
|
||||||
local COUNTDOWN_TICKS = 4
|
local COUNTDOWN_TICKS = 4
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local PWR_CAPA = 100
|
local PWR_PERF = 100
|
||||||
|
|
||||||
local function formspec(self, pos, nvm)
|
local function formspec2(self, pos, nvm)
|
||||||
return "size[4,4]"..
|
return "size[4,4]"..
|
||||||
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
|
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
|
||||||
"label[1,-0.1;"..minetest.colorize( "#000000", S("Power Source")).."]"..
|
"label[1,-0.1;"..minetest.colorize( "#000000", S("Power Source")).."]"..
|
||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
default.gui_slots..
|
default.gui_slots..
|
||||||
power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
|
techage.power.formspec_label_bar(pos, 0, 0.8, Axle, S("power"), PWR_PERF, nvm.provided)..
|
||||||
|
"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).."]"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function formspec4(self, pos, nvm)
|
||||||
|
return "size[4,4]"..
|
||||||
|
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
|
||||||
|
"label[1,-0.1;"..minetest.colorize( "#000000", S("Power Source")).."]"..
|
||||||
|
default.gui_bg..
|
||||||
|
default.gui_bg_img..
|
||||||
|
default.gui_slots..
|
||||||
|
techage.power.formspec_label_bar(pos, 0, 0.8, Cable, S("power"), PWR_PERF, 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
|
||||||
@ -48,68 +60,71 @@ end
|
|||||||
|
|
||||||
local function start_node2(pos, nvm, state)
|
local function start_node2(pos, nvm, state)
|
||||||
nvm.generating = true
|
nvm.generating = true
|
||||||
|
nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_start(pos, Axle, CYCLE_TIME, outdir)
|
|
||||||
switch_axles(pos, true)
|
switch_axles(pos, true)
|
||||||
|
power.start_storage_calc(pos, Axle, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_node2(pos, nvm, state)
|
local function stop_node2(pos, nvm, state)
|
||||||
nvm.generating = false
|
nvm.generating = false
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
|
nvm.load = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_stop(pos, Axle, outdir)
|
|
||||||
switch_axles(pos, false)
|
switch_axles(pos, false)
|
||||||
|
power.start_storage_calc(pos, Axle, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function start_node3(pos, nvm, state)
|
--local function start_node3(pos, nvm, state)
|
||||||
nvm.generating = true
|
-- nvm.generating = true
|
||||||
local outdir = M(pos):get_int("outdir")
|
-- local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_start(pos, Pipe, CYCLE_TIME, outdir)
|
-- power.generator_start(pos, Pipe, CYCLE_TIME, outdir)
|
||||||
end
|
--end
|
||||||
|
|
||||||
local function stop_node3(pos, nvm, state)
|
--local function stop_node3(pos, nvm, state)
|
||||||
nvm.generating = false
|
-- nvm.generating = false
|
||||||
nvm.provided = 0
|
-- nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
-- local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_stop(pos, Pipe, outdir)
|
-- power.generator_stop(pos, Pipe, outdir)
|
||||||
end
|
--end
|
||||||
|
|
||||||
local function start_node4(pos, nvm, state)
|
local function start_node4(pos, nvm, state)
|
||||||
nvm.generating = true
|
nvm.generating = true
|
||||||
|
nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_node4(pos, nvm, state)
|
local function stop_node4(pos, nvm, state)
|
||||||
nvm.generating = false
|
nvm.generating = false
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_stop(pos, Cable, outdir)
|
power.start_storage_calc(pos, Cable, outdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
local State2 = techage.NodeStates:new({
|
local State2 = techage.NodeStates:new({
|
||||||
node_name_passive = "techage:t2_source",
|
node_name_passive = "techage:t2_source",
|
||||||
cycle_time = CYCLE_TIME,
|
cycle_time = CYCLE_TIME,
|
||||||
standby_ticks = STANDBY_TICKS,
|
standby_ticks = STANDBY_TICKS,
|
||||||
formspec_func = formspec,
|
formspec_func = formspec2,
|
||||||
start_node = start_node2,
|
start_node = start_node2,
|
||||||
stop_node = stop_node2,
|
stop_node = stop_node2,
|
||||||
})
|
})
|
||||||
|
|
||||||
local State3 = techage.NodeStates:new({
|
--local State3 = techage.NodeStates:new({
|
||||||
node_name_passive = "techage:t3_source",
|
-- node_name_passive = "techage:t3_source",
|
||||||
cycle_time = CYCLE_TIME,
|
-- cycle_time = CYCLE_TIME,
|
||||||
standby_ticks = STANDBY_TICKS,
|
-- standby_ticks = STANDBY_TICKS,
|
||||||
formspec_func = formspec,
|
-- formspec_func = formspec3,
|
||||||
start_node = start_node3,
|
-- start_node = start_node3,
|
||||||
stop_node = stop_node3,
|
-- stop_node = stop_node3,
|
||||||
})
|
--})
|
||||||
|
|
||||||
local State4 = techage.NodeStates:new({
|
local State4 = techage.NodeStates:new({
|
||||||
node_name_passive = "techage:t4_source",
|
node_name_passive = "techage:t4_source",
|
||||||
cycle_time = CYCLE_TIME,
|
cycle_time = CYCLE_TIME,
|
||||||
standby_ticks = STANDBY_TICKS,
|
standby_ticks = STANDBY_TICKS,
|
||||||
formspec_func = formspec,
|
formspec_func = formspec4,
|
||||||
start_node = start_node4,
|
start_node = start_node4,
|
||||||
stop_node = stop_node4,
|
stop_node = stop_node4,
|
||||||
})
|
})
|
||||||
@ -118,31 +133,39 @@ local function node_timer2(pos, elapsed)
|
|||||||
--print("node_timer2")
|
--print("node_timer2")
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
nvm.provided = power.generator_alive(pos, Axle, CYCLE_TIME, outdir)
|
nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF)
|
||||||
|
local data = power.get_storage_data(pos, Axle, outdir)
|
||||||
|
if data then
|
||||||
|
nvm.load = data.level * PWR_PERF * 4
|
||||||
|
end
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State2, pos, nvm))
|
M(pos):set_string("formspec", formspec2(State2, pos, nvm))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function node_timer3(pos, elapsed)
|
--local function node_timer3(pos, elapsed)
|
||||||
--print("node_timer3")
|
-- --print("node_timer3")
|
||||||
local nvm = techage.get_nvm(pos)
|
-- local nvm = techage.get_nvm(pos)
|
||||||
local outdir = M(pos):get_int("outdir")
|
-- local outdir = M(pos):get_int("outdir")
|
||||||
nvm.provided = power.generator_alive(pos, Pipe, CYCLE_TIME, outdir)
|
-- nvm.provided = power.generator_alive(pos, Pipe, CYCLE_TIME, outdir)
|
||||||
if techage.is_activeformspec(pos) then
|
-- if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
-- M(pos):set_string("formspec", formspec3(State3, pos, nvm))
|
||||||
end
|
-- end
|
||||||
return true
|
-- return true
|
||||||
end
|
--end
|
||||||
|
|
||||||
local function node_timer4(pos, elapsed)
|
local function node_timer4(pos, elapsed)
|
||||||
--print("node_timer4")
|
--print("node_timer4")
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
|
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF)
|
||||||
|
local data = power.get_storage_data(pos, Cable, outdir)
|
||||||
|
if data then
|
||||||
|
nvm.load = data.level * PWR_PERF
|
||||||
|
end
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State4, pos, nvm))
|
M(pos):set_string("formspec", formspec4(State4, pos, nvm))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -153,17 +176,17 @@ local function on_receive_fields2(pos, formname, fields, player)
|
|||||||
end
|
end
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
State2:state_button_event(pos, nvm, fields)
|
State2:state_button_event(pos, nvm, fields)
|
||||||
M(pos):set_string("formspec", formspec(State2, pos, nvm))
|
M(pos):set_string("formspec", formspec2(State2, pos, nvm))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_receive_fields3(pos, formname, fields, player)
|
--local function on_receive_fields3(pos, formname, fields, player)
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
-- if minetest.is_protected(pos, player:get_player_name()) then
|
||||||
return
|
-- return
|
||||||
end
|
-- end
|
||||||
local nvm = techage.get_nvm(pos)
|
-- local nvm = techage.get_nvm(pos)
|
||||||
State3:state_button_event(pos, nvm, fields)
|
-- State3:state_button_event(pos, nvm, fields)
|
||||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
-- M(pos):set_string("formspec", formspec3(State3, pos, nvm))
|
||||||
end
|
--end
|
||||||
|
|
||||||
local function on_receive_fields4(pos, formname, fields, player)
|
local function on_receive_fields4(pos, formname, fields, player)
|
||||||
if minetest.is_protected(pos, player:get_player_name()) then
|
if minetest.is_protected(pos, player:get_player_name()) then
|
||||||
@ -171,48 +194,48 @@ local function on_receive_fields4(pos, formname, fields, player)
|
|||||||
end
|
end
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
State4:state_button_event(pos, nvm, fields)
|
State4:state_button_event(pos, nvm, fields)
|
||||||
M(pos):set_string("formspec", formspec(State4, pos, nvm))
|
M(pos):set_string("formspec", formspec4(State4, pos, nvm))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_rightclick2(pos, node, clicker)
|
local function on_rightclick2(pos, node, clicker)
|
||||||
techage.set_activeformspec(pos, clicker)
|
techage.set_activeformspec(pos, clicker)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
M(pos):set_string("formspec", formspec(State2, pos, nvm))
|
M(pos):set_string("formspec", formspec2(State2, pos, nvm))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_rightclick3(pos, node, clicker)
|
--local function on_rightclick3(pos, node, clicker)
|
||||||
techage.set_activeformspec(pos, clicker)
|
-- techage.set_activeformspec(pos, clicker)
|
||||||
local nvm = techage.get_nvm(pos)
|
-- local nvm = techage.get_nvm(pos)
|
||||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
-- M(pos):set_string("formspec", formspec3(State3, pos, nvm))
|
||||||
end
|
--end
|
||||||
|
|
||||||
local function on_rightclick4(pos, node, clicker)
|
local function on_rightclick4(pos, node, clicker)
|
||||||
techage.set_activeformspec(pos, clicker)
|
techage.set_activeformspec(pos, clicker)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
M(pos):set_string("formspec", formspec(State4, pos, nvm))
|
M(pos):set_string("formspec", formspec4(State4, pos, nvm))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function after_place_node2(pos)
|
local function after_place_node2(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
State2:node_init(pos, nvm, "")
|
State2:node_init(pos, nvm, "")
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||||
M(pos):set_string("formspec", formspec(State2, pos, nvm))
|
M(pos):set_string("formspec", formspec2(State2, pos, nvm))
|
||||||
Axle:after_place_node(pos)
|
Axle:after_place_node(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function after_place_node3(pos)
|
--local function after_place_node3(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
-- local nvm = techage.get_nvm(pos)
|
||||||
State3:node_init(pos, nvm, "")
|
-- State3:node_init(pos, nvm, "")
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
-- M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
-- M(pos):set_string("formspec", formspec3(State3, pos, nvm))
|
||||||
Pipe:after_place_node(pos)
|
-- Pipe:after_place_node(pos)
|
||||||
end
|
--end
|
||||||
|
|
||||||
local function after_place_node4(pos)
|
local function after_place_node4(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
State4:node_init(pos, nvm, "")
|
State4:node_init(pos, nvm, "")
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||||
M(pos):set_string("formspec", formspec(State4, pos, nvm))
|
M(pos):set_string("formspec", formspec4(State4, pos, nvm))
|
||||||
Cable:after_place_node(pos)
|
Cable:after_place_node(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -221,44 +244,24 @@ local function after_dig_node2(pos, oldnode)
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function after_dig_node3(pos, oldnode)
|
--local function after_dig_node3(pos, oldnode)
|
||||||
Pipe:after_dig_node(pos)
|
-- Pipe:after_dig_node(pos)
|
||||||
techage.del_mem(pos)
|
-- techage.del_mem(pos)
|
||||||
end
|
--end
|
||||||
|
|
||||||
local function after_dig_node4(pos, oldnode)
|
local function after_dig_node4(pos, oldnode)
|
||||||
Cable:after_dig_node(pos)
|
Cable:after_dig_node(pos)
|
||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
local function get_generator_data(pos, tlib2)
|
||||||
power.update_network(pos, outdir, tlib2)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
if nvm.generating then
|
||||||
|
return {level = (nvm.load or 0) / PWR_PERF, capa = PWR_PERF * 4}
|
||||||
|
else
|
||||||
|
return {level = 0, capa = PWR_PERF * 4}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local net_def2 = {
|
|
||||||
axle = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_CAPA,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local net_def3 = {
|
|
||||||
pipe1 = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_CAPA,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local net_def4 = {
|
|
||||||
ele1 = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_CAPA,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("techage:t2_source", {
|
minetest.register_node("techage:t2_source", {
|
||||||
description = S("Axle Power Source"),
|
description = S("Axle Power Source"),
|
||||||
@ -280,33 +283,31 @@ minetest.register_node("techage:t2_source", {
|
|||||||
on_timer = node_timer2,
|
on_timer = node_timer2,
|
||||||
after_place_node = after_place_node2,
|
after_place_node = after_place_node2,
|
||||||
after_dig_node = after_dig_node2,
|
after_dig_node = after_dig_node2,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
get_generator_data = get_generator_data,
|
||||||
networks = net_def2,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("techage:t3_source", {
|
--minetest.register_node("techage:t3_source", {
|
||||||
description = S("Steam Power Source"),
|
-- description = S("Steam Power Source"),
|
||||||
tiles = {
|
-- tiles = {
|
||||||
-- up, down, right, left, back, front
|
-- -- up, down, right, left, back, front
|
||||||
"techage_filling_ta3.png^techage_frame_ta3_top.png",
|
-- "techage_filling_ta3.png^techage_frame_ta3_top.png",
|
||||||
"techage_filling_ta3.png^techage_frame_ta3.png",
|
-- "techage_filling_ta3.png^techage_frame_ta3.png",
|
||||||
"techage_filling_ta3.png^techage_steam_hole.png^techage_frame_ta3.png",
|
-- "techage_filling_ta3.png^techage_steam_hole.png^techage_frame_ta3.png",
|
||||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
-- "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
||||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
-- "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
||||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
-- "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
||||||
},
|
-- },
|
||||||
paramtype2 = "facedir",
|
-- paramtype2 = "facedir",
|
||||||
groups = {cracky=2, crumbly=2, choppy=2},
|
-- groups = {cracky=2, crumbly=2, choppy=2},
|
||||||
on_rotate = screwdriver.disallow,
|
-- on_rotate = screwdriver.disallow,
|
||||||
is_ground_content = false,
|
-- is_ground_content = false,
|
||||||
on_receive_fields = on_receive_fields3,
|
-- on_receive_fields = on_receive_fields3,
|
||||||
on_rightclick = on_rightclick3,
|
-- on_rightclick = on_rightclick3,
|
||||||
on_timer = node_timer3,
|
-- on_timer = node_timer3,
|
||||||
after_place_node = after_place_node3,
|
-- after_place_node = after_place_node3,
|
||||||
after_dig_node = after_dig_node3,
|
-- after_dig_node = after_dig_node3,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
-- get_generator_data = get_generator_data,
|
||||||
networks = net_def3,
|
--})
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("techage:t4_source", {
|
minetest.register_node("techage:t4_source", {
|
||||||
description = S("Ele Power Source"),
|
description = S("Ele Power Source"),
|
||||||
@ -328,10 +329,9 @@ minetest.register_node("techage:t4_source", {
|
|||||||
on_timer = node_timer4,
|
on_timer = node_timer4,
|
||||||
after_place_node = after_place_node4,
|
after_place_node = after_place_node4,
|
||||||
after_dig_node = after_dig_node4,
|
after_dig_node = after_dig_node4,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
get_generator_data = get_generator_data,
|
||||||
networks = net_def4,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Axle:add_secondary_node_names({"techage:t2_source"})
|
power.register_nodes({"techage:t2_source"}, Axle, "gen", {"R"})
|
||||||
--Pipe:add_secondary_node_names({"techage:t3_source"})
|
--power.register_nodes({"techage:t3_source"}, Pipe, "gen", {"R"})
|
||||||
Cable:add_secondary_node_names({"techage:t4_source"})
|
power.register_nodes({"techage:t4_source"}, Cable, "gen", {"R"})
|
||||||
|
@ -164,6 +164,11 @@ local function is_air_like(name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
techage.SystemTime = 0
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
techage.SystemTime = techage.SystemTime + dtime
|
||||||
|
end)
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
-- API helper functions
|
-- API helper functions
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
|
@ -1,362 +0,0 @@
|
|||||||
--[[
|
|
||||||
|
|
||||||
TechAge
|
|
||||||
=======
|
|
||||||
|
|
||||||
Copyright (C) 2019 Joachim Stolberg
|
|
||||||
|
|
||||||
AGPL v3
|
|
||||||
See LICENSE.txt for more information
|
|
||||||
|
|
||||||
Networks - the connection of tubelib2 tube/pipe/cable lines to networks
|
|
||||||
]]--
|
|
||||||
|
|
||||||
local S2P = minetest.string_to_pos
|
|
||||||
local P2S = minetest.pos_to_string
|
|
||||||
local M = minetest.get_meta
|
|
||||||
local N = techage.get_node_lvm
|
|
||||||
local S = techage.S
|
|
||||||
local hex = function(val) return string.format("%x", val) end
|
|
||||||
|
|
||||||
local Networks = {} -- cache for networks
|
|
||||||
|
|
||||||
techage.networks = {} -- name space
|
|
||||||
|
|
||||||
local MAX_NUM_NODES = 1000
|
|
||||||
local BEST_BEFORE = 5 * 60 -- 5 minutes
|
|
||||||
local Route = {} -- Used to determine the already passed nodes while walking
|
|
||||||
local NumNodes = 0
|
|
||||||
local DirToSide = {"B", "R", "F", "L", "D", "U"}
|
|
||||||
local Sides = {B = true, R = true, F = true, L = true, D = true, U = true}
|
|
||||||
local SideToDir = {B=1, R=2, F=3, L=4, D=5, U=6}
|
|
||||||
local Flip = {[0]=0,3,4,1,2,6,5} -- 180 degree turn
|
|
||||||
|
|
||||||
local function error(pos, msg)
|
|
||||||
minetest.log("error", "[techage] "..msg.." at "..P2S(pos).." "..N(pos).name)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function count_nodes(ntype, nodes)
|
|
||||||
local num = 0
|
|
||||||
for _,pos in ipairs(nodes or {}) do
|
|
||||||
num = num + 1
|
|
||||||
end
|
|
||||||
return ntype.."="..num
|
|
||||||
end
|
|
||||||
|
|
||||||
local function output(network, valid)
|
|
||||||
local tbl = {}
|
|
||||||
for ntype,table in pairs(network) do
|
|
||||||
if type(table) == "table" then
|
|
||||||
tbl[#tbl+1] = count_nodes(ntype, table)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
print("Network ("..valid.."): "..table.concat(tbl, ", "))
|
|
||||||
end
|
|
||||||
|
|
||||||
local function debug(ntype)
|
|
||||||
local tbl = {}
|
|
||||||
for netID,netw in pairs(Networks[ntype] or {}) do
|
|
||||||
if type(netw) == "table" then
|
|
||||||
tbl[#tbl+1] = string.format("%X", netID)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "Networks: "..table.concat(tbl, ", ")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function hidden_node(pos, net_name)
|
|
||||||
local name = M(pos):get_string("techage_hidden_nodename")
|
|
||||||
local ndef = minetest.registered_nodes[name]
|
|
||||||
if ndef and ndef.networks then
|
|
||||||
return ndef.networks[net_name] or {}
|
|
||||||
end
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- return the node definition local networks table
|
|
||||||
local function net_def(pos, net_name)
|
|
||||||
local ndef = minetest.registered_nodes[techage.get_node_lvm(pos).name]
|
|
||||||
if ndef and ndef.networks then
|
|
||||||
return ndef.networks[net_name] or {}
|
|
||||||
else -- hidden junction
|
|
||||||
return hidden_node(pos, net_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function net_def2(pos, node_name, net_name)
|
|
||||||
local ndef = minetest.registered_nodes[node_name]
|
|
||||||
if ndef and ndef.networks then
|
|
||||||
return ndef.networks[net_name] or {}
|
|
||||||
else -- hidden junction
|
|
||||||
return hidden_node(pos, net_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function connected(tlib2, pos, dir)
|
|
||||||
local param2, npos = tlib2:get_primary_node_param2(pos, dir)
|
|
||||||
if param2 then
|
|
||||||
local d1, d2, num = tlib2:decode_param2(npos, param2)
|
|
||||||
if not num then return end
|
|
||||||
return Flip[dir] == d1 or Flip[dir] == d2
|
|
||||||
end
|
|
||||||
-- secondary nodes allowed?
|
|
||||||
if tlib2.force_to_use_tubes then
|
|
||||||
return tlib2:is_special_node(pos, dir)
|
|
||||||
else
|
|
||||||
return tlib2:is_secondary_node(pos, dir)
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Calculate the node outdir based on node.param2 and nominal dir (according to side)
|
|
||||||
local function dir_to_outdir(dir, param2)
|
|
||||||
if dir < 5 then
|
|
||||||
return ((dir + param2 - 1) % 4) + 1
|
|
||||||
end
|
|
||||||
return dir
|
|
||||||
end
|
|
||||||
|
|
||||||
local function indir_to_dir(indir, param2)
|
|
||||||
if indir < 5 then
|
|
||||||
return ((indir - param2 + 5) % 4) + 1
|
|
||||||
end
|
|
||||||
return Flip[indir]
|
|
||||||
end
|
|
||||||
|
|
||||||
local function outdir_to_dir(outdir, param2)
|
|
||||||
if outdir < 5 then
|
|
||||||
return ((outdir - param2 + 3) % 4) + 1
|
|
||||||
end
|
|
||||||
return outdir
|
|
||||||
end
|
|
||||||
|
|
||||||
local function side_to_outdir(pos, side)
|
|
||||||
return dir_to_outdir(SideToDir[side], techage.get_node_lvm(pos).param2)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Get tlib2 connection dirs as table
|
|
||||||
-- used e.g. for the connection walk
|
|
||||||
local function get_node_connections(pos, net_name)
|
|
||||||
local val = M(pos):get_int(net_name.."_conn")
|
|
||||||
local tbl = {}
|
|
||||||
if val % 0x40 >= 0x20 then tbl[#tbl+1] = 1 end
|
|
||||||
if val % 0x20 >= 0x10 then tbl[#tbl+1] = 2 end
|
|
||||||
if val % 0x10 >= 0x08 then tbl[#tbl+1] = 3 end
|
|
||||||
if val % 0x08 >= 0x04 then tbl[#tbl+1] = 4 end
|
|
||||||
if val % 0x04 >= 0x02 then tbl[#tbl+1] = 5 end
|
|
||||||
if val % 0x02 >= 0x01 then tbl[#tbl+1] = 6 end
|
|
||||||
return tbl
|
|
||||||
end
|
|
||||||
|
|
||||||
-- store all node sides with tube connections as nodemeta
|
|
||||||
local function node_connections(pos, tlib2)
|
|
||||||
local node = techage.get_node_lvm(pos)
|
|
||||||
local val = 0
|
|
||||||
local ndef = net_def2(pos, node.name, tlib2.tube_type)
|
|
||||||
local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node)
|
|
||||||
if sides then
|
|
||||||
for dir = 1,6 do
|
|
||||||
val = val * 2
|
|
||||||
local side = DirToSide[outdir_to_dir(dir, node.param2)]
|
|
||||||
if sides[side] then
|
|
||||||
if connected(tlib2, pos, dir) then
|
|
||||||
--techage.mark_side("singleplayer", pos, dir, "node_connections", "", 1)--------------------
|
|
||||||
val = val + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
M(pos):set_int(tlib2.tube_type.."_conn", val)
|
|
||||||
else
|
|
||||||
--error(pos, "sides missing")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function pos_already_reached(pos)
|
|
||||||
local key = minetest.hash_node_position(pos)
|
|
||||||
if not Route[key] and NumNodes < MAX_NUM_NODES then
|
|
||||||
Route[key] = true
|
|
||||||
NumNodes = NumNodes + 1
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check if the given pipe dir into the node is valid
|
|
||||||
local function valid_indir(pos, indir, node, net_name)
|
|
||||||
local ndef = net_def2(pos, node.name, net_name)
|
|
||||||
local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node)
|
|
||||||
local side = DirToSide[indir_to_dir(indir, node.param2)]
|
|
||||||
if not sides or sides and not sides[side] then return false end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function is_junction(pos, name, tube_type)
|
|
||||||
local ndef = net_def2(pos, name, tube_type)
|
|
||||||
-- ntype can be a string or an array of strings or nil
|
|
||||||
if ndef.ntype == "junc" then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if type(ndef.ntype) == "table" then
|
|
||||||
for _,ntype in ipairs(ndef.ntype) do
|
|
||||||
if ntype == "junc" then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- do the walk through the tubelib2 network
|
|
||||||
-- indir is the direction which should not be covered by the walk
|
|
||||||
-- (coming from there)
|
|
||||||
-- if outdirs is given, only this dirs are used
|
|
||||||
local function connection_walk(pos, outdirs, indir, node, tlib2, clbk)
|
|
||||||
if clbk then clbk(pos, indir, node) end
|
|
||||||
--techage.mark_position("singleplayer", pos, "walk", "", 1)
|
|
||||||
--print("connection_walk", node.name, outdirs or is_junction(pos, node.name, tlib2.tube_type))
|
|
||||||
if outdirs or is_junction(pos, node.name, tlib2.tube_type) then
|
|
||||||
for _,outdir in pairs(outdirs or get_node_connections(pos, tlib2.tube_type)) do
|
|
||||||
--techage.mark_side("singleplayer", pos, outdir, "connection_walk", "", 3)--------------------
|
|
||||||
--print("get_node_connections", node.name, outdir)
|
|
||||||
local pos2, indir2 = tlib2:get_connected_node_pos(pos, outdir)
|
|
||||||
local node = techage.get_node_lvm(pos2)
|
|
||||||
if pos2 and not pos_already_reached(pos2) and valid_indir(pos2, indir2, node, tlib2.tube_type) then
|
|
||||||
connection_walk(pos2, nil, indir2, node, tlib2, clbk)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function collect_network_nodes(pos, outdir, tlib2)
|
|
||||||
Route = {}
|
|
||||||
NumNodes = 0
|
|
||||||
pos_already_reached(pos)
|
|
||||||
local netw = {}
|
|
||||||
local node = techage.get_node_lvm(pos)
|
|
||||||
local net_name = tlib2.tube_type
|
|
||||||
-- outdir corresponds to the indir coming from
|
|
||||||
connection_walk(pos, outdir and {outdir}, nil, node, tlib2, function(pos, indir, node)
|
|
||||||
local ndef = net_def2(pos, node.name, net_name)
|
|
||||||
-- ntype can be a string or an array of strings or nil
|
|
||||||
local ntypes = ndef.ntype or {}
|
|
||||||
if type(ntypes) == "string" then
|
|
||||||
ntypes = {ntypes}
|
|
||||||
end
|
|
||||||
for _,ntype in ipairs(ntypes) do
|
|
||||||
if not netw[ntype] then netw[ntype] = {} end
|
|
||||||
netw[ntype][#netw[ntype] + 1] = {pos = pos, indir = indir, nominal = ndef.nominal, regenerative = ndef.regenerative}
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
netw.best_before = minetest.get_gametime() + BEST_BEFORE
|
|
||||||
netw.num_nodes = NumNodes
|
|
||||||
return netw
|
|
||||||
end
|
|
||||||
|
|
||||||
-- keep data base small and valid
|
|
||||||
-- needed for networks without scheduler
|
|
||||||
local function remove_outdated_networks()
|
|
||||||
local to_be_deleted = {}
|
|
||||||
local t = minetest.get_gametime()
|
|
||||||
for net_name,tbl in pairs(Networks) do
|
|
||||||
for netID,network in pairs(tbl) do
|
|
||||||
local valid = (network.best_before or 0) - t
|
|
||||||
--output(network, valid)
|
|
||||||
if valid < 0 then
|
|
||||||
to_be_deleted[#to_be_deleted+1] = {net_name, netID}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for _,item in ipairs(to_be_deleted) do
|
|
||||||
local net_name, netID = unpack(item)
|
|
||||||
Networks[net_name][netID] = nil
|
|
||||||
end
|
|
||||||
minetest.after(60, remove_outdated_networks)
|
|
||||||
end
|
|
||||||
minetest.after(60, remove_outdated_networks)
|
|
||||||
|
|
||||||
--
|
|
||||||
-- API Functions
|
|
||||||
--
|
|
||||||
|
|
||||||
-- Table fo a 180 degree turn
|
|
||||||
techage.networks.Flip = Flip
|
|
||||||
|
|
||||||
-- techage.networks.net_def(pos, net_name)
|
|
||||||
techage.networks.net_def = net_def
|
|
||||||
|
|
||||||
techage.networks.AllSides = Sides -- table for all 6 node sides
|
|
||||||
|
|
||||||
-- techage.networks.side_to_outdir(pos, side)
|
|
||||||
techage.networks.side_to_outdir = side_to_outdir
|
|
||||||
|
|
||||||
-- techage.networks.node_connections(pos, tlib2)
|
|
||||||
techage.networks.node_connections = node_connections
|
|
||||||
|
|
||||||
-- techage.networks.collect_network_nodes(pos, outdir, tlib2)
|
|
||||||
techage.networks.collect_network_nodes = collect_network_nodes
|
|
||||||
|
|
||||||
function techage.networks.connection_walk(pos, outdir, tlib2, clbk)
|
|
||||||
Route = {}
|
|
||||||
NumNodes = 0
|
|
||||||
pos_already_reached(pos) -- don't consider the start pos
|
|
||||||
local node = techage.get_node_lvm(pos)
|
|
||||||
connection_walk(pos, outdir and {outdir}, Flip[outdir], node, tlib2, clbk)
|
|
||||||
return NumNodes
|
|
||||||
end
|
|
||||||
|
|
||||||
-- return network without maintainting the "alive" data
|
|
||||||
function techage.networks.peek_network(tube_type, netID)
|
|
||||||
--print("peek_network", debug(tube_type))
|
|
||||||
return Networks[tube_type] and Networks[tube_type][netID]
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.networks.set_network(tube_type, netID, network)
|
|
||||||
if netID then
|
|
||||||
if not Networks[tube_type] then
|
|
||||||
Networks[tube_type] = {}
|
|
||||||
end
|
|
||||||
Networks[tube_type][netID] = network
|
|
||||||
Networks[tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Power API
|
|
||||||
--
|
|
||||||
function techage.networks.has_network(tube_type, netID)
|
|
||||||
return Networks[tube_type] and Networks[tube_type][netID]
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.networks.build_network(pos, outdir, tlib2, netID)
|
|
||||||
local netw = collect_network_nodes(pos, outdir, tlib2)
|
|
||||||
Networks[tlib2.tube_type] = Networks[tlib2.tube_type] or {}
|
|
||||||
Networks[tlib2.tube_type][netID] = netw
|
|
||||||
netw.alive = 3
|
|
||||||
-- sort generating1 nodes, so that regenerative ones will be used first
|
|
||||||
if netw.gen1 then
|
|
||||||
table.sort(netw.gen1, function(a,b) return a.regenerative and not b.regenerative end)
|
|
||||||
end
|
|
||||||
techage.schedule.start(tlib2.tube_type, netID)
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.networks.get_network(tube_type, netID)
|
|
||||||
--print("get_network", string.format("%X", netID), debug(tube_type))
|
|
||||||
local netw = Networks[tube_type] and Networks[tube_type][netID]
|
|
||||||
if netw then
|
|
||||||
netw.alive = 3 -- monitored by scheduler (power)
|
|
||||||
netw.best_before = minetest.get_gametime() + BEST_BEFORE -- monitored by networks (liquids)
|
|
||||||
return netw
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.networks.delete_network(tube_type, netID)
|
|
||||||
if Networks[tube_type] and Networks[tube_type][netID] then
|
|
||||||
Networks[tube_type][netID] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Get node tubelib2 connections as table of outdirs
|
|
||||||
-- techage.networks.get_node_connections(pos, net_name)
|
|
||||||
techage.networks.get_node_connections = get_node_connections
|
|
||||||
|
|
||||||
techage.networks.MAX_NUM_NODES = MAX_NUM_NODES
|
|
@ -155,14 +155,7 @@ end
|
|||||||
-- consumes power
|
-- consumes power
|
||||||
function techage.needs_power(nvm)
|
function techage.needs_power(nvm)
|
||||||
local state = nvm.techage_state or STOPPED
|
local state = nvm.techage_state or STOPPED
|
||||||
-- "blocked" must need power, otherwise it could happen, that the node
|
return state == RUNNING or state == NOPOWER
|
||||||
-- is not in the power network anymore and gets not started if
|
|
||||||
-- power is turned off and on again.
|
|
||||||
return state < STANDBY or state == NOPOWER
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.needs_power2(state)
|
|
||||||
return state < STANDBY or state == NOPOWER
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function techage.get_state_string(nvm)
|
function techage.get_state_string(nvm)
|
||||||
|
313
init.lua
313
init.lua
@ -85,7 +85,6 @@ dofile(MP.."/basis/fuel_lib.lua") -- common fuel functions
|
|||||||
dofile(MP.."/basis/mark.lua")
|
dofile(MP.."/basis/mark.lua")
|
||||||
dofile(MP.."/basis/mark2.lua")
|
dofile(MP.."/basis/mark2.lua")
|
||||||
dofile(MP.."/basis/assemble.lua")
|
dofile(MP.."/basis/assemble.lua")
|
||||||
dofile(MP.."/basis/networks.lua")
|
|
||||||
dofile(MP.."/basis/recipe_lib.lua")
|
dofile(MP.."/basis/recipe_lib.lua")
|
||||||
dofile(MP.."/basis/formspec_update.lua")
|
dofile(MP.."/basis/formspec_update.lua")
|
||||||
dofile(MP.."/basis/windturbine_lib.lua")
|
dofile(MP.."/basis/windturbine_lib.lua")
|
||||||
@ -99,26 +98,25 @@ dofile(MP.."/doc/items.lua")
|
|||||||
dofile(MP.."/doc/guide.lua") -- construction guides
|
dofile(MP.."/doc/guide.lua") -- construction guides
|
||||||
dofile(MP.."/doc/manual_api.lua") -- external API
|
dofile(MP.."/doc/manual_api.lua") -- external API
|
||||||
|
|
||||||
|
dofile(MP.."/items/filling.lua")
|
||||||
|
|
||||||
-- Power networks
|
-- Power networks
|
||||||
dofile(MP.."/power/node_api.lua")
|
|
||||||
dofile(MP.."/power/junction.lua")
|
|
||||||
dofile(MP.."/power/distribution.lua")
|
|
||||||
dofile(MP.."/power/schedule.lua")
|
|
||||||
dofile(MP.."/power/formspecs.lua")
|
dofile(MP.."/power/formspecs.lua")
|
||||||
dofile(MP.."/power/drive_axle.lua")
|
dofile(MP.."/power/drive_axle.lua")
|
||||||
dofile(MP.."/power/gearbox.lua")
|
dofile(MP.."/power/gearbox.lua")
|
||||||
dofile(MP.."/power/steam_pipe.lua")
|
dofile(MP.."/power/steam_pipe.lua")
|
||||||
dofile(MP.."/power/electric_cable.lua")
|
dofile(MP.."/power/electric_cable.lua")
|
||||||
dofile(MP.."/power/junctionbox.lua")
|
dofile(MP.."/power/junctionbox.lua")
|
||||||
dofile(MP.."/power/power_terminal.lua")
|
--dofile(MP.."/power/power_terminal.lua")
|
||||||
dofile(MP.."/power/power_terminal2.lua")
|
--dofile(MP.."/power/power_terminal2.lua")
|
||||||
|
dofile(MP.."/power/powerswitchbox_legacy.lua")
|
||||||
dofile(MP.."/power/powerswitchbox.lua")
|
dofile(MP.."/power/powerswitchbox.lua")
|
||||||
dofile(MP.."/power/powerswitch.lua")
|
dofile(MP.."/power/powerswitch.lua")
|
||||||
dofile(MP.."/power/protection.lua")
|
dofile(MP.."/power/protection.lua")
|
||||||
dofile(MP.."/power/power_line.lua")
|
--dofile(MP.."/power/power_line.lua")
|
||||||
dofile(MP.."/power/ta4_cable.lua")
|
--dofile(MP.."/power/ta4_cable.lua")
|
||||||
dofile(MP.."/power/ta4_cable_wall_entry.lua")
|
--dofile(MP.."/power/ta4_cable_wall_entry.lua")
|
||||||
dofile(MP.."/power/laser.lua")
|
--dofile(MP.."/power/laser.lua")
|
||||||
|
|
||||||
-- Iron Age
|
-- Iron Age
|
||||||
dofile(MP.."/iron_age/main.lua")
|
dofile(MP.."/iron_age/main.lua")
|
||||||
@ -145,9 +143,8 @@ dofile(MP.."/steam_engine/flywheel.lua")
|
|||||||
|
|
||||||
-- Liquids I
|
-- Liquids I
|
||||||
dofile(MP.."/liquids/liquid_pipe.lua")
|
dofile(MP.."/liquids/liquid_pipe.lua")
|
||||||
dofile(MP.."/liquids/valve.lua")
|
--dofile(MP.."/liquids/valve.lua")
|
||||||
dofile(MP.."/liquids/node_api.lua")
|
--dofile(MP.."/liquids/pipe_wall_entry.lua")
|
||||||
dofile(MP.."/liquids/pipe_wall_entry.lua")
|
|
||||||
|
|
||||||
-- Basic Machines
|
-- Basic Machines
|
||||||
dofile(MP.."/basic_machines/consumer.lua") -- consumer base model
|
dofile(MP.."/basic_machines/consumer.lua") -- consumer base model
|
||||||
@ -156,192 +153,194 @@ dofile(MP.."/basic_machines/pusher.lua")
|
|||||||
dofile(MP.."/basic_machines/legacy_nodes.lua")
|
dofile(MP.."/basic_machines/legacy_nodes.lua")
|
||||||
dofile(MP.."/basic_machines/mods_support.lua")
|
dofile(MP.."/basic_machines/mods_support.lua")
|
||||||
dofile(MP.."/basic_machines/grinder.lua")
|
dofile(MP.."/basic_machines/grinder.lua")
|
||||||
dofile(MP.."/basic_machines/distributor.lua")
|
--dofile(MP.."/basic_machines/distributor.lua")
|
||||||
dofile(MP.."/basic_machines/gravelsieve.lua")
|
--dofile(MP.."/basic_machines/gravelsieve.lua")
|
||||||
dofile(MP.."/basic_machines/gravelrinser.lua")
|
--dofile(MP.."/basic_machines/gravelrinser.lua")
|
||||||
dofile(MP.."/basic_machines/chest.lua")
|
dofile(MP.."/basic_machines/chest.lua")
|
||||||
dofile(MP.."/basic_machines/autocrafter.lua")
|
--dofile(MP.."/basic_machines/autocrafter.lua")
|
||||||
dofile(MP.."/basic_machines/electronic_fab.lua")
|
--dofile(MP.."/basic_machines/electronic_fab.lua")
|
||||||
dofile(MP.."/basic_machines/liquidsampler.lua")
|
--dofile(MP.."/basic_machines/liquidsampler.lua")
|
||||||
dofile(MP.."/basic_machines/quarry.lua")
|
--dofile(MP.."/basic_machines/quarry.lua")
|
||||||
dofile(MP.."/basic_machines/ta4_chest.lua")
|
--dofile(MP.."/basic_machines/ta4_chest.lua")
|
||||||
dofile(MP.."/basic_machines/ta4_injector.lua")
|
--dofile(MP.."/basic_machines/ta4_injector.lua")
|
||||||
dofile(MP.."/basic_machines/itemsource.lua")
|
--dofile(MP.."/basic_machines/itemsource.lua")
|
||||||
dofile(MP.."/basic_machines/recycler.lua")
|
--dofile(MP.."/basic_machines/recycler.lua")
|
||||||
dofile(MP.."/basic_machines/concentrator.lua")
|
--dofile(MP.."/basic_machines/concentrator.lua")
|
||||||
|
|
||||||
-- Liquids II
|
-- Liquids II
|
||||||
dofile(MP.."/liquids/tank.lua")
|
--dofile(MP.."/liquids/tank.lua")
|
||||||
dofile(MP.."/liquids/filler.lua")
|
--dofile(MP.."/liquids/filler.lua")
|
||||||
dofile(MP.."/liquids/silo.lua")
|
--dofile(MP.."/liquids/silo.lua")
|
||||||
dofile(MP.."/liquids/pump.lua")
|
--dofile(MP.."/liquids/pump.lua")
|
||||||
dofile(MP.."/liquids/waterpump.lua")
|
--dofile(MP.."/liquids/waterpump.lua")
|
||||||
dofile(MP.."/liquids/waterinlet.lua")
|
--dofile(MP.."/liquids/waterinlet.lua")
|
||||||
|
|
||||||
-- Coal power station
|
-- Coal power station
|
||||||
dofile(MP.."/coal_power_station/firebox.lua")
|
--dofile(MP.."/coal_power_station/firebox.lua")
|
||||||
dofile(MP.."/coal_power_station/boiler_base.lua")
|
--dofile(MP.."/coal_power_station/boiler_base.lua")
|
||||||
dofile(MP.."/coal_power_station/boiler_top.lua")
|
--dofile(MP.."/coal_power_station/boiler_top.lua")
|
||||||
dofile(MP.."/coal_power_station/generator.lua")
|
--dofile(MP.."/coal_power_station/generator.lua")
|
||||||
dofile(MP.."/coal_power_station/turbine.lua")
|
--dofile(MP.."/coal_power_station/turbine.lua")
|
||||||
dofile(MP.."/coal_power_station/cooler.lua")
|
--dofile(MP.."/coal_power_station/cooler.lua")
|
||||||
dofile(MP.."/coal_power_station/oilfirebox.lua")
|
--dofile(MP.."/coal_power_station/oilfirebox.lua")
|
||||||
|
|
||||||
-- Industrial Furnace
|
-- Industrial Furnace
|
||||||
dofile(MP.."/furnace/firebox.lua")
|
--dofile(MP.."/furnace/firebox.lua")
|
||||||
dofile(MP.."/furnace/cooking.lua")
|
--dofile(MP.."/furnace/cooking.lua")
|
||||||
dofile(MP.."/furnace/furnace_top.lua")
|
--dofile(MP.."/furnace/furnace_top.lua")
|
||||||
dofile(MP.."/furnace/booster.lua")
|
--dofile(MP.."/furnace/booster.lua")
|
||||||
dofile(MP.."/furnace/heater.lua")
|
--dofile(MP.."/furnace/heater.lua")
|
||||||
dofile(MP.."/furnace/recipes.lua")
|
--dofile(MP.."/furnace/recipes.lua")
|
||||||
|
|
||||||
-- Tools
|
-- Tools
|
||||||
dofile(MP.."/tools/trowel.lua")
|
--dofile(MP.."/tools/trowel.lua")
|
||||||
dofile(MP.."/tools/repairkit.lua")
|
--dofile(MP.."/tools/repairkit.lua")
|
||||||
dofile(MP.."/tools/pipe_wrench.lua")
|
--dofile(MP.."/tools/pipe_wrench.lua")
|
||||||
dofile(MP.."/basic_machines/blackhole.lua")
|
--dofile(MP.."/basic_machines/blackhole.lua")
|
||||||
dofile(MP.."/basic_machines/forceload.lua")
|
--dofile(MP.."/basic_machines/forceload.lua")
|
||||||
|
|
||||||
-- Lamps
|
-- Lamps
|
||||||
dofile(MP.."/lamps/lib.lua")
|
--dofile(MP.."/lamps/lib.lua")
|
||||||
dofile(MP.."/lamps/lightblock.lua")
|
--dofile(MP.."/lamps/lightblock.lua")
|
||||||
dofile(MP.."/lamps/simplelamp.lua")
|
--dofile(MP.."/lamps/simplelamp.lua")
|
||||||
dofile(MP.."/lamps/streetlamp.lua")
|
--dofile(MP.."/lamps/streetlamp.lua")
|
||||||
dofile(MP.."/lamps/streetlamp2.lua")
|
--dofile(MP.."/lamps/streetlamp2.lua")
|
||||||
dofile(MP.."/lamps/ceilinglamp.lua")
|
--dofile(MP.."/lamps/ceilinglamp.lua")
|
||||||
dofile(MP.."/lamps/industriallamp1.lua")
|
--dofile(MP.."/lamps/industriallamp1.lua")
|
||||||
dofile(MP.."/lamps/industriallamp2.lua")
|
--dofile(MP.."/lamps/industriallamp2.lua")
|
||||||
dofile(MP.."/lamps/industriallamp3.lua")
|
--dofile(MP.."/lamps/industriallamp3.lua")
|
||||||
dofile(MP.."/lamps/industriallamp4.lua")
|
--dofile(MP.."/lamps/industriallamp4.lua")
|
||||||
dofile(MP.."/lamps/growlight.lua")
|
--dofile(MP.."/lamps/growlight.lua")
|
||||||
dofile(MP.."/lamps/lampholder.lua")
|
--dofile(MP.."/lamps/lampholder.lua")
|
||||||
|
|
||||||
-- Oil
|
-- Oil
|
||||||
dofile(MP.."/oil/explore.lua")
|
--dofile(MP.."/oil/explore.lua")
|
||||||
dofile(MP.."/oil/tower.lua")
|
--dofile(MP.."/oil/tower.lua")
|
||||||
dofile(MP.."/oil/drillbox.lua")
|
--dofile(MP.."/oil/drillbox.lua")
|
||||||
dofile(MP.."/oil/pumpjack.lua")
|
--dofile(MP.."/oil/pumpjack.lua")
|
||||||
dofile(MP.."/oil/distiller.lua")
|
--dofile(MP.."/oil/distiller.lua")
|
||||||
dofile(MP.."/oil/reboiler.lua")
|
--dofile(MP.."/oil/reboiler.lua")
|
||||||
-- dofile(MP.."/oil/gasflare.lua")
|
-- -- dofile(MP.."/oil/gasflare.lua")
|
||||||
|
|
||||||
-- TA3 power based
|
-- TA3 power based
|
||||||
dofile(MP.."/ta3_power/tiny_generator.lua")
|
--dofile(MP.."/ta3_power/tiny_generator.lua")
|
||||||
dofile(MP.."/ta3_power/akkubox.lua")
|
--dofile(MP.."/ta3_power/akkubox.lua")
|
||||||
dofile(MP.."/ta3_power/axle2power.lua")
|
--dofile(MP.."/ta3_power/axle2power.lua")
|
||||||
dofile(MP.."/ta3_power/power2axle.lua")
|
--dofile(MP.."/ta3_power/power2axle.lua")
|
||||||
|
|
||||||
-- Digtron
|
-- Digtron
|
||||||
if minetest.global_exists("digtron") then
|
--if minetest.global_exists("digtron") then
|
||||||
dofile(MP.."/digtron/battery.lua")
|
-- dofile(MP.."/digtron/battery.lua")
|
||||||
end
|
--end
|
||||||
|
|
||||||
-- Logic
|
-- Logic
|
||||||
dofile(MP.."/logic/lib.lua")
|
--dofile(MP.."/logic/lib.lua")
|
||||||
dofile(MP.."/logic/terminal.lua")
|
--dofile(MP.."/logic/terminal.lua")
|
||||||
dofile(MP.."/logic/button.lua")
|
--dofile(MP.."/logic/button.lua")
|
||||||
dofile(MP.."/logic/detector.lua")
|
--dofile(MP.."/logic/detector.lua")
|
||||||
dofile(MP.."/logic/repeater.lua")
|
--dofile(MP.."/logic/repeater.lua")
|
||||||
dofile(MP.."/logic/programmer.lua")
|
--dofile(MP.."/logic/programmer.lua")
|
||||||
dofile(MP.."/logic/signallamp.lua")
|
--dofile(MP.."/logic/signallamp.lua")
|
||||||
dofile(MP.."/logic/sequencer.lua")
|
--dofile(MP.."/logic/sequencer.lua")
|
||||||
dofile(MP.."/logic/timer.lua")
|
--dofile(MP.."/logic/timer.lua")
|
||||||
dofile(MP.."/logic/lua_logic.lua") -- old
|
--dofile(MP.."/logic/lua_logic.lua") -- old
|
||||||
dofile(MP.."/logic/logic_block.lua") -- new
|
--dofile(MP.."/logic/logic_block.lua") -- new
|
||||||
dofile(MP.."/logic/node_detector.lua")
|
--dofile(MP.."/logic/node_detector.lua")
|
||||||
dofile(MP.."/logic/player_detector.lua")
|
--dofile(MP.."/logic/player_detector.lua")
|
||||||
dofile(MP.."/logic/cart_detector.lua")
|
--dofile(MP.."/logic/cart_detector.lua")
|
||||||
dofile(MP.."/logic/gateblock.lua")
|
--dofile(MP.."/logic/gateblock.lua")
|
||||||
dofile(MP.."/logic/doorblock.lua")
|
--dofile(MP.."/logic/doorblock.lua")
|
||||||
dofile(MP.."/logic/doorcontroller.lua") -- old
|
--dofile(MP.."/logic/doorcontroller.lua") -- old
|
||||||
dofile(MP.."/logic/doorcontroller2.lua") -- new
|
--dofile(MP.."/logic/doorcontroller2.lua") -- new
|
||||||
dofile(MP.."/logic/collector.lua")
|
--dofile(MP.."/logic/collector.lua")
|
||||||
if minetest.global_exists("mesecon") then
|
--if minetest.global_exists("mesecon") then
|
||||||
dofile(MP.."/logic/mesecons_converter.lua")
|
-- dofile(MP.."/logic/mesecons_converter.lua")
|
||||||
end
|
--end
|
||||||
|
|
||||||
-- Test
|
-- Test
|
||||||
dofile(MP.."/recipe_checker.lua")
|
dofile(MP.."/recipe_checker.lua")
|
||||||
dofile(MP.."/.test/sink.lua")
|
dofile(MP.."/.test/sink.lua")
|
||||||
--dofile(MP.."/.test/meta_node.lua")
|
|
||||||
|
|
||||||
-- Solar
|
-- Solar
|
||||||
dofile(MP.."/solar/minicell.lua")
|
--dofile(MP.."/solar/minicell.lua")
|
||||||
dofile(MP.."/solar/solarcell.lua")
|
--dofile(MP.."/solar/solarcell.lua")
|
||||||
dofile(MP.."/solar/inverter.lua")
|
--dofile(MP.."/solar/inverter.lua")
|
||||||
|
|
||||||
-- Wind
|
-- Wind
|
||||||
dofile(MP.."/wind_turbine/rotor.lua")
|
--dofile(MP.."/wind_turbine/rotor.lua")
|
||||||
dofile(MP.."/wind_turbine/pillar.lua")
|
--dofile(MP.."/wind_turbine/pillar.lua")
|
||||||
dofile(MP.."/wind_turbine/signallamp.lua")
|
--dofile(MP.."/wind_turbine/signallamp.lua")
|
||||||
|
|
||||||
-- TA4 Energy Storage
|
-- TA4 Energy Storage
|
||||||
dofile(MP.."/energy_storage/heatexchanger3.lua")
|
--dofile(MP.."/energy_storage/heatexchanger3.lua")
|
||||||
dofile(MP.."/energy_storage/heatexchanger2.lua")
|
--dofile(MP.."/energy_storage/heatexchanger2.lua")
|
||||||
dofile(MP.."/energy_storage/heatexchanger1.lua")
|
--dofile(MP.."/energy_storage/heatexchanger1.lua")
|
||||||
dofile(MP.."/energy_storage/generator.lua")
|
--dofile(MP.."/energy_storage/generator.lua")
|
||||||
dofile(MP.."/energy_storage/turbine.lua")
|
--dofile(MP.."/energy_storage/turbine.lua")
|
||||||
dofile(MP.."/energy_storage/inlet.lua")
|
--dofile(MP.."/energy_storage/inlet.lua")
|
||||||
dofile(MP.."/energy_storage/nodes.lua")
|
--dofile(MP.."/energy_storage/nodes.lua")
|
||||||
|
|
||||||
-- Chemistry
|
-- Chemistry
|
||||||
dofile(MP.."/chemistry/ta4_reactor.lua")
|
--dofile(MP.."/chemistry/ta4_reactor.lua")
|
||||||
dofile(MP.."/chemistry/ta4_stand.lua")
|
--dofile(MP.."/chemistry/ta4_stand.lua")
|
||||||
dofile(MP.."/chemistry/ta4_doser.lua")
|
--dofile(MP.."/chemistry/ta4_doser.lua")
|
||||||
dofile(MP.."/chemistry/ta4_liquid_filter.lua")
|
--dofile(MP.."/chemistry/ta4_liquid_filter.lua")
|
||||||
|
|
||||||
-- Hydrogen
|
-- Hydrogen
|
||||||
dofile(MP.."/hydrogen/fuelcellstack.lua")
|
--dofile(MP.."/hydrogen/fuelcellstack.lua")
|
||||||
dofile(MP.."/hydrogen/electrolyzer.lua")
|
--dofile(MP.."/hydrogen/electrolyzer.lua")
|
||||||
dofile(MP.."/hydrogen/fuelcell.lua")
|
--dofile(MP.."/hydrogen/fuelcell.lua")
|
||||||
|
|
||||||
-- ICTA Controller
|
-- ICTA Controller
|
||||||
dofile(MP.."/icta_controller/submenu.lua")
|
--dofile(MP.."/icta_controller/submenu.lua")
|
||||||
dofile(MP.."/icta_controller/condition.lua")
|
--dofile(MP.."/icta_controller/condition.lua")
|
||||||
dofile(MP.."/icta_controller/action.lua")
|
--dofile(MP.."/icta_controller/action.lua")
|
||||||
dofile(MP.."/icta_controller/formspec.lua")
|
--dofile(MP.."/icta_controller/formspec.lua")
|
||||||
dofile(MP.."/icta_controller/controller.lua")
|
--dofile(MP.."/icta_controller/controller.lua")
|
||||||
dofile(MP.."/icta_controller/commands.lua")
|
--dofile(MP.."/icta_controller/commands.lua")
|
||||||
dofile(MP.."/icta_controller/edit.lua")
|
--dofile(MP.."/icta_controller/edit.lua")
|
||||||
dofile(MP.."/icta_controller/battery.lua")
|
--dofile(MP.."/icta_controller/battery.lua")
|
||||||
dofile(MP.."/icta_controller/display.lua")
|
--dofile(MP.."/icta_controller/display.lua")
|
||||||
dofile(MP.."/icta_controller/signaltower.lua")
|
--dofile(MP.."/icta_controller/signaltower.lua")
|
||||||
|
|
||||||
-- Lua Controller
|
-- Lua Controller
|
||||||
dofile(MP.."/lua_controller/controller.lua")
|
dofile(MP.."/lua_controller/controller.lua")
|
||||||
dofile(MP.."/lua_controller/commands.lua")
|
--dofile(MP.."/lua_controller/commands.lua")
|
||||||
dofile(MP.."/lua_controller/server.lua")
|
--dofile(MP.."/lua_controller/server.lua")
|
||||||
dofile(MP.."/lua_controller/sensorchest.lua")
|
--dofile(MP.."/lua_controller/sensorchest.lua")
|
||||||
dofile(MP.."/lua_controller/terminal.lua")
|
--dofile(MP.."/lua_controller/terminal.lua")
|
||||||
|
|
||||||
-- Items
|
-- Items
|
||||||
dofile(MP.."/items/registered_nodes.lua")
|
--dofile(MP.."/items/registered_nodes.lua")
|
||||||
dofile(MP.."/items/barrel.lua")
|
--dofile(MP.."/items/barrel.lua")
|
||||||
dofile(MP.."/items/baborium.lua")
|
--dofile(MP.."/items/baborium.lua")
|
||||||
dofile(MP.."/items/usmium.lua")
|
--dofile(MP.."/items/usmium.lua")
|
||||||
dofile(MP.."/items/lye.lua")
|
--dofile(MP.."/items/lye.lua")
|
||||||
dofile(MP.."/items/oil.lua")
|
--dofile(MP.."/items/oil.lua")
|
||||||
dofile(MP.."/items/petroleum.lua")
|
--dofile(MP.."/items/petroleum.lua")
|
||||||
dofile(MP.."/items/bauxit.lua")
|
--dofile(MP.."/items/bauxit.lua")
|
||||||
dofile(MP.."/items/silicon.lua")
|
--dofile(MP.."/items/silicon.lua")
|
||||||
dofile(MP.."/items/steelmat.lua")
|
--dofile(MP.."/items/steelmat.lua")
|
||||||
dofile(MP.."/items/powder.lua")
|
--dofile(MP.."/items/powder.lua")
|
||||||
dofile(MP.."/items/epoxy.lua")
|
--dofile(MP.."/items/epoxy.lua")
|
||||||
dofile(MP.."/items/aluminium.lua")
|
--dofile(MP.."/items/aluminium.lua")
|
||||||
dofile(MP.."/items/plastic.lua")
|
--dofile(MP.."/items/plastic.lua")
|
||||||
dofile(MP.."/items/hydrogen.lua")
|
--dofile(MP.."/items/hydrogen.lua")
|
||||||
dofile(MP.."/items/electronic.lua")
|
--dofile(MP.."/items/electronic.lua")
|
||||||
dofile(MP.."/items/redstone.lua")
|
--dofile(MP.."/items/redstone.lua")
|
||||||
dofile(MP.."/items/cement.lua")
|
--dofile(MP.."/items/cement.lua")
|
||||||
dofile(MP.."/items/cracking.lua")
|
--dofile(MP.."/items/cracking.lua")
|
||||||
dofile(MP.."/items/ceramic.lua")
|
--dofile(MP.."/items/ceramic.lua")
|
||||||
dofile(MP.."/items/basalt.lua")
|
--dofile(MP.."/items/basalt.lua")
|
||||||
dofile(MP.."/items/moreblocks.lua")
|
--dofile(MP.."/items/moreblocks.lua")
|
||||||
|
|
||||||
-- Carts
|
-- Carts
|
||||||
dofile(MP.."/carts/tank_cart.lua")
|
--dofile(MP.."/carts/tank_cart.lua")
|
||||||
dofile(MP.."/carts/chest_cart.lua")
|
--dofile(MP.."/carts/chest_cart.lua")
|
||||||
|
|
||||||
|
|
||||||
-- Prevent other mods from using IE
|
-- Prevent other mods from using IE
|
||||||
techage.IE = nil
|
techage.IE = nil
|
||||||
|
|
||||||
|
|
||||||
|
function techage.icta_register_condition(key, tData) end
|
||||||
|
29
items/filling.lua
Normal file
29
items/filling.lua
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-- Needed for the trowel
|
||||||
|
techage.FILLING_ITEMS = {
|
||||||
|
"default:stone",
|
||||||
|
"default:stonebrick",
|
||||||
|
"default:stone_block",
|
||||||
|
"default:clay",
|
||||||
|
"default:snowblock",
|
||||||
|
"default:ice",
|
||||||
|
"default:glass",
|
||||||
|
"default:obsidian_glass",
|
||||||
|
"default:brick",
|
||||||
|
"default:tree",
|
||||||
|
"default:wood",
|
||||||
|
"default:jungletree",
|
||||||
|
"default:junglewood",
|
||||||
|
"default:pine_tree",
|
||||||
|
"default:pine_wood",
|
||||||
|
"default:acacia_tree",
|
||||||
|
"default:acacia_wood",
|
||||||
|
"default:aspen_tree",
|
||||||
|
"default:aspen_wood",
|
||||||
|
"default:steelblock",
|
||||||
|
"default:copperblock",
|
||||||
|
"default:tinblock",
|
||||||
|
"default:bronzeblock",
|
||||||
|
"default:goldblock",
|
||||||
|
"default:mese",
|
||||||
|
"default:diamondblock",
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -19,7 +19,8 @@ local M = minetest.get_meta
|
|||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local MAX_PIPE_LENGHT = 100
|
local MAX_PIPE_LENGHT = 100
|
||||||
local networks = techage.networks
|
|
||||||
|
local power = networks.power
|
||||||
|
|
||||||
local Pipe = tubelib2.Tube:new({
|
local Pipe = tubelib2.Tube:new({
|
||||||
dirs_to_check = {1,2,3,4,5,6},
|
dirs_to_check = {1,2,3,4,5,6},
|
||||||
@ -31,7 +32,7 @@ local Pipe = tubelib2.Tube:new({
|
|||||||
"techage:ta3_pipeS", "techage:ta3_pipeA",
|
"techage:ta3_pipeS", "techage:ta3_pipeA",
|
||||||
"techage:ta3_pipe_wall_entry", "techage:ta3_valve_open",
|
"techage:ta3_pipe_wall_entry", "techage:ta3_valve_open",
|
||||||
},
|
},
|
||||||
secondary_node_names = {"techage:ta3_valve_closed"},
|
secondary_node_names = {},
|
||||||
after_place_tube = function(pos, param2, tube_type, num_tubes)
|
after_place_tube = function(pos, param2, tube_type, num_tubes)
|
||||||
local name = minetest.get_node(pos).name
|
local name = minetest.get_node(pos).name
|
||||||
if name == "techage:ta3_pipe_wall_entry" then
|
if name == "techage:ta3_pipe_wall_entry" then
|
||||||
@ -44,6 +45,11 @@ local Pipe = tubelib2.Tube:new({
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Use global callback instead of node related functions
|
||||||
|
Pipe:register_on_tube_update2(function(pos, outdir, tlib2, node)
|
||||||
|
power.update_network(pos, outdir, tlib2, node)
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_node("techage:ta3_pipeS", {
|
minetest.register_node("techage:ta3_pipeS", {
|
||||||
description = S("TA Pipe"),
|
description = S("TA Pipe"),
|
||||||
tiles = {
|
tiles = {
|
||||||
@ -150,9 +156,11 @@ local Boxes = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, Pipe, {
|
local names = networks.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, Pipe, {
|
||||||
description = S("TA Junction Pipe"),
|
description = S("TA Junction Pipe"),
|
||||||
tiles = {"techage_gaspipe_junction.png"},
|
tiles = {"techage_gaspipe_junction.png"},
|
||||||
|
use_texture_alpha = "clip",
|
||||||
|
is_ground_content = false,
|
||||||
groups = {crumbly = 2, cracky = 2, snappy = 2, techage_trowel = 1},
|
groups = {crumbly = 2, cracky = 2, snappy = 2, techage_trowel = 1},
|
||||||
sounds = default.node_sound_metal_defaults(),
|
sounds = default.node_sound_metal_defaults(),
|
||||||
|
|
||||||
@ -164,19 +172,15 @@ techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, Pipe, {
|
|||||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
||||||
local name = "techage:ta3_junctionpipe"..techage.junction_type(pos, Pipe)
|
local name = "techage:ta3_junctionpipe"..techage.junction_type(pos, Pipe)
|
||||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||||
techage.liquid.update_network(pos)
|
power.update_network(pos, 0, tlib2, node)
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Pipe:after_dig_node(pos)
|
Pipe:after_dig_node(pos)
|
||||||
end,
|
end,
|
||||||
networks = {
|
|
||||||
pipe2 = {
|
|
||||||
sides = networks.AllSides, -- connection sides for pipes
|
|
||||||
ntype = "junc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, 25)
|
}, 25)
|
||||||
|
|
||||||
|
power.register_nodes(names, Pipe, "junc")
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:ta3_junctionpipe25 2",
|
output = "techage:ta3_junctionpipe25 2",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
4
mod.conf
4
mod.conf
@ -1,4 +1,4 @@
|
|||||||
name = techage
|
name = techage
|
||||||
depends = default,doors,flowers,tubelib2,basic_materials,bucket,stairs,screwdriver,minecart,lcdlib,safer_lua
|
depends = default,doors,flowers,tubelib2,networks,basic_materials,bucket,stairs,screwdriver,minecart,lcdlib,safer_lua
|
||||||
optional_depends = unified_inventory,wielded_light,unifieddyes,moreores,ethereal,mesecon,digtron,bakedclay,moreblocks
|
optional_depends = unified_inventory,wielded_light,unifieddyes,moreores,ethereal,mesecon,digtron,bakedclay,moreblocks,autobahn
|
||||||
description = Techage, go through 4 tech ages in search of wealth and power!
|
description = Techage, go through 4 tech ages in search of wealth and power!
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -17,13 +17,15 @@ local P = minetest.string_to_pos
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
|
local power = networks.power
|
||||||
|
|
||||||
local Axle = tubelib2.Tube:new({
|
local Axle = tubelib2.Tube:new({
|
||||||
dirs_to_check = {1,2,3,4,5,6},
|
dirs_to_check = {1,2,3,4,5,6},
|
||||||
max_tube_length = 8,
|
max_tube_length = 8,
|
||||||
show_infotext = false,
|
show_infotext = false,
|
||||||
tube_type = "axle",
|
tube_type = "axle",
|
||||||
primary_node_names = {"techage:axle", "techage:axle_on"},
|
primary_node_names = {"techage:axle", "techage:axle_on"},
|
||||||
secondary_node_names = {"techage:flywheel", "techage:flywheel_on", "techage:gearbox", "techage:gearbox_on"},
|
secondary_node_names = {},
|
||||||
after_place_tube = function(pos, param2, tube_type, num_tubes, state)
|
after_place_tube = function(pos, param2, tube_type, num_tubes, state)
|
||||||
if state == "on" then
|
if state == "on" then
|
||||||
minetest.swap_node(pos, {name = "techage:axle_on", param2 = param2})
|
minetest.swap_node(pos, {name = "techage:axle_on", param2 = param2})
|
||||||
@ -33,6 +35,10 @@ local Axle = tubelib2.Tube:new({
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Use global callback instead of node related functions
|
||||||
|
Axle:register_on_tube_update2(function(pos, outdir, tlib2, node)
|
||||||
|
power.update_network(pos, outdir, tlib2, node)
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_node("techage:axle", {
|
minetest.register_node("techage:axle", {
|
||||||
description = S("TA2 Drive Axle"),
|
description = S("TA2 Drive Axle"),
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -18,7 +18,7 @@ local P2S = minetest.pos_to_string
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
|
|
||||||
local ELE1_MAX_CABLE_LENGHT = 1000
|
local ELE1_MAX_CABLE_LENGHT = 1000
|
||||||
|
|
||||||
@ -29,56 +29,32 @@ local Cable = tubelib2.Tube:new({
|
|||||||
tube_type = "ele1",
|
tube_type = "ele1",
|
||||||
primary_node_names = {"techage:electric_cableS", "techage:electric_cableA",
|
primary_node_names = {"techage:electric_cableS", "techage:electric_cableA",
|
||||||
"techage:power_line", "techage:power_lineS", "techage:power_lineA",
|
"techage:power_line", "techage:power_lineS", "techage:power_lineA",
|
||||||
"techage:power_pole2", "techage:powerswitch_box"},
|
"techage:power_pole2", "techage:powerswitch_box", "techage:powerswitch_box_on"},
|
||||||
secondary_node_names = {},
|
secondary_node_names = {},
|
||||||
after_place_tube = function(pos, param2, tube_type, num_tubes)
|
after_place_tube = function(pos, param2, tube_type, num_tubes)
|
||||||
|
if networks.node_to_be_replaced(pos, param2, tube_type, num_tubes) then
|
||||||
-- Handle "power line" nodes
|
-- Handle "power line" nodes
|
||||||
local name = minetest.get_node(pos).name
|
local name = minetest.get_node(pos).name
|
||||||
if name == "techage:power_pole2" then
|
if name == "techage:powerswitch_box" or name == "techage:powerswitch_box_on" or name == "techage:powerswitch_box_off" then
|
||||||
M(pos):set_int("tl2_param2", param2)
|
minetest.swap_node(pos, {name = name, param2 = param2 % 32})
|
||||||
return
|
|
||||||
elseif name == "techage:powerswitch_box" then
|
|
||||||
minetest.swap_node(pos, {name = "techage:powerswitch_box", param2 = param2 % 32})
|
|
||||||
M(pos):set_int("tl2_param2", param2)
|
|
||||||
return
|
|
||||||
elseif name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then
|
elseif name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then
|
||||||
minetest.swap_node(pos, {name = "techage:power_line"..tube_type, param2 = param2 % 32})
|
minetest.swap_node(pos, {name = "techage:power_line"..tube_type, param2 = param2 % 32})
|
||||||
M(pos):set_int("tl2_param2", param2)
|
else
|
||||||
return
|
|
||||||
end
|
|
||||||
-- Don't replace "hidden" cable
|
|
||||||
if M(pos):get_string("techage_hidden_nodename") == "" then
|
|
||||||
minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32})
|
minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32})
|
||||||
end
|
end
|
||||||
M(pos):set_int("tl2_param2", param2)
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Enable hidden cables
|
||||||
|
networks.use_metadata(Cable)
|
||||||
|
networks.register_hidden_message("Use the tool to remove the node.")
|
||||||
|
networks.register_filling_items(techage.FILLING_ITEMS)
|
||||||
|
|
||||||
-- Overridden method of tubelib2!
|
-- Use global callback instead of node related functions
|
||||||
function Cable:get_primary_node_param2(pos, dir)
|
Cable:register_on_tube_update2(function(pos, outdir, tlib2, node)
|
||||||
return techage.get_primary_node_param2(pos, dir)
|
power.update_network(pos, outdir, tlib2, node)
|
||||||
end
|
end)
|
||||||
|
|
||||||
function Cable:is_primary_node(pos, dir)
|
|
||||||
return techage.is_primary_node(pos, dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Cable:get_secondary_node(pos, dir)
|
|
||||||
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
|
|
||||||
local node = self:get_node_lvm(npos)
|
|
||||||
if self.secondary_node_names[node.name] or
|
|
||||||
self.secondary_node_names[M(npos):get_string("techage_hidden_nodename")] then
|
|
||||||
return node, npos, true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Cable:is_secondary_node(pos, dir)
|
|
||||||
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
|
|
||||||
local node = self:get_node_lvm(npos)
|
|
||||||
return self.secondary_node_names[node.name] or
|
|
||||||
self.secondary_node_names[M(npos):get_string("techage_hidden_nodename")]
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_node("techage:electric_cableS", {
|
minetest.register_node("techage:electric_cableS", {
|
||||||
description = S("TA Electric Cable"),
|
description = S("TA Electric Cable"),
|
||||||
@ -163,11 +139,6 @@ minetest.register_node("techage:electric_cableA", {
|
|||||||
drop = "techage:electric_cableS",
|
drop = "techage:electric_cableS",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- only needed for hidden nodes, cause they don't have a tubelib2_on_update2 callback
|
|
||||||
Cable:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
|
|
||||||
power.update_network(pos, nil, Cable)
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:electric_cableS 6",
|
output = "techage:electric_cableS 6",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
@ -17,6 +17,12 @@
|
|||||||
--local N = function(pos) return minetest.get_node(pos).name end
|
--local N = function(pos) return minetest.get_node(pos).name end
|
||||||
--local S = techage.S
|
--local S = techage.S
|
||||||
local in_range = techage.in_range
|
local in_range = techage.in_range
|
||||||
|
local power = networks.power
|
||||||
|
techage.power = {}
|
||||||
|
|
||||||
|
local function round(val)
|
||||||
|
return math.floor((val * 10) + 0.5) / 10
|
||||||
|
end
|
||||||
|
|
||||||
function techage.power.percent(max_val, curr_val)
|
function techage.power.percent(max_val, curr_val)
|
||||||
return math.min(math.ceil(((curr_val or 0) * 100) / (max_val or 1.0)), 100)
|
return math.min(math.ceil(((curr_val or 0) * 100) / (max_val or 1.0)), 100)
|
||||||
@ -48,15 +54,16 @@ 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(pos, x, y, label, max_power, current_power, unit)
|
function techage.power.formspec_label_bar(pos, x, y, tlib2, label, max_power, current_power, unit)
|
||||||
local percent, ypos
|
local percent, ypos
|
||||||
|
|
||||||
max_power = max_power or 1
|
max_power = max_power or 1
|
||||||
|
current_power = round(current_power or 0)
|
||||||
unit = unit or "ku"
|
unit = unit or "ku"
|
||||||
|
|
||||||
if current_power == 0 then
|
if current_power > 0 then
|
||||||
-- check if power network is overloaded
|
-- check if power network is overloaded
|
||||||
if techage.power.network_overloaded(pos, techage.ElectricCable) then
|
if not power.power_available(pos, tlib2) then
|
||||||
return "container["..x..","..y.."]"..
|
return "container["..x..","..y.."]"..
|
||||||
"box[0,0;2.3,3.3;#395c74]"..
|
"box[0,0;2.3,3.3;#395c74]"..
|
||||||
"label[0.2,0;"..label.."]"..
|
"label[0.2,0;"..label.."]"..
|
||||||
@ -65,7 +72,7 @@ function techage.power.formspec_label_bar(pos, x, y, label, max_power, current_p
|
|||||||
"container_end[]"
|
"container_end[]"
|
||||||
end
|
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
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -18,15 +18,14 @@ local M = minetest.get_meta
|
|||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local PWR_NEEDED = 1
|
local PWR_NEEDED = 1
|
||||||
local CYCLE_TIME = 4
|
local CYCLE_TIME = 2
|
||||||
|
|
||||||
local Axle = techage.Axle
|
local Axle = techage.Axle
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
local networks = techage.networks
|
|
||||||
|
|
||||||
-- Axles texture animation
|
-- Axles texture animation
|
||||||
local function switch_axles(pos, on)
|
local function switch_axles(pos, on)
|
||||||
for _,outdir in ipairs(networks.get_node_connections(pos, "axle")) do
|
for _,outdir in ipairs(networks.get_outdirs(pos, Axle)) do
|
||||||
Axle:switch_tube_line(pos, outdir, on and "on" or "off")
|
Axle:switch_tube_line(pos, outdir, on and "on" or "off")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -40,63 +39,56 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_power(pos)
|
local function node_timer_on(pos, elapsed)
|
||||||
swap_node(pos, "techage:gearbox_on")
|
local consumed = power.consume_power(pos, Axle, 0, PWR_NEEDED)
|
||||||
switch_axles(pos, true)
|
if consumed == 0 then
|
||||||
end
|
|
||||||
|
|
||||||
local function on_nopower(pos)
|
|
||||||
swap_node(pos, "techage:gearbox")
|
swap_node(pos, "techage:gearbox")
|
||||||
switch_axles(pos, false)
|
switch_axles(pos, false)
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
local function node_timer_off(pos, elapsed)
|
||||||
power.consumer_alive(pos, Axle, CYCLE_TIME)
|
if power.power_available(pos, Axle, 0) then
|
||||||
|
swap_node(pos, "techage:gearbox_on")
|
||||||
|
switch_axles(pos, true)
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- to be able to restart the node after server crashes
|
-- to be able to restart the node after server crashes
|
||||||
local function techage_on_repair(pos)
|
local function techage_on_repair(pos)
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
power.consumer_start(pos, Axle, CYCLE_TIME)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function after_place_node(pos)
|
local function after_place_node(pos)
|
||||||
Axle:after_place_node(pos)
|
Axle:after_place_node(pos)
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
power.consumer_start(pos, Axle, CYCLE_TIME)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function after_dig_node(pos, oldnode)
|
local function after_dig_node(pos, oldnode)
|
||||||
Axle:after_dig_node(pos)
|
Axle:after_dig_node(pos)
|
||||||
techage.del_mem(pos)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
local function tubelib2_on_update2_on(pos, outdir, tlib2, node)
|
||||||
power.update_network(pos, nil, tlib2)
|
power.update_network(pos, 0, tlib2, node)
|
||||||
|
switch_axles(pos, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local net_def = {
|
local function tubelib2_on_update2_off(pos, outdir, tlib2, node)
|
||||||
axle = {
|
power.update_network(pos, 0, tlib2, node)
|
||||||
sides = techage.networks.AllSides, -- Cable connection sides
|
switch_axles(pos, false)
|
||||||
ntype = {"con1", "junc"},
|
end
|
||||||
on_power = on_power,
|
|
||||||
on_nopower = on_nopower,
|
|
||||||
nominal = PWR_NEEDED,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:gearbox", {
|
minetest.register_node("techage:gearbox", {
|
||||||
description = S("TA2 Gearbox"),
|
description = S("TA2 Gearbox"),
|
||||||
tiles = {"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png"},
|
tiles = {"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png"},
|
||||||
|
|
||||||
on_timer = node_timer,
|
on_timer = node_timer_off,
|
||||||
techage_on_repair = techage_on_repair,
|
techage_on_repair = techage_on_repair,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
tubelib2_on_update2 = tubelib2_on_update2_off,
|
||||||
networks = net_def,
|
|
||||||
|
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
light_source = 0,
|
light_source = 0,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -122,13 +114,11 @@ minetest.register_node("techage:gearbox_on", {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
on_timer = node_timer,
|
on_timer = node_timer_on,
|
||||||
techage_on_repair = techage_on_repair,
|
techage_on_repair = techage_on_repair,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
tubelib2_on_update2 = tubelib2_on_update2_on,
|
||||||
networks = net_def,
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
diggable = false,
|
diggable = false,
|
||||||
@ -138,7 +128,7 @@ minetest.register_node("techage:gearbox_on", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Axle:add_secondary_node_names({"techage:gearbox", "techage:gearbox_on"})
|
power.register_nodes({"techage:gearbox", "techage:gearbox_on"}, Axle, "junc")
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:gearbox 2",
|
output = "techage:gearbox 2",
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
--[[
|
|
||||||
|
|
||||||
TechAge
|
|
||||||
=======
|
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
|
||||||
|
|
||||||
AGPL v3
|
|
||||||
See LICENSE.txt for more information
|
|
||||||
|
|
||||||
Junction for power distribution
|
|
||||||
|
|
||||||
]]--
|
|
||||||
|
|
||||||
-- for lazy programmers
|
|
||||||
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
|
||||||
local P = minetest.string_to_pos
|
|
||||||
local M = minetest.get_meta
|
|
||||||
|
|
||||||
|
|
||||||
local function bit(p)
|
|
||||||
return 2 ^ (p - 1) -- 1-based indexing
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Typical call: if hasbit(x, bit(3)) then ...
|
|
||||||
local function hasbit(x, p)
|
|
||||||
return x % (p + p) >= p
|
|
||||||
end
|
|
||||||
|
|
||||||
local function setbit(x, p)
|
|
||||||
return hasbit(x, p) and x or x + p
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_node_box(val, size, boxes)
|
|
||||||
local fixed = {{-size, -size, -size, size, size, size}}
|
|
||||||
for i = 1,6 do
|
|
||||||
if hasbit(val, bit(i)) then
|
|
||||||
for _,box in ipairs(boxes[i]) do
|
|
||||||
table.insert(fixed, box)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = fixed,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 'size' is the size of the junction cube without any connection, e.g. 1/8
|
|
||||||
-- 'boxes' is a table with 6 table elements for the 6 possible connection arms
|
|
||||||
-- 'tlib2' is the tubelib2 instance
|
|
||||||
-- 'node' is the node definition with tiles, callback functions, and so on
|
|
||||||
-- 'index' number for the inventory node (default 0)
|
|
||||||
function techage.register_junction(name, size, boxes, tlib2, node, index)
|
|
||||||
local names = {}
|
|
||||||
for idx = 0,63 do
|
|
||||||
local ndef = table.copy(node)
|
|
||||||
if idx == (index or 0) then
|
|
||||||
ndef.groups.not_in_creative_inventory = 0
|
|
||||||
else
|
|
||||||
ndef.groups.not_in_creative_inventory = 1
|
|
||||||
end
|
|
||||||
ndef.groups.techage_trowel = 1
|
|
||||||
ndef.drawtype = "nodebox"
|
|
||||||
ndef.node_box = get_node_box(idx, size, boxes)
|
|
||||||
ndef.paramtype2 = "facedir"
|
|
||||||
ndef.on_rotate = screwdriver.disallow
|
|
||||||
ndef.paramtype = "light"
|
|
||||||
ndef.use_texture_alpha = techage.CLIP
|
|
||||||
ndef.sunlight_propagates = true
|
|
||||||
ndef.is_ground_content = false
|
|
||||||
ndef.drop = name..(index or "0")
|
|
||||||
minetest.register_node(name..idx, ndef)
|
|
||||||
tlib2:add_secondary_node_names({name..idx})
|
|
||||||
-- for the case that 'tlib2.force_to_use_tubes' is set
|
|
||||||
tlib2:add_special_node_names({name..idx})
|
|
||||||
names[#names + 1] = name..idx
|
|
||||||
end
|
|
||||||
return names
|
|
||||||
end
|
|
||||||
|
|
||||||
local SideToDir = {B=1, R=2, F=3, L=4}
|
|
||||||
local function dir_to_dir2(dir, param2)
|
|
||||||
if param2 == 0 then
|
|
||||||
return dir
|
|
||||||
elseif param2 == 1 then
|
|
||||||
return ({4,1,2,3,5,6})[dir]
|
|
||||||
elseif param2 == 2 then
|
|
||||||
return ({3,4,1,2,5,6})[dir]
|
|
||||||
elseif param2 == 3 then
|
|
||||||
return ({2,3,4,1,5,6})[dir]
|
|
||||||
end
|
|
||||||
return dir
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.junction_type(pos, network, default_side, param2)
|
|
||||||
local connected = function(self, pos, dir)
|
|
||||||
if network:is_primary_node(pos, dir) then
|
|
||||||
local param2, npos = self:get_primary_node_param2(pos, dir)
|
|
||||||
if param2 then
|
|
||||||
local d1, d2, num = self:decode_param2(npos, param2)
|
|
||||||
dir = tubelib2.Turn180Deg[dir]
|
|
||||||
return d1 == dir or dir == d2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local val = 0
|
|
||||||
if default_side then
|
|
||||||
val = setbit(val, bit(SideToDir[default_side]))
|
|
||||||
end
|
|
||||||
for dir = 1,6 do
|
|
||||||
local dir2 = dir_to_dir2(dir, param2)
|
|
||||||
if network.force_to_use_tubes then
|
|
||||||
if connected(network, pos, dir) then
|
|
||||||
val = setbit(val, bit(dir2))
|
|
||||||
elseif network:is_special_node(pos, dir) then
|
|
||||||
val = setbit(val, bit(dir2))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if connected(network, pos, dir) then
|
|
||||||
val = setbit(val, bit(dir2))
|
|
||||||
elseif network:is_secondary_node(pos, dir) then
|
|
||||||
val = setbit(val, bit(dir2))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
|
|
@ -16,9 +16,8 @@
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local networks = techage.networks
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
|
|
||||||
local size = 3/32
|
local size = 3/32
|
||||||
local Boxes = {
|
local Boxes = {
|
||||||
@ -30,33 +29,31 @@ local Boxes = {
|
|||||||
{{-size, -size, -size, size, 0.5, size}}, -- y+
|
{{-size, -size, -size, size, 0.5, size}}, -- y+
|
||||||
}
|
}
|
||||||
|
|
||||||
techage.register_junction("techage:electric_junction", 2/8, Boxes, Cable, {
|
local names = networks.register_junction("techage:electric_junction", 2/8, Boxes, Cable, {
|
||||||
description = S("TA Electric Junction Box"),
|
description = S("TA Electric Junction Box"),
|
||||||
tiles = {"techage_electric_junction.png"},
|
tiles = {"techage_electric_junction.png"},
|
||||||
|
use_texture_alpha = "clip",
|
||||||
|
is_ground_content = false,
|
||||||
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1},
|
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1},
|
||||||
sounds = default.node_sound_defaults(),
|
sounds = default.node_sound_defaults(),
|
||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local name = "techage:electric_junction"..techage.junction_type(pos, Cable)
|
local name = "techage:electric_junction" .. networks.junction_type(pos, Cable)
|
||||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||||
Cable:after_place_node(pos)
|
Cable:after_place_node(pos)
|
||||||
end,
|
end,
|
||||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
||||||
local name = "techage:electric_junction"..techage.junction_type(pos, Cable)
|
local name = "techage:electric_junction" .. networks.junction_type(pos, Cable)
|
||||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||||
power.update_network(pos, nil, tlib2)
|
power.update_network(pos, 0, tlib2, node)
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Cable:after_dig_node(pos)
|
Cable:after_dig_node(pos)
|
||||||
end,
|
end,
|
||||||
networks = {
|
|
||||||
ele1 = {
|
|
||||||
sides = networks.AllSides, -- connection sides for cables
|
|
||||||
ntype = "junc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
power.register_nodes(names, Cable, "junc")
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:electric_junction0 2",
|
output = "techage:electric_junction0 2",
|
||||||
recipe = {
|
recipe = {
|
||||||
|
@ -1,262 +0,0 @@
|
|||||||
--[[
|
|
||||||
|
|
||||||
TechAge
|
|
||||||
=======
|
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
|
||||||
|
|
||||||
AGPL v3
|
|
||||||
See LICENSE.txt for more information
|
|
||||||
|
|
||||||
API for Power Nodes
|
|
||||||
|
|
||||||
]]--
|
|
||||||
|
|
||||||
--local P2S = minetest.pos_to_string
|
|
||||||
--local M = minetest.get_meta
|
|
||||||
--local N = function(pos) return minetest.get_node(pos).name end
|
|
||||||
--local S = techage.S
|
|
||||||
|
|
||||||
local net_def = techage.networks.net_def
|
|
||||||
local networks = techage.networks
|
|
||||||
|
|
||||||
-- Consumer States
|
|
||||||
local STOPPED = 1
|
|
||||||
local NOPOWER = 2
|
|
||||||
local RUNNING = 3
|
|
||||||
|
|
||||||
techage.power = {}
|
|
||||||
|
|
||||||
techage.power.STOPPED = STOPPED
|
|
||||||
techage.power.NOPOWER = NOPOWER
|
|
||||||
techage.power.RUNNING = RUNNING
|
|
||||||
|
|
||||||
-- determine network ID (largest hash number of all generators)
|
|
||||||
local function determine_netID(pos, outdir, Cable)
|
|
||||||
local netID = 0
|
|
||||||
networks.connection_walk(pos, outdir, Cable, function(pos, indir, node)
|
|
||||||
local ntype = net_def(pos, Cable.tube_type).ntype
|
|
||||||
if ntype ~= "junc" then
|
|
||||||
local new = minetest.hash_node_position(pos)
|
|
||||||
if netID <= new then
|
|
||||||
netID = new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
return netID
|
|
||||||
end
|
|
||||||
|
|
||||||
-- store network ID on each node
|
|
||||||
local function store_netID(pos, outdir, netID, Cable)
|
|
||||||
networks.connection_walk(pos, outdir, Cable, function(pos, indir, node)
|
|
||||||
--techage.mark_position("singleplayer", pos, "store", "", 2)-----------------------------------------
|
|
||||||
--print(node.name, dump(net_def(pos, Cable.tube_type)))
|
|
||||||
if net_def(pos, Cable.tube_type) then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
nvm[Cable.tube_type] = nvm[Cable.tube_type] or {}
|
|
||||||
nvm[Cable.tube_type]["netID"] = netID
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- delete network and ID on each node
|
|
||||||
local function delete_netID(pos, outdir, Cable)
|
|
||||||
local netID = 0
|
|
||||||
networks.connection_walk(pos, outdir, Cable, function(pos, indir, node)
|
|
||||||
--techage.mark_position("singleplayer", pos, "delete", "", 2)----------------------------------------
|
|
||||||
if net_def(pos, Cable.tube_type) then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
if nvm[Cable.tube_type] and nvm[Cable.tube_type]["netID"] then
|
|
||||||
netID = nvm[Cable.tube_type]["netID"]
|
|
||||||
nvm[Cable.tube_type]["netID"] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
networks.delete_network(Cable.tube_type, netID)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Keep the network up and running
|
|
||||||
local function trigger_network(pos, outdir, Cable)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local netID = nvm[Cable.tube_type] and nvm[Cable.tube_type]["netID"]
|
|
||||||
if not netID then
|
|
||||||
--print("determine_netID !!!!!!!!!!!!!!!!!!!!")
|
|
||||||
netID = determine_netID(pos, outdir, Cable)
|
|
||||||
store_netID(pos, outdir, netID, Cable)
|
|
||||||
networks.build_network(pos, outdir, Cable, netID)
|
|
||||||
elseif not networks.get_network(Cable.tube_type, netID) then
|
|
||||||
--print("build_network !!!!!!!!!!!!!!!!!!!!")
|
|
||||||
netID = determine_netID(pos, outdir, Cable)
|
|
||||||
store_netID(pos, outdir, netID, Cable)
|
|
||||||
networks.build_network(pos, outdir, Cable, netID)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function build_network_consumer(pos, Cable)
|
|
||||||
local outdirs = techage.networks.get_node_connections(pos, Cable.tube_type)
|
|
||||||
if #outdirs == 1 then
|
|
||||||
local netID = determine_netID(pos, outdirs[1], Cable)
|
|
||||||
store_netID(pos, outdirs[1], netID, Cable)
|
|
||||||
networks.build_network(pos, outdirs[1], Cable, netID)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- To be called from each node via 'tubelib2_on_update2'
|
|
||||||
-- 'output' is optional and only needed for nodes with dedicated
|
|
||||||
-- pipe sides (e.g. pumps).
|
|
||||||
function techage.power.update_network(pos, outdir, Cable)
|
|
||||||
networks.node_connections(pos, Cable) -- update node internal data
|
|
||||||
delete_netID(pos, outdir, Cable) -- network walk to delete all IDs
|
|
||||||
end
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Read the current power value from all connected devices (used for solar cells)
|
|
||||||
-- Only used by the solar inverter to collect the power of all solar cells.
|
|
||||||
-- Only one inverter per network is allowed. Therefore, we have to check,
|
|
||||||
-- if additional inverters are in the network.
|
|
||||||
-- Function returns in addition the number of found inverters.
|
|
||||||
function techage.power.get_power(pos, outdir, Cable, inverter)
|
|
||||||
local sum = 0
|
|
||||||
local num_inverter = 0
|
|
||||||
networks.connection_walk(pos, outdir, Cable, function(pos, indir, node)
|
|
||||||
--techage.mark_position("singleplayer", pos, "get_power", "", 2)-----------------------------------------
|
|
||||||
local def = net_def(pos, Cable.tube_type)
|
|
||||||
if def and def.on_getpower then
|
|
||||||
sum = sum + def.on_getpower(pos)
|
|
||||||
else
|
|
||||||
local node = techage.get_node_lvm(pos)
|
|
||||||
if node.name == inverter then
|
|
||||||
num_inverter = num_inverter + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
return sum, num_inverter
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Consumer related functions
|
|
||||||
--
|
|
||||||
|
|
||||||
-- function checks for a power grid, not for enough power
|
|
||||||
function techage.power.power_available(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)
|
|
||||||
return netw and netw.on and netw.alive and netw.alive > 0
|
|
||||||
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()
|
|
||||||
function techage.power.consumer_start(pos, Cable, cycle_time)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local tlib_type = Cable.tube_type
|
|
||||||
nvm[tlib_type] = nvm[tlib_type] or {}
|
|
||||||
nvm[tlib_type]["calive"] = (cycle_time / 2) + 1
|
|
||||||
nvm[tlib_type]["cstate"] = NOPOWER
|
|
||||||
nvm[tlib_type]["taken"] = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.power.consumer_stop(pos, Cable)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local tlib_type = Cable.tube_type
|
|
||||||
nvm[tlib_type] = nvm[tlib_type] or {}
|
|
||||||
nvm[tlib_type]["calive"] = -1
|
|
||||||
nvm[tlib_type]["cstate"] = STOPPED
|
|
||||||
nvm[tlib_type]["taken"] = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.power.consumer_alive(pos, Cable, cycle_time)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local def = nvm[Cable.tube_type] -- power related network data
|
|
||||||
if def then
|
|
||||||
-- if network is deleted (cable removed/placed) rebuild it to prevent flickering lights
|
|
||||||
if not def["netID"] or not networks.get_network(Cable.tube_type, def["netID"]) then
|
|
||||||
build_network_consumer(pos, Cable)
|
|
||||||
end
|
|
||||||
local rv = (cycle_time / 2) + 1
|
|
||||||
if def["netID"] and def["calive"] and def["calive"] < rv then -- network available
|
|
||||||
def["calive"] = rv
|
|
||||||
return def["taken"] or 0
|
|
||||||
elseif not def["cstate"] or def["cstate"] == RUNNING then
|
|
||||||
local ndef = net_def(pos, Cable.tube_type)
|
|
||||||
ndef.on_nopower(pos, Cable.tube_type)
|
|
||||||
def["cstate"] = NOPOWER
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local ndef = net_def(pos, Cable.tube_type)
|
|
||||||
ndef.on_nopower(pos, Cable.tube_type)
|
|
||||||
end
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Generator related functions
|
|
||||||
--
|
|
||||||
-- curr_power is optional, only needed for generators with variable output power
|
|
||||||
function techage.power.generator_start(pos, Cable, cycle_time, outdir, curr_power)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local tlib_type = Cable.tube_type
|
|
||||||
nvm[tlib_type] = nvm[tlib_type] or {}
|
|
||||||
nvm[tlib_type]["galive"] = (cycle_time / 2) + 2
|
|
||||||
nvm[tlib_type]["gstate"] = RUNNING
|
|
||||||
nvm[tlib_type]["given"] = 0
|
|
||||||
nvm[tlib_type]["curr_power"] = curr_power
|
|
||||||
trigger_network(pos, outdir, Cable)
|
|
||||||
end
|
|
||||||
|
|
||||||
function techage.power.generator_stop(pos, Cable, outdir)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local tlib_type = Cable.tube_type
|
|
||||||
nvm[tlib_type] = nvm[tlib_type] or {}
|
|
||||||
nvm[tlib_type]["galive"] = -1
|
|
||||||
nvm[tlib_type]["gstate"] = STOPPED
|
|
||||||
nvm[tlib_type]["given"] = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- curr_power is optional, only needed for generators with variable output power
|
|
||||||
function techage.power.generator_alive(pos, Cable, cycle_time, outdir, curr_power)
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local def = nvm[Cable.tube_type] -- power related network data
|
|
||||||
if def then
|
|
||||||
trigger_network(pos, outdir, Cable)
|
|
||||||
def["galive"] = (cycle_time / 2) + 2
|
|
||||||
def["curr_power"] = curr_power
|
|
||||||
return def["given"] or 0
|
|
||||||
end
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Calculate the needed power over all con1 consumers
|
|
||||||
function techage.power.needed_power(pos, Cable, outdir)
|
|
||||||
local sum = 0
|
|
||||||
networks.connection_walk(pos, outdir, Cable, function(pos, indir, node)
|
|
||||||
local net = net_def(pos, Cable.tube_type) -- network definition
|
|
||||||
if net.ntype == "con1" then
|
|
||||||
local nvm = techage.get_nvm(pos)
|
|
||||||
local def = nvm[Cable.tube_type] -- power related data
|
|
||||||
|
|
||||||
if def and def["cstate"] and def["cstate"] ~= STOPPED then
|
|
||||||
if def["calive"] >= 0 then
|
|
||||||
sum = sum + (net.nominal or def.curr_power or 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
return sum
|
|
||||||
end
|
|
||||||
|
|
||||||
-- function delete_netID(pos, outdir, Cable)
|
|
||||||
techage.power.delete_netID = delete_netID
|
|
@ -16,9 +16,8 @@ local P = minetest.string_to_pos
|
|||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local networks = techage.networks
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
|
|
||||||
local function can_dig(pos, digger)
|
local function can_dig(pos, digger)
|
||||||
if M(pos):get_string("owner") == digger:get_player_name() then
|
if M(pos):get_string("owner") == digger:get_player_name() then
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -19,28 +19,29 @@ local N = function(pos) return minetest.get_node(pos).name end
|
|||||||
local S = techage.S
|
local S = techage.S
|
||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
|
local power = networks.power
|
||||||
|
|
||||||
-- primary power node
|
local node_box = {
|
||||||
minetest.register_node("techage:powerswitch_box", {
|
|
||||||
description = S("TA Power Switch Box"),
|
|
||||||
tiles = {
|
|
||||||
-- up, down, right, left, back, front
|
|
||||||
'techage_electric_switch.png^[transformR90',
|
|
||||||
'techage_electric_switch.png^[transformR90',
|
|
||||||
'techage_electric_switch.png',
|
|
||||||
'techage_electric_switch.png',
|
|
||||||
'techage_electric_junction.png',
|
|
||||||
'techage_electric_junction.png',
|
|
||||||
},
|
|
||||||
|
|
||||||
drawtype = "nodebox",
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {
|
fixed = {
|
||||||
{ -1/4, -1/4, -2/4, 1/4, 1/4, 2/4},
|
{ -1/4, -1/4, -2/4, 1/4, 1/4, 2/4},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
|
||||||
|
-- The on-switch is a "primary node" like cables
|
||||||
|
minetest.register_node("techage:powerswitch_box_on", {
|
||||||
|
description = S("TA Power Switch Box"),
|
||||||
|
paramtype = "light",
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = node_box,
|
||||||
|
tiles = {
|
||||||
|
"techage_electric_switch.png^[transformR90",
|
||||||
|
"techage_electric_switch.png^[transformR90",
|
||||||
|
"techage_electric_switch.png",
|
||||||
|
"techage_electric_switch.png",
|
||||||
|
"techage_electric_junction.png",
|
||||||
|
"techage_electric_junction.png",
|
||||||
|
},
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
if not Cable:after_place_tube(pos, placer, pointed_thing) then
|
if not Cable:after_place_tube(pos, placer, pointed_thing) then
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
@ -48,23 +49,65 @@ minetest.register_node("techage:powerswitch_box", {
|
|||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
on_rightclick = function(pos, node, clicker)
|
||||||
|
if power.turn_switch_off(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then
|
||||||
|
minetest.sound_play("doors_glass_door_open", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1,
|
||||||
|
max_hear_distance = 5})
|
||||||
|
end
|
||||||
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
paramtype = "light",
|
|
||||||
use_texture_alpha = techage.CLIP,
|
|
||||||
sunlight_propagates = true,
|
|
||||||
on_rotate = screwdriver.disallow, -- important!
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1},
|
on_rotate = screwdriver.disallow,
|
||||||
|
use_texture_alpha = "clip",
|
||||||
|
sunlight_propagates = true,
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
sounds = default.node_sound_wood_defaults(),
|
groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1},
|
||||||
|
sounds = default.node_sound_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- The off-switch is a "secondary node" without connection sides
|
||||||
|
minetest.register_node("techage:powerswitch_box_off", {
|
||||||
|
description = S("TA Power Switch Box"),
|
||||||
|
paramtype = "light",
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = node_box,
|
||||||
|
tiles = {
|
||||||
|
"techage_electric_switch_off.png^[transformR90",
|
||||||
|
"techage_electric_switch_off.png^[transformR90",
|
||||||
|
"techage_electric_switch_off.png",
|
||||||
|
"techage_electric_switch_off.png",
|
||||||
|
"techage_electric_junction.png",
|
||||||
|
"techage_electric_junction.png",
|
||||||
|
},
|
||||||
|
on_rightclick = function(pos, node, clicker)
|
||||||
|
if power.turn_switch_on(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then
|
||||||
|
minetest.sound_play("doors_glass_door_open", {
|
||||||
|
pos = pos,
|
||||||
|
gain = 1,
|
||||||
|
max_hear_distance = 5})
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
|
Cable:after_dig_node(pos)
|
||||||
|
end,
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
on_rotate = screwdriver.disallow,
|
||||||
|
use_texture_alpha = "clip",
|
||||||
|
sunlight_propagates = true,
|
||||||
|
is_ground_content = false,
|
||||||
|
drop = "techage:powerswitch_box_on",
|
||||||
|
groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1, not_in_creative_inventory = 1},
|
||||||
|
sounds = default.node_sound_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
power.register_nodes({"techage:powerswitch_box_off"}, Cable, "con", {})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "techage:powerswitch_box",
|
output = "techage:powerswitch_box_on",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"", "basic_materials:plastic_sheet", ""},
|
{"", "basic_materials:plastic_sheet", ""},
|
||||||
{"techage:electric_cableS", "basic_materials:copper_wire", "techage:electric_cableS"},
|
{"techage:electric_cableS", "basic_materials:copper_wire", "techage:electric_cableS"},
|
||||||
|
86
power/powerswitchbox_legacy.lua
Normal file
86
power/powerswitchbox_legacy.lua
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
--[[
|
||||||
|
|
||||||
|
TechAge
|
||||||
|
=======
|
||||||
|
|
||||||
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
|
AGPL v3
|
||||||
|
See LICENSE.txt for more information
|
||||||
|
|
||||||
|
TA3 Old Power Switch Box
|
||||||
|
]]--
|
||||||
|
|
||||||
|
-- for lazy programmers
|
||||||
|
local S2P = minetest.string_to_pos
|
||||||
|
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||||
|
local M = minetest.get_meta
|
||||||
|
local N = function(pos) return minetest.get_node(pos).name end
|
||||||
|
local S = techage.S
|
||||||
|
|
||||||
|
local Cable = techage.ElectricCable
|
||||||
|
local power = networks.power
|
||||||
|
|
||||||
|
local node_box = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {
|
||||||
|
{ -1/4, -1/4, -2/4, 1/4, 1/4, 2/4},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- legacy node
|
||||||
|
minetest.register_node("techage:powerswitch_box", {
|
||||||
|
description = S("TA Power Switch Box"),
|
||||||
|
tiles = {
|
||||||
|
-- up, down, right, left, back, front
|
||||||
|
'techage_electric_switch.png^[transformR90',
|
||||||
|
'techage_electric_switch.png^[transformR90',
|
||||||
|
'techage_electric_switch.png',
|
||||||
|
'techage_electric_switch.png',
|
||||||
|
'techage_electric_junction.png',
|
||||||
|
'techage_electric_junction.png',
|
||||||
|
},
|
||||||
|
|
||||||
|
drawtype = "nodebox",
|
||||||
|
node_box = node_box,
|
||||||
|
|
||||||
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
|
if not Cable:after_place_tube(pos, placer, pointed_thing) then
|
||||||
|
minetest.remove_node(pos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
minetest.swap_node(pos, {name = "techage:powerswitch_box_on", param2 = node.param2})
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
|
||||||
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
|
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
||||||
|
end,
|
||||||
|
|
||||||
|
paramtype = "light",
|
||||||
|
use_texture_alpha = techage.CLIP,
|
||||||
|
sunlight_propagates = true,
|
||||||
|
on_rotate = screwdriver.disallow, -- important!
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
drop = "techage:powerswitch_box_on",
|
||||||
|
groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1, not_in_creative_inventory = 1},
|
||||||
|
is_ground_content = false,
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "[techage] legacy Power Switch Box",
|
||||||
|
name = "techage:powerswitch_box",
|
||||||
|
nodenames = {"techage:powerswitch_box"},
|
||||||
|
run_at_every_load = false,
|
||||||
|
action = function(pos, node)
|
||||||
|
if M(pos):get_int("tl2_param2" == 0 then
|
||||||
|
minetest.swap_node(pos, {name = "techage:powerswitch_box_off", param2 = node.param2})
|
||||||
|
M(pos):set_int("networks_param2", 0)
|
||||||
|
else
|
||||||
|
minetest.swap_node(pos, {name = "techage:powerswitch_box_on", param2 = node.param2})
|
||||||
|
M(pos):set_int("networks_param2", M(pos):get_int("tl2_param2"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
@ -1,83 +0,0 @@
|
|||||||
--[[
|
|
||||||
|
|
||||||
TechAge
|
|
||||||
=======
|
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
|
||||||
|
|
||||||
AGPL v3
|
|
||||||
See LICENSE.txt for more information
|
|
||||||
|
|
||||||
Global power Job Scheduler
|
|
||||||
|
|
||||||
]]--
|
|
||||||
|
|
||||||
-- for lazy programmers
|
|
||||||
local P2P = minetest.string_to_pos
|
|
||||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
|
||||||
local M = minetest.get_meta
|
|
||||||
local N = function(pos) return minetest.get_node(pos).name end
|
|
||||||
local HEX = function(val) return string.format("%XH", val) end
|
|
||||||
|
|
||||||
local power = techage.power
|
|
||||||
local networks = techage.networks
|
|
||||||
|
|
||||||
local CYCLE_TIME = 1
|
|
||||||
|
|
||||||
techage.schedule = {}
|
|
||||||
|
|
||||||
local JobTable = {}
|
|
||||||
local JobQueue = {}
|
|
||||||
local first = 0
|
|
||||||
local last = -1
|
|
||||||
|
|
||||||
techage.SystemTime = 0
|
|
||||||
|
|
||||||
local function push(item)
|
|
||||||
last = last + 1
|
|
||||||
item.time = techage.SystemTime + CYCLE_TIME
|
|
||||||
JobQueue[last] = item
|
|
||||||
end
|
|
||||||
|
|
||||||
local function pop()
|
|
||||||
if first > last then return end
|
|
||||||
local item = JobQueue[first]
|
|
||||||
if item.time <= techage.SystemTime then
|
|
||||||
JobQueue[first] = nil -- to allow garbage collection
|
|
||||||
first = first + 1
|
|
||||||
return item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Scheduler
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
techage.SystemTime = techage.SystemTime + dtime
|
|
||||||
local item = pop()
|
|
||||||
local t = minetest.get_us_time()
|
|
||||||
while item do
|
|
||||||
local network = networks.peek_network(item.tube_type, item.netID)
|
|
||||||
if network and network.alive and network.alive >= 0 then
|
|
||||||
power.power_distribution(network, item.tube_type, item.netID, CYCLE_TIME)
|
|
||||||
network.alive = network.alive - 1
|
|
||||||
push(item)
|
|
||||||
else
|
|
||||||
JobTable[item.netID] = nil
|
|
||||||
networks.delete_network(item.tube_type, item.netID)
|
|
||||||
end
|
|
||||||
item = pop()
|
|
||||||
end
|
|
||||||
t = minetest.get_us_time() - t
|
|
||||||
if t > 10000 then
|
|
||||||
minetest.log("action", "[TA Schedule] duration="..t.."us")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
function techage.schedule.start(tube_type, netID)
|
|
||||||
if not JobTable[netID] then
|
|
||||||
local network = networks.peek_network(tube_type, netID)
|
|
||||||
power.power_distribution(network, tube_type, netID, CYCLE_TIME/2)
|
|
||||||
network.alive = network.alive - 1
|
|
||||||
push({tube_type = tube_type, netID = netID})
|
|
||||||
JobTable[netID] = true
|
|
||||||
end
|
|
||||||
end
|
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
TechAge
|
TechAge
|
||||||
=======
|
=======
|
||||||
|
|
||||||
Copyright (C) 2019-2020 Joachim Stolberg
|
Copyright (C) 2019-2021 Joachim Stolberg
|
||||||
|
|
||||||
AGPL v3
|
AGPL v3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
@ -19,11 +19,10 @@ local S = techage.S
|
|||||||
local STANDBY_TICKS = 4
|
local STANDBY_TICKS = 4
|
||||||
local COUNTDOWN_TICKS = 4
|
local COUNTDOWN_TICKS = 4
|
||||||
local CYCLE_TIME = 2
|
local CYCLE_TIME = 2
|
||||||
local PWR_CAPA = 25
|
local PWR_PERF = 25
|
||||||
|
|
||||||
local Axle = techage.Axle
|
local Axle = techage.Axle
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
local networks = techage.networks
|
|
||||||
|
|
||||||
-- Axles texture animation
|
-- Axles texture animation
|
||||||
local function switch_axles(pos, on)
|
local function switch_axles(pos, on)
|
||||||
@ -38,7 +37,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(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
|
techage.power.formspec_label_bar(pos, 0, 0.8, Axle, S("power"), PWR_PERF, 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
|
||||||
@ -55,7 +54,7 @@ end
|
|||||||
local function start_node(pos, nvm, state)
|
local function start_node(pos, nvm, state)
|
||||||
switch_axles(pos, true)
|
switch_axles(pos, true)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_start(pos, Axle, CYCLE_TIME, outdir)
|
power.start_storage_calc(pos, Axle, outdir)
|
||||||
transfer_cylinder(pos, "start")
|
transfer_cylinder(pos, "start")
|
||||||
nvm.running = true
|
nvm.running = true
|
||||||
end
|
end
|
||||||
@ -63,7 +62,7 @@ end
|
|||||||
local function stop_node(pos, nvm, state)
|
local function stop_node(pos, nvm, state)
|
||||||
switch_axles(pos, false)
|
switch_axles(pos, false)
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
power.generator_stop(pos, Axle, outdir)
|
power.start_storage_calc(pos, Axle, outdir)
|
||||||
nvm.provided = 0
|
nvm.provided = 0
|
||||||
transfer_cylinder(pos, "stop")
|
transfer_cylinder(pos, "stop")
|
||||||
nvm.running = false
|
nvm.running = false
|
||||||
@ -89,8 +88,12 @@ local function node_timer(pos, elapsed)
|
|||||||
transfer_cylinder(pos, "stop")
|
transfer_cylinder(pos, "stop")
|
||||||
else
|
else
|
||||||
local outdir = M(pos):get_int("outdir")
|
local outdir = M(pos):get_int("outdir")
|
||||||
nvm.provided = power.generator_alive(pos, Axle, CYCLE_TIME, outdir)
|
nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF)
|
||||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||||
|
local data = power.get_storage_data(pos, Axle, outdir)
|
||||||
|
if data then
|
||||||
|
nvm.load = data.level * PWR_PERF
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if techage.is_activeformspec(pos) then
|
if techage.is_activeformspec(pos) then
|
||||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||||
@ -125,17 +128,14 @@ local function after_dig_node(pos, oldnode)
|
|||||||
techage.del_mem(pos)
|
techage.del_mem(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
local function get_generator_data(pos, tlib2)
|
||||||
power.update_network(pos, outdir, tlib2)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
if nvm.running then
|
||||||
|
return {level = (nvm.load or 0) / PWR_PERF, capa = PWR_PERF * 4}
|
||||||
|
else
|
||||||
|
return {level = 0, capa = PWR_PERF * 4}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local net_def = {
|
|
||||||
axle = {
|
|
||||||
sides = {R = 1},
|
|
||||||
ntype = "gen1",
|
|
||||||
nominal = PWR_CAPA,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
minetest.register_node("techage:flywheel", {
|
minetest.register_node("techage:flywheel", {
|
||||||
description = S("TA2 Flywheel"),
|
description = S("TA2 Flywheel"),
|
||||||
@ -154,8 +154,7 @@ minetest.register_node("techage:flywheel", {
|
|||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
get_generator_data = get_generator_data,
|
||||||
networks = net_def,
|
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2, crumbly=2, choppy=2},
|
groups = {cracky=2, crumbly=2, choppy=2},
|
||||||
@ -208,8 +207,7 @@ minetest.register_node("techage:flywheel_on", {
|
|||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
after_place_node = after_place_node,
|
after_place_node = after_place_node,
|
||||||
after_dig_node = after_dig_node,
|
after_dig_node = after_dig_node,
|
||||||
tubelib2_on_update2 = tubelib2_on_update2,
|
get_generator_data = get_generator_data,
|
||||||
networks = net_def,
|
|
||||||
|
|
||||||
drop = "",
|
drop = "",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
@ -220,7 +218,7 @@ minetest.register_node("techage:flywheel_on", {
|
|||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
Axle:add_secondary_node_names({"techage:flywheel", "techage:flywheel_on"})
|
power.register_nodes({"techage:flywheel", "techage:flywheel_on"}, Axle, "gen", {"R"})
|
||||||
|
|
||||||
techage.register_node({"techage:flywheel", "techage:flywheel_on"}, {
|
techage.register_node({"techage:flywheel", "techage:flywheel_on"}, {
|
||||||
on_transfer = function(pos, in_dir, topic, payload)
|
on_transfer = function(pos, in_dir, topic, payload)
|
||||||
@ -228,14 +226,13 @@ techage.register_node({"techage:flywheel", "techage:flywheel_on"}, {
|
|||||||
if topic == "trigger" then
|
if topic == "trigger" then
|
||||||
nvm.firebox_trigger = 3
|
nvm.firebox_trigger = 3
|
||||||
if nvm.running then
|
if nvm.running then
|
||||||
return math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.1)
|
return math.max((nvm.provided or PWR_PERF) / PWR_PERF, 0.1)
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_node_load = function(pos, node)
|
on_node_load = function(pos, node)
|
||||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
|
||||||
State:on_node_load(pos)
|
State:on_node_load(pos)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 188 B |
BIN
textures/techage_electric_switch_off.png
Normal file
BIN
textures/techage_electric_switch_off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 195 B |
Binary file not shown.
Before Width: | Height: | Size: 396 B After Width: | Height: | Size: 395 B |
Loading…
Reference in New Issue
Block a user