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
23 #include "object-flavor.h"
24 #include "object-hook.h"
32 #include "monster-status.h"
33 #include "player-status.h"
35 #include "view-mainwindow.h"
38 * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
39 * @return 配置に成功したらTRUEを返す
41 bool new_player_spot(void)
43 POSITION y = 0, x = 0;
44 int max_attempts = 10000;
49 /* Place the player */
50 while (max_attempts--)
52 /* Pick a legal spot */
53 y = (POSITION)rand_range(1, current_floor_ptr->height - 2);
54 x = (POSITION)rand_range(1, current_floor_ptr->width - 2);
56 g_ptr = ¤t_floor_ptr->grid_array[y][x];
58 /* Must be a "naked" floor grid */
59 if (g_ptr->m_idx) continue;
60 if (current_floor_ptr->dun_level)
62 f_ptr = &f_info[g_ptr->feat];
64 if (max_attempts > 5000) /* Rule 1 */
66 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
70 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
71 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
74 /* Refuse to start on anti-teleport grids in dungeon */
75 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
77 if (!player_can_enter(g_ptr->feat, 0)) continue;
78 if (!in_bounds(y, x)) continue;
80 /* Refuse to start on anti-teleport grids */
81 if (g_ptr->info & (CAVE_ICKY)) continue;
86 if (max_attempts < 1) /* Should be -1, actually if we failed... */
89 /* Save the new player grid */
99 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
100 * @param y 配置を試みたいマスのY座標
101 * @param x 配置を試みたいマスのX座標
104 void place_random_stairs(POSITION y, POSITION x)
106 bool up_stairs = TRUE;
107 bool down_stairs = TRUE;
109 g_ptr = ¤t_floor_ptr->grid_array[y][x];
110 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
113 if (!current_floor_ptr->dun_level) up_stairs = FALSE;
116 if (ironman_downward) up_stairs = FALSE;
119 if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
122 if (quest_number(current_floor_ptr->dun_level) && (current_floor_ptr->dun_level > 1)) down_stairs = FALSE;
124 /* We can't place both */
125 if (down_stairs && up_stairs)
127 /* Choose a staircase randomly */
128 if (randint0(100) < 50) up_stairs = FALSE;
129 else down_stairs = FALSE;
132 /* Place the stairs */
133 if (up_stairs) place_up_stairs(y, x);
134 else if (down_stairs) place_down_stairs(y, x);
138 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
139 * @param y ドアの配置を試みたいマスのY座標
140 * @param x ドアの配置を試みたいマスのX座標
141 * @param room 部屋に接している場合向けのドア生成か否か
144 void place_random_door(POSITION y, POSITION x, bool room)
147 FEAT_IDX feat = feat_none;
148 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
150 /* Initialize mimic info */
153 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
155 place_floor_bold(y, x);
159 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
160 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
161 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
163 /* Choose an object */
164 tmp = randint0(1000);
166 /* Open doors (300/1000) */
169 /* Create open door */
170 feat = feat_door[type].open;
173 /* Broken doors (100/1000) */
176 /* Create broken door */
177 feat = feat_door[type].broken;
180 /* Secret doors (200/1000) */
183 /* Create secret door */
184 place_closed_door(y, x, type);
186 if (type != DOOR_CURTAIN)
188 /* Hide. If on the edge of room, use outer wall. */
189 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
191 /* Floor type terrain cannot hide a door */
192 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
194 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
196 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
203 /* Closed, locked, or stuck doors (400/1000) */
204 else place_closed_door(y, x, type);
208 if (feat != feat_none)
210 set_cave_feat(y, x, feat);
214 place_floor_bold(y, x);
218 delete_monster(y, x);
222 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
223 * @param y ドアの配置を試みたいマスのY座標
224 * @param x ドアの配置を試みたいマスのX座標
225 * @param type ドアの地形ID
228 void place_closed_door(POSITION y, POSITION x, int type)
231 FEAT_IDX feat = feat_none;
233 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
235 place_floor_bold(y, x);
239 /* Choose an object */
242 /* Closed doors (300/400) */
245 /* Create closed door */
246 feat = feat_door[type].closed;
249 /* Locked doors (99/400) */
252 /* Create locked door */
253 feat = feat_locked_door_random(type);
256 /* Stuck doors (1/400) */
259 /* Create jammed door */
260 feat = feat_jammed_door_random(type);
263 if (feat != feat_none)
265 cave_set_feat(y, x, feat);
267 /* Now it is not floor */
268 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
272 place_floor_bold(y, x);
277 * @brief 鍵のかかったドアを配置する
278 * @param y 配置したいフロアのY座標
279 * @param x 配置したいフロアのX座標
282 void place_locked_door(POSITION y, POSITION x)
284 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
286 place_floor_bold(y, x);
290 set_cave_feat(y, x, feat_locked_door_random((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
291 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
292 delete_monster(y, x);
299 * @param y 配置したいフロアのY座標
300 * @param x 配置したいフロアのX座標
301 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
304 void place_secret_door(POSITION y, POSITION x, int type)
306 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
308 place_floor_bold(y, x);
312 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
314 if (type == DOOR_DEFAULT)
316 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
317 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
318 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
321 /* Create secret door */
322 place_closed_door(y, x, type);
324 if (type != DOOR_CURTAIN)
326 /* Hide by inner wall because this is used in rooms only */
327 g_ptr->mimic = feat_wall_inner;
329 /* Floor type terrain cannot hide a door */
330 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
332 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
334 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
340 g_ptr->info &= ~(CAVE_FLOOR);
341 delete_monster(y, x);
346 * Routine used by the random vault creators to add a door to a location
347 * Note that range checking has to be done in the calling routine.
349 * The doors must be INSIDE the allocated region.
351 void add_door(POSITION x, POSITION y)
353 /* Need to have a wall in the center square */
354 if (!is_outer_bold(y, x)) return;
365 if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
366 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
369 place_secret_door(y, x, DOOR_DEFAULT);
371 /* set boundarys so don't get wide doors */
372 place_solid_bold(y, x - 1);
373 place_solid_bold(y, x + 1);
382 * where x = don't care
385 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
386 is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
389 place_secret_door(y, x, DOOR_DEFAULT);
391 /* set boundarys so don't get wide doors */
392 place_solid_bold(y - 1, x);
393 place_solid_bold(y + 1, x);
398 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
399 * @param y1 基準となるマスのY座標
400 * @param x1 基準となるマスのX座標
402 * @note Assumes "in_bounds(y1, x1)"
404 * XXX XXX This routine currently only counts actual "empty floor"\n
405 * grids which are not in rooms. We might want to also count stairs,\n
406 * open doors, closed doors, etc.
408 static int next_to_corr(POSITION y1, POSITION x1)
415 /* Scan adjacent grids */
416 for (i = 0; i < 4; i++)
418 /* Extract the location */
421 g_ptr = ¤t_floor_ptr->grid_array[y][x];
423 /* Skip non floors */
424 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
426 /* Skip non "empty floor" grids */
427 if (!is_floor_grid(g_ptr))
430 /* Skip grids inside rooms */
431 if (g_ptr->info & (CAVE_ROOM)) continue;
433 /* Count these grids */
437 /* Return the number of corridors */
442 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
443 * @param y 判定を行いたいマスのY座標
444 * @param x 判定を行いたいマスのX座標
445 * @return ドアを設置可能ならばTRUEを返す
446 * @note Assumes "in_bounds(y1, x1)"
449 * Assumes "in_bounds(y, x)"\n
451 static bool possible_doorway(POSITION y, POSITION x)
453 /* Count the adjacent corridors */
454 if (next_to_corr(y, x) >= 2)
457 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
458 cave_have_flag_bold(y + 1, x, FF_WALL))
463 /* Check Horizontal */
464 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
465 cave_have_flag_bold(y, x + 1, FF_WALL))
476 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
477 * @param y 設置を行いたいマスのY座標
478 * @param x 設置を行いたいマスのX座標
481 void try_door(POSITION y, POSITION x)
482 { if (!in_bounds(y, x)) return;
485 if (cave_have_flag_bold(y, x, FF_WALL)) return;
487 /* Ignore room grids */
488 if (current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
490 /* Occasional door (if allowed) */
491 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
494 place_random_door(y, x, FALSE);
500 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
501 * @param x1 長方形の左端X座標(-1)
502 * @param x2 長方形の右端X座標(+1)
503 * @param y1 長方形の上端Y座標(-1)
504 * @param y2 長方形の下端Y座標(+1)
508 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
512 /* Place a full floor under the room */
513 for (y = y1 - 1; y <= y2 + 1; y++)
515 for (x = x1 - 1; x <= x2 + 1; x++)
517 place_floor_bold(y, x);
518 add_cave_info(y, x, CAVE_ROOM);
519 if (light) add_cave_info(y, x, CAVE_GLOW);
526 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
527 * @param x1 長方形の左端X座標(-1)
528 * @param x2 長方形の右端X座標(+1)
529 * @param y1 長方形の上端Y座標(-1)
530 * @param y2 長方形の下端Y座標(+1)
534 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
538 place_floor(x1, x2, y1, y2, light);
540 /* Walls around the room */
541 for (y = y1 - 1; y <= y2 + 1; y++)
543 place_outer_bold(y, x1 - 1);
544 place_outer_bold(y, x2 + 1);
546 for (x = x1 - 1; x <= x2 + 1; x++)
548 place_outer_bold(y1 - 1, x);
549 place_outer_bold(y2 + 1, x);
555 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
556 * @param y 配置したい中心マスのY座標
557 * @param x 配置したい中心マスのX座標
561 * Only really called by some of the "vault" routines.
563 void vault_objects(POSITION y, POSITION x, int num)
566 int i = 0, j = y, k = x;
571 /* Attempt to place 'num' objects */
572 for (; num > 0; --num)
574 /* Try up to 11 spots looking for empty space */
575 for (i = 0; i < 11; ++i)
577 /* Pick a random location */
578 while (dummy < SAFE_MAX_ATTEMPTS)
580 j = rand_spread(y, 2);
581 k = rand_spread(x, 3);
583 if (!in_bounds(j, k)) continue;
587 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
589 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
592 /* Require "clean" floor space */
593 g_ptr = ¤t_floor_ptr->grid_array[j][k];
594 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
596 if (randint0(100) < 75)
598 place_object(j, k, 0L);
605 /* Placement accomplished */
612 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
613 * @param y トラップを配置したいマスの中心Y座標
614 * @param x トラップを配置したいマスの中心X座標
615 * @param yd Y方向の配置分散マス数
616 * @param xd X方向の配置分散マス数
619 * Only really called by some of the "vault" routines.
621 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
623 int count = 0, y1 = y, x1 = x;
629 for (count = 0; count <= 5; count++)
632 while (dummy < SAFE_MAX_ATTEMPTS)
634 y1 = rand_spread(y, yd);
635 x1 = rand_spread(x, xd);
637 if (!in_bounds(y1, x1)) continue;
641 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
643 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
646 /* Require "naked" floor grids */
647 g_ptr = ¤t_floor_ptr->grid_array[y1][x1];
648 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
658 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
659 * @param y トラップを配置したいマスの中心Y座標
660 * @param x トラップを配置したいマスの中心X座標
661 * @param yd Y方向の配置分散マス数
662 * @param xd X方向の配置分散マス数
663 * @param num 配置したいトラップの数
666 * Only really called by some of the "vault" routines.
668 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
672 for (i = 0; i < num; i++)
674 vault_trap_aux(y, x, yd, xd);
679 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
680 * @param y1 モンスターを配置したいマスの中心Y座標
681 * @param x1 モンスターを配置したいマスの中心X座標
682 * @param num 配置したいモンスターの数
685 * Only really called by some of the "vault" routines.
687 void vault_monsters(POSITION y1, POSITION x1, int num)
693 /* Try to summon "num" monsters "near" the given location */
694 for (k = 0; k < num; k++)
696 /* Try nine locations */
697 for (i = 0; i < 9; i++)
701 /* Pick a nearby location */
702 scatter(&y, &x, y1, x1, d, 0);
704 /* Require "empty" floor grids */
705 g_ptr = ¤t_floor_ptr->grid_array[y][x];
706 if (!cave_empty_grid(g_ptr)) continue;
708 /* Place the monster (allow groups) */
709 current_floor_ptr->monster_level = current_floor_ptr->base_level + 2;
710 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
711 current_floor_ptr->monster_level = current_floor_ptr->base_level;
717 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
718 * @param x チェックするマスのX座標
719 * @param y チェックするマスのY座標
720 * @return 床系地形ならばTRUE
722 bool get_is_floor(POSITION x, POSITION y)
724 if (!in_bounds(y, x))
730 /* Do the real check */
731 if (is_floor_bold(y, x)) return (TRUE);
737 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
738 * @param x 地形を変えたいマスのX座標
739 * @param y 地形を変えたいマスのY座標
742 void set_floor(POSITION x, POSITION y)
744 if (!in_bounds(y, x))
750 if (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
752 /* A room border don't touch. */
756 /* Set to be floor if is a wall (don't touch lakes). */
757 if (is_extra_bold(y, x))
758 place_floor_bold(y, x);
762 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
763 * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
766 void place_bound_perm_wall(grid_type *g_ptr)
768 if (bound_walls_perm)
770 /* Clear boundary mimic */
775 feature_type *f_ptr = &f_info[g_ptr->feat];
777 /* Hack -- Decline boundary walls with known treasure */
778 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
779 !have_flag(f_ptr->flags, FF_SECRET))
780 g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
782 /* Set boundary mimic */
783 g_ptr->mimic = g_ptr->feat;
786 /* Add "solid" perma-wall */
787 place_solid_perm_grid(g_ptr);
791 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
792 * @param g_ptr マス構造体の参照ポインタ
793 * @return 看破済みの罠があるならTRUEを返す。
795 bool is_known_trap(grid_type *g_ptr)
797 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
798 is_trap(g_ptr->feat)) return TRUE;
806 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
807 * @param g_ptr マス構造体の参照ポインタ
808 * @return 隠されたドアがあるならTRUEを返す。
810 bool is_hidden_door(grid_type *g_ptr)
812 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
813 is_closed_door(g_ptr->feat))
819 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
823 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
826 * @return 指定された座標に照明がかかっているならTRUEを返す。。
828 bool check_local_illumination(POSITION y, POSITION x)
830 /* Hack -- move towards player */
831 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
832 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
834 /* Check for "local" illumination */
836 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
838 /* Check for "complex" illumination */
839 if ((feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][xx])) &&
840 (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
841 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[y][xx])) &&
842 (current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
843 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][x])) &&
844 (current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
850 #else /* COMPLEX_WALL_ILLUMINATION */
852 /* Check for "simple" illumination */
853 return (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
855 #endif /* COMPLEX_WALL_ILLUMINATION */
859 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
860 #define update_local_illumination_aux(Y, X) \
862 if (player_has_los_bold((Y), (X))) \
864 /* Update the monster */ \
865 if (current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster(current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
867 /* Notice and redraw */ \
868 note_spot((Y), (X)); \
869 lite_spot((Y), (X)); \
874 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
879 void update_local_illumination(POSITION y, POSITION x)
884 if (!in_bounds(y, x)) return;
886 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
888 if ((y != p_ptr->y) && (x != p_ptr->x))
890 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
891 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
892 update_local_illumination_aux(yy, xx);
893 update_local_illumination_aux(y, xx);
894 update_local_illumination_aux(yy, x);
896 else if (x != p_ptr->x) /* y == p_ptr->y */
898 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
899 for (i = -1; i <= 1; i++)
902 update_local_illumination_aux(yy, xx);
905 update_local_illumination_aux(yy, x);
907 update_local_illumination_aux(yy, x);
909 else if (y != p_ptr->y) /* x == p_ptr->x */
911 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
912 for (i = -1; i <= 1; i++)
915 update_local_illumination_aux(yy, xx);
918 update_local_illumination_aux(y, xx);
920 update_local_illumination_aux(y, xx);
922 else /* Player's grid */
924 for (i = 0; i < 8; i++)
928 update_local_illumination_aux(yy, xx);
932 #else /* COMPLEX_WALL_ILLUMINATION */
934 if ((y != p_ptr->y) && (x != p_ptr->x))
936 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
937 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
938 update_local_illumination_aux(yy, xx);
940 else if (x != p_ptr->x) /* y == p_ptr->y */
942 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
943 for (i = -1; i <= 1; i++)
946 update_local_illumination_aux(yy, xx);
949 else if (y != p_ptr->y) /* x == p_ptr->x */
951 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
952 for (i = -1; i <= 1; i++)
955 update_local_illumination_aux(yy, xx);
958 else /* Player's grid */
960 for (i = 0; i < 8; i++)
964 update_local_illumination_aux(yy, xx);
968 #endif /* COMPLEX_WALL_ILLUMINATION */
973 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
976 * @return 視覚に収められる状態ならTRUEを返す
978 * He must have vision, illumination, and line of sight.\n
980 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
981 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
983 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
984 * that a wall is visible from any direction. That would be odd. Except\n
985 * under wizard light, which might make sense. Thus, for walls, we require\n
986 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
987 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
988 * in line of sight of the player.\n
990 * This extra check is expensive, but it provides a more "correct" semantics.\n
992 * Note that we should not run this check on walls which are "outer walls" of\n
993 * the dungeon, or we will induce a memory fault, but actually verifying all\n
994 * of the locations would be extremely expensive.\n
996 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
997 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
998 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
999 * and the player has more important things on his mind when he is attacking a\n
1000 * monster vault. It is annoying, but an extremely important optimization.\n
1002 * Note that "glowing walls" are only considered to be "illuminated" if the\n
1003 * grid which is next to the wall in the direction of the player is also a\n
1004 * "glowing" grid. This prevents the player from being able to "see" the\n
1005 * walls of illuminated rooms from a corridor outside the room.\n
1007 bool player_can_see_bold(POSITION y, POSITION x)
1011 /* Blind players see nothing */
1012 if (p_ptr->blind) return FALSE;
1014 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1016 /* Note that "torch-lite" yields "illumination" */
1017 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
1019 /* Require line of sight to the grid */
1020 if (!player_has_los_bold(y, x)) return FALSE;
1022 /* Noctovision of Ninja */
1023 if (p_ptr->see_nocto) return TRUE;
1025 /* Require "perma-lite" of the grid */
1026 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
1028 /* Feature code (applying "mimic" field) */
1029 /* Floors are simple */
1030 if (feat_supports_los(get_feat_mimic(g_ptr))) return TRUE;
1032 /* Check for "local" illumination */
1033 return check_local_illumination(y, x);
1037 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
1038 * @return 視覚に収められていないならTRUEを返す
1039 * @details player_can_see_bold()関数の返り値の否定を返している。
1043 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
1048 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
1051 * @return 各種の変更が可能ならTRUEを返す。
1053 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
1055 bool cave_valid_bold(POSITION y, POSITION x)
1057 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1058 OBJECT_IDX this_o_idx, next_o_idx = 0;
1060 /* Forbid perma-grids */
1061 if (cave_perma_grid(g_ptr)) return (FALSE);
1064 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1067 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1068 next_o_idx = o_ptr->next_o_idx;
1070 /* Forbid artifact grids */
1071 if (object_is_artifact(o_ptr)) return (FALSE);
1079 * Moves the cursor to a given MAP (y,x) location
1081 void move_cursor_relative(int row, int col)
1083 /* Real co-ords convert to screen positions */
1084 row -= panel_row_prt;
1087 Term_gotoxy(panel_col_of(col), row);
1093 * Place an attr/char pair at the given map coordinate, if legal.
1095 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
1097 /* Only do "legal" locations */
1098 if (panel_contains(y, x))
1100 /* Hack -- fake monochrome */
1103 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1104 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1105 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1108 /* Draw the char using the attr */
1109 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
1118 * Memorize interesting viewable object/features in the given grid
1120 * This function should only be called on "legal" grids.
1122 * This function will memorize the object and/or feature in the given
1123 * grid, if they are (1) viewable and (2) interesting. Note that all
1124 * objects are interesting, all terrain features except floors (and
1125 * invisible traps) are interesting, and floors (and invisible traps)
1126 * are interesting sometimes (depending on various options involving
1127 * the illumination of floor grids).
1129 * The automatic memorization of all objects and non-floor terrain
1130 * features as soon as they are displayed allows incredible amounts
1131 * of optimization in various places, especially "map_info()".
1133 * Note that the memorization of objects is completely separate from
1134 * the memorization of terrain features, preventing annoying floor
1135 * memorization when a detected object is picked up from a dark floor,
1136 * and object memorization when an object is dropped into a floor grid
1137 * which is memorized but out-of-sight.
1139 * This function should be called every time the "memorization" of
1140 * a grid (or the object in a grid) is called into question, such
1141 * as when an object is created in a grid, when a terrain feature
1142 * "changes" from "floor" to "non-floor", when any grid becomes
1143 * "illuminated" or "viewable", and when a "floor" grid becomes
1146 * Note the relatively efficient use of this function by the various
1147 * "update_view()" and "update_lite()" calls, to allow objects and
1148 * terrain features to be memorized (and drawn) whenever they become
1149 * viewable or illuminated in any way, but not when they "maintain"
1150 * or "lose" their previous viewability or illumination.
1152 * Note the butchered "internal" version of "player_can_see_bold()",
1153 * optimized primarily for the most common cases, that is, for the
1154 * non-marked floor grids.
1156 void note_spot(POSITION y, POSITION x)
1158 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1159 OBJECT_IDX this_o_idx, next_o_idx = 0;
1161 /* Blind players see nothing */
1162 if (p_ptr->blind) return;
1164 /* Analyze non-torch-lit grids */
1165 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1167 /* Require line of sight to the grid */
1168 if (!(g_ptr->info & (CAVE_VIEW))) return;
1170 /* Require "perma-lite" of the grid */
1171 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1174 if (!p_ptr->see_nocto) return;
1179 /* Hack -- memorize objects */
1180 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1182 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1183 next_o_idx = o_ptr->next_o_idx;
1185 /* Memorize objects */
1186 o_ptr->marked |= OM_FOUND;
1190 /* Hack -- memorize grids */
1191 if (!(g_ptr->info & (CAVE_MARK)))
1193 /* Feature code (applying "mimic" field) */
1194 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
1196 /* Memorize some "boring" grids */
1197 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1199 /* Option -- memorize all torch-lit floors */
1200 if (view_torch_grids &&
1201 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1203 g_ptr->info |= (CAVE_MARK);
1206 /* Option -- memorize all perma-lit floors */
1207 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1209 g_ptr->info |= (CAVE_MARK);
1213 /* Memorize normal grids */
1214 else if (have_flag(f_ptr->flags, FF_LOS))
1216 g_ptr->info |= (CAVE_MARK);
1219 /* Memorize torch-lit walls */
1220 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1222 g_ptr->info |= (CAVE_MARK);
1225 /* Memorize walls seen by noctovision of Ninja */
1226 else if (p_ptr->see_nocto)
1228 g_ptr->info |= (CAVE_MARK);
1231 /* Memorize certain non-torch-lit wall grids */
1232 else if (check_local_illumination(y, x))
1234 g_ptr->info |= (CAVE_MARK);
1238 /* Memorize terrain of the grid */
1239 g_ptr->info |= (CAVE_KNOWN);
1243 void display_dungeon(void)
1250 SYMBOL_CODE tc = '\0';
1252 for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
1254 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
1256 if (in_bounds2(y, x))
1258 map_info(y, x, &a, &c, &ta, &tc);
1260 /* Hack -- fake monochrome */
1263 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1264 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1265 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1268 /* Hack -- Queue it */
1269 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1273 /* Clear out-of-bound tiles */
1275 /* Access darkness */
1276 feature_type *f_ptr = &f_info[feat_none];
1279 a = f_ptr->x_attr[F_LIT_STANDARD];
1282 c = f_ptr->x_char[F_LIT_STANDARD];
1284 /* Hack -- Queue it */
1285 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1293 * Redraw (on the screen) a given MAP location
1295 * This function should only be called on "legal" grids
1297 void lite_spot(POSITION y, POSITION x)
1299 /* Redraw if on screen */
1300 if (panel_contains(y, x) && in_bounds2(y, x))
1307 map_info(y, x, &a, &c, &ta, &tc);
1309 /* Hack -- fake monochrome */
1312 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1313 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1314 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1317 /* Hack -- Queue it */
1318 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
1320 /* Update sub-windows */
1321 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1327 * print project path
1329 void prt_path(POSITION y, POSITION x)
1334 byte_hack default_color = TERM_SLATE;
1336 if (!display_path) return;
1337 if (-1 == project_length)
1340 /* Get projection path */
1341 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
1343 p_ptr->redraw |= (PR_MAP);
1347 for (i = 0; i < path_n; i++)
1349 POSITION ny = GRID_Y(path_g[i]);
1350 POSITION nx = GRID_X(path_g[i]);
1351 grid_type *g_ptr = ¤t_floor_ptr->grid_array[ny][nx];
1353 if (panel_contains(ny, nx))
1355 TERM_COLOR a = default_color;
1358 TERM_COLOR ta = default_color;
1361 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
1363 /* Determine what is there */
1364 map_info(ny, nx, &a, &c, &ta, &tc);
1366 if (!is_ascii_graphics(a))
1368 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1370 else if (a == default_color)
1376 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1377 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1378 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1383 /* Hack -- Queue it */
1384 Term_queue_bigchar(panel_col_of(nx), ny - panel_row_prt, a, c, ta, tc);
1388 if ((g_ptr->info & CAVE_MARK) && !cave_have_flag_grid(g_ptr, FF_PROJECT)) break;
1391 if (nx == x && ny == y) default_color = TERM_L_DARK;
1396 * Some comments on the grid flags. -BEN-
1399 * One of the major bottlenecks in previous versions of Angband was in
1400 * the calculation of "line of sight" from the player to various grids,
1401 * such as monsters. This was such a nasty bottleneck that a lot of
1402 * silly things were done to reduce the dependancy on "line of sight",
1403 * for example, you could not "see" any grids in a lit room until you
1404 * actually entered the room, and there were all kinds of bizarre grid
1405 * flags to enable this behavior. This is also why the "call light"
1406 * spells always lit an entire room.
1408 * The code below provides functions to calculate the "field of view"
1409 * for the player, which, once calculated, provides extremely fast
1410 * calculation of "line of sight from the player", and to calculate
1411 * the "field of torch lite", which, again, once calculated, provides
1412 * extremely fast calculation of "which grids are lit by the player's
1413 * lite source". In addition to marking grids as "GRID_VIEW" and/or
1414 * "GRID_LITE", as appropriate, these functions maintain an array for
1415 * each of these two flags, each array containing the locations of all
1416 * of the grids marked with the appropriate flag, which can be used to
1417 * very quickly scan through all of the grids in a given set.
1419 * To allow more "semantically valid" field of view semantics, whenever
1420 * the field of view (or the set of torch lit grids) changes, all of the
1421 * grids in the field of view (or the set of torch lit grids) are "drawn"
1422 * so that changes in the world will become apparent as soon as possible.
1423 * This has been optimized so that only grids which actually "change" are
1424 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
1425 * of the grids which are entering or leaving the relevent set of grids.
1427 * These new methods are so efficient that the old nasty code was removed.
1429 * Note that there is no reason to "update" the "viewable space" unless
1430 * the player "moves", or walls/doors are created/destroyed, and there
1431 * is no reason to "update" the "torch lit grids" unless the field of
1432 * view changes, or the "light radius" changes. This means that when
1433 * the player is resting, or digging, or doing anything that does not
1434 * involve movement or changing the state of the dungeon, there is no
1435 * need to update the "view" or the "lite" regions, which is nice.
1437 * Note that the calls to the nasty "los()" function have been reduced
1438 * to a bare minimum by the use of the new "field of view" calculations.
1440 * I wouldn't be surprised if slight modifications to the "update_view()"
1441 * function would allow us to determine "reverse line-of-sight" as well
1442 * as "normal line-of-sight", which would allow monsters to use a more
1443 * "correct" calculation to determine if they can "see" the player. For
1444 * now, monsters simply "cheat" somewhat and assume that if the player
1445 * has "line of sight" to the monster, then the monster can "pretend"
1446 * that it has "line of sight" to the player.
1449 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
1450 * grid and maintains an array of all "CAVE_LITE" grids.
1452 * This set of grids is the complete set of all grids which are lit by
1453 * the players light source, which allows the "player_can_see_bold()"
1454 * function to work very quickly.
1456 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
1457 * fact, the player (unless blind) can always "see" all grids which are
1458 * marked as "CAVE_LITE", unless they are "off screen".
1461 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
1462 * grid and maintains an array of all "CAVE_VIEW" grids.
1464 * This set of grids is the complete set of all grids within line of sight
1465 * of the player, allowing the "player_has_los_bold()" macro to work very
1469 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
1470 * temporary internal flag to mark those grids which are not only in view,
1471 * but which are also "easily" in line of sight of the player. This flag
1472 * is always cleared when we are done.
1475 * The current "update_lite()" and "update_view()" algorithms use the
1476 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
1477 * to keep track of which grids were previously marked as "CAVE_LITE" or
1478 * "CAVE_VIEW", which allows us to optimize the "screen updates".
1480 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
1481 * for various other purposes, such as spreading lite or darkness during
1482 * "lite_room()" / "unlite_room()", and for calculating monster flow.
1485 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
1486 * in some way permanently lit. However, for the player to "see" anything
1487 * in the grid, as determined by "player_can_see()", the player must not be
1488 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
1489 * grids, even if marked as "perma lit", are only illuminated if they touch
1490 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
1493 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
1494 * that even if the player cannot "see" the grid, he "knows" the terrain in
1495 * that grid. This is used to "remember" walls/doors/stairs/floors when they
1496 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
1497 * or when one of the "memorize floor grids" options induces memorization.
1499 * Objects are "memorized" in a different way, using a special "marked" flag
1500 * on the object itself, which is set when an object is observed or detected.
1503 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
1504 * and should be illuminated by "lite room" and "darkness" spells.
1507 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
1508 * and should be unavailable for "teleportation" destinations.
1511 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
1512 * which is observed, and the "view_torch_grids" allows the player to memorize
1513 * every torch-lit grid. The player will always memorize important walls,
1514 * doors, stairs, and other terrain features, as well as any "detected" grids.
1516 * Note that the new "update_view()" method allows, among other things, a room
1517 * to be "partially" seen as the player approaches it, with a growing cone of
1518 * floor appearing as the player gets closer to the door. Also, by not turning
1519 * on the "memorize perma-lit grids" option, the player will only "see" those
1520 * floor grids which are actually in line of sight.
1522 * And my favorite "plus" is that you can now use a special option to draw the
1523 * "floors" in the "viewable region" brightly (actually, to draw the *other*
1524 * grids dimly), providing a "pretty" effect as the player runs around, and
1525 * to efficiently display the "torch lite" in a special color.
1528 * Some comments on the "update_view()" algorithm...
1530 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
1531 * and only has to call "los()" on the borderline cases. The major axes/diags
1532 * even terminate early when they hit walls. I need to find a quick way
1533 * to "terminate" the other scans.
1535 * Note that in the worst case (a big empty area with say 5% scattered walls),
1536 * each of the 1500 or so nearby grids is checked once, most of them getting
1537 * an "instant" rating, and only a small portion requiring a call to "los()".
1539 * The only time that the algorithm appears to be "noticeably" too slow is
1540 * when running, and this is usually only important in town, since the town
1541 * provides about the worst scenario possible, with large open regions and
1542 * a few scattered obstructions. There is a special "efficiency" option to
1543 * allow the player to reduce his field of view in town, if needed.
1545 * In the "best" case (say, a normal stretch of corridor), the algorithm
1546 * makes one check for each viewable grid, and makes no calls to "los()".
1547 * So running in corridors is very fast, and if a lot of monsters are
1548 * nearby, it is much faster than the old methods.
1550 * Note that resting, most normal commands, and several forms of running,
1551 * plus all commands executed near large groups of monsters, are strictly
1552 * more efficient with "update_view()" that with the old "compute los() on
1553 * demand" method, primarily because once the "field of view" has been
1554 * calculated, it does not have to be recalculated until the player moves
1555 * (or a wall or door is created or destroyed).
1557 * Note that we no longer have to do as many "los()" checks, since once the
1558 * "view" region has been built, very few things cause it to be "changed"
1559 * (player movement, and the opening/closing of doors, changes in wall status).
1560 * Note that door/wall changes are only relevant when the door/wall itself is
1561 * in the "view" region.
1563 * The algorithm seems to only call "los()" from zero to ten times, usually
1564 * only when coming down a corridor into a room, or standing in a room, just
1565 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
1566 * we will be reducing the calls to "los()".
1568 * I am thinking in terms of an algorithm that "walks" from the central point
1569 * out to the maximal "distance", at each point, determining the "view" code
1570 * (above). For each grid not on a major axis or diagonal, the "view" code
1571 * depends on the "cave_los_bold()" and "view" of exactly two other grids
1572 * (the one along the nearest diagonal, and the one next to that one, see
1573 * "update_view_aux()"...).
1575 * We "memorize" the viewable space array, so that at the cost of under 3000
1576 * bytes, we reduce the time taken by "forget_view()" to one assignment for
1577 * each grid actually in the "viewable space". And for another 3000 bytes,
1578 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
1579 * are also used by other routines, thus reducing the cost to almost nothing.
1581 * A similar thing is done for "forget_lite()" in which case the savings are
1582 * much less, but save us from doing bizarre maintenance checking.
1584 * In the worst "normal" case (in the middle of the town), the reachable space
1585 * actually reaches to more than half of the largest possible "circle" of view,
1586 * or about 800 grids, and in the worse case (in the middle of a dungeon level
1587 * where all the walls have been removed), the reachable space actually reaches
1588 * the theoretical maximum size of just under 1500 grids.
1590 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
1591 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
1592 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
1593 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
1594 * entire possible space (including initialization) in one step per grid. If
1595 * we do the "clearing" as a separate step (and use an array of "view" grids),
1596 * then the clearing will take as many steps as grids that were viewed, and the
1597 * algorithm will be able to "stop" scanning at various points.
1598 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
1602 * Mega-Hack -- Delayed visual update
1603 * Only used if update_view(), update_lite() or update_mon_lite() was called
1605 void delayed_visual_update(void)
1611 /* Update needed grids */
1612 for (i = 0; i < current_floor_ptr->redraw_n; i++)
1614 y = current_floor_ptr->redraw_y[i];
1615 x = current_floor_ptr->redraw_x[i];
1616 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1618 /* Update only needed grids (prevent multiple updating) */
1619 if (!(g_ptr->info & CAVE_REDRAW)) continue;
1621 /* If required, note */
1622 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
1626 /* Hack -- Visual update of monster on this grid */
1627 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1629 /* No longer in the array */
1630 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
1634 current_floor_ptr->redraw_n = 0;
1639 * Hack -- forget the "flow" information
1641 void forget_flow(void)
1645 /* Check the entire dungeon */
1646 for (y = 0; y < current_floor_ptr->height; y++)
1648 for (x = 0; x < current_floor_ptr->width; x++)
1650 /* Forget the old data */
1651 current_floor_ptr->grid_array[y][x].dist = 0;
1652 current_floor_ptr->grid_array[y][x].cost = 0;
1653 current_floor_ptr->grid_array[y][x].when = 0;
1660 * Hack - speed up the update_flow algorithm by only doing
1661 * it everytime the player moves out of LOS of the last
1664 static POSITION flow_x = 0;
1665 static POSITION flow_y = 0;
1670 * Hack -- fill in the "cost" field of every grid that the player
1671 * can "reach" with the number of steps needed to reach that grid.
1672 * This also yields the "distance" of the player from every grid.
1674 * In addition, mark the "when" of the grids that can reach
1675 * the player with the incremented value of "flow_n".
1677 * Hack -- use the "seen" array as a "circular queue".
1679 * We do not need a priority queue because the cost from grid
1680 * to grid is always "one" and we process them in order.
1682 void update_flow(void)
1689 /* Paranoia -- make sure the array is empty */
1690 if (tmp_pos.n) return;
1692 /* The last way-point is on the map */
1693 if (running && in_bounds(flow_y, flow_x))
1695 /* The way point is in sight - do not update. (Speedup) */
1696 if (current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
1699 /* Erase all of the current flow information */
1700 for (y = 0; y < current_floor_ptr->height; y++)
1702 for (x = 0; x < current_floor_ptr->width; x++)
1704 current_floor_ptr->grid_array[y][x].cost = 0;
1705 current_floor_ptr->grid_array[y][x].dist = 0;
1709 /* Save player position */
1713 /* Add the player's grid to the queue */
1714 tmp_pos.y[0] = p_ptr->y;
1715 tmp_pos.x[0] = p_ptr->x;
1717 /* Now process the queue */
1718 while (flow_head != flow_tail)
1722 /* Extract the next entry */
1723 ty = tmp_pos.y[flow_tail];
1724 tx = tmp_pos.x[flow_tail];
1726 /* Forget that entry */
1727 if (++flow_tail == TEMP_MAX) flow_tail = 0;
1729 /* Add the "children" */
1730 for (d = 0; d < 8; d++)
1732 int old_head = flow_head;
1733 byte_hack m = current_floor_ptr->grid_array[ty][tx].cost + 1;
1734 byte_hack n = current_floor_ptr->grid_array[ty][tx].dist + 1;
1737 /* Child location */
1738 y = ty + ddy_ddd[d];
1739 x = tx + ddx_ddd[d];
1741 /* Ignore player's grid */
1742 if (player_bold(y, x)) continue;
1744 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1746 if (is_closed_door(g_ptr->feat)) m += 3;
1748 /* Ignore "pre-stamped" entries */
1749 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
1751 /* Ignore "walls" and "rubble" */
1752 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1754 /* Save the flow cost */
1755 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
1756 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
1758 /* Hack -- limit flow depth */
1759 if (n == MONSTER_FLOW_DEPTH) continue;
1761 /* Enqueue that entry */
1762 tmp_pos.y[flow_head] = y;
1763 tmp_pos.x[flow_head] = x;
1765 /* Advance the queue */
1766 if (++flow_head == TEMP_MAX) flow_head = 0;
1768 /* Hack -- notice overflow by forgetting new entry */
1769 if (flow_head == flow_tail) flow_head = old_head;
1775 static int scent_when = 0;
1778 * Characters leave scent trails for perceptive monsters to track.
1780 * Smell is rather more limited than sound. Many creatures cannot use
1781 * it at all, it doesn't extend very far outwards from the character's
1782 * current position, and monsters can use it to home in the character,
1783 * but not to run away from him.
1785 * Smell is valued according to age. When a character takes his current_world_ptr->game_turn,
1786 * scent is aged by one, and new scent of the current age is laid down.
1787 * Speedy characters leave more scent, true, but it also ages faster,
1788 * which makes it harder to hunt them down.
1790 * Whenever the age count loops, most of the scent trail is erased and
1791 * the age of the remainder is recalculated.
1793 void update_smell(void)
1798 /* Create a table that controls the spread of scent */
1799 const int scent_adjust[5][5] =
1808 /* Loop the age and adjust scent values when necessary */
1809 if (++scent_when == 254)
1811 /* Scan the entire dungeon */
1812 for (y = 0; y < current_floor_ptr->height; y++)
1814 for (x = 0; x < current_floor_ptr->width; x++)
1816 int w = current_floor_ptr->grid_array[y][x].when;
1817 current_floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
1826 /* Lay down new scent */
1827 for (i = 0; i < 5; i++)
1829 for (j = 0; j < 5; j++)
1833 /* Translate table to map grids */
1834 y = i + p_ptr->y - 2;
1835 x = j + p_ptr->x - 2;
1838 if (!in_bounds(y, x)) continue;
1840 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1842 /* Walls, water, and lava cannot hold scent. */
1843 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1845 /* Grid must not be blocked by walls from the character */
1846 if (!player_has_los_bold(y, x)) continue;
1848 /* Note grids that are too far away */
1849 if (scent_adjust[i][j] == -1) continue;
1851 /* Mark the grid with new scent */
1852 g_ptr->when = scent_when + scent_adjust[i][j];
1860 * Change the "feat" flag for a grid, and notice/redraw the grid
1862 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
1864 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1865 feature_type *f_ptr = &f_info[feat];
1866 bool old_los, old_mirror;
1868 if (!character_dungeon)
1870 /* Clear mimic type */
1873 /* Change the feature */
1876 /* Hack -- glow the GLOW terrain */
1877 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1882 for (i = 0; i < 9; i++)
1884 yy = y + ddy_ddd[i];
1885 xx = x + ddx_ddd[i];
1886 if (!in_bounds2(yy, xx)) continue;
1887 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
1894 old_los = cave_have_flag_bold(y, x, FF_LOS);
1895 old_mirror = is_mirror_grid(g_ptr);
1897 /* Clear mimic type */
1900 /* Change the feature */
1903 /* Remove flag for mirror/glyph */
1904 g_ptr->info &= ~(CAVE_OBJECT);
1906 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1908 g_ptr->info &= ~(CAVE_GLOW);
1909 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1911 update_local_illumination(y, x);
1914 /* Check for change to boring grid */
1915 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1916 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1921 /* Check if los has changed */
1922 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
1925 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1927 update_local_illumination(y, x);
1929 #endif /* COMPLEX_WALL_ILLUMINATION */
1931 /* Update the visuals */
1932 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
1935 /* Hack -- glow the GLOW terrain */
1936 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1942 for (i = 0; i < 9; i++)
1944 yy = y + ddy_ddd[i];
1945 xx = x + ddx_ddd[i];
1946 if (!in_bounds2(yy, xx)) continue;
1947 cc_ptr = ¤t_floor_ptr->grid_array[yy][xx];
1948 cc_ptr->info |= CAVE_GLOW;
1950 if (player_has_los_grid(cc_ptr))
1952 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
1959 update_local_illumination(yy, xx);
1962 if (p_ptr->special_defense & NINJA_S_STEALTH)
1964 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
1970 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
1972 feature_type *f_ptr = &f_info[newfeat];
1974 if (have_flag(f_ptr->flags, FF_CONVERT))
1976 switch (f_ptr->subtype)
1978 case CONVERT_TYPE_FLOOR:
1979 return feat_ground_type[randint0(100)];
1980 case CONVERT_TYPE_WALL:
1981 return feat_wall_type[randint0(100)];
1982 case CONVERT_TYPE_INNER:
1983 return feat_wall_inner;
1984 case CONVERT_TYPE_OUTER:
1985 return feat_wall_outer;
1986 case CONVERT_TYPE_SOLID:
1987 return feat_wall_solid;
1988 case CONVERT_TYPE_STREAM1:
1989 return d_info[p_ptr->dungeon_idx].stream1;
1990 case CONVERT_TYPE_STREAM2:
1991 return d_info[p_ptr->dungeon_idx].stream2;
1996 else return newfeat;
2001 * Take a feature, determine what that feature becomes
2002 * through applying the given action.
2004 FEAT_IDX feat_state(FEAT_IDX feat, int action)
2006 feature_type *f_ptr = &f_info[feat];
2009 /* Get the new feature */
2010 for (i = 0; i < MAX_FEAT_STATES; i++)
2012 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
2015 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
2017 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
2021 * Takes a location and action and changes the feature at that
2022 * location through applying the given action.
2024 void cave_alter_feat(POSITION y, POSITION x, int action)
2026 /* Set old feature */
2027 FEAT_IDX oldfeat = current_floor_ptr->grid_array[y][x].feat;
2029 /* Get the new feat */
2030 FEAT_IDX newfeat = feat_state(oldfeat, action);
2033 if (newfeat == oldfeat) return;
2035 /* Set the new feature */
2036 cave_set_feat(y, x, newfeat);
2038 if (!(feature_action_flags[action] & FAF_NO_DROP))
2040 feature_type *old_f_ptr = &f_info[oldfeat];
2041 feature_type *f_ptr = &f_info[newfeat];
2045 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
2047 /* Place some gold */
2053 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)))
2056 place_object(y, x, 0L);
2060 if (found && character_dungeon && player_can_see_bold(y, x))
2062 msg_print(_("何かを発見した!", "You have found something!"));
2066 if (feature_action_flags[action] & FAF_CRASH_GLASS)
2068 feature_type *old_f_ptr = &f_info[oldfeat];
2070 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
2072 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
2073 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
2079 /* Remove a mirror */
2080 void remove_mirror(POSITION y, POSITION x)
2082 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2084 /* Remove the mirror */
2085 g_ptr->info &= ~(CAVE_OBJECT);
2088 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
2090 g_ptr->info &= ~(CAVE_GLOW);
2091 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
2092 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
2094 update_local_illumination(y, x);
2104 * Return TRUE if there is a mirror on the grid.
2106 bool is_mirror_grid(grid_type *g_ptr)
2108 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
2116 * Return TRUE if there is a mirror on the grid.
2118 bool is_glyph_grid(grid_type *g_ptr)
2120 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
2128 * Return TRUE if there is a mirror on the grid.
2130 bool is_explosive_rune_grid(grid_type *g_ptr)
2132 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
2140 * Track a new monster
2142 void health_track(MONSTER_IDX m_idx)
2144 /* Mount monster is already tracked */
2145 if (m_idx && m_idx == p_ptr->riding) return;
2147 /* Track a new guy */
2148 p_ptr->health_who = m_idx;
2150 /* Redraw (later) */
2151 p_ptr->redraw |= (PR_HEALTH);
2157 * Hack -- track the given monster race
2159 void monster_race_track(MONRACE_IDX r_idx)
2161 /* Save this monster ID */
2162 p_ptr->monster_race_idx = r_idx;
2164 p_ptr->window |= (PW_MONSTER);
2170 * Hack -- track the given object kind
2172 void object_kind_track(KIND_OBJECT_IDX k_idx)
2174 /* Save this monster ID */
2175 p_ptr->object_kind_idx = k_idx;
2177 p_ptr->window |= (PW_OBJECT);
2182 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
2183 * @param m_idx モンスターID
2187 * @return テレポート先として妥当ならばtrue
2189 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
2191 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
2192 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2193 feature_type *f_ptr = &f_info[g_ptr->feat];
2195 /* Require "teleportable" space */
2196 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
2198 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
2199 if (player_bold(y, x)) return FALSE;
2201 /* Hack -- no teleport onto glyph of warding */
2202 if (is_glyph_grid(g_ptr)) return FALSE;
2203 if (is_explosive_rune_grid(g_ptr)) return FALSE;
2205 if (!(mode & TELEPORT_PASSIVE))
2207 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
2214 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
2218 * @return テレポート先として妥当ならばtrue
2220 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
2222 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2223 feature_type *f_ptr = &f_info[g_ptr->feat];
2225 /* Require "teleportable" space */
2226 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
2228 /* No magical teleporting into vaults and such */
2229 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
2231 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
2233 /* don't teleport on a trap. */
2234 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
2236 if (!(mode & TELEPORT_PASSIVE))
2238 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
2240 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
2242 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
2245 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
2247 /* Always forbid deep lava */
2248 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
2250 /* Forbid shallow lava when the player don't have levitation */
2251 if (!p_ptr->levitation) return FALSE;
2260 * @brief 地形は開くものであって、かつ開かれているかを返す /
2261 * Attempt to open the given chest at the given location
2263 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
2265 bool is_open(FEAT_IDX feat)
2267 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
2271 * @brief プレイヤーが地形踏破可能かを返す
2272 * @param feature 判定したい地形ID
2273 * @param mode 移動に関するオプションフラグ
2274 * @return 移動可能ならばTRUEを返す
2276 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
2278 feature_type *f_ptr = &f_info[feature];
2280 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);
2282 if (have_flag(f_ptr->flags, FF_PATTERN))
2284 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
2287 if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
2288 if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
2289 if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
2291 if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;