Routines
 Prev: 25306 Up: Map Next: 25385
25307: Control the sniper
Used by the command list at 64890. Checks whether conditions are right for the sniper to appear, and if they are, hands over control to the interruptible subcommand routine at 25118.
Input
H 227 (sniper)
25307 LD A,(32767) 32767 holds the y-coordinate of the topmost row of the play area on screen
25310 CP 20 Is the sidewalk on screen at the moment?
25312 RET NZ Return if not
25313 LD A,(32764) Collect Sam's status flags from 32764
25316 AND 129 Is Sam being carried or falling from a building at the moment?
25318 RET NZ Return if so
25319 LD L,3 Set bit 7 of byte 3 of the sniper's buffer, making him move quickly
25321 SET 7,(HL)
25323 LD L,10 Decrement and then collect byte 10 of the sniper's buffer
25325 DEC (HL)
25326 LD A,(HL)
25327 AND 15 Are any of bits 0-3 set?
25329 RET NZ Return if so (15 times out of 16)
Now we check how many keys Sam has collected. The exact number in Sam's possession affects the probability that the sniper will appear.
25330 LD A,(32746) Collect the key inventory flags from 32746
25333 LD B,31 B=31 if Sam has no keys or one key, 63 if he has two keys, 127 if he has three, or 255 if he has all four
25336 JR Z,25344
25338 JR NC,25335
25340 RL B
25342 JR 25335
25344 CALL 61823 Get a random number in A
25347 CP B Is A>=B?
25348 RET NC Return if so
The dice are telling us that the sniper should appear. But can we find a suitable spot for him?
25349 LD DE,25106 Point DE at the table of potential x-coordinates for the sniper at 25106
25352 LD L,1 Point HL at byte 1 of the sniper's buffer
25354 LD B,7 There are 7 entries in the table
25356 LD A,(DE) A=potential x-coordinate for the sniper
25357 INC E Point DE at the next potential x-coordinate
25358 LD (HL),A Set the sniper's x-coordinate for testing
25359 CALL 26330 Would this bring the sniper on screen no less than 8 x-coordinates away from Sam?
25362 JR Z,25367 Jump if so
25364 DJNZ 25356 Otherwise consider the next potential x-coordinate
25366 RET
We have found a suitable place for the sniper to emerge from.
25367 LD L,17 Byte 17 of the sniper's buffer is used to regulate the delay between shots; initialise it to 0
25369 LD (HL),A
25370 DEC L L=16
25371 CALL 61823 Get a random number in A
25374 AND 15 Byte 16 of the sniper's buffer is used to decide when to duck and when to shoot; initialise it to a number between 10 and 25