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;
19 * Distance between two points via Newton-Raphson technique
21 int distance (int y1, int x1, int y2, int x2)
23 int dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
24 int dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
26 /* Squared distance */
27 int target = (dy * dy) + (dx * dx);
29 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
30 int d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
35 if (!dy || !dx) return d;
39 /* Approximate error */
40 err = (target - d * d) / (2 * d);
42 /* No error - we are done */
54 * Return TRUE if the given feature is a trap
56 bool is_trap(int feat)
60 case FEAT_TRAP_TRAPDOOR:
62 case FEAT_TRAP_SPIKED_PIT:
63 case FEAT_TRAP_POISON_PIT:
64 case FEAT_TRAP_TY_CURSE:
65 case FEAT_TRAP_TELEPORT:
69 case FEAT_TRAP_LOSE_STR:
70 case FEAT_TRAP_LOSE_DEX:
71 case FEAT_TRAP_LOSE_CON:
73 case FEAT_TRAP_CONFUSE:
74 case FEAT_TRAP_POISON:
91 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,
92 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.
94 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
96 * The LOS begins at the center of the tile (x1,y1) and ends at the center of
97 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line
98 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
100 * We assume that the "mathematical corner" of a non-floor tile does not
101 * block line of sight.
103 * Because this function uses (short) ints for all calculations, overflow may
104 * occur if dx and dy exceed 90.
106 * Once all the degenerate cases are eliminated, the values "qx", "qy", and
107 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
108 * we can use integer arithmetic.
110 * We travel from start to finish along the longer axis, starting at the border
111 * between the first and second tiles, where the y offset = .5 * slope, taking
112 * into account the scale factor. See below.
114 * Also note that this function and the "move towards target" code do NOT
115 * share the same properties. Thus, you can see someone, target them, and
116 * then fire a bolt at them, but the bolt may hit a wall, not them. However,
117 * by clever choice of target locations, you can sometimes throw a "curve".
119 * Note that "line of sight" is not "reflexive" in all cases.
121 * Use the "projectable()" routine to test "spell/missile line of sight".
123 * Use the "update_view()" function to determine player line-of-sight.
125 bool los(int y1, int x1, int y2, int x2)
145 /* Slope, or 1/Slope, of LOS */
149 /* Extract the offset */
153 /* Extract the absolute offset */
158 /* Handle adjacent (or identical) grids */
159 if ((ax < 2) && (ay < 2)) return (TRUE);
162 /* Paranoia -- require "safe" origin */
163 /* if (!in_bounds(y1, x1)) return (FALSE); */
164 /* if (!in_bounds(y2, x2)) return (FALSE); */
167 /* Directly South/North */
170 /* South -- check for walls */
173 for (ty = y1 + 1; ty < y2; ty++)
175 if (!cave_floor_bold(ty, x1)) return (FALSE);
179 /* North -- check for walls */
182 for (ty = y1 - 1; ty > y2; ty--)
184 if (!cave_floor_bold(ty, x1)) return (FALSE);
192 /* Directly East/West */
195 /* East -- check for walls */
198 for (tx = x1 + 1; tx < x2; tx++)
200 if (!cave_floor_bold(y1, tx)) return (FALSE);
204 /* West -- check for walls */
207 for (tx = x1 - 1; tx > x2; tx--)
209 if (!cave_floor_bold(y1, tx)) return (FALSE);
218 /* Extract some signs */
219 sx = (dx < 0) ? -1 : 1;
220 sy = (dy < 0) ? -1 : 1;
223 /* Vertical "knights" */
228 if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
232 /* Horizontal "knights" */
237 if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
242 /* Calculate scale factor div 2 */
245 /* Calculate scale factor */
249 /* Travel horizontally */
252 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
258 /* Consider the special case where slope == 1. */
269 /* Note (below) the case (qy == f2), where */
270 /* the LOS exactly meets the corner of a tile. */
273 if (!cave_floor_bold(ty, tx)) return (FALSE);
284 if (!cave_floor_bold(ty, tx)) return (FALSE);
297 /* Travel vertically */
300 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
316 /* Note (below) the case (qx == f2), where */
317 /* the LOS exactly meets the corner of a tile. */
320 if (!cave_floor_bold(ty, tx)) return (FALSE);
331 if (!cave_floor_bold(ty, tx)) return (FALSE);
354 * Can the player "see" the given grid in detail?
356 * He must have vision, illumination, and line of sight.
358 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
359 * So, given "CAVE_LITE", we know that the grid is "fully visible".
361 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
362 * that a wall is visible from any direction. That would be odd. Except
363 * under wizard light, which might make sense. Thus, for walls, we require
364 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
365 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
366 * in line of sight of the player.
368 * This extra check is expensive, but it provides a more "correct" semantics.
370 * Note that we should not run this check on walls which are "outer walls" of
371 * the dungeon, or we will induce a memory fault, but actually verifying all
372 * of the locations would be extremely expensive.
374 * Thus, to speed up the function, we assume that all "perma-walls" which are
375 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
376 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
377 * and the player has more important things on his mind when he is attacking a
378 * monster vault. It is annoying, but an extremely important optimization.
380 * Note that "glowing walls" are only considered to be "illuminated" if the
381 * grid which is next to the wall in the direction of the player is also a
382 * "glowing" grid. This prevents the player from being able to "see" the
383 * walls of illuminated rooms from a corridor outside the room.
385 bool player_can_see_bold(int y, int x)
391 /* Blind players see nothing */
392 if (p_ptr->blind) return (FALSE);
394 /* Access the cave grid */
397 /* Note that "torch-lite" yields "illumination" */
398 if (c_ptr->info & (CAVE_LITE)) return (TRUE);
400 /* Require line of sight to the grid */
401 if (!player_has_los_bold(y, x)) return (FALSE);
403 if (p_ptr->pclass == CLASS_NINJA) return TRUE;
405 /* Require "perma-lite" of the grid */
406 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return (FALSE);
408 /* Floors are simple */
409 if (cave_floor_bold(y, x)) return (TRUE);
411 /* Hack -- move towards player */
412 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
413 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
415 /* Check for "local" illumination */
416 if (cave[yy][xx].info & (CAVE_GLOW | CAVE_MNLT))
418 /* Assume the wall is really illuminated */
422 /* Assume not visible */
429 * Returns true if the player's grid is dark
433 return (!player_can_see_bold(py, px));
440 * Determine if a given location may be "destroyed"
442 * Used by destruction spells, and for placing stairs, etc.
444 bool cave_valid_bold(int y, int x)
446 cave_type *c_ptr = &cave[y][x];
448 s16b this_o_idx, next_o_idx = 0;
451 /* Forbid perma-grids */
452 if (cave_perma_grid(c_ptr)) return (FALSE);
455 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
460 o_ptr = &o_list[this_o_idx];
462 /* Acquire next object */
463 next_o_idx = o_ptr->next_o_idx;
465 /* Forbid artifact grids */
466 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
477 * Determine if a given location may be "destroyed"
479 * Used by destruction spells, and for placing stairs, etc.
481 bool cave_valid_grid(cave_type *c_ptr)
483 s16b this_o_idx, next_o_idx = 0;
486 /* Forbid perma-grids */
487 if (cave_perma_grid(c_ptr)) return (FALSE);
490 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
495 o_ptr = &o_list[this_o_idx];
497 /* Acquire next object */
498 next_o_idx = o_ptr->next_o_idx;
500 /* Forbid artifact grids */
501 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
512 * Hack -- Legal monster codes
514 static cptr image_monster_hack = \
515 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
518 * Hack -- Legal monster codes for IBM pseudo-graphics
520 static cptr image_monster_hack_ibm = \
524 * Mega-Hack -- Hallucinatory monster
526 static void image_monster(byte *ap, char *cp)
528 int n = strlen(image_monster_hack);
530 /* Random symbol from set above */
533 /* Normal graphics */
534 if (!(streq(ANGBAND_SYS, "ibm")))
536 (*cp) = r_info[randint(max_r_idx-1)].x_char;
537 (*ap) = r_info[randint(max_r_idx-1)].x_attr;
540 /* IBM-pseudo graphics */
542 n = strlen(image_monster_hack_ibm);
543 (*cp) = (image_monster_hack_ibm[rand_int(n)]);
552 (*cp) = (image_monster_hack[rand_int(n)]);
562 * Hack -- Legal object codes
564 static cptr image_object_hack = \
565 "?/|\\\"!$()_-=[]{},~";
567 static cptr image_object_hack_ibm = \
571 * Mega-Hack -- Hallucinatory object
573 static void image_object(byte *ap, char *cp)
575 int n = strlen(image_object_hack);
579 if (!(streq(ANGBAND_SYS, "ibm")))
581 (*cp) = k_info[randint(max_k_idx-1)].x_char;
582 (*ap) = k_info[randint(max_k_idx-1)].x_attr;
586 n = strlen(image_object_hack_ibm);
587 (*cp) = (image_object_hack_ibm[rand_int(n)]);
595 (*cp) = (image_object_hack[rand_int(n)]);
605 * Hack -- Random hallucination
607 static void image_random(byte *ap, char *cp)
609 /* Normally, assume monsters */
610 if (rand_int(100) < 75)
612 image_monster(ap, cp);
615 /* Otherwise, assume objects */
618 image_object(ap, cp);
623 * Not using graphical tiles for this feature?
625 #define is_ascii_graphics(C , A) \
626 (!(((C) & 0x80) && ((A) & 0x80)))
629 * The 16x16 tile of the terrain supports lighting
631 static bool feat_supports_lighting(byte feat)
633 if (is_trap(feat)) return TRUE;
652 case FEAT_WALL_EXTRA:
653 case FEAT_WALL_INNER:
654 case FEAT_WALL_OUTER:
655 case FEAT_WALL_SOLID:
656 case FEAT_PERM_EXTRA:
657 case FEAT_PERM_INNER:
658 case FEAT_PERM_OUTER:
659 case FEAT_PERM_SOLID:
660 case FEAT_MINOR_GLYPH:
661 case FEAT_DEEP_WATER:
662 case FEAT_SHAL_WATER:
669 case FEAT_DEEP_GRASS:
679 * This array lists the effects of "brightness" on various "base" colours.
681 * This is used to do dynamic lighting effects in ascii :-)
682 * At the moment, only the various "floor" tiles are affected.
684 * The layout of the array is [x][0] = light and [x][1] = dark.
687 static byte lighting_colours[16][2] =
690 {TERM_L_DARK, TERM_DARK},
693 {TERM_YELLOW, TERM_SLATE},
696 {TERM_WHITE, TERM_L_DARK},
699 {TERM_YELLOW, TERM_UMBER},
702 {TERM_RED, TERM_RED},
705 {TERM_L_GREEN, TERM_GREEN},
708 {TERM_BLUE, TERM_BLUE},
711 {TERM_L_UMBER, TERM_RED},
714 {TERM_SLATE, TERM_L_DARK},
717 {TERM_WHITE, TERM_SLATE},
720 {TERM_L_RED, TERM_BLUE},
723 {TERM_YELLOW, TERM_ORANGE},
726 {TERM_L_RED, TERM_L_RED},
729 {TERM_L_GREEN, TERM_GREEN},
732 {TERM_L_BLUE, TERM_L_BLUE},
735 {TERM_YELLOW, TERM_UMBER}
739 * Extract the attr/char to display at the given (legal) map location
741 * Basically, we "paint" the chosen attr/char in several passes, starting
742 * with any known "terrain features" (defaulting to darkness), then adding
743 * any known "objects", and finally, adding any known "monsters". This
744 * is not the fastest method but since most of the calls to this function
745 * are made for grids with no monsters or objects, it is fast enough.
747 * Note that this function, if used on the grid containing the "player",
748 * will return the attr/char of the grid underneath the player, and not
749 * the actual player attr/char itself, allowing a lot of optimization
750 * in various "display" functions.
752 * Note that the "zero" entry in the feature/object/monster arrays are
753 * used to provide "special" attr/char codes, with "monster zero" being
754 * used for the player attr/char, "object zero" being used for the "stack"
755 * attr/char, and "feature zero" being used for the "nothing" attr/char,
756 * though this function makes use of only "feature zero".
758 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
759 * which means their color changes, and "ATTR_CLEAR", which means they take
760 * the color of whatever is under them, and "CHAR_CLEAR", which means that
761 * they take the symbol of whatever is under them. Technically, the flag
762 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
763 * examined, but this flag is currently ignored.
765 * Currently, we do nothing with multi-hued objects, because there are
766 * not any. If there were, they would have to set "shimmer_objects"
767 * when they were created, and then new "shimmer" code in "dungeon.c"
768 * would have to be created handle the "shimmer" effect, and the code
769 * in "cave.c" would have to be updated to create the shimmer effect.
771 * Note the effects of hallucination. Objects always appear as random
772 * "objects", monsters as random "monsters", and normal grids occasionally
773 * appear as random "monsters" or "objects", but note that these random
774 * "monsters" and "objects" are really just "colored ascii symbols".
776 * Note that "floors" and "invisible traps" (and "zero" features) are
777 * drawn as "floors" using a special check for optimization purposes,
778 * and these are the only features which get drawn using the special
779 * lighting effects activated by "view_special_lite".
781 * Note the use of the "mimic" field in the "terrain feature" processing,
782 * which allows any feature to "pretend" to be another feature. This is
783 * used to "hide" secret doors, and to make all "doors" appear the same,
784 * and all "walls" appear the same, and "hidden" treasure stay hidden.
785 * It is possible to use this field to make a feature "look" like a floor,
786 * but the "special lighting effects" for floors will not be used.
788 * Note the use of the new "terrain feature" information. Note that the
789 * assumption that all interesting "objects" and "terrain features" are
790 * memorized allows extremely optimized processing below. Note the use
791 * of separate flags on objects to mark them as memorized allows a grid
792 * to have memorized "terrain" without granting knowledge of any object
793 * which may appear in that grid.
795 * Note the efficient code used to determine if a "floor" grid is
796 * "memorized" or "viewable" by the player, where the test for the
797 * grid being "viewable" is based on the facts that (1) the grid
798 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
799 * line of sight, and (3) the player must not be blind, and uses the
800 * assumption that all torch-lit grids are in line of sight.
802 * Note that floors (and invisible traps) are the only grids which are
803 * not memorized when seen, so only these grids need to check to see if
804 * the grid is "viewable" to the player (if it is not memorized). Since
805 * most non-memorized grids are in fact walls, this induces *massive*
806 * efficiency, at the cost of *forcing* the memorization of non-floor
807 * grids when they are first seen. Note that "invisible traps" are
808 * always treated exactly like "floors", which prevents "cheating".
810 * Note the "special lighting effects" which can be activated for floor
811 * grids using the "view_special_lite" option (for "white" floor grids),
812 * causing certain grids to be displayed using special colors. If the
813 * player is "blind", we will use "dark gray", else if the grid is lit
814 * by the torch, and the "view_yellow_lite" option is set, we will use
815 * "yellow", else if the grid is "dark", we will use "dark gray", else
816 * if the grid is not "viewable", and the "view_bright_lite" option is
817 * set, and the we will use "slate" (gray). We will use "white" for all
818 * other cases, in particular, for illuminated viewable floor grids.
820 * Note the "special lighting effects" which can be activated for wall
821 * grids using the "view_granite_lite" option (for "white" wall grids),
822 * causing certain grids to be displayed using special colors. If the
823 * player is "blind", we will use "dark gray", else if the grid is lit
824 * by the torch, and the "view_yellow_lite" option is set, we will use
825 * "yellow", else if the "view_bright_lite" option is set, and the grid
826 * is not "viewable", or is "dark", or is glowing, but not when viewed
827 * from the player's current location, we will use "slate" (gray). We
828 * will use "white" for all other cases, in particular, for correctly
829 * illuminated viewable wall grids.
831 * Note that, when "view_granite_lite" is set, we use an inline version
832 * of the "player_can_see_bold()" function to check the "viewability" of
833 * grids when the "view_bright_lite" option is set, and we do NOT use
834 * any special colors for "dark" wall grids, since this would allow the
835 * player to notice the walls of illuminated rooms from a hallway that
836 * happened to run beside the room. The alternative, by the way, would
837 * be to prevent the generation of hallways next to rooms, but this
838 * would still allow problems when digging towards a room.
840 * Note that bizarre things must be done when the "attr" and/or "char"
841 * codes have the "high-bit" set, since these values are used to encode
842 * various "special" pictures in some versions, and certain situations,
843 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
844 * to be "scrambled" in various ways.
846 * Note that eventually we may use the "&" symbol for embedded treasure,
847 * and use the "*" symbol to indicate multiple objects, though this will
848 * have to wait for Angband 2.8.0 or later. Note that currently, this
849 * is not important, since only one object or terrain feature is allowed
850 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
852 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
853 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
854 * then a whole lot of code should be changed... XXX XXX
856 #ifdef USE_TRANSPARENCY
857 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
858 #else /* USE_TRANSPARENCY */
859 void map_info(int y, int x, byte *ap, char *cp)
860 #endif /* USE_TRANSPARENCY */
866 s16b this_o_idx, next_o_idx = 0;
880 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
882 /* Memorized (or visible) floor */
883 if ((c_ptr->info & CAVE_MARK) ||
884 (((c_ptr->info & CAVE_LITE) || (c_ptr->info & CAVE_MNLT) ||
885 ((c_ptr->info & CAVE_GLOW) &&
886 (c_ptr->info & CAVE_VIEW))) &&
890 f_ptr = &f_info[feat];
898 /* Special lighting effects */
899 if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_transparency))
904 if (new_ascii_graphics)
906 if (is_ascii_graphics(c,a))
908 /* Use darkened colour */
909 a = lighting_colours[a][1];
911 else if (use_transparency && feat_supports_lighting(feat))
913 /* Use a dark tile */
919 if (use_transparency)
921 /* Use a dark tile */
926 /* Use "dark gray" */
932 /* Handle "torch-lit" grids */
933 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
936 if (view_yellow_lite && !p_ptr->wild_mode)
938 if (new_ascii_graphics)
940 if (is_ascii_graphics(c,a))
942 /* Use lightened colour */
943 a = lighting_colours[a][0];
945 else if (use_transparency &&
946 feat_supports_lighting(feat))
948 /* Use a brightly lit tile */
955 if (view_yellow_lite)
957 if (use_transparency)
959 /* Use a brightly lit tile */
972 /* Handle "dark" grids */
973 else if (!(c_ptr->info & CAVE_GLOW))
975 if (new_ascii_graphics)
977 if (is_ascii_graphics(c,a))
979 /* Use darkened colour */
980 a = lighting_colours[a][1];
982 else if (use_transparency && feat_supports_lighting(feat))
984 /* Use a dark tile */
990 if (use_transparency)
992 /* Use a dark tile */
997 /* Use "dark gray" */
1003 /* Handle "out-of-sight" grids */
1004 else if (!(c_ptr->info & CAVE_VIEW))
1007 if (view_bright_lite && !p_ptr->wild_mode)
1009 if (new_ascii_graphics)
1011 if (is_ascii_graphics(c,a))
1013 /* Use darkened colour */
1014 a = lighting_colours[a][1];
1016 else if (use_transparency && feat_supports_lighting(feat))
1018 /* Use a dark tile */
1024 if (use_transparency)
1026 /* Use a dark tile */
1043 /* Access darkness */
1044 f_ptr = &f_info[FEAT_NONE];
1057 /* Memorized grids */
1058 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || !new_ascii_graphics))
1060 /* Apply "mimic" field */
1062 feat = c_ptr->mimic;
1064 feat = f_info[feat].mimic;
1066 /* Access feature */
1067 f_ptr = &f_info[feat];
1075 if (new_ascii_graphics)
1077 /* Handle "blind" */
1080 if (is_ascii_graphics(c,a))
1082 /* Use darkened colour */
1083 a = lighting_colours[a][1];
1085 else if (use_transparency && feat_supports_lighting(feat))
1087 /* Use a dark tile */
1092 /* Handle "torch-lit" grids */
1093 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1096 if (view_yellow_lite && !p_ptr->wild_mode && (!use_transparency || feat_supports_lighting(feat) || is_ascii_graphics(c,a)))
1098 if (is_ascii_graphics(c,a))
1100 /* Use lightened colour */
1101 a = lighting_colours[a][0];
1103 else if (use_transparency &&
1104 feat_supports_lighting(c_ptr->feat))
1106 /* Use a brightly lit tile */
1112 /* Handle "view_bright_lite" */
1113 else if (view_bright_lite && !p_ptr->wild_mode && (!use_transparency || feat_supports_lighting(feat) || is_ascii_graphics(c,a)))
1116 if (!(c_ptr->info & CAVE_VIEW))
1118 if (is_ascii_graphics(c,a))
1120 /* Use darkened colour */
1121 a = lighting_colours[a][1];
1123 else if (use_transparency && feat_supports_lighting(feat))
1125 /* Use a dark tile */
1131 else if (!(c_ptr->info & CAVE_GLOW))
1133 if (is_ascii_graphics(c,a))
1135 /* Use darkened colour */
1136 a = lighting_colours[a][1];
1141 /* Special lighting effects */
1142 else if (view_granite_lite && !p_ptr->wild_mode &&
1143 (((a == TERM_WHITE) && !use_transparency) ||
1144 (use_transparency && feat_supports_lighting(c_ptr->feat))))
1146 /* Handle "blind" */
1149 if (use_transparency)
1151 /* Use a dark tile */
1156 /* Use "dark gray" */
1161 /* Handle "torch-lit" grids */
1162 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1165 if (view_yellow_lite && !p_ptr->wild_mode)
1167 if (use_transparency)
1169 /* Use a brightly lit tile */
1180 /* Handle "view_bright_lite" */
1181 else if (view_bright_lite && !p_ptr->wild_mode)
1184 if (!(c_ptr->info & CAVE_VIEW))
1186 if (use_transparency)
1188 /* Use a dark tile */
1199 else if (!(c_ptr->info & CAVE_GLOW))
1201 if (use_transparency)
1203 /* Use a lit tile */
1212 /* Not glowing correctly */
1217 /* Hack -- move towards player */
1218 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1219 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1221 /* Check for "local" illumination */
1222 if (!(cave[yy][xx].info & CAVE_GLOW))
1224 if (use_transparency)
1226 /* Use a lit tile */
1239 /* "Simple Lighting" */
1242 /* Access feature */
1243 f_ptr = &f_info[feat];
1245 /* Handle "blind" */
1246 if (!(c_ptr->info & CAVE_MARK))
1248 /* Access darkness */
1249 f_ptr = &f_info[FEAT_NONE];
1260 /* Hack -- rare random hallucination, except on outer dungeon walls */
1261 if (p_ptr->image && (c_ptr->feat < FEAT_PERM_SOLID) && !rand_int(256))
1264 image_random(ap, cp);
1267 #ifdef USE_TRANSPARENCY
1268 /* Save the terrain info for the transparency effects */
1271 #endif /* USE_TRANSPARENCY */
1278 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1282 /* Acquire object */
1283 o_ptr = &o_list[this_o_idx];
1285 /* Acquire next object */
1286 next_o_idx = o_ptr->next_o_idx;
1288 /* Memorized objects */
1291 if (display_autopick)
1295 match_autopick = is_autopick(o_ptr);
1296 if(match_autopick == -1)
1299 act = autopick_action[match_autopick];
1301 if ((act & DO_DISPLAY) && (act & display_autopick))
1303 autopick_obj = o_ptr;
1307 match_autopick = -1;
1312 (*cp) = object_char(o_ptr);
1315 (*ap) = object_attr(o_ptr);
1317 /* Hack -- hallucination */
1318 if (p_ptr->image) image_object(ap, cp);
1326 /* Handle monsters */
1327 if (c_ptr->m_idx && display_autopick == 0 )
1329 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1331 /* Visible monster */
1334 monster_race *r_ptr;
1335 if (m_ptr->mflag2 & MFLAG_KAGE) r_ptr = &r_info[MON_KAGE];
1336 else r_ptr = &r_info[m_ptr->r_idx];
1344 /* Mimics' colors vary */
1345 if (strchr("\"!=", c) && !(r_ptr->flags1 & RF1_UNIQUE))
1350 /* Use semi-random attr */
1351 (*ap) = c_ptr->m_idx % 15 + 1;
1354 /* Special attr/char codes */
1355 else if ((a & 0x80) && (c & 0x80))
1364 /* Multi-hued monster */
1365 else if (r_ptr->flags1 & (RF1_ATTR_MULTI))
1367 /* Is it a shapechanger? */
1368 if (r_ptr->flags2 & (RF2_SHAPECHANGER))
1372 if (!(streq(ANGBAND_SYS, "ibm")))
1374 (*cp) = r_info[randint(max_r_idx-1)].x_char;
1375 (*ap) = r_info[randint(max_r_idx-1)].x_attr;
1379 int n = strlen(image_monster_hack_ibm);
1380 (*cp) = (image_monster_hack_ibm[rand_int(n)]);
1383 (*ap) = randint(15);
1388 (*cp) = (randint(25) == 1 ?
1389 image_object_hack[randint(strlen(image_object_hack))] :
1390 image_monster_hack[randint(strlen(image_monster_hack))]);
1396 /* Multi-hued attr */
1397 if (r_ptr->flags2 & RF2_ATTR_ANY)
1398 (*ap) = randint(15);
1399 else switch (randint(7))
1411 (*ap) = TERM_L_GREEN;
1417 (*ap) = TERM_L_DARK;
1425 /* Normal monster (not "clear" in any way) */
1426 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR | RF1_CHAR_CLEAR)))
1435 /* Hack -- Bizarre grid under monster */
1436 else if ((*ap & 0x80) || (*cp & 0x80))
1448 /* Normal (non-clear char) monster */
1449 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR)))
1455 /* Normal (non-clear attr) monster */
1456 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR)))
1463 /* Hack -- hallucination */
1466 /* Hallucinatory monster */
1467 image_monster(ap, cp);
1472 /* Handle "player" */
1473 if ((y == py) && (x == px))
1475 monster_race *r_ptr = &r_info[0];
1477 /* Get the "player" attr */
1480 /* Get the "player" char */
1483 #ifdef VARIABLE_PLAYER_GRAPH
1485 if (!streq(ANGBAND_GRAF, "new"))
1487 if (streq(ANGBAND_SYS,"ibm"))
1489 if (use_graphics && player_symbols)
1491 if (p_ptr->psex == SEX_FEMALE) c = (char)242;
1492 switch (p_ptr->pclass)
1495 if (p_ptr->lev < 20)
1501 case CLASS_WARRIOR_MAGE:
1502 case CLASS_RED_MAGE:
1503 if (p_ptr->lev < 20)
1508 case CLASS_CHAOS_WARRIOR:
1513 while (a == TERM_DARK);
1516 case CLASS_HIGH_MAGE:
1517 case CLASS_SORCERER:
1518 case CLASS_MAGIC_EATER:
1519 case CLASS_BLUE_MAGE:
1520 if (p_ptr->lev < 20)
1528 if (p_ptr->lev < 20)
1536 if (p_ptr->lev < 20)
1543 if (p_ptr->lev < 20)
1550 case CLASS_BERSERKER:
1552 if (p_ptr->lev < 20)
1558 case CLASS_MINDCRAFTER:
1559 case CLASS_FORCETRAINER:
1560 case CLASS_MIRROR_MASTER:
1561 if (p_ptr->lev < 20)
1567 default: /* Unknown */
1571 switch (p_ptr->prace)
1583 case RACE_HALF_TROLL:
1593 case RACE_HALF_OGRE:
1596 case RACE_HALF_GIANT:
1597 case RACE_HALF_TITAN:
1616 case RACE_DRACONIAN:
1617 if (p_ptr->lev < 20)
1619 else if (p_ptr->lev < 40)
1624 case RACE_MIND_FLAYER:
1635 if (p_ptr->pclass == CLASS_MAGE ||
1636 p_ptr->pclass == CLASS_PRIEST ||
1637 p_ptr->pclass == CLASS_HIGH_MAGE ||
1638 p_ptr->pclass == CLASS_SORCERER ||
1639 p_ptr->pclass == CLASS_MONK ||
1640 p_ptr->pclass == CLASS_FORCETRAINER ||
1641 p_ptr->pclass == CLASS_BLUE_MAGE ||
1642 p_ptr->pclass == CLASS_MIRROR_MASTER ||
1643 p_ptr->pclass == CLASS_MINDCRAFTER)
1677 #endif /* VARIABLE_PLAYER_GRAPH */
1685 * Moves the cursor to a given MAP (y,x) location
1687 void move_cursor_relative(int row, int col)
1689 /* Real co-ords convert to screen positions */
1690 row -= panel_row_prt;
1691 col -= panel_col_prt;
1694 Term_gotoxy(col, row);
1700 * Place an attr/char pair at the given map coordinate, if legal.
1702 void print_rel(char c, byte a, int y, int x)
1704 /* Only do "legal" locations */
1705 if (panel_contains(y, x))
1707 /* Hack -- fake monochrome */
1708 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
1710 if (world_monster) a = TERM_DARK;
1711 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
1712 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
1713 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1716 /* Draw the char using the attr */
1717 Term_draw(x-panel_col_prt, y-panel_row_prt, a, c);
1726 * Memorize interesting viewable object/features in the given grid
1728 * This function should only be called on "legal" grids.
1730 * This function will memorize the object and/or feature in the given
1731 * grid, if they are (1) viewable and (2) interesting. Note that all
1732 * objects are interesting, all terrain features except floors (and
1733 * invisible traps) are interesting, and floors (and invisible traps)
1734 * are interesting sometimes (depending on various options involving
1735 * the illumination of floor grids).
1737 * The automatic memorization of all objects and non-floor terrain
1738 * features as soon as they are displayed allows incredible amounts
1739 * of optimization in various places, especially "map_info()".
1741 * Note that the memorization of objects is completely separate from
1742 * the memorization of terrain features, preventing annoying floor
1743 * memorization when a detected object is picked up from a dark floor,
1744 * and object memorization when an object is dropped into a floor grid
1745 * which is memorized but out-of-sight.
1747 * This function should be called every time the "memorization" of
1748 * a grid (or the object in a grid) is called into question, such
1749 * as when an object is created in a grid, when a terrain feature
1750 * "changes" from "floor" to "non-floor", when any grid becomes
1751 * "illuminated" or "viewable", and when a "floor" grid becomes
1754 * Note the relatively efficient use of this function by the various
1755 * "update_view()" and "update_lite()" calls, to allow objects and
1756 * terrain features to be memorized (and drawn) whenever they become
1757 * viewable or illuminated in any way, but not when they "maintain"
1758 * or "lose" their previous viewability or illumination.
1760 * Note the butchered "internal" version of "player_can_see_bold()",
1761 * optimized primarily for the most common cases, that is, for the
1762 * non-marked floor grids.
1764 void note_spot(int y, int x)
1766 cave_type *c_ptr = &cave[y][x];
1768 s16b this_o_idx, next_o_idx = 0;
1771 /* Blind players see nothing */
1772 if (p_ptr->blind) return;
1774 /* Analyze non-torch-lit grids */
1775 if (!(c_ptr->info & (CAVE_LITE)))
1777 /* Require line of sight to the grid */
1778 if (!(c_ptr->info & (CAVE_VIEW))) return;
1780 if (p_ptr->pclass != CLASS_NINJA)
1782 /* Require "perma-lite" of the grid */
1783 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return;
1788 /* Hack -- memorize objects */
1789 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1791 object_type *o_ptr = &o_list[this_o_idx];
1793 /* Acquire next object */
1794 next_o_idx = o_ptr->next_o_idx;
1796 /* Memorize objects */
1797 o_ptr->marked = TRUE;
1801 /* Hack -- memorize grids */
1802 if (!(c_ptr->info & (CAVE_MARK)))
1804 if (p_ptr->pclass == CLASS_NINJA)
1806 c_ptr->info |= (CAVE_MARK);
1808 /* Handle floor grids first */
1809 if ((c_ptr->feat <= FEAT_INVIS) || (c_ptr->feat == FEAT_DIRT) || (c_ptr->feat == FEAT_GRASS))
1811 /* Option -- memorize all torch-lit floors */
1812 if (view_torch_grids && (c_ptr->info & (CAVE_LITE)))
1815 c_ptr->info |= (CAVE_MARK);
1818 /* Option -- memorize all perma-lit floors */
1819 else if (view_perma_grids && (c_ptr->info & (CAVE_GLOW)))
1822 c_ptr->info |= (CAVE_MARK);
1826 /* Memorize normal grids */
1827 else if (cave_floor_grid(c_ptr))
1830 c_ptr->info |= (CAVE_MARK);
1833 /* Memorize torch-lit walls */
1834 else if (c_ptr->info & (CAVE_LITE))
1837 c_ptr->info |= (CAVE_MARK);
1840 /* Memorize certain non-torch-lit wall grids */
1845 /* Hack -- move one grid towards player */
1846 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1847 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1849 /* Check for "local" illumination */
1850 if (cave[yy][xx].info & (CAVE_GLOW))
1853 c_ptr->info |= (CAVE_MARK);
1860 void display_dungeon(void)
1866 #ifdef USE_TRANSPARENCY
1869 #endif /* USE_TRANSPARENCY */
1871 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1873 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1875 if (in_bounds2(y, x))
1878 #ifdef USE_TRANSPARENCY
1879 /* Examine the grid */
1880 map_info(y, x, &a, &c, &ta, &tc);
1881 #else /* USE_TRANSPARENCY */
1882 /* Examine the grid */
1883 map_info(y, x, &a, &c);
1884 #endif /* USE_TRANSPARENCY */
1886 /* Hack -- fake monochrome */
1887 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
1889 if (world_monster) a = TERM_DARK;
1890 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
1891 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
1892 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1895 #ifdef USE_TRANSPARENCY
1896 /* Hack -- Queue it */
1897 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1898 #else /* USE_TRANSPARENCY */
1899 /* Hack -- Queue it */
1900 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
1901 #endif /* USE_TRANSPARENCY */
1906 /* Clear out-of-bound tiles */
1908 /* Access darkness */
1909 feature_type *f_ptr = &f_info[FEAT_NONE];
1917 #ifdef USE_TRANSPARENCY
1918 /* Hack -- Queue it */
1919 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1920 #else /* USE_TRANSPARENCY */
1921 /* Hack -- Queue it */
1922 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
1923 #endif /* USE_TRANSPARENCY */
1931 * Redraw (on the screen) a given MAP location
1933 * This function should only be called on "legal" grids
1935 void lite_spot(int y, int x)
1937 /* Redraw if on screen */
1938 if (panel_contains(y, x))
1943 #ifdef USE_TRANSPARENCY
1947 /* Examine the grid */
1948 map_info(y, x, &a, &c, &ta, &tc);
1949 #else /* USE_TRANSPARENCY */
1950 /* Examine the grid */
1951 map_info(y, x, &a, &c);
1952 #endif /* USE_TRANSPARENCY */
1954 /* Hack -- fake monochrome */
1955 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
1957 if (world_monster) a = TERM_DARK;
1958 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
1959 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
1960 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1963 #ifdef USE_TRANSPARENCY
1964 /* Hack -- Queue it */
1965 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c, ta, tc);
1966 #else /* USE_TRANSPARENCY */
1967 /* Hack -- Queue it */
1968 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c);
1969 #endif /* USE_TRANSPARENCY */
1975 * Prints the map of the dungeon
1977 * Note that, for efficiency, we contain an "optimized" version
1978 * of both "lite_spot()" and "print_rel()", and that we use the
1979 * "lite_spot()" function to display the player grid, if needed.
1985 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
1988 /* Access the cursor state */
1989 (void)Term_get_cursor(&v);
1991 /* Hide the cursor */
1992 (void)Term_set_cursor(0);
1995 for (y = panel_row_min; y <= panel_row_max; y++)
1997 /* Scan the columns of row "y" */
1998 for (x = panel_col_min; x <= panel_col_max; x++)
2003 #ifdef USE_TRANSPARENCY
2007 /* Determine what is there */
2008 map_info(y, x, &a, &c, &ta, &tc);
2010 /* Hack -- fake monochrome */
2011 if (fake_monochrome)
2013 if (world_monster) a = TERM_DARK;
2014 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2015 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2016 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2019 /* Efficiency -- Redraw that grid of the map */
2020 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c, ta, tc);
2021 #else /* USE_TRANSPARENCY */
2022 /* Determine what is there */
2023 map_info(y, x, &a, &c);
2025 /* Hack -- fake monochrome */
2026 if (fake_monochrome)
2028 if (world_monster) a = TERM_DARK;
2029 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2030 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2031 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2034 /* Efficiency -- Redraw that grid of the map */
2035 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c);
2036 #endif /* USE_TRANSPARENCY */
2040 /* Display player */
2043 /* Restore the cursor */
2044 (void)Term_set_cursor(v);
2050 * print project path
2052 void prt_path(int y, int x)
2057 int default_color = TERM_SLATE;
2058 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2060 if (!display_path) return;
2061 if (-1 == project_length)
2064 /* Get projection path */
2065 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2068 p_ptr->redraw |= (PR_MAP);
2074 for (i = 0; i < path_n; i++)
2076 int ny = GRID_Y(path_g[i]);
2077 int nx = GRID_X(path_g[i]);
2079 if (panel_contains(ny, nx))
2081 byte a = default_color;
2084 #ifdef USE_TRANSPARENCY
2088 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2090 /* Determine what is there */
2091 map_info(ny, nx, &a, &c, &ta, &tc);
2093 if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2095 else if (a == default_color)
2099 if (fake_monochrome)
2101 if (world_monster) a = TERM_DARK;
2102 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2103 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2104 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2108 /* Hack -- Queue it */
2109 Term_queue_char(nx-panel_col_prt, ny-panel_row_prt, a, '*', ta, tc);
2110 #else /* USE_TRANSPARENCY */
2112 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2114 /* Determine what is there */
2115 map_info(ny, nx, &a, &c);
2117 if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2119 else if (a == default_color)
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 /* Hack -- Queue it */
2132 Term_queue_char(nx-panel_col_prt, ny-panel_row_prt, a, '*');
2133 #endif /* USE_TRANSPARENCY */
2137 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2140 if (nx == x && ny == y) default_color = TERM_L_DARK;
2148 * Display highest priority object in the RATIO by RATIO area
2154 * Hack -- priority array (see below)
2156 * Note that all "walls" always look like "secret doors" (see "map_info()").
2158 static byte priority_table[][2] =
2167 { FEAT_SECRET, 10 },
2170 { FEAT_QUARTZ, 11 },
2176 { FEAT_RUBBLE, 13 },
2180 { FEAT_BROKEN, 15 },
2183 { FEAT_DOOR_HEAD + 0x00, 17 },
2186 { FEAT_QUARTZ_K, 19 },
2187 { FEAT_MAGMA_K, 19 },
2189 /* water, lava, & trees */
2190 { FEAT_DEEP_WATER, 20 },
2191 { FEAT_SHAL_WATER, 20 },
2192 { FEAT_DEEP_LAVA, 20 },
2193 { FEAT_SHAL_LAVA, 20 },
2197 { FEAT_DEEP_GRASS, 6 },
2198 { FEAT_DARK_PIT, 20 },
2200 { FEAT_MOUNTAIN, 20 },
2205 { FEAT_LESS_LESS, 25 },
2206 { FEAT_MORE_MORE, 25 },
2207 { FEAT_ENTRANCE, 25 },
2209 { FEAT_QUEST_ENTER, 25 },
2210 { FEAT_QUEST_EXIT, 25 },
2211 { FEAT_QUEST_DOWN, 25 },
2212 { FEAT_QUEST_UP, 25 },
2220 * Hack -- a priority function (see below)
2222 static byte priority(byte a, char c)
2226 feature_type *f_ptr;
2228 /* Scan the table */
2229 for (i = 0; TRUE; i++)
2231 /* Priority level */
2232 p1 = priority_table[i][1];
2238 p0 = priority_table[i][0];
2240 /* Access the feature */
2241 f_ptr = &f_info[p0];
2243 /* Check character and attribute, accept matches */
2244 if ((f_ptr->x_char == c) && (f_ptr->x_attr == a)) return (p1);
2251 static cptr simplify_list[][2] =
2258 {"^Amulet of ", "\""},
2259 {"^Scroll of ", "?"},
2260 {"^Scroll titled ", "?"},
2261 {"^Wand of " , "-"},
2263 {"^Staff of " , "_"},
2264 {"^Potion of ", "!"},
2276 static void display_shortened_item_name(object_type *o_ptr, int y)
2282 object_desc(buf, o_ptr, FALSE, 0);
2284 for (c = buf; *c; c++)
2287 for (i = 0; simplify_list[i][1]; i++)
2289 cptr org_w = simplify_list[i][0];
2299 if (!strncmp(c, org_w, strlen(org_w)))
2302 cptr tmp = simplify_list[i][1];
2305 tmp = c + strlen(org_w);
2315 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2321 if(len + 2 > 12) break;
2328 if(len + 1 > 12) break;
2334 Term_putstr(0, y, 12, tval_to_attr[o_ptr->tval % 128], buf);
2338 * Display a "small-scale" map of the dungeon in the active Term
2340 * Note that the "map_info()" function must return fully colorized
2341 * data or this function will not work correctly.
2343 * Note that this function must "disable" the special lighting
2344 * effects so that the "priority" function will work.
2346 * Note the use of a specialized "priority" function to allow this
2347 * function to work with any graphic attr/char mappings, and the
2348 * attempts to optimize this function where possible.
2350 void display_map(int *cy, int *cx)
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 /* Fill in the map */
2402 for (i = 0; i < cur_wid; ++i)
2404 for (j = 0; j < cur_hgt; ++j)
2413 /* Extract the current attr/char at that map location */
2414 #ifdef USE_TRANSPARENCY
2415 map_info(j, i, &ta, &tc, &ta, &tc);
2416 #else /* USE_TRANSPARENCY */
2417 map_info(j, i, &ta, &tc);
2418 #endif /* USE_TRANSPARENCY */
2420 /* Extract the priority of that attr/char */
2421 tp = priority(ta, tc);
2423 if(match_autopick!=-1
2424 && (match_autopick_yx[y][x] == -1
2425 || match_autopick_yx[y][x] > match_autopick))
2427 match_autopick_yx[y][x] = match_autopick;
2428 object_autopick_yx[y][x] = autopick_obj;
2452 /* Draw the corners */
2453 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2455 /* Draw the horizontal edges */
2456 for (x = 1; x <= SCREEN_WID; x++) mc[0][x] = mc[y][x] = '-';
2458 /* Draw the vertical edges */
2459 for (y = 1; y <= SCREEN_HGT; y++) mc[y][0] = mc[y][x] = '|';
2462 /* Display each map line in order */
2463 for (y = 0; y < SCREEN_HGT+2; ++y)
2465 /* Start a new line */
2466 Term_gotoxy(COL_MAP, y);
2468 /* Display the line */
2469 for (x = 0; x < SCREEN_WID+2; ++x)
2474 /* Hack -- fake monochrome */
2475 if (fake_monochrome)
2477 if (world_monster) ta = TERM_DARK;
2478 else if (p_ptr->invuln || world_player) ta = TERM_WHITE;
2479 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) ta = TERM_WHITE;
2480 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2483 /* Add the character */
2489 for (y = 1; y < SCREEN_HGT+1; ++y)
2491 match_autopick = -1;
2492 for (x = 1; x <= SCREEN_WID; x++){
2493 if (match_autopick_yx[y][x] != -1 &&
2494 (match_autopick > match_autopick_yx[y][x] ||
2495 match_autopick == -1)){
2496 match_autopick = match_autopick_yx[y][x];
2497 autopick_obj = object_autopick_yx[y][x];
2501 /* Clear old display */
2502 Term_putstr(0, y, 12, 0, " ");
2504 if (match_autopick != -1)
2506 display_shortened_item_name(autopick_obj, y);
2509 char buf[13] = "\0";
2510 strncpy(buf,autopick_name[match_autopick],12);
2518 /* Player location */
2519 (*cy) = py / yrat + 1 + ROW_MAP;
2520 (*cx) = px / xrat + 1 + COL_MAP;
2523 /* Restore lighting effects */
2524 view_special_lite = old_view_special_lite;
2525 view_granite_lite = old_view_granite_lite;
2530 * Display a "small-scale" map of the dungeon for the player
2532 * Currently, the "player" is displayed on the map. XXX XXX XXX
2534 void do_cmd_view_map(void)
2539 /* Save the screen */
2544 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2546 prt("Please wait...", 0, 0);
2552 /* Clear the screen */
2555 display_autopick = 0;
2557 /* Display the map */
2558 display_map(&cy, &cx);
2561 if(max_autopick && !p_ptr->wild_mode)
2563 display_autopick = ITEM_DISPLAY;
2571 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", 23, 1);
2573 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", 23, 1);
2576 /* Hilite the player */
2577 move_cursor(cy, cx);
2584 flag = DONT_AUTOPICK;
2586 flag = DO_AUTODESTROY;
2588 flag = (DO_AUTOPICK | DONT_AUTOPICK);
2594 if (~display_autopick & flag)
2595 display_autopick |= flag;
2597 display_autopick &= ~flag;
2598 /* Display the map */
2599 display_map(&cy, &cx);
2602 display_autopick = 0;
2608 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2610 put_str("Hit any key to continue", 23, 30);
2611 #endif /* Hilite the player */
2612 move_cursor(cy, cx);
2617 /* Restore the screen */
2626 * Some comments on the cave grid flags. -BEN-
2629 * One of the major bottlenecks in previous versions of Angband was in
2630 * the calculation of "line of sight" from the player to various grids,
2631 * such as monsters. This was such a nasty bottleneck that a lot of
2632 * silly things were done to reduce the dependancy on "line of sight",
2633 * for example, you could not "see" any grids in a lit room until you
2634 * actually entered the room, and there were all kinds of bizarre grid
2635 * flags to enable this behavior. This is also why the "call light"
2636 * spells always lit an entire room.
2638 * The code below provides functions to calculate the "field of view"
2639 * for the player, which, once calculated, provides extremely fast
2640 * calculation of "line of sight from the player", and to calculate
2641 * the "field of torch lite", which, again, once calculated, provides
2642 * extremely fast calculation of "which grids are lit by the player's
2643 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2644 * "GRID_LITE", as appropriate, these functions maintain an array for
2645 * each of these two flags, each array containing the locations of all
2646 * of the grids marked with the appropriate flag, which can be used to
2647 * very quickly scan through all of the grids in a given set.
2649 * To allow more "semantically valid" field of view semantics, whenever
2650 * the field of view (or the set of torch lit grids) changes, all of the
2651 * grids in the field of view (or the set of torch lit grids) are "drawn"
2652 * so that changes in the world will become apparent as soon as possible.
2653 * This has been optimized so that only grids which actually "change" are
2654 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2655 * of the grids which are entering or leaving the relevent set of grids.
2657 * These new methods are so efficient that the old nasty code was removed.
2659 * Note that there is no reason to "update" the "viewable space" unless
2660 * the player "moves", or walls/doors are created/destroyed, and there
2661 * is no reason to "update" the "torch lit grids" unless the field of
2662 * view changes, or the "light radius" changes. This means that when
2663 * the player is resting, or digging, or doing anything that does not
2664 * involve movement or changing the state of the dungeon, there is no
2665 * need to update the "view" or the "lite" regions, which is nice.
2667 * Note that the calls to the nasty "los()" function have been reduced
2668 * to a bare minimum by the use of the new "field of view" calculations.
2670 * I wouldn't be surprised if slight modifications to the "update_view()"
2671 * function would allow us to determine "reverse line-of-sight" as well
2672 * as "normal line-of-sight", which would allow monsters to use a more
2673 * "correct" calculation to determine if they can "see" the player. For
2674 * now, monsters simply "cheat" somewhat and assume that if the player
2675 * has "line of sight" to the monster, then the monster can "pretend"
2676 * that it has "line of sight" to the player.
2679 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2680 * grid and maintains an array of all "CAVE_LITE" grids.
2682 * This set of grids is the complete set of all grids which are lit by
2683 * the players light source, which allows the "player_can_see_bold()"
2684 * function to work very quickly.
2686 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2687 * fact, the player (unless blind) can always "see" all grids which are
2688 * marked as "CAVE_LITE", unless they are "off screen".
2691 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2692 * grid and maintains an array of all "CAVE_VIEW" grids.
2694 * This set of grids is the complete set of all grids within line of sight
2695 * of the player, allowing the "player_has_los_bold()" macro to work very
2699 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2700 * temporary internal flag to mark those grids which are not only in view,
2701 * but which are also "easily" in line of sight of the player. This flag
2702 * is always cleared when we are done.
2705 * The current "update_lite()" and "update_view()" algorithms use the
2706 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2707 * to keep track of which grids were previously marked as "CAVE_LITE" or
2708 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2710 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2711 * for various other purposes, such as spreading lite or darkness during
2712 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2715 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2716 * in some way permanently lit. However, for the player to "see" anything
2717 * in the grid, as determined by "player_can_see()", the player must not be
2718 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2719 * grids, even if marked as "perma lit", are only illuminated if they touch
2720 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2723 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2724 * that even if the player cannot "see" the grid, he "knows" the terrain in
2725 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2726 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2727 * or when one of the "memorize floor grids" options induces memorization.
2729 * Objects are "memorized" in a different way, using a special "marked" flag
2730 * on the object itself, which is set when an object is observed or detected.
2733 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2734 * and should be illuminated by "lite room" and "darkness" spells.
2737 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2738 * and should be unavailable for "teleportation" destinations.
2741 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2742 * which is observed, and the "view_torch_grids" allows the player to memorize
2743 * every torch-lit grid. The player will always memorize important walls,
2744 * doors, stairs, and other terrain features, as well as any "detected" grids.
2746 * Note that the new "update_view()" method allows, among other things, a room
2747 * to be "partially" seen as the player approaches it, with a growing cone of
2748 * floor appearing as the player gets closer to the door. Also, by not turning
2749 * on the "memorize perma-lit grids" option, the player will only "see" those
2750 * floor grids which are actually in line of sight.
2752 * And my favorite "plus" is that you can now use a special option to draw the
2753 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2754 * grids dimly), providing a "pretty" effect as the player runs around, and
2755 * to efficiently display the "torch lite" in a special color.
2758 * Some comments on the "update_view()" algorithm...
2760 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2761 * and only has to call "los()" on the borderline cases. The major axes/diags
2762 * even terminate early when they hit walls. I need to find a quick way
2763 * to "terminate" the other scans.
2765 * Note that in the worst case (a big empty area with say 5% scattered walls),
2766 * each of the 1500 or so nearby grids is checked once, most of them getting
2767 * an "instant" rating, and only a small portion requiring a call to "los()".
2769 * The only time that the algorithm appears to be "noticeably" too slow is
2770 * when running, and this is usually only important in town, since the town
2771 * provides about the worst scenario possible, with large open regions and
2772 * a few scattered obstructions. There is a special "efficiency" option to
2773 * allow the player to reduce his field of view in town, if needed.
2775 * In the "best" case (say, a normal stretch of corridor), the algorithm
2776 * makes one check for each viewable grid, and makes no calls to "los()".
2777 * So running in corridors is very fast, and if a lot of monsters are
2778 * nearby, it is much faster than the old methods.
2780 * Note that resting, most normal commands, and several forms of running,
2781 * plus all commands executed near large groups of monsters, are strictly
2782 * more efficient with "update_view()" that with the old "compute los() on
2783 * demand" method, primarily because once the "field of view" has been
2784 * calculated, it does not have to be recalculated until the player moves
2785 * (or a wall or door is created or destroyed).
2787 * Note that we no longer have to do as many "los()" checks, since once the
2788 * "view" region has been built, very few things cause it to be "changed"
2789 * (player movement, and the opening/closing of doors, changes in wall status).
2790 * Note that door/wall changes are only relevant when the door/wall itself is
2791 * in the "view" region.
2793 * The algorithm seems to only call "los()" from zero to ten times, usually
2794 * only when coming down a corridor into a room, or standing in a room, just
2795 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2796 * we will be reducing the calls to "los()".
2798 * I am thinking in terms of an algorithm that "walks" from the central point
2799 * out to the maximal "distance", at each point, determining the "view" code
2800 * (above). For each grid not on a major axis or diagonal, the "view" code
2801 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
2802 * (the one along the nearest diagonal, and the one next to that one, see
2803 * "update_view_aux()"...).
2805 * We "memorize" the viewable space array, so that at the cost of under 3000
2806 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2807 * each grid actually in the "viewable space". And for another 3000 bytes,
2808 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2809 * are also used by other routines, thus reducing the cost to almost nothing.
2811 * A similar thing is done for "forget_lite()" in which case the savings are
2812 * much less, but save us from doing bizarre maintenance checking.
2814 * In the worst "normal" case (in the middle of the town), the reachable space
2815 * actually reaches to more than half of the largest possible "circle" of view,
2816 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2817 * where all the walls have been removed), the reachable space actually reaches
2818 * the theoretical maximum size of just under 1500 grids.
2820 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2821 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2822 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2823 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2824 * entire possible space (including initialization) in one step per grid. If
2825 * we do the "clearing" as a separate step (and use an array of "view" grids),
2826 * then the clearing will take as many steps as grids that were viewed, and the
2827 * algorithm will be able to "stop" scanning at various points.
2828 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2839 * Actually erase the entire "lite" array, redrawing every grid
2841 void forget_lite(void)
2845 /* None to forget */
2846 if (!lite_n) return;
2848 /* Clear them all */
2849 for (i = 0; i < lite_n; i++)
2854 /* Forget "LITE" flag */
2855 cave[y][x].info &= ~(CAVE_LITE);
2869 * This macro allows us to efficiently add a grid to the "lite" array,
2870 * note that we are never called for illegal grids, or for grids which
2871 * have already been placed into the "lite" array, and we are never
2872 * called when the "lite" array is full.
2874 #define cave_lite_hack(Y,X) \
2876 if (!(cave[Y][X].info & (CAVE_LITE))) { \
2877 cave[Y][X].info |= (CAVE_LITE); \
2878 lite_y[lite_n] = (Y); \
2879 lite_x[lite_n] = (X); \
2885 * Update the set of grids "illuminated" by the player's lite.
2887 * This routine needs to use the results of "update_view()"
2889 * Note that "blindness" does NOT affect "torch lite". Be careful!
2891 * We optimize most lites (all non-artifact lites) by using "obvious"
2892 * facts about the results of "small" lite radius, and we attempt to
2893 * list the "nearby" grids before the more "distant" ones in the
2894 * array of torch-lit grids.
2896 * We will correctly handle "large" radius lites, though currently,
2897 * it is impossible for the player to have more than radius 3 lite.
2899 * We assume that "radius zero" lite is in fact no lite at all.
2901 * Torch Lantern Artifacts
2911 void update_lite(void)
2913 int i, x, y, min_x, max_x, min_y, max_y;
2914 int p = p_ptr->cur_lite;
2916 /*** Special case ***/
2918 /* Hack -- Player has no lite */
2921 /* Forget the old lite */
2924 /* Draw the player */
2929 /*** Save the old "lite" grids for later ***/
2931 /* Clear them all */
2932 for (i = 0; i < lite_n; i++)
2937 /* Mark the grid as not "lite" */
2938 cave[y][x].info &= ~(CAVE_LITE);
2940 /* Mark the grid as "seen" */
2941 cave[y][x].info |= (CAVE_TEMP);
2943 /* Add it to the "seen" set */
2953 /*** Collect the new "lite" grids ***/
2955 /* Radius 1 -- torch radius */
2959 cave_lite_hack(py, px);
2962 cave_lite_hack(py+1, px);
2963 cave_lite_hack(py-1, px);
2964 cave_lite_hack(py, px+1);
2965 cave_lite_hack(py, px-1);
2967 /* Diagonal grids */
2968 cave_lite_hack(py+1, px+1);
2969 cave_lite_hack(py+1, px-1);
2970 cave_lite_hack(py-1, px+1);
2971 cave_lite_hack(py-1, px-1);
2974 /* Radius 2 -- lantern radius */
2977 /* South of the player */
2978 if (cave_floor_bold(py+1, px))
2980 cave_lite_hack(py+2, px);
2981 cave_lite_hack(py+2, px+1);
2982 cave_lite_hack(py+2, px-1);
2985 /* North of the player */
2986 if (cave_floor_bold(py-1, px))
2988 cave_lite_hack(py-2, px);
2989 cave_lite_hack(py-2, px+1);
2990 cave_lite_hack(py-2, px-1);
2993 /* East of the player */
2994 if (cave_floor_bold(py, px+1))
2996 cave_lite_hack(py, px+2);
2997 cave_lite_hack(py+1, px+2);
2998 cave_lite_hack(py-1, px+2);
3001 /* West of the player */
3002 if (cave_floor_bold(py, px-1))
3004 cave_lite_hack(py, px-2);
3005 cave_lite_hack(py+1, px-2);
3006 cave_lite_hack(py-1, px-2);
3010 /* Radius 3+ -- artifact radius */
3015 /* Paranoia -- see "LITE_MAX" */
3018 /* South-East of the player */
3019 if (cave_floor_bold(py+1, px+1))
3021 cave_lite_hack(py+2, px+2);
3024 /* South-West of the player */
3025 if (cave_floor_bold(py+1, px-1))
3027 cave_lite_hack(py+2, px-2);
3030 /* North-East of the player */
3031 if (cave_floor_bold(py-1, px+1))
3033 cave_lite_hack(py-2, px+2);
3036 /* North-West of the player */
3037 if (cave_floor_bold(py-1, px-1))
3039 cave_lite_hack(py-2, px-2);
3044 if (min_y < 0) min_y = 0;
3048 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3052 if (min_x < 0) min_x = 0;
3056 if (max_x > cur_wid-1) max_x = cur_wid-1;
3058 /* Scan the maximal box */
3059 for (y = min_y; y <= max_y; y++)
3061 for (x = min_x; x <= max_x; x++)
3063 int dy = (py > y) ? (py - y) : (y - py);
3064 int dx = (px > x) ? (px - x) : (x - px);
3066 /* Skip the "central" grids (above) */
3067 if ((dy <= 2) && (dx <= 2)) continue;
3069 /* Hack -- approximate the distance */
3070 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3072 /* Skip distant grids */
3073 if (d > p) continue;
3075 /* Viewable, nearby, grids get "torch lit" */
3076 if (player_has_los_bold(y, x))
3078 /* This grid is "torch lit" */
3079 cave_lite_hack(y, x);
3086 /*** Complete the algorithm ***/
3088 /* Draw the new grids */
3089 for (i = 0; i < lite_n; i++)
3094 /* Update fresh grids */
3095 if (cave[y][x].info & (CAVE_TEMP)) continue;
3104 /* Clear them all */
3105 for (i = 0; i < temp_n; i++)
3110 /* No longer in the array */
3111 cave[y][x].info &= ~(CAVE_TEMP);
3113 /* Update stale grids */
3114 if (cave[y][x].info & (CAVE_LITE)) continue;
3125 static bool mon_invis;
3128 * Add a square to the changes array
3130 static void mon_lite_hack(int y, int x)
3135 if (!in_bounds2(y, x)) return;
3137 c_ptr = &cave[y][x];
3139 /* Want a unlit square in view of the player */
3140 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3142 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3143 if (!cave_floor_grid(c_ptr) && mon_invis) return;
3145 /* Save this square */
3146 if (temp_n < TEMP_MAX)
3154 c_ptr->info |= CAVE_MNLT;
3161 * Update squares illuminated by monsters.
3163 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3164 * denote squares illuminated by monsters.
3166 * The CAVE_TEMP flag is used to store the state during the
3167 * updating. Only squares in view of the player, whos state
3168 * changes are drawn via lite_spot().
3170 void update_mon_lite(void)
3179 bool daytime = ((turn % (20L * TOWN_DAWN)) < ((20L * TOWN_DAWN) / 2));
3181 /* Clear all monster lit squares */
3182 for (i = 0; i < mon_lite_n; i++)
3185 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3188 c_ptr->info |= (CAVE_TEMP);
3190 /* Clear monster illumination flag */
3191 c_ptr->info &= ~(CAVE_MNLT);
3194 /* Empty temp list of new squares to lite up */
3197 /* Loop through monsters, adding newly lit squares to changes list */
3198 for (i = 1; i < m_max; i++)
3200 monster_type *m_ptr = &m_list[i];
3201 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3203 /* Skip dead monsters */
3204 if (!m_ptr->r_idx) continue;
3206 /* Is it too far away? */
3207 if (m_ptr->cdis > ((d_info[dungeon_type].flags1 & DF1_DARKNESS) ? MAX_SIGHT / 2 + 1 : MAX_SIGHT + 3)) continue;
3209 /* Get lite radius */
3212 /* Note the radii are cumulative */
3213 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3214 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3216 /* Exit if has no light */
3218 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && daytime) || p_ptr->inside_battle)) continue;
3220 if (world_monster) continue;
3222 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3224 /* Access the location */
3228 /* Is the monster visible? */
3229 mon_invis = !(cave[fy][fx].info & CAVE_VIEW);
3231 /* The square it is on */
3232 mon_lite_hack(fy, fx);
3234 /* Adjacent squares */
3235 mon_lite_hack(fy + 1, fx);
3236 mon_lite_hack(fy - 1, fx);
3237 mon_lite_hack(fy, fx + 1);
3238 mon_lite_hack(fy, fx - 1);
3239 mon_lite_hack(fy + 1, fx + 1);
3240 mon_lite_hack(fy + 1, fx - 1);
3241 mon_lite_hack(fy - 1, fx + 1);
3242 mon_lite_hack(fy - 1, fx - 1);
3247 /* South of the monster */
3248 if (cave_floor_bold(fy + 1, fx))
3250 mon_lite_hack(fy + 2, fx + 1);
3251 mon_lite_hack(fy + 2, fx);
3252 mon_lite_hack(fy + 2, fx - 1);
3254 c_ptr = &cave[fy + 2][fx];
3257 if ((rad == 3) && cave_floor_grid(c_ptr))
3259 mon_lite_hack(fy + 3, fx + 1);
3260 mon_lite_hack(fy + 3, fx);
3261 mon_lite_hack(fy + 3, fx - 1);
3265 /* North of the monster */
3266 if (cave_floor_bold(fy - 1, fx))
3268 mon_lite_hack(fy - 2, fx + 1);
3269 mon_lite_hack(fy - 2, fx);
3270 mon_lite_hack(fy - 2, fx - 1);
3272 c_ptr = &cave[fy - 2][fx];
3275 if ((rad == 3) && cave_floor_grid(c_ptr))
3277 mon_lite_hack(fy - 3, fx + 1);
3278 mon_lite_hack(fy - 3, fx);
3279 mon_lite_hack(fy - 3, fx - 1);
3283 /* East of the monster */
3284 if (cave_floor_bold(fy, fx + 1))
3286 mon_lite_hack(fy + 1, fx + 2);
3287 mon_lite_hack(fy, fx + 2);
3288 mon_lite_hack(fy - 1, fx + 2);
3290 c_ptr = &cave[fy][fx + 2];
3293 if ((rad == 3) && cave_floor_grid(c_ptr))
3295 mon_lite_hack(fy + 1, fx + 3);
3296 mon_lite_hack(fy, fx + 3);
3297 mon_lite_hack(fy - 1, fx + 3);
3301 /* West of the monster */
3302 if (cave_floor_bold(fy, fx - 1))
3304 mon_lite_hack(fy + 1, fx - 2);
3305 mon_lite_hack(fy, fx - 2);
3306 mon_lite_hack(fy - 1, fx - 2);
3308 c_ptr = &cave[fy][fx - 2];
3311 if ((rad == 3) && cave_floor_grid(c_ptr))
3313 mon_lite_hack(fy + 1, fx - 3);
3314 mon_lite_hack(fy, fx - 3);
3315 mon_lite_hack(fy - 1, fx - 3);
3323 /* South-East of the monster */
3324 if (cave_floor_bold(fy + 1, fx + 1))
3326 mon_lite_hack(fy + 2, fx + 2);
3329 /* South-West of the monster */
3330 if (cave_floor_bold(fy + 1, fx - 1))
3332 mon_lite_hack(fy + 2, fx - 2);
3335 /* North-East of the monster */
3336 if (cave_floor_bold(fy - 1, fx + 1))
3338 mon_lite_hack(fy - 2, fx + 2);
3341 /* North-West of the monster */
3342 if (cave_floor_bold(fy - 1, fx - 1))
3344 mon_lite_hack(fy - 2, fx - 2);
3349 /* Save end of list of new squares */
3353 * Look at old set flags to see if there are any changes.
3355 for (i = 0; i < mon_lite_n; i++)
3360 if (!in_bounds2(fy, fx)) continue;
3363 c_ptr = &cave[fy][fx];
3365 /* It it no longer lit? */
3366 if (!(c_ptr->info & CAVE_MNLT) && player_has_los_grid(c_ptr))
3368 /* It is now unlit */
3373 /* Add to end of temp array */
3374 temp_x[temp_n] = (byte)fx;
3375 temp_y[temp_n] = (byte)fy;
3379 /* Clear the lite array */
3382 /* Copy the temp array into the lit array lighting the new squares. */
3383 for (i = 0; i < temp_n; i++)
3388 if (!in_bounds2(fy, fx)) continue;
3391 c_ptr = &cave[fy][fx];
3395 /* Clear the temp flag for the old lit grids */
3396 c_ptr->info &= ~(CAVE_TEMP);
3400 /* The is the square newly lit and visible? */
3401 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3408 /* Save in the monster lit array */
3409 mon_lite_x[mon_lite_n] = fx;
3410 mon_lite_y[mon_lite_n] = fy;
3415 /* Finished with temp_n */
3418 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3420 if (p_ptr->special_defense & NINJA_S_STEALTH)
3422 if (p_ptr->old_monlite != p_ptr->monlite)
3427 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3429 msg_print("Your mantle of shadow become thin.");
3435 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3437 msg_print("Your mantle of shadow restored its original darkness.");
3442 p_ptr->old_monlite = p_ptr->monlite;
3445 void clear_mon_lite(void)
3450 /* Clear all monster lit squares */
3451 for (i = 0; i < mon_lite_n; i++)
3454 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3456 /* Clear monster illumination flag */
3457 c_ptr->info &= ~(CAVE_MNLT);
3460 /* Empty the array */
3467 * Clear the viewable space
3469 void forget_view(void)
3475 /* None to forget */
3476 if (!view_n) return;
3478 /* Clear them all */
3479 for (i = 0; i < view_n; i++)
3484 /* Access the grid */
3485 c_ptr = &cave[y][x];
3487 /* Forget that the grid is viewable */
3488 c_ptr->info &= ~(CAVE_VIEW);
3490 /* Update the screen */
3501 * This macro allows us to efficiently add a grid to the "view" array,
3502 * note that we are never called for illegal grids, or for grids which
3503 * have already been placed into the "view" array, and we are never
3504 * called when the "view" array is full.
3506 #define cave_view_hack(C,Y,X) \
3508 if (!((C)->info & (CAVE_VIEW))){\
3509 (C)->info |= (CAVE_VIEW); \
3510 view_y[view_n] = (Y); \
3511 view_x[view_n] = (X); \
3518 * Helper function for "update_view()" below
3520 * We are checking the "viewability" of grid (y,x) by the player.
3522 * This function assumes that (y,x) is legal (i.e. on the map).
3524 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3525 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3527 * Note that we are using the "CAVE_XTRA" field for marking grids as
3528 * "easily viewable". This bit is cleared at the end of "update_view()".
3530 * This function adds (y,x) to the "viewable set" if necessary.
3532 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3534 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3536 bool f1, f2, v1, v2, z1, z2, wall;
3540 cave_type *g1_c_ptr;
3541 cave_type *g2_c_ptr;
3543 /* Access the grids */
3544 g1_c_ptr = &cave[y1][x1];
3545 g2_c_ptr = &cave[y2][x2];
3548 /* Check for walls */
3549 f1 = (cave_floor_grid(g1_c_ptr));
3550 f2 = (cave_floor_grid(g2_c_ptr));
3552 /* Totally blocked by physical walls */
3553 if (!f1 && !f2) return (TRUE);
3556 /* Check for visibility */
3557 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3558 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3560 /* Totally blocked by "unviewable neighbors" */
3561 if (!v1 && !v2) return (TRUE);
3564 /* Access the grid */
3565 c_ptr = &cave[y][x];
3568 /* Check for walls */
3569 wall = (!cave_floor_grid(c_ptr));
3572 /* Check the "ease" of visibility */
3573 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3574 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3576 /* Hack -- "easy" plus "easy" yields "easy" */
3579 c_ptr->info |= (CAVE_XTRA);
3581 cave_view_hack(c_ptr, y, x);
3586 /* Hack -- primary "easy" yields "viewed" */
3589 cave_view_hack(c_ptr, y, x);
3594 /* Hack -- "view" plus "view" yields "view" */
3597 /* c_ptr->info |= (CAVE_XTRA); */
3599 cave_view_hack(c_ptr, y, x);
3605 /* Mega-Hack -- the "los()" function works poorly on walls */
3608 cave_view_hack(c_ptr, y, x);
3614 /* Hack -- check line of sight */
3615 if (los(py, px, y, x))
3617 cave_view_hack(c_ptr, y, x);
3623 /* Assume no line of sight. */
3630 * Calculate the viewable space
3632 * 1: Process the player
3633 * 1a: The player is always (easily) viewable
3634 * 2: Process the diagonals
3635 * 2a: The diagonals are (easily) viewable up to the first wall
3636 * 2b: But never go more than 2/3 of the "full" distance
3637 * 3: Process the main axes
3638 * 3a: The main axes are (easily) viewable up to the first wall
3639 * 3b: But never go more than the "full" distance
3640 * 4: Process sequential "strips" in each of the eight octants
3641 * 4a: Each strip runs along the previous strip
3642 * 4b: The main axes are "previous" to the first strip
3643 * 4c: Process both "sides" of each "direction" of each strip
3644 * 4c1: Each side aborts as soon as possible
3645 * 4c2: Each side tells the next strip how far it has to check
3647 * Note that the octant processing involves some pretty interesting
3648 * observations involving when a grid might possibly be viewable from
3649 * a given grid, and on the order in which the strips are processed.
3651 * Note the use of the mathematical facts shown below, which derive
3652 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3653 * hypotenuse of a right triangle is primarily determined by the length
3654 * of the longest side, when one side is small, and is strictly less
3655 * than one-and-a-half times as long as the longest side when both of
3656 * the sides are large.
3658 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3659 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3661 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3663 * These observations are important because the calculation of the actual
3664 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3665 * while for small values (up to about 20 or so), the approximations above
3666 * are correct to within an error of at most one grid or so.
3668 * Observe the use of "full" and "over" in the code below, and the use of
3669 * the specialized calculation involving "limit", all of which derive from
3670 * the observations given above. Basically, we note that the "circle" of
3671 * view is completely contained in an "octagon" whose bounds are easy to
3672 * determine, and that only a few steps are needed to derive the actual
3673 * bounds of the circle given the bounds of the octagon.
3675 * Note that by skipping all the grids in the corners of the octagon, we
3676 * place an upper limit on the number of grids in the field of view, given
3677 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3678 * view, only about 1475 of these are in the "octagon" of view, and even
3679 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3680 * entries to completely contain the actual field of view.
3682 * Note also the care taken to prevent "running off the map". The use of
3683 * explicit checks on the "validity" of the "diagonal", and the fact that
3684 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3685 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3686 * of multiple checks on the validity of grids.
3688 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3689 * "ws","wn" variables. They work like this: While travelling down the
3690 * south-bound strip just to the east of the main south axis, as soon as
3691 * we get to a grid which does not "transmit" viewing, if all of the strips
3692 * preceding us (in this case, just the main axis) had terminated at or before
3693 * the same point, then we can stop, and reset the "max distance" to ourself.
3694 * So, each strip (named by major axis plus offset, thus "se" in this case)
3695 * maintains a "blockage" variable, initialized during the main axis step,
3696 * and checks it whenever a blockage is observed. After processing each
3697 * strip as far as the previous strip told us to process, the next strip is
3698 * told not to go farther than the current strip's farthest viewable grid,
3699 * unless open space is still available. This uses the "k" variable.
3701 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3702 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3703 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3704 * chunk of code which adds the given location to the "view" array if it
3705 * is not already there, using both the actual location and a pointer to
3706 * the cave grid. See above.
3708 * By the way, the purpose of this code is to reduce the dependancy on the
3709 * "los()" function which is slow, and, in some cases, not very accurate.
3711 * It is very possible that I am the only person who fully understands this
3712 * function, and for that I am truly sorry, but efficiency was very important
3713 * and the "simple" version of this function was just not fast enough. I am
3714 * more than willing to replace this function with a simpler one, if it is
3715 * equally efficient, and especially willing if the new function happens to
3716 * derive "reverse-line-of-sight" at the same time, since currently monsters
3717 * just use an optimized hack of "you see me, so I see you", and then use the
3718 * actual "projectable()" function to check spell attacks.
3720 void update_view(void)
3722 int n, m, d, k, y, x, z;
3724 int se, sw, ne, nw, es, en, ws, wn;
3728 int y_max = cur_hgt - 1;
3729 int x_max = cur_wid - 1;
3733 /*** Initialize ***/
3736 if (view_reduce_view && !dun_level)
3738 /* Full radius (10) */
3739 full = MAX_SIGHT / 2;
3741 /* Octagon factor (15) */
3742 over = MAX_SIGHT * 3 / 4;
3748 /* Full radius (20) */
3751 /* Octagon factor (30) */
3752 over = MAX_SIGHT * 3 / 2;
3756 /*** Step 0 -- Begin ***/
3758 /* Save the old "view" grids for later */
3759 for (n = 0; n < view_n; n++)
3764 /* Access the grid */
3765 c_ptr = &cave[y][x];
3767 /* Mark the grid as not in "view" */
3768 c_ptr->info &= ~(CAVE_VIEW);
3770 /* Mark the grid as "seen" */
3771 c_ptr->info |= (CAVE_TEMP);
3773 /* Add it to the "seen" set */
3779 /* Start over with the "view" array */
3782 /*** Step 1 -- adjacent grids ***/
3784 /* Now start on the player */
3788 /* Access the grid */
3789 c_ptr = &cave[y][x];
3791 /* Assume the player grid is easily viewable */
3792 c_ptr->info |= (CAVE_XTRA);
3794 /* Assume the player grid is viewable */
3795 cave_view_hack(c_ptr, y, x);
3798 /*** Step 2 -- Major Diagonals ***/
3803 /* Scan south-east */
3804 for (d = 1; d <= z; d++)
3806 c_ptr = &cave[y+d][x+d];
3807 c_ptr->info |= (CAVE_XTRA);
3808 cave_view_hack(c_ptr, y+d, x+d);
3809 if (!cave_floor_grid(c_ptr)) break;
3812 /* Scan south-west */
3813 for (d = 1; d <= z; d++)
3815 c_ptr = &cave[y+d][x-d];
3816 c_ptr->info |= (CAVE_XTRA);
3817 cave_view_hack(c_ptr, y+d, x-d);
3818 if (!cave_floor_grid(c_ptr)) break;
3821 /* Scan north-east */
3822 for (d = 1; d <= z; d++)
3824 c_ptr = &cave[y-d][x+d];
3825 c_ptr->info |= (CAVE_XTRA);
3826 cave_view_hack(c_ptr, y-d, x+d);
3827 if (!cave_floor_grid(c_ptr)) break;
3830 /* Scan north-west */
3831 for (d = 1; d <= z; d++)
3833 c_ptr = &cave[y-d][x-d];
3834 c_ptr->info |= (CAVE_XTRA);
3835 cave_view_hack(c_ptr, y-d, x-d);
3836 if (!cave_floor_grid(c_ptr)) break;
3840 /*** Step 3 -- major axes ***/
3843 for (d = 1; d <= full; d++)
3845 c_ptr = &cave[y+d][x];
3846 c_ptr->info |= (CAVE_XTRA);
3847 cave_view_hack(c_ptr, y+d, x);
3848 if (!cave_floor_grid(c_ptr)) break;
3851 /* Initialize the "south strips" */
3855 for (d = 1; d <= full; d++)
3857 c_ptr = &cave[y-d][x];
3858 c_ptr->info |= (CAVE_XTRA);
3859 cave_view_hack(c_ptr, y-d, x);
3860 if (!cave_floor_grid(c_ptr)) break;
3863 /* Initialize the "north strips" */
3867 for (d = 1; d <= full; d++)
3869 c_ptr = &cave[y][x+d];
3870 c_ptr->info |= (CAVE_XTRA);
3871 cave_view_hack(c_ptr, y, x+d);
3872 if (!cave_floor_grid(c_ptr)) break;
3875 /* Initialize the "east strips" */
3879 for (d = 1; d <= full; d++)
3881 c_ptr = &cave[y][x-d];
3882 c_ptr->info |= (CAVE_XTRA);
3883 cave_view_hack(c_ptr, y, x-d);
3884 if (!cave_floor_grid(c_ptr)) break;
3887 /* Initialize the "west strips" */
3891 /*** Step 4 -- Divide each "octant" into "strips" ***/
3893 /* Now check each "diagonal" (in parallel) */
3894 for (n = 1; n <= over / 2; n++)
3896 int ypn, ymn, xpn, xmn;
3899 /* Acquire the "bounds" of the maximal circle */
3901 if (z > full - n) z = full - n;
3902 while ((z + n + (n>>1)) > full) z--;
3905 /* Access the four diagonal grids */
3915 /* Maximum distance */
3916 m = MIN(z, y_max - ypn);
3919 if ((xpn <= x_max) && (n < se))
3922 for (k = n, d = 1; d <= m; d++)
3924 /* Check grid "d" in strip "n", notice "blockage" */
3925 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3927 if (n + d >= se) break;
3930 /* Track most distant "non-blockage" */
3937 /* Limit the next strip */
3942 if ((xmn >= 0) && (n < sw))
3945 for (k = n, d = 1; d <= m; d++)
3947 /* Check grid "d" in strip "n", notice "blockage" */
3948 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3950 if (n + d >= sw) break;
3953 /* Track most distant "non-blockage" */
3960 /* Limit the next strip */
3969 /* Maximum distance */
3973 if ((xpn <= x_max) && (n < ne))
3976 for (k = n, d = 1; d <= m; d++)
3978 /* Check grid "d" in strip "n", notice "blockage" */
3979 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3981 if (n + d >= ne) break;
3984 /* Track most distant "non-blockage" */
3991 /* Limit the next strip */
3996 if ((xmn >= 0) && (n < nw))
3999 for (k = n, d = 1; d <= m; d++)
4001 /* Check grid "d" in strip "n", notice "blockage" */
4002 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
4004 if (n + d >= nw) break;
4007 /* Track most distant "non-blockage" */
4014 /* Limit the next strip */
4023 /* Maximum distance */
4024 m = MIN(z, x_max - xpn);
4027 if ((ypn <= x_max) && (n < es))
4030 for (k = n, d = 1; d <= m; d++)
4032 /* Check grid "d" in strip "n", notice "blockage" */
4033 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
4035 if (n + d >= es) break;
4038 /* Track most distant "non-blockage" */
4045 /* Limit the next strip */
4050 if ((ymn >= 0) && (n < en))
4053 for (k = n, d = 1; d <= m; d++)
4055 /* Check grid "d" in strip "n", notice "blockage" */
4056 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4058 if (n + d >= en) break;
4061 /* Track most distant "non-blockage" */
4068 /* Limit the next strip */
4077 /* Maximum distance */
4081 if ((ypn <= y_max) && (n < ws))
4084 for (k = n, d = 1; d <= m; d++)
4086 /* Check grid "d" in strip "n", notice "blockage" */
4087 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4089 if (n + d >= ws) break;
4092 /* Track most distant "non-blockage" */
4099 /* Limit the next strip */
4104 if ((ymn >= 0) && (n < wn))
4107 for (k = n, d = 1; d <= m; d++)
4109 /* Check grid "d" in strip "n", notice "blockage" */
4110 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4112 if (n + d >= wn) break;
4115 /* Track most distant "non-blockage" */
4122 /* Limit the next strip */
4129 /*** Step 5 -- Complete the algorithm ***/
4131 /* Update all the new grids */
4132 for (n = 0; n < view_n; n++)
4137 /* Access the grid */
4138 c_ptr = &cave[y][x];
4140 /* Clear the "CAVE_XTRA" flag */
4141 c_ptr->info &= ~(CAVE_XTRA);
4143 /* Update only newly viewed grids */
4144 if (c_ptr->info & (CAVE_TEMP)) continue;
4153 /* Wipe the old grids, update as needed */
4154 for (n = 0; n < temp_n; n++)
4159 /* Access the grid */
4160 c_ptr = &cave[y][x];
4162 /* No longer in the array */
4163 c_ptr->info &= ~(CAVE_TEMP);
4165 /* Update only non-viewable grids */
4166 if (c_ptr->info & (CAVE_VIEW)) continue;
4182 * Hack -- provide some "speed" for the "flow" code
4183 * This entry is the "current index" for the "when" field
4184 * Note that a "when" value of "zero" means "not used".
4186 * Note that the "cost" indexes from 1 to 127 are for
4187 * "old" data, and from 128 to 255 are for "new" data.
4189 * This means that as long as the player does not "teleport",
4190 * then any monster up to 128 + MONSTER_FLOW_DEPTH will be
4191 * able to track down the player, and in general, will be
4192 * able to track down either the player or a position recently
4193 * occupied by the player.
4195 static int flow_n = 0;
4199 * Hack -- forget the "flow" information
4201 void forget_flow(void)
4205 /* Nothing to forget */
4206 if (!flow_n) return;
4208 /* Check the entire dungeon */
4209 for (y = 0; y < cur_hgt; y++)
4211 for (x = 0; x < cur_wid; x++)
4213 /* Forget the old data */
4214 cave[y][x].dist = 0;
4215 cave[y][x].cost = 0;
4216 cave[y][x].when = 0;
4226 * Hack -- Allow us to treat the "seen" array as a queue
4228 static int flow_head = 0;
4229 static int flow_tail = 0;
4233 * Take note of a reachable grid. Assume grid is legal.
4235 static void update_flow_aux(int y, int x, int m, int n)
4239 int old_head = flow_head;
4243 c_ptr = &cave[y][x];
4245 /* Ignore "pre-stamped" entries */
4246 if (c_ptr->when == flow_n && (c_ptr->dist <= n) && (c_ptr->cost <= m)) return;
4248 /* Ignore "walls" and "rubble" */
4249 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) return;
4251 /* Save the flow cost */
4252 if (c_ptr->when != flow_n || c_ptr->cost > m) c_ptr->cost = m;
4253 if (c_ptr->when != flow_n || c_ptr->dist > n) c_ptr->dist = n;
4255 /* Save the time-stamp */
4256 c_ptr->when = flow_n;
4258 /* Hack -- limit flow depth */
4259 if (n == MONSTER_FLOW_DEPTH) return;
4261 /* Enqueue that entry */
4262 temp_y[flow_head] = y;
4263 temp_x[flow_head] = x;
4265 /* Advance the queue */
4266 if (++flow_head == TEMP_MAX) flow_head = 0;
4268 /* Hack -- notice overflow by forgetting new entry */
4269 if (flow_head == flow_tail) flow_head = old_head;
4274 * Hack - speed up the update_flow algorithm by only doing
4275 * it everytime the player moves out of LOS of the last
4278 static u16b flow_x = 0;
4279 static u16b flow_y = 0;
4284 * Hack -- fill in the "cost" field of every grid that the player
4285 * can "reach" with the number of steps needed to reach that grid.
4286 * This also yields the "distance" of the player from every grid.
4288 * In addition, mark the "when" of the grids that can reach
4289 * the player with the incremented value of "flow_n".
4291 * Hack -- use the "seen" array as a "circular queue".
4293 * We do not need a priority queue because the cost from grid
4294 * to grid is always "one" and we process them in order.
4296 void update_flow(void)
4300 /* Hack -- disabled */
4301 if (stupid_monsters) return;
4303 /* Paranoia -- make sure the array is empty */
4307 /* The last way-point is on the map */
4308 if (running && in_bounds(flow_y, flow_x))
4310 /* The way point is in sight - do not update. (Speedup) */
4311 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4315 /* Save player position */
4319 /* Cycle the old entries (once per 128 updates) */
4322 /* Rotate the time-stamps */
4323 for (y = 0; y < cur_hgt; y++)
4325 for (x = 0; x < cur_wid; x++)
4327 int w = cave[y][x].when;
4328 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4336 /* Start a new flow (never use "zero") */
4340 /* Reset the "queue" */
4341 flow_head = flow_tail = 0;
4343 /* Add the player's grid to the queue */
4344 update_flow_aux(py, px, 0, 0);
4346 /* Now process the queue */
4347 while (flow_head != flow_tail)
4349 /* Extract the next entry */
4350 y = temp_y[flow_tail];
4351 x = temp_x[flow_tail];
4353 /* Forget that entry */
4354 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4356 /* Add the "children" */
4357 for (d = 0; d < 8; d++)
4359 int tmp = cave[y][x].cost+1;
4360 int yy = y+ddy_ddd[d];
4361 int xx = x+ddx_ddd[d];
4363 if ((cave[yy][xx].feat >= FEAT_DOOR_HEAD) && (cave[yy][xx].feat <= FEAT_SECRET)) tmp += 3;
4364 /* Add that child if "legal" */
4365 update_flow_aux(yy, xx, tmp, cave[y][x].dist+1);
4369 /* Forget the flow info */
4370 flow_head = flow_tail = 0;
4376 * Hack -- map the current panel (plus some) ala "magic mapping"
4378 void map_area(int range)
4384 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4386 /* Scan that area */
4387 for (y = 1; y < cur_hgt - 1; y++)
4389 for (x = 1; x < cur_wid - 1; x++)
4391 if (distance(py, px, y, x) > range) continue;
4393 c_ptr = &cave[y][x];
4395 /* All non-walls are "checked" */
4396 if ((c_ptr->feat < FEAT_SECRET) ||
4397 (c_ptr->feat == FEAT_RUBBLE) ||
4398 ((c_ptr->feat >= FEAT_MINOR_GLYPH) &&
4399 (c_ptr->feat <= FEAT_TREES)) ||
4400 (c_ptr->feat >= FEAT_TOWN))
4402 /* Memorize normal features */
4403 if ((c_ptr->feat > FEAT_INVIS) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4405 /* Memorize the object */
4406 c_ptr->info |= (CAVE_MARK);
4409 /* Memorize known walls */
4410 for (i = 0; i < 8; i++)
4412 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4414 /* Memorize walls (etc) */
4415 if ((c_ptr->feat >= FEAT_SECRET) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4417 /* Memorize the walls */
4418 c_ptr->info |= (CAVE_MARK);
4426 p_ptr->redraw |= (PR_MAP);
4429 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4435 * Light up the dungeon using "clairvoyance"
4437 * This function "illuminates" every grid in the dungeon, memorizes all
4438 * "objects", memorizes all grids as with magic mapping, and, under the
4439 * standard option settings (view_perma_grids but not view_torch_grids)
4440 * memorizes all floor grids too.
4442 * Note that if "view_perma_grids" is not set, we do not memorize floor
4443 * grids, since this would defeat the purpose of "view_perma_grids", not
4444 * that anyone seems to play without this option.
4446 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4447 * since this would prevent the use of "view_torch_grids" as a method to
4448 * keep track of what grids have been observed directly.
4450 void wiz_lite(bool wizard, bool ninja)
4454 /* Memorize objects */
4455 for (i = 1; i < o_max; i++)
4457 object_type *o_ptr = &o_list[i];
4459 /* Skip dead objects */
4460 if (!o_ptr->k_idx) continue;
4462 /* Skip held objects */
4463 if (o_ptr->held_m_idx) continue;
4466 /* Skip objects in vaults, if not a wizard. -LM- */
4467 if ((wizard == FALSE) &&
4468 (cave[o_ptr->iy][o_ptr->ix].info & (CAVE_ICKY))) continue;
4472 o_ptr->marked = TRUE;
4475 /* Scan all normal grids */
4476 for (y = 1; y < cur_hgt - 1; y++)
4478 /* Scan all normal grids */
4479 for (x = 1; x < cur_wid - 1; x++)
4481 cave_type *c_ptr = &cave[y][x];
4483 /* Process all non-walls */
4484 if (cave_floor_bold(y, x) || (c_ptr->feat == FEAT_RUBBLE) || (c_ptr->feat == FEAT_TREES) || (c_ptr->feat == FEAT_MOUNTAIN))
4486 /* Scan all neighbors */
4487 for (i = 0; i < 9; i++)
4489 int yy = y + ddy_ddd[i];
4490 int xx = x + ddx_ddd[i];
4493 c_ptr = &cave[yy][xx];
4495 /* Memorize normal features */
4498 /* Memorize the grid */
4499 c_ptr->info |= (CAVE_MARK);
4503 if ((c_ptr->feat > FEAT_INVIS))
4505 /* Memorize the grid */
4506 c_ptr->info |= (CAVE_MARK);
4509 /* Perma-lite the grid */
4510 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4512 c_ptr->info |= (CAVE_GLOW);
4514 /* Normally, memorize floors (see above) */
4515 if (view_perma_grids && !view_torch_grids)
4517 /* Memorize the grid */
4518 c_ptr->info |= (CAVE_MARK);
4527 /* Update the monsters */
4528 p_ptr->update |= (PU_MONSTERS);
4531 p_ptr->redraw |= (PR_MAP);
4534 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4539 * Forget the dungeon map (ala "Thinking of Maud...").
4546 /* Forget every grid */
4547 for (y = 0; y < cur_hgt; y++)
4549 for (x = 0; x < cur_wid; x++)
4551 cave_type *c_ptr = &cave[y][x];
4553 /* Process the grid */
4554 c_ptr->info &= ~(CAVE_MARK);
4558 /* Forget all objects */
4559 for (i = 1; i < o_max; i++)
4561 object_type *o_ptr = &o_list[i];
4563 /* Skip dead objects */
4564 if (!o_ptr->k_idx) continue;
4566 /* Skip held objects */
4567 if (o_ptr->held_m_idx) continue;
4569 /* Forget the object */
4570 o_ptr->marked = FALSE;
4573 /* Mega-Hack -- Forget the view and lite */
4574 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4576 /* Update the view and lite */
4577 p_ptr->update |= (PU_VIEW | PU_LITE);
4579 /* Update the monsters */
4580 p_ptr->update |= (PU_MONSTERS);
4583 p_ptr->redraw |= (PR_MAP);
4586 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4594 * Change the "feat" flag for a grid, and notice/redraw the grid
4596 void cave_set_feat(int y, int x, int feat)
4598 cave_type *c_ptr = &cave[y][x];
4600 /* Change the feature */
4613 * Calculate "incremental motion". Used by project() and shoot().
4614 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4616 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4618 int dy, dx, dist, shift;
4620 /* Extract the distance travelled */
4621 dy = (*y < y1) ? y1 - *y : *y - y1;
4622 dx = (*x < x1) ? x1 - *x : *x - x1;
4624 /* Number of steps */
4625 dist = (dy > dx) ? dy : dx;
4627 /* We are calculating the next location */
4631 /* Calculate the total distance along each axis */
4632 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4633 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4635 /* Paranoia -- Hack -- no motion */
4636 if (!dy && !dx) return;
4639 /* Move mostly vertically */
4642 /* Extract a shift factor */
4643 shift = (dist * dx + (dy - 1) / 2) / dy;
4645 /* Sometimes move along the minor axis */
4646 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4648 /* Always move along major axis */
4649 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4652 /* Move mostly horizontally */
4655 /* Extract a shift factor */
4656 shift = (dist * dy + (dx - 1) / 2) / dx;
4658 /* Sometimes move along the minor axis */
4659 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4661 /* Always move along major axis */
4662 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4669 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4670 * at the final destination, assuming no monster gets in the way.
4672 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4674 bool projectable(int y1, int x1, int y2, int x2)
4681 /* Check the projection path */
4682 grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, 0);
4684 /* No grid is ever projectable from itself */
4685 if (!grid_n) return (FALSE);
4688 y = GRID_Y(grid_g[grid_n - 1]);
4689 x = GRID_X(grid_g[grid_n - 1]);
4691 /* May not end in an unrequested grid */
4692 if ((y != y2) || (x != x2)) return (FALSE);
4700 * Standard "find me a location" function
4702 * Obtains a legal location within the given distance of the initial
4703 * location, and with "los()" from the source to destination location.
4705 * This function is often called from inside a loop which searches for
4706 * locations while increasing the "d" distance.
4708 * Currently the "m" parameter is unused.
4710 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4717 /* Pick a location */
4720 /* Pick a new location */
4721 ny = rand_spread(y, d);
4722 nx = rand_spread(x, d);
4724 /* Ignore annoying locations */
4725 if (!in_bounds(ny, nx)) continue;
4727 /* Ignore "excessively distant" locations */
4728 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4730 /* Require "line of sight" */
4731 if (los(y, x, ny, nx)) break;
4734 /* Save the location */
4743 * Track a new monster
4745 void health_track(int m_idx)
4747 /* Track a new guy */
4748 p_ptr->health_who = m_idx;
4750 /* Redraw (later) */
4751 p_ptr->redraw |= (PR_HEALTH);
4757 * Hack -- track the given monster race
4759 void monster_race_track(bool kage, int r_idx)
4761 if (kage) r_idx = MON_KAGE;
4763 /* Save this monster ID */
4764 p_ptr->monster_race_idx = r_idx;
4767 p_ptr->window |= (PW_MONSTER);
4773 * Hack -- track the given object kind
4775 void object_kind_track(int k_idx)
4777 /* Save this monster ID */
4778 p_ptr->object_kind_idx = k_idx;
4781 p_ptr->window |= (PW_OBJECT);
4787 * Something has happened to disturb the player.
4789 * The first arg indicates a major disturbance, which affects search.
4791 * The second arg is currently unused, but could induce output flush.
4793 * All disturbance cancels repeated commands, resting, and running.
4795 void disturb(int stop_search, int unused_flag)
4798 unused_flag = unused_flag;
4800 /* Cancel auto-commands */
4801 /* command_new = 0; */
4803 /* Cancel repeated commands */
4809 /* Redraw the state (later) */
4810 p_ptr->redraw |= (PR_STATE);
4813 /* Cancel Resting */
4814 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
4817 set_action(ACTION_NONE);
4820 /* Cancel running */
4826 /* Check for new panel if appropriate */
4827 if (center_player && !center_running) verify_panel();
4829 /* Calculate torch radius */
4830 p_ptr->update |= (PU_TORCH);
4833 /* Flush the input if requested */
4834 if (flush_disturb) flush();