Stepping into chompers

Discuss PoP1 for DOS here.
Post Reply
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Stepping into chompers

Post by David »

From viewtopic.php?p=15821#p15821 :
xhul wrote: From what i've understood of chompers, the careful step has a chance to fail if you execute it at the wrong time.
Really? I thought that it is related to the distance.
Maybe it's both?

I made a test level that looks like this: (see screenshot)
There is a floor and a chomper next to each other. The kid starts on the right side of the chomper's floor, turned right.
If I turn left and immediately step left, then the chomper *might* kill the kid.
Update:
It happens only if I press shift-left when the kid is showing the frame that you can see the screenshot below.
(Frame 0x32, res450, that is turning\frame06.bmp; see here for a table of frames and sequences.)
The state of the chomper does *not* matter.
The distance from the chomper does *not* matter either.
The kid will always step right *into* the chomper, event if he would step over it otherwise.
step_now.png
step_now.png (2.9 KiB) Viewed 3441 times
This is only part of the answer, because I remember this can happen without turning.
And of course I have to figure out why does this happen only when I step at *this* frame, and not otherwise.
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: Stepping into chompers

Post by xhul »

Interesting.
So that would basically mean that the algorithm doesn't interpret the key combination properly when is it pressed at that specific frame.
In other words, the careful step can still be seen, but a different code is executed.
Looks to me like a synchronization issue (position of the prince).
Anyway, very good to know.
Let's wait a little bit before "careful-stepping" XD
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Stepping into chompers

Post by Norbert »

Actually, at the location where the prince died in my screenshot, I think it has to do with entering another room.
It's quite easy to replicate. Here's a sample video:

xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: Stepping into chompers

Post by xhul »

Yeah, i also thought that changing rooms can matter (maybe a separate bug, maybe not).
I'm just curious : if you try the exact same thing, but you wait a little before pressing the keys, does he get killed ?
I mean, being sure the run animation is completely over (kid not moving) before doing [shift]+[right].
Let us know =]
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Stepping into chompers

Post by David »

I figured out these things:
* The last frame of stop-run that I see on Norbert's video before the step (frame 0x33) is the frame after the frame you can see on my screenshot (frame 0x32).
(Yes, some frames of turning were reused in the stop-run animation.)
* If I single-step with esc until I get frame 0x32 (as on my screenshot) and then press shift-right, then the kid will show frame 0x33 for a moment, and only *then* will he step forward.
(I made a video of that because otherwise it's hard to see.)
* That is, what I described earlier seems to be the same that happens in Norbert's video.

This works without the room-changing, i.e. if the chomper is in the middle of the room.

An other interesting thing:
* Single-step until frame 0x33. (One frame after what you see on my screenshot.)
* Press shift-right.
* Now press shift-right again. The kid won't step through the chomper, but do a very small step instead.
* Now press shift-right once again. The kid will now step through the chomper.

I could reproduce the above things in SDLPoP, so its source might give further help.
* The safe step is started in safe_step() (seg005.c).
* The size of the step is determined by get_edge_distance() (seg004.c).
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Stepping into chompers

Post by David »

Today I debugged SDLPoP while doing steps from various frames.
(I tested it with the left wall in the first room of level 1. Instead of a "chomp" you get a "bump".)
Here are my findings:
(Apologies if it's hard to understand, but I can't explain it simpler!)

* The size of the step is ultimately decided in dist_from_wall_forward() (seg004.c).
It calculates the difference between x-coordinates of the edge of the kid's hitbox (char_x_left/right_coll) and the obstacle's edge.
From now on, assume the kid is turned left, so we look only at char_x_left_coll.

Now, the position of the kid's hitbox depends on two things: (See set_char_collision() in seg006.c)
* (1) By default, it is located at the edge of the kid's image.
* The "front" edge of the kid's image is in front of the actual xpos, the distance is the "DX" value of the current frame.
(That is, char_x_left_coll = Char.xpos - cur_frame.dx; In reality this is achieved in a bit more complicated way.)
(The sequence and frame tables can be found here: viewtopic.php?p=15726#p15726
You should look at them if you want to follow me. Turning is sequence 5, end-run is sequence 13.)
* (2) Some frames may specify "thin". This moves the left and right edges of the hitbox by 4 units towards the other side.
(That is, char_x_left_coll += 4;)

The safe step works correctly if the kid starts from standing (frame 0x0F).
The attributes of frame 0x0F are: DX=0, THIN=0. Therefore, char_x_left_coll = Char.xpos;
Now look at the frames of turning:
frame 0x32 DX=4 THIN=1 -> char_x_left_coll = Char.xpos - 4 + 4 = Char.xpos; No problem here.
frame 0x33 DX=3 THIN=1 -> char_x_left_coll = Char.xpos - 3 + 4 = Char.xpos + 1; It's *as if* the kid was one unit further right, so he will step one unit bigger.
frame 0x34 DX=1 THIN=0 -> char_x_left_coll = Char.xpos - 1; It's *as if* the kid was one unit further left, so he will step one unit smaller.

Remember what happened in the game?
* If I single-step with esc until I get frame 0x32 (as on my screenshot) and then press shift-right, then the kid will show frame 0x33 for a moment, and only *then* will he step forward.
And what did we get above for frame 0x33? "It's *as if* the kid was one unit further right, so he will step one unit bigger."
This "one unit" is enough to step into the chomper!

And the error in the other direction:
* Single-step until frame 0x33. (One frame after what you see on my screenshot.)
* Press shift-right.
According to my previous quote, this will show frame 0x34 briefly and the kid will step only then!
* Now press shift-right again. The kid won't step through the chomper, but do a very small step instead.
And what did we get above for frame 0x34? "It's *as if* the kid was one unit further left, so he will step one unit smaller."
The second, "very small" step is making up for the "one unit smaller" first step.

So... are you still with me or did I lose you earlier? :?
xhul
Sheikh
Sheikh
Posts: 27
Joined: October 28th, 2014, 6:27 pm

Re: Stepping into chompers

Post by xhul »

Nice digging david =]
Now we're sure it's a bad idea to do careful steps in a hurry when chompers are around...
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Stepping into chompers

Post by David »

Exactly...
Somehow this bug does not seem to appear if you're stepping up to a close button or an edge.
Post Reply