This commit is contained in:
Joachim Stolberg 2019-03-08 21:18:55 +01:00
parent dc02a9f45b
commit fc88161bf8
5 changed files with 106 additions and 103 deletions

View File

@ -57,6 +57,8 @@ local function turn_power_on(pos, in_dir, sum)
mem.power_result = sum mem.power_result = sum
if State:is_active(mem) and sum <= 0 then if State:is_active(mem) and sum <= 0 then
State:fault(pos, mem) State:fault(pos, mem)
-- No automatic turn on
mem.power_capacity = 0
end end
M(pos):set_string("formspec", formspec(State, pos, mem)) M(pos):set_string("formspec", formspec(State, pos, mem))
end end
@ -103,6 +105,7 @@ minetest.register_node("techage:generator", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = generator.after_place_node(pos) local mem = generator.after_place_node(pos)
State:node_init(pos, mem, "") State:node_init(pos, mem, "")
on_rightclick(pos)
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
@ -113,5 +116,6 @@ minetest.register_node("techage:generator", {
after_tube_update = generator.after_tube_update, after_tube_update = generator.after_tube_update,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_timer = node_timer,
}) })

View File

@ -19,14 +19,14 @@ dofile(MP.."/basis/trowel.lua") -- hidden networks
dofile(MP.."/basis/junction.lua") -- network junction box dofile(MP.."/basis/junction.lua") -- network junction box
-- Steam Engine -- Steam Engine
--dofile(MP.."/steam_engine/drive_axle.lua") dofile(MP.."/steam_engine/drive_axle.lua")
--dofile(MP.."/steam_engine/steam_pipe.lua") dofile(MP.."/steam_engine/steam_pipe.lua")
--dofile(MP.."/steam_engine/firebox.lua") dofile(MP.."/steam_engine/firebox.lua")
--dofile(MP.."/steam_engine/boiler.lua") dofile(MP.."/steam_engine/boiler.lua")
--dofile(MP.."/steam_engine/cylinder.lua") dofile(MP.."/steam_engine/cylinder.lua")
--dofile(MP.."/steam_engine/flywheel.lua") dofile(MP.."/steam_engine/flywheel.lua")
--dofile(MP.."/steam_engine/gearbox.lua") dofile(MP.."/steam_engine/gearbox.lua")
--dofile(MP.."/steam_engine/consumer.lua") dofile(MP.."/steam_engine/consumer.lua")
dofile(MP.."/electric/electric_cable.lua") dofile(MP.."/electric/electric_cable.lua")
dofile(MP.."/electric/test.lua") dofile(MP.."/electric/test.lua")

View File

@ -21,14 +21,17 @@ local M = minetest.get_meta
local MP = minetest.get_modpath("tubelib2") local MP = minetest.get_modpath("tubelib2")
local I,_ = dofile(MP.."/intllib.lua") local I,_ = dofile(MP.."/intllib.lua")
local CYCLE_TIME = 4 local CYCLE_TIME = 4
local STANDBY_TICKS = 2 local STANDBY_TICKS = 2
local COUNTDOWN_TICKS = 2 local COUNTDOWN_TICKS = 2
local HEAT_STEP = 10 local HEAT_STEP = 10
local WATER_CONSUMPTION = 0.5 local WATER_CONSUMPTION = 0.5
local MAX_WATER = 10 local MAX_WATER = 10
local POWER = 10 local POWER_CAPACITY = 10
local Pipe = techage.SteamPipe
local generator = techage.generator
local Water = { local Water = {
["bucket:bucket_river_water"] = true, ["bucket:bucket_river_water"] = true,
@ -50,7 +53,7 @@ local function formspec(self, pos, mem)
"image[1,1.6;1,1;techage_form_mask.png]".. "image[1,1.6;1,1;techage_form_mask.png]"..
"image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:".. "image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:"..
temp..":techage_form_temp_fg.png]".. temp..":techage_form_temp_fg.png]"..
"image[7,0.5;1,2;"..techage.generator_formspec_level(mem).. "image[7,0.5;1,2;"..generator.formspec_level(mem, mem.power_result)..
"image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[3,1.5;2,1;update;"..I("Update").."]".. "button[3,1.5;2,1;update;"..I("Update").."]"..
"list[current_player;main;0,3;8,4;]".. "list[current_player;main;0,3;8,4;]"..
@ -59,19 +62,12 @@ local function formspec(self, pos, mem)
default.get_hotbar_bg(0, 3) default.get_hotbar_bg(0, 3)
end end
local function can_start(pos, mem, state)
if mem.temperature >= 80 then
return techage.calc_power_consumption(pos, mem, POWER) > 0
end
return false
end
local function start_node(pos, mem, state) local function start_node(pos, mem, state)
techage.generator_on(pos, mem) generator.turn_power_on(pos, POWER_CAPACITY)
end end
local function stop_node(pos, mem, state) local function stop_node(pos, mem, state)
techage.generator_off(pos, mem) generator.turn_power_on(pos, 0)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -80,7 +76,6 @@ local State = techage.NodeStates:new({
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
has_item_meter = false, has_item_meter = false,
formspec_func = formspec, formspec_func = formspec,
can_start = can_start,
start_node = start_node, start_node = start_node,
stop_node = stop_node, stop_node = stop_node,
}) })
@ -118,8 +113,7 @@ end
local function steaming(pos, mem, temp) local function steaming(pos, mem, temp)
mem.water_level = math.max((mem.water_level or 0) - WATER_CONSUMPTION, 0) mem.water_level = math.max((mem.water_level or 0) - WATER_CONSUMPTION, 0)
if temp >= 80 then if temp >= 80 then
local sum = techage.calc_power_consumption(pos, mem, POWER) if mem.power_result > 0 then
if sum > 0 then
State:keep_running(pos, mem, COUNTDOWN_TICKS) State:keep_running(pos, mem, COUNTDOWN_TICKS)
else else
State:fault(pos, mem) State:fault(pos, mem)
@ -139,6 +133,18 @@ local function node_timer(pos, elapsed)
return mem.temperature > 20 return mem.temperature > 20
end end
local function turn_power_on(pos, in_dir, sum)
local mem = tubelib2.get_mem(pos)
-- store result for formspec
mem.power_result = sum
if State:is_active(mem) and sum <= 0 then
State:fault(pos, mem)
-- No automatic turn on
mem.power_capacity = 0
end
M(pos):set_string("formspec", formspec(State, pos, mem))
end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(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
@ -151,16 +157,6 @@ local function on_receive_fields(pos, formname, fields, player)
end end
end end
local function valid_power_dir(pos, mem, in_dir)
return mem.power_dir == in_dir
end
local function turn_power_on(pos, in_dir, on)
local mem = tubelib2.get_mem(pos)
if State:is_active(mem) and not on then
State:fault(pos, mem)
end
end
local function on_rightclick(pos) local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
@ -256,9 +252,9 @@ minetest.register_node("techage:boiler2", {
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
techage = { techage = {
power_consumption = techage.generator_power_consumption, turn_on = turn_power_on,
power_network = techage.SteamPipe, read_power_consumption = generator.read_power_consumption,
power_consume = 0, power_network = Pipe,
trigger_boiler = function(pos) trigger_boiler = function(pos)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.fire_trigger = true mem.fire_trigger = true
@ -267,8 +263,6 @@ minetest.register_node("techage:boiler2", {
end end
end, end,
power_side = "U", power_side = "U",
valid_power_dir = valid_power_dir,
turn_on = turn_power_on,
}, },
on_construct = function(pos) on_construct = function(pos)
@ -278,7 +272,7 @@ minetest.register_node("techage:boiler2", {
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = techage.generator_after_place_node(pos) local mem = generator.after_place_node(pos)
State:node_init(pos, mem, "") State:node_init(pos, mem, "")
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name == "techage:boiler1" then if node.name == "techage:boiler1" then
@ -288,11 +282,10 @@ minetest.register_node("techage:boiler2", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
State:after_dig_node(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger)
techage.generator_after_dig_node(pos, oldnode) generator.after_dig_node(pos, oldnode)
end, end,
after_tube_update = techage.generator_after_tube_update, after_tube_update = generator.after_tube_update,
on_destruct = techage.generator_on_destruct,
on_metadata_inventory_put = function(pos) on_metadata_inventory_put = function(pos)
minetest.after(0.5, move_to_water, pos) minetest.after(0.5, move_to_water, pos)

View File

@ -23,7 +23,10 @@ local TN = function(node) return (minetest.registered_nodes[node.name] or {}).te
local MP = minetest.get_modpath("tubelib2") local MP = minetest.get_modpath("tubelib2")
local I,_ = dofile(MP.."/intllib.lua") local I,_ = dofile(MP.."/intllib.lua")
local POWER_CONSUME = 8 local POWER_CONSUMPTION = 8
local Pipe = techage.SteamPipe
local consumer = techage.consumer
local function swap_node(pos, name) local function swap_node(pos, name)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
@ -40,21 +43,21 @@ local function valid_power_dir(pos, mem, in_dir)
end end
-- called from pipe network -- called from pipe network
local function turn_power_on(pos, in_dir, on) local function turn_power_on_clbk(pos, in_dir, sum)
print("turn_power_on", in_dir, on)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.power_supply = on -- Simply store state to be prepared, when flywheel wants to start.
mem.running = sum > 0
end end
-- called from flywheel -- called from flywheel
local function start_cylinder(pos, on) local function start_cylinder(pos, on)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if on and mem.power_supply then if on and mem.running then
mem.power_consume = POWER_CONSUME consumer.turn_power_on(pos, POWER_CONSUMPTION)
swap_node(pos, "techage:cylinder_on") swap_node(pos, "techage:cylinder_on")
return true return true
else else
mem.power_consume = 0 consumer.turn_power_on(pos, 0)
swap_node(pos, "techage:cylinder") swap_node(pos, "techage:cylinder")
end end
return false return false
@ -73,22 +76,22 @@ minetest.register_node("techage:cylinder", {
"techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png",
}, },
techage = { techage = {
turn_on = turn_power_on, turn_on = turn_power_on_clbk,
power_consumption = techage.consumer_power_consumption, read_power_consumption = consumer.read_power_consumption,
power_network = techage.SteamPipe, power_network = Pipe,
power_side = 'L', power_side = "L",
valid_power_dir = valid_power_dir, valid_power_dir = valid_power_dir,
start_cylinder = start_cylinder, start_cylinder = start_cylinder,
}, },
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = techage.consumer_after_place_node(pos, placer) local mem = consumer.after_place_node(pos, placer)
mem.power_consume = 0 -- needed power to run mem.power_consume = 0 -- needed power to run
mem.power_supply = false -- power available? mem.power_supply = false -- power available?
end, end,
after_tube_update = techage.consumer_after_tube_update, after_tube_update = consumer.after_tube_update,
after_dig_node = techage.consumer_after_dig_node, after_dig_node = consumer.after_dig_node,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
@ -127,16 +130,16 @@ minetest.register_node("techage:cylinder_on", {
}, },
}, },
techage = { techage = {
turn_on = turn_power_on, turn_on = turn_power_on_clbk,
power_consumption = techage.consumer_power_consumption, read_power_consumption = consumer.read_power_consumption,
power_network = techage.SteamPipe, power_network = Pipe,
power_side = 'L', power_side = "L",
valid_power_dir = valid_power_dir, valid_power_dir = valid_power_dir,
start_cylinder = start_cylinder, start_cylinder = start_cylinder,
}, },
after_tube_update = techage.consumer_after_tube_update, after_tube_update = consumer.after_tube_update,
after_dig_node = techage.consumer_after_dig_node, after_dig_node = consumer.after_dig_node,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},

View File

@ -26,45 +26,43 @@ local I,_ = dofile(MP.."/intllib.lua")
local STANDBY_TICKS = 4 local STANDBY_TICKS = 4
local COUNTDOWN_TICKS = 4 local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 8 local CYCLE_TIME = 8
local POWER = 8 local POWER_CAPACITY = 8
local Axle = techage.Axle
local generator = techage.generator
local function formspec(self, pos, mem) local function formspec(self, pos, mem)
return "size[8,7]".. return "size[8,7]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[6,0.5;1,2;"..techage.generator_formspec_level(mem).. "image[6,0.5;1,2;"..generator.formspec_level(mem, mem.power_result)..
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"button[2,1.5;2,1;update;"..I("Update").."]".. "button[2,1.5;2,1;update;"..I("Update").."]"..
"list[current_player;main;0,3;8,4;]".. "list[current_player;main;0,3;8,4;]"..
default.get_hotbar_bg(0, 3) default.get_hotbar_bg(0, 3)
end end
local function can_start(pos, mem, state) local function start_cylinder(pos, on)
local pos2 = techage.get_pos(pos, 'L') local pos2 = techage.get_pos(pos, 'L')
if minetest.get_node(pos2).name == "techage:cylinder" and tubelib2.get_mem(pos2).power_supply then local that = TP(pos2)
local sum = techage.calc_power_consumption(pos, mem, POWER) if that and that.start_cylinder then
return sum > 0 return that.start_cylinder(pos2, on)
end end
return false return false
end end
local function can_start(pos, mem, state)
return start_cylinder(pos, true)
end
local function start_node(pos, mem, state) local function start_node(pos, mem, state)
local pos2 = techage.get_pos(pos, 'L') generator.turn_power_on(pos, POWER_CAPACITY)
local that = TP(pos2)
if that and that.start_cylinder then
that.start_cylinder(pos2, true)
techage.generator_on(pos, mem)
end
end end
local function stop_node(pos, mem, state) local function stop_node(pos, mem, state)
techage.generator_off(pos, mem) start_cylinder(pos, false)
local pos2 = techage.get_pos(pos, 'L') generator.turn_power_on(pos, 0)
local that = TP(pos2)
if that and that.start_cylinder then
that.start_cylinder(pos2, false)
end
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -79,11 +77,11 @@ local State = techage.NodeStates:new({
}) })
local function distibuting(pos, mem) local function distibuting(pos, mem)
local sum = techage.calc_power_consumption(pos, mem, 8) if mem.power_result > 0 then
if sum > 0 then
State:keep_running(pos, mem, COUNTDOWN_TICKS) State:keep_running(pos, mem, COUNTDOWN_TICKS)
else else
State:fault(pos, mem) State:fault(pos, mem)
start_cylinder(pos, false)
end end
end end
@ -91,10 +89,11 @@ local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
print("flywheel node_timer") print("flywheel node_timer")
local pos2 = techage.get_pos(pos, 'L') local pos2 = techage.get_pos(pos, 'L')
if minetest.get_node(pos2).name == "techage:cylinder_on" and tubelib2.get_mem(pos2).power_supply then if minetest.get_node(pos2).name == "techage:cylinder_on" and tubelib2.get_mem(pos2).running then
distibuting(pos, mem) distibuting(pos, mem)
else else
State:fault(pos, mem) State:fault(pos, mem)
start_cylinder(pos, false)
end end
return State:is_active(mem) return State:is_active(mem)
end end
@ -103,11 +102,17 @@ local function valid_power_dir(pos, mem, in_dir)
return mem.power_dir == in_dir return mem.power_dir == in_dir
end end
local function turn_power_on(pos, in_dir, on) local function turn_power_on(pos, in_dir, sum)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if State:is_active(mem) and not on then -- store result for formspec
mem.power_result = sum
if State:is_active(mem) and sum <= 0 then
State:fault(pos, mem) State:fault(pos, mem)
start_cylinder(pos, false)
-- No automatic turn on
mem.power_capacity = 0
end end
M(pos):set_string("formspec", formspec(State, pos, mem))
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
@ -139,31 +144,27 @@ minetest.register_node("techage:flywheel", {
"techage_filling_ta2.png^techage_frame_ta2.png^techage_flywheel.png^[transformFX]", "techage_filling_ta2.png^techage_frame_ta2.png^techage_flywheel.png^[transformFX]",
}, },
techage = { techage = {
power_network = techage.Axle,
power_consumption = techage.generator_power_consumption,
power_consume = 0,
animated_power_network = true,
valid_power_dir = valid_power_dir,
turn_on = turn_power_on, turn_on = turn_power_on,
read_power_consumption = generator.read_power_consumption,
power_network = Axle,
animated_power_network = true,
}, },
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local mem = techage.generator_after_place_node(pos) local mem = generator.after_place_node(pos)
State:node_init(pos, mem, "") State:node_init(pos, mem, "")
on_rightclick(pos) on_rightclick(pos)
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
State:after_dig_node(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger)
techage.generator_after_dig_node(pos, oldnode) generator.after_dig_node(pos, oldnode)
end, end,
after_tube_update = techage.generator_after_tube_update, after_tube_update = generator.after_tube_update,
on_destruct = techage.generator_on_destruct,
on_timer = node_timer,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_timer = node_timer,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
@ -211,19 +212,21 @@ minetest.register_node("techage:flywheel_on", {
}, },
}, },
techage = { techage = {
power_network = techage.Axle,
power_consumption = techage.generator_power_consumption,
power_consume = 0,
animated_power_network = true,
valid_power_dir = valid_power_dir,
turn_on = turn_power_on, turn_on = turn_power_on,
read_power_consumption = generator.read_power_consumption,
power_network = Axle,
animated_power_network = true,
}, },
after_tube_update = techage.generator_after_tube_update, after_dig_node = function(pos, oldnode, oldmetadata, digger)
State:after_dig_node(pos, oldnode, oldmetadata, digger)
generator.after_dig_node(pos, oldnode)
end,
on_timer = node_timer, after_tube_update = generator.after_tube_update,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_timer = node_timer,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},