Prev: 51998 Up: Map Next: 52163
52036: Script Routine: (75) Task-four entity action
Nudge the task-four creature one character toward its target.
Input
IX Address of complex state data for an entity
ScriptRoutine_TaskFourStepToward 52036 LD A,(IX+13) Load A with the current entity's extra state.
52039 BIT 4,A Is bit 4 of the current entity's extra state set? If not, jump to ScriptRoutine_TaskFourStepToward_RequireExtraBit2.
52041 JR Z,ScriptRoutine_TaskFourStepToward_RequireExtraBit2
52043 RES 4,A Clear bit 4 of the flag byte in A.
52045 LD (IX+13),A Set the current entity's extra state.
52048 JR ScriptRoutine_TaskFourStepToward_MaybeNegateDelta Jump to ScriptRoutine_TaskFourStepToward_MaybeNegateDelta to continue this routine.
Require extra-state bit 2 before stepping; otherwise bail to the next script.
ScriptRoutine_TaskFourStepToward_RequireExtraBit2 52050 BIT 2,A Is bit 2 of the current entity's extra state set? If so, jump to AdvanceScriptInstruction.
52052 JP NZ,AdvanceScriptInstruction
At extra-state ends (11 or 0), reverse the signed step via ScriptRoutine_TaskFourStepToward_NegateDirection.
ScriptRoutine_TaskFourStepToward_MaybeNegateDelta 52055 LD A,(IX+12) Load A with the current entity's extra state.
52058 CP 11 Is the current entity's extra state equal to 11? If so, call ScriptRoutine_TaskFourStepToward_NegateDirection.
52060 CALL Z,ScriptRoutine_TaskFourStepToward_NegateDirection
52063 OR A Is A zero? If so, call ScriptRoutine_TaskFourStepToward_NegateDirection.
52064 CALL Z,ScriptRoutine_TaskFourStepToward_NegateDirection
Apply the signed step: grow or shrink extra state, then rewrite X / X-extent.
ScriptRoutine_TaskFourStepToward_ApplySignedStep 52067 LD C,(IX+9) Load C with the current entity's direction / state.
52070 BIT 7,C Is bit 7 of the direction/state in C set (negative delta)? If so, jump to ScriptRoutine_TaskFourStepToward_DecExtraState.
52072 JR NZ,ScriptRoutine_TaskFourStepToward_DecExtraState
52074 INC A Advance the current entity's extra state by one.
52075 JR ScriptRoutine_TaskFourStepToward_WriteCoordsAndFlags Jump to ScriptRoutine_TaskFourStepToward_WriteCoordsAndFlags to continue this routine.
Negative delta path: shrink extra state before rewriting coordinates.
ScriptRoutine_TaskFourStepToward_DecExtraState 52077 DEC A Step the current entity's extra state back by one.
Commit the stepped X band, clear latch bit 4, and at X=108 raise it and maybe reverse.
ScriptRoutine_TaskFourStepToward_WriteCoordsAndFlags 52078 LD (IX+12),A Set the current entity's extra state.
52081 LD A,C Copy the saved count/flag from C into A.
52082 ADD A,(IX+7) Add the current entity's x-coordinate to A.
52085 LD (IX+7),A Set the current entity's x-coordinate.
52088 LD A,C Copy the saved count/flag from C into A.
52089 ADD A,(IX+8) Add the current entity's x-extent to A.
52092 LD (IX+8),A Set the current entity's x-extent.
52095 LD A,(29363) Load A with the game event flags (GameEventFlags).
52098 RES 4,A Clear bit 4 of the flag byte in A.
52100 LD (29363),A Set the game event flags (GameEventFlags).
52103 LD A,(IX+7) Load A with the current entity's x-coordinate.
52106 CP 108 Is the current entity's x-coordinate equal to 108? If not, jump to AdvanceScriptInstruction.
52108 JP NZ,AdvanceScriptInstruction
52111 LD A,(29363) Load A with the game event flags (GameEventFlags).
52114 SET 4,A Set bit 4 of game event flags.
52116 LD (29363),A Set the game event flags (GameEventFlags).
52119 BIT 1,A Is bit 1 of game event flags set? If not, jump to ScriptRoutine_TaskFourStepToward_MatchCreatureThenRetrace.
52121 JR Z,ScriptRoutine_TaskFourStepToward_MatchCreatureThenRetrace
52123 LD HL,51867 Point HL at task-four script entry 51867.
52126 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
At the turnaround X, retrace only when aligned with the vat (StateData_Complex_28) in room 3.
ScriptRoutine_TaskFourStepToward_MatchCreatureThenRetrace 52129 LD IY,36977 Point IY at the vat entity at StateData_Complex_28.
52133 LD A,(IX+7) Load A with the current entity's x-coordinate.
52136 CP (IY+7) Does this entity's x match the referenced entity's x (IY+7)? If not, jump to AdvanceScriptInstruction.
52139 JP NZ,AdvanceScriptInstruction
52142 LD A,(IY+4) Load A with the referenced entity's room index.
52145 CP 3 Is referenced entity's room index equal to 3? If not, jump to AdvanceScriptInstruction.
52147 JP NZ,AdvanceScriptInstruction
52150 JR ScriptRoutine_TaskFourStepToward_ApplySignedStep Jump to ScriptRoutine_TaskFourStepToward_ApplySignedStep to continue this routine.
Negate the stored direction / step delta so the entity walks the other way.
ScriptRoutine_TaskFourStepToward_NegateDirection 52152 PUSH AF Stash AF on the stack.
52153 LD A,(IX+9) Load A with the current entity's direction / state.
52156 NEG Negate A (flip a delta/direction).
52158 LD (IX+9),A Set the current entity's direction / state.
52161 POP AF Restore AF from the stack.
52162 RET Return.
Prev: 51998 Up: Map Next: 52163