How does pathfinding work in Scumm?

Ask for help with ScummVM problems

Moderator: ScummVM Team

Post Reply
aliebert
Posts: 2
Joined: Sat Sep 22, 2007 3:28 am
Location: san francisco
Contact:

How does pathfinding work in Scumm?

Post by aliebert »

Greetings gang,

I thought some of the programming Wizards who put together ScummVM could answer a question for me.

What kind of pathfinding do the old Scumm game use? It works quite well for what it is...yet I'm thinking perhaps it's not A*? All the articles on the topic nowadays talk about A* or something that's more processor intensive than that, but I'm hoping/guessing that Scumm used some cleverer, cheaper trick to get it working.

Any general explanation of the method would be great.

Thanks!!
seubz
Posts: 41
Joined: Sat Aug 11, 2007 1:24 am

Post by seubz »

The only thng I know is that the resource files store all paths. For example, when a character is on Box 1 and he wants to go on Box2, SCUMM will automatically find in which box to go next by looking into an already computed matrix in the resource files (BOXM block). I don't know how this matrices were computed, but most likely with A*. Once the next box in the path is found, I have no idea what happens, I guess the path has to be filtered some way so that the characters don't always go in the center of the boxes or something... ScummVM guys might be able to ask this question though.
aliebert
Posts: 2
Joined: Sat Sep 22, 2007 3:28 am
Location: san francisco
Contact:

Post by aliebert »

Thanks for the info! So that path info is precalculated, not calculated at run time...

Yes, I am still curious what happens to get to a specific point within a node once the path to that node is determined.
spacetroll
Posts: 53
Joined: Tue Jul 10, 2007 6:15 pm

Post by spacetroll »

You might find it more illuminating to research this on some of the adventure-game-maker sites, like AGAST or AGS. Both those programs use simple and efficient path-finding techniques that I'm sure are similar to the SCUMM games.
User avatar
john_doe
ScummVM Developer
Posts: 117
Joined: Fri Nov 04, 2005 8:25 pm
Location: Stuttgart, Germany

Post by john_doe »

You might find this article interesting:
http://graphics.cs.ucdavis.edu/~okreylo ... nding.html
I'm not that familiar with SCUMM's internals but I guess conceptually this is a similar approach, except here they use polygons while in SCUMM the polygons are restricted to be rectangles.
fingolfin
Retired
Posts: 1452
Joined: Wed Sep 21, 2005 4:12 pm

Post by fingolfin »

ScummVM doesn't using anything complicated like A* at all!

Rather, the game screen is divided into so-called "boxes" (which in the later SCUMM versions could essentially be almost arbitrary non-overlapping quadrangles).

Normally, an "actor" (like e.g. Guybrush in Monkey Island) is confined to movement within those boxes. So at any time, an actor has a "current box" attribute assigned to it. Let's assume the actor is in box 1.

When the user clicks somewhere, the engine first determines which box the click was in. If it's the same as the actor to be moved is in anyway, it can just be walked there. That's easy. Now assume the click was in a different box, e.g. box 5. THen the engine first determines how to get to that box. For this, it looks in the "box matrix", which is essentially a precomputed n*n matrix, where n is the total number of boxes in the room. For each pair (i,j) of boxes, it contains a value k which says: "If you are in box i and want to get to get to box j, first go to box k". Note that "k" could equal j if box i and j are adjacent.
Now, equipped with this value, the engine will first compute a path for the actor to walk from its current position to the new box k. This depends on how the boxes i and k "touch".
Anyway, so the actor walks a bit and reaches box k. If this was the same as the box of our final destination, then we just walk to the final destination, and are done. If not, we rince and repeat: Look up the entry (k,j) in the box matrix to find the next box; walk to that; etc.

This probably sounds more complicated than it is, really :-).

There is also code in ScummVM to compute the box matrix (not all game versions carried the box matrix in the resources, for some it had to be computed on the fly). This, too, is a very simple task, (see createBoxMatrix() in boxes.cpp), and we implement it using Kleene's algorithm (start with an incidence matrix, and iteratively compute the box matrix from that; the source code is documented, take a look there, and/or look it up on Wikipedia).
Post Reply