reactor and doser activated

This commit is contained in:
Joachim Stolberg 2019-11-11 21:25:20 +01:00
parent 406b5ad6a5
commit 0a27fb122c
10 changed files with 310 additions and 183 deletions

View File

@ -42,10 +42,8 @@ local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if not mem.running and power.power_available(pos, mem, PWR_NEEDED) then if not mem.running and power.power_available(pos, mem, PWR_NEEDED) then
mem.running = true mem.running = true
--swap_node(pos, "techage:sink_on")
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
minetest.get_node_timer(pos):start(CYCLE_TIME) M(pos):set_string("infotext", "...")
M(pos):set_string("infotext", "on")
else else
mem.running = false mem.running = false
swap_node(pos, "techage:sink") swap_node(pos, "techage:sink")

View File

@ -21,10 +21,9 @@ local recipes = techage.recipes
local Liquids = {} -- {hash(pos) = {name = outdir},...} local Liquids = {} -- {hash(pos) = {name = outdir},...}
local STANDBY_TICKS = 0 local STANDBY_TICKS = 4
local COUNTDOWN_TICKS = 6 local COUNTDOWN_TICKS = 4
local CYCLE_TIME = 2 local CYCLE_TIME = 4
local POWER_NEED = 10
local function formspec(self, pos, mem) local function formspec(self, pos, mem)
return "size[8,7]".. return "size[8,7]"..
@ -73,20 +72,24 @@ end
local function can_start(pos, mem, state) local function can_start(pos, mem, state)
-- check reactor -- check reactor
local res = reactor_cmnd(pos, "can_start") local res = reactor_cmnd(pos, "check")
if not res then if not res then
return S("reactor defect") return S("reactor defect")
end end
res = reactor_cmnd(pos, "can_start")
if not res then
return S("reactor defect or no power")
end
return true return true
end end
local function start_node(pos, mem, state) local function start_node(pos, mem, state)
reactor_cmnd(pos, "start", {cycle_time = CYCLE_TIME, pwr_needed = POWER_NEED}) reactor_cmnd(pos, "start")
mem.running = true mem.running = true
end end
local function stop_node(pos, mem, state) local function stop_node(pos, mem, state)
reactor_cmnd(pos, "stop", nil) reactor_cmnd(pos, "stop")
mem.running = false mem.running = false
end end
@ -108,35 +111,43 @@ end
local function dosing(pos, mem, elapsed) local function dosing(pos, mem, elapsed)
-- trigger reactor (power) -- trigger reactor (power)
if not reactor_cmnd(pos, "power", POWER_NEED) then if not reactor_cmnd(pos, "power") then
if not mem.techage_countdown or mem.techage_countdown < 2 then
State:nopower(pos, mem, S("reactor has no power")) State:nopower(pos, mem, S("reactor has no power"))
end
State:idle(pos, mem)
return return
end end
-- available liquids -- -- available liquids
local liquids = get_liquids(pos) -- local liquids = get_liquids(pos)
local recipe = recipes.get(mem, "ta4_doser") -- local recipe = recipes.get(mem, "ta4_doser")
if not liquids or not recipe then return end -- if not liquids or not recipe then return end
-- inputs -- -- inputs
for _,item in pairs(recipe.input) do -- for _,item in pairs(recipe.input) do
if item.name ~= "" then -- if item.name ~= "" then
print("dosing", item.name, dump(liquids)) -- print("dosing", item.name, dump(liquids))
local outdir = liquids[item.name] -- local outdir = liquids[item.name]
if not outdir then -- if not outdir then
State:fault(pos, mem, S("input missing")) -- State:fault(pos, mem, S("input missing"))
return -- return
end -- end
if liquid.take(pos, outdir, item.name, item.num) < item.num then -- if liquid.take(pos, outdir, item.name, item.num) < item.num then
State:fault(pos, mem, S("input missing")) -- State:fault(pos, mem, S("input missing"))
return -- return
end -- end
end -- end
end -- end
-- output -- output
if not reactor_cmnd(pos, "output", recipe.output.name) then --if not reactor_cmnd(pos, "output", recipe.output.name) then
local leftover
leftover = reactor_cmnd(pos, "output", {name = "techage:gasoline", amount = 1, player_name = "singleplayer"})
if not leftover or leftover > 0 then
State:fault(pos, mem, S("output blocked")) State:fault(pos, mem, S("output blocked"))
return return
end end
if not reactor_cmnd(pos, "waste", recipe.waste.name) then --if not reactor_cmnd(pos, "waste", recipe.waste.name) then
leftover = reactor_cmnd(pos, "waste", {name = "techage:bitumen", amount = 1, player_name = "singleplayer"})
if not leftover or leftover > 0 then
State:fault(pos, mem, S("output blocked")) State:fault(pos, mem, S("output blocked"))
return return
end end

View File

@ -13,100 +13,13 @@
]]-- ]]--
local S = techage.S local S = techage.S
local M = minetest.get_meta
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
local Pipe = techage.LiquidPipe local Pipe = techage.LiquidPipe
local networks = techage.networks local networks = techage.networks
local liquid = techage.liquid local liquid = techage.liquid
-- pos of the reactor stand
local function on_power(pos, mem)
mem.running = true
end
local function on_nopower(pos, mem)
mem.running = false
end
minetest.register_node("techage:ta4_reactor", {
description = S("TA4 Reactor"),
tiles = {"techage_reactor_side.png"},
drawtype = "mesh",
mesh = "techage_cylinder_12h.obj",
selection_box = {
type = "fixed",
fixed = {-1/2, -23/32, -1/2, 1/2, 32/32, 1/2},
},
collision_box = {
type = "fixed",
fixed = {-1/2, -23/32, -1/2, 1/2, 32/32, 1/2},
},
paramtype = "light",
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
minetest.register_node("techage:ta4_reactor_stand", {
description = S("TA4 Reactor"),
tiles = {
-- up, down, right, left, back, front
"techage_reactor_stand_top.png^[transformR90",
"techage_reactor_stand_bottom.png^[transformFY^[transformR270",
"techage_reactor_stand_front.png",
"techage_reactor_stand_back.png",
"techage_reactor_stand_side.png^[transformFX",
"techage_reactor_stand_side.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -8/16, 2/16, -8/16, 8/16, 4/16, 8/16 },
{ -8/16, -8/16, -8/16, -6/16, 8/16, -6/16 },
{ 6/16, -8/16, -8/16, 8/16, 8/16, -6/16 },
{ -8/16, -8/16, 6/16, -6/16, 8/16, 8/16 },
{ 6/16, -8/16, 6/16, 8/16, 8/16, 8/16 },
{-1/8, -4/8, -1/8, 1/8, 4/8, 1/8},
{-4/8, -1/8, -1/8, 4/8, 1/8, 1/8},
-- {-3/8, -1/8, -4/8, 3/8, 1/8, -3/8},
{-4/8, -1/8, -3/8, -3/8, 1/8, 3/8},
-- {-3/8, -1/8, 3/8, 3/8, 1/8, 4/8},
{ 3/8, -1/8, -3/8, 4/8, 1/8, 3/8},
},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
},
paramtype = "light",
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
networks = {
pipe = {
sides = {R=1}, -- Pipe connection sides
ntype = "pump",
},
},
})
-- for electrical connections
techage.power.register_node({"techage:ta4_reactor_stand"}, {
conn_sides = {"L"},
power_network = Cable,
})
minetest.register_node("techage:ta4_reactor_fillerpipe", { minetest.register_node("techage:ta4_reactor_fillerpipe", {
description = S("TA4 Reactor Filler Pipe"), description = S("TA4 Reactor Filler Pipe"),
tiles = { tiles = {
@ -130,7 +43,6 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
}, },
after_place_node = function(pos) after_place_node = function(pos)
local pos1 = {x = pos.x, y = pos.y-1, z = pos.z} local pos1 = {x = pos.x, y = pos.y-1, z = pos.z}
print(minetest.get_node(pos1).name)
if minetest.get_node(pos1).name == "air" then if minetest.get_node(pos1).name == "air" then
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
minetest.remove_node(pos) minetest.remove_node(pos)
@ -161,70 +73,63 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
}, },
}) })
local function stand_cmnd(pos, cmnd, payload)
return techage.transfer(
{x = pos.x, y = pos.y-1, z = pos.z},
5, -- outdir
cmnd, -- topic
payload, -- payload
nil, -- network
{"techage:ta4_reactor_stand"})
end
local function base_waste(pos, payload)
local pos2 = {x = pos.x, y = pos.y-3, z = pos.z}
local outdir = M(pos2):get_int("outdir")
return liquid.put(pos2, outdir, payload.name, payload.amount, payload.player_name)
end
-- controlled by the doser -- controlled by the doser
techage.register_node({"techage:ta4_reactor_fillerpipe"}, { techage.register_node({"techage:ta4_reactor_fillerpipe"}, {
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
-- pos of the reactor stand if topic == "check" then
local pos2 = {x = pos.x, y = pos.y-2, z = pos.z} local pos2,node = Pipe:get_node(pos, 5)
local mem = tubelib2.get_mem(pos2) if not node or node.name ~= "techage:ta4_reactor" then
if topic == "power" then return false
power.consumer_alive(pos2, mem) end
return mem.running pos2,node = Pipe:get_node(pos2, 5)
elseif topic == "can_start" then if not node or node.name ~= "techage:ta4_reactor_stand" then
local pos1 = {x = pos.x, y = pos.y-1, z = pos.z} return false
if minetest.get_node(pos1).name ~= "techage:ta4_reactor" then return false end end
if minetest.get_node(pos2).name ~= "techage:ta4_reactor_stand" then return false end
return true
elseif topic == "start" and payload then
mem.running = true
power.consumer_start(pos2, mem, payload.cycle_time or 0, payload.pwr_needed or 0)
return true
elseif topic == "stop" then
mem.running = false
power.consumer_stop(pos2, mem)
return true return true
elseif topic == "waste" then
return base_waste(pos, payload or {})
else
return stand_cmnd(pos, topic, payload or {})
end end
end, end,
}) })
minetest.register_node("techage:ta4_reactor_base", { minetest.register_node("techage:ta4_reactor", {
description = S("TA4 Reactor Base"), description = S("TA4 Reactor"),
tiles = { tiles = {"techage_reactor_side.png"},
-- up, down, right, left, back, front drawtype = "mesh",
"techage_concrete.png^techage_appl_arrowXL.png^techage_appl_hole_pipe.png^[transformR270", mesh = "techage_cylinder_12h.obj",
"techage_concrete.png", selection_box = {
"techage_concrete.png^techage_appl_hole_pipe.png", type = "fixed",
"techage_concrete.png", fixed = {-1/2, -23/32, -1/2, 1/2, 32/32, 1/2},
"techage_concrete.png", },
"techage_concrete.png", collision_box = {
type = "fixed",
fixed = {-1/2, -23/32, -1/2, 1/2, 32/32, 1/2},
}, },
after_place_node = function(pos, placer) paramtype = "light",
Pipe:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, dir, tlib2, node)
liquid.update_network(pos)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
end,
paramtype2 = "facedir", paramtype2 = "facedir",
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
groups = {cracky=2}, groups = {cracky=2},
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_metal_defaults(),
networks = {
pipe = {
sides = {R=1}, -- Pipe connection sides
ntype = "pump",
},
},
}) })
Pipe:add_secondary_node_names({ Pipe:add_secondary_node_names({"techage:ta4_reactor_fillerpipe"})
"techage:ta4_reactor_base",
"techage:ta4_reactor_fillerpipe",
"techage:ta4_reactor_stand",
})

201
chemistry/ta4_stand.lua Normal file
View File

@ -0,0 +1,201 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA4 Reactor Stand and Base
]]--
local S = techage.S
local M = minetest.get_meta
local Cable = techage.ElectricCable
local power = techage.power
local Pipe = techage.LiquidPipe
local networks = techage.networks
local liquid = techage.liquid
local PWR_NEEDED = 8
local CYCLE_TIME = 4
local function on_power(pos, mem)
if mem.running then
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", S("on"))
mem.has_power = true
end
end
local function on_nopower(pos, mem)
M(pos):set_string("infotext", S("no power"))
mem.has_power = false
end
minetest.register_node("techage:ta4_reactor_stand", {
description = S("TA4 Reactor"),
tiles = {
-- up, down, right, left, back, front
"techage_reactor_stand_top.png^[transformR90",
"techage_reactor_stand_bottom.png^[transformFY^[transformR270",
"techage_reactor_stand_front.png",
"techage_reactor_stand_back.png",
"techage_reactor_stand_side.png^[transformFX",
"techage_reactor_stand_side.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -8/16, 2/16, -8/16, 8/16, 4/16, 8/16 },
{ -8/16, -8/16, -8/16, -6/16, 8/16, -6/16 },
{ 6/16, -8/16, -8/16, 8/16, 8/16, -6/16 },
{ -8/16, -8/16, 6/16, -6/16, 8/16, 8/16 },
{ 6/16, -8/16, 6/16, 8/16, 8/16, 8/16 },
{-1/8, -4/8, -1/8, 1/8, 4/8, 1/8},
{-4/8, -1/8, -1/8, 4/8, 1/8, 1/8},
{-4/8, -1/8, -3/8, -3/8, 1/8, 3/8},
{ 3/8, -1/8, -3/8, 4/8, 1/8, 3/8},
},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
},
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
techage.power.after_place_node(pos)
M(pos):set_string("infotext", S("off"))
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, dir, tlib2, node)
liquid.update_network(pos)
end,
after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir)
techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir)
end,
on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos)
power.consumer_alive(pos, mem)
return mem.running
end,
on_rightclick = function(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
if not mem.running and power.power_available(pos, mem, PWR_NEEDED) then
mem.running = true
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
M(pos):set_string("infotext", "...")
else
mem.running = false
power.consumer_stop(pos, mem)
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", S("off"))
end
end,
after_dig_node = function(pos, oldnode)
techage.power.after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos)
tubelib2.del_mem(pos)
end,
paramtype = "light",
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
-- Pipe connection
networks = {
pipe = {
sides = {R=1},
ntype = "pump",
},
},
})
-- for electrical connections
techage.power.enrich_node({"techage:ta4_reactor_stand"}, {
conn_sides = {"L"},
power_network = Cable,
on_power = on_power,
on_nopower = on_nopower,
})
-- controlled by the fillerpipe
techage.register_node({"techage:ta4_reactor_stand"}, {
on_transfer = function(pos, in_dir, topic, payload)
print(topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "power" then
return mem.has_power
elseif topic == "output" then
local outdir = M(pos):get_int("outdir")
return liquid.put(pos, outdir, payload.name, payload.amount, payload.player_name)
elseif topic == "can_start" then
return power.power_available(pos, mem, 0)
elseif topic == "start" and payload then
mem.running = true
mem.has_power = false
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
M(pos):set_string("infotext", "...")
return true
elseif topic == "stop" then
mem.running = false
mem.has_power = false
power.consumer_stop(pos, mem)
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", S("off"))
return true
end
end,
})
minetest.register_node("techage:ta4_reactor_base", {
description = S("TA4 Reactor Base"),
tiles = {
-- up, down, right, left, back, front
"techage_concrete.png^techage_appl_arrowXL.png^techage_appl_hole_pipe.png^[transformR270",
"techage_concrete.png",
"techage_concrete.png^techage_appl_hole_pipe.png",
"techage_concrete.png",
"techage_concrete.png",
"techage_concrete.png",
},
after_place_node = function(pos, placer)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, dir, tlib2, node)
liquid.update_network(pos)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
end,
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
networks = {
pipe = {
sides = {R=1}, -- Pipe connection sides
ntype = "pump",
},
},
})
Pipe:add_secondary_node_names({
"techage:ta4_reactor_base",
"techage:ta4_reactor_stand",
})

View File

@ -37,14 +37,23 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
end end
local function play_sound(pos)
local function node_timer(pos)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if mem.running then if mem.running then
mem.handle = minetest.sound_play("techage_turbine", { mem.handle = minetest.sound_play("techage_turbine", {
pos = pos, pos = pos,
gain = 1, gain = 1,
max_hear_distance = 15}) max_hear_distance = 15})
minetest.after(2, play_sound, pos) end
return mem.running
end
local function play_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then
node_timer(pos)
minetest.get_node_timer(pos):start(2)
end end
end end
@ -53,6 +62,7 @@ local function stop_sound(pos)
if mem.running and mem.handle then if mem.running and mem.handle then
minetest.sound_stop(mem.handle) minetest.sound_stop(mem.handle)
mem.handle = nil mem.handle = nil
minetest.get_node_timer(pos):stop(2)
end end
end end
@ -102,6 +112,7 @@ minetest.register_node("techage:turbine_on", {
}, },
}, },
}, },
on_timer = node_timer,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
diggable = false, diggable = false,

View File

@ -195,7 +195,7 @@ else
-- 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/source.lua") dofile(MP.."/.test/source.lua")
--dofile(MP.."/.test/akku.lua") --dofile(MP.."/.test/akku.lua")
--dofile(MP.."/.test/switch.lua") --dofile(MP.."/.test/switch.lua")
@ -219,8 +219,9 @@ else
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_doser.lua") dofile(MP.."/chemistry/ta4_stand.lua")
dofile(MP.."/chemistry/ta4_doser.lua")
-- Hydrogen -- Hydrogen
dofile(MP.."/hydrogen/hydrogen.lua") dofile(MP.."/hydrogen/hydrogen.lua")

View File

@ -119,7 +119,7 @@ function techage.liquid.put(pos, outdir, name, amount, player_name)
local peek = liquid.peek(item.pos, item.indir) local peek = liquid.peek(item.pos, item.indir)
if peek and peek ~= name then return amount or 0 end if peek and peek ~= name then return amount or 0 end
if player_name then if player_name then
local num = techage.get_node_number(pos) local num = techage.get_node_number(pos) or "000"
techage.mark_position(player_name, item.pos, "("..num..") put", "", 1) techage.mark_position(player_name, item.pos, "("..num..") put", "", 1)
end end
amount = liquid.put(item.pos, item.indir, name, amount) amount = liquid.put(item.pos, item.indir, name, amount)

View File

@ -148,7 +148,7 @@ local function can_dig(pos, player)
end end
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
local inv = minetest.get_meta(pos):get_inventory() local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("src") and inv:is_empty("dst") and (mem.liquid.amount or 0) == 0 return inv:is_empty("src") and inv:is_empty("dst") and (not mem.liquid or (mem.liquid.amount or 0) == 0)
end end

View File

@ -76,7 +76,7 @@ Power=Energie
Primary available=Primär verfügbar Primary available=Primär verfügbar
Primary needed=Primär benötigt Primary needed=Primär benötigt
Pusher=Schieber Pusher=Schieber
Recipe=Rezepte Recipe=Rezept
Remove derrick=Entferne Ölturm Remove derrick=Entferne Ölturm
Rinsing=Waschen Rinsing=Waschen
River Water Barrel=Flusswasserfass River Water Barrel=Flusswasserfass

View File

@ -156,7 +156,7 @@ local function command(pos, command, player)
return return
end end
local cmnd, payload = command:match('^pipe%s+(%w+)%s*(.*)$') local cmnd, payload = command:match('^pipe%s+([%w_]+)%s*(.*)$')
if cmnd then if cmnd then
if not minetest.check_player_privs(player, "server") then if not minetest.check_player_privs(player, "server") then
output(pos, "server privs missing") output(pos, "server privs missing")