Auto-resurrection

Discuss PoP1 for DOS here.
Post Reply
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5746
Joined: April 9th, 2009, 10:58 pm

Auto-resurrection

Post by Norbert »

Aram wrote: April 16th, 2018, 9:31 pm I'll just do the trick.
That is very interesting.
David, any idea what happens there?
Maybe the prince briefly meeting the shadow while jumping changes some kind of game state?
Or a buffer overflow, maybe?
(Level 12a of Pyramid)
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Auto-resurrection

Post by David »

(I moved your post so our discussion won't get lost in the Pyramid topic.)
Norbert wrote: April 16th, 2018, 9:50 pm That is very interesting.
David, any idea what happens there?
Maybe the prince briefly meeting the shadow while jumping changes some kind of game state?
Or a buffer overflow, maybe?
(Level 12a of Pyramid)
I tested this now.

It seems that you indeed have to visit the shadow's room. (The shadow's HP stays on screen, but the video is cropped so that's not visible.)
It also works if I merely look at the shadow's room with the H/J/U/N keys.
For easier testing I moved the starting position to the ledge below the shadow's room.
From there I can't actually go up, but pressing "U" works. But if I don't press "U" then there is no resurrection.

The gate also needs to be closed. (Well, the first half of the video is about reaching the button that closes that gate.)

This also happens in SDLPoP, so I can probably figure out what happens by debugging.
Expect a follow-up coming soon...
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Auto-resurrection

Post by David »

David wrote: April 22nd, 2018, 11:02 am This also happens in SDLPoP, so I can probably figure out what happens by debugging.
Expect a follow-up coming soon...
Here is what I found out:
  • When the kid lands, all his HPs are taken; in land()
  • This doesn't immediately zero the kid's HP, it merely sets hitp_delta; in take_hp()
  • If you saw the shadow:
    • The presence of the shadow sets guardhp_delta=4; in do_init_shad()
    • guardhp_delta is copied to hitp_delta, and hitp_delta is applied; in do_delta_hp()
      This means that the loss of hit points from the hard landing is *not* effective.
      Note: This HP regeneration was already mentioned in the "permadeath" topic: viewtopic.php?p=15794#p15794
  • If you didn't see the shadow:
    • do_delta_hp() zeroes the kid's HP.
    • Since the kid has zero HP, he is marked dead; in control_kid()
  • If the gate is closed then the kid bumps into it; in check_bumped_look_left()
  • The kid can bump into things only if he is alive; in bumped()
  • Finally the game plays the "bumped" animation; in bumped_floor()
Note: If you saw the shadow but the gate is open, then the kid will appear dead but he will have non-zero HP.
And the game won't display "Press Button to Continue".
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5746
Joined: April 9th, 2009, 10:58 pm

Re: Auto-resurrection

Post by Norbert »

Thanks for doing the analysis.

It's not clear to me what is the relevance - if any? - of the closed gate.
Maybe I overlooked something in your post.

Why won't this work?
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Auto-resurrection

Post by David »

Norbert wrote: April 22nd, 2018, 2:34 pm It's not clear to me what is the relevance - if any? - of the closed gate.
Maybe I overlooked something in your post.
The kid bumps into the gate only if it's closed.
But it does not have to be a gate, it could also be a wall, or a gate top.
The mod uses an initially open gate because it forces the player to find the close button.
Norbert wrote: April 22nd, 2018, 2:34 pm Why won't this work?
Because of this: https://github.com/NagyD/SDLPoP/blob/ma ... 02.c#L1139
(In that code, Char=shadow, Opp=prince.)

The shadow regenerates the kid's HP only while the shadow is made "stuck" offscreen by being initialized in every frame.
The game keeps the shadow "stuck" while the prince's x coordinate is at least 150.
That place is near the middle of the fourth tile from the right.
This is so that the shadow won't appear until you run over the loose floors on the original level 12.

Once the prince is left from that place (in any room!), shadow_initialized becomes true (1), and do_init_shad() is never called again (until you re-enter the shadow's room), and the shadow falls into the room.
In your video, you enter a room from the left, that is when x becomes less than 150.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5746
Joined: April 9th, 2009, 10:58 pm

Re: Auto-resurrection

Post by Norbert »

Okay, so...
The prince needs to bump into something, apparently.
Also, he needs to be above (or below?) 150 from the left - I think.
But not 150 pixels and/or not from the left screen border, because that's not the middle of the fourth tile from the right...
And by entering from the left, x becomes less than 150, but running right apparently does not change x?
Just now I tried moving the hole in my test level further left and further right, but the prince still dies.
What are the exact conditions required for this to work?
Maybe, after 'seeing' the shadow room, the prince's horizontal position may never again be in the 0-150 range, for the trick to work?
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Auto-resurrection

Post by David »

Norbert wrote: April 28th, 2018, 7:49 pm Also, he needs to be above (or below?) 150 from the left - I think.
But not 150 pixels and/or not from the left screen border, because that's not the middle of the fourth tile from the right...
Character's x positions are measured in a special coordinate system.
You can find a drawing in Mechner's docs about PoP1, on page 7.
Basically, x = 58 is the left edge of the screen, and the screen is 140 units wide, making each tile 14 units wide.
On the DOS screen, that will mean x = (150 - 58) * 320 / 140 = 210.
Norbert wrote: April 28th, 2018, 7:49 pm And by entering from the left, x becomes less than 150, but running right apparently does not change x?
Running right *does* change x.
However, HP regeneration is disabled in the first frame when x is less than 150. Here: https://github.com/NagyD/SDLPoP/blob/ma ... 02.c#L1143
After that, it is not enabled again until you see the shadow's room again. Here: https://github.com/NagyD/SDLPoP/blob/ma ... g002.c#L71
Norbert wrote: April 28th, 2018, 7:49 pm Maybe, after 'seeing' the shadow room, the prince's horizontal position may never again be in the 0-150 range, for the trick to work?
Exactly. See above.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5746
Joined: April 9th, 2009, 10:58 pm

Re: Auto-resurrection

Post by Norbert »

I see. Thanks for the explanation.
Post Reply