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(POSITION y, POSITION x)
391 /* Hack -- move towards player */
392 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
393 POSITION 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(POSITION y, POSITION x)
445 if (!in_bounds(y, x)) return;
447 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
449 if ((y != p_ptr->y) && (x != p_ptr->x))
451 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
452 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
453 update_local_illumination_aux(yy, xx);
454 update_local_illumination_aux(y, xx);
455 update_local_illumination_aux(yy, x);
457 else if (x != p_ptr->x) /* y == p_ptr->y */
459 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
460 for (i = -1; i <= 1; i++)
463 update_local_illumination_aux(yy, xx);
466 update_local_illumination_aux(yy, x);
468 update_local_illumination_aux(yy, x);
470 else if (y != p_ptr->y) /* x == p_ptr->x */
472 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
473 for (i = -1; i <= 1; i++)
476 update_local_illumination_aux(yy, xx);
479 update_local_illumination_aux(y, xx);
481 update_local_illumination_aux(y, xx);
483 else /* Player's grid */
485 for (i = 0; i < 8; i++)
489 update_local_illumination_aux(yy, xx);
493 #else /* COMPLEX_WALL_ILLUMINATION */
495 if ((y != p_ptr->y) && (x != p_ptr->x))
497 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
498 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
499 update_local_illumination_aux(yy, xx);
501 else if (x != p_ptr->x) /* y == p_ptr->y */
503 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
504 for (i = -1; i <= 1; i++)
507 update_local_illumination_aux(yy, xx);
510 else if (y != p_ptr->y) /* x == p_ptr->x */
512 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
513 for (i = -1; i <= 1; i++)
516 update_local_illumination_aux(yy, xx);
519 else /* Player's grid */
521 for (i = 0; i < 8; i++)
525 update_local_illumination_aux(yy, xx);
529 #endif /* COMPLEX_WALL_ILLUMINATION */
534 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
537 * @return 視覚に収められる状態ならTRUEを返す
539 * He must have vision, illumination, and line of sight.\n
541 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
542 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
544 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
545 * that a wall is visible from any direction. That would be odd. Except\n
546 * under wizard light, which might make sense. Thus, for walls, we require\n
547 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
548 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
549 * in line of sight of the player.\n
551 * This extra check is expensive, but it provides a more "correct" semantics.\n
553 * Note that we should not run this check on walls which are "outer walls" of\n
554 * the dungeon, or we will induce a memory fault, but actually verifying all\n
555 * of the locations would be extremely expensive.\n
557 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
558 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
559 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
560 * and the player has more important things on his mind when he is attacking a\n
561 * monster vault. It is annoying, but an extremely important optimization.\n
563 * Note that "glowing walls" are only considered to be "illuminated" if the\n
564 * grid which is next to the wall in the direction of the player is also a\n
565 * "glowing" grid. This prevents the player from being able to "see" the\n
566 * walls of illuminated rooms from a corridor outside the room.\n
568 bool player_can_see_bold(POSITION y, POSITION x)
572 /* Blind players see nothing */
573 if (p_ptr->blind) return FALSE;
575 /* Access the cave grid */
578 /* Note that "torch-lite" yields "illumination" */
579 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
581 /* Require line of sight to the grid */
582 if (!player_has_los_bold(y, x)) return FALSE;
584 /* Noctovision of Ninja */
585 if (p_ptr->see_nocto) return TRUE;
587 /* Require "perma-lite" of the grid */
588 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
590 /* Feature code (applying "mimic" field) */
591 /* Floors are simple */
592 if (feat_supports_los(get_feat_mimic(c_ptr))) return TRUE;
594 /* Check for "local" illumination */
595 return check_local_illumination(y, x);
599 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
600 * @return 視覚に収められていないならTRUEを返す
601 * @details player_can_see_bold()関数の返り値の否定を返している。
605 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
610 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
613 * @return 各種の変更が可能ならTRUEを返す。
615 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
617 bool cave_valid_bold(POSITION y, POSITION x)
619 cave_type *c_ptr = &cave[y][x];
620 OBJECT_IDX this_o_idx, next_o_idx = 0;
622 /* Forbid perma-grids */
623 if (cave_perma_grid(c_ptr)) return (FALSE);
626 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
631 o_ptr = &o_list[this_o_idx];
633 /* Acquire next object */
634 next_o_idx = o_ptr->next_o_idx;
636 /* Forbid artifact grids */
637 if (object_is_artifact(o_ptr)) return (FALSE);
648 * 一般的にモンスターシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal monster codes
650 static char image_monster_hack[] = \
651 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
654 * 一般的にオブジェクトシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal object codes
656 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
659 * @brief モンスターの表示を幻覚状態に差し替える / Mega-Hack -- Hallucinatory monster
664 static void image_monster(TERM_COLOR *ap, char *cp)
666 /* Random symbol from set above */
669 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
678 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
679 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
687 * @brief オブジェクトの表示を幻覚状態に差し替える / Hallucinatory object
692 static void image_object(TERM_COLOR *ap, char *cp)
696 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
703 int n = sizeof(image_object_hack) - 1;
705 *cp = image_object_hack[randint0(n)];
714 * @brief オブジェクト&モンスターの表示を幻覚状態に差し替える / Hack -- Random hallucination
719 static void image_random(TERM_COLOR *ap, char *cp)
721 /* Normally, assume monsters */
722 if (randint0(100) < 75)
724 image_monster(ap, cp);
727 /* Otherwise, assume objects */
730 image_object(ap, cp);
735 * 照明の表現を行うための色合いの関係を{暗闇時, 照明時} で定義する /
736 * This array lists the effects of "brightness" on various "base" colours.\n
738 * This is used to do dynamic lighting effects in ascii :-)\n
739 * At the moment, only the various "floor" tiles are affected.\n
741 * The layout of the array is [x][0] = light and [x][1] = dark.\n
743 static byte lighting_colours[16][2] =
746 {TERM_L_DARK, TERM_DARK},
749 {TERM_YELLOW, TERM_SLATE},
752 {TERM_WHITE, TERM_L_DARK},
755 {TERM_L_UMBER, TERM_UMBER},
758 {TERM_RED, TERM_RED},
761 {TERM_L_GREEN, TERM_GREEN},
764 {TERM_BLUE, TERM_BLUE},
767 {TERM_L_UMBER, TERM_RED},
770 {TERM_SLATE, TERM_L_DARK},
773 {TERM_WHITE, TERM_SLATE},
776 {TERM_L_RED, TERM_BLUE},
779 {TERM_YELLOW, TERM_ORANGE},
782 {TERM_L_RED, TERM_L_RED},
785 {TERM_L_GREEN, TERM_GREEN},
788 {TERM_L_BLUE, TERM_L_BLUE},
791 {TERM_L_UMBER, TERM_UMBER}
798 void apply_default_feat_lighting(TERM_COLOR f_attr[F_LIT_MAX], byte f_char[F_LIT_MAX])
800 TERM_COLOR s_attr = f_attr[F_LIT_STANDARD];
801 byte s_char = f_char[F_LIT_STANDARD];
804 if (is_ascii_graphics(s_attr)) /* For ASCII */
806 f_attr[F_LIT_LITE] = lighting_colours[s_attr & 0x0f][0];
807 f_attr[F_LIT_DARK] = lighting_colours[s_attr & 0x0f][1];
808 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_char[i] = s_char;
810 else /* For tile graphics */
812 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_attr[i] = s_attr;
813 f_char[F_LIT_LITE] = s_char + 2;
814 f_char[F_LIT_DARK] = s_char + 1;
820 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
822 #define darkened_grid(C) \
823 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
828 * @brief Mコマンドによる縮小マップの表示を行う / Extract the attr/char to display at the given (legal) map location
830 * Basically, we "paint" the chosen attr/char in several passes, starting\n
831 * with any known "terrain features" (defaulting to darkness), then adding\n
832 * any known "objects", and finally, adding any known "monsters". This\n
833 * is not the fastest method but since most of the calls to this function\n
834 * are made for grids with no monsters or objects, it is fast enough.\n
836 * Note that this function, if used on the grid containing the "player",\n
837 * will return the attr/char of the grid underneath the player, and not\n
838 * the actual player attr/char itself, allowing a lot of optimization\n
839 * in various "display" functions.\n
841 * Note that the "zero" entry in the feature/object/monster arrays are\n
842 * used to provide "special" attr/char codes, with "monster zero" being\n
843 * used for the player attr/char, "object zero" being used for the "stack"\n
844 * attr/char, and "feature zero" being used for the "nothing" attr/char,\n
845 * though this function makes use of only "feature zero".\n
847 * Note that monsters can have some "special" flags, including "ATTR_MULTI",\n
848 * which means their color changes, and "ATTR_CLEAR", which means they take\n
849 * the color of whatever is under them, and "CHAR_CLEAR", which means that\n
850 * they take the symbol of whatever is under them. Technically, the flag\n
851 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when\n
852 * examined, but this flag is currently ignored.\n
854 * Currently, we do nothing with multi-hued objects, because there are\n
855 * not any. If there were, they would have to set "shimmer_objects"\n
856 * when they were created, and then new "shimmer" code in "dungeon.c"\n
857 * would have to be created handle the "shimmer" effect, and the code\n
858 * in "cave.c" would have to be updated to create the shimmer effect.\n
860 * Note the effects of hallucination. Objects always appear as random\n
861 * "objects", monsters as random "monsters", and normal grids occasionally\n
862 * appear as random "monsters" or "objects", but note that these random\n
863 * "monsters" and "objects" are really just "colored ascii symbols".\n
865 * Note that "floors" and "invisible traps" (and "zero" features) are\n
866 * drawn as "floors" using a special check for optimization purposes,\n
867 * and these are the only features which get drawn using the special\n
868 * lighting effects activated by "view_special_lite".\n
870 * Note the use of the "mimic" field in the "terrain feature" processing,\n
871 * which allows any feature to "pretend" to be another feature. This is\n
872 * used to "hide" secret doors, and to make all "doors" appear the same,\n
873 * and all "walls" appear the same, and "hidden" treasure stay hidden.\n
874 * It is possible to use this field to make a feature "look" like a floor,\n
875 * but the "special lighting effects" for floors will not be used.\n
877 * Note the use of the new "terrain feature" information. Note that the\n
878 * assumption that all interesting "objects" and "terrain features" are\n
879 * memorized allows extremely optimized processing below. Note the use\n
880 * of separate flags on objects to mark them as memorized allows a grid\n
881 * to have memorized "terrain" without granting knowledge of any object\n
882 * which may appear in that grid.\n
884 * Note the efficient code used to determine if a "floor" grid is\n
885 * "memorized" or "viewable" by the player, where the test for the\n
886 * grid being "viewable" is based on the facts that (1) the grid\n
887 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in\n
888 * line of sight, and (3) the player must not be blind, and uses the\n
889 * assumption that all torch-lit grids are in line of sight.\n
891 * Note that floors (and invisible traps) are the only grids which are\n
892 * not memorized when seen, so only these grids need to check to see if\n
893 * the grid is "viewable" to the player (if it is not memorized). Since\n
894 * most non-memorized grids are in fact walls, this induces *massive*\n
895 * efficiency, at the cost of *forcing* the memorization of non-floor\n
896 * grids when they are first seen. Note that "invisible traps" are\n
897 * always treated exactly like "floors", which prevents "cheating".\n
899 * Note the "special lighting effects" which can be activated for floor\n
900 * grids using the "view_special_lite" option (for "white" floor grids),\n
901 * causing certain grids to be displayed using special colors. If the\n
902 * player is "blind", we will use "dark gray", else if the grid is lit\n
903 * by the torch, and the "view_yellow_lite" option is set, we will use\n
904 * "yellow", else if the grid is "dark", we will use "dark gray", else\n
905 * if the grid is not "viewable", and the "view_bright_lite" option is\n
906 * set, and the we will use "slate" (gray). We will use "white" for all\n
907 * other cases, in particular, for illuminated viewable floor grids.\n
909 * Note the "special lighting effects" which can be activated for wall\n
910 * grids using the "view_granite_lite" option (for "white" wall grids),\n
911 * causing certain grids to be displayed using special colors. If the\n
912 * player is "blind", we will use "dark gray", else if the grid is lit\n
913 * by the torch, and the "view_yellow_lite" option is set, we will use\n
914 * "yellow", else if the "view_bright_lite" option is set, and the grid\n
915 * is not "viewable", or is "dark", or is glowing, but not when viewed\n
916 * from the player's current location, we will use "slate" (gray). We\n
917 * will use "white" for all other cases, in particular, for correctly\n
918 * illuminated viewable wall grids.\n
920 * Note that, when "view_granite_lite" is set, we use an inline version\n
921 * of the "player_can_see_bold()" function to check the "viewability" of\n
922 * grids when the "view_bright_lite" option is set, and we do NOT use\n
923 * any special colors for "dark" wall grids, since this would allow the\n
924 * player to notice the walls of illuminated rooms from a hallway that\n
925 * happened to run beside the room. The alternative, by the way, would\n
926 * be to prevent the generation of hallways next to rooms, but this\n
927 * would still allow problems when digging towards a room.\n
929 * Note that bizarre things must be done when the "attr" and/or "char"\n
930 * codes have the "high-bit" set, since these values are used to encode\n
931 * various "special" pictures in some versions, and certain situations,\n
932 * such as "multi-hued" or "clear" monsters, cause the attr/char codes\n
933 * to be "scrambled" in various ways.\n
935 * Note that eventually we may use the "&" symbol for embedded treasure,\n
936 * and use the "*" symbol to indicate multiple objects, though this will\n
937 * have to wait for Angband 2.8.0 or later. Note that currently, this\n
938 * is not important, since only one object or terrain feature is allowed\n
939 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.\n
941 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of\n
942 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect\n
943 * then a whole lot of code should be changed... XXX XXX\n
945 void map_info(POSITION y, POSITION x, TERM_COLOR *ap, char *cp, TERM_COLOR *tap, char *tcp)
948 cave_type *c_ptr = &cave[y][x];
950 OBJECT_IDX this_o_idx, next_o_idx = 0;
952 /* Feature code (applying "mimic" field) */
953 FEAT_IDX feat = get_feat_mimic(c_ptr);
956 feature_type *f_ptr = &f_info[feat];
961 /* Boring grids (floors, etc) */
962 if (!have_flag(f_ptr->flags, FF_REMEMBER))
965 * Handle Memorized or visible floor
967 * No visual when blinded.
968 * (to prevent strange effects on darkness breath)
970 * - Can see grids with CAVE_MARK.
971 * - Can see grids with CAVE_LITE or CAVE_MNLT.
972 * (Such grids also have CAVE_VIEW)
973 * - Can see grids with CAVE_VIEW unless darkened by monsters.
976 ((c_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
977 ((c_ptr->info & CAVE_VIEW) && (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
979 /* Normal attr/char */
980 a = f_ptr->x_attr[F_LIT_STANDARD];
981 c = f_ptr->x_char[F_LIT_STANDARD];
983 if (p_ptr->wild_mode)
985 /* Special lighting effects */
987 if (view_special_lite && !is_daytime())
989 /* Use a darkened colour/tile */
990 a = f_ptr->x_attr[F_LIT_DARK];
991 c = f_ptr->x_char[F_LIT_DARK];
995 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
996 else if (darkened_grid(c_ptr))
998 /* Unsafe cave grid -- idea borrowed from Unangband */
999 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1001 /* Access darkness */
1002 f_ptr = &f_info[feat];
1004 /* Char and attr of darkness */
1005 a = f_ptr->x_attr[F_LIT_STANDARD];
1006 c = f_ptr->x_char[F_LIT_STANDARD];
1009 /* Special lighting effects */
1010 else if (view_special_lite)
1012 /* Handle "torch-lit" grids */
1013 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1016 if (view_yellow_lite)
1018 /* Use a brightly lit colour/tile */
1019 a = f_ptr->x_attr[F_LIT_LITE];
1020 c = f_ptr->x_char[F_LIT_LITE];
1024 /* Handle "dark" grids */
1025 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1027 /* Use a darkened colour/tile */
1028 a = f_ptr->x_attr[F_LIT_DARK];
1029 c = f_ptr->x_char[F_LIT_DARK];
1032 /* Handle "out-of-sight" grids */
1033 else if (!(c_ptr->info & CAVE_VIEW))
1036 if (view_bright_lite)
1038 /* Use a darkened colour/tile */
1039 a = f_ptr->x_attr[F_LIT_DARK];
1040 c = f_ptr->x_char[F_LIT_DARK];
1049 /* Unsafe cave grid -- idea borrowed from Unangband */
1050 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1052 /* Access darkness */
1053 f_ptr = &f_info[feat];
1055 /* Normal attr/char */
1056 a = f_ptr->x_attr[F_LIT_STANDARD];
1057 c = f_ptr->x_char[F_LIT_STANDARD];
1061 /* Interesting grids (non-floors) */
1064 /* Memorized grids */
1065 if (c_ptr->info & CAVE_MARK)
1067 /* Normal attr/char */
1068 a = f_ptr->x_attr[F_LIT_STANDARD];
1069 c = f_ptr->x_char[F_LIT_STANDARD];
1071 if (p_ptr->wild_mode)
1073 /* Special lighting effects */
1074 /* Handle "blind" or "night" */
1075 if (view_granite_lite && (p_ptr->blind || !is_daytime()))
1077 /* Use a darkened colour/tile */
1078 a = f_ptr->x_attr[F_LIT_DARK];
1079 c = f_ptr->x_char[F_LIT_DARK];
1083 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1084 else if (darkened_grid(c_ptr) && !p_ptr->blind)
1086 if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
1088 /* Unsafe cave grid -- idea borrowed from Unangband */
1089 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1091 /* Access darkness */
1092 f_ptr = &f_info[feat];
1094 /* Char and attr of darkness */
1095 a = f_ptr->x_attr[F_LIT_STANDARD];
1096 c = f_ptr->x_char[F_LIT_STANDARD];
1098 else if (view_granite_lite && view_bright_lite)
1100 /* Use a darkened colour/tile */
1101 a = f_ptr->x_attr[F_LIT_DARK];
1102 c = f_ptr->x_char[F_LIT_DARK];
1106 /* Special lighting effects */
1107 else if (view_granite_lite)
1109 /* Handle "blind" */
1112 /* Use a darkened colour/tile */
1113 a = f_ptr->x_attr[F_LIT_DARK];
1114 c = f_ptr->x_char[F_LIT_DARK];
1117 /* Handle "torch-lit" grids */
1118 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1121 if (view_yellow_lite)
1123 /* Use a brightly lit colour/tile */
1124 a = f_ptr->x_attr[F_LIT_LITE];
1125 c = f_ptr->x_char[F_LIT_LITE];
1129 /* Handle "view_bright_lite" */
1130 else if (view_bright_lite)
1133 if (!(c_ptr->info & CAVE_VIEW))
1135 /* Use a darkened colour/tile */
1136 a = f_ptr->x_attr[F_LIT_DARK];
1137 c = f_ptr->x_char[F_LIT_DARK];
1141 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1143 /* Use a darkened colour/tile */
1144 a = f_ptr->x_attr[F_LIT_DARK];
1145 c = f_ptr->x_char[F_LIT_DARK];
1148 /* Not glowing correctly */
1149 else if (!have_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(y, x))
1151 /* Use a darkened colour/tile */
1152 a = f_ptr->x_attr[F_LIT_DARK];
1153 c = f_ptr->x_char[F_LIT_DARK];
1162 /* Unsafe cave grid -- idea borrowed from Unangband */
1163 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1165 /* Access feature */
1166 f_ptr = &f_info[feat];
1168 /* Normal attr/char */
1169 a = f_ptr->x_attr[F_LIT_STANDARD];
1170 c = f_ptr->x_char[F_LIT_STANDARD];
1174 if (feat_priority == -1) feat_priority = f_ptr->priority;
1176 /* Save the terrain info for the transparency effects */
1184 /* Hack -- rare random hallucination, except on outer dungeon walls */
1190 image_random(ap, cp);
1195 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1199 /* Acquire object */
1200 o_ptr = &o_list[this_o_idx];
1202 /* Acquire next object */
1203 next_o_idx = o_ptr->next_o_idx;
1205 /* Memorized objects */
1206 if (o_ptr->marked & OM_FOUND)
1208 if (display_autopick)
1212 match_autopick = is_autopick(o_ptr);
1213 if(match_autopick == -1)
1216 act = autopick_list[match_autopick].action;
1218 if ((act & DO_DISPLAY) && (act & display_autopick))
1220 autopick_obj = o_ptr;
1224 match_autopick = -1;
1229 (*cp) = object_char(o_ptr);
1232 (*ap) = object_attr(o_ptr);
1236 /* Hack -- hallucination */
1237 if (p_ptr->image) image_object(ap, cp);
1244 /* Handle monsters */
1245 if (c_ptr->m_idx && display_autopick == 0 )
1247 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1249 /* Visible monster */
1252 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1260 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1261 * flags are always unseen.
1263 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1269 /* Hallucinatory monster */
1270 image_monster(ap, cp);
1275 /* Monster attr/char */
1279 /* Normal monsters */
1280 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1281 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1283 /* Desired monster attr/char */
1289 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1290 * flags are always unseen.
1292 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1299 /*** Monster's attr ***/
1300 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1305 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1307 /* Multi-hued attr */
1308 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1309 else switch (randint1(7))
1311 case 1: *ap = TERM_RED; break;
1312 case 2: *ap = TERM_L_RED; break;
1313 case 3: *ap = TERM_WHITE; break;
1314 case 4: *ap = TERM_L_GREEN; break;
1315 case 5: *ap = TERM_BLUE; break;
1316 case 6: *ap = TERM_L_DARK; break;
1317 case 7: *ap = TERM_GREEN; break;
1320 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1322 /* Use semi-random attr (usually mimics' colors vary) */
1323 *ap = c_ptr->m_idx % 15 + 1;
1331 /*** Monster's char ***/
1332 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1337 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1341 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1342 *cp = tmp_r_ptr->x_char;
1343 *ap = tmp_r_ptr->x_attr;
1347 *cp = (one_in_(25) ?
1348 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1349 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1362 /* Handle "player" */
1363 if (player_bold(y, x))
1365 monster_race *r_ptr = &r_info[0];
1367 /* Get the "player" attr */
1368 *ap = r_ptr->x_attr;
1370 /* Get the "player" char */
1371 *cp = r_ptr->x_char;
1379 * Calculate panel colum of a location in the map
1381 static int panel_col_of(int col)
1383 col -= panel_col_min;
1384 if (use_bigtile) col *= 2;
1390 * Moves the cursor to a given MAP (y,x) location
1392 void move_cursor_relative(int row, int col)
1394 /* Real co-ords convert to screen positions */
1395 row -= panel_row_prt;
1398 Term_gotoxy(panel_col_of(col), row);
1404 * Place an attr/char pair at the given map coordinate, if legal.
1406 void print_rel(char c, byte a, TERM_LEN y, TERM_LEN x)
1408 /* Only do "legal" locations */
1409 if (panel_contains(y, x))
1411 /* Hack -- fake monochrome */
1414 if (world_monster) a = TERM_DARK;
1415 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1416 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1419 /* Draw the char using the attr */
1420 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, 0, 0);
1429 * Memorize interesting viewable object/features in the given grid
1431 * This function should only be called on "legal" grids.
1433 * This function will memorize the object and/or feature in the given
1434 * grid, if they are (1) viewable and (2) interesting. Note that all
1435 * objects are interesting, all terrain features except floors (and
1436 * invisible traps) are interesting, and floors (and invisible traps)
1437 * are interesting sometimes (depending on various options involving
1438 * the illumination of floor grids).
1440 * The automatic memorization of all objects and non-floor terrain
1441 * features as soon as they are displayed allows incredible amounts
1442 * of optimization in various places, especially "map_info()".
1444 * Note that the memorization of objects is completely separate from
1445 * the memorization of terrain features, preventing annoying floor
1446 * memorization when a detected object is picked up from a dark floor,
1447 * and object memorization when an object is dropped into a floor grid
1448 * which is memorized but out-of-sight.
1450 * This function should be called every time the "memorization" of
1451 * a grid (or the object in a grid) is called into question, such
1452 * as when an object is created in a grid, when a terrain feature
1453 * "changes" from "floor" to "non-floor", when any grid becomes
1454 * "illuminated" or "viewable", and when a "floor" grid becomes
1457 * Note the relatively efficient use of this function by the various
1458 * "update_view()" and "update_lite()" calls, to allow objects and
1459 * terrain features to be memorized (and drawn) whenever they become
1460 * viewable or illuminated in any way, but not when they "maintain"
1461 * or "lose" their previous viewability or illumination.
1463 * Note the butchered "internal" version of "player_can_see_bold()",
1464 * optimized primarily for the most common cases, that is, for the
1465 * non-marked floor grids.
1467 void note_spot(POSITION y, POSITION x)
1469 cave_type *c_ptr = &cave[y][x];
1470 OBJECT_IDX this_o_idx, next_o_idx = 0;
1472 /* Blind players see nothing */
1473 if (p_ptr->blind) return;
1475 /* Analyze non-torch-lit grids */
1476 if (!(c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1478 /* Require line of sight to the grid */
1479 if (!(c_ptr->info & (CAVE_VIEW))) return;
1481 /* Require "perma-lite" of the grid */
1482 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1485 if (!p_ptr->see_nocto) return;
1490 /* Hack -- memorize objects */
1491 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1493 object_type *o_ptr = &o_list[this_o_idx];
1495 /* Acquire next object */
1496 next_o_idx = o_ptr->next_o_idx;
1498 /* Memorize objects */
1499 o_ptr->marked |= OM_FOUND;
1503 /* Hack -- memorize grids */
1504 if (!(c_ptr->info & (CAVE_MARK)))
1506 /* Feature code (applying "mimic" field) */
1507 feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
1509 /* Memorize some "boring" grids */
1510 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1512 /* Option -- memorize all torch-lit floors */
1513 if (view_torch_grids &&
1514 ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1517 c_ptr->info |= (CAVE_MARK);
1520 /* Option -- memorize all perma-lit floors */
1521 else if (view_perma_grids && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1524 c_ptr->info |= (CAVE_MARK);
1528 /* Memorize normal grids */
1529 else if (have_flag(f_ptr->flags, FF_LOS))
1532 c_ptr->info |= (CAVE_MARK);
1535 /* Memorize torch-lit walls */
1536 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1539 c_ptr->info |= (CAVE_MARK);
1542 /* Memorize walls seen by noctovision of Ninja */
1543 else if (p_ptr->see_nocto)
1546 c_ptr->info |= (CAVE_MARK);
1549 /* Memorize certain non-torch-lit wall grids */
1550 else if (check_local_illumination(y, x))
1553 c_ptr->info |= (CAVE_MARK);
1557 /* Memorize terrain of the grid */
1558 c_ptr->info |= (CAVE_KNOWN);
1562 void display_dungeon(void)
1571 for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
1573 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
1575 if (in_bounds2(y, x))
1578 /* Examine the grid */
1579 map_info(y, x, &a, &c, &ta, &tc);
1581 /* Hack -- fake monochrome */
1584 if (world_monster) a = TERM_DARK;
1585 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1586 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1589 /* Hack -- Queue it */
1590 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1594 /* Clear out-of-bound tiles */
1596 /* Access darkness */
1597 feature_type *f_ptr = &f_info[feat_none];
1600 a = f_ptr->x_attr[F_LIT_STANDARD];
1603 c = f_ptr->x_char[F_LIT_STANDARD];
1605 /* Hack -- Queue it */
1606 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1614 * Redraw (on the screen) a given MAP location
1616 * This function should only be called on "legal" grids
1618 void lite_spot(POSITION y, POSITION x)
1620 /* Redraw if on screen */
1621 if (panel_contains(y, x) && in_bounds2(y, x))
1629 /* Examine the grid */
1630 map_info(y, x, &a, &c, &ta, &tc);
1632 /* Hack -- fake monochrome */
1635 if (world_monster) a = TERM_DARK;
1636 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1637 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1640 /* Hack -- Queue it */
1641 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1643 /* Update sub-windows */
1644 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1650 * Prints the map of the dungeon
1652 * Note that, for efficiency, we contain an "optimized" version
1653 * of both "lite_spot()" and "print_rel()", and that we use the
1654 * "lite_spot()" function to display the player grid, if needed.
1662 s16b xmin, xmax, ymin, ymax;
1667 Term_get_size(&wid, &hgt);
1669 /* Remove map offset */
1673 /* Access the cursor state */
1674 (void)Term_get_cursor(&v);
1676 /* Hide the cursor */
1677 (void)Term_set_cursor(0);
1680 xmin = (0 < panel_col_min) ? panel_col_min : 0;
1681 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1682 ymin = (0 < panel_row_min) ? panel_row_min : 0;
1683 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1685 /* Bottom section of screen */
1686 for (y = 1; y <= ymin - panel_row_prt; y++)
1688 /* Erase the section */
1689 Term_erase(COL_MAP, y, wid);
1692 /* Top section of screen */
1693 for (y = ymax - panel_row_prt; y <= hgt; y++)
1695 /* Erase the section */
1696 Term_erase(COL_MAP, y, wid);
1700 for (y = ymin; y <= ymax; y++)
1702 /* Scan the columns of row "y" */
1703 for (x = xmin; x <= xmax; x++)
1711 /* Determine what is there */
1712 map_info(y, x, &a, &c, &ta, &tc);
1714 /* Hack -- fake monochrome */
1717 if (world_monster) a = TERM_DARK;
1718 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1719 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1722 /* Efficiency -- Redraw that grid of the map */
1723 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1727 /* Display player */
1728 lite_spot(p_ptr->y, p_ptr->x);
1730 /* Restore the cursor */
1731 (void)Term_set_cursor(v);
1737 * print project path
1739 void prt_path(POSITION y, POSITION x)
1744 byte_hack default_color = TERM_SLATE;
1746 if (!display_path) return;
1747 if (-1 == project_length)
1750 /* Get projection path */
1751 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH|PROJECT_THRU);
1754 p_ptr->redraw |= (PR_MAP);
1760 for (i = 0; i < path_n; i++)
1762 int ny = GRID_Y(path_g[i]);
1763 int nx = GRID_X(path_g[i]);
1764 cave_type *c_ptr = &cave[ny][nx];
1766 if (panel_contains(ny, nx))
1768 TERM_COLOR a = default_color;
1774 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1776 /* Determine what is there */
1777 map_info(ny, nx, &a, &c, &ta, &tc);
1779 if (!is_ascii_graphics(a))
1781 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1783 else if (a == default_color)
1789 if (world_monster) a = TERM_DARK;
1790 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1791 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1796 /* Hack -- Queue it */
1797 Term_queue_bigchar(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
1801 if ((c_ptr->info & CAVE_MARK) && !cave_have_flag_grid(c_ptr, FF_PROJECT)) break;
1804 if (nx == x && ny == y) default_color = TERM_L_DARK;
1809 static cptr simplify_list[][2] =
1816 {"^Amulet of ", "\""},
1817 {"^Scroll of ", "?"},
1818 {"^Scroll titled ", "?"},
1819 {"^Wand of " , "-"},
1821 {"^Staff of " , "_"},
1822 {"^Potion of ", "!"},
1834 static void display_shortened_item_name(object_type *o_ptr, int y)
1841 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
1842 attr = tval_to_attr[o_ptr->tval % 128];
1847 strcpy(buf, _("何か奇妙な物", "something strange"));
1850 for (c = buf; *c; c++)
1853 for (i = 0; simplify_list[i][1]; i++)
1855 cptr org_w = simplify_list[i][0];
1865 if (!strncmp(c, org_w, strlen(org_w)))
1868 cptr tmp = simplify_list[i][1];
1871 tmp = c + strlen(org_w);
1887 if(len + 2 > 12) break;
1894 if(len + 1 > 12) break;
1900 Term_putstr(0, y, 12, attr, buf);
1904 * Display a "small-scale" map of the dungeon in the active Term
1906 void display_map(int *cy, int *cx)
1923 /* Save lighting effects */
1924 bool old_view_special_lite = view_special_lite;
1925 bool old_view_granite_lite = view_granite_lite;
1927 int hgt, wid, yrat, xrat;
1929 int **match_autopick_yx;
1930 object_type ***object_autopick_yx;
1933 Term_get_size(&wid, &hgt);
1936 if (use_bigtile) wid /= 2;
1938 yrat = (cur_hgt + hgt - 1) / hgt;
1939 xrat = (cur_wid + wid - 1) / wid;
1941 /* Disable lighting effects */
1942 view_special_lite = FALSE;
1943 view_granite_lite = FALSE;
1945 /* Allocate the maps */
1946 C_MAKE(ma, (hgt + 2), TERM_COLOR *);
1947 C_MAKE(mc, (hgt + 2), char_ptr);
1948 C_MAKE(mp, (hgt + 2), byte_ptr);
1949 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
1950 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
1952 /* Allocate and wipe each line map */
1953 for (y = 0; y < (hgt + 2); y++)
1955 /* Allocate one row each array */
1956 C_MAKE(ma[y], (wid + 2), TERM_COLOR);
1957 C_MAKE(mc[y], (wid + 2), char);
1958 C_MAKE(mp[y], (wid + 2), byte);
1959 C_MAKE(match_autopick_yx[y], (wid + 2), int);
1960 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
1962 for (x = 0; x < wid + 2; ++x)
1964 match_autopick_yx[y][x] = -1;
1965 object_autopick_yx[y][x] = NULL;
1968 ma[y][x] = TERM_WHITE;
1976 /* Allocate the maps */
1977 C_MAKE(bigma, (cur_hgt + 2), TERM_COLOR *);
1978 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
1979 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
1981 /* Allocate and wipe each line map */
1982 for (y = 0; y < (cur_hgt + 2); y++)
1984 /* Allocate one row each array */
1985 C_MAKE(bigma[y], (cur_wid + 2), TERM_COLOR);
1986 C_MAKE(bigmc[y], (cur_wid + 2), char);
1987 C_MAKE(bigmp[y], (cur_wid + 2), byte);
1989 for (x = 0; x < cur_wid + 2; ++x)
1992 bigma[y][x] = TERM_WHITE;
2000 /* Fill in the map */
2001 for (i = 0; i < cur_wid; ++i)
2003 for (j = 0; j < cur_hgt; ++j)
2013 /* Extract the current attr/char at that map location */
2014 map_info(j, i, &ta, &tc, &ta, &tc);
2016 /* Extract the priority */
2017 tp = (byte_hack)feat_priority;
2019 if(match_autopick!=-1
2020 && (match_autopick_yx[y][x] == -1
2021 || match_autopick_yx[y][x] > match_autopick))
2023 match_autopick_yx[y][x] = match_autopick;
2024 object_autopick_yx[y][x] = autopick_obj;
2028 /* Save the char, attr and priority */
2029 bigmc[j+1][i+1] = tc;
2030 bigma[j+1][i+1] = ta;
2031 bigmp[j+1][i+1] = tp;
2035 for (j = 0; j < cur_hgt; ++j)
2037 for (i = 0; i < cur_wid; ++i)
2043 tc = bigmc[j+1][i+1];
2044 ta = bigma[j+1][i+1];
2045 tp = bigmp[j+1][i+1];
2047 /* rare feature has more priority */
2053 for (t = 0; t < 8; t++)
2055 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2056 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2066 /* Save the char, attr and priority */
2079 /* Draw the corners */
2080 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2082 /* Draw the horizontal edges */
2083 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2085 /* Draw the vertical edges */
2086 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2089 /* Display each map line in order */
2090 for (y = 0; y < hgt + 2; ++y)
2092 /* Start a new line */
2093 Term_gotoxy(COL_MAP, y);
2095 /* Display the line */
2096 for (x = 0; x < wid + 2; ++x)
2101 /* Hack -- fake monochrome */
2104 if (world_monster) ta = TERM_DARK;
2105 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2106 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2109 /* Add the character */
2110 Term_add_bigch(ta, tc);
2115 for (y = 1; y < hgt + 1; ++y)
2117 match_autopick = -1;
2118 for (x = 1; x <= wid; x++){
2119 if (match_autopick_yx[y][x] != -1 &&
2120 (match_autopick > match_autopick_yx[y][x] ||
2121 match_autopick == -1)){
2122 match_autopick = match_autopick_yx[y][x];
2123 autopick_obj = object_autopick_yx[y][x];
2127 /* Clear old display */
2128 Term_putstr(0, y, 12, 0, " ");
2130 if (match_autopick != -1)
2132 display_shortened_item_name(autopick_obj, y);
2135 char buf[13] = "\0";
2136 strncpy(buf,autopick_list[match_autopick].name,12);
2144 /* Player location */
2145 (*cy) = p_ptr->y / yrat + 1 + ROW_MAP;
2147 (*cx) = p_ptr->x / xrat + 1 + COL_MAP;
2149 (*cx) = (p_ptr->x / xrat + 1) * 2 + COL_MAP;
2151 /* Restore lighting effects */
2152 view_special_lite = old_view_special_lite;
2153 view_granite_lite = old_view_granite_lite;
2155 /* Free each line map */
2156 for (y = 0; y < (hgt + 2); y++)
2158 /* Free one row each array */
2159 C_KILL(ma[y], (wid + 2), TERM_COLOR);
2160 C_KILL(mc[y], (wid + 2), char);
2161 C_KILL(mp[y], (wid + 2), byte);
2162 C_KILL(match_autopick_yx[y], (wid + 2), int);
2163 C_KILL(object_autopick_yx[y], (wid + 2), object_type *);
2166 /* Free each line map */
2167 C_KILL(ma, (hgt + 2), TERM_COLOR *);
2168 C_KILL(mc, (hgt + 2), char_ptr);
2169 C_KILL(mp, (hgt + 2), byte_ptr);
2170 C_KILL(match_autopick_yx, (hgt + 2), sint_ptr);
2171 C_KILL(object_autopick_yx, (hgt + 2), object_type **);
2173 /* Free each line map */
2174 for (y = 0; y < (cur_hgt + 2); y++)
2176 /* Free one row each array */
2177 C_KILL(bigma[y], (cur_wid + 2), TERM_COLOR);
2178 C_KILL(bigmc[y], (cur_wid + 2), char);
2179 C_KILL(bigmp[y], (cur_wid + 2), byte);
2182 /* Free each line map */
2183 C_KILL(bigma, (cur_hgt + 2), TERM_COLOR *);
2184 C_KILL(bigmc, (cur_hgt + 2), char_ptr);
2185 C_KILL(bigmp, (cur_hgt + 2), byte_ptr);
2190 * Display a "small-scale" map of the dungeon for the player
2192 * Currently, the "player" is displayed on the map. XXX XXX XXX
2194 void do_cmd_view_map(void)
2199 /* Save the screen */
2203 prt(_("お待ち下さい...", "Please wait..."), 0, 0);
2208 /* Clear the screen */
2211 display_autopick = 0;
2213 /* Display the map */
2214 display_map(&cy, &cx);
2217 if(max_autopick && !p_ptr->wild_mode)
2219 display_autopick = ITEM_DISPLAY;
2226 int wid, hgt, row_message;
2228 Term_get_size(&wid, &hgt);
2229 row_message = hgt - 1;
2231 put_str(_("何かキーを押してください('M':拾う 'N':放置 'D':M+N 'K':壊すアイテムを表示)",
2232 " Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items."), row_message, 1);
2234 /* Hilite the player */
2235 move_cursor(cy, cx);
2240 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2242 flag = DONT_AUTOPICK;
2244 flag = DO_AUTODESTROY;
2246 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2252 if (~display_autopick & flag)
2253 display_autopick |= flag;
2255 display_autopick &= ~flag;
2256 /* Display the map */
2257 display_map(&cy, &cx);
2260 display_autopick = 0;
2265 put_str(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"), 23, 30);
2266 /* Hilite the player */
2267 move_cursor(cy, cx);
2272 /* Restore the screen */
2281 * Some comments on the cave grid flags. -BEN-
2284 * One of the major bottlenecks in previous versions of Angband was in
2285 * the calculation of "line of sight" from the player to various grids,
2286 * such as monsters. This was such a nasty bottleneck that a lot of
2287 * silly things were done to reduce the dependancy on "line of sight",
2288 * for example, you could not "see" any grids in a lit room until you
2289 * actually entered the room, and there were all kinds of bizarre grid
2290 * flags to enable this behavior. This is also why the "call light"
2291 * spells always lit an entire room.
2293 * The code below provides functions to calculate the "field of view"
2294 * for the player, which, once calculated, provides extremely fast
2295 * calculation of "line of sight from the player", and to calculate
2296 * the "field of torch lite", which, again, once calculated, provides
2297 * extremely fast calculation of "which grids are lit by the player's
2298 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2299 * "GRID_LITE", as appropriate, these functions maintain an array for
2300 * each of these two flags, each array containing the locations of all
2301 * of the grids marked with the appropriate flag, which can be used to
2302 * very quickly scan through all of the grids in a given set.
2304 * To allow more "semantically valid" field of view semantics, whenever
2305 * the field of view (or the set of torch lit grids) changes, all of the
2306 * grids in the field of view (or the set of torch lit grids) are "drawn"
2307 * so that changes in the world will become apparent as soon as possible.
2308 * This has been optimized so that only grids which actually "change" are
2309 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2310 * of the grids which are entering or leaving the relevent set of grids.
2312 * These new methods are so efficient that the old nasty code was removed.
2314 * Note that there is no reason to "update" the "viewable space" unless
2315 * the player "moves", or walls/doors are created/destroyed, and there
2316 * is no reason to "update" the "torch lit grids" unless the field of
2317 * view changes, or the "light radius" changes. This means that when
2318 * the player is resting, or digging, or doing anything that does not
2319 * involve movement or changing the state of the dungeon, there is no
2320 * need to update the "view" or the "lite" regions, which is nice.
2322 * Note that the calls to the nasty "los()" function have been reduced
2323 * to a bare minimum by the use of the new "field of view" calculations.
2325 * I wouldn't be surprised if slight modifications to the "update_view()"
2326 * function would allow us to determine "reverse line-of-sight" as well
2327 * as "normal line-of-sight", which would allow monsters to use a more
2328 * "correct" calculation to determine if they can "see" the player. For
2329 * now, monsters simply "cheat" somewhat and assume that if the player
2330 * has "line of sight" to the monster, then the monster can "pretend"
2331 * that it has "line of sight" to the player.
2334 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2335 * grid and maintains an array of all "CAVE_LITE" grids.
2337 * This set of grids is the complete set of all grids which are lit by
2338 * the players light source, which allows the "player_can_see_bold()"
2339 * function to work very quickly.
2341 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2342 * fact, the player (unless blind) can always "see" all grids which are
2343 * marked as "CAVE_LITE", unless they are "off screen".
2346 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2347 * grid and maintains an array of all "CAVE_VIEW" grids.
2349 * This set of grids is the complete set of all grids within line of sight
2350 * of the player, allowing the "player_has_los_bold()" macro to work very
2354 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2355 * temporary internal flag to mark those grids which are not only in view,
2356 * but which are also "easily" in line of sight of the player. This flag
2357 * is always cleared when we are done.
2360 * The current "update_lite()" and "update_view()" algorithms use the
2361 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2362 * to keep track of which grids were previously marked as "CAVE_LITE" or
2363 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2365 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2366 * for various other purposes, such as spreading lite or darkness during
2367 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2370 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2371 * in some way permanently lit. However, for the player to "see" anything
2372 * in the grid, as determined by "player_can_see()", the player must not be
2373 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2374 * grids, even if marked as "perma lit", are only illuminated if they touch
2375 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2378 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2379 * that even if the player cannot "see" the grid, he "knows" the terrain in
2380 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2381 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2382 * or when one of the "memorize floor grids" options induces memorization.
2384 * Objects are "memorized" in a different way, using a special "marked" flag
2385 * on the object itself, which is set when an object is observed or detected.
2388 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2389 * and should be illuminated by "lite room" and "darkness" spells.
2392 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2393 * and should be unavailable for "teleportation" destinations.
2396 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2397 * which is observed, and the "view_torch_grids" allows the player to memorize
2398 * every torch-lit grid. The player will always memorize important walls,
2399 * doors, stairs, and other terrain features, as well as any "detected" grids.
2401 * Note that the new "update_view()" method allows, among other things, a room
2402 * to be "partially" seen as the player approaches it, with a growing cone of
2403 * floor appearing as the player gets closer to the door. Also, by not turning
2404 * on the "memorize perma-lit grids" option, the player will only "see" those
2405 * floor grids which are actually in line of sight.
2407 * And my favorite "plus" is that you can now use a special option to draw the
2408 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2409 * grids dimly), providing a "pretty" effect as the player runs around, and
2410 * to efficiently display the "torch lite" in a special color.
2413 * Some comments on the "update_view()" algorithm...
2415 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2416 * and only has to call "los()" on the borderline cases. The major axes/diags
2417 * even terminate early when they hit walls. I need to find a quick way
2418 * to "terminate" the other scans.
2420 * Note that in the worst case (a big empty area with say 5% scattered walls),
2421 * each of the 1500 or so nearby grids is checked once, most of them getting
2422 * an "instant" rating, and only a small portion requiring a call to "los()".
2424 * The only time that the algorithm appears to be "noticeably" too slow is
2425 * when running, and this is usually only important in town, since the town
2426 * provides about the worst scenario possible, with large open regions and
2427 * a few scattered obstructions. There is a special "efficiency" option to
2428 * allow the player to reduce his field of view in town, if needed.
2430 * In the "best" case (say, a normal stretch of corridor), the algorithm
2431 * makes one check for each viewable grid, and makes no calls to "los()".
2432 * So running in corridors is very fast, and if a lot of monsters are
2433 * nearby, it is much faster than the old methods.
2435 * Note that resting, most normal commands, and several forms of running,
2436 * plus all commands executed near large groups of monsters, are strictly
2437 * more efficient with "update_view()" that with the old "compute los() on
2438 * demand" method, primarily because once the "field of view" has been
2439 * calculated, it does not have to be recalculated until the player moves
2440 * (or a wall or door is created or destroyed).
2442 * Note that we no longer have to do as many "los()" checks, since once the
2443 * "view" region has been built, very few things cause it to be "changed"
2444 * (player movement, and the opening/closing of doors, changes in wall status).
2445 * Note that door/wall changes are only relevant when the door/wall itself is
2446 * in the "view" region.
2448 * The algorithm seems to only call "los()" from zero to ten times, usually
2449 * only when coming down a corridor into a room, or standing in a room, just
2450 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2451 * we will be reducing the calls to "los()".
2453 * I am thinking in terms of an algorithm that "walks" from the central point
2454 * out to the maximal "distance", at each point, determining the "view" code
2455 * (above). For each grid not on a major axis or diagonal, the "view" code
2456 * depends on the "cave_los_bold()" and "view" of exactly two other grids
2457 * (the one along the nearest diagonal, and the one next to that one, see
2458 * "update_view_aux()"...).
2460 * We "memorize" the viewable space array, so that at the cost of under 3000
2461 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2462 * each grid actually in the "viewable space". And for another 3000 bytes,
2463 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2464 * are also used by other routines, thus reducing the cost to almost nothing.
2466 * A similar thing is done for "forget_lite()" in which case the savings are
2467 * much less, but save us from doing bizarre maintenance checking.
2469 * In the worst "normal" case (in the middle of the town), the reachable space
2470 * actually reaches to more than half of the largest possible "circle" of view,
2471 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2472 * where all the walls have been removed), the reachable space actually reaches
2473 * the theoretical maximum size of just under 1500 grids.
2475 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2476 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2477 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2478 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2479 * entire possible space (including initialization) in one step per grid. If
2480 * we do the "clearing" as a separate step (and use an array of "view" grids),
2481 * then the clearing will take as many steps as grids that were viewed, and the
2482 * algorithm will be able to "stop" scanning at various points.
2483 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2494 * Actually erase the entire "lite" array, redrawing every grid
2496 void forget_lite(void)
2500 /* None to forget */
2501 if (!lite_n) return;
2503 /* Clear them all */
2504 for (i = 0; i < lite_n; i++)
2509 /* Forget "LITE" flag */
2510 cave[y][x].info &= ~(CAVE_LITE);
2513 /* lite_spot(y, x); Perhaps don't need? */
2522 * For delayed visual update
2524 #define cave_note_and_redraw_later(C,Y,X) \
2526 (C)->info |= CAVE_NOTE; \
2527 cave_redraw_later((C), (Y), (X)); \
2532 * For delayed visual update
2534 #define cave_redraw_later(C,Y,X) \
2536 if (!((C)->info & CAVE_REDRAW)) \
2538 (C)->info |= CAVE_REDRAW; \
2539 redraw_y[redraw_n] = (Y); \
2540 redraw_x[redraw_n++] = (X); \
2548 * This macro allows us to efficiently add a grid to the "lite" array,
2549 * note that we are never called for illegal grids, or for grids which
2550 * have already been placed into the "lite" array, and we are never
2551 * called when the "lite" array is full.
2553 #define cave_lite_hack(Y,X) \
2555 if (!(cave[Y][X].info & (CAVE_LITE))) \
2557 cave[Y][X].info |= (CAVE_LITE); \
2558 lite_y[lite_n] = (Y); \
2559 lite_x[lite_n++] = (X); \
2565 * Update the set of grids "illuminated" by the player's lite.
2567 * This routine needs to use the results of "update_view()"
2569 * Note that "blindness" does NOT affect "torch lite". Be careful!
2571 * We optimize most lites (all non-artifact lites) by using "obvious"
2572 * facts about the results of "small" lite radius, and we attempt to
2573 * list the "nearby" grids before the more "distant" ones in the
2574 * array of torch-lit grids.
2576 * We assume that "radius zero" lite is in fact no lite at all.
2578 * Torch Lantern Artifacts
2588 void update_lite(void)
2590 int i, x, y, min_x, max_x, min_y, max_y;
2591 int p = p_ptr->cur_lite;
2594 /*** Special case ***/
2597 /* Hack -- Player has no lite */
2600 /* Forget the old lite */
2601 /* forget_lite(); Perhaps don't need? */
2603 /* Add it to later visual update */
2604 cave_redraw_later(&cave[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
2608 /*** Save the old "lite" grids for later ***/
2610 /* Clear them all */
2611 for (i = 0; i < lite_n; i++)
2616 /* Mark the grid as not "lite" */
2617 cave[y][x].info &= ~(CAVE_LITE);
2619 /* Mark the grid as "seen" */
2620 cave[y][x].info |= (CAVE_TEMP);
2622 /* Add it to the "seen" set */
2632 /*** Collect the new "lite" grids ***/
2634 /* Radius 1 -- torch radius */
2638 cave_lite_hack(p_ptr->y, p_ptr->x);
2641 cave_lite_hack(p_ptr->y+1, p_ptr->x);
2642 cave_lite_hack(p_ptr->y-1, p_ptr->x);
2643 cave_lite_hack(p_ptr->y, p_ptr->x+1);
2644 cave_lite_hack(p_ptr->y, p_ptr->x-1);
2646 /* Diagonal grids */
2647 cave_lite_hack(p_ptr->y+1, p_ptr->x+1);
2648 cave_lite_hack(p_ptr->y+1, p_ptr->x-1);
2649 cave_lite_hack(p_ptr->y-1, p_ptr->x+1);
2650 cave_lite_hack(p_ptr->y-1, p_ptr->x-1);
2653 /* Radius 2 -- lantern radius */
2656 /* South of the player */
2657 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
2659 cave_lite_hack(p_ptr->y+2, p_ptr->x);
2660 cave_lite_hack(p_ptr->y+2, p_ptr->x+1);
2661 cave_lite_hack(p_ptr->y+2, p_ptr->x-1);
2664 /* North of the player */
2665 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
2667 cave_lite_hack(p_ptr->y-2, p_ptr->x);
2668 cave_lite_hack(p_ptr->y-2, p_ptr->x+1);
2669 cave_lite_hack(p_ptr->y-2, p_ptr->x-1);
2672 /* East of the player */
2673 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
2675 cave_lite_hack(p_ptr->y, p_ptr->x+2);
2676 cave_lite_hack(p_ptr->y+1, p_ptr->x+2);
2677 cave_lite_hack(p_ptr->y-1, p_ptr->x+2);
2680 /* West of the player */
2681 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
2683 cave_lite_hack(p_ptr->y, p_ptr->x-2);
2684 cave_lite_hack(p_ptr->y+1, p_ptr->x-2);
2685 cave_lite_hack(p_ptr->y-1, p_ptr->x-2);
2689 /* Radius 3+ -- artifact radius */
2694 /* Paranoia -- see "LITE_MAX" */
2697 /* South-East of the player */
2698 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
2700 cave_lite_hack(p_ptr->y+2, p_ptr->x+2);
2703 /* South-West of the player */
2704 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
2706 cave_lite_hack(p_ptr->y+2, p_ptr->x-2);
2709 /* North-East of the player */
2710 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
2712 cave_lite_hack(p_ptr->y-2, p_ptr->x+2);
2715 /* North-West of the player */
2716 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
2718 cave_lite_hack(p_ptr->y-2, p_ptr->x-2);
2722 min_y = p_ptr->y - p;
2723 if (min_y < 0) min_y = 0;
2726 max_y = p_ptr->y + p;
2727 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
2730 min_x = p_ptr->x - p;
2731 if (min_x < 0) min_x = 0;
2734 max_x = p_ptr->x + p;
2735 if (max_x > cur_wid-1) max_x = cur_wid-1;
2737 /* Scan the maximal box */
2738 for (y = min_y; y <= max_y; y++)
2740 for (x = min_x; x <= max_x; x++)
2742 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
2743 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
2745 /* Skip the "central" grids (above) */
2746 if ((dy <= 2) && (dx <= 2)) continue;
2748 /* Hack -- approximate the distance */
2749 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2751 /* Skip distant grids */
2752 if (d > p) continue;
2754 /* Viewable, nearby, grids get "torch lit" */
2755 if (cave[y][x].info & CAVE_VIEW)
2757 /* This grid is "torch lit" */
2758 cave_lite_hack(y, x);
2765 /*** Complete the algorithm ***/
2767 /* Draw the new grids */
2768 for (i = 0; i < lite_n; i++)
2773 c_ptr = &cave[y][x];
2775 /* Update fresh grids */
2776 if (c_ptr->info & (CAVE_TEMP)) continue;
2778 /* Add it to later visual update */
2779 cave_note_and_redraw_later(c_ptr, y, x);
2782 /* Clear them all */
2783 for (i = 0; i < temp_n; i++)
2788 c_ptr = &cave[y][x];
2790 /* No longer in the array */
2791 c_ptr->info &= ~(CAVE_TEMP);
2793 /* Update stale grids */
2794 if (c_ptr->info & (CAVE_LITE)) continue;
2796 /* Add it to later visual update */
2797 cave_redraw_later(c_ptr, y, x);
2803 /* Mega-Hack -- Visual update later */
2804 p_ptr->update |= (PU_DELAY_VIS);
2808 static bool mon_invis;
2809 static POSITION mon_fy, mon_fx;
2812 * Add a square to the changes array
2814 static void mon_lite_hack(POSITION y, POSITION x)
2820 /* We trust this grid is in bounds */
2821 /* if (!in_bounds2(y, x)) return; */
2823 c_ptr = &cave[y][x];
2825 /* Want a unlit square in view of the player */
2826 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
2828 if (!cave_los_grid(c_ptr))
2830 /* Hack -- Prevent monster lite leakage in walls */
2832 /* Horizontal walls between player and a monster */
2833 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2835 dpf = p_ptr->y - mon_fy;
2837 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2839 /* Only first wall viewed from mid-x is lit */
2842 if (!cave_los_bold(y, x + 1)) return;
2844 else if (x > midpoint)
2846 if (!cave_los_bold(y, x - 1)) return;
2849 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2850 else if (mon_invis) return;
2853 /* Vertical walls between player and a monster */
2854 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2856 dpf = p_ptr->x - mon_fx;
2858 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2860 /* Only first wall viewed from mid-y is lit */
2863 if (!cave_los_bold(y + 1, x)) return;
2865 else if (y > midpoint)
2867 if (!cave_los_bold(y - 1, x)) return;
2870 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2871 else if (mon_invis) return;
2875 /* We trust temp_n does not exceed TEMP_MAX */
2878 if (!(c_ptr->info & CAVE_MNDK))
2880 /* Save this square */
2889 /* No longer dark */
2890 c_ptr->info &= ~(CAVE_MNDK);
2894 c_ptr->info |= CAVE_MNLT;
2899 * Add a square to the changes array
2901 static void mon_dark_hack(POSITION y, POSITION x)
2904 int midpoint, dpf, d;
2906 /* We trust this grid is in bounds */
2907 /* if (!in_bounds2(y, x)) return; */
2909 c_ptr = &cave[y][x];
2911 /* Want a unlit and undarkened square in view of the player */
2912 if ((c_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
2914 if (!cave_los_grid(c_ptr) && !cave_have_flag_grid(c_ptr, FF_PROJECT))
2916 /* Hack -- Prevent monster dark lite leakage in walls */
2918 /* Horizontal walls between player and a monster */
2919 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2921 dpf = p_ptr->y - mon_fy;
2923 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2925 /* Only first wall viewed from mid-x is lit */
2928 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
2930 else if (x > midpoint)
2932 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
2935 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2936 else if (mon_invis) return;
2939 /* Vertical walls between player and a monster */
2940 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2942 dpf = p_ptr->x - mon_fx;
2944 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2946 /* Only first wall viewed from mid-y is lit */
2949 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
2951 else if (y > midpoint)
2953 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
2956 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2957 else if (mon_invis) return;
2961 /* We trust temp_n does not exceed TEMP_MAX */
2963 /* Save this square */
2969 c_ptr->info |= CAVE_MNDK;
2974 * Update squares illuminated or darkened by monsters.
2976 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
2977 * denote squares illuminated by monsters.
2979 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
2980 * updating. Only squares in view of the player, whos state
2981 * changes are drawn via lite_spot().
2983 void update_mon_lite(void)
2989 void (*add_mon_lite)(POSITION, POSITION);
2994 /* Non-Ninja player in the darkness */
2995 int dis_lim = ((d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
2996 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
2998 /* Clear all monster lit squares */
2999 for (i = 0; i < mon_lite_n; i++)
3002 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3004 /* Set temp or xtra flag */
3005 c_ptr->info |= (c_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
3007 /* Clear monster illumination flag */
3008 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3011 /* Empty temp list of new squares to lite up */
3014 /* If a monster stops time, don't process */
3017 monster_type *m_ptr;
3018 monster_race *r_ptr;
3020 /* Loop through monsters, adding newly lit squares to changes list */
3021 for (i = 1; i < m_max; i++)
3024 r_ptr = &r_info[m_ptr->r_idx];
3026 /* Skip dead monsters */
3027 if (!m_ptr->r_idx) continue;
3029 /* Is it too far away? */
3030 if (m_ptr->cdis > dis_lim) continue;
3032 /* Get lite radius */
3035 /* Note the radii are cumulative */
3036 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3037 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3038 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3039 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3041 /* Exit if has no light */
3045 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;
3046 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3047 add_mon_lite = mon_lite_hack;
3052 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && !is_daytime()))) continue;
3053 add_mon_lite = mon_dark_hack;
3054 f_flag = FF_PROJECT;
3055 rad = -rad; /* Use absolute value */
3058 /* Access the location */
3062 /* Is the monster visible? */
3063 mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
3065 /* The square it is on */
3066 add_mon_lite(mon_fy, mon_fx);
3068 /* Adjacent squares */
3069 add_mon_lite(mon_fy + 1, mon_fx);
3070 add_mon_lite(mon_fy - 1, mon_fx);
3071 add_mon_lite(mon_fy, mon_fx + 1);
3072 add_mon_lite(mon_fy, mon_fx - 1);
3073 add_mon_lite(mon_fy + 1, mon_fx + 1);
3074 add_mon_lite(mon_fy + 1, mon_fx - 1);
3075 add_mon_lite(mon_fy - 1, mon_fx + 1);
3076 add_mon_lite(mon_fy - 1, mon_fx - 1);
3081 /* South of the monster */
3082 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
3084 add_mon_lite(mon_fy + 2, mon_fx + 1);
3085 add_mon_lite(mon_fy + 2, mon_fx);
3086 add_mon_lite(mon_fy + 2, mon_fx - 1);
3088 c_ptr = &cave[mon_fy + 2][mon_fx];
3091 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3093 add_mon_lite(mon_fy + 3, mon_fx + 1);
3094 add_mon_lite(mon_fy + 3, mon_fx);
3095 add_mon_lite(mon_fy + 3, mon_fx - 1);
3099 /* North of the monster */
3100 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
3102 add_mon_lite(mon_fy - 2, mon_fx + 1);
3103 add_mon_lite(mon_fy - 2, mon_fx);
3104 add_mon_lite(mon_fy - 2, mon_fx - 1);
3106 c_ptr = &cave[mon_fy - 2][mon_fx];
3109 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3111 add_mon_lite(mon_fy - 3, mon_fx + 1);
3112 add_mon_lite(mon_fy - 3, mon_fx);
3113 add_mon_lite(mon_fy - 3, mon_fx - 1);
3117 /* East of the monster */
3118 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
3120 add_mon_lite(mon_fy + 1, mon_fx + 2);
3121 add_mon_lite(mon_fy, mon_fx + 2);
3122 add_mon_lite(mon_fy - 1, mon_fx + 2);
3124 c_ptr = &cave[mon_fy][mon_fx + 2];
3127 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3129 add_mon_lite(mon_fy + 1, mon_fx + 3);
3130 add_mon_lite(mon_fy, mon_fx + 3);
3131 add_mon_lite(mon_fy - 1, mon_fx + 3);
3135 /* West of the monster */
3136 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
3138 add_mon_lite(mon_fy + 1, mon_fx - 2);
3139 add_mon_lite(mon_fy, mon_fx - 2);
3140 add_mon_lite(mon_fy - 1, mon_fx - 2);
3142 c_ptr = &cave[mon_fy][mon_fx - 2];
3145 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3147 add_mon_lite(mon_fy + 1, mon_fx - 3);
3148 add_mon_lite(mon_fy, mon_fx - 3);
3149 add_mon_lite(mon_fy - 1, mon_fx - 3);
3157 /* South-East of the monster */
3158 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
3160 add_mon_lite(mon_fy + 2, mon_fx + 2);
3163 /* South-West of the monster */
3164 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
3166 add_mon_lite(mon_fy + 2, mon_fx - 2);
3169 /* North-East of the monster */
3170 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
3172 add_mon_lite(mon_fy - 2, mon_fx + 2);
3175 /* North-West of the monster */
3176 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
3178 add_mon_lite(mon_fy - 2, mon_fx - 2);
3184 /* Save end of list of new squares */
3188 * Look at old set flags to see if there are any changes.
3190 for (i = 0; i < mon_lite_n; i++)
3195 /* We trust this grid is in bounds */
3198 c_ptr = &cave[fy][fx];
3200 if (c_ptr->info & CAVE_TEMP) /* Pervious lit */
3202 /* It it no longer lit? */
3203 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3205 /* It is now unlit */
3206 /* Add it to later visual update */
3207 cave_note_and_redraw_later(c_ptr, fy, fx);
3210 else /* Pervious darkened */
3212 /* It it no longer darken? */
3213 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3215 /* It is now undarken */
3216 /* Add it to later visual update */
3217 cave_note_and_redraw_later(c_ptr, fy, fx);
3221 /* Add to end of temp array */
3222 temp_x[temp_n] = fx;
3223 temp_y[temp_n] = fy;
3227 /* Clear the lite array */
3230 /* Copy the temp array into the lit array lighting the new squares. */
3231 for (i = 0; i < end_temp; i++)
3236 /* We trust this grid is in bounds */
3239 c_ptr = &cave[fy][fx];
3241 if (c_ptr->info & CAVE_MNLT) /* Lit */
3243 /* The is the square newly lit and visible? */
3244 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3247 /* Add it to later visual update */
3248 cave_note_and_redraw_later(c_ptr, fy, fx);
3253 /* The is the square newly darkened and visible? */
3254 if ((c_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3256 /* It is now darkened */
3257 /* Add it to later visual update */
3258 cave_note_and_redraw_later(c_ptr, fy, fx);
3262 /* Save in the monster lit or darkened array */
3263 mon_lite_x[mon_lite_n] = fx;
3264 mon_lite_y[mon_lite_n] = fy;
3268 /* Clear the temp flag for the old lit or darken grids */
3269 for (i = end_temp; i < temp_n; i++)
3271 /* We trust this grid is in bounds */
3273 cave[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3276 /* Finished with temp_n */
3279 /* Mega-Hack -- Visual update later */
3280 p_ptr->update |= (PU_DELAY_VIS);
3282 p_ptr->monlite = (cave[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
3284 if (p_ptr->special_defense & NINJA_S_STEALTH)
3286 if (p_ptr->old_monlite != p_ptr->monlite)
3290 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
3294 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
3298 p_ptr->old_monlite = p_ptr->monlite;
3301 void clear_mon_lite(void)
3306 /* Clear all monster lit squares */
3307 for (i = 0; i < mon_lite_n; i++)
3310 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3312 /* Clear monster illumination flag */
3313 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3316 /* Empty the array */
3323 * Clear the viewable space
3325 void forget_view(void)
3331 /* None to forget */
3332 if (!view_n) return;
3334 /* Clear them all */
3335 for (i = 0; i < view_n; i++)
3337 POSITION y = view_y[i];
3338 POSITION x = view_x[i];
3340 /* Access the grid */
3341 c_ptr = &cave[y][x];
3343 /* Forget that the grid is viewable */
3344 c_ptr->info &= ~(CAVE_VIEW);
3346 /* if (!panel_contains(y, x)) continue; */
3348 /* Update the screen */
3349 /* lite_spot(y, x); Perhaps don't need? */
3359 * This macro allows us to efficiently add a grid to the "view" array,
3360 * note that we are never called for illegal grids, or for grids which
3361 * have already been placed into the "view" array, and we are never
3362 * called when the "view" array is full.
3364 #define cave_view_hack(C,Y,X) \
3366 if (!((C)->info & (CAVE_VIEW))){\
3367 (C)->info |= (CAVE_VIEW); \
3368 view_y[view_n] = (Y); \
3369 view_x[view_n] = (X); \
3376 * Helper function for "update_view()" below
3378 * We are checking the "viewability" of grid (y,x) by the player.
3380 * This function assumes that (y,x) is legal (i.e. on the map).
3382 * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
3383 * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
3385 * Note that we are using the "CAVE_XTRA" field for marking grids as
3386 * "easily viewable". This bit is cleared at the end of "update_view()".
3388 * This function adds (y,x) to the "viewable set" if necessary.
3390 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3392 static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
3394 bool f1, f2, v1, v2, z1, z2, wall;
3398 cave_type *g1_c_ptr;
3399 cave_type *g2_c_ptr;
3401 /* Access the grids */
3402 g1_c_ptr = &cave[y1][x1];
3403 g2_c_ptr = &cave[y2][x2];
3406 /* Check for walls */
3407 f1 = (cave_los_grid(g1_c_ptr));
3408 f2 = (cave_los_grid(g2_c_ptr));
3410 /* Totally blocked by physical walls */
3411 if (!f1 && !f2) return (TRUE);
3414 /* Check for visibility */
3415 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3416 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3418 /* Totally blocked by "unviewable neighbors" */
3419 if (!v1 && !v2) return (TRUE);
3422 /* Access the grid */
3423 c_ptr = &cave[y][x];
3426 /* Check for walls */
3427 wall = (!cave_los_grid(c_ptr));
3430 /* Check the "ease" of visibility */
3431 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3432 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3434 /* Hack -- "easy" plus "easy" yields "easy" */
3437 c_ptr->info |= (CAVE_XTRA);
3439 cave_view_hack(c_ptr, y, x);
3444 /* Hack -- primary "easy" yields "viewed" */
3447 cave_view_hack(c_ptr, y, x);
3452 /* Hack -- "view" plus "view" yields "view" */
3455 /* c_ptr->info |= (CAVE_XTRA); */
3457 cave_view_hack(c_ptr, y, x);
3463 /* Mega-Hack -- the "los()" function works poorly on walls */
3466 cave_view_hack(c_ptr, y, x);
3472 /* Hack -- check line of sight */
3473 if (los(p_ptr->y, p_ptr->x, y, x))
3475 cave_view_hack(c_ptr, y, x);
3481 /* Assume no line of sight. */
3488 * Calculate the viewable space
3490 * 1: Process the player
3491 * 1a: The player is always (easily) viewable
3492 * 2: Process the diagonals
3493 * 2a: The diagonals are (easily) viewable up to the first wall
3494 * 2b: But never go more than 2/3 of the "full" distance
3495 * 3: Process the main axes
3496 * 3a: The main axes are (easily) viewable up to the first wall
3497 * 3b: But never go more than the "full" distance
3498 * 4: Process sequential "strips" in each of the eight octants
3499 * 4a: Each strip runs along the previous strip
3500 * 4b: The main axes are "previous" to the first strip
3501 * 4c: Process both "sides" of each "direction" of each strip
3502 * 4c1: Each side aborts as soon as possible
3503 * 4c2: Each side tells the next strip how far it has to check
3505 * Note that the octant processing involves some pretty interesting
3506 * observations involving when a grid might possibly be viewable from
3507 * a given grid, and on the order in which the strips are processed.
3509 * Note the use of the mathematical facts shown below, which derive
3510 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3511 * hypotenuse of a right triangle is primarily determined by the length
3512 * of the longest side, when one side is small, and is strictly less
3513 * than one-and-a-half times as long as the longest side when both of
3514 * the sides are large.
3516 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3517 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3519 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3521 * These observations are important because the calculation of the actual
3522 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3523 * while for small values (up to about 20 or so), the approximations above
3524 * are correct to within an error of at most one grid or so.
3526 * Observe the use of "full" and "over" in the code below, and the use of
3527 * the specialized calculation involving "limit", all of which derive from
3528 * the observations given above. Basically, we note that the "circle" of
3529 * view is completely contained in an "octagon" whose bounds are easy to
3530 * determine, and that only a few steps are needed to derive the actual
3531 * bounds of the circle given the bounds of the octagon.
3533 * Note that by skipping all the grids in the corners of the octagon, we
3534 * place an upper limit on the number of grids in the field of view, given
3535 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3536 * view, only about 1475 of these are in the "octagon" of view, and even
3537 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3538 * entries to completely contain the actual field of view.
3540 * Note also the care taken to prevent "running off the map". The use of
3541 * explicit checks on the "validity" of the "diagonal", and the fact that
3542 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3543 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
3544 * of multiple checks on the validity of grids.
3546 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3547 * "ws","wn" variables. They work like this: While travelling down the
3548 * south-bound strip just to the east of the main south axis, as soon as
3549 * we get to a grid which does not "transmit" viewing, if all of the strips
3550 * preceding us (in this case, just the main axis) had terminated at or before
3551 * the same point, then we can stop, and reset the "max distance" to ourself.
3552 * So, each strip (named by major axis plus offset, thus "se" in this case)
3553 * maintains a "blockage" variable, initialized during the main axis step,
3554 * and checks it whenever a blockage is observed. After processing each
3555 * strip as far as the previous strip told us to process, the next strip is
3556 * told not to go farther than the current strip's farthest viewable grid,
3557 * unless open space is still available. This uses the "k" variable.
3559 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
3560 * macro is a replacement for "cave_los_bold()" which takes a pointer to
3561 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3562 * chunk of code which adds the given location to the "view" array if it
3563 * is not already there, using both the actual location and a pointer to
3564 * the cave grid. See above.
3566 * By the way, the purpose of this code is to reduce the dependancy on the
3567 * "los()" function which is slow, and, in some cases, not very accurate.
3569 * It is very possible that I am the only person who fully understands this
3570 * function, and for that I am truly sorry, but efficiency was very important
3571 * and the "simple" version of this function was just not fast enough. I am
3572 * more than willing to replace this function with a simpler one, if it is
3573 * equally efficient, and especially willing if the new function happens to
3574 * derive "reverse-line-of-sight" at the same time, since currently monsters
3575 * just use an optimized hack of "you see me, so I see you", and then use the
3576 * actual "projectable()" function to check spell attacks.
3578 void update_view(void)
3583 int se, sw, ne, nw, es, en, ws, wn;
3587 POSITION y_max = cur_hgt - 1;
3588 POSITION x_max = cur_wid - 1;
3592 /*** Initialize ***/
3595 if (view_reduce_view && !dun_level)
3597 /* Full radius (10) */
3598 full = MAX_SIGHT / 2;
3600 /* Octagon factor (15) */
3601 over = MAX_SIGHT * 3 / 4;
3607 /* Full radius (20) */
3610 /* Octagon factor (30) */
3611 over = MAX_SIGHT * 3 / 2;
3615 /*** Step 0 -- Begin ***/
3617 /* Save the old "view" grids for later */
3618 for (n = 0; n < view_n; n++)
3623 /* Access the grid */
3624 c_ptr = &cave[y][x];
3626 /* Mark the grid as not in "view" */
3627 c_ptr->info &= ~(CAVE_VIEW);
3629 /* Mark the grid as "seen" */
3630 c_ptr->info |= (CAVE_TEMP);
3632 /* Add it to the "seen" set */
3638 /* Start over with the "view" array */
3641 /*** Step 1 -- adjacent grids ***/
3643 /* Now start on the player */
3647 /* Access the grid */
3648 c_ptr = &cave[y][x];
3650 /* Assume the player grid is easily viewable */
3651 c_ptr->info |= (CAVE_XTRA);
3653 /* Assume the player grid is viewable */
3654 cave_view_hack(c_ptr, y, x);
3657 /*** Step 2 -- Major Diagonals ***/
3662 /* Scan south-east */
3663 for (d = 1; d <= z; d++)
3665 c_ptr = &cave[y+d][x+d];
3666 c_ptr->info |= (CAVE_XTRA);
3667 cave_view_hack(c_ptr, y+d, x+d);
3668 if (!cave_los_grid(c_ptr)) break;
3671 /* Scan south-west */
3672 for (d = 1; d <= z; d++)
3674 c_ptr = &cave[y+d][x-d];
3675 c_ptr->info |= (CAVE_XTRA);
3676 cave_view_hack(c_ptr, y+d, x-d);
3677 if (!cave_los_grid(c_ptr)) break;
3680 /* Scan north-east */
3681 for (d = 1; d <= z; d++)
3683 c_ptr = &cave[y-d][x+d];
3684 c_ptr->info |= (CAVE_XTRA);
3685 cave_view_hack(c_ptr, y-d, x+d);
3686 if (!cave_los_grid(c_ptr)) break;
3689 /* Scan north-west */
3690 for (d = 1; d <= z; d++)
3692 c_ptr = &cave[y-d][x-d];
3693 c_ptr->info |= (CAVE_XTRA);
3694 cave_view_hack(c_ptr, y-d, x-d);
3695 if (!cave_los_grid(c_ptr)) break;
3699 /*** Step 3 -- major axes ***/
3702 for (d = 1; d <= full; d++)
3704 c_ptr = &cave[y+d][x];
3705 c_ptr->info |= (CAVE_XTRA);
3706 cave_view_hack(c_ptr, y+d, x);
3707 if (!cave_los_grid(c_ptr)) break;
3710 /* Initialize the "south strips" */
3714 for (d = 1; d <= full; d++)
3716 c_ptr = &cave[y-d][x];
3717 c_ptr->info |= (CAVE_XTRA);
3718 cave_view_hack(c_ptr, y-d, x);
3719 if (!cave_los_grid(c_ptr)) break;
3722 /* Initialize the "north strips" */
3726 for (d = 1; d <= full; d++)
3728 c_ptr = &cave[y][x+d];
3729 c_ptr->info |= (CAVE_XTRA);
3730 cave_view_hack(c_ptr, y, x+d);
3731 if (!cave_los_grid(c_ptr)) break;
3734 /* Initialize the "east strips" */
3738 for (d = 1; d <= full; d++)
3740 c_ptr = &cave[y][x-d];
3741 c_ptr->info |= (CAVE_XTRA);
3742 cave_view_hack(c_ptr, y, x-d);
3743 if (!cave_los_grid(c_ptr)) break;
3746 /* Initialize the "west strips" */
3750 /*** Step 4 -- Divide each "octant" into "strips" ***/
3752 /* Now check each "diagonal" (in parallel) */
3753 for (n = 1; n <= over / 2; n++)
3755 int ypn, ymn, xpn, xmn;
3758 /* Acquire the "bounds" of the maximal circle */
3760 if (z > full - n) z = full - n;
3761 while ((z + n + (n>>1)) > full) z--;
3764 /* Access the four diagonal grids */
3774 /* Maximum distance */
3775 m = MIN(z, y_max - ypn);
3778 if ((xpn <= x_max) && (n < se))
3781 for (k = n, d = 1; d <= m; d++)
3783 /* Check grid "d" in strip "n", notice "blockage" */
3784 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3786 if (n + d >= se) break;
3789 /* Track most distant "non-blockage" */
3796 /* Limit the next strip */
3801 if ((xmn >= 0) && (n < sw))
3804 for (k = n, d = 1; d <= m; d++)
3806 /* Check grid "d" in strip "n", notice "blockage" */
3807 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3809 if (n + d >= sw) break;
3812 /* Track most distant "non-blockage" */
3819 /* Limit the next strip */
3828 /* Maximum distance */
3832 if ((xpn <= x_max) && (n < ne))
3835 for (k = n, d = 1; d <= m; d++)
3837 /* Check grid "d" in strip "n", notice "blockage" */
3838 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3840 if (n + d >= ne) break;
3843 /* Track most distant "non-blockage" */
3850 /* Limit the next strip */
3855 if ((xmn >= 0) && (n < nw))
3858 for (k = n, d = 1; d <= m; d++)
3860 /* Check grid "d" in strip "n", notice "blockage" */
3861 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
3863 if (n + d >= nw) break;
3866 /* Track most distant "non-blockage" */
3873 /* Limit the next strip */
3882 /* Maximum distance */
3883 m = MIN(z, x_max - xpn);
3886 if ((ypn <= x_max) && (n < es))
3889 for (k = n, d = 1; d <= m; d++)
3891 /* Check grid "d" in strip "n", notice "blockage" */
3892 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
3894 if (n + d >= es) break;
3897 /* Track most distant "non-blockage" */
3904 /* Limit the next strip */
3909 if ((ymn >= 0) && (n < en))
3912 for (k = n, d = 1; d <= m; d++)
3914 /* Check grid "d" in strip "n", notice "blockage" */
3915 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
3917 if (n + d >= en) break;
3920 /* Track most distant "non-blockage" */
3927 /* Limit the next strip */
3936 /* Maximum distance */
3940 if ((ypn <= y_max) && (n < ws))
3943 for (k = n, d = 1; d <= m; d++)
3945 /* Check grid "d" in strip "n", notice "blockage" */
3946 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
3948 if (n + d >= ws) break;
3951 /* Track most distant "non-blockage" */
3958 /* Limit the next strip */
3963 if ((ymn >= 0) && (n < wn))
3966 for (k = n, d = 1; d <= m; d++)
3968 /* Check grid "d" in strip "n", notice "blockage" */
3969 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
3971 if (n + d >= wn) break;
3974 /* Track most distant "non-blockage" */
3981 /* Limit the next strip */
3988 /*** Step 5 -- Complete the algorithm ***/
3990 /* Update all the new grids */
3991 for (n = 0; n < view_n; n++)
3996 /* Access the grid */
3997 c_ptr = &cave[y][x];
3999 /* Clear the "CAVE_XTRA" flag */
4000 c_ptr->info &= ~(CAVE_XTRA);
4002 /* Update only newly viewed grids */
4003 if (c_ptr->info & (CAVE_TEMP)) continue;
4005 /* Add it to later visual update */
4006 cave_note_and_redraw_later(c_ptr, y, x);
4009 /* Wipe the old grids, update as needed */
4010 for (n = 0; n < temp_n; n++)
4015 /* Access the grid */
4016 c_ptr = &cave[y][x];
4018 /* No longer in the array */
4019 c_ptr->info &= ~(CAVE_TEMP);
4021 /* Update only non-viewable grids */
4022 if (c_ptr->info & (CAVE_VIEW)) continue;
4024 /* Add it to later visual update */
4025 cave_redraw_later(c_ptr, y, x);
4031 /* Mega-Hack -- Visual update later */
4032 p_ptr->update |= (PU_DELAY_VIS);
4037 * Mega-Hack -- Delayed visual update
4038 * Only used if update_view(), update_lite() or update_mon_lite() was called
4040 void delayed_visual_update(void)
4045 /* Update needed grids */
4046 for (i = 0; i < redraw_n; i++)
4051 /* Access the grid */
4052 c_ptr = &cave[y][x];
4054 /* Update only needed grids (prevent multiple updating) */
4055 if (!(c_ptr->info & CAVE_REDRAW)) continue;
4057 /* If required, note */
4058 if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
4063 /* Hack -- Visual update of monster on this grid */
4064 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4066 /* No longer in the array */
4067 c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4076 * Hack -- forget the "flow" information
4078 void forget_flow(void)
4082 /* Check the entire dungeon */
4083 for (y = 0; y < cur_hgt; y++)
4085 for (x = 0; x < cur_wid; x++)
4087 /* Forget the old data */
4088 cave[y][x].dist = 0;
4089 cave[y][x].cost = 0;
4090 cave[y][x].when = 0;
4097 * Hack - speed up the update_flow algorithm by only doing
4098 * it everytime the player moves out of LOS of the last
4101 static POSITION flow_x = 0;
4102 static POSITION flow_y = 0;
4107 * Hack -- fill in the "cost" field of every grid that the player
4108 * can "reach" with the number of steps needed to reach that grid.
4109 * This also yields the "distance" of the player from every grid.
4111 * In addition, mark the "when" of the grids that can reach
4112 * the player with the incremented value of "flow_n".
4114 * Hack -- use the "seen" array as a "circular queue".
4116 * We do not need a priority queue because the cost from grid
4117 * to grid is always "one" and we process them in order.
4119 void update_flow(void)
4125 /* Paranoia -- make sure the array is empty */
4128 /* The last way-point is on the map */
4129 if (running && in_bounds(flow_y, flow_x))
4131 /* The way point is in sight - do not update. (Speedup) */
4132 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4135 /* Erase all of the current flow information */
4136 for (y = 0; y < cur_hgt; y++)
4138 for (x = 0; x < cur_wid; x++)
4140 cave[y][x].cost = 0;
4141 cave[y][x].dist = 0;
4145 /* Save player position */
4149 /* Add the player's grid to the queue */
4150 temp_y[0] = p_ptr->y;
4151 temp_x[0] = p_ptr->x;
4153 /* Now process the queue */
4154 while (flow_head != flow_tail)
4158 /* Extract the next entry */
4159 ty = temp_y[flow_tail];
4160 tx = temp_x[flow_tail];
4162 /* Forget that entry */
4163 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4165 /* Add the "children" */
4166 for (d = 0; d < 8; d++)
4168 int old_head = flow_head;
4169 byte_hack m = cave[ty][tx].cost + 1;
4170 byte_hack n = cave[ty][tx].dist + 1;
4173 /* Child location */
4174 y = ty + ddy_ddd[d];
4175 x = tx + ddx_ddd[d];
4177 /* Ignore player's grid */
4178 if (player_bold(y, x)) continue;
4180 c_ptr = &cave[y][x];
4182 if (is_closed_door(c_ptr->feat)) m += 3;
4184 /* Ignore "pre-stamped" entries */
4185 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4187 /* Ignore "walls" and "rubble" */
4188 if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4190 /* Save the flow cost */
4191 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4192 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4194 /* Hack -- limit flow depth */
4195 if (n == MONSTER_FLOW_DEPTH) continue;
4197 /* Enqueue that entry */
4198 temp_y[flow_head] = y;
4199 temp_x[flow_head] = x;
4201 /* Advance the queue */
4202 if (++flow_head == TEMP_MAX) flow_head = 0;
4204 /* Hack -- notice overflow by forgetting new entry */
4205 if (flow_head == flow_tail) flow_head = old_head;
4211 static int scent_when = 0;
4214 * Characters leave scent trails for perceptive monsters to track.
4216 * Smell is rather more limited than sound. Many creatures cannot use
4217 * it at all, it doesn't extend very far outwards from the character's
4218 * current position, and monsters can use it to home in the character,
4219 * but not to run away from him.
4221 * Smell is valued according to age. When a character takes his turn,
4222 * scent is aged by one, and new scent of the current age is laid down.
4223 * Speedy characters leave more scent, true, but it also ages faster,
4224 * which makes it harder to hunt them down.
4226 * Whenever the age count loops, most of the scent trail is erased and
4227 * the age of the remainder is recalculated.
4229 void update_smell(void)
4234 /* Create a table that controls the spread of scent */
4235 const int scent_adjust[5][5] =
4244 /* Loop the age and adjust scent values when necessary */
4245 if (++scent_when == 254)
4247 /* Scan the entire dungeon */
4248 for (y = 0; y < cur_hgt; y++)
4250 for (x = 0; x < cur_wid; x++)
4252 int w = cave[y][x].when;
4253 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4262 /* Lay down new scent */
4263 for (i = 0; i < 5; i++)
4265 for (j = 0; j < 5; j++)
4269 /* Translate table to map grids */
4270 y = i + p_ptr->y - 2;
4271 x = j + p_ptr->x - 2;
4274 if (!in_bounds(y, x)) continue;
4276 c_ptr = &cave[y][x];
4278 /* Walls, water, and lava cannot hold scent. */
4279 if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4281 /* Grid must not be blocked by walls from the character */
4282 if (!player_has_los_bold(y, x)) continue;
4284 /* Note grids that are too far away */
4285 if (scent_adjust[i][j] == -1) continue;
4287 /* Mark the grid with new scent */
4288 c_ptr->when = scent_when + scent_adjust[i][j];
4295 * Hack -- map the current panel (plus some) ala "magic mapping"
4297 void map_area(POSITION range)
4302 feature_type *f_ptr;
4304 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4306 /* Scan that area */
4307 for (y = 1; y < cur_hgt - 1; y++)
4309 for (x = 1; x < cur_wid - 1; x++)
4311 if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
4313 c_ptr = &cave[y][x];
4315 /* Memorize terrain of the grid */
4316 c_ptr->info |= (CAVE_KNOWN);
4318 /* Feature code (applying "mimic" field) */
4319 feat = get_feat_mimic(c_ptr);
4320 f_ptr = &f_info[feat];
4322 /* All non-walls are "checked" */
4323 if (!have_flag(f_ptr->flags, FF_WALL))
4325 /* Memorize normal features */
4326 if (have_flag(f_ptr->flags, FF_REMEMBER))
4328 /* Memorize the object */
4329 c_ptr->info |= (CAVE_MARK);
4332 /* Memorize known walls */
4333 for (i = 0; i < 8; i++)
4335 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4337 /* Feature code (applying "mimic" field) */
4338 feat = get_feat_mimic(c_ptr);
4339 f_ptr = &f_info[feat];
4341 /* Memorize walls (etc) */
4342 if (have_flag(f_ptr->flags, FF_REMEMBER))
4344 /* Memorize the walls */
4345 c_ptr->info |= (CAVE_MARK);
4353 p_ptr->redraw |= (PR_MAP);
4356 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4362 * Light up the dungeon using "clairvoyance"
4364 * This function "illuminates" every grid in the dungeon, memorizes all
4365 * "objects", memorizes all grids as with magic mapping, and, under the
4366 * standard option settings (view_perma_grids but not view_torch_grids)
4367 * memorizes all floor grids too.
4369 * Note that if "view_perma_grids" is not set, we do not memorize floor
4370 * grids, since this would defeat the purpose of "view_perma_grids", not
4371 * that anyone seems to play without this option.
4373 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4374 * since this would prevent the use of "view_torch_grids" as a method to
4375 * keep track of what grids have been observed directly.
4377 void wiz_lite(bool ninja)
4381 feature_type *f_ptr;
4383 /* Memorize objects */
4384 for (i = 1; i < o_max; i++)
4386 object_type *o_ptr = &o_list[i];
4388 /* Skip dead objects */
4389 if (!o_ptr->k_idx) continue;
4391 /* Skip held objects */
4392 if (o_ptr->held_m_idx) continue;
4395 o_ptr->marked |= OM_FOUND;
4398 /* Scan all normal grids */
4399 for (y = 1; y < cur_hgt - 1; y++)
4401 /* Scan all normal grids */
4402 for (x = 1; x < cur_wid - 1; x++)
4404 cave_type *c_ptr = &cave[y][x];
4406 /* Memorize terrain of the grid */
4407 c_ptr->info |= (CAVE_KNOWN);
4409 /* Feature code (applying "mimic" field) */
4410 feat = get_feat_mimic(c_ptr);
4411 f_ptr = &f_info[feat];
4413 /* Process all non-walls */
4414 if (!have_flag(f_ptr->flags, FF_WALL))
4416 /* Scan all neighbors */
4417 for (i = 0; i < 9; i++)
4419 POSITION yy = y + ddy_ddd[i];
4420 POSITION xx = x + ddx_ddd[i];
4423 c_ptr = &cave[yy][xx];
4425 /* Feature code (applying "mimic" field) */
4426 f_ptr = &f_info[get_feat_mimic(c_ptr)];
4428 /* Perma-lite the grid */
4429 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS) && !ninja)
4431 c_ptr->info |= (CAVE_GLOW);
4434 /* Memorize normal features */
4435 if (have_flag(f_ptr->flags, FF_REMEMBER))
4437 /* Memorize the grid */
4438 c_ptr->info |= (CAVE_MARK);
4441 /* Perma-lit grids (newly and previously) */
4442 else if (c_ptr->info & CAVE_GLOW)
4444 /* Normally, memorize floors (see above) */
4445 if (view_perma_grids && !view_torch_grids)
4447 /* Memorize the grid */
4448 c_ptr->info |= (CAVE_MARK);
4456 /* Update the monsters */
4457 p_ptr->update |= (PU_MONSTERS);
4460 p_ptr->redraw |= (PR_MAP);
4463 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4465 if (p_ptr->special_defense & NINJA_S_STEALTH)
4467 if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
4473 * Forget the dungeon map (ala "Thinking of Maud...").
4480 /* Forget every grid */
4481 for (y = 1; y < cur_hgt - 1; y++)
4483 for (x = 1; x < cur_wid - 1; x++)
4485 cave_type *c_ptr = &cave[y][x];
4487 /* Process the grid */
4488 c_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT | CAVE_KNOWN);
4489 c_ptr->info |= (CAVE_UNSAFE);
4493 /* Forget every grid on horizontal edge */
4494 for (x = 0; x < cur_wid; x++)
4496 cave[0][x].info &= ~(CAVE_MARK);
4497 cave[cur_hgt - 1][x].info &= ~(CAVE_MARK);
4500 /* Forget every grid on vertical edge */
4501 for (y = 1; y < (cur_hgt - 1); y++)
4503 cave[y][0].info &= ~(CAVE_MARK);
4504 cave[y][cur_wid - 1].info &= ~(CAVE_MARK);
4507 /* Forget all objects */
4508 for (i = 1; i < o_max; i++)
4510 object_type *o_ptr = &o_list[i];
4512 /* Skip dead objects */
4513 if (!o_ptr->k_idx) continue;
4515 /* Skip held objects */
4516 if (o_ptr->held_m_idx) continue;
4518 /* Forget the object */
4519 o_ptr->marked &= OM_TOUCHED;
4522 /* Forget travel route when we have forgotten map */
4523 forget_travel_flow();
4525 /* Mega-Hack -- Forget the view and lite */
4526 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4528 /* Update the view and lite */
4529 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4531 /* Update the monsters */
4532 p_ptr->update |= (PU_MONSTERS);
4535 p_ptr->redraw |= (PR_MAP);
4538 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4546 * Change the "feat" flag for a grid, and notice/redraw the grid
4548 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
4550 cave_type *c_ptr = &cave[y][x];
4551 feature_type *f_ptr = &f_info[feat];
4552 bool old_los, old_mirror;
4554 if (!character_dungeon)
4556 /* Clear mimic type */
4559 /* Change the feature */
4562 /* Hack -- glow the GLOW terrain */
4563 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4567 for (i = 0; i < 9; i++)
4569 yy = y + ddy_ddd[i];
4570 xx = x + ddx_ddd[i];
4571 if (!in_bounds2(yy, xx)) continue;
4572 cave[yy][xx].info |= CAVE_GLOW;
4579 old_los = cave_have_flag_bold(y, x, FF_LOS);
4580 old_mirror = is_mirror_grid(c_ptr);
4582 /* Clear mimic type */
4585 /* Change the feature */
4588 /* Remove flag for mirror/glyph */
4589 c_ptr->info &= ~(CAVE_OBJECT);
4591 if (old_mirror && (d_info[dungeon_type].flags1 & DF1_DARKNESS))
4593 c_ptr->info &= ~(CAVE_GLOW);
4594 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4596 update_local_illumination(y, x);
4599 /* Check for change to boring grid */
4600 if (!have_flag(f_ptr->flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
4602 /* Update the monster */
4603 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4611 /* Check if los has changed */
4612 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
4615 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
4617 update_local_illumination(y, x);
4619 #endif /* COMPLEX_WALL_ILLUMINATION */
4621 /* Update the visuals */
4622 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
4625 /* Hack -- glow the GLOW terrain */
4626 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4631 for (i = 0; i < 9; i++)
4633 yy = y + ddy_ddd[i];
4634 xx = x + ddx_ddd[i];
4635 if (!in_bounds2(yy, xx)) continue;
4636 cc_ptr = &cave[yy][xx];
4637 cc_ptr->info |= CAVE_GLOW;
4639 if (player_has_los_grid(cc_ptr))
4641 /* Update the monster */
4642 if (cc_ptr->m_idx) update_mon(cc_ptr->m_idx, FALSE);
4651 update_local_illumination(yy, xx);
4654 if (p_ptr->special_defense & NINJA_S_STEALTH)
4656 if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
4662 IDX conv_dungeon_feat(IDX newfeat)
4664 feature_type *f_ptr = &f_info[newfeat];
4666 if (have_flag(f_ptr->flags, FF_CONVERT))
4668 switch (f_ptr->subtype)
4670 case CONVERT_TYPE_FLOOR:
4671 return floor_type[randint0(100)];
4672 case CONVERT_TYPE_WALL:
4673 return fill_type[randint0(100)];
4674 case CONVERT_TYPE_INNER:
4675 return feat_wall_inner;
4676 case CONVERT_TYPE_OUTER:
4677 return feat_wall_outer;
4678 case CONVERT_TYPE_SOLID:
4679 return feat_wall_solid;
4680 case CONVERT_TYPE_STREAM1:
4681 return d_info[dungeon_type].stream1;
4682 case CONVERT_TYPE_STREAM2:
4683 return d_info[dungeon_type].stream2;
4688 else return newfeat;
4693 * Take a feature, determine what that feature becomes
4694 * through applying the given action.
4696 IDX feat_state(IDX feat, int action)
4698 feature_type *f_ptr = &f_info[feat];
4701 /* Get the new feature */
4702 for (i = 0; i < MAX_FEAT_STATES; i++)
4704 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
4707 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
4709 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
4713 * Takes a location and action and changes the feature at that
4714 * location through applying the given action.
4716 void cave_alter_feat(POSITION y, POSITION x, int action)
4718 /* Set old feature */
4719 IDX oldfeat = cave[y][x].feat;
4721 /* Get the new feat */
4722 IDX newfeat = feat_state(oldfeat, action);
4725 if (newfeat == oldfeat) return;
4727 /* Set the new feature */
4728 cave_set_feat(y, x, newfeat);
4730 if (!(feature_action_flags[action] & FAF_NO_DROP))
4732 feature_type *old_f_ptr = &f_info[oldfeat];
4733 feature_type *f_ptr = &f_info[newfeat];
4737 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
4739 /* Place some gold */
4745 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - dun_level / 2)))
4748 place_object(y, x, 0L);
4752 if (found && character_dungeon && player_can_see_bold(y, x))
4754 msg_print(_("何かを発見した!", "You have found something!"));
4758 if (feature_action_flags[action] & FAF_CRASH_GLASS)
4760 feature_type *old_f_ptr = &f_info[oldfeat];
4762 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
4764 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(dun_level, 100) / 4, GF_SHARDS,
4765 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
4771 /* Remove a mirror */
4772 void remove_mirror(POSITION y, POSITION x)
4774 cave_type *c_ptr = &cave[y][x];
4776 /* Remove the mirror */
4777 c_ptr->info &= ~(CAVE_OBJECT);
4780 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4782 c_ptr->info &= ~(CAVE_GLOW);
4783 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4785 /* Update the monster */
4786 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4788 update_local_illumination(y, x);
4800 * Return TRUE if there is a mirror on the grid.
4802 bool is_mirror_grid(cave_type *c_ptr)
4804 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MIRROR))
4812 * Return TRUE if there is a mirror on the grid.
4814 bool is_glyph_grid(cave_type *c_ptr)
4816 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_GLYPH))
4824 * Return TRUE if there is a mirror on the grid.
4826 bool is_explosive_rune_grid(cave_type *c_ptr)
4828 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MINOR_GLYPH))
4836 * Calculate "incremental motion". Used by project() and shoot().
4837 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4839 void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4841 POSITION dy, dx, dist, shift;
4843 /* Extract the distance travelled */
4844 dy = (*y < y1) ? y1 - *y : *y - y1;
4845 dx = (*x < x1) ? x1 - *x : *x - x1;
4847 /* Number of steps */
4848 dist = (dy > dx) ? dy : dx;
4850 /* We are calculating the next location */
4854 /* Calculate the total distance along each axis */
4855 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4856 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4858 /* Paranoia -- Hack -- no motion */
4859 if (!dy && !dx) return;
4862 /* Move mostly vertically */
4865 /* Extract a shift factor */
4866 shift = (dist * dx + (dy - 1) / 2) / dy;
4868 /* Sometimes move along the minor axis */
4869 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4871 /* Always move along major axis */
4872 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4875 /* Move mostly horizontally */
4878 /* Extract a shift factor */
4879 shift = (dist * dy + (dx - 1) / 2) / dx;
4881 /* Sometimes move along the minor axis */
4882 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4884 /* Always move along major axis */
4885 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4892 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4893 * at the final destination, assuming no monster gets in the way.
4895 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4897 bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4904 /* Check the projection path */
4905 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4907 /* Identical grid */
4908 if (!grid_n) return TRUE;
4911 y = GRID_Y(grid_g[grid_n - 1]);
4912 x = GRID_X(grid_g[grid_n - 1]);
4914 /* May not end in an unrequested grid */
4915 if ((y != y2) || (x != x2)) return (FALSE);
4923 * Standard "find me a location" function
4925 * Obtains a legal location within the given distance of the initial
4926 * location, and with "los()" from the source to destination location.
4928 * This function is often called from inside a loop which searches for
4929 * locations while increasing the "d" distance.
4931 * Currently the "m" parameter is unused.
4933 void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
4937 /* Pick a location */
4940 /* Pick a new location */
4941 ny = rand_spread(y, d);
4942 nx = rand_spread(x, d);
4944 /* Ignore annoying locations */
4945 if (!in_bounds(ny, nx)) continue;
4947 /* Ignore "excessively distant" locations */
4948 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4950 if (mode & PROJECT_LOS)
4952 if(los(y, x, ny, nx)) break;
4956 if(projectable(y, x, ny, nx)) break;
4961 /* Save the location */
4970 * Track a new monster
4972 void health_track(MONSTER_IDX m_idx)
4974 /* Mount monster is already tracked */
4975 if (m_idx && m_idx == p_ptr->riding) return;
4977 /* Track a new guy */
4978 p_ptr->health_who = m_idx;
4980 /* Redraw (later) */
4981 p_ptr->redraw |= (PR_HEALTH);
4987 * Hack -- track the given monster race
4989 void monster_race_track(MONRACE_IDX r_idx)
4991 /* Save this monster ID */
4992 p_ptr->monster_race_idx = r_idx;
4995 p_ptr->window |= (PW_MONSTER);
5001 * Hack -- track the given object kind
5003 void object_kind_track(KIND_OBJECT_IDX k_idx)
5005 /* Save this monster ID */
5006 p_ptr->object_kind_idx = k_idx;
5009 p_ptr->window |= (PW_OBJECT);
5015 * Something has happened to disturb the player.
5017 * The first arg indicates a major disturbance, which affects search.
5019 * The second arg is currently unused, but could induce output flush.
5021 * All disturbance cancels repeated commands, resting, and running.
5023 void disturb(int stop_search, int stop_travel)
5027 stop_travel = stop_travel;
5030 /* Cancel auto-commands */
5031 /* command_new = 0; */
5033 /* Cancel repeated commands */
5039 /* Redraw the state (later) */
5040 p_ptr->redraw |= (PR_STATE);
5043 /* Cancel Resting */
5044 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5047 set_action(ACTION_NONE);
5050 /* Cancel running */
5056 /* Check for new panel if appropriate */
5057 if (center_player && !center_running) verify_panel();
5059 /* Calculate torch radius */
5060 p_ptr->update |= (PU_TORCH);
5062 /* Update monster flow */
5063 p_ptr->update |= (PU_FLOW);
5072 /* Check for new panel if appropriate */
5073 if (center_player && !center_running) verify_panel();
5075 /* Calculate torch radius */
5076 p_ptr->update |= (PU_TORCH);
5080 /* Flush the input if requested */
5081 if (flush_disturb) flush();
5086 * Glow deep lava and building entrances in the floor
5088 void glow_deep_lava_and_bldg(void)
5090 POSITION y, x, yy, xx;
5094 /* Not in the darkness dungeon */
5095 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
5097 for (y = 0; y < cur_hgt; y++)
5099 for (x = 0; x < cur_wid; x++)
5101 c_ptr = &cave[y][x];
5103 /* Feature code (applying "mimic" field) */
5105 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_GLOW))
5107 for (i = 0; i < 9; i++)
5109 yy = y + ddy_ddd[i];
5110 xx = x + ddx_ddd[i];
5111 if (!in_bounds2(yy, xx)) continue;
5112 cave[yy][xx].info |= CAVE_GLOW;
5118 /* Update the view and lite */
5119 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
5122 p_ptr->redraw |= (PR_MAP);
5126 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
5127 * @param m_idx モンスターID
5131 * @return テレポート先として妥当ならばtrue
5133 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
5135 monster_type *m_ptr = &m_list[m_idx];
5136 cave_type *c_ptr = &cave[y][x];
5137 feature_type *f_ptr = &f_info[c_ptr->feat];
5139 /* Require "teleportable" space */
5140 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5142 if (c_ptr->m_idx && (c_ptr->m_idx != m_idx)) return FALSE;
5143 if (player_bold(y, x)) return FALSE;
5145 /* Hack -- no teleport onto glyph of warding */
5146 if (is_glyph_grid(c_ptr)) return FALSE;
5147 if (is_explosive_rune_grid(c_ptr)) return FALSE;
5149 if (!(mode & TELEPORT_PASSIVE))
5151 if (!monster_can_cross_terrain(c_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
5158 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
5162 * @return テレポート先として妥当ならばtrue
5164 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
5166 cave_type *c_ptr = &cave[y][x];
5167 feature_type *f_ptr = &f_info[c_ptr->feat];
5169 /* Require "teleportable" space */
5170 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5172 /* No magical teleporting into vaults and such */
5173 if (!(mode & TELEPORT_NONMAGICAL) && (c_ptr->info & CAVE_ICKY)) return FALSE;
5175 if (c_ptr->m_idx && (c_ptr->m_idx != p_ptr->riding)) return FALSE;
5177 /* don't teleport on a trap. */
5178 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
5180 if (!(mode & TELEPORT_PASSIVE))
5182 if (!player_can_enter(c_ptr->feat, 0)) return FALSE;
5184 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
5186 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
5189 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
5191 /* Always forbid deep lava */
5192 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
5194 /* Forbid shallow lava when the player don't have levitation */
5195 if (!p_ptr->levitation) return FALSE;