Routines

30380: Control flight of catapult pellet


The address of this routine is placed into a catapult pellet's buffer by the routine at 30555

H Pellet's character number (213 or 214)

30380 2E13 LD L,19
30382 35 DEC (HL) Has the pellet finished travelling?
30383 CACF74 JP Z,29903 Jump if so
30386 7E LD A,(HL)
30387 FE05 CP 5 Does the pellet have fewer than 5 spaces left to travel?
30389 3816 JR C,30413 Jump if so (to check for hittable obstacles)

The pellet is merrily wending its way through the air. It's not ready to hit anything vulnerable yet, or has simply failed to do so. The only thing that can stop it at the moment is a wall, door or window.
30391 2E00 LD L,0
30393 7E LD A,(HL) A=animatory state of pellet
30394 07 RLCA Set carry flag if pellet is travelling towards the right
30395 3F CCF
30396 9F SBC A,A
30397 87 ADD A,A
30398 3C INC A
30399 2C INC L
30400 86 ADD A,(HL) Now A=x-coordinate of location directly in front of pellet
30401 5F LD E,A Store this in E
30402 2C INC L
30403 56 LD D,(HL) And get the pellet's y-coordinate in D
30404 CD5476 CALL 30292 Check for closed doors, windows and walls in the pellet's path
30407 DACF74 JP C,29903 Terminate pellet if there is one
30410 C35072 JP 29264 Otherwise just advance pellet one space

The pellet is ready to hit a vulnerable character, cup or tree.
30413 CD1576 CALL 30229 Has pellet hit a water- or sherry-filled cup?
30416 2011 JR NZ,30435 Jump if not

The pellet has hit a water- or sherry-filled cup, or a conker in the tree. The A register holds the animatory state of the object (drop of water/sherry, or conker) that the pellet will become.
30418 2E12 LD L,18 Place the address of the routine at 29896 into bytes 17 and 18 of the catapult pellet's buffer
30420 3674 LD (HL),116
30422 2D DEC L
30423 36C8 LD (HL),200
30425 F5 PUSH AF Save the new animatory state of the transmuted pellet
30426 CDB461 CALL 25012 Update SRB for pellet's current location
30429 F1 POP AF Restore the transmuted pellet's animatory state
30430 15 DEC D The projectile will ascend two levels
30431 15 DEC D
30432 C33061 JP 24880 Update SRB for projectile's new location

The pellet hasn't hit a water- or sherry-filled cup. Has it hit a teacher?
30435 2E01 LD L,1
30437 5E LD E,(HL) E=pellet's x-coordinate
30438 2C INC L
30439 56 LD D,(HL) D=pellet's y-coordinate
30440 0605 LD B,5 There are 5 teachers who can be hit by a pellet
30442 CDA274 CALL 29858 Has the pellet hit any of these teachers?
30445 202C JR NZ,30491 Jump if not
30447 0E00 LD C,0
30449 0A LD A,(BC) A=animatory state of teacher hit by pellet
30450 E607 AND 7
30452 FE06 CP 6 Is the teacher already sitting on the floor?
30454 201A JR NZ,30482 Jump if not
30456 2E13 LD L,19 Place 6 into byte 19 of the pellet's buffer (the distance the pellet will travel after bouncing off the teacher's head)
30458 77 LD (HL),A

This section of code controls the pellet's motion on its ascent from the teacher's head.
30459 2E13 LD L,19
30461 35 DEC (HL)
30462 CACF74 JP Z,29903 Terminate pellet if time to do so
30465 CD1576 CALL 30229 Has pellet hit a water- or sherry-filled cup?
30468 28CC JR Z,30418 Jump if so
30470 CDB461 CALL 25012 Update SRB for pellet's current location
30473 15 DEC D Has the pellet hit the ceiling on the top floor?
30474 2001 JR NZ,30477 Jump if not (having raised the pellet one level)
30476 14 INC D D=1
30477 CD4677 CALL 30534 Place address 30480 (that of the next instruction) into pellet's buffer
30480 18E9 JR 30459

The pellet has hit a teacher who's standing up.
30482 0E12 LD C,18
30484 0A LD A,(BC) A=byte 18 of buffer of teacher hit by pellet
30485 C5 PUSH BC
30486 A7 AND A
30487 CA1F75 JP Z,29983 Jump if this teacher can be knocked over
30490 C1 POP BC

The pellet hasn't hit any liquid-containing cups or vulnerable teachers. Has it hit any kids?
30491 16CE LD D,206 206=BOY WANDER
30493 0605 LD B,5 There are 5 kids who can be knocked over
30495 CDAC6C CALL 27820 Has the pellet hit any of them?
30498 D24278 JP NC,30786 Knock them down if so

The pellet hasn't hit any liquid-containing cups, teachers or kids. Has it hit a conker in the tree?
30501 2E13 LD L,19
30503 7E LD A,(HL) A=byte 19 of pellet's character buffer
30504 3D DEC A
30505 CAB776 JP Z,30391
30508 2E02 LD L,2
30510 7E LD A,(HL) A=pellet's y-coordinate
30511 FE04 CP 4 Was the pellet fired on the top floor?
30513 3009 JR NC,30524 Jump if not
30515 2D DEC L
30516 7E LD A,(HL) A=pellet's x-coordinate
30517 FE80 CP 128
30519 3003 JR NC,30524
30521 FE60 CP 96
30523 3F CCF
30524 D2B776 JP NC,30391 Jump unless the pellet will knock a conker out of the tree
30527 3E37 LD A,55 55: animatory state of conker
30529 C3D276 JP 30418