![]() |
Routines |
| Prev: 54626 | Up: Map | Next: 54686 |
|
Pick a random continuation from the collectible's script table.
|
||||||||
| ScriptRoutine_CollectibleRandomScript | 54634 | LD A,4 | .. | |||||
| 54636 | CALL PseudoRandom | Call PseudoRandom to pick a pseudo-random value and keep it in B. | ||||||
| 54639 | LD B,A | |||||||
| 54640 | INC B | Advance the loop index in B. | ||||||
| 54641 | ADD A,A | Double A to form a word index into the script/handler table. | ||||||
| 54642 | LD C,A | Keep the index in C. | ||||||
| 54643 | LD A,128 | Load A with 128. | ||||||
|
Rotate a bit mask until it differs from this collectible's direction / state.
|
||||||||
| ScriptRoutine_CollectibleRandomScript_RotateMask | 54645 | RLC A | Rotate the collectible bitmask in A left circular. | |||||
| 54647 | DJNZ ScriptRoutine_CollectibleRandomScript_RotateMask | Decrease the loop counter in B and jump to ScriptRoutine_CollectibleRandomScript_RotateMask if more iterations remain. | ||||||
| 54649 | CP (IX+9) | Does A match this entity's direction/state (IX+9)? If so, jump to ScriptRoutine_CollectibleRandomScript. | ||||||
| 54652 | JR Z,ScriptRoutine_CollectibleRandomScript | |||||||
| 54654 | LD (IX+9),A | Set the current entity's direction / state. | ||||||
| 54657 | AND %00000011 | Keep only the low two direction bits of A. | ||||||
| 54659 | JR NZ,ScriptRoutine_CollectibleRandomScript_RandomMax1E | Jump to ScriptRoutine_CollectibleRandomScript_RandomMax1E to continue if the comparison did not match. | ||||||
| 54661 | LD A,2 | Load A with 2. | ||||||
| 54663 | JR ScriptRoutine_CollectibleRandomScript_SetCounterAndScript | Jump to ScriptRoutine_CollectibleRandomScript_SetCounterAndScript to continue this routine. | ||||||
|
Use random maximum 30 when the new mask is not in the low two direction bits.
|
||||||||
| ScriptRoutine_CollectibleRandomScript_RandomMax1E | 54665 | LD A,30 | Load A with 30. | |||||
|
Reseed the collectible counter and launch the matching script word from Data_CollectibleScriptTable.
|
||||||||
| ScriptRoutine_CollectibleRandomScript_SetCounterAndScript | 54667 | CALL PseudoRandom | Call PseudoRandom to pick a pseudo-random value. | |||||
| 54670 | INC A | Advance 30 by one. | ||||||
| 54671 | LD (29372),A | Set the collectible counter (CollectibleCounter). | ||||||
| 54674 | LD HL,54626 | Point HL at unused padding before the collectible script (Data_CollectibleScriptTable). | ||||||
| 54677 | ADD HL,BC | Add the length/offset in BC to the pointer in HL. | ||||||
| 54678 | LD C,(HL) | Fetch the new script address into BC. | ||||||
| 54679 | INC HL | |||||||
| 54680 | LD B,(HL) | |||||||
| 54681 | LD L,C | Copy the script address from BC into HL. | ||||||
| 54682 | LD H,B | |||||||
| 54683 | JP ScriptInstruction | Jump to ScriptInstruction to execute the script instruction at HL. | ||||||
| Prev: 54626 | Up: Map | Next: 54686 |