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;
70 if (max_attempts < 1) /* Should be -1, actually if we failed... */
73 /* Save the new player grid */
83 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
84 * @param y 配置を試みたいマスのY座標
85 * @param x 配置を試みたいマスのX座標
88 void place_random_stairs(POSITION y, POSITION x)
90 bool up_stairs = TRUE;
91 bool down_stairs = TRUE;
96 if (!is_floor_grid(c_ptr) || c_ptr->o_idx) return;
103 if (ironman_downward)
107 if (dun_level >= d_info[dungeon_type].maxdepth)
111 if (quest_number(dun_level) && (dun_level > 1))
114 /* We can't place both */
115 if (down_stairs && up_stairs)
117 /* Choose a staircase randomly */
118 if (randint0(100) < 50)
124 /* Place the stairs */
126 place_up_stairs(y, x);
127 else if (down_stairs)
128 place_down_stairs(y, x);
132 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
133 * @param y ドアの配置を試みたいマスのY座標
134 * @param x ドアの配置を試みたいマスのX座標
135 * @param room 部屋に接している場合向けのドア生成か否か
138 void place_random_door(POSITION y, POSITION x, bool room)
141 FEAT_IDX feat = feat_none;
142 cave_type *c_ptr = &cave[y][x];
144 /* Initialize mimic info */
147 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
149 place_floor_bold(y, x);
153 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
154 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
155 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
157 /* Choose an object */
158 tmp = randint0(1000);
160 /* Open doors (300/1000) */
163 /* Create open door */
164 feat = feat_door[type].open;
167 /* Broken doors (100/1000) */
170 /* Create broken door */
171 feat = feat_door[type].broken;
174 /* Secret doors (200/1000) */
177 /* Create secret door */
178 place_closed_door(y, x, type);
180 if (type != DOOR_CURTAIN)
182 /* Hide. If on the edge of room, use outer wall. */
183 c_ptr->mimic = room ? feat_wall_outer : fill_type[randint0(100)];
185 /* Floor type terrain cannot hide a door */
186 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
188 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
190 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
197 /* Closed, locked, or stuck doors (400/1000) */
198 else place_closed_door(y, x, type);
202 if (feat != feat_none)
204 set_cave_feat(y, x, feat);
208 place_floor_bold(y, x);
212 delete_monster(y, x);
216 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
217 * @param y ドアの配置を試みたいマスのY座標
218 * @param x ドアの配置を試みたいマスのX座標
219 * @param type ドアの地形ID
222 void place_closed_door(POSITION y, POSITION x, int type)
225 FEAT_IDX feat = feat_none;
227 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
229 place_floor_bold(y, x);
233 /* Choose an object */
236 /* Closed doors (300/400) */
239 /* Create closed door */
240 feat = feat_door[type].closed;
243 /* Locked doors (99/400) */
246 /* Create locked door */
247 feat = feat_locked_door_random(type);
250 /* Stuck doors (1/400) */
253 /* Create jammed door */
254 feat = feat_jammed_door_random(type);
257 if (feat != feat_none)
259 cave_set_feat(y, x, feat);
261 /* Now it is not floor */
262 cave[y][x].info &= ~(CAVE_MASK);
266 place_floor_bold(y, x);
271 * @brief 鍵のかかったドアを配置する
272 * @param y 配置したいフロアのY座標
273 * @param x 配置したいフロアのX座標
276 void place_locked_door(POSITION y, POSITION x)
278 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
280 place_floor_bold(y, x);
284 set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
285 cave[y][x].info &= ~(CAVE_FLOOR);
286 delete_monster(y, x);
293 * @param y 配置したいフロアのY座標
294 * @param x 配置したいフロアのX座標
295 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
298 void place_secret_door(POSITION y, POSITION x, int type)
300 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
302 place_floor_bold(y, x);
306 cave_type *c_ptr = &cave[y][x];
308 if (type == DOOR_DEFAULT)
310 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
311 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
312 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
315 /* Create secret door */
316 place_closed_door(y, x, type);
318 if (type != DOOR_CURTAIN)
320 /* Hide by inner wall because this is used in rooms only */
321 c_ptr->mimic = feat_wall_inner;
323 /* Floor type terrain cannot hide a door */
324 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
326 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
328 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
334 c_ptr->info &= ~(CAVE_FLOOR);
335 delete_monster(y, x);
340 * Routine used by the random vault creators to add a door to a location
341 * Note that range checking has to be done in the calling routine.
343 * The doors must be INSIDE the allocated region.
345 void add_door(POSITION x, POSITION y)
347 /* Need to have a wall in the center square */
348 if (!is_outer_bold(y, x)) return;
359 if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
360 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
363 place_secret_door(y, x, DOOR_DEFAULT);
365 /* set boundarys so don't get wide doors */
366 place_solid_bold(y, x - 1);
367 place_solid_bold(y, x + 1);
376 * where x = don't care
379 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
380 is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
383 place_secret_door(y, x, DOOR_DEFAULT);
385 /* set boundarys so don't get wide doors */
386 place_solid_bold(y - 1, x);
387 place_solid_bold(y + 1, x);
392 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
393 * @param y1 基準となるマスのY座標
394 * @param x1 基準となるマスのX座標
396 * @note Assumes "in_bounds(y1, x1)"
398 * XXX XXX This routine currently only counts actual "empty floor"\n
399 * grids which are not in rooms. We might want to also count stairs,\n
400 * open doors, closed doors, etc.
402 static int next_to_corr(POSITION y1, POSITION 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(POSITION y, POSITION 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;
661 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
662 * @param y トラップを配置したいマスの中心Y座標
663 * @param x トラップを配置したいマスの中心X座標
664 * @param yd Y方向の配置分散マス数
665 * @param xd X方向の配置分散マス数
666 * @param num 配置したいトラップの数
669 * Only really called by some of the "vault" routines.
671 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
675 for (i = 0; i < num; i++)
677 vault_trap_aux(y, x, yd, xd);
682 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
683 * @param y1 モンスターを配置したいマスの中心Y座標
684 * @param x1 モンスターを配置したいマスの中心X座標
685 * @param num 配置したいモンスターの数
688 * Only really called by some of the "vault" routines.
690 void vault_monsters(POSITION y1, POSITION x1, int num)
696 /* Try to summon "num" monsters "near" the given location */
697 for (k = 0; k < num; k++)
699 /* Try nine locations */
700 for (i = 0; i < 9; i++)
704 /* Pick a nearby location */
705 scatter(&y, &x, y1, x1, d, 0);
707 /* Require "empty" floor grids */
709 if (!cave_empty_grid(c_ptr)) continue;
711 /* Place the monster (allow groups) */
712 monster_level = base_level + 2;
713 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
714 monster_level = base_level;
721 * @brief build_tunnel用に通路を掘るための方向を位置関係通りに決める / Always picks a correct direction
722 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
723 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
730 void correct_dir(int *rdir, int *cdir, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
732 /* Extract vertical and horizontal directions */
733 *rdir = (y1 == y2) ? 0 : (y1 < y2) ? 1 : -1;
734 *cdir = (x1 == x2) ? 0 : (x1 < x2) ? 1 : -1;
736 /* Never move diagonally */
739 if (randint0(100) < 50)
747 * @brief build_tunnel用に通路を掘るための方向をランダムに決める / Pick a random direction
748 * @param rdir Y方向に取るべきベクトル値を返す参照ポインタ
749 * @param cdir X方向に取るべきベクトル値を返す参照ポインタ
752 void rand_dir(int *rdir, int *cdir)
754 /* Pick a random direction */
757 /* Extract the dy/dx components */
763 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
764 * @param x チェックするマスのX座標
765 * @param y チェックするマスのY座標
766 * @return 床系地形ならばTRUE
768 bool get_is_floor(POSITION x, POSITION y)
770 if (!in_bounds(y, x))
776 /* Do the real check */
777 if (is_floor_bold(y, x)) return (TRUE);
783 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
784 * @param x 地形を変えたいマスのX座標
785 * @param y 地形を変えたいマスのY座標
788 void set_floor(POSITION x, POSITION y)
790 if (!in_bounds(y, x))
796 if (cave[y][x].info & CAVE_ROOM)
798 /* A room border don't touch. */
802 /* Set to be floor if is a wall (don't touch lakes). */
803 if (is_extra_bold(y, x))
804 place_floor_bold(y, x);