/
mkroom.c
985 lines (909 loc) · 26.6 KB
/
mkroom.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
/* NetHack 3.6 mkroom.c $NHDT-Date: 1446887530 2015/11/07 09:12:10 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */
/*
* Entry points:
* mkroom() -- make and stock a room of a given type
* nexttodoor() -- return TRUE if adjacent to a door
* has_dnstairs() -- return TRUE if given room has a down staircase
* has_upstairs() -- return TRUE if given room has an up staircase
* courtmon() -- generate a court monster
* save_rooms() -- save rooms into file fd
* rest_rooms() -- restore rooms from file fd
* cmap_to_type() -- convert S_xxx symbol to XXX topology code
*/
#include "hack.h"
STATIC_DCL boolean FDECL(isbig, (struct mkroom *));
STATIC_DCL struct mkroom *FDECL(pick_room, (BOOLEAN_P));
STATIC_DCL void NDECL(mkshop), FDECL(mkzoo, (int)), NDECL(mkswamp);
STATIC_DCL void NDECL(mktemple);
STATIC_DCL coord *FDECL(shrine_pos, (int));
STATIC_DCL struct permonst *NDECL(morguemon);
STATIC_DCL struct permonst *NDECL(squadmon);
STATIC_DCL void FDECL(save_room, (int, struct mkroom *));
STATIC_DCL void FDECL(rest_room, (int, struct mkroom *));
#define sq(x) ((x) * (x))
extern const struct shclass shtypes[]; /* defined in shknam.c */
STATIC_OVL boolean
isbig(sroom)
register struct mkroom *sroom;
{
register int area = (sroom->hx - sroom->lx + 1)
* (sroom->hy - sroom->ly + 1);
return (boolean) (area > 20);
}
/* make and stock a room of a given type */
void
mkroom(roomtype)
int roomtype;
{
if (roomtype >= SHOPBASE)
mkshop(); /* someday, we should be able to specify shop type */
else
switch (roomtype) {
case COURT:
mkzoo(COURT);
break;
case ZOO:
mkzoo(ZOO);
break;
case BEEHIVE:
mkzoo(BEEHIVE);
break;
case MORGUE:
mkzoo(MORGUE);
break;
case BARRACKS:
mkzoo(BARRACKS);
break;
case SWAMP:
mkswamp();
break;
case TEMPLE:
mktemple();
break;
case LEPREHALL:
mkzoo(LEPREHALL);
break;
case COCKNEST:
mkzoo(COCKNEST);
break;
case ANTHOLE:
mkzoo(ANTHOLE);
break;
default:
impossible("Tried to make a room of type %d.", roomtype);
}
}
STATIC_OVL void
mkshop()
{
register struct mkroom *sroom;
int i = -1;
char *ep = (char *) 0; /* (init == lint suppression) */
/* first determine shoptype */
if (wizard) {
#ifndef MAC
ep = nh_getenv("SHOPTYPE");
if (ep) {
if (*ep == 'z' || *ep == 'Z') {
mkzoo(ZOO);
return;
}
if (*ep == 'm' || *ep == 'M') {
mkzoo(MORGUE);
return;
}
if (*ep == 'b' || *ep == 'B') {
mkzoo(BEEHIVE);
return;
}
if (*ep == 't' || *ep == 'T' || *ep == '\\') {
mkzoo(COURT);
return;
}
if (*ep == 's' || *ep == 'S') {
mkzoo(BARRACKS);
return;
}
if (*ep == 'a' || *ep == 'A') {
mkzoo(ANTHOLE);
return;
}
if (*ep == 'c' || *ep == 'C') {
mkzoo(COCKNEST);
return;
}
if (*ep == 'l' || *ep == 'L') {
mkzoo(LEPREHALL);
return;
}
if (*ep == '_') {
mktemple();
return;
}
if (*ep == '}') {
mkswamp();
return;
}
for (i = 0; shtypes[i].name; i++)
if (*ep == def_oc_syms[(int) shtypes[i].symb].sym)
goto gottype;
if (*ep == 'g' || *ep == 'G')
i = 0;
else if (*ep == 'v' || *ep == 'V')
i = FODDERSHOP - SHOPBASE; /* veggy food */
else
i = -1;
}
#endif
}
#ifndef MAC
gottype:
#endif
for (sroom = &rooms[0];; sroom++) {
if (sroom->hx < 0)
return;
if (sroom - rooms >= nroom) {
pline("rooms not closed by -1?");
return;
}
if (sroom->rtype != OROOM)
continue;
if (has_dnstairs(sroom) || has_upstairs(sroom))
continue;
if ((wizard && ep && sroom->doorct != 0) || sroom->doorct == 1)
break;
}
if (!sroom->rlit) {
int x, y;
for (x = sroom->lx - 1; x <= sroom->hx + 1; x++)
for (y = sroom->ly - 1; y <= sroom->hy + 1; y++)
levl[x][y].lit = 1;
sroom->rlit = 1;
}
if (i < 0) { /* shoptype not yet determined */
register int j;
/* pick a shop type at random */
for (j = rnd(100), i = 0; (j -= shtypes[i].prob) > 0; i++)
continue;
/* big rooms cannot be wand or book shops,
* - so make them general stores
*/
if (isbig(sroom) && (shtypes[i].symb == WAND_CLASS
|| shtypes[i].symb == SPBOOK_CLASS))
i = 0;
}
sroom->rtype = SHOPBASE + i;
/* set room bits before stocking the shop */
#ifdef SPECIALIZATION
topologize(sroom, FALSE); /* doesn't matter - this is a special room */
#else
topologize(sroom);
#endif
/* stock the room with a shopkeeper and artifacts */
stock_room(i, sroom);
}
/* pick an unused room, preferably with only one door */
STATIC_OVL struct mkroom *
pick_room(strict)
register boolean strict;
{
register struct mkroom *sroom;
register int i = nroom;
for (sroom = &rooms[rn2(nroom)]; i--; sroom++) {
if (sroom == &rooms[nroom])
sroom = &rooms[0];
if (sroom->hx < 0)
return (struct mkroom *) 0;
if (sroom->rtype != OROOM)
continue;
if (!strict) {
if (has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3)))
continue;
} else if (has_upstairs(sroom) || has_dnstairs(sroom))
continue;
if (sroom->doorct == 1 || !rn2(5) || wizard)
return sroom;
}
return (struct mkroom *) 0;
}
STATIC_OVL void
mkzoo(type)
int type;
{
register struct mkroom *sroom;
if ((sroom = pick_room(FALSE)) != 0) {
sroom->rtype = type;
fill_zoo(sroom);
}
}
void
mk_zoo_thronemon(x,y)
int x,y;
{
int i = rnd(level_difficulty());
int pm = (i > 9) ? PM_OGRE_KING
: (i > 5) ? PM_ELVENKING
: (i > 2) ? PM_DWARF_KING
: PM_GNOME_KING;
struct monst *mon = makemon(&mons[pm], x, y, NO_MM_FLAGS);
if (mon) {
mon->msleeping = 1;
mon->mpeaceful = 0;
set_malign(mon);
/* Give him a sceptre to pound in judgment */
(void) mongets(mon, MACE);
}
}
void
fill_zoo(sroom)
struct mkroom *sroom;
{
struct monst *mon;
register int sx, sy, i;
int sh, tx = 0, ty = 0, goldlim = 0, type = sroom->rtype;
int rmno = (int) ((sroom - rooms) + ROOMOFFSET);
coord mm;
sh = sroom->fdoor;
switch (type) {
case COURT:
if (level.flags.is_maze_lev) {
for (tx = sroom->lx; tx <= sroom->hx; tx++)
for (ty = sroom->ly; ty <= sroom->hy; ty++)
if (IS_THRONE(levl[tx][ty].typ))
goto throne_placed;
}
i = 100;
do { /* don't place throne on top of stairs */
(void) somexy(sroom, &mm);
tx = mm.x;
ty = mm.y;
} while (occupied((xchar) tx, (xchar) ty) && --i > 0);
throne_placed:
mk_zoo_thronemon(tx, ty);
break;
case BEEHIVE:
tx = sroom->lx + (sroom->hx - sroom->lx + 1) / 2;
ty = sroom->ly + (sroom->hy - sroom->ly + 1) / 2;
if (sroom->irregular) {
/* center might not be valid, so put queen elsewhere */
if ((int) levl[tx][ty].roomno != rmno || levl[tx][ty].edge) {
(void) somexy(sroom, &mm);
tx = mm.x;
ty = mm.y;
}
}
break;
case ZOO:
case LEPREHALL:
goldlim = 500 * level_difficulty();
break;
}
for (sx = sroom->lx; sx <= sroom->hx; sx++)
for (sy = sroom->ly; sy <= sroom->hy; sy++) {
if (sroom->irregular) {
if ((int) levl[sx][sy].roomno != rmno || levl[sx][sy].edge
|| (sroom->doorct
&& distmin(sx, sy, doors[sh].x, doors[sh].y) <= 1))
continue;
} else if (!SPACE_POS(levl[sx][sy].typ)
|| (sroom->doorct
&& ((sx == sroom->lx && doors[sh].x == sx - 1)
|| (sx == sroom->hx && doors[sh].x == sx + 1)
|| (sy == sroom->ly && doors[sh].y == sy - 1)
|| (sy == sroom->hy
&& doors[sh].y == sy + 1))))
continue;
/* don't place monster on explicitly placed throne */
if (type == COURT && IS_THRONE(levl[sx][sy].typ))
continue;
mon = makemon((type == COURT)
? courtmon()
: (type == BARRACKS)
? squadmon()
: (type == MORGUE)
? morguemon()
: (type == BEEHIVE)
? (sx == tx && sy == ty
? &mons[PM_QUEEN_BEE]
: &mons[PM_KILLER_BEE])
: (type == LEPREHALL)
? &mons[PM_LEPRECHAUN]
: (type == COCKNEST)
? &mons[PM_COCKATRICE]
: (type == ANTHOLE)
? antholemon()
: (struct permonst *) 0,
sx, sy, MM_ASLEEP);
if (mon) {
mon->msleeping = 1;
if (type == COURT && mon->mpeaceful) {
mon->mpeaceful = 0;
set_malign(mon);
}
}
switch (type) {
case ZOO:
case LEPREHALL:
if (sroom->doorct) {
int distval = dist2(sx, sy, doors[sh].x, doors[sh].y);
i = sq(distval);
} else
i = goldlim;
if (i >= goldlim)
i = 5 * level_difficulty();
goldlim -= i;
(void) mkgold((long) rn1(i, 10), sx, sy);
break;
case MORGUE:
if (!rn2(5))
(void) mk_tt_object(CORPSE, sx, sy);
if (!rn2(10)) /* lots of treasure buried with dead */
(void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, sx, sy,
TRUE, FALSE);
if (!rn2(5))
make_grave(sx, sy, (char *) 0);
break;
case BEEHIVE:
if (!rn2(3))
(void) mksobj_at(LUMP_OF_ROYAL_JELLY, sx, sy, TRUE,
FALSE);
break;
case BARRACKS:
if (!rn2(20)) /* the payroll and some loot */
(void) mksobj_at((rn2(3)) ? LARGE_BOX : CHEST, sx, sy,
TRUE, FALSE);
break;
case COCKNEST:
if (!rn2(3)) {
struct obj *sobj = mk_tt_object(STATUE, sx, sy);
if (sobj) {
for (i = rn2(5); i; i--)
(void) add_to_container(
sobj, mkobj(RANDOM_CLASS, FALSE));
sobj->owt = weight(sobj);
}
}
break;
case ANTHOLE:
if (!rn2(3))
(void) mkobj_at(FOOD_CLASS, sx, sy, FALSE);
break;
}
}
switch (type) {
case COURT: {
struct obj *chest, *gold;
levl[tx][ty].typ = THRONE;
(void) somexy(sroom, &mm);
gold = mksobj(GOLD_PIECE, TRUE, FALSE);
gold->quan = (long) rn1(50 * level_difficulty(), 10);
gold->owt = weight(gold);
/* the royal coffers */
chest = mksobj_at(CHEST, mm.x, mm.y, TRUE, FALSE);
add_to_container(chest, gold);
chest->owt = weight(chest);
chest->spe = 2; /* so it can be found later */
level.flags.has_court = 1;
break;
}
case BARRACKS:
level.flags.has_barracks = 1;
break;
case ZOO:
level.flags.has_zoo = 1;
break;
case MORGUE:
level.flags.has_morgue = 1;
break;
case SWAMP:
level.flags.has_swamp = 1;
break;
case BEEHIVE:
level.flags.has_beehive = 1;
break;
}
}
/* make a swarm of undead around mm */
void
mkundead(mm, revive_corpses, mm_flags)
coord *mm;
boolean revive_corpses;
int mm_flags;
{
int cnt = (level_difficulty() + 1) / 10 + rnd(5);
struct permonst *mdat;
struct obj *otmp;
coord cc;
while (cnt--) {
mdat = morguemon();
if (mdat && enexto(&cc, mm->x, mm->y, mdat)
&& (!revive_corpses
|| !(otmp = sobj_at(CORPSE, cc.x, cc.y))
|| !revive(otmp, FALSE)))
(void) makemon(mdat, cc.x, cc.y, mm_flags);
}
level.flags.graveyard = TRUE; /* reduced chance for undead corpse */
}
STATIC_OVL struct permonst *
morguemon()
{
register int i = rn2(100), hd = rn2(level_difficulty());
if (hd > 10 && i < 10) {
if (Inhell || In_endgame(&u.uz)) {
return mkclass(S_DEMON, 0);
} else {
int ndemon_res = ndemon(A_NONE);
if (ndemon_res != NON_PM)
return &mons[ndemon_res];
/* else do what? As is, it will drop to ghost/wraith/zombie */
}
}
if (hd > 8 && i > 85)
return mkclass(S_VAMPIRE, 0);
return ((i < 20) ? &mons[PM_GHOST]
: (i < 40) ? &mons[PM_WRAITH]
: mkclass(S_ZOMBIE, 0));
}
struct permonst *
antholemon()
{
int mtyp, indx, trycnt = 0;
/* casts are for dealing with time_t */
indx = (int) ((long) ubirthday % 3L);
indx += level_difficulty();
/* Same monsters within a level, different ones between levels */
do {
switch ((indx + trycnt) % 3) {
case 0:
mtyp = PM_SOLDIER_ANT;
break;
case 1:
mtyp = PM_FIRE_ANT;
break;
default:
mtyp = PM_GIANT_ANT;
break;
}
/* try again if chosen type has been genocided or used up */
} while (++trycnt < 3 && (mvitals[mtyp].mvflags & G_GONE));
return ((mvitals[mtyp].mvflags & G_GONE) ? (struct permonst *) 0
: &mons[mtyp]);
}
STATIC_OVL void
mkswamp() /* Michiel Huisjes & Fred de Wilde */
{
register struct mkroom *sroom;
register int sx, sy, i, eelct = 0;
for (i = 0; i < 5; i++) { /* turn up to 5 rooms swampy */
sroom = &rooms[rn2(nroom)];
if (sroom->hx < 0 || sroom->rtype != OROOM || has_upstairs(sroom)
|| has_dnstairs(sroom))
continue;
/* satisfied; make a swamp */
sroom->rtype = SWAMP;
for (sx = sroom->lx; sx <= sroom->hx; sx++)
for (sy = sroom->ly; sy <= sroom->hy; sy++)
if (!OBJ_AT(sx, sy) && !MON_AT(sx, sy) && !t_at(sx, sy)
&& !nexttodoor(sx, sy)) {
if ((sx + sy) % 2) {
levl[sx][sy].typ = POOL;
if (!eelct || !rn2(4)) {
/* mkclass() won't do, as we might get kraken */
(void) makemon(rn2(5)
? &mons[PM_GIANT_EEL]
: rn2(2)
? &mons[PM_PIRANHA]
: &mons[PM_ELECTRIC_EEL],
sx, sy, NO_MM_FLAGS);
eelct++;
}
} else if (!rn2(4)) /* swamps tend to be moldy */
(void) makemon(mkclass(S_FUNGUS, 0), sx, sy,
NO_MM_FLAGS);
}
level.flags.has_swamp = 1;
}
}
STATIC_OVL coord *
shrine_pos(roomno)
int roomno;
{
static coord buf;
int delta;
struct mkroom *troom = &rooms[roomno - ROOMOFFSET];
/* if width and height are odd, placement will be the exact center;
if either or both are even, center point is a hypothetical spot
between map locations and placement will be adjacent to that */
delta = troom->hx - troom->lx;
buf.x = troom->lx + delta / 2;
if ((delta % 2) && rn2(2))
buf.x++;
delta = troom->hy - troom->ly;
buf.y = troom->ly + delta / 2;
if ((delta % 2) && rn2(2))
buf.y++;
return &buf;
}
STATIC_OVL void
mktemple()
{
register struct mkroom *sroom;
coord *shrine_spot;
register struct rm *lev;
if (!(sroom = pick_room(TRUE)))
return;
/* set up Priest and shrine */
sroom->rtype = TEMPLE;
/*
* In temples, shrines are blessed altars
* located in the center of the room
*/
shrine_spot = shrine_pos((int) ((sroom - rooms) + ROOMOFFSET));
lev = &levl[shrine_spot->x][shrine_spot->y];
lev->typ = ALTAR;
lev->altarmask = induced_align(80);
priestini(&u.uz, sroom, shrine_spot->x, shrine_spot->y, FALSE);
lev->altarmask |= AM_SHRINE;
level.flags.has_temple = 1;
}
boolean
nexttodoor(sx, sy)
register int sx, sy;
{
register int dx, dy;
register struct rm *lev;
for (dx = -1; dx <= 1; dx++)
for (dy = -1; dy <= 1; dy++) {
if (!isok(sx + dx, sy + dy))
continue;
lev = &levl[sx + dx][sy + dy];
if (IS_DOOR(lev->typ) || lev->typ == SDOOR)
return TRUE;
}
return FALSE;
}
boolean
has_dnstairs(sroom)
register struct mkroom *sroom;
{
if (sroom == dnstairs_room)
return TRUE;
if (sstairs.sx && !sstairs.up)
return (boolean) (sroom == sstairs_room);
return FALSE;
}
boolean
has_upstairs(sroom)
register struct mkroom *sroom;
{
if (sroom == upstairs_room)
return TRUE;
if (sstairs.sx && sstairs.up)
return (boolean) (sroom == sstairs_room);
return FALSE;
}
int
somex(croom)
register struct mkroom *croom;
{
return rn1(croom->hx - croom->lx + 1, croom->lx);
}
int
somey(croom)
register struct mkroom *croom;
{
return rn1(croom->hy - croom->ly + 1, croom->ly);
}
boolean
inside_room(croom, x, y)
struct mkroom *croom;
xchar x, y;
{
return (boolean) (x >= croom->lx - 1 && x <= croom->hx + 1
&& y >= croom->ly - 1 && y <= croom->hy + 1);
}
boolean
somexy(croom, c)
struct mkroom *croom;
coord *c;
{
int try_cnt = 0;
int i;
if (croom->irregular) {
i = (int) ((croom - rooms) + ROOMOFFSET);
while (try_cnt++ < 100) {
c->x = somex(croom);
c->y = somey(croom);
if (!levl[c->x][c->y].edge && (int) levl[c->x][c->y].roomno == i)
return TRUE;
}
/* try harder; exhaustively search until one is found */
for (c->x = croom->lx; c->x <= croom->hx; c->x++)
for (c->y = croom->ly; c->y <= croom->hy; c->y++)
if (!levl[c->x][c->y].edge
&& (int) levl[c->x][c->y].roomno == i)
return TRUE;
return FALSE;
}
if (!croom->nsubrooms) {
c->x = somex(croom);
c->y = somey(croom);
return TRUE;
}
/* Check that coords doesn't fall into a subroom or into a wall */
while (try_cnt++ < 100) {
c->x = somex(croom);
c->y = somey(croom);
if (IS_WALL(levl[c->x][c->y].typ))
continue;
for (i = 0; i < croom->nsubrooms; i++)
if (inside_room(croom->sbrooms[i], c->x, c->y))
goto you_lose;
break;
you_lose:
;
}
if (try_cnt >= 100)
return FALSE;
return TRUE;
}
/*
* Search for a special room given its type (zoo, court, etc...)
* Special values :
* - ANY_SHOP
* - ANY_TYPE
*/
struct mkroom *
search_special(type)
schar type;
{
register struct mkroom *croom;
for (croom = &rooms[0]; croom->hx >= 0; croom++)
if ((type == ANY_TYPE && croom->rtype != OROOM)
|| (type == ANY_SHOP && croom->rtype >= SHOPBASE)
|| croom->rtype == type)
return croom;
for (croom = &subrooms[0]; croom->hx >= 0; croom++)
if ((type == ANY_TYPE && croom->rtype != OROOM)
|| (type == ANY_SHOP && croom->rtype >= SHOPBASE)
|| croom->rtype == type)
return croom;
return (struct mkroom *) 0;
}
struct permonst *
courtmon()
{
int i = rn2(60) + rn2(3 * level_difficulty());
if (i > 100)
return mkclass(S_DRAGON, 0);
else if (i > 95)
return mkclass(S_GIANT, 0);
else if (i > 85)
return mkclass(S_TROLL, 0);
else if (i > 75)
return mkclass(S_CENTAUR, 0);
else if (i > 60)
return mkclass(S_ORC, 0);
else if (i > 45)
return &mons[PM_BUGBEAR];
else if (i > 30)
return &mons[PM_HOBGOBLIN];
else if (i > 15)
return mkclass(S_GNOME, 0);
else
return mkclass(S_KOBOLD, 0);
}
#define NSTYPES (PM_CAPTAIN - PM_SOLDIER + 1)
static struct {
unsigned pm;
unsigned prob;
} squadprob[NSTYPES] = { { PM_SOLDIER, 80 },
{ PM_SERGEANT, 15 },
{ PM_LIEUTENANT, 4 },
{ PM_CAPTAIN, 1 } };
/* return soldier types. */
STATIC_OVL struct permonst *
squadmon()
{
int sel_prob, i, cpro, mndx;
sel_prob = rnd(80 + level_difficulty());
cpro = 0;
for (i = 0; i < NSTYPES; i++) {
cpro += squadprob[i].prob;
if (cpro > sel_prob) {
mndx = squadprob[i].pm;
goto gotone;
}
}
mndx = squadprob[rn2(NSTYPES)].pm;
gotone:
if (!(mvitals[mndx].mvflags & G_GONE))
return &mons[mndx];
else
return (struct permonst *) 0;
}
/*
* save_room : A recursive function that saves a room and its subrooms
* (if any).
*/
STATIC_OVL void
save_room(fd, r)
int fd;
struct mkroom *r;
{
short i;
/*
* Well, I really should write only useful information instead
* of writing the whole structure. That is I should not write
* the subrooms pointers, but who cares ?
*/
bwrite(fd, (genericptr_t) r, sizeof (struct mkroom));
for (i = 0; i < r->nsubrooms; i++)
save_room(fd, r->sbrooms[i]);
}
/*
* save_rooms : Save all the rooms on disk!
*/
void
save_rooms(fd)
int fd;
{
short i;
/* First, write the number of rooms */
bwrite(fd, (genericptr_t) &nroom, sizeof(nroom));
for (i = 0; i < nroom; i++)
save_room(fd, &rooms[i]);
}
STATIC_OVL void
rest_room(fd, r)
int fd;
struct mkroom *r;
{
short i;
mread(fd, (genericptr_t) r, sizeof(struct mkroom));
for (i = 0; i < r->nsubrooms; i++) {
r->sbrooms[i] = &subrooms[nsubroom];
rest_room(fd, &subrooms[nsubroom]);
subrooms[nsubroom++].resident = (struct monst *) 0;
}
}
/*
* rest_rooms : That's for restoring rooms. Read the rooms structure from
* the disk.
*/
void
rest_rooms(fd)
int fd;
{
short i;
mread(fd, (genericptr_t) &nroom, sizeof(nroom));
nsubroom = 0;
for (i = 0; i < nroom; i++) {
rest_room(fd, &rooms[i]);
rooms[i].resident = (struct monst *) 0;
}
rooms[nroom].hx = -1; /* restore ending flags */
subrooms[nsubroom].hx = -1;
}
/* convert a display symbol for terrain into topology type;
used for remembered terrain when mimics pose as furniture */
int
cmap_to_type(sym)
int sym;
{
int typ = STONE; /* catchall */
switch (sym) {
case S_stone:
typ = STONE;
break;
case S_vwall:
typ = VWALL;
break;
case S_hwall:
typ = HWALL;
break;
case S_tlcorn:
typ = TLCORNER;
break;
case S_trcorn:
typ = TRCORNER;
break;
case S_blcorn:
typ = BLCORNER;
break;
case S_brcorn:
typ = BRCORNER;
break;
case S_crwall:
typ = CROSSWALL;
break;
case S_tuwall:
typ = TUWALL;
break;
case S_tdwall:
typ = TDWALL;
break;
case S_tlwall:
typ = TLWALL;
break;
case S_trwall:
typ = TRWALL;
break;
case S_ndoor: /* no door (empty doorway) */
case S_vodoor: /* open door in vertical wall */
case S_hodoor: /* open door in horizontal wall */
case S_vcdoor: /* closed door in vertical wall */
case S_hcdoor:
typ = DOOR;
break;
case S_bars:
typ = IRONBARS;
break;
case S_tree:
typ = TREE;
break;
case S_room:
typ = ROOM;
break;
case S_corr:
case S_litcorr:
typ = CORR;
break;
case S_upstair:
case S_dnstair:
typ = STAIRS;
break;
case S_upladder:
case S_dnladder:
typ = LADDER;
break;
case S_altar:
typ = ALTAR;
break;
case S_grave:
typ = GRAVE;
break;
case S_throne:
typ = THRONE;
break;
case S_sink:
typ = SINK;
break;
case S_fountain:
typ = FOUNTAIN;
break;
case S_pool:
typ = POOL;
break;
case S_ice:
typ = ICE;
break;
case S_lava:
typ = LAVAPOOL;
break;
case S_vodbridge: /* open drawbridge spanning north/south */
case S_hodbridge:
typ = DRAWBRIDGE_DOWN;
break; /* east/west */
case S_vcdbridge: /* closed drawbridge in vertical wall */
case S_hcdbridge:
typ = DBWALL;
break;
case S_air:
typ = AIR;
break;
case S_cloud:
typ = CLOUD;
break;
case S_water:
typ = WATER;
break;
default:
break; /* not a cmap symbol? */
}
return typ;
}
/*mkroom.c*/