-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate.c
1983 lines (1574 loc) · 43 KB
/
generate.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
/* File: generate.c */
/*
* Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
*
* This software may be copied and distributed for educational, research,
* and not for profit purposes provided that this copyright and statement
* are included in all such copies. Other copyrights may also apply.
*/
#include "z-rand.h"
#include "h-define.h"
#include "h-type.h"
#include "defines.h"
#include "externs.h"
/*
* Note that Level generation is *not* an important bottleneck,
* though it can be annoyingly slow on older machines... Thus
* we emphasize "simplicity" and "correctness" over "speed".
*
* This entire file is only needed for generating levels.
* This may allow smart compilers to only load it when needed.
*
* Consider the "v_info.txt" file for vault generation.
*
* In this file, we use the "special" granite and perma-wall sub-types,
* where "basic" is normal, "inner" is inside a room, "outer" is the
* outer wall of a room, and "solid" is the outer wall of the dungeon
* or any walls that may not be pierced by corridors. Thus the only
* wall type that may be pierced by a corridor is the "outer granite"
* type. The "basic granite" type yields the "actual" corridors.
*
* Note that we use the special "solid" granite wall type to prevent
* multiple corridors from piercing a wall in two adjacent locations,
* which would be messy, and we use the special "outer" granite wall
* to indicate which walls "surround" rooms, and may thus be "pierced"
* by corridors entering or leaving the room.
*
* Note that a tunnel which attempts to leave a room near the "edge"
* of the dungeon in a direction toward that edge will cause "silly"
* wall piercings, but will have no permanently incorrect effects,
* as long as the tunnel can *eventually* exit from another side.
* And note that the wall may not come back into the room by the
* hole it left through, so it must bend to the left or right and
* then optionally re-enter the room (at least 2 grids away). This
* is not a problem since every room that is large enough to block
* the passage of tunnels is also large enough to allow the tunnel
* to pierce the room itself several times.
*
* Note that no two corridors may enter a room through adjacent grids,
* they must either share an entryway or else use entryways at least
* two grids apart. This prevents "large" (or "silly") doorways.
*
* To create rooms in the dungeon, we first divide the dungeon up
* into "blocks" of 11x11 grids each, and require that all rooms
* occupy a rectangular group of blocks. As long as each room type
* reserves a sufficient number of blocks, the room building routines
* will not need to check bounds. Note that most of the normal rooms
* actually only use 23x11 grids, and so reserve 33x11 grids.
*
* Note that the use of 11x11 blocks (instead of the 33x11 panels)
* allows more variability in the horizontal placement of rooms, and
* at the same time has the disadvantage that some rooms (two thirds
* of the normal rooms) may be "split" by panel boundaries. This can
* induce a situation where a player is in a room and part of the room
* is off the screen. This can be so annoying that the player must set
* a special option to enable "non-aligned" room generation.
*
* Note that the dungeon generation routines are much different (2.7.5)
* and perhaps "DUN_ROOMS" should be less than 50.
*
* XXX XXX XXX Note that it is possible to create a room which is only
* connected to itself, because the "tunnel generation" code allows a
* tunnel to leave a room, wander around, and then re-enter the room.
*
* XXX XXX XXX Note that it is possible to create a set of rooms which
* are only connected to other rooms in that set, since there is nothing
* explicit in the code to prevent this from happening. But this is less
* likely than the "isolated room" problem, because each room attempts to
* connect to another room, in a giant cycle, thus requiring at least two
* bizarre occurances to create an isolated section of the dungeon.
*
* Note that (2.7.9) monster pits have been split into monster "nests"
* and monster "pits". The "nests" have a collection of monsters of a
* given type strewn randomly around the room (jelly, animal, or undead),
* while the "pits" have a collection of monsters of a given type placed
* around the room in an organized manner (orc, troll, giant, dragon, or
* demon). Note that both "nests" and "pits" are now "level dependant",
* and both make 16 "expensive" calls to the "get_mon_num()" function.
*
* Note that the cave grid flags changed in a rather drastic manner
* for Angband 2.8.0 (and 2.7.9+), in particular, dungeon terrain
* features, such as doors and stairs and traps and rubble and walls,
* are all handled as a set of 64 possible "terrain features", and
* not as "fake" objects (440-479) as in pre-2.8.0 versions.
*
* The 64 new "dungeon features" will also be used for "visual display"
* but we must be careful not to allow, for example, the user to display
* hidden traps in a different way from floors, or secret doors in a way
* different from granite walls, or even permanent granite in a different
* way from granite. XXX XXX XXX
*/
/*
* Dungeon generation values
*/
#define DUN_ROOMS 100 /* Number of rooms to attempt */
#define DUN_UNUSUAL 200 /* Level/chance of unusual room */
#define DUN_DEST 15 /* 1/chance of having a destroyed level */
/*
* Dungeon tunnel generation values
*/
#define DUN_TUN_RND 10 /* Chance of random direction */
#define DUN_TUN_CHG 30 /* Chance of changing direction */
#define DUN_TUN_CON 15 /* Chance of extra tunneling */
#define DUN_TUN_PEN 25 /* Chance of doors at room entrances */
#define DUN_TUN_JCT 90 /* Chance of doors at tunnel junctions */
/*
* Dungeon streamer generation values
*/
#define DUN_STR_DEN 5 /* Density of streamers */
#define DUN_STR_RNG 2 /* Width of streamers */
#define DUN_STR_MAG 3 /* Number of magma streamers */
#define DUN_STR_MC 90 /* 1/chance of treasure per magma */
#define DUN_STR_QUA 2 /* Number of quartz streamers */
#define DUN_STR_QC 40 /* 1/chance of treasure per quartz */
/*
* Dungeon treausre allocation values
*/
#define DUN_AMT_ROOM 24 /* Amount of objects for rooms */
#define DUN_AMT_ITEM 12 /* Amount of objects for rooms/corridors */
#define DUN_AMT_GOLD 6 /* Amount of treasure for rooms/corridors */
/*
* Hack -- Dungeon allocation "places"
*/
#define ALLOC_SET_CORR 1 /* Hallway */
#define ALLOC_SET_ROOM 2 /* Room */
#define ALLOC_SET_BOTH 3 /* Anywhere */
/*
* Hack -- Dungeon allocation "types"
*/
#define ALLOC_TYP_RUBBLE 1 /* Rubble */
#define ALLOC_TYP_TRAP 3 /* Trap */
#define ALLOC_TYP_GOLD 4 /* Gold */
#define ALLOC_TYP_OBJECT 5 /* Object */
/*
* Maximum numbers of rooms along each axis (currently 6x18)
*/
#define MAX_ROOMS_ROW (DUNGEON_HGT / BLOCK_HGT)
#define MAX_ROOMS_COL (DUNGEON_WID / BLOCK_WID)
/*
* Bounds on some arrays used in the "dun_data" structure.
* These bounds are checked, though usually this is a formality.
*/
#define CENT_MAX 100
#define DOOR_MAX 200
#define WALL_MAX 500
#define TUNN_MAX 900
/*
* Maximal number of room types
*/
#define ROOM_MAX 5
/*
* Simple structure to hold a map location
*/
typedef struct coord coord;
struct coord
{
byte y;
byte x;
};
/*
* Room type information
*/
typedef struct room_data room_data;
struct room_data
{
/* Required size in blocks */
s16b dy1, dy2, dx1, dx2;
/* Hack -- minimum level */
s16b level;
};
/*
* Structure to hold all "dungeon generation" data
*/
typedef struct dun_data dun_data;
struct dun_data
{
/* Array of centers of rooms */
int cent_n;
coord cent[CENT_MAX];
/* Array of possible door locations */
int door_n;
coord door[DOOR_MAX];
/* Array of wall piercing locations */
int wall_n;
coord wall[WALL_MAX];
/* Array of tunnel grids */
int tunn_n;
coord tunn[TUNN_MAX];
/* Number of blocks along each axis */
int row_rooms;
int col_rooms;
/* Array of which blocks are used */
bool room_map[MAX_ROOMS_ROW][MAX_ROOMS_COL];
/* Hack -- there is a pit/nest on this level */
bool crowded;
};
/*
* Dungeon generation data -- see "cave_gen()"
*/
static dun_data *dun;
/*
* Array of room types (assumes 11x11 blocks)
*/
static room_data room[ROOM_MAX] =
{
{ 0, 0, 0, 0, 0 }, /* 0 = Nothing */
{ 0, 0, -1, 1, 1 }, /* 1 = Simple (33x11) */
{ 0, 0, -1, 1, 1 }, /* 2 = Overlapping (33x11) */
{ 0, 0, -1, 1, 3 }, /* 3 = Crossed (33x11) */
{ 0, 0, -1, 1, 3 }, /* 4 = Large (33x11) */
};
/*
* Always picks a correct direction
*/
static void correct_dir(int *rdir, int *cdir, int y1, int x1, int y2, int x2)
{
/* Extract vertical and horizontal directions */
*rdir = (y1 == y2) ? 0 : (y1 < y2) ? 1 : -1;
*cdir = (x1 == x2) ? 0 : (x1 < x2) ? 1 : -1;
/* Never move diagonally */
if (*rdir && *cdir)
{
if (rand_int(100) < 50)
{
*rdir = 0;
}
else
{
*cdir = 0;
}
}
}
/*
* Pick a random direction
*/
static void rand_dir(int *rdir, int *cdir)
{
/* Pick a random direction */
int i = rand_int(4);
/* Extract the dy/dx components */
*rdir = ddy_ddd[i];
*cdir = ddx_ddd[i];
}
/*
* Returns random co-ordinates for player/monster/object
*/
static void new_player_spot(void)
{
int y, x;
/* Place the player */
while (1)
{
/* Pick a legal spot */
y = rand_range(1, DUNGEON_HGT - 2);
x = rand_range(1, DUNGEON_WID - 2);
/* Must be a "naked" floor grid */
if (!cave_naked_bold(y, x)) continue;
/* Refuse to start on anti-teleport grids */
if (cave_info[y][x] & (CAVE_ICKY)) continue;
/* Done */
break;
}
/* Place the player */
player_place(y, x);
}
/*
* Count the number of walls adjacent to the given grid.
*
* Note -- Assumes "in_bounds_fully(y, x)"
*
* We count only granite walls and permanent walls.
*/
static int next_to_walls(int y, int x)
{
int k = 0;
if (cave_feat[y+1][x] >= FEAT_WALL_EXTRA) k++;
if (cave_feat[y-1][x] >= FEAT_WALL_EXTRA) k++;
if (cave_feat[y][x+1] >= FEAT_WALL_EXTRA) k++;
if (cave_feat[y][x-1] >= FEAT_WALL_EXTRA) k++;
return (k);
}
/*
* Convert existing terrain type to rubble
*/
static void place_rubble(int y, int x)
{
/* Create rubble */
/* cave_set_feat(y, x, FEAT_RUBBLE); don't do that */
}
/*
* Convert existing terrain type to "up stairs"
*/
static void place_up_stairs(int y, int x)
{
/* Create up stairs */
cave_set_feat(y, x, FEAT_LESS);
}
/*
* Convert existing terrain type to "down stairs"
*/
static void place_down_stairs(int y, int x)
{
/* Create down stairs */
cave_set_feat(y, x, FEAT_MORE);
}
/*
* Place an up/down staircase at given location
*/
static void place_random_stairs(int y, int x)
{
/* Paranoia */
if (!cave_clean_bold(y, x)) return;
/* Choose a staircase */
if (rand_int(100) < 50)
{
place_down_stairs(y, x);
}
else
{
place_up_stairs(y, x);
}
}
/*
* Place a secret door at the given location
*/
static void place_secret_door(int y, int x, int sector)
{
/* Create secret door */
cave_set_feat(y, x, FEAT_SECRET);
cave_sector_map[y][x]=sector;
}
/*
* Place a random type of door at the given location
*/
static void place_random_door(int y, int x)
{
int tmp;
/* Choose an object */
tmp = rand_int(5);
if(tmp==1) {
cave_set_feat(y, x, FEAT_SECRET);
} else {
cave_set_feat(y, x, FEAT_DOOR_HEAD);
}
cave_sector_map[y][x]=++sector_counter;
}
/*
* Places some staircases near walls
*/
static void alloc_stairs(int feat, int num, int walls)
{
int y, x, i, j, flag;
/* Place "num" stairs */
for (i = 0; i < num; i++)
{
/* Place some stairs */
for (flag = FALSE; !flag; )
{
/* Try several times, then decrease "walls" */
for (j = 0; !flag && j <= 3000; j++)
{
/* Pick a random grid */
y = rand_int(DUNGEON_HGT);
x = rand_int(DUNGEON_WID);
/* Require "naked" floor grid */
if (!cave_naked_bold(y, x)) continue;
/* Require a certain number of adjacent walls */
if (next_to_walls(y, x) < walls) continue;
/* Clear previous contents, add stairs */
cave_set_feat(y, x, feat);
/* All done */
flag = TRUE;
}
/* Require fewer walls */
if (walls) walls--;
}
}
}
/*
* Allocates some objects (using "place" and "type")
*/
static void alloc_object(int set, int typ, int num)
{
int y, x, k;
/* Place some objects */
for (k = 0; k < num; k++)
{
/* Pick a "legal" spot */
while (TRUE)
{
bool room;
/* Location */
y = rand_int(DUNGEON_HGT);
x = rand_int(DUNGEON_WID);
/* Require "naked" floor grid */
if (!cave_naked_bold(y, x)) continue;
/* Check for "room" */
room = (cave_info[y][x] & (CAVE_ROOM)) ? TRUE : FALSE;
/* Require corridor? */
if ((set == ALLOC_SET_CORR) && room) continue;
/* Require room? */
if ((set == ALLOC_SET_ROOM) && !room) continue;
/* Accept it */
break;
}
/* Place something */
switch (typ)
{
case ALLOC_TYP_RUBBLE:
{
place_rubble(y, x);
break;
}
case ALLOC_TYP_TRAP:
{
place_trap(y, x);
break;
}
case ALLOC_TYP_GOLD:
{
place_gold(y, x);
break;
}
case ALLOC_TYP_OBJECT:
{
place_object(y, x, FALSE, FALSE);
break;
}
}
}
}
/*
* Places "streamers" of rock through dungeon
*
* Note that their are actually six different terrain features used
* to represent streamers. Three each of magma and quartz, one for
* basic vein, one with hidden gold, and one with known gold. The
* hidden gold types are currently unused.
*/
static void build_streamer(int feat, int chance)
{
int i, tx, ty;
int y, x, dir;
/* Hack -- Choose starting point */
y = rand_spread(DUNGEON_HGT / 2, 10);
x = rand_spread(DUNGEON_WID / 2, 15);
/* Choose a random compass direction */
dir = ddd[rand_int(8)];
/* Place streamer into dungeon */
while (TRUE)
{
/* One grid per density */
for (i = 0; i < DUN_STR_DEN; i++)
{
int d = DUN_STR_RNG;
/* Pick a nearby grid */
while (1)
{
ty = rand_spread(y, d);
tx = rand_spread(x, d);
if (!in_bounds(ty, tx)) continue;
break;
}
/* Only convert "granite" walls */
if (cave_feat[ty][tx] < FEAT_WALL_EXTRA) continue;
if (cave_feat[ty][tx] > FEAT_WALL_SOLID) continue;
/* Clear previous contents, add proper vein type */
cave_set_feat(ty, tx, feat);
/* Hack -- Add some (known) treasure */
if (rand_int(chance) == 0) cave_feat[ty][tx] += 0x04;
}
/* Advance the streamer */
y += ddy[dir];
x += ddx[dir];
/* Stop at dungeon edge */
if (!in_bounds(y, x)) break;
}
}
/*
* Create up to "num" objects near the given coordinates
* Only really called by some of the "vault" routines.
*/
static void vault_objects(int y, int x, int num)
{
int i, j, k;
/* Attempt to place 'num' objects */
for (; num > 0; --num)
{
/* Try up to 11 spots looking for empty space */
for (i = 0; i < 11; ++i)
{
/* Pick a random location */
while (1)
{
j = rand_spread(y, 2);
k = rand_spread(x, 3);
if (!in_bounds(j, k)) continue;
break;
}
/* Require "clean" floor space */
if (!cave_clean_bold(j, k)) continue;
/* Place an item */
if (rand_int(100) < 75)
{
place_object(j, k, FALSE, FALSE);
}
/* Place gold */
else
{
place_gold(j, k);
}
/* Placement accomplished */
break;
}
}
}
/*
* Place a trap with a given displacement of point
*/
static void vault_trap_aux(int y, int x, int yd, int xd)
{
int count, y1, x1;
/* Place traps */
for (count = 0; count <= 5; count++)
{
/* Get a location */
while (1)
{
y1 = rand_spread(y, yd);
x1 = rand_spread(x, xd);
if (!in_bounds(y1, x1)) continue;
break;
}
/* Require "naked" floor grids */
if (!cave_naked_bold(y1, x1)) continue;
/* Place the trap */
place_trap(y1, x1);
/* Done */
break;
}
}
/*
* Place some traps with a given displacement of given location
*/
static void vault_traps(int y, int x, int yd, int xd, int num)
{
int i;
for (i = 0; i < num; i++)
{
vault_trap_aux(y, x, yd, xd);
}
}
/*
* Generate helper -- create a new room with optional light
*/
static void generate_room(int y1, int x1, int y2, int x2, int light)
{
int y, x;
for (y = y1; y <= y2; y++)
{
for (x = x1; x <= x2; x++)
{
cave_info[y][x] |= (CAVE_ROOM);
if (light) cave_info[y][x] |= (CAVE_GLOW);
}
}
}
/*
* Generate helper -- fill a rectangle with a feature
*/
static void generate_fill(int y1, int x1, int y2, int x2, int feat, int sector)
{
int y, x;
for (y = y1; y <= y2; y++)
{
for (x = x1; x <= x2; x++)
{
cave_set_feat(y, x, feat);
cave_sector_map[y][x]=sector;
}
}
}
/*
* Generate helper -- draw a rectangle with a feature
*/
static void generate_draw(int y1, int x1, int y2, int x2, int feat, int sector)
{
int y, x;
for (y = y1; y <= y2; y++)
{
cave_set_feat(y, x1, feat);
cave_set_feat(y, x2, feat);
cave_sector_map[y][x1]=sector;
cave_sector_map[y][x2]=sector;
}
for (x = x1; x <= x2; x++)
{
cave_set_feat(y1, x, feat);
cave_set_feat(y2, x, feat);
cave_sector_map[y1][x]=sector;
cave_sector_map[y2][x]=sector;
}
}
/*
* Generate helper -- split a rectangle with a feature
*/
static void generate_plus(int y1, int x1, int y2, int x2, int feat, int sector)
{
int y, x;
int y0, x0;
/* Center */
y0 = (y1 + y2) / 2;
x0 = (x1 + x2) / 2;
for (y = y1; y <= y2; y++)
{
cave_set_feat(y, x0, feat);
cave_sector_map[y][x0]=sector;
}
for (x = x1; x <= x2; x++)
{
cave_set_feat(y0, x, feat);
cave_sector_map[y0][x]=sector;
}
}
/*
* Generate helper -- open one side of a rectangle with a feature
*/
static void generate_hole(int y1, int x1, int y2, int x2, int feat, int sector)
{
int y0, x0;
/* Center */
y0 = (y1 + y2) / 2;
x0 = (x1 + x2) / 2;
/* Open random side */
switch (rand_int(4))
{
case 0:
{
cave_set_feat(y1, x0, feat);
cave_sector_map[y1][x0]=sector;
break;
}
case 1:
{
cave_set_feat(y0, x1, feat);
cave_sector_map[y0][x1]=sector;
break;
}
case 2:
{
cave_set_feat(y2, x0, feat);
cave_sector_map[y2][x0]=sector;
break;
}
case 3:
{
cave_set_feat(y0, x2, feat);
cave_sector_map[y0][x2]=sector;
break;
}
}
}
/*
* Hack -- Place some sleeping monsters near the given location
*/
static void vault_monsters(int y1, int x1, int num)
{
int k, i, y, x;
/* Try to summon "num" monsters "near" the given location */
for (k = 0; k < num; k++)
{
/* Try nine locations */
for (i = 0; i < 9; i++)
{
int d = 1;
/* Pick a nearby location */
scatter(&y, &x, y1, x1, d, 0);
/* Require "empty" floor grids */
if (!cave_empty_bold(y, x)) continue;
/* Place the monster (allow groups) */
(void)place_monster(y, x, TRUE, TRUE);
}
}
}
/*
* Room building routines.
*
* Six basic room types:
* 1 -- normal
* 2 -- overlapping
* 3 -- cross shaped
* 4 -- large room with features
* 5 -- monster nests
* 6 -- monster pits
* 7 -- simple vaults
* 8 -- greater vaults
*/
/*
* Type 1 -- normal rectangular rooms
*/
static void build_type1(int y0, int x0)
{
int y, x;
int y1, x1, y2, x2;
int light = FALSE;
/* Pick a room size */
y1 = y0 - randint(4);
x1 = x0 - randint(11);
y2 = y0 + randint(3);
x2 = x0 + randint(11);
/* Generate new room */
generate_room(y1-1, x1-1, y2+1, x2+1, light);
/* Generate outer walls */
generate_draw(y1-1, x1-1, y2+1, x2+1, FEAT_WALL_OUTER, 0);
/* Generate inner floors */
generate_fill(y1, x1, y2, x2, FEAT_FLOOR, ++sector_counter);
/* Hack -- Occasional pillar room */
if (rand_int(20) == 0)
{
for (y = y1; y <= y2; y += 2)
{
for (x = x1; x <= x2; x += 2)
{
cave_set_feat(y, x, FEAT_WALL_INNER);
cave_sector_map[y][x]=0;
}
}
}
/* Hack -- Occasional ragged-edge room */
else if (rand_int(50) == 0)
{
for (y = y1 + 2; y <= y2 - 2; y += 2)
{
cave_set_feat(y, x1, FEAT_WALL_INNER);
cave_set_feat(y, x2, FEAT_WALL_INNER);
cave_sector_map[y][x1]=0;
cave_sector_map[y][x2]=0;
}
for (x = x1 + 2; x <= x2 - 2; x += 2)
{
cave_set_feat(y1, x, FEAT_WALL_INNER);
cave_set_feat(y2, x, FEAT_WALL_INNER);
cave_sector_map[y1][x]=0;
cave_sector_map[y2][x]=0;
}
}
}
/*
* Type 2 -- Overlapping rectangular rooms
*/
static void build_type2(int y0, int x0)
{
int y1a, x1a, y2a, x2a;
int y1b, x1b, y2b, x2b;
int light = FALSE;
/* Determine extents of room (a) */
y1a = y0 - randint(4);
x1a = x0 - randint(11);
y2a = y0 + randint(3);
x2a = x0 + randint(10);
/* Determine extents of room (b) */
y1b = y0 - randint(3);
x1b = x0 - randint(10);
y2b = y0 + randint(4);
x2b = x0 + randint(11);
/* Generate new room (a) */
generate_room(y1a-1, x1a-1, y2a+1, x2a+1, light);
/* Generate new room (b) */
generate_room(y1b-1, x1b-1, y2b+1, x2b+1, light);
/* Generate outer walls (a) */
generate_draw(y1a-1, x1a-1, y2a+1, x2a+1, FEAT_WALL_OUTER, 0);
/* Generate outer walls (b) */
generate_draw(y1b-1, x1b-1, y2b+1, x2b+1, FEAT_WALL_OUTER, 0);
/* Generate inner floors (a) */
generate_fill(y1a, x1a, y2a, x2a, FEAT_FLOOR, ++sector_counter);
/* Generate inner floors (b) */
generate_fill(y1b, x1b, y2b, x2b, FEAT_FLOOR, sector_counter);
}
/*
* Type 3 -- Cross shaped rooms
*
* Room "a" runs north/south, and Room "b" runs east/east
* So a "central pillar" would run from x1a,y1b to x2a,y2b.
*
* Note that currently, the "center" is always 3x3, but I think that
* the code below will work for 5x5 (and perhaps even for unsymetric
* values like 4x3 or 5x3 or 3x4 or 3x5).
*/
static void build_type3(int y0, int x0)
{
int y, x;
int y1a, x1a, y2a, x2a;
int y1b, x1b, y2b, x2b;
int dy, dx, wy, wx;
int light = FALSE;