We iterate through the 10 types of monsters and check if any of them exist at this level of the dungeon. If not, we skip this entire routine.
4000 FOR MM = 1 TO 10: IF MZ%(MM,0) = 0 THEN 4999
So, there's one at level MM
. It's location is currently given by ML%(MM,0)
and ML%(MM,1)
.
First we calculate the distant between the monster and the player:
4010 RA = SQR ((PX - ML%(MM,0)) ; 2 + (PY - ML%(MM,1)) ; 2)
(is ; 2 really how you square? Is that a de-tokenization bug?)
If the HIT POINTS is less than the dungeon level * the player difficulty level, skip to 4030:
4011 IF MZ%(MM,1) < IN * LP THEN 4030
If the distance is < 1.3 (i.e. it's adjacent), then skip to Monster Attack:
4020 IF RA < 1.3 THEN 4500
If it's a MIMIC within a distance of 3, it won't do anything and skip to the next monster.
4025 IF MM = 8 AND RA < 3 THEN 4999
Calculate the direction the player is in from the monster:
4030 X1 = SGN (PX - ML%(MM,0)):Y1 = SGN (PY - ML%(MM,1))
If the HIT POINTS is less than the dungeon level * the player difficulty level, flip the directions (i.e. plan to move away from the player):
4031 IF MZ%(MM,1) < IN * LP THEN X1 = - X1:Y1 = - Y1
If the the player is due east or west (i.e. the change in Y
is 0), skip the next part.
4035 IF Y1 = 0 THEN 4045
(the player isn't due east or west so we're going to need to move north or south) Look at what's in the north/south direction of desired travel. If it's a WALL (1) or another monster or TRAP (2), skip to 4045.
4040 D = DNG%(ML%(MM,0),(ML%(MM,1) + Y1 + .5)): IF D = 1 OR D > 9 OR D = 2 THEN 4045
But if the monster can move in that north/south direction, set X1
to 0 (as it won't be moving east/west this turn).
4042 X1 = 0: GOTO 4050
We get here if the player is due east/west or if something it blocking the monster from going north/south. As the monster won't be moving north/south this turn, we set Y1
to 0. If the player is still due north/south, though, we skip the next line and go to 4050.
4045 Y1 = 0: IF X1 = 0 THEN 4050
The monster desires to go east/west. It looks to see what's in the desired direction. If it's a WALL (1) or another monster or a TRAP (2), then set X1
to 0 (as it can't move in that direction) and go to 4081.
4046 D = DN%((ML%(MM,0) + X1 + .5),ML%(MM,1)): IF D = 1 OR D > 9 OR D = 2 THEN X1 = 0: GOTO 4081
We remove the monster from its existing place in DNG%()
:
4050 DNG%(ML%(MM,0),ML%(MM,1)) = DNG%(ML%(MM,0),ML%(MM,1)) - 10 * MM
If the move would place the monster on the place as the player, we skip the rest and go to the next monster (note they would leave it removed it from DNG%()
, though):
4055 IF ML%(MM,0) + X1 = PX AND ML%(MM,1) + Y1 = PY THEN 4999
Otherwise, we move the monster:
4060 ML%(MM,0) = ML%(MM,0) + X1:ML%(MM,1) = ML%(MM,1) + Y1
and update the DNG%()
to include it at its new location:
4080 DNG%(ML%(MM,0),ML%(MM,1)) = (DNG%(ML%(MM,0),ML%(MM,1)) + 10 * MM + .5)
(not sure what the + .5
here and above is for).
If we get here and there was a movement, we skip to the next monster:
4081 IF X1 < > 0 OR Y1 < > 0 THEN 4999
If the HIT POINTS is less than the dungeon level * player difficulty level and the player is adjacent to the monster, go to Monster Attack:
4082 IF MZ%(MM,1) < IN * LP AND RA < 1.3 THEN 4500
Otherwise, if the HIT POINTS is less than the dungeon level * player difficulty level, the HIT POINTS rise by monster level + dungeon level (healing):
4083 IF MZ%(MM,1) < IN * LP THEN MZ%(MM,1) = MZ%(MM,1) + MM + IN
And we move to the next monster:
4499 GOTO 4999
If the monster is a THIEF or a GREMLIN, it steals rather than attacks to we skip to Monster Theft:
4500 IF MM = 2 OR MM = 7 THEN 4600
We tell the player what they are being attacked by:
4509 PRINT "YOU ARE BEING ATTACKED": PRINT "BY A ";M$(MM)
We determine whether they hit based on whether the player has a shield, the player stamina, the monster level and the dungeon level:
4510 IF RND (1) * 20 - SGN (PW(3)) - C(3) + MM + IN < 0 THEN PRINT "MISSED": GOTO 4525
If it's a hit, the HIT POINTS lost is base on monster level + dungeon level:
4520 PRINT "HIT":C(0) = C(0) - INT ( RND (1) * MM + IN)
If PAUSE is ON we wait for the player to hit CR:
4525 IF PA = 1 THEN PRINT "-CR- TO CONT. ";: INPUT Q$
Then go to the next monster to move:
4530 GOTO 4999
There is a 50% chance the thief or gremlin will just attack anyway:
4600 IF RND (1) < .5 THEN 4509
But if they steal...
If they are a gremlin, half the food will be gone:
4610 IF MM = 7 THEN PW(0) = INT (PW(0) / 2): PRINT "A GREMLIN STOLE SOME FOOD": GOTO 4525
Otherwise (i.e. they are a thief), one of the possessions the player has will be stolen at random:
4620 ZZ = INT ( RND (1) * 6): IF PW(ZZ) < 1 THEN 4620
4630 PRINT "A THIEF STOLE A ";W$(ZZ):PW(ZZ) = PW(ZZ) - 1: GOTO 4525
And finally we go to the next monster then return:
4999 NEXT : RETURN