Prev: B3DA Up: Map Next: B484
B420: Create Outlaw
Used by the routine at CreateTownObjects.
Called every frame in the town. Puts the outlaw (an object of type 0A or 16) in a random cell of the town in the fifth object slot if the slot is free and the cell is not blocked. The outlaw is made faster, and given type 16, if a random number is less than sixteen times the level (the level is reduced by four from level sixteen).
CreateOutlaw B420 LD DE,$A2BD Point DE at ObjectSlot_05.
B423 LD A,(DE) Fetch the type of the object in the slot.
B424 AND A Test whether the slot is in use.
B425 RET NZ Return if it is.
B426 PUSH DE Copy DE to IY (using the stack).
B427 POP IY
B429 LD HL,$B484 Point HL at OutlawTemplate.
B42C LD BC,$0010 Set the size of an object slot in BC.
B42F LDIR Copy the template into the slot.
Choose a random cell.
B431 LD A,($A218) Keep a random horizontal cell from 00 to 0F in L.
B434 AND %00001111
B436 LD L,A
B437 LD A,($A219) Keep a random vertical cell from 00 to 0F in H.
B43A AND %00001111
B43C LD H,A
B43D LD (IY+$02),L Set the horizontal cell of the outlaw.
B440 LD (IY+$04),H Set the vertical cell of the outlaw.
B443 CALL GetMapCell Check whether the cell is blocked.
B446 CP $01 Return if the cell is blocked.
B448 RET Z
Choose the outlaw.
B449 LD A,($A260) Fetch the level.
B44C LD HL,$B494 Point HL at OutlawNumbers.
B44F CALL AddAToHL Point HL at the number for the level.
B452 LD A,(HL) Fetch the number of the outlaw.
B453 LD (IY+$0A),A Set it in the object.
B456 LD (IY+$00),$0A Make the slot an outlaw.
Choose how fast the outlaw moves.
B45A LD A,($A21A) Fetch a random number.
B45D AND %00000110 Keep bits 1 and 2.
B45F ADD A,$02 Add two to give a speed of two, four, six or eight.
B461 LD (IY+$05),A Set the speed of the outlaw.
B464 LD A,($A260) Fetch the level.
B467 CP $10 Jump to CreateOutlaw_MultiplyLevel if the level is below 10.
B469 JR C,CreateOutlaw_MultiplyLevel
B46B SUB $04 Take four off the level.
CreateOutlaw_MultiplyLevel B46D RLCA Multiply the level by sixteen.
B46E RLCA
B46F RLCA
B470 RLCA
B471 LD C,A Keep the level times sixteen in C.
B472 LD A,($A21B) Fetch another random number.
B475 CP C Return if it is not smaller than the number worked out from the level.
B476 RET NC
B477 LD A,(IY+$05) Fetch the speed of the outlaw.
B47A ADD A,$08 Add eight.
B47C LD (IY+$05),A Set the speed of the outlaw.
B47F LD (IY+$00),$16 Make the slot a faster outlaw.
B483 RET Return.
Prev: B3DA Up: Map Next: B484