2 * @brief ダンジョン生成に利用する関数群 / Used by dungeon generation.
5 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
10 * Purpose: This file holds all the
11 * functions that are applied to a level after the rest has been
12 * generated, ie streams and level destruction.
15 #include "floor/floor-streams.h"
16 #include "dungeon/dungeon-flag-types.h"
17 #include "dungeon/dungeon.h"
18 #include "flavor/flavor-describer.h"
19 #include "flavor/object-flavor-types.h"
20 #include "floor/cave.h"
21 #include "floor/floor-generator-util.h"
22 #include "floor/floor-generator.h"
23 #include "floor/floor-object.h"
24 #include "floor/geometry.h"
25 #include "game-option/birth-options.h"
26 #include "game-option/cheat-options.h"
27 #include "game-option/cheat-types.h"
28 #include "grid/feature.h"
29 #include "grid/grid.h"
30 #include "monster-race/monster-race.h"
31 #include "monster/monster-info.h"
32 #include "object-hook/hook-enchant.h"
33 #include "room/lake-types.h"
34 #include "spell-kind/spells-floor.h"
35 #include "system/artifact-type-definition.h"
36 #include "system/dungeon-data-definition.h"
37 #include "system/floor-type-definition.h"
38 #include "system/grid-type-definition.h"
39 #include "system/monster-race-definition.h"
40 #include "system/monster-type-definition.h"
41 #include "system/player-type-definition.h"
42 #include "util/bit-flags-calculator.h"
43 #include "view/display-messages.h"
44 #include "wizard/wizard-messages.h"
47 * @brief 再帰フラクタルアルゴリズムによりダンジョン内に川を配置する /
48 * Recursive fractal algorithm to place water through the dungeon.
53 * @param feat1 中央部地形ID
54 * @param feat2 境界部地形ID
57 static void recursive_river(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX feat1, FEAT_IDX feat2, POSITION width)
59 POSITION dx, dy, length, l, x, y;
60 POSITION changex, changey;
65 length = distance(x1, y1, x2, y2);
69 * Divide path in half and call routine twice.
70 * There is a small chance of splitting the river
76 /* perturbation perpendicular to path */
77 changex = randint1(abs(dy)) * 2 - abs(dy);
83 /* perturbation perpendicular to path */
84 changey = randint1(abs(dx)) * 2 - abs(dx);
89 if (!in_bounds(floor_ptr, y1 + dy + changey, x1 + dx + changex)) {
94 /* construct river out of two smaller ones */
95 recursive_river(floor_ptr, x1, y1, x1 + dx + changex, y1 + dy + changey, feat1, feat2, width);
96 recursive_river(floor_ptr, x1 + dx + changex, y1 + dy + changey, x2, y2, feat1, feat2, width);
98 /* Split the river some of the time - junctions look cool */
99 if (one_in_(DUN_WAT_CHG) && (width > 0)) {
100 recursive_river(floor_ptr, x1 + dx + changex, y1 + dy + changey, x1 + 8 * (dx + changex), y1 + 8 * (dy + changey), feat1, feat2, width - 1);
103 /* Actually build the river */
104 for (l = 0; l < length; l++) {
105 x = x1 + l * (x2 - x1) / length;
106 y = y1 + l * (y2 - y1) / length;
111 for (ty = y - width - 1; ty <= y + width + 1; ty++) {
112 for (tx = x - width - 1; tx <= x + width + 1; tx++) {
113 if (!in_bounds2(floor_ptr, ty, tx))
116 g_ptr = &floor_ptr->grid_array[ty][tx];
118 if (g_ptr->feat == feat1)
120 if (g_ptr->feat == feat2)
123 if (distance(ty, tx, y, x) > rand_spread(width, 1))
126 /* Do not convert permanent features */
127 if (cave_has_flag_grid(g_ptr, FF_PERMANENT))
131 * Clear previous contents, add feature
132 * The border mainly gets feat2, while the center gets feat1
134 if (distance(ty, tx, y, x) > width)
139 /* Clear garbage of hidden trap or door */
142 /* Lava terrain glows */
143 if (has_flag(f_info[feat1].flags, FF_LAVA)) {
144 if (d_info[floor_ptr->dungeon_idx].flags.has_not(DF::DARKNESS))
145 g_ptr->info |= CAVE_GLOW;
148 /* Hack -- don't teleport here */
149 g_ptr->info |= CAVE_ICKY;
160 * @brief ランダムに川/溶岩流をダンジョンに配置する /
161 * Places water /lava through dungeon.
162 * @param feat1 中央部地形ID
163 * @param feat2 境界部地形ID
165 void add_river(floor_type *floor_ptr, dun_data_type *dd_ptr)
167 dungeon_type *dungeon_ptr;
169 POSITION y1 = 0, x1 = 0;
171 FEAT_IDX feat1 = 0, feat2 = 0;
173 dungeon_ptr = &d_info[floor_ptr->dungeon_idx];
175 /* Choose water mainly */
176 if ((randint1(MAX_DEPTH * 2) - 1 > floor_ptr->dun_level) && dungeon_ptr->flags.has(DF::WATER_RIVER)) {
177 feat1 = feat_deep_water;
178 feat2 = feat_shallow_water;
181 FEAT_IDX select_deep_feat[10];
182 FEAT_IDX select_shallow_feat[10];
183 int select_id_max = 0, selected;
185 if (dungeon_ptr->flags.has(DF::LAVA_RIVER)) {
186 select_deep_feat[select_id_max] = feat_deep_lava;
187 select_shallow_feat[select_id_max] = feat_shallow_lava;
190 if (dungeon_ptr->flags.has(DF::POISONOUS_RIVER)) {
191 select_deep_feat[select_id_max] = feat_deep_poisonous_puddle;
192 select_shallow_feat[select_id_max] = feat_shallow_poisonous_puddle;
195 if (dungeon_ptr->flags.has(DF::ACID_RIVER)) {
196 select_deep_feat[select_id_max] = feat_deep_acid_puddle;
197 select_shallow_feat[select_id_max] = feat_shallow_acid_puddle;
201 if (select_id_max > 0) {
202 selected = randint0(select_id_max);
203 feat1 = select_deep_feat[selected];
204 feat2 = select_shallow_feat[selected];
211 feature_type *f_ptr = &f_info[feat1];
213 /* Only add river if matches lake type or if have no lake at all */
214 if (!(((dd_ptr->laketype == LAKE_T_LAVA) && has_flag(f_ptr->flags, FF_LAVA)) || ((dd_ptr->laketype == LAKE_T_WATER) && has_flag(f_ptr->flags, FF_WATER))
215 || !dd_ptr->laketype)) {
220 /* Hack -- Choose starting point */
221 y2 = randint1(floor_ptr->height / 2 - 2) + floor_ptr->height / 2;
222 x2 = randint1(floor_ptr->width / 2 - 2) + floor_ptr->width / 2;
224 /* Hack -- Choose ending point somewhere on boundary */
225 switch (randint1(4)) {
228 x1 = randint1(floor_ptr->width - 2) + 1;
235 y1 = randint1(floor_ptr->height - 2) + 1;
240 x1 = floor_ptr->width - 1;
241 y1 = randint1(floor_ptr->height - 2) + 1;
245 /* bottom boundary */
246 x1 = randint1(floor_ptr->width - 2) + 1;
247 y1 = floor_ptr->height - 1;
252 wid = randint1(DUN_WAT_RNG);
253 recursive_river(floor_ptr, x1, y1, x2, y2, feat1, feat2, wid);
255 /* Hack - Save the location as a "room" */
256 if (dd_ptr->cent_n < CENT_MAX) {
257 dd_ptr->cent[dd_ptr->cent_n].y = y2;
258 dd_ptr->cent[dd_ptr->cent_n].x = x2;
264 * @brief ダンジョンの壁部にストリーマー(地質の変化)を与える /
265 * Places "streamers" of rock through dungeon
266 * @param player_ptr プレーヤーへの参照ポインタ
267 * @param feat ストリーマー地形ID
271 * Note that their are actually six different terrain features used
272 * to represent streamers. Three each of magma and quartz, one for
273 * basic vein, one with hidden gold, and one with known gold. The
274 * hidden gold types are currently unused.
277 void build_streamer(player_type *player_ptr, FEAT_IDX feat, int chance)
280 POSITION y, x, tx, ty;
287 feature_type *streamer_ptr = &f_info[feat];
288 bool streamer_is_wall = has_flag(streamer_ptr->flags, FF_WALL) && !has_flag(streamer_ptr->flags, FF_PERMANENT);
289 bool streamer_may_have_gold = has_flag(streamer_ptr->flags, FF_MAY_HAVE_GOLD);
291 /* Hack -- Choose starting point */
292 floor_type *floor_ptr = player_ptr->current_floor_ptr;
293 y = rand_spread(floor_ptr->height / 2, floor_ptr->height / 6);
294 x = rand_spread(floor_ptr->width / 2, floor_ptr->width / 6);
296 /* Choose a random compass direction */
299 /* Place streamer into dungeon */
300 while (dummy < SAFE_MAX_ATTEMPTS) {
303 /* One grid per density */
304 for (i = 0; i < DUN_STR_DEN; i++) {
307 /* Pick a nearby grid */
309 ty = rand_spread(y, d);
310 tx = rand_spread(x, d);
311 if (!in_bounds2(floor_ptr, ty, tx))
315 g_ptr = &floor_ptr->grid_array[ty][tx];
316 f_ptr = &f_info[g_ptr->feat];
318 if (has_flag(f_ptr->flags, FF_MOVE) && (has_flag(f_ptr->flags, FF_WATER) || has_flag(f_ptr->flags, FF_LAVA)))
321 /* Do not convert permanent features */
322 if (has_flag(f_ptr->flags, FF_PERMANENT))
325 /* Only convert "granite" walls */
326 if (streamer_is_wall) {
327 if (!g_ptr->is_extra() && !g_ptr->is_inner() && !g_ptr->is_outer() && !g_ptr->is_solid())
329 if (is_closed_door(player_ptr, g_ptr->feat))
334 && !(has_flag(streamer_ptr->flags, FF_PLACE)
335 && monster_can_cross_terrain(player_ptr, feat, &r_info[floor_ptr->m_list[g_ptr->m_idx].r_idx], 0))) {
336 /* Delete the monster (if any) */
337 delete_monster(player_ptr, ty, tx);
340 if (!g_ptr->o_idx_list.empty() && !has_flag(streamer_ptr->flags, FF_DROP)) {
342 /* Scan all objects in the grid */
343 for (const auto this_o_idx : g_ptr->o_idx_list) {
344 object_type *o_ptr = &floor_ptr->o_list[this_o_idx];
346 /* Hack -- Preserve unknown artifacts */
347 if (object_is_fixed_artifact(o_ptr)) {
348 /* Mega-Hack -- Preserve the artifact */
349 a_info[o_ptr->name1].cur_num = 0;
352 GAME_TEXT o_name[MAX_NLEN];
353 describe_flavor(player_ptr, o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
354 msg_format(_("伝説のアイテム (%s) はストリーマーにより削除された。", "Artifact (%s) was deleted by streamer."), o_name);
356 } else if (cheat_peek && o_ptr->art_name) {
357 msg_print(_("ランダム・アーティファクトの1つはストリーマーにより削除された。", "One of the random artifacts was deleted by streamer."));
361 delete_all_items_from_floor(player_ptr, ty, tx);
364 /* Clear previous contents, add proper vein type */
367 /* Paranoia: Clear mimic field */
370 if (streamer_may_have_gold) {
371 /* Hack -- Add some known treasure */
372 if (one_in_(chance)) {
373 cave_alter_feat(player_ptr, ty, tx, FF_MAY_HAVE_GOLD);
376 /* Hack -- Add some hidden treasure */
377 else if (one_in_(chance / 4)) {
378 cave_alter_feat(player_ptr, ty, tx, FF_MAY_HAVE_GOLD);
379 cave_alter_feat(player_ptr, ty, tx, FF_ENSECRET);
384 if (dummy >= SAFE_MAX_ATTEMPTS) {
385 msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("地形のストリーマー処理に失敗しました。", "Failed to place streamer."));
389 /* Advance the streamer */
397 dir = (dir > 0) ? dir - 1 : 7;
400 /* Quit before leaving the dungeon */
401 if (!in_bounds(floor_ptr, y, x))
407 * @brief ダンジョンの指定位置近辺に森林を配置する /
408 * Places "streamers" of rock through dungeon
413 * Put trees near a hole in the dungeon roof (rubble on ground + up stairway)
414 * This happens in real world lava tubes.
417 void place_trees(player_type *player_ptr, POSITION x, POSITION y)
422 /* place trees/ rubble in ovalish distribution */
423 floor_type *floor_ptr = player_ptr->current_floor_ptr;
424 for (i = x - 3; i < x + 4; i++) {
425 for (j = y - 3; j < y + 4; j++) {
426 if (!in_bounds(floor_ptr, j, i))
428 g_ptr = &floor_ptr->grid_array[j][i];
430 if (g_ptr->info & CAVE_ICKY)
432 if (!g_ptr->o_idx_list.empty())
435 /* Want square to be in the circle and accessable. */
436 if ((distance(j, i, y, x) < 4) && !cave_has_flag_grid(g_ptr, FF_PERMANENT)) {
438 * Clear previous contents, add feature
439 * The border mainly gets trees, while the center gets rubble
441 if ((distance(j, i, y, x) > 1) || (randint1(100) < 25)) {
442 if (randint1(100) < 75)
443 floor_ptr->grid_array[j][i].feat = feat_tree;
445 floor_ptr->grid_array[j][i].feat = feat_rubble;
448 /* Clear garbage of hidden trap or door */
451 /* Light area since is open above */
452 if (d_info[player_ptr->dungeon_idx].flags.has_not(DF::DARKNESS))
453 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
458 /* No up stairs in ironman mode */
459 if (!ironman_downward && one_in_(3)) {
461 floor_ptr->grid_array[y][x].feat = feat_up_stair;
466 * @brief ダンジョンに*破壊*済み地形ランダムに施す /
467 * Build a destroyed level
469 void destroy_level(player_type *player_ptr)
471 msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("階に*破壊*の痕跡を生成しました。", "Destroyed Level."));
473 /* Drop a few epi-centers (usually about two) */
475 floor_type *floor_ptr = player_ptr->current_floor_ptr;
476 for (int n = 0; n < randint1(5); n++) {
477 /* Pick an epi-center */
478 x1 = rand_range(5, floor_ptr->width - 1 - 5);
479 y1 = rand_range(5, floor_ptr->height - 1 - 5);
481 (void)destroy_area(player_ptr, y1, x1, 15, true);