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:
93 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,
94 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.
96 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
98 * The LOS begins at the center of the tile (x1,y1) and ends at the center of
99 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line
100 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
102 * We assume that the "mathematical corner" of a non-floor tile does not
103 * block line of sight.
105 * Because this function uses (short) ints for all calculations, overflow may
106 * occur if dx and dy exceed 90.
108 * Once all the degenerate cases are eliminated, the values "qx", "qy", and
109 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
110 * we can use integer arithmetic.
112 * We travel from start to finish along the longer axis, starting at the border
113 * between the first and second tiles, where the y offset = .5 * slope, taking
114 * into account the scale factor. See below.
116 * Also note that this function and the "move towards target" code do NOT
117 * share the same properties. Thus, you can see someone, target them, and
118 * then fire a bolt at them, but the bolt may hit a wall, not them. However,
119 * by clever choice of target locations, you can sometimes throw a "curve".
121 * Note that "line of sight" is not "reflexive" in all cases.
123 * Use the "projectable()" routine to test "spell/missile line of sight".
125 * Use the "update_view()" function to determine player line-of-sight.
127 bool los(int y1, int x1, int y2, int x2)
147 /* Slope, or 1/Slope, of LOS */
151 /* Extract the offset */
155 /* Extract the absolute offset */
160 /* Handle adjacent (or identical) grids */
161 if ((ax < 2) && (ay < 2)) return (TRUE);
164 /* Paranoia -- require "safe" origin */
165 /* if (!in_bounds(y1, x1)) return (FALSE); */
166 /* if (!in_bounds(y2, x2)) return (FALSE); */
169 /* Directly South/North */
172 /* South -- check for walls */
175 for (ty = y1 + 1; ty < y2; ty++)
177 if (!cave_floor_bold(ty, x1)) return (FALSE);
181 /* North -- check for walls */
184 for (ty = y1 - 1; ty > y2; ty--)
186 if (!cave_floor_bold(ty, x1)) return (FALSE);
194 /* Directly East/West */
197 /* East -- check for walls */
200 for (tx = x1 + 1; tx < x2; tx++)
202 if (!cave_floor_bold(y1, tx)) return (FALSE);
206 /* West -- check for walls */
209 for (tx = x1 - 1; tx > x2; tx--)
211 if (!cave_floor_bold(y1, tx)) return (FALSE);
220 /* Extract some signs */
221 sx = (dx < 0) ? -1 : 1;
222 sy = (dy < 0) ? -1 : 1;
225 /* Vertical "knights" */
230 if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
234 /* Horizontal "knights" */
239 if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
244 /* Calculate scale factor div 2 */
247 /* Calculate scale factor */
251 /* Travel horizontally */
254 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
260 /* Consider the special case where slope == 1. */
271 /* Note (below) the case (qy == f2), where */
272 /* the LOS exactly meets the corner of a tile. */
275 if (!cave_floor_bold(ty, tx)) return (FALSE);
286 if (!cave_floor_bold(ty, tx)) return (FALSE);
299 /* Travel vertically */
302 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
318 /* Note (below) the case (qx == f2), where */
319 /* the LOS exactly meets the corner of a tile. */
322 if (!cave_floor_bold(ty, tx)) return (FALSE);
333 if (!cave_floor_bold(ty, tx)) return (FALSE);
356 * Can the player "see" the given grid in detail?
358 * He must have vision, illumination, and line of sight.
360 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
361 * So, given "CAVE_LITE", we know that the grid is "fully visible".
363 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
364 * that a wall is visible from any direction. That would be odd. Except
365 * under wizard light, which might make sense. Thus, for walls, we require
366 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
367 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
368 * in line of sight of the player.
370 * This extra check is expensive, but it provides a more "correct" semantics.
372 * Note that we should not run this check on walls which are "outer walls" of
373 * the dungeon, or we will induce a memory fault, but actually verifying all
374 * of the locations would be extremely expensive.
376 * Thus, to speed up the function, we assume that all "perma-walls" which are
377 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
378 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
379 * and the player has more important things on his mind when he is attacking a
380 * monster vault. It is annoying, but an extremely important optimization.
382 * Note that "glowing walls" are only considered to be "illuminated" if the
383 * grid which is next to the wall in the direction of the player is also a
384 * "glowing" grid. This prevents the player from being able to "see" the
385 * walls of illuminated rooms from a corridor outside the room.
387 bool player_can_see_bold(int y, int x)
393 /* Blind players see nothing */
394 if (p_ptr->blind) return (FALSE);
396 /* Access the cave grid */
399 /* Note that "torch-lite" yields "illumination" */
400 if (c_ptr->info & (CAVE_LITE)) return (TRUE);
402 /* Require line of sight to the grid */
403 if (!player_has_los_bold(y, x)) return (FALSE);
405 if (p_ptr->pclass == CLASS_NINJA) return TRUE;
407 /* Require "perma-lite" of the grid */
408 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return (FALSE);
410 /* Floors are simple */
411 if (cave_floor_bold(y, x)) return (TRUE);
413 /* Hack -- move towards player */
414 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
415 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
417 /* Check for "local" illumination */
418 if (cave[yy][xx].info & (CAVE_GLOW | CAVE_MNLT))
420 /* Assume the wall is really illuminated */
424 /* Assume not visible */
431 * Returns true if the player's grid is dark
435 return (!player_can_see_bold(py, px));
442 * Determine if a given location may be "destroyed"
444 * Used by destruction spells, and for placing stairs, etc.
446 bool cave_valid_bold(int y, int x)
448 cave_type *c_ptr = &cave[y][x];
450 s16b this_o_idx, next_o_idx = 0;
453 /* Forbid perma-grids */
454 if (cave_perma_grid(c_ptr)) return (FALSE);
457 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
462 o_ptr = &o_list[this_o_idx];
464 /* Acquire next object */
465 next_o_idx = o_ptr->next_o_idx;
467 /* Forbid artifact grids */
468 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
479 * Determine if a given location may be "destroyed"
481 * Used by destruction spells, and for placing stairs, etc.
483 bool cave_valid_grid(cave_type *c_ptr)
485 s16b this_o_idx, next_o_idx = 0;
488 /* Forbid perma-grids */
489 if (cave_perma_grid(c_ptr)) return (FALSE);
492 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
497 o_ptr = &o_list[this_o_idx];
499 /* Acquire next object */
500 next_o_idx = o_ptr->next_o_idx;
502 /* Forbid artifact grids */
503 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
514 * Hack -- Legal monster codes
516 static cptr image_monster_hack = \
517 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
520 * Hack -- Legal monster codes for IBM pseudo-graphics
522 static cptr image_monster_hack_ibm = \
526 * Mega-Hack -- Hallucinatory monster
528 static void image_monster(byte *ap, char *cp)
530 int n = strlen(image_monster_hack);
532 /* Random symbol from set above */
535 /* Normal graphics */
536 if (!(streq(ANGBAND_SYS, "ibm")))
538 (*cp) = r_info[randint1(max_r_idx-1)].x_char;
539 (*ap) = r_info[randint1(max_r_idx-1)].x_attr;
542 /* IBM-pseudo graphics */
544 n = strlen(image_monster_hack_ibm);
545 (*cp) = (image_monster_hack_ibm[randint0(n)]);
548 (*ap) = randint1(15);
554 (*cp) = (image_monster_hack[randint0(n)]);
557 (*ap) = randint1(15);
564 * Hack -- Legal object codes
566 static cptr image_object_hack = \
567 "?/|\\\"!$()_-=[]{},~";
569 static cptr image_object_hack_ibm = \
573 * Mega-Hack -- Hallucinatory object
575 static void image_object(byte *ap, char *cp)
577 int n = strlen(image_object_hack);
581 if (!(streq(ANGBAND_SYS, "ibm")))
583 (*cp) = k_info[randint1(max_k_idx-1)].x_char;
584 (*ap) = k_info[randint1(max_k_idx-1)].x_attr;
588 n = strlen(image_object_hack_ibm);
589 (*cp) = (image_object_hack_ibm[randint0(n)]);
592 (*ap) = randint1(15);
597 (*cp) = (image_object_hack[randint0(n)]);
600 (*ap) = randint1(15);
607 * Hack -- Random hallucination
609 static void image_random(byte *ap, char *cp)
611 /* Normally, assume monsters */
612 if (randint0(100) < 75)
614 image_monster(ap, cp);
617 /* Otherwise, assume objects */
620 image_object(ap, cp);
625 * Not using graphical tiles for this feature?
627 #define is_ascii_graphics(C , A) \
628 (!(((C) & 0x80) && ((A) & 0x80)))
631 * The 16x16 tile of the terrain supports lighting
633 static bool feat_supports_lighting(byte feat)
635 if (is_trap(feat)) return TRUE;
654 case FEAT_WALL_EXTRA:
655 case FEAT_WALL_INNER:
656 case FEAT_WALL_OUTER:
657 case FEAT_WALL_SOLID:
658 case FEAT_PERM_EXTRA:
659 case FEAT_PERM_INNER:
660 case FEAT_PERM_OUTER:
661 case FEAT_PERM_SOLID:
662 case FEAT_MINOR_GLYPH:
663 case FEAT_DEEP_WATER:
664 case FEAT_SHAL_WATER:
671 case FEAT_DEEP_GRASS:
682 * This array lists the effects of "brightness" on various "base" colours.
684 * This is used to do dynamic lighting effects in ascii :-)
685 * At the moment, only the various "floor" tiles are affected.
687 * The layout of the array is [x][0] = light and [x][1] = dark.
690 static byte lighting_colours[16][2] =
693 {TERM_L_DARK, TERM_DARK},
696 {TERM_YELLOW, TERM_SLATE},
699 {TERM_WHITE, TERM_L_DARK},
702 {TERM_L_UMBER, TERM_UMBER},
705 {TERM_RED, TERM_RED},
708 {TERM_L_GREEN, TERM_GREEN},
711 {TERM_BLUE, TERM_BLUE},
714 {TERM_L_UMBER, TERM_RED},
717 {TERM_SLATE, TERM_L_DARK},
720 {TERM_WHITE, TERM_SLATE},
723 {TERM_L_RED, TERM_BLUE},
726 {TERM_YELLOW, TERM_ORANGE},
729 {TERM_L_RED, TERM_L_RED},
732 {TERM_L_GREEN, TERM_GREEN},
735 {TERM_L_BLUE, TERM_L_BLUE},
738 {TERM_L_UMBER, TERM_UMBER}
742 * Extract the attr/char to display at the given (legal) map location
744 * Basically, we "paint" the chosen attr/char in several passes, starting
745 * with any known "terrain features" (defaulting to darkness), then adding
746 * any known "objects", and finally, adding any known "monsters". This
747 * is not the fastest method but since most of the calls to this function
748 * are made for grids with no monsters or objects, it is fast enough.
750 * Note that this function, if used on the grid containing the "player",
751 * will return the attr/char of the grid underneath the player, and not
752 * the actual player attr/char itself, allowing a lot of optimization
753 * in various "display" functions.
755 * Note that the "zero" entry in the feature/object/monster arrays are
756 * used to provide "special" attr/char codes, with "monster zero" being
757 * used for the player attr/char, "object zero" being used for the "stack"
758 * attr/char, and "feature zero" being used for the "nothing" attr/char,
759 * though this function makes use of only "feature zero".
761 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
762 * which means their color changes, and "ATTR_CLEAR", which means they take
763 * the color of whatever is under them, and "CHAR_CLEAR", which means that
764 * they take the symbol of whatever is under them. Technically, the flag
765 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
766 * examined, but this flag is currently ignored.
768 * Currently, we do nothing with multi-hued objects, because there are
769 * not any. If there were, they would have to set "shimmer_objects"
770 * when they were created, and then new "shimmer" code in "dungeon.c"
771 * would have to be created handle the "shimmer" effect, and the code
772 * in "cave.c" would have to be updated to create the shimmer effect.
774 * Note the effects of hallucination. Objects always appear as random
775 * "objects", monsters as random "monsters", and normal grids occasionally
776 * appear as random "monsters" or "objects", but note that these random
777 * "monsters" and "objects" are really just "colored ascii symbols".
779 * Note that "floors" and "invisible traps" (and "zero" features) are
780 * drawn as "floors" using a special check for optimization purposes,
781 * and these are the only features which get drawn using the special
782 * lighting effects activated by "view_special_lite".
784 * Note the use of the "mimic" field in the "terrain feature" processing,
785 * which allows any feature to "pretend" to be another feature. This is
786 * used to "hide" secret doors, and to make all "doors" appear the same,
787 * and all "walls" appear the same, and "hidden" treasure stay hidden.
788 * It is possible to use this field to make a feature "look" like a floor,
789 * but the "special lighting effects" for floors will not be used.
791 * Note the use of the new "terrain feature" information. Note that the
792 * assumption that all interesting "objects" and "terrain features" are
793 * memorized allows extremely optimized processing below. Note the use
794 * of separate flags on objects to mark them as memorized allows a grid
795 * to have memorized "terrain" without granting knowledge of any object
796 * which may appear in that grid.
798 * Note the efficient code used to determine if a "floor" grid is
799 * "memorized" or "viewable" by the player, where the test for the
800 * grid being "viewable" is based on the facts that (1) the grid
801 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
802 * line of sight, and (3) the player must not be blind, and uses the
803 * assumption that all torch-lit grids are in line of sight.
805 * Note that floors (and invisible traps) are the only grids which are
806 * not memorized when seen, so only these grids need to check to see if
807 * the grid is "viewable" to the player (if it is not memorized). Since
808 * most non-memorized grids are in fact walls, this induces *massive*
809 * efficiency, at the cost of *forcing* the memorization of non-floor
810 * grids when they are first seen. Note that "invisible traps" are
811 * always treated exactly like "floors", which prevents "cheating".
813 * Note the "special lighting effects" which can be activated for floor
814 * grids using the "view_special_lite" option (for "white" floor grids),
815 * causing certain grids to be displayed using special colors. If the
816 * player is "blind", we will use "dark gray", else if the grid is lit
817 * by the torch, and the "view_yellow_lite" option is set, we will use
818 * "yellow", else if the grid is "dark", we will use "dark gray", else
819 * if the grid is not "viewable", and the "view_bright_lite" option is
820 * set, and the we will use "slate" (gray). We will use "white" for all
821 * other cases, in particular, for illuminated viewable floor grids.
823 * Note the "special lighting effects" which can be activated for wall
824 * grids using the "view_granite_lite" option (for "white" wall grids),
825 * causing certain grids to be displayed using special colors. If the
826 * player is "blind", we will use "dark gray", else if the grid is lit
827 * by the torch, and the "view_yellow_lite" option is set, we will use
828 * "yellow", else if the "view_bright_lite" option is set, and the grid
829 * is not "viewable", or is "dark", or is glowing, but not when viewed
830 * from the player's current location, we will use "slate" (gray). We
831 * will use "white" for all other cases, in particular, for correctly
832 * illuminated viewable wall grids.
834 * Note that, when "view_granite_lite" is set, we use an inline version
835 * of the "player_can_see_bold()" function to check the "viewability" of
836 * grids when the "view_bright_lite" option is set, and we do NOT use
837 * any special colors for "dark" wall grids, since this would allow the
838 * player to notice the walls of illuminated rooms from a hallway that
839 * happened to run beside the room. The alternative, by the way, would
840 * be to prevent the generation of hallways next to rooms, but this
841 * would still allow problems when digging towards a room.
843 * Note that bizarre things must be done when the "attr" and/or "char"
844 * codes have the "high-bit" set, since these values are used to encode
845 * various "special" pictures in some versions, and certain situations,
846 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
847 * to be "scrambled" in various ways.
849 * Note that eventually we may use the "&" symbol for embedded treasure,
850 * and use the "*" symbol to indicate multiple objects, though this will
851 * have to wait for Angband 2.8.0 or later. Note that currently, this
852 * is not important, since only one object or terrain feature is allowed
853 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
855 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
856 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
857 * then a whole lot of code should be changed... XXX XXX
859 #ifdef USE_TRANSPARENCY
860 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
861 #else /* USE_TRANSPARENCY */
862 void map_info(int y, int x, byte *ap, char *cp)
863 #endif /* USE_TRANSPARENCY */
869 s16b this_o_idx, next_o_idx = 0;
883 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
885 /* Memorized (or visible) floor */
886 if ((c_ptr->info & CAVE_MARK) ||
887 (((c_ptr->info & CAVE_LITE) || (c_ptr->info & CAVE_MNLT) ||
888 ((c_ptr->info & CAVE_GLOW) &&
889 (c_ptr->info & CAVE_VIEW))) &&
893 f_ptr = &f_info[feat];
901 /* Special lighting effects */
902 if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_graphics))
910 * feat_supports_lighting(feat)
911 * is always TRUE here
914 /* Use a dark tile */
919 /* Use "dark gray" */
924 /* Handle "torch-lit" grids */
925 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
928 if (view_yellow_lite && !p_ptr->wild_mode)
933 * feat_supports_lighting(feat)
934 * is always TRUE here
937 /* Use a brightly lit tile */
948 /* Handle "dark" grids */
949 else if (!(c_ptr->info & CAVE_GLOW))
954 * feat_supports_lighting(feat)
955 * is always TRUE here
958 /* Use a dark tile */
963 /* Use "dark gray" */
968 /* Handle "out-of-sight" grids */
969 else if (!(c_ptr->info & CAVE_VIEW))
972 if (view_bright_lite && !p_ptr->wild_mode)
977 * feat_supports_lighting(feat)
978 * is always TRUE here
981 /* Use a dark tile */
999 /* Access darkness */
1000 f_ptr = &f_info[feat];
1013 /* Memorized grids */
1014 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || new_ascii_graphics))
1016 /* Apply "mimic" field */
1018 feat = c_ptr->mimic;
1020 feat = f_info[feat].mimic;
1022 /* Access feature */
1023 f_ptr = &f_info[feat];
1031 if (new_ascii_graphics)
1033 /* Handle "blind" */
1036 if (is_ascii_graphics(c,a))
1038 /* Use darkened colour */
1039 a = lighting_colours[a][1];
1041 else if (use_graphics && feat_supports_lighting(feat))
1043 /* Use a dark tile */
1048 /* Handle "torch-lit" grids */
1049 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1052 if (view_yellow_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1054 if (is_ascii_graphics(c,a))
1056 /* Use lightened colour */
1057 a = lighting_colours[a][0];
1059 else if (use_graphics &&
1060 feat_supports_lighting(c_ptr->feat))
1062 /* Use a brightly lit tile */
1068 /* Handle "view_bright_lite" */
1069 else if (view_bright_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1072 if (!(c_ptr->info & CAVE_VIEW))
1074 if (is_ascii_graphics(c,a))
1076 /* Use darkened colour */
1077 a = lighting_colours[a][1];
1079 else if (use_graphics && feat_supports_lighting(feat))
1081 /* Use a dark tile */
1087 else if (!(c_ptr->info & CAVE_GLOW))
1089 if (is_ascii_graphics(c,a))
1091 /* Use darkened colour */
1092 a = lighting_colours[a][1];
1097 /* Special lighting effects */
1098 else if (view_granite_lite && !p_ptr->wild_mode &&
1099 (((a == TERM_WHITE) && !use_graphics) ||
1100 (use_graphics && feat_supports_lighting(c_ptr->feat))))
1102 /* Handle "blind" */
1107 /* Use a dark tile */
1112 /* Use "dark gray" */
1117 /* Handle "torch-lit" grids */
1118 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1121 if (view_yellow_lite && !p_ptr->wild_mode)
1125 /* Use a brightly lit tile */
1136 /* Handle "view_bright_lite" */
1137 else if (view_bright_lite && !p_ptr->wild_mode)
1140 if (!(c_ptr->info & CAVE_VIEW))
1144 /* Use a dark tile */
1155 else if (!(c_ptr->info & CAVE_GLOW))
1159 /* Use a lit tile */
1168 /* Not glowing correctly */
1173 /* Hack -- move towards player */
1174 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1175 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1177 /* Check for "local" illumination */
1178 if (!(cave[yy][xx].info & CAVE_GLOW))
1182 /* Use a lit tile */
1195 /* "Simple Lighting" */
1198 /* Handle "blind" */
1199 if (!(c_ptr->info & CAVE_MARK))
1204 /* Access feature */
1205 f_ptr = &f_info[feat];
1215 if (feat_priority == -1)
1226 case FEAT_TRAP_TRAPDOOR:
1228 case FEAT_TRAP_SPIKED_PIT:
1229 case FEAT_TRAP_POISON_PIT:
1230 case FEAT_TRAP_TY_CURSE:
1231 case FEAT_TRAP_TELEPORT:
1232 case FEAT_TRAP_FIRE:
1233 case FEAT_TRAP_ACID:
1234 case FEAT_TRAP_SLOW:
1235 case FEAT_TRAP_LOSE_STR:
1236 case FEAT_TRAP_LOSE_DEX:
1237 case FEAT_TRAP_LOSE_CON:
1238 case FEAT_TRAP_BLIND:
1239 case FEAT_TRAP_CONFUSE:
1240 case FEAT_TRAP_POISON:
1241 case FEAT_TRAP_SLEEP:
1242 case FEAT_TRAP_TRAPS:
1243 case FEAT_TRAP_ALARM:
1247 case FEAT_DEEP_GRASS:
1256 case FEAT_WALL_EXTRA:
1257 case FEAT_WALL_INNER:
1258 case FEAT_WALL_OUTER:
1259 case FEAT_WALL_SOLID:
1260 case FEAT_DEEP_WATER:
1261 case FEAT_SHAL_WATER:
1262 case FEAT_DEEP_LAVA:
1263 case FEAT_SHAL_LAVA:
1273 case FEAT_PERM_EXTRA:
1274 case FEAT_PERM_INNER:
1275 case FEAT_PERM_OUTER:
1276 case FEAT_PERM_SOLID:
1280 /* default is feat_priority = 20; (doors and stores) */
1283 case FEAT_MINOR_GLYPH:
1285 case FEAT_PATTERN_START:
1286 case FEAT_PATTERN_1:
1287 case FEAT_PATTERN_2:
1288 case FEAT_PATTERN_3:
1289 case FEAT_PATTERN_4:
1290 case FEAT_PATTERN_END:
1291 case FEAT_PATTERN_OLD:
1292 case FEAT_PATTERN_XTRA1:
1293 case FEAT_PATTERN_XTRA2:
1297 /* objects have feat_priority = 20 */
1298 /* monsters have feat_priority = 30 */
1302 case FEAT_QUEST_ENTER:
1303 case FEAT_QUEST_EXIT:
1304 case FEAT_QUEST_DOWN:
1306 case FEAT_LESS_LESS:
1307 case FEAT_MORE_MORE:
1319 #ifdef USE_TRANSPARENCY
1320 /* Save the terrain info for the transparency effects */
1323 #endif /* USE_TRANSPARENCY */
1329 /* Hack -- rare random hallucination, except on outer dungeon walls */
1330 if (p_ptr->image && (c_ptr->feat < FEAT_PERM_SOLID) && !randint0(256))
1333 image_random(ap, cp);
1337 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1341 /* Acquire object */
1342 o_ptr = &o_list[this_o_idx];
1344 /* Acquire next object */
1345 next_o_idx = o_ptr->next_o_idx;
1347 /* Memorized objects */
1350 if (display_autopick)
1354 match_autopick = is_autopick(o_ptr);
1355 if(match_autopick == -1)
1358 act = autopick_list[match_autopick].action;
1360 if ((act & DO_DISPLAY) && (act & display_autopick))
1362 autopick_obj = o_ptr;
1366 match_autopick = -1;
1371 (*cp) = object_char(o_ptr);
1374 (*ap) = object_attr(o_ptr);
1378 /* Hack -- hallucination */
1379 if (p_ptr->image) image_object(ap, cp);
1387 /* Handle monsters */
1388 if (c_ptr->m_idx && display_autopick == 0 )
1390 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1392 /* Visible monster */
1395 monster_race *r_ptr;
1396 r_ptr = &r_info[m_ptr->ap_r_idx];
1406 /* Mimics' colors vary */
1407 if (strchr("\"!=", c) && !(r_ptr->flags1 & RF1_UNIQUE))
1412 /* Use semi-random attr */
1413 (*ap) = c_ptr->m_idx % 15 + 1;
1416 /* Special attr/char codes */
1417 else if ((a & 0x80) && (c & 0x80))
1426 /* Multi-hued monster */
1427 else if (r_ptr->flags1 & (RF1_ATTR_MULTI))
1429 /* Is it a shapechanger? */
1430 if (r_ptr->flags2 & (RF2_SHAPECHANGER))
1434 if (!(streq(ANGBAND_SYS, "ibm")))
1436 (*cp) = r_info[randint1(max_r_idx-1)].x_char;
1437 (*ap) = r_info[randint1(max_r_idx-1)].x_attr;
1441 int n = strlen(image_monster_hack_ibm);
1442 (*cp) = (image_monster_hack_ibm[randint0(n)]);
1445 (*ap) = randint1(15);
1450 (*cp) = (one_in_(25) ?
1451 image_object_hack[randint0(strlen(image_object_hack))] :
1452 image_monster_hack[randint0(strlen(image_monster_hack))]);
1458 /* Multi-hued attr */
1459 if (r_ptr->flags2 & RF2_ATTR_ANY)
1460 (*ap) = randint1(15);
1461 else switch (randint1(7))
1473 (*ap) = TERM_L_GREEN;
1479 (*ap) = TERM_L_DARK;
1487 /* Normal monster (not "clear" in any way) */
1488 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR | RF1_CHAR_CLEAR)))
1497 /* Hack -- Bizarre grid under monster */
1498 else if ((*ap & 0x80) || (*cp & 0x80))
1510 /* Normal (non-clear char) monster */
1511 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR)))
1517 /* Normal (non-clear attr) monster */
1518 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR)))
1525 /* Hack -- hallucination */
1528 /* Hallucinatory monster */
1529 image_monster(ap, cp);
1534 /* Handle "player" */
1535 if ((y == py) && (x == px))
1537 monster_race *r_ptr = &r_info[0];
1541 /* Get the "player" attr */
1544 /* Get the "player" char */
1547 #ifdef VARIABLE_PLAYER_GRAPH
1549 if (!streq(ANGBAND_GRAF, "new"))
1551 if (streq(ANGBAND_SYS,"ibm"))
1553 if (use_graphics && player_symbols)
1555 if (p_ptr->psex == SEX_FEMALE) c = (char)242;
1556 switch (p_ptr->pclass)
1559 if (p_ptr->lev < 20)
1565 case CLASS_WARRIOR_MAGE:
1566 case CLASS_RED_MAGE:
1567 if (p_ptr->lev < 20)
1572 case CLASS_CHAOS_WARRIOR:
1577 while (a == TERM_DARK);
1580 case CLASS_HIGH_MAGE:
1581 case CLASS_SORCERER:
1582 case CLASS_MAGIC_EATER:
1583 case CLASS_BLUE_MAGE:
1584 if (p_ptr->lev < 20)
1592 if (p_ptr->lev < 20)
1600 if (p_ptr->lev < 20)
1607 if (p_ptr->lev < 20)
1614 case CLASS_BERSERKER:
1616 if (p_ptr->lev < 20)
1622 case CLASS_MINDCRAFTER:
1623 case CLASS_FORCETRAINER:
1624 case CLASS_MIRROR_MASTER:
1625 if (p_ptr->lev < 20)
1631 default: /* Unknown */
1635 switch (p_ptr->prace)
1647 case RACE_HALF_TROLL:
1657 case RACE_HALF_OGRE:
1660 case RACE_HALF_GIANT:
1661 case RACE_HALF_TITAN:
1680 case RACE_DRACONIAN:
1681 if (p_ptr->lev < 20)
1683 else if (p_ptr->lev < 40)
1688 case RACE_MIND_FLAYER:
1699 if (p_ptr->pclass == CLASS_MAGE ||
1700 p_ptr->pclass == CLASS_PRIEST ||
1701 p_ptr->pclass == CLASS_HIGH_MAGE ||
1702 p_ptr->pclass == CLASS_SORCERER ||
1703 p_ptr->pclass == CLASS_MONK ||
1704 p_ptr->pclass == CLASS_FORCETRAINER ||
1705 p_ptr->pclass == CLASS_BLUE_MAGE ||
1706 p_ptr->pclass == CLASS_MIRROR_MASTER ||
1707 p_ptr->pclass == CLASS_MINDCRAFTER)
1741 #endif /* VARIABLE_PLAYER_GRAPH */
1749 * Table of Ascii-to-Zenkaku
1750 * ¡Ö¢£¡×¤ÏÆóÇÜÉýƦÉå¤ÎÆâÉô¥³¡¼¥É¤Ë»ÈÍÑ¡£
1752 static char ascii_to_zenkaku[2*128+1] = "\
1753 ¡¡¡ª¡É¡ô¡ð¡ó¡õ¡Ç¡Ê¡Ë¡ö¡Ü¡¤¡Ý¡¥¡¿\
1754 £°£±£²£³£´£µ£¶£·£¸£¹¡§¡¨¡ã¡á¡ä¡©\
1755 ¡÷£Á£Â£Ã£Ä£Å£Æ£Ç£È£É£Ê£Ë£Ì£Í£Î£Ï\
1756 £Ð£Ñ£Ò£Ó£Ô£Õ£Ö£×£Ø£Ù£Ú¡Î¡À¡Ï¡°¡²\
1757 ¡Æ£á£â£ã£ä£å£æ£ç£è£é£ê£ë£ì£í£î£ï\
1758 £ð£ñ£ò£ó£ô£õ£ö£÷£ø£ù£ú¡Ð¡Ã¡Ñ¡Á¢£";
1762 * Prepare Bigtile or 2-bytes character attr/char pairs
1764 static void bigtile_attr(char *cp, byte *ap, char *cp2, byte *ap2)
1774 if (isprint(*cp) || *cp == 127)
1776 *ap2 = (*ap) | 0xf0;
1777 *cp2 = ascii_to_zenkaku[2*(*cp-' ') + 1];
1778 *cp = ascii_to_zenkaku[2*(*cp-' ')];
1789 * Calculate panel colum of a location in the map
1791 static int panel_col_of(int col)
1793 col -= panel_col_min;
1794 if (use_bigtile) col *= 2;
1800 * Moves the cursor to a given MAP (y,x) location
1802 void move_cursor_relative(int row, int col)
1804 /* Real co-ords convert to screen positions */
1805 row -= panel_row_prt;
1808 Term_gotoxy(panel_col_of(col), row);
1814 * Place an attr/char pair at the given map coordinate, if legal.
1816 void print_rel(char c, byte a, int y, int x)
1821 /* Only do "legal" locations */
1822 if (panel_contains(y, x))
1824 /* Hack -- fake monochrome */
1825 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
1827 if (world_monster) a = TERM_DARK;
1828 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
1829 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
1830 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1833 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
1835 /* Draw the char using the attr */
1836 Term_draw(panel_col_of(x), y-panel_row_prt, a, c);
1838 Term_draw(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
1847 * Memorize interesting viewable object/features in the given grid
1849 * This function should only be called on "legal" grids.
1851 * This function will memorize the object and/or feature in the given
1852 * grid, if they are (1) viewable and (2) interesting. Note that all
1853 * objects are interesting, all terrain features except floors (and
1854 * invisible traps) are interesting, and floors (and invisible traps)
1855 * are interesting sometimes (depending on various options involving
1856 * the illumination of floor grids).
1858 * The automatic memorization of all objects and non-floor terrain
1859 * features as soon as they are displayed allows incredible amounts
1860 * of optimization in various places, especially "map_info()".
1862 * Note that the memorization of objects is completely separate from
1863 * the memorization of terrain features, preventing annoying floor
1864 * memorization when a detected object is picked up from a dark floor,
1865 * and object memorization when an object is dropped into a floor grid
1866 * which is memorized but out-of-sight.
1868 * This function should be called every time the "memorization" of
1869 * a grid (or the object in a grid) is called into question, such
1870 * as when an object is created in a grid, when a terrain feature
1871 * "changes" from "floor" to "non-floor", when any grid becomes
1872 * "illuminated" or "viewable", and when a "floor" grid becomes
1875 * Note the relatively efficient use of this function by the various
1876 * "update_view()" and "update_lite()" calls, to allow objects and
1877 * terrain features to be memorized (and drawn) whenever they become
1878 * viewable or illuminated in any way, but not when they "maintain"
1879 * or "lose" their previous viewability or illumination.
1881 * Note the butchered "internal" version of "player_can_see_bold()",
1882 * optimized primarily for the most common cases, that is, for the
1883 * non-marked floor grids.
1885 void note_spot(int y, int x)
1887 cave_type *c_ptr = &cave[y][x];
1889 s16b this_o_idx, next_o_idx = 0;
1892 /* Blind players see nothing */
1893 if (p_ptr->blind) return;
1895 /* Analyze non-torch-lit grids */
1896 if (!(c_ptr->info & (CAVE_LITE)))
1898 /* Require line of sight to the grid */
1899 if (!(c_ptr->info & (CAVE_VIEW))) return;
1901 if (p_ptr->pclass != CLASS_NINJA)
1903 /* Require "perma-lite" of the grid */
1904 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return;
1909 /* Hack -- memorize objects */
1910 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1912 object_type *o_ptr = &o_list[this_o_idx];
1914 /* Acquire next object */
1915 next_o_idx = o_ptr->next_o_idx;
1917 /* Memorize objects */
1918 o_ptr->marked = TRUE;
1922 /* Hack -- memorize grids */
1923 if (!(c_ptr->info & (CAVE_MARK)))
1925 if (p_ptr->pclass == CLASS_NINJA)
1927 c_ptr->info |= (CAVE_MARK);
1929 /* Handle floor grids first */
1930 if ((c_ptr->feat <= FEAT_INVIS) || (c_ptr->feat == FEAT_DIRT) || (c_ptr->feat == FEAT_GRASS))
1932 /* Option -- memorize all torch-lit floors */
1933 if (view_torch_grids && (c_ptr->info & (CAVE_LITE)))
1936 c_ptr->info |= (CAVE_MARK);
1939 /* Option -- memorize all perma-lit floors */
1940 else if (view_perma_grids && (c_ptr->info & (CAVE_GLOW)))
1943 c_ptr->info |= (CAVE_MARK);
1947 /* Memorize normal grids */
1948 else if (cave_floor_grid(c_ptr))
1951 c_ptr->info |= (CAVE_MARK);
1954 /* Memorize torch-lit walls */
1955 else if (c_ptr->info & (CAVE_LITE))
1958 c_ptr->info |= (CAVE_MARK);
1961 /* Memorize certain non-torch-lit wall grids */
1966 /* Hack -- move one grid towards player */
1967 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1968 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1970 /* Check for "local" illumination */
1971 if (cave[yy][xx].info & (CAVE_GLOW))
1974 c_ptr->info |= (CAVE_MARK);
1981 void display_dungeon(void)
1987 #ifdef USE_TRANSPARENCY
1990 #endif /* USE_TRANSPARENCY */
1992 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1994 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1996 if (in_bounds2(y, x))
1999 #ifdef USE_TRANSPARENCY
2000 /* Examine the grid */
2001 map_info(y, x, &a, &c, &ta, &tc);
2002 #else /* USE_TRANSPARENCY */
2003 /* Examine the grid */
2004 map_info(y, x, &a, &c);
2005 #endif /* USE_TRANSPARENCY */
2007 /* Hack -- fake monochrome */
2008 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2010 if (world_monster) a = TERM_DARK;
2011 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2012 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2013 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2016 #ifdef USE_TRANSPARENCY
2017 /* Hack -- Queue it */
2018 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2019 #else /* USE_TRANSPARENCY */
2020 /* Hack -- Queue it */
2021 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2022 #endif /* USE_TRANSPARENCY */
2027 /* Clear out-of-bound tiles */
2029 /* Access darkness */
2030 feature_type *f_ptr = &f_info[FEAT_NONE];
2038 #ifdef USE_TRANSPARENCY
2039 /* Hack -- Queue it */
2040 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2041 #else /* USE_TRANSPARENCY */
2042 /* Hack -- Queue it */
2043 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2044 #endif /* USE_TRANSPARENCY */
2052 * Redraw (on the screen) a given MAP location
2054 * This function should only be called on "legal" grids
2056 void lite_spot(int y, int x)
2058 /* Redraw if on screen */
2059 if (panel_contains(y, x) && in_bounds2(y, x))
2064 #ifdef USE_TRANSPARENCY
2068 /* Examine the grid */
2069 map_info(y, x, &a, &c, &ta, &tc);
2070 #else /* USE_TRANSPARENCY */
2071 /* Examine the grid */
2072 map_info(y, x, &a, &c);
2073 #endif /* USE_TRANSPARENCY */
2075 /* Hack -- fake monochrome */
2076 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2078 if (world_monster) a = TERM_DARK;
2079 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2080 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2081 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2085 if (use_bigtile && !(a & 0x80) && (isprint(c) || c == 127))
2087 /* Term_queue_chars ¤ÏÁ´³ÑASCIIÃÏ·Á¤òÀµ¤·¤¯update¤¹¤ë¡£ */
2088 Term_queue_chars(panel_col_of(x), y-panel_row_prt, 2, a, &ascii_to_zenkaku[2*(c-' ')]);
2093 #ifdef USE_TRANSPARENCY
2094 /* Hack -- Queue it */
2095 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
2097 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, 255, 0, 0);
2098 #else /* USE_TRANSPARENCY */
2099 /* Hack -- Queue it */
2100 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
2102 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, 255);
2103 #endif /* USE_TRANSPARENCY */
2109 * Prints the map of the dungeon
2111 * Note that, for efficiency, we contain an "optimized" version
2112 * of both "lite_spot()" and "print_rel()", and that we use the
2113 * "lite_spot()" function to display the player grid, if needed.
2121 s16b xmin, xmax, ymin, ymax;
2125 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2128 Term_get_size(&wid, &hgt);
2130 /* Remove map offset */
2134 /* Access the cursor state */
2135 (void)Term_get_cursor(&v);
2137 /* Hide the cursor */
2138 (void)Term_set_cursor(0);
2141 xmin = (0 < panel_col_min) ? panel_col_min : 0;
2142 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
2143 ymin = (0 < panel_row_min) ? panel_row_min : 0;
2144 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
2146 /* Bottom section of screen */
2147 for (y = 1; y <= ymin - panel_row_prt; y++)
2149 /* Erase the section */
2150 Term_erase(COL_MAP, y, wid);
2153 /* Top section of screen */
2154 for (y = ymax - panel_row_prt; y <= hgt; y++)
2156 /* Erase the section */
2157 Term_erase(COL_MAP, y, wid);
2161 for (y = ymin; y <= ymax; y++)
2163 /* Scan the columns of row "y" */
2164 for (x = xmin; x <= xmax; x++)
2169 #ifdef USE_TRANSPARENCY
2173 /* Determine what is there */
2174 map_info(y, x, &a, &c, &ta, &tc);
2176 /* Determine what is there */
2177 map_info(y, x, &a, &c);
2180 /* Hack -- fake monochrome */
2181 if (fake_monochrome)
2183 if (world_monster) a = TERM_DARK;
2184 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2185 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2186 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2189 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2191 /* Efficiency -- Redraw that grid of the map */
2192 #ifdef USE_TRANSPARENCY
2193 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
2194 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2, 0, 0);
2196 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
2197 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
2202 /* Display player */
2205 /* Restore the cursor */
2206 (void)Term_set_cursor(v);
2212 * print project path
2214 void prt_path(int y, int x)
2219 int default_color = TERM_SLATE;
2220 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2222 if (!display_path) return;
2223 if (-1 == project_length)
2226 /* Get projection path */
2227 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2230 p_ptr->redraw |= (PR_MAP);
2236 for (i = 0; i < path_n; i++)
2238 int ny = GRID_Y(path_g[i]);
2239 int nx = GRID_X(path_g[i]);
2241 if (panel_contains(ny, nx))
2243 byte a2, a = default_color;
2246 #ifdef USE_TRANSPARENCY
2251 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2253 /* Determine what is there */
2254 #ifdef USE_TRANSPARENCY
2255 map_info(ny, nx, &a, &c, &ta, &tc);
2257 map_info(ny, nx, &a, &c);
2261 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2263 else if (a == default_color)
2267 if (fake_monochrome)
2269 if (world_monster) a = TERM_DARK;
2270 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2271 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2272 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2276 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2278 /* Hack -- Queue it */
2279 #ifdef USE_TRANSPARENCY
2280 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
2281 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2, 0, 0);
2283 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c);
2284 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2);
2289 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2292 if (nx == x && ny == y) default_color = TERM_L_DARK;
2297 static cptr simplify_list[][2] =
2304 {"^Amulet of ", "\""},
2305 {"^Scroll of ", "?"},
2306 {"^Scroll titled ", "?"},
2307 {"^Wand of " , "-"},
2309 {"^Staff of " , "_"},
2310 {"^Potion of ", "!"},
2322 static void display_shortened_item_name(object_type *o_ptr, int y)
2329 object_desc(buf, o_ptr, FALSE, 0);
2330 attr = tval_to_attr[o_ptr->tval % 128];
2336 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
2338 strcpy(buf, "something strange");
2342 for (c = buf; *c; c++)
2345 for (i = 0; simplify_list[i][1]; i++)
2347 cptr org_w = simplify_list[i][0];
2357 if (!strncmp(c, org_w, strlen(org_w)))
2360 cptr tmp = simplify_list[i][1];
2363 tmp = c + strlen(org_w);
2373 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2379 if(len + 2 > 12) break;
2386 if(len + 1 > 12) break;
2392 Term_putstr(0, y, 12, attr, buf);
2396 * Display a "small-scale" map of the dungeon in the active Term
2398 void display_map(int *cy, int *cx)
2415 /* Save lighting effects */
2416 bool old_view_special_lite = view_special_lite;
2417 bool old_view_granite_lite = view_granite_lite;
2419 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2421 int hgt, wid, yrat, xrat;
2423 int **match_autopick_yx;
2424 object_type ***object_autopick_yx;
2427 Term_get_size(&wid, &hgt);
2430 if (use_bigtile) wid /= 2;
2432 yrat = (cur_hgt + hgt - 1) / hgt;
2433 xrat = (cur_wid + wid - 1) / wid;
2435 /* Disable lighting effects */
2436 view_special_lite = FALSE;
2437 view_granite_lite = FALSE;
2439 /* Allocate the maps */
2440 C_MAKE(ma, (hgt + 2), byte_ptr);
2441 C_MAKE(mc, (hgt + 2), char_ptr);
2442 C_MAKE(mp, (hgt + 2), byte_ptr);
2443 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2444 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2446 /* Allocate and wipe each line map */
2447 for (y = 0; y < (hgt + 2); y++)
2449 /* Allocate one row each array */
2450 C_MAKE(ma[y], (wid + 2), byte);
2451 C_MAKE(mc[y], (wid + 2), char);
2452 C_MAKE(mp[y], (wid + 2), byte);
2453 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2454 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2456 for (x = 0; x < wid + 2; ++x)
2458 match_autopick_yx[y][x] = -1;
2459 object_autopick_yx[y][x] = NULL;
2462 ma[y][x] = TERM_WHITE;
2470 /* Allocate the maps */
2471 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
2472 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
2473 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
2475 /* Allocate and wipe each line map */
2476 for (y = 0; y < (cur_hgt + 2); y++)
2478 /* Allocate one row each array */
2479 C_MAKE(bigma[y], (cur_wid + 2), byte);
2480 C_MAKE(bigmc[y], (cur_wid + 2), char);
2481 C_MAKE(bigmp[y], (cur_wid + 2), byte);
2483 for (x = 0; x < cur_wid + 2; ++x)
2486 bigma[y][x] = TERM_WHITE;
2494 /* Fill in the map */
2495 for (i = 0; i < cur_wid; ++i)
2497 for (j = 0; j < cur_hgt; ++j)
2507 /* Extract the current attr/char at that map location */
2508 #ifdef USE_TRANSPARENCY
2509 map_info(j, i, &ta, &tc, &ta, &tc);
2510 #else /* USE_TRANSPARENCY */
2511 map_info(j, i, &ta, &tc);
2512 #endif /* USE_TRANSPARENCY */
2514 /* Extract the priority */
2517 if(match_autopick!=-1
2518 && (match_autopick_yx[y][x] == -1
2519 || match_autopick_yx[y][x] > match_autopick))
2521 match_autopick_yx[y][x] = match_autopick;
2522 object_autopick_yx[y][x] = autopick_obj;
2526 /* Save the char, attr and priority */
2527 bigmc[j+1][i+1] = tc;
2528 bigma[j+1][i+1] = ta;
2529 bigmp[j+1][i+1] = tp;
2533 for (j = 0; j < cur_hgt; ++j)
2535 for (i = 0; i < cur_wid; ++i)
2541 tc = bigmc[j+1][i+1];
2542 ta = bigma[j+1][i+1];
2543 tp = bigmp[j+1][i+1];
2545 /* rare feature has more priority */
2551 for (t = 0; t < 8; t++)
2553 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2554 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2564 /* Save the char, attr and priority */
2577 /* Draw the corners */
2578 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2580 /* Draw the horizontal edges */
2581 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2583 /* Draw the vertical edges */
2584 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2587 /* Display each map line in order */
2588 for (y = 0; y < hgt + 2; ++y)
2590 /* Start a new line */
2591 Term_gotoxy(COL_MAP, y);
2593 /* Display the line */
2594 for (x = 0; x < wid + 2; ++x)
2599 /* Hack -- fake monochrome */
2600 if (fake_monochrome)
2602 if (world_monster) ta = TERM_DARK;
2603 else if (p_ptr->invuln || world_player) ta = TERM_WHITE;
2604 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) ta = TERM_WHITE;
2605 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2608 if (use_bigtile) bigtile_attr(&tc, &ta, &c2, &a2);
2610 /* Add the character */
2612 if (use_bigtile) Term_addch(a2, c2);
2617 for (y = 1; y < hgt + 1; ++y)
2619 match_autopick = -1;
2620 for (x = 1; x <= wid; x++){
2621 if (match_autopick_yx[y][x] != -1 &&
2622 (match_autopick > match_autopick_yx[y][x] ||
2623 match_autopick == -1)){
2624 match_autopick = match_autopick_yx[y][x];
2625 autopick_obj = object_autopick_yx[y][x];
2629 /* Clear old display */
2630 Term_putstr(0, y, 12, 0, " ");
2632 if (match_autopick != -1)
2634 display_shortened_item_name(autopick_obj, y);
2637 char buf[13] = "\0";
2638 strncpy(buf,autopick_list[match_autopick].name,12);
2646 /* Player location */
2647 (*cy) = py / yrat + 1 + ROW_MAP;
2649 (*cx) = px / xrat + 1 + COL_MAP;
2651 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2653 /* Restore lighting effects */
2654 view_special_lite = old_view_special_lite;
2655 view_granite_lite = old_view_granite_lite;
2657 /* Free each line map */
2658 for (y = 0; y < (hgt + 2); y++)
2660 /* Free one row each array */
2661 C_FREE(ma[y], (wid + 2), byte);
2662 C_FREE(mc[y], (wid + 2), char);
2663 C_FREE(mp[y], (wid + 2), byte);
2664 C_FREE(match_autopick_yx[y], (wid + 2), int);
2665 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2668 /* Free each line map */
2669 C_FREE(ma, (hgt + 2), byte_ptr);
2670 C_FREE(mc, (hgt + 2), char_ptr);
2671 C_FREE(mp, (hgt + 2), byte_ptr);
2672 C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2673 C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2675 /* Free each line map */
2676 for (y = 0; y < (cur_hgt + 2); y++)
2678 /* Free one row each array */
2679 C_FREE(bigma[y], (cur_wid + 2), byte);
2680 C_FREE(bigmc[y], (cur_wid + 2), char);
2681 C_FREE(bigmp[y], (cur_wid + 2), byte);
2684 /* Free each line map */
2685 C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2686 C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2687 C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2692 * Display a "small-scale" map of the dungeon for the player
2694 * Currently, the "player" is displayed on the map. XXX XXX XXX
2696 void do_cmd_view_map(void)
2701 /* Save the screen */
2706 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2708 prt("Please wait...", 0, 0);
2714 /* Clear the screen */
2717 display_autopick = 0;
2719 /* Display the map */
2720 display_map(&cy, &cx);
2723 if(max_autopick && !p_ptr->wild_mode)
2725 display_autopick = ITEM_DISPLAY;
2732 int wid, hgt, row_message;
2734 Term_get_size(&wid, &hgt);
2735 row_message = hgt - 1;
2738 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2740 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2743 /* Hilite the player */
2744 move_cursor(cy, cx);
2751 flag = DONT_AUTOPICK;
2753 flag = DO_AUTODESTROY;
2755 flag = (DO_AUTOPICK | DONT_AUTOPICK);
2761 if (~display_autopick & flag)
2762 display_autopick |= flag;
2764 display_autopick &= ~flag;
2765 /* Display the map */
2766 display_map(&cy, &cx);
2769 display_autopick = 0;
2775 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2777 put_str("Hit any key to continue", 23, 30);
2778 #endif /* Hilite the player */
2779 move_cursor(cy, cx);
2784 /* Restore the screen */
2793 * Some comments on the cave grid flags. -BEN-
2796 * One of the major bottlenecks in previous versions of Angband was in
2797 * the calculation of "line of sight" from the player to various grids,
2798 * such as monsters. This was such a nasty bottleneck that a lot of
2799 * silly things were done to reduce the dependancy on "line of sight",
2800 * for example, you could not "see" any grids in a lit room until you
2801 * actually entered the room, and there were all kinds of bizarre grid
2802 * flags to enable this behavior. This is also why the "call light"
2803 * spells always lit an entire room.
2805 * The code below provides functions to calculate the "field of view"
2806 * for the player, which, once calculated, provides extremely fast
2807 * calculation of "line of sight from the player", and to calculate
2808 * the "field of torch lite", which, again, once calculated, provides
2809 * extremely fast calculation of "which grids are lit by the player's
2810 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2811 * "GRID_LITE", as appropriate, these functions maintain an array for
2812 * each of these two flags, each array containing the locations of all
2813 * of the grids marked with the appropriate flag, which can be used to
2814 * very quickly scan through all of the grids in a given set.
2816 * To allow more "semantically valid" field of view semantics, whenever
2817 * the field of view (or the set of torch lit grids) changes, all of the
2818 * grids in the field of view (or the set of torch lit grids) are "drawn"
2819 * so that changes in the world will become apparent as soon as possible.
2820 * This has been optimized so that only grids which actually "change" are
2821 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2822 * of the grids which are entering or leaving the relevent set of grids.
2824 * These new methods are so efficient that the old nasty code was removed.
2826 * Note that there is no reason to "update" the "viewable space" unless
2827 * the player "moves", or walls/doors are created/destroyed, and there
2828 * is no reason to "update" the "torch lit grids" unless the field of
2829 * view changes, or the "light radius" changes. This means that when
2830 * the player is resting, or digging, or doing anything that does not
2831 * involve movement or changing the state of the dungeon, there is no
2832 * need to update the "view" or the "lite" regions, which is nice.
2834 * Note that the calls to the nasty "los()" function have been reduced
2835 * to a bare minimum by the use of the new "field of view" calculations.
2837 * I wouldn't be surprised if slight modifications to the "update_view()"
2838 * function would allow us to determine "reverse line-of-sight" as well
2839 * as "normal line-of-sight", which would allow monsters to use a more
2840 * "correct" calculation to determine if they can "see" the player. For
2841 * now, monsters simply "cheat" somewhat and assume that if the player
2842 * has "line of sight" to the monster, then the monster can "pretend"
2843 * that it has "line of sight" to the player.
2846 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2847 * grid and maintains an array of all "CAVE_LITE" grids.
2849 * This set of grids is the complete set of all grids which are lit by
2850 * the players light source, which allows the "player_can_see_bold()"
2851 * function to work very quickly.
2853 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2854 * fact, the player (unless blind) can always "see" all grids which are
2855 * marked as "CAVE_LITE", unless they are "off screen".
2858 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2859 * grid and maintains an array of all "CAVE_VIEW" grids.
2861 * This set of grids is the complete set of all grids within line of sight
2862 * of the player, allowing the "player_has_los_bold()" macro to work very
2866 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2867 * temporary internal flag to mark those grids which are not only in view,
2868 * but which are also "easily" in line of sight of the player. This flag
2869 * is always cleared when we are done.
2872 * The current "update_lite()" and "update_view()" algorithms use the
2873 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2874 * to keep track of which grids were previously marked as "CAVE_LITE" or
2875 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2877 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2878 * for various other purposes, such as spreading lite or darkness during
2879 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2882 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2883 * in some way permanently lit. However, for the player to "see" anything
2884 * in the grid, as determined by "player_can_see()", the player must not be
2885 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2886 * grids, even if marked as "perma lit", are only illuminated if they touch
2887 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2890 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2891 * that even if the player cannot "see" the grid, he "knows" the terrain in
2892 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2893 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2894 * or when one of the "memorize floor grids" options induces memorization.
2896 * Objects are "memorized" in a different way, using a special "marked" flag
2897 * on the object itself, which is set when an object is observed or detected.
2900 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2901 * and should be illuminated by "lite room" and "darkness" spells.
2904 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2905 * and should be unavailable for "teleportation" destinations.
2908 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2909 * which is observed, and the "view_torch_grids" allows the player to memorize
2910 * every torch-lit grid. The player will always memorize important walls,
2911 * doors, stairs, and other terrain features, as well as any "detected" grids.
2913 * Note that the new "update_view()" method allows, among other things, a room
2914 * to be "partially" seen as the player approaches it, with a growing cone of
2915 * floor appearing as the player gets closer to the door. Also, by not turning
2916 * on the "memorize perma-lit grids" option, the player will only "see" those
2917 * floor grids which are actually in line of sight.
2919 * And my favorite "plus" is that you can now use a special option to draw the
2920 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2921 * grids dimly), providing a "pretty" effect as the player runs around, and
2922 * to efficiently display the "torch lite" in a special color.
2925 * Some comments on the "update_view()" algorithm...
2927 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2928 * and only has to call "los()" on the borderline cases. The major axes/diags
2929 * even terminate early when they hit walls. I need to find a quick way
2930 * to "terminate" the other scans.
2932 * Note that in the worst case (a big empty area with say 5% scattered walls),
2933 * each of the 1500 or so nearby grids is checked once, most of them getting
2934 * an "instant" rating, and only a small portion requiring a call to "los()".
2936 * The only time that the algorithm appears to be "noticeably" too slow is
2937 * when running, and this is usually only important in town, since the town
2938 * provides about the worst scenario possible, with large open regions and
2939 * a few scattered obstructions. There is a special "efficiency" option to
2940 * allow the player to reduce his field of view in town, if needed.
2942 * In the "best" case (say, a normal stretch of corridor), the algorithm
2943 * makes one check for each viewable grid, and makes no calls to "los()".
2944 * So running in corridors is very fast, and if a lot of monsters are
2945 * nearby, it is much faster than the old methods.
2947 * Note that resting, most normal commands, and several forms of running,
2948 * plus all commands executed near large groups of monsters, are strictly
2949 * more efficient with "update_view()" that with the old "compute los() on
2950 * demand" method, primarily because once the "field of view" has been
2951 * calculated, it does not have to be recalculated until the player moves
2952 * (or a wall or door is created or destroyed).
2954 * Note that we no longer have to do as many "los()" checks, since once the
2955 * "view" region has been built, very few things cause it to be "changed"
2956 * (player movement, and the opening/closing of doors, changes in wall status).
2957 * Note that door/wall changes are only relevant when the door/wall itself is
2958 * in the "view" region.
2960 * The algorithm seems to only call "los()" from zero to ten times, usually
2961 * only when coming down a corridor into a room, or standing in a room, just
2962 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
2963 * we will be reducing the calls to "los()".
2965 * I am thinking in terms of an algorithm that "walks" from the central point
2966 * out to the maximal "distance", at each point, determining the "view" code
2967 * (above). For each grid not on a major axis or diagonal, the "view" code
2968 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
2969 * (the one along the nearest diagonal, and the one next to that one, see
2970 * "update_view_aux()"...).
2972 * We "memorize" the viewable space array, so that at the cost of under 3000
2973 * bytes, we reduce the time taken by "forget_view()" to one assignment for
2974 * each grid actually in the "viewable space". And for another 3000 bytes,
2975 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
2976 * are also used by other routines, thus reducing the cost to almost nothing.
2978 * A similar thing is done for "forget_lite()" in which case the savings are
2979 * much less, but save us from doing bizarre maintenance checking.
2981 * In the worst "normal" case (in the middle of the town), the reachable space
2982 * actually reaches to more than half of the largest possible "circle" of view,
2983 * or about 800 grids, and in the worse case (in the middle of a dungeon level
2984 * where all the walls have been removed), the reachable space actually reaches
2985 * the theoretical maximum size of just under 1500 grids.
2987 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2988 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
2989 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
2990 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2991 * entire possible space (including initialization) in one step per grid. If
2992 * we do the "clearing" as a separate step (and use an array of "view" grids),
2993 * then the clearing will take as many steps as grids that were viewed, and the
2994 * algorithm will be able to "stop" scanning at various points.
2995 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
3006 * Actually erase the entire "lite" array, redrawing every grid
3008 void forget_lite(void)
3012 /* None to forget */
3013 if (!lite_n) return;
3015 /* Clear them all */
3016 for (i = 0; i < lite_n; i++)
3021 /* Forget "LITE" flag */
3022 cave[y][x].info &= ~(CAVE_LITE);
3036 * This macro allows us to efficiently add a grid to the "lite" array,
3037 * note that we are never called for illegal grids, or for grids which
3038 * have already been placed into the "lite" array, and we are never
3039 * called when the "lite" array is full.
3041 #define cave_lite_hack(Y,X) \
3043 if (!(cave[Y][X].info & (CAVE_LITE))) { \
3044 cave[Y][X].info |= (CAVE_LITE); \
3045 lite_y[lite_n] = (Y); \
3046 lite_x[lite_n] = (X); \
3052 * Update the set of grids "illuminated" by the player's lite.
3054 * This routine needs to use the results of "update_view()"
3056 * Note that "blindness" does NOT affect "torch lite". Be careful!
3058 * We optimize most lites (all non-artifact lites) by using "obvious"
3059 * facts about the results of "small" lite radius, and we attempt to
3060 * list the "nearby" grids before the more "distant" ones in the
3061 * array of torch-lit grids.
3063 * We assume that "radius zero" lite is in fact no lite at all.
3065 * Torch Lantern Artifacts
3075 void update_lite(void)
3077 int i, x, y, min_x, max_x, min_y, max_y;
3078 int p = p_ptr->cur_lite;
3080 /*** Special case ***/
3082 /* Hack -- Player has no lite */
3085 /* Forget the old lite */
3088 /* Draw the player */
3093 /*** Save the old "lite" grids for later ***/
3095 /* Clear them all */
3096 for (i = 0; i < lite_n; i++)
3101 /* Mark the grid as not "lite" */
3102 cave[y][x].info &= ~(CAVE_LITE);
3104 /* Mark the grid as "seen" */
3105 cave[y][x].info |= (CAVE_TEMP);
3107 /* Add it to the "seen" set */
3117 /*** Collect the new "lite" grids ***/
3119 /* Radius 1 -- torch radius */
3123 cave_lite_hack(py, px);
3126 cave_lite_hack(py+1, px);
3127 cave_lite_hack(py-1, px);
3128 cave_lite_hack(py, px+1);
3129 cave_lite_hack(py, px-1);
3131 /* Diagonal grids */
3132 cave_lite_hack(py+1, px+1);
3133 cave_lite_hack(py+1, px-1);
3134 cave_lite_hack(py-1, px+1);
3135 cave_lite_hack(py-1, px-1);
3138 /* Radius 2 -- lantern radius */
3141 /* South of the player */
3142 if (cave_floor_bold(py+1, px))
3144 cave_lite_hack(py+2, px);
3145 cave_lite_hack(py+2, px+1);
3146 cave_lite_hack(py+2, px-1);
3149 /* North of the player */
3150 if (cave_floor_bold(py-1, px))
3152 cave_lite_hack(py-2, px);
3153 cave_lite_hack(py-2, px+1);
3154 cave_lite_hack(py-2, px-1);
3157 /* East of the player */
3158 if (cave_floor_bold(py, px+1))
3160 cave_lite_hack(py, px+2);
3161 cave_lite_hack(py+1, px+2);
3162 cave_lite_hack(py-1, px+2);
3165 /* West of the player */
3166 if (cave_floor_bold(py, px-1))
3168 cave_lite_hack(py, px-2);
3169 cave_lite_hack(py+1, px-2);
3170 cave_lite_hack(py-1, px-2);
3174 /* Radius 3+ -- artifact radius */
3179 /* Paranoia -- see "LITE_MAX" */
3182 /* South-East of the player */
3183 if (cave_floor_bold(py+1, px+1))
3185 cave_lite_hack(py+2, px+2);
3188 /* South-West of the player */
3189 if (cave_floor_bold(py+1, px-1))
3191 cave_lite_hack(py+2, px-2);
3194 /* North-East of the player */
3195 if (cave_floor_bold(py-1, px+1))
3197 cave_lite_hack(py-2, px+2);
3200 /* North-West of the player */
3201 if (cave_floor_bold(py-1, px-1))
3203 cave_lite_hack(py-2, px-2);
3208 if (min_y < 0) min_y = 0;
3212 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3216 if (min_x < 0) min_x = 0;
3220 if (max_x > cur_wid-1) max_x = cur_wid-1;
3222 /* Scan the maximal box */
3223 for (y = min_y; y <= max_y; y++)
3225 for (x = min_x; x <= max_x; x++)
3227 int dy = (py > y) ? (py - y) : (y - py);
3228 int dx = (px > x) ? (px - x) : (x - px);
3230 /* Skip the "central" grids (above) */
3231 if ((dy <= 2) && (dx <= 2)) continue;
3233 /* Hack -- approximate the distance */
3234 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3236 /* Skip distant grids */
3237 if (d > p) continue;
3239 /* Viewable, nearby, grids get "torch lit" */
3240 if (player_has_los_bold(y, x))
3242 /* This grid is "torch lit" */
3243 cave_lite_hack(y, x);
3250 /*** Complete the algorithm ***/
3252 /* Draw the new grids */
3253 for (i = 0; i < lite_n; i++)
3258 /* Update fresh grids */
3259 if (cave[y][x].info & (CAVE_TEMP)) continue;
3268 /* Clear them all */
3269 for (i = 0; i < temp_n; i++)
3274 /* No longer in the array */
3275 cave[y][x].info &= ~(CAVE_TEMP);
3277 /* Update stale grids */
3278 if (cave[y][x].info & (CAVE_LITE)) continue;
3289 static bool mon_invis;
3292 * Add a square to the changes array
3294 static void mon_lite_hack(int y, int x)
3299 if (!in_bounds2(y, x)) return;
3301 c_ptr = &cave[y][x];
3303 /* Want a unlit square in view of the player */
3304 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3306 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3307 if (!cave_floor_grid(c_ptr) && mon_invis) return;
3309 /* Save this square */
3310 if (temp_n < TEMP_MAX)
3318 c_ptr->info |= CAVE_MNLT;
3325 * Update squares illuminated by monsters.
3327 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3328 * denote squares illuminated by monsters.
3330 * The CAVE_TEMP flag is used to store the state during the
3331 * updating. Only squares in view of the player, whos state
3332 * changes are drawn via lite_spot().
3334 void update_mon_lite(void)
3343 /* Clear all monster lit squares */
3344 for (i = 0; i < mon_lite_n; i++)
3347 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3350 c_ptr->info |= (CAVE_TEMP);
3352 /* Clear monster illumination flag */
3353 c_ptr->info &= ~(CAVE_MNLT);
3356 /* Empty temp list of new squares to lite up */
3359 /* Loop through monsters, adding newly lit squares to changes list */
3360 for (i = 1; i < m_max; i++)
3362 monster_type *m_ptr = &m_list[i];
3363 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3365 /* Skip dead monsters */
3366 if (!m_ptr->r_idx) continue;
3368 /* Is it too far away? */
3369 if (m_ptr->cdis > ((d_info[dungeon_type].flags1 & DF1_DARKNESS) ? MAX_SIGHT / 2 + 1 : MAX_SIGHT + 3)) continue;
3371 /* Get lite radius */
3374 /* Note the radii are cumulative */
3375 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3376 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3378 /* Exit if has no light */
3380 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3382 if (world_monster) continue;
3384 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3386 /* Access the location */
3390 /* Is the monster visible? */
3391 mon_invis = !(cave[fy][fx].info & CAVE_VIEW);
3393 /* The square it is on */
3394 mon_lite_hack(fy, fx);
3396 /* Adjacent squares */
3397 mon_lite_hack(fy + 1, fx);
3398 mon_lite_hack(fy - 1, fx);
3399 mon_lite_hack(fy, fx + 1);
3400 mon_lite_hack(fy, fx - 1);
3401 mon_lite_hack(fy + 1, fx + 1);
3402 mon_lite_hack(fy + 1, fx - 1);
3403 mon_lite_hack(fy - 1, fx + 1);
3404 mon_lite_hack(fy - 1, fx - 1);
3409 /* South of the monster */
3410 if (cave_floor_bold(fy + 1, fx))
3412 mon_lite_hack(fy + 2, fx + 1);
3413 mon_lite_hack(fy + 2, fx);
3414 mon_lite_hack(fy + 2, fx - 1);
3416 c_ptr = &cave[fy + 2][fx];
3419 if ((rad == 3) && cave_floor_grid(c_ptr))
3421 mon_lite_hack(fy + 3, fx + 1);
3422 mon_lite_hack(fy + 3, fx);
3423 mon_lite_hack(fy + 3, fx - 1);
3427 /* North of the monster */
3428 if (cave_floor_bold(fy - 1, fx))
3430 mon_lite_hack(fy - 2, fx + 1);
3431 mon_lite_hack(fy - 2, fx);
3432 mon_lite_hack(fy - 2, fx - 1);
3434 c_ptr = &cave[fy - 2][fx];
3437 if ((rad == 3) && cave_floor_grid(c_ptr))
3439 mon_lite_hack(fy - 3, fx + 1);
3440 mon_lite_hack(fy - 3, fx);
3441 mon_lite_hack(fy - 3, fx - 1);
3445 /* East of the monster */
3446 if (cave_floor_bold(fy, fx + 1))
3448 mon_lite_hack(fy + 1, fx + 2);
3449 mon_lite_hack(fy, fx + 2);
3450 mon_lite_hack(fy - 1, fx + 2);
3452 c_ptr = &cave[fy][fx + 2];
3455 if ((rad == 3) && cave_floor_grid(c_ptr))
3457 mon_lite_hack(fy + 1, fx + 3);
3458 mon_lite_hack(fy, fx + 3);
3459 mon_lite_hack(fy - 1, fx + 3);
3463 /* West of the monster */
3464 if (cave_floor_bold(fy, fx - 1))
3466 mon_lite_hack(fy + 1, fx - 2);
3467 mon_lite_hack(fy, fx - 2);
3468 mon_lite_hack(fy - 1, fx - 2);
3470 c_ptr = &cave[fy][fx - 2];
3473 if ((rad == 3) && cave_floor_grid(c_ptr))
3475 mon_lite_hack(fy + 1, fx - 3);
3476 mon_lite_hack(fy, fx - 3);
3477 mon_lite_hack(fy - 1, fx - 3);
3485 /* South-East of the monster */
3486 if (cave_floor_bold(fy + 1, fx + 1))
3488 mon_lite_hack(fy + 2, fx + 2);
3491 /* South-West of the monster */
3492 if (cave_floor_bold(fy + 1, fx - 1))
3494 mon_lite_hack(fy + 2, fx - 2);
3497 /* North-East of the monster */
3498 if (cave_floor_bold(fy - 1, fx + 1))
3500 mon_lite_hack(fy - 2, fx + 2);
3503 /* North-West of the monster */
3504 if (cave_floor_bold(fy - 1, fx - 1))
3506 mon_lite_hack(fy - 2, fx - 2);
3511 /* Save end of list of new squares */
3515 * Look at old set flags to see if there are any changes.
3517 for (i = 0; i < mon_lite_n; i++)
3522 if (!in_bounds2(fy, fx)) continue;
3525 c_ptr = &cave[fy][fx];
3527 /* It it no longer lit? */
3528 if (!(c_ptr->info & CAVE_MNLT) && player_has_los_grid(c_ptr))
3530 /* It is now unlit */
3535 /* Add to end of temp array */
3536 temp_x[temp_n] = (byte)fx;
3537 temp_y[temp_n] = (byte)fy;
3541 /* Clear the lite array */
3544 /* Copy the temp array into the lit array lighting the new squares. */
3545 for (i = 0; i < temp_n; i++)
3550 if (!in_bounds2(fy, fx)) continue;
3553 c_ptr = &cave[fy][fx];
3557 /* Clear the temp flag for the old lit grids */
3558 c_ptr->info &= ~(CAVE_TEMP);
3562 /* The is the square newly lit and visible? */
3563 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3570 /* Save in the monster lit array */
3571 mon_lite_x[mon_lite_n] = fx;
3572 mon_lite_y[mon_lite_n] = fy;
3577 /* Finished with temp_n */
3580 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3582 if (p_ptr->special_defense & NINJA_S_STEALTH)
3584 if (p_ptr->old_monlite != p_ptr->monlite)
3589 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3591 msg_print("Your mantle of shadow become thin.");
3597 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3599 msg_print("Your mantle of shadow restored its original darkness.");
3604 p_ptr->old_monlite = p_ptr->monlite;
3607 void clear_mon_lite(void)
3612 /* Clear all monster lit squares */
3613 for (i = 0; i < mon_lite_n; i++)
3616 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3618 /* Clear monster illumination flag */
3619 c_ptr->info &= ~(CAVE_MNLT);
3622 /* Empty the array */
3629 * Clear the viewable space
3631 void forget_view(void)
3637 /* None to forget */
3638 if (!view_n) return;
3640 /* Clear them all */
3641 for (i = 0; i < view_n; i++)
3646 /* Access the grid */
3647 c_ptr = &cave[y][x];
3649 /* Forget that the grid is viewable */
3650 c_ptr->info &= ~(CAVE_VIEW);
3652 if (!panel_contains(y, x)) continue;
3654 /* Update the screen */
3665 * This macro allows us to efficiently add a grid to the "view" array,
3666 * note that we are never called for illegal grids, or for grids which
3667 * have already been placed into the "view" array, and we are never
3668 * called when the "view" array is full.
3670 #define cave_view_hack(C,Y,X) \
3672 if (!((C)->info & (CAVE_VIEW))){\
3673 (C)->info |= (CAVE_VIEW); \
3674 view_y[view_n] = (Y); \
3675 view_x[view_n] = (X); \
3682 * Helper function for "update_view()" below
3684 * We are checking the "viewability" of grid (y,x) by the player.
3686 * This function assumes that (y,x) is legal (i.e. on the map).
3688 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3689 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3691 * Note that we are using the "CAVE_XTRA" field for marking grids as
3692 * "easily viewable". This bit is cleared at the end of "update_view()".
3694 * This function adds (y,x) to the "viewable set" if necessary.
3696 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3698 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3700 bool f1, f2, v1, v2, z1, z2, wall;
3704 cave_type *g1_c_ptr;
3705 cave_type *g2_c_ptr;
3707 /* Access the grids */
3708 g1_c_ptr = &cave[y1][x1];
3709 g2_c_ptr = &cave[y2][x2];
3712 /* Check for walls */
3713 f1 = (cave_floor_grid(g1_c_ptr));
3714 f2 = (cave_floor_grid(g2_c_ptr));
3716 /* Totally blocked by physical walls */
3717 if (!f1 && !f2) return (TRUE);
3720 /* Check for visibility */
3721 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3722 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3724 /* Totally blocked by "unviewable neighbors" */
3725 if (!v1 && !v2) return (TRUE);
3728 /* Access the grid */
3729 c_ptr = &cave[y][x];
3732 /* Check for walls */
3733 wall = (!cave_floor_grid(c_ptr));
3736 /* Check the "ease" of visibility */
3737 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3738 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3740 /* Hack -- "easy" plus "easy" yields "easy" */
3743 c_ptr->info |= (CAVE_XTRA);
3745 cave_view_hack(c_ptr, y, x);
3750 /* Hack -- primary "easy" yields "viewed" */
3753 cave_view_hack(c_ptr, y, x);
3758 /* Hack -- "view" plus "view" yields "view" */
3761 /* c_ptr->info |= (CAVE_XTRA); */
3763 cave_view_hack(c_ptr, y, x);
3769 /* Mega-Hack -- the "los()" function works poorly on walls */
3772 cave_view_hack(c_ptr, y, x);
3778 /* Hack -- check line of sight */
3779 if (los(py, px, y, x))
3781 cave_view_hack(c_ptr, y, x);
3787 /* Assume no line of sight. */
3794 * Calculate the viewable space
3796 * 1: Process the player
3797 * 1a: The player is always (easily) viewable
3798 * 2: Process the diagonals
3799 * 2a: The diagonals are (easily) viewable up to the first wall
3800 * 2b: But never go more than 2/3 of the "full" distance
3801 * 3: Process the main axes
3802 * 3a: The main axes are (easily) viewable up to the first wall
3803 * 3b: But never go more than the "full" distance
3804 * 4: Process sequential "strips" in each of the eight octants
3805 * 4a: Each strip runs along the previous strip
3806 * 4b: The main axes are "previous" to the first strip
3807 * 4c: Process both "sides" of each "direction" of each strip
3808 * 4c1: Each side aborts as soon as possible
3809 * 4c2: Each side tells the next strip how far it has to check
3811 * Note that the octant processing involves some pretty interesting
3812 * observations involving when a grid might possibly be viewable from
3813 * a given grid, and on the order in which the strips are processed.
3815 * Note the use of the mathematical facts shown below, which derive
3816 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3817 * hypotenuse of a right triangle is primarily determined by the length
3818 * of the longest side, when one side is small, and is strictly less
3819 * than one-and-a-half times as long as the longest side when both of
3820 * the sides are large.
3822 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3823 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3825 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3827 * These observations are important because the calculation of the actual
3828 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3829 * while for small values (up to about 20 or so), the approximations above
3830 * are correct to within an error of at most one grid or so.
3832 * Observe the use of "full" and "over" in the code below, and the use of
3833 * the specialized calculation involving "limit", all of which derive from
3834 * the observations given above. Basically, we note that the "circle" of
3835 * view is completely contained in an "octagon" whose bounds are easy to
3836 * determine, and that only a few steps are needed to derive the actual
3837 * bounds of the circle given the bounds of the octagon.
3839 * Note that by skipping all the grids in the corners of the octagon, we
3840 * place an upper limit on the number of grids in the field of view, given
3841 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3842 * view, only about 1475 of these are in the "octagon" of view, and even
3843 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3844 * entries to completely contain the actual field of view.
3846 * Note also the care taken to prevent "running off the map". The use of
3847 * explicit checks on the "validity" of the "diagonal", and the fact that
3848 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3849 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3850 * of multiple checks on the validity of grids.
3852 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3853 * "ws","wn" variables. They work like this: While travelling down the
3854 * south-bound strip just to the east of the main south axis, as soon as
3855 * we get to a grid which does not "transmit" viewing, if all of the strips
3856 * preceding us (in this case, just the main axis) had terminated at or before
3857 * the same point, then we can stop, and reset the "max distance" to ourself.
3858 * So, each strip (named by major axis plus offset, thus "se" in this case)
3859 * maintains a "blockage" variable, initialized during the main axis step,
3860 * and checks it whenever a blockage is observed. After processing each
3861 * strip as far as the previous strip told us to process, the next strip is
3862 * told not to go farther than the current strip's farthest viewable grid,
3863 * unless open space is still available. This uses the "k" variable.
3865 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3866 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3867 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3868 * chunk of code which adds the given location to the "view" array if it
3869 * is not already there, using both the actual location and a pointer to
3870 * the cave grid. See above.
3872 * By the way, the purpose of this code is to reduce the dependancy on the
3873 * "los()" function which is slow, and, in some cases, not very accurate.
3875 * It is very possible that I am the only person who fully understands this
3876 * function, and for that I am truly sorry, but efficiency was very important
3877 * and the "simple" version of this function was just not fast enough. I am
3878 * more than willing to replace this function with a simpler one, if it is
3879 * equally efficient, and especially willing if the new function happens to
3880 * derive "reverse-line-of-sight" at the same time, since currently monsters
3881 * just use an optimized hack of "you see me, so I see you", and then use the
3882 * actual "projectable()" function to check spell attacks.
3884 void update_view(void)
3886 int n, m, d, k, y, x, z;
3888 int se, sw, ne, nw, es, en, ws, wn;
3892 int y_max = cur_hgt - 1;
3893 int x_max = cur_wid - 1;
3897 /*** Initialize ***/
3900 if (view_reduce_view && !dun_level)
3902 /* Full radius (10) */
3903 full = MAX_SIGHT / 2;
3905 /* Octagon factor (15) */
3906 over = MAX_SIGHT * 3 / 4;
3912 /* Full radius (20) */
3915 /* Octagon factor (30) */
3916 over = MAX_SIGHT * 3 / 2;
3920 /*** Step 0 -- Begin ***/
3922 /* Save the old "view" grids for later */
3923 for (n = 0; n < view_n; n++)
3928 /* Access the grid */
3929 c_ptr = &cave[y][x];
3931 /* Mark the grid as not in "view" */
3932 c_ptr->info &= ~(CAVE_VIEW);
3934 /* Mark the grid as "seen" */
3935 c_ptr->info |= (CAVE_TEMP);
3937 /* Add it to the "seen" set */
3943 /* Start over with the "view" array */
3946 /*** Step 1 -- adjacent grids ***/
3948 /* Now start on the player */
3952 /* Access the grid */
3953 c_ptr = &cave[y][x];
3955 /* Assume the player grid is easily viewable */
3956 c_ptr->info |= (CAVE_XTRA);
3958 /* Assume the player grid is viewable */
3959 cave_view_hack(c_ptr, y, x);
3962 /*** Step 2 -- Major Diagonals ***/
3967 /* Scan south-east */
3968 for (d = 1; d <= z; d++)
3970 c_ptr = &cave[y+d][x+d];
3971 c_ptr->info |= (CAVE_XTRA);
3972 cave_view_hack(c_ptr, y+d, x+d);
3973 if (!cave_floor_grid(c_ptr)) break;
3976 /* Scan south-west */
3977 for (d = 1; d <= z; d++)
3979 c_ptr = &cave[y+d][x-d];
3980 c_ptr->info |= (CAVE_XTRA);
3981 cave_view_hack(c_ptr, y+d, x-d);
3982 if (!cave_floor_grid(c_ptr)) break;
3985 /* Scan north-east */
3986 for (d = 1; d <= z; d++)
3988 c_ptr = &cave[y-d][x+d];
3989 c_ptr->info |= (CAVE_XTRA);
3990 cave_view_hack(c_ptr, y-d, x+d);
3991 if (!cave_floor_grid(c_ptr)) break;
3994 /* Scan north-west */
3995 for (d = 1; d <= z; d++)
3997 c_ptr = &cave[y-d][x-d];
3998 c_ptr->info |= (CAVE_XTRA);
3999 cave_view_hack(c_ptr, y-d, x-d);
4000 if (!cave_floor_grid(c_ptr)) break;
4004 /*** Step 3 -- major axes ***/
4007 for (d = 1; d <= full; d++)
4009 c_ptr = &cave[y+d][x];
4010 c_ptr->info |= (CAVE_XTRA);
4011 cave_view_hack(c_ptr, y+d, x);
4012 if (!cave_floor_grid(c_ptr)) break;
4015 /* Initialize the "south strips" */
4019 for (d = 1; d <= full; d++)
4021 c_ptr = &cave[y-d][x];
4022 c_ptr->info |= (CAVE_XTRA);
4023 cave_view_hack(c_ptr, y-d, x);
4024 if (!cave_floor_grid(c_ptr)) break;
4027 /* Initialize the "north strips" */
4031 for (d = 1; d <= full; d++)
4033 c_ptr = &cave[y][x+d];
4034 c_ptr->info |= (CAVE_XTRA);
4035 cave_view_hack(c_ptr, y, x+d);
4036 if (!cave_floor_grid(c_ptr)) break;
4039 /* Initialize the "east strips" */
4043 for (d = 1; d <= full; d++)
4045 c_ptr = &cave[y][x-d];
4046 c_ptr->info |= (CAVE_XTRA);
4047 cave_view_hack(c_ptr, y, x-d);
4048 if (!cave_floor_grid(c_ptr)) break;
4051 /* Initialize the "west strips" */
4055 /*** Step 4 -- Divide each "octant" into "strips" ***/
4057 /* Now check each "diagonal" (in parallel) */
4058 for (n = 1; n <= over / 2; n++)
4060 int ypn, ymn, xpn, xmn;
4063 /* Acquire the "bounds" of the maximal circle */
4065 if (z > full - n) z = full - n;
4066 while ((z + n + (n>>1)) > full) z--;
4069 /* Access the four diagonal grids */
4079 /* Maximum distance */
4080 m = MIN(z, y_max - ypn);
4083 if ((xpn <= x_max) && (n < se))
4086 for (k = n, d = 1; d <= m; d++)
4088 /* Check grid "d" in strip "n", notice "blockage" */
4089 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
4091 if (n + d >= se) break;
4094 /* Track most distant "non-blockage" */
4101 /* Limit the next strip */
4106 if ((xmn >= 0) && (n < sw))
4109 for (k = n, d = 1; d <= m; d++)
4111 /* Check grid "d" in strip "n", notice "blockage" */
4112 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
4114 if (n + d >= sw) break;
4117 /* Track most distant "non-blockage" */
4124 /* Limit the next strip */
4133 /* Maximum distance */
4137 if ((xpn <= x_max) && (n < ne))
4140 for (k = n, d = 1; d <= m; d++)
4142 /* Check grid "d" in strip "n", notice "blockage" */
4143 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
4145 if (n + d >= ne) break;
4148 /* Track most distant "non-blockage" */
4155 /* Limit the next strip */
4160 if ((xmn >= 0) && (n < nw))
4163 for (k = n, d = 1; d <= m; d++)
4165 /* Check grid "d" in strip "n", notice "blockage" */
4166 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
4168 if (n + d >= nw) break;
4171 /* Track most distant "non-blockage" */
4178 /* Limit the next strip */
4187 /* Maximum distance */
4188 m = MIN(z, x_max - xpn);
4191 if ((ypn <= x_max) && (n < es))
4194 for (k = n, d = 1; d <= m; d++)
4196 /* Check grid "d" in strip "n", notice "blockage" */
4197 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
4199 if (n + d >= es) break;
4202 /* Track most distant "non-blockage" */
4209 /* Limit the next strip */
4214 if ((ymn >= 0) && (n < en))
4217 for (k = n, d = 1; d <= m; d++)
4219 /* Check grid "d" in strip "n", notice "blockage" */
4220 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4222 if (n + d >= en) break;
4225 /* Track most distant "non-blockage" */
4232 /* Limit the next strip */
4241 /* Maximum distance */
4245 if ((ypn <= y_max) && (n < ws))
4248 for (k = n, d = 1; d <= m; d++)
4250 /* Check grid "d" in strip "n", notice "blockage" */
4251 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4253 if (n + d >= ws) break;
4256 /* Track most distant "non-blockage" */
4263 /* Limit the next strip */
4268 if ((ymn >= 0) && (n < wn))
4271 for (k = n, d = 1; d <= m; d++)
4273 /* Check grid "d" in strip "n", notice "blockage" */
4274 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4276 if (n + d >= wn) break;
4279 /* Track most distant "non-blockage" */
4286 /* Limit the next strip */
4293 /*** Step 5 -- Complete the algorithm ***/
4295 /* Update all the new grids */
4296 for (n = 0; n < view_n; n++)
4301 /* Access the grid */
4302 c_ptr = &cave[y][x];
4304 /* Clear the "CAVE_XTRA" flag */
4305 c_ptr->info &= ~(CAVE_XTRA);
4307 /* Update only newly viewed grids */
4308 if (c_ptr->info & (CAVE_TEMP)) continue;
4317 /* Wipe the old grids, update as needed */
4318 for (n = 0; n < temp_n; n++)
4323 /* Access the grid */
4324 c_ptr = &cave[y][x];
4326 /* No longer in the array */
4327 c_ptr->info &= ~(CAVE_TEMP);
4329 /* Update only non-viewable grids */
4330 if (c_ptr->info & (CAVE_VIEW)) continue;
4346 * Hack -- provide some "speed" for the "flow" code
4347 * This entry is the "current index" for the "when" field
4348 * Note that a "when" value of "zero" means "not used".
4350 * Note that the "cost" indexes from 1 to 127 are for
4351 * "old" data, and from 128 to 255 are for "new" data.
4353 * This means that as long as the player does not "teleport",
4354 * then any monster up to 128 + MONSTER_FLOW_DEPTH will be
4355 * able to track down the player, and in general, will be
4356 * able to track down either the player or a position recently
4357 * occupied by the player.
4359 static int flow_n = 0;
4363 * Hack -- forget the "flow" information
4365 void forget_flow(void)
4369 /* Nothing to forget */
4370 if (!flow_n) return;
4372 /* Check the entire dungeon */
4373 for (y = 0; y < cur_hgt; y++)
4375 for (x = 0; x < cur_wid; x++)
4377 /* Forget the old data */
4378 cave[y][x].dist = 0;
4379 cave[y][x].cost = 0;
4380 cave[y][x].when = 0;
4390 * Hack - speed up the update_flow algorithm by only doing
4391 * it everytime the player moves out of LOS of the last
4394 static u16b flow_x = 0;
4395 static u16b flow_y = 0;
4400 * Hack -- fill in the "cost" field of every grid that the player
4401 * can "reach" with the number of steps needed to reach that grid.
4402 * This also yields the "distance" of the player from every grid.
4404 * In addition, mark the "when" of the grids that can reach
4405 * the player with the incremented value of "flow_n".
4407 * Hack -- use the "seen" array as a "circular queue".
4409 * We do not need a priority queue because the cost from grid
4410 * to grid is always "one" and we process them in order.
4412 void update_flow(void)
4418 /* Hack -- disabled */
4419 if (stupid_monsters) return;
4421 /* Paranoia -- make sure the array is empty */
4424 /* The last way-point is on the map */
4425 if (running && in_bounds(flow_y, flow_x))
4427 /* The way point is in sight - do not update. (Speedup) */
4428 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4431 /* Erase all of the current flow information */
4432 for (y = 0; y < cur_hgt; y++)
4434 for (x = 0; x < cur_wid; x++)
4436 cave[y][x].cost = 0;
4437 cave[y][x].dist = 0;
4441 /* Save player position */
4445 /* Add the player's grid to the queue */
4449 /* Now process the queue */
4450 while (flow_head != flow_tail)
4454 /* Extract the next entry */
4455 ty = temp_y[flow_tail];
4456 tx = temp_x[flow_tail];
4458 /* Forget that entry */
4459 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4461 /* Add the "children" */
4462 for (d = 0; d < 8; d++)
4464 int old_head = flow_head;
4465 int m = cave[ty][tx].cost + 1;
4466 int n = cave[ty][tx].dist + 1;
4469 /* Child location */
4470 y = ty + ddy_ddd[d];
4471 x = tx + ddx_ddd[d];
4473 /* Ignore player's grid */
4474 if (x == px && y == py) continue;
4476 c_ptr = &cave[y][x];
4478 if ((c_ptr->feat >= FEAT_DOOR_HEAD) && (c_ptr->feat <= FEAT_SECRET)) m += 3;
4480 /* Ignore "pre-stamped" entries */
4481 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4483 /* Ignore "walls" and "rubble" */
4484 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4486 /* Save the flow cost */
4487 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4488 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4490 /* Hack -- limit flow depth */
4491 if (n == MONSTER_FLOW_DEPTH) continue;
4493 /* Enqueue that entry */
4494 temp_y[flow_head] = y;
4495 temp_x[flow_head] = x;
4497 /* Advance the queue */
4498 if (++flow_head == TEMP_MAX) flow_head = 0;
4500 /* Hack -- notice overflow by forgetting new entry */
4501 if (flow_head == flow_tail) flow_head = old_head;
4507 static int scent_when = 0;
4510 * Characters leave scent trails for perceptive monsters to track.
4512 * Smell is rather more limited than sound. Many creatures cannot use
4513 * it at all, it doesn't extend very far outwards from the character's
4514 * current position, and monsters can use it to home in the character,
4515 * but not to run away from him.
4517 * Smell is valued according to age. When a character takes his turn,
4518 * scent is aged by one, and new scent of the current age is laid down.
4519 * Speedy characters leave more scent, true, but it also ages faster,
4520 * which makes it harder to hunt them down.
4522 * Whenever the age count loops, most of the scent trail is erased and
4523 * the age of the remainder is recalculated.
4525 void update_smell(void)
4530 /* Create a table that controls the spread of scent */
4531 const int scent_adjust[5][5] =
4540 /* Loop the age and adjust scent values when necessary */
4541 if (++scent_when == 254)
4543 /* Scan the entire dungeon */
4544 for (y = 0; y < cur_hgt; y++)
4546 for (x = 0; x < cur_wid; x++)
4548 int w = cave[y][x].when;
4549 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4558 /* Lay down new scent */
4559 for (i = 0; i < 5; i++)
4561 for (j = 0; j < 5; j++)
4565 /* Translate table to map grids */
4570 if (!in_bounds(y, x)) continue;
4572 c_ptr = &cave[y][x];
4574 /* Walls, water, and lava cannot hold scent. */
4575 if ((c_ptr->feat > FEAT_SECRET) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4577 /* Grid must not be blocked by walls from the character */
4578 if (!player_has_los_bold(y, x)) continue;
4580 /* Note grids that are too far away */
4581 if (scent_adjust[i][j] == -1) continue;
4583 /* Mark the grid with new scent */
4584 c_ptr->when = scent_when + scent_adjust[i][j];
4591 * Hack -- map the current panel (plus some) ala "magic mapping"
4593 void map_area(int range)
4599 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4601 /* Scan that area */
4602 for (y = 1; y < cur_hgt - 1; y++)
4604 for (x = 1; x < cur_wid - 1; x++)
4606 if (distance(py, px, y, x) > range) continue;
4608 c_ptr = &cave[y][x];
4610 /* All non-walls are "checked" */
4611 if ((c_ptr->feat < FEAT_SECRET) ||
4612 (c_ptr->feat == FEAT_RUBBLE) ||
4613 ((c_ptr->feat >= FEAT_MINOR_GLYPH) &&
4614 (c_ptr->feat <= FEAT_TREES)) ||
4615 (c_ptr->feat >= FEAT_TOWN))
4617 /* Memorize normal features */
4618 if ((c_ptr->feat > FEAT_INVIS) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4620 /* Memorize the object */
4621 c_ptr->info |= (CAVE_MARK);
4624 /* Memorize known walls */
4625 for (i = 0; i < 8; i++)
4627 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4629 /* Memorize walls (etc) */
4630 if ((c_ptr->feat >= FEAT_SECRET) && (c_ptr->feat != FEAT_DIRT) && (c_ptr->feat != FEAT_GRASS))
4632 /* Memorize the walls */
4633 c_ptr->info |= (CAVE_MARK);
4641 p_ptr->redraw |= (PR_MAP);
4644 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4650 * Light up the dungeon using "clairvoyance"
4652 * This function "illuminates" every grid in the dungeon, memorizes all
4653 * "objects", memorizes all grids as with magic mapping, and, under the
4654 * standard option settings (view_perma_grids but not view_torch_grids)
4655 * memorizes all floor grids too.
4657 * Note that if "view_perma_grids" is not set, we do not memorize floor
4658 * grids, since this would defeat the purpose of "view_perma_grids", not
4659 * that anyone seems to play without this option.
4661 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4662 * since this would prevent the use of "view_torch_grids" as a method to
4663 * keep track of what grids have been observed directly.
4665 void wiz_lite(bool wizard, bool ninja)
4669 /* Memorize objects */
4670 for (i = 1; i < o_max; i++)
4672 object_type *o_ptr = &o_list[i];
4674 /* Skip dead objects */
4675 if (!o_ptr->k_idx) continue;
4677 /* Skip held objects */
4678 if (o_ptr->held_m_idx) continue;
4681 /* Skip objects in vaults, if not a wizard. -LM- */
4682 if ((wizard == FALSE) &&
4683 (cave[o_ptr->iy][o_ptr->ix].info & (CAVE_ICKY))) continue;
4687 o_ptr->marked = TRUE;
4690 /* Scan all normal grids */
4691 for (y = 1; y < cur_hgt - 1; y++)
4693 /* Scan all normal grids */
4694 for (x = 1; x < cur_wid - 1; x++)
4696 cave_type *c_ptr = &cave[y][x];
4698 /* Process all non-walls */
4699 if (cave_floor_bold(y, x) || (c_ptr->feat == FEAT_RUBBLE) || (c_ptr->feat == FEAT_TREES) || (c_ptr->feat == FEAT_MOUNTAIN))
4701 /* Scan all neighbors */
4702 for (i = 0; i < 9; i++)
4704 int yy = y + ddy_ddd[i];
4705 int xx = x + ddx_ddd[i];
4708 c_ptr = &cave[yy][xx];
4710 /* Memorize normal features */
4713 /* Memorize the grid */
4714 c_ptr->info |= (CAVE_MARK);
4718 if ((c_ptr->feat > FEAT_INVIS))
4720 /* Memorize the grid */
4721 c_ptr->info |= (CAVE_MARK);
4724 /* Perma-lite the grid */
4725 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4727 c_ptr->info |= (CAVE_GLOW);
4729 /* Normally, memorize floors (see above) */
4730 if (view_perma_grids && !view_torch_grids)
4732 /* Memorize the grid */
4733 c_ptr->info |= (CAVE_MARK);
4742 /* Update the monsters */
4743 p_ptr->update |= (PU_MONSTERS);
4746 p_ptr->redraw |= (PR_MAP);
4749 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4754 * Forget the dungeon map (ala "Thinking of Maud...").
4761 /* Forget every grid */
4762 for (y = 0; y < cur_hgt; y++)
4764 for (x = 0; x < cur_wid; x++)
4766 cave_type *c_ptr = &cave[y][x];
4768 /* Process the grid */
4769 c_ptr->info &= ~(CAVE_MARK);
4773 /* Forget all objects */
4774 for (i = 1; i < o_max; i++)
4776 object_type *o_ptr = &o_list[i];
4778 /* Skip dead objects */
4779 if (!o_ptr->k_idx) continue;
4781 /* Skip held objects */
4782 if (o_ptr->held_m_idx) continue;
4784 /* Forget the object */
4785 o_ptr->marked = FALSE;
4788 /* Mega-Hack -- Forget the view and lite */
4789 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4791 /* Update the view and lite */
4792 p_ptr->update |= (PU_VIEW | PU_LITE);
4794 /* Update the monsters */
4795 p_ptr->update |= (PU_MONSTERS);
4798 p_ptr->redraw |= (PR_MAP);
4801 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4809 * Change the "feat" flag for a grid, and notice/redraw the grid
4811 void cave_set_feat(int y, int x, int feat)
4813 cave_type *c_ptr = &cave[y][x];
4815 /* Change the feature */
4828 * Calculate "incremental motion". Used by project() and shoot().
4829 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4831 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4833 int dy, dx, dist, shift;
4835 /* Extract the distance travelled */
4836 dy = (*y < y1) ? y1 - *y : *y - y1;
4837 dx = (*x < x1) ? x1 - *x : *x - x1;
4839 /* Number of steps */
4840 dist = (dy > dx) ? dy : dx;
4842 /* We are calculating the next location */
4846 /* Calculate the total distance along each axis */
4847 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4848 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4850 /* Paranoia -- Hack -- no motion */
4851 if (!dy && !dx) return;
4854 /* Move mostly vertically */
4857 /* Extract a shift factor */
4858 shift = (dist * dx + (dy - 1) / 2) / dy;
4860 /* Sometimes move along the minor axis */
4861 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4863 /* Always move along major axis */
4864 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4867 /* Move mostly horizontally */
4870 /* Extract a shift factor */
4871 shift = (dist * dy + (dx - 1) / 2) / dx;
4873 /* Sometimes move along the minor axis */
4874 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4876 /* Always move along major axis */
4877 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4884 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4885 * at the final destination, assuming no monster gets in the way.
4887 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4889 bool projectable(int y1, int x1, int y2, int x2)
4896 /* Check the projection path */
4897 grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, 0);
4899 /* No grid is ever projectable from itself */
4900 if (!grid_n) return (FALSE);
4903 y = GRID_Y(grid_g[grid_n - 1]);
4904 x = GRID_X(grid_g[grid_n - 1]);
4906 /* May not end in an unrequested grid */
4907 if ((y != y2) || (x != x2)) return (FALSE);
4915 * Standard "find me a location" function
4917 * Obtains a legal location within the given distance of the initial
4918 * location, and with "los()" from the source to destination location.
4920 * This function is often called from inside a loop which searches for
4921 * locations while increasing the "d" distance.
4923 * Currently the "m" parameter is unused.
4925 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4932 /* Pick a location */
4935 /* Pick a new location */
4936 ny = rand_spread(y, d);
4937 nx = rand_spread(x, d);
4939 /* Ignore annoying locations */
4940 if (!in_bounds(ny, nx)) continue;
4942 /* Ignore "excessively distant" locations */
4943 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4945 /* Require "line of sight" */
4946 if (los(y, x, ny, nx)) break;
4949 /* Save the location */
4958 * Track a new monster
4960 void health_track(int m_idx)
4962 /* Track a new guy */
4963 p_ptr->health_who = m_idx;
4965 /* Redraw (later) */
4966 p_ptr->redraw |= (PR_HEALTH);
4972 * Hack -- track the given monster race
4974 void monster_race_track(int r_idx)
4976 /* Save this monster ID */
4977 p_ptr->monster_race_idx = r_idx;
4980 p_ptr->window |= (PW_MONSTER);
4986 * Hack -- track the given object kind
4988 void object_kind_track(int k_idx)
4990 /* Save this monster ID */
4991 p_ptr->object_kind_idx = k_idx;
4994 p_ptr->window |= (PW_OBJECT);
5000 * Something has happened to disturb the player.
5002 * The first arg indicates a major disturbance, which affects search.
5004 * The second arg is currently unused, but could induce output flush.
5006 * All disturbance cancels repeated commands, resting, and running.
5008 void disturb(int stop_search, int unused_flag)
5011 unused_flag = unused_flag;
5013 /* Cancel auto-commands */
5014 /* command_new = 0; */
5016 /* Cancel repeated commands */
5022 /* Redraw the state (later) */
5023 p_ptr->redraw |= (PR_STATE);
5026 /* Cancel Resting */
5027 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5030 set_action(ACTION_NONE);
5033 /* Cancel running */
5039 /* Check for new panel if appropriate */
5040 if (center_player && !center_running) verify_panel();
5042 /* Calculate torch radius */
5043 p_ptr->update |= (PU_TORCH);
5045 /* Update monster flow */
5046 p_ptr->update |= (PU_FLOW);
5049 /* Flush the input if requested */
5050 if (flush_disturb) flush();