3 * @brief ダンジョンの基礎部分実装(主にマスの実装) / low level dungeon routines -BEN-
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
8 * This software may be copied and distributed for educational, research,\n
9 * and not for profit purposes provided that this copyright and statement\n
10 * are included in all such copies. Other copyrights may also apply.\n
12 * Support for Adam Bolt's tileset, lighting and transparency effects\n
13 * by Robert Ruehlmann (rr9@angband.org)\n
15 * 2013 Deskull Doxygen向けのコメント整理\n
21 #include "projection.h"
23 static byte display_autopick; /*!< 自動拾い状態の設定フラグ */
24 static int match_autopick;
25 static object_type *autopick_obj; /*!< 各種自動拾い処理時に使うオブジェクトポインタ */
26 static int feat_priority; /*!< マップ縮小表示時に表示すべき地形の優先度を保管する */
29 * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
36 POSITION distance (POSITION y1, POSITION x1, POSITION y2, POSITION x2)
38 POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
39 POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
41 /* Squared distance */
42 POSITION target = (dy * dy) + (dx * dx);
44 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
45 POSITION d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
50 if (!dy || !dx) return d;
54 /* Approximate error */
55 err = (target - d * d) / (2 * d);
57 /* No error - we are done */
68 * @brief 地形が罠持ちであるかの判定を行う。 / Return TRUE if the given feature is a trap
70 * @return 罠持ちの地形ならばTRUEを返す。
72 bool is_trap(FEAT_IDX feat)
74 return have_flag(f_info[feat].flags, FF_TRAP);
78 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
79 * @param c_ptr マス構造体の参照ポインタ
80 * @return 看破済みの罠があるならTRUEを返す。
82 bool is_known_trap(cave_type *c_ptr)
84 if (!c_ptr->mimic && !cave_have_flag_grid(c_ptr, FF_SECRET) &&
85 is_trap(c_ptr->feat)) return TRUE;
91 * @brief 地形が閉じたドアであるかの判定を行う。 / Return TRUE if the given grid is a closed door
93 * @return 閉じたドアのある地形ならばTRUEを返す。
95 bool is_closed_door(FEAT_IDX feat)
97 feature_type *f_ptr = &f_info[feat];
99 return (have_flag(f_ptr->flags, FF_OPEN) || have_flag(f_ptr->flags, FF_BASH)) &&
100 !have_flag(f_ptr->flags, FF_MOVE);
104 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
105 * @param c_ptr マス構造体の参照ポインタ
106 * @return 隠されたドアがあるならTRUEを返す。
108 bool is_hidden_door(cave_type *c_ptr)
110 if ((c_ptr->mimic || cave_have_flag_grid(c_ptr, FF_SECRET)) &&
111 is_closed_door(c_ptr->feat))
118 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
123 * @return LOSが通っているならTRUEを返す。
125 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
126 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
128 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
130 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
131 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
132 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
134 * We assume that the "mathematical corner" of a non-floor tile does not\n
135 * block line of sight.\n
137 * Because this function uses (short) ints for all calculations, overflow may\n
138 * occur if dx and dy exceed 90.\n
140 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
141 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
142 * we can use integer arithmetic.\n
144 * We travel from start to finish along the longer axis, starting at the border\n
145 * between the first and second tiles, where the y offset = .5 * slope, taking\n
146 * into account the scale factor. See below.\n
148 * Also note that this function and the "move towards target" code do NOT\n
149 * share the same properties. Thus, you can see someone, target them, and\n
150 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
151 * by clever choice of target locations, you can sometimes throw a "curve".\n
153 * Note that "line of sight" is not "reflexive" in all cases.\n
155 * Use the "projectable()" routine to test "spell/missile line of sight".\n
157 * Use the "update_view()" function to determine player line-of-sight.\n
159 bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
179 /* Slope, or 1/Slope, of LOS */
183 /* Extract the offset */
187 /* Extract the absolute offset */
192 /* Handle adjacent (or identical) grids */
193 if ((ax < 2) && (ay < 2)) return TRUE;
196 /* Paranoia -- require "safe" origin */
197 /* if (!in_bounds(y1, x1)) return FALSE; */
198 /* if (!in_bounds(y2, x2)) return FALSE; */
201 /* Directly South/North */
204 /* South -- check for walls */
207 for (ty = y1 + 1; ty < y2; ty++)
209 if (!cave_los_bold(ty, x1)) return FALSE;
213 /* North -- check for walls */
216 for (ty = y1 - 1; ty > y2; ty--)
218 if (!cave_los_bold(ty, x1)) return FALSE;
226 /* Directly East/West */
229 /* East -- check for walls */
232 for (tx = x1 + 1; tx < x2; tx++)
234 if (!cave_los_bold(y1, tx)) return FALSE;
238 /* West -- check for walls */
241 for (tx = x1 - 1; tx > x2; tx--)
243 if (!cave_los_bold(y1, tx)) return FALSE;
252 /* Extract some signs */
253 sx = (dx < 0) ? -1 : 1;
254 sy = (dy < 0) ? -1 : 1;
257 /* Vertical "knights" */
262 if (cave_los_bold(y1 + sy, x1)) return TRUE;
266 /* Horizontal "knights" */
271 if (cave_los_bold(y1, x1 + sx)) return TRUE;
276 /* Calculate scale factor div 2 */
279 /* Calculate scale factor */
283 /* Travel horizontally */
286 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
292 /* Consider the special case where slope == 1. */
303 /* Note (below) the case (qy == f2), where */
304 /* the LOS exactly meets the corner of a tile. */
307 if (!cave_los_bold(ty, tx)) return FALSE;
318 if (!cave_los_bold(ty, tx)) return FALSE;
331 /* Travel vertically */
334 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
350 /* Note (below) the case (qx == f2), where */
351 /* the LOS exactly meets the corner of a tile. */
354 if (!cave_los_bold(ty, tx)) return FALSE;
365 if (!cave_los_bold(ty, tx)) return FALSE;
382 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
386 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
389 * @return 指定された座標に照明がかかっているならTRUEを返す。。
391 static bool check_local_illumination(POSITION y, POSITION x)
393 /* Hack -- move towards player */
394 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
395 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
397 /* Check for "local" illumination */
399 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
401 /* Check for "complex" illumination */
402 if ((feat_supports_los(get_feat_mimic(&cave[yy][xx])) &&
403 (cave[yy][xx].info & CAVE_GLOW)) ||
404 (feat_supports_los(get_feat_mimic(&cave[y][xx])) &&
405 (cave[y][xx].info & CAVE_GLOW)) ||
406 (feat_supports_los(get_feat_mimic(&cave[yy][x])) &&
407 (cave[yy][x].info & CAVE_GLOW)))
413 #else /* COMPLEX_WALL_ILLUMINATION */
415 /* Check for "simple" illumination */
416 return (cave[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
418 #endif /* COMPLEX_WALL_ILLUMINATION */
422 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
423 #define update_local_illumination_aux(Y, X) \
425 if (player_has_los_bold((Y), (X))) \
427 /* Update the monster */ \
428 if (cave[(Y)][(X)].m_idx) update_monster(cave[(Y)][(X)].m_idx, FALSE); \
430 /* Notice and redraw */ \
431 note_spot((Y), (X)); \
432 lite_spot((Y), (X)); \
437 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
442 void update_local_illumination(POSITION y, POSITION x)
447 if (!in_bounds(y, x)) return;
449 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
451 if ((y != p_ptr->y) && (x != p_ptr->x))
453 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
454 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
455 update_local_illumination_aux(yy, xx);
456 update_local_illumination_aux(y, xx);
457 update_local_illumination_aux(yy, x);
459 else if (x != p_ptr->x) /* y == p_ptr->y */
461 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
462 for (i = -1; i <= 1; i++)
465 update_local_illumination_aux(yy, xx);
468 update_local_illumination_aux(yy, x);
470 update_local_illumination_aux(yy, x);
472 else if (y != p_ptr->y) /* x == p_ptr->x */
474 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
475 for (i = -1; i <= 1; i++)
478 update_local_illumination_aux(yy, xx);
481 update_local_illumination_aux(y, xx);
483 update_local_illumination_aux(y, xx);
485 else /* Player's grid */
487 for (i = 0; i < 8; i++)
491 update_local_illumination_aux(yy, xx);
495 #else /* COMPLEX_WALL_ILLUMINATION */
497 if ((y != p_ptr->y) && (x != p_ptr->x))
499 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
500 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
501 update_local_illumination_aux(yy, xx);
503 else if (x != p_ptr->x) /* y == p_ptr->y */
505 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
506 for (i = -1; i <= 1; i++)
509 update_local_illumination_aux(yy, xx);
512 else if (y != p_ptr->y) /* x == p_ptr->x */
514 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
515 for (i = -1; i <= 1; i++)
518 update_local_illumination_aux(yy, xx);
521 else /* Player's grid */
523 for (i = 0; i < 8; i++)
527 update_local_illumination_aux(yy, xx);
531 #endif /* COMPLEX_WALL_ILLUMINATION */
536 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
539 * @return 視覚に収められる状態ならTRUEを返す
541 * He must have vision, illumination, and line of sight.\n
543 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
544 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
546 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
547 * that a wall is visible from any direction. That would be odd. Except\n
548 * under wizard light, which might make sense. Thus, for walls, we require\n
549 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
550 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
551 * in line of sight of the player.\n
553 * This extra check is expensive, but it provides a more "correct" semantics.\n
555 * Note that we should not run this check on walls which are "outer walls" of\n
556 * the dungeon, or we will induce a memory fault, but actually verifying all\n
557 * of the locations would be extremely expensive.\n
559 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
560 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
561 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
562 * and the player has more important things on his mind when he is attacking a\n
563 * monster vault. It is annoying, but an extremely important optimization.\n
565 * Note that "glowing walls" are only considered to be "illuminated" if the\n
566 * grid which is next to the wall in the direction of the player is also a\n
567 * "glowing" grid. This prevents the player from being able to "see" the\n
568 * walls of illuminated rooms from a corridor outside the room.\n
570 bool player_can_see_bold(POSITION y, POSITION x)
574 /* Blind players see nothing */
575 if (p_ptr->blind) return FALSE;
579 /* Note that "torch-lite" yields "illumination" */
580 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
582 /* Require line of sight to the grid */
583 if (!player_has_los_bold(y, x)) return FALSE;
585 /* Noctovision of Ninja */
586 if (p_ptr->see_nocto) return TRUE;
588 /* Require "perma-lite" of the grid */
589 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
591 /* Feature code (applying "mimic" field) */
592 /* Floors are simple */
593 if (feat_supports_los(get_feat_mimic(c_ptr))) return TRUE;
595 /* Check for "local" illumination */
596 return check_local_illumination(y, x);
600 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
601 * @return 視覚に収められていないならTRUEを返す
602 * @details player_can_see_bold()関数の返り値の否定を返している。
606 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
611 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
614 * @return 各種の変更が可能ならTRUEを返す。
616 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
618 bool cave_valid_bold(POSITION y, POSITION x)
620 cave_type *c_ptr = &cave[y][x];
621 OBJECT_IDX this_o_idx, next_o_idx = 0;
623 /* Forbid perma-grids */
624 if (cave_perma_grid(c_ptr)) return (FALSE);
627 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
630 o_ptr = &o_list[this_o_idx];
632 /* Acquire next object */
633 next_o_idx = o_ptr->next_o_idx;
635 /* Forbid artifact grids */
636 if (object_is_artifact(o_ptr)) return (FALSE);
647 * 一般的にモンスターシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal monster codes
649 static char image_monster_hack[] = \
650 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
653 * 一般的にオブジェクトシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal object codes
655 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
658 * @brief モンスターの表示を幻覚状態に差し替える / Mega-Hack -- Hallucinatory monster
663 static void image_monster(TERM_COLOR *ap, SYMBOL_CODE *cp)
665 /* Random symbol from set above */
668 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
677 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
678 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
686 * @brief オブジェクトの表示を幻覚状態に差し替える / Hallucinatory object
691 static void image_object(TERM_COLOR *ap, SYMBOL_CODE *cp)
695 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
702 int n = sizeof(image_object_hack) - 1;
704 *cp = image_object_hack[randint0(n)];
713 * @brief オブジェクト&モンスターの表示を幻覚状態に差し替える / Hack -- Random hallucination
718 static void image_random(TERM_COLOR *ap, SYMBOL_CODE *cp)
720 /* Normally, assume monsters */
721 if (randint0(100) < 75)
723 image_monster(ap, cp);
726 /* Otherwise, assume objects */
729 image_object(ap, cp);
734 * 照明の表現を行うための色合いの関係を{暗闇時, 照明時} で定義する /
735 * This array lists the effects of "brightness" on various "base" colours.\n
737 * This is used to do dynamic lighting effects in ascii :-)\n
738 * At the moment, only the various "floor" tiles are affected.\n
740 * The layout of the array is [x][0] = light and [x][1] = dark.\n
742 static byte lighting_colours[16][2] =
745 {TERM_L_DARK, TERM_DARK},
748 {TERM_YELLOW, TERM_SLATE},
751 {TERM_WHITE, TERM_L_DARK},
754 {TERM_L_UMBER, TERM_UMBER},
757 {TERM_RED, TERM_RED},
760 {TERM_L_GREEN, TERM_GREEN},
763 {TERM_BLUE, TERM_BLUE},
766 {TERM_L_UMBER, TERM_RED},
769 {TERM_SLATE, TERM_L_DARK},
772 {TERM_WHITE, TERM_SLATE},
775 {TERM_L_RED, TERM_BLUE},
778 {TERM_YELLOW, TERM_ORANGE},
781 {TERM_L_RED, TERM_L_RED},
784 {TERM_L_GREEN, TERM_GREEN},
787 {TERM_L_BLUE, TERM_L_BLUE},
790 {TERM_L_UMBER, TERM_UMBER}
797 void apply_default_feat_lighting(TERM_COLOR f_attr[F_LIT_MAX], SYMBOL_CODE f_char[F_LIT_MAX])
799 TERM_COLOR s_attr = f_attr[F_LIT_STANDARD];
800 SYMBOL_CODE s_char = f_char[F_LIT_STANDARD];
803 if (is_ascii_graphics(s_attr)) /* For ASCII */
805 f_attr[F_LIT_LITE] = lighting_colours[s_attr & 0x0f][0];
806 f_attr[F_LIT_DARK] = lighting_colours[s_attr & 0x0f][1];
807 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_char[i] = s_char;
809 else /* For tile graphics */
811 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_attr[i] = s_attr;
812 f_char[F_LIT_LITE] = s_char + 2;
813 f_char[F_LIT_DARK] = s_char + 1;
819 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
821 #define darkened_grid(C) \
822 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
827 * @brief Mコマンドによる縮小マップの表示を行う / Extract the attr/char to display at the given (legal) map location
829 * Basically, we "paint" the chosen attr/char in several passes, starting\n
830 * with any known "terrain features" (defaulting to darkness), then adding\n
831 * any known "objects", and finally, adding any known "monsters". This\n
832 * is not the fastest method but since most of the calls to this function\n
833 * are made for grids with no monsters or objects, it is fast enough.\n
835 * Note that this function, if used on the grid containing the "player",\n
836 * will return the attr/char of the grid underneath the player, and not\n
837 * the actual player attr/char itself, allowing a lot of optimization\n
838 * in various "display" functions.\n
840 * Note that the "zero" entry in the feature/object/monster arrays are\n
841 * used to provide "special" attr/char codes, with "monster zero" being\n
842 * used for the player attr/char, "object zero" being used for the "stack"\n
843 * attr/char, and "feature zero" being used for the "nothing" attr/char,\n
844 * though this function makes use of only "feature zero".\n
846 * Note that monsters can have some "special" flags, including "ATTR_MULTI",\n
847 * which means their color changes, and "ATTR_CLEAR", which means they take\n
848 * the color of whatever is under them, and "CHAR_CLEAR", which means that\n
849 * they take the symbol of whatever is under them. Technically, the flag\n
850 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when\n
851 * examined, but this flag is currently ignored.\n
853 * Currently, we do nothing with multi-hued objects, because there are\n
854 * not any. If there were, they would have to set "shimmer_objects"\n
855 * when they were created, and then new "shimmer" code in "dungeon.c"\n
856 * would have to be created handle the "shimmer" effect, and the code\n
857 * in "cave.c" would have to be updated to create the shimmer effect.\n
859 * Note the effects of hallucination. Objects always appear as random\n
860 * "objects", monsters as random "monsters", and normal grids occasionally\n
861 * appear as random "monsters" or "objects", but note that these random\n
862 * "monsters" and "objects" are really just "colored ascii symbols".\n
864 * Note that "floors" and "invisible traps" (and "zero" features) are\n
865 * drawn as "floors" using a special check for optimization purposes,\n
866 * and these are the only features which get drawn using the special\n
867 * lighting effects activated by "view_special_lite".\n
869 * Note the use of the "mimic" field in the "terrain feature" processing,\n
870 * which allows any feature to "pretend" to be another feature. This is\n
871 * used to "hide" secret doors, and to make all "doors" appear the same,\n
872 * and all "walls" appear the same, and "hidden" treasure stay hidden.\n
873 * It is possible to use this field to make a feature "look" like a floor,\n
874 * but the "special lighting effects" for floors will not be used.\n
876 * Note the use of the new "terrain feature" information. Note that the\n
877 * assumption that all interesting "objects" and "terrain features" are\n
878 * memorized allows extremely optimized processing below. Note the use\n
879 * of separate flags on objects to mark them as memorized allows a grid\n
880 * to have memorized "terrain" without granting knowledge of any object\n
881 * which may appear in that grid.\n
883 * Note the efficient code used to determine if a "floor" grid is\n
884 * "memorized" or "viewable" by the player, where the test for the\n
885 * grid being "viewable" is based on the facts that (1) the grid\n
886 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in\n
887 * line of sight, and (3) the player must not be blind, and uses the\n
888 * assumption that all torch-lit grids are in line of sight.\n
890 * Note that floors (and invisible traps) are the only grids which are\n
891 * not memorized when seen, so only these grids need to check to see if\n
892 * the grid is "viewable" to the player (if it is not memorized). Since\n
893 * most non-memorized grids are in fact walls, this induces *massive*\n
894 * efficiency, at the cost of *forcing* the memorization of non-floor\n
895 * grids when they are first seen. Note that "invisible traps" are\n
896 * always treated exactly like "floors", which prevents "cheating".\n
898 * Note the "special lighting effects" which can be activated for floor\n
899 * grids using the "view_special_lite" option (for "white" floor grids),\n
900 * causing certain grids to be displayed using special colors. If the\n
901 * player is "blind", we will use "dark gray", else if the grid is lit\n
902 * by the torch, and the "view_yellow_lite" option is set, we will use\n
903 * "yellow", else if the grid is "dark", we will use "dark gray", else\n
904 * if the grid is not "viewable", and the "view_bright_lite" option is\n
905 * set, and the we will use "slate" (gray). We will use "white" for all\n
906 * other cases, in particular, for illuminated viewable floor grids.\n
908 * Note the "special lighting effects" which can be activated for wall\n
909 * grids using the "view_granite_lite" option (for "white" wall grids),\n
910 * causing certain grids to be displayed using special colors. If the\n
911 * player is "blind", we will use "dark gray", else if the grid is lit\n
912 * by the torch, and the "view_yellow_lite" option is set, we will use\n
913 * "yellow", else if the "view_bright_lite" option is set, and the grid\n
914 * is not "viewable", or is "dark", or is glowing, but not when viewed\n
915 * from the player's current location, we will use "slate" (gray). We\n
916 * will use "white" for all other cases, in particular, for correctly\n
917 * illuminated viewable wall grids.\n
919 * Note that, when "view_granite_lite" is set, we use an inline version\n
920 * of the "player_can_see_bold()" function to check the "viewability" of\n
921 * grids when the "view_bright_lite" option is set, and we do NOT use\n
922 * any special colors for "dark" wall grids, since this would allow the\n
923 * player to notice the walls of illuminated rooms from a hallway that\n
924 * happened to run beside the room. The alternative, by the way, would\n
925 * be to prevent the generation of hallways next to rooms, but this\n
926 * would still allow problems when digging towards a room.\n
928 * Note that bizarre things must be done when the "attr" and/or "char"\n
929 * codes have the "high-bit" set, since these values are used to encode\n
930 * various "special" pictures in some versions, and certain situations,\n
931 * such as "multi-hued" or "clear" monsters, cause the attr/char codes\n
932 * to be "scrambled" in various ways.\n
934 * Note that eventually we may use the "&" symbol for embedded treasure,\n
935 * and use the "*" symbol to indicate multiple objects, though this will\n
936 * have to wait for Angband 2.8.0 or later. Note that currently, this\n
937 * is not important, since only one object or terrain feature is allowed\n
938 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.\n
940 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of\n
941 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect\n
942 * then a whole lot of code should be changed... XXX XXX\n
944 void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp)
947 cave_type *c_ptr = &cave[y][x];
949 OBJECT_IDX this_o_idx, next_o_idx = 0;
951 /* Feature code (applying "mimic" field) */
952 FEAT_IDX feat = get_feat_mimic(c_ptr);
955 feature_type *f_ptr = &f_info[feat];
960 /* Boring grids (floors, etc) */
961 if (!have_flag(f_ptr->flags, FF_REMEMBER))
964 * Handle Memorized or visible floor
966 * No visual when blinded.
967 * (to prevent strange effects on darkness breath)
969 * - Can see grids with CAVE_MARK.
970 * - Can see grids with CAVE_LITE or CAVE_MNLT.
971 * (Such grids also have CAVE_VIEW)
972 * - Can see grids with CAVE_VIEW unless darkened by monsters.
975 ((c_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
976 ((c_ptr->info & CAVE_VIEW) && (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
978 /* Normal attr/char */
979 a = f_ptr->x_attr[F_LIT_STANDARD];
980 c = f_ptr->x_char[F_LIT_STANDARD];
982 if (p_ptr->wild_mode)
984 /* Special lighting effects */
986 if (view_special_lite && !is_daytime())
988 /* Use a darkened colour/tile */
989 a = f_ptr->x_attr[F_LIT_DARK];
990 c = f_ptr->x_char[F_LIT_DARK];
994 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
995 else if (darkened_grid(c_ptr))
997 /* Unsafe cave grid -- idea borrowed from Unangband */
998 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1000 /* Access darkness */
1001 f_ptr = &f_info[feat];
1003 /* Char and attr of darkness */
1004 a = f_ptr->x_attr[F_LIT_STANDARD];
1005 c = f_ptr->x_char[F_LIT_STANDARD];
1008 /* Special lighting effects */
1009 else if (view_special_lite)
1011 /* Handle "torch-lit" grids */
1012 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1015 if (view_yellow_lite)
1017 /* Use a brightly lit colour/tile */
1018 a = f_ptr->x_attr[F_LIT_LITE];
1019 c = f_ptr->x_char[F_LIT_LITE];
1023 /* Handle "dark" grids */
1024 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1026 /* Use a darkened colour/tile */
1027 a = f_ptr->x_attr[F_LIT_DARK];
1028 c = f_ptr->x_char[F_LIT_DARK];
1031 /* Handle "out-of-sight" grids */
1032 else if (!(c_ptr->info & CAVE_VIEW))
1035 if (view_bright_lite)
1037 /* Use a darkened colour/tile */
1038 a = f_ptr->x_attr[F_LIT_DARK];
1039 c = f_ptr->x_char[F_LIT_DARK];
1048 /* Unsafe cave grid -- idea borrowed from Unangband */
1049 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1051 /* Access darkness */
1052 f_ptr = &f_info[feat];
1054 /* Normal attr/char */
1055 a = f_ptr->x_attr[F_LIT_STANDARD];
1056 c = f_ptr->x_char[F_LIT_STANDARD];
1060 /* Interesting grids (non-floors) */
1063 /* Memorized grids */
1064 if (c_ptr->info & CAVE_MARK)
1066 /* Normal attr/char */
1067 a = f_ptr->x_attr[F_LIT_STANDARD];
1068 c = f_ptr->x_char[F_LIT_STANDARD];
1070 if (p_ptr->wild_mode)
1072 /* Special lighting effects */
1073 /* Handle "blind" or "night" */
1074 if (view_granite_lite && (p_ptr->blind || !is_daytime()))
1076 /* Use a darkened colour/tile */
1077 a = f_ptr->x_attr[F_LIT_DARK];
1078 c = f_ptr->x_char[F_LIT_DARK];
1082 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1083 else if (darkened_grid(c_ptr) && !p_ptr->blind)
1085 if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
1087 /* Unsafe cave grid -- idea borrowed from Unangband */
1088 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1090 /* Access darkness */
1091 f_ptr = &f_info[feat];
1093 /* Char and attr of darkness */
1094 a = f_ptr->x_attr[F_LIT_STANDARD];
1095 c = f_ptr->x_char[F_LIT_STANDARD];
1097 else if (view_granite_lite && view_bright_lite)
1099 /* Use a darkened colour/tile */
1100 a = f_ptr->x_attr[F_LIT_DARK];
1101 c = f_ptr->x_char[F_LIT_DARK];
1105 /* Special lighting effects */
1106 else if (view_granite_lite)
1108 /* Handle "blind" */
1111 /* Use a darkened colour/tile */
1112 a = f_ptr->x_attr[F_LIT_DARK];
1113 c = f_ptr->x_char[F_LIT_DARK];
1116 /* Handle "torch-lit" grids */
1117 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1120 if (view_yellow_lite)
1122 /* Use a brightly lit colour/tile */
1123 a = f_ptr->x_attr[F_LIT_LITE];
1124 c = f_ptr->x_char[F_LIT_LITE];
1128 /* Handle "view_bright_lite" */
1129 else if (view_bright_lite)
1132 if (!(c_ptr->info & CAVE_VIEW))
1134 /* Use a darkened colour/tile */
1135 a = f_ptr->x_attr[F_LIT_DARK];
1136 c = f_ptr->x_char[F_LIT_DARK];
1140 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1142 /* Use a darkened colour/tile */
1143 a = f_ptr->x_attr[F_LIT_DARK];
1144 c = f_ptr->x_char[F_LIT_DARK];
1147 /* Not glowing correctly */
1148 else if (!have_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(y, x))
1150 /* Use a darkened colour/tile */
1151 a = f_ptr->x_attr[F_LIT_DARK];
1152 c = f_ptr->x_char[F_LIT_DARK];
1161 /* Unsafe cave grid -- idea borrowed from Unangband */
1162 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1164 /* Access feature */
1165 f_ptr = &f_info[feat];
1167 /* Normal attr/char */
1168 a = f_ptr->x_attr[F_LIT_STANDARD];
1169 c = f_ptr->x_char[F_LIT_STANDARD];
1173 if (feat_priority == -1) feat_priority = f_ptr->priority;
1175 /* Save the terrain info for the transparency effects */
1183 /* Hack -- rare random hallucination, except on outer dungeon walls */
1189 image_random(ap, cp);
1194 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1197 o_ptr = &o_list[this_o_idx];
1199 /* Acquire next object */
1200 next_o_idx = o_ptr->next_o_idx;
1202 /* Memorized objects */
1203 if (o_ptr->marked & OM_FOUND)
1205 if (display_autopick)
1209 match_autopick = is_autopick(o_ptr);
1210 if(match_autopick == -1)
1213 act = autopick_list[match_autopick].action;
1215 if ((act & DO_DISPLAY) && (act & display_autopick))
1217 autopick_obj = o_ptr;
1221 match_autopick = -1;
1226 (*cp) = object_char(o_ptr);
1229 (*ap) = object_attr(o_ptr);
1233 /* Hack -- hallucination */
1234 if (p_ptr->image) image_object(ap, cp);
1241 /* Handle monsters */
1242 if (c_ptr->m_idx && display_autopick == 0 )
1244 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1246 /* Visible monster */
1249 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1257 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1258 * flags are always unseen.
1260 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1266 /* Hallucinatory monster */
1267 image_monster(ap, cp);
1272 /* Monster attr/char */
1276 /* Normal monsters */
1277 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1278 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1280 /* Desired monster attr/char */
1286 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1287 * flags are always unseen.
1289 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1296 /*** Monster's attr ***/
1297 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1302 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1304 /* Multi-hued attr */
1305 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1306 else switch (randint1(7))
1308 case 1: *ap = TERM_RED; break;
1309 case 2: *ap = TERM_L_RED; break;
1310 case 3: *ap = TERM_WHITE; break;
1311 case 4: *ap = TERM_L_GREEN; break;
1312 case 5: *ap = TERM_BLUE; break;
1313 case 6: *ap = TERM_L_DARK; break;
1314 case 7: *ap = TERM_GREEN; break;
1317 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1319 /* Use semi-random attr (usually mimics' colors vary) */
1320 *ap = c_ptr->m_idx % 15 + 1;
1328 /*** Monster's char ***/
1329 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1334 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1338 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1339 *cp = tmp_r_ptr->x_char;
1340 *ap = tmp_r_ptr->x_attr;
1344 *cp = (one_in_(25) ?
1345 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1346 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1359 /* Handle "player" */
1360 if (player_bold(y, x))
1362 monster_race *r_ptr = &r_info[0];
1363 *ap = r_ptr->x_attr;
1364 *cp = r_ptr->x_char;
1371 * Calculate panel colum of a location in the map
1373 static int panel_col_of(int col)
1375 col -= panel_col_min;
1376 if (use_bigtile) col *= 2;
1382 * Moves the cursor to a given MAP (y,x) location
1384 void move_cursor_relative(int row, int col)
1386 /* Real co-ords convert to screen positions */
1387 row -= panel_row_prt;
1390 Term_gotoxy(panel_col_of(col), row);
1396 * Place an attr/char pair at the given map coordinate, if legal.
1398 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
1400 /* Only do "legal" locations */
1401 if (panel_contains(y, x))
1403 /* Hack -- fake monochrome */
1406 if (world_monster) a = TERM_DARK;
1407 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1408 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1411 /* Draw the char using the attr */
1412 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, 0, 0);
1421 * Memorize interesting viewable object/features in the given grid
1423 * This function should only be called on "legal" grids.
1425 * This function will memorize the object and/or feature in the given
1426 * grid, if they are (1) viewable and (2) interesting. Note that all
1427 * objects are interesting, all terrain features except floors (and
1428 * invisible traps) are interesting, and floors (and invisible traps)
1429 * are interesting sometimes (depending on various options involving
1430 * the illumination of floor grids).
1432 * The automatic memorization of all objects and non-floor terrain
1433 * features as soon as they are displayed allows incredible amounts
1434 * of optimization in various places, especially "map_info()".
1436 * Note that the memorization of objects is completely separate from
1437 * the memorization of terrain features, preventing annoying floor
1438 * memorization when a detected object is picked up from a dark floor,
1439 * and object memorization when an object is dropped into a floor grid
1440 * which is memorized but out-of-sight.
1442 * This function should be called every time the "memorization" of
1443 * a grid (or the object in a grid) is called into question, such
1444 * as when an object is created in a grid, when a terrain feature
1445 * "changes" from "floor" to "non-floor", when any grid becomes
1446 * "illuminated" or "viewable", and when a "floor" grid becomes
1449 * Note the relatively efficient use of this function by the various
1450 * "update_view()" and "update_lite()" calls, to allow objects and
1451 * terrain features to be memorized (and drawn) whenever they become
1452 * viewable or illuminated in any way, but not when they "maintain"
1453 * or "lose" their previous viewability or illumination.
1455 * Note the butchered "internal" version of "player_can_see_bold()",
1456 * optimized primarily for the most common cases, that is, for the
1457 * non-marked floor grids.
1459 void note_spot(POSITION y, POSITION x)
1461 cave_type *c_ptr = &cave[y][x];
1462 OBJECT_IDX this_o_idx, next_o_idx = 0;
1464 /* Blind players see nothing */
1465 if (p_ptr->blind) return;
1467 /* Analyze non-torch-lit grids */
1468 if (!(c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1470 /* Require line of sight to the grid */
1471 if (!(c_ptr->info & (CAVE_VIEW))) return;
1473 /* Require "perma-lite" of the grid */
1474 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1477 if (!p_ptr->see_nocto) return;
1482 /* Hack -- memorize objects */
1483 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1485 object_type *o_ptr = &o_list[this_o_idx];
1487 /* Acquire next object */
1488 next_o_idx = o_ptr->next_o_idx;
1490 /* Memorize objects */
1491 o_ptr->marked |= OM_FOUND;
1495 /* Hack -- memorize grids */
1496 if (!(c_ptr->info & (CAVE_MARK)))
1498 /* Feature code (applying "mimic" field) */
1499 feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
1501 /* Memorize some "boring" grids */
1502 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1504 /* Option -- memorize all torch-lit floors */
1505 if (view_torch_grids &&
1506 ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1508 c_ptr->info |= (CAVE_MARK);
1511 /* Option -- memorize all perma-lit floors */
1512 else if (view_perma_grids && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1514 c_ptr->info |= (CAVE_MARK);
1518 /* Memorize normal grids */
1519 else if (have_flag(f_ptr->flags, FF_LOS))
1521 c_ptr->info |= (CAVE_MARK);
1524 /* Memorize torch-lit walls */
1525 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1527 c_ptr->info |= (CAVE_MARK);
1530 /* Memorize walls seen by noctovision of Ninja */
1531 else if (p_ptr->see_nocto)
1533 c_ptr->info |= (CAVE_MARK);
1536 /* Memorize certain non-torch-lit wall grids */
1537 else if (check_local_illumination(y, x))
1539 c_ptr->info |= (CAVE_MARK);
1543 /* Memorize terrain of the grid */
1544 c_ptr->info |= (CAVE_KNOWN);
1548 void display_dungeon(void)
1555 SYMBOL_CODE tc = '\0';
1557 for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
1559 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
1561 if (in_bounds2(y, x))
1564 /* Examine the grid */
1565 map_info(y, x, &a, &c, &ta, &tc);
1567 /* Hack -- fake monochrome */
1570 if (world_monster) a = TERM_DARK;
1571 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1572 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1575 /* Hack -- Queue it */
1576 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1580 /* Clear out-of-bound tiles */
1582 /* Access darkness */
1583 feature_type *f_ptr = &f_info[feat_none];
1586 a = f_ptr->x_attr[F_LIT_STANDARD];
1589 c = f_ptr->x_char[F_LIT_STANDARD];
1591 /* Hack -- Queue it */
1592 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1600 * Redraw (on the screen) a given MAP location
1602 * This function should only be called on "legal" grids
1604 void lite_spot(POSITION y, POSITION x)
1606 /* Redraw if on screen */
1607 if (panel_contains(y, x) && in_bounds2(y, x))
1615 /* Examine the grid */
1616 map_info(y, x, &a, &c, &ta, &tc);
1618 /* Hack -- fake monochrome */
1621 if (world_monster) a = TERM_DARK;
1622 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1623 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1626 /* Hack -- Queue it */
1627 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1629 /* Update sub-windows */
1630 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1636 * Prints the map of the dungeon
1638 * Note that, for efficiency, we contain an "optimized" version
1639 * of both "lite_spot()" and "print_rel()", and that we use the
1640 * "lite_spot()" function to display the player grid, if needed.
1648 POSITION xmin, xmax, ymin, ymax;
1652 Term_get_size(&wid, &hgt);
1654 /* Remove map offset */
1658 /* Access the cursor state */
1659 (void)Term_get_cursor(&v);
1661 /* Hide the cursor */
1662 (void)Term_set_cursor(0);
1665 xmin = (0 < panel_col_min) ? panel_col_min : 0;
1666 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1667 ymin = (0 < panel_row_min) ? panel_row_min : 0;
1668 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1670 /* Bottom section of screen */
1671 for (y = 1; y <= ymin - panel_row_prt; y++)
1673 /* Erase the section */
1674 Term_erase(COL_MAP, y, wid);
1677 /* Top section of screen */
1678 for (y = ymax - panel_row_prt; y <= hgt; y++)
1680 /* Erase the section */
1681 Term_erase(COL_MAP, y, wid);
1685 for (y = ymin; y <= ymax; y++)
1687 /* Scan the columns of row "y" */
1688 for (x = xmin; x <= xmax; x++)
1696 /* Determine what is there */
1697 map_info(y, x, &a, &c, &ta, &tc);
1699 /* Hack -- fake monochrome */
1702 if (world_monster) a = TERM_DARK;
1703 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1704 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1707 /* Efficiency -- Redraw that grid of the map */
1708 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1712 /* Display player */
1713 lite_spot(p_ptr->y, p_ptr->x);
1715 /* Restore the cursor */
1716 (void)Term_set_cursor(v);
1722 * print project path
1724 void prt_path(POSITION y, POSITION x)
1729 byte_hack default_color = TERM_SLATE;
1731 if (!display_path) return;
1732 if (-1 == project_length)
1735 /* Get projection path */
1736 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH|PROJECT_THRU);
1738 p_ptr->redraw |= (PR_MAP);
1742 for (i = 0; i < path_n; i++)
1744 POSITION ny = GRID_Y(path_g[i]);
1745 POSITION nx = GRID_X(path_g[i]);
1746 cave_type *c_ptr = &cave[ny][nx];
1748 if (panel_contains(ny, nx))
1750 TERM_COLOR a = default_color;
1753 TERM_COLOR ta = default_color;
1756 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1758 /* Determine what is there */
1759 map_info(ny, nx, &a, &c, &ta, &tc);
1761 if (!is_ascii_graphics(a))
1763 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1765 else if (a == default_color)
1771 if (world_monster) a = TERM_DARK;
1772 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1773 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1778 /* Hack -- Queue it */
1779 Term_queue_bigchar(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
1783 if ((c_ptr->info & CAVE_MARK) && !cave_have_flag_grid(c_ptr, FF_PROJECT)) break;
1786 if (nx == x && ny == y) default_color = TERM_L_DARK;
1791 static concptr simplify_list[][2] =
1798 {"^Amulet of ", "\""},
1799 {"^Scroll of ", "?"},
1800 {"^Scroll titled ", "?"},
1801 {"^Wand of " , "-"},
1803 {"^Staff of " , "_"},
1804 {"^Potion of ", "!"},
1816 static void display_shortened_item_name(object_type *o_ptr, int y)
1823 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
1824 attr = tval_to_attr[o_ptr->tval % 128];
1829 strcpy(buf, _("何か奇妙な物", "something strange"));
1832 for (c = buf; *c; c++)
1835 for (i = 0; simplify_list[i][1]; i++)
1837 concptr org_w = simplify_list[i][0];
1847 if (!strncmp(c, org_w, strlen(org_w)))
1850 concptr tmp = simplify_list[i][1];
1853 tmp = c + strlen(org_w);
1869 if(len + 2 > 12) break;
1876 if(len + 1 > 12) break;
1882 Term_putstr(0, y, 12, attr, buf);
1886 * Display a "small-scale" map of the dungeon in the active Term
1888 void display_map(int *cy, int *cx)
1898 SYMBOL_CODE **bigmc;
1905 /* Save lighting effects */
1906 bool old_view_special_lite = view_special_lite;
1907 bool old_view_granite_lite = view_granite_lite;
1909 TERM_LEN hgt, wid, yrat, xrat;
1911 int **match_autopick_yx;
1912 object_type ***object_autopick_yx;
1914 Term_get_size(&wid, &hgt);
1917 if (use_bigtile) wid /= 2;
1919 yrat = (cur_hgt + hgt - 1) / hgt;
1920 xrat = (cur_wid + wid - 1) / wid;
1922 /* Disable lighting effects */
1923 view_special_lite = FALSE;
1924 view_granite_lite = FALSE;
1926 /* Allocate the maps */
1927 C_MAKE(ma, (hgt + 2), TERM_COLOR *);
1928 C_MAKE(mc, (hgt + 2), char_ptr);
1929 C_MAKE(mp, (hgt + 2), byte_ptr);
1930 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
1931 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
1933 /* Allocate and wipe each line map */
1934 for (y = 0; y < (hgt + 2); y++)
1936 /* Allocate one row each array */
1937 C_MAKE(ma[y], (wid + 2), TERM_COLOR);
1938 C_MAKE(mc[y], (wid + 2), char);
1939 C_MAKE(mp[y], (wid + 2), byte);
1940 C_MAKE(match_autopick_yx[y], (wid + 2), int);
1941 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
1943 for (x = 0; x < wid + 2; ++x)
1945 match_autopick_yx[y][x] = -1;
1946 object_autopick_yx[y][x] = NULL;
1949 ma[y][x] = TERM_WHITE;
1957 /* Allocate the maps */
1958 C_MAKE(bigma, (cur_hgt + 2), TERM_COLOR *);
1959 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
1960 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
1962 /* Allocate and wipe each line map */
1963 for (y = 0; y < (cur_hgt + 2); y++)
1965 /* Allocate one row each array */
1966 C_MAKE(bigma[y], (cur_wid + 2), TERM_COLOR);
1967 C_MAKE(bigmc[y], (cur_wid + 2), char);
1968 C_MAKE(bigmp[y], (cur_wid + 2), byte);
1970 for (x = 0; x < cur_wid + 2; ++x)
1973 bigma[y][x] = TERM_WHITE;
1981 /* Fill in the map */
1982 for (i = 0; i < cur_wid; ++i)
1984 for (j = 0; j < cur_hgt; ++j)
1993 /* Extract the current attr/char at that map location */
1994 map_info(j, i, &ta, &tc, &ta, &tc);
1996 /* Extract the priority */
1997 tp = (byte_hack)feat_priority;
1999 if(match_autopick!=-1
2000 && (match_autopick_yx[y][x] == -1
2001 || match_autopick_yx[y][x] > match_autopick))
2003 match_autopick_yx[y][x] = match_autopick;
2004 object_autopick_yx[y][x] = autopick_obj;
2008 /* Save the char, attr and priority */
2009 bigmc[j+1][i+1] = tc;
2010 bigma[j+1][i+1] = ta;
2011 bigmp[j+1][i+1] = tp;
2015 for (j = 0; j < cur_hgt; ++j)
2017 for (i = 0; i < cur_wid; ++i)
2022 tc = bigmc[j+1][i+1];
2023 ta = bigma[j+1][i+1];
2024 tp = bigmp[j+1][i+1];
2026 /* rare feature has more priority */
2032 for (t = 0; t < 8; t++)
2034 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2035 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2045 /* Save the char, attr and priority */
2058 /* Draw the corners */
2059 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2061 /* Draw the horizontal edges */
2062 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2064 /* Draw the vertical edges */
2065 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2068 /* Display each map line in order */
2069 for (y = 0; y < hgt + 2; ++y)
2071 /* Start a new line */
2072 Term_gotoxy(COL_MAP, y);
2074 /* Display the line */
2075 for (x = 0; x < wid + 2; ++x)
2080 /* Hack -- fake monochrome */
2083 if (world_monster) ta = TERM_DARK;
2084 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2085 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2088 /* Add the character */
2089 Term_add_bigch(ta, tc);
2094 for (y = 1; y < hgt + 1; ++y)
2096 match_autopick = -1;
2097 for (x = 1; x <= wid; x++){
2098 if (match_autopick_yx[y][x] != -1 &&
2099 (match_autopick > match_autopick_yx[y][x] ||
2100 match_autopick == -1)){
2101 match_autopick = match_autopick_yx[y][x];
2102 autopick_obj = object_autopick_yx[y][x];
2106 /* Clear old display */
2107 Term_putstr(0, y, 12, 0, " ");
2109 if (match_autopick != -1)
2111 display_shortened_item_name(autopick_obj, y);
2114 char buf[13] = "\0";
2115 strncpy(buf,autopick_list[match_autopick].name,12);
2123 /* Player location */
2124 (*cy) = p_ptr->y / yrat + 1 + ROW_MAP;
2126 (*cx) = p_ptr->x / xrat + 1 + COL_MAP;
2128 (*cx) = (p_ptr->x / xrat + 1) * 2 + COL_MAP;
2130 /* Restore lighting effects */
2131 view_special_lite = old_view_special_lite;
2132 view_granite_lite = old_view_granite_lite;
2134 /* Free each line map */
2135 for (y = 0; y < (hgt + 2); y++)
2137 /* Free one row each array */
2138 C_KILL(ma[y], (wid + 2), TERM_COLOR);
2139 C_KILL(mc[y], (wid + 2), SYMBOL_CODE);
2140 C_KILL(mp[y], (wid + 2), byte);
2141 C_KILL(match_autopick_yx[y], (wid + 2), int);
2142 C_KILL(object_autopick_yx[y], (wid + 2), object_type *);
2145 /* Free each line map */
2146 C_KILL(ma, (hgt + 2), TERM_COLOR *);
2147 C_KILL(mc, (hgt + 2), char_ptr);
2148 C_KILL(mp, (hgt + 2), byte_ptr);
2149 C_KILL(match_autopick_yx, (hgt + 2), sint_ptr);
2150 C_KILL(object_autopick_yx, (hgt + 2), object_type **);
2152 /* Free each line map */
2153 for (y = 0; y < (cur_hgt + 2); y++)
2155 /* Free one row each array */
2156 C_KILL(bigma[y], (cur_wid + 2), TERM_COLOR);
2157 C_KILL(bigmc[y], (cur_wid + 2), SYMBOL_CODE);
2158 C_KILL(bigmp[y], (cur_wid + 2), byte);
2161 /* Free each line map */
2162 C_KILL(bigma, (cur_hgt + 2), TERM_COLOR *);
2163 C_KILL(bigmc, (cur_hgt + 2), char_ptr);
2164 C_KILL(bigmp, (cur_hgt + 2), byte_ptr);
2169 * Display a "small-scale" map of the dungeon for the player
2171 * Currently, the "player" is displayed on the map.
2173 void do_cmd_view_map(void)
2179 prt(_("お待ち下さい...", "Please wait..."), 0, 0);
2184 display_autopick = 0;
2186 /* Display the map */
2187 display_map(&cy, &cx);
2190 if(max_autopick && !p_ptr->wild_mode)
2192 display_autopick = ITEM_DISPLAY;
2199 int wid, hgt, row_message;
2201 Term_get_size(&wid, &hgt);
2202 row_message = hgt - 1;
2204 put_str(_("何かキーを押してください('M':拾う 'N':放置 'D':M+N 'K':壊すアイテムを表示)",
2205 " Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items."), row_message, 1);
2207 /* Hilite the player */
2208 move_cursor(cy, cx);
2213 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2215 flag = DONT_AUTOPICK;
2217 flag = DO_AUTODESTROY;
2219 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2225 if (~display_autopick & flag)
2226 display_autopick |= flag;
2228 display_autopick &= ~flag;
2229 /* Display the map */
2230 display_map(&cy, &cx);
2233 display_autopick = 0;
2238 put_str(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"), 23, 30);
2239 /* Hilite the player */
2240 move_cursor(cy, cx);
2252 * Some comments on the cave grid flags. -BEN-
2255 * One of the major bottlenecks in previous versions of Angband was in
2256 * the calculation of "line of sight" from the player to various grids,
2257 * such as monsters. This was such a nasty bottleneck that a lot of
2258 * silly things were done to reduce the dependancy on "line of sight",
2259 * for example, you could not "see" any grids in a lit room until you
2260 * actually entered the room, and there were all kinds of bizarre grid
2261 * flags to enable this behavior. This is also why the "call light"
2262 * spells always lit an entire room.
2264 * The code below provides functions to calculate the "field of view"
2265 * for the player, which, once calculated, provides extremely fast
2266 * calculation of "line of sight from the player", and to calculate
2267 * the "field of torch lite", which, again, once calculated, provides
2268 * extremely fast calculation of "which grids are lit by the player's
2269 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2270 * "GRID_LITE", as appropriate, these functions maintain an array for
2271 * each of these two flags, each array containing the locations of all
2272 * of the grids marked with the appropriate flag, which can be used to
2273 * very quickly scan through all of the grids in a given set.
2275 * To allow more "semantically valid" field of view semantics, whenever
2276 * the field of view (or the set of torch lit grids) changes, all of the
2277 * grids in the field of view (or the set of torch lit grids) are "drawn"
2278 * so that changes in the world will become apparent as soon as possible.
2279 * This has been optimized so that only grids which actually "change" are
2280 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2281 * of the grids which are entering or leaving the relevent set of grids.
2283 * These new methods are so efficient that the old nasty code was removed.
2285 * Note that there is no reason to "update" the "viewable space" unless
2286 * the player "moves", or walls/doors are created/destroyed, and there
2287 * is no reason to "update" the "torch lit grids" unless the field of
2288 * view changes, or the "light radius" changes. This means that when
2289 * the player is resting, or digging, or doing anything that does not
2290 * involve movement or changing the state of the dungeon, there is no
2291 * need to update the "view" or the "lite" regions, which is nice.
2293 * Note that the calls to the nasty "los()" function have been reduced
2294 * to a bare minimum by the use of the new "field of view" calculations.
2296 * I wouldn't be surprised if slight modifications to the "update_view()"
2297 * function would allow us to determine "reverse line-of-sight" as well
2298 * as "normal line-of-sight", which would allow monsters to use a more
2299 * "correct" calculation to determine if they can "see" the player. For
2300 * now, monsters simply "cheat" somewhat and assume that if the player
2301 * has "line of sight" to the monster, then the monster can "pretend"
2302 * that it has "line of sight" to the player.
2305 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2306 * grid and maintains an array of all "CAVE_LITE" grids.
2308 * This set of grids is the complete set of all grids which are lit by
2309 * the players light source, which allows the "player_can_see_bold()"
2310 * function to work very quickly.
2312 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2313 * fact, the player (unless blind) can always "see" all grids which are
2314 * marked as "CAVE_LITE", unless they are "off screen".
2317 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2318 * grid and maintains an array of all "CAVE_VIEW" grids.
2320 * This set of grids is the complete set of all grids within line of sight
2321 * of the player, allowing the "player_has_los_bold()" macro to work very
2325 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2326 * temporary internal flag to mark those grids which are not only in view,
2327 * but which are also "easily" in line of sight of the player. This flag
2328 * is always cleared when we are done.
2331 * The current "update_lite()" and "update_view()" algorithms use the
2332 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2333 * to keep track of which grids were previously marked as "CAVE_LITE" or
2334 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2336 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2337 * for various other purposes, such as spreading lite or darkness during
2338 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2341 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2342 * in some way permanently lit. However, for the player to "see" anything
2343 * in the grid, as determined by "player_can_see()", the player must not be
2344 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2345 * grids, even if marked as "perma lit", are only illuminated if they touch
2346 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2349 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2350 * that even if the player cannot "see" the grid, he "knows" the terrain in
2351 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2352 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2353 * or when one of the "memorize floor grids" options induces memorization.
2355 * Objects are "memorized" in a different way, using a special "marked" flag
2356 * on the object itself, which is set when an object is observed or detected.
2359 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2360 * and should be illuminated by "lite room" and "darkness" spells.
2363 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2364 * and should be unavailable for "teleportation" destinations.
2367 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2368 * which is observed, and the "view_torch_grids" allows the player to memorize
2369 * every torch-lit grid. The player will always memorize important walls,
2370 * doors, stairs, and other terrain features, as well as any "detected" grids.
2372 * Note that the new "update_view()" method allows, among other things, a room
2373 * to be "partially" seen as the player approaches it, with a growing cone of
2374 * floor appearing as the player gets closer to the door. Also, by not turning
2375 * on the "memorize perma-lit grids" option, the player will only "see" those
2376 * floor grids which are actually in line of sight.
2378 * And my favorite "plus" is that you can now use a special option to draw the
2379 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2380 * grids dimly), providing a "pretty" effect as the player runs around, and
2381 * to efficiently display the "torch lite" in a special color.
2384 * Some comments on the "update_view()" algorithm...
2386 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2387 * and only has to call "los()" on the borderline cases. The major axes/diags
2388 * even terminate early when they hit walls. I need to find a quick way
2389 * to "terminate" the other scans.
2391 * Note that in the worst case (a big empty area with say 5% scattered walls),
2392 * each of the 1500 or so nearby grids is checked once, most of them getting
2393 * an "instant" rating, and only a small portion requiring a call to "los()".
2395 * The only time that the algorithm appears to be "noticeably" too slow is
2396 * when running, and this is usually only important in town, since the town
2397 * provides about the worst scenario possible, with large open regions and
2398 * a few scattered obstructions. There is a special "efficiency" option to
2399 * allow the player to reduce his field of view in town, if needed.
2401 * In the "best" case (say, a normal stretch of corridor), the algorithm
2402 * makes one check for each viewable grid, and makes no calls to "los()".
2403 * So running in corridors is very fast, and if a lot of monsters are
2404 * nearby, it is much faster than the old methods.
2406 * Note that resting, most normal commands, and several forms of running,
2407 * plus all commands executed near large groups of monsters, are strictly
2408 * more efficient with "update_view()" that with the old "compute los() on
2409 * demand" method, primarily because once the "field of view" has been
2410 * calculated, it does not have to be recalculated until the player moves
2411 * (or a wall or door is created or destroyed).
2413 * Note that we no longer have to do as many "los()" checks, since once the
2414 * "view" region has been built, very few things cause it to be "changed"
2415 * (player movement, and the opening/closing of doors, changes in wall status).
2416 * Note that door/wall changes are only relevant when the door/wall itself is
2417 * in the "view" region.
2419 * The algorithm seems to only call "los()" from zero to ten times, usually
2420 * only when coming down a corridor into a room, or standing in a room, just
2421 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2422 * we will be reducing the calls to "los()".
2424 * I am thinking in terms of an algorithm that "walks" from the central point
2425 * out to the maximal "distance", at each point, determining the "view" code
2426 * (above). For each grid not on a major axis or diagonal, the "view" code
2427 * depends on the "cave_los_bold()" and "view" of exactly two other grids
2428 * (the one along the nearest diagonal, and the one next to that one, see
2429 * "update_view_aux()"...).
2431 * We "memorize" the viewable space array, so that at the cost of under 3000
2432 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2433 * each grid actually in the "viewable space". And for another 3000 bytes,
2434 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2435 * are also used by other routines, thus reducing the cost to almost nothing.
2437 * A similar thing is done for "forget_lite()" in which case the savings are
2438 * much less, but save us from doing bizarre maintenance checking.
2440 * In the worst "normal" case (in the middle of the town), the reachable space
2441 * actually reaches to more than half of the largest possible "circle" of view,
2442 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2443 * where all the walls have been removed), the reachable space actually reaches
2444 * the theoretical maximum size of just under 1500 grids.
2446 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2447 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2448 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2449 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2450 * entire possible space (including initialization) in one step per grid. If
2451 * we do the "clearing" as a separate step (and use an array of "view" grids),
2452 * then the clearing will take as many steps as grids that were viewed, and the
2453 * algorithm will be able to "stop" scanning at various points.
2454 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2465 * Actually erase the entire "lite" array, redrawing every grid
2467 void forget_lite(void)
2471 /* None to forget */
2472 if (!lite_n) return;
2474 /* Clear them all */
2475 for (i = 0; i < lite_n; i++)
2480 /* Forget "LITE" flag */
2481 cave[y][x].info &= ~(CAVE_LITE);
2483 /* lite_spot(y, x); Perhaps don't need? */
2492 * For delayed visual update
2494 #define cave_note_and_redraw_later(C,Y,X) \
2496 (C)->info |= CAVE_NOTE; \
2497 cave_redraw_later((C), (Y), (X)); \
2502 * For delayed visual update
2504 #define cave_redraw_later(C,Y,X) \
2506 if (!((C)->info & CAVE_REDRAW)) \
2508 (C)->info |= CAVE_REDRAW; \
2509 redraw_y[redraw_n] = (Y); \
2510 redraw_x[redraw_n++] = (X); \
2516 * This macro allows us to efficiently add a grid to the "lite" array,
2517 * note that we are never called for illegal grids, or for grids which
2518 * have already been placed into the "lite" array, and we are never
2519 * called when the "lite" array is full.
2521 #define cave_lite_hack(Y,X) \
2523 if (!(cave[Y][X].info & (CAVE_LITE))) \
2525 cave[Y][X].info |= (CAVE_LITE); \
2526 lite_y[lite_n] = (Y); \
2527 lite_x[lite_n++] = (X); \
2533 * Update the set of grids "illuminated" by the player's lite.
2535 * This routine needs to use the results of "update_view()"
2537 * Note that "blindness" does NOT affect "torch lite". Be careful!
2539 * We optimize most lites (all non-artifact lites) by using "obvious"
2540 * facts about the results of "small" lite radius, and we attempt to
2541 * list the "nearby" grids before the more "distant" ones in the
2542 * array of torch-lit grids.
2544 * We assume that "radius zero" lite is in fact no lite at all.
2546 * Torch Lantern Artifacts
2556 void update_lite(void)
2558 int i, x, y, min_x, max_x, min_y, max_y;
2559 int p = p_ptr->cur_lite;
2562 /*** Special case ***/
2565 /* Hack -- Player has no lite */
2568 /* Forget the old lite */
2569 /* forget_lite(); Perhaps don't need? */
2571 /* Add it to later visual update */
2572 cave_redraw_later(&cave[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
2576 /*** Save the old "lite" grids for later ***/
2578 /* Clear them all */
2579 for (i = 0; i < lite_n; i++)
2584 /* Mark the grid as not "lite" */
2585 cave[y][x].info &= ~(CAVE_LITE);
2587 /* Mark the grid as "seen" */
2588 cave[y][x].info |= (CAVE_TEMP);
2590 /* Add it to the "seen" set */
2600 /*** Collect the new "lite" grids ***/
2602 /* Radius 1 -- torch radius */
2606 cave_lite_hack(p_ptr->y, p_ptr->x);
2609 cave_lite_hack(p_ptr->y+1, p_ptr->x);
2610 cave_lite_hack(p_ptr->y-1, p_ptr->x);
2611 cave_lite_hack(p_ptr->y, p_ptr->x+1);
2612 cave_lite_hack(p_ptr->y, p_ptr->x-1);
2614 /* Diagonal grids */
2615 cave_lite_hack(p_ptr->y+1, p_ptr->x+1);
2616 cave_lite_hack(p_ptr->y+1, p_ptr->x-1);
2617 cave_lite_hack(p_ptr->y-1, p_ptr->x+1);
2618 cave_lite_hack(p_ptr->y-1, p_ptr->x-1);
2621 /* Radius 2 -- lantern radius */
2624 /* South of the player */
2625 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
2627 cave_lite_hack(p_ptr->y+2, p_ptr->x);
2628 cave_lite_hack(p_ptr->y+2, p_ptr->x+1);
2629 cave_lite_hack(p_ptr->y+2, p_ptr->x-1);
2632 /* North of the player */
2633 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
2635 cave_lite_hack(p_ptr->y-2, p_ptr->x);
2636 cave_lite_hack(p_ptr->y-2, p_ptr->x+1);
2637 cave_lite_hack(p_ptr->y-2, p_ptr->x-1);
2640 /* East of the player */
2641 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
2643 cave_lite_hack(p_ptr->y, p_ptr->x+2);
2644 cave_lite_hack(p_ptr->y+1, p_ptr->x+2);
2645 cave_lite_hack(p_ptr->y-1, p_ptr->x+2);
2648 /* West of the player */
2649 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
2651 cave_lite_hack(p_ptr->y, p_ptr->x-2);
2652 cave_lite_hack(p_ptr->y+1, p_ptr->x-2);
2653 cave_lite_hack(p_ptr->y-1, p_ptr->x-2);
2657 /* Radius 3+ -- artifact radius */
2662 /* Paranoia -- see "LITE_MAX" */
2665 /* South-East of the player */
2666 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
2668 cave_lite_hack(p_ptr->y+2, p_ptr->x+2);
2671 /* South-West of the player */
2672 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
2674 cave_lite_hack(p_ptr->y+2, p_ptr->x-2);
2677 /* North-East of the player */
2678 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
2680 cave_lite_hack(p_ptr->y-2, p_ptr->x+2);
2683 /* North-West of the player */
2684 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
2686 cave_lite_hack(p_ptr->y-2, p_ptr->x-2);
2690 min_y = p_ptr->y - p;
2691 if (min_y < 0) min_y = 0;
2694 max_y = p_ptr->y + p;
2695 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
2698 min_x = p_ptr->x - p;
2699 if (min_x < 0) min_x = 0;
2702 max_x = p_ptr->x + p;
2703 if (max_x > cur_wid-1) max_x = cur_wid-1;
2705 /* Scan the maximal box */
2706 for (y = min_y; y <= max_y; y++)
2708 for (x = min_x; x <= max_x; x++)
2710 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
2711 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
2713 /* Skip the "central" grids (above) */
2714 if ((dy <= 2) && (dx <= 2)) continue;
2716 /* Hack -- approximate the distance */
2717 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2719 /* Skip distant grids */
2720 if (d > p) continue;
2722 /* Viewable, nearby, grids get "torch lit" */
2723 if (cave[y][x].info & CAVE_VIEW)
2725 /* This grid is "torch lit" */
2726 cave_lite_hack(y, x);
2733 /*** Complete the algorithm ***/
2735 /* Draw the new grids */
2736 for (i = 0; i < lite_n; i++)
2741 c_ptr = &cave[y][x];
2743 /* Update fresh grids */
2744 if (c_ptr->info & (CAVE_TEMP)) continue;
2746 /* Add it to later visual update */
2747 cave_note_and_redraw_later(c_ptr, y, x);
2750 /* Clear them all */
2751 for (i = 0; i < temp_n; i++)
2756 c_ptr = &cave[y][x];
2758 /* No longer in the array */
2759 c_ptr->info &= ~(CAVE_TEMP);
2761 /* Update stale grids */
2762 if (c_ptr->info & (CAVE_LITE)) continue;
2764 /* Add it to later visual update */
2765 cave_redraw_later(c_ptr, y, x);
2771 /* Mega-Hack -- Visual update later */
2772 p_ptr->update |= (PU_DELAY_VIS);
2776 static bool mon_invis;
2777 static POSITION mon_fy, mon_fx;
2780 * Add a square to the changes array
2782 static void mon_lite_hack(POSITION y, POSITION x)
2788 /* We trust this grid is in bounds */
2789 /* if (!in_bounds2(y, x)) return; */
2791 c_ptr = &cave[y][x];
2793 /* Want a unlit square in view of the player */
2794 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
2796 if (!cave_los_grid(c_ptr))
2798 /* Hack -- Prevent monster lite leakage in walls */
2800 /* Horizontal walls between player and a monster */
2801 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2803 dpf = p_ptr->y - mon_fy;
2805 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2807 /* Only first wall viewed from mid-x is lit */
2810 if (!cave_los_bold(y, x + 1)) return;
2812 else if (x > midpoint)
2814 if (!cave_los_bold(y, x - 1)) return;
2817 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2818 else if (mon_invis) return;
2821 /* Vertical walls between player and a monster */
2822 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2824 dpf = p_ptr->x - mon_fx;
2826 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2828 /* Only first wall viewed from mid-y is lit */
2831 if (!cave_los_bold(y + 1, x)) return;
2833 else if (y > midpoint)
2835 if (!cave_los_bold(y - 1, x)) return;
2838 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2839 else if (mon_invis) return;
2843 /* We trust temp_n does not exceed TEMP_MAX */
2846 if (!(c_ptr->info & CAVE_MNDK))
2848 /* Save this square */
2857 /* No longer dark */
2858 c_ptr->info &= ~(CAVE_MNDK);
2862 c_ptr->info |= CAVE_MNLT;
2867 * Add a square to the changes array
2869 static void mon_dark_hack(POSITION y, POSITION x)
2872 int midpoint, dpf, d;
2874 /* We trust this grid is in bounds */
2875 /* if (!in_bounds2(y, x)) return; */
2877 c_ptr = &cave[y][x];
2879 /* Want a unlit and undarkened square in view of the player */
2880 if ((c_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
2882 if (!cave_los_grid(c_ptr) && !cave_have_flag_grid(c_ptr, FF_PROJECT))
2884 /* Hack -- Prevent monster dark lite leakage in walls */
2886 /* Horizontal walls between player and a monster */
2887 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2889 dpf = p_ptr->y - mon_fy;
2891 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2893 /* Only first wall viewed from mid-x is lit */
2896 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
2898 else if (x > midpoint)
2900 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
2903 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2904 else if (mon_invis) return;
2907 /* Vertical walls between player and a monster */
2908 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2910 dpf = p_ptr->x - mon_fx;
2912 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2914 /* Only first wall viewed from mid-y is lit */
2917 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
2919 else if (y > midpoint)
2921 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
2924 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2925 else if (mon_invis) return;
2929 /* We trust temp_n does not exceed TEMP_MAX */
2931 /* Save this square */
2937 c_ptr->info |= CAVE_MNDK;
2942 * Update squares illuminated or darkened by monsters.
2944 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
2945 * denote squares illuminated by monsters.
2947 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
2948 * updating. Only squares in view of the player, whos state
2949 * changes are drawn via lite_spot().
2951 void update_mon_lite(void)
2957 void (*add_mon_lite)(POSITION, POSITION);
2962 /* Non-Ninja player in the darkness */
2963 int dis_lim = ((d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
2964 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
2966 /* Clear all monster lit squares */
2967 for (i = 0; i < mon_lite_n; i++)
2970 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
2972 /* Set temp or xtra flag */
2973 c_ptr->info |= (c_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
2975 /* Clear monster illumination flag */
2976 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
2979 /* Empty temp list of new squares to lite up */
2982 /* If a monster stops time, don't process */
2985 monster_type *m_ptr;
2986 monster_race *r_ptr;
2988 /* Loop through monsters, adding newly lit squares to changes list */
2989 for (i = 1; i < m_max; i++)
2992 r_ptr = &r_info[m_ptr->r_idx];
2994 /* Skip dead monsters */
2995 if (!m_ptr->r_idx) continue;
2997 /* Is it too far away? */
2998 if (m_ptr->cdis > dis_lim) continue;
3000 /* Get lite radius */
3003 /* Note the radii are cumulative */
3004 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3005 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3006 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3007 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3009 /* Exit if has no light */
3013 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3014 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3015 add_mon_lite = mon_lite_hack;
3020 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && !is_daytime()))) continue;
3021 add_mon_lite = mon_dark_hack;
3022 f_flag = FF_PROJECT;
3023 rad = -rad; /* Use absolute value */
3026 /* Access the location */
3030 /* Is the monster visible? */
3031 mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
3033 /* The square it is on */
3034 add_mon_lite(mon_fy, mon_fx);
3036 /* Adjacent squares */
3037 add_mon_lite(mon_fy + 1, mon_fx);
3038 add_mon_lite(mon_fy - 1, mon_fx);
3039 add_mon_lite(mon_fy, mon_fx + 1);
3040 add_mon_lite(mon_fy, mon_fx - 1);
3041 add_mon_lite(mon_fy + 1, mon_fx + 1);
3042 add_mon_lite(mon_fy + 1, mon_fx - 1);
3043 add_mon_lite(mon_fy - 1, mon_fx + 1);
3044 add_mon_lite(mon_fy - 1, mon_fx - 1);
3049 /* South of the monster */
3050 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
3052 add_mon_lite(mon_fy + 2, mon_fx + 1);
3053 add_mon_lite(mon_fy + 2, mon_fx);
3054 add_mon_lite(mon_fy + 2, mon_fx - 1);
3056 c_ptr = &cave[mon_fy + 2][mon_fx];
3059 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3061 add_mon_lite(mon_fy + 3, mon_fx + 1);
3062 add_mon_lite(mon_fy + 3, mon_fx);
3063 add_mon_lite(mon_fy + 3, mon_fx - 1);
3067 /* North of the monster */
3068 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
3070 add_mon_lite(mon_fy - 2, mon_fx + 1);
3071 add_mon_lite(mon_fy - 2, mon_fx);
3072 add_mon_lite(mon_fy - 2, mon_fx - 1);
3074 c_ptr = &cave[mon_fy - 2][mon_fx];
3077 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3079 add_mon_lite(mon_fy - 3, mon_fx + 1);
3080 add_mon_lite(mon_fy - 3, mon_fx);
3081 add_mon_lite(mon_fy - 3, mon_fx - 1);
3085 /* East of the monster */
3086 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
3088 add_mon_lite(mon_fy + 1, mon_fx + 2);
3089 add_mon_lite(mon_fy, mon_fx + 2);
3090 add_mon_lite(mon_fy - 1, mon_fx + 2);
3092 c_ptr = &cave[mon_fy][mon_fx + 2];
3095 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3097 add_mon_lite(mon_fy + 1, mon_fx + 3);
3098 add_mon_lite(mon_fy, mon_fx + 3);
3099 add_mon_lite(mon_fy - 1, mon_fx + 3);
3103 /* West of the monster */
3104 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
3106 add_mon_lite(mon_fy + 1, mon_fx - 2);
3107 add_mon_lite(mon_fy, mon_fx - 2);
3108 add_mon_lite(mon_fy - 1, mon_fx - 2);
3110 c_ptr = &cave[mon_fy][mon_fx - 2];
3113 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3115 add_mon_lite(mon_fy + 1, mon_fx - 3);
3116 add_mon_lite(mon_fy, mon_fx - 3);
3117 add_mon_lite(mon_fy - 1, mon_fx - 3);
3125 /* South-East of the monster */
3126 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
3128 add_mon_lite(mon_fy + 2, mon_fx + 2);
3131 /* South-West of the monster */
3132 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
3134 add_mon_lite(mon_fy + 2, mon_fx - 2);
3137 /* North-East of the monster */
3138 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
3140 add_mon_lite(mon_fy - 2, mon_fx + 2);
3143 /* North-West of the monster */
3144 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
3146 add_mon_lite(mon_fy - 2, mon_fx - 2);
3152 /* Save end of list of new squares */
3156 * Look at old set flags to see if there are any changes.
3158 for (i = 0; i < mon_lite_n; i++)
3163 /* We trust this grid is in bounds */
3166 c_ptr = &cave[fy][fx];
3168 if (c_ptr->info & CAVE_TEMP) /* Pervious lit */
3170 /* It it no longer lit? */
3171 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3173 /* It is now unlit */
3174 /* Add it to later visual update */
3175 cave_note_and_redraw_later(c_ptr, fy, fx);
3178 else /* Pervious darkened */
3180 /* It it no longer darken? */
3181 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3183 /* It is now undarken */
3184 /* Add it to later visual update */
3185 cave_note_and_redraw_later(c_ptr, fy, fx);
3189 /* Add to end of temp array */
3190 temp_x[temp_n] = fx;
3191 temp_y[temp_n] = fy;
3195 /* Clear the lite array */
3198 /* Copy the temp array into the lit array lighting the new squares. */
3199 for (i = 0; i < end_temp; i++)
3204 /* We trust this grid is in bounds */
3207 c_ptr = &cave[fy][fx];
3209 if (c_ptr->info & CAVE_MNLT) /* Lit */
3211 /* The is the square newly lit and visible? */
3212 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3215 /* Add it to later visual update */
3216 cave_note_and_redraw_later(c_ptr, fy, fx);
3221 /* The is the square newly darkened and visible? */
3222 if ((c_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3224 /* It is now darkened */
3225 /* Add it to later visual update */
3226 cave_note_and_redraw_later(c_ptr, fy, fx);
3230 /* Save in the monster lit or darkened array */
3231 mon_lite_x[mon_lite_n] = fx;
3232 mon_lite_y[mon_lite_n] = fy;
3236 /* Clear the temp flag for the old lit or darken grids */
3237 for (i = end_temp; i < temp_n; i++)
3239 /* We trust this grid is in bounds */
3241 cave[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3244 /* Finished with temp_n */
3247 /* Mega-Hack -- Visual update later */
3248 p_ptr->update |= (PU_DELAY_VIS);
3250 p_ptr->monlite = (cave[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
3252 if (p_ptr->special_defense & NINJA_S_STEALTH)
3254 if (p_ptr->old_monlite != p_ptr->monlite)
3258 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
3262 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
3266 p_ptr->old_monlite = p_ptr->monlite;
3269 void clear_mon_lite(void)
3274 /* Clear all monster lit squares */
3275 for (i = 0; i < mon_lite_n; i++)
3278 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3280 /* Clear monster illumination flag */
3281 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3284 /* Empty the array */
3291 * Clear the viewable space
3293 void forget_view(void)
3299 /* None to forget */
3300 if (!view_n) return;
3302 /* Clear them all */
3303 for (i = 0; i < view_n; i++)
3305 POSITION y = view_y[i];
3306 POSITION x = view_x[i];
3307 c_ptr = &cave[y][x];
3309 /* Forget that the grid is viewable */
3310 c_ptr->info &= ~(CAVE_VIEW);
3312 /* if (!panel_contains(y, x)) continue; */
3314 /* Update the screen */
3315 /* lite_spot(y, x); Perhaps don't need? */
3325 * This macro allows us to efficiently add a grid to the "view" array,
3326 * note that we are never called for illegal grids, or for grids which
3327 * have already been placed into the "view" array, and we are never
3328 * called when the "view" array is full.
3330 #define cave_view_hack(C,Y,X) \
3332 if (!((C)->info & (CAVE_VIEW))){\
3333 (C)->info |= (CAVE_VIEW); \
3334 view_y[view_n] = (Y); \
3335 view_x[view_n] = (X); \
3342 * Helper function for "update_view()" below
3344 * We are checking the "viewability" of grid (y,x) by the player.
3346 * This function assumes that (y,x) is legal (i.e. on the map).
3348 * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
3349 * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
3351 * Note that we are using the "CAVE_XTRA" field for marking grids as
3352 * "easily viewable". This bit is cleared at the end of "update_view()".
3354 * This function adds (y,x) to the "viewable set" if necessary.
3356 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3358 static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
3360 bool f1, f2, v1, v2, z1, z2, wall;
3364 cave_type *g1_c_ptr;
3365 cave_type *g2_c_ptr;
3367 /* Access the grids */
3368 g1_c_ptr = &cave[y1][x1];
3369 g2_c_ptr = &cave[y2][x2];
3372 /* Check for walls */
3373 f1 = (cave_los_grid(g1_c_ptr));
3374 f2 = (cave_los_grid(g2_c_ptr));
3376 /* Totally blocked by physical walls */
3377 if (!f1 && !f2) return (TRUE);
3380 /* Check for visibility */
3381 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3382 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3384 /* Totally blocked by "unviewable neighbors" */
3385 if (!v1 && !v2) return (TRUE);
3387 c_ptr = &cave[y][x];
3390 /* Check for walls */
3391 wall = (!cave_los_grid(c_ptr));
3394 /* Check the "ease" of visibility */
3395 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3396 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3398 /* Hack -- "easy" plus "easy" yields "easy" */
3401 c_ptr->info |= (CAVE_XTRA);
3403 cave_view_hack(c_ptr, y, x);
3408 /* Hack -- primary "easy" yields "viewed" */
3411 cave_view_hack(c_ptr, y, x);
3416 /* Hack -- "view" plus "view" yields "view" */
3419 /* c_ptr->info |= (CAVE_XTRA); */
3421 cave_view_hack(c_ptr, y, x);
3427 /* Mega-Hack -- the "los()" function works poorly on walls */
3430 cave_view_hack(c_ptr, y, x);
3436 /* Hack -- check line of sight */
3437 if (los(p_ptr->y, p_ptr->x, y, x))
3439 cave_view_hack(c_ptr, y, x);
3445 /* Assume no line of sight. */
3452 * Calculate the viewable space
3454 * 1: Process the player
3455 * 1a: The player is always (easily) viewable
3456 * 2: Process the diagonals
3457 * 2a: The diagonals are (easily) viewable up to the first wall
3458 * 2b: But never go more than 2/3 of the "full" distance
3459 * 3: Process the main axes
3460 * 3a: The main axes are (easily) viewable up to the first wall
3461 * 3b: But never go more than the "full" distance
3462 * 4: Process sequential "strips" in each of the eight octants
3463 * 4a: Each strip runs along the previous strip
3464 * 4b: The main axes are "previous" to the first strip
3465 * 4c: Process both "sides" of each "direction" of each strip
3466 * 4c1: Each side aborts as soon as possible
3467 * 4c2: Each side tells the next strip how far it has to check
3469 * Note that the octant processing involves some pretty interesting
3470 * observations involving when a grid might possibly be viewable from
3471 * a given grid, and on the order in which the strips are processed.
3473 * Note the use of the mathematical facts shown below, which derive
3474 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3475 * hypotenuse of a right triangle is primarily determined by the length
3476 * of the longest side, when one side is small, and is strictly less
3477 * than one-and-a-half times as long as the longest side when both of
3478 * the sides are large.
3480 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3481 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3483 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3485 * These observations are important because the calculation of the actual
3486 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3487 * while for small values (up to about 20 or so), the approximations above
3488 * are correct to within an error of at most one grid or so.
3490 * Observe the use of "full" and "over" in the code below, and the use of
3491 * the specialized calculation involving "limit", all of which derive from
3492 * the observations given above. Basically, we note that the "circle" of
3493 * view is completely contained in an "octagon" whose bounds are easy to
3494 * determine, and that only a few steps are needed to derive the actual
3495 * bounds of the circle given the bounds of the octagon.
3497 * Note that by skipping all the grids in the corners of the octagon, we
3498 * place an upper limit on the number of grids in the field of view, given
3499 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3500 * view, only about 1475 of these are in the "octagon" of view, and even
3501 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3502 * entries to completely contain the actual field of view.
3504 * Note also the care taken to prevent "running off the map". The use of
3505 * explicit checks on the "validity" of the "diagonal", and the fact that
3506 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3507 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
3508 * of multiple checks on the validity of grids.
3510 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3511 * "ws","wn" variables. They work like this: While travelling down the
3512 * south-bound strip just to the east of the main south axis, as soon as
3513 * we get to a grid which does not "transmit" viewing, if all of the strips
3514 * preceding us (in this case, just the main axis) had terminated at or before
3515 * the same point, then we can stop, and reset the "max distance" to ourself.
3516 * So, each strip (named by major axis plus offset, thus "se" in this case)
3517 * maintains a "blockage" variable, initialized during the main axis step,
3518 * and checks it whenever a blockage is observed. After processing each
3519 * strip as far as the previous strip told us to process, the next strip is
3520 * told not to go farther than the current strip's farthest viewable grid,
3521 * unless open space is still available. This uses the "k" variable.
3523 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
3524 * macro is a replacement for "cave_los_bold()" which takes a pointer to
3525 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3526 * chunk of code which adds the given location to the "view" array if it
3527 * is not already there, using both the actual location and a pointer to
3528 * the cave grid. See above.
3530 * By the way, the purpose of this code is to reduce the dependancy on the
3531 * "los()" function which is slow, and, in some cases, not very accurate.
3533 * It is very possible that I am the only person who fully understands this
3534 * function, and for that I am truly sorry, but efficiency was very important
3535 * and the "simple" version of this function was just not fast enough. I am
3536 * more than willing to replace this function with a simpler one, if it is
3537 * equally efficient, and especially willing if the new function happens to
3538 * derive "reverse-line-of-sight" at the same time, since currently monsters
3539 * just use an optimized hack of "you see me, so I see you", and then use the
3540 * actual "projectable()" function to check spell attacks.
3542 void update_view(void)
3547 int se, sw, ne, nw, es, en, ws, wn;
3551 POSITION y_max = cur_hgt - 1;
3552 POSITION x_max = cur_wid - 1;
3556 /*** Initialize ***/
3559 if (view_reduce_view && !dun_level)
3561 /* Full radius (10) */
3562 full = MAX_SIGHT / 2;
3564 /* Octagon factor (15) */
3565 over = MAX_SIGHT * 3 / 4;
3571 /* Full radius (20) */
3574 /* Octagon factor (30) */
3575 over = MAX_SIGHT * 3 / 2;
3579 /*** Step 0 -- Begin ***/
3581 /* Save the old "view" grids for later */
3582 for (n = 0; n < view_n; n++)
3586 c_ptr = &cave[y][x];
3588 /* Mark the grid as not in "view" */
3589 c_ptr->info &= ~(CAVE_VIEW);
3591 /* Mark the grid as "seen" */
3592 c_ptr->info |= (CAVE_TEMP);
3594 /* Add it to the "seen" set */
3600 /* Start over with the "view" array */
3603 /*** Step 1 -- adjacent grids ***/
3605 /* Now start on the player */
3608 c_ptr = &cave[y][x];
3610 /* Assume the player grid is easily viewable */
3611 c_ptr->info |= (CAVE_XTRA);
3613 /* Assume the player grid is viewable */
3614 cave_view_hack(c_ptr, y, x);
3617 /*** Step 2 -- Major Diagonals ***/
3622 /* Scan south-east */
3623 for (d = 1; d <= z; d++)
3625 c_ptr = &cave[y+d][x+d];
3626 c_ptr->info |= (CAVE_XTRA);
3627 cave_view_hack(c_ptr, y+d, x+d);
3628 if (!cave_los_grid(c_ptr)) break;
3631 /* Scan south-west */
3632 for (d = 1; d <= z; d++)
3634 c_ptr = &cave[y+d][x-d];
3635 c_ptr->info |= (CAVE_XTRA);
3636 cave_view_hack(c_ptr, y+d, x-d);
3637 if (!cave_los_grid(c_ptr)) break;
3640 /* Scan north-east */
3641 for (d = 1; d <= z; d++)
3643 c_ptr = &cave[y-d][x+d];
3644 c_ptr->info |= (CAVE_XTRA);
3645 cave_view_hack(c_ptr, y-d, x+d);
3646 if (!cave_los_grid(c_ptr)) break;
3649 /* Scan north-west */
3650 for (d = 1; d <= z; d++)
3652 c_ptr = &cave[y-d][x-d];
3653 c_ptr->info |= (CAVE_XTRA);
3654 cave_view_hack(c_ptr, y-d, x-d);
3655 if (!cave_los_grid(c_ptr)) break;
3659 /*** Step 3 -- major axes ***/
3662 for (d = 1; d <= full; d++)
3664 c_ptr = &cave[y+d][x];
3665 c_ptr->info |= (CAVE_XTRA);
3666 cave_view_hack(c_ptr, y+d, x);
3667 if (!cave_los_grid(c_ptr)) break;
3670 /* Initialize the "south strips" */
3674 for (d = 1; d <= full; d++)
3676 c_ptr = &cave[y-d][x];
3677 c_ptr->info |= (CAVE_XTRA);
3678 cave_view_hack(c_ptr, y-d, x);
3679 if (!cave_los_grid(c_ptr)) break;
3682 /* Initialize the "north strips" */
3686 for (d = 1; d <= full; d++)
3688 c_ptr = &cave[y][x+d];
3689 c_ptr->info |= (CAVE_XTRA);
3690 cave_view_hack(c_ptr, y, x+d);
3691 if (!cave_los_grid(c_ptr)) break;
3694 /* Initialize the "east strips" */
3698 for (d = 1; d <= full; d++)
3700 c_ptr = &cave[y][x-d];
3701 c_ptr->info |= (CAVE_XTRA);
3702 cave_view_hack(c_ptr, y, x-d);
3703 if (!cave_los_grid(c_ptr)) break;
3706 /* Initialize the "west strips" */
3710 /*** Step 4 -- Divide each "octant" into "strips" ***/
3712 /* Now check each "diagonal" (in parallel) */
3713 for (n = 1; n <= over / 2; n++)
3715 int ypn, ymn, xpn, xmn;
3718 /* Acquire the "bounds" of the maximal circle */
3720 if (z > full - n) z = full - n;
3721 while ((z + n + (n>>1)) > full) z--;
3724 /* Access the four diagonal grids */
3734 /* Maximum distance */
3735 m = MIN(z, y_max - ypn);
3738 if ((xpn <= x_max) && (n < se))
3741 for (k = n, d = 1; d <= m; d++)
3743 /* Check grid "d" in strip "n", notice "blockage" */
3744 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3746 if (n + d >= se) break;
3749 /* Track most distant "non-blockage" */
3756 /* Limit the next strip */
3761 if ((xmn >= 0) && (n < sw))
3764 for (k = n, d = 1; d <= m; d++)
3766 /* Check grid "d" in strip "n", notice "blockage" */
3767 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3769 if (n + d >= sw) break;
3772 /* Track most distant "non-blockage" */
3779 /* Limit the next strip */
3788 /* Maximum distance */
3792 if ((xpn <= x_max) && (n < ne))
3795 for (k = n, d = 1; d <= m; d++)
3797 /* Check grid "d" in strip "n", notice "blockage" */
3798 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3800 if (n + d >= ne) break;
3803 /* Track most distant "non-blockage" */
3810 /* Limit the next strip */
3815 if ((xmn >= 0) && (n < nw))
3818 for (k = n, d = 1; d <= m; d++)
3820 /* Check grid "d" in strip "n", notice "blockage" */
3821 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
3823 if (n + d >= nw) break;
3826 /* Track most distant "non-blockage" */
3833 /* Limit the next strip */
3842 /* Maximum distance */
3843 m = MIN(z, x_max - xpn);
3846 if ((ypn <= x_max) && (n < es))
3849 for (k = n, d = 1; d <= m; d++)
3851 /* Check grid "d" in strip "n", notice "blockage" */
3852 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
3854 if (n + d >= es) break;
3857 /* Track most distant "non-blockage" */
3864 /* Limit the next strip */
3869 if ((ymn >= 0) && (n < en))
3872 for (k = n, d = 1; d <= m; d++)
3874 /* Check grid "d" in strip "n", notice "blockage" */
3875 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
3877 if (n + d >= en) break;
3880 /* Track most distant "non-blockage" */
3887 /* Limit the next strip */
3896 /* Maximum distance */
3900 if ((ypn <= y_max) && (n < ws))
3903 for (k = n, d = 1; d <= m; d++)
3905 /* Check grid "d" in strip "n", notice "blockage" */
3906 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
3908 if (n + d >= ws) break;
3911 /* Track most distant "non-blockage" */
3918 /* Limit the next strip */
3923 if ((ymn >= 0) && (n < wn))
3926 for (k = n, d = 1; d <= m; d++)
3928 /* Check grid "d" in strip "n", notice "blockage" */
3929 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
3931 if (n + d >= wn) break;
3934 /* Track most distant "non-blockage" */
3941 /* Limit the next strip */
3948 /*** Step 5 -- Complete the algorithm ***/
3950 /* Update all the new grids */
3951 for (n = 0; n < view_n; n++)
3955 c_ptr = &cave[y][x];
3957 /* Clear the "CAVE_XTRA" flag */
3958 c_ptr->info &= ~(CAVE_XTRA);
3960 /* Update only newly viewed grids */
3961 if (c_ptr->info & (CAVE_TEMP)) continue;
3963 /* Add it to later visual update */
3964 cave_note_and_redraw_later(c_ptr, y, x);
3967 /* Wipe the old grids, update as needed */
3968 for (n = 0; n < temp_n; n++)
3972 c_ptr = &cave[y][x];
3974 /* No longer in the array */
3975 c_ptr->info &= ~(CAVE_TEMP);
3977 /* Update only non-viewable grids */
3978 if (c_ptr->info & (CAVE_VIEW)) continue;
3980 /* Add it to later visual update */
3981 cave_redraw_later(c_ptr, y, x);
3987 /* Mega-Hack -- Visual update later */
3988 p_ptr->update |= (PU_DELAY_VIS);
3993 * Mega-Hack -- Delayed visual update
3994 * Only used if update_view(), update_lite() or update_mon_lite() was called
3996 void delayed_visual_update(void)
4001 /* Update needed grids */
4002 for (i = 0; i < redraw_n; i++)
4006 c_ptr = &cave[y][x];
4008 /* Update only needed grids (prevent multiple updating) */
4009 if (!(c_ptr->info & CAVE_REDRAW)) continue;
4011 /* If required, note */
4012 if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
4016 /* Hack -- Visual update of monster on this grid */
4017 if (c_ptr->m_idx) update_monster(c_ptr->m_idx, FALSE);
4019 /* No longer in the array */
4020 c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4029 * Hack -- forget the "flow" information
4031 void forget_flow(void)
4035 /* Check the entire dungeon */
4036 for (y = 0; y < cur_hgt; y++)
4038 for (x = 0; x < cur_wid; x++)
4040 /* Forget the old data */
4041 cave[y][x].dist = 0;
4042 cave[y][x].cost = 0;
4043 cave[y][x].when = 0;
4050 * Hack - speed up the update_flow algorithm by only doing
4051 * it everytime the player moves out of LOS of the last
4054 static POSITION flow_x = 0;
4055 static POSITION flow_y = 0;
4060 * Hack -- fill in the "cost" field of every grid that the player
4061 * can "reach" with the number of steps needed to reach that grid.
4062 * This also yields the "distance" of the player from every grid.
4064 * In addition, mark the "when" of the grids that can reach
4065 * the player with the incremented value of "flow_n".
4067 * Hack -- use the "seen" array as a "circular queue".
4069 * We do not need a priority queue because the cost from grid
4070 * to grid is always "one" and we process them in order.
4072 void update_flow(void)
4078 /* Paranoia -- make sure the array is empty */
4081 /* The last way-point is on the map */
4082 if (running && in_bounds(flow_y, flow_x))
4084 /* The way point is in sight - do not update. (Speedup) */
4085 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4088 /* Erase all of the current flow information */
4089 for (y = 0; y < cur_hgt; y++)
4091 for (x = 0; x < cur_wid; x++)
4093 cave[y][x].cost = 0;
4094 cave[y][x].dist = 0;
4098 /* Save player position */
4102 /* Add the player's grid to the queue */
4103 temp_y[0] = p_ptr->y;
4104 temp_x[0] = p_ptr->x;
4106 /* Now process the queue */
4107 while (flow_head != flow_tail)
4111 /* Extract the next entry */
4112 ty = temp_y[flow_tail];
4113 tx = temp_x[flow_tail];
4115 /* Forget that entry */
4116 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4118 /* Add the "children" */
4119 for (d = 0; d < 8; d++)
4121 int old_head = flow_head;
4122 byte_hack m = cave[ty][tx].cost + 1;
4123 byte_hack n = cave[ty][tx].dist + 1;
4126 /* Child location */
4127 y = ty + ddy_ddd[d];
4128 x = tx + ddx_ddd[d];
4130 /* Ignore player's grid */
4131 if (player_bold(y, x)) continue;
4133 c_ptr = &cave[y][x];
4135 if (is_closed_door(c_ptr->feat)) m += 3;
4137 /* Ignore "pre-stamped" entries */
4138 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4140 /* Ignore "walls" and "rubble" */
4141 if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4143 /* Save the flow cost */
4144 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4145 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4147 /* Hack -- limit flow depth */
4148 if (n == MONSTER_FLOW_DEPTH) continue;
4150 /* Enqueue that entry */
4151 temp_y[flow_head] = y;
4152 temp_x[flow_head] = x;
4154 /* Advance the queue */
4155 if (++flow_head == TEMP_MAX) flow_head = 0;
4157 /* Hack -- notice overflow by forgetting new entry */
4158 if (flow_head == flow_tail) flow_head = old_head;
4164 static int scent_when = 0;
4167 * Characters leave scent trails for perceptive monsters to track.
4169 * Smell is rather more limited than sound. Many creatures cannot use
4170 * it at all, it doesn't extend very far outwards from the character's
4171 * current position, and monsters can use it to home in the character,
4172 * but not to run away from him.
4174 * Smell is valued according to age. When a character takes his turn,
4175 * scent is aged by one, and new scent of the current age is laid down.
4176 * Speedy characters leave more scent, true, but it also ages faster,
4177 * which makes it harder to hunt them down.
4179 * Whenever the age count loops, most of the scent trail is erased and
4180 * the age of the remainder is recalculated.
4182 void update_smell(void)
4187 /* Create a table that controls the spread of scent */
4188 const int scent_adjust[5][5] =
4197 /* Loop the age and adjust scent values when necessary */
4198 if (++scent_when == 254)
4200 /* Scan the entire dungeon */
4201 for (y = 0; y < cur_hgt; y++)
4203 for (x = 0; x < cur_wid; x++)
4205 int w = cave[y][x].when;
4206 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4215 /* Lay down new scent */
4216 for (i = 0; i < 5; i++)
4218 for (j = 0; j < 5; j++)
4222 /* Translate table to map grids */
4223 y = i + p_ptr->y - 2;
4224 x = j + p_ptr->x - 2;
4227 if (!in_bounds(y, x)) continue;
4229 c_ptr = &cave[y][x];
4231 /* Walls, water, and lava cannot hold scent. */
4232 if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4234 /* Grid must not be blocked by walls from the character */
4235 if (!player_has_los_bold(y, x)) continue;
4237 /* Note grids that are too far away */
4238 if (scent_adjust[i][j] == -1) continue;
4240 /* Mark the grid with new scent */
4241 c_ptr->when = scent_when + scent_adjust[i][j];
4248 * Hack -- map the current panel (plus some) ala "magic mapping"
4250 void map_area(POSITION range)
4256 feature_type *f_ptr;
4258 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4260 /* Scan that area */
4261 for (y = 1; y < cur_hgt - 1; y++)
4263 for (x = 1; x < cur_wid - 1; x++)
4265 if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
4267 c_ptr = &cave[y][x];
4269 /* Memorize terrain of the grid */
4270 c_ptr->info |= (CAVE_KNOWN);
4272 /* Feature code (applying "mimic" field) */
4273 feat = get_feat_mimic(c_ptr);
4274 f_ptr = &f_info[feat];
4276 /* All non-walls are "checked" */
4277 if (!have_flag(f_ptr->flags, FF_WALL))
4279 /* Memorize normal features */
4280 if (have_flag(f_ptr->flags, FF_REMEMBER))
4282 /* Memorize the object */
4283 c_ptr->info |= (CAVE_MARK);
4286 /* Memorize known walls */
4287 for (i = 0; i < 8; i++)
4289 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4291 /* Feature code (applying "mimic" field) */
4292 feat = get_feat_mimic(c_ptr);
4293 f_ptr = &f_info[feat];
4295 /* Memorize walls (etc) */
4296 if (have_flag(f_ptr->flags, FF_REMEMBER))
4298 /* Memorize the walls */
4299 c_ptr->info |= (CAVE_MARK);
4306 p_ptr->redraw |= (PR_MAP);
4308 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4314 * Light up the dungeon using "clairvoyance"
4316 * This function "illuminates" every grid in the dungeon, memorizes all
4317 * "objects", memorizes all grids as with magic mapping, and, under the
4318 * standard option settings (view_perma_grids but not view_torch_grids)
4319 * memorizes all floor grids too.
4321 * Note that if "view_perma_grids" is not set, we do not memorize floor
4322 * grids, since this would defeat the purpose of "view_perma_grids", not
4323 * that anyone seems to play without this option.
4325 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4326 * since this would prevent the use of "view_torch_grids" as a method to
4327 * keep track of what grids have been observed directly.
4329 void wiz_lite(bool ninja)
4334 feature_type *f_ptr;
4336 /* Memorize objects */
4337 for (i = 1; i < o_max; i++)
4339 object_type *o_ptr = &o_list[i];
4341 /* Skip dead objects */
4342 if (!o_ptr->k_idx) continue;
4344 /* Skip held objects */
4345 if (o_ptr->held_m_idx) continue;
4348 o_ptr->marked |= OM_FOUND;
4351 /* Scan all normal grids */
4352 for (y = 1; y < cur_hgt - 1; y++)
4354 /* Scan all normal grids */
4355 for (x = 1; x < cur_wid - 1; x++)
4357 cave_type *c_ptr = &cave[y][x];
4359 /* Memorize terrain of the grid */
4360 c_ptr->info |= (CAVE_KNOWN);
4362 /* Feature code (applying "mimic" field) */
4363 feat = get_feat_mimic(c_ptr);
4364 f_ptr = &f_info[feat];
4366 /* Process all non-walls */
4367 if (!have_flag(f_ptr->flags, FF_WALL))
4369 /* Scan all neighbors */
4370 for (i = 0; i < 9; i++)
4372 POSITION yy = y + ddy_ddd[i];
4373 POSITION xx = x + ddx_ddd[i];
4376 c_ptr = &cave[yy][xx];
4378 /* Feature code (applying "mimic" field) */
4379 f_ptr = &f_info[get_feat_mimic(c_ptr)];
4381 /* Perma-lite the grid */
4382 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS) && !ninja)
4384 c_ptr->info |= (CAVE_GLOW);
4387 /* Memorize normal features */
4388 if (have_flag(f_ptr->flags, FF_REMEMBER))
4390 /* Memorize the grid */
4391 c_ptr->info |= (CAVE_MARK);
4394 /* Perma-lit grids (newly and previously) */
4395 else if (c_ptr->info & CAVE_GLOW)
4397 /* Normally, memorize floors (see above) */
4398 if (view_perma_grids && !view_torch_grids)
4400 /* Memorize the grid */
4401 c_ptr->info |= (CAVE_MARK);
4409 p_ptr->update |= (PU_MONSTERS);
4410 p_ptr->redraw |= (PR_MAP);
4411 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4413 if (p_ptr->special_defense & NINJA_S_STEALTH)
4415 if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
4421 * Forget the dungeon map (ala "Thinking of Maud...").
4428 /* Forget every grid */
4429 for (y = 1; y < cur_hgt - 1; y++)
4431 for (x = 1; x < cur_wid - 1; x++)
4433 cave_type *c_ptr = &cave[y][x];
4435 /* Process the grid */
4436 c_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT | CAVE_KNOWN);
4437 c_ptr->info |= (CAVE_UNSAFE);
4441 /* Forget every grid on horizontal edge */
4442 for (x = 0; x < cur_wid; x++)
4444 cave[0][x].info &= ~(CAVE_MARK);
4445 cave[cur_hgt - 1][x].info &= ~(CAVE_MARK);
4448 /* Forget every grid on vertical edge */
4449 for (y = 1; y < (cur_hgt - 1); y++)
4451 cave[y][0].info &= ~(CAVE_MARK);
4452 cave[y][cur_wid - 1].info &= ~(CAVE_MARK);
4455 /* Forget all objects */
4456 for (i = 1; i < o_max; i++)
4458 object_type *o_ptr = &o_list[i];
4460 /* Skip dead objects */
4461 if (!o_ptr->k_idx) continue;
4463 /* Skip held objects */
4464 if (o_ptr->held_m_idx) continue;
4466 /* Forget the object */
4467 o_ptr->marked &= OM_TOUCHED;
4470 /* Forget travel route when we have forgotten map */
4471 forget_travel_flow();
4473 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4474 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4475 p_ptr->update |= (PU_MONSTERS);
4476 p_ptr->redraw |= (PR_MAP);
4477 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4481 * Change the "feat" flag for a grid, and notice/redraw the grid
4483 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
4485 cave_type *c_ptr = &cave[y][x];
4486 feature_type *f_ptr = &f_info[feat];
4487 bool old_los, old_mirror;
4489 if (!character_dungeon)
4491 /* Clear mimic type */
4494 /* Change the feature */
4497 /* Hack -- glow the GLOW terrain */
4498 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4503 for (i = 0; i < 9; i++)
4505 yy = y + ddy_ddd[i];
4506 xx = x + ddx_ddd[i];
4507 if (!in_bounds2(yy, xx)) continue;
4508 cave[yy][xx].info |= CAVE_GLOW;
4515 old_los = cave_have_flag_bold(y, x, FF_LOS);
4516 old_mirror = is_mirror_grid(c_ptr);
4518 /* Clear mimic type */
4521 /* Change the feature */
4524 /* Remove flag for mirror/glyph */
4525 c_ptr->info &= ~(CAVE_OBJECT);
4527 if (old_mirror && (d_info[dungeon_type].flags1 & DF1_DARKNESS))
4529 c_ptr->info &= ~(CAVE_GLOW);
4530 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4532 update_local_illumination(y, x);
4535 /* Check for change to boring grid */
4536 if (!have_flag(f_ptr->flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
4537 if (c_ptr->m_idx) update_monster(c_ptr->m_idx, FALSE);
4543 /* Check if los has changed */
4544 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
4547 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
4549 update_local_illumination(y, x);
4551 #endif /* COMPLEX_WALL_ILLUMINATION */
4553 /* Update the visuals */
4554 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
4557 /* Hack -- glow the GLOW terrain */
4558 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4564 for (i = 0; i < 9; i++)
4566 yy = y + ddy_ddd[i];
4567 xx = x + ddx_ddd[i];
4568 if (!in_bounds2(yy, xx)) continue;
4569 cc_ptr = &cave[yy][xx];
4570 cc_ptr->info |= CAVE_GLOW;
4572 if (player_has_los_grid(cc_ptr))
4574 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
4581 update_local_illumination(yy, xx);
4584 if (p_ptr->special_defense & NINJA_S_STEALTH)
4586 if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
4592 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
4594 feature_type *f_ptr = &f_info[newfeat];
4596 if (have_flag(f_ptr->flags, FF_CONVERT))
4598 switch (f_ptr->subtype)
4600 case CONVERT_TYPE_FLOOR:
4601 return floor_type[randint0(100)];
4602 case CONVERT_TYPE_WALL:
4603 return fill_type[randint0(100)];
4604 case CONVERT_TYPE_INNER:
4605 return feat_wall_inner;
4606 case CONVERT_TYPE_OUTER:
4607 return feat_wall_outer;
4608 case CONVERT_TYPE_SOLID:
4609 return feat_wall_solid;
4610 case CONVERT_TYPE_STREAM1:
4611 return d_info[dungeon_type].stream1;
4612 case CONVERT_TYPE_STREAM2:
4613 return d_info[dungeon_type].stream2;
4618 else return newfeat;
4623 * Take a feature, determine what that feature becomes
4624 * through applying the given action.
4626 FEAT_IDX feat_state(FEAT_IDX feat, int action)
4628 feature_type *f_ptr = &f_info[feat];
4631 /* Get the new feature */
4632 for (i = 0; i < MAX_FEAT_STATES; i++)
4634 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
4637 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
4639 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
4643 * Takes a location and action and changes the feature at that
4644 * location through applying the given action.
4646 void cave_alter_feat(POSITION y, POSITION x, int action)
4648 /* Set old feature */
4649 FEAT_IDX oldfeat = cave[y][x].feat;
4651 /* Get the new feat */
4652 FEAT_IDX newfeat = feat_state(oldfeat, action);
4655 if (newfeat == oldfeat) return;
4657 /* Set the new feature */
4658 cave_set_feat(y, x, newfeat);
4660 if (!(feature_action_flags[action] & FAF_NO_DROP))
4662 feature_type *old_f_ptr = &f_info[oldfeat];
4663 feature_type *f_ptr = &f_info[newfeat];
4667 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
4669 /* Place some gold */
4675 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - dun_level / 2)))
4678 place_object(y, x, 0L);
4682 if (found && character_dungeon && player_can_see_bold(y, x))
4684 msg_print(_("何かを発見した!", "You have found something!"));
4688 if (feature_action_flags[action] & FAF_CRASH_GLASS)
4690 feature_type *old_f_ptr = &f_info[oldfeat];
4692 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
4694 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(dun_level, 100) / 4, GF_SHARDS,
4695 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
4701 /* Remove a mirror */
4702 void remove_mirror(POSITION y, POSITION x)
4704 cave_type *c_ptr = &cave[y][x];
4706 /* Remove the mirror */
4707 c_ptr->info &= ~(CAVE_OBJECT);
4710 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4712 c_ptr->info &= ~(CAVE_GLOW);
4713 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4714 if (c_ptr->m_idx) update_monster(c_ptr->m_idx, FALSE);
4716 update_local_illumination(y, x);
4726 * Return TRUE if there is a mirror on the grid.
4728 bool is_mirror_grid(cave_type *c_ptr)
4730 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MIRROR))
4738 * Return TRUE if there is a mirror on the grid.
4740 bool is_glyph_grid(cave_type *c_ptr)
4742 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_GLYPH))
4750 * Return TRUE if there is a mirror on the grid.
4752 bool is_explosive_rune_grid(cave_type *c_ptr)
4754 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MINOR_GLYPH))
4762 * Calculate "incremental motion". Used by project() and shoot().
4763 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4765 void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4767 POSITION dy, dx, dist, shift;
4769 /* Extract the distance travelled */
4770 dy = (*y < y1) ? y1 - *y : *y - y1;
4771 dx = (*x < x1) ? x1 - *x : *x - x1;
4773 /* Number of steps */
4774 dist = (dy > dx) ? dy : dx;
4776 /* We are calculating the next location */
4780 /* Calculate the total distance along each axis */
4781 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4782 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4784 /* Paranoia -- Hack -- no motion */
4785 if (!dy && !dx) return;
4788 /* Move mostly vertically */
4791 /* Extract a shift factor */
4792 shift = (dist * dx + (dy - 1) / 2) / dy;
4794 /* Sometimes move along the minor axis */
4795 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4797 /* Always move along major axis */
4798 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4801 /* Move mostly horizontally */
4804 /* Extract a shift factor */
4805 shift = (dist * dy + (dx - 1) / 2) / dx;
4807 /* Sometimes move along the minor axis */
4808 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4810 /* Always move along major axis */
4811 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4818 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4819 * at the final destination, assuming no monster gets in the way.
4821 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4823 bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4830 /* Check the projection path */
4831 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4833 /* Identical grid */
4834 if (!grid_n) return TRUE;
4837 y = GRID_Y(grid_g[grid_n - 1]);
4838 x = GRID_X(grid_g[grid_n - 1]);
4840 /* May not end in an unrequested grid */
4841 if ((y != y2) || (x != x2)) return (FALSE);
4849 * Standard "find me a location" function
4851 * Obtains a legal location within the given distance of the initial
4852 * location, and with "los()" from the source to destination location.
4854 * This function is often called from inside a loop which searches for
4855 * locations while increasing the "d" distance.
4857 * Currently the "m" parameter is unused.
4859 void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
4863 /* Pick a location */
4866 /* Pick a new location */
4867 ny = rand_spread(y, d);
4868 nx = rand_spread(x, d);
4870 /* Ignore annoying locations */
4871 if (!in_bounds(ny, nx)) continue;
4873 /* Ignore "excessively distant" locations */
4874 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4876 if (mode & PROJECT_LOS)
4878 if(los(y, x, ny, nx)) break;
4882 if(projectable(y, x, ny, nx)) break;
4887 /* Save the location */
4896 * Track a new monster
4898 void health_track(MONSTER_IDX m_idx)
4900 /* Mount monster is already tracked */
4901 if (m_idx && m_idx == p_ptr->riding) return;
4903 /* Track a new guy */
4904 p_ptr->health_who = m_idx;
4906 /* Redraw (later) */
4907 p_ptr->redraw |= (PR_HEALTH);
4913 * Hack -- track the given monster race
4915 void monster_race_track(MONRACE_IDX r_idx)
4917 /* Save this monster ID */
4918 p_ptr->monster_race_idx = r_idx;
4920 p_ptr->window |= (PW_MONSTER);
4926 * Hack -- track the given object kind
4928 void object_kind_track(KIND_OBJECT_IDX k_idx)
4930 /* Save this monster ID */
4931 p_ptr->object_kind_idx = k_idx;
4933 p_ptr->window |= (PW_OBJECT);
4939 * Something has happened to disturb the player.
4941 * The first arg indicates a major disturbance, which affects search.
4943 * The second arg is currently unused, but could induce output flush.
4945 * All disturbance cancels repeated commands, resting, and running.
4947 void disturb(bool stop_search, bool stop_travel)
4951 stop_travel = stop_travel;
4954 /* Cancel auto-commands */
4955 /* command_new = 0; */
4957 /* Cancel repeated commands */
4963 /* Redraw the state (later) */
4964 p_ptr->redraw |= (PR_STATE);
4967 /* Cancel Resting */
4968 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
4971 set_action(ACTION_NONE);
4974 /* Cancel running */
4980 /* Check for new panel if appropriate */
4981 if (center_player && !center_running) verify_panel();
4983 /* Calculate torch radius */
4984 p_ptr->update |= (PU_TORCH);
4986 /* Update monster flow */
4987 p_ptr->update |= (PU_FLOW);
4996 /* Check for new panel if appropriate */
4997 if (center_player && !center_running) verify_panel();
4999 /* Calculate torch radius */
5000 p_ptr->update |= (PU_TORCH);
5004 /* Flush the input if requested */
5005 if (flush_disturb) flush();
5010 * Glow deep lava and building entrances in the floor
5012 void glow_deep_lava_and_bldg(void)
5014 POSITION y, x, yy, xx;
5018 /* Not in the darkness dungeon */
5019 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
5021 for (y = 0; y < cur_hgt; y++)
5023 for (x = 0; x < cur_wid; x++)
5025 c_ptr = &cave[y][x];
5027 /* Feature code (applying "mimic" field) */
5029 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_GLOW))
5031 for (i = 0; i < 9; i++)
5033 yy = y + ddy_ddd[i];
5034 xx = x + ddx_ddd[i];
5035 if (!in_bounds2(yy, xx)) continue;
5036 cave[yy][xx].info |= CAVE_GLOW;
5042 /* Update the view and lite */
5043 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
5045 p_ptr->redraw |= (PR_MAP);
5049 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
5050 * @param m_idx モンスターID
5054 * @return テレポート先として妥当ならばtrue
5056 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
5058 monster_type *m_ptr = &m_list[m_idx];
5059 cave_type *c_ptr = &cave[y][x];
5060 feature_type *f_ptr = &f_info[c_ptr->feat];
5062 /* Require "teleportable" space */
5063 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5065 if (c_ptr->m_idx && (c_ptr->m_idx != m_idx)) return FALSE;
5066 if (player_bold(y, x)) return FALSE;
5068 /* Hack -- no teleport onto glyph of warding */
5069 if (is_glyph_grid(c_ptr)) return FALSE;
5070 if (is_explosive_rune_grid(c_ptr)) return FALSE;
5072 if (!(mode & TELEPORT_PASSIVE))
5074 if (!monster_can_cross_terrain(c_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
5081 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
5085 * @return テレポート先として妥当ならばtrue
5087 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
5089 cave_type *c_ptr = &cave[y][x];
5090 feature_type *f_ptr = &f_info[c_ptr->feat];
5092 /* Require "teleportable" space */
5093 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5095 /* No magical teleporting into vaults and such */
5096 if (!(mode & TELEPORT_NONMAGICAL) && (c_ptr->info & CAVE_ICKY)) return FALSE;
5098 if (c_ptr->m_idx && (c_ptr->m_idx != p_ptr->riding)) return FALSE;
5100 /* don't teleport on a trap. */
5101 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
5103 if (!(mode & TELEPORT_PASSIVE))
5105 if (!player_can_enter(c_ptr->feat, 0)) return FALSE;
5107 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
5109 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
5112 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
5114 /* Always forbid deep lava */
5115 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
5117 /* Forbid shallow lava when the player don't have levitation */
5118 if (!p_ptr->levitation) return FALSE;
5127 * @brief 地形は開くものであって、かつ開かれているかを返す /
5128 * Attempt to open the given chest at the given location
5130 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
5132 bool is_open(FEAT_IDX feat)
5134 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));