3 /* Purpose: low level dungeon routines -BEN- */
10 * Support for Adam Bolt's tileset, lighting and transparency effects
11 * by Robert Ruehlmann (rr9@angband.org)
14 static byte display_autopick;
15 static int match_autopick;
16 static object_type *autopick_obj;
17 static int feat_priority;
20 * Distance between two points via Newton-Raphson technique
22 int distance (int y1, int x1, int y2, int x2)
24 int dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
25 int dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
27 /* Squared distance */
28 int target = (dy * dy) + (dx * dx);
30 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
31 int d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
36 if (!dy || !dx) return d;
40 /* Approximate error */
41 err = (target - d * d) / (2 * d);
43 /* No error - we are done */
55 * Return TRUE if the given feature is a trap
57 bool is_trap(int feat)
62 case FEAT_TRAP_TRAPDOOR:
64 case FEAT_TRAP_SPIKED_PIT:
65 case FEAT_TRAP_POISON_PIT:
66 case FEAT_TRAP_TY_CURSE:
67 case FEAT_TRAP_TELEPORT:
71 case FEAT_TRAP_LOSE_STR:
72 case FEAT_TRAP_LOSE_DEX:
73 case FEAT_TRAP_LOSE_CON:
75 case FEAT_TRAP_CONFUSE:
76 case FEAT_TRAP_POISON:
95 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,
96 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.
98 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
100 * The LOS begins at the center of the tile (x1,y1) and ends at the center of
101 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line
102 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
104 * We assume that the "mathematical corner" of a non-floor tile does not
105 * block line of sight.
107 * Because this function uses (short) ints for all calculations, overflow may
108 * occur if dx and dy exceed 90.
110 * Once all the degenerate cases are eliminated, the values "qx", "qy", and
111 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
112 * we can use integer arithmetic.
114 * We travel from start to finish along the longer axis, starting at the border
115 * between the first and second tiles, where the y offset = .5 * slope, taking
116 * into account the scale factor. See below.
118 * Also note that this function and the "move towards target" code do NOT
119 * share the same properties. Thus, you can see someone, target them, and
120 * then fire a bolt at them, but the bolt may hit a wall, not them. However,
121 * by clever choice of target locations, you can sometimes throw a "curve".
123 * Note that "line of sight" is not "reflexive" in all cases.
125 * Use the "projectable()" routine to test "spell/missile line of sight".
127 * Use the "update_view()" function to determine player line-of-sight.
129 bool los(int y1, int x1, int y2, int x2)
149 /* Slope, or 1/Slope, of LOS */
153 /* Extract the offset */
157 /* Extract the absolute offset */
162 /* Handle adjacent (or identical) grids */
163 if ((ax < 2) && (ay < 2)) return (TRUE);
166 /* Paranoia -- require "safe" origin */
167 /* if (!in_bounds(y1, x1)) return (FALSE); */
168 /* if (!in_bounds(y2, x2)) return (FALSE); */
171 /* Directly South/North */
174 /* South -- check for walls */
177 for (ty = y1 + 1; ty < y2; ty++)
179 if (!cave_floor_bold(ty, x1)) return (FALSE);
183 /* North -- check for walls */
186 for (ty = y1 - 1; ty > y2; ty--)
188 if (!cave_floor_bold(ty, x1)) return (FALSE);
196 /* Directly East/West */
199 /* East -- check for walls */
202 for (tx = x1 + 1; tx < x2; tx++)
204 if (!cave_floor_bold(y1, tx)) return (FALSE);
208 /* West -- check for walls */
211 for (tx = x1 - 1; tx > x2; tx--)
213 if (!cave_floor_bold(y1, tx)) return (FALSE);
222 /* Extract some signs */
223 sx = (dx < 0) ? -1 : 1;
224 sy = (dy < 0) ? -1 : 1;
227 /* Vertical "knights" */
232 if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
236 /* Horizontal "knights" */
241 if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
246 /* Calculate scale factor div 2 */
249 /* Calculate scale factor */
253 /* Travel horizontally */
256 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
262 /* Consider the special case where slope == 1. */
273 /* Note (below) the case (qy == f2), where */
274 /* the LOS exactly meets the corner of a tile. */
277 if (!cave_floor_bold(ty, tx)) return (FALSE);
288 if (!cave_floor_bold(ty, tx)) return (FALSE);
301 /* Travel vertically */
304 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
320 /* Note (below) the case (qx == f2), where */
321 /* the LOS exactly meets the corner of a tile. */
324 if (!cave_floor_bold(ty, tx)) return (FALSE);
335 if (!cave_floor_bold(ty, tx)) return (FALSE);
358 * Can the player "see" the given grid in detail?
360 * He must have vision, illumination, and line of sight.
362 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
363 * So, given "CAVE_LITE", we know that the grid is "fully visible".
365 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
366 * that a wall is visible from any direction. That would be odd. Except
367 * under wizard light, which might make sense. Thus, for walls, we require
368 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
369 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
370 * in line of sight of the player.
372 * This extra check is expensive, but it provides a more "correct" semantics.
374 * Note that we should not run this check on walls which are "outer walls" of
375 * the dungeon, or we will induce a memory fault, but actually verifying all
376 * of the locations would be extremely expensive.
378 * Thus, to speed up the function, we assume that all "perma-walls" which are
379 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
380 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
381 * and the player has more important things on his mind when he is attacking a
382 * monster vault. It is annoying, but an extremely important optimization.
384 * Note that "glowing walls" are only considered to be "illuminated" if the
385 * grid which is next to the wall in the direction of the player is also a
386 * "glowing" grid. This prevents the player from being able to "see" the
387 * walls of illuminated rooms from a corridor outside the room.
389 bool player_can_see_bold(int y, int x)
395 /* Blind players see nothing */
396 if (p_ptr->blind) return (FALSE);
398 /* Access the cave grid */
401 /* Note that "torch-lite" yields "illumination" */
402 if (c_ptr->info & (CAVE_LITE)) return (TRUE);
404 /* Require line of sight to the grid */
405 if (!player_has_los_bold(y, x)) return (FALSE);
407 if (p_ptr->pclass == CLASS_NINJA) return TRUE;
409 /* Require "perma-lite" of the grid */
410 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return (FALSE);
412 /* Floors are simple */
413 if (cave_floor_bold(y, x)) return (TRUE);
415 /* Hack -- move towards player */
416 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
417 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
419 /* Check for "local" illumination */
420 if (cave[yy][xx].info & (CAVE_GLOW | CAVE_MNLT))
422 /* Assume the wall is really illuminated */
426 /* Assume not visible */
433 * Returns true if the player's grid is dark
437 return (!player_can_see_bold(py, px));
444 * Determine if a given location may be "destroyed"
446 * Used by destruction spells, and for placing stairs, etc.
448 bool cave_valid_bold(int y, int x)
450 cave_type *c_ptr = &cave[y][x];
452 s16b this_o_idx, next_o_idx = 0;
455 /* Forbid perma-grids */
456 if (cave_perma_grid(c_ptr)) return (FALSE);
459 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
464 o_ptr = &o_list[this_o_idx];
466 /* Acquire next object */
467 next_o_idx = o_ptr->next_o_idx;
469 /* Forbid artifact grids */
470 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
481 * Determine if a given location may be "destroyed"
483 * Used by destruction spells, and for placing stairs, etc.
485 bool cave_valid_grid(cave_type *c_ptr)
487 s16b this_o_idx, next_o_idx = 0;
490 /* Forbid perma-grids */
491 if (cave_perma_grid(c_ptr)) return (FALSE);
494 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
499 o_ptr = &o_list[this_o_idx];
501 /* Acquire next object */
502 next_o_idx = o_ptr->next_o_idx;
504 /* Forbid artifact grids */
505 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
516 * Hack -- Legal monster codes
518 static cptr image_monster_hack = \
519 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
522 * Hack -- Legal monster codes for IBM pseudo-graphics
524 static cptr image_monster_hack_ibm = \
528 * Mega-Hack -- Hallucinatory monster
530 static void image_monster(byte *ap, char *cp)
532 int n = strlen(image_monster_hack);
534 /* Random symbol from set above */
537 /* Normal graphics */
538 if (!(streq(ANGBAND_SYS, "ibm")))
540 (*cp) = r_info[randint1(max_r_idx-1)].x_char;
541 (*ap) = r_info[randint1(max_r_idx-1)].x_attr;
544 /* IBM-pseudo graphics */
546 n = strlen(image_monster_hack_ibm);
547 (*cp) = (image_monster_hack_ibm[randint0(n)]);
550 (*ap) = randint1(15);
556 (*cp) = (image_monster_hack[randint0(n)]);
559 (*ap) = randint1(15);
566 * Hack -- Legal object codes
568 static cptr image_object_hack = \
569 "?/|\\\"!$()_-=[]{},~";
571 static cptr image_object_hack_ibm = \
575 * Mega-Hack -- Hallucinatory object
577 static void image_object(byte *ap, char *cp)
579 int n = strlen(image_object_hack);
583 if (!(streq(ANGBAND_SYS, "ibm")))
585 (*cp) = k_info[randint1(max_k_idx-1)].x_char;
586 (*ap) = k_info[randint1(max_k_idx-1)].x_attr;
590 n = strlen(image_object_hack_ibm);
591 (*cp) = (image_object_hack_ibm[randint0(n)]);
594 (*ap) = randint1(15);
599 (*cp) = (image_object_hack[randint0(n)]);
602 (*ap) = randint1(15);
609 * Hack -- Random hallucination
611 static void image_random(byte *ap, char *cp)
613 /* Normally, assume monsters */
614 if (randint0(100) < 75)
616 image_monster(ap, cp);
619 /* Otherwise, assume objects */
622 image_object(ap, cp);
627 * Not using graphical tiles for this feature?
629 #define is_ascii_graphics(C , A) \
630 (!(((C) & 0x80) && ((A) & 0x80)))
633 * The 16x16 tile of the terrain supports lighting
635 static bool feat_supports_lighting(byte feat)
637 if (is_trap(feat)) return streq(ANGBAND_GRAF, "new");
656 case FEAT_WALL_EXTRA:
657 case FEAT_WALL_INNER:
658 case FEAT_WALL_OUTER:
659 case FEAT_WALL_SOLID:
660 case FEAT_PERM_EXTRA:
661 case FEAT_PERM_INNER:
662 case FEAT_PERM_OUTER:
663 case FEAT_PERM_SOLID:
664 case FEAT_MINOR_GLYPH:
665 case FEAT_DEEP_WATER:
666 case FEAT_SHAL_WATER:
673 case FEAT_DEEP_GRASS:
684 * This array lists the effects of "brightness" on various "base" colours.
686 * This is used to do dynamic lighting effects in ascii :-)
687 * At the moment, only the various "floor" tiles are affected.
689 * The layout of the array is [x][0] = light and [x][1] = dark.
692 static byte lighting_colours[16][2] =
695 {TERM_L_DARK, TERM_DARK},
698 {TERM_YELLOW, TERM_SLATE},
701 {TERM_WHITE, TERM_L_DARK},
704 {TERM_L_UMBER, TERM_UMBER},
707 {TERM_RED, TERM_RED},
710 {TERM_L_GREEN, TERM_GREEN},
713 {TERM_BLUE, TERM_BLUE},
716 {TERM_L_UMBER, TERM_RED},
719 {TERM_SLATE, TERM_L_DARK},
722 {TERM_WHITE, TERM_SLATE},
725 {TERM_L_RED, TERM_BLUE},
728 {TERM_YELLOW, TERM_ORANGE},
731 {TERM_L_RED, TERM_L_RED},
734 {TERM_L_GREEN, TERM_GREEN},
737 {TERM_L_BLUE, TERM_L_BLUE},
740 {TERM_L_UMBER, TERM_UMBER}
744 * Extract the attr/char to display at the given (legal) map location
746 * Basically, we "paint" the chosen attr/char in several passes, starting
747 * with any known "terrain features" (defaulting to darkness), then adding
748 * any known "objects", and finally, adding any known "monsters". This
749 * is not the fastest method but since most of the calls to this function
750 * are made for grids with no monsters or objects, it is fast enough.
752 * Note that this function, if used on the grid containing the "player",
753 * will return the attr/char of the grid underneath the player, and not
754 * the actual player attr/char itself, allowing a lot of optimization
755 * in various "display" functions.
757 * Note that the "zero" entry in the feature/object/monster arrays are
758 * used to provide "special" attr/char codes, with "monster zero" being
759 * used for the player attr/char, "object zero" being used for the "stack"
760 * attr/char, and "feature zero" being used for the "nothing" attr/char,
761 * though this function makes use of only "feature zero".
763 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
764 * which means their color changes, and "ATTR_CLEAR", which means they take
765 * the color of whatever is under them, and "CHAR_CLEAR", which means that
766 * they take the symbol of whatever is under them. Technically, the flag
767 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
768 * examined, but this flag is currently ignored.
770 * Currently, we do nothing with multi-hued objects, because there are
771 * not any. If there were, they would have to set "shimmer_objects"
772 * when they were created, and then new "shimmer" code in "dungeon.c"
773 * would have to be created handle the "shimmer" effect, and the code
774 * in "cave.c" would have to be updated to create the shimmer effect.
776 * Note the effects of hallucination. Objects always appear as random
777 * "objects", monsters as random "monsters", and normal grids occasionally
778 * appear as random "monsters" or "objects", but note that these random
779 * "monsters" and "objects" are really just "colored ascii symbols".
781 * Note that "floors" and "invisible traps" (and "zero" features) are
782 * drawn as "floors" using a special check for optimization purposes,
783 * and these are the only features which get drawn using the special
784 * lighting effects activated by "view_special_lite".
786 * Note the use of the "mimic" field in the "terrain feature" processing,
787 * which allows any feature to "pretend" to be another feature. This is
788 * used to "hide" secret doors, and to make all "doors" appear the same,
789 * and all "walls" appear the same, and "hidden" treasure stay hidden.
790 * It is possible to use this field to make a feature "look" like a floor,
791 * but the "special lighting effects" for floors will not be used.
793 * Note the use of the new "terrain feature" information. Note that the
794 * assumption that all interesting "objects" and "terrain features" are
795 * memorized allows extremely optimized processing below. Note the use
796 * of separate flags on objects to mark them as memorized allows a grid
797 * to have memorized "terrain" without granting knowledge of any object
798 * which may appear in that grid.
800 * Note the efficient code used to determine if a "floor" grid is
801 * "memorized" or "viewable" by the player, where the test for the
802 * grid being "viewable" is based on the facts that (1) the grid
803 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
804 * line of sight, and (3) the player must not be blind, and uses the
805 * assumption that all torch-lit grids are in line of sight.
807 * Note that floors (and invisible traps) are the only grids which are
808 * not memorized when seen, so only these grids need to check to see if
809 * the grid is "viewable" to the player (if it is not memorized). Since
810 * most non-memorized grids are in fact walls, this induces *massive*
811 * efficiency, at the cost of *forcing* the memorization of non-floor
812 * grids when they are first seen. Note that "invisible traps" are
813 * always treated exactly like "floors", which prevents "cheating".
815 * Note the "special lighting effects" which can be activated for floor
816 * grids using the "view_special_lite" option (for "white" floor grids),
817 * causing certain grids to be displayed using special colors. If the
818 * player is "blind", we will use "dark gray", else if the grid is lit
819 * by the torch, and the "view_yellow_lite" option is set, we will use
820 * "yellow", else if the grid is "dark", we will use "dark gray", else
821 * if the grid is not "viewable", and the "view_bright_lite" option is
822 * set, and the we will use "slate" (gray). We will use "white" for all
823 * other cases, in particular, for illuminated viewable floor grids.
825 * Note the "special lighting effects" which can be activated for wall
826 * grids using the "view_granite_lite" option (for "white" wall grids),
827 * causing certain grids to be displayed using special colors. If the
828 * player is "blind", we will use "dark gray", else if the grid is lit
829 * by the torch, and the "view_yellow_lite" option is set, we will use
830 * "yellow", else if the "view_bright_lite" option is set, and the grid
831 * is not "viewable", or is "dark", or is glowing, but not when viewed
832 * from the player's current location, we will use "slate" (gray). We
833 * will use "white" for all other cases, in particular, for correctly
834 * illuminated viewable wall grids.
836 * Note that, when "view_granite_lite" is set, we use an inline version
837 * of the "player_can_see_bold()" function to check the "viewability" of
838 * grids when the "view_bright_lite" option is set, and we do NOT use
839 * any special colors for "dark" wall grids, since this would allow the
840 * player to notice the walls of illuminated rooms from a hallway that
841 * happened to run beside the room. The alternative, by the way, would
842 * be to prevent the generation of hallways next to rooms, but this
843 * would still allow problems when digging towards a room.
845 * Note that bizarre things must be done when the "attr" and/or "char"
846 * codes have the "high-bit" set, since these values are used to encode
847 * various "special" pictures in some versions, and certain situations,
848 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
849 * to be "scrambled" in various ways.
851 * Note that eventually we may use the "&" symbol for embedded treasure,
852 * and use the "*" symbol to indicate multiple objects, though this will
853 * have to wait for Angband 2.8.0 or later. Note that currently, this
854 * is not important, since only one object or terrain feature is allowed
855 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
857 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
858 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
859 * then a whole lot of code should be changed... XXX XXX
861 #ifdef USE_TRANSPARENCY
862 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
863 #else /* USE_TRANSPARENCY */
864 void map_info(int y, int x, byte *ap, char *cp)
865 #endif /* USE_TRANSPARENCY */
871 s16b this_o_idx, next_o_idx = 0;
882 feat = c_ptr->mimic ? c_ptr->mimic : c_ptr->feat;
883 feat = (c_ptr->info & CAVE_IN_MIRROR) ? FEAT_MIRROR : feat;
886 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
888 /* Memorized (or visible) floor */
889 if ((c_ptr->info & CAVE_MARK) ||
890 (((c_ptr->info & CAVE_LITE) || (c_ptr->info & CAVE_MNLT) ||
891 ((c_ptr->info & CAVE_GLOW) &&
892 (c_ptr->info & CAVE_VIEW))) &&
896 f_ptr = &f_info[feat];
904 /* Special lighting effects */
905 if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_graphics))
913 * feat_supports_lighting(feat)
914 * is always TRUE here
917 /* Use a dark tile */
922 /* Use "dark gray" */
927 /* Handle "torch-lit" grids */
928 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
931 if (view_yellow_lite && !p_ptr->wild_mode)
936 * feat_supports_lighting(feat)
937 * is always TRUE here
940 /* Use a brightly lit tile */
951 /* Handle "dark" grids */
952 else if (!(c_ptr->info & CAVE_GLOW))
957 * feat_supports_lighting(feat)
958 * is always TRUE here
961 /* Use a dark tile */
966 /* Use "dark gray" */
971 /* Handle "out-of-sight" grids */
972 else if (!(c_ptr->info & CAVE_VIEW))
975 if (view_bright_lite && !p_ptr->wild_mode)
980 * feat_supports_lighting(feat)
981 * is always TRUE here
984 /* Use a dark tile */
1000 /* Unsafe cave grid -- idea borrowed from Unangband */
1001 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1002 feat = FEAT_UNDETECTD;
1006 /* Access darkness */
1007 f_ptr = &f_info[feat];
1020 /* Memorized grids */
1021 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || new_ascii_graphics))
1023 /* Apply "mimic" field */
1025 feat = c_ptr->mimic;
1027 feat = f_info[feat].mimic;
1029 /* Access feature */
1030 f_ptr = &f_info[feat];
1038 if (new_ascii_graphics)
1040 /* Handle "blind" */
1043 if (is_ascii_graphics(c,a))
1045 /* Use darkened colour */
1046 a = lighting_colours[a][1];
1048 else if (use_graphics && feat_supports_lighting(feat))
1050 /* Use a dark tile */
1055 /* Handle "torch-lit" grids */
1056 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1059 if (view_yellow_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1061 if (is_ascii_graphics(c,a))
1063 /* Use lightened colour */
1064 a = lighting_colours[a][0];
1066 else if (use_graphics &&
1067 feat_supports_lighting(c_ptr->feat))
1069 /* Use a brightly lit tile */
1075 /* Handle "view_bright_lite" */
1076 else if (view_bright_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1079 if (!(c_ptr->info & CAVE_VIEW))
1081 if (is_ascii_graphics(c,a))
1083 /* Use darkened colour */
1084 a = lighting_colours[a][1];
1086 else if (use_graphics && feat_supports_lighting(feat))
1088 /* Use a dark tile */
1094 else if (!(c_ptr->info & CAVE_GLOW))
1096 if (is_ascii_graphics(c,a))
1098 /* Use darkened colour */
1099 a = lighting_colours[a][1];
1104 /* Special lighting effects */
1105 else if (view_granite_lite && !p_ptr->wild_mode &&
1106 (((a == TERM_WHITE) && !use_graphics) ||
1107 (use_graphics && feat_supports_lighting(c_ptr->feat))))
1109 /* Handle "blind" */
1114 /* Use a dark tile */
1119 /* Use "dark gray" */
1124 /* Handle "torch-lit" grids */
1125 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1128 if (view_yellow_lite && !p_ptr->wild_mode)
1132 /* Use a brightly lit tile */
1143 /* Handle "view_bright_lite" */
1144 else if (view_bright_lite && !p_ptr->wild_mode)
1147 if (!(c_ptr->info & CAVE_VIEW))
1151 /* Use a dark tile */
1162 else if (!(c_ptr->info & CAVE_GLOW))
1166 /* Use a lit tile */
1175 /* Not glowing correctly */
1180 /* Hack -- move towards player */
1181 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1182 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1184 /* Check for "local" illumination */
1185 if (!(cave[yy][xx].info & CAVE_GLOW))
1189 /* Use a lit tile */
1202 /* "Simple Lighting" */
1205 /* Handle "blind" */
1206 if (!(c_ptr->info & CAVE_MARK))
1208 /* Unsafe cave grid -- idea borrowed from Unangband */
1209 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1210 feat = FEAT_UNDETECTD;
1215 /* Access feature */
1216 f_ptr = &f_info[feat];
1226 if (feat_priority == -1)
1231 case FEAT_UNDETECTD:
1238 case FEAT_TRAP_TRAPDOOR:
1240 case FEAT_TRAP_SPIKED_PIT:
1241 case FEAT_TRAP_POISON_PIT:
1242 case FEAT_TRAP_TY_CURSE:
1243 case FEAT_TRAP_TELEPORT:
1244 case FEAT_TRAP_FIRE:
1245 case FEAT_TRAP_ACID:
1246 case FEAT_TRAP_SLOW:
1247 case FEAT_TRAP_LOSE_STR:
1248 case FEAT_TRAP_LOSE_DEX:
1249 case FEAT_TRAP_LOSE_CON:
1250 case FEAT_TRAP_BLIND:
1251 case FEAT_TRAP_CONFUSE:
1252 case FEAT_TRAP_POISON:
1253 case FEAT_TRAP_SLEEP:
1254 case FEAT_TRAP_TRAPS:
1255 case FEAT_TRAP_ALARM:
1259 case FEAT_DEEP_GRASS:
1268 case FEAT_WALL_EXTRA:
1269 case FEAT_WALL_INNER:
1270 case FEAT_WALL_OUTER:
1271 case FEAT_WALL_SOLID:
1272 case FEAT_DEEP_WATER:
1273 case FEAT_SHAL_WATER:
1274 case FEAT_DEEP_LAVA:
1275 case FEAT_SHAL_LAVA:
1285 case FEAT_PERM_EXTRA:
1286 case FEAT_PERM_INNER:
1287 case FEAT_PERM_OUTER:
1288 case FEAT_PERM_SOLID:
1292 /* default is feat_priority = 20; (doors and stores) */
1295 case FEAT_MINOR_GLYPH:
1297 case FEAT_PATTERN_START:
1298 case FEAT_PATTERN_1:
1299 case FEAT_PATTERN_2:
1300 case FEAT_PATTERN_3:
1301 case FEAT_PATTERN_4:
1302 case FEAT_PATTERN_END:
1303 case FEAT_PATTERN_OLD:
1304 case FEAT_PATTERN_XTRA1:
1305 case FEAT_PATTERN_XTRA2:
1309 /* objects have feat_priority = 20 */
1310 /* monsters have feat_priority = 30 */
1314 case FEAT_QUEST_ENTER:
1315 case FEAT_QUEST_EXIT:
1316 case FEAT_QUEST_DOWN:
1318 case FEAT_LESS_LESS:
1319 case FEAT_MORE_MORE:
1331 #ifdef USE_TRANSPARENCY
1332 /* Save the terrain info for the transparency effects */
1335 #endif /* USE_TRANSPARENCY */
1341 /* Hack -- rare random hallucination, except on outer dungeon walls */
1342 if (p_ptr->image && (c_ptr->feat < FEAT_PERM_SOLID) && !randint0(256))
1345 image_random(ap, cp);
1349 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1353 /* Acquire object */
1354 o_ptr = &o_list[this_o_idx];
1356 /* Acquire next object */
1357 next_o_idx = o_ptr->next_o_idx;
1359 /* Memorized objects */
1362 if (display_autopick)
1366 match_autopick = is_autopick(o_ptr);
1367 if(match_autopick == -1)
1370 act = autopick_list[match_autopick].action;
1372 if ((act & DO_DISPLAY) && (act & display_autopick))
1374 autopick_obj = o_ptr;
1378 match_autopick = -1;
1383 (*cp) = object_char(o_ptr);
1386 (*ap) = object_attr(o_ptr);
1390 /* Hack -- hallucination */
1391 if (p_ptr->image) image_object(ap, cp);
1399 /* Handle monsters */
1400 if (c_ptr->m_idx && display_autopick == 0 )
1402 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1404 /* Visible monster */
1407 monster_race *r_ptr;
1408 r_ptr = &r_info[m_ptr->ap_r_idx];
1418 /* Mimics' colors vary */
1419 if (strchr("\"!=", c) && !(r_ptr->flags1 & RF1_UNIQUE))
1424 /* Use semi-random attr */
1425 (*ap) = c_ptr->m_idx % 15 + 1;
1428 /* Special attr/char codes */
1429 else if ((a & 0x80) && (c & 0x80))
1438 /* Multi-hued monster */
1439 else if (r_ptr->flags1 & (RF1_ATTR_MULTI))
1441 /* Is it a shapechanger? */
1442 if (r_ptr->flags2 & (RF2_SHAPECHANGER))
1446 if (!(streq(ANGBAND_SYS, "ibm")))
1448 (*cp) = r_info[randint1(max_r_idx-1)].x_char;
1449 (*ap) = r_info[randint1(max_r_idx-1)].x_attr;
1453 int n = strlen(image_monster_hack_ibm);
1454 (*cp) = (image_monster_hack_ibm[randint0(n)]);
1457 (*ap) = randint1(15);
1462 (*cp) = (one_in_(25) ?
1463 image_object_hack[randint0(strlen(image_object_hack))] :
1464 image_monster_hack[randint0(strlen(image_monster_hack))]);
1470 /* Multi-hued attr */
1471 if (r_ptr->flags2 & RF2_ATTR_ANY)
1472 (*ap) = randint1(15);
1473 else switch (randint1(7))
1485 (*ap) = TERM_L_GREEN;
1491 (*ap) = TERM_L_DARK;
1499 /* Normal monster (not "clear" in any way) */
1500 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR | RF1_CHAR_CLEAR)))
1509 /* Hack -- Bizarre grid under monster */
1510 else if ((*ap & 0x80) || (*cp & 0x80))
1522 /* Normal (non-clear char) monster */
1523 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR)))
1529 /* Normal (non-clear attr) monster */
1530 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR)))
1537 /* Hack -- hallucination */
1540 /* Hallucinatory monster */
1541 image_monster(ap, cp);
1546 /* Handle "player" */
1547 if ((y == py) && (x == px))
1549 monster_race *r_ptr = &r_info[0];
1553 /* Get the "player" attr */
1556 /* Get the "player" char */
1559 #ifdef VARIABLE_PLAYER_GRAPH
1561 if (!streq(ANGBAND_GRAF, "new"))
1563 if (streq(ANGBAND_SYS,"ibm"))
1565 if (use_graphics && player_symbols)
1567 if (p_ptr->psex == SEX_FEMALE) c = (char)242;
1568 switch (p_ptr->pclass)
1571 if (p_ptr->lev < 20)
1577 case CLASS_WARRIOR_MAGE:
1578 case CLASS_RED_MAGE:
1579 if (p_ptr->lev < 20)
1584 case CLASS_CHAOS_WARRIOR:
1589 while (a == TERM_DARK);
1592 case CLASS_HIGH_MAGE:
1593 case CLASS_SORCERER:
1594 case CLASS_MAGIC_EATER:
1595 case CLASS_BLUE_MAGE:
1596 if (p_ptr->lev < 20)
1604 if (p_ptr->lev < 20)
1612 if (p_ptr->lev < 20)
1619 if (p_ptr->lev < 20)
1626 case CLASS_BERSERKER:
1628 if (p_ptr->lev < 20)
1634 case CLASS_MINDCRAFTER:
1635 case CLASS_FORCETRAINER:
1636 case CLASS_MIRROR_MASTER:
1637 if (p_ptr->lev < 20)
1643 default: /* Unknown */
1647 switch (p_ptr->prace)
1659 case RACE_HALF_TROLL:
1669 case RACE_HALF_OGRE:
1672 case RACE_HALF_GIANT:
1673 case RACE_HALF_TITAN:
1692 case RACE_DRACONIAN:
1693 if (p_ptr->lev < 20)
1695 else if (p_ptr->lev < 40)
1700 case RACE_MIND_FLAYER:
1711 if (p_ptr->pclass == CLASS_MAGE ||
1712 p_ptr->pclass == CLASS_PRIEST ||
1713 p_ptr->pclass == CLASS_HIGH_MAGE ||
1714 p_ptr->pclass == CLASS_SORCERER ||
1715 p_ptr->pclass == CLASS_MONK ||
1716 p_ptr->pclass == CLASS_FORCETRAINER ||
1717 p_ptr->pclass == CLASS_BLUE_MAGE ||
1718 p_ptr->pclass == CLASS_MIRROR_MASTER ||
1719 p_ptr->pclass == CLASS_MINDCRAFTER)
1753 #endif /* VARIABLE_PLAYER_GRAPH */
1761 * Table of Ascii-to-Zenkaku
1762 * ¡Ö¢£¡×¤ÏÆóÇÜÉýƦÉå¤ÎÆâÉô¥³¡¼¥É¤Ë»ÈÍÑ¡£
1764 static char ascii_to_zenkaku[2*128+1] = "\
1765 ¡¡¡ª¡É¡ô¡ð¡ó¡õ¡Ç¡Ê¡Ë¡ö¡Ü¡¤¡Ý¡¥¡¿\
1766 £°£±£²£³£´£µ£¶£·£¸£¹¡§¡¨¡ã¡á¡ä¡©\
1767 ¡÷£Á£Â£Ã£Ä£Å£Æ£Ç£È£É£Ê£Ë£Ì£Í£Î£Ï\
1768 £Ð£Ñ£Ò£Ó£Ô£Õ£Ö£×£Ø£Ù£Ú¡Î¡À¡Ï¡°¡²\
1769 ¡Æ£á£â£ã£ä£å£æ£ç£è£é£ê£ë£ì£í£î£ï\
1770 £ð£ñ£ò£ó£ô£õ£ö£÷£ø£ù£ú¡Ð¡Ã¡Ñ¡Á¢£";
1774 * Prepare Bigtile or 2-bytes character attr/char pairs
1776 static void bigtile_attr(char *cp, byte *ap, char *cp2, byte *ap2)
1786 if (isprint(*cp) || *cp == 127)
1788 *ap2 = (*ap) | 0xf0;
1789 *cp2 = ascii_to_zenkaku[2*(*cp-' ') + 1];
1790 *cp = ascii_to_zenkaku[2*(*cp-' ')];
1801 * Calculate panel colum of a location in the map
1803 static int panel_col_of(int col)
1805 col -= panel_col_min;
1806 if (use_bigtile) col *= 2;
1812 * Moves the cursor to a given MAP (y,x) location
1814 void move_cursor_relative(int row, int col)
1816 /* Real co-ords convert to screen positions */
1817 row -= panel_row_prt;
1820 Term_gotoxy(panel_col_of(col), row);
1826 * Place an attr/char pair at the given map coordinate, if legal.
1828 void print_rel(char c, byte a, int y, int x)
1833 /* Only do "legal" locations */
1834 if (panel_contains(y, x))
1836 /* Hack -- fake monochrome */
1837 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
1839 if (world_monster) a = TERM_DARK;
1840 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
1841 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
1842 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1845 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
1847 /* Draw the char using the attr */
1848 Term_draw(panel_col_of(x), y-panel_row_prt, a, c);
1850 Term_draw(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
1859 * Memorize interesting viewable object/features in the given grid
1861 * This function should only be called on "legal" grids.
1863 * This function will memorize the object and/or feature in the given
1864 * grid, if they are (1) viewable and (2) interesting. Note that all
1865 * objects are interesting, all terrain features except floors (and
1866 * invisible traps) are interesting, and floors (and invisible traps)
1867 * are interesting sometimes (depending on various options involving
1868 * the illumination of floor grids).
1870 * The automatic memorization of all objects and non-floor terrain
1871 * features as soon as they are displayed allows incredible amounts
1872 * of optimization in various places, especially "map_info()".
1874 * Note that the memorization of objects is completely separate from
1875 * the memorization of terrain features, preventing annoying floor
1876 * memorization when a detected object is picked up from a dark floor,
1877 * and object memorization when an object is dropped into a floor grid
1878 * which is memorized but out-of-sight.
1880 * This function should be called every time the "memorization" of
1881 * a grid (or the object in a grid) is called into question, such
1882 * as when an object is created in a grid, when a terrain feature
1883 * "changes" from "floor" to "non-floor", when any grid becomes
1884 * "illuminated" or "viewable", and when a "floor" grid becomes
1887 * Note the relatively efficient use of this function by the various
1888 * "update_view()" and "update_lite()" calls, to allow objects and
1889 * terrain features to be memorized (and drawn) whenever they become
1890 * viewable or illuminated in any way, but not when they "maintain"
1891 * or "lose" their previous viewability or illumination.
1893 * Note the butchered "internal" version of "player_can_see_bold()",
1894 * optimized primarily for the most common cases, that is, for the
1895 * non-marked floor grids.
1897 void note_spot(int y, int x)
1899 cave_type *c_ptr = &cave[y][x];
1901 s16b this_o_idx, next_o_idx = 0;
1904 /* Blind players see nothing */
1905 if (p_ptr->blind) return;
1907 /* Analyze non-torch-lit grids */
1908 if (!(c_ptr->info & (CAVE_LITE)))
1910 /* Require line of sight to the grid */
1911 if (!(c_ptr->info & (CAVE_VIEW))) return;
1913 if (p_ptr->pclass != CLASS_NINJA)
1915 /* Require "perma-lite" of the grid */
1916 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return;
1921 /* Hack -- memorize objects */
1922 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1924 object_type *o_ptr = &o_list[this_o_idx];
1926 /* Acquire next object */
1927 next_o_idx = o_ptr->next_o_idx;
1929 /* Memorize objects */
1930 o_ptr->marked = TRUE;
1934 /* Hack -- memorize grids */
1935 if (!(c_ptr->info & (CAVE_MARK)))
1937 if (p_ptr->pclass == CLASS_NINJA)
1939 c_ptr->info |= (CAVE_MARK);
1941 /* Handle floor grids first */
1942 if ((c_ptr->feat <= FEAT_INVIS) || (c_ptr->feat == FEAT_DIRT) || (c_ptr->feat == FEAT_GRASS))
1944 /* Option -- memorize all torch-lit floors */
1945 if (view_torch_grids && (c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1948 c_ptr->info |= (CAVE_MARK);
1951 /* Option -- memorize all perma-lit floors */
1952 else if (view_perma_grids && (c_ptr->info & (CAVE_GLOW)))
1955 c_ptr->info |= (CAVE_MARK);
1959 /* Memorize normal grids */
1960 else if (cave_floor_grid(c_ptr))
1963 c_ptr->info |= (CAVE_MARK);
1966 /* Memorize torch-lit walls */
1967 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1970 c_ptr->info |= (CAVE_MARK);
1973 /* Memorize certain non-torch-lit wall grids */
1978 /* Hack -- move one grid towards player */
1979 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1980 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1982 /* Check for "local" illumination */
1983 if (cave[yy][xx].info & (CAVE_GLOW))
1986 c_ptr->info |= (CAVE_MARK);
1993 void display_dungeon(void)
1999 #ifdef USE_TRANSPARENCY
2002 #endif /* USE_TRANSPARENCY */
2004 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
2006 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
2008 if (in_bounds2(y, x))
2011 #ifdef USE_TRANSPARENCY
2012 /* Examine the grid */
2013 map_info(y, x, &a, &c, &ta, &tc);
2014 #else /* USE_TRANSPARENCY */
2015 /* Examine the grid */
2016 map_info(y, x, &a, &c);
2017 #endif /* USE_TRANSPARENCY */
2019 /* Hack -- fake monochrome */
2020 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2022 if (world_monster) a = TERM_DARK;
2023 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2024 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2025 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2028 #ifdef USE_TRANSPARENCY
2029 /* Hack -- Queue it */
2030 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2031 #else /* USE_TRANSPARENCY */
2032 /* Hack -- Queue it */
2033 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2034 #endif /* USE_TRANSPARENCY */
2039 /* Clear out-of-bound tiles */
2041 /* Access darkness */
2042 feature_type *f_ptr = &f_info[FEAT_NONE];
2050 #ifdef USE_TRANSPARENCY
2051 /* Hack -- Queue it */
2052 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2053 #else /* USE_TRANSPARENCY */
2054 /* Hack -- Queue it */
2055 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2056 #endif /* USE_TRANSPARENCY */
2064 * Redraw (on the screen) a given MAP location
2066 * This function should only be called on "legal" grids
2068 void lite_spot(int y, int x)
2070 /* Redraw if on screen */
2071 if (panel_contains(y, x) && in_bounds2(y, x))
2076 #ifdef USE_TRANSPARENCY
2080 /* Examine the grid */
2081 map_info(y, x, &a, &c, &ta, &tc);
2082 #else /* USE_TRANSPARENCY */
2083 /* Examine the grid */
2084 map_info(y, x, &a, &c);
2085 #endif /* USE_TRANSPARENCY */
2087 /* Hack -- fake monochrome */
2088 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2090 if (world_monster) a = TERM_DARK;
2091 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2092 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2093 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2097 if (use_bigtile && !(a & 0x80) && (isprint(c) || c == 127))
2099 /* Term_queue_chars ¤ÏÁ´³ÑASCIIÃÏ·Á¤òÀµ¤·¤¯update¤¹¤ë¡£ */
2100 Term_queue_chars(panel_col_of(x), y-panel_row_prt, 2, a, &ascii_to_zenkaku[2*(c-' ')]);
2105 #ifdef USE_TRANSPARENCY
2106 /* Hack -- Queue it */
2107 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
2109 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1, 0, 0);
2110 #else /* USE_TRANSPARENCY */
2111 /* Hack -- Queue it */
2112 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
2114 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1);
2115 #endif /* USE_TRANSPARENCY */
2121 * Prints the map of the dungeon
2123 * Note that, for efficiency, we contain an "optimized" version
2124 * of both "lite_spot()" and "print_rel()", and that we use the
2125 * "lite_spot()" function to display the player grid, if needed.
2133 s16b xmin, xmax, ymin, ymax;
2137 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2140 Term_get_size(&wid, &hgt);
2142 /* Remove map offset */
2146 /* Access the cursor state */
2147 (void)Term_get_cursor(&v);
2149 /* Hide the cursor */
2150 (void)Term_set_cursor(0);
2153 xmin = (0 < panel_col_min) ? panel_col_min : 0;
2154 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
2155 ymin = (0 < panel_row_min) ? panel_row_min : 0;
2156 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
2158 /* Bottom section of screen */
2159 for (y = 1; y <= ymin - panel_row_prt; y++)
2161 /* Erase the section */
2162 Term_erase(COL_MAP, y, wid);
2165 /* Top section of screen */
2166 for (y = ymax - panel_row_prt; y <= hgt; y++)
2168 /* Erase the section */
2169 Term_erase(COL_MAP, y, wid);
2173 for (y = ymin; y <= ymax; y++)
2175 /* Scan the columns of row "y" */
2176 for (x = xmin; x <= xmax; x++)
2181 #ifdef USE_TRANSPARENCY
2185 /* Determine what is there */
2186 map_info(y, x, &a, &c, &ta, &tc);
2188 /* Determine what is there */
2189 map_info(y, x, &a, &c);
2192 /* Hack -- fake monochrome */
2193 if (fake_monochrome)
2195 if (world_monster) a = TERM_DARK;
2196 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2197 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2198 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2201 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2203 /* Efficiency -- Redraw that grid of the map */
2204 #ifdef USE_TRANSPARENCY
2205 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
2206 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2, 0, 0);
2208 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
2209 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
2214 /* Display player */
2217 /* Restore the cursor */
2218 (void)Term_set_cursor(v);
2224 * print project path
2226 void prt_path(int y, int x)
2231 int default_color = TERM_SLATE;
2232 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2234 if (!display_path) return;
2235 if (-1 == project_length)
2238 /* Get projection path */
2239 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2242 p_ptr->redraw |= (PR_MAP);
2248 for (i = 0; i < path_n; i++)
2250 int ny = GRID_Y(path_g[i]);
2251 int nx = GRID_X(path_g[i]);
2253 if (panel_contains(ny, nx))
2255 byte a2, a = default_color;
2258 #ifdef USE_TRANSPARENCY
2263 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2265 /* Determine what is there */
2266 #ifdef USE_TRANSPARENCY
2267 map_info(ny, nx, &a, &c, &ta, &tc);
2269 map_info(ny, nx, &a, &c);
2273 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2275 else if (a == default_color)
2279 if (fake_monochrome)
2281 if (world_monster) a = TERM_DARK;
2282 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2283 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2284 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2288 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2290 /* Hack -- Queue it */
2291 #ifdef USE_TRANSPARENCY
2292 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
2293 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2, 0, 0);
2295 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c);
2296 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2);
2301 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2304 if (nx == x && ny == y) default_color = TERM_L_DARK;
2309 static cptr simplify_list[][2] =
2316 {"^Amulet of ", "\""},
2317 {"^Scroll of ", "?"},
2318 {"^Scroll titled ", "?"},
2319 {"^Wand of " , "-"},
2321 {"^Staff of " , "_"},
2322 {"^Potion of ", "!"},
2334 static void display_shortened_item_name(object_type *o_ptr, int y)
2341 object_desc(buf, o_ptr, FALSE, 0);
2342 attr = tval_to_attr[o_ptr->tval % 128];
2348 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
2350 strcpy(buf, "something strange");
2354 for (c = buf; *c; c++)
2357 for (i = 0; simplify_list[i][1]; i++)
2359 cptr org_w = simplify_list[i][0];
2369 if (!strncmp(c, org_w, strlen(org_w)))
2372 cptr tmp = simplify_list[i][1];
2375 tmp = c + strlen(org_w);
2385 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2391 if(len + 2 > 12) break;
2398 if(len + 1 > 12) break;
2404 Term_putstr(0, y, 12, attr, buf);
2408 * Display a "small-scale" map of the dungeon in the active Term
2410 void display_map(int *cy, int *cx)
2427 /* Save lighting effects */
2428 bool old_view_special_lite = view_special_lite;
2429 bool old_view_granite_lite = view_granite_lite;
2431 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2433 int hgt, wid, yrat, xrat;
2435 int **match_autopick_yx;
2436 object_type ***object_autopick_yx;
2439 Term_get_size(&wid, &hgt);
2442 if (use_bigtile) wid /= 2;
2444 yrat = (cur_hgt + hgt - 1) / hgt;
2445 xrat = (cur_wid + wid - 1) / wid;
2447 /* Disable lighting effects */
2448 view_special_lite = FALSE;
2449 view_granite_lite = FALSE;
2451 /* Allocate the maps */
2452 C_MAKE(ma, (hgt + 2), byte_ptr);
2453 C_MAKE(mc, (hgt + 2), char_ptr);
2454 C_MAKE(mp, (hgt + 2), byte_ptr);
2455 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2456 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2458 /* Allocate and wipe each line map */
2459 for (y = 0; y < (hgt + 2); y++)
2461 /* Allocate one row each array */
2462 C_MAKE(ma[y], (wid + 2), byte);
2463 C_MAKE(mc[y], (wid + 2), char);
2464 C_MAKE(mp[y], (wid + 2), byte);
2465 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2466 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2468 for (x = 0; x < wid + 2; ++x)
2470 match_autopick_yx[y][x] = -1;
2471 object_autopick_yx[y][x] = NULL;
2474 ma[y][x] = TERM_WHITE;
2482 /* Allocate the maps */
2483 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
2484 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
2485 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
2487 /* Allocate and wipe each line map */
2488 for (y = 0; y < (cur_hgt + 2); y++)
2490 /* Allocate one row each array */
2491 C_MAKE(bigma[y], (cur_wid + 2), byte);
2492 C_MAKE(bigmc[y], (cur_wid + 2), char);
2493 C_MAKE(bigmp[y], (cur_wid + 2), byte);
2495 for (x = 0; x < cur_wid + 2; ++x)
2498 bigma[y][x] = TERM_WHITE;
2506 /* Fill in the map */
2507 for (i = 0; i < cur_wid; ++i)
2509 for (j = 0; j < cur_hgt; ++j)
2519 /* Extract the current attr/char at that map location */
2520 #ifdef USE_TRANSPARENCY
2521 map_info(j, i, &ta, &tc, &ta, &tc);
2522 #else /* USE_TRANSPARENCY */
2523 map_info(j, i, &ta, &tc);
2524 #endif /* USE_TRANSPARENCY */
2526 /* Extract the priority */
2529 if(match_autopick!=-1
2530 && (match_autopick_yx[y][x] == -1
2531 || match_autopick_yx[y][x] > match_autopick))
2533 match_autopick_yx[y][x] = match_autopick;
2534 object_autopick_yx[y][x] = autopick_obj;
2538 /* Save the char, attr and priority */
2539 bigmc[j+1][i+1] = tc;
2540 bigma[j+1][i+1] = ta;
2541 bigmp[j+1][i+1] = tp;
2545 for (j = 0; j < cur_hgt; ++j)
2547 for (i = 0; i < cur_wid; ++i)
2553 tc = bigmc[j+1][i+1];
2554 ta = bigma[j+1][i+1];
2555 tp = bigmp[j+1][i+1];
2557 /* rare feature has more priority */
2563 for (t = 0; t < 8; t++)
2565 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2566 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2576 /* Save the char, attr and priority */
2589 /* Draw the corners */
2590 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2592 /* Draw the horizontal edges */
2593 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2595 /* Draw the vertical edges */
2596 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2599 /* Display each map line in order */
2600 for (y = 0; y < hgt + 2; ++y)
2602 /* Start a new line */
2603 Term_gotoxy(COL_MAP, y);
2605 /* Display the line */
2606 for (x = 0; x < wid + 2; ++x)
2611 /* Hack -- fake monochrome */
2612 if (fake_monochrome)
2614 if (world_monster) ta = TERM_DARK;
2615 else if (p_ptr->invuln || world_player) ta = TERM_WHITE;
2616 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) ta = TERM_WHITE;
2617 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2620 if (use_bigtile) bigtile_attr(&tc, &ta, &c2, &a2);
2622 /* Add the character */
2624 if (use_bigtile) Term_addch(a2, c2);
2629 for (y = 1; y < hgt + 1; ++y)
2631 match_autopick = -1;
2632 for (x = 1; x <= wid; x++){
2633 if (match_autopick_yx[y][x] != -1 &&
2634 (match_autopick > match_autopick_yx[y][x] ||
2635 match_autopick == -1)){
2636 match_autopick = match_autopick_yx[y][x];
2637 autopick_obj = object_autopick_yx[y][x];
2641 /* Clear old display */
2642 Term_putstr(0, y, 12, 0, " ");
2644 if (match_autopick != -1)
2646 display_shortened_item_name(autopick_obj, y);
2649 char buf[13] = "\0";
2650 strncpy(buf,autopick_list[match_autopick].name,12);
2658 /* Player location */
2659 (*cy) = py / yrat + 1 + ROW_MAP;
2661 (*cx) = px / xrat + 1 + COL_MAP;
2663 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2665 /* Restore lighting effects */
2666 view_special_lite = old_view_special_lite;
2667 view_granite_lite = old_view_granite_lite;
2669 /* Free each line map */
2670 for (y = 0; y < (hgt + 2); y++)
2672 /* Free one row each array */
2673 C_FREE(ma[y], (wid + 2), byte);
2674 C_FREE(mc[y], (wid + 2), char);
2675 C_FREE(mp[y], (wid + 2), byte);
2676 C_FREE(match_autopick_yx[y], (wid + 2), int);
2677 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2680 /* Free each line map */
2681 C_FREE(ma, (hgt + 2), byte_ptr);
2682 C_FREE(mc, (hgt + 2), char_ptr);
2683 C_FREE(mp, (hgt + 2), byte_ptr);
2684 C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2685 C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2687 /* Free each line map */
2688 for (y = 0; y < (cur_hgt + 2); y++)
2690 /* Free one row each array */
2691 C_FREE(bigma[y], (cur_wid + 2), byte);
2692 C_FREE(bigmc[y], (cur_wid + 2), char);
2693 C_FREE(bigmp[y], (cur_wid + 2), byte);
2696 /* Free each line map */
2697 C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2698 C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2699 C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2704 * Display a "small-scale" map of the dungeon for the player
2706 * Currently, the "player" is displayed on the map. XXX XXX XXX
2708 void do_cmd_view_map(void)
2713 /* Save the screen */
2718 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2720 prt("Please wait...", 0, 0);
2726 /* Clear the screen */
2729 display_autopick = 0;
2731 /* Display the map */
2732 display_map(&cy, &cx);
2735 if(max_autopick && !p_ptr->wild_mode)
2737 display_autopick = ITEM_DISPLAY;
2744 int wid, hgt, row_message;
2746 Term_get_size(&wid, &hgt);
2747 row_message = hgt - 1;
2750 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2752 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2755 /* Hilite the player */
2756 move_cursor(cy, cx);
2763 flag = DONT_AUTOPICK;
2765 flag = DO_AUTODESTROY;
2767 flag = (DO_AUTOPICK | DONT_AUTOPICK);
2773 if (~display_autopick & flag)
2774 display_autopick |= flag;
2776 display_autopick &= ~flag;
2777 /* Display the map */
2778 display_map(&cy, &cx);
2781 display_autopick = 0;
2787 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2789 put_str("Hit any key to continue", 23, 30);
2790 #endif /* Hilite the player */
2791 move_cursor(cy, cx);
2796 /* Restore the screen */
2805 * Some comments on the cave grid flags. -BEN-
2808 * One of the major bottlenecks in previous versions of Angband was in
2809 * the calculation of "line of sight" from the player to various grids,
2810 * such as monsters. This was such a nasty bottleneck that a lot of
2811 * silly things were done to reduce the dependancy on "line of sight",
2812 * for example, you could not "see" any grids in a lit room until you
2813 * actually entered the room, and there were all kinds of bizarre grid
2814 * flags to enable this behavior. This is also why the "call light"
2815 * spells always lit an entire room.
2817 * The code below provides functions to calculate the "field of view"
2818 * for the player, which, once calculated, provides extremely fast
2819 * calculation of "line of sight from the player", and to calculate
2820 * the "field of torch lite", which, again, once calculated, provides
2821 * extremely fast calculation of "which grids are lit by the player's
2822 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2823 * "GRID_LITE", as appropriate, these functions maintain an array for
2824 * each of these two flags, each array containing the locations of all
2825 * of the grids marked with the appropriate flag, which can be used to
2826 * very quickly scan through all of the grids in a given set.
2828 * To allow more "semantically valid" field of view semantics, whenever
2829 * the field of view (or the set of torch lit grids) changes, all of the
2830 * grids in the field of view (or the set of torch lit grids) are "drawn"
2831 * so that changes in the world will become apparent as soon as possible.
2832 * This has been optimized so that only grids which actually "change" are
2833 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2834 * of the grids which are entering or leaving the relevent set of grids.
2836 * These new methods are so efficient that the old nasty code was removed.
2838 * Note that there is no reason to "update" the "viewable space" unless
2839 * the player "moves", or walls/doors are created/destroyed, and there
2840 * is no reason to "update" the "torch lit grids" unless the field of
2841 * view changes, or the "light radius" changes. This means that when
2842 * the player is resting, or digging, or doing anything that does not
2843 * involve movement or changing the state of the dungeon, there is no
2844 * need to update the "view" or the "lite" regions, which is nice.
2846 * Note that the calls to the nasty "los()" function have been reduced
2847 * to a bare minimum by the use of the new "field of view" calculations.
2849 * I wouldn't be surprised if slight modifications to the "update_view()"
2850 * function would allow us to determine "reverse line-of-sight" as well
2851 * as "normal line-of-sight", which would allow monsters to use a more
2852 * "correct" calculation to determine if they can "see" the player. For
2853 * now, monsters simply "cheat" somewhat and assume that if the player
2854 * has "line of sight" to the monster, then the monster can "pretend"
2855 * that it has "line of sight" to the player.
2858 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2859 * grid and maintains an array of all "CAVE_LITE" grids.
2861 * This set of grids is the complete set of all grids which are lit by
2862 * the players light source, which allows the "player_can_see_bold()"
2863 * function to work very quickly.
2865 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2866 * fact, the player (unless blind) can always "see" all grids which are
2867 * marked as "CAVE_LITE", unless they are "off screen".
2870 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2871 * grid and maintains an array of all "CAVE_VIEW" grids.
2873 * This set of grids is the complete set of all grids within line of sight
2874 * of the player, allowing the "player_has_los_bold()" macro to work very
2878 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2879 * temporary internal flag to mark those grids which are not only in view,
2880 * but which are also "easily" in line of sight of the player. This flag
2881 * is always cleared when we are done.
2884 * The current "update_lite()" and "update_view()" algorithms use the
2885 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2886 * to keep track of which grids were previously marked as "CAVE_LITE" or
2887 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2889 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2890 * for various other purposes, such as spreading lite or darkness during
2891 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2894 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2895 * in some way permanently lit. However, for the player to "see" anything
2896 * in the grid, as determined by "player_can_see()", the player must not be
2897 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2898 * grids, even if marked as "perma lit", are only illuminated if they touch
2899 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2902 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2903 * that even if the player cannot "see" the grid, he "knows" the terrain in
2904 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2905 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2906 * or when one of the "memorize floor grids" options induces memorization.
2908 * Objects are "memorized" in a different way, using a special "marked" flag
2909 * on the object itself, which is set when an object is observed or detected.
2912 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2913 * and should be illuminated by "lite room" and "darkness" spells.
2916 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2917 * and should be unavailable for "teleportation" destinations.
2920 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2921 * which is observed, and the "view_torch_grids" allows the player to memorize
2922 * every torch-lit grid. The player will always memorize important walls,
2923 * doors, stairs, and other terrain features, as well as any "detected" grids.
2925 * Note that the new "update_view()" method allows, among other things, a room
2926 * to be "partially" seen as the player approaches it, with a growing cone of
2927 * floor appearing as the player gets closer to the door. Also, by not turning
2928 * on the "memorize perma-lit grids" option, the player will only "see" those
2929 * floor grids which are actually in line of sight.
2931 * And my favorite "plus" is that you can now use a special option to draw the
2932 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2933 * grids dimly), providing a "pretty" effect as the player runs around, and
2934 * to efficiently display the "torch lite" in a special color.
2937 * Some comments on the "update_view()" algorithm...
2939 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2940 * and only has to call "los()" on the borderline cases. The major axes/diags
2941 * even terminate early when they hit walls. I need to find a quick way
2942 * to "terminate" the other scans.
2944 * Note that in the worst case (a big empty area with say 5% scattered walls),
2945 * each of the 1500 or so nearby grids is checked once, most of them getting
2946 * an "instant" rating, and only a small portion requiring a call to "los()".
2948 * The only time that the algorithm appears to be "noticeably" too slow is
2949 * when running, and this is usually only important in town, since the town
2950 * provides about the worst scenario possible, with large open regions and
2951 * a few scattered obstructions. There is a special "efficiency" option to
2952 * allow the player to reduce his field of view in town, if needed.
2954 * In the "best" case (say, a normal stretch of corridor), the algorithm
2955 * makes one check for each viewable grid, and makes no calls to "los()".
2956 * So running in corridors is very fast, and if a lot of monsters are
2957 * nearby, it is much faster than the old methods.
2959 * Note that resting, most normal commands, and several forms of running,
2960 * plus all commands executed near large groups of monsters, are strictly
2961 * more efficient with "update_view()" that with the old "compute los() on
2962 * demand" method, primarily because once the "field of view" has been
2963 * calculated, it does not have to be recalculated until the player moves
2964 * (or a wall or door is created or destroyed).
2966 * Note that we no longer have to do as many "los()" checks, since once the
2967 * "view" region has been built, very few things cause it to be "changed"
2968 * (player movement, and the opening/closing of doors, changes in wall status).
2969 * Note that door/wall changes are only relevant when the door/wall itself is
2970 * in the "view" region.
2972 * The algorithm seems to only call "los()" from zero to ten times, usually
2973 * only when coming down a corridor into a room, or standing in a room, just
2974 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2975 * we will be reducing the calls to "los()".
2977 * I am thinking in terms of an algorithm that "walks" from the central point
2978 * out to the maximal "distance", at each point, determining the "view" code
2979 * (above). For each grid not on a major axis or diagonal, the "view" code
2980 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
2981 * (the one along the nearest diagonal, and the one next to that one, see
2982 * "update_view_aux()"...).
2984 * We "memorize" the viewable space array, so that at the cost of under 3000
2985 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2986 * each grid actually in the "viewable space". And for another 3000 bytes,
2987 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2988 * are also used by other routines, thus reducing the cost to almost nothing.
2990 * A similar thing is done for "forget_lite()" in which case the savings are
2991 * much less, but save us from doing bizarre maintenance checking.
2993 * In the worst "normal" case (in the middle of the town), the reachable space
2994 * actually reaches to more than half of the largest possible "circle" of view,
2995 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2996 * where all the walls have been removed), the reachable space actually reaches
2997 * the theoretical maximum size of just under 1500 grids.
2999 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
3000 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
3001 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
3002 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
3003 * entire possible space (including initialization) in one step per grid. If
3004 * we do the "clearing" as a separate step (and use an array of "view" grids),
3005 * then the clearing will take as many steps as grids that were viewed, and the
3006 * algorithm will be able to "stop" scanning at various points.
3007 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
3018 * Actually erase the entire "lite" array, redrawing every grid
3020 void forget_lite(void)
3024 /* None to forget */
3025 if (!lite_n) return;
3027 /* Clear them all */
3028 for (i = 0; i < lite_n; i++)
3033 /* Forget "LITE" flag */
3034 cave[y][x].info &= ~(CAVE_LITE);
3048 * This macro allows us to efficiently add a grid to the "lite" array,
3049 * note that we are never called for illegal grids, or for grids which
3050 * have already been placed into the "lite" array, and we are never
3051 * called when the "lite" array is full.
3053 #define cave_lite_hack(Y,X) \
3055 if (!(cave[Y][X].info & (CAVE_LITE))) { \
3056 cave[Y][X].info |= (CAVE_LITE); \
3057 lite_y[lite_n] = (Y); \
3058 lite_x[lite_n] = (X); \
3064 * Update the set of grids "illuminated" by the player's lite.
3066 * This routine needs to use the results of "update_view()"
3068 * Note that "blindness" does NOT affect "torch lite". Be careful!
3070 * We optimize most lites (all non-artifact lites) by using "obvious"
3071 * facts about the results of "small" lite radius, and we attempt to
3072 * list the "nearby" grids before the more "distant" ones in the
3073 * array of torch-lit grids.
3075 * We assume that "radius zero" lite is in fact no lite at all.
3077 * Torch Lantern Artifacts
3087 void update_lite(void)
3089 int i, x, y, min_x, max_x, min_y, max_y;
3090 int p = p_ptr->cur_lite;
3092 /*** Special case ***/
3094 /* Hack -- Player has no lite */
3097 /* Forget the old lite */
3100 /* Draw the player */
3105 /*** Save the old "lite" grids for later ***/
3107 /* Clear them all */
3108 for (i = 0; i < lite_n; i++)
3113 /* Mark the grid as not "lite" */
3114 cave[y][x].info &= ~(CAVE_LITE);
3116 /* Mark the grid as "seen" */
3117 cave[y][x].info |= (CAVE_TEMP);
3119 /* Add it to the "seen" set */
3129 /*** Collect the new "lite" grids ***/
3131 /* Radius 1 -- torch radius */
3135 cave_lite_hack(py, px);
3138 cave_lite_hack(py+1, px);
3139 cave_lite_hack(py-1, px);
3140 cave_lite_hack(py, px+1);
3141 cave_lite_hack(py, px-1);
3143 /* Diagonal grids */
3144 cave_lite_hack(py+1, px+1);
3145 cave_lite_hack(py+1, px-1);
3146 cave_lite_hack(py-1, px+1);
3147 cave_lite_hack(py-1, px-1);
3150 /* Radius 2 -- lantern radius */
3153 /* South of the player */
3154 if (cave_floor_bold(py+1, px))
3156 cave_lite_hack(py+2, px);
3157 cave_lite_hack(py+2, px+1);
3158 cave_lite_hack(py+2, px-1);
3161 /* North of the player */
3162 if (cave_floor_bold(py-1, px))
3164 cave_lite_hack(py-2, px);
3165 cave_lite_hack(py-2, px+1);
3166 cave_lite_hack(py-2, px-1);
3169 /* East of the player */
3170 if (cave_floor_bold(py, px+1))
3172 cave_lite_hack(py, px+2);
3173 cave_lite_hack(py+1, px+2);
3174 cave_lite_hack(py-1, px+2);
3177 /* West of the player */
3178 if (cave_floor_bold(py, px-1))
3180 cave_lite_hack(py, px-2);
3181 cave_lite_hack(py+1, px-2);
3182 cave_lite_hack(py-1, px-2);
3186 /* Radius 3+ -- artifact radius */
3191 /* Paranoia -- see "LITE_MAX" */
3194 /* South-East of the player */
3195 if (cave_floor_bold(py+1, px+1))
3197 cave_lite_hack(py+2, px+2);
3200 /* South-West of the player */
3201 if (cave_floor_bold(py+1, px-1))
3203 cave_lite_hack(py+2, px-2);
3206 /* North-East of the player */
3207 if (cave_floor_bold(py-1, px+1))
3209 cave_lite_hack(py-2, px+2);
3212 /* North-West of the player */
3213 if (cave_floor_bold(py-1, px-1))
3215 cave_lite_hack(py-2, px-2);
3220 if (min_y < 0) min_y = 0;
3224 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3228 if (min_x < 0) min_x = 0;
3232 if (max_x > cur_wid-1) max_x = cur_wid-1;
3234 /* Scan the maximal box */
3235 for (y = min_y; y <= max_y; y++)
3237 for (x = min_x; x <= max_x; x++)
3239 int dy = (py > y) ? (py - y) : (y - py);
3240 int dx = (px > x) ? (px - x) : (x - px);
3242 /* Skip the "central" grids (above) */
3243 if ((dy <= 2) && (dx <= 2)) continue;
3245 /* Hack -- approximate the distance */
3246 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3248 /* Skip distant grids */
3249 if (d > p) continue;
3251 /* Viewable, nearby, grids get "torch lit" */
3252 if (player_has_los_bold(y, x))
3254 /* This grid is "torch lit" */
3255 cave_lite_hack(y, x);
3262 /*** Complete the algorithm ***/
3264 /* Draw the new grids */
3265 for (i = 0; i < lite_n; i++)
3270 /* Update fresh grids */
3271 if (cave[y][x].info & (CAVE_TEMP)) continue;
3280 /* Clear them all */
3281 for (i = 0; i < temp_n; i++)
3286 /* No longer in the array */
3287 cave[y][x].info &= ~(CAVE_TEMP);
3289 /* Update stale grids */
3290 if (cave[y][x].info & (CAVE_LITE)) continue;
3301 static bool mon_invis;
3304 * Add a square to the changes array
3306 static void mon_lite_hack(int y, int x)
3311 if (!in_bounds2(y, x)) return;
3313 c_ptr = &cave[y][x];
3315 /* Want a unlit square in view of the player */
3316 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3318 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3319 if (!cave_floor_grid(c_ptr) && mon_invis) return;
3321 /* Save this square */
3322 if (temp_n < TEMP_MAX)
3330 c_ptr->info |= CAVE_MNLT;
3337 * Update squares illuminated by monsters.
3339 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3340 * denote squares illuminated by monsters.
3342 * The CAVE_TEMP flag is used to store the state during the
3343 * updating. Only squares in view of the player, whos state
3344 * changes are drawn via lite_spot().
3346 void update_mon_lite(void)
3355 /* Clear all monster lit squares */
3356 for (i = 0; i < mon_lite_n; i++)
3359 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3362 c_ptr->info |= (CAVE_TEMP);
3364 /* Clear monster illumination flag */
3365 c_ptr->info &= ~(CAVE_MNLT);
3368 /* Empty temp list of new squares to lite up */
3371 /* Loop through monsters, adding newly lit squares to changes list */
3372 for (i = 1; i < m_max; i++)
3374 monster_type *m_ptr = &m_list[i];
3375 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3377 /* Skip dead monsters */
3378 if (!m_ptr->r_idx) continue;
3380 /* Is it too far away? */
3381 if (m_ptr->cdis > ((d_info[dungeon_type].flags1 & DF1_DARKNESS) ? MAX_SIGHT / 2 + 1 : MAX_SIGHT + 3)) continue;
3383 /* Get lite radius */
3386 /* Note the radii are cumulative */
3387 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3388 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3390 /* Exit if has no light */
3392 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3394 if (world_monster) continue;
3396 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3398 /* Access the location */
3402 /* Is the monster visible? */
3403 mon_invis = !(cave[fy][fx].info & CAVE_VIEW);
3405 /* The square it is on */
3406 mon_lite_hack(fy, fx);
3408 /* Adjacent squares */
3409 mon_lite_hack(fy + 1, fx);
3410 mon_lite_hack(fy - 1, fx);
3411 mon_lite_hack(fy, fx + 1);
3412 mon_lite_hack(fy, fx - 1);
3413 mon_lite_hack(fy + 1, fx + 1);
3414 mon_lite_hack(fy + 1, fx - 1);
3415 mon_lite_hack(fy - 1, fx + 1);
3416 mon_lite_hack(fy - 1, fx - 1);
3421 /* South of the monster */
3422 if (cave_floor_bold(fy + 1, fx))
3424 mon_lite_hack(fy + 2, fx + 1);
3425 mon_lite_hack(fy + 2, fx);
3426 mon_lite_hack(fy + 2, fx - 1);
3428 c_ptr = &cave[fy + 2][fx];
3431 if ((rad == 3) && cave_floor_grid(c_ptr))
3433 mon_lite_hack(fy + 3, fx + 1);
3434 mon_lite_hack(fy + 3, fx);
3435 mon_lite_hack(fy + 3, fx - 1);
3439 /* North of the monster */
3440 if (cave_floor_bold(fy - 1, fx))
3442 mon_lite_hack(fy - 2, fx + 1);
3443 mon_lite_hack(fy - 2, fx);
3444 mon_lite_hack(fy - 2, fx - 1);
3446 c_ptr = &cave[fy - 2][fx];
3449 if ((rad == 3) && cave_floor_grid(c_ptr))
3451 mon_lite_hack(fy - 3, fx + 1);
3452 mon_lite_hack(fy - 3, fx);
3453 mon_lite_hack(fy - 3, fx - 1);
3457 /* East of the monster */
3458 if (cave_floor_bold(fy, fx + 1))
3460 mon_lite_hack(fy + 1, fx + 2);
3461 mon_lite_hack(fy, fx + 2);
3462 mon_lite_hack(fy - 1, fx + 2);
3464 c_ptr = &cave[fy][fx + 2];
3467 if ((rad == 3) && cave_floor_grid(c_ptr))
3469 mon_lite_hack(fy + 1, fx + 3);
3470 mon_lite_hack(fy, fx + 3);
3471 mon_lite_hack(fy - 1, fx + 3);
3475 /* West of the monster */
3476 if (cave_floor_bold(fy, fx - 1))
3478 mon_lite_hack(fy + 1, fx - 2);
3479 mon_lite_hack(fy, fx - 2);
3480 mon_lite_hack(fy - 1, fx - 2);
3482 c_ptr = &cave[fy][fx - 2];
3485 if ((rad == 3) && cave_floor_grid(c_ptr))
3487 mon_lite_hack(fy + 1, fx - 3);
3488 mon_lite_hack(fy, fx - 3);
3489 mon_lite_hack(fy - 1, fx - 3);
3497 /* South-East of the monster */
3498 if (cave_floor_bold(fy + 1, fx + 1))
3500 mon_lite_hack(fy + 2, fx + 2);
3503 /* South-West of the monster */
3504 if (cave_floor_bold(fy + 1, fx - 1))
3506 mon_lite_hack(fy + 2, fx - 2);
3509 /* North-East of the monster */
3510 if (cave_floor_bold(fy - 1, fx + 1))
3512 mon_lite_hack(fy - 2, fx + 2);
3515 /* North-West of the monster */
3516 if (cave_floor_bold(fy - 1, fx - 1))
3518 mon_lite_hack(fy - 2, fx - 2);
3523 /* Save end of list of new squares */
3527 * Look at old set flags to see if there are any changes.
3529 for (i = 0; i < mon_lite_n; i++)
3534 if (!in_bounds2(fy, fx)) continue;
3537 c_ptr = &cave[fy][fx];
3539 /* It it no longer lit? */
3540 if (!(c_ptr->info & CAVE_MNLT) && player_has_los_grid(c_ptr))
3542 /* It is now unlit */
3547 /* Add to end of temp array */
3548 temp_x[temp_n] = (byte)fx;
3549 temp_y[temp_n] = (byte)fy;
3553 /* Clear the lite array */
3556 /* Copy the temp array into the lit array lighting the new squares. */
3557 for (i = 0; i < temp_n; i++)
3562 if (!in_bounds2(fy, fx)) continue;
3565 c_ptr = &cave[fy][fx];
3569 /* Clear the temp flag for the old lit grids */
3570 c_ptr->info &= ~(CAVE_TEMP);
3574 /* The is the square newly lit and visible? */
3575 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3582 /* Save in the monster lit array */
3583 mon_lite_x[mon_lite_n] = fx;
3584 mon_lite_y[mon_lite_n] = fy;
3589 /* Finished with temp_n */
3592 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3594 if (p_ptr->special_defense & NINJA_S_STEALTH)
3596 if (p_ptr->old_monlite != p_ptr->monlite)
3601 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3603 msg_print("Your mantle of shadow become thin.");
3609 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3611 msg_print("Your mantle of shadow restored its original darkness.");
3616 p_ptr->old_monlite = p_ptr->monlite;
3619 void clear_mon_lite(void)
3624 /* Clear all monster lit squares */
3625 for (i = 0; i < mon_lite_n; i++)
3628 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3630 /* Clear monster illumination flag */
3631 c_ptr->info &= ~(CAVE_MNLT);
3634 /* Empty the array */
3641 * Clear the viewable space
3643 void forget_view(void)
3649 /* None to forget */
3650 if (!view_n) return;
3652 /* Clear them all */
3653 for (i = 0; i < view_n; i++)
3658 /* Access the grid */
3659 c_ptr = &cave[y][x];
3661 /* Forget that the grid is viewable */
3662 c_ptr->info &= ~(CAVE_VIEW);
3664 if (!panel_contains(y, x)) continue;
3666 /* Update the screen */
3677 * This macro allows us to efficiently add a grid to the "view" array,
3678 * note that we are never called for illegal grids, or for grids which
3679 * have already been placed into the "view" array, and we are never
3680 * called when the "view" array is full.
3682 #define cave_view_hack(C,Y,X) \
3684 if (!((C)->info & (CAVE_VIEW))){\
3685 (C)->info |= (CAVE_VIEW); \
3686 view_y[view_n] = (Y); \
3687 view_x[view_n] = (X); \
3694 * Helper function for "update_view()" below
3696 * We are checking the "viewability" of grid (y,x) by the player.
3698 * This function assumes that (y,x) is legal (i.e. on the map).
3700 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3701 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3703 * Note that we are using the "CAVE_XTRA" field for marking grids as
3704 * "easily viewable". This bit is cleared at the end of "update_view()".
3706 * This function adds (y,x) to the "viewable set" if necessary.
3708 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3710 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3712 bool f1, f2, v1, v2, z1, z2, wall;
3716 cave_type *g1_c_ptr;
3717 cave_type *g2_c_ptr;
3719 /* Access the grids */
3720 g1_c_ptr = &cave[y1][x1];
3721 g2_c_ptr = &cave[y2][x2];
3724 /* Check for walls */
3725 f1 = (cave_floor_grid(g1_c_ptr));
3726 f2 = (cave_floor_grid(g2_c_ptr));
3728 /* Totally blocked by physical walls */
3729 if (!f1 && !f2) return (TRUE);
3732 /* Check for visibility */
3733 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3734 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3736 /* Totally blocked by "unviewable neighbors" */
3737 if (!v1 && !v2) return (TRUE);
3740 /* Access the grid */
3741 c_ptr = &cave[y][x];
3744 /* Check for walls */
3745 wall = (!cave_floor_grid(c_ptr));
3748 /* Check the "ease" of visibility */
3749 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3750 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3752 /* Hack -- "easy" plus "easy" yields "easy" */
3755 c_ptr->info |= (CAVE_XTRA);
3757 cave_view_hack(c_ptr, y, x);
3762 /* Hack -- primary "easy" yields "viewed" */
3765 cave_view_hack(c_ptr, y, x);
3770 /* Hack -- "view" plus "view" yields "view" */
3773 /* c_ptr->info |= (CAVE_XTRA); */
3775 cave_view_hack(c_ptr, y, x);
3781 /* Mega-Hack -- the "los()" function works poorly on walls */
3784 cave_view_hack(c_ptr, y, x);
3790 /* Hack -- check line of sight */
3791 if (los(py, px, y, x))
3793 cave_view_hack(c_ptr, y, x);
3799 /* Assume no line of sight. */
3806 * Calculate the viewable space
3808 * 1: Process the player
3809 * 1a: The player is always (easily) viewable
3810 * 2: Process the diagonals
3811 * 2a: The diagonals are (easily) viewable up to the first wall
3812 * 2b: But never go more than 2/3 of the "full" distance
3813 * 3: Process the main axes
3814 * 3a: The main axes are (easily) viewable up to the first wall
3815 * 3b: But never go more than the "full" distance
3816 * 4: Process sequential "strips" in each of the eight octants
3817 * 4a: Each strip runs along the previous strip
3818 * 4b: The main axes are "previous" to the first strip
3819 * 4c: Process both "sides" of each "direction" of each strip
3820 * 4c1: Each side aborts as soon as possible
3821 * 4c2: Each side tells the next strip how far it has to check
3823 * Note that the octant processing involves some pretty interesting
3824 * observations involving when a grid might possibly be viewable from
3825 * a given grid, and on the order in which the strips are processed.
3827 * Note the use of the mathematical facts shown below, which derive
3828 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3829 * hypotenuse of a right triangle is primarily determined by the length
3830 * of the longest side, when one side is small, and is strictly less
3831 * than one-and-a-half times as long as the longest side when both of
3832 * the sides are large.
3834 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3835 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3837 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3839 * These observations are important because the calculation of the actual
3840 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3841 * while for small values (up to about 20 or so), the approximations above
3842 * are correct to within an error of at most one grid or so.
3844 * Observe the use of "full" and "over" in the code below, and the use of
3845 * the specialized calculation involving "limit", all of which derive from
3846 * the observations given above. Basically, we note that the "circle" of
3847 * view is completely contained in an "octagon" whose bounds are easy to
3848 * determine, and that only a few steps are needed to derive the actual
3849 * bounds of the circle given the bounds of the octagon.
3851 * Note that by skipping all the grids in the corners of the octagon, we
3852 * place an upper limit on the number of grids in the field of view, given
3853 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3854 * view, only about 1475 of these are in the "octagon" of view, and even
3855 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3856 * entries to completely contain the actual field of view.
3858 * Note also the care taken to prevent "running off the map". The use of
3859 * explicit checks on the "validity" of the "diagonal", and the fact that
3860 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3861 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3862 * of multiple checks on the validity of grids.
3864 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3865 * "ws","wn" variables. They work like this: While travelling down the
3866 * south-bound strip just to the east of the main south axis, as soon as
3867 * we get to a grid which does not "transmit" viewing, if all of the strips
3868 * preceding us (in this case, just the main axis) had terminated at or before
3869 * the same point, then we can stop, and reset the "max distance" to ourself.
3870 * So, each strip (named by major axis plus offset, thus "se" in this case)
3871 * maintains a "blockage" variable, initialized during the main axis step,
3872 * and checks it whenever a blockage is observed. After processing each
3873 * strip as far as the previous strip told us to process, the next strip is
3874 * told not to go farther than the current strip's farthest viewable grid,
3875 * unless open space is still available. This uses the "k" variable.
3877 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3878 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3879 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3880 * chunk of code which adds the given location to the "view" array if it
3881 * is not already there, using both the actual location and a pointer to
3882 * the cave grid. See above.
3884 * By the way, the purpose of this code is to reduce the dependancy on the
3885 * "los()" function which is slow, and, in some cases, not very accurate.
3887 * It is very possible that I am the only person who fully understands this
3888 * function, and for that I am truly sorry, but efficiency was very important
3889 * and the "simple" version of this function was just not fast enough. I am
3890 * more than willing to replace this function with a simpler one, if it is
3891 * equally efficient, and especially willing if the new function happens to
3892 * derive "reverse-line-of-sight" at the same time, since currently monsters
3893 * just use an optimized hack of "you see me, so I see you", and then use the
3894 * actual "projectable()" function to check spell attacks.
3896 void update_view(void)
3898 int n, m, d, k, y, x, z;
3900 int se, sw, ne, nw, es, en, ws, wn;
3904 int y_max = cur_hgt - 1;
3905 int x_max = cur_wid - 1;
3909 /*** Initialize ***/
3912 if (view_reduce_view && !dun_level)
3914 /* Full radius (10) */
3915 full = MAX_SIGHT / 2;
3917 /* Octagon factor (15) */
3918 over = MAX_SIGHT * 3 / 4;
3924 /* Full radius (20) */
3927 /* Octagon factor (30) */
3928 over = MAX_SIGHT * 3 / 2;
3932 /*** Step 0 -- Begin ***/
3934 /* Save the old "view" grids for later */
3935 for (n = 0; n < view_n; n++)
3940 /* Access the grid */
3941 c_ptr = &cave[y][x];
3943 /* Mark the grid as not in "view" */
3944 c_ptr->info &= ~(CAVE_VIEW);
3946 /* Mark the grid as "seen" */
3947 c_ptr->info |= (CAVE_TEMP);
3949 /* Add it to the "seen" set */
3955 /* Start over with the "view" array */
3958 /*** Step 1 -- adjacent grids ***/
3960 /* Now start on the player */
3964 /* Access the grid */
3965 c_ptr = &cave[y][x];
3967 /* Assume the player grid is easily viewable */
3968 c_ptr->info |= (CAVE_XTRA);
3970 /* Assume the player grid is viewable */
3971 cave_view_hack(c_ptr, y, x);
3974 /*** Step 2 -- Major Diagonals ***/
3979 /* Scan south-east */
3980 for (d = 1; d <= z; d++)
3982 c_ptr = &cave[y+d][x+d];
3983 c_ptr->info |= (CAVE_XTRA);
3984 cave_view_hack(c_ptr, y+d, x+d);
3985 if (!cave_floor_grid(c_ptr)) break;
3988 /* Scan south-west */
3989 for (d = 1; d <= z; d++)
3991 c_ptr = &cave[y+d][x-d];
3992 c_ptr->info |= (CAVE_XTRA);
3993 cave_view_hack(c_ptr, y+d, x-d);
3994 if (!cave_floor_grid(c_ptr)) break;
3997 /* Scan north-east */
3998 for (d = 1; d <= z; d++)
4000 c_ptr = &cave[y-d][x+d];
4001 c_ptr->info |= (CAVE_XTRA);
4002 cave_view_hack(c_ptr, y-d, x+d);
4003 if (!cave_floor_grid(c_ptr)) break;
4006 /* Scan north-west */
4007 for (d = 1; d <= z; d++)
4009 c_ptr = &cave[y-d][x-d];
4010 c_ptr->info |= (CAVE_XTRA);
4011 cave_view_hack(c_ptr, y-d, x-d);
4012 if (!cave_floor_grid(c_ptr)) break;
4016 /*** Step 3 -- major axes ***/
4019 for (d = 1; d <= full; d++)
4021 c_ptr = &cave[y+d][x];
4022 c_ptr->info |= (CAVE_XTRA);
4023 cave_view_hack(c_ptr, y+d, x);
4024 if (!cave_floor_grid(c_ptr)) break;
4027 /* Initialize the "south strips" */
4031 for (d = 1; d <= full; d++)
4033 c_ptr = &cave[y-d][x];
4034 c_ptr->info |= (CAVE_XTRA);
4035 cave_view_hack(c_ptr, y-d, x);
4036 if (!cave_floor_grid(c_ptr)) break;
4039 /* Initialize the "north strips" */
4043 for (d = 1; d <= full; d++)
4045 c_ptr = &cave[y][x+d];
4046 c_ptr->info |= (CAVE_XTRA);
4047 cave_view_hack(c_ptr, y, x+d);
4048 if (!cave_floor_grid(c_ptr)) break;
4051 /* Initialize the "east strips" */
4055 for (d = 1; d <= full; d++)
4057 c_ptr = &cave[y][x-d];
4058 c_ptr->info |= (CAVE_XTRA);
4059 cave_view_hack(c_ptr, y, x-d);
4060 if (!cave_floor_grid(c_ptr)) break;
4063 /* Initialize the "west strips" */
4067 /*** Step 4 -- Divide each "octant" into "strips" ***/
4069 /* Now check each "diagonal" (in parallel) */
4070 for (n = 1; n <= over / 2; n++)
4072 int ypn, ymn, xpn, xmn;
4075 /* Acquire the "bounds" of the maximal circle */
4077 if (z > full - n) z = full - n;
4078 while ((z + n + (n>>1)) > full) z--;
4081 /* Access the four diagonal grids */
4091 /* Maximum distance */
4092 m = MIN(z, y_max - ypn);
4095 if ((xpn <= x_max) && (n < se))
4098 for (k = n, d = 1; d <= m; d++)
4100 /* Check grid "d" in strip "n", notice "blockage" */
4101 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
4103 if (n + d >= se) break;
4106 /* Track most distant "non-blockage" */
4113 /* Limit the next strip */
4118 if ((xmn >= 0) && (n < sw))
4121 for (k = n, d = 1; d <= m; d++)
4123 /* Check grid "d" in strip "n", notice "blockage" */
4124 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
4126 if (n + d >= sw) break;
4129 /* Track most distant "non-blockage" */
4136 /* Limit the next strip */
4145 /* Maximum distance */
4149 if ((xpn <= x_max) && (n < ne))
4152 for (k = n, d = 1; d <= m; d++)
4154 /* Check grid "d" in strip "n", notice "blockage" */
4155 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
4157 if (n + d >= ne) break;
4160 /* Track most distant "non-blockage" */
4167 /* Limit the next strip */
4172 if ((xmn >= 0) && (n < nw))
4175 for (k = n, d = 1; d <= m; d++)
4177 /* Check grid "d" in strip "n", notice "blockage" */
4178 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
4180 if (n + d >= nw) break;
4183 /* Track most distant "non-blockage" */
4190 /* Limit the next strip */
4199 /* Maximum distance */
4200 m = MIN(z, x_max - xpn);
4203 if ((ypn <= x_max) && (n < es))
4206 for (k = n, d = 1; d <= m; d++)
4208 /* Check grid "d" in strip "n", notice "blockage" */
4209 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
4211 if (n + d >= es) break;
4214 /* Track most distant "non-blockage" */
4221 /* Limit the next strip */
4226 if ((ymn >= 0) && (n < en))
4229 for (k = n, d = 1; d <= m; d++)
4231 /* Check grid "d" in strip "n", notice "blockage" */
4232 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4234 if (n + d >= en) break;
4237 /* Track most distant "non-blockage" */
4244 /* Limit the next strip */
4253 /* Maximum distance */
4257 if ((ypn <= y_max) && (n < ws))
4260 for (k = n, d = 1; d <= m; d++)
4262 /* Check grid "d" in strip "n", notice "blockage" */
4263 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4265 if (n + d >= ws) break;
4268 /* Track most distant "non-blockage" */
4275 /* Limit the next strip */
4280 if ((ymn >= 0) && (n < wn))
4283 for (k = n, d = 1; d <= m; d++)
4285 /* Check grid "d" in strip "n", notice "blockage" */
4286 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4288 if (n + d >= wn) break;
4291 /* Track most distant "non-blockage" */
4298 /* Limit the next strip */
4305 /*** Step 5 -- Complete the algorithm ***/
4307 /* Update all the new grids */
4308 for (n = 0; n < view_n; n++)
4313 /* Access the grid */
4314 c_ptr = &cave[y][x];
4316 /* Clear the "CAVE_XTRA" flag */
4317 c_ptr->info &= ~(CAVE_XTRA);
4319 /* Update only newly viewed grids */
4320 if (c_ptr->info & (CAVE_TEMP)) continue;
4329 /* Wipe the old grids, update as needed */
4330 for (n = 0; n < temp_n; n++)
4335 /* Access the grid */
4336 c_ptr = &cave[y][x];
4338 /* No longer in the array */
4339 c_ptr->info &= ~(CAVE_TEMP);
4341 /* Update only non-viewable grids */
4342 if (c_ptr->info & (CAVE_VIEW)) continue;
4358 * Hack -- provide some "speed" for the "flow" code
4359 * This entry is the "current index" for the "when" field
4360 * Note that a "when" value of "zero" means "not used".
4362 * Note that the "cost" indexes from 1 to 127 are for
4363 * "old" data, and from 128 to 255 are for "new" data.
4365 * This means that as long as the player does not "teleport",
4366 * then any monster up to 128 + MONSTER_FLOW_DEPTH will be
4367 * able to track down the player, and in general, will be
4368 * able to track down either the player or a position recently
4369 * occupied by the player.
4371 static int flow_n = 0;
4375 * Hack -- forget the "flow" information
4377 void forget_flow(void)
4381 /* Nothing to forget */
4382 if (!flow_n) return;
4384 /* Check the entire dungeon */
4385 for (y = 0; y < cur_hgt; y++)
4387 for (x = 0; x < cur_wid; x++)
4389 /* Forget the old data */
4390 cave[y][x].dist = 0;
4391 cave[y][x].cost = 0;
4392 cave[y][x].when = 0;
4402 * Hack - speed up the update_flow algorithm by only doing
4403 * it everytime the player moves out of LOS of the last
4406 static u16b flow_x = 0;
4407 static u16b flow_y = 0;
4412 * Hack -- fill in the "cost" field of every grid that the player
4413 * can "reach" with the number of steps needed to reach that grid.
4414 * This also yields the "distance" of the player from every grid.
4416 * In addition, mark the "when" of the grids that can reach
4417 * the player with the incremented value of "flow_n".
4419 * Hack -- use the "seen" array as a "circular queue".
4421 * We do not need a priority queue because the cost from grid
4422 * to grid is always "one" and we process them in order.
4424 void update_flow(void)
4430 /* Hack -- disabled */
4431 if (stupid_monsters) return;
4433 /* Paranoia -- make sure the array is empty */
4436 /* The last way-point is on the map */
4437 if (running && in_bounds(flow_y, flow_x))
4439 /* The way point is in sight - do not update. (Speedup) */
4440 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4443 /* Erase all of the current flow information */
4444 for (y = 0; y < cur_hgt; y++)
4446 for (x = 0; x < cur_wid; x++)
4448 cave[y][x].cost = 0;
4449 cave[y][x].dist = 0;
4453 /* Save player position */
4457 /* Add the player's grid to the queue */
4461 /* Now process the queue */
4462 while (flow_head != flow_tail)
4466 /* Extract the next entry */
4467 ty = temp_y[flow_tail];
4468 tx = temp_x[flow_tail];
4470 /* Forget that entry */
4471 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4473 /* Add the "children" */
4474 for (d = 0; d < 8; d++)
4476 int old_head = flow_head;
4477 int m = cave[ty][tx].cost + 1;
4478 int n = cave[ty][tx].dist + 1;
4481 /* Child location */
4482 y = ty + ddy_ddd[d];
4483 x = tx + ddx_ddd[d];
4485 /* Ignore player's grid */
4486 if (x == px && y == py) continue;
4488 c_ptr = &cave[y][x];
4490 if ((c_ptr->feat >= FEAT_DOOR_HEAD) && (c_ptr->feat <= FEAT_SECRET)) m += 3;
4492 /* Ignore "pre-stamped" entries */
4493 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4495 /* Ignore "walls" and "rubble" */
4496 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4498 /* Save the flow cost */
4499 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4500 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4502 /* Hack -- limit flow depth */
4503 if (n == MONSTER_FLOW_DEPTH) continue;
4505 /* Enqueue that entry */
4506 temp_y[flow_head] = y;
4507 temp_x[flow_head] = x;
4509 /* Advance the queue */
4510 if (++flow_head == TEMP_MAX) flow_head = 0;
4512 /* Hack -- notice overflow by forgetting new entry */
4513 if (flow_head == flow_tail) flow_head = old_head;
4519 static int scent_when = 0;
4522 * Characters leave scent trails for perceptive monsters to track.
4524 * Smell is rather more limited than sound. Many creatures cannot use
4525 * it at all, it doesn't extend very far outwards from the character's
4526 * current position, and monsters can use it to home in the character,
4527 * but not to run away from him.
4529 * Smell is valued according to age. When a character takes his turn,
4530 * scent is aged by one, and new scent of the current age is laid down.
4531 * Speedy characters leave more scent, true, but it also ages faster,
4532 * which makes it harder to hunt them down.
4534 * Whenever the age count loops, most of the scent trail is erased and
4535 * the age of the remainder is recalculated.
4537 void update_smell(void)
4542 /* Create a table that controls the spread of scent */
4543 const int scent_adjust[5][5] =
4552 /* Loop the age and adjust scent values when necessary */
4553 if (++scent_when == 254)
4555 /* Scan the entire dungeon */
4556 for (y = 0; y < cur_hgt; y++)
4558 for (x = 0; x < cur_wid; x++)
4560 int w = cave[y][x].when;
4561 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4570 /* Lay down new scent */
4571 for (i = 0; i < 5; i++)
4573 for (j = 0; j < 5; j++)
4577 /* Translate table to map grids */
4582 if (!in_bounds(y, x)) continue;
4584 c_ptr = &cave[y][x];
4586 /* Walls, water, and lava cannot hold scent. */
4587 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4589 /* Grid must not be blocked by walls from the character */
4590 if (!player_has_los_bold(y, x)) continue;
4592 /* Note grids that are too far away */
4593 if (scent_adjust[i][j] == -1) continue;
4595 /* Mark the grid with new scent */
4596 c_ptr->when = scent_when + scent_adjust[i][j];
4603 * Hack -- map the current panel (plus some) ala "magic mapping"
4605 void map_area(int range)
4611 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4613 /* Scan that area */
4614 for (y = 1; y < cur_hgt - 1; y++)
4616 for (x = 1; x < cur_wid - 1; x++)
4618 if (distance(py, px, y, x) > range) continue;
4620 c_ptr = &cave[y][x];
4622 /* All non-walls are "checked" */
4623 if ((c_ptr->feat < FEAT_SECRET) ||
4624 (c_ptr->feat == FEAT_RUBBLE) ||
4625 ((c_ptr->feat >= FEAT_MINOR_GLYPH) &&
4626 (c_ptr->feat <= FEAT_TREES)) ||
4627 (c_ptr->feat >= FEAT_TOWN))
4629 /* Memorize normal features */
4630 if ((c_ptr->feat > FEAT_INVIS) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4632 /* Memorize the object */
4633 c_ptr->info |= (CAVE_MARK);
4636 /* Memorize known walls */
4637 for (i = 0; i < 8; i++)
4639 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4641 /* Memorize walls (etc) */
4642 if ((c_ptr->feat >= FEAT_SECRET) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4644 /* Memorize the walls */
4645 c_ptr->info |= (CAVE_MARK);
4653 p_ptr->redraw |= (PR_MAP);
4656 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4662 * Light up the dungeon using "clairvoyance"
4664 * This function "illuminates" every grid in the dungeon, memorizes all
4665 * "objects", memorizes all grids as with magic mapping, and, under the
4666 * standard option settings (view_perma_grids but not view_torch_grids)
4667 * memorizes all floor grids too.
4669 * Note that if "view_perma_grids" is not set, we do not memorize floor
4670 * grids, since this would defeat the purpose of "view_perma_grids", not
4671 * that anyone seems to play without this option.
4673 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4674 * since this would prevent the use of "view_torch_grids" as a method to
4675 * keep track of what grids have been observed directly.
4677 void wiz_lite(bool wizard, bool ninja)
4681 /* Memorize objects */
4682 for (i = 1; i < o_max; i++)
4684 object_type *o_ptr = &o_list[i];
4686 /* Skip dead objects */
4687 if (!o_ptr->k_idx) continue;
4689 /* Skip held objects */
4690 if (o_ptr->held_m_idx) continue;
4693 /* Skip objects in vaults, if not a wizard. -LM- */
4694 if ((wizard == FALSE) &&
4695 (cave[o_ptr->iy][o_ptr->ix].info & (CAVE_ICKY))) continue;
4699 o_ptr->marked = TRUE;
4702 /* Scan all normal grids */
4703 for (y = 1; y < cur_hgt - 1; y++)
4705 /* Scan all normal grids */
4706 for (x = 1; x < cur_wid - 1; x++)
4708 cave_type *c_ptr = &cave[y][x];
4710 /* Process all non-walls */
4711 if (cave_floor_bold(y, x) || (c_ptr->feat == FEAT_RUBBLE) || (c_ptr->feat == FEAT_TREES) || (c_ptr->feat == FEAT_MOUNTAIN))
4713 /* Scan all neighbors */
4714 for (i = 0; i < 9; i++)
4716 int yy = y + ddy_ddd[i];
4717 int xx = x + ddx_ddd[i];
4720 c_ptr = &cave[yy][xx];
4722 /* Memorize normal features */
4725 /* Memorize the grid */
4726 c_ptr->info |= (CAVE_MARK);
4730 if ((c_ptr->feat > FEAT_INVIS))
4732 /* Memorize the grid */
4733 c_ptr->info |= (CAVE_MARK);
4736 /* Perma-lite the grid */
4737 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4739 c_ptr->info |= (CAVE_GLOW);
4741 /* Normally, memorize floors (see above) */
4742 if (view_perma_grids && !view_torch_grids)
4744 /* Memorize the grid */
4745 c_ptr->info |= (CAVE_MARK);
4754 /* Update the monsters */
4755 p_ptr->update |= (PU_MONSTERS);
4758 p_ptr->redraw |= (PR_MAP);
4761 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4766 * Forget the dungeon map (ala "Thinking of Maud...").
4773 /* Forget every grid */
4774 for (y = 0; y < cur_hgt; y++)
4776 for (x = 0; x < cur_wid; x++)
4778 cave_type *c_ptr = &cave[y][x];
4780 /* Process the grid */
4781 c_ptr->info &= ~(CAVE_MARK);
4785 /* Forget all objects */
4786 for (i = 1; i < o_max; i++)
4788 object_type *o_ptr = &o_list[i];
4790 /* Skip dead objects */
4791 if (!o_ptr->k_idx) continue;
4793 /* Skip held objects */
4794 if (o_ptr->held_m_idx) continue;
4796 /* Forget the object */
4797 o_ptr->marked = FALSE;
4800 /* Mega-Hack -- Forget the view and lite */
4801 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4803 /* Update the view and lite */
4804 p_ptr->update |= (PU_VIEW | PU_LITE);
4806 /* Update the monsters */
4807 p_ptr->update |= (PU_MONSTERS);
4810 p_ptr->redraw |= (PR_MAP);
4813 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4821 * Change the "feat" flag for a grid, and notice/redraw the grid
4823 void cave_set_feat(int y, int x, int feat)
4825 cave_type *c_ptr = &cave[y][x];
4827 /* Change the feature */
4837 /* Remove a mirror */
4838 void remove_mirror(int y, int x)
4840 /* Remove the mirror */
4841 cave[y][x].info &= ~(CAVE_IN_MIRROR);
4843 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4845 cave[y][x].info &= ~(CAVE_GLOW);
4846 if( !view_torch_grids )cave[y][x].info &= ~(CAVE_MARK);
4856 * Calculate "incremental motion". Used by project() and shoot().
4857 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4859 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4861 int dy, dx, dist, shift;
4863 /* Extract the distance travelled */
4864 dy = (*y < y1) ? y1 - *y : *y - y1;
4865 dx = (*x < x1) ? x1 - *x : *x - x1;
4867 /* Number of steps */
4868 dist = (dy > dx) ? dy : dx;
4870 /* We are calculating the next location */
4874 /* Calculate the total distance along each axis */
4875 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4876 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4878 /* Paranoia -- Hack -- no motion */
4879 if (!dy && !dx) return;
4882 /* Move mostly vertically */
4885 /* Extract a shift factor */
4886 shift = (dist * dx + (dy - 1) / 2) / dy;
4888 /* Sometimes move along the minor axis */
4889 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4891 /* Always move along major axis */
4892 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4895 /* Move mostly horizontally */
4898 /* Extract a shift factor */
4899 shift = (dist * dy + (dx - 1) / 2) / dx;
4901 /* Sometimes move along the minor axis */
4902 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4904 /* Always move along major axis */
4905 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4912 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4913 * at the final destination, assuming no monster gets in the way.
4915 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4917 bool projectable(int y1, int x1, int y2, int x2)
4924 /* Check the projection path */
4925 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4927 /* No grid is ever projectable from itself */
4928 if (!grid_n) return (FALSE);
4931 y = GRID_Y(grid_g[grid_n - 1]);
4932 x = GRID_X(grid_g[grid_n - 1]);
4934 /* May not end in an unrequested grid */
4935 if ((y != y2) || (x != x2)) return (FALSE);
4943 * Standard "find me a location" function
4945 * Obtains a legal location within the given distance of the initial
4946 * location, and with "los()" from the source to destination location.
4948 * This function is often called from inside a loop which searches for
4949 * locations while increasing the "d" distance.
4951 * Currently the "m" parameter is unused.
4953 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4960 /* Pick a location */
4963 /* Pick a new location */
4964 ny = rand_spread(y, d);
4965 nx = rand_spread(x, d);
4967 /* Ignore annoying locations */
4968 if (!in_bounds(ny, nx)) continue;
4970 /* Ignore "excessively distant" locations */
4971 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4973 /* Require "line of sight" */
4974 if (los(y, x, ny, nx)) break;
4977 /* Save the location */
4986 * Track a new monster
4988 void health_track(int m_idx)
4990 /* Track a new guy */
4991 p_ptr->health_who = m_idx;
4993 /* Redraw (later) */
4994 p_ptr->redraw |= (PR_HEALTH);
5000 * Hack -- track the given monster race
5002 void monster_race_track(int r_idx)
5004 /* Save this monster ID */
5005 p_ptr->monster_race_idx = r_idx;
5008 p_ptr->window |= (PW_MONSTER);
5014 * Hack -- track the given object kind
5016 void object_kind_track(int k_idx)
5018 /* Save this monster ID */
5019 p_ptr->object_kind_idx = k_idx;
5022 p_ptr->window |= (PW_OBJECT);
5028 * Something has happened to disturb the player.
5030 * The first arg indicates a major disturbance, which affects search.
5032 * The second arg is currently unused, but could induce output flush.
5034 * All disturbance cancels repeated commands, resting, and running.
5036 void disturb(int stop_search, int unused_flag)
5039 unused_flag = unused_flag;
5041 /* Cancel auto-commands */
5042 /* command_new = 0; */
5044 /* Cancel repeated commands */
5050 /* Redraw the state (later) */
5051 p_ptr->redraw |= (PR_STATE);
5054 /* Cancel Resting */
5055 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5058 set_action(ACTION_NONE);
5061 /* Cancel running */
5067 /* Check for new panel if appropriate */
5068 if (center_player && !center_running) verify_panel();
5070 /* Calculate torch radius */
5071 p_ptr->update |= (PU_TORCH);
5073 /* Update monster flow */
5074 p_ptr->update |= (PU_FLOW);
5077 /* Flush the input if requested */
5078 if (flush_disturb) flush();