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 static byte display_autopick; /*!< 自動拾い状態の設定フラグ */
22 static int match_autopick;
23 static object_type *autopick_obj; /*!< 各種自動拾い処理時に使うオブジェクトポインタ */
24 static int feat_priority; /*!< マップ縮小表示時に表示すべき地形の優先度を保管する */
27 * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
34 POSITION distance (POSITION y1, POSITION x1, POSITION y2, POSITION x2)
36 POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
37 POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
39 /* Squared distance */
40 POSITION target = (dy * dy) + (dx * dx);
42 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
43 POSITION d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
48 if (!dy || !dx) return d;
52 /* Approximate error */
53 err = (target - d * d) / (2 * d);
55 /* No error - we are done */
66 * @brief 地形が罠持ちであるかの判定を行う。 / Return TRUE if the given feature is a trap
68 * @return 罠持ちの地形ならばTRUEを返す。
70 bool is_trap(IDX feat)
72 return have_flag(f_info[feat].flags, FF_TRAP);
76 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
77 * @param c_ptr マス構造体の参照ポインタ
78 * @return 看破済みの罠があるならTRUEを返す。
80 bool is_known_trap(cave_type *c_ptr)
82 if (!c_ptr->mimic && !cave_have_flag_grid(c_ptr, FF_SECRET) &&
83 is_trap(c_ptr->feat)) return TRUE;
89 * @brief 地形が閉じたドアであるかの判定を行う。 / Return TRUE if the given grid is a closed door
91 * @return 閉じたドアのある地形ならばTRUEを返す。
93 bool is_closed_door(IDX feat)
95 feature_type *f_ptr = &f_info[feat];
97 return (have_flag(f_ptr->flags, FF_OPEN) || have_flag(f_ptr->flags, FF_BASH)) &&
98 !have_flag(f_ptr->flags, FF_MOVE);
102 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
103 * @param c_ptr マス構造体の参照ポインタ
104 * @return 隠されたドアがあるならTRUEを返す。
106 bool is_hidden_door(cave_type *c_ptr)
108 if ((c_ptr->mimic || cave_have_flag_grid(c_ptr, FF_SECRET)) &&
109 is_closed_door(c_ptr->feat))
116 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
121 * @return LOSが通っているならTRUEを返す。
123 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
124 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
126 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
128 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
129 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
130 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
132 * We assume that the "mathematical corner" of a non-floor tile does not\n
133 * block line of sight.\n
135 * Because this function uses (short) ints for all calculations, overflow may\n
136 * occur if dx and dy exceed 90.\n
138 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
139 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
140 * we can use integer arithmetic.\n
142 * We travel from start to finish along the longer axis, starting at the border\n
143 * between the first and second tiles, where the y offset = .5 * slope, taking\n
144 * into account the scale factor. See below.\n
146 * Also note that this function and the "move towards target" code do NOT\n
147 * share the same properties. Thus, you can see someone, target them, and\n
148 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
149 * by clever choice of target locations, you can sometimes throw a "curve".\n
151 * Note that "line of sight" is not "reflexive" in all cases.\n
153 * Use the "projectable()" routine to test "spell/missile line of sight".\n
155 * Use the "update_view()" function to determine player line-of-sight.\n
157 bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
177 /* Slope, or 1/Slope, of LOS */
181 /* Extract the offset */
185 /* Extract the absolute offset */
190 /* Handle adjacent (or identical) grids */
191 if ((ax < 2) && (ay < 2)) return TRUE;
194 /* Paranoia -- require "safe" origin */
195 /* if (!in_bounds(y1, x1)) return FALSE; */
196 /* if (!in_bounds(y2, x2)) return FALSE; */
199 /* Directly South/North */
202 /* South -- check for walls */
205 for (ty = y1 + 1; ty < y2; ty++)
207 if (!cave_los_bold(ty, x1)) return FALSE;
211 /* North -- check for walls */
214 for (ty = y1 - 1; ty > y2; ty--)
216 if (!cave_los_bold(ty, x1)) return FALSE;
224 /* Directly East/West */
227 /* East -- check for walls */
230 for (tx = x1 + 1; tx < x2; tx++)
232 if (!cave_los_bold(y1, tx)) return FALSE;
236 /* West -- check for walls */
239 for (tx = x1 - 1; tx > x2; tx--)
241 if (!cave_los_bold(y1, tx)) return FALSE;
250 /* Extract some signs */
251 sx = (dx < 0) ? -1 : 1;
252 sy = (dy < 0) ? -1 : 1;
255 /* Vertical "knights" */
260 if (cave_los_bold(y1 + sy, x1)) return TRUE;
264 /* Horizontal "knights" */
269 if (cave_los_bold(y1, x1 + sx)) return TRUE;
274 /* Calculate scale factor div 2 */
277 /* Calculate scale factor */
281 /* Travel horizontally */
284 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
290 /* Consider the special case where slope == 1. */
301 /* Note (below) the case (qy == f2), where */
302 /* the LOS exactly meets the corner of a tile. */
305 if (!cave_los_bold(ty, tx)) return FALSE;
316 if (!cave_los_bold(ty, tx)) return FALSE;
329 /* Travel vertically */
332 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
348 /* Note (below) the case (qx == f2), where */
349 /* the LOS exactly meets the corner of a tile. */
352 if (!cave_los_bold(ty, tx)) return FALSE;
363 if (!cave_los_bold(ty, tx)) return FALSE;
380 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
384 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
387 * @return 指定された座標に照明がかかっているならTRUEを返す。。
389 static bool check_local_illumination(int y, int x)
391 /* Hack -- move towards player */
392 int yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
393 int xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
395 /* Check for "local" illumination */
397 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
399 /* Check for "complex" illumination */
400 if ((feat_supports_los(get_feat_mimic(&cave[yy][xx])) &&
401 (cave[yy][xx].info & CAVE_GLOW)) ||
402 (feat_supports_los(get_feat_mimic(&cave[y][xx])) &&
403 (cave[y][xx].info & CAVE_GLOW)) ||
404 (feat_supports_los(get_feat_mimic(&cave[yy][x])) &&
405 (cave[yy][x].info & CAVE_GLOW)))
411 #else /* COMPLEX_WALL_ILLUMINATION */
413 /* Check for "simple" illumination */
414 return (cave[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
416 #endif /* COMPLEX_WALL_ILLUMINATION */
420 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
421 #define update_local_illumination_aux(Y, X) \
423 if (player_has_los_bold((Y), (X))) \
425 /* Update the monster */ \
426 if (cave[(Y)][(X)].m_idx) update_mon(cave[(Y)][(X)].m_idx, FALSE); \
428 /* Notice and redraw */ \
429 note_spot((Y), (X)); \
430 lite_spot((Y), (X)); \
435 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
440 void update_local_illumination(int y, int x)
444 if (!in_bounds(y, x)) return;
446 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
448 if ((y != p_ptr->y) && (x != p_ptr->x))
450 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
451 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
452 update_local_illumination_aux(yy, xx);
453 update_local_illumination_aux(y, xx);
454 update_local_illumination_aux(yy, x);
456 else if (x != p_ptr->x) /* y == p_ptr->y */
458 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
459 for (i = -1; i <= 1; i++)
462 update_local_illumination_aux(yy, xx);
465 update_local_illumination_aux(yy, x);
467 update_local_illumination_aux(yy, x);
469 else if (y != p_ptr->y) /* x == p_ptr->x */
471 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
472 for (i = -1; i <= 1; i++)
475 update_local_illumination_aux(yy, xx);
478 update_local_illumination_aux(y, xx);
480 update_local_illumination_aux(y, xx);
482 else /* Player's grid */
484 for (i = 0; i < 8; i++)
488 update_local_illumination_aux(yy, xx);
492 #else /* COMPLEX_WALL_ILLUMINATION */
494 if ((y != p_ptr->y) && (x != p_ptr->x))
496 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
497 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
498 update_local_illumination_aux(yy, xx);
500 else if (x != p_ptr->x) /* y == p_ptr->y */
502 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
503 for (i = -1; i <= 1; i++)
506 update_local_illumination_aux(yy, xx);
509 else if (y != p_ptr->y) /* x == p_ptr->x */
511 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
512 for (i = -1; i <= 1; i++)
515 update_local_illumination_aux(yy, xx);
518 else /* Player's grid */
520 for (i = 0; i < 8; i++)
524 update_local_illumination_aux(yy, xx);
528 #endif /* COMPLEX_WALL_ILLUMINATION */
533 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
536 * @return 視覚に収められる状態ならTRUEを返す
538 * He must have vision, illumination, and line of sight.\n
540 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
541 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
543 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
544 * that a wall is visible from any direction. That would be odd. Except\n
545 * under wizard light, which might make sense. Thus, for walls, we require\n
546 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
547 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
548 * in line of sight of the player.\n
550 * This extra check is expensive, but it provides a more "correct" semantics.\n
552 * Note that we should not run this check on walls which are "outer walls" of\n
553 * the dungeon, or we will induce a memory fault, but actually verifying all\n
554 * of the locations would be extremely expensive.\n
556 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
557 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
558 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
559 * and the player has more important things on his mind when he is attacking a\n
560 * monster vault. It is annoying, but an extremely important optimization.\n
562 * Note that "glowing walls" are only considered to be "illuminated" if the\n
563 * grid which is next to the wall in the direction of the player is also a\n
564 * "glowing" grid. This prevents the player from being able to "see" the\n
565 * walls of illuminated rooms from a corridor outside the room.\n
567 bool player_can_see_bold(int y, int x)
571 /* Blind players see nothing */
572 if (p_ptr->blind) return FALSE;
574 /* Access the cave grid */
577 /* Note that "torch-lite" yields "illumination" */
578 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
580 /* Require line of sight to the grid */
581 if (!player_has_los_bold(y, x)) return FALSE;
583 /* Noctovision of Ninja */
584 if (p_ptr->see_nocto) return TRUE;
586 /* Require "perma-lite" of the grid */
587 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
589 /* Feature code (applying "mimic" field) */
590 /* Floors are simple */
591 if (feat_supports_los(get_feat_mimic(c_ptr))) return TRUE;
593 /* Check for "local" illumination */
594 return check_local_illumination(y, x);
598 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
599 * @return 視覚に収められていないならTRUEを返す
600 * @details player_can_see_bold()関数の返り値の否定を返している。
604 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
609 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
612 * @return 各種の変更が可能ならTRUEを返す。
614 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
616 bool cave_valid_bold(int y, int x)
618 cave_type *c_ptr = &cave[y][x];
620 s16b 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)
632 o_ptr = &o_list[this_o_idx];
634 /* Acquire next object */
635 next_o_idx = o_ptr->next_o_idx;
637 /* Forbid artifact grids */
638 if (object_is_artifact(o_ptr)) return (FALSE);
649 * 一般的にモンスターシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal monster codes
651 static char image_monster_hack[] = \
652 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
655 * 一般的にオブジェクトシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal object codes
657 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
660 * @brief モンスターの表示を幻覚状態に差し替える / Mega-Hack -- Hallucinatory monster
665 static void image_monster(byte *ap, char *cp)
667 /* Random symbol from set above */
670 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
679 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
680 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
688 * @brief オブジェクトの表示を幻覚状態に差し替える / Hallucinatory object
693 static void image_object(byte *ap, char *cp)
697 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
704 int n = sizeof(image_object_hack) - 1;
706 *cp = image_object_hack[randint0(n)];
715 * @brief オブジェクト&モンスターの表示を幻覚状態に差し替える / Hack -- Random hallucination
720 static void image_random(byte *ap, char *cp)
722 /* Normally, assume monsters */
723 if (randint0(100) < 75)
725 image_monster(ap, cp);
728 /* Otherwise, assume objects */
731 image_object(ap, cp);
736 * 照明の表現を行うための色合いの関係を{暗闇時, 照明時} で定義する /
737 * This array lists the effects of "brightness" on various "base" colours.\n
739 * This is used to do dynamic lighting effects in ascii :-)\n
740 * At the moment, only the various "floor" tiles are affected.\n
742 * The layout of the array is [x][0] = light and [x][1] = dark.\n
744 static byte lighting_colours[16][2] =
747 {TERM_L_DARK, TERM_DARK},
750 {TERM_YELLOW, TERM_SLATE},
753 {TERM_WHITE, TERM_L_DARK},
756 {TERM_L_UMBER, TERM_UMBER},
759 {TERM_RED, TERM_RED},
762 {TERM_L_GREEN, TERM_GREEN},
765 {TERM_BLUE, TERM_BLUE},
768 {TERM_L_UMBER, TERM_RED},
771 {TERM_SLATE, TERM_L_DARK},
774 {TERM_WHITE, TERM_SLATE},
777 {TERM_L_RED, TERM_BLUE},
780 {TERM_YELLOW, TERM_ORANGE},
783 {TERM_L_RED, TERM_L_RED},
786 {TERM_L_GREEN, TERM_GREEN},
789 {TERM_L_BLUE, TERM_L_BLUE},
792 {TERM_L_UMBER, TERM_UMBER}
799 void apply_default_feat_lighting(byte f_attr[F_LIT_MAX], byte f_char[F_LIT_MAX])
801 byte s_attr = f_attr[F_LIT_STANDARD];
802 byte s_char = f_char[F_LIT_STANDARD];
805 if (is_ascii_graphics(s_attr)) /* For ASCII */
807 f_attr[F_LIT_LITE] = lighting_colours[s_attr & 0x0f][0];
808 f_attr[F_LIT_DARK] = lighting_colours[s_attr & 0x0f][1];
809 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_char[i] = s_char;
811 else /* For tile graphics */
813 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_attr[i] = s_attr;
814 f_char[F_LIT_LITE] = s_char + 2;
815 f_char[F_LIT_DARK] = s_char + 1;
821 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
823 #define darkened_grid(C) \
824 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
829 * @brief Mコマンドによる縮小マップの表示を行う / Extract the attr/char to display at the given (legal) map location
831 * Basically, we "paint" the chosen attr/char in several passes, starting\n
832 * with any known "terrain features" (defaulting to darkness), then adding\n
833 * any known "objects", and finally, adding any known "monsters". This\n
834 * is not the fastest method but since most of the calls to this function\n
835 * are made for grids with no monsters or objects, it is fast enough.\n
837 * Note that this function, if used on the grid containing the "player",\n
838 * will return the attr/char of the grid underneath the player, and not\n
839 * the actual player attr/char itself, allowing a lot of optimization\n
840 * in various "display" functions.\n
842 * Note that the "zero" entry in the feature/object/monster arrays are\n
843 * used to provide "special" attr/char codes, with "monster zero" being\n
844 * used for the player attr/char, "object zero" being used for the "stack"\n
845 * attr/char, and "feature zero" being used for the "nothing" attr/char,\n
846 * though this function makes use of only "feature zero".\n
848 * Note that monsters can have some "special" flags, including "ATTR_MULTI",\n
849 * which means their color changes, and "ATTR_CLEAR", which means they take\n
850 * the color of whatever is under them, and "CHAR_CLEAR", which means that\n
851 * they take the symbol of whatever is under them. Technically, the flag\n
852 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when\n
853 * examined, but this flag is currently ignored.\n
855 * Currently, we do nothing with multi-hued objects, because there are\n
856 * not any. If there were, they would have to set "shimmer_objects"\n
857 * when they were created, and then new "shimmer" code in "dungeon.c"\n
858 * would have to be created handle the "shimmer" effect, and the code\n
859 * in "cave.c" would have to be updated to create the shimmer effect.\n
861 * Note the effects of hallucination. Objects always appear as random\n
862 * "objects", monsters as random "monsters", and normal grids occasionally\n
863 * appear as random "monsters" or "objects", but note that these random\n
864 * "monsters" and "objects" are really just "colored ascii symbols".\n
866 * Note that "floors" and "invisible traps" (and "zero" features) are\n
867 * drawn as "floors" using a special check for optimization purposes,\n
868 * and these are the only features which get drawn using the special\n
869 * lighting effects activated by "view_special_lite".\n
871 * Note the use of the "mimic" field in the "terrain feature" processing,\n
872 * which allows any feature to "pretend" to be another feature. This is\n
873 * used to "hide" secret doors, and to make all "doors" appear the same,\n
874 * and all "walls" appear the same, and "hidden" treasure stay hidden.\n
875 * It is possible to use this field to make a feature "look" like a floor,\n
876 * but the "special lighting effects" for floors will not be used.\n
878 * Note the use of the new "terrain feature" information. Note that the\n
879 * assumption that all interesting "objects" and "terrain features" are\n
880 * memorized allows extremely optimized processing below. Note the use\n
881 * of separate flags on objects to mark them as memorized allows a grid\n
882 * to have memorized "terrain" without granting knowledge of any object\n
883 * which may appear in that grid.\n
885 * Note the efficient code used to determine if a "floor" grid is\n
886 * "memorized" or "viewable" by the player, where the test for the\n
887 * grid being "viewable" is based on the facts that (1) the grid\n
888 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in\n
889 * line of sight, and (3) the player must not be blind, and uses the\n
890 * assumption that all torch-lit grids are in line of sight.\n
892 * Note that floors (and invisible traps) are the only grids which are\n
893 * not memorized when seen, so only these grids need to check to see if\n
894 * the grid is "viewable" to the player (if it is not memorized). Since\n
895 * most non-memorized grids are in fact walls, this induces *massive*\n
896 * efficiency, at the cost of *forcing* the memorization of non-floor\n
897 * grids when they are first seen. Note that "invisible traps" are\n
898 * always treated exactly like "floors", which prevents "cheating".\n
900 * Note the "special lighting effects" which can be activated for floor\n
901 * grids using the "view_special_lite" option (for "white" floor grids),\n
902 * causing certain grids to be displayed using special colors. If the\n
903 * player is "blind", we will use "dark gray", else if the grid is lit\n
904 * by the torch, and the "view_yellow_lite" option is set, we will use\n
905 * "yellow", else if the grid is "dark", we will use "dark gray", else\n
906 * if the grid is not "viewable", and the "view_bright_lite" option is\n
907 * set, and the we will use "slate" (gray). We will use "white" for all\n
908 * other cases, in particular, for illuminated viewable floor grids.\n
910 * Note the "special lighting effects" which can be activated for wall\n
911 * grids using the "view_granite_lite" option (for "white" wall grids),\n
912 * causing certain grids to be displayed using special colors. If the\n
913 * player is "blind", we will use "dark gray", else if the grid is lit\n
914 * by the torch, and the "view_yellow_lite" option is set, we will use\n
915 * "yellow", else if the "view_bright_lite" option is set, and the grid\n
916 * is not "viewable", or is "dark", or is glowing, but not when viewed\n
917 * from the player's current location, we will use "slate" (gray). We\n
918 * will use "white" for all other cases, in particular, for correctly\n
919 * illuminated viewable wall grids.\n
921 * Note that, when "view_granite_lite" is set, we use an inline version\n
922 * of the "player_can_see_bold()" function to check the "viewability" of\n
923 * grids when the "view_bright_lite" option is set, and we do NOT use\n
924 * any special colors for "dark" wall grids, since this would allow the\n
925 * player to notice the walls of illuminated rooms from a hallway that\n
926 * happened to run beside the room. The alternative, by the way, would\n
927 * be to prevent the generation of hallways next to rooms, but this\n
928 * would still allow problems when digging towards a room.\n
930 * Note that bizarre things must be done when the "attr" and/or "char"\n
931 * codes have the "high-bit" set, since these values are used to encode\n
932 * various "special" pictures in some versions, and certain situations,\n
933 * such as "multi-hued" or "clear" monsters, cause the attr/char codes\n
934 * to be "scrambled" in various ways.\n
936 * Note that eventually we may use the "&" symbol for embedded treasure,\n
937 * and use the "*" symbol to indicate multiple objects, though this will\n
938 * have to wait for Angband 2.8.0 or later. Note that currently, this\n
939 * is not important, since only one object or terrain feature is allowed\n
940 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.\n
942 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of\n
943 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect\n
944 * then a whole lot of code should be changed... XXX XXX\n
946 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
949 cave_type *c_ptr = &cave[y][x];
951 s16b this_o_idx, next_o_idx = 0;
953 /* Feature code (applying "mimic" field) */
954 s16b feat = get_feat_mimic(c_ptr);
957 feature_type *f_ptr = &f_info[feat];
962 /* Boring grids (floors, etc) */
963 if (!have_flag(f_ptr->flags, FF_REMEMBER))
966 * Handle Memorized or visible floor
968 * No visual when blinded.
969 * (to prevent strange effects on darkness breath)
971 * - Can see grids with CAVE_MARK.
972 * - Can see grids with CAVE_LITE or CAVE_MNLT.
973 * (Such grids also have CAVE_VIEW)
974 * - Can see grids with CAVE_VIEW unless darkened by monsters.
977 ((c_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
978 ((c_ptr->info & CAVE_VIEW) && (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
980 /* Normal attr/char */
981 a = f_ptr->x_attr[F_LIT_STANDARD];
982 c = f_ptr->x_char[F_LIT_STANDARD];
984 if (p_ptr->wild_mode)
986 /* Special lighting effects */
988 if (view_special_lite && !is_daytime())
990 /* Use a darkened colour/tile */
991 a = f_ptr->x_attr[F_LIT_DARK];
992 c = f_ptr->x_char[F_LIT_DARK];
996 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
997 else if (darkened_grid(c_ptr))
999 /* Unsafe cave grid -- idea borrowed from Unangband */
1000 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1002 /* Access darkness */
1003 f_ptr = &f_info[feat];
1005 /* Char and attr of darkness */
1006 a = f_ptr->x_attr[F_LIT_STANDARD];
1007 c = f_ptr->x_char[F_LIT_STANDARD];
1010 /* Special lighting effects */
1011 else if (view_special_lite)
1013 /* Handle "torch-lit" grids */
1014 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1017 if (view_yellow_lite)
1019 /* Use a brightly lit colour/tile */
1020 a = f_ptr->x_attr[F_LIT_LITE];
1021 c = f_ptr->x_char[F_LIT_LITE];
1025 /* Handle "dark" grids */
1026 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1028 /* Use a darkened colour/tile */
1029 a = f_ptr->x_attr[F_LIT_DARK];
1030 c = f_ptr->x_char[F_LIT_DARK];
1033 /* Handle "out-of-sight" grids */
1034 else if (!(c_ptr->info & CAVE_VIEW))
1037 if (view_bright_lite)
1039 /* Use a darkened colour/tile */
1040 a = f_ptr->x_attr[F_LIT_DARK];
1041 c = f_ptr->x_char[F_LIT_DARK];
1050 /* Unsafe cave grid -- idea borrowed from Unangband */
1051 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1053 /* Access darkness */
1054 f_ptr = &f_info[feat];
1056 /* Normal attr/char */
1057 a = f_ptr->x_attr[F_LIT_STANDARD];
1058 c = f_ptr->x_char[F_LIT_STANDARD];
1062 /* Interesting grids (non-floors) */
1065 /* Memorized grids */
1066 if (c_ptr->info & CAVE_MARK)
1068 /* Normal attr/char */
1069 a = f_ptr->x_attr[F_LIT_STANDARD];
1070 c = f_ptr->x_char[F_LIT_STANDARD];
1072 if (p_ptr->wild_mode)
1074 /* Special lighting effects */
1075 /* Handle "blind" or "night" */
1076 if (view_granite_lite && (p_ptr->blind || !is_daytime()))
1078 /* Use a darkened colour/tile */
1079 a = f_ptr->x_attr[F_LIT_DARK];
1080 c = f_ptr->x_char[F_LIT_DARK];
1084 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1085 else if (darkened_grid(c_ptr) && !p_ptr->blind)
1087 if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
1089 /* Unsafe cave grid -- idea borrowed from Unangband */
1090 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1092 /* Access darkness */
1093 f_ptr = &f_info[feat];
1095 /* Char and attr of darkness */
1096 a = f_ptr->x_attr[F_LIT_STANDARD];
1097 c = f_ptr->x_char[F_LIT_STANDARD];
1099 else if (view_granite_lite && view_bright_lite)
1101 /* Use a darkened colour/tile */
1102 a = f_ptr->x_attr[F_LIT_DARK];
1103 c = f_ptr->x_char[F_LIT_DARK];
1107 /* Special lighting effects */
1108 else if (view_granite_lite)
1110 /* Handle "blind" */
1113 /* Use a darkened colour/tile */
1114 a = f_ptr->x_attr[F_LIT_DARK];
1115 c = f_ptr->x_char[F_LIT_DARK];
1118 /* Handle "torch-lit" grids */
1119 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1122 if (view_yellow_lite)
1124 /* Use a brightly lit colour/tile */
1125 a = f_ptr->x_attr[F_LIT_LITE];
1126 c = f_ptr->x_char[F_LIT_LITE];
1130 /* Handle "view_bright_lite" */
1131 else if (view_bright_lite)
1134 if (!(c_ptr->info & CAVE_VIEW))
1136 /* Use a darkened colour/tile */
1137 a = f_ptr->x_attr[F_LIT_DARK];
1138 c = f_ptr->x_char[F_LIT_DARK];
1142 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1144 /* Use a darkened colour/tile */
1145 a = f_ptr->x_attr[F_LIT_DARK];
1146 c = f_ptr->x_char[F_LIT_DARK];
1149 /* Not glowing correctly */
1150 else if (!have_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(y, x))
1152 /* Use a darkened colour/tile */
1153 a = f_ptr->x_attr[F_LIT_DARK];
1154 c = f_ptr->x_char[F_LIT_DARK];
1163 /* Unsafe cave grid -- idea borrowed from Unangband */
1164 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1166 /* Access feature */
1167 f_ptr = &f_info[feat];
1169 /* Normal attr/char */
1170 a = f_ptr->x_attr[F_LIT_STANDARD];
1171 c = f_ptr->x_char[F_LIT_STANDARD];
1175 if (feat_priority == -1) feat_priority = f_ptr->priority;
1177 /* Save the terrain info for the transparency effects */
1185 /* Hack -- rare random hallucination, except on outer dungeon walls */
1191 image_random(ap, cp);
1196 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1200 /* Acquire object */
1201 o_ptr = &o_list[this_o_idx];
1203 /* Acquire next object */
1204 next_o_idx = o_ptr->next_o_idx;
1206 /* Memorized objects */
1207 if (o_ptr->marked & OM_FOUND)
1209 if (display_autopick)
1213 match_autopick = is_autopick(o_ptr);
1214 if(match_autopick == -1)
1217 act = autopick_list[match_autopick].action;
1219 if ((act & DO_DISPLAY) && (act & display_autopick))
1221 autopick_obj = o_ptr;
1225 match_autopick = -1;
1230 (*cp) = object_char(o_ptr);
1233 (*ap) = object_attr(o_ptr);
1237 /* Hack -- hallucination */
1238 if (p_ptr->image) image_object(ap, cp);
1246 /* Handle monsters */
1247 if (c_ptr->m_idx && display_autopick == 0 )
1249 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1251 /* Visible monster */
1254 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1262 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1263 * flags are always unseen.
1265 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1271 /* Hallucinatory monster */
1272 image_monster(ap, cp);
1277 /* Monster attr/char */
1281 /* Normal monsters */
1282 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1283 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1285 /* Desired monster attr/char */
1291 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1292 * flags are always unseen.
1294 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1301 /*** Monster's attr ***/
1302 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1307 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1309 /* Multi-hued attr */
1310 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1311 else switch (randint1(7))
1313 case 1: *ap = TERM_RED; break;
1314 case 2: *ap = TERM_L_RED; break;
1315 case 3: *ap = TERM_WHITE; break;
1316 case 4: *ap = TERM_L_GREEN; break;
1317 case 5: *ap = TERM_BLUE; break;
1318 case 6: *ap = TERM_L_DARK; break;
1319 case 7: *ap = TERM_GREEN; break;
1322 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1324 /* Use semi-random attr (usually mimics' colors vary) */
1325 *ap = c_ptr->m_idx % 15 + 1;
1333 /*** Monster's char ***/
1334 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1339 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1343 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1344 *cp = tmp_r_ptr->x_char;
1345 *ap = tmp_r_ptr->x_attr;
1349 *cp = (one_in_(25) ?
1350 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1351 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1364 /* Handle "player" */
1365 if (player_bold(y, x))
1367 monster_race *r_ptr = &r_info[0];
1369 /* Get the "player" attr */
1370 *ap = r_ptr->x_attr;
1372 /* Get the "player" char */
1373 *cp = r_ptr->x_char;
1381 * Calculate panel colum of a location in the map
1383 static int panel_col_of(int col)
1385 col -= panel_col_min;
1386 if (use_bigtile) col *= 2;
1392 * Moves the cursor to a given MAP (y,x) location
1394 void move_cursor_relative(int row, int col)
1396 /* Real co-ords convert to screen positions */
1397 row -= panel_row_prt;
1400 Term_gotoxy(panel_col_of(col), row);
1406 * Place an attr/char pair at the given map coordinate, if legal.
1408 void print_rel(char c, byte a, int y, int x)
1410 /* Only do "legal" locations */
1411 if (panel_contains(y, x))
1413 /* Hack -- fake monochrome */
1416 if (world_monster) a = TERM_DARK;
1417 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1418 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1421 /* Draw the char using the attr */
1422 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, 0, 0);
1431 * Memorize interesting viewable object/features in the given grid
1433 * This function should only be called on "legal" grids.
1435 * This function will memorize the object and/or feature in the given
1436 * grid, if they are (1) viewable and (2) interesting. Note that all
1437 * objects are interesting, all terrain features except floors (and
1438 * invisible traps) are interesting, and floors (and invisible traps)
1439 * are interesting sometimes (depending on various options involving
1440 * the illumination of floor grids).
1442 * The automatic memorization of all objects and non-floor terrain
1443 * features as soon as they are displayed allows incredible amounts
1444 * of optimization in various places, especially "map_info()".
1446 * Note that the memorization of objects is completely separate from
1447 * the memorization of terrain features, preventing annoying floor
1448 * memorization when a detected object is picked up from a dark floor,
1449 * and object memorization when an object is dropped into a floor grid
1450 * which is memorized but out-of-sight.
1452 * This function should be called every time the "memorization" of
1453 * a grid (or the object in a grid) is called into question, such
1454 * as when an object is created in a grid, when a terrain feature
1455 * "changes" from "floor" to "non-floor", when any grid becomes
1456 * "illuminated" or "viewable", and when a "floor" grid becomes
1459 * Note the relatively efficient use of this function by the various
1460 * "update_view()" and "update_lite()" calls, to allow objects and
1461 * terrain features to be memorized (and drawn) whenever they become
1462 * viewable or illuminated in any way, but not when they "maintain"
1463 * or "lose" their previous viewability or illumination.
1465 * Note the butchered "internal" version of "player_can_see_bold()",
1466 * optimized primarily for the most common cases, that is, for the
1467 * non-marked floor grids.
1469 void note_spot(int y, int x)
1471 cave_type *c_ptr = &cave[y][x];
1473 s16b this_o_idx, next_o_idx = 0;
1476 /* Blind players see nothing */
1477 if (p_ptr->blind) return;
1479 /* Analyze non-torch-lit grids */
1480 if (!(c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1482 /* Require line of sight to the grid */
1483 if (!(c_ptr->info & (CAVE_VIEW))) return;
1485 /* Require "perma-lite" of the grid */
1486 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1489 if (!p_ptr->see_nocto) return;
1494 /* Hack -- memorize objects */
1495 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1497 object_type *o_ptr = &o_list[this_o_idx];
1499 /* Acquire next object */
1500 next_o_idx = o_ptr->next_o_idx;
1502 /* Memorize objects */
1503 o_ptr->marked |= OM_FOUND;
1507 /* Hack -- memorize grids */
1508 if (!(c_ptr->info & (CAVE_MARK)))
1510 /* Feature code (applying "mimic" field) */
1511 feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
1513 /* Memorize some "boring" grids */
1514 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1516 /* Option -- memorize all torch-lit floors */
1517 if (view_torch_grids &&
1518 ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1521 c_ptr->info |= (CAVE_MARK);
1524 /* Option -- memorize all perma-lit floors */
1525 else if (view_perma_grids && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1528 c_ptr->info |= (CAVE_MARK);
1532 /* Memorize normal grids */
1533 else if (have_flag(f_ptr->flags, FF_LOS))
1536 c_ptr->info |= (CAVE_MARK);
1539 /* Memorize torch-lit walls */
1540 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1543 c_ptr->info |= (CAVE_MARK);
1546 /* Memorize walls seen by noctovision of Ninja */
1547 else if (p_ptr->see_nocto)
1550 c_ptr->info |= (CAVE_MARK);
1553 /* Memorize certain non-torch-lit wall grids */
1554 else if (check_local_illumination(y, x))
1557 c_ptr->info |= (CAVE_MARK);
1561 /* Memorize terrain of the grid */
1562 c_ptr->info |= (CAVE_KNOWN);
1566 void display_dungeon(void)
1575 for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
1577 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
1579 if (in_bounds2(y, x))
1582 /* Examine the grid */
1583 map_info(y, x, &a, &c, &ta, &tc);
1585 /* Hack -- fake monochrome */
1588 if (world_monster) a = TERM_DARK;
1589 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1590 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1593 /* Hack -- Queue it */
1594 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1598 /* Clear out-of-bound tiles */
1600 /* Access darkness */
1601 feature_type *f_ptr = &f_info[feat_none];
1604 a = f_ptr->x_attr[F_LIT_STANDARD];
1607 c = f_ptr->x_char[F_LIT_STANDARD];
1609 /* Hack -- Queue it */
1610 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1618 * Redraw (on the screen) a given MAP location
1620 * This function should only be called on "legal" grids
1622 void lite_spot(int y, int x)
1624 /* Redraw if on screen */
1625 if (panel_contains(y, x) && in_bounds2(y, x))
1633 /* Examine the grid */
1634 map_info(y, x, &a, &c, &ta, &tc);
1636 /* Hack -- fake monochrome */
1639 if (world_monster) a = TERM_DARK;
1640 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1641 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1644 /* Hack -- Queue it */
1645 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1647 /* Update sub-windows */
1648 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1654 * Prints the map of the dungeon
1656 * Note that, for efficiency, we contain an "optimized" version
1657 * of both "lite_spot()" and "print_rel()", and that we use the
1658 * "lite_spot()" function to display the player grid, if needed.
1666 s16b xmin, xmax, ymin, ymax;
1671 Term_get_size(&wid, &hgt);
1673 /* Remove map offset */
1677 /* Access the cursor state */
1678 (void)Term_get_cursor(&v);
1680 /* Hide the cursor */
1681 (void)Term_set_cursor(0);
1684 xmin = (0 < panel_col_min) ? panel_col_min : 0;
1685 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1686 ymin = (0 < panel_row_min) ? panel_row_min : 0;
1687 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1689 /* Bottom section of screen */
1690 for (y = 1; y <= ymin - panel_row_prt; y++)
1692 /* Erase the section */
1693 Term_erase(COL_MAP, y, wid);
1696 /* Top section of screen */
1697 for (y = ymax - panel_row_prt; y <= hgt; y++)
1699 /* Erase the section */
1700 Term_erase(COL_MAP, y, wid);
1704 for (y = ymin; y <= ymax; y++)
1706 /* Scan the columns of row "y" */
1707 for (x = xmin; x <= xmax; x++)
1715 /* Determine what is there */
1716 map_info(y, x, &a, &c, &ta, &tc);
1718 /* Hack -- fake monochrome */
1721 if (world_monster) a = TERM_DARK;
1722 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1723 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1726 /* Efficiency -- Redraw that grid of the map */
1727 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1731 /* Display player */
1732 lite_spot(p_ptr->y, p_ptr->x);
1734 /* Restore the cursor */
1735 (void)Term_set_cursor(v);
1741 * print project path
1743 void prt_path(int y, int x)
1748 byte_hack default_color = TERM_SLATE;
1750 if (!display_path) return;
1751 if (-1 == project_length)
1754 /* Get projection path */
1755 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH|PROJECT_THRU);
1758 p_ptr->redraw |= (PR_MAP);
1764 for (i = 0; i < path_n; i++)
1766 int ny = GRID_Y(path_g[i]);
1767 int nx = GRID_X(path_g[i]);
1768 cave_type *c_ptr = &cave[ny][nx];
1770 if (panel_contains(ny, nx))
1772 byte a = default_color;
1778 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1780 /* Determine what is there */
1781 map_info(ny, nx, &a, &c, &ta, &tc);
1783 if (!is_ascii_graphics(a))
1785 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1787 else if (a == default_color)
1793 if (world_monster) a = TERM_DARK;
1794 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1795 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1800 /* Hack -- Queue it */
1801 Term_queue_bigchar(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
1805 if ((c_ptr->info & CAVE_MARK) && !cave_have_flag_grid(c_ptr, FF_PROJECT)) break;
1808 if (nx == x && ny == y) default_color = TERM_L_DARK;
1813 static cptr simplify_list[][2] =
1820 {"^Amulet of ", "\""},
1821 {"^Scroll of ", "?"},
1822 {"^Scroll titled ", "?"},
1823 {"^Wand of " , "-"},
1825 {"^Staff of " , "_"},
1826 {"^Potion of ", "!"},
1838 static void display_shortened_item_name(object_type *o_ptr, int y)
1845 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
1846 attr = tval_to_attr[o_ptr->tval % 128];
1851 strcpy(buf, _("何か奇妙な物", "something strange"));
1854 for (c = buf; *c; c++)
1857 for (i = 0; simplify_list[i][1]; i++)
1859 cptr org_w = simplify_list[i][0];
1869 if (!strncmp(c, org_w, strlen(org_w)))
1872 cptr tmp = simplify_list[i][1];
1875 tmp = c + strlen(org_w);
1891 if(len + 2 > 12) break;
1898 if(len + 1 > 12) break;
1904 Term_putstr(0, y, 12, attr, buf);
1908 * Display a "small-scale" map of the dungeon in the active Term
1910 void display_map(int *cy, int *cx)
1927 /* Save lighting effects */
1928 bool old_view_special_lite = view_special_lite;
1929 bool old_view_granite_lite = view_granite_lite;
1931 int hgt, wid, yrat, xrat;
1933 int **match_autopick_yx;
1934 object_type ***object_autopick_yx;
1937 Term_get_size(&wid, &hgt);
1940 if (use_bigtile) wid /= 2;
1942 yrat = (cur_hgt + hgt - 1) / hgt;
1943 xrat = (cur_wid + wid - 1) / wid;
1945 /* Disable lighting effects */
1946 view_special_lite = FALSE;
1947 view_granite_lite = FALSE;
1949 /* Allocate the maps */
1950 C_MAKE(ma, (hgt + 2), byte_ptr);
1951 C_MAKE(mc, (hgt + 2), char_ptr);
1952 C_MAKE(mp, (hgt + 2), byte_ptr);
1953 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
1954 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
1956 /* Allocate and wipe each line map */
1957 for (y = 0; y < (hgt + 2); y++)
1959 /* Allocate one row each array */
1960 C_MAKE(ma[y], (wid + 2), byte);
1961 C_MAKE(mc[y], (wid + 2), char);
1962 C_MAKE(mp[y], (wid + 2), byte);
1963 C_MAKE(match_autopick_yx[y], (wid + 2), int);
1964 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
1966 for (x = 0; x < wid + 2; ++x)
1968 match_autopick_yx[y][x] = -1;
1969 object_autopick_yx[y][x] = NULL;
1972 ma[y][x] = TERM_WHITE;
1980 /* Allocate the maps */
1981 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
1982 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
1983 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
1985 /* Allocate and wipe each line map */
1986 for (y = 0; y < (cur_hgt + 2); y++)
1988 /* Allocate one row each array */
1989 C_MAKE(bigma[y], (cur_wid + 2), byte);
1990 C_MAKE(bigmc[y], (cur_wid + 2), char);
1991 C_MAKE(bigmp[y], (cur_wid + 2), byte);
1993 for (x = 0; x < cur_wid + 2; ++x)
1996 bigma[y][x] = TERM_WHITE;
2004 /* Fill in the map */
2005 for (i = 0; i < cur_wid; ++i)
2007 for (j = 0; j < cur_hgt; ++j)
2017 /* Extract the current attr/char at that map location */
2018 map_info(j, i, &ta, &tc, &ta, &tc);
2020 /* Extract the priority */
2021 tp = (byte_hack)feat_priority;
2023 if(match_autopick!=-1
2024 && (match_autopick_yx[y][x] == -1
2025 || match_autopick_yx[y][x] > match_autopick))
2027 match_autopick_yx[y][x] = match_autopick;
2028 object_autopick_yx[y][x] = autopick_obj;
2032 /* Save the char, attr and priority */
2033 bigmc[j+1][i+1] = tc;
2034 bigma[j+1][i+1] = ta;
2035 bigmp[j+1][i+1] = tp;
2039 for (j = 0; j < cur_hgt; ++j)
2041 for (i = 0; i < cur_wid; ++i)
2047 tc = bigmc[j+1][i+1];
2048 ta = bigma[j+1][i+1];
2049 tp = bigmp[j+1][i+1];
2051 /* rare feature has more priority */
2057 for (t = 0; t < 8; t++)
2059 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2060 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2070 /* Save the char, attr and priority */
2083 /* Draw the corners */
2084 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2086 /* Draw the horizontal edges */
2087 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2089 /* Draw the vertical edges */
2090 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2093 /* Display each map line in order */
2094 for (y = 0; y < hgt + 2; ++y)
2096 /* Start a new line */
2097 Term_gotoxy(COL_MAP, y);
2099 /* Display the line */
2100 for (x = 0; x < wid + 2; ++x)
2105 /* Hack -- fake monochrome */
2108 if (world_monster) ta = TERM_DARK;
2109 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2110 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2113 /* Add the character */
2114 Term_add_bigch(ta, tc);
2119 for (y = 1; y < hgt + 1; ++y)
2121 match_autopick = -1;
2122 for (x = 1; x <= wid; x++){
2123 if (match_autopick_yx[y][x] != -1 &&
2124 (match_autopick > match_autopick_yx[y][x] ||
2125 match_autopick == -1)){
2126 match_autopick = match_autopick_yx[y][x];
2127 autopick_obj = object_autopick_yx[y][x];
2131 /* Clear old display */
2132 Term_putstr(0, y, 12, 0, " ");
2134 if (match_autopick != -1)
2136 display_shortened_item_name(autopick_obj, y);
2139 char buf[13] = "\0";
2140 strncpy(buf,autopick_list[match_autopick].name,12);
2148 /* Player location */
2149 (*cy) = p_ptr->y / yrat + 1 + ROW_MAP;
2151 (*cx) = p_ptr->x / xrat + 1 + COL_MAP;
2153 (*cx) = (p_ptr->x / xrat + 1) * 2 + COL_MAP;
2155 /* Restore lighting effects */
2156 view_special_lite = old_view_special_lite;
2157 view_granite_lite = old_view_granite_lite;
2159 /* Free each line map */
2160 for (y = 0; y < (hgt + 2); y++)
2162 /* Free one row each array */
2163 C_KILL(ma[y], (wid + 2), byte);
2164 C_KILL(mc[y], (wid + 2), char);
2165 C_KILL(mp[y], (wid + 2), byte);
2166 C_KILL(match_autopick_yx[y], (wid + 2), int);
2167 C_KILL(object_autopick_yx[y], (wid + 2), object_type *);
2170 /* Free each line map */
2171 C_KILL(ma, (hgt + 2), byte_ptr);
2172 C_KILL(mc, (hgt + 2), char_ptr);
2173 C_KILL(mp, (hgt + 2), byte_ptr);
2174 C_KILL(match_autopick_yx, (hgt + 2), sint_ptr);
2175 C_KILL(object_autopick_yx, (hgt + 2), object_type **);
2177 /* Free each line map */
2178 for (y = 0; y < (cur_hgt + 2); y++)
2180 /* Free one row each array */
2181 C_KILL(bigma[y], (cur_wid + 2), byte);
2182 C_KILL(bigmc[y], (cur_wid + 2), char);
2183 C_KILL(bigmp[y], (cur_wid + 2), byte);
2186 /* Free each line map */
2187 C_KILL(bigma, (cur_hgt + 2), byte_ptr);
2188 C_KILL(bigmc, (cur_hgt + 2), char_ptr);
2189 C_KILL(bigmp, (cur_hgt + 2), byte_ptr);
2194 * Display a "small-scale" map of the dungeon for the player
2196 * Currently, the "player" is displayed on the map. XXX XXX XXX
2198 void do_cmd_view_map(void)
2203 /* Save the screen */
2207 prt(_("お待ち下さい...", "Please wait..."), 0, 0);
2212 /* Clear the screen */
2215 display_autopick = 0;
2217 /* Display the map */
2218 display_map(&cy, &cx);
2221 if(max_autopick && !p_ptr->wild_mode)
2223 display_autopick = ITEM_DISPLAY;
2230 int wid, hgt, row_message;
2232 Term_get_size(&wid, &hgt);
2233 row_message = hgt - 1;
2235 put_str(_("何かキーを押してください('M':拾う 'N':放置 'D':M+N 'K':壊すアイテムを表示)",
2236 " Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items."), row_message, 1);
2238 /* Hilite the player */
2239 move_cursor(cy, cx);
2244 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2246 flag = DONT_AUTOPICK;
2248 flag = DO_AUTODESTROY;
2250 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2256 if (~display_autopick & flag)
2257 display_autopick |= flag;
2259 display_autopick &= ~flag;
2260 /* Display the map */
2261 display_map(&cy, &cx);
2264 display_autopick = 0;
2269 put_str(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"), 23, 30);
2270 /* Hilite the player */
2271 move_cursor(cy, cx);
2276 /* Restore the screen */
2285 * Some comments on the cave grid flags. -BEN-
2288 * One of the major bottlenecks in previous versions of Angband was in
2289 * the calculation of "line of sight" from the player to various grids,
2290 * such as monsters. This was such a nasty bottleneck that a lot of
2291 * silly things were done to reduce the dependancy on "line of sight",
2292 * for example, you could not "see" any grids in a lit room until you
2293 * actually entered the room, and there were all kinds of bizarre grid
2294 * flags to enable this behavior. This is also why the "call light"
2295 * spells always lit an entire room.
2297 * The code below provides functions to calculate the "field of view"
2298 * for the player, which, once calculated, provides extremely fast
2299 * calculation of "line of sight from the player", and to calculate
2300 * the "field of torch lite", which, again, once calculated, provides
2301 * extremely fast calculation of "which grids are lit by the player's
2302 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2303 * "GRID_LITE", as appropriate, these functions maintain an array for
2304 * each of these two flags, each array containing the locations of all
2305 * of the grids marked with the appropriate flag, which can be used to
2306 * very quickly scan through all of the grids in a given set.
2308 * To allow more "semantically valid" field of view semantics, whenever
2309 * the field of view (or the set of torch lit grids) changes, all of the
2310 * grids in the field of view (or the set of torch lit grids) are "drawn"
2311 * so that changes in the world will become apparent as soon as possible.
2312 * This has been optimized so that only grids which actually "change" are
2313 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2314 * of the grids which are entering or leaving the relevent set of grids.
2316 * These new methods are so efficient that the old nasty code was removed.
2318 * Note that there is no reason to "update" the "viewable space" unless
2319 * the player "moves", or walls/doors are created/destroyed, and there
2320 * is no reason to "update" the "torch lit grids" unless the field of
2321 * view changes, or the "light radius" changes. This means that when
2322 * the player is resting, or digging, or doing anything that does not
2323 * involve movement or changing the state of the dungeon, there is no
2324 * need to update the "view" or the "lite" regions, which is nice.
2326 * Note that the calls to the nasty "los()" function have been reduced
2327 * to a bare minimum by the use of the new "field of view" calculations.
2329 * I wouldn't be surprised if slight modifications to the "update_view()"
2330 * function would allow us to determine "reverse line-of-sight" as well
2331 * as "normal line-of-sight", which would allow monsters to use a more
2332 * "correct" calculation to determine if they can "see" the player. For
2333 * now, monsters simply "cheat" somewhat and assume that if the player
2334 * has "line of sight" to the monster, then the monster can "pretend"
2335 * that it has "line of sight" to the player.
2338 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2339 * grid and maintains an array of all "CAVE_LITE" grids.
2341 * This set of grids is the complete set of all grids which are lit by
2342 * the players light source, which allows the "player_can_see_bold()"
2343 * function to work very quickly.
2345 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2346 * fact, the player (unless blind) can always "see" all grids which are
2347 * marked as "CAVE_LITE", unless they are "off screen".
2350 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2351 * grid and maintains an array of all "CAVE_VIEW" grids.
2353 * This set of grids is the complete set of all grids within line of sight
2354 * of the player, allowing the "player_has_los_bold()" macro to work very
2358 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2359 * temporary internal flag to mark those grids which are not only in view,
2360 * but which are also "easily" in line of sight of the player. This flag
2361 * is always cleared when we are done.
2364 * The current "update_lite()" and "update_view()" algorithms use the
2365 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2366 * to keep track of which grids were previously marked as "CAVE_LITE" or
2367 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2369 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2370 * for various other purposes, such as spreading lite or darkness during
2371 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2374 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2375 * in some way permanently lit. However, for the player to "see" anything
2376 * in the grid, as determined by "player_can_see()", the player must not be
2377 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2378 * grids, even if marked as "perma lit", are only illuminated if they touch
2379 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2382 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2383 * that even if the player cannot "see" the grid, he "knows" the terrain in
2384 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2385 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2386 * or when one of the "memorize floor grids" options induces memorization.
2388 * Objects are "memorized" in a different way, using a special "marked" flag
2389 * on the object itself, which is set when an object is observed or detected.
2392 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2393 * and should be illuminated by "lite room" and "darkness" spells.
2396 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2397 * and should be unavailable for "teleportation" destinations.
2400 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2401 * which is observed, and the "view_torch_grids" allows the player to memorize
2402 * every torch-lit grid. The player will always memorize important walls,
2403 * doors, stairs, and other terrain features, as well as any "detected" grids.
2405 * Note that the new "update_view()" method allows, among other things, a room
2406 * to be "partially" seen as the player approaches it, with a growing cone of
2407 * floor appearing as the player gets closer to the door. Also, by not turning
2408 * on the "memorize perma-lit grids" option, the player will only "see" those
2409 * floor grids which are actually in line of sight.
2411 * And my favorite "plus" is that you can now use a special option to draw the
2412 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2413 * grids dimly), providing a "pretty" effect as the player runs around, and
2414 * to efficiently display the "torch lite" in a special color.
2417 * Some comments on the "update_view()" algorithm...
2419 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2420 * and only has to call "los()" on the borderline cases. The major axes/diags
2421 * even terminate early when they hit walls. I need to find a quick way
2422 * to "terminate" the other scans.
2424 * Note that in the worst case (a big empty area with say 5% scattered walls),
2425 * each of the 1500 or so nearby grids is checked once, most of them getting
2426 * an "instant" rating, and only a small portion requiring a call to "los()".
2428 * The only time that the algorithm appears to be "noticeably" too slow is
2429 * when running, and this is usually only important in town, since the town
2430 * provides about the worst scenario possible, with large open regions and
2431 * a few scattered obstructions. There is a special "efficiency" option to
2432 * allow the player to reduce his field of view in town, if needed.
2434 * In the "best" case (say, a normal stretch of corridor), the algorithm
2435 * makes one check for each viewable grid, and makes no calls to "los()".
2436 * So running in corridors is very fast, and if a lot of monsters are
2437 * nearby, it is much faster than the old methods.
2439 * Note that resting, most normal commands, and several forms of running,
2440 * plus all commands executed near large groups of monsters, are strictly
2441 * more efficient with "update_view()" that with the old "compute los() on
2442 * demand" method, primarily because once the "field of view" has been
2443 * calculated, it does not have to be recalculated until the player moves
2444 * (or a wall or door is created or destroyed).
2446 * Note that we no longer have to do as many "los()" checks, since once the
2447 * "view" region has been built, very few things cause it to be "changed"
2448 * (player movement, and the opening/closing of doors, changes in wall status).
2449 * Note that door/wall changes are only relevant when the door/wall itself is
2450 * in the "view" region.
2452 * The algorithm seems to only call "los()" from zero to ten times, usually
2453 * only when coming down a corridor into a room, or standing in a room, just
2454 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2455 * we will be reducing the calls to "los()".
2457 * I am thinking in terms of an algorithm that "walks" from the central point
2458 * out to the maximal "distance", at each point, determining the "view" code
2459 * (above). For each grid not on a major axis or diagonal, the "view" code
2460 * depends on the "cave_los_bold()" and "view" of exactly two other grids
2461 * (the one along the nearest diagonal, and the one next to that one, see
2462 * "update_view_aux()"...).
2464 * We "memorize" the viewable space array, so that at the cost of under 3000
2465 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2466 * each grid actually in the "viewable space". And for another 3000 bytes,
2467 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2468 * are also used by other routines, thus reducing the cost to almost nothing.
2470 * A similar thing is done for "forget_lite()" in which case the savings are
2471 * much less, but save us from doing bizarre maintenance checking.
2473 * In the worst "normal" case (in the middle of the town), the reachable space
2474 * actually reaches to more than half of the largest possible "circle" of view,
2475 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2476 * where all the walls have been removed), the reachable space actually reaches
2477 * the theoretical maximum size of just under 1500 grids.
2479 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2480 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2481 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2482 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2483 * entire possible space (including initialization) in one step per grid. If
2484 * we do the "clearing" as a separate step (and use an array of "view" grids),
2485 * then the clearing will take as many steps as grids that were viewed, and the
2486 * algorithm will be able to "stop" scanning at various points.
2487 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2498 * Actually erase the entire "lite" array, redrawing every grid
2500 void forget_lite(void)
2504 /* None to forget */
2505 if (!lite_n) return;
2507 /* Clear them all */
2508 for (i = 0; i < lite_n; i++)
2513 /* Forget "LITE" flag */
2514 cave[y][x].info &= ~(CAVE_LITE);
2517 /* lite_spot(y, x); Perhaps don't need? */
2526 * For delayed visual update
2528 #define cave_note_and_redraw_later(C,Y,X) \
2530 (C)->info |= CAVE_NOTE; \
2531 cave_redraw_later((C), (Y), (X)); \
2536 * For delayed visual update
2538 #define cave_redraw_later(C,Y,X) \
2540 if (!((C)->info & CAVE_REDRAW)) \
2542 (C)->info |= CAVE_REDRAW; \
2543 redraw_y[redraw_n] = (Y); \
2544 redraw_x[redraw_n++] = (X); \
2552 * This macro allows us to efficiently add a grid to the "lite" array,
2553 * note that we are never called for illegal grids, or for grids which
2554 * have already been placed into the "lite" array, and we are never
2555 * called when the "lite" array is full.
2557 #define cave_lite_hack(Y,X) \
2559 if (!(cave[Y][X].info & (CAVE_LITE))) \
2561 cave[Y][X].info |= (CAVE_LITE); \
2562 lite_y[lite_n] = (Y); \
2563 lite_x[lite_n++] = (X); \
2569 * Update the set of grids "illuminated" by the player's lite.
2571 * This routine needs to use the results of "update_view()"
2573 * Note that "blindness" does NOT affect "torch lite". Be careful!
2575 * We optimize most lites (all non-artifact lites) by using "obvious"
2576 * facts about the results of "small" lite radius, and we attempt to
2577 * list the "nearby" grids before the more "distant" ones in the
2578 * array of torch-lit grids.
2580 * We assume that "radius zero" lite is in fact no lite at all.
2582 * Torch Lantern Artifacts
2592 void update_lite(void)
2594 int i, x, y, min_x, max_x, min_y, max_y;
2595 int p = p_ptr->cur_lite;
2598 /*** Special case ***/
2601 /* Hack -- Player has no lite */
2604 /* Forget the old lite */
2605 /* forget_lite(); Perhaps don't need? */
2607 /* Add it to later visual update */
2608 cave_redraw_later(&cave[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
2612 /*** Save the old "lite" grids for later ***/
2614 /* Clear them all */
2615 for (i = 0; i < lite_n; i++)
2620 /* Mark the grid as not "lite" */
2621 cave[y][x].info &= ~(CAVE_LITE);
2623 /* Mark the grid as "seen" */
2624 cave[y][x].info |= (CAVE_TEMP);
2626 /* Add it to the "seen" set */
2636 /*** Collect the new "lite" grids ***/
2638 /* Radius 1 -- torch radius */
2642 cave_lite_hack(p_ptr->y, p_ptr->x);
2645 cave_lite_hack(p_ptr->y+1, p_ptr->x);
2646 cave_lite_hack(p_ptr->y-1, p_ptr->x);
2647 cave_lite_hack(p_ptr->y, p_ptr->x+1);
2648 cave_lite_hack(p_ptr->y, p_ptr->x-1);
2650 /* Diagonal grids */
2651 cave_lite_hack(p_ptr->y+1, p_ptr->x+1);
2652 cave_lite_hack(p_ptr->y+1, p_ptr->x-1);
2653 cave_lite_hack(p_ptr->y-1, p_ptr->x+1);
2654 cave_lite_hack(p_ptr->y-1, p_ptr->x-1);
2657 /* Radius 2 -- lantern radius */
2660 /* South of the player */
2661 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
2663 cave_lite_hack(p_ptr->y+2, p_ptr->x);
2664 cave_lite_hack(p_ptr->y+2, p_ptr->x+1);
2665 cave_lite_hack(p_ptr->y+2, p_ptr->x-1);
2668 /* North of the player */
2669 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
2671 cave_lite_hack(p_ptr->y-2, p_ptr->x);
2672 cave_lite_hack(p_ptr->y-2, p_ptr->x+1);
2673 cave_lite_hack(p_ptr->y-2, p_ptr->x-1);
2676 /* East of the player */
2677 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
2679 cave_lite_hack(p_ptr->y, p_ptr->x+2);
2680 cave_lite_hack(p_ptr->y+1, p_ptr->x+2);
2681 cave_lite_hack(p_ptr->y-1, p_ptr->x+2);
2684 /* West of the player */
2685 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
2687 cave_lite_hack(p_ptr->y, p_ptr->x-2);
2688 cave_lite_hack(p_ptr->y+1, p_ptr->x-2);
2689 cave_lite_hack(p_ptr->y-1, p_ptr->x-2);
2693 /* Radius 3+ -- artifact radius */
2698 /* Paranoia -- see "LITE_MAX" */
2701 /* South-East of the player */
2702 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
2704 cave_lite_hack(p_ptr->y+2, p_ptr->x+2);
2707 /* South-West of the player */
2708 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
2710 cave_lite_hack(p_ptr->y+2, p_ptr->x-2);
2713 /* North-East of the player */
2714 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
2716 cave_lite_hack(p_ptr->y-2, p_ptr->x+2);
2719 /* North-West of the player */
2720 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
2722 cave_lite_hack(p_ptr->y-2, p_ptr->x-2);
2726 min_y = p_ptr->y - p;
2727 if (min_y < 0) min_y = 0;
2730 max_y = p_ptr->y + p;
2731 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
2734 min_x = p_ptr->x - p;
2735 if (min_x < 0) min_x = 0;
2738 max_x = p_ptr->x + p;
2739 if (max_x > cur_wid-1) max_x = cur_wid-1;
2741 /* Scan the maximal box */
2742 for (y = min_y; y <= max_y; y++)
2744 for (x = min_x; x <= max_x; x++)
2746 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
2747 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
2749 /* Skip the "central" grids (above) */
2750 if ((dy <= 2) && (dx <= 2)) continue;
2752 /* Hack -- approximate the distance */
2753 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2755 /* Skip distant grids */
2756 if (d > p) continue;
2758 /* Viewable, nearby, grids get "torch lit" */
2759 if (cave[y][x].info & CAVE_VIEW)
2761 /* This grid is "torch lit" */
2762 cave_lite_hack(y, x);
2769 /*** Complete the algorithm ***/
2771 /* Draw the new grids */
2772 for (i = 0; i < lite_n; i++)
2777 c_ptr = &cave[y][x];
2779 /* Update fresh grids */
2780 if (c_ptr->info & (CAVE_TEMP)) continue;
2782 /* Add it to later visual update */
2783 cave_note_and_redraw_later(c_ptr, y, x);
2786 /* Clear them all */
2787 for (i = 0; i < temp_n; i++)
2792 c_ptr = &cave[y][x];
2794 /* No longer in the array */
2795 c_ptr->info &= ~(CAVE_TEMP);
2797 /* Update stale grids */
2798 if (c_ptr->info & (CAVE_LITE)) continue;
2800 /* Add it to later visual update */
2801 cave_redraw_later(c_ptr, y, x);
2807 /* Mega-Hack -- Visual update later */
2808 p_ptr->update |= (PU_DELAY_VIS);
2812 static bool mon_invis;
2813 static POSITION mon_fy, mon_fx;
2816 * Add a square to the changes array
2818 static void mon_lite_hack(POSITION y, POSITION x)
2824 /* We trust this grid is in bounds */
2825 /* if (!in_bounds2(y, x)) return; */
2827 c_ptr = &cave[y][x];
2829 /* Want a unlit square in view of the player */
2830 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
2832 if (!cave_los_grid(c_ptr))
2834 /* Hack -- Prevent monster lite leakage in walls */
2836 /* Horizontal walls between player and a monster */
2837 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2839 dpf = p_ptr->y - mon_fy;
2841 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2843 /* Only first wall viewed from mid-x is lit */
2846 if (!cave_los_bold(y, x + 1)) return;
2848 else if (x > midpoint)
2850 if (!cave_los_bold(y, x - 1)) return;
2853 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2854 else if (mon_invis) return;
2857 /* Vertical walls between player and a monster */
2858 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2860 dpf = p_ptr->x - mon_fx;
2862 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2864 /* Only first wall viewed from mid-y is lit */
2867 if (!cave_los_bold(y + 1, x)) return;
2869 else if (y > midpoint)
2871 if (!cave_los_bold(y - 1, x)) return;
2874 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2875 else if (mon_invis) return;
2879 /* We trust temp_n does not exceed TEMP_MAX */
2882 if (!(c_ptr->info & CAVE_MNDK))
2884 /* Save this square */
2893 /* No longer dark */
2894 c_ptr->info &= ~(CAVE_MNDK);
2898 c_ptr->info |= CAVE_MNLT;
2903 * Add a square to the changes array
2905 static void mon_dark_hack(POSITION y, POSITION x)
2908 int midpoint, dpf, d;
2910 /* We trust this grid is in bounds */
2911 /* if (!in_bounds2(y, x)) return; */
2913 c_ptr = &cave[y][x];
2915 /* Want a unlit and undarkened square in view of the player */
2916 if ((c_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
2918 if (!cave_los_grid(c_ptr) && !cave_have_flag_grid(c_ptr, FF_PROJECT))
2920 /* Hack -- Prevent monster dark lite leakage in walls */
2922 /* Horizontal walls between player and a monster */
2923 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2925 dpf = p_ptr->y - mon_fy;
2927 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2929 /* Only first wall viewed from mid-x is lit */
2932 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
2934 else if (x > midpoint)
2936 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
2939 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2940 else if (mon_invis) return;
2943 /* Vertical walls between player and a monster */
2944 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2946 dpf = p_ptr->x - mon_fx;
2948 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2950 /* Only first wall viewed from mid-y is lit */
2953 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
2955 else if (y > midpoint)
2957 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
2960 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2961 else if (mon_invis) return;
2965 /* We trust temp_n does not exceed TEMP_MAX */
2967 /* Save this square */
2973 c_ptr->info |= CAVE_MNDK;
2978 * Update squares illuminated or darkened by monsters.
2980 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
2981 * denote squares illuminated by monsters.
2983 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
2984 * updating. Only squares in view of the player, whos state
2985 * changes are drawn via lite_spot().
2987 void update_mon_lite(void)
2993 void (*add_mon_lite)(POSITION, POSITION);
2998 /* Non-Ninja player in the darkness */
2999 int dis_lim = ((d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
3000 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
3002 /* Clear all monster lit squares */
3003 for (i = 0; i < mon_lite_n; i++)
3006 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3008 /* Set temp or xtra flag */
3009 c_ptr->info |= (c_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
3011 /* Clear monster illumination flag */
3012 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3015 /* Empty temp list of new squares to lite up */
3018 /* If a monster stops time, don't process */
3021 monster_type *m_ptr;
3022 monster_race *r_ptr;
3024 /* Loop through monsters, adding newly lit squares to changes list */
3025 for (i = 1; i < m_max; i++)
3028 r_ptr = &r_info[m_ptr->r_idx];
3030 /* Skip dead monsters */
3031 if (!m_ptr->r_idx) continue;
3033 /* Is it too far away? */
3034 if (m_ptr->cdis > dis_lim) continue;
3036 /* Get lite radius */
3039 /* Note the radii are cumulative */
3040 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3041 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3042 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3043 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3045 /* Exit if has no light */
3049 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;
3050 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3051 add_mon_lite = mon_lite_hack;
3056 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && !is_daytime()))) continue;
3057 add_mon_lite = mon_dark_hack;
3058 f_flag = FF_PROJECT;
3059 rad = -rad; /* Use absolute value */
3062 /* Access the location */
3066 /* Is the monster visible? */
3067 mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
3069 /* The square it is on */
3070 add_mon_lite(mon_fy, mon_fx);
3072 /* Adjacent squares */
3073 add_mon_lite(mon_fy + 1, mon_fx);
3074 add_mon_lite(mon_fy - 1, mon_fx);
3075 add_mon_lite(mon_fy, mon_fx + 1);
3076 add_mon_lite(mon_fy, mon_fx - 1);
3077 add_mon_lite(mon_fy + 1, mon_fx + 1);
3078 add_mon_lite(mon_fy + 1, mon_fx - 1);
3079 add_mon_lite(mon_fy - 1, mon_fx + 1);
3080 add_mon_lite(mon_fy - 1, mon_fx - 1);
3085 /* South of the monster */
3086 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
3088 add_mon_lite(mon_fy + 2, mon_fx + 1);
3089 add_mon_lite(mon_fy + 2, mon_fx);
3090 add_mon_lite(mon_fy + 2, mon_fx - 1);
3092 c_ptr = &cave[mon_fy + 2][mon_fx];
3095 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3097 add_mon_lite(mon_fy + 3, mon_fx + 1);
3098 add_mon_lite(mon_fy + 3, mon_fx);
3099 add_mon_lite(mon_fy + 3, mon_fx - 1);
3103 /* North of the monster */
3104 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
3106 add_mon_lite(mon_fy - 2, mon_fx + 1);
3107 add_mon_lite(mon_fy - 2, mon_fx);
3108 add_mon_lite(mon_fy - 2, mon_fx - 1);
3110 c_ptr = &cave[mon_fy - 2][mon_fx];
3113 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3115 add_mon_lite(mon_fy - 3, mon_fx + 1);
3116 add_mon_lite(mon_fy - 3, mon_fx);
3117 add_mon_lite(mon_fy - 3, mon_fx - 1);
3121 /* East of the monster */
3122 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
3124 add_mon_lite(mon_fy + 1, mon_fx + 2);
3125 add_mon_lite(mon_fy, mon_fx + 2);
3126 add_mon_lite(mon_fy - 1, mon_fx + 2);
3128 c_ptr = &cave[mon_fy][mon_fx + 2];
3131 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3133 add_mon_lite(mon_fy + 1, mon_fx + 3);
3134 add_mon_lite(mon_fy, mon_fx + 3);
3135 add_mon_lite(mon_fy - 1, mon_fx + 3);
3139 /* West of the monster */
3140 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
3142 add_mon_lite(mon_fy + 1, mon_fx - 2);
3143 add_mon_lite(mon_fy, mon_fx - 2);
3144 add_mon_lite(mon_fy - 1, mon_fx - 2);
3146 c_ptr = &cave[mon_fy][mon_fx - 2];
3149 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3151 add_mon_lite(mon_fy + 1, mon_fx - 3);
3152 add_mon_lite(mon_fy, mon_fx - 3);
3153 add_mon_lite(mon_fy - 1, mon_fx - 3);
3161 /* South-East of the monster */
3162 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
3164 add_mon_lite(mon_fy + 2, mon_fx + 2);
3167 /* South-West of the monster */
3168 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
3170 add_mon_lite(mon_fy + 2, mon_fx - 2);
3173 /* North-East of the monster */
3174 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
3176 add_mon_lite(mon_fy - 2, mon_fx + 2);
3179 /* North-West of the monster */
3180 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
3182 add_mon_lite(mon_fy - 2, mon_fx - 2);
3188 /* Save end of list of new squares */
3192 * Look at old set flags to see if there are any changes.
3194 for (i = 0; i < mon_lite_n; i++)
3199 /* We trust this grid is in bounds */
3202 c_ptr = &cave[fy][fx];
3204 if (c_ptr->info & CAVE_TEMP) /* Pervious lit */
3206 /* It it no longer lit? */
3207 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3209 /* It is now unlit */
3210 /* Add it to later visual update */
3211 cave_note_and_redraw_later(c_ptr, fy, fx);
3214 else /* Pervious darkened */
3216 /* It it no longer darken? */
3217 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3219 /* It is now undarken */
3220 /* Add it to later visual update */
3221 cave_note_and_redraw_later(c_ptr, fy, fx);
3225 /* Add to end of temp array */
3226 temp_x[temp_n] = fx;
3227 temp_y[temp_n] = fy;
3231 /* Clear the lite array */
3234 /* Copy the temp array into the lit array lighting the new squares. */
3235 for (i = 0; i < end_temp; i++)
3240 /* We trust this grid is in bounds */
3243 c_ptr = &cave[fy][fx];
3245 if (c_ptr->info & CAVE_MNLT) /* Lit */
3247 /* The is the square newly lit and visible? */
3248 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3251 /* Add it to later visual update */
3252 cave_note_and_redraw_later(c_ptr, fy, fx);
3257 /* The is the square newly darkened and visible? */
3258 if ((c_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3260 /* It is now darkened */
3261 /* Add it to later visual update */
3262 cave_note_and_redraw_later(c_ptr, fy, fx);
3266 /* Save in the monster lit or darkened array */
3267 mon_lite_x[mon_lite_n] = fx;
3268 mon_lite_y[mon_lite_n] = fy;
3272 /* Clear the temp flag for the old lit or darken grids */
3273 for (i = end_temp; i < temp_n; i++)
3275 /* We trust this grid is in bounds */
3277 cave[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3280 /* Finished with temp_n */
3283 /* Mega-Hack -- Visual update later */
3284 p_ptr->update |= (PU_DELAY_VIS);
3286 p_ptr->monlite = (cave[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
3288 if (p_ptr->special_defense & NINJA_S_STEALTH)
3290 if (p_ptr->old_monlite != p_ptr->monlite)
3294 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
3298 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
3302 p_ptr->old_monlite = p_ptr->monlite;
3305 void clear_mon_lite(void)
3310 /* Clear all monster lit squares */
3311 for (i = 0; i < mon_lite_n; i++)
3314 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3316 /* Clear monster illumination flag */
3317 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3320 /* Empty the array */
3327 * Clear the viewable space
3329 void forget_view(void)
3335 /* None to forget */
3336 if (!view_n) return;
3338 /* Clear them all */
3339 for (i = 0; i < view_n; i++)
3344 /* Access the grid */
3345 c_ptr = &cave[y][x];
3347 /* Forget that the grid is viewable */
3348 c_ptr->info &= ~(CAVE_VIEW);
3350 /* if (!panel_contains(y, x)) continue; */
3352 /* Update the screen */
3353 /* lite_spot(y, x); Perhaps don't need? */
3363 * This macro allows us to efficiently add a grid to the "view" array,
3364 * note that we are never called for illegal grids, or for grids which
3365 * have already been placed into the "view" array, and we are never
3366 * called when the "view" array is full.
3368 #define cave_view_hack(C,Y,X) \
3370 if (!((C)->info & (CAVE_VIEW))){\
3371 (C)->info |= (CAVE_VIEW); \
3372 view_y[view_n] = (Y); \
3373 view_x[view_n] = (X); \
3380 * Helper function for "update_view()" below
3382 * We are checking the "viewability" of grid (y,x) by the player.
3384 * This function assumes that (y,x) is legal (i.e. on the map).
3386 * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
3387 * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
3389 * Note that we are using the "CAVE_XTRA" field for marking grids as
3390 * "easily viewable". This bit is cleared at the end of "update_view()".
3392 * This function adds (y,x) to the "viewable set" if necessary.
3394 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3396 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3398 bool f1, f2, v1, v2, z1, z2, wall;
3402 cave_type *g1_c_ptr;
3403 cave_type *g2_c_ptr;
3405 /* Access the grids */
3406 g1_c_ptr = &cave[y1][x1];
3407 g2_c_ptr = &cave[y2][x2];
3410 /* Check for walls */
3411 f1 = (cave_los_grid(g1_c_ptr));
3412 f2 = (cave_los_grid(g2_c_ptr));
3414 /* Totally blocked by physical walls */
3415 if (!f1 && !f2) return (TRUE);
3418 /* Check for visibility */
3419 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3420 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3422 /* Totally blocked by "unviewable neighbors" */
3423 if (!v1 && !v2) return (TRUE);
3426 /* Access the grid */
3427 c_ptr = &cave[y][x];
3430 /* Check for walls */
3431 wall = (!cave_los_grid(c_ptr));
3434 /* Check the "ease" of visibility */
3435 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3436 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3438 /* Hack -- "easy" plus "easy" yields "easy" */
3441 c_ptr->info |= (CAVE_XTRA);
3443 cave_view_hack(c_ptr, y, x);
3448 /* Hack -- primary "easy" yields "viewed" */
3451 cave_view_hack(c_ptr, y, x);
3456 /* Hack -- "view" plus "view" yields "view" */
3459 /* c_ptr->info |= (CAVE_XTRA); */
3461 cave_view_hack(c_ptr, y, x);
3467 /* Mega-Hack -- the "los()" function works poorly on walls */
3470 cave_view_hack(c_ptr, y, x);
3476 /* Hack -- check line of sight */
3477 if (los(p_ptr->y, p_ptr->x, y, x))
3479 cave_view_hack(c_ptr, y, x);
3485 /* Assume no line of sight. */
3492 * Calculate the viewable space
3494 * 1: Process the player
3495 * 1a: The player is always (easily) viewable
3496 * 2: Process the diagonals
3497 * 2a: The diagonals are (easily) viewable up to the first wall
3498 * 2b: But never go more than 2/3 of the "full" distance
3499 * 3: Process the main axes
3500 * 3a: The main axes are (easily) viewable up to the first wall
3501 * 3b: But never go more than the "full" distance
3502 * 4: Process sequential "strips" in each of the eight octants
3503 * 4a: Each strip runs along the previous strip
3504 * 4b: The main axes are "previous" to the first strip
3505 * 4c: Process both "sides" of each "direction" of each strip
3506 * 4c1: Each side aborts as soon as possible
3507 * 4c2: Each side tells the next strip how far it has to check
3509 * Note that the octant processing involves some pretty interesting
3510 * observations involving when a grid might possibly be viewable from
3511 * a given grid, and on the order in which the strips are processed.
3513 * Note the use of the mathematical facts shown below, which derive
3514 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3515 * hypotenuse of a right triangle is primarily determined by the length
3516 * of the longest side, when one side is small, and is strictly less
3517 * than one-and-a-half times as long as the longest side when both of
3518 * the sides are large.
3520 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3521 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3523 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3525 * These observations are important because the calculation of the actual
3526 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3527 * while for small values (up to about 20 or so), the approximations above
3528 * are correct to within an error of at most one grid or so.
3530 * Observe the use of "full" and "over" in the code below, and the use of
3531 * the specialized calculation involving "limit", all of which derive from
3532 * the observations given above. Basically, we note that the "circle" of
3533 * view is completely contained in an "octagon" whose bounds are easy to
3534 * determine, and that only a few steps are needed to derive the actual
3535 * bounds of the circle given the bounds of the octagon.
3537 * Note that by skipping all the grids in the corners of the octagon, we
3538 * place an upper limit on the number of grids in the field of view, given
3539 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3540 * view, only about 1475 of these are in the "octagon" of view, and even
3541 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3542 * entries to completely contain the actual field of view.
3544 * Note also the care taken to prevent "running off the map". The use of
3545 * explicit checks on the "validity" of the "diagonal", and the fact that
3546 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3547 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
3548 * of multiple checks on the validity of grids.
3550 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3551 * "ws","wn" variables. They work like this: While travelling down the
3552 * south-bound strip just to the east of the main south axis, as soon as
3553 * we get to a grid which does not "transmit" viewing, if all of the strips
3554 * preceding us (in this case, just the main axis) had terminated at or before
3555 * the same point, then we can stop, and reset the "max distance" to ourself.
3556 * So, each strip (named by major axis plus offset, thus "se" in this case)
3557 * maintains a "blockage" variable, initialized during the main axis step,
3558 * and checks it whenever a blockage is observed. After processing each
3559 * strip as far as the previous strip told us to process, the next strip is
3560 * told not to go farther than the current strip's farthest viewable grid,
3561 * unless open space is still available. This uses the "k" variable.
3563 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
3564 * macro is a replacement for "cave_los_bold()" which takes a pointer to
3565 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3566 * chunk of code which adds the given location to the "view" array if it
3567 * is not already there, using both the actual location and a pointer to
3568 * the cave grid. See above.
3570 * By the way, the purpose of this code is to reduce the dependancy on the
3571 * "los()" function which is slow, and, in some cases, not very accurate.
3573 * It is very possible that I am the only person who fully understands this
3574 * function, and for that I am truly sorry, but efficiency was very important
3575 * and the "simple" version of this function was just not fast enough. I am
3576 * more than willing to replace this function with a simpler one, if it is
3577 * equally efficient, and especially willing if the new function happens to
3578 * derive "reverse-line-of-sight" at the same time, since currently monsters
3579 * just use an optimized hack of "you see me, so I see you", and then use the
3580 * actual "projectable()" function to check spell attacks.
3582 void update_view(void)
3587 int se, sw, ne, nw, es, en, ws, wn;
3591 POSITION y_max = cur_hgt - 1;
3592 POSITION x_max = cur_wid - 1;
3596 /*** Initialize ***/
3599 if (view_reduce_view && !dun_level)
3601 /* Full radius (10) */
3602 full = MAX_SIGHT / 2;
3604 /* Octagon factor (15) */
3605 over = MAX_SIGHT * 3 / 4;
3611 /* Full radius (20) */
3614 /* Octagon factor (30) */
3615 over = MAX_SIGHT * 3 / 2;
3619 /*** Step 0 -- Begin ***/
3621 /* Save the old "view" grids for later */
3622 for (n = 0; n < view_n; n++)
3627 /* Access the grid */
3628 c_ptr = &cave[y][x];
3630 /* Mark the grid as not in "view" */
3631 c_ptr->info &= ~(CAVE_VIEW);
3633 /* Mark the grid as "seen" */
3634 c_ptr->info |= (CAVE_TEMP);
3636 /* Add it to the "seen" set */
3642 /* Start over with the "view" array */
3645 /*** Step 1 -- adjacent grids ***/
3647 /* Now start on the player */
3651 /* Access the grid */
3652 c_ptr = &cave[y][x];
3654 /* Assume the player grid is easily viewable */
3655 c_ptr->info |= (CAVE_XTRA);
3657 /* Assume the player grid is viewable */
3658 cave_view_hack(c_ptr, y, x);
3661 /*** Step 2 -- Major Diagonals ***/
3666 /* Scan south-east */
3667 for (d = 1; d <= z; d++)
3669 c_ptr = &cave[y+d][x+d];
3670 c_ptr->info |= (CAVE_XTRA);
3671 cave_view_hack(c_ptr, y+d, x+d);
3672 if (!cave_los_grid(c_ptr)) break;
3675 /* Scan south-west */
3676 for (d = 1; d <= z; d++)
3678 c_ptr = &cave[y+d][x-d];
3679 c_ptr->info |= (CAVE_XTRA);
3680 cave_view_hack(c_ptr, y+d, x-d);
3681 if (!cave_los_grid(c_ptr)) break;
3684 /* Scan north-east */
3685 for (d = 1; d <= z; d++)
3687 c_ptr = &cave[y-d][x+d];
3688 c_ptr->info |= (CAVE_XTRA);
3689 cave_view_hack(c_ptr, y-d, x+d);
3690 if (!cave_los_grid(c_ptr)) break;
3693 /* Scan north-west */
3694 for (d = 1; d <= z; d++)
3696 c_ptr = &cave[y-d][x-d];
3697 c_ptr->info |= (CAVE_XTRA);
3698 cave_view_hack(c_ptr, y-d, x-d);
3699 if (!cave_los_grid(c_ptr)) break;
3703 /*** Step 3 -- major axes ***/
3706 for (d = 1; d <= full; d++)
3708 c_ptr = &cave[y+d][x];
3709 c_ptr->info |= (CAVE_XTRA);
3710 cave_view_hack(c_ptr, y+d, x);
3711 if (!cave_los_grid(c_ptr)) break;
3714 /* Initialize the "south strips" */
3718 for (d = 1; d <= full; d++)
3720 c_ptr = &cave[y-d][x];
3721 c_ptr->info |= (CAVE_XTRA);
3722 cave_view_hack(c_ptr, y-d, x);
3723 if (!cave_los_grid(c_ptr)) break;
3726 /* Initialize the "north strips" */
3730 for (d = 1; d <= full; d++)
3732 c_ptr = &cave[y][x+d];
3733 c_ptr->info |= (CAVE_XTRA);
3734 cave_view_hack(c_ptr, y, x+d);
3735 if (!cave_los_grid(c_ptr)) break;
3738 /* Initialize the "east strips" */
3742 for (d = 1; d <= full; d++)
3744 c_ptr = &cave[y][x-d];
3745 c_ptr->info |= (CAVE_XTRA);
3746 cave_view_hack(c_ptr, y, x-d);
3747 if (!cave_los_grid(c_ptr)) break;
3750 /* Initialize the "west strips" */
3754 /*** Step 4 -- Divide each "octant" into "strips" ***/
3756 /* Now check each "diagonal" (in parallel) */
3757 for (n = 1; n <= over / 2; n++)
3759 int ypn, ymn, xpn, xmn;
3762 /* Acquire the "bounds" of the maximal circle */
3764 if (z > full - n) z = full - n;
3765 while ((z + n + (n>>1)) > full) z--;
3768 /* Access the four diagonal grids */
3778 /* Maximum distance */
3779 m = MIN(z, y_max - ypn);
3782 if ((xpn <= x_max) && (n < se))
3785 for (k = n, d = 1; d <= m; d++)
3787 /* Check grid "d" in strip "n", notice "blockage" */
3788 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3790 if (n + d >= se) break;
3793 /* Track most distant "non-blockage" */
3800 /* Limit the next strip */
3805 if ((xmn >= 0) && (n < sw))
3808 for (k = n, d = 1; d <= m; d++)
3810 /* Check grid "d" in strip "n", notice "blockage" */
3811 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3813 if (n + d >= sw) break;
3816 /* Track most distant "non-blockage" */
3823 /* Limit the next strip */
3832 /* Maximum distance */
3836 if ((xpn <= x_max) && (n < ne))
3839 for (k = n, d = 1; d <= m; d++)
3841 /* Check grid "d" in strip "n", notice "blockage" */
3842 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3844 if (n + d >= ne) break;
3847 /* Track most distant "non-blockage" */
3854 /* Limit the next strip */
3859 if ((xmn >= 0) && (n < nw))
3862 for (k = n, d = 1; d <= m; d++)
3864 /* Check grid "d" in strip "n", notice "blockage" */
3865 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
3867 if (n + d >= nw) break;
3870 /* Track most distant "non-blockage" */
3877 /* Limit the next strip */
3886 /* Maximum distance */
3887 m = MIN(z, x_max - xpn);
3890 if ((ypn <= x_max) && (n < es))
3893 for (k = n, d = 1; d <= m; d++)
3895 /* Check grid "d" in strip "n", notice "blockage" */
3896 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
3898 if (n + d >= es) break;
3901 /* Track most distant "non-blockage" */
3908 /* Limit the next strip */
3913 if ((ymn >= 0) && (n < en))
3916 for (k = n, d = 1; d <= m; d++)
3918 /* Check grid "d" in strip "n", notice "blockage" */
3919 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
3921 if (n + d >= en) break;
3924 /* Track most distant "non-blockage" */
3931 /* Limit the next strip */
3940 /* Maximum distance */
3944 if ((ypn <= y_max) && (n < ws))
3947 for (k = n, d = 1; d <= m; d++)
3949 /* Check grid "d" in strip "n", notice "blockage" */
3950 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
3952 if (n + d >= ws) break;
3955 /* Track most distant "non-blockage" */
3962 /* Limit the next strip */
3967 if ((ymn >= 0) && (n < wn))
3970 for (k = n, d = 1; d <= m; d++)
3972 /* Check grid "d" in strip "n", notice "blockage" */
3973 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
3975 if (n + d >= wn) break;
3978 /* Track most distant "non-blockage" */
3985 /* Limit the next strip */
3992 /*** Step 5 -- Complete the algorithm ***/
3994 /* Update all the new grids */
3995 for (n = 0; n < view_n; n++)
4000 /* Access the grid */
4001 c_ptr = &cave[y][x];
4003 /* Clear the "CAVE_XTRA" flag */
4004 c_ptr->info &= ~(CAVE_XTRA);
4006 /* Update only newly viewed grids */
4007 if (c_ptr->info & (CAVE_TEMP)) continue;
4009 /* Add it to later visual update */
4010 cave_note_and_redraw_later(c_ptr, y, x);
4013 /* Wipe the old grids, update as needed */
4014 for (n = 0; n < temp_n; n++)
4019 /* Access the grid */
4020 c_ptr = &cave[y][x];
4022 /* No longer in the array */
4023 c_ptr->info &= ~(CAVE_TEMP);
4025 /* Update only non-viewable grids */
4026 if (c_ptr->info & (CAVE_VIEW)) continue;
4028 /* Add it to later visual update */
4029 cave_redraw_later(c_ptr, y, x);
4035 /* Mega-Hack -- Visual update later */
4036 p_ptr->update |= (PU_DELAY_VIS);
4041 * Mega-Hack -- Delayed visual update
4042 * Only used if update_view(), update_lite() or update_mon_lite() was called
4044 void delayed_visual_update(void)
4049 /* Update needed grids */
4050 for (i = 0; i < redraw_n; i++)
4055 /* Access the grid */
4056 c_ptr = &cave[y][x];
4058 /* Update only needed grids (prevent multiple updating) */
4059 if (!(c_ptr->info & CAVE_REDRAW)) continue;
4061 /* If required, note */
4062 if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
4067 /* Hack -- Visual update of monster on this grid */
4068 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4070 /* No longer in the array */
4071 c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4080 * Hack -- forget the "flow" information
4082 void forget_flow(void)
4086 /* Check the entire dungeon */
4087 for (y = 0; y < cur_hgt; y++)
4089 for (x = 0; x < cur_wid; x++)
4091 /* Forget the old data */
4092 cave[y][x].dist = 0;
4093 cave[y][x].cost = 0;
4094 cave[y][x].when = 0;
4101 * Hack - speed up the update_flow algorithm by only doing
4102 * it everytime the player moves out of LOS of the last
4105 static POSITION flow_x = 0;
4106 static POSITION flow_y = 0;
4111 * Hack -- fill in the "cost" field of every grid that the player
4112 * can "reach" with the number of steps needed to reach that grid.
4113 * This also yields the "distance" of the player from every grid.
4115 * In addition, mark the "when" of the grids that can reach
4116 * the player with the incremented value of "flow_n".
4118 * Hack -- use the "seen" array as a "circular queue".
4120 * We do not need a priority queue because the cost from grid
4121 * to grid is always "one" and we process them in order.
4123 void update_flow(void)
4129 /* Paranoia -- make sure the array is empty */
4132 /* The last way-point is on the map */
4133 if (running && in_bounds(flow_y, flow_x))
4135 /* The way point is in sight - do not update. (Speedup) */
4136 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4139 /* Erase all of the current flow information */
4140 for (y = 0; y < cur_hgt; y++)
4142 for (x = 0; x < cur_wid; x++)
4144 cave[y][x].cost = 0;
4145 cave[y][x].dist = 0;
4149 /* Save player position */
4153 /* Add the player's grid to the queue */
4154 temp_y[0] = p_ptr->y;
4155 temp_x[0] = p_ptr->x;
4157 /* Now process the queue */
4158 while (flow_head != flow_tail)
4162 /* Extract the next entry */
4163 ty = temp_y[flow_tail];
4164 tx = temp_x[flow_tail];
4166 /* Forget that entry */
4167 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4169 /* Add the "children" */
4170 for (d = 0; d < 8; d++)
4172 int old_head = flow_head;
4173 byte_hack m = cave[ty][tx].cost + 1;
4174 byte_hack n = cave[ty][tx].dist + 1;
4177 /* Child location */
4178 y = ty + ddy_ddd[d];
4179 x = tx + ddx_ddd[d];
4181 /* Ignore player's grid */
4182 if (player_bold(y, x)) continue;
4184 c_ptr = &cave[y][x];
4186 if (is_closed_door(c_ptr->feat)) m += 3;
4188 /* Ignore "pre-stamped" entries */
4189 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4191 /* Ignore "walls" and "rubble" */
4192 if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4194 /* Save the flow cost */
4195 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4196 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4198 /* Hack -- limit flow depth */
4199 if (n == MONSTER_FLOW_DEPTH) continue;
4201 /* Enqueue that entry */
4202 temp_y[flow_head] = y;
4203 temp_x[flow_head] = x;
4205 /* Advance the queue */
4206 if (++flow_head == TEMP_MAX) flow_head = 0;
4208 /* Hack -- notice overflow by forgetting new entry */
4209 if (flow_head == flow_tail) flow_head = old_head;
4215 static int scent_when = 0;
4218 * Characters leave scent trails for perceptive monsters to track.
4220 * Smell is rather more limited than sound. Many creatures cannot use
4221 * it at all, it doesn't extend very far outwards from the character's
4222 * current position, and monsters can use it to home in the character,
4223 * but not to run away from him.
4225 * Smell is valued according to age. When a character takes his turn,
4226 * scent is aged by one, and new scent of the current age is laid down.
4227 * Speedy characters leave more scent, true, but it also ages faster,
4228 * which makes it harder to hunt them down.
4230 * Whenever the age count loops, most of the scent trail is erased and
4231 * the age of the remainder is recalculated.
4233 void update_smell(void)
4238 /* Create a table that controls the spread of scent */
4239 const int scent_adjust[5][5] =
4248 /* Loop the age and adjust scent values when necessary */
4249 if (++scent_when == 254)
4251 /* Scan the entire dungeon */
4252 for (y = 0; y < cur_hgt; y++)
4254 for (x = 0; x < cur_wid; x++)
4256 int w = cave[y][x].when;
4257 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4266 /* Lay down new scent */
4267 for (i = 0; i < 5; i++)
4269 for (j = 0; j < 5; j++)
4273 /* Translate table to map grids */
4274 y = i + p_ptr->y - 2;
4275 x = j + p_ptr->x - 2;
4278 if (!in_bounds(y, x)) continue;
4280 c_ptr = &cave[y][x];
4282 /* Walls, water, and lava cannot hold scent. */
4283 if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4285 /* Grid must not be blocked by walls from the character */
4286 if (!player_has_los_bold(y, x)) continue;
4288 /* Note grids that are too far away */
4289 if (scent_adjust[i][j] == -1) continue;
4291 /* Mark the grid with new scent */
4292 c_ptr->when = scent_when + scent_adjust[i][j];
4299 * Hack -- map the current panel (plus some) ala "magic mapping"
4301 void map_area(POSITION range)
4306 feature_type *f_ptr;
4308 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4310 /* Scan that area */
4311 for (y = 1; y < cur_hgt - 1; y++)
4313 for (x = 1; x < cur_wid - 1; x++)
4315 if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
4317 c_ptr = &cave[y][x];
4319 /* Memorize terrain of the grid */
4320 c_ptr->info |= (CAVE_KNOWN);
4322 /* Feature code (applying "mimic" field) */
4323 feat = get_feat_mimic(c_ptr);
4324 f_ptr = &f_info[feat];
4326 /* All non-walls are "checked" */
4327 if (!have_flag(f_ptr->flags, FF_WALL))
4329 /* Memorize normal features */
4330 if (have_flag(f_ptr->flags, FF_REMEMBER))
4332 /* Memorize the object */
4333 c_ptr->info |= (CAVE_MARK);
4336 /* Memorize known walls */
4337 for (i = 0; i < 8; i++)
4339 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4341 /* Feature code (applying "mimic" field) */
4342 feat = get_feat_mimic(c_ptr);
4343 f_ptr = &f_info[feat];
4345 /* Memorize walls (etc) */
4346 if (have_flag(f_ptr->flags, FF_REMEMBER))
4348 /* Memorize the walls */
4349 c_ptr->info |= (CAVE_MARK);
4357 p_ptr->redraw |= (PR_MAP);
4360 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4366 * Light up the dungeon using "clairvoyance"
4368 * This function "illuminates" every grid in the dungeon, memorizes all
4369 * "objects", memorizes all grids as with magic mapping, and, under the
4370 * standard option settings (view_perma_grids but not view_torch_grids)
4371 * memorizes all floor grids too.
4373 * Note that if "view_perma_grids" is not set, we do not memorize floor
4374 * grids, since this would defeat the purpose of "view_perma_grids", not
4375 * that anyone seems to play without this option.
4377 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4378 * since this would prevent the use of "view_torch_grids" as a method to
4379 * keep track of what grids have been observed directly.
4381 void wiz_lite(bool ninja)
4385 feature_type *f_ptr;
4387 /* Memorize objects */
4388 for (i = 1; i < o_max; i++)
4390 object_type *o_ptr = &o_list[i];
4392 /* Skip dead objects */
4393 if (!o_ptr->k_idx) continue;
4395 /* Skip held objects */
4396 if (o_ptr->held_m_idx) continue;
4399 o_ptr->marked |= OM_FOUND;
4402 /* Scan all normal grids */
4403 for (y = 1; y < cur_hgt - 1; y++)
4405 /* Scan all normal grids */
4406 for (x = 1; x < cur_wid - 1; x++)
4408 cave_type *c_ptr = &cave[y][x];
4410 /* Memorize terrain of the grid */
4411 c_ptr->info |= (CAVE_KNOWN);
4413 /* Feature code (applying "mimic" field) */
4414 feat = get_feat_mimic(c_ptr);
4415 f_ptr = &f_info[feat];
4417 /* Process all non-walls */
4418 if (!have_flag(f_ptr->flags, FF_WALL))
4420 /* Scan all neighbors */
4421 for (i = 0; i < 9; i++)
4423 int yy = y + ddy_ddd[i];
4424 int xx = x + ddx_ddd[i];
4427 c_ptr = &cave[yy][xx];
4429 /* Feature code (applying "mimic" field) */
4430 f_ptr = &f_info[get_feat_mimic(c_ptr)];
4432 /* Perma-lite the grid */
4433 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS) && !ninja)
4435 c_ptr->info |= (CAVE_GLOW);
4438 /* Memorize normal features */
4439 if (have_flag(f_ptr->flags, FF_REMEMBER))
4441 /* Memorize the grid */
4442 c_ptr->info |= (CAVE_MARK);
4445 /* Perma-lit grids (newly and previously) */
4446 else if (c_ptr->info & CAVE_GLOW)
4448 /* Normally, memorize floors (see above) */
4449 if (view_perma_grids && !view_torch_grids)
4451 /* Memorize the grid */
4452 c_ptr->info |= (CAVE_MARK);
4460 /* Update the monsters */
4461 p_ptr->update |= (PU_MONSTERS);
4464 p_ptr->redraw |= (PR_MAP);
4467 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4469 if (p_ptr->special_defense & NINJA_S_STEALTH)
4471 if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
4477 * Forget the dungeon map (ala "Thinking of Maud...").
4484 /* Forget every grid */
4485 for (y = 1; y < cur_hgt - 1; y++)
4487 for (x = 1; x < cur_wid - 1; x++)
4489 cave_type *c_ptr = &cave[y][x];
4491 /* Process the grid */
4492 c_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT | CAVE_KNOWN);
4493 c_ptr->info |= (CAVE_UNSAFE);
4497 /* Forget every grid on horizontal edge */
4498 for (x = 0; x < cur_wid; x++)
4500 cave[0][x].info &= ~(CAVE_MARK);
4501 cave[cur_hgt - 1][x].info &= ~(CAVE_MARK);
4504 /* Forget every grid on vertical edge */
4505 for (y = 1; y < (cur_hgt - 1); y++)
4507 cave[y][0].info &= ~(CAVE_MARK);
4508 cave[y][cur_wid - 1].info &= ~(CAVE_MARK);
4511 /* Forget all objects */
4512 for (i = 1; i < o_max; i++)
4514 object_type *o_ptr = &o_list[i];
4516 /* Skip dead objects */
4517 if (!o_ptr->k_idx) continue;
4519 /* Skip held objects */
4520 if (o_ptr->held_m_idx) continue;
4522 /* Forget the object */
4523 o_ptr->marked &= OM_TOUCHED;
4526 /* Forget travel route when we have forgotten map */
4527 forget_travel_flow();
4529 /* Mega-Hack -- Forget the view and lite */
4530 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4532 /* Update the view and lite */
4533 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4535 /* Update the monsters */
4536 p_ptr->update |= (PU_MONSTERS);
4539 p_ptr->redraw |= (PR_MAP);
4542 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4550 * Change the "feat" flag for a grid, and notice/redraw the grid
4552 void cave_set_feat(POSITION y, POSITION x, IDX feat)
4554 cave_type *c_ptr = &cave[y][x];
4555 feature_type *f_ptr = &f_info[feat];
4556 bool old_los, old_mirror;
4558 if (!character_dungeon)
4560 /* Clear mimic type */
4563 /* Change the feature */
4566 /* Hack -- glow the GLOW terrain */
4567 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4571 for (i = 0; i < 9; i++)
4573 yy = y + ddy_ddd[i];
4574 xx = x + ddx_ddd[i];
4575 if (!in_bounds2(yy, xx)) continue;
4576 cave[yy][xx].info |= CAVE_GLOW;
4583 old_los = cave_have_flag_bold(y, x, FF_LOS);
4584 old_mirror = is_mirror_grid(c_ptr);
4586 /* Clear mimic type */
4589 /* Change the feature */
4592 /* Remove flag for mirror/glyph */
4593 c_ptr->info &= ~(CAVE_OBJECT);
4595 if (old_mirror && (d_info[dungeon_type].flags1 & DF1_DARKNESS))
4597 c_ptr->info &= ~(CAVE_GLOW);
4598 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4600 update_local_illumination(y, x);
4603 /* Check for change to boring grid */
4604 if (!have_flag(f_ptr->flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
4606 /* Update the monster */
4607 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4615 /* Check if los has changed */
4616 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
4619 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
4621 update_local_illumination(y, x);
4623 #endif /* COMPLEX_WALL_ILLUMINATION */
4625 /* Update the visuals */
4626 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
4629 /* Hack -- glow the GLOW terrain */
4630 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4635 for (i = 0; i < 9; i++)
4637 yy = y + ddy_ddd[i];
4638 xx = x + ddx_ddd[i];
4639 if (!in_bounds2(yy, xx)) continue;
4640 cc_ptr = &cave[yy][xx];
4641 cc_ptr->info |= CAVE_GLOW;
4643 if (player_has_los_grid(cc_ptr))
4645 /* Update the monster */
4646 if (cc_ptr->m_idx) update_mon(cc_ptr->m_idx, FALSE);
4655 update_local_illumination(yy, xx);
4658 if (p_ptr->special_defense & NINJA_S_STEALTH)
4660 if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
4666 IDX conv_dungeon_feat(IDX newfeat)
4668 feature_type *f_ptr = &f_info[newfeat];
4670 if (have_flag(f_ptr->flags, FF_CONVERT))
4672 switch (f_ptr->subtype)
4674 case CONVERT_TYPE_FLOOR:
4675 return floor_type[randint0(100)];
4676 case CONVERT_TYPE_WALL:
4677 return fill_type[randint0(100)];
4678 case CONVERT_TYPE_INNER:
4679 return feat_wall_inner;
4680 case CONVERT_TYPE_OUTER:
4681 return feat_wall_outer;
4682 case CONVERT_TYPE_SOLID:
4683 return feat_wall_solid;
4684 case CONVERT_TYPE_STREAM1:
4685 return d_info[dungeon_type].stream1;
4686 case CONVERT_TYPE_STREAM2:
4687 return d_info[dungeon_type].stream2;
4692 else return newfeat;
4697 * Take a feature, determine what that feature becomes
4698 * through applying the given action.
4700 IDX feat_state(IDX feat, int action)
4702 feature_type *f_ptr = &f_info[feat];
4705 /* Get the new feature */
4706 for (i = 0; i < MAX_FEAT_STATES; i++)
4708 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
4711 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
4713 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
4717 * Takes a location and action and changes the feature at that
4718 * location through applying the given action.
4720 void cave_alter_feat(int y, int x, int action)
4722 /* Set old feature */
4723 IDX oldfeat = cave[y][x].feat;
4725 /* Get the new feat */
4726 IDX newfeat = feat_state(oldfeat, action);
4729 if (newfeat == oldfeat) return;
4731 /* Set the new feature */
4732 cave_set_feat(y, x, newfeat);
4734 if (!(feature_action_flags[action] & FAF_NO_DROP))
4736 feature_type *old_f_ptr = &f_info[oldfeat];
4737 feature_type *f_ptr = &f_info[newfeat];
4741 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
4743 /* Place some gold */
4749 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - dun_level / 2)))
4752 place_object(y, x, 0L);
4756 if (found && character_dungeon && player_can_see_bold(y, x))
4758 msg_print(_("何かを発見した!", "You have found something!"));
4762 if (feature_action_flags[action] & FAF_CRASH_GLASS)
4764 feature_type *old_f_ptr = &f_info[oldfeat];
4766 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
4768 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(dun_level, 100) / 4, GF_SHARDS,
4769 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
4775 /* Remove a mirror */
4776 void remove_mirror(int y, int x)
4778 cave_type *c_ptr = &cave[y][x];
4780 /* Remove the mirror */
4781 c_ptr->info &= ~(CAVE_OBJECT);
4784 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4786 c_ptr->info &= ~(CAVE_GLOW);
4787 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4789 /* Update the monster */
4790 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4792 update_local_illumination(y, x);
4804 * Return TRUE if there is a mirror on the grid.
4806 bool is_mirror_grid(cave_type *c_ptr)
4808 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MIRROR))
4816 * Return TRUE if there is a mirror on the grid.
4818 bool is_glyph_grid(cave_type *c_ptr)
4820 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_GLYPH))
4828 * Return TRUE if there is a mirror on the grid.
4830 bool is_explosive_rune_grid(cave_type *c_ptr)
4832 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MINOR_GLYPH))
4840 * Calculate "incremental motion". Used by project() and shoot().
4841 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4843 void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4845 POSITION dy, dx, dist, shift;
4847 /* Extract the distance travelled */
4848 dy = (*y < y1) ? y1 - *y : *y - y1;
4849 dx = (*x < x1) ? x1 - *x : *x - x1;
4851 /* Number of steps */
4852 dist = (dy > dx) ? dy : dx;
4854 /* We are calculating the next location */
4858 /* Calculate the total distance along each axis */
4859 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4860 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4862 /* Paranoia -- Hack -- no motion */
4863 if (!dy && !dx) return;
4866 /* Move mostly vertically */
4869 /* Extract a shift factor */
4870 shift = (dist * dx + (dy - 1) / 2) / dy;
4872 /* Sometimes move along the minor axis */
4873 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4875 /* Always move along major axis */
4876 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4879 /* Move mostly horizontally */
4882 /* Extract a shift factor */
4883 shift = (dist * dy + (dx - 1) / 2) / dx;
4885 /* Sometimes move along the minor axis */
4886 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4888 /* Always move along major axis */
4889 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4896 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4897 * at the final destination, assuming no monster gets in the way.
4899 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4901 bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4908 /* Check the projection path */
4909 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4911 /* Identical grid */
4912 if (!grid_n) return TRUE;
4915 y = GRID_Y(grid_g[grid_n - 1]);
4916 x = GRID_X(grid_g[grid_n - 1]);
4918 /* May not end in an unrequested grid */
4919 if ((y != y2) || (x != x2)) return (FALSE);
4927 * Standard "find me a location" function
4929 * Obtains a legal location within the given distance of the initial
4930 * location, and with "los()" from the source to destination location.
4932 * This function is often called from inside a loop which searches for
4933 * locations while increasing the "d" distance.
4935 * Currently the "m" parameter is unused.
4937 void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
4941 /* Pick a location */
4944 /* Pick a new location */
4945 ny = rand_spread(y, d);
4946 nx = rand_spread(x, d);
4948 /* Ignore annoying locations */
4949 if (!in_bounds(ny, nx)) continue;
4951 /* Ignore "excessively distant" locations */
4952 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4954 if (mode & PROJECT_LOS)
4956 if(los(y, x, ny, nx)) break;
4960 if(projectable(y, x, ny, nx)) break;
4965 /* Save the location */
4974 * Track a new monster
4976 void health_track(MONSTER_IDX m_idx)
4978 /* Mount monster is already tracked */
4979 if (m_idx && m_idx == p_ptr->riding) return;
4981 /* Track a new guy */
4982 p_ptr->health_who = m_idx;
4984 /* Redraw (later) */
4985 p_ptr->redraw |= (PR_HEALTH);
4991 * Hack -- track the given monster race
4993 void monster_race_track(MONRACE_IDX r_idx)
4995 /* Save this monster ID */
4996 p_ptr->monster_race_idx = r_idx;
4999 p_ptr->window |= (PW_MONSTER);
5005 * Hack -- track the given object kind
5007 void object_kind_track(IDX k_idx)
5009 /* Save this monster ID */
5010 p_ptr->object_kind_idx = k_idx;
5013 p_ptr->window |= (PW_OBJECT);
5019 * Something has happened to disturb the player.
5021 * The first arg indicates a major disturbance, which affects search.
5023 * The second arg is currently unused, but could induce output flush.
5025 * All disturbance cancels repeated commands, resting, and running.
5027 void disturb(int stop_search, int stop_travel)
5031 stop_travel = stop_travel;
5034 /* Cancel auto-commands */
5035 /* command_new = 0; */
5037 /* Cancel repeated commands */
5043 /* Redraw the state (later) */
5044 p_ptr->redraw |= (PR_STATE);
5047 /* Cancel Resting */
5048 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5051 set_action(ACTION_NONE);
5054 /* Cancel running */
5060 /* Check for new panel if appropriate */
5061 if (center_player && !center_running) verify_panel();
5063 /* Calculate torch radius */
5064 p_ptr->update |= (PU_TORCH);
5066 /* Update monster flow */
5067 p_ptr->update |= (PU_FLOW);
5076 /* Check for new panel if appropriate */
5077 if (center_player && !center_running) verify_panel();
5079 /* Calculate torch radius */
5080 p_ptr->update |= (PU_TORCH);
5084 /* Flush the input if requested */
5085 if (flush_disturb) flush();
5090 * Glow deep lava and building entrances in the floor
5092 void glow_deep_lava_and_bldg(void)
5094 int y, x, i, yy, xx;
5097 /* Not in the darkness dungeon */
5098 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
5100 for (y = 0; y < cur_hgt; y++)
5102 for (x = 0; x < cur_wid; x++)
5104 c_ptr = &cave[y][x];
5106 /* Feature code (applying "mimic" field) */
5108 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_GLOW))
5110 for (i = 0; i < 9; i++)
5112 yy = y + ddy_ddd[i];
5113 xx = x + ddx_ddd[i];
5114 if (!in_bounds2(yy, xx)) continue;
5115 cave[yy][xx].info |= CAVE_GLOW;
5121 /* Update the view and lite */
5122 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
5125 p_ptr->redraw |= (PR_MAP);