Prev: 57631 Up: Map Next: 57901
57642: Animals Event Timing
Used by the routine at Handler_Animals.
*PlayerBooty starts at 0000 and counts up for every item of booty collected. This means that, the chance that animals appear increases when the player has collected over 100 items (of booty, not treasure - which counts down from 0125).
AnimalsEventTiming 57642 LD BC,(23540) If the player has collected over 100 items of booty (in *PlayerBooty) then jump to IncreasedFrequencyAnimalsEventTiming.
57646 LD A,C
57647 CP 100
57649 JR NC,IncreasedFrequencyAnimalsEventTiming
57651 LD HL,(23672) Return if *FRAMES is lower than 1400.
57654 LD DE,1400
57657 SBC HL,DE
57659 RET C
This entry point is used by the routine at IncreasedFrequencyAnimalsEventTiming.
Use FRAMES as a counter.
StartAnimalsEvent 57660 LD HL,0 Reset *FRAMES to 0000 to start a new event cycle.
57663 LD (23672),HL
Pick a spawn row from TableAnimalSpawnRows.
57666 CALL GetRandomNumber Call GetRandomNumber.
57669 AND %00000011 Ensure the random number is between 0 and 3.
57671 LD HL,62231 Point HL at that row in TableAnimalSpawnRows.
57674 LD E,A
57675 LD D,0
57677 ADD HL,DE
57678 PUSH HL Stash the spawn-row pointer on the stack.
57679 INC HL Advance to the next table byte.
57680 LD A,(HL) A=the door-row to match.
Abort if a locked door already sits on that row.
57681 LD IX,(23514) IX=*ReferenceKeysAndLockedDoors.
57685 LD B,A B=the door-row to match.
AnimalsEventTiming_ScanDoors 57686 LD A,(IX+0) Jump to AnimalsEventTiming_ChooseSide if this entry is the terminator (255).
57689 CP 255
57691 JR Z,AnimalsEventTiming_ChooseSide
57693 LD A,(IX+1) Jump to AnimalsEventTiming_NextDoor if this door's vertical is not the match row.
57696 CP B
57697 JR NZ,AnimalsEventTiming_NextDoor
57699 LD A,(IX+5) Jump to AbortAnimalEvent if a key or locked door already occupies this row.
57702 CP 0
57704 JP NZ,AbortAnimalEvent
AnimalsEventTiming_NextDoor 57707 LD DE,6 Move IX on to the next six-byte door entry.
57710 ADD IX,DE
57712 JR AnimalsEventTiming_ScanDoors Jump to AnimalsEventTiming_ScanDoors.
AnimalsEventTiming_ChooseSide 57714 LD IX,62236 Point IX at TableAnimalAttributes.
Choose whether the animal enters from the left or the right.
57718 CALL GetRandomNumber Call GetRandomNumber.
57721 BIT 3,A Test bit 3 of A.
57723 JR Z,AnimalsEventTiming_EnterFromRight Jump to AnimalsEventTiming_EnterFromRight if the animal should enter from the right.
Enter from the left, moving left.
57725 LD (IX+0),2 Write the left-hand column (2) to the horizontal co-ordinate.
57729 LD (IX+2),1 Write 1 to the horizontal offset.
57733 LD (IX+4),1 Set horizontal movement to left (1).
57737 LD (IX+5),0 Clear vertical movement.
57741 LD (IX+11),1 Write 1 to the previous horizontal offset.
57745 LD (IX+13),2 Write 2 to the previous horizontal co-ordinate.
57749 JR AnimalsEventTiming_ChooseSpecies Jump to AnimalsEventTiming_ChooseSpecies.
Enter from the right, moving right.
AnimalsEventTiming_EnterFromRight 57751 LD (IX+0),37 Write the right-hand column (37) to the horizontal co-ordinate.
57755 LD (IX+2),0 Write 0 to the horizontal offset.
57759 LD (IX+4),255 Set horizontal movement to right (255).
57763 LD (IX+5),0 Clear vertical movement.
57767 LD (IX+11),0 Write 0 to the previous horizontal offset.
57771 LD (IX+13),36 Write 36 to the previous horizontal co-ordinate.
Choose a rat or a bird.
AnimalsEventTiming_ChooseSpecies 57775 CALL GetRandomNumber Call GetRandomNumber.
57778 BIT 5,A Test bit 5 of A.
57780 JR Z,AnimalsEventTiming_SpawnBird Jump to AnimalsEventTiming_SpawnBird if this should be a bird.
Spawn a rat on the chosen row, but only if that scanline is empty.
57782 POP HL Restore the spawn-row pointer from the stack.
57783 PUSH HL Stash the spawn-row pointer on the stack.
57784 LD A,(HL) Set up the screen buffer location 33/*HL using CL_SET.
57785 LD B,A
57786 LD C,33
57788 CALL 3545
57791 LD HL,(23684) HL=*DF_CC.
57794 LD B,32 B=32 (one character row).
AnimalsEventTiming_CopyScreenLoop 57796 LD A,(HL) Fetch a screen byte.
57797 INC HL Advance the screen pointer.
57798 CP 255 Jump to AbortAnimalEvent if this byte is not empty (255).
57800 JP NZ,AbortAnimalEvent
57803 DJNZ AnimalsEventTiming_CopyScreenLoop Decrease counter by one and loop back to AnimalsEventTiming_CopyScreenLoop until the whole row has been tested.
57805 POP HL Restore the spawn-row pointer from the stack.
57806 LD A,(HL) A=the spawn row.
57807 INC A Increment A by one.
57808 LD (IX+1),A Write it to the animal vertical co-ordinate.
57811 LD (IX+14),A Write it to the previous vertical co-ordinate.
57814 LD (IX+3),3 Write 3 to the vertical offset.
57818 LD (IX+15),3 Write 3 to the previous vertical offset.
57822 LD (IX+6),32 Write the first rat frame (32) to the sprite ID.
57826 LD (IX+9),3 Write the rat attribute (3).
57830 LD (IX+7),4 Write the rat width (4).
57834 LD (IX+8),1 Write the rat height (1).
57838 LD A,1 Queue the rat sound at SoundFlag_Animal.
57840 LD (65535),A
57843 LD A,(IX+4) Return if the animal is moving left.
57846 CP 1
57848 RET Z
57849 LD (IX+6),36 Else use the right-facing rat frame (36).
57853 RET Return.
Spawn a bird three rows below the chosen spawn row.
AnimalsEventTiming_SpawnBird 57854 POP HL Restore the spawn-row pointer from the stack.
57855 LD A,(HL) A=the spawn row.
57856 INC A Add 3 for the bird's flying height.
57857 INC A
57858 INC A
57859 LD (IX+1),A Write it to the animal vertical co-ordinate.
57862 LD (IX+14),A Write it to the previous vertical co-ordinate.
57865 LD (IX+3),3 Write 3 to the vertical offset.
57869 LD (IX+6),40 Write the first bird frame (40) to the sprite ID.
57873 LD (IX+9),6 Write the bird attribute (6).
57877 LD (IX+7),2 Write the bird width (2).
57881 LD (IX+8),2 Write the bird height (2).
57885 LD A,2 Queue the bird sound at SoundFlag_Animal.
57887 LD (65535),A
57890 LD A,(IX+4) Return if the animal is moving right.
57893 CP 255
57895 RET Z
57896 LD (IX+6),44 Else use the left-facing bird frame (44).
57900 RET Return.
Prev: 57631 Up: Map Next: 57901