Prev: 46285 Up: Map Next: 46458
46289: Throw Weapon
Throws a weapon that Sabreman is carrying. Nothing happens if bit 0 of the redraw flags of Sabreman is set or if he is not carrying a weapon (one of the types 104 to 107 in the three slots from Weapon_Slots).
One weapon at a time is thrown unless the counter in Fire_Key_Flag allows another: the counter is reset while both weapon records are empty, and while a weapon is in flight it goes up each time this routine is called, so a weapon is thrown only when its low three bits are zero.
The weapon record is a free one of the two records at Object_Records and Second_Weapon_Record. The type, the position and the attribute are copied from Sabreman. The type of the weapon is then changed to the type of the projectile for the weapon that was carried (from the table at Weapon_Projectile_Types), plus one if it is thrown to the left. The weapon starts 8 pixels to the side of Sabreman and 8 pixels higher, with an x velocity between 64 and 127 and an upward y velocity that comes from the frame counter. Bit 2 of the type of Sabreman, less one (or less two if his type is 21 or more), tells which way he is facing (set for the right). The weapon is not thrown if there is no room to its left.
Input
IX Object record of Sabreman
Throw_Weapon 46289 LD A,(36649) Fetch the redraw flags of Sabreman.
46292 AND %00000001 Keep only bit 0.
46294 RET NZ Return if Sabreman has only just appeared in the room (bit 0 is set).
46295 LD HL,36587 Point HL at the first of the three slots that hold the items that Sabreman carries.
46298 LD B,3 Set a counter in B for the three slots.
Throw_Weapon_Find_Weapon 46300 LD A,(HL) Fetch the type of the item.
46301 AND %11111100 Reset the two low bits.
46303 CP 104 Jump to Throw_Weapon_Found if the item is a weapon.
46305 JR Z,Throw_Weapon_Found
46307 INC HL Move on to the next slot.
46308 DJNZ Throw_Weapon_Find_Weapon Decrease the slot counter and loop back for the next slot.
46310 RET Return, as Sabreman has no weapon.
Throw_Weapon_Found 46311 LD C,(HL) Fetch the type of the weapon into C.
46312 LD A,(36602) Fetch the type of the first weapon record into B.
46315 LD B,A
46316 LD A,(36618) Combine it with the type of the second weapon record, and jump to Throw_Weapon_Store_Counter if both of the records are empty.
46319 OR B
46320 JR Z,Throw_Weapon_Store_Counter
46322 LD A,(43691) Fetch the fire key flag.
46325 INC A Increase it.
Throw_Weapon_Store_Counter 46326 LD (43691),A Store the counter.
46329 AND %00000111 Keep only the low three bits.
46331 RET NZ Return unless they are zero (a weapon can only be thrown on one pass in eight).
46332 LD DE,36602 Point DE at Object_Records.
46335 LD A,(DE) Fetch its type.
46336 AND A Jump to Throw_Weapon_Copy_Position if the record is empty.
46337 JR Z,Throw_Weapon_Copy_Position
46339 LD DE,36618 Point DE at Second_Weapon_Record.
46342 LD A,(DE) Fetch its type.
46343 AND A Return if the record is in use too.
46344 RET NZ
Throw_Weapon_Copy_Position 46345 LD HL,36634 Point HL at the record of Sabreman.
46348 PUSH BC Stash the type of the weapon.
46349 LD BC,6 Set the number of bytes to copy to 6.
46352 PUSH DE Stash the address of the weapon record.
46353 LDIR Copy the type, the position and the attribute of Sabreman to the weapon record.
46355 POP HL Restore the address of the weapon record to HL.
46356 POP BC Restore the type of the weapon to C.
46357 LD A,(23672) Fetch the low byte of the frame counter.
46360 LD B,A Store it in B.
46361 LD A,(36566) Fetch the tick counter.
46364 ADD A,B Add the low byte of the frame counter.
46365 AND %01111111 Keep only the low seven bits.
46367 OR %01000000 Set bit 6.
46369 LD B,A Store the result in B, to use as the x velocity of the weapon.
46370 LD A,C Fetch the type of the weapon.
46371 AND %00000011 Keep only the two low bits.
46373 LD DE,46931 Point DE at Weapon_Projectile_Types.
46376 ADD A,E Add the weapon number to the address.
46377 LD E,A
46378 LD A,D
46379 ADC A,0
46381 LD D,A
46382 LD A,(DE) Fetch the type of the projectile into C.
46383 LD C,A
46384 LD A,(IX+0) Fetch the type of Sabreman.
46387 CP 21 Jump to Adjust_Throw_Facing if the type is 21 or more.
46389 JR NC,Adjust_Throw_Facing
46391 DEC A Subtract one from the type.
This entry point is used by the routine at Adjust_Throw_Facing.
Throw_Weapon_Test_Facing 46392 INC HL Move to the x position in the weapon record.
46393 LD DE,3 Set DE to 3.
46396 AND %00000100 Test which way Sabreman is facing (bit 2 of the type that was worked out).
46398 LD A,(HL) Fetch the x position.
46399 JR Z,Throw_Weapon_Face_Left Jump to Throw_Weapon_Face_Left if Sabreman is facing left.
46401 ADD A,8 Add 8 to start the weapon on his right.
46403 JR Throw_Weapon_Store_Position Jump to Throw_Weapon_Store_Position.
Throw_Weapon_Face_Left 46405 SUB 8 Jump to Throw_Weapon_Cancel if the x position would be below zero.
46407 JR C,Throw_Weapon_Cancel
46409 PUSH AF Invert the x velocity in B, so that it is negative.
46410 LD A,B
46411 CPL
46412 LD B,A
46413 POP AF
46414 INC C Use the next projectile type, for a weapon that travels to the left.
Throw_Weapon_Store_Position 46415 LD (HL),A Store the x position.
46416 DEC HL Move back to the type.
46417 LD (HL),C Store the type of the projectile.
46418 INC HL Move to the y position.
46419 INC HL
46420 INC HL
46421 LD A,(HL) Fetch the y position.
46422 SUB 8 Subtract 8.
46424 LD (HL),A Store the y position.
46425 ADD HL,DE Move to byte 6 of the record.
46426 LD (HL),0 Clear byte 6 of the record.
46428 INC HL Move to the x velocity.
46429 INC HL
46430 LD (HL),B Store the x velocity.
46431 INC HL Move to the y velocity.
46432 LD A,(23672) Fetch the low byte of the frame counter.
46435 RLA Multiply it by four.
46436 RLA
46437 AND %01111111 Keep only the low seven bits.
46439 NEG Negate it, to make an upward velocity.
46441 LD (HL),A Store the y velocity.
46442 LD A,(36645) Fetch the contact flags of Sabreman.
46445 INC HL Move to the contact flags.
46446 INC HL
46447 LD (HL),A Store the contact flags.
46448 LD E,4 Set E to 4.
46450 ADD HL,DE Move to the redraw flags.
46451 LD (HL),1 Set bit 0 of the redraw flags, so that the weapon is drawn without being erased first.
46453 RET Return.
Throw_Weapon_Cancel 46454 DEC HL Move back to the type.
46455 LD (HL),0 Empty the weapon record.
46457 RET Return.
Prev: 46285 Up: Map Next: 46458