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 "flavor/flavor-describer.h"
18 #include "flavor/object-flavor-types.h"
19 #include "floor/cave.h"
20 #include "floor/floor-generator-util.h"
21 #include "floor/floor-generator.h"
22 #include "floor/floor-object.h"
23 #include "floor/geometry.h"
24 #include "game-option/birth-options.h"
25 #include "game-option/cheat-options.h"
26 #include "game-option/cheat-types.h"
27 #include "grid/feature.h"
28 #include "grid/grid.h"
29 #include "monster-race/monster-race.h"
30 #include "monster/monster-info.h"
31 #include "room/lake-types.h"
32 #include "spell-kind/spells-floor.h"
33 #include "system/artifact-type-definition.h"
34 #include "system/dungeon-data-definition.h"
35 #include "system/dungeon-info.h"
36 #include "system/floor-type-definition.h"
37 #include "system/grid-type-definition.h"
38 #include "system/monster-race-definition.h"
39 #include "system/monster-type-definition.h"
40 #include "system/player-type-definition.h"
41 #include "system/terrain-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(FloorType *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)) {
117 g_ptr = &floor_ptr->grid_array[ty][tx];
119 if (g_ptr->feat == feat1) {
122 if (g_ptr->feat == feat2) {
126 if (distance(ty, tx, y, x) > rand_spread(width, 1)) {
130 /* Do not convert permanent features */
131 if (g_ptr->cave_has_flag(TerrainCharacteristics::PERMANENT)) {
136 * Clear previous contents, add feature
137 * The border mainly gets feat2, while the center gets feat1
139 if (distance(ty, tx, y, x) > width) {
145 /* Clear garbage of hidden trap or door */
148 /* Lava terrain glows */
149 if (terrains_info[feat1].flags.has(TerrainCharacteristics::LAVA)) {
150 if (dungeons_info[floor_ptr->dungeon_idx].flags.has_not(DungeonFeatureType::DARKNESS)) {
151 g_ptr->info |= CAVE_GLOW;
155 /* Hack -- don't teleport here */
156 g_ptr->info |= CAVE_ICKY;
167 * @brief ランダムに川/溶岩流をダンジョンに配置する /
168 * Places water /lava through dungeon.
169 * @param feat1 中央部地形ID
170 * @param feat2 境界部地形ID
172 void add_river(FloorType *floor_ptr, dun_data_type *dd_ptr)
174 dungeon_type *dungeon_ptr;
176 POSITION y1 = 0, x1 = 0;
178 FEAT_IDX feat1 = 0, feat2 = 0;
180 dungeon_ptr = &dungeons_info[floor_ptr->dungeon_idx];
182 /* Choose water mainly */
183 if ((randint1(MAX_DEPTH * 2) - 1 > floor_ptr->dun_level) && dungeon_ptr->flags.has(DungeonFeatureType::WATER_RIVER)) {
184 feat1 = feat_deep_water;
185 feat2 = feat_shallow_water;
188 FEAT_IDX select_deep_feat[10];
189 FEAT_IDX select_shallow_feat[10];
190 int select_id_max = 0, selected;
192 if (dungeon_ptr->flags.has(DungeonFeatureType::LAVA_RIVER)) {
193 select_deep_feat[select_id_max] = feat_deep_lava;
194 select_shallow_feat[select_id_max] = feat_shallow_lava;
197 if (dungeon_ptr->flags.has(DungeonFeatureType::POISONOUS_RIVER)) {
198 select_deep_feat[select_id_max] = feat_deep_poisonous_puddle;
199 select_shallow_feat[select_id_max] = feat_shallow_poisonous_puddle;
202 if (dungeon_ptr->flags.has(DungeonFeatureType::ACID_RIVER)) {
203 select_deep_feat[select_id_max] = feat_deep_acid_puddle;
204 select_shallow_feat[select_id_max] = feat_shallow_acid_puddle;
208 if (select_id_max > 0) {
209 selected = randint0(select_id_max);
210 feat1 = select_deep_feat[selected];
211 feat2 = select_shallow_feat[selected];
218 auto *f_ptr = &terrains_info[feat1];
220 /* Only add river if matches lake type or if have no lake at all */
221 if (!(((dd_ptr->laketype == LAKE_T_LAVA) && f_ptr->flags.has(TerrainCharacteristics::LAVA)) || ((dd_ptr->laketype == LAKE_T_WATER) && f_ptr->flags.has(TerrainCharacteristics::WATER)) || !dd_ptr->laketype)) {
226 /* Hack -- Choose starting point */
227 y2 = randint1(floor_ptr->height / 2 - 2) + floor_ptr->height / 2;
228 x2 = randint1(floor_ptr->width / 2 - 2) + floor_ptr->width / 2;
230 /* Hack -- Choose ending point somewhere on boundary */
231 switch (randint1(4)) {
234 x1 = randint1(floor_ptr->width - 2) + 1;
241 y1 = randint1(floor_ptr->height - 2) + 1;
246 x1 = floor_ptr->width - 1;
247 y1 = randint1(floor_ptr->height - 2) + 1;
251 /* bottom boundary */
252 x1 = randint1(floor_ptr->width - 2) + 1;
253 y1 = floor_ptr->height - 1;
258 wid = randint1(DUN_WAT_RNG);
259 recursive_river(floor_ptr, x1, y1, x2, y2, feat1, feat2, wid);
261 /* Hack - Save the location as a "room" */
262 if (dd_ptr->cent_n < CENT_MAX) {
263 dd_ptr->cent[dd_ptr->cent_n].y = y2;
264 dd_ptr->cent[dd_ptr->cent_n].x = x2;
270 * @brief ダンジョンの壁部にストリーマー(地質の変化)を与える /
271 * Places "streamers" of rock through dungeon
272 * @param player_ptr プレイヤーへの参照ポインタ
273 * @param feat ストリーマー地形ID
277 * Note that their are actually six different terrain features used
278 * to represent streamers. Three each of magma and quartz, one for
279 * basic vein, one with hidden gold, and one with known gold. The
280 * hidden gold types are currently unused.
283 void build_streamer(PlayerType *player_ptr, FEAT_IDX feat, int chance)
286 POSITION y, x, tx, ty;
293 TerrainType *streamer_ptr = &terrains_info[feat];
294 bool streamer_is_wall = streamer_ptr->flags.has(TerrainCharacteristics::WALL) && streamer_ptr->flags.has_not(TerrainCharacteristics::PERMANENT);
295 bool streamer_may_have_gold = streamer_ptr->flags.has(TerrainCharacteristics::MAY_HAVE_GOLD);
297 /* Hack -- Choose starting point */
298 auto *floor_ptr = player_ptr->current_floor_ptr;
299 y = rand_spread(floor_ptr->height / 2, floor_ptr->height / 6);
300 x = rand_spread(floor_ptr->width / 2, floor_ptr->width / 6);
302 /* Choose a random compass direction */
305 /* Place streamer into dungeon */
306 while (dummy < SAFE_MAX_ATTEMPTS) {
309 /* One grid per density */
310 constexpr auto stream_density = 5;
311 for (i = 0; i < stream_density; i++) {
312 constexpr auto stream_width = 5;
313 int d = stream_width;
315 /* Pick a nearby grid */
317 ty = rand_spread(y, d);
318 tx = rand_spread(x, d);
319 if (!in_bounds2(floor_ptr, ty, tx)) {
324 g_ptr = &floor_ptr->grid_array[ty][tx];
325 f_ptr = &terrains_info[g_ptr->feat];
327 if (f_ptr->flags.has(TerrainCharacteristics::MOVE) && f_ptr->flags.has_any_of({ TerrainCharacteristics::WATER, TerrainCharacteristics::LAVA })) {
331 /* Do not convert permanent features */
332 if (f_ptr->flags.has(TerrainCharacteristics::PERMANENT)) {
336 /* Only convert "granite" walls */
337 if (streamer_is_wall) {
338 if (!g_ptr->is_extra() && !g_ptr->is_inner() && !g_ptr->is_outer() && !g_ptr->is_solid()) {
341 if (is_closed_door(player_ptr, g_ptr->feat)) {
346 if (g_ptr->m_idx && !(streamer_ptr->flags.has(TerrainCharacteristics::PLACE) && monster_can_cross_terrain(player_ptr, feat, &monraces_info[floor_ptr->m_list[g_ptr->m_idx].r_idx], 0))) {
347 /* Delete the monster (if any) */
348 delete_monster(player_ptr, ty, tx);
351 if (!g_ptr->o_idx_list.empty() && streamer_ptr->flags.has_not(TerrainCharacteristics::DROP)) {
353 /* Scan all objects in the grid */
354 for (const auto this_o_idx : g_ptr->o_idx_list) {
355 auto *o_ptr = &floor_ptr->o_list[this_o_idx];
357 /* Hack -- Preserve unknown artifacts */
358 if (o_ptr->is_fixed_artifact()) {
359 artifacts_info.at(o_ptr->fixed_artifact_idx).is_generated = false;
362 GAME_TEXT o_name[MAX_NLEN];
363 describe_flavor(player_ptr, o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
364 msg_format(_("伝説のアイテム (%s) はストリーマーにより削除された。", "Artifact (%s) was deleted by streamer."), o_name);
366 } else if (cheat_peek && o_ptr->art_name) {
367 msg_print(_("ランダム・アーティファクトの1つはストリーマーにより削除された。", "One of the random artifacts was deleted by streamer."));
371 delete_all_items_from_floor(player_ptr, ty, tx);
374 /* Clear previous contents, add proper vein type */
377 /* Paranoia: Clear mimic field */
380 if (streamer_may_have_gold) {
381 /* Hack -- Add some known treasure */
382 if (one_in_(chance)) {
383 cave_alter_feat(player_ptr, ty, tx, TerrainCharacteristics::MAY_HAVE_GOLD);
386 /* Hack -- Add some hidden treasure */
387 else if (one_in_(chance / 4)) {
388 cave_alter_feat(player_ptr, ty, tx, TerrainCharacteristics::MAY_HAVE_GOLD);
389 cave_alter_feat(player_ptr, ty, tx, TerrainCharacteristics::ENSECRET);
394 if (dummy >= SAFE_MAX_ATTEMPTS) {
395 msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("地形のストリーマー処理に失敗しました。", "Failed to place streamer."));
399 /* Advance the streamer */
407 dir = (dir > 0) ? dir - 1 : 7;
411 /* Quit before leaving the dungeon */
412 if (!in_bounds(floor_ptr, y, x)) {
419 * @brief ダンジョンの指定位置近辺に森林を配置する /
420 * Places "streamers" of rock through dungeon
425 * Put trees near a hole in the dungeon roof (rubble on ground + up stairway)
426 * This happens in real world lava tubes.
429 void place_trees(PlayerType *player_ptr, POSITION x, POSITION y)
434 /* place trees/ rubble in ovalish distribution */
435 auto *floor_ptr = player_ptr->current_floor_ptr;
436 for (i = x - 3; i < x + 4; i++) {
437 for (j = y - 3; j < y + 4; j++) {
438 if (!in_bounds(floor_ptr, j, i)) {
441 g_ptr = &floor_ptr->grid_array[j][i];
443 if (g_ptr->info & CAVE_ICKY) {
446 if (!g_ptr->o_idx_list.empty()) {
450 /* Want square to be in the circle and accessable. */
451 if ((distance(j, i, y, x) < 4) && !g_ptr->cave_has_flag(TerrainCharacteristics::PERMANENT)) {
453 * Clear previous contents, add feature
454 * The border mainly gets trees, while the center gets rubble
456 if ((distance(j, i, y, x) > 1) || (randint1(100) < 25)) {
457 if (randint1(100) < 75) {
458 floor_ptr->grid_array[j][i].feat = feat_tree;
461 floor_ptr->grid_array[j][i].feat = feat_rubble;
464 /* Clear garbage of hidden trap or door */
467 /* Light area since is open above */
468 if (dungeons_info[player_ptr->dungeon_idx].flags.has_not(DungeonFeatureType::DARKNESS)) {
469 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
475 /* No up stairs in ironman mode */
476 if (!ironman_downward && one_in_(3)) {
478 floor_ptr->grid_array[y][x].feat = feat_up_stair;
483 * @brief ダンジョンに*破壊*済み地形ランダムに施す /
484 * Build a destroyed level
486 void destroy_level(PlayerType *player_ptr)
488 msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("階に*破壊*の痕跡を生成しました。", "Destroyed Level."));
490 /* Drop a few epi-centers (usually about two) */
492 auto *floor_ptr = player_ptr->current_floor_ptr;
493 for (int n = 0; n < randint1(5); n++) {
494 /* Pick an epi-center */
495 x1 = rand_range(5, floor_ptr->width - 1 - 5);
496 y1 = rand_range(5, floor_ptr->height - 1 - 5);
498 (void)destroy_area(player_ptr, y1, x1, 15, true);