Prev: 54634 Up: Map Next: 54765
54686: Script Routine: (54) Collectible action
Update the collectible counter for this entity's current state.
Input
IX Address of complex state data for an entity
ScriptRoutine_CollectibleScanCounter 54686 LD A,(29372) Load A with the collectible counter (CollectibleCounter).
54689 CP 128 Is collectible counter equal to 128? If not, jump to ScriptRoutine_CollectibleScanCounter_DecCounterScan.
54691 JR NZ,ScriptRoutine_CollectibleScanCounter_DecCounterScan
54693 LD HL,54230 Point HL at the dialogue/message table (54230).
54696 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Tick the counter and, if the crusher (StateData_Complex_16) is live, measure its X delta.
ScriptRoutine_CollectibleScanCounter_DecCounterScan 54699 DEC A Step collectible counter back by one.
54700 LD (29372),A Set the collectible counter (CollectibleCounter).
54703 LD IY,36809 Point IY at the crusher entity (StateData_Complex_16).
54707 LD A,(IY+0) Load A with the referenced entity's entity type.
54710 OR A Is the referenced entity's entity type zero? If so, jump to AdvanceScriptInstruction to run the next script instruction.
54711 JP Z,AdvanceScriptInstruction
54714 BIT 5,(IY+1) Is bit 5 of the referenced entity's flags byte 1 set? If so, jump to AdvanceScriptInstruction.
54718 JP NZ,AdvanceScriptInstruction
54721 LD A,(IY+7) Load A with the referenced entity's x-coordinate.
54724 INC A Advance referenced entity's x-coordinate by one.
54725 SUB (IX+7) Subtract the current entity's x-coordinate from A.
54728 PUSH AF Stash AF on the stack.
54729 JR NC,ScriptRoutine_CollectibleScanCounter_TestAbsDeltaX Jump to ScriptRoutine_CollectibleScanCounter_TestAbsDeltaX if the result did not underflow.
54731 NEG Negate A (flip a delta/direction).
Only react when the crusher is within 10 characters horizontally.
ScriptRoutine_CollectibleScanCounter_TestAbsDeltaX 54733 CP 10 Is referenced entity's x-coordinate less than 10? If so, jump to ScriptRoutine_CollectibleScanCounter_PickScriptBySign.
54735 JR C,ScriptRoutine_CollectibleScanCounter_PickScriptBySign
54737 POP AF Restore AF from the stack.
54738 JP AdvanceScriptInstruction Jump to AdvanceScriptInstruction to run the next script instruction.
Pick the left or right reaction script from the sign of the crusher X delta.
ScriptRoutine_CollectibleScanCounter_PickScriptBySign 54741 POP AF Restore AF from the stack.
54742 JR C,ScriptRoutine_CollectibleScanCounter_RunScript Jump to ScriptRoutine_CollectibleScanCounter_RunScript if the result underflowed.
54744 LD HL,54286 Point HL at collectible/score table data 54286.
54747 JR ScriptRoutine_CollectibleScanCounter_RandomiseCounterAndRun Jump to ScriptRoutine_CollectibleScanCounter_RandomiseCounterAndRun to continue this routine.
Use the leftward crusher-reaction script at 54278.
ScriptRoutine_CollectibleScanCounter_RunScript 54749 LD HL,54278 Point HL at collectible/score table data 54278.
Reseed the counter to 10 plus a random and run the chosen reaction script.
ScriptRoutine_CollectibleScanCounter_RandomiseCounterAndRun 54752 LD A,50 Load A with 50 as the PseudoRandom random maximum.
54754 CALL PseudoRandom Call PseudoRandom to pick a pseudo-random value.
54757 ADD A,10 Add 10 to A (adjust a collectible/timer value).
54759 LD (29372),A Set the collectible counter (CollectibleCounter).
54762 JP ScriptInstruction Jump to ScriptInstruction to execute the script instruction at HL.
Prev: 54634 Up: Map Next: 54765