3 * @brief ダンジョン生成に利用する関数群 / Used by dungeon generation.
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
13 * Purpose: This file holds all the
14 * functions that are applied to a level after the rest has been
15 * generated, ie streams and level destruction.
20 #include "floor-streams.h"
26 * @brief 再帰フラクタルアルゴリズムによりダンジョン内に川を配置する /
27 * Recursive fractal algorithm to place water through the dungeon.
32 * @param feat1 中央部地形ID
33 * @param feat2 境界部地形ID
37 static void recursive_river(POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX feat1, FEAT_IDX feat2, POSITION width)
39 POSITION dx, dy, length, l, x, y;
40 POSITION changex, changey;
45 length = distance(x1, y1, x2, y2);
50 * Divide path in half and call routine twice.
51 * There is a small chance of splitting the river
58 /* perturbation perpendicular to path */
59 changex = randint1(abs(dy)) * 2 - abs(dy);
68 /* perturbation perpendicular to path */
69 changey = randint1(abs(dx)) * 2 - abs(dx);
76 if (!in_bounds(y1 + dy + changey, x1 + dx + changex))
82 /* construct river out of two smaller ones */
83 recursive_river(x1, y1, x1 + dx + changex, y1 + dy + changey, feat1, feat2, width);
84 recursive_river(x1 + dx + changex, y1 + dy + changey, x2, y2, feat1, feat2, width);
86 /* Split the river some of the time - junctions look cool */
87 if (one_in_(DUN_WAT_CHG) && (width > 0))
89 recursive_river(x1 + dx + changex, y1 + dy + changey,
90 x1 + 8 * (dx + changex), y1 + 8 * (dy + changey),
91 feat1, feat2, width - 1);
96 /* Actually build the river */
97 for (l = 0; l < length; l++)
99 x = x1 + l * (x2 - x1) / length;
100 y = y1 + l * (y2 - y1) / length;
106 for (ty = y - width - 1; ty <= y + width + 1; ty++)
108 for (tx = x - width - 1; tx <= x + width + 1; tx++)
110 if (!in_bounds2(ty, tx)) continue;
112 g_ptr = ¤t_floor->grid_array[ty][tx];
114 if (g_ptr->feat == feat1) continue;
115 if (g_ptr->feat == feat2) continue;
117 if (distance(ty, tx, y, x) > rand_spread(width, 1)) continue;
119 /* Do not convert permanent features */
120 if (cave_perma_grid(g_ptr)) continue;
123 * Clear previous contents, add feature
124 * The border mainly gets feat2, while the center gets feat1
126 if (distance(ty, tx, y, x) > width)
131 /* Clear garbage of hidden trap or door */
134 /* Lava terrain glows */
135 if (have_flag(f_info[feat1].flags, FF_LAVA))
137 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) g_ptr->info |= CAVE_GLOW;
140 /* Hack -- don't teleport here */
141 g_ptr->info |= CAVE_ICKY;
153 * @brief ランダムに川/溶岩流をダンジョンに配置する /
154 * Places water /lava through dungeon.
155 * @param feat1 中央部地形ID
156 * @param feat2 境界部地形ID
159 void add_river(IDX feat1, IDX feat2)
162 POSITION y1 = 0, x1 = 0;
166 /* Hack -- Choose starting point */
167 y2 = randint1(cur_hgt / 2 - 2) + cur_hgt / 2;
168 x2 = randint1(cur_wid / 2 - 2) + cur_wid / 2;
170 /* Hack -- Choose ending point somewhere on boundary */
176 x1 = randint1(cur_wid-2)+1;
184 y1 = randint1(cur_hgt-2)+1;
191 y1 = randint1(cur_hgt-2)+1;
196 /* bottom boundary */
197 x1 = randint1(cur_wid-2)+1;
203 wid = randint1(DUN_WAT_RNG);
204 recursive_river(x1, y1, x2, y2, feat1, feat2, wid);
206 /* Hack - Save the location as a "room" */
207 if (dun->cent_n < CENT_MAX)
209 dun->cent[dun->cent_n].y = y2;
210 dun->cent[dun->cent_n].x = x2;
217 * @brief ダンジョンの壁部にストリーマー(地質の変化)を与える /
218 * Places "streamers" of rock through dungeon
219 * @param feat ストリーマー地形ID
224 * Note that their are actually six different terrain features used
225 * to represent streamers. Three each of magma and quartz, one for
226 * basic vein, one with hidden gold, and one with known gold. The
227 * hidden gold types are currently unused.
230 void build_streamer(IDX feat, int chance)
239 feature_type *streamer_ptr = &f_info[feat];
240 bool streamer_is_wall = have_flag(streamer_ptr->flags, FF_WALL) && !have_flag(streamer_ptr->flags, FF_PERMANENT);
241 bool streamer_may_have_gold = have_flag(streamer_ptr->flags, FF_MAY_HAVE_GOLD);
243 /* Hack -- Choose starting point */
244 y = rand_spread(cur_hgt / 2, cur_hgt / 6);
245 x = rand_spread(cur_wid / 2, cur_wid / 6);
247 /* Choose a random compass direction */
250 /* Place streamer into dungeon */
251 while (dummy < SAFE_MAX_ATTEMPTS)
255 /* One grid per density */
256 for (i = 0; i < DUN_STR_DEN; i++)
260 /* Pick a nearby grid */
263 ty = rand_spread(y, d);
264 tx = rand_spread(x, d);
265 if (!in_bounds2(ty, tx)) continue;
268 g_ptr = ¤t_floor->grid_array[ty][tx];
269 f_ptr = &f_info[g_ptr->feat];
271 if (have_flag(f_ptr->flags, FF_MOVE) && (have_flag(f_ptr->flags, FF_WATER) || have_flag(f_ptr->flags, FF_LAVA)))
274 /* Do not convert permanent features */
275 if (have_flag(f_ptr->flags, FF_PERMANENT)) continue;
277 /* Only convert "granite" walls */
278 if (streamer_is_wall)
280 if (!is_extra_grid(g_ptr) && !is_inner_grid(g_ptr) && !is_outer_grid(g_ptr) && !is_solid_grid(g_ptr)) continue;
281 if (is_closed_door(g_ptr->feat)) continue;
284 if (g_ptr->m_idx && !(have_flag(streamer_ptr->flags, FF_PLACE) && monster_can_cross_terrain(feat, &r_info[m_list[g_ptr->m_idx].r_idx], 0)))
286 /* Delete the monster (if any) */
287 delete_monster(ty, tx);
290 if (g_ptr->o_idx && !have_flag(streamer_ptr->flags, FF_DROP))
292 OBJECT_IDX this_o_idx, next_o_idx = 0;
294 /* Scan all objects in the grid */
295 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
297 object_type *o_ptr = &o_list[this_o_idx];
299 /* Acquire next object */
300 next_o_idx = o_ptr->next_o_idx;
302 /* Hack -- Preserve unknown artifacts */
303 if (object_is_fixed_artifact(o_ptr))
305 /* Mega-Hack -- Preserve the artifact */
306 a_info[o_ptr->name1].cur_num = 0;
310 GAME_TEXT o_name[MAX_NLEN];
311 object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
312 msg_format(_("伝説のアイテム (%s) はストリーマーにより削除された。",
313 "Artifact (%s) was deleted by streamer."), o_name);
316 else if (cheat_peek && o_ptr->art_name)
318 msg_print(_("ランダム・アーティファクトの1つはストリーマーにより削除された。",
319 "One of the random artifacts was deleted by streamer."));
323 delete_object(ty, tx);
326 /* Clear previous contents, add proper vein type */
329 /* Paranoia: Clear mimic field */
332 if (streamer_may_have_gold)
334 /* Hack -- Add some known treasure */
337 cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
340 /* Hack -- Add some hidden treasure */
341 else if (one_in_(chance / 4))
343 cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
344 cave_alter_feat(ty, tx, FF_ENSECRET);
349 if (dummy >= SAFE_MAX_ATTEMPTS)
351 msg_print_wizard(CHEAT_DUNGEON, _("地形のストリーマー処理に失敗しました。", "Failed to place streamer."));
355 /* Advance the streamer */
361 if(one_in_(2)) dir = (dir + 1) % 8;
362 else dir = (dir > 0) ? dir - 1 : 7;
365 /* Quit before leaving the dungeon */
366 if (!in_bounds(y, x)) break;
372 * @brief ダンジョンの指定位置近辺に森林を配置する /
373 * Places "streamers" of rock through dungeon
379 * Put trees near a hole in the dungeon roof (rubble on ground + up stairway)
380 * This happens in real world lava tubes.
383 void place_trees(POSITION x, POSITION y)
388 /* place trees/ rubble in ovalish distribution */
389 for (i = x - 3; i < x + 4; i++)
391 for (j = y - 3; j < y + 4; j++)
393 if (!in_bounds(j, i)) continue;
394 g_ptr = ¤t_floor->grid_array[j][i];
396 if (g_ptr->info & CAVE_ICKY) continue;
397 if (g_ptr->o_idx) continue;
399 /* Want square to be in the circle and accessable. */
400 if ((distance(j, i, y, x) < 4) && !cave_perma_grid(g_ptr))
403 * Clear previous contents, add feature
404 * The border mainly gets trees, while the center gets rubble
406 if ((distance(j, i, y, x) > 1) || (randint1(100) < 25))
408 if (randint1(100) < 75)
409 current_floor->grid_array[j][i].feat = feat_tree;
413 current_floor->grid_array[j][i].feat = feat_rubble;
416 /* Clear garbage of hidden trap or door */
419 /* Light area since is open above */
420 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) current_floor->grid_array[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
425 /* No up stairs in ironman mode */
426 if (!ironman_downward && one_in_(3))
429 current_floor->grid_array[y][x].feat = feat_up_stair;
435 * @brief ダンジョンに*破壊*済み地形ランダムに施す /
436 * Build a destroyed level
439 void destroy_level(void)
444 /* Note destroyed levels */
445 msg_print_wizard(CHEAT_DUNGEON, _("階に*破壊*の痕跡を生成しました。", "Destroyed Level."));
447 /* Drop a few epi-centers (usually about two) */
448 for (n = 0; n < randint1(5); n++)
450 /* Pick an epi-center */
451 x1 = rand_range(5, cur_wid - 1 - 5);
452 y1 = rand_range(5, cur_hgt - 1 - 5);
454 (void)destroy_area(y1, x1, 15, TRUE);