Allow ability to search for nodes on a height limit on node_query

master^2
Hector Franqui 2018-06-28 18:58:54 -04:00
parent a7ac7d5a60
commit 2994018e99
2 changed files with 6 additions and 5 deletions

View File

@ -323,10 +323,10 @@ end
-- This function searches on a squared are of the given radius
-- for nodes of the given type. The type should be npc.locations.nodes
function npc.locations.find_node_nearby(pos, type, radius, fixed_vertical)
local y_offset = 1
if not fixed_vertical then
y_offset = radius
function npc.locations.find_node_nearby(pos, type, radius, vertical_range_limit)
local y_offset = radius
if vertical_range_limit then
y_offset = vertical_range_limit
end
-- Determine area points
local start_pos = {x=pos.x - radius, y=pos.y - y_offset, z=pos.z - radius}

View File

@ -13,6 +13,7 @@ npc.programs.register("advanced_npc:node_query", function(self, args)
local min_count = args.min_count
local state_program_on_finished = args.state_program_on_finished
local range = args.range
local vertical_range_limit = args.vertical_range_limit or args.range
local walkable_nodes = args.walkable_nodes
local nodes = args.nodes
local prefer_last_acted_upon_node = args.prefer_last_acted_upon_node
@ -30,7 +31,7 @@ npc.programs.register("advanced_npc:node_query", function(self, args)
-- Get NPC position
local start_pos = self.object:getpos()
-- Search nodes
local found_nodes = npc.locations.find_node_nearby(start_pos, nodes, range)
local found_nodes = npc.locations.find_node_nearby(start_pos, nodes, range, vertical_range_limit)
-- Check if any node was found
npc.log("DEBUG_SCHEDULE", "Found nodes using radius: "..dump(found_nodes))
if found_nodes and #found_nodes > 0 then