Prev: C63B Up: Map Next: C70E
C65C: Update Task Three Helpers
Used by the routine at Update_Task_Three_Entities.
Update Task Three Helpers for the current Thing Upstairs task.
Update_Task_Three_Helpers C65C LD IX,$8F13 Point IX at the first Slimies entity (StateData_Complex_03).
C660 LD DE,$000E Each entity record is 000E bytes long, then load that length into DE.
C663 LD B,$04 Load B with 04 as a loop counter.
Scan each upstairs helper: skip inactive / low slots, then randomly wander, climb, or drop a room.
Update_Task_Three_Helpers_Scan C665 PUSH BC Stash BC on the stack.
C666 LD A,(IX+$01) Load A with the current entity's flags byte 1.
C669 AND %11100000 Keep only the top bits E0 of the flag/coordinate in A.
C66B JR NZ,Update_Task_Three_Helpers_AdvanceSlot If the result was non-zero, jump to Update_Task_Three_Helpers_AdvanceSlot.
C66D LD A,(IX+$06) Load A with the current entity's y-extent.
C670 CP $22 Is the current entity's y-extent less than 22? If so, jump to Update_Task_Three_Helpers_AdvanceSlot.
C672 JR C,Update_Task_Three_Helpers_AdvanceSlot
C674 BIT 7,(IX+$00) Is bit 07 of the current entity's entity type set? If not, call Update_Task_Three_Helpers_MaybeSetFlagBit2.
C678 CALL Z,Update_Task_Three_Helpers_MaybeSetFlagBit2
C67B LD A,$15 Load A with 15.
C67D CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
C680 OR A Is 15 zero? If so, jump to Update_Task_Three_Helpers_ClearTypeBit7.
C681 JR Z,Update_Task_Three_Helpers_ClearTypeBit7
C683 CP $06 Is 15 less than 06? If so, jump to Update_Task_Three_Helpers_TryMoveLeft.
C685 JR C,Update_Task_Three_Helpers_TryMoveLeft
C687 CP $0B Is 15 less than 0B? If so, jump to Update_Task_Three_Helpers_TryMoveRight.
C689 JR C,Update_Task_Three_Helpers_TryMoveRight
C68B CP $10 Is 15 less than 10? If so, jump to Update_Task_Three_Helpers_MoveRoomDown.
C68D JR C,Update_Task_Three_Helpers_MoveRoomDown
C68F LD A,(IX+$04) Load A with the current entity's room index.
C692 CP $05 Is the current entity's room index equal to 05? If so, jump to Update_Task_Three_Helpers_AdvanceSlot.
C694 JR Z,Update_Task_Three_Helpers_AdvanceSlot
C696 INC (IX+$05) Move this entity one character down.
C699 INC (IX+$06)
C69C INC (IX+$04) Advance this entity into the next room.
C69F JR Update_Task_Three_Helpers_AdvanceSlot Jump to Update_Task_Three_Helpers_AdvanceSlot to advance to the next helper entity.
Move this helper up one room (unless already in room 01).
Update_Task_Three_Helpers_MoveRoomDown C6A1 LD A,(IX+$04) Load A with the current entity's room index.
C6A4 CP $01 Is the current entity's room index equal to 01? If so, jump to Update_Task_Three_Helpers_AdvanceSlot.
C6A6 JR Z,Update_Task_Three_Helpers_AdvanceSlot
C6A8 DEC (IX+$05) Move this entity one character up.
C6AB DEC (IX+$06)
C6AE DEC (IX+$04) Move this entity back one room.
C6B1 JR Update_Task_Three_Helpers_AdvanceSlot Jump to Update_Task_Three_Helpers_AdvanceSlot to advance to the next helper entity.
Try a left wander step, respecting the high-X and low-X bounds.
Update_Task_Three_Helpers_TryMoveLeft C6B3 LD A,(IX+$07) Load A with the current entity's x-coordinate.
C6B6 CP $E0 Is the current entity's x-coordinate less than E0? If so, jump to Update_Task_Three_Helpers_LeftBoundCheck.
C6B8 JR C,Update_Task_Three_Helpers_LeftBoundCheck
C6BA CP $E4 Is the current entity's x-coordinate less than E4? If so, jump to Update_Task_Three_Helpers_AdvanceSlot.
C6BC JR C,Update_Task_Three_Helpers_AdvanceSlot
C6BE JR Update_Task_Three_Helpers_DecX Jump to Update_Task_Three_Helpers_DecX to decrease the helper's x-coordinate.
Left-bound check: below 43 step right instead of left.
Update_Task_Three_Helpers_LeftBoundCheck C6C0 CP $43 Is the current entity's x-coordinate less than 43? If so, jump to Update_Task_Three_Helpers_IncX.
C6C2 JR C,Update_Task_Three_Helpers_IncX
Nudge the helper one character left.
Update_Task_Three_Helpers_DecX C6C4 DEC (IX+$07) Move this entity one character left.
C6C7 DEC (IX+$08)
C6CA JR Update_Task_Three_Helpers_AdvanceSlot Jump to Update_Task_Three_Helpers_AdvanceSlot to advance to the next helper entity.
Try a right wander step, respecting the high-X and mid-X bounds.
Update_Task_Three_Helpers_TryMoveRight C6CC LD A,(IX+$07) Load A with the current entity's x-coordinate.
C6CF CP $E0 Is the current entity's x-coordinate less than E0? If so, jump to Update_Task_Three_Helpers_RightBoundCheck.
C6D1 JR C,Update_Task_Three_Helpers_RightBoundCheck
C6D3 CP $FB Is the current entity's x-coordinate less than FB? If not, jump to Update_Task_Three_Helpers_AdvanceSlot.
C6D5 JR NC,Update_Task_Three_Helpers_AdvanceSlot
C6D7 JR Update_Task_Three_Helpers_IncX Jump to Update_Task_Three_Helpers_IncX to increase the helper's x-coordinate.
Right-bound check: at or beyond BB step left instead of right.
Update_Task_Three_Helpers_RightBoundCheck C6D9 CP $BB Is the current entity's x-coordinate less than BB? If not, jump to Update_Task_Three_Helpers_DecX.
C6DB JR NC,Update_Task_Three_Helpers_DecX
Nudge the helper one character right.
Update_Task_Three_Helpers_IncX C6DD INC (IX+$07) Move this entity one character right.
C6E0 INC (IX+$08)
Advance to the next helper slot and loop until all 04 are done.
Update_Task_Three_Helpers_AdvanceSlot C6E3 ADD IX,DE Advance IX to the next entity record.
C6E5 POP BC Restore BC from the stack.
C6E6 DEC B Step the loop counter in B back by one.
C6E7 JP NZ,Update_Task_Three_Helpers_Scan If the result was non-zero, jump to Update_Task_Three_Helpers_Scan.
C6EA RET Return.
Clear type bit 07 (end the 'loose' pose) and advance.
Update_Task_Three_Helpers_ClearTypeBit7 C6EB RES 7,(IX+$00) Reset bit 07 of the current entity's entity type.
C6EF JR Update_Task_Three_Helpers_AdvanceSlot Jump to Update_Task_Three_Helpers_AdvanceSlot to advance to the next helper entity.
When X is below E0, clear type bit 07 and raise SlimyLoose on TaskThreeFlags.
Update_Task_Three_Helpers_MaybeSetFlagBit2 C6F1 LD A,(IX+$07) Load A with the current entity's x-coordinate.
C6F4 CP $E0 Is the current entity's x-coordinate less than E0? If not, jump to Update_Task_Three_Helpers_MaybeSetTypeBit7.
C6F6 JR NC,Update_Task_Three_Helpers_MaybeSetTypeBit7
C6F8 RES 7,(IX+$00) Reset bit 07 of the current entity's entity type.
C6FC LD HL,$72B6 Point HL at the task-three flags (TaskThreeFlags).
C6FF SET 2,(HL) Set SlimyLoose (bit 02 of TaskThreeFlags. D907 skips that line while set).
C701 RET Return.
Rarely set type bit 07 so this helper can enter the SlimyLoose path.
Update_Task_Three_Helpers_MaybeSetTypeBit7 C702 LD A,$0A Load A with 0A.
C704 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
C707 OR A Is the random result in A zero? If not, return.
C708 RET NZ
C709 SET 7,(IX+$00) Set bit 07 of the current entity's entity type.
C70D RET Return.
Prev: C63B Up: Map Next: C70E