1 #include "floor/floor.h"
2 #include "core/player-redraw-types.h"
3 #include "core/player-update-types.h"
4 #include "core/window-redrawer.h"
5 #include "dungeon/dungeon-flag-types.h"
6 #include "dungeon/dungeon.h"
7 #include "dungeon/quest.h"
8 #include "effect/effect-characteristics.h"
9 #include "effect/spells-effect-util.h"
10 #include "floor/cave.h"
11 #include "floor/floor-generate.h"
12 #include "floor/floor-object.h"
13 #include "game-option/birth-options.h"
14 #include "game-option/cheat-options.h"
15 #include "game-option/map-screen-options.h"
16 #include "grid/grid.h"
17 #include "grid/trap.h"
18 #include "mind/mind-ninja.h"
19 #include "monster-floor/monster-generator.h"
20 #include "monster-floor/monster-remover.h"
21 #include "monster/monster-update.h"
22 #include "monster-floor/place-monster-types.h"
23 #include "object-enchant/special-object-flags.h"
24 #include "object-hook/hook-checker.h"
25 #include "object-hook/hook-enchant.h"
26 #include "object/object-generator.h"
27 #include "object/object-kind.h"
28 #include "perception/object-perception.h"
29 #include "player/special-defense-types.h"
30 #include "room/door-definition.h"
31 #include "system/artifact-type-definition.h"
32 #include "system/floor-type-definition.h"
33 #include "target/targeting.h"
34 #include "util/bit-flags-calculator.h"
35 #include "view/display-messages.h"
36 #include "world/world-object.h"
37 #include "world/world.h"
40 * The array of floor [MAX_WID][MAX_HGT].
41 * Not completely allocated, that would be inefficient
42 * Not completely hardcoded, that would overflow memory
44 floor_type floor_info;
47 * Grid based version of "cave_empty_bold()"
49 bool is_cave_empty_grid(player_type *player_ptr, grid_type *g_ptr)
51 bool is_empty_grid = cave_have_flag_grid(g_ptr, FF_PLACE);
52 is_empty_grid &= g_ptr->m_idx == 0;
53 is_empty_grid &= !player_grid(player_ptr, g_ptr);
58 bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x)
60 return cave_have_flag_bold(floor_ptr, y, x, FF_PATTERN);
65 * @brief 鍵のかかったドアを配置する
66 * @param player_ptr プレーヤーへの参照ポインタ
67 * @param y 配置したいフロアのY座標
68 * @param x 配置したいフロアのX座標
71 void place_locked_door(player_type *player_ptr, POSITION y, POSITION x)
73 floor_type *floor_ptr = player_ptr->current_floor_ptr;
74 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
76 place_bold(player_ptr, y, x, GB_FLOOR);
80 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));
81 floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
82 delete_monster(player_ptr, y, x);
88 * @param player_ptr プレーヤーへの参照ポインタ
89 * @param y 配置したいフロアのY座標
90 * @param x 配置したいフロアのX座標
91 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
94 void place_secret_door(player_type *player_ptr, POSITION y, POSITION x, int type)
96 floor_type *floor_ptr = player_ptr->current_floor_ptr;
97 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
99 place_bold(player_ptr, y, x, GB_FLOOR);
103 if (type == DOOR_DEFAULT)
105 type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
106 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
107 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
110 place_closed_door(player_ptr, y, x, type);
111 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
112 if (type != DOOR_CURTAIN)
114 g_ptr->mimic = feat_wall_inner;
115 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
117 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
119 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
126 g_ptr->info &= ~(CAVE_FLOOR);
127 delete_monster(player_ptr, y, x);
130 static int scent_when = 0;
133 * Characters leave scent trails for perceptive monsters to track.
135 * Smell is rather more limited than sound. Many creatures cannot use
136 * it at all, it doesn't extend very far outwards from the character's
137 * current position, and monsters can use it to home in the character,
138 * but not to run away from him.
140 * Smell is valued according to age. When a character takes his turn,
141 * scent is aged by one, and new scent of the current age is laid down.
142 * Speedy characters leave more scent, true, but it also ages faster,
143 * which makes it harder to hunt them down.
145 * Whenever the age count loops, most of the scent trail is erased and
146 * the age of the remainder is recalculated.
148 void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
150 /* Create a table that controls the spread of scent */
151 const int scent_adjust[5][5] =
160 if (++scent_when == 254)
162 for (POSITION y = 0; y < floor_ptr->height; y++)
164 for (POSITION x = 0; x < floor_ptr->width; x++)
166 int w = floor_ptr->grid_array[y][x].when;
167 floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
174 for (POSITION i = 0; i < 5; i++)
176 for (POSITION j = 0; j < 5; j++)
179 POSITION y = i + subject_ptr->y - 2;
180 POSITION x = j + subject_ptr->x - 2;
181 if (!in_bounds(floor_ptr, y, x)) continue;
183 g_ptr = &floor_ptr->grid_array[y][x];
184 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(subject_ptr, g_ptr->feat)) continue;
185 if (!player_has_los_bold(subject_ptr, y, x)) continue;
186 if (scent_adjust[i][j] == -1) continue;
188 g_ptr->when = scent_when + scent_adjust[i][j];
195 * Hack -- forget the "flow" information
197 void forget_flow(floor_type *floor_ptr)
199 for (POSITION y = 0; y < floor_ptr->height; y++)
201 for (POSITION x = 0; x < floor_ptr->width; x++)
203 floor_ptr->grid_array[y][x].dist = 0;
204 floor_ptr->grid_array[y][x].cost = 0;
205 floor_ptr->grid_array[y][x].when = 0;
212 * Routine used by the random vault creators to add a door to a location
213 * Note that range checking has to be done in the calling routine.
215 * The doors must be INSIDE the allocated region.
217 void add_door(player_type *player_ptr, POSITION x, POSITION y)
219 floor_type *floor_ptr = player_ptr->current_floor_ptr;
220 if (!is_outer_bold(floor_ptr, y, x)) return;
231 if (is_floor_bold(floor_ptr, y - 1, x) && is_floor_bold(floor_ptr, y + 1, x) &&
232 (is_outer_bold(floor_ptr, y, x - 1) && is_outer_bold(floor_ptr, y, x + 1)))
234 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
235 place_bold(player_ptr, y, x - 1, GB_SOLID);
236 place_bold(player_ptr, y, x + 1, GB_SOLID);
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))
250 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
251 place_bold(player_ptr, y - 1, x, GB_SOLID);
252 place_bold(player_ptr, y + 1, x, GB_SOLID);
258 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
259 * @param player_ptr プレーヤーへの参照ポインタ
260 * @param y 配置を試みたいマスのY座標
261 * @param x 配置を試みたいマスのX座標
264 void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
266 bool up_stairs = TRUE;
267 bool down_stairs = TRUE;
269 floor_type *floor_ptr = player_ptr->current_floor_ptr;
270 g_ptr = &floor_ptr->grid_array[y][x];
271 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
273 if (!floor_ptr->dun_level) up_stairs = FALSE;
274 if (ironman_downward) up_stairs = FALSE;
275 if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
276 if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1)) down_stairs = FALSE;
278 if (down_stairs && up_stairs)
280 if (randint0(100) < 50) up_stairs = FALSE;
281 else down_stairs = FALSE;
284 if (up_stairs) set_cave_feat(floor_ptr, y, x, feat_up_stair);
285 else if (down_stairs) set_cave_feat(floor_ptr, y, x, feat_down_stair);
290 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
291 * @param player_ptr プレーヤーへの参照ポインタ
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(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
334 POSITION dy = y2 - y1;
335 POSITION dx = x2 - x1;
336 POSITION ay = ABS(dy);
337 POSITION ax = ABS(dx);
338 if ((ax < 2) && (ay < 2)) return TRUE;
340 /* Directly South/North */
341 floor_type *floor_ptr = player_ptr->current_floor_ptr;
345 /* South -- check for walls */
348 for (ty = y1 + 1; ty < y2; ty++)
350 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
354 /* North -- check for walls */
357 for (ty = y1 - 1; ty > y2; ty--)
359 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
367 /* Directly East/West */
370 /* East -- check for walls */
373 for (tx = x1 + 1; tx < x2; tx++)
375 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
379 /* West -- check for walls */
382 for (tx = x1 - 1; tx > x2; tx--)
384 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
391 POSITION sx = (dx < 0) ? -1 : 1;
392 POSITION sy = (dy < 0) ? -1 : 1;
398 if (cave_los_bold(floor_ptr, y1 + sy, x1)) return TRUE;
405 if (cave_los_bold(floor_ptr, y1, x1 + sx)) return TRUE;
409 POSITION f2 = (ax * ay);
410 POSITION f1 = f2 << 1;
428 /* Note (below) the case (qy == f2), where */
429 /* the LOS exactly meets the corner of a tile. */
432 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
445 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
459 /* Travel vertically */
460 POSITION qx = ax * ax;
473 /* Note (below) the case (qx == f2), where */
474 /* the LOS exactly meets the corner of a tile. */
477 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
490 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
506 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
507 * at the final destination, assuming no monster gets in the way.
509 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
511 bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
514 int grid_n = project_path(player_ptr, grid_g, (project_length ? project_length : get_max_range(player_ptr)), y1, x1, y2, x2, 0);
515 if (!grid_n) return TRUE;
517 POSITION y = GRID_Y(grid_g[grid_n - 1]);
518 POSITION x = GRID_X(grid_g[grid_n - 1]);
519 if ((y != y2) || (x != x2)) return FALSE;
526 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
527 * @param player_ptr プレーヤーへの参照ポインタ
528 * @param y1 モンスターを配置したいマスの中心Y座標
529 * @param x1 モンスターを配置したいマスの中心X座標
530 * @param num 配置したいモンスターの数
533 * Only really called by some of the "vault" routines.
535 void vault_monsters(player_type *player_ptr, POSITION y1, POSITION x1, int num)
537 floor_type *floor_ptr = player_ptr->current_floor_ptr;
538 for (int k = 0; k < num; k++)
540 for (int i = 0; i < 9; i++)
544 scatter(player_ptr, &y, &x, y1, x1, d, 0);
546 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
547 if (!is_cave_empty_grid(player_ptr, g_ptr)) continue;
549 floor_ptr->monster_level = floor_ptr->base_level + 2;
550 (void)place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
551 floor_ptr->monster_level = floor_ptr->base_level;
558 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
559 * @param player_ptr プレーヤーへの参照ポインタ
562 * @return 各種の変更が可能ならTRUEを返す。
564 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
566 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
568 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
569 if (cave_perma_grid(g_ptr)) return FALSE;
571 OBJECT_IDX next_o_idx = 0;
572 for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
575 o_ptr = &floor_ptr->o_list[this_o_idx];
576 next_o_idx = o_ptr->next_o_idx;
577 if (object_is_artifact(o_ptr)) return FALSE;
585 * Change the "feat" flag for a grid, and notice/redraw the grid
587 void cave_set_feat(player_type *player_ptr, POSITION y, POSITION x, FEAT_IDX feat)
589 floor_type *floor_ptr = player_ptr->current_floor_ptr;
590 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
591 feature_type *f_ptr = &f_info[feat];
592 if (!current_world_ptr->character_dungeon)
596 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
598 for (DIRECTION i = 0; i < 9; i++)
600 POSITION yy = y + ddy_ddd[i];
601 POSITION xx = x + ddx_ddd[i];
602 if (!in_bounds2(floor_ptr, yy, xx)) continue;
603 floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
610 bool old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
611 bool old_mirror = is_mirror_grid(g_ptr);
615 g_ptr->info &= ~(CAVE_OBJECT);
616 if (old_mirror && (d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
618 g_ptr->info &= ~(CAVE_GLOW);
619 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
621 update_local_illumination(player_ptr, y, x);
624 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
625 if (g_ptr->m_idx) update_monster(player_ptr, g_ptr->m_idx, FALSE);
627 note_spot(player_ptr, y, x);
628 lite_spot(player_ptr, y, x);
629 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
632 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
634 update_local_illumination(player_ptr, y, x);
636 #endif /* COMPLEX_WALL_ILLUMINATION */
638 player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
641 if (!have_flag(f_ptr->flags, FF_GLOW) || (d_info[player_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
644 for (DIRECTION i = 0; i < 9; i++)
646 POSITION yy = y + ddy_ddd[i];
647 POSITION xx = x + ddx_ddd[i];
648 if (!in_bounds2(floor_ptr, yy, xx)) continue;
651 cc_ptr = &floor_ptr->grid_array[yy][xx];
652 cc_ptr->info |= CAVE_GLOW;
654 if (player_has_los_grid(cc_ptr))
656 if (cc_ptr->m_idx) update_monster(player_ptr, cc_ptr->m_idx, FALSE);
657 note_spot(player_ptr, yy, xx);
658 lite_spot(player_ptr, yy, xx);
661 update_local_illumination(player_ptr, yy, xx);
664 if (player_ptr->special_defense & NINJA_S_STEALTH)
666 if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW) set_superstealth(player_ptr, FALSE);
672 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
673 * @param player_ptr プレーヤーへの参照ポインタ
674 * @param y ドアの配置を試みたいマスのY座標
675 * @param x ドアの配置を試みたいマスのX座標
676 * @param room 部屋に接している場合向けのドア生成か否か
679 void place_random_door(player_type *player_ptr, POSITION y, POSITION x, bool room)
681 floor_type *floor_ptr = player_ptr->current_floor_ptr;
682 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
685 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
687 place_bold(player_ptr, y, x, GB_FLOOR);
691 int type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
692 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
693 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
695 int tmp = randint0(1000);
696 FEAT_IDX feat = feat_none;
699 feat = feat_door[type].open;
703 feat = feat_door[type].broken;
707 place_closed_door(player_ptr, y, x, type);
709 if (type != DOOR_CURTAIN)
711 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
712 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
714 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
716 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
724 place_closed_door(player_ptr, y, x, type);
729 delete_monster(player_ptr, y, x);
733 if (feat != feat_none)
735 set_cave_feat(floor_ptr, y, x, feat);
739 place_bold(player_ptr, y, x, GB_FLOOR);
742 delete_monster(player_ptr, y, x);
747 * @brief グローバルオブジェクト配列を初期化する /
748 * Delete all the items when player leaves the level
749 * @note we do NOT visually reflect these (irrelevant) changes
751 * Hack -- we clear the "g_ptr->o_idx" field for every grid,
752 * and the "m_ptr->next_o_idx" field for every monster, since
753 * we know we are clearing every object. Technically, we only
754 * clear those fields for grids/monsters containing objects,
755 * and we clear it once for every such object.
758 void wipe_o_list(floor_type *floor_ptr)
760 for (int i = 1; i < floor_ptr->o_max; i++)
762 object_type *o_ptr = &floor_ptr->o_list[i];
763 if (!object_is_valid(o_ptr)) continue;
765 if (!current_world_ptr->character_dungeon || preserve_mode)
767 if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
769 a_info[o_ptr->name1].cur_num = 0;
773 if (object_is_held_monster(o_ptr))
776 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
777 m_ptr->hold_o_idx = 0;
783 POSITION y = o_ptr->iy;
784 POSITION x = o_ptr->ix;
786 g_ptr = &floor_ptr->grid_array[y][x];
791 floor_ptr->o_max = 1;
792 floor_ptr->o_cnt = 0;
797 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
798 * @param player_ptr プレーヤーへの参照ポインタ
799 * @param y ドアの配置を試みたいマスのY座標
800 * @param x ドアの配置を試みたいマスのX座標
801 * @param type ドアの地形ID
804 void place_closed_door(player_type *player_ptr, POSITION y, POSITION x, int type)
806 floor_type *floor_ptr = player_ptr->current_floor_ptr;
807 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
809 place_bold(player_ptr, y, x, GB_FLOOR);
813 int tmp = randint0(400);
814 FEAT_IDX feat = feat_none;
817 /* Create closed door */
818 feat = feat_door[type].closed;
822 feat = feat_locked_door_random(type);
826 feat = feat_jammed_door_random(type);
829 if (feat == feat_none)
831 place_bold(player_ptr, y, x, GB_FLOOR);
835 cave_set_feat(player_ptr, y, x, feat);
836 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
841 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
842 * @param y トラップを配置したいマスの中心Y座標
843 * @param x トラップを配置したいマスの中心X座標
844 * @param yd Y方向の配置分散マス数
845 * @param xd X方向の配置分散マス数
848 * Only really called by some of the "vault" routines.
850 void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
853 floor_type *floor_ptr = player_ptr->current_floor_ptr;
856 for (int count = 0; count <= 5; count++)
858 while (dummy < SAFE_MAX_ATTEMPTS)
860 y1 = rand_spread(y, yd);
861 x1 = rand_spread(x, xd);
863 if (!in_bounds(floor_ptr, y1, x1)) continue;
867 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
869 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
872 g_ptr = &floor_ptr->grid_array[y1][x1];
873 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
875 place_trap(player_ptr, y1, x1);
882 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
883 * @param x チェックするマスのX座標
884 * @param y チェックするマスのY座標
885 * @return 床系地形ならばTRUE
887 bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
889 if (!in_bounds(floor_ptr, y, x))
894 if (is_floor_bold(floor_ptr, y, x)) return TRUE;
901 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
902 * @param y1 基準となるマスのY座標
903 * @param x1 基準となるマスのX座標
905 * @note Assumes "in_bounds(y1, x1)"
907 * XXX XXX This routine currently only counts actual "empty floor"\n
908 * grids which are not in rooms. We might want to also count stairs,\n
909 * open doors, closed doors, etc.
911 static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
914 for (int i = 0; i < 4; i++)
916 POSITION y = y1 + ddy_ddd[i];
917 POSITION x = x1 + ddx_ddd[i];
919 g_ptr = &floor_ptr->grid_array[y][x];
921 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
922 if (!is_floor_grid(g_ptr)) continue;
923 if (g_ptr->info & (CAVE_ROOM)) continue;
932 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
933 * @param y 判定を行いたいマスのY座標
934 * @param x 判定を行いたいマスのX座標
935 * @return ドアを設置可能ならばTRUEを返す
936 * @note Assumes "in_bounds()"
939 * Assumes "in_bounds()"\n
941 static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
943 if (next_to_corr(floor_ptr, y, x) < 2) return FALSE;
946 if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) &&
947 cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
952 /* Check Horizontal */
953 if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) &&
954 cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
964 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
965 * @param player_ptr プレーヤーへの参照ポインタ
966 * @param y 設置を行いたいマスのY座標
967 * @param x 設置を行いたいマスのX座標
970 void try_door(player_type *player_ptr, POSITION y, POSITION x)
972 floor_type *floor_ptr = player_ptr->current_floor_ptr;
973 if (!in_bounds(floor_ptr, y, x)) return;
975 if (cave_have_flag_bold(floor_ptr, y, x, FF_WALL)) return;
976 if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
978 bool can_place_door = randint0(100) < dun_tun_jct;
979 can_place_door &= possible_doorway(floor_ptr, y, x);
980 can_place_door &= (d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) == 0;
983 place_random_door(player_ptr, y, x, FALSE);
988 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
990 feature_type *f_ptr = &f_info[newfeat];
991 if (have_flag(f_ptr->flags, FF_CONVERT))
993 switch (f_ptr->subtype)
995 case CONVERT_TYPE_FLOOR:
996 return feat_ground_type[randint0(100)];
997 case CONVERT_TYPE_WALL:
998 return feat_wall_type[randint0(100)];
999 case CONVERT_TYPE_INNER:
1000 return feat_wall_inner;
1001 case CONVERT_TYPE_OUTER:
1002 return feat_wall_outer;
1003 case CONVERT_TYPE_SOLID:
1004 return feat_wall_solid;
1005 case CONVERT_TYPE_STREAM1:
1006 return d_info[floor_ptr->dungeon_idx].stream1;
1007 case CONVERT_TYPE_STREAM2:
1008 return d_info[floor_ptr->dungeon_idx].stream2;
1013 else return newfeat;
1018 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
1019 * @param player_ptr プレーヤーへの参照ポインタ
1020 * @param y 配置したい中心マスのY座標
1021 * @param x 配置したい中心マスのX座標
1025 * Only really called by some of the "vault" routines.
1027 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
1029 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1030 for (; num > 0; --num)
1034 for (int i = 0; i < 11; ++i)
1036 while (dummy < SAFE_MAX_ATTEMPTS)
1038 j = rand_spread(y, 2);
1039 k = rand_spread(x, 3);
1041 if (!in_bounds(floor_ptr, j, k)) continue;
1045 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
1047 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
1051 g_ptr = &floor_ptr->grid_array[j][k];
1052 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
1054 if (randint0(100) < 75)
1056 place_object(player_ptr, j, k, 0L);
1060 place_gold(player_ptr, j, k);
1070 * @brief 始点から終点への直線経路を返す /
1071 * Determine the path taken by a projection.
1072 * @param player_ptr プレーヤーへの参照ポインタ
1073 * @param gp 経路座標リストを返す参照ポインタ
1083 * The projection will always start from the grid (y1,x1), and will travel
1084 * towards the grid (y2,x2), touching one grid per unit of distance along
1085 * the major axis, and stopping when it enters the destination grid or a
1086 * wall grid, or has travelled the maximum legal distance of "range".
1088 * Note that "distance" in this function (as in the "update_view()" code)
1089 * is defined as "MAX(dy,dx) + MIN(dy,dx)/2", which means that the player
1090 * actually has an "octagon of projection" not a "circle of projection".
1092 * The path grids are saved into the grid array pointed to by "gp", and
1093 * there should be room for at least "range" grids in "gp". Note that
1094 * due to the way in which distance is calculated, this function normally
1095 * uses fewer than "range" grids for the projection path, so the result
1096 * of this function should never be compared directly to "range". Note
1097 * that the initial grid (y1,x1) is never saved into the grid array, not
1098 * even if the initial grid is also the final grid.
1100 * The "flg" flags can be used to modify the behavior of this function.
1102 * In particular, the "PROJECT_STOP" and "PROJECT_THRU" flags have the same
1103 * semantics as they do for the "project" function, namely, that the path
1104 * will stop as soon as it hits a monster, or that the path will continue
1105 * through the destination grid, respectively.
1107 * The "PROJECT_JUMP" flag, which for the "project()" function means to
1108 * start at a special grid (which makes no sense in this function), means
1109 * that the path should be "angled" slightly if needed to avoid any wall
1110 * grids, allowing the player to "target" any grid which is in "view".
1111 * This flag is non-trivial and has not yet been implemented, but could
1112 * perhaps make use of the "vinfo" array (above).
1114 * This function returns the number of grids (if any) in the path. This
1115 * function will return zero if and only if (y1,x1) and (y2,x2) are equal.
1117 * This algorithm is similar to, but slightly different from, the one used
1118 * by "update_view_los()", and very different from the one used by "los()".
1121 int project_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
1123 if ((x1 == x2) && (y1 == y2)) return 0;
1153 int half = (ay * ax);
1154 int full = half << 1;
1157 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1175 gp[n++] = GRID(y, x);
1176 if ((n + (k >> 1)) >= range) break;
1178 if (!(flg & (PROJECT_THRU)))
1180 if ((x == x2) && (y == y2)) break;
1183 if (flg & (PROJECT_DISI))
1185 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1187 else if (flg & (PROJECT_LOS))
1189 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1191 else if (!(flg & (PROJECT_PATH)))
1193 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1196 if (flg & (PROJECT_STOP))
1199 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1203 if (!in_bounds(floor_ptr, y, x)) break;
1238 gp[n++] = GRID(y, x);
1239 if ((n + (k >> 1)) >= range) break;
1241 if (!(flg & (PROJECT_THRU)))
1243 if ((x == x2) && (y == y2)) break;
1246 if (flg & (PROJECT_DISI))
1248 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1250 else if (flg & (PROJECT_LOS))
1252 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1254 else if (!(flg & (PROJECT_PATH)))
1256 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1259 if (flg & (PROJECT_STOP))
1262 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1266 if (!in_bounds(floor_ptr, y, x)) break;
1290 gp[n++] = GRID(y, x);
1291 if ((n + (n >> 1)) >= range) break;
1293 if (!(flg & (PROJECT_THRU)))
1295 if ((x == x2) && (y == y2)) break;
1298 if (flg & (PROJECT_DISI))
1300 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1302 else if (flg & (PROJECT_LOS))
1304 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1306 else if (!(flg & (PROJECT_PATH)))
1308 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1311 if (flg & (PROJECT_STOP))
1314 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1318 if (!in_bounds(floor_ptr, y, x)) break;
1329 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
1330 * @param player_ptr プレーヤーへの参照ポインタ
1331 * @param x 地形を変えたいマスのX座標
1332 * @param y 地形を変えたいマスのY座標
1335 void set_floor(player_type *player_ptr, POSITION x, POSITION y)
1337 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1338 if (!in_bounds(floor_ptr, y, x))
1343 if (floor_ptr->grid_array[y][x].info & CAVE_ROOM)
1348 if (is_extra_bold(floor_ptr, y, x))
1349 place_bold(player_ptr, y, x, GB_FLOOR);
1354 * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
1355 * Attempt to place an object (normal or good/great) at the given location.
1356 * @param owner_ptr プレーヤーへの参照ポインタ
1357 * @param y 配置したいフロアのY座標
1358 * @param x 配置したいフロアのX座標
1359 * @param mode オプションフラグ
1360 * @return 生成に成功したらTRUEを返す。
1362 * This routine plays nasty games to generate the "special artifacts".\n
1363 * This routine uses "object_level" for the "generation level".\n
1364 * This routine requires a clean floor grid destination.\n
1366 void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
1368 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
1369 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1372 if (!in_bounds(floor_ptr, y, x)) return;
1373 if (!cave_drop_bold(floor_ptr, y, x)) return;
1374 if (g_ptr->o_idx) return;
1378 if (!make_object(owner_ptr, q_ptr, mode)) return;
1380 OBJECT_IDX o_idx = o_pop(floor_ptr);
1383 if (object_is_fixed_artifact(q_ptr))
1385 a_info[q_ptr->name1].cur_num = 0;
1392 o_ptr = &floor_ptr->o_list[o_idx];
1393 object_copy(o_ptr, q_ptr);
1397 o_ptr->next_o_idx = g_ptr->o_idx;
1399 g_ptr->o_idx = o_idx;
1400 note_spot(owner_ptr, y, x);
1401 lite_spot(owner_ptr, y, x);
1406 * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
1407 * Places a treasure (Gold or Gems) at given location
1408 * @param player_ptr プレーヤーへの参照ポインタ
1409 * @param y 配置したいフロアのY座標
1410 * @param x 配置したいフロアのX座標
1411 * @return 生成に成功したらTRUEを返す。
1413 * The location must be a legal, clean, floor grid.
1415 void place_gold(player_type *player_ptr, POSITION y, POSITION x)
1417 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1418 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1419 if (!in_bounds(floor_ptr, y, x)) return;
1420 if (!cave_drop_bold(floor_ptr, y, x)) return;
1421 if (g_ptr->o_idx) return;
1427 if (!make_gold(player_ptr, q_ptr)) return;
1429 OBJECT_IDX o_idx = o_pop(floor_ptr);
1430 if (o_idx == 0) return;
1433 o_ptr = &floor_ptr->o_list[o_idx];
1434 object_copy(o_ptr, q_ptr);
1438 o_ptr->next_o_idx = g_ptr->o_idx;
1440 g_ptr->o_idx = o_idx;
1441 note_spot(player_ptr, y, x);
1442 lite_spot(player_ptr, y, x);
1447 * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
1448 * @param player_ptr プレーヤーへの参照ポインタ
1453 void delete_monster(player_type *player_ptr, POSITION y, POSITION x)
1456 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1457 if (!in_bounds(floor_ptr, y, x)) return;
1459 g_ptr = &floor_ptr->grid_array[y][x];
1460 if (g_ptr->m_idx) delete_monster_idx(player_ptr, g_ptr->m_idx);
1465 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
1466 * Move an object from index i1 to index i2 in the object list
1467 * @param i1 整理したい配列の始点
1468 * @param i2 整理したい配列の終点
1471 static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX i2)
1473 if (i1 == i2) return;
1476 for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
1478 o_ptr = &floor_ptr->o_list[i];
1479 if (!o_ptr->k_idx) continue;
1481 if (o_ptr->next_o_idx == i1)
1483 o_ptr->next_o_idx = i2;
1487 o_ptr = &floor_ptr->o_list[i1];
1489 if (object_is_held_monster(o_ptr))
1491 monster_type *m_ptr;
1492 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1493 if (m_ptr->hold_o_idx == i1)
1495 m_ptr->hold_o_idx = i2;
1500 POSITION y = o_ptr->iy;
1501 POSITION x = o_ptr->ix;
1503 g_ptr = &floor_ptr->grid_array[y][x];
1505 if (g_ptr->o_idx == i1)
1511 floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
1517 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
1518 * Compact and Reorder the object list.
1519 * @param player_ptr プレーヤーへの参照ポインタ
1520 * @param size 最低でも減らしたいオブジェクト数の水準
1524 * This function can be very dangerous, use with caution!\n
1526 * When actually "compacting" objects, we base the saving throw on a\n
1527 * combination of object level, distance from player, and current\n
1530 * After "compacting" (if needed), we "reorder" the objects into a more\n
1531 * compact order, and we reset the allocation info, and the "live" array.\n
1533 void compact_objects(player_type *player_ptr, int size)
1538 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
1539 player_ptr->redraw |= (PR_MAP);
1540 player_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1543 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1544 for (int num = 0, cnt = 1; num < size; cnt++)
1546 int cur_lev = 5 * cnt;
1547 int cur_dis = 5 * (20 - cnt);
1548 for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
1550 o_ptr = &floor_ptr->o_list[i];
1552 if (!object_is_valid(o_ptr)) continue;
1553 if (k_info[o_ptr->k_idx].level > cur_lev) continue;
1556 if (object_is_held_monster(o_ptr))
1558 monster_type *m_ptr;
1559 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1563 if (randint0(100) < 90) continue;
1571 if ((cur_dis > 0) && (distance(player_ptr->y, player_ptr->x, y, x) < cur_dis)) continue;
1574 if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
1575 (cnt < 1000)) chance = 100;
1577 if (randint0(100) < chance) continue;
1579 delete_object_idx(player_ptr, i);
1584 for (OBJECT_IDX i = floor_ptr->o_max - 1; i >= 1; i--)
1586 o_ptr = &floor_ptr->o_list[i];
1587 if (o_ptr->k_idx) continue;
1589 compact_objects_aux(floor_ptr, floor_ptr->o_max - 1, i);
1596 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
1597 * @param player_ptr プレーヤーへの参照ポインタ
1598 * @param y トラップを配置したいマスの中心Y座標
1599 * @param x トラップを配置したいマスの中心X座標
1600 * @param yd Y方向の配置分散マス数
1601 * @param xd X方向の配置分散マス数
1602 * @param num 配置したいトラップの数
1605 * Only really called by some of the "vault" routines.
1607 void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
1609 for (int i = 0; i < num; i++)
1611 vault_trap_aux(player_ptr, y, x, yd, xd);
1617 * Standard "find me a location" function
1619 * Obtains a legal location within the given distance of the initial
1620 * location, and with "los()" from the source to destination location.
1622 * This function is often called from inside a loop which searches for
1623 * locations while increasing the "d" distance.
1625 * Currently the "m" parameter is unused.
1627 void scatter(player_type *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
1629 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1633 ny = rand_spread(y, d);
1634 nx = rand_spread(x, d);
1636 if (!in_bounds(floor_ptr, ny, nx)) continue;
1637 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
1638 if (mode & PROJECT_LOS)
1640 if (los(player_ptr, y, x, ny, nx)) break;
1644 if (projectable(player_ptr, y, x, ny, nx)) break;