3 * @brief ダンジョンの生成処理の基幹部分 / low-level dungeon creation primitives
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
8 * This software may be copied and distributed for educational, research,\n
9 * and not for profit purposes provided that this copyright and statement\n
10 * are included in all such copies. Other copyrights may also apply.\n
12 * 2014 Deskull Doxygen向けのコメント整理\n
22 * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
23 * @return 配置に成功したらTRUEを返す
25 bool new_player_spot(void)
27 POSITION y = 0, x = 0;
28 int max_attempts = 10000;
33 /* Place the player */
34 while (max_attempts--)
36 /* Pick a legal spot */
37 y = (POSITION)rand_range(1, cur_hgt - 2);
38 x = (POSITION)rand_range(1, cur_wid - 2);
42 /* Must be a "naked" floor grid */
43 if (c_ptr->m_idx) continue;
46 f_ptr = &f_info[c_ptr->feat];
48 if (max_attempts > 5000) /* Rule 1 */
50 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
54 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
55 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
58 /* Refuse to start on anti-teleport grids in dungeon */
59 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
61 if (!player_can_enter(c_ptr->feat, 0)) continue;
62 if (!in_bounds(y, x)) continue;
64 /* Refuse to start on anti-teleport grids */
65 if (c_ptr->info & (CAVE_ICKY)) continue;
71 if (max_attempts < 1) /* Should be -1, actually if we failed... */
74 /* Save the new player grid */
84 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
85 * @param y 配置を試みたいマスのY座標
86 * @param x 配置を試みたいマスのX座標
89 void place_random_stairs(POSITION y, POSITION x)
91 bool up_stairs = TRUE;
92 bool down_stairs = TRUE;
97 if (!is_floor_grid(c_ptr) || c_ptr->o_idx) return;
104 if (ironman_downward)
108 if (dun_level >= d_info[dungeon_type].maxdepth)
112 if (quest_number(dun_level) && (dun_level > 1))
115 /* We can't place both */
116 if (down_stairs && up_stairs)
118 /* Choose a staircase randomly */
119 if (randint0(100) < 50)
125 /* Place the stairs */
127 place_up_stairs(y, x);
128 else if (down_stairs)
129 place_down_stairs(y, x);
133 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
134 * @param y ドアの配置を試みたいマスのY座標
135 * @param x ドアの配置を試みたいマスのX座標
136 * @param room 部屋に接している場合向けのドア生成か否か
139 void place_random_door(POSITION y, POSITION x, bool room)
142 s16b feat = feat_none;
143 cave_type *c_ptr = &cave[y][x];
145 /* Initialize mimic info */
148 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
150 place_floor_bold(y, x);
154 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
155 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
156 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
158 /* Choose an object */
159 tmp = randint0(1000);
161 /* Open doors (300/1000) */
164 /* Create open door */
165 feat = feat_door[type].open;
168 /* Broken doors (100/1000) */
171 /* Create broken door */
172 feat = feat_door[type].broken;
175 /* Secret doors (200/1000) */
178 /* Create secret door */
179 place_closed_door(y, x, type);
181 if (type != DOOR_CURTAIN)
183 /* Hide. If on the edge of room, use outer wall. */
184 c_ptr->mimic = room ? feat_wall_outer : fill_type[randint0(100)];
186 /* Floor type terrain cannot hide a door */
187 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
189 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
191 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
198 /* Closed, locked, or stuck doors (400/1000) */
199 else place_closed_door(y, x, type);
203 if (feat != feat_none)
205 set_cave_feat(y, x, feat);
209 place_floor_bold(y, x);
213 delete_monster(y, x);
217 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
218 * @param y ドアの配置を試みたいマスのY座標
219 * @param x ドアの配置を試みたいマスのX座標
220 * @param type ドアの地形ID
223 void place_closed_door(POSITION y, POSITION x, int type)
226 s16b feat = feat_none;
228 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
230 place_floor_bold(y, x);
234 /* Choose an object */
237 /* Closed doors (300/400) */
240 /* Create closed door */
241 feat = feat_door[type].closed;
244 /* Locked doors (99/400) */
247 /* Create locked door */
248 feat = feat_locked_door_random(type);
251 /* Stuck doors (1/400) */
254 /* Create jammed door */
255 feat = feat_jammed_door_random(type);
258 if (feat != feat_none)
260 cave_set_feat(y, x, feat);
262 /* Now it is not floor */
263 cave[y][x].info &= ~(CAVE_MASK);
267 place_floor_bold(y, x);
272 * @brief 鍵のかかったドアを配置する
273 * @param y 配置したいフロアのY座標
274 * @param x 配置したいフロアのX座標
277 void place_locked_door(POSITION y, POSITION x)
279 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
281 place_floor_bold(y, x);
285 set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
286 cave[y][x].info &= ~(CAVE_FLOOR);
287 delete_monster(y, x);
294 * @param y 配置したいフロアのY座標
295 * @param x 配置したいフロアのX座標
296 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
299 void place_secret_door(POSITION y, POSITION x, int type)
301 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
303 place_floor_bold(y, x);
307 cave_type *c_ptr = &cave[y][x];
309 if (type == DOOR_DEFAULT)
311 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
312 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
313 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
316 /* Create secret door */
317 place_closed_door(y, x, type);
319 if (type != DOOR_CURTAIN)
321 /* Hide by inner wall because this is used in rooms only */
322 c_ptr->mimic = feat_wall_inner;
324 /* Floor type terrain cannot hide a door */
325 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
327 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
329 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
335 c_ptr->info &= ~(CAVE_FLOOR);
336 delete_monster(y, x);
341 * Routine used by the random vault creators to add a door to a location
342 * Note that range checking has to be done in the calling routine.
344 * The doors must be INSIDE the allocated region.
346 void add_door(POSITION x, POSITION y)
348 /* Need to have a wall in the center square */
349 if (!is_outer_bold(y, x)) return;
360 if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
361 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
364 place_secret_door(y, x, DOOR_DEFAULT);
366 /* set boundarys so don't get wide doors */
367 place_solid_bold(y, x - 1);
368 place_solid_bold(y, x + 1);
377 * where x = don't care
380 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
381 is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
384 place_secret_door(y, x, DOOR_DEFAULT);
386 /* set boundarys so don't get wide doors */
387 place_solid_bold(y - 1, x);
388 place_solid_bold(y + 1, x);
393 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
394 * @param y1 基準となるマスのY座標
395 * @param x1 基準となるマスのX座標
397 * @note Assumes "in_bounds(y1, x1)"
399 * XXX XXX This routine currently only counts actual "empty floor"\n
400 * grids which are not in rooms. We might want to also count stairs,\n
401 * open doors, closed doors, etc.
403 static int next_to_corr(int y1, int x1)
409 /* Scan adjacent grids */
410 for (i = 0; i < 4; i++)
412 /* Extract the location */
416 /* Access the grid */
419 /* Skip non floors */
420 if (cave_have_flag_grid(c_ptr, FF_WALL)) continue;
422 /* Skip non "empty floor" grids */
423 if (!is_floor_grid(c_ptr))
426 /* Skip grids inside rooms */
427 if (c_ptr->info & (CAVE_ROOM)) continue;
429 /* Count these grids */
433 /* Return the number of corridors */
438 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
439 * @param y 判定を行いたいマスのY座標
440 * @param x 判定を行いたいマスのX座標
441 * @return ドアを設置可能ならばTRUEを返す
442 * @note Assumes "in_bounds(y1, x1)"
445 * Assumes "in_bounds(y, x)"\n
447 static bool possible_doorway(int y, int x)
449 /* Count the adjacent corridors */
450 if (next_to_corr(y, x) >= 2)
453 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
454 cave_have_flag_bold(y + 1, x, FF_WALL))
459 /* Check Horizontal */
460 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
461 cave_have_flag_bold(y, x + 1, FF_WALL))
472 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
473 * @param y 設置を行いたいマスのY座標
474 * @param x 設置を行いたいマスのX座標
477 void try_door(POSITION y, POSITION x)
480 if (!in_bounds(y, x)) return;
483 if (cave_have_flag_bold(y, x, FF_WALL)) return;
485 /* Ignore room grids */
486 if (cave[y][x].info & (CAVE_ROOM)) return;
488 /* Occasional door (if allowed) */
489 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
492 place_random_door(y, x, FALSE);
498 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
499 * @param x1 長方形の左端X座標(-1)
500 * @param x2 長方形の右端X座標(+1)
501 * @param y1 長方形の上端Y座標(-1)
502 * @param y2 長方形の下端Y座標(+1)
506 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
510 /* Place a full floor under the room */
511 for (y = y1 - 1; y <= y2 + 1; y++)
513 for (x = x1 - 1; x <= x2 + 1; x++)
515 place_floor_bold(y, x);
516 add_cave_info(y, x, CAVE_ROOM);
517 if (light) add_cave_info(y, x, CAVE_GLOW);
524 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
525 * @param x1 長方形の左端X座標(-1)
526 * @param x2 長方形の右端X座標(+1)
527 * @param y1 長方形の上端Y座標(-1)
528 * @param y2 長方形の下端Y座標(+1)
532 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
536 place_floor(x1, x2, y1, y2, light);
538 /* Walls around the room */
539 for (y = y1 - 1; y <= y2 + 1; y++)
541 place_outer_bold(y, x1 - 1);
542 place_outer_bold(y, x2 + 1);
544 for (x = x1 - 1; x <= x2 + 1; x++)
546 place_outer_bold(y1 - 1, x);
547 place_outer_bold(y2 + 1, x);
553 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
554 * @param y 配置したい中心マスのY座標
555 * @param x 配置したい中心マスのX座標
559 * Only really called by some of the "vault" routines.
561 void vault_objects(POSITION y, POSITION x, int num)
564 int i = 0, j = y, k = x;
569 /* Attempt to place 'num' objects */
570 for (; num > 0; --num)
572 /* Try up to 11 spots looking for empty space */
573 for (i = 0; i < 11; ++i)
575 /* Pick a random location */
576 while (dummy < SAFE_MAX_ATTEMPTS)
578 j = rand_spread(y, 2);
579 k = rand_spread(x, 3);
581 if (!in_bounds(j, k)) continue;
586 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
588 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
592 /* Require "clean" floor space */
594 if (!is_floor_grid(c_ptr) || c_ptr->o_idx) continue;
597 if (randint0(100) < 75)
599 place_object(j, k, 0L);
608 /* Placement accomplished */
615 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
616 * @param y トラップを配置したいマスの中心Y座標
617 * @param x トラップを配置したいマスの中心X座標
618 * @param yd Y方向の配置分散マス数
619 * @param xd X方向の配置分散マス数
622 * Only really called by some of the "vault" routines.
624 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
626 int count = 0, y1 = y, x1 = x;
632 for (count = 0; count <= 5; count++)
635 while (dummy < SAFE_MAX_ATTEMPTS)
637 y1 = rand_spread(y, yd);
638 x1 = rand_spread(x, xd);
640 if (!in_bounds(y1, x1)) continue;
644 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
646 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
649 /* Require "naked" floor grids */
650 c_ptr = &cave[y1][x1];
651 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
662 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
663 * @param y トラップを配置したいマスの中心Y座標
664 * @param x トラップを配置したいマスの中心X座標
665 * @param yd Y方向の配置分散マス数
666 * @param xd X方向の配置分散マス数
667 * @param num 配置したいトラップの数
670 * Only really called by some of the "vault" routines.
672 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
676 for (i = 0; i < num; i++)
678 vault_trap_aux(y, x, yd, xd);
683 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
684 * @param y1 モンスターを配置したいマスの中心Y座標
685 * @param x1 モンスターを配置したいマスの中心X座標
686 * @param num 配置したいモンスターの数
689 * Only really called by some of the "vault" routines.
691 void vault_monsters(POSITION y1, POSITION x1, int num)
697 /* Try to summon "num" monsters "near" the given location */
698 for (k = 0; k < num; k++)
700 /* Try nine locations */
701 for (i = 0; i < 9; i++)
705 /* Pick a nearby location */
706 scatter(&y, &x, y1, x1, d, 0);
708 /* Require "empty" floor grids */
710 if (!cave_empty_grid(c_ptr)) continue;
712 /* Place the monster (allow groups) */
713 monster_level = base_level + 2;
714 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
715 monster_level = base_level;
722 * @brief build_tunnel用に通路を掘るための方向を位置関係通りに決める / Always picks a correct direction
723 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
724 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
731 void correct_dir(int *rdir, int *cdir, int y1, int x1, int y2, int x2)
733 /* Extract vertical and horizontal directions */
734 *rdir = (y1 == y2) ? 0 : (y1 < y2) ? 1 : -1;
735 *cdir = (x1 == x2) ? 0 : (x1 < x2) ? 1 : -1;
737 /* Never move diagonally */
740 if (randint0(100) < 50)
748 * @brief build_tunnel用に通路を掘るための方向をランダムに決める / Pick a random direction
749 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
750 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
753 void rand_dir(int *rdir, int *cdir)
755 /* Pick a random direction */
758 /* Extract the dy/dx components */
764 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
765 * @param x チェックするマスのX座標
766 * @param y チェックするマスのY座標
767 * @return 床系地形ならばTRUE
769 bool get_is_floor(int x, int y)
771 if (!in_bounds(y, x))
777 /* Do the real check */
778 if (is_floor_bold(y, x)) return (TRUE);
784 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
785 * @param x 地形を変えたいマスのX座標
786 * @param y 地形を変えたいマスのY座標
789 void set_floor(int x, int y)
791 if (!in_bounds(y, x))
797 if (cave[y][x].info & CAVE_ROOM)
799 /* A room border don't touch. */
803 /* Set to be floor if is a wall (don't touch lakes). */
804 if (is_extra_bold(y, x))
805 place_floor_bold(y, x);
810 * @brief 部屋間のトンネルを生成する / Constructs a tunnel between two points
815 * @return 生成に成功したらTRUEを返す
817 * This function must be called BEFORE any streamers are created,\n
818 * since we use the special "granite wall" sub-types to keep track\n
819 * of legal places for corridors to pierce rooms.\n
821 * We use "door_flag" to prevent excessive construction of doors\n
822 * along overlapping corridors.\n
824 * We queue the tunnel grids to prevent door creation along a corridor\n
825 * which intersects itself.\n
827 * We queue the wall piercing grids to prevent a corridor from leaving\n
828 * a room and then coming back in through the same entrance.\n
830 * We "pierce" grids which are "outer" walls of rooms, and when we\n
831 * do so, we change all adjacent "outer" walls of rooms into "solid"\n
832 * walls so that no two corridors may use adjacent grids for exits.\n
834 * The "solid" wall check prevents corridors from "chopping" the\n
835 * corners of rooms off, as well as "silly" door placement, and\n
836 * "excessively wide" room entrances.\n
840 * inner -- inner room walls\n
841 * outer -- outer room walls\n
842 * solid -- solid room walls\n
844 bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
847 POSITION tmp_row, tmp_col;
848 int row_dir, col_dir;
849 int start_row, start_col;
850 int main_loop_count = 0;
852 bool door_flag = FALSE;
856 /* Save the starting location */
860 /* Start out in the correct direction */
861 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
863 /* Keep going until done (or bored) */
864 while ((row1 != row2) || (col1 != col2))
866 /* Mega-Hack -- Paranoia -- prevent infinite loops */
867 if (main_loop_count++ > 2000) return FALSE;
869 /* Allow bends in the tunnel */
870 if (randint0(100) < dun_tun_chg)
872 /* Acquire the correct direction */
873 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
875 /* Random direction */
876 if (randint0(100) < dun_tun_rnd)
878 rand_dir(&row_dir, &col_dir);
882 /* Get the next location */
883 tmp_row = row1 + row_dir;
884 tmp_col = col1 + col_dir;
887 /* Extremely Important -- do not leave the dungeon */
888 while (!in_bounds(tmp_row, tmp_col))
890 /* Acquire the correct direction */
891 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
893 /* Random direction */
894 if (randint0(100) < dun_tun_rnd)
896 rand_dir(&row_dir, &col_dir);
899 /* Get the next location */
900 tmp_row = row1 + row_dir;
901 tmp_col = col1 + col_dir;
905 /* Access the location */
906 c_ptr = &cave[tmp_row][tmp_col];
908 /* Avoid "solid" walls */
909 if (is_solid_grid(c_ptr)) continue;
911 /* Pierce "outer" walls of rooms */
912 if (is_outer_grid(c_ptr))
914 /* Acquire the "next" location */
915 y = tmp_row + row_dir;
916 x = tmp_col + col_dir;
918 /* Hack -- Avoid outer/solid walls */
919 if (is_outer_bold(y, x)) continue;
920 if (is_solid_bold(y, x)) continue;
922 /* Accept this location */
923 row1 = (POSITION)tmp_row;
924 col1 = (POSITION)tmp_col;
926 /* Save the wall location */
927 if (dun->wall_n < WALL_MAX)
929 dun->wall[dun->wall_n].y = row1;
930 dun->wall[dun->wall_n].x = col1;
935 /* Forbid re-entry near this piercing */
936 for (y = row1 - 1; y <= row1 + 1; y++)
938 for (x = col1 - 1; x <= col1 + 1; x++)
940 /* Convert adjacent "outer" walls as "solid" walls */
941 if (is_outer_bold(y, x))
943 /* Change the wall to a "solid" wall */
944 place_solid_noperm_bold(y, x);
950 /* Travel quickly through rooms */
951 else if (c_ptr->info & (CAVE_ROOM))
953 /* Accept the location */
958 /* Tunnel through all other walls */
959 else if (is_extra_grid(c_ptr) || is_inner_grid(c_ptr) || is_solid_grid(c_ptr))
961 /* Accept this location */
965 /* Save the tunnel location */
966 if (dun->tunn_n < TUNN_MAX)
968 dun->tunn[dun->tunn_n].y = row1;
969 dun->tunn[dun->tunn_n].x = col1;
974 /* Allow door in next grid */
978 /* Handle corridor intersections or overlaps */
981 /* Accept the location */
985 /* Collect legal door locations */
988 /* Save the door location */
989 if (dun->door_n < DOOR_MAX)
991 dun->door[dun->door_n].y = row1;
992 dun->door[dun->door_n].x = col1;
997 /* No door in next grid */
1001 /* Hack -- allow pre-emptive tunnel termination */
1002 if (randint0(100) >= dun_tun_con)
1004 /* Distance between row1 and start_row */
1005 tmp_row = row1 - start_row;
1006 if (tmp_row < 0) tmp_row = (-tmp_row);
1008 /* Distance between col1 and start_col */
1009 tmp_col = col1 - start_col;
1010 if (tmp_col < 0) tmp_col = (-tmp_col);
1012 /* Terminate the tunnel */
1013 if ((tmp_row > 10) || (tmp_col > 10)) break;
1023 * @brief トンネル生成のための基準点を指定する。
1024 * @param x 基準点を指定するX座標の参照ポインタ、適時値が修正される。
1025 * @param y 基準点を指定するY座標の参照ポインタ、適時値が修正される。
1026 * @param affectwall (調査中)
1029 * This routine adds the square to the tunnel\n
1030 * It also checks for SOLID walls - and returns a nearby\n
1031 * non-SOLID square in (x,y) so that a simple avoiding\n
1032 * routine can be used. The returned boolean value reflects\n
1033 * whether or not this routine hit a SOLID wall.\n
1035 * "affectwall" toggles whether or not this new square affects\n
1036 * the boundaries of rooms. - This is used by the catacomb\n
1038 * @todo 特に詳細な処理の意味を調査すべし
1040 static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
1044 cave_type *c_ptr = &cave[*y][*x];
1046 if (!in_bounds(*y, *x)) return TRUE;
1048 if (is_inner_grid(c_ptr))
1053 if (is_extra_bold(*y,*x))
1055 /* Save the tunnel location */
1056 if (dun->tunn_n < TUNN_MAX)
1058 dun->tunn[dun->tunn_n].y = *y;
1059 dun->tunn[dun->tunn_n].x = *x;
1067 if (is_floor_bold(*y, *x))
1069 /* Don't do anything */
1073 if (is_outer_grid(c_ptr) && affectwall)
1075 /* Save the wall location */
1076 if (dun->wall_n < WALL_MAX)
1078 dun->wall[dun->wall_n].y = *y;
1079 dun->wall[dun->wall_n].x = *x;
1084 /* Forbid re-entry near this piercing */
1085 for (j = *y - 1; j <= *y + 1; j++)
1087 for (i = *x - 1; i <= *x + 1; i++)
1089 /* Convert adjacent "outer" walls as "solid" walls */
1090 if (is_outer_bold(j, i))
1092 /* Change the wall to a "solid" wall */
1093 place_solid_noperm_bold(j, i);
1098 /* Clear mimic type */
1099 cave[*y][*x].mimic = 0;
1101 place_floor_bold(*y, *x);
1106 if (is_solid_grid(c_ptr) && affectwall)
1108 /* cannot place tunnel here - use a square to the side */
1110 /* find usable square and return value in (x,y) */
1116 while ((i > 0) && is_solid_bold(*y + dy, *x + dx))
1118 dy = randint0(3) - 1;
1119 dx = randint0(3) - 1;
1121 if (!in_bounds(*y + dy, *x + dx))
1132 /* Failed for some reason: hack - ignore the solidness */
1133 place_outer_grid(c_ptr);
1138 /* Give new, acceptable coordinate. */
1150 * @brief 外壁を削って「カタコンベ状」の通路を作成する / This routine creates the catacomb-like tunnels by removing extra rock.
1155 * Note that this routine is only called on "even" squares - so it gives
1156 * a natural checkerboard pattern.
1158 static void create_cata_tunnel(POSITION x, POSITION y)
1165 set_tunnel(&x1, &y1, FALSE);
1169 set_tunnel(&x1, &y1, FALSE);
1173 set_tunnel(&x1, &y1, FALSE);
1177 set_tunnel(&x1, &y1, FALSE);
1182 * @brief トンネル生成処理(詳細調査中)/ This routine does the bulk of the work in creating the new types of tunnels.
1186 * It is designed to use very simple algorithms to go from (x1,y1) to (x2,y2)\n
1187 * It doesn't need to add any complexity - straight lines are fine.\n
1188 * The SOLID walls are avoided by a recursive algorithm which tries random ways\n
1189 * around the obstical until it works. The number of itterations is counted, and it\n
1190 * this gets too large the routine exits. This should stop any crashes - but may leave\n
1191 * small gaps in the tunnel where there are too many SOLID walls.\n
1193 * Type 1 tunnels are extremely simple - straight line from A to B. This is only used\n
1194 * as a part of the dodge SOLID walls algorithm.\n
1196 * Type 2 tunnels are made of two straight lines at right angles. When this is used with\n
1197 * short line segments it gives the "cavelike" tunnels seen deeper in the dungeon.\n
1199 * Type 3 tunnels are made of two straight lines like type 2, but with extra rock removed.\n
1200 * This, when used with longer line segments gives the "catacomb-like" tunnels seen near\n
1203 static void short_seg_hack(int x1, int y1, int x2, int y2, int type, int count, bool *fail)
1209 /* Check for early exit */
1210 if (!(*fail)) return;
1212 length = distance(x1, y1, x2, y2);
1216 if ((type == 1) && (length != 0))
1219 for (i = 0; i <= length; i++)
1221 x = x1 + i * (x2 - x1) / length;
1222 y = y1 + i * (y2 - y1) / length;
1223 if (!set_tunnel(&x, &y, TRUE))
1227 /* This isn't working - probably have an infinite loop */
1232 /* solid wall - so try to go around */
1233 short_seg_hack(x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
1234 short_seg_hack(x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
1238 else if ((type == 2) || (type == 3))
1242 for (i = x1; i <= x2; i++)
1246 if (!set_tunnel(&x, &y, TRUE))
1248 /* solid wall - so try to go around */
1249 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1250 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1252 if ((type == 3) && ((x + y) % 2))
1254 create_cata_tunnel(i, y1);
1260 for (i = x2; i <= x1; i++)
1264 if (!set_tunnel(&x, &y, TRUE))
1266 /* solid wall - so try to go around */
1267 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1268 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1270 if ((type == 3) && ((x + y) % 2))
1272 create_cata_tunnel(i, y1);
1279 for (i = y1; i <= y2; i++)
1283 if (!set_tunnel(&x, &y, TRUE))
1285 /* solid wall - so try to go around */
1286 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1287 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1289 if ((type == 3) && ((x + y) % 2))
1291 create_cata_tunnel(x2, i);
1297 for (i = y2; i <= y1; i++)
1301 if (!set_tunnel(&x, &y, TRUE))
1303 /* solid wall - so try to go around */
1304 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1305 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1307 if ((type == 3) && ((x + y) % 2))
1309 create_cata_tunnel(x2, i);
1318 * @brief 特定の壁(永久壁など)を避けながら部屋間の通路を作成する / This routine maps a path from (x1, y1) to (x2, y2) avoiding SOLID walls.
1322 * Permanent rock is ignored in this path finding- sometimes there is no\n
1323 * path around anyway -so there will be a crash if we try to find one.\n
1324 * This routine is much like the river creation routine in Zangband.\n
1325 * It works by dividing a line segment into two. The segments are divided\n
1326 * until they are less than "cutoff" - when the corresponding routine from\n
1327 * "short_seg_hack" is called.\n
1328 * Note it is VERY important that the "stop if hit another passage" logic\n
1329 * stays as is. Without this the dungeon turns into Swiss Cheese...\n
1331 bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
1333 POSITION x3, y3, dx, dy;
1334 int changex, changey;
1337 bool retval, firstsuccede;
1340 length = distance(x1, y1, x2, y2);
1342 if (length > cutoff)
1345 * Divide path in half and call routine twice.
1350 /* perturbation perpendicular to path */
1351 changex = (randint0(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
1352 changey = (randint0(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
1354 /* Work out "mid" ponit */
1355 x3 = x1 + dx + changex;
1356 y3 = y1 + dy + changey;
1358 /* See if in bounds - if not - do not perturb point */
1359 if (!in_bounds(y3, x3))
1365 c_ptr = &cave[y3][x3];
1366 if (is_solid_grid(c_ptr))
1368 /* move midpoint a bit to avoid problem. */
1374 while ((i > 0) && is_solid_bold(y3 + dy, x3 + dx))
1376 dy = randint0(3) - 1;
1377 dx = randint0(3) - 1;
1378 if (!in_bounds(y3 + dy, x3 + dx))
1388 /* Failed for some reason: hack - ignore the solidness */
1389 place_outer_bold(y3, x3);
1395 c_ptr = &cave[y3][x3];
1398 if (is_floor_grid(c_ptr))
1400 if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
1402 if ((cave[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
1404 /* do second half only if works + if have hit a room */
1405 retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
1409 /* have hit another tunnel - make a set of doors here */
1412 /* Save the door location */
1413 if (dun->door_n < DOOR_MAX)
1415 dun->door[dun->door_n].y = (POSITION)y3;
1416 dun->door[dun->door_n].x = (POSITION)x3;
1421 firstsuccede = TRUE;
1425 /* false- didn't work all the way */
1427 firstsuccede = FALSE;
1432 /* tunnel through walls */
1433 if (build_tunnel2(x1, y1, (POSITION)x3, (POSITION)y3, type, cutoff))
1435 retval = build_tunnel2((POSITION)x3, (POSITION)y3, x2, y2, type, cutoff);
1436 firstsuccede = TRUE;
1440 /* false- didn't work all the way */
1442 firstsuccede = FALSE;
1447 /* only do this if the first half has worked */
1448 set_tunnel(&x3, &y3, TRUE);
1450 /* return value calculated above */
1455 /* Do a short segment */
1457 short_seg_hack(x1, y1, x2, y2, type, 0, &retval);
1459 /* Hack - ignore return value so avoid infinite loops */