Spawner: Assign entrance door to every NPC spawned.
Increased ABM chance to make NPC spawning less laggy. Improved building scanning, finally now has correct data for scanning nodes. Places: Finding entrances is limited now to MTG doors.
This commit is contained in:
@ -113,7 +113,7 @@ function npc.actions.execute(self, command, args)
|
||||
return npc.actions.use_sittable(self, args)
|
||||
elseif command == npc.actions.cmd.WALK_TO_POS then
|
||||
-- Call walk to position task
|
||||
minetest.log("Self: "..dump(self)..", Command: "..dump(command)..", args: "..dump(args))
|
||||
--minetest.log("Self: "..dump(self)..", Command: "..dump(command)..", args: "..dump(args))
|
||||
return npc.actions.walk_to_pos(self, args)
|
||||
end
|
||||
end
|
||||
@ -603,9 +603,9 @@ function npc.actions.use_sittable(self, args)
|
||||
local pos_out_of_sittable = pos
|
||||
local empty_nodes = npc.places.find_node_orthogonally(pos, {"air"}, 0)
|
||||
if empty_nodes ~= nil and #empty_nodes > 0 then
|
||||
minetest.log("Empty nodes: "..dump(empty_nodes))
|
||||
minetest.log("Npc.actions.get_direction: "..dump(npc.actions.get_direction))
|
||||
minetest.log("Pos: "..dump(pos))
|
||||
--minetest.log("Empty nodes: "..dump(empty_nodes))
|
||||
--minetest.log("Npc.actions.get_direction: "..dump(npc.actions.get_direction))
|
||||
--minetest.log("Pos: "..dump(pos))
|
||||
-- Get direction to the empty node
|
||||
dir = npc.actions.get_direction(pos, empty_nodes[1].pos)
|
||||
-- Calculate position to get out of sittable node
|
||||
|
@ -73,6 +73,7 @@ local function is_good_node(node, exceptions)
|
||||
-- Is openable is to support doors, fence gates and other
|
||||
-- doors from other mods. Currently, default doors, gates
|
||||
-- and cottages doors are supported.
|
||||
--minetest.log("Is good node: "..dump(node))
|
||||
local is_openable = false
|
||||
for _,node_prefix in pairs(pathfinder.nodes.openable_prefix) do
|
||||
local start_i,end_i = string.find(node.name, node_prefix)
|
||||
@ -140,9 +141,14 @@ function pathfinder.create_map(start_pos, end_pos, extra_range, walkables)
|
||||
else
|
||||
-- Check if node is walkable
|
||||
local node = minetest.get_node(current_pos)
|
||||
-- Check node has air above it
|
||||
local node_above = minetest.get_node({x=current_pos.x, y=current_pos.y+1, z=current_pos.z})
|
||||
if node.name == "air" then
|
||||
-- If air do no more checks
|
||||
table.insert(current_row, {pos=current_pos, type=pathfinder.node_types.walkable})
|
||||
-- Check if node above is air
|
||||
if node.name == "air" then
|
||||
-- If air do no more checks
|
||||
table.insert(current_row, {pos=current_pos, type=pathfinder.node_types.walkable})
|
||||
end
|
||||
else
|
||||
-- Check if it is of a walkable or openable type
|
||||
table.insert(current_row, {pos=current_pos, type=is_good_node(node, walkables)})
|
||||
|
@ -142,10 +142,24 @@ end
|
||||
-- The openable node with the shortest path to the plotmarker node
|
||||
-- Based on this definition, other entrances aren't going to be used
|
||||
-- by the NPC to get into the building
|
||||
function npc.places.find_entrance_from_openable_nodes(openable_nodes, marker_pos)
|
||||
function npc.places.find_entrance_from_openable_nodes(all_openable_nodes, marker_pos)
|
||||
local result = nil
|
||||
local openable_nodes = {}
|
||||
local min = 100
|
||||
|
||||
-- Filter out all other openable nodes except MTG doors.
|
||||
-- Why? For supported village types (which are: medieval, nore
|
||||
-- and logcabin) all buildings use, as the main entrance,
|
||||
-- a MTG door. Some medieval building have "half_doors" (like farms)
|
||||
-- which NPCs love to confuse with the right building entrance.
|
||||
for i = 1, #all_openable_nodes do
|
||||
local name = minetest.get_node(all_openable_nodes[i].node_pos).name
|
||||
local doors_st, doors_en = string.find(name, "doors:")
|
||||
if doors_st ~= nil then
|
||||
table.insert(openable_nodes, all_openable_nodes[i])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for i = 1, #openable_nodes do
|
||||
|
||||
@ -314,13 +328,13 @@ function npc.places.find_node_behind_door(door_pos)
|
||||
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}
|
||||
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}
|
||||
return {x=door_pos.x - 1, y=door_pos.y, z=door_pos.z}
|
||||
end
|
||||
end
|
||||
|
||||
@ -328,17 +342,18 @@ end
|
||||
-- front of a door. Used to make NPCs exit buildings.
|
||||
function npc.places.find_node_in_front_of_door(door_pos)
|
||||
local door = minetest.get_node(door_pos)
|
||||
minetest.log("Param2 of door: "..dump(door.param2))
|
||||
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}
|
||||
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}
|
||||
return {x=door_pos.x + 1, y=door_pos.y, z=door_pos.z}
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user