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)
69 case FEAT_TRAP_TRAPDOOR:
71 case FEAT_TRAP_SPIKED_PIT:
72 case FEAT_TRAP_POISON_PIT:
73 case FEAT_TRAP_TY_CURSE:
74 case FEAT_TRAP_TELEPORT:
78 case FEAT_TRAP_LOSE_STR:
79 case FEAT_TRAP_LOSE_DEX:
80 case FEAT_TRAP_LOSE_CON:
82 case FEAT_TRAP_CONFUSE:
83 case FEAT_TRAP_POISON:
88 case FEAT_TRAP_ARMAGEDDON:
89 case FEAT_TRAP_PIRANHA:
104 * Return TRUE if the given grid is a known trap
106 bool is_known_trap(cave_type *c_ptr)
108 if (!c_ptr->mimic && is_trap(c_ptr->feat)) return TRUE;
114 * Return TRUE if the given grid is a closed door
116 bool is_closed_door(int feat)
118 return (feat >= FEAT_DOOR_HEAD && feat <= FEAT_DOOR_TAIL);
123 * Return TRUE if the given grid is a hidden closed door
125 bool is_hidden_door(cave_type *c_ptr)
128 is_closed_door(c_ptr->feat))
136 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,
137 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.
139 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
141 * The LOS begins at the center of the tile (x1,y1) and ends at the center of
142 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line
143 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
145 * We assume that the "mathematical corner" of a non-floor tile does not
146 * block line of sight.
148 * Because this function uses (short) ints for all calculations, overflow may
149 * occur if dx and dy exceed 90.
151 * Once all the degenerate cases are eliminated, the values "qx", "qy", and
152 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
153 * we can use integer arithmetic.
155 * We travel from start to finish along the longer axis, starting at the border
156 * between the first and second tiles, where the y offset = .5 * slope, taking
157 * into account the scale factor. See below.
159 * Also note that this function and the "move towards target" code do NOT
160 * share the same properties. Thus, you can see someone, target them, and
161 * then fire a bolt at them, but the bolt may hit a wall, not them. However,
162 * by clever choice of target locations, you can sometimes throw a "curve".
164 * Note that "line of sight" is not "reflexive" in all cases.
166 * Use the "projectable()" routine to test "spell/missile line of sight".
168 * Use the "update_view()" function to determine player line-of-sight.
170 bool los(int y1, int x1, int y2, int x2)
190 /* Slope, or 1/Slope, of LOS */
194 /* Extract the offset */
198 /* Extract the absolute offset */
203 /* Handle adjacent (or identical) grids */
204 if ((ax < 2) && (ay < 2)) return (TRUE);
207 /* Paranoia -- require "safe" origin */
208 /* if (!in_bounds(y1, x1)) return (FALSE); */
209 /* if (!in_bounds(y2, x2)) return (FALSE); */
212 /* Directly South/North */
215 /* South -- check for walls */
218 for (ty = y1 + 1; ty < y2; ty++)
220 if (!cave_floor_bold(ty, x1)) return (FALSE);
224 /* North -- check for walls */
227 for (ty = y1 - 1; ty > y2; ty--)
229 if (!cave_floor_bold(ty, x1)) return (FALSE);
237 /* Directly East/West */
240 /* East -- check for walls */
243 for (tx = x1 + 1; tx < x2; tx++)
245 if (!cave_floor_bold(y1, tx)) return (FALSE);
249 /* West -- check for walls */
252 for (tx = x1 - 1; tx > x2; tx--)
254 if (!cave_floor_bold(y1, tx)) return (FALSE);
263 /* Extract some signs */
264 sx = (dx < 0) ? -1 : 1;
265 sy = (dy < 0) ? -1 : 1;
268 /* Vertical "knights" */
273 if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
277 /* Horizontal "knights" */
282 if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
287 /* Calculate scale factor div 2 */
290 /* Calculate scale factor */
294 /* Travel horizontally */
297 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
303 /* Consider the special case where slope == 1. */
314 /* Note (below) the case (qy == f2), where */
315 /* the LOS exactly meets the corner of a tile. */
318 if (!cave_floor_bold(ty, tx)) return (FALSE);
329 if (!cave_floor_bold(ty, tx)) return (FALSE);
342 /* Travel vertically */
345 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
361 /* Note (below) the case (qx == f2), where */
362 /* the LOS exactly meets the corner of a tile. */
365 if (!cave_floor_bold(ty, tx)) return (FALSE);
376 if (!cave_floor_bold(ty, tx)) return (FALSE);
399 * Can the player "see" the given grid in detail?
401 * He must have vision, illumination, and line of sight.
403 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
404 * So, given "CAVE_LITE", we know that the grid is "fully visible".
406 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
407 * that a wall is visible from any direction. That would be odd. Except
408 * under wizard light, which might make sense. Thus, for walls, we require
409 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
410 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
411 * in line of sight of the player.
413 * This extra check is expensive, but it provides a more "correct" semantics.
415 * Note that we should not run this check on walls which are "outer walls" of
416 * the dungeon, or we will induce a memory fault, but actually verifying all
417 * of the locations would be extremely expensive.
419 * Thus, to speed up the function, we assume that all "perma-walls" which are
420 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
421 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
422 * and the player has more important things on his mind when he is attacking a
423 * monster vault. It is annoying, but an extremely important optimization.
425 * Note that "glowing walls" are only considered to be "illuminated" if the
426 * grid which is next to the wall in the direction of the player is also a
427 * "glowing" grid. This prevents the player from being able to "see" the
428 * walls of illuminated rooms from a corridor outside the room.
430 bool player_can_see_bold(int y, int x)
436 /* Blind players see nothing */
437 if (p_ptr->blind) return (FALSE);
439 /* Access the cave grid */
442 /* Note that "torch-lite" yields "illumination" */
443 if (c_ptr->info & (CAVE_LITE)) return (TRUE);
445 /* Require line of sight to the grid */
446 if (!player_has_los_bold(y, x)) return (FALSE);
448 /* Ninja or Vampire without lite */
449 if (p_ptr->see_nocto > p_ptr->cur_lite)
451 if (p_ptr->see_nocto == MAX_SIGHT) return TRUE;
454 if ((y >= (py - 1)) && (y <= (py + 1)) && (x >= (px - 1)) && (x <= (px + 1))) return TRUE;
458 /* Require "perma-lite" of the grid */
459 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return (FALSE);
461 /* Floors are simple */
462 if (cave_floor_bold(y, x)) return (TRUE);
464 /* Hack -- move towards player */
465 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
466 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
468 /* Check for "local" illumination */
469 if (cave[yy][xx].info & (CAVE_GLOW | CAVE_MNLT))
471 /* Assume the wall is really illuminated */
475 /* Assume not visible */
482 * Returns true if the player's grid is dark
486 return (!player_can_see_bold(py, px));
493 * Determine if a given location may be "destroyed"
495 * Used by destruction spells, and for placing stairs, etc.
497 bool cave_valid_bold(int y, int x)
499 cave_type *c_ptr = &cave[y][x];
501 s16b this_o_idx, next_o_idx = 0;
504 /* Forbid perma-grids */
505 if (cave_perma_grid(c_ptr)) return (FALSE);
508 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
513 o_ptr = &o_list[this_o_idx];
515 /* Acquire next object */
516 next_o_idx = o_ptr->next_o_idx;
518 /* Forbid artifact grids */
519 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
530 * Determine if a given location may be "destroyed"
532 * Used by destruction spells, and for placing stairs, etc.
534 bool cave_valid_grid(cave_type *c_ptr)
536 s16b this_o_idx, next_o_idx = 0;
539 /* Forbid perma-grids */
540 if (cave_perma_grid(c_ptr)) return (FALSE);
543 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
548 o_ptr = &o_list[this_o_idx];
550 /* Acquire next object */
551 next_o_idx = o_ptr->next_o_idx;
553 /* Forbid artifact grids */
554 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
565 * Hack -- Legal monster codes
567 static char image_monster_hack[] = \
568 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
571 * Mega-Hack -- Hallucinatory monster
573 static void image_monster(byte *ap, char *cp)
575 /* Random symbol from set above */
578 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
586 int n = sizeof(image_monster_hack) - 1;
588 *cp = image_monster_hack[randint0(n)];
598 * Hack -- Legal object codes
600 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
603 * Mega-Hack -- Hallucinatory object
605 static void image_object(byte *ap, char *cp)
609 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
616 int n = sizeof(image_object_hack) - 1;
618 *cp = image_object_hack[randint0(n)];
628 * Hack -- Random hallucination
630 static void image_random(byte *ap, char *cp)
632 /* Normally, assume monsters */
633 if (randint0(100) < 75)
635 image_monster(ap, cp);
638 /* Otherwise, assume objects */
641 image_object(ap, cp);
646 * Not using graphical tiles for this feature?
648 #define is_ascii_graphics(A) (!((A) & 0x80))
651 * The 16x16 tile of the terrain supports lighting
653 static bool feat_supports_lighting(byte feat)
655 if (is_trap(feat)) return streq(ANGBAND_GRAF, "new");
673 case FEAT_WALL_EXTRA:
674 case FEAT_WALL_INNER:
675 case FEAT_WALL_OUTER:
676 case FEAT_WALL_SOLID:
677 case FEAT_PERM_EXTRA:
678 case FEAT_PERM_INNER:
679 case FEAT_PERM_OUTER:
680 case FEAT_PERM_SOLID:
681 case FEAT_MINOR_GLYPH:
682 case FEAT_DEEP_WATER:
683 case FEAT_SHAL_WATER:
690 case FEAT_DEEP_GRASS:
701 * This array lists the effects of "brightness" on various "base" colours.
703 * This is used to do dynamic lighting effects in ascii :-)
704 * At the moment, only the various "floor" tiles are affected.
706 * The layout of the array is [x][0] = light and [x][1] = dark.
709 static byte lighting_colours[16][2] =
712 {TERM_L_DARK, TERM_DARK},
715 {TERM_YELLOW, TERM_SLATE},
718 {TERM_WHITE, TERM_L_DARK},
721 {TERM_L_UMBER, TERM_UMBER},
724 {TERM_RED, TERM_RED},
727 {TERM_L_GREEN, TERM_GREEN},
730 {TERM_BLUE, TERM_BLUE},
733 {TERM_L_UMBER, TERM_RED},
736 {TERM_SLATE, TERM_L_DARK},
739 {TERM_WHITE, TERM_SLATE},
742 {TERM_L_RED, TERM_BLUE},
745 {TERM_YELLOW, TERM_ORANGE},
748 {TERM_L_RED, TERM_L_RED},
751 {TERM_L_GREEN, TERM_GREEN},
754 {TERM_L_BLUE, TERM_L_BLUE},
757 {TERM_L_UMBER, TERM_UMBER}
761 * Extract the attr/char to display at the given (legal) map location
763 * Basically, we "paint" the chosen attr/char in several passes, starting
764 * with any known "terrain features" (defaulting to darkness), then adding
765 * any known "objects", and finally, adding any known "monsters". This
766 * is not the fastest method but since most of the calls to this function
767 * are made for grids with no monsters or objects, it is fast enough.
769 * Note that this function, if used on the grid containing the "player",
770 * will return the attr/char of the grid underneath the player, and not
771 * the actual player attr/char itself, allowing a lot of optimization
772 * in various "display" functions.
774 * Note that the "zero" entry in the feature/object/monster arrays are
775 * used to provide "special" attr/char codes, with "monster zero" being
776 * used for the player attr/char, "object zero" being used for the "stack"
777 * attr/char, and "feature zero" being used for the "nothing" attr/char,
778 * though this function makes use of only "feature zero".
780 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
781 * which means their color changes, and "ATTR_CLEAR", which means they take
782 * the color of whatever is under them, and "CHAR_CLEAR", which means that
783 * they take the symbol of whatever is under them. Technically, the flag
784 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
785 * examined, but this flag is currently ignored.
787 * Currently, we do nothing with multi-hued objects, because there are
788 * not any. If there were, they would have to set "shimmer_objects"
789 * when they were created, and then new "shimmer" code in "dungeon.c"
790 * would have to be created handle the "shimmer" effect, and the code
791 * in "cave.c" would have to be updated to create the shimmer effect.
793 * Note the effects of hallucination. Objects always appear as random
794 * "objects", monsters as random "monsters", and normal grids occasionally
795 * appear as random "monsters" or "objects", but note that these random
796 * "monsters" and "objects" are really just "colored ascii symbols".
798 * Note that "floors" and "invisible traps" (and "zero" features) are
799 * drawn as "floors" using a special check for optimization purposes,
800 * and these are the only features which get drawn using the special
801 * lighting effects activated by "view_special_lite".
803 * Note the use of the "mimic" field in the "terrain feature" processing,
804 * which allows any feature to "pretend" to be another feature. This is
805 * used to "hide" secret doors, and to make all "doors" appear the same,
806 * and all "walls" appear the same, and "hidden" treasure stay hidden.
807 * It is possible to use this field to make a feature "look" like a floor,
808 * but the "special lighting effects" for floors will not be used.
810 * Note the use of the new "terrain feature" information. Note that the
811 * assumption that all interesting "objects" and "terrain features" are
812 * memorized allows extremely optimized processing below. Note the use
813 * of separate flags on objects to mark them as memorized allows a grid
814 * to have memorized "terrain" without granting knowledge of any object
815 * which may appear in that grid.
817 * Note the efficient code used to determine if a "floor" grid is
818 * "memorized" or "viewable" by the player, where the test for the
819 * grid being "viewable" is based on the facts that (1) the grid
820 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
821 * line of sight, and (3) the player must not be blind, and uses the
822 * assumption that all torch-lit grids are in line of sight.
824 * Note that floors (and invisible traps) are the only grids which are
825 * not memorized when seen, so only these grids need to check to see if
826 * the grid is "viewable" to the player (if it is not memorized). Since
827 * most non-memorized grids are in fact walls, this induces *massive*
828 * efficiency, at the cost of *forcing* the memorization of non-floor
829 * grids when they are first seen. Note that "invisible traps" are
830 * always treated exactly like "floors", which prevents "cheating".
832 * Note the "special lighting effects" which can be activated for floor
833 * grids using the "view_special_lite" option (for "white" floor grids),
834 * causing certain grids to be displayed using special colors. If the
835 * player is "blind", we will use "dark gray", else if the grid is lit
836 * by the torch, and the "view_yellow_lite" option is set, we will use
837 * "yellow", else if the grid is "dark", we will use "dark gray", else
838 * if the grid is not "viewable", and the "view_bright_lite" option is
839 * set, and the we will use "slate" (gray). We will use "white" for all
840 * other cases, in particular, for illuminated viewable floor grids.
842 * Note the "special lighting effects" which can be activated for wall
843 * grids using the "view_granite_lite" option (for "white" wall grids),
844 * causing certain grids to be displayed using special colors. If the
845 * player is "blind", we will use "dark gray", else if the grid is lit
846 * by the torch, and the "view_yellow_lite" option is set, we will use
847 * "yellow", else if the "view_bright_lite" option is set, and the grid
848 * is not "viewable", or is "dark", or is glowing, but not when viewed
849 * from the player's current location, we will use "slate" (gray). We
850 * will use "white" for all other cases, in particular, for correctly
851 * illuminated viewable wall grids.
853 * Note that, when "view_granite_lite" is set, we use an inline version
854 * of the "player_can_see_bold()" function to check the "viewability" of
855 * grids when the "view_bright_lite" option is set, and we do NOT use
856 * any special colors for "dark" wall grids, since this would allow the
857 * player to notice the walls of illuminated rooms from a hallway that
858 * happened to run beside the room. The alternative, by the way, would
859 * be to prevent the generation of hallways next to rooms, but this
860 * would still allow problems when digging towards a room.
862 * Note that bizarre things must be done when the "attr" and/or "char"
863 * codes have the "high-bit" set, since these values are used to encode
864 * various "special" pictures in some versions, and certain situations,
865 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
866 * to be "scrambled" in various ways.
868 * Note that eventually we may use the "&" symbol for embedded treasure,
869 * and use the "*" symbol to indicate multiple objects, though this will
870 * have to wait for Angband 2.8.0 or later. Note that currently, this
871 * is not important, since only one object or terrain feature is allowed
872 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
874 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
875 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
876 * then a whole lot of code should be changed... XXX XXX
878 #ifdef USE_TRANSPARENCY
879 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
880 #else /* USE_TRANSPARENCY */
881 void map_info(int y, int x, byte *ap, char *cp)
882 #endif /* USE_TRANSPARENCY */
888 s16b this_o_idx, next_o_idx = 0;
895 bool can_see_dark_grid;
900 /* Feature code (applying "mimic" field) */
901 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
904 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
907 if (p_ptr->see_nocto <= p_ptr->cur_lite) can_see_dark_grid = FALSE;
909 /* Ninja or Vampire without lite */
912 if (p_ptr->see_nocto == MAX_SIGHT) can_see_dark_grid = TRUE;
915 if ((y < (py - 1)) || (y > (py + 1)) || (x < (px - 1)) || (x > (px + 1))) can_see_dark_grid = FALSE;
916 else can_see_dark_grid = TRUE;
920 /* Memorized (or visible) floor */
921 if ((c_ptr->info & CAVE_MARK) ||
922 (((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) ||
923 ((c_ptr->info & CAVE_VIEW) &&
924 ((c_ptr->info & CAVE_GLOW) || can_see_dark_grid))) &&
928 f_ptr = &f_info[feat];
936 /* Special lighting effects */
937 if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_graphics))
945 * feat_supports_lighting(feat)
946 * is always TRUE here
949 /* Use a dark tile */
954 /* Use "dark gray" */
959 /* Handle "torch-lit" grids */
960 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
963 if (view_yellow_lite && !p_ptr->wild_mode)
968 * feat_supports_lighting(feat)
969 * is always TRUE here
972 /* Use a brightly lit tile */
983 /* Handle "dark" grids */
984 else if (!(c_ptr->info & CAVE_GLOW))
989 * feat_supports_lighting(feat)
990 * is always TRUE here
993 /* Use a dark tile */
998 /* Use "dark gray" */
1003 /* Handle "out-of-sight" grids */
1004 else if (!(c_ptr->info & CAVE_VIEW))
1007 if (view_bright_lite && !p_ptr->wild_mode)
1012 * feat_supports_lighting(feat)
1013 * is always TRUE here
1016 /* Use a dark tile */
1032 /* Unsafe cave grid -- idea borrowed from Unangband */
1033 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1034 feat = FEAT_UNDETECTD;
1038 /* Access darkness */
1039 f_ptr = &f_info[feat];
1052 /* Memorized grids */
1053 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || new_ascii_graphics))
1055 /* Access feature */
1056 f_ptr = &f_info[feat];
1064 if (new_ascii_graphics)
1066 /* Handle "blind" */
1069 if (is_ascii_graphics(a))
1071 /* Use darkened colour */
1072 a = lighting_colours[a][1];
1074 else if (use_graphics && feat_supports_lighting(feat))
1076 /* Use a dark tile */
1081 /* Handle "torch-lit" grids */
1082 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1085 if (view_yellow_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(a)))
1087 if (is_ascii_graphics(a))
1089 /* Use lightened colour */
1090 a = lighting_colours[a][0];
1092 else if (use_graphics &&
1093 feat_supports_lighting(feat))
1095 /* Use a brightly lit tile */
1101 /* Handle "view_bright_lite" */
1102 else if (view_bright_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(a)))
1105 if (!(c_ptr->info & CAVE_VIEW))
1107 if (is_ascii_graphics(a))
1109 /* Use darkened colour */
1110 a = lighting_colours[a][1];
1112 else if (use_graphics && feat_supports_lighting(feat))
1114 /* Use a dark tile */
1120 else if (!(c_ptr->info & CAVE_GLOW))
1122 if (is_ascii_graphics(a))
1124 /* Use darkened colour */
1125 a = lighting_colours[a][1];
1130 /* Special lighting effects */
1131 else if (view_granite_lite && !p_ptr->wild_mode &&
1132 (((a == TERM_WHITE) && !use_graphics) ||
1133 (use_graphics && feat_supports_lighting(feat))))
1135 /* Handle "blind" */
1140 /* Use a dark tile */
1145 /* Use "dark gray" */
1150 /* Handle "torch-lit" grids */
1151 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1154 if (view_yellow_lite && !p_ptr->wild_mode)
1158 /* Use a brightly lit tile */
1169 /* Handle "view_bright_lite" */
1170 else if (view_bright_lite && !p_ptr->wild_mode)
1173 if (!(c_ptr->info & CAVE_VIEW))
1177 /* Use a dark tile */
1188 else if (!(c_ptr->info & CAVE_GLOW))
1192 /* Use a lit tile */
1201 /* Not glowing correctly */
1206 /* Hack -- move towards player */
1207 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1208 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1210 /* Check for "local" illumination */
1211 if (!(cave[yy][xx].info & CAVE_GLOW))
1215 /* Use a lit tile */
1228 /* "Simple Lighting" */
1231 /* Handle "blind" */
1232 if (!(c_ptr->info & CAVE_MARK))
1234 /* Unsafe cave grid -- idea borrowed from Unangband */
1235 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1236 feat = FEAT_UNDETECTD;
1241 /* Access feature */
1242 f_ptr = &f_info[feat];
1252 if (feat_priority == -1)
1257 case FEAT_UNDETECTD:
1264 case FEAT_TRAP_TRAPDOOR:
1266 case FEAT_TRAP_SPIKED_PIT:
1267 case FEAT_TRAP_POISON_PIT:
1268 case FEAT_TRAP_TY_CURSE:
1269 case FEAT_TRAP_TELEPORT:
1270 case FEAT_TRAP_FIRE:
1271 case FEAT_TRAP_ACID:
1272 case FEAT_TRAP_SLOW:
1273 case FEAT_TRAP_LOSE_STR:
1274 case FEAT_TRAP_LOSE_DEX:
1275 case FEAT_TRAP_LOSE_CON:
1276 case FEAT_TRAP_BLIND:
1277 case FEAT_TRAP_CONFUSE:
1278 case FEAT_TRAP_POISON:
1279 case FEAT_TRAP_SLEEP:
1280 case FEAT_TRAP_TRAPS:
1281 case FEAT_TRAP_ALARM:
1285 case FEAT_DEEP_GRASS:
1293 case FEAT_WALL_EXTRA:
1294 case FEAT_WALL_INNER:
1295 case FEAT_WALL_OUTER:
1296 case FEAT_WALL_SOLID:
1297 case FEAT_DEEP_WATER:
1298 case FEAT_SHAL_WATER:
1299 case FEAT_DEEP_LAVA:
1300 case FEAT_SHAL_LAVA:
1306 /* Now a days treasere grid is too many */
1311 case FEAT_PERM_EXTRA:
1312 case FEAT_PERM_INNER:
1313 case FEAT_PERM_OUTER:
1314 case FEAT_PERM_SOLID:
1318 /* default is feat_priority = 20; (doors and stores) */
1321 case FEAT_MINOR_GLYPH:
1323 case FEAT_PATTERN_START:
1324 case FEAT_PATTERN_1:
1325 case FEAT_PATTERN_2:
1326 case FEAT_PATTERN_3:
1327 case FEAT_PATTERN_4:
1328 case FEAT_PATTERN_END:
1329 case FEAT_PATTERN_OLD:
1330 case FEAT_PATTERN_XTRA1:
1331 case FEAT_PATTERN_XTRA2:
1335 /* objects have feat_priority = 20 */
1336 /* monsters have feat_priority = 30 */
1340 case FEAT_QUEST_ENTER:
1341 case FEAT_QUEST_EXIT:
1342 case FEAT_QUEST_DOWN:
1344 case FEAT_LESS_LESS:
1345 case FEAT_MORE_MORE:
1357 #ifdef USE_TRANSPARENCY
1358 /* Save the terrain info for the transparency effects */
1361 #endif /* USE_TRANSPARENCY */
1367 /* Hack -- rare random hallucination, except on outer dungeon walls */
1368 if (p_ptr->image && (feat < FEAT_PERM_SOLID) && one_in_(256))
1371 image_random(ap, cp);
1375 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1379 /* Acquire object */
1380 o_ptr = &o_list[this_o_idx];
1382 /* Acquire next object */
1383 next_o_idx = o_ptr->next_o_idx;
1385 /* Memorized objects */
1388 if (display_autopick)
1392 match_autopick = is_autopick(o_ptr);
1393 if(match_autopick == -1)
1396 act = autopick_list[match_autopick].action;
1398 if ((act & DO_DISPLAY) && (act & display_autopick))
1400 autopick_obj = o_ptr;
1404 match_autopick = -1;
1409 (*cp) = object_char(o_ptr);
1412 (*ap) = object_attr(o_ptr);
1416 /* Hack -- hallucination */
1417 if (p_ptr->image) image_object(ap, cp);
1425 /* Handle monsters */
1426 if (c_ptr->m_idx && display_autopick == 0 )
1428 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1430 /* Visible monster */
1433 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1441 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1442 * flags are always unseen.
1444 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1450 /* Hallucinatory monster */
1451 image_monster(ap, cp);
1456 /* Monster attr/char */
1460 /* Normal monsters */
1461 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1462 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1464 /* Desired monster attr/char */
1470 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1471 * flags are always unseen.
1473 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1480 /*** Monster's attr ***/
1481 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1486 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1488 /* Multi-hued attr */
1489 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1490 else switch (randint1(7))
1492 case 1: *ap = TERM_RED; break;
1493 case 2: *ap = TERM_L_RED; break;
1494 case 3: *ap = TERM_WHITE; break;
1495 case 4: *ap = TERM_L_GREEN; break;
1496 case 5: *ap = TERM_BLUE; break;
1497 case 6: *ap = TERM_L_DARK; break;
1498 case 7: *ap = TERM_GREEN; break;
1501 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1503 /* Use semi-random attr (usually mimics' colors vary) */
1504 *ap = c_ptr->m_idx % 15 + 1;
1512 /*** Monster's char ***/
1513 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1518 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1522 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1523 *cp = tmp_r_ptr->x_char;
1524 *ap = tmp_r_ptr->x_attr;
1528 *cp = (one_in_(25) ?
1529 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1530 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1543 /* Handle "player" */
1544 if (player_bold(y, x))
1546 monster_race *r_ptr = &r_info[0];
1548 /* Get the "player" attr */
1549 *ap = r_ptr->x_attr;
1551 /* Get the "player" char */
1552 *cp = r_ptr->x_char;
1561 * Table of Ascii-to-Zenkaku
1562 * ¡Ö¢£¡×¤ÏÆóÇÜÉýƦÉå¤ÎÆâÉô¥³¡¼¥É¤Ë»ÈÍÑ¡£
1564 static char ascii_to_zenkaku[2*128+1] = "\
1565 ¡¡¡ª¡É¡ô¡ð¡ó¡õ¡Ç¡Ê¡Ë¡ö¡Ü¡¤¡Ý¡¥¡¿\
1566 £°£±£²£³£´£µ£¶£·£¸£¹¡§¡¨¡ã¡á¡ä¡©\
1567 ¡÷£Á£Â£Ã£Ä£Å£Æ£Ç£È£É£Ê£Ë£Ì£Í£Î£Ï\
1568 £Ð£Ñ£Ò£Ó£Ô£Õ£Ö£×£Ø£Ù£Ú¡Î¡À¡Ï¡°¡²\
1569 ¡Æ£á£â£ã£ä£å£æ£ç£è£é£ê£ë£ì£í£î£ï\
1570 £ð£ñ£ò£ó£ô£õ£ö£÷£ø£ù£ú¡Ð¡Ã¡Ñ¡Á¢£";
1574 * Prepare Bigtile or 2-bytes character attr/char pairs
1576 void bigtile_attr(char *cp, byte *ap, char *cp2, byte *ap2)
1578 if ((*ap & 0x80) && (*cp & 0x80))
1586 if (isprint(*cp) || *cp == 127)
1588 *ap2 = (*ap) | 0xf0;
1589 *cp2 = ascii_to_zenkaku[2*(*cp-' ') + 1];
1590 *cp = ascii_to_zenkaku[2*(*cp-' ')];
1601 * Calculate panel colum of a location in the map
1603 static int panel_col_of(int col)
1605 col -= panel_col_min;
1606 if (use_bigtile) col *= 2;
1612 * Moves the cursor to a given MAP (y,x) location
1614 void move_cursor_relative(int row, int col)
1616 /* Real co-ords convert to screen positions */
1617 row -= panel_row_prt;
1620 Term_gotoxy(panel_col_of(col), row);
1626 * Place an attr/char pair at the given map coordinate, if legal.
1628 void print_rel(char c, byte a, int y, int x)
1633 /* Only do "legal" locations */
1634 if (panel_contains(y, x))
1636 /* Hack -- fake monochrome */
1639 if (world_monster) a = TERM_DARK;
1640 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1641 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1644 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
1646 /* Draw the char using the attr */
1647 Term_draw(panel_col_of(x), y-panel_row_prt, a, c);
1649 Term_draw(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
1658 * Memorize interesting viewable object/features in the given grid
1660 * This function should only be called on "legal" grids.
1662 * This function will memorize the object and/or feature in the given
1663 * grid, if they are (1) viewable and (2) interesting. Note that all
1664 * objects are interesting, all terrain features except floors (and
1665 * invisible traps) are interesting, and floors (and invisible traps)
1666 * are interesting sometimes (depending on various options involving
1667 * the illumination of floor grids).
1669 * The automatic memorization of all objects and non-floor terrain
1670 * features as soon as they are displayed allows incredible amounts
1671 * of optimization in various places, especially "map_info()".
1673 * Note that the memorization of objects is completely separate from
1674 * the memorization of terrain features, preventing annoying floor
1675 * memorization when a detected object is picked up from a dark floor,
1676 * and object memorization when an object is dropped into a floor grid
1677 * which is memorized but out-of-sight.
1679 * This function should be called every time the "memorization" of
1680 * a grid (or the object in a grid) is called into question, such
1681 * as when an object is created in a grid, when a terrain feature
1682 * "changes" from "floor" to "non-floor", when any grid becomes
1683 * "illuminated" or "viewable", and when a "floor" grid becomes
1686 * Note the relatively efficient use of this function by the various
1687 * "update_view()" and "update_lite()" calls, to allow objects and
1688 * terrain features to be memorized (and drawn) whenever they become
1689 * viewable or illuminated in any way, but not when they "maintain"
1690 * or "lose" their previous viewability or illumination.
1692 * Note the butchered "internal" version of "player_can_see_bold()",
1693 * optimized primarily for the most common cases, that is, for the
1694 * non-marked floor grids.
1696 void note_spot(int y, int x)
1698 cave_type *c_ptr = &cave[y][x];
1700 s16b this_o_idx, next_o_idx = 0;
1704 /* Feature code (applying "mimic" field) */
1705 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
1708 /* Blind players see nothing */
1709 if (p_ptr->blind) return;
1711 /* Analyze non-torch-lit grids */
1712 if (!(c_ptr->info & (CAVE_LITE)))
1714 /* Require line of sight to the grid */
1715 if (!(c_ptr->info & (CAVE_VIEW))) return;
1717 /* Require "perma-lite" of the grid */
1718 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT)))
1720 /* Neither Ninja nor Vampire without lite */
1721 if (p_ptr->see_nocto <= p_ptr->cur_lite) return;
1723 /* Hack -- Vampires' noctovision is limited to adjacent grids */
1724 else if (p_ptr->see_nocto == 1)
1726 if ((y < (py - 1)) || (y > (py + 1)) || (x < (px - 1)) || (x > (px + 1))) return;
1732 /* Hack -- memorize objects */
1733 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1735 object_type *o_ptr = &o_list[this_o_idx];
1737 /* Acquire next object */
1738 next_o_idx = o_ptr->next_o_idx;
1740 /* Memorize objects */
1741 o_ptr->marked |= OM_FOUND;
1745 /* Hack -- memorize grids */
1746 if (!(c_ptr->info & (CAVE_MARK)))
1748 /* Handle floor grids first */
1749 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
1751 /* Option -- memorize all torch-lit floors */
1752 if (view_torch_grids &&
1753 ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1756 c_ptr->info |= (CAVE_MARK);
1759 /* Option -- memorize all perma-lit floors */
1760 else if (view_perma_grids && (c_ptr->info & (CAVE_GLOW)))
1763 c_ptr->info |= (CAVE_MARK);
1767 /* Memorize normal grids */
1768 else if (cave_floor_grid(c_ptr))
1771 c_ptr->info |= (CAVE_MARK);
1774 /* Memorize torch-lit walls */
1775 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1778 c_ptr->info |= (CAVE_MARK);
1781 /* Mwemorize walls seen by noctovision of Ninja or Vampire */
1782 else if (p_ptr->see_nocto)
1785 c_ptr->info |= (CAVE_MARK);
1788 /* Memorize certain non-torch-lit wall grids */
1793 /* Hack -- move one grid towards player */
1794 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1795 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1797 /* Check for "local" illumination */
1798 if (cave[yy][xx].info & (CAVE_GLOW))
1801 c_ptr->info |= (CAVE_MARK);
1808 void display_dungeon(void)
1814 #ifdef USE_TRANSPARENCY
1817 #endif /* USE_TRANSPARENCY */
1819 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1821 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1823 if (in_bounds2(y, x))
1826 #ifdef USE_TRANSPARENCY
1827 /* Examine the grid */
1828 map_info(y, x, &a, &c, &ta, &tc);
1829 #else /* USE_TRANSPARENCY */
1830 /* Examine the grid */
1831 map_info(y, x, &a, &c);
1832 #endif /* USE_TRANSPARENCY */
1834 /* Hack -- fake monochrome */
1837 if (world_monster) a = TERM_DARK;
1838 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1839 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1842 #ifdef USE_TRANSPARENCY
1843 /* Hack -- Queue it */
1844 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1845 #else /* USE_TRANSPARENCY */
1846 /* Hack -- Queue it */
1847 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
1848 #endif /* USE_TRANSPARENCY */
1853 /* Clear out-of-bound tiles */
1855 /* Access darkness */
1856 feature_type *f_ptr = &f_info[FEAT_NONE];
1864 #ifdef USE_TRANSPARENCY
1865 /* Hack -- Queue it */
1866 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1867 #else /* USE_TRANSPARENCY */
1868 /* Hack -- Queue it */
1869 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
1870 #endif /* USE_TRANSPARENCY */
1878 * Redraw (on the screen) a given MAP location
1880 * This function should only be called on "legal" grids
1882 void lite_spot(int y, int x)
1884 /* Redraw if on screen */
1885 if (panel_contains(y, x) && in_bounds2(y, x))
1890 #ifdef USE_TRANSPARENCY
1894 /* Examine the grid */
1895 map_info(y, x, &a, &c, &ta, &tc);
1896 #else /* USE_TRANSPARENCY */
1897 /* Examine the grid */
1898 map_info(y, x, &a, &c);
1899 #endif /* USE_TRANSPARENCY */
1901 /* Hack -- fake monochrome */
1904 if (world_monster) a = TERM_DARK;
1905 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1906 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1910 if (use_bigtile && is_ascii_graphics(a) && (isprint(c) || c == 127))
1912 /* Term_queue_chars ¤ÏÁ´³ÑASCIIÃÏ·Á¤òÀµ¤·¤¯update¤¹¤ë¡£ */
1913 Term_queue_chars(panel_col_of(x), y-panel_row_prt, 2, a, &ascii_to_zenkaku[2*(c-' ')]);
1918 #ifdef USE_TRANSPARENCY
1919 /* Hack -- Queue it */
1920 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1922 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1, 0, 0);
1923 #else /* USE_TRANSPARENCY */
1924 /* Hack -- Queue it */
1925 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
1927 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1);
1928 #endif /* USE_TRANSPARENCY */
1930 /* Update sub-windows */
1931 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1937 * Prints the map of the dungeon
1939 * Note that, for efficiency, we contain an "optimized" version
1940 * of both "lite_spot()" and "print_rel()", and that we use the
1941 * "lite_spot()" function to display the player grid, if needed.
1949 s16b xmin, xmax, ymin, ymax;
1954 Term_get_size(&wid, &hgt);
1956 /* Remove map offset */
1960 /* Access the cursor state */
1961 (void)Term_get_cursor(&v);
1963 /* Hide the cursor */
1964 (void)Term_set_cursor(0);
1967 xmin = (0 < panel_col_min) ? panel_col_min : 0;
1968 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1969 ymin = (0 < panel_row_min) ? panel_row_min : 0;
1970 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1972 /* Bottom section of screen */
1973 for (y = 1; y <= ymin - panel_row_prt; y++)
1975 /* Erase the section */
1976 Term_erase(COL_MAP, y, wid);
1979 /* Top section of screen */
1980 for (y = ymax - panel_row_prt; y <= hgt; y++)
1982 /* Erase the section */
1983 Term_erase(COL_MAP, y, wid);
1987 for (y = ymin; y <= ymax; y++)
1989 /* Scan the columns of row "y" */
1990 for (x = xmin; x <= xmax; x++)
1995 #ifdef USE_TRANSPARENCY
1999 /* Determine what is there */
2000 map_info(y, x, &a, &c, &ta, &tc);
2002 /* Determine what is there */
2003 map_info(y, x, &a, &c);
2006 /* Hack -- fake monochrome */
2009 if (world_monster) a = TERM_DARK;
2010 else if (IS_INVULN() || world_player) a = TERM_WHITE;
2011 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2014 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2016 /* Efficiency -- Redraw that grid of the map */
2017 #ifdef USE_TRANSPARENCY
2018 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
2019 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2, 0, 0);
2021 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
2022 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
2027 /* Display player */
2030 /* Restore the cursor */
2031 (void)Term_set_cursor(v);
2037 * print project path
2039 void prt_path(int y, int x)
2044 int default_color = TERM_SLATE;
2046 if (!display_path) return;
2047 if (-1 == project_length)
2050 /* Get projection path */
2051 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2054 p_ptr->redraw |= (PR_MAP);
2060 for (i = 0; i < path_n; i++)
2062 int ny = GRID_Y(path_g[i]);
2063 int nx = GRID_X(path_g[i]);
2065 if (panel_contains(ny, nx))
2067 byte a2, a = default_color;
2070 #ifdef USE_TRANSPARENCY
2075 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2077 /* Determine what is there */
2078 #ifdef USE_TRANSPARENCY
2079 map_info(ny, nx, &a, &c, &ta, &tc);
2081 map_info(ny, nx, &a, &c);
2083 if (!is_ascii_graphics(a))
2085 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2087 else if (a == default_color)
2093 if (world_monster) a = TERM_DARK;
2094 else if (IS_INVULN() || world_player) a = TERM_WHITE;
2095 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2099 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2101 /* Hack -- Queue it */
2102 #ifdef USE_TRANSPARENCY
2103 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
2104 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2, 0, 0);
2106 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c);
2107 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2);
2112 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2115 if (nx == x && ny == y) default_color = TERM_L_DARK;
2120 static cptr simplify_list[][2] =
2127 {"^Amulet of ", "\""},
2128 {"^Scroll of ", "?"},
2129 {"^Scroll titled ", "?"},
2130 {"^Wand of " , "-"},
2132 {"^Staff of " , "_"},
2133 {"^Potion of ", "!"},
2145 static void display_shortened_item_name(object_type *o_ptr, int y)
2152 object_desc(buf, o_ptr, FALSE, 0);
2153 attr = tval_to_attr[o_ptr->tval % 128];
2159 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
2161 strcpy(buf, "something strange");
2165 for (c = buf; *c; c++)
2168 for (i = 0; simplify_list[i][1]; i++)
2170 cptr org_w = simplify_list[i][0];
2180 if (!strncmp(c, org_w, strlen(org_w)))
2183 cptr tmp = simplify_list[i][1];
2186 tmp = c + strlen(org_w);
2196 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2202 if(len + 2 > 12) break;
2209 if(len + 1 > 12) break;
2215 Term_putstr(0, y, 12, attr, buf);
2219 * Display a "small-scale" map of the dungeon in the active Term
2221 void display_map(int *cy, int *cx)
2238 /* Save lighting effects */
2239 bool old_view_special_lite = view_special_lite;
2240 bool old_view_granite_lite = view_granite_lite;
2242 int hgt, wid, yrat, xrat;
2244 int **match_autopick_yx;
2245 object_type ***object_autopick_yx;
2248 Term_get_size(&wid, &hgt);
2251 if (use_bigtile) wid /= 2;
2253 yrat = (cur_hgt + hgt - 1) / hgt;
2254 xrat = (cur_wid + wid - 1) / wid;
2256 /* Disable lighting effects */
2257 view_special_lite = FALSE;
2258 view_granite_lite = FALSE;
2260 /* Allocate the maps */
2261 C_MAKE(ma, (hgt + 2), byte_ptr);
2262 C_MAKE(mc, (hgt + 2), char_ptr);
2263 C_MAKE(mp, (hgt + 2), byte_ptr);
2264 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2265 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2267 /* Allocate and wipe each line map */
2268 for (y = 0; y < (hgt + 2); y++)
2270 /* Allocate one row each array */
2271 C_MAKE(ma[y], (wid + 2), byte);
2272 C_MAKE(mc[y], (wid + 2), char);
2273 C_MAKE(mp[y], (wid + 2), byte);
2274 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2275 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2277 for (x = 0; x < wid + 2; ++x)
2279 match_autopick_yx[y][x] = -1;
2280 object_autopick_yx[y][x] = NULL;
2283 ma[y][x] = TERM_WHITE;
2291 /* Allocate the maps */
2292 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
2293 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
2294 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
2296 /* Allocate and wipe each line map */
2297 for (y = 0; y < (cur_hgt + 2); y++)
2299 /* Allocate one row each array */
2300 C_MAKE(bigma[y], (cur_wid + 2), byte);
2301 C_MAKE(bigmc[y], (cur_wid + 2), char);
2302 C_MAKE(bigmp[y], (cur_wid + 2), byte);
2304 for (x = 0; x < cur_wid + 2; ++x)
2307 bigma[y][x] = TERM_WHITE;
2315 /* Fill in the map */
2316 for (i = 0; i < cur_wid; ++i)
2318 for (j = 0; j < cur_hgt; ++j)
2328 /* Extract the current attr/char at that map location */
2329 #ifdef USE_TRANSPARENCY
2330 map_info(j, i, &ta, &tc, &ta, &tc);
2331 #else /* USE_TRANSPARENCY */
2332 map_info(j, i, &ta, &tc);
2333 #endif /* USE_TRANSPARENCY */
2335 /* Extract the priority */
2338 if(match_autopick!=-1
2339 && (match_autopick_yx[y][x] == -1
2340 || match_autopick_yx[y][x] > match_autopick))
2342 match_autopick_yx[y][x] = match_autopick;
2343 object_autopick_yx[y][x] = autopick_obj;
2347 /* Save the char, attr and priority */
2348 bigmc[j+1][i+1] = tc;
2349 bigma[j+1][i+1] = ta;
2350 bigmp[j+1][i+1] = tp;
2354 for (j = 0; j < cur_hgt; ++j)
2356 for (i = 0; i < cur_wid; ++i)
2362 tc = bigmc[j+1][i+1];
2363 ta = bigma[j+1][i+1];
2364 tp = bigmp[j+1][i+1];
2366 /* rare feature has more priority */
2372 for (t = 0; t < 8; t++)
2374 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2375 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2385 /* Save the char, attr and priority */
2398 /* Draw the corners */
2399 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2401 /* Draw the horizontal edges */
2402 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2404 /* Draw the vertical edges */
2405 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2408 /* Display each map line in order */
2409 for (y = 0; y < hgt + 2; ++y)
2411 /* Start a new line */
2412 Term_gotoxy(COL_MAP, y);
2414 /* Display the line */
2415 for (x = 0; x < wid + 2; ++x)
2420 /* Hack -- fake monochrome */
2423 if (world_monster) ta = TERM_DARK;
2424 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2425 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2428 if (use_bigtile) bigtile_attr(&tc, &ta, &c2, &a2);
2430 /* Add the character */
2432 if (use_bigtile) Term_addch(a2, c2);
2437 for (y = 1; y < hgt + 1; ++y)
2439 match_autopick = -1;
2440 for (x = 1; x <= wid; x++){
2441 if (match_autopick_yx[y][x] != -1 &&
2442 (match_autopick > match_autopick_yx[y][x] ||
2443 match_autopick == -1)){
2444 match_autopick = match_autopick_yx[y][x];
2445 autopick_obj = object_autopick_yx[y][x];
2449 /* Clear old display */
2450 Term_putstr(0, y, 12, 0, " ");
2452 if (match_autopick != -1)
2454 display_shortened_item_name(autopick_obj, y);
2457 char buf[13] = "\0";
2458 strncpy(buf,autopick_list[match_autopick].name,12);
2466 /* Player location */
2467 (*cy) = py / yrat + 1 + ROW_MAP;
2469 (*cx) = px / xrat + 1 + COL_MAP;
2471 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2473 /* Restore lighting effects */
2474 view_special_lite = old_view_special_lite;
2475 view_granite_lite = old_view_granite_lite;
2477 /* Free each line map */
2478 for (y = 0; y < (hgt + 2); y++)
2480 /* Free one row each array */
2481 C_FREE(ma[y], (wid + 2), byte);
2482 C_FREE(mc[y], (wid + 2), char);
2483 C_FREE(mp[y], (wid + 2), byte);
2484 C_FREE(match_autopick_yx[y], (wid + 2), int);
2485 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2488 /* Free each line map */
2489 C_FREE(ma, (hgt + 2), byte_ptr);
2490 C_FREE(mc, (hgt + 2), char_ptr);
2491 C_FREE(mp, (hgt + 2), byte_ptr);
2492 C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2493 C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2495 /* Free each line map */
2496 for (y = 0; y < (cur_hgt + 2); y++)
2498 /* Free one row each array */
2499 C_FREE(bigma[y], (cur_wid + 2), byte);
2500 C_FREE(bigmc[y], (cur_wid + 2), char);
2501 C_FREE(bigmp[y], (cur_wid + 2), byte);
2504 /* Free each line map */
2505 C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2506 C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2507 C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2512 * Display a "small-scale" map of the dungeon for the player
2514 * Currently, the "player" is displayed on the map. XXX XXX XXX
2516 void do_cmd_view_map(void)
2521 /* Save the screen */
2526 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2528 prt("Please wait...", 0, 0);
2534 /* Clear the screen */
2537 display_autopick = 0;
2539 /* Display the map */
2540 display_map(&cy, &cx);
2543 if(max_autopick && !p_ptr->wild_mode)
2545 display_autopick = ITEM_DISPLAY;
2552 int wid, hgt, row_message;
2554 Term_get_size(&wid, &hgt);
2555 row_message = hgt - 1;
2558 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2560 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2563 /* Hilite the player */
2564 move_cursor(cy, cx);
2569 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2571 flag = DONT_AUTOPICK;
2573 flag = DO_AUTODESTROY;
2575 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2581 if (~display_autopick & flag)
2582 display_autopick |= flag;
2584 display_autopick &= ~flag;
2585 /* Display the map */
2586 display_map(&cy, &cx);
2589 display_autopick = 0;
2595 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2597 put_str("Hit any key to continue", 23, 30);
2598 #endif /* Hilite the player */
2599 move_cursor(cy, cx);
2604 /* Restore the screen */
2613 * Some comments on the cave grid flags. -BEN-
2616 * One of the major bottlenecks in previous versions of Angband was in
2617 * the calculation of "line of sight" from the player to various grids,
2618 * such as monsters. This was such a nasty bottleneck that a lot of
2619 * silly things were done to reduce the dependancy on "line of sight",
2620 * for example, you could not "see" any grids in a lit room until you
2621 * actually entered the room, and there were all kinds of bizarre grid
2622 * flags to enable this behavior. This is also why the "call light"
2623 * spells always lit an entire room.
2625 * The code below provides functions to calculate the "field of view"
2626 * for the player, which, once calculated, provides extremely fast
2627 * calculation of "line of sight from the player", and to calculate
2628 * the "field of torch lite", which, again, once calculated, provides
2629 * extremely fast calculation of "which grids are lit by the player's
2630 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2631 * "GRID_LITE", as appropriate, these functions maintain an array for
2632 * each of these two flags, each array containing the locations of all
2633 * of the grids marked with the appropriate flag, which can be used to
2634 * very quickly scan through all of the grids in a given set.
2636 * To allow more "semantically valid" field of view semantics, whenever
2637 * the field of view (or the set of torch lit grids) changes, all of the
2638 * grids in the field of view (or the set of torch lit grids) are "drawn"
2639 * so that changes in the world will become apparent as soon as possible.
2640 * This has been optimized so that only grids which actually "change" are
2641 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2642 * of the grids which are entering or leaving the relevent set of grids.
2644 * These new methods are so efficient that the old nasty code was removed.
2646 * Note that there is no reason to "update" the "viewable space" unless
2647 * the player "moves", or walls/doors are created/destroyed, and there
2648 * is no reason to "update" the "torch lit grids" unless the field of
2649 * view changes, or the "light radius" changes. This means that when
2650 * the player is resting, or digging, or doing anything that does not
2651 * involve movement or changing the state of the dungeon, there is no
2652 * need to update the "view" or the "lite" regions, which is nice.
2654 * Note that the calls to the nasty "los()" function have been reduced
2655 * to a bare minimum by the use of the new "field of view" calculations.
2657 * I wouldn't be surprised if slight modifications to the "update_view()"
2658 * function would allow us to determine "reverse line-of-sight" as well
2659 * as "normal line-of-sight", which would allow monsters to use a more
2660 * "correct" calculation to determine if they can "see" the player. For
2661 * now, monsters simply "cheat" somewhat and assume that if the player
2662 * has "line of sight" to the monster, then the monster can "pretend"
2663 * that it has "line of sight" to the player.
2666 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2667 * grid and maintains an array of all "CAVE_LITE" grids.
2669 * This set of grids is the complete set of all grids which are lit by
2670 * the players light source, which allows the "player_can_see_bold()"
2671 * function to work very quickly.
2673 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2674 * fact, the player (unless blind) can always "see" all grids which are
2675 * marked as "CAVE_LITE", unless they are "off screen".
2678 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2679 * grid and maintains an array of all "CAVE_VIEW" grids.
2681 * This set of grids is the complete set of all grids within line of sight
2682 * of the player, allowing the "player_has_los_bold()" macro to work very
2686 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2687 * temporary internal flag to mark those grids which are not only in view,
2688 * but which are also "easily" in line of sight of the player. This flag
2689 * is always cleared when we are done.
2692 * The current "update_lite()" and "update_view()" algorithms use the
2693 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2694 * to keep track of which grids were previously marked as "CAVE_LITE" or
2695 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2697 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2698 * for various other purposes, such as spreading lite or darkness during
2699 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2702 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2703 * in some way permanently lit. However, for the player to "see" anything
2704 * in the grid, as determined by "player_can_see()", the player must not be
2705 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2706 * grids, even if marked as "perma lit", are only illuminated if they touch
2707 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2710 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2711 * that even if the player cannot "see" the grid, he "knows" the terrain in
2712 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2713 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2714 * or when one of the "memorize floor grids" options induces memorization.
2716 * Objects are "memorized" in a different way, using a special "marked" flag
2717 * on the object itself, which is set when an object is observed or detected.
2720 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2721 * and should be illuminated by "lite room" and "darkness" spells.
2724 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2725 * and should be unavailable for "teleportation" destinations.
2728 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2729 * which is observed, and the "view_torch_grids" allows the player to memorize
2730 * every torch-lit grid. The player will always memorize important walls,
2731 * doors, stairs, and other terrain features, as well as any "detected" grids.
2733 * Note that the new "update_view()" method allows, among other things, a room
2734 * to be "partially" seen as the player approaches it, with a growing cone of
2735 * floor appearing as the player gets closer to the door. Also, by not turning
2736 * on the "memorize perma-lit grids" option, the player will only "see" those
2737 * floor grids which are actually in line of sight.
2739 * And my favorite "plus" is that you can now use a special option to draw the
2740 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2741 * grids dimly), providing a "pretty" effect as the player runs around, and
2742 * to efficiently display the "torch lite" in a special color.
2745 * Some comments on the "update_view()" algorithm...
2747 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2748 * and only has to call "los()" on the borderline cases. The major axes/diags
2749 * even terminate early when they hit walls. I need to find a quick way
2750 * to "terminate" the other scans.
2752 * Note that in the worst case (a big empty area with say 5% scattered walls),
2753 * each of the 1500 or so nearby grids is checked once, most of them getting
2754 * an "instant" rating, and only a small portion requiring a call to "los()".
2756 * The only time that the algorithm appears to be "noticeably" too slow is
2757 * when running, and this is usually only important in town, since the town
2758 * provides about the worst scenario possible, with large open regions and
2759 * a few scattered obstructions. There is a special "efficiency" option to
2760 * allow the player to reduce his field of view in town, if needed.
2762 * In the "best" case (say, a normal stretch of corridor), the algorithm
2763 * makes one check for each viewable grid, and makes no calls to "los()".
2764 * So running in corridors is very fast, and if a lot of monsters are
2765 * nearby, it is much faster than the old methods.
2767 * Note that resting, most normal commands, and several forms of running,
2768 * plus all commands executed near large groups of monsters, are strictly
2769 * more efficient with "update_view()" that with the old "compute los() on
2770 * demand" method, primarily because once the "field of view" has been
2771 * calculated, it does not have to be recalculated until the player moves
2772 * (or a wall or door is created or destroyed).
2774 * Note that we no longer have to do as many "los()" checks, since once the
2775 * "view" region has been built, very few things cause it to be "changed"
2776 * (player movement, and the opening/closing of doors, changes in wall status).
2777 * Note that door/wall changes are only relevant when the door/wall itself is
2778 * in the "view" region.
2780 * The algorithm seems to only call "los()" from zero to ten times, usually
2781 * only when coming down a corridor into a room, or standing in a room, just
2782 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2783 * we will be reducing the calls to "los()".
2785 * I am thinking in terms of an algorithm that "walks" from the central point
2786 * out to the maximal "distance", at each point, determining the "view" code
2787 * (above). For each grid not on a major axis or diagonal, the "view" code
2788 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
2789 * (the one along the nearest diagonal, and the one next to that one, see
2790 * "update_view_aux()"...).
2792 * We "memorize" the viewable space array, so that at the cost of under 3000
2793 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2794 * each grid actually in the "viewable space". And for another 3000 bytes,
2795 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2796 * are also used by other routines, thus reducing the cost to almost nothing.
2798 * A similar thing is done for "forget_lite()" in which case the savings are
2799 * much less, but save us from doing bizarre maintenance checking.
2801 * In the worst "normal" case (in the middle of the town), the reachable space
2802 * actually reaches to more than half of the largest possible "circle" of view,
2803 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2804 * where all the walls have been removed), the reachable space actually reaches
2805 * the theoretical maximum size of just under 1500 grids.
2807 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2808 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2809 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2810 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2811 * entire possible space (including initialization) in one step per grid. If
2812 * we do the "clearing" as a separate step (and use an array of "view" grids),
2813 * then the clearing will take as many steps as grids that were viewed, and the
2814 * algorithm will be able to "stop" scanning at various points.
2815 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2826 * Actually erase the entire "lite" array, redrawing every grid
2828 void forget_lite(void)
2832 /* None to forget */
2833 if (!lite_n) return;
2835 /* Clear them all */
2836 for (i = 0; i < lite_n; i++)
2841 /* Forget "LITE" flag */
2842 cave[y][x].info &= ~(CAVE_LITE);
2845 /* lite_spot(y, x); Perhaps don't need? */
2854 * For delayed visual update
2856 #define cave_note_and_redraw_later(C,Y,X) \
2858 (C)->info |= CAVE_NOTE; \
2859 cave_redraw_later((C), (Y), (X)); \
2864 * For delayed visual update
2866 #define cave_redraw_later(C,Y,X) \
2868 if (!((C)->info & CAVE_REDRAW)) \
2870 (C)->info |= CAVE_REDRAW; \
2871 redraw_y[redraw_n] = (Y); \
2872 redraw_x[redraw_n++] = (X); \
2880 * This macro allows us to efficiently add a grid to the "lite" array,
2881 * note that we are never called for illegal grids, or for grids which
2882 * have already been placed into the "lite" array, and we are never
2883 * called when the "lite" array is full.
2885 #define cave_lite_hack(Y,X) \
2887 if (!(cave[Y][X].info & (CAVE_LITE))) { \
2888 cave[Y][X].info |= (CAVE_LITE); \
2889 lite_y[lite_n] = (Y); \
2890 lite_x[lite_n] = (X); \
2896 * Update the set of grids "illuminated" by the player's lite.
2898 * This routine needs to use the results of "update_view()"
2900 * Note that "blindness" does NOT affect "torch lite". Be careful!
2902 * We optimize most lites (all non-artifact lites) by using "obvious"
2903 * facts about the results of "small" lite radius, and we attempt to
2904 * list the "nearby" grids before the more "distant" ones in the
2905 * array of torch-lit grids.
2907 * We assume that "radius zero" lite is in fact no lite at all.
2909 * Torch Lantern Artifacts
2919 void update_lite(void)
2921 int i, x, y, min_x, max_x, min_y, max_y;
2922 int p = p_ptr->cur_lite;
2925 /*** Special case ***/
2928 /* Hack -- Player has no lite */
2931 /* Forget the old lite */
2932 /* forget_lite(); Perhaps don't need? */
2934 /* Add it to later visual update */
2935 cave_redraw_later(&cave[py][px], py, px);
2939 /*** Save the old "lite" grids for later ***/
2941 /* Clear them all */
2942 for (i = 0; i < lite_n; i++)
2947 /* Mark the grid as not "lite" */
2948 cave[y][x].info &= ~(CAVE_LITE);
2950 /* Mark the grid as "seen" */
2951 cave[y][x].info |= (CAVE_TEMP);
2953 /* Add it to the "seen" set */
2963 /*** Collect the new "lite" grids ***/
2965 /* Radius 1 -- torch radius */
2969 cave_lite_hack(py, px);
2972 cave_lite_hack(py+1, px);
2973 cave_lite_hack(py-1, px);
2974 cave_lite_hack(py, px+1);
2975 cave_lite_hack(py, px-1);
2977 /* Diagonal grids */
2978 cave_lite_hack(py+1, px+1);
2979 cave_lite_hack(py+1, px-1);
2980 cave_lite_hack(py-1, px+1);
2981 cave_lite_hack(py-1, px-1);
2984 /* Radius 2 -- lantern radius */
2987 /* South of the player */
2988 if (cave_floor_bold(py+1, px))
2990 cave_lite_hack(py+2, px);
2991 cave_lite_hack(py+2, px+1);
2992 cave_lite_hack(py+2, px-1);
2995 /* North of the player */
2996 if (cave_floor_bold(py-1, px))
2998 cave_lite_hack(py-2, px);
2999 cave_lite_hack(py-2, px+1);
3000 cave_lite_hack(py-2, px-1);
3003 /* East of the player */
3004 if (cave_floor_bold(py, px+1))
3006 cave_lite_hack(py, px+2);
3007 cave_lite_hack(py+1, px+2);
3008 cave_lite_hack(py-1, px+2);
3011 /* West of the player */
3012 if (cave_floor_bold(py, px-1))
3014 cave_lite_hack(py, px-2);
3015 cave_lite_hack(py+1, px-2);
3016 cave_lite_hack(py-1, px-2);
3020 /* Radius 3+ -- artifact radius */
3025 /* Paranoia -- see "LITE_MAX" */
3028 /* South-East of the player */
3029 if (cave_floor_bold(py+1, px+1))
3031 cave_lite_hack(py+2, px+2);
3034 /* South-West of the player */
3035 if (cave_floor_bold(py+1, px-1))
3037 cave_lite_hack(py+2, px-2);
3040 /* North-East of the player */
3041 if (cave_floor_bold(py-1, px+1))
3043 cave_lite_hack(py-2, px+2);
3046 /* North-West of the player */
3047 if (cave_floor_bold(py-1, px-1))
3049 cave_lite_hack(py-2, px-2);
3054 if (min_y < 0) min_y = 0;
3058 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3062 if (min_x < 0) min_x = 0;
3066 if (max_x > cur_wid-1) max_x = cur_wid-1;
3068 /* Scan the maximal box */
3069 for (y = min_y; y <= max_y; y++)
3071 for (x = min_x; x <= max_x; x++)
3073 int dy = (py > y) ? (py - y) : (y - py);
3074 int dx = (px > x) ? (px - x) : (x - px);
3076 /* Skip the "central" grids (above) */
3077 if ((dy <= 2) && (dx <= 2)) continue;
3079 /* Hack -- approximate the distance */
3080 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3082 /* Skip distant grids */
3083 if (d > p) continue;
3085 /* Viewable, nearby, grids get "torch lit" */
3086 if (player_has_los_bold(y, x))
3088 /* This grid is "torch lit" */
3089 cave_lite_hack(y, x);
3096 /*** Complete the algorithm ***/
3098 /* Draw the new grids */
3099 for (i = 0; i < lite_n; i++)
3104 c_ptr = &cave[y][x];
3106 /* Update fresh grids */
3107 if (c_ptr->info & (CAVE_TEMP)) continue;
3109 /* Add it to later visual update */
3110 cave_note_and_redraw_later(c_ptr, y, x);
3113 /* Clear them all */
3114 for (i = 0; i < temp_n; i++)
3119 c_ptr = &cave[y][x];
3121 /* No longer in the array */
3122 c_ptr->info &= ~(CAVE_TEMP);
3124 /* Update stale grids */
3125 if (c_ptr->info & (CAVE_LITE)) continue;
3127 /* Add it to later visual update */
3128 cave_redraw_later(c_ptr, y, x);
3134 /* Mega-Hack -- Visual update later */
3135 p_ptr->update |= (PU_DELAY_VIS);
3139 static bool mon_invis;
3142 * Add a square to the changes array
3144 static void mon_lite_hack(int y, int x)
3149 if (!in_bounds2(y, x)) return;
3151 c_ptr = &cave[y][x];
3153 /* Want a unlit square in view of the player */
3154 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3156 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3157 if (!cave_floor_grid(c_ptr) && mon_invis) return;
3159 /* Save this square */
3160 if (temp_n < TEMP_MAX)
3168 c_ptr->info |= CAVE_MNLT;
3175 * Update squares illuminated by monsters.
3177 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3178 * denote squares illuminated by monsters.
3180 * The CAVE_TEMP flag is used to store the state during the
3181 * updating. Only squares in view of the player, whos state
3182 * changes are drawn via lite_spot().
3184 void update_mon_lite(void)
3193 /* Non-Ninja player in the darkness */
3194 bool in_darkness = (d_info[dungeon_type].flags1 & DF1_DARKNESS) && (p_ptr->see_nocto < MAX_SIGHT);
3196 /* Clear all monster lit squares */
3197 for (i = 0; i < mon_lite_n; i++)
3200 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3203 c_ptr->info |= (CAVE_TEMP);
3205 /* Clear monster illumination flag */
3206 c_ptr->info &= ~(CAVE_MNLT);
3209 /* Empty temp list of new squares to lite up */
3212 /* Loop through monsters, adding newly lit squares to changes list */
3213 for (i = 1; i < m_max; i++)
3215 monster_type *m_ptr = &m_list[i];
3216 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3218 /* Skip dead monsters */
3219 if (!m_ptr->r_idx) continue;
3221 /* Is it too far away? */
3222 if (m_ptr->cdis > (in_darkness ? MAX_SIGHT / 2 + 1 : MAX_SIGHT + 3)) continue;
3224 /* Get lite radius */
3227 /* Note the radii are cumulative */
3228 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3229 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3231 /* Exit if has no light */
3233 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3235 if (world_monster) continue;
3237 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3239 /* Access the location */
3243 /* Is the monster visible? */
3244 mon_invis = !(cave[fy][fx].info & CAVE_VIEW);
3246 /* The square it is on */
3247 mon_lite_hack(fy, fx);
3249 /* Adjacent squares */
3250 mon_lite_hack(fy + 1, fx);
3251 mon_lite_hack(fy - 1, fx);
3252 mon_lite_hack(fy, fx + 1);
3253 mon_lite_hack(fy, fx - 1);
3254 mon_lite_hack(fy + 1, fx + 1);
3255 mon_lite_hack(fy + 1, fx - 1);
3256 mon_lite_hack(fy - 1, fx + 1);
3257 mon_lite_hack(fy - 1, fx - 1);
3262 /* South of the monster */
3263 if (cave_floor_bold(fy + 1, fx))
3265 mon_lite_hack(fy + 2, fx + 1);
3266 mon_lite_hack(fy + 2, fx);
3267 mon_lite_hack(fy + 2, fx - 1);
3269 c_ptr = &cave[fy + 2][fx];
3272 if ((rad == 3) && cave_floor_grid(c_ptr))
3274 mon_lite_hack(fy + 3, fx + 1);
3275 mon_lite_hack(fy + 3, fx);
3276 mon_lite_hack(fy + 3, fx - 1);
3280 /* North of the monster */
3281 if (cave_floor_bold(fy - 1, fx))
3283 mon_lite_hack(fy - 2, fx + 1);
3284 mon_lite_hack(fy - 2, fx);
3285 mon_lite_hack(fy - 2, fx - 1);
3287 c_ptr = &cave[fy - 2][fx];
3290 if ((rad == 3) && cave_floor_grid(c_ptr))
3292 mon_lite_hack(fy - 3, fx + 1);
3293 mon_lite_hack(fy - 3, fx);
3294 mon_lite_hack(fy - 3, fx - 1);
3298 /* East of the monster */
3299 if (cave_floor_bold(fy, fx + 1))
3301 mon_lite_hack(fy + 1, fx + 2);
3302 mon_lite_hack(fy, fx + 2);
3303 mon_lite_hack(fy - 1, fx + 2);
3305 c_ptr = &cave[fy][fx + 2];
3308 if ((rad == 3) && cave_floor_grid(c_ptr))
3310 mon_lite_hack(fy + 1, fx + 3);
3311 mon_lite_hack(fy, fx + 3);
3312 mon_lite_hack(fy - 1, fx + 3);
3316 /* West of the monster */
3317 if (cave_floor_bold(fy, fx - 1))
3319 mon_lite_hack(fy + 1, fx - 2);
3320 mon_lite_hack(fy, fx - 2);
3321 mon_lite_hack(fy - 1, fx - 2);
3323 c_ptr = &cave[fy][fx - 2];
3326 if ((rad == 3) && cave_floor_grid(c_ptr))
3328 mon_lite_hack(fy + 1, fx - 3);
3329 mon_lite_hack(fy, fx - 3);
3330 mon_lite_hack(fy - 1, fx - 3);
3338 /* South-East of the monster */
3339 if (cave_floor_bold(fy + 1, fx + 1))
3341 mon_lite_hack(fy + 2, fx + 2);
3344 /* South-West of the monster */
3345 if (cave_floor_bold(fy + 1, fx - 1))
3347 mon_lite_hack(fy + 2, fx - 2);
3350 /* North-East of the monster */
3351 if (cave_floor_bold(fy - 1, fx + 1))
3353 mon_lite_hack(fy - 2, fx + 2);
3356 /* North-West of the monster */
3357 if (cave_floor_bold(fy - 1, fx - 1))
3359 mon_lite_hack(fy - 2, fx - 2);
3364 /* Save end of list of new squares */
3368 * Look at old set flags to see if there are any changes.
3370 for (i = 0; i < mon_lite_n; i++)
3375 if (!in_bounds2(fy, fx)) continue;
3378 c_ptr = &cave[fy][fx];
3380 /* It it no longer lit? */
3381 if (!(c_ptr->info & CAVE_MNLT) && player_has_los_grid(c_ptr))
3383 /* Add it to later visual update */
3384 cave_note_and_redraw_later(c_ptr, fy, fx);
3387 /* Add to end of temp array */
3388 temp_x[temp_n] = (byte)fx;
3389 temp_y[temp_n] = (byte)fy;
3393 /* Clear the lite array */
3396 /* Copy the temp array into the lit array lighting the new squares. */
3397 for (i = 0; i < temp_n; i++)
3402 if (!in_bounds2(fy, fx)) continue;
3405 c_ptr = &cave[fy][fx];
3409 /* Clear the temp flag for the old lit grids */
3410 c_ptr->info &= ~(CAVE_TEMP);
3414 /* The is the square newly lit and visible? */
3415 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3418 /* Add it to later visual update */
3419 cave_note_and_redraw_later(c_ptr, fy, fx);
3422 /* Save in the monster lit array */
3423 mon_lite_x[mon_lite_n] = fx;
3424 mon_lite_y[mon_lite_n] = fy;
3429 /* Finished with temp_n */
3432 /* Mega-Hack -- Visual update later */
3433 p_ptr->update |= (PU_DELAY_VIS);
3435 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3437 if (p_ptr->special_defense & NINJA_S_STEALTH)
3439 if (p_ptr->old_monlite != p_ptr->monlite)
3444 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3446 msg_print("Your mantle of shadow become thin.");
3452 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3454 msg_print("Your mantle of shadow restored its original darkness.");
3459 p_ptr->old_monlite = p_ptr->monlite;
3462 void clear_mon_lite(void)
3467 /* Clear all monster lit squares */
3468 for (i = 0; i < mon_lite_n; i++)
3471 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3473 /* Clear monster illumination flag */
3474 c_ptr->info &= ~(CAVE_MNLT);
3477 /* Empty the array */
3484 * Clear the viewable space
3486 void forget_view(void)
3492 /* None to forget */
3493 if (!view_n) return;
3495 /* Clear them all */
3496 for (i = 0; i < view_n; i++)
3501 /* Access the grid */
3502 c_ptr = &cave[y][x];
3504 /* Forget that the grid is viewable */
3505 c_ptr->info &= ~(CAVE_VIEW);
3507 if (!panel_contains(y, x)) continue;
3509 /* Update the screen */
3510 /* lite_spot(y, x); Perhaps don't need? */
3520 * This macro allows us to efficiently add a grid to the "view" array,
3521 * note that we are never called for illegal grids, or for grids which
3522 * have already been placed into the "view" array, and we are never
3523 * called when the "view" array is full.
3525 #define cave_view_hack(C,Y,X) \
3527 if (!((C)->info & (CAVE_VIEW))){\
3528 (C)->info |= (CAVE_VIEW); \
3529 view_y[view_n] = (Y); \
3530 view_x[view_n] = (X); \
3537 * Helper function for "update_view()" below
3539 * We are checking the "viewability" of grid (y,x) by the player.
3541 * This function assumes that (y,x) is legal (i.e. on the map).
3543 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3544 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3546 * Note that we are using the "CAVE_XTRA" field for marking grids as
3547 * "easily viewable". This bit is cleared at the end of "update_view()".
3549 * This function adds (y,x) to the "viewable set" if necessary.
3551 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3553 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3555 bool f1, f2, v1, v2, z1, z2, wall;
3559 cave_type *g1_c_ptr;
3560 cave_type *g2_c_ptr;
3562 /* Access the grids */
3563 g1_c_ptr = &cave[y1][x1];
3564 g2_c_ptr = &cave[y2][x2];
3567 /* Check for walls */
3568 f1 = (cave_floor_grid(g1_c_ptr));
3569 f2 = (cave_floor_grid(g2_c_ptr));
3571 /* Totally blocked by physical walls */
3572 if (!f1 && !f2) return (TRUE);
3575 /* Check for visibility */
3576 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3577 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3579 /* Totally blocked by "unviewable neighbors" */
3580 if (!v1 && !v2) return (TRUE);
3583 /* Access the grid */
3584 c_ptr = &cave[y][x];
3587 /* Check for walls */
3588 wall = (!cave_floor_grid(c_ptr));
3591 /* Check the "ease" of visibility */
3592 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3593 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3595 /* Hack -- "easy" plus "easy" yields "easy" */
3598 c_ptr->info |= (CAVE_XTRA);
3600 cave_view_hack(c_ptr, y, x);
3605 /* Hack -- primary "easy" yields "viewed" */
3608 cave_view_hack(c_ptr, y, x);
3613 /* Hack -- "view" plus "view" yields "view" */
3616 /* c_ptr->info |= (CAVE_XTRA); */
3618 cave_view_hack(c_ptr, y, x);
3624 /* Mega-Hack -- the "los()" function works poorly on walls */
3627 cave_view_hack(c_ptr, y, x);
3633 /* Hack -- check line of sight */
3634 if (los(py, px, y, x))
3636 cave_view_hack(c_ptr, y, x);
3642 /* Assume no line of sight. */
3649 * Calculate the viewable space
3651 * 1: Process the player
3652 * 1a: The player is always (easily) viewable
3653 * 2: Process the diagonals
3654 * 2a: The diagonals are (easily) viewable up to the first wall
3655 * 2b: But never go more than 2/3 of the "full" distance
3656 * 3: Process the main axes
3657 * 3a: The main axes are (easily) viewable up to the first wall
3658 * 3b: But never go more than the "full" distance
3659 * 4: Process sequential "strips" in each of the eight octants
3660 * 4a: Each strip runs along the previous strip
3661 * 4b: The main axes are "previous" to the first strip
3662 * 4c: Process both "sides" of each "direction" of each strip
3663 * 4c1: Each side aborts as soon as possible
3664 * 4c2: Each side tells the next strip how far it has to check
3666 * Note that the octant processing involves some pretty interesting
3667 * observations involving when a grid might possibly be viewable from
3668 * a given grid, and on the order in which the strips are processed.
3670 * Note the use of the mathematical facts shown below, which derive
3671 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3672 * hypotenuse of a right triangle is primarily determined by the length
3673 * of the longest side, when one side is small, and is strictly less
3674 * than one-and-a-half times as long as the longest side when both of
3675 * the sides are large.
3677 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3678 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3680 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3682 * These observations are important because the calculation of the actual
3683 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3684 * while for small values (up to about 20 or so), the approximations above
3685 * are correct to within an error of at most one grid or so.
3687 * Observe the use of "full" and "over" in the code below, and the use of
3688 * the specialized calculation involving "limit", all of which derive from
3689 * the observations given above. Basically, we note that the "circle" of
3690 * view is completely contained in an "octagon" whose bounds are easy to
3691 * determine, and that only a few steps are needed to derive the actual
3692 * bounds of the circle given the bounds of the octagon.
3694 * Note that by skipping all the grids in the corners of the octagon, we
3695 * place an upper limit on the number of grids in the field of view, given
3696 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3697 * view, only about 1475 of these are in the "octagon" of view, and even
3698 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3699 * entries to completely contain the actual field of view.
3701 * Note also the care taken to prevent "running off the map". The use of
3702 * explicit checks on the "validity" of the "diagonal", and the fact that
3703 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3704 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3705 * of multiple checks on the validity of grids.
3707 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3708 * "ws","wn" variables. They work like this: While travelling down the
3709 * south-bound strip just to the east of the main south axis, as soon as
3710 * we get to a grid which does not "transmit" viewing, if all of the strips
3711 * preceding us (in this case, just the main axis) had terminated at or before
3712 * the same point, then we can stop, and reset the "max distance" to ourself.
3713 * So, each strip (named by major axis plus offset, thus "se" in this case)
3714 * maintains a "blockage" variable, initialized during the main axis step,
3715 * and checks it whenever a blockage is observed. After processing each
3716 * strip as far as the previous strip told us to process, the next strip is
3717 * told not to go farther than the current strip's farthest viewable grid,
3718 * unless open space is still available. This uses the "k" variable.
3720 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3721 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3722 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3723 * chunk of code which adds the given location to the "view" array if it
3724 * is not already there, using both the actual location and a pointer to
3725 * the cave grid. See above.
3727 * By the way, the purpose of this code is to reduce the dependancy on the
3728 * "los()" function which is slow, and, in some cases, not very accurate.
3730 * It is very possible that I am the only person who fully understands this
3731 * function, and for that I am truly sorry, but efficiency was very important
3732 * and the "simple" version of this function was just not fast enough. I am
3733 * more than willing to replace this function with a simpler one, if it is
3734 * equally efficient, and especially willing if the new function happens to
3735 * derive "reverse-line-of-sight" at the same time, since currently monsters
3736 * just use an optimized hack of "you see me, so I see you", and then use the
3737 * actual "projectable()" function to check spell attacks.
3739 void update_view(void)
3741 int n, m, d, k, y, x, z;
3743 int se, sw, ne, nw, es, en, ws, wn;
3747 int y_max = cur_hgt - 1;
3748 int x_max = cur_wid - 1;
3752 /*** Initialize ***/
3755 if (view_reduce_view && !dun_level)
3757 /* Full radius (10) */
3758 full = MAX_SIGHT / 2;
3760 /* Octagon factor (15) */
3761 over = MAX_SIGHT * 3 / 4;
3767 /* Full radius (20) */
3770 /* Octagon factor (30) */
3771 over = MAX_SIGHT * 3 / 2;
3775 /*** Step 0 -- Begin ***/
3777 /* Save the old "view" grids for later */
3778 for (n = 0; n < view_n; n++)
3783 /* Access the grid */
3784 c_ptr = &cave[y][x];
3786 /* Mark the grid as not in "view" */
3787 c_ptr->info &= ~(CAVE_VIEW);
3789 /* Mark the grid as "seen" */
3790 c_ptr->info |= (CAVE_TEMP);
3792 /* Add it to the "seen" set */
3798 /* Start over with the "view" array */
3801 /*** Step 1 -- adjacent grids ***/
3803 /* Now start on the player */
3807 /* Access the grid */
3808 c_ptr = &cave[y][x];
3810 /* Assume the player grid is easily viewable */
3811 c_ptr->info |= (CAVE_XTRA);
3813 /* Assume the player grid is viewable */
3814 cave_view_hack(c_ptr, y, x);
3817 /*** Step 2 -- Major Diagonals ***/
3822 /* Scan south-east */
3823 for (d = 1; d <= z; d++)
3825 c_ptr = &cave[y+d][x+d];
3826 c_ptr->info |= (CAVE_XTRA);
3827 cave_view_hack(c_ptr, y+d, x+d);
3828 if (!cave_floor_grid(c_ptr)) break;
3831 /* Scan south-west */
3832 for (d = 1; d <= z; d++)
3834 c_ptr = &cave[y+d][x-d];
3835 c_ptr->info |= (CAVE_XTRA);
3836 cave_view_hack(c_ptr, y+d, x-d);
3837 if (!cave_floor_grid(c_ptr)) break;
3840 /* Scan north-east */
3841 for (d = 1; d <= z; d++)
3843 c_ptr = &cave[y-d][x+d];
3844 c_ptr->info |= (CAVE_XTRA);
3845 cave_view_hack(c_ptr, y-d, x+d);
3846 if (!cave_floor_grid(c_ptr)) break;
3849 /* Scan north-west */
3850 for (d = 1; d <= z; d++)
3852 c_ptr = &cave[y-d][x-d];
3853 c_ptr->info |= (CAVE_XTRA);
3854 cave_view_hack(c_ptr, y-d, x-d);
3855 if (!cave_floor_grid(c_ptr)) break;
3859 /*** Step 3 -- major axes ***/
3862 for (d = 1; d <= full; d++)
3864 c_ptr = &cave[y+d][x];
3865 c_ptr->info |= (CAVE_XTRA);
3866 cave_view_hack(c_ptr, y+d, x);
3867 if (!cave_floor_grid(c_ptr)) break;
3870 /* Initialize the "south strips" */
3874 for (d = 1; d <= full; d++)
3876 c_ptr = &cave[y-d][x];
3877 c_ptr->info |= (CAVE_XTRA);
3878 cave_view_hack(c_ptr, y-d, x);
3879 if (!cave_floor_grid(c_ptr)) break;
3882 /* Initialize the "north strips" */
3886 for (d = 1; d <= full; d++)
3888 c_ptr = &cave[y][x+d];
3889 c_ptr->info |= (CAVE_XTRA);
3890 cave_view_hack(c_ptr, y, x+d);
3891 if (!cave_floor_grid(c_ptr)) break;
3894 /* Initialize the "east strips" */
3898 for (d = 1; d <= full; d++)
3900 c_ptr = &cave[y][x-d];
3901 c_ptr->info |= (CAVE_XTRA);
3902 cave_view_hack(c_ptr, y, x-d);
3903 if (!cave_floor_grid(c_ptr)) break;
3906 /* Initialize the "west strips" */
3910 /*** Step 4 -- Divide each "octant" into "strips" ***/
3912 /* Now check each "diagonal" (in parallel) */
3913 for (n = 1; n <= over / 2; n++)
3915 int ypn, ymn, xpn, xmn;
3918 /* Acquire the "bounds" of the maximal circle */
3920 if (z > full - n) z = full - n;
3921 while ((z + n + (n>>1)) > full) z--;
3924 /* Access the four diagonal grids */
3934 /* Maximum distance */
3935 m = MIN(z, y_max - ypn);
3938 if ((xpn <= x_max) && (n < se))
3941 for (k = n, d = 1; d <= m; d++)
3943 /* Check grid "d" in strip "n", notice "blockage" */
3944 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3946 if (n + d >= se) break;
3949 /* Track most distant "non-blockage" */
3956 /* Limit the next strip */
3961 if ((xmn >= 0) && (n < sw))
3964 for (k = n, d = 1; d <= m; d++)
3966 /* Check grid "d" in strip "n", notice "blockage" */
3967 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3969 if (n + d >= sw) break;
3972 /* Track most distant "non-blockage" */
3979 /* Limit the next strip */
3988 /* Maximum distance */
3992 if ((xpn <= x_max) && (n < ne))
3995 for (k = n, d = 1; d <= m; d++)
3997 /* Check grid "d" in strip "n", notice "blockage" */
3998 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
4000 if (n + d >= ne) break;
4003 /* Track most distant "non-blockage" */
4010 /* Limit the next strip */
4015 if ((xmn >= 0) && (n < nw))
4018 for (k = n, d = 1; d <= m; d++)
4020 /* Check grid "d" in strip "n", notice "blockage" */
4021 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
4023 if (n + d >= nw) break;
4026 /* Track most distant "non-blockage" */
4033 /* Limit the next strip */
4042 /* Maximum distance */
4043 m = MIN(z, x_max - xpn);
4046 if ((ypn <= x_max) && (n < es))
4049 for (k = n, d = 1; d <= m; d++)
4051 /* Check grid "d" in strip "n", notice "blockage" */
4052 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
4054 if (n + d >= es) break;
4057 /* Track most distant "non-blockage" */
4064 /* Limit the next strip */
4069 if ((ymn >= 0) && (n < en))
4072 for (k = n, d = 1; d <= m; d++)
4074 /* Check grid "d" in strip "n", notice "blockage" */
4075 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4077 if (n + d >= en) break;
4080 /* Track most distant "non-blockage" */
4087 /* Limit the next strip */
4096 /* Maximum distance */
4100 if ((ypn <= y_max) && (n < ws))
4103 for (k = n, d = 1; d <= m; d++)
4105 /* Check grid "d" in strip "n", notice "blockage" */
4106 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4108 if (n + d >= ws) break;
4111 /* Track most distant "non-blockage" */
4118 /* Limit the next strip */
4123 if ((ymn >= 0) && (n < wn))
4126 for (k = n, d = 1; d <= m; d++)
4128 /* Check grid "d" in strip "n", notice "blockage" */
4129 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4131 if (n + d >= wn) break;
4134 /* Track most distant "non-blockage" */
4141 /* Limit the next strip */
4148 /*** Step 5 -- Complete the algorithm ***/
4150 /* Update all the new grids */
4151 for (n = 0; n < view_n; n++)
4156 /* Access the grid */
4157 c_ptr = &cave[y][x];
4159 /* Clear the "CAVE_XTRA" flag */
4160 c_ptr->info &= ~(CAVE_XTRA);
4162 /* Update only newly viewed grids */
4163 if (c_ptr->info & (CAVE_TEMP)) continue;
4165 /* Add it to later visual update */
4166 cave_note_and_redraw_later(c_ptr, y, x);
4169 /* Wipe the old grids, update as needed */
4170 for (n = 0; n < temp_n; n++)
4175 /* Access the grid */
4176 c_ptr = &cave[y][x];
4178 /* No longer in the array */
4179 c_ptr->info &= ~(CAVE_TEMP);
4181 /* Update only non-viewable grids */
4182 if (c_ptr->info & (CAVE_VIEW)) continue;
4184 /* Add it to later visual update */
4185 cave_redraw_later(c_ptr, y, x);
4192 /*** Step 6 -- Vampires hack if without lite ***/
4194 if ((p_ptr->see_nocto == 1) && !p_ptr->cur_lite && !p_ptr->blind)
4196 /* Hack -- Vampires' noctovision is limited to adjacent grids */
4197 for (n = 0; n < 9; n++)
4199 y = py + ddy_ddd[n];
4200 x = px + ddx_ddd[n];
4202 /* Access the grid */
4203 c_ptr = &cave[y][x];
4205 /* Add it to later visual update */
4206 cave_note_and_redraw_later(c_ptr, y, x);
4210 /* Mega-Hack -- Visual update later */
4211 p_ptr->update |= (PU_DELAY_VIS);
4216 * Mega-Hack -- Delayed visual update
4217 * Only used if update_view(), update_lite() or update_mon_lite() was called
4219 void delayed_visual_update(void)
4224 /* Update needed grids */
4225 for (i = 0; i < redraw_n; i++)
4230 /* Access the grid */
4231 c_ptr = &cave[y][x];
4233 /* Update only needed grids (prevent multiple updating) */
4234 if (!(c_ptr->info & CAVE_REDRAW)) continue;
4236 /* If required, note */
4237 if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
4242 /* Hack -- Visual update of monster on this grid */
4243 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4245 /* No longer in the array */
4246 c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4255 * Hack -- forget the "flow" information
4257 void forget_flow(void)
4261 /* Check the entire dungeon */
4262 for (y = 0; y < cur_hgt; y++)
4264 for (x = 0; x < cur_wid; x++)
4266 /* Forget the old data */
4267 cave[y][x].dist = 0;
4268 cave[y][x].cost = 0;
4269 cave[y][x].when = 0;
4276 * Hack - speed up the update_flow algorithm by only doing
4277 * it everytime the player moves out of LOS of the last
4280 static u16b flow_x = 0;
4281 static u16b flow_y = 0;
4286 * Hack -- fill in the "cost" field of every grid that the player
4287 * can "reach" with the number of steps needed to reach that grid.
4288 * This also yields the "distance" of the player from every grid.
4290 * In addition, mark the "when" of the grids that can reach
4291 * the player with the incremented value of "flow_n".
4293 * Hack -- use the "seen" array as a "circular queue".
4295 * We do not need a priority queue because the cost from grid
4296 * to grid is always "one" and we process them in order.
4298 void update_flow(void)
4304 /* Paranoia -- make sure the array is empty */
4307 /* The last way-point is on the map */
4308 if (running && in_bounds(flow_y, flow_x))
4310 /* The way point is in sight - do not update. (Speedup) */
4311 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4314 /* Erase all of the current flow information */
4315 for (y = 0; y < cur_hgt; y++)
4317 for (x = 0; x < cur_wid; x++)
4319 cave[y][x].cost = 0;
4320 cave[y][x].dist = 0;
4324 /* Save player position */
4328 /* Add the player's grid to the queue */
4332 /* Now process the queue */
4333 while (flow_head != flow_tail)
4337 /* Extract the next entry */
4338 ty = temp_y[flow_tail];
4339 tx = temp_x[flow_tail];
4341 /* Forget that entry */
4342 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4344 /* Add the "children" */
4345 for (d = 0; d < 8; d++)
4347 int old_head = flow_head;
4348 int m = cave[ty][tx].cost + 1;
4349 int n = cave[ty][tx].dist + 1;
4352 /* Child location */
4353 y = ty + ddy_ddd[d];
4354 x = tx + ddx_ddd[d];
4356 /* Ignore player's grid */
4357 if (player_bold(y, x)) continue;
4359 c_ptr = &cave[y][x];
4361 if (is_closed_door(c_ptr->feat)) m += 3;
4363 /* Ignore "pre-stamped" entries */
4364 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4366 /* Ignore "walls" and "rubble" */
4367 if ((c_ptr->feat >= FEAT_RUBBLE) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4369 /* Save the flow cost */
4370 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4371 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4373 /* Hack -- limit flow depth */
4374 if (n == MONSTER_FLOW_DEPTH) continue;
4376 /* Enqueue that entry */
4377 temp_y[flow_head] = y;
4378 temp_x[flow_head] = x;
4380 /* Advance the queue */
4381 if (++flow_head == TEMP_MAX) flow_head = 0;
4383 /* Hack -- notice overflow by forgetting new entry */
4384 if (flow_head == flow_tail) flow_head = old_head;
4390 static int scent_when = 0;
4393 * Characters leave scent trails for perceptive monsters to track.
4395 * Smell is rather more limited than sound. Many creatures cannot use
4396 * it at all, it doesn't extend very far outwards from the character's
4397 * current position, and monsters can use it to home in the character,
4398 * but not to run away from him.
4400 * Smell is valued according to age. When a character takes his turn,
4401 * scent is aged by one, and new scent of the current age is laid down.
4402 * Speedy characters leave more scent, true, but it also ages faster,
4403 * which makes it harder to hunt them down.
4405 * Whenever the age count loops, most of the scent trail is erased and
4406 * the age of the remainder is recalculated.
4408 void update_smell(void)
4413 /* Create a table that controls the spread of scent */
4414 const int scent_adjust[5][5] =
4423 /* Loop the age and adjust scent values when necessary */
4424 if (++scent_when == 254)
4426 /* Scan the entire dungeon */
4427 for (y = 0; y < cur_hgt; y++)
4429 for (x = 0; x < cur_wid; x++)
4431 int w = cave[y][x].when;
4432 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4441 /* Lay down new scent */
4442 for (i = 0; i < 5; i++)
4444 for (j = 0; j < 5; j++)
4448 /* Translate table to map grids */
4453 if (!in_bounds(y, x)) continue;
4455 c_ptr = &cave[y][x];
4457 /* Walls, water, and lava cannot hold scent. */
4458 if ((c_ptr->feat >= FEAT_RUBBLE) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4460 /* Grid must not be blocked by walls from the character */
4461 if (!player_has_los_bold(y, x)) continue;
4463 /* Note grids that are too far away */
4464 if (scent_adjust[i][j] == -1) continue;
4466 /* Mark the grid with new scent */
4467 c_ptr->when = scent_when + scent_adjust[i][j];
4474 * Hack -- map the current panel (plus some) ala "magic mapping"
4476 void map_area(int range)
4484 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4486 /* Scan that area */
4487 for (y = 1; y < cur_hgt - 1; y++)
4489 for (x = 1; x < cur_wid - 1; x++)
4491 if (distance(py, px, y, x) > range) continue;
4493 c_ptr = &cave[y][x];
4495 /* Feature code (applying "mimic" field) */
4496 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4498 /* All non-walls are "checked" */
4499 if ((feat <= FEAT_DOOR_TAIL) ||
4500 (feat == FEAT_RUBBLE) ||
4501 ((feat >= FEAT_MINOR_GLYPH) &&
4502 (feat <= FEAT_TREES)) ||
4503 (feat >= FEAT_TOWN))
4505 /* Memorize normal features */
4506 if ((feat > FEAT_INVIS) && (feat != FEAT_DIRT) && (feat != FEAT_GRASS))
4508 /* Memorize the object */
4509 c_ptr->info |= (CAVE_MARK);
4512 /* Memorize known walls */
4513 for (i = 0; i < 8; i++)
4515 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4517 /* Feature code (applying "mimic" field) */
4518 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4520 /* Memorize walls (etc) */
4521 if ((feat >= FEAT_RUBBLE) && (feat != FEAT_DIRT) && (feat != FEAT_GRASS))
4523 /* Memorize the walls */
4524 c_ptr->info |= (CAVE_MARK);
4532 p_ptr->redraw |= (PR_MAP);
4535 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4541 * Light up the dungeon using "clairvoyance"
4543 * This function "illuminates" every grid in the dungeon, memorizes all
4544 * "objects", memorizes all grids as with magic mapping, and, under the
4545 * standard option settings (view_perma_grids but not view_torch_grids)
4546 * memorizes all floor grids too.
4548 * Note that if "view_perma_grids" is not set, we do not memorize floor
4549 * grids, since this would defeat the purpose of "view_perma_grids", not
4550 * that anyone seems to play without this option.
4552 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4553 * since this would prevent the use of "view_torch_grids" as a method to
4554 * keep track of what grids have been observed directly.
4556 void wiz_lite(bool ninja)
4561 /* Memorize objects */
4562 for (i = 1; i < o_max; i++)
4564 object_type *o_ptr = &o_list[i];
4566 /* Skip dead objects */
4567 if (!o_ptr->k_idx) continue;
4569 /* Skip held objects */
4570 if (o_ptr->held_m_idx) continue;
4573 o_ptr->marked |= OM_FOUND;
4576 /* Scan all normal grids */
4577 for (y = 1; y < cur_hgt - 1; y++)
4579 /* Scan all normal grids */
4580 for (x = 1; x < cur_wid - 1; x++)
4582 cave_type *c_ptr = &cave[y][x];
4584 /* Feature code (applying "mimic" field) */
4585 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4587 /* Process all non-walls */
4588 if (cave_floor_bold(y, x) || (feat == FEAT_RUBBLE) || (feat == FEAT_TREES) || (feat == FEAT_MOUNTAIN))
4590 /* Scan all neighbors */
4591 for (i = 0; i < 9; i++)
4593 int yy = y + ddy_ddd[i];
4594 int xx = x + ddx_ddd[i];
4597 c_ptr = &cave[yy][xx];
4599 /* Feature code (applying "mimic" field) */
4600 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4602 /* Memorize normal features */
4605 /* Memorize the grid */
4606 c_ptr->info |= (CAVE_MARK);
4610 if ((feat > FEAT_INVIS))
4612 /* Memorize the grid */
4613 c_ptr->info |= (CAVE_MARK);
4616 /* Perma-lite the grid */
4617 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4619 c_ptr->info |= (CAVE_GLOW);
4621 /* Normally, memorize floors (see above) */
4622 if (view_perma_grids && !view_torch_grids)
4624 /* Memorize the grid */
4625 c_ptr->info |= (CAVE_MARK);
4634 /* Update the monsters */
4635 p_ptr->update |= (PU_MONSTERS);
4638 p_ptr->redraw |= (PR_MAP);
4641 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4646 * Forget the dungeon map (ala "Thinking of Maud...").
4653 /* Forget every grid */
4654 for (y = 0; y < cur_hgt; y++)
4656 for (x = 0; x < cur_wid; x++)
4658 cave_type *c_ptr = &cave[y][x];
4660 /* Process the grid */
4661 c_ptr->info &= ~(CAVE_MARK);
4665 /* Forget all objects */
4666 for (i = 1; i < o_max; i++)
4668 object_type *o_ptr = &o_list[i];
4670 /* Skip dead objects */
4671 if (!o_ptr->k_idx) continue;
4673 /* Skip held objects */
4674 if (o_ptr->held_m_idx) continue;
4676 /* Forget the object */
4680 /* Mega-Hack -- Forget the view and lite */
4681 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4683 /* Update the view and lite */
4684 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4686 /* Update the monsters */
4687 p_ptr->update |= (PU_MONSTERS);
4690 p_ptr->redraw |= (PR_MAP);
4693 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4701 * Change the "feat" flag for a grid, and notice/redraw the grid
4703 void cave_set_feat(int y, int x, int feat)
4705 cave_type *c_ptr = &cave[y][x];
4707 /* Clear mimic type */
4710 /* Remove flag for mirror/glyph */
4711 c_ptr->info &= ~(CAVE_OBJECT);
4713 /* Change the feature */
4716 /* Hack -- glow the deep lava */
4717 if ((feat == FEAT_DEEP_LAVA) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4721 for (i = 0; i < 9; i++)
4723 yy = y + ddy_ddd[i];
4724 xx = x + ddx_ddd[i];
4725 if (!in_bounds2(yy, xx)) continue;
4726 cave[yy][xx].info |= CAVE_GLOW;
4727 if (player_has_los_bold(yy, xx))
4745 /* Remove a mirror */
4746 void remove_mirror(int y, int x)
4748 /* Remove the mirror */
4749 cave[y][x].info &= ~(CAVE_OBJECT);
4750 cave[y][x].mimic = 0;
4752 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4754 cave[y][x].info &= ~(CAVE_GLOW);
4755 if( !view_torch_grids )cave[y][x].info &= ~(CAVE_MARK);
4766 * Return TRUE if there is a mirror on the grid.
4768 bool is_mirror_grid(cave_type *c_ptr)
4770 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_MIRROR)
4778 * Return TRUE if there is a mirror on the grid.
4780 bool is_glyph_grid(cave_type *c_ptr)
4782 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_GLYPH)
4790 * Return TRUE if there is a mirror on the grid.
4792 bool is_explosive_rune_grid(cave_type *c_ptr)
4794 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_MINOR_GLYPH)
4802 * Calculate "incremental motion". Used by project() and shoot().
4803 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4805 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4807 int dy, dx, dist, shift;
4809 /* Extract the distance travelled */
4810 dy = (*y < y1) ? y1 - *y : *y - y1;
4811 dx = (*x < x1) ? x1 - *x : *x - x1;
4813 /* Number of steps */
4814 dist = (dy > dx) ? dy : dx;
4816 /* We are calculating the next location */
4820 /* Calculate the total distance along each axis */
4821 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4822 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4824 /* Paranoia -- Hack -- no motion */
4825 if (!dy && !dx) return;
4828 /* Move mostly vertically */
4831 /* Extract a shift factor */
4832 shift = (dist * dx + (dy - 1) / 2) / dy;
4834 /* Sometimes move along the minor axis */
4835 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4837 /* Always move along major axis */
4838 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4841 /* Move mostly horizontally */
4844 /* Extract a shift factor */
4845 shift = (dist * dy + (dx - 1) / 2) / dx;
4847 /* Sometimes move along the minor axis */
4848 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4850 /* Always move along major axis */
4851 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4858 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4859 * at the final destination, assuming no monster gets in the way.
4861 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4863 bool projectable(int y1, int x1, int y2, int x2)
4870 /* Check the projection path */
4871 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4873 /* No grid is ever projectable from itself */
4874 if (!grid_n) return (FALSE);
4877 y = GRID_Y(grid_g[grid_n - 1]);
4878 x = GRID_X(grid_g[grid_n - 1]);
4880 /* May not end in an unrequested grid */
4881 if ((y != y2) || (x != x2)) return (FALSE);
4889 * Standard "find me a location" function
4891 * Obtains a legal location within the given distance of the initial
4892 * location, and with "los()" from the source to destination location.
4894 * This function is often called from inside a loop which searches for
4895 * locations while increasing the "d" distance.
4897 * Currently the "m" parameter is unused.
4899 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4906 /* Pick a location */
4909 /* Pick a new location */
4910 ny = rand_spread(y, d);
4911 nx = rand_spread(x, d);
4913 /* Ignore annoying locations */
4914 if (!in_bounds(ny, nx)) continue;
4916 /* Ignore "excessively distant" locations */
4917 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4919 /* Require "line of sight" */
4920 if (los(y, x, ny, nx)) break;
4923 /* Save the location */
4932 * Track a new monster
4934 void health_track(int m_idx)
4936 /* Mount monster is already tracked */
4937 if (m_idx && m_idx == p_ptr->riding) return;
4939 /* Track a new guy */
4940 p_ptr->health_who = m_idx;
4942 /* Redraw (later) */
4943 p_ptr->redraw |= (PR_HEALTH);
4949 * Hack -- track the given monster race
4951 void monster_race_track(int r_idx)
4953 /* Save this monster ID */
4954 p_ptr->monster_race_idx = r_idx;
4957 p_ptr->window |= (PW_MONSTER);
4963 * Hack -- track the given object kind
4965 void object_kind_track(int k_idx)
4967 /* Save this monster ID */
4968 p_ptr->object_kind_idx = k_idx;
4971 p_ptr->window |= (PW_OBJECT);
4977 * Something has happened to disturb the player.
4979 * The first arg indicates a major disturbance, which affects search.
4981 * The second arg is currently unused, but could induce output flush.
4983 * All disturbance cancels repeated commands, resting, and running.
4985 void disturb(int stop_search, int unused_flag)
4988 unused_flag = unused_flag;
4990 /* Cancel auto-commands */
4991 /* command_new = 0; */
4993 /* Cancel repeated commands */
4999 /* Redraw the state (later) */
5000 p_ptr->redraw |= (PR_STATE);
5003 /* Cancel Resting */
5004 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5007 set_action(ACTION_NONE);
5010 /* Cancel running */
5016 /* Check for new panel if appropriate */
5017 if (center_player && !center_running) verify_panel();
5019 /* Calculate torch radius */
5020 p_ptr->update |= (PU_TORCH);
5022 /* Update monster flow */
5023 p_ptr->update |= (PU_FLOW);
5026 /* Flush the input if requested */
5027 if (flush_disturb) flush();
5032 * Glow deep lava and building entrances in the floor
5034 void glow_deep_lava_and_bldg(void)
5036 int y, x, i, yy, xx;
5040 /* Not in the darkness dungeon */
5041 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
5043 for (y = 0; y < cur_hgt; y++)
5045 for (x = 0; x < cur_wid; x++)
5047 c_ptr = &cave[y][x];
5049 /* Feature code (applying "mimic" field) */
5050 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
5052 if ((feat == FEAT_DEEP_LAVA) ||
5053 ((feat >= FEAT_SHOP_HEAD) &&
5054 (feat <= FEAT_SHOP_TAIL)) ||
5055 (feat == FEAT_MUSEUM) ||
5056 ((feat >= FEAT_BLDG_HEAD) &&
5057 (feat <= FEAT_BLDG_TAIL)))
5059 for (i = 0; i < 9; i++)
5061 yy = y + ddy_ddd[i];
5062 xx = x + ddx_ddd[i];
5063 if (!in_bounds2(yy, xx)) continue;
5064 cave[yy][xx].info |= CAVE_GLOW;
5065 if (player_has_los_bold(yy, xx)) note_spot(yy, xx);