mob
var/steps = 3
proc
tile_find()
ID:157352
Mar 27 2010, 6:29 pm
|
|
How would I go about making a procedure which would find tiles around a mob which the mob is capable of traveling to, and no diagonal movement with a limited number of steps the mob can take?
|
Mar 27 2010, 6:33 pm
|
|
Describe better. This might need a pathfinding algorithm, like Dijkstra's.
|
In response to Popisfizzy
|
|
Would it help if I mentioned games like Final Fantasy Tactics and Advanced Wars?
|
I think what Speedro means is a system where the player clicks on a tile (or highlights the tile) and the mob moves to it, like a chessboard.
As far as my contribution, I'll tell you its possible, you'll probably use Move(), and from my understanding its been done several times so a look into some demos wouldn't hurt. |
As Popisfizzy said, generally you would use a good pathfinding algorithm for problems like this. If, however, all you want to know is "Is it possible for object A to get to location B using only N steps?" for all locations B within N steps and N is guaranteed to be small, and you don't care about the best path, then you can make a very simple algorithm to check this.
If you want to check for object A, but the turf at object A's coordinates into a list L. Now start the following loop: for index = 1 to numberOfSteps for all locations B in list L for all locations C in list(get_step(B, NORTH), get_step(B, SOUTH), etc.) if it is possible to move from B to C and C is not in L or in L2 add C to list L2 (yes, a different, temporary list, so it doesn't modify L until we're done looping through C in L) add all elements from L2 to L, then empty L2 You're starting at the initial location, then adding in any tiles you could step to from there, then you're also adding in any tiles you could step to from those tiles, then any tiles you could step to from those tiles, and you're doing this a number of times equal to numberOfSteps. With minor modifications, this could also take into account warp portals, stairs, and other relocation effects and the continued motion on the other side of them as well. Please NOTE: For the specific pseudocode I gave, that is a terribly, horrendously UNoptomized way to do it, so it will take more time to compute than necessary. It should not be too difficult, though, to optimize it in several ways. I leave that as an exercise to you; however, if your numberOfSteps is small enough, it should be good enough even if left unoptimized. If the number of steps is 3, for example, it's still going to take only a fraction of a millisecond to figure out even if not optimized. |
In response to Loduwijk
|
|
How would I make it flexible with more list entries than just 3 though, because some things might be able to move as far as 6 or 8? Or do I have to continually rewrite it?
mob mob Yeah, I clearly have no idea what I'm doing: mob None of that even makes sense. |
In response to Loduwijk
|
|
You could, alternatively, use a recursive algorithm.
turf This assumes that /turf.Enter() doesn't do any checking as to whether the mob is adjecent to the turf or any directional checking, mind. If you need that, you may have to fiddle with the proc a bit. This also only finds the turfs the mob can step to. It doesn't actually find the path for them to get somewhere. The good thing about this, though, is that it will make pathfinding quicker. Since you know that they are allowed to step anywhere in the list that this proc returns, their path should only include turfs in this list, so you can ignore anything outside it. |
In response to Popisfizzy
|
|
You could easily get a path from that with one simple modification. Change the line:
current += a to: current[a] = source Then, you can find the path to a destination by following the association backwards, like so: var/list/L = src.GetSteppable(4) Actually, that'll break because your algorithm doesn't include the source turf. So you'd need to change one other line: current = new |
In response to Garthor
|
|
You could, but I think there's the possibility that may provide a peculiar path rather than the shortest or most visually correct one.
|
In response to Popisfizzy
|
|
Seems to make sense...
mob |