Fix crash when npc close a door

Comment debug messages
This commit is contained in:
sys4-fr
2018-03-27 23:29:04 +02:00
parent dfaa904ba8
commit 97da2dc191
10 changed files with 90 additions and 87 deletions

View File

@ -201,7 +201,7 @@ function npc.actions.freeze(self, args)
local freeze_mobs_api = args.freeze
local disable_rightclick = args.disable_rightclick
if disable_rightclick ~= nil then
npc.log("INFO", "Enabling interactions for NPC "..self.npc_name..": "..dump(not(disable_rightclick)))
--npc.log("INFO", "Enabling interactions for NPC "..self.npc_name..": "..dump(not(disable_rightclick)))
self.enable_rightclick_interaction = not(disable_rightclick)
end
-- minetest.log("Received: "..dump(freeze_mobs_api))
@ -751,7 +751,7 @@ end
function npc.actions.use_furnace(self, args)
local pos = get_pos_argument(self, args.pos)
if pos == nil then
npc.log("WARNING", "Got nil position in 'use_furnace' using args.pos: "..dump(args.pos))
-- npc.log("WARNING", "Got nil position in 'use_furnace' using args.pos: "..dump(args.pos))
return
end
@ -787,16 +787,16 @@ function npc.actions.use_furnace(self, args)
local fuel_time =
minetest.get_craft_result({method="fuel", width=1, items={ItemStack(fuel_item.item_string)}}).time
local total_fuel_time = fuel_time * npc.get_item_count(fuel_item.item_string)
npc.log("DEBUG", "Fuel time: "..dump(fuel_time))
--npc.log("DEBUG", "Fuel time: "..dump(fuel_time))
-- Get item to cook's cooking time
local cook_result =
minetest.get_craft_result({method="cooking", width=1, items={ItemStack(src_item.item_string)}})
local total_cook_time = cook_result.time * npc.get_item_count(item)
npc.log("DEBUG", "Cook: "..dump(cook_result))
--npc.log("DEBUG", "Cook: "..dump(cook_result))
npc.log("DEBUG", "Total cook time: "..total_cook_time
..", total fuel burn time: "..dump(total_fuel_time))
-- npc.log("DEBUG", "Total cook time: "..total_cook_time
-- ..", total fuel burn time: "..dump(total_fuel_time))
-- Check if there is enough fuel to cook all items
if total_cook_time > total_fuel_time then
@ -844,7 +844,7 @@ function npc.actions.use_furnace(self, args)
npc.add_action(self, npc.actions.cmd.PUT_ITEM, args)
-- Now, set NPC to wait until furnace is done.
npc.log("DEBUG", "Setting wait action for "..dump(total_cook_time))
-- npc.log("DEBUG", "Setting wait action for "..dump(total_cook_time))
npc.add_action(self, npc.actions.cmd.SET_INTERVAL, {interval=total_cook_time, freeze=freeze})
-- Reset timer
@ -853,7 +853,7 @@ function npc.actions.use_furnace(self, args)
-- If freeze is false, then we will have to find the way back to the furnace
-- once cooking is done.
if freeze == false then
npc.log("DEBUG", "Adding walk to position to wandering: "..dump(pos))
-- npc.log("DEBUG", "Adding walk to position to wandering: "..dump(pos))
npc.add_task(self, npc.actions.cmd.WALK_TO_POS, {end_pos=pos, walkable={}})
end
@ -870,7 +870,7 @@ function npc.actions.use_furnace(self, args)
npc.log("DEBUG", "Taking item back: "..minetest.pos_to_string(pos))
npc.add_action(self, npc.actions.cmd.TAKE_ITEM, args)
npc.log("DEBUG", "Inventory: "..dump(self.inventory))
-- npc.log("DEBUG", "Inventory: "..dump(self.inventory))
-- Set furnace as unused if flag is enabled
if enable_usage_marking then
@ -890,7 +890,7 @@ end
function npc.actions.use_bed(self, args)
local pos = get_pos_argument(self, args.pos)
if pos == nil then
npc.log("WARNING", "Got nil position in 'use_bed' using args.pos: "..dump(args.pos))
-- npc.log("WARNING", "Got nil position in 'use_bed' using args.pos: "..dump(args.pos))
return
end
local action = args.action
@ -973,7 +973,7 @@ end
function npc.actions.use_sittable(self, args)
local pos = get_pos_argument(self, args.pos)
if pos == nil then
npc.log("WARNING", "Got nil position in 'use_sittable' using args.pos: "..dump(args.pos))
-- npc.log("WARNING", "Got nil position in 'use_sittable' using args.pos: "..dump(args.pos))
return
end
local action = args.action
@ -1068,7 +1068,7 @@ function npc.actions.walk_to_pos(self, args)
local use_access_node = args.use_access_node or true
local end_pos, node_pos = get_pos_argument(self, args.end_pos, use_access_node)
if end_pos == nil then
npc.log("WARNING", "Got nil position in 'walk_to_pos' using args.pos: "..dump(args.end_pos))
-- npc.log("WARNING", "Got nil position in 'walk_to_pos' using args.pos: "..dump(args.end_pos))
return
end
local enforce_move = args.enforce_move or true
@ -1128,7 +1128,7 @@ function npc.actions.walk_to_pos(self, args)
if use_access_node == true then
dir = npc.actions.get_direction(end_pos, node_pos)
end
minetest.log("Dir: "..dump(dir))
-- minetest.log("Dir: "..dump(dir))
-- Change dir if using access_node
npc.add_action(self, npc.actions.cmd.STAND, {dir = dir})
break
@ -1146,6 +1146,8 @@ function npc.actions.walk_to_pos(self, args)
-- Open door
npc.add_action(self, npc.actions.cmd.USE_OPENABLE, {pos=path[i+1].pos, dir=dir, action=npc.actions.const.doors.action.OPEN})
door_opened = true
else
door_opened = true
end
@ -1170,9 +1172,10 @@ function npc.actions.walk_to_pos(self, args)
-- Add extra walk step to ensure that one is standing at other side of openable node
-- npc.add_action(self, npc.actions.cmd.WALK_STEP, {dir = dir, speed = speed, target_pos = path[i+2].pos})
-- Stop to close the door
npc.add_action(self, npc.actions.cmd.STAND, {dir=(dir + 2) % 4 })--, pos=pos_on_close})
--npc.add_action(self, npc.actions.cmd.STAND, {dir=(dir + 2) % 4 })--, pos=pos_on_close})
npc.add_action(self, npc.actions.cmd.STAND, {dir=dir })--, pos=pos_on_close})
-- Close door
npc.add_action(self, npc.actions.cmd.USE_OPENABLE, {pos=path[i+1].pos, action=npc.actions.const.doors.action.CLOSE})
npc.add_action(self, npc.actions.cmd.USE_OPENABLE, {pos=path[i+1].pos, dir=dir, action=npc.actions.const.doors.action.CLOSE})
door_opened = false
end

View File

@ -67,7 +67,7 @@ function pathfinder.get_decorated_path(path)
type=pathfinder.is_good_node(node, {})})
end
npc.log("DEBUG", "Detailed path: "..dump(path_detail))
--npc.log("DEBUG", "Detailed path: "..dump(path_detail))
return path_detail
end

View File

@ -179,8 +179,8 @@ function npc.places.add_owned_accessible_place(self, nodes, place_type, walkable
-- Assign node to NPC
npc.places.add_owned(self, place_type, place_type,
nodes[i].node_pos, empty_nodes[1].pos)
npc.log("DEBUG", "Added node at "..minetest.pos_to_string(nodes[i].node_pos)
.." to NPC "..dump(self.npc_name))
-- npc.log("DEBUG", "Added node at "..minetest.pos_to_string(nodes[i].node_pos)
-- .." to NPC "..dump(self.npc_name))
break
end
end
@ -227,12 +227,12 @@ function npc.places.mark_place_used(pos, value)
local meta = minetest.get_meta(pos)
local used = meta:get_string("advanced_npc:used")
if value == used then
npc.log("WARNING", "Attempted to set 'used' property of node at "
..minetest.pos_to_string(pos).." to the same value: '"..dump(value).."'")
-- npc.log("WARNING", "Attempted to set 'used' property of node at "
-- ..minetest.pos_to_string(pos).." to the same value: '"..dump(value).."'")
return false
else
meta:set_string("advanced_npc:used", value)
npc.log("DEBUG", "'Used' value at pos "..minetest.pos_to_string(pos)..": "..dump(meta:get_string("advanced_npc:used")))
-- npc.log("DEBUG", "'Used' value at pos "..minetest.pos_to_string(pos)..": "..dump(meta:get_string("advanced_npc:used")))
return true
end
end