3 #include "floor-save.h"
4 #include "floor-generate.h"
9 #include "object-hook.h"
11 #include "player-effects.h"
13 #include "object-hook.h"
15 #include "objectkind.h"
19 * The array of floor [MAX_WID][MAX_HGT].
20 * Not completely allocated, that would be inefficient
21 * Not completely hardcoded, that would overflow memory
23 floor_type floor_info;
26 * The array of saved floors
28 saved_floor_type saved_floors[MAX_SAVED_FLOORS];
31 * @brief 鍵のかかったドアを配置する
32 * @param player_ptr プレーヤーへの参照ポインタ
33 * @param y 配置したいフロアのY座標
34 * @param x 配置したいフロアのX座標
37 void place_locked_door(player_type *player_ptr, POSITION y, POSITION x)
39 floor_type *floor_ptr = player_ptr->current_floor_ptr;
40 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
42 place_floor_bold(floor_ptr, y, x);
46 set_cave_feat(floor_ptr, y, x, feat_locked_door_random((d_info[player_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
47 floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
48 delete_monster(floor_ptr, y, x);
55 * @param player_ptr プレーヤーへの参照ポインタ
56 * @param y 配置したいフロアのY座標
57 * @param x 配置したいフロアのX座標
58 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
61 void place_secret_door(player_type *player_ptr, POSITION y, POSITION x, int type)
63 floor_type *floor_ptr = player_ptr->current_floor_ptr;
64 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
66 place_floor_bold(floor_ptr, y, x);
70 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
72 if (type == DOOR_DEFAULT)
74 type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
75 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
76 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
79 /* Create secret door */
80 place_closed_door(player_ptr, y, x, type);
82 if (type != DOOR_CURTAIN)
84 /* Hide by inner wall because this is used in rooms only */
85 g_ptr->mimic = feat_wall_inner;
87 /* Floor type terrain cannot hide a door */
88 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
90 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
92 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
98 g_ptr->info &= ~(CAVE_FLOOR);
99 delete_monster(floor_ptr, y, x);
103 static int scent_when = 0;
106 * Characters leave scent trails for perceptive monsters to track.
108 * Smell is rather more limited than sound. Many creatures cannot use
109 * it at all, it doesn't extend very far outwards from the character's
110 * current position, and monsters can use it to home in the character,
111 * but not to run away from him.
113 * Smell is valued according to age. When a character takes his turn,
114 * scent is aged by one, and new scent of the current age is laid down.
115 * Speedy characters leave more scent, true, but it also ages faster,
116 * which makes it harder to hunt them down.
118 * Whenever the age count loops, most of the scent trail is erased and
119 * the age of the remainder is recalculated.
121 void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
126 /* Create a table that controls the spread of scent */
127 const int scent_adjust[5][5] =
136 /* Loop the age and adjust scent values when necessary */
137 if (++scent_when == 254)
139 /* Scan the entire dungeon */
140 for (y = 0; y < floor_ptr->height; y++)
142 for (x = 0; x < floor_ptr->width; x++)
144 int w = floor_ptr->grid_array[y][x].when;
145 floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
154 /* Lay down new scent */
155 for (i = 0; i < 5; i++)
157 for (j = 0; j < 5; j++)
161 /* Translate table to map grids */
162 y = i + subject_ptr->y - 2;
163 x = j + subject_ptr->x - 2;
166 if (!in_bounds(floor_ptr, y, x)) continue;
168 g_ptr = &floor_ptr->grid_array[y][x];
170 /* Walls, water, and lava cannot hold scent. */
171 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
173 /* Grid must not be blocked by walls from the character */
174 if (!player_has_los_bold(subject_ptr, y, x)) continue;
176 /* Note grids that are too far away */
177 if (scent_adjust[i][j] == -1) continue;
179 /* Mark the grid with new scent */
180 g_ptr->when = scent_when + scent_adjust[i][j];
187 * Hack -- forget the "flow" information
189 void forget_flow(floor_type *floor_ptr)
193 /* Check the entire dungeon */
194 for (y = 0; y < floor_ptr->height; y++)
196 for (x = 0; x < floor_ptr->width; x++)
198 /* Forget the old data */
199 floor_ptr->grid_array[y][x].dist = 0;
200 floor_ptr->grid_array[y][x].cost = 0;
201 floor_ptr->grid_array[y][x].when = 0;
207 * Routine used by the random vault creators to add a door to a location
208 * Note that range checking has to be done in the calling routine.
210 * The doors must be INSIDE the allocated region.
212 void add_door(player_type *player_ptr, POSITION x, POSITION y)
214 /* Need to have a wall in the center square */
215 floor_type *floor_ptr = player_ptr->current_floor_ptr;
216 if (!is_outer_bold(floor_ptr, y, x)) return;
227 if (is_floor_bold(floor_ptr, y - 1, x) && is_floor_bold(floor_ptr, y + 1, x) &&
228 (is_outer_bold(floor_ptr, y, x - 1) && is_outer_bold(floor_ptr, y, x + 1)))
231 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
233 /* set boundarys so don't get wide doors */
234 place_solid_bold(floor_ptr, y, x - 1);
235 place_solid_bold(floor_ptr, y, x + 1);
244 * where x = don't care
247 if (is_outer_bold(floor_ptr, y - 1, x) && is_outer_bold(floor_ptr, y + 1, x) &&
248 is_floor_bold(floor_ptr, y, x - 1) && is_floor_bold(floor_ptr, y, x + 1))
251 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
253 /* set boundarys so don't get wide doors */
254 place_solid_bold(floor_ptr, y - 1, x);
255 place_solid_bold(floor_ptr, y + 1, x);
260 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
261 * @param player_ptr プレーヤーへの参照ポインタ
262 * @param y 配置を試みたいマスのY座標
263 * @param x 配置を試みたいマスのX座標
266 void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
268 bool up_stairs = TRUE;
269 bool down_stairs = TRUE;
271 floor_type *floor_ptr = player_ptr->current_floor_ptr;
272 g_ptr = &floor_ptr->grid_array[y][x];
273 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
275 if (!floor_ptr->dun_level) up_stairs = FALSE;
276 if (ironman_downward) up_stairs = FALSE;
277 if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
278 if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1)) down_stairs = FALSE;
280 /* We can't place both */
281 if (down_stairs && up_stairs)
283 /* Choose a staircase randomly */
284 if (randint0(100) < 50) up_stairs = FALSE;
285 else down_stairs = FALSE;
288 /* Place the stairs */
289 if (up_stairs) set_cave_feat(floor_ptr, y, x, feat_up_stair);
290 else if (down_stairs) set_cave_feat(floor_ptr, y, x, feat_down_stair);
294 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
299 * @return LOSが通っているならTRUEを返す。
301 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
302 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
304 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
306 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
307 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
308 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
310 * We assume that the "mathematical corner" of a non-floor tile does not\n
311 * block line of sight.\n
313 * Because this function uses (short) ints for all calculations, overflow may\n
314 * occur if dx and dy exceed 90.\n
316 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
317 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
318 * we can use integer arithmetic.\n
320 * We travel from start to finish along the longer axis, starting at the border\n
321 * between the first and second tiles, where the y offset = .5 * slope, taking\n
322 * into account the scale factor. See below.\n
324 * Also note that this function and the "move towards target" code do NOT\n
325 * share the same properties. Thus, you can see someone, target them, and\n
326 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
327 * by clever choice of target locations, you can sometimes throw a "curve".\n
329 * Note that "line of sight" is not "reflexive" in all cases.\n
331 * Use the "projectable()" routine to test "spell/missile line of sight".\n
333 * Use the "update_view()" function to determine player line-of-sight.\n
335 bool los(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
355 /* Slope, or 1/Slope, of LOS */
359 /* Extract the offset */
363 /* Extract the absolute offset */
368 /* Handle adjacent (or identical) grids */
369 if ((ax < 2) && (ay < 2)) return TRUE;
372 /* Paranoia -- require "safe" origin */
373 /* if (!in_bounds(floor_ptr, y1, x1)) return FALSE; */
374 /* if (!in_bounds(floor_ptr, y2, x2)) return FALSE; */
377 /* Directly South/North */
380 /* South -- check for walls */
383 for (ty = y1 + 1; ty < y2; ty++)
385 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
389 /* North -- check for walls */
392 for (ty = y1 - 1; ty > y2; ty--)
394 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
402 /* Directly East/West */
405 /* East -- check for walls */
408 for (tx = x1 + 1; tx < x2; tx++)
410 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
414 /* West -- check for walls */
417 for (tx = x1 - 1; tx > x2; tx--)
419 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
428 /* Extract some signs */
429 sx = (dx < 0) ? -1 : 1;
430 sy = (dy < 0) ? -1 : 1;
433 /* Vertical "knights" */
438 if (cave_los_bold(floor_ptr, y1 + sy, x1)) return TRUE;
442 /* Horizontal "knights" */
447 if (cave_los_bold(floor_ptr, y1, x1 + sx)) return TRUE;
452 /* Calculate scale factor div 2 */
455 /* Calculate scale factor */
459 /* Travel horizontally */
462 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
468 /* Consider the special case where slope == 1. */
479 /* Note (below) the case (qy == f2), where */
480 /* the LOS exactly meets the corner of a tile. */
483 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
494 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
507 /* Travel vertically */
510 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
526 /* Note (below) the case (qx == f2), where */
527 /* the LOS exactly meets the corner of a tile. */
530 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
541 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
560 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
561 * at the final destination, assuming no monster gets in the way.
563 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
565 bool projectable(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
572 /* Check the projection path */
573 grid_n = project_path(floor_ptr, grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
576 if (!grid_n) return TRUE;
579 y = GRID_Y(grid_g[grid_n - 1]);
580 x = GRID_X(grid_g[grid_n - 1]);
582 /* May not end in an unrequested grid */
583 if ((y != y2) || (x != x2)) return FALSE;
591 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
592 * @param y1 モンスターを配置したいマスの中心Y座標
593 * @param x1 モンスターを配置したいマスの中心X座標
594 * @param num 配置したいモンスターの数
597 * Only really called by some of the "vault" routines.
599 void vault_monsters(floor_type *floor_ptr, POSITION y1, POSITION x1, int num)
605 /* Try to summon "num" monsters "near" the given location */
606 for (k = 0; k < num; k++)
608 /* Try nine locations */
609 for (i = 0; i < 9; i++)
613 /* Pick a nearby location */
614 scatter(floor_ptr, &y, &x, y1, x1, d, 0);
616 /* Require "empty" floor grids */
617 g_ptr = &floor_ptr->grid_array[y][x];
618 if (!cave_empty_grid(g_ptr)) continue;
620 /* Place the monster (allow groups) */
621 floor_ptr->monster_level = floor_ptr->base_level + 2;
622 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
623 floor_ptr->monster_level = floor_ptr->base_level;
630 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
631 * @param player_ptr プレーヤーへの参照ポインタ
634 * @return 各種の変更が可能ならTRUEを返す。
636 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
638 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
640 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
641 OBJECT_IDX this_o_idx, next_o_idx = 0;
643 /* Forbid perma-grids */
644 if (cave_perma_grid(g_ptr)) return FALSE;
647 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
650 o_ptr = &floor_ptr->o_list[this_o_idx];
651 next_o_idx = o_ptr->next_o_idx;
653 /* Forbid artifact grids */
654 if (object_is_artifact(o_ptr)) return FALSE;
662 * Change the "feat" flag for a grid, and notice/redraw the grid
664 void cave_set_feat(player_type *player_ptr, POSITION y, POSITION x, FEAT_IDX feat)
666 floor_type *floor_ptr = player_ptr->current_floor_ptr;
667 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
668 feature_type *f_ptr = &f_info[feat];
669 bool old_los, old_mirror;
671 if (!current_world_ptr->character_dungeon)
673 /* Clear mimic type */
676 /* Change the feature */
679 /* Hack -- glow the GLOW terrain */
680 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
685 for (i = 0; i < 9; i++)
689 if (!in_bounds2(floor_ptr, yy, xx)) continue;
690 floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
697 old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
698 old_mirror = is_mirror_grid(g_ptr);
700 /* Clear mimic type */
703 /* Change the feature */
706 /* Remove flag for mirror/glyph */
707 g_ptr->info &= ~(CAVE_OBJECT);
709 if (old_mirror && (d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
711 g_ptr->info &= ~(CAVE_GLOW);
712 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
714 update_local_illumination(player_ptr, y, x);
717 /* Check for change to boring grid */
718 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
719 if (g_ptr->m_idx) update_monster(player_ptr, g_ptr->m_idx, FALSE);
724 /* Check if los has changed */
725 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
728 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
730 update_local_illumination(player_ptr, y, x);
732 #endif /* COMPLEX_WALL_ILLUMINATION */
734 /* Update the visuals */
735 player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
738 /* Hack -- glow the GLOW terrain */
739 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[player_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
745 for (i = 0; i < 9; i++)
749 if (!in_bounds2(floor_ptr, yy, xx)) continue;
750 cc_ptr = &floor_ptr->grid_array[yy][xx];
751 cc_ptr->info |= CAVE_GLOW;
753 if (player_has_los_grid(cc_ptr))
755 if (cc_ptr->m_idx) update_monster(player_ptr, cc_ptr->m_idx, FALSE);
760 update_local_illumination(player_ptr, yy, xx);
763 if (player_ptr->special_defense & NINJA_S_STEALTH)
765 if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW) set_superstealth(player_ptr, FALSE);
772 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
773 * @param player_ptr プレーヤーへの参照ポインタ
774 * @param y ドアの配置を試みたいマスのY座標
775 * @param x ドアの配置を試みたいマスのX座標
776 * @param room 部屋に接している場合向けのドア生成か否か
779 void place_random_door(player_type *player_ptr, POSITION y, POSITION x, bool room)
782 FEAT_IDX feat = feat_none;
783 floor_type *floor_ptr = player_ptr->current_floor_ptr;
784 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
786 /* Initialize mimic info */
789 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
791 place_floor_bold(floor_ptr, y, x);
795 type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
796 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
797 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
799 /* Choose an object */
800 tmp = randint0(1000);
802 /* Open doors (300/1000) */
805 /* Create open door */
806 feat = feat_door[type].open;
809 /* Broken doors (100/1000) */
812 /* Create broken door */
813 feat = feat_door[type].broken;
816 /* Secret doors (200/1000) */
819 /* Create secret door */
820 place_closed_door(player_ptr, y, x, type);
822 if (type != DOOR_CURTAIN)
824 /* Hide. If on the edge of room, use outer wall. */
825 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
827 /* Floor type terrain cannot hide a door */
828 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
830 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
832 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
839 /* Closed, locked, or stuck doors (400/1000) */
840 else place_closed_door(player_ptr, y, x, type);
844 if (feat != feat_none)
846 set_cave_feat(floor_ptr, y, x, feat);
850 place_floor_bold(floor_ptr, y, x);
854 delete_monster(floor_ptr, y, x);
860 * @brief グローバルオブジェクト配列を初期化する /
861 * Delete all the items when player leaves the level
862 * @note we do NOT visually reflect these (irrelevant) changes
864 * Hack -- we clear the "g_ptr->o_idx" field for every grid,
865 * and the "m_ptr->next_o_idx" field for every monster, since
866 * we know we are clearing every object. Technically, we only
867 * clear those fields for grids/monsters containing objects,
868 * and we clear it once for every such object.
871 void wipe_o_list(floor_type *floor_ptr)
875 /* Delete the existing objects */
876 for (i = 1; i < floor_ptr->o_max; i++)
878 object_type *o_ptr = &floor_ptr->o_list[i];
880 if (!OBJECT_IS_VALID(o_ptr)) continue;
882 /* Mega-Hack -- preserve artifacts */
883 if (!current_world_ptr->character_dungeon || preserve_mode)
885 /* Hack -- Preserve unknown artifacts */
886 if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
888 /* Mega-Hack -- Preserve the artifact */
889 a_info[o_ptr->name1].cur_num = 0;
893 if (OBJECT_IS_HELD_MONSTER(o_ptr))
896 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
898 /* Hack -- see above */
899 m_ptr->hold_o_idx = 0;
907 /* Access location */
908 POSITION y = o_ptr->iy;
909 POSITION x = o_ptr->ix;
912 g_ptr = &floor_ptr->grid_array[y][x];
914 /* Hack -- see above */
920 /* Reset "floor_ptr->o_max" */
921 floor_ptr->o_max = 1;
923 /* Reset "floor_ptr->o_cnt" */
924 floor_ptr->o_cnt = 0;
929 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
930 * @param player_ptr プレーヤーへの参照ポインタ
931 * @param y ドアの配置を試みたいマスのY座標
932 * @param x ドアの配置を試みたいマスのX座標
933 * @param type ドアの地形ID
936 void place_closed_door(player_type *player_ptr, POSITION y, POSITION x, int type)
939 FEAT_IDX feat = feat_none;
941 floor_type *floor_ptr = player_ptr->current_floor_ptr;
942 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
944 place_floor_bold(floor_ptr, y, x);
948 /* Choose an object */
951 /* Closed doors (300/400) */
954 /* Create closed door */
955 feat = feat_door[type].closed;
958 /* Locked doors (99/400) */
961 /* Create locked door */
962 feat = feat_locked_door_random(type);
965 /* Stuck doors (1/400) */
968 /* Create jammed door */
969 feat = feat_jammed_door_random(type);
972 if (feat != feat_none)
974 cave_set_feat(player_ptr, y, x, feat);
976 /* Now it is not floor */
977 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
981 place_floor_bold(floor_ptr, y, x);
986 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
987 * @param y トラップを配置したいマスの中心Y座標
988 * @param x トラップを配置したいマスの中心X座標
989 * @param yd Y方向の配置分散マス数
990 * @param xd X方向の配置分散マス数
993 * Only really called by some of the "vault" routines.
995 void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
997 int count = 0, y1 = y, x1 = x;
1003 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1004 for (count = 0; count <= 5; count++)
1006 /* Get a location */
1007 while (dummy < SAFE_MAX_ATTEMPTS)
1009 y1 = rand_spread(y, yd);
1010 x1 = rand_spread(x, xd);
1012 if (!in_bounds(floor_ptr, y1, x1)) continue;
1016 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
1018 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
1021 /* Require "naked" floor grids */
1022 g_ptr = &floor_ptr->grid_array[y1][x1];
1023 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
1025 /* Place the trap */
1026 place_trap(player_ptr, y1, x1);
1033 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
1034 * @param x チェックするマスのX座標
1035 * @param y チェックするマスのY座標
1036 * @return 床系地形ならばTRUE
1038 bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
1040 if (!in_bounds(floor_ptr, y, x))
1046 /* Do the real check */
1047 if (is_floor_bold(floor_ptr, y, x)) return TRUE;
1053 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
1054 * @param y1 基準となるマスのY座標
1055 * @param x1 基準となるマスのX座標
1057 * @note Assumes "in_bounds(y1, x1)"
1059 * XXX XXX This routine currently only counts actual "empty floor"\n
1060 * grids which are not in rooms. We might want to also count stairs,\n
1061 * open doors, closed doors, etc.
1063 static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
1070 /* Scan adjacent grids */
1071 for (i = 0; i < 4; i++)
1073 y = y1 + ddy_ddd[i];
1074 x = x1 + ddx_ddd[i];
1075 g_ptr = &floor_ptr->grid_array[y][x];
1077 /* Skip non floors */
1078 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
1080 /* Skip non "empty floor" grids */
1081 if (!is_floor_grid(g_ptr))
1084 /* Skip grids inside rooms */
1085 if (g_ptr->info & (CAVE_ROOM)) continue;
1087 /* Count these grids */
1091 /* Return the number of corridors */
1096 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
1097 * @param y 判定を行いたいマスのY座標
1098 * @param x 判定を行いたいマスのX座標
1099 * @return ドアを設置可能ならばTRUEを返す
1100 * @note Assumes "in_bounds()"
1103 * Assumes "in_bounds()"\n
1105 static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
1107 /* Count the adjacent corridors */
1108 if (next_to_corr(floor_ptr, y, x) >= 2)
1110 /* Check Vertical */
1111 if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) &&
1112 cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
1117 /* Check Horizontal */
1118 if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) &&
1119 cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
1130 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
1131 * @param player_ptr プレーヤーへの参照ポインタ
1132 * @param y 設置を行いたいマスのY座標
1133 * @param x 設置を行いたいマスのX座標
1136 void try_door(player_type *player_ptr, POSITION y, POSITION x)
1138 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1139 if (!in_bounds(floor_ptr, y, x)) return;
1142 if (cave_have_flag_bold(floor_ptr, y, x, FF_WALL)) return;
1144 /* Ignore room grids */
1145 if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
1147 /* Occasional door (if allowed) */
1148 if ((randint0(100) < dun_tun_jct) && possible_doorway(floor_ptr, y, x) && !(d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
1151 place_random_door(player_ptr, y, x, FALSE);
1156 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
1158 feature_type *f_ptr = &f_info[newfeat];
1160 if (have_flag(f_ptr->flags, FF_CONVERT))
1162 switch (f_ptr->subtype)
1164 case CONVERT_TYPE_FLOOR:
1165 return feat_ground_type[randint0(100)];
1166 case CONVERT_TYPE_WALL:
1167 return feat_wall_type[randint0(100)];
1168 case CONVERT_TYPE_INNER:
1169 return feat_wall_inner;
1170 case CONVERT_TYPE_OUTER:
1171 return feat_wall_outer;
1172 case CONVERT_TYPE_SOLID:
1173 return feat_wall_solid;
1174 case CONVERT_TYPE_STREAM1:
1175 return d_info[floor_ptr->dungeon_idx].stream1;
1176 case CONVERT_TYPE_STREAM2:
1177 return d_info[floor_ptr->dungeon_idx].stream2;
1182 else return newfeat;
1187 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
1188 * @param player_ptr プレーヤーへの参照ポインタ
1189 * @param y 配置したい中心マスのY座標
1190 * @param x 配置したい中心マスのX座標
1194 * Only really called by some of the "vault" routines.
1196 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
1199 int i = 0, j = y, k = x;
1202 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1204 /* Attempt to place 'num' objects */
1205 for (; num > 0; --num)
1207 /* Try up to 11 spots looking for empty space */
1208 for (i = 0; i < 11; ++i)
1210 /* Pick a random location */
1211 while (dummy < SAFE_MAX_ATTEMPTS)
1213 j = rand_spread(y, 2);
1214 k = rand_spread(x, 3);
1216 if (!in_bounds(floor_ptr, j, k)) continue;
1220 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
1222 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
1225 /* Require "clean" floor space */
1226 g_ptr = &floor_ptr->grid_array[j][k];
1227 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
1229 if (randint0(100) < 75)
1231 place_object(player_ptr, j, k, 0L);
1235 place_gold(floor_ptr, j, k);
1238 /* Placement accomplished */
1245 * @brief 始点から終点への直線経路を返す /
1246 * Determine the path taken by a projection.
1247 * @param player_ptr プレーヤーへの参照ポインタ
1248 * @param gp 経路座標リストを返す参照ポインタ
1258 * The projection will always start from the grid (y1,x1), and will travel
1259 * towards the grid (y2,x2), touching one grid per unit of distance along
1260 * the major axis, and stopping when it enters the destination grid or a
1261 * wall grid, or has travelled the maximum legal distance of "range".
1263 * Note that "distance" in this function (as in the "update_view()" code)
1264 * is defined as "MAX(dy,dx) + MIN(dy,dx)/2", which means that the player
1265 * actually has an "octagon of projection" not a "circle of projection".
1267 * The path grids are saved into the grid array pointed to by "gp", and
1268 * there should be room for at least "range" grids in "gp". Note that
1269 * due to the way in which distance is calculated, this function normally
1270 * uses fewer than "range" grids for the projection path, so the result
1271 * of this function should never be compared directly to "range". Note
1272 * that the initial grid (y1,x1) is never saved into the grid array, not
1273 * even if the initial grid is also the final grid.
1275 * The "flg" flags can be used to modify the behavior of this function.
1277 * In particular, the "PROJECT_STOP" and "PROJECT_THRU" flags have the same
1278 * semantics as they do for the "project" function, namely, that the path
1279 * will stop as soon as it hits a monster, or that the path will continue
1280 * through the destination grid, respectively.
1282 * The "PROJECT_JUMP" flag, which for the "project()" function means to
1283 * start at a special grid (which makes no sense in this function), means
1284 * that the path should be "angled" slightly if needed to avoid any wall
1285 * grids, allowing the player to "target" any grid which is in "view".
1286 * This flag is non-trivial and has not yet been implemented, but could
1287 * perhaps make use of the "vinfo" array (above).
1289 * This function returns the number of grids (if any) in the path. This
1290 * function will return zero if and only if (y1,x1) and (y2,x2) are equal.
1292 * This algorithm is similar to, but slightly different from, the one used
1293 * by "update_view_los()", and very different from the one used by "los()".
1296 sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
1318 /* No path necessary (or allowed) */
1319 if ((x1 == x2) && (y1 == y2)) return (0);
1347 /* Number of "units" in one "half" grid */
1350 /* Number of "units" in one "full" grid */
1356 /* Let m = ((dx/dy) * full) = (dx * dx * 2) */
1367 /* Advance (X) part 2 */
1370 /* Advance (X) part 3 */
1373 /* Track distance */
1377 /* Create the projection path */
1381 gp[n++] = GRID(y, x);
1383 /* Hack -- Check maximum range */
1384 if ((n + (k >> 1)) >= range) break;
1386 /* Sometimes stop at destination grid */
1387 if (!(flg & (PROJECT_THRU)))
1389 if ((x == x2) && (y == y2)) break;
1392 if (flg & (PROJECT_DISI))
1394 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1396 else if (flg & (PROJECT_LOS))
1398 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1400 else if (!(flg & (PROJECT_PATH)))
1402 /* Always stop at non-initial wall grids */
1403 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1406 /* Sometimes stop at non-initial monsters/players */
1407 if (flg & (PROJECT_STOP))
1410 (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1414 if (!in_bounds(floor_ptr, y, x)) break;
1419 /* Advance (X) part 1 */
1422 /* Horizontal change */
1425 /* Advance (X) part 2 */
1428 /* Advance (X) part 3 */
1431 /* Track distance */
1444 /* Let m = ((dy/dx) * full) = (dy * dy * 2) */
1453 /* Vertical change */
1456 /* Advance (Y) part 2 */
1459 /* Advance (Y) part 3 */
1462 /* Track distance */
1466 /* Create the projection path */
1470 gp[n++] = GRID(y, x);
1472 /* Hack -- Check maximum range */
1473 if ((n + (k >> 1)) >= range) break;
1475 /* Sometimes stop at destination grid */
1476 if (!(flg & (PROJECT_THRU)))
1478 if ((x == x2) && (y == y2)) break;
1481 if (flg & (PROJECT_DISI))
1483 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1485 else if (flg & (PROJECT_LOS))
1487 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1489 else if (!(flg & (PROJECT_PATH)))
1491 /* Always stop at non-initial wall grids */
1492 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1495 /* Sometimes stop at non-initial monsters/players */
1496 if (flg & (PROJECT_STOP))
1499 (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1503 if (!in_bounds(floor_ptr, y, x)) break;
1508 /* Advance (Y) part 1 */
1511 /* Vertical change */
1514 /* Advance (Y) part 2 */
1517 /* Advance (Y) part 3 */
1520 /* Track distance */
1537 /* Create the projection path */
1541 gp[n++] = GRID(y, x);
1543 /* Hack -- Check maximum range */
1544 if ((n + (n >> 1)) >= range) break;
1546 /* Sometimes stop at destination grid */
1547 if (!(flg & (PROJECT_THRU)))
1549 if ((x == x2) && (y == y2)) break;
1552 if (flg & (PROJECT_DISI))
1554 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1556 else if (flg & (PROJECT_LOS))
1558 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1560 else if (!(flg & (PROJECT_PATH)))
1562 /* Always stop at non-initial wall grids */
1563 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1566 /* Sometimes stop at non-initial monsters/players */
1567 if (flg & (PROJECT_STOP))
1570 (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1574 if (!in_bounds(floor_ptr, y, x)) break;
1590 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
1591 * @param x 地形を変えたいマスのX座標
1592 * @param y 地形を変えたいマスのY座標
1595 void set_floor(floor_type *floor_ptr, POSITION x, POSITION y)
1597 if (!in_bounds(floor_ptr, y, x))
1603 if (floor_ptr->grid_array[y][x].info & CAVE_ROOM)
1605 /* A room border don't touch. */
1609 /* Set to be floor if is a wall (don't touch lakes). */
1610 if (is_extra_bold(floor_ptr, y, x))
1611 place_floor_bold(floor_ptr, y, x);
1616 * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
1617 * Attempt to place an object (normal or good/great) at the given location.
1618 * @param owner_ptr プレーヤーへの参照ポインタ
1619 * @param y 配置したいフロアのY座標
1620 * @param x 配置したいフロアのX座標
1621 * @param mode オプションフラグ
1622 * @return 生成に成功したらTRUEを返す。
1624 * This routine plays nasty games to generate the "special artifacts".\n
1625 * This routine uses "object_level" for the "generation level".\n
1626 * This routine requires a clean floor grid destination.\n
1628 void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
1630 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
1633 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1638 /* Paranoia -- check bounds */
1639 if (!in_bounds(floor_ptr, y, x)) return;
1641 /* Require floor space */
1642 if (!cave_drop_bold(floor_ptr, y, x)) return;
1644 /* Avoid stacking on other objects */
1645 if (g_ptr->o_idx) return;
1650 /* Make an object (if possible) */
1651 if (!make_object(owner_ptr, q_ptr, mode)) return;
1653 OBJECT_IDX o_idx = o_pop(floor_ptr);
1659 o_ptr = &floor_ptr->o_list[o_idx];
1661 /* Structure Copy */
1662 object_copy(o_ptr, q_ptr);
1668 o_ptr->next_o_idx = g_ptr->o_idx;
1670 g_ptr->o_idx = o_idx;
1676 /* Hack -- Preserve artifacts */
1677 if (object_is_fixed_artifact(q_ptr))
1679 a_info[q_ptr->name1].cur_num = 0;
1687 * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
1688 * Places a treasure (Gold or Gems) at given location
1689 * @param floor_ptr 現在フロアへの参照ポインタ
1690 * @param y 配置したいフロアのY座標
1691 * @param x 配置したいフロアのX座標
1692 * @return 生成に成功したらTRUEを返す。
1694 * The location must be a legal, clean, floor grid.
1696 void place_gold(floor_type *floor_ptr, POSITION y, POSITION x)
1701 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1707 /* Paranoia -- check bounds */
1708 if (!in_bounds(floor_ptr, y, x)) return;
1710 /* Require floor space */
1711 if (!cave_drop_bold(floor_ptr, y, x)) return;
1713 /* Avoid stacking on other objects */
1714 if (g_ptr->o_idx) return;
1719 /* Make some gold */
1720 if (!make_gold(floor_ptr, q_ptr)) return;
1722 o_idx = o_pop(floor_ptr);
1728 o_ptr = &floor_ptr->o_list[o_idx];
1729 object_copy(o_ptr, q_ptr);
1736 o_ptr->next_o_idx = g_ptr->o_idx;
1738 g_ptr->o_idx = o_idx;
1746 * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
1751 void delete_monster(floor_type *floor_ptr, POSITION y, POSITION x)
1754 if (!in_bounds(floor_ptr, y, x)) return;
1756 /* Check the grid */
1757 g_ptr = &floor_ptr->grid_array[y][x];
1759 /* Delete the monster (if any) */
1760 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
1766 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
1767 * Move an object from index i1 to index i2 in the object list
1768 * @param i1 整理したい配列の始点
1769 * @param i2 整理したい配列の終点
1772 static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX i2)
1779 if (i1 == i2) return;
1781 /* Repair objects */
1782 for (i = 1; i < floor_ptr->o_max; i++)
1784 o_ptr = &floor_ptr->o_list[i];
1786 /* Skip "dead" objects */
1787 if (!o_ptr->k_idx) continue;
1789 /* Repair "next" pointers */
1790 if (o_ptr->next_o_idx == i1)
1793 o_ptr->next_o_idx = i2;
1796 o_ptr = &floor_ptr->o_list[i1];
1798 if (OBJECT_IS_HELD_MONSTER(o_ptr))
1800 monster_type *m_ptr;
1801 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1803 /* Repair monster */
1804 if (m_ptr->hold_o_idx == i1)
1807 m_ptr->hold_o_idx = i2;
1816 /* Acquire location */
1821 g_ptr = &floor_ptr->grid_array[y][x];
1824 if (g_ptr->o_idx == i1)
1831 /* Structure copy */
1832 floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
1839 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
1840 * Compact and Reorder the object list.
1841 * @param player_ptr プレーヤーへの参照ポインタ
1842 * @param size 最低でも減らしたいオブジェクト数の水準
1846 * This function can be very dangerous, use with caution!\n
1848 * When actually "compacting" objects, we base the saving throw on a\n
1849 * combination of object level, distance from player, and current\n
1852 * After "compacting" (if needed), we "reorder" the objects into a more\n
1853 * compact order, and we reset the allocation info, and the "live" array.\n
1855 void compact_objects(floor_type *floor_ptr, int size)
1860 int cur_lev, cur_dis, chance;
1866 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
1867 p_ptr->redraw |= (PR_MAP);
1868 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1872 /* Compact at least 'size' objects */
1873 for (num = 0, cnt = 1; num < size; cnt++)
1875 /* Get more vicious each iteration */
1878 /* Get closer each iteration */
1879 cur_dis = 5 * (20 - cnt);
1881 /* Examine the objects */
1882 for (i = 1; i < floor_ptr->o_max; i++)
1884 o_ptr = &floor_ptr->o_list[i];
1886 if (!OBJECT_IS_VALID(o_ptr)) continue;
1888 /* Hack -- High level objects start out "immune" */
1889 if (k_info[o_ptr->k_idx].level > cur_lev) continue;
1891 if (OBJECT_IS_HELD_MONSTER(o_ptr))
1893 monster_type *m_ptr;
1894 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1899 /* Monsters protect their objects */
1900 if (randint0(100) < 90) continue;
1910 /* Nearby objects start out "immune" */
1911 if ((cur_dis > 0) && (distance(p_ptr->y, p_ptr->x, y, x) < cur_dis)) continue;
1916 /* Hack -- only compact artifacts in emergencies */
1917 if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
1918 (cnt < 1000)) chance = 100;
1920 /* Apply the saving throw */
1921 if (randint0(100) < chance) continue;
1923 delete_object_idx(floor_ptr, i);
1931 /* Excise dead objects (backwards!) */
1932 for (i = floor_ptr->o_max - 1; i >= 1; i--)
1934 o_ptr = &floor_ptr->o_list[i];
1936 /* Skip real objects */
1937 if (o_ptr->k_idx) continue;
1939 /* Move last object into open hole */
1940 compact_objects_aux(floor_ptr, floor_ptr->o_max - 1, i);
1942 /* Compress "floor_ptr->o_max" */
1948 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
1949 * @param player_ptr プレーヤーへの参照ポインタ
1950 * @param y トラップを配置したいマスの中心Y座標
1951 * @param x トラップを配置したいマスの中心X座標
1952 * @param yd Y方向の配置分散マス数
1953 * @param xd X方向の配置分散マス数
1954 * @param num 配置したいトラップの数
1957 * Only really called by some of the "vault" routines.
1959 void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
1963 for (i = 0; i < num; i++)
1965 vault_trap_aux(player_ptr, y, x, yd, xd);
1971 * Standard "find me a location" function
1973 * Obtains a legal location within the given distance of the initial
1974 * location, and with "los()" from the source to destination location.
1976 * This function is often called from inside a loop which searches for
1977 * locations while increasing the "d" distance.
1979 * Currently the "m" parameter is unused.
1981 void scatter(floor_type *floor_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
1985 /* Pick a location */
1988 /* Pick a new location */
1989 ny = rand_spread(y, d);
1990 nx = rand_spread(x, d);
1992 /* Ignore annoying locations */
1993 if (!in_bounds(floor_ptr, ny, nx)) continue;
1995 /* Ignore "excessively distant" locations */
1996 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
1998 if (mode & PROJECT_LOS)
2000 if (los(floor_ptr, y, x, ny, nx)) break;
2004 if (projectable(floor_ptr, y, x, ny, nx)) break;
2009 /* Save the location */