4 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: low level dungeon routines -BEN- */
18 * Support for Adam Bolt's tileset, lighting and transparency effects
19 * by Robert Ruehlmann (rr9@angband.org)
22 static byte display_autopick;
23 static int match_autopick;
24 static object_type *autopick_obj;
25 static int feat_priority;
28 * Distance between two points via Newton-Raphson technique
30 int distance (int y1, int x1, int y2, int x2)
32 int dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
33 int dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
35 /* Squared distance */
36 int target = (dy * dy) + (dx * dx);
38 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
39 int d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
44 if (!dy || !dx) return d;
48 /* Approximate error */
49 err = (target - d * d) / (2 * d);
51 /* No error - we are done */
63 * Return TRUE if the given feature is a trap
65 bool is_trap(int feat)
67 return have_flag(f_info[feat].flags, FF_TRAP);
72 * Return TRUE if the given grid is a known trap
74 bool is_known_trap(cave_type *c_ptr)
76 if (!c_ptr->mimic && !have_flag(f_flags_grid(c_ptr), FF_SECRET) &&
77 is_trap(c_ptr->feat)) return TRUE;
84 * Return TRUE if the given grid is a closed door
86 bool is_closed_door(int feat)
88 feature_type *f_ptr = &f_info[feat];
90 return (have_flag(f_ptr->flags, FF_OPEN) || have_flag(f_ptr->flags, FF_BASH)) &&
91 !have_flag(f_ptr->flags, FF_MOVE);
96 * Return TRUE if the given grid is a hidden closed door
98 bool is_hidden_door(cave_type *c_ptr)
100 if ((c_ptr->mimic || have_flag(f_flags_grid(c_ptr), FF_SECRET)) &&
101 is_closed_door(c_ptr->feat))
109 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,
110 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.
112 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
114 * The LOS begins at the center of the tile (x1,y1) and ends at the center of
115 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line
116 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
118 * We assume that the "mathematical corner" of a non-floor tile does not
119 * block line of sight.
121 * Because this function uses (short) ints for all calculations, overflow may
122 * occur if dx and dy exceed 90.
124 * Once all the degenerate cases are eliminated, the values "qx", "qy", and
125 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
126 * we can use integer arithmetic.
128 * We travel from start to finish along the longer axis, starting at the border
129 * between the first and second tiles, where the y offset = .5 * slope, taking
130 * into account the scale factor. See below.
132 * Also note that this function and the "move towards target" code do NOT
133 * share the same properties. Thus, you can see someone, target them, and
134 * then fire a bolt at them, but the bolt may hit a wall, not them. However,
135 * by clever choice of target locations, you can sometimes throw a "curve".
137 * Note that "line of sight" is not "reflexive" in all cases.
139 * Use the "projectable()" routine to test "spell/missile line of sight".
141 * Use the "update_view()" function to determine player line-of-sight.
143 bool los(int y1, int x1, int y2, int x2)
163 /* Slope, or 1/Slope, of LOS */
167 /* Extract the offset */
171 /* Extract the absolute offset */
176 /* Handle adjacent (or identical) grids */
177 if ((ax < 2) && (ay < 2)) return TRUE;
180 /* Paranoia -- require "safe" origin */
181 /* if (!in_bounds(y1, x1)) return FALSE; */
182 /* if (!in_bounds(y2, x2)) return FALSE; */
185 /* Directly South/North */
188 /* South -- check for walls */
191 for (ty = y1 + 1; ty < y2; ty++)
193 if (!cave_los_bold(ty, x1)) return FALSE;
197 /* North -- check for walls */
200 for (ty = y1 - 1; ty > y2; ty--)
202 if (!cave_los_bold(ty, x1)) return FALSE;
210 /* Directly East/West */
213 /* East -- check for walls */
216 for (tx = x1 + 1; tx < x2; tx++)
218 if (!cave_los_bold(y1, tx)) return FALSE;
222 /* West -- check for walls */
225 for (tx = x1 - 1; tx > x2; tx--)
227 if (!cave_los_bold(y1, tx)) return FALSE;
236 /* Extract some signs */
237 sx = (dx < 0) ? -1 : 1;
238 sy = (dy < 0) ? -1 : 1;
241 /* Vertical "knights" */
246 if (cave_los_bold(y1 + sy, x1)) return TRUE;
250 /* Horizontal "knights" */
255 if (cave_los_bold(y1, x1 + sx)) return TRUE;
260 /* Calculate scale factor div 2 */
263 /* Calculate scale factor */
267 /* Travel horizontally */
270 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
276 /* Consider the special case where slope == 1. */
287 /* Note (below) the case (qy == f2), where */
288 /* the LOS exactly meets the corner of a tile. */
291 if (!cave_los_bold(ty, tx)) return FALSE;
302 if (!cave_los_bold(ty, tx)) return FALSE;
315 /* Travel vertically */
318 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
334 /* Note (below) the case (qx == f2), where */
335 /* the LOS exactly meets the corner of a tile. */
338 if (!cave_los_bold(ty, tx)) return FALSE;
349 if (!cave_los_bold(ty, tx)) return FALSE;
372 * Check for "local" illumination
374 static bool check_local_illumination(int y, int x)
376 /* Hack -- move towards player */
377 int yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
378 int xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
380 /* Check for "local" illumination */
381 return (cave[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
386 * Update "local" illumination
388 void update_local_illumination(int y, int x)
392 if (!in_bounds(y, x)) return;
394 if ((y != py) && (x != px))
396 yy = (y < py) ? (y - 1) : (y + 1);
397 xx = (x < px) ? (x - 1) : (x + 1);
399 if (player_has_los_bold(yy, xx))
401 /* Update the monster */
402 if (cave[yy][xx].m_idx) update_mon(cave[yy][xx].m_idx, FALSE);
404 /* Notice and redraw */
409 else if (x != px) /* y == py */
411 xx = (x < px) ? (x - 1) : (x + 1);
413 for (i = -1; i <= 1; i++)
416 if (!player_has_los_bold(yy, xx)) continue;
418 /* Update the monster */
419 if (cave[yy][xx].m_idx) update_mon(cave[yy][xx].m_idx, FALSE);
421 /* Notice and redraw */
426 else if (y != py) /* x == px */
428 yy = (y < py) ? (y - 1) : (y + 1);
430 for (i = -1; i <= 1; i++)
433 if (!player_has_los_bold(yy, xx)) continue;
435 /* Update the monster */
436 if (cave[yy][xx].m_idx) update_mon(cave[yy][xx].m_idx, FALSE);
438 /* Notice and redraw */
443 else /* Player's grid */
445 for (i = 0; i < 9; i++)
449 if (!player_has_los_bold(yy, xx)) continue;
451 /* Update the monster */
452 if (cave[yy][xx].m_idx) update_mon(cave[yy][xx].m_idx, FALSE);
454 /* Notice and redraw */
463 * Can the player "see" the given grid in detail?
465 * He must have vision, illumination, and line of sight.
467 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
468 * So, given "CAVE_LITE", we know that the grid is "fully visible".
470 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
471 * that a wall is visible from any direction. That would be odd. Except
472 * under wizard light, which might make sense. Thus, for walls, we require
473 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
474 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
475 * in line of sight of the player.
477 * This extra check is expensive, but it provides a more "correct" semantics.
479 * Note that we should not run this check on walls which are "outer walls" of
480 * the dungeon, or we will induce a memory fault, but actually verifying all
481 * of the locations would be extremely expensive.
483 * Thus, to speed up the function, we assume that all "perma-walls" which are
484 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
485 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
486 * and the player has more important things on his mind when he is attacking a
487 * monster vault. It is annoying, but an extremely important optimization.
489 * Note that "glowing walls" are only considered to be "illuminated" if the
490 * grid which is next to the wall in the direction of the player is also a
491 * "glowing" grid. This prevents the player from being able to "see" the
492 * walls of illuminated rooms from a corridor outside the room.
494 bool player_can_see_bold(int y, int x)
499 /* Blind players see nothing */
500 if (p_ptr->blind) return FALSE;
502 /* Access the cave grid */
505 /* Note that "torch-lite" yields "illumination" */
506 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
508 /* Require line of sight to the grid */
509 if (!player_has_los_bold(y, x)) return FALSE;
511 /* Noctovision of Ninja */
512 if (p_ptr->see_nocto) return TRUE;
514 /* Require "perma-lite" of the grid */
515 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
517 /* Feature code (applying "mimic" field) */
518 feat = get_feat_mimic(c_ptr);
520 /* Floors are simple */
521 if (feat_supports_los(feat)) return TRUE;
523 /* Check for "local" illumination */
524 return check_local_illumination(y, x);
530 * Returns true if the player's grid is dark
534 return (!player_can_see_bold(py, px));
541 * Determine if a given location may be "destroyed"
543 * Used by destruction spells, and for placing stairs, etc.
545 bool cave_valid_bold(int y, int x)
547 cave_type *c_ptr = &cave[y][x];
549 s16b this_o_idx, next_o_idx = 0;
552 /* Forbid perma-grids */
553 if (cave_perma_grid(c_ptr)) return (FALSE);
556 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
561 o_ptr = &o_list[this_o_idx];
563 /* Acquire next object */
564 next_o_idx = o_ptr->next_o_idx;
566 /* Forbid artifact grids */
567 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
578 * Determine if a given location may be "destroyed"
580 * Used by destruction spells, and for placing stairs, etc.
582 bool cave_valid_grid(cave_type *c_ptr)
584 s16b this_o_idx, next_o_idx = 0;
587 /* Forbid perma-grids */
588 if (cave_perma_grid(c_ptr)) return (FALSE);
591 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
596 o_ptr = &o_list[this_o_idx];
598 /* Acquire next object */
599 next_o_idx = o_ptr->next_o_idx;
601 /* Forbid artifact grids */
602 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
613 * Hack -- Legal monster codes
615 static char image_monster_hack[] = \
616 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
619 * Hack -- Legal object codes
621 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
624 * Mega-Hack -- Hallucinatory monster
626 static void image_monster(byte *ap, char *cp)
628 /* Random symbol from set above */
631 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
640 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
641 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
650 * Mega-Hack -- Hallucinatory object
652 static void image_object(byte *ap, char *cp)
656 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
663 int n = sizeof(image_object_hack) - 1;
665 *cp = image_object_hack[randint0(n)];
675 * Hack -- Random hallucination
677 static void image_random(byte *ap, char *cp)
679 /* Normally, assume monsters */
680 if (randint0(100) < 75)
682 image_monster(ap, cp);
685 /* Otherwise, assume objects */
688 image_object(ap, cp);
693 * This array lists the effects of "brightness" on various "base" colours.
695 * This is used to do dynamic lighting effects in ascii :-)
696 * At the moment, only the various "floor" tiles are affected.
698 * The layout of the array is [x][0] = light and [x][1] = dark.
701 byte lighting_colours[16][2] =
704 {TERM_L_DARK, TERM_DARK},
707 {TERM_YELLOW, TERM_SLATE},
710 {TERM_WHITE, TERM_L_DARK},
713 {TERM_L_UMBER, TERM_UMBER},
716 {TERM_RED, TERM_RED},
719 {TERM_L_GREEN, TERM_GREEN},
722 {TERM_BLUE, TERM_BLUE},
725 {TERM_L_UMBER, TERM_RED},
728 {TERM_SLATE, TERM_L_DARK},
731 {TERM_WHITE, TERM_SLATE},
734 {TERM_L_RED, TERM_BLUE},
737 {TERM_YELLOW, TERM_ORANGE},
740 {TERM_L_RED, TERM_L_RED},
743 {TERM_L_GREEN, TERM_GREEN},
746 {TERM_L_BLUE, TERM_L_BLUE},
749 {TERM_L_UMBER, TERM_UMBER}
754 * Mega-Hack -- Partial code of map_info() for darkened grids
755 * Note: Each variable is declared in map_info().
756 * This macro modifies "feat", "f_ptr", "c" and "a".
758 #define darkened_grid_hack() \
760 if (feat_supports_los(feat)) \
762 /* Unsafe cave grid -- idea borrowed from Unangband */ \
763 if (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) \
764 feat = FEAT_UNDETECTED; \
768 /* Access darkness */ \
769 f_ptr = &f_info[feat]; \
771 /* Char and attr of darkness */ \
772 c = f_ptr->x_char[F_LIT_STANDARD]; \
773 a = f_ptr->x_attr[F_LIT_STANDARD]; \
775 else if (view_granite_lite && view_yellow_lite) \
777 /* Use a darkly darkened colour/tile */ \
778 a = f_ptr->x_attr[F_LIT_DARKDARK]; \
779 c = f_ptr->x_char[F_LIT_DARKDARK]; \
784 /* Is this grid "darkened" by monster? */
785 #define darkened_grid(C) \
786 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
787 !p_ptr->see_nocto && !p_ptr->blind)
791 * Extract the attr/char to display at the given (legal) map location
793 * Basically, we "paint" the chosen attr/char in several passes, starting
794 * with any known "terrain features" (defaulting to darkness), then adding
795 * any known "objects", and finally, adding any known "monsters". This
796 * is not the fastest method but since most of the calls to this function
797 * are made for grids with no monsters or objects, it is fast enough.
799 * Note that this function, if used on the grid containing the "player",
800 * will return the attr/char of the grid underneath the player, and not
801 * the actual player attr/char itself, allowing a lot of optimization
802 * in various "display" functions.
804 * Note that the "zero" entry in the feature/object/monster arrays are
805 * used to provide "special" attr/char codes, with "monster zero" being
806 * used for the player attr/char, "object zero" being used for the "stack"
807 * attr/char, and "feature zero" being used for the "nothing" attr/char,
808 * though this function makes use of only "feature zero".
810 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
811 * which means their color changes, and "ATTR_CLEAR", which means they take
812 * the color of whatever is under them, and "CHAR_CLEAR", which means that
813 * they take the symbol of whatever is under them. Technically, the flag
814 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
815 * examined, but this flag is currently ignored.
817 * Currently, we do nothing with multi-hued objects, because there are
818 * not any. If there were, they would have to set "shimmer_objects"
819 * when they were created, and then new "shimmer" code in "dungeon.c"
820 * would have to be created handle the "shimmer" effect, and the code
821 * in "cave.c" would have to be updated to create the shimmer effect.
823 * Note the effects of hallucination. Objects always appear as random
824 * "objects", monsters as random "monsters", and normal grids occasionally
825 * appear as random "monsters" or "objects", but note that these random
826 * "monsters" and "objects" are really just "colored ascii symbols".
828 * Note that "floors" and "invisible traps" (and "zero" features) are
829 * drawn as "floors" using a special check for optimization purposes,
830 * and these are the only features which get drawn using the special
831 * lighting effects activated by "view_special_lite".
833 * Note the use of the "mimic" field in the "terrain feature" processing,
834 * which allows any feature to "pretend" to be another feature. This is
835 * used to "hide" secret doors, and to make all "doors" appear the same,
836 * and all "walls" appear the same, and "hidden" treasure stay hidden.
837 * It is possible to use this field to make a feature "look" like a floor,
838 * but the "special lighting effects" for floors will not be used.
840 * Note the use of the new "terrain feature" information. Note that the
841 * assumption that all interesting "objects" and "terrain features" are
842 * memorized allows extremely optimized processing below. Note the use
843 * of separate flags on objects to mark them as memorized allows a grid
844 * to have memorized "terrain" without granting knowledge of any object
845 * which may appear in that grid.
847 * Note the efficient code used to determine if a "floor" grid is
848 * "memorized" or "viewable" by the player, where the test for the
849 * grid being "viewable" is based on the facts that (1) the grid
850 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
851 * line of sight, and (3) the player must not be blind, and uses the
852 * assumption that all torch-lit grids are in line of sight.
854 * Note that floors (and invisible traps) are the only grids which are
855 * not memorized when seen, so only these grids need to check to see if
856 * the grid is "viewable" to the player (if it is not memorized). Since
857 * most non-memorized grids are in fact walls, this induces *massive*
858 * efficiency, at the cost of *forcing* the memorization of non-floor
859 * grids when they are first seen. Note that "invisible traps" are
860 * always treated exactly like "floors", which prevents "cheating".
862 * Note the "special lighting effects" which can be activated for floor
863 * grids using the "view_special_lite" option (for "white" floor grids),
864 * causing certain grids to be displayed using special colors. If the
865 * player is "blind", we will use "dark gray", else if the grid is lit
866 * by the torch, and the "view_yellow_lite" option is set, we will use
867 * "yellow", else if the grid is "dark", we will use "dark gray", else
868 * if the grid is not "viewable", and the "view_bright_lite" option is
869 * set, and the we will use "slate" (gray). We will use "white" for all
870 * other cases, in particular, for illuminated viewable floor grids.
872 * Note the "special lighting effects" which can be activated for wall
873 * grids using the "view_granite_lite" option (for "white" wall grids),
874 * causing certain grids to be displayed using special colors. If the
875 * player is "blind", we will use "dark gray", else if the grid is lit
876 * by the torch, and the "view_yellow_lite" option is set, we will use
877 * "yellow", else if the "view_bright_lite" option is set, and the grid
878 * is not "viewable", or is "dark", or is glowing, but not when viewed
879 * from the player's current location, we will use "slate" (gray). We
880 * will use "white" for all other cases, in particular, for correctly
881 * illuminated viewable wall grids.
883 * Note that, when "view_granite_lite" is set, we use an inline version
884 * of the "player_can_see_bold()" function to check the "viewability" of
885 * grids when the "view_bright_lite" option is set, and we do NOT use
886 * any special colors for "dark" wall grids, since this would allow the
887 * player to notice the walls of illuminated rooms from a hallway that
888 * happened to run beside the room. The alternative, by the way, would
889 * be to prevent the generation of hallways next to rooms, but this
890 * would still allow problems when digging towards a room.
892 * Note that bizarre things must be done when the "attr" and/or "char"
893 * codes have the "high-bit" set, since these values are used to encode
894 * various "special" pictures in some versions, and certain situations,
895 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
896 * to be "scrambled" in various ways.
898 * Note that eventually we may use the "&" symbol for embedded treasure,
899 * and use the "*" symbol to indicate multiple objects, though this will
900 * have to wait for Angband 2.8.0 or later. Note that currently, this
901 * is not important, since only one object or terrain feature is allowed
902 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
904 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
905 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
906 * then a whole lot of code should be changed... XXX XXX
908 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
911 cave_type *c_ptr = &cave[y][x];
913 s16b this_o_idx, next_o_idx = 0;
915 /* Feature code (applying "mimic" field) */
916 s16b feat = get_feat_mimic(c_ptr);
919 feature_type *f_ptr = &f_info[feat];
924 /* Boring grids (floors, etc) */
925 if (!have_flag(f_ptr->flags, FF_REMEMBER))
927 /* Memorized (or visible) floor */
928 if ((c_ptr->info & CAVE_MARK) ||
929 (((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) ||
930 ((c_ptr->info & CAVE_VIEW) &&
931 (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))) &&
935 c = f_ptr->x_char[F_LIT_STANDARD];
938 a = f_ptr->x_attr[F_LIT_STANDARD];
940 if (p_ptr->wild_mode)
942 /* Special lighting effects */
944 if (view_special_lite && p_ptr->blind)
946 /* Use a darkly darkened colour/tile */
947 a = f_ptr->x_attr[F_LIT_DARKDARK];
948 c = f_ptr->x_char[F_LIT_DARKDARK];
952 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
953 else if (darkened_grid(c_ptr))
955 darkened_grid_hack();
958 /* Special lighting effects */
959 else if (view_special_lite)
964 /* Use a darkly darkened colour/tile */
965 a = f_ptr->x_attr[F_LIT_DARKDARK];
966 c = f_ptr->x_char[F_LIT_DARKDARK];
969 /* Handle "torch-lit" grids */
970 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
973 if (view_yellow_lite)
975 /* Use a brightly lit colour/tile */
976 a = f_ptr->x_attr[F_LIT_LITE];
977 c = f_ptr->x_char[F_LIT_LITE];
981 /* Handle "dark" grids */
982 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
984 /* Use a darkly darkened colour/tile */
985 a = f_ptr->x_attr[F_LIT_DARKDARK];
986 c = f_ptr->x_char[F_LIT_DARKDARK];
989 /* Handle "out-of-sight" grids */
990 else if (!(c_ptr->info & CAVE_VIEW))
993 if (view_bright_lite)
995 /* Use a darkened colour/tile */
996 a = f_ptr->x_attr[F_LIT_DARK];
997 c = f_ptr->x_char[F_LIT_DARK];
1006 /* Unsafe cave grid -- idea borrowed from Unangband */
1007 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1008 feat = FEAT_UNDETECTED;
1012 /* Access darkness */
1013 f_ptr = &f_info[feat];
1016 a = f_ptr->x_attr[F_LIT_STANDARD];
1019 c = f_ptr->x_char[F_LIT_STANDARD];
1023 /* Interesting grids (non-floors) */
1026 /* Memorized grids */
1027 if (c_ptr->info & CAVE_MARK)
1030 c = f_ptr->x_char[F_LIT_STANDARD];
1033 a = f_ptr->x_attr[F_LIT_STANDARD];
1035 if (p_ptr->wild_mode)
1037 /* Special lighting effects */
1038 /* Handle "blind" */
1039 if (view_granite_lite && p_ptr->blind)
1041 /* Use a darkened colour/tile */
1042 a = f_ptr->x_attr[F_LIT_DARK];
1043 c = f_ptr->x_char[F_LIT_DARK];
1047 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1048 else if (darkened_grid(c_ptr))
1050 darkened_grid_hack();
1053 /* Special lighting effects */
1054 else if (view_granite_lite)
1056 /* Handle "blind" */
1059 /* Use a darkened colour/tile */
1060 a = f_ptr->x_attr[F_LIT_DARK];
1061 c = f_ptr->x_char[F_LIT_DARK];
1064 /* Handle "torch-lit" grids */
1065 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1068 if (view_yellow_lite)
1070 /* Use a brightly lit colour/tile */
1071 a = f_ptr->x_attr[F_LIT_LITE];
1072 c = f_ptr->x_char[F_LIT_LITE];
1076 /* Handle "view_bright_lite" */
1077 else if (view_bright_lite)
1080 if (!(c_ptr->info & CAVE_VIEW))
1082 /* Use a darkened colour/tile */
1083 a = f_ptr->x_attr[F_LIT_DARK];
1084 c = f_ptr->x_char[F_LIT_DARK];
1088 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1090 /* Use a darkened colour/tile */
1091 a = f_ptr->x_attr[F_LIT_DARK];
1092 c = f_ptr->x_char[F_LIT_DARK];
1095 /* Not glowing correctly */
1096 else if (!feat_supports_los(feat) && !check_local_illumination(y, x))
1098 /* Use a darkened colour/tile */
1099 a = f_ptr->x_attr[F_LIT_DARK];
1100 c = f_ptr->x_char[F_LIT_DARK];
1109 /* Unsafe cave grid -- idea borrowed from Unangband */
1110 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1111 feat = FEAT_UNDETECTED;
1115 /* Access feature */
1116 f_ptr = &f_info[feat];
1119 a = f_ptr->x_attr[F_LIT_STANDARD];
1122 c = f_ptr->x_char[F_LIT_STANDARD];
1126 if (feat_priority == -1) feat_priority = f_ptr->priority;
1128 /* Save the terrain info for the transparency effects */
1136 /* Hack -- rare random hallucination, except on outer dungeon walls */
1142 image_random(ap, cp);
1147 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1151 /* Acquire object */
1152 o_ptr = &o_list[this_o_idx];
1154 /* Acquire next object */
1155 next_o_idx = o_ptr->next_o_idx;
1157 /* Memorized objects */
1160 if (display_autopick)
1164 match_autopick = is_autopick(o_ptr);
1165 if(match_autopick == -1)
1168 act = autopick_list[match_autopick].action;
1170 if ((act & DO_DISPLAY) && (act & display_autopick))
1172 autopick_obj = o_ptr;
1176 match_autopick = -1;
1181 (*cp) = object_char(o_ptr);
1184 (*ap) = object_attr(o_ptr);
1188 /* Hack -- hallucination */
1189 if (p_ptr->image) image_object(ap, cp);
1197 /* Handle monsters */
1198 if (c_ptr->m_idx && display_autopick == 0 )
1200 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1202 /* Visible monster */
1205 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1213 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1214 * flags are always unseen.
1216 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1222 /* Hallucinatory monster */
1223 image_monster(ap, cp);
1228 /* Monster attr/char */
1232 /* Normal monsters */
1233 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1234 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1236 /* Desired monster attr/char */
1242 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1243 * flags are always unseen.
1245 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1252 /*** Monster's attr ***/
1253 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1258 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1260 /* Multi-hued attr */
1261 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1262 else switch (randint1(7))
1264 case 1: *ap = TERM_RED; break;
1265 case 2: *ap = TERM_L_RED; break;
1266 case 3: *ap = TERM_WHITE; break;
1267 case 4: *ap = TERM_L_GREEN; break;
1268 case 5: *ap = TERM_BLUE; break;
1269 case 6: *ap = TERM_L_DARK; break;
1270 case 7: *ap = TERM_GREEN; break;
1273 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1275 /* Use semi-random attr (usually mimics' colors vary) */
1276 *ap = c_ptr->m_idx % 15 + 1;
1284 /*** Monster's char ***/
1285 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1290 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1294 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1295 *cp = tmp_r_ptr->x_char;
1296 *ap = tmp_r_ptr->x_attr;
1300 *cp = (one_in_(25) ?
1301 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1302 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1315 /* Handle "player" */
1316 if (player_bold(y, x))
1318 monster_race *r_ptr = &r_info[0];
1320 /* Get the "player" attr */
1321 *ap = r_ptr->x_attr;
1323 /* Get the "player" char */
1324 *cp = r_ptr->x_char;
1332 * Calculate panel colum of a location in the map
1334 static int panel_col_of(int col)
1336 col -= panel_col_min;
1337 if (use_bigtile) col *= 2;
1343 * Moves the cursor to a given MAP (y,x) location
1345 void move_cursor_relative(int row, int col)
1347 /* Real co-ords convert to screen positions */
1348 row -= panel_row_prt;
1351 Term_gotoxy(panel_col_of(col), row);
1357 * Place an attr/char pair at the given map coordinate, if legal.
1359 void print_rel(char c, byte a, int y, int x)
1361 /* Only do "legal" locations */
1362 if (panel_contains(y, x))
1364 /* Hack -- fake monochrome */
1367 if (world_monster) a = TERM_DARK;
1368 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1369 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1372 /* Draw the char using the attr */
1373 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, 0, 0);
1382 * Memorize interesting viewable object/features in the given grid
1384 * This function should only be called on "legal" grids.
1386 * This function will memorize the object and/or feature in the given
1387 * grid, if they are (1) viewable and (2) interesting. Note that all
1388 * objects are interesting, all terrain features except floors (and
1389 * invisible traps) are interesting, and floors (and invisible traps)
1390 * are interesting sometimes (depending on various options involving
1391 * the illumination of floor grids).
1393 * The automatic memorization of all objects and non-floor terrain
1394 * features as soon as they are displayed allows incredible amounts
1395 * of optimization in various places, especially "map_info()".
1397 * Note that the memorization of objects is completely separate from
1398 * the memorization of terrain features, preventing annoying floor
1399 * memorization when a detected object is picked up from a dark floor,
1400 * and object memorization when an object is dropped into a floor grid
1401 * which is memorized but out-of-sight.
1403 * This function should be called every time the "memorization" of
1404 * a grid (or the object in a grid) is called into question, such
1405 * as when an object is created in a grid, when a terrain feature
1406 * "changes" from "floor" to "non-floor", when any grid becomes
1407 * "illuminated" or "viewable", and when a "floor" grid becomes
1410 * Note the relatively efficient use of this function by the various
1411 * "update_view()" and "update_lite()" calls, to allow objects and
1412 * terrain features to be memorized (and drawn) whenever they become
1413 * viewable or illuminated in any way, but not when they "maintain"
1414 * or "lose" their previous viewability or illumination.
1416 * Note the butchered "internal" version of "player_can_see_bold()",
1417 * optimized primarily for the most common cases, that is, for the
1418 * non-marked floor grids.
1420 void note_spot(int y, int x)
1422 cave_type *c_ptr = &cave[y][x];
1424 s16b this_o_idx, next_o_idx = 0;
1427 /* Blind players see nothing */
1428 if (p_ptr->blind) return;
1430 /* Analyze non-torch-lit grids */
1431 if (!(c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1433 /* Require line of sight to the grid */
1434 if (!(c_ptr->info & (CAVE_VIEW))) return;
1436 /* Require "perma-lite" of the grid */
1437 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1440 if (!p_ptr->see_nocto) return;
1445 /* Hack -- memorize objects */
1446 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1448 object_type *o_ptr = &o_list[this_o_idx];
1450 /* Acquire next object */
1451 next_o_idx = o_ptr->next_o_idx;
1453 /* Memorize objects */
1454 o_ptr->marked |= OM_FOUND;
1458 /* Hack -- memorize grids */
1459 if (!(c_ptr->info & (CAVE_MARK)))
1461 /* Feature code (applying "mimic" field) */
1462 s16b feat = get_feat_mimic(c_ptr);
1464 /* Memorize some "boring" grids */
1465 if (!have_flag(f_info[feat].flags, FF_REMEMBER))
1467 /* Option -- memorize all torch-lit floors */
1468 if (view_torch_grids &&
1469 ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1472 c_ptr->info |= (CAVE_MARK);
1475 /* Option -- memorize all perma-lit floors */
1476 else if (view_perma_grids && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1479 c_ptr->info |= (CAVE_MARK);
1483 /* Memorize normal grids */
1484 else if (feat_supports_los(feat))
1487 c_ptr->info |= (CAVE_MARK);
1490 /* Memorize torch-lit walls */
1491 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1494 c_ptr->info |= (CAVE_MARK);
1497 /* Memorize walls seen by noctovision of Ninja */
1498 else if (p_ptr->see_nocto)
1501 c_ptr->info |= (CAVE_MARK);
1504 /* Memorize certain non-torch-lit wall grids */
1505 else if (check_local_illumination(y, x))
1508 c_ptr->info |= (CAVE_MARK);
1514 void display_dungeon(void)
1523 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1525 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1527 if (in_bounds2(y, x))
1530 /* Examine the grid */
1531 map_info(y, x, &a, &c, &ta, &tc);
1533 /* Hack -- fake monochrome */
1536 if (world_monster) a = TERM_DARK;
1537 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1538 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1541 /* Hack -- Queue it */
1542 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1546 /* Clear out-of-bound tiles */
1548 /* Access darkness */
1549 feature_type *f_ptr = &f_info[FEAT_NONE];
1552 a = f_ptr->x_attr[F_LIT_STANDARD];
1555 c = f_ptr->x_char[F_LIT_STANDARD];
1557 /* Hack -- Queue it */
1558 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1566 * Redraw (on the screen) a given MAP location
1568 * This function should only be called on "legal" grids
1570 void lite_spot(int y, int x)
1572 /* Redraw if on screen */
1573 if (panel_contains(y, x) && in_bounds2(y, x))
1581 /* Examine the grid */
1582 map_info(y, x, &a, &c, &ta, &tc);
1584 /* Hack -- fake monochrome */
1587 if (world_monster) a = TERM_DARK;
1588 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1589 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1592 /* Hack -- Queue it */
1593 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1595 /* Update sub-windows */
1596 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1602 * Prints the map of the dungeon
1604 * Note that, for efficiency, we contain an "optimized" version
1605 * of both "lite_spot()" and "print_rel()", and that we use the
1606 * "lite_spot()" function to display the player grid, if needed.
1614 s16b xmin, xmax, ymin, ymax;
1619 Term_get_size(&wid, &hgt);
1621 /* Remove map offset */
1625 /* Access the cursor state */
1626 (void)Term_get_cursor(&v);
1628 /* Hide the cursor */
1629 (void)Term_set_cursor(0);
1632 xmin = (0 < panel_col_min) ? panel_col_min : 0;
1633 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1634 ymin = (0 < panel_row_min) ? panel_row_min : 0;
1635 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1637 /* Bottom section of screen */
1638 for (y = 1; y <= ymin - panel_row_prt; y++)
1640 /* Erase the section */
1641 Term_erase(COL_MAP, y, wid);
1644 /* Top section of screen */
1645 for (y = ymax - panel_row_prt; y <= hgt; y++)
1647 /* Erase the section */
1648 Term_erase(COL_MAP, y, wid);
1652 for (y = ymin; y <= ymax; y++)
1654 /* Scan the columns of row "y" */
1655 for (x = xmin; x <= xmax; x++)
1663 /* Determine what is there */
1664 map_info(y, x, &a, &c, &ta, &tc);
1666 /* Hack -- fake monochrome */
1669 if (world_monster) a = TERM_DARK;
1670 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1671 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1674 /* Efficiency -- Redraw that grid of the map */
1675 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1679 /* Display player */
1682 /* Restore the cursor */
1683 (void)Term_set_cursor(v);
1689 * print project path
1691 void prt_path(int y, int x)
1696 int default_color = TERM_SLATE;
1698 if (!display_path) return;
1699 if (-1 == project_length)
1702 /* Get projection path */
1703 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
1706 p_ptr->redraw |= (PR_MAP);
1712 for (i = 0; i < path_n; i++)
1714 int ny = GRID_Y(path_g[i]);
1715 int nx = GRID_X(path_g[i]);
1716 cave_type *c_ptr = &cave[ny][nx];
1718 if (panel_contains(ny, nx))
1720 byte a = default_color;
1726 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1728 /* Determine what is there */
1729 map_info(ny, nx, &a, &c, &ta, &tc);
1731 if (!is_ascii_graphics(a))
1733 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1735 else if (a == default_color)
1741 if (world_monster) a = TERM_DARK;
1742 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1743 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1748 /* Hack -- Queue it */
1749 Term_queue_bigchar(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
1753 if ((c_ptr->info & CAVE_MARK) && !have_flag(f_flags_grid(c_ptr), FF_PROJECT)) break;
1756 if (nx == x && ny == y) default_color = TERM_L_DARK;
1761 static cptr simplify_list[][2] =
1768 {"^Amulet of ", "\""},
1769 {"^Scroll of ", "?"},
1770 {"^Scroll titled ", "?"},
1771 {"^Wand of " , "-"},
1773 {"^Staff of " , "_"},
1774 {"^Potion of ", "!"},
1786 static void display_shortened_item_name(object_type *o_ptr, int y)
1793 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
1794 attr = tval_to_attr[o_ptr->tval % 128];
1800 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
1802 strcpy(buf, "something strange");
1806 for (c = buf; *c; c++)
1809 for (i = 0; simplify_list[i][1]; i++)
1811 cptr org_w = simplify_list[i][0];
1821 if (!strncmp(c, org_w, strlen(org_w)))
1824 cptr tmp = simplify_list[i][1];
1827 tmp = c + strlen(org_w);
1837 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
1843 if(len + 2 > 12) break;
1850 if(len + 1 > 12) break;
1856 Term_putstr(0, y, 12, attr, buf);
1860 * Display a "small-scale" map of the dungeon in the active Term
1862 void display_map(int *cy, int *cx)
1879 /* Save lighting effects */
1880 bool old_view_special_lite = view_special_lite;
1881 bool old_view_granite_lite = view_granite_lite;
1883 int hgt, wid, yrat, xrat;
1885 int **match_autopick_yx;
1886 object_type ***object_autopick_yx;
1889 Term_get_size(&wid, &hgt);
1892 if (use_bigtile) wid /= 2;
1894 yrat = (cur_hgt + hgt - 1) / hgt;
1895 xrat = (cur_wid + wid - 1) / wid;
1897 /* Disable lighting effects */
1898 view_special_lite = FALSE;
1899 view_granite_lite = FALSE;
1901 /* Allocate the maps */
1902 C_MAKE(ma, (hgt + 2), byte_ptr);
1903 C_MAKE(mc, (hgt + 2), char_ptr);
1904 C_MAKE(mp, (hgt + 2), byte_ptr);
1905 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
1906 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
1908 /* Allocate and wipe each line map */
1909 for (y = 0; y < (hgt + 2); y++)
1911 /* Allocate one row each array */
1912 C_MAKE(ma[y], (wid + 2), byte);
1913 C_MAKE(mc[y], (wid + 2), char);
1914 C_MAKE(mp[y], (wid + 2), byte);
1915 C_MAKE(match_autopick_yx[y], (wid + 2), int);
1916 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
1918 for (x = 0; x < wid + 2; ++x)
1920 match_autopick_yx[y][x] = -1;
1921 object_autopick_yx[y][x] = NULL;
1924 ma[y][x] = TERM_WHITE;
1932 /* Allocate the maps */
1933 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
1934 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
1935 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
1937 /* Allocate and wipe each line map */
1938 for (y = 0; y < (cur_hgt + 2); y++)
1940 /* Allocate one row each array */
1941 C_MAKE(bigma[y], (cur_wid + 2), byte);
1942 C_MAKE(bigmc[y], (cur_wid + 2), char);
1943 C_MAKE(bigmp[y], (cur_wid + 2), byte);
1945 for (x = 0; x < cur_wid + 2; ++x)
1948 bigma[y][x] = TERM_WHITE;
1956 /* Fill in the map */
1957 for (i = 0; i < cur_wid; ++i)
1959 for (j = 0; j < cur_hgt; ++j)
1969 /* Extract the current attr/char at that map location */
1970 map_info(j, i, &ta, &tc, &ta, &tc);
1972 /* Extract the priority */
1975 if(match_autopick!=-1
1976 && (match_autopick_yx[y][x] == -1
1977 || match_autopick_yx[y][x] > match_autopick))
1979 match_autopick_yx[y][x] = match_autopick;
1980 object_autopick_yx[y][x] = autopick_obj;
1984 /* Save the char, attr and priority */
1985 bigmc[j+1][i+1] = tc;
1986 bigma[j+1][i+1] = ta;
1987 bigmp[j+1][i+1] = tp;
1991 for (j = 0; j < cur_hgt; ++j)
1993 for (i = 0; i < cur_wid; ++i)
1999 tc = bigmc[j+1][i+1];
2000 ta = bigma[j+1][i+1];
2001 tp = bigmp[j+1][i+1];
2003 /* rare feature has more priority */
2009 for (t = 0; t < 8; t++)
2011 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2012 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2022 /* Save the char, attr and priority */
2035 /* Draw the corners */
2036 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2038 /* Draw the horizontal edges */
2039 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2041 /* Draw the vertical edges */
2042 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2045 /* Display each map line in order */
2046 for (y = 0; y < hgt + 2; ++y)
2048 /* Start a new line */
2049 Term_gotoxy(COL_MAP, y);
2051 /* Display the line */
2052 for (x = 0; x < wid + 2; ++x)
2057 /* Hack -- fake monochrome */
2060 if (world_monster) ta = TERM_DARK;
2061 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2062 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2065 /* Add the character */
2066 Term_add_bigch(ta, tc);
2071 for (y = 1; y < hgt + 1; ++y)
2073 match_autopick = -1;
2074 for (x = 1; x <= wid; x++){
2075 if (match_autopick_yx[y][x] != -1 &&
2076 (match_autopick > match_autopick_yx[y][x] ||
2077 match_autopick == -1)){
2078 match_autopick = match_autopick_yx[y][x];
2079 autopick_obj = object_autopick_yx[y][x];
2083 /* Clear old display */
2084 Term_putstr(0, y, 12, 0, " ");
2086 if (match_autopick != -1)
2088 display_shortened_item_name(autopick_obj, y);
2091 char buf[13] = "\0";
2092 strncpy(buf,autopick_list[match_autopick].name,12);
2100 /* Player location */
2101 (*cy) = py / yrat + 1 + ROW_MAP;
2103 (*cx) = px / xrat + 1 + COL_MAP;
2105 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2107 /* Restore lighting effects */
2108 view_special_lite = old_view_special_lite;
2109 view_granite_lite = old_view_granite_lite;
2111 /* Free each line map */
2112 for (y = 0; y < (hgt + 2); y++)
2114 /* Free one row each array */
2115 C_FREE(ma[y], (wid + 2), byte);
2116 C_FREE(mc[y], (wid + 2), char);
2117 C_FREE(mp[y], (wid + 2), byte);
2118 C_FREE(match_autopick_yx[y], (wid + 2), int);
2119 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2122 /* Free each line map */
2123 C_FREE(ma, (hgt + 2), byte_ptr);
2124 C_FREE(mc, (hgt + 2), char_ptr);
2125 C_FREE(mp, (hgt + 2), byte_ptr);
2126 C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2127 C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2129 /* Free each line map */
2130 for (y = 0; y < (cur_hgt + 2); y++)
2132 /* Free one row each array */
2133 C_FREE(bigma[y], (cur_wid + 2), byte);
2134 C_FREE(bigmc[y], (cur_wid + 2), char);
2135 C_FREE(bigmp[y], (cur_wid + 2), byte);
2138 /* Free each line map */
2139 C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2140 C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2141 C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2146 * Display a "small-scale" map of the dungeon for the player
2148 * Currently, the "player" is displayed on the map. XXX XXX XXX
2150 void do_cmd_view_map(void)
2155 /* Save the screen */
2160 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2162 prt("Please wait...", 0, 0);
2168 /* Clear the screen */
2171 display_autopick = 0;
2173 /* Display the map */
2174 display_map(&cy, &cx);
2177 if(max_autopick && !p_ptr->wild_mode)
2179 display_autopick = ITEM_DISPLAY;
2186 int wid, hgt, row_message;
2188 Term_get_size(&wid, &hgt);
2189 row_message = hgt - 1;
2192 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2194 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2197 /* Hilite the player */
2198 move_cursor(cy, cx);
2203 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2205 flag = DONT_AUTOPICK;
2207 flag = DO_AUTODESTROY;
2209 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2215 if (~display_autopick & flag)
2216 display_autopick |= flag;
2218 display_autopick &= ~flag;
2219 /* Display the map */
2220 display_map(&cy, &cx);
2223 display_autopick = 0;
2229 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2231 put_str("Hit any key to continue", 23, 30);
2232 #endif /* Hilite the player */
2233 move_cursor(cy, cx);
2238 /* Restore the screen */
2247 * Some comments on the cave grid flags. -BEN-
2250 * One of the major bottlenecks in previous versions of Angband was in
2251 * the calculation of "line of sight" from the player to various grids,
2252 * such as monsters. This was such a nasty bottleneck that a lot of
2253 * silly things were done to reduce the dependancy on "line of sight",
2254 * for example, you could not "see" any grids in a lit room until you
2255 * actually entered the room, and there were all kinds of bizarre grid
2256 * flags to enable this behavior. This is also why the "call light"
2257 * spells always lit an entire room.
2259 * The code below provides functions to calculate the "field of view"
2260 * for the player, which, once calculated, provides extremely fast
2261 * calculation of "line of sight from the player", and to calculate
2262 * the "field of torch lite", which, again, once calculated, provides
2263 * extremely fast calculation of "which grids are lit by the player's
2264 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2265 * "GRID_LITE", as appropriate, these functions maintain an array for
2266 * each of these two flags, each array containing the locations of all
2267 * of the grids marked with the appropriate flag, which can be used to
2268 * very quickly scan through all of the grids in a given set.
2270 * To allow more "semantically valid" field of view semantics, whenever
2271 * the field of view (or the set of torch lit grids) changes, all of the
2272 * grids in the field of view (or the set of torch lit grids) are "drawn"
2273 * so that changes in the world will become apparent as soon as possible.
2274 * This has been optimized so that only grids which actually "change" are
2275 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2276 * of the grids which are entering or leaving the relevent set of grids.
2278 * These new methods are so efficient that the old nasty code was removed.
2280 * Note that there is no reason to "update" the "viewable space" unless
2281 * the player "moves", or walls/doors are created/destroyed, and there
2282 * is no reason to "update" the "torch lit grids" unless the field of
2283 * view changes, or the "light radius" changes. This means that when
2284 * the player is resting, or digging, or doing anything that does not
2285 * involve movement or changing the state of the dungeon, there is no
2286 * need to update the "view" or the "lite" regions, which is nice.
2288 * Note that the calls to the nasty "los()" function have been reduced
2289 * to a bare minimum by the use of the new "field of view" calculations.
2291 * I wouldn't be surprised if slight modifications to the "update_view()"
2292 * function would allow us to determine "reverse line-of-sight" as well
2293 * as "normal line-of-sight", which would allow monsters to use a more
2294 * "correct" calculation to determine if they can "see" the player. For
2295 * now, monsters simply "cheat" somewhat and assume that if the player
2296 * has "line of sight" to the monster, then the monster can "pretend"
2297 * that it has "line of sight" to the player.
2300 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2301 * grid and maintains an array of all "CAVE_LITE" grids.
2303 * This set of grids is the complete set of all grids which are lit by
2304 * the players light source, which allows the "player_can_see_bold()"
2305 * function to work very quickly.
2307 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2308 * fact, the player (unless blind) can always "see" all grids which are
2309 * marked as "CAVE_LITE", unless they are "off screen".
2312 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2313 * grid and maintains an array of all "CAVE_VIEW" grids.
2315 * This set of grids is the complete set of all grids within line of sight
2316 * of the player, allowing the "player_has_los_bold()" macro to work very
2320 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2321 * temporary internal flag to mark those grids which are not only in view,
2322 * but which are also "easily" in line of sight of the player. This flag
2323 * is always cleared when we are done.
2326 * The current "update_lite()" and "update_view()" algorithms use the
2327 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2328 * to keep track of which grids were previously marked as "CAVE_LITE" or
2329 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2331 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2332 * for various other purposes, such as spreading lite or darkness during
2333 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2336 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2337 * in some way permanently lit. However, for the player to "see" anything
2338 * in the grid, as determined by "player_can_see()", the player must not be
2339 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2340 * grids, even if marked as "perma lit", are only illuminated if they touch
2341 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2344 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2345 * that even if the player cannot "see" the grid, he "knows" the terrain in
2346 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2347 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2348 * or when one of the "memorize floor grids" options induces memorization.
2350 * Objects are "memorized" in a different way, using a special "marked" flag
2351 * on the object itself, which is set when an object is observed or detected.
2354 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2355 * and should be illuminated by "lite room" and "darkness" spells.
2358 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2359 * and should be unavailable for "teleportation" destinations.
2362 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2363 * which is observed, and the "view_torch_grids" allows the player to memorize
2364 * every torch-lit grid. The player will always memorize important walls,
2365 * doors, stairs, and other terrain features, as well as any "detected" grids.
2367 * Note that the new "update_view()" method allows, among other things, a room
2368 * to be "partially" seen as the player approaches it, with a growing cone of
2369 * floor appearing as the player gets closer to the door. Also, by not turning
2370 * on the "memorize perma-lit grids" option, the player will only "see" those
2371 * floor grids which are actually in line of sight.
2373 * And my favorite "plus" is that you can now use a special option to draw the
2374 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2375 * grids dimly), providing a "pretty" effect as the player runs around, and
2376 * to efficiently display the "torch lite" in a special color.
2379 * Some comments on the "update_view()" algorithm...
2381 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2382 * and only has to call "los()" on the borderline cases. The major axes/diags
2383 * even terminate early when they hit walls. I need to find a quick way
2384 * to "terminate" the other scans.
2386 * Note that in the worst case (a big empty area with say 5% scattered walls),
2387 * each of the 1500 or so nearby grids is checked once, most of them getting
2388 * an "instant" rating, and only a small portion requiring a call to "los()".
2390 * The only time that the algorithm appears to be "noticeably" too slow is
2391 * when running, and this is usually only important in town, since the town
2392 * provides about the worst scenario possible, with large open regions and
2393 * a few scattered obstructions. There is a special "efficiency" option to
2394 * allow the player to reduce his field of view in town, if needed.
2396 * In the "best" case (say, a normal stretch of corridor), the algorithm
2397 * makes one check for each viewable grid, and makes no calls to "los()".
2398 * So running in corridors is very fast, and if a lot of monsters are
2399 * nearby, it is much faster than the old methods.
2401 * Note that resting, most normal commands, and several forms of running,
2402 * plus all commands executed near large groups of monsters, are strictly
2403 * more efficient with "update_view()" that with the old "compute los() on
2404 * demand" method, primarily because once the "field of view" has been
2405 * calculated, it does not have to be recalculated until the player moves
2406 * (or a wall or door is created or destroyed).
2408 * Note that we no longer have to do as many "los()" checks, since once the
2409 * "view" region has been built, very few things cause it to be "changed"
2410 * (player movement, and the opening/closing of doors, changes in wall status).
2411 * Note that door/wall changes are only relevant when the door/wall itself is
2412 * in the "view" region.
2414 * The algorithm seems to only call "los()" from zero to ten times, usually
2415 * only when coming down a corridor into a room, or standing in a room, just
2416 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2417 * we will be reducing the calls to "los()".
2419 * I am thinking in terms of an algorithm that "walks" from the central point
2420 * out to the maximal "distance", at each point, determining the "view" code
2421 * (above). For each grid not on a major axis or diagonal, the "view" code
2422 * depends on the "cave_los_bold()" and "view" of exactly two other grids
2423 * (the one along the nearest diagonal, and the one next to that one, see
2424 * "update_view_aux()"...).
2426 * We "memorize" the viewable space array, so that at the cost of under 3000
2427 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2428 * each grid actually in the "viewable space". And for another 3000 bytes,
2429 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2430 * are also used by other routines, thus reducing the cost to almost nothing.
2432 * A similar thing is done for "forget_lite()" in which case the savings are
2433 * much less, but save us from doing bizarre maintenance checking.
2435 * In the worst "normal" case (in the middle of the town), the reachable space
2436 * actually reaches to more than half of the largest possible "circle" of view,
2437 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2438 * where all the walls have been removed), the reachable space actually reaches
2439 * the theoretical maximum size of just under 1500 grids.
2441 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2442 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2443 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2444 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2445 * entire possible space (including initialization) in one step per grid. If
2446 * we do the "clearing" as a separate step (and use an array of "view" grids),
2447 * then the clearing will take as many steps as grids that were viewed, and the
2448 * algorithm will be able to "stop" scanning at various points.
2449 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2460 * Actually erase the entire "lite" array, redrawing every grid
2462 void forget_lite(void)
2466 /* None to forget */
2467 if (!lite_n) return;
2469 /* Clear them all */
2470 for (i = 0; i < lite_n; i++)
2475 /* Forget "LITE" flag */
2476 cave[y][x].info &= ~(CAVE_LITE);
2479 /* lite_spot(y, x); Perhaps don't need? */
2488 * For delayed visual update
2490 #define cave_note_and_redraw_later(C,Y,X) \
2492 (C)->info |= CAVE_NOTE; \
2493 cave_redraw_later((C), (Y), (X)); \
2498 * For delayed visual update
2500 #define cave_redraw_later(C,Y,X) \
2502 if (!((C)->info & CAVE_REDRAW)) \
2504 (C)->info |= CAVE_REDRAW; \
2505 redraw_y[redraw_n] = (Y); \
2506 redraw_x[redraw_n++] = (X); \
2514 * This macro allows us to efficiently add a grid to the "lite" array,
2515 * note that we are never called for illegal grids, or for grids which
2516 * have already been placed into the "lite" array, and we are never
2517 * called when the "lite" array is full.
2519 #define cave_lite_hack(Y,X) \
2521 if (!(cave[Y][X].info & (CAVE_LITE))) \
2523 cave[Y][X].info |= (CAVE_LITE); \
2524 lite_y[lite_n] = (Y); \
2525 lite_x[lite_n++] = (X); \
2531 * Update the set of grids "illuminated" by the player's lite.
2533 * This routine needs to use the results of "update_view()"
2535 * Note that "blindness" does NOT affect "torch lite". Be careful!
2537 * We optimize most lites (all non-artifact lites) by using "obvious"
2538 * facts about the results of "small" lite radius, and we attempt to
2539 * list the "nearby" grids before the more "distant" ones in the
2540 * array of torch-lit grids.
2542 * We assume that "radius zero" lite is in fact no lite at all.
2544 * Torch Lantern Artifacts
2554 void update_lite(void)
2556 int i, x, y, min_x, max_x, min_y, max_y;
2557 int p = p_ptr->cur_lite;
2560 /*** Special case ***/
2563 /* Hack -- Player has no lite */
2566 /* Forget the old lite */
2567 /* forget_lite(); Perhaps don't need? */
2569 /* Add it to later visual update */
2570 cave_redraw_later(&cave[py][px], py, px);
2574 /*** Save the old "lite" grids for later ***/
2576 /* Clear them all */
2577 for (i = 0; i < lite_n; i++)
2582 /* Mark the grid as not "lite" */
2583 cave[y][x].info &= ~(CAVE_LITE);
2585 /* Mark the grid as "seen" */
2586 cave[y][x].info |= (CAVE_TEMP);
2588 /* Add it to the "seen" set */
2598 /*** Collect the new "lite" grids ***/
2600 /* Radius 1 -- torch radius */
2604 cave_lite_hack(py, px);
2607 cave_lite_hack(py+1, px);
2608 cave_lite_hack(py-1, px);
2609 cave_lite_hack(py, px+1);
2610 cave_lite_hack(py, px-1);
2612 /* Diagonal grids */
2613 cave_lite_hack(py+1, px+1);
2614 cave_lite_hack(py+1, px-1);
2615 cave_lite_hack(py-1, px+1);
2616 cave_lite_hack(py-1, px-1);
2619 /* Radius 2 -- lantern radius */
2622 /* South of the player */
2623 if (cave_los_bold(py + 1, px))
2625 cave_lite_hack(py+2, px);
2626 cave_lite_hack(py+2, px+1);
2627 cave_lite_hack(py+2, px-1);
2630 /* North of the player */
2631 if (cave_los_bold(py - 1, px))
2633 cave_lite_hack(py-2, px);
2634 cave_lite_hack(py-2, px+1);
2635 cave_lite_hack(py-2, px-1);
2638 /* East of the player */
2639 if (cave_los_bold(py, px + 1))
2641 cave_lite_hack(py, px+2);
2642 cave_lite_hack(py+1, px+2);
2643 cave_lite_hack(py-1, px+2);
2646 /* West of the player */
2647 if (cave_los_bold(py, px - 1))
2649 cave_lite_hack(py, px-2);
2650 cave_lite_hack(py+1, px-2);
2651 cave_lite_hack(py-1, px-2);
2655 /* Radius 3+ -- artifact radius */
2660 /* Paranoia -- see "LITE_MAX" */
2663 /* South-East of the player */
2664 if (cave_los_bold(py + 1, px + 1))
2666 cave_lite_hack(py+2, px+2);
2669 /* South-West of the player */
2670 if (cave_los_bold(py + 1, px - 1))
2672 cave_lite_hack(py+2, px-2);
2675 /* North-East of the player */
2676 if (cave_los_bold(py - 1, px + 1))
2678 cave_lite_hack(py-2, px+2);
2681 /* North-West of the player */
2682 if (cave_los_bold(py - 1, px - 1))
2684 cave_lite_hack(py-2, px-2);
2689 if (min_y < 0) min_y = 0;
2693 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
2697 if (min_x < 0) min_x = 0;
2701 if (max_x > cur_wid-1) max_x = cur_wid-1;
2703 /* Scan the maximal box */
2704 for (y = min_y; y <= max_y; y++)
2706 for (x = min_x; x <= max_x; x++)
2708 int dy = (py > y) ? (py - y) : (y - py);
2709 int dx = (px > x) ? (px - x) : (x - px);
2711 /* Skip the "central" grids (above) */
2712 if ((dy <= 2) && (dx <= 2)) continue;
2714 /* Hack -- approximate the distance */
2715 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2717 /* Skip distant grids */
2718 if (d > p) continue;
2720 /* Viewable, nearby, grids get "torch lit" */
2721 if (player_has_los_bold(y, x))
2723 /* This grid is "torch lit" */
2724 cave_lite_hack(y, x);
2731 /*** Complete the algorithm ***/
2733 /* Draw the new grids */
2734 for (i = 0; i < lite_n; i++)
2739 c_ptr = &cave[y][x];
2741 /* Update fresh grids */
2742 if (c_ptr->info & (CAVE_TEMP)) continue;
2744 /* Add it to later visual update */
2745 cave_note_and_redraw_later(c_ptr, y, x);
2748 /* Clear them all */
2749 for (i = 0; i < temp_n; i++)
2754 c_ptr = &cave[y][x];
2756 /* No longer in the array */
2757 c_ptr->info &= ~(CAVE_TEMP);
2759 /* Update stale grids */
2760 if (c_ptr->info & (CAVE_LITE)) continue;
2762 /* Add it to later visual update */
2763 cave_redraw_later(c_ptr, y, x);
2769 /* Mega-Hack -- Visual update later */
2770 p_ptr->update |= (PU_DELAY_VIS);
2774 static bool mon_invis;
2775 static s16b mon_fy, mon_fx;
2778 * Add a square to the changes array
2780 static void mon_lite_hack(int y, int x)
2783 int midpoint, dpf, d;
2785 /* We trust this grid is in bounds */
2786 /* if (!in_bounds2(y, x)) return; */
2788 c_ptr = &cave[y][x];
2790 /* Want a unlit square in view of the player */
2791 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
2793 if (!cave_los_grid(c_ptr))
2795 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2796 if (mon_invis) return;
2798 /* Hack -- Prevent monster lite leakage in walls */
2800 /* Horizontal walls between player and a monster */
2801 if (((y < py) && (y > mon_fy)) || ((y > py) && (y < mon_fy)))
2805 midpoint = mon_fx + ((px - mon_fx) * ABS(d)) / ABS(dpf);
2807 /* Only first wall viewed from mid-x is lit */
2810 if (!cave_los_bold(y, x + 1)) return;
2812 else if (x > midpoint)
2814 if (!cave_los_bold(y, x - 1)) return;
2818 /* Vertical walls between player and a monster */
2819 if (((x < px) && (x > mon_fx)) || ((x > px) && (x < mon_fx)))
2823 midpoint = mon_fy + ((py - mon_fy) * ABS(d)) / ABS(dpf);
2825 /* Only first wall viewed from mid-y is lit */
2828 if (!cave_los_bold(y + 1, x)) return;
2830 else if (y > midpoint)
2832 if (!cave_los_bold(y - 1, x)) return;
2837 /* We trust temp_n does not exceed TEMP_MAX */
2840 if (!(c_ptr->info & CAVE_MNDK))
2842 /* Save this square */
2851 /* No longer dark */
2852 c_ptr->info &= ~(CAVE_MNDK);
2856 c_ptr->info |= CAVE_MNLT;
2861 * Add a square to the changes array
2863 static void mon_dark_hack(int y, int x)
2866 int midpoint, dpf, d;
2868 /* We trust this grid is in bounds */
2869 /* if (!in_bounds2(y, x)) return; */
2871 c_ptr = &cave[y][x];
2873 /* Want a unlit and undarkened square in view of the player */
2874 if ((c_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
2876 if (!cave_los_grid(c_ptr))
2878 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2879 if (mon_invis) return;
2881 /* Hack -- Prevent monster dark lite leakage in walls */
2883 /* Horizontal walls between player and a monster */
2884 if (((y < py) && (y > mon_fy)) || ((y > py) && (y < mon_fy)))
2888 midpoint = mon_fx + ((px - mon_fx) * ABS(d)) / ABS(dpf);
2890 /* Only first wall viewed from mid-x is lit */
2893 if (!cave_los_bold(y, x + 1)) return;
2895 else if (x > midpoint)
2897 if (!cave_los_bold(y, x - 1)) return;
2901 /* Vertical walls between player and a monster */
2902 if (((x < px) && (x > mon_fx)) || ((x > px) && (x < mon_fx)))
2906 midpoint = mon_fy + ((py - mon_fy) * ABS(d)) / ABS(dpf);
2908 /* Only first wall viewed from mid-y is lit */
2911 if (!cave_los_bold(y + 1, x)) return;
2913 else if (y > midpoint)
2915 if (!cave_los_bold(y - 1, x)) return;
2920 /* We trust temp_n does not exceed TEMP_MAX */
2922 /* Save this square */
2928 c_ptr->info |= CAVE_MNDK;
2933 * Update squares illuminated or darkened by monsters.
2935 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
2936 * denote squares illuminated by monsters.
2938 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
2939 * updating. Only squares in view of the player, whos state
2940 * changes are drawn via lite_spot().
2942 void update_mon_lite(void)
2948 void (*add_mon_lite)(int, int);
2952 /* Non-Ninja player in the darkness */
2953 int dis_lim = ((d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
2954 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
2956 /* Clear all monster lit squares */
2957 for (i = 0; i < mon_lite_n; i++)
2960 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
2962 /* Set temp or xtra flag */
2963 c_ptr->info |= (c_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
2965 /* Clear monster illumination flag */
2966 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
2969 /* Empty temp list of new squares to lite up */
2972 /* Loop through monsters, adding newly lit squares to changes list */
2973 for (i = 1; i < m_max; i++)
2975 monster_type *m_ptr = &m_list[i];
2976 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2978 /* Skip dead monsters */
2979 if (!m_ptr->r_idx) continue;
2981 /* Is it too far away? */
2982 if (m_ptr->cdis > dis_lim) continue;
2984 /* If a monster stops time, break */
2985 if (world_monster) break;
2987 /* Get lite radius */
2990 /* Note the radii are cumulative */
2991 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
2992 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
2993 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
2994 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
2996 /* Exit if has no light */
3000 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3001 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3002 add_mon_lite = mon_lite_hack;
3006 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (m_ptr->csleep || (!dun_level && !is_daytime()))) continue;
3007 add_mon_lite = mon_dark_hack;
3008 rad = -rad; /* Use absolute value */
3011 /* Access the location */
3015 /* Is the monster visible? */
3016 mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
3018 /* The square it is on */
3019 add_mon_lite(mon_fy, mon_fx);
3021 /* Adjacent squares */
3022 add_mon_lite(mon_fy + 1, mon_fx);
3023 add_mon_lite(mon_fy - 1, mon_fx);
3024 add_mon_lite(mon_fy, mon_fx + 1);
3025 add_mon_lite(mon_fy, mon_fx - 1);
3026 add_mon_lite(mon_fy + 1, mon_fx + 1);
3027 add_mon_lite(mon_fy + 1, mon_fx - 1);
3028 add_mon_lite(mon_fy - 1, mon_fx + 1);
3029 add_mon_lite(mon_fy - 1, mon_fx - 1);
3034 /* South of the monster */
3035 if (cave_los_bold(mon_fy + 1, mon_fx))
3037 add_mon_lite(mon_fy + 2, mon_fx + 1);
3038 add_mon_lite(mon_fy + 2, mon_fx);
3039 add_mon_lite(mon_fy + 2, mon_fx - 1);
3041 c_ptr = &cave[mon_fy + 2][mon_fx];
3044 if ((rad == 3) && cave_los_grid(c_ptr))
3046 add_mon_lite(mon_fy + 3, mon_fx + 1);
3047 add_mon_lite(mon_fy + 3, mon_fx);
3048 add_mon_lite(mon_fy + 3, mon_fx - 1);
3052 /* North of the monster */
3053 if (cave_los_bold(mon_fy - 1, mon_fx))
3055 add_mon_lite(mon_fy - 2, mon_fx + 1);
3056 add_mon_lite(mon_fy - 2, mon_fx);
3057 add_mon_lite(mon_fy - 2, mon_fx - 1);
3059 c_ptr = &cave[mon_fy - 2][mon_fx];
3062 if ((rad == 3) && cave_los_grid(c_ptr))
3064 add_mon_lite(mon_fy - 3, mon_fx + 1);
3065 add_mon_lite(mon_fy - 3, mon_fx);
3066 add_mon_lite(mon_fy - 3, mon_fx - 1);
3070 /* East of the monster */
3071 if (cave_los_bold(mon_fy, mon_fx + 1))
3073 add_mon_lite(mon_fy + 1, mon_fx + 2);
3074 add_mon_lite(mon_fy, mon_fx + 2);
3075 add_mon_lite(mon_fy - 1, mon_fx + 2);
3077 c_ptr = &cave[mon_fy][mon_fx + 2];
3080 if ((rad == 3) && cave_los_grid(c_ptr))
3082 add_mon_lite(mon_fy + 1, mon_fx + 3);
3083 add_mon_lite(mon_fy, mon_fx + 3);
3084 add_mon_lite(mon_fy - 1, mon_fx + 3);
3088 /* West of the monster */
3089 if (cave_los_bold(mon_fy, mon_fx - 1))
3091 add_mon_lite(mon_fy + 1, mon_fx - 2);
3092 add_mon_lite(mon_fy, mon_fx - 2);
3093 add_mon_lite(mon_fy - 1, mon_fx - 2);
3095 c_ptr = &cave[mon_fy][mon_fx - 2];
3098 if ((rad == 3) && cave_los_grid(c_ptr))
3100 add_mon_lite(mon_fy + 1, mon_fx - 3);
3101 add_mon_lite(mon_fy, mon_fx - 3);
3102 add_mon_lite(mon_fy - 1, mon_fx - 3);
3110 /* South-East of the monster */
3111 if (cave_los_bold(mon_fy + 1, mon_fx + 1))
3113 add_mon_lite(mon_fy + 2, mon_fx + 2);
3116 /* South-West of the monster */
3117 if (cave_los_bold(mon_fy + 1, mon_fx - 1))
3119 add_mon_lite(mon_fy + 2, mon_fx - 2);
3122 /* North-East of the monster */
3123 if (cave_los_bold(mon_fy - 1, mon_fx + 1))
3125 add_mon_lite(mon_fy - 2, mon_fx + 2);
3128 /* North-West of the monster */
3129 if (cave_los_bold(mon_fy - 1, mon_fx - 1))
3131 add_mon_lite(mon_fy - 2, mon_fx - 2);
3136 /* Save end of list of new squares */
3140 * Look at old set flags to see if there are any changes.
3142 for (i = 0; i < mon_lite_n; i++)
3147 /* We trust this grid is in bounds */
3150 c_ptr = &cave[fy][fx];
3152 if (c_ptr->info & CAVE_TEMP) /* Pervious lit */
3154 /* It it no longer lit? */
3155 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3157 /* It is now unlit */
3158 /* Add it to later visual update */
3159 cave_note_and_redraw_later(c_ptr, fy, fx);
3162 else /* Pervious darkened */
3164 /* It it no longer darken? */
3165 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3167 /* It is now undarken */
3168 /* Add it to later visual update */
3169 cave_note_and_redraw_later(c_ptr, fy, fx);
3173 /* Add to end of temp array */
3174 temp_x[temp_n] = (byte)fx;
3175 temp_y[temp_n] = (byte)fy;
3179 /* Clear the lite array */
3182 /* Copy the temp array into the lit array lighting the new squares. */
3183 for (i = 0; i < end_temp; i++)
3188 /* We trust this grid is in bounds */
3191 c_ptr = &cave[fy][fx];
3193 if (c_ptr->info & CAVE_MNLT) /* Lit */
3195 /* The is the square newly lit and visible? */
3196 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3199 /* Add it to later visual update */
3200 cave_note_and_redraw_later(c_ptr, fy, fx);
3205 /* The is the square newly darkened and visible? */
3206 if ((c_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3208 /* It is now darkened */
3209 /* Add it to later visual update */
3210 cave_note_and_redraw_later(c_ptr, fy, fx);
3214 /* Save in the monster lit or darkened array */
3215 mon_lite_x[mon_lite_n] = fx;
3216 mon_lite_y[mon_lite_n] = fy;
3220 /* Clear the temp flag for the old lit or darken grids */
3221 for (i = end_temp; i < temp_n; i++)
3223 /* We trust this grid is in bounds */
3225 cave[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3228 /* Finished with temp_n */
3231 /* Mega-Hack -- Visual update later */
3232 p_ptr->update |= (PU_DELAY_VIS);
3234 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3236 if (p_ptr->special_defense & NINJA_S_STEALTH)
3238 if (p_ptr->old_monlite != p_ptr->monlite)
3243 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3245 msg_print("Your mantle of shadow become thin.");
3251 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3253 msg_print("Your mantle of shadow restored its original darkness.");
3258 p_ptr->old_monlite = p_ptr->monlite;
3261 void clear_mon_lite(void)
3266 /* Clear all monster lit squares */
3267 for (i = 0; i < mon_lite_n; i++)
3270 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3272 /* Clear monster illumination flag */
3273 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3276 /* Empty the array */
3283 * Clear the viewable space
3285 void forget_view(void)
3291 /* None to forget */
3292 if (!view_n) return;
3294 /* Clear them all */
3295 for (i = 0; i < view_n; i++)
3300 /* Access the grid */
3301 c_ptr = &cave[y][x];
3303 /* Forget that the grid is viewable */
3304 c_ptr->info &= ~(CAVE_VIEW);
3306 if (!panel_contains(y, x)) continue;
3308 /* Update the screen */
3309 /* lite_spot(y, x); Perhaps don't need? */
3319 * This macro allows us to efficiently add a grid to the "view" array,
3320 * note that we are never called for illegal grids, or for grids which
3321 * have already been placed into the "view" array, and we are never
3322 * called when the "view" array is full.
3324 #define cave_view_hack(C,Y,X) \
3326 if (!((C)->info & (CAVE_VIEW))){\
3327 (C)->info |= (CAVE_VIEW); \
3328 view_y[view_n] = (Y); \
3329 view_x[view_n] = (X); \
3336 * Helper function for "update_view()" below
3338 * We are checking the "viewability" of grid (y,x) by the player.
3340 * This function assumes that (y,x) is legal (i.e. on the map).
3342 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3343 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3345 * Note that we are using the "CAVE_XTRA" field for marking grids as
3346 * "easily viewable". This bit is cleared at the end of "update_view()".
3348 * This function adds (y,x) to the "viewable set" if necessary.
3350 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3352 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3354 bool f1, f2, v1, v2, z1, z2, wall;
3358 cave_type *g1_c_ptr;
3359 cave_type *g2_c_ptr;
3361 /* Access the grids */
3362 g1_c_ptr = &cave[y1][x1];
3363 g2_c_ptr = &cave[y2][x2];
3366 /* Check for walls */
3367 f1 = (cave_los_grid(g1_c_ptr));
3368 f2 = (cave_los_grid(g2_c_ptr));
3370 /* Totally blocked by physical walls */
3371 if (!f1 && !f2) return (TRUE);
3374 /* Check for visibility */
3375 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3376 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3378 /* Totally blocked by "unviewable neighbors" */
3379 if (!v1 && !v2) return (TRUE);
3382 /* Access the grid */
3383 c_ptr = &cave[y][x];
3386 /* Check for walls */
3387 wall = (!cave_los_grid(c_ptr));
3390 /* Check the "ease" of visibility */
3391 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3392 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3394 /* Hack -- "easy" plus "easy" yields "easy" */
3397 c_ptr->info |= (CAVE_XTRA);
3399 cave_view_hack(c_ptr, y, x);
3404 /* Hack -- primary "easy" yields "viewed" */
3407 cave_view_hack(c_ptr, y, x);
3412 /* Hack -- "view" plus "view" yields "view" */
3415 /* c_ptr->info |= (CAVE_XTRA); */
3417 cave_view_hack(c_ptr, y, x);
3423 /* Mega-Hack -- the "los()" function works poorly on walls */
3426 cave_view_hack(c_ptr, y, x);
3432 /* Hack -- check line of sight */
3433 if (los(py, px, y, x))
3435 cave_view_hack(c_ptr, y, x);
3441 /* Assume no line of sight. */
3448 * Calculate the viewable space
3450 * 1: Process the player
3451 * 1a: The player is always (easily) viewable
3452 * 2: Process the diagonals
3453 * 2a: The diagonals are (easily) viewable up to the first wall
3454 * 2b: But never go more than 2/3 of the "full" distance
3455 * 3: Process the main axes
3456 * 3a: The main axes are (easily) viewable up to the first wall
3457 * 3b: But never go more than the "full" distance
3458 * 4: Process sequential "strips" in each of the eight octants
3459 * 4a: Each strip runs along the previous strip
3460 * 4b: The main axes are "previous" to the first strip
3461 * 4c: Process both "sides" of each "direction" of each strip
3462 * 4c1: Each side aborts as soon as possible
3463 * 4c2: Each side tells the next strip how far it has to check
3465 * Note that the octant processing involves some pretty interesting
3466 * observations involving when a grid might possibly be viewable from
3467 * a given grid, and on the order in which the strips are processed.
3469 * Note the use of the mathematical facts shown below, which derive
3470 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3471 * hypotenuse of a right triangle is primarily determined by the length
3472 * of the longest side, when one side is small, and is strictly less
3473 * than one-and-a-half times as long as the longest side when both of
3474 * the sides are large.
3476 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3477 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3479 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3481 * These observations are important because the calculation of the actual
3482 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3483 * while for small values (up to about 20 or so), the approximations above
3484 * are correct to within an error of at most one grid or so.
3486 * Observe the use of "full" and "over" in the code below, and the use of
3487 * the specialized calculation involving "limit", all of which derive from
3488 * the observations given above. Basically, we note that the "circle" of
3489 * view is completely contained in an "octagon" whose bounds are easy to
3490 * determine, and that only a few steps are needed to derive the actual
3491 * bounds of the circle given the bounds of the octagon.
3493 * Note that by skipping all the grids in the corners of the octagon, we
3494 * place an upper limit on the number of grids in the field of view, given
3495 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3496 * view, only about 1475 of these are in the "octagon" of view, and even
3497 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3498 * entries to completely contain the actual field of view.
3500 * Note also the care taken to prevent "running off the map". The use of
3501 * explicit checks on the "validity" of the "diagonal", and the fact that
3502 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3503 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
3504 * of multiple checks on the validity of grids.
3506 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3507 * "ws","wn" variables. They work like this: While travelling down the
3508 * south-bound strip just to the east of the main south axis, as soon as
3509 * we get to a grid which does not "transmit" viewing, if all of the strips
3510 * preceding us (in this case, just the main axis) had terminated at or before
3511 * the same point, then we can stop, and reset the "max distance" to ourself.
3512 * So, each strip (named by major axis plus offset, thus "se" in this case)
3513 * maintains a "blockage" variable, initialized during the main axis step,
3514 * and checks it whenever a blockage is observed. After processing each
3515 * strip as far as the previous strip told us to process, the next strip is
3516 * told not to go farther than the current strip's farthest viewable grid,
3517 * unless open space is still available. This uses the "k" variable.
3519 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
3520 * macro is a replacement for "cave_los_bold()" which takes a pointer to
3521 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3522 * chunk of code which adds the given location to the "view" array if it
3523 * is not already there, using both the actual location and a pointer to
3524 * the cave grid. See above.
3526 * By the way, the purpose of this code is to reduce the dependancy on the
3527 * "los()" function which is slow, and, in some cases, not very accurate.
3529 * It is very possible that I am the only person who fully understands this
3530 * function, and for that I am truly sorry, but efficiency was very important
3531 * and the "simple" version of this function was just not fast enough. I am
3532 * more than willing to replace this function with a simpler one, if it is
3533 * equally efficient, and especially willing if the new function happens to
3534 * derive "reverse-line-of-sight" at the same time, since currently monsters
3535 * just use an optimized hack of "you see me, so I see you", and then use the
3536 * actual "projectable()" function to check spell attacks.
3538 void update_view(void)
3540 int n, m, d, k, y, x, z;
3542 int se, sw, ne, nw, es, en, ws, wn;
3546 int y_max = cur_hgt - 1;
3547 int x_max = cur_wid - 1;
3551 /*** Initialize ***/
3554 if (view_reduce_view && !dun_level)
3556 /* Full radius (10) */
3557 full = MAX_SIGHT / 2;
3559 /* Octagon factor (15) */
3560 over = MAX_SIGHT * 3 / 4;
3566 /* Full radius (20) */
3569 /* Octagon factor (30) */
3570 over = MAX_SIGHT * 3 / 2;
3574 /*** Step 0 -- Begin ***/
3576 /* Save the old "view" grids for later */
3577 for (n = 0; n < view_n; n++)
3582 /* Access the grid */
3583 c_ptr = &cave[y][x];
3585 /* Mark the grid as not in "view" */
3586 c_ptr->info &= ~(CAVE_VIEW);
3588 /* Mark the grid as "seen" */
3589 c_ptr->info |= (CAVE_TEMP);
3591 /* Add it to the "seen" set */
3597 /* Start over with the "view" array */
3600 /*** Step 1 -- adjacent grids ***/
3602 /* Now start on the player */
3606 /* Access the grid */
3607 c_ptr = &cave[y][x];
3609 /* Assume the player grid is easily viewable */
3610 c_ptr->info |= (CAVE_XTRA);
3612 /* Assume the player grid is viewable */
3613 cave_view_hack(c_ptr, y, x);
3616 /*** Step 2 -- Major Diagonals ***/
3621 /* Scan south-east */
3622 for (d = 1; d <= z; d++)
3624 c_ptr = &cave[y+d][x+d];
3625 c_ptr->info |= (CAVE_XTRA);
3626 cave_view_hack(c_ptr, y+d, x+d);
3627 if (!cave_los_grid(c_ptr)) break;
3630 /* Scan south-west */
3631 for (d = 1; d <= z; d++)
3633 c_ptr = &cave[y+d][x-d];
3634 c_ptr->info |= (CAVE_XTRA);
3635 cave_view_hack(c_ptr, y+d, x-d);
3636 if (!cave_los_grid(c_ptr)) break;
3639 /* Scan north-east */
3640 for (d = 1; d <= z; d++)
3642 c_ptr = &cave[y-d][x+d];
3643 c_ptr->info |= (CAVE_XTRA);
3644 cave_view_hack(c_ptr, y-d, x+d);
3645 if (!cave_los_grid(c_ptr)) break;
3648 /* Scan north-west */
3649 for (d = 1; d <= z; d++)
3651 c_ptr = &cave[y-d][x-d];
3652 c_ptr->info |= (CAVE_XTRA);
3653 cave_view_hack(c_ptr, y-d, x-d);
3654 if (!cave_los_grid(c_ptr)) break;
3658 /*** Step 3 -- major axes ***/
3661 for (d = 1; d <= full; d++)
3663 c_ptr = &cave[y+d][x];
3664 c_ptr->info |= (CAVE_XTRA);
3665 cave_view_hack(c_ptr, y+d, x);
3666 if (!cave_los_grid(c_ptr)) break;
3669 /* Initialize the "south strips" */
3673 for (d = 1; d <= full; d++)
3675 c_ptr = &cave[y-d][x];
3676 c_ptr->info |= (CAVE_XTRA);
3677 cave_view_hack(c_ptr, y-d, x);
3678 if (!cave_los_grid(c_ptr)) break;
3681 /* Initialize the "north strips" */
3685 for (d = 1; d <= full; d++)
3687 c_ptr = &cave[y][x+d];
3688 c_ptr->info |= (CAVE_XTRA);
3689 cave_view_hack(c_ptr, y, x+d);
3690 if (!cave_los_grid(c_ptr)) break;
3693 /* Initialize the "east strips" */
3697 for (d = 1; d <= full; d++)
3699 c_ptr = &cave[y][x-d];
3700 c_ptr->info |= (CAVE_XTRA);
3701 cave_view_hack(c_ptr, y, x-d);
3702 if (!cave_los_grid(c_ptr)) break;
3705 /* Initialize the "west strips" */
3709 /*** Step 4 -- Divide each "octant" into "strips" ***/
3711 /* Now check each "diagonal" (in parallel) */
3712 for (n = 1; n <= over / 2; n++)
3714 int ypn, ymn, xpn, xmn;
3717 /* Acquire the "bounds" of the maximal circle */
3719 if (z > full - n) z = full - n;
3720 while ((z + n + (n>>1)) > full) z--;
3723 /* Access the four diagonal grids */
3733 /* Maximum distance */
3734 m = MIN(z, y_max - ypn);
3737 if ((xpn <= x_max) && (n < se))
3740 for (k = n, d = 1; d <= m; d++)
3742 /* Check grid "d" in strip "n", notice "blockage" */
3743 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3745 if (n + d >= se) break;
3748 /* Track most distant "non-blockage" */
3755 /* Limit the next strip */
3760 if ((xmn >= 0) && (n < sw))
3763 for (k = n, d = 1; d <= m; d++)
3765 /* Check grid "d" in strip "n", notice "blockage" */
3766 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3768 if (n + d >= sw) break;
3771 /* Track most distant "non-blockage" */
3778 /* Limit the next strip */
3787 /* Maximum distance */
3791 if ((xpn <= x_max) && (n < ne))
3794 for (k = n, d = 1; d <= m; d++)
3796 /* Check grid "d" in strip "n", notice "blockage" */
3797 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3799 if (n + d >= ne) break;
3802 /* Track most distant "non-blockage" */
3809 /* Limit the next strip */
3814 if ((xmn >= 0) && (n < nw))
3817 for (k = n, d = 1; d <= m; d++)
3819 /* Check grid "d" in strip "n", notice "blockage" */
3820 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
3822 if (n + d >= nw) break;
3825 /* Track most distant "non-blockage" */
3832 /* Limit the next strip */
3841 /* Maximum distance */
3842 m = MIN(z, x_max - xpn);
3845 if ((ypn <= x_max) && (n < es))
3848 for (k = n, d = 1; d <= m; d++)
3850 /* Check grid "d" in strip "n", notice "blockage" */
3851 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
3853 if (n + d >= es) break;
3856 /* Track most distant "non-blockage" */
3863 /* Limit the next strip */
3868 if ((ymn >= 0) && (n < en))
3871 for (k = n, d = 1; d <= m; d++)
3873 /* Check grid "d" in strip "n", notice "blockage" */
3874 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
3876 if (n + d >= en) break;
3879 /* Track most distant "non-blockage" */
3886 /* Limit the next strip */
3895 /* Maximum distance */
3899 if ((ypn <= y_max) && (n < ws))
3902 for (k = n, d = 1; d <= m; d++)
3904 /* Check grid "d" in strip "n", notice "blockage" */
3905 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
3907 if (n + d >= ws) break;
3910 /* Track most distant "non-blockage" */
3917 /* Limit the next strip */
3922 if ((ymn >= 0) && (n < wn))
3925 for (k = n, d = 1; d <= m; d++)
3927 /* Check grid "d" in strip "n", notice "blockage" */
3928 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
3930 if (n + d >= wn) break;
3933 /* Track most distant "non-blockage" */
3940 /* Limit the next strip */
3947 /*** Step 5 -- Complete the algorithm ***/
3949 /* Update all the new grids */
3950 for (n = 0; n < view_n; n++)
3955 /* Access the grid */
3956 c_ptr = &cave[y][x];
3958 /* Clear the "CAVE_XTRA" flag */
3959 c_ptr->info &= ~(CAVE_XTRA);
3961 /* Update only newly viewed grids */
3962 if (c_ptr->info & (CAVE_TEMP)) continue;
3964 /* Add it to later visual update */
3965 cave_note_and_redraw_later(c_ptr, y, x);
3968 /* Wipe the old grids, update as needed */
3969 for (n = 0; n < temp_n; n++)
3974 /* Access the grid */
3975 c_ptr = &cave[y][x];
3977 /* No longer in the array */
3978 c_ptr->info &= ~(CAVE_TEMP);
3980 /* Update only non-viewable grids */
3981 if (c_ptr->info & (CAVE_VIEW)) continue;
3983 /* Add it to later visual update */
3984 cave_redraw_later(c_ptr, y, x);
3990 /* Mega-Hack -- Visual update later */
3991 p_ptr->update |= (PU_DELAY_VIS);
3996 * Mega-Hack -- Delayed visual update
3997 * Only used if update_view(), update_lite() or update_mon_lite() was called
3999 void delayed_visual_update(void)
4004 /* Update needed grids */
4005 for (i = 0; i < redraw_n; i++)
4010 /* Access the grid */
4011 c_ptr = &cave[y][x];
4013 /* Update only needed grids (prevent multiple updating) */
4014 if (!(c_ptr->info & CAVE_REDRAW)) continue;
4016 /* If required, note */
4017 if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
4022 /* Hack -- Visual update of monster on this grid */
4023 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4025 /* No longer in the array */
4026 c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4035 * Hack -- forget the "flow" information
4037 void forget_flow(void)
4041 /* Check the entire dungeon */
4042 for (y = 0; y < cur_hgt; y++)
4044 for (x = 0; x < cur_wid; x++)
4046 /* Forget the old data */
4047 cave[y][x].dist = 0;
4048 cave[y][x].cost = 0;
4049 cave[y][x].when = 0;
4056 * Hack - speed up the update_flow algorithm by only doing
4057 * it everytime the player moves out of LOS of the last
4060 static u16b flow_x = 0;
4061 static u16b flow_y = 0;
4066 * Hack -- fill in the "cost" field of every grid that the player
4067 * can "reach" with the number of steps needed to reach that grid.
4068 * This also yields the "distance" of the player from every grid.
4070 * In addition, mark the "when" of the grids that can reach
4071 * the player with the incremented value of "flow_n".
4073 * Hack -- use the "seen" array as a "circular queue".
4075 * We do not need a priority queue because the cost from grid
4076 * to grid is always "one" and we process them in order.
4078 void update_flow(void)
4084 /* Paranoia -- make sure the array is empty */
4087 /* The last way-point is on the map */
4088 if (running && in_bounds(flow_y, flow_x))
4090 /* The way point is in sight - do not update. (Speedup) */
4091 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4094 /* Erase all of the current flow information */
4095 for (y = 0; y < cur_hgt; y++)
4097 for (x = 0; x < cur_wid; x++)
4099 cave[y][x].cost = 0;
4100 cave[y][x].dist = 0;
4104 /* Save player position */
4108 /* Add the player's grid to the queue */
4112 /* Now process the queue */
4113 while (flow_head != flow_tail)
4117 /* Extract the next entry */
4118 ty = temp_y[flow_tail];
4119 tx = temp_x[flow_tail];
4121 /* Forget that entry */
4122 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4124 /* Add the "children" */
4125 for (d = 0; d < 8; d++)
4127 int old_head = flow_head;
4128 int m = cave[ty][tx].cost + 1;
4129 int n = cave[ty][tx].dist + 1;
4132 /* Child location */
4133 y = ty + ddy_ddd[d];
4134 x = tx + ddx_ddd[d];
4136 /* Ignore player's grid */
4137 if (player_bold(y, x)) continue;
4139 c_ptr = &cave[y][x];
4141 if (is_closed_door(c_ptr->feat)) m += 3;
4143 /* Ignore "pre-stamped" entries */
4144 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4146 /* Ignore "walls" and "rubble" */
4147 if (!have_flag(f_flags_grid(c_ptr), FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4149 /* Save the flow cost */
4150 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4151 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4153 /* Hack -- limit flow depth */
4154 if (n == MONSTER_FLOW_DEPTH) continue;
4156 /* Enqueue that entry */
4157 temp_y[flow_head] = y;
4158 temp_x[flow_head] = x;
4160 /* Advance the queue */
4161 if (++flow_head == TEMP_MAX) flow_head = 0;
4163 /* Hack -- notice overflow by forgetting new entry */
4164 if (flow_head == flow_tail) flow_head = old_head;
4170 static int scent_when = 0;
4173 * Characters leave scent trails for perceptive monsters to track.
4175 * Smell is rather more limited than sound. Many creatures cannot use
4176 * it at all, it doesn't extend very far outwards from the character's
4177 * current position, and monsters can use it to home in the character,
4178 * but not to run away from him.
4180 * Smell is valued according to age. When a character takes his turn,
4181 * scent is aged by one, and new scent of the current age is laid down.
4182 * Speedy characters leave more scent, true, but it also ages faster,
4183 * which makes it harder to hunt them down.
4185 * Whenever the age count loops, most of the scent trail is erased and
4186 * the age of the remainder is recalculated.
4188 void update_smell(void)
4193 /* Create a table that controls the spread of scent */
4194 const int scent_adjust[5][5] =
4203 /* Loop the age and adjust scent values when necessary */
4204 if (++scent_when == 254)
4206 /* Scan the entire dungeon */
4207 for (y = 0; y < cur_hgt; y++)
4209 for (x = 0; x < cur_wid; x++)
4211 int w = cave[y][x].when;
4212 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4221 /* Lay down new scent */
4222 for (i = 0; i < 5; i++)
4224 for (j = 0; j < 5; j++)
4228 /* Translate table to map grids */
4233 if (!in_bounds(y, x)) continue;
4235 c_ptr = &cave[y][x];
4237 /* Walls, water, and lava cannot hold scent. */
4238 if (!have_flag(f_flags_grid(c_ptr), FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4240 /* Grid must not be blocked by walls from the character */
4241 if (!player_has_los_bold(y, x)) continue;
4243 /* Note grids that are too far away */
4244 if (scent_adjust[i][j] == -1) continue;
4246 /* Mark the grid with new scent */
4247 c_ptr->when = scent_when + scent_adjust[i][j];
4254 * Hack -- map the current panel (plus some) ala "magic mapping"
4256 void map_area(int range)
4261 feature_type *f_ptr;
4263 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4265 /* Scan that area */
4266 for (y = 1; y < cur_hgt - 1; y++)
4268 for (x = 1; x < cur_wid - 1; x++)
4270 if (distance(py, px, y, x) > range) continue;
4272 c_ptr = &cave[y][x];
4274 /* Feature code (applying "mimic" field) */
4275 feat = get_feat_mimic(c_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 c_ptr->info |= (CAVE_MARK);
4288 /* Memorize known walls */
4289 for (i = 0; i < 8; i++)
4291 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4293 /* Feature code (applying "mimic" field) */
4294 feat = get_feat_mimic(c_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 c_ptr->info |= (CAVE_MARK);
4309 p_ptr->redraw |= (PR_MAP);
4312 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4318 * Light up the dungeon using "clairvoyance"
4320 * This function "illuminates" every grid in the dungeon, memorizes all
4321 * "objects", memorizes all grids as with magic mapping, and, under the
4322 * standard option settings (view_perma_grids but not view_torch_grids)
4323 * memorizes all floor grids too.
4325 * Note that if "view_perma_grids" is not set, we do not memorize floor
4326 * grids, since this would defeat the purpose of "view_perma_grids", not
4327 * that anyone seems to play without this option.
4329 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4330 * since this would prevent the use of "view_torch_grids" as a method to
4331 * keep track of what grids have been observed directly.
4333 void wiz_lite(bool ninja)
4337 feature_type *f_ptr;
4339 /* Memorize objects */
4340 for (i = 1; i < o_max; i++)
4342 object_type *o_ptr = &o_list[i];
4344 /* Skip dead objects */
4345 if (!o_ptr->k_idx) continue;
4347 /* Skip held objects */
4348 if (o_ptr->held_m_idx) continue;
4351 o_ptr->marked |= OM_FOUND;
4354 /* Scan all normal grids */
4355 for (y = 1; y < cur_hgt - 1; y++)
4357 /* Scan all normal grids */
4358 for (x = 1; x < cur_wid - 1; x++)
4360 cave_type *c_ptr = &cave[y][x];
4362 /* Feature code (applying "mimic" field) */
4363 feat = get_feat_mimic(c_ptr);
4364 f_ptr = &f_info[feat];
4366 /* Process all non-walls */
4367 if (!have_flag(f_ptr->flags, FF_WALL))
4369 /* Scan all neighbors */
4370 for (i = 0; i < 9; i++)
4372 int yy = y + ddy_ddd[i];
4373 int xx = x + ddx_ddd[i];
4376 c_ptr = &cave[yy][xx];
4378 /* Feature code (applying "mimic" field) */
4379 f_ptr = &f_info[get_feat_mimic(c_ptr)];
4381 /* Perma-lite the grid */
4382 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS) && !ninja)
4384 c_ptr->info |= (CAVE_GLOW);
4387 /* Memorize normal features */
4388 if (have_flag(f_ptr->flags, FF_REMEMBER))
4390 /* Memorize the grid */
4391 c_ptr->info |= (CAVE_MARK);
4394 /* Perma-lit grids (newly and previously) */
4395 else if (c_ptr->info & CAVE_GLOW)
4397 /* Normally, memorize floors (see above) */
4398 if (view_perma_grids && !view_torch_grids)
4400 /* Memorize the grid */
4401 c_ptr->info |= (CAVE_MARK);
4409 /* Update the monsters */
4410 p_ptr->update |= (PU_MONSTERS);
4413 p_ptr->redraw |= (PR_MAP);
4416 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4421 * Forget the dungeon map (ala "Thinking of Maud...").
4428 /* Forget every grid */
4429 for (y = 1; y < cur_hgt - 1; y++)
4431 for (x = 1; x < cur_wid - 1; x++)
4433 cave_type *c_ptr = &cave[y][x];
4435 /* Process the grid */
4436 c_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT);
4437 c_ptr->info |= (CAVE_UNSAFE);
4441 /* Forget every grid on horizontal edge */
4442 for (x = 0; x < cur_wid; x++)
4444 cave[0][x].info &= ~(CAVE_MARK);
4445 cave[cur_hgt - 1][x].info &= ~(CAVE_MARK);
4448 /* Forget every grid on vertical edge */
4449 for (y = 1; y < (cur_hgt - 1); y++)
4451 cave[y][0].info &= ~(CAVE_MARK);
4452 cave[y][cur_wid - 1].info &= ~(CAVE_MARK);
4455 /* Forget all objects */
4456 for (i = 1; i < o_max; i++)
4458 object_type *o_ptr = &o_list[i];
4460 /* Skip dead objects */
4461 if (!o_ptr->k_idx) continue;
4463 /* Skip held objects */
4464 if (o_ptr->held_m_idx) continue;
4466 /* Forget the object */
4470 /* Mega-Hack -- Forget the view and lite */
4471 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4473 /* Update the view and lite */
4474 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4476 /* Update the monsters */
4477 p_ptr->update |= (PU_MONSTERS);
4480 p_ptr->redraw |= (PR_MAP);
4483 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4491 * Change the "feat" flag for a grid, and notice/redraw the grid
4493 void cave_set_feat(int y, int x, int feat)
4495 cave_type *c_ptr = &cave[y][x];
4496 feature_type *f_ptr = &f_info[feat];
4498 if (character_dungeon && is_mirror_grid(c_ptr) && (d_info[dungeon_type].flags1 & DF1_DARKNESS))
4500 c_ptr->info &= ~(CAVE_GLOW);
4501 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4503 /* Remove flag for mirror/glyph */
4504 c_ptr->info &= ~(CAVE_OBJECT);
4506 update_local_illumination(y, x);
4509 /* Clear mimic type */
4512 /* Change the feature */
4515 if (character_dungeon)
4517 /* Check for change to boring grid */
4518 if (!have_flag(f_ptr->flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
4520 /* Check for change to out of sight grid */
4521 else if (!player_can_see_bold(y, x)) c_ptr->info &= ~(CAVE_MARK);
4523 /* Update the monster */
4524 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4533 /* Hack -- glow the deep lava */
4534 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4539 for (i = 0; i < 9; i++)
4541 yy = y + ddy_ddd[i];
4542 xx = x + ddx_ddd[i];
4543 if (!in_bounds2(yy, xx)) continue;
4544 cc_ptr = &cave[yy][xx];
4545 cc_ptr->info |= CAVE_GLOW;
4546 if (character_dungeon)
4548 if (player_has_los_grid(cc_ptr))
4550 /* Update the monster */
4551 if (cc_ptr->m_idx) update_mon(cc_ptr->m_idx, FALSE);
4560 update_local_illumination(yy, xx);
4567 int conv_dungeon_feat(int newfeat)
4569 feature_type *f_ptr = &f_info[newfeat];
4571 if (have_flag(f_ptr->flags, FF_CONVERT))
4573 switch (f_ptr->power)
4575 case CONVERT_TYPE_FLOOR:
4576 return floor_type[randint0(100)];
4577 case CONVERT_TYPE_WALL:
4578 return fill_type[randint0(100)];
4579 case CONVERT_TYPE_INNER:
4580 return feat_wall_inner;
4581 case CONVERT_TYPE_OUTER:
4582 return feat_wall_outer;
4583 case CONVERT_TYPE_SOLID:
4584 return feat_wall_solid;
4585 case CONVERT_TYPE_STREAM1:
4586 return d_info[dungeon_type].stream1;
4587 case CONVERT_TYPE_STREAM2:
4588 return d_info[dungeon_type].stream2;
4593 else return newfeat;
4598 * Take a feature, determine what that feature becomes
4599 * through applying the given action.
4601 int feat_state(int feat, int action)
4603 feature_type *f_ptr = &f_info[feat];
4606 /* Get the new feature */
4607 for (i = 0; i < MAX_FEAT_STATES; i++)
4609 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
4612 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
4614 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
4618 * Takes a location and action and changes the feature at that
4619 * location through applying the given action.
4621 void cave_alter_feat(int y, int x, int action)
4623 /* Set old feature */
4624 int oldfeat = cave[y][x].feat;
4626 /* Get the new feat */
4627 int newfeat = feat_state(oldfeat, action);
4630 if (newfeat == oldfeat) return;
4632 /* Set the new feature */
4633 cave_set_feat(y, x, newfeat);
4635 if (!(feature_action_flags[action] & FAF_NO_DROP))
4637 feature_type *old_f_ptr = &f_info[oldfeat];
4638 feature_type *f_ptr = &f_info[newfeat];
4642 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
4644 /* Place some gold */
4650 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - dun_level / 2)))
4653 place_object(y, x, 0L);
4657 if (found && character_dungeon && player_can_see_bold(y, x))
4660 msg_print("²¿¤«¤òȯ¸«¤·¤¿¡ª");
4662 msg_print("You have found something!");
4669 /* Remove a mirror */
4670 void remove_mirror(int y, int x)
4672 cave_type *c_ptr = &cave[y][x];
4674 /* Remove the mirror */
4675 c_ptr->info &= ~(CAVE_OBJECT);
4678 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4680 c_ptr->info &= ~(CAVE_GLOW);
4681 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4683 /* Update the monster */
4684 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4686 update_local_illumination(y, x);
4698 * Return TRUE if there is a mirror on the grid.
4700 bool is_mirror_grid(cave_type *c_ptr)
4702 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MIRROR))
4710 * Return TRUE if there is a mirror on the grid.
4712 bool is_glyph_grid(cave_type *c_ptr)
4714 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_GLYPH))
4722 * Return TRUE if there is a mirror on the grid.
4724 bool is_explosive_rune_grid(cave_type *c_ptr)
4726 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MINOR_GLYPH))
4734 * Calculate "incremental motion". Used by project() and shoot().
4735 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4737 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4739 int dy, dx, dist, shift;
4741 /* Extract the distance travelled */
4742 dy = (*y < y1) ? y1 - *y : *y - y1;
4743 dx = (*x < x1) ? x1 - *x : *x - x1;
4745 /* Number of steps */
4746 dist = (dy > dx) ? dy : dx;
4748 /* We are calculating the next location */
4752 /* Calculate the total distance along each axis */
4753 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4754 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4756 /* Paranoia -- Hack -- no motion */
4757 if (!dy && !dx) return;
4760 /* Move mostly vertically */
4763 /* Extract a shift factor */
4764 shift = (dist * dx + (dy - 1) / 2) / dy;
4766 /* Sometimes move along the minor axis */
4767 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4769 /* Always move along major axis */
4770 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4773 /* Move mostly horizontally */
4776 /* Extract a shift factor */
4777 shift = (dist * dy + (dx - 1) / 2) / dx;
4779 /* Sometimes move along the minor axis */
4780 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4782 /* Always move along major axis */
4783 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4790 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4791 * at the final destination, assuming no monster gets in the way.
4793 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4795 bool projectable(int y1, int x1, int y2, int x2)
4802 /* Check the projection path */
4803 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4805 /* Identical grid */
4806 if (!grid_n) return TRUE;
4809 y = GRID_Y(grid_g[grid_n - 1]);
4810 x = GRID_X(grid_g[grid_n - 1]);
4812 /* May not end in an unrequested grid */
4813 if ((y != y2) || (x != x2)) return (FALSE);
4821 * Standard "find me a location" function
4823 * Obtains a legal location within the given distance of the initial
4824 * location, and with "los()" from the source to destination location.
4826 * This function is often called from inside a loop which searches for
4827 * locations while increasing the "d" distance.
4829 * Currently the "m" parameter is unused.
4831 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4838 /* Pick a location */
4841 /* Pick a new location */
4842 ny = rand_spread(y, d);
4843 nx = rand_spread(x, d);
4845 /* Ignore annoying locations */
4846 if (!in_bounds(ny, nx)) continue;
4848 /* Ignore "excessively distant" locations */
4849 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4851 /* Require "line of projection" */
4852 if (projectable(y, x, ny, nx)) break;
4855 /* Save the location */
4864 * Track a new monster
4866 void health_track(int m_idx)
4868 /* Mount monster is already tracked */
4869 if (m_idx && m_idx == p_ptr->riding) return;
4871 /* Track a new guy */
4872 p_ptr->health_who = m_idx;
4874 /* Redraw (later) */
4875 p_ptr->redraw |= (PR_HEALTH);
4881 * Hack -- track the given monster race
4883 void monster_race_track(int r_idx)
4885 /* Save this monster ID */
4886 p_ptr->monster_race_idx = r_idx;
4889 p_ptr->window |= (PW_MONSTER);
4895 * Hack -- track the given object kind
4897 void object_kind_track(int k_idx)
4899 /* Save this monster ID */
4900 p_ptr->object_kind_idx = k_idx;
4903 p_ptr->window |= (PW_OBJECT);
4909 * Something has happened to disturb the player.
4911 * The first arg indicates a major disturbance, which affects search.
4913 * The second arg is currently unused, but could induce output flush.
4915 * All disturbance cancels repeated commands, resting, and running.
4917 void disturb(int stop_search, int unused_flag)
4920 unused_flag = unused_flag;
4922 /* Cancel auto-commands */
4923 /* command_new = 0; */
4925 /* Cancel repeated commands */
4931 /* Redraw the state (later) */
4932 p_ptr->redraw |= (PR_STATE);
4935 /* Cancel Resting */
4936 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
4939 set_action(ACTION_NONE);
4942 /* Cancel running */
4948 /* Check for new panel if appropriate */
4949 if (center_player && !center_running) verify_panel();
4951 /* Calculate torch radius */
4952 p_ptr->update |= (PU_TORCH);
4954 /* Update monster flow */
4955 p_ptr->update |= (PU_FLOW);
4958 /* Flush the input if requested */
4959 if (flush_disturb) flush();
4964 * Glow deep lava and building entrances in the floor
4966 void glow_deep_lava_and_bldg(void)
4968 int y, x, i, yy, xx;
4971 /* Not in the darkness dungeon */
4972 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
4974 for (y = 0; y < cur_hgt; y++)
4976 for (x = 0; x < cur_wid; x++)
4978 c_ptr = &cave[y][x];
4980 /* Feature code (applying "mimic" field) */
4982 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_GLOW))
4984 for (i = 0; i < 9; i++)
4986 yy = y + ddy_ddd[i];
4987 xx = x + ddx_ddd[i];
4988 if (!in_bounds2(yy, xx)) continue;
4989 cave[yy][xx].info |= CAVE_GLOW;
4995 /* Update the view and lite */
4996 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4999 p_ptr->redraw |= (PR_MAP);