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 FEAT_IDX 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 FEAT_IDX 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(POSITION y1, POSITION x1)
410 /* Scan adjacent grids */
411 for (i = 0; i < 4; i++)
413 /* Extract the location */
417 /* Access the grid */
420 /* Skip non floors */
421 if (cave_have_flag_grid(c_ptr, FF_WALL)) continue;
423 /* Skip non "empty floor" grids */
424 if (!is_floor_grid(c_ptr))
427 /* Skip grids inside rooms */
428 if (c_ptr->info & (CAVE_ROOM)) continue;
430 /* Count these grids */
434 /* Return the number of corridors */
439 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
440 * @param y 判定を行いたいマスのY座標
441 * @param x 判定を行いたいマスのX座標
442 * @return ドアを設置可能ならばTRUEを返す
443 * @note Assumes "in_bounds(y1, x1)"
446 * Assumes "in_bounds(y, x)"\n
448 static bool possible_doorway(POSITION y, POSITION x)
450 /* Count the adjacent corridors */
451 if (next_to_corr(y, x) >= 2)
454 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
455 cave_have_flag_bold(y + 1, x, FF_WALL))
460 /* Check Horizontal */
461 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
462 cave_have_flag_bold(y, x + 1, FF_WALL))
473 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
474 * @param y 設置を行いたいマスのY座標
475 * @param x 設置を行いたいマスのX座標
478 void try_door(POSITION y, POSITION x)
481 if (!in_bounds(y, x)) return;
484 if (cave_have_flag_bold(y, x, FF_WALL)) return;
486 /* Ignore room grids */
487 if (cave[y][x].info & (CAVE_ROOM)) return;
489 /* Occasional door (if allowed) */
490 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
493 place_random_door(y, x, FALSE);
499 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
500 * @param x1 長方形の左端X座標(-1)
501 * @param x2 長方形の右端X座標(+1)
502 * @param y1 長方形の上端Y座標(-1)
503 * @param y2 長方形の下端Y座標(+1)
507 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
511 /* Place a full floor under the room */
512 for (y = y1 - 1; y <= y2 + 1; y++)
514 for (x = x1 - 1; x <= x2 + 1; x++)
516 place_floor_bold(y, x);
517 add_cave_info(y, x, CAVE_ROOM);
518 if (light) add_cave_info(y, x, CAVE_GLOW);
525 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
526 * @param x1 長方形の左端X座標(-1)
527 * @param x2 長方形の右端X座標(+1)
528 * @param y1 長方形の上端Y座標(-1)
529 * @param y2 長方形の下端Y座標(+1)
533 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
537 place_floor(x1, x2, y1, y2, light);
539 /* Walls around the room */
540 for (y = y1 - 1; y <= y2 + 1; y++)
542 place_outer_bold(y, x1 - 1);
543 place_outer_bold(y, x2 + 1);
545 for (x = x1 - 1; x <= x2 + 1; x++)
547 place_outer_bold(y1 - 1, x);
548 place_outer_bold(y2 + 1, x);
554 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
555 * @param y 配置したい中心マスのY座標
556 * @param x 配置したい中心マスのX座標
560 * Only really called by some of the "vault" routines.
562 void vault_objects(POSITION y, POSITION x, int num)
565 int i = 0, j = y, k = x;
570 /* Attempt to place 'num' objects */
571 for (; num > 0; --num)
573 /* Try up to 11 spots looking for empty space */
574 for (i = 0; i < 11; ++i)
576 /* Pick a random location */
577 while (dummy < SAFE_MAX_ATTEMPTS)
579 j = rand_spread(y, 2);
580 k = rand_spread(x, 3);
582 if (!in_bounds(j, k)) continue;
587 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
589 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
593 /* Require "clean" floor space */
595 if (!is_floor_grid(c_ptr) || c_ptr->o_idx) continue;
598 if (randint0(100) < 75)
600 place_object(j, k, 0L);
609 /* Placement accomplished */
616 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
617 * @param y トラップを配置したいマスの中心Y座標
618 * @param x トラップを配置したいマスの中心X座標
619 * @param yd Y方向の配置分散マス数
620 * @param xd X方向の配置分散マス数
623 * Only really called by some of the "vault" routines.
625 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
627 int count = 0, y1 = y, x1 = x;
633 for (count = 0; count <= 5; count++)
636 while (dummy < SAFE_MAX_ATTEMPTS)
638 y1 = rand_spread(y, yd);
639 x1 = rand_spread(x, xd);
641 if (!in_bounds(y1, x1)) continue;
645 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
647 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
650 /* Require "naked" floor grids */
651 c_ptr = &cave[y1][x1];
652 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
663 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
664 * @param y トラップを配置したいマスの中心Y座標
665 * @param x トラップを配置したいマスの中心X座標
666 * @param yd Y方向の配置分散マス数
667 * @param xd X方向の配置分散マス数
668 * @param num 配置したいトラップの数
671 * Only really called by some of the "vault" routines.
673 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
677 for (i = 0; i < num; i++)
679 vault_trap_aux(y, x, yd, xd);
684 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
685 * @param y1 モンスターを配置したいマスの中心Y座標
686 * @param x1 モンスターを配置したいマスの中心X座標
687 * @param num 配置したいモンスターの数
690 * Only really called by some of the "vault" routines.
692 void vault_monsters(POSITION y1, POSITION x1, int num)
698 /* Try to summon "num" monsters "near" the given location */
699 for (k = 0; k < num; k++)
701 /* Try nine locations */
702 for (i = 0; i < 9; i++)
706 /* Pick a nearby location */
707 scatter(&y, &x, y1, x1, d, 0);
709 /* Require "empty" floor grids */
711 if (!cave_empty_grid(c_ptr)) continue;
713 /* Place the monster (allow groups) */
714 monster_level = base_level + 2;
715 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
716 monster_level = base_level;
723 * @brief build_tunnel用に通路を掘るための方向を位置関係通りに決める / Always picks a correct direction
724 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
725 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
732 void correct_dir(int *rdir, int *cdir, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
734 /* Extract vertical and horizontal directions */
735 *rdir = (y1 == y2) ? 0 : (y1 < y2) ? 1 : -1;
736 *cdir = (x1 == x2) ? 0 : (x1 < x2) ? 1 : -1;
738 /* Never move diagonally */
741 if (randint0(100) < 50)
749 * @brief build_tunnel用に通路を掘るための方向をランダムに決める / Pick a random direction
750 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
751 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
754 void rand_dir(int *rdir, int *cdir)
756 /* Pick a random direction */
759 /* Extract the dy/dx components */
765 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
766 * @param x チェックするマスのX座標
767 * @param y チェックするマスのY座標
768 * @return 床系地形ならばTRUE
770 bool get_is_floor(POSITION x, POSITION y)
772 if (!in_bounds(y, x))
778 /* Do the real check */
779 if (is_floor_bold(y, x)) return (TRUE);
785 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
786 * @param x 地形を変えたいマスのX座標
787 * @param y 地形を変えたいマスのY座標
790 void set_floor(POSITION x, POSITION y)
792 if (!in_bounds(y, x))
798 if (cave[y][x].info & CAVE_ROOM)
800 /* A room border don't touch. */
804 /* Set to be floor if is a wall (don't touch lakes). */
805 if (is_extra_bold(y, x))
806 place_floor_bold(y, x);