3 * Purpose: Used by dungeon generation. This file holds all the
4 * functions that are applied to a level after the rest has been
5 * generated, ie streams and level destruction.
9 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
11 * This software may be copied and distributed for educational, research, and
12 * not for profit purposes provided that this copyright and statement are
13 * included in all such copies.
23 * Recursive fractal algorithm to place water through the dungeon.
25 static void recursive_river(int x1, int y1, int x2, int y2, int feat1, int feat2, int width)
27 int dx, dy, length, l, x, y;
33 length = distance(x1, y1, x2, y2);
38 * Divide path in half and call routine twice.
39 * There is a small chance of splitting the river
46 /* perturbation perpendicular to path */
47 changex = randint(abs(dy)) * 2 - abs(dy);
56 /* perturbation perpendicular to path */
57 changey = randint(abs(dx)) * 2 - abs(dx);
64 if (!in_bounds(y1 + dy + changey, x1 + dx + changex))
70 /* construct river out of two smaller ones */
71 recursive_river(x1, y1, x1 + dx + changex, y1 + dy + changey, feat1, feat2, width);
72 recursive_river(x1 + dx + changex, y1 + dy + changey, x2, y2, feat1, feat2, width);
74 /* Split the river some of the time - junctions look cool */
75 if ((randint(DUN_WAT_CHG) == 1) && (width > 0))
77 recursive_river(x1 + dx + changex, y1 + dy + changey,
78 x1 + 8 * (dx + changex), y1 + 8 * (dy + changey),
79 feat1, feat2, width - 1);
84 /* Actually build the river */
85 for (l = 0; l < length; l++)
87 x = x1 + l * (x2 - x1) / length;
88 y = y1 + l * (y2 - y1) / length;
94 for (ty = y - width - 1; ty <= y + width + 1; ty++)
96 for (tx = x - width - 1; tx <= x + width + 1; tx++)
98 if (!in_bounds(ty, tx)) continue;
100 c_ptr = &cave[ty][tx];
102 if (c_ptr->feat == feat1) continue;
103 if (c_ptr->feat == feat2) continue;
105 if (distance(ty, tx, y, x) > rand_spread(width, 1)) continue;
107 /* Do not convert permanent features */
108 if (cave_perma_grid(c_ptr) && (c_ptr->feat != FEAT_MOUNTAIN)) continue;
111 * Clear previous contents, add feature
112 * The border mainly gets feat2, while the center gets feat1
114 if (distance(ty, tx, y, x) > width)
119 /* Lava terrain glows */
120 if ((feat1 == FEAT_DEEP_LAVA) || (feat1 == FEAT_SHAL_LAVA))
122 c_ptr->info |= CAVE_GLOW;
125 /* Hack -- don't teleport here */
126 c_ptr->info |= CAVE_ICKY;
138 * Places water /lava through dungeon.
140 void add_river(int feat1, int feat2)
147 /* Hack -- Choose starting point */
148 y2 = randint(cur_hgt / 2 - 2) + cur_hgt / 2;
149 x2 = randint(cur_wid / 2 - 2) + cur_wid / 2;
151 /* Hack -- Choose ending point somewhere on boundary */
157 x1 = randint(cur_wid-2)+1;
165 y1 = randint(cur_hgt-2)+1;
172 y1 = randint(cur_hgt-2)+1;
177 /* bottom boundary */
178 x1 = randint(cur_wid-2)+1;
184 wid = randint(DUN_WAT_RNG);
185 recursive_river(x1, y1, x2, y2, feat1, feat2, wid);
187 /* Hack - Save the location as a "room" */
188 if (dun->cent_n < CENT_MAX)
190 dun->cent[dun->cent_n].y = y2;
191 dun->cent[dun->cent_n].x = x2;
198 * Places "streamers" of rock through dungeon
200 * Note that their are actually six different terrain features used
201 * to represent streamers. Three each of magma and quartz, one for
202 * basic vein, one with hidden gold, and one with known gold. The
203 * hidden gold types are currently unused.
205 void build_streamer(int feat, int chance)
210 bool treasure = FALSE;
214 /* Hack -- Choose starting point */
215 y = rand_spread(cur_hgt / 2, 10);
216 x = rand_spread(cur_wid / 2, 15);
218 /* Choose a random compass direction */
219 dir = ddd[rand_int(8)];
221 /* Place streamer into dungeon */
222 while (dummy < SAFE_MAX_ATTEMPTS)
226 /* One grid per density */
227 for (i = 0; i < DUN_STR_DEN; i++)
231 /* Pick a nearby grid */
234 ty = rand_spread(y, d);
235 tx = rand_spread(x, d);
236 if (!in_bounds(ty, tx)) continue;
240 /* Access the grid */
241 c_ptr = &cave[ty][tx];
243 if ((c_ptr->feat >= FEAT_DEEP_WATER) && (c_ptr->feat <= FEAT_SHAL_LAVA)) continue;
244 if ((c_ptr->feat >= FEAT_PERM_EXTRA) && (c_ptr->feat <= FEAT_PERM_SOLID)) continue;
246 /* Only convert "granite" walls */
247 if ((feat >= FEAT_MAGMA) && (feat <= FEAT_WALL_SOLID))
249 if (!is_extra_grid(c_ptr) && !is_inner_grid(c_ptr) && !is_outer_grid(c_ptr) && !is_solid_grid(c_ptr)) continue;
250 if ((c_ptr->feat >= FEAT_DOOR_HEAD) && (c_ptr->feat <= FEAT_SECRET)) continue;
251 if ((feat == FEAT_MAGMA) || (feat == FEAT_QUARTZ)) treasure = TRUE;
255 if (cave_perma_grid(c_ptr) && (c_ptr->feat != FEAT_MOUNTAIN)) continue;
258 /* Clear previous contents, add proper vein type */
261 /* Hack -- Add some (known) treasure */
262 if (treasure && (rand_int(chance) == 0)) c_ptr->feat += 0x04;
265 if (dummy >= SAFE_MAX_ATTEMPTS)
270 msg_print("·Ù¹ð¡ª¥¹¥È¥ê¡¼¥Þ¡¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
272 msg_print("Warning! Could not place streamer!");
280 /* Advance the streamer */
284 /* Quit before leaving the dungeon */
285 if (!in_bounds(y, x)) break;
291 * Put trees near a hole in the dungeon roof (rubble on ground + up stairway)
292 * This happens in real world lava tubes.
294 void place_trees(int x, int y)
299 /* place trees/ rubble in ovalish distribution */
300 for (i = x - 3; i < x + 4; i++)
302 for (j = y - 3; j < y + 4; j++)
304 if (!in_bounds(j, i)) continue;
307 if (c_ptr->info & CAVE_ICKY) continue;
308 if (c_ptr->info & CAVE_TRAP) continue;
309 if (c_ptr->o_idx) continue;
311 /* Want square to be in the circle and accessable. */
312 if ((distance(j, i, y, x) < 4) && !cave_perma_grid(c_ptr))
315 * Clear previous contents, add feature
316 * The border mainly gets trees, while the center gets rubble
318 if ((distance(j, i, y, x) > 1) || (randint(100) < 25))
320 if (randint(100) < 75)
321 cave[j][i].feat = FEAT_TREES;
325 cave[j][i].feat = FEAT_RUBBLE;
328 /* Light area since is open above */
329 cave[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
334 /* No up stairs in ironman mode */
335 if (!ironman_downward && (randint(3) == 1))
338 cave[y][x].feat = FEAT_LESS;
344 * Build a destroyed level
346 void destroy_level(void)
348 int y1, x1, y, x, k, t, n;
352 /* Note destroyed levels */
354 if (cheat_room) msg_print("Ç˲õ¤µ¤ì¤¿³¬");
356 if (cheat_room) msg_print("Destroyed Level");
360 /* Drop a few epi-centers (usually about two) */
361 for (n = 0; n < randint(5); n++)
363 /* Pick an epi-center */
364 x1 = rand_range(5, cur_wid - 1 - 5);
365 y1 = rand_range(5, cur_hgt - 1 - 5);
367 /* Big area of affect */
368 for (y = (y1 - 15); y <= (y1 + 15); y++)
370 for (x = (x1 - 15); x <= (x1 + 15); x++)
372 /* Skip illegal grids */
373 if (!in_bounds(y, x)) continue;
375 /* Extract the distance */
376 k = distance(y1, x1, y, x);
378 /* Stay in the circle of death */
379 if (k >= 16) continue;
381 /* Delete the monster (if any) */
382 delete_monster(y, x);
384 /* Access the grid */
387 /* Destroy valid grids */
388 if (cave_valid_grid(c_ptr))
393 /* Wall (or floor) type */
399 /* Create granite wall */
400 place_extra_grid(c_ptr);
406 /* Create quartz vein */
407 c_ptr->feat = FEAT_QUARTZ;
413 /* Create magma vein */
414 c_ptr->feat = FEAT_MAGMA;
421 place_floor_grid(c_ptr);
424 /* No longer part of a room or vault */
425 c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
427 /* No longer illuminated or known */
428 c_ptr->info &= ~(CAVE_MARK | CAVE_GLOW);