Prev: 929C Up: Map Next: 92EE
92B4: Choose Target
Used by the routine at UpdateChasingObject.
Looks through the first seven enemy slots for the active object with the highest priority and stores the number of its slot in the top four bits of the second set of flags of the object in IX. The priority of each type of object comes from the table at TargetPriorities.
Input
IX Address of the object that is choosing
ChooseTarget 92B4 LD IY,$9974 Use the first enemy slot.
92B8 LD B,$07 Set a counter for seven slots.
92BA XOR A Clear the highest priority so far.
92BB LD ($5C1C),A
ChooseTarget_Loop 92BE BIT 7,(IY+$10) Jump to ChooseTarget_Next if bit 7 of the flags of the object in the slot is clear.
92C2 JR Z,ChooseTarget_Next
92C4 LD A,(IY+$00) Fetch the type of the object.
92C7 INC A Increment it.
92C8 JR Z,ChooseTarget_Next Jump to ChooseTarget_Next if the slot is free.
92CA SUB $14 Subtract 14, which leaves the type minus 13 as the type has been incremented.
92CC LD HL,$92EE Use the table at TargetPriorities.
92CF CALL AddAToHL Add the offset to the address.
92D2 LD A,($5C1C) Fetch the highest priority so far from ScratchValue.
92D5 CP (HL) Compare it with the priority of this type.
92D6 JR NC,ChooseTarget_Next Jump to ChooseTarget_Next if it is not lower.
92D8 LD A,(HL) Fetch the priority of this type.
92D9 LD ($5C1C),A Make it the highest priority so far.
92DC LD A,B Fetch the slot counter.
92DD XOR %00000111 Turn it into the number of the slot.
92DF ADD A,A Shift the number into the top four bits.
92E0 ADD A,A
92E1 ADD A,A
92E2 ADD A,A
92E3 LD (IX+$17),A Store it in the second set of flags of the object.
ChooseTarget_Next 92E6 LD DE,$0018 Set the length of a slot.
92E9 ADD IY,DE Move on to the next slot.
92EB DJNZ ChooseTarget_Loop Decrease the slot counter by one and loop back to ChooseTarget_Loop until none remain.
92ED RET Return.
Prev: 929C Up: Map Next: 92EE