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 y 配置したいフロアのY座標
56 * @param x 配置したいフロアのX座標
57 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
60 void place_secret_door(floor_type *floor_ptr, POSITION y, POSITION x, int type)
62 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
64 place_floor_bold(floor_ptr, y, x);
68 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
70 if (type == DOOR_DEFAULT)
72 type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
73 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
74 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
77 /* Create secret door */
78 place_closed_door(floor_ptr, y, x, type);
80 if (type != DOOR_CURTAIN)
82 /* Hide by inner wall because this is used in rooms only */
83 g_ptr->mimic = feat_wall_inner;
85 /* Floor type terrain cannot hide a door */
86 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
88 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
90 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
96 g_ptr->info &= ~(CAVE_FLOOR);
97 delete_monster(floor_ptr, y, x);
101 static int scent_when = 0;
104 * Characters leave scent trails for perceptive monsters to track.
106 * Smell is rather more limited than sound. Many creatures cannot use
107 * it at all, it doesn't extend very far outwards from the character's
108 * current position, and monsters can use it to home in the character,
109 * but not to run away from him.
111 * Smell is valued according to age. When a character takes his turn,
112 * scent is aged by one, and new scent of the current age is laid down.
113 * Speedy characters leave more scent, true, but it also ages faster,
114 * which makes it harder to hunt them down.
116 * Whenever the age count loops, most of the scent trail is erased and
117 * the age of the remainder is recalculated.
119 void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
124 /* Create a table that controls the spread of scent */
125 const int scent_adjust[5][5] =
134 /* Loop the age and adjust scent values when necessary */
135 if (++scent_when == 254)
137 /* Scan the entire dungeon */
138 for (y = 0; y < floor_ptr->height; y++)
140 for (x = 0; x < floor_ptr->width; x++)
142 int w = floor_ptr->grid_array[y][x].when;
143 floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
152 /* Lay down new scent */
153 for (i = 0; i < 5; i++)
155 for (j = 0; j < 5; j++)
159 /* Translate table to map grids */
160 y = i + subject_ptr->y - 2;
161 x = j + subject_ptr->x - 2;
164 if (!in_bounds(floor_ptr, y, x)) continue;
166 g_ptr = &floor_ptr->grid_array[y][x];
168 /* Walls, water, and lava cannot hold scent. */
169 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
171 /* Grid must not be blocked by walls from the character */
172 if (!player_has_los_bold(subject_ptr, y, x)) continue;
174 /* Note grids that are too far away */
175 if (scent_adjust[i][j] == -1) continue;
177 /* Mark the grid with new scent */
178 g_ptr->when = scent_when + scent_adjust[i][j];
185 * Hack -- forget the "flow" information
187 void forget_flow(floor_type *floor_ptr)
191 /* Check the entire dungeon */
192 for (y = 0; y < floor_ptr->height; y++)
194 for (x = 0; x < floor_ptr->width; x++)
196 /* Forget the old data */
197 floor_ptr->grid_array[y][x].dist = 0;
198 floor_ptr->grid_array[y][x].cost = 0;
199 floor_ptr->grid_array[y][x].when = 0;
205 * Routine used by the random vault creators to add a door to a location
206 * Note that range checking has to be done in the calling routine.
208 * The doors must be INSIDE the allocated region.
210 void add_door(floor_type* floor_ptr, POSITION x, POSITION y)
212 /* Need to have a wall in the center square */
213 if (!is_outer_bold(floor_ptr, y, x)) return;
224 if (is_floor_bold(floor_ptr, y - 1, x) && is_floor_bold(floor_ptr, y + 1, x) &&
225 (is_outer_bold(floor_ptr, y, x - 1) && is_outer_bold(floor_ptr, y, x + 1)))
228 place_secret_door(floor_ptr, y, x, DOOR_DEFAULT);
230 /* set boundarys so don't get wide doors */
231 place_solid_bold(floor_ptr, y, x - 1);
232 place_solid_bold(floor_ptr, y, x + 1);
241 * where x = don't care
244 if (is_outer_bold(floor_ptr, y - 1, x) && is_outer_bold(floor_ptr, y + 1, x) &&
245 is_floor_bold(floor_ptr, y, x - 1) && is_floor_bold(floor_ptr, y, x + 1))
248 place_secret_door(floor_ptr, y, x, DOOR_DEFAULT);
250 /* set boundarys so don't get wide doors */
251 place_solid_bold(floor_ptr, y - 1, x);
252 place_solid_bold(floor_ptr, y + 1, x);
257 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
258 * @param player_ptr プレーヤーへの参照ポインタ
259 * @param y 配置を試みたいマスのY座標
260 * @param x 配置を試みたいマスのX座標
263 void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
265 bool up_stairs = TRUE;
266 bool down_stairs = TRUE;
268 floor_type *floor_ptr = player_ptr->current_floor_ptr;
269 g_ptr = &floor_ptr->grid_array[y][x];
270 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
272 if (!floor_ptr->dun_level) up_stairs = FALSE;
273 if (ironman_downward) up_stairs = FALSE;
274 if (floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
275 if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1)) down_stairs = FALSE;
277 /* We can't place both */
278 if (down_stairs && up_stairs)
280 /* Choose a staircase randomly */
281 if (randint0(100) < 50) up_stairs = FALSE;
282 else down_stairs = FALSE;
285 /* Place the stairs */
286 if (up_stairs) set_cave_feat(floor_ptr, y, x, feat_up_stair);
287 else if (down_stairs) set_cave_feat(floor_ptr, y, x, feat_down_stair);
291 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
296 * @return LOSが通っているならTRUEを返す。
298 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
299 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
301 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
303 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
304 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
305 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
307 * We assume that the "mathematical corner" of a non-floor tile does not\n
308 * block line of sight.\n
310 * Because this function uses (short) ints for all calculations, overflow may\n
311 * occur if dx and dy exceed 90.\n
313 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
314 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
315 * we can use integer arithmetic.\n
317 * We travel from start to finish along the longer axis, starting at the border\n
318 * between the first and second tiles, where the y offset = .5 * slope, taking\n
319 * into account the scale factor. See below.\n
321 * Also note that this function and the "move towards target" code do NOT\n
322 * share the same properties. Thus, you can see someone, target them, and\n
323 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
324 * by clever choice of target locations, you can sometimes throw a "curve".\n
326 * Note that "line of sight" is not "reflexive" in all cases.\n
328 * Use the "projectable()" routine to test "spell/missile line of sight".\n
330 * Use the "update_view()" function to determine player line-of-sight.\n
332 bool los(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
352 /* Slope, or 1/Slope, of LOS */
356 /* Extract the offset */
360 /* Extract the absolute offset */
365 /* Handle adjacent (or identical) grids */
366 if ((ax < 2) && (ay < 2)) return TRUE;
369 /* Paranoia -- require "safe" origin */
370 /* if (!in_bounds(floor_ptr, y1, x1)) return FALSE; */
371 /* if (!in_bounds(floor_ptr, y2, x2)) return FALSE; */
374 /* Directly South/North */
377 /* South -- check for walls */
380 for (ty = y1 + 1; ty < y2; ty++)
382 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
386 /* North -- check for walls */
389 for (ty = y1 - 1; ty > y2; ty--)
391 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
399 /* Directly East/West */
402 /* East -- check for walls */
405 for (tx = x1 + 1; tx < x2; tx++)
407 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
411 /* West -- check for walls */
414 for (tx = x1 - 1; tx > x2; tx--)
416 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
425 /* Extract some signs */
426 sx = (dx < 0) ? -1 : 1;
427 sy = (dy < 0) ? -1 : 1;
430 /* Vertical "knights" */
435 if (cave_los_bold(floor_ptr, y1 + sy, x1)) return TRUE;
439 /* Horizontal "knights" */
444 if (cave_los_bold(floor_ptr, y1, x1 + sx)) return TRUE;
449 /* Calculate scale factor div 2 */
452 /* Calculate scale factor */
456 /* Travel horizontally */
459 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
465 /* Consider the special case where slope == 1. */
476 /* Note (below) the case (qy == f2), where */
477 /* the LOS exactly meets the corner of a tile. */
480 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
491 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
504 /* Travel vertically */
507 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
523 /* Note (below) the case (qx == f2), where */
524 /* the LOS exactly meets the corner of a tile. */
527 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
538 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
557 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
558 * at the final destination, assuming no monster gets in the way.
560 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
562 bool projectable(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
569 /* Check the projection path */
570 grid_n = project_path(floor_ptr, grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
573 if (!grid_n) return TRUE;
576 y = GRID_Y(grid_g[grid_n - 1]);
577 x = GRID_X(grid_g[grid_n - 1]);
579 /* May not end in an unrequested grid */
580 if ((y != y2) || (x != x2)) return FALSE;
588 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
589 * @param y1 モンスターを配置したいマスの中心Y座標
590 * @param x1 モンスターを配置したいマスの中心X座標
591 * @param num 配置したいモンスターの数
594 * Only really called by some of the "vault" routines.
596 void vault_monsters(floor_type *floor_ptr, POSITION y1, POSITION x1, int num)
602 /* Try to summon "num" monsters "near" the given location */
603 for (k = 0; k < num; k++)
605 /* Try nine locations */
606 for (i = 0; i < 9; i++)
610 /* Pick a nearby location */
611 scatter(floor_ptr, &y, &x, y1, x1, d, 0);
613 /* Require "empty" floor grids */
614 g_ptr = &floor_ptr->grid_array[y][x];
615 if (!cave_empty_grid(g_ptr)) continue;
617 /* Place the monster (allow groups) */
618 floor_ptr->monster_level = floor_ptr->base_level + 2;
619 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
620 floor_ptr->monster_level = floor_ptr->base_level;
627 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
628 * @param player_ptr プレーヤーへの参照ポインタ
631 * @return 各種の変更が可能ならTRUEを返す。
633 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
635 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
637 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
638 OBJECT_IDX this_o_idx, next_o_idx = 0;
640 /* Forbid perma-grids */
641 if (cave_perma_grid(g_ptr)) return FALSE;
644 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
647 o_ptr = &floor_ptr->o_list[this_o_idx];
648 next_o_idx = o_ptr->next_o_idx;
650 /* Forbid artifact grids */
651 if (object_is_artifact(o_ptr)) return FALSE;
659 * Change the "feat" flag for a grid, and notice/redraw the grid
661 void cave_set_feat(floor_type *floor_ptr, POSITION y, POSITION x, FEAT_IDX feat)
663 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
664 feature_type *f_ptr = &f_info[feat];
665 bool old_los, old_mirror;
667 if (!current_world_ptr->character_dungeon)
669 /* Clear mimic type */
672 /* Change the feature */
675 /* Hack -- glow the GLOW terrain */
676 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
681 for (i = 0; i < 9; i++)
685 if (!in_bounds2(floor_ptr, yy, xx)) continue;
686 floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
693 old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
694 old_mirror = is_mirror_grid(g_ptr);
696 /* Clear mimic type */
699 /* Change the feature */
702 /* Remove flag for mirror/glyph */
703 g_ptr->info &= ~(CAVE_OBJECT);
705 if (old_mirror && (d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
707 g_ptr->info &= ~(CAVE_GLOW);
708 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
710 update_local_illumination(p_ptr, y, x);
713 /* Check for change to boring grid */
714 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
715 if (g_ptr->m_idx) update_monster(p_ptr, g_ptr->m_idx, FALSE);
720 /* Check if los has changed */
721 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
724 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
726 update_local_illumination(p_ptr, y, x);
728 #endif /* COMPLEX_WALL_ILLUMINATION */
730 /* Update the visuals */
731 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
734 /* Hack -- glow the GLOW terrain */
735 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
741 for (i = 0; i < 9; i++)
745 if (!in_bounds2(floor_ptr, yy, xx)) continue;
746 cc_ptr = &floor_ptr->grid_array[yy][xx];
747 cc_ptr->info |= CAVE_GLOW;
749 if (player_has_los_grid(cc_ptr))
751 if (cc_ptr->m_idx) update_monster(p_ptr, cc_ptr->m_idx, FALSE);
756 update_local_illumination(p_ptr, yy, xx);
759 if (p_ptr->special_defense & NINJA_S_STEALTH)
761 if (floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(p_ptr, FALSE);
768 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
769 * @param y ドアの配置を試みたいマスのY座標
770 * @param x ドアの配置を試みたいマスのX座標
771 * @param room 部屋に接している場合向けのドア生成か否か
774 void place_random_door(floor_type *floor_ptr, POSITION y, POSITION x, bool room)
777 FEAT_IDX feat = feat_none;
778 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
780 /* Initialize mimic info */
783 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
785 place_floor_bold(floor_ptr, y, x);
789 type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
790 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
791 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
793 /* Choose an object */
794 tmp = randint0(1000);
796 /* Open doors (300/1000) */
799 /* Create open door */
800 feat = feat_door[type].open;
803 /* Broken doors (100/1000) */
806 /* Create broken door */
807 feat = feat_door[type].broken;
810 /* Secret doors (200/1000) */
813 /* Create secret door */
814 place_closed_door(floor_ptr, y, x, type);
816 if (type != DOOR_CURTAIN)
818 /* Hide. If on the edge of room, use outer wall. */
819 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
821 /* Floor type terrain cannot hide a door */
822 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
824 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
826 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
833 /* Closed, locked, or stuck doors (400/1000) */
834 else place_closed_door(floor_ptr, y, x, type);
838 if (feat != feat_none)
840 set_cave_feat(floor_ptr, y, x, feat);
844 place_floor_bold(floor_ptr, y, x);
848 delete_monster(floor_ptr, y, x);
854 * @brief グローバルオブジェクト配列を初期化する /
855 * Delete all the items when player leaves the level
856 * @note we do NOT visually reflect these (irrelevant) changes
858 * Hack -- we clear the "g_ptr->o_idx" field for every grid,
859 * and the "m_ptr->next_o_idx" field for every monster, since
860 * we know we are clearing every object. Technically, we only
861 * clear those fields for grids/monsters containing objects,
862 * and we clear it once for every such object.
865 void wipe_o_list(floor_type *floor_ptr)
869 /* Delete the existing objects */
870 for (i = 1; i < floor_ptr->o_max; i++)
872 object_type *o_ptr = &floor_ptr->o_list[i];
874 if (!OBJECT_IS_VALID(o_ptr)) continue;
876 /* Mega-Hack -- preserve artifacts */
877 if (!current_world_ptr->character_dungeon || preserve_mode)
879 /* Hack -- Preserve unknown artifacts */
880 if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
882 /* Mega-Hack -- Preserve the artifact */
883 a_info[o_ptr->name1].cur_num = 0;
887 if (OBJECT_IS_HELD_MONSTER(o_ptr))
890 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
892 /* Hack -- see above */
893 m_ptr->hold_o_idx = 0;
901 /* Access location */
902 POSITION y = o_ptr->iy;
903 POSITION x = o_ptr->ix;
906 g_ptr = &floor_ptr->grid_array[y][x];
908 /* Hack -- see above */
914 /* Reset "floor_ptr->o_max" */
915 floor_ptr->o_max = 1;
917 /* Reset "floor_ptr->o_cnt" */
918 floor_ptr->o_cnt = 0;
923 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
924 * @param y ドアの配置を試みたいマスのY座標
925 * @param x ドアの配置を試みたいマスのX座標
926 * @param type ドアの地形ID
929 void place_closed_door(floor_type *floor_ptr, POSITION y, POSITION x, int type)
932 FEAT_IDX feat = feat_none;
934 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
936 place_floor_bold(floor_ptr, y, x);
940 /* Choose an object */
943 /* Closed doors (300/400) */
946 /* Create closed door */
947 feat = feat_door[type].closed;
950 /* Locked doors (99/400) */
953 /* Create locked door */
954 feat = feat_locked_door_random(type);
957 /* Stuck doors (1/400) */
960 /* Create jammed door */
961 feat = feat_jammed_door_random(type);
964 if (feat != feat_none)
966 cave_set_feat(floor_ptr, y, x, feat);
968 /* Now it is not floor */
969 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
973 place_floor_bold(floor_ptr, y, x);
978 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
979 * @param y トラップを配置したいマスの中心Y座標
980 * @param x トラップを配置したいマスの中心X座標
981 * @param yd Y方向の配置分散マス数
982 * @param xd X方向の配置分散マス数
985 * Only really called by some of the "vault" routines.
987 void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
989 int count = 0, y1 = y, x1 = x;
995 floor_type *floor_ptr = player_ptr->current_floor_ptr;
996 for (count = 0; count <= 5; count++)
999 while (dummy < SAFE_MAX_ATTEMPTS)
1001 y1 = rand_spread(y, yd);
1002 x1 = rand_spread(x, xd);
1004 if (!in_bounds(floor_ptr, y1, x1)) continue;
1008 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
1010 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
1013 /* Require "naked" floor grids */
1014 g_ptr = &floor_ptr->grid_array[y1][x1];
1015 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
1017 /* Place the trap */
1018 place_trap(player_ptr, y1, x1);
1025 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
1026 * @param x チェックするマスのX座標
1027 * @param y チェックするマスのY座標
1028 * @return 床系地形ならばTRUE
1030 bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
1032 if (!in_bounds(floor_ptr, y, x))
1038 /* Do the real check */
1039 if (is_floor_bold(floor_ptr, y, x)) return TRUE;
1045 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
1046 * @param y1 基準となるマスのY座標
1047 * @param x1 基準となるマスのX座標
1049 * @note Assumes "in_bounds(y1, x1)"
1051 * XXX XXX This routine currently only counts actual "empty floor"\n
1052 * grids which are not in rooms. We might want to also count stairs,\n
1053 * open doors, closed doors, etc.
1055 static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
1062 /* Scan adjacent grids */
1063 for (i = 0; i < 4; i++)
1065 y = y1 + ddy_ddd[i];
1066 x = x1 + ddx_ddd[i];
1067 g_ptr = &floor_ptr->grid_array[y][x];
1069 /* Skip non floors */
1070 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
1072 /* Skip non "empty floor" grids */
1073 if (!is_floor_grid(g_ptr))
1076 /* Skip grids inside rooms */
1077 if (g_ptr->info & (CAVE_ROOM)) continue;
1079 /* Count these grids */
1083 /* Return the number of corridors */
1088 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
1089 * @param y 判定を行いたいマスのY座標
1090 * @param x 判定を行いたいマスのX座標
1091 * @return ドアを設置可能ならばTRUEを返す
1092 * @note Assumes "in_bounds()"
1095 * Assumes "in_bounds()"\n
1097 static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
1099 /* Count the adjacent corridors */
1100 if (next_to_corr(floor_ptr, y, x) >= 2)
1102 /* Check Vertical */
1103 if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) &&
1104 cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
1109 /* Check Horizontal */
1110 if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) &&
1111 cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
1122 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
1123 * @param player_ptr プレーヤーへの参照ポインタ
1124 * @param y 設置を行いたいマスのY座標
1125 * @param x 設置を行いたいマスのX座標
1128 void try_door(floor_type *floor_ptr, POSITION y, POSITION x)
1130 if (!in_bounds(floor_ptr, y, x)) return;
1133 if (cave_have_flag_bold(floor_ptr, y, x, FF_WALL)) return;
1135 /* Ignore room grids */
1136 if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
1138 /* Occasional door (if allowed) */
1139 if ((randint0(100) < dun_tun_jct) && possible_doorway(floor_ptr, y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
1142 place_random_door(floor_ptr, y, x, FALSE);
1147 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
1149 feature_type *f_ptr = &f_info[newfeat];
1151 if (have_flag(f_ptr->flags, FF_CONVERT))
1153 switch (f_ptr->subtype)
1155 case CONVERT_TYPE_FLOOR:
1156 return feat_ground_type[randint0(100)];
1157 case CONVERT_TYPE_WALL:
1158 return feat_wall_type[randint0(100)];
1159 case CONVERT_TYPE_INNER:
1160 return feat_wall_inner;
1161 case CONVERT_TYPE_OUTER:
1162 return feat_wall_outer;
1163 case CONVERT_TYPE_SOLID:
1164 return feat_wall_solid;
1165 case CONVERT_TYPE_STREAM1:
1166 return d_info[floor_ptr->dungeon_idx].stream1;
1167 case CONVERT_TYPE_STREAM2:
1168 return d_info[floor_ptr->dungeon_idx].stream2;
1173 else return newfeat;
1178 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
1179 * @param player_ptr プレーヤーへの参照ポインタ
1180 * @param y 配置したい中心マスのY座標
1181 * @param x 配置したい中心マスのX座標
1185 * Only really called by some of the "vault" routines.
1187 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
1190 int i = 0, j = y, k = x;
1193 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1195 /* Attempt to place 'num' objects */
1196 for (; num > 0; --num)
1198 /* Try up to 11 spots looking for empty space */
1199 for (i = 0; i < 11; ++i)
1201 /* Pick a random location */
1202 while (dummy < SAFE_MAX_ATTEMPTS)
1204 j = rand_spread(y, 2);
1205 k = rand_spread(x, 3);
1207 if (!in_bounds(floor_ptr, j, k)) continue;
1211 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
1213 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
1216 /* Require "clean" floor space */
1217 g_ptr = &floor_ptr->grid_array[j][k];
1218 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
1220 if (randint0(100) < 75)
1222 place_object(player_ptr, j, k, 0L);
1226 place_gold(floor_ptr, j, k);
1229 /* Placement accomplished */
1236 * @brief 始点から終点への直線経路を返す /
1237 * Determine the path taken by a projection.
1238 * @param player_ptr プレーヤーへの参照ポインタ
1239 * @param gp 経路座標リストを返す参照ポインタ
1249 * The projection will always start from the grid (y1,x1), and will travel
1250 * towards the grid (y2,x2), touching one grid per unit of distance along
1251 * the major axis, and stopping when it enters the destination grid or a
1252 * wall grid, or has travelled the maximum legal distance of "range".
1254 * Note that "distance" in this function (as in the "update_view()" code)
1255 * is defined as "MAX(dy,dx) + MIN(dy,dx)/2", which means that the player
1256 * actually has an "octagon of projection" not a "circle of projection".
1258 * The path grids are saved into the grid array pointed to by "gp", and
1259 * there should be room for at least "range" grids in "gp". Note that
1260 * due to the way in which distance is calculated, this function normally
1261 * uses fewer than "range" grids for the projection path, so the result
1262 * of this function should never be compared directly to "range". Note
1263 * that the initial grid (y1,x1) is never saved into the grid array, not
1264 * even if the initial grid is also the final grid.
1266 * The "flg" flags can be used to modify the behavior of this function.
1268 * In particular, the "PROJECT_STOP" and "PROJECT_THRU" flags have the same
1269 * semantics as they do for the "project" function, namely, that the path
1270 * will stop as soon as it hits a monster, or that the path will continue
1271 * through the destination grid, respectively.
1273 * The "PROJECT_JUMP" flag, which for the "project()" function means to
1274 * start at a special grid (which makes no sense in this function), means
1275 * that the path should be "angled" slightly if needed to avoid any wall
1276 * grids, allowing the player to "target" any grid which is in "view".
1277 * This flag is non-trivial and has not yet been implemented, but could
1278 * perhaps make use of the "vinfo" array (above).
1280 * This function returns the number of grids (if any) in the path. This
1281 * function will return zero if and only if (y1,x1) and (y2,x2) are equal.
1283 * This algorithm is similar to, but slightly different from, the one used
1284 * by "update_view_los()", and very different from the one used by "los()".
1287 sint project_path(floor_type *floor_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
1309 /* No path necessary (or allowed) */
1310 if ((x1 == x2) && (y1 == y2)) return (0);
1338 /* Number of "units" in one "half" grid */
1341 /* Number of "units" in one "full" grid */
1347 /* Let m = ((dx/dy) * full) = (dx * dx * 2) */
1358 /* Advance (X) part 2 */
1361 /* Advance (X) part 3 */
1364 /* Track distance */
1368 /* Create the projection path */
1372 gp[n++] = GRID(y, x);
1374 /* Hack -- Check maximum range */
1375 if ((n + (k >> 1)) >= range) break;
1377 /* Sometimes stop at destination grid */
1378 if (!(flg & (PROJECT_THRU)))
1380 if ((x == x2) && (y == y2)) break;
1383 if (flg & (PROJECT_DISI))
1385 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1387 else if (flg & (PROJECT_LOS))
1389 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1391 else if (!(flg & (PROJECT_PATH)))
1393 /* Always stop at non-initial wall grids */
1394 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1397 /* Sometimes stop at non-initial monsters/players */
1398 if (flg & (PROJECT_STOP))
1401 (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1405 if (!in_bounds(floor_ptr, y, x)) break;
1410 /* Advance (X) part 1 */
1413 /* Horizontal change */
1416 /* Advance (X) part 2 */
1419 /* Advance (X) part 3 */
1422 /* Track distance */
1435 /* Let m = ((dy/dx) * full) = (dy * dy * 2) */
1444 /* Vertical change */
1447 /* Advance (Y) part 2 */
1450 /* Advance (Y) part 3 */
1453 /* Track distance */
1457 /* Create the projection path */
1461 gp[n++] = GRID(y, x);
1463 /* Hack -- Check maximum range */
1464 if ((n + (k >> 1)) >= range) break;
1466 /* Sometimes stop at destination grid */
1467 if (!(flg & (PROJECT_THRU)))
1469 if ((x == x2) && (y == y2)) break;
1472 if (flg & (PROJECT_DISI))
1474 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1476 else if (flg & (PROJECT_LOS))
1478 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1480 else if (!(flg & (PROJECT_PATH)))
1482 /* Always stop at non-initial wall grids */
1483 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1486 /* Sometimes stop at non-initial monsters/players */
1487 if (flg & (PROJECT_STOP))
1490 (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1494 if (!in_bounds(floor_ptr, y, x)) break;
1499 /* Advance (Y) part 1 */
1502 /* Vertical change */
1505 /* Advance (Y) part 2 */
1508 /* Advance (Y) part 3 */
1511 /* Track distance */
1528 /* Create the projection path */
1532 gp[n++] = GRID(y, x);
1534 /* Hack -- Check maximum range */
1535 if ((n + (n >> 1)) >= range) break;
1537 /* Sometimes stop at destination grid */
1538 if (!(flg & (PROJECT_THRU)))
1540 if ((x == x2) && (y == y2)) break;
1543 if (flg & (PROJECT_DISI))
1545 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1547 else if (flg & (PROJECT_LOS))
1549 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1551 else if (!(flg & (PROJECT_PATH)))
1553 /* Always stop at non-initial wall grids */
1554 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1557 /* Sometimes stop at non-initial monsters/players */
1558 if (flg & (PROJECT_STOP))
1561 (player_bold(p_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1565 if (!in_bounds(floor_ptr, y, x)) break;
1581 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
1582 * @param x 地形を変えたいマスのX座標
1583 * @param y 地形を変えたいマスのY座標
1586 void set_floor(floor_type *floor_ptr, POSITION x, POSITION y)
1588 if (!in_bounds(floor_ptr, y, x))
1594 if (floor_ptr->grid_array[y][x].info & CAVE_ROOM)
1596 /* A room border don't touch. */
1600 /* Set to be floor if is a wall (don't touch lakes). */
1601 if (is_extra_bold(floor_ptr, y, x))
1602 place_floor_bold(floor_ptr, y, x);
1607 * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
1608 * Attempt to place an object (normal or good/great) at the given location.
1609 * @param owner_ptr プレーヤーへの参照ポインタ
1610 * @param y 配置したいフロアのY座標
1611 * @param x 配置したいフロアのX座標
1612 * @param mode オプションフラグ
1613 * @return 生成に成功したらTRUEを返す。
1615 * This routine plays nasty games to generate the "special artifacts".\n
1616 * This routine uses "object_level" for the "generation level".\n
1617 * This routine requires a clean floor grid destination.\n
1619 void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
1621 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
1624 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1629 /* Paranoia -- check bounds */
1630 if (!in_bounds(floor_ptr, y, x)) return;
1632 /* Require floor space */
1633 if (!cave_drop_bold(floor_ptr, y, x)) return;
1635 /* Avoid stacking on other objects */
1636 if (g_ptr->o_idx) return;
1641 /* Make an object (if possible) */
1642 if (!make_object(owner_ptr, q_ptr, mode)) return;
1644 OBJECT_IDX o_idx = o_pop(floor_ptr);
1650 o_ptr = &floor_ptr->o_list[o_idx];
1652 /* Structure Copy */
1653 object_copy(o_ptr, q_ptr);
1659 o_ptr->next_o_idx = g_ptr->o_idx;
1661 g_ptr->o_idx = o_idx;
1667 /* Hack -- Preserve artifacts */
1668 if (object_is_fixed_artifact(q_ptr))
1670 a_info[q_ptr->name1].cur_num = 0;
1678 * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
1679 * Places a treasure (Gold or Gems) at given location
1680 * @param floor_ptr 現在フロアへの参照ポインタ
1681 * @param y 配置したいフロアのY座標
1682 * @param x 配置したいフロアのX座標
1683 * @return 生成に成功したらTRUEを返す。
1685 * The location must be a legal, clean, floor grid.
1687 void place_gold(floor_type *floor_ptr, POSITION y, POSITION x)
1692 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1698 /* Paranoia -- check bounds */
1699 if (!in_bounds(floor_ptr, y, x)) return;
1701 /* Require floor space */
1702 if (!cave_drop_bold(floor_ptr, y, x)) return;
1704 /* Avoid stacking on other objects */
1705 if (g_ptr->o_idx) return;
1710 /* Make some gold */
1711 if (!make_gold(floor_ptr, q_ptr)) return;
1713 o_idx = o_pop(floor_ptr);
1719 o_ptr = &floor_ptr->o_list[o_idx];
1720 object_copy(o_ptr, q_ptr);
1727 o_ptr->next_o_idx = g_ptr->o_idx;
1729 g_ptr->o_idx = o_idx;
1737 * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
1742 void delete_monster(floor_type *floor_ptr, POSITION y, POSITION x)
1745 if (!in_bounds(floor_ptr, y, x)) return;
1747 /* Check the grid */
1748 g_ptr = &floor_ptr->grid_array[y][x];
1750 /* Delete the monster (if any) */
1751 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
1757 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
1758 * Move an object from index i1 to index i2 in the object list
1759 * @param i1 整理したい配列の始点
1760 * @param i2 整理したい配列の終点
1763 static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX i2)
1770 if (i1 == i2) return;
1772 /* Repair objects */
1773 for (i = 1; i < floor_ptr->o_max; i++)
1775 o_ptr = &floor_ptr->o_list[i];
1777 /* Skip "dead" objects */
1778 if (!o_ptr->k_idx) continue;
1780 /* Repair "next" pointers */
1781 if (o_ptr->next_o_idx == i1)
1784 o_ptr->next_o_idx = i2;
1787 o_ptr = &floor_ptr->o_list[i1];
1789 if (OBJECT_IS_HELD_MONSTER(o_ptr))
1791 monster_type *m_ptr;
1792 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1794 /* Repair monster */
1795 if (m_ptr->hold_o_idx == i1)
1798 m_ptr->hold_o_idx = i2;
1807 /* Acquire location */
1812 g_ptr = &floor_ptr->grid_array[y][x];
1815 if (g_ptr->o_idx == i1)
1822 /* Structure copy */
1823 floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
1830 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
1831 * Compact and Reorder the object list.
1832 * @param player_ptr プレーヤーへの参照ポインタ
1833 * @param size 最低でも減らしたいオブジェクト数の水準
1837 * This function can be very dangerous, use with caution!\n
1839 * When actually "compacting" objects, we base the saving throw on a\n
1840 * combination of object level, distance from player, and current\n
1843 * After "compacting" (if needed), we "reorder" the objects into a more\n
1844 * compact order, and we reset the allocation info, and the "live" array.\n
1846 void compact_objects(floor_type *floor_ptr, int size)
1851 int cur_lev, cur_dis, chance;
1857 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
1858 p_ptr->redraw |= (PR_MAP);
1859 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1863 /* Compact at least 'size' objects */
1864 for (num = 0, cnt = 1; num < size; cnt++)
1866 /* Get more vicious each iteration */
1869 /* Get closer each iteration */
1870 cur_dis = 5 * (20 - cnt);
1872 /* Examine the objects */
1873 for (i = 1; i < floor_ptr->o_max; i++)
1875 o_ptr = &floor_ptr->o_list[i];
1877 if (!OBJECT_IS_VALID(o_ptr)) continue;
1879 /* Hack -- High level objects start out "immune" */
1880 if (k_info[o_ptr->k_idx].level > cur_lev) continue;
1882 if (OBJECT_IS_HELD_MONSTER(o_ptr))
1884 monster_type *m_ptr;
1885 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1890 /* Monsters protect their objects */
1891 if (randint0(100) < 90) continue;
1901 /* Nearby objects start out "immune" */
1902 if ((cur_dis > 0) && (distance(p_ptr->y, p_ptr->x, y, x) < cur_dis)) continue;
1907 /* Hack -- only compact artifacts in emergencies */
1908 if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
1909 (cnt < 1000)) chance = 100;
1911 /* Apply the saving throw */
1912 if (randint0(100) < chance) continue;
1914 delete_object_idx(floor_ptr, i);
1922 /* Excise dead objects (backwards!) */
1923 for (i = floor_ptr->o_max - 1; i >= 1; i--)
1925 o_ptr = &floor_ptr->o_list[i];
1927 /* Skip real objects */
1928 if (o_ptr->k_idx) continue;
1930 /* Move last object into open hole */
1931 compact_objects_aux(floor_ptr, floor_ptr->o_max - 1, i);
1933 /* Compress "floor_ptr->o_max" */
1939 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
1940 * @param player_ptr プレーヤーへの参照ポインタ
1941 * @param y トラップを配置したいマスの中心Y座標
1942 * @param x トラップを配置したいマスの中心X座標
1943 * @param yd Y方向の配置分散マス数
1944 * @param xd X方向の配置分散マス数
1945 * @param num 配置したいトラップの数
1948 * Only really called by some of the "vault" routines.
1950 void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
1954 for (i = 0; i < num; i++)
1956 vault_trap_aux(player_ptr, y, x, yd, xd);
1962 * Standard "find me a location" function
1964 * Obtains a legal location within the given distance of the initial
1965 * location, and with "los()" from the source to destination location.
1967 * This function is often called from inside a loop which searches for
1968 * locations while increasing the "d" distance.
1970 * Currently the "m" parameter is unused.
1972 void scatter(floor_type *floor_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
1976 /* Pick a location */
1979 /* Pick a new location */
1980 ny = rand_spread(y, d);
1981 nx = rand_spread(x, d);
1983 /* Ignore annoying locations */
1984 if (!in_bounds(floor_ptr, ny, nx)) continue;
1986 /* Ignore "excessively distant" locations */
1987 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
1989 if (mode & PROJECT_LOS)
1991 if (los(floor_ptr, y, x, ny, nx)) break;
1995 if (projectable(floor_ptr, y, x, ny, nx)) break;
2000 /* Save the location */