LBM wieder entfernt

This commit is contained in:
Joachim Stolberg 2018-07-13 21:07:34 +02:00
parent 38dafae5a4
commit 49f6c8c13a
3 changed files with 64 additions and 59 deletions

@ -229,11 +229,13 @@ local function check_fuel(pos, meta)
end end
local function reset_robot(pos, meta) local function reset_robot(pos, meta)
print("robot_pos", meta:get_string("robot_pos"))
local robot_pos = minetest.string_to_pos(meta:get_string("robot_pos")) local robot_pos = minetest.string_to_pos(meta:get_string("robot_pos"))
minetest.log("action", "[robby] reset_robot "..meta:get_string("robot_pos"))
if robot_pos then if robot_pos then
sl_robot.remove_robot(robot_pos) minetest.after(5, minetest.remove_node, robot_pos)
end end
local param2 = (minetest.get_node(pos).param2 + 1) % 4 local param2 = (minetest.get_node(pos).param2 + 1) % 4
robot_pos = sl_robot.new_pos(pos, param2, 1) robot_pos = sl_robot.new_pos(pos, param2, 1)
local pos_below = {x=robot_pos.x, y=robot_pos.y-1, z=robot_pos.z} local pos_below = {x=robot_pos.x, y=robot_pos.y-1, z=robot_pos.z}

@ -37,6 +37,7 @@ sl_robot.register_action("forward", {
idx = idx + 1 idx = idx + 1
end end
meta:set_string("robot_pos", minetest.pos_to_string(new_pos)) meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
minetest.log("action", "[robby] forward "..meta:get_string("robot_pos"))
else -- blocked else -- blocked
-- because of unloaded areas and the LBM replace blocked robots -- because of unloaded areas and the LBM replace blocked robots
--minetest.set_node(robot_pos, {name = "sl_robot:robot_dummy", param2 = robot_param2}) --minetest.set_node(robot_pos, {name = "sl_robot:robot_dummy", param2 = robot_param2})
@ -54,6 +55,7 @@ sl_robot.register_action("left", {
local robot_param2 = meta:get_int("robot_param2") local robot_param2 = meta:get_int("robot_param2")
robot_param2 = sl_robot.turn_robot(robot_pos, robot_param2, "L") robot_param2 = sl_robot.turn_robot(robot_pos, robot_param2, "L")
meta:set_int("robot_param2", robot_param2) meta:set_int("robot_param2", robot_param2)
minetest.log("action", "[robby] left "..meta:get_string("robot_pos"))
coroutine.yield() coroutine.yield()
end, end,
help = "tbd" help = "tbd"
@ -66,6 +68,7 @@ sl_robot.register_action("right", {
local robot_param2 = meta:get_int("robot_param2") local robot_param2 = meta:get_int("robot_param2")
robot_param2 = sl_robot.turn_robot(robot_pos, robot_param2, "R") robot_param2 = sl_robot.turn_robot(robot_pos, robot_param2, "R")
meta:set_int("robot_param2", robot_param2) meta:set_int("robot_param2", robot_param2)
minetest.log("action", "[robby] right "..meta:get_string("robot_pos"))
coroutine.yield() coroutine.yield()
end, end,
help = "tbd" help = "tbd"
@ -83,6 +86,7 @@ sl_robot.register_action("up", {
coroutine.yield() coroutine.yield()
end end
meta:set_string("robot_pos", minetest.pos_to_string(new_pos)) meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
minetest.log("action", "[robby] up "..meta:get_string("robot_pos"))
coroutine.yield() coroutine.yield()
end, end,
help = "tbd" help = "tbd"
@ -93,12 +97,14 @@ sl_robot.register_action("down", {
local meta = minetest.get_meta(self.meta.pos) local meta = minetest.get_meta(self.meta.pos)
local robot_pos = minetest.string_to_pos(meta:get_string("robot_pos")) local robot_pos = minetest.string_to_pos(meta:get_string("robot_pos"))
local robot_param2 = meta:get_int("robot_param2") local robot_param2 = meta:get_int("robot_param2")
local new_pos
while true do while true do
new_pos = sl_robot.robot_down(robot_pos, robot_param2) new_pos = sl_robot.robot_down(robot_pos, robot_param2)
if new_pos then break end if new_pos then break end
coroutine.yield() coroutine.yield()
end end
meta:set_string("robot_pos", minetest.pos_to_string(new_pos)) meta:set_string("robot_pos", minetest.pos_to_string(new_pos))
minetest.log("action", "[robby] down "..meta:get_string("robot_pos"))
coroutine.yield() coroutine.yield()
end, end,
help = "tbd" help = "tbd"

@ -61,7 +61,7 @@ end
function sl_robot.remove_robot(pos) function sl_robot.remove_robot(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if node.name == "sl_robot:robot" or node.name == "sl_robot:robot_dummy" then if node.name == "sl_robot:robot" then
minetest.remove_node(pos) minetest.remove_node(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}
node = minetest.get_node(pos1) node = minetest.get_node(pos1)
@ -144,7 +144,7 @@ function sl_robot.robot_up(pos, param2)
minetest.swap_node(pos, {name="sl_robot:robot_foot"}) minetest.swap_node(pos, {name="sl_robot:robot_foot"})
end end
minetest.set_node(pos1, {name="sl_robot:robot", param2=param2}) minetest.set_node(pos1, {name="sl_robot:robot", param2=param2})
minetest.sound_play('sl_robot_step', {pos = new_pos}) minetest.sound_play('sl_robot_step', {pos = pos1})
return pos1 return pos1
end end
return nil return nil
@ -154,21 +154,18 @@ end
-- [R] -- [R]
-- 1 -- 1
-- 2 -- 2
-- 3
function sl_robot.robot_down(pos, param2) function sl_robot.robot_down(pos, param2)
if dir == "U" then dir = 1 else dir = -1 end local pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
local new_pos = {x=pos.x, y=pos.y-1, z=pos.z} local pos2 = {x=pos.x, y=pos.y-2, z=pos.z}
local new_pos_node = minetest.get_node(new_pos) local pos3 = {x=pos.x, y=pos.y-3, z=pos.z}
local objects = minetest.get_objects_inside_radius(new_pos, 1) local node1 = minetest.get_node_or_nil(pos1) or read_node_with_vm(pos1)
if #objects == 0 and new_pos_node.name == "sl_robot:robot_foot" or if node1.name == "air" and check_pos(pos2, pos3) then
new_pos_node.name == "sl_robot:robot_leg" then
minetest.remove_node(pos) minetest.remove_node(pos)
minetest.set_node(new_pos, {name="sl_robot:robot", param2=param2}) minetest.set_node(pos2, {name="sl_robot:robot", param2=param2})
minetest.sound_play('sl_robot_step', {pos = new_pos}) minetest.sound_play('sl_robot_step', {pos = pos2})
return new_pos return pos2
end end
pos.y = pos.y+1
minetest.sound_play('sl_robot_go_away', {pos = pos, gain = 0.6})
pos.y = pos.y-1
return nil return nil
end end
@ -201,36 +198,36 @@ minetest.register_node("sl_robot:robot", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
-- dummy robots are used as marker for stucked robots in unloaded areas ---- dummy robots are used as marker for stucked robots in unloaded areas
minetest.register_node("sl_robot:robot_dummy", { --minetest.register_node("sl_robot:robot_dummy", {
description = "SaferLua Robot", -- description = "SaferLua Robot",
-- up, down, right, left, back, front -- -- up, down, right, left, back, front
tiles = { -- tiles = {
"sl_robot_robot_top.png^[opacity:127", -- "sl_robot_robot_top.png^[opacity:127",
"sl_robot_robot_bottom.png^[opacity:127", -- "sl_robot_robot_bottom.png^[opacity:127",
"sl_robot_robot_right.png^[opacity:127", -- "sl_robot_robot_right.png^[opacity:127",
"sl_robot_robot_left.png^[opacity:127", -- "sl_robot_robot_left.png^[opacity:127",
"sl_robot_robot_front.png^[opacity:127", -- "sl_robot_robot_front.png^[opacity:127",
"sl_robot_robot_back.png^[opacity:127", -- "sl_robot_robot_back.png^[opacity:127",
}, -- },
drawtype = "nodebox", -- drawtype = "nodebox",
use_texture_alpha = true, -- use_texture_alpha = true,
node_box = { -- node_box = {
type = "fixed", -- type = "fixed",
fixed = { -- fixed = {
{ -5/16, 3/16, -5/16, 5/16, 8/16, 5/16}, -- { -5/16, 3/16, -5/16, 5/16, 8/16, 5/16},
{ -3/16, 2/16, -3/16, 3/16, 3/16, 3/16}, -- { -3/16, 2/16, -3/16, 3/16, 3/16, 3/16},
{ -6/16, -7/16, -6/16, 6/16, 2/16, 6/16}, -- { -6/16, -7/16, -6/16, 6/16, 2/16, 6/16},
{ -6/16, -8/16, -3/16, 6/16, -7/16, 3/16}, -- { -6/16, -8/16, -3/16, 6/16, -7/16, 3/16},
}, -- },
}, -- },
paramtype2 = "facedir", -- paramtype2 = "facedir",
is_ground_content = false, -- is_ground_content = false,
walkable = false, -- walkable = false,
drop = "", -- drop = "",
groups = {cracky = 3}, -- groups = {cracky = 3},
sounds = default.node_sound_metal_defaults(), -- sounds = default.node_sound_metal_defaults(),
}) --})
minetest.register_node("sl_robot:robot_leg", { minetest.register_node("sl_robot:robot_leg", {
description = "SaferLua Robot", description = "SaferLua Robot",
@ -266,17 +263,17 @@ minetest.register_node("sl_robot:robot_foot", {
}) })
minetest.register_lbm({ --minetest.register_lbm({
label = "[sl_robot] Remove Robots", -- label = "[sl_robot] Remove Robots",
name = "sl_robot:update", -- name = "sl_robot:update",
nodenames = {"sl_robot:robot", "sl_robot:robot_leg", "sl_robot:robot_foot"}, -- nodenames = {"sl_robot:robot", "sl_robot:robot_leg", "sl_robot:robot_foot"},
run_at_every_load = true, -- run_at_every_load = true,
action = function(pos, node) -- action = function(pos, node)
if node.name == "sl_robot:robot" then -- if node.name == "sl_robot:robot" then
minetest.swap_node(pos, {name="sl_robot:robot_dummy", param2 = node.param2}) -- minetest.swap_node(pos, {name="sl_robot:robot_dummy", param2 = node.param2})
else -- else
minetest.remove_node(pos) -- minetest.remove_node(pos)
end -- end
end -- end
}) --})