Prev: CD88 Up: Map Next: CE71
CDD7: Change creature behaviour based on Maroc's magic
Used by the routine at CD88.
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 EAAA.
CDD7 LD A,($EB46) Creature type
CDDA CP $08 Guardian of Chaos
CDDC JP Z,$CF0B
CDDF JP C,$CE71 If creature type < 8 then it's a warlock, If so, skip this routine as they have a different movement pattern to other creatures
CDE2 CP $0B Wraith
CDE4 JR Z,$CE2E
CDE6 CP $09 Goblin warrior
CDE8 JP Z,$CF3E
CDEB CP $0C Demon
CDED JP Z,$CE2E
Goblin missile thrower (creature type #10)
Goblin missile throwers won't fire any missiles at Maroc if UNSEEN or FREEZE spell is active
CDF0 LD A,($EB4E) Creature properties byte
CDF3 AND $01
CDF5 JP Z,$CF0B If creature is off screen, check if its movement needs to be changed due to the UNSEEN spell being active
CDF8 LD A,($EB50) Creature is on-screen. Get graphic frame number offset
CDFB AND $07 Keep bits 0-2
CDFD CP $03 Is the graphic frame #3?
CDFF JR NZ,$CE12 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)
CE01 LD A,($EAE9) Currently active spell
CE04 CP $09 Check if the UNSEEN spell is active
CE06 JR Z,$CE12 Jump to CE12 if UNSEEN is active
CE08 LD A,($EC9C) Check FREEZE spell timer counter
CE0B CP $00
CE0D JR NZ,$CE12 If counter is > 0, FREEZE spell is active - jump to CE12
CE0F JP $CF58 Neither FREEZE or UNSEEN is active so initialize a missile
UNSEEN or FREEZE spell is active
CE12 LD A,($EAAA) Game cycle counter
CE15 AND $0F Check bits 0-3
CE17 JP Z,$CF0B Every 16th game cycle check the UNSEEN spell and alter the creature's movement accordingly
CE1A CP $0C
CE1C JR Z,$CE4F On each game cycle #12 (of 16) randomize the creature's movement
CE1E CP $00
CE20 JP NZ,$D04B
CE23 LD A,$00 On every 16th game cycle, stop moving:
CE25 LD ($EB4C),A Set horizontal movement speed/direction to zero
CE28 LD ($EB4D),A Set vertical movement speed/direction to zero
CE2B JP $D04B
Jump here from CDD7 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)
CE2E LD A,($EAEC) Get activated spell
CE31 CP $04 If spell number >=4, jump to CF1D
CE33 JP NC,$CF1D
CE36 LD A,($EAE9) Check for currently active effect spells
CE39 CP $09
CE3B JP Z,$CF1D If UNSEEN spell is active, jump to CF1D
CE3E LD A,($EAAA) Game cycle counter
CE41 AND $1F Check if any bits 0-4 set
CE43 CP $00
CE45 JR NZ,$CE69 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
CE47 LD A,($EB46) Check if creature is type number #12 (demon)
CE4A CP $0C
CE4C JP Z,$CF58 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 (CF3E)
  • Goblin missile thrower, every 16 game cycles
  • Guardian of Chaos if the UNSEEN spell is active CF0B
  • Wraith, every 32 game cycles
CE4F CALL $DB06 Generate pseudo-random number
CE52 LD C,A Temp store in C register
CE53 AND $0F Only need bits 0-3 (values 0-15)
CE55 SUB $07 Subtract 7, so values between -7 and +8
CE57 ADD A,A
CE58 ADD A,A Multiply by 4, so values now between -28 and +32 (in multiples of 4)
CE59 LD ($EB4C),A Store as creature's horizontal speed (negative numbers = left, positive = right)
CE5C LD A,C Retrieve stored pseudo-random number
CE5D RRA
CE5E RRA Divide by 4 (creates a different number from the previous one)
CE5F AND $0F Keep bits 0-3 (values 0-15)
CE61 SUB $07 Subtract 7, so values now between -7 and +8
CE63 LD ($EB4D),A Store as creature's vertical speed (negative numbers = up, positive = down)
CE66 JP $D04B
WRAITH or DEMON movement - continued from CE45
CE69 AND $07 (Game timer counter) - check bits 0-2
CE6B JP NZ,$D04B
CE6E JP $CF1D Every 8 game cycles, re-calculate the creature's homing trajectory based on Maroc's position
Prev: CD88 Up: Map Next: CE71