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
53 #define feat_locked_door_random(DOOR_TYPE) \
54 (feat_door[(DOOR_TYPE)].num_locked ? \
55 feat_door[(DOOR_TYPE)].locked[randint0(feat_door[(DOOR_TYPE)].num_locked)] : feat_none)
57 #define feat_jammed_door_random(DOOR_TYPE) \
58 (feat_door[(DOOR_TYPE)].num_jammed ? \
59 feat_door[(DOOR_TYPE)].jammed[randint0(feat_door[(DOOR_TYPE)].num_jammed)] : feat_none)
62 * @brief 地形状態フラグテーブル /
63 * The table of features' actions
65 static const byte feature_action_flags[FF_FLAG_MAX] =
77 FAF_CRASH_GLASS, /* BASH */
79 FAF_DESTROY, /* DISARM */
81 FAF_DESTROY | FAF_CRASH_GLASS, /* TUNNEL */
82 0, /* MAY_HAVE_GOLD */
112 FAF_DESTROY | FAF_CRASH_GLASS, /* HURT_ROCK */
167 FAF_DESTROY | FAF_NO_DROP | FAF_CRASH_GLASS, /* HURT_DISI */
180 0, /* TELEPORTABLE */
186 * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
187 * @return 配置に成功したらTRUEを返す
189 bool new_player_spot(void)
191 POSITION y = 0, x = 0;
192 int max_attempts = 10000;
197 /* Place the player */
198 while (max_attempts--)
200 /* Pick a legal spot */
201 y = (POSITION)rand_range(1, current_floor_ptr->height - 2);
202 x = (POSITION)rand_range(1, current_floor_ptr->width - 2);
204 g_ptr = ¤t_floor_ptr->grid_array[y][x];
206 /* Must be a "naked" floor grid */
207 if (g_ptr->m_idx) continue;
208 if (current_floor_ptr->dun_level)
210 f_ptr = &f_info[g_ptr->feat];
212 if (max_attempts > 5000) /* Rule 1 */
214 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
218 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
219 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
222 /* Refuse to start on anti-teleport grids in dungeon */
223 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
225 if (!player_can_enter(g_ptr->feat, 0)) continue;
226 if (!in_bounds(y, x)) continue;
228 /* Refuse to start on anti-teleport grids */
229 if (g_ptr->info & (CAVE_ICKY)) continue;
234 if (max_attempts < 1) /* Should be -1, actually if we failed... */
237 /* Save the new player grid */
247 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
248 * @param y 配置を試みたいマスのY座標
249 * @param x 配置を試みたいマスのX座標
252 void place_random_stairs(POSITION y, POSITION x)
254 bool up_stairs = TRUE;
255 bool down_stairs = TRUE;
257 g_ptr = ¤t_floor_ptr->grid_array[y][x];
258 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
261 if (!current_floor_ptr->dun_level) up_stairs = FALSE;
264 if (ironman_downward) up_stairs = FALSE;
267 if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
270 if (quest_number(current_floor_ptr->dun_level) && (current_floor_ptr->dun_level > 1)) down_stairs = FALSE;
272 /* We can't place both */
273 if (down_stairs && up_stairs)
275 /* Choose a staircase randomly */
276 if (randint0(100) < 50) up_stairs = FALSE;
277 else down_stairs = FALSE;
280 /* Place the stairs */
281 if (up_stairs) place_up_stairs(y, x);
282 else if (down_stairs) place_down_stairs(y, x);
286 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
287 * @param y ドアの配置を試みたいマスのY座標
288 * @param x ドアの配置を試みたいマスのX座標
289 * @param room 部屋に接している場合向けのドア生成か否か
292 void place_random_door(POSITION y, POSITION x, bool room)
295 FEAT_IDX feat = feat_none;
296 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
298 /* Initialize mimic info */
301 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
303 place_floor_bold(y, x);
307 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
308 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
309 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
311 /* Choose an object */
312 tmp = randint0(1000);
314 /* Open doors (300/1000) */
317 /* Create open door */
318 feat = feat_door[type].open;
321 /* Broken doors (100/1000) */
324 /* Create broken door */
325 feat = feat_door[type].broken;
328 /* Secret doors (200/1000) */
331 /* Create secret door */
332 place_closed_door(y, x, type);
334 if (type != DOOR_CURTAIN)
336 /* Hide. If on the edge of room, use outer wall. */
337 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
339 /* Floor type terrain cannot hide a door */
340 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
342 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
344 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
351 /* Closed, locked, or stuck doors (400/1000) */
352 else place_closed_door(y, x, type);
356 if (feat != feat_none)
358 set_cave_feat(y, x, feat);
362 place_floor_bold(y, x);
366 delete_monster(y, x);
370 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
371 * @param y ドアの配置を試みたいマスのY座標
372 * @param x ドアの配置を試みたいマスのX座標
373 * @param type ドアの地形ID
376 void place_closed_door(POSITION y, POSITION x, int type)
379 FEAT_IDX feat = feat_none;
381 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
383 place_floor_bold(y, x);
387 /* Choose an object */
390 /* Closed doors (300/400) */
393 /* Create closed door */
394 feat = feat_door[type].closed;
397 /* Locked doors (99/400) */
400 /* Create locked door */
401 feat = feat_locked_door_random(type);
404 /* Stuck doors (1/400) */
407 /* Create jammed door */
408 feat = feat_jammed_door_random(type);
411 if (feat != feat_none)
413 cave_set_feat(y, x, feat);
415 /* Now it is not floor */
416 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
420 place_floor_bold(y, x);
425 * @brief 鍵のかかったドアを配置する
426 * @param y 配置したいフロアのY座標
427 * @param x 配置したいフロアのX座標
430 void place_locked_door(POSITION y, POSITION x)
432 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
434 place_floor_bold(y, x);
438 set_cave_feat(y, x, feat_locked_door_random((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
439 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
440 delete_monster(y, x);
447 * @param y 配置したいフロアのY座標
448 * @param x 配置したいフロアのX座標
449 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
452 void place_secret_door(POSITION y, POSITION x, int type)
454 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
456 place_floor_bold(y, x);
460 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
462 if (type == DOOR_DEFAULT)
464 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
465 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
466 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
469 /* Create secret door */
470 place_closed_door(y, x, type);
472 if (type != DOOR_CURTAIN)
474 /* Hide by inner wall because this is used in rooms only */
475 g_ptr->mimic = feat_wall_inner;
477 /* Floor type terrain cannot hide a door */
478 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
480 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
482 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
488 g_ptr->info &= ~(CAVE_FLOOR);
489 delete_monster(y, x);
494 * Routine used by the random vault creators to add a door to a location
495 * Note that range checking has to be done in the calling routine.
497 * The doors must be INSIDE the allocated region.
499 void add_door(POSITION x, POSITION y)
501 /* Need to have a wall in the center square */
502 if (!is_outer_bold(y, x)) return;
513 if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
514 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
517 place_secret_door(y, x, DOOR_DEFAULT);
519 /* set boundarys so don't get wide doors */
520 place_solid_bold(y, x - 1);
521 place_solid_bold(y, x + 1);
530 * where x = don't care
533 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
534 is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
537 place_secret_door(y, x, DOOR_DEFAULT);
539 /* set boundarys so don't get wide doors */
540 place_solid_bold(y - 1, x);
541 place_solid_bold(y + 1, x);
546 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
547 * @param y1 基準となるマスのY座標
548 * @param x1 基準となるマスのX座標
550 * @note Assumes "in_bounds(y1, x1)"
552 * XXX XXX This routine currently only counts actual "empty floor"\n
553 * grids which are not in rooms. We might want to also count stairs,\n
554 * open doors, closed doors, etc.
556 static int next_to_corr(POSITION y1, POSITION x1)
563 /* Scan adjacent grids */
564 for (i = 0; i < 4; i++)
568 g_ptr = ¤t_floor_ptr->grid_array[y][x];
570 /* Skip non floors */
571 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
573 /* Skip non "empty floor" grids */
574 if (!is_floor_grid(g_ptr))
577 /* Skip grids inside rooms */
578 if (g_ptr->info & (CAVE_ROOM)) continue;
580 /* Count these grids */
584 /* Return the number of corridors */
589 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
590 * @param y 判定を行いたいマスのY座標
591 * @param x 判定を行いたいマスのX座標
592 * @return ドアを設置可能ならばTRUEを返す
593 * @note Assumes "in_bounds(y1, x1)"
596 * Assumes "in_bounds(y, x)"\n
598 static bool possible_doorway(POSITION y, POSITION x)
600 /* Count the adjacent corridors */
601 if (next_to_corr(y, x) >= 2)
604 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
605 cave_have_flag_bold(y + 1, x, FF_WALL))
610 /* Check Horizontal */
611 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
612 cave_have_flag_bold(y, x + 1, FF_WALL))
623 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
624 * @param y 設置を行いたいマスのY座標
625 * @param x 設置を行いたいマスのX座標
628 void try_door(POSITION y, POSITION x)
629 { if (!in_bounds(y, x)) return;
632 if (cave_have_flag_bold(y, x, FF_WALL)) return;
634 /* Ignore room grids */
635 if (current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
637 /* Occasional door (if allowed) */
638 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
641 place_random_door(y, x, FALSE);
647 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
648 * @param x1 長方形の左端X座標(-1)
649 * @param x2 長方形の右端X座標(+1)
650 * @param y1 長方形の上端Y座標(-1)
651 * @param y2 長方形の下端Y座標(+1)
655 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
659 /* Place a full floor under the room */
660 for (y = y1 - 1; y <= y2 + 1; y++)
662 for (x = x1 - 1; x <= x2 + 1; x++)
664 place_floor_bold(y, x);
665 add_cave_info(y, x, CAVE_ROOM);
666 if (light) add_cave_info(y, x, CAVE_GLOW);
673 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
674 * @param x1 長方形の左端X座標(-1)
675 * @param x2 長方形の右端X座標(+1)
676 * @param y1 長方形の上端Y座標(-1)
677 * @param y2 長方形の下端Y座標(+1)
681 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
685 place_floor(x1, x2, y1, y2, light);
687 /* Walls around the room */
688 for (y = y1 - 1; y <= y2 + 1; y++)
690 place_outer_bold(y, x1 - 1);
691 place_outer_bold(y, x2 + 1);
693 for (x = x1 - 1; x <= x2 + 1; x++)
695 place_outer_bold(y1 - 1, x);
696 place_outer_bold(y2 + 1, x);
702 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
703 * @param y 配置したい中心マスのY座標
704 * @param x 配置したい中心マスのX座標
708 * Only really called by some of the "vault" routines.
710 void vault_objects(POSITION y, POSITION x, int num)
713 int i = 0, j = y, k = x;
718 /* Attempt to place 'num' objects */
719 for (; num > 0; --num)
721 /* Try up to 11 spots looking for empty space */
722 for (i = 0; i < 11; ++i)
724 /* Pick a random location */
725 while (dummy < SAFE_MAX_ATTEMPTS)
727 j = rand_spread(y, 2);
728 k = rand_spread(x, 3);
730 if (!in_bounds(j, k)) continue;
734 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
736 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
739 /* Require "clean" floor space */
740 g_ptr = ¤t_floor_ptr->grid_array[j][k];
741 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
743 if (randint0(100) < 75)
745 place_object(j, k, 0L);
752 /* Placement accomplished */
759 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
760 * @param y トラップを配置したいマスの中心Y座標
761 * @param x トラップを配置したいマスの中心X座標
762 * @param yd Y方向の配置分散マス数
763 * @param xd X方向の配置分散マス数
766 * Only really called by some of the "vault" routines.
768 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
770 int count = 0, y1 = y, x1 = x;
776 for (count = 0; count <= 5; count++)
779 while (dummy < SAFE_MAX_ATTEMPTS)
781 y1 = rand_spread(y, yd);
782 x1 = rand_spread(x, xd);
784 if (!in_bounds(y1, x1)) continue;
788 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
790 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
793 /* Require "naked" floor grids */
794 g_ptr = ¤t_floor_ptr->grid_array[y1][x1];
795 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
805 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
806 * @param y トラップを配置したいマスの中心Y座標
807 * @param x トラップを配置したいマスの中心X座標
808 * @param yd Y方向の配置分散マス数
809 * @param xd X方向の配置分散マス数
810 * @param num 配置したいトラップの数
813 * Only really called by some of the "vault" routines.
815 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
819 for (i = 0; i < num; i++)
821 vault_trap_aux(y, x, yd, xd);
826 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
827 * @param y1 モンスターを配置したいマスの中心Y座標
828 * @param x1 モンスターを配置したいマスの中心X座標
829 * @param num 配置したいモンスターの数
832 * Only really called by some of the "vault" routines.
834 void vault_monsters(POSITION y1, POSITION x1, int num)
840 /* Try to summon "num" monsters "near" the given location */
841 for (k = 0; k < num; k++)
843 /* Try nine locations */
844 for (i = 0; i < 9; i++)
848 /* Pick a nearby location */
849 scatter(&y, &x, y1, x1, d, 0);
851 /* Require "empty" floor grids */
852 g_ptr = ¤t_floor_ptr->grid_array[y][x];
853 if (!cave_empty_grid(g_ptr)) continue;
855 /* Place the monster (allow groups) */
856 current_floor_ptr->monster_level = current_floor_ptr->base_level + 2;
857 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
858 current_floor_ptr->monster_level = current_floor_ptr->base_level;
864 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
865 * @param x チェックするマスのX座標
866 * @param y チェックするマスのY座標
867 * @return 床系地形ならばTRUE
869 bool get_is_floor(POSITION x, POSITION y)
871 if (!in_bounds(y, x))
877 /* Do the real check */
878 if (is_floor_bold(y, x)) return (TRUE);
884 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
885 * @param x 地形を変えたいマスのX座標
886 * @param y 地形を変えたいマスのY座標
889 void set_floor(POSITION x, POSITION y)
891 if (!in_bounds(y, x))
897 if (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
899 /* A room border don't touch. */
903 /* Set to be floor if is a wall (don't touch lakes). */
904 if (is_extra_bold(y, x))
905 place_floor_bold(y, x);
909 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
910 * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
913 void place_bound_perm_wall(grid_type *g_ptr)
915 if (bound_walls_perm)
917 /* Clear boundary mimic */
922 feature_type *f_ptr = &f_info[g_ptr->feat];
924 /* Hack -- Decline boundary walls with known treasure */
925 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
926 !have_flag(f_ptr->flags, FF_SECRET))
927 g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
929 /* Set boundary mimic */
930 g_ptr->mimic = g_ptr->feat;
933 /* Add "solid" perma-wall */
934 place_solid_perm_grid(g_ptr);
938 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
939 * @param g_ptr マス構造体の参照ポインタ
940 * @return 看破済みの罠があるならTRUEを返す。
942 bool is_known_trap(grid_type *g_ptr)
944 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
945 is_trap(g_ptr->feat)) return TRUE;
953 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
954 * @param g_ptr マス構造体の参照ポインタ
955 * @return 隠されたドアがあるならTRUEを返す。
957 bool is_hidden_door(grid_type *g_ptr)
959 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
960 is_closed_door(g_ptr->feat))
966 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
970 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
973 * @return 指定された座標に照明がかかっているならTRUEを返す。。
975 bool check_local_illumination(POSITION y, POSITION x)
977 /* Hack -- move towards player */
978 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
979 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
981 /* Check for "local" illumination */
983 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
985 /* Check for "complex" illumination */
986 if ((feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][xx])) &&
987 (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
988 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[y][xx])) &&
989 (current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
990 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][x])) &&
991 (current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
997 #else /* COMPLEX_WALL_ILLUMINATION */
999 /* Check for "simple" illumination */
1000 return (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
1002 #endif /* COMPLEX_WALL_ILLUMINATION */
1006 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
1007 #define update_local_illumination_aux(Y, X) \
1009 if (player_has_los_bold((Y), (X))) \
1011 /* Update the monster */ \
1012 if (current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster(current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
1014 /* Notice and redraw */ \
1015 note_spot((Y), (X)); \
1016 lite_spot((Y), (X)); \
1021 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
1026 void update_local_illumination(POSITION y, POSITION x)
1031 if (!in_bounds(y, x)) return;
1033 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1035 if ((y != p_ptr->y) && (x != p_ptr->x))
1037 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1038 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1039 update_local_illumination_aux(yy, xx);
1040 update_local_illumination_aux(y, xx);
1041 update_local_illumination_aux(yy, x);
1043 else if (x != p_ptr->x) /* y == p_ptr->y */
1045 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1046 for (i = -1; i <= 1; i++)
1049 update_local_illumination_aux(yy, xx);
1052 update_local_illumination_aux(yy, x);
1054 update_local_illumination_aux(yy, x);
1056 else if (y != p_ptr->y) /* x == p_ptr->x */
1058 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1059 for (i = -1; i <= 1; i++)
1062 update_local_illumination_aux(yy, xx);
1065 update_local_illumination_aux(y, xx);
1067 update_local_illumination_aux(y, xx);
1069 else /* Player's grid */
1071 for (i = 0; i < 8; i++)
1073 yy = y + ddy_cdd[i];
1074 xx = x + ddx_cdd[i];
1075 update_local_illumination_aux(yy, xx);
1079 #else /* COMPLEX_WALL_ILLUMINATION */
1081 if ((y != p_ptr->y) && (x != p_ptr->x))
1083 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1084 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1085 update_local_illumination_aux(yy, xx);
1087 else if (x != p_ptr->x) /* y == p_ptr->y */
1089 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1090 for (i = -1; i <= 1; i++)
1093 update_local_illumination_aux(yy, xx);
1096 else if (y != p_ptr->y) /* x == p_ptr->x */
1098 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1099 for (i = -1; i <= 1; i++)
1102 update_local_illumination_aux(yy, xx);
1105 else /* Player's grid */
1107 for (i = 0; i < 8; i++)
1109 yy = y + ddy_cdd[i];
1110 xx = x + ddx_cdd[i];
1111 update_local_illumination_aux(yy, xx);
1115 #endif /* COMPLEX_WALL_ILLUMINATION */
1120 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
1123 * @return 視覚に収められる状態ならTRUEを返す
1125 * He must have vision, illumination, and line of sight.\n
1127 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
1128 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
1130 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
1131 * that a wall is visible from any direction. That would be odd. Except\n
1132 * under wizard light, which might make sense. Thus, for walls, we require\n
1133 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
1134 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
1135 * in line of sight of the player.\n
1137 * This extra check is expensive, but it provides a more "correct" semantics.\n
1139 * Note that we should not run this check on walls which are "outer walls" of\n
1140 * the dungeon, or we will induce a memory fault, but actually verifying all\n
1141 * of the locations would be extremely expensive.\n
1143 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
1144 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
1145 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
1146 * and the player has more important things on his mind when he is attacking a\n
1147 * monster vault. It is annoying, but an extremely important optimization.\n
1149 * Note that "glowing walls" are only considered to be "illuminated" if the\n
1150 * grid which is next to the wall in the direction of the player is also a\n
1151 * "glowing" grid. This prevents the player from being able to "see" the\n
1152 * walls of illuminated rooms from a corridor outside the room.\n
1154 bool player_can_see_bold(POSITION y, POSITION x)
1158 /* Blind players see nothing */
1159 if (p_ptr->blind) return FALSE;
1161 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1163 /* Note that "torch-lite" yields "illumination" */
1164 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
1166 /* Require line of sight to the grid */
1167 if (!player_has_los_bold(y, x)) return FALSE;
1169 /* Noctovision of Ninja */
1170 if (p_ptr->see_nocto) return TRUE;
1172 /* Require "perma-lite" of the grid */
1173 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
1175 /* Feature code (applying "mimic" field) */
1176 /* Floors are simple */
1177 if (feat_supports_los(get_feat_mimic(g_ptr))) return TRUE;
1179 /* Check for "local" illumination */
1180 return check_local_illumination(y, x);
1184 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
1185 * @return 視覚に収められていないならTRUEを返す
1186 * @details player_can_see_bold()関数の返り値の否定を返している。
1190 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
1195 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
1198 * @return 各種の変更が可能ならTRUEを返す。
1200 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
1202 bool cave_valid_bold(POSITION y, POSITION x)
1204 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1205 OBJECT_IDX this_o_idx, next_o_idx = 0;
1207 /* Forbid perma-grids */
1208 if (cave_perma_grid(g_ptr)) return (FALSE);
1211 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1214 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1215 next_o_idx = o_ptr->next_o_idx;
1217 /* Forbid artifact grids */
1218 if (object_is_artifact(o_ptr)) return (FALSE);
1228 * Place an attr/char pair at the given map coordinate, if legal.
1230 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
1232 /* Only do "legal" locations */
1233 if (panel_contains(y, x))
1235 /* Hack -- fake monochrome */
1238 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1239 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1240 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1243 /* Draw the char using the attr */
1244 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
1253 * Memorize interesting viewable object/features in the given grid
1255 * This function should only be called on "legal" grids.
1257 * This function will memorize the object and/or feature in the given
1258 * grid, if they are (1) viewable and (2) interesting. Note that all
1259 * objects are interesting, all terrain features except floors (and
1260 * invisible traps) are interesting, and floors (and invisible traps)
1261 * are interesting sometimes (depending on various options involving
1262 * the illumination of floor grids).
1264 * The automatic memorization of all objects and non-floor terrain
1265 * features as soon as they are displayed allows incredible amounts
1266 * of optimization in various places, especially "map_info()".
1268 * Note that the memorization of objects is completely separate from
1269 * the memorization of terrain features, preventing annoying floor
1270 * memorization when a detected object is picked up from a dark floor,
1271 * and object memorization when an object is dropped into a floor grid
1272 * which is memorized but out-of-sight.
1274 * This function should be called every time the "memorization" of
1275 * a grid (or the object in a grid) is called into question, such
1276 * as when an object is created in a grid, when a terrain feature
1277 * "changes" from "floor" to "non-floor", when any grid becomes
1278 * "illuminated" or "viewable", and when a "floor" grid becomes
1281 * Note the relatively efficient use of this function by the various
1282 * "update_view()" and "update_lite()" calls, to allow objects and
1283 * terrain features to be memorized (and drawn) whenever they become
1284 * viewable or illuminated in any way, but not when they "maintain"
1285 * or "lose" their previous viewability or illumination.
1287 * Note the butchered "internal" version of "player_can_see_bold()",
1288 * optimized primarily for the most common cases, that is, for the
1289 * non-marked floor grids.
1291 void note_spot(POSITION y, POSITION x)
1293 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1294 OBJECT_IDX this_o_idx, next_o_idx = 0;
1296 /* Blind players see nothing */
1297 if (p_ptr->blind) return;
1299 /* Analyze non-torch-lit grids */
1300 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1302 /* Require line of sight to the grid */
1303 if (!(g_ptr->info & (CAVE_VIEW))) return;
1305 /* Require "perma-lite" of the grid */
1306 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1309 if (!p_ptr->see_nocto) return;
1314 /* Hack -- memorize objects */
1315 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1317 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1318 next_o_idx = o_ptr->next_o_idx;
1320 /* Memorize objects */
1321 o_ptr->marked |= OM_FOUND;
1325 /* Hack -- memorize grids */
1326 if (!(g_ptr->info & (CAVE_MARK)))
1328 /* Feature code (applying "mimic" field) */
1329 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
1331 /* Memorize some "boring" grids */
1332 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1334 /* Option -- memorize all torch-lit floors */
1335 if (view_torch_grids &&
1336 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1338 g_ptr->info |= (CAVE_MARK);
1341 /* Option -- memorize all perma-lit floors */
1342 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1344 g_ptr->info |= (CAVE_MARK);
1348 /* Memorize normal grids */
1349 else if (have_flag(f_ptr->flags, FF_LOS))
1351 g_ptr->info |= (CAVE_MARK);
1354 /* Memorize torch-lit walls */
1355 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1357 g_ptr->info |= (CAVE_MARK);
1360 /* Memorize walls seen by noctovision of Ninja */
1361 else if (p_ptr->see_nocto)
1363 g_ptr->info |= (CAVE_MARK);
1366 /* Memorize certain non-torch-lit wall grids */
1367 else if (check_local_illumination(y, x))
1369 g_ptr->info |= (CAVE_MARK);
1373 /* Memorize terrain of the grid */
1374 g_ptr->info |= (CAVE_KNOWN);
1378 * Redraw (on the screen) a given MAP location
1380 * This function should only be called on "legal" grids
1382 void lite_spot(POSITION y, POSITION x)
1384 /* Redraw if on screen */
1385 if (panel_contains(y, x) && in_bounds2(y, x))
1392 map_info(y, x, &a, &c, &ta, &tc);
1394 /* Hack -- fake monochrome */
1397 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1398 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1399 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1402 /* Hack -- Queue it */
1403 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
1405 /* Update sub-windows */
1406 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1411 * Some comments on the grid flags. -BEN-
1414 * One of the major bottlenecks in previous versions of Angband was in
1415 * the calculation of "line of sight" from the player to various grids,
1416 * such as monsters. This was such a nasty bottleneck that a lot of
1417 * silly things were done to reduce the dependancy on "line of sight",
1418 * for example, you could not "see" any grids in a lit room until you
1419 * actually entered the room, and there were all kinds of bizarre grid
1420 * flags to enable this behavior. This is also why the "call light"
1421 * spells always lit an entire room.
1423 * The code below provides functions to calculate the "field of view"
1424 * for the player, which, once calculated, provides extremely fast
1425 * calculation of "line of sight from the player", and to calculate
1426 * the "field of torch lite", which, again, once calculated, provides
1427 * extremely fast calculation of "which grids are lit by the player's
1428 * lite source". In addition to marking grids as "GRID_VIEW" and/or
1429 * "GRID_LITE", as appropriate, these functions maintain an array for
1430 * each of these two flags, each array containing the locations of all
1431 * of the grids marked with the appropriate flag, which can be used to
1432 * very quickly scan through all of the grids in a given set.
1434 * To allow more "semantically valid" field of view semantics, whenever
1435 * the field of view (or the set of torch lit grids) changes, all of the
1436 * grids in the field of view (or the set of torch lit grids) are "drawn"
1437 * so that changes in the world will become apparent as soon as possible.
1438 * This has been optimized so that only grids which actually "change" are
1439 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
1440 * of the grids which are entering or leaving the relevent set of grids.
1442 * These new methods are so efficient that the old nasty code was removed.
1444 * Note that there is no reason to "update" the "viewable space" unless
1445 * the player "moves", or walls/doors are created/destroyed, and there
1446 * is no reason to "update" the "torch lit grids" unless the field of
1447 * view changes, or the "light radius" changes. This means that when
1448 * the player is resting, or digging, or doing anything that does not
1449 * involve movement or changing the state of the dungeon, there is no
1450 * need to update the "view" or the "lite" regions, which is nice.
1452 * Note that the calls to the nasty "los()" function have been reduced
1453 * to a bare minimum by the use of the new "field of view" calculations.
1455 * I wouldn't be surprised if slight modifications to the "update_view()"
1456 * function would allow us to determine "reverse line-of-sight" as well
1457 * as "normal line-of-sight", which would allow monsters to use a more
1458 * "correct" calculation to determine if they can "see" the player. For
1459 * now, monsters simply "cheat" somewhat and assume that if the player
1460 * has "line of sight" to the monster, then the monster can "pretend"
1461 * that it has "line of sight" to the player.
1464 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
1465 * grid and maintains an array of all "CAVE_LITE" grids.
1467 * This set of grids is the complete set of all grids which are lit by
1468 * the players light source, which allows the "player_can_see_bold()"
1469 * function to work very quickly.
1471 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
1472 * fact, the player (unless blind) can always "see" all grids which are
1473 * marked as "CAVE_LITE", unless they are "off screen".
1476 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
1477 * grid and maintains an array of all "CAVE_VIEW" grids.
1479 * This set of grids is the complete set of all grids within line of sight
1480 * of the player, allowing the "player_has_los_bold()" macro to work very
1484 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
1485 * temporary internal flag to mark those grids which are not only in view,
1486 * but which are also "easily" in line of sight of the player. This flag
1487 * is always cleared when we are done.
1490 * The current "update_lite()" and "update_view()" algorithms use the
1491 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
1492 * to keep track of which grids were previously marked as "CAVE_LITE" or
1493 * "CAVE_VIEW", which allows us to optimize the "screen updates".
1495 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
1496 * for various other purposes, such as spreading lite or darkness during
1497 * "lite_room()" / "unlite_room()", and for calculating monster flow.
1500 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
1501 * in some way permanently lit. However, for the player to "see" anything
1502 * in the grid, as determined by "player_can_see()", the player must not be
1503 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
1504 * grids, even if marked as "perma lit", are only illuminated if they touch
1505 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
1508 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
1509 * that even if the player cannot "see" the grid, he "knows" the terrain in
1510 * that grid. This is used to "remember" walls/doors/stairs/floors when they
1511 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
1512 * or when one of the "memorize floor grids" options induces memorization.
1514 * Objects are "memorized" in a different way, using a special "marked" flag
1515 * on the object itself, which is set when an object is observed or detected.
1518 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
1519 * and should be illuminated by "lite room" and "darkness" spells.
1522 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
1523 * and should be unavailable for "teleportation" destinations.
1526 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
1527 * which is observed, and the "view_torch_grids" allows the player to memorize
1528 * every torch-lit grid. The player will always memorize important walls,
1529 * doors, stairs, and other terrain features, as well as any "detected" grids.
1531 * Note that the new "update_view()" method allows, among other things, a room
1532 * to be "partially" seen as the player approaches it, with a growing cone of
1533 * floor appearing as the player gets closer to the door. Also, by not turning
1534 * on the "memorize perma-lit grids" option, the player will only "see" those
1535 * floor grids which are actually in line of sight.
1537 * And my favorite "plus" is that you can now use a special option to draw the
1538 * "floors" in the "viewable region" brightly (actually, to draw the *other*
1539 * grids dimly), providing a "pretty" effect as the player runs around, and
1540 * to efficiently display the "torch lite" in a special color.
1543 * Some comments on the "update_view()" algorithm...
1545 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
1546 * and only has to call "los()" on the borderline cases. The major axes/diags
1547 * even terminate early when they hit walls. I need to find a quick way
1548 * to "terminate" the other scans.
1550 * Note that in the worst case (a big empty area with say 5% scattered walls),
1551 * each of the 1500 or so nearby grids is checked once, most of them getting
1552 * an "instant" rating, and only a small portion requiring a call to "los()".
1554 * The only time that the algorithm appears to be "noticeably" too slow is
1555 * when running, and this is usually only important in town, since the town
1556 * provides about the worst scenario possible, with large open regions and
1557 * a few scattered obstructions. There is a special "efficiency" option to
1558 * allow the player to reduce his field of view in town, if needed.
1560 * In the "best" case (say, a normal stretch of corridor), the algorithm
1561 * makes one check for each viewable grid, and makes no calls to "los()".
1562 * So running in corridors is very fast, and if a lot of monsters are
1563 * nearby, it is much faster than the old methods.
1565 * Note that resting, most normal commands, and several forms of running,
1566 * plus all commands executed near large groups of monsters, are strictly
1567 * more efficient with "update_view()" that with the old "compute los() on
1568 * demand" method, primarily because once the "field of view" has been
1569 * calculated, it does not have to be recalculated until the player moves
1570 * (or a wall or door is created or destroyed).
1572 * Note that we no longer have to do as many "los()" checks, since once the
1573 * "view" region has been built, very few things cause it to be "changed"
1574 * (player movement, and the opening/closing of doors, changes in wall status).
1575 * Note that door/wall changes are only relevant when the door/wall itself is
1576 * in the "view" region.
1578 * The algorithm seems to only call "los()" from zero to ten times, usually
1579 * only when coming down a corridor into a room, or standing in a room, just
1580 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
1581 * we will be reducing the calls to "los()".
1583 * I am thinking in terms of an algorithm that "walks" from the central point
1584 * out to the maximal "distance", at each point, determining the "view" code
1585 * (above). For each grid not on a major axis or diagonal, the "view" code
1586 * depends on the "cave_los_bold()" and "view" of exactly two other grids
1587 * (the one along the nearest diagonal, and the one next to that one, see
1588 * "update_view_aux()"...).
1590 * We "memorize" the viewable space array, so that at the cost of under 3000
1591 * bytes, we reduce the time taken by "forget_view()" to one assignment for
1592 * each grid actually in the "viewable space". And for another 3000 bytes,
1593 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
1594 * are also used by other routines, thus reducing the cost to almost nothing.
1596 * A similar thing is done for "forget_lite()" in which case the savings are
1597 * much less, but save us from doing bizarre maintenance checking.
1599 * In the worst "normal" case (in the middle of the town), the reachable space
1600 * actually reaches to more than half of the largest possible "circle" of view,
1601 * or about 800 grids, and in the worse case (in the middle of a dungeon level
1602 * where all the walls have been removed), the reachable space actually reaches
1603 * the theoretical maximum size of just under 1500 grids.
1605 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
1606 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
1607 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
1608 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
1609 * entire possible space (including initialization) in one step per grid. If
1610 * we do the "clearing" as a separate step (and use an array of "view" grids),
1611 * then the clearing will take as many steps as grids that were viewed, and the
1612 * algorithm will be able to "stop" scanning at various points.
1613 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
1617 * Mega-Hack -- Delayed visual update
1618 * Only used if update_view(), update_lite() or update_mon_lite() was called
1620 void delayed_visual_update(void)
1626 /* Update needed grids */
1627 for (i = 0; i < current_floor_ptr->redraw_n; i++)
1629 y = current_floor_ptr->redraw_y[i];
1630 x = current_floor_ptr->redraw_x[i];
1631 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1633 /* Update only needed grids (prevent multiple updating) */
1634 if (!(g_ptr->info & CAVE_REDRAW)) continue;
1636 /* If required, note */
1637 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
1641 /* Hack -- Visual update of monster on this grid */
1642 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1644 /* No longer in the array */
1645 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
1649 current_floor_ptr->redraw_n = 0;
1654 * Hack -- forget the "flow" information
1656 void forget_flow(void)
1660 /* Check the entire dungeon */
1661 for (y = 0; y < current_floor_ptr->height; y++)
1663 for (x = 0; x < current_floor_ptr->width; x++)
1665 /* Forget the old data */
1666 current_floor_ptr->grid_array[y][x].dist = 0;
1667 current_floor_ptr->grid_array[y][x].cost = 0;
1668 current_floor_ptr->grid_array[y][x].when = 0;
1675 * Hack - speed up the update_flow algorithm by only doing
1676 * it everytime the player moves out of LOS of the last
1679 static POSITION flow_x = 0;
1680 static POSITION flow_y = 0;
1685 * Hack -- fill in the "cost" field of every grid that the player
1686 * can "reach" with the number of steps needed to reach that grid.
1687 * This also yields the "distance" of the player from every grid.
1689 * In addition, mark the "when" of the grids that can reach
1690 * the player with the incremented value of "flow_n".
1692 * Hack -- use the "seen" array as a "circular queue".
1694 * We do not need a priority queue because the cost from grid
1695 * to grid is always "one" and we process them in order.
1697 void update_flow(void)
1704 /* Paranoia -- make sure the array is empty */
1705 if (tmp_pos.n) return;
1707 /* The last way-point is on the map */
1708 if (p_ptr->running && in_bounds(flow_y, flow_x))
1710 /* The way point is in sight - do not update. (Speedup) */
1711 if (current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
1714 /* Erase all of the current flow information */
1715 for (y = 0; y < current_floor_ptr->height; y++)
1717 for (x = 0; x < current_floor_ptr->width; x++)
1719 current_floor_ptr->grid_array[y][x].cost = 0;
1720 current_floor_ptr->grid_array[y][x].dist = 0;
1724 /* Save player position */
1728 /* Add the player's grid to the queue */
1729 tmp_pos.y[0] = p_ptr->y;
1730 tmp_pos.x[0] = p_ptr->x;
1732 /* Now process the queue */
1733 while (flow_head != flow_tail)
1737 /* Extract the next entry */
1738 ty = tmp_pos.y[flow_tail];
1739 tx = tmp_pos.x[flow_tail];
1741 /* Forget that entry */
1742 if (++flow_tail == TEMP_MAX) flow_tail = 0;
1744 /* Add the "children" */
1745 for (d = 0; d < 8; d++)
1747 int old_head = flow_head;
1748 byte_hack m = current_floor_ptr->grid_array[ty][tx].cost + 1;
1749 byte_hack n = current_floor_ptr->grid_array[ty][tx].dist + 1;
1752 /* Child location */
1753 y = ty + ddy_ddd[d];
1754 x = tx + ddx_ddd[d];
1756 /* Ignore player's grid */
1757 if (player_bold(y, x)) continue;
1759 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1761 if (is_closed_door(g_ptr->feat)) m += 3;
1763 /* Ignore "pre-stamped" entries */
1764 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
1766 /* Ignore "walls" and "rubble" */
1767 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1769 /* Save the flow cost */
1770 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
1771 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
1773 /* Hack -- limit flow depth */
1774 if (n == MONSTER_FLOW_DEPTH) continue;
1776 /* Enqueue that entry */
1777 tmp_pos.y[flow_head] = y;
1778 tmp_pos.x[flow_head] = x;
1780 /* Advance the queue */
1781 if (++flow_head == TEMP_MAX) flow_head = 0;
1783 /* Hack -- notice overflow by forgetting new entry */
1784 if (flow_head == flow_tail) flow_head = old_head;
1790 static int scent_when = 0;
1793 * Characters leave scent trails for perceptive monsters to track.
1795 * Smell is rather more limited than sound. Many creatures cannot use
1796 * it at all, it doesn't extend very far outwards from the character's
1797 * current position, and monsters can use it to home in the character,
1798 * but not to run away from him.
1800 * Smell is valued according to age. When a character takes his current_world_ptr->game_turn,
1801 * scent is aged by one, and new scent of the current age is laid down.
1802 * Speedy characters leave more scent, true, but it also ages faster,
1803 * which makes it harder to hunt them down.
1805 * Whenever the age count loops, most of the scent trail is erased and
1806 * the age of the remainder is recalculated.
1808 void update_smell(void)
1813 /* Create a table that controls the spread of scent */
1814 const int scent_adjust[5][5] =
1823 /* Loop the age and adjust scent values when necessary */
1824 if (++scent_when == 254)
1826 /* Scan the entire dungeon */
1827 for (y = 0; y < current_floor_ptr->height; y++)
1829 for (x = 0; x < current_floor_ptr->width; x++)
1831 int w = current_floor_ptr->grid_array[y][x].when;
1832 current_floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
1841 /* Lay down new scent */
1842 for (i = 0; i < 5; i++)
1844 for (j = 0; j < 5; j++)
1848 /* Translate table to map grids */
1849 y = i + p_ptr->y - 2;
1850 x = j + p_ptr->x - 2;
1853 if (!in_bounds(y, x)) continue;
1855 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1857 /* Walls, water, and lava cannot hold scent. */
1858 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1860 /* Grid must not be blocked by walls from the character */
1861 if (!player_has_los_bold(y, x)) continue;
1863 /* Note grids that are too far away */
1864 if (scent_adjust[i][j] == -1) continue;
1866 /* Mark the grid with new scent */
1867 g_ptr->when = scent_when + scent_adjust[i][j];
1875 * Change the "feat" flag for a grid, and notice/redraw the grid
1877 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
1879 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1880 feature_type *f_ptr = &f_info[feat];
1881 bool old_los, old_mirror;
1883 if (!current_world_ptr->character_dungeon)
1885 /* Clear mimic type */
1888 /* Change the feature */
1891 /* Hack -- glow the GLOW terrain */
1892 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1897 for (i = 0; i < 9; i++)
1899 yy = y + ddy_ddd[i];
1900 xx = x + ddx_ddd[i];
1901 if (!in_bounds2(yy, xx)) continue;
1902 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
1909 old_los = cave_have_flag_bold(y, x, FF_LOS);
1910 old_mirror = is_mirror_grid(g_ptr);
1912 /* Clear mimic type */
1915 /* Change the feature */
1918 /* Remove flag for mirror/glyph */
1919 g_ptr->info &= ~(CAVE_OBJECT);
1921 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1923 g_ptr->info &= ~(CAVE_GLOW);
1924 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1926 update_local_illumination(y, x);
1929 /* Check for change to boring grid */
1930 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1931 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1936 /* Check if los has changed */
1937 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
1940 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1942 update_local_illumination(y, x);
1944 #endif /* COMPLEX_WALL_ILLUMINATION */
1946 /* Update the visuals */
1947 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
1950 /* Hack -- glow the GLOW terrain */
1951 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1957 for (i = 0; i < 9; i++)
1959 yy = y + ddy_ddd[i];
1960 xx = x + ddx_ddd[i];
1961 if (!in_bounds2(yy, xx)) continue;
1962 cc_ptr = ¤t_floor_ptr->grid_array[yy][xx];
1963 cc_ptr->info |= CAVE_GLOW;
1965 if (player_has_los_grid(cc_ptr))
1967 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
1974 update_local_illumination(yy, xx);
1977 if (p_ptr->special_defense & NINJA_S_STEALTH)
1979 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
1984 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
1986 feature_type *f_ptr = &f_info[newfeat];
1988 if (have_flag(f_ptr->flags, FF_CONVERT))
1990 switch (f_ptr->subtype)
1992 case CONVERT_TYPE_FLOOR:
1993 return feat_ground_type[randint0(100)];
1994 case CONVERT_TYPE_WALL:
1995 return feat_wall_type[randint0(100)];
1996 case CONVERT_TYPE_INNER:
1997 return feat_wall_inner;
1998 case CONVERT_TYPE_OUTER:
1999 return feat_wall_outer;
2000 case CONVERT_TYPE_SOLID:
2001 return feat_wall_solid;
2002 case CONVERT_TYPE_STREAM1:
2003 return d_info[p_ptr->dungeon_idx].stream1;
2004 case CONVERT_TYPE_STREAM2:
2005 return d_info[p_ptr->dungeon_idx].stream2;
2010 else return newfeat;
2015 * Take a feature, determine what that feature becomes
2016 * through applying the given action.
2018 FEAT_IDX feat_state(FEAT_IDX feat, int action)
2020 feature_type *f_ptr = &f_info[feat];
2023 /* Get the new feature */
2024 for (i = 0; i < MAX_FEAT_STATES; i++)
2026 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
2029 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
2031 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
2035 * Takes a location and action and changes the feature at that
2036 * location through applying the given action.
2038 void cave_alter_feat(POSITION y, POSITION x, int action)
2040 /* Set old feature */
2041 FEAT_IDX oldfeat = current_floor_ptr->grid_array[y][x].feat;
2043 /* Get the new feat */
2044 FEAT_IDX newfeat = feat_state(oldfeat, action);
2047 if (newfeat == oldfeat) return;
2049 /* Set the new feature */
2050 cave_set_feat(y, x, newfeat);
2052 if (!(feature_action_flags[action] & FAF_NO_DROP))
2054 feature_type *old_f_ptr = &f_info[oldfeat];
2055 feature_type *f_ptr = &f_info[newfeat];
2059 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
2061 /* Place some gold */
2067 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - current_floor_ptr->dun_level / 2)))
2070 place_object(y, x, 0L);
2074 if (found && current_world_ptr->character_dungeon && player_can_see_bold(y, x))
2076 msg_print(_("何かを発見した!", "You have found something!"));
2080 if (feature_action_flags[action] & FAF_CRASH_GLASS)
2082 feature_type *old_f_ptr = &f_info[oldfeat];
2084 if (have_flag(old_f_ptr->flags, FF_GLASS) && current_world_ptr->character_dungeon)
2086 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
2087 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
2093 /* Remove a mirror */
2094 void remove_mirror(POSITION y, POSITION x)
2096 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2098 /* Remove the mirror */
2099 g_ptr->info &= ~(CAVE_OBJECT);
2102 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
2104 g_ptr->info &= ~(CAVE_GLOW);
2105 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
2106 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
2108 update_local_illumination(y, x);
2118 * Return TRUE if there is a mirror on the grid.
2120 bool is_mirror_grid(grid_type *g_ptr)
2122 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
2130 * Return TRUE if there is a mirror on the grid.
2132 bool is_glyph_grid(grid_type *g_ptr)
2134 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
2142 * Return TRUE if there is a mirror on the grid.
2144 bool is_explosive_rune_grid(grid_type *g_ptr)
2146 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
2153 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
2154 * @param m_idx モンスターID
2158 * @return テレポート先として妥当ならばtrue
2160 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
2162 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
2163 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2164 feature_type *f_ptr = &f_info[g_ptr->feat];
2166 /* Require "teleportable" space */
2167 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
2169 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
2170 if (player_bold(y, x)) return FALSE;
2172 /* Hack -- no teleport onto glyph of warding */
2173 if (is_glyph_grid(g_ptr)) return FALSE;
2174 if (is_explosive_rune_grid(g_ptr)) return FALSE;
2176 if (!(mode & TELEPORT_PASSIVE))
2178 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
2185 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
2189 * @return テレポート先として妥当ならばtrue
2191 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
2193 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2194 feature_type *f_ptr = &f_info[g_ptr->feat];
2196 /* Require "teleportable" space */
2197 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
2199 /* No magical teleporting into vaults and such */
2200 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
2202 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
2204 /* don't teleport on a trap. */
2205 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
2207 if (!(mode & TELEPORT_PASSIVE))
2209 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
2211 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
2213 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
2216 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
2218 /* Always forbid deep lava */
2219 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
2221 /* Forbid shallow lava when the player don't have levitation */
2222 if (!p_ptr->levitation) return FALSE;
2231 * @brief 地形は開くものであって、かつ開かれているかを返す /
2232 * Attempt to open the given chest at the given location
2234 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
2236 bool is_open(FEAT_IDX feat)
2238 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
2242 * @brief プレイヤーが地形踏破可能かを返す
2243 * @param feature 判定したい地形ID
2244 * @param mode 移動に関するオプションフラグ
2245 * @return 移動可能ならばTRUEを返す
2247 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
2249 feature_type *f_ptr = &f_info[feature];
2251 if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[current_floor_ptr->m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
2253 if (have_flag(f_ptr->flags, FF_PATTERN))
2255 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
2258 if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
2259 if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
2260 if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
2262 if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;