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)
61 case FEAT_TRAP_TRAPDOOR:
63 case FEAT_TRAP_SPIKED_PIT:
64 case FEAT_TRAP_POISON_PIT:
65 case FEAT_TRAP_TY_CURSE:
66 case FEAT_TRAP_TELEPORT:
70 case FEAT_TRAP_LOSE_STR:
71 case FEAT_TRAP_LOSE_DEX:
72 case FEAT_TRAP_LOSE_CON:
74 case FEAT_TRAP_CONFUSE:
75 case FEAT_TRAP_POISON:
92 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,
93 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.
95 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
97 * The LOS begins at the center of the tile (x1,y1) and ends at the center of
98 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line
99 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
101 * We assume that the "mathematical corner" of a non-floor tile does not
102 * block line of sight.
104 * Because this function uses (short) ints for all calculations, overflow may
105 * occur if dx and dy exceed 90.
107 * Once all the degenerate cases are eliminated, the values "qx", "qy", and
108 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
109 * we can use integer arithmetic.
111 * We travel from start to finish along the longer axis, starting at the border
112 * between the first and second tiles, where the y offset = .5 * slope, taking
113 * into account the scale factor. See below.
115 * Also note that this function and the "move towards target" code do NOT
116 * share the same properties. Thus, you can see someone, target them, and
117 * then fire a bolt at them, but the bolt may hit a wall, not them. However,
118 * by clever choice of target locations, you can sometimes throw a "curve".
120 * Note that "line of sight" is not "reflexive" in all cases.
122 * Use the "projectable()" routine to test "spell/missile line of sight".
124 * Use the "update_view()" function to determine player line-of-sight.
126 bool los(int y1, int x1, int y2, int x2)
146 /* Slope, or 1/Slope, of LOS */
150 /* Extract the offset */
154 /* Extract the absolute offset */
159 /* Handle adjacent (or identical) grids */
160 if ((ax < 2) && (ay < 2)) return (TRUE);
163 /* Paranoia -- require "safe" origin */
164 /* if (!in_bounds(y1, x1)) return (FALSE); */
165 /* if (!in_bounds(y2, x2)) return (FALSE); */
168 /* Directly South/North */
171 /* South -- check for walls */
174 for (ty = y1 + 1; ty < y2; ty++)
176 if (!cave_floor_bold(ty, x1)) return (FALSE);
180 /* North -- check for walls */
183 for (ty = y1 - 1; ty > y2; ty--)
185 if (!cave_floor_bold(ty, x1)) return (FALSE);
193 /* Directly East/West */
196 /* East -- check for walls */
199 for (tx = x1 + 1; tx < x2; tx++)
201 if (!cave_floor_bold(y1, tx)) return (FALSE);
205 /* West -- check for walls */
208 for (tx = x1 - 1; tx > x2; tx--)
210 if (!cave_floor_bold(y1, tx)) return (FALSE);
219 /* Extract some signs */
220 sx = (dx < 0) ? -1 : 1;
221 sy = (dy < 0) ? -1 : 1;
224 /* Vertical "knights" */
229 if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
233 /* Horizontal "knights" */
238 if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
243 /* Calculate scale factor div 2 */
246 /* Calculate scale factor */
250 /* Travel horizontally */
253 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
259 /* Consider the special case where slope == 1. */
270 /* Note (below) the case (qy == f2), where */
271 /* the LOS exactly meets the corner of a tile. */
274 if (!cave_floor_bold(ty, tx)) return (FALSE);
285 if (!cave_floor_bold(ty, tx)) return (FALSE);
298 /* Travel vertically */
301 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
317 /* Note (below) the case (qx == f2), where */
318 /* the LOS exactly meets the corner of a tile. */
321 if (!cave_floor_bold(ty, tx)) return (FALSE);
332 if (!cave_floor_bold(ty, tx)) return (FALSE);
355 * Can the player "see" the given grid in detail?
357 * He must have vision, illumination, and line of sight.
359 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
360 * So, given "CAVE_LITE", we know that the grid is "fully visible".
362 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
363 * that a wall is visible from any direction. That would be odd. Except
364 * under wizard light, which might make sense. Thus, for walls, we require
365 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
366 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
367 * in line of sight of the player.
369 * This extra check is expensive, but it provides a more "correct" semantics.
371 * Note that we should not run this check on walls which are "outer walls" of
372 * the dungeon, or we will induce a memory fault, but actually verifying all
373 * of the locations would be extremely expensive.
375 * Thus, to speed up the function, we assume that all "perma-walls" which are
376 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
377 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
378 * and the player has more important things on his mind when he is attacking a
379 * monster vault. It is annoying, but an extremely important optimization.
381 * Note that "glowing walls" are only considered to be "illuminated" if the
382 * grid which is next to the wall in the direction of the player is also a
383 * "glowing" grid. This prevents the player from being able to "see" the
384 * walls of illuminated rooms from a corridor outside the room.
386 bool player_can_see_bold(int y, int x)
392 /* Blind players see nothing */
393 if (p_ptr->blind) return (FALSE);
395 /* Access the cave grid */
398 /* Note that "torch-lite" yields "illumination" */
399 if (c_ptr->info & (CAVE_LITE)) return (TRUE);
401 /* Require line of sight to the grid */
402 if (!player_has_los_bold(y, x)) return (FALSE);
404 if (p_ptr->pclass == CLASS_NINJA) return TRUE;
406 /* Require "perma-lite" of the grid */
407 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return (FALSE);
409 /* Floors are simple */
410 if (cave_floor_bold(y, x)) return (TRUE);
412 /* Hack -- move towards player */
413 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
414 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
416 /* Check for "local" illumination */
417 if (cave[yy][xx].info & (CAVE_GLOW | CAVE_MNLT))
419 /* Assume the wall is really illuminated */
423 /* Assume not visible */
430 * Returns true if the player's grid is dark
434 return (!player_can_see_bold(py, px));
441 * Determine if a given location may be "destroyed"
443 * Used by destruction spells, and for placing stairs, etc.
445 bool cave_valid_bold(int y, int x)
447 cave_type *c_ptr = &cave[y][x];
449 s16b this_o_idx, next_o_idx = 0;
452 /* Forbid perma-grids */
453 if (cave_perma_grid(c_ptr)) return (FALSE);
456 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
461 o_ptr = &o_list[this_o_idx];
463 /* Acquire next object */
464 next_o_idx = o_ptr->next_o_idx;
466 /* Forbid artifact grids */
467 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
478 * Determine if a given location may be "destroyed"
480 * Used by destruction spells, and for placing stairs, etc.
482 bool cave_valid_grid(cave_type *c_ptr)
484 s16b this_o_idx, next_o_idx = 0;
487 /* Forbid perma-grids */
488 if (cave_perma_grid(c_ptr)) return (FALSE);
491 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
496 o_ptr = &o_list[this_o_idx];
498 /* Acquire next object */
499 next_o_idx = o_ptr->next_o_idx;
501 /* Forbid artifact grids */
502 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
513 * Hack -- Legal monster codes
515 static cptr image_monster_hack = \
516 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
519 * Hack -- Legal monster codes for IBM pseudo-graphics
521 static cptr image_monster_hack_ibm = \
525 * Mega-Hack -- Hallucinatory monster
527 static void image_monster(byte *ap, char *cp)
529 int n = strlen(image_monster_hack);
531 /* Random symbol from set above */
534 /* Normal graphics */
535 if (!(streq(ANGBAND_SYS, "ibm")))
537 (*cp) = r_info[randint(max_r_idx-1)].x_char;
538 (*ap) = r_info[randint(max_r_idx-1)].x_attr;
541 /* IBM-pseudo graphics */
543 n = strlen(image_monster_hack_ibm);
544 (*cp) = (image_monster_hack_ibm[rand_int(n)]);
553 (*cp) = (image_monster_hack[rand_int(n)]);
563 * Hack -- Legal object codes
565 static cptr image_object_hack = \
566 "?/|\\\"!$()_-=[]{},~";
568 static cptr image_object_hack_ibm = \
572 * Mega-Hack -- Hallucinatory object
574 static void image_object(byte *ap, char *cp)
576 int n = strlen(image_object_hack);
580 if (!(streq(ANGBAND_SYS, "ibm")))
582 (*cp) = k_info[randint(max_k_idx-1)].x_char;
583 (*ap) = k_info[randint(max_k_idx-1)].x_attr;
587 n = strlen(image_object_hack_ibm);
588 (*cp) = (image_object_hack_ibm[rand_int(n)]);
596 (*cp) = (image_object_hack[rand_int(n)]);
606 * Hack -- Random hallucination
608 static void image_random(byte *ap, char *cp)
610 /* Normally, assume monsters */
611 if (rand_int(100) < 75)
613 image_monster(ap, cp);
616 /* Otherwise, assume objects */
619 image_object(ap, cp);
624 * Not using graphical tiles for this feature?
626 #define is_ascii_graphics(C , A) \
627 (!(((C) & 0x80) && ((A) & 0x80)))
630 * The 16x16 tile of the terrain supports lighting
632 static bool feat_supports_lighting(byte feat)
634 if (is_trap(feat)) return TRUE;
653 case FEAT_WALL_EXTRA:
654 case FEAT_WALL_INNER:
655 case FEAT_WALL_OUTER:
656 case FEAT_WALL_SOLID:
657 case FEAT_PERM_EXTRA:
658 case FEAT_PERM_INNER:
659 case FEAT_PERM_OUTER:
660 case FEAT_PERM_SOLID:
661 case FEAT_MINOR_GLYPH:
662 case FEAT_DEEP_WATER:
663 case FEAT_SHAL_WATER:
670 case FEAT_DEEP_GRASS:
681 * This array lists the effects of "brightness" on various "base" colours.
683 * This is used to do dynamic lighting effects in ascii :-)
684 * At the moment, only the various "floor" tiles are affected.
686 * The layout of the array is [x][0] = light and [x][1] = dark.
689 static byte lighting_colours[16][2] =
692 {TERM_L_DARK, TERM_DARK},
695 {TERM_YELLOW, TERM_SLATE},
698 {TERM_WHITE, TERM_L_DARK},
701 {TERM_YELLOW, TERM_UMBER},
704 {TERM_RED, TERM_RED},
707 {TERM_L_GREEN, TERM_GREEN},
710 {TERM_BLUE, TERM_BLUE},
713 {TERM_L_UMBER, TERM_RED},
716 {TERM_SLATE, TERM_L_DARK},
719 {TERM_WHITE, TERM_SLATE},
722 {TERM_L_RED, TERM_BLUE},
725 {TERM_YELLOW, TERM_ORANGE},
728 {TERM_L_RED, TERM_L_RED},
731 {TERM_L_GREEN, TERM_GREEN},
734 {TERM_L_BLUE, TERM_L_BLUE},
737 {TERM_YELLOW, TERM_UMBER}
741 * Extract the attr/char to display at the given (legal) map location
743 * Basically, we "paint" the chosen attr/char in several passes, starting
744 * with any known "terrain features" (defaulting to darkness), then adding
745 * any known "objects", and finally, adding any known "monsters". This
746 * is not the fastest method but since most of the calls to this function
747 * are made for grids with no monsters or objects, it is fast enough.
749 * Note that this function, if used on the grid containing the "player",
750 * will return the attr/char of the grid underneath the player, and not
751 * the actual player attr/char itself, allowing a lot of optimization
752 * in various "display" functions.
754 * Note that the "zero" entry in the feature/object/monster arrays are
755 * used to provide "special" attr/char codes, with "monster zero" being
756 * used for the player attr/char, "object zero" being used for the "stack"
757 * attr/char, and "feature zero" being used for the "nothing" attr/char,
758 * though this function makes use of only "feature zero".
760 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
761 * which means their color changes, and "ATTR_CLEAR", which means they take
762 * the color of whatever is under them, and "CHAR_CLEAR", which means that
763 * they take the symbol of whatever is under them. Technically, the flag
764 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
765 * examined, but this flag is currently ignored.
767 * Currently, we do nothing with multi-hued objects, because there are
768 * not any. If there were, they would have to set "shimmer_objects"
769 * when they were created, and then new "shimmer" code in "dungeon.c"
770 * would have to be created handle the "shimmer" effect, and the code
771 * in "cave.c" would have to be updated to create the shimmer effect.
773 * Note the effects of hallucination. Objects always appear as random
774 * "objects", monsters as random "monsters", and normal grids occasionally
775 * appear as random "monsters" or "objects", but note that these random
776 * "monsters" and "objects" are really just "colored ascii symbols".
778 * Note that "floors" and "invisible traps" (and "zero" features) are
779 * drawn as "floors" using a special check for optimization purposes,
780 * and these are the only features which get drawn using the special
781 * lighting effects activated by "view_special_lite".
783 * Note the use of the "mimic" field in the "terrain feature" processing,
784 * which allows any feature to "pretend" to be another feature. This is
785 * used to "hide" secret doors, and to make all "doors" appear the same,
786 * and all "walls" appear the same, and "hidden" treasure stay hidden.
787 * It is possible to use this field to make a feature "look" like a floor,
788 * but the "special lighting effects" for floors will not be used.
790 * Note the use of the new "terrain feature" information. Note that the
791 * assumption that all interesting "objects" and "terrain features" are
792 * memorized allows extremely optimized processing below. Note the use
793 * of separate flags on objects to mark them as memorized allows a grid
794 * to have memorized "terrain" without granting knowledge of any object
795 * which may appear in that grid.
797 * Note the efficient code used to determine if a "floor" grid is
798 * "memorized" or "viewable" by the player, where the test for the
799 * grid being "viewable" is based on the facts that (1) the grid
800 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
801 * line of sight, and (3) the player must not be blind, and uses the
802 * assumption that all torch-lit grids are in line of sight.
804 * Note that floors (and invisible traps) are the only grids which are
805 * not memorized when seen, so only these grids need to check to see if
806 * the grid is "viewable" to the player (if it is not memorized). Since
807 * most non-memorized grids are in fact walls, this induces *massive*
808 * efficiency, at the cost of *forcing* the memorization of non-floor
809 * grids when they are first seen. Note that "invisible traps" are
810 * always treated exactly like "floors", which prevents "cheating".
812 * Note the "special lighting effects" which can be activated for floor
813 * grids using the "view_special_lite" option (for "white" floor grids),
814 * causing certain grids to be displayed using special colors. If the
815 * player is "blind", we will use "dark gray", else if the grid is lit
816 * by the torch, and the "view_yellow_lite" option is set, we will use
817 * "yellow", else if the grid is "dark", we will use "dark gray", else
818 * if the grid is not "viewable", and the "view_bright_lite" option is
819 * set, and the we will use "slate" (gray). We will use "white" for all
820 * other cases, in particular, for illuminated viewable floor grids.
822 * Note the "special lighting effects" which can be activated for wall
823 * grids using the "view_granite_lite" option (for "white" wall grids),
824 * causing certain grids to be displayed using special colors. If the
825 * player is "blind", we will use "dark gray", else if the grid is lit
826 * by the torch, and the "view_yellow_lite" option is set, we will use
827 * "yellow", else if the "view_bright_lite" option is set, and the grid
828 * is not "viewable", or is "dark", or is glowing, but not when viewed
829 * from the player's current location, we will use "slate" (gray). We
830 * will use "white" for all other cases, in particular, for correctly
831 * illuminated viewable wall grids.
833 * Note that, when "view_granite_lite" is set, we use an inline version
834 * of the "player_can_see_bold()" function to check the "viewability" of
835 * grids when the "view_bright_lite" option is set, and we do NOT use
836 * any special colors for "dark" wall grids, since this would allow the
837 * player to notice the walls of illuminated rooms from a hallway that
838 * happened to run beside the room. The alternative, by the way, would
839 * be to prevent the generation of hallways next to rooms, but this
840 * would still allow problems when digging towards a room.
842 * Note that bizarre things must be done when the "attr" and/or "char"
843 * codes have the "high-bit" set, since these values are used to encode
844 * various "special" pictures in some versions, and certain situations,
845 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
846 * to be "scrambled" in various ways.
848 * Note that eventually we may use the "&" symbol for embedded treasure,
849 * and use the "*" symbol to indicate multiple objects, though this will
850 * have to wait for Angband 2.8.0 or later. Note that currently, this
851 * is not important, since only one object or terrain feature is allowed
852 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
854 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
855 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
856 * then a whole lot of code should be changed... XXX XXX
858 #ifdef USE_TRANSPARENCY
859 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
860 #else /* USE_TRANSPARENCY */
861 void map_info(int y, int x, byte *ap, char *cp)
862 #endif /* USE_TRANSPARENCY */
868 s16b this_o_idx, next_o_idx = 0;
882 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
884 /* Memorized (or visible) floor */
885 if ((c_ptr->info & CAVE_MARK) ||
886 (((c_ptr->info & CAVE_LITE) || (c_ptr->info & CAVE_MNLT) ||
887 ((c_ptr->info & CAVE_GLOW) &&
888 (c_ptr->info & CAVE_VIEW))) &&
892 f_ptr = &f_info[feat];
900 /* Special lighting effects */
901 if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_graphics))
906 if (new_ascii_graphics)
908 if (is_ascii_graphics(c,a))
910 /* Use darkened colour */
911 a = lighting_colours[a][1];
913 else if (use_graphics && feat_supports_lighting(feat))
915 /* Use a dark tile */
923 /* Use a dark tile */
928 /* Use "dark gray" */
934 /* Handle "torch-lit" grids */
935 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
938 if (view_yellow_lite && !p_ptr->wild_mode)
940 if (new_ascii_graphics)
942 if (is_ascii_graphics(c,a))
944 /* Use lightened colour */
945 a = lighting_colours[a][0];
947 else if (use_graphics &&
948 feat_supports_lighting(feat))
950 /* Use a brightly lit tile */
957 if (view_yellow_lite)
961 /* Use a brightly lit tile */
974 /* Handle "dark" grids */
975 else if (!(c_ptr->info & CAVE_GLOW))
977 if (new_ascii_graphics)
979 if (is_ascii_graphics(c,a))
981 /* Use darkened colour */
982 a = lighting_colours[a][1];
984 else if (use_graphics && feat_supports_lighting(feat))
986 /* Use a dark tile */
994 /* Use a dark tile */
999 /* Use "dark gray" */
1005 /* Handle "out-of-sight" grids */
1006 else if (!(c_ptr->info & CAVE_VIEW))
1009 if (view_bright_lite && !p_ptr->wild_mode)
1011 if (new_ascii_graphics)
1013 if (is_ascii_graphics(c,a))
1015 /* Use darkened colour */
1016 a = lighting_colours[a][1];
1018 else if (use_graphics && feat_supports_lighting(feat))
1020 /* Use a dark tile */
1028 /* Use a dark tile */
1047 /* Access darkness */
1048 f_ptr = &f_info[feat];
1061 /* Memorized grids */
1062 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || !new_ascii_graphics))
1064 /* Apply "mimic" field */
1066 feat = c_ptr->mimic;
1068 feat = f_info[feat].mimic;
1070 /* Access feature */
1071 f_ptr = &f_info[feat];
1079 if (new_ascii_graphics)
1081 /* Handle "blind" */
1084 if (is_ascii_graphics(c,a))
1086 /* Use darkened colour */
1087 a = lighting_colours[a][1];
1089 else if (use_graphics && feat_supports_lighting(feat))
1091 /* Use a dark tile */
1096 /* Handle "torch-lit" grids */
1097 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1100 if (view_yellow_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1102 if (is_ascii_graphics(c,a))
1104 /* Use lightened colour */
1105 a = lighting_colours[a][0];
1107 else if (use_graphics &&
1108 feat_supports_lighting(c_ptr->feat))
1110 /* Use a brightly lit tile */
1116 /* Handle "view_bright_lite" */
1117 else if (view_bright_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1120 if (!(c_ptr->info & CAVE_VIEW))
1122 if (is_ascii_graphics(c,a))
1124 /* Use darkened colour */
1125 a = lighting_colours[a][1];
1127 else if (use_graphics && feat_supports_lighting(feat))
1129 /* Use a dark tile */
1135 else if (!(c_ptr->info & CAVE_GLOW))
1137 if (is_ascii_graphics(c,a))
1139 /* Use darkened colour */
1140 a = lighting_colours[a][1];
1145 /* Special lighting effects */
1146 else if (view_granite_lite && !p_ptr->wild_mode &&
1147 (((a == TERM_WHITE) && !use_graphics) ||
1148 (use_graphics && feat_supports_lighting(c_ptr->feat))))
1150 /* Handle "blind" */
1155 /* Use a dark tile */
1160 /* Use "dark gray" */
1165 /* Handle "torch-lit" grids */
1166 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1169 if (view_yellow_lite && !p_ptr->wild_mode)
1173 /* Use a brightly lit tile */
1184 /* Handle "view_bright_lite" */
1185 else if (view_bright_lite && !p_ptr->wild_mode)
1188 if (!(c_ptr->info & CAVE_VIEW))
1192 /* Use a dark tile */
1203 else if (!(c_ptr->info & CAVE_GLOW))
1207 /* Use a lit tile */
1216 /* Not glowing correctly */
1221 /* Hack -- move towards player */
1222 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1223 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1225 /* Check for "local" illumination */
1226 if (!(cave[yy][xx].info & CAVE_GLOW))
1230 /* Use a lit tile */
1243 /* "Simple Lighting" */
1246 /* Handle "blind" */
1247 if (!(c_ptr->info & CAVE_MARK))
1252 /* Access feature */
1253 f_ptr = &f_info[feat];
1263 if (feat_priority == -1)
1274 case FEAT_TRAP_TRAPDOOR:
1276 case FEAT_TRAP_SPIKED_PIT:
1277 case FEAT_TRAP_POISON_PIT:
1278 case FEAT_TRAP_TY_CURSE:
1279 case FEAT_TRAP_TELEPORT:
1280 case FEAT_TRAP_FIRE:
1281 case FEAT_TRAP_ACID:
1282 case FEAT_TRAP_SLOW:
1283 case FEAT_TRAP_LOSE_STR:
1284 case FEAT_TRAP_LOSE_DEX:
1285 case FEAT_TRAP_LOSE_CON:
1286 case FEAT_TRAP_BLIND:
1287 case FEAT_TRAP_CONFUSE:
1288 case FEAT_TRAP_POISON:
1289 case FEAT_TRAP_SLEEP:
1290 case FEAT_TRAP_TRAPS:
1294 case FEAT_DEEP_GRASS:
1303 case FEAT_WALL_EXTRA:
1304 case FEAT_WALL_INNER:
1305 case FEAT_WALL_OUTER:
1306 case FEAT_WALL_SOLID:
1307 case FEAT_DEEP_WATER:
1308 case FEAT_SHAL_WATER:
1309 case FEAT_DEEP_LAVA:
1310 case FEAT_SHAL_LAVA:
1320 case FEAT_PERM_EXTRA:
1321 case FEAT_PERM_INNER:
1322 case FEAT_PERM_OUTER:
1323 case FEAT_PERM_SOLID:
1327 /* default is feat_priority = 20; (doors and stores) */
1330 case FEAT_MINOR_GLYPH:
1332 case FEAT_PATTERN_START:
1333 case FEAT_PATTERN_1:
1334 case FEAT_PATTERN_2:
1335 case FEAT_PATTERN_3:
1336 case FEAT_PATTERN_4:
1337 case FEAT_PATTERN_END:
1338 case FEAT_PATTERN_OLD:
1339 case FEAT_PATTERN_XTRA1:
1340 case FEAT_PATTERN_XTRA2:
1344 /* objects have feat_priority = 20 */
1345 /* monsters have feat_priority = 30 */
1349 case FEAT_QUEST_ENTER:
1350 case FEAT_QUEST_EXIT:
1351 case FEAT_QUEST_DOWN:
1353 case FEAT_LESS_LESS:
1354 case FEAT_MORE_MORE:
1366 /* Hack -- rare random hallucination, except on outer dungeon walls */
1367 if (p_ptr->image && (c_ptr->feat < FEAT_PERM_SOLID) && !rand_int(256))
1370 image_random(ap, cp);
1373 #ifdef USE_TRANSPARENCY
1374 /* Save the terrain info for the transparency effects */
1377 #endif /* USE_TRANSPARENCY */
1384 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1388 /* Acquire object */
1389 o_ptr = &o_list[this_o_idx];
1391 /* Acquire next object */
1392 next_o_idx = o_ptr->next_o_idx;
1394 /* Memorized objects */
1397 if (display_autopick)
1401 match_autopick = is_autopick(o_ptr);
1402 if(match_autopick == -1)
1405 act = autopick_action[match_autopick];
1407 if ((act & DO_DISPLAY) && (act & display_autopick))
1409 autopick_obj = o_ptr;
1413 match_autopick = -1;
1418 (*cp) = object_char(o_ptr);
1421 (*ap) = object_attr(o_ptr);
1425 /* Hack -- hallucination */
1426 if (p_ptr->image) image_object(ap, cp);
1434 /* Handle monsters */
1435 if (c_ptr->m_idx && display_autopick == 0 )
1437 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1439 /* Visible monster */
1442 monster_race *r_ptr;
1443 if (m_ptr->mflag2 & MFLAG_KAGE) r_ptr = &r_info[MON_KAGE];
1444 else r_ptr = &r_info[m_ptr->r_idx];
1454 /* Mimics' colors vary */
1455 if (strchr("\"!=", c) && !(r_ptr->flags1 & RF1_UNIQUE))
1460 /* Use semi-random attr */
1461 (*ap) = c_ptr->m_idx % 15 + 1;
1464 /* Special attr/char codes */
1465 else if ((a & 0x80) && (c & 0x80))
1474 /* Multi-hued monster */
1475 else if (r_ptr->flags1 & (RF1_ATTR_MULTI))
1477 /* Is it a shapechanger? */
1478 if (r_ptr->flags2 & (RF2_SHAPECHANGER))
1482 if (!(streq(ANGBAND_SYS, "ibm")))
1484 (*cp) = r_info[randint(max_r_idx-1)].x_char;
1485 (*ap) = r_info[randint(max_r_idx-1)].x_attr;
1489 int n = strlen(image_monster_hack_ibm);
1490 (*cp) = (image_monster_hack_ibm[rand_int(n)]);
1493 (*ap) = randint(15);
1498 (*cp) = (randint(25) == 1 ?
1499 image_object_hack[rand_int(strlen(image_object_hack))] :
1500 image_monster_hack[rand_int(strlen(image_monster_hack))]);
1506 /* Multi-hued attr */
1507 if (r_ptr->flags2 & RF2_ATTR_ANY)
1508 (*ap) = randint(15);
1509 else switch (randint(7))
1521 (*ap) = TERM_L_GREEN;
1527 (*ap) = TERM_L_DARK;
1535 /* Normal monster (not "clear" in any way) */
1536 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR | RF1_CHAR_CLEAR)))
1545 /* Hack -- Bizarre grid under monster */
1546 else if ((*ap & 0x80) || (*cp & 0x80))
1558 /* Normal (non-clear char) monster */
1559 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR)))
1565 /* Normal (non-clear attr) monster */
1566 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR)))
1573 /* Hack -- hallucination */
1576 /* Hallucinatory monster */
1577 image_monster(ap, cp);
1582 /* Handle "player" */
1583 if ((y == py) && (x == px))
1585 monster_race *r_ptr = &r_info[0];
1589 /* Get the "player" attr */
1592 /* Get the "player" char */
1595 #ifdef VARIABLE_PLAYER_GRAPH
1597 if (!streq(ANGBAND_GRAF, "new"))
1599 if (streq(ANGBAND_SYS,"ibm"))
1601 if (use_graphics && player_symbols)
1603 if (p_ptr->psex == SEX_FEMALE) c = (char)242;
1604 switch (p_ptr->pclass)
1607 if (p_ptr->lev < 20)
1613 case CLASS_WARRIOR_MAGE:
1614 case CLASS_RED_MAGE:
1615 if (p_ptr->lev < 20)
1620 case CLASS_CHAOS_WARRIOR:
1625 while (a == TERM_DARK);
1628 case CLASS_HIGH_MAGE:
1629 case CLASS_SORCERER:
1630 case CLASS_MAGIC_EATER:
1631 case CLASS_BLUE_MAGE:
1632 if (p_ptr->lev < 20)
1640 if (p_ptr->lev < 20)
1648 if (p_ptr->lev < 20)
1655 if (p_ptr->lev < 20)
1662 case CLASS_BERSERKER:
1664 if (p_ptr->lev < 20)
1670 case CLASS_MINDCRAFTER:
1671 case CLASS_FORCETRAINER:
1672 case CLASS_MIRROR_MASTER:
1673 if (p_ptr->lev < 20)
1679 default: /* Unknown */
1683 switch (p_ptr->prace)
1695 case RACE_HALF_TROLL:
1705 case RACE_HALF_OGRE:
1708 case RACE_HALF_GIANT:
1709 case RACE_HALF_TITAN:
1728 case RACE_DRACONIAN:
1729 if (p_ptr->lev < 20)
1731 else if (p_ptr->lev < 40)
1736 case RACE_MIND_FLAYER:
1747 if (p_ptr->pclass == CLASS_MAGE ||
1748 p_ptr->pclass == CLASS_PRIEST ||
1749 p_ptr->pclass == CLASS_HIGH_MAGE ||
1750 p_ptr->pclass == CLASS_SORCERER ||
1751 p_ptr->pclass == CLASS_MONK ||
1752 p_ptr->pclass == CLASS_FORCETRAINER ||
1753 p_ptr->pclass == CLASS_BLUE_MAGE ||
1754 p_ptr->pclass == CLASS_MIRROR_MASTER ||
1755 p_ptr->pclass == CLASS_MINDCRAFTER)
1789 #endif /* VARIABLE_PLAYER_GRAPH */
1797 * Moves the cursor to a given MAP (y,x) location
1799 void move_cursor_relative(int row, int col)
1801 /* Real co-ords convert to screen positions */
1802 row -= panel_row_prt;
1803 col -= panel_col_prt;
1806 Term_gotoxy(col, row);
1812 * Place an attr/char pair at the given map coordinate, if legal.
1814 void print_rel(char c, byte a, int y, int x)
1816 /* Only do "legal" locations */
1817 if (panel_contains(y, x))
1819 /* Hack -- fake monochrome */
1820 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
1822 if (world_monster) a = TERM_DARK;
1823 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
1824 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
1825 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1828 /* Draw the char using the attr */
1829 Term_draw(x-panel_col_prt, y-panel_row_prt, a, c);
1838 * Memorize interesting viewable object/features in the given grid
1840 * This function should only be called on "legal" grids.
1842 * This function will memorize the object and/or feature in the given
1843 * grid, if they are (1) viewable and (2) interesting. Note that all
1844 * objects are interesting, all terrain features except floors (and
1845 * invisible traps) are interesting, and floors (and invisible traps)
1846 * are interesting sometimes (depending on various options involving
1847 * the illumination of floor grids).
1849 * The automatic memorization of all objects and non-floor terrain
1850 * features as soon as they are displayed allows incredible amounts
1851 * of optimization in various places, especially "map_info()".
1853 * Note that the memorization of objects is completely separate from
1854 * the memorization of terrain features, preventing annoying floor
1855 * memorization when a detected object is picked up from a dark floor,
1856 * and object memorization when an object is dropped into a floor grid
1857 * which is memorized but out-of-sight.
1859 * This function should be called every time the "memorization" of
1860 * a grid (or the object in a grid) is called into question, such
1861 * as when an object is created in a grid, when a terrain feature
1862 * "changes" from "floor" to "non-floor", when any grid becomes
1863 * "illuminated" or "viewable", and when a "floor" grid becomes
1866 * Note the relatively efficient use of this function by the various
1867 * "update_view()" and "update_lite()" calls, to allow objects and
1868 * terrain features to be memorized (and drawn) whenever they become
1869 * viewable or illuminated in any way, but not when they "maintain"
1870 * or "lose" their previous viewability or illumination.
1872 * Note the butchered "internal" version of "player_can_see_bold()",
1873 * optimized primarily for the most common cases, that is, for the
1874 * non-marked floor grids.
1876 void note_spot(int y, int x)
1878 cave_type *c_ptr = &cave[y][x];
1880 s16b this_o_idx, next_o_idx = 0;
1883 /* Blind players see nothing */
1884 if (p_ptr->blind) return;
1886 /* Analyze non-torch-lit grids */
1887 if (!(c_ptr->info & (CAVE_LITE)))
1889 /* Require line of sight to the grid */
1890 if (!(c_ptr->info & (CAVE_VIEW))) return;
1892 if (p_ptr->pclass != CLASS_NINJA)
1894 /* Require "perma-lite" of the grid */
1895 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return;
1900 /* Hack -- memorize objects */
1901 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1903 object_type *o_ptr = &o_list[this_o_idx];
1905 /* Acquire next object */
1906 next_o_idx = o_ptr->next_o_idx;
1908 /* Memorize objects */
1909 o_ptr->marked = TRUE;
1913 /* Hack -- memorize grids */
1914 if (!(c_ptr->info & (CAVE_MARK)))
1916 if (p_ptr->pclass == CLASS_NINJA)
1918 c_ptr->info |= (CAVE_MARK);
1920 /* Handle floor grids first */
1921 if ((c_ptr->feat <= FEAT_INVIS) || (c_ptr->feat == FEAT_DIRT) || (c_ptr->feat == FEAT_GRASS))
1923 /* Option -- memorize all torch-lit floors */
1924 if (view_torch_grids && (c_ptr->info & (CAVE_LITE)))
1927 c_ptr->info |= (CAVE_MARK);
1930 /* Option -- memorize all perma-lit floors */
1931 else if (view_perma_grids && (c_ptr->info & (CAVE_GLOW)))
1934 c_ptr->info |= (CAVE_MARK);
1938 /* Memorize normal grids */
1939 else if (cave_floor_grid(c_ptr))
1942 c_ptr->info |= (CAVE_MARK);
1945 /* Memorize torch-lit walls */
1946 else if (c_ptr->info & (CAVE_LITE))
1949 c_ptr->info |= (CAVE_MARK);
1952 /* Memorize certain non-torch-lit wall grids */
1957 /* Hack -- move one grid towards player */
1958 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1959 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1961 /* Check for "local" illumination */
1962 if (cave[yy][xx].info & (CAVE_GLOW))
1965 c_ptr->info |= (CAVE_MARK);
1972 void display_dungeon(void)
1978 #ifdef USE_TRANSPARENCY
1981 #endif /* USE_TRANSPARENCY */
1983 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1985 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1987 if (in_bounds2(y, x))
1990 #ifdef USE_TRANSPARENCY
1991 /* Examine the grid */
1992 map_info(y, x, &a, &c, &ta, &tc);
1993 #else /* USE_TRANSPARENCY */
1994 /* Examine the grid */
1995 map_info(y, x, &a, &c);
1996 #endif /* USE_TRANSPARENCY */
1998 /* Hack -- fake monochrome */
1999 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2001 if (world_monster) a = TERM_DARK;
2002 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2003 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2004 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2007 #ifdef USE_TRANSPARENCY
2008 /* Hack -- Queue it */
2009 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2010 #else /* USE_TRANSPARENCY */
2011 /* Hack -- Queue it */
2012 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2013 #endif /* USE_TRANSPARENCY */
2018 /* Clear out-of-bound tiles */
2020 /* Access darkness */
2021 feature_type *f_ptr = &f_info[FEAT_NONE];
2029 #ifdef USE_TRANSPARENCY
2030 /* Hack -- Queue it */
2031 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2032 #else /* USE_TRANSPARENCY */
2033 /* Hack -- Queue it */
2034 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2035 #endif /* USE_TRANSPARENCY */
2043 * Redraw (on the screen) a given MAP location
2045 * This function should only be called on "legal" grids
2047 void lite_spot(int y, int x)
2049 /* Redraw if on screen */
2050 if (panel_contains(y, x))
2055 #ifdef USE_TRANSPARENCY
2059 /* Examine the grid */
2060 map_info(y, x, &a, &c, &ta, &tc);
2061 #else /* USE_TRANSPARENCY */
2062 /* Examine the grid */
2063 map_info(y, x, &a, &c);
2064 #endif /* USE_TRANSPARENCY */
2066 /* Hack -- fake monochrome */
2067 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2069 if (world_monster) a = TERM_DARK;
2070 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2071 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2072 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2075 #ifdef USE_TRANSPARENCY
2076 /* Hack -- Queue it */
2077 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c, ta, tc);
2078 #else /* USE_TRANSPARENCY */
2079 /* Hack -- Queue it */
2080 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c);
2081 #endif /* USE_TRANSPARENCY */
2087 * Prints the map of the dungeon
2089 * Note that, for efficiency, we contain an "optimized" version
2090 * of both "lite_spot()" and "print_rel()", and that we use the
2091 * "lite_spot()" function to display the player grid, if needed.
2097 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2100 /* Access the cursor state */
2101 (void)Term_get_cursor(&v);
2103 /* Hide the cursor */
2104 (void)Term_set_cursor(0);
2107 for (y = panel_row_min; y <= panel_row_max; y++)
2109 /* Scan the columns of row "y" */
2110 for (x = panel_col_min; x <= panel_col_max; x++)
2115 #ifdef USE_TRANSPARENCY
2119 /* Determine what is there */
2120 map_info(y, x, &a, &c, &ta, &tc);
2122 /* Hack -- fake monochrome */
2123 if (fake_monochrome)
2125 if (world_monster) a = TERM_DARK;
2126 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2127 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2128 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2131 /* Efficiency -- Redraw that grid of the map */
2132 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c, ta, tc);
2133 #else /* USE_TRANSPARENCY */
2134 /* Determine what is there */
2135 map_info(y, x, &a, &c);
2137 /* Hack -- fake monochrome */
2138 if (fake_monochrome)
2140 if (world_monster) a = TERM_DARK;
2141 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2142 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2143 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2146 /* Efficiency -- Redraw that grid of the map */
2147 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c);
2148 #endif /* USE_TRANSPARENCY */
2152 /* Display player */
2155 /* Restore the cursor */
2156 (void)Term_set_cursor(v);
2162 * print project path
2164 void prt_path(int y, int x)
2169 int default_color = TERM_SLATE;
2170 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2172 if (!display_path) return;
2173 if (-1 == project_length)
2176 /* Get projection path */
2177 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2180 p_ptr->redraw |= (PR_MAP);
2186 for (i = 0; i < path_n; i++)
2188 int ny = GRID_Y(path_g[i]);
2189 int nx = GRID_X(path_g[i]);
2191 if (panel_contains(ny, nx))
2193 byte a = default_color;
2196 #ifdef USE_TRANSPARENCY
2200 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2202 /* Determine what is there */
2203 map_info(ny, nx, &a, &c, &ta, &tc);
2205 if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2207 else if (a == default_color)
2211 if (fake_monochrome)
2213 if (world_monster) a = TERM_DARK;
2214 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2215 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2216 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2220 /* Hack -- Queue it */
2221 Term_queue_char(nx-panel_col_prt, ny-panel_row_prt, a, '*', ta, tc);
2222 #else /* USE_TRANSPARENCY */
2224 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2226 /* Determine what is there */
2227 map_info(ny, nx, &a, &c);
2229 if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2231 else if (a == default_color)
2235 if (fake_monochrome)
2237 if (world_monster) a = TERM_DARK;
2238 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2239 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2240 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2243 /* Hack -- Queue it */
2244 Term_queue_char(nx-panel_col_prt, ny-panel_row_prt, a, '*');
2245 #endif /* USE_TRANSPARENCY */
2249 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2252 if (nx == x && ny == y) default_color = TERM_L_DARK;
2257 static cptr simplify_list[][2] =
2264 {"^Amulet of ", "\""},
2265 {"^Scroll of ", "?"},
2266 {"^Scroll titled ", "?"},
2267 {"^Wand of " , "-"},
2269 {"^Staff of " , "_"},
2270 {"^Potion of ", "!"},
2282 static void display_shortened_item_name(object_type *o_ptr, int y)
2288 object_desc(buf, o_ptr, FALSE, 0);
2290 for (c = buf; *c; c++)
2293 for (i = 0; simplify_list[i][1]; i++)
2295 cptr org_w = simplify_list[i][0];
2305 if (!strncmp(c, org_w, strlen(org_w)))
2308 cptr tmp = simplify_list[i][1];
2311 tmp = c + strlen(org_w);
2321 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2327 if(len + 2 > 12) break;
2334 if(len + 1 > 12) break;
2340 Term_putstr(0, y, 12, tval_to_attr[o_ptr->tval % 128], buf);
2344 * Display a "small-scale" map of the dungeon in the active Term
2346 void display_map(int *cy, int *cx)
2355 byte bigma[MAX_HGT+2][MAX_WID+2];
2356 char bigmc[MAX_HGT+2][MAX_WID+2];
2357 byte bigmp[MAX_HGT+2][MAX_WID+2];
2359 byte ma[SCREEN_HGT + 2][SCREEN_WID + 2];
2360 char mc[SCREEN_HGT + 2][SCREEN_WID + 2];
2362 byte mp[SCREEN_HGT + 2][SCREEN_WID + 2];
2364 bool old_view_special_lite;
2365 bool old_view_granite_lite;
2367 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2369 int yrat = cur_hgt / SCREEN_HGT;
2370 int xrat = cur_wid / SCREEN_WID;
2373 int match_autopick_yx[SCREEN_HGT+2][SCREEN_WID+2];
2374 object_type *object_autopick_yx[SCREEN_HGT+2][SCREEN_WID+2];
2376 /* Save lighting effects */
2377 old_view_special_lite = view_special_lite;
2378 old_view_granite_lite = view_granite_lite;
2380 /* Disable lighting effects */
2381 view_special_lite = FALSE;
2382 view_granite_lite = FALSE;
2384 /* Clear the chars and attributes */
2385 for (y = 0; y < SCREEN_HGT + 2; ++y)
2387 for (x = 0; x < SCREEN_WID + 2; ++x)
2389 match_autopick_yx[y][x] = -1;
2390 object_autopick_yx[y][x] = NULL;
2393 ma[y][x] = TERM_WHITE;
2401 for (j = 0; j < cur_hgt + 2; ++j)
2403 for (i = 0; i < cur_wid + 2; ++i)
2406 bigma[j][i] = TERM_WHITE;
2414 /* Fill in the map */
2415 for (i = 0; i < cur_wid; ++i)
2417 for (j = 0; j < cur_hgt; ++j)
2427 /* Extract the current attr/char at that map location */
2428 #ifdef USE_TRANSPARENCY
2429 map_info(j, i, &ta, &tc, &ta, &tc);
2430 #else /* USE_TRANSPARENCY */
2431 map_info(j, i, &ta, &tc);
2432 #endif /* USE_TRANSPARENCY */
2434 /* Extract the priority */
2437 if(match_autopick!=-1
2438 && (match_autopick_yx[y][x] == -1
2439 || match_autopick_yx[y][x] > match_autopick))
2441 match_autopick_yx[y][x] = match_autopick;
2442 object_autopick_yx[y][x] = autopick_obj;
2446 /* Save the char, attr and priority */
2447 bigmc[j+1][i+1] = tc;
2448 bigma[j+1][i+1] = ta;
2449 bigmp[j+1][i+1] = tp;
2453 for (j = 0; j < cur_hgt; ++j)
2455 for (i = 0; i < cur_wid; ++i)
2461 tc = bigmc[j+1][i+1];
2462 ta = bigma[j+1][i+1];
2463 tp = bigmp[j+1][i+1];
2465 /* rare feature has more priority */
2471 for (t = 0; t < 8; t++)
2473 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2474 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2484 /* Save the char, attr and priority */
2497 /* Draw the corners */
2498 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2500 /* Draw the horizontal edges */
2501 for (x = 1; x <= SCREEN_WID; x++) mc[0][x] = mc[y][x] = '-';
2503 /* Draw the vertical edges */
2504 for (y = 1; y <= SCREEN_HGT; y++) mc[y][0] = mc[y][x] = '|';
2507 /* Display each map line in order */
2508 for (y = 0; y < SCREEN_HGT+2; ++y)
2510 /* Start a new line */
2511 Term_gotoxy(COL_MAP, y);
2513 /* Display the line */
2514 for (x = 0; x < SCREEN_WID+2; ++x)
2519 /* Hack -- fake monochrome */
2520 if (fake_monochrome)
2522 if (world_monster) ta = TERM_DARK;
2523 else if (p_ptr->invuln || world_player) ta = TERM_WHITE;
2524 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) ta = TERM_WHITE;
2525 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2528 /* Add the character */
2534 for (y = 1; y < SCREEN_HGT+1; ++y)
2536 match_autopick = -1;
2537 for (x = 1; x <= SCREEN_WID; x++){
2538 if (match_autopick_yx[y][x] != -1 &&
2539 (match_autopick > match_autopick_yx[y][x] ||
2540 match_autopick == -1)){
2541 match_autopick = match_autopick_yx[y][x];
2542 autopick_obj = object_autopick_yx[y][x];
2546 /* Clear old display */
2547 Term_putstr(0, y, 12, 0, " ");
2549 if (match_autopick != -1)
2551 display_shortened_item_name(autopick_obj, y);
2554 char buf[13] = "\0";
2555 strncpy(buf,autopick_name[match_autopick],12);
2563 /* Player location */
2564 (*cy) = py / yrat + 1 + ROW_MAP;
2565 (*cx) = px / xrat + 1 + COL_MAP;
2568 /* Restore lighting effects */
2569 view_special_lite = old_view_special_lite;
2570 view_granite_lite = old_view_granite_lite;
2575 * Display a "small-scale" map of the dungeon for the player
2577 * Currently, the "player" is displayed on the map. XXX XXX XXX
2579 void do_cmd_view_map(void)
2584 /* Save the screen */
2589 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2591 prt("Please wait...", 0, 0);
2597 /* Clear the screen */
2600 display_autopick = 0;
2602 /* Display the map */
2603 display_map(&cy, &cx);
2606 if(max_autopick && !p_ptr->wild_mode)
2608 display_autopick = ITEM_DISPLAY;
2616 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", 23, 1);
2618 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", 23, 1);
2621 /* Hilite the player */
2622 move_cursor(cy, cx);
2629 flag = DONT_AUTOPICK;
2631 flag = DO_AUTODESTROY;
2633 flag = (DO_AUTOPICK | DONT_AUTOPICK);
2639 if (~display_autopick & flag)
2640 display_autopick |= flag;
2642 display_autopick &= ~flag;
2643 /* Display the map */
2644 display_map(&cy, &cx);
2647 display_autopick = 0;
2653 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2655 put_str("Hit any key to continue", 23, 30);
2656 #endif /* Hilite the player */
2657 move_cursor(cy, cx);
2662 /* Restore the screen */
2671 * Some comments on the cave grid flags. -BEN-
2674 * One of the major bottlenecks in previous versions of Angband was in
2675 * the calculation of "line of sight" from the player to various grids,
2676 * such as monsters. This was such a nasty bottleneck that a lot of
2677 * silly things were done to reduce the dependancy on "line of sight",
2678 * for example, you could not "see" any grids in a lit room until you
2679 * actually entered the room, and there were all kinds of bizarre grid
2680 * flags to enable this behavior. This is also why the "call light"
2681 * spells always lit an entire room.
2683 * The code below provides functions to calculate the "field of view"
2684 * for the player, which, once calculated, provides extremely fast
2685 * calculation of "line of sight from the player", and to calculate
2686 * the "field of torch lite", which, again, once calculated, provides
2687 * extremely fast calculation of "which grids are lit by the player's
2688 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2689 * "GRID_LITE", as appropriate, these functions maintain an array for
2690 * each of these two flags, each array containing the locations of all
2691 * of the grids marked with the appropriate flag, which can be used to
2692 * very quickly scan through all of the grids in a given set.
2694 * To allow more "semantically valid" field of view semantics, whenever
2695 * the field of view (or the set of torch lit grids) changes, all of the
2696 * grids in the field of view (or the set of torch lit grids) are "drawn"
2697 * so that changes in the world will become apparent as soon as possible.
2698 * This has been optimized so that only grids which actually "change" are
2699 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2700 * of the grids which are entering or leaving the relevent set of grids.
2702 * These new methods are so efficient that the old nasty code was removed.
2704 * Note that there is no reason to "update" the "viewable space" unless
2705 * the player "moves", or walls/doors are created/destroyed, and there
2706 * is no reason to "update" the "torch lit grids" unless the field of
2707 * view changes, or the "light radius" changes. This means that when
2708 * the player is resting, or digging, or doing anything that does not
2709 * involve movement or changing the state of the dungeon, there is no
2710 * need to update the "view" or the "lite" regions, which is nice.
2712 * Note that the calls to the nasty "los()" function have been reduced
2713 * to a bare minimum by the use of the new "field of view" calculations.
2715 * I wouldn't be surprised if slight modifications to the "update_view()"
2716 * function would allow us to determine "reverse line-of-sight" as well
2717 * as "normal line-of-sight", which would allow monsters to use a more
2718 * "correct" calculation to determine if they can "see" the player. For
2719 * now, monsters simply "cheat" somewhat and assume that if the player
2720 * has "line of sight" to the monster, then the monster can "pretend"
2721 * that it has "line of sight" to the player.
2724 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2725 * grid and maintains an array of all "CAVE_LITE" grids.
2727 * This set of grids is the complete set of all grids which are lit by
2728 * the players light source, which allows the "player_can_see_bold()"
2729 * function to work very quickly.
2731 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2732 * fact, the player (unless blind) can always "see" all grids which are
2733 * marked as "CAVE_LITE", unless they are "off screen".
2736 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2737 * grid and maintains an array of all "CAVE_VIEW" grids.
2739 * This set of grids is the complete set of all grids within line of sight
2740 * of the player, allowing the "player_has_los_bold()" macro to work very
2744 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2745 * temporary internal flag to mark those grids which are not only in view,
2746 * but which are also "easily" in line of sight of the player. This flag
2747 * is always cleared when we are done.
2750 * The current "update_lite()" and "update_view()" algorithms use the
2751 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2752 * to keep track of which grids were previously marked as "CAVE_LITE" or
2753 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2755 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2756 * for various other purposes, such as spreading lite or darkness during
2757 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2760 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2761 * in some way permanently lit. However, for the player to "see" anything
2762 * in the grid, as determined by "player_can_see()", the player must not be
2763 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2764 * grids, even if marked as "perma lit", are only illuminated if they touch
2765 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2768 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2769 * that even if the player cannot "see" the grid, he "knows" the terrain in
2770 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2771 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2772 * or when one of the "memorize floor grids" options induces memorization.
2774 * Objects are "memorized" in a different way, using a special "marked" flag
2775 * on the object itself, which is set when an object is observed or detected.
2778 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2779 * and should be illuminated by "lite room" and "darkness" spells.
2782 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2783 * and should be unavailable for "teleportation" destinations.
2786 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2787 * which is observed, and the "view_torch_grids" allows the player to memorize
2788 * every torch-lit grid. The player will always memorize important walls,
2789 * doors, stairs, and other terrain features, as well as any "detected" grids.
2791 * Note that the new "update_view()" method allows, among other things, a room
2792 * to be "partially" seen as the player approaches it, with a growing cone of
2793 * floor appearing as the player gets closer to the door. Also, by not turning
2794 * on the "memorize perma-lit grids" option, the player will only "see" those
2795 * floor grids which are actually in line of sight.
2797 * And my favorite "plus" is that you can now use a special option to draw the
2798 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2799 * grids dimly), providing a "pretty" effect as the player runs around, and
2800 * to efficiently display the "torch lite" in a special color.
2803 * Some comments on the "update_view()" algorithm...
2805 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2806 * and only has to call "los()" on the borderline cases. The major axes/diags
2807 * even terminate early when they hit walls. I need to find a quick way
2808 * to "terminate" the other scans.
2810 * Note that in the worst case (a big empty area with say 5% scattered walls),
2811 * each of the 1500 or so nearby grids is checked once, most of them getting
2812 * an "instant" rating, and only a small portion requiring a call to "los()".
2814 * The only time that the algorithm appears to be "noticeably" too slow is
2815 * when running, and this is usually only important in town, since the town
2816 * provides about the worst scenario possible, with large open regions and
2817 * a few scattered obstructions. There is a special "efficiency" option to
2818 * allow the player to reduce his field of view in town, if needed.
2820 * In the "best" case (say, a normal stretch of corridor), the algorithm
2821 * makes one check for each viewable grid, and makes no calls to "los()".
2822 * So running in corridors is very fast, and if a lot of monsters are
2823 * nearby, it is much faster than the old methods.
2825 * Note that resting, most normal commands, and several forms of running,
2826 * plus all commands executed near large groups of monsters, are strictly
2827 * more efficient with "update_view()" that with the old "compute los() on
2828 * demand" method, primarily because once the "field of view" has been
2829 * calculated, it does not have to be recalculated until the player moves
2830 * (or a wall or door is created or destroyed).
2832 * Note that we no longer have to do as many "los()" checks, since once the
2833 * "view" region has been built, very few things cause it to be "changed"
2834 * (player movement, and the opening/closing of doors, changes in wall status).
2835 * Note that door/wall changes are only relevant when the door/wall itself is
2836 * in the "view" region.
2838 * The algorithm seems to only call "los()" from zero to ten times, usually
2839 * only when coming down a corridor into a room, or standing in a room, just
2840 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2841 * we will be reducing the calls to "los()".
2843 * I am thinking in terms of an algorithm that "walks" from the central point
2844 * out to the maximal "distance", at each point, determining the "view" code
2845 * (above). For each grid not on a major axis or diagonal, the "view" code
2846 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
2847 * (the one along the nearest diagonal, and the one next to that one, see
2848 * "update_view_aux()"...).
2850 * We "memorize" the viewable space array, so that at the cost of under 3000
2851 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2852 * each grid actually in the "viewable space". And for another 3000 bytes,
2853 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2854 * are also used by other routines, thus reducing the cost to almost nothing.
2856 * A similar thing is done for "forget_lite()" in which case the savings are
2857 * much less, but save us from doing bizarre maintenance checking.
2859 * In the worst "normal" case (in the middle of the town), the reachable space
2860 * actually reaches to more than half of the largest possible "circle" of view,
2861 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2862 * where all the walls have been removed), the reachable space actually reaches
2863 * the theoretical maximum size of just under 1500 grids.
2865 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2866 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2867 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2868 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2869 * entire possible space (including initialization) in one step per grid. If
2870 * we do the "clearing" as a separate step (and use an array of "view" grids),
2871 * then the clearing will take as many steps as grids that were viewed, and the
2872 * algorithm will be able to "stop" scanning at various points.
2873 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2884 * Actually erase the entire "lite" array, redrawing every grid
2886 void forget_lite(void)
2890 /* None to forget */
2891 if (!lite_n) return;
2893 /* Clear them all */
2894 for (i = 0; i < lite_n; i++)
2899 /* Forget "LITE" flag */
2900 cave[y][x].info &= ~(CAVE_LITE);
2914 * This macro allows us to efficiently add a grid to the "lite" array,
2915 * note that we are never called for illegal grids, or for grids which
2916 * have already been placed into the "lite" array, and we are never
2917 * called when the "lite" array is full.
2919 #define cave_lite_hack(Y,X) \
2921 if (!(cave[Y][X].info & (CAVE_LITE))) { \
2922 cave[Y][X].info |= (CAVE_LITE); \
2923 lite_y[lite_n] = (Y); \
2924 lite_x[lite_n] = (X); \
2930 * Update the set of grids "illuminated" by the player's lite.
2932 * This routine needs to use the results of "update_view()"
2934 * Note that "blindness" does NOT affect "torch lite". Be careful!
2936 * We optimize most lites (all non-artifact lites) by using "obvious"
2937 * facts about the results of "small" lite radius, and we attempt to
2938 * list the "nearby" grids before the more "distant" ones in the
2939 * array of torch-lit grids.
2941 * We will correctly handle "large" radius lites, though currently,
2942 * it is impossible for the player to have more than radius 3 lite.
2944 * We assume that "radius zero" lite is in fact no lite at all.
2946 * Torch Lantern Artifacts
2956 void update_lite(void)
2958 int i, x, y, min_x, max_x, min_y, max_y;
2959 int p = p_ptr->cur_lite;
2961 /*** Special case ***/
2963 /* Hack -- Player has no lite */
2966 /* Forget the old lite */
2969 /* Draw the player */
2974 /*** Save the old "lite" grids for later ***/
2976 /* Clear them all */
2977 for (i = 0; i < lite_n; i++)
2982 /* Mark the grid as not "lite" */
2983 cave[y][x].info &= ~(CAVE_LITE);
2985 /* Mark the grid as "seen" */
2986 cave[y][x].info |= (CAVE_TEMP);
2988 /* Add it to the "seen" set */
2998 /*** Collect the new "lite" grids ***/
3000 /* Radius 1 -- torch radius */
3004 cave_lite_hack(py, px);
3007 cave_lite_hack(py+1, px);
3008 cave_lite_hack(py-1, px);
3009 cave_lite_hack(py, px+1);
3010 cave_lite_hack(py, px-1);
3012 /* Diagonal grids */
3013 cave_lite_hack(py+1, px+1);
3014 cave_lite_hack(py+1, px-1);
3015 cave_lite_hack(py-1, px+1);
3016 cave_lite_hack(py-1, px-1);
3019 /* Radius 2 -- lantern radius */
3022 /* South of the player */
3023 if (cave_floor_bold(py+1, px))
3025 cave_lite_hack(py+2, px);
3026 cave_lite_hack(py+2, px+1);
3027 cave_lite_hack(py+2, px-1);
3030 /* North of the player */
3031 if (cave_floor_bold(py-1, px))
3033 cave_lite_hack(py-2, px);
3034 cave_lite_hack(py-2, px+1);
3035 cave_lite_hack(py-2, px-1);
3038 /* East of the player */
3039 if (cave_floor_bold(py, px+1))
3041 cave_lite_hack(py, px+2);
3042 cave_lite_hack(py+1, px+2);
3043 cave_lite_hack(py-1, px+2);
3046 /* West of the player */
3047 if (cave_floor_bold(py, px-1))
3049 cave_lite_hack(py, px-2);
3050 cave_lite_hack(py+1, px-2);
3051 cave_lite_hack(py-1, px-2);
3055 /* Radius 3+ -- artifact radius */
3060 /* Paranoia -- see "LITE_MAX" */
3063 /* South-East of the player */
3064 if (cave_floor_bold(py+1, px+1))
3066 cave_lite_hack(py+2, px+2);
3069 /* South-West of the player */
3070 if (cave_floor_bold(py+1, px-1))
3072 cave_lite_hack(py+2, px-2);
3075 /* North-East of the player */
3076 if (cave_floor_bold(py-1, px+1))
3078 cave_lite_hack(py-2, px+2);
3081 /* North-West of the player */
3082 if (cave_floor_bold(py-1, px-1))
3084 cave_lite_hack(py-2, px-2);
3089 if (min_y < 0) min_y = 0;
3093 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3097 if (min_x < 0) min_x = 0;
3101 if (max_x > cur_wid-1) max_x = cur_wid-1;
3103 /* Scan the maximal box */
3104 for (y = min_y; y <= max_y; y++)
3106 for (x = min_x; x <= max_x; x++)
3108 int dy = (py > y) ? (py - y) : (y - py);
3109 int dx = (px > x) ? (px - x) : (x - px);
3111 /* Skip the "central" grids (above) */
3112 if ((dy <= 2) && (dx <= 2)) continue;
3114 /* Hack -- approximate the distance */
3115 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3117 /* Skip distant grids */
3118 if (d > p) continue;
3120 /* Viewable, nearby, grids get "torch lit" */
3121 if (player_has_los_bold(y, x))
3123 /* This grid is "torch lit" */
3124 cave_lite_hack(y, x);
3131 /*** Complete the algorithm ***/
3133 /* Draw the new grids */
3134 for (i = 0; i < lite_n; i++)
3139 /* Update fresh grids */
3140 if (cave[y][x].info & (CAVE_TEMP)) continue;
3149 /* Clear them all */
3150 for (i = 0; i < temp_n; i++)
3155 /* No longer in the array */
3156 cave[y][x].info &= ~(CAVE_TEMP);
3158 /* Update stale grids */
3159 if (cave[y][x].info & (CAVE_LITE)) continue;
3170 static bool mon_invis;
3173 * Add a square to the changes array
3175 static void mon_lite_hack(int y, int x)
3180 if (!in_bounds2(y, x)) return;
3182 c_ptr = &cave[y][x];
3184 /* Want a unlit square in view of the player */
3185 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3187 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3188 if (!cave_floor_grid(c_ptr) && mon_invis) return;
3190 /* Save this square */
3191 if (temp_n < TEMP_MAX)
3199 c_ptr->info |= CAVE_MNLT;
3206 * Update squares illuminated by monsters.
3208 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3209 * denote squares illuminated by monsters.
3211 * The CAVE_TEMP flag is used to store the state during the
3212 * updating. Only squares in view of the player, whos state
3213 * changes are drawn via lite_spot().
3215 void update_mon_lite(void)
3224 bool daytime = ((turn % (20L * TOWN_DAWN)) < ((20L * TOWN_DAWN) / 2));
3226 /* Clear all monster lit squares */
3227 for (i = 0; i < mon_lite_n; i++)
3230 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3233 c_ptr->info |= (CAVE_TEMP);
3235 /* Clear monster illumination flag */
3236 c_ptr->info &= ~(CAVE_MNLT);
3239 /* Empty temp list of new squares to lite up */
3242 /* Loop through monsters, adding newly lit squares to changes list */
3243 for (i = 1; i < m_max; i++)
3245 monster_type *m_ptr = &m_list[i];
3246 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3248 /* Skip dead monsters */
3249 if (!m_ptr->r_idx) continue;
3251 /* Is it too far away? */
3252 if (m_ptr->cdis > ((d_info[dungeon_type].flags1 & DF1_DARKNESS) ? MAX_SIGHT / 2 + 1 : MAX_SIGHT + 3)) continue;
3254 /* Get lite radius */
3257 /* Note the radii are cumulative */
3258 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3259 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3261 /* Exit if has no light */
3263 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && daytime) || p_ptr->inside_battle)) continue;
3265 if (world_monster) continue;
3267 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3269 /* Access the location */
3273 /* Is the monster visible? */
3274 mon_invis = !(cave[fy][fx].info & CAVE_VIEW);
3276 /* The square it is on */
3277 mon_lite_hack(fy, fx);
3279 /* Adjacent squares */
3280 mon_lite_hack(fy + 1, fx);
3281 mon_lite_hack(fy - 1, fx);
3282 mon_lite_hack(fy, fx + 1);
3283 mon_lite_hack(fy, fx - 1);
3284 mon_lite_hack(fy + 1, fx + 1);
3285 mon_lite_hack(fy + 1, fx - 1);
3286 mon_lite_hack(fy - 1, fx + 1);
3287 mon_lite_hack(fy - 1, fx - 1);
3292 /* South of the monster */
3293 if (cave_floor_bold(fy + 1, fx))
3295 mon_lite_hack(fy + 2, fx + 1);
3296 mon_lite_hack(fy + 2, fx);
3297 mon_lite_hack(fy + 2, fx - 1);
3299 c_ptr = &cave[fy + 2][fx];
3302 if ((rad == 3) && cave_floor_grid(c_ptr))
3304 mon_lite_hack(fy + 3, fx + 1);
3305 mon_lite_hack(fy + 3, fx);
3306 mon_lite_hack(fy + 3, fx - 1);
3310 /* North of the monster */
3311 if (cave_floor_bold(fy - 1, fx))
3313 mon_lite_hack(fy - 2, fx + 1);
3314 mon_lite_hack(fy - 2, fx);
3315 mon_lite_hack(fy - 2, fx - 1);
3317 c_ptr = &cave[fy - 2][fx];
3320 if ((rad == 3) && cave_floor_grid(c_ptr))
3322 mon_lite_hack(fy - 3, fx + 1);
3323 mon_lite_hack(fy - 3, fx);
3324 mon_lite_hack(fy - 3, fx - 1);
3328 /* East of the monster */
3329 if (cave_floor_bold(fy, fx + 1))
3331 mon_lite_hack(fy + 1, fx + 2);
3332 mon_lite_hack(fy, fx + 2);
3333 mon_lite_hack(fy - 1, fx + 2);
3335 c_ptr = &cave[fy][fx + 2];
3338 if ((rad == 3) && cave_floor_grid(c_ptr))
3340 mon_lite_hack(fy + 1, fx + 3);
3341 mon_lite_hack(fy, fx + 3);
3342 mon_lite_hack(fy - 1, fx + 3);
3346 /* West of the monster */
3347 if (cave_floor_bold(fy, fx - 1))
3349 mon_lite_hack(fy + 1, fx - 2);
3350 mon_lite_hack(fy, fx - 2);
3351 mon_lite_hack(fy - 1, fx - 2);
3353 c_ptr = &cave[fy][fx - 2];
3356 if ((rad == 3) && cave_floor_grid(c_ptr))
3358 mon_lite_hack(fy + 1, fx - 3);
3359 mon_lite_hack(fy, fx - 3);
3360 mon_lite_hack(fy - 1, fx - 3);
3368 /* South-East of the monster */
3369 if (cave_floor_bold(fy + 1, fx + 1))
3371 mon_lite_hack(fy + 2, fx + 2);
3374 /* South-West of the monster */
3375 if (cave_floor_bold(fy + 1, fx - 1))
3377 mon_lite_hack(fy + 2, fx - 2);
3380 /* North-East of the monster */
3381 if (cave_floor_bold(fy - 1, fx + 1))
3383 mon_lite_hack(fy - 2, fx + 2);
3386 /* North-West of the monster */
3387 if (cave_floor_bold(fy - 1, fx - 1))
3389 mon_lite_hack(fy - 2, fx - 2);
3394 /* Save end of list of new squares */
3398 * Look at old set flags to see if there are any changes.
3400 for (i = 0; i < mon_lite_n; i++)
3405 if (!in_bounds2(fy, fx)) continue;
3408 c_ptr = &cave[fy][fx];
3410 /* It it no longer lit? */
3411 if (!(c_ptr->info & CAVE_MNLT) && player_has_los_grid(c_ptr))
3413 /* It is now unlit */
3418 /* Add to end of temp array */
3419 temp_x[temp_n] = (byte)fx;
3420 temp_y[temp_n] = (byte)fy;
3424 /* Clear the lite array */
3427 /* Copy the temp array into the lit array lighting the new squares. */
3428 for (i = 0; i < temp_n; i++)
3433 if (!in_bounds2(fy, fx)) continue;
3436 c_ptr = &cave[fy][fx];
3440 /* Clear the temp flag for the old lit grids */
3441 c_ptr->info &= ~(CAVE_TEMP);
3445 /* The is the square newly lit and visible? */
3446 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3453 /* Save in the monster lit array */
3454 mon_lite_x[mon_lite_n] = fx;
3455 mon_lite_y[mon_lite_n] = fy;
3460 /* Finished with temp_n */
3463 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3465 if (p_ptr->special_defense & NINJA_S_STEALTH)
3467 if (p_ptr->old_monlite != p_ptr->monlite)
3472 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3474 msg_print("Your mantle of shadow become thin.");
3480 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3482 msg_print("Your mantle of shadow restored its original darkness.");
3487 p_ptr->old_monlite = p_ptr->monlite;
3490 void clear_mon_lite(void)
3495 /* Clear all monster lit squares */
3496 for (i = 0; i < mon_lite_n; i++)
3499 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3501 /* Clear monster illumination flag */
3502 c_ptr->info &= ~(CAVE_MNLT);
3505 /* Empty the array */
3512 * Clear the viewable space
3514 void forget_view(void)
3520 /* None to forget */
3521 if (!view_n) return;
3523 /* Clear them all */
3524 for (i = 0; i < view_n; i++)
3529 /* Access the grid */
3530 c_ptr = &cave[y][x];
3532 /* Forget that the grid is viewable */
3533 c_ptr->info &= ~(CAVE_VIEW);
3535 /* Update the screen */
3546 * This macro allows us to efficiently add a grid to the "view" array,
3547 * note that we are never called for illegal grids, or for grids which
3548 * have already been placed into the "view" array, and we are never
3549 * called when the "view" array is full.
3551 #define cave_view_hack(C,Y,X) \
3553 if (!((C)->info & (CAVE_VIEW))){\
3554 (C)->info |= (CAVE_VIEW); \
3555 view_y[view_n] = (Y); \
3556 view_x[view_n] = (X); \
3563 * Helper function for "update_view()" below
3565 * We are checking the "viewability" of grid (y,x) by the player.
3567 * This function assumes that (y,x) is legal (i.e. on the map).
3569 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3570 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3572 * Note that we are using the "CAVE_XTRA" field for marking grids as
3573 * "easily viewable". This bit is cleared at the end of "update_view()".
3575 * This function adds (y,x) to the "viewable set" if necessary.
3577 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3579 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3581 bool f1, f2, v1, v2, z1, z2, wall;
3585 cave_type *g1_c_ptr;
3586 cave_type *g2_c_ptr;
3588 /* Access the grids */
3589 g1_c_ptr = &cave[y1][x1];
3590 g2_c_ptr = &cave[y2][x2];
3593 /* Check for walls */
3594 f1 = (cave_floor_grid(g1_c_ptr));
3595 f2 = (cave_floor_grid(g2_c_ptr));
3597 /* Totally blocked by physical walls */
3598 if (!f1 && !f2) return (TRUE);
3601 /* Check for visibility */
3602 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3603 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3605 /* Totally blocked by "unviewable neighbors" */
3606 if (!v1 && !v2) return (TRUE);
3609 /* Access the grid */
3610 c_ptr = &cave[y][x];
3613 /* Check for walls */
3614 wall = (!cave_floor_grid(c_ptr));
3617 /* Check the "ease" of visibility */
3618 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3619 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3621 /* Hack -- "easy" plus "easy" yields "easy" */
3624 c_ptr->info |= (CAVE_XTRA);
3626 cave_view_hack(c_ptr, y, x);
3631 /* Hack -- primary "easy" yields "viewed" */
3634 cave_view_hack(c_ptr, y, x);
3639 /* Hack -- "view" plus "view" yields "view" */
3642 /* c_ptr->info |= (CAVE_XTRA); */
3644 cave_view_hack(c_ptr, y, x);
3650 /* Mega-Hack -- the "los()" function works poorly on walls */
3653 cave_view_hack(c_ptr, y, x);
3659 /* Hack -- check line of sight */
3660 if (los(py, px, y, x))
3662 cave_view_hack(c_ptr, y, x);
3668 /* Assume no line of sight. */
3675 * Calculate the viewable space
3677 * 1: Process the player
3678 * 1a: The player is always (easily) viewable
3679 * 2: Process the diagonals
3680 * 2a: The diagonals are (easily) viewable up to the first wall
3681 * 2b: But never go more than 2/3 of the "full" distance
3682 * 3: Process the main axes
3683 * 3a: The main axes are (easily) viewable up to the first wall
3684 * 3b: But never go more than the "full" distance
3685 * 4: Process sequential "strips" in each of the eight octants
3686 * 4a: Each strip runs along the previous strip
3687 * 4b: The main axes are "previous" to the first strip
3688 * 4c: Process both "sides" of each "direction" of each strip
3689 * 4c1: Each side aborts as soon as possible
3690 * 4c2: Each side tells the next strip how far it has to check
3692 * Note that the octant processing involves some pretty interesting
3693 * observations involving when a grid might possibly be viewable from
3694 * a given grid, and on the order in which the strips are processed.
3696 * Note the use of the mathematical facts shown below, which derive
3697 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3698 * hypotenuse of a right triangle is primarily determined by the length
3699 * of the longest side, when one side is small, and is strictly less
3700 * than one-and-a-half times as long as the longest side when both of
3701 * the sides are large.
3703 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3704 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3706 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3708 * These observations are important because the calculation of the actual
3709 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3710 * while for small values (up to about 20 or so), the approximations above
3711 * are correct to within an error of at most one grid or so.
3713 * Observe the use of "full" and "over" in the code below, and the use of
3714 * the specialized calculation involving "limit", all of which derive from
3715 * the observations given above. Basically, we note that the "circle" of
3716 * view is completely contained in an "octagon" whose bounds are easy to
3717 * determine, and that only a few steps are needed to derive the actual
3718 * bounds of the circle given the bounds of the octagon.
3720 * Note that by skipping all the grids in the corners of the octagon, we
3721 * place an upper limit on the number of grids in the field of view, given
3722 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3723 * view, only about 1475 of these are in the "octagon" of view, and even
3724 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3725 * entries to completely contain the actual field of view.
3727 * Note also the care taken to prevent "running off the map". The use of
3728 * explicit checks on the "validity" of the "diagonal", and the fact that
3729 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3730 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3731 * of multiple checks on the validity of grids.
3733 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3734 * "ws","wn" variables. They work like this: While travelling down the
3735 * south-bound strip just to the east of the main south axis, as soon as
3736 * we get to a grid which does not "transmit" viewing, if all of the strips
3737 * preceding us (in this case, just the main axis) had terminated at or before
3738 * the same point, then we can stop, and reset the "max distance" to ourself.
3739 * So, each strip (named by major axis plus offset, thus "se" in this case)
3740 * maintains a "blockage" variable, initialized during the main axis step,
3741 * and checks it whenever a blockage is observed. After processing each
3742 * strip as far as the previous strip told us to process, the next strip is
3743 * told not to go farther than the current strip's farthest viewable grid,
3744 * unless open space is still available. This uses the "k" variable.
3746 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3747 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3748 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3749 * chunk of code which adds the given location to the "view" array if it
3750 * is not already there, using both the actual location and a pointer to
3751 * the cave grid. See above.
3753 * By the way, the purpose of this code is to reduce the dependancy on the
3754 * "los()" function which is slow, and, in some cases, not very accurate.
3756 * It is very possible that I am the only person who fully understands this
3757 * function, and for that I am truly sorry, but efficiency was very important
3758 * and the "simple" version of this function was just not fast enough. I am
3759 * more than willing to replace this function with a simpler one, if it is
3760 * equally efficient, and especially willing if the new function happens to
3761 * derive "reverse-line-of-sight" at the same time, since currently monsters
3762 * just use an optimized hack of "you see me, so I see you", and then use the
3763 * actual "projectable()" function to check spell attacks.
3765 void update_view(void)
3767 int n, m, d, k, y, x, z;
3769 int se, sw, ne, nw, es, en, ws, wn;
3773 int y_max = cur_hgt - 1;
3774 int x_max = cur_wid - 1;
3778 /*** Initialize ***/
3781 if (view_reduce_view && !dun_level)
3783 /* Full radius (10) */
3784 full = MAX_SIGHT / 2;
3786 /* Octagon factor (15) */
3787 over = MAX_SIGHT * 3 / 4;
3793 /* Full radius (20) */
3796 /* Octagon factor (30) */
3797 over = MAX_SIGHT * 3 / 2;
3801 /*** Step 0 -- Begin ***/
3803 /* Save the old "view" grids for later */
3804 for (n = 0; n < view_n; n++)
3809 /* Access the grid */
3810 c_ptr = &cave[y][x];
3812 /* Mark the grid as not in "view" */
3813 c_ptr->info &= ~(CAVE_VIEW);
3815 /* Mark the grid as "seen" */
3816 c_ptr->info |= (CAVE_TEMP);
3818 /* Add it to the "seen" set */
3824 /* Start over with the "view" array */
3827 /*** Step 1 -- adjacent grids ***/
3829 /* Now start on the player */
3833 /* Access the grid */
3834 c_ptr = &cave[y][x];
3836 /* Assume the player grid is easily viewable */
3837 c_ptr->info |= (CAVE_XTRA);
3839 /* Assume the player grid is viewable */
3840 cave_view_hack(c_ptr, y, x);
3843 /*** Step 2 -- Major Diagonals ***/
3848 /* Scan south-east */
3849 for (d = 1; d <= z; d++)
3851 c_ptr = &cave[y+d][x+d];
3852 c_ptr->info |= (CAVE_XTRA);
3853 cave_view_hack(c_ptr, y+d, x+d);
3854 if (!cave_floor_grid(c_ptr)) break;
3857 /* Scan south-west */
3858 for (d = 1; d <= z; d++)
3860 c_ptr = &cave[y+d][x-d];
3861 c_ptr->info |= (CAVE_XTRA);
3862 cave_view_hack(c_ptr, y+d, x-d);
3863 if (!cave_floor_grid(c_ptr)) break;
3866 /* Scan north-east */
3867 for (d = 1; d <= z; d++)
3869 c_ptr = &cave[y-d][x+d];
3870 c_ptr->info |= (CAVE_XTRA);
3871 cave_view_hack(c_ptr, y-d, x+d);
3872 if (!cave_floor_grid(c_ptr)) break;
3875 /* Scan north-west */
3876 for (d = 1; d <= z; d++)
3878 c_ptr = &cave[y-d][x-d];
3879 c_ptr->info |= (CAVE_XTRA);
3880 cave_view_hack(c_ptr, y-d, x-d);
3881 if (!cave_floor_grid(c_ptr)) break;
3885 /*** Step 3 -- major axes ***/
3888 for (d = 1; d <= full; d++)
3890 c_ptr = &cave[y+d][x];
3891 c_ptr->info |= (CAVE_XTRA);
3892 cave_view_hack(c_ptr, y+d, x);
3893 if (!cave_floor_grid(c_ptr)) break;
3896 /* Initialize the "south strips" */
3900 for (d = 1; d <= full; d++)
3902 c_ptr = &cave[y-d][x];
3903 c_ptr->info |= (CAVE_XTRA);
3904 cave_view_hack(c_ptr, y-d, x);
3905 if (!cave_floor_grid(c_ptr)) break;
3908 /* Initialize the "north strips" */
3912 for (d = 1; d <= full; d++)
3914 c_ptr = &cave[y][x+d];
3915 c_ptr->info |= (CAVE_XTRA);
3916 cave_view_hack(c_ptr, y, x+d);
3917 if (!cave_floor_grid(c_ptr)) break;
3920 /* Initialize the "east strips" */
3924 for (d = 1; d <= full; d++)
3926 c_ptr = &cave[y][x-d];
3927 c_ptr->info |= (CAVE_XTRA);
3928 cave_view_hack(c_ptr, y, x-d);
3929 if (!cave_floor_grid(c_ptr)) break;
3932 /* Initialize the "west strips" */
3936 /*** Step 4 -- Divide each "octant" into "strips" ***/
3938 /* Now check each "diagonal" (in parallel) */
3939 for (n = 1; n <= over / 2; n++)
3941 int ypn, ymn, xpn, xmn;
3944 /* Acquire the "bounds" of the maximal circle */
3946 if (z > full - n) z = full - n;
3947 while ((z + n + (n>>1)) > full) z--;
3950 /* Access the four diagonal grids */
3960 /* Maximum distance */
3961 m = MIN(z, y_max - ypn);
3964 if ((xpn <= x_max) && (n < se))
3967 for (k = n, d = 1; d <= m; d++)
3969 /* Check grid "d" in strip "n", notice "blockage" */
3970 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3972 if (n + d >= se) break;
3975 /* Track most distant "non-blockage" */
3982 /* Limit the next strip */
3987 if ((xmn >= 0) && (n < sw))
3990 for (k = n, d = 1; d <= m; d++)
3992 /* Check grid "d" in strip "n", notice "blockage" */
3993 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3995 if (n + d >= sw) break;
3998 /* Track most distant "non-blockage" */
4005 /* Limit the next strip */
4014 /* Maximum distance */
4018 if ((xpn <= x_max) && (n < ne))
4021 for (k = n, d = 1; d <= m; d++)
4023 /* Check grid "d" in strip "n", notice "blockage" */
4024 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
4026 if (n + d >= ne) break;
4029 /* Track most distant "non-blockage" */
4036 /* Limit the next strip */
4041 if ((xmn >= 0) && (n < nw))
4044 for (k = n, d = 1; d <= m; d++)
4046 /* Check grid "d" in strip "n", notice "blockage" */
4047 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
4049 if (n + d >= nw) break;
4052 /* Track most distant "non-blockage" */
4059 /* Limit the next strip */
4068 /* Maximum distance */
4069 m = MIN(z, x_max - xpn);
4072 if ((ypn <= x_max) && (n < es))
4075 for (k = n, d = 1; d <= m; d++)
4077 /* Check grid "d" in strip "n", notice "blockage" */
4078 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
4080 if (n + d >= es) break;
4083 /* Track most distant "non-blockage" */
4090 /* Limit the next strip */
4095 if ((ymn >= 0) && (n < en))
4098 for (k = n, d = 1; d <= m; d++)
4100 /* Check grid "d" in strip "n", notice "blockage" */
4101 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4103 if (n + d >= en) break;
4106 /* Track most distant "non-blockage" */
4113 /* Limit the next strip */
4122 /* Maximum distance */
4126 if ((ypn <= y_max) && (n < ws))
4129 for (k = n, d = 1; d <= m; d++)
4131 /* Check grid "d" in strip "n", notice "blockage" */
4132 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4134 if (n + d >= ws) break;
4137 /* Track most distant "non-blockage" */
4144 /* Limit the next strip */
4149 if ((ymn >= 0) && (n < wn))
4152 for (k = n, d = 1; d <= m; d++)
4154 /* Check grid "d" in strip "n", notice "blockage" */
4155 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4157 if (n + d >= wn) break;
4160 /* Track most distant "non-blockage" */
4167 /* Limit the next strip */
4174 /*** Step 5 -- Complete the algorithm ***/
4176 /* Update all the new grids */
4177 for (n = 0; n < view_n; n++)
4182 /* Access the grid */
4183 c_ptr = &cave[y][x];
4185 /* Clear the "CAVE_XTRA" flag */
4186 c_ptr->info &= ~(CAVE_XTRA);
4188 /* Update only newly viewed grids */
4189 if (c_ptr->info & (CAVE_TEMP)) continue;
4198 /* Wipe the old grids, update as needed */
4199 for (n = 0; n < temp_n; n++)
4204 /* Access the grid */
4205 c_ptr = &cave[y][x];
4207 /* No longer in the array */
4208 c_ptr->info &= ~(CAVE_TEMP);
4210 /* Update only non-viewable grids */
4211 if (c_ptr->info & (CAVE_VIEW)) continue;
4227 * Hack -- provide some "speed" for the "flow" code
4228 * This entry is the "current index" for the "when" field
4229 * Note that a "when" value of "zero" means "not used".
4231 * Note that the "cost" indexes from 1 to 127 are for
4232 * "old" data, and from 128 to 255 are for "new" data.
4234 * This means that as long as the player does not "teleport",
4235 * then any monster up to 128 + MONSTER_FLOW_DEPTH will be
4236 * able to track down the player, and in general, will be
4237 * able to track down either the player or a position recently
4238 * occupied by the player.
4240 static int flow_n = 0;
4244 * Hack -- forget the "flow" information
4246 void forget_flow(void)
4250 /* Nothing to forget */
4251 if (!flow_n) return;
4253 /* Check the entire dungeon */
4254 for (y = 0; y < cur_hgt; y++)
4256 for (x = 0; x < cur_wid; x++)
4258 /* Forget the old data */
4259 cave[y][x].dist = 0;
4260 cave[y][x].cost = 0;
4261 cave[y][x].when = 0;
4271 * Hack - speed up the update_flow algorithm by only doing
4272 * it everytime the player moves out of LOS of the last
4275 static u16b flow_x = 0;
4276 static u16b flow_y = 0;
4281 * Hack -- fill in the "cost" field of every grid that the player
4282 * can "reach" with the number of steps needed to reach that grid.
4283 * This also yields the "distance" of the player from every grid.
4285 * In addition, mark the "when" of the grids that can reach
4286 * the player with the incremented value of "flow_n".
4288 * Hack -- use the "seen" array as a "circular queue".
4290 * We do not need a priority queue because the cost from grid
4291 * to grid is always "one" and we process them in order.
4293 void update_flow(void)
4299 /* Hack -- disabled */
4300 if (stupid_monsters) return;
4302 /* Paranoia -- make sure the array is empty */
4305 /* The last way-point is on the map */
4306 if (running && in_bounds(flow_y, flow_x))
4308 /* The way point is in sight - do not update. (Speedup) */
4309 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4312 /* Erase all of the current flow information */
4313 for (y = 0; y < cur_hgt; y++)
4315 for (x = 0; x < cur_wid; x++)
4317 cave[y][x].cost = 0;
4318 cave[y][x].dist = 0;
4322 /* Save player position */
4326 /* Add the player's grid to the queue */
4330 /* Now process the queue */
4331 while (flow_head != flow_tail)
4335 /* Extract the next entry */
4336 ty = temp_y[flow_tail];
4337 tx = temp_x[flow_tail];
4339 /* Forget that entry */
4340 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4342 /* Add the "children" */
4343 for (d = 0; d < 8; d++)
4345 int old_head = flow_head;
4346 int m = cave[ty][tx].cost + 1;
4347 int n = cave[ty][tx].dist + 1;
4350 /* Child location */
4351 y = ty + ddy_ddd[d];
4352 x = tx + ddx_ddd[d];
4354 /* Ignore player's grid */
4355 if (x == px && y == py) continue;
4357 c_ptr = &cave[y][x];
4359 if ((c_ptr->feat >= FEAT_DOOR_HEAD) && (c_ptr->feat <= FEAT_SECRET)) m += 3;
4361 /* Ignore "pre-stamped" entries */
4362 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4364 /* Ignore "walls" and "rubble" */
4365 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4367 /* Save the flow cost */
4368 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4369 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4371 /* Hack -- limit flow depth */
4372 if (n == MONSTER_FLOW_DEPTH) continue;
4374 /* Enqueue that entry */
4375 temp_y[flow_head] = y;
4376 temp_x[flow_head] = x;
4378 /* Advance the queue */
4379 if (++flow_head == TEMP_MAX) flow_head = 0;
4381 /* Hack -- notice overflow by forgetting new entry */
4382 if (flow_head == flow_tail) flow_head = old_head;
4388 static int scent_when = 0;
4391 * Characters leave scent trails for perceptive monsters to track.
4393 * Smell is rather more limited than sound. Many creatures cannot use
4394 * it at all, it doesn't extend very far outwards from the character's
4395 * current position, and monsters can use it to home in the character,
4396 * but not to run away from him.
4398 * Smell is valued according to age. When a character takes his turn,
4399 * scent is aged by one, and new scent of the current age is laid down.
4400 * Speedy characters leave more scent, true, but it also ages faster,
4401 * which makes it harder to hunt them down.
4403 * Whenever the age count loops, most of the scent trail is erased and
4404 * the age of the remainder is recalculated.
4406 void update_smell(void)
4411 /* Create a table that controls the spread of scent */
4412 int scent_adjust[5][5] =
4414 { 250, 0, 0, 0, 250 },
4418 { 250, 0, 0, 0, 250 },
4421 /* Loop the age and adjust scent values when necessary */
4422 if (scent_when++ == 250)
4424 /* Scan the entire dungeon */
4425 for (y = 0; y < cur_hgt; y++)
4427 for (x = 0; x < cur_wid; x++)
4429 int w = cave[y][x].when;
4430 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4439 /* Lay down new scent */
4440 for (i = 0; i < 5; i++)
4442 for (j = 0; j < 5; j++)
4446 /* Translate table to map grids */
4451 if (!in_bounds(y, x)) continue;
4453 c_ptr = &cave[y][x];
4455 /* Walls, water, and lava cannot hold scent. */
4456 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4458 /* Grid must not be blocked by walls from the character */
4459 if (!player_has_los_bold(y, x)) continue;
4461 /* Note grids that are too far away */
4462 if (scent_adjust[i][j] == 250) continue;
4464 /* Mark the grid with new scent */
4465 c_ptr->when = scent_when + scent_adjust[i][j];
4472 * Hack -- map the current panel (plus some) ala "magic mapping"
4474 void map_area(int range)
4480 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4482 /* Scan that area */
4483 for (y = 1; y < cur_hgt - 1; y++)
4485 for (x = 1; x < cur_wid - 1; x++)
4487 if (distance(py, px, y, x) > range) continue;
4489 c_ptr = &cave[y][x];
4491 /* All non-walls are "checked" */
4492 if ((c_ptr->feat < FEAT_SECRET) ||
4493 (c_ptr->feat == FEAT_RUBBLE) ||
4494 ((c_ptr->feat >= FEAT_MINOR_GLYPH) &&
4495 (c_ptr->feat <= FEAT_TREES)) ||
4496 (c_ptr->feat >= FEAT_TOWN))
4498 /* Memorize normal features */
4499 if ((c_ptr->feat > FEAT_INVIS) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4501 /* Memorize the object */
4502 c_ptr->info |= (CAVE_MARK);
4505 /* Memorize known walls */
4506 for (i = 0; i < 8; i++)
4508 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4510 /* Memorize walls (etc) */
4511 if ((c_ptr->feat >= FEAT_SECRET) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4513 /* Memorize the walls */
4514 c_ptr->info |= (CAVE_MARK);
4522 p_ptr->redraw |= (PR_MAP);
4525 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4531 * Light up the dungeon using "clairvoyance"
4533 * This function "illuminates" every grid in the dungeon, memorizes all
4534 * "objects", memorizes all grids as with magic mapping, and, under the
4535 * standard option settings (view_perma_grids but not view_torch_grids)
4536 * memorizes all floor grids too.
4538 * Note that if "view_perma_grids" is not set, we do not memorize floor
4539 * grids, since this would defeat the purpose of "view_perma_grids", not
4540 * that anyone seems to play without this option.
4542 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4543 * since this would prevent the use of "view_torch_grids" as a method to
4544 * keep track of what grids have been observed directly.
4546 void wiz_lite(bool wizard, bool ninja)
4550 /* Memorize objects */
4551 for (i = 1; i < o_max; i++)
4553 object_type *o_ptr = &o_list[i];
4555 /* Skip dead objects */
4556 if (!o_ptr->k_idx) continue;
4558 /* Skip held objects */
4559 if (o_ptr->held_m_idx) continue;
4562 /* Skip objects in vaults, if not a wizard. -LM- */
4563 if ((wizard == FALSE) &&
4564 (cave[o_ptr->iy][o_ptr->ix].info & (CAVE_ICKY))) continue;
4568 o_ptr->marked = TRUE;
4571 /* Scan all normal grids */
4572 for (y = 1; y < cur_hgt - 1; y++)
4574 /* Scan all normal grids */
4575 for (x = 1; x < cur_wid - 1; x++)
4577 cave_type *c_ptr = &cave[y][x];
4579 /* Process all non-walls */
4580 if (cave_floor_bold(y, x) || (c_ptr->feat == FEAT_RUBBLE) || (c_ptr->feat == FEAT_TREES) || (c_ptr->feat == FEAT_MOUNTAIN))
4582 /* Scan all neighbors */
4583 for (i = 0; i < 9; i++)
4585 int yy = y + ddy_ddd[i];
4586 int xx = x + ddx_ddd[i];
4589 c_ptr = &cave[yy][xx];
4591 /* Memorize normal features */
4594 /* Memorize the grid */
4595 c_ptr->info |= (CAVE_MARK);
4599 if ((c_ptr->feat > FEAT_INVIS))
4601 /* Memorize the grid */
4602 c_ptr->info |= (CAVE_MARK);
4605 /* Perma-lite the grid */
4606 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4608 c_ptr->info |= (CAVE_GLOW);
4610 /* Normally, memorize floors (see above) */
4611 if (view_perma_grids && !view_torch_grids)
4613 /* Memorize the grid */
4614 c_ptr->info |= (CAVE_MARK);
4623 /* Update the monsters */
4624 p_ptr->update |= (PU_MONSTERS);
4627 p_ptr->redraw |= (PR_MAP);
4630 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4635 * Forget the dungeon map (ala "Thinking of Maud...").
4642 /* Forget every grid */
4643 for (y = 0; y < cur_hgt; y++)
4645 for (x = 0; x < cur_wid; x++)
4647 cave_type *c_ptr = &cave[y][x];
4649 /* Process the grid */
4650 c_ptr->info &= ~(CAVE_MARK);
4654 /* Forget all objects */
4655 for (i = 1; i < o_max; i++)
4657 object_type *o_ptr = &o_list[i];
4659 /* Skip dead objects */
4660 if (!o_ptr->k_idx) continue;
4662 /* Skip held objects */
4663 if (o_ptr->held_m_idx) continue;
4665 /* Forget the object */
4666 o_ptr->marked = FALSE;
4669 /* Mega-Hack -- Forget the view and lite */
4670 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4672 /* Update the view and lite */
4673 p_ptr->update |= (PU_VIEW | PU_LITE);
4675 /* Update the monsters */
4676 p_ptr->update |= (PU_MONSTERS);
4679 p_ptr->redraw |= (PR_MAP);
4682 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4690 * Change the "feat" flag for a grid, and notice/redraw the grid
4692 void cave_set_feat(int y, int x, int feat)
4694 cave_type *c_ptr = &cave[y][x];
4696 /* Change the feature */
4709 * Calculate "incremental motion". Used by project() and shoot().
4710 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4712 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4714 int dy, dx, dist, shift;
4716 /* Extract the distance travelled */
4717 dy = (*y < y1) ? y1 - *y : *y - y1;
4718 dx = (*x < x1) ? x1 - *x : *x - x1;
4720 /* Number of steps */
4721 dist = (dy > dx) ? dy : dx;
4723 /* We are calculating the next location */
4727 /* Calculate the total distance along each axis */
4728 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4729 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4731 /* Paranoia -- Hack -- no motion */
4732 if (!dy && !dx) return;
4735 /* Move mostly vertically */
4738 /* Extract a shift factor */
4739 shift = (dist * dx + (dy - 1) / 2) / dy;
4741 /* Sometimes move along the minor axis */
4742 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4744 /* Always move along major axis */
4745 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4748 /* Move mostly horizontally */
4751 /* Extract a shift factor */
4752 shift = (dist * dy + (dx - 1) / 2) / dx;
4754 /* Sometimes move along the minor axis */
4755 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4757 /* Always move along major axis */
4758 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4765 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4766 * at the final destination, assuming no monster gets in the way.
4768 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4770 bool projectable(int y1, int x1, int y2, int x2)
4777 /* Check the projection path */
4778 grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, 0);
4780 /* No grid is ever projectable from itself */
4781 if (!grid_n) return (FALSE);
4784 y = GRID_Y(grid_g[grid_n - 1]);
4785 x = GRID_X(grid_g[grid_n - 1]);
4787 /* May not end in an unrequested grid */
4788 if ((y != y2) || (x != x2)) return (FALSE);
4796 * Standard "find me a location" function
4798 * Obtains a legal location within the given distance of the initial
4799 * location, and with "los()" from the source to destination location.
4801 * This function is often called from inside a loop which searches for
4802 * locations while increasing the "d" distance.
4804 * Currently the "m" parameter is unused.
4806 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4813 /* Pick a location */
4816 /* Pick a new location */
4817 ny = rand_spread(y, d);
4818 nx = rand_spread(x, d);
4820 /* Ignore annoying locations */
4821 if (!in_bounds(ny, nx)) continue;
4823 /* Ignore "excessively distant" locations */
4824 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4826 /* Require "line of sight" */
4827 if (los(y, x, ny, nx)) break;
4830 /* Save the location */
4839 * Track a new monster
4841 void health_track(int m_idx)
4843 /* Track a new guy */
4844 p_ptr->health_who = m_idx;
4846 /* Redraw (later) */
4847 p_ptr->redraw |= (PR_HEALTH);
4853 * Hack -- track the given monster race
4855 void monster_race_track(bool kage, int r_idx)
4857 if (kage) r_idx = MON_KAGE;
4859 /* Save this monster ID */
4860 p_ptr->monster_race_idx = r_idx;
4863 p_ptr->window |= (PW_MONSTER);
4869 * Hack -- track the given object kind
4871 void object_kind_track(int k_idx)
4873 /* Save this monster ID */
4874 p_ptr->object_kind_idx = k_idx;
4877 p_ptr->window |= (PW_OBJECT);
4883 * Something has happened to disturb the player.
4885 * The first arg indicates a major disturbance, which affects search.
4887 * The second arg is currently unused, but could induce output flush.
4889 * All disturbance cancels repeated commands, resting, and running.
4891 void disturb(int stop_search, int unused_flag)
4894 unused_flag = unused_flag;
4896 /* Cancel auto-commands */
4897 /* command_new = 0; */
4899 /* Cancel repeated commands */
4905 /* Redraw the state (later) */
4906 p_ptr->redraw |= (PR_STATE);
4909 /* Cancel Resting */
4910 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
4913 set_action(ACTION_NONE);
4916 /* Cancel running */
4922 /* Check for new panel if appropriate */
4923 if (center_player && !center_running) verify_panel();
4925 /* Calculate torch radius */
4926 p_ptr->update |= (PU_TORCH);
4929 /* Flush the input if requested */
4930 if (flush_disturb) flush();