Prev: 45086 Up: Map Next: 45422
45108: 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 45108 LD IX,37005 Point IX at the weight-chain entity (StateData_Complex_30).
45112 LD HL,29370 Point HL at the trap door flags (TrapDoorFlags).
45115 BIT 1,(HL) Is a weight-chain layout swap pending (bit 1)? If not, continue at Update_Drutt_CheckCounter.
45117 JR Z,Update_Drutt_CheckCounter
45119 RES 1,(HL) Clear the layout-swap latch.
45121 LD BC,40545 Load the resting weight-chain layout address (GraphicLayout_WeightChain).
45124 LD (37015),BC Write that layout into the creature's layout field (37015).
45128 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 45129 LD A,(29371) Fetch Drutt's animation counter (DruttAnimationCounter).
45132 OR A Is the counter idle (zero)? If so, watch for Berk at Update_Drutt_WatchBerk.
45133 JP Z,Update_Drutt_WatchBerk
45136 LD B,A Keep the remaining tick count in B.
45137 INC A Advance the animation counter by one.
45138 LD (29371),A Store the updated counter at DruttAnimationCounter.
Handle animation: move the creature down a row and finish or keep going.
Update_Drutt_AnimateFrame 45141 INC (IX+5) Move the creature down one character (raise y).
45144 INC (IX+6) Grow its y-extent to match.
45147 LD A,(IX+6) Load the new y-extent.
45150 CP 37 Has it reached the open-trap row (y-extent 37)? If not, keep animating at Update_Drutt_MidAnimation.
45152 JR NZ,Update_Drutt_MidAnimation
45154 LD A,142 Queue sound effect 142 (trap door thump).
45156 CALL Queue_Sound Call Queue_Sound to play that effect.
45159 XOR A Clear A so the animation counter can stop.
45160 LD (29371),A Clear Drutt's animation counter (DruttAnimationCounter).
45163 LD BC,43047 Load the closed-trap graphic layout (GraphicLayout_LeverClosedLeft).
45166 LD (37295),BC Write it into the lever layout slot (Pointer_AnimatingSceneryLayout).
45170 BIT 2,(HL) Is Drutt mid trap door animation (bit 2)? If not, nothing more to do.
45172 RET Z
45173 RES 2,(HL) Clear the mid-animation latch.
45175 SET 1,(HL) Request a weight-chain layout swap next frame (set bit 1).
45177 LD A,(45019) Fetch the entity type Drutt saved at Drutt_SavedEntityType.
45180 CP 32 Was it type 32? If so, boil the cauldron at Update_Drutt_CaughtPot.
45182 JR Z,Update_Drutt_CaughtPot
45184 LD HL,40520 Point HL at 40520.
45187 JR Update_Drutt_InstallLayout Skip the pot update and install that layout at Update_Drutt_InstallLayout.
Update the cauldron after a type-32 catch and use the weight chain layout.
Update_Drutt_CaughtPot 45189 CALL Update_Cauldron Call Update_Cauldron to update the cauldron after Drutt's catch.
45192 LD HL,40512 Point HL at GraphicLayout_WeightChainWrapper.
Install the chosen post-catch layout into the weight-chain slot.
Update_Drutt_InstallLayout 45195 LD (37015),HL Write the chosen layout into the weight-chain layout field (37015).
Step Drutt's chew animation; special type 31 gets Reposition_CameraFollowEntity, else clear the chewed slot.
Update_Drutt_EatLoop 45198 CALL Update_Drutt_Animation Call Update_Drutt_Animation to step Drutt's eat / chew animation.
45201 RET Z Return if that animation has finished.
45202 LD A,(IY+0) Load the type of the entity Drutt is chewing.
45205 CP 31 Is it type 31 (inedible / special)? If not, clear the slot at Update_Drutt_ClearChewed.
45207 JR NZ,Update_Drutt_ClearChewed
45209 CALL Reposition_CameraFollowEntity Call Reposition_CameraFollowEntity to handle the special chew.
45212 RET Return.
Clear the chewed entity type and keep looping the eat animation.
Update_Drutt_ClearChewed 45213 LD (IY+0),0 Clear the chewed entity's type (deactivate the slot).
45217 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 45219 BIT 2,(HL) Still mid trap door animation (bit 2)? If not, look for a new catch at Update_Drutt_SeekCatch.
45221 JR Z,Update_Drutt_SeekCatch
45223 LD IY,(45017) Load the entity Drutt is currently grabbing (TemporaryEntityPointer_Drutt).
45227 LD A,(IY+6) Load that entity's y-extent.
45230 SUB (IY+5) Subtract its y-coordinate to get its height.
45233 SRL A Halve the height.
45235 ADD A,(IY+5) Add the y-coordinate back to get the vertical centre.
45238 LD C,A Keep the grabbed entity's vertical centre in C.
45239 LD A,(IX+6) Load the creature's y-extent.
45242 CP C Has the creature's mouth reached that centre yet? If not, keep animating at Update_Drutt_NextAnimTick.
45243 JR C,Update_Drutt_NextAnimTick
45245 LD (IY+0),0 Clear the grabbed entity's type (Drutt swallowed it).
Consume the remaining animation ticks by looping back to Update_Drutt_AnimateFrame.
Update_Drutt_NextAnimTick 45249 DJNZ Update_Drutt_AnimateFrame Decrease the remaining tick count and loop to Update_Drutt_AnimateFrame while ticks remain.
45251 RET Return when the animation ticks are exhausted.
Handle catch: find a candidate entity under the mouth and classify it.
Update_Drutt_SeekCatch 45252 CALL Update_Drutt_Animation Call Update_Drutt_Animation to see whether Drutt can start a catch this frame.
45255 JR Z,Update_Drutt_NextAnimTick If not, just consume an animation tick at Update_Drutt_NextAnimTick.
45257 LD A,(IX+6) Load the creature's y-extent.
45260 INC A Peek one row below the mouth.
45261 CP (IY+5) Does that row meet the candidate entity's y? If not, keep waiting at Update_Drutt_NextAnimTick.
45264 JR NZ,Update_Drutt_NextAnimTick
45266 LD (45017),IY Remember this candidate at TemporaryEntityPointer_Drutt.
45270 LD A,(IY+5) Load the candidate's y-coordinate.
45273 CP (IY+6) Is the candidate a flat / already-swallowed slot (y == y-extent)? If not, classify it at Update_Drutt_ClassifyCatch.
45276 JR NZ,Update_Drutt_ClassifyCatch
45278 LD (IY+0),0 Clear that empty slot's type.
45282 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 45284 LD A,(IY+0) Load the candidate's entity type.
45287 LD (45019),A Save it at Drutt_SavedEntityType for the layout chooser.
45290 CP 22 Type 22 (worm)?, then play the catch sound at Update_Drutt_CatchSound.
45292 JR Z,Update_Drutt_CatchSound
45294 CP 24 Type 24 (collectible eyeball variant)?, then same catch sound at Update_Drutt_CatchSound.
45296 JR Z,Update_Drutt_CatchSound
45298 CP 23 Type 23? If not, mark a failed catch at Update_Drutt_CatchFailed.
45300 JR NZ,Update_Drutt_CatchFailed
45302 LD A,(45085) Fetch Drutt's saved animation state (Drutt_SavedAnimationState).
45305 CP 28 Is that saved state 28? If so, take the type-28 collect path at Update_Drutt_CollectSafeLoot.
45307 JR Z,Update_Drutt_CollectSafeLoot
45309 JR NC,Update_Drutt_CatchSound If the saved state is above 28, just play the catch sound at Update_Drutt_CatchSound.
45311 LD B,3 Lift the catch three rows (loop counter 3).
Lift the caught entity with the creature, retype it as a collected eye, and mark task progress.
Update_Drutt_LiftCatch 45313 INC (IX+5) Raise the creature's y.
45316 INC (IX+6) Grow its y-extent.
45319 INC (IY+5) Raise the caught entity's y with it.
45322 DJNZ Update_Drutt_LiftCatch Loop to Update_Drutt_LiftCatch for each remaining row.
45324 LD (IY+0),24 Retype the catch as 24 (collected eye).
45328 LD DE,40789 Point DE at the collected-eye layout (40789).
45331 LD (37001),DE Write that layout into entity state at 37001.
45335 LD HL,29364 Point HL at the task status flags (TaskStatusFlags).
45338 SET 4,(HL) Mark "Drutt collected a type-24 object" (bit 4).
45340 JR Update_Drutt_CollectDone Finish the collect at Update_Drutt_CollectDone.
Install the type-28 collect layout and mark that collection on the task status flags.
Update_Drutt_CollectSafeLoot 45342 LD DE,40710 Point DE at the type-28 collect layout (GraphicLayout_OpenSafe).
45345 LD (37001),DE Write that layout into entity state at 37001.
45349 LD HL,29364 Point HL at the task status flags (TaskStatusFlags).
45352 SET 5,(HL) Mark "Drutt collected a type-28 object" (bit 5).
Gate task progress and clear the current task index after a successful collect.
Update_Drutt_CollectDone 45354 SET 0,(HL) Set the task-progress gate (bit 0 of TaskStatusFlags).
45356 XOR A Clear A so the current task index can reset.
45357 LD (29358),A Clear the current task index (CurrentTaskIndex).
Update_Drutt_CatchSound 45360 LD A,142 Queue sound effect 142 (catch thump).
45362 CALL Queue_Sound Call Queue_Sound to play it.
45365 XOR A Clear A to stop further animation ticks.
45366 LD (29371),A Clear Drutt's animation counter (DruttAnimationCounter).
45369 RET Return.
Failed catch: special-case type 31, clear the mid-animation latch, then consume a tick.
Update_Drutt_CatchFailed 45370 CP 31 Was the saved type 31? If not, stay mid-animation at Update_Drutt_StayMidAnimation.
45372 JR NZ,Update_Drutt_StayMidAnimation
45374 CALL Reposition_CameraFollowEntity Call Reposition_CameraFollowEntity for the special failure case.
45377 XOR A Clear A so the saved entity type can be wiped.
45378 LD (45019),A Clear Drutt's saved entity type (Drutt_SavedEntityType).
45381 RES 2,(HL) Clear the mid-animation latch (bit 2 of TrapDoorFlags).
45383 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 45386 SET 2,(HL) Keep the mid-animation latch set (bit 2 of TrapDoorFlags).
45388 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 45391 LD A,(IX+6) Load the creature's y-extent.
45394 CP 30 Is the mouth still above the trigger row (y-extent < 30)? If not, return.
45396 RET NC
45397 LD A,(29443) Fetch Berk's X-coordinate copy (BerkXCoordinateCopy).
45400 CP 160 Is Berk left of the trap mouth (x < 160)? If so, return.
45402 RET C
45403 CP 224 Is Berk right of the trap mouth (x >= 224)? If so, return.
45405 RET NC
45406 CALL Update_Drutt_Animation Call Update_Drutt_Animation to see whether a catchable entity is present.
45409 RET Z Return if nothing is ready.
45410 LD A,(IY+5) Load that entity's y-coordinate.
45413 DEC A Step one row up from the candidate entity's y-coordinate.
45414 DEC A Step a second row up.
45415 CP (IX+6) Has the creature's mouth reached that row yet? If not, return.
45418 RET C
45419 JP Reset_Trap_Door_Animation_State Jump to Reset_Trap_Door_Animation_State to reset the trap door animation state and begin.
Prev: 45086 Up: Map Next: 45422