Prev: B01E Up: Map Next: B16E
B034: Update Drutt
Used by the routine at GameStart.
Advance Drutt's trap door animation and collection logic using the weight-chain slot at StateData_Complex_30 and Drutt's state at StateData_Drutt.
Finish a pending weight-chain layout swap, then either tick the animation counter or watch for Berk near the trap.
Update_Drutt B034 LD IX,$908D Point IX at the weight-chain entity (StateData_Complex_30).
B038 LD HL,$72BA Point HL at the trap door flags (TrapDoorFlags).
B03B BIT 1,(HL) Is a weight-chain layout swap pending (bit 01)? If not, continue at Update_Drutt_CheckCounter.
B03D JR Z,Update_Drutt_CheckCounter
B03F RES 1,(HL) Clear the layout-swap latch.
B041 LD BC,$9E61 Load the resting weight-chain layout address (GraphicLayout_WeightChain).
B044 LD ($9097),BC Write that layout into the creature's layout field (9097).
B048 RET Return, then the swap is done for this frame.
If Drutt's animation counter is idle, watch for Berk; otherwise tick it and animate.
Update_Drutt_CheckCounter B049 LD A,($72BB) Fetch Drutt's animation counter (DruttAnimationCounter).
B04C OR A Is the counter idle (zero)? If so, watch for Berk at Update_Drutt_WatchBerk.
B04D JP Z,Update_Drutt_WatchBerk
B050 LD B,A Keep the remaining tick count in B.
B051 INC A Advance the animation counter by one.
B052 LD ($72BB),A Store the updated counter at DruttAnimationCounter.
Handle animation: move the creature down a row and finish or keep going.
Update_Drutt_AnimateFrame B055 INC (IX+$05) Move the creature down one character (raise y).
B058 INC (IX+$06) Grow its y-extent to match.
B05B LD A,(IX+$06) Load the new y-extent.
B05E CP $25 Has it reached the open-trap row (y-extent 25)? If not, keep animating at Update_Drutt_MidAnimation.
B060 JR NZ,Update_Drutt_MidAnimation
B062 LD A,$8E Queue sound effect 8E (trap door thump).
B064 CALL Queue_Sound Call Queue_Sound to play that effect.
B067 XOR A Clear A so the animation counter can stop.
B068 LD ($72BB),A Clear Drutt's animation counter (DruttAnimationCounter).
B06B LD BC,$A827 Load the closed-trap graphic layout (GraphicLayout_LeverClosedLeft).
B06E LD ($91AF),BC Write it into the lever layout slot (Pointer_AnimatingSceneryLayout).
B072 BIT 2,(HL) Is Drutt mid trap door animation (bit 02)? If not, nothing more to do.
B074 RET Z
B075 RES 2,(HL) Clear the mid-animation latch.
B077 SET 1,(HL) Request a weight-chain layout swap next frame (set bit 01).
B079 LD A,($AFDB) Fetch the entity type Drutt saved at Drutt_SavedEntityType.
B07C CP $20 Was it type 20? If so, boil the cauldron at Update_Drutt_CaughtPot.
B07E JR Z,Update_Drutt_CaughtPot
B080 LD HL,$9E48 Point HL at 9E48.
B083 JR Update_Drutt_InstallLayout Skip the pot update and install that layout at Update_Drutt_InstallLayout.
Update the cauldron after a type-20 catch and use the weight chain layout.
Update_Drutt_CaughtPot B085 CALL Update_Cauldron Call Update_Cauldron to update the cauldron after Drutt's catch.
B088 LD HL,$9E40 Point HL at GraphicLayout_WeightChainWrapper.
Install the chosen post-catch layout into the weight-chain slot.
Update_Drutt_InstallLayout B08B LD ($9097),HL Write the chosen layout into the weight-chain layout field (9097).
Step Drutt's chew animation; special type 1F gets Reposition_CameraFollowEntity, else clear the chewed slot.
Update_Drutt_EatLoop B08E CALL Update_Drutt_Animation Call Update_Drutt_Animation to step Drutt's eat / chew animation.
B091 RET Z Return if that animation has finished.
B092 LD A,(IY+$00) Load the type of the entity Drutt is chewing.
B095 CP $1F Is it type 1F (inedible / special)? If not, clear the slot at Update_Drutt_ClearChewed.
B097 JR NZ,Update_Drutt_ClearChewed
B099 CALL Reposition_CameraFollowEntity Call Reposition_CameraFollowEntity to handle the special chew.
B09C RET Return.
Clear the chewed entity type and keep looping the eat animation.
Update_Drutt_ClearChewed B09D LD (IY+$00),$00 Clear the chewed entity's type (deactivate the slot).
B0A1 JR Update_Drutt_EatLoop Keep chewing via Update_Drutt_EatLoop.
While mid trap door animation, wait until the mouth reaches the grabbed entity's centre, then swallow it.
Update_Drutt_MidAnimation B0A3 BIT 2,(HL) Still mid trap door animation (bit 02)? If not, look for a new catch at Update_Drutt_SeekCatch.
B0A5 JR Z,Update_Drutt_SeekCatch
B0A7 LD IY,($AFD9) Load the entity Drutt is currently grabbing (TemporaryEntityPointer_Drutt).
B0AB LD A,(IY+$06) Load that entity's y-extent.
B0AE SUB (IY+$05) Subtract its y-coordinate to get its height.
B0B1 SRL A Halve the height.
B0B3 ADD A,(IY+$05) Add the y-coordinate back to get the vertical centre.
B0B6 LD C,A Keep the grabbed entity's vertical centre in C.
B0B7 LD A,(IX+$06) Load the creature's y-extent.
B0BA CP C Has the creature's mouth reached that centre yet? If not, keep animating at Update_Drutt_NextAnimTick.
B0BB JR C,Update_Drutt_NextAnimTick
B0BD LD (IY+$00),$00 Clear the grabbed entity's type (Drutt swallowed it).
Consume the remaining animation ticks by looping back to Update_Drutt_AnimateFrame.
Update_Drutt_NextAnimTick B0C1 DJNZ Update_Drutt_AnimateFrame Decrease the remaining tick count and loop to Update_Drutt_AnimateFrame while ticks remain.
B0C3 RET Return when the animation ticks are exhausted.
Handle catch: find a candidate entity under the mouth and classify it.
Update_Drutt_SeekCatch B0C4 CALL Update_Drutt_Animation Call Update_Drutt_Animation to see whether Drutt can start a catch this frame.
B0C7 JR Z,Update_Drutt_NextAnimTick If not, just consume an animation tick at Update_Drutt_NextAnimTick.
B0C9 LD A,(IX+$06) Load the creature's y-extent.
B0CC INC A Peek one row below the mouth.
B0CD CP (IY+$05) Does that row meet the candidate entity's y? If not, keep waiting at Update_Drutt_NextAnimTick.
B0D0 JR NZ,Update_Drutt_NextAnimTick
B0D2 LD ($AFD9),IY Remember this candidate at TemporaryEntityPointer_Drutt.
B0D6 LD A,(IY+$05) Load the candidate's y-coordinate.
B0D9 CP (IY+$06) Is the candidate a flat / already-swallowed slot (y == y-extent)? If not, classify it at Update_Drutt_ClassifyCatch.
B0DC JR NZ,Update_Drutt_ClassifyCatch
B0DE LD (IY+$00),$00 Clear that empty slot's type.
B0E2 JR Update_Drutt_CatchFailed Treat it as a failed catch at Update_Drutt_CatchFailed.
Handle collectible types: worms, eyes and special catches.
Update_Drutt_ClassifyCatch B0E4 LD A,(IY+$00) Load the candidate's entity type.
B0E7 LD ($AFDB),A Save it at Drutt_SavedEntityType for the layout chooser.
B0EA CP $16 Type 16 (worm)?, then play the catch sound at Update_Drutt_CatchSound.
B0EC JR Z,Update_Drutt_CatchSound
B0EE CP $18 Type 18 (collectible eyeball variant)?, then same catch sound at Update_Drutt_CatchSound.
B0F0 JR Z,Update_Drutt_CatchSound
B0F2 CP $17 Type 17? If not, mark a failed catch at Update_Drutt_CatchFailed.
B0F4 JR NZ,Update_Drutt_CatchFailed
B0F6 LD A,($B01D) Fetch Drutt's saved animation state (Drutt_SavedAnimationState).
B0F9 CP $1C Is that saved state 1C? If so, take the type-1C collect path at Update_Drutt_CollectSafeLoot.
B0FB JR Z,Update_Drutt_CollectSafeLoot
B0FD JR NC,Update_Drutt_CatchSound If the saved state is above 1C, just play the catch sound at Update_Drutt_CatchSound.
B0FF LD B,$03 Lift the catch three rows (loop counter 03).
Lift the caught entity with the creature, retype it as a collected eye, and mark task progress.
Update_Drutt_LiftCatch B101 INC (IX+$05) Raise the creature's y.
B104 INC (IX+$06) Grow its y-extent.
B107 INC (IY+$05) Raise the caught entity's y with it.
B10A DJNZ Update_Drutt_LiftCatch Loop to Update_Drutt_LiftCatch for each remaining row.
B10C LD (IY+$00),$18 Retype the catch as 18 (collected eye).
B110 LD DE,$9F55 Point DE at the collected-eye layout (9F55).
B113 LD ($9089),DE Write that layout into entity state at 9089.
B117 LD HL,$72B4 Point HL at the task status flags (TaskStatusFlags).
B11A SET 4,(HL) Mark "Drutt collected a type-18 object" (bit 04).
B11C JR Update_Drutt_CollectDone Finish the collect at Update_Drutt_CollectDone.
Install the type-1C collect layout and mark that collection on the task status flags.
Update_Drutt_CollectSafeLoot B11E LD DE,$9F06 Point DE at the type-1C collect layout (GraphicLayout_OpenSafe).
B121 LD ($9089),DE Write that layout into entity state at 9089.
B125 LD HL,$72B4 Point HL at the task status flags (TaskStatusFlags).
B128 SET 5,(HL) Mark "Drutt collected a type-1C object" (bit 05).
Gate task progress and clear the current task index after a successful collect.
Update_Drutt_CollectDone B12A SET 0,(HL) Set the task-progress gate (bit 00 of TaskStatusFlags).
B12C XOR A Clear A so the current task index can reset.
B12D LD ($72AE),A Clear the current task index (CurrentTaskIndex).
Update_Drutt_CatchSound B130 LD A,$8E Queue sound effect 8E (catch thump).
B132 CALL Queue_Sound Call Queue_Sound to play it.
B135 XOR A Clear A to stop further animation ticks.
B136 LD ($72BB),A Clear Drutt's animation counter (DruttAnimationCounter).
B139 RET Return.
Failed catch: special-case type 1F, clear the mid-animation latch, then consume a tick.
Update_Drutt_CatchFailed B13A CP $1F Was the saved type 1F? If not, stay mid-animation at Update_Drutt_StayMidAnimation.
B13C JR NZ,Update_Drutt_StayMidAnimation
B13E CALL Reposition_CameraFollowEntity Call Reposition_CameraFollowEntity for the special failure case.
B141 XOR A Clear A so the saved entity type can be wiped.
B142 LD ($AFDB),A Clear Drutt's saved entity type (Drutt_SavedEntityType).
B145 RES 2,(HL) Clear the mid-animation latch (bit 02 of TrapDoorFlags).
B147 JP Update_Drutt_NextAnimTick Consume an animation tick at Update_Drutt_NextAnimTick.
Keep the mid-animation latch set and consume an animation tick.
Update_Drutt_StayMidAnimation B14A SET 2,(HL) Keep the mid-animation latch set (bit 02 of TrapDoorFlags).
B14C JP Update_Drutt_NextAnimTick Consume an animation tick at Update_Drutt_NextAnimTick.
Handle idle watch: start a trap door animation only when Berk is in the mouth band.
Update_Drutt_WatchBerk B14F LD A,(IX+$06) Load the creature's y-extent.
B152 CP $1E Is the mouth still above the trigger row (y-extent < 1E)? If not, return.
B154 RET NC
B155 LD A,($7303) Fetch Berk's X-coordinate copy (BerkXCoordinateCopy).
B158 CP $A0 Is Berk left of the trap mouth (x < A0)? If so, return.
B15A RET C
B15B CP $E0 Is Berk right of the trap mouth (x >= E0)? If so, return.
B15D RET NC
B15E CALL Update_Drutt_Animation Call Update_Drutt_Animation to see whether a catchable entity is present.
B161 RET Z Return if nothing is ready.
B162 LD A,(IY+$05) Load that entity's y-coordinate.
B165 DEC A Step one row up from the candidate entity's y-coordinate.
B166 DEC A Step a second row up.
B167 CP (IX+$06) Has the creature's mouth reached that row yet? If not, return.
B16A RET C
B16B JP Reset_Trap_Door_Animation_State Jump to Reset_Trap_Door_Animation_State to reset the trap door animation state and begin.
Prev: B01E Up: Map Next: B16E