Prev: 52914 Up: Map Next: 53057
52967: Script routine: (52) Increase worm's age and decrease time until direction change, or react to Drutt's presence
When both Drutt and the worm are in the same room, and the worm is alerted to Drutt's presence, then the worm will take on its alarmed appearance and start fleeing in the direction away from Drutt. As long as Drutt remains in the same room as the worm, and within the "alerting" distance, the worm will continue fleeing in the same direction, and its time until direction change will be frozen.
As soon as the distance between Drutt and the worm exceeds the "alerting" distance, or the two find themselves in different rooms, the worm will see its in-danger flag reset and its time until direction change will resume counting down. The worm's alarmed appearance (and increased speed) will remain, however, until the time until direction change reaches zero.
As long as the worm's in-danger flag is reset, its time until direction change will decrease.
Used by the routine at 48096.
Input
IX Address of complex state data for an entity
Output
HL New address in script data
52967 CALL 53057 Increase worm's age and, if it has expired, set its depth to zero and return
52970 LD IY,(34242) Load IY with address of current level's complex state data for Drutt
52974 LD A,(IX+0) If Drutt and the worm are in the same room...
52977 CP (IY+0) ...
52980 JR Z,53004 ...then skip ahead to 53004
Drutt and worm in different rooms, so countdown to next direction change resumes as worm out of danger
52982 RES 1,(IX+9) Reset in-danger flag
52986 LD A,(IX+12) If worm's time until direction change is zero...
52989 OR A ...
52990 JR Z,52998 ...then skip ahead to 52998 (have worm choose new direction)
52992 DEC (IX+12) Decrease worm's time until direction change
52995 JP 48096 Advance HL to next script instruction and execute
52998 LD HL,52747 Point HL at script data for worm, choosing next direction...
53001 JP 48098 ...and execute
Drutt and worm in same room, so worm potentially in danger
53004 LD A,(IX+5) Load A with x-coordinate of worm's left edge...
53007 INC A ...plus one...
53008 SUB (IY+5) ...minus x-coordinate of Drutt's left edge
53011 JR C,53034 If negative then skip ahead to 53034
53013 CP 10 If worm's left edge is 9 characters or more to the right of Drutt's...
53015 JR NC,52982 ...then jump back to 52982
53017 BIT 1,(IX+9) If in-danger flag is set...
53021 JP NZ,48096 ...then jump to 48096 (advance HL to next script instruction and execute)
53024 SET 1,(IX+9) Set in-danger flag
53028 LD HL,52817 Point HL at script data for worm, fleeing right...
53031 JP 48098 ...and execute
Drutt's left edge more than one character to the right of worm's left edge
53034 NEG If worm's left edge is 11 characters or more to the left of Drutt's...
53036 CP 10 ...
53038 JR NC,52982 ...then jump back to 52982
53040 BIT 1,(IX+9) If in-danger flag is set...
53044 JP NZ,48096 ...then jump to 48096 (advance HL to next script instruction and execute)
53047 SET 1,(IX+9) Set in-danger flag
53051 LD HL,52797 Point HL at script data for worm, fleeing left...
53054 JP 48098 ...and execute
Prev: 52914 Up: Map Next: 53057