forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmklev.c
1898 lines (1713 loc) · 56.8 KB
/
mklev.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* NetHack 3.6 mklev.c $NHDT-Date: 1562455089 2019/07/06 23:18:09 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.63 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Alex Smith, 2017. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
/* for UNIX, Rand #def'd to (long)lrand48() or (long)random() */
/* croom->lx etc are schar (width <= int), so % arith ensures that */
/* conversion of result to int is reasonable */
STATIC_DCL void FDECL(mkfount, (int, struct mkroom *));
STATIC_DCL void FDECL(mksink, (struct mkroom *));
STATIC_DCL void FDECL(mkaltar, (struct mkroom *));
STATIC_DCL void FDECL(mkgrave, (struct mkroom *));
STATIC_DCL void NDECL(makevtele);
STATIC_DCL void NDECL(clear_level_structures);
STATIC_DCL void NDECL(makelevel);
STATIC_DCL boolean FDECL(bydoor, (XCHAR_P, XCHAR_P));
STATIC_DCL struct mkroom *FDECL(find_branch_room, (coord *));
STATIC_DCL struct mkroom *FDECL(pos_to_room, (XCHAR_P, XCHAR_P));
STATIC_DCL boolean FDECL(place_niche, (struct mkroom *, int *, int *, int *));
STATIC_DCL void FDECL(makeniche, (int));
STATIC_DCL void NDECL(make_niches);
STATIC_PTR int FDECL(CFDECLSPEC do_comp, (const genericptr,
const genericptr));
STATIC_DCL void FDECL(dosdoor, (XCHAR_P, XCHAR_P, struct mkroom *, int));
STATIC_DCL void FDECL(join, (int, int, BOOLEAN_P));
STATIC_DCL void FDECL(do_room_or_subroom, (struct mkroom *, int, int,
int, int, BOOLEAN_P,
SCHAR_P, BOOLEAN_P, BOOLEAN_P));
STATIC_DCL void NDECL(makerooms);
STATIC_DCL void FDECL(finddpos, (coord *, XCHAR_P, XCHAR_P,
XCHAR_P, XCHAR_P));
STATIC_DCL void FDECL(mkinvpos, (XCHAR_P, XCHAR_P, int));
STATIC_DCL void FDECL(mk_knox_portal, (XCHAR_P, XCHAR_P));
#define create_vault() create_room(-1, -1, 2, 2, -1, -1, VAULT, TRUE)
#define init_vault() vault_x = -1
#define do_vault() (vault_x != -1)
static xchar vault_x, vault_y;
static boolean made_branch; /* used only during level creation */
/* Args must be (const genericptr) so that qsort will always be happy. */
STATIC_PTR int CFDECLSPEC
do_comp(vx, vy)
const genericptr vx;
const genericptr vy;
{
#ifdef LINT
/* lint complains about possible pointer alignment problems, but we know
that vx and vy are always properly aligned. Hence, the following
bogus definition:
*/
return (vx == vy) ? 0 : -1;
#else
register const struct mkroom *x, *y;
x = (const struct mkroom *) vx;
y = (const struct mkroom *) vy;
if (x->lx < y->lx)
return -1;
return (x->lx > y->lx);
#endif /* LINT */
}
STATIC_OVL void
finddpos(cc, xl, yl, xh, yh)
coord *cc;
xchar xl, yl, xh, yh;
{
register xchar x, y;
x = rn1(xh - xl + 1, xl);
y = rn1(yh - yl + 1, yl);
if (okdoor(x, y))
goto gotit;
for (x = xl; x <= xh; x++)
for (y = yl; y <= yh; y++)
if (okdoor(x, y))
goto gotit;
for (x = xl; x <= xh; x++)
for (y = yl; y <= yh; y++)
if (IS_DOOR(levl[x][y].typ) || levl[x][y].typ == SDOOR)
goto gotit;
/* cannot find something reasonable -- strange */
x = xl;
y = yh;
gotit:
cc->x = x;
cc->y = y;
return;
}
void
sort_rooms()
{
#if defined(SYSV) || defined(DGUX)
#define CAST_nroom (unsigned) nroom
#else
#define CAST_nroom nroom /*as-is*/
#endif
qsort((genericptr_t) rooms, CAST_nroom, sizeof (struct mkroom), do_comp);
#undef CAST_nroom
}
STATIC_OVL void
do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, rtype, special, is_room)
register struct mkroom *croom;
int lowx, lowy;
register int hix, hiy;
boolean lit;
schar rtype;
boolean special;
boolean is_room;
{
register int x, y;
struct rm *lev;
/* locations might bump level edges in wall-less rooms */
/* add/subtract 1 to allow for edge locations */
if (!lowx)
lowx++;
if (!lowy)
lowy++;
if (hix >= COLNO - 1)
hix = COLNO - 2;
if (hiy >= ROWNO - 1)
hiy = ROWNO - 2;
if (lit) {
for (x = lowx - 1; x <= hix + 1; x++) {
lev = &levl[x][max(lowy - 1, 0)];
for (y = lowy - 1; y <= hiy + 1; y++)
lev++->lit = 1;
}
croom->rlit = 1;
} else
croom->rlit = 0;
croom->lx = lowx;
croom->hx = hix;
croom->ly = lowy;
croom->hy = hiy;
croom->rtype = rtype;
croom->doorct = 0;
/* if we're not making a vault, doorindex will still be 0
* if we are, we'll have problems adding niches to the previous room
* unless fdoor is at least doorindex
*/
croom->fdoor = doorindex;
croom->irregular = FALSE;
croom->nsubrooms = 0;
croom->sbrooms[0] = (struct mkroom *) 0;
if (!special) {
for (x = lowx - 1; x <= hix + 1; x++)
for (y = lowy - 1; y <= hiy + 1; y += (hiy - lowy + 2)) {
levl[x][y].typ = HWALL;
levl[x][y].horizontal = 1; /* For open/secret doors. */
}
for (x = lowx - 1; x <= hix + 1; x += (hix - lowx + 2))
for (y = lowy; y <= hiy; y++) {
levl[x][y].typ = VWALL;
levl[x][y].horizontal = 0; /* For open/secret doors. */
}
for (x = lowx; x <= hix; x++) {
lev = &levl[x][lowy];
for (y = lowy; y <= hiy; y++)
lev++->typ = ROOM;
}
if (is_room) {
levl[lowx - 1][lowy - 1].typ = TLCORNER;
levl[hix + 1][lowy - 1].typ = TRCORNER;
levl[lowx - 1][hiy + 1].typ = BLCORNER;
levl[hix + 1][hiy + 1].typ = BRCORNER;
} else { /* a subroom */
wallification(lowx - 1, lowy - 1, hix + 1, hiy + 1);
}
}
}
void
add_room(lowx, lowy, hix, hiy, lit, rtype, special)
int lowx, lowy, hix, hiy;
boolean lit;
schar rtype;
boolean special;
{
register struct mkroom *croom;
croom = &rooms[nroom];
do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, rtype, special,
(boolean) TRUE);
croom++;
croom->hx = -1;
nroom++;
}
void
add_subroom(proom, lowx, lowy, hix, hiy, lit, rtype, special)
struct mkroom *proom;
int lowx, lowy, hix, hiy;
boolean lit;
schar rtype;
boolean special;
{
register struct mkroom *croom;
croom = &subrooms[nsubroom];
do_room_or_subroom(croom, lowx, lowy, hix, hiy, lit, rtype, special,
(boolean) FALSE);
proom->sbrooms[proom->nsubrooms++] = croom;
croom++;
croom->hx = -1;
nsubroom++;
}
STATIC_OVL void
makerooms()
{
boolean tried_vault = FALSE;
/* make rooms until satisfied */
/* rnd_rect() will returns 0 if no more rects are available... */
while (nroom < MAXNROFROOMS && rnd_rect()) {
if (nroom >= (MAXNROFROOMS / 6) && rn2(2) && !tried_vault) {
tried_vault = TRUE;
if (create_vault()) {
vault_x = rooms[nroom].lx;
vault_y = rooms[nroom].ly;
rooms[nroom].hx = -1;
}
} else if (!create_room(-1, -1, -1, -1, -1, -1, OROOM, -1))
return;
}
return;
}
STATIC_OVL void
join(a, b, nxcor)
register int a, b;
boolean nxcor;
{
coord cc, tt, org, dest;
register xchar tx, ty, xx, yy;
register struct mkroom *croom, *troom;
register int dx, dy;
croom = &rooms[a];
troom = &rooms[b];
/* find positions cc and tt for doors in croom and troom
and direction for a corridor between them */
if (troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX)
return;
if (troom->lx > croom->hx) {
dx = 1;
dy = 0;
xx = croom->hx + 1;
tx = troom->lx - 1;
finddpos(&cc, xx, croom->ly, xx, croom->hy);
finddpos(&tt, tx, troom->ly, tx, troom->hy);
} else if (troom->hy < croom->ly) {
dy = -1;
dx = 0;
yy = croom->ly - 1;
finddpos(&cc, croom->lx, yy, croom->hx, yy);
ty = troom->hy + 1;
finddpos(&tt, troom->lx, ty, troom->hx, ty);
} else if (troom->hx < croom->lx) {
dx = -1;
dy = 0;
xx = croom->lx - 1;
tx = troom->hx + 1;
finddpos(&cc, xx, croom->ly, xx, croom->hy);
finddpos(&tt, tx, troom->ly, tx, troom->hy);
} else {
dy = 1;
dx = 0;
yy = croom->hy + 1;
ty = troom->ly - 1;
finddpos(&cc, croom->lx, yy, croom->hx, yy);
finddpos(&tt, troom->lx, ty, troom->hx, ty);
}
xx = cc.x;
yy = cc.y;
tx = tt.x - dx;
ty = tt.y - dy;
if (nxcor && levl[xx + dx][yy + dy].typ)
return;
if (okdoor(xx, yy) || !nxcor)
dodoor(xx, yy, croom);
org.x = xx + dx;
org.y = yy + dy;
dest.x = tx;
dest.y = ty;
if (!dig_corridor(&org, &dest, nxcor, level.flags.arboreal ? ROOM : CORR,
STONE))
return;
/* we succeeded in digging the corridor */
if (okdoor(tt.x, tt.y) || !nxcor)
dodoor(tt.x, tt.y, troom);
if (smeq[a] < smeq[b])
smeq[b] = smeq[a];
else
smeq[a] = smeq[b];
}
void
makecorridors()
{
int a, b, i;
boolean any = TRUE;
for (a = 0; a < nroom - 1; a++) {
join(a, a + 1, FALSE);
if (!rn2(50))
break; /* allow some randomness */
}
for (a = 0; a < nroom - 2; a++)
if (smeq[a] != smeq[a + 2])
join(a, a + 2, FALSE);
for (a = 0; any && a < nroom; a++) {
any = FALSE;
for (b = 0; b < nroom; b++)
if (smeq[a] != smeq[b]) {
join(a, b, FALSE);
any = TRUE;
}
}
if (nroom > 2)
for (i = rn2(nroom) + 4; i; i--) {
a = rn2(nroom);
b = rn2(nroom - 2);
if (b >= a)
b += 2;
join(a, b, TRUE);
}
}
void
add_door(x, y, aroom)
register int x, y;
register struct mkroom *aroom;
{
register struct mkroom *broom;
register int tmp;
int i;
if (aroom->doorct == 0)
aroom->fdoor = doorindex;
aroom->doorct++;
for (tmp = doorindex; tmp > aroom->fdoor; tmp--)
doors[tmp] = doors[tmp - 1];
for (i = 0; i < nroom; i++) {
broom = &rooms[i];
if (broom != aroom && broom->doorct && broom->fdoor >= aroom->fdoor)
broom->fdoor++;
}
for (i = 0; i < nsubroom; i++) {
broom = &subrooms[i];
if (broom != aroom && broom->doorct && broom->fdoor >= aroom->fdoor)
broom->fdoor++;
}
doorindex++;
doors[aroom->fdoor].x = x;
doors[aroom->fdoor].y = y;
}
STATIC_OVL void
dosdoor(x, y, aroom, type)
register xchar x, y;
struct mkroom *aroom;
int type;
{
boolean shdoor = *in_rooms(x, y, SHOPBASE) ? TRUE : FALSE;
if (!IS_WALL(levl[x][y].typ)) /* avoid SDOORs on already made doors */
type = DOOR;
levl[x][y].typ = type;
if (type == DOOR) {
if (!rn2(3)) { /* is it a locked door, closed, or a doorway? */
if (!rn2(5))
levl[x][y].doormask = D_ISOPEN;
else if (!rn2(6))
levl[x][y].doormask = D_LOCKED;
else
levl[x][y].doormask = D_CLOSED;
if (levl[x][y].doormask != D_ISOPEN && !shdoor
&& level_difficulty() >= 5 && !rn2(25))
levl[x][y].doormask |= D_TRAPPED;
} else {
#ifdef STUPID
if (shdoor)
levl[x][y].doormask = D_ISOPEN;
else
levl[x][y].doormask = D_NODOOR;
#else
levl[x][y].doormask = (shdoor ? D_ISOPEN : D_NODOOR);
#endif
}
/* also done in roguecorr(); doing it here first prevents
making mimics in place of trapped doors on rogue level */
if (Is_rogue_level(&u.uz))
levl[x][y].doormask = D_NODOOR;
if (levl[x][y].doormask & D_TRAPPED) {
struct monst *mtmp;
if (level_difficulty() >= 9 && !rn2(5)
&& !((mvitals[PM_SMALL_MIMIC].mvflags & G_GONE)
&& (mvitals[PM_LARGE_MIMIC].mvflags & G_GONE)
&& (mvitals[PM_GIANT_MIMIC].mvflags & G_GONE))) {
/* make a mimic instead */
levl[x][y].doormask = D_NODOOR;
mtmp = makemon(mkclass(S_MIMIC, 0), x, y, NO_MM_FLAGS);
if (mtmp)
set_mimic_sym(mtmp);
}
}
/* newsym(x,y); */
} else { /* SDOOR */
if (shdoor || !rn2(5))
levl[x][y].doormask = D_LOCKED;
else
levl[x][y].doormask = D_CLOSED;
if (!shdoor && level_difficulty() >= 4 && !rn2(20))
levl[x][y].doormask |= D_TRAPPED;
}
add_door(x, y, aroom);
}
STATIC_OVL boolean
place_niche(aroom, dy, xx, yy)
register struct mkroom *aroom;
int *dy, *xx, *yy;
{
coord dd;
if (rn2(2)) {
*dy = 1;
finddpos(&dd, aroom->lx, aroom->hy + 1, aroom->hx, aroom->hy + 1);
} else {
*dy = -1;
finddpos(&dd, aroom->lx, aroom->ly - 1, aroom->hx, aroom->ly - 1);
}
*xx = dd.x;
*yy = dd.y;
return (boolean) ((isok(*xx, *yy + *dy)
&& levl[*xx][*yy + *dy].typ == STONE)
&& (isok(*xx, *yy - *dy)
&& !IS_POOL(levl[*xx][*yy - *dy].typ)
&& !IS_FURNITURE(levl[*xx][*yy - *dy].typ)));
}
/* there should be one of these per trap, in the same order as trap.h */
static NEARDATA const char *trap_engravings[TRAPNUM] = {
(char *) 0, (char *) 0, (char *) 0, (char *) 0, (char *) 0,
(char *) 0, (char *) 0, (char *) 0, (char *) 0, (char *) 0,
(char *) 0, (char *) 0, (char *) 0, (char *) 0,
/* 14..16: trap door, teleport, level-teleport */
"Vlad was here", "ad aerarium", "ad aerarium", (char *) 0, (char *) 0,
(char *) 0, (char *) 0, (char *) 0, (char *) 0, (char *) 0,
};
STATIC_OVL void
makeniche(trap_type)
int trap_type;
{
register struct mkroom *aroom;
struct rm *rm;
int vct = 8;
int dy, xx, yy;
struct trap *ttmp;
if (doorindex < DOORMAX) {
while (vct--) {
aroom = &rooms[rn2(nroom)];
if (aroom->rtype != OROOM)
continue; /* not an ordinary room */
if (aroom->doorct == 1 && rn2(5))
continue;
if (!place_niche(aroom, &dy, &xx, &yy))
continue;
rm = &levl[xx][yy + dy];
if (trap_type || !rn2(4)) {
rm->typ = SCORR;
if (trap_type) {
if (is_hole(trap_type) && !Can_fall_thru(&u.uz))
trap_type = ROCKTRAP;
ttmp = maketrap(xx, yy + dy, trap_type);
if (ttmp) {
if (trap_type != ROCKTRAP)
ttmp->once = 1;
if (trap_engravings[trap_type]) {
make_engr_at(xx, yy - dy,
trap_engravings[trap_type], 0L,
DUST);
wipe_engr_at(xx, yy - dy, 5,
FALSE); /* age it a little */
}
}
}
dosdoor(xx, yy, aroom, SDOOR);
} else {
rm->typ = CORR;
if (rn2(7))
dosdoor(xx, yy, aroom, rn2(5) ? SDOOR : DOOR);
else {
/* inaccessible niches occasionally have iron bars */
if (!rn2(5) && IS_WALL(levl[xx][yy].typ)) {
levl[xx][yy].typ = IRONBARS;
if (rn2(3))
(void) mkcorpstat(CORPSE, (struct monst *) 0,
mkclass(S_HUMAN, 0), xx,
yy + dy, TRUE);
}
if (!level.flags.noteleport)
(void) mksobj_at(SCR_TELEPORTATION, xx, yy + dy, TRUE,
FALSE);
if (!rn2(3))
(void) mkobj_at(0, xx, yy + dy, TRUE);
}
}
return;
}
}
}
STATIC_OVL void
make_niches()
{
int ct = rnd((nroom >> 1) + 1), dep = depth(&u.uz);
boolean ltptr = (!level.flags.noteleport && dep > 15),
vamp = (dep > 5 && dep < 25);
while (ct--) {
if (ltptr && !rn2(6)) {
ltptr = FALSE;
makeniche(LEVEL_TELEP);
} else if (vamp && !rn2(6)) {
vamp = FALSE;
makeniche(TRAPDOOR);
} else
makeniche(NO_TRAP);
}
}
STATIC_OVL void
makevtele()
{
makeniche(TELEP_TRAP);
}
/* clear out various globals that keep information on the current level.
* some of this is only necessary for some types of levels (maze, normal,
* special) but it's easier to put it all in one place than make sure
* each type initializes what it needs to separately.
*/
STATIC_OVL void
clear_level_structures()
{
static struct rm zerorm = { cmap_to_glyph(S_stone),
0, 0, 0, 0, 0, 0, 0, 0, 0 };
register int x, y;
register struct rm *lev;
/* note: normally we'd start at x=1 because map column #0 isn't used
(except for placing vault guard at <0,0> when removed from the map
but not from the level); explicitly reset column #0 along with the
rest so that we start the new level with a completely clean slate */
for (x = 0; x < COLNO; x++) {
lev = &levl[x][0];
for (y = 0; y < ROWNO; y++) {
*lev++ = zerorm;
/*
* These used to be '#if MICROPORT_BUG',
* with use of memset(0) for '#if !MICROPORT_BUG' below,
* but memset is not appropriate for initializing pointers,
* so do these level.objects[][] and level.monsters[][]
* initializations unconditionally.
*/
level.objects[x][y] = (struct obj *) 0;
level.monsters[x][y] = (struct monst *) 0;
}
}
level.objlist = (struct obj *) 0;
level.buriedobjlist = (struct obj *) 0;
level.monlist = (struct monst *) 0;
level.damagelist = (struct damage *) 0;
level.bonesinfo = (struct cemetery *) 0;
level.flags.nfountains = 0;
level.flags.nsinks = 0;
level.flags.has_shop = 0;
level.flags.has_vault = 0;
level.flags.has_zoo = 0;
level.flags.has_court = 0;
level.flags.has_morgue = level.flags.graveyard = 0;
level.flags.has_beehive = 0;
level.flags.has_barracks = 0;
level.flags.has_temple = 0;
level.flags.has_swamp = 0;
level.flags.noteleport = 0;
level.flags.hardfloor = 0;
level.flags.nommap = 0;
level.flags.hero_memory = 1;
level.flags.shortsighted = 0;
level.flags.sokoban_rules = 0;
level.flags.is_maze_lev = 0;
level.flags.is_cavernous_lev = 0;
level.flags.arboreal = 0;
level.flags.wizard_bones = 0;
level.flags.corrmaze = 0;
nroom = 0;
rooms[0].hx = -1;
nsubroom = 0;
subrooms[0].hx = -1;
doorindex = 0;
init_rect();
init_vault();
xdnstair = ydnstair = xupstair = yupstair = 0;
sstairs.sx = sstairs.sy = 0;
xdnladder = ydnladder = xupladder = yupladder = 0;
dnstairs_room = upstairs_room = sstairs_room = (struct mkroom *) 0;
made_branch = FALSE;
clear_regions();
}
STATIC_OVL void
makelevel()
{
register struct mkroom *croom, *troom;
register int tryct;
register int x, y;
struct monst *tmonst; /* always put a web with a spider */
branch *branchp;
int room_threshold;
if (wiz1_level.dlevel == 0)
init_dungeons();
oinit(); /* assign level dependent obj probabilities */
clear_level_structures();
{
register s_level *slev = Is_special(&u.uz);
/* check for special levels */
if (slev && !Is_rogue_level(&u.uz)) {
makemaz(slev->proto);
return;
} else if (dungeons[u.uz.dnum].proto[0]) {
makemaz("");
return;
} else if (In_mines(&u.uz)) {
makemaz("minefill");
return;
} else if (In_quest(&u.uz)) {
char fillname[9];
s_level *loc_lev;
Sprintf(fillname, "%s-loca", urole.filecode);
loc_lev = find_level(fillname);
Sprintf(fillname, "%s-fil", urole.filecode);
Strcat(fillname,
(u.uz.dlevel < loc_lev->dlevel.dlevel) ? "a" : "b");
makemaz(fillname);
return;
} else if (In_hell(&u.uz)
|| (rn2(5) && u.uz.dnum == medusa_level.dnum
&& depth(&u.uz) > depth(&medusa_level))) {
makemaz("");
return;
}
}
/* otherwise, fall through - it's a "regular" level. */
if (Is_rogue_level(&u.uz)) {
makeroguerooms();
makerogueghost();
} else
makerooms();
sort_rooms();
/* construct stairs (up and down in different rooms if possible) */
croom = &rooms[rn2(nroom)];
if (!Is_botlevel(&u.uz))
mkstairs(somex(croom), somey(croom), 0, croom); /* down */
if (nroom > 1) {
troom = croom;
croom = &rooms[rn2(nroom - 1)];
if (croom == troom)
croom++;
}
if (u.uz.dlevel != 1) {
xchar sx, sy;
do {
sx = somex(croom);
sy = somey(croom);
} while (occupied(sx, sy));
mkstairs(sx, sy, 1, croom); /* up */
}
branchp = Is_branchlev(&u.uz); /* possible dungeon branch */
room_threshold = branchp ? 4 : 3; /* minimum number of rooms needed
to allow a random special room */
if (Is_rogue_level(&u.uz))
goto skip0;
makecorridors();
make_niches();
/* make a secret treasure vault, not connected to the rest */
if (do_vault()) {
xchar w, h;
debugpline0("trying to make a vault...");
w = 1;
h = 1;
if (check_room(&vault_x, &w, &vault_y, &h, TRUE)) {
fill_vault:
add_room(vault_x, vault_y, vault_x + w, vault_y + h,
TRUE, VAULT, FALSE);
level.flags.has_vault = 1;
++room_threshold;
fill_room(&rooms[nroom - 1], FALSE);
mk_knox_portal(vault_x + w, vault_y + h);
if (!level.flags.noteleport && !rn2(3))
makevtele();
} else if (rnd_rect() && create_vault()) {
vault_x = rooms[nroom].lx;
vault_y = rooms[nroom].ly;
if (check_room(&vault_x, &w, &vault_y, &h, TRUE))
goto fill_vault;
else
rooms[nroom].hx = -1;
}
}
{
register int u_depth = depth(&u.uz);
if (wizard && nh_getenv("SHOPTYPE"))
mkroom(SHOPBASE);
else if (u_depth > 1 && u_depth < depth(&medusa_level)
&& nroom >= room_threshold && rn2(u_depth) < 3)
mkroom(SHOPBASE);
else if (u_depth > 4 && !rn2(6))
mkroom(COURT);
else if (u_depth > 5 && !rn2(8)
&& !(mvitals[PM_LEPRECHAUN].mvflags & G_GONE))
mkroom(LEPREHALL);
else if (u_depth > 6 && !rn2(7))
mkroom(ZOO);
else if (u_depth > 8 && !rn2(5))
mkroom(TEMPLE);
else if (u_depth > 9 && !rn2(5)
&& !(mvitals[PM_KILLER_BEE].mvflags & G_GONE))
mkroom(BEEHIVE);
else if (u_depth > 11 && !rn2(6))
mkroom(MORGUE);
else if (u_depth > 12 && !rn2(8) && antholemon())
mkroom(ANTHOLE);
else if (u_depth > 14 && !rn2(4)
&& !(mvitals[PM_SOLDIER].mvflags & G_GONE))
mkroom(BARRACKS);
else if (u_depth > 15 && !rn2(6))
mkroom(SWAMP);
else if (u_depth > 16 && !rn2(8)
&& !(mvitals[PM_COCKATRICE].mvflags & G_GONE))
mkroom(COCKNEST);
}
skip0:
/* Place multi-dungeon branch. */
place_branch(branchp, 0, 0);
/* for each room: put things inside */
for (croom = rooms; croom->hx > 0; croom++) {
if (croom->rtype != OROOM)
continue;
/* put a sleeping monster inside */
/* Note: monster may be on the stairs. This cannot be
avoided: maybe the player fell through a trap door
while a monster was on the stairs. Conclusion:
we have to check for monsters on the stairs anyway. */
if (u.uhave.amulet || !rn2(3)) {
x = somex(croom);
y = somey(croom);
tmonst = makemon((struct permonst *) 0, x, y, MM_NOGRP);
if (tmonst && tmonst->data == &mons[PM_GIANT_SPIDER]
&& !occupied(x, y))
(void) maketrap(x, y, WEB);
}
/* put traps and mimics inside */
x = 8 - (level_difficulty() / 6);
if (x <= 1)
x = 2;
while (!rn2(x))
mktrap(0, 0, croom, (coord *) 0);
if (!rn2(3))
(void) mkgold(0L, somex(croom), somey(croom));
if (Is_rogue_level(&u.uz))
goto skip_nonrogue;
if (!rn2(10))
mkfount(0, croom);
if (!rn2(60))
mksink(croom);
if (!rn2(60))
mkaltar(croom);
x = 80 - (depth(&u.uz) * 2);
if (x < 2)
x = 2;
if (!rn2(x))
mkgrave(croom);
/* put statues inside */
if (!rn2(20))
(void) mkcorpstat(STATUE, (struct monst *) 0,
(struct permonst *) 0, somex(croom),
somey(croom), CORPSTAT_INIT);
/* put box/chest inside;
* 40% chance for at least 1 box, regardless of number
* of rooms; about 5 - 7.5% for 2 boxes, least likely
* when few rooms; chance for 3 or more is negligible.
*/
if (!rn2(nroom * 5 / 2))
(void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, somex(croom),
somey(croom), TRUE, FALSE);
/* maybe make some graffiti */
if (!rn2(27 + 3 * abs(depth(&u.uz)))) {
char buf[BUFSZ];
const char *mesg = random_engraving(buf);
if (mesg) {
do {
x = somex(croom);
y = somey(croom);
} while (levl[x][y].typ != ROOM && !rn2(40));
if (!(IS_POOL(levl[x][y].typ)
|| IS_FURNITURE(levl[x][y].typ)))
make_engr_at(x, y, mesg, 0L, MARK);
}
}
skip_nonrogue:
if (!rn2(3)) {
(void) mkobj_at(0, somex(croom), somey(croom), TRUE);
tryct = 0;
while (!rn2(5)) {
if (++tryct > 100) {
impossible("tryct overflow4");
break;
}
(void) mkobj_at(0, somex(croom), somey(croom), TRUE);
}
}
}
}
/*
* Place deposits of minerals (gold and misc gems) in the stone
* surrounding the rooms on the map.
* Also place kelp in water.
* mineralize(-1, -1, -1, -1, FALSE); => "default" behaviour
*/
void
mineralize(kelp_pool, kelp_moat, goldprob, gemprob, skip_lvl_checks)
int kelp_pool, kelp_moat, goldprob, gemprob;
boolean skip_lvl_checks;
{
s_level *sp;
struct obj *otmp;
int x, y, cnt;
if (kelp_pool < 0)
kelp_pool = 10;
if (kelp_moat < 0)
kelp_moat = 30;
/* Place kelp, except on the plane of water */
if (!skip_lvl_checks && In_endgame(&u.uz))
return;
for (x = 2; x < (COLNO - 2); x++)
for (y = 1; y < (ROWNO - 1); y++)
if ((kelp_pool && levl[x][y].typ == POOL && !rn2(kelp_pool))
|| (kelp_moat && levl[x][y].typ == MOAT && !rn2(kelp_moat)))
(void) mksobj_at(KELP_FROND, x, y, TRUE, FALSE);
/* determine if it is even allowed;
almost all special levels are excluded */
if (!skip_lvl_checks
&& (In_hell(&u.uz) || In_V_tower(&u.uz) || Is_rogue_level(&u.uz)
|| level.flags.arboreal
|| ((sp = Is_special(&u.uz)) != 0 && !Is_oracle_level(&u.uz)
&& (!In_mines(&u.uz) || sp->flags.town))))
return;
/* basic level-related probabilities */
if (goldprob < 0)
goldprob = 20 + depth(&u.uz) / 3;
if (gemprob < 0)
gemprob = goldprob / 4;
/* mines have ***MORE*** goodies - otherwise why mine? */
if (!skip_lvl_checks) {
if (In_mines(&u.uz)) {
goldprob *= 2;
gemprob *= 3;
} else if (In_quest(&u.uz)) {
goldprob /= 4;
gemprob /= 6;
}
}
/*
* Seed rock areas with gold and/or gems.
* We use fairly low level object handling to avoid unnecessary
* overhead from placing things in the floor chain prior to burial.
*/
for (x = 2; x < (COLNO - 2); x++)
for (y = 1; y < (ROWNO - 1); y++)
if (levl[x][y + 1].typ != STONE) { /* <x,y> spot not eligible */
y += 2; /* next two spots aren't eligible either */
} else if (levl[x][y].typ != STONE) { /* this spot not eligible */
y += 1; /* next spot isn't eligible either */
} else if (!(levl[x][y].wall_info & W_NONDIGGABLE)
&& levl[x][y - 1].typ == STONE
&& levl[x + 1][y - 1].typ == STONE
&& levl[x - 1][y - 1].typ == STONE
&& levl[x + 1][y].typ == STONE
&& levl[x - 1][y].typ == STONE
&& levl[x + 1][y + 1].typ == STONE
&& levl[x - 1][y + 1].typ == STONE) {
if (rn2(1000) < goldprob) {
if ((otmp = mksobj(GOLD_PIECE, FALSE, FALSE)) != 0) {
otmp->ox = x, otmp->oy = y;
otmp->quan = 1L + rnd(goldprob * 3);
otmp->owt = weight(otmp);
if (!rn2(3))
add_to_buried(otmp);
else
place_object(otmp, x, y);
}
}
if (rn2(1000) < gemprob) {
for (cnt = rnd(2 + dunlev(&u.uz) / 3); cnt > 0; cnt--)
if ((otmp = mkobj(GEM_CLASS, FALSE)) != 0) {
if (otmp->otyp == ROCK) {
dealloc_obj(otmp); /* discard it */
} else {
otmp->ox = x, otmp->oy = y;
if (!rn2(3))
add_to_buried(otmp);
else
place_object(otmp, x, y);
}
}
}
}
}
void
mklev()
{
struct mkroom *croom;
int ridx;
reseed_random(rn2);
reseed_random(rn2_on_display_rng);
init_mapseen(&u.uz);
if (getbones())
return;
in_mklev = TRUE;