Guards Question

Discuss PoP1 for DOS here.
Post Reply
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1785
Joined: January 21st, 2020, 2:53 pm
Contact:

Guards Question

Post by atrueprincefanfrom18 »

I have two questions...

1. Why do guards disappear when they go out of the screen? For example, I pushed a guard below of the room, although there was a tile on the top floor below the current room, the game assume that guard is killed.

2. Why does the guard disappear when we enter the same room through a broken room link? Is the room redrawn without the guard or something like that?
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
Dh73
Vizier
Vizier
Posts: 104
Joined: October 30th, 2019, 9:20 pm
Contact:

Re: Guards Question

Post by Dh73 »

atrueprincefanfrom18 wrote: April 16th, 2020, 9:34 am I have two questions...

1. Why do guards disappear when they go out of the screen? For example, I pushed a guard below of the room, although there was a tile on the top floor below the current room, the game assume that guard is killed.

2. Why does the guard disappear when we enter the same room through a broken room link? Is the room redrawn without the guard or something like that?
Yes in fact, I've already asked myself too in my last level 09; and also, why they are sometimes disappear near a tapestry or they are sometimes inoffensive near a tapestry?
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1785
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: Guards Question

Post by atrueprincefanfrom18 »

Maybe David or Falcury can look at source code of SDLPoP and find the issue...
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Guards Question

Post by David »

atrueprincefanfrom18 wrote: April 16th, 2020, 9:34 am 1. Why do guards disappear when they go out of the screen? For example, I pushed a guard below of the room, although there was a tile on the top floor below the current room, the game assume that guard is killed.
Mechner simply chose to remove the guard when he falls out of the current room:
https://github.com/jmechner/Prince-of-P ... TO.S#L1391

The equivalent part in SDLPoP:
https://github.com/NagyD/SDLPoP/blob/ma ... 002.c#L233

atrueprincefanfrom18 wrote: April 16th, 2020, 9:34 am 2. Why does the guard disappear when we enter the same room through a broken room link? Is the room redrawn without the guard or something like that?
The guard is removed at: play_frame() -> exit_room() -> leave_guard()
The guard would be added at: play_frame() -> check_the_end() -> check_shadow() -> enter_guard()
But he's not added because the game checks if the next room is the currently drawn room:
https://github.com/NagyD/SDLPoP/blob/ma ... 00.c#L1185
And if they are the same, then the game skips a few things, like loading the guard in the next room.

By the way, the same happens if you switch to a room which contains a guard (using H,J,U,N in cheat mode) then you enter that room.

Dh73 wrote: April 16th, 2020, 11:01 am Yes in fact, I've already asked myself too in my last level 09; and also, why they are sometimes disappear near a tapestry or they are sometimes inoffensive near a tapestry?
disappear:
What do you mean? Can you show an example?

inoffensive:
The game erroneously treats tapestries (door tops) as if they were opaque from both left and right.
https://github.com/NagyD/SDLPoP/blob/ma ... 003.c#L652
They should be conditionally ignored in the same way as gates are a few lines above.

By the way, if you put a guard right onto a doortop+floor tile, turned right, then he will repeatedly switch between being active and inactive. :)
See attachment.
Attachments
guard_doortop.p1r
(3.11 KiB) Downloaded 60 times
Dh73
Vizier
Vizier
Posts: 104
Joined: October 30th, 2019, 9:20 pm
Contact:

Re: Guards Question

Post by Dh73 »

David wrote: April 18th, 2020, 12:04 pm
atrueprincefanfrom18 wrote: April 16th, 2020, 9:34 am 1. Why do guards disappear when they go out of the screen? For example, I pushed a guard below of the room, although there was a tile on the top floor below the current room, the game assume that guard is killed.
Mechner simply chose to remove the guard when he falls out of the current room:
https://github.com/jmechner/Prince-of-P ... TO.S#L1391

The equivalent part in SDLPoP:
https://github.com/NagyD/SDLPoP/blob/ma ... 002.c#L233

atrueprincefanfrom18 wrote: April 16th, 2020, 9:34 am 2. Why does the guard disappear when we enter the same room through a broken room link? Is the room redrawn without the guard or something like that?
The guard is removed at: play_frame() -> exit_room() -> leave_guard()
The guard would be added at: play_frame() -> check_the_end() -> check_shadow() -> enter_guard()
But he's not added because the game checks if the next room is the currently drawn room:
https://github.com/NagyD/SDLPoP/blob/ma ... 00.c#L1185
And if they are the same, then the game skips a few things, like loading the guard in the next room.

By the way, the same happens if you switch to a room which contains a guard (using H,J,U,N in cheat mode) then you enter that room.

Dh73 wrote: April 16th, 2020, 11:01 am Yes in fact, I've already asked myself too in my last level 09; and also, why they are sometimes disappear near a tapestry or they are sometimes inoffensive near a tapestry?
disappear:
What do you mean? Can you show an example?

inoffensive:
The game erroneously treats tapestries (door tops) as if they were opaque from both left and right.
https://github.com/NagyD/SDLPoP/blob/ma ... 003.c#L652
They should be conditionally ignored in the same way as gates are a few lines above.

By the way, if you put a guard right onto a doortop+floor tile, turned right, then he will repeatedly switch between being active and inactive. :)
See attachment.
here there are what I meant for disappear (Example_01.avi) and for inoffensive (Example_02.avi) ;) :? :)
Attachments
Example_02.zip
(2.88 MiB) Downloaded 57 times
Example_01.zip
(3.92 MiB) Downloaded 52 times
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1785
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: Guards Question

Post by atrueprincefanfrom18 »

Hmm... Interesting!
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
David
The Prince of Persia
The Prince of Persia
Posts: 2850
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Guards Question

Post by David »

Dh73 wrote: April 18th, 2020, 7:49 pm here there are what I meant for disappear (Example_01.avi)
When someone (a guard or the prince) is standing on a tapestry tile, their sprite will be clipped at the left edge of the tapestry.
https://github.com/NagyD/SDLPoP/blob/ma ... 06.c#L1606

If you press Shift+B (blind mode) in cheat mode, you'll see that the guard is still there.
But because of the clip, the game won't draw even those parts which should be visible to the right of the tapestry.

How I made this screenshot: I placed a guard turned left, then I ran under him to turn him right. Then I pressed Shift+B.
The guard is at the area where part of the tapestry and the floor remained visible.
However, all of that area is on the right side of the tapestry's left edge, and thus the whole guard sprite gets clipped.
guard_doortop_blindmode.png
guard_doortop_blindmode.png (1.54 KiB) Viewed 1759 times
This clipping is a bit like when cartoon characters hide behind a thin tree. :)
Dh73 wrote: April 18th, 2020, 7:49 pm and for inoffensive (Example_02.avi) ;) :? :)
Hm, so it works also when the prince (not the guard) is on the tapestry's floor!
Dh73
Vizier
Vizier
Posts: 104
Joined: October 30th, 2019, 9:20 pm
Contact:

Re: Guards Question

Post by Dh73 »

David wrote: April 18th, 2020, 10:41 pm
Dh73 wrote: April 18th, 2020, 7:49 pm here there are what I meant for disappear (Example_01.avi)
When someone (a guard or the prince) is standing on a tapestry tile, their sprite will be clipped at the left edge of the tapestry.
https://github.com/NagyD/SDLPoP/blob/ma ... 06.c#L1606

If you press Shift+B (blind mode) in cheat mode, you'll see that the guard is still there.
But because of the clip, the game won't draw even those parts which should be visible to the right of the tapestry.

How I made this screenshot: I placed a guard turned left, then I ran under him to turn him right. Then I pressed Shift+B.
The guard is at the area where part of the tapestry and the floor remained visible.
However, all of that area is on the right side of the tapestry's left edge, and thus the whole guard sprite gets clipped.
guard_doortop_blindmode.png
This clipping is a bit like when cartoon characters hide behind a thin tree. :)
Dh73 wrote: April 18th, 2020, 7:49 pm and for inoffensive (Example_02.avi) ;) :? :)
Hm, so it works also when the prince (not the guard) is on the tapestry's floor!
Ok: thanks a lot for your answers and explanations :)
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Guards Question

Post by dmitrys »

This is a actually loaded question mostly related to the fact that most computers in the late 80s had 512-640 KB of RAM. So the game had to limit how many objects/characters are visible at one time. There is only 1 visible slot for a guard in each room that can also be used by mouse/shadow/etc. So you cannot have 2 characters besides kid appear at the same time. The Repetition of Time mod uses a trick where a guard disappears on level 8 because a mouse appears on the screen, but it is hidden behind a wall.

There are multiple ways a guard can disappear. The first way is for the guard to die between rooms. The visible screen has 59 pixels on each side that are invisible (out of bounds). SDLPoP has a flag that would make the guard drawn in the next room but the original game just would not display it.

There is the fallout scenario. If you push a guard into a chasm that makes him fall to the room below, the guard disappears at the bottom the of the room and is not drawn in the room below. While it could be possible to use the guard slot in the room below to draw the fallen guard, it would be a problem if there is already a guard in the room below. The other guard would disappear; or the fallen guard would have to disappear. There are 2 different use cases that you have to handle - a regular fallout in the same room (ex: fat guard on level 6), a guard pushed into an abiss in the next room (ex: second guard on level 7 pushed into an abiss to the right). The second scenario is different because the fallout does not happen until the guard is in the next room.

Then you have the guard follows kid scenario. Typically guard follows kid into the next room if they are in fight mode or the distance between them is small enough. What that means is once the guard moves into the the non-visible area of the previous room, he is removed from that room and is drawn in the calculated slot in the room where kid is. If there is no continuous floor the guard can disappear even when there is only a 1 floor drop. And the logic gets more complicated because if there is a guard in the next room or kid dropped out the guard would be left in the previous room.

A room that links to itself is actually an interesting scenario and that is one scenario that I have not yet tested. Guards in the active room use the "Guard" slot while guards in other rooms are stored inside variables of the "level" variable in the "exit_room" method. When you enter the room, the "Guard" slot gets overwritten with the values from the "level" variable for that specific room in the "enter_room" method. So some logic might be broken if both variables point at the same room.

I have done a lot of work in an SDLPoP fork to allow multiple dead guards (up to 3) by introducing separate slots for them and making sure the guard can fall out and follow you into rooms with dead guards or even an active guard if a dead guard fell out. I am planning on release the final version of the mod early next year and have a bunch of videos showing progress here: viewtopic.php?f=73&t=4606&start=120.

The changes actually fixed a few bugs from the original PoP1, like a guard getting thrown into spikes into the next room (on level 11) and getting rendered inside a wall in the wrong room as well as spikes next to the spiked guard getting stuck open. You can also have guards fall onto buttons in rooms below and having new guards coming into rooms when you kill the active guard (like PoP2).

In PoP2 they have made extensive changes to allow multiple active guards in the room. They also have a set of slots for dead guards separate from active guards and guards can also fall out of the room randomly or when that heap of dead guards is full. Guards can also run and jump. I wish that source code was available.
Post Reply