Prev: 54363 Up: Map Next: 54626
54414: Collect Entity
Used by the routine at Update_Collectibles.
Collect Entity against the complex entity table at StateData_Boney.
Input
IX Address of complex state data for an entity
Awards score and clears a collectible when Berk touches it.
Collect_Entity 54414 LD DE,(29435) Load DE with the camera room-origin pointer (Pointer_CameraRoomOrigin).
54418 LD L,C Copy the low byte from C into L (build HL).
54419 LD H,B Copy the high byte from B into H (build HL).
54420 LD A,(29363) Load A with the game event flags (GameEventFlags).
54423 LD B,A Keep game event flags in B for later.
54424 LD A,(IX+0) Fetch the current entity's type for the type test.
54427 BIT 7,A Is bit 7 of the current entity's entity type set? If so, return.
54429 RET NZ
54430 OR A Is the current entity's entity type zero? If so, jump to Collect_Entity_TypeZeroBit5.
54431 JR Z,Collect_Entity_TypeZeroBit5
54433 CP 11 Is the current entity's entity type equal to 11? If so, jump to Collect_Entity_AsHeld.
54435 JR Z,Collect_Entity_AsHeld
54437 BIT 1,B Is bit 1 of the loop/flags byte in B set? If so, jump to AdvanceScriptInstruction.
54439 JP NZ,AdvanceScriptInstruction
54442 LD (IX+0),0 Write 0 to the current entity's entity type.
54446 RET Return.
Empty slot with bit 5 set: under the event latch, become type 10 and clear that bit.
Collect_Entity_TypeZeroBit5 54447 BIT 5,(IX+3) Is bit 5 of flags byte 3 (IX+3) set? If not, jump to Collect_Entity_MaybeSetBit5.
54451 JP Z,Collect_Entity_MaybeSetBit5
54454 BIT 1,B Is bit 1 of the loop/flags byte in B set? If not, return.
54456 RET Z
54457 LD (IX+0),10 Write 10 to the current entity's entity type.
54461 RES 5,(IX+3) Reset bit 5 of flags byte 3 (IX+3).
54465 RET Return.
Type-11 collectible: score it, branch on flags, or tick its counter / wander script.
Collect_Entity_AsHeld 54466 LD A,(IX+1) Load A with the current entity's flags byte 1.
54469 BIT 6,A Is bit 6 of the current entity's flags byte 1 set? If so, jump to Collect_Entity_RunScoreScript.
54471 JR NZ,Collect_Entity_RunScoreScript
54473 AND %10100000 Keep only bits 7 and 5 of that flags byte (mask 160).
54475 JR NZ,Collect_Entity_Branch If the result was non-zero, jump to Collect_Entity_Branch.
54477 LD A,(IX+6) Load A with the current entity's y-extent.
54480 CP 35 Is the current entity's y-extent less than 35? If not, jump to Collect_Entity_TestCounterBit7.
54482 JR NC,Collect_Entity_TestCounterBit7
Run the collectible score script at 54216.
Collect_Entity_RunScoreScript 54484 LD HL,54216 Point HL at collectible/score table data (54216).
54487 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Flagged type-11 path: clear the counter and run the alternate score script at 54294.
Collect_Entity_Branch 54490 XOR A Clear the collectible counter.
54491 LD (29372),A Set the collectible counter (CollectibleCounter).
54494 LD HL,54294 Point HL at collectible/score table data (54294).
54497 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
High collectibles skip scripting while counter bit 7 is set.
Collect_Entity_TestCounterBit7 54500 LD A,(29372) Load A with the collectible counter (CollectibleCounter).
54503 BIT 7,A Is bit 7 of collectible counter set? If so, jump to AdvanceScriptInstruction.
54505 JP NZ,AdvanceScriptInstruction
Tick the collectible counter down, or reseed it and launch a wander script when it hits zero.
Collect_Entity_DecCounterOrScript 54508 OR A Is collectible counter zero? If so, jump to Collect_Entity_RandomiseCounterScript.
54509 JR Z,Collect_Entity_RandomiseCounterScript
54511 DEC A Step collectible counter back by one.
54512 LD (29372),A Set the collectible counter (CollectibleCounter).
54515 JP AdvanceScriptInstruction Jump to AdvanceScriptInstruction to run the next script instruction.
Reseed the counter to 132 plus a random and run the wander script at 54222.
Collect_Entity_RandomiseCounterScript 54518 LD A,6 Load A with 6 as the PseudoRandom random maximum.
54520 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
54523 ADD A,132 Add 132 to A (build a score/message digit address).
54525 LD (29372),A Set the collectible counter (CollectibleCounter).
54528 LD HL,54222 Point HL at collectible/score table data (54222).
54531 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
54534 INC B Advance the collectible-slot counter in B.
54535 LD L,L Keep L unchanged (alignment byte in the compiled routine).
54536 INC H Advance the high byte of the pointer in HL.
54537 LD (BC),A Write the computed score/digit byte through BC.
54538 LD HL,(1492) Load HL from 1492.
54541 LD L,L Keep L unchanged (alignment byte in the compiled routine).
54542 DAA Decimal-adjust A after adding to a score digit.
54543 INC BC Advance the counter/pointer in BC by one.
54544 INC E Advance the low byte of the pointer/offset in DE.
54545 CALL NC,27392 If not below, call PrimaryDisplayBuffer_0.
54548 DEC H Step the high byte of the score/table pointer back by one.
54549 INC BC Advance the counter/pointer in BC by one.
54550 JR C,Collect_Entity_DecCounterOrScript If a hit/borrow was signaled, jump to Collect_Entity_DecCounterOrScript.
Idle empty slot: rarely raise bit 5 and copy spawn coordinates from table 54534.
Collect_Entity_MaybeSetBit5 54552 BIT 1,B Is bit 1 of the loop/flags byte in B set? If so, return.
54554 RET NZ
54555 LD A,10 Load A with 10.
54557 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
54560 OR A Is 10 zero? If not, return.
54561 RET NZ
54562 SET 5,(IX+3) Set bit 5 of flags byte 3 (IX+3).
54566 LD A,3 Load A with 3.
54568 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
54571 ADD A,A Double 3 (word index).
54572 LD C,A Keep 3 in C for later.
54573 ADD A,A Double 3 (word index).
54574 ADD A,C Add the saved count in C to A.
54575 LD C,A Keep 3 in C for later.
54576 LD B,0 Load B with 0 as a loop counter.
54578 LD IY,54534 Point IY at collectible storage (54534).
54582 ADD IY,BC Add the offset in BC to the entity pointer in IY.
54584 LD A,(IY+0) Load A with the referenced entity's entity type.
54587 OR A Is referenced entity's entity type zero? If so, jump to Collect_Entity_CopyIYCoordsToIX.
54588 JR Z,Collect_Entity_CopyIYCoordsToIX
54590 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
Copy the chosen spawn coords / room from IY into this slot and launch its script.
Collect_Entity_CopyIYCoordsToIX 54593 ADD A,(IY+1) Add the referenced entity's flags byte 1 to A.
54596 LD (IX+7),A Set the current entity's x-coordinate.
54599 LD (IX+8),A Set the current entity's x-extent.
54602 LD A,(IY+2) Load A with the referenced entity's flags byte 2.
54605 LD (IX+5),A Set the current entity's y-coordinate.
54608 LD (IX+6),A Set the current entity's y-extent.
54611 LD A,(IY+3) Load A with the referenced entity's flags byte 3.
54614 LD (IX+4),A Set the current entity's room index.
54617 LD L,(IY+4) Load L with the referenced entity's room index.
54620 LD H,(IY+5) Load H with the referenced entity's y-coordinate.
54623 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Prev: 54363 Up: Map Next: 54626