Fixed bugs related to door positioning, opening/closing, and finding
positions in general.
This commit is contained in:
parent
43c69ffee4
commit
d92b729e19
@ -603,11 +603,18 @@ end
|
|||||||
|
|
||||||
-- TODO: Refactor this function so that it uses a table to check
|
-- TODO: Refactor this function so that it uses a table to check
|
||||||
-- for doors instead of having separate logic for each door type
|
-- for doors instead of having separate logic for each door type
|
||||||
function npc.actions.get_openable_node_state(node, npc_dir)
|
function npc.actions.get_openable_node_state(node, pos, npc_dir)
|
||||||
--minetest.log("Node name: "..dump(node.name))
|
--minetest.log("Node name: "..dump(node.name))
|
||||||
local state = npc.actions.const.doors.state.CLOSED
|
local state = npc.actions.const.doors.state.CLOSED
|
||||||
-- Check for default doors and gates
|
-- Check for MTG doors and gates
|
||||||
local a_i1, a_i2 = string.find(node.name, "_a")
|
local mtg_door_closed = false
|
||||||
|
if minetest.get_item_group(node.name, "door") > 0 then
|
||||||
|
local back_pos = vector.add(pos, minetest.facedir_to_dir(node.param2))
|
||||||
|
local back_node = minetest.get_node(back_pos)
|
||||||
|
if back_node.name == "air" or minetest.registered_nodes[back_node.name].walkable == false then
|
||||||
|
mtg_door_closed = true
|
||||||
|
end
|
||||||
|
end
|
||||||
-- Check for cottages gates
|
-- Check for cottages gates
|
||||||
local open_i1, open_i2 = string.find(node.name, "_close")
|
local open_i1, open_i2 = string.find(node.name, "_close")
|
||||||
-- Check for cottages half door
|
-- Check for cottages half door
|
||||||
@ -615,7 +622,7 @@ function npc.actions.get_openable_node_state(node, npc_dir)
|
|||||||
if node.name == "cottages:half_door" then
|
if node.name == "cottages:half_door" then
|
||||||
half_door_is_closed = (node.param2 + 2) % 4 == npc_dir
|
half_door_is_closed = (node.param2 + 2) % 4 == npc_dir
|
||||||
end
|
end
|
||||||
if a_i1 == nil and open_i1 == nil and not half_door_is_closed then
|
if mtg_door_closed == false and open_i1 == nil and half_door_is_closed == false then
|
||||||
state = npc.actions.const.doors.state.OPEN
|
state = npc.actions.const.doors.state.OPEN
|
||||||
end
|
end
|
||||||
--minetest.log("Door state: "..dump(state))
|
--minetest.log("Door state: "..dump(state))
|
||||||
@ -630,7 +637,7 @@ function npc.actions.use_openable(self, args)
|
|||||||
local action = args.action
|
local action = args.action
|
||||||
local dir = args.dir
|
local dir = args.dir
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local state = npc.actions.get_openable_node_state(node, dir)
|
local state = npc.actions.get_openable_node_state(node, pos, dir)
|
||||||
|
|
||||||
local clicker = self.object
|
local clicker = self.object
|
||||||
if action ~= state then
|
if action ~= state then
|
||||||
@ -1048,7 +1055,8 @@ function npc.actions.walk_to_pos(self, args)
|
|||||||
-- Add stand animation at end
|
-- Add stand animation at end
|
||||||
if use_access_node == true then
|
if use_access_node == true then
|
||||||
dir = npc.actions.get_direction(end_pos, node_pos)
|
dir = npc.actions.get_direction(end_pos, node_pos)
|
||||||
end
|
end
|
||||||
|
minetest.log("Dir: "..dump(dir))
|
||||||
-- Change dir if using access_node
|
-- Change dir if using access_node
|
||||||
npc.add_action(self, npc.actions.cmd.STAND, {dir = dir})
|
npc.add_action(self, npc.actions.cmd.STAND, {dir = dir})
|
||||||
break
|
break
|
||||||
@ -1059,7 +1067,7 @@ function npc.actions.walk_to_pos(self, args)
|
|||||||
if path[i+1].type == npc.pathfinder.node_types.openable then
|
if path[i+1].type == npc.pathfinder.node_types.openable then
|
||||||
-- Check if door is already open
|
-- Check if door is already open
|
||||||
local node = minetest.get_node(path[i+1].pos)
|
local node = minetest.get_node(path[i+1].pos)
|
||||||
if npc.actions.get_openable_node_state(node, dir) == npc.actions.const.doors.state.CLOSED then
|
if npc.actions.get_openable_node_state(node, path[i+1].pos, dir) == npc.actions.const.doors.state.CLOSED then
|
||||||
--minetest.log("Opening action to open door")
|
--minetest.log("Opening action to open door")
|
||||||
-- Stop to open door, this avoids misplaced movements later on
|
-- Stop to open door, this avoids misplaced movements later on
|
||||||
npc.add_action(self, npc.actions.cmd.STAND, {dir=dir})
|
npc.add_action(self, npc.actions.cmd.STAND, {dir=dir})
|
||||||
|
@ -109,7 +109,7 @@ function npc.places.add_owned_accessible_place(self, nodes, place_type, walkable
|
|||||||
if nodes[i].owner == "" then
|
if nodes[i].owner == "" then
|
||||||
-- If node has no owner, check if it is accessible
|
-- If node has no owner, check if it is accessible
|
||||||
local empty_nodes = npc.places.find_orthogonal_accessible_node(
|
local empty_nodes = npc.places.find_orthogonal_accessible_node(
|
||||||
nodes[i].node_pos, nil, 0, true, walkables)
|
nodes[i].node_pos, nil, 0, true, walkables)
|
||||||
-- Check if node is accessible
|
-- Check if node is accessible
|
||||||
if #empty_nodes > 0 then
|
if #empty_nodes > 0 then
|
||||||
-- Set owner to this NPC
|
-- Set owner to this NPC
|
||||||
@ -237,10 +237,10 @@ function npc.places.find_orthogonal_accessible_node(pos, nodes, y_adjustment, in
|
|||||||
else
|
else
|
||||||
-- Search for air, walkable nodes, or any node availble in the extra_walkables array
|
-- Search for air, walkable nodes, or any node availble in the extra_walkables array
|
||||||
if node.name == "air"
|
if node.name == "air"
|
||||||
or (include_walkables == true
|
or (include_walkables == true
|
||||||
and minetest.registered_nodes[node.name].walkable
|
and minetest.registered_nodes[node.name].walkable == false
|
||||||
and minetest.registered_nodes[node.name].groups.fence ~= 1)
|
and minetest.registered_nodes[node.name].groups.fence ~= 1)
|
||||||
or (extra_walkables and npc.utils.array_contains(extra_walkables, node.name)) then
|
or (extra_walkables and npc.utils.array_contains(extra_walkables, node.name)) then
|
||||||
table.insert(result, {name=node.name, pos=point, param2=node.param2})
|
table.insert(result, {name=node.name, pos=point, param2=node.param2})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -635,39 +635,56 @@ end
|
|||||||
|
|
||||||
-- Specialized function to find the node position right behind
|
-- Specialized function to find the node position right behind
|
||||||
-- a door. Used to make NPCs enter buildings.
|
-- a door. Used to make NPCs enter buildings.
|
||||||
function npc.places.find_node_behind_door(door_pos)
|
function npc.places.find_node_in_front_and_behind_door(door_pos)
|
||||||
local door = minetest.get_node(door_pos)
|
local door = minetest.get_node(door_pos)
|
||||||
if door.param2 == 0 then
|
|
||||||
-- Looking south
|
local facedir_vector = minetest.facedir_to_dir(door.param2)
|
||||||
return {x=door_pos.x, y=door_pos.y, z=door_pos.z + 1}
|
local back_pos = vector.add(door_pos, facedir_vector)
|
||||||
elseif door.param2 == 1 then
|
local back_node = minetest.get_node(back_pos)
|
||||||
-- Looking east
|
local front_pos
|
||||||
return {x=door_pos.x + 1, y=door_pos.y, z=door_pos.z}
|
if back_node.name == "air" or minetest.registered_nodes[back_node.name].walkable == false then
|
||||||
elseif door.param2 == 2 then
|
-- Door is closed, so back_pos is the actual behind position.
|
||||||
-- Looking north
|
-- Calculate front node
|
||||||
return {x=door_pos.x, y=door_pos.y, z=door_pos.z - 1}
|
front_pos = vector.add(door_pos, vector.multiply(facedir_vector, -1))
|
||||||
-- Looking west
|
else
|
||||||
elseif door.param2 == 3 then
|
-- Door is open, need to find the front and back pos
|
||||||
return {x=door_pos.x - 1, y=door_pos.y, z=door_pos.z}
|
facedir_vector = minetest.facedir_to_dir((door.param2 + 2) % 4)
|
||||||
|
back_pos = vector.add(door_pos, facedir_vector)
|
||||||
|
front_pos = vector.add(door_pos, vector.multiply(facedir_vector, -1))
|
||||||
end
|
end
|
||||||
|
return back_pos, front_pos
|
||||||
|
|
||||||
|
-- if door.param2 == 0 then
|
||||||
|
-- -- Looking south
|
||||||
|
-- return {x=door_pos.x, y=door_pos.y, z=door_pos.z + 1}
|
||||||
|
-- elseif door.param2 == 1 then
|
||||||
|
-- -- Looking east
|
||||||
|
-- return {x=door_pos.x + 1, y=door_pos.y, z=door_pos.z}
|
||||||
|
-- elseif door.param2 == 2 then
|
||||||
|
-- -- Looking north
|
||||||
|
-- return {x=door_pos.x, y=door_pos.y, z=door_pos.z - 1}
|
||||||
|
-- -- Looking west
|
||||||
|
-- elseif door.param2 == 3 then
|
||||||
|
-- return {x=door_pos.x - 1, y=door_pos.y, z=door_pos.z}
|
||||||
|
-- end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Specialized function to find the node position right in
|
-- Specialized function to find the node position right in
|
||||||
-- front of a door. Used to make NPCs exit buildings.
|
-- front of a door. Used to make NPCs exit buildings.
|
||||||
function npc.places.find_node_in_front_of_door(door_pos)
|
--function npc.places.find_node_in_front_of_door(door_pos)
|
||||||
local door = minetest.get_node(door_pos)
|
-- local door = minetest.get_node(door_pos)
|
||||||
--minetest.log("Param2 of door: "..dump(door.param2))
|
-- --minetest.log("Param2 of door: "..dump(door.param2))
|
||||||
if door.param2 == 0 then
|
-- if door.param2 == 0 then
|
||||||
-- Looking south
|
-- -- Looking south
|
||||||
return {x=door_pos.x, y=door_pos.y, z=door_pos.z - 1}
|
-- return {x=door_pos.x, y=door_pos.y, z=door_pos.z - 1}
|
||||||
elseif door.param2 == 1 then
|
-- elseif door.param2 == 1 then
|
||||||
-- Looking east
|
-- -- Looking east
|
||||||
return {x=door_pos.x - 1, y=door_pos.y, z=door_pos.z}
|
-- return {x=door_pos.x - 1, y=door_pos.y, z=door_pos.z}
|
||||||
elseif door.param2 == 2 then
|
-- elseif door.param2 == 2 then
|
||||||
-- Looking north
|
-- -- Looking north
|
||||||
return {x=door_pos.x, y=door_pos.y, z=door_pos.z + 1}
|
-- return {x=door_pos.x, y=door_pos.y, z=door_pos.z + 1}
|
||||||
elseif door.param2 == 3 then
|
-- elseif door.param2 == 3 then
|
||||||
-- Looking west
|
-- -- Looking west
|
||||||
return {x=door_pos.x + 1, y=door_pos.y, z=door_pos.z}
|
-- return {x=door_pos.x + 1, y=door_pos.y, z=door_pos.z}
|
||||||
end
|
-- end
|
||||||
end
|
--end
|
||||||
|
@ -499,8 +499,9 @@ function npc.spawner.assign_places(self, entrance, node_data, pos)
|
|||||||
if entrance ~= nil and entrance.node_pos ~= nil then
|
if entrance ~= nil and entrance.node_pos ~= nil then
|
||||||
npc.places.add_shared(self, npc.places.PLACE_TYPE.OPENABLE.HOME_ENTRANCE_DOOR, npc.places.PLACE_TYPE.OPENABLE.HOME_ENTRANCE_DOOR, entrance.node_pos)
|
npc.places.add_shared(self, npc.places.PLACE_TYPE.OPENABLE.HOME_ENTRANCE_DOOR, npc.places.PLACE_TYPE.OPENABLE.HOME_ENTRANCE_DOOR, entrance.node_pos)
|
||||||
-- Find the position inside and outside the door
|
-- Find the position inside and outside the door
|
||||||
local entrance_inside = npc.places.find_node_behind_door(entrance.node_pos)
|
local entrance_inside, entrance_outside = npc.places.find_node_in_front_and_behind_door(entrance.node_pos)
|
||||||
local entrance_outside = npc.places.find_node_in_front_of_door(entrance.node_pos)
|
--local entrance_inside = npc.places.find_node_behind_door(entrance.node_pos)
|
||||||
|
--local entrance_outside = npc.places.find_node_in_front_of_door(entrance.node_pos)
|
||||||
-- Assign these places to NPC
|
-- Assign these places to NPC
|
||||||
npc.places.add_shared(self, npc.places.PLACE_TYPE.OTHER.HOME_INSIDE, npc.places.PLACE_TYPE.OTHER.HOME_INSIDE, entrance_inside)
|
npc.places.add_shared(self, npc.places.PLACE_TYPE.OTHER.HOME_INSIDE, npc.places.PLACE_TYPE.OTHER.HOME_INSIDE, entrance_inside)
|
||||||
npc.places.add_shared(self, npc.places.PLACE_TYPE.OTHER.HOME_OUTSIDE, npc.places.PLACE_TYPE.OTHER.HOME_OUTSIDE, entrance_outside)
|
npc.places.add_shared(self, npc.places.PLACE_TYPE.OTHER.HOME_OUTSIDE, npc.places.PLACE_TYPE.OTHER.HOME_OUTSIDE, entrance_outside)
|
||||||
|
Loading…
Reference in New Issue
Block a user