4 * @brief グリッドの実装 / low level dungeon routines -BEN-
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
9 * This software may be copied and distributed for educational, research,\n
10 * and not for profit purposes provided that this copyright and statement\n
11 * are included in all such copies. Other copyrights may also apply.\n
13 * Support for Adam Bolt's tileset, lighting and transparency effects\n
14 * by Robert Ruehlmann (rr9@angband.org)\n
16 * 2013 Deskull Doxygen向けのコメント整理\n
26 #include "object-flavor.h"
27 #include "object-hook.h"
29 #include "floor-generate.h"
36 #include "monster-status.h"
37 #include "player-status.h"
38 #include "player-effects.h"
39 #include "player-class.h"
41 #include "view-mainwindow.h"
42 #include "realm-song.h"
44 #define MONSTER_FLOW_DEPTH 32 /*!< 敵のプレイヤーに対する移動道のりの最大値(この値以上は処理を打ち切る) / OPTION: Maximum flow depth when using "MONSTER_FLOW" */
47 * Feature action flags
49 #define FAF_DESTROY 0x01
50 #define FAF_NO_DROP 0x02
51 #define FAF_CRASH_GLASS 0x04
54 * @brief 地形状態フラグテーブル /
55 * The table of features' actions
57 static const byte feature_action_flags[FF_FLAG_MAX] =
69 FAF_CRASH_GLASS, /* BASH */
71 FAF_DESTROY, /* DISARM */
73 FAF_DESTROY | FAF_CRASH_GLASS, /* TUNNEL */
74 0, /* MAY_HAVE_GOLD */
104 FAF_DESTROY | FAF_CRASH_GLASS, /* HURT_ROCK */
159 FAF_DESTROY | FAF_NO_DROP | FAF_CRASH_GLASS, /* HURT_DISI */
172 0, /* TELEPORTABLE */
178 * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
179 * @param creature_ptr 配置したいクリーチャーの参照ポインタ
180 * @return 配置に成功したらTRUEを返す
182 bool new_player_spot(player_type *creature_ptr)
184 POSITION y = 0, x = 0;
185 int max_attempts = 10000;
190 while (max_attempts--)
192 /* Pick a legal spot */
193 y = (POSITION)rand_range(1, creature_ptr->current_floor_ptr->height - 2);
194 x = (POSITION)rand_range(1, creature_ptr->current_floor_ptr->width - 2);
196 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
198 /* Must be a "naked" floor grid */
199 if (g_ptr->m_idx) continue;
200 if (creature_ptr->current_floor_ptr->dun_level)
202 f_ptr = &f_info[g_ptr->feat];
204 if (max_attempts > 5000) /* Rule 1 */
206 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
210 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
211 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
214 /* Refuse to start on anti-teleport grids in dungeon */
215 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
217 if (!player_can_enter(g_ptr->feat, 0)) continue;
218 if (!in_bounds(creature_ptr->current_floor_ptr, y, x)) continue;
220 /* Refuse to start on anti-teleport grids */
221 if (g_ptr->info & (CAVE_ICKY)) continue;
226 if (max_attempts < 1) /* Should be -1, actually if we failed... */
229 /* Save the new player grid */
239 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
240 * @param y ドアの配置を試みたいマスのY座標
241 * @param x ドアの配置を試みたいマスのX座標
242 * @param room 部屋に接している場合向けのドア生成か否か
245 void place_random_door(POSITION y, POSITION x, bool room)
248 FEAT_IDX feat = feat_none;
249 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
251 /* Initialize mimic info */
254 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
256 place_floor_bold(p_ptr->current_floor_ptr, y, x);
260 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
261 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
262 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
264 /* Choose an object */
265 tmp = randint0(1000);
267 /* Open doors (300/1000) */
270 /* Create open door */
271 feat = feat_door[type].open;
274 /* Broken doors (100/1000) */
277 /* Create broken door */
278 feat = feat_door[type].broken;
281 /* Secret doors (200/1000) */
284 /* Create secret door */
285 place_closed_door(y, x, type);
287 if (type != DOOR_CURTAIN)
289 /* Hide. If on the edge of room, use outer wall. */
290 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
292 /* Floor type terrain cannot hide a door */
293 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
295 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
297 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
304 /* Closed, locked, or stuck doors (400/1000) */
305 else place_closed_door(y, x, type);
309 if (feat != feat_none)
311 set_cave_feat(p_ptr->current_floor_ptr, y, x, feat);
315 place_floor_bold(p_ptr->current_floor_ptr, y, x);
319 delete_monster(y, x);
323 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
324 * @param y ドアの配置を試みたいマスのY座標
325 * @param x ドアの配置を試みたいマスのX座標
326 * @param type ドアの地形ID
329 void place_closed_door(POSITION y, POSITION x, int type)
332 FEAT_IDX feat = feat_none;
334 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
336 place_floor_bold(p_ptr->current_floor_ptr, y, x);
340 /* Choose an object */
343 /* Closed doors (300/400) */
346 /* Create closed door */
347 feat = feat_door[type].closed;
350 /* Locked doors (99/400) */
353 /* Create locked door */
354 feat = feat_locked_door_random(type);
357 /* Stuck doors (1/400) */
360 /* Create jammed door */
361 feat = feat_jammed_door_random(type);
364 if (feat != feat_none)
366 cave_set_feat(y, x, feat);
368 /* Now it is not floor */
369 p_ptr->current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
373 place_floor_bold(p_ptr->current_floor_ptr, y, x);
378 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
379 * @param y1 基準となるマスのY座標
380 * @param x1 基準となるマスのX座標
382 * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y1, x1)"
384 * XXX XXX This routine currently only counts actual "empty floor"\n
385 * grids which are not in rooms. We might want to also count stairs,\n
386 * open doors, closed doors, etc.
388 static int next_to_corr(POSITION y1, POSITION x1)
395 /* Scan adjacent grids */
396 for (i = 0; i < 4; i++)
400 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
402 /* Skip non floors */
403 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
405 /* Skip non "empty floor" grids */
406 if (!is_floor_grid(g_ptr))
409 /* Skip grids inside rooms */
410 if (g_ptr->info & (CAVE_ROOM)) continue;
412 /* Count these grids */
416 /* Return the number of corridors */
421 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
422 * @param y 判定を行いたいマスのY座標
423 * @param x 判定を行いたいマスのX座標
424 * @return ドアを設置可能ならばTRUEを返す
425 * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y1, x1)"
428 * Assumes "in_bounds(p_ptr->current_floor_ptr, y, x)"\n
430 static bool possible_doorway(POSITION y, POSITION x)
432 /* Count the adjacent corridors */
433 if (next_to_corr(y, x) >= 2)
436 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
437 cave_have_flag_bold(y + 1, x, FF_WALL))
442 /* Check Horizontal */
443 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
444 cave_have_flag_bold(y, x + 1, FF_WALL))
455 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
456 * @param y 設置を行いたいマスのY座標
457 * @param x 設置を行いたいマスのX座標
460 void try_door(POSITION y, POSITION x)
461 { if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
464 if (cave_have_flag_bold(y, x, FF_WALL)) return;
466 /* Ignore room grids */
467 if (p_ptr->current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
469 /* Occasional door (if allowed) */
470 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
473 place_random_door(y, x, FALSE);
479 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
480 * @param x1 長方形の左端X座標(-1)
481 * @param x2 長方形の右端X座標(+1)
482 * @param y1 長方形の上端Y座標(-1)
483 * @param y2 長方形の下端Y座標(+1)
487 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
491 /* Place a full floor under the room */
492 for (y = y1 - 1; y <= y2 + 1; y++)
494 for (x = x1 - 1; x <= x2 + 1; x++)
496 place_floor_bold(p_ptr->current_floor_ptr, y, x);
497 add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_ROOM);
498 if (light) add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_GLOW);
505 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
506 * @param x1 長方形の左端X座標(-1)
507 * @param x2 長方形の右端X座標(+1)
508 * @param y1 長方形の上端Y座標(-1)
509 * @param y2 長方形の下端Y座標(+1)
513 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
517 place_floor(x1, x2, y1, y2, light);
519 /* Walls around the room */
520 for (y = y1 - 1; y <= y2 + 1; y++)
522 place_outer_bold(p_ptr->current_floor_ptr, y, x1 - 1);
523 place_outer_bold(p_ptr->current_floor_ptr, y, x2 + 1);
525 for (x = x1 - 1; x <= x2 + 1; x++)
527 place_outer_bold(p_ptr->current_floor_ptr, y1 - 1, x);
528 place_outer_bold(p_ptr->current_floor_ptr, y2 + 1, x);
534 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
535 * @param y 配置したい中心マスのY座標
536 * @param x 配置したい中心マスのX座標
540 * Only really called by some of the "vault" routines.
542 void vault_objects(POSITION y, POSITION x, int num)
545 int i = 0, j = y, k = x;
550 /* Attempt to place 'num' objects */
551 for (; num > 0; --num)
553 /* Try up to 11 spots looking for empty space */
554 for (i = 0; i < 11; ++i)
556 /* Pick a random location */
557 while (dummy < SAFE_MAX_ATTEMPTS)
559 j = rand_spread(y, 2);
560 k = rand_spread(x, 3);
562 if (!in_bounds(p_ptr->current_floor_ptr, j, k)) continue;
566 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
568 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
571 /* Require "clean" floor space */
572 g_ptr = &p_ptr->current_floor_ptr->grid_array[j][k];
573 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
575 if (randint0(100) < 75)
577 place_object(j, k, 0L);
584 /* Placement accomplished */
591 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
592 * @param y トラップを配置したいマスの中心Y座標
593 * @param x トラップを配置したいマスの中心X座標
594 * @param yd Y方向の配置分散マス数
595 * @param xd X方向の配置分散マス数
598 * Only really called by some of the "vault" routines.
600 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
602 int count = 0, y1 = y, x1 = x;
608 for (count = 0; count <= 5; count++)
611 while (dummy < SAFE_MAX_ATTEMPTS)
613 y1 = rand_spread(y, yd);
614 x1 = rand_spread(x, xd);
616 if (!in_bounds(p_ptr->current_floor_ptr, y1, x1)) continue;
620 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
622 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
625 /* Require "naked" floor grids */
626 g_ptr = &p_ptr->current_floor_ptr->grid_array[y1][x1];
627 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
630 place_trap(p_ptr->current_floor_ptr, y1, x1);
637 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
638 * @param y トラップを配置したいマスの中心Y座標
639 * @param x トラップを配置したいマスの中心X座標
640 * @param yd Y方向の配置分散マス数
641 * @param xd X方向の配置分散マス数
642 * @param num 配置したいトラップの数
645 * Only really called by some of the "vault" routines.
647 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
651 for (i = 0; i < num; i++)
653 vault_trap_aux(y, x, yd, xd);
658 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
659 * @param x チェックするマスのX座標
660 * @param y チェックするマスのY座標
661 * @return 床系地形ならばTRUE
663 bool get_is_floor(POSITION x, POSITION y)
665 if (!in_bounds(p_ptr->current_floor_ptr, y, x))
671 /* Do the real check */
672 if (is_floor_bold(p_ptr->current_floor_ptr, y, x)) return (TRUE);
678 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
679 * @param x 地形を変えたいマスのX座標
680 * @param y 地形を変えたいマスのY座標
683 void set_floor(POSITION x, POSITION y)
685 if (!in_bounds(p_ptr->current_floor_ptr, y, x))
691 if (p_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
693 /* A room border don't touch. */
697 /* Set to be floor if is a wall (don't touch lakes). */
698 if (is_extra_bold(p_ptr->current_floor_ptr, y, x))
699 place_floor_bold(p_ptr->current_floor_ptr, y, x);
703 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
704 * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
707 void place_bound_perm_wall(grid_type *g_ptr)
709 if (bound_walls_perm)
711 /* Clear boundary mimic */
716 feature_type *f_ptr = &f_info[g_ptr->feat];
718 /* Hack -- Decline boundary walls with known treasure */
719 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
720 !have_flag(f_ptr->flags, FF_SECRET))
721 g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
723 /* Set boundary mimic */
724 g_ptr->mimic = g_ptr->feat;
727 /* Add "solid" perma-wall */
728 place_solid_perm_grid(g_ptr);
732 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
733 * @param g_ptr マス構造体の参照ポインタ
734 * @return 看破済みの罠があるならTRUEを返す。
736 bool is_known_trap(grid_type *g_ptr)
738 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
739 is_trap(g_ptr->feat)) return TRUE;
747 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
748 * @param g_ptr マス構造体の参照ポインタ
749 * @return 隠されたドアがあるならTRUEを返す。
751 bool is_hidden_door(grid_type *g_ptr)
753 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
754 is_closed_door(g_ptr->feat))
760 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
764 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
767 * @return 指定された座標に照明がかかっているならTRUEを返す。。
769 bool check_local_illumination(POSITION y, POSITION x)
771 /* Hack -- move towards player */
772 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
773 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
775 /* Check for "local" illumination */
777 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
779 /* Check for "complex" illumination */
780 if ((feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[yy][xx])) &&
781 (p_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
782 (feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[y][xx])) &&
783 (p_ptr->current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
784 (feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[yy][x])) &&
785 (p_ptr->current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
791 #else /* COMPLEX_WALL_ILLUMINATION */
793 /* Check for "simple" illumination */
794 return (p_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
796 #endif /* COMPLEX_WALL_ILLUMINATION */
800 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
801 #define update_local_illumination_aux(C, Y, X) \
803 if (player_has_los_bold((C), (Y), (X))) \
805 /* Update the monster */ \
806 if ((C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster((C), (C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
808 /* Notice and redraw */ \
809 note_spot((Y), (X)); \
810 lite_spot((Y), (X)); \
815 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
816 * @param creature_ptr 視界元のクリーチャー
821 void update_local_illumination(player_type * creature_ptr, POSITION y, POSITION x)
826 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
828 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
830 if ((y != creature_ptr->y) && (x != creature_ptr->x))
832 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
833 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
834 update_local_illumination_aux(creature_ptr, yy, xx);
835 update_local_illumination_aux(creature_ptr, y, xx);
836 update_local_illumination_aux(creature_ptr, yy, x);
838 else if (x != creature_ptr->x) /* y == creature_ptr->y */
840 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
841 for (i = -1; i <= 1; i++)
844 update_local_illumination_aux(creature_ptr, yy, xx);
847 update_local_illumination_aux(creature_ptr, yy, x);
849 update_local_illumination_aux(creature_ptr, yy, x);
851 else if (y != creature_ptr->y) /* x == creature_ptr->x */
853 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
854 for (i = -1; i <= 1; i++)
857 update_local_illumination_aux(creature_ptr, yy, xx);
860 update_local_illumination_aux(creature_ptr, y, xx);
862 update_local_illumination_aux(creature_ptr, y, xx);
864 else /* Player's grid */
866 for (i = 0; i < 8; i++)
870 update_local_illumination_aux(creature_ptr, yy, xx);
874 #else /* COMPLEX_WALL_ILLUMINATION */
876 if ((y != creature_ptr->y) && (x != creature_ptr->x))
878 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
879 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
880 update_local_illumination_aux(creature_ptr, yy, xx);
882 else if (x != creature_ptr->x) /* y == creature_ptr->y */
884 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
885 for (i = -1; i <= 1; i++)
888 update_local_illumination_aux(creature_ptr, yy, xx);
891 else if (y != creature_ptr->y) /* x == creature_ptr->x */
893 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
894 for (i = -1; i <= 1; i++)
897 update_local_illumination_aux(creature_ptr, yy, xx);
900 else /* Player's grid */
902 for (i = 0; i < 8; i++)
906 update_local_illumination_aux(creature_ptr, yy, xx);
910 #endif /* COMPLEX_WALL_ILLUMINATION */
915 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
916 * @return 視覚に収められていないならTRUEを返す
917 * @details player_can_see_bold()関数の返り値の否定を返している。
921 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
925 * Place an attr/char pair at the given map coordinate, if legal.
927 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
929 /* Only do "legal" locations */
930 if (panel_contains(y, x))
932 /* Hack -- fake monochrome */
935 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
936 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
937 else if (p_ptr->wraith_form) a = TERM_L_DARK;
940 /* Draw the char using the attr */
941 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
947 * Memorize interesting viewable object/features in the given grid
949 * This function should only be called on "legal" grids.
951 * This function will memorize the object and/or feature in the given
952 * grid, if they are (1) viewable and (2) interesting. Note that all
953 * objects are interesting, all terrain features except floors (and
954 * invisible traps) are interesting, and floors (and invisible traps)
955 * are interesting sometimes (depending on various options involving
956 * the illumination of floor grids).
958 * The automatic memorization of all objects and non-floor terrain
959 * features as soon as they are displayed allows incredible amounts
960 * of optimization in various places, especially "map_info()".
962 * Note that the memorization of objects is completely separate from
963 * the memorization of terrain features, preventing annoying floor
964 * memorization when a detected object is picked up from a dark floor,
965 * and object memorization when an object is dropped into a floor grid
966 * which is memorized but out-of-sight.
968 * This function should be called every time the "memorization" of
969 * a grid (or the object in a grid) is called into question, such
970 * as when an object is created in a grid, when a terrain feature
971 * "changes" from "floor" to "non-floor", when any grid becomes
972 * "illuminated" or "viewable", and when a "floor" grid becomes
975 * Note the relatively efficient use of this function by the various
976 * "update_view()" and "update_lite()" calls, to allow objects and
977 * terrain features to be memorized (and drawn) whenever they become
978 * viewable or illuminated in any way, but not when they "maintain"
979 * or "lose" their previous viewability or illumination.
981 * Note the butchered "internal" version of "player_can_see_bold()",
982 * optimized primarily for the most common cases, that is, for the
983 * non-marked floor grids.
985 void note_spot(POSITION y, POSITION x)
987 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
988 OBJECT_IDX this_o_idx, next_o_idx = 0;
990 /* Blind players see nothing */
991 if (p_ptr->blind) return;
993 /* Analyze non-torch-lit grids */
994 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
996 /* Require line of sight to the grid */
997 if (!(g_ptr->info & (CAVE_VIEW))) return;
999 /* Require "perma-lite" of the grid */
1000 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1003 if (!p_ptr->see_nocto) return;
1008 /* Hack -- memorize objects */
1009 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1011 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
1012 next_o_idx = o_ptr->next_o_idx;
1014 /* Memorize objects */
1015 o_ptr->marked |= OM_FOUND;
1019 /* Hack -- memorize grids */
1020 if (!(g_ptr->info & (CAVE_MARK)))
1022 /* Feature code (applying "mimic" field) */
1023 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
1025 /* Memorize some "boring" grids */
1026 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1028 /* Option -- memorize all torch-lit floors */
1029 if (view_torch_grids &&
1030 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1032 g_ptr->info |= (CAVE_MARK);
1035 /* Option -- memorize all perma-lit floors */
1036 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1038 g_ptr->info |= (CAVE_MARK);
1042 /* Memorize normal grids */
1043 else if (have_flag(f_ptr->flags, FF_LOS))
1045 g_ptr->info |= (CAVE_MARK);
1048 /* Memorize torch-lit walls */
1049 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1051 g_ptr->info |= (CAVE_MARK);
1054 /* Memorize walls seen by noctovision of Ninja */
1055 else if (p_ptr->see_nocto)
1057 g_ptr->info |= (CAVE_MARK);
1060 /* Memorize certain non-torch-lit wall grids */
1061 else if (check_local_illumination(y, x))
1063 g_ptr->info |= (CAVE_MARK);
1067 /* Memorize terrain of the grid */
1068 g_ptr->info |= (CAVE_KNOWN);
1072 * Redraw (on the screen) a given MAP location
1074 * This function should only be called on "legal" grids
1076 void lite_spot(POSITION y, POSITION x)
1078 /* Redraw if on screen */
1079 if (panel_contains(y, x) && in_bounds2(p_ptr->current_floor_ptr, y, x))
1086 map_info(y, x, &a, &c, &ta, &tc);
1088 /* Hack -- fake monochrome */
1091 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1092 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1093 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1096 /* Hack -- Queue it */
1097 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
1099 /* Update sub-windows */
1100 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1105 * Some comments on the grid flags. -BEN-
1108 * One of the major bottlenecks in previous versions of Angband was in
1109 * the calculation of "line of sight" from the player to various grids,
1110 * such as monsters. This was such a nasty bottleneck that a lot of
1111 * silly things were done to reduce the dependancy on "line of sight",
1112 * for example, you could not "see" any grids in a lit room until you
1113 * actually entered the room, and there were all kinds of bizarre grid
1114 * flags to enable this behavior. This is also why the "call light"
1115 * spells always lit an entire room.
1117 * The code below provides functions to calculate the "field of view"
1118 * for the player, which, once calculated, provides extremely fast
1119 * calculation of "line of sight from the player", and to calculate
1120 * the "field of torch lite", which, again, once calculated, provides
1121 * extremely fast calculation of "which grids are lit by the player's
1122 * lite source". In addition to marking grids as "GRID_VIEW" and/or
1123 * "GRID_LITE", as appropriate, these functions maintain an array for
1124 * each of these two flags, each array containing the locations of all
1125 * of the grids marked with the appropriate flag, which can be used to
1126 * very quickly scan through all of the grids in a given set.
1128 * To allow more "semantically valid" field of view semantics, whenever
1129 * the field of view (or the set of torch lit grids) changes, all of the
1130 * grids in the field of view (or the set of torch lit grids) are "drawn"
1131 * so that changes in the world will become apparent as soon as possible.
1132 * This has been optimized so that only grids which actually "change" are
1133 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
1134 * of the grids which are entering or leaving the relevent set of grids.
1136 * These new methods are so efficient that the old nasty code was removed.
1138 * Note that there is no reason to "update" the "viewable space" unless
1139 * the player "moves", or walls/doors are created/destroyed, and there
1140 * is no reason to "update" the "torch lit grids" unless the field of
1141 * view changes, or the "light radius" changes. This means that when
1142 * the player is resting, or digging, or doing anything that does not
1143 * involve movement or changing the state of the dungeon, there is no
1144 * need to update the "view" or the "lite" regions, which is nice.
1146 * Note that the calls to the nasty "los()" function have been reduced
1147 * to a bare minimum by the use of the new "field of view" calculations.
1149 * I wouldn't be surprised if slight modifications to the "update_view()"
1150 * function would allow us to determine "reverse line-of-sight" as well
1151 * as "normal line-of-sight", which would allow monsters to use a more
1152 * "correct" calculation to determine if they can "see" the player. For
1153 * now, monsters simply "cheat" somewhat and assume that if the player
1154 * has "line of sight" to the monster, then the monster can "pretend"
1155 * that it has "line of sight" to the player.
1158 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
1159 * grid and maintains an array of all "CAVE_LITE" grids.
1161 * This set of grids is the complete set of all grids which are lit by
1162 * the players light source, which allows the "player_can_see_bold()"
1163 * function to work very quickly.
1165 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
1166 * fact, the player (unless blind) can always "see" all grids which are
1167 * marked as "CAVE_LITE", unless they are "off screen".
1170 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
1171 * grid and maintains an array of all "CAVE_VIEW" grids.
1173 * This set of grids is the complete set of all grids within line of sight
1174 * of the player, allowing the "player_has_los_bold(p_ptr, )" macro to work very
1178 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
1179 * temporary internal flag to mark those grids which are not only in view,
1180 * but which are also "easily" in line of sight of the player. This flag
1181 * is always cleared when we are done.
1184 * The current "update_lite()" and "update_view()" algorithms use the
1185 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
1186 * to keep track of which grids were previously marked as "CAVE_LITE" or
1187 * "CAVE_VIEW", which allows us to optimize the "screen updates".
1189 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
1190 * for various other purposes, such as spreading lite or darkness during
1191 * "lite_room()" / "unlite_room()", and for calculating monster flow.
1194 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
1195 * in some way permanently lit. However, for the player to "see" anything
1196 * in the grid, as determined by "player_can_see()", the player must not be
1197 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
1198 * grids, even if marked as "perma lit", are only illuminated if they touch
1199 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
1202 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
1203 * that even if the player cannot "see" the grid, he "knows" the terrain in
1204 * that grid. This is used to "remember" walls/doors/stairs/floors when they
1205 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite(p_ptr, )",
1206 * or when one of the "memorize floor grids" options induces memorization.
1208 * Objects are "memorized" in a different way, using a special "marked" flag
1209 * on the object itself, which is set when an object is observed or detected.
1212 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
1213 * and should be illuminated by "lite room" and "darkness" spells.
1216 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
1217 * and should be unavailable for "teleportation" destinations.
1220 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
1221 * which is observed, and the "view_torch_grids" allows the player to memorize
1222 * every torch-lit grid. The player will always memorize important walls,
1223 * doors, stairs, and other terrain features, as well as any "detected" grids.
1225 * Note that the new "update_view()" method allows, among other things, a room
1226 * to be "partially" seen as the player approaches it, with a growing cone of
1227 * floor appearing as the player gets closer to the door. Also, by not turning
1228 * on the "memorize perma-lit grids" option, the player will only "see" those
1229 * floor grids which are actually in line of sight.
1231 * And my favorite "plus" is that you can now use a special option to draw the
1232 * "floors" in the "viewable region" brightly (actually, to draw the *other*
1233 * grids dimly), providing a "pretty" effect as the player runs around, and
1234 * to efficiently display the "torch lite" in a special color.
1237 * Some comments on the "update_view()" algorithm...
1239 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
1240 * and only has to call "los()" on the borderline cases. The major axes/diags
1241 * even terminate early when they hit walls. I need to find a quick way
1242 * to "terminate" the other scans.
1244 * Note that in the worst case (a big empty area with say 5% scattered walls),
1245 * each of the 1500 or so nearby grids is checked once, most of them getting
1246 * an "instant" rating, and only a small portion requiring a call to "los()".
1248 * The only time that the algorithm appears to be "noticeably" too slow is
1249 * when running, and this is usually only important in town, since the town
1250 * provides about the worst scenario possible, with large open regions and
1251 * a few scattered obstructions. There is a special "efficiency" option to
1252 * allow the player to reduce his field of view in town, if needed.
1254 * In the "best" case (say, a normal stretch of corridor), the algorithm
1255 * makes one check for each viewable grid, and makes no calls to "los()".
1256 * So running in corridors is very fast, and if a lot of monsters are
1257 * nearby, it is much faster than the old methods.
1259 * Note that resting, most normal commands, and several forms of running,
1260 * plus all commands executed near large groups of monsters, are strictly
1261 * more efficient with "update_view()" that with the old "compute los() on
1262 * demand" method, primarily because once the "field of view" has been
1263 * calculated, it does not have to be recalculated until the player moves
1264 * (or a wall or door is created or destroyed).
1266 * Note that we no longer have to do as many "los()" checks, since once the
1267 * "view" region has been built, very few things cause it to be "changed"
1268 * (player movement, and the opening/closing of doors, changes in wall status).
1269 * Note that door/wall changes are only relevant when the door/wall itself is
1270 * in the "view" region.
1272 * The algorithm seems to only call "los()" from zero to ten times, usually
1273 * only when coming down a corridor into a room, or standing in a room, just
1274 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
1275 * we will be reducing the calls to "los()".
1277 * I am thinking in terms of an algorithm that "walks" from the central point
1278 * out to the maximal "distance", at each point, determining the "view" code
1279 * (above). For each grid not on a major axis or diagonal, the "view" code
1280 * depends on the "cave_los_bold(p_ptr->current_floor_ptr, )" and "view" of exactly two other grids
1281 * (the one along the nearest diagonal, and the one next to that one, see
1282 * "update_view_aux()"...).
1284 * We "memorize" the viewable space array, so that at the cost of under 3000
1285 * bytes, we reduce the time taken by "forget_view()" to one assignment for
1286 * each grid actually in the "viewable space". And for another 3000 bytes,
1287 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
1288 * are also used by other routines, thus reducing the cost to almost nothing.
1290 * A similar thing is done for "forget_lite()" in which case the savings are
1291 * much less, but save us from doing bizarre maintenance checking.
1293 * In the worst "normal" case (in the middle of the town), the reachable space
1294 * actually reaches to more than half of the largest possible "circle" of view,
1295 * or about 800 grids, and in the worse case (in the middle of a dungeon level
1296 * where all the walls have been removed), the reachable space actually reaches
1297 * the theoretical maximum size of just under 1500 grids.
1299 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
1300 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
1301 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
1302 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
1303 * entire possible space (including initialization) in one step per grid. If
1304 * we do the "clearing" as a separate step (and use an array of "view" grids),
1305 * then the clearing will take as many steps as grids that were viewed, and the
1306 * algorithm will be able to "stop" scanning at various points.
1307 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
1311 * Mega-Hack -- Delayed visual update
1312 * Only used if update_view(), update_lite() or update_mon_lite() was called
1314 void delayed_visual_update(void)
1320 /* Update needed grids */
1321 for (i = 0; i < p_ptr->current_floor_ptr->redraw_n; i++)
1323 y = p_ptr->current_floor_ptr->redraw_y[i];
1324 x = p_ptr->current_floor_ptr->redraw_x[i];
1325 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1327 /* Update only needed grids (prevent multiple updating) */
1328 if (!(g_ptr->info & CAVE_REDRAW)) continue;
1330 /* If required, note */
1331 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
1335 /* Hack -- Visual update of monster on this grid */
1336 if (g_ptr->m_idx) update_monster(p_ptr, g_ptr->m_idx, FALSE);
1338 /* No longer in the array */
1339 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
1343 p_ptr->current_floor_ptr->redraw_n = 0;
1348 * Hack - speed up the update_flow algorithm by only doing
1349 * it everytime the player moves out of LOS of the last
1352 static POSITION flow_x = 0;
1353 static POSITION flow_y = 0;
1358 * Hack -- fill in the "cost" field of every grid that the player
1359 * can "reach" with the number of steps needed to reach that grid.
1360 * This also yields the "distance" of the player from every grid.
1362 * In addition, mark the "when" of the grids that can reach
1363 * the player with the incremented value of "flow_n".
1365 * Hack -- use the "seen" array as a "circular queue".
1367 * We do not need a priority queue because the cost from grid
1368 * to grid is always "one" and we process them in order.
1370 void update_flow(void)
1377 /* Paranoia -- make sure the array is empty */
1378 if (tmp_pos.n) return;
1380 /* The last way-point is on the map */
1381 if (p_ptr->running && in_bounds(p_ptr->current_floor_ptr, flow_y, flow_x))
1383 /* The way point is in sight - do not update. (Speedup) */
1384 if (p_ptr->current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
1387 /* Erase all of the current flow information */
1388 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
1390 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
1392 p_ptr->current_floor_ptr->grid_array[y][x].cost = 0;
1393 p_ptr->current_floor_ptr->grid_array[y][x].dist = 0;
1397 /* Save player position */
1401 /* Add the player's grid to the queue */
1402 tmp_pos.y[0] = p_ptr->y;
1403 tmp_pos.x[0] = p_ptr->x;
1405 /* Now process the queue */
1406 while (flow_head != flow_tail)
1410 /* Extract the next entry */
1411 ty = tmp_pos.y[flow_tail];
1412 tx = tmp_pos.x[flow_tail];
1414 /* Forget that entry */
1415 if (++flow_tail == TEMP_MAX) flow_tail = 0;
1417 /* Add the "children" */
1418 for (d = 0; d < 8; d++)
1420 int old_head = flow_head;
1421 byte_hack m = p_ptr->current_floor_ptr->grid_array[ty][tx].cost + 1;
1422 byte_hack n = p_ptr->current_floor_ptr->grid_array[ty][tx].dist + 1;
1425 /* Child location */
1426 y = ty + ddy_ddd[d];
1427 x = tx + ddx_ddd[d];
1429 /* Ignore player's grid */
1430 if (player_bold(p_ptr, y, x)) continue;
1432 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1434 if (is_closed_door(g_ptr->feat)) m += 3;
1436 /* Ignore "pre-stamped" entries */
1437 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
1439 /* Ignore "walls" and "rubble" */
1440 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1442 /* Save the flow cost */
1443 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
1444 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
1446 /* Hack -- limit flow depth */
1447 if (n == MONSTER_FLOW_DEPTH) continue;
1449 /* Enqueue that entry */
1450 tmp_pos.y[flow_head] = y;
1451 tmp_pos.x[flow_head] = x;
1453 /* Advance the queue */
1454 if (++flow_head == TEMP_MAX) flow_head = 0;
1456 /* Hack -- notice overflow by forgetting new entry */
1457 if (flow_head == flow_tail) flow_head = old_head;
1463 * Change the "feat" flag for a grid, and notice/redraw the grid
1465 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
1467 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1468 feature_type *f_ptr = &f_info[feat];
1469 bool old_los, old_mirror;
1471 if (!current_world_ptr->character_dungeon)
1473 /* Clear mimic type */
1476 /* Change the feature */
1479 /* Hack -- glow the GLOW terrain */
1480 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1485 for (i = 0; i < 9; i++)
1487 yy = y + ddy_ddd[i];
1488 xx = x + ddx_ddd[i];
1489 if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
1490 p_ptr->current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
1497 old_los = cave_have_flag_bold(y, x, FF_LOS);
1498 old_mirror = is_mirror_grid(g_ptr);
1500 /* Clear mimic type */
1503 /* Change the feature */
1506 /* Remove flag for mirror/glyph */
1507 g_ptr->info &= ~(CAVE_OBJECT);
1509 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1511 g_ptr->info &= ~(CAVE_GLOW);
1512 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1514 update_local_illumination(p_ptr, y, x);
1517 /* Check for change to boring grid */
1518 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1519 if (g_ptr->m_idx) update_monster(p_ptr, g_ptr->m_idx, FALSE);
1524 /* Check if los has changed */
1525 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
1528 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1530 update_local_illumination(p_ptr, y, x);
1532 #endif /* COMPLEX_WALL_ILLUMINATION */
1534 /* Update the visuals */
1535 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
1538 /* Hack -- glow the GLOW terrain */
1539 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1545 for (i = 0; i < 9; i++)
1547 yy = y + ddy_ddd[i];
1548 xx = x + ddx_ddd[i];
1549 if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
1550 cc_ptr = &p_ptr->current_floor_ptr->grid_array[yy][xx];
1551 cc_ptr->info |= CAVE_GLOW;
1553 if (player_has_los_grid(cc_ptr))
1555 if (cc_ptr->m_idx) update_monster(p_ptr, cc_ptr->m_idx, FALSE);
1562 update_local_illumination(p_ptr, yy, xx);
1565 if (p_ptr->special_defense & NINJA_S_STEALTH)
1567 if (p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(p_ptr, FALSE);
1572 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
1574 feature_type *f_ptr = &f_info[newfeat];
1576 if (have_flag(f_ptr->flags, FF_CONVERT))
1578 switch (f_ptr->subtype)
1580 case CONVERT_TYPE_FLOOR:
1581 return feat_ground_type[randint0(100)];
1582 case CONVERT_TYPE_WALL:
1583 return feat_wall_type[randint0(100)];
1584 case CONVERT_TYPE_INNER:
1585 return feat_wall_inner;
1586 case CONVERT_TYPE_OUTER:
1587 return feat_wall_outer;
1588 case CONVERT_TYPE_SOLID:
1589 return feat_wall_solid;
1590 case CONVERT_TYPE_STREAM1:
1591 return d_info[p_ptr->dungeon_idx].stream1;
1592 case CONVERT_TYPE_STREAM2:
1593 return d_info[p_ptr->dungeon_idx].stream2;
1598 else return newfeat;
1603 * Take a feature, determine what that feature becomes
1604 * through applying the given action.
1606 FEAT_IDX feat_state(FEAT_IDX feat, int action)
1608 feature_type *f_ptr = &f_info[feat];
1611 /* Get the new feature */
1612 for (i = 0; i < MAX_FEAT_STATES; i++)
1614 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
1617 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
1619 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
1623 * Takes a location and action and changes the feature at that
1624 * location through applying the given action.
1626 void cave_alter_feat(POSITION y, POSITION x, int action)
1628 /* Set old feature */
1629 FEAT_IDX oldfeat = p_ptr->current_floor_ptr->grid_array[y][x].feat;
1631 /* Get the new feat */
1632 FEAT_IDX newfeat = feat_state(oldfeat, action);
1635 if (newfeat == oldfeat) return;
1637 /* Set the new feature */
1638 cave_set_feat(y, x, newfeat);
1640 if (!(feature_action_flags[action] & FAF_NO_DROP))
1642 feature_type *old_f_ptr = &f_info[oldfeat];
1643 feature_type *f_ptr = &f_info[newfeat];
1647 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
1649 /* Place some gold */
1655 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - p_ptr->current_floor_ptr->dun_level / 2)))
1658 place_object(y, x, 0L);
1662 if (found && current_world_ptr->character_dungeon && player_can_see_bold(y, x))
1664 msg_print(_("何かを発見した!", "You have found something!"));
1668 if (feature_action_flags[action] & FAF_CRASH_GLASS)
1670 feature_type *old_f_ptr = &f_info[oldfeat];
1672 if (have_flag(old_f_ptr->flags, FF_GLASS) && current_world_ptr->character_dungeon)
1674 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(p_ptr->current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
1675 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
1681 /* Remove a mirror */
1682 void remove_mirror(POSITION y, POSITION x)
1684 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1686 /* Remove the mirror */
1687 g_ptr->info &= ~(CAVE_OBJECT);
1690 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
1692 g_ptr->info &= ~(CAVE_GLOW);
1693 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1694 if (g_ptr->m_idx) update_monster(p_ptr, g_ptr->m_idx, FALSE);
1696 update_local_illumination(p_ptr, y, x);
1706 * Return TRUE if there is a mirror on the grid.
1708 bool is_mirror_grid(grid_type *g_ptr)
1710 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
1718 * Return TRUE if there is a mirror on the grid.
1720 bool is_glyph_grid(grid_type *g_ptr)
1722 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
1730 * Return TRUE if there is a mirror on the grid.
1732 bool is_explosive_rune_grid(grid_type *g_ptr)
1734 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
1741 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
1742 * @param m_idx モンスターID
1746 * @return テレポート先として妥当ならばtrue
1748 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
1750 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
1751 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1752 feature_type *f_ptr = &f_info[g_ptr->feat];
1754 /* Require "teleportable" space */
1755 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
1757 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
1758 if (player_bold(p_ptr, y, x)) return FALSE;
1760 /* Hack -- no teleport onto glyph of warding */
1761 if (is_glyph_grid(g_ptr)) return FALSE;
1762 if (is_explosive_rune_grid(g_ptr)) return FALSE;
1764 if (!(mode & TELEPORT_PASSIVE))
1766 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
1773 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
1777 * @return テレポート先として妥当ならばtrue
1779 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
1781 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1782 feature_type *f_ptr = &f_info[g_ptr->feat];
1784 /* Require "teleportable" space */
1785 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
1787 /* No magical teleporting into vaults and such */
1788 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
1790 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
1792 /* don't teleport on a trap. */
1793 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
1795 if (!(mode & TELEPORT_PASSIVE))
1797 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
1799 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
1801 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
1804 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
1806 /* Always forbid deep lava */
1807 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
1809 /* Forbid shallow lava when the player don't have levitation */
1810 if (!p_ptr->levitation) return FALSE;
1819 * @brief 地形は開くものであって、かつ開かれているかを返す /
1820 * Attempt to open the given chest at the given location
1822 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
1824 bool is_open(FEAT_IDX feat)
1826 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
1830 * @brief プレイヤーが地形踏破可能かを返す
1831 * @param feature 判定したい地形ID
1832 * @param mode 移動に関するオプションフラグ
1833 * @return 移動可能ならばTRUEを返す
1835 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
1837 feature_type *f_ptr = &f_info[feature];
1839 if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[p_ptr->current_floor_ptr->m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
1841 if (have_flag(f_ptr->flags, FF_PATTERN))
1843 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
1846 if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
1847 if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
1848 if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
1850 if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;