Patch:Map (Keen 4)

From KeenWiki
Jump to navigation Jump to search

This page contains patches that relate to the map in Keen 4, that is, things that can only be done on the map.

Other pages that contain patches related to ones here are Patch:Wetsuit, Patch:Miragia Patch:Flags and Patch:Foot.


What level is the map

These patches alter what level the map is. There are several aspects to this which potentially allows multiple map levels.


Level game starts in

This patch causes the player to start the game in a different level than the map. (Level 0) The values of the level variable given here will start the game in the default BWB level.

There is one minor side effect to this patch; the high word of the Extra Keen At score is not set to 0. What this means is that the game cannot start with an Extra Keen At score of more than 65'000 or so without a slightly more complicated patch being used.

Keen 4

#Keen starts game in the BWB
%patch $5CBB {$7A68W} [$0012W]


Level Keen returns to on completing a level

This patch changes what level the player returns to when he completes any level. (Including level 0, the default map.) By default this is level 0, but it can be any other game level if desired. If the starting level is not changed, (See above) then the game will in effect have a 'starting map' that may never be accessed again after a level is entered.

This doesn't affect what level Keen goes to when he rescues a Council Member however. (See below.)

Keen 4

#Level Keen returns to on completing a level
%patch $6B33 {$7A68W} [$0000W]


Level Keen returns to on saving a Member

This patch changes what level the player returns to when he rescues a Council Member. By default this is level 0, but it can be any other game level if desired. This can allow a 'special map' that can only be accessed by saving a member.

This doesn't affect what level Keen goes to when he completes a level however. (See above.)

Keen 4

#Level Keen returns to on saving a Member
%patch $6AEB {$7A68W} [$0000W]


Level with map-type scrolling

This patch allows the modder to change what levels behave as map-type levels. By default both the map (level 0) and the Well Of Wishes‎;(level 17) are map-type levels. map-type levels scroll differently and cannot be 'won' by moving off the left or right sides of the level. They also don't directly kill Keen when he leaves the top or the bottom; another piece of code does this.

The patch below has three parts, first what is checked for in brown ($A7EDW, the current level); second the value in blue ($00 = 0, so level 0); and thirdly the jump, again in brown. ($74, only jump if...) The net result is that if the current level is 17 or 0, the 'normal level' code is skipped.

Keen 4

#Which levels are WoW levels
%patch $9051 {$A7EDW}  [$00] {$74}


Levels map tile code is used in

In Keen Galaxy and Dreams there are two 'player tile interactions' that are used by the current player sprite in addition to that sprite's own tile interaction code. The 'level tile code' is responsible for the player's interactions with items, gem holders and deadly tiles while the 'map tile code' is responsible for the player's interaction with map teleporters and water entrances.

By default only in level 0 does the player sprite use the map tile code; otherwise the level tile code is used instead. This can however be changed.

Levels map tile code is used in

#What level(s) Keen uses map tile interaction in -Keen 4
%patch $8FBC {$A7EDW} [$00] {$74}

#What level(s) Keen uses map tile interaction in -Keen 5
%patch $8F2E {$9E55W} [$00] {$74}

#What level(s) Keen uses map tile interaction in -Keen 6
%patch $8D96 {$A97BW} [$00] {$74}


No map, just go to next level

This patch alters the 'complete level' code so that Keen will not return to the map but instead moves to the next level A side effect of this is that Keen can complete level 0 and go to level 1. (No map.) Levels are not marked as done, but this has no effect in the default game.

This also means the 'one moment' window will not appear when exiting the original map level. (Level 0.) It is compatible with most other patches on this wiki. Note that Keen will go to the map (Level 0) if he rescues a Council Member.

The second version of the patch sets a 'maximum level' (marked in blue) that Keen cannot advance past; finishing this level simply causes it to reload. The third version of the patch is the same, except that Keen is sent back to level 0 on finishing the highest level.

Keen 4

#Winning level goes to next level
%patch $6B1E $FF $06 $7A20W  $90 $90 $90
%patch $6B31 $A1 $7A20W  $A3 $7A68W
%patch $6B3D $EB $0A

#Winning level goes to next level -max level is 16, stay there
%patch $6B1E $FF $06 $7A20W  $90 $90 $90
%patch $6B31 $83 $3E $7A20W  [$10] $76 $04 $FF $0E $7A20W  $A1 $7A20W
                 $A3 $7A68W  $A1 $A7EDW  $A3 $A7C2W  $90

#Winning level goes to next level -max level is 16, loop to level 0
%patch $6B1E $FF $06 $7A20W  $90 $90 $90
%patch $6B31 $83 $3E $7A20W  [$10] $76 $05 $33 $C0 $A3 $7A20W  $A1
             $7A20W  $A3 $7A68W  $A1 $A7EDW  $A3 $A7C2W


Keen can exit the map level by going offscreen

This patch changes things so that Keen can 'win' the map level by going offscreen. (by default nothing happens, Keen can wander offscreen as far as he likes.) When winning Keen will be sent back to the map by default, basically restarting the level.

Keen 4

#Can exit the map by going offscreen
%patch $904F $EB $05


No flipping flags\No flags

In Keen 4 the flags 'flip' toward the level flag holder when (and only when) the level is first completed. The first patch here makes it so that flags always spawn in holders, with no flipping. The second makes it so nothing is spawned when levels are first completed.

Keen 4: No flipping flags

#Flags are always sitting
%patch $6146 $0D8F09FDRL

#No flipping flag
%patch $6145 $90 $90 $90 $90 $90

The first patch here makes flags always flip, due to the way this works, the flag of the lowest level Keen has completed will flip normally, the other levels will have no flipping flag, but a flag will appear in the holder about a second after the level is exited. This is a bit odd, but may be useful. The second patch prevents sitting flags appearing on levels Keen has already completed but keeps the flipping flag (and thus sitting flag produced) that appears when a level is first done. Finally the third patch completely removes flags from the map.

Keen 4: No sitting flags

#Flags always flip
%patch $6154 $0D8F0A5BRL

#No sitting flags
%patch $6153 $90 $90 $90 $90 $90

#No flags at all
%patch $6145 $90 $90 $90 $90 $90
%patch $6153 $90 $90 $90 $90 $90


Foot on map

When Keen exits a level by touching the foot, he will appear on the map as the 'riding the foot' sprite. Depending on what level he just left he will then move to one of two locations. Patches relating to the foot itself can be found at Patch:Foot.


Disable

This disables the foot entirely so that Keen appears on the map as normal if he wins a level with the foot.

Keen 4

#Totally disable foot
%patch $DE02 $90 $90


Foot destinations

This changes the destination the foot moves to. Which destination depends on the level Keen has just played. If it is the secret level then he will go to destination 2, otherwise to destination 1. The first trip moves in a downwards direction, if the level where Keen can get the foot is below this destination, problems can arise. The second is in an upwards direction and trouble can arise if the secret level is below this.

There is also a patch that makes the foot take Keen to a relative location, but it may have undesirable side effects.

Keen 4

#Foot location 1:
%patch $DE43 $1E
%patch $DE58 $37

#Location 2: (When exiting POTF)
%patch $DE78 $10
%patch $DE8C $2F

#When foot got, moves Keen 10 tiles right from whatever level entrance
#he was in (Instead of always to the same location)
%patch $DE65 $10


Wetsuit and swim message

This relates to the wetsuit and the 'I can't swim' message.


Swim message

This message is displayed whenever something with the 'map Keen tile collision' hits a tile with one of the 'water entrance' properties. It is thus possible to get other things than Keen to produce the message and not only on the map. However, using other sprites tends to produce the dreaded 'infinitely repeating message' problem.

Using this patch requires knowledge of Patch:Game stats and Patch:Text patches. When the window is opened it stores a graphic chunk in memory, then displays it in the window. The image is right aligned (its rightmost edge touches the right side of the window.) according to the 'image width' variable. This doesn't have to be the actual width of the image and can be used to position the image in the window. (For example, by default the displayed image is 48 pixels wide and the width value keeps it on the right of the window. If the value is made larger than the actual image width then the image appears more left in the window.) A matching value is the ' horizontal text alignment' variable which stops the text from spilling over onto the image. By default it matches the image width. Finally there is the 'vertical text alignment' which controls how far down from the top of the window the text appears.

In this case only one chunk is cached and displayed, so the two values MUST be the same. Note also there is a pause before the window can be dismissed. Any key pressed during this time 'won't count'.

Keen 4

#Can't swim message
%patch $F370 [$0008W] #Window height
%patch $F374 [$001AW] #Window width
%patch $F364 [$006FW] #Cache chunk 111
%patch $F380 [$006FW] #Display chunk 111
%patch $F38F [$0030W] #'Width of image'
%patch $F39E [$30]    #Horizontal text alignment
%patch $F3A3 [$0C]    #Vertical text alignment
%patch $F3A5 [$1BCDW] #Text read from
%patch $F3B6 [$001EW] #Pause before window can be dismissed

#Text
%patch $30A3D  "I can't swim!" $00


Complete window code

This is the complete swim window code. On the first line chunk 111 is cached for display. On the second line the window's height and width are set. On the third line chunk 111 is displayed in the window. The fourth line contains the 'image width variable' used to position the text in the window along with the image.

The text itself is called at the end of line 5.It is positioned $0C pixels down from the window top and $30 pixels left on the window's right side. At the start of line 7 is a pause where the window can't be dismissed. (Vital to stop the player accidentally skipping it.)

Complete Can't swim window code

#Complete Can't swim window code
%patch $F356 $55 $8B $EC $9A $18740AFDRL     $9A $12A614CDRL     $B8 [$006FW]
             $50 $9A $12A61117RL     $83 $C4 $02 $B8 [$0008W]  $50 $B8 [$001AW]
             $50 $9A $19311070RL     $83 $C4 $04 $B8 [$006FW]  $50 $FF $36 $DE
             $A7 $A1 $A533W  $03 $06 $A531W  $2D [$0030W]  $50 $9A $1D060C79RL
                 $83 $C4 $06 $83 $2E $A531W  [$30] $83 $06 $A535W  [$0C] $B8 [$1BCDW]
                 $50 $9A $19310EBDRL     $83 $C4 $02 $9A $1D060A9BRL     $B8
             [$001EW]  $50 $9A $1E0A0AD3RL     $83 $C4 $02 $9A $146008A8RL   
             $9A $14600EDFRL     $9A $12A614EDRL     $5D $CB


What triggers 'can't swim'

This is what the map looks for when either letting Keen swim or not. By default if the suit variable is NOT equal to 0 then Keen can swim. It is thus possible to make the trigger something like a gem or completed level. Looking at Patch:Jump conditions will allow you to make it so Keen can always or never swim on the map.

Map suit check

#Swimsuit map trigger:
%patch $E208 {$7A5C} [$00] $75


Keen doesn't interact with map water

This patches makes it so that Keen doesn't interact with water entrances or exits at all.

Keen doesn't interact with map water

#Keen doesn't interact with map water
%patch $8FC0 $1A


Levels Keen uses map tile interaction in

This patch controls what levels the player sprite uses the map tile interaction in. By default this is only in level 0, the map. Noe that if Keen uses this code he cannot use the 'normal' tile interaction that allows him to pick up item tiles.

What level(s) Keen uses map tile interaction in

#What level(s) Keen uses map tile interaction in
%patch $8FBC {$A7EDW} [$00] {$74}


Teleporters on the map

It is possible to overwrite the Miragia sprite with a teleporter. This will utterly erase the sprite's original function but allow Keen to teleport around the map.

As set up by the patch below the teleport consists of a 3x3 square of tiles with a teleporter sprite in the middle (The sprite will resemble Map Keen.) Keen must touch the teleport sprite (Located at the middle tile, tile 5) to initiate a teleport. He will be 'frozen while the start teleport square animates four frames before becoming invisible and moving with the screen. When Keen reaches his destination he will appear a tile below it and move down slightly. A sound also plays on teleport.

Keen cannot teleport to an area of the map blocked by a scrollbar as the camera moves with him. The 3x3 tiles must be animating with a delay of 0, just like door tiles. The teleport should be set up as follows, with at least two teleporters being placed in the level:

S I
  1 2 3
  4 5 6
  7 8 9

Here the numbers are the 3x3 animating square, 'S' is where the Miragia sprite is placed in the level and 'I' is the destination ($XXYYW) that the teleporter will send Keen to. Each teleporter can only send Keen to one destination. Teleporters can be adapted for either the map or normal levels, but not both. (Since the teleporting Keen actions will either return Keen to map Keen or in-level Keen.) The patch is as follows with brief explanation to follow.

For a thorough breakdown of the patch, including a working mod set up to use it see https://dl.dropboxusercontent.com/u/3786745/telepatch.zip

Compact Miragia teleport sprite patch

#########################
# MIRAGIA TELEPORT PATCH#
#########################

#Teleport resting action
%patch $30C6C $0116W $0116W $0000W $0000W $0000W $0030W $0000W $0000W
              $09DC171FRL   $0FA80040RL   $09DC176ERL   $1DFCW

#Teleport animation actions
%patch $30C8A $0117W $0117W $0000W $0000W $0000W $0030W $0000W $0000W
              $0FA80110RL   $00000000L    $09DC176ERL   $1E38W
%patch $30CA8 $0118W $0118W $0000W $0000W $0000W $0030W $0000W $0000W
              $0FA80110RL   $00000000L    $09DC176ERL   $1E56W
%patch $30CC6 $0117W $0117W $0000W $0000W $0000W $0030W $0000W $0000W
              $0FA80110RL   $00000000L    $09DC176ERL   $1E74W
%patch $30CE4 $0118W $0118W $0000W $0000W $0000W $0030W $0000W $0000W
              $0FA80110RL   $00000000L    $09DC176ERL   $1E92W

#Teleport move Keen action
%patch $30D02 $FFFFW $FFFFW $0000W $0000W $0000W $0006W $0000W $0000W
              $0FA80090RL   $00000000L    $00000000L    $1DFCW

#Teleporting keen actions
%patch $30D20 $0116W $116W $0000W $0000W $0000W $0130W $0000W $0000W
              $00000000L   $00000000L    $09DC176ERL   $1ECEW
%patch $30D3E $0117W $117W $0000W $0000W $0000W $0030W $0000W $0000W
              $00000000L   $00000000L    $09DC176ERL   $15A0W

#Teleport spawn code
%patch $FA80 $55 $8B $EC $33 $C0 $50 $9A $06BD1E11RL     $83 $C4 $02 $8B $1E
             $D8 $A7 $C7 $07 [$0001W]  $C7 $47 $02 [$0002W]  $8B $46 $06 $C1 $E0
             $08 $05 [$0200W]  $89 $47 $0A $8B $46 $08 $C1 $E0 $08 $05 [$0200W]
             $89 $47 $0C $C7 $47 $1C {$1DFCW}  $C7 $47 $06 [$0000W]  $5D $CB

#Teleport collision: Keen triggers teleport sequence
%patch $FAC0 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $1D
             $B8 [$0007W]  $50 $9A $187409F1RL     $44 $44 $C7 $44 $1C {$1E1AW}
             $B8 {$1EB0W}  $50 $57 $9A $09DC118CRL     $83 $C4 $04 $5F $5E $5D
             $CB

#Teleporter teleport Keen behavior
%patch $FB10 $55 $8B $EC $83 $EC $04 $56 $57 $8B $76 $06 $8B $5C $2E $4B $4B
             $D1 $E3 $8B $87 $25 $C9 $D1 $E8 $D1 $E0 $8B $16 $EB $A7 $8B $5C
             $2C $4B $D1 $E3 $03 $C3 $89 $56 $FE $89 $46 $FC $C4 $5E $FC $26
             $8B $17 $8B $C2 $25 $FF $00 $B1 $08 $D3 $E0 $05 $0020W  $8B $3E
             $A7D6W  $89 $45 $0C $8B $C2 $D3 $E8 $D3 $E0 $89 $45 $0A $C7 $45
             $20 [$0001W]  $C7 $45 $06 [$0000W]  $8B $5D $1C $FF $77 $1C $57 $9A
             $09DC120ARL     $83 $C4 $04 $C7 $45 $06 [$0001W]  $C7 $45 $10 [$0001W]
                 $5F $5E $8B $E5 $5D $CB

#Teleporter animate tiles behavior
%patch $FB90 $55 $8B $EC $83 $EC $06 $56 $57 $8B $76 $06 $8B $5C $2E $4B $D1
             $E3 $8B $87 $25 $C9 $D1 $E8 $D1 $E0 $8B $16 $A7E9W  $8B $5C $2C
             $4B $D1 $E3 $03 $C3 $89 $56 $FE $89 $46 $FC $C4 $5E $FC $8A $74
             $2E $FE $CE $B9 [$0003W]  $51 $8A $54 $2C $FE $CA $B9 [$0003W]  $26
             $8B $3F $53 $06 $8B $DF $8E $06 $A1 $C8 $26 $8A $87 $42 $39 $98
             $03 $C7 $89 $46 $FA $60 $B8 [$0001W]  $50 $50 $8A $C6 $98 $50 $8A
             $C2 $98 $50 $B8 [$0001W]  $50 $16 $8D $46 $FA $50 $9A $16540F28RL
                 $83 $C4 $0E $61 $07 $5B $43 $43 $FE $C2 $E2 $C2 $59 $03 $1E
             $E6E2W  $83 $EB $06 $FE $C6 $E2 $AD $5F $5E $8B $E5 $5D $CB $0C
             $5E $5D $CB

The first part of the patch deals with sprite actions; six are needed for the teleporter and two for Keen. The first action is the 'resting' action for the teleporter; what it does when nothing else is happening. It animates to itself, uses one of Map Keen's animations and also a special collision that is triggered when Keen touches it. The next four actions are used when the teleporter is 'active'; each action does nothing more than animate a 3x3 block of tiles one frame. Finally the sixth action teleports Keen which uses a special behavior to move Keen across the map.

Keen meanwhile has two actions. Neither 'do' anything, they merely sit there and stop the player from moving during the teleport sequence. They return Keen to the 'stand on map' action. Changing $15A0W to 'standing Keen' will make the patch work in normal levels but not on the map.

Following this is the spawn code for the teleporter, which places it in the level. The sprite is given type 1, activity 2, an action of $1DFCW (The resting teleporter action.) and no clipping. It is also spawned $0200W,$0200W from where it is placed, or 2 tiles down and two tiles right, as reflected in the tile-sprite setup for this patch.

Next is the resting teleport's sprite collision. This reacts to Keen's sprite type. This means Keen must touch the teleport sprite to activate it. When he does so sound 7 plays, the teleporter's action is changed to $1E1AW (Active teleporter) and Keen's action is changed to $1EB0W (Teleporting Keen 1).

The second to last block involves the teleporter's teleporting Keen behavior; this is used by the teleporter and not by Keen. It takes Keen and first sets his foreground to 1 and removes his clipping; this is so he can pass through solid tiles while teleporting and not look odd. It also changes his action (to teleporting Keen 2) When Keen arrives at his destination his clipping is set to 1 (So he doesn't walk through solid stuff.) and his vertical direction is set to 1. (On the map this makes him move down, away from the teleporter destination slightly.)

The final and largest part of the patch deals with the active teleporter's behavior. This animates a 3x3 block of tiles. The size of the block can be changed by altering the two blue $0003Ws in the patch. The second blue $0001W alters the foreground tiles, setting this to 0 makes it alter the background tiles instead. (The first marks the fact that 1x1 tiles will be altered each time, it is best not to interfere with this.)


Teleporter patch without tile animation

This version of the above patch Teleports Keen without animating the map tiles or teleporter sprite. This allows the teleporter to be much more compact and versatile, if less showy. it works nearly identically to the patch above and all notes also apply here. Note that the 'pause' action is used to allow a small pause between Keen touching the teleporter and being teleported, otherwise he teleports instantly.

The one difference is that the teleporter spawns exactly where placed on the map instead of two tiles down and left.

Compact Miragia teleport sprite patch less tile animation

#########################
# MIRAGIA TELEPORT PATCH#
#########################

#Teleport resting action
%patch $30C6C $0116W $0116W $0000W $0000W $0000W $0030W $0000W $0000W
              $09DC171FRL   $0FA80040RL   $09DC176ERL   $1DFCW

#Teleport pause before teleporting Keen action
%patch $30CE4 $0116W $0116W $0000W $0000W $0000W $0030W $0000W $0000W
              $09DC171FRL   $00000000L    $09DC176ERL   $1E92W

#Teleport move Keen action
%patch $30D02 $FFFFW $FFFFW $0000W $0000W $0000W $0006W $0000W $0000W
              $0FA80090RL   $00000000L    $00000000L    $1DFCW

#Teleporting keen actions
%patch $30D20 $0116W $116W $0000W $0000W $0000W $0130W $0000W $0000W
              $00000000L   $00000000L    $09DC176ERL   $1ECEW
%patch $30D3E $0117W $117W $0000W $0000W $0000W $0030W $0000W $0000W
              $00000000L   $00000000L    $09DC176ERL   $15A0W

#Teleport spawn code
%patch $FA80 $55 $8B $EC $33 $C0 $50 $9A $06BD1E11RL     $83 $C4 $02 $8B $1E
             $D8 $A7 $C7 $07 [$0001W]  $C7 $47 $02 [$0002W]  $8B $46 $06 $C1 $E0
             $08 $05 [$0000W]  $89 $47 $0A $8B $46 $08 $C1 $E0 $08 $05 [$0000W]
             $89 $47 $0C $C7 $47 $1C {$1DFCW}  $C7 $47 $06 [$0000W]  $5D $CB

#Teleport collision: Keen triggers teleport sequence
%patch $FAC0 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $83 $3D [$02] {$75} $1D
             $B8 [$0007W]  $50 $9A $187409F1RL     $44 $44 $C7 $44 $1C {$1E74W}
             $B8 {$1EB0W}  $50 $57 $9A $09DC118CRL     $83 $C4 $04 $5F $5E $5D
             $CB

#Teleporter teleport Keen behavior
%patch $FB10 $55 $8B $EC $83 $EC $04 $56 $57 $8B $76 $06 $8B $5C $2E
             $D1 $E3 $8B $87 $25 $C9 $D1 $E8 $D1 $E0 $8B $16 $EB $A7 $8B $5C
             $2C $4B $D1 $E3 $03 $C3 $89 $56 $FE $89 $46 $FC $C4 $5E $FC $26
             $8B $17 $8B $C2 $25 $FF $00 $B1 $08 $D3 $E0 $05 $0020W  $8B $3E
             $A7D6W  $89 $45 $0C $8B $C2 $D3 $E8 $D3 $E0 $89 $45 $0A $C7 $45
             $20 [$0001W]  $C7 $45 $06 [$0000W]  $8B $5D $1C $FF $77 $1C $57 $9A
             $09DC120ARL     $83 $C4 $04 $C7 $45 $06 [$0001W]  $C7 $45 $10 [$0001W]
                 $5F $5E $8B $E5 $5D $CB


Stop Ctrl, Alt, Space entering levels

These patches disable various keys on the map so that the player cannot use them to enter levels. Different lines are needed for when Keen is sitting still or moving. It is also possible to disable entering levels completely, in which case some other way for Keen to enter levels will be required.

Keen 4

#Disable Ctrl to enter levels
%patch $DFC5 $90 $90 #When still
%patch $E011 $90 $90 #When moving

#Disable Alt to enter levels
%patch $DFCC $90 $90 #When still
%patch $E018 $90 $90 #When moving

#Disable space to enter levels
%patch $DFD3 $EB #When still
%patch $E01F $EB #When moving

#Disable entering levels completely
%patch $DFC0 $5E $5D $CB #When still
%patch $E00C $EB $1B     #When moving