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.
22 #include "floor-generate.h"
25 #include "floor-streams.h"
29 #include "object-flavor.h"
30 #include "object-hook.h"
32 #include "spells-floor.h"
36 * @brief 再帰フラクタルアルゴリズムによりダンジョン内に川を配置する /
37 * Recursive fractal algorithm to place water through the dungeon.
42 * @param feat1 中央部地形ID
43 * @param feat2 境界部地形ID
47 static void recursive_river(POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX feat1, FEAT_IDX feat2, POSITION width)
49 POSITION dx, dy, length, l, x, y;
50 POSITION changex, changey;
55 length = distance(x1, y1, x2, y2);
60 * Divide path in half and call routine twice.
61 * There is a small chance of splitting the river
68 /* perturbation perpendicular to path */
69 changex = randint1(abs(dy)) * 2 - abs(dy);
78 /* perturbation perpendicular to path */
79 changey = randint1(abs(dx)) * 2 - abs(dx);
86 if (!in_bounds(p_ptr->current_floor_ptr, y1 + dy + changey, x1 + dx + changex))
92 /* construct river out of two smaller ones */
93 recursive_river(x1, y1, x1 + dx + changex, y1 + dy + changey, feat1, feat2, width);
94 recursive_river(x1 + dx + changex, y1 + dy + changey, x2, y2, feat1, feat2, width);
96 /* Split the river some of the time - junctions look cool */
97 if (one_in_(DUN_WAT_CHG) && (width > 0))
99 recursive_river(x1 + dx + changex, y1 + dy + changey,
100 x1 + 8 * (dx + changex), y1 + 8 * (dy + changey),
101 feat1, feat2, width - 1);
106 /* Actually build the river */
107 for (l = 0; l < length; l++)
109 x = x1 + l * (x2 - x1) / length;
110 y = y1 + l * (y2 - y1) / length;
116 for (ty = y - width - 1; ty <= y + width + 1; ty++)
118 for (tx = x - width - 1; tx <= x + width + 1; tx++)
120 if (!in_bounds2(p_ptr->current_floor_ptr, ty, tx)) continue;
122 g_ptr = &p_ptr->current_floor_ptr->grid_array[ty][tx];
124 if (g_ptr->feat == feat1) continue;
125 if (g_ptr->feat == feat2) continue;
127 if (distance(ty, tx, y, x) > rand_spread(width, 1)) continue;
129 /* Do not convert permanent features */
130 if (cave_perma_grid(g_ptr)) continue;
133 * Clear previous contents, add feature
134 * The border mainly gets feat2, while the center gets feat1
136 if (distance(ty, tx, y, x) > width)
141 /* Clear garbage of hidden trap or door */
144 /* Lava terrain glows */
145 if (have_flag(f_info[feat1].flags, FF_LAVA))
147 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) g_ptr->info |= CAVE_GLOW;
150 /* Hack -- don't teleport here */
151 g_ptr->info |= CAVE_ICKY;
163 * @brief ランダムに川/溶岩流をダンジョンに配置する /
164 * Places water /lava through dungeon.
165 * @param feat1 中央部地形ID
166 * @param feat2 境界部地形ID
169 void add_river(floor_type *floor_ptr, FEAT_IDX feat1, FEAT_IDX feat2)
172 POSITION y1 = 0, x1 = 0;
176 /* Hack -- Choose starting point */
177 y2 = randint1(floor_ptr->height / 2 - 2) + floor_ptr->height / 2;
178 x2 = randint1(floor_ptr->width / 2 - 2) + floor_ptr->width / 2;
180 /* Hack -- Choose ending point somewhere on boundary */
186 x1 = randint1(floor_ptr->width-2)+1;
194 y1 = randint1(floor_ptr->height-2)+1;
200 x1 = floor_ptr->width-1;
201 y1 = randint1(floor_ptr->height-2)+1;
206 /* bottom boundary */
207 x1 = randint1(floor_ptr->width-2)+1;
208 y1 = floor_ptr->height-1;
213 wid = randint1(DUN_WAT_RNG);
214 recursive_river(x1, y1, x2, y2, feat1, feat2, wid);
216 /* Hack - Save the location as a "room" */
217 if (dun->cent_n < CENT_MAX)
219 dun->cent[dun->cent_n].y = y2;
220 dun->cent[dun->cent_n].x = x2;
227 * @brief ダンジョンの壁部にストリーマー(地質の変化)を与える /
228 * Places "streamers" of rock through dungeon
229 * @param feat ストリーマー地形ID
234 * Note that their are actually six different terrain features used
235 * to represent streamers. Three each of magma and quartz, one for
236 * basic vein, one with hidden gold, and one with known gold. The
237 * hidden gold types are currently unused.
240 void build_streamer(FEAT_IDX feat, int chance)
243 POSITION y, x, tx, ty;
250 feature_type *streamer_ptr = &f_info[feat];
251 bool streamer_is_wall = have_flag(streamer_ptr->flags, FF_WALL) && !have_flag(streamer_ptr->flags, FF_PERMANENT);
252 bool streamer_may_have_gold = have_flag(streamer_ptr->flags, FF_MAY_HAVE_GOLD);
254 /* Hack -- Choose starting point */
255 y = rand_spread(p_ptr->current_floor_ptr->height / 2, p_ptr->current_floor_ptr->height / 6);
256 x = rand_spread(p_ptr->current_floor_ptr->width / 2, p_ptr->current_floor_ptr->width / 6);
258 /* Choose a random compass direction */
261 /* Place streamer into dungeon */
262 while (dummy < SAFE_MAX_ATTEMPTS)
266 /* One grid per density */
267 for (i = 0; i < DUN_STR_DEN; i++)
271 /* Pick a nearby grid */
274 ty = rand_spread(y, d);
275 tx = rand_spread(x, d);
276 if (!in_bounds2(p_ptr->current_floor_ptr, ty, tx)) continue;
279 g_ptr = &p_ptr->current_floor_ptr->grid_array[ty][tx];
280 f_ptr = &f_info[g_ptr->feat];
282 if (have_flag(f_ptr->flags, FF_MOVE) && (have_flag(f_ptr->flags, FF_WATER) || have_flag(f_ptr->flags, FF_LAVA)))
285 /* Do not convert permanent features */
286 if (have_flag(f_ptr->flags, FF_PERMANENT)) continue;
288 /* Only convert "granite" walls */
289 if (streamer_is_wall)
291 if (!is_extra_grid(g_ptr) && !is_inner_grid(g_ptr) && !is_outer_grid(g_ptr) && !is_solid_grid(g_ptr)) continue;
292 if (is_closed_door(g_ptr->feat)) continue;
295 if (g_ptr->m_idx && !(have_flag(streamer_ptr->flags, FF_PLACE) && monster_can_cross_terrain(feat, &r_info[p_ptr->current_floor_ptr->m_list[g_ptr->m_idx].r_idx], 0)))
297 /* Delete the monster (if any) */
298 delete_monster(ty, tx);
301 if (g_ptr->o_idx && !have_flag(streamer_ptr->flags, FF_DROP))
303 OBJECT_IDX this_o_idx, next_o_idx = 0;
305 /* Scan all objects in the grid */
306 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
308 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
309 next_o_idx = o_ptr->next_o_idx;
311 /* Hack -- Preserve unknown artifacts */
312 if (object_is_fixed_artifact(o_ptr))
314 /* Mega-Hack -- Preserve the artifact */
315 a_info[o_ptr->name1].cur_num = 0;
319 GAME_TEXT o_name[MAX_NLEN];
320 object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
321 msg_format(_("伝説のアイテム (%s) はストリーマーにより削除された。",
322 "Artifact (%s) was deleted by streamer."), o_name);
325 else if (cheat_peek && o_ptr->art_name)
327 msg_print(_("ランダム・アーティファクトの1つはストリーマーにより削除された。",
328 "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)
360 msg_print_wizard(CHEAT_DUNGEON, _("地形のストリーマー処理に失敗しました。", "Failed to place streamer."));
364 /* Advance the streamer */
370 if(one_in_(2)) dir = (dir + 1) % 8;
371 else dir = (dir > 0) ? dir - 1 : 7;
374 /* Quit before leaving the dungeon */
375 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) break;
381 * @brief ダンジョンの指定位置近辺に森林を配置する /
382 * Places "streamers" of rock through dungeon
388 * Put trees near a hole in the dungeon roof (rubble on ground + up stairway)
389 * This happens in real world lava tubes.
392 void place_trees(floor_type *floor_ptr, POSITION x, POSITION y)
397 /* place trees/ rubble in ovalish distribution */
398 for (i = x - 3; i < x + 4; i++)
400 for (j = y - 3; j < y + 4; j++)
402 if (!in_bounds(floor_ptr, j, i)) continue;
403 g_ptr = &floor_ptr->grid_array[j][i];
405 if (g_ptr->info & CAVE_ICKY) continue;
406 if (g_ptr->o_idx) continue;
408 /* Want square to be in the circle and accessable. */
409 if ((distance(j, i, y, x) < 4) && !cave_perma_grid(g_ptr))
412 * Clear previous contents, add feature
413 * The border mainly gets trees, while the center gets rubble
415 if ((distance(j, i, y, x) > 1) || (randint1(100) < 25))
417 if (randint1(100) < 75)
418 floor_ptr->grid_array[j][i].feat = feat_tree;
422 floor_ptr->grid_array[j][i].feat = feat_rubble;
425 /* Clear garbage of hidden trap or door */
428 /* Light area since is open above */
429 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
434 /* No up stairs in ironman mode */
435 if (!ironman_downward && one_in_(3))
438 floor_ptr->grid_array[y][x].feat = feat_up_stair;
444 * @brief ダンジョンに*破壊*済み地形ランダムに施す /
445 * Build a destroyed level
448 void destroy_level(void)
453 /* Note destroyed levels */
454 msg_print_wizard(CHEAT_DUNGEON, _("階に*破壊*の痕跡を生成しました。", "Destroyed Level."));
456 /* Drop a few epi-centers (usually about two) */
457 for (n = 0; n < randint1(5); n++)
459 /* Pick an epi-center */
460 x1 = rand_range(5, p_ptr->current_floor_ptr->width - 1 - 5);
461 y1 = rand_range(5, p_ptr->current_floor_ptr->height - 1 - 5);
463 (void)destroy_area(y1, x1, 15, TRUE);