Prev: 52616 Up: Map Next: 52849
52695: Change creature behaviour based on Maroc's magic
Used by the routine at 52616.
The different creatures in Avalon have their own distinct movement patterns. For example, wraiths will occasionally dart towards or away from Maroc. Goblin missile throwers stop in one place and fire missiles at Maroc from a distance.
Movement patterns are affected by Maroc's active spells (particularly UNSEEN and FREEZE), at different intervals using the game cycle timer/counter stored at 60074.
52695 LD A,(60230) Creature type
52698 CP 8 Guardian of Chaos
52700 JP Z,53003
52703 JP C,52849 If creature type < 8 then it's a warlock, If so, skip this routine as they have a different movement pattern to other creatures
52706 CP 11 Wraith
52708 JR Z,52782
52710 CP 9 Goblin warrior
52712 JP Z,53054
52715 CP 12 Demon
52717 JP Z,52782
Goblin missile thrower (creature type #10)
Goblin missile throwers won't fire any missiles at Maroc if UNSEEN or FREEZE spell is active
52720 LD A,(60238) Creature properties byte
52723 AND 1
52725 JP Z,53003 If creature is off screen, check if its movement needs to be changed due to the UNSEEN spell being active
52728 LD A,(60240) Creature is on-screen. Get graphic frame number offset
52731 AND 7 Keep bits 0-2
52733 CP 3 Is the graphic frame #3?
52735 JR NZ,52754 If not, jump to the next section to determine the creature's movement
If the creature has reached frame 3, it can fire a missile (as long as FREEZE or UNSEEN aren't active)
52737 LD A,(60137) Currently active spell
52740 CP 9 Check if the UNSEEN spell is active
52742 JR Z,52754 Jump to 52754 if UNSEEN is active
52744 LD A,(60572) Check FREEZE spell timer counter
52747 CP 0
52749 JR NZ,52754 If counter is > 0, FREEZE spell is active - jump to 52754
52751 JP 53080 Neither FREEZE or UNSEEN is active so initialize a missile
UNSEEN or FREEZE spell is active
52754 LD A,(60074) Game cycle counter
52757 AND 15 Check bits 0-3
52759 JP Z,53003 Every 16th game cycle check the UNSEEN spell and alter the creature's movement accordingly
52762 CP 12
52764 JR Z,52815 On each game cycle #12 (of 16) randomize the creature's movement
52766 CP 0
52768 JP NZ,53323
52771 LD A,0 On every 16th game cycle, stop moving:
52773 LD (60236),A Set horizontal movement speed/direction to zero
52776 LD (60237),A Set vertical movement speed/direction to zero
52779 JP 53323
Jump here from 52695 if creature type is WRAITH or DEMON.
These two creatures can 'sniff out' powerful magic.
  • If Maroc has UNSEEN active, they are able to home in on his position, making them potentially more dangerous, though DEMONs will not fire missiles which tend to be more difficult to avoid
  • They will also move towards Maroc's screen position if he casts ANY 'powerful' spell (i.e. spell number >=4)
52782 LD A,(60140) Get activated spell
52785 CP 4 If spell number >=4, jump to 53021
52787 JP NC,53021
52790 LD A,(60137) Check for currently active effect spells
52793 CP 9
52795 JP Z,53021 If UNSEEN spell is active, jump to 53021
52798 LD A,(60074) Game cycle counter
52801 AND 31 Check if any bits 0-4 set
52803 CP 0
52805 JR NZ,52841 If not, skip the next two sets of instructions
Every 32 game cycles
  • Wraiths will change their movement direction
  • Demons will fire a missile at Maroc
52807 LD A,(60230) Check if creature is type number #12 (demon)
52810 CP 12
52812 JP Z,53080 If so, go and initialize a missile/bolt
Otherwise it's a wraith, so continue to the next instructions to randomize its movement
Randomize creature movement
Changes movement speeds/directions for:
  • Goblin warrior if Maroc has cast a powerful spell (53054)
  • Goblin missile thrower, every 16 game cycles
  • Guardian of Chaos if the UNSEEN spell is active 53003
  • Wraith, every 32 game cycles
52815 CALL 56070 Generate pseudo-random number
52818 LD C,A Temp store in C register
52819 AND 15 Only need bits 0-3 (values 0-15)
52821 SUB 7 Subtract 7, so values between -7 and +8
52823 ADD A,A
52824 ADD A,A Multiply by 4, so values now between -28 and +32 (in multiples of 4)
52825 LD (60236),A Store as creature's horizontal speed (negative numbers = left, positive = right)
52828 LD A,C Retrieve stored pseudo-random number
52829 RRA
52830 RRA Divide by 4 (creates a different number from the previous one)
52831 AND 15 Keep bits 0-3 (values 0-15)
52833 SUB 7 Subtract 7, so values now between -7 and +8
52835 LD (60237),A Store as creature's vertical speed (negative numbers = up, positive = down)
52838 JP 53323
WRAITH or DEMON movement - continued from 52805
52841 AND 7 (Game timer counter) - check bits 0-2
52843 JP NZ,53323
52846 JP 53021 Every 8 game cycles, re-calculate the creature's homing trajectory based on Maroc's position
Prev: 52616 Up: Map Next: 52849