As alluded to in my last post I've added some additional functionality. There is a possibility it'll break code but hopefully that won't be the case.
The Dijkstra proc has been modified so that it can get many paths in one search with no extra cost as it doesn't have to repeat any work. In your finished proc simply return P_DIJKSTRA_ADD_PATH and it'll add the path to that location to the return list and continue searching for more paths. However be aware that the return value of finished is no longer a bool. 0 still indicates not a finish point and 1 indicates a finish point and to stop searching so I'm hoping this won't break any code as those are the common values for true and false people use. Though even if you use them and they work I'd still advise switching to the consts P_DIJKSTRA_NOT_FOUND and P_DIJKSTRA_FINISHED in case I need to change the values in future versions so your code won't break. Also an extra parameter called compatibility has been added and is by default on. This is to help ensure less code gets broken from this update. If only one path is generated and compatibility mode is on the function will simply return the path rather than return it as a list of paths containing one path. If you're expecting the new functionality it'll probably be easier to turn the compatibility mode off so the return value is always consistent.
This should be quite handy as previously to do the same thing would require several searches resulting in a massive amounts of testing the same tiles over and over with the same conditions. Before if you wanted a monster to say chase a player you could have used the proc to find the closest one however for AI reasons that might not have been the best choice. Now you can generate paths quickly(as quick as a single path to the farthest player if done right) to all the players and then have the AI compare the paths or test them to maybe find the nearest clump of players to go at. The same could be done for any other number of scenarios in which you want several destinations and use path lengths/weights to decide on an optimal target which may not be the nearest. This could also be used for detect skills in MUDs. Just set the maxnodedepth to the range of the skill and don't stop adding paths until you've got paths to all the things you are sensing and return a list of the stuff the player sensed all in one quick search! Or maybe you have an RTS game and want to pregenerate paths to all the nearby resource nodes from a given drop off point. Piece of cake and quite fast to do now!
Well hopefully this update helps a bit for path finding. And given how powerful and efficient this library is no AI should ever be lost unless it is intended to be!
ID:30692
May 18 2007, 8:12 am
|
|
That is pure genius. Great job.