Prev: 29091 Up: Map Next: 29305
29144: Create Actor
Used by the routine at NextActor.
Creates a new actor from the pantry, if the conditions are right. It is not done if six or more actors are in play, if the delay at the start of a life is running, if no more ingredients are needed, or if Charlie is not in his normal form (ID 1 or 2). It is also done on average only one pass in every 32 which is decided with the frame counter and a random number. The new actor is made from the template at Template_NewActor, in the first of the six slots from ActorSpawnSlots which is empty. It starts at the right, at the height of the shelf in the pantry for the level (47 71 95 119 or 143).
Usually it is the ingredient for the level (see IntroductionIngredients), but it is one of the nasties (the tack, the washer or the bolt) if the number of slots which are left (including this one) is not more than the set the level is in (up to a maximum of 4) plus one. So there are more nasties in the later sets of levels. The monster is also created by CreateMonster, if it is not already.
CreateActor 29144 LD A,(24347) Fetch the number of actors in play.
29147 CP 6 Jump to CreateActor_Finished if there are six actors in play.
29149 JR NC,CreateActor_Finished
29151 LD A,(24349) Fetch the frame counter and keep it in B.
29154 LD B,A
29155 LD A,R Fetch a random number.
29157 ADD A,B Add the frame counter.
29158 AND %00011111 Keep only bits 0-4.
29160 JR NZ,CreateActor_Finished Jump to CreateActor_Finished if the result is not zero.
29162 LD A,(24357) Fetch the game delay timer.
29165 AND A Is the delay at the start of a life still running?
29166 JR NZ,CreateActor_Finished Jump to CreateActor_Finished if it is.
29168 LD A,(24367) Fetch the number of ingredients which the active player needs.
29171 AND A Are any more ingredients needed?
29172 JR Z,CreateActor_Finished Jump to CreateActor_Finished if not.
29174 LD A,(24373) Fetch Charlie's ID.
29177 AND %00111111 Keep only bits 0-5.
29179 DEC A Is Charlie's ID 1?
29180 JR Z,CreateActor_FindSlot Jump to CreateActor_FindSlot if Charlie's ID is 1.
29182 DEC A Is Charlie's ID 2?
29183 JR NZ,CreateActor_Finished Jump to CreateActor_Finished if Charlie's ID is not 2.
Find the first empty slot out of the six.
CreateActor_FindSlot 29185 LD HL,24405 Point HL at the first slot for spawned actors.
29188 LD B,6 Set the slot counter to 6 (the number of slots).
29190 LD DE,8 Set the size of an actor to 8.
CreateActor_FindSlotLoop 29193 LD A,(HL) Fetch the actor ID.
29194 AND A Is the slot empty?
29195 JP Z,CreateActor_Create Jump to CreateActor_Create if it is.
29198 ADD HL,DE Move on to the next slot.
29199 DJNZ CreateActor_FindSlotLoop Decrease the slot counter by one and loop back to CreateActor_FindSlotLoop until all of the slots have been tried.
CreateActor_Finished 29201 JP MainLoop_NewPass Jump to MainLoop_NewPass.
Make the new actor from the template.
CreateActor_Create 29204 EX DE,HL Point DE at the empty slot.
29205 LD HL,29305 Point HL at Template_NewActor.
29208 PUSH BC Save the slot counter on the stack.
29209 LD BC,8 Set the number of bytes to copy to 8.
29212 PUSH DE Save the address of the slot on the stack.
29213 LDIR Copy the template into the slot.
29215 POP IX Point IX at the new actor.
29217 LD A,8 A=8.
29219 LD (IX+0),A Update the actor ID.
Work out the height of the shelf in the pantry for the level; it is 47 + ((24 * the level within the set) AND 120).
29222 LD A,(24365) Fetch the level of the active player.
29225 AND %00000111 Keep only bits 0-2.
29227 LD C,A Keep the level within the set in C.
29228 SLA A Multiply the level within the set by two.
29230 ADD A,C Add the level within the set, to multiply it by three.
29231 RLA Rotate left three times, to multiply it by eight.
29232 RLA
29233 RLA
29234 AND %01111000 Keep only bits 3-6.
29236 ADD A,47 Add 47 to get the height of the shelf.
29238 LD (IX+2),A Set the vertical co-ordinate to the height of the shelf.
Use the ID and the colour of the ingredient for the level.
29241 LD HL,28029 Point HL at IntroductionIngredients.
29244 SLA C Multiply the level within the set by two.
29246 LD B,0 Set the high byte of the offset to 0.
29248 ADD HL,BC Find the ingredient for the level.
29249 LD A,(HL) Fetch the sprite ID of the ingredient.
29250 LD (IX+0),A Update the actor ID.
29253 INC HL Move on to the colour.
29254 LD A,(HL) Fetch the colour of the ingredient.
29255 LD (IX+3),A Update the actor colour.
Decide whether to make it one of the nasties.
29258 LD A,(24365) Fetch the level of the active player.
29261 SRL A Divide the level by eight, to get the set of levels.
29263 SRL A
29265 SRL A
29267 POP BC Restore the slot counter from the stack.
29268 CP 4 Jump to CreateActor_TestNasty if the set is less than 4.
29270 JR C,CreateActor_TestNasty
29272 LD A,4 Limit the set to 4.
CreateActor_TestNasty 29274 INC A Add 1.
29275 SUB B Subtract the slot counter.
29276 JP M,CreateActor_Draw Jump to CreateActor_Draw if this is an ingredient.
29279 LD A,R Fetch a random number.
29281 AND %00000011 Keep only bits 0-1.
29283 JR NZ,CreateActor_Nasty Jump to CreateActor_Nasty if the result is not zero.
29285 INC A Increase A by one, so it is in the range 1 to 3.
CreateActor_Nasty 29286 SLA A Multiply the result by two.
29288 ADD A,28 Add 28 to get the ID of the tack (30), the washer (32) or the bolt (34).
29290 LD (IX+0),A Update the actor ID.
29293 LD (IX+3),69 Set the actor colour to 69 (cyan).
CreateActor_Draw 29297 CALL DrawEntity Draw the actor using DrawEntity.
29300 CALL CreateMonster Create the monster using CreateMonster.
29303 JR CreateActor_Finished Jump to CreateActor_Finished.
Prev: 29091 Up: Map Next: 29305