Dungeon level generation is a routine from lines 500–590 (with a call out to 2000).
The dungeon level information is primarily stored in DNG%()
(sometimes referred to as just DN%()
) which is an 11 x 11 matrix.
We generate a ZZ but I still don't know what that's for.
500 ZZ = RND ( - ABS (LN) - TX * 10 - TY * 1000 + INOUT * 31.4)
Next we zero out the inside of DNG%()
:
501 FOR X = 1 TO 9: FOR Y = 1 TO 9:DNG%(X,Y) = 0: NEXT : NEXT
Then we set the outsides to WALLS (1
):
510 FOR X = 0 TO 10:DNG%(X,0) = 1:DNG%(X,10) = 1:DNG%(0,X) = 1:DNG%(10,X) = 1: NEXT
Then we draw rows of walls on the even coordinates.
520 FOR X = 2 TO 8 STEP 2: FOR Y = 1 TO 9:DNG%(X,Y) = 1:DNG(Y,X) = 1: NEXT : NEXT
The result at this point is:
11111111111
10101010101
11111111111
10101010101
11111111111
10101010101
11111111111
10101010101
11111111111
10101010101
11111111111
Then, for each element of those rows of inside walls, we randomly replace the wall with a TRAP (2), ? (3), ? (4), CHEST (5) or DOWN LADDER? (9).
530 FOR X = 2 TO 8 STEP 2: FOR Y = 1 TO 9 STEP 2
540 IF RND (1) > .95 THEN DNG%(X,Y) = 2
541 IF RND (1) > .95 THEN DNG%(Y,X) = 2
542 IF RND (1) > .6 THEN DNG%(Y,X) = 3
543 IF RND (1) > .6 THEN DNG%(X,Y) = 3
544 IF RND (1) > .6 THEN DNG%(X,Y) = 4
545 IF RND (1) > .6 THEN DNG%(Y,X) = 4
546 IF RND (1) > .97 THEN DNG%(Y,X) = 9
547 IF RND (1) > .97 THEN DNG%(X,Y) = 9
548 IF RND (1) > .94 THEN DNG%(X,Y) = 5
549 IF RND (1) > .94 THEN DNG%(Y,X) = 5
568 NEXT : NEXT
(2,1) is always cleared. If the player is on an even level, (7,3) is a DOWN LADDER and (3, 7) is an UP LADDER. If the player is on an odd level, (7,3) is an UP LADDER and (3,7) is a DOWN LADDER (of course).
569 DNG%(2,1) = 0: IF INOUT / 2 = INT (INOUT / 2) THEN DNG%(7,3) = 7:DNG%(3,7) = 8
570 IF INOUT / 2 < > INT (INOUT / 2) THEN DNG%(7,3) = 8:DNG%(3,7) = 7
If the player is on the first level of the dungeon (closest to surface) then (1,1) is an UP LADDER instead of (7,3). Presumably this is where the player starts.
580 IF INOUT = 1 THEN DNG%(1,1) = 8:DNG%(7,3) = 0
We call out to 2000 to place monsters.
585 GOSUB 2000
And we're done.
590 RETURN