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 if (p_ptr->pclass == CLASS_NINJA) return TRUE;
450 /* Require "perma-lite" of the grid */
451 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return (FALSE);
453 /* Floors are simple */
454 if (cave_floor_bold(y, x)) return (TRUE);
456 /* Hack -- move towards player */
457 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
458 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
460 /* Check for "local" illumination */
461 if (cave[yy][xx].info & (CAVE_GLOW | CAVE_MNLT))
463 /* Assume the wall is really illuminated */
467 /* Assume not visible */
474 * Returns true if the player's grid is dark
478 return (!player_can_see_bold(py, px));
485 * Determine if a given location may be "destroyed"
487 * Used by destruction spells, and for placing stairs, etc.
489 bool cave_valid_bold(int y, int x)
491 cave_type *c_ptr = &cave[y][x];
493 s16b this_o_idx, next_o_idx = 0;
496 /* Forbid perma-grids */
497 if (cave_perma_grid(c_ptr)) return (FALSE);
500 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
505 o_ptr = &o_list[this_o_idx];
507 /* Acquire next object */
508 next_o_idx = o_ptr->next_o_idx;
510 /* Forbid artifact grids */
511 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
522 * Determine if a given location may be "destroyed"
524 * Used by destruction spells, and for placing stairs, etc.
526 bool cave_valid_grid(cave_type *c_ptr)
528 s16b this_o_idx, next_o_idx = 0;
531 /* Forbid perma-grids */
532 if (cave_perma_grid(c_ptr)) return (FALSE);
535 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
540 o_ptr = &o_list[this_o_idx];
542 /* Acquire next object */
543 next_o_idx = o_ptr->next_o_idx;
545 /* Forbid artifact grids */
546 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
557 * Hack -- Legal monster codes
559 static char image_monster_hack[] = \
560 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
563 * Mega-Hack -- Hallucinatory monster
565 static void image_monster(byte *ap, char *cp)
567 /* Random symbol from set above */
570 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
578 int n = sizeof(image_monster_hack) - 1;
580 *cp = image_monster_hack[randint0(n)];
590 * Hack -- Legal object codes
592 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
595 * Mega-Hack -- Hallucinatory object
597 static void image_object(byte *ap, char *cp)
601 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
608 int n = sizeof(image_object_hack) - 1;
610 *cp = image_object_hack[randint0(n)];
620 * Hack -- Random hallucination
622 static void image_random(byte *ap, char *cp)
624 /* Normally, assume monsters */
625 if (randint0(100) < 75)
627 image_monster(ap, cp);
630 /* Otherwise, assume objects */
633 image_object(ap, cp);
638 * Not using graphical tiles for this feature?
640 #define is_ascii_graphics(A) (!((A) & 0x80))
643 * The 16x16 tile of the terrain supports lighting
645 static bool feat_supports_lighting(byte feat)
647 if (is_trap(feat)) return streq(ANGBAND_GRAF, "new");
665 case FEAT_WALL_EXTRA:
666 case FEAT_WALL_INNER:
667 case FEAT_WALL_OUTER:
668 case FEAT_WALL_SOLID:
669 case FEAT_PERM_EXTRA:
670 case FEAT_PERM_INNER:
671 case FEAT_PERM_OUTER:
672 case FEAT_PERM_SOLID:
673 case FEAT_MINOR_GLYPH:
674 case FEAT_DEEP_WATER:
675 case FEAT_SHAL_WATER:
682 case FEAT_DEEP_GRASS:
693 * This array lists the effects of "brightness" on various "base" colours.
695 * This is used to do dynamic lighting effects in ascii :-)
696 * At the moment, only the various "floor" tiles are affected.
698 * The layout of the array is [x][0] = light and [x][1] = dark.
701 static byte lighting_colours[16][2] =
704 {TERM_L_DARK, TERM_DARK},
707 {TERM_YELLOW, TERM_SLATE},
710 {TERM_WHITE, TERM_L_DARK},
713 {TERM_L_UMBER, TERM_UMBER},
716 {TERM_RED, TERM_RED},
719 {TERM_L_GREEN, TERM_GREEN},
722 {TERM_BLUE, TERM_BLUE},
725 {TERM_L_UMBER, TERM_RED},
728 {TERM_SLATE, TERM_L_DARK},
731 {TERM_WHITE, TERM_SLATE},
734 {TERM_L_RED, TERM_BLUE},
737 {TERM_YELLOW, TERM_ORANGE},
740 {TERM_L_RED, TERM_L_RED},
743 {TERM_L_GREEN, TERM_GREEN},
746 {TERM_L_BLUE, TERM_L_BLUE},
749 {TERM_L_UMBER, TERM_UMBER}
753 * Extract the attr/char to display at the given (legal) map location
755 * Basically, we "paint" the chosen attr/char in several passes, starting
756 * with any known "terrain features" (defaulting to darkness), then adding
757 * any known "objects", and finally, adding any known "monsters". This
758 * is not the fastest method but since most of the calls to this function
759 * are made for grids with no monsters or objects, it is fast enough.
761 * Note that this function, if used on the grid containing the "player",
762 * will return the attr/char of the grid underneath the player, and not
763 * the actual player attr/char itself, allowing a lot of optimization
764 * in various "display" functions.
766 * Note that the "zero" entry in the feature/object/monster arrays are
767 * used to provide "special" attr/char codes, with "monster zero" being
768 * used for the player attr/char, "object zero" being used for the "stack"
769 * attr/char, and "feature zero" being used for the "nothing" attr/char,
770 * though this function makes use of only "feature zero".
772 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
773 * which means their color changes, and "ATTR_CLEAR", which means they take
774 * the color of whatever is under them, and "CHAR_CLEAR", which means that
775 * they take the symbol of whatever is under them. Technically, the flag
776 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
777 * examined, but this flag is currently ignored.
779 * Currently, we do nothing with multi-hued objects, because there are
780 * not any. If there were, they would have to set "shimmer_objects"
781 * when they were created, and then new "shimmer" code in "dungeon.c"
782 * would have to be created handle the "shimmer" effect, and the code
783 * in "cave.c" would have to be updated to create the shimmer effect.
785 * Note the effects of hallucination. Objects always appear as random
786 * "objects", monsters as random "monsters", and normal grids occasionally
787 * appear as random "monsters" or "objects", but note that these random
788 * "monsters" and "objects" are really just "colored ascii symbols".
790 * Note that "floors" and "invisible traps" (and "zero" features) are
791 * drawn as "floors" using a special check for optimization purposes,
792 * and these are the only features which get drawn using the special
793 * lighting effects activated by "view_special_lite".
795 * Note the use of the "mimic" field in the "terrain feature" processing,
796 * which allows any feature to "pretend" to be another feature. This is
797 * used to "hide" secret doors, and to make all "doors" appear the same,
798 * and all "walls" appear the same, and "hidden" treasure stay hidden.
799 * It is possible to use this field to make a feature "look" like a floor,
800 * but the "special lighting effects" for floors will not be used.
802 * Note the use of the new "terrain feature" information. Note that the
803 * assumption that all interesting "objects" and "terrain features" are
804 * memorized allows extremely optimized processing below. Note the use
805 * of separate flags on objects to mark them as memorized allows a grid
806 * to have memorized "terrain" without granting knowledge of any object
807 * which may appear in that grid.
809 * Note the efficient code used to determine if a "floor" grid is
810 * "memorized" or "viewable" by the player, where the test for the
811 * grid being "viewable" is based on the facts that (1) the grid
812 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
813 * line of sight, and (3) the player must not be blind, and uses the
814 * assumption that all torch-lit grids are in line of sight.
816 * Note that floors (and invisible traps) are the only grids which are
817 * not memorized when seen, so only these grids need to check to see if
818 * the grid is "viewable" to the player (if it is not memorized). Since
819 * most non-memorized grids are in fact walls, this induces *massive*
820 * efficiency, at the cost of *forcing* the memorization of non-floor
821 * grids when they are first seen. Note that "invisible traps" are
822 * always treated exactly like "floors", which prevents "cheating".
824 * Note the "special lighting effects" which can be activated for floor
825 * grids using the "view_special_lite" option (for "white" floor grids),
826 * causing certain grids to be displayed using special colors. If the
827 * player is "blind", we will use "dark gray", else if the grid is lit
828 * by the torch, and the "view_yellow_lite" option is set, we will use
829 * "yellow", else if the grid is "dark", we will use "dark gray", else
830 * if the grid is not "viewable", and the "view_bright_lite" option is
831 * set, and the we will use "slate" (gray). We will use "white" for all
832 * other cases, in particular, for illuminated viewable floor grids.
834 * Note the "special lighting effects" which can be activated for wall
835 * grids using the "view_granite_lite" option (for "white" wall grids),
836 * causing certain grids to be displayed using special colors. If the
837 * player is "blind", we will use "dark gray", else if the grid is lit
838 * by the torch, and the "view_yellow_lite" option is set, we will use
839 * "yellow", else if the "view_bright_lite" option is set, and the grid
840 * is not "viewable", or is "dark", or is glowing, but not when viewed
841 * from the player's current location, we will use "slate" (gray). We
842 * will use "white" for all other cases, in particular, for correctly
843 * illuminated viewable wall grids.
845 * Note that, when "view_granite_lite" is set, we use an inline version
846 * of the "player_can_see_bold()" function to check the "viewability" of
847 * grids when the "view_bright_lite" option is set, and we do NOT use
848 * any special colors for "dark" wall grids, since this would allow the
849 * player to notice the walls of illuminated rooms from a hallway that
850 * happened to run beside the room. The alternative, by the way, would
851 * be to prevent the generation of hallways next to rooms, but this
852 * would still allow problems when digging towards a room.
854 * Note that bizarre things must be done when the "attr" and/or "char"
855 * codes have the "high-bit" set, since these values are used to encode
856 * various "special" pictures in some versions, and certain situations,
857 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
858 * to be "scrambled" in various ways.
860 * Note that eventually we may use the "&" symbol for embedded treasure,
861 * and use the "*" symbol to indicate multiple objects, though this will
862 * have to wait for Angband 2.8.0 or later. Note that currently, this
863 * is not important, since only one object or terrain feature is allowed
864 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
866 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
867 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
868 * then a whole lot of code should be changed... XXX XXX
870 #ifdef USE_TRANSPARENCY
871 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
872 #else /* USE_TRANSPARENCY */
873 void map_info(int y, int x, byte *ap, char *cp)
874 #endif /* USE_TRANSPARENCY */
880 s16b this_o_idx, next_o_idx = 0;
890 /* Feature code (applying "mimic" field) */
891 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
894 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
896 /* Memorized (or visible) floor */
897 if ((c_ptr->info & CAVE_MARK) ||
898 (((c_ptr->info & CAVE_LITE) || (c_ptr->info & CAVE_MNLT) ||
899 ((c_ptr->info & CAVE_GLOW) &&
900 (c_ptr->info & CAVE_VIEW))) &&
904 f_ptr = &f_info[feat];
912 /* Special lighting effects */
913 if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_graphics))
921 * feat_supports_lighting(feat)
922 * is always TRUE here
925 /* Use a dark tile */
930 /* Use "dark gray" */
935 /* Handle "torch-lit" grids */
936 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
939 if (view_yellow_lite && !p_ptr->wild_mode)
944 * feat_supports_lighting(feat)
945 * is always TRUE here
948 /* Use a brightly lit tile */
959 /* Handle "dark" grids */
960 else if (!(c_ptr->info & CAVE_GLOW))
965 * feat_supports_lighting(feat)
966 * is always TRUE here
969 /* Use a dark tile */
974 /* Use "dark gray" */
979 /* Handle "out-of-sight" grids */
980 else if (!(c_ptr->info & CAVE_VIEW))
983 if (view_bright_lite && !p_ptr->wild_mode)
988 * feat_supports_lighting(feat)
989 * is always TRUE here
992 /* Use a dark tile */
1008 /* Unsafe cave grid -- idea borrowed from Unangband */
1009 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1010 feat = FEAT_UNDETECTD;
1014 /* Access darkness */
1015 f_ptr = &f_info[feat];
1028 /* Memorized grids */
1029 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || new_ascii_graphics))
1031 /* Access feature */
1032 f_ptr = &f_info[feat];
1040 if (new_ascii_graphics)
1042 /* Handle "blind" */
1045 if (is_ascii_graphics(a))
1047 /* Use darkened colour */
1048 a = lighting_colours[a][1];
1050 else if (use_graphics && feat_supports_lighting(feat))
1052 /* Use a dark tile */
1057 /* Handle "torch-lit" grids */
1058 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1061 if (view_yellow_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(a)))
1063 if (is_ascii_graphics(a))
1065 /* Use lightened colour */
1066 a = lighting_colours[a][0];
1068 else if (use_graphics &&
1069 feat_supports_lighting(feat))
1071 /* Use a brightly lit tile */
1077 /* Handle "view_bright_lite" */
1078 else if (view_bright_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(a)))
1081 if (!(c_ptr->info & CAVE_VIEW))
1083 if (is_ascii_graphics(a))
1085 /* Use darkened colour */
1086 a = lighting_colours[a][1];
1088 else if (use_graphics && feat_supports_lighting(feat))
1090 /* Use a dark tile */
1096 else if (!(c_ptr->info & CAVE_GLOW))
1098 if (is_ascii_graphics(a))
1100 /* Use darkened colour */
1101 a = lighting_colours[a][1];
1106 /* Special lighting effects */
1107 else if (view_granite_lite && !p_ptr->wild_mode &&
1108 (((a == TERM_WHITE) && !use_graphics) ||
1109 (use_graphics && feat_supports_lighting(feat))))
1111 /* Handle "blind" */
1116 /* Use a dark tile */
1121 /* Use "dark gray" */
1126 /* Handle "torch-lit" grids */
1127 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1130 if (view_yellow_lite && !p_ptr->wild_mode)
1134 /* Use a brightly lit tile */
1145 /* Handle "view_bright_lite" */
1146 else if (view_bright_lite && !p_ptr->wild_mode)
1149 if (!(c_ptr->info & CAVE_VIEW))
1153 /* Use a dark tile */
1164 else if (!(c_ptr->info & CAVE_GLOW))
1168 /* Use a lit tile */
1177 /* Not glowing correctly */
1182 /* Hack -- move towards player */
1183 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1184 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1186 /* Check for "local" illumination */
1187 if (!(cave[yy][xx].info & CAVE_GLOW))
1191 /* Use a lit tile */
1204 /* "Simple Lighting" */
1207 /* Handle "blind" */
1208 if (!(c_ptr->info & CAVE_MARK))
1210 /* Unsafe cave grid -- idea borrowed from Unangband */
1211 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1212 feat = FEAT_UNDETECTD;
1217 /* Access feature */
1218 f_ptr = &f_info[feat];
1228 if (feat_priority == -1)
1233 case FEAT_UNDETECTD:
1240 case FEAT_TRAP_TRAPDOOR:
1242 case FEAT_TRAP_SPIKED_PIT:
1243 case FEAT_TRAP_POISON_PIT:
1244 case FEAT_TRAP_TY_CURSE:
1245 case FEAT_TRAP_TELEPORT:
1246 case FEAT_TRAP_FIRE:
1247 case FEAT_TRAP_ACID:
1248 case FEAT_TRAP_SLOW:
1249 case FEAT_TRAP_LOSE_STR:
1250 case FEAT_TRAP_LOSE_DEX:
1251 case FEAT_TRAP_LOSE_CON:
1252 case FEAT_TRAP_BLIND:
1253 case FEAT_TRAP_CONFUSE:
1254 case FEAT_TRAP_POISON:
1255 case FEAT_TRAP_SLEEP:
1256 case FEAT_TRAP_TRAPS:
1257 case FEAT_TRAP_ALARM:
1261 case FEAT_DEEP_GRASS:
1269 case FEAT_WALL_EXTRA:
1270 case FEAT_WALL_INNER:
1271 case FEAT_WALL_OUTER:
1272 case FEAT_WALL_SOLID:
1273 case FEAT_DEEP_WATER:
1274 case FEAT_SHAL_WATER:
1275 case FEAT_DEEP_LAVA:
1276 case FEAT_SHAL_LAVA:
1282 /* Now a days treasere grid is too many */
1287 case FEAT_PERM_EXTRA:
1288 case FEAT_PERM_INNER:
1289 case FEAT_PERM_OUTER:
1290 case FEAT_PERM_SOLID:
1294 /* default is feat_priority = 20; (doors and stores) */
1297 case FEAT_MINOR_GLYPH:
1299 case FEAT_PATTERN_START:
1300 case FEAT_PATTERN_1:
1301 case FEAT_PATTERN_2:
1302 case FEAT_PATTERN_3:
1303 case FEAT_PATTERN_4:
1304 case FEAT_PATTERN_END:
1305 case FEAT_PATTERN_OLD:
1306 case FEAT_PATTERN_XTRA1:
1307 case FEAT_PATTERN_XTRA2:
1311 /* objects have feat_priority = 20 */
1312 /* monsters have feat_priority = 30 */
1316 case FEAT_QUEST_ENTER:
1317 case FEAT_QUEST_EXIT:
1318 case FEAT_QUEST_DOWN:
1320 case FEAT_LESS_LESS:
1321 case FEAT_MORE_MORE:
1333 #ifdef USE_TRANSPARENCY
1334 /* Save the terrain info for the transparency effects */
1337 #endif /* USE_TRANSPARENCY */
1343 /* Hack -- rare random hallucination, except on outer dungeon walls */
1344 if (p_ptr->image && (feat < FEAT_PERM_SOLID) && one_in_(256))
1347 image_random(ap, cp);
1351 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1355 /* Acquire object */
1356 o_ptr = &o_list[this_o_idx];
1358 /* Acquire next object */
1359 next_o_idx = o_ptr->next_o_idx;
1361 /* Memorized objects */
1364 if (display_autopick)
1368 match_autopick = is_autopick(o_ptr);
1369 if(match_autopick == -1)
1372 act = autopick_list[match_autopick].action;
1374 if ((act & DO_DISPLAY) && (act & display_autopick))
1376 autopick_obj = o_ptr;
1380 match_autopick = -1;
1385 (*cp) = object_char(o_ptr);
1388 (*ap) = object_attr(o_ptr);
1392 /* Hack -- hallucination */
1393 if (p_ptr->image) image_object(ap, cp);
1401 /* Handle monsters */
1402 if (c_ptr->m_idx && display_autopick == 0 )
1404 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1406 /* Visible monster */
1409 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1417 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1418 * flags are always unseen.
1420 if (!(~r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)))
1426 /* Hallucinatory monster */
1427 image_monster(ap, cp);
1432 /* Monster attr/char */
1436 /* Normal monsters */
1437 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR | RF1_ATTR_MULTI)))
1439 /* Desired monster attr/char */
1443 /* Mimics' colors vary */
1444 if (((c == '\"') || (c == '!') || (c == '='))
1445 && !(r_ptr->flags1 & RF1_UNIQUE))
1447 /* Use semi-random attr */
1448 *ap = c_ptr->m_idx % 15 + 1;
1453 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1454 * flags are always unseen.
1456 if (!(~r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)))
1463 /*** Monster's attr ***/
1464 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && !use_graphics)
1469 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1471 /* Multi-hued attr */
1472 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1473 else switch (randint1(7))
1475 case 1: *ap = TERM_RED; break;
1476 case 2: *ap = TERM_L_RED; break;
1477 case 3: *ap = TERM_WHITE; break;
1478 case 4: *ap = TERM_L_GREEN; break;
1479 case 5: *ap = TERM_BLUE; break;
1480 case 6: *ap = TERM_L_DARK; break;
1481 case 7: *ap = TERM_GREEN; break;
1490 /*** Monster's char ***/
1491 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && !use_graphics)
1496 else if (r_ptr->flags2 & RF2_SHAPECHANGER)
1500 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1501 *cp = tmp_r_ptr->x_char;
1502 *ap = tmp_r_ptr->x_attr;
1506 *cp = (one_in_(25) ?
1507 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1508 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1521 /* Handle "player" */
1522 if ((y == py) && (x == px))
1524 monster_race *r_ptr = &r_info[0];
1528 /* Get the "player" attr */
1531 /* Get the "player" char */
1534 #ifdef VARIABLE_PLAYER_GRAPH
1540 #endif /* VARIABLE_PLAYER_GRAPH */
1548 * Table of Ascii-to-Zenkaku
1549 * ¡Ö¢£¡×¤ÏÆóÇÜÉýƦÉå¤ÎÆâÉô¥³¡¼¥É¤Ë»ÈÍÑ¡£
1551 static char ascii_to_zenkaku[2*128+1] = "\
1552 ¡¡¡ª¡É¡ô¡ð¡ó¡õ¡Ç¡Ê¡Ë¡ö¡Ü¡¤¡Ý¡¥¡¿\
1553 £°£±£²£³£´£µ£¶£·£¸£¹¡§¡¨¡ã¡á¡ä¡©\
1554 ¡÷£Á£Â£Ã£Ä£Å£Æ£Ç£È£É£Ê£Ë£Ì£Í£Î£Ï\
1555 £Ð£Ñ£Ò£Ó£Ô£Õ£Ö£×£Ø£Ù£Ú¡Î¡À¡Ï¡°¡²\
1556 ¡Æ£á£â£ã£ä£å£æ£ç£è£é£ê£ë£ì£í£î£ï\
1557 £ð£ñ£ò£ó£ô£õ£ö£÷£ø£ù£ú¡Ð¡Ã¡Ñ¡Á¢£";
1561 * Prepare Bigtile or 2-bytes character attr/char pairs
1563 void bigtile_attr(char *cp, byte *ap, char *cp2, byte *ap2)
1565 if ((*ap & 0x80) && (*cp & 0x80))
1573 if (isprint(*cp) || *cp == 127)
1575 *ap2 = (*ap) | 0xf0;
1576 *cp2 = ascii_to_zenkaku[2*(*cp-' ') + 1];
1577 *cp = ascii_to_zenkaku[2*(*cp-' ')];
1588 * Calculate panel colum of a location in the map
1590 static int panel_col_of(int col)
1592 col -= panel_col_min;
1593 if (use_bigtile) col *= 2;
1599 * Moves the cursor to a given MAP (y,x) location
1601 void move_cursor_relative(int row, int col)
1603 /* Real co-ords convert to screen positions */
1604 row -= panel_row_prt;
1607 Term_gotoxy(panel_col_of(col), row);
1613 * Place an attr/char pair at the given map coordinate, if legal.
1615 void print_rel(char c, byte a, int y, int x)
1620 /* Only do "legal" locations */
1621 if (panel_contains(y, x))
1623 /* Hack -- fake monochrome */
1626 if (world_monster) a = TERM_DARK;
1627 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1628 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1631 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
1633 /* Draw the char using the attr */
1634 Term_draw(panel_col_of(x), y-panel_row_prt, a, c);
1636 Term_draw(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
1645 * Memorize interesting viewable object/features in the given grid
1647 * This function should only be called on "legal" grids.
1649 * This function will memorize the object and/or feature in the given
1650 * grid, if they are (1) viewable and (2) interesting. Note that all
1651 * objects are interesting, all terrain features except floors (and
1652 * invisible traps) are interesting, and floors (and invisible traps)
1653 * are interesting sometimes (depending on various options involving
1654 * the illumination of floor grids).
1656 * The automatic memorization of all objects and non-floor terrain
1657 * features as soon as they are displayed allows incredible amounts
1658 * of optimization in various places, especially "map_info()".
1660 * Note that the memorization of objects is completely separate from
1661 * the memorization of terrain features, preventing annoying floor
1662 * memorization when a detected object is picked up from a dark floor,
1663 * and object memorization when an object is dropped into a floor grid
1664 * which is memorized but out-of-sight.
1666 * This function should be called every time the "memorization" of
1667 * a grid (or the object in a grid) is called into question, such
1668 * as when an object is created in a grid, when a terrain feature
1669 * "changes" from "floor" to "non-floor", when any grid becomes
1670 * "illuminated" or "viewable", and when a "floor" grid becomes
1673 * Note the relatively efficient use of this function by the various
1674 * "update_view()" and "update_lite()" calls, to allow objects and
1675 * terrain features to be memorized (and drawn) whenever they become
1676 * viewable or illuminated in any way, but not when they "maintain"
1677 * or "lose" their previous viewability or illumination.
1679 * Note the butchered "internal" version of "player_can_see_bold()",
1680 * optimized primarily for the most common cases, that is, for the
1681 * non-marked floor grids.
1683 void note_spot(int y, int x)
1685 cave_type *c_ptr = &cave[y][x];
1687 s16b this_o_idx, next_o_idx = 0;
1691 /* Feature code (applying "mimic" field) */
1692 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
1695 /* Blind players see nothing */
1696 if (p_ptr->blind) return;
1698 /* Analyze non-torch-lit grids */
1699 if (!(c_ptr->info & (CAVE_LITE)))
1701 /* Require line of sight to the grid */
1702 if (!(c_ptr->info & (CAVE_VIEW))) return;
1704 if (p_ptr->pclass != CLASS_NINJA)
1706 /* Require "perma-lite" of the grid */
1707 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return;
1712 /* Hack -- memorize objects */
1713 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1715 object_type *o_ptr = &o_list[this_o_idx];
1717 /* Acquire next object */
1718 next_o_idx = o_ptr->next_o_idx;
1720 /* Memorize objects */
1721 o_ptr->marked |= OM_FOUND;
1725 /* Hack -- memorize grids */
1726 if (!(c_ptr->info & (CAVE_MARK)))
1728 if (p_ptr->pclass == CLASS_NINJA)
1730 c_ptr->info |= (CAVE_MARK);
1732 /* Handle floor grids first */
1733 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
1735 /* Option -- memorize all torch-lit floors */
1736 if (view_torch_grids && (c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1739 c_ptr->info |= (CAVE_MARK);
1742 /* Option -- memorize all perma-lit floors */
1743 else if (view_perma_grids && (c_ptr->info & (CAVE_GLOW)))
1746 c_ptr->info |= (CAVE_MARK);
1750 /* Memorize normal grids */
1751 else if (cave_floor_grid(c_ptr))
1754 c_ptr->info |= (CAVE_MARK);
1757 /* Memorize torch-lit walls */
1758 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1761 c_ptr->info |= (CAVE_MARK);
1764 /* Memorize certain non-torch-lit wall grids */
1769 /* Hack -- move one grid towards player */
1770 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1771 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1773 /* Check for "local" illumination */
1774 if (cave[yy][xx].info & (CAVE_GLOW))
1777 c_ptr->info |= (CAVE_MARK);
1784 void display_dungeon(void)
1790 #ifdef USE_TRANSPARENCY
1793 #endif /* USE_TRANSPARENCY */
1795 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1797 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1799 if (in_bounds2(y, x))
1802 #ifdef USE_TRANSPARENCY
1803 /* Examine the grid */
1804 map_info(y, x, &a, &c, &ta, &tc);
1805 #else /* USE_TRANSPARENCY */
1806 /* Examine the grid */
1807 map_info(y, x, &a, &c);
1808 #endif /* USE_TRANSPARENCY */
1810 /* Hack -- fake monochrome */
1813 if (world_monster) a = TERM_DARK;
1814 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1815 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1818 #ifdef USE_TRANSPARENCY
1819 /* Hack -- Queue it */
1820 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1821 #else /* USE_TRANSPARENCY */
1822 /* Hack -- Queue it */
1823 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
1824 #endif /* USE_TRANSPARENCY */
1829 /* Clear out-of-bound tiles */
1831 /* Access darkness */
1832 feature_type *f_ptr = &f_info[FEAT_NONE];
1840 #ifdef USE_TRANSPARENCY
1841 /* Hack -- Queue it */
1842 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1843 #else /* USE_TRANSPARENCY */
1844 /* Hack -- Queue it */
1845 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
1846 #endif /* USE_TRANSPARENCY */
1854 * Redraw (on the screen) a given MAP location
1856 * This function should only be called on "legal" grids
1858 void lite_spot(int y, int x)
1860 /* Redraw if on screen */
1861 if (panel_contains(y, x) && in_bounds2(y, x))
1866 #ifdef USE_TRANSPARENCY
1870 /* Examine the grid */
1871 map_info(y, x, &a, &c, &ta, &tc);
1872 #else /* USE_TRANSPARENCY */
1873 /* Examine the grid */
1874 map_info(y, x, &a, &c);
1875 #endif /* USE_TRANSPARENCY */
1877 /* Hack -- fake monochrome */
1880 if (world_monster) a = TERM_DARK;
1881 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1882 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1886 if (use_bigtile && is_ascii_graphics(a) && (isprint(c) || c == 127))
1888 /* Term_queue_chars ¤ÏÁ´³ÑASCIIÃÏ·Á¤òÀµ¤·¤¯update¤¹¤ë¡£ */
1889 Term_queue_chars(panel_col_of(x), y-panel_row_prt, 2, a, &ascii_to_zenkaku[2*(c-' ')]);
1894 #ifdef USE_TRANSPARENCY
1895 /* Hack -- Queue it */
1896 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1898 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1, 0, 0);
1899 #else /* USE_TRANSPARENCY */
1900 /* Hack -- Queue it */
1901 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
1903 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1);
1904 #endif /* USE_TRANSPARENCY */
1906 /* Update sub-windows */
1907 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1913 * Prints the map of the dungeon
1915 * Note that, for efficiency, we contain an "optimized" version
1916 * of both "lite_spot()" and "print_rel()", and that we use the
1917 * "lite_spot()" function to display the player grid, if needed.
1925 s16b xmin, xmax, ymin, ymax;
1930 Term_get_size(&wid, &hgt);
1932 /* Remove map offset */
1936 /* Access the cursor state */
1937 (void)Term_get_cursor(&v);
1939 /* Hide the cursor */
1940 (void)Term_set_cursor(0);
1943 xmin = (0 < panel_col_min) ? panel_col_min : 0;
1944 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1945 ymin = (0 < panel_row_min) ? panel_row_min : 0;
1946 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1948 /* Bottom section of screen */
1949 for (y = 1; y <= ymin - panel_row_prt; y++)
1951 /* Erase the section */
1952 Term_erase(COL_MAP, y, wid);
1955 /* Top section of screen */
1956 for (y = ymax - panel_row_prt; y <= hgt; y++)
1958 /* Erase the section */
1959 Term_erase(COL_MAP, y, wid);
1963 for (y = ymin; y <= ymax; y++)
1965 /* Scan the columns of row "y" */
1966 for (x = xmin; x <= xmax; x++)
1971 #ifdef USE_TRANSPARENCY
1975 /* Determine what is there */
1976 map_info(y, x, &a, &c, &ta, &tc);
1978 /* Determine what is there */
1979 map_info(y, x, &a, &c);
1982 /* Hack -- fake monochrome */
1985 if (world_monster) a = TERM_DARK;
1986 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1987 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1990 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
1992 /* Efficiency -- Redraw that grid of the map */
1993 #ifdef USE_TRANSPARENCY
1994 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1995 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2, 0, 0);
1997 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
1998 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
2003 /* Display player */
2006 /* Restore the cursor */
2007 (void)Term_set_cursor(v);
2013 * print project path
2015 void prt_path(int y, int x)
2020 int default_color = TERM_SLATE;
2022 if (!display_path) return;
2023 if (-1 == project_length)
2026 /* Get projection path */
2027 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2030 p_ptr->redraw |= (PR_MAP);
2036 for (i = 0; i < path_n; i++)
2038 int ny = GRID_Y(path_g[i]);
2039 int nx = GRID_X(path_g[i]);
2041 if (panel_contains(ny, nx))
2043 byte a2, a = default_color;
2046 #ifdef USE_TRANSPARENCY
2051 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2053 /* Determine what is there */
2054 #ifdef USE_TRANSPARENCY
2055 map_info(ny, nx, &a, &c, &ta, &tc);
2057 map_info(ny, nx, &a, &c);
2059 if (!is_ascii_graphics(a))
2061 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2063 else if (a == default_color)
2069 if (world_monster) a = TERM_DARK;
2070 else if (IS_INVULN() || world_player) a = TERM_WHITE;
2071 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2075 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2077 /* Hack -- Queue it */
2078 #ifdef USE_TRANSPARENCY
2079 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
2080 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2, 0, 0);
2082 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c);
2083 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2);
2088 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2091 if (nx == x && ny == y) default_color = TERM_L_DARK;
2096 static cptr simplify_list[][2] =
2103 {"^Amulet of ", "\""},
2104 {"^Scroll of ", "?"},
2105 {"^Scroll titled ", "?"},
2106 {"^Wand of " , "-"},
2108 {"^Staff of " , "_"},
2109 {"^Potion of ", "!"},
2121 static void display_shortened_item_name(object_type *o_ptr, int y)
2128 object_desc(buf, o_ptr, FALSE, 0);
2129 attr = tval_to_attr[o_ptr->tval % 128];
2135 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
2137 strcpy(buf, "something strange");
2141 for (c = buf; *c; c++)
2144 for (i = 0; simplify_list[i][1]; i++)
2146 cptr org_w = simplify_list[i][0];
2156 if (!strncmp(c, org_w, strlen(org_w)))
2159 cptr tmp = simplify_list[i][1];
2162 tmp = c + strlen(org_w);
2172 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2178 if(len + 2 > 12) break;
2185 if(len + 1 > 12) break;
2191 Term_putstr(0, y, 12, attr, buf);
2195 * Display a "small-scale" map of the dungeon in the active Term
2197 void display_map(int *cy, int *cx)
2214 /* Save lighting effects */
2215 bool old_view_special_lite = view_special_lite;
2216 bool old_view_granite_lite = view_granite_lite;
2218 int hgt, wid, yrat, xrat;
2220 int **match_autopick_yx;
2221 object_type ***object_autopick_yx;
2224 Term_get_size(&wid, &hgt);
2227 if (use_bigtile) wid /= 2;
2229 yrat = (cur_hgt + hgt - 1) / hgt;
2230 xrat = (cur_wid + wid - 1) / wid;
2232 /* Disable lighting effects */
2233 view_special_lite = FALSE;
2234 view_granite_lite = FALSE;
2236 /* Allocate the maps */
2237 C_MAKE(ma, (hgt + 2), byte_ptr);
2238 C_MAKE(mc, (hgt + 2), char_ptr);
2239 C_MAKE(mp, (hgt + 2), byte_ptr);
2240 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2241 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2243 /* Allocate and wipe each line map */
2244 for (y = 0; y < (hgt + 2); y++)
2246 /* Allocate one row each array */
2247 C_MAKE(ma[y], (wid + 2), byte);
2248 C_MAKE(mc[y], (wid + 2), char);
2249 C_MAKE(mp[y], (wid + 2), byte);
2250 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2251 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2253 for (x = 0; x < wid + 2; ++x)
2255 match_autopick_yx[y][x] = -1;
2256 object_autopick_yx[y][x] = NULL;
2259 ma[y][x] = TERM_WHITE;
2267 /* Allocate the maps */
2268 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
2269 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
2270 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
2272 /* Allocate and wipe each line map */
2273 for (y = 0; y < (cur_hgt + 2); y++)
2275 /* Allocate one row each array */
2276 C_MAKE(bigma[y], (cur_wid + 2), byte);
2277 C_MAKE(bigmc[y], (cur_wid + 2), char);
2278 C_MAKE(bigmp[y], (cur_wid + 2), byte);
2280 for (x = 0; x < cur_wid + 2; ++x)
2283 bigma[y][x] = TERM_WHITE;
2291 /* Fill in the map */
2292 for (i = 0; i < cur_wid; ++i)
2294 for (j = 0; j < cur_hgt; ++j)
2304 /* Extract the current attr/char at that map location */
2305 #ifdef USE_TRANSPARENCY
2306 map_info(j, i, &ta, &tc, &ta, &tc);
2307 #else /* USE_TRANSPARENCY */
2308 map_info(j, i, &ta, &tc);
2309 #endif /* USE_TRANSPARENCY */
2311 /* Extract the priority */
2314 if(match_autopick!=-1
2315 && (match_autopick_yx[y][x] == -1
2316 || match_autopick_yx[y][x] > match_autopick))
2318 match_autopick_yx[y][x] = match_autopick;
2319 object_autopick_yx[y][x] = autopick_obj;
2323 /* Save the char, attr and priority */
2324 bigmc[j+1][i+1] = tc;
2325 bigma[j+1][i+1] = ta;
2326 bigmp[j+1][i+1] = tp;
2330 for (j = 0; j < cur_hgt; ++j)
2332 for (i = 0; i < cur_wid; ++i)
2338 tc = bigmc[j+1][i+1];
2339 ta = bigma[j+1][i+1];
2340 tp = bigmp[j+1][i+1];
2342 /* rare feature has more priority */
2348 for (t = 0; t < 8; t++)
2350 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2351 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2361 /* Save the char, attr and priority */
2374 /* Draw the corners */
2375 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2377 /* Draw the horizontal edges */
2378 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2380 /* Draw the vertical edges */
2381 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2384 /* Display each map line in order */
2385 for (y = 0; y < hgt + 2; ++y)
2387 /* Start a new line */
2388 Term_gotoxy(COL_MAP, y);
2390 /* Display the line */
2391 for (x = 0; x < wid + 2; ++x)
2396 /* Hack -- fake monochrome */
2399 if (world_monster) ta = TERM_DARK;
2400 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2401 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2404 if (use_bigtile) bigtile_attr(&tc, &ta, &c2, &a2);
2406 /* Add the character */
2408 if (use_bigtile) Term_addch(a2, c2);
2413 for (y = 1; y < hgt + 1; ++y)
2415 match_autopick = -1;
2416 for (x = 1; x <= wid; x++){
2417 if (match_autopick_yx[y][x] != -1 &&
2418 (match_autopick > match_autopick_yx[y][x] ||
2419 match_autopick == -1)){
2420 match_autopick = match_autopick_yx[y][x];
2421 autopick_obj = object_autopick_yx[y][x];
2425 /* Clear old display */
2426 Term_putstr(0, y, 12, 0, " ");
2428 if (match_autopick != -1)
2430 display_shortened_item_name(autopick_obj, y);
2433 char buf[13] = "\0";
2434 strncpy(buf,autopick_list[match_autopick].name,12);
2442 /* Player location */
2443 (*cy) = py / yrat + 1 + ROW_MAP;
2445 (*cx) = px / xrat + 1 + COL_MAP;
2447 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2449 /* Restore lighting effects */
2450 view_special_lite = old_view_special_lite;
2451 view_granite_lite = old_view_granite_lite;
2453 /* Free each line map */
2454 for (y = 0; y < (hgt + 2); y++)
2456 /* Free one row each array */
2457 C_FREE(ma[y], (wid + 2), byte);
2458 C_FREE(mc[y], (wid + 2), char);
2459 C_FREE(mp[y], (wid + 2), byte);
2460 C_FREE(match_autopick_yx[y], (wid + 2), int);
2461 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2464 /* Free each line map */
2465 C_FREE(ma, (hgt + 2), byte_ptr);
2466 C_FREE(mc, (hgt + 2), char_ptr);
2467 C_FREE(mp, (hgt + 2), byte_ptr);
2468 C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2469 C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2471 /* Free each line map */
2472 for (y = 0; y < (cur_hgt + 2); y++)
2474 /* Free one row each array */
2475 C_FREE(bigma[y], (cur_wid + 2), byte);
2476 C_FREE(bigmc[y], (cur_wid + 2), char);
2477 C_FREE(bigmp[y], (cur_wid + 2), byte);
2480 /* Free each line map */
2481 C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2482 C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2483 C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2488 * Display a "small-scale" map of the dungeon for the player
2490 * Currently, the "player" is displayed on the map. XXX XXX XXX
2492 void do_cmd_view_map(void)
2497 /* Save the screen */
2502 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2504 prt("Please wait...", 0, 0);
2510 /* Clear the screen */
2513 display_autopick = 0;
2515 /* Display the map */
2516 display_map(&cy, &cx);
2519 if(max_autopick && !p_ptr->wild_mode)
2521 display_autopick = ITEM_DISPLAY;
2528 int wid, hgt, row_message;
2530 Term_get_size(&wid, &hgt);
2531 row_message = hgt - 1;
2534 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2536 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2539 /* Hilite the player */
2540 move_cursor(cy, cx);
2545 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2547 flag = DONT_AUTOPICK;
2549 flag = DO_AUTODESTROY;
2551 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2557 if (~display_autopick & flag)
2558 display_autopick |= flag;
2560 display_autopick &= ~flag;
2561 /* Display the map */
2562 display_map(&cy, &cx);
2565 display_autopick = 0;
2571 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2573 put_str("Hit any key to continue", 23, 30);
2574 #endif /* Hilite the player */
2575 move_cursor(cy, cx);
2580 /* Restore the screen */
2589 * Some comments on the cave grid flags. -BEN-
2592 * One of the major bottlenecks in previous versions of Angband was in
2593 * the calculation of "line of sight" from the player to various grids,
2594 * such as monsters. This was such a nasty bottleneck that a lot of
2595 * silly things were done to reduce the dependancy on "line of sight",
2596 * for example, you could not "see" any grids in a lit room until you
2597 * actually entered the room, and there were all kinds of bizarre grid
2598 * flags to enable this behavior. This is also why the "call light"
2599 * spells always lit an entire room.
2601 * The code below provides functions to calculate the "field of view"
2602 * for the player, which, once calculated, provides extremely fast
2603 * calculation of "line of sight from the player", and to calculate
2604 * the "field of torch lite", which, again, once calculated, provides
2605 * extremely fast calculation of "which grids are lit by the player's
2606 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2607 * "GRID_LITE", as appropriate, these functions maintain an array for
2608 * each of these two flags, each array containing the locations of all
2609 * of the grids marked with the appropriate flag, which can be used to
2610 * very quickly scan through all of the grids in a given set.
2612 * To allow more "semantically valid" field of view semantics, whenever
2613 * the field of view (or the set of torch lit grids) changes, all of the
2614 * grids in the field of view (or the set of torch lit grids) are "drawn"
2615 * so that changes in the world will become apparent as soon as possible.
2616 * This has been optimized so that only grids which actually "change" are
2617 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2618 * of the grids which are entering or leaving the relevent set of grids.
2620 * These new methods are so efficient that the old nasty code was removed.
2622 * Note that there is no reason to "update" the "viewable space" unless
2623 * the player "moves", or walls/doors are created/destroyed, and there
2624 * is no reason to "update" the "torch lit grids" unless the field of
2625 * view changes, or the "light radius" changes. This means that when
2626 * the player is resting, or digging, or doing anything that does not
2627 * involve movement or changing the state of the dungeon, there is no
2628 * need to update the "view" or the "lite" regions, which is nice.
2630 * Note that the calls to the nasty "los()" function have been reduced
2631 * to a bare minimum by the use of the new "field of view" calculations.
2633 * I wouldn't be surprised if slight modifications to the "update_view()"
2634 * function would allow us to determine "reverse line-of-sight" as well
2635 * as "normal line-of-sight", which would allow monsters to use a more
2636 * "correct" calculation to determine if they can "see" the player. For
2637 * now, monsters simply "cheat" somewhat and assume that if the player
2638 * has "line of sight" to the monster, then the monster can "pretend"
2639 * that it has "line of sight" to the player.
2642 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2643 * grid and maintains an array of all "CAVE_LITE" grids.
2645 * This set of grids is the complete set of all grids which are lit by
2646 * the players light source, which allows the "player_can_see_bold()"
2647 * function to work very quickly.
2649 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2650 * fact, the player (unless blind) can always "see" all grids which are
2651 * marked as "CAVE_LITE", unless they are "off screen".
2654 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2655 * grid and maintains an array of all "CAVE_VIEW" grids.
2657 * This set of grids is the complete set of all grids within line of sight
2658 * of the player, allowing the "player_has_los_bold()" macro to work very
2662 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2663 * temporary internal flag to mark those grids which are not only in view,
2664 * but which are also "easily" in line of sight of the player. This flag
2665 * is always cleared when we are done.
2668 * The current "update_lite()" and "update_view()" algorithms use the
2669 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2670 * to keep track of which grids were previously marked as "CAVE_LITE" or
2671 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2673 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2674 * for various other purposes, such as spreading lite or darkness during
2675 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2678 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2679 * in some way permanently lit. However, for the player to "see" anything
2680 * in the grid, as determined by "player_can_see()", the player must not be
2681 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2682 * grids, even if marked as "perma lit", are only illuminated if they touch
2683 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2686 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2687 * that even if the player cannot "see" the grid, he "knows" the terrain in
2688 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2689 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2690 * or when one of the "memorize floor grids" options induces memorization.
2692 * Objects are "memorized" in a different way, using a special "marked" flag
2693 * on the object itself, which is set when an object is observed or detected.
2696 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2697 * and should be illuminated by "lite room" and "darkness" spells.
2700 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2701 * and should be unavailable for "teleportation" destinations.
2704 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2705 * which is observed, and the "view_torch_grids" allows the player to memorize
2706 * every torch-lit grid. The player will always memorize important walls,
2707 * doors, stairs, and other terrain features, as well as any "detected" grids.
2709 * Note that the new "update_view()" method allows, among other things, a room
2710 * to be "partially" seen as the player approaches it, with a growing cone of
2711 * floor appearing as the player gets closer to the door. Also, by not turning
2712 * on the "memorize perma-lit grids" option, the player will only "see" those
2713 * floor grids which are actually in line of sight.
2715 * And my favorite "plus" is that you can now use a special option to draw the
2716 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2717 * grids dimly), providing a "pretty" effect as the player runs around, and
2718 * to efficiently display the "torch lite" in a special color.
2721 * Some comments on the "update_view()" algorithm...
2723 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2724 * and only has to call "los()" on the borderline cases. The major axes/diags
2725 * even terminate early when they hit walls. I need to find a quick way
2726 * to "terminate" the other scans.
2728 * Note that in the worst case (a big empty area with say 5% scattered walls),
2729 * each of the 1500 or so nearby grids is checked once, most of them getting
2730 * an "instant" rating, and only a small portion requiring a call to "los()".
2732 * The only time that the algorithm appears to be "noticeably" too slow is
2733 * when running, and this is usually only important in town, since the town
2734 * provides about the worst scenario possible, with large open regions and
2735 * a few scattered obstructions. There is a special "efficiency" option to
2736 * allow the player to reduce his field of view in town, if needed.
2738 * In the "best" case (say, a normal stretch of corridor), the algorithm
2739 * makes one check for each viewable grid, and makes no calls to "los()".
2740 * So running in corridors is very fast, and if a lot of monsters are
2741 * nearby, it is much faster than the old methods.
2743 * Note that resting, most normal commands, and several forms of running,
2744 * plus all commands executed near large groups of monsters, are strictly
2745 * more efficient with "update_view()" that with the old "compute los() on
2746 * demand" method, primarily because once the "field of view" has been
2747 * calculated, it does not have to be recalculated until the player moves
2748 * (or a wall or door is created or destroyed).
2750 * Note that we no longer have to do as many "los()" checks, since once the
2751 * "view" region has been built, very few things cause it to be "changed"
2752 * (player movement, and the opening/closing of doors, changes in wall status).
2753 * Note that door/wall changes are only relevant when the door/wall itself is
2754 * in the "view" region.
2756 * The algorithm seems to only call "los()" from zero to ten times, usually
2757 * only when coming down a corridor into a room, or standing in a room, just
2758 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2759 * we will be reducing the calls to "los()".
2761 * I am thinking in terms of an algorithm that "walks" from the central point
2762 * out to the maximal "distance", at each point, determining the "view" code
2763 * (above). For each grid not on a major axis or diagonal, the "view" code
2764 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
2765 * (the one along the nearest diagonal, and the one next to that one, see
2766 * "update_view_aux()"...).
2768 * We "memorize" the viewable space array, so that at the cost of under 3000
2769 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2770 * each grid actually in the "viewable space". And for another 3000 bytes,
2771 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2772 * are also used by other routines, thus reducing the cost to almost nothing.
2774 * A similar thing is done for "forget_lite()" in which case the savings are
2775 * much less, but save us from doing bizarre maintenance checking.
2777 * In the worst "normal" case (in the middle of the town), the reachable space
2778 * actually reaches to more than half of the largest possible "circle" of view,
2779 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2780 * where all the walls have been removed), the reachable space actually reaches
2781 * the theoretical maximum size of just under 1500 grids.
2783 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2784 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2785 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2786 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2787 * entire possible space (including initialization) in one step per grid. If
2788 * we do the "clearing" as a separate step (and use an array of "view" grids),
2789 * then the clearing will take as many steps as grids that were viewed, and the
2790 * algorithm will be able to "stop" scanning at various points.
2791 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2802 * Actually erase the entire "lite" array, redrawing every grid
2804 void forget_lite(void)
2808 /* None to forget */
2809 if (!lite_n) return;
2811 /* Clear them all */
2812 for (i = 0; i < lite_n; i++)
2817 /* Forget "LITE" flag */
2818 cave[y][x].info &= ~(CAVE_LITE);
2821 /* lite_spot(y, x); Perhaps don't need? */
2832 * This macro allows us to efficiently add a grid to the "lite" array,
2833 * note that we are never called for illegal grids, or for grids which
2834 * have already been placed into the "lite" array, and we are never
2835 * called when the "lite" array is full.
2837 #define cave_lite_hack(Y,X) \
2839 if (!(cave[Y][X].info & (CAVE_LITE))) { \
2840 cave[Y][X].info |= (CAVE_LITE); \
2841 lite_y[lite_n] = (Y); \
2842 lite_x[lite_n] = (X); \
2848 * Update the set of grids "illuminated" by the player's lite.
2850 * This routine needs to use the results of "update_view()"
2852 * Note that "blindness" does NOT affect "torch lite". Be careful!
2854 * We optimize most lites (all non-artifact lites) by using "obvious"
2855 * facts about the results of "small" lite radius, and we attempt to
2856 * list the "nearby" grids before the more "distant" ones in the
2857 * array of torch-lit grids.
2859 * We assume that "radius zero" lite is in fact no lite at all.
2861 * Torch Lantern Artifacts
2871 void update_lite(void)
2873 int i, x, y, min_x, max_x, min_y, max_y;
2874 int p = p_ptr->cur_lite;
2876 /*** Special case ***/
2878 /* Hack -- Player has no lite */
2881 /* Forget the old lite */
2884 /* Draw the player */
2889 /*** Save the old "lite" grids for later ***/
2891 /* Clear them all */
2892 for (i = 0; i < lite_n; i++)
2897 /* Mark the grid as not "lite" */
2898 cave[y][x].info &= ~(CAVE_LITE);
2900 /* Mark the grid as "seen" */
2901 cave[y][x].info |= (CAVE_TEMP);
2903 /* Add it to the "seen" set */
2913 /*** Collect the new "lite" grids ***/
2915 /* Radius 1 -- torch radius */
2919 cave_lite_hack(py, px);
2922 cave_lite_hack(py+1, px);
2923 cave_lite_hack(py-1, px);
2924 cave_lite_hack(py, px+1);
2925 cave_lite_hack(py, px-1);
2927 /* Diagonal grids */
2928 cave_lite_hack(py+1, px+1);
2929 cave_lite_hack(py+1, px-1);
2930 cave_lite_hack(py-1, px+1);
2931 cave_lite_hack(py-1, px-1);
2934 /* Radius 2 -- lantern radius */
2937 /* South of the player */
2938 if (cave_floor_bold(py+1, px))
2940 cave_lite_hack(py+2, px);
2941 cave_lite_hack(py+2, px+1);
2942 cave_lite_hack(py+2, px-1);
2945 /* North of the player */
2946 if (cave_floor_bold(py-1, px))
2948 cave_lite_hack(py-2, px);
2949 cave_lite_hack(py-2, px+1);
2950 cave_lite_hack(py-2, px-1);
2953 /* East of the player */
2954 if (cave_floor_bold(py, px+1))
2956 cave_lite_hack(py, px+2);
2957 cave_lite_hack(py+1, px+2);
2958 cave_lite_hack(py-1, px+2);
2961 /* West of the player */
2962 if (cave_floor_bold(py, px-1))
2964 cave_lite_hack(py, px-2);
2965 cave_lite_hack(py+1, px-2);
2966 cave_lite_hack(py-1, px-2);
2970 /* Radius 3+ -- artifact radius */
2975 /* Paranoia -- see "LITE_MAX" */
2978 /* South-East of the player */
2979 if (cave_floor_bold(py+1, px+1))
2981 cave_lite_hack(py+2, px+2);
2984 /* South-West of the player */
2985 if (cave_floor_bold(py+1, px-1))
2987 cave_lite_hack(py+2, px-2);
2990 /* North-East of the player */
2991 if (cave_floor_bold(py-1, px+1))
2993 cave_lite_hack(py-2, px+2);
2996 /* North-West of the player */
2997 if (cave_floor_bold(py-1, px-1))
2999 cave_lite_hack(py-2, px-2);
3004 if (min_y < 0) min_y = 0;
3008 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3012 if (min_x < 0) min_x = 0;
3016 if (max_x > cur_wid-1) max_x = cur_wid-1;
3018 /* Scan the maximal box */
3019 for (y = min_y; y <= max_y; y++)
3021 for (x = min_x; x <= max_x; x++)
3023 int dy = (py > y) ? (py - y) : (y - py);
3024 int dx = (px > x) ? (px - x) : (x - px);
3026 /* Skip the "central" grids (above) */
3027 if ((dy <= 2) && (dx <= 2)) continue;
3029 /* Hack -- approximate the distance */
3030 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3032 /* Skip distant grids */
3033 if (d > p) continue;
3035 /* Viewable, nearby, grids get "torch lit" */
3036 if (player_has_los_bold(y, x))
3038 /* This grid is "torch lit" */
3039 cave_lite_hack(y, x);
3046 /*** Complete the algorithm ***/
3048 /* Draw the new grids */
3049 for (i = 0; i < lite_n; i++)
3054 /* Update fresh grids */
3055 if (cave[y][x].info & (CAVE_TEMP)) continue;
3064 /* Clear them all */
3065 for (i = 0; i < temp_n; i++)
3070 /* No longer in the array */
3071 cave[y][x].info &= ~(CAVE_TEMP);
3073 /* Update stale grids */
3074 if (cave[y][x].info & (CAVE_LITE)) continue;
3085 static bool mon_invis;
3088 * Add a square to the changes array
3090 static void mon_lite_hack(int y, int x)
3095 if (!in_bounds2(y, x)) return;
3097 c_ptr = &cave[y][x];
3099 /* Want a unlit square in view of the player */
3100 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3102 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3103 if (!cave_floor_grid(c_ptr) && mon_invis) return;
3105 /* Save this square */
3106 if (temp_n < TEMP_MAX)
3114 c_ptr->info |= CAVE_MNLT;
3121 * Update squares illuminated by monsters.
3123 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3124 * denote squares illuminated by monsters.
3126 * The CAVE_TEMP flag is used to store the state during the
3127 * updating. Only squares in view of the player, whos state
3128 * changes are drawn via lite_spot().
3130 void update_mon_lite(void)
3139 /* Clear all monster lit squares */
3140 for (i = 0; i < mon_lite_n; i++)
3143 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3146 c_ptr->info |= (CAVE_TEMP);
3148 /* Clear monster illumination flag */
3149 c_ptr->info &= ~(CAVE_MNLT);
3152 /* Empty temp list of new squares to lite up */
3155 /* Loop through monsters, adding newly lit squares to changes list */
3156 for (i = 1; i < m_max; i++)
3158 monster_type *m_ptr = &m_list[i];
3159 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3161 /* Skip dead monsters */
3162 if (!m_ptr->r_idx) continue;
3164 /* Is it too far away? */
3165 if (m_ptr->cdis > ((d_info[dungeon_type].flags1 & DF1_DARKNESS) ? MAX_SIGHT / 2 + 1 : MAX_SIGHT + 3)) continue;
3167 /* Get lite radius */
3170 /* Note the radii are cumulative */
3171 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3172 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3174 /* Exit if has no light */
3176 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3178 if (world_monster) continue;
3180 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3182 /* Access the location */
3186 /* Is the monster visible? */
3187 mon_invis = !(cave[fy][fx].info & CAVE_VIEW);
3189 /* The square it is on */
3190 mon_lite_hack(fy, fx);
3192 /* Adjacent squares */
3193 mon_lite_hack(fy + 1, fx);
3194 mon_lite_hack(fy - 1, fx);
3195 mon_lite_hack(fy, fx + 1);
3196 mon_lite_hack(fy, fx - 1);
3197 mon_lite_hack(fy + 1, fx + 1);
3198 mon_lite_hack(fy + 1, fx - 1);
3199 mon_lite_hack(fy - 1, fx + 1);
3200 mon_lite_hack(fy - 1, fx - 1);
3205 /* South of the monster */
3206 if (cave_floor_bold(fy + 1, fx))
3208 mon_lite_hack(fy + 2, fx + 1);
3209 mon_lite_hack(fy + 2, fx);
3210 mon_lite_hack(fy + 2, fx - 1);
3212 c_ptr = &cave[fy + 2][fx];
3215 if ((rad == 3) && cave_floor_grid(c_ptr))
3217 mon_lite_hack(fy + 3, fx + 1);
3218 mon_lite_hack(fy + 3, fx);
3219 mon_lite_hack(fy + 3, fx - 1);
3223 /* North of the monster */
3224 if (cave_floor_bold(fy - 1, fx))
3226 mon_lite_hack(fy - 2, fx + 1);
3227 mon_lite_hack(fy - 2, fx);
3228 mon_lite_hack(fy - 2, fx - 1);
3230 c_ptr = &cave[fy - 2][fx];
3233 if ((rad == 3) && cave_floor_grid(c_ptr))
3235 mon_lite_hack(fy - 3, fx + 1);
3236 mon_lite_hack(fy - 3, fx);
3237 mon_lite_hack(fy - 3, fx - 1);
3241 /* East of the monster */
3242 if (cave_floor_bold(fy, fx + 1))
3244 mon_lite_hack(fy + 1, fx + 2);
3245 mon_lite_hack(fy, fx + 2);
3246 mon_lite_hack(fy - 1, fx + 2);
3248 c_ptr = &cave[fy][fx + 2];
3251 if ((rad == 3) && cave_floor_grid(c_ptr))
3253 mon_lite_hack(fy + 1, fx + 3);
3254 mon_lite_hack(fy, fx + 3);
3255 mon_lite_hack(fy - 1, fx + 3);
3259 /* West of the monster */
3260 if (cave_floor_bold(fy, fx - 1))
3262 mon_lite_hack(fy + 1, fx - 2);
3263 mon_lite_hack(fy, fx - 2);
3264 mon_lite_hack(fy - 1, fx - 2);
3266 c_ptr = &cave[fy][fx - 2];
3269 if ((rad == 3) && cave_floor_grid(c_ptr))
3271 mon_lite_hack(fy + 1, fx - 3);
3272 mon_lite_hack(fy, fx - 3);
3273 mon_lite_hack(fy - 1, fx - 3);
3281 /* South-East of the monster */
3282 if (cave_floor_bold(fy + 1, fx + 1))
3284 mon_lite_hack(fy + 2, fx + 2);
3287 /* South-West of the monster */
3288 if (cave_floor_bold(fy + 1, fx - 1))
3290 mon_lite_hack(fy + 2, fx - 2);
3293 /* North-East of the monster */
3294 if (cave_floor_bold(fy - 1, fx + 1))
3296 mon_lite_hack(fy - 2, fx + 2);
3299 /* North-West of the monster */
3300 if (cave_floor_bold(fy - 1, fx - 1))
3302 mon_lite_hack(fy - 2, fx - 2);
3307 /* Save end of list of new squares */
3311 * Look at old set flags to see if there are any changes.
3313 for (i = 0; i < mon_lite_n; i++)
3318 if (!in_bounds2(fy, fx)) continue;
3321 c_ptr = &cave[fy][fx];
3323 /* It it no longer lit? */
3324 if (!(c_ptr->info & CAVE_MNLT) && player_has_los_grid(c_ptr))
3326 /* It is now unlit */
3331 /* Add to end of temp array */
3332 temp_x[temp_n] = (byte)fx;
3333 temp_y[temp_n] = (byte)fy;
3337 /* Clear the lite array */
3340 /* Copy the temp array into the lit array lighting the new squares. */
3341 for (i = 0; i < temp_n; i++)
3346 if (!in_bounds2(fy, fx)) continue;
3349 c_ptr = &cave[fy][fx];
3353 /* Clear the temp flag for the old lit grids */
3354 c_ptr->info &= ~(CAVE_TEMP);
3358 /* The is the square newly lit and visible? */
3359 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3366 /* Save in the monster lit array */
3367 mon_lite_x[mon_lite_n] = fx;
3368 mon_lite_y[mon_lite_n] = fy;
3373 /* Finished with temp_n */
3376 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3378 if (p_ptr->special_defense & NINJA_S_STEALTH)
3380 if (p_ptr->old_monlite != p_ptr->monlite)
3385 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3387 msg_print("Your mantle of shadow become thin.");
3393 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3395 msg_print("Your mantle of shadow restored its original darkness.");
3400 p_ptr->old_monlite = p_ptr->monlite;
3403 void clear_mon_lite(void)
3408 /* Clear all monster lit squares */
3409 for (i = 0; i < mon_lite_n; i++)
3412 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3414 /* Clear monster illumination flag */
3415 c_ptr->info &= ~(CAVE_MNLT);
3418 /* Empty the array */
3425 * Clear the viewable space
3427 void forget_view(void)
3433 /* None to forget */
3434 if (!view_n) return;
3436 /* Clear them all */
3437 for (i = 0; i < view_n; i++)
3442 /* Access the grid */
3443 c_ptr = &cave[y][x];
3445 /* Forget that the grid is viewable */
3446 c_ptr->info &= ~(CAVE_VIEW);
3448 if (!panel_contains(y, x)) continue;
3450 /* Update the screen */
3451 /* lite_spot(y, x); Perhaps don't need? */
3461 * This macro allows us to efficiently add a grid to the "view" array,
3462 * note that we are never called for illegal grids, or for grids which
3463 * have already been placed into the "view" array, and we are never
3464 * called when the "view" array is full.
3466 #define cave_view_hack(C,Y,X) \
3468 if (!((C)->info & (CAVE_VIEW))){\
3469 (C)->info |= (CAVE_VIEW); \
3470 view_y[view_n] = (Y); \
3471 view_x[view_n] = (X); \
3478 * Helper function for "update_view()" below
3480 * We are checking the "viewability" of grid (y,x) by the player.
3482 * This function assumes that (y,x) is legal (i.e. on the map).
3484 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3485 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3487 * Note that we are using the "CAVE_XTRA" field for marking grids as
3488 * "easily viewable". This bit is cleared at the end of "update_view()".
3490 * This function adds (y,x) to the "viewable set" if necessary.
3492 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3494 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3496 bool f1, f2, v1, v2, z1, z2, wall;
3500 cave_type *g1_c_ptr;
3501 cave_type *g2_c_ptr;
3503 /* Access the grids */
3504 g1_c_ptr = &cave[y1][x1];
3505 g2_c_ptr = &cave[y2][x2];
3508 /* Check for walls */
3509 f1 = (cave_floor_grid(g1_c_ptr));
3510 f2 = (cave_floor_grid(g2_c_ptr));
3512 /* Totally blocked by physical walls */
3513 if (!f1 && !f2) return (TRUE);
3516 /* Check for visibility */
3517 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3518 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3520 /* Totally blocked by "unviewable neighbors" */
3521 if (!v1 && !v2) return (TRUE);
3524 /* Access the grid */
3525 c_ptr = &cave[y][x];
3528 /* Check for walls */
3529 wall = (!cave_floor_grid(c_ptr));
3532 /* Check the "ease" of visibility */
3533 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3534 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3536 /* Hack -- "easy" plus "easy" yields "easy" */
3539 c_ptr->info |= (CAVE_XTRA);
3541 cave_view_hack(c_ptr, y, x);
3546 /* Hack -- primary "easy" yields "viewed" */
3549 cave_view_hack(c_ptr, y, x);
3554 /* Hack -- "view" plus "view" yields "view" */
3557 /* c_ptr->info |= (CAVE_XTRA); */
3559 cave_view_hack(c_ptr, y, x);
3565 /* Mega-Hack -- the "los()" function works poorly on walls */
3568 cave_view_hack(c_ptr, y, x);
3574 /* Hack -- check line of sight */
3575 if (los(py, px, y, x))
3577 cave_view_hack(c_ptr, y, x);
3583 /* Assume no line of sight. */
3590 * Calculate the viewable space
3592 * 1: Process the player
3593 * 1a: The player is always (easily) viewable
3594 * 2: Process the diagonals
3595 * 2a: The diagonals are (easily) viewable up to the first wall
3596 * 2b: But never go more than 2/3 of the "full" distance
3597 * 3: Process the main axes
3598 * 3a: The main axes are (easily) viewable up to the first wall
3599 * 3b: But never go more than the "full" distance
3600 * 4: Process sequential "strips" in each of the eight octants
3601 * 4a: Each strip runs along the previous strip
3602 * 4b: The main axes are "previous" to the first strip
3603 * 4c: Process both "sides" of each "direction" of each strip
3604 * 4c1: Each side aborts as soon as possible
3605 * 4c2: Each side tells the next strip how far it has to check
3607 * Note that the octant processing involves some pretty interesting
3608 * observations involving when a grid might possibly be viewable from
3609 * a given grid, and on the order in which the strips are processed.
3611 * Note the use of the mathematical facts shown below, which derive
3612 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3613 * hypotenuse of a right triangle is primarily determined by the length
3614 * of the longest side, when one side is small, and is strictly less
3615 * than one-and-a-half times as long as the longest side when both of
3616 * the sides are large.
3618 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3619 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3621 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3623 * These observations are important because the calculation of the actual
3624 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3625 * while for small values (up to about 20 or so), the approximations above
3626 * are correct to within an error of at most one grid or so.
3628 * Observe the use of "full" and "over" in the code below, and the use of
3629 * the specialized calculation involving "limit", all of which derive from
3630 * the observations given above. Basically, we note that the "circle" of
3631 * view is completely contained in an "octagon" whose bounds are easy to
3632 * determine, and that only a few steps are needed to derive the actual
3633 * bounds of the circle given the bounds of the octagon.
3635 * Note that by skipping all the grids in the corners of the octagon, we
3636 * place an upper limit on the number of grids in the field of view, given
3637 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3638 * view, only about 1475 of these are in the "octagon" of view, and even
3639 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3640 * entries to completely contain the actual field of view.
3642 * Note also the care taken to prevent "running off the map". The use of
3643 * explicit checks on the "validity" of the "diagonal", and the fact that
3644 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3645 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3646 * of multiple checks on the validity of grids.
3648 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3649 * "ws","wn" variables. They work like this: While travelling down the
3650 * south-bound strip just to the east of the main south axis, as soon as
3651 * we get to a grid which does not "transmit" viewing, if all of the strips
3652 * preceding us (in this case, just the main axis) had terminated at or before
3653 * the same point, then we can stop, and reset the "max distance" to ourself.
3654 * So, each strip (named by major axis plus offset, thus "se" in this case)
3655 * maintains a "blockage" variable, initialized during the main axis step,
3656 * and checks it whenever a blockage is observed. After processing each
3657 * strip as far as the previous strip told us to process, the next strip is
3658 * told not to go farther than the current strip's farthest viewable grid,
3659 * unless open space is still available. This uses the "k" variable.
3661 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3662 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3663 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3664 * chunk of code which adds the given location to the "view" array if it
3665 * is not already there, using both the actual location and a pointer to
3666 * the cave grid. See above.
3668 * By the way, the purpose of this code is to reduce the dependancy on the
3669 * "los()" function which is slow, and, in some cases, not very accurate.
3671 * It is very possible that I am the only person who fully understands this
3672 * function, and for that I am truly sorry, but efficiency was very important
3673 * and the "simple" version of this function was just not fast enough. I am
3674 * more than willing to replace this function with a simpler one, if it is
3675 * equally efficient, and especially willing if the new function happens to
3676 * derive "reverse-line-of-sight" at the same time, since currently monsters
3677 * just use an optimized hack of "you see me, so I see you", and then use the
3678 * actual "projectable()" function to check spell attacks.
3680 void update_view(void)
3682 int n, m, d, k, y, x, z;
3684 int se, sw, ne, nw, es, en, ws, wn;
3688 int y_max = cur_hgt - 1;
3689 int x_max = cur_wid - 1;
3693 /*** Initialize ***/
3696 if (view_reduce_view && !dun_level)
3698 /* Full radius (10) */
3699 full = MAX_SIGHT / 2;
3701 /* Octagon factor (15) */
3702 over = MAX_SIGHT * 3 / 4;
3708 /* Full radius (20) */
3711 /* Octagon factor (30) */
3712 over = MAX_SIGHT * 3 / 2;
3716 /*** Step 0 -- Begin ***/
3718 /* Save the old "view" grids for later */
3719 for (n = 0; n < view_n; n++)
3724 /* Access the grid */
3725 c_ptr = &cave[y][x];
3727 /* Mark the grid as not in "view" */
3728 c_ptr->info &= ~(CAVE_VIEW);
3730 /* Mark the grid as "seen" */
3731 c_ptr->info |= (CAVE_TEMP);
3733 /* Add it to the "seen" set */
3739 /* Start over with the "view" array */
3742 /*** Step 1 -- adjacent grids ***/
3744 /* Now start on the player */
3748 /* Access the grid */
3749 c_ptr = &cave[y][x];
3751 /* Assume the player grid is easily viewable */
3752 c_ptr->info |= (CAVE_XTRA);
3754 /* Assume the player grid is viewable */
3755 cave_view_hack(c_ptr, y, x);
3758 /*** Step 2 -- Major Diagonals ***/
3763 /* Scan south-east */
3764 for (d = 1; d <= z; d++)
3766 c_ptr = &cave[y+d][x+d];
3767 c_ptr->info |= (CAVE_XTRA);
3768 cave_view_hack(c_ptr, y+d, x+d);
3769 if (!cave_floor_grid(c_ptr)) break;
3772 /* Scan south-west */
3773 for (d = 1; d <= z; d++)
3775 c_ptr = &cave[y+d][x-d];
3776 c_ptr->info |= (CAVE_XTRA);
3777 cave_view_hack(c_ptr, y+d, x-d);
3778 if (!cave_floor_grid(c_ptr)) break;
3781 /* Scan north-east */
3782 for (d = 1; d <= z; d++)
3784 c_ptr = &cave[y-d][x+d];
3785 c_ptr->info |= (CAVE_XTRA);
3786 cave_view_hack(c_ptr, y-d, x+d);
3787 if (!cave_floor_grid(c_ptr)) break;
3790 /* Scan north-west */
3791 for (d = 1; d <= z; d++)
3793 c_ptr = &cave[y-d][x-d];
3794 c_ptr->info |= (CAVE_XTRA);
3795 cave_view_hack(c_ptr, y-d, x-d);
3796 if (!cave_floor_grid(c_ptr)) break;
3800 /*** Step 3 -- major axes ***/
3803 for (d = 1; d <= full; d++)
3805 c_ptr = &cave[y+d][x];
3806 c_ptr->info |= (CAVE_XTRA);
3807 cave_view_hack(c_ptr, y+d, x);
3808 if (!cave_floor_grid(c_ptr)) break;
3811 /* Initialize the "south strips" */
3815 for (d = 1; d <= full; d++)
3817 c_ptr = &cave[y-d][x];
3818 c_ptr->info |= (CAVE_XTRA);
3819 cave_view_hack(c_ptr, y-d, x);
3820 if (!cave_floor_grid(c_ptr)) break;
3823 /* Initialize the "north strips" */
3827 for (d = 1; d <= full; d++)
3829 c_ptr = &cave[y][x+d];
3830 c_ptr->info |= (CAVE_XTRA);
3831 cave_view_hack(c_ptr, y, x+d);
3832 if (!cave_floor_grid(c_ptr)) break;
3835 /* Initialize the "east strips" */
3839 for (d = 1; d <= full; d++)
3841 c_ptr = &cave[y][x-d];
3842 c_ptr->info |= (CAVE_XTRA);
3843 cave_view_hack(c_ptr, y, x-d);
3844 if (!cave_floor_grid(c_ptr)) break;
3847 /* Initialize the "west strips" */
3851 /*** Step 4 -- Divide each "octant" into "strips" ***/
3853 /* Now check each "diagonal" (in parallel) */
3854 for (n = 1; n <= over / 2; n++)
3856 int ypn, ymn, xpn, xmn;
3859 /* Acquire the "bounds" of the maximal circle */
3861 if (z > full - n) z = full - n;
3862 while ((z + n + (n>>1)) > full) z--;
3865 /* Access the four diagonal grids */
3875 /* Maximum distance */
3876 m = MIN(z, y_max - ypn);
3879 if ((xpn <= x_max) && (n < se))
3882 for (k = n, d = 1; d <= m; d++)
3884 /* Check grid "d" in strip "n", notice "blockage" */
3885 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3887 if (n + d >= se) break;
3890 /* Track most distant "non-blockage" */
3897 /* Limit the next strip */
3902 if ((xmn >= 0) && (n < sw))
3905 for (k = n, d = 1; d <= m; d++)
3907 /* Check grid "d" in strip "n", notice "blockage" */
3908 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3910 if (n + d >= sw) break;
3913 /* Track most distant "non-blockage" */
3920 /* Limit the next strip */
3929 /* Maximum distance */
3933 if ((xpn <= x_max) && (n < ne))
3936 for (k = n, d = 1; d <= m; d++)
3938 /* Check grid "d" in strip "n", notice "blockage" */
3939 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3941 if (n + d >= ne) break;
3944 /* Track most distant "non-blockage" */
3951 /* Limit the next strip */
3956 if ((xmn >= 0) && (n < nw))
3959 for (k = n, d = 1; d <= m; d++)
3961 /* Check grid "d" in strip "n", notice "blockage" */
3962 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
3964 if (n + d >= nw) break;
3967 /* Track most distant "non-blockage" */
3974 /* Limit the next strip */
3983 /* Maximum distance */
3984 m = MIN(z, x_max - xpn);
3987 if ((ypn <= x_max) && (n < es))
3990 for (k = n, d = 1; d <= m; d++)
3992 /* Check grid "d" in strip "n", notice "blockage" */
3993 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
3995 if (n + d >= es) break;
3998 /* Track most distant "non-blockage" */
4005 /* Limit the next strip */
4010 if ((ymn >= 0) && (n < en))
4013 for (k = n, d = 1; d <= m; d++)
4015 /* Check grid "d" in strip "n", notice "blockage" */
4016 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4018 if (n + d >= en) break;
4021 /* Track most distant "non-blockage" */
4028 /* Limit the next strip */
4037 /* Maximum distance */
4041 if ((ypn <= y_max) && (n < ws))
4044 for (k = n, d = 1; d <= m; d++)
4046 /* Check grid "d" in strip "n", notice "blockage" */
4047 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4049 if (n + d >= ws) break;
4052 /* Track most distant "non-blockage" */
4059 /* Limit the next strip */
4064 if ((ymn >= 0) && (n < wn))
4067 for (k = n, d = 1; d <= m; d++)
4069 /* Check grid "d" in strip "n", notice "blockage" */
4070 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4072 if (n + d >= wn) break;
4075 /* Track most distant "non-blockage" */
4082 /* Limit the next strip */
4089 /*** Step 5 -- Complete the algorithm ***/
4091 /* Update all the new grids */
4092 for (n = 0; n < view_n; n++)
4097 /* Access the grid */
4098 c_ptr = &cave[y][x];
4100 /* Clear the "CAVE_XTRA" flag */
4101 c_ptr->info &= ~(CAVE_XTRA);
4103 /* Update only newly viewed grids */
4104 if (c_ptr->info & (CAVE_TEMP)) continue;
4113 /* Wipe the old grids, update as needed */
4114 for (n = 0; n < temp_n; n++)
4119 /* Access the grid */
4120 c_ptr = &cave[y][x];
4122 /* No longer in the array */
4123 c_ptr->info &= ~(CAVE_TEMP);
4125 /* Update only non-viewable grids */
4126 if (c_ptr->info & (CAVE_VIEW)) continue;
4139 * Hack -- forget the "flow" information
4141 void forget_flow(void)
4145 /* Check the entire dungeon */
4146 for (y = 0; y < cur_hgt; y++)
4148 for (x = 0; x < cur_wid; x++)
4150 /* Forget the old data */
4151 cave[y][x].dist = 0;
4152 cave[y][x].cost = 0;
4153 cave[y][x].when = 0;
4160 * Hack - speed up the update_flow algorithm by only doing
4161 * it everytime the player moves out of LOS of the last
4164 static u16b flow_x = 0;
4165 static u16b flow_y = 0;
4170 * Hack -- fill in the "cost" field of every grid that the player
4171 * can "reach" with the number of steps needed to reach that grid.
4172 * This also yields the "distance" of the player from every grid.
4174 * In addition, mark the "when" of the grids that can reach
4175 * the player with the incremented value of "flow_n".
4177 * Hack -- use the "seen" array as a "circular queue".
4179 * We do not need a priority queue because the cost from grid
4180 * to grid is always "one" and we process them in order.
4182 void update_flow(void)
4188 /* Paranoia -- make sure the array is empty */
4191 /* The last way-point is on the map */
4192 if (running && in_bounds(flow_y, flow_x))
4194 /* The way point is in sight - do not update. (Speedup) */
4195 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4198 /* Erase all of the current flow information */
4199 for (y = 0; y < cur_hgt; y++)
4201 for (x = 0; x < cur_wid; x++)
4203 cave[y][x].cost = 0;
4204 cave[y][x].dist = 0;
4208 /* Save player position */
4212 /* Add the player's grid to the queue */
4216 /* Now process the queue */
4217 while (flow_head != flow_tail)
4221 /* Extract the next entry */
4222 ty = temp_y[flow_tail];
4223 tx = temp_x[flow_tail];
4225 /* Forget that entry */
4226 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4228 /* Add the "children" */
4229 for (d = 0; d < 8; d++)
4231 int old_head = flow_head;
4232 int m = cave[ty][tx].cost + 1;
4233 int n = cave[ty][tx].dist + 1;
4236 /* Child location */
4237 y = ty + ddy_ddd[d];
4238 x = tx + ddx_ddd[d];
4240 /* Ignore player's grid */
4241 if (x == px && y == py) continue;
4243 c_ptr = &cave[y][x];
4245 if (is_closed_door(c_ptr->feat)) m += 3;
4247 /* Ignore "pre-stamped" entries */
4248 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4250 /* Ignore "walls" and "rubble" */
4251 if ((c_ptr->feat >= FEAT_RUBBLE) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4253 /* Save the flow cost */
4254 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4255 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4257 /* Hack -- limit flow depth */
4258 if (n == MONSTER_FLOW_DEPTH) continue;
4260 /* Enqueue that entry */
4261 temp_y[flow_head] = y;
4262 temp_x[flow_head] = x;
4264 /* Advance the queue */
4265 if (++flow_head == TEMP_MAX) flow_head = 0;
4267 /* Hack -- notice overflow by forgetting new entry */
4268 if (flow_head == flow_tail) flow_head = old_head;
4274 static int scent_when = 0;
4277 * Characters leave scent trails for perceptive monsters to track.
4279 * Smell is rather more limited than sound. Many creatures cannot use
4280 * it at all, it doesn't extend very far outwards from the character's
4281 * current position, and monsters can use it to home in the character,
4282 * but not to run away from him.
4284 * Smell is valued according to age. When a character takes his turn,
4285 * scent is aged by one, and new scent of the current age is laid down.
4286 * Speedy characters leave more scent, true, but it also ages faster,
4287 * which makes it harder to hunt them down.
4289 * Whenever the age count loops, most of the scent trail is erased and
4290 * the age of the remainder is recalculated.
4292 void update_smell(void)
4297 /* Create a table that controls the spread of scent */
4298 const int scent_adjust[5][5] =
4307 /* Loop the age and adjust scent values when necessary */
4308 if (++scent_when == 254)
4310 /* Scan the entire dungeon */
4311 for (y = 0; y < cur_hgt; y++)
4313 for (x = 0; x < cur_wid; x++)
4315 int w = cave[y][x].when;
4316 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4325 /* Lay down new scent */
4326 for (i = 0; i < 5; i++)
4328 for (j = 0; j < 5; j++)
4332 /* Translate table to map grids */
4337 if (!in_bounds(y, x)) continue;
4339 c_ptr = &cave[y][x];
4341 /* Walls, water, and lava cannot hold scent. */
4342 if ((c_ptr->feat >= FEAT_RUBBLE) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4344 /* Grid must not be blocked by walls from the character */
4345 if (!player_has_los_bold(y, x)) continue;
4347 /* Note grids that are too far away */
4348 if (scent_adjust[i][j] == -1) continue;
4350 /* Mark the grid with new scent */
4351 c_ptr->when = scent_when + scent_adjust[i][j];
4358 * Hack -- map the current panel (plus some) ala "magic mapping"
4360 void map_area(int range)
4368 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4370 /* Scan that area */
4371 for (y = 1; y < cur_hgt - 1; y++)
4373 for (x = 1; x < cur_wid - 1; x++)
4375 if (distance(py, px, y, x) > range) continue;
4377 c_ptr = &cave[y][x];
4379 /* Feature code (applying "mimic" field) */
4380 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4382 /* All non-walls are "checked" */
4383 if ((feat <= FEAT_DOOR_TAIL) ||
4384 (feat == FEAT_RUBBLE) ||
4385 ((feat >= FEAT_MINOR_GLYPH) &&
4386 (feat <= FEAT_TREES)) ||
4387 (feat >= FEAT_TOWN))
4389 /* Memorize normal features */
4390 if ((feat > FEAT_INVIS) && (feat != FEAT_DIRT) && (feat != FEAT_GRASS))
4392 /* Memorize the object */
4393 c_ptr->info |= (CAVE_MARK);
4396 /* Memorize known walls */
4397 for (i = 0; i < 8; i++)
4399 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4401 /* Feature code (applying "mimic" field) */
4402 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4404 /* Memorize walls (etc) */
4405 if ((feat >= FEAT_RUBBLE) && (feat != FEAT_DIRT) && (feat != FEAT_GRASS))
4407 /* Memorize the walls */
4408 c_ptr->info |= (CAVE_MARK);
4416 p_ptr->redraw |= (PR_MAP);
4419 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4425 * Light up the dungeon using "clairvoyance"
4427 * This function "illuminates" every grid in the dungeon, memorizes all
4428 * "objects", memorizes all grids as with magic mapping, and, under the
4429 * standard option settings (view_perma_grids but not view_torch_grids)
4430 * memorizes all floor grids too.
4432 * Note that if "view_perma_grids" is not set, we do not memorize floor
4433 * grids, since this would defeat the purpose of "view_perma_grids", not
4434 * that anyone seems to play without this option.
4436 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4437 * since this would prevent the use of "view_torch_grids" as a method to
4438 * keep track of what grids have been observed directly.
4440 void wiz_lite(bool ninja)
4445 /* Memorize objects */
4446 for (i = 1; i < o_max; i++)
4448 object_type *o_ptr = &o_list[i];
4450 /* Skip dead objects */
4451 if (!o_ptr->k_idx) continue;
4453 /* Skip held objects */
4454 if (o_ptr->held_m_idx) continue;
4457 o_ptr->marked |= OM_FOUND;
4460 /* Scan all normal grids */
4461 for (y = 1; y < cur_hgt - 1; y++)
4463 /* Scan all normal grids */
4464 for (x = 1; x < cur_wid - 1; x++)
4466 cave_type *c_ptr = &cave[y][x];
4468 /* Feature code (applying "mimic" field) */
4469 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4471 /* Process all non-walls */
4472 if (cave_floor_bold(y, x) || (feat == FEAT_RUBBLE) || (feat == FEAT_TREES) || (feat == FEAT_MOUNTAIN))
4474 /* Scan all neighbors */
4475 for (i = 0; i < 9; i++)
4477 int yy = y + ddy_ddd[i];
4478 int xx = x + ddx_ddd[i];
4481 c_ptr = &cave[yy][xx];
4483 /* Feature code (applying "mimic" field) */
4484 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4486 /* Memorize normal features */
4489 /* Memorize the grid */
4490 c_ptr->info |= (CAVE_MARK);
4494 if ((feat > FEAT_INVIS))
4496 /* Memorize the grid */
4497 c_ptr->info |= (CAVE_MARK);
4500 /* Perma-lite the grid */
4501 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4503 c_ptr->info |= (CAVE_GLOW);
4505 /* Normally, memorize floors (see above) */
4506 if (view_perma_grids && !view_torch_grids)
4508 /* Memorize the grid */
4509 c_ptr->info |= (CAVE_MARK);
4518 /* Update the monsters */
4519 p_ptr->update |= (PU_MONSTERS);
4522 p_ptr->redraw |= (PR_MAP);
4525 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4530 * Forget the dungeon map (ala "Thinking of Maud...").
4537 /* Forget every grid */
4538 for (y = 0; y < cur_hgt; y++)
4540 for (x = 0; x < cur_wid; x++)
4542 cave_type *c_ptr = &cave[y][x];
4544 /* Process the grid */
4545 c_ptr->info &= ~(CAVE_MARK);
4549 /* Forget all objects */
4550 for (i = 1; i < o_max; i++)
4552 object_type *o_ptr = &o_list[i];
4554 /* Skip dead objects */
4555 if (!o_ptr->k_idx) continue;
4557 /* Skip held objects */
4558 if (o_ptr->held_m_idx) continue;
4560 /* Forget the object */
4564 /* Mega-Hack -- Forget the view and lite */
4565 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4567 /* Update the view and lite */
4568 p_ptr->update |= (PU_VIEW | PU_LITE);
4570 /* Update the monsters */
4571 p_ptr->update |= (PU_MONSTERS);
4574 p_ptr->redraw |= (PR_MAP);
4577 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4585 * Change the "feat" flag for a grid, and notice/redraw the grid
4587 void cave_set_feat(int y, int x, int feat)
4589 cave_type *c_ptr = &cave[y][x];
4591 /* Clear mimic type */
4594 /* Remove flag for mirror/glyph */
4595 c_ptr->info &= ~(CAVE_OBJECT);
4597 /* Change the feature */
4600 /* Hack -- glow the deep lava */
4601 if ((feat == FEAT_DEEP_LAVA) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4605 for (i = 0; i < 9; i++)
4607 yy = y + ddy_ddd[i];
4608 xx = x + ddx_ddd[i];
4609 if (!in_bounds2(yy, xx)) continue;
4610 cave[yy][xx].info |= CAVE_GLOW;
4611 if (player_has_los_bold(yy, xx))
4629 /* Remove a mirror */
4630 void remove_mirror(int y, int x)
4632 /* Remove the mirror */
4633 cave[y][x].info &= ~(CAVE_OBJECT);
4634 cave[y][x].mimic = 0;
4636 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4638 cave[y][x].info &= ~(CAVE_GLOW);
4639 if( !view_torch_grids )cave[y][x].info &= ~(CAVE_MARK);
4650 * Return TRUE if there is a mirror on the grid.
4652 bool is_mirror_grid(cave_type *c_ptr)
4654 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_MIRROR)
4662 * Return TRUE if there is a mirror on the grid.
4664 bool is_glyph_grid(cave_type *c_ptr)
4666 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_GLYPH)
4674 * Return TRUE if there is a mirror on the grid.
4676 bool is_explosive_rune_grid(cave_type *c_ptr)
4678 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_MINOR_GLYPH)
4686 * Calculate "incremental motion". Used by project() and shoot().
4687 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4689 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4691 int dy, dx, dist, shift;
4693 /* Extract the distance travelled */
4694 dy = (*y < y1) ? y1 - *y : *y - y1;
4695 dx = (*x < x1) ? x1 - *x : *x - x1;
4697 /* Number of steps */
4698 dist = (dy > dx) ? dy : dx;
4700 /* We are calculating the next location */
4704 /* Calculate the total distance along each axis */
4705 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4706 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4708 /* Paranoia -- Hack -- no motion */
4709 if (!dy && !dx) return;
4712 /* Move mostly vertically */
4715 /* Extract a shift factor */
4716 shift = (dist * dx + (dy - 1) / 2) / dy;
4718 /* Sometimes move along the minor axis */
4719 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4721 /* Always move along major axis */
4722 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4725 /* Move mostly horizontally */
4728 /* Extract a shift factor */
4729 shift = (dist * dy + (dx - 1) / 2) / dx;
4731 /* Sometimes move along the minor axis */
4732 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4734 /* Always move along major axis */
4735 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4742 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4743 * at the final destination, assuming no monster gets in the way.
4745 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4747 bool projectable(int y1, int x1, int y2, int x2)
4754 /* Check the projection path */
4755 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4757 /* No grid is ever projectable from itself */
4758 if (!grid_n) return (FALSE);
4761 y = GRID_Y(grid_g[grid_n - 1]);
4762 x = GRID_X(grid_g[grid_n - 1]);
4764 /* May not end in an unrequested grid */
4765 if ((y != y2) || (x != x2)) return (FALSE);
4773 * Standard "find me a location" function
4775 * Obtains a legal location within the given distance of the initial
4776 * location, and with "los()" from the source to destination location.
4778 * This function is often called from inside a loop which searches for
4779 * locations while increasing the "d" distance.
4781 * Currently the "m" parameter is unused.
4783 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4790 /* Pick a location */
4793 /* Pick a new location */
4794 ny = rand_spread(y, d);
4795 nx = rand_spread(x, d);
4797 /* Ignore annoying locations */
4798 if (!in_bounds(ny, nx)) continue;
4800 /* Ignore "excessively distant" locations */
4801 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4803 /* Require "line of sight" */
4804 if (los(y, x, ny, nx)) break;
4807 /* Save the location */
4816 * Track a new monster
4818 void health_track(int m_idx)
4820 /* Mount monster is already tracked */
4821 if (m_idx && m_idx == p_ptr->riding) return;
4823 /* Track a new guy */
4824 p_ptr->health_who = m_idx;
4826 /* Redraw (later) */
4827 p_ptr->redraw |= (PR_HEALTH);
4833 * Hack -- track the given monster race
4835 void monster_race_track(int r_idx)
4837 /* Save this monster ID */
4838 p_ptr->monster_race_idx = r_idx;
4841 p_ptr->window |= (PW_MONSTER);
4847 * Hack -- track the given object kind
4849 void object_kind_track(int k_idx)
4851 /* Save this monster ID */
4852 p_ptr->object_kind_idx = k_idx;
4855 p_ptr->window |= (PW_OBJECT);
4861 * Something has happened to disturb the player.
4863 * The first arg indicates a major disturbance, which affects search.
4865 * The second arg is currently unused, but could induce output flush.
4867 * All disturbance cancels repeated commands, resting, and running.
4869 void disturb(int stop_search, int unused_flag)
4872 unused_flag = unused_flag;
4874 /* Cancel auto-commands */
4875 /* command_new = 0; */
4877 /* Cancel repeated commands */
4883 /* Redraw the state (later) */
4884 p_ptr->redraw |= (PR_STATE);
4887 /* Cancel Resting */
4888 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
4891 set_action(ACTION_NONE);
4894 /* Cancel running */
4900 /* Check for new panel if appropriate */
4901 if (center_player && !center_running) verify_panel();
4903 /* Calculate torch radius */
4904 p_ptr->update |= (PU_TORCH);
4906 /* Update monster flow */
4907 p_ptr->update |= (PU_FLOW);
4910 /* Flush the input if requested */
4911 if (flush_disturb) flush();
4916 * Glow deep lava in the floor
4918 void glow_deep_lava(void)
4920 int y, x, i, yy, xx;
4923 /* Not in the darkness dungeon */
4924 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
4926 for (y = 1; y < cur_hgt - 1; y++)
4928 for (x = 1; x < cur_wid - 1; x++)
4930 c_ptr = &cave[y][x];
4932 if (c_ptr->feat == FEAT_DEEP_LAVA)
4934 for (i = 0; i < 9; i++)
4936 yy = y + ddy_ddd[i];
4937 xx = x + ddx_ddd[i];
4938 cave[yy][xx].info |= CAVE_GLOW;
4939 if (player_has_los_bold(yy, xx)) note_spot(yy, xx);