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.
25 * @brief 再帰フラクタルアルゴリズムによりダンジョン内に川を配置する /
26 * Recursive fractal algorithm to place water through the dungeon.
31 * @param feat1 中央部地形ID
32 * @param feat2 境界部地形ID
36 static void recursive_river(int x1, int y1, int x2, int y2, int feat1, int feat2, int width)
38 int dx, dy, length, l, x, y;
44 length = distance(x1, y1, x2, y2);
49 * Divide path in half and call routine twice.
50 * There is a small chance of splitting the river
57 /* perturbation perpendicular to path */
58 changex = randint1(abs(dy)) * 2 - abs(dy);
67 /* perturbation perpendicular to path */
68 changey = randint1(abs(dx)) * 2 - abs(dx);
75 if (!in_bounds(y1 + dy + changey, x1 + dx + changex))
81 /* construct river out of two smaller ones */
82 recursive_river(x1, y1, x1 + dx + changex, y1 + dy + changey, feat1, feat2, width);
83 recursive_river(x1 + dx + changex, y1 + dy + changey, x2, y2, feat1, feat2, width);
85 /* Split the river some of the time - junctions look cool */
86 if (one_in_(DUN_WAT_CHG) && (width > 0))
88 recursive_river(x1 + dx + changex, y1 + dy + changey,
89 x1 + 8 * (dx + changex), y1 + 8 * (dy + changey),
90 feat1, feat2, width - 1);
95 /* Actually build the river */
96 for (l = 0; l < length; l++)
98 x = x1 + l * (x2 - x1) / length;
99 y = y1 + l * (y2 - y1) / length;
105 for (ty = y - width - 1; ty <= y + width + 1; ty++)
107 for (tx = x - width - 1; tx <= x + width + 1; tx++)
109 if (!in_bounds2(ty, tx)) continue;
111 c_ptr = &cave[ty][tx];
113 if (c_ptr->feat == feat1) continue;
114 if (c_ptr->feat == feat2) continue;
116 if (distance(ty, tx, y, x) > rand_spread(width, 1)) continue;
118 /* Do not convert permanent features */
119 if (cave_perma_grid(c_ptr)) continue;
122 * Clear previous contents, add feature
123 * The border mainly gets feat2, while the center gets feat1
125 if (distance(ty, tx, y, x) > width)
130 /* Clear garbage of hidden trap or door */
133 /* Lava terrain glows */
134 if (have_flag(f_info[feat1].flags, FF_LAVA))
136 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) c_ptr->info |= CAVE_GLOW;
139 /* Hack -- don't teleport here */
140 c_ptr->info |= CAVE_ICKY;
152 * @brief ランダムに川/溶岩流をダンジョンに配置する /
153 * Places water /lava through dungeon.
154 * @param feat1 中央部地形ID
155 * @param feat2 境界部地形ID
158 void add_river(int feat1, int feat2)
165 /* Hack -- Choose starting point */
166 y2 = randint1(cur_hgt / 2 - 2) + cur_hgt / 2;
167 x2 = randint1(cur_wid / 2 - 2) + cur_wid / 2;
169 /* Hack -- Choose ending point somewhere on boundary */
175 x1 = randint1(cur_wid-2)+1;
183 y1 = randint1(cur_hgt-2)+1;
190 y1 = randint1(cur_hgt-2)+1;
195 /* bottom boundary */
196 x1 = randint1(cur_wid-2)+1;
202 wid = randint1(DUN_WAT_RNG);
203 recursive_river(x1, y1, x2, y2, feat1, feat2, wid);
205 /* Hack - Save the location as a "room" */
206 if (dun->cent_n < CENT_MAX)
208 dun->cent[dun->cent_n].y = y2;
209 dun->cent[dun->cent_n].x = x2;
216 * @brief ダンジョンの壁部にストリーマー(地質の変化)を与える /
217 * Places "streamers" of rock through dungeon
218 * @param feat ストリーマー地形ID
223 * Note that their are actually six different terrain features used
224 * to represent streamers. Three each of magma and quartz, one for
225 * basic vein, one with hidden gold, and one with known gold. The
226 * hidden gold types are currently unused.
229 void build_streamer(int feat, int chance)
238 feature_type *streamer_ptr = &f_info[feat];
239 bool streamer_is_wall = have_flag(streamer_ptr->flags, FF_WALL) && !have_flag(streamer_ptr->flags, FF_PERMANENT);
240 bool streamer_may_have_gold = have_flag(streamer_ptr->flags, FF_MAY_HAVE_GOLD);
242 /* Hack -- Choose starting point */
243 y = rand_spread(cur_hgt / 2, cur_hgt / 6);
244 x = rand_spread(cur_wid / 2, cur_wid / 6);
246 /* Choose a random compass direction */
249 /* Place streamer into dungeon */
250 while (dummy < SAFE_MAX_ATTEMPTS)
254 /* One grid per density */
255 for (i = 0; i < DUN_STR_DEN; i++)
259 /* Pick a nearby grid */
262 ty = rand_spread(y, d);
263 tx = rand_spread(x, d);
264 if (!in_bounds2(ty, tx)) continue;
268 /* Access the grid */
269 c_ptr = &cave[ty][tx];
270 f_ptr = &f_info[c_ptr->feat];
272 if (have_flag(f_ptr->flags, FF_MOVE) && (have_flag(f_ptr->flags, FF_WATER) || have_flag(f_ptr->flags, FF_LAVA)))
275 /* Do not convert permanent features */
276 if (have_flag(f_ptr->flags, FF_PERMANENT)) continue;
278 /* Only convert "granite" walls */
279 if (streamer_is_wall)
281 if (!is_extra_grid(c_ptr) && !is_inner_grid(c_ptr) && !is_outer_grid(c_ptr) && !is_solid_grid(c_ptr)) continue;
282 if (is_closed_door(c_ptr->feat)) continue;
285 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)))
287 /* Delete the monster (if any) */
288 delete_monster(ty, tx);
291 if (c_ptr->o_idx && !have_flag(streamer_ptr->flags, FF_DROP))
293 s16b this_o_idx, next_o_idx = 0;
295 /* Scan all objects in the grid */
296 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
299 object_type *o_ptr = &o_list[this_o_idx];
301 /* Acquire next object */
302 next_o_idx = o_ptr->next_o_idx;
304 /* Hack -- Preserve unknown artifacts */
305 if (object_is_fixed_artifact(o_ptr))
307 /* Mega-Hack -- Preserve the artifact */
308 a_info[o_ptr->name1].cur_num = 0;
312 char o_name[MAX_NLEN];
313 object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
315 msg_format("伝説のアイテム (%s) はストリーマーにより削除された。", o_name);
317 msg_format("Artifact (%s) was deleted by streamer.", o_name);
321 else if (cheat_peek && o_ptr->art_name)
324 msg_print("ランダム・アーティファクトの1つはストリーマーにより削除された。");
326 msg_print("One of the random artifacts was deleted by streamer.");
332 delete_object(ty, tx);
335 /* Clear previous contents, add proper vein type */
338 /* Paranoia: Clear mimic field */
341 if (streamer_may_have_gold)
343 /* Hack -- Add some known treasure */
346 cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
349 /* Hack -- Add some hidden treasure */
350 else if (one_in_(chance / 4))
352 cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
353 cave_alter_feat(ty, tx, FF_ENSECRET);
358 if (dummy >= SAFE_MAX_ATTEMPTS)
363 msg_print("警告!ストリーマーを配置できません!");
365 msg_print("Warning! Could not place streamer!");
373 /* Advance the streamer */
379 if(one_in_(2)) dir = (dir + 1) % 8;
380 else dir = (dir > 0) ? dir - 1 : 7;
383 /* Quit before leaving the dungeon */
384 if (!in_bounds(y, x)) break;
390 * @brief ダンジョンの指定位置近辺に森林を配置する /
391 * Places "streamers" of rock through dungeon
397 * Put trees near a hole in the dungeon roof (rubble on ground + up stairway)
398 * This happens in real world lava tubes.
401 void place_trees(int x, int y)
406 /* place trees/ rubble in ovalish distribution */
407 for (i = x - 3; i < x + 4; i++)
409 for (j = y - 3; j < y + 4; j++)
411 if (!in_bounds(j, i)) continue;
414 if (c_ptr->info & CAVE_ICKY) continue;
415 if (c_ptr->o_idx) continue;
417 /* Want square to be in the circle and accessable. */
418 if ((distance(j, i, y, x) < 4) && !cave_perma_grid(c_ptr))
421 * Clear previous contents, add feature
422 * The border mainly gets trees, while the center gets rubble
424 if ((distance(j, i, y, x) > 1) || (randint1(100) < 25))
426 if (randint1(100) < 75)
427 cave[j][i].feat = feat_tree;
431 cave[j][i].feat = feat_rubble;
434 /* Clear garbage of hidden trap or door */
437 /* Light area since is open above */
438 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
443 /* No up stairs in ironman mode */
444 if (!ironman_downward && one_in_(3))
447 cave[y][x].feat = feat_up_stair;
453 * @brief ダンジョンに*破壊*済み地形ランダムに施す /
454 * Build a destroyed level
457 void destroy_level(void)
461 /* Note destroyed levels */
463 if (cheat_room) msg_print("破壊された階");
465 if (cheat_room) msg_print("Destroyed Level");
468 /* Drop a few epi-centers (usually about two) */
469 for (n = 0; n < randint1(5); n++)
471 /* Pick an epi-center */
472 x1 = rand_range(5, cur_wid - 1 - 5);
473 y1 = rand_range(5, cur_hgt - 1 - 5);
475 (void)destroy_area(y1, x1, 15, TRUE);