Prev: 47091 Up: Map Next: 47404
47228: Berk Pick Up Entity
Used by the routine at Berk_Interact_With_Entity.
Berk Pick Up Entity for the player character using complex state at StateData_Boney.
Input
IX Address of complex state data for an entity
Berk_Pick_Up_Entity 47228 LD BC,(29354) Load BC with the last-collided entity pointer (Pointer_LastCollidedEntity).
47232 INC BC Advance the counter/pointer in BC by one.
47233 LD A,(BC) Fetch a byte through the pointer in BC.
47234 AND %00001000 Keep only bit 3 of the flag byte in A (mask 8).
47236 JR NZ,Berk_Pick_Up_Entity_FromCollision If the result was non-zero, jump to Berk_Pick_Up_Entity_FromCollision.
47238 XOR A Clear A as a false / no-match result.
47239 RET Return.
Pick-up from the last collision: reject if X is too far left, else test on-left.
Berk_Pick_Up_Entity_FromCollision 47240 PUSH IX Stash IX on the stack.
47242 LD IX,(29354) Load IX with the last-collided entity pointer (Pointer_LastCollidedEntity).
47246 LD A,(IX+7) Load A with the current entity's x-coordinate.
47249 CP 73 Is the current entity's x-coordinate less than 73? If not, jump to Berk_Pick_Up_Entity_TestOnLeft.
47251 JR NC,Berk_Pick_Up_Entity_TestOnLeft
47253 XOR A Clear A as a no-entity-found result.
47254 JR Berk_Pick_Up_Entity_RestoreReturn Jump to Berk_Pick_Up_Entity_RestoreReturn to restore IX and return with no pick-up.
Confirm the collidee sits on Berk's left before marking the pick-up.
Berk_Pick_Up_Entity_TestOnLeft 47256 CALL Test_EntityOnLeft Call Test_EntityOnLeft to test Entity On Left? If not, jump to Berk_Pick_Up_Entity_RetryCollision.
47259 JR NC,Berk_Pick_Up_Entity_RetryCollision
Mark the picked-up entity's direction/state as held (130).
Berk_Pick_Up_Entity_MarkDirection 47261 LD (IX+9),130 Write 130 to the current entity's direction / state.
Exit the pick-up attempt, restoring Berk's entity pointer in IX.
Berk_Pick_Up_Entity_RestoreReturn 47265 POP IX Restore IX from the stack.
47267 RET Return.
Retry pick-up via Berk_Pick_Up_Entity after the on-left test failed.
Berk_Pick_Up_Entity_RetryCollision 47268 CALL Berk_Pick_Up_Entity Call Berk_Pick_Up_Entity to let Berk pick up an entity? If so, jump to Berk_Pick_Up_Entity_MarkDirection.
47271 JR C,Berk_Pick_Up_Entity_MarkDirection
47273 POP IX Restore IX from the stack.
47275 RET Return.
This entry point is used by the routine at Berk_Interact_With_Entity.
Trap door height on left: choose open vs closed trap scripts from bit 1 of GameEventFlags.
Berk_Pick_Up_Entity_TrapDoorScripts 47276 BIT 4,(IX+3) Is bit 4 of flags byte 3 (IX+3) set? If so, jump to Berk_ReadControls_Idle.
47280 JP NZ,Berk_ReadControls_Idle
47283 LD HL,29363 Point HL at the game event flags (GameEventFlags).
47286 BIT 1,(HL) Is "trap door is open / trap door event armed" (bit 1 of GameEventFlags) set? If so, jump to Berk_Pick_Up_Entity_TrapOpenScript.
47288 JR NZ,Berk_Pick_Up_Entity_TrapOpenScript
47290 LD HL,47923 Point HL at Berk control/put-down script data (47923).
47293 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Trap already open: run the open-trap interaction script (47937).
Berk_Pick_Up_Entity_TrapOpenScript 47296 LD HL,47937 Point HL at Berk control/put-down script data (47937).
47299 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
This entry point is used by the routine at Update_Berk_ReadControls.
Handle right: clear facing-left, then walk or turn Berk right.
Berk_WalkRight 47302 RES 1,(IX+3) Clear Berk's facing-left flag (bit 1 of IX+3).
47306 LD A,(IX+4) Fetch Berk's room index.
47309 CP 0 Is Berk in room 0? If not, continue the right-walk at Berk_WalkRight_TestBelow.
47311 JR NZ,Berk_WalkRight_TestBelow
47313 LD A,(IX+6) Fetch Berk's y-extent.
47316 CP 27 Is he still on the trap door row (y-extent 27)? If not, continue the current script at AdvanceScriptInstruction.
47318 JP NZ,AdvanceScriptInstruction
Right walk outside room 0: test an entity below before turning or interacting.
Berk_WalkRight_TestBelow 47321 CALL Test_EntityBelow Call Test_EntityBelow to test Entity Below? If not, jump to Berk_WalkRight_ByYExtent.
47324 JR NC,Berk_WalkRight_ByYExtent
Already facing the walk-right way: continue the script or run face-right put-down BerkPutDownScript_WalkRightFace.
Berk_WalkRight_FaceCheck 47326 BIT 0,(IX+9) Is bit 0 of the current entity's direction / state set? If so, jump to AdvanceScriptInstruction.
47330 JP NZ,AdvanceScriptInstruction
47333 LD HL,47735 Point HL at Berk control/put-down script data (BerkPutDownScript_WalkRightFace).
47336 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Right walk by y-extent: high rows put down, mid rows idle, else try a put-down.
Berk_WalkRight_ByYExtent 47339 CP 65 Is the current entity's y-extent equal to 65? If so, jump to Berk_Put_Down_Entity_AtYExtent41.
47341 JP Z,Berk_Put_Down_Entity_AtYExtent41
47344 CP 56 Is the current entity's y-extent equal to 56? If so, jump to Berk_Put_Down_Entity_AtYExtent38.
47346 JR Z,Berk_Put_Down_Entity_AtYExtent38
47348 CP 59 Is the current entity's y-extent equal to 59? If so, jump to Berk_Put_Down_Entity_TrapDoor.
47350 JP Z,Berk_Put_Down_Entity_TrapDoor
47353 CP 50 Is the current entity's y-extent less than 50? If not, jump to Berk_ReadControls_Idle.
47355 JP NC,Berk_ReadControls_Idle
47358 BIT 4,(IX+3) Is bit 4 of flags byte 3 (IX+3) set? If so, jump to Berk_WalkRight_FaceCheck.
47362 JP NZ,Berk_WalkRight_FaceCheck
47365 LD BC,(29354) Load BC with the last-collided entity pointer (Pointer_LastCollidedEntity).
47369 INC BC Advance the counter/pointer in BC by one.
47370 LD A,(BC) Fetch a byte through the pointer in BC.
47371 AND %00010000 Keep only bit 4 of the flag byte in A (mask 16).
47373 JR NZ,Berk_WalkRight_FaceCheck If the result was non-zero, jump to Berk_WalkRight_FaceCheck.
47375 BIT 3,(IX+3) Is bit 3 of flags byte 3 (IX+3) set? If so, jump to Berk_WalkRight_TryPutDown.
47379 JR NZ,Berk_WalkRight_TryPutDown
47381 BIT 0,(IX+9) Is bit 0 of the current entity's direction / state set? If so, jump to AdvanceScriptInstruction.
47385 JP NZ,AdvanceScriptInstruction
Try Berk_Put_Down_Entity to put down; on success lock held-state and run script 47857.
Berk_WalkRight_TryPutDown 47388 CALL Berk_Put_Down_Entity Call Berk_Put_Down_Entity to let Berk put down an entity? If not, jump to Berk_ReadControls_Idle.
47391 JP NC,Berk_ReadControls_Idle
47394 SET 3,(IX+3) Set bit 3 of the current entity's flags byte 3.
47398 LD HL,47857 Point HL at Berk control/put-down script data (47857).
47401 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Prev: 47091 Up: Map Next: 47404