3 /* Purpose: low level dungeon routines -BEN- */
10 * Support for Adam Bolt's tileset, lighting and transparency effects
11 * by Robert Ruehlmann (rr9@angband.org)
14 static byte display_autopick;
15 static int match_autopick;
16 static object_type *autopick_obj;
17 static int feat_priority;
20 * Distance between two points via Newton-Raphson technique
22 int distance (int y1, int x1, int y2, int x2)
24 int dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
25 int dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
27 /* Squared distance */
28 int target = (dy * dy) + (dx * dx);
30 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
31 int d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
36 if (!dy || !dx) return d;
40 /* Approximate error */
41 err = (target - d * d) / (2 * d);
43 /* No error - we are done */
55 * Return TRUE if the given feature is a trap
57 bool is_trap(int feat)
61 case FEAT_TRAP_TRAPDOOR:
63 case FEAT_TRAP_SPIKED_PIT:
64 case FEAT_TRAP_POISON_PIT:
65 case FEAT_TRAP_TY_CURSE:
66 case FEAT_TRAP_TELEPORT:
70 case FEAT_TRAP_LOSE_STR:
71 case FEAT_TRAP_LOSE_DEX:
72 case FEAT_TRAP_LOSE_CON:
74 case FEAT_TRAP_CONFUSE:
75 case FEAT_TRAP_POISON:
92 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,
93 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.
95 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
97 * The LOS begins at the center of the tile (x1,y1) and ends at the center of
98 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line
99 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
101 * We assume that the "mathematical corner" of a non-floor tile does not
102 * block line of sight.
104 * Because this function uses (short) ints for all calculations, overflow may
105 * occur if dx and dy exceed 90.
107 * Once all the degenerate cases are eliminated, the values "qx", "qy", and
108 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
109 * we can use integer arithmetic.
111 * We travel from start to finish along the longer axis, starting at the border
112 * between the first and second tiles, where the y offset = .5 * slope, taking
113 * into account the scale factor. See below.
115 * Also note that this function and the "move towards target" code do NOT
116 * share the same properties. Thus, you can see someone, target them, and
117 * then fire a bolt at them, but the bolt may hit a wall, not them. However,
118 * by clever choice of target locations, you can sometimes throw a "curve".
120 * Note that "line of sight" is not "reflexive" in all cases.
122 * Use the "projectable()" routine to test "spell/missile line of sight".
124 * Use the "update_view()" function to determine player line-of-sight.
126 bool los(int y1, int x1, int y2, int x2)
146 /* Slope, or 1/Slope, of LOS */
150 /* Extract the offset */
154 /* Extract the absolute offset */
159 /* Handle adjacent (or identical) grids */
160 if ((ax < 2) && (ay < 2)) return (TRUE);
163 /* Paranoia -- require "safe" origin */
164 /* if (!in_bounds(y1, x1)) return (FALSE); */
165 /* if (!in_bounds(y2, x2)) return (FALSE); */
168 /* Directly South/North */
171 /* South -- check for walls */
174 for (ty = y1 + 1; ty < y2; ty++)
176 if (!cave_floor_bold(ty, x1)) return (FALSE);
180 /* North -- check for walls */
183 for (ty = y1 - 1; ty > y2; ty--)
185 if (!cave_floor_bold(ty, x1)) return (FALSE);
193 /* Directly East/West */
196 /* East -- check for walls */
199 for (tx = x1 + 1; tx < x2; tx++)
201 if (!cave_floor_bold(y1, tx)) return (FALSE);
205 /* West -- check for walls */
208 for (tx = x1 - 1; tx > x2; tx--)
210 if (!cave_floor_bold(y1, tx)) return (FALSE);
219 /* Extract some signs */
220 sx = (dx < 0) ? -1 : 1;
221 sy = (dy < 0) ? -1 : 1;
224 /* Vertical "knights" */
229 if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
233 /* Horizontal "knights" */
238 if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
243 /* Calculate scale factor div 2 */
246 /* Calculate scale factor */
250 /* Travel horizontally */
253 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
259 /* Consider the special case where slope == 1. */
270 /* Note (below) the case (qy == f2), where */
271 /* the LOS exactly meets the corner of a tile. */
274 if (!cave_floor_bold(ty, tx)) return (FALSE);
285 if (!cave_floor_bold(ty, tx)) return (FALSE);
298 /* Travel vertically */
301 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
317 /* Note (below) the case (qx == f2), where */
318 /* the LOS exactly meets the corner of a tile. */
321 if (!cave_floor_bold(ty, tx)) return (FALSE);
332 if (!cave_floor_bold(ty, tx)) return (FALSE);
355 * Can the player "see" the given grid in detail?
357 * He must have vision, illumination, and line of sight.
359 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
360 * So, given "CAVE_LITE", we know that the grid is "fully visible".
362 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
363 * that a wall is visible from any direction. That would be odd. Except
364 * under wizard light, which might make sense. Thus, for walls, we require
365 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
366 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
367 * in line of sight of the player.
369 * This extra check is expensive, but it provides a more "correct" semantics.
371 * Note that we should not run this check on walls which are "outer walls" of
372 * the dungeon, or we will induce a memory fault, but actually verifying all
373 * of the locations would be extremely expensive.
375 * Thus, to speed up the function, we assume that all "perma-walls" which are
376 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
377 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
378 * and the player has more important things on his mind when he is attacking a
379 * monster vault. It is annoying, but an extremely important optimization.
381 * Note that "glowing walls" are only considered to be "illuminated" if the
382 * grid which is next to the wall in the direction of the player is also a
383 * "glowing" grid. This prevents the player from being able to "see" the
384 * walls of illuminated rooms from a corridor outside the room.
386 bool player_can_see_bold(int y, int x)
392 /* Blind players see nothing */
393 if (p_ptr->blind) return (FALSE);
395 /* Access the cave grid */
398 /* Note that "torch-lite" yields "illumination" */
399 if (c_ptr->info & (CAVE_LITE)) return (TRUE);
401 /* Require line of sight to the grid */
402 if (!player_has_los_bold(y, x)) return (FALSE);
404 if (p_ptr->pclass == CLASS_NINJA) return TRUE;
406 /* Require "perma-lite" of the grid */
407 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return (FALSE);
409 /* Floors are simple */
410 if (cave_floor_bold(y, x)) return (TRUE);
412 /* Hack -- move towards player */
413 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
414 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
416 /* Check for "local" illumination */
417 if (cave[yy][xx].info & (CAVE_GLOW | CAVE_MNLT))
419 /* Assume the wall is really illuminated */
423 /* Assume not visible */
430 * Returns true if the player's grid is dark
434 return (!player_can_see_bold(py, px));
441 * Determine if a given location may be "destroyed"
443 * Used by destruction spells, and for placing stairs, etc.
445 bool cave_valid_bold(int y, int x)
447 cave_type *c_ptr = &cave[y][x];
449 s16b this_o_idx, next_o_idx = 0;
452 /* Forbid perma-grids */
453 if (cave_perma_grid(c_ptr)) return (FALSE);
456 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
461 o_ptr = &o_list[this_o_idx];
463 /* Acquire next object */
464 next_o_idx = o_ptr->next_o_idx;
466 /* Forbid artifact grids */
467 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
478 * Determine if a given location may be "destroyed"
480 * Used by destruction spells, and for placing stairs, etc.
482 bool cave_valid_grid(cave_type *c_ptr)
484 s16b this_o_idx, next_o_idx = 0;
487 /* Forbid perma-grids */
488 if (cave_perma_grid(c_ptr)) return (FALSE);
491 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
496 o_ptr = &o_list[this_o_idx];
498 /* Acquire next object */
499 next_o_idx = o_ptr->next_o_idx;
501 /* Forbid artifact grids */
502 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
513 * Hack -- Legal monster codes
515 static cptr image_monster_hack = \
516 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
519 * Hack -- Legal monster codes for IBM pseudo-graphics
521 static cptr image_monster_hack_ibm = \
525 * Mega-Hack -- Hallucinatory monster
527 static void image_monster(byte *ap, char *cp)
529 int n = strlen(image_monster_hack);
531 /* Random symbol from set above */
534 /* Normal graphics */
535 if (!(streq(ANGBAND_SYS, "ibm")))
537 (*cp) = r_info[randint1(max_r_idx-1)].x_char;
538 (*ap) = r_info[randint1(max_r_idx-1)].x_attr;
541 /* IBM-pseudo graphics */
543 n = strlen(image_monster_hack_ibm);
544 (*cp) = (image_monster_hack_ibm[randint0(n)]);
547 (*ap) = randint1(15);
553 (*cp) = (image_monster_hack[randint0(n)]);
556 (*ap) = randint1(15);
563 * Hack -- Legal object codes
565 static cptr image_object_hack = \
566 "?/|\\\"!$()_-=[]{},~";
568 static cptr image_object_hack_ibm = \
572 * Mega-Hack -- Hallucinatory object
574 static void image_object(byte *ap, char *cp)
576 int n = strlen(image_object_hack);
580 if (!(streq(ANGBAND_SYS, "ibm")))
582 (*cp) = k_info[randint1(max_k_idx-1)].x_char;
583 (*ap) = k_info[randint1(max_k_idx-1)].x_attr;
587 n = strlen(image_object_hack_ibm);
588 (*cp) = (image_object_hack_ibm[randint0(n)]);
591 (*ap) = randint1(15);
596 (*cp) = (image_object_hack[randint0(n)]);
599 (*ap) = randint1(15);
606 * Hack -- Random hallucination
608 static void image_random(byte *ap, char *cp)
610 /* Normally, assume monsters */
611 if (randint0(100) < 75)
613 image_monster(ap, cp);
616 /* Otherwise, assume objects */
619 image_object(ap, cp);
624 * Not using graphical tiles for this feature?
626 #define is_ascii_graphics(C , A) \
627 (!(((C) & 0x80) && ((A) & 0x80)))
630 * The 16x16 tile of the terrain supports lighting
632 static bool feat_supports_lighting(byte feat)
634 if (is_trap(feat)) return TRUE;
653 case FEAT_WALL_EXTRA:
654 case FEAT_WALL_INNER:
655 case FEAT_WALL_OUTER:
656 case FEAT_WALL_SOLID:
657 case FEAT_PERM_EXTRA:
658 case FEAT_PERM_INNER:
659 case FEAT_PERM_OUTER:
660 case FEAT_PERM_SOLID:
661 case FEAT_MINOR_GLYPH:
662 case FEAT_DEEP_WATER:
663 case FEAT_SHAL_WATER:
670 case FEAT_DEEP_GRASS:
681 * This array lists the effects of "brightness" on various "base" colours.
683 * This is used to do dynamic lighting effects in ascii :-)
684 * At the moment, only the various "floor" tiles are affected.
686 * The layout of the array is [x][0] = light and [x][1] = dark.
689 static byte lighting_colours[16][2] =
692 {TERM_L_DARK, TERM_DARK},
695 {TERM_YELLOW, TERM_SLATE},
698 {TERM_WHITE, TERM_L_DARK},
701 {TERM_YELLOW, TERM_UMBER},
704 {TERM_RED, TERM_RED},
707 {TERM_L_GREEN, TERM_GREEN},
710 {TERM_BLUE, TERM_BLUE},
713 {TERM_L_UMBER, TERM_RED},
716 {TERM_SLATE, TERM_L_DARK},
719 {TERM_WHITE, TERM_SLATE},
722 {TERM_L_RED, TERM_BLUE},
725 {TERM_YELLOW, TERM_ORANGE},
728 {TERM_L_RED, TERM_L_RED},
731 {TERM_L_GREEN, TERM_GREEN},
734 {TERM_L_BLUE, TERM_L_BLUE},
737 {TERM_YELLOW, TERM_UMBER}
741 * Extract the attr/char to display at the given (legal) map location
743 * Basically, we "paint" the chosen attr/char in several passes, starting
744 * with any known "terrain features" (defaulting to darkness), then adding
745 * any known "objects", and finally, adding any known "monsters". This
746 * is not the fastest method but since most of the calls to this function
747 * are made for grids with no monsters or objects, it is fast enough.
749 * Note that this function, if used on the grid containing the "player",
750 * will return the attr/char of the grid underneath the player, and not
751 * the actual player attr/char itself, allowing a lot of optimization
752 * in various "display" functions.
754 * Note that the "zero" entry in the feature/object/monster arrays are
755 * used to provide "special" attr/char codes, with "monster zero" being
756 * used for the player attr/char, "object zero" being used for the "stack"
757 * attr/char, and "feature zero" being used for the "nothing" attr/char,
758 * though this function makes use of only "feature zero".
760 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
761 * which means their color changes, and "ATTR_CLEAR", which means they take
762 * the color of whatever is under them, and "CHAR_CLEAR", which means that
763 * they take the symbol of whatever is under them. Technically, the flag
764 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
765 * examined, but this flag is currently ignored.
767 * Currently, we do nothing with multi-hued objects, because there are
768 * not any. If there were, they would have to set "shimmer_objects"
769 * when they were created, and then new "shimmer" code in "dungeon.c"
770 * would have to be created handle the "shimmer" effect, and the code
771 * in "cave.c" would have to be updated to create the shimmer effect.
773 * Note the effects of hallucination. Objects always appear as random
774 * "objects", monsters as random "monsters", and normal grids occasionally
775 * appear as random "monsters" or "objects", but note that these random
776 * "monsters" and "objects" are really just "colored ascii symbols".
778 * Note that "floors" and "invisible traps" (and "zero" features) are
779 * drawn as "floors" using a special check for optimization purposes,
780 * and these are the only features which get drawn using the special
781 * lighting effects activated by "view_special_lite".
783 * Note the use of the "mimic" field in the "terrain feature" processing,
784 * which allows any feature to "pretend" to be another feature. This is
785 * used to "hide" secret doors, and to make all "doors" appear the same,
786 * and all "walls" appear the same, and "hidden" treasure stay hidden.
787 * It is possible to use this field to make a feature "look" like a floor,
788 * but the "special lighting effects" for floors will not be used.
790 * Note the use of the new "terrain feature" information. Note that the
791 * assumption that all interesting "objects" and "terrain features" are
792 * memorized allows extremely optimized processing below. Note the use
793 * of separate flags on objects to mark them as memorized allows a grid
794 * to have memorized "terrain" without granting knowledge of any object
795 * which may appear in that grid.
797 * Note the efficient code used to determine if a "floor" grid is
798 * "memorized" or "viewable" by the player, where the test for the
799 * grid being "viewable" is based on the facts that (1) the grid
800 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
801 * line of sight, and (3) the player must not be blind, and uses the
802 * assumption that all torch-lit grids are in line of sight.
804 * Note that floors (and invisible traps) are the only grids which are
805 * not memorized when seen, so only these grids need to check to see if
806 * the grid is "viewable" to the player (if it is not memorized). Since
807 * most non-memorized grids are in fact walls, this induces *massive*
808 * efficiency, at the cost of *forcing* the memorization of non-floor
809 * grids when they are first seen. Note that "invisible traps" are
810 * always treated exactly like "floors", which prevents "cheating".
812 * Note the "special lighting effects" which can be activated for floor
813 * grids using the "view_special_lite" option (for "white" floor grids),
814 * causing certain grids to be displayed using special colors. If the
815 * player is "blind", we will use "dark gray", else if the grid is lit
816 * by the torch, and the "view_yellow_lite" option is set, we will use
817 * "yellow", else if the grid is "dark", we will use "dark gray", else
818 * if the grid is not "viewable", and the "view_bright_lite" option is
819 * set, and the we will use "slate" (gray). We will use "white" for all
820 * other cases, in particular, for illuminated viewable floor grids.
822 * Note the "special lighting effects" which can be activated for wall
823 * grids using the "view_granite_lite" option (for "white" wall grids),
824 * causing certain grids to be displayed using special colors. If the
825 * player is "blind", we will use "dark gray", else if the grid is lit
826 * by the torch, and the "view_yellow_lite" option is set, we will use
827 * "yellow", else if the "view_bright_lite" option is set, and the grid
828 * is not "viewable", or is "dark", or is glowing, but not when viewed
829 * from the player's current location, we will use "slate" (gray). We
830 * will use "white" for all other cases, in particular, for correctly
831 * illuminated viewable wall grids.
833 * Note that, when "view_granite_lite" is set, we use an inline version
834 * of the "player_can_see_bold()" function to check the "viewability" of
835 * grids when the "view_bright_lite" option is set, and we do NOT use
836 * any special colors for "dark" wall grids, since this would allow the
837 * player to notice the walls of illuminated rooms from a hallway that
838 * happened to run beside the room. The alternative, by the way, would
839 * be to prevent the generation of hallways next to rooms, but this
840 * would still allow problems when digging towards a room.
842 * Note that bizarre things must be done when the "attr" and/or "char"
843 * codes have the "high-bit" set, since these values are used to encode
844 * various "special" pictures in some versions, and certain situations,
845 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
846 * to be "scrambled" in various ways.
848 * Note that eventually we may use the "&" symbol for embedded treasure,
849 * and use the "*" symbol to indicate multiple objects, though this will
850 * have to wait for Angband 2.8.0 or later. Note that currently, this
851 * is not important, since only one object or terrain feature is allowed
852 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
854 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
855 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
856 * then a whole lot of code should be changed... XXX XXX
858 #ifdef USE_TRANSPARENCY
859 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
860 #else /* USE_TRANSPARENCY */
861 void map_info(int y, int x, byte *ap, char *cp)
862 #endif /* USE_TRANSPARENCY */
868 s16b this_o_idx, next_o_idx = 0;
882 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
884 /* Memorized (or visible) floor */
885 if ((c_ptr->info & CAVE_MARK) ||
886 (((c_ptr->info & CAVE_LITE) || (c_ptr->info & CAVE_MNLT) ||
887 ((c_ptr->info & CAVE_GLOW) &&
888 (c_ptr->info & CAVE_VIEW))) &&
892 f_ptr = &f_info[feat];
900 /* Special lighting effects */
901 if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_graphics))
906 if (new_ascii_graphics)
908 if (is_ascii_graphics(c,a))
910 /* Use darkened colour */
911 a = lighting_colours[a][1];
913 else if (use_graphics && feat_supports_lighting(feat))
915 /* Use a dark tile */
923 /* Use a dark tile */
928 /* Use "dark gray" */
934 /* Handle "torch-lit" grids */
935 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
938 if (view_yellow_lite && !p_ptr->wild_mode)
940 if (new_ascii_graphics)
942 if (is_ascii_graphics(c,a))
944 /* Use lightened colour */
945 a = lighting_colours[a][0];
947 else if (use_graphics &&
948 feat_supports_lighting(feat))
950 /* Use a brightly lit tile */
957 if (view_yellow_lite)
961 /* Use a brightly lit tile */
974 /* Handle "dark" grids */
975 else if (!(c_ptr->info & CAVE_GLOW))
977 if (new_ascii_graphics)
979 if (is_ascii_graphics(c,a))
981 /* Use darkened colour */
982 a = lighting_colours[a][1];
984 else if (use_graphics && feat_supports_lighting(feat))
986 /* Use a dark tile */
994 /* Use a dark tile */
999 /* Use "dark gray" */
1005 /* Handle "out-of-sight" grids */
1006 else if (!(c_ptr->info & CAVE_VIEW))
1009 if (view_bright_lite && !p_ptr->wild_mode)
1011 if (new_ascii_graphics)
1013 if (is_ascii_graphics(c,a))
1015 /* Use darkened colour */
1016 a = lighting_colours[a][1];
1018 else if (use_graphics && feat_supports_lighting(feat))
1020 /* Use a dark tile */
1028 /* Use a dark tile */
1047 /* Access darkness */
1048 f_ptr = &f_info[feat];
1061 /* Memorized grids */
1062 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || !new_ascii_graphics))
1064 /* Apply "mimic" field */
1066 feat = c_ptr->mimic;
1068 feat = f_info[feat].mimic;
1070 /* Access feature */
1071 f_ptr = &f_info[feat];
1079 if (new_ascii_graphics)
1081 /* Handle "blind" */
1084 if (is_ascii_graphics(c,a))
1086 /* Use darkened colour */
1087 a = lighting_colours[a][1];
1089 else if (use_graphics && feat_supports_lighting(feat))
1091 /* Use a dark tile */
1096 /* Handle "torch-lit" grids */
1097 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1100 if (view_yellow_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1102 if (is_ascii_graphics(c,a))
1104 /* Use lightened colour */
1105 a = lighting_colours[a][0];
1107 else if (use_graphics &&
1108 feat_supports_lighting(c_ptr->feat))
1110 /* Use a brightly lit tile */
1116 /* Handle "view_bright_lite" */
1117 else if (view_bright_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1120 if (!(c_ptr->info & CAVE_VIEW))
1122 if (is_ascii_graphics(c,a))
1124 /* Use darkened colour */
1125 a = lighting_colours[a][1];
1127 else if (use_graphics && feat_supports_lighting(feat))
1129 /* Use a dark tile */
1135 else if (!(c_ptr->info & CAVE_GLOW))
1137 if (is_ascii_graphics(c,a))
1139 /* Use darkened colour */
1140 a = lighting_colours[a][1];
1145 /* Special lighting effects */
1146 else if (view_granite_lite && !p_ptr->wild_mode &&
1147 (((a == TERM_WHITE) && !use_graphics) ||
1148 (use_graphics && feat_supports_lighting(c_ptr->feat))))
1150 /* Handle "blind" */
1155 /* Use a dark tile */
1160 /* Use "dark gray" */
1165 /* Handle "torch-lit" grids */
1166 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1169 if (view_yellow_lite && !p_ptr->wild_mode)
1173 /* Use a brightly lit tile */
1184 /* Handle "view_bright_lite" */
1185 else if (view_bright_lite && !p_ptr->wild_mode)
1188 if (!(c_ptr->info & CAVE_VIEW))
1192 /* Use a dark tile */
1203 else if (!(c_ptr->info & CAVE_GLOW))
1207 /* Use a lit tile */
1216 /* Not glowing correctly */
1221 /* Hack -- move towards player */
1222 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1223 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1225 /* Check for "local" illumination */
1226 if (!(cave[yy][xx].info & CAVE_GLOW))
1230 /* Use a lit tile */
1243 /* "Simple Lighting" */
1246 /* Handle "blind" */
1247 if (!(c_ptr->info & CAVE_MARK))
1252 /* Access feature */
1253 f_ptr = &f_info[feat];
1263 if (feat_priority == -1)
1274 case FEAT_TRAP_TRAPDOOR:
1276 case FEAT_TRAP_SPIKED_PIT:
1277 case FEAT_TRAP_POISON_PIT:
1278 case FEAT_TRAP_TY_CURSE:
1279 case FEAT_TRAP_TELEPORT:
1280 case FEAT_TRAP_FIRE:
1281 case FEAT_TRAP_ACID:
1282 case FEAT_TRAP_SLOW:
1283 case FEAT_TRAP_LOSE_STR:
1284 case FEAT_TRAP_LOSE_DEX:
1285 case FEAT_TRAP_LOSE_CON:
1286 case FEAT_TRAP_BLIND:
1287 case FEAT_TRAP_CONFUSE:
1288 case FEAT_TRAP_POISON:
1289 case FEAT_TRAP_SLEEP:
1290 case FEAT_TRAP_TRAPS:
1294 case FEAT_DEEP_GRASS:
1303 case FEAT_WALL_EXTRA:
1304 case FEAT_WALL_INNER:
1305 case FEAT_WALL_OUTER:
1306 case FEAT_WALL_SOLID:
1307 case FEAT_DEEP_WATER:
1308 case FEAT_SHAL_WATER:
1309 case FEAT_DEEP_LAVA:
1310 case FEAT_SHAL_LAVA:
1320 case FEAT_PERM_EXTRA:
1321 case FEAT_PERM_INNER:
1322 case FEAT_PERM_OUTER:
1323 case FEAT_PERM_SOLID:
1327 /* default is feat_priority = 20; (doors and stores) */
1330 case FEAT_MINOR_GLYPH:
1332 case FEAT_PATTERN_START:
1333 case FEAT_PATTERN_1:
1334 case FEAT_PATTERN_2:
1335 case FEAT_PATTERN_3:
1336 case FEAT_PATTERN_4:
1337 case FEAT_PATTERN_END:
1338 case FEAT_PATTERN_OLD:
1339 case FEAT_PATTERN_XTRA1:
1340 case FEAT_PATTERN_XTRA2:
1344 /* objects have feat_priority = 20 */
1345 /* monsters have feat_priority = 30 */
1349 case FEAT_QUEST_ENTER:
1350 case FEAT_QUEST_EXIT:
1351 case FEAT_QUEST_DOWN:
1353 case FEAT_LESS_LESS:
1354 case FEAT_MORE_MORE:
1366 /* Hack -- rare random hallucination, except on outer dungeon walls */
1367 if (p_ptr->image && (c_ptr->feat < FEAT_PERM_SOLID) && !randint0(256))
1370 image_random(ap, cp);
1373 #ifdef USE_TRANSPARENCY
1374 /* Save the terrain info for the transparency effects */
1377 #endif /* USE_TRANSPARENCY */
1384 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1388 /* Acquire object */
1389 o_ptr = &o_list[this_o_idx];
1391 /* Acquire next object */
1392 next_o_idx = o_ptr->next_o_idx;
1394 /* Memorized objects */
1397 if (display_autopick)
1401 match_autopick = is_autopick(o_ptr);
1402 if(match_autopick == -1)
1405 act = autopick_action[match_autopick];
1407 if ((act & DO_DISPLAY) && (act & display_autopick))
1409 autopick_obj = o_ptr;
1413 match_autopick = -1;
1418 (*cp) = object_char(o_ptr);
1421 (*ap) = object_attr(o_ptr);
1425 /* Hack -- hallucination */
1426 if (p_ptr->image) image_object(ap, cp);
1434 /* Handle monsters */
1435 if (c_ptr->m_idx && display_autopick == 0 )
1437 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1439 /* Visible monster */
1442 monster_race *r_ptr;
1443 if (m_ptr->mflag2 & MFLAG_KAGE) r_ptr = &r_info[MON_KAGE];
1444 else r_ptr = &r_info[m_ptr->r_idx];
1454 /* Mimics' colors vary */
1455 if (strchr("\"!=", c) && !(r_ptr->flags1 & RF1_UNIQUE))
1460 /* Use semi-random attr */
1461 (*ap) = c_ptr->m_idx % 15 + 1;
1464 /* Special attr/char codes */
1465 else if ((a & 0x80) && (c & 0x80))
1474 /* Multi-hued monster */
1475 else if (r_ptr->flags1 & (RF1_ATTR_MULTI))
1477 /* Is it a shapechanger? */
1478 if (r_ptr->flags2 & (RF2_SHAPECHANGER))
1482 if (!(streq(ANGBAND_SYS, "ibm")))
1484 (*cp) = r_info[randint1(max_r_idx-1)].x_char;
1485 (*ap) = r_info[randint1(max_r_idx-1)].x_attr;
1489 int n = strlen(image_monster_hack_ibm);
1490 (*cp) = (image_monster_hack_ibm[randint0(n)]);
1493 (*ap) = randint1(15);
1498 (*cp) = (one_in_(25) ?
1499 image_object_hack[randint0(strlen(image_object_hack))] :
1500 image_monster_hack[randint0(strlen(image_monster_hack))]);
1506 /* Multi-hued attr */
1507 if (r_ptr->flags2 & RF2_ATTR_ANY)
1508 (*ap) = randint1(15);
1509 else switch (randint1(7))
1521 (*ap) = TERM_L_GREEN;
1527 (*ap) = TERM_L_DARK;
1535 /* Normal monster (not "clear" in any way) */
1536 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR | RF1_CHAR_CLEAR)))
1545 /* Hack -- Bizarre grid under monster */
1546 else if ((*ap & 0x80) || (*cp & 0x80))
1558 /* Normal (non-clear char) monster */
1559 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR)))
1565 /* Normal (non-clear attr) monster */
1566 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR)))
1573 /* Hack -- hallucination */
1576 /* Hallucinatory monster */
1577 image_monster(ap, cp);
1582 /* Handle "player" */
1583 if ((y == py) && (x == px))
1585 monster_race *r_ptr = &r_info[0];
1589 /* Get the "player" attr */
1592 /* Get the "player" char */
1595 #ifdef VARIABLE_PLAYER_GRAPH
1597 if (!streq(ANGBAND_GRAF, "new"))
1599 if (streq(ANGBAND_SYS,"ibm"))
1601 if (use_graphics && player_symbols)
1603 if (p_ptr->psex == SEX_FEMALE) c = (char)242;
1604 switch (p_ptr->pclass)
1607 if (p_ptr->lev < 20)
1613 case CLASS_WARRIOR_MAGE:
1614 case CLASS_RED_MAGE:
1615 if (p_ptr->lev < 20)
1620 case CLASS_CHAOS_WARRIOR:
1625 while (a == TERM_DARK);
1628 case CLASS_HIGH_MAGE:
1629 case CLASS_SORCERER:
1630 case CLASS_MAGIC_EATER:
1631 case CLASS_BLUE_MAGE:
1632 if (p_ptr->lev < 20)
1640 if (p_ptr->lev < 20)
1648 if (p_ptr->lev < 20)
1655 if (p_ptr->lev < 20)
1662 case CLASS_BERSERKER:
1664 if (p_ptr->lev < 20)
1670 case CLASS_MINDCRAFTER:
1671 case CLASS_FORCETRAINER:
1672 case CLASS_MIRROR_MASTER:
1673 if (p_ptr->lev < 20)
1679 default: /* Unknown */
1683 switch (p_ptr->prace)
1695 case RACE_HALF_TROLL:
1705 case RACE_HALF_OGRE:
1708 case RACE_HALF_GIANT:
1709 case RACE_HALF_TITAN:
1728 case RACE_DRACONIAN:
1729 if (p_ptr->lev < 20)
1731 else if (p_ptr->lev < 40)
1736 case RACE_MIND_FLAYER:
1747 if (p_ptr->pclass == CLASS_MAGE ||
1748 p_ptr->pclass == CLASS_PRIEST ||
1749 p_ptr->pclass == CLASS_HIGH_MAGE ||
1750 p_ptr->pclass == CLASS_SORCERER ||
1751 p_ptr->pclass == CLASS_MONK ||
1752 p_ptr->pclass == CLASS_FORCETRAINER ||
1753 p_ptr->pclass == CLASS_BLUE_MAGE ||
1754 p_ptr->pclass == CLASS_MIRROR_MASTER ||
1755 p_ptr->pclass == CLASS_MINDCRAFTER)
1789 #endif /* VARIABLE_PLAYER_GRAPH */
1797 * Moves the cursor to a given MAP (y,x) location
1799 void move_cursor_relative(int row, int col)
1801 /* Real co-ords convert to screen positions */
1802 row -= panel_row_prt;
1803 col -= panel_col_prt;
1806 Term_gotoxy(col, row);
1812 * Place an attr/char pair at the given map coordinate, if legal.
1814 void print_rel(char c, byte a, int y, int x)
1816 /* Only do "legal" locations */
1817 if (panel_contains(y, x))
1819 /* Hack -- fake monochrome */
1820 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
1822 if (world_monster) a = TERM_DARK;
1823 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
1824 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
1825 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1828 /* Draw the char using the attr */
1829 Term_draw(x-panel_col_prt, y-panel_row_prt, a, c);
1838 * Memorize interesting viewable object/features in the given grid
1840 * This function should only be called on "legal" grids.
1842 * This function will memorize the object and/or feature in the given
1843 * grid, if they are (1) viewable and (2) interesting. Note that all
1844 * objects are interesting, all terrain features except floors (and
1845 * invisible traps) are interesting, and floors (and invisible traps)
1846 * are interesting sometimes (depending on various options involving
1847 * the illumination of floor grids).
1849 * The automatic memorization of all objects and non-floor terrain
1850 * features as soon as they are displayed allows incredible amounts
1851 * of optimization in various places, especially "map_info()".
1853 * Note that the memorization of objects is completely separate from
1854 * the memorization of terrain features, preventing annoying floor
1855 * memorization when a detected object is picked up from a dark floor,
1856 * and object memorization when an object is dropped into a floor grid
1857 * which is memorized but out-of-sight.
1859 * This function should be called every time the "memorization" of
1860 * a grid (or the object in a grid) is called into question, such
1861 * as when an object is created in a grid, when a terrain feature
1862 * "changes" from "floor" to "non-floor", when any grid becomes
1863 * "illuminated" or "viewable", and when a "floor" grid becomes
1866 * Note the relatively efficient use of this function by the various
1867 * "update_view()" and "update_lite()" calls, to allow objects and
1868 * terrain features to be memorized (and drawn) whenever they become
1869 * viewable or illuminated in any way, but not when they "maintain"
1870 * or "lose" their previous viewability or illumination.
1872 * Note the butchered "internal" version of "player_can_see_bold()",
1873 * optimized primarily for the most common cases, that is, for the
1874 * non-marked floor grids.
1876 void note_spot(int y, int x)
1878 cave_type *c_ptr = &cave[y][x];
1880 s16b this_o_idx, next_o_idx = 0;
1883 /* Blind players see nothing */
1884 if (p_ptr->blind) return;
1886 /* Analyze non-torch-lit grids */
1887 if (!(c_ptr->info & (CAVE_LITE)))
1889 /* Require line of sight to the grid */
1890 if (!(c_ptr->info & (CAVE_VIEW))) return;
1892 if (p_ptr->pclass != CLASS_NINJA)
1894 /* Require "perma-lite" of the grid */
1895 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return;
1900 /* Hack -- memorize objects */
1901 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1903 object_type *o_ptr = &o_list[this_o_idx];
1905 /* Acquire next object */
1906 next_o_idx = o_ptr->next_o_idx;
1908 /* Memorize objects */
1909 o_ptr->marked = TRUE;
1913 /* Hack -- memorize grids */
1914 if (!(c_ptr->info & (CAVE_MARK)))
1916 if (p_ptr->pclass == CLASS_NINJA)
1918 c_ptr->info |= (CAVE_MARK);
1920 /* Handle floor grids first */
1921 if ((c_ptr->feat <= FEAT_INVIS) || (c_ptr->feat == FEAT_DIRT) || (c_ptr->feat == FEAT_GRASS))
1923 /* Option -- memorize all torch-lit floors */
1924 if (view_torch_grids && (c_ptr->info & (CAVE_LITE)))
1927 c_ptr->info |= (CAVE_MARK);
1930 /* Option -- memorize all perma-lit floors */
1931 else if (view_perma_grids && (c_ptr->info & (CAVE_GLOW)))
1934 c_ptr->info |= (CAVE_MARK);
1938 /* Memorize normal grids */
1939 else if (cave_floor_grid(c_ptr))
1942 c_ptr->info |= (CAVE_MARK);
1945 /* Memorize torch-lit walls */
1946 else if (c_ptr->info & (CAVE_LITE))
1949 c_ptr->info |= (CAVE_MARK);
1952 /* Memorize certain non-torch-lit wall grids */
1957 /* Hack -- move one grid towards player */
1958 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1959 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1961 /* Check for "local" illumination */
1962 if (cave[yy][xx].info & (CAVE_GLOW))
1965 c_ptr->info |= (CAVE_MARK);
1972 void display_dungeon(void)
1978 #ifdef USE_TRANSPARENCY
1981 #endif /* USE_TRANSPARENCY */
1983 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1985 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1987 if (in_bounds2(y, x))
1990 #ifdef USE_TRANSPARENCY
1991 /* Examine the grid */
1992 map_info(y, x, &a, &c, &ta, &tc);
1993 #else /* USE_TRANSPARENCY */
1994 /* Examine the grid */
1995 map_info(y, x, &a, &c);
1996 #endif /* USE_TRANSPARENCY */
1998 /* Hack -- fake monochrome */
1999 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2001 if (world_monster) a = TERM_DARK;
2002 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2003 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2004 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2007 #ifdef USE_TRANSPARENCY
2008 /* Hack -- Queue it */
2009 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2010 #else /* USE_TRANSPARENCY */
2011 /* Hack -- Queue it */
2012 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2013 #endif /* USE_TRANSPARENCY */
2018 /* Clear out-of-bound tiles */
2020 /* Access darkness */
2021 feature_type *f_ptr = &f_info[FEAT_NONE];
2029 #ifdef USE_TRANSPARENCY
2030 /* Hack -- Queue it */
2031 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2032 #else /* USE_TRANSPARENCY */
2033 /* Hack -- Queue it */
2034 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2035 #endif /* USE_TRANSPARENCY */
2043 * Redraw (on the screen) a given MAP location
2045 * This function should only be called on "legal" grids
2047 void lite_spot(int y, int x)
2049 /* Redraw if on screen */
2050 if (panel_contains(y, x))
2055 #ifdef USE_TRANSPARENCY
2059 /* Examine the grid */
2060 map_info(y, x, &a, &c, &ta, &tc);
2061 #else /* USE_TRANSPARENCY */
2062 /* Examine the grid */
2063 map_info(y, x, &a, &c);
2064 #endif /* USE_TRANSPARENCY */
2066 /* Hack -- fake monochrome */
2067 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2069 if (world_monster) a = TERM_DARK;
2070 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2071 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2072 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2075 #ifdef USE_TRANSPARENCY
2076 /* Hack -- Queue it */
2077 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c, ta, tc);
2078 #else /* USE_TRANSPARENCY */
2079 /* Hack -- Queue it */
2080 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c);
2081 #endif /* USE_TRANSPARENCY */
2087 * Prints the map of the dungeon
2089 * Note that, for efficiency, we contain an "optimized" version
2090 * of both "lite_spot()" and "print_rel()", and that we use the
2091 * "lite_spot()" function to display the player grid, if needed.
2097 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2100 /* Access the cursor state */
2101 (void)Term_get_cursor(&v);
2103 /* Hide the cursor */
2104 (void)Term_set_cursor(0);
2107 for (y = panel_row_min; y <= panel_row_max; y++)
2109 /* Scan the columns of row "y" */
2110 for (x = panel_col_min; x <= panel_col_max; x++)
2115 #ifdef USE_TRANSPARENCY
2119 /* Determine what is there */
2120 map_info(y, x, &a, &c, &ta, &tc);
2122 /* Hack -- fake monochrome */
2123 if (fake_monochrome)
2125 if (world_monster) a = TERM_DARK;
2126 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2127 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2128 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2131 /* Efficiency -- Redraw that grid of the map */
2132 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c, ta, tc);
2133 #else /* USE_TRANSPARENCY */
2134 /* Determine what is there */
2135 map_info(y, x, &a, &c);
2137 /* Hack -- fake monochrome */
2138 if (fake_monochrome)
2140 if (world_monster) a = TERM_DARK;
2141 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2142 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2143 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2146 /* Efficiency -- Redraw that grid of the map */
2147 Term_queue_char(x-panel_col_prt, y-panel_row_prt, a, c);
2148 #endif /* USE_TRANSPARENCY */
2152 /* Display player */
2155 /* Restore the cursor */
2156 (void)Term_set_cursor(v);
2162 * print project path
2164 void prt_path(int y, int x)
2169 int default_color = TERM_SLATE;
2170 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2172 if (!display_path) return;
2173 if (-1 == project_length)
2176 /* Get projection path */
2177 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2180 p_ptr->redraw |= (PR_MAP);
2186 for (i = 0; i < path_n; i++)
2188 int ny = GRID_Y(path_g[i]);
2189 int nx = GRID_X(path_g[i]);
2191 if (panel_contains(ny, nx))
2193 byte a = default_color;
2196 #ifdef USE_TRANSPARENCY
2200 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2202 /* Determine what is there */
2203 map_info(ny, nx, &a, &c, &ta, &tc);
2205 if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2207 else if (a == default_color)
2211 if (fake_monochrome)
2213 if (world_monster) a = TERM_DARK;
2214 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2215 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2216 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2220 /* Hack -- Queue it */
2221 Term_queue_char(nx-panel_col_prt, ny-panel_row_prt, a, '*', ta, tc);
2222 #else /* USE_TRANSPARENCY */
2224 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2226 /* Determine what is there */
2227 map_info(ny, nx, &a, &c);
2229 if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2231 else if (a == default_color)
2235 if (fake_monochrome)
2237 if (world_monster) a = TERM_DARK;
2238 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2239 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2240 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2243 /* Hack -- Queue it */
2244 Term_queue_char(nx-panel_col_prt, ny-panel_row_prt, a, '*');
2245 #endif /* USE_TRANSPARENCY */
2249 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2252 if (nx == x && ny == y) default_color = TERM_L_DARK;
2257 static cptr simplify_list[][2] =
2264 {"^Amulet of ", "\""},
2265 {"^Scroll of ", "?"},
2266 {"^Scroll titled ", "?"},
2267 {"^Wand of " , "-"},
2269 {"^Staff of " , "_"},
2270 {"^Potion of ", "!"},
2282 static void display_shortened_item_name(object_type *o_ptr, int y)
2289 object_desc(buf, o_ptr, FALSE, 0);
2290 attr = tval_to_attr[o_ptr->tval % 128];
2296 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
2298 strcpy(buf, "something strange");
2302 for (c = buf; *c; c++)
2305 for (i = 0; simplify_list[i][1]; i++)
2307 cptr org_w = simplify_list[i][0];
2317 if (!strncmp(c, org_w, strlen(org_w)))
2320 cptr tmp = simplify_list[i][1];
2323 tmp = c + strlen(org_w);
2333 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2339 if(len + 2 > 12) break;
2346 if(len + 1 > 12) break;
2352 Term_putstr(0, y, 12, attr, buf);
2356 * Display a "small-scale" map of the dungeon in the active Term
2358 void display_map(int *cy, int *cx)
2367 byte bigma[MAX_HGT+2][MAX_WID+2];
2368 char bigmc[MAX_HGT+2][MAX_WID+2];
2369 byte bigmp[MAX_HGT+2][MAX_WID+2];
2371 byte ma[SCREEN_HGT + 2][SCREEN_WID + 2];
2372 char mc[SCREEN_HGT + 2][SCREEN_WID + 2];
2374 byte mp[SCREEN_HGT + 2][SCREEN_WID + 2];
2376 bool old_view_special_lite;
2377 bool old_view_granite_lite;
2379 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2381 int yrat = cur_hgt / SCREEN_HGT;
2382 int xrat = cur_wid / SCREEN_WID;
2385 int match_autopick_yx[SCREEN_HGT+2][SCREEN_WID+2];
2386 object_type *object_autopick_yx[SCREEN_HGT+2][SCREEN_WID+2];
2388 /* Save lighting effects */
2389 old_view_special_lite = view_special_lite;
2390 old_view_granite_lite = view_granite_lite;
2392 /* Disable lighting effects */
2393 view_special_lite = FALSE;
2394 view_granite_lite = FALSE;
2396 /* Clear the chars and attributes */
2397 for (y = 0; y < SCREEN_HGT + 2; ++y)
2399 for (x = 0; x < SCREEN_WID + 2; ++x)
2401 match_autopick_yx[y][x] = -1;
2402 object_autopick_yx[y][x] = NULL;
2405 ma[y][x] = TERM_WHITE;
2413 for (j = 0; j < cur_hgt + 2; ++j)
2415 for (i = 0; i < cur_wid + 2; ++i)
2418 bigma[j][i] = TERM_WHITE;
2426 /* Fill in the map */
2427 for (i = 0; i < cur_wid; ++i)
2429 for (j = 0; j < cur_hgt; ++j)
2439 /* Extract the current attr/char at that map location */
2440 #ifdef USE_TRANSPARENCY
2441 map_info(j, i, &ta, &tc, &ta, &tc);
2442 #else /* USE_TRANSPARENCY */
2443 map_info(j, i, &ta, &tc);
2444 #endif /* USE_TRANSPARENCY */
2446 /* Extract the priority */
2449 if(match_autopick!=-1
2450 && (match_autopick_yx[y][x] == -1
2451 || match_autopick_yx[y][x] > match_autopick))
2453 match_autopick_yx[y][x] = match_autopick;
2454 object_autopick_yx[y][x] = autopick_obj;
2458 /* Save the char, attr and priority */
2459 bigmc[j+1][i+1] = tc;
2460 bigma[j+1][i+1] = ta;
2461 bigmp[j+1][i+1] = tp;
2465 for (j = 0; j < cur_hgt; ++j)
2467 for (i = 0; i < cur_wid; ++i)
2473 tc = bigmc[j+1][i+1];
2474 ta = bigma[j+1][i+1];
2475 tp = bigmp[j+1][i+1];
2477 /* rare feature has more priority */
2483 for (t = 0; t < 8; t++)
2485 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2486 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2496 /* Save the char, attr and priority */
2509 /* Draw the corners */
2510 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2512 /* Draw the horizontal edges */
2513 for (x = 1; x <= SCREEN_WID; x++) mc[0][x] = mc[y][x] = '-';
2515 /* Draw the vertical edges */
2516 for (y = 1; y <= SCREEN_HGT; y++) mc[y][0] = mc[y][x] = '|';
2519 /* Display each map line in order */
2520 for (y = 0; y < SCREEN_HGT+2; ++y)
2522 /* Start a new line */
2523 Term_gotoxy(COL_MAP, y);
2525 /* Display the line */
2526 for (x = 0; x < SCREEN_WID+2; ++x)
2531 /* Hack -- fake monochrome */
2532 if (fake_monochrome)
2534 if (world_monster) ta = TERM_DARK;
2535 else if (p_ptr->invuln || world_player) ta = TERM_WHITE;
2536 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) ta = TERM_WHITE;
2537 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2540 /* Add the character */
2546 for (y = 1; y < SCREEN_HGT+1; ++y)
2548 match_autopick = -1;
2549 for (x = 1; x <= SCREEN_WID; x++){
2550 if (match_autopick_yx[y][x] != -1 &&
2551 (match_autopick > match_autopick_yx[y][x] ||
2552 match_autopick == -1)){
2553 match_autopick = match_autopick_yx[y][x];
2554 autopick_obj = object_autopick_yx[y][x];
2558 /* Clear old display */
2559 Term_putstr(0, y, 12, 0, " ");
2561 if (match_autopick != -1)
2563 display_shortened_item_name(autopick_obj, y);
2566 char buf[13] = "\0";
2567 strncpy(buf,autopick_name[match_autopick],12);
2575 /* Player location */
2576 (*cy) = py / yrat + 1 + ROW_MAP;
2577 (*cx) = px / xrat + 1 + COL_MAP;
2580 /* Restore lighting effects */
2581 view_special_lite = old_view_special_lite;
2582 view_granite_lite = old_view_granite_lite;
2587 * Display a "small-scale" map of the dungeon for the player
2589 * Currently, the "player" is displayed on the map. XXX XXX XXX
2591 void do_cmd_view_map(void)
2596 /* Save the screen */
2601 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2603 prt("Please wait...", 0, 0);
2609 /* Clear the screen */
2612 display_autopick = 0;
2614 /* Display the map */
2615 display_map(&cy, &cx);
2618 if(max_autopick && !p_ptr->wild_mode)
2620 display_autopick = ITEM_DISPLAY;
2628 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", 23, 1);
2630 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", 23, 1);
2633 /* Hilite the player */
2634 move_cursor(cy, cx);
2641 flag = DONT_AUTOPICK;
2643 flag = DO_AUTODESTROY;
2645 flag = (DO_AUTOPICK | DONT_AUTOPICK);
2651 if (~display_autopick & flag)
2652 display_autopick |= flag;
2654 display_autopick &= ~flag;
2655 /* Display the map */
2656 display_map(&cy, &cx);
2659 display_autopick = 0;
2665 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2667 put_str("Hit any key to continue", 23, 30);
2668 #endif /* Hilite the player */
2669 move_cursor(cy, cx);
2674 /* Restore the screen */
2683 * Some comments on the cave grid flags. -BEN-
2686 * One of the major bottlenecks in previous versions of Angband was in
2687 * the calculation of "line of sight" from the player to various grids,
2688 * such as monsters. This was such a nasty bottleneck that a lot of
2689 * silly things were done to reduce the dependancy on "line of sight",
2690 * for example, you could not "see" any grids in a lit room until you
2691 * actually entered the room, and there were all kinds of bizarre grid
2692 * flags to enable this behavior. This is also why the "call light"
2693 * spells always lit an entire room.
2695 * The code below provides functions to calculate the "field of view"
2696 * for the player, which, once calculated, provides extremely fast
2697 * calculation of "line of sight from the player", and to calculate
2698 * the "field of torch lite", which, again, once calculated, provides
2699 * extremely fast calculation of "which grids are lit by the player's
2700 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2701 * "GRID_LITE", as appropriate, these functions maintain an array for
2702 * each of these two flags, each array containing the locations of all
2703 * of the grids marked with the appropriate flag, which can be used to
2704 * very quickly scan through all of the grids in a given set.
2706 * To allow more "semantically valid" field of view semantics, whenever
2707 * the field of view (or the set of torch lit grids) changes, all of the
2708 * grids in the field of view (or the set of torch lit grids) are "drawn"
2709 * so that changes in the world will become apparent as soon as possible.
2710 * This has been optimized so that only grids which actually "change" are
2711 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2712 * of the grids which are entering or leaving the relevent set of grids.
2714 * These new methods are so efficient that the old nasty code was removed.
2716 * Note that there is no reason to "update" the "viewable space" unless
2717 * the player "moves", or walls/doors are created/destroyed, and there
2718 * is no reason to "update" the "torch lit grids" unless the field of
2719 * view changes, or the "light radius" changes. This means that when
2720 * the player is resting, or digging, or doing anything that does not
2721 * involve movement or changing the state of the dungeon, there is no
2722 * need to update the "view" or the "lite" regions, which is nice.
2724 * Note that the calls to the nasty "los()" function have been reduced
2725 * to a bare minimum by the use of the new "field of view" calculations.
2727 * I wouldn't be surprised if slight modifications to the "update_view()"
2728 * function would allow us to determine "reverse line-of-sight" as well
2729 * as "normal line-of-sight", which would allow monsters to use a more
2730 * "correct" calculation to determine if they can "see" the player. For
2731 * now, monsters simply "cheat" somewhat and assume that if the player
2732 * has "line of sight" to the monster, then the monster can "pretend"
2733 * that it has "line of sight" to the player.
2736 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2737 * grid and maintains an array of all "CAVE_LITE" grids.
2739 * This set of grids is the complete set of all grids which are lit by
2740 * the players light source, which allows the "player_can_see_bold()"
2741 * function to work very quickly.
2743 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2744 * fact, the player (unless blind) can always "see" all grids which are
2745 * marked as "CAVE_LITE", unless they are "off screen".
2748 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2749 * grid and maintains an array of all "CAVE_VIEW" grids.
2751 * This set of grids is the complete set of all grids within line of sight
2752 * of the player, allowing the "player_has_los_bold()" macro to work very
2756 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2757 * temporary internal flag to mark those grids which are not only in view,
2758 * but which are also "easily" in line of sight of the player. This flag
2759 * is always cleared when we are done.
2762 * The current "update_lite()" and "update_view()" algorithms use the
2763 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2764 * to keep track of which grids were previously marked as "CAVE_LITE" or
2765 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2767 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2768 * for various other purposes, such as spreading lite or darkness during
2769 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2772 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2773 * in some way permanently lit. However, for the player to "see" anything
2774 * in the grid, as determined by "player_can_see()", the player must not be
2775 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2776 * grids, even if marked as "perma lit", are only illuminated if they touch
2777 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2780 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2781 * that even if the player cannot "see" the grid, he "knows" the terrain in
2782 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2783 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2784 * or when one of the "memorize floor grids" options induces memorization.
2786 * Objects are "memorized" in a different way, using a special "marked" flag
2787 * on the object itself, which is set when an object is observed or detected.
2790 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2791 * and should be illuminated by "lite room" and "darkness" spells.
2794 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2795 * and should be unavailable for "teleportation" destinations.
2798 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2799 * which is observed, and the "view_torch_grids" allows the player to memorize
2800 * every torch-lit grid. The player will always memorize important walls,
2801 * doors, stairs, and other terrain features, as well as any "detected" grids.
2803 * Note that the new "update_view()" method allows, among other things, a room
2804 * to be "partially" seen as the player approaches it, with a growing cone of
2805 * floor appearing as the player gets closer to the door. Also, by not turning
2806 * on the "memorize perma-lit grids" option, the player will only "see" those
2807 * floor grids which are actually in line of sight.
2809 * And my favorite "plus" is that you can now use a special option to draw the
2810 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2811 * grids dimly), providing a "pretty" effect as the player runs around, and
2812 * to efficiently display the "torch lite" in a special color.
2815 * Some comments on the "update_view()" algorithm...
2817 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2818 * and only has to call "los()" on the borderline cases. The major axes/diags
2819 * even terminate early when they hit walls. I need to find a quick way
2820 * to "terminate" the other scans.
2822 * Note that in the worst case (a big empty area with say 5% scattered walls),
2823 * each of the 1500 or so nearby grids is checked once, most of them getting
2824 * an "instant" rating, and only a small portion requiring a call to "los()".
2826 * The only time that the algorithm appears to be "noticeably" too slow is
2827 * when running, and this is usually only important in town, since the town
2828 * provides about the worst scenario possible, with large open regions and
2829 * a few scattered obstructions. There is a special "efficiency" option to
2830 * allow the player to reduce his field of view in town, if needed.
2832 * In the "best" case (say, a normal stretch of corridor), the algorithm
2833 * makes one check for each viewable grid, and makes no calls to "los()".
2834 * So running in corridors is very fast, and if a lot of monsters are
2835 * nearby, it is much faster than the old methods.
2837 * Note that resting, most normal commands, and several forms of running,
2838 * plus all commands executed near large groups of monsters, are strictly
2839 * more efficient with "update_view()" that with the old "compute los() on
2840 * demand" method, primarily because once the "field of view" has been
2841 * calculated, it does not have to be recalculated until the player moves
2842 * (or a wall or door is created or destroyed).
2844 * Note that we no longer have to do as many "los()" checks, since once the
2845 * "view" region has been built, very few things cause it to be "changed"
2846 * (player movement, and the opening/closing of doors, changes in wall status).
2847 * Note that door/wall changes are only relevant when the door/wall itself is
2848 * in the "view" region.
2850 * The algorithm seems to only call "los()" from zero to ten times, usually
2851 * only when coming down a corridor into a room, or standing in a room, just
2852 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2853 * we will be reducing the calls to "los()".
2855 * I am thinking in terms of an algorithm that "walks" from the central point
2856 * out to the maximal "distance", at each point, determining the "view" code
2857 * (above). For each grid not on a major axis or diagonal, the "view" code
2858 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
2859 * (the one along the nearest diagonal, and the one next to that one, see
2860 * "update_view_aux()"...).
2862 * We "memorize" the viewable space array, so that at the cost of under 3000
2863 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2864 * each grid actually in the "viewable space". And for another 3000 bytes,
2865 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2866 * are also used by other routines, thus reducing the cost to almost nothing.
2868 * A similar thing is done for "forget_lite()" in which case the savings are
2869 * much less, but save us from doing bizarre maintenance checking.
2871 * In the worst "normal" case (in the middle of the town), the reachable space
2872 * actually reaches to more than half of the largest possible "circle" of view,
2873 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2874 * where all the walls have been removed), the reachable space actually reaches
2875 * the theoretical maximum size of just under 1500 grids.
2877 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2878 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2879 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2880 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2881 * entire possible space (including initialization) in one step per grid. If
2882 * we do the "clearing" as a separate step (and use an array of "view" grids),
2883 * then the clearing will take as many steps as grids that were viewed, and the
2884 * algorithm will be able to "stop" scanning at various points.
2885 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2896 * Actually erase the entire "lite" array, redrawing every grid
2898 void forget_lite(void)
2902 /* None to forget */
2903 if (!lite_n) return;
2905 /* Clear them all */
2906 for (i = 0; i < lite_n; i++)
2911 /* Forget "LITE" flag */
2912 cave[y][x].info &= ~(CAVE_LITE);
2926 * This macro allows us to efficiently add a grid to the "lite" array,
2927 * note that we are never called for illegal grids, or for grids which
2928 * have already been placed into the "lite" array, and we are never
2929 * called when the "lite" array is full.
2931 #define cave_lite_hack(Y,X) \
2933 if (!(cave[Y][X].info & (CAVE_LITE))) { \
2934 cave[Y][X].info |= (CAVE_LITE); \
2935 lite_y[lite_n] = (Y); \
2936 lite_x[lite_n] = (X); \
2942 * Update the set of grids "illuminated" by the player's lite.
2944 * This routine needs to use the results of "update_view()"
2946 * Note that "blindness" does NOT affect "torch lite". Be careful!
2948 * We optimize most lites (all non-artifact lites) by using "obvious"
2949 * facts about the results of "small" lite radius, and we attempt to
2950 * list the "nearby" grids before the more "distant" ones in the
2951 * array of torch-lit grids.
2953 * We will correctly handle "large" radius lites, though currently,
2954 * it is impossible for the player to have more than radius 3 lite.
2956 * We assume that "radius zero" lite is in fact no lite at all.
2958 * Torch Lantern Artifacts
2968 void update_lite(void)
2970 int i, x, y, min_x, max_x, min_y, max_y;
2971 int p = p_ptr->cur_lite;
2973 /*** Special case ***/
2975 /* Hack -- Player has no lite */
2978 /* Forget the old lite */
2981 /* Draw the player */
2986 /*** Save the old "lite" grids for later ***/
2988 /* Clear them all */
2989 for (i = 0; i < lite_n; i++)
2994 /* Mark the grid as not "lite" */
2995 cave[y][x].info &= ~(CAVE_LITE);
2997 /* Mark the grid as "seen" */
2998 cave[y][x].info |= (CAVE_TEMP);
3000 /* Add it to the "seen" set */
3010 /*** Collect the new "lite" grids ***/
3012 /* Radius 1 -- torch radius */
3016 cave_lite_hack(py, px);
3019 cave_lite_hack(py+1, px);
3020 cave_lite_hack(py-1, px);
3021 cave_lite_hack(py, px+1);
3022 cave_lite_hack(py, px-1);
3024 /* Diagonal grids */
3025 cave_lite_hack(py+1, px+1);
3026 cave_lite_hack(py+1, px-1);
3027 cave_lite_hack(py-1, px+1);
3028 cave_lite_hack(py-1, px-1);
3031 /* Radius 2 -- lantern radius */
3034 /* South of the player */
3035 if (cave_floor_bold(py+1, px))
3037 cave_lite_hack(py+2, px);
3038 cave_lite_hack(py+2, px+1);
3039 cave_lite_hack(py+2, px-1);
3042 /* North of the player */
3043 if (cave_floor_bold(py-1, px))
3045 cave_lite_hack(py-2, px);
3046 cave_lite_hack(py-2, px+1);
3047 cave_lite_hack(py-2, px-1);
3050 /* East of the player */
3051 if (cave_floor_bold(py, px+1))
3053 cave_lite_hack(py, px+2);
3054 cave_lite_hack(py+1, px+2);
3055 cave_lite_hack(py-1, px+2);
3058 /* West of the player */
3059 if (cave_floor_bold(py, px-1))
3061 cave_lite_hack(py, px-2);
3062 cave_lite_hack(py+1, px-2);
3063 cave_lite_hack(py-1, px-2);
3067 /* Radius 3+ -- artifact radius */
3072 /* Paranoia -- see "LITE_MAX" */
3075 /* South-East of the player */
3076 if (cave_floor_bold(py+1, px+1))
3078 cave_lite_hack(py+2, px+2);
3081 /* South-West of the player */
3082 if (cave_floor_bold(py+1, px-1))
3084 cave_lite_hack(py+2, px-2);
3087 /* North-East of the player */
3088 if (cave_floor_bold(py-1, px+1))
3090 cave_lite_hack(py-2, px+2);
3093 /* North-West of the player */
3094 if (cave_floor_bold(py-1, px-1))
3096 cave_lite_hack(py-2, px-2);
3101 if (min_y < 0) min_y = 0;
3105 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3109 if (min_x < 0) min_x = 0;
3113 if (max_x > cur_wid-1) max_x = cur_wid-1;
3115 /* Scan the maximal box */
3116 for (y = min_y; y <= max_y; y++)
3118 for (x = min_x; x <= max_x; x++)
3120 int dy = (py > y) ? (py - y) : (y - py);
3121 int dx = (px > x) ? (px - x) : (x - px);
3123 /* Skip the "central" grids (above) */
3124 if ((dy <= 2) && (dx <= 2)) continue;
3126 /* Hack -- approximate the distance */
3127 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3129 /* Skip distant grids */
3130 if (d > p) continue;
3132 /* Viewable, nearby, grids get "torch lit" */
3133 if (player_has_los_bold(y, x))
3135 /* This grid is "torch lit" */
3136 cave_lite_hack(y, x);
3143 /*** Complete the algorithm ***/
3145 /* Draw the new grids */
3146 for (i = 0; i < lite_n; i++)
3151 /* Update fresh grids */
3152 if (cave[y][x].info & (CAVE_TEMP)) continue;
3161 /* Clear them all */
3162 for (i = 0; i < temp_n; i++)
3167 /* No longer in the array */
3168 cave[y][x].info &= ~(CAVE_TEMP);
3170 /* Update stale grids */
3171 if (cave[y][x].info & (CAVE_LITE)) continue;
3182 static bool mon_invis;
3185 * Add a square to the changes array
3187 static void mon_lite_hack(int y, int x)
3192 if (!in_bounds2(y, x)) return;
3194 c_ptr = &cave[y][x];
3196 /* Want a unlit square in view of the player */
3197 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3199 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3200 if (!cave_floor_grid(c_ptr) && mon_invis) return;
3202 /* Save this square */
3203 if (temp_n < TEMP_MAX)
3211 c_ptr->info |= CAVE_MNLT;
3218 * Update squares illuminated by monsters.
3220 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3221 * denote squares illuminated by monsters.
3223 * The CAVE_TEMP flag is used to store the state during the
3224 * updating. Only squares in view of the player, whos state
3225 * changes are drawn via lite_spot().
3227 void update_mon_lite(void)
3236 bool daytime = ((turn % (20L * TOWN_DAWN)) < ((20L * TOWN_DAWN) / 2));
3238 /* Clear all monster lit squares */
3239 for (i = 0; i < mon_lite_n; i++)
3242 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3245 c_ptr->info |= (CAVE_TEMP);
3247 /* Clear monster illumination flag */
3248 c_ptr->info &= ~(CAVE_MNLT);
3251 /* Empty temp list of new squares to lite up */
3254 /* Loop through monsters, adding newly lit squares to changes list */
3255 for (i = 1; i < m_max; i++)
3257 monster_type *m_ptr = &m_list[i];
3258 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3260 /* Skip dead monsters */
3261 if (!m_ptr->r_idx) continue;
3263 /* Is it too far away? */
3264 if (m_ptr->cdis > ((d_info[dungeon_type].flags1 & DF1_DARKNESS) ? MAX_SIGHT / 2 + 1 : MAX_SIGHT + 3)) continue;
3266 /* Get lite radius */
3269 /* Note the radii are cumulative */
3270 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3271 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3273 /* Exit if has no light */
3275 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && daytime) || p_ptr->inside_battle)) continue;
3277 if (world_monster) continue;
3279 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3281 /* Access the location */
3285 /* Is the monster visible? */
3286 mon_invis = !(cave[fy][fx].info & CAVE_VIEW);
3288 /* The square it is on */
3289 mon_lite_hack(fy, fx);
3291 /* Adjacent squares */
3292 mon_lite_hack(fy + 1, fx);
3293 mon_lite_hack(fy - 1, fx);
3294 mon_lite_hack(fy, fx + 1);
3295 mon_lite_hack(fy, fx - 1);
3296 mon_lite_hack(fy + 1, fx + 1);
3297 mon_lite_hack(fy + 1, fx - 1);
3298 mon_lite_hack(fy - 1, fx + 1);
3299 mon_lite_hack(fy - 1, fx - 1);
3304 /* South of the monster */
3305 if (cave_floor_bold(fy + 1, fx))
3307 mon_lite_hack(fy + 2, fx + 1);
3308 mon_lite_hack(fy + 2, fx);
3309 mon_lite_hack(fy + 2, fx - 1);
3311 c_ptr = &cave[fy + 2][fx];
3314 if ((rad == 3) && cave_floor_grid(c_ptr))
3316 mon_lite_hack(fy + 3, fx + 1);
3317 mon_lite_hack(fy + 3, fx);
3318 mon_lite_hack(fy + 3, fx - 1);
3322 /* North of the monster */
3323 if (cave_floor_bold(fy - 1, fx))
3325 mon_lite_hack(fy - 2, fx + 1);
3326 mon_lite_hack(fy - 2, fx);
3327 mon_lite_hack(fy - 2, fx - 1);
3329 c_ptr = &cave[fy - 2][fx];
3332 if ((rad == 3) && cave_floor_grid(c_ptr))
3334 mon_lite_hack(fy - 3, fx + 1);
3335 mon_lite_hack(fy - 3, fx);
3336 mon_lite_hack(fy - 3, fx - 1);
3340 /* East of the monster */
3341 if (cave_floor_bold(fy, fx + 1))
3343 mon_lite_hack(fy + 1, fx + 2);
3344 mon_lite_hack(fy, fx + 2);
3345 mon_lite_hack(fy - 1, fx + 2);
3347 c_ptr = &cave[fy][fx + 2];
3350 if ((rad == 3) && cave_floor_grid(c_ptr))
3352 mon_lite_hack(fy + 1, fx + 3);
3353 mon_lite_hack(fy, fx + 3);
3354 mon_lite_hack(fy - 1, fx + 3);
3358 /* West of the monster */
3359 if (cave_floor_bold(fy, fx - 1))
3361 mon_lite_hack(fy + 1, fx - 2);
3362 mon_lite_hack(fy, fx - 2);
3363 mon_lite_hack(fy - 1, fx - 2);
3365 c_ptr = &cave[fy][fx - 2];
3368 if ((rad == 3) && cave_floor_grid(c_ptr))
3370 mon_lite_hack(fy + 1, fx - 3);
3371 mon_lite_hack(fy, fx - 3);
3372 mon_lite_hack(fy - 1, fx - 3);
3380 /* South-East of the monster */
3381 if (cave_floor_bold(fy + 1, fx + 1))
3383 mon_lite_hack(fy + 2, fx + 2);
3386 /* South-West of the monster */
3387 if (cave_floor_bold(fy + 1, fx - 1))
3389 mon_lite_hack(fy + 2, fx - 2);
3392 /* North-East of the monster */
3393 if (cave_floor_bold(fy - 1, fx + 1))
3395 mon_lite_hack(fy - 2, fx + 2);
3398 /* North-West of the monster */
3399 if (cave_floor_bold(fy - 1, fx - 1))
3401 mon_lite_hack(fy - 2, fx - 2);
3406 /* Save end of list of new squares */
3410 * Look at old set flags to see if there are any changes.
3412 for (i = 0; i < mon_lite_n; i++)
3417 if (!in_bounds2(fy, fx)) continue;
3420 c_ptr = &cave[fy][fx];
3422 /* It it no longer lit? */
3423 if (!(c_ptr->info & CAVE_MNLT) && player_has_los_grid(c_ptr))
3425 /* It is now unlit */
3430 /* Add to end of temp array */
3431 temp_x[temp_n] = (byte)fx;
3432 temp_y[temp_n] = (byte)fy;
3436 /* Clear the lite array */
3439 /* Copy the temp array into the lit array lighting the new squares. */
3440 for (i = 0; i < temp_n; i++)
3445 if (!in_bounds2(fy, fx)) continue;
3448 c_ptr = &cave[fy][fx];
3452 /* Clear the temp flag for the old lit grids */
3453 c_ptr->info &= ~(CAVE_TEMP);
3457 /* The is the square newly lit and visible? */
3458 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3465 /* Save in the monster lit array */
3466 mon_lite_x[mon_lite_n] = fx;
3467 mon_lite_y[mon_lite_n] = fy;
3472 /* Finished with temp_n */
3475 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3477 if (p_ptr->special_defense & NINJA_S_STEALTH)
3479 if (p_ptr->old_monlite != p_ptr->monlite)
3484 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3486 msg_print("Your mantle of shadow become thin.");
3492 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3494 msg_print("Your mantle of shadow restored its original darkness.");
3499 p_ptr->old_monlite = p_ptr->monlite;
3502 void clear_mon_lite(void)
3507 /* Clear all monster lit squares */
3508 for (i = 0; i < mon_lite_n; i++)
3511 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3513 /* Clear monster illumination flag */
3514 c_ptr->info &= ~(CAVE_MNLT);
3517 /* Empty the array */
3524 * Clear the viewable space
3526 void forget_view(void)
3532 /* None to forget */
3533 if (!view_n) return;
3535 /* Clear them all */
3536 for (i = 0; i < view_n; i++)
3541 /* Access the grid */
3542 c_ptr = &cave[y][x];
3544 /* Forget that the grid is viewable */
3545 c_ptr->info &= ~(CAVE_VIEW);
3547 /* Update the screen */
3558 * This macro allows us to efficiently add a grid to the "view" array,
3559 * note that we are never called for illegal grids, or for grids which
3560 * have already been placed into the "view" array, and we are never
3561 * called when the "view" array is full.
3563 #define cave_view_hack(C,Y,X) \
3565 if (!((C)->info & (CAVE_VIEW))){\
3566 (C)->info |= (CAVE_VIEW); \
3567 view_y[view_n] = (Y); \
3568 view_x[view_n] = (X); \
3575 * Helper function for "update_view()" below
3577 * We are checking the "viewability" of grid (y,x) by the player.
3579 * This function assumes that (y,x) is legal (i.e. on the map).
3581 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3582 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3584 * Note that we are using the "CAVE_XTRA" field for marking grids as
3585 * "easily viewable". This bit is cleared at the end of "update_view()".
3587 * This function adds (y,x) to the "viewable set" if necessary.
3589 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3591 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3593 bool f1, f2, v1, v2, z1, z2, wall;
3597 cave_type *g1_c_ptr;
3598 cave_type *g2_c_ptr;
3600 /* Access the grids */
3601 g1_c_ptr = &cave[y1][x1];
3602 g2_c_ptr = &cave[y2][x2];
3605 /* Check for walls */
3606 f1 = (cave_floor_grid(g1_c_ptr));
3607 f2 = (cave_floor_grid(g2_c_ptr));
3609 /* Totally blocked by physical walls */
3610 if (!f1 && !f2) return (TRUE);
3613 /* Check for visibility */
3614 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3615 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3617 /* Totally blocked by "unviewable neighbors" */
3618 if (!v1 && !v2) return (TRUE);
3621 /* Access the grid */
3622 c_ptr = &cave[y][x];
3625 /* Check for walls */
3626 wall = (!cave_floor_grid(c_ptr));
3629 /* Check the "ease" of visibility */
3630 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3631 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3633 /* Hack -- "easy" plus "easy" yields "easy" */
3636 c_ptr->info |= (CAVE_XTRA);
3638 cave_view_hack(c_ptr, y, x);
3643 /* Hack -- primary "easy" yields "viewed" */
3646 cave_view_hack(c_ptr, y, x);
3651 /* Hack -- "view" plus "view" yields "view" */
3654 /* c_ptr->info |= (CAVE_XTRA); */
3656 cave_view_hack(c_ptr, y, x);
3662 /* Mega-Hack -- the "los()" function works poorly on walls */
3665 cave_view_hack(c_ptr, y, x);
3671 /* Hack -- check line of sight */
3672 if (los(py, px, y, x))
3674 cave_view_hack(c_ptr, y, x);
3680 /* Assume no line of sight. */
3687 * Calculate the viewable space
3689 * 1: Process the player
3690 * 1a: The player is always (easily) viewable
3691 * 2: Process the diagonals
3692 * 2a: The diagonals are (easily) viewable up to the first wall
3693 * 2b: But never go more than 2/3 of the "full" distance
3694 * 3: Process the main axes
3695 * 3a: The main axes are (easily) viewable up to the first wall
3696 * 3b: But never go more than the "full" distance
3697 * 4: Process sequential "strips" in each of the eight octants
3698 * 4a: Each strip runs along the previous strip
3699 * 4b: The main axes are "previous" to the first strip
3700 * 4c: Process both "sides" of each "direction" of each strip
3701 * 4c1: Each side aborts as soon as possible
3702 * 4c2: Each side tells the next strip how far it has to check
3704 * Note that the octant processing involves some pretty interesting
3705 * observations involving when a grid might possibly be viewable from
3706 * a given grid, and on the order in which the strips are processed.
3708 * Note the use of the mathematical facts shown below, which derive
3709 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3710 * hypotenuse of a right triangle is primarily determined by the length
3711 * of the longest side, when one side is small, and is strictly less
3712 * than one-and-a-half times as long as the longest side when both of
3713 * the sides are large.
3715 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3716 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3718 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3720 * These observations are important because the calculation of the actual
3721 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3722 * while for small values (up to about 20 or so), the approximations above
3723 * are correct to within an error of at most one grid or so.
3725 * Observe the use of "full" and "over" in the code below, and the use of
3726 * the specialized calculation involving "limit", all of which derive from
3727 * the observations given above. Basically, we note that the "circle" of
3728 * view is completely contained in an "octagon" whose bounds are easy to
3729 * determine, and that only a few steps are needed to derive the actual
3730 * bounds of the circle given the bounds of the octagon.
3732 * Note that by skipping all the grids in the corners of the octagon, we
3733 * place an upper limit on the number of grids in the field of view, given
3734 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3735 * view, only about 1475 of these are in the "octagon" of view, and even
3736 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3737 * entries to completely contain the actual field of view.
3739 * Note also the care taken to prevent "running off the map". The use of
3740 * explicit checks on the "validity" of the "diagonal", and the fact that
3741 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3742 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3743 * of multiple checks on the validity of grids.
3745 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3746 * "ws","wn" variables. They work like this: While travelling down the
3747 * south-bound strip just to the east of the main south axis, as soon as
3748 * we get to a grid which does not "transmit" viewing, if all of the strips
3749 * preceding us (in this case, just the main axis) had terminated at or before
3750 * the same point, then we can stop, and reset the "max distance" to ourself.
3751 * So, each strip (named by major axis plus offset, thus "se" in this case)
3752 * maintains a "blockage" variable, initialized during the main axis step,
3753 * and checks it whenever a blockage is observed. After processing each
3754 * strip as far as the previous strip told us to process, the next strip is
3755 * told not to go farther than the current strip's farthest viewable grid,
3756 * unless open space is still available. This uses the "k" variable.
3758 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3759 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3760 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3761 * chunk of code which adds the given location to the "view" array if it
3762 * is not already there, using both the actual location and a pointer to
3763 * the cave grid. See above.
3765 * By the way, the purpose of this code is to reduce the dependancy on the
3766 * "los()" function which is slow, and, in some cases, not very accurate.
3768 * It is very possible that I am the only person who fully understands this
3769 * function, and for that I am truly sorry, but efficiency was very important
3770 * and the "simple" version of this function was just not fast enough. I am
3771 * more than willing to replace this function with a simpler one, if it is
3772 * equally efficient, and especially willing if the new function happens to
3773 * derive "reverse-line-of-sight" at the same time, since currently monsters
3774 * just use an optimized hack of "you see me, so I see you", and then use the
3775 * actual "projectable()" function to check spell attacks.
3777 void update_view(void)
3779 int n, m, d, k, y, x, z;
3781 int se, sw, ne, nw, es, en, ws, wn;
3785 int y_max = cur_hgt - 1;
3786 int x_max = cur_wid - 1;
3790 /*** Initialize ***/
3793 if (view_reduce_view && !dun_level)
3795 /* Full radius (10) */
3796 full = MAX_SIGHT / 2;
3798 /* Octagon factor (15) */
3799 over = MAX_SIGHT * 3 / 4;
3805 /* Full radius (20) */
3808 /* Octagon factor (30) */
3809 over = MAX_SIGHT * 3 / 2;
3813 /*** Step 0 -- Begin ***/
3815 /* Save the old "view" grids for later */
3816 for (n = 0; n < view_n; n++)
3821 /* Access the grid */
3822 c_ptr = &cave[y][x];
3824 /* Mark the grid as not in "view" */
3825 c_ptr->info &= ~(CAVE_VIEW);
3827 /* Mark the grid as "seen" */
3828 c_ptr->info |= (CAVE_TEMP);
3830 /* Add it to the "seen" set */
3836 /* Start over with the "view" array */
3839 /*** Step 1 -- adjacent grids ***/
3841 /* Now start on the player */
3845 /* Access the grid */
3846 c_ptr = &cave[y][x];
3848 /* Assume the player grid is easily viewable */
3849 c_ptr->info |= (CAVE_XTRA);
3851 /* Assume the player grid is viewable */
3852 cave_view_hack(c_ptr, y, x);
3855 /*** Step 2 -- Major Diagonals ***/
3860 /* Scan south-east */
3861 for (d = 1; d <= z; d++)
3863 c_ptr = &cave[y+d][x+d];
3864 c_ptr->info |= (CAVE_XTRA);
3865 cave_view_hack(c_ptr, y+d, x+d);
3866 if (!cave_floor_grid(c_ptr)) break;
3869 /* Scan south-west */
3870 for (d = 1; d <= z; d++)
3872 c_ptr = &cave[y+d][x-d];
3873 c_ptr->info |= (CAVE_XTRA);
3874 cave_view_hack(c_ptr, y+d, x-d);
3875 if (!cave_floor_grid(c_ptr)) break;
3878 /* Scan north-east */
3879 for (d = 1; d <= z; d++)
3881 c_ptr = &cave[y-d][x+d];
3882 c_ptr->info |= (CAVE_XTRA);
3883 cave_view_hack(c_ptr, y-d, x+d);
3884 if (!cave_floor_grid(c_ptr)) break;
3887 /* Scan north-west */
3888 for (d = 1; d <= z; d++)
3890 c_ptr = &cave[y-d][x-d];
3891 c_ptr->info |= (CAVE_XTRA);
3892 cave_view_hack(c_ptr, y-d, x-d);
3893 if (!cave_floor_grid(c_ptr)) break;
3897 /*** Step 3 -- major axes ***/
3900 for (d = 1; d <= full; d++)
3902 c_ptr = &cave[y+d][x];
3903 c_ptr->info |= (CAVE_XTRA);
3904 cave_view_hack(c_ptr, y+d, x);
3905 if (!cave_floor_grid(c_ptr)) break;
3908 /* Initialize the "south strips" */
3912 for (d = 1; d <= full; d++)
3914 c_ptr = &cave[y-d][x];
3915 c_ptr->info |= (CAVE_XTRA);
3916 cave_view_hack(c_ptr, y-d, x);
3917 if (!cave_floor_grid(c_ptr)) break;
3920 /* Initialize the "north strips" */
3924 for (d = 1; d <= full; d++)
3926 c_ptr = &cave[y][x+d];
3927 c_ptr->info |= (CAVE_XTRA);
3928 cave_view_hack(c_ptr, y, x+d);
3929 if (!cave_floor_grid(c_ptr)) break;
3932 /* Initialize the "east strips" */
3936 for (d = 1; d <= full; d++)
3938 c_ptr = &cave[y][x-d];
3939 c_ptr->info |= (CAVE_XTRA);
3940 cave_view_hack(c_ptr, y, x-d);
3941 if (!cave_floor_grid(c_ptr)) break;
3944 /* Initialize the "west strips" */
3948 /*** Step 4 -- Divide each "octant" into "strips" ***/
3950 /* Now check each "diagonal" (in parallel) */
3951 for (n = 1; n <= over / 2; n++)
3953 int ypn, ymn, xpn, xmn;
3956 /* Acquire the "bounds" of the maximal circle */
3958 if (z > full - n) z = full - n;
3959 while ((z + n + (n>>1)) > full) z--;
3962 /* Access the four diagonal grids */
3972 /* Maximum distance */
3973 m = MIN(z, y_max - ypn);
3976 if ((xpn <= x_max) && (n < se))
3979 for (k = n, d = 1; d <= m; d++)
3981 /* Check grid "d" in strip "n", notice "blockage" */
3982 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3984 if (n + d >= se) break;
3987 /* Track most distant "non-blockage" */
3994 /* Limit the next strip */
3999 if ((xmn >= 0) && (n < sw))
4002 for (k = n, d = 1; d <= m; d++)
4004 /* Check grid "d" in strip "n", notice "blockage" */
4005 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
4007 if (n + d >= sw) break;
4010 /* Track most distant "non-blockage" */
4017 /* Limit the next strip */
4026 /* Maximum distance */
4030 if ((xpn <= x_max) && (n < ne))
4033 for (k = n, d = 1; d <= m; d++)
4035 /* Check grid "d" in strip "n", notice "blockage" */
4036 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
4038 if (n + d >= ne) break;
4041 /* Track most distant "non-blockage" */
4048 /* Limit the next strip */
4053 if ((xmn >= 0) && (n < nw))
4056 for (k = n, d = 1; d <= m; d++)
4058 /* Check grid "d" in strip "n", notice "blockage" */
4059 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
4061 if (n + d >= nw) break;
4064 /* Track most distant "non-blockage" */
4071 /* Limit the next strip */
4080 /* Maximum distance */
4081 m = MIN(z, x_max - xpn);
4084 if ((ypn <= x_max) && (n < es))
4087 for (k = n, d = 1; d <= m; d++)
4089 /* Check grid "d" in strip "n", notice "blockage" */
4090 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
4092 if (n + d >= es) break;
4095 /* Track most distant "non-blockage" */
4102 /* Limit the next strip */
4107 if ((ymn >= 0) && (n < en))
4110 for (k = n, d = 1; d <= m; d++)
4112 /* Check grid "d" in strip "n", notice "blockage" */
4113 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4115 if (n + d >= en) break;
4118 /* Track most distant "non-blockage" */
4125 /* Limit the next strip */
4134 /* Maximum distance */
4138 if ((ypn <= y_max) && (n < ws))
4141 for (k = n, d = 1; d <= m; d++)
4143 /* Check grid "d" in strip "n", notice "blockage" */
4144 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4146 if (n + d >= ws) break;
4149 /* Track most distant "non-blockage" */
4156 /* Limit the next strip */
4161 if ((ymn >= 0) && (n < wn))
4164 for (k = n, d = 1; d <= m; d++)
4166 /* Check grid "d" in strip "n", notice "blockage" */
4167 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4169 if (n + d >= wn) break;
4172 /* Track most distant "non-blockage" */
4179 /* Limit the next strip */
4186 /*** Step 5 -- Complete the algorithm ***/
4188 /* Update all the new grids */
4189 for (n = 0; n < view_n; n++)
4194 /* Access the grid */
4195 c_ptr = &cave[y][x];
4197 /* Clear the "CAVE_XTRA" flag */
4198 c_ptr->info &= ~(CAVE_XTRA);
4200 /* Update only newly viewed grids */
4201 if (c_ptr->info & (CAVE_TEMP)) continue;
4210 /* Wipe the old grids, update as needed */
4211 for (n = 0; n < temp_n; n++)
4216 /* Access the grid */
4217 c_ptr = &cave[y][x];
4219 /* No longer in the array */
4220 c_ptr->info &= ~(CAVE_TEMP);
4222 /* Update only non-viewable grids */
4223 if (c_ptr->info & (CAVE_VIEW)) continue;
4239 * Hack -- provide some "speed" for the "flow" code
4240 * This entry is the "current index" for the "when" field
4241 * Note that a "when" value of "zero" means "not used".
4243 * Note that the "cost" indexes from 1 to 127 are for
4244 * "old" data, and from 128 to 255 are for "new" data.
4246 * This means that as long as the player does not "teleport",
4247 * then any monster up to 128 + MONSTER_FLOW_DEPTH will be
4248 * able to track down the player, and in general, will be
4249 * able to track down either the player or a position recently
4250 * occupied by the player.
4252 static int flow_n = 0;
4256 * Hack -- forget the "flow" information
4258 void forget_flow(void)
4262 /* Nothing to forget */
4263 if (!flow_n) return;
4265 /* Check the entire dungeon */
4266 for (y = 0; y < cur_hgt; y++)
4268 for (x = 0; x < cur_wid; x++)
4270 /* Forget the old data */
4271 cave[y][x].dist = 0;
4272 cave[y][x].cost = 0;
4273 cave[y][x].when = 0;
4283 * Hack - speed up the update_flow algorithm by only doing
4284 * it everytime the player moves out of LOS of the last
4287 static u16b flow_x = 0;
4288 static u16b flow_y = 0;
4293 * Hack -- fill in the "cost" field of every grid that the player
4294 * can "reach" with the number of steps needed to reach that grid.
4295 * This also yields the "distance" of the player from every grid.
4297 * In addition, mark the "when" of the grids that can reach
4298 * the player with the incremented value of "flow_n".
4300 * Hack -- use the "seen" array as a "circular queue".
4302 * We do not need a priority queue because the cost from grid
4303 * to grid is always "one" and we process them in order.
4305 void update_flow(void)
4311 /* Hack -- disabled */
4312 if (stupid_monsters) return;
4314 /* Paranoia -- make sure the array is empty */
4317 /* The last way-point is on the map */
4318 if (running && in_bounds(flow_y, flow_x))
4320 /* The way point is in sight - do not update. (Speedup) */
4321 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4324 /* Erase all of the current flow information */
4325 for (y = 0; y < cur_hgt; y++)
4327 for (x = 0; x < cur_wid; x++)
4329 cave[y][x].cost = 0;
4330 cave[y][x].dist = 0;
4334 /* Save player position */
4338 /* Add the player's grid to the queue */
4342 /* Now process the queue */
4343 while (flow_head != flow_tail)
4347 /* Extract the next entry */
4348 ty = temp_y[flow_tail];
4349 tx = temp_x[flow_tail];
4351 /* Forget that entry */
4352 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4354 /* Add the "children" */
4355 for (d = 0; d < 8; d++)
4357 int old_head = flow_head;
4358 int m = cave[ty][tx].cost + 1;
4359 int n = cave[ty][tx].dist + 1;
4362 /* Child location */
4363 y = ty + ddy_ddd[d];
4364 x = tx + ddx_ddd[d];
4366 /* Ignore player's grid */
4367 if (x == px && y == py) continue;
4369 c_ptr = &cave[y][x];
4371 if ((c_ptr->feat >= FEAT_DOOR_HEAD) && (c_ptr->feat <= FEAT_SECRET)) m += 3;
4373 /* Ignore "pre-stamped" entries */
4374 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4376 /* Ignore "walls" and "rubble" */
4377 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4379 /* Save the flow cost */
4380 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4381 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4383 /* Hack -- limit flow depth */
4384 if (n == MONSTER_FLOW_DEPTH) continue;
4386 /* Enqueue that entry */
4387 temp_y[flow_head] = y;
4388 temp_x[flow_head] = x;
4390 /* Advance the queue */
4391 if (++flow_head == TEMP_MAX) flow_head = 0;
4393 /* Hack -- notice overflow by forgetting new entry */
4394 if (flow_head == flow_tail) flow_head = old_head;
4400 static int scent_when = 0;
4403 * Characters leave scent trails for perceptive monsters to track.
4405 * Smell is rather more limited than sound. Many creatures cannot use
4406 * it at all, it doesn't extend very far outwards from the character's
4407 * current position, and monsters can use it to home in the character,
4408 * but not to run away from him.
4410 * Smell is valued according to age. When a character takes his turn,
4411 * scent is aged by one, and new scent of the current age is laid down.
4412 * Speedy characters leave more scent, true, but it also ages faster,
4413 * which makes it harder to hunt them down.
4415 * Whenever the age count loops, most of the scent trail is erased and
4416 * the age of the remainder is recalculated.
4418 void update_smell(void)
4423 /* Create a table that controls the spread of scent */
4424 const int scent_adjust[5][5] =
4433 /* Loop the age and adjust scent values when necessary */
4434 if (++scent_when == 254)
4436 /* Scan the entire dungeon */
4437 for (y = 0; y < cur_hgt; y++)
4439 for (x = 0; x < cur_wid; x++)
4441 int w = cave[y][x].when;
4442 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4451 /* Lay down new scent */
4452 for (i = 0; i < 5; i++)
4454 for (j = 0; j < 5; j++)
4458 /* Translate table to map grids */
4463 if (!in_bounds(y, x)) continue;
4465 c_ptr = &cave[y][x];
4467 /* Walls, water, and lava cannot hold scent. */
4468 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4470 /* Grid must not be blocked by walls from the character */
4471 if (!player_has_los_bold(y, x)) continue;
4473 /* Note grids that are too far away */
4474 if (scent_adjust[i][j] == -1) continue;
4476 /* Mark the grid with new scent */
4477 c_ptr->when = scent_when + scent_adjust[i][j];
4484 * Hack -- map the current panel (plus some) ala "magic mapping"
4486 void map_area(int range)
4492 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4494 /* Scan that area */
4495 for (y = 1; y < cur_hgt - 1; y++)
4497 for (x = 1; x < cur_wid - 1; x++)
4499 if (distance(py, px, y, x) > range) continue;
4501 c_ptr = &cave[y][x];
4503 /* All non-walls are "checked" */
4504 if ((c_ptr->feat < FEAT_SECRET) ||
4505 (c_ptr->feat == FEAT_RUBBLE) ||
4506 ((c_ptr->feat >= FEAT_MINOR_GLYPH) &&
4507 (c_ptr->feat <= FEAT_TREES)) ||
4508 (c_ptr->feat >= FEAT_TOWN))
4510 /* Memorize normal features */
4511 if ((c_ptr->feat > FEAT_INVIS) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4513 /* Memorize the object */
4514 c_ptr->info |= (CAVE_MARK);
4517 /* Memorize known walls */
4518 for (i = 0; i < 8; i++)
4520 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4522 /* Memorize walls (etc) */
4523 if ((c_ptr->feat >= FEAT_SECRET) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4525 /* Memorize the walls */
4526 c_ptr->info |= (CAVE_MARK);
4534 p_ptr->redraw |= (PR_MAP);
4537 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4543 * Light up the dungeon using "clairvoyance"
4545 * This function "illuminates" every grid in the dungeon, memorizes all
4546 * "objects", memorizes all grids as with magic mapping, and, under the
4547 * standard option settings (view_perma_grids but not view_torch_grids)
4548 * memorizes all floor grids too.
4550 * Note that if "view_perma_grids" is not set, we do not memorize floor
4551 * grids, since this would defeat the purpose of "view_perma_grids", not
4552 * that anyone seems to play without this option.
4554 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4555 * since this would prevent the use of "view_torch_grids" as a method to
4556 * keep track of what grids have been observed directly.
4558 void wiz_lite(bool wizard, bool ninja)
4562 /* Memorize objects */
4563 for (i = 1; i < o_max; i++)
4565 object_type *o_ptr = &o_list[i];
4567 /* Skip dead objects */
4568 if (!o_ptr->k_idx) continue;
4570 /* Skip held objects */
4571 if (o_ptr->held_m_idx) continue;
4574 /* Skip objects in vaults, if not a wizard. -LM- */
4575 if ((wizard == FALSE) &&
4576 (cave[o_ptr->iy][o_ptr->ix].info & (CAVE_ICKY))) continue;
4580 o_ptr->marked = TRUE;
4583 /* Scan all normal grids */
4584 for (y = 1; y < cur_hgt - 1; y++)
4586 /* Scan all normal grids */
4587 for (x = 1; x < cur_wid - 1; x++)
4589 cave_type *c_ptr = &cave[y][x];
4591 /* Process all non-walls */
4592 if (cave_floor_bold(y, x) || (c_ptr->feat == FEAT_RUBBLE) || (c_ptr->feat == FEAT_TREES) || (c_ptr->feat == FEAT_MOUNTAIN))
4594 /* Scan all neighbors */
4595 for (i = 0; i < 9; i++)
4597 int yy = y + ddy_ddd[i];
4598 int xx = x + ddx_ddd[i];
4601 c_ptr = &cave[yy][xx];
4603 /* Memorize normal features */
4606 /* Memorize the grid */
4607 c_ptr->info |= (CAVE_MARK);
4611 if ((c_ptr->feat > FEAT_INVIS))
4613 /* Memorize the grid */
4614 c_ptr->info |= (CAVE_MARK);
4617 /* Perma-lite the grid */
4618 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4620 c_ptr->info |= (CAVE_GLOW);
4622 /* Normally, memorize floors (see above) */
4623 if (view_perma_grids && !view_torch_grids)
4625 /* Memorize the grid */
4626 c_ptr->info |= (CAVE_MARK);
4635 /* Update the monsters */
4636 p_ptr->update |= (PU_MONSTERS);
4639 p_ptr->redraw |= (PR_MAP);
4642 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4647 * Forget the dungeon map (ala "Thinking of Maud...").
4654 /* Forget every grid */
4655 for (y = 0; y < cur_hgt; y++)
4657 for (x = 0; x < cur_wid; x++)
4659 cave_type *c_ptr = &cave[y][x];
4661 /* Process the grid */
4662 c_ptr->info &= ~(CAVE_MARK);
4666 /* Forget all objects */
4667 for (i = 1; i < o_max; i++)
4669 object_type *o_ptr = &o_list[i];
4671 /* Skip dead objects */
4672 if (!o_ptr->k_idx) continue;
4674 /* Skip held objects */
4675 if (o_ptr->held_m_idx) continue;
4677 /* Forget the object */
4678 o_ptr->marked = FALSE;
4681 /* Mega-Hack -- Forget the view and lite */
4682 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4684 /* Update the view and lite */
4685 p_ptr->update |= (PU_VIEW | PU_LITE);
4687 /* Update the monsters */
4688 p_ptr->update |= (PU_MONSTERS);
4691 p_ptr->redraw |= (PR_MAP);
4694 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4702 * Change the "feat" flag for a grid, and notice/redraw the grid
4704 void cave_set_feat(int y, int x, int feat)
4706 cave_type *c_ptr = &cave[y][x];
4708 /* Change the feature */
4721 * Calculate "incremental motion". Used by project() and shoot().
4722 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4724 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4726 int dy, dx, dist, shift;
4728 /* Extract the distance travelled */
4729 dy = (*y < y1) ? y1 - *y : *y - y1;
4730 dx = (*x < x1) ? x1 - *x : *x - x1;
4732 /* Number of steps */
4733 dist = (dy > dx) ? dy : dx;
4735 /* We are calculating the next location */
4739 /* Calculate the total distance along each axis */
4740 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4741 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4743 /* Paranoia -- Hack -- no motion */
4744 if (!dy && !dx) return;
4747 /* Move mostly vertically */
4750 /* Extract a shift factor */
4751 shift = (dist * dx + (dy - 1) / 2) / dy;
4753 /* Sometimes move along the minor axis */
4754 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4756 /* Always move along major axis */
4757 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4760 /* Move mostly horizontally */
4763 /* Extract a shift factor */
4764 shift = (dist * dy + (dx - 1) / 2) / dx;
4766 /* Sometimes move along the minor axis */
4767 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4769 /* Always move along major axis */
4770 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4777 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4778 * at the final destination, assuming no monster gets in the way.
4780 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4782 bool projectable(int y1, int x1, int y2, int x2)
4789 /* Check the projection path */
4790 grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, 0);
4792 /* No grid is ever projectable from itself */
4793 if (!grid_n) return (FALSE);
4796 y = GRID_Y(grid_g[grid_n - 1]);
4797 x = GRID_X(grid_g[grid_n - 1]);
4799 /* May not end in an unrequested grid */
4800 if ((y != y2) || (x != x2)) return (FALSE);
4808 * Standard "find me a location" function
4810 * Obtains a legal location within the given distance of the initial
4811 * location, and with "los()" from the source to destination location.
4813 * This function is often called from inside a loop which searches for
4814 * locations while increasing the "d" distance.
4816 * Currently the "m" parameter is unused.
4818 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4825 /* Pick a location */
4828 /* Pick a new location */
4829 ny = rand_spread(y, d);
4830 nx = rand_spread(x, d);
4832 /* Ignore annoying locations */
4833 if (!in_bounds(ny, nx)) continue;
4835 /* Ignore "excessively distant" locations */
4836 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4838 /* Require "line of sight" */
4839 if (los(y, x, ny, nx)) break;
4842 /* Save the location */
4851 * Track a new monster
4853 void health_track(int m_idx)
4855 /* Track a new guy */
4856 p_ptr->health_who = m_idx;
4858 /* Redraw (later) */
4859 p_ptr->redraw |= (PR_HEALTH);
4865 * Hack -- track the given monster race
4867 void monster_race_track(bool kage, int r_idx)
4869 if (kage) r_idx = MON_KAGE;
4871 /* Save this monster ID */
4872 p_ptr->monster_race_idx = r_idx;
4875 p_ptr->window |= (PW_MONSTER);
4881 * Hack -- track the given object kind
4883 void object_kind_track(int k_idx)
4885 /* Save this monster ID */
4886 p_ptr->object_kind_idx = k_idx;
4889 p_ptr->window |= (PW_OBJECT);
4895 * Something has happened to disturb the player.
4897 * The first arg indicates a major disturbance, which affects search.
4899 * The second arg is currently unused, but could induce output flush.
4901 * All disturbance cancels repeated commands, resting, and running.
4903 void disturb(int stop_search, int unused_flag)
4906 unused_flag = unused_flag;
4908 /* Cancel auto-commands */
4909 /* command_new = 0; */
4911 /* Cancel repeated commands */
4917 /* Redraw the state (later) */
4918 p_ptr->redraw |= (PR_STATE);
4921 /* Cancel Resting */
4922 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
4925 set_action(ACTION_NONE);
4928 /* Cancel running */
4934 /* Check for new panel if appropriate */
4935 if (center_player && !center_running) verify_panel();
4937 /* Calculate torch radius */
4938 p_ptr->update |= (PU_TORCH);
4940 /* Update monster flow */
4941 p_ptr->update |= (PU_FLOW);
4944 /* Flush the input if requested */
4945 if (flush_disturb) flush();