![]() |
Routines |
| Prev: 37532 | Up: Map | Next: 37614 |
|
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.
|
||||||||
| ChooseTarget | 37556 | LD IY,39284 | Use the first enemy slot. | |||||
| 37560 | LD B,7 | Set a counter for seven slots. | ||||||
| 37562 | XOR A | Clear the highest priority so far. | ||||||
| 37563 | LD (23580),A | |||||||
| ChooseTarget_Loop | 37566 | BIT 7,(IY+16) | Jump to ChooseTarget_Next if bit 7 of the flags of the object in the slot is clear. | |||||
| 37570 | JR Z,ChooseTarget_Next | |||||||
| 37572 | LD A,(IY+0) | Fetch the type of the object. | ||||||
| 37575 | INC A | Increment it. | ||||||
| 37576 | JR Z,ChooseTarget_Next | Jump to ChooseTarget_Next if the slot is free. | ||||||
| 37578 | SUB 20 | Subtract 20, which leaves the type minus 19 as the type has been incremented. | ||||||
| 37580 | LD HL,37614 | Use the table at TargetPriorities. | ||||||
| 37583 | CALL AddAToHL | Add the offset to the address. | ||||||
| 37586 | LD A,(23580) | Fetch the highest priority so far from ScratchValue. | ||||||
| 37589 | CP (HL) | Compare it with the priority of this type. | ||||||
| 37590 | JR NC,ChooseTarget_Next | Jump to ChooseTarget_Next if it is not lower. | ||||||
| 37592 | LD A,(HL) | Fetch the priority of this type. | ||||||
| 37593 | LD (23580),A | Make it the highest priority so far. | ||||||
| 37596 | LD A,B | Fetch the slot counter. | ||||||
| 37597 | XOR %00000111 | Turn it into the number of the slot. | ||||||
| 37599 | ADD A,A | Shift the number into the top four bits. | ||||||
| 37600 | ADD A,A | |||||||
| 37601 | ADD A,A | |||||||
| 37602 | ADD A,A | |||||||
| 37603 | LD (IX+23),A | Store it in the second set of flags of the object. | ||||||
| ChooseTarget_Next | 37606 | LD DE,24 | Set the length of a slot. | |||||
| 37609 | ADD IY,DE | Move on to the next slot. | ||||||
| 37611 | DJNZ ChooseTarget_Loop | Decrease the slot counter by one and loop back to ChooseTarget_Loop until none remain. | ||||||
| 37613 | RET | Return. | ||||||
| Prev: 37532 | Up: Map | Next: 37614 |