Fix valve protection and tank cart bugs, add command payload to buttons

This commit is contained in:
Joachim Stolberg 2021-10-22 19:03:02 +02:00
parent 58b1be93ca
commit 43bb2705cf
14 changed files with 151 additions and 122 deletions

View File

@ -136,4 +136,4 @@ end
function techage.recipes.get_recipe(name) function techage.recipes.get_recipe(name)
return NormalizedRecipes[name] return NormalizedRecipes[name]
end end

View File

@ -118,6 +118,9 @@ minetest.register_node("techage:tank_cart", {
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {} nvm.liquid = nvm.liquid or {}
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm)) M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
-- Delete the network between pump and cart
Pipe:after_dig_node(pos)
Pipe:after_place_node(pos)
end, end,
set_cargo = function(pos, data) set_cargo = function(pos, data)

View File

@ -264,7 +264,7 @@ 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/sequencer2.lua") --dofile(MP.."/logic/sequencer2.lua") still under dev.
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
@ -277,7 +277,7 @@ 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")
dofile(MP.."/logic/button_4x.lua") dofile(MP.."/logic/button_4x.lua")
dofile(MP.."/logic/movecontroller.lua") --dofile(MP.."/logic/movecontroller.lua") still under dev.
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

View File

@ -45,7 +45,6 @@ local function pumping(pos, nvm, state, capa)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.dbg_cycles = (mem.dbg_cycles or 0) - 1 mem.dbg_cycles = (mem.dbg_cycles or 0) - 1
local outdir = M(pos):get_int("outdir") local outdir = M(pos):get_int("outdir")
--print("pumping", outdir, Flip[outdir])
local taken, name = liquid.take(pos, Pipe, Flip[outdir], nil, capa, mem.dbg_cycles > 0) local taken, name = liquid.take(pos, Pipe, Flip[outdir], nil, capa, mem.dbg_cycles > 0)
if taken > 0 then if taken > 0 then
local leftover = liquid.put(pos, Pipe, outdir, name, taken, mem.dbg_cycles > 0) local leftover = liquid.put(pos, Pipe, outdir, name, taken, mem.dbg_cycles > 0)

View File

@ -43,6 +43,9 @@ minetest.register_node("techage:ta3_valve_open", {
return false return false
end, end,
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
if minetest.is_protected(pos, clicker:get_player_name()) then
return
end
if liquid.turn_valve_off(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") then if liquid.turn_valve_off(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") then
minetest.sound_play("techage_valve", { minetest.sound_play("techage_valve", {
pos = pos, pos = pos,
@ -84,6 +87,9 @@ minetest.register_node("techage:ta3_valve_closed", {
}, },
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
if minetest.is_protected(pos, clicker:get_player_name()) then
return
end
if liquid.turn_valve_on(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") then if liquid.turn_valve_on(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") then
minetest.sound_play("techage_valve", { minetest.sound_play("techage_valve", {
pos = pos, pos = pos,

View File

@ -38,8 +38,9 @@ local function switch_on(pos)
logic.swap_node(pos, "techage:ta4_button_on") logic.swap_node(pos, "techage:ta4_button_on")
end end
local meta = M(pos) local meta = M(pos)
local cmnd = meta:contains("command") and meta:get_string("command") or "on" local s = meta:contains("command") and meta:get_string("command") or "on"
logic.send_cmnd(pos, M(pos), cmnd, cycle_time) local command, payload = unpack(string.split(s, " ", false, 1))
logic.send_cmnd(pos, M(pos), command, payload, cycle_time)
minetest.sound_play("techage_button", { minetest.sound_play("techage_button", {
pos = pos, pos = pos,
gain = 0.5, gain = 0.5,

View File

@ -18,20 +18,22 @@ local S = techage.S
local function get_button_num(pos, clicker, pointed_thing) local function get_button_num(pos, clicker, pointed_thing)
-- use the node behind the button to get better results -- use the node behind the button to get better results
local offs = vector.subtract(pointed_thing.under, pointed_thing.above) if clicker and pointed_thing then
pointed_thing.under = vector.add(pointed_thing.under, offs) local offs = vector.subtract(pointed_thing.under, pointed_thing.above)
pointed_thing.above = vector.add(pointed_thing.above, offs) pointed_thing.under = vector.add(pointed_thing.under, offs)
local pos1 = minetest.pointed_thing_to_face_pos(clicker, pointed_thing) pointed_thing.above = vector.add(pointed_thing.above, offs)
local y = pos1.y - pos.y local pos1 = minetest.pointed_thing_to_face_pos(clicker, pointed_thing)
local y = pos1.y - pos.y
if y < -0.3 then
return 4 if y < -0.3 then
elseif y < -0.03 and y > -0.22 then return 4
return 3 elseif y < -0.03 and y > -0.22 then
elseif y > 0.03 and y < 0.22 then return 3
return 2 elseif y > 0.03 and y < 0.22 then
elseif y > 0.3 then return 2
return 1 elseif y > 0.3 then
return 1
end
end end
end end
@ -134,10 +136,11 @@ local function send_cmnd(pos, num)
local meta = M(pos) local meta = M(pos)
local own_num = meta:get_string("node_number") local own_num = meta:get_string("node_number")
local dest = meta:get_string("dest_number" .. num) local dest = meta:get_string("dest_number" .. num)
local cmnd = meta:get_string("command" .. num) local s = meta:get_string("command" .. num)
local command, payload = unpack(string.split(s, " ", false, 1))
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
if techage.check_numbers(dest, owner) then if techage.check_numbers(dest, owner) then
techage.send_multi(own_num, dest, cmnd) techage.send_multi(own_num, dest, command, payload)
end end
end end

View File

@ -425,3 +425,5 @@ for _, name in ipairs(ProtectorDoors) do
logic.register_doorcontroller_nodes({name .. "_" .. postfix}) logic.register_doorcontroller_nodes({name .. "_" .. postfix})
end end
end end
logic.SimpleNodes = RegisteredNodes

View File

@ -67,13 +67,13 @@ function techage.logic.send_on(pos, meta, time)
return own_num == numbers return own_num == numbers
end end
function techage.logic.send_cmnd(pos, meta, cmnd, time) function techage.logic.send_cmnd(pos, meta, cmnd, payload, time)
local own_num = meta:get_string("node_number") or "" local own_num = meta:get_string("node_number") or ""
local numbers = meta:get_string("numbers") or "" local numbers = meta:get_string("numbers") or ""
if time and time > 0 then if time and time > 0 then
minetest.get_node_timer(pos):start(time) minetest.get_node_timer(pos):start(time)
end end
techage.send_multi(own_num, numbers, cmnd) techage.send_multi(own_num, numbers, cmnd, payload)
end end
function techage.logic.send_off(pos, meta) function techage.logic.send_off(pos, meta)

View File

@ -88,12 +88,12 @@ end
-- Attach player/mob to given parent object (block) -- Attach player/mob to given parent object (block)
local function attach_single_object(parent, obj, dir, height) local function attach_single_object(parent, obj, dir, height)
local self = parent:get_luaentity() local self = parent:get_luaentity()
local rot = obj:get_rotation() or {x=0, y=0, z=0} local rot = {x=0, y=0, z=0}
local prop = obj:get_properties() local prop = obj:get_properties()
local res = obj:get_attach() local res = obj:get_attach()
if not res and prop and prop.collisionbox then if not res and prop and prop.collisionbox then
dir = table.copy(dir) dir = table.copy(dir)
dir.y = dir.y - 1.5 + height - prop.collisionbox[2] dir.y = dir.y - 1.5 + (height or 1) - prop.collisionbox[2]
dir = vector.multiply(dir, 29) dir = vector.multiply(dir, 29)
obj:set_attach(parent, "", dir, rot, true) obj:set_attach(parent, "", dir, rot, true)
obj:set_properties({visual_size = {x = 2.9, y = 2.9}}) obj:set_properties({visual_size = {x = 2.9, y = 2.9}})
@ -108,23 +108,25 @@ local function attach_single_object(parent, obj, dir, height)
end end
-- Attach all entities around to the parent object (block). -- Attach all entities around to the parent object (block).
-- height is the parrwent block height (-0.5 to 0.5) -- height is the parent block height (0.1 to 1.0)
local function attach_objects(pos, parent, dir, height) local function attach_objects(pos, parent, dir, height)
local pos1 = vector.add(pos, dir) local pos1 = vector.add(pos, dir)
local self = parent:get_luaentity() local self = parent:get_luaentity()
self.players = self.players or {} self.players = self.players or {}
self.entities = self.entities or {} self.entities = self.entities or {}
for _, obj in pairs(minetest.get_objects_inside_radius(pos1, 0.8)) do print("pos1", P2S(pos1))
for _, obj in pairs(minetest.get_objects_inside_radius(pos1, 0.9)) do
local entity = obj:get_luaentity() local entity = obj:get_luaentity()
if entity then if entity then
if entity.name == "__builtin:item" then -- dropped items if entity.name == "__builtin:item" then -- dropped items
--obj:set_attach(objref, "", {x=0, y=0, z=0}, {x=0, y=0, z=0}, true) -- hier kracht es --obj:set_attach(objref, "", {x=0, y=0, z=0}, {x=0, y=0, z=0}, true) -- hier kracht es
elseif entity.name ~= "techage:move_item" then elseif entity.name ~= "techage:move_item" then
attach_single_object(parent, obj, dir, height) attach_single_object(parent, obj, dir, 1)
end end
elseif obj:is_player() then elseif obj:is_player() then
attach_single_object(parent, obj, dir) print("is_player")
attach_single_object(parent, obj, dir, 1)
end end
end end
end end
@ -158,7 +160,7 @@ local function detach_objects(pos, parent, dir)
end end
local function entity_to_node(pos, obj) local function entity_to_node(pos, obj)
local name = obj:get_luaentity().item or "air" local name = (obj:get_luaentity() or {}).item or "air"
local rot = obj:get_rotation() local rot = obj:get_rotation()
detach_objects(pos, obj) detach_objects(pos, obj)
obj:remove() obj:remove()
@ -183,13 +185,16 @@ local function node_to_entity(pos, handover)
local dir = minetest.facedir_to_dir(node.param2) local dir = minetest.facedir_to_dir(node.param2)
local yaw = minetest.dir_to_yaw(dir) local yaw = minetest.dir_to_yaw(dir)
local obj = minetest.add_entity(pos, "techage:move_item") local obj = minetest.add_entity(pos, "techage:move_item")
local self = obj:get_luaentity() if obj then
obj:set_rotation({x=0, y=yaw, z=0}) local self = obj:get_luaentity()
obj:set_properties({wield_item = node.name}) obj:set_rotation({x=0, y=yaw, z=0})
obj:set_armor_groups({immortal=1}) obj:set_properties({wield_item = node.name})
self.item = node.name obj:set_armor_groups({immortal=1})
self.handover = handover self.item = node.name
return obj self.handover = handover
self.start_pos = table.copy(pos)
return obj
end
end end
local function capture_entity(pos) local function capture_entity(pos)
@ -219,12 +224,15 @@ local function move_entity(obj, pos2, dir, max_speed)
end end
-- Handover the entity to the next movecontroller -- Handover the entity to the next movecontroller
local function handover_to(self) local function handover_to(pos, self)
local info = techage.get_node_info(self.handover) local info = techage.get_node_info(self.handover)
if info and info.name == "techage:ta4_movecontroller" then if info and info.name == "techage:ta4_movecontroller" then
local mem = techage.get_mem(info.pos) local mem = techage.get_mem(info.pos)
if not mem.entities_are_there then if not mem.entities_are_there then
mem.entities_are_there = true mem.entities_are_there = true
-- copy move direction
--print("techage.get_nvm(pos).pos_2to1", techage.get_nvm(pos).pos_2to1)
techage.get_nvm(info.pos).pos_2to1 = techage.get_nvm(pos).pos_2to1
minetest.after(0.2, techage.send_single, "0", self.handover, "handover") minetest.after(0.2, techage.send_single, "0", self.handover, "handover")
end end
return true return true
@ -249,7 +257,9 @@ minetest.register_entity("techage:move_item", {
item = self.item, item = self.item,
max_speed = self.max_speed, max_speed = self.max_speed,
dest_pos = self.dest_pos, dest_pos = self.dest_pos,
start_pos = self.start_pos,
dir = self.dir, dir = self.dir,
respawn = true,
}) })
end, end,
@ -259,8 +269,12 @@ minetest.register_entity("techage:move_item", {
self.item = tbl.item or "air" self.item = tbl.item or "air"
self.max_speed = tbl.max_speed or MAX_SPEED self.max_speed = tbl.max_speed or MAX_SPEED
self.dest_pos = tbl.dest_pos or self.object:get_pos() self.dest_pos = tbl.dest_pos or self.object:get_pos()
self.start_pos = tbl.start_pos or self.object:get_pos()
self.dir = tbl.dir or {x=0, y=0, z=0} self.dir = tbl.dir or {x=0, y=0, z=0}
self.object:set_properties({wield_item = self.item}) self.object:set_properties({wield_item = self.item})
if tbl.respawn then
entity_to_node(self.start_pos, self.object)
end
end end
end, end,
@ -277,7 +291,7 @@ minetest.register_entity("techage:move_item", {
obj:set_acceleration({x=0, y=0, z=0}) obj:set_acceleration({x=0, y=0, z=0})
obj:set_velocity({x=0, y=0, z=0}) obj:set_velocity({x=0, y=0, z=0})
self.dest_pos = nil self.dest_pos = nil
if not self.handover or not handover_to(self) then if not self.handover or not handover_to(pos, self) then
minetest.after(0.5, entity_to_node, pos, obj) minetest.after(0.5, entity_to_node, pos, obj)
end end
self.ttl = 2 self.ttl = 2
@ -308,7 +322,7 @@ minetest.register_entity("techage:move_item", {
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
local MarkedNodes = {} -- t[player] = {{entity, pos},...} local MarkedNodes = {} -- t[player] = {{entity, pos},...}
local CurrentPos -- to mark punched entities local CurrentPos -- to mark punched entities
local RegisteredNodes = {} -- to be checked before removed/placed local SimpleNodes = techage.logic.SimpleNodes
local function is_air_like(pos) local function is_air_like(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
@ -322,8 +336,8 @@ end
local function is_simple_node(pos) local function is_simple_node(pos)
-- special handling -- special handling
local name = minetest.get_node(pos).name local name = minetest.get_node(pos).name
if RegisteredNodes[name] ~= nil then if SimpleNodes[name] ~= nil then
return RegisteredNodes[name] return SimpleNodes[name]
end end
local ndef = minetest.registered_nodes[name] local ndef = minetest.registered_nodes[name]
@ -496,13 +510,15 @@ local function move_node(pos, pos1, pos2, max_speed, handover, height)
local dir = determine_dir(pos1, pos2) local dir = determine_dir(pos1, pos2)
local obj = node_to_entity(pos1, handover) local obj = node_to_entity(pos1, handover)
attach_objects(pos1, obj, {x=0, y=1, z=0}, height) if obj then
if dir.y == 0 then attach_objects(pos1, obj, {x=0, y=height, z=0}, height)
if (dir.x ~= 0 and dir.z == 0) or (dir.x == 0 and dir.z ~= 0) then if dir.y == 0 then
attach_objects(pos1, obj, dir, height) if (dir.x ~= 0 and dir.z == 0) or (dir.x == 0 and dir.z ~= 0) then
attach_objects(pos1, obj, dir, 1)
end
end end
move_entity(obj, pos2, dir, max_speed)
end end
move_entity(obj, pos2, dir, max_speed)
end end
local function move_nodes(pos, lpos1, lpos2, handover) local function move_nodes(pos, lpos1, lpos2, handover)
@ -596,16 +612,16 @@ local function move_to_other_pos(pos)
local meta = M(pos) local meta = M(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
if nvm.pos2 then if nvm.pos_2to1 then
local lpos1 = nvm.lpos1 or {} local lpos1 = nvm.lpos1 or {}
local lpos2 = nvm.lpos2 or {} local lpos2 = nvm.lpos2 or {}
nvm.pos2 = false nvm.pos_2to1 = false
local handover = meta:contains("handoverA") and meta:get_string("handoverA") local handover = meta:contains("handoverA") and meta:get_string("handoverA")
return move_nodes(pos, lpos2, lpos1, handover) return move_nodes(pos, lpos2, lpos1, handover)
else else
local lpos1 = nvm.lpos1 or {} local lpos1 = nvm.lpos1 or {}
local lpos2 = nvm.lpos2 or {} local lpos2 = nvm.lpos2 or {}
nvm.pos2 = true nvm.pos_2to1 = true
local handover = meta:contains("handoverB") and meta:get_string("handoverB") local handover = meta:contains("handoverB") and meta:get_string("handoverB")
return move_nodes(pos, lpos1, lpos2, handover) return move_nodes(pos, lpos1, lpos2, handover)
end end
@ -617,16 +633,16 @@ local function takeover(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.entities_are_there = nil mem.entities_are_there = nil
if nvm.pos2 then if nvm.pos_2to1 then
local lpos1 = nvm.lpos1 or {} local lpos1 = nvm.lpos1 or {}
local lpos2 = nvm.lpos2 or {} local lpos2 = nvm.lpos2 or {}
nvm.pos2 = false nvm.pos_2to1 = false
local handover = meta:contains("handoverA") and meta:get_string("handoverA") local handover = meta:contains("handoverA") and meta:get_string("handoverA")
return moveon_nodes(pos, lpos2, lpos1, handover) return moveon_nodes(pos, lpos2, lpos1, handover)
else else
local lpos1 = nvm.lpos1 or {} local lpos1 = nvm.lpos1 or {}
local lpos2 = nvm.lpos2 or {} local lpos2 = nvm.lpos2 or {}
nvm.pos2 = true nvm.pos_2to1 = true
local handover = meta:contains("handoverB") and meta:get_string("handoverB") local handover = meta:contains("handoverB") and meta:get_string("handoverB")
return moveon_nodes(pos, lpos1, lpos2, handover) return moveon_nodes(pos, lpos1, lpos2, handover)
end end
@ -660,7 +676,7 @@ minetest.register_node("techage:ta4_movecontroller", {
if fields.record then if fields.record then
nvm.lpos1 = nil nvm.lpos1 = nil
nvm.lpos2 = nil nvm.lpos2 = nil
nvm.pos2 = false nvm.pos_2to1 = false
meta:set_string("status", S("Recording...")) meta:set_string("status", S("Recording..."))
local name = player:get_player_name() local name = player:get_player_name()
minetest.chat_send_player(name, S("Click on all blocks that shall be moved")) minetest.chat_send_player(name, S("Click on all blocks that shall be moved"))
@ -674,17 +690,17 @@ minetest.register_node("techage:ta4_movecontroller", {
meta:set_string("distance", fields.distance) meta:set_string("distance", fields.distance)
nvm.lpos1 = pos_list nvm.lpos1 = pos_list
nvm.lpos2 = table_add(pos_list, to_vector(fields.distance)) nvm.lpos2 = table_add(pos_list, to_vector(fields.distance))
nvm.pos2 = false nvm.pos_2to1 = false
unmark_all(name) unmark_all(name)
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
elseif fields.store then elseif fields.store then
meta:set_string("distance", fields.distance) meta:set_string("distance", fields.distance)
nvm.lpos2 = table_add(nvm.lpos1, to_vector(fields.distance)) nvm.lpos2 = table_add(nvm.lpos1, to_vector(fields.distance))
nvm.pos2 = false nvm.pos_2to1 = false
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
elseif fields.moveAB then elseif fields.moveAB then
meta:set_string("status", "") meta:set_string("status", "")
nvm.pos2 = false nvm.pos_2to1 = false
if move_to_other_pos(pos) then if move_to_other_pos(pos) then
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
local name = player:get_player_name() local name = player:get_player_name()
@ -692,7 +708,7 @@ minetest.register_node("techage:ta4_movecontroller", {
end end
elseif fields.moveBA then elseif fields.moveBA then
meta:set_string("status", "") meta:set_string("status", "")
nvm.pos2 = true nvm.pos_2to1 = true
if move_to_other_pos(pos) then if move_to_other_pos(pos) then
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
local name = player:get_player_name() local name = player:get_player_name()
@ -723,11 +739,11 @@ techage.register_node({"techage:ta4_movecontroller"}, {
return INFO return INFO
elseif topic == "a2b" then elseif topic == "a2b" then
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.pos2 = false nvm.pos_2to1 = false
return move_to_other_pos(pos) return move_to_other_pos(pos)
elseif topic == "b2a" then elseif topic == "b2a" then
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.pos2 = true nvm.pos_2to1 = true
return move_to_other_pos(pos) return move_to_other_pos(pos)
elseif topic == "move" then elseif topic == "move" then
return move_to_other_pos(pos) return move_to_other_pos(pos)
@ -738,14 +754,14 @@ techage.register_node({"techage:ta4_movecontroller"}, {
end, end,
}) })
--minetest.register_craft({ minetest.register_craft({
-- output = "techage:ta4_movecontroller", output = "techage:ta4_movecontroller",
-- recipe = { recipe = {
-- {"techage:aluminum", "group:wood","techage:aluminum"}, {"default:steel_ingot", "dye:blue", "default:steel_ingot"},
-- {"default:mese_crystal_fragment", "techage:ta4_wlanchip", "default:mese_crystal_fragment"}, {"default:mese_crystal_fragment", "techage:ta4_wlanchip", "default:mese_crystal_fragment"},
-- {"group:wood", "basic_materials:gear_steel", "group:wood"}, {"group:wood", "basic_materials:gear_steel", "group:wood"},
-- }, },
--}) })
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
unlock_player(player) unlock_player(player)

View File

@ -60,7 +60,7 @@ local function formspec_help()
"label[0,1;Define a sequence of commands\nto control other machines.]".. "label[0,1;Define a sequence of commands\nto control other machines.]"..
"label[0,2.2;Numbers(s) are the node numbers,\nthe command shall sent to.]".. "label[0,2.2;Numbers(s) are the node numbers,\nthe command shall sent to.]"..
"label[0,3.4;The commands 'on'/'off' are used\n for machines and other nodes.]".. "label[0,3.4;The commands 'on'/'off' are used\n for machines and other nodes.]"..
"label[0,4.6;Offset is the time to the\nnext line in seconds (1..999).]".. "label[0,4.6;Offset is the time to the\nnext line in seconds (0.2 to 999).]"..
"label[0,5.8;If endless is set, the Sequencer\nrestarts again and again.]".. "label[0,5.8;If endless is set, the Sequencer\nrestarts again and again.]"..
"label[0,7;The command ' ' does nothing,\nonly consuming the offset time.]".. "label[0,7;The command ' ' does nothing,\nonly consuming the offset time.]"..
"button[3,8;2,1;exit;close]" "button[3,8;2,1;exit;close]"

View File

@ -31,10 +31,8 @@ end
local function command(s) local function command(s)
local num, cmd, pld = unpack(string.split(s, " ", false, 2)) local num, cmd, pld = unpack(string.split(s, " ", false, 2))
if not num or not cmd then if not num or not cmd then
print("error: Invalid command") return "Invalid command!"
return
end end
print(num, cmd, pld)
return {number = num, cmnd = cmd, payload = pld} return {number = num, cmnd = cmd, payload = pld}
end end
@ -62,14 +60,12 @@ local function compile(s, tRes)
local old_idx = 0 local old_idx = 0
local start_idx local start_idx
print("Compile")
for i, line in ipairs(strsplit(s)) do for i, line in ipairs(strsplit(s)) do
line = trim(line) line = trim(line)
line = string.split(line, "--", true, 1)[1] or "" line = string.split(line, "--", true, 1)[1] or ""
if line ~= "" then if line ~= "" then
local idx, cmnd1, cmnd2 = unpack(string.split(line, " ", false, 2)) local idx, cmnd1, cmnd2 = unpack(string.split(line, " ", false, 2))
idx = tonumber(string.match(idx, "^%[(%d+)%]$")) idx = tonumber(string.match(idx, "^%[(%d+)%]$"))
print(idx, old_idx)
if not idx then if not idx then
return exception(tRes, i, "Syntax error!") return exception(tRes, i, "Syntax error!")
end end
@ -81,23 +77,29 @@ local function compile(s, tRes)
tCode[old_idx].next_idx = idx tCode[old_idx].next_idx = idx
end end
if cmnd1 == "send" then if cmnd1 == "send" then
tCode[idx] = command(cmnd2) local res = command(cmnd2)
if type(res) == "string" then
return exception(tRes, i, res)
end
tCode[idx] = res
elseif cmnd1 == "goto" then elseif cmnd1 == "goto" then
tCode[idx] = {next_idx = tonumber(cmnd2) or 1} tCode[idx] = {next_idx = tonumber(cmnd2) or 1}
elseif cmnd1 == "stop" then
tCode[idx] = false
elseif cmnd1 == nil then elseif cmnd1 == nil then
tCode[idx] = {} tCode[idx] = {}
end end
old_idx = idx old_idx = idx
end end
end end
-- return { -- Returns:
-- {
-- start_idx = 1, -- start_idx = 1,
-- tCode = { -- tCode = {
-- <idx> = {number = <number>, cmnd = <string>, payload = <data>, next_idx = <idx>}, -- <idx> = {number = <number>, cmnd = <string>, payload = <data>, next_idx = <idx>},
-- ... -- ...
-- }, -- },
-- } -- }
print(dump(tCode))
return {start_idx=start_idx, tCode=tCode} return {start_idx=start_idx, tCode=tCode}
end end
@ -160,7 +162,6 @@ local function restart_timer(pos, time)
end end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
print("node_timer")
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
if nvm.running then if nvm.running then
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
@ -169,7 +170,8 @@ local function node_timer(pos, elapsed)
mem.idx = mem.idx or mem.code.start_idx mem.idx = mem.idx or mem.code.start_idx
local code = mem.code.tCode[mem.idx] local code = mem.code.tCode[mem.idx]
if code and code.cmnd then if code and code.cmnd then
print(code.number, code.cmnd, code.payload, code.next_idx) local src = M(pos):get_string("node_number")
techage.send_single(src, code.number, code.cmnd, code.payload)
end end
if code and code.next_idx then if code and code.next_idx then
local offs = code.next_idx - mem.idx local offs = code.next_idx - mem.idx
@ -186,36 +188,37 @@ local function on_receive_fields(pos, formname, fields, player)
return return
end end
--print(dump(fields))
local meta = M(pos) local meta = M(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
nvm.running = nvm.running or false nvm.running = nvm.running or false
if fields.help then if fields.stop then
meta:set_string("formspec", formspec_help(nvm, meta))
return
elseif fields.edit then
meta:set_string("formspec", formspec(nvm, meta))
return
end
if fields.save then
nvm.running = false nvm.running = false
meta:set_string("text", fields.text or "") minetest.get_node_timer(pos):stop()
mem.code = nil elseif not nvm.running then
mem.idx = nil if fields.help then
elseif fields.start then meta:set_string("formspec", formspec_help(nvm, meta))
if check_syntax(meta) then return
nvm.running = true elseif fields.edit then
meta:set_string("formspec", formspec(nvm, meta))
return
end
if fields.save then
nvm.running = false
meta:set_string("text", fields.text or "") meta:set_string("text", fields.text or "")
mem.code = nil mem.code = nil
mem.idx = nil mem.idx = nil
minetest.get_node_timer(pos):start(0.5) elseif fields.start then
if check_syntax(meta) then
nvm.running = true
meta:set_string("text", fields.text or "")
mem.code = nil
mem.idx = nil
minetest.get_node_timer(pos):start(0.5)
end
end end
elseif fields.stop then
nvm.running = false
minetest.get_node_timer(pos):stop()
end end
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
end end
@ -257,35 +260,31 @@ minetest.register_node("techage:ta4_sequencer", {
minetest.register_craft({ minetest.register_craft({
output = "techage:ta4_sequencer", output = "techage:ta4_sequencer",
recipe = { recipe = {
{"group:wood", "group:wood", ""}, {"default:steel_ingot", "dye:blue", "default:steel_ingot"},
{"default:mese_crystal", "techage:wlanchip", ""}, {"techage:ta4_ramchip", "default:mese_crystal", "techage:wlanchip"},
{"group:wood", "group:wood", ""}, {"techage:aluminum", "group:wood","techage:aluminum"},
}, },
}) })
local INFO = [[Commands: 'goto <num>', 'stop']]
techage.register_node({"techage:ta4_sequencer"}, { techage.register_node({"techage:ta4_sequencer"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
if topic == "on" then if topic == "goto" then
start_the_sequencer(pos) local mem = techage.get_mem(pos)
elseif topic == "off" then
-- do not stop immediately
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
if not nvm.running then nvm.running = true
nvm.endless = not (nvm.endless or false) mem.idx = tonumber(payload or 1) or 1
else restart_timer(pos, 0.1)
nvm.endless = false elseif topic == "stop" then
end local nvm = techage.get_nvm(pos)
elseif topic == "pause" then nvm.running = false
stop_the_sequencer(pos) minetest.get_node_timer(pos):stop()
elseif topic == "info" then
return INFO
else else
return "unsupported" return "unsupported"
end end
end, end,
on_node_load = function(pos)
local nvm = techage.get_nvm(pos)
if nvm.running then
minetest.get_node_timer(pos):start(1)
end
end,
}) })

View File

@ -76,7 +76,7 @@ local function read_state(itemstack, user, pointed_thing)
if ndef and ndef.description then if ndef and ndef.description then
local info = techage.send_single("0", number, "info", nil) local info = techage.send_single("0", number, "info", nil)
if info and info ~= "" and info ~= "unsupported" then if info and info ~= "" and info ~= "unsupported" then
info = dump(info) info = tostring(info)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..":\n"..info.." ") minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..":\n"..info.." ")
end end
local state = techage.send_single("0", number, "state", nil) local state = techage.send_single("0", number, "state", nil)

View File

@ -130,7 +130,7 @@ local function value_check(elem, value)
if elem.check then if elem.check then
return elem.check(value) return elem.check(value)
end end
return true return value ~= nil
end end
local function evaluate_data(pos, meta, form_def, fields, player_name) local function evaluate_data(pos, meta, form_def, fields, player_name)