Prev: 46042 Up: Map Next: 46212
46112: Create Outlaw
Used by the routine at CreateTownObjects.
Called every frame in the town. Puts the outlaw (an object of type 10 or 22) 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 22, if a random number is less than sixteen times the level (the level is reduced by four from level sixteen).
CreateOutlaw 46112 LD DE,41661 Point DE at ObjectSlot_05.
46115 LD A,(DE) Fetch the type of the object in the slot.
46116 AND A Test whether the slot is in use.
46117 RET NZ Return if it is.
46118 PUSH DE Copy DE to IY (using the stack).
46119 POP IY
46121 LD HL,46212 Point HL at OutlawTemplate.
46124 LD BC,16 Set the size of an object slot in BC.
46127 LDIR Copy the template into the slot.
Choose a random cell.
46129 LD A,(41496) Keep a random horizontal cell from 0 to 15 in L.
46132 AND %00001111
46134 LD L,A
46135 LD A,(41497) Keep a random vertical cell from 0 to 15 in H.
46138 AND %00001111
46140 LD H,A
46141 LD (IY+2),L Set the horizontal cell of the outlaw.
46144 LD (IY+4),H Set the vertical cell of the outlaw.
46147 CALL GetMapCell Check whether the cell is blocked.
46150 CP 1 Return if the cell is blocked.
46152 RET Z
Choose the outlaw.
46153 LD A,(41568) Fetch the level.
46156 LD HL,46228 Point HL at OutlawNumbers.
46159 CALL AddAToHL Point HL at the number for the level.
46162 LD A,(HL) Fetch the number of the outlaw.
46163 LD (IY+10),A Set it in the object.
46166 LD (IY+0),10 Make the slot an outlaw.
Choose how fast the outlaw moves.
46170 LD A,(41498) Fetch a random number.
46173 AND %00000110 Keep bits 1 and 2.
46175 ADD A,2 Add two to give a speed of two, four, six or eight.
46177 LD (IY+5),A Set the speed of the outlaw.
46180 LD A,(41568) Fetch the level.
46183 CP 16 Jump to CreateOutlaw_MultiplyLevel if the level is below 16.
46185 JR C,CreateOutlaw_MultiplyLevel
46187 SUB 4 Take four off the level.
CreateOutlaw_MultiplyLevel 46189 RLCA Multiply the level by sixteen.
46190 RLCA
46191 RLCA
46192 RLCA
46193 LD C,A Keep the level times sixteen in C.
46194 LD A,(41499) Fetch another random number.
46197 CP C Return if it is not smaller than the number worked out from the level.
46198 RET NC
46199 LD A,(IY+5) Fetch the speed of the outlaw.
46202 ADD A,8 Add eight.
46204 LD (IY+5),A Set the speed of the outlaw.
46207 LD (IY+0),22 Make the slot a faster outlaw.
46211 RET Return.
Prev: 46042 Up: Map Next: 46212