3 * @brief ダンジョンの基礎部分実装(主にマスの実装) / low level dungeon routines -BEN-
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
8 * This software may be copied and distributed for educational, research,\n
9 * and not for profit purposes provided that this copyright and statement\n
10 * are included in all such copies. Other copyrights may also apply.\n
12 * Support for Adam Bolt's tileset, lighting and transparency effects\n
13 * by Robert Ruehlmann (rr9@angband.org)\n
15 * 2013 Deskull Doxygen向けのコメント整理\n
21 #include "projection.h"
22 #include "object-hook.h"
24 static byte display_autopick; /*!< 自動拾い状態の設定フラグ */
25 static int match_autopick;
26 static object_type *autopick_obj; /*!< 各種自動拾い処理時に使うオブジェクトポインタ */
27 static int feat_priority; /*!< マップ縮小表示時に表示すべき地形の優先度を保管する */
30 * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
37 POSITION distance (POSITION y1, POSITION x1, POSITION y2, POSITION x2)
39 POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
40 POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
42 /* Squared distance */
43 POSITION target = (dy * dy) + (dx * dx);
45 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
46 POSITION d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
51 if (!dy || !dx) return d;
55 /* Approximate error */
56 err = (target - d * d) / (2 * d);
58 /* No error - we are done */
69 * @brief 地形が罠持ちであるかの判定を行う。 / Return TRUE if the given feature is a trap
71 * @return 罠持ちの地形ならばTRUEを返す。
73 bool is_trap(FEAT_IDX feat)
75 return have_flag(f_info[feat].flags, FF_TRAP);
79 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
80 * @param g_ptr マス構造体の参照ポインタ
81 * @return 看破済みの罠があるならTRUEを返す。
83 bool is_known_trap(grid_type *g_ptr)
85 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
86 is_trap(g_ptr->feat)) return TRUE;
92 * @brief 地形が閉じたドアであるかの判定を行う。 / Return TRUE if the given grid is a closed door
94 * @return 閉じたドアのある地形ならばTRUEを返す。
96 bool is_closed_door(FEAT_IDX feat)
98 feature_type *f_ptr = &f_info[feat];
100 return (have_flag(f_ptr->flags, FF_OPEN) || have_flag(f_ptr->flags, FF_BASH)) &&
101 !have_flag(f_ptr->flags, FF_MOVE);
105 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
106 * @param g_ptr マス構造体の参照ポインタ
107 * @return 隠されたドアがあるならTRUEを返す。
109 bool is_hidden_door(grid_type *g_ptr)
111 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
112 is_closed_door(g_ptr->feat))
119 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
124 * @return LOSが通っているならTRUEを返す。
126 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
127 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
129 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
131 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
132 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
133 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
135 * We assume that the "mathematical corner" of a non-floor tile does not\n
136 * block line of sight.\n
138 * Because this function uses (short) ints for all calculations, overflow may\n
139 * occur if dx and dy exceed 90.\n
141 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
142 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
143 * we can use integer arithmetic.\n
145 * We travel from start to finish along the longer axis, starting at the border\n
146 * between the first and second tiles, where the y offset = .5 * slope, taking\n
147 * into account the scale factor. See below.\n
149 * Also note that this function and the "move towards target" code do NOT\n
150 * share the same properties. Thus, you can see someone, target them, and\n
151 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
152 * by clever choice of target locations, you can sometimes throw a "curve".\n
154 * Note that "line of sight" is not "reflexive" in all cases.\n
156 * Use the "projectable()" routine to test "spell/missile line of sight".\n
158 * Use the "update_view()" function to determine player line-of-sight.\n
160 bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
180 /* Slope, or 1/Slope, of LOS */
184 /* Extract the offset */
188 /* Extract the absolute offset */
193 /* Handle adjacent (or identical) grids */
194 if ((ax < 2) && (ay < 2)) return TRUE;
197 /* Paranoia -- require "safe" origin */
198 /* if (!in_bounds(y1, x1)) return FALSE; */
199 /* if (!in_bounds(y2, x2)) return FALSE; */
202 /* Directly South/North */
205 /* South -- check for walls */
208 for (ty = y1 + 1; ty < y2; ty++)
210 if (!cave_los_bold(ty, x1)) return FALSE;
214 /* North -- check for walls */
217 for (ty = y1 - 1; ty > y2; ty--)
219 if (!cave_los_bold(ty, x1)) return FALSE;
227 /* Directly East/West */
230 /* East -- check for walls */
233 for (tx = x1 + 1; tx < x2; tx++)
235 if (!cave_los_bold(y1, tx)) return FALSE;
239 /* West -- check for walls */
242 for (tx = x1 - 1; tx > x2; tx--)
244 if (!cave_los_bold(y1, tx)) return FALSE;
253 /* Extract some signs */
254 sx = (dx < 0) ? -1 : 1;
255 sy = (dy < 0) ? -1 : 1;
258 /* Vertical "knights" */
263 if (cave_los_bold(y1 + sy, x1)) return TRUE;
267 /* Horizontal "knights" */
272 if (cave_los_bold(y1, x1 + sx)) return TRUE;
277 /* Calculate scale factor div 2 */
280 /* Calculate scale factor */
284 /* Travel horizontally */
287 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
293 /* Consider the special case where slope == 1. */
304 /* Note (below) the case (qy == f2), where */
305 /* the LOS exactly meets the corner of a tile. */
308 if (!cave_los_bold(ty, tx)) return FALSE;
319 if (!cave_los_bold(ty, tx)) return FALSE;
332 /* Travel vertically */
335 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
351 /* Note (below) the case (qx == f2), where */
352 /* the LOS exactly meets the corner of a tile. */
355 if (!cave_los_bold(ty, tx)) return FALSE;
366 if (!cave_los_bold(ty, tx)) return FALSE;
383 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
387 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
390 * @return 指定された座標に照明がかかっているならTRUEを返す。。
392 static bool check_local_illumination(POSITION y, POSITION x)
394 /* Hack -- move towards player */
395 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
396 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
398 /* Check for "local" illumination */
400 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
402 /* Check for "complex" illumination */
403 if ((feat_supports_los(get_feat_mimic(&grid_array[yy][xx])) &&
404 (grid_array[yy][xx].info & CAVE_GLOW)) ||
405 (feat_supports_los(get_feat_mimic(&grid_array[y][xx])) &&
406 (grid_array[y][xx].info & CAVE_GLOW)) ||
407 (feat_supports_los(get_feat_mimic(&grid_array[yy][x])) &&
408 (grid_array[yy][x].info & CAVE_GLOW)))
414 #else /* COMPLEX_WALL_ILLUMINATION */
416 /* Check for "simple" illumination */
417 return (grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
419 #endif /* COMPLEX_WALL_ILLUMINATION */
423 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
424 #define update_local_illumination_aux(Y, X) \
426 if (player_has_los_bold((Y), (X))) \
428 /* Update the monster */ \
429 if (grid_array[(Y)][(X)].m_idx) update_monster(grid_array[(Y)][(X)].m_idx, FALSE); \
431 /* Notice and redraw */ \
432 note_spot((Y), (X)); \
433 lite_spot((Y), (X)); \
438 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
443 void update_local_illumination(POSITION y, POSITION x)
448 if (!in_bounds(y, x)) return;
450 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
452 if ((y != p_ptr->y) && (x != p_ptr->x))
454 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
455 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
456 update_local_illumination_aux(yy, xx);
457 update_local_illumination_aux(y, xx);
458 update_local_illumination_aux(yy, x);
460 else if (x != p_ptr->x) /* y == p_ptr->y */
462 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
463 for (i = -1; i <= 1; i++)
466 update_local_illumination_aux(yy, xx);
469 update_local_illumination_aux(yy, x);
471 update_local_illumination_aux(yy, x);
473 else if (y != p_ptr->y) /* x == p_ptr->x */
475 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
476 for (i = -1; i <= 1; i++)
479 update_local_illumination_aux(yy, xx);
482 update_local_illumination_aux(y, xx);
484 update_local_illumination_aux(y, xx);
486 else /* Player's grid */
488 for (i = 0; i < 8; i++)
492 update_local_illumination_aux(yy, xx);
496 #else /* COMPLEX_WALL_ILLUMINATION */
498 if ((y != p_ptr->y) && (x != p_ptr->x))
500 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
501 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
502 update_local_illumination_aux(yy, xx);
504 else if (x != p_ptr->x) /* y == p_ptr->y */
506 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
507 for (i = -1; i <= 1; i++)
510 update_local_illumination_aux(yy, xx);
513 else if (y != p_ptr->y) /* x == p_ptr->x */
515 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
516 for (i = -1; i <= 1; i++)
519 update_local_illumination_aux(yy, xx);
522 else /* Player's grid */
524 for (i = 0; i < 8; i++)
528 update_local_illumination_aux(yy, xx);
532 #endif /* COMPLEX_WALL_ILLUMINATION */
537 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
540 * @return 視覚に収められる状態ならTRUEを返す
542 * He must have vision, illumination, and line of sight.\n
544 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
545 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
547 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
548 * that a wall is visible from any direction. That would be odd. Except\n
549 * under wizard light, which might make sense. Thus, for walls, we require\n
550 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
551 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
552 * in line of sight of the player.\n
554 * This extra check is expensive, but it provides a more "correct" semantics.\n
556 * Note that we should not run this check on walls which are "outer walls" of\n
557 * the dungeon, or we will induce a memory fault, but actually verifying all\n
558 * of the locations would be extremely expensive.\n
560 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
561 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
562 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
563 * and the player has more important things on his mind when he is attacking a\n
564 * monster vault. It is annoying, but an extremely important optimization.\n
566 * Note that "glowing walls" are only considered to be "illuminated" if the\n
567 * grid which is next to the wall in the direction of the player is also a\n
568 * "glowing" grid. This prevents the player from being able to "see" the\n
569 * walls of illuminated rooms from a corridor outside the room.\n
571 bool player_can_see_bold(POSITION y, POSITION x)
575 /* Blind players see nothing */
576 if (p_ptr->blind) return FALSE;
578 g_ptr = &grid_array[y][x];
580 /* Note that "torch-lite" yields "illumination" */
581 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
583 /* Require line of sight to the grid */
584 if (!player_has_los_bold(y, x)) return FALSE;
586 /* Noctovision of Ninja */
587 if (p_ptr->see_nocto) return TRUE;
589 /* Require "perma-lite" of the grid */
590 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
592 /* Feature code (applying "mimic" field) */
593 /* Floors are simple */
594 if (feat_supports_los(get_feat_mimic(g_ptr))) return TRUE;
596 /* Check for "local" illumination */
597 return check_local_illumination(y, x);
601 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
602 * @return 視覚に収められていないならTRUEを返す
603 * @details player_can_see_bold()関数の返り値の否定を返している。
607 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
612 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
615 * @return 各種の変更が可能ならTRUEを返す。
617 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
619 bool cave_valid_bold(POSITION y, POSITION x)
621 grid_type *g_ptr = &grid_array[y][x];
622 OBJECT_IDX this_o_idx, next_o_idx = 0;
624 /* Forbid perma-grids */
625 if (cave_perma_grid(g_ptr)) return (FALSE);
628 for (this_o_idx = g_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, SYMBOL_CODE *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, SYMBOL_CODE *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, SYMBOL_CODE *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 TERM_COLOR 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], SYMBOL_CODE f_char[F_LIT_MAX])
800 TERM_COLOR s_attr = f_attr[F_LIT_STANDARD];
801 SYMBOL_CODE 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 "grid_array.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, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp)
947 /* Get the grid_array */
948 grid_type *g_ptr = &grid_array[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(g_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 ((g_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
977 ((g_ptr->info & CAVE_VIEW) && (((g_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(g_ptr))
998 /* Unsafe grid -- idea borrowed from Unangband */
999 feat = (view_unsafe_grids && (g_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 (g_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 ((g_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 (!(g_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 grid -- idea borrowed from Unangband */
1050 feat = (view_unsafe_grids && (g_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 (g_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(g_ptr) && !p_ptr->blind)
1086 if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
1088 /* Unsafe grid -- idea borrowed from Unangband */
1089 feat = (view_unsafe_grids && (g_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 (g_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 (!(g_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 ((g_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 grid -- idea borrowed from Unangband */
1163 feat = (view_unsafe_grids && (g_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 = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1198 o_ptr = &o_list[this_o_idx];
1200 /* Acquire next object */
1201 next_o_idx = o_ptr->next_o_idx;
1203 /* Memorized objects */
1204 if (o_ptr->marked & OM_FOUND)
1206 if (display_autopick)
1210 match_autopick = is_autopick(o_ptr);
1211 if(match_autopick == -1)
1214 act = autopick_list[match_autopick].action;
1216 if ((act & DO_DISPLAY) && (act & display_autopick))
1218 autopick_obj = o_ptr;
1222 match_autopick = -1;
1227 (*cp) = object_char(o_ptr);
1230 (*ap) = object_attr(o_ptr);
1234 /* Hack -- hallucination */
1235 if (p_ptr->image) image_object(ap, cp);
1242 /* Handle monsters */
1243 if (g_ptr->m_idx && display_autopick == 0 )
1245 monster_type *m_ptr = &m_list[g_ptr->m_idx];
1247 /* Visible monster */
1250 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1258 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1259 * flags are always unseen.
1261 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1267 /* Hallucinatory monster */
1268 image_monster(ap, cp);
1273 /* Monster attr/char */
1277 /* Normal monsters */
1278 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1279 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1281 /* Desired monster attr/char */
1287 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1288 * flags are always unseen.
1290 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1297 /*** Monster's attr ***/
1298 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1303 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1305 /* Multi-hued attr */
1306 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1307 else switch (randint1(7))
1309 case 1: *ap = TERM_RED; break;
1310 case 2: *ap = TERM_L_RED; break;
1311 case 3: *ap = TERM_WHITE; break;
1312 case 4: *ap = TERM_L_GREEN; break;
1313 case 5: *ap = TERM_BLUE; break;
1314 case 6: *ap = TERM_L_DARK; break;
1315 case 7: *ap = TERM_GREEN; break;
1318 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1320 /* Use semi-random attr (usually mimics' colors vary) */
1321 *ap = g_ptr->m_idx % 15 + 1;
1329 /*** Monster's char ***/
1330 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1335 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1339 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1340 *cp = tmp_r_ptr->x_char;
1341 *ap = tmp_r_ptr->x_attr;
1345 *cp = (one_in_(25) ?
1346 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1347 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1360 /* Handle "player" */
1361 if (player_bold(y, x))
1363 monster_race *r_ptr = &r_info[0];
1364 *ap = r_ptr->x_attr;
1365 *cp = r_ptr->x_char;
1372 * Calculate panel colum of a location in the map
1374 static int panel_col_of(int col)
1376 col -= panel_col_min;
1377 if (use_bigtile) col *= 2;
1383 * Moves the cursor to a given MAP (y,x) location
1385 void move_cursor_relative(int row, int col)
1387 /* Real co-ords convert to screen positions */
1388 row -= panel_row_prt;
1391 Term_gotoxy(panel_col_of(col), row);
1397 * Place an attr/char pair at the given map coordinate, if legal.
1399 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
1401 /* Only do "legal" locations */
1402 if (panel_contains(y, x))
1404 /* Hack -- fake monochrome */
1407 if (world_monster) a = TERM_DARK;
1408 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1409 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1412 /* Draw the char using the attr */
1413 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, 0, 0);
1422 * Memorize interesting viewable object/features in the given grid
1424 * This function should only be called on "legal" grids.
1426 * This function will memorize the object and/or feature in the given
1427 * grid, if they are (1) viewable and (2) interesting. Note that all
1428 * objects are interesting, all terrain features except floors (and
1429 * invisible traps) are interesting, and floors (and invisible traps)
1430 * are interesting sometimes (depending on various options involving
1431 * the illumination of floor grids).
1433 * The automatic memorization of all objects and non-floor terrain
1434 * features as soon as they are displayed allows incredible amounts
1435 * of optimization in various places, especially "map_info()".
1437 * Note that the memorization of objects is completely separate from
1438 * the memorization of terrain features, preventing annoying floor
1439 * memorization when a detected object is picked up from a dark floor,
1440 * and object memorization when an object is dropped into a floor grid
1441 * which is memorized but out-of-sight.
1443 * This function should be called every time the "memorization" of
1444 * a grid (or the object in a grid) is called into question, such
1445 * as when an object is created in a grid, when a terrain feature
1446 * "changes" from "floor" to "non-floor", when any grid becomes
1447 * "illuminated" or "viewable", and when a "floor" grid becomes
1450 * Note the relatively efficient use of this function by the various
1451 * "update_view()" and "update_lite()" calls, to allow objects and
1452 * terrain features to be memorized (and drawn) whenever they become
1453 * viewable or illuminated in any way, but not when they "maintain"
1454 * or "lose" their previous viewability or illumination.
1456 * Note the butchered "internal" version of "player_can_see_bold()",
1457 * optimized primarily for the most common cases, that is, for the
1458 * non-marked floor grids.
1460 void note_spot(POSITION y, POSITION x)
1462 grid_type *g_ptr = &grid_array[y][x];
1463 OBJECT_IDX this_o_idx, next_o_idx = 0;
1465 /* Blind players see nothing */
1466 if (p_ptr->blind) return;
1468 /* Analyze non-torch-lit grids */
1469 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1471 /* Require line of sight to the grid */
1472 if (!(g_ptr->info & (CAVE_VIEW))) return;
1474 /* Require "perma-lite" of the grid */
1475 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1478 if (!p_ptr->see_nocto) return;
1483 /* Hack -- memorize objects */
1484 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1486 object_type *o_ptr = &o_list[this_o_idx];
1488 /* Acquire next object */
1489 next_o_idx = o_ptr->next_o_idx;
1491 /* Memorize objects */
1492 o_ptr->marked |= OM_FOUND;
1496 /* Hack -- memorize grids */
1497 if (!(g_ptr->info & (CAVE_MARK)))
1499 /* Feature code (applying "mimic" field) */
1500 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
1502 /* Memorize some "boring" grids */
1503 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1505 /* Option -- memorize all torch-lit floors */
1506 if (view_torch_grids &&
1507 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1509 g_ptr->info |= (CAVE_MARK);
1512 /* Option -- memorize all perma-lit floors */
1513 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1515 g_ptr->info |= (CAVE_MARK);
1519 /* Memorize normal grids */
1520 else if (have_flag(f_ptr->flags, FF_LOS))
1522 g_ptr->info |= (CAVE_MARK);
1525 /* Memorize torch-lit walls */
1526 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1528 g_ptr->info |= (CAVE_MARK);
1531 /* Memorize walls seen by noctovision of Ninja */
1532 else if (p_ptr->see_nocto)
1534 g_ptr->info |= (CAVE_MARK);
1537 /* Memorize certain non-torch-lit wall grids */
1538 else if (check_local_illumination(y, x))
1540 g_ptr->info |= (CAVE_MARK);
1544 /* Memorize terrain of the grid */
1545 g_ptr->info |= (CAVE_KNOWN);
1549 void display_dungeon(void)
1556 SYMBOL_CODE tc = '\0';
1558 for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
1560 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
1562 if (in_bounds2(y, x))
1565 /* Examine the grid */
1566 map_info(y, x, &a, &c, &ta, &tc);
1568 /* Hack -- fake monochrome */
1571 if (world_monster) a = TERM_DARK;
1572 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1573 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1576 /* Hack -- Queue it */
1577 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1581 /* Clear out-of-bound tiles */
1583 /* Access darkness */
1584 feature_type *f_ptr = &f_info[feat_none];
1587 a = f_ptr->x_attr[F_LIT_STANDARD];
1590 c = f_ptr->x_char[F_LIT_STANDARD];
1592 /* Hack -- Queue it */
1593 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1601 * Redraw (on the screen) a given MAP location
1603 * This function should only be called on "legal" grids
1605 void lite_spot(POSITION y, POSITION x)
1607 /* Redraw if on screen */
1608 if (panel_contains(y, x) && in_bounds2(y, x))
1616 /* Examine the grid */
1617 map_info(y, x, &a, &c, &ta, &tc);
1619 /* Hack -- fake monochrome */
1622 if (world_monster) a = TERM_DARK;
1623 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1624 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1627 /* Hack -- Queue it */
1628 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1630 /* Update sub-windows */
1631 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1637 * Prints the map of the dungeon
1639 * Note that, for efficiency, we contain an "optimized" version
1640 * of both "lite_spot()" and "print_rel()", and that we use the
1641 * "lite_spot()" function to display the player grid, if needed.
1649 POSITION xmin, xmax, ymin, ymax;
1653 Term_get_size(&wid, &hgt);
1655 /* Remove map offset */
1659 /* Access the cursor state */
1660 (void)Term_get_cursor(&v);
1662 /* Hide the cursor */
1663 (void)Term_set_cursor(0);
1666 xmin = (0 < panel_col_min) ? panel_col_min : 0;
1667 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1668 ymin = (0 < panel_row_min) ? panel_row_min : 0;
1669 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1671 /* Bottom section of screen */
1672 for (y = 1; y <= ymin - panel_row_prt; y++)
1674 /* Erase the section */
1675 Term_erase(COL_MAP, y, wid);
1678 /* Top section of screen */
1679 for (y = ymax - panel_row_prt; y <= hgt; y++)
1681 /* Erase the section */
1682 Term_erase(COL_MAP, y, wid);
1686 for (y = ymin; y <= ymax; y++)
1688 /* Scan the columns of row "y" */
1689 for (x = xmin; x <= xmax; x++)
1697 /* Determine what is there */
1698 map_info(y, x, &a, &c, &ta, &tc);
1700 /* Hack -- fake monochrome */
1703 if (world_monster) a = TERM_DARK;
1704 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1705 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1708 /* Efficiency -- Redraw that grid of the map */
1709 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1713 /* Display player */
1714 lite_spot(p_ptr->y, p_ptr->x);
1716 /* Restore the cursor */
1717 (void)Term_set_cursor(v);
1723 * print project path
1725 void prt_path(POSITION y, POSITION x)
1730 byte_hack default_color = TERM_SLATE;
1732 if (!display_path) return;
1733 if (-1 == project_length)
1736 /* Get projection path */
1737 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH|PROJECT_THRU);
1739 p_ptr->redraw |= (PR_MAP);
1743 for (i = 0; i < path_n; i++)
1745 POSITION ny = GRID_Y(path_g[i]);
1746 POSITION nx = GRID_X(path_g[i]);
1747 grid_type *g_ptr = &grid_array[ny][nx];
1749 if (panel_contains(ny, nx))
1751 TERM_COLOR a = default_color;
1754 TERM_COLOR ta = default_color;
1757 if (g_ptr->m_idx && m_list[g_ptr->m_idx].ml)
1759 /* Determine what is there */
1760 map_info(ny, nx, &a, &c, &ta, &tc);
1762 if (!is_ascii_graphics(a))
1764 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1766 else if (a == default_color)
1772 if (world_monster) a = TERM_DARK;
1773 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1774 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1779 /* Hack -- Queue it */
1780 Term_queue_bigchar(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
1784 if ((g_ptr->info & CAVE_MARK) && !cave_have_flag_grid(g_ptr, FF_PROJECT)) break;
1787 if (nx == x && ny == y) default_color = TERM_L_DARK;
1792 static concptr simplify_list[][2] =
1799 {"^Amulet of ", "\""},
1800 {"^Scroll of ", "?"},
1801 {"^Scroll titled ", "?"},
1802 {"^Wand of " , "-"},
1804 {"^Staff of " , "_"},
1805 {"^Potion of ", "!"},
1817 static void display_shortened_item_name(object_type *o_ptr, int y)
1824 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
1825 attr = tval_to_attr[o_ptr->tval % 128];
1830 strcpy(buf, _("何か奇妙な物", "something strange"));
1833 for (c = buf; *c; c++)
1836 for (i = 0; simplify_list[i][1]; i++)
1838 concptr org_w = simplify_list[i][0];
1848 if (!strncmp(c, org_w, strlen(org_w)))
1851 concptr tmp = simplify_list[i][1];
1854 tmp = c + strlen(org_w);
1870 if(len + 2 > 12) break;
1877 if(len + 1 > 12) break;
1883 Term_putstr(0, y, 12, attr, buf);
1887 * Display a "small-scale" map of the dungeon in the active Term
1889 void display_map(int *cy, int *cx)
1899 SYMBOL_CODE **bigmc;
1906 /* Save lighting effects */
1907 bool old_view_special_lite = view_special_lite;
1908 bool old_view_granite_lite = view_granite_lite;
1910 TERM_LEN hgt, wid, yrat, xrat;
1912 int **match_autopick_yx;
1913 object_type ***object_autopick_yx;
1915 Term_get_size(&wid, &hgt);
1918 if (use_bigtile) wid /= 2;
1920 yrat = (cur_hgt + hgt - 1) / hgt;
1921 xrat = (cur_wid + wid - 1) / wid;
1923 /* Disable lighting effects */
1924 view_special_lite = FALSE;
1925 view_granite_lite = FALSE;
1927 /* Allocate the maps */
1928 C_MAKE(ma, (hgt + 2), TERM_COLOR *);
1929 C_MAKE(mc, (hgt + 2), char_ptr);
1930 C_MAKE(mp, (hgt + 2), byte_ptr);
1931 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
1932 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
1934 /* Allocate and wipe each line map */
1935 for (y = 0; y < (hgt + 2); y++)
1937 /* Allocate one row each array */
1938 C_MAKE(ma[y], (wid + 2), TERM_COLOR);
1939 C_MAKE(mc[y], (wid + 2), char);
1940 C_MAKE(mp[y], (wid + 2), byte);
1941 C_MAKE(match_autopick_yx[y], (wid + 2), int);
1942 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
1944 for (x = 0; x < wid + 2; ++x)
1946 match_autopick_yx[y][x] = -1;
1947 object_autopick_yx[y][x] = NULL;
1950 ma[y][x] = TERM_WHITE;
1958 /* Allocate the maps */
1959 C_MAKE(bigma, (cur_hgt + 2), TERM_COLOR *);
1960 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
1961 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
1963 /* Allocate and wipe each line map */
1964 for (y = 0; y < (cur_hgt + 2); y++)
1966 /* Allocate one row each array */
1967 C_MAKE(bigma[y], (cur_wid + 2), TERM_COLOR);
1968 C_MAKE(bigmc[y], (cur_wid + 2), char);
1969 C_MAKE(bigmp[y], (cur_wid + 2), byte);
1971 for (x = 0; x < cur_wid + 2; ++x)
1974 bigma[y][x] = TERM_WHITE;
1982 /* Fill in the map */
1983 for (i = 0; i < cur_wid; ++i)
1985 for (j = 0; j < cur_hgt; ++j)
1994 /* Extract the current attr/char at that map location */
1995 map_info(j, i, &ta, &tc, &ta, &tc);
1997 /* Extract the priority */
1998 tp = (byte_hack)feat_priority;
2000 if(match_autopick!=-1
2001 && (match_autopick_yx[y][x] == -1
2002 || match_autopick_yx[y][x] > match_autopick))
2004 match_autopick_yx[y][x] = match_autopick;
2005 object_autopick_yx[y][x] = autopick_obj;
2009 /* Save the char, attr and priority */
2010 bigmc[j+1][i+1] = tc;
2011 bigma[j+1][i+1] = ta;
2012 bigmp[j+1][i+1] = tp;
2016 for (j = 0; j < cur_hgt; ++j)
2018 for (i = 0; i < cur_wid; ++i)
2023 tc = bigmc[j+1][i+1];
2024 ta = bigma[j+1][i+1];
2025 tp = bigmp[j+1][i+1];
2027 /* rare feature has more priority */
2033 for (t = 0; t < 8; t++)
2035 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2036 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2046 /* Save the char, attr and priority */
2059 /* Draw the corners */
2060 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2062 /* Draw the horizontal edges */
2063 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2065 /* Draw the vertical edges */
2066 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2069 /* Display each map line in order */
2070 for (y = 0; y < hgt + 2; ++y)
2072 /* Start a new line */
2073 Term_gotoxy(COL_MAP, y);
2075 /* Display the line */
2076 for (x = 0; x < wid + 2; ++x)
2081 /* Hack -- fake monochrome */
2084 if (world_monster) ta = TERM_DARK;
2085 else if (IS_INVULN() || p_ptr->timewalk) ta = TERM_WHITE;
2086 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2089 /* Add the character */
2090 Term_add_bigch(ta, tc);
2095 for (y = 1; y < hgt + 1; ++y)
2097 match_autopick = -1;
2098 for (x = 1; x <= wid; x++){
2099 if (match_autopick_yx[y][x] != -1 &&
2100 (match_autopick > match_autopick_yx[y][x] ||
2101 match_autopick == -1)){
2102 match_autopick = match_autopick_yx[y][x];
2103 autopick_obj = object_autopick_yx[y][x];
2107 /* Clear old display */
2108 Term_putstr(0, y, 12, 0, " ");
2110 if (match_autopick != -1)
2112 display_shortened_item_name(autopick_obj, y);
2115 char buf[13] = "\0";
2116 strncpy(buf,autopick_list[match_autopick].name,12);
2124 /* Player location */
2125 (*cy) = p_ptr->y / yrat + 1 + ROW_MAP;
2127 (*cx) = p_ptr->x / xrat + 1 + COL_MAP;
2129 (*cx) = (p_ptr->x / xrat + 1) * 2 + COL_MAP;
2131 /* Restore lighting effects */
2132 view_special_lite = old_view_special_lite;
2133 view_granite_lite = old_view_granite_lite;
2135 /* Free each line map */
2136 for (y = 0; y < (hgt + 2); y++)
2138 /* Free one row each array */
2139 C_KILL(ma[y], (wid + 2), TERM_COLOR);
2140 C_KILL(mc[y], (wid + 2), SYMBOL_CODE);
2141 C_KILL(mp[y], (wid + 2), byte);
2142 C_KILL(match_autopick_yx[y], (wid + 2), int);
2143 C_KILL(object_autopick_yx[y], (wid + 2), object_type *);
2146 /* Free each line map */
2147 C_KILL(ma, (hgt + 2), TERM_COLOR *);
2148 C_KILL(mc, (hgt + 2), char_ptr);
2149 C_KILL(mp, (hgt + 2), byte_ptr);
2150 C_KILL(match_autopick_yx, (hgt + 2), sint_ptr);
2151 C_KILL(object_autopick_yx, (hgt + 2), object_type **);
2153 /* Free each line map */
2154 for (y = 0; y < (cur_hgt + 2); y++)
2156 /* Free one row each array */
2157 C_KILL(bigma[y], (cur_wid + 2), TERM_COLOR);
2158 C_KILL(bigmc[y], (cur_wid + 2), SYMBOL_CODE);
2159 C_KILL(bigmp[y], (cur_wid + 2), byte);
2162 /* Free each line map */
2163 C_KILL(bigma, (cur_hgt + 2), TERM_COLOR *);
2164 C_KILL(bigmc, (cur_hgt + 2), char_ptr);
2165 C_KILL(bigmp, (cur_hgt + 2), byte_ptr);
2170 * Display a "small-scale" map of the dungeon for the player
2172 * Currently, the "player" is displayed on the map.
2174 void do_cmd_view_map(void)
2180 prt(_("お待ち下さい...", "Please wait..."), 0, 0);
2185 display_autopick = 0;
2187 /* Display the map */
2188 display_map(&cy, &cx);
2191 if(max_autopick && !p_ptr->wild_mode)
2193 display_autopick = ITEM_DISPLAY;
2200 int wid, hgt, row_message;
2202 Term_get_size(&wid, &hgt);
2203 row_message = hgt - 1;
2205 put_str(_("何かキーを押してください('M':拾う 'N':放置 'D':M+N 'K':壊すアイテムを表示)",
2206 " Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items."), row_message, 1);
2208 /* Hilite the player */
2209 move_cursor(cy, cx);
2214 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2216 flag = DONT_AUTOPICK;
2218 flag = DO_AUTODESTROY;
2220 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2226 if (~display_autopick & flag)
2227 display_autopick |= flag;
2229 display_autopick &= ~flag;
2230 /* Display the map */
2231 display_map(&cy, &cx);
2234 display_autopick = 0;
2239 put_str(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"), 23, 30);
2240 /* Hilite the player */
2241 move_cursor(cy, cx);
2253 * Some comments on the grid flags. -BEN-
2256 * One of the major bottlenecks in previous versions of Angband was in
2257 * the calculation of "line of sight" from the player to various grids,
2258 * such as monsters. This was such a nasty bottleneck that a lot of
2259 * silly things were done to reduce the dependancy on "line of sight",
2260 * for example, you could not "see" any grids in a lit room until you
2261 * actually entered the room, and there were all kinds of bizarre grid
2262 * flags to enable this behavior. This is also why the "call light"
2263 * spells always lit an entire room.
2265 * The code below provides functions to calculate the "field of view"
2266 * for the player, which, once calculated, provides extremely fast
2267 * calculation of "line of sight from the player", and to calculate
2268 * the "field of torch lite", which, again, once calculated, provides
2269 * extremely fast calculation of "which grids are lit by the player's
2270 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2271 * "GRID_LITE", as appropriate, these functions maintain an array for
2272 * each of these two flags, each array containing the locations of all
2273 * of the grids marked with the appropriate flag, which can be used to
2274 * very quickly scan through all of the grids in a given set.
2276 * To allow more "semantically valid" field of view semantics, whenever
2277 * the field of view (or the set of torch lit grids) changes, all of the
2278 * grids in the field of view (or the set of torch lit grids) are "drawn"
2279 * so that changes in the world will become apparent as soon as possible.
2280 * This has been optimized so that only grids which actually "change" are
2281 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2282 * of the grids which are entering or leaving the relevent set of grids.
2284 * These new methods are so efficient that the old nasty code was removed.
2286 * Note that there is no reason to "update" the "viewable space" unless
2287 * the player "moves", or walls/doors are created/destroyed, and there
2288 * is no reason to "update" the "torch lit grids" unless the field of
2289 * view changes, or the "light radius" changes. This means that when
2290 * the player is resting, or digging, or doing anything that does not
2291 * involve movement or changing the state of the dungeon, there is no
2292 * need to update the "view" or the "lite" regions, which is nice.
2294 * Note that the calls to the nasty "los()" function have been reduced
2295 * to a bare minimum by the use of the new "field of view" calculations.
2297 * I wouldn't be surprised if slight modifications to the "update_view()"
2298 * function would allow us to determine "reverse line-of-sight" as well
2299 * as "normal line-of-sight", which would allow monsters to use a more
2300 * "correct" calculation to determine if they can "see" the player. For
2301 * now, monsters simply "cheat" somewhat and assume that if the player
2302 * has "line of sight" to the monster, then the monster can "pretend"
2303 * that it has "line of sight" to the player.
2306 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2307 * grid and maintains an array of all "CAVE_LITE" grids.
2309 * This set of grids is the complete set of all grids which are lit by
2310 * the players light source, which allows the "player_can_see_bold()"
2311 * function to work very quickly.
2313 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2314 * fact, the player (unless blind) can always "see" all grids which are
2315 * marked as "CAVE_LITE", unless they are "off screen".
2318 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2319 * grid and maintains an array of all "CAVE_VIEW" grids.
2321 * This set of grids is the complete set of all grids within line of sight
2322 * of the player, allowing the "player_has_los_bold()" macro to work very
2326 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2327 * temporary internal flag to mark those grids which are not only in view,
2328 * but which are also "easily" in line of sight of the player. This flag
2329 * is always cleared when we are done.
2332 * The current "update_lite()" and "update_view()" algorithms use the
2333 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2334 * to keep track of which grids were previously marked as "CAVE_LITE" or
2335 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2337 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2338 * for various other purposes, such as spreading lite or darkness during
2339 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2342 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2343 * in some way permanently lit. However, for the player to "see" anything
2344 * in the grid, as determined by "player_can_see()", the player must not be
2345 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2346 * grids, even if marked as "perma lit", are only illuminated if they touch
2347 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2350 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2351 * that even if the player cannot "see" the grid, he "knows" the terrain in
2352 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2353 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2354 * or when one of the "memorize floor grids" options induces memorization.
2356 * Objects are "memorized" in a different way, using a special "marked" flag
2357 * on the object itself, which is set when an object is observed or detected.
2360 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2361 * and should be illuminated by "lite room" and "darkness" spells.
2364 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2365 * and should be unavailable for "teleportation" destinations.
2368 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2369 * which is observed, and the "view_torch_grids" allows the player to memorize
2370 * every torch-lit grid. The player will always memorize important walls,
2371 * doors, stairs, and other terrain features, as well as any "detected" grids.
2373 * Note that the new "update_view()" method allows, among other things, a room
2374 * to be "partially" seen as the player approaches it, with a growing cone of
2375 * floor appearing as the player gets closer to the door. Also, by not turning
2376 * on the "memorize perma-lit grids" option, the player will only "see" those
2377 * floor grids which are actually in line of sight.
2379 * And my favorite "plus" is that you can now use a special option to draw the
2380 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2381 * grids dimly), providing a "pretty" effect as the player runs around, and
2382 * to efficiently display the "torch lite" in a special color.
2385 * Some comments on the "update_view()" algorithm...
2387 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2388 * and only has to call "los()" on the borderline cases. The major axes/diags
2389 * even terminate early when they hit walls. I need to find a quick way
2390 * to "terminate" the other scans.
2392 * Note that in the worst case (a big empty area with say 5% scattered walls),
2393 * each of the 1500 or so nearby grids is checked once, most of them getting
2394 * an "instant" rating, and only a small portion requiring a call to "los()".
2396 * The only time that the algorithm appears to be "noticeably" too slow is
2397 * when running, and this is usually only important in town, since the town
2398 * provides about the worst scenario possible, with large open regions and
2399 * a few scattered obstructions. There is a special "efficiency" option to
2400 * allow the player to reduce his field of view in town, if needed.
2402 * In the "best" case (say, a normal stretch of corridor), the algorithm
2403 * makes one check for each viewable grid, and makes no calls to "los()".
2404 * So running in corridors is very fast, and if a lot of monsters are
2405 * nearby, it is much faster than the old methods.
2407 * Note that resting, most normal commands, and several forms of running,
2408 * plus all commands executed near large groups of monsters, are strictly
2409 * more efficient with "update_view()" that with the old "compute los() on
2410 * demand" method, primarily because once the "field of view" has been
2411 * calculated, it does not have to be recalculated until the player moves
2412 * (or a wall or door is created or destroyed).
2414 * Note that we no longer have to do as many "los()" checks, since once the
2415 * "view" region has been built, very few things cause it to be "changed"
2416 * (player movement, and the opening/closing of doors, changes in wall status).
2417 * Note that door/wall changes are only relevant when the door/wall itself is
2418 * in the "view" region.
2420 * The algorithm seems to only call "los()" from zero to ten times, usually
2421 * only when coming down a corridor into a room, or standing in a room, just
2422 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2423 * we will be reducing the calls to "los()".
2425 * I am thinking in terms of an algorithm that "walks" from the central point
2426 * out to the maximal "distance", at each point, determining the "view" code
2427 * (above). For each grid not on a major axis or diagonal, the "view" code
2428 * depends on the "cave_los_bold()" and "view" of exactly two other grids
2429 * (the one along the nearest diagonal, and the one next to that one, see
2430 * "update_view_aux()"...).
2432 * We "memorize" the viewable space array, so that at the cost of under 3000
2433 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2434 * each grid actually in the "viewable space". And for another 3000 bytes,
2435 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2436 * are also used by other routines, thus reducing the cost to almost nothing.
2438 * A similar thing is done for "forget_lite()" in which case the savings are
2439 * much less, but save us from doing bizarre maintenance checking.
2441 * In the worst "normal" case (in the middle of the town), the reachable space
2442 * actually reaches to more than half of the largest possible "circle" of view,
2443 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2444 * where all the walls have been removed), the reachable space actually reaches
2445 * the theoretical maximum size of just under 1500 grids.
2447 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2448 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2449 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2450 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2451 * entire possible space (including initialization) in one step per grid. If
2452 * we do the "clearing" as a separate step (and use an array of "view" grids),
2453 * then the clearing will take as many steps as grids that were viewed, and the
2454 * algorithm will be able to "stop" scanning at various points.
2455 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2466 * Actually erase the entire "lite" array, redrawing every grid
2468 void forget_lite(void)
2472 /* None to forget */
2473 if (!lite_n) return;
2475 /* Clear them all */
2476 for (i = 0; i < lite_n; i++)
2481 /* Forget "LITE" flag */
2482 grid_array[y][x].info &= ~(CAVE_LITE);
2484 /* lite_spot(y, x); Perhaps don't need? */
2493 * For delayed visual update
2495 #define cave_note_and_redraw_later(C,Y,X) \
2497 (C)->info |= CAVE_NOTE; \
2498 cave_redraw_later((C), (Y), (X)); \
2503 * For delayed visual update
2505 #define cave_redraw_later(C,Y,X) \
2507 if (!((C)->info & CAVE_REDRAW)) \
2509 (C)->info |= CAVE_REDRAW; \
2510 redraw_y[redraw_n] = (Y); \
2511 redraw_x[redraw_n++] = (X); \
2517 * This macro allows us to efficiently add a grid to the "lite" array,
2518 * note that we are never called for illegal grids, or for grids which
2519 * have already been placed into the "lite" array, and we are never
2520 * called when the "lite" array is full.
2522 #define cave_lite_hack(Y,X) \
2524 if (!(grid_array[Y][X].info & (CAVE_LITE))) \
2526 grid_array[Y][X].info |= (CAVE_LITE); \
2527 lite_y[lite_n] = (Y); \
2528 lite_x[lite_n++] = (X); \
2534 * Update the set of grids "illuminated" by the player's lite.
2536 * This routine needs to use the results of "update_view()"
2538 * Note that "blindness" does NOT affect "torch lite". Be careful!
2540 * We optimize most lites (all non-artifact lites) by using "obvious"
2541 * facts about the results of "small" lite radius, and we attempt to
2542 * list the "nearby" grids before the more "distant" ones in the
2543 * array of torch-lit grids.
2545 * We assume that "radius zero" lite is in fact no lite at all.
2547 * Torch Lantern Artifacts
2557 void update_lite(void)
2560 POSITION x, y, min_x, max_x, min_y, max_y;
2561 int p = p_ptr->cur_lite;
2564 /*** Special case ***/
2567 /* Hack -- Player has no lite */
2570 /* Forget the old lite */
2571 /* forget_lite(); Perhaps don't need? */
2573 /* Add it to later visual update */
2574 cave_redraw_later(&grid_array[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
2578 /*** Save the old "lite" grids for later ***/
2580 /* Clear them all */
2581 for (i = 0; i < lite_n; i++)
2586 /* Mark the grid as not "lite" */
2587 grid_array[y][x].info &= ~(CAVE_LITE);
2589 /* Mark the grid as "seen" */
2590 grid_array[y][x].info |= (CAVE_TEMP);
2592 /* Add it to the "seen" set */
2602 /*** Collect the new "lite" grids ***/
2604 /* Radius 1 -- torch radius */
2608 cave_lite_hack(p_ptr->y, p_ptr->x);
2611 cave_lite_hack(p_ptr->y+1, p_ptr->x);
2612 cave_lite_hack(p_ptr->y-1, p_ptr->x);
2613 cave_lite_hack(p_ptr->y, p_ptr->x+1);
2614 cave_lite_hack(p_ptr->y, p_ptr->x-1);
2616 /* Diagonal grids */
2617 cave_lite_hack(p_ptr->y+1, p_ptr->x+1);
2618 cave_lite_hack(p_ptr->y+1, p_ptr->x-1);
2619 cave_lite_hack(p_ptr->y-1, p_ptr->x+1);
2620 cave_lite_hack(p_ptr->y-1, p_ptr->x-1);
2623 /* Radius 2 -- lantern radius */
2626 /* South of the player */
2627 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
2629 cave_lite_hack(p_ptr->y+2, p_ptr->x);
2630 cave_lite_hack(p_ptr->y+2, p_ptr->x+1);
2631 cave_lite_hack(p_ptr->y+2, p_ptr->x-1);
2634 /* North of the player */
2635 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
2637 cave_lite_hack(p_ptr->y-2, p_ptr->x);
2638 cave_lite_hack(p_ptr->y-2, p_ptr->x+1);
2639 cave_lite_hack(p_ptr->y-2, p_ptr->x-1);
2642 /* East of the player */
2643 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
2645 cave_lite_hack(p_ptr->y, p_ptr->x+2);
2646 cave_lite_hack(p_ptr->y+1, p_ptr->x+2);
2647 cave_lite_hack(p_ptr->y-1, p_ptr->x+2);
2650 /* West of the player */
2651 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
2653 cave_lite_hack(p_ptr->y, p_ptr->x-2);
2654 cave_lite_hack(p_ptr->y+1, p_ptr->x-2);
2655 cave_lite_hack(p_ptr->y-1, p_ptr->x-2);
2659 /* Radius 3+ -- artifact radius */
2664 /* Paranoia -- see "LITE_MAX" */
2667 /* South-East of the player */
2668 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
2670 cave_lite_hack(p_ptr->y+2, p_ptr->x+2);
2673 /* South-West of the player */
2674 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
2676 cave_lite_hack(p_ptr->y+2, p_ptr->x-2);
2679 /* North-East of the player */
2680 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
2682 cave_lite_hack(p_ptr->y-2, p_ptr->x+2);
2685 /* North-West of the player */
2686 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
2688 cave_lite_hack(p_ptr->y-2, p_ptr->x-2);
2692 min_y = p_ptr->y - p;
2693 if (min_y < 0) min_y = 0;
2696 max_y = p_ptr->y + p;
2697 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
2700 min_x = p_ptr->x - p;
2701 if (min_x < 0) min_x = 0;
2704 max_x = p_ptr->x + p;
2705 if (max_x > cur_wid-1) max_x = cur_wid-1;
2707 /* Scan the maximal box */
2708 for (y = min_y; y <= max_y; y++)
2710 for (x = min_x; x <= max_x; x++)
2712 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
2713 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
2715 /* Skip the "central" grids (above) */
2716 if ((dy <= 2) && (dx <= 2)) continue;
2718 /* Hack -- approximate the distance */
2719 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2721 /* Skip distant grids */
2722 if (d > p) continue;
2724 /* Viewable, nearby, grids get "torch lit" */
2725 if (grid_array[y][x].info & CAVE_VIEW)
2727 /* This grid is "torch lit" */
2728 cave_lite_hack(y, x);
2735 /*** Complete the algorithm ***/
2737 /* Draw the new grids */
2738 for (i = 0; i < lite_n; i++)
2743 g_ptr = &grid_array[y][x];
2745 /* Update fresh grids */
2746 if (g_ptr->info & (CAVE_TEMP)) continue;
2748 /* Add it to later visual update */
2749 cave_note_and_redraw_later(g_ptr, y, x);
2752 /* Clear them all */
2753 for (i = 0; i < temp_n; i++)
2758 g_ptr = &grid_array[y][x];
2760 /* No longer in the array */
2761 g_ptr->info &= ~(CAVE_TEMP);
2763 /* Update stale grids */
2764 if (g_ptr->info & (CAVE_LITE)) continue;
2766 /* Add it to later visual update */
2767 cave_redraw_later(g_ptr, y, x);
2773 /* Mega-Hack -- Visual update later */
2774 p_ptr->update |= (PU_DELAY_VIS);
2778 static bool mon_invis;
2779 static POSITION mon_fy, mon_fx;
2782 * Add a square to the changes array
2784 static void mon_lite_hack(POSITION y, POSITION x)
2790 /* We trust this grid is in bounds */
2791 /* if (!in_bounds2(y, x)) return; */
2793 g_ptr = &grid_array[y][x];
2795 /* Want a unlit square in view of the player */
2796 if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
2798 if (!cave_los_grid(g_ptr))
2800 /* Hack -- Prevent monster lite leakage in walls */
2802 /* Horizontal walls between player and a monster */
2803 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2805 dpf = p_ptr->y - mon_fy;
2807 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2809 /* Only first wall viewed from mid-x is lit */
2812 if (!cave_los_bold(y, x + 1)) return;
2814 else if (x > midpoint)
2816 if (!cave_los_bold(y, x - 1)) return;
2819 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2820 else if (mon_invis) return;
2823 /* Vertical walls between player and a monster */
2824 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2826 dpf = p_ptr->x - mon_fx;
2828 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2830 /* Only first wall viewed from mid-y is lit */
2833 if (!cave_los_bold(y + 1, x)) return;
2835 else if (y > midpoint)
2837 if (!cave_los_bold(y - 1, x)) return;
2840 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2841 else if (mon_invis) return;
2845 /* We trust temp_n does not exceed TEMP_MAX */
2848 if (!(g_ptr->info & CAVE_MNDK))
2850 /* Save this square */
2859 /* No longer dark */
2860 g_ptr->info &= ~(CAVE_MNDK);
2864 g_ptr->info |= CAVE_MNLT;
2869 * Add a square to the changes array
2871 static void mon_dark_hack(POSITION y, POSITION x)
2874 int midpoint, dpf, d;
2876 /* We trust this grid is in bounds */
2877 /* if (!in_bounds2(y, x)) return; */
2879 g_ptr = &grid_array[y][x];
2881 /* Want a unlit and undarkened square in view of the player */
2882 if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
2884 if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
2886 /* Hack -- Prevent monster dark lite leakage in walls */
2888 /* Horizontal walls between player and a monster */
2889 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2891 dpf = p_ptr->y - mon_fy;
2893 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2895 /* Only first wall viewed from mid-x is lit */
2898 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
2900 else if (x > midpoint)
2902 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
2905 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2906 else if (mon_invis) return;
2909 /* Vertical walls between player and a monster */
2910 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2912 dpf = p_ptr->x - mon_fx;
2914 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2916 /* Only first wall viewed from mid-y is lit */
2919 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
2921 else if (y > midpoint)
2923 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
2926 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2927 else if (mon_invis) return;
2931 /* We trust temp_n does not exceed TEMP_MAX */
2933 /* Save this square */
2939 g_ptr->info |= CAVE_MNDK;
2944 * Update squares illuminated or darkened by monsters.
2946 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
2947 * denote squares illuminated by monsters.
2949 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
2950 * updating. Only squares in view of the player, whos state
2951 * changes are drawn via lite_spot().
2953 void update_mon_lite(void)
2959 void (*add_mon_lite)(POSITION, POSITION);
2964 /* Non-Ninja player in the darkness */
2965 int dis_lim = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
2966 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
2968 /* Clear all monster lit squares */
2969 for (i = 0; i < mon_lite_n; i++)
2972 g_ptr = &grid_array[mon_lite_y[i]][mon_lite_x[i]];
2974 /* Set temp or xtra flag */
2975 g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
2977 /* Clear monster illumination flag */
2978 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
2981 /* Empty temp list of new squares to lite up */
2984 /* If a monster stops time, don't process */
2987 monster_type *m_ptr;
2988 monster_race *r_ptr;
2990 /* Loop through monsters, adding newly lit squares to changes list */
2991 for (i = 1; i < m_max; i++)
2994 r_ptr = &r_info[m_ptr->r_idx];
2996 /* Skip dead monsters */
2997 if (!m_ptr->r_idx) continue;
2999 /* Is it too far away? */
3000 if (m_ptr->cdis > dis_lim) continue;
3002 /* Get lite radius */
3005 /* Note the radii are cumulative */
3006 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3007 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3008 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3009 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3011 /* Exit if has no light */
3015 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;
3016 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
3017 add_mon_lite = mon_lite_hack;
3022 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && !is_daytime()))) continue;
3023 add_mon_lite = mon_dark_hack;
3024 f_flag = FF_PROJECT;
3025 rad = -rad; /* Use absolute value */
3028 /* Access the location */
3032 /* Is the monster visible? */
3033 mon_invis = !(grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
3035 /* The square it is on */
3036 add_mon_lite(mon_fy, mon_fx);
3038 /* Adjacent squares */
3039 add_mon_lite(mon_fy + 1, mon_fx);
3040 add_mon_lite(mon_fy - 1, mon_fx);
3041 add_mon_lite(mon_fy, mon_fx + 1);
3042 add_mon_lite(mon_fy, mon_fx - 1);
3043 add_mon_lite(mon_fy + 1, mon_fx + 1);
3044 add_mon_lite(mon_fy + 1, mon_fx - 1);
3045 add_mon_lite(mon_fy - 1, mon_fx + 1);
3046 add_mon_lite(mon_fy - 1, mon_fx - 1);
3051 /* South of the monster */
3052 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
3054 add_mon_lite(mon_fy + 2, mon_fx + 1);
3055 add_mon_lite(mon_fy + 2, mon_fx);
3056 add_mon_lite(mon_fy + 2, mon_fx - 1);
3058 g_ptr = &grid_array[mon_fy + 2][mon_fx];
3061 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3063 add_mon_lite(mon_fy + 3, mon_fx + 1);
3064 add_mon_lite(mon_fy + 3, mon_fx);
3065 add_mon_lite(mon_fy + 3, mon_fx - 1);
3069 /* North of the monster */
3070 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
3072 add_mon_lite(mon_fy - 2, mon_fx + 1);
3073 add_mon_lite(mon_fy - 2, mon_fx);
3074 add_mon_lite(mon_fy - 2, mon_fx - 1);
3076 g_ptr = &grid_array[mon_fy - 2][mon_fx];
3079 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3081 add_mon_lite(mon_fy - 3, mon_fx + 1);
3082 add_mon_lite(mon_fy - 3, mon_fx);
3083 add_mon_lite(mon_fy - 3, mon_fx - 1);
3087 /* East of the monster */
3088 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
3090 add_mon_lite(mon_fy + 1, mon_fx + 2);
3091 add_mon_lite(mon_fy, mon_fx + 2);
3092 add_mon_lite(mon_fy - 1, mon_fx + 2);
3094 g_ptr = &grid_array[mon_fy][mon_fx + 2];
3097 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3099 add_mon_lite(mon_fy + 1, mon_fx + 3);
3100 add_mon_lite(mon_fy, mon_fx + 3);
3101 add_mon_lite(mon_fy - 1, mon_fx + 3);
3105 /* West of the monster */
3106 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
3108 add_mon_lite(mon_fy + 1, mon_fx - 2);
3109 add_mon_lite(mon_fy, mon_fx - 2);
3110 add_mon_lite(mon_fy - 1, mon_fx - 2);
3112 g_ptr = &grid_array[mon_fy][mon_fx - 2];
3115 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3117 add_mon_lite(mon_fy + 1, mon_fx - 3);
3118 add_mon_lite(mon_fy, mon_fx - 3);
3119 add_mon_lite(mon_fy - 1, mon_fx - 3);
3127 /* South-East of the monster */
3128 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
3130 add_mon_lite(mon_fy + 2, mon_fx + 2);
3133 /* South-West of the monster */
3134 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
3136 add_mon_lite(mon_fy + 2, mon_fx - 2);
3139 /* North-East of the monster */
3140 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
3142 add_mon_lite(mon_fy - 2, mon_fx + 2);
3145 /* North-West of the monster */
3146 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
3148 add_mon_lite(mon_fy - 2, mon_fx - 2);
3154 /* Save end of list of new squares */
3158 * Look at old set flags to see if there are any changes.
3160 for (i = 0; i < mon_lite_n; i++)
3165 /* We trust this grid is in bounds */
3168 g_ptr = &grid_array[fy][fx];
3170 if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
3172 /* It it no longer lit? */
3173 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3175 /* It is now unlit */
3176 /* Add it to later visual update */
3177 cave_note_and_redraw_later(g_ptr, fy, fx);
3180 else /* Pervious darkened */
3182 /* It it no longer darken? */
3183 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3185 /* It is now undarken */
3186 /* Add it to later visual update */
3187 cave_note_and_redraw_later(g_ptr, fy, fx);
3191 /* Add to end of temp array */
3192 temp_x[temp_n] = fx;
3193 temp_y[temp_n] = fy;
3197 /* Clear the lite array */
3200 /* Copy the temp array into the lit array lighting the new squares. */
3201 for (i = 0; i < end_temp; i++)
3206 /* We trust this grid is in bounds */
3209 g_ptr = &grid_array[fy][fx];
3211 if (g_ptr->info & CAVE_MNLT) /* Lit */
3213 /* The is the square newly lit and visible? */
3214 if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3217 /* Add it to later visual update */
3218 cave_note_and_redraw_later(g_ptr, fy, fx);
3223 /* The is the square newly darkened and visible? */
3224 if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3226 /* It is now darkened */
3227 /* Add it to later visual update */
3228 cave_note_and_redraw_later(g_ptr, fy, fx);
3232 /* Save in the monster lit or darkened array */
3233 mon_lite_x[mon_lite_n] = fx;
3234 mon_lite_y[mon_lite_n] = fy;
3238 /* Clear the temp flag for the old lit or darken grids */
3239 for (i = end_temp; i < temp_n; i++)
3241 /* We trust this grid is in bounds */
3243 grid_array[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3246 /* Finished with temp_n */
3249 /* Mega-Hack -- Visual update later */
3250 p_ptr->update |= (PU_DELAY_VIS);
3252 p_ptr->monlite = (grid_array[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
3254 if (p_ptr->special_defense & NINJA_S_STEALTH)
3256 if (p_ptr->old_monlite != p_ptr->monlite)
3260 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
3264 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
3268 p_ptr->old_monlite = p_ptr->monlite;
3271 void clear_mon_lite(void)
3276 /* Clear all monster lit squares */
3277 for (i = 0; i < mon_lite_n; i++)
3280 g_ptr = &grid_array[mon_lite_y[i]][mon_lite_x[i]];
3282 /* Clear monster illumination flag */
3283 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3286 /* Empty the array */
3293 * Clear the viewable space
3295 void forget_view(void)
3301 /* None to forget */
3302 if (!view_n) return;
3304 /* Clear them all */
3305 for (i = 0; i < view_n; i++)
3307 POSITION y = view_y[i];
3308 POSITION x = view_x[i];
3309 g_ptr = &grid_array[y][x];
3311 /* Forget that the grid is viewable */
3312 g_ptr->info &= ~(CAVE_VIEW);
3314 /* if (!panel_contains(y, x)) continue; */
3316 /* Update the screen */
3317 /* lite_spot(y, x); Perhaps don't need? */
3327 * This macro allows us to efficiently add a grid to the "view" array,
3328 * note that we are never called for illegal grids, or for grids which
3329 * have already been placed into the "view" array, and we are never
3330 * called when the "view" array is full.
3332 #define cave_view_hack(C,Y,X) \
3334 if (!((C)->info & (CAVE_VIEW))){\
3335 (C)->info |= (CAVE_VIEW); \
3336 view_y[view_n] = (Y); \
3337 view_x[view_n] = (X); \
3344 * Helper function for "update_view()" below
3346 * We are checking the "viewability" of grid (y,x) by the player.
3348 * This function assumes that (y,x) is legal (i.e. on the map).
3350 * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
3351 * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
3353 * Note that we are using the "CAVE_XTRA" field for marking grids as
3354 * "easily viewable". This bit is cleared at the end of "update_view()".
3356 * This function adds (y,x) to the "viewable set" if necessary.
3358 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3360 static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
3362 bool f1, f2, v1, v2, z1, z2, wall;
3366 grid_type *g1_c_ptr;
3367 grid_type *g2_c_ptr;
3369 /* Access the grids */
3370 g1_c_ptr = &grid_array[y1][x1];
3371 g2_c_ptr = &grid_array[y2][x2];
3374 /* Check for walls */
3375 f1 = (cave_los_grid(g1_c_ptr));
3376 f2 = (cave_los_grid(g2_c_ptr));
3378 /* Totally blocked by physical walls */
3379 if (!f1 && !f2) return (TRUE);
3382 /* Check for visibility */
3383 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3384 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3386 /* Totally blocked by "unviewable neighbors" */
3387 if (!v1 && !v2) return (TRUE);
3389 g_ptr = &grid_array[y][x];
3392 /* Check for walls */
3393 wall = (!cave_los_grid(g_ptr));
3396 /* Check the "ease" of visibility */
3397 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3398 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3400 /* Hack -- "easy" plus "easy" yields "easy" */
3403 g_ptr->info |= (CAVE_XTRA);
3405 cave_view_hack(g_ptr, y, x);
3410 /* Hack -- primary "easy" yields "viewed" */
3413 cave_view_hack(g_ptr, y, x);
3418 /* Hack -- "view" plus "view" yields "view" */
3421 /* g_ptr->info |= (CAVE_XTRA); */
3423 cave_view_hack(g_ptr, y, x);
3429 /* Mega-Hack -- the "los()" function works poorly on walls */
3432 cave_view_hack(g_ptr, y, x);
3438 /* Hack -- check line of sight */
3439 if (los(p_ptr->y, p_ptr->x, y, x))
3441 cave_view_hack(g_ptr, y, x);
3447 /* Assume no line of sight. */
3454 * Calculate the viewable space
3456 * 1: Process the player
3457 * 1a: The player is always (easily) viewable
3458 * 2: Process the diagonals
3459 * 2a: The diagonals are (easily) viewable up to the first wall
3460 * 2b: But never go more than 2/3 of the "full" distance
3461 * 3: Process the main axes
3462 * 3a: The main axes are (easily) viewable up to the first wall
3463 * 3b: But never go more than the "full" distance
3464 * 4: Process sequential "strips" in each of the eight octants
3465 * 4a: Each strip runs along the previous strip
3466 * 4b: The main axes are "previous" to the first strip
3467 * 4c: Process both "sides" of each "direction" of each strip
3468 * 4c1: Each side aborts as soon as possible
3469 * 4c2: Each side tells the next strip how far it has to check
3471 * Note that the octant processing involves some pretty interesting
3472 * observations involving when a grid might possibly be viewable from
3473 * a given grid, and on the order in which the strips are processed.
3475 * Note the use of the mathematical facts shown below, which derive
3476 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3477 * hypotenuse of a right triangle is primarily determined by the length
3478 * of the longest side, when one side is small, and is strictly less
3479 * than one-and-a-half times as long as the longest side when both of
3480 * the sides are large.
3482 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3483 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3485 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3487 * These observations are important because the calculation of the actual
3488 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3489 * while for small values (up to about 20 or so), the approximations above
3490 * are correct to within an error of at most one grid or so.
3492 * Observe the use of "full" and "over" in the code below, and the use of
3493 * the specialized calculation involving "limit", all of which derive from
3494 * the observations given above. Basically, we note that the "circle" of
3495 * view is completely contained in an "octagon" whose bounds are easy to
3496 * determine, and that only a few steps are needed to derive the actual
3497 * bounds of the circle given the bounds of the octagon.
3499 * Note that by skipping all the grids in the corners of the octagon, we
3500 * place an upper limit on the number of grids in the field of view, given
3501 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3502 * view, only about 1475 of these are in the "octagon" of view, and even
3503 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3504 * entries to completely contain the actual field of view.
3506 * Note also the care taken to prevent "running off the map". The use of
3507 * explicit checks on the "validity" of the "diagonal", and the fact that
3508 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3509 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
3510 * of multiple checks on the validity of grids.
3512 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3513 * "ws","wn" variables. They work like this: While travelling down the
3514 * south-bound strip just to the east of the main south axis, as soon as
3515 * we get to a grid which does not "transmit" viewing, if all of the strips
3516 * preceding us (in this case, just the main axis) had terminated at or before
3517 * the same point, then we can stop, and reset the "max distance" to ourself.
3518 * So, each strip (named by major axis plus offset, thus "se" in this case)
3519 * maintains a "blockage" variable, initialized during the main axis step,
3520 * and checks it whenever a blockage is observed. After processing each
3521 * strip as far as the previous strip told us to process, the next strip is
3522 * told not to go farther than the current strip's farthest viewable grid,
3523 * unless open space is still available. This uses the "k" variable.
3525 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
3526 * macro is a replacement for "cave_los_bold()" which takes a pointer to
3527 * a grid instead of its location. The "cave_view_hack()" macro is a
3528 * chunk of code which adds the given location to the "view" array if it
3529 * is not already there, using both the actual location and a pointer to
3530 * the grid. See above.
3532 * By the way, the purpose of this code is to reduce the dependancy on the
3533 * "los()" function which is slow, and, in some cases, not very accurate.
3535 * It is very possible that I am the only person who fully understands this
3536 * function, and for that I am truly sorry, but efficiency was very important
3537 * and the "simple" version of this function was just not fast enough. I am
3538 * more than willing to replace this function with a simpler one, if it is
3539 * equally efficient, and especially willing if the new function happens to
3540 * derive "reverse-line-of-sight" at the same time, since currently monsters
3541 * just use an optimized hack of "you see me, so I see you", and then use the
3542 * actual "projectable()" function to check spell attacks.
3544 void update_view(void)
3549 int se, sw, ne, nw, es, en, ws, wn;
3553 POSITION y_max = cur_hgt - 1;
3554 POSITION x_max = cur_wid - 1;
3558 /*** Initialize ***/
3561 if (view_reduce_view && !dun_level)
3563 /* Full radius (10) */
3564 full = MAX_SIGHT / 2;
3566 /* Octagon factor (15) */
3567 over = MAX_SIGHT * 3 / 4;
3573 /* Full radius (20) */
3576 /* Octagon factor (30) */
3577 over = MAX_SIGHT * 3 / 2;
3581 /*** Step 0 -- Begin ***/
3583 /* Save the old "view" grids for later */
3584 for (n = 0; n < view_n; n++)
3588 g_ptr = &grid_array[y][x];
3590 /* Mark the grid as not in "view" */
3591 g_ptr->info &= ~(CAVE_VIEW);
3593 /* Mark the grid as "seen" */
3594 g_ptr->info |= (CAVE_TEMP);
3596 /* Add it to the "seen" set */
3602 /* Start over with the "view" array */
3605 /*** Step 1 -- adjacent grids ***/
3607 /* Now start on the player */
3610 g_ptr = &grid_array[y][x];
3612 /* Assume the player grid is easily viewable */
3613 g_ptr->info |= (CAVE_XTRA);
3615 /* Assume the player grid is viewable */
3616 cave_view_hack(g_ptr, y, x);
3619 /*** Step 2 -- Major Diagonals ***/
3624 /* Scan south-east */
3625 for (d = 1; d <= z; d++)
3627 g_ptr = &grid_array[y+d][x+d];
3628 g_ptr->info |= (CAVE_XTRA);
3629 cave_view_hack(g_ptr, y+d, x+d);
3630 if (!cave_los_grid(g_ptr)) break;
3633 /* Scan south-west */
3634 for (d = 1; d <= z; d++)
3636 g_ptr = &grid_array[y+d][x-d];
3637 g_ptr->info |= (CAVE_XTRA);
3638 cave_view_hack(g_ptr, y+d, x-d);
3639 if (!cave_los_grid(g_ptr)) break;
3642 /* Scan north-east */
3643 for (d = 1; d <= z; d++)
3645 g_ptr = &grid_array[y-d][x+d];
3646 g_ptr->info |= (CAVE_XTRA);
3647 cave_view_hack(g_ptr, y-d, x+d);
3648 if (!cave_los_grid(g_ptr)) break;
3651 /* Scan north-west */
3652 for (d = 1; d <= z; d++)
3654 g_ptr = &grid_array[y-d][x-d];
3655 g_ptr->info |= (CAVE_XTRA);
3656 cave_view_hack(g_ptr, y-d, x-d);
3657 if (!cave_los_grid(g_ptr)) break;
3660 /*** Step 3 -- major axes ***/
3663 for (d = 1; d <= full; d++)
3665 g_ptr = &grid_array[y+d][x];
3666 g_ptr->info |= (CAVE_XTRA);
3667 cave_view_hack(g_ptr, y+d, x);
3668 if (!cave_los_grid(g_ptr)) break;
3671 /* Initialize the "south strips" */
3675 for (d = 1; d <= full; d++)
3677 g_ptr = &grid_array[y-d][x];
3678 g_ptr->info |= (CAVE_XTRA);
3679 cave_view_hack(g_ptr, y-d, x);
3680 if (!cave_los_grid(g_ptr)) break;
3683 /* Initialize the "north strips" */
3687 for (d = 1; d <= full; d++)
3689 g_ptr = &grid_array[y][x+d];
3690 g_ptr->info |= (CAVE_XTRA);
3691 cave_view_hack(g_ptr, y, x+d);
3692 if (!cave_los_grid(g_ptr)) break;
3695 /* Initialize the "east strips" */
3699 for (d = 1; d <= full; d++)
3701 g_ptr = &grid_array[y][x-d];
3702 g_ptr->info |= (CAVE_XTRA);
3703 cave_view_hack(g_ptr, y, x-d);
3704 if (!cave_los_grid(g_ptr)) break;
3707 /* Initialize the "west strips" */
3711 /*** Step 4 -- Divide each "octant" into "strips" ***/
3713 /* Now check each "diagonal" (in parallel) */
3714 for (n = 1; n <= over / 2; n++)
3716 POSITION ypn, ymn, xpn, xmn;
3718 /* Acquire the "bounds" of the maximal circle */
3720 if (z > full - n) z = full - n;
3721 while ((z + n + (n>>1)) > full) z--;
3724 /* Access the four diagonal grids */
3734 /* Maximum distance */
3735 m = MIN(z, y_max - ypn);
3738 if ((xpn <= x_max) && (n < se))
3741 for (k = n, d = 1; d <= m; d++)
3743 /* Check grid "d" in strip "n", notice "blockage" */
3744 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3746 if (n + d >= se) break;
3749 /* Track most distant "non-blockage" */
3756 /* Limit the next strip */
3761 if ((xmn >= 0) && (n < sw))
3764 for (k = n, d = 1; d <= m; d++)
3766 /* Check grid "d" in strip "n", notice "blockage" */
3767 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3769 if (n + d >= sw) break;
3772 /* Track most distant "non-blockage" */
3779 /* Limit the next strip */
3788 /* Maximum distance */
3792 if ((xpn <= x_max) && (n < ne))
3795 for (k = n, d = 1; d <= m; d++)
3797 /* Check grid "d" in strip "n", notice "blockage" */
3798 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3800 if (n + d >= ne) break;
3803 /* Track most distant "non-blockage" */
3810 /* Limit the next strip */
3815 if ((xmn >= 0) && (n < nw))
3818 for (k = n, d = 1; d <= m; d++)
3820 /* Check grid "d" in strip "n", notice "blockage" */
3821 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
3823 if (n + d >= nw) break;
3826 /* Track most distant "non-blockage" */
3833 /* Limit the next strip */
3842 /* Maximum distance */
3843 m = MIN(z, x_max - xpn);
3846 if ((ypn <= x_max) && (n < es))
3849 for (k = n, d = 1; d <= m; d++)
3851 /* Check grid "d" in strip "n", notice "blockage" */
3852 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
3854 if (n + d >= es) break;
3857 /* Track most distant "non-blockage" */
3864 /* Limit the next strip */
3869 if ((ymn >= 0) && (n < en))
3872 for (k = n, d = 1; d <= m; d++)
3874 /* Check grid "d" in strip "n", notice "blockage" */
3875 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
3877 if (n + d >= en) break;
3880 /* Track most distant "non-blockage" */
3887 /* Limit the next strip */
3896 /* Maximum distance */
3900 if ((ypn <= y_max) && (n < ws))
3903 for (k = n, d = 1; d <= m; d++)
3905 /* Check grid "d" in strip "n", notice "blockage" */
3906 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
3908 if (n + d >= ws) break;
3911 /* Track most distant "non-blockage" */
3918 /* Limit the next strip */
3923 if ((ymn >= 0) && (n < wn))
3926 for (k = n, d = 1; d <= m; d++)
3928 /* Check grid "d" in strip "n", notice "blockage" */
3929 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
3931 if (n + d >= wn) break;
3934 /* Track most distant "non-blockage" */
3941 /* Limit the next strip */
3948 /*** Step 5 -- Complete the algorithm ***/
3950 /* Update all the new grids */
3951 for (n = 0; n < view_n; n++)
3955 g_ptr = &grid_array[y][x];
3957 /* Clear the "CAVE_XTRA" flag */
3958 g_ptr->info &= ~(CAVE_XTRA);
3960 /* Update only newly viewed grids */
3961 if (g_ptr->info & (CAVE_TEMP)) continue;
3963 /* Add it to later visual update */
3964 cave_note_and_redraw_later(g_ptr, y, x);
3967 /* Wipe the old grids, update as needed */
3968 for (n = 0; n < temp_n; n++)
3972 g_ptr = &grid_array[y][x];
3974 /* No longer in the array */
3975 g_ptr->info &= ~(CAVE_TEMP);
3977 /* Update only non-viewable grids */
3978 if (g_ptr->info & (CAVE_VIEW)) continue;
3980 /* Add it to later visual update */
3981 cave_redraw_later(g_ptr, y, x);
3987 /* Mega-Hack -- Visual update later */
3988 p_ptr->update |= (PU_DELAY_VIS);
3993 * Mega-Hack -- Delayed visual update
3994 * Only used if update_view(), update_lite() or update_mon_lite() was called
3996 void delayed_visual_update(void)
4002 /* Update needed grids */
4003 for (i = 0; i < redraw_n; i++)
4007 g_ptr = &grid_array[y][x];
4009 /* Update only needed grids (prevent multiple updating) */
4010 if (!(g_ptr->info & CAVE_REDRAW)) continue;
4012 /* If required, note */
4013 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
4017 /* Hack -- Visual update of monster on this grid */
4018 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
4020 /* No longer in the array */
4021 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4030 * Hack -- forget the "flow" information
4032 void forget_flow(void)
4036 /* Check the entire dungeon */
4037 for (y = 0; y < cur_hgt; y++)
4039 for (x = 0; x < cur_wid; x++)
4041 /* Forget the old data */
4042 grid_array[y][x].dist = 0;
4043 grid_array[y][x].cost = 0;
4044 grid_array[y][x].when = 0;
4051 * Hack - speed up the update_flow algorithm by only doing
4052 * it everytime the player moves out of LOS of the last
4055 static POSITION flow_x = 0;
4056 static POSITION flow_y = 0;
4061 * Hack -- fill in the "cost" field of every grid that the player
4062 * can "reach" with the number of steps needed to reach that grid.
4063 * This also yields the "distance" of the player from every grid.
4065 * In addition, mark the "when" of the grids that can reach
4066 * the player with the incremented value of "flow_n".
4068 * Hack -- use the "seen" array as a "circular queue".
4070 * We do not need a priority queue because the cost from grid
4071 * to grid is always "one" and we process them in order.
4073 void update_flow(void)
4080 /* Paranoia -- make sure the array is empty */
4083 /* The last way-point is on the map */
4084 if (running && in_bounds(flow_y, flow_x))
4086 /* The way point is in sight - do not update. (Speedup) */
4087 if (grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
4090 /* Erase all of the current flow information */
4091 for (y = 0; y < cur_hgt; y++)
4093 for (x = 0; x < cur_wid; x++)
4095 grid_array[y][x].cost = 0;
4096 grid_array[y][x].dist = 0;
4100 /* Save player position */
4104 /* Add the player's grid to the queue */
4105 temp_y[0] = p_ptr->y;
4106 temp_x[0] = p_ptr->x;
4108 /* Now process the queue */
4109 while (flow_head != flow_tail)
4113 /* Extract the next entry */
4114 ty = temp_y[flow_tail];
4115 tx = temp_x[flow_tail];
4117 /* Forget that entry */
4118 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4120 /* Add the "children" */
4121 for (d = 0; d < 8; d++)
4123 int old_head = flow_head;
4124 byte_hack m = grid_array[ty][tx].cost + 1;
4125 byte_hack n = grid_array[ty][tx].dist + 1;
4128 /* Child location */
4129 y = ty + ddy_ddd[d];
4130 x = tx + ddx_ddd[d];
4132 /* Ignore player's grid */
4133 if (player_bold(y, x)) continue;
4135 g_ptr = &grid_array[y][x];
4137 if (is_closed_door(g_ptr->feat)) m += 3;
4139 /* Ignore "pre-stamped" entries */
4140 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
4142 /* Ignore "walls" and "rubble" */
4143 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
4145 /* Save the flow cost */
4146 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
4147 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
4149 /* Hack -- limit flow depth */
4150 if (n == MONSTER_FLOW_DEPTH) continue;
4152 /* Enqueue that entry */
4153 temp_y[flow_head] = y;
4154 temp_x[flow_head] = x;
4156 /* Advance the queue */
4157 if (++flow_head == TEMP_MAX) flow_head = 0;
4159 /* Hack -- notice overflow by forgetting new entry */
4160 if (flow_head == flow_tail) flow_head = old_head;
4166 static int scent_when = 0;
4169 * Characters leave scent trails for perceptive monsters to track.
4171 * Smell is rather more limited than sound. Many creatures cannot use
4172 * it at all, it doesn't extend very far outwards from the character's
4173 * current position, and monsters can use it to home in the character,
4174 * but not to run away from him.
4176 * Smell is valued according to age. When a character takes his turn,
4177 * scent is aged by one, and new scent of the current age is laid down.
4178 * Speedy characters leave more scent, true, but it also ages faster,
4179 * which makes it harder to hunt them down.
4181 * Whenever the age count loops, most of the scent trail is erased and
4182 * the age of the remainder is recalculated.
4184 void update_smell(void)
4189 /* Create a table that controls the spread of scent */
4190 const int scent_adjust[5][5] =
4199 /* Loop the age and adjust scent values when necessary */
4200 if (++scent_when == 254)
4202 /* Scan the entire dungeon */
4203 for (y = 0; y < cur_hgt; y++)
4205 for (x = 0; x < cur_wid; x++)
4207 int w = grid_array[y][x].when;
4208 grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
4217 /* Lay down new scent */
4218 for (i = 0; i < 5; i++)
4220 for (j = 0; j < 5; j++)
4224 /* Translate table to map grids */
4225 y = i + p_ptr->y - 2;
4226 x = j + p_ptr->x - 2;
4229 if (!in_bounds(y, x)) continue;
4231 g_ptr = &grid_array[y][x];
4233 /* Walls, water, and lava cannot hold scent. */
4234 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
4236 /* Grid must not be blocked by walls from the character */
4237 if (!player_has_los_bold(y, x)) continue;
4239 /* Note grids that are too far away */
4240 if (scent_adjust[i][j] == -1) continue;
4242 /* Mark the grid with new scent */
4243 g_ptr->when = scent_when + scent_adjust[i][j];
4250 * Hack -- map the current panel (plus some) ala "magic mapping"
4252 void map_area(POSITION range)
4258 feature_type *f_ptr;
4260 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) range /= 3;
4262 /* Scan that area */
4263 for (y = 1; y < cur_hgt - 1; y++)
4265 for (x = 1; x < cur_wid - 1; x++)
4267 if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
4269 g_ptr = &grid_array[y][x];
4271 /* Memorize terrain of the grid */
4272 g_ptr->info |= (CAVE_KNOWN);
4274 /* Feature code (applying "mimic" field) */
4275 feat = get_feat_mimic(g_ptr);
4276 f_ptr = &f_info[feat];
4278 /* All non-walls are "checked" */
4279 if (!have_flag(f_ptr->flags, FF_WALL))
4281 /* Memorize normal features */
4282 if (have_flag(f_ptr->flags, FF_REMEMBER))
4284 /* Memorize the object */
4285 g_ptr->info |= (CAVE_MARK);
4288 /* Memorize known walls */
4289 for (i = 0; i < 8; i++)
4291 g_ptr = &grid_array[y + ddy_ddd[i]][x + ddx_ddd[i]];
4293 /* Feature code (applying "mimic" field) */
4294 feat = get_feat_mimic(g_ptr);
4295 f_ptr = &f_info[feat];
4297 /* Memorize walls (etc) */
4298 if (have_flag(f_ptr->flags, FF_REMEMBER))
4300 /* Memorize the walls */
4301 g_ptr->info |= (CAVE_MARK);
4308 p_ptr->redraw |= (PR_MAP);
4310 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4315 * Change the "feat" flag for a grid, and notice/redraw the grid
4317 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
4319 grid_type *g_ptr = &grid_array[y][x];
4320 feature_type *f_ptr = &f_info[feat];
4321 bool old_los, old_mirror;
4323 if (!character_dungeon)
4325 /* Clear mimic type */
4328 /* Change the feature */
4331 /* Hack -- glow the GLOW terrain */
4332 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
4337 for (i = 0; i < 9; i++)
4339 yy = y + ddy_ddd[i];
4340 xx = x + ddx_ddd[i];
4341 if (!in_bounds2(yy, xx)) continue;
4342 grid_array[yy][xx].info |= CAVE_GLOW;
4349 old_los = cave_have_flag_bold(y, x, FF_LOS);
4350 old_mirror = is_mirror_grid(g_ptr);
4352 /* Clear mimic type */
4355 /* Change the feature */
4358 /* Remove flag for mirror/glyph */
4359 g_ptr->info &= ~(CAVE_OBJECT);
4361 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
4363 g_ptr->info &= ~(CAVE_GLOW);
4364 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
4366 update_local_illumination(y, x);
4369 /* Check for change to boring grid */
4370 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
4371 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
4377 /* Check if los has changed */
4378 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
4381 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
4383 update_local_illumination(y, x);
4385 #endif /* COMPLEX_WALL_ILLUMINATION */
4387 /* Update the visuals */
4388 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
4391 /* Hack -- glow the GLOW terrain */
4392 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
4398 for (i = 0; i < 9; i++)
4400 yy = y + ddy_ddd[i];
4401 xx = x + ddx_ddd[i];
4402 if (!in_bounds2(yy, xx)) continue;
4403 cc_ptr = &grid_array[yy][xx];
4404 cc_ptr->info |= CAVE_GLOW;
4406 if (player_has_los_grid(cc_ptr))
4408 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
4415 update_local_illumination(yy, xx);
4418 if (p_ptr->special_defense & NINJA_S_STEALTH)
4420 if (grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
4426 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
4428 feature_type *f_ptr = &f_info[newfeat];
4430 if (have_flag(f_ptr->flags, FF_CONVERT))
4432 switch (f_ptr->subtype)
4434 case CONVERT_TYPE_FLOOR:
4435 return feat_ground_type[randint0(100)];
4436 case CONVERT_TYPE_WALL:
4437 return feat_wall_type[randint0(100)];
4438 case CONVERT_TYPE_INNER:
4439 return feat_wall_inner;
4440 case CONVERT_TYPE_OUTER:
4441 return feat_wall_outer;
4442 case CONVERT_TYPE_SOLID:
4443 return feat_wall_solid;
4444 case CONVERT_TYPE_STREAM1:
4445 return d_info[p_ptr->dungeon_idx].stream1;
4446 case CONVERT_TYPE_STREAM2:
4447 return d_info[p_ptr->dungeon_idx].stream2;
4452 else return newfeat;
4457 * Take a feature, determine what that feature becomes
4458 * through applying the given action.
4460 FEAT_IDX feat_state(FEAT_IDX feat, int action)
4462 feature_type *f_ptr = &f_info[feat];
4465 /* Get the new feature */
4466 for (i = 0; i < MAX_FEAT_STATES; i++)
4468 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
4471 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
4473 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
4477 * Takes a location and action and changes the feature at that
4478 * location through applying the given action.
4480 void cave_alter_feat(POSITION y, POSITION x, int action)
4482 /* Set old feature */
4483 FEAT_IDX oldfeat = grid_array[y][x].feat;
4485 /* Get the new feat */
4486 FEAT_IDX newfeat = feat_state(oldfeat, action);
4489 if (newfeat == oldfeat) return;
4491 /* Set the new feature */
4492 cave_set_feat(y, x, newfeat);
4494 if (!(feature_action_flags[action] & FAF_NO_DROP))
4496 feature_type *old_f_ptr = &f_info[oldfeat];
4497 feature_type *f_ptr = &f_info[newfeat];
4501 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
4503 /* Place some gold */
4509 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - dun_level / 2)))
4512 place_object(y, x, 0L);
4516 if (found && character_dungeon && player_can_see_bold(y, x))
4518 msg_print(_("何かを発見した!", "You have found something!"));
4522 if (feature_action_flags[action] & FAF_CRASH_GLASS)
4524 feature_type *old_f_ptr = &f_info[oldfeat];
4526 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
4528 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(dun_level, 100) / 4, GF_SHARDS,
4529 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
4535 /* Remove a mirror */
4536 void remove_mirror(POSITION y, POSITION x)
4538 grid_type *g_ptr = &grid_array[y][x];
4540 /* Remove the mirror */
4541 g_ptr->info &= ~(CAVE_OBJECT);
4544 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
4546 g_ptr->info &= ~(CAVE_GLOW);
4547 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
4548 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
4550 update_local_illumination(y, x);
4560 * Return TRUE if there is a mirror on the grid.
4562 bool is_mirror_grid(grid_type *g_ptr)
4564 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
4572 * Return TRUE if there is a mirror on the grid.
4574 bool is_glyph_grid(grid_type *g_ptr)
4576 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
4584 * Return TRUE if there is a mirror on the grid.
4586 bool is_explosive_rune_grid(grid_type *g_ptr)
4588 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
4596 * Calculate "incremental motion". Used by project() and shoot().
4597 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4599 void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4601 POSITION dy, dx, dist, shift;
4603 /* Extract the distance travelled */
4604 dy = (*y < y1) ? y1 - *y : *y - y1;
4605 dx = (*x < x1) ? x1 - *x : *x - x1;
4607 /* Number of steps */
4608 dist = (dy > dx) ? dy : dx;
4610 /* We are calculating the next location */
4614 /* Calculate the total distance along each axis */
4615 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4616 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4618 /* Paranoia -- Hack -- no motion */
4619 if (!dy && !dx) return;
4622 /* Move mostly vertically */
4625 /* Extract a shift factor */
4626 shift = (dist * dx + (dy - 1) / 2) / dy;
4628 /* Sometimes move along the minor axis */
4629 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4631 /* Always move along major axis */
4632 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4635 /* Move mostly horizontally */
4638 /* Extract a shift factor */
4639 shift = (dist * dy + (dx - 1) / 2) / dx;
4641 /* Sometimes move along the minor axis */
4642 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4644 /* Always move along major axis */
4645 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4652 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4653 * at the final destination, assuming no monster gets in the way.
4655 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4657 bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4664 /* Check the projection path */
4665 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4667 /* Identical grid */
4668 if (!grid_n) return TRUE;
4671 y = GRID_Y(grid_g[grid_n - 1]);
4672 x = GRID_X(grid_g[grid_n - 1]);
4674 /* May not end in an unrequested grid */
4675 if ((y != y2) || (x != x2)) return (FALSE);
4683 * Standard "find me a location" function
4685 * Obtains a legal location within the given distance of the initial
4686 * location, and with "los()" from the source to destination location.
4688 * This function is often called from inside a loop which searches for
4689 * locations while increasing the "d" distance.
4691 * Currently the "m" parameter is unused.
4693 void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
4697 /* Pick a location */
4700 /* Pick a new location */
4701 ny = rand_spread(y, d);
4702 nx = rand_spread(x, d);
4704 /* Ignore annoying locations */
4705 if (!in_bounds(ny, nx)) continue;
4707 /* Ignore "excessively distant" locations */
4708 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4710 if (mode & PROJECT_LOS)
4712 if(los(y, x, ny, nx)) break;
4716 if(projectable(y, x, ny, nx)) break;
4721 /* Save the location */
4730 * Track a new monster
4732 void health_track(MONSTER_IDX m_idx)
4734 /* Mount monster is already tracked */
4735 if (m_idx && m_idx == p_ptr->riding) return;
4737 /* Track a new guy */
4738 p_ptr->health_who = m_idx;
4740 /* Redraw (later) */
4741 p_ptr->redraw |= (PR_HEALTH);
4747 * Hack -- track the given monster race
4749 void monster_race_track(MONRACE_IDX r_idx)
4751 /* Save this monster ID */
4752 p_ptr->monster_race_idx = r_idx;
4754 p_ptr->window |= (PW_MONSTER);
4760 * Hack -- track the given object kind
4762 void object_kind_track(KIND_OBJECT_IDX k_idx)
4764 /* Save this monster ID */
4765 p_ptr->object_kind_idx = k_idx;
4767 p_ptr->window |= (PW_OBJECT);
4773 * Something has happened to disturb the player.
4775 * The first arg indicates a major disturbance, which affects search.
4777 * The second arg is currently unused, but could induce output flush.
4779 * All disturbance cancels repeated commands, resting, and running.
4781 void disturb(bool stop_search, bool stop_travel)
4785 stop_travel = stop_travel;
4788 /* Cancel auto-commands */
4789 /* command_new = 0; */
4791 /* Cancel repeated commands */
4797 /* Redraw the state (later) */
4798 p_ptr->redraw |= (PR_STATE);
4801 /* Cancel Resting */
4802 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
4805 set_action(ACTION_NONE);
4808 /* Cancel running */
4814 /* Check for new panel if appropriate */
4815 if (center_player && !center_running) verify_panel();
4817 /* Calculate torch radius */
4818 p_ptr->update |= (PU_TORCH);
4820 /* Update monster flow */
4821 p_ptr->update |= (PU_FLOW);
4830 /* Check for new panel if appropriate */
4831 if (center_player && !center_running) verify_panel();
4833 /* Calculate torch radius */
4834 p_ptr->update |= (PU_TORCH);
4838 /* Flush the input if requested */
4839 if (flush_disturb) flush();
4844 * Glow deep lava and building entrances in the floor
4846 void glow_deep_lava_and_bldg(void)
4848 POSITION y, x, yy, xx;
4852 /* Not in the darkness dungeon */
4853 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) return;
4855 for (y = 0; y < cur_hgt; y++)
4857 for (x = 0; x < cur_wid; x++)
4859 g_ptr = &grid_array[y][x];
4861 /* Feature code (applying "mimic" field) */
4863 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_GLOW))
4865 for (i = 0; i < 9; i++)
4867 yy = y + ddy_ddd[i];
4868 xx = x + ddx_ddd[i];
4869 if (!in_bounds2(yy, xx)) continue;
4870 grid_array[yy][xx].info |= CAVE_GLOW;
4876 /* Update the view and lite */
4877 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4879 p_ptr->redraw |= (PR_MAP);
4883 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
4884 * @param m_idx モンスターID
4888 * @return テレポート先として妥当ならばtrue
4890 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
4892 monster_type *m_ptr = &m_list[m_idx];
4893 grid_type *g_ptr = &grid_array[y][x];
4894 feature_type *f_ptr = &f_info[g_ptr->feat];
4896 /* Require "teleportable" space */
4897 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
4899 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
4900 if (player_bold(y, x)) return FALSE;
4902 /* Hack -- no teleport onto glyph of warding */
4903 if (is_glyph_grid(g_ptr)) return FALSE;
4904 if (is_explosive_rune_grid(g_ptr)) return FALSE;
4906 if (!(mode & TELEPORT_PASSIVE))
4908 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
4915 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
4919 * @return テレポート先として妥当ならばtrue
4921 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
4923 grid_type *g_ptr = &grid_array[y][x];
4924 feature_type *f_ptr = &f_info[g_ptr->feat];
4926 /* Require "teleportable" space */
4927 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
4929 /* No magical teleporting into vaults and such */
4930 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
4932 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
4934 /* don't teleport on a trap. */
4935 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
4937 if (!(mode & TELEPORT_PASSIVE))
4939 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
4941 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
4943 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
4946 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
4948 /* Always forbid deep lava */
4949 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
4951 /* Forbid shallow lava when the player don't have levitation */
4952 if (!p_ptr->levitation) return FALSE;
4961 * @brief 地形は開くものであって、かつ開かれているかを返す /
4962 * Attempt to open the given chest at the given location
4964 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
4966 bool is_open(FEAT_IDX feat)
4968 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));