if we have just performed a melee attack we enter at 6990 and draw the players attack pose. Otherwise we enter at 7000 where we update the player's fatigue based on the action the player just performed ( 650 ).
If there is a monster ( NB>0), we jump to the monster logic. Otherwise, we see if we can spawn a wandering monster ( 4850). If one was not spawned, we return to the top of the main loop ( 5044).
Otherwise, we announce the arrival of the monster, set it up and return to the top of the loop.
6990 K = 1: GOSUB 600
7000 GOSUB 650: IF NB > 0 THEN 7005
7001 GOSUB 4850: IF NB = 0 THEN 5044
7002 QX = 195:QY = 80:Q$ = "APPEARS!": GOSUB 15010: GOSUB 75:QY = 72: GOSUB 15010:QX = 195:Q$ = A$: GOSUB 75: GOSUB 300: GOTO 5044
Monster logic. If the monster is friendly (IN>0), skip attack to 7500. Also skip if HI is not equal to 0. This seems to always be 0, so I am going to guess that is a developer flag used to disable monsters for testing purposes.
If monsters are not disabled, either attack the player or move towards them. Line 7010 is what amounts to AI in ToA.
7005 QY = 48: GOSUB 15010: IF IN > 0 OR HI > 0 THEN 7500
7010 IF ABS (X0 - XM) > 5 OR ABS (Y0 - YM) > 5 THEN 7300
Monster attack. Monsters can have multiple attacks. MA stores the number of attacks a monster can make. Each attack is performed by the monster rolling a d20, adding its level and the player defense penalty/bonus from the attack type table. If a monster hits, we test against the player's shield points ( a function of the shield size and the player dexterity ). If a d20 rolls lower than the shield points, then the shield is hit and the shield's armor is added onto the player armor.
7015 IM = MA
7017 IM = IM - 1: IF IM < 0 THEN 7250
7020 P = PA - ZD(IA):R = RND (1) * 20 + ML: IF R < P THEN QX = 195:QY = 48:Q$ = "IT MISSED!": GOSUB 15010: GOSUB 75: GOTO 7017
7030 GOSUB 65: IF RND (1) * 20 - 1 < PEEK (KB + 4) THEN QX = 195:QY = 48:Q$ = "SHIELD HIT!": GOSUB 15010: GOSUB 75:K = - PS: GOTO 7040
7035 QX = 195:QY = 48:Q$ = "STRUCK THEE!": GOSUB 15010: GOSUB 75:K = 0: IF PEEK (US + MQ) = 2 AND RND (1) * 20 > PEEK (KB + 21) / 2 + PEEK (KA - 81) AND PEEK (KA - 88) = 0 THEN GOSUB 50:QX = 195:QY = 48:Q$ = "A CHILL": GOSUB 15010: GOSUB 75
7040 K = K + INT ((MD * (R - P)) / 10) - AA - PEEK (KB + 16): IF K < 0 THEN K = 0
7050 PC = PC - K: IF PC < 1 THEN FOR I = 1 TO 1000: NEXT I: GOTO 11000
7060 QX = 249:QY = 8:Q$ = STR$ ( INT (100 * PC / PH + .5)) + "%": GOSUB 15000: GOSUB 75: IF NB > 0 THEN 7017
7070 GOTO 5044
Move monster a little for cosmetic effect.
7250 IF NB = 0 THEN 5044
7255 GOSUB 350:L = 2: ON RND (1) * 4 + 1 GOTO 7260,7270,7280,7290
7260 YM = YM + L: GOTO 7490
7270 XM = XM + L: GOTO 7490
7280 YM = YM - L: GOTO 7490
7290 XM = XM - L: GOTO 7490
Move monster towards the player
7300 GOSUB 350: GOSUB 679:XX = XL - XM:YY = YL - YM: IF ABS (XX) < ABS (YY) THEN 7306
7301 IF XX > 0 THEN MF = 2
7302 IF XX < = 0 THEN MF = 4
7304 GOTO 7310
7306 IF YY > 0 THEN MF = 1: GOTO 7310
7307 MF = 3
7310 L = MS: ON MF GOTO 7320,7360,7400,7440
7320 IF YM + L > YL - 3 THEN YM = YL - 3: GOTO 7490
7330 YM = YM + L: GOTO 7490
7360 IF XM + L > XL - 3 THEN XM = XL - 3: GOTO 7490
7370 XM = XM + L: GOTO 7490
7400 IF YM - L < YL + 3 THEN YM = YL + 3: GOTO 7490
7410 YM = YM - L: GOTO 7490
7440 IF XM - L < XL + 3 THEN XM = XL + 3: GOTO 7490
7450 XM = XM - L: GOTO 7490
7490 GOSUB 55: GOSUB 300
Check if a monster has been killed. If so award experience and increase the count of monsters slain. If there are multiple monsters in this room, decrease the count and reset the monster.
7500 IF MP < 1 AND NB > 0 THEN GOSUB 350: GOSUB 450:EX = EX + 20 * ML * ML + 15:KC = KC + 1:QX = 195:QY = 96:Q$ = STR$ (KC): GOSUB 15000: GOSUB 75:QX = 1195:QY = 32:Q$ = "MONSTER SLAIN!": GOSUB 15010: GOSUB 75:M = PEEK (MN + KR)
7504 IF MP > = 1 OR NB < = 0 THEN 7510
7505 IF M > 0 THEN POKE MN + KR,M - 1: IF M > 1 THEN GOSUB 4500:QX = 195:QY = 32:Q$ = "ANOTHER COMES": GOSUB 15010: GOSUB 75: GOSUB 300
7510 IF MP < 1 THEN NB = 0:QY = 40: GOSUB 15010:QY = 48: GOSUB 15010:QY = 72: GOSUB 15010:QY = 80: GOSUB 15010
7520 GOTO 5044
Comments