Prev: 48845 Up: Map Next: 49015
48870: Update Task Two Entity State
Used by the routine at Update_Task_Two_Entities.
Restore the upstairs helper if needed, then either start/stop its script from the game event flags or pick the next wandering script.
Update_TaskTwoEntityState 48870 LD HL,29365 Point HL at the task-two flags (TaskTwoFlags).
48873 LD A,(29358) Fetch the current task index (CurrentTaskIndex).
48876 CP 2 Is task two itself active (index 2)? If so, skip the spawn latch at Update_TaskTwo_CheckHelperRestore.
48878 JR Z,Update_TaskTwo_CheckHelperRestore
48880 BIT 1,(HL) Is the task-two "advance script" bit already set (bit 1)? If so, skip the spawn latch.
48882 JR Z,Update_TaskTwo_CheckHelperRestore
48884 SET 2,(HL) Otherwise arm the spawn / random-walk latch (set bit 2).
Handle helper restore: rewrite the upstairs helper layout when bit 3 is set.
Update_TaskTwo_CheckHelperRestore 48886 BIT 3,(HL) Does the helper need its layout restoring (bit 3)? If not, select the entity at Update_TaskTwo_SelectEntity.
48888 JR Z,Update_TaskTwo_SelectEntity
48890 RES 3,(HL) Clear the restore latch.
48892 LD HL,40371 Point HL at spawned-helper layout GraphicLayout_WhiteOrb.
48895 LD (36833),HL Write that layout into the helper's record (36833).
48898 LD HL,36823 Point HL at the spawned-helper entity (StateData_Complex_17).
48901 SET 7,(HL) Mark that helper active (set bit 7 of its type/flags byte).
Handle start/stop: use game event flags to run or halt the upstairs helper script.
Update_TaskTwo_SelectEntity 48903 LD IX,36837 Point IX at the upstairs helper entity (StateData_Complex_18).
48907 LD HL,(29391) Keep the temporary script pointer in HL (Pointer_ActiveScriptCursor).
48910 LD A,(29363) Fetch the game event flags (GameEventFlags).
48913 BIT 7,A Is a task entity script marked active (bit 7)? If not, take the wander branch at Update_TaskTwo_ScriptBranch.
48915 JR NZ,Update_TaskTwo_ScriptBranch
48917 BIT 7,(IX+0) Is this helper already running (bit 7 of its type)? If not, decide whether to stop it at Update_TaskTwo_StopEntity.
48921 JR NZ,Update_TaskTwo_StopEntity
48923 BIT 1,A Is the trap door open (game event bit 1)? If so, (re)start the helper at Update_TaskTwo_StartEntity.
48925 JR Z,Update_TaskTwo_StartEntity
48927 JR Update_TaskTwo_ScriptBranch Otherwise wander at Update_TaskTwo_ScriptBranch.
Stop the upstairs helper when the trap is open but the helper was not running.
Update_TaskTwo_StopEntity 48929 BIT 1,A Is the trap door open? If not, leave the helper alone and return.
48931 RET Z
48932 RES 7,(IX+0) Clear the helper's "running" type bit.
48936 JP AdvanceScriptInstruction Advance its current script at AdvanceScriptInstruction.
Start the upstairs helper: clear the task latch and publish script Data_BirdScripts.
Update_TaskTwo_StartEntity 48939 SET 7,(IX+0) Mark the helper running (set bit 7 of its type).
48943 LD HL,29363 Point HL at the game event flags (GameEventFlags).
48946 RES 7,(HL) Clear "task entity script active" (bit 7).
48948 XOR A Clear A so the task phase can reset.
48949 LD (29359),A Clear the current task phase (CurrentTaskPhase).
48952 LD HL,48749 Point HL at the bird scripts (Data_BirdScripts).
48955 LD (29391),HL Publish it through the active script cursor (Pointer_ActiveScriptCursor).
48958 RET Return.
This entry point is used by the routine at ScriptRoutine_TaskTwoRiseOnEvent.
Shared entry used by script routine ScriptRoutine_TaskTwoRiseOnEvent when the helper reaches column 39: clear the upstairs event latch and restart.
Update_TaskTwo_ClearTrapFlags 48959 LD HL,29363 Point HL at the game event flags (GameEventFlags).
48962 RES 4,(HL) Clear the task-two / upstairs event latch (bit 4).
48964 LD A,40 Load a fresh game-tick delay of 40 frames.
48966 LD (29426),A Store it in the game tick counter (GameTickCounter).
48969 LD HL,29365 Point HL at the task-two flags (TaskTwoFlags).
48972 RES 2,(HL) Clear the spawn / random-walk latch (bit 2).
48974 JR Update_TaskTwo_StartEntity Restart the helper at Update_TaskTwo_StartEntity.
Handle wander: pick the next bird script when no start/stop event is pending.
Update_TaskTwo_ScriptBranch 48976 LD A,(29365) Fetch the task-two flags (TaskTwoFlags).
48979 BIT 1,A Is "advance script" still set (bit 1)? If so, just step the current script at AdvanceScriptInstruction.
48981 JP Z,AdvanceScriptInstruction
48984 RES 1,A Clear that advance bit.
48986 LD (29365),A Write the updated task-two flags back.
48989 BIT 2,A Is the spawn / random-walk latch set (bit 2)? If not, use the alternate script at Update_TaskTwo_AltScript.
48991 JR NZ,Update_TaskTwo_AltScript
48993 LD A,24 Load random range base 24 for a wander destination.
48995 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
48998 ADD A,22 Bias it into the bird script table (22+A).
49000 LD (48795),A Poke that index into task-two storage at 48795.
49003 LD HL,48785 Point HL at the wander script (BirdScript_Wander).
49006 JP ScriptInstruction Run it via ScriptInstruction.
Wander without the spawn latch: run the alternate bird script (BirdScript_AltWander).
Update_TaskTwo_AltScript 49009 LD HL,48833 Point HL at the alternate bird script (BirdScript_AltWander).
49012 JP ScriptInstruction Run it via ScriptInstruction.
Prev: 48845 Up: Map Next: 49015