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 /* Noctovision of Ninja */
449 if (p_ptr->see_nocto) return TRUE;
451 /* Require "perma-lite" of the grid */
452 if (!(c_ptr->info & CAVE_MNLT) && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)) return FALSE;
454 /* Floors are simple */
455 if (cave_floor_bold(y, x)) return (TRUE);
457 /* Hack -- move towards player */
458 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
459 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
461 /* Check for "local" illumination */
462 if ((cave[yy][xx].info & CAVE_MNLT) || ((cave[yy][xx].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
464 /* Assume the wall is really illuminated */
468 /* Assume not visible */
475 * Returns true if the player's grid is dark
479 return (!player_can_see_bold(py, px));
486 * Determine if a given location may be "destroyed"
488 * Used by destruction spells, and for placing stairs, etc.
490 bool cave_valid_bold(int y, int x)
492 cave_type *c_ptr = &cave[y][x];
494 s16b this_o_idx, next_o_idx = 0;
497 /* Forbid perma-grids */
498 if (cave_perma_grid(c_ptr)) return (FALSE);
501 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
506 o_ptr = &o_list[this_o_idx];
508 /* Acquire next object */
509 next_o_idx = o_ptr->next_o_idx;
511 /* Forbid artifact grids */
512 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
523 * Determine if a given location may be "destroyed"
525 * Used by destruction spells, and for placing stairs, etc.
527 bool cave_valid_grid(cave_type *c_ptr)
529 s16b this_o_idx, next_o_idx = 0;
532 /* Forbid perma-grids */
533 if (cave_perma_grid(c_ptr)) return (FALSE);
536 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
541 o_ptr = &o_list[this_o_idx];
543 /* Acquire next object */
544 next_o_idx = o_ptr->next_o_idx;
546 /* Forbid artifact grids */
547 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
558 * Hack -- Legal monster codes
560 static char image_monster_hack[] = \
561 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
564 * Mega-Hack -- Hallucinatory monster
566 static void image_monster(byte *ap, char *cp)
568 /* Random symbol from set above */
571 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
579 int n = sizeof(image_monster_hack) - 1;
581 *cp = image_monster_hack[randint0(n)];
591 * Hack -- Legal object codes
593 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
596 * Mega-Hack -- Hallucinatory object
598 static void image_object(byte *ap, char *cp)
602 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
609 int n = sizeof(image_object_hack) - 1;
611 *cp = image_object_hack[randint0(n)];
621 * Hack -- Random hallucination
623 static void image_random(byte *ap, char *cp)
625 /* Normally, assume monsters */
626 if (randint0(100) < 75)
628 image_monster(ap, cp);
631 /* Otherwise, assume objects */
634 image_object(ap, cp);
639 * Not using graphical tiles for this feature?
641 #define is_ascii_graphics(A) (!((A) & 0x80))
644 * The 16x16 tile of the terrain supports lighting
646 static bool feat_supports_lighting(byte feat)
648 if (is_trap(feat)) return streq(ANGBAND_GRAF, "new");
666 case FEAT_WALL_EXTRA:
667 case FEAT_WALL_INNER:
668 case FEAT_WALL_OUTER:
669 case FEAT_WALL_SOLID:
670 case FEAT_PERM_EXTRA:
671 case FEAT_PERM_INNER:
672 case FEAT_PERM_OUTER:
673 case FEAT_PERM_SOLID:
674 case FEAT_MINOR_GLYPH:
675 case FEAT_DEEP_WATER:
676 case FEAT_SHAL_WATER:
683 case FEAT_DEEP_GRASS:
694 * This array lists the effects of "brightness" on various "base" colours.
696 * This is used to do dynamic lighting effects in ascii :-)
697 * At the moment, only the various "floor" tiles are affected.
699 * The layout of the array is [x][0] = light and [x][1] = dark.
702 static byte lighting_colours[16][2] =
705 {TERM_L_DARK, TERM_DARK},
708 {TERM_YELLOW, TERM_SLATE},
711 {TERM_WHITE, TERM_L_DARK},
714 {TERM_L_UMBER, TERM_UMBER},
717 {TERM_RED, TERM_RED},
720 {TERM_L_GREEN, TERM_GREEN},
723 {TERM_BLUE, TERM_BLUE},
726 {TERM_L_UMBER, TERM_RED},
729 {TERM_SLATE, TERM_L_DARK},
732 {TERM_WHITE, TERM_SLATE},
735 {TERM_L_RED, TERM_BLUE},
738 {TERM_YELLOW, TERM_ORANGE},
741 {TERM_L_RED, TERM_L_RED},
744 {TERM_L_GREEN, TERM_GREEN},
747 {TERM_L_BLUE, TERM_L_BLUE},
750 {TERM_L_UMBER, TERM_UMBER}
755 * Mega-Hack -- Partial code of map_info() for darkened grids
756 * Note: Each variable is declared in map_info().
757 * This macro modifies "feat", "f_ptr", "c" and "a".
759 #define darkened_grid_hack() \
761 if (feat_floor(feat)) \
763 /* Unsafe cave grid -- idea borrowed from Unangband */ \
764 if (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) \
766 feat = FEAT_UNDETECTD; \
768 /* Access unsafe darkness */ \
769 f_ptr = &f_info[feat]; \
771 /* Char and attr of unsafe grid */ \
777 /* For feat_priority control */ \
782 /* Access darkness */ \
783 f_ptr = &f_info[feat]; \
785 /* Char and attr of darkness */ \
798 if (is_ascii_graphics(a)) \
800 /* Use darkened colour */ \
801 a = !new_ascii_graphics ? TERM_L_DARK : lighting_colours[a][1]; \
803 else if (use_graphics && feat_supports_lighting(feat)) \
805 /* Use a dark tile */ \
813 * Extract the attr/char to display at the given (legal) map location
815 * Basically, we "paint" the chosen attr/char in several passes, starting
816 * with any known "terrain features" (defaulting to darkness), then adding
817 * any known "objects", and finally, adding any known "monsters". This
818 * is not the fastest method but since most of the calls to this function
819 * are made for grids with no monsters or objects, it is fast enough.
821 * Note that this function, if used on the grid containing the "player",
822 * will return the attr/char of the grid underneath the player, and not
823 * the actual player attr/char itself, allowing a lot of optimization
824 * in various "display" functions.
826 * Note that the "zero" entry in the feature/object/monster arrays are
827 * used to provide "special" attr/char codes, with "monster zero" being
828 * used for the player attr/char, "object zero" being used for the "stack"
829 * attr/char, and "feature zero" being used for the "nothing" attr/char,
830 * though this function makes use of only "feature zero".
832 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
833 * which means their color changes, and "ATTR_CLEAR", which means they take
834 * the color of whatever is under them, and "CHAR_CLEAR", which means that
835 * they take the symbol of whatever is under them. Technically, the flag
836 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
837 * examined, but this flag is currently ignored.
839 * Currently, we do nothing with multi-hued objects, because there are
840 * not any. If there were, they would have to set "shimmer_objects"
841 * when they were created, and then new "shimmer" code in "dungeon.c"
842 * would have to be created handle the "shimmer" effect, and the code
843 * in "cave.c" would have to be updated to create the shimmer effect.
845 * Note the effects of hallucination. Objects always appear as random
846 * "objects", monsters as random "monsters", and normal grids occasionally
847 * appear as random "monsters" or "objects", but note that these random
848 * "monsters" and "objects" are really just "colored ascii symbols".
850 * Note that "floors" and "invisible traps" (and "zero" features) are
851 * drawn as "floors" using a special check for optimization purposes,
852 * and these are the only features which get drawn using the special
853 * lighting effects activated by "view_special_lite".
855 * Note the use of the "mimic" field in the "terrain feature" processing,
856 * which allows any feature to "pretend" to be another feature. This is
857 * used to "hide" secret doors, and to make all "doors" appear the same,
858 * and all "walls" appear the same, and "hidden" treasure stay hidden.
859 * It is possible to use this field to make a feature "look" like a floor,
860 * but the "special lighting effects" for floors will not be used.
862 * Note the use of the new "terrain feature" information. Note that the
863 * assumption that all interesting "objects" and "terrain features" are
864 * memorized allows extremely optimized processing below. Note the use
865 * of separate flags on objects to mark them as memorized allows a grid
866 * to have memorized "terrain" without granting knowledge of any object
867 * which may appear in that grid.
869 * Note the efficient code used to determine if a "floor" grid is
870 * "memorized" or "viewable" by the player, where the test for the
871 * grid being "viewable" is based on the facts that (1) the grid
872 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
873 * line of sight, and (3) the player must not be blind, and uses the
874 * assumption that all torch-lit grids are in line of sight.
876 * Note that floors (and invisible traps) are the only grids which are
877 * not memorized when seen, so only these grids need to check to see if
878 * the grid is "viewable" to the player (if it is not memorized). Since
879 * most non-memorized grids are in fact walls, this induces *massive*
880 * efficiency, at the cost of *forcing* the memorization of non-floor
881 * grids when they are first seen. Note that "invisible traps" are
882 * always treated exactly like "floors", which prevents "cheating".
884 * Note the "special lighting effects" which can be activated for floor
885 * grids using the "view_special_lite" option (for "white" floor grids),
886 * causing certain grids to be displayed using special colors. If the
887 * player is "blind", we will use "dark gray", else if the grid is lit
888 * by the torch, and the "view_yellow_lite" option is set, we will use
889 * "yellow", else if the grid is "dark", we will use "dark gray", else
890 * if the grid is not "viewable", and the "view_bright_lite" option is
891 * set, and the we will use "slate" (gray). We will use "white" for all
892 * other cases, in particular, for illuminated viewable floor grids.
894 * Note the "special lighting effects" which can be activated for wall
895 * grids using the "view_granite_lite" option (for "white" wall grids),
896 * causing certain grids to be displayed using special colors. If the
897 * player is "blind", we will use "dark gray", else if the grid is lit
898 * by the torch, and the "view_yellow_lite" option is set, we will use
899 * "yellow", else if the "view_bright_lite" option is set, and the grid
900 * is not "viewable", or is "dark", or is glowing, but not when viewed
901 * from the player's current location, we will use "slate" (gray). We
902 * will use "white" for all other cases, in particular, for correctly
903 * illuminated viewable wall grids.
905 * Note that, when "view_granite_lite" is set, we use an inline version
906 * of the "player_can_see_bold()" function to check the "viewability" of
907 * grids when the "view_bright_lite" option is set, and we do NOT use
908 * any special colors for "dark" wall grids, since this would allow the
909 * player to notice the walls of illuminated rooms from a hallway that
910 * happened to run beside the room. The alternative, by the way, would
911 * be to prevent the generation of hallways next to rooms, but this
912 * would still allow problems when digging towards a room.
914 * Note that bizarre things must be done when the "attr" and/or "char"
915 * codes have the "high-bit" set, since these values are used to encode
916 * various "special" pictures in some versions, and certain situations,
917 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
918 * to be "scrambled" in various ways.
920 * Note that eventually we may use the "&" symbol for embedded treasure,
921 * and use the "*" symbol to indicate multiple objects, though this will
922 * have to wait for Angband 2.8.0 or later. Note that currently, this
923 * is not important, since only one object or terrain feature is allowed
924 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
926 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
927 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
928 * then a whole lot of code should be changed... XXX XXX
930 #ifdef USE_TRANSPARENCY
931 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
932 #else /* USE_TRANSPARENCY */
933 void map_info(int y, int x, byte *ap, char *cp)
934 #endif /* USE_TRANSPARENCY */
937 cave_type *c_ptr = &cave[y][x];
941 s16b this_o_idx, next_o_idx = 0;
943 /* Feature code (applying "mimic" field) */
944 byte feat = f_info[c_ptr->mimic ? c_ptr->mimic : c_ptr->feat].mimic;
949 /* Is this grid "darkened" by monster? */
950 bool darkened_grid = ((c_ptr->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) &&
951 !p_ptr->see_nocto && !p_ptr->blind;
954 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
956 /* Memorized (or visible) floor */
957 if ((c_ptr->info & CAVE_MARK) ||
958 (((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) ||
959 ((c_ptr->info & CAVE_VIEW) &&
960 (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))) &&
964 f_ptr = &f_info[feat];
972 /* Mega-Hack -- Handle "in-sight" and "darkened" grids first */
975 darkened_grid_hack();
978 /* Special lighting effects */
979 else if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_graphics))
987 * feat_supports_lighting(feat)
988 * is always TRUE here
991 /* Use a dark tile */
996 /* Use "dark gray" */
1001 /* Handle "torch-lit" grids */
1002 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1005 if (view_yellow_lite && !p_ptr->wild_mode)
1010 * feat_supports_lighting(feat)
1011 * is always TRUE here
1014 /* Use a brightly lit tile */
1025 /* Handle "dark" grids */
1026 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1031 * feat_supports_lighting(feat)
1032 * is always TRUE here
1035 /* Use a dark tile */
1040 /* Use "dark gray" */
1045 /* Handle "out-of-sight" grids */
1046 else if (!(c_ptr->info & CAVE_VIEW))
1049 if (view_bright_lite && !p_ptr->wild_mode)
1054 * feat_supports_lighting(feat)
1055 * is always TRUE here
1058 /* Use a dark tile */
1074 /* Unsafe cave grid -- idea borrowed from Unangband */
1075 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1076 feat = FEAT_UNDETECTD;
1080 /* Access darkness */
1081 f_ptr = &f_info[feat];
1094 /* Memorized grids */
1095 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || new_ascii_graphics))
1097 /* Access feature */
1098 f_ptr = &f_info[feat];
1106 /* Mega-Hack -- Handle "in-sight" and "darkened" grids first */
1109 darkened_grid_hack();
1112 else if (new_ascii_graphics)
1114 /* Handle "blind" */
1117 if (is_ascii_graphics(a))
1119 /* Use darkened colour */
1120 a = lighting_colours[a][1];
1122 else if (use_graphics && feat_supports_lighting(feat))
1124 /* Use a dark tile */
1129 /* Handle "torch-lit" grids */
1130 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1133 if (view_yellow_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(a)))
1135 if (is_ascii_graphics(a))
1137 /* Use lightened colour */
1138 a = lighting_colours[a][0];
1140 else if (use_graphics &&
1141 feat_supports_lighting(feat))
1143 /* Use a brightly lit tile */
1149 /* Handle "view_bright_lite" */
1150 else if (view_bright_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(a)))
1153 if (!(c_ptr->info & CAVE_VIEW))
1155 if (is_ascii_graphics(a))
1157 /* Use darkened colour */
1158 a = lighting_colours[a][1];
1160 else if (use_graphics && feat_supports_lighting(feat))
1162 /* Use a dark tile */
1168 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1170 if (is_ascii_graphics(a))
1172 /* Use darkened colour */
1173 a = lighting_colours[a][1];
1179 /* Special lighting effects */
1180 else if (view_granite_lite && !p_ptr->wild_mode &&
1181 (((a == TERM_WHITE) && !use_graphics) ||
1182 (use_graphics && feat_supports_lighting(feat))))
1184 /* Handle "blind" */
1189 /* Use a dark tile */
1194 /* Use "dark gray" */
1199 /* Handle "torch-lit" grids */
1200 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1203 if (view_yellow_lite && !p_ptr->wild_mode)
1207 /* Use a brightly lit tile */
1218 /* Handle "view_bright_lite" */
1219 else if (view_bright_lite && !p_ptr->wild_mode)
1222 if (!(c_ptr->info & CAVE_VIEW))
1226 /* Use a dark tile */
1237 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1241 /* Use a lit tile */
1250 /* Not glowing correctly */
1255 /* Hack -- move towards player */
1256 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1257 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1259 /* Check for "local" illumination */
1260 if ((cave[yy][xx].info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1264 /* Use a lit tile */
1277 /* "Simple Lighting" */
1280 /* Handle "blind" */
1281 if (!(c_ptr->info & CAVE_MARK))
1283 /* Unsafe cave grid -- idea borrowed from Unangband */
1284 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1285 feat = FEAT_UNDETECTD;
1290 /* Access feature */
1291 f_ptr = &f_info[feat];
1299 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1302 darkened_grid_hack();
1307 if (feat_priority == -1)
1312 case FEAT_UNDETECTD:
1319 case FEAT_TRAP_TRAPDOOR:
1321 case FEAT_TRAP_SPIKED_PIT:
1322 case FEAT_TRAP_POISON_PIT:
1323 case FEAT_TRAP_TY_CURSE:
1324 case FEAT_TRAP_TELEPORT:
1325 case FEAT_TRAP_FIRE:
1326 case FEAT_TRAP_ACID:
1327 case FEAT_TRAP_SLOW:
1328 case FEAT_TRAP_LOSE_STR:
1329 case FEAT_TRAP_LOSE_DEX:
1330 case FEAT_TRAP_LOSE_CON:
1331 case FEAT_TRAP_BLIND:
1332 case FEAT_TRAP_CONFUSE:
1333 case FEAT_TRAP_POISON:
1334 case FEAT_TRAP_SLEEP:
1335 case FEAT_TRAP_TRAPS:
1336 case FEAT_TRAP_ALARM:
1340 case FEAT_DEEP_GRASS:
1348 case FEAT_WALL_EXTRA:
1349 case FEAT_WALL_INNER:
1350 case FEAT_WALL_OUTER:
1351 case FEAT_WALL_SOLID:
1352 case FEAT_DEEP_WATER:
1353 case FEAT_SHAL_WATER:
1354 case FEAT_DEEP_LAVA:
1355 case FEAT_SHAL_LAVA:
1361 /* Now a days treasere grid is too many */
1366 case FEAT_PERM_EXTRA:
1367 case FEAT_PERM_INNER:
1368 case FEAT_PERM_OUTER:
1369 case FEAT_PERM_SOLID:
1373 /* default is feat_priority = 20; (doors and stores) */
1376 case FEAT_MINOR_GLYPH:
1378 case FEAT_PATTERN_START:
1379 case FEAT_PATTERN_1:
1380 case FEAT_PATTERN_2:
1381 case FEAT_PATTERN_3:
1382 case FEAT_PATTERN_4:
1383 case FEAT_PATTERN_END:
1384 case FEAT_PATTERN_OLD:
1385 case FEAT_PATTERN_XTRA1:
1386 case FEAT_PATTERN_XTRA2:
1390 /* objects have feat_priority = 20 */
1391 /* monsters have feat_priority = 30 */
1395 case FEAT_QUEST_ENTER:
1396 case FEAT_QUEST_EXIT:
1397 case FEAT_QUEST_DOWN:
1399 case FEAT_LESS_LESS:
1400 case FEAT_MORE_MORE:
1412 #ifdef USE_TRANSPARENCY
1413 /* Save the terrain info for the transparency effects */
1416 #endif /* USE_TRANSPARENCY */
1422 /* Hack -- rare random hallucination, except on outer dungeon walls */
1423 if (p_ptr->image && (feat < FEAT_PERM_SOLID) && one_in_(256))
1426 image_random(ap, cp);
1430 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1434 /* Acquire object */
1435 o_ptr = &o_list[this_o_idx];
1437 /* Acquire next object */
1438 next_o_idx = o_ptr->next_o_idx;
1440 /* Memorized objects */
1443 if (display_autopick)
1447 match_autopick = is_autopick(o_ptr);
1448 if(match_autopick == -1)
1451 act = autopick_list[match_autopick].action;
1453 if ((act & DO_DISPLAY) && (act & display_autopick))
1455 autopick_obj = o_ptr;
1459 match_autopick = -1;
1464 (*cp) = object_char(o_ptr);
1467 (*ap) = object_attr(o_ptr);
1471 /* Hack -- hallucination */
1472 if (p_ptr->image) image_object(ap, cp);
1480 /* Handle monsters */
1481 if (c_ptr->m_idx && display_autopick == 0 )
1483 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1485 /* Visible monster */
1488 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1496 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1497 * flags are always unseen.
1499 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1505 /* Hallucinatory monster */
1506 image_monster(ap, cp);
1511 /* Monster attr/char */
1515 /* Normal monsters */
1516 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1517 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1519 /* Desired monster attr/char */
1525 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1526 * flags are always unseen.
1528 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1535 /*** Monster's attr ***/
1536 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1541 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1543 /* Multi-hued attr */
1544 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1545 else switch (randint1(7))
1547 case 1: *ap = TERM_RED; break;
1548 case 2: *ap = TERM_L_RED; break;
1549 case 3: *ap = TERM_WHITE; break;
1550 case 4: *ap = TERM_L_GREEN; break;
1551 case 5: *ap = TERM_BLUE; break;
1552 case 6: *ap = TERM_L_DARK; break;
1553 case 7: *ap = TERM_GREEN; break;
1556 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1558 /* Use semi-random attr (usually mimics' colors vary) */
1559 *ap = c_ptr->m_idx % 15 + 1;
1567 /*** Monster's char ***/
1568 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1573 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1577 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1578 *cp = tmp_r_ptr->x_char;
1579 *ap = tmp_r_ptr->x_attr;
1583 *cp = (one_in_(25) ?
1584 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1585 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1598 /* Handle "player" */
1599 if (player_bold(y, x))
1601 monster_race *r_ptr = &r_info[0];
1603 /* Get the "player" attr */
1604 *ap = r_ptr->x_attr;
1606 /* Get the "player" char */
1607 *cp = r_ptr->x_char;
1616 * Table of Ascii-to-Zenkaku
1617 * ¡Ö¢£¡×¤ÏÆóÇÜÉýƦÉå¤ÎÆâÉô¥³¡¼¥É¤Ë»ÈÍÑ¡£
1619 static char ascii_to_zenkaku[2*128+1] = "\
1620 ¡¡¡ª¡É¡ô¡ð¡ó¡õ¡Ç¡Ê¡Ë¡ö¡Ü¡¤¡Ý¡¥¡¿\
1621 £°£±£²£³£´£µ£¶£·£¸£¹¡§¡¨¡ã¡á¡ä¡©\
1622 ¡÷£Á£Â£Ã£Ä£Å£Æ£Ç£È£É£Ê£Ë£Ì£Í£Î£Ï\
1623 £Ð£Ñ£Ò£Ó£Ô£Õ£Ö£×£Ø£Ù£Ú¡Î¡À¡Ï¡°¡²\
1624 ¡Æ£á£â£ã£ä£å£æ£ç£è£é£ê£ë£ì£í£î£ï\
1625 £ð£ñ£ò£ó£ô£õ£ö£÷£ø£ù£ú¡Ð¡Ã¡Ñ¡Á¢£";
1629 * Prepare Bigtile or 2-bytes character attr/char pairs
1631 void bigtile_attr(char *cp, byte *ap, char *cp2, byte *ap2)
1633 if ((*ap & 0x80) && (*cp & 0x80))
1641 if (isprint(*cp) || *cp == 127)
1643 *ap2 = (*ap) | 0xf0;
1644 *cp2 = ascii_to_zenkaku[2*(*cp-' ') + 1];
1645 *cp = ascii_to_zenkaku[2*(*cp-' ')];
1656 * Calculate panel colum of a location in the map
1658 static int panel_col_of(int col)
1660 col -= panel_col_min;
1661 if (use_bigtile) col *= 2;
1667 * Moves the cursor to a given MAP (y,x) location
1669 void move_cursor_relative(int row, int col)
1671 /* Real co-ords convert to screen positions */
1672 row -= panel_row_prt;
1675 Term_gotoxy(panel_col_of(col), row);
1681 * Place an attr/char pair at the given map coordinate, if legal.
1683 void print_rel(char c, byte a, int y, int x)
1688 /* Only do "legal" locations */
1689 if (panel_contains(y, x))
1691 /* Hack -- fake monochrome */
1694 if (world_monster) a = TERM_DARK;
1695 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1696 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1699 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
1701 /* Draw the char using the attr */
1702 Term_draw(panel_col_of(x), y-panel_row_prt, a, c);
1704 Term_draw(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
1713 * Memorize interesting viewable object/features in the given grid
1715 * This function should only be called on "legal" grids.
1717 * This function will memorize the object and/or feature in the given
1718 * grid, if they are (1) viewable and (2) interesting. Note that all
1719 * objects are interesting, all terrain features except floors (and
1720 * invisible traps) are interesting, and floors (and invisible traps)
1721 * are interesting sometimes (depending on various options involving
1722 * the illumination of floor grids).
1724 * The automatic memorization of all objects and non-floor terrain
1725 * features as soon as they are displayed allows incredible amounts
1726 * of optimization in various places, especially "map_info()".
1728 * Note that the memorization of objects is completely separate from
1729 * the memorization of terrain features, preventing annoying floor
1730 * memorization when a detected object is picked up from a dark floor,
1731 * and object memorization when an object is dropped into a floor grid
1732 * which is memorized but out-of-sight.
1734 * This function should be called every time the "memorization" of
1735 * a grid (or the object in a grid) is called into question, such
1736 * as when an object is created in a grid, when a terrain feature
1737 * "changes" from "floor" to "non-floor", when any grid becomes
1738 * "illuminated" or "viewable", and when a "floor" grid becomes
1741 * Note the relatively efficient use of this function by the various
1742 * "update_view()" and "update_lite()" calls, to allow objects and
1743 * terrain features to be memorized (and drawn) whenever they become
1744 * viewable or illuminated in any way, but not when they "maintain"
1745 * or "lose" their previous viewability or illumination.
1747 * Note the butchered "internal" version of "player_can_see_bold()",
1748 * optimized primarily for the most common cases, that is, for the
1749 * non-marked floor grids.
1751 void note_spot(int y, int x)
1753 cave_type *c_ptr = &cave[y][x];
1755 s16b this_o_idx, next_o_idx = 0;
1759 /* Feature code (applying "mimic" field) */
1760 feat = f_info[c_ptr->mimic ? c_ptr->mimic : c_ptr->feat].mimic;
1763 /* Blind players see nothing */
1764 if (p_ptr->blind) return;
1766 /* Analyze non-torch-lit grids */
1767 if (!(c_ptr->info & (CAVE_LITE)))
1769 /* Require line of sight to the grid */
1770 if (!(c_ptr->info & (CAVE_VIEW))) return;
1772 /* Require "perma-lite" of the grid */
1773 if (!(c_ptr->info & CAVE_MNLT) && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW))
1776 if (!p_ptr->see_nocto) return;
1781 /* Hack -- memorize objects */
1782 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1784 object_type *o_ptr = &o_list[this_o_idx];
1786 /* Acquire next object */
1787 next_o_idx = o_ptr->next_o_idx;
1789 /* Memorize objects */
1790 o_ptr->marked |= OM_FOUND;
1794 /* Hack -- memorize grids */
1795 if (!(c_ptr->info & (CAVE_MARK)))
1797 /* Handle floor grids first */
1798 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
1800 /* Option -- memorize all torch-lit floors */
1801 if (view_torch_grids &&
1802 ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1805 c_ptr->info |= (CAVE_MARK);
1808 /* Option -- memorize all perma-lit floors */
1809 else if (view_perma_grids && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1812 c_ptr->info |= (CAVE_MARK);
1816 /* Memorize normal grids */
1817 else if (cave_floor_grid(c_ptr))
1820 c_ptr->info |= (CAVE_MARK);
1823 /* Memorize torch-lit walls */
1824 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1827 c_ptr->info |= (CAVE_MARK);
1830 /* Memorize walls seen by noctovision of Ninja */
1831 else if (p_ptr->see_nocto)
1834 c_ptr->info |= (CAVE_MARK);
1837 /* Memorize certain non-torch-lit wall grids */
1842 /* Hack -- move one grid towards player */
1843 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1844 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1846 /* Check for "local" illumination */
1847 if ((cave[yy][xx].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
1850 c_ptr->info |= (CAVE_MARK);
1857 void display_dungeon(void)
1863 #ifdef USE_TRANSPARENCY
1866 #endif /* USE_TRANSPARENCY */
1868 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1870 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1872 if (in_bounds2(y, x))
1875 #ifdef USE_TRANSPARENCY
1876 /* Examine the grid */
1877 map_info(y, x, &a, &c, &ta, &tc);
1878 #else /* USE_TRANSPARENCY */
1879 /* Examine the grid */
1880 map_info(y, x, &a, &c);
1881 #endif /* USE_TRANSPARENCY */
1883 /* Hack -- fake monochrome */
1886 if (world_monster) a = TERM_DARK;
1887 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1888 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1891 #ifdef USE_TRANSPARENCY
1892 /* Hack -- Queue it */
1893 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1894 #else /* USE_TRANSPARENCY */
1895 /* Hack -- Queue it */
1896 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
1897 #endif /* USE_TRANSPARENCY */
1902 /* Clear out-of-bound tiles */
1904 /* Access darkness */
1905 feature_type *f_ptr = &f_info[FEAT_NONE];
1913 #ifdef USE_TRANSPARENCY
1914 /* Hack -- Queue it */
1915 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1916 #else /* USE_TRANSPARENCY */
1917 /* Hack -- Queue it */
1918 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
1919 #endif /* USE_TRANSPARENCY */
1927 * Redraw (on the screen) a given MAP location
1929 * This function should only be called on "legal" grids
1931 void lite_spot(int y, int x)
1933 /* Redraw if on screen */
1934 if (panel_contains(y, x) && in_bounds2(y, x))
1939 #ifdef USE_TRANSPARENCY
1943 /* Examine the grid */
1944 map_info(y, x, &a, &c, &ta, &tc);
1945 #else /* USE_TRANSPARENCY */
1946 /* Examine the grid */
1947 map_info(y, x, &a, &c);
1948 #endif /* USE_TRANSPARENCY */
1950 /* Hack -- fake monochrome */
1953 if (world_monster) a = TERM_DARK;
1954 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1955 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1959 if (use_bigtile && is_ascii_graphics(a) && (isprint(c) || c == 127))
1961 /* Term_queue_chars ¤ÏÁ´³ÑASCIIÃÏ·Á¤òÀµ¤·¤¯update¤¹¤ë¡£ */
1962 Term_queue_chars(panel_col_of(x), y-panel_row_prt, 2, a, &ascii_to_zenkaku[2*(c-' ')]);
1967 #ifdef USE_TRANSPARENCY
1968 /* Hack -- Queue it */
1969 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1971 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1, 0, 0);
1972 #else /* USE_TRANSPARENCY */
1973 /* Hack -- Queue it */
1974 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
1976 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1);
1977 #endif /* USE_TRANSPARENCY */
1979 /* Update sub-windows */
1980 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1986 * Prints the map of the dungeon
1988 * Note that, for efficiency, we contain an "optimized" version
1989 * of both "lite_spot()" and "print_rel()", and that we use the
1990 * "lite_spot()" function to display the player grid, if needed.
1998 s16b xmin, xmax, ymin, ymax;
2003 Term_get_size(&wid, &hgt);
2005 /* Remove map offset */
2009 /* Access the cursor state */
2010 (void)Term_get_cursor(&v);
2012 /* Hide the cursor */
2013 (void)Term_set_cursor(0);
2016 xmin = (0 < panel_col_min) ? panel_col_min : 0;
2017 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
2018 ymin = (0 < panel_row_min) ? panel_row_min : 0;
2019 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
2021 /* Bottom section of screen */
2022 for (y = 1; y <= ymin - panel_row_prt; y++)
2024 /* Erase the section */
2025 Term_erase(COL_MAP, y, wid);
2028 /* Top section of screen */
2029 for (y = ymax - panel_row_prt; y <= hgt; y++)
2031 /* Erase the section */
2032 Term_erase(COL_MAP, y, wid);
2036 for (y = ymin; y <= ymax; y++)
2038 /* Scan the columns of row "y" */
2039 for (x = xmin; x <= xmax; x++)
2044 #ifdef USE_TRANSPARENCY
2048 /* Determine what is there */
2049 map_info(y, x, &a, &c, &ta, &tc);
2051 /* Determine what is there */
2052 map_info(y, x, &a, &c);
2055 /* Hack -- fake monochrome */
2058 if (world_monster) a = TERM_DARK;
2059 else if (IS_INVULN() || world_player) a = TERM_WHITE;
2060 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2063 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2065 /* Efficiency -- Redraw that grid of the map */
2066 #ifdef USE_TRANSPARENCY
2067 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
2068 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2, 0, 0);
2070 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
2071 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
2076 /* Display player */
2079 /* Restore the cursor */
2080 (void)Term_set_cursor(v);
2086 * print project path
2088 void prt_path(int y, int x)
2093 int default_color = TERM_SLATE;
2095 if (!display_path) return;
2096 if (-1 == project_length)
2099 /* Get projection path */
2100 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2103 p_ptr->redraw |= (PR_MAP);
2109 for (i = 0; i < path_n; i++)
2111 int ny = GRID_Y(path_g[i]);
2112 int nx = GRID_X(path_g[i]);
2114 if (panel_contains(ny, nx))
2116 byte a2, a = default_color;
2119 #ifdef USE_TRANSPARENCY
2124 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2126 /* Determine what is there */
2127 #ifdef USE_TRANSPARENCY
2128 map_info(ny, nx, &a, &c, &ta, &tc);
2130 map_info(ny, nx, &a, &c);
2132 if (!is_ascii_graphics(a))
2134 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2136 else if (a == default_color)
2142 if (world_monster) a = TERM_DARK;
2143 else if (IS_INVULN() || world_player) a = TERM_WHITE;
2144 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2148 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2150 /* Hack -- Queue it */
2151 #ifdef USE_TRANSPARENCY
2152 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
2153 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2, 0, 0);
2155 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c);
2156 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2);
2161 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2164 if (nx == x && ny == y) default_color = TERM_L_DARK;
2169 static cptr simplify_list[][2] =
2176 {"^Amulet of ", "\""},
2177 {"^Scroll of ", "?"},
2178 {"^Scroll titled ", "?"},
2179 {"^Wand of " , "-"},
2181 {"^Staff of " , "_"},
2182 {"^Potion of ", "!"},
2194 static void display_shortened_item_name(object_type *o_ptr, int y)
2201 object_desc(buf, o_ptr, FALSE, 0);
2202 attr = tval_to_attr[o_ptr->tval % 128];
2208 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
2210 strcpy(buf, "something strange");
2214 for (c = buf; *c; c++)
2217 for (i = 0; simplify_list[i][1]; i++)
2219 cptr org_w = simplify_list[i][0];
2229 if (!strncmp(c, org_w, strlen(org_w)))
2232 cptr tmp = simplify_list[i][1];
2235 tmp = c + strlen(org_w);
2245 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2251 if(len + 2 > 12) break;
2258 if(len + 1 > 12) break;
2264 Term_putstr(0, y, 12, attr, buf);
2268 * Display a "small-scale" map of the dungeon in the active Term
2270 void display_map(int *cy, int *cx)
2287 /* Save lighting effects */
2288 bool old_view_special_lite = view_special_lite;
2289 bool old_view_granite_lite = view_granite_lite;
2291 int hgt, wid, yrat, xrat;
2293 int **match_autopick_yx;
2294 object_type ***object_autopick_yx;
2297 Term_get_size(&wid, &hgt);
2300 if (use_bigtile) wid /= 2;
2302 yrat = (cur_hgt + hgt - 1) / hgt;
2303 xrat = (cur_wid + wid - 1) / wid;
2305 /* Disable lighting effects */
2306 view_special_lite = FALSE;
2307 view_granite_lite = FALSE;
2309 /* Allocate the maps */
2310 C_MAKE(ma, (hgt + 2), byte_ptr);
2311 C_MAKE(mc, (hgt + 2), char_ptr);
2312 C_MAKE(mp, (hgt + 2), byte_ptr);
2313 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2314 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2316 /* Allocate and wipe each line map */
2317 for (y = 0; y < (hgt + 2); y++)
2319 /* Allocate one row each array */
2320 C_MAKE(ma[y], (wid + 2), byte);
2321 C_MAKE(mc[y], (wid + 2), char);
2322 C_MAKE(mp[y], (wid + 2), byte);
2323 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2324 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2326 for (x = 0; x < wid + 2; ++x)
2328 match_autopick_yx[y][x] = -1;
2329 object_autopick_yx[y][x] = NULL;
2332 ma[y][x] = TERM_WHITE;
2340 /* Allocate the maps */
2341 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
2342 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
2343 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
2345 /* Allocate and wipe each line map */
2346 for (y = 0; y < (cur_hgt + 2); y++)
2348 /* Allocate one row each array */
2349 C_MAKE(bigma[y], (cur_wid + 2), byte);
2350 C_MAKE(bigmc[y], (cur_wid + 2), char);
2351 C_MAKE(bigmp[y], (cur_wid + 2), byte);
2353 for (x = 0; x < cur_wid + 2; ++x)
2356 bigma[y][x] = TERM_WHITE;
2364 /* Fill in the map */
2365 for (i = 0; i < cur_wid; ++i)
2367 for (j = 0; j < cur_hgt; ++j)
2377 /* Extract the current attr/char at that map location */
2378 #ifdef USE_TRANSPARENCY
2379 map_info(j, i, &ta, &tc, &ta, &tc);
2380 #else /* USE_TRANSPARENCY */
2381 map_info(j, i, &ta, &tc);
2382 #endif /* USE_TRANSPARENCY */
2384 /* Extract the priority */
2387 if(match_autopick!=-1
2388 && (match_autopick_yx[y][x] == -1
2389 || match_autopick_yx[y][x] > match_autopick))
2391 match_autopick_yx[y][x] = match_autopick;
2392 object_autopick_yx[y][x] = autopick_obj;
2396 /* Save the char, attr and priority */
2397 bigmc[j+1][i+1] = tc;
2398 bigma[j+1][i+1] = ta;
2399 bigmp[j+1][i+1] = tp;
2403 for (j = 0; j < cur_hgt; ++j)
2405 for (i = 0; i < cur_wid; ++i)
2411 tc = bigmc[j+1][i+1];
2412 ta = bigma[j+1][i+1];
2413 tp = bigmp[j+1][i+1];
2415 /* rare feature has more priority */
2421 for (t = 0; t < 8; t++)
2423 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2424 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2434 /* Save the char, attr and priority */
2447 /* Draw the corners */
2448 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2450 /* Draw the horizontal edges */
2451 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2453 /* Draw the vertical edges */
2454 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2457 /* Display each map line in order */
2458 for (y = 0; y < hgt + 2; ++y)
2460 /* Start a new line */
2461 Term_gotoxy(COL_MAP, y);
2463 /* Display the line */
2464 for (x = 0; x < wid + 2; ++x)
2469 /* Hack -- fake monochrome */
2472 if (world_monster) ta = TERM_DARK;
2473 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2474 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2477 if (use_bigtile) bigtile_attr(&tc, &ta, &c2, &a2);
2479 /* Add the character */
2481 if (use_bigtile) Term_addch(a2, c2);
2486 for (y = 1; y < hgt + 1; ++y)
2488 match_autopick = -1;
2489 for (x = 1; x <= wid; x++){
2490 if (match_autopick_yx[y][x] != -1 &&
2491 (match_autopick > match_autopick_yx[y][x] ||
2492 match_autopick == -1)){
2493 match_autopick = match_autopick_yx[y][x];
2494 autopick_obj = object_autopick_yx[y][x];
2498 /* Clear old display */
2499 Term_putstr(0, y, 12, 0, " ");
2501 if (match_autopick != -1)
2503 display_shortened_item_name(autopick_obj, y);
2506 char buf[13] = "\0";
2507 strncpy(buf,autopick_list[match_autopick].name,12);
2515 /* Player location */
2516 (*cy) = py / yrat + 1 + ROW_MAP;
2518 (*cx) = px / xrat + 1 + COL_MAP;
2520 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2522 /* Restore lighting effects */
2523 view_special_lite = old_view_special_lite;
2524 view_granite_lite = old_view_granite_lite;
2526 /* Free each line map */
2527 for (y = 0; y < (hgt + 2); y++)
2529 /* Free one row each array */
2530 C_FREE(ma[y], (wid + 2), byte);
2531 C_FREE(mc[y], (wid + 2), char);
2532 C_FREE(mp[y], (wid + 2), byte);
2533 C_FREE(match_autopick_yx[y], (wid + 2), int);
2534 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2537 /* Free each line map */
2538 C_FREE(ma, (hgt + 2), byte_ptr);
2539 C_FREE(mc, (hgt + 2), char_ptr);
2540 C_FREE(mp, (hgt + 2), byte_ptr);
2541 C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2542 C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2544 /* Free each line map */
2545 for (y = 0; y < (cur_hgt + 2); y++)
2547 /* Free one row each array */
2548 C_FREE(bigma[y], (cur_wid + 2), byte);
2549 C_FREE(bigmc[y], (cur_wid + 2), char);
2550 C_FREE(bigmp[y], (cur_wid + 2), byte);
2553 /* Free each line map */
2554 C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2555 C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2556 C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2561 * Display a "small-scale" map of the dungeon for the player
2563 * Currently, the "player" is displayed on the map. XXX XXX XXX
2565 void do_cmd_view_map(void)
2570 /* Save the screen */
2575 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2577 prt("Please wait...", 0, 0);
2583 /* Clear the screen */
2586 display_autopick = 0;
2588 /* Display the map */
2589 display_map(&cy, &cx);
2592 if(max_autopick && !p_ptr->wild_mode)
2594 display_autopick = ITEM_DISPLAY;
2601 int wid, hgt, row_message;
2603 Term_get_size(&wid, &hgt);
2604 row_message = hgt - 1;
2607 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2609 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2612 /* Hilite the player */
2613 move_cursor(cy, cx);
2618 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2620 flag = DONT_AUTOPICK;
2622 flag = DO_AUTODESTROY;
2624 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2630 if (~display_autopick & flag)
2631 display_autopick |= flag;
2633 display_autopick &= ~flag;
2634 /* Display the map */
2635 display_map(&cy, &cx);
2638 display_autopick = 0;
2644 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2646 put_str("Hit any key to continue", 23, 30);
2647 #endif /* Hilite the player */
2648 move_cursor(cy, cx);
2653 /* Restore the screen */
2662 * Some comments on the cave grid flags. -BEN-
2665 * One of the major bottlenecks in previous versions of Angband was in
2666 * the calculation of "line of sight" from the player to various grids,
2667 * such as monsters. This was such a nasty bottleneck that a lot of
2668 * silly things were done to reduce the dependancy on "line of sight",
2669 * for example, you could not "see" any grids in a lit room until you
2670 * actually entered the room, and there were all kinds of bizarre grid
2671 * flags to enable this behavior. This is also why the "call light"
2672 * spells always lit an entire room.
2674 * The code below provides functions to calculate the "field of view"
2675 * for the player, which, once calculated, provides extremely fast
2676 * calculation of "line of sight from the player", and to calculate
2677 * the "field of torch lite", which, again, once calculated, provides
2678 * extremely fast calculation of "which grids are lit by the player's
2679 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2680 * "GRID_LITE", as appropriate, these functions maintain an array for
2681 * each of these two flags, each array containing the locations of all
2682 * of the grids marked with the appropriate flag, which can be used to
2683 * very quickly scan through all of the grids in a given set.
2685 * To allow more "semantically valid" field of view semantics, whenever
2686 * the field of view (or the set of torch lit grids) changes, all of the
2687 * grids in the field of view (or the set of torch lit grids) are "drawn"
2688 * so that changes in the world will become apparent as soon as possible.
2689 * This has been optimized so that only grids which actually "change" are
2690 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2691 * of the grids which are entering or leaving the relevent set of grids.
2693 * These new methods are so efficient that the old nasty code was removed.
2695 * Note that there is no reason to "update" the "viewable space" unless
2696 * the player "moves", or walls/doors are created/destroyed, and there
2697 * is no reason to "update" the "torch lit grids" unless the field of
2698 * view changes, or the "light radius" changes. This means that when
2699 * the player is resting, or digging, or doing anything that does not
2700 * involve movement or changing the state of the dungeon, there is no
2701 * need to update the "view" or the "lite" regions, which is nice.
2703 * Note that the calls to the nasty "los()" function have been reduced
2704 * to a bare minimum by the use of the new "field of view" calculations.
2706 * I wouldn't be surprised if slight modifications to the "update_view()"
2707 * function would allow us to determine "reverse line-of-sight" as well
2708 * as "normal line-of-sight", which would allow monsters to use a more
2709 * "correct" calculation to determine if they can "see" the player. For
2710 * now, monsters simply "cheat" somewhat and assume that if the player
2711 * has "line of sight" to the monster, then the monster can "pretend"
2712 * that it has "line of sight" to the player.
2715 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2716 * grid and maintains an array of all "CAVE_LITE" grids.
2718 * This set of grids is the complete set of all grids which are lit by
2719 * the players light source, which allows the "player_can_see_bold()"
2720 * function to work very quickly.
2722 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2723 * fact, the player (unless blind) can always "see" all grids which are
2724 * marked as "CAVE_LITE", unless they are "off screen".
2727 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2728 * grid and maintains an array of all "CAVE_VIEW" grids.
2730 * This set of grids is the complete set of all grids within line of sight
2731 * of the player, allowing the "player_has_los_bold()" macro to work very
2735 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2736 * temporary internal flag to mark those grids which are not only in view,
2737 * but which are also "easily" in line of sight of the player. This flag
2738 * is always cleared when we are done.
2741 * The current "update_lite()" and "update_view()" algorithms use the
2742 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2743 * to keep track of which grids were previously marked as "CAVE_LITE" or
2744 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2746 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2747 * for various other purposes, such as spreading lite or darkness during
2748 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2751 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2752 * in some way permanently lit. However, for the player to "see" anything
2753 * in the grid, as determined by "player_can_see()", the player must not be
2754 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2755 * grids, even if marked as "perma lit", are only illuminated if they touch
2756 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2759 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2760 * that even if the player cannot "see" the grid, he "knows" the terrain in
2761 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2762 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2763 * or when one of the "memorize floor grids" options induces memorization.
2765 * Objects are "memorized" in a different way, using a special "marked" flag
2766 * on the object itself, which is set when an object is observed or detected.
2769 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2770 * and should be illuminated by "lite room" and "darkness" spells.
2773 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2774 * and should be unavailable for "teleportation" destinations.
2777 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2778 * which is observed, and the "view_torch_grids" allows the player to memorize
2779 * every torch-lit grid. The player will always memorize important walls,
2780 * doors, stairs, and other terrain features, as well as any "detected" grids.
2782 * Note that the new "update_view()" method allows, among other things, a room
2783 * to be "partially" seen as the player approaches it, with a growing cone of
2784 * floor appearing as the player gets closer to the door. Also, by not turning
2785 * on the "memorize perma-lit grids" option, the player will only "see" those
2786 * floor grids which are actually in line of sight.
2788 * And my favorite "plus" is that you can now use a special option to draw the
2789 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2790 * grids dimly), providing a "pretty" effect as the player runs around, and
2791 * to efficiently display the "torch lite" in a special color.
2794 * Some comments on the "update_view()" algorithm...
2796 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2797 * and only has to call "los()" on the borderline cases. The major axes/diags
2798 * even terminate early when they hit walls. I need to find a quick way
2799 * to "terminate" the other scans.
2801 * Note that in the worst case (a big empty area with say 5% scattered walls),
2802 * each of the 1500 or so nearby grids is checked once, most of them getting
2803 * an "instant" rating, and only a small portion requiring a call to "los()".
2805 * The only time that the algorithm appears to be "noticeably" too slow is
2806 * when running, and this is usually only important in town, since the town
2807 * provides about the worst scenario possible, with large open regions and
2808 * a few scattered obstructions. There is a special "efficiency" option to
2809 * allow the player to reduce his field of view in town, if needed.
2811 * In the "best" case (say, a normal stretch of corridor), the algorithm
2812 * makes one check for each viewable grid, and makes no calls to "los()".
2813 * So running in corridors is very fast, and if a lot of monsters are
2814 * nearby, it is much faster than the old methods.
2816 * Note that resting, most normal commands, and several forms of running,
2817 * plus all commands executed near large groups of monsters, are strictly
2818 * more efficient with "update_view()" that with the old "compute los() on
2819 * demand" method, primarily because once the "field of view" has been
2820 * calculated, it does not have to be recalculated until the player moves
2821 * (or a wall or door is created or destroyed).
2823 * Note that we no longer have to do as many "los()" checks, since once the
2824 * "view" region has been built, very few things cause it to be "changed"
2825 * (player movement, and the opening/closing of doors, changes in wall status).
2826 * Note that door/wall changes are only relevant when the door/wall itself is
2827 * in the "view" region.
2829 * The algorithm seems to only call "los()" from zero to ten times, usually
2830 * only when coming down a corridor into a room, or standing in a room, just
2831 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2832 * we will be reducing the calls to "los()".
2834 * I am thinking in terms of an algorithm that "walks" from the central point
2835 * out to the maximal "distance", at each point, determining the "view" code
2836 * (above). For each grid not on a major axis or diagonal, the "view" code
2837 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
2838 * (the one along the nearest diagonal, and the one next to that one, see
2839 * "update_view_aux()"...).
2841 * We "memorize" the viewable space array, so that at the cost of under 3000
2842 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2843 * each grid actually in the "viewable space". And for another 3000 bytes,
2844 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2845 * are also used by other routines, thus reducing the cost to almost nothing.
2847 * A similar thing is done for "forget_lite()" in which case the savings are
2848 * much less, but save us from doing bizarre maintenance checking.
2850 * In the worst "normal" case (in the middle of the town), the reachable space
2851 * actually reaches to more than half of the largest possible "circle" of view,
2852 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2853 * where all the walls have been removed), the reachable space actually reaches
2854 * the theoretical maximum size of just under 1500 grids.
2856 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2857 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2858 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2859 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2860 * entire possible space (including initialization) in one step per grid. If
2861 * we do the "clearing" as a separate step (and use an array of "view" grids),
2862 * then the clearing will take as many steps as grids that were viewed, and the
2863 * algorithm will be able to "stop" scanning at various points.
2864 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2875 * Actually erase the entire "lite" array, redrawing every grid
2877 void forget_lite(void)
2881 /* None to forget */
2882 if (!lite_n) return;
2884 /* Clear them all */
2885 for (i = 0; i < lite_n; i++)
2890 /* Forget "LITE" flag */
2891 cave[y][x].info &= ~(CAVE_LITE);
2894 /* lite_spot(y, x); Perhaps don't need? */
2903 * For delayed visual update
2905 #define cave_note_and_redraw_later(C,Y,X) \
2907 (C)->info |= CAVE_NOTE; \
2908 cave_redraw_later((C), (Y), (X)); \
2913 * For delayed visual update
2915 #define cave_redraw_later(C,Y,X) \
2917 if (!((C)->info & CAVE_REDRAW)) \
2919 (C)->info |= CAVE_REDRAW; \
2920 redraw_y[redraw_n] = (Y); \
2921 redraw_x[redraw_n++] = (X); \
2929 * This macro allows us to efficiently add a grid to the "lite" array,
2930 * note that we are never called for illegal grids, or for grids which
2931 * have already been placed into the "lite" array, and we are never
2932 * called when the "lite" array is full.
2934 #define cave_lite_hack(Y,X) \
2936 if (!(cave[Y][X].info & (CAVE_LITE))) { \
2937 cave[Y][X].info |= (CAVE_LITE); \
2938 lite_y[lite_n] = (Y); \
2939 lite_x[lite_n] = (X); \
2945 * Update the set of grids "illuminated" by the player's lite.
2947 * This routine needs to use the results of "update_view()"
2949 * Note that "blindness" does NOT affect "torch lite". Be careful!
2951 * We optimize most lites (all non-artifact lites) by using "obvious"
2952 * facts about the results of "small" lite radius, and we attempt to
2953 * list the "nearby" grids before the more "distant" ones in the
2954 * array of torch-lit grids.
2956 * We assume that "radius zero" lite is in fact no lite at all.
2958 * Torch Lantern Artifacts
2968 void update_lite(void)
2970 int i, x, y, min_x, max_x, min_y, max_y;
2971 int p = p_ptr->cur_lite;
2974 /*** Special case ***/
2977 /* Hack -- Player has no lite */
2980 /* Forget the old lite */
2981 /* forget_lite(); Perhaps don't need? */
2983 /* Add it to later visual update */
2984 cave_redraw_later(&cave[py][px], py, px);
2988 /*** Save the old "lite" grids for later ***/
2990 /* Clear them all */
2991 for (i = 0; i < lite_n; i++)
2996 /* Mark the grid as not "lite" */
2997 cave[y][x].info &= ~(CAVE_LITE);
2999 /* Mark the grid as "seen" */
3000 cave[y][x].info |= (CAVE_TEMP);
3002 /* Add it to the "seen" set */
3012 /*** Collect the new "lite" grids ***/
3014 /* Radius 1 -- torch radius */
3018 cave_lite_hack(py, px);
3021 cave_lite_hack(py+1, px);
3022 cave_lite_hack(py-1, px);
3023 cave_lite_hack(py, px+1);
3024 cave_lite_hack(py, px-1);
3026 /* Diagonal grids */
3027 cave_lite_hack(py+1, px+1);
3028 cave_lite_hack(py+1, px-1);
3029 cave_lite_hack(py-1, px+1);
3030 cave_lite_hack(py-1, px-1);
3033 /* Radius 2 -- lantern radius */
3036 /* South of the player */
3037 if (cave_floor_bold(py+1, px))
3039 cave_lite_hack(py+2, px);
3040 cave_lite_hack(py+2, px+1);
3041 cave_lite_hack(py+2, px-1);
3044 /* North of the player */
3045 if (cave_floor_bold(py-1, px))
3047 cave_lite_hack(py-2, px);
3048 cave_lite_hack(py-2, px+1);
3049 cave_lite_hack(py-2, px-1);
3052 /* East of the player */
3053 if (cave_floor_bold(py, px+1))
3055 cave_lite_hack(py, px+2);
3056 cave_lite_hack(py+1, px+2);
3057 cave_lite_hack(py-1, px+2);
3060 /* West of the player */
3061 if (cave_floor_bold(py, px-1))
3063 cave_lite_hack(py, px-2);
3064 cave_lite_hack(py+1, px-2);
3065 cave_lite_hack(py-1, px-2);
3069 /* Radius 3+ -- artifact radius */
3074 /* Paranoia -- see "LITE_MAX" */
3077 /* South-East of the player */
3078 if (cave_floor_bold(py+1, px+1))
3080 cave_lite_hack(py+2, px+2);
3083 /* South-West of the player */
3084 if (cave_floor_bold(py+1, px-1))
3086 cave_lite_hack(py+2, px-2);
3089 /* North-East of the player */
3090 if (cave_floor_bold(py-1, px+1))
3092 cave_lite_hack(py-2, px+2);
3095 /* North-West of the player */
3096 if (cave_floor_bold(py-1, px-1))
3098 cave_lite_hack(py-2, px-2);
3103 if (min_y < 0) min_y = 0;
3107 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3111 if (min_x < 0) min_x = 0;
3115 if (max_x > cur_wid-1) max_x = cur_wid-1;
3117 /* Scan the maximal box */
3118 for (y = min_y; y <= max_y; y++)
3120 for (x = min_x; x <= max_x; x++)
3122 int dy = (py > y) ? (py - y) : (y - py);
3123 int dx = (px > x) ? (px - x) : (x - px);
3125 /* Skip the "central" grids (above) */
3126 if ((dy <= 2) && (dx <= 2)) continue;
3128 /* Hack -- approximate the distance */
3129 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3131 /* Skip distant grids */
3132 if (d > p) continue;
3134 /* Viewable, nearby, grids get "torch lit" */
3135 if (player_has_los_bold(y, x))
3137 /* This grid is "torch lit" */
3138 cave_lite_hack(y, x);
3145 /*** Complete the algorithm ***/
3147 /* Draw the new grids */
3148 for (i = 0; i < lite_n; i++)
3153 c_ptr = &cave[y][x];
3155 /* Update fresh grids */
3156 if (c_ptr->info & (CAVE_TEMP)) continue;
3158 /* Add it to later visual update */
3159 cave_note_and_redraw_later(c_ptr, y, x);
3162 /* Clear them all */
3163 for (i = 0; i < temp_n; i++)
3168 c_ptr = &cave[y][x];
3170 /* No longer in the array */
3171 c_ptr->info &= ~(CAVE_TEMP);
3173 /* Update stale grids */
3174 if (c_ptr->info & (CAVE_LITE)) continue;
3176 /* Add it to later visual update */
3177 cave_redraw_later(c_ptr, y, x);
3183 /* Mega-Hack -- Visual update later */
3184 p_ptr->update |= (PU_DELAY_VIS);
3188 static bool mon_invis;
3189 static s16b mon_fy, mon_fx;
3192 * Add a square to the changes array
3194 static void mon_lite_hack(int y, int x)
3197 int midpoint, dpf, d;
3199 /* We trust this grid is in bounds */
3200 /* if (!in_bounds2(y, x)) return; */
3202 c_ptr = &cave[y][x];
3204 /* Want a unlit square in view of the player */
3205 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3207 if (!cave_floor_grid(c_ptr))
3209 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3210 if (mon_invis) return;
3212 /* Hack -- Prevent monster lite leakage in walls */
3214 /* Horizontal walls between player and a monster */
3215 if (((y < py) && (y > mon_fy)) || ((y > py) && (y < mon_fy)))
3219 midpoint = mon_fx + ((px - mon_fx) * ABS(d)) / ABS(dpf);
3221 /* Only first wall viewed from mid-x is lit */
3224 if (!cave_floor_bold(y, x + 1)) return;
3226 else if (x > midpoint)
3228 if (!cave_floor_bold(y, x - 1)) return;
3232 /* Vertical walls between player and a monster */
3233 if (((x < px) && (x > mon_fx)) || ((x > px) && (x < mon_fx)))
3237 midpoint = mon_fy + ((py - mon_fy) * ABS(d)) / ABS(dpf);
3239 /* Only first wall viewed from mid-y is lit */
3242 if (!cave_floor_bold(y + 1, x)) return;
3244 else if (y > midpoint)
3246 if (!cave_floor_bold(y - 1, x)) return;
3251 /* We trust temp_n does not exceed TEMP_MAX */
3254 if (!(c_ptr->info & CAVE_MNDK))
3256 /* Save this square */
3265 /* No longer dark */
3266 c_ptr->info &= ~(CAVE_MNDK);
3270 c_ptr->info |= CAVE_MNLT;
3275 * Add a square to the changes array
3277 static void mon_dark_hack(int y, int x)
3280 int midpoint, dpf, d;
3282 /* We trust this grid is in bounds */
3283 /* if (!in_bounds2(y, x)) return; */
3285 c_ptr = &cave[y][x];
3287 /* Want a unlit and undarkened square in view of the player */
3288 if ((c_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
3290 if (!cave_floor_grid(c_ptr))
3292 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3293 if (mon_invis) return;
3295 /* Hack -- Prevent monster dark lite leakage in walls */
3297 /* Horizontal walls between player and a monster */
3298 if (((y < py) && (y > mon_fy)) || ((y > py) && (y < mon_fy)))
3302 midpoint = mon_fx + ((px - mon_fx) * ABS(d)) / ABS(dpf);
3304 /* Only first wall viewed from mid-x is lit */
3307 if (!cave_floor_bold(y, x + 1)) return;
3309 else if (x > midpoint)
3311 if (!cave_floor_bold(y, x - 1)) return;
3315 /* Vertical walls between player and a monster */
3316 if (((x < px) && (x > mon_fx)) || ((x > px) && (x < mon_fx)))
3320 midpoint = mon_fy + ((py - mon_fy) * ABS(d)) / ABS(dpf);
3322 /* Only first wall viewed from mid-y is lit */
3325 if (!cave_floor_bold(y + 1, x)) return;
3327 else if (y > midpoint)
3329 if (!cave_floor_bold(y - 1, x)) return;
3334 /* We trust temp_n does not exceed TEMP_MAX */
3336 /* Save this square */
3342 c_ptr->info |= CAVE_MNDK;
3347 * Update squares illuminated or darkened by monsters.
3349 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3350 * denote squares illuminated by monsters.
3352 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
3353 * updating. Only squares in view of the player, whos state
3354 * changes are drawn via lite_spot().
3356 void update_mon_lite(void)
3362 void (*add_mon_lite)(int, int);
3366 /* Non-Ninja player in the darkness */
3367 int dis_lim = ((d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
3368 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
3370 /* Clear all monster lit squares */
3371 for (i = 0; i < mon_lite_n; i++)
3374 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3376 /* Set temp or xtra flag */
3377 c_ptr->info |= (c_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
3379 /* Clear monster illumination flag */
3380 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3383 /* Empty temp list of new squares to lite up */
3386 /* Loop through monsters, adding newly lit squares to changes list */
3387 for (i = 1; i < m_max; i++)
3389 monster_type *m_ptr = &m_list[i];
3390 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3392 /* Skip dead monsters */
3393 if (!m_ptr->r_idx) continue;
3395 /* Is it too far away? */
3396 if (m_ptr->cdis > dis_lim) continue;
3398 /* If a monster stops time, break */
3399 if (world_monster) break;
3401 /* Get lite radius */
3404 /* Note the radii are cumulative */
3405 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3406 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3407 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3408 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3410 /* Exit if has no light */
3414 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3415 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3416 add_mon_lite = mon_lite_hack;
3420 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (m_ptr->csleep || (!dun_level && !is_daytime()))) continue;
3421 add_mon_lite = mon_dark_hack;
3422 rad = -rad; /* Use absolute value */
3425 /* Access the location */
3429 /* Is the monster visible? */
3430 mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
3432 /* The square it is on */
3433 add_mon_lite(mon_fy, mon_fx);
3435 /* Adjacent squares */
3436 add_mon_lite(mon_fy + 1, mon_fx);
3437 add_mon_lite(mon_fy - 1, mon_fx);
3438 add_mon_lite(mon_fy, mon_fx + 1);
3439 add_mon_lite(mon_fy, mon_fx - 1);
3440 add_mon_lite(mon_fy + 1, mon_fx + 1);
3441 add_mon_lite(mon_fy + 1, mon_fx - 1);
3442 add_mon_lite(mon_fy - 1, mon_fx + 1);
3443 add_mon_lite(mon_fy - 1, mon_fx - 1);
3448 /* South of the monster */
3449 if (cave_floor_bold(mon_fy + 1, mon_fx))
3451 add_mon_lite(mon_fy + 2, mon_fx + 1);
3452 add_mon_lite(mon_fy + 2, mon_fx);
3453 add_mon_lite(mon_fy + 2, mon_fx - 1);
3455 c_ptr = &cave[mon_fy + 2][mon_fx];
3458 if ((rad == 3) && cave_floor_grid(c_ptr))
3460 add_mon_lite(mon_fy + 3, mon_fx + 1);
3461 add_mon_lite(mon_fy + 3, mon_fx);
3462 add_mon_lite(mon_fy + 3, mon_fx - 1);
3466 /* North of the monster */
3467 if (cave_floor_bold(mon_fy - 1, mon_fx))
3469 add_mon_lite(mon_fy - 2, mon_fx + 1);
3470 add_mon_lite(mon_fy - 2, mon_fx);
3471 add_mon_lite(mon_fy - 2, mon_fx - 1);
3473 c_ptr = &cave[mon_fy - 2][mon_fx];
3476 if ((rad == 3) && cave_floor_grid(c_ptr))
3478 add_mon_lite(mon_fy - 3, mon_fx + 1);
3479 add_mon_lite(mon_fy - 3, mon_fx);
3480 add_mon_lite(mon_fy - 3, mon_fx - 1);
3484 /* East of the monster */
3485 if (cave_floor_bold(mon_fy, mon_fx + 1))
3487 add_mon_lite(mon_fy + 1, mon_fx + 2);
3488 add_mon_lite(mon_fy, mon_fx + 2);
3489 add_mon_lite(mon_fy - 1, mon_fx + 2);
3491 c_ptr = &cave[mon_fy][mon_fx + 2];
3494 if ((rad == 3) && cave_floor_grid(c_ptr))
3496 add_mon_lite(mon_fy + 1, mon_fx + 3);
3497 add_mon_lite(mon_fy, mon_fx + 3);
3498 add_mon_lite(mon_fy - 1, mon_fx + 3);
3502 /* West of the monster */
3503 if (cave_floor_bold(mon_fy, mon_fx - 1))
3505 add_mon_lite(mon_fy + 1, mon_fx - 2);
3506 add_mon_lite(mon_fy, mon_fx - 2);
3507 add_mon_lite(mon_fy - 1, mon_fx - 2);
3509 c_ptr = &cave[mon_fy][mon_fx - 2];
3512 if ((rad == 3) && cave_floor_grid(c_ptr))
3514 add_mon_lite(mon_fy + 1, mon_fx - 3);
3515 add_mon_lite(mon_fy, mon_fx - 3);
3516 add_mon_lite(mon_fy - 1, mon_fx - 3);
3524 /* South-East of the monster */
3525 if (cave_floor_bold(mon_fy + 1, mon_fx + 1))
3527 add_mon_lite(mon_fy + 2, mon_fx + 2);
3530 /* South-West of the monster */
3531 if (cave_floor_bold(mon_fy + 1, mon_fx - 1))
3533 add_mon_lite(mon_fy + 2, mon_fx - 2);
3536 /* North-East of the monster */
3537 if (cave_floor_bold(mon_fy - 1, mon_fx + 1))
3539 add_mon_lite(mon_fy - 2, mon_fx + 2);
3542 /* North-West of the monster */
3543 if (cave_floor_bold(mon_fy - 1, mon_fx - 1))
3545 add_mon_lite(mon_fy - 2, mon_fx - 2);
3550 /* Save end of list of new squares */
3554 * Look at old set flags to see if there are any changes.
3556 for (i = 0; i < mon_lite_n; i++)
3561 /* We trust this grid is in bounds */
3564 c_ptr = &cave[fy][fx];
3566 if (c_ptr->info & CAVE_TEMP) /* Pervious lit */
3568 /* It it no longer lit? */
3569 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3571 /* It is now unlit */
3572 /* Add it to later visual update */
3573 cave_note_and_redraw_later(c_ptr, fy, fx);
3576 else /* Pervious darkened */
3578 /* It it no longer darken? */
3579 if ((c_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3581 /* It is now undarken */
3582 /* Add it to later visual update */
3583 cave_note_and_redraw_later(c_ptr, fy, fx);
3587 /* Add to end of temp array */
3588 temp_x[temp_n] = (byte)fx;
3589 temp_y[temp_n] = (byte)fy;
3593 /* Clear the lite array */
3596 /* Copy the temp array into the lit array lighting the new squares. */
3597 for (i = 0; i < end_temp; i++)
3602 /* We trust this grid is in bounds */
3605 c_ptr = &cave[fy][fx];
3607 if (c_ptr->info & CAVE_MNLT) /* Lit */
3609 /* The is the square newly lit and visible? */
3610 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3613 /* Add it to later visual update */
3614 cave_note_and_redraw_later(c_ptr, fy, fx);
3619 /* The is the square newly darkened and visible? */
3620 if ((c_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3622 /* It is now darkened */
3623 /* Add it to later visual update */
3624 cave_note_and_redraw_later(c_ptr, fy, fx);
3628 /* Save in the monster lit or darkened array */
3629 mon_lite_x[mon_lite_n] = fx;
3630 mon_lite_y[mon_lite_n] = fy;
3634 /* Clear the temp flag for the old lit or darken grids */
3635 for (i = end_temp; i < temp_n; i++)
3637 /* We trust this grid is in bounds */
3639 cave[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3642 /* Finished with temp_n */
3645 /* Mega-Hack -- Visual update later */
3646 p_ptr->update |= (PU_DELAY_VIS);
3648 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3650 if (p_ptr->special_defense & NINJA_S_STEALTH)
3652 if (p_ptr->old_monlite != p_ptr->monlite)
3657 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3659 msg_print("Your mantle of shadow become thin.");
3665 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3667 msg_print("Your mantle of shadow restored its original darkness.");
3672 p_ptr->old_monlite = p_ptr->monlite;
3675 void clear_mon_lite(void)
3680 /* Clear all monster lit squares */
3681 for (i = 0; i < mon_lite_n; i++)
3684 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3686 /* Clear monster illumination flag */
3687 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3690 /* Empty the array */
3697 * Clear the viewable space
3699 void forget_view(void)
3705 /* None to forget */
3706 if (!view_n) return;
3708 /* Clear them all */
3709 for (i = 0; i < view_n; i++)
3714 /* Access the grid */
3715 c_ptr = &cave[y][x];
3717 /* Forget that the grid is viewable */
3718 c_ptr->info &= ~(CAVE_VIEW);
3720 if (!panel_contains(y, x)) continue;
3722 /* Update the screen */
3723 /* lite_spot(y, x); Perhaps don't need? */
3733 * This macro allows us to efficiently add a grid to the "view" array,
3734 * note that we are never called for illegal grids, or for grids which
3735 * have already been placed into the "view" array, and we are never
3736 * called when the "view" array is full.
3738 #define cave_view_hack(C,Y,X) \
3740 if (!((C)->info & (CAVE_VIEW))){\
3741 (C)->info |= (CAVE_VIEW); \
3742 view_y[view_n] = (Y); \
3743 view_x[view_n] = (X); \
3750 * Helper function for "update_view()" below
3752 * We are checking the "viewability" of grid (y,x) by the player.
3754 * This function assumes that (y,x) is legal (i.e. on the map).
3756 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3757 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3759 * Note that we are using the "CAVE_XTRA" field for marking grids as
3760 * "easily viewable". This bit is cleared at the end of "update_view()".
3762 * This function adds (y,x) to the "viewable set" if necessary.
3764 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3766 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3768 bool f1, f2, v1, v2, z1, z2, wall;
3772 cave_type *g1_c_ptr;
3773 cave_type *g2_c_ptr;
3775 /* Access the grids */
3776 g1_c_ptr = &cave[y1][x1];
3777 g2_c_ptr = &cave[y2][x2];
3780 /* Check for walls */
3781 f1 = (cave_floor_grid(g1_c_ptr));
3782 f2 = (cave_floor_grid(g2_c_ptr));
3784 /* Totally blocked by physical walls */
3785 if (!f1 && !f2) return (TRUE);
3788 /* Check for visibility */
3789 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3790 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3792 /* Totally blocked by "unviewable neighbors" */
3793 if (!v1 && !v2) return (TRUE);
3796 /* Access the grid */
3797 c_ptr = &cave[y][x];
3800 /* Check for walls */
3801 wall = (!cave_floor_grid(c_ptr));
3804 /* Check the "ease" of visibility */
3805 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3806 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3808 /* Hack -- "easy" plus "easy" yields "easy" */
3811 c_ptr->info |= (CAVE_XTRA);
3813 cave_view_hack(c_ptr, y, x);
3818 /* Hack -- primary "easy" yields "viewed" */
3821 cave_view_hack(c_ptr, y, x);
3826 /* Hack -- "view" plus "view" yields "view" */
3829 /* c_ptr->info |= (CAVE_XTRA); */
3831 cave_view_hack(c_ptr, y, x);
3837 /* Mega-Hack -- the "los()" function works poorly on walls */
3840 cave_view_hack(c_ptr, y, x);
3846 /* Hack -- check line of sight */
3847 if (los(py, px, y, x))
3849 cave_view_hack(c_ptr, y, x);
3855 /* Assume no line of sight. */
3862 * Calculate the viewable space
3864 * 1: Process the player
3865 * 1a: The player is always (easily) viewable
3866 * 2: Process the diagonals
3867 * 2a: The diagonals are (easily) viewable up to the first wall
3868 * 2b: But never go more than 2/3 of the "full" distance
3869 * 3: Process the main axes
3870 * 3a: The main axes are (easily) viewable up to the first wall
3871 * 3b: But never go more than the "full" distance
3872 * 4: Process sequential "strips" in each of the eight octants
3873 * 4a: Each strip runs along the previous strip
3874 * 4b: The main axes are "previous" to the first strip
3875 * 4c: Process both "sides" of each "direction" of each strip
3876 * 4c1: Each side aborts as soon as possible
3877 * 4c2: Each side tells the next strip how far it has to check
3879 * Note that the octant processing involves some pretty interesting
3880 * observations involving when a grid might possibly be viewable from
3881 * a given grid, and on the order in which the strips are processed.
3883 * Note the use of the mathematical facts shown below, which derive
3884 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3885 * hypotenuse of a right triangle is primarily determined by the length
3886 * of the longest side, when one side is small, and is strictly less
3887 * than one-and-a-half times as long as the longest side when both of
3888 * the sides are large.
3890 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3891 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3893 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3895 * These observations are important because the calculation of the actual
3896 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3897 * while for small values (up to about 20 or so), the approximations above
3898 * are correct to within an error of at most one grid or so.
3900 * Observe the use of "full" and "over" in the code below, and the use of
3901 * the specialized calculation involving "limit", all of which derive from
3902 * the observations given above. Basically, we note that the "circle" of
3903 * view is completely contained in an "octagon" whose bounds are easy to
3904 * determine, and that only a few steps are needed to derive the actual
3905 * bounds of the circle given the bounds of the octagon.
3907 * Note that by skipping all the grids in the corners of the octagon, we
3908 * place an upper limit on the number of grids in the field of view, given
3909 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3910 * view, only about 1475 of these are in the "octagon" of view, and even
3911 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3912 * entries to completely contain the actual field of view.
3914 * Note also the care taken to prevent "running off the map". The use of
3915 * explicit checks on the "validity" of the "diagonal", and the fact that
3916 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3917 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3918 * of multiple checks on the validity of grids.
3920 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3921 * "ws","wn" variables. They work like this: While travelling down the
3922 * south-bound strip just to the east of the main south axis, as soon as
3923 * we get to a grid which does not "transmit" viewing, if all of the strips
3924 * preceding us (in this case, just the main axis) had terminated at or before
3925 * the same point, then we can stop, and reset the "max distance" to ourself.
3926 * So, each strip (named by major axis plus offset, thus "se" in this case)
3927 * maintains a "blockage" variable, initialized during the main axis step,
3928 * and checks it whenever a blockage is observed. After processing each
3929 * strip as far as the previous strip told us to process, the next strip is
3930 * told not to go farther than the current strip's farthest viewable grid,
3931 * unless open space is still available. This uses the "k" variable.
3933 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3934 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3935 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3936 * chunk of code which adds the given location to the "view" array if it
3937 * is not already there, using both the actual location and a pointer to
3938 * the cave grid. See above.
3940 * By the way, the purpose of this code is to reduce the dependancy on the
3941 * "los()" function which is slow, and, in some cases, not very accurate.
3943 * It is very possible that I am the only person who fully understands this
3944 * function, and for that I am truly sorry, but efficiency was very important
3945 * and the "simple" version of this function was just not fast enough. I am
3946 * more than willing to replace this function with a simpler one, if it is
3947 * equally efficient, and especially willing if the new function happens to
3948 * derive "reverse-line-of-sight" at the same time, since currently monsters
3949 * just use an optimized hack of "you see me, so I see you", and then use the
3950 * actual "projectable()" function to check spell attacks.
3952 void update_view(void)
3954 int n, m, d, k, y, x, z;
3956 int se, sw, ne, nw, es, en, ws, wn;
3960 int y_max = cur_hgt - 1;
3961 int x_max = cur_wid - 1;
3965 /*** Initialize ***/
3968 if (view_reduce_view && !dun_level)
3970 /* Full radius (10) */
3971 full = MAX_SIGHT / 2;
3973 /* Octagon factor (15) */
3974 over = MAX_SIGHT * 3 / 4;
3980 /* Full radius (20) */
3983 /* Octagon factor (30) */
3984 over = MAX_SIGHT * 3 / 2;
3988 /*** Step 0 -- Begin ***/
3990 /* Save the old "view" grids for later */
3991 for (n = 0; n < view_n; n++)
3996 /* Access the grid */
3997 c_ptr = &cave[y][x];
3999 /* Mark the grid as not in "view" */
4000 c_ptr->info &= ~(CAVE_VIEW);
4002 /* Mark the grid as "seen" */
4003 c_ptr->info |= (CAVE_TEMP);
4005 /* Add it to the "seen" set */
4011 /* Start over with the "view" array */
4014 /*** Step 1 -- adjacent grids ***/
4016 /* Now start on the player */
4020 /* Access the grid */
4021 c_ptr = &cave[y][x];
4023 /* Assume the player grid is easily viewable */
4024 c_ptr->info |= (CAVE_XTRA);
4026 /* Assume the player grid is viewable */
4027 cave_view_hack(c_ptr, y, x);
4030 /*** Step 2 -- Major Diagonals ***/
4035 /* Scan south-east */
4036 for (d = 1; d <= z; d++)
4038 c_ptr = &cave[y+d][x+d];
4039 c_ptr->info |= (CAVE_XTRA);
4040 cave_view_hack(c_ptr, y+d, x+d);
4041 if (!cave_floor_grid(c_ptr)) break;
4044 /* Scan south-west */
4045 for (d = 1; d <= z; d++)
4047 c_ptr = &cave[y+d][x-d];
4048 c_ptr->info |= (CAVE_XTRA);
4049 cave_view_hack(c_ptr, y+d, x-d);
4050 if (!cave_floor_grid(c_ptr)) break;
4053 /* Scan north-east */
4054 for (d = 1; d <= z; d++)
4056 c_ptr = &cave[y-d][x+d];
4057 c_ptr->info |= (CAVE_XTRA);
4058 cave_view_hack(c_ptr, y-d, x+d);
4059 if (!cave_floor_grid(c_ptr)) break;
4062 /* Scan north-west */
4063 for (d = 1; d <= z; d++)
4065 c_ptr = &cave[y-d][x-d];
4066 c_ptr->info |= (CAVE_XTRA);
4067 cave_view_hack(c_ptr, y-d, x-d);
4068 if (!cave_floor_grid(c_ptr)) break;
4072 /*** Step 3 -- major axes ***/
4075 for (d = 1; d <= full; d++)
4077 c_ptr = &cave[y+d][x];
4078 c_ptr->info |= (CAVE_XTRA);
4079 cave_view_hack(c_ptr, y+d, x);
4080 if (!cave_floor_grid(c_ptr)) break;
4083 /* Initialize the "south strips" */
4087 for (d = 1; d <= full; d++)
4089 c_ptr = &cave[y-d][x];
4090 c_ptr->info |= (CAVE_XTRA);
4091 cave_view_hack(c_ptr, y-d, x);
4092 if (!cave_floor_grid(c_ptr)) break;
4095 /* Initialize the "north strips" */
4099 for (d = 1; d <= full; d++)
4101 c_ptr = &cave[y][x+d];
4102 c_ptr->info |= (CAVE_XTRA);
4103 cave_view_hack(c_ptr, y, x+d);
4104 if (!cave_floor_grid(c_ptr)) break;
4107 /* Initialize the "east strips" */
4111 for (d = 1; d <= full; d++)
4113 c_ptr = &cave[y][x-d];
4114 c_ptr->info |= (CAVE_XTRA);
4115 cave_view_hack(c_ptr, y, x-d);
4116 if (!cave_floor_grid(c_ptr)) break;
4119 /* Initialize the "west strips" */
4123 /*** Step 4 -- Divide each "octant" into "strips" ***/
4125 /* Now check each "diagonal" (in parallel) */
4126 for (n = 1; n <= over / 2; n++)
4128 int ypn, ymn, xpn, xmn;
4131 /* Acquire the "bounds" of the maximal circle */
4133 if (z > full - n) z = full - n;
4134 while ((z + n + (n>>1)) > full) z--;
4137 /* Access the four diagonal grids */
4147 /* Maximum distance */
4148 m = MIN(z, y_max - ypn);
4151 if ((xpn <= x_max) && (n < se))
4154 for (k = n, d = 1; d <= m; d++)
4156 /* Check grid "d" in strip "n", notice "blockage" */
4157 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
4159 if (n + d >= se) break;
4162 /* Track most distant "non-blockage" */
4169 /* Limit the next strip */
4174 if ((xmn >= 0) && (n < sw))
4177 for (k = n, d = 1; d <= m; d++)
4179 /* Check grid "d" in strip "n", notice "blockage" */
4180 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
4182 if (n + d >= sw) break;
4185 /* Track most distant "non-blockage" */
4192 /* Limit the next strip */
4201 /* Maximum distance */
4205 if ((xpn <= x_max) && (n < ne))
4208 for (k = n, d = 1; d <= m; d++)
4210 /* Check grid "d" in strip "n", notice "blockage" */
4211 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
4213 if (n + d >= ne) break;
4216 /* Track most distant "non-blockage" */
4223 /* Limit the next strip */
4228 if ((xmn >= 0) && (n < nw))
4231 for (k = n, d = 1; d <= m; d++)
4233 /* Check grid "d" in strip "n", notice "blockage" */
4234 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
4236 if (n + d >= nw) break;
4239 /* Track most distant "non-blockage" */
4246 /* Limit the next strip */
4255 /* Maximum distance */
4256 m = MIN(z, x_max - xpn);
4259 if ((ypn <= x_max) && (n < es))
4262 for (k = n, d = 1; d <= m; d++)
4264 /* Check grid "d" in strip "n", notice "blockage" */
4265 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
4267 if (n + d >= es) break;
4270 /* Track most distant "non-blockage" */
4277 /* Limit the next strip */
4282 if ((ymn >= 0) && (n < en))
4285 for (k = n, d = 1; d <= m; d++)
4287 /* Check grid "d" in strip "n", notice "blockage" */
4288 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4290 if (n + d >= en) break;
4293 /* Track most distant "non-blockage" */
4300 /* Limit the next strip */
4309 /* Maximum distance */
4313 if ((ypn <= y_max) && (n < ws))
4316 for (k = n, d = 1; d <= m; d++)
4318 /* Check grid "d" in strip "n", notice "blockage" */
4319 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4321 if (n + d >= ws) break;
4324 /* Track most distant "non-blockage" */
4331 /* Limit the next strip */
4336 if ((ymn >= 0) && (n < wn))
4339 for (k = n, d = 1; d <= m; d++)
4341 /* Check grid "d" in strip "n", notice "blockage" */
4342 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4344 if (n + d >= wn) break;
4347 /* Track most distant "non-blockage" */
4354 /* Limit the next strip */
4361 /*** Step 5 -- Complete the algorithm ***/
4363 /* Update all the new grids */
4364 for (n = 0; n < view_n; n++)
4369 /* Access the grid */
4370 c_ptr = &cave[y][x];
4372 /* Clear the "CAVE_XTRA" flag */
4373 c_ptr->info &= ~(CAVE_XTRA);
4375 /* Update only newly viewed grids */
4376 if (c_ptr->info & (CAVE_TEMP)) continue;
4378 /* Add it to later visual update */
4379 cave_note_and_redraw_later(c_ptr, y, x);
4382 /* Wipe the old grids, update as needed */
4383 for (n = 0; n < temp_n; n++)
4388 /* Access the grid */
4389 c_ptr = &cave[y][x];
4391 /* No longer in the array */
4392 c_ptr->info &= ~(CAVE_TEMP);
4394 /* Update only non-viewable grids */
4395 if (c_ptr->info & (CAVE_VIEW)) continue;
4397 /* Add it to later visual update */
4398 cave_redraw_later(c_ptr, y, x);
4404 /* Mega-Hack -- Visual update later */
4405 p_ptr->update |= (PU_DELAY_VIS);
4410 * Mega-Hack -- Delayed visual update
4411 * Only used if update_view(), update_lite() or update_mon_lite() was called
4413 void delayed_visual_update(void)
4418 /* Update needed grids */
4419 for (i = 0; i < redraw_n; i++)
4424 /* Access the grid */
4425 c_ptr = &cave[y][x];
4427 /* Update only needed grids (prevent multiple updating) */
4428 if (!(c_ptr->info & CAVE_REDRAW)) continue;
4430 /* If required, note */
4431 if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
4436 /* Hack -- Visual update of monster on this grid */
4437 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4439 /* No longer in the array */
4440 c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4449 * Hack -- forget the "flow" information
4451 void forget_flow(void)
4455 /* Check the entire dungeon */
4456 for (y = 0; y < cur_hgt; y++)
4458 for (x = 0; x < cur_wid; x++)
4460 /* Forget the old data */
4461 cave[y][x].dist = 0;
4462 cave[y][x].cost = 0;
4463 cave[y][x].when = 0;
4470 * Hack - speed up the update_flow algorithm by only doing
4471 * it everytime the player moves out of LOS of the last
4474 static u16b flow_x = 0;
4475 static u16b flow_y = 0;
4480 * Hack -- fill in the "cost" field of every grid that the player
4481 * can "reach" with the number of steps needed to reach that grid.
4482 * This also yields the "distance" of the player from every grid.
4484 * In addition, mark the "when" of the grids that can reach
4485 * the player with the incremented value of "flow_n".
4487 * Hack -- use the "seen" array as a "circular queue".
4489 * We do not need a priority queue because the cost from grid
4490 * to grid is always "one" and we process them in order.
4492 void update_flow(void)
4498 /* Paranoia -- make sure the array is empty */
4501 /* The last way-point is on the map */
4502 if (running && in_bounds(flow_y, flow_x))
4504 /* The way point is in sight - do not update. (Speedup) */
4505 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4508 /* Erase all of the current flow information */
4509 for (y = 0; y < cur_hgt; y++)
4511 for (x = 0; x < cur_wid; x++)
4513 cave[y][x].cost = 0;
4514 cave[y][x].dist = 0;
4518 /* Save player position */
4522 /* Add the player's grid to the queue */
4526 /* Now process the queue */
4527 while (flow_head != flow_tail)
4531 /* Extract the next entry */
4532 ty = temp_y[flow_tail];
4533 tx = temp_x[flow_tail];
4535 /* Forget that entry */
4536 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4538 /* Add the "children" */
4539 for (d = 0; d < 8; d++)
4541 int old_head = flow_head;
4542 int m = cave[ty][tx].cost + 1;
4543 int n = cave[ty][tx].dist + 1;
4546 /* Child location */
4547 y = ty + ddy_ddd[d];
4548 x = tx + ddx_ddd[d];
4550 /* Ignore player's grid */
4551 if (player_bold(y, x)) continue;
4553 c_ptr = &cave[y][x];
4555 if (is_closed_door(c_ptr->feat)) m += 3;
4557 /* Ignore "pre-stamped" entries */
4558 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4560 /* Ignore "walls" and "rubble" */
4561 if ((c_ptr->feat >= FEAT_RUBBLE) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4563 /* Save the flow cost */
4564 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4565 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4567 /* Hack -- limit flow depth */
4568 if (n == MONSTER_FLOW_DEPTH) continue;
4570 /* Enqueue that entry */
4571 temp_y[flow_head] = y;
4572 temp_x[flow_head] = x;
4574 /* Advance the queue */
4575 if (++flow_head == TEMP_MAX) flow_head = 0;
4577 /* Hack -- notice overflow by forgetting new entry */
4578 if (flow_head == flow_tail) flow_head = old_head;
4584 static int scent_when = 0;
4587 * Characters leave scent trails for perceptive monsters to track.
4589 * Smell is rather more limited than sound. Many creatures cannot use
4590 * it at all, it doesn't extend very far outwards from the character's
4591 * current position, and monsters can use it to home in the character,
4592 * but not to run away from him.
4594 * Smell is valued according to age. When a character takes his turn,
4595 * scent is aged by one, and new scent of the current age is laid down.
4596 * Speedy characters leave more scent, true, but it also ages faster,
4597 * which makes it harder to hunt them down.
4599 * Whenever the age count loops, most of the scent trail is erased and
4600 * the age of the remainder is recalculated.
4602 void update_smell(void)
4607 /* Create a table that controls the spread of scent */
4608 const int scent_adjust[5][5] =
4617 /* Loop the age and adjust scent values when necessary */
4618 if (++scent_when == 254)
4620 /* Scan the entire dungeon */
4621 for (y = 0; y < cur_hgt; y++)
4623 for (x = 0; x < cur_wid; x++)
4625 int w = cave[y][x].when;
4626 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4635 /* Lay down new scent */
4636 for (i = 0; i < 5; i++)
4638 for (j = 0; j < 5; j++)
4642 /* Translate table to map grids */
4647 if (!in_bounds(y, x)) continue;
4649 c_ptr = &cave[y][x];
4651 /* Walls, water, and lava cannot hold scent. */
4652 if ((c_ptr->feat >= FEAT_RUBBLE) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4654 /* Grid must not be blocked by walls from the character */
4655 if (!player_has_los_bold(y, x)) continue;
4657 /* Note grids that are too far away */
4658 if (scent_adjust[i][j] == -1) continue;
4660 /* Mark the grid with new scent */
4661 c_ptr->when = scent_when + scent_adjust[i][j];
4668 * Hack -- map the current panel (plus some) ala "magic mapping"
4670 void map_area(int range)
4678 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4680 /* Scan that area */
4681 for (y = 1; y < cur_hgt - 1; y++)
4683 for (x = 1; x < cur_wid - 1; x++)
4685 if (distance(py, px, y, x) > range) continue;
4687 c_ptr = &cave[y][x];
4689 /* Feature code (applying "mimic" field) */
4690 feat = f_info[c_ptr->mimic ? c_ptr->mimic : c_ptr->feat].mimic;
4692 /* All non-walls are "checked" */
4693 if ((feat <= FEAT_DOOR_TAIL) ||
4694 (feat == FEAT_RUBBLE) ||
4695 ((feat >= FEAT_MINOR_GLYPH) &&
4696 (feat <= FEAT_TREES)) ||
4697 (feat >= FEAT_TOWN))
4699 /* Memorize normal features */
4700 if ((feat > FEAT_INVIS) && (feat != FEAT_DIRT) && (feat != FEAT_GRASS))
4702 /* Memorize the object */
4703 c_ptr->info |= (CAVE_MARK);
4706 /* Memorize known walls */
4707 for (i = 0; i < 8; i++)
4709 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4711 /* Feature code (applying "mimic" field) */
4712 feat = f_info[c_ptr->mimic ? c_ptr->mimic : c_ptr->feat].mimic;
4714 /* Memorize walls (etc) */
4715 if ((feat >= FEAT_RUBBLE) && (feat != FEAT_DIRT) && (feat != FEAT_GRASS))
4717 /* Memorize the walls */
4718 c_ptr->info |= (CAVE_MARK);
4726 p_ptr->redraw |= (PR_MAP);
4729 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4735 * Light up the dungeon using "clairvoyance"
4737 * This function "illuminates" every grid in the dungeon, memorizes all
4738 * "objects", memorizes all grids as with magic mapping, and, under the
4739 * standard option settings (view_perma_grids but not view_torch_grids)
4740 * memorizes all floor grids too.
4742 * Note that if "view_perma_grids" is not set, we do not memorize floor
4743 * grids, since this would defeat the purpose of "view_perma_grids", not
4744 * that anyone seems to play without this option.
4746 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4747 * since this would prevent the use of "view_torch_grids" as a method to
4748 * keep track of what grids have been observed directly.
4750 void wiz_lite(bool ninja)
4755 /* Memorize objects */
4756 for (i = 1; i < o_max; i++)
4758 object_type *o_ptr = &o_list[i];
4760 /* Skip dead objects */
4761 if (!o_ptr->k_idx) continue;
4763 /* Skip held objects */
4764 if (o_ptr->held_m_idx) continue;
4767 o_ptr->marked |= OM_FOUND;
4770 /* Scan all normal grids */
4771 for (y = 1; y < cur_hgt - 1; y++)
4773 /* Scan all normal grids */
4774 for (x = 1; x < cur_wid - 1; x++)
4776 cave_type *c_ptr = &cave[y][x];
4778 /* Feature code (applying "mimic" field) */
4779 feat = f_info[c_ptr->mimic ? c_ptr->mimic : c_ptr->feat].mimic;
4781 /* Process all non-walls */
4782 if (cave_floor_bold(y, x) || (feat == FEAT_RUBBLE) || (feat == FEAT_TREES) || (feat == FEAT_MOUNTAIN))
4784 /* Scan all neighbors */
4785 for (i = 0; i < 9; i++)
4787 int yy = y + ddy_ddd[i];
4788 int xx = x + ddx_ddd[i];
4791 c_ptr = &cave[yy][xx];
4793 /* Feature code (applying "mimic" field) */
4794 feat = f_info[c_ptr->mimic ? c_ptr->mimic : c_ptr->feat].mimic;
4796 /* Memorize normal features */
4799 /* Memorize the grid */
4800 c_ptr->info |= (CAVE_MARK);
4804 if ((feat > FEAT_INVIS))
4806 /* Memorize the grid */
4807 c_ptr->info |= (CAVE_MARK);
4810 /* Perma-lite the grid */
4811 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4813 c_ptr->info |= (CAVE_GLOW);
4815 /* Normally, memorize floors (see above) */
4816 if (view_perma_grids && !view_torch_grids)
4818 /* Memorize the grid */
4819 c_ptr->info |= (CAVE_MARK);
4828 /* Update the monsters */
4829 p_ptr->update |= (PU_MONSTERS);
4832 p_ptr->redraw |= (PR_MAP);
4835 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4840 * Forget the dungeon map (ala "Thinking of Maud...").
4847 /* Forget every grid */
4848 for (y = 1; y < cur_hgt - 1; y++)
4850 for (x = 1; x < cur_wid - 1; x++)
4852 cave_type *c_ptr = &cave[y][x];
4854 /* Process the grid */
4855 c_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT);
4856 c_ptr->info |= (CAVE_UNSAFE);
4860 /* Forget every grid on horizontal edge */
4861 for (x = 0; x < cur_wid; x++)
4863 cave[0][x].info &= ~(CAVE_MARK);
4864 cave[cur_hgt - 1][x].info &= ~(CAVE_MARK);
4867 /* Forget every grid on vertical edge */
4868 for (y = 1; y < (cur_hgt - 1); y++)
4870 cave[y][0].info &= ~(CAVE_MARK);
4871 cave[y][cur_wid - 1].info &= ~(CAVE_MARK);
4874 /* Forget all objects */
4875 for (i = 1; i < o_max; i++)
4877 object_type *o_ptr = &o_list[i];
4879 /* Skip dead objects */
4880 if (!o_ptr->k_idx) continue;
4882 /* Skip held objects */
4883 if (o_ptr->held_m_idx) continue;
4885 /* Forget the object */
4889 /* Mega-Hack -- Forget the view and lite */
4890 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4892 /* Update the view and lite */
4893 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4895 /* Update the monsters */
4896 p_ptr->update |= (PU_MONSTERS);
4899 p_ptr->redraw |= (PR_MAP);
4902 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4910 * Change the "feat" flag for a grid, and notice/redraw the grid
4912 void cave_set_feat(int y, int x, int feat)
4914 cave_type *c_ptr = &cave[y][x];
4916 /* Clear mimic type */
4919 /* Remove flag for mirror/glyph */
4920 c_ptr->info &= ~(CAVE_OBJECT);
4922 /* Change the feature */
4925 /* Hack -- glow the deep lava */
4926 if ((feat == FEAT_DEEP_LAVA) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4930 for (i = 0; i < 9; i++)
4932 yy = y + ddy_ddd[i];
4933 xx = x + ddx_ddd[i];
4934 if (!in_bounds2(yy, xx)) continue;
4935 cave[yy][xx].info |= CAVE_GLOW;
4936 if (player_has_los_bold(yy, xx))
4954 /* Remove a mirror */
4955 void remove_mirror(int y, int x)
4957 /* Remove the mirror */
4958 cave[y][x].info &= ~(CAVE_OBJECT);
4959 cave[y][x].mimic = 0;
4961 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4963 cave[y][x].info &= ~(CAVE_GLOW);
4964 if( !view_torch_grids )cave[y][x].info &= ~(CAVE_MARK);
4975 * Return TRUE if there is a mirror on the grid.
4977 bool is_mirror_grid(cave_type *c_ptr)
4979 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_MIRROR)
4987 * Return TRUE if there is a mirror on the grid.
4989 bool is_glyph_grid(cave_type *c_ptr)
4991 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_GLYPH)
4999 * Return TRUE if there is a mirror on the grid.
5001 bool is_explosive_rune_grid(cave_type *c_ptr)
5003 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_MINOR_GLYPH)
5011 * Calculate "incremental motion". Used by project() and shoot().
5012 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
5014 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
5016 int dy, dx, dist, shift;
5018 /* Extract the distance travelled */
5019 dy = (*y < y1) ? y1 - *y : *y - y1;
5020 dx = (*x < x1) ? x1 - *x : *x - x1;
5022 /* Number of steps */
5023 dist = (dy > dx) ? dy : dx;
5025 /* We are calculating the next location */
5029 /* Calculate the total distance along each axis */
5030 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
5031 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
5033 /* Paranoia -- Hack -- no motion */
5034 if (!dy && !dx) return;
5037 /* Move mostly vertically */
5040 /* Extract a shift factor */
5041 shift = (dist * dx + (dy - 1) / 2) / dy;
5043 /* Sometimes move along the minor axis */
5044 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
5046 /* Always move along major axis */
5047 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
5050 /* Move mostly horizontally */
5053 /* Extract a shift factor */
5054 shift = (dist * dy + (dx - 1) / 2) / dx;
5056 /* Sometimes move along the minor axis */
5057 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
5059 /* Always move along major axis */
5060 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
5067 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
5068 * at the final destination, assuming no monster gets in the way.
5070 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
5072 bool projectable(int y1, int x1, int y2, int x2)
5079 /* Check the projection path */
5080 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
5082 /* No grid is ever projectable from itself */
5083 if (!grid_n) return (FALSE);
5086 y = GRID_Y(grid_g[grid_n - 1]);
5087 x = GRID_X(grid_g[grid_n - 1]);
5089 /* May not end in an unrequested grid */
5090 if ((y != y2) || (x != x2)) return (FALSE);
5098 * Standard "find me a location" function
5100 * Obtains a legal location within the given distance of the initial
5101 * location, and with "los()" from the source to destination location.
5103 * This function is often called from inside a loop which searches for
5104 * locations while increasing the "d" distance.
5106 * Currently the "m" parameter is unused.
5108 void scatter(int *yp, int *xp, int y, int x, int d, int m)
5115 /* Pick a location */
5118 /* Pick a new location */
5119 ny = rand_spread(y, d);
5120 nx = rand_spread(x, d);
5122 /* Ignore annoying locations */
5123 if (!in_bounds(ny, nx)) continue;
5125 /* Ignore "excessively distant" locations */
5126 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
5128 /* Require "line of sight" */
5129 if (los(y, x, ny, nx)) break;
5132 /* Save the location */
5141 * Track a new monster
5143 void health_track(int m_idx)
5145 /* Mount monster is already tracked */
5146 if (m_idx && m_idx == p_ptr->riding) return;
5148 /* Track a new guy */
5149 p_ptr->health_who = m_idx;
5151 /* Redraw (later) */
5152 p_ptr->redraw |= (PR_HEALTH);
5158 * Hack -- track the given monster race
5160 void monster_race_track(int r_idx)
5162 /* Save this monster ID */
5163 p_ptr->monster_race_idx = r_idx;
5166 p_ptr->window |= (PW_MONSTER);
5172 * Hack -- track the given object kind
5174 void object_kind_track(int k_idx)
5176 /* Save this monster ID */
5177 p_ptr->object_kind_idx = k_idx;
5180 p_ptr->window |= (PW_OBJECT);
5186 * Something has happened to disturb the player.
5188 * The first arg indicates a major disturbance, which affects search.
5190 * The second arg is currently unused, but could induce output flush.
5192 * All disturbance cancels repeated commands, resting, and running.
5194 void disturb(int stop_search, int unused_flag)
5197 unused_flag = unused_flag;
5199 /* Cancel auto-commands */
5200 /* command_new = 0; */
5202 /* Cancel repeated commands */
5208 /* Redraw the state (later) */
5209 p_ptr->redraw |= (PR_STATE);
5212 /* Cancel Resting */
5213 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5216 set_action(ACTION_NONE);
5219 /* Cancel running */
5225 /* Check for new panel if appropriate */
5226 if (center_player && !center_running) verify_panel();
5228 /* Calculate torch radius */
5229 p_ptr->update |= (PU_TORCH);
5231 /* Update monster flow */
5232 p_ptr->update |= (PU_FLOW);
5235 /* Flush the input if requested */
5236 if (flush_disturb) flush();
5241 * Glow deep lava and building entrances in the floor
5243 void glow_deep_lava_and_bldg(void)
5245 int y, x, i, yy, xx;
5249 /* Not in the darkness dungeon */
5250 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
5252 for (y = 0; y < cur_hgt; y++)
5254 for (x = 0; x < cur_wid; x++)
5256 c_ptr = &cave[y][x];
5258 /* Feature code (applying "mimic" field) */
5259 feat = f_info[c_ptr->mimic ? c_ptr->mimic : c_ptr->feat].mimic;
5261 if ((feat == FEAT_DEEP_LAVA) ||
5262 ((feat >= FEAT_SHOP_HEAD) &&
5263 (feat <= FEAT_SHOP_TAIL)) ||
5264 (feat == FEAT_MUSEUM) ||
5265 ((feat >= FEAT_BLDG_HEAD) &&
5266 (feat <= FEAT_BLDG_TAIL)))
5268 for (i = 0; i < 9; i++)
5270 yy = y + ddy_ddd[i];
5271 xx = x + ddx_ddd[i];
5272 if (!in_bounds2(yy, xx)) continue;
5273 cave[yy][xx].info |= CAVE_GLOW;
5274 if (player_has_los_bold(yy, xx)) note_spot(yy, xx);