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 cave_type *c_ptr = &cave[y][x];
150 /* Require "naked" floor grid */
151 if (!is_floor_grid(c_ptr)) return FALSE;
152 if (pattern_tile(y, x)) return FALSE;
153 if (c_ptr->o_idx || c_ptr->m_idx) return FALSE;
155 /* Require a certain number of adjacent walls */
156 if (next_to_walls(y, x) < walls) return FALSE;
163 * @brief 外壁に隣接させて階段を生成する / Places some staircases near walls
164 * @param feat 配置したい地形ID
165 * @param num 配置したい階段の数
166 * @param walls 最低減隣接させたい外壁の数
167 * @return 規定数通りに生成に成功したらTRUEを返す。
169 static bool alloc_stairs(IDX feat, int num, int walls)
174 feature_type *f_ptr = &f_info[feat];
176 if (have_flag(f_ptr->flags, FF_LESS))
178 /* No up stairs in town or in ironman mode */
179 if (ironman_downward || !dun_level) return TRUE;
181 if (dun_level > d_info[dungeon_type].mindepth)
182 shaft_num = (randint1(num+1))/2;
184 else if (have_flag(f_ptr->flags, FF_MORE))
186 QUEST_IDX q_idx = quest_number(dun_level);
188 /* No downstairs on quest levels */
189 if (dun_level > 1 && q_idx)
191 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
193 /* The quest monster(s) is still alive? */
194 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
198 /* No downstairs at the bottom */
199 if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
201 if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
202 shaft_num = (randint1(num)+1)/2;
209 /* Place "num" stairs */
210 for (i = 0; i < num; i++)
220 for (y = 1; y < cur_hgt - 1; y++)
222 for (x = 1; x < cur_wid - 1; x++)
224 if (alloc_stairs_aux(y, x, walls))
226 /* A valid space found */
232 /* No valid place! */
235 /* There are exactly no place! */
236 if (walls <= 0) return FALSE;
238 /* Decrease walls limit, and try again */
243 /* Choose a random one */
244 pick = randint1(candidates);
246 for (y = 1; y < cur_hgt - 1; y++)
248 for (x = 1; x < cur_wid - 1; x++)
250 if (alloc_stairs_aux(y, x, walls))
254 /* Is this a picked one? */
263 /* Clear possible garbage of hidden trap */
266 /* Clear previous contents, add stairs */
267 c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
269 /* No longer "FLOOR" */
270 c_ptr->info &= ~(CAVE_FLOOR);
280 * @brief フロア上のランダム位置に各種オブジェクトを配置する / Allocates some objects (using "place" and "type")
281 * @param set 配置したい地形の種類
282 * @param typ 配置したいオブジェクトの種類
284 * @return 規定数通りに生成に成功したらTRUEを返す。
286 static void alloc_object(int set, EFFECT_ID typ, int num)
288 POSITION y = 0, x = 0;
293 /* A small level has few objects. */
294 num = num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID) +1;
296 /* Place some objects */
297 for (k = 0; k < num; k++)
299 /* Pick a "legal" spot */
300 while (dummy < SAFE_MAX_ATTEMPTS)
306 y = randint0(cur_hgt);
307 x = randint0(cur_wid);
311 /* Require "naked" floor grid */
312 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
314 /* Avoid player location */
315 if (player_bold(y, x)) continue;
317 /* Check for "room" */
318 room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
320 /* Require corridor? */
321 if ((set == ALLOC_SET_CORR) && room) continue;
324 if ((set == ALLOC_SET_ROOM) && !room) continue;
330 if (dummy >= SAFE_MAX_ATTEMPTS)
332 msg_print_wizard(CHEAT_DUNGEON, _("アイテムの配置に失敗しました。", "Failed to place object."));
337 /* Place something */
340 case ALLOC_TYP_RUBBLE:
343 cave[y][x].info &= ~(CAVE_FLOOR);
350 cave[y][x].info &= ~(CAVE_FLOOR);
360 case ALLOC_TYP_OBJECT:
362 place_object(y, x, 0L);
373 * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
374 * @return 成功したならばTRUEを返す
376 bool place_quest_monsters(void)
380 /* Handle the quest monster placements */
381 for (i = 0; i < max_q_idx; i++)
387 if (quest[i].status != QUEST_STATUS_TAKEN ||
388 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
389 quest[i].type != QUEST_TYPE_RANDOM) ||
390 quest[i].level != dun_level ||
391 dungeon_type != quest[i].dungeon ||
392 (quest[i].flags & QUEST_FLAG_PRESET))
398 r_ptr = &r_info[quest[i].r_idx];
400 /* Hack -- "unique" monsters must be "unique" */
401 if ((r_ptr->flags1 & RF1_UNIQUE) &&
402 (r_ptr->cur_num >= r_ptr->max_num)) continue;
404 mode = (PM_NO_KAGE | PM_NO_PET);
406 if (!(r_ptr->flags1 & RF1_FRIENDS))
407 mode |= PM_ALLOW_GROUP;
409 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
413 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
415 POSITION x = 0, y = 0;
418 /* Find an empty grid */
419 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
424 y = randint0(cur_hgt);
425 x = randint0(cur_wid);
428 f_ptr = &f_info[c_ptr->feat];
430 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
431 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
432 if (distance(y, x, p_ptr->y, p_ptr->x) < 10) continue;
433 if (c_ptr->info & CAVE_ICKY) continue;
437 /* Failed to place */
438 if (!l) return FALSE;
440 /* Try to place the monster */
441 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
448 /* Failure - Try again */
453 /* Failed to place */
454 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
463 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
464 * @param c_ptr 永久壁を廃止したいマス構造体の参照ポインタ
467 static void set_bound_perm_wall(cave_type *c_ptr)
469 if (bound_walls_perm)
471 /* Clear boundary mimic */
476 feature_type *f_ptr = &f_info[c_ptr->feat];
478 /* Hack -- Decline boundary walls with known treasure */
479 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
480 !have_flag(f_ptr->flags, FF_SECRET))
481 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
483 /* Set boundary mimic */
484 c_ptr->mimic = c_ptr->feat;
487 /* Add "solid" perma-wall */
488 place_solid_perm_grid(c_ptr);
492 * @brief フロアに洞窟や湖を配置する / Generate various caverns and lakes
493 * @details There were moved from cave_gen().
496 static void gen_caverns_and_lakes(void)
498 #ifdef ALLOW_CAVERNS_AND_LAKES
499 /* Possible "destroyed" level */
500 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
502 dun->destroyed = TRUE;
504 /* extra rubble around the place looks cool */
505 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
508 /* Make a lake some of the time */
509 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
510 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
513 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
514 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
515 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
516 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
518 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
521 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
525 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
529 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
532 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
536 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
540 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
543 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
546 /* Lake of rubble2 */
547 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
552 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
556 msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
557 build_lake(dun->laketype);
561 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
562 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
563 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
567 /* make a large fractal cave in the middle of the dungeon */
569 msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
572 #endif /* ALLOW_CAVERNS_AND_LAKES */
574 /* Hack -- No destroyed "quest" levels */
575 if (quest_number(dun_level)) dun->destroyed = FALSE;
580 * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
581 * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
582 * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
584 static bool cave_gen(void)
593 dun->destroyed = FALSE;
594 dun->empty_level = FALSE;
598 /* Fill the arrays of floors and walls in the good proportions */
599 set_floor_and_wall(dungeon_type);
601 /* Prepare allocation table */
602 get_mon_num_prep(get_monster_hook(), NULL);
604 /* Randomize the dungeon creation values */
605 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
606 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
607 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
608 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
609 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
611 /* Actual maximum number of rooms on this level */
612 dun->row_rooms = cur_hgt / BLOCK_HGT;
613 dun->col_rooms = cur_wid / BLOCK_WID;
615 /* Initialize the room table */
616 for (y = 0; y < dun->row_rooms; y++)
618 for (x = 0; x < dun->col_rooms; x++)
620 dun->room_map[y][x] = FALSE;
627 /* Empty arena levels */
628 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
630 dun->empty_level = TRUE;
631 msg_print_wizard(CHEAT_DUNGEON, _("アリーナレベルを生成。", "Arena level."));
634 if (dun->empty_level)
636 /* Start with floors */
637 for (y = 0; y < cur_hgt; y++)
639 for (x = 0; x < cur_wid; x++)
641 place_floor_bold(y, x);
645 /* Special boundary walls -- Top and bottom */
646 for (x = 0; x < cur_wid; x++)
648 place_extra_bold(0, x);
649 place_extra_bold(cur_hgt - 1, x);
652 /* Special boundary walls -- Left and right */
653 for (y = 1; y < (cur_hgt - 1); y++)
655 place_extra_bold(y, 0);
656 place_extra_bold(y, cur_wid - 1);
661 /* Start with walls */
662 for (y = 0; y < cur_hgt; y++)
664 for (x = 0; x < cur_wid; x++)
666 place_extra_bold(y, x);
672 /* Generate various caverns and lakes */
673 gen_caverns_and_lakes();
677 if (d_info[dungeon_type].flags1 & DF1_MAZE)
679 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
681 /* Place 3 or 4 down stairs near some walls */
682 if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
684 /* Place 1 or 2 up stairs near some walls */
685 if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
688 /* Build some rooms */
691 int tunnel_fail_count = 0;
694 * Build each type of room in turn until we cannot build any more.
696 if (!generate_rooms()) return FALSE;
699 /* Make a hole in the dungeon roof sometimes at level 1 */
702 while (one_in_(DUN_MOS_DEN))
704 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
708 /* Destroy the level if necessary */
709 if (dun->destroyed) destroy_level();
711 /* Hack -- Add some rivers */
712 if (one_in_(3) && (randint1(dun_level) > 5))
714 FEAT_IDX feat1 = 0, feat2 = 0;
716 /* Choose water mainly */
717 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
719 feat1 = feat_deep_water;
720 feat2 = feat_shallow_water;
724 FEAT_IDX select_deep_feat[10];
725 FEAT_IDX select_shallow_feat[10];
726 int select_id_max = 0, selected;
728 if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
730 select_deep_feat[select_id_max] = feat_deep_lava;
731 select_shallow_feat[select_id_max] = feat_shallow_lava;
734 if (d_info[dungeon_type].flags1 & DF1_POISONOUS_RIVER)
736 select_deep_feat[select_id_max] = feat_deep_poisonous_puddle;
737 select_shallow_feat[select_id_max] = feat_shallow_poisonous_puddle;
740 if (d_info[dungeon_type].flags1 & DF1_ACID_RIVER)
742 select_deep_feat[select_id_max] = feat_deep_acid_puddle;
743 select_shallow_feat[select_id_max] = feat_shallow_acid_puddle;
747 selected = randint0(select_id_max);
748 feat1 = select_deep_feat[selected];
749 feat2 = select_shallow_feat[selected];
754 feature_type *f_ptr = &f_info[feat1];
756 /* Only add river if matches lake type or if have no lake at all */
757 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
758 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
761 add_river(feat1, feat2);
766 /* Hack -- Scramble the room order */
767 for (i = 0; i < dun->cent_n; i++)
770 int pick = rand_range(0, i);
774 dun->cent[i].y = dun->cent[pick].y;
775 dun->cent[i].x = dun->cent[pick].x;
776 dun->cent[pick].y = ty;
777 dun->cent[pick].x = tx;
780 /* Start with no tunnel doors */
783 /* Hack -- connect the first room to the last room */
784 y = dun->cent[dun->cent_n-1].y;
785 x = dun->cent[dun->cent_n-1].x;
787 /* Connect all the rooms together */
788 for (i = 0; i < dun->cent_n; i++)
792 /* Reset the arrays */
796 /* Connect the room to the previous room */
797 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
799 /* make cave-like tunnel */
800 (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
804 /* make normal tunnel */
805 if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
808 if (tunnel_fail_count >= 2) return FALSE;
810 /* Turn the tunnel into corridor */
811 for (j = 0; j < dun->tunn_n; j++)
818 f_ptr = &f_info[c_ptr->feat];
820 /* Clear previous contents (if not a lake), add a floor */
821 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
823 /* Clear mimic type */
826 place_floor_grid(c_ptr);
830 /* Apply the piercings that we found */
831 for (j = 0; j < dun->wall_n; j++)
838 /* Clear mimic type */
841 /* Clear previous contents, add up floor */
842 place_floor_grid(c_ptr);
844 /* Occasional doorway */
845 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
847 /* Place a random door */
848 place_random_door(y, x, TRUE);
852 /* Remember the "previous" room */
857 /* Place intersection doors */
858 for (i = 0; i < dun->door_n; i++)
860 /* Extract junction location */
864 /* Try placing doors */
871 /* Place 3 or 4 down stairs near some walls */
872 if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
874 /* Place 1 or 2 up stairs near some walls */
875 if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
880 if (d_info[dungeon_type].stream2)
882 /* Hack -- Add some quartz streamers */
883 for (i = 0; i < DUN_STR_QUA; i++)
885 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
889 if (d_info[dungeon_type].stream1)
891 /* Hack -- Add some magma streamers */
892 for (i = 0; i < DUN_STR_MAG; i++)
894 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
899 /* Special boundary walls -- Top and bottom */
900 for (x = 0; x < cur_wid; x++)
902 set_bound_perm_wall(&cave[0][x]);
903 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
906 /* Special boundary walls -- Left and right */
907 for (y = 1; y < (cur_hgt - 1); y++)
909 set_bound_perm_wall(&cave[y][0]);
910 set_bound_perm_wall(&cave[y][cur_wid - 1]);
913 /* Determine the character location */
914 if (!new_player_spot()) return FALSE;
916 if (!place_quest_monsters()) return FALSE;
923 /* Pick a base number of monsters */
924 i = d_info[dungeon_type].min_m_alloc_level;
926 /* To make small levels a bit more playable */
927 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
929 int small_tester = i;
931 i = (i * cur_hgt) / MAX_HGT;
932 i = (i * cur_wid) / MAX_WID;
935 if (i > small_tester) i = small_tester;
936 else msg_format_wizard(CHEAT_DUNGEON,
937 _("モンスター数基本値を %d から %d に減らします", "Reduced monsters base from %d to %d"), small_tester, i);
943 /* Put some monsters in the dungeon */
944 for (i = i + k; i > 0; i--)
946 (void)alloc_monster(0, PM_ALLOW_SLEEP);
949 /* Place some traps in the dungeon */
950 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
952 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
953 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
955 /* Mega Hack -- No object at first level of deeper dungeon */
956 if (p_ptr->enter_dungeon && dun_level > 1)
962 /* Put some objects in rooms */
963 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
965 /* Put some objects/gold in the dungeon */
966 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
967 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
969 /* Set back to default */
970 object_level = base_level;
972 /* Put the Guardian */
973 if (!alloc_guardian(TRUE)) return FALSE;
975 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
978 for (y = 0; y < cur_hgt; y++)
980 for (x = 0; x < cur_wid; x++)
982 cave[y][x].info |= (CAVE_GLOW);
991 * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
994 static void build_arena(void)
996 POSITION yval, y_height, y_depth, xval, x_left, x_right;
999 yval = SCREEN_HGT / 2;
1000 xval = SCREEN_WID / 2;
1001 y_height = yval - 10;
1002 y_depth = yval + 10;
1004 x_right = xval + 32;
1006 for (i = y_height; i <= y_height + 5; i++)
1007 for (j = x_left; j <= x_right; j++)
1009 place_extra_perm_bold(i, j);
1010 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1012 for (i = y_depth; i >= y_depth - 5; i--)
1013 for (j = x_left; j <= x_right; j++)
1015 place_extra_perm_bold(i, j);
1016 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1018 for (j = x_left; j <= x_left + 17; j++)
1019 for (i = y_height; i <= y_depth; i++)
1021 place_extra_perm_bold(i, j);
1022 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1024 for (j = x_right; j >= x_right - 17; j--)
1025 for (i = y_height; i <= y_depth; i++)
1027 place_extra_perm_bold(i, j);
1028 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1031 place_extra_perm_bold(y_height+6, x_left+18);
1032 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1033 place_extra_perm_bold(y_depth-6, x_left+18);
1034 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1035 place_extra_perm_bold(y_height+6, x_right-18);
1036 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1037 place_extra_perm_bold(y_depth-6, x_right-18);
1038 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1042 cave[i][j].feat = f_tag_to_index("ARENA_GATE");
1043 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1048 * @brief 闘技場への入場処理 / Town logic flow for generation of arena -KMW-
1051 static void arena_gen(void)
1058 cur_hgt = SCREEN_HGT;
1059 cur_wid = SCREEN_WID;
1061 /* Start with solid walls */
1062 for (y = 0; y < MAX_HGT; y++)
1064 for (x = 0; x < MAX_WID; x++)
1066 /* Create "solid" perma-wall */
1067 place_solid_perm_bold(y, x);
1069 /* Illuminate and memorize the walls */
1070 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1074 /* Then place some floors */
1075 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1077 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1079 /* Create empty floor */
1080 cave[y][x].feat = feat_floor;
1086 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)))
1088 p_ptr->exit_bldg = TRUE;
1089 p_ptr->arena_number++;
1090 msg_print(_("相手は欠場した。あなたの不戦勝だ。", "The enemy is unable appear. You won by default."));
1096 * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
1099 static void build_battle(void)
1101 POSITION yval, y_height, y_depth, xval, x_left, x_right;
1104 yval = SCREEN_HGT / 2;
1105 xval = SCREEN_WID / 2;
1106 y_height = yval - 10;
1107 y_depth = yval + 10;
1109 x_right = xval + 32;
1111 for (i = y_height; i <= y_height + 5; i++)
1112 for (j = x_left; j <= x_right; j++)
1114 place_extra_perm_bold(i, j);
1115 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1117 for (i = y_depth; i >= y_depth - 3; i--)
1118 for (j = x_left; j <= x_right; j++)
1120 place_extra_perm_bold(i, j);
1121 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1123 for (j = x_left; j <= x_left + 17; j++)
1124 for (i = y_height; i <= y_depth; i++)
1126 place_extra_perm_bold(i, j);
1127 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1129 for (j = x_right; j >= x_right - 17; j--)
1130 for (i = y_height; i <= y_depth; i++)
1132 place_extra_perm_bold(i, j);
1133 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1136 place_extra_perm_bold(y_height+6, x_left+18);
1137 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1138 place_extra_perm_bold(y_depth-4, x_left+18);
1139 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1140 place_extra_perm_bold(y_height+6, x_right-18);
1141 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1142 place_extra_perm_bold(y_depth-4, x_right-18);
1143 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1145 for (i = y_height + 1; i <= y_height + 5; i++)
1146 for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
1148 cave[i][j].feat = feat_permanent_glass_wall;
1153 cave[i][j].feat = f_tag_to_index("BUILDING_3");
1154 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1159 * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
1162 static void battle_gen(void)
1169 /* Start with solid walls */
1170 for (y = 0; y < MAX_HGT; y++)
1172 for (x = 0; x < MAX_WID; x++)
1174 /* Create "solid" perma-wall */
1175 place_solid_perm_bold(y, x);
1177 /* Illuminate and memorize the walls */
1178 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1182 /* Then place some floors */
1183 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1185 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1187 /* Create empty floor */
1188 cave[y][x].feat = feat_floor;
1194 for(i = 0; i < 4; i++)
1196 place_monster_aux(0, p_ptr->y + 8 + (i/2)*4, p_ptr->x - 2 + (i%2)*4, battle_mon[i], (PM_NO_KAGE | PM_NO_PET));
1197 set_friendly(&m_list[cave[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
1199 for(i = 1; i < m_max; i++)
1201 monster_type *m_ptr = &m_list[i];
1203 if (!m_ptr->r_idx) continue;
1205 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1206 update_monster(i, FALSE);
1211 * @brief 固定マップクエストのフロア生成 / Generate a quest level
1214 static void quest_gen(void)
1218 /* Start with perm walls */
1219 for (y = 0; y < cur_hgt; y++)
1221 for (x = 0; x < cur_wid; x++)
1223 place_solid_perm_bold(y, x);
1227 /* Set the quest level */
1228 base_level = quest[p_ptr->inside_quest].level;
1229 dun_level = base_level;
1230 object_level = base_level;
1231 monster_level = base_level;
1233 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1235 /* Prepare allocation table */
1236 get_mon_num_prep(get_monster_hook(), NULL);
1238 init_flags = INIT_CREATE_DUNGEON;
1240 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1244 * @brief ダンジョン時のランダムフロア生成 / Make a real level
1245 * @return フロアの生成に成功したらTRUE
1247 static bool level_gen(concptr *why)
1249 int level_height, level_width;
1251 if ((always_small_levels || ironman_small_levels ||
1252 (one_in_(SMALL_LEVEL) && small_levels) ||
1253 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1254 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1255 !(d_info[dungeon_type].flags1 & DF1_BIG))
1257 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1262 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1271 level_height = randint1(MAX_HGT/SCREEN_HGT);
1272 level_width = randint1(MAX_WID/SCREEN_WID);
1274 while ((level_height == MAX_HGT/SCREEN_HGT) && (level_width == MAX_WID/SCREEN_WID));
1277 cur_hgt = level_height * SCREEN_HGT;
1278 cur_wid = level_width * SCREEN_WID;
1280 /* Assume illegal panel */
1281 panel_row_min = cur_hgt;
1282 panel_col_min = cur_wid;
1284 msg_format_wizard(CHEAT_DUNGEON,
1285 _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."),
1294 /* Assume illegal panel */
1295 panel_row_min = cur_hgt;
1296 panel_col_min = cur_wid;
1299 /* Make a dungeon */
1302 *why = _("ダンジョン生成に失敗", "could not place player");
1309 * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after cave generation
1312 void wipe_generate_cave_flags(void)
1316 for (y = 0; y < cur_hgt; y++)
1318 for (x = 0; x < cur_wid; x++)
1320 /* Wipe unused flags */
1321 cave[y][x].info &= ~(CAVE_MASK);
1327 for (y = 1; y < cur_hgt - 1; y++)
1329 for (x = 1; x < cur_wid - 1; x++)
1331 /* There might be trap */
1332 cave[y][x].info |= CAVE_UNSAFE;
1339 * @brief フロアの全情報を初期化する / Clear and empty the cave
1342 void clear_cave(void)
1347 /* Very simplified version of wipe_o_list() */
1348 (void)C_WIPE(o_list, o_max, object_type);
1352 /* Very simplified version of wipe_m_list() */
1353 for (i = 1; i < max_r_idx; i++)
1354 r_info[i].cur_num = 0;
1355 (void)C_WIPE(m_list, m_max, monster_type);
1358 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
1360 /* Pre-calc cur_num of pets in party_mon[] */
1361 precalc_cur_num_of_pet();
1364 /* Start with a blank cave */
1365 for (y = 0; y < MAX_HGT; y++)
1367 for (x = 0; x < MAX_WID; x++)
1369 cave_type *c_ptr = &cave[y][x];
1382 /* Mega-Hack -- no player yet */
1383 p_ptr->x = p_ptr->y = 0;
1385 /* Set the base level */
1386 base_level = dun_level;
1388 /* Reset the monster generation level */
1389 monster_level = base_level;
1391 /* Reset the object generation level */
1392 object_level = base_level;
1397 * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
1399 * @note Hack -- regenerate any "overflow" levels
1401 void generate_cave(void)
1405 /* Fill the arrays of floors and walls in the good proportions */
1406 set_floor_and_wall(dungeon_type);
1409 for (num = 0; TRUE; num++)
1415 /* Clear and empty the cave */
1418 /* Build the arena -KMW- */
1419 if (p_ptr->inside_arena)
1425 /* Build the battle -KMW- */
1426 else if (p_ptr->inside_battle)
1432 else if (p_ptr->inside_quest)
1437 /* Build the town */
1438 else if (!dun_level)
1440 /* Make the wilderness */
1441 if (p_ptr->wild_mode) wilderness_gen_small();
1442 else wilderness_gen();
1445 /* Build a real level */
1448 okay = level_gen(&why);
1452 /* Prevent object over-flow */
1453 if (o_max >= max_o_idx)
1455 why = _("アイテムが多すぎる", "too many objects");
1458 /* Prevent monster over-flow */
1459 else if (m_max >= max_m_idx)
1461 why = _("モンスターが多すぎる", "too many monsters");
1468 if (why) msg_format(_("生成やり直し(%s)", "Generation restarted (%s)"), why);
1474 /* Glow deep lava and building entrances */
1475 glow_deep_lava_and_bldg();
1478 p_ptr->enter_dungeon = FALSE;
1480 wipe_generate_cave_flags();
1484 * @brief 部屋間のトンネルを生成する / Constructs a tunnel between two points
1489 * @return 生成に成功したらTRUEを返す
1491 * This function must be called BEFORE any streamers are created,\n
1492 * since we use the special "granite wall" sub-types to keep track\n
1493 * of legal places for corridors to pierce rooms.\n
1495 * We use "door_flag" to prevent excessive construction of doors\n
1496 * along overlapping corridors.\n
1498 * We queue the tunnel grids to prevent door creation along a corridor\n
1499 * which intersects itself.\n
1501 * We queue the wall piercing grids to prevent a corridor from leaving\n
1502 * a room and then coming back in through the same entrance.\n
1504 * We "pierce" grids which are "outer" walls of rooms, and when we\n
1505 * do so, we change all adjacent "outer" walls of rooms into "solid"\n
1506 * walls so that no two corridors may use adjacent grids for exits.\n
1508 * The "solid" wall check prevents corridors from "chopping" the\n
1509 * corners of rooms off, as well as "silly" door placement, and\n
1510 * "excessively wide" room entrances.\n
1514 * inner -- inner room walls\n
1515 * outer -- outer room walls\n
1516 * solid -- solid room walls\n
1518 bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
1521 POSITION tmp_row, tmp_col;
1522 POSITION row_dir, col_dir;
1523 POSITION start_row, start_col;
1524 int main_loop_count = 0;
1526 bool door_flag = FALSE;
1530 /* Save the starting location */
1534 /* Start out in the correct direction */
1535 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1537 /* Keep going until done (or bored) */
1538 while ((row1 != row2) || (col1 != col2))
1540 /* Mega-Hack -- Paranoia -- prevent infinite loops */
1541 if (main_loop_count++ > 2000) return FALSE;
1543 /* Allow bends in the tunnel */
1544 if (randint0(100) < dun_tun_chg)
1546 /* Acquire the correct direction */
1547 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1549 /* Random direction */
1550 if (randint0(100) < dun_tun_rnd)
1552 rand_dir(&row_dir, &col_dir);
1556 /* Get the next location */
1557 tmp_row = row1 + row_dir;
1558 tmp_col = col1 + col_dir;
1561 /* Extremely Important -- do not leave the dungeon */
1562 while (!in_bounds(tmp_row, tmp_col))
1564 /* Acquire the correct direction */
1565 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1567 /* Random direction */
1568 if (randint0(100) < dun_tun_rnd)
1570 rand_dir(&row_dir, &col_dir);
1573 /* Get the next location */
1574 tmp_row = row1 + row_dir;
1575 tmp_col = col1 + col_dir;
1579 /* Access the location */
1580 c_ptr = &cave[tmp_row][tmp_col];
1582 /* Avoid "solid" walls */
1583 if (is_solid_grid(c_ptr)) continue;
1585 /* Pierce "outer" walls of rooms */
1586 if (is_outer_grid(c_ptr))
1588 /* Acquire the "next" location */
1589 y = tmp_row + row_dir;
1590 x = tmp_col + col_dir;
1592 /* Hack -- Avoid outer/solid walls */
1593 if (is_outer_bold(y, x)) continue;
1594 if (is_solid_bold(y, x)) continue;
1596 /* Accept this location */
1597 row1 = (POSITION)tmp_row;
1598 col1 = (POSITION)tmp_col;
1600 /* Save the wall location */
1601 if (dun->wall_n < WALL_MAX)
1603 dun->wall[dun->wall_n].y = row1;
1604 dun->wall[dun->wall_n].x = col1;
1609 /* Forbid re-entry near this piercing */
1610 for (y = row1 - 1; y <= row1 + 1; y++)
1612 for (x = col1 - 1; x <= col1 + 1; x++)
1614 /* Convert adjacent "outer" walls as "solid" walls */
1615 if (is_outer_bold(y, x))
1617 /* Change the wall to a "solid" wall */
1618 place_solid_noperm_bold(y, x);
1624 /* Travel quickly through rooms */
1625 else if (c_ptr->info & (CAVE_ROOM))
1627 /* Accept the location */
1632 /* Tunnel through all other walls */
1633 else if (is_extra_grid(c_ptr) || is_inner_grid(c_ptr) || is_solid_grid(c_ptr))
1635 /* Accept this location */
1639 /* Save the tunnel location */
1640 if (dun->tunn_n < TUNN_MAX)
1642 dun->tunn[dun->tunn_n].y = row1;
1643 dun->tunn[dun->tunn_n].x = col1;
1648 /* Allow door in next grid */
1652 /* Handle corridor intersections or overlaps */
1655 /* Accept the location */
1659 /* Collect legal door locations */
1662 /* Save the door location */
1663 if (dun->door_n < DOOR_MAX)
1665 dun->door[dun->door_n].y = row1;
1666 dun->door[dun->door_n].x = col1;
1671 /* No door in next grid */
1675 /* Hack -- allow pre-emptive tunnel termination */
1676 if (randint0(100) >= dun_tun_con)
1678 /* Distance between row1 and start_row */
1679 tmp_row = row1 - start_row;
1680 if (tmp_row < 0) tmp_row = (-tmp_row);
1682 /* Distance between col1 and start_col */
1683 tmp_col = col1 - start_col;
1684 if (tmp_col < 0) tmp_col = (-tmp_col);
1686 /* Terminate the tunnel */
1687 if ((tmp_row > 10) || (tmp_col > 10)) break;
1697 * @brief トンネル生成のための基準点を指定する。
1698 * @param x 基準点を指定するX座標の参照ポインタ、適時値が修正される。
1699 * @param y 基準点を指定するY座標の参照ポインタ、適時値が修正される。
1700 * @param affectwall (調査中)
1703 * This routine adds the square to the tunnel\n
1704 * It also checks for SOLID walls - and returns a nearby\n
1705 * non-SOLID square in (x,y) so that a simple avoiding\n
1706 * routine can be used. The returned boolean value reflects\n
1707 * whether or not this routine hit a SOLID wall.\n
1709 * "affectwall" toggles whether or not this new square affects\n
1710 * the boundaries of rooms. - This is used by the catacomb\n
1712 * @todo 特に詳細な処理の意味を調査すべし
1714 static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
1718 cave_type *c_ptr = &cave[*y][*x];
1720 if (!in_bounds(*y, *x)) return TRUE;
1722 if (is_inner_grid(c_ptr))
1727 if (is_extra_bold(*y, *x))
1729 /* Save the tunnel location */
1730 if (dun->tunn_n < TUNN_MAX)
1732 dun->tunn[dun->tunn_n].y = *y;
1733 dun->tunn[dun->tunn_n].x = *x;
1741 if (is_floor_bold(*y, *x))
1743 /* Don't do anything */
1747 if (is_outer_grid(c_ptr) && affectwall)
1749 /* Save the wall location */
1750 if (dun->wall_n < WALL_MAX)
1752 dun->wall[dun->wall_n].y = *y;
1753 dun->wall[dun->wall_n].x = *x;
1758 /* Forbid re-entry near this piercing */
1759 for (j = *y - 1; j <= *y + 1; j++)
1761 for (i = *x - 1; i <= *x + 1; i++)
1763 /* Convert adjacent "outer" walls as "solid" walls */
1764 if (is_outer_bold(j, i))
1766 /* Change the wall to a "solid" wall */
1767 place_solid_noperm_bold(j, i);
1772 /* Clear mimic type */
1773 cave[*y][*x].mimic = 0;
1775 place_floor_bold(*y, *x);
1780 if (is_solid_grid(c_ptr) && affectwall)
1782 /* cannot place tunnel here - use a square to the side */
1784 /* find usable square and return value in (x,y) */
1790 while ((i > 0) && is_solid_bold(*y + dy, *x + dx))
1792 dy = randint0(3) - 1;
1793 dx = randint0(3) - 1;
1795 if (!in_bounds(*y + dy, *x + dx))
1806 /* Failed for some reason: hack - ignore the solidness */
1807 place_outer_grid(c_ptr);
1812 /* Give new, acceptable coordinate. */
1824 * @brief 外壁を削って「カタコンベ状」の通路を作成する / This routine creates the catacomb-like tunnels by removing extra rock.
1829 * Note that this routine is only called on "even" squares - so it gives
1830 * a natural checkerboard pattern.
1832 static void create_cata_tunnel(POSITION x, POSITION y)
1839 set_tunnel(&x1, &y1, FALSE);
1843 set_tunnel(&x1, &y1, FALSE);
1847 set_tunnel(&x1, &y1, FALSE);
1851 set_tunnel(&x1, &y1, FALSE);
1856 * @brief トンネル生成処理(詳細調査中)/ This routine does the bulk of the work in creating the new types of tunnels.
1860 * It is designed to use very simple algorithms to go from (x1,y1) to (x2,y2)\n
1861 * It doesn't need to add any complexity - straight lines are fine.\n
1862 * The SOLID walls are avoided by a recursive algorithm which tries random ways\n
1863 * around the obstical until it works. The number of itterations is counted, and it\n
1864 * this gets too large the routine exits. This should stop any crashes - but may leave\n
1865 * small gaps in the tunnel where there are too many SOLID walls.\n
1867 * Type 1 tunnels are extremely simple - straight line from A to B. This is only used\n
1868 * as a part of the dodge SOLID walls algorithm.\n
1870 * Type 2 tunnels are made of two straight lines at right angles. When this is used with\n
1871 * short line segments it gives the "cavelike" tunnels seen deeper in the dungeon.\n
1873 * Type 3 tunnels are made of two straight lines like type 2, but with extra rock removed.\n
1874 * This, when used with longer line segments gives the "catacomb-like" tunnels seen near\n
1877 static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
1883 /* Check for early exit */
1884 if (!(*fail)) return;
1886 length = distance(x1, y1, x2, y2);
1890 if ((type == 1) && (length != 0))
1893 for (i = 0; i <= length; i++)
1895 x = x1 + i * (x2 - x1) / length;
1896 y = y1 + i * (y2 - y1) / length;
1897 if (!set_tunnel(&x, &y, TRUE))
1901 /* This isn't working - probably have an infinite loop */
1906 /* solid wall - so try to go around */
1907 short_seg_hack(x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
1908 short_seg_hack(x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
1912 else if ((type == 2) || (type == 3))
1916 for (i = x1; i <= x2; i++)
1920 if (!set_tunnel(&x, &y, TRUE))
1922 /* solid wall - so try to go around */
1923 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1924 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1926 if ((type == 3) && ((x + y) % 2))
1928 create_cata_tunnel(i, y1);
1934 for (i = x2; i <= x1; i++)
1938 if (!set_tunnel(&x, &y, TRUE))
1940 /* solid wall - so try to go around */
1941 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1942 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1944 if ((type == 3) && ((x + y) % 2))
1946 create_cata_tunnel(i, y1);
1953 for (i = y1; i <= y2; i++)
1957 if (!set_tunnel(&x, &y, TRUE))
1959 /* solid wall - so try to go around */
1960 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1961 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1963 if ((type == 3) && ((x + y) % 2))
1965 create_cata_tunnel(x2, i);
1971 for (i = y2; i <= y1; i++)
1975 if (!set_tunnel(&x, &y, TRUE))
1977 /* solid wall - so try to go around */
1978 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1979 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1981 if ((type == 3) && ((x + y) % 2))
1983 create_cata_tunnel(x2, i);
1992 * @brief 特定の壁(永久壁など)を避けながら部屋間の通路を作成する / This routine maps a path from (x1, y1) to (x2, y2) avoiding SOLID walls.
1996 * Permanent rock is ignored in this path finding- sometimes there is no\n
1997 * path around anyway -so there will be a crash if we try to find one.\n
1998 * This routine is much like the river creation routine in Zangband.\n
1999 * It works by dividing a line segment into two. The segments are divided\n
2000 * until they are less than "cutoff" - when the corresponding routine from\n
2001 * "short_seg_hack" is called.\n
2002 * Note it is VERY important that the "stop if hit another passage" logic\n
2003 * stays as is. Without this the dungeon turns into Swiss Cheese...\n
2005 bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
2007 POSITION x3, y3, dx, dy;
2008 POSITION changex, changey;
2011 bool retval, firstsuccede;
2014 length = distance(x1, y1, x2, y2);
2016 if (length > cutoff)
2019 * Divide path in half and call routine twice.
2024 /* perturbation perpendicular to path */
2025 changex = (randint0(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
2026 changey = (randint0(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
2028 /* Work out "mid" ponit */
2029 x3 = x1 + dx + changex;
2030 y3 = y1 + dy + changey;
2032 /* See if in bounds - if not - do not perturb point */
2033 if (!in_bounds(y3, x3))
2039 c_ptr = &cave[y3][x3];
2040 if (is_solid_grid(c_ptr))
2042 /* move midpoint a bit to avoid problem. */
2048 while ((i > 0) && is_solid_bold(y3 + dy, x3 + dx))
2050 dy = randint0(3) - 1;
2051 dx = randint0(3) - 1;
2052 if (!in_bounds(y3 + dy, x3 + dx))
2062 /* Failed for some reason: hack - ignore the solidness */
2063 place_outer_bold(y3, x3);
2069 c_ptr = &cave[y3][x3];
2072 if (is_floor_grid(c_ptr))
2074 if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
2076 if ((cave[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
2078 /* do second half only if works + if have hit a room */
2079 retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
2083 /* have hit another tunnel - make a set of doors here */
2086 /* Save the door location */
2087 if (dun->door_n < DOOR_MAX)
2089 dun->door[dun->door_n].y = (POSITION)y3;
2090 dun->door[dun->door_n].x = (POSITION)x3;
2095 firstsuccede = TRUE;
2099 /* false- didn't work all the way */
2101 firstsuccede = FALSE;
2106 /* tunnel through walls */
2107 if (build_tunnel2(x1, y1, (POSITION)x3, (POSITION)y3, type, cutoff))
2109 retval = build_tunnel2((POSITION)x3, (POSITION)y3, x2, y2, type, cutoff);
2110 firstsuccede = TRUE;
2114 /* false- didn't work all the way */
2116 firstsuccede = FALSE;
2121 /* only do this if the first half has worked */
2122 set_tunnel(&x3, &y3, TRUE);
2124 /* return value calculated above */
2129 /* Do a short segment */
2131 short_seg_hack(x1, y1, x2, y2, type, 0, &retval);
2133 /* Hack - ignore return value so avoid infinite loops */