3 * @brief ダンジョンの生成 / Dungeon generation
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research,\n
8 * and not for profit purposes provided that this copyright and statement\n
9 * are included in all such copies. Other copyrights may also apply.\n
10 * 2014 Deskull rearranged comment for Doxygen. \n
13 #include "system/angband.h"
14 #include "util/util.h"
15 #include "system/system-variables.h"
16 #include "cmd-building/cmd-building.h"
17 #include "io/write-diary.h"
18 #include "cmd-io/cmd-dump.h"
19 #include "grid/grid.h"
20 #include "market/arena-info-table.h"
21 #include "room/rooms.h"
22 #include "dungeon/dungeon.h"
23 #include "floor/floor.h"
24 #include "floor/floor-save.h"
25 #include "floor/floor-streams.h"
26 #include "floor/floor-generate.h"
27 #include "floor/floor-events.h"
28 #include "floor/floor-generate.h"
29 #include "grid/feature.h"
30 #include "grid/trap.h"
31 #include "info-reader/feature-reader.h"
32 #include "monster/monster.h"
33 #include "dungeon/quest.h"
34 #include "player/player-status.h"
35 #include "floor/wild.h"
36 #include "monster/monster-status.h"
37 #include "dungeon/dungeon-file.h"
38 #include "grid/feature.h"
39 #include "world/world.h"
40 #include "view/display-main-window.h"
50 * Dungeon generation data -- see "cave_gen()"
56 * @brief 上下左右の外壁数をカウントする / Count the number of walls adjacent to the given grid.
60 * @note Assumes "in_bounds()"
61 * @details We count only granite walls and permanent walls.
63 static int next_to_walls(floor_type* floor_ptr, POSITION y, POSITION x)
67 if (in_bounds(floor_ptr, y + 1, x) && is_extra_bold(floor_ptr, y + 1, x)) k++;
68 if (in_bounds(floor_ptr, y - 1, x) && is_extra_bold(floor_ptr, y - 1, x)) k++;
69 if (in_bounds(floor_ptr, y, x + 1) && is_extra_bold(floor_ptr, y, x + 1)) k++;
70 if (in_bounds(floor_ptr, y, x - 1) && is_extra_bold(floor_ptr, y, x - 1)) k++;
76 * @brief alloc_stairs()の補助として指定の位置に階段を生成できるかの判定を行う / Helper function for alloc_stairs(). Is this a good location for stairs?
77 * @param player_ptr プレーヤーへの参照ポインタ
80 * @param walls 最低減隣接させたい外壁の数
81 * @return 階段を生成して問題がないならばTRUEを返す。
83 static bool alloc_stairs_aux(player_type *player_ptr, POSITION y, POSITION x, int walls)
85 floor_type *floor_ptr = player_ptr->current_floor_ptr;
86 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
88 /* Require "naked" floor grid */
89 if (!is_floor_grid(g_ptr)) return FALSE;
90 if (pattern_tile(floor_ptr, y, x)) return FALSE;
91 if (g_ptr->o_idx || g_ptr->m_idx) return FALSE;
93 /* Require a certain number of adjacent walls */
94 if (next_to_walls(floor_ptr, y, x) < walls) return FALSE;
101 * @brief 外壁に隣接させて階段を生成する / Places some staircases near walls
102 * @param owner_ptr プレーヤーへの参照ポインタ
103 * @param feat 配置したい地形ID
104 * @param num 配置したい階段の数
105 * @param walls 最低減隣接させたい外壁の数
106 * @return 規定数通りに生成に成功したらTRUEを返す。
108 static bool alloc_stairs(player_type *owner_ptr, FEAT_IDX feat, int num, int walls)
113 feature_type *f_ptr = &f_info[feat];
115 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
116 if (have_flag(f_ptr->flags, FF_LESS))
118 /* No up stairs in town or in ironman mode */
119 if (ironman_downward || !floor_ptr->dun_level) return TRUE;
121 if (floor_ptr->dun_level > d_info[floor_ptr->dungeon_idx].mindepth)
122 shaft_num = (randint1(num+1))/2;
124 else if (have_flag(f_ptr->flags, FF_MORE))
126 QUEST_IDX q_idx = quest_number(owner_ptr, floor_ptr->dun_level);
128 /* No downstairs on quest levels */
129 if (floor_ptr->dun_level > 1 && q_idx)
131 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
133 /* The quest monster(s) is still alive? */
134 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
138 /* No downstairs at the bottom */
139 if (floor_ptr->dun_level >= d_info[floor_ptr->dungeon_idx].maxdepth) return TRUE;
141 if ((floor_ptr->dun_level < d_info[floor_ptr->dungeon_idx].maxdepth-1) && !quest_number(owner_ptr, floor_ptr->dun_level+1))
142 shaft_num = (randint1(num)+1)/2;
147 /* Place "num" stairs */
148 for (i = 0; i < num; i++)
158 for (y = 1; y < floor_ptr->height - 1; y++)
160 for (x = 1; x < floor_ptr->width - 1; x++)
162 if (alloc_stairs_aux(owner_ptr, y, x, walls))
164 /* A valid space found */
170 /* No valid place! */
173 /* There are exactly no place! */
174 if (walls <= 0) return FALSE;
176 /* Decrease walls limit, and try again */
181 /* Choose a random one */
182 pick = randint1(candidates);
184 for (y = 1; y < floor_ptr->height - 1; y++)
186 for (x = 1; x < floor_ptr->width - 1; x++)
188 if (alloc_stairs_aux(owner_ptr, y, x, walls))
192 /* Is this a picked one? */
199 g_ptr = &floor_ptr->grid_array[y][x];
201 /* Clear possible garbage of hidden trap */
204 /* Clear previous contents, add stairs */
205 g_ptr->feat = (i < shaft_num) ? feat_state(owner_ptr, feat, FF_SHAFT) : feat;
207 /* No longer "FLOOR" */
208 g_ptr->info &= ~(CAVE_FLOOR);
218 * @brief フロア上のランダム位置に各種オブジェクトを配置する / Allocates some objects (using "place" and "type")
219 * @param set 配置したい地形の種類
220 * @param typ 配置したいオブジェクトの種類
222 * @return 規定数通りに生成に成功したらTRUEを返す。
224 static void alloc_object(player_type *owner_ptr, int set, EFFECT_ID typ, int num)
226 POSITION y = 0, x = 0;
231 /* A small level has few objects. */
232 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
233 num = num * floor_ptr->height * floor_ptr->width / (MAX_HGT*MAX_WID) +1;
235 /* Place some objects */
236 for (k = 0; k < num; k++)
238 /* Pick a "legal" spot */
239 while (dummy < SAFE_MAX_ATTEMPTS)
245 y = randint0(floor_ptr->height);
246 x = randint0(floor_ptr->width);
248 g_ptr = &floor_ptr->grid_array[y][x];
250 /* Require "naked" floor grid */
251 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
253 /* Avoid player location */
254 if (player_bold(owner_ptr, y, x)) continue;
256 /* Check for "room" */
257 room = (floor_ptr->grid_array[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
259 /* Require corridor? */
260 if ((set == ALLOC_SET_CORR) && room) continue;
263 if ((set == ALLOC_SET_ROOM) && !room) continue;
269 if (dummy >= SAFE_MAX_ATTEMPTS)
271 msg_print_wizard(CHEAT_DUNGEON, _("アイテムの配置に失敗しました。", "Failed to place object."));
276 /* Place something */
279 case ALLOC_TYP_RUBBLE:
281 place_rubble(floor_ptr, y, x);
282 floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
288 place_trap(owner_ptr, y, x);
289 floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
295 place_gold(owner_ptr, y, x);
299 case ALLOC_TYP_OBJECT:
301 place_object(owner_ptr, y, x, 0L);
312 * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
313 * @param creature_ptr プレーヤーへの参照ポインタ
314 * @return 成功したならばTRUEを返す
316 bool place_quest_monsters(player_type *creature_ptr)
320 /* Handle the quest monster placements */
321 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
322 for (i = 0; i < max_q_idx; i++)
328 if (quest[i].status != QUEST_STATUS_TAKEN ||
329 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
330 quest[i].type != QUEST_TYPE_RANDOM) ||
331 quest[i].level != floor_ptr->dun_level ||
332 creature_ptr->dungeon_idx != quest[i].dungeon ||
333 (quest[i].flags & QUEST_FLAG_PRESET))
339 r_ptr = &r_info[quest[i].r_idx];
341 /* Hack -- "unique" monsters must be "unique" */
342 if ((r_ptr->flags1 & RF1_UNIQUE) &&
343 (r_ptr->cur_num >= r_ptr->max_num)) continue;
345 mode = (PM_NO_KAGE | PM_NO_PET);
347 if (!(r_ptr->flags1 & RF1_FRIENDS))
348 mode |= PM_ALLOW_GROUP;
350 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
354 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
356 POSITION x = 0, y = 0;
359 /* Find an empty grid */
360 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
365 y = randint0(floor_ptr->height);
366 x = randint0(floor_ptr->width);
368 g_ptr = &floor_ptr->grid_array[y][x];
369 f_ptr = &f_info[g_ptr->feat];
371 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
372 if (!monster_can_enter(creature_ptr, y, x, r_ptr, 0)) continue;
373 if (distance(y, x, creature_ptr->y, creature_ptr->x) < 10) continue;
374 if (g_ptr->info & CAVE_ICKY) continue;
378 /* Failed to place */
379 if (!l) return FALSE;
381 /* Try to place the monster */
382 if (place_monster_aux(creature_ptr, 0, y, x, quest[i].r_idx, mode))
389 /* Failure - Try again */
394 /* Failed to place */
395 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
403 * @brief フロアに洞窟や湖を配置する / Generate various caverns and lakes
404 * @details There were moved from cave_gen().
407 static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, player_type *owner_ptr)
409 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
410 /* Possible "destroyed" level */
411 if ((floor_ptr->dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (dungeon_ptr->flags1 & DF1_DESTROY))
413 dun->destroyed = TRUE;
415 /* extra rubble around the place looks cool */
416 build_lake(owner_ptr, one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
419 /* Make a lake some of the time */
420 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
421 (dungeon_ptr->flags1 & DF1_LAKE_MASK))
424 if (dungeon_ptr->flags1 & DF1_LAKE_WATER) count += 3;
425 if (dungeon_ptr->flags1 & DF1_LAKE_LAVA) count += 3;
426 if (dungeon_ptr->flags1 & DF1_LAKE_RUBBLE) count += 3;
427 if (dungeon_ptr->flags1 & DF1_LAKE_TREE) count += 3;
429 if (dungeon_ptr->flags1 & DF1_LAKE_LAVA)
432 if ((floor_ptr->dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
436 if (!dun->laketype && (floor_ptr->dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
440 if ((dungeon_ptr->flags1 & DF1_LAKE_WATER) && !dun->laketype)
443 if ((floor_ptr->dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
447 if (!dun->laketype && (floor_ptr->dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
451 if ((dungeon_ptr->flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
454 if ((floor_ptr->dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
457 /* Lake of rubble2 */
458 if (!dun->laketype && (floor_ptr->dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
463 if ((floor_ptr->dun_level > 5) && (dungeon_ptr->flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
467 msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
468 build_lake(owner_ptr, dun->laketype);
472 if ((floor_ptr->dun_level > DUN_CAVERN) && !dun->empty_level &&
473 (dungeon_ptr->flags1 & DF1_CAVERN) &&
474 !dun->laketype && !dun->destroyed && (randint1(1000) < floor_ptr->dun_level))
478 /* make a large fractal floor_ptr->grid_array in the middle of the dungeon */
480 msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
481 build_cavern(owner_ptr);
484 /* Hack -- No destroyed "quest" levels */
485 if (quest_number(owner_ptr, floor_ptr->dun_level)) dun->destroyed = FALSE;
490 * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
491 * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
492 * @param player_ptr プレーヤーへの参照ポインタ
493 * @param why エラー原因メッセージを返す
494 * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
496 static bool cave_gen(player_type *player_ptr, concptr *why)
502 floor_type *floor_ptr = player_ptr->current_floor_ptr;
503 dungeon_type* dungeon_ptr = &d_info[floor_ptr->dungeon_idx];
505 floor_ptr->lite_n = 0;
506 floor_ptr->mon_lite_n = 0;
507 floor_ptr->redraw_n = 0;
508 floor_ptr->view_n = 0;
513 dun->destroyed = FALSE;
514 dun->empty_level = FALSE;
518 /* Fill the arrays of floors and walls in the good proportions */
519 set_floor_and_wall(floor_ptr->dungeon_idx);
520 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), NULL);
522 /* Randomize the dungeon creation values */
523 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
524 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
525 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
526 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
527 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
529 /* Actual maximum number of rooms on this level */
530 dun->row_rooms = floor_ptr->height / BLOCK_HGT;
531 dun->col_rooms = floor_ptr->width / BLOCK_WID;
533 /* Initialize the room table */
534 for (y = 0; y < dun->row_rooms; y++)
536 for (x = 0; x < dun->col_rooms; x++)
538 dun->room_map[y][x] = FALSE;
545 /* Empty arena levels */
546 if (ironman_empty_levels || ((dungeon_ptr->flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
548 dun->empty_level = TRUE;
549 msg_print_wizard(CHEAT_DUNGEON, _("アリーナレベルを生成。", "Arena level."));
552 if (dun->empty_level)
554 /* Start with floors */
555 for (y = 0; y < floor_ptr->height; y++)
557 for (x = 0; x < floor_ptr->width; x++)
559 place_bold(player_ptr, y, x, GB_FLOOR);
563 /* Special boundary walls -- Top and bottom */
564 for (x = 0; x < floor_ptr->width; x++)
566 place_bold(player_ptr, 0, x, GB_EXTRA);
567 place_bold(player_ptr, floor_ptr->height - 1, x, GB_EXTRA);
570 /* Special boundary walls -- Left and right */
571 for (y = 1; y < (floor_ptr->height - 1); y++)
573 place_bold(player_ptr, y, 0, GB_EXTRA);
574 place_bold(player_ptr, y, floor_ptr->width - 1, GB_EXTRA);
579 /* Start with walls */
580 for (y = 0; y < floor_ptr->height; y++)
582 for (x = 0; x < floor_ptr->width; x++)
584 place_bold(player_ptr, y, x, GB_EXTRA);
589 /* Generate various caverns and lakes */
590 gen_caverns_and_lakes(dungeon_ptr, player_ptr);
593 if (dungeon_ptr->flags1 & DF1_MAZE)
595 build_maze_vault(player_ptr, floor_ptr->width/2-1, floor_ptr->height/2-1, floor_ptr->width-4, floor_ptr->height-4, FALSE);
597 /* Place 3 or 4 down stairs near some walls */
598 if (!alloc_stairs(player_ptr, feat_down_stair, rand_range(2, 3), 3))
600 *why = _("迷宮ダンジョンの下り階段生成に失敗", "Failed to alloc up stairs in maze dungeon.");
604 /* Place 1 or 2 up stairs near some walls */
605 if (!alloc_stairs(player_ptr, feat_up_stair, 1, 3))
607 *why = _("迷宮ダンジョンの上り階段生成に失敗", "Failed to alloc down stairs in maze dungeon.");
612 /* Build some rooms */
615 int tunnel_fail_count = 0;
618 * Build each type of room in turn until we cannot build any more.
620 if (!generate_rooms(player_ptr))
622 *why = _("部屋群の生成に失敗", "Failed to generate rooms");
627 /* Make a hole in the dungeon roof sometimes at level 1 */
628 if (floor_ptr->dun_level == 1)
630 while (one_in_(DUN_MOS_DEN))
632 place_trees(player_ptr, randint1(floor_ptr->width - 2), randint1(floor_ptr->height - 2));
638 destroy_level(player_ptr);
641 if (HAS_RIVER_FLAG(dungeon_ptr) && one_in_(3) && (randint1(floor_ptr->dun_level) > 5))
643 add_river(floor_ptr);
646 /* Hack -- Scramble the room order */
647 for (i = 0; i < dun->cent_n; i++)
650 int pick = rand_range(0, i);
654 dun->cent[i].y = dun->cent[pick].y;
655 dun->cent[i].x = dun->cent[pick].x;
656 dun->cent[pick].y = ty;
657 dun->cent[pick].x = tx;
660 /* Start with no tunnel doors */
663 /* Hack -- connect the first room to the last room */
664 y = dun->cent[dun->cent_n-1].y;
665 x = dun->cent[dun->cent_n-1].x;
667 /* Connect all the rooms together */
668 for (i = 0; i < dun->cent_n; i++)
672 /* Reset the arrays */
676 /* Connect the room to the previous room */
677 if (randint1(floor_ptr->dun_level) > dungeon_ptr->tunnel_percent)
679 /* make cavelike tunnel */
680 (void)build_tunnel2(player_ptr, dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
684 /* make normal tunnel */
685 if (!build_tunnel(player_ptr, dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
688 if (tunnel_fail_count >= 2)
690 *why = _("トンネル接続に失敗", "Failed to generate tunnels");
694 /* Turn the tunnel into corridor */
695 for (j = 0; j < dun->tunn_n; j++)
701 g_ptr = &floor_ptr->grid_array[y][x];
702 f_ptr = &f_info[g_ptr->feat];
704 /* Clear previous contents (if not a lake), add a floor */
705 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
707 /* Clear mimic type */
710 place_grid(player_ptr, g_ptr, GB_FLOOR);
714 /* Apply the piercings that we found */
715 for (j = 0; j < dun->wall_n; j++)
720 g_ptr = &floor_ptr->grid_array[y][x];
722 /* Clear mimic type */
725 /* Clear previous contents, add up floor */
726 place_grid(player_ptr, g_ptr, GB_FLOOR);
728 /* Occasional doorway */
729 if ((randint0(100) < dun_tun_pen) && !(dungeon_ptr->flags1 & DF1_NO_DOORS))
731 /* Place a random door */
732 place_random_door(player_ptr, y, x, TRUE);
736 /* Remember the "previous" room */
741 /* Place intersection doors */
742 for (i = 0; i < dun->door_n; i++)
744 /* Extract junction location */
748 /* Try placing doors */
749 try_door(player_ptr, y, x - 1);
750 try_door(player_ptr, y, x + 1);
751 try_door(player_ptr, y - 1, x);
752 try_door(player_ptr, y + 1, x);
755 /* Place 3 or 4 down stairs near some walls */
756 if (!alloc_stairs(player_ptr, feat_down_stair, rand_range(3, 4), 3))
758 *why = _("下り階段生成に失敗", "Failed to generate down stairs.");
762 /* Place 1 or 2 up stairs near some walls */
763 if (!alloc_stairs(player_ptr, feat_up_stair, rand_range(1, 2), 3))
765 *why = _("上り階段生成に失敗", "Failed to generate up stairs.");
772 if (dungeon_ptr->stream2)
774 /* Hack -- Add some quartz streamers */
775 for (i = 0; i < DUN_STR_QUA; i++)
777 build_streamer(player_ptr, dungeon_ptr->stream2, DUN_STR_QC);
781 if (dungeon_ptr->stream1)
783 /* Hack -- Add some magma streamers */
784 for (i = 0; i < DUN_STR_MAG; i++)
786 build_streamer(player_ptr, dungeon_ptr->stream1, DUN_STR_MC);
791 /* Special boundary walls -- Top and bottom */
792 for (x = 0; x < floor_ptr->width; x++)
794 place_bound_perm_wall(player_ptr, &floor_ptr->grid_array[0][x]);
795 place_bound_perm_wall(player_ptr, &floor_ptr->grid_array[floor_ptr->height - 1][x]);
798 /* Special boundary walls -- Left and right */
799 for (y = 1; y < (floor_ptr->height - 1); y++)
801 place_bound_perm_wall(player_ptr, &floor_ptr->grid_array[y][0]);
802 place_bound_perm_wall(player_ptr, &floor_ptr->grid_array[y][floor_ptr->width - 1]);
805 /* Determine the character location */
806 if (!new_player_spot(player_ptr))
808 *why = _("プレイヤー配置に失敗", "Failed to place a player");
812 if (!place_quest_monsters(player_ptr))
814 *why = _("クエストモンスター配置に失敗", "Failed to place a quest monster");
819 k = (floor_ptr->dun_level / 3);
823 /* Pick a base number of monsters */
824 i = dungeon_ptr->min_m_alloc_level;
826 /* To make small levels a bit more playable */
827 if (floor_ptr->height < MAX_HGT || floor_ptr->width < MAX_WID)
829 int small_tester = i;
831 i = (i * floor_ptr->height) / MAX_HGT;
832 i = (i * floor_ptr->width) / MAX_WID;
835 if (i > small_tester) i = small_tester;
836 else msg_format_wizard(CHEAT_DUNGEON,
837 _("モンスター数基本値を %d から %d に減らします", "Reduced monsters base from %d to %d"), small_tester, i);
843 /* Put some monsters in the dungeon */
844 for (i = i + k; i > 0; i--)
846 (void)alloc_monster(player_ptr, 0, PM_ALLOW_SLEEP);
849 /* Place some traps in the dungeon */
850 alloc_object(player_ptr, ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
852 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
853 if (!(dungeon_ptr->flags1 & DF1_NO_CAVE)) alloc_object(player_ptr, ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
855 /* Mega Hack -- No object at first level of deeper dungeon */
856 if (player_ptr->enter_dungeon && floor_ptr->dun_level > 1)
859 floor_ptr->object_level = 1;
862 /* Put some objects in rooms */
863 alloc_object(player_ptr, ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
865 /* Put some objects/gold in the dungeon */
866 alloc_object(player_ptr, ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
867 alloc_object(player_ptr, ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
869 /* Set back to default */
870 floor_ptr->object_level = floor_ptr->base_level;
872 /* Put the Guardian */
873 if (!alloc_guardian(player_ptr, TRUE))
875 *why = _("ダンジョンの主配置に失敗", "Failed to place a dungeon guardian");
879 bool is_empty_or_dark = dun->empty_level;
880 is_empty_or_dark &= !one_in_(DARK_EMPTY) || (randint1(100) > floor_ptr->dun_level);
881 is_empty_or_dark &= (dungeon_ptr->flags1 & DF1_DARKNESS) == 0;
882 if (!is_empty_or_dark) return TRUE;
884 /* Lite the floor_ptr->grid_array */
885 for (y = 0; y < floor_ptr->height; y++)
887 for (x = 0; x < floor_ptr->width; x++)
889 floor_ptr->grid_array[y][x].info |= (CAVE_GLOW);
897 * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
898 * @param player_ptr プレーヤーへの参照ポインタ
901 static void build_arena(player_type *player_ptr, POSITION *start_y, POSITION *start_x)
903 POSITION yval, y_height, y_depth, xval, x_left, x_right;
906 yval = SCREEN_HGT / 2;
907 xval = SCREEN_WID / 2;
908 y_height = yval - 10;
913 floor_type *floor_ptr = player_ptr->current_floor_ptr;
914 for (i = y_height; i <= y_height + 5; i++)
915 for (j = x_left; j <= x_right; j++)
917 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
918 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
920 for (i = y_depth; i >= y_depth - 5; i--)
921 for (j = x_left; j <= x_right; j++)
923 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
924 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
926 for (j = x_left; j <= x_left + 17; j++)
927 for (i = y_height; i <= y_depth; i++)
929 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
930 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
932 for (j = x_right; j >= x_right - 17; j--)
933 for (i = y_height; i <= y_depth; i++)
935 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
936 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
939 place_bold(player_ptr, y_height + 6, x_left + 18, GB_EXTRA_PERM);
940 floor_ptr->grid_array[y_height + 6][x_left + 18].info |= (CAVE_GLOW | CAVE_MARK);
941 place_bold(player_ptr, y_depth - 6, x_left + 18, GB_EXTRA_PERM);
942 floor_ptr->grid_array[y_depth - 6][x_left + 18].info |= (CAVE_GLOW | CAVE_MARK);
943 place_bold(player_ptr, y_height + 6, x_right - 18, GB_EXTRA_PERM);
944 floor_ptr->grid_array[y_height + 6][x_right - 18].info |= (CAVE_GLOW | CAVE_MARK);
945 place_bold(player_ptr, y_depth - 6, x_right - 18, GB_EXTRA_PERM);
946 floor_ptr->grid_array[y_depth - 6][x_right - 18].info |= (CAVE_GLOW | CAVE_MARK);
948 *start_y = y_height + 5;
950 floor_ptr->grid_array[*start_y][*start_x].feat = f_tag_to_index("ARENA_GATE");
951 floor_ptr->grid_array[*start_y][*start_x].info |= (CAVE_GLOW | CAVE_MARK);
955 * @brief 挑戦時闘技場への入場処理 / Town logic flow for generation of arena -KMW-
958 static void generate_challenge_arena(player_type *challanger_ptr)
965 floor_type *floor_ptr = challanger_ptr->current_floor_ptr;
966 floor_ptr->height = SCREEN_HGT;
967 floor_ptr->width = SCREEN_WID;
969 /* Start with solid walls */
970 for (y = 0; y < MAX_HGT; y++)
972 for (x = 0; x < MAX_WID; x++)
974 /* Create "solid" perma-wall */
975 place_bold(challanger_ptr, y, x, GB_SOLID_PERM);
977 /* Illuminate and memorize the walls */
978 floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
982 /* Then place some floors */
983 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
985 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
987 /* Create empty floor */
988 floor_ptr->grid_array[y][x].feat = feat_floor;
992 build_arena(challanger_ptr, &y, &x);
993 player_place(challanger_ptr, y, x);
995 if(!place_monster_aux(challanger_ptr, 0, challanger_ptr->y + 5, challanger_ptr->x, arena_info[challanger_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET)))
997 challanger_ptr->exit_bldg = TRUE;
998 challanger_ptr->arena_number++;
999 msg_print(_("相手は欠場した。あなたの不戦勝だ。", "The enemy is unable appear. You won by default."));
1005 * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
1006 * @param player_ptr プレーヤーへの参照ポインタ
1009 static void build_battle(player_type *player_ptr, POSITION *y, POSITION *x)
1011 POSITION yval, y_height, y_depth, xval, x_left, x_right;
1014 yval = SCREEN_HGT / 2;
1015 xval = SCREEN_WID / 2;
1016 y_height = yval - 10;
1017 y_depth = yval + 10;
1019 x_right = xval + 32;
1021 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1022 for (i = y_height; i <= y_height + 5; i++)
1023 for (j = x_left; j <= x_right; j++)
1025 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
1026 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1028 for (i = y_depth; i >= y_depth - 3; i--)
1029 for (j = x_left; j <= x_right; j++)
1031 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
1032 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1034 for (j = x_left; j <= x_left + 17; j++)
1035 for (i = y_height; i <= y_depth; i++)
1037 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
1038 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1040 for (j = x_right; j >= x_right - 17; j--)
1041 for (i = y_height; i <= y_depth; i++)
1043 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
1044 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1047 place_bold(player_ptr, y_height+6, x_left+18, GB_EXTRA_PERM);
1048 floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1049 place_bold(player_ptr, y_depth-4, x_left+18, GB_EXTRA_PERM);
1050 floor_ptr->grid_array[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1051 place_bold(player_ptr, y_height+6, x_right-18, GB_EXTRA_PERM);
1052 floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1053 place_bold(player_ptr, y_depth-4, x_right-18, GB_EXTRA_PERM);
1054 floor_ptr->grid_array[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1056 for (i = y_height + 1; i <= y_height + 5; i++)
1057 for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
1059 floor_ptr->grid_array[i][j].feat = feat_permanent_glass_wall;
1064 floor_ptr->grid_array[i][j].feat = f_tag_to_index("BUILDING_3");
1065 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1072 * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
1075 static void generate_gambling_arena(player_type *creature_ptr)
1082 /* Start with solid walls */
1083 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1084 for (y = 0; y < MAX_HGT; y++)
1086 for (x = 0; x < MAX_WID; x++)
1088 /* Create "solid" perma-wall */
1089 place_bold(creature_ptr, y, x, GB_SOLID_PERM);
1091 /* Illuminate and memorize the walls */
1092 floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1096 /* Then place some floors */
1097 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1099 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1101 /* Create empty floor */
1102 floor_ptr->grid_array[y][x].feat = feat_floor;
1106 build_battle(creature_ptr, &y, &x);
1108 player_place(creature_ptr, y, x);
1110 for(i = 0; i < 4; i++)
1112 place_monster_aux(creature_ptr, 0, creature_ptr->y + 8 + (i/2)*4, creature_ptr->x - 2 + (i%2)*4, battle_mon[i], (PM_NO_KAGE | PM_NO_PET));
1113 set_friendly(&floor_ptr->m_list[floor_ptr->grid_array[creature_ptr->y+8+(i/2)*4][creature_ptr->x-2+(i%2)*4].m_idx]);
1115 for(i = 1; i < floor_ptr->m_max; i++)
1117 monster_type *m_ptr = &floor_ptr->m_list[i];
1119 if (!monster_is_valid(m_ptr)) continue;
1121 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1122 update_monster(creature_ptr, i, FALSE);
1127 * @brief 固定マップクエストのフロア生成 / Generate a quest level
1128 * @param player_ptr プレーヤーへの参照ポインタ
1131 static void generate_fixed_floor(player_type *player_ptr)
1135 /* Start with perm walls */
1136 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1137 for (y = 0; y < floor_ptr->height; y++)
1139 for (x = 0; x < floor_ptr->width; x++)
1141 place_bold(player_ptr, y, x, GB_SOLID_PERM);
1145 /* Set the quest level */
1146 floor_ptr->base_level = quest[floor_ptr->inside_quest].level;
1147 floor_ptr->dun_level = floor_ptr->base_level;
1148 floor_ptr->object_level = floor_ptr->base_level;
1149 floor_ptr->monster_level = floor_ptr->base_level;
1151 if (record_stair) exe_write_diary(player_ptr, DIARY_TO_QUEST, floor_ptr->inside_quest, NULL);
1152 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), NULL);
1154 init_flags = INIT_CREATE_DUNGEON;
1156 process_dungeon_file(player_ptr, "q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1160 * @brief ダンジョン時のランダムフロア生成 / Make a real level
1161 * @param player_ptr プレーヤーへの参照ポインタ
1163 * @return フロアの生成に成功したらTRUE
1165 static bool level_gen(player_type *player_ptr, concptr *why)
1167 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1168 DUNGEON_IDX d_idx = floor_ptr->dungeon_idx;
1170 if ((always_small_levels || ironman_small_levels ||
1171 (one_in_(SMALL_LEVEL) && small_levels) ||
1172 (d_info[d_idx].flags1 & DF1_BEGINNER) ||
1173 (d_info[d_idx].flags1 & DF1_SMALLEST)) &&
1174 !(d_info[d_idx].flags1 & DF1_BIG))
1176 int level_height, level_width;
1177 if (d_info[d_idx].flags1 & DF1_SMALLEST)
1182 else if (d_info[d_idx].flags1 & DF1_BEGINNER)
1189 level_height = randint1(MAX_HGT / SCREEN_HGT);
1190 level_width = randint1(MAX_WID / SCREEN_WID);
1191 bool is_first_level_area = TRUE;
1192 bool is_max_area = (level_height == MAX_HGT / SCREEN_HGT) && (level_width == MAX_WID / SCREEN_WID);
1193 while (is_first_level_area || is_max_area)
1195 level_height = randint1(MAX_HGT / SCREEN_HGT);
1196 level_width = randint1(MAX_WID / SCREEN_WID);
1197 is_first_level_area = FALSE;
1198 is_max_area = (level_height == MAX_HGT / SCREEN_HGT) && (level_width == MAX_WID / SCREEN_WID);
1202 floor_ptr->height = level_height * SCREEN_HGT;
1203 floor_ptr->width = level_width * SCREEN_WID;
1205 /* Assume illegal panel */
1206 panel_row_min = floor_ptr->height;
1207 panel_col_min = floor_ptr->width;
1209 msg_format_wizard(CHEAT_DUNGEON,
1210 _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."),
1211 floor_ptr->width, floor_ptr->height);
1216 floor_ptr->height = MAX_HGT;
1217 floor_ptr->width = MAX_WID;
1219 /* Assume illegal panel */
1220 panel_row_min = floor_ptr->height;
1221 panel_col_min = floor_ptr->width;
1224 if (!cave_gen(player_ptr, why))
1233 * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after grid_array generation
1236 void wipe_generate_random_floor_flags(floor_type *floor_ptr)
1240 for (y = 0; y < floor_ptr->height; y++)
1242 for (x = 0; x < floor_ptr->width; x++)
1244 /* Wipe unused flags */
1245 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
1249 if (floor_ptr->dun_level)
1251 for (y = 1; y < floor_ptr->height - 1; y++)
1253 for (x = 1; x < floor_ptr->width - 1; x++)
1255 /* There might be trap */
1256 floor_ptr->grid_array[y][x].info |= CAVE_UNSAFE;
1263 * @brief フロアの全情報を初期化する / Clear and empty floor.
1264 * @parama player_ptr プレーヤーへの参照ポインタ
1267 void clear_cave(player_type *player_ptr)
1272 /* Very simplified version of wipe_o_list() */
1273 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1274 (void)C_WIPE(floor_ptr->o_list, floor_ptr->o_max, object_type);
1275 floor_ptr->o_max = 1;
1276 floor_ptr->o_cnt = 0;
1278 /* Very simplified version of wipe_m_list() */
1279 for (i = 1; i < max_r_idx; i++)
1280 r_info[i].cur_num = 0;
1281 (void)C_WIPE(floor_ptr->m_list, floor_ptr->m_max, monster_type);
1282 floor_ptr->m_max = 1;
1283 floor_ptr->m_cnt = 0;
1284 for (i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0;
1286 /* Pre-calc cur_num of pets in party_mon[] */
1287 precalc_cur_num_of_pet(player_ptr);
1290 /* Start with a blank floor_ptr->grid_array */
1291 for (y = 0; y < MAX_HGT; y++)
1293 for (x = 0; x < MAX_WID; x++)
1295 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1308 /* Set the base level */
1309 floor_ptr->base_level = floor_ptr->dun_level;
1311 /* Reset the monster generation level */
1312 floor_ptr->monster_level = floor_ptr->base_level;
1314 /* Reset the object generation level */
1315 floor_ptr->object_level = floor_ptr->base_level;
1320 * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
1321 * @parama player_ptr プレーヤーへの参照ポインタ
1323 * @note Hack -- regenerate any "overflow" levels
1325 void generate_floor(player_type *player_ptr)
1328 /* Fill the arrays of floors and walls in the good proportions */
1329 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1330 floor_ptr->dungeon_idx = player_ptr->dungeon_idx;
1331 set_floor_and_wall(floor_ptr->dungeon_idx);
1334 for (num = 0; TRUE; num++)
1339 clear_cave(player_ptr);
1341 /* Mega-Hack -- no player yet */
1342 player_ptr->x = player_ptr->y = 0;
1344 if (floor_ptr->inside_arena)
1346 generate_challenge_arena(player_ptr);
1349 else if (player_ptr->phase_out)
1351 generate_gambling_arena(player_ptr);
1354 else if (floor_ptr->inside_quest)
1356 generate_fixed_floor(player_ptr);
1359 /* Build the town */
1360 else if (!floor_ptr->dun_level)
1362 /* Make the wilderness */
1363 if (player_ptr->wild_mode) wilderness_gen_small(player_ptr);
1364 else wilderness_gen(player_ptr);
1367 /* Build a real level */
1370 okay = level_gen(player_ptr, &why);
1374 /* Prevent object over-flow */
1375 if (floor_ptr->o_max >= current_world_ptr->max_o_idx)
1377 why = _("アイテムが多すぎる", "too many objects");
1380 /* Prevent monster over-flow */
1381 else if (floor_ptr->m_max >= current_world_ptr->max_m_idx)
1383 why = _("モンスターが多すぎる", "too many monsters");
1390 if (why) msg_format(_("生成やり直し(%s)", "Generation restarted (%s)"), why);
1392 wipe_o_list(floor_ptr);
1393 wipe_monsters_list(player_ptr);
1396 /* Glow deep lava and building entrances tempor */
1397 glow_deep_lava_and_bldg(player_ptr);
1400 player_ptr->enter_dungeon = FALSE;
1402 wipe_generate_random_floor_flags(floor_ptr);
1406 * @brief build_tunnel用に通路を掘るための方向をランダムに決める / Pick a random direction
1407 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
1408 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
1411 static void rand_dir(POSITION *rdir, POSITION *cdir)
1413 /* Pick a random direction */
1414 int i = randint0(4);
1416 /* Extract the dy/dx components */
1422 * @brief build_tunnel用に通路を掘るための方向を位置関係通りに決める / Always picks a correct direction
1423 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
1424 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
1431 static void correct_dir(POSITION *rdir, POSITION *cdir, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
1433 /* Extract vertical and horizontal directions */
1434 *rdir = (y1 == y2) ? 0 : (y1 < y2) ? 1 : -1;
1435 *cdir = (x1 == x2) ? 0 : (x1 < x2) ? 1 : -1;
1437 /* Never move diagonally */
1440 if (randint0(100) < 50)
1448 * @brief 部屋間のトンネルを生成する / Constructs a tunnel between two points
1449 * @param player_ptr プレーヤーへの参照ポインタ
1454 * @return 生成に成功したらTRUEを返す
1456 * This function must be called BEFORE any streamers are created,\n
1457 * since we use the special "granite wall" sub-types to keep track\n
1458 * of legal places for corridors to pierce rooms.\n
1460 * We use "door_flag" to prevent excessive construction of doors\n
1461 * along overlapping corridors.\n
1463 * We queue the tunnel grids to prevent door creation along a corridor\n
1464 * which intersects itself.\n
1466 * We queue the wall piercing grids to prevent a corridor from leaving\n
1467 * a room and then coming back in through the same entrance.\n
1469 * We "pierce" grids which are "outer" walls of rooms, and when we\n
1470 * do so, we change all adjacent "outer" walls of rooms into "solid"\n
1471 * walls so that no two corridors may use adjacent grids for exits.\n
1473 * The "solid" wall check prevents corridors from "chopping" the\n
1474 * corners of rooms off, as well as "silly" door placement, and\n
1475 * "excessively wide" room entrances.\n
1479 * inner -- inner room walls\n
1480 * outer -- outer room walls\n
1481 * solid -- solid room walls\n
1483 bool build_tunnel(player_type *player_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2)
1486 POSITION tmp_row, tmp_col;
1487 POSITION row_dir, col_dir;
1488 POSITION start_row, start_col;
1489 int main_loop_count = 0;
1491 bool door_flag = FALSE;
1495 /* Save the starting location */
1499 /* Start out in the correct direction */
1500 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1502 /* Keep going until done (or bored) */
1503 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1504 while ((row1 != row2) || (col1 != col2))
1506 /* Mega-Hack -- Paranoia -- prevent infinite loops */
1507 if (main_loop_count++ > 2000) return FALSE;
1509 /* Allow bends in the tunnel */
1510 if (randint0(100) < dun_tun_chg)
1512 /* Acquire the correct direction */
1513 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1515 /* Random direction */
1516 if (randint0(100) < dun_tun_rnd)
1518 rand_dir(&row_dir, &col_dir);
1522 /* Get the next location */
1523 tmp_row = row1 + row_dir;
1524 tmp_col = col1 + col_dir;
1527 /* Extremely Important -- do not leave the dungeon */
1528 while (!in_bounds(floor_ptr, tmp_row, tmp_col))
1530 /* Acquire the correct direction */
1531 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1533 /* Random direction */
1534 if (randint0(100) < dun_tun_rnd)
1536 rand_dir(&row_dir, &col_dir);
1539 /* Get the next location */
1540 tmp_row = row1 + row_dir;
1541 tmp_col = col1 + col_dir;
1544 g_ptr = &floor_ptr->grid_array[tmp_row][tmp_col];
1546 /* Avoid "solid" walls */
1547 if (is_solid_grid(g_ptr)) continue;
1549 /* Pierce "outer" walls of rooms */
1550 if (is_outer_grid(g_ptr))
1552 /* Acquire the "next" location */
1553 y = tmp_row + row_dir;
1554 x = tmp_col + col_dir;
1556 /* Hack -- Avoid outer/solid walls */
1557 if (is_outer_bold(floor_ptr, y, x)) continue;
1558 if (is_solid_bold(floor_ptr, y, x)) continue;
1560 /* Accept this location */
1564 /* Save the wall location */
1565 if (dun->wall_n < WALL_MAX)
1567 dun->wall[dun->wall_n].y = row1;
1568 dun->wall[dun->wall_n].x = col1;
1573 /* Forbid re-entry near this piercing */
1574 for (y = row1 - 1; y <= row1 + 1; y++)
1576 for (x = col1 - 1; x <= col1 + 1; x++)
1578 /* Convert adjacent "outer" walls as "solid" walls */
1579 if (is_outer_bold(floor_ptr, y, x))
1581 /* Change the wall to a "solid" wall */
1582 place_bold(player_ptr, y, x, GB_SOLID_NOPERM);
1588 /* Travel quickly through rooms */
1589 else if (g_ptr->info & (CAVE_ROOM))
1591 /* Accept the location */
1596 /* Tunnel through all other walls */
1597 else if (is_extra_grid(g_ptr) || is_inner_grid(g_ptr) || is_solid_grid(g_ptr))
1599 /* Accept this location */
1603 /* Save the tunnel location */
1604 if (dun->tunn_n < TUNN_MAX)
1606 dun->tunn[dun->tunn_n].y = row1;
1607 dun->tunn[dun->tunn_n].x = col1;
1612 /* Allow door in next grid */
1616 /* Handle corridor intersections or overlaps */
1619 /* Accept the location */
1623 /* Collect legal door locations */
1626 /* Save the door location */
1627 if (dun->door_n < DOOR_MAX)
1629 dun->door[dun->door_n].y = row1;
1630 dun->door[dun->door_n].x = col1;
1635 /* No door in next grid */
1639 /* Hack -- allow pre-emptive tunnel termination */
1640 if (randint0(100) >= dun_tun_con)
1642 /* Distance between row1 and start_row */
1643 tmp_row = row1 - start_row;
1644 if (tmp_row < 0) tmp_row = (-tmp_row);
1646 /* Distance between col1 and start_col */
1647 tmp_col = col1 - start_col;
1648 if (tmp_col < 0) tmp_col = (-tmp_col);
1650 /* Terminate the tunnel */
1651 if ((tmp_row > 10) || (tmp_col > 10)) break;
1661 * @brief トンネル生成のための基準点を指定する。
1662 * @param player_ptr プレーヤーへの参照ポインタ
1663 * @param x 基準点を指定するX座標の参照ポインタ、適時値が修正される。
1664 * @param y 基準点を指定するY座標の参照ポインタ、適時値が修正される。
1665 * @param affectwall (調査中)
1668 * This routine adds the square to the tunnel\n
1669 * It also checks for SOLID walls - and returns a nearby\n
1670 * non-SOLID square in (x,y) so that a simple avoiding\n
1671 * routine can be used. The returned boolean value reflects\n
1672 * whether or not this routine hit a SOLID wall.\n
1674 * "affectwall" toggles whether or not this new square affects\n
1675 * the boundaries of rooms. - This is used by the catacomb\n
1677 * @todo 特に詳細な処理の意味を調査すべし
1679 static bool set_tunnel(player_type *player_ptr, POSITION *x, POSITION *y, bool affectwall)
1683 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1684 grid_type *g_ptr = &floor_ptr->grid_array[*y][*x];
1686 if (!in_bounds(floor_ptr, *y, *x)) return TRUE;
1688 if (is_inner_grid(g_ptr))
1693 if (is_extra_bold(floor_ptr, *y, *x))
1695 /* Save the tunnel location */
1696 if (dun->tunn_n < TUNN_MAX)
1698 dun->tunn[dun->tunn_n].y = *y;
1699 dun->tunn[dun->tunn_n].x = *x;
1707 if (is_floor_bold(floor_ptr, *y, *x))
1709 /* Don't do anything */
1713 if (is_outer_grid(g_ptr) && affectwall)
1715 /* Save the wall location */
1716 if (dun->wall_n < WALL_MAX)
1718 dun->wall[dun->wall_n].y = *y;
1719 dun->wall[dun->wall_n].x = *x;
1724 /* Forbid re-entry near this piercing */
1725 for (j = *y - 1; j <= *y + 1; j++)
1727 for (i = *x - 1; i <= *x + 1; i++)
1729 /* Convert adjacent "outer" walls as "solid" walls */
1730 if (is_outer_bold(floor_ptr, j, i))
1732 /* Change the wall to a "solid" wall */
1733 place_bold(player_ptr, j, i, GB_SOLID_NOPERM);
1738 /* Clear mimic type */
1739 floor_ptr->grid_array[*y][*x].mimic = 0;
1741 place_bold(player_ptr, *y, *x, GB_FLOOR);
1746 if (is_solid_grid(g_ptr) && affectwall)
1748 /* cannot place tunnel here - use a square to the side */
1750 /* find usable square and return value in (x,y) */
1756 while ((i > 0) && is_solid_bold(floor_ptr, *y + dy, *x + dx))
1758 dy = randint0(3) - 1;
1759 dx = randint0(3) - 1;
1761 if (!in_bounds(floor_ptr, *y + dy, *x + dx))
1772 /* Failed for some reason: hack - ignore the solidness */
1773 place_grid(player_ptr, g_ptr, GB_OUTER);
1778 /* Give new, acceptable coordinate. */
1790 * @brief 外壁を削って「カタコンベ状」の通路を作成する / This routine creates the catacomb-like tunnels by removing extra rock.
1791 * @param player_ptr プレーヤーへの参照ポインタ
1796 * Note that this routine is only called on "even" squares - so it gives
1797 * a natural checkerboard pattern.
1799 static void create_cata_tunnel(player_type *player_ptr, POSITION x, POSITION y)
1806 set_tunnel(player_ptr, &x1, &y1, FALSE);
1810 set_tunnel(player_ptr, &x1, &y1, FALSE);
1814 set_tunnel(player_ptr, &x1, &y1, FALSE);
1818 set_tunnel(player_ptr, &x1, &y1, FALSE);
1823 * @brief トンネル生成処理(詳細調査中)/ This routine does the bulk of the work in creating the new types of tunnels.
1824 * @param player_ptr プレーヤーへの参照ポインタ
1828 * It is designed to use very simple algorithms to go from (x1,y1) to (x2,y2)\n
1829 * It doesn't need to add any complexity - straight lines are fine.\n
1830 * The SOLID walls are avoided by a recursive algorithm which tries random ways\n
1831 * around the obstical until it works. The number of itterations is counted, and it\n
1832 * this gets too large the routine exits. This should stop any crashes - but may leave\n
1833 * small gaps in the tunnel where there are too many SOLID walls.\n
1835 * Type 1 tunnels are extremely simple - straight line from A to B. This is only used\n
1836 * as a part of the dodge SOLID walls algorithm.\n
1838 * Type 2 tunnels are made of two straight lines at right angles. When this is used with\n
1839 * short line segments it gives the "cavelike" tunnels seen deeper in the dungeon.\n
1841 * Type 3 tunnels are made of two straight lines like type 2, but with extra rock removed.\n
1842 * This, when used with longer line segments gives the "catacomb-like" tunnels seen near\n
1845 static void short_seg_hack(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
1851 /* Check for early exit */
1852 if (!(*fail)) return;
1854 length = distance(x1, y1, x2, y2);
1858 if ((type == 1) && (length != 0))
1861 for (i = 0; i <= length; i++)
1863 x = x1 + i * (x2 - x1) / length;
1864 y = y1 + i * (y2 - y1) / length;
1865 if (!set_tunnel(player_ptr, &x, &y, TRUE))
1869 /* This isn't working - probably have an infinite loop */
1874 /* solid wall - so try to go around */
1875 short_seg_hack(player_ptr, x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
1876 short_seg_hack(player_ptr, x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
1880 else if ((type == 2) || (type == 3))
1884 for (i = x1; i <= x2; i++)
1888 if (!set_tunnel(player_ptr, &x, &y, TRUE))
1890 /* solid wall - so try to go around */
1891 short_seg_hack(player_ptr, x, y, i - 1, y1, 1, count, fail);
1892 short_seg_hack(player_ptr, x, y, i + 1, y1, 1, count, fail);
1894 if ((type == 3) && ((x + y) % 2))
1896 create_cata_tunnel(player_ptr, i, y1);
1902 for (i = x2; i <= x1; i++)
1906 if (!set_tunnel(player_ptr, &x, &y, TRUE))
1908 /* solid wall - so try to go around */
1909 short_seg_hack(player_ptr, x, y, i - 1, y1, 1, count, fail);
1910 short_seg_hack(player_ptr, x, y, i + 1, y1, 1, count, fail);
1912 if ((type == 3) && ((x + y) % 2))
1914 create_cata_tunnel(player_ptr, i, y1);
1921 for (i = y1; i <= y2; i++)
1925 if (!set_tunnel(player_ptr, &x, &y, TRUE))
1927 /* solid wall - so try to go around */
1928 short_seg_hack(player_ptr, x, y, x2, i - 1, 1, count, fail);
1929 short_seg_hack(player_ptr, x, y, x2, i + 1, 1, count, fail);
1931 if ((type == 3) && ((x + y) % 2))
1933 create_cata_tunnel(player_ptr, x2, i);
1939 for (i = y2; i <= y1; i++)
1943 if (!set_tunnel(player_ptr, &x, &y, TRUE))
1945 /* solid wall - so try to go around */
1946 short_seg_hack(player_ptr, x, y, x2, i - 1, 1, count, fail);
1947 short_seg_hack(player_ptr, x, y, x2, i + 1, 1, count, fail);
1949 if ((type == 3) && ((x + y) % 2))
1951 create_cata_tunnel(player_ptr, x2, i);
1960 * @brief 特定の壁(永久壁など)を避けながら部屋間の通路を作成する / This routine maps a path from (x1, y1) to (x2, y2) avoiding SOLID walls.
1964 * Permanent rock is ignored in this path finding- sometimes there is no\n
1965 * path around anyway -so there will be a crash if we try to find one.\n
1966 * This routine is much like the river creation routine in Zangband.\n
1967 * It works by dividing a line segment into two. The segments are divided\n
1968 * until they are less than "cutoff" - when the corresponding routine from\n
1969 * "short_seg_hack" is called.\n
1970 * Note it is VERY important that the "stop if hit another passage" logic\n
1971 * stays as is. Without this the dungeon turns into Swiss Cheese...\n
1973 bool build_tunnel2(player_type *player_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
1975 POSITION x3, y3, dx, dy;
1976 POSITION changex, changey;
1979 bool retval, firstsuccede;
1982 length = distance(x1, y1, x2, y2);
1983 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1984 if (length > cutoff)
1987 * Divide path in half and call routine twice.
1992 /* perturbation perpendicular to path */
1993 changex = (randint0(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
1994 changey = (randint0(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
1996 /* Work out "mid" ponit */
1997 x3 = x1 + dx + changex;
1998 y3 = y1 + dy + changey;
2000 /* See if in bounds - if not - do not perturb point */
2001 if (!in_bounds(floor_ptr, y3, x3))
2007 g_ptr = &floor_ptr->grid_array[y3][x3];
2008 if (is_solid_grid(g_ptr))
2010 /* move midpoint a bit to avoid problem. */
2016 while ((i > 0) && is_solid_bold(floor_ptr, y3 + dy, x3 + dx))
2018 dy = randint0(3) - 1;
2019 dx = randint0(3) - 1;
2020 if (!in_bounds(floor_ptr, y3 + dy, x3 + dx))
2030 /* Failed for some reason: hack - ignore the solidness */
2031 place_bold(player_ptr, y3, x3, GB_OUTER);
2037 g_ptr = &floor_ptr->grid_array[y3][x3];
2040 if (is_floor_grid(g_ptr))
2042 if (build_tunnel2(player_ptr, x1, y1, x3, y3, type, cutoff))
2044 if ((floor_ptr->grid_array[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
2046 /* do second half only if works + if have hit a room */
2047 retval = build_tunnel2(player_ptr, x3, y3, x2, y2, type, cutoff);
2051 /* have hit another tunnel - make a set of doors here */
2054 /* Save the door location */
2055 if (dun->door_n < DOOR_MAX)
2057 dun->door[dun->door_n].y = y3;
2058 dun->door[dun->door_n].x = x3;
2063 firstsuccede = TRUE;
2067 /* false- didn't work all the way */
2069 firstsuccede = FALSE;
2074 /* tunnel through walls */
2075 if (build_tunnel2(player_ptr, x1, y1, x3, y3, type, cutoff))
2077 retval = build_tunnel2(player_ptr, x3, y3, x2, y2, type, cutoff);
2078 firstsuccede = TRUE;
2082 /* false- didn't work all the way */
2084 firstsuccede = FALSE;
2089 /* only do this if the first half has worked */
2090 set_tunnel(player_ptr, &x3, &y3, TRUE);
2092 /* return value calculated above */
2097 /* Do a short segment */
2099 short_seg_hack(player_ptr, x1, y1, x2, y2, type, 0, &retval);
2101 /* Hack - ignore return value so avoid infinite loops */