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 && !cave_have_flag_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 || cave_have_flag_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;
371 #define COMPLEX_WALL_ILLUMINATION
374 * Check for "local" illumination
376 static bool check_local_illumination(int y, int x)
378 /* Hack -- move towards player */
379 int yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
380 int xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
382 /* Check for "local" illumination */
384 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
386 /* Check for "complex" illumination */
387 if ((feat_supports_los(get_feat_mimic(&cave[yy][xx])) &&
388 (cave[yy][xx].info & CAVE_GLOW)) ||
389 (feat_supports_los(get_feat_mimic(&cave[y][xx])) &&
390 (cave[y][xx].info & CAVE_GLOW)) ||
391 (feat_supports_los(get_feat_mimic(&cave[yy][x])) &&
392 (cave[yy][x].info & CAVE_GLOW)))
398 #else /* COMPLEX_WALL_ILLUMINATION */
400 /* Check for "simple" illumination */
401 return (cave[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
403 #endif /* COMPLEX_WALL_ILLUMINATION */
407 #define update_local_illumination_aux(Y, X) \
409 if (player_has_los_bold((Y), (X))) \
411 /* Update the monster */ \
412 if (cave[(Y)][(X)].m_idx) update_mon(cave[(Y)][(X)].m_idx, FALSE); \
414 /* Notice and redraw */ \
415 note_spot((Y), (X)); \
416 lite_spot((Y), (X)); \
422 * Update "local" illumination
424 void update_local_illumination(int y, int x)
428 if (!in_bounds(y, x)) return;
430 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
432 if ((y != py) && (x != px))
434 yy = (y < py) ? (y - 1) : (y + 1);
435 xx = (x < px) ? (x - 1) : (x + 1);
436 update_local_illumination_aux(yy, xx);
437 update_local_illumination_aux(y, xx);
438 update_local_illumination_aux(yy, x);
440 else if (x != px) /* y == py */
442 xx = (x < px) ? (x - 1) : (x + 1);
443 for (i = -1; i <= 1; i++)
446 update_local_illumination_aux(yy, xx);
449 update_local_illumination_aux(yy, x);
451 update_local_illumination_aux(yy, x);
453 else if (y != py) /* x == px */
455 yy = (y < py) ? (y - 1) : (y + 1);
456 for (i = -1; i <= 1; i++)
459 update_local_illumination_aux(yy, xx);
462 update_local_illumination_aux(y, xx);
464 update_local_illumination_aux(y, xx);
466 else /* Player's grid */
468 for (i = 0; i < 8; i++)
472 update_local_illumination_aux(yy, xx);
476 #else /* COMPLEX_WALL_ILLUMINATION */
478 if ((y != py) && (x != px))
480 yy = (y < py) ? (y - 1) : (y + 1);
481 xx = (x < px) ? (x - 1) : (x + 1);
482 update_local_illumination_aux(yy, xx);
484 else if (x != px) /* y == py */
486 xx = (x < px) ? (x - 1) : (x + 1);
487 for (i = -1; i <= 1; i++)
490 update_local_illumination_aux(yy, xx);
493 else if (y != py) /* x == px */
495 yy = (y < py) ? (y - 1) : (y + 1);
496 for (i = -1; i <= 1; i++)
499 update_local_illumination_aux(yy, xx);
502 else /* Player's grid */
504 for (i = 0; i < 8; i++)
508 update_local_illumination_aux(yy, xx);
512 #endif /* COMPLEX_WALL_ILLUMINATION */
517 * Can the player "see" the given grid in detail?
519 * He must have vision, illumination, and line of sight.
521 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
522 * So, given "CAVE_LITE", we know that the grid is "fully visible".
524 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
525 * that a wall is visible from any direction. That would be odd. Except
526 * under wizard light, which might make sense. Thus, for walls, we require
527 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
528 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
529 * in line of sight of the player.
531 * This extra check is expensive, but it provides a more "correct" semantics.
533 * Note that we should not run this check on walls which are "outer walls" of
534 * the dungeon, or we will induce a memory fault, but actually verifying all
535 * of the locations would be extremely expensive.
537 * Thus, to speed up the function, we assume that all "perma-walls" which are
538 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
539 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
540 * and the player has more important things on his mind when he is attacking a
541 * monster vault. It is annoying, but an extremely important optimization.
543 * Note that "glowing walls" are only considered to be "illuminated" if the
544 * grid which is next to the wall in the direction of the player is also a
545 * "glowing" grid. This prevents the player from being able to "see" the
546 * walls of illuminated rooms from a corridor outside the room.
548 bool player_can_see_bold(int y, int x)
552 /* Blind players see nothing */
553 if (p_ptr->blind) return FALSE;
555 /* Access the cave grid */
558 /* Note that "torch-lite" yields "illumination" */
559 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
561 /* Require line of sight to the grid */
562 if (!player_has_los_bold(y, x)) return FALSE;
564 /* Noctovision of Ninja */
565 if (p_ptr->see_nocto) return TRUE;
567 /* Require "perma-lite" of the grid */
568 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
570 /* Feature code (applying "mimic" field) */
571 /* Floors are simple */
572 if (feat_supports_los(get_feat_mimic(c_ptr))) return TRUE;
574 /* Check for "local" illumination */
575 return check_local_illumination(y, x);
581 * Returns true if the player's grid is dark
585 return (!player_can_see_bold(py, px));
592 * Determine if a given location may be "destroyed"
594 * Used by destruction spells, and for placing stairs, etc.
596 bool cave_valid_bold(int y, int x)
598 cave_type *c_ptr = &cave[y][x];
600 s16b this_o_idx, next_o_idx = 0;
603 /* Forbid perma-grids */
604 if (cave_perma_grid(c_ptr)) return (FALSE);
607 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
612 o_ptr = &o_list[this_o_idx];
614 /* Acquire next object */
615 next_o_idx = o_ptr->next_o_idx;
617 /* Forbid artifact grids */
618 if (object_is_artifact(o_ptr)) return (FALSE);
629 * Hack -- Legal monster codes
631 static char image_monster_hack[] = \
632 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
635 * Hack -- Legal object codes
637 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
640 * Mega-Hack -- Hallucinatory monster
642 static void image_monster(byte *ap, char *cp)
644 /* Random symbol from set above */
647 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
656 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
657 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
666 * Mega-Hack -- Hallucinatory object
668 static void image_object(byte *ap, char *cp)
672 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
679 int n = sizeof(image_object_hack) - 1;
681 *cp = image_object_hack[randint0(n)];
691 * Hack -- Random hallucination
693 static void image_random(byte *ap, char *cp)
695 /* Normally, assume monsters */
696 if (randint0(100) < 75)
698 image_monster(ap, cp);
701 /* Otherwise, assume objects */
704 image_object(ap, cp);
709 * This array lists the effects of "brightness" on various "base" colours.
711 * This is used to do dynamic lighting effects in ascii :-)
712 * At the moment, only the various "floor" tiles are affected.
714 * The layout of the array is [x][0] = light and [x][1] = dark.
717 static byte lighting_colours[16][2] =
720 {TERM_L_DARK, TERM_DARK},
723 {TERM_YELLOW, TERM_SLATE},
726 {TERM_WHITE, TERM_L_DARK},
729 {TERM_L_UMBER, TERM_UMBER},
732 {TERM_RED, TERM_RED},
735 {TERM_L_GREEN, TERM_GREEN},
738 {TERM_BLUE, TERM_BLUE},
741 {TERM_L_UMBER, TERM_RED},
744 {TERM_SLATE, TERM_L_DARK},
747 {TERM_WHITE, TERM_SLATE},
750 {TERM_L_RED, TERM_BLUE},
753 {TERM_YELLOW, TERM_ORANGE},
756 {TERM_L_RED, TERM_L_RED},
759 {TERM_L_GREEN, TERM_GREEN},
762 {TERM_L_BLUE, TERM_L_BLUE},
765 {TERM_L_UMBER, TERM_UMBER}
770 * Apply "default" feature lighting effects
772 void apply_default_feat_lighting(byte f_attr[F_LIT_MAX], byte f_char[F_LIT_MAX])
774 byte s_attr = f_attr[F_LIT_STANDARD];
775 byte s_char = f_char[F_LIT_STANDARD];
778 if (is_ascii_graphics(s_attr)) /* For ASCII */
780 f_attr[F_LIT_LITE] = lighting_colours[s_attr & 0x0f][0];
781 f_attr[F_LIT_DARK] = lighting_colours[s_attr & 0x0f][1];
782 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_char[i] = s_char;
784 else /* For tile graphics */
786 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_attr[i] = s_attr;
787 f_char[F_LIT_LITE] = s_char + 2;
788 f_char[F_LIT_DARK] = s_char + 1;
793 /* Is this grid "darkened" by monster? */
794 #define darkened_grid(C) \
795 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
800 * Extract the attr/char to display at the given (legal) map location
802 * Basically, we "paint" the chosen attr/char in several passes, starting
803 * with any known "terrain features" (defaulting to darkness), then adding
804 * any known "objects", and finally, adding any known "monsters". This
805 * is not the fastest method but since most of the calls to this function
806 * are made for grids with no monsters or objects, it is fast enough.
808 * Note that this function, if used on the grid containing the "player",
809 * will return the attr/char of the grid underneath the player, and not
810 * the actual player attr/char itself, allowing a lot of optimization
811 * in various "display" functions.
813 * Note that the "zero" entry in the feature/object/monster arrays are
814 * used to provide "special" attr/char codes, with "monster zero" being
815 * used for the player attr/char, "object zero" being used for the "stack"
816 * attr/char, and "feature zero" being used for the "nothing" attr/char,
817 * though this function makes use of only "feature zero".
819 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
820 * which means their color changes, and "ATTR_CLEAR", which means they take
821 * the color of whatever is under them, and "CHAR_CLEAR", which means that
822 * they take the symbol of whatever is under them. Technically, the flag
823 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
824 * examined, but this flag is currently ignored.
826 * Currently, we do nothing with multi-hued objects, because there are
827 * not any. If there were, they would have to set "shimmer_objects"
828 * when they were created, and then new "shimmer" code in "dungeon.c"
829 * would have to be created handle the "shimmer" effect, and the code
830 * in "cave.c" would have to be updated to create the shimmer effect.
832 * Note the effects of hallucination. Objects always appear as random
833 * "objects", monsters as random "monsters", and normal grids occasionally
834 * appear as random "monsters" or "objects", but note that these random
835 * "monsters" and "objects" are really just "colored ascii symbols".
837 * Note that "floors" and "invisible traps" (and "zero" features) are
838 * drawn as "floors" using a special check for optimization purposes,
839 * and these are the only features which get drawn using the special
840 * lighting effects activated by "view_special_lite".
842 * Note the use of the "mimic" field in the "terrain feature" processing,
843 * which allows any feature to "pretend" to be another feature. This is
844 * used to "hide" secret doors, and to make all "doors" appear the same,
845 * and all "walls" appear the same, and "hidden" treasure stay hidden.
846 * It is possible to use this field to make a feature "look" like a floor,
847 * but the "special lighting effects" for floors will not be used.
849 * Note the use of the new "terrain feature" information. Note that the
850 * assumption that all interesting "objects" and "terrain features" are
851 * memorized allows extremely optimized processing below. Note the use
852 * of separate flags on objects to mark them as memorized allows a grid
853 * to have memorized "terrain" without granting knowledge of any object
854 * which may appear in that grid.
856 * Note the efficient code used to determine if a "floor" grid is
857 * "memorized" or "viewable" by the player, where the test for the
858 * grid being "viewable" is based on the facts that (1) the grid
859 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
860 * line of sight, and (3) the player must not be blind, and uses the
861 * assumption that all torch-lit grids are in line of sight.
863 * Note that floors (and invisible traps) are the only grids which are
864 * not memorized when seen, so only these grids need to check to see if
865 * the grid is "viewable" to the player (if it is not memorized). Since
866 * most non-memorized grids are in fact walls, this induces *massive*
867 * efficiency, at the cost of *forcing* the memorization of non-floor
868 * grids when they are first seen. Note that "invisible traps" are
869 * always treated exactly like "floors", which prevents "cheating".
871 * Note the "special lighting effects" which can be activated for floor
872 * grids using the "view_special_lite" option (for "white" floor grids),
873 * causing certain grids to be displayed using special colors. If the
874 * player is "blind", we will use "dark gray", else if the grid is lit
875 * by the torch, and the "view_yellow_lite" option is set, we will use
876 * "yellow", else if the grid is "dark", we will use "dark gray", else
877 * if the grid is not "viewable", and the "view_bright_lite" option is
878 * set, and the we will use "slate" (gray). We will use "white" for all
879 * other cases, in particular, for illuminated viewable floor grids.
881 * Note the "special lighting effects" which can be activated for wall
882 * grids using the "view_granite_lite" option (for "white" wall grids),
883 * causing certain grids to be displayed using special colors. If the
884 * player is "blind", we will use "dark gray", else if the grid is lit
885 * by the torch, and the "view_yellow_lite" option is set, we will use
886 * "yellow", else if the "view_bright_lite" option is set, and the grid
887 * is not "viewable", or is "dark", or is glowing, but not when viewed
888 * from the player's current location, we will use "slate" (gray). We
889 * will use "white" for all other cases, in particular, for correctly
890 * illuminated viewable wall grids.
892 * Note that, when "view_granite_lite" is set, we use an inline version
893 * of the "player_can_see_bold()" function to check the "viewability" of
894 * grids when the "view_bright_lite" option is set, and we do NOT use
895 * any special colors for "dark" wall grids, since this would allow the
896 * player to notice the walls of illuminated rooms from a hallway that
897 * happened to run beside the room. The alternative, by the way, would
898 * be to prevent the generation of hallways next to rooms, but this
899 * would still allow problems when digging towards a room.
901 * Note that bizarre things must be done when the "attr" and/or "char"
902 * codes have the "high-bit" set, since these values are used to encode
903 * various "special" pictures in some versions, and certain situations,
904 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
905 * to be "scrambled" in various ways.
907 * Note that eventually we may use the "&" symbol for embedded treasure,
908 * and use the "*" symbol to indicate multiple objects, though this will
909 * have to wait for Angband 2.8.0 or later. Note that currently, this
910 * is not important, since only one object or terrain feature is allowed
911 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
913 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
914 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
915 * then a whole lot of code should be changed... XXX XXX
917 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
920 cave_type *c_ptr = &cave[y][x];
922 s16b this_o_idx, next_o_idx = 0;
924 /* Feature code (applying "mimic" field) */
925 s16b feat = get_feat_mimic(c_ptr);
928 feature_type *f_ptr = &f_info[feat];
933 /* Boring grids (floors, etc) */
934 if (!have_flag(f_ptr->flags, FF_REMEMBER))
937 * Handle Memorized or visible floor
939 * No visual when blinded.
940 * (to prevent strange effects on darkness breath)
942 * - Can see grids with CAVE_MARK.
943 * - Can see grids with CAVE_LITE or CAVE_MNLT.
944 * (Such grids also have CAVE_VIEW)
945 * - Can see grids with CAVE_VIEW unless darkened by monsters.
948 ((c_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
949 ((c_ptr->info & CAVE_VIEW) && (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
951 /* Normal attr/char */
952 a = f_ptr->x_attr[F_LIT_STANDARD];
953 c = f_ptr->x_char[F_LIT_STANDARD];
955 if (p_ptr->wild_mode)
957 /* Special lighting effects */
959 if (view_special_lite && !is_daytime())
961 /* Use a darkened colour/tile */
962 a = f_ptr->x_attr[F_LIT_DARK];
963 c = f_ptr->x_char[F_LIT_DARK];
967 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
968 else if (darkened_grid(c_ptr))
970 /* Unsafe cave grid -- idea borrowed from Unangband */
971 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? FEAT_UNDETECTED : FEAT_NONE;
973 /* Access darkness */
974 f_ptr = &f_info[feat];
976 /* Char and attr of darkness */
977 a = f_ptr->x_attr[F_LIT_STANDARD];
978 c = f_ptr->x_char[F_LIT_STANDARD];
981 /* Special lighting effects */
982 else if (view_special_lite)
984 /* Handle "torch-lit" grids */
985 if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
988 if (view_yellow_lite)
990 /* Use a brightly lit colour/tile */
991 a = f_ptr->x_attr[F_LIT_LITE];
992 c = f_ptr->x_char[F_LIT_LITE];
996 /* Handle "dark" grids */
997 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
999 /* Use a darkened colour/tile */
1000 a = f_ptr->x_attr[F_LIT_DARK];
1001 c = f_ptr->x_char[F_LIT_DARK];
1004 /* Handle "out-of-sight" grids */
1005 else if (!(c_ptr->info & CAVE_VIEW))
1008 if (view_bright_lite)
1010 /* Use a darkened colour/tile */
1011 a = f_ptr->x_attr[F_LIT_DARK];
1012 c = f_ptr->x_char[F_LIT_DARK];
1021 /* Unsafe cave grid -- idea borrowed from Unangband */
1022 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1023 feat = FEAT_UNDETECTED;
1027 /* Access darkness */
1028 f_ptr = &f_info[feat];
1030 /* Normal attr/char */
1031 a = f_ptr->x_attr[F_LIT_STANDARD];
1032 c = f_ptr->x_char[F_LIT_STANDARD];
1036 /* Interesting grids (non-floors) */
1039 /* Memorized grids */
1040 if (c_ptr->info & CAVE_MARK)
1042 /* Normal attr/char */
1043 a = f_ptr->x_attr[F_LIT_STANDARD];
1044 c = f_ptr->x_char[F_LIT_STANDARD];
1046 if (p_ptr->wild_mode)
1048 /* Special lighting effects */
1049 /* Handle "blind" or "night" */
1050 if (view_granite_lite && (p_ptr->blind || !is_daytime()))
1052 /* Use a darkened colour/tile */
1053 a = f_ptr->x_attr[F_LIT_DARK];
1054 c = f_ptr->x_char[F_LIT_DARK];
1058 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1059 else if (darkened_grid(c_ptr) && !p_ptr->blind)
1061 if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
1063 /* Unsafe cave grid -- idea borrowed from Unangband */
1064 feat = (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) ? FEAT_UNDETECTED : FEAT_NONE;
1066 /* Access darkness */
1067 f_ptr = &f_info[feat];
1069 /* Char and attr of darkness */
1070 a = f_ptr->x_attr[F_LIT_STANDARD];
1071 c = f_ptr->x_char[F_LIT_STANDARD];
1073 else if (view_granite_lite && view_bright_lite)
1075 /* Use a darkened colour/tile */
1076 a = f_ptr->x_attr[F_LIT_DARK];
1077 c = f_ptr->x_char[F_LIT_DARK];
1081 /* Special lighting effects */
1082 else if (view_granite_lite)
1084 /* Handle "blind" */
1087 /* Use a darkened colour/tile */
1088 a = f_ptr->x_attr[F_LIT_DARK];
1089 c = f_ptr->x_char[F_LIT_DARK];
1092 /* Handle "torch-lit" grids */
1093 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1096 if (view_yellow_lite)
1098 /* Use a brightly lit colour/tile */
1099 a = f_ptr->x_attr[F_LIT_LITE];
1100 c = f_ptr->x_char[F_LIT_LITE];
1104 /* Handle "view_bright_lite" */
1105 else if (view_bright_lite)
1108 if (!(c_ptr->info & CAVE_VIEW))
1110 /* Use a darkened colour/tile */
1111 a = f_ptr->x_attr[F_LIT_DARK];
1112 c = f_ptr->x_char[F_LIT_DARK];
1116 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1118 /* Use a darkened colour/tile */
1119 a = f_ptr->x_attr[F_LIT_DARK];
1120 c = f_ptr->x_char[F_LIT_DARK];
1123 /* Not glowing correctly */
1124 else if (!have_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(y, x))
1126 /* Use a darkened colour/tile */
1127 a = f_ptr->x_attr[F_LIT_DARK];
1128 c = f_ptr->x_char[F_LIT_DARK];
1137 /* Unsafe cave grid -- idea borrowed from Unangband */
1138 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1139 feat = FEAT_UNDETECTED;
1143 /* Access feature */
1144 f_ptr = &f_info[feat];
1146 /* Normal attr/char */
1147 a = f_ptr->x_attr[F_LIT_STANDARD];
1148 c = f_ptr->x_char[F_LIT_STANDARD];
1152 if (feat_priority == -1) feat_priority = f_ptr->priority;
1154 /* Save the terrain info for the transparency effects */
1162 /* Hack -- rare random hallucination, except on outer dungeon walls */
1168 image_random(ap, cp);
1173 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1177 /* Acquire object */
1178 o_ptr = &o_list[this_o_idx];
1180 /* Acquire next object */
1181 next_o_idx = o_ptr->next_o_idx;
1183 /* Memorized objects */
1184 if (o_ptr->marked & OM_FOUND)
1186 if (display_autopick)
1190 match_autopick = is_autopick(o_ptr);
1191 if(match_autopick == -1)
1194 act = autopick_list[match_autopick].action;
1196 if ((act & DO_DISPLAY) && (act & display_autopick))
1198 autopick_obj = o_ptr;
1202 match_autopick = -1;
1207 (*cp) = object_char(o_ptr);
1210 (*ap) = object_attr(o_ptr);
1214 /* Hack -- hallucination */
1215 if (p_ptr->image) image_object(ap, cp);
1223 /* Handle monsters */
1224 if (c_ptr->m_idx && display_autopick == 0 )
1226 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1228 /* Visible monster */
1231 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1239 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1240 * flags are always unseen.
1242 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1248 /* Hallucinatory monster */
1249 image_monster(ap, cp);
1254 /* Monster attr/char */
1258 /* Normal monsters */
1259 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1260 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1262 /* Desired monster attr/char */
1268 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1269 * flags are always unseen.
1271 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1278 /*** Monster's attr ***/
1279 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1284 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1286 /* Multi-hued attr */
1287 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1288 else switch (randint1(7))
1290 case 1: *ap = TERM_RED; break;
1291 case 2: *ap = TERM_L_RED; break;
1292 case 3: *ap = TERM_WHITE; break;
1293 case 4: *ap = TERM_L_GREEN; break;
1294 case 5: *ap = TERM_BLUE; break;
1295 case 6: *ap = TERM_L_DARK; break;
1296 case 7: *ap = TERM_GREEN; break;
1299 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1301 /* Use semi-random attr (usually mimics' colors vary) */
1302 *ap = c_ptr->m_idx % 15 + 1;
1310 /*** Monster's char ***/
1311 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1316 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1320 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1321 *cp = tmp_r_ptr->x_char;
1322 *ap = tmp_r_ptr->x_attr;
1326 *cp = (one_in_(25) ?
1327 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1328 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1341 /* Handle "player" */
1342 if (player_bold(y, x))
1344 monster_race *r_ptr = &r_info[0];
1346 /* Get the "player" attr */
1347 *ap = r_ptr->x_attr;
1349 /* Get the "player" char */
1350 *cp = r_ptr->x_char;
1358 * Calculate panel colum of a location in the map
1360 static int panel_col_of(int col)
1362 col -= panel_col_min;
1363 if (use_bigtile) col *= 2;
1369 * Moves the cursor to a given MAP (y,x) location
1371 void move_cursor_relative(int row, int col)
1373 /* Real co-ords convert to screen positions */
1374 row -= panel_row_prt;
1377 Term_gotoxy(panel_col_of(col), row);
1383 * Place an attr/char pair at the given map coordinate, if legal.
1385 void print_rel(char c, byte a, int y, int x)
1387 /* Only do "legal" locations */
1388 if (panel_contains(y, x))
1390 /* Hack -- fake monochrome */
1393 if (world_monster) a = TERM_DARK;
1394 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1395 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1398 /* Draw the char using the attr */
1399 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, 0, 0);
1408 * Memorize interesting viewable object/features in the given grid
1410 * This function should only be called on "legal" grids.
1412 * This function will memorize the object and/or feature in the given
1413 * grid, if they are (1) viewable and (2) interesting. Note that all
1414 * objects are interesting, all terrain features except floors (and
1415 * invisible traps) are interesting, and floors (and invisible traps)
1416 * are interesting sometimes (depending on various options involving
1417 * the illumination of floor grids).
1419 * The automatic memorization of all objects and non-floor terrain
1420 * features as soon as they are displayed allows incredible amounts
1421 * of optimization in various places, especially "map_info()".
1423 * Note that the memorization of objects is completely separate from
1424 * the memorization of terrain features, preventing annoying floor
1425 * memorization when a detected object is picked up from a dark floor,
1426 * and object memorization when an object is dropped into a floor grid
1427 * which is memorized but out-of-sight.
1429 * This function should be called every time the "memorization" of
1430 * a grid (or the object in a grid) is called into question, such
1431 * as when an object is created in a grid, when a terrain feature
1432 * "changes" from "floor" to "non-floor", when any grid becomes
1433 * "illuminated" or "viewable", and when a "floor" grid becomes
1436 * Note the relatively efficient use of this function by the various
1437 * "update_view()" and "update_lite()" calls, to allow objects and
1438 * terrain features to be memorized (and drawn) whenever they become
1439 * viewable or illuminated in any way, but not when they "maintain"
1440 * or "lose" their previous viewability or illumination.
1442 * Note the butchered "internal" version of "player_can_see_bold()",
1443 * optimized primarily for the most common cases, that is, for the
1444 * non-marked floor grids.
1446 void note_spot(int y, int x)
1448 cave_type *c_ptr = &cave[y][x];
1450 s16b this_o_idx, next_o_idx = 0;
1453 /* Blind players see nothing */
1454 if (p_ptr->blind) return;
1456 /* Analyze non-torch-lit grids */
1457 if (!(c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1459 /* Require line of sight to the grid */
1460 if (!(c_ptr->info & (CAVE_VIEW))) return;
1462 /* Require "perma-lite" of the grid */
1463 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1466 if (!p_ptr->see_nocto) return;
1471 /* Hack -- memorize objects */
1472 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1474 object_type *o_ptr = &o_list[this_o_idx];
1476 /* Acquire next object */
1477 next_o_idx = o_ptr->next_o_idx;
1479 /* Memorize objects */
1480 o_ptr->marked |= OM_FOUND;
1484 /* Hack -- memorize grids */
1485 if (!(c_ptr->info & (CAVE_MARK)))
1487 /* Feature code (applying "mimic" field) */
1488 feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
1490 /* Memorize some "boring" grids */
1491 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1493 /* Option -- memorize all torch-lit floors */
1494 if (view_torch_grids &&
1495 ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1498 c_ptr->info |= (CAVE_MARK);
1501 /* Option -- memorize all perma-lit floors */
1502 else if (view_perma_grids && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1505 c_ptr->info |= (CAVE_MARK);
1509 /* Memorize normal grids */
1510 else if (have_flag(f_ptr->flags, FF_LOS))
1513 c_ptr->info |= (CAVE_MARK);
1516 /* Memorize torch-lit walls */
1517 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1520 c_ptr->info |= (CAVE_MARK);
1523 /* Memorize walls seen by noctovision of Ninja */
1524 else if (p_ptr->see_nocto)
1527 c_ptr->info |= (CAVE_MARK);
1530 /* Memorize certain non-torch-lit wall grids */
1531 else if (check_local_illumination(y, x))
1534 c_ptr->info |= (CAVE_MARK);
1540 void display_dungeon(void)
1549 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1551 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1553 if (in_bounds2(y, x))
1556 /* Examine the grid */
1557 map_info(y, x, &a, &c, &ta, &tc);
1559 /* Hack -- fake monochrome */
1562 if (world_monster) a = TERM_DARK;
1563 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1564 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1567 /* Hack -- Queue it */
1568 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1572 /* Clear out-of-bound tiles */
1574 /* Access darkness */
1575 feature_type *f_ptr = &f_info[FEAT_NONE];
1578 a = f_ptr->x_attr[F_LIT_STANDARD];
1581 c = f_ptr->x_char[F_LIT_STANDARD];
1583 /* Hack -- Queue it */
1584 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1592 * Redraw (on the screen) a given MAP location
1594 * This function should only be called on "legal" grids
1596 void lite_spot(int y, int x)
1598 /* Redraw if on screen */
1599 if (panel_contains(y, x) && in_bounds2(y, x))
1607 /* Examine the grid */
1608 map_info(y, x, &a, &c, &ta, &tc);
1610 /* Hack -- fake monochrome */
1613 if (world_monster) a = TERM_DARK;
1614 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1615 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1618 /* Hack -- Queue it */
1619 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1621 /* Update sub-windows */
1622 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1628 * Prints the map of the dungeon
1630 * Note that, for efficiency, we contain an "optimized" version
1631 * of both "lite_spot()" and "print_rel()", and that we use the
1632 * "lite_spot()" function to display the player grid, if needed.
1640 s16b xmin, xmax, ymin, ymax;
1645 Term_get_size(&wid, &hgt);
1647 /* Remove map offset */
1651 /* Access the cursor state */
1652 (void)Term_get_cursor(&v);
1654 /* Hide the cursor */
1655 (void)Term_set_cursor(0);
1658 xmin = (0 < panel_col_min) ? panel_col_min : 0;
1659 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1660 ymin = (0 < panel_row_min) ? panel_row_min : 0;
1661 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1663 /* Bottom section of screen */
1664 for (y = 1; y <= ymin - panel_row_prt; y++)
1666 /* Erase the section */
1667 Term_erase(COL_MAP, y, wid);
1670 /* Top section of screen */
1671 for (y = ymax - panel_row_prt; y <= hgt; y++)
1673 /* Erase the section */
1674 Term_erase(COL_MAP, y, wid);
1678 for (y = ymin; y <= ymax; y++)
1680 /* Scan the columns of row "y" */
1681 for (x = xmin; x <= xmax; x++)
1689 /* Determine what is there */
1690 map_info(y, x, &a, &c, &ta, &tc);
1692 /* Hack -- fake monochrome */
1695 if (world_monster) a = TERM_DARK;
1696 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1697 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1700 /* Efficiency -- Redraw that grid of the map */
1701 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1705 /* Display player */
1708 /* Restore the cursor */
1709 (void)Term_set_cursor(v);
1715 * print project path
1717 void prt_path(int y, int x)
1722 int default_color = TERM_SLATE;
1724 if (!display_path) return;
1725 if (-1 == project_length)
1728 /* Get projection path */
1729 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
1732 p_ptr->redraw |= (PR_MAP);
1738 for (i = 0; i < path_n; i++)
1740 int ny = GRID_Y(path_g[i]);
1741 int nx = GRID_X(path_g[i]);
1742 cave_type *c_ptr = &cave[ny][nx];
1744 if (panel_contains(ny, nx))
1746 byte a = default_color;
1752 if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1754 /* Determine what is there */
1755 map_info(ny, nx, &a, &c, &ta, &tc);
1757 if (!is_ascii_graphics(a))
1759 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1761 else if (a == default_color)
1767 if (world_monster) a = TERM_DARK;
1768 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1769 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1774 /* Hack -- Queue it */
1775 Term_queue_bigchar(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
1779 if ((c_ptr->info & CAVE_MARK) && !cave_have_flag_grid(c_ptr, FF_PROJECT)) break;
1782 if (nx == x && ny == y) default_color = TERM_L_DARK;
1787 static cptr simplify_list[][2] =
1794 {"^Amulet of ", "\""},
1795 {"^Scroll of ", "?"},
1796 {"^Scroll titled ", "?"},
1797 {"^Wand of " , "-"},
1799 {"^Staff of " , "_"},
1800 {"^Potion of ", "!"},
1812 static void display_shortened_item_name(object_type *o_ptr, int y)
1819 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
1820 attr = tval_to_attr[o_ptr->tval % 128];
1826 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
1828 strcpy(buf, "something strange");
1832 for (c = buf; *c; c++)
1835 for (i = 0; simplify_list[i][1]; i++)
1837 cptr org_w = simplify_list[i][0];
1847 if (!strncmp(c, org_w, strlen(org_w)))
1850 cptr tmp = simplify_list[i][1];
1853 tmp = c + strlen(org_w);
1863 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
1869 if(len + 2 > 12) break;
1876 if(len + 1 > 12) break;
1882 Term_putstr(0, y, 12, attr, buf);
1886 * Display a "small-scale" map of the dungeon in the active Term
1888 void display_map(int *cy, int *cx)
1905 /* Save lighting effects */
1906 bool old_view_special_lite = view_special_lite;
1907 bool old_view_granite_lite = view_granite_lite;
1909 int hgt, wid, yrat, xrat;
1911 int **match_autopick_yx;
1912 object_type ***object_autopick_yx;
1915 Term_get_size(&wid, &hgt);
1918 if (use_bigtile) wid /= 2;
1920 yrat = (cur_hgt + hgt - 1) / hgt;
1921 xrat = (cur_wid + wid - 1) / wid;
1923 /* Disable lighting effects */
1924 view_special_lite = FALSE;
1925 view_granite_lite = FALSE;
1927 /* Allocate the maps */
1928 C_MAKE(ma, (hgt + 2), byte_ptr);
1929 C_MAKE(mc, (hgt + 2), char_ptr);
1930 C_MAKE(mp, (hgt + 2), byte_ptr);
1931 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
1932 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
1934 /* Allocate and wipe each line map */
1935 for (y = 0; y < (hgt + 2); y++)
1937 /* Allocate one row each array */
1938 C_MAKE(ma[y], (wid + 2), byte);
1939 C_MAKE(mc[y], (wid + 2), char);
1940 C_MAKE(mp[y], (wid + 2), byte);
1941 C_MAKE(match_autopick_yx[y], (wid + 2), int);
1942 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
1944 for (x = 0; x < wid + 2; ++x)
1946 match_autopick_yx[y][x] = -1;
1947 object_autopick_yx[y][x] = NULL;
1950 ma[y][x] = TERM_WHITE;
1958 /* Allocate the maps */
1959 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
1960 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
1961 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
1963 /* Allocate and wipe each line map */
1964 for (y = 0; y < (cur_hgt + 2); y++)
1966 /* Allocate one row each array */
1967 C_MAKE(bigma[y], (cur_wid + 2), byte);
1968 C_MAKE(bigmc[y], (cur_wid + 2), char);
1969 C_MAKE(bigmp[y], (cur_wid + 2), byte);
1971 for (x = 0; x < cur_wid + 2; ++x)
1974 bigma[y][x] = TERM_WHITE;
1982 /* Fill in the map */
1983 for (i = 0; i < cur_wid; ++i)
1985 for (j = 0; j < cur_hgt; ++j)
1995 /* Extract the current attr/char at that map location */
1996 map_info(j, i, &ta, &tc, &ta, &tc);
1998 /* Extract the priority */
2001 if(match_autopick!=-1
2002 && (match_autopick_yx[y][x] == -1
2003 || match_autopick_yx[y][x] > match_autopick))
2005 match_autopick_yx[y][x] = match_autopick;
2006 object_autopick_yx[y][x] = autopick_obj;
2010 /* Save the char, attr and priority */
2011 bigmc[j+1][i+1] = tc;
2012 bigma[j+1][i+1] = ta;
2013 bigmp[j+1][i+1] = tp;
2017 for (j = 0; j < cur_hgt; ++j)
2019 for (i = 0; i < cur_wid; ++i)
2025 tc = bigmc[j+1][i+1];
2026 ta = bigma[j+1][i+1];
2027 tp = bigmp[j+1][i+1];
2029 /* rare feature has more priority */
2035 for (t = 0; t < 8; t++)
2037 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2038 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2048 /* Save the char, attr and priority */
2061 /* Draw the corners */
2062 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2064 /* Draw the horizontal edges */
2065 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2067 /* Draw the vertical edges */
2068 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2071 /* Display each map line in order */
2072 for (y = 0; y < hgt + 2; ++y)
2074 /* Start a new line */
2075 Term_gotoxy(COL_MAP, y);
2077 /* Display the line */
2078 for (x = 0; x < wid + 2; ++x)
2083 /* Hack -- fake monochrome */
2086 if (world_monster) ta = TERM_DARK;
2087 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2088 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2091 /* Add the character */
2092 Term_add_bigch(ta, tc);
2097 for (y = 1; y < hgt + 1; ++y)
2099 match_autopick = -1;
2100 for (x = 1; x <= wid; x++){
2101 if (match_autopick_yx[y][x] != -1 &&
2102 (match_autopick > match_autopick_yx[y][x] ||
2103 match_autopick == -1)){
2104 match_autopick = match_autopick_yx[y][x];
2105 autopick_obj = object_autopick_yx[y][x];
2109 /* Clear old display */
2110 Term_putstr(0, y, 12, 0, " ");
2112 if (match_autopick != -1)
2114 display_shortened_item_name(autopick_obj, y);
2117 char buf[13] = "\0";
2118 strncpy(buf,autopick_list[match_autopick].name,12);
2126 /* Player location */
2127 (*cy) = py / yrat + 1 + ROW_MAP;
2129 (*cx) = px / xrat + 1 + COL_MAP;
2131 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2133 /* Restore lighting effects */
2134 view_special_lite = old_view_special_lite;
2135 view_granite_lite = old_view_granite_lite;
2137 /* Free each line map */
2138 for (y = 0; y < (hgt + 2); y++)
2140 /* Free one row each array */
2141 C_FREE(ma[y], (wid + 2), byte);
2142 C_FREE(mc[y], (wid + 2), char);
2143 C_FREE(mp[y], (wid + 2), byte);
2144 C_FREE(match_autopick_yx[y], (wid + 2), int);
2145 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2148 /* Free each line map */
2149 C_FREE(ma, (hgt + 2), byte_ptr);
2150 C_FREE(mc, (hgt + 2), char_ptr);
2151 C_FREE(mp, (hgt + 2), byte_ptr);
2152 C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2153 C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2155 /* Free each line map */
2156 for (y = 0; y < (cur_hgt + 2); y++)
2158 /* Free one row each array */
2159 C_FREE(bigma[y], (cur_wid + 2), byte);
2160 C_FREE(bigmc[y], (cur_wid + 2), char);
2161 C_FREE(bigmp[y], (cur_wid + 2), byte);
2164 /* Free each line map */
2165 C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2166 C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2167 C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2172 * Display a "small-scale" map of the dungeon for the player
2174 * Currently, the "player" is displayed on the map. XXX XXX XXX
2176 void do_cmd_view_map(void)
2181 /* Save the screen */
2186 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2188 prt("Please wait...", 0, 0);
2194 /* Clear the screen */
2197 display_autopick = 0;
2199 /* Display the map */
2200 display_map(&cy, &cx);
2203 if(max_autopick && !p_ptr->wild_mode)
2205 display_autopick = ITEM_DISPLAY;
2212 int wid, hgt, row_message;
2214 Term_get_size(&wid, &hgt);
2215 row_message = hgt - 1;
2218 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2220 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2223 /* Hilite the player */
2224 move_cursor(cy, cx);
2229 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2231 flag = DONT_AUTOPICK;
2233 flag = DO_AUTODESTROY;
2235 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2241 if (~display_autopick & flag)
2242 display_autopick |= flag;
2244 display_autopick &= ~flag;
2245 /* Display the map */
2246 display_map(&cy, &cx);
2249 display_autopick = 0;
2255 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2257 put_str("Hit any key to continue", 23, 30);
2258 #endif /* Hilite the player */
2259 move_cursor(cy, cx);
2264 /* Restore the screen */
2273 * Some comments on the cave grid flags. -BEN-
2276 * One of the major bottlenecks in previous versions of Angband was in
2277 * the calculation of "line of sight" from the player to various grids,
2278 * such as monsters. This was such a nasty bottleneck that a lot of
2279 * silly things were done to reduce the dependancy on "line of sight",
2280 * for example, you could not "see" any grids in a lit room until you
2281 * actually entered the room, and there were all kinds of bizarre grid
2282 * flags to enable this behavior. This is also why the "call light"
2283 * spells always lit an entire room.
2285 * The code below provides functions to calculate the "field of view"
2286 * for the player, which, once calculated, provides extremely fast
2287 * calculation of "line of sight from the player", and to calculate
2288 * the "field of torch lite", which, again, once calculated, provides
2289 * extremely fast calculation of "which grids are lit by the player's
2290 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2291 * "GRID_LITE", as appropriate, these functions maintain an array for
2292 * each of these two flags, each array containing the locations of all
2293 * of the grids marked with the appropriate flag, which can be used to
2294 * very quickly scan through all of the grids in a given set.
2296 * To allow more "semantically valid" field of view semantics, whenever
2297 * the field of view (or the set of torch lit grids) changes, all of the
2298 * grids in the field of view (or the set of torch lit grids) are "drawn"
2299 * so that changes in the world will become apparent as soon as possible.
2300 * This has been optimized so that only grids which actually "change" are
2301 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2302 * of the grids which are entering or leaving the relevent set of grids.
2304 * These new methods are so efficient that the old nasty code was removed.
2306 * Note that there is no reason to "update" the "viewable space" unless
2307 * the player "moves", or walls/doors are created/destroyed, and there
2308 * is no reason to "update" the "torch lit grids" unless the field of
2309 * view changes, or the "light radius" changes. This means that when
2310 * the player is resting, or digging, or doing anything that does not
2311 * involve movement or changing the state of the dungeon, there is no
2312 * need to update the "view" or the "lite" regions, which is nice.
2314 * Note that the calls to the nasty "los()" function have been reduced
2315 * to a bare minimum by the use of the new "field of view" calculations.
2317 * I wouldn't be surprised if slight modifications to the "update_view()"
2318 * function would allow us to determine "reverse line-of-sight" as well
2319 * as "normal line-of-sight", which would allow monsters to use a more
2320 * "correct" calculation to determine if they can "see" the player. For
2321 * now, monsters simply "cheat" somewhat and assume that if the player
2322 * has "line of sight" to the monster, then the monster can "pretend"
2323 * that it has "line of sight" to the player.
2326 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2327 * grid and maintains an array of all "CAVE_LITE" grids.
2329 * This set of grids is the complete set of all grids which are lit by
2330 * the players light source, which allows the "player_can_see_bold()"
2331 * function to work very quickly.
2333 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2334 * fact, the player (unless blind) can always "see" all grids which are
2335 * marked as "CAVE_LITE", unless they are "off screen".
2338 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2339 * grid and maintains an array of all "CAVE_VIEW" grids.
2341 * This set of grids is the complete set of all grids within line of sight
2342 * of the player, allowing the "player_has_los_bold()" macro to work very
2346 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2347 * temporary internal flag to mark those grids which are not only in view,
2348 * but which are also "easily" in line of sight of the player. This flag
2349 * is always cleared when we are done.
2352 * The current "update_lite()" and "update_view()" algorithms use the
2353 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2354 * to keep track of which grids were previously marked as "CAVE_LITE" or
2355 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2357 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2358 * for various other purposes, such as spreading lite or darkness during
2359 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2362 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2363 * in some way permanently lit. However, for the player to "see" anything
2364 * in the grid, as determined by "player_can_see()", the player must not be
2365 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2366 * grids, even if marked as "perma lit", are only illuminated if they touch
2367 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2370 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2371 * that even if the player cannot "see" the grid, he "knows" the terrain in
2372 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2373 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2374 * or when one of the "memorize floor grids" options induces memorization.
2376 * Objects are "memorized" in a different way, using a special "marked" flag
2377 * on the object itself, which is set when an object is observed or detected.
2380 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2381 * and should be illuminated by "lite room" and "darkness" spells.
2384 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2385 * and should be unavailable for "teleportation" destinations.
2388 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2389 * which is observed, and the "view_torch_grids" allows the player to memorize
2390 * every torch-lit grid. The player will always memorize important walls,
2391 * doors, stairs, and other terrain features, as well as any "detected" grids.
2393 * Note that the new "update_view()" method allows, among other things, a room
2394 * to be "partially" seen as the player approaches it, with a growing cone of
2395 * floor appearing as the player gets closer to the door. Also, by not turning
2396 * on the "memorize perma-lit grids" option, the player will only "see" those
2397 * floor grids which are actually in line of sight.
2399 * And my favorite "plus" is that you can now use a special option to draw the
2400 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2401 * grids dimly), providing a "pretty" effect as the player runs around, and
2402 * to efficiently display the "torch lite" in a special color.
2405 * Some comments on the "update_view()" algorithm...
2407 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2408 * and only has to call "los()" on the borderline cases. The major axes/diags
2409 * even terminate early when they hit walls. I need to find a quick way
2410 * to "terminate" the other scans.
2412 * Note that in the worst case (a big empty area with say 5% scattered walls),
2413 * each of the 1500 or so nearby grids is checked once, most of them getting
2414 * an "instant" rating, and only a small portion requiring a call to "los()".
2416 * The only time that the algorithm appears to be "noticeably" too slow is
2417 * when running, and this is usually only important in town, since the town
2418 * provides about the worst scenario possible, with large open regions and
2419 * a few scattered obstructions. There is a special "efficiency" option to
2420 * allow the player to reduce his field of view in town, if needed.
2422 * In the "best" case (say, a normal stretch of corridor), the algorithm
2423 * makes one check for each viewable grid, and makes no calls to "los()".
2424 * So running in corridors is very fast, and if a lot of monsters are
2425 * nearby, it is much faster than the old methods.
2427 * Note that resting, most normal commands, and several forms of running,
2428 * plus all commands executed near large groups of monsters, are strictly
2429 * more efficient with "update_view()" that with the old "compute los() on
2430 * demand" method, primarily because once the "field of view" has been
2431 * calculated, it does not have to be recalculated until the player moves
2432 * (or a wall or door is created or destroyed).
2434 * Note that we no longer have to do as many "los()" checks, since once the
2435 * "view" region has been built, very few things cause it to be "changed"
2436 * (player movement, and the opening/closing of doors, changes in wall status).
2437 * Note that door/wall changes are only relevant when the door/wall itself is
2438 * in the "view" region.
2440 * The algorithm seems to only call "los()" from zero to ten times, usually
2441 * only when coming down a corridor into a room, or standing in a room, just
2442 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2443 * we will be reducing the calls to "los()".
2445 * I am thinking in terms of an algorithm that "walks" from the central point
2446 * out to the maximal "distance", at each point, determining the "view" code
2447 * (above). For each grid not on a major axis or diagonal, the "view" code
2448 * depends on the "cave_los_bold()" and "view" of exactly two other grids
2449 * (the one along the nearest diagonal, and the one next to that one, see
2450 * "update_view_aux()"...).
2452 * We "memorize" the viewable space array, so that at the cost of under 3000
2453 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2454 * each grid actually in the "viewable space". And for another 3000 bytes,
2455 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2456 * are also used by other routines, thus reducing the cost to almost nothing.
2458 * A similar thing is done for "forget_lite()" in which case the savings are
2459 * much less, but save us from doing bizarre maintenance checking.
2461 * In the worst "normal" case (in the middle of the town), the reachable space
2462 * actually reaches to more than half of the largest possible "circle" of view,
2463 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2464 * where all the walls have been removed), the reachable space actually reaches
2465 * the theoretical maximum size of just under 1500 grids.
2467 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2468 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2469 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2470 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2471 * entire possible space (including initialization) in one step per grid. If
2472 * we do the "clearing" as a separate step (and use an array of "view" grids),
2473 * then the clearing will take as many steps as grids that were viewed, and the
2474 * algorithm will be able to "stop" scanning at various points.
2475 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2486 * Actually erase the entire "lite" array, redrawing every grid
2488 void forget_lite(void)
2492 /* None to forget */
2493 if (!lite_n) return;
2495 /* Clear them all */
2496 for (i = 0; i < lite_n; i++)
2501 /* Forget "LITE" flag */
2502 cave[y][x].info &= ~(CAVE_LITE);
2505 /* lite_spot(y, x); Perhaps don't need? */
2514 * For delayed visual update
2516 #define cave_note_and_redraw_later(C,Y,X) \
2518 (C)->info |= CAVE_NOTE; \
2519 cave_redraw_later((C), (Y), (X)); \
2524 * For delayed visual update
2526 #define cave_redraw_later(C,Y,X) \
2528 if (!((C)->info & CAVE_REDRAW)) \
2530 (C)->info |= CAVE_REDRAW; \
2531 redraw_y[redraw_n] = (Y); \
2532 redraw_x[redraw_n++] = (X); \
2540 * This macro allows us to efficiently add a grid to the "lite" array,
2541 * note that we are never called for illegal grids, or for grids which
2542 * have already been placed into the "lite" array, and we are never
2543 * called when the "lite" array is full.
2545 #define cave_lite_hack(Y,X) \
2547 if (!(cave[Y][X].info & (CAVE_LITE))) \
2549 cave[Y][X].info |= (CAVE_LITE); \
2550 lite_y[lite_n] = (Y); \
2551 lite_x[lite_n++] = (X); \
2557 * Update the set of grids "illuminated" by the player's lite.
2559 * This routine needs to use the results of "update_view()"
2561 * Note that "blindness" does NOT affect "torch lite". Be careful!
2563 * We optimize most lites (all non-artifact lites) by using "obvious"
2564 * facts about the results of "small" lite radius, and we attempt to
2565 * list the "nearby" grids before the more "distant" ones in the
2566 * array of torch-lit grids.
2568 * We assume that "radius zero" lite is in fact no lite at all.
2570 * Torch Lantern Artifacts
2580 void update_lite(void)
2582 int i, x, y, min_x, max_x, min_y, max_y;
2583 int p = p_ptr->cur_lite;
2586 /*** Special case ***/
2589 /* Hack -- Player has no lite */
2592 /* Forget the old lite */
2593 /* forget_lite(); Perhaps don't need? */
2595 /* Add it to later visual update */
2596 cave_redraw_later(&cave[py][px], py, px);
2600 /*** Save the old "lite" grids for later ***/
2602 /* Clear them all */
2603 for (i = 0; i < lite_n; i++)
2608 /* Mark the grid as not "lite" */
2609 cave[y][x].info &= ~(CAVE_LITE);
2611 /* Mark the grid as "seen" */
2612 cave[y][x].info |= (CAVE_TEMP);
2614 /* Add it to the "seen" set */
2624 /*** Collect the new "lite" grids ***/
2626 /* Radius 1 -- torch radius */
2630 cave_lite_hack(py, px);
2633 cave_lite_hack(py+1, px);
2634 cave_lite_hack(py-1, px);
2635 cave_lite_hack(py, px+1);
2636 cave_lite_hack(py, px-1);
2638 /* Diagonal grids */
2639 cave_lite_hack(py+1, px+1);
2640 cave_lite_hack(py+1, px-1);
2641 cave_lite_hack(py-1, px+1);
2642 cave_lite_hack(py-1, px-1);
2645 /* Radius 2 -- lantern radius */
2648 /* South of the player */
2649 if (cave_los_bold(py + 1, px))
2651 cave_lite_hack(py+2, px);
2652 cave_lite_hack(py+2, px+1);
2653 cave_lite_hack(py+2, px-1);
2656 /* North of the player */
2657 if (cave_los_bold(py - 1, px))
2659 cave_lite_hack(py-2, px);
2660 cave_lite_hack(py-2, px+1);
2661 cave_lite_hack(py-2, px-1);
2664 /* East of the player */
2665 if (cave_los_bold(py, px + 1))
2667 cave_lite_hack(py, px+2);
2668 cave_lite_hack(py+1, px+2);
2669 cave_lite_hack(py-1, px+2);
2672 /* West of the player */
2673 if (cave_los_bold(py, px - 1))
2675 cave_lite_hack(py, px-2);
2676 cave_lite_hack(py+1, px-2);
2677 cave_lite_hack(py-1, px-2);
2681 /* Radius 3+ -- artifact radius */
2686 /* Paranoia -- see "LITE_MAX" */
2689 /* South-East of the player */
2690 if (cave_los_bold(py + 1, px + 1))
2692 cave_lite_hack(py+2, px+2);
2695 /* South-West of the player */
2696 if (cave_los_bold(py + 1, px - 1))
2698 cave_lite_hack(py+2, px-2);
2701 /* North-East of the player */
2702 if (cave_los_bold(py - 1, px + 1))
2704 cave_lite_hack(py-2, px+2);
2707 /* North-West of the player */
2708 if (cave_los_bold(py - 1, px - 1))
2710 cave_lite_hack(py-2, px-2);
2715 if (min_y < 0) min_y = 0;
2719 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
2723 if (min_x < 0) min_x = 0;
2727 if (max_x > cur_wid-1) max_x = cur_wid-1;
2729 /* Scan the maximal box */
2730 for (y = min_y; y <= max_y; y++)
2732 for (x = min_x; x <= max_x; x++)
2734 int dy = (py > y) ? (py - y) : (y - py);
2735 int dx = (px > x) ? (px - x) : (x - px);
2737 /* Skip the "central" grids (above) */
2738 if ((dy <= 2) && (dx <= 2)) continue;
2740 /* Hack -- approximate the distance */
2741 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2743 /* Skip distant grids */
2744 if (d > p) continue;
2746 /* Viewable, nearby, grids get "torch lit" */
2747 if (player_has_los_bold(y, x))
2749 /* This grid is "torch lit" */
2750 cave_lite_hack(y, x);
2757 /*** Complete the algorithm ***/
2759 /* Draw the new grids */
2760 for (i = 0; i < lite_n; i++)
2765 c_ptr = &cave[y][x];
2767 /* Update fresh grids */
2768 if (c_ptr->info & (CAVE_TEMP)) continue;
2770 /* Add it to later visual update */
2771 cave_note_and_redraw_later(c_ptr, y, x);
2774 /* Clear them all */
2775 for (i = 0; i < temp_n; i++)
2780 c_ptr = &cave[y][x];
2782 /* No longer in the array */
2783 c_ptr->info &= ~(CAVE_TEMP);
2785 /* Update stale grids */
2786 if (c_ptr->info & (CAVE_LITE)) continue;
2788 /* Add it to later visual update */
2789 cave_redraw_later(c_ptr, y, x);
2795 /* Mega-Hack -- Visual update later */
2796 p_ptr->update |= (PU_DELAY_VIS);
2800 static bool mon_invis;
2801 static s16b mon_fy, mon_fx;
2804 * Add a square to the changes array
2806 static void mon_lite_hack(int y, int x)
2809 int midpoint, dpf, d;
2811 /* We trust this grid is in bounds */
2812 /* if (!in_bounds2(y, x)) return; */
2814 c_ptr = &cave[y][x];
2816 /* Want a unlit square in view of the player */
2817 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
2819 if (!cave_los_grid(c_ptr))
2821 /* Hack -- Prevent monster lite leakage in walls */
2823 /* Horizontal walls between player and a monster */
2824 if (((y < py) && (y > mon_fy)) || ((y > py) && (y < mon_fy)))
2828 midpoint = mon_fx + ((px - mon_fx) * ABS(d)) / ABS(dpf);
2830 /* Only first wall viewed from mid-x is lit */
2833 if (!cave_los_bold(y, x + 1)) return;
2835 else if (x > midpoint)
2837 if (!cave_los_bold(y, x - 1)) return;
2840 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2841 else if (mon_invis) return;
2844 /* Vertical walls between player and a monster */
2845 if (((x < px) && (x > mon_fx)) || ((x > px) && (x < mon_fx)))
2849 midpoint = mon_fy + ((py - mon_fy) * ABS(d)) / ABS(dpf);
2851 /* Only first wall viewed from mid-y is lit */
2854 if (!cave_los_bold(y + 1, x)) return;
2856 else if (y > midpoint)
2858 if (!cave_los_bold(y - 1, x)) return;
2861 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2862 else if (mon_invis) return;
2866 /* We trust temp_n does not exceed TEMP_MAX */
2869 if (!(c_ptr->info & CAVE_MNDK))
2871 /* Save this square */
2880 /* No longer dark */
2881 c_ptr->info &= ~(CAVE_MNDK);
2885 c_ptr->info |= CAVE_MNLT;
2890 * Add a square to the changes array
2892 static void mon_dark_hack(int y, int x)
2895 int midpoint, dpf, d;
2897 /* We trust this grid is in bounds */
2898 /* if (!in_bounds2(y, x)) return; */
2900 c_ptr = &cave[y][x];
2902 /* Want a unlit and undarkened square in view of the player */
2903 if ((c_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
2905 if (!cave_los_grid(c_ptr) && !cave_have_flag_grid(c_ptr, FF_PROJECT))
2907 /* Hack -- Prevent monster dark lite leakage in walls */
2909 /* Horizontal walls between player and a monster */
2910 if (((y < py) && (y > mon_fy)) || ((y > py) && (y < mon_fy)))
2914 midpoint = mon_fx + ((px - mon_fx) * ABS(d)) / ABS(dpf);
2916 /* Only first wall viewed from mid-x is lit */
2919 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
2921 else if (x > midpoint)
2923 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
2926 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2927 else if (mon_invis) return;
2930 /* Vertical walls between player and a monster */
2931 if (((x < px) && (x > mon_fx)) || ((x > px) && (x < mon_fx)))
2935 midpoint = mon_fy + ((py - mon_fy) * ABS(d)) / ABS(dpf);
2937 /* Only first wall viewed from mid-y is lit */
2940 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
2942 else if (y > midpoint)
2944 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
2947 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2948 else if (mon_invis) return;
2952 /* We trust temp_n does not exceed TEMP_MAX */
2954 /* Save this square */
2960 c_ptr->info |= CAVE_MNDK;
2965 * Update squares illuminated or darkened by monsters.
2967 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
2968 * denote squares illuminated by monsters.
2970 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
2971 * updating. Only squares in view of the player, whos state
2972 * changes are drawn via lite_spot().
2974 void update_mon_lite(void)
2980 void (*add_mon_lite)(int, int);
2985 /* Non-Ninja player in the darkness */
2986 int dis_lim = ((d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
2987 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
2989 /* Clear all monster lit squares */
2990 for (i = 0; i < mon_lite_n; i++)
2993 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
2995 /* Set temp or xtra flag */
2996 c_ptr->info |= (c_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
2998 /* Clear monster illumination flag */
2999 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3002 /* Empty temp list of new squares to lite up */
3005 /* If a monster stops time, don't process */
3008 monster_type *m_ptr;
3009 monster_race *r_ptr;
3011 /* Loop through monsters, adding newly lit squares to changes list */
3012 for (i = 1; i < m_max; i++)
3015 r_ptr = &r_info[m_ptr->r_idx];
3017 /* Skip dead monsters */
3018 if (!m_ptr->r_idx) continue;
3020 /* Is it too far away? */
3021 if (m_ptr->cdis > dis_lim) continue;
3023 /* Get lite radius */
3026 /* Note the radii are cumulative */
3027 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3028 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3029 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3030 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3032 /* Exit if has no light */
3036 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3037 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3038 add_mon_lite = mon_lite_hack;
3043 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!dun_level && !is_daytime()))) continue;
3044 add_mon_lite = mon_dark_hack;
3045 f_flag = FF_PROJECT;
3046 rad = -rad; /* Use absolute value */
3049 /* Access the location */
3053 /* Is the monster visible? */
3054 mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
3056 /* The square it is on */
3057 add_mon_lite(mon_fy, mon_fx);
3059 /* Adjacent squares */
3060 add_mon_lite(mon_fy + 1, mon_fx);
3061 add_mon_lite(mon_fy - 1, mon_fx);
3062 add_mon_lite(mon_fy, mon_fx + 1);
3063 add_mon_lite(mon_fy, mon_fx - 1);
3064 add_mon_lite(mon_fy + 1, mon_fx + 1);
3065 add_mon_lite(mon_fy + 1, mon_fx - 1);
3066 add_mon_lite(mon_fy - 1, mon_fx + 1);
3067 add_mon_lite(mon_fy - 1, mon_fx - 1);
3072 /* South of the monster */
3073 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
3075 add_mon_lite(mon_fy + 2, mon_fx + 1);
3076 add_mon_lite(mon_fy + 2, mon_fx);
3077 add_mon_lite(mon_fy + 2, mon_fx - 1);
3079 c_ptr = &cave[mon_fy + 2][mon_fx];
3082 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3084 add_mon_lite(mon_fy + 3, mon_fx + 1);
3085 add_mon_lite(mon_fy + 3, mon_fx);
3086 add_mon_lite(mon_fy + 3, mon_fx - 1);
3090 /* North of the monster */
3091 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
3093 add_mon_lite(mon_fy - 2, mon_fx + 1);
3094 add_mon_lite(mon_fy - 2, mon_fx);
3095 add_mon_lite(mon_fy - 2, mon_fx - 1);
3097 c_ptr = &cave[mon_fy - 2][mon_fx];
3100 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3102 add_mon_lite(mon_fy - 3, mon_fx + 1);
3103 add_mon_lite(mon_fy - 3, mon_fx);
3104 add_mon_lite(mon_fy - 3, mon_fx - 1);
3108 /* East of the monster */
3109 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
3111 add_mon_lite(mon_fy + 1, mon_fx + 2);
3112 add_mon_lite(mon_fy, mon_fx + 2);
3113 add_mon_lite(mon_fy - 1, mon_fx + 2);
3115 c_ptr = &cave[mon_fy][mon_fx + 2];
3118 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3120 add_mon_lite(mon_fy + 1, mon_fx + 3);
3121 add_mon_lite(mon_fy, mon_fx + 3);
3122 add_mon_lite(mon_fy - 1, mon_fx + 3);
3126 /* West of the monster */
3127 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
3129 add_mon_lite(mon_fy + 1, mon_fx - 2);
3130 add_mon_lite(mon_fy, mon_fx - 2);
3131 add_mon_lite(mon_fy - 1, mon_fx - 2);
3133 c_ptr = &cave[mon_fy][mon_fx - 2];
3136 if ((rad == 3) && cave_have_flag_grid(c_ptr, f_flag))
3138 add_mon_lite(mon_fy + 1, mon_fx - 3);
3139 add_mon_lite(mon_fy, mon_fx - 3);
3140 add_mon_lite(mon_fy - 1, mon_fx - 3);
3148 /* South-East of the monster */
3149 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
3151 add_mon_lite(mon_fy + 2, mon_fx + 2);
3154 /* South-West of the monster */
3155 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
3157 add_mon_lite(mon_fy + 2, mon_fx - 2);
3160 /* North-East of the monster */
3161 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
3163 add_mon_lite(mon_fy - 2, mon_fx + 2);
3166 /* North-West of the monster */
3167 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
3169 add_mon_lite(mon_fy - 2, mon_fx - 2);
3175 /* Save end of list of new squares */
3179 * Look at old set flags to see if there are any changes.
3181 for (i = 0; i < mon_lite_n; i++)
3186 /* We trust this grid is in bounds */
3189 c_ptr = &cave[fy][fx];
3191 if (c_ptr->info & CAVE_TEMP) /* Pervious lit */
3193 /* It it no longer lit? */
3194 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3196 /* It is now unlit */
3197 /* Add it to later visual update */
3198 cave_note_and_redraw_later(c_ptr, fy, fx);
3201 else /* Pervious darkened */
3203 /* It it no longer darken? */
3204 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3206 /* It is now undarken */
3207 /* Add it to later visual update */
3208 cave_note_and_redraw_later(c_ptr, fy, fx);
3212 /* Add to end of temp array */
3213 temp_x[temp_n] = (byte)fx;
3214 temp_y[temp_n] = (byte)fy;
3218 /* Clear the lite array */
3221 /* Copy the temp array into the lit array lighting the new squares. */
3222 for (i = 0; i < end_temp; i++)
3227 /* We trust this grid is in bounds */
3230 c_ptr = &cave[fy][fx];
3232 if (c_ptr->info & CAVE_MNLT) /* Lit */
3234 /* The is the square newly lit and visible? */
3235 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3238 /* Add it to later visual update */
3239 cave_note_and_redraw_later(c_ptr, fy, fx);
3244 /* The is the square newly darkened and visible? */
3245 if ((c_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3247 /* It is now darkened */
3248 /* Add it to later visual update */
3249 cave_note_and_redraw_later(c_ptr, fy, fx);
3253 /* Save in the monster lit or darkened array */
3254 mon_lite_x[mon_lite_n] = fx;
3255 mon_lite_y[mon_lite_n] = fy;
3259 /* Clear the temp flag for the old lit or darken grids */
3260 for (i = end_temp; i < temp_n; i++)
3262 /* We trust this grid is in bounds */
3264 cave[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3267 /* Finished with temp_n */
3270 /* Mega-Hack -- Visual update later */
3271 p_ptr->update |= (PU_DELAY_VIS);
3273 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3275 if (p_ptr->special_defense & NINJA_S_STEALTH)
3277 if (p_ptr->old_monlite != p_ptr->monlite)
3282 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3284 msg_print("Your mantle of shadow become thin.");
3290 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3292 msg_print("Your mantle of shadow restored its original darkness.");
3297 p_ptr->old_monlite = p_ptr->monlite;
3300 void clear_mon_lite(void)
3305 /* Clear all monster lit squares */
3306 for (i = 0; i < mon_lite_n; i++)
3309 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3311 /* Clear monster illumination flag */
3312 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3315 /* Empty the array */
3322 * Clear the viewable space
3324 void forget_view(void)
3330 /* None to forget */
3331 if (!view_n) return;
3333 /* Clear them all */
3334 for (i = 0; i < view_n; i++)
3339 /* Access the grid */
3340 c_ptr = &cave[y][x];
3342 /* Forget that the grid is viewable */
3343 c_ptr->info &= ~(CAVE_VIEW);
3345 /* if (!panel_contains(y, x)) continue; */
3347 /* Update the screen */
3348 /* lite_spot(y, x); Perhaps don't need? */
3358 * This macro allows us to efficiently add a grid to the "view" array,
3359 * note that we are never called for illegal grids, or for grids which
3360 * have already been placed into the "view" array, and we are never
3361 * called when the "view" array is full.
3363 #define cave_view_hack(C,Y,X) \
3365 if (!((C)->info & (CAVE_VIEW))){\
3366 (C)->info |= (CAVE_VIEW); \
3367 view_y[view_n] = (Y); \
3368 view_x[view_n] = (X); \
3375 * Helper function for "update_view()" below
3377 * We are checking the "viewability" of grid (y,x) by the player.
3379 * This function assumes that (y,x) is legal (i.e. on the map).
3381 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3382 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3384 * Note that we are using the "CAVE_XTRA" field for marking grids as
3385 * "easily viewable". This bit is cleared at the end of "update_view()".
3387 * This function adds (y,x) to the "viewable set" if necessary.
3389 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3391 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3393 bool f1, f2, v1, v2, z1, z2, wall;
3397 cave_type *g1_c_ptr;
3398 cave_type *g2_c_ptr;
3400 /* Access the grids */
3401 g1_c_ptr = &cave[y1][x1];
3402 g2_c_ptr = &cave[y2][x2];
3405 /* Check for walls */
3406 f1 = (cave_los_grid(g1_c_ptr));
3407 f2 = (cave_los_grid(g2_c_ptr));
3409 /* Totally blocked by physical walls */
3410 if (!f1 && !f2) return (TRUE);
3413 /* Check for visibility */
3414 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3415 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3417 /* Totally blocked by "unviewable neighbors" */
3418 if (!v1 && !v2) return (TRUE);
3421 /* Access the grid */
3422 c_ptr = &cave[y][x];
3425 /* Check for walls */
3426 wall = (!cave_los_grid(c_ptr));
3429 /* Check the "ease" of visibility */
3430 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3431 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3433 /* Hack -- "easy" plus "easy" yields "easy" */
3436 c_ptr->info |= (CAVE_XTRA);
3438 cave_view_hack(c_ptr, y, x);
3443 /* Hack -- primary "easy" yields "viewed" */
3446 cave_view_hack(c_ptr, y, x);
3451 /* Hack -- "view" plus "view" yields "view" */
3454 /* c_ptr->info |= (CAVE_XTRA); */
3456 cave_view_hack(c_ptr, y, x);
3462 /* Mega-Hack -- the "los()" function works poorly on walls */
3465 cave_view_hack(c_ptr, y, x);
3471 /* Hack -- check line of sight */
3472 if (los(py, px, y, x))
3474 cave_view_hack(c_ptr, y, x);
3480 /* Assume no line of sight. */
3487 * Calculate the viewable space
3489 * 1: Process the player
3490 * 1a: The player is always (easily) viewable
3491 * 2: Process the diagonals
3492 * 2a: The diagonals are (easily) viewable up to the first wall
3493 * 2b: But never go more than 2/3 of the "full" distance
3494 * 3: Process the main axes
3495 * 3a: The main axes are (easily) viewable up to the first wall
3496 * 3b: But never go more than the "full" distance
3497 * 4: Process sequential "strips" in each of the eight octants
3498 * 4a: Each strip runs along the previous strip
3499 * 4b: The main axes are "previous" to the first strip
3500 * 4c: Process both "sides" of each "direction" of each strip
3501 * 4c1: Each side aborts as soon as possible
3502 * 4c2: Each side tells the next strip how far it has to check
3504 * Note that the octant processing involves some pretty interesting
3505 * observations involving when a grid might possibly be viewable from
3506 * a given grid, and on the order in which the strips are processed.
3508 * Note the use of the mathematical facts shown below, which derive
3509 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3510 * hypotenuse of a right triangle is primarily determined by the length
3511 * of the longest side, when one side is small, and is strictly less
3512 * than one-and-a-half times as long as the longest side when both of
3513 * the sides are large.
3515 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3516 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3518 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3520 * These observations are important because the calculation of the actual
3521 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3522 * while for small values (up to about 20 or so), the approximations above
3523 * are correct to within an error of at most one grid or so.
3525 * Observe the use of "full" and "over" in the code below, and the use of
3526 * the specialized calculation involving "limit", all of which derive from
3527 * the observations given above. Basically, we note that the "circle" of
3528 * view is completely contained in an "octagon" whose bounds are easy to
3529 * determine, and that only a few steps are needed to derive the actual
3530 * bounds of the circle given the bounds of the octagon.
3532 * Note that by skipping all the grids in the corners of the octagon, we
3533 * place an upper limit on the number of grids in the field of view, given
3534 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3535 * view, only about 1475 of these are in the "octagon" of view, and even
3536 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3537 * entries to completely contain the actual field of view.
3539 * Note also the care taken to prevent "running off the map". The use of
3540 * explicit checks on the "validity" of the "diagonal", and the fact that
3541 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3542 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
3543 * of multiple checks on the validity of grids.
3545 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3546 * "ws","wn" variables. They work like this: While travelling down the
3547 * south-bound strip just to the east of the main south axis, as soon as
3548 * we get to a grid which does not "transmit" viewing, if all of the strips
3549 * preceding us (in this case, just the main axis) had terminated at or before
3550 * the same point, then we can stop, and reset the "max distance" to ourself.
3551 * So, each strip (named by major axis plus offset, thus "se" in this case)
3552 * maintains a "blockage" variable, initialized during the main axis step,
3553 * and checks it whenever a blockage is observed. After processing each
3554 * strip as far as the previous strip told us to process, the next strip is
3555 * told not to go farther than the current strip's farthest viewable grid,
3556 * unless open space is still available. This uses the "k" variable.
3558 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
3559 * macro is a replacement for "cave_los_bold()" which takes a pointer to
3560 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3561 * chunk of code which adds the given location to the "view" array if it
3562 * is not already there, using both the actual location and a pointer to
3563 * the cave grid. See above.
3565 * By the way, the purpose of this code is to reduce the dependancy on the
3566 * "los()" function which is slow, and, in some cases, not very accurate.
3568 * It is very possible that I am the only person who fully understands this
3569 * function, and for that I am truly sorry, but efficiency was very important
3570 * and the "simple" version of this function was just not fast enough. I am
3571 * more than willing to replace this function with a simpler one, if it is
3572 * equally efficient, and especially willing if the new function happens to
3573 * derive "reverse-line-of-sight" at the same time, since currently monsters
3574 * just use an optimized hack of "you see me, so I see you", and then use the
3575 * actual "projectable()" function to check spell attacks.
3577 void update_view(void)
3579 int n, m, d, k, y, x, z;
3581 int se, sw, ne, nw, es, en, ws, wn;
3585 int y_max = cur_hgt - 1;
3586 int x_max = cur_wid - 1;
3590 /*** Initialize ***/
3593 if (view_reduce_view && !dun_level)
3595 /* Full radius (10) */
3596 full = MAX_SIGHT / 2;
3598 /* Octagon factor (15) */
3599 over = MAX_SIGHT * 3 / 4;
3605 /* Full radius (20) */
3608 /* Octagon factor (30) */
3609 over = MAX_SIGHT * 3 / 2;
3613 /*** Step 0 -- Begin ***/
3615 /* Save the old "view" grids for later */
3616 for (n = 0; n < view_n; n++)
3621 /* Access the grid */
3622 c_ptr = &cave[y][x];
3624 /* Mark the grid as not in "view" */
3625 c_ptr->info &= ~(CAVE_VIEW);
3627 /* Mark the grid as "seen" */
3628 c_ptr->info |= (CAVE_TEMP);
3630 /* Add it to the "seen" set */
3636 /* Start over with the "view" array */
3639 /*** Step 1 -- adjacent grids ***/
3641 /* Now start on the player */
3645 /* Access the grid */
3646 c_ptr = &cave[y][x];
3648 /* Assume the player grid is easily viewable */
3649 c_ptr->info |= (CAVE_XTRA);
3651 /* Assume the player grid is viewable */
3652 cave_view_hack(c_ptr, y, x);
3655 /*** Step 2 -- Major Diagonals ***/
3660 /* Scan south-east */
3661 for (d = 1; d <= z; d++)
3663 c_ptr = &cave[y+d][x+d];
3664 c_ptr->info |= (CAVE_XTRA);
3665 cave_view_hack(c_ptr, y+d, x+d);
3666 if (!cave_los_grid(c_ptr)) break;
3669 /* Scan south-west */
3670 for (d = 1; d <= z; d++)
3672 c_ptr = &cave[y+d][x-d];
3673 c_ptr->info |= (CAVE_XTRA);
3674 cave_view_hack(c_ptr, y+d, x-d);
3675 if (!cave_los_grid(c_ptr)) break;
3678 /* Scan north-east */
3679 for (d = 1; d <= z; d++)
3681 c_ptr = &cave[y-d][x+d];
3682 c_ptr->info |= (CAVE_XTRA);
3683 cave_view_hack(c_ptr, y-d, x+d);
3684 if (!cave_los_grid(c_ptr)) break;
3687 /* Scan north-west */
3688 for (d = 1; d <= z; d++)
3690 c_ptr = &cave[y-d][x-d];
3691 c_ptr->info |= (CAVE_XTRA);
3692 cave_view_hack(c_ptr, y-d, x-d);
3693 if (!cave_los_grid(c_ptr)) break;
3697 /*** Step 3 -- major axes ***/
3700 for (d = 1; d <= full; d++)
3702 c_ptr = &cave[y+d][x];
3703 c_ptr->info |= (CAVE_XTRA);
3704 cave_view_hack(c_ptr, y+d, x);
3705 if (!cave_los_grid(c_ptr)) break;
3708 /* Initialize the "south strips" */
3712 for (d = 1; d <= full; d++)
3714 c_ptr = &cave[y-d][x];
3715 c_ptr->info |= (CAVE_XTRA);
3716 cave_view_hack(c_ptr, y-d, x);
3717 if (!cave_los_grid(c_ptr)) break;
3720 /* Initialize the "north strips" */
3724 for (d = 1; d <= full; d++)
3726 c_ptr = &cave[y][x+d];
3727 c_ptr->info |= (CAVE_XTRA);
3728 cave_view_hack(c_ptr, y, x+d);
3729 if (!cave_los_grid(c_ptr)) break;
3732 /* Initialize the "east strips" */
3736 for (d = 1; d <= full; d++)
3738 c_ptr = &cave[y][x-d];
3739 c_ptr->info |= (CAVE_XTRA);
3740 cave_view_hack(c_ptr, y, x-d);
3741 if (!cave_los_grid(c_ptr)) break;
3744 /* Initialize the "west strips" */
3748 /*** Step 4 -- Divide each "octant" into "strips" ***/
3750 /* Now check each "diagonal" (in parallel) */
3751 for (n = 1; n <= over / 2; n++)
3753 int ypn, ymn, xpn, xmn;
3756 /* Acquire the "bounds" of the maximal circle */
3758 if (z > full - n) z = full - n;
3759 while ((z + n + (n>>1)) > full) z--;
3762 /* Access the four diagonal grids */
3772 /* Maximum distance */
3773 m = MIN(z, y_max - ypn);
3776 if ((xpn <= x_max) && (n < se))
3779 for (k = n, d = 1; d <= m; d++)
3781 /* Check grid "d" in strip "n", notice "blockage" */
3782 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3784 if (n + d >= se) break;
3787 /* Track most distant "non-blockage" */
3794 /* Limit the next strip */
3799 if ((xmn >= 0) && (n < sw))
3802 for (k = n, d = 1; d <= m; d++)
3804 /* Check grid "d" in strip "n", notice "blockage" */
3805 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3807 if (n + d >= sw) break;
3810 /* Track most distant "non-blockage" */
3817 /* Limit the next strip */
3826 /* Maximum distance */
3830 if ((xpn <= x_max) && (n < ne))
3833 for (k = n, d = 1; d <= m; d++)
3835 /* Check grid "d" in strip "n", notice "blockage" */
3836 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3838 if (n + d >= ne) break;
3841 /* Track most distant "non-blockage" */
3848 /* Limit the next strip */
3853 if ((xmn >= 0) && (n < nw))
3856 for (k = n, d = 1; d <= m; d++)
3858 /* Check grid "d" in strip "n", notice "blockage" */
3859 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
3861 if (n + d >= nw) break;
3864 /* Track most distant "non-blockage" */
3871 /* Limit the next strip */
3880 /* Maximum distance */
3881 m = MIN(z, x_max - xpn);
3884 if ((ypn <= x_max) && (n < es))
3887 for (k = n, d = 1; d <= m; d++)
3889 /* Check grid "d" in strip "n", notice "blockage" */
3890 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
3892 if (n + d >= es) break;
3895 /* Track most distant "non-blockage" */
3902 /* Limit the next strip */
3907 if ((ymn >= 0) && (n < en))
3910 for (k = n, d = 1; d <= m; d++)
3912 /* Check grid "d" in strip "n", notice "blockage" */
3913 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
3915 if (n + d >= en) break;
3918 /* Track most distant "non-blockage" */
3925 /* Limit the next strip */
3934 /* Maximum distance */
3938 if ((ypn <= y_max) && (n < ws))
3941 for (k = n, d = 1; d <= m; d++)
3943 /* Check grid "d" in strip "n", notice "blockage" */
3944 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
3946 if (n + d >= ws) break;
3949 /* Track most distant "non-blockage" */
3956 /* Limit the next strip */
3961 if ((ymn >= 0) && (n < wn))
3964 for (k = n, d = 1; d <= m; d++)
3966 /* Check grid "d" in strip "n", notice "blockage" */
3967 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
3969 if (n + d >= wn) break;
3972 /* Track most distant "non-blockage" */
3979 /* Limit the next strip */
3986 /*** Step 5 -- Complete the algorithm ***/
3988 /* Update all the new grids */
3989 for (n = 0; n < view_n; n++)
3994 /* Access the grid */
3995 c_ptr = &cave[y][x];
3997 /* Clear the "CAVE_XTRA" flag */
3998 c_ptr->info &= ~(CAVE_XTRA);
4000 /* Update only newly viewed grids */
4001 if (c_ptr->info & (CAVE_TEMP)) continue;
4003 /* Add it to later visual update */
4004 cave_note_and_redraw_later(c_ptr, y, x);
4007 /* Wipe the old grids, update as needed */
4008 for (n = 0; n < temp_n; n++)
4013 /* Access the grid */
4014 c_ptr = &cave[y][x];
4016 /* No longer in the array */
4017 c_ptr->info &= ~(CAVE_TEMP);
4019 /* Update only non-viewable grids */
4020 if (c_ptr->info & (CAVE_VIEW)) continue;
4022 /* Add it to later visual update */
4023 cave_redraw_later(c_ptr, y, x);
4029 /* Mega-Hack -- Visual update later */
4030 p_ptr->update |= (PU_DELAY_VIS);
4035 * Mega-Hack -- Delayed visual update
4036 * Only used if update_view(), update_lite() or update_mon_lite() was called
4038 void delayed_visual_update(void)
4043 /* Update needed grids */
4044 for (i = 0; i < redraw_n; i++)
4049 /* Access the grid */
4050 c_ptr = &cave[y][x];
4052 /* Update only needed grids (prevent multiple updating) */
4053 if (!(c_ptr->info & CAVE_REDRAW)) continue;
4055 /* If required, note */
4056 if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
4061 /* Hack -- Visual update of monster on this grid */
4062 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4064 /* No longer in the array */
4065 c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4074 * Hack -- forget the "flow" information
4076 void forget_flow(void)
4080 /* Check the entire dungeon */
4081 for (y = 0; y < cur_hgt; y++)
4083 for (x = 0; x < cur_wid; x++)
4085 /* Forget the old data */
4086 cave[y][x].dist = 0;
4087 cave[y][x].cost = 0;
4088 cave[y][x].when = 0;
4095 * Hack - speed up the update_flow algorithm by only doing
4096 * it everytime the player moves out of LOS of the last
4099 static u16b flow_x = 0;
4100 static u16b flow_y = 0;
4105 * Hack -- fill in the "cost" field of every grid that the player
4106 * can "reach" with the number of steps needed to reach that grid.
4107 * This also yields the "distance" of the player from every grid.
4109 * In addition, mark the "when" of the grids that can reach
4110 * the player with the incremented value of "flow_n".
4112 * Hack -- use the "seen" array as a "circular queue".
4114 * We do not need a priority queue because the cost from grid
4115 * to grid is always "one" and we process them in order.
4117 void update_flow(void)
4123 /* Paranoia -- make sure the array is empty */
4126 /* The last way-point is on the map */
4127 if (running && in_bounds(flow_y, flow_x))
4129 /* The way point is in sight - do not update. (Speedup) */
4130 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4133 /* Erase all of the current flow information */
4134 for (y = 0; y < cur_hgt; y++)
4136 for (x = 0; x < cur_wid; x++)
4138 cave[y][x].cost = 0;
4139 cave[y][x].dist = 0;
4143 /* Save player position */
4147 /* Add the player's grid to the queue */
4151 /* Now process the queue */
4152 while (flow_head != flow_tail)
4156 /* Extract the next entry */
4157 ty = temp_y[flow_tail];
4158 tx = temp_x[flow_tail];
4160 /* Forget that entry */
4161 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4163 /* Add the "children" */
4164 for (d = 0; d < 8; d++)
4166 int old_head = flow_head;
4167 int m = cave[ty][tx].cost + 1;
4168 int n = cave[ty][tx].dist + 1;
4171 /* Child location */
4172 y = ty + ddy_ddd[d];
4173 x = tx + ddx_ddd[d];
4175 /* Ignore player's grid */
4176 if (player_bold(y, x)) continue;
4178 c_ptr = &cave[y][x];
4180 if (is_closed_door(c_ptr->feat)) m += 3;
4182 /* Ignore "pre-stamped" entries */
4183 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4185 /* Ignore "walls" and "rubble" */
4186 if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4188 /* Save the flow cost */
4189 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4190 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4192 /* Hack -- limit flow depth */
4193 if (n == MONSTER_FLOW_DEPTH) continue;
4195 /* Enqueue that entry */
4196 temp_y[flow_head] = y;
4197 temp_x[flow_head] = x;
4199 /* Advance the queue */
4200 if (++flow_head == TEMP_MAX) flow_head = 0;
4202 /* Hack -- notice overflow by forgetting new entry */
4203 if (flow_head == flow_tail) flow_head = old_head;
4209 static int scent_when = 0;
4212 * Characters leave scent trails for perceptive monsters to track.
4214 * Smell is rather more limited than sound. Many creatures cannot use
4215 * it at all, it doesn't extend very far outwards from the character's
4216 * current position, and monsters can use it to home in the character,
4217 * but not to run away from him.
4219 * Smell is valued according to age. When a character takes his turn,
4220 * scent is aged by one, and new scent of the current age is laid down.
4221 * Speedy characters leave more scent, true, but it also ages faster,
4222 * which makes it harder to hunt them down.
4224 * Whenever the age count loops, most of the scent trail is erased and
4225 * the age of the remainder is recalculated.
4227 void update_smell(void)
4232 /* Create a table that controls the spread of scent */
4233 const int scent_adjust[5][5] =
4242 /* Loop the age and adjust scent values when necessary */
4243 if (++scent_when == 254)
4245 /* Scan the entire dungeon */
4246 for (y = 0; y < cur_hgt; y++)
4248 for (x = 0; x < cur_wid; x++)
4250 int w = cave[y][x].when;
4251 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4260 /* Lay down new scent */
4261 for (i = 0; i < 5; i++)
4263 for (j = 0; j < 5; j++)
4267 /* Translate table to map grids */
4272 if (!in_bounds(y, x)) continue;
4274 c_ptr = &cave[y][x];
4276 /* Walls, water, and lava cannot hold scent. */
4277 if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4279 /* Grid must not be blocked by walls from the character */
4280 if (!player_has_los_bold(y, x)) continue;
4282 /* Note grids that are too far away */
4283 if (scent_adjust[i][j] == -1) continue;
4285 /* Mark the grid with new scent */
4286 c_ptr->when = scent_when + scent_adjust[i][j];
4293 * Hack -- map the current panel (plus some) ala "magic mapping"
4295 void map_area(int range)
4300 feature_type *f_ptr;
4302 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4304 /* Scan that area */
4305 for (y = 1; y < cur_hgt - 1; y++)
4307 for (x = 1; x < cur_wid - 1; x++)
4309 if (distance(py, px, y, x) > range) continue;
4311 c_ptr = &cave[y][x];
4313 /* Feature code (applying "mimic" field) */
4314 feat = get_feat_mimic(c_ptr);
4315 f_ptr = &f_info[feat];
4317 /* All non-walls are "checked" */
4318 if (!have_flag(f_ptr->flags, FF_WALL))
4320 /* Memorize normal features */
4321 if (have_flag(f_ptr->flags, FF_REMEMBER))
4323 /* Memorize the object */
4324 c_ptr->info |= (CAVE_MARK);
4327 /* Memorize known walls */
4328 for (i = 0; i < 8; i++)
4330 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4332 /* Feature code (applying "mimic" field) */
4333 feat = get_feat_mimic(c_ptr);
4334 f_ptr = &f_info[feat];
4336 /* Memorize walls (etc) */
4337 if (have_flag(f_ptr->flags, FF_REMEMBER))
4339 /* Memorize the walls */
4340 c_ptr->info |= (CAVE_MARK);
4348 p_ptr->redraw |= (PR_MAP);
4351 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4357 * Light up the dungeon using "clairvoyance"
4359 * This function "illuminates" every grid in the dungeon, memorizes all
4360 * "objects", memorizes all grids as with magic mapping, and, under the
4361 * standard option settings (view_perma_grids but not view_torch_grids)
4362 * memorizes all floor grids too.
4364 * Note that if "view_perma_grids" is not set, we do not memorize floor
4365 * grids, since this would defeat the purpose of "view_perma_grids", not
4366 * that anyone seems to play without this option.
4368 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4369 * since this would prevent the use of "view_torch_grids" as a method to
4370 * keep track of what grids have been observed directly.
4372 void wiz_lite(bool ninja)
4376 feature_type *f_ptr;
4378 /* Memorize objects */
4379 for (i = 1; i < o_max; i++)
4381 object_type *o_ptr = &o_list[i];
4383 /* Skip dead objects */
4384 if (!o_ptr->k_idx) continue;
4386 /* Skip held objects */
4387 if (o_ptr->held_m_idx) continue;
4390 o_ptr->marked |= OM_FOUND;
4393 /* Scan all normal grids */
4394 for (y = 1; y < cur_hgt - 1; y++)
4396 /* Scan all normal grids */
4397 for (x = 1; x < cur_wid - 1; x++)
4399 cave_type *c_ptr = &cave[y][x];
4401 /* Feature code (applying "mimic" field) */
4402 feat = get_feat_mimic(c_ptr);
4403 f_ptr = &f_info[feat];
4405 /* Process all non-walls */
4406 if (!have_flag(f_ptr->flags, FF_WALL))
4408 /* Scan all neighbors */
4409 for (i = 0; i < 9; i++)
4411 int yy = y + ddy_ddd[i];
4412 int xx = x + ddx_ddd[i];
4415 c_ptr = &cave[yy][xx];
4417 /* Feature code (applying "mimic" field) */
4418 f_ptr = &f_info[get_feat_mimic(c_ptr)];
4420 /* Perma-lite the grid */
4421 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS) && !ninja)
4423 c_ptr->info |= (CAVE_GLOW);
4426 /* Memorize normal features */
4427 if (have_flag(f_ptr->flags, FF_REMEMBER))
4429 /* Memorize the grid */
4430 c_ptr->info |= (CAVE_MARK);
4433 /* Perma-lit grids (newly and previously) */
4434 else if (c_ptr->info & CAVE_GLOW)
4436 /* Normally, memorize floors (see above) */
4437 if (view_perma_grids && !view_torch_grids)
4439 /* Memorize the grid */
4440 c_ptr->info |= (CAVE_MARK);
4448 /* Update the monsters */
4449 p_ptr->update |= (PU_MONSTERS);
4452 p_ptr->redraw |= (PR_MAP);
4455 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4457 if (p_ptr->special_defense & NINJA_S_STEALTH)
4459 if (cave[py][px].info & CAVE_GLOW) set_superstealth(FALSE);
4465 * Forget the dungeon map (ala "Thinking of Maud...").
4472 /* Forget every grid */
4473 for (y = 1; y < cur_hgt - 1; y++)
4475 for (x = 1; x < cur_wid - 1; x++)
4477 cave_type *c_ptr = &cave[y][x];
4479 /* Process the grid */
4480 c_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT);
4481 c_ptr->info |= (CAVE_UNSAFE);
4485 /* Forget every grid on horizontal edge */
4486 for (x = 0; x < cur_wid; x++)
4488 cave[0][x].info &= ~(CAVE_MARK);
4489 cave[cur_hgt - 1][x].info &= ~(CAVE_MARK);
4492 /* Forget every grid on vertical edge */
4493 for (y = 1; y < (cur_hgt - 1); y++)
4495 cave[y][0].info &= ~(CAVE_MARK);
4496 cave[y][cur_wid - 1].info &= ~(CAVE_MARK);
4499 /* Forget all objects */
4500 for (i = 1; i < o_max; i++)
4502 object_type *o_ptr = &o_list[i];
4504 /* Skip dead objects */
4505 if (!o_ptr->k_idx) continue;
4507 /* Skip held objects */
4508 if (o_ptr->held_m_idx) continue;
4510 /* Forget the object */
4514 /* Mega-Hack -- Forget the view and lite */
4515 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4517 /* Update the view and lite */
4518 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4520 /* Update the monsters */
4521 p_ptr->update |= (PU_MONSTERS);
4524 p_ptr->redraw |= (PR_MAP);
4527 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4535 * Change the "feat" flag for a grid, and notice/redraw the grid
4537 void cave_set_feat(int y, int x, int feat)
4539 cave_type *c_ptr = &cave[y][x];
4540 feature_type *f_ptr = &f_info[feat];
4541 bool old_los, old_mirror;
4543 if (!character_dungeon)
4545 /* Clear mimic type */
4548 /* Change the feature */
4551 /* Hack -- glow the GLOW terrain */
4552 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4556 for (i = 0; i < 9; i++)
4558 yy = y + ddy_ddd[i];
4559 xx = x + ddx_ddd[i];
4560 if (!in_bounds2(yy, xx)) continue;
4561 cave[yy][xx].info |= CAVE_GLOW;
4568 old_los = cave_have_flag_bold(y, x, FF_LOS);
4569 old_mirror = is_mirror_grid(c_ptr);
4571 /* Clear mimic type */
4574 /* Change the feature */
4577 /* Remove flag for mirror/glyph */
4578 c_ptr->info &= ~(CAVE_OBJECT);
4580 if (old_mirror && (d_info[dungeon_type].flags1 & DF1_DARKNESS))
4582 c_ptr->info &= ~(CAVE_GLOW);
4583 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4585 update_local_illumination(y, x);
4588 /* Check for change to boring grid */
4589 if (!have_flag(f_ptr->flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
4591 /* Update the monster */
4592 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4600 /* Check if los has changed */
4601 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
4604 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
4606 update_local_illumination(y, x);
4608 #endif /* COMPLEX_WALL_ILLUMINATION */
4610 /* Update the visuals */
4611 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
4614 /* Hack -- glow the GLOW terrain */
4615 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4620 for (i = 0; i < 9; i++)
4622 yy = y + ddy_ddd[i];
4623 xx = x + ddx_ddd[i];
4624 if (!in_bounds2(yy, xx)) continue;
4625 cc_ptr = &cave[yy][xx];
4626 cc_ptr->info |= CAVE_GLOW;
4628 if (player_has_los_grid(cc_ptr))
4630 /* Update the monster */
4631 if (cc_ptr->m_idx) update_mon(cc_ptr->m_idx, FALSE);
4640 update_local_illumination(yy, xx);
4643 if (p_ptr->special_defense & NINJA_S_STEALTH)
4645 if (cave[py][px].info & CAVE_GLOW) set_superstealth(FALSE);
4651 int conv_dungeon_feat(int newfeat)
4653 feature_type *f_ptr = &f_info[newfeat];
4655 if (have_flag(f_ptr->flags, FF_CONVERT))
4657 switch (f_ptr->power)
4659 case CONVERT_TYPE_FLOOR:
4660 return floor_type[randint0(100)];
4661 case CONVERT_TYPE_WALL:
4662 return fill_type[randint0(100)];
4663 case CONVERT_TYPE_INNER:
4664 return feat_wall_inner;
4665 case CONVERT_TYPE_OUTER:
4666 return feat_wall_outer;
4667 case CONVERT_TYPE_SOLID:
4668 return feat_wall_solid;
4669 case CONVERT_TYPE_STREAM1:
4670 return d_info[dungeon_type].stream1;
4671 case CONVERT_TYPE_STREAM2:
4672 return d_info[dungeon_type].stream2;
4677 else return newfeat;
4682 * Take a feature, determine what that feature becomes
4683 * through applying the given action.
4685 int feat_state(int feat, int action)
4687 feature_type *f_ptr = &f_info[feat];
4690 /* Get the new feature */
4691 for (i = 0; i < MAX_FEAT_STATES; i++)
4693 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
4696 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
4698 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
4702 * Takes a location and action and changes the feature at that
4703 * location through applying the given action.
4705 void cave_alter_feat(int y, int x, int action)
4707 /* Set old feature */
4708 int oldfeat = cave[y][x].feat;
4710 /* Get the new feat */
4711 int newfeat = feat_state(oldfeat, action);
4714 if (newfeat == oldfeat) return;
4716 /* Set the new feature */
4717 cave_set_feat(y, x, newfeat);
4719 if (!(feature_action_flags[action] & FAF_NO_DROP))
4721 feature_type *old_f_ptr = &f_info[oldfeat];
4722 feature_type *f_ptr = &f_info[newfeat];
4726 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
4728 /* Place some gold */
4734 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - dun_level / 2)))
4737 place_object(y, x, 0L);
4741 if (found && character_dungeon && player_can_see_bold(y, x))
4744 msg_print("²¿¤«¤òȯ¸«¤·¤¿¡ª");
4746 msg_print("You have found something!");
4753 /* Remove a mirror */
4754 void remove_mirror(int y, int x)
4756 cave_type *c_ptr = &cave[y][x];
4758 /* Remove the mirror */
4759 c_ptr->info &= ~(CAVE_OBJECT);
4762 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4764 c_ptr->info &= ~(CAVE_GLOW);
4765 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4767 /* Update the monster */
4768 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4770 update_local_illumination(y, x);
4782 * Return TRUE if there is a mirror on the grid.
4784 bool is_mirror_grid(cave_type *c_ptr)
4786 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MIRROR))
4794 * Return TRUE if there is a mirror on the grid.
4796 bool is_glyph_grid(cave_type *c_ptr)
4798 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_GLYPH))
4806 * Return TRUE if there is a mirror on the grid.
4808 bool is_explosive_rune_grid(cave_type *c_ptr)
4810 if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MINOR_GLYPH))
4818 * Calculate "incremental motion". Used by project() and shoot().
4819 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4821 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4823 int dy, dx, dist, shift;
4825 /* Extract the distance travelled */
4826 dy = (*y < y1) ? y1 - *y : *y - y1;
4827 dx = (*x < x1) ? x1 - *x : *x - x1;
4829 /* Number of steps */
4830 dist = (dy > dx) ? dy : dx;
4832 /* We are calculating the next location */
4836 /* Calculate the total distance along each axis */
4837 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4838 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4840 /* Paranoia -- Hack -- no motion */
4841 if (!dy && !dx) return;
4844 /* Move mostly vertically */
4847 /* Extract a shift factor */
4848 shift = (dist * dx + (dy - 1) / 2) / dy;
4850 /* Sometimes move along the minor axis */
4851 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4853 /* Always move along major axis */
4854 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4857 /* Move mostly horizontally */
4860 /* Extract a shift factor */
4861 shift = (dist * dy + (dx - 1) / 2) / dx;
4863 /* Sometimes move along the minor axis */
4864 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4866 /* Always move along major axis */
4867 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4874 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4875 * at the final destination, assuming no monster gets in the way.
4877 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4879 bool projectable(int y1, int x1, int y2, int x2)
4886 /* Check the projection path */
4887 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4889 /* Identical grid */
4890 if (!grid_n) return TRUE;
4893 y = GRID_Y(grid_g[grid_n - 1]);
4894 x = GRID_X(grid_g[grid_n - 1]);
4896 /* May not end in an unrequested grid */
4897 if ((y != y2) || (x != x2)) return (FALSE);
4905 * Standard "find me a location" function
4907 * Obtains a legal location within the given distance of the initial
4908 * location, and with "los()" from the source to destination location.
4910 * This function is often called from inside a loop which searches for
4911 * locations while increasing the "d" distance.
4913 * Currently the "m" parameter is unused.
4915 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4922 /* Pick a location */
4925 /* Pick a new location */
4926 ny = rand_spread(y, d);
4927 nx = rand_spread(x, d);
4929 /* Ignore annoying locations */
4930 if (!in_bounds(ny, nx)) continue;
4932 /* Ignore "excessively distant" locations */
4933 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4935 /* Require "line of projection" */
4936 if (projectable(y, x, ny, nx)) break;
4939 /* Save the location */
4948 * Track a new monster
4950 void health_track(int m_idx)
4952 /* Mount monster is already tracked */
4953 if (m_idx && m_idx == p_ptr->riding) return;
4955 /* Track a new guy */
4956 p_ptr->health_who = m_idx;
4958 /* Redraw (later) */
4959 p_ptr->redraw |= (PR_HEALTH);
4965 * Hack -- track the given monster race
4967 void monster_race_track(int r_idx)
4969 /* Save this monster ID */
4970 p_ptr->monster_race_idx = r_idx;
4973 p_ptr->window |= (PW_MONSTER);
4979 * Hack -- track the given object kind
4981 void object_kind_track(int k_idx)
4983 /* Save this monster ID */
4984 p_ptr->object_kind_idx = k_idx;
4987 p_ptr->window |= (PW_OBJECT);
4993 * Something has happened to disturb the player.
4995 * The first arg indicates a major disturbance, which affects search.
4997 * The second arg is currently unused, but could induce output flush.
4999 * All disturbance cancels repeated commands, resting, and running.
5001 void disturb(int stop_search, int unused_flag)
5004 unused_flag = unused_flag;
5006 /* Cancel auto-commands */
5007 /* command_new = 0; */
5009 /* Cancel repeated commands */
5015 /* Redraw the state (later) */
5016 p_ptr->redraw |= (PR_STATE);
5019 /* Cancel Resting */
5020 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5023 set_action(ACTION_NONE);
5026 /* Cancel running */
5032 /* Check for new panel if appropriate */
5033 if (center_player && !center_running) verify_panel();
5035 /* Calculate torch radius */
5036 p_ptr->update |= (PU_TORCH);
5038 /* Update monster flow */
5039 p_ptr->update |= (PU_FLOW);
5042 /* Flush the input if requested */
5043 if (flush_disturb) flush();
5048 * Glow deep lava and building entrances in the floor
5050 void glow_deep_lava_and_bldg(void)
5052 int y, x, i, yy, xx;
5055 /* Not in the darkness dungeon */
5056 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
5058 for (y = 0; y < cur_hgt; y++)
5060 for (x = 0; x < cur_wid; x++)
5062 c_ptr = &cave[y][x];
5064 /* Feature code (applying "mimic" field) */
5066 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_GLOW))
5068 for (i = 0; i < 9; i++)
5070 yy = y + ddy_ddd[i];
5071 xx = x + ddx_ddd[i];
5072 if (!in_bounds2(yy, xx)) continue;
5073 cave[yy][xx].info |= CAVE_GLOW;
5079 /* Update the view and lite */
5080 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
5083 p_ptr->redraw |= (PR_MAP);