Pathfinding: Fix for mod security - joining up Jumper library code (WIP)
This commit is contained in:
83
npc.lua
83
npc.lua
@ -269,9 +269,11 @@ function npc.initialize(entity, pos, is_lua_entity)
|
||||
|
||||
-- Temporary initialization of actions for testing
|
||||
local nodes = npc.places.find_node_nearby(ent.object:getpos(), {"cottages:bench"}, 20)
|
||||
--minetest.log("Found nodes: "..dump(nodes))
|
||||
|
||||
--local path = pathfinder.find_path(ent.object:getpos(), nodes[1], 20)
|
||||
|
||||
minetest.log("Self destination: "..minetest.pos_to_string(nodes[1]))
|
||||
|
||||
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})
|
||||
@ -861,6 +863,8 @@ mobs:register_mob("advanced_npc:npc", {
|
||||
minetest.log("[advanced_npc] WARNING: Initializing NPC from entity step. This message should only be appearing if an NPC is being spawned from inventory with egg!")
|
||||
npc.initialize(self, self.object:getpos(), true)
|
||||
else
|
||||
self.tamed = false
|
||||
self.owner = nil
|
||||
-- NPC is initialized, check other variables
|
||||
-- Timer function for casual traders to reset their trade offers
|
||||
self.trader_data.change_offers_timer = self.trader_data.change_offers_timer + dtime
|
||||
@ -971,6 +975,81 @@ mobs:register_mob("advanced_npc:npc", {
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- if self.follow_path then
|
||||
-- self.home_timer = (self.home_timer or 0) + dtime
|
||||
-- if self.home_timer < 1 then return end -- every 1 second
|
||||
-- self.home_timer = 0
|
||||
|
||||
-- -- if self.time_of_day > 0.2 and self.time_of_day < 0.8 then
|
||||
-- -- return -- return if not night time
|
||||
-- -- end
|
||||
|
||||
-- local h = self.destination
|
||||
-- --local h = {x = 1, y = 8, z = 2} -- destination coords
|
||||
-- local p = self.object:getpos() -- mob position
|
||||
|
||||
-- -- lets try find a path, first take care of positions
|
||||
-- -- since pathfinder is very sensitive
|
||||
-- local pheight = self.collisionbox[5] - self.collisionbox[2]
|
||||
|
||||
-- -- round position to center of node to avoid stuck in walls
|
||||
-- -- also adjust height for player models!
|
||||
-- p.x = math.floor(p.x + 0.5)
|
||||
-- p.y = math.floor(p.y + 0.5) - pheight
|
||||
-- p.z = math.floor(p.z + 0.5)
|
||||
|
||||
-- local ssight, sground = minetest.line_of_sight(p, {
|
||||
-- x = p.x, y = p.y - 4, z = p.z}, 1)
|
||||
|
||||
-- -- determine node above ground
|
||||
-- if not ssight then
|
||||
-- p.y = sground.y + 1
|
||||
-- end
|
||||
|
||||
-- h.x = math.floor(h.x + 0.5)
|
||||
-- h.y = math.floor(h.y + 0.5)
|
||||
-- h.z = math.floor(h.z + 0.5)
|
||||
|
||||
|
||||
-- local x, y, z = p.x - h.x, p.y - h.y, p.z - h.z
|
||||
-- local dist = math.floor(math.sqrt(x * x + y * y + z * z))
|
||||
|
||||
-- minetest.log("Self pos : "..minetest.pos_to_string(p))
|
||||
-- minetest.log("Self dest: "..minetest.pos_to_string(h))
|
||||
|
||||
-- if dist <= 1 then
|
||||
-- print ("--- home!")
|
||||
-- self.homepath = nil
|
||||
-- self.state = "stand"
|
||||
-- return
|
||||
-- end
|
||||
|
||||
-- if self.homepath == nil then
|
||||
-- self.homepath = minetest.find_path(p, h, 50, 3, 6, "A*")
|
||||
-- print ("--- finding route", self.homepath, dist)
|
||||
-- end
|
||||
|
||||
-- if self.homepath then
|
||||
-- print ("--- following path", dist, #self.homepath)
|
||||
|
||||
-- local np = self.homepath[1] ; if not np then return end
|
||||
|
||||
-- if math.abs(np.x - p.x) + math.abs(np.z - p.z) < 0.6 then
|
||||
-- table.remove(self.homepath, 1) ; print ("-- removed entry")
|
||||
-- end
|
||||
|
||||
-- np = {x = np.x, y = np.y, z = np.z}
|
||||
|
||||
-- local vec = {x = np.x - p.x, z = np.z - p.z}
|
||||
-- local yaw = (math.atan(vec.z / vec.x) + math.pi / 2) - self.rotate
|
||||
|
||||
-- if np.x > p.x then yaw = yaw + math.pi end
|
||||
|
||||
-- self.object:setyaw(yaw)
|
||||
-- set_velocity(self, self.walk_velocity)
|
||||
-- end
|
||||
-- end
|
||||
|
||||
return self.freeze
|
||||
end
|
||||
|
Reference in New Issue
Block a user