Actions: Added door opening/closing to walk action.
This commit is contained in:
parent
cffd307cfe
commit
7f22a74d7d
@ -165,6 +165,15 @@ function npc.actions.take_item_from_external_inventory(args)
|
||||
return false
|
||||
end
|
||||
|
||||
function npc.actions.get_openable_node_state(node)
|
||||
local state = npc.actions.door_state.CLOSED
|
||||
local a_i1, a_i2 = string.find(node.name, "_a")
|
||||
if a_i1 == nil then
|
||||
state = npc.actions.door_state.OPEN
|
||||
end
|
||||
return state
|
||||
end
|
||||
|
||||
-- This function is used to open or close doors from
|
||||
-- that use the default doors mod
|
||||
function npc.actions.use_door(args)
|
||||
@ -172,12 +181,8 @@ function npc.actions.use_door(args)
|
||||
local pos = args.pos
|
||||
local action = args.action
|
||||
local node = minetest.get_node(pos)
|
||||
local state = npc.actions.door_state.CLOSED
|
||||
local a_i1, a_i2 = string.find(node.name, "_a")
|
||||
if a_i1 == nil then
|
||||
state = npc.actions.door_state.OPEN
|
||||
end
|
||||
--minetest.log("Node: "..dump(node)..". State: "..dump(state)..", Action: "..dump(action))
|
||||
local state = npc.actions.get_openable_node_state(node)
|
||||
|
||||
local clicker = self.object
|
||||
if action ~= state then
|
||||
minetest.registered_nodes[node.name].on_rightclick(pos, node, clicker, nil, nil)
|
||||
@ -268,6 +273,17 @@ function npc.actions.walk_to_pos(self, end_pos)
|
||||
end
|
||||
-- Get direction to move from path[i] to path[i+1]
|
||||
local dir = npc.actions.get_direction(path[i].pos, path[i+1].pos)
|
||||
-- Check if next node is a door, if it is, open it, then walk
|
||||
if path[i+1].type == "O" then
|
||||
-- Check if door is already open
|
||||
local node = minetest.get_node(path[i+1].pos)
|
||||
if npc.actions.get_openable_node_state(node) == npc.actions.door_state.CLOSED then
|
||||
-- Stop to open door, this avoids misplaced movements later on
|
||||
npc.add_action(self, npc.actions.stand, {self = self})
|
||||
-- Open door
|
||||
npc.add_action(self, npc.actions.use_door, {self=self, pos=path[i+1].pos, action=npc.actions.door_action.OPEN})
|
||||
end
|
||||
end
|
||||
-- Add walk action to action queue
|
||||
npc.add_action(self, npc.actions.walk_step, {self = self, dir = dir})
|
||||
end
|
||||
|
8
npc.lua
8
npc.lua
@ -346,11 +346,11 @@ local function npc_spawn(self, pos)
|
||||
ent.places_map = {}
|
||||
|
||||
-- Temporary initialization of actions for testing
|
||||
local nodes = npc.places.find_new_nearby(ent, {"doors:door_wood_a", "doors:door_wood_b"}, 2)
|
||||
npc.add_action(ent, npc.actions.use_door, {self = ent, pos = nodes[1], action = npc.actions.door_action.OPEN})
|
||||
local nodes = npc.places.find_new_nearby(ent, {"default:furnace"}, 20)
|
||||
--npc.add_action(ent, npc.actions.use_door, {self = ent, pos = nodes[1], action = npc.actions.door_action.OPEN})
|
||||
--npc.add_action(ent, npc.actions.stand, {self = ent})
|
||||
--npc.add_action(ent, npc.actions.stand, {self = ent}
|
||||
--npc.actions.walk_to_pos(ent, nodes[1])
|
||||
npc.add_action(ent, npc.actions.stand, {self = ent})
|
||||
npc.actions.walk_to_pos(ent, nodes[1])
|
||||
-- npc.add_action(ent, npc.action.stand, {self = ent})
|
||||
-- npc.add_action(ent, npc.action.stand, {self = ent})
|
||||
-- npc.add_action(ent, npc.action.walk_step, {self = ent, dir = npc.direction.east})
|
||||
|
Loading…
Reference in New Issue
Block a user