Patch:Butler Robot

From KeenWiki
Jump to navigation Jump to search

Butler Robots are harmless, small, grey enemies found in Keen 1. This page lists patches relating to Butler sprites. It is divided into sections relating to the various sprite properties the patches involved. Being fluent with various sprite patch pages will help when working with these patches.

Sprite Type

Butler Robots use sprite type 5 which means they push Keen about but don't hurt him. See Patch:Keen (Keen 1) for how to patch the pushing of Keen. This will affect the Patch:Tank Robot too!

Keen 1

#Butler Bot sprite type:
%patch $1782 $05

Sprite Behavior

There are three behaviors relating to the Butler Robot, one of which is its collision. The Robot can walk back and forth, turning when it hits a wall or reaches a platform end; the second, turning behavior, just lets the robot sit and animate for a short period before walking again.

The Robot's collision stops Keen's shots, but otherwise nothing affects it and it cannot be shot. The Robot starts out walking.

$1DC7W #Butler Bot walk back and forth, turn at platform edges 
$1E5EW #Butler Bot turn
$1E94W #Butler Bot collision (Shots hit, keeps going)

When spawned

%patch $17C6 {$1DC7W}

In level

%patch $1E51 {$1E5EW} #After hitting left wall
%patch $1E1D {$1E5EW} #After reaching end of platforms
%patch $1E37 {$1E5EW} #After hitting right wall
%patch $1E74 {$1DC7W} #After turning

%patch $17CB {$1E94W} #Butler Robot collision

Walk off platform edges

This patch makes the Butler robot not turn at the edge of platforms, only when hitting walls. This means it will fall off platform edges, much like a Yorp or a Garg. The first patch stops the behavior changing; so when the Butler robot lands, it will be moving in the same direction. (That is, only hitting a wall will make it turn.) while the second patch will make it change behaviors and it will move in the opposite direction when it lands. (It will turn in midair so to speak.) and the changed behavior can be used to make a 'falling' bot behavior.

Bots walk off platform edges

#Butler robot walks of edge of platforms, no direction change
%patch $1DFF $EB

#Butler robot walks of edge of platforms, turn
%patch $1E0B $90 $90 $90 $90 $90 $90
%patch $1E1D {$1E5EW} #Do this behavior (Turn)

Butler Robot flies

This patch makes the Butler Robot fly, that is, it does not need to be on the ground. As a side effect it cannot turn at platform edges, instead behaving like a horizontal platform. (Which can be made vertical.)

Bots fly

#Butler robot flies
%patch $1DF4 $90 $90 $90 #Don't fall when walking
%patch $1E8C $90 $90 $90 #Don't fall when turning
%patch $1DFF $EB	 #Don't turn at platform edges

Time spent turning

This is how long Butler Robots spend turning before they resume walking. It can be as long or short as desired. To remove turning entirely it is best to change all the turning behavior calls to walking ones however.

Time spent turning

#Butler robot flies
%patch $1E6C [$0032W]

Complete Butler bot walking code

This is the complete default code for the Butler Robot's walking code. It contains, and is thus incompatible with, many of the patches on this page.

For the moving code, the first thing done is to set the animations at the end of line 1 and the start of line 2. These will be different depending on the direction the bot is traveling. This is followed by the animation speed and then the number of animation frames at the start of line 3. All of these values are highlighted in blue.

This is followed by two calls to gravity and tile collision, $E8 $xxxxW. Replacing the first with $90 $90 $90 will make the Bot never fall and the second will make it pass through tiles like a ghost. (Both of these affect the Butler Bot less than you would think.) After this comes three tile checks, beneath, right and left. For each the Bot checks things before altering its speed and action to 'turning'

The first check, on line 4, sees if the Bot has reached the end of a platform. (That is if there are not tiles with a solid top under it.) If it has, its speed is set to 0 and it turns. The next, on line 7, checks to see if it has hit a right wall, if so its speed becomes negative (left) and it turns. Finally on line 9 it checks to see if it has hit a left wall, if so its speed becomes right and it turns.

Notable is that the 'speeds' set in this behavior are actually saved to Misc variable C in the sprite, and the actual speed set to 0. This is to stop the Butler Bot when it is turning, but then let it use this 'saved speed' when it resumes walking. (In the case of the 'end of platforms' case the Butler Robot saves a reversed speed, so it turns around.)

Butler Bot moving code

#Butler robot moving code
%patch $1DC7 $55 $8B $EC $56 $83 $3E $40 $82 $00 $7E $08 $C7 $06 $48 $82 [$0058W]
                 $EB $06 $C7 $06 $48 $82 [$005CW]  $A1 $35 $51 $B1 [$05] $D3 $E8
             $25 [$0003W]  $8B $16 $48 $82 $03 $D0 $89 $16 $48 $82 {$E8 $0E33W}
             {$E8 $0E73W}  $8B $F0 $A9 $02 $00 $75 $26 $A1 $3C $82 $F7 $D8 $D1 #Edge of platform check
             $E0 $A3 $3C $82 $C7 $06 $3E $82 [$0000W]  $A1 $40 $82 $F7 $D8 $A3
             $4C $82 $C7 $06 $52 $82 {$1E5EW}  $33 $C0 $A3 $40 $82 $A3 $4A $82
             $F7 $C6 $04 $00 $74 $14 $C7 $06 $4C $82 [$FFA6W]  $C7 $06 $52 $82 #Right wall check
             {$1E5EW}  $33 $C0 $A3 $40 $82 $A3 $4A $82 $F7 $C6 $01 $00 $74 $14 #Left wall check
             $C7 $06 $4C $82 [$005AW]  $C7 $06 $52 $82 {$1E5EW}  $33 $C0 $A3 $40
             $82 $A3 $4A $82 $5E $5D $C3

More efficient Bot moving code

This is a more efficient version of the Butler Bot's movement code above. It removes repeated sections of code to make it significantly smaller and more flexible in patches. Notice that this makes it even more incompatible with other patches on this page, such as the behavior patches.

More efficient Bot moving code

#Butler robot moving code -more efficient
%patch $1DC7 $55 $8B $EC $56 $83 $3E $40 $82 $00 $7E $08 $C7 $06 $48 $82 [$0058W]
                 $EB $06 $C7 $06 $48 $82 [$005CW]  $A1 $35 $51 $B1 [$05] $D3 $E8
             $25 [$0003W]  $8B $16 $48 $82 $03 $D0 $89 $16 $48 $82 {$E8 $0E33W}
             {$E8 $0E73W}  $8B $F0 $A9 $02 $00 $75 $1A $A1 $3C $82 $F7 $D8 $D1
             $E0 $A3 $3C $82 $C7 $06 $3E $82 [$0000W]  $A1 $40 $82 $F7 $D8 $A3
             $4C $82 $EB $1A $F7 $C6 $04 $00 $74 $08 $C7 $06 $4C $82 [$FFA6W]
             $EB $0C $F7 $C6 $01 $00 $74 $14 $C7 $06 $4C $82 [$005AW]  $C7 $06
             $52 $82 {$1E5EW}  $33 $C0 $A3 $40 $82 $A3 $4A $82 $5E $5D $C3

Complete Butler bot turning code

This is the complete default code for the Butler Robot's turning code. It contains, and is thus incompatible with, many of the patches on this page.

The turning code is quite simple. On the first line is a time check, once this time is up the behavior will change to walking, seen on the second line. On the third line the animation speed, animation frames and sprite are set, in that order. All these values are marked in blue. Finally there are two calls to gravity and tile collision, $E8 $xxxxW. Replacing the first with $90 $90 $90 will make the turning Bot never fall and the second will make it pass through tiles like a ghost. (Both of these affect the Butler Bot much less than you would think.)

Butler Bot turning code

#Butler Robot turning code
%patch $1E5E $55 $8B $EC $A1 $4A $82 $03 $06 $14 $5B $A3 $4A $82 $3D [$0032W]
             $7E $0C $C7 $06 $52 $82 {$1DC7W}  $A1 $4C $82 $A3 $40 $82 $A1 $35
             $51 $B1 [$05] $D3 $E8 $25 [$0001W]  $05 [$0060W]  $A3 $48 $82 {$E8 $0D9BW}
                 {$E8 $0DDBW}  $5D $C3


The default speed of Butler Robots is +-90. When spawned Butler Robots will head right by default. After that it has two speeds depending on which direction it is moving.

Starting speed

%patch $17A5 [$005AW] #Move right

In level

%patch $1E4B [$005AW] #If turned right (Move right)
%patch $1E31 [$FFA6W] #If turned left (Move left)

Sprite Collision

Butler Robots interact with Keen's shots. This destroys the shot but leaves the Butler Robot unchanged.. (See behavior section.)

Keen 1

%patch $17CB {$1E94W}  #Butler Robot collision
%patch $1E9B $3F $0A #Robot stop Keen's shots

End level when two Bots collide

This patch causes the level to end when two Butler Bots collide. it is also possible to have Keen teleport to the

The large segment of code at the patch start is the 15Kb tile space patch that provides 15Kb of patch space for this patch. It is thus incompatible with any other patch using this. (Though not hard to fit into other patches.)

It can be seen that the bot reacts to two sprite types, Keen's shot ($000AW) and itself ($0005W) The first destroys the shot, the second is what causes the level to end. Changing the blue highlighted $0001W to $0002W will cause Keen to teleport to the secret level instead.

It is also possible to modify this patch using game stats to change something other than the level state (What wins the level here, highlighted in brown.)

Keen 1

#Rewrite tile routine to free up 15Kb
%patch $11F80 $06 $1E $50 $A1 $B2 $35 $8E $C0 $A1 $6A $83 $8E $D8 $A4 $A4 $03
              $FA $A4 $A4 $03 $FA $A4 $A4 $03 $FA $A4 $A4 $03 $FA $A4 $A4 $03
              $FA $A4 $A4 $03 $FA $A4 $A4 $03 $FA $A4 $A4 $03 $FA $A4 $A4 $03
              $FA $A4 $A4 $03 $FA $A4 $A4 $03 $FA $A4 $A4 $03 $FA $A4 $A4 $03
              $FA $A4 $A4 $03 $FA $A4 $A4 $03 $FA $A4 $A4 $03 $FA $58 $1F $07
              $C3 $BA $2E $00 $66 $33 $C0 $8B $C3 $66 $8B $D8 $66 $33 $C0 $8B
              $C8 $3D $26 $01 $7D $35 $67 $26 $8B $34 $43 $D1 $E6 $8B $32 $67
              $3B $34 $45 $16 $5B $00 $00 $74 $13 $67 $89 $34 $45 $16 $5B $00
              $00 $67 $8B $3C $45 $C0 $35 $00 $00 $E8 $74 $FF $40 $41 $83 $F9
              $15 $7C $CE $33 $C9 $03 $1E $54 $56 $EB $C6 $CB $BA $2E $00 $66
              $33 $C0 $8B $C3 $66 $8B $D8 $66 $33 $C0 $8B $C8 $3D $26 $01 $7D
              $35 $67 $26 $8B $34 $43 $D1 $E6 $8B $32 $67 $3B $34 $45 $B8 $5D
              $00 $00 $74 $13 $67 $89 $34 $45 $B8 $5D $00 $00 $67 $8B $3C $45
              $C0 $35 $00 $00 $E8 $29 $FF $40 $41 $83 $F9 $15 $7C $CE $33 $C9
              $03 $1E $54 $56 $EB $C6 $CB
%patch $B7B2 $3911W #UpdateFarCall to ADT_0
%patch $B7AA $395CW #UpdateFarCall to ADT_1

#Colliding bots use new code
%patch $17CB $F000W

#New collision code
%patchfile $F000 $55 $8B $EC $8B $5E $06 $81 $3F [$000AW]  {$74} $0E $81 $3F [$0005W]
                 {$75} $10 $C7 $06 {$6C60W}  [$0001W]  $EB $08 $8B $5E $04 $C7 $47 $2A #Change $0001W->$0002W to teleport
                 $0000W  $5D $C3

Misc collision patches

These patches affect Butler Bot collision so that when the Bot collides with anything, be it Keen, shots or other enemies, something will happen. This can make the Bot very powerful, but hard to use. They may also have unintended consequences due to being potentially unstable.

Keen 1

#When Bot hits sprites, Keen goes to map less one life
%patch $17CC $03

Keen 1

#When Bot hits sprites, Keen wins the level
%patch $17CC $04

Keen 1

#When Bot hits sprites, goes to map
%patch $17CC $07


When spawned

%patch $17D0 [$0060W] #Start

In level

%patch $1DD6 [$0058W] #Walking right
%patch $1DDE [$005CW] #Walking left
%patch $1DE8 $03    #And next 3 frames
%patch $1DE4 $05    #Animation speed

%patch $1E87 [$0060W] #Turning
%patch $1E84 $01    #And next frame
%patch $1E80 $05    #Animation speed

Sprite Spawning

This is the initiation and spawning code for the Butler Bot. When created the Butler Bot is given a sprite type of 5, a starting speed of 90 (moving right), a behavior at $1DC7, a collision at $1E94 and finally an initial animation of 96.

Keen 1

#Initiation code: goes to Butler Bot (Code at $1676 + $FC + $5 = $1777)
%patch $1676 $57 $56 $E8 $00FCW  $83 $C4 $04 $EB $6F		

#Butler bot
%patch $1777 $55 $8B $EC $56 $E8 $11B7W  $8B $F0 $C7 $04 [$0005W]  $8B $46 $04 #Sprite type = 5
             $99 $B1 $0C $E8 $C9C4W  $89 $44 $04 $89 $54 $06 $8B $46 $06 $99
             $B1 $0C $E8 $C9B5W  $89 $44 $08 $89 $54 $0A $C7 $44 $20 [$005AW]  #Start speed = $5A
             $8B $44 $06 $8B $54 $04 $3B $06 $E0 $6E $7F $10 $7C $06 $3B $16
             $DE $6E $73 $08 $8B $44 $20 $F7 $D8 $89 $44 $20 $C7 $44 $32
         {$1DC7W}  $C7 $44 $34 {$1E94W}  $C7 $44 $28 [$0060W]  $5E $5D $C3         #Beh 1DC7, death 1E94, start anim $60


These are patches that do not fit into any of the above sections. They may affect other sprites or have unintended side-effects.

Smooth pushing

This path lets the Butler and Tank push Keen smoothly, like the Meep in Keen 3, rather then in jerks as they usually do. Here sound 2 is played on contact (While the bot is pushing Keen) to not play any sound, change the last byte ($41) to $47 (helpful if you don't like annoying noises.)

As you may have noticed, this also affects the Tank bot exactly the same.

Keen 1

#Butler/Tank bots push keen smoothly
%patch $4646 $57 $56 $E8 $EB92W $59 $59 $B8 [$0002W] $EB [$41]