ID:152299
 
While you're hangin' about (which is a good thing):

How would you go about accounting for AI moving around mobs in your pathfinding library? IOW, I made a hack into the lib in order to allow other mobs to be avoided in a mob's path[] (I'm only using 1 mob per tile, ATM). The way I did it was:
//change the call parameters for AStar
AStar(mob/mover,start,end,adjacent,dist,maxnodes,maxnodedepth,mintargetdist,minnodedist)
//and inside this proc, called the adjacent proc like so:
var/L[] = call(cur.source,adjacent)(mover)

//where it would show back up in the user-defined proc
proc/AdjacentTurfs(var/mob/TBSS_mob/mover)


Is there a better way to do this that you can see?
Is there a better way to do this that you can see?

It's probably best not to mess with the library itself as you'll have to make the change every time I update :P. Best to just store any information that the adjacentnodes and dist procs need in a global. At least until I get around to doing a version wrapped in a datum.

Anyway the best way to avoid a mob is to increase the distance for tile transitions that move you close to the mob. To do this you can just loop through all mobs in range in the dist proc and scale the distance according to how close the tile is. Unfortunately this can be very slow as the distance proc is called a whole lot so you don't want to do this for long paths. Another method is to make a threat map(a grid with modifications to the tile weights or just store the threat value of a tile directly on the tile) and just adjust it each time a mob that affects the threat value of tiles moves. Plus you can also use this for anything else that is a threat and you want to make the pathfinder try and avoid tiles. Then in the dist proc add in the threat map value to the distance for the tile.

Another thing to consider is that if you are traversing a long area and have to deal with dynamic obsticals is that they change and the longer the path the more likely stuff has changed at the end of the path before you got there. When making long paths have a much simpler version of the dist proc and adjacent nodes one which ignores dynamic obsticals completely. Then when following the path generate new smaller paths to follow for subsections of the path say every 10 or so tiles using much more detailed adjacent nodes and dist procs and set a maxnodedepth so it doesn't wander far to generate the small path to guide it along the larger one. You can also use the new mintargetdist parameter to keep it from trying to hit exact points along the larger path rather just stick close to it in case one of the original tiles in the path is blocked.
In response to Theodis
Theodis wrote:
Is there a better way to do this that you can see?

It's probably best not to mess with the library itself as you'll have to make the change every time I update :P.

Yeah, that's how this post came to mind in the first place. It's not a huge bother as its not too much code at all.

Best to just store any information that the adjacentnodes and dist procs need in a global. At least until I get around to doing a version wrapped in a datum.

Well, I'm attempting to encapsulate this as much as possible so, I dunno, I might be able to move it into my AI datum.

...Then in the dist proc add in the threat map value to the distance for the tile.

Agreed on that. I haven't gotten to the point of getting my AI that smart yet (to avoid encounters with hostiles). Most move toward the nearest enemy mob and engage. Not the best strategy :P, but it serves for this point in the progress of things.
At the point where I can start working on the fun stuff (AI, etc.) I'll look into adding weights based on attack/defense values relative to the mob creating the path. Although, keeping threat maps in mind now (and how to incorporate them) will undoubtedly save me some headaches later adding it in.

...Then when following the path generate new smaller paths to follow for subsections of the path say every 10 or so tiles using much more detailed adjacent nodes and dist procs and set a maxnodedepth so it doesn't wander far to generate the small path to guide it along the larger one. ...

I hadn't really though of two layers of paths. It's a good idea. It's turn based, so it's not a huge issue if it causes a speed drain, but efficiency is never a bad thing. I also considered breaking a long path into 'waypoints' and creating mob paths from one to the next.

Thanks for the ideas!