1 #include "floor/floor.h"
2 #include "dungeon/dungeon.h"
3 #include "dungeon/quest.h"
4 #include "effect/effect-characteristics.h"
5 #include "effect/spells-effect-util.h"
6 #include "floor/floor-generate.h"
7 #include "floor/floor-object.h"
10 #include "object-enchant/artifact.h"
11 #include "object/object-appraiser.h"
12 #include "object/object-generator.h"
13 #include "object/object-hook.h"
14 #include "object/object-kind.h"
15 #include "object/object1.h"
16 #include "object-enchant/special-object-flags.h"
17 #include "player/player-effects.h"
18 #include "room/rooms.h"
19 #include "world/world-object.h"
20 #include "world/world.h"
23 * The array of floor [MAX_WID][MAX_HGT].
24 * Not completely allocated, that would be inefficient
25 * Not completely hardcoded, that would overflow memory
27 floor_type floor_info;
30 * The array of saved floors
32 saved_floor_type saved_floors[MAX_SAVED_FLOORS];
35 * Grid based version of "cave_empty_bold()"
37 bool is_cave_empty_grid(player_type *player_ptr, grid_type *g_ptr)
39 bool is_empty_grid = cave_have_flag_grid(g_ptr, FF_PLACE);
40 is_empty_grid &= g_ptr->m_idx == 0;
41 is_empty_grid &= !player_grid(player_ptr, g_ptr);
46 bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x)
48 return cave_have_flag_bold(floor_ptr, y, x, FF_PATTERN);
53 * Determine if a "legal" grid is an "empty" floor grid
54 * Determine if monsters are allowed to move into a grid
56 * Line 1 -- forbid non-placement grids
57 * Line 2 -- forbid normal monsters
58 * Line 3 -- forbid the player
60 bool is_cave_empty_bold(player_type *player_ptr, POSITION y, POSITION x)
62 floor_type *floor_ptr = player_ptr->current_floor_ptr;
63 bool is_empty_grid = cave_have_flag_bold(floor_ptr, y, x, FF_PLACE);
64 is_empty_grid &= !(floor_ptr->grid_array[y][x].m_idx);
65 is_empty_grid &= !player_bold(player_ptr, y, x);
71 * Determine if a "legal" grid is an "empty" floor grid
72 * Determine if monster generation is allowed in a grid
74 * Line 1 -- forbid non-empty grids
75 * Line 2 -- forbid trees while dungeon generation
77 bool is_cave_empty_bold2(player_type *player_ptr, POSITION y, POSITION x)
79 bool is_empty_grid = is_cave_empty_bold(player_ptr, y, x);
80 is_empty_grid &= current_world_ptr->character_dungeon || !cave_have_flag_bold(player_ptr->current_floor_ptr, y, x, FF_TREE);
86 * @brief 鍵のかかったドアを配置する
87 * @param player_ptr プレーヤーへの参照ポインタ
88 * @param y 配置したいフロアのY座標
89 * @param x 配置したいフロアのX座標
92 void place_locked_door(player_type *player_ptr, POSITION y, POSITION x)
94 floor_type *floor_ptr = player_ptr->current_floor_ptr;
95 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
97 place_bold(player_ptr, y, x, GB_FLOOR);
101 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));
102 floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
103 delete_monster(player_ptr, y, x);
109 * @param player_ptr プレーヤーへの参照ポインタ
110 * @param y 配置したいフロアのY座標
111 * @param x 配置したいフロアのX座標
112 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
115 void place_secret_door(player_type *player_ptr, POSITION y, POSITION x, int type)
117 floor_type *floor_ptr = player_ptr->current_floor_ptr;
118 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
120 place_bold(player_ptr, y, x, GB_FLOOR);
124 if (type == DOOR_DEFAULT)
126 type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
127 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
128 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
131 place_closed_door(player_ptr, y, x, type);
132 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
133 if (type != DOOR_CURTAIN)
135 g_ptr->mimic = feat_wall_inner;
136 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
138 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
140 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
147 g_ptr->info &= ~(CAVE_FLOOR);
148 delete_monster(player_ptr, y, x);
151 static int scent_when = 0;
154 * Characters leave scent trails for perceptive monsters to track.
156 * Smell is rather more limited than sound. Many creatures cannot use
157 * it at all, it doesn't extend very far outwards from the character's
158 * current position, and monsters can use it to home in the character,
159 * but not to run away from him.
161 * Smell is valued according to age. When a character takes his turn,
162 * scent is aged by one, and new scent of the current age is laid down.
163 * Speedy characters leave more scent, true, but it also ages faster,
164 * which makes it harder to hunt them down.
166 * Whenever the age count loops, most of the scent trail is erased and
167 * the age of the remainder is recalculated.
169 void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
171 /* Create a table that controls the spread of scent */
172 const int scent_adjust[5][5] =
181 if (++scent_when == 254)
183 for (POSITION y = 0; y < floor_ptr->height; y++)
185 for (POSITION x = 0; x < floor_ptr->width; x++)
187 int w = floor_ptr->grid_array[y][x].when;
188 floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
195 for (POSITION i = 0; i < 5; i++)
197 for (POSITION j = 0; j < 5; j++)
200 POSITION y = i + subject_ptr->y - 2;
201 POSITION x = j + subject_ptr->x - 2;
202 if (!in_bounds(floor_ptr, y, x)) continue;
204 g_ptr = &floor_ptr->grid_array[y][x];
205 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(subject_ptr, g_ptr->feat)) continue;
206 if (!player_has_los_bold(subject_ptr, y, x)) continue;
207 if (scent_adjust[i][j] == -1) continue;
209 g_ptr->when = scent_when + scent_adjust[i][j];
216 * Hack -- forget the "flow" information
218 void forget_flow(floor_type *floor_ptr)
220 for (POSITION y = 0; y < floor_ptr->height; y++)
222 for (POSITION x = 0; x < floor_ptr->width; x++)
224 floor_ptr->grid_array[y][x].dist = 0;
225 floor_ptr->grid_array[y][x].cost = 0;
226 floor_ptr->grid_array[y][x].when = 0;
233 * Routine used by the random vault creators to add a door to a location
234 * Note that range checking has to be done in the calling routine.
236 * The doors must be INSIDE the allocated region.
238 void add_door(player_type *player_ptr, POSITION x, POSITION y)
240 floor_type *floor_ptr = player_ptr->current_floor_ptr;
241 if (!is_outer_bold(floor_ptr, y, x)) return;
252 if (is_floor_bold(floor_ptr, y - 1, x) && is_floor_bold(floor_ptr, y + 1, x) &&
253 (is_outer_bold(floor_ptr, y, x - 1) && is_outer_bold(floor_ptr, y, x + 1)))
255 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
256 place_bold(player_ptr, y, x - 1, GB_SOLID);
257 place_bold(player_ptr, y, x + 1, GB_SOLID);
265 * where x = don't care
268 if (is_outer_bold(floor_ptr, y - 1, x) && is_outer_bold(floor_ptr, y + 1, x) &&
269 is_floor_bold(floor_ptr, y, x - 1) && is_floor_bold(floor_ptr, y, x + 1))
271 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
272 place_bold(player_ptr, y - 1, x, GB_SOLID);
273 place_bold(player_ptr, y + 1, x, GB_SOLID);
279 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
280 * @param player_ptr プレーヤーへの参照ポインタ
281 * @param y 配置を試みたいマスのY座標
282 * @param x 配置を試みたいマスのX座標
285 void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
287 bool up_stairs = TRUE;
288 bool down_stairs = TRUE;
290 floor_type *floor_ptr = player_ptr->current_floor_ptr;
291 g_ptr = &floor_ptr->grid_array[y][x];
292 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
294 if (!floor_ptr->dun_level) up_stairs = FALSE;
295 if (ironman_downward) up_stairs = FALSE;
296 if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
297 if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1)) down_stairs = FALSE;
299 if (down_stairs && up_stairs)
301 if (randint0(100) < 50) up_stairs = FALSE;
302 else down_stairs = FALSE;
305 if (up_stairs) set_cave_feat(floor_ptr, y, x, feat_up_stair);
306 else if (down_stairs) set_cave_feat(floor_ptr, y, x, feat_down_stair);
311 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
312 * @param player_ptr プレーヤーへの参照ポインタ
317 * @return LOSが通っているならTRUEを返す。
319 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
320 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
322 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
324 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
325 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
326 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
328 * We assume that the "mathematical corner" of a non-floor tile does not\n
329 * block line of sight.\n
331 * Because this function uses (short) ints for all calculations, overflow may\n
332 * occur if dx and dy exceed 90.\n
334 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
335 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
336 * we can use integer arithmetic.\n
338 * We travel from start to finish along the longer axis, starting at the border\n
339 * between the first and second tiles, where the y offset = .5 * slope, taking\n
340 * into account the scale factor. See below.\n
342 * Also note that this function and the "move towards target" code do NOT\n
343 * share the same properties. Thus, you can see someone, target them, and\n
344 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
345 * by clever choice of target locations, you can sometimes throw a "curve".\n
347 * Note that "line of sight" is not "reflexive" in all cases.\n
349 * Use the "projectable()" routine to test "spell/missile line of sight".\n
351 * Use the "update_view()" function to determine player line-of-sight.\n
353 bool los(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
355 POSITION dy = y2 - y1;
356 POSITION dx = x2 - x1;
357 POSITION ay = ABS(dy);
358 POSITION ax = ABS(dx);
359 if ((ax < 2) && (ay < 2)) return TRUE;
361 /* Directly South/North */
362 floor_type *floor_ptr = player_ptr->current_floor_ptr;
366 /* South -- check for walls */
369 for (ty = y1 + 1; ty < y2; ty++)
371 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
375 /* North -- check for walls */
378 for (ty = y1 - 1; ty > y2; ty--)
380 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
388 /* Directly East/West */
391 /* East -- check for walls */
394 for (tx = x1 + 1; tx < x2; tx++)
396 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
400 /* West -- check for walls */
403 for (tx = x1 - 1; tx > x2; tx--)
405 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
412 POSITION sx = (dx < 0) ? -1 : 1;
413 POSITION sy = (dy < 0) ? -1 : 1;
419 if (cave_los_bold(floor_ptr, y1 + sy, x1)) return TRUE;
426 if (cave_los_bold(floor_ptr, y1, x1 + sx)) return TRUE;
430 POSITION f2 = (ax * ay);
431 POSITION f1 = f2 << 1;
449 /* Note (below) the case (qy == f2), where */
450 /* the LOS exactly meets the corner of a tile. */
453 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
466 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
480 /* Travel vertically */
481 POSITION qx = ax * ax;
494 /* Note (below) the case (qx == f2), where */
495 /* the LOS exactly meets the corner of a tile. */
498 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
511 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
527 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
528 * at the final destination, assuming no monster gets in the way.
530 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
532 bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
535 int grid_n = project_path(player_ptr, grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
536 if (!grid_n) return TRUE;
538 POSITION y = GRID_Y(grid_g[grid_n - 1]);
539 POSITION x = GRID_X(grid_g[grid_n - 1]);
540 if ((y != y2) || (x != x2)) return FALSE;
547 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
548 * @param player_ptr プレーヤーへの参照ポインタ
549 * @param y1 モンスターを配置したいマスの中心Y座標
550 * @param x1 モンスターを配置したいマスの中心X座標
551 * @param num 配置したいモンスターの数
554 * Only really called by some of the "vault" routines.
556 void vault_monsters(player_type *player_ptr, POSITION y1, POSITION x1, int num)
558 floor_type *floor_ptr = player_ptr->current_floor_ptr;
559 for (int k = 0; k < num; k++)
561 for (int i = 0; i < 9; i++)
565 scatter(player_ptr, &y, &x, y1, x1, d, 0);
567 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
568 if (!is_cave_empty_grid(player_ptr, g_ptr)) continue;
570 floor_ptr->monster_level = floor_ptr->base_level + 2;
571 (void)place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
572 floor_ptr->monster_level = floor_ptr->base_level;
579 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
580 * @param player_ptr プレーヤーへの参照ポインタ
583 * @return 各種の変更が可能ならTRUEを返す。
585 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
587 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
589 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
590 if (cave_perma_grid(g_ptr)) return FALSE;
592 OBJECT_IDX next_o_idx = 0;
593 for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
596 o_ptr = &floor_ptr->o_list[this_o_idx];
597 next_o_idx = o_ptr->next_o_idx;
598 if (object_is_artifact(o_ptr)) return FALSE;
606 * Change the "feat" flag for a grid, and notice/redraw the grid
608 void cave_set_feat(player_type *player_ptr, POSITION y, POSITION x, FEAT_IDX feat)
610 floor_type *floor_ptr = player_ptr->current_floor_ptr;
611 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
612 feature_type *f_ptr = &f_info[feat];
613 if (!current_world_ptr->character_dungeon)
617 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
619 for (DIRECTION i = 0; i < 9; i++)
621 POSITION yy = y + ddy_ddd[i];
622 POSITION xx = x + ddx_ddd[i];
623 if (!in_bounds2(floor_ptr, yy, xx)) continue;
624 floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
631 bool old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
632 bool old_mirror = is_mirror_grid(g_ptr);
636 g_ptr->info &= ~(CAVE_OBJECT);
637 if (old_mirror && (d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
639 g_ptr->info &= ~(CAVE_GLOW);
640 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
642 update_local_illumination(player_ptr, y, x);
645 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
646 if (g_ptr->m_idx) update_monster(player_ptr, g_ptr->m_idx, FALSE);
648 note_spot(player_ptr, y, x);
649 lite_spot(player_ptr, y, x);
650 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
653 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
655 update_local_illumination(player_ptr, y, x);
657 #endif /* COMPLEX_WALL_ILLUMINATION */
659 player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
662 if (!have_flag(f_ptr->flags, FF_GLOW) || (d_info[player_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
665 for (DIRECTION i = 0; i < 9; i++)
667 POSITION yy = y + ddy_ddd[i];
668 POSITION xx = x + ddx_ddd[i];
669 if (!in_bounds2(floor_ptr, yy, xx)) continue;
672 cc_ptr = &floor_ptr->grid_array[yy][xx];
673 cc_ptr->info |= CAVE_GLOW;
675 if (player_has_los_grid(cc_ptr))
677 if (cc_ptr->m_idx) update_monster(player_ptr, cc_ptr->m_idx, FALSE);
678 note_spot(player_ptr, yy, xx);
679 lite_spot(player_ptr, yy, xx);
682 update_local_illumination(player_ptr, yy, xx);
685 if (player_ptr->special_defense & NINJA_S_STEALTH)
687 if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW) set_superstealth(player_ptr, FALSE);
693 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
694 * @param player_ptr プレーヤーへの参照ポインタ
695 * @param y ドアの配置を試みたいマスのY座標
696 * @param x ドアの配置を試みたいマスのX座標
697 * @param room 部屋に接している場合向けのドア生成か否か
700 void place_random_door(player_type *player_ptr, POSITION y, POSITION x, bool room)
702 floor_type *floor_ptr = player_ptr->current_floor_ptr;
703 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
706 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
708 place_bold(player_ptr, y, x, GB_FLOOR);
712 int type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
713 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
714 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
716 int tmp = randint0(1000);
717 FEAT_IDX feat = feat_none;
720 feat = feat_door[type].open;
724 feat = feat_door[type].broken;
728 place_closed_door(player_ptr, y, x, type);
730 if (type != DOOR_CURTAIN)
732 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
733 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
735 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
737 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
745 place_closed_door(player_ptr, y, x, type);
750 delete_monster(player_ptr, y, x);
754 if (feat != feat_none)
756 set_cave_feat(floor_ptr, y, x, feat);
760 place_bold(player_ptr, y, x, GB_FLOOR);
763 delete_monster(player_ptr, y, x);
768 * @brief グローバルオブジェクト配列を初期化する /
769 * Delete all the items when player leaves the level
770 * @note we do NOT visually reflect these (irrelevant) changes
772 * Hack -- we clear the "g_ptr->o_idx" field for every grid,
773 * and the "m_ptr->next_o_idx" field for every monster, since
774 * we know we are clearing every object. Technically, we only
775 * clear those fields for grids/monsters containing objects,
776 * and we clear it once for every such object.
779 void wipe_o_list(floor_type *floor_ptr)
781 for (int i = 1; i < floor_ptr->o_max; i++)
783 object_type *o_ptr = &floor_ptr->o_list[i];
784 if (!OBJECT_IS_VALID(o_ptr)) continue;
786 if (!current_world_ptr->character_dungeon || preserve_mode)
788 if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
790 a_info[o_ptr->name1].cur_num = 0;
794 if (OBJECT_IS_HELD_MONSTER(o_ptr))
797 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
798 m_ptr->hold_o_idx = 0;
804 POSITION y = o_ptr->iy;
805 POSITION x = o_ptr->ix;
807 g_ptr = &floor_ptr->grid_array[y][x];
812 floor_ptr->o_max = 1;
813 floor_ptr->o_cnt = 0;
818 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
819 * @param player_ptr プレーヤーへの参照ポインタ
820 * @param y ドアの配置を試みたいマスのY座標
821 * @param x ドアの配置を試みたいマスのX座標
822 * @param type ドアの地形ID
825 void place_closed_door(player_type *player_ptr, POSITION y, POSITION x, int type)
827 floor_type *floor_ptr = player_ptr->current_floor_ptr;
828 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
830 place_bold(player_ptr, y, x, GB_FLOOR);
834 int tmp = randint0(400);
835 FEAT_IDX feat = feat_none;
838 /* Create closed door */
839 feat = feat_door[type].closed;
843 feat = feat_locked_door_random(type);
847 feat = feat_jammed_door_random(type);
850 if (feat == feat_none)
852 place_bold(player_ptr, y, x, GB_FLOOR);
856 cave_set_feat(player_ptr, y, x, feat);
857 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
862 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
863 * @param y トラップを配置したいマスの中心Y座標
864 * @param x トラップを配置したいマスの中心X座標
865 * @param yd Y方向の配置分散マス数
866 * @param xd X方向の配置分散マス数
869 * Only really called by some of the "vault" routines.
871 void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
874 floor_type *floor_ptr = player_ptr->current_floor_ptr;
877 for (int count = 0; count <= 5; count++)
879 while (dummy < SAFE_MAX_ATTEMPTS)
881 y1 = rand_spread(y, yd);
882 x1 = rand_spread(x, xd);
884 if (!in_bounds(floor_ptr, y1, x1)) continue;
888 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
890 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
893 g_ptr = &floor_ptr->grid_array[y1][x1];
894 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
896 place_trap(player_ptr, y1, x1);
903 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
904 * @param x チェックするマスのX座標
905 * @param y チェックするマスのY座標
906 * @return 床系地形ならばTRUE
908 bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
910 if (!in_bounds(floor_ptr, y, x))
915 if (is_floor_bold(floor_ptr, y, x)) return TRUE;
922 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
923 * @param y1 基準となるマスのY座標
924 * @param x1 基準となるマスのX座標
926 * @note Assumes "in_bounds(y1, x1)"
928 * XXX XXX This routine currently only counts actual "empty floor"\n
929 * grids which are not in rooms. We might want to also count stairs,\n
930 * open doors, closed doors, etc.
932 static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
935 for (int i = 0; i < 4; i++)
937 POSITION y = y1 + ddy_ddd[i];
938 POSITION x = x1 + ddx_ddd[i];
940 g_ptr = &floor_ptr->grid_array[y][x];
942 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
943 if (!is_floor_grid(g_ptr)) continue;
944 if (g_ptr->info & (CAVE_ROOM)) continue;
953 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
954 * @param y 判定を行いたいマスのY座標
955 * @param x 判定を行いたいマスのX座標
956 * @return ドアを設置可能ならばTRUEを返す
957 * @note Assumes "in_bounds()"
960 * Assumes "in_bounds()"\n
962 static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
964 if (next_to_corr(floor_ptr, y, x) < 2) return FALSE;
967 if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) &&
968 cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
973 /* Check Horizontal */
974 if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) &&
975 cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
985 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
986 * @param player_ptr プレーヤーへの参照ポインタ
987 * @param y 設置を行いたいマスのY座標
988 * @param x 設置を行いたいマスのX座標
991 void try_door(player_type *player_ptr, POSITION y, POSITION x)
993 floor_type *floor_ptr = player_ptr->current_floor_ptr;
994 if (!in_bounds(floor_ptr, y, x)) return;
996 if (cave_have_flag_bold(floor_ptr, y, x, FF_WALL)) return;
997 if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
999 bool can_place_door = randint0(100) < dun_tun_jct;
1000 can_place_door &= possible_doorway(floor_ptr, y, x);
1001 can_place_door &= (d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) == 0;
1004 place_random_door(player_ptr, y, x, FALSE);
1009 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
1011 feature_type *f_ptr = &f_info[newfeat];
1012 if (have_flag(f_ptr->flags, FF_CONVERT))
1014 switch (f_ptr->subtype)
1016 case CONVERT_TYPE_FLOOR:
1017 return feat_ground_type[randint0(100)];
1018 case CONVERT_TYPE_WALL:
1019 return feat_wall_type[randint0(100)];
1020 case CONVERT_TYPE_INNER:
1021 return feat_wall_inner;
1022 case CONVERT_TYPE_OUTER:
1023 return feat_wall_outer;
1024 case CONVERT_TYPE_SOLID:
1025 return feat_wall_solid;
1026 case CONVERT_TYPE_STREAM1:
1027 return d_info[floor_ptr->dungeon_idx].stream1;
1028 case CONVERT_TYPE_STREAM2:
1029 return d_info[floor_ptr->dungeon_idx].stream2;
1034 else return newfeat;
1039 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
1040 * @param player_ptr プレーヤーへの参照ポインタ
1041 * @param y 配置したい中心マスのY座標
1042 * @param x 配置したい中心マスのX座標
1046 * Only really called by some of the "vault" routines.
1048 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
1050 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1051 for (; num > 0; --num)
1055 for (int i = 0; i < 11; ++i)
1057 while (dummy < SAFE_MAX_ATTEMPTS)
1059 j = rand_spread(y, 2);
1060 k = rand_spread(x, 3);
1062 if (!in_bounds(floor_ptr, j, k)) continue;
1066 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
1068 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
1072 g_ptr = &floor_ptr->grid_array[j][k];
1073 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
1075 if (randint0(100) < 75)
1077 place_object(player_ptr, j, k, 0L);
1081 place_gold(player_ptr, j, k);
1091 * @brief 始点から終点への直線経路を返す /
1092 * Determine the path taken by a projection.
1093 * @param player_ptr プレーヤーへの参照ポインタ
1094 * @param gp 経路座標リストを返す参照ポインタ
1104 * The projection will always start from the grid (y1,x1), and will travel
1105 * towards the grid (y2,x2), touching one grid per unit of distance along
1106 * the major axis, and stopping when it enters the destination grid or a
1107 * wall grid, or has travelled the maximum legal distance of "range".
1109 * Note that "distance" in this function (as in the "update_view()" code)
1110 * is defined as "MAX(dy,dx) + MIN(dy,dx)/2", which means that the player
1111 * actually has an "octagon of projection" not a "circle of projection".
1113 * The path grids are saved into the grid array pointed to by "gp", and
1114 * there should be room for at least "range" grids in "gp". Note that
1115 * due to the way in which distance is calculated, this function normally
1116 * uses fewer than "range" grids for the projection path, so the result
1117 * of this function should never be compared directly to "range". Note
1118 * that the initial grid (y1,x1) is never saved into the grid array, not
1119 * even if the initial grid is also the final grid.
1121 * The "flg" flags can be used to modify the behavior of this function.
1123 * In particular, the "PROJECT_STOP" and "PROJECT_THRU" flags have the same
1124 * semantics as they do for the "project" function, namely, that the path
1125 * will stop as soon as it hits a monster, or that the path will continue
1126 * through the destination grid, respectively.
1128 * The "PROJECT_JUMP" flag, which for the "project()" function means to
1129 * start at a special grid (which makes no sense in this function), means
1130 * that the path should be "angled" slightly if needed to avoid any wall
1131 * grids, allowing the player to "target" any grid which is in "view".
1132 * This flag is non-trivial and has not yet been implemented, but could
1133 * perhaps make use of the "vinfo" array (above).
1135 * This function returns the number of grids (if any) in the path. This
1136 * function will return zero if and only if (y1,x1) and (y2,x2) are equal.
1138 * This algorithm is similar to, but slightly different from, the one used
1139 * by "update_view_los()", and very different from the one used by "los()".
1142 sint project_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
1144 if ((x1 == x2) && (y1 == y2)) return 0;
1174 int half = (ay * ax);
1175 int full = half << 1;
1178 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1196 gp[n++] = GRID(y, x);
1197 if ((n + (k >> 1)) >= range) break;
1199 if (!(flg & (PROJECT_THRU)))
1201 if ((x == x2) && (y == y2)) break;
1204 if (flg & (PROJECT_DISI))
1206 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1208 else if (flg & (PROJECT_LOS))
1210 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1212 else if (!(flg & (PROJECT_PATH)))
1214 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1217 if (flg & (PROJECT_STOP))
1220 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1224 if (!in_bounds(floor_ptr, y, x)) break;
1259 gp[n++] = GRID(y, x);
1260 if ((n + (k >> 1)) >= range) break;
1262 if (!(flg & (PROJECT_THRU)))
1264 if ((x == x2) && (y == y2)) break;
1267 if (flg & (PROJECT_DISI))
1269 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1271 else if (flg & (PROJECT_LOS))
1273 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1275 else if (!(flg & (PROJECT_PATH)))
1277 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1280 if (flg & (PROJECT_STOP))
1283 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1287 if (!in_bounds(floor_ptr, y, x)) break;
1311 gp[n++] = GRID(y, x);
1312 if ((n + (n >> 1)) >= range) break;
1314 if (!(flg & (PROJECT_THRU)))
1316 if ((x == x2) && (y == y2)) break;
1319 if (flg & (PROJECT_DISI))
1321 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1323 else if (flg & (PROJECT_LOS))
1325 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1327 else if (!(flg & (PROJECT_PATH)))
1329 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1332 if (flg & (PROJECT_STOP))
1335 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1339 if (!in_bounds(floor_ptr, y, x)) break;
1350 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
1351 * @param player_ptr プレーヤーへの参照ポインタ
1352 * @param x 地形を変えたいマスのX座標
1353 * @param y 地形を変えたいマスのY座標
1356 void set_floor(player_type *player_ptr, POSITION x, POSITION y)
1358 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1359 if (!in_bounds(floor_ptr, y, x))
1364 if (floor_ptr->grid_array[y][x].info & CAVE_ROOM)
1369 if (is_extra_bold(floor_ptr, y, x))
1370 place_bold(player_ptr, y, x, GB_FLOOR);
1375 * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
1376 * Attempt to place an object (normal or good/great) at the given location.
1377 * @param owner_ptr プレーヤーへの参照ポインタ
1378 * @param y 配置したいフロアのY座標
1379 * @param x 配置したいフロアのX座標
1380 * @param mode オプションフラグ
1381 * @return 生成に成功したらTRUEを返す。
1383 * This routine plays nasty games to generate the "special artifacts".\n
1384 * This routine uses "object_level" for the "generation level".\n
1385 * This routine requires a clean floor grid destination.\n
1387 void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
1389 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
1390 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1393 if (!in_bounds(floor_ptr, y, x)) return;
1394 if (!cave_drop_bold(floor_ptr, y, x)) return;
1395 if (g_ptr->o_idx) return;
1399 if (!make_object(owner_ptr, q_ptr, mode)) return;
1401 OBJECT_IDX o_idx = o_pop(floor_ptr);
1404 if (object_is_fixed_artifact(q_ptr))
1406 a_info[q_ptr->name1].cur_num = 0;
1413 o_ptr = &floor_ptr->o_list[o_idx];
1414 object_copy(o_ptr, q_ptr);
1418 o_ptr->next_o_idx = g_ptr->o_idx;
1420 g_ptr->o_idx = o_idx;
1421 note_spot(owner_ptr, y, x);
1422 lite_spot(owner_ptr, y, x);
1427 * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
1428 * Places a treasure (Gold or Gems) at given location
1429 * @param player_ptr プレーヤーへの参照ポインタ
1430 * @param y 配置したいフロアのY座標
1431 * @param x 配置したいフロアのX座標
1432 * @return 生成に成功したらTRUEを返す。
1434 * The location must be a legal, clean, floor grid.
1436 void place_gold(player_type *player_ptr, POSITION y, POSITION x)
1438 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1439 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1440 if (!in_bounds(floor_ptr, y, x)) return;
1441 if (!cave_drop_bold(floor_ptr, y, x)) return;
1442 if (g_ptr->o_idx) return;
1448 if (!make_gold(floor_ptr, q_ptr)) return;
1450 OBJECT_IDX o_idx = o_pop(floor_ptr);
1451 if (o_idx == 0) return;
1454 o_ptr = &floor_ptr->o_list[o_idx];
1455 object_copy(o_ptr, q_ptr);
1459 o_ptr->next_o_idx = g_ptr->o_idx;
1461 g_ptr->o_idx = o_idx;
1462 note_spot(player_ptr, y, x);
1463 lite_spot(player_ptr, y, x);
1468 * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
1469 * @param player_ptr プレーヤーへの参照ポインタ
1474 void delete_monster(player_type *player_ptr, POSITION y, POSITION x)
1477 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1478 if (!in_bounds(floor_ptr, y, x)) return;
1480 g_ptr = &floor_ptr->grid_array[y][x];
1481 if (g_ptr->m_idx) delete_monster_idx(player_ptr, g_ptr->m_idx);
1486 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
1487 * Move an object from index i1 to index i2 in the object list
1488 * @param i1 整理したい配列の始点
1489 * @param i2 整理したい配列の終点
1492 static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX i2)
1494 if (i1 == i2) return;
1497 for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
1499 o_ptr = &floor_ptr->o_list[i];
1500 if (!o_ptr->k_idx) continue;
1502 if (o_ptr->next_o_idx == i1)
1504 o_ptr->next_o_idx = i2;
1508 o_ptr = &floor_ptr->o_list[i1];
1510 if (OBJECT_IS_HELD_MONSTER(o_ptr))
1512 monster_type *m_ptr;
1513 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1514 if (m_ptr->hold_o_idx == i1)
1516 m_ptr->hold_o_idx = i2;
1521 POSITION y = o_ptr->iy;
1522 POSITION x = o_ptr->ix;
1524 g_ptr = &floor_ptr->grid_array[y][x];
1526 if (g_ptr->o_idx == i1)
1532 floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
1538 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
1539 * Compact and Reorder the object list.
1540 * @param player_ptr プレーヤーへの参照ポインタ
1541 * @param size 最低でも減らしたいオブジェクト数の水準
1545 * This function can be very dangerous, use with caution!\n
1547 * When actually "compacting" objects, we base the saving throw on a\n
1548 * combination of object level, distance from player, and current\n
1551 * After "compacting" (if needed), we "reorder" the objects into a more\n
1552 * compact order, and we reset the allocation info, and the "live" array.\n
1554 void compact_objects(player_type *player_ptr, int size)
1559 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
1560 player_ptr->redraw |= (PR_MAP);
1561 player_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1564 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1565 for (int num = 0, cnt = 1; num < size; cnt++)
1567 int cur_lev = 5 * cnt;
1568 int cur_dis = 5 * (20 - cnt);
1569 for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
1571 o_ptr = &floor_ptr->o_list[i];
1573 if (!OBJECT_IS_VALID(o_ptr)) continue;
1574 if (k_info[o_ptr->k_idx].level > cur_lev) continue;
1577 if (OBJECT_IS_HELD_MONSTER(o_ptr))
1579 monster_type *m_ptr;
1580 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1584 if (randint0(100) < 90) continue;
1592 if ((cur_dis > 0) && (distance(player_ptr->y, player_ptr->x, y, x) < cur_dis)) continue;
1595 if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
1596 (cnt < 1000)) chance = 100;
1598 if (randint0(100) < chance) continue;
1600 delete_object_idx(player_ptr, i);
1605 for (OBJECT_IDX i = floor_ptr->o_max - 1; i >= 1; i--)
1607 o_ptr = &floor_ptr->o_list[i];
1608 if (o_ptr->k_idx) continue;
1610 compact_objects_aux(floor_ptr, floor_ptr->o_max - 1, i);
1617 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
1618 * @param player_ptr プレーヤーへの参照ポインタ
1619 * @param y トラップを配置したいマスの中心Y座標
1620 * @param x トラップを配置したいマスの中心X座標
1621 * @param yd Y方向の配置分散マス数
1622 * @param xd X方向の配置分散マス数
1623 * @param num 配置したいトラップの数
1626 * Only really called by some of the "vault" routines.
1628 void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
1630 for (int i = 0; i < num; i++)
1632 vault_trap_aux(player_ptr, y, x, yd, xd);
1638 * Standard "find me a location" function
1640 * Obtains a legal location within the given distance of the initial
1641 * location, and with "los()" from the source to destination location.
1643 * This function is often called from inside a loop which searches for
1644 * locations while increasing the "d" distance.
1646 * Currently the "m" parameter is unused.
1648 void scatter(player_type *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
1650 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1654 ny = rand_spread(y, d);
1655 nx = rand_spread(x, d);
1657 if (!in_bounds(floor_ptr, ny, nx)) continue;
1658 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
1659 if (mode & PROJECT_LOS)
1661 if (los(player_ptr, y, x, ny, nx)) break;
1665 if (projectable(player_ptr, y, x, ny, nx)) break;
1674 * @brief 指定のマスが光を通すか(LOSフラグを持つか)を返す。 / Aux function -- see below
1675 * @param floor_ptr 配置するフロアの参照ポインタ
1678 * @return 光を通すならばtrueを返す。
1680 bool cave_los_bold(floor_type *floor_ptr, POSITION y, POSITION x)
1682 return feat_supports_los(floor_ptr->grid_array[y][x].feat);