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) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
11 * This software may be copied and distributed for educational, research,
12 * and not for profit purposes provided that this copyright and statement
13 * are included in all such copies. Other copyrights may also apply.
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 = randint1(abs(dy)) * 2 - abs(dy);
56 /* perturbation perpendicular to path */
57 changey = randint1(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 (one_in_(DUN_WAT_CHG) && (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_bounds2(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)) 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 /* Clear garbage of hidden trap or door */
122 /* Lava terrain glows */
123 if (have_flag(f_info[feat1].flags, FF_LAVA))
125 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) c_ptr->info |= CAVE_GLOW;
128 /* Hack -- don't teleport here */
129 c_ptr->info |= CAVE_ICKY;
141 * Places water /lava through dungeon.
143 void add_river(int feat1, int feat2)
150 /* Hack -- Choose starting point */
151 y2 = randint1(cur_hgt / 2 - 2) + cur_hgt / 2;
152 x2 = randint1(cur_wid / 2 - 2) + cur_wid / 2;
154 /* Hack -- Choose ending point somewhere on boundary */
160 x1 = randint1(cur_wid-2)+1;
168 y1 = randint1(cur_hgt-2)+1;
175 y1 = randint1(cur_hgt-2)+1;
180 /* bottom boundary */
181 x1 = randint1(cur_wid-2)+1;
187 wid = randint1(DUN_WAT_RNG);
188 recursive_river(x1, y1, x2, y2, feat1, feat2, wid);
190 /* Hack - Save the location as a "room" */
191 if (dun->cent_n < CENT_MAX)
193 dun->cent[dun->cent_n].y = y2;
194 dun->cent[dun->cent_n].x = x2;
201 * Places "streamers" of rock through dungeon
203 * Note that their are actually six different terrain features used
204 * to represent streamers. Three each of magma and quartz, one for
205 * basic vein, one with hidden gold, and one with known gold. The
206 * hidden gold types are currently unused.
208 void build_streamer(int feat, int chance)
217 feature_type *streamer_ptr = &f_info[feat];
218 bool streamer_is_wall = have_flag(streamer_ptr->flags, FF_WALL) && !have_flag(streamer_ptr->flags, FF_PERMANENT);
219 bool streamer_may_have_gold = have_flag(streamer_ptr->flags, FF_MAY_HAVE_GOLD);
221 /* Hack -- Choose starting point */
222 y = rand_spread(cur_hgt / 2, cur_hgt / 6);
223 x = rand_spread(cur_wid / 2, cur_wid / 6);
225 /* Choose a random compass direction */
226 dir = ddd[randint0(8)];
228 /* Place streamer into dungeon */
229 while (dummy < SAFE_MAX_ATTEMPTS)
233 /* One grid per density */
234 for (i = 0; i < DUN_STR_DEN; i++)
238 /* Pick a nearby grid */
241 ty = rand_spread(y, d);
242 tx = rand_spread(x, d);
243 if (!in_bounds2(ty, tx)) continue;
247 /* Access the grid */
248 c_ptr = &cave[ty][tx];
249 f_ptr = &f_info[c_ptr->feat];
251 if (have_flag(f_ptr->flags, FF_MOVE) && (have_flag(f_ptr->flags, FF_WATER) || have_flag(f_ptr->flags, FF_LAVA)))
254 /* Do not convert permanent features */
255 if (have_flag(f_ptr->flags, FF_PERMANENT)) continue;
257 /* Only convert "granite" walls */
258 if (streamer_is_wall)
260 if (!is_extra_grid(c_ptr) && !is_inner_grid(c_ptr) && !is_outer_grid(c_ptr) && !is_solid_grid(c_ptr)) continue;
261 if (is_closed_door(c_ptr->feat)) continue;
264 if (c_ptr->m_idx && !(have_flag(streamer_ptr->flags, FF_PLACE) && monster_can_cross_terrain(feat, &r_info[m_list[c_ptr->m_idx].r_idx], 0)))
266 /* Delete the monster (if any) */
267 delete_monster(ty, tx);
270 if (c_ptr->o_idx && !have_flag(streamer_ptr->flags, FF_DROP))
272 s16b this_o_idx, next_o_idx = 0;
274 /* Scan all objects in the grid */
275 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
278 object_type *o_ptr = &o_list[this_o_idx];
280 /* Acquire next object */
281 next_o_idx = o_ptr->next_o_idx;
283 /* Hack -- Preserve unknown artifacts */
284 if (object_is_fixed_artifact(o_ptr))
286 /* Mega-Hack -- Preserve the artifact */
287 a_info[o_ptr->name1].cur_num = 0;
291 char o_name[MAX_NLEN];
292 object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
294 msg_format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à (%s) ¤Ï¥¹¥È¥ê¡¼¥Þ¡¼¤Ë¤è¤êºï½ü¤µ¤ì¤¿¡£", o_name);
296 msg_format("Artifact (%s) was deleted by streamer.", o_name);
300 else if (cheat_peek && o_ptr->art_name)
303 msg_print("¥é¥ó¥À¥à¡¦¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î1¤Ä¤Ï¥¹¥È¥ê¡¼¥Þ¡¼¤Ë¤è¤êºï½ü¤µ¤ì¤¿¡£");
305 msg_print("One of the random artifacts was deleted by streamer.");
311 delete_object(ty, tx);
314 /* Clear previous contents, add proper vein type */
317 /* Paranoia: Clear mimic field */
320 if (streamer_may_have_gold)
322 /* Hack -- Add some known treasure */
325 cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
328 /* Hack -- Add some hidden treasure */
329 else if (one_in_(chance / 4))
331 cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
332 cave_alter_feat(ty, tx, FF_ENSECRET);
337 if (dummy >= SAFE_MAX_ATTEMPTS)
342 msg_print("·Ù¹ð¡ª¥¹¥È¥ê¡¼¥Þ¡¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
344 msg_print("Warning! Could not place streamer!");
352 /* Advance the streamer */
356 /* Quit before leaving the dungeon */
357 if (!in_bounds(y, x)) break;
363 * Put trees near a hole in the dungeon roof (rubble on ground + up stairway)
364 * This happens in real world lava tubes.
366 void place_trees(int x, int y)
371 /* place trees/ rubble in ovalish distribution */
372 for (i = x - 3; i < x + 4; i++)
374 for (j = y - 3; j < y + 4; j++)
376 if (!in_bounds(j, i)) continue;
379 if (c_ptr->info & CAVE_ICKY) continue;
380 if (c_ptr->o_idx) continue;
382 /* Want square to be in the circle and accessable. */
383 if ((distance(j, i, y, x) < 4) && !cave_perma_grid(c_ptr))
386 * Clear previous contents, add feature
387 * The border mainly gets trees, while the center gets rubble
389 if ((distance(j, i, y, x) > 1) || (randint1(100) < 25))
391 if (randint1(100) < 75)
392 cave[j][i].feat = feat_tree;
396 cave[j][i].feat = feat_rubble;
399 /* Clear garbage of hidden trap or door */
402 /* Light area since is open above */
403 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
408 /* No up stairs in ironman mode */
409 if (!ironman_downward && one_in_(3))
412 cave[y][x].feat = feat_up_stair;
418 * Build a destroyed level
420 void destroy_level(void)
424 /* Note destroyed levels */
426 if (cheat_room) msg_print("Ç˲õ¤µ¤ì¤¿³¬");
428 if (cheat_room) msg_print("Destroyed Level");
431 /* Drop a few epi-centers (usually about two) */
432 for (n = 0; n < randint1(5); n++)
434 /* Pick an epi-center */
435 x1 = rand_range(5, cur_wid - 1 - 5);
436 y1 = rand_range(5, cur_hgt - 1 - 5);
438 (void)destroy_area(y1, x1, 15, TRUE);