Prev: B065 Up: Map Next: B11D
B0D1: Test Target Range
Used by the routines at Handler_SidewaysMissile and Handler_AlienBasePlasma.
Return carry if this actor is close enough to its target: Jetman when he is riding the rover, otherwise the parked rover. The world X difference is scaled by 08 and must be less than 00C0 and the target must be 00-1F below the actor.
Input
IX Actor slot
Handler_Missile_TestJetmanRange B0D1 LD A,($6078) Fetch Jetman_Slot.
Types 12-19 are Jetman seated on the rover; use his slot. Otherwise use the rover slot when its type is in 1A-29.
B0D4 SUB $12 Subtract 12.
B0D6 CP $08 Jump to Handler_Missile_FetchJetman if Jetman is seated.
B0D8 JR C,Handler_Missile_FetchJetman
B0DA LD A,($6090) Fetch Rover_Slot.
B0DD SUB $1A Subtract 1A.
B0DF CP $10 Jump to Handler_Missile_OutOfRange if that is not a rover frame.
B0E1 JR NC,Handler_Missile_OutOfRange
B0E3 LD HL,($6092) Fetch Rover_Position.
B0E6 LD A,($6094) Fetch the rover Y.
B0E9 LD C,A Stash it in C.
Scale both world X values and test the horizontal range.
Handler_Missile_ScaleTargetX B0EA ADD HL,HL Multiply the target world X by 08.
B0EB ADD HL,HL
B0EC ADD HL,HL
B0ED LD E,(IX+$02) Fetch the actor world X.
B0F0 LD D,(IX+$03) Fetch the high byte.
B0F3 EX DE,HL Switch the pairs.
B0F4 ADD HL,HL Multiply the actor world X by 08.
B0F5 ADD HL,HL
B0F6 ADD HL,HL
Take the absolute horizontal distance between the two scaled X values.
B0F7 AND A Subtract the target world X.
B0F8 SBC HL,DE
B0FA LD A,H Fetch the high byte of the difference.
B0FB AND A Jump to Handler_Missile_SubtractRange if the result is positive.
B0FC JP P,Handler_Missile_SubtractRange
B0FF CALL NegateHL Call NegateHL.
Return unless the actor is within the horizontal range.
Handler_Missile_SubtractRange B102 LD DE,$00C0 DE=00C0.
B105 AND A Subtract the range.
B106 SBC HL,DE
B108 RET NC Return if the actor is too far away.
Test the vertical distance to the target.
B109 LD A,(IX+$04) Fetch the actor Y.
B10C SUB C Subtract the target Y.
B10D NEG Negate the difference.
B10F CP $20 Compare it against 20.
B111 RET Return.
Use Jetman's position as the target when he is seated.
Handler_Missile_FetchJetman B112 LD HL,($607A) Fetch Jetman_Position.
B115 LD A,($607C) Fetch Jetman_Y.
B118 LD C,A Stash it in C.
B119 JR Handler_Missile_ScaleTargetX Jump to Handler_Missile_ScaleTargetX.
Handler_Missile_OutOfRange B11B AND A Return with the carry flag clear.
B11C RET
Prev: B065 Up: Map Next: B11D