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 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"
104 #include "floor-generate.h"
108 #include "player-status.h"
110 #include "monster-status.h"
120 * Dungeon generation data -- see "cave_gen()"
126 * @brief 上下左右の外壁数をカウントする / Count the number of walls adjacent to the given grid.
130 * @note Assumes "in_bounds(y, x)"
131 * @details We count only granite walls and permanent walls.
133 static int next_to_walls(POSITION y, POSITION x)
137 if (in_bounds(y + 1, x) && is_extra_bold(y + 1, x)) k++;
138 if (in_bounds(y - 1, x) && is_extra_bold(y - 1, x)) k++;
139 if (in_bounds(y, x + 1) && is_extra_bold(y, x + 1)) k++;
140 if (in_bounds(y, x - 1) && is_extra_bold(y, x - 1)) k++;
146 * @brief alloc_stairs()の補助として指定の位置に階段を生成できるかの判定を行う / Helper function for alloc_stairs(). Is this a good location for stairs?
149 * @param walls 最低減隣接させたい外壁の数
150 * @return 階段を生成して問題がないならばTRUEを返す。
152 static bool alloc_stairs_aux(POSITION y, POSITION x, int walls)
154 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
156 /* Require "naked" floor grid */
157 if (!is_floor_grid(g_ptr)) return FALSE;
158 if (pattern_tile(y, x)) return FALSE;
159 if (g_ptr->o_idx || g_ptr->m_idx) return FALSE;
161 /* Require a certain number of adjacent walls */
162 if (next_to_walls(y, x) < walls) return FALSE;
169 * @brief 外壁に隣接させて階段を生成する / Places some staircases near walls
170 * @param feat 配置したい地形ID
171 * @param num 配置したい階段の数
172 * @param walls 最低減隣接させたい外壁の数
173 * @return 規定数通りに生成に成功したらTRUEを返す。
175 static bool alloc_stairs(IDX feat, int num, int walls)
180 feature_type *f_ptr = &f_info[feat];
182 if (have_flag(f_ptr->flags, FF_LESS))
184 /* No up stairs in town or in ironman mode */
185 if (ironman_downward || !current_floor_ptr->dun_level) return TRUE;
187 if (current_floor_ptr->dun_level > d_info[p_ptr->dungeon_idx].mindepth)
188 shaft_num = (randint1(num+1))/2;
190 else if (have_flag(f_ptr->flags, FF_MORE))
192 QUEST_IDX q_idx = quest_number(current_floor_ptr->dun_level);
194 /* No downstairs on quest levels */
195 if (current_floor_ptr->dun_level > 1 && q_idx)
197 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
199 /* The quest monster(s) is still alive? */
200 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
204 /* No downstairs at the bottom */
205 if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) return TRUE;
207 if ((current_floor_ptr->dun_level < d_info[p_ptr->dungeon_idx].maxdepth-1) && !quest_number(current_floor_ptr->dun_level+1))
208 shaft_num = (randint1(num)+1)/2;
213 /* Place "num" stairs */
214 for (i = 0; i < num; i++)
224 for (y = 1; y < current_floor_ptr->height - 1; y++)
226 for (x = 1; x < current_floor_ptr->width - 1; x++)
228 if (alloc_stairs_aux(y, x, walls))
230 /* A valid space found */
236 /* No valid place! */
239 /* There are exactly no place! */
240 if (walls <= 0) return FALSE;
242 /* Decrease walls limit, and try again */
247 /* Choose a random one */
248 pick = randint1(candidates);
250 for (y = 1; y < current_floor_ptr->height - 1; y++)
252 for (x = 1; x < current_floor_ptr->width - 1; x++)
254 if (alloc_stairs_aux(y, x, walls))
258 /* Is this a picked one? */
265 g_ptr = ¤t_floor_ptr->grid_array[y][x];
267 /* Clear possible garbage of hidden trap */
270 /* Clear previous contents, add stairs */
271 g_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
273 /* No longer "FLOOR" */
274 g_ptr->info &= ~(CAVE_FLOOR);
284 * @brief フロア上のランダム位置に各種オブジェクトを配置する / Allocates some objects (using "place" and "type")
285 * @param set 配置したい地形の種類
286 * @param typ 配置したいオブジェクトの種類
288 * @return 規定数通りに生成に成功したらTRUEを返す。
290 static void alloc_object(int set, EFFECT_ID typ, int num)
292 POSITION y = 0, x = 0;
297 /* A small level has few objects. */
298 num = num * current_floor_ptr->height * current_floor_ptr->width / (MAX_HGT*MAX_WID) +1;
300 /* Place some objects */
301 for (k = 0; k < num; k++)
303 /* Pick a "legal" spot */
304 while (dummy < SAFE_MAX_ATTEMPTS)
310 y = randint0(current_floor_ptr->height);
311 x = randint0(current_floor_ptr->width);
313 g_ptr = ¤t_floor_ptr->grid_array[y][x];
315 /* Require "naked" floor grid */
316 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
318 /* Avoid player location */
319 if (player_bold(y, x)) continue;
321 /* Check for "room" */
322 room = (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
324 /* Require corridor? */
325 if ((set == ALLOC_SET_CORR) && room) continue;
328 if ((set == ALLOC_SET_ROOM) && !room) continue;
334 if (dummy >= SAFE_MAX_ATTEMPTS)
336 msg_print_wizard(CHEAT_DUNGEON, _("アイテムの配置に失敗しました。", "Failed to place object."));
341 /* Place something */
344 case ALLOC_TYP_RUBBLE:
347 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
354 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
364 case ALLOC_TYP_OBJECT:
366 place_object(y, x, 0L);
377 * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
378 * @return 成功したならばTRUEを返す
380 bool place_quest_monsters(void)
384 /* Handle the quest monster placements */
385 for (i = 0; i < max_q_idx; i++)
391 if (quest[i].status != QUEST_STATUS_TAKEN ||
392 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
393 quest[i].type != QUEST_TYPE_RANDOM) ||
394 quest[i].level != current_floor_ptr->dun_level ||
395 p_ptr->dungeon_idx != quest[i].dungeon ||
396 (quest[i].flags & QUEST_FLAG_PRESET))
402 r_ptr = &r_info[quest[i].r_idx];
404 /* Hack -- "unique" monsters must be "unique" */
405 if ((r_ptr->flags1 & RF1_UNIQUE) &&
406 (r_ptr->cur_num >= r_ptr->max_num)) continue;
408 mode = (PM_NO_KAGE | PM_NO_PET);
410 if (!(r_ptr->flags1 & RF1_FRIENDS))
411 mode |= PM_ALLOW_GROUP;
413 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
417 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
419 POSITION x = 0, y = 0;
422 /* Find an empty grid */
423 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
428 y = randint0(current_floor_ptr->height);
429 x = randint0(current_floor_ptr->width);
431 g_ptr = ¤t_floor_ptr->grid_array[y][x];
432 f_ptr = &f_info[g_ptr->feat];
434 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
435 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
436 if (distance(y, x, p_ptr->y, p_ptr->x) < 10) continue;
437 if (g_ptr->info & CAVE_ICKY) continue;
441 /* Failed to place */
442 if (!l) return FALSE;
444 /* Try to place the monster */
445 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
452 /* Failure - Try again */
457 /* Failed to place */
458 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
466 * @brief フロアに洞窟や湖を配置する / Generate various caverns and lakes
467 * @details There were moved from cave_gen().
470 static void gen_caverns_and_lakes(void)
472 #ifdef ALLOW_CAVERNS_AND_LAKES
473 /* Possible "destroyed" level */
474 if ((current_floor_ptr->dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DESTROY))
476 dun->destroyed = TRUE;
478 /* extra rubble around the place looks cool */
479 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
482 /* Make a lake some of the time */
483 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
484 (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_MASK))
487 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_WATER) count += 3;
488 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_LAVA) count += 3;
489 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_RUBBLE) count += 3;
490 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_TREE) count += 3;
492 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_LAVA)
495 if ((current_floor_ptr->dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
499 if (!dun->laketype && (current_floor_ptr->dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
503 if ((d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_WATER) && !dun->laketype)
506 if ((current_floor_ptr->dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
510 if (!dun->laketype && (current_floor_ptr->dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
514 if ((d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
517 if ((current_floor_ptr->dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
520 /* Lake of rubble2 */
521 if (!dun->laketype && (current_floor_ptr->dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
526 if ((current_floor_ptr->dun_level > 5) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
530 msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
531 build_lake(dun->laketype);
535 if ((current_floor_ptr->dun_level > DUN_CAVERN) && !dun->empty_level &&
536 (d_info[p_ptr->dungeon_idx].flags1 & DF1_CAVERN) &&
537 !dun->laketype && !dun->destroyed && (randint1(1000) < current_floor_ptr->dun_level))
541 /* make a large fractal current_floor_ptr->grid_array in the middle of the dungeon */
543 msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
546 #endif /* ALLOW_CAVERNS_AND_LAKES */
548 /* Hack -- No destroyed "quest" levels */
549 if (quest_number(current_floor_ptr->dun_level)) dun->destroyed = FALSE;
554 * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
555 * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
556 * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
558 static bool cave_gen(void)
564 current_floor_ptr->lite_n = 0;
565 current_floor_ptr->mon_lite_n = 0;
566 current_floor_ptr->redraw_n = 0;
567 current_floor_ptr->view_n = 0;
572 dun->destroyed = FALSE;
573 dun->empty_level = FALSE;
577 /* Fill the arrays of floors and walls in the good proportions */
578 set_floor_and_wall(p_ptr->dungeon_idx);
579 get_mon_num_prep(get_monster_hook(), NULL);
581 /* Randomize the dungeon creation values */
582 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
583 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
584 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
585 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
586 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
588 /* Actual maximum number of rooms on this level */
589 dun->row_rooms = current_floor_ptr->height / BLOCK_HGT;
590 dun->col_rooms = current_floor_ptr->width / BLOCK_WID;
592 /* Initialize the room table */
593 for (y = 0; y < dun->row_rooms; y++)
595 for (x = 0; x < dun->col_rooms; x++)
597 dun->room_map[y][x] = FALSE;
604 /* Empty arena levels */
605 if (ironman_empty_levels || ((d_info[p_ptr->dungeon_idx].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
607 dun->empty_level = TRUE;
608 msg_print_wizard(CHEAT_DUNGEON, _("アリーナレベルを生成。", "Arena level."));
611 if (dun->empty_level)
613 /* Start with floors */
614 for (y = 0; y < current_floor_ptr->height; y++)
616 for (x = 0; x < current_floor_ptr->width; x++)
618 place_floor_bold(y, x);
622 /* Special boundary walls -- Top and bottom */
623 for (x = 0; x < current_floor_ptr->width; x++)
625 place_extra_bold(0, x);
626 place_extra_bold(current_floor_ptr->height - 1, x);
629 /* Special boundary walls -- Left and right */
630 for (y = 1; y < (current_floor_ptr->height - 1); y++)
632 place_extra_bold(y, 0);
633 place_extra_bold(y, current_floor_ptr->width - 1);
638 /* Start with walls */
639 for (y = 0; y < current_floor_ptr->height; y++)
641 for (x = 0; x < current_floor_ptr->width; x++)
643 place_extra_bold(y, x);
648 /* Generate various caverns and lakes */
649 gen_caverns_and_lakes();
652 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_MAZE)
654 build_maze_vault(current_floor_ptr->width/2-1, current_floor_ptr->height/2-1, current_floor_ptr->width-4, current_floor_ptr->height-4, FALSE);
656 /* Place 3 or 4 down stairs near some walls */
657 if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
659 /* Place 1 or 2 up stairs near some walls */
660 if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
663 /* Build some rooms */
666 int tunnel_fail_count = 0;
669 * Build each type of room in current_world_ptr->game_turn until we cannot build any more.
671 if (!generate_rooms()) return FALSE;
674 /* Make a hole in the dungeon roof sometimes at level 1 */
675 if (current_floor_ptr->dun_level == 1)
677 while (one_in_(DUN_MOS_DEN))
679 place_trees(randint1(current_floor_ptr->width - 2), randint1(current_floor_ptr->height - 2));
683 /* Destroy the level if necessary */
684 if (dun->destroyed) destroy_level();
686 /* Hack -- Add some rivers */
687 if (one_in_(3) && (randint1(current_floor_ptr->dun_level) > 5))
689 FEAT_IDX feat1 = 0, feat2 = 0;
691 /* Choose water mainly */
692 if ((randint1(MAX_DEPTH * 2) - 1 > current_floor_ptr->dun_level) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_WATER_RIVER))
694 feat1 = feat_deep_water;
695 feat2 = feat_shallow_water;
699 FEAT_IDX select_deep_feat[10];
700 FEAT_IDX select_shallow_feat[10];
701 int select_id_max = 0, selected;
703 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAVA_RIVER)
705 select_deep_feat[select_id_max] = feat_deep_lava;
706 select_shallow_feat[select_id_max] = feat_shallow_lava;
709 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_POISONOUS_RIVER)
711 select_deep_feat[select_id_max] = feat_deep_poisonous_puddle;
712 select_shallow_feat[select_id_max] = feat_shallow_poisonous_puddle;
715 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_ACID_RIVER)
717 select_deep_feat[select_id_max] = feat_deep_acid_puddle;
718 select_shallow_feat[select_id_max] = feat_shallow_acid_puddle;
722 selected = randint0(select_id_max);
723 feat1 = select_deep_feat[selected];
724 feat2 = select_shallow_feat[selected];
729 feature_type *f_ptr = &f_info[feat1];
731 /* Only add river if matches lake type or if have no lake at all */
732 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
733 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
736 add_river(feat1, feat2);
741 /* Hack -- Scramble the room order */
742 for (i = 0; i < dun->cent_n; i++)
745 int pick = rand_range(0, i);
749 dun->cent[i].y = dun->cent[pick].y;
750 dun->cent[i].x = dun->cent[pick].x;
751 dun->cent[pick].y = ty;
752 dun->cent[pick].x = tx;
755 /* Start with no tunnel doors */
758 /* Hack -- connect the first room to the last room */
759 y = dun->cent[dun->cent_n-1].y;
760 x = dun->cent[dun->cent_n-1].x;
762 /* Connect all the rooms together */
763 for (i = 0; i < dun->cent_n; i++)
767 /* Reset the arrays */
771 /* Connect the room to the previous room */
772 if (randint1(current_floor_ptr->dun_level) > d_info[p_ptr->dungeon_idx].tunnel_percent)
774 /* make cavelike tunnel */
775 (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
779 /* make normal tunnel */
780 if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
783 if (tunnel_fail_count >= 2) return FALSE;
785 /* Turn the tunnel into corridor */
786 for (j = 0; j < dun->tunn_n; j++)
792 g_ptr = ¤t_floor_ptr->grid_array[y][x];
793 f_ptr = &f_info[g_ptr->feat];
795 /* Clear previous contents (if not a lake), add a floor */
796 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
798 /* Clear mimic type */
801 place_floor_grid(g_ptr);
805 /* Apply the piercings that we found */
806 for (j = 0; j < dun->wall_n; j++)
811 g_ptr = ¤t_floor_ptr->grid_array[y][x];
813 /* Clear mimic type */
816 /* Clear previous contents, add up floor */
817 place_floor_grid(g_ptr);
819 /* Occasional doorway */
820 if ((randint0(100) < dun_tun_pen) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
822 /* Place a random door */
823 place_random_door(y, x, TRUE);
827 /* Remember the "previous" room */
832 /* Place intersection doors */
833 for (i = 0; i < dun->door_n; i++)
835 /* Extract junction location */
839 /* Try placing doors */
846 /* Place 3 or 4 down stairs near some walls */
847 if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
849 /* Place 1 or 2 up stairs near some walls */
850 if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
855 if (d_info[p_ptr->dungeon_idx].stream2)
857 /* Hack -- Add some quartz streamers */
858 for (i = 0; i < DUN_STR_QUA; i++)
860 build_streamer(d_info[p_ptr->dungeon_idx].stream2, DUN_STR_QC);
864 if (d_info[p_ptr->dungeon_idx].stream1)
866 /* Hack -- Add some magma streamers */
867 for (i = 0; i < DUN_STR_MAG; i++)
869 build_streamer(d_info[p_ptr->dungeon_idx].stream1, DUN_STR_MC);
874 /* Special boundary walls -- Top and bottom */
875 for (x = 0; x < current_floor_ptr->width; x++)
877 place_bound_perm_wall(¤t_floor_ptr->grid_array[0][x]);
878 place_bound_perm_wall(¤t_floor_ptr->grid_array[current_floor_ptr->height - 1][x]);
881 /* Special boundary walls -- Left and right */
882 for (y = 1; y < (current_floor_ptr->height - 1); y++)
884 place_bound_perm_wall(¤t_floor_ptr->grid_array[y][0]);
885 place_bound_perm_wall(¤t_floor_ptr->grid_array[y][current_floor_ptr->width - 1]);
888 /* Determine the character location */
889 if (!new_player_spot()) return FALSE;
891 if (!place_quest_monsters()) return FALSE;
894 k = (current_floor_ptr->dun_level / 3);
898 /* Pick a base number of monsters */
899 i = d_info[p_ptr->dungeon_idx].min_m_alloc_level;
901 /* To make small levels a bit more playable */
902 if (current_floor_ptr->height < MAX_HGT || current_floor_ptr->width < MAX_WID)
904 int small_tester = i;
906 i = (i * current_floor_ptr->height) / MAX_HGT;
907 i = (i * current_floor_ptr->width) / MAX_WID;
910 if (i > small_tester) i = small_tester;
911 else msg_format_wizard(CHEAT_DUNGEON,
912 _("モンスター数基本値を %d から %d に減らします", "Reduced monsters base from %d to %d"), small_tester, i);
918 /* Put some monsters in the dungeon */
919 for (i = i + k; i > 0; i--)
921 (void)alloc_monster(0, PM_ALLOW_SLEEP);
924 /* Place some traps in the dungeon */
925 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
927 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
928 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
930 /* Mega Hack -- No object at first level of deeper dungeon */
931 if (p_ptr->enter_dungeon && current_floor_ptr->dun_level > 1)
934 current_floor_ptr->object_level = 1;
937 /* Put some objects in rooms */
938 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
940 /* Put some objects/gold in the dungeon */
941 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
942 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
944 /* Set back to default */
945 current_floor_ptr->object_level = current_floor_ptr->base_level;
947 /* Put the Guardian */
948 if (!alloc_guardian(TRUE)) return FALSE;
950 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > current_floor_ptr->dun_level)) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
952 /* Lite the current_floor_ptr->grid_array */
953 for (y = 0; y < current_floor_ptr->height; y++)
955 for (x = 0; x < current_floor_ptr->width; x++)
957 current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW);
966 * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
969 static void build_arena(void)
971 POSITION yval, y_height, y_depth, xval, x_left, x_right;
974 yval = SCREEN_HGT / 2;
975 xval = SCREEN_WID / 2;
976 y_height = yval - 10;
981 for (i = y_height; i <= y_height + 5; i++)
982 for (j = x_left; j <= x_right; j++)
984 place_extra_perm_bold(i, j);
985 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
987 for (i = y_depth; i >= y_depth - 5; i--)
988 for (j = x_left; j <= x_right; j++)
990 place_extra_perm_bold(i, j);
991 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
993 for (j = x_left; j <= x_left + 17; j++)
994 for (i = y_height; i <= y_depth; i++)
996 place_extra_perm_bold(i, j);
997 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
999 for (j = x_right; j >= x_right - 17; j--)
1000 for (i = y_height; i <= y_depth; i++)
1002 place_extra_perm_bold(i, j);
1003 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1006 place_extra_perm_bold(y_height+6, x_left+18);
1007 current_floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1008 place_extra_perm_bold(y_depth-6, x_left+18);
1009 current_floor_ptr->grid_array[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1010 place_extra_perm_bold(y_height+6, x_right-18);
1011 current_floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1012 place_extra_perm_bold(y_depth-6, x_right-18);
1013 current_floor_ptr->grid_array[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1017 current_floor_ptr->grid_array[i][j].feat = f_tag_to_index("ARENA_GATE");
1018 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1023 * @brief 挑戦時闘技場への入場処理 / Town logic flow for generation of arena -KMW-
1026 static void generate_challenge_arena(void)
1033 current_floor_ptr->height = SCREEN_HGT;
1034 current_floor_ptr->width = SCREEN_WID;
1036 /* Start with solid walls */
1037 for (y = 0; y < MAX_HGT; y++)
1039 for (x = 0; x < MAX_WID; x++)
1041 /* Create "solid" perma-wall */
1042 place_solid_perm_bold(y, x);
1044 /* Illuminate and memorize the walls */
1045 current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1049 /* Then place some floors */
1050 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1052 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1054 /* Create empty floor */
1055 current_floor_ptr->grid_array[y][x].feat = feat_floor;
1061 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)))
1063 p_ptr->exit_bldg = TRUE;
1064 p_ptr->arena_number++;
1065 msg_print(_("相手は欠場した。あなたの不戦勝だ。", "The enemy is unable appear. You won by default."));
1071 * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
1074 static void build_battle(void)
1076 POSITION yval, y_height, y_depth, xval, x_left, x_right;
1079 yval = SCREEN_HGT / 2;
1080 xval = SCREEN_WID / 2;
1081 y_height = yval - 10;
1082 y_depth = yval + 10;
1084 x_right = xval + 32;
1086 for (i = y_height; i <= y_height + 5; i++)
1087 for (j = x_left; j <= x_right; j++)
1089 place_extra_perm_bold(i, j);
1090 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1092 for (i = y_depth; i >= y_depth - 3; i--)
1093 for (j = x_left; j <= x_right; j++)
1095 place_extra_perm_bold(i, j);
1096 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1098 for (j = x_left; j <= x_left + 17; j++)
1099 for (i = y_height; i <= y_depth; i++)
1101 place_extra_perm_bold(i, j);
1102 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1104 for (j = x_right; j >= x_right - 17; j--)
1105 for (i = y_height; i <= y_depth; i++)
1107 place_extra_perm_bold(i, j);
1108 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1111 place_extra_perm_bold(y_height+6, x_left+18);
1112 current_floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1113 place_extra_perm_bold(y_depth-4, x_left+18);
1114 current_floor_ptr->grid_array[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1115 place_extra_perm_bold(y_height+6, x_right-18);
1116 current_floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1117 place_extra_perm_bold(y_depth-4, x_right-18);
1118 current_floor_ptr->grid_array[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1120 for (i = y_height + 1; i <= y_height + 5; i++)
1121 for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
1123 current_floor_ptr->grid_array[i][j].feat = feat_permanent_glass_wall;
1128 current_floor_ptr->grid_array[i][j].feat = f_tag_to_index("BUILDING_3");
1129 current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1134 * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
1137 static void generate_gambling_arena(void)
1144 /* Start with solid walls */
1145 for (y = 0; y < MAX_HGT; y++)
1147 for (x = 0; x < MAX_WID; x++)
1149 /* Create "solid" perma-wall */
1150 place_solid_perm_bold(y, x);
1152 /* Illuminate and memorize the walls */
1153 current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1157 /* Then place some floors */
1158 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1160 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1162 /* Create empty floor */
1163 current_floor_ptr->grid_array[y][x].feat = feat_floor;
1169 for(i = 0; i < 4; i++)
1171 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));
1172 set_friendly(¤t_floor_ptr->m_list[current_floor_ptr->grid_array[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
1174 for(i = 1; i < m_max; i++)
1176 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1178 if (!monster_is_valid(m_ptr)) continue;
1180 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1181 update_monster(i, FALSE);
1186 * @brief 固定マップクエストのフロア生成 / Generate a quest level
1189 static void generate_fixed_floor(void)
1193 /* Start with perm walls */
1194 for (y = 0; y < current_floor_ptr->height; y++)
1196 for (x = 0; x < current_floor_ptr->width; x++)
1198 place_solid_perm_bold(y, x);
1202 /* Set the quest level */
1203 current_floor_ptr->base_level = quest[p_ptr->inside_quest].level;
1204 current_floor_ptr->dun_level = current_floor_ptr->base_level;
1205 current_floor_ptr->object_level = current_floor_ptr->base_level;
1206 current_floor_ptr->monster_level = current_floor_ptr->base_level;
1208 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1209 get_mon_num_prep(get_monster_hook(), NULL);
1211 init_flags = INIT_CREATE_DUNGEON;
1213 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1217 * @brief ダンジョン時のランダムフロア生成 / Make a real level
1218 * @return フロアの生成に成功したらTRUE
1220 static bool level_gen(concptr *why)
1222 int level_height, level_width;
1224 if ((always_small_levels || ironman_small_levels ||
1225 (one_in_(SMALL_LEVEL) && small_levels) ||
1226 (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER) ||
1227 (d_info[p_ptr->dungeon_idx].flags1 & DF1_SMALLEST)) &&
1228 !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BIG))
1230 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_SMALLEST)
1235 else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
1244 level_height = randint1(MAX_HGT/SCREEN_HGT);
1245 level_width = randint1(MAX_WID/SCREEN_WID);
1247 while ((level_height == MAX_HGT/SCREEN_HGT) && (level_width == MAX_WID/SCREEN_WID));
1250 current_floor_ptr->height = level_height * SCREEN_HGT;
1251 current_floor_ptr->width = level_width * SCREEN_WID;
1253 /* Assume illegal panel */
1254 panel_row_min = current_floor_ptr->height;
1255 panel_col_min = current_floor_ptr->width;
1257 msg_format_wizard(CHEAT_DUNGEON,
1258 _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."),
1259 current_floor_ptr->width, current_floor_ptr->height);
1264 current_floor_ptr->height = MAX_HGT;
1265 current_floor_ptr->width = MAX_WID;
1267 /* Assume illegal panel */
1268 panel_row_min = current_floor_ptr->height;
1269 panel_col_min = current_floor_ptr->width;
1272 /* Make a dungeon */
1275 *why = _("ダンジョン生成に失敗", "could not place player");
1282 * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after current_floor_ptr->grid_array generation
1285 void wipe_generate_random_floor_flags(void)
1289 for (y = 0; y < current_floor_ptr->height; y++)
1291 for (x = 0; x < current_floor_ptr->width; x++)
1293 /* Wipe unused flags */
1294 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
1298 if (current_floor_ptr->dun_level)
1300 for (y = 1; y < current_floor_ptr->height - 1; y++)
1302 for (x = 1; x < current_floor_ptr->width - 1; x++)
1304 /* There might be trap */
1305 current_floor_ptr->grid_array[y][x].info |= CAVE_UNSAFE;
1312 * @brief フロアの全情報を初期化する / Clear and empty the current_floor_ptr->grid_array
1315 void clear_cave(void)
1320 /* Very simplified version of wipe_o_list() */
1321 (void)C_WIPE(current_floor_ptr->o_list, o_max, object_type);
1325 /* Very simplified version of wipe_m_list() */
1326 for (i = 1; i < max_r_idx; i++)
1327 r_info[i].cur_num = 0;
1328 (void)C_WIPE(current_floor_ptr->m_list, m_max, monster_type);
1331 for (i = 0; i < MAX_MTIMED; i++) current_floor_ptr->mproc_max[i] = 0;
1333 /* Pre-calc cur_num of pets in party_mon[] */
1334 precalc_cur_num_of_pet();
1337 /* Start with a blank current_floor_ptr->grid_array */
1338 for (y = 0; y < MAX_HGT; y++)
1340 for (x = 0; x < MAX_WID; x++)
1342 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1355 /* Mega-Hack -- no player yet */
1356 p_ptr->x = p_ptr->y = 0;
1358 /* Set the base level */
1359 current_floor_ptr->base_level = current_floor_ptr->dun_level;
1361 /* Reset the monster generation level */
1362 current_floor_ptr->monster_level = current_floor_ptr->base_level;
1364 /* Reset the object generation level */
1365 current_floor_ptr->object_level = current_floor_ptr->base_level;
1370 * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
1372 * @note Hack -- regenerate any "overflow" levels
1374 void generate_random_floor(void)
1378 /* Fill the arrays of floors and walls in the good proportions */
1379 set_floor_and_wall(p_ptr->dungeon_idx);
1382 for (num = 0; TRUE; num++)
1388 /* Clear and empty the current_floor_ptr->grid_array */
1391 /* Build the arena -KMW- */
1392 if (p_ptr->inside_arena)
1395 generate_challenge_arena();
1398 /* Build the battle -KMW- */
1399 else if (p_ptr->inside_battle)
1402 generate_gambling_arena();
1405 else if (p_ptr->inside_quest)
1407 generate_fixed_floor();
1410 /* Build the town */
1411 else if (!current_floor_ptr->dun_level)
1413 /* Make the wilderness */
1414 if (p_ptr->wild_mode) wilderness_gen_small();
1415 else wilderness_gen();
1418 /* Build a real level */
1421 okay = level_gen(&why);
1425 /* Prevent object over-flow */
1426 if (o_max >= current_floor_ptr->max_o_idx)
1428 why = _("アイテムが多すぎる", "too many objects");
1431 /* Prevent monster over-flow */
1432 else if (m_max >= current_floor_ptr->max_m_idx)
1434 why = _("モンスターが多すぎる", "too many monsters");
1441 if (why) msg_format(_("生成やり直し(%s)", "Generation restarted (%s)"), why);
1447 /* Glow deep lava and building entrances */
1448 glow_deep_lava_and_bldg();
1451 p_ptr->enter_dungeon = FALSE;
1453 wipe_generate_random_floor_flags();
1457 * @brief build_tunnel用に通路を掘るための方向をランダムに決める / Pick a random direction
1458 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
1459 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
1462 static void rand_dir(POSITION *rdir, POSITION *cdir)
1464 /* Pick a random direction */
1465 int i = randint0(4);
1467 /* Extract the dy/dx components */
1473 * @brief build_tunnel用に通路を掘るための方向を位置関係通りに決める / Always picks a correct direction
1474 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
1475 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
1482 static void correct_dir(POSITION *rdir, POSITION *cdir, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
1484 /* Extract vertical and horizontal directions */
1485 *rdir = (y1 == y2) ? 0 : (y1 < y2) ? 1 : -1;
1486 *cdir = (x1 == x2) ? 0 : (x1 < x2) ? 1 : -1;
1488 /* Never move diagonally */
1491 if (randint0(100) < 50)
1499 * @brief 部屋間のトンネルを生成する / Constructs a tunnel between two points
1504 * @return 生成に成功したらTRUEを返す
1506 * This function must be called BEFORE any streamers are created,\n
1507 * since we use the special "granite wall" sub-types to keep track\n
1508 * of legal places for corridors to pierce rooms.\n
1510 * We use "door_flag" to prevent excessive construction of doors\n
1511 * along overlapping corridors.\n
1513 * We queue the tunnel grids to prevent door creation along a corridor\n
1514 * which intersects itself.\n
1516 * We queue the wall piercing grids to prevent a corridor from leaving\n
1517 * a room and then coming back in through the same entrance.\n
1519 * We "pierce" grids which are "outer" walls of rooms, and when we\n
1520 * do so, we change all adjacent "outer" walls of rooms into "solid"\n
1521 * walls so that no two corridors may use adjacent grids for exits.\n
1523 * The "solid" wall check prevents corridors from "chopping" the\n
1524 * corners of rooms off, as well as "silly" door placement, and\n
1525 * "excessively wide" room entrances.\n
1529 * inner -- inner room walls\n
1530 * outer -- outer room walls\n
1531 * solid -- solid room walls\n
1533 bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
1536 POSITION tmp_row, tmp_col;
1537 POSITION row_dir, col_dir;
1538 POSITION start_row, start_col;
1539 int main_loop_count = 0;
1541 bool door_flag = FALSE;
1545 /* Save the starting location */
1549 /* Start out in the correct direction */
1550 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1552 /* Keep going until done (or bored) */
1553 while ((row1 != row2) || (col1 != col2))
1555 /* Mega-Hack -- Paranoia -- prevent infinite loops */
1556 if (main_loop_count++ > 2000) return FALSE;
1558 /* Allow bends in the tunnel */
1559 if (randint0(100) < dun_tun_chg)
1561 /* Acquire the correct direction */
1562 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
1564 /* Random direction */
1565 if (randint0(100) < dun_tun_rnd)
1567 rand_dir(&row_dir, &col_dir);
1571 /* Get the next location */
1572 tmp_row = row1 + row_dir;
1573 tmp_col = col1 + col_dir;
1576 /* Extremely Important -- do not leave the dungeon */
1577 while (!in_bounds(tmp_row, tmp_col))
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);
1588 /* Get the next location */
1589 tmp_row = row1 + row_dir;
1590 tmp_col = col1 + col_dir;
1593 g_ptr = ¤t_floor_ptr->grid_array[tmp_row][tmp_col];
1595 /* Avoid "solid" walls */
1596 if (is_solid_grid(g_ptr)) continue;
1598 /* Pierce "outer" walls of rooms */
1599 if (is_outer_grid(g_ptr))
1601 /* Acquire the "next" location */
1602 y = tmp_row + row_dir;
1603 x = tmp_col + col_dir;
1605 /* Hack -- Avoid outer/solid walls */
1606 if (is_outer_bold(y, x)) continue;
1607 if (is_solid_bold(y, x)) continue;
1609 /* Accept this location */
1613 /* Save the wall location */
1614 if (dun->wall_n < WALL_MAX)
1616 dun->wall[dun->wall_n].y = row1;
1617 dun->wall[dun->wall_n].x = col1;
1622 /* Forbid re-entry near this piercing */
1623 for (y = row1 - 1; y <= row1 + 1; y++)
1625 for (x = col1 - 1; x <= col1 + 1; x++)
1627 /* Convert adjacent "outer" walls as "solid" walls */
1628 if (is_outer_bold(y, x))
1630 /* Change the wall to a "solid" wall */
1631 place_solid_noperm_bold(y, x);
1637 /* Travel quickly through rooms */
1638 else if (g_ptr->info & (CAVE_ROOM))
1640 /* Accept the location */
1645 /* Tunnel through all other walls */
1646 else if (is_extra_grid(g_ptr) || is_inner_grid(g_ptr) || is_solid_grid(g_ptr))
1648 /* Accept this location */
1652 /* Save the tunnel location */
1653 if (dun->tunn_n < TUNN_MAX)
1655 dun->tunn[dun->tunn_n].y = row1;
1656 dun->tunn[dun->tunn_n].x = col1;
1661 /* Allow door in next grid */
1665 /* Handle corridor intersections or overlaps */
1668 /* Accept the location */
1672 /* Collect legal door locations */
1675 /* Save the door location */
1676 if (dun->door_n < DOOR_MAX)
1678 dun->door[dun->door_n].y = row1;
1679 dun->door[dun->door_n].x = col1;
1684 /* No door in next grid */
1688 /* Hack -- allow pre-emptive tunnel termination */
1689 if (randint0(100) >= dun_tun_con)
1691 /* Distance between row1 and start_row */
1692 tmp_row = row1 - start_row;
1693 if (tmp_row < 0) tmp_row = (-tmp_row);
1695 /* Distance between col1 and start_col */
1696 tmp_col = col1 - start_col;
1697 if (tmp_col < 0) tmp_col = (-tmp_col);
1699 /* Terminate the tunnel */
1700 if ((tmp_row > 10) || (tmp_col > 10)) break;
1710 * @brief トンネル生成のための基準点を指定する。
1711 * @param x 基準点を指定するX座標の参照ポインタ、適時値が修正される。
1712 * @param y 基準点を指定するY座標の参照ポインタ、適時値が修正される。
1713 * @param affectwall (調査中)
1716 * This routine adds the square to the tunnel\n
1717 * It also checks for SOLID walls - and returns a nearby\n
1718 * non-SOLID square in (x,y) so that a simple avoiding\n
1719 * routine can be used. The returned boolean value reflects\n
1720 * whether or not this routine hit a SOLID wall.\n
1722 * "affectwall" toggles whether or not this new square affects\n
1723 * the boundaries of rooms. - This is used by the catacomb\n
1725 * @todo 特に詳細な処理の意味を調査すべし
1727 static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
1731 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
1733 if (!in_bounds(*y, *x)) return TRUE;
1735 if (is_inner_grid(g_ptr))
1740 if (is_extra_bold(*y, *x))
1742 /* Save the tunnel location */
1743 if (dun->tunn_n < TUNN_MAX)
1745 dun->tunn[dun->tunn_n].y = *y;
1746 dun->tunn[dun->tunn_n].x = *x;
1754 if (is_floor_bold(*y, *x))
1756 /* Don't do anything */
1760 if (is_outer_grid(g_ptr) && affectwall)
1762 /* Save the wall location */
1763 if (dun->wall_n < WALL_MAX)
1765 dun->wall[dun->wall_n].y = *y;
1766 dun->wall[dun->wall_n].x = *x;
1771 /* Forbid re-entry near this piercing */
1772 for (j = *y - 1; j <= *y + 1; j++)
1774 for (i = *x - 1; i <= *x + 1; i++)
1776 /* Convert adjacent "outer" walls as "solid" walls */
1777 if (is_outer_bold(j, i))
1779 /* Change the wall to a "solid" wall */
1780 place_solid_noperm_bold(j, i);
1785 /* Clear mimic type */
1786 current_floor_ptr->grid_array[*y][*x].mimic = 0;
1788 place_floor_bold(*y, *x);
1793 if (is_solid_grid(g_ptr) && affectwall)
1795 /* cannot place tunnel here - use a square to the side */
1797 /* find usable square and return value in (x,y) */
1803 while ((i > 0) && is_solid_bold(*y + dy, *x + dx))
1805 dy = randint0(3) - 1;
1806 dx = randint0(3) - 1;
1808 if (!in_bounds(*y + dy, *x + dx))
1819 /* Failed for some reason: hack - ignore the solidness */
1820 place_outer_grid(g_ptr);
1825 /* Give new, acceptable coordinate. */
1837 * @brief 外壁を削って「カタコンベ状」の通路を作成する / This routine creates the catacomb-like tunnels by removing extra rock.
1842 * Note that this routine is only called on "even" squares - so it gives
1843 * a natural checkerboard pattern.
1845 static void create_cata_tunnel(POSITION x, POSITION y)
1852 set_tunnel(&x1, &y1, FALSE);
1856 set_tunnel(&x1, &y1, FALSE);
1860 set_tunnel(&x1, &y1, FALSE);
1864 set_tunnel(&x1, &y1, FALSE);
1869 * @brief トンネル生成処理(詳細調査中)/ This routine does the bulk of the work in creating the new types of tunnels.
1873 * It is designed to use very simple algorithms to go from (x1,y1) to (x2,y2)\n
1874 * It doesn't need to add any complexity - straight lines are fine.\n
1875 * The SOLID walls are avoided by a recursive algorithm which tries random ways\n
1876 * around the obstical until it works. The number of itterations is counted, and it\n
1877 * this gets too large the routine exits. This should stop any crashes - but may leave\n
1878 * small gaps in the tunnel where there are too many SOLID walls.\n
1880 * Type 1 tunnels are extremely simple - straight line from A to B. This is only used\n
1881 * as a part of the dodge SOLID walls algorithm.\n
1883 * Type 2 tunnels are made of two straight lines at right angles. When this is used with\n
1884 * short line segments it gives the "cavelike" tunnels seen deeper in the dungeon.\n
1886 * Type 3 tunnels are made of two straight lines like type 2, but with extra rock removed.\n
1887 * This, when used with longer line segments gives the "catacomb-like" tunnels seen near\n
1890 static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
1896 /* Check for early exit */
1897 if (!(*fail)) return;
1899 length = distance(x1, y1, x2, y2);
1903 if ((type == 1) && (length != 0))
1906 for (i = 0; i <= length; i++)
1908 x = x1 + i * (x2 - x1) / length;
1909 y = y1 + i * (y2 - y1) / length;
1910 if (!set_tunnel(&x, &y, TRUE))
1914 /* This isn't working - probably have an infinite loop */
1919 /* solid wall - so try to go around */
1920 short_seg_hack(x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
1921 short_seg_hack(x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
1925 else if ((type == 2) || (type == 3))
1929 for (i = x1; i <= x2; i++)
1933 if (!set_tunnel(&x, &y, TRUE))
1935 /* solid wall - so try to go around */
1936 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1937 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1939 if ((type == 3) && ((x + y) % 2))
1941 create_cata_tunnel(i, y1);
1947 for (i = x2; i <= x1; i++)
1951 if (!set_tunnel(&x, &y, TRUE))
1953 /* solid wall - so try to go around */
1954 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1955 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1957 if ((type == 3) && ((x + y) % 2))
1959 create_cata_tunnel(i, y1);
1966 for (i = y1; i <= y2; i++)
1970 if (!set_tunnel(&x, &y, TRUE))
1972 /* solid wall - so try to go around */
1973 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1974 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1976 if ((type == 3) && ((x + y) % 2))
1978 create_cata_tunnel(x2, i);
1984 for (i = y2; i <= y1; i++)
1988 if (!set_tunnel(&x, &y, TRUE))
1990 /* solid wall - so try to go around */
1991 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1992 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1994 if ((type == 3) && ((x + y) % 2))
1996 create_cata_tunnel(x2, i);
2005 * @brief 特定の壁(永久壁など)を避けながら部屋間の通路を作成する / This routine maps a path from (x1, y1) to (x2, y2) avoiding SOLID walls.
2009 * Permanent rock is ignored in this path finding- sometimes there is no\n
2010 * path around anyway -so there will be a crash if we try to find one.\n
2011 * This routine is much like the river creation routine in Zangband.\n
2012 * It works by dividing a line segment into two. The segments are divided\n
2013 * until they are less than "cutoff" - when the corresponding routine from\n
2014 * "short_seg_hack" is called.\n
2015 * Note it is VERY important that the "stop if hit another passage" logic\n
2016 * stays as is. Without this the dungeon turns into Swiss Cheese...\n
2018 bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
2020 POSITION x3, y3, dx, dy;
2021 POSITION changex, changey;
2024 bool retval, firstsuccede;
2027 length = distance(x1, y1, x2, y2);
2029 if (length > cutoff)
2032 * Divide path in half and call routine twice.
2037 /* perturbation perpendicular to path */
2038 changex = (randint0(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
2039 changey = (randint0(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
2041 /* Work out "mid" ponit */
2042 x3 = x1 + dx + changex;
2043 y3 = y1 + dy + changey;
2045 /* See if in bounds - if not - do not perturb point */
2046 if (!in_bounds(y3, x3))
2052 g_ptr = ¤t_floor_ptr->grid_array[y3][x3];
2053 if (is_solid_grid(g_ptr))
2055 /* move midpoint a bit to avoid problem. */
2061 while ((i > 0) && is_solid_bold(y3 + dy, x3 + dx))
2063 dy = randint0(3) - 1;
2064 dx = randint0(3) - 1;
2065 if (!in_bounds(y3 + dy, x3 + dx))
2075 /* Failed for some reason: hack - ignore the solidness */
2076 place_outer_bold(y3, x3);
2082 g_ptr = ¤t_floor_ptr->grid_array[y3][x3];
2085 if (is_floor_grid(g_ptr))
2087 if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
2089 if ((current_floor_ptr->grid_array[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
2091 /* do second half only if works + if have hit a room */
2092 retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
2096 /* have hit another tunnel - make a set of doors here */
2099 /* Save the door location */
2100 if (dun->door_n < DOOR_MAX)
2102 dun->door[dun->door_n].y = y3;
2103 dun->door[dun->door_n].x = x3;
2108 firstsuccede = TRUE;
2112 /* false- didn't work all the way */
2114 firstsuccede = FALSE;
2119 /* tunnel through walls */
2120 if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
2122 retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
2123 firstsuccede = TRUE;
2127 /* false- didn't work all the way */
2129 firstsuccede = FALSE;
2134 /* only do this if the first half has worked */
2135 set_tunnel(&x3, &y3, TRUE);
2137 /* return value calculated above */
2142 /* Do a short segment */
2144 short_seg_hack(x1, y1, x2, y2, type, 0, &retval);
2146 /* Hack - ignore return value so avoid infinite loops */