Adds pathfinding library Jumper by Ronald Yonaba. This includes an implementation of the A* pathfinding algorithm which makes NPC now always get to their goal node.

Pathfinding: Adds functions that allows to map the Minetest 3D map to a 2D array to use by the pathfinding algorithm.
Actions: Use new code for find_path function. Improves door opening while walking on paths, and also now close them. Cottages fence gates and doors are also now supported in addition to the default doors and gates.
Changes to the Readme and the License.
This commit is contained in:
zorman2000
2017-01-06 07:57:42 -05:00
parent 80b7eb6ec9
commit 554fde4643
13 changed files with 412615 additions and 313 deletions

25
npc.lua
View File

@ -183,7 +183,7 @@ end
-- Actions should be added in strict order for tasks to work as expected.
function npc.add_action(self, action, arguments)
self.freeze = true
minetest.log("Current Pos: "..dump(self.object:getpos()))
--minetest.log("Current Pos: "..dump(self.object:getpos()))
local action_entry = {action=action, args=arguments}
--minetest.log(dump(action_entry))
table.insert(self.actions.queue, action_entry)
@ -346,17 +346,22 @@ local function npc_spawn(self, pos)
ent.places_map = {}
-- Temporary initialization of actions for testing
local nodes = npc.places.find_new_nearby(ent, {"beds:bed_bottom"}, 20)
local nodes = npc.places.find_new_nearby(ent, {"cottages:tub"}, 30)
minetest.log("Found nodes: "..dump(nodes))
--local path = pathfinder.find_path(ent.object:getpos(), nodes[1], 20)
--minetest.log("Path to node: "..dump(path))
--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.add_action(ent, npc.actions.stand, {self = ent})
npc.actions.walk_to_pos(ent, nodes[1])
npc.actions.use_bed(ent, nodes[1], npc.actions.bed_action.LAY)
npc.add_action(ent, npc.actions.lay, {self = ent})
npc.add_action(ent, npc.actions.lay, {self = ent})
npc.add_action(ent, npc.actions.lay, {self = ent})
npc.add_action(ent, npc.actions.lay, {self = ent})
npc.actions.use_bed(ent, nodes[1], npc.actions.bed_action.GET_UP)
--npc.actions.use_bed(ent, nodes[1], npc.actions.const.beds.LAY)
--npc.add_action(ent, npc.actions.lay, {self = ent})
-- npc.add_action(ent, npc.actions.lay, {self = ent})
-- npc.add_action(ent, npc.actions.lay, {self = ent})
-- npc.add_action(ent, npc.actions.lay, {self = ent})
--npc.actions.use_bed(ent, nodes[1], npc.actions.const.beds.GET_UP)
-- npc.add_action(ent, npc.action.stand, {self = ent})
-- npc.add_action(ent, npc.action.stand, {self = ent})
@ -546,7 +551,7 @@ mobs:register_mob("advanced_npc:npc", {
-- Spawn
mobs:spawn({
name = "advanced_npc:npc",
nodes = {"default:stone"},
nodes = {"mg_villages:plotmarker", "default:stone"},
min_light = 3,
active_object_count = 1,
interval = 5,