build capable

This commit is contained in:
nyje 2019-07-29 07:15:10 +00:00
parent cf5ca9e5ef
commit 97171280fb
3 changed files with 73 additions and 69 deletions

View File

@ -56,11 +56,10 @@ local function panel_commands()
{"move_forward","move_backward","move_up","move_down"},
{"turn_clockwise","turn_anticlockwise","turn_random"},
{"mode_dig_up","mode_dig","mode_dig_down"},
--{"mode_build_up","mode_build","mode_build_down"},
{"mode_build_up","mode_build","mode_build_down"},
--{"case_repeat","case_test","case_end","case_success","case_failure","case_yes","case_no" },
--{"mode_examine","mode_pause","mode_wait"},
{},
{},
{"number_0","number_1","number_2","number_3","number_4"},
{"number_5","number_6","number_7","number_8","number_9"},
{"run_1","run_2","run_3","run_4","run_5","run_6"}

View File

@ -16,7 +16,7 @@ local trashInv = minetest.create_detached_inventory(
end
})
trashInv:set_size("main", 1)
local STEPTIME = 0.3
-------------------------------------
-- Generate 32 bit key for formspec identification
-------------------------------------
@ -30,6 +30,38 @@ function vbots.get_key()
return key
end
vbots.bot_togglestate = function(pos,mode)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local timer = minetest.get_node_timer(pos)
local newname
if not mode then
if node.name == "vbots:off" then
mode = "on"
elseif node.name == "vbots:on" then
mode = "off"
end
end
if mode == "on" then
newname = "vbots:on"
timer:start(1)
meta:set_int("PC",STEPTIME)
meta:set_int("PR",0)
meta:set_string("stack","")
elseif mode == "off" then
newname = "vbots:off"
timer:stop()
meta:set_int("PC",0)
meta:set_int("PR",0)
meta:set_string("stack","")
end
--print(node.name.." "..newname)
if newname then
minetest.swap_node(pos,{name=newname, param2=node.param2})
end
end
dofile(vbots.modpath.."/formspec.lua")
dofile(vbots.modpath.."/formspec_handler.lua")
dofile(vbots.modpath.."/register_bot.lua")

View File

@ -216,70 +216,31 @@ local function bot_dig(pos,digy)
end
end
vbots.bot_togglestate = function(pos,mode)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local timer = minetest.get_node_timer(pos)
local newname
if not mode then
if node.name == "vbots:off" then
mode = "on"
elseif node.name == "vbots:on" then
mode = "off"
end
end
if mode == "on" then
newname = "vbots:on"
timer:start(1)
meta:set_int("PC",STEPTIME)
meta:set_int("PR",0)
meta:set_string("stack","")
elseif mode == "off" then
newname = "vbots:off"
timer:stop()
meta:set_int("PC",0)
meta:set_int("PR",0)
meta:set_string("stack","")
end
--print(node.name.." "..newname)
if newname then
minetest.swap_node(pos,{name=newname, param2=node.param2})
end
end
local function punch_bot(pos,player)
local function bot_build(pos,buildy)
local meta = minetest.get_meta(pos)
local bot_owner = meta:get_string("owner")
if bot_owner == player:get_player_name() then
local item = player:get_wielded_item():get_name()
if item == "" then
vbots.bot_togglestate(pos)
elseif item == "vbots:move_forward" then
move_bot(pos,"f")
elseif item == "vbots:move_backward" then
move_bot(pos,"b")
elseif item == "vbots:move_up" then
move_bot(pos,"u")
elseif item == "vbots:move_down" then
move_bot(pos,"d")
elseif item == "vbots:turn_clockwise" then
bot_turn_clockwise(pos)
elseif item == "vbots:turn_anticlockwise" then
bot_turn_anticlockwise(pos)
elseif item == "vbots:turn_random" then
bot_turn_random(pos)
elseif item == "vbots:mode_dig" then
bot_dig(pos,0)
elseif item == "vbots:mode_dig_down" then
bot_dig(pos,-1)
elseif item == "vbots:mode_dig_up" then
bot_dig(pos,1)
elseif item == "vbots:mode_build" then
bot_build(pos,0)
elseif item == "vbots:mode_build_down" then
bot_build(pos,-1)
elseif item == "vbots:mode_build_up" then
bot_build(pos,1)
local node = minetest.get_node(pos)
local dir = minetest.facedir_to_dir(node.param2)
local inv=minetest.get_inventory({type="node", pos=pos})
local buildpos
if buildy == 0 then
buildpos = {x = pos.x+dir.x, y = pos.y, z = pos.z+dir.z}
else
buildpos = {x = pos.x, y = pos.y+buildy, z = pos.z}
end
if not minetest.is_protected(buildpos, bot_owner) then
local content = inv:get_list("main")
local a = 1
local found = nil
while( a<57 and not found) do
if not content[a]:is_empty() then
found = content[a]:get_name()
end
a=a+1
end
if found then
print(found)
minetest.set_node(buildpos,{name=found})
end
end
end
@ -321,17 +282,29 @@ local function bot_parsecommand(pos,item)
local PC = meta:get_int("PC")
local PR = meta:get_int("PR")
local R = meta:get_int("repeat")
print("Pushing state...")
-- print("Pushing state...")
push_state(pos,PC,PR,R)
meta:set_int("PR", item_parts[2])
meta:set_int("PC", 0)
meta:set_int("repeat", 0)
print("after update PR:"..PR..
" PC:"..meta:get_int("PC")..
" R:"..meta:get_int("repeat"))
-- print("after update PR:"..PR..
-- " PC:"..meta:get_int("PC")..
-- " R:"..meta:get_int("repeat"))
end
end
local function punch_bot(pos,player)
local meta = minetest.get_meta(pos)
local bot_owner = meta:get_string("owner")
if bot_owner == player:get_player_name() then
local item = player:get_wielded_item():get_name()
if item == "" then
vbots.bot_togglestate(pos)
else
bot_parsecommand(pos,item)
end
end
end
local function bot_handletimer(pos)
local inv=minetest.get_inventory({type="node", pos=pos})