ID:2828873
 
Here's a little snippet of a pathfinding system I created.

This would allow you to easily integrate emergent behavior as you could effectively alter the actions/paths/behavior and such of NPCs mid-travel.

Someone might find it useful :D

/* EXAMPLE USAGE AREA */

world/New()
Global_Pathfinding_Proc()

turf/Click()
SetPath(usr,src) // This will cause you to pathfind to where you clicked.

/* END OF EXAMPLE USAGE AREA */

var list/pathfinding_objects = new

proc/Global_Pathfinding_Proc()
set background = TRUE
var object,l,tick = 2
for()
sleep(tick)
for(object in pathfinding_objects)
l = pathfinding_objects[object]
if(step(object,l[2][l[1]]) && ++l[1] > l[2].len)
pathfinding_objects -= object

proc/SetPath(object,location)
pathfinding_objects[object] = list(1,get_steps_to(object,location))