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
12 * Note that Level generation is *not* an important bottleneck,\n
13 * though it can be annoyingly slow on older machines... Thus\n
14 * we emphasize "simplicity" and "correctness" over "speed".\n
16 * This entire file is only needed for generating levels.\n
17 * This may allow smart compilers to only load it when needed.\n
19 * Consider the "v_info.txt" file for vault generation.\n
21 * In this file, we use the "special" granite and perma-wall sub-types,\n
22 * where "basic" is normal, "inner" is inside a room, "outer" is the\n
23 * outer wall of a room, and "solid" is the outer wall of the dungeon\n
24 * or any walls that may not be pierced by corridors. Thus the only\n
25 * wall type that may be pierced by a corridor is the "outer granite"\n
26 * type. The "basic granite" type yields the "actual" corridors.\n
28 * Note that we use the special "solid" granite wall type to prevent\n
29 * multiple corridors from piercing a wall in two adjacent locations,\n
30 * which would be messy, and we use the special "outer" granite wall\n
31 * to indicate which walls "surround" rooms, and may thus be "pierced"\n
32 * by corridors entering or leaving the room.\n
34 * Note that a tunnel which attempts to leave a room near the "edge"\n
35 * of the dungeon in a direction toward that edge will cause "silly"\n
36 * wall piercings, but will have no permanently incorrect effects,\n
37 * as long as the tunnel can *eventually* exit from another side.\n
38 * And note that the wall may not come back into the room by the\n
39 * hole it left through, so it must bend to the left or right and\n
40 * then optionally re-enter the room (at least 2 grids away). This\n
41 * is not a problem since every room that is large enough to block\n
42 * the passage of tunnels is also large enough to allow the tunnel\n
43 * to pierce the room itself several times.\n
45 * Note that no two corridors may enter a room through adjacent grids,\n
46 * they must either share an entryway or else use entryways at least\n
47 * two grids apart. This prevents "large" (or "silly") doorways.\n
49 * To create rooms in the dungeon, we first divide the dungeon up\n
50 * into "blocks" of 11x11 grids each, and require that all rooms\n
51 * occupy a rectangular group of blocks. As long as each room type\n
52 * reserves a sufficient number of blocks, the room building routines\n
53 * will not need to check bounds. Note that most of the normal rooms\n
54 * actually only use 23x11 grids, and so reserve 33x11 grids.\n
56 * Note that the use of 11x11 blocks (instead of the old 33x11 blocks)\n
57 * allows more variability in the horizontal placement of rooms, and\n
58 * at the same time has the disadvantage that some rooms (two thirds\n
59 * of the normal rooms) may be "split" by panel boundaries. This can\n
60 * induce a situation where a player is in a room and part of the room\n
61 * is off the screen. It may be annoying enough to go back to 33x11\n
62 * blocks to prevent this visual situation.\n
64 * Note that the dungeon generation routines are much different (2.7.5)\n
65 * and perhaps "DUN_ROOMS" should be less than 50.\n
67 * Note that it is possible to create a room which is only\n
68 * connected to itself, because the "tunnel generation" code allows a\n
69 * tunnel to leave a room, wander around, and then re-enter the room.\n
71 * Note that it is possible to create a set of rooms which\n
72 * are only connected to other rooms in that set, since there is nothing\n
73 * explicit in the code to prevent this from happening. But this is less\n
74 * likely than the "isolated room" problem, because each room attempts to\n
75 * connect to another room, in a giant cycle, thus requiring at least two\n
76 * bizarre occurances to create an isolated section of the dungeon.\n
78 * Note that (2.7.9) monster pits have been split into monster "nests"\n
79 * and monster "pits". The "nests" have a collection of monsters of a\n
80 * given type strewn randomly around the room (jelly, animal, or undead),\n
81 * while the "pits" have a collection of monsters of a given type placed\n
82 * around the room in an organized manner (orc, troll, giant, dragon, or\n
83 * demon). Note that both "nests" and "pits" are now "level dependant",\n
84 * and both make 16 "expensive" calls to the "get_mon_num()" function.\n
86 * Note that the cave grid flags changed in a rather drastic manner\n
87 * for Angband 2.8.0 (and 2.7.9+), in particular, dungeon terrain\n
88 * features, such as doors and stairs and traps and rubble and walls,\n
89 * are all handled as a set of 64 possible "terrain features", and\n
90 * not as "fake" objects (440-479) as in pre-2.8.0 versions.\n
92 * The 64 new "dungeon features" will also be used for "visual display"\n
93 * but we must be careful not to allow, for example, the user to display\n
94 * hidden traps in a different way from floors, or secret doors in a way\n
95 * different from granite walls, or even permanent granite in a different\n
96 * way from granite. \n
100 #include "generate.h"
103 #include "floor-streams.h"
114 * Dungeon generation data -- see "cave_gen()"
120 * @brief 上下左右の外壁数をカウントする / Count the number of walls adjacent to the given grid.
124 * @note Assumes "in_bounds(y, x)"
125 * @details We count only granite walls and permanent walls.
127 static int next_to_walls(POSITION y, POSITION x)
131 if (in_bounds(y + 1, x) && is_extra_bold(y + 1, x)) k++;
132 if (in_bounds(y - 1, x) && is_extra_bold(y - 1, x)) k++;
133 if (in_bounds(y, x + 1) && is_extra_bold(y, x + 1)) k++;
134 if (in_bounds(y, x - 1) && is_extra_bold(y, x - 1)) k++;
140 * @brief alloc_stairs()の補助として指定の位置に階段を生成できるかの判定を行う / Helper function for alloc_stairs(). Is this a good location for stairs?
143 * @param walls 最低減隣接させたい外壁の数
144 * @return 階段を生成して問題がないならばTRUEを返す。
146 static bool alloc_stairs_aux(POSITION y, POSITION x, int walls)
148 /* Access the grid */
149 cave_type *c_ptr = &cave[y][x];
151 /* Require "naked" floor grid */
152 if (!is_floor_grid(c_ptr)) return FALSE;
153 if (pattern_tile(y, x)) return FALSE;
154 if (c_ptr->o_idx || c_ptr->m_idx) return FALSE;
156 /* Require a certain number of adjacent walls */
157 if (next_to_walls(y, x) < walls) return FALSE;
164 * @brief 外壁に隣接させて階段を生成する / Places some staircases near walls
165 * @param feat 配置したい地形ID
166 * @param num 配置したい階段の数
167 * @param walls 最低減隣接させたい外壁の数
168 * @return 規定数通りに生成に成功したらTRUEを返す。
170 static bool alloc_stairs(IDX feat, int num, int walls)
175 feature_type *f_ptr = &f_info[feat];
177 if (have_flag(f_ptr->flags, FF_LESS))
179 /* No up stairs in town or in ironman mode */
180 if (ironman_downward || !dun_level) return TRUE;
182 if (dun_level > d_info[dungeon_type].mindepth)
183 shaft_num = (randint1(num+1))/2;
185 else if (have_flag(f_ptr->flags, FF_MORE))
187 QUEST_IDX q_idx = quest_number(dun_level);
189 /* No downstairs on quest levels */
190 if (dun_level > 1 && q_idx)
192 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
194 /* The quest monster(s) is still alive? */
195 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
199 /* No downstairs at the bottom */
200 if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
202 if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
203 shaft_num = (randint1(num)+1)/2;
210 /* Place "num" stairs */
211 for (i = 0; i < num; i++)
221 for (y = 1; y < cur_hgt - 1; y++)
223 for (x = 1; x < cur_wid - 1; x++)
225 if (alloc_stairs_aux(y, x, walls))
227 /* A valid space found */
233 /* No valid place! */
236 /* There are exactly no place! */
237 if (walls <= 0) return FALSE;
239 /* Decrease walls limit, and try again */
244 /* Choose a random one */
245 pick = randint1(candidates);
247 for (y = 1; y < cur_hgt - 1; y++)
249 for (x = 1; x < cur_wid - 1; x++)
251 if (alloc_stairs_aux(y, x, walls))
255 /* Is this a picked one? */
263 /* Access the grid */
266 /* Clear possible garbage of hidden trap */
269 /* Clear previous contents, add stairs */
270 c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
272 /* No longer "FLOOR" */
273 c_ptr->info &= ~(CAVE_FLOOR);
283 * @brief フロア上のランダム位置に各種オブジェクトを配置する / Allocates some objects (using "place" and "type")
284 * @param set 配置したい地形の種類
285 * @param typ 配置したいオブジェクトの種類
287 * @return 規定数通りに生成に成功したらTRUEを返す。
289 static void alloc_object(int set, EFFECT_ID typ, int num)
291 POSITION y = 0, x = 0;
296 /* A small level has few objects. */
297 num = num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID) +1;
299 /* Place some objects */
300 for (k = 0; k < num; k++)
302 /* Pick a "legal" spot */
303 while (dummy < SAFE_MAX_ATTEMPTS)
309 y = randint0(cur_hgt);
310 x = randint0(cur_wid);
314 /* Require "naked" floor grid */
315 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
317 /* Avoid player location */
318 if (player_bold(y, x)) continue;
320 /* Check for "room" */
321 room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
323 /* Require corridor? */
324 if ((set == ALLOC_SET_CORR) && room) continue;
327 if ((set == ALLOC_SET_ROOM) && !room) continue;
333 if (dummy >= SAFE_MAX_ATTEMPTS)
335 msg_print_wizard(CHEAT_DUNGEON, _("アイテムの配置に失敗しました。", "Failed to place object."));
340 /* Place something */
343 case ALLOC_TYP_RUBBLE:
346 cave[y][x].info &= ~(CAVE_FLOOR);
353 cave[y][x].info &= ~(CAVE_FLOOR);
363 case ALLOC_TYP_OBJECT:
365 place_object(y, x, 0L);
376 * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
377 * @return 成功したならばTRUEを返す
379 bool place_quest_monsters(void)
383 /* Handle the quest monster placements */
384 for (i = 0; i < max_q_idx; i++)
390 if (quest[i].status != QUEST_STATUS_TAKEN ||
391 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
392 quest[i].type != QUEST_TYPE_RANDOM) ||
393 quest[i].level != dun_level ||
394 dungeon_type != quest[i].dungeon ||
395 (quest[i].flags & QUEST_FLAG_PRESET))
401 r_ptr = &r_info[quest[i].r_idx];
403 /* Hack -- "unique" monsters must be "unique" */
404 if ((r_ptr->flags1 & RF1_UNIQUE) &&
405 (r_ptr->cur_num >= r_ptr->max_num)) continue;
407 mode = (PM_NO_KAGE | PM_NO_PET);
409 if (!(r_ptr->flags1 & RF1_FRIENDS))
410 mode |= PM_ALLOW_GROUP;
412 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
416 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
418 POSITION x = 0, y = 0;
421 /* Find an empty grid */
422 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
427 y = randint0(cur_hgt);
428 x = randint0(cur_wid);
431 f_ptr = &f_info[c_ptr->feat];
433 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
434 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
435 if (distance(y, x, p_ptr->y, p_ptr->x) < 10) continue;
436 if (c_ptr->info & CAVE_ICKY) continue;
440 /* Failed to place */
441 if (!l) return FALSE;
443 /* Try to place the monster */
444 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
451 /* Failure - Try again */
456 /* Failed to place */
457 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
466 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
467 * @param c_ptr 永久壁を廃止したいマス構造体の参照ポインタ
470 static void set_bound_perm_wall(cave_type *c_ptr)
472 if (bound_walls_perm)
474 /* Clear boundary mimic */
479 feature_type *f_ptr = &f_info[c_ptr->feat];
481 /* Hack -- Decline boundary walls with known treasure */
482 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
483 !have_flag(f_ptr->flags, FF_SECRET))
484 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
486 /* Set boundary mimic */
487 c_ptr->mimic = c_ptr->feat;
490 /* Add "solid" perma-wall */
491 place_solid_perm_grid(c_ptr);
495 * @brief フロアに洞窟や湖を配置する / Generate various caverns and lakes
496 * @details There were moved from cave_gen().
499 static void gen_caverns_and_lakes(void)
501 #ifdef ALLOW_CAVERNS_AND_LAKES
502 /* Possible "destroyed" level */
503 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
505 dun->destroyed = TRUE;
507 /* extra rubble around the place looks cool */
508 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
511 /* Make a lake some of the time */
512 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
513 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
516 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
517 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
518 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
519 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
521 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
524 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
528 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
532 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
535 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
539 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
543 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
546 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
549 /* Lake of rubble2 */
550 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
555 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
559 msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
560 build_lake(dun->laketype);
564 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
565 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
566 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
570 /* make a large fractal cave in the middle of the dungeon */
572 msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
575 #endif /* ALLOW_CAVERNS_AND_LAKES */
577 /* Hack -- No destroyed "quest" levels */
578 if (quest_number(dun_level)) dun->destroyed = FALSE;
583 * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
584 * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
585 * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
587 static bool cave_gen(void)
596 dun->destroyed = FALSE;
597 dun->empty_level = FALSE;
601 /* Fill the arrays of floors and walls in the good proportions */
602 set_floor_and_wall(dungeon_type);
604 /* Prepare allocation table */
605 get_mon_num_prep(get_monster_hook(), NULL);
607 /* Randomize the dungeon creation values */
608 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
609 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
610 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
611 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
612 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
614 /* Actual maximum number of rooms on this level */
615 dun->row_rooms = cur_hgt / BLOCK_HGT;
616 dun->col_rooms = cur_wid / BLOCK_WID;
618 /* Initialize the room table */
619 for (y = 0; y < dun->row_rooms; y++)
621 for (x = 0; x < dun->col_rooms; x++)
623 dun->room_map[y][x] = FALSE;
630 /* Empty arena levels */
631 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
633 dun->empty_level = TRUE;
634 msg_print_wizard(CHEAT_DUNGEON, _("アリーナレベルを生成。", "Arena level."));
637 if (dun->empty_level)
639 /* Start with floors */
640 for (y = 0; y < cur_hgt; y++)
642 for (x = 0; x < cur_wid; x++)
644 place_floor_bold(y, x);
648 /* Special boundary walls -- Top and bottom */
649 for (x = 0; x < cur_wid; x++)
651 place_extra_bold(0, x);
652 place_extra_bold(cur_hgt - 1, x);
655 /* Special boundary walls -- Left and right */
656 for (y = 1; y < (cur_hgt - 1); y++)
658 place_extra_bold(y, 0);
659 place_extra_bold(y, cur_wid - 1);
664 /* Start with walls */
665 for (y = 0; y < cur_hgt; y++)
667 for (x = 0; x < cur_wid; x++)
669 place_extra_bold(y, x);
675 /* Generate various caverns and lakes */
676 gen_caverns_and_lakes();
680 if (d_info[dungeon_type].flags1 & DF1_MAZE)
682 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
684 /* Place 3 or 4 down stairs near some walls */
685 if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
687 /* Place 1 or 2 up stairs near some walls */
688 if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
691 /* Build some rooms */
694 int tunnel_fail_count = 0;
697 * Build each type of room in turn until we cannot build any more.
699 if (!generate_rooms()) return FALSE;
702 /* Make a hole in the dungeon roof sometimes at level 1 */
705 while (one_in_(DUN_MOS_DEN))
707 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
711 /* Destroy the level if necessary */
712 if (dun->destroyed) destroy_level();
714 /* Hack -- Add some rivers */
715 if (one_in_(3) && (randint1(dun_level) > 5))
717 IDX feat1 = 0, feat2 = 0;
719 /* Choose water or lava */
720 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
722 feat1 = feat_deep_water;
723 feat2 = feat_shallow_water;
725 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
727 feat1 = feat_deep_lava;
728 feat2 = feat_shallow_lava;
734 feature_type *f_ptr = &f_info[feat1];
736 /* Only add river if matches lake type or if have no lake at all */
737 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
738 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
741 add_river(feat1, feat2);
746 /* Hack -- Scramble the room order */
747 for (i = 0; i < dun->cent_n; i++)
750 int pick = rand_range(0, i);
754 dun->cent[i].y = dun->cent[pick].y;
755 dun->cent[i].x = dun->cent[pick].x;
756 dun->cent[pick].y = ty;
757 dun->cent[pick].x = tx;
760 /* Start with no tunnel doors */
763 /* Hack -- connect the first room to the last room */
764 y = dun->cent[dun->cent_n-1].y;
765 x = dun->cent[dun->cent_n-1].x;
767 /* Connect all the rooms together */
768 for (i = 0; i < dun->cent_n; i++)
772 /* Reset the arrays */
776 /* Connect the room to the previous room */
777 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
779 /* make cave-like tunnel */
780 (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
784 /* make normal tunnel */
785 if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
788 if (tunnel_fail_count >= 2) return FALSE;
790 /* Turn the tunnel into corridor */
791 for (j = 0; j < dun->tunn_n; j++)
796 /* Access the grid */
800 /* Access the grid */
802 f_ptr = &f_info[c_ptr->feat];
804 /* Clear previous contents (if not a lake), add a floor */
805 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
807 /* Clear mimic type */
810 place_floor_grid(c_ptr);
814 /* Apply the piercings that we found */
815 for (j = 0; j < dun->wall_n; j++)
819 /* Access the grid */
823 /* Access the grid */
826 /* Clear mimic type */
829 /* Clear previous contents, add up floor */
830 place_floor_grid(c_ptr);
832 /* Occasional doorway */
833 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
835 /* Place a random door */
836 place_random_door(y, x, TRUE);
840 /* Remember the "previous" room */
845 /* Place intersection doors */
846 for (i = 0; i < dun->door_n; i++)
848 /* Extract junction location */
852 /* Try placing doors */
859 /* Place 3 or 4 down stairs near some walls */
860 if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
862 /* Place 1 or 2 up stairs near some walls */
863 if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
868 if (d_info[dungeon_type].stream2)
870 /* Hack -- Add some quartz streamers */
871 for (i = 0; i < DUN_STR_QUA; i++)
873 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
877 if (d_info[dungeon_type].stream1)
879 /* Hack -- Add some magma streamers */
880 for (i = 0; i < DUN_STR_MAG; i++)
882 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
887 /* Special boundary walls -- Top and bottom */
888 for (x = 0; x < cur_wid; x++)
890 set_bound_perm_wall(&cave[0][x]);
891 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
894 /* Special boundary walls -- Left and right */
895 for (y = 1; y < (cur_hgt - 1); y++)
897 set_bound_perm_wall(&cave[y][0]);
898 set_bound_perm_wall(&cave[y][cur_wid - 1]);
901 /* Determine the character location */
902 if (!new_player_spot()) return FALSE;
904 if (!place_quest_monsters()) return FALSE;
911 /* Pick a base number of monsters */
912 i = d_info[dungeon_type].min_m_alloc_level;
914 /* To make small levels a bit more playable */
915 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
917 int small_tester = i;
919 i = (i * cur_hgt) / MAX_HGT;
920 i = (i * cur_wid) / MAX_WID;
923 if (i > small_tester) i = small_tester;
924 else msg_format_wizard(CHEAT_DUNGEON,
925 _("モンスター数基本値を %d から %d に減らします", "Reduced monsters base from %d to %d"), small_tester, i);
931 /* Put some monsters in the dungeon */
932 for (i = i + k; i > 0; i--)
934 (void)alloc_monster(0, PM_ALLOW_SLEEP);
937 /* Place some traps in the dungeon */
938 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
940 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
941 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
943 /* Mega Hack -- No object at first level of deeper dungeon */
944 if (p_ptr->enter_dungeon && dun_level > 1)
950 /* Put some objects in rooms */
951 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
953 /* Put some objects/gold in the dungeon */
954 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
955 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
957 /* Set back to default */
958 object_level = base_level;
960 /* Put the Guardian */
961 if (!alloc_guardian(TRUE)) return FALSE;
963 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
966 for (y = 0; y < cur_hgt; y++)
968 for (x = 0; x < cur_wid; x++)
970 cave[y][x].info |= (CAVE_GLOW);
979 * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
982 static void build_arena(void)
984 POSITION yval, y_height, y_depth, xval, x_left, x_right;
987 yval = SCREEN_HGT / 2;
988 xval = SCREEN_WID / 2;
989 y_height = yval - 10;
994 for (i = y_height; i <= y_height + 5; i++)
995 for (j = x_left; j <= x_right; j++)
997 place_extra_perm_bold(i, j);
998 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1000 for (i = y_depth; i >= y_depth - 5; i--)
1001 for (j = x_left; j <= x_right; j++)
1003 place_extra_perm_bold(i, j);
1004 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1006 for (j = x_left; j <= x_left + 17; j++)
1007 for (i = y_height; i <= y_depth; i++)
1009 place_extra_perm_bold(i, j);
1010 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1012 for (j = x_right; j >= x_right - 17; j--)
1013 for (i = y_height; i <= y_depth; i++)
1015 place_extra_perm_bold(i, j);
1016 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1019 place_extra_perm_bold(y_height+6, x_left+18);
1020 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1021 place_extra_perm_bold(y_depth-6, x_left+18);
1022 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1023 place_extra_perm_bold(y_height+6, x_right-18);
1024 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1025 place_extra_perm_bold(y_depth-6, x_right-18);
1026 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1030 cave[i][j].feat = f_tag_to_index("ARENA_GATE");
1031 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1036 * @brief 闘技場への入場処理 / Town logic flow for generation of arena -KMW-
1039 static void arena_gen(void)
1046 cur_hgt = SCREEN_HGT;
1047 cur_wid = SCREEN_WID;
1049 /* Start with solid walls */
1050 for (y = 0; y < MAX_HGT; y++)
1052 for (x = 0; x < MAX_WID; x++)
1054 /* Create "solid" perma-wall */
1055 place_solid_perm_bold(y, x);
1057 /* Illuminate and memorize the walls */
1058 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1062 /* Then place some floors */
1063 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1065 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1067 /* Create empty floor */
1068 cave[y][x].feat = feat_floor;
1074 if(!place_monster_aux(0, p_ptr->y + 5, p_ptr->x, arena_info[p_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET)))
1076 p_ptr->exit_bldg = TRUE;
1077 p_ptr->arena_number++;
1078 msg_print(_("相手は欠場した。あなたの不戦勝だ。", "The enemy is unable appear. You won by default."));
1084 * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
1087 static void build_battle(void)
1089 POSITION yval, y_height, y_depth, xval, x_left, x_right;
1092 yval = SCREEN_HGT / 2;
1093 xval = SCREEN_WID / 2;
1094 y_height = yval - 10;
1095 y_depth = yval + 10;
1097 x_right = xval + 32;
1099 for (i = y_height; i <= y_height + 5; i++)
1100 for (j = x_left; j <= x_right; j++)
1102 place_extra_perm_bold(i, j);
1103 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1105 for (i = y_depth; i >= y_depth - 3; i--)
1106 for (j = x_left; j <= x_right; j++)
1108 place_extra_perm_bold(i, j);
1109 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1111 for (j = x_left; j <= x_left + 17; j++)
1112 for (i = y_height; i <= y_depth; i++)
1114 place_extra_perm_bold(i, j);
1115 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1117 for (j = x_right; j >= x_right - 17; j--)
1118 for (i = y_height; i <= y_depth; i++)
1120 place_extra_perm_bold(i, j);
1121 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1124 place_extra_perm_bold(y_height+6, x_left+18);
1125 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1126 place_extra_perm_bold(y_depth-4, x_left+18);
1127 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1128 place_extra_perm_bold(y_height+6, x_right-18);
1129 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1130 place_extra_perm_bold(y_depth-4, x_right-18);
1131 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1133 for (i = y_height + 1; i <= y_height + 5; i++)
1134 for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
1136 cave[i][j].feat = feat_permanent_glass_wall;
1141 cave[i][j].feat = f_tag_to_index("BUILDING_3");
1142 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1147 * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
1150 static void battle_gen(void)
1157 /* Start with solid walls */
1158 for (y = 0; y < MAX_HGT; y++)
1160 for (x = 0; x < MAX_WID; x++)
1162 /* Create "solid" perma-wall */
1163 place_solid_perm_bold(y, x);
1165 /* Illuminate and memorize the walls */
1166 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1170 /* Then place some floors */
1171 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1173 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1175 /* Create empty floor */
1176 cave[y][x].feat = feat_floor;
1182 for(i = 0; i < 4; i++)
1184 place_monster_aux(0, p_ptr->y + 8 + (i/2)*4, p_ptr->x - 2 + (i%2)*4, battle_mon[i],
1185 (PM_NO_KAGE | PM_NO_PET));
1186 set_friendly(&m_list[cave[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
1188 for(i = 1; i < m_max; i++)
1190 monster_type *m_ptr = &m_list[i];
1192 if (!m_ptr->r_idx) continue;
1194 /* Hack -- Detect monster */
1195 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1197 /* Update the monster */
1198 update_mon(i, FALSE);
1203 * @brief 固定マップクエストのフロア生成 / Generate a quest level
1206 static void quest_gen(void)
1211 /* Start with perm walls */
1212 for (y = 0; y < cur_hgt; y++)
1214 for (x = 0; x < cur_wid; x++)
1216 place_solid_perm_bold(y, x);
1220 /* Set the quest level */
1221 base_level = quest[p_ptr->inside_quest].level;
1222 dun_level = base_level;
1223 object_level = base_level;
1224 monster_level = base_level;
1226 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1228 /* Prepare allocation table */
1229 get_mon_num_prep(get_monster_hook(), NULL);
1231 init_flags = INIT_CREATE_DUNGEON;
1233 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1237 * @brief ダンジョン時のランダムフロア生成 / Make a real level
1238 * @return フロアの生成に成功したらTRUE
1240 static bool level_gen(cptr *why)
1242 int level_height, level_width;
1244 if ((always_small_levels || ironman_small_levels ||
1245 (one_in_(SMALL_LEVEL) && small_levels) ||
1246 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1247 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1248 !(d_info[dungeon_type].flags1 & DF1_BIG))
1250 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1255 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1264 level_height = randint1(MAX_HGT/SCREEN_HGT);
1265 level_width = randint1(MAX_WID/SCREEN_WID);
1267 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1268 (level_width == MAX_WID/SCREEN_WID));
1271 cur_hgt = level_height * SCREEN_HGT;
1272 cur_wid = level_width * SCREEN_WID;
1274 /* Assume illegal panel */
1275 panel_row_min = cur_hgt;
1276 panel_col_min = cur_wid;
1278 msg_format_wizard(CHEAT_DUNGEON,
1279 _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."),
1288 /* Assume illegal panel */
1289 panel_row_min = cur_hgt;
1290 panel_col_min = cur_wid;
1293 /* Make a dungeon */
1297 *why = "ダンジョン生成に失敗";
1299 *why = "could not place player";
1308 * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after cave generation
1311 void wipe_generate_cave_flags(void)
1315 for (y = 0; y < cur_hgt; y++)
1317 for (x = 0; x < cur_wid; x++)
1319 /* Wipe unused flags */
1320 cave[y][x].info &= ~(CAVE_MASK);
1326 for (y = 1; y < cur_hgt - 1; y++)
1328 for (x = 1; x < cur_wid - 1; x++)
1330 /* There might be trap */
1331 cave[y][x].info |= CAVE_UNSAFE;
1338 * @brief フロアの全情報を初期化する / Clear and empty the cave
1341 void clear_cave(void)
1346 /* Very simplified version of wipe_o_list() */
1347 (void)C_WIPE(o_list, o_max, object_type);
1351 /* Very simplified version of wipe_m_list() */
1352 for (i = 1; i < max_r_idx; i++)
1353 r_info[i].cur_num = 0;
1354 (void)C_WIPE(m_list, m_max, monster_type);
1357 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
1359 /* Pre-calc cur_num of pets in party_mon[] */
1360 precalc_cur_num_of_pet();
1363 /* Start with a blank cave */
1364 for (y = 0; y < MAX_HGT; y++)
1366 for (x = 0; x < MAX_WID; x++)
1368 cave_type *c_ptr = &cave[y][x];
1395 /* Mega-Hack -- no player yet */
1396 p_ptr->x = p_ptr->y = 0;
1398 /* Set the base level */
1399 base_level = dun_level;
1401 /* Reset the monster generation level */
1402 monster_level = base_level;
1404 /* Reset the object generation level */
1405 object_level = base_level;
1410 * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
1412 * @note Hack -- regenerate any "overflow" levels
1414 void generate_cave(void)
1418 /* Fill the arrays of floors and walls in the good proportions */
1419 set_floor_and_wall(dungeon_type);
1422 for (num = 0; TRUE; num++)
1428 /* Clear and empty the cave */
1431 /* Build the arena -KMW- */
1432 if (p_ptr->inside_arena)
1438 /* Build the battle -KMW- */
1439 else if (p_ptr->inside_battle)
1445 else if (p_ptr->inside_quest)
1450 /* Build the town */
1451 else if (!dun_level)
1453 /* Make the wilderness */
1454 if (p_ptr->wild_mode) wilderness_gen_small();
1455 else wilderness_gen();
1458 /* Build a real level */
1461 okay = level_gen(&why);
1465 /* Prevent object over-flow */
1466 if (o_max >= max_o_idx)
1471 why = "too many objects";
1477 /* Prevent monster over-flow */
1478 else if (m_max >= max_m_idx)
1483 why = "too many monsters";
1494 if (why) msg_format("生成やり直し(%s)", why);
1496 if (why) msg_format("Generation restarted (%s)", why);
1500 /* Wipe the objects */
1503 /* Wipe the monsters */
1507 /* Glow deep lava and building entrances */
1508 glow_deep_lava_and_bldg();
1511 p_ptr->enter_dungeon = FALSE;
1513 wipe_generate_cave_flags();
1517 * @brief 部屋間のトンネルを生成する / Constructs a tunnel between two points
1522 * @return 生成に成功したらTRUEを返す
1524 * This function must be called BEFORE any streamers are created,\n
1525 * since we use the special "granite wall" sub-types to keep track\n
1526 * of legal places for corridors to pierce rooms.\n
1528 * We use "door_flag" to prevent excessive construction of doors\n
1529 * along overlapping corridors.\n
1531 * We queue the tunnel grids to prevent door creation along a corridor\n
1532 * which intersects itself.\n
1534 * We queue the wall piercing grids to prevent a corridor from leaving\n
1535 * a room and then coming back in through the same entrance.\n
1537 * We "pierce" grids which are "outer" walls of rooms, and when we\n
1538 * do so, we change all adjacent "outer" walls of rooms into "solid"\n
1539 * walls so that no two corridors may use adjacent grids for exits.\n
1541 * The "solid" wall check prevents corridors from "chopping" the\n
1542 * corners of rooms off, as well as "silly" door placement, and\n
1543 * "excessively wide" room entrances.\n
1547 * inner -- inner room walls\n
1548 * outer -- outer room walls\n
1549 * solid -- solid room walls\n
1551 bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
1554 POSITION tmp_row, tmp_col;
1555 DIRECTION row_dir, col_dir;
1556 POSITION start_row, start_col;
1557 int main_loop_count = 0;
1559 bool door_flag = FALSE;
1563 /* Save the starting location */
1567 /* Start out in the correct direction */
1568 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1570 /* Keep going until done (or bored) */
1571 while ((row1 != row2) || (col1 != col2))
1573 /* Mega-Hack -- Paranoia -- prevent infinite loops */
1574 if (main_loop_count++ > 2000) return FALSE;
1576 /* Allow bends in the tunnel */
1577 if (randint0(100) < dun_tun_chg)
1579 /* Acquire the correct direction */
1580 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1582 /* Random direction */
1583 if (randint0(100) < dun_tun_rnd)
1585 rand_dir(&row_dir, &col_dir);
1589 /* Get the next location */
1590 tmp_row = row1 + row_dir;
1591 tmp_col = col1 + col_dir;
1594 /* Extremely Important -- do not leave the dungeon */
1595 while (!in_bounds(tmp_row, tmp_col))
1597 /* Acquire the correct direction */
1598 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1600 /* Random direction */
1601 if (randint0(100) < dun_tun_rnd)
1603 rand_dir(&row_dir, &col_dir);
1606 /* Get the next location */
1607 tmp_row = row1 + row_dir;
1608 tmp_col = col1 + col_dir;
1612 /* Access the location */
1613 c_ptr = &cave[tmp_row][tmp_col];
1615 /* Avoid "solid" walls */
1616 if (is_solid_grid(c_ptr)) continue;
1618 /* Pierce "outer" walls of rooms */
1619 if (is_outer_grid(c_ptr))
1621 /* Acquire the "next" location */
1622 y = tmp_row + row_dir;
1623 x = tmp_col + col_dir;
1625 /* Hack -- Avoid outer/solid walls */
1626 if (is_outer_bold(y, x)) continue;
1627 if (is_solid_bold(y, x)) continue;
1629 /* Accept this location */
1630 row1 = (POSITION)tmp_row;
1631 col1 = (POSITION)tmp_col;
1633 /* Save the wall location */
1634 if (dun->wall_n < WALL_MAX)
1636 dun->wall[dun->wall_n].y = row1;
1637 dun->wall[dun->wall_n].x = col1;
1642 /* Forbid re-entry near this piercing */
1643 for (y = row1 - 1; y <= row1 + 1; y++)
1645 for (x = col1 - 1; x <= col1 + 1; x++)
1647 /* Convert adjacent "outer" walls as "solid" walls */
1648 if (is_outer_bold(y, x))
1650 /* Change the wall to a "solid" wall */
1651 place_solid_noperm_bold(y, x);
1657 /* Travel quickly through rooms */
1658 else if (c_ptr->info & (CAVE_ROOM))
1660 /* Accept the location */
1665 /* Tunnel through all other walls */
1666 else if (is_extra_grid(c_ptr) || is_inner_grid(c_ptr) || is_solid_grid(c_ptr))
1668 /* Accept this location */
1672 /* Save the tunnel location */
1673 if (dun->tunn_n < TUNN_MAX)
1675 dun->tunn[dun->tunn_n].y = row1;
1676 dun->tunn[dun->tunn_n].x = col1;
1681 /* Allow door in next grid */
1685 /* Handle corridor intersections or overlaps */
1688 /* Accept the location */
1692 /* Collect legal door locations */
1695 /* Save the door location */
1696 if (dun->door_n < DOOR_MAX)
1698 dun->door[dun->door_n].y = row1;
1699 dun->door[dun->door_n].x = col1;
1704 /* No door in next grid */
1708 /* Hack -- allow pre-emptive tunnel termination */
1709 if (randint0(100) >= dun_tun_con)
1711 /* Distance between row1 and start_row */
1712 tmp_row = row1 - start_row;
1713 if (tmp_row < 0) tmp_row = (-tmp_row);
1715 /* Distance between col1 and start_col */
1716 tmp_col = col1 - start_col;
1717 if (tmp_col < 0) tmp_col = (-tmp_col);
1719 /* Terminate the tunnel */
1720 if ((tmp_row > 10) || (tmp_col > 10)) break;
1730 * @brief トンネル生成のための基準点を指定する。
1731 * @param x 基準点を指定するX座標の参照ポインタ、適時値が修正される。
1732 * @param y 基準点を指定するY座標の参照ポインタ、適時値が修正される。
1733 * @param affectwall (調査中)
1736 * This routine adds the square to the tunnel\n
1737 * It also checks for SOLID walls - and returns a nearby\n
1738 * non-SOLID square in (x,y) so that a simple avoiding\n
1739 * routine can be used. The returned boolean value reflects\n
1740 * whether or not this routine hit a SOLID wall.\n
1742 * "affectwall" toggles whether or not this new square affects\n
1743 * the boundaries of rooms. - This is used by the catacomb\n
1745 * @todo 特に詳細な処理の意味を調査すべし
1747 static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
1751 cave_type *c_ptr = &cave[*y][*x];
1753 if (!in_bounds(*y, *x)) return TRUE;
1755 if (is_inner_grid(c_ptr))
1760 if (is_extra_bold(*y, *x))
1762 /* Save the tunnel location */
1763 if (dun->tunn_n < TUNN_MAX)
1765 dun->tunn[dun->tunn_n].y = *y;
1766 dun->tunn[dun->tunn_n].x = *x;
1774 if (is_floor_bold(*y, *x))
1776 /* Don't do anything */
1780 if (is_outer_grid(c_ptr) && affectwall)
1782 /* Save the wall location */
1783 if (dun->wall_n < WALL_MAX)
1785 dun->wall[dun->wall_n].y = *y;
1786 dun->wall[dun->wall_n].x = *x;
1791 /* Forbid re-entry near this piercing */
1792 for (j = *y - 1; j <= *y + 1; j++)
1794 for (i = *x - 1; i <= *x + 1; i++)
1796 /* Convert adjacent "outer" walls as "solid" walls */
1797 if (is_outer_bold(j, i))
1799 /* Change the wall to a "solid" wall */
1800 place_solid_noperm_bold(j, i);
1805 /* Clear mimic type */
1806 cave[*y][*x].mimic = 0;
1808 place_floor_bold(*y, *x);
1813 if (is_solid_grid(c_ptr) && affectwall)
1815 /* cannot place tunnel here - use a square to the side */
1817 /* find usable square and return value in (x,y) */
1823 while ((i > 0) && is_solid_bold(*y + dy, *x + dx))
1825 dy = randint0(3) - 1;
1826 dx = randint0(3) - 1;
1828 if (!in_bounds(*y + dy, *x + dx))
1839 /* Failed for some reason: hack - ignore the solidness */
1840 place_outer_grid(c_ptr);
1845 /* Give new, acceptable coordinate. */
1857 * @brief 外壁を削って「カタコンベ状」の通路を作成する / This routine creates the catacomb-like tunnels by removing extra rock.
1862 * Note that this routine is only called on "even" squares - so it gives
1863 * a natural checkerboard pattern.
1865 static void create_cata_tunnel(POSITION x, POSITION y)
1872 set_tunnel(&x1, &y1, FALSE);
1876 set_tunnel(&x1, &y1, FALSE);
1880 set_tunnel(&x1, &y1, FALSE);
1884 set_tunnel(&x1, &y1, FALSE);
1889 * @brief トンネル生成処理(詳細調査中)/ This routine does the bulk of the work in creating the new types of tunnels.
1893 * It is designed to use very simple algorithms to go from (x1,y1) to (x2,y2)\n
1894 * It doesn't need to add any complexity - straight lines are fine.\n
1895 * The SOLID walls are avoided by a recursive algorithm which tries random ways\n
1896 * around the obstical until it works. The number of itterations is counted, and it\n
1897 * this gets too large the routine exits. This should stop any crashes - but may leave\n
1898 * small gaps in the tunnel where there are too many SOLID walls.\n
1900 * Type 1 tunnels are extremely simple - straight line from A to B. This is only used\n
1901 * as a part of the dodge SOLID walls algorithm.\n
1903 * Type 2 tunnels are made of two straight lines at right angles. When this is used with\n
1904 * short line segments it gives the "cavelike" tunnels seen deeper in the dungeon.\n
1906 * Type 3 tunnels are made of two straight lines like type 2, but with extra rock removed.\n
1907 * This, when used with longer line segments gives the "catacomb-like" tunnels seen near\n
1910 static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
1916 /* Check for early exit */
1917 if (!(*fail)) return;
1919 length = distance(x1, y1, x2, y2);
1923 if ((type == 1) && (length != 0))
1926 for (i = 0; i <= length; i++)
1928 x = x1 + i * (x2 - x1) / length;
1929 y = y1 + i * (y2 - y1) / length;
1930 if (!set_tunnel(&x, &y, TRUE))
1934 /* This isn't working - probably have an infinite loop */
1939 /* solid wall - so try to go around */
1940 short_seg_hack(x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
1941 short_seg_hack(x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
1945 else if ((type == 2) || (type == 3))
1949 for (i = x1; i <= x2; i++)
1953 if (!set_tunnel(&x, &y, TRUE))
1955 /* solid wall - so try to go around */
1956 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1957 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1959 if ((type == 3) && ((x + y) % 2))
1961 create_cata_tunnel(i, y1);
1967 for (i = x2; i <= x1; i++)
1971 if (!set_tunnel(&x, &y, TRUE))
1973 /* solid wall - so try to go around */
1974 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1975 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1977 if ((type == 3) && ((x + y) % 2))
1979 create_cata_tunnel(i, y1);
1986 for (i = y1; i <= y2; i++)
1990 if (!set_tunnel(&x, &y, TRUE))
1992 /* solid wall - so try to go around */
1993 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1994 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1996 if ((type == 3) && ((x + y) % 2))
1998 create_cata_tunnel(x2, i);
2004 for (i = y2; i <= y1; i++)
2008 if (!set_tunnel(&x, &y, TRUE))
2010 /* solid wall - so try to go around */
2011 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
2012 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
2014 if ((type == 3) && ((x + y) % 2))
2016 create_cata_tunnel(x2, i);
2025 * @brief 特定の壁(永久壁など)を避けながら部屋間の通路を作成する / This routine maps a path from (x1, y1) to (x2, y2) avoiding SOLID walls.
2029 * Permanent rock is ignored in this path finding- sometimes there is no\n
2030 * path around anyway -so there will be a crash if we try to find one.\n
2031 * This routine is much like the river creation routine in Zangband.\n
2032 * It works by dividing a line segment into two. The segments are divided\n
2033 * until they are less than "cutoff" - when the corresponding routine from\n
2034 * "short_seg_hack" is called.\n
2035 * Note it is VERY important that the "stop if hit another passage" logic\n
2036 * stays as is. Without this the dungeon turns into Swiss Cheese...\n
2038 bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
2040 POSITION x3, y3, dx, dy;
2041 POSITION changex, changey;
2044 bool retval, firstsuccede;
2047 length = distance(x1, y1, x2, y2);
2049 if (length > cutoff)
2052 * Divide path in half and call routine twice.
2057 /* perturbation perpendicular to path */
2058 changex = (randint0(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
2059 changey = (randint0(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
2061 /* Work out "mid" ponit */
2062 x3 = x1 + dx + changex;
2063 y3 = y1 + dy + changey;
2065 /* See if in bounds - if not - do not perturb point */
2066 if (!in_bounds(y3, x3))
2072 c_ptr = &cave[y3][x3];
2073 if (is_solid_grid(c_ptr))
2075 /* move midpoint a bit to avoid problem. */
2081 while ((i > 0) && is_solid_bold(y3 + dy, x3 + dx))
2083 dy = randint0(3) - 1;
2084 dx = randint0(3) - 1;
2085 if (!in_bounds(y3 + dy, x3 + dx))
2095 /* Failed for some reason: hack - ignore the solidness */
2096 place_outer_bold(y3, x3);
2102 c_ptr = &cave[y3][x3];
2105 if (is_floor_grid(c_ptr))
2107 if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
2109 if ((cave[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
2111 /* do second half only if works + if have hit a room */
2112 retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
2116 /* have hit another tunnel - make a set of doors here */
2119 /* Save the door location */
2120 if (dun->door_n < DOOR_MAX)
2122 dun->door[dun->door_n].y = (POSITION)y3;
2123 dun->door[dun->door_n].x = (POSITION)x3;
2128 firstsuccede = TRUE;
2132 /* false- didn't work all the way */
2134 firstsuccede = FALSE;
2139 /* tunnel through walls */
2140 if (build_tunnel2(x1, y1, (POSITION)x3, (POSITION)y3, type, cutoff))
2142 retval = build_tunnel2((POSITION)x3, (POSITION)y3, x2, y2, type, cutoff);
2143 firstsuccede = TRUE;
2147 /* false- didn't work all the way */
2149 firstsuccede = FALSE;
2154 /* only do this if the first half has worked */
2155 set_tunnel(&x3, &y3, TRUE);
2157 /* return value calculated above */
2162 /* Do a short segment */
2164 short_seg_hack(x1, y1, x2, y2, type, 0, &retval);
2166 /* Hack - ignore return value so avoid infinite loops */