From 55c6146e943daa88e19c1bb680214b1ca1a092c1 Mon Sep 17 00:00:00 2001 From: Zorman2000 Date: Mon, 10 Apr 2017 22:42:21 -0400 Subject: [PATCH] Spawning: Find entrance doors to building. --- actions/pathfinder.lua | 2 +- actions/places.lua | 36 ++++++++++++++++++++++++++++++------ spawner.lua | 5 +++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/actions/pathfinder.lua b/actions/pathfinder.lua index 38aed11..9e47325 100644 --- a/actions/pathfinder.lua +++ b/actions/pathfinder.lua @@ -181,7 +181,7 @@ end -- for the pathfinding algorithm to use function pathfinder.find_start_and_end_pos(map) -- This is for debug - print_map(map) + --print_map(map) local result = {} for z,row in pairs(map) do for x,node in pairs(row) do diff --git a/actions/places.lua b/actions/places.lua index e61ec1f..a52467d 100644 --- a/actions/places.lua +++ b/actions/places.lua @@ -140,24 +140,30 @@ function npc.places.find_entrance_from_openable_nodes(openable_nodes, marker_pos local result = nil local min = 100 + for i = 1, #openable_nodes do + local open_pos = openable_nodes[i].node_pos + -- Get node name - check if this node is a 'door'. The way to check -- is by explicitly checking for 'door' string local name = minetest.get_node(open_pos).name local start_i, end_i = string.find(name, "door") + if start_i ~= nil then -- Define start and end pos - local start_pos, end_pos = open_pos, marker_pos - -- Check if there's any difference in vertical position - minetest.log("Openable node pos: "..minetest.pos_to_string(open_pos)) - minetest.log("Plotmarker node pos: "..minetest.pos_to_string(marker_pos)) + local start_pos = {x=open_pos.x, y=open_pos.y, z=open_pos.z} + local end_pos = {x=marker_pos.x, y=marker_pos.y, z=marker_pos.z} - if open_pos.y ~= marker_pos.y then + -- Check if there's any difference in vertical position + -- minetest.log("Openable node pos: "..minetest.pos_to_string(open_pos)) + -- minetest.log("Plotmarker node pos: "..minetest.pos_to_string(marker_pos)) + if start_pos.y ~= end_pos.y then -- Adjust to make pathfinder find nodes one node above - start_pos.y = marker_pos.y + end_pos.y = start_pos.y end + -- This adjustment allows the map to be created correctly start_pos.y = start_pos.y + 1 end_pos.y = end_pos.y + 1 @@ -170,7 +176,25 @@ function npc.places.find_entrance_from_openable_nodes(openable_nodes, marker_pos -- Set min to path length and the result to the currently found node min = #path result = openable_nodes[i] + else + -- Specific check to prefer mtg's doors to cottages' doors. + -- The reason? Sometimes a cottages' door could be closer to the + -- plotmarker, but not being the building entrance. MTG doors + -- are usually the entrance... so yes, hackity hack. + -- Get the name of the currently mininum-distance door + min_node_name = minetest.get_node(result.node_pos).name + -- Check if this is a door from MTG's doors. + local doors_st, doors_en = string.find(name, "doors:") + -- Check if min-distance door is a cottages door + -- while we have a MTG door + if min_node_name == "cottages:half_door" and doors_st ~= nil then + minetest.log("Assigned new door...") + min = #path + result = openable_nodes[i] + end end + else + minetest.log("Path not found to marker from "..minetest.pos_to_string(start_pos)) end end end diff --git a/spawner.lua b/spawner.lua index aed970d..0010e9a 100644 --- a/spawner.lua +++ b/spawner.lua @@ -67,6 +67,11 @@ npc.spawner.spawn_data = { -- Scanning functions --------------------------------------------------------------------------------------- +function spawner.filter_first_floor_nodes(nodes) + local result = {} + +end + -- Creates an array of {pos=, owner=''} for managing -- which NPC owns what function spawner.get_nodes_by_type(start_pos, end_pos, type)