Tuesday, July 18, 2017

Door Into Bummer

Not far into act 1 of Lava Reef Zone, we come across this simple obstacle: a wall-mounted cannon over a closed door, shooting an endless barrage of teeny tiny pellets. Once the thing is put out of its misery, the door slides open, revealing the path to the rest of the stage.


When the cannon object is punched in the face, it does a couple of important things. First, it sets one of the flags in the level trigger array, based on the four lowest bits of its subtype. The trigger array is a set of general-purpose, temporary flags which get cleared whenever a level loads. In particular, the flag set by the cannon is under the watchful eye of the nearby door object. As soon as the flag is set, the door wakes up and does its thing.
loc_42E84:
    ...
    move.b  $2C(a0),d0
    andi.w  #$F,d0
    lea     (Level_trigger_array).w,a3
    lea     (a3,d0.w),a3
    moveq   #0,d3
    ...

sub_42EC0:
    ...
    bset    d3,(a3)
    move.l  #Obj_Explosion,(a0)
    move.b  #2,5(a0)
    ...
The second thing the cannon does is overwrite its own code pointer with the address for the enemy explosion object. It also sets the routine byte to 2 in order to skip over the initial bit which spawns a small animal along with a score popup. The key takeaway though, is that once the explosion object does its thing, it calls Delete_Current_Sprite, which deletes the object and ensures it doesn't spawn again lest the player wander off and then come back.

So far everything sounds good. But there's a wrinkle to this plan. Remember how I said the level trigger array is cleared whenever a level loads? Well, there's a star post right before this area. If you destroy the cannon, then hit the star post with enough rings to enter a bonus stage, and then come back...


Congratulations, you have screwed yourself over.

When you enter a bonus stage, the object respawn table for the current stage is not cleared. This is what prevents you from going back and tagging all the rings and enemies again. However, the level trigger array is cleared, putting you in a situation where the door is very much closed, but the only object that can do anything about it has been permanently removed from the map. The only way out of this mess is to lose a life or reload your save file.

2 comments:

  1. Did you know about this before I told you on the Sonic 3 Complete thread on Sonic Retro?

    ReplyDelete