Prev: 45157 Up: Map Next: 45341
45265: 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 8 and must be less than 0192 and the target must be 0-31 below the actor.
Input
IX Actor slot
Handler_Missile_TestJetmanRange 45265 LD A,(24696) Fetch Jetman_Slot.
Types 18-25 are Jetman seated on the rover; use his slot. Otherwise use the rover slot when its type is in 26-41.
45268 SUB 18 Subtract 18.
45270 CP 8 Jump to Handler_Missile_FetchJetman if Jetman is seated.
45272 JR C,Handler_Missile_FetchJetman
45274 LD A,(24720) Fetch Rover_Slot.
45277 SUB 26 Subtract 26.
45279 CP 16 Jump to Handler_Missile_OutOfRange if that is not a rover frame.
45281 JR NC,Handler_Missile_OutOfRange
45283 LD HL,(24722) Fetch Rover_Position.
45286 LD A,(24724) Fetch the rover Y.
45289 LD C,A Stash it in C.
Scale both world X values and test the horizontal range.
Handler_Missile_ScaleTargetX 45290 ADD HL,HL Multiply the target world X by 8.
45291 ADD HL,HL
45292 ADD HL,HL
45293 LD E,(IX+2) Fetch the actor world X.
45296 LD D,(IX+3) Fetch the high byte.
45299 EX DE,HL Switch the pairs.
45300 ADD HL,HL Multiply the actor world X by 8.
45301 ADD HL,HL
45302 ADD HL,HL
Take the absolute horizontal distance between the two scaled X values.
45303 AND A Subtract the target world X.
45304 SBC HL,DE
45306 LD A,H Fetch the high byte of the difference.
45307 AND A Jump to Handler_Missile_SubtractRange if the result is positive.
45308 JP P,Handler_Missile_SubtractRange
45311 CALL NegateHL Call NegateHL.
Return unless the actor is within the horizontal range.
Handler_Missile_SubtractRange 45314 LD DE,192 DE=0192.
45317 AND A Subtract the range.
45318 SBC HL,DE
45320 RET NC Return if the actor is too far away.
Test the vertical distance to the target.
45321 LD A,(IX+4) Fetch the actor Y.
45324 SUB C Subtract the target Y.
45325 NEG Negate the difference.
45327 CP 32 Compare it against 32.
45329 RET Return.
Use Jetman's position as the target when he is seated.
Handler_Missile_FetchJetman 45330 LD HL,(24698) Fetch Jetman_Position.
45333 LD A,(24700) Fetch Jetman_Y.
45336 LD C,A Stash it in C.
45337 JR Handler_Missile_ScaleTargetX Jump to Handler_Missile_ScaleTargetX.
Handler_Missile_OutOfRange 45339 AND A Return with the carry flag clear.
45340 RET
Prev: 45157 Up: Map Next: 45341