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:
80 case FEAT_TRAP_ARMAGEDDON:
81 case FEAT_TRAP_PIRANHA:
96 * Return TRUE if the given grid is a known trap
98 bool is_known_trap(cave_type *c_ptr)
100 if (!c_ptr->mimic && is_trap(c_ptr->feat)) return TRUE;
106 * Return TRUE if the given grid is a closed door
108 bool is_closed_door(int feat)
110 return (feat >= FEAT_DOOR_HEAD && feat <= FEAT_DOOR_TAIL);
115 * Return TRUE if the given grid is a hidden closed door
117 bool is_hidden_door(cave_type *c_ptr)
120 is_closed_door(c_ptr->feat))
128 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,
129 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.
131 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
133 * The LOS begins at the center of the tile (x1,y1) and ends at the center of
134 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line
135 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
137 * We assume that the "mathematical corner" of a non-floor tile does not
138 * block line of sight.
140 * Because this function uses (short) ints for all calculations, overflow may
141 * occur if dx and dy exceed 90.
143 * Once all the degenerate cases are eliminated, the values "qx", "qy", and
144 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
145 * we can use integer arithmetic.
147 * We travel from start to finish along the longer axis, starting at the border
148 * between the first and second tiles, where the y offset = .5 * slope, taking
149 * into account the scale factor. See below.
151 * Also note that this function and the "move towards target" code do NOT
152 * share the same properties. Thus, you can see someone, target them, and
153 * then fire a bolt at them, but the bolt may hit a wall, not them. However,
154 * by clever choice of target locations, you can sometimes throw a "curve".
156 * Note that "line of sight" is not "reflexive" in all cases.
158 * Use the "projectable()" routine to test "spell/missile line of sight".
160 * Use the "update_view()" function to determine player line-of-sight.
162 bool los(int y1, int x1, int y2, int x2)
182 /* Slope, or 1/Slope, of LOS */
186 /* Extract the offset */
190 /* Extract the absolute offset */
195 /* Handle adjacent (or identical) grids */
196 if ((ax < 2) && (ay < 2)) return (TRUE);
199 /* Paranoia -- require "safe" origin */
200 /* if (!in_bounds(y1, x1)) return (FALSE); */
201 /* if (!in_bounds(y2, x2)) return (FALSE); */
204 /* Directly South/North */
207 /* South -- check for walls */
210 for (ty = y1 + 1; ty < y2; ty++)
212 if (!cave_floor_bold(ty, x1)) return (FALSE);
216 /* North -- check for walls */
219 for (ty = y1 - 1; ty > y2; ty--)
221 if (!cave_floor_bold(ty, x1)) return (FALSE);
229 /* Directly East/West */
232 /* East -- check for walls */
235 for (tx = x1 + 1; tx < x2; tx++)
237 if (!cave_floor_bold(y1, tx)) return (FALSE);
241 /* West -- check for walls */
244 for (tx = x1 - 1; tx > x2; tx--)
246 if (!cave_floor_bold(y1, tx)) return (FALSE);
255 /* Extract some signs */
256 sx = (dx < 0) ? -1 : 1;
257 sy = (dy < 0) ? -1 : 1;
260 /* Vertical "knights" */
265 if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
269 /* Horizontal "knights" */
274 if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
279 /* Calculate scale factor div 2 */
282 /* Calculate scale factor */
286 /* Travel horizontally */
289 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
295 /* Consider the special case where slope == 1. */
306 /* Note (below) the case (qy == f2), where */
307 /* the LOS exactly meets the corner of a tile. */
310 if (!cave_floor_bold(ty, tx)) return (FALSE);
321 if (!cave_floor_bold(ty, tx)) return (FALSE);
334 /* Travel vertically */
337 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
353 /* Note (below) the case (qx == f2), where */
354 /* the LOS exactly meets the corner of a tile. */
357 if (!cave_floor_bold(ty, tx)) return (FALSE);
368 if (!cave_floor_bold(ty, tx)) return (FALSE);
391 * Can the player "see" the given grid in detail?
393 * He must have vision, illumination, and line of sight.
395 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
396 * So, given "CAVE_LITE", we know that the grid is "fully visible".
398 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
399 * that a wall is visible from any direction. That would be odd. Except
400 * under wizard light, which might make sense. Thus, for walls, we require
401 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
402 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
403 * in line of sight of the player.
405 * This extra check is expensive, but it provides a more "correct" semantics.
407 * Note that we should not run this check on walls which are "outer walls" of
408 * the dungeon, or we will induce a memory fault, but actually verifying all
409 * of the locations would be extremely expensive.
411 * Thus, to speed up the function, we assume that all "perma-walls" which are
412 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases
413 * except "vaults" and the "buildings" in town. But the town is a hack anyway,
414 * and the player has more important things on his mind when he is attacking a
415 * monster vault. It is annoying, but an extremely important optimization.
417 * Note that "glowing walls" are only considered to be "illuminated" if the
418 * grid which is next to the wall in the direction of the player is also a
419 * "glowing" grid. This prevents the player from being able to "see" the
420 * walls of illuminated rooms from a corridor outside the room.
422 bool player_can_see_bold(int y, int x)
428 /* Blind players see nothing */
429 if (p_ptr->blind) return (FALSE);
431 /* Access the cave grid */
434 /* Note that "torch-lite" yields "illumination" */
435 if (c_ptr->info & (CAVE_LITE)) return (TRUE);
437 /* Require line of sight to the grid */
438 if (!player_has_los_bold(y, x)) return (FALSE);
440 if (p_ptr->pclass == CLASS_NINJA) return TRUE;
442 /* Require "perma-lite" of the grid */
443 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return (FALSE);
445 /* Floors are simple */
446 if (cave_floor_bold(y, x)) return (TRUE);
448 /* Hack -- move towards player */
449 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
450 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
452 /* Check for "local" illumination */
453 if (cave[yy][xx].info & (CAVE_GLOW | CAVE_MNLT))
455 /* Assume the wall is really illuminated */
459 /* Assume not visible */
466 * Returns true if the player's grid is dark
470 return (!player_can_see_bold(py, px));
477 * Determine if a given location may be "destroyed"
479 * Used by destruction spells, and for placing stairs, etc.
481 bool cave_valid_bold(int y, int x)
483 cave_type *c_ptr = &cave[y][x];
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 * Determine if a given location may be "destroyed"
516 * Used by destruction spells, and for placing stairs, etc.
518 bool cave_valid_grid(cave_type *c_ptr)
520 s16b this_o_idx, next_o_idx = 0;
523 /* Forbid perma-grids */
524 if (cave_perma_grid(c_ptr)) return (FALSE);
527 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
532 o_ptr = &o_list[this_o_idx];
534 /* Acquire next object */
535 next_o_idx = o_ptr->next_o_idx;
537 /* Forbid artifact grids */
538 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
549 * Hack -- Legal monster codes
551 static cptr image_monster_hack = \
552 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
555 * Hack -- Legal monster codes for IBM pseudo-graphics
557 static cptr image_monster_hack_ibm = \
561 * Mega-Hack -- Hallucinatory monster
563 static void image_monster(byte *ap, char *cp)
565 int n = strlen(image_monster_hack);
567 /* Random symbol from set above */
570 /* Normal graphics */
571 if (!(streq(ANGBAND_SYS, "ibm")))
573 (*cp) = r_info[randint1(max_r_idx-1)].x_char;
574 (*ap) = r_info[randint1(max_r_idx-1)].x_attr;
577 /* IBM-pseudo graphics */
579 n = strlen(image_monster_hack_ibm);
580 (*cp) = (image_monster_hack_ibm[randint0(n)]);
583 (*ap) = randint1(15);
589 (*cp) = (image_monster_hack[randint0(n)]);
592 (*ap) = randint1(15);
599 * Hack -- Legal object codes
601 static cptr image_object_hack = \
602 "?/|\\\"!$()_-=[]{},~";
604 static cptr image_object_hack_ibm = \
608 * Mega-Hack -- Hallucinatory object
610 static void image_object(byte *ap, char *cp)
612 int n = strlen(image_object_hack);
616 if (!(streq(ANGBAND_SYS, "ibm")))
618 (*cp) = k_info[randint1(max_k_idx-1)].x_char;
619 (*ap) = k_info[randint1(max_k_idx-1)].x_attr;
623 n = strlen(image_object_hack_ibm);
624 (*cp) = (image_object_hack_ibm[randint0(n)]);
627 (*ap) = randint1(15);
632 (*cp) = (image_object_hack[randint0(n)]);
635 (*ap) = randint1(15);
642 * Hack -- Random hallucination
644 static void image_random(byte *ap, char *cp)
646 /* Normally, assume monsters */
647 if (randint0(100) < 75)
649 image_monster(ap, cp);
652 /* Otherwise, assume objects */
655 image_object(ap, cp);
660 * Not using graphical tiles for this feature?
662 #define is_ascii_graphics(C , A) \
663 (!(((C) & 0x80) && ((A) & 0x80)))
666 * The 16x16 tile of the terrain supports lighting
668 static bool feat_supports_lighting(byte feat)
670 if (is_trap(feat)) return streq(ANGBAND_GRAF, "new");
688 case FEAT_WALL_EXTRA:
689 case FEAT_WALL_INNER:
690 case FEAT_WALL_OUTER:
691 case FEAT_WALL_SOLID:
692 case FEAT_PERM_EXTRA:
693 case FEAT_PERM_INNER:
694 case FEAT_PERM_OUTER:
695 case FEAT_PERM_SOLID:
696 case FEAT_MINOR_GLYPH:
697 case FEAT_DEEP_WATER:
698 case FEAT_SHAL_WATER:
705 case FEAT_DEEP_GRASS:
716 * This array lists the effects of "brightness" on various "base" colours.
718 * This is used to do dynamic lighting effects in ascii :-)
719 * At the moment, only the various "floor" tiles are affected.
721 * The layout of the array is [x][0] = light and [x][1] = dark.
724 static byte lighting_colours[16][2] =
727 {TERM_L_DARK, TERM_DARK},
730 {TERM_YELLOW, TERM_SLATE},
733 {TERM_WHITE, TERM_L_DARK},
736 {TERM_L_UMBER, TERM_UMBER},
739 {TERM_RED, TERM_RED},
742 {TERM_L_GREEN, TERM_GREEN},
745 {TERM_BLUE, TERM_BLUE},
748 {TERM_L_UMBER, TERM_RED},
751 {TERM_SLATE, TERM_L_DARK},
754 {TERM_WHITE, TERM_SLATE},
757 {TERM_L_RED, TERM_BLUE},
760 {TERM_YELLOW, TERM_ORANGE},
763 {TERM_L_RED, TERM_L_RED},
766 {TERM_L_GREEN, TERM_GREEN},
769 {TERM_L_BLUE, TERM_L_BLUE},
772 {TERM_L_UMBER, TERM_UMBER}
776 * Extract the attr/char to display at the given (legal) map location
778 * Basically, we "paint" the chosen attr/char in several passes, starting
779 * with any known "terrain features" (defaulting to darkness), then adding
780 * any known "objects", and finally, adding any known "monsters". This
781 * is not the fastest method but since most of the calls to this function
782 * are made for grids with no monsters or objects, it is fast enough.
784 * Note that this function, if used on the grid containing the "player",
785 * will return the attr/char of the grid underneath the player, and not
786 * the actual player attr/char itself, allowing a lot of optimization
787 * in various "display" functions.
789 * Note that the "zero" entry in the feature/object/monster arrays are
790 * used to provide "special" attr/char codes, with "monster zero" being
791 * used for the player attr/char, "object zero" being used for the "stack"
792 * attr/char, and "feature zero" being used for the "nothing" attr/char,
793 * though this function makes use of only "feature zero".
795 * Note that monsters can have some "special" flags, including "ATTR_MULTI",
796 * which means their color changes, and "ATTR_CLEAR", which means they take
797 * the color of whatever is under them, and "CHAR_CLEAR", which means that
798 * they take the symbol of whatever is under them. Technically, the flag
799 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
800 * examined, but this flag is currently ignored.
802 * Currently, we do nothing with multi-hued objects, because there are
803 * not any. If there were, they would have to set "shimmer_objects"
804 * when they were created, and then new "shimmer" code in "dungeon.c"
805 * would have to be created handle the "shimmer" effect, and the code
806 * in "cave.c" would have to be updated to create the shimmer effect.
808 * Note the effects of hallucination. Objects always appear as random
809 * "objects", monsters as random "monsters", and normal grids occasionally
810 * appear as random "monsters" or "objects", but note that these random
811 * "monsters" and "objects" are really just "colored ascii symbols".
813 * Note that "floors" and "invisible traps" (and "zero" features) are
814 * drawn as "floors" using a special check for optimization purposes,
815 * and these are the only features which get drawn using the special
816 * lighting effects activated by "view_special_lite".
818 * Note the use of the "mimic" field in the "terrain feature" processing,
819 * which allows any feature to "pretend" to be another feature. This is
820 * used to "hide" secret doors, and to make all "doors" appear the same,
821 * and all "walls" appear the same, and "hidden" treasure stay hidden.
822 * It is possible to use this field to make a feature "look" like a floor,
823 * but the "special lighting effects" for floors will not be used.
825 * Note the use of the new "terrain feature" information. Note that the
826 * assumption that all interesting "objects" and "terrain features" are
827 * memorized allows extremely optimized processing below. Note the use
828 * of separate flags on objects to mark them as memorized allows a grid
829 * to have memorized "terrain" without granting knowledge of any object
830 * which may appear in that grid.
832 * Note the efficient code used to determine if a "floor" grid is
833 * "memorized" or "viewable" by the player, where the test for the
834 * grid being "viewable" is based on the facts that (1) the grid
835 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
836 * line of sight, and (3) the player must not be blind, and uses the
837 * assumption that all torch-lit grids are in line of sight.
839 * Note that floors (and invisible traps) are the only grids which are
840 * not memorized when seen, so only these grids need to check to see if
841 * the grid is "viewable" to the player (if it is not memorized). Since
842 * most non-memorized grids are in fact walls, this induces *massive*
843 * efficiency, at the cost of *forcing* the memorization of non-floor
844 * grids when they are first seen. Note that "invisible traps" are
845 * always treated exactly like "floors", which prevents "cheating".
847 * Note the "special lighting effects" which can be activated for floor
848 * grids using the "view_special_lite" option (for "white" floor grids),
849 * causing certain grids to be displayed using special colors. If the
850 * player is "blind", we will use "dark gray", else if the grid is lit
851 * by the torch, and the "view_yellow_lite" option is set, we will use
852 * "yellow", else if the grid is "dark", we will use "dark gray", else
853 * if the grid is not "viewable", and the "view_bright_lite" option is
854 * set, and the we will use "slate" (gray). We will use "white" for all
855 * other cases, in particular, for illuminated viewable floor grids.
857 * Note the "special lighting effects" which can be activated for wall
858 * grids using the "view_granite_lite" option (for "white" wall grids),
859 * causing certain grids to be displayed using special colors. If the
860 * player is "blind", we will use "dark gray", else if the grid is lit
861 * by the torch, and the "view_yellow_lite" option is set, we will use
862 * "yellow", else if the "view_bright_lite" option is set, and the grid
863 * is not "viewable", or is "dark", or is glowing, but not when viewed
864 * from the player's current location, we will use "slate" (gray). We
865 * will use "white" for all other cases, in particular, for correctly
866 * illuminated viewable wall grids.
868 * Note that, when "view_granite_lite" is set, we use an inline version
869 * of the "player_can_see_bold()" function to check the "viewability" of
870 * grids when the "view_bright_lite" option is set, and we do NOT use
871 * any special colors for "dark" wall grids, since this would allow the
872 * player to notice the walls of illuminated rooms from a hallway that
873 * happened to run beside the room. The alternative, by the way, would
874 * be to prevent the generation of hallways next to rooms, but this
875 * would still allow problems when digging towards a room.
877 * Note that bizarre things must be done when the "attr" and/or "char"
878 * codes have the "high-bit" set, since these values are used to encode
879 * various "special" pictures in some versions, and certain situations,
880 * such as "multi-hued" or "clear" monsters, cause the attr/char codes
881 * to be "scrambled" in various ways.
883 * Note that eventually we may use the "&" symbol for embedded treasure,
884 * and use the "*" symbol to indicate multiple objects, though this will
885 * have to wait for Angband 2.8.0 or later. Note that currently, this
886 * is not important, since only one object or terrain feature is allowed
887 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.
889 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
890 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
891 * then a whole lot of code should be changed... XXX XXX
893 #ifdef USE_TRANSPARENCY
894 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
895 #else /* USE_TRANSPARENCY */
896 void map_info(int y, int x, byte *ap, char *cp)
897 #endif /* USE_TRANSPARENCY */
903 s16b this_o_idx, next_o_idx = 0;
913 /* Feature code (applying "mimic" field) */
914 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
917 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
919 /* Memorized (or visible) floor */
920 if ((c_ptr->info & CAVE_MARK) ||
921 (((c_ptr->info & CAVE_LITE) || (c_ptr->info & CAVE_MNLT) ||
922 ((c_ptr->info & CAVE_GLOW) &&
923 (c_ptr->info & CAVE_VIEW))) &&
927 f_ptr = &f_info[feat];
935 /* Special lighting effects */
936 if (view_special_lite && (!p_ptr->wild_mode) && ((a == TERM_WHITE) || use_graphics))
944 * feat_supports_lighting(feat)
945 * is always TRUE here
948 /* Use a dark tile */
953 /* Use "dark gray" */
958 /* Handle "torch-lit" grids */
959 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
962 if (view_yellow_lite && !p_ptr->wild_mode)
967 * feat_supports_lighting(feat)
968 * is always TRUE here
971 /* Use a brightly lit tile */
982 /* Handle "dark" grids */
983 else if (!(c_ptr->info & CAVE_GLOW))
988 * feat_supports_lighting(feat)
989 * is always TRUE here
992 /* Use a dark tile */
997 /* Use "dark gray" */
1002 /* Handle "out-of-sight" grids */
1003 else if (!(c_ptr->info & CAVE_VIEW))
1006 if (view_bright_lite && !p_ptr->wild_mode)
1011 * feat_supports_lighting(feat)
1012 * is always TRUE here
1015 /* Use a dark tile */
1031 /* Unsafe cave grid -- idea borrowed from Unangband */
1032 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1033 feat = FEAT_UNDETECTD;
1037 /* Access darkness */
1038 f_ptr = &f_info[feat];
1051 /* Memorized grids */
1052 if ((c_ptr->info & CAVE_MARK) && (view_granite_lite || new_ascii_graphics))
1054 /* Access feature */
1055 f_ptr = &f_info[feat];
1063 if (new_ascii_graphics)
1065 /* Handle "blind" */
1068 if (is_ascii_graphics(c,a))
1070 /* Use darkened colour */
1071 a = lighting_colours[a][1];
1073 else if (use_graphics && feat_supports_lighting(feat))
1075 /* Use a dark tile */
1080 /* Handle "torch-lit" grids */
1081 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1084 if (view_yellow_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1086 if (is_ascii_graphics(c,a))
1088 /* Use lightened colour */
1089 a = lighting_colours[a][0];
1091 else if (use_graphics &&
1092 feat_supports_lighting(feat))
1094 /* Use a brightly lit tile */
1100 /* Handle "view_bright_lite" */
1101 else if (view_bright_lite && !p_ptr->wild_mode && ((use_graphics && feat_supports_lighting(feat)) || is_ascii_graphics(c,a)))
1104 if (!(c_ptr->info & CAVE_VIEW))
1106 if (is_ascii_graphics(c,a))
1108 /* Use darkened colour */
1109 a = lighting_colours[a][1];
1111 else if (use_graphics && feat_supports_lighting(feat))
1113 /* Use a dark tile */
1119 else if (!(c_ptr->info & CAVE_GLOW))
1121 if (is_ascii_graphics(c,a))
1123 /* Use darkened colour */
1124 a = lighting_colours[a][1];
1129 /* Special lighting effects */
1130 else if (view_granite_lite && !p_ptr->wild_mode &&
1131 (((a == TERM_WHITE) && !use_graphics) ||
1132 (use_graphics && feat_supports_lighting(feat))))
1134 /* Handle "blind" */
1139 /* Use a dark tile */
1144 /* Use "dark gray" */
1149 /* Handle "torch-lit" grids */
1150 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1153 if (view_yellow_lite && !p_ptr->wild_mode)
1157 /* Use a brightly lit tile */
1168 /* Handle "view_bright_lite" */
1169 else if (view_bright_lite && !p_ptr->wild_mode)
1172 if (!(c_ptr->info & CAVE_VIEW))
1176 /* Use a dark tile */
1187 else if (!(c_ptr->info & CAVE_GLOW))
1191 /* Use a lit tile */
1200 /* Not glowing correctly */
1205 /* Hack -- move towards player */
1206 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
1207 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
1209 /* Check for "local" illumination */
1210 if (!(cave[yy][xx].info & CAVE_GLOW))
1214 /* Use a lit tile */
1227 /* "Simple Lighting" */
1230 /* Handle "blind" */
1231 if (!(c_ptr->info & CAVE_MARK))
1233 /* Unsafe cave grid -- idea borrowed from Unangband */
1234 if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1235 feat = FEAT_UNDETECTD;
1240 /* Access feature */
1241 f_ptr = &f_info[feat];
1251 if (feat_priority == -1)
1256 case FEAT_UNDETECTD:
1263 case FEAT_TRAP_TRAPDOOR:
1265 case FEAT_TRAP_SPIKED_PIT:
1266 case FEAT_TRAP_POISON_PIT:
1267 case FEAT_TRAP_TY_CURSE:
1268 case FEAT_TRAP_TELEPORT:
1269 case FEAT_TRAP_FIRE:
1270 case FEAT_TRAP_ACID:
1271 case FEAT_TRAP_SLOW:
1272 case FEAT_TRAP_LOSE_STR:
1273 case FEAT_TRAP_LOSE_DEX:
1274 case FEAT_TRAP_LOSE_CON:
1275 case FEAT_TRAP_BLIND:
1276 case FEAT_TRAP_CONFUSE:
1277 case FEAT_TRAP_POISON:
1278 case FEAT_TRAP_SLEEP:
1279 case FEAT_TRAP_TRAPS:
1280 case FEAT_TRAP_ALARM:
1284 case FEAT_DEEP_GRASS:
1292 case FEAT_WALL_EXTRA:
1293 case FEAT_WALL_INNER:
1294 case FEAT_WALL_OUTER:
1295 case FEAT_WALL_SOLID:
1296 case FEAT_DEEP_WATER:
1297 case FEAT_SHAL_WATER:
1298 case FEAT_DEEP_LAVA:
1299 case FEAT_SHAL_LAVA:
1305 /* Now a days treasere grid is too many */
1310 case FEAT_PERM_EXTRA:
1311 case FEAT_PERM_INNER:
1312 case FEAT_PERM_OUTER:
1313 case FEAT_PERM_SOLID:
1317 /* default is feat_priority = 20; (doors and stores) */
1320 case FEAT_MINOR_GLYPH:
1322 case FEAT_PATTERN_START:
1323 case FEAT_PATTERN_1:
1324 case FEAT_PATTERN_2:
1325 case FEAT_PATTERN_3:
1326 case FEAT_PATTERN_4:
1327 case FEAT_PATTERN_END:
1328 case FEAT_PATTERN_OLD:
1329 case FEAT_PATTERN_XTRA1:
1330 case FEAT_PATTERN_XTRA2:
1334 /* objects have feat_priority = 20 */
1335 /* monsters have feat_priority = 30 */
1339 case FEAT_QUEST_ENTER:
1340 case FEAT_QUEST_EXIT:
1341 case FEAT_QUEST_DOWN:
1343 case FEAT_LESS_LESS:
1344 case FEAT_MORE_MORE:
1356 #ifdef USE_TRANSPARENCY
1357 /* Save the terrain info for the transparency effects */
1360 #endif /* USE_TRANSPARENCY */
1366 /* Hack -- rare random hallucination, except on outer dungeon walls */
1367 if (p_ptr->image && (feat < FEAT_PERM_SOLID) && !randint0(256))
1370 image_random(ap, cp);
1374 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1378 /* Acquire object */
1379 o_ptr = &o_list[this_o_idx];
1381 /* Acquire next object */
1382 next_o_idx = o_ptr->next_o_idx;
1384 /* Memorized objects */
1387 if (display_autopick)
1391 match_autopick = is_autopick(o_ptr);
1392 if(match_autopick == -1)
1395 act = autopick_list[match_autopick].action;
1397 if ((act & DO_DISPLAY) && (act & display_autopick))
1399 autopick_obj = o_ptr;
1403 match_autopick = -1;
1408 (*cp) = object_char(o_ptr);
1411 (*ap) = object_attr(o_ptr);
1415 /* Hack -- hallucination */
1416 if (p_ptr->image) image_object(ap, cp);
1424 /* Handle monsters */
1425 if (c_ptr->m_idx && display_autopick == 0 )
1427 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1429 /* Visible monster */
1432 monster_race *r_ptr;
1433 r_ptr = &r_info[m_ptr->ap_r_idx];
1443 /* Mimics' colors vary */
1444 if (strchr("\"!=", c) && !(r_ptr->flags1 & RF1_UNIQUE))
1449 /* Use semi-random attr */
1450 (*ap) = c_ptr->m_idx % 15 + 1;
1453 /* Special attr/char codes */
1454 else if ((a & 0x80) && (c & 0x80))
1463 /* Multi-hued monster */
1464 else if (r_ptr->flags1 & (RF1_ATTR_MULTI))
1466 /* Is it a shapechanger? */
1467 if (r_ptr->flags2 & (RF2_SHAPECHANGER))
1471 if (!(streq(ANGBAND_SYS, "ibm")))
1473 (*cp) = r_info[randint1(max_r_idx-1)].x_char;
1474 (*ap) = r_info[randint1(max_r_idx-1)].x_attr;
1478 int n = strlen(image_monster_hack_ibm);
1479 (*cp) = (image_monster_hack_ibm[randint0(n)]);
1482 (*ap) = randint1(15);
1487 (*cp) = (one_in_(25) ?
1488 image_object_hack[randint0(strlen(image_object_hack))] :
1489 image_monster_hack[randint0(strlen(image_monster_hack))]);
1495 /* Multi-hued attr */
1496 if (r_ptr->flags2 & RF2_ATTR_ANY)
1497 (*ap) = randint1(15);
1498 else switch (randint1(7))
1510 (*ap) = TERM_L_GREEN;
1516 (*ap) = TERM_L_DARK;
1524 /* Normal monster (not "clear" in any way) */
1525 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR | RF1_CHAR_CLEAR)))
1534 /* Hack -- Bizarre grid under monster */
1535 else if ((*ap & 0x80) || (*cp & 0x80))
1547 /* Normal (non-clear char) monster */
1548 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR)))
1554 /* Normal (non-clear attr) monster */
1555 else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR)))
1562 /* Hack -- hallucination */
1565 /* Hallucinatory monster */
1566 image_monster(ap, cp);
1571 /* Handle "player" */
1572 if ((y == py) && (x == px))
1574 monster_race *r_ptr = &r_info[0];
1578 /* Get the "player" attr */
1581 /* Get the "player" char */
1584 #ifdef VARIABLE_PLAYER_GRAPH
1586 if (!streq(ANGBAND_GRAF, "new"))
1588 if (streq(ANGBAND_SYS,"ibm"))
1590 if (use_graphics && player_symbols)
1592 if (p_ptr->psex == SEX_FEMALE) c = (char)242;
1593 switch (p_ptr->pclass)
1596 if (p_ptr->lev < 20)
1602 case CLASS_WARRIOR_MAGE:
1603 case CLASS_RED_MAGE:
1604 if (p_ptr->lev < 20)
1609 case CLASS_CHAOS_WARRIOR:
1614 while (a == TERM_DARK);
1617 case CLASS_HIGH_MAGE:
1618 case CLASS_SORCERER:
1619 case CLASS_MAGIC_EATER:
1620 case CLASS_BLUE_MAGE:
1621 if (p_ptr->lev < 20)
1629 if (p_ptr->lev < 20)
1637 if (p_ptr->lev < 20)
1644 if (p_ptr->lev < 20)
1651 case CLASS_BERSERKER:
1653 if (p_ptr->lev < 20)
1659 case CLASS_MINDCRAFTER:
1660 case CLASS_FORCETRAINER:
1661 case CLASS_MIRROR_MASTER:
1662 if (p_ptr->lev < 20)
1668 default: /* Unknown */
1672 switch (p_ptr->prace)
1684 case RACE_HALF_TROLL:
1694 case RACE_HALF_OGRE:
1697 case RACE_HALF_GIANT:
1698 case RACE_HALF_TITAN:
1717 case RACE_DRACONIAN:
1718 if (p_ptr->lev < 20)
1720 else if (p_ptr->lev < 40)
1725 case RACE_MIND_FLAYER:
1736 if (p_ptr->pclass == CLASS_MAGE ||
1737 p_ptr->pclass == CLASS_PRIEST ||
1738 p_ptr->pclass == CLASS_HIGH_MAGE ||
1739 p_ptr->pclass == CLASS_SORCERER ||
1740 p_ptr->pclass == CLASS_MONK ||
1741 p_ptr->pclass == CLASS_FORCETRAINER ||
1742 p_ptr->pclass == CLASS_BLUE_MAGE ||
1743 p_ptr->pclass == CLASS_MIRROR_MASTER ||
1744 p_ptr->pclass == CLASS_MINDCRAFTER)
1778 #endif /* VARIABLE_PLAYER_GRAPH */
1786 * Table of Ascii-to-Zenkaku
1787 * ¡Ö¢£¡×¤ÏÆóÇÜÉýƦÉå¤ÎÆâÉô¥³¡¼¥É¤Ë»ÈÍÑ¡£
1789 static char ascii_to_zenkaku[2*128+1] = "\
1790 ¡¡¡ª¡É¡ô¡ð¡ó¡õ¡Ç¡Ê¡Ë¡ö¡Ü¡¤¡Ý¡¥¡¿\
1791 £°£±£²£³£´£µ£¶£·£¸£¹¡§¡¨¡ã¡á¡ä¡©\
1792 ¡÷£Á£Â£Ã£Ä£Å£Æ£Ç£È£É£Ê£Ë£Ì£Í£Î£Ï\
1793 £Ð£Ñ£Ò£Ó£Ô£Õ£Ö£×£Ø£Ù£Ú¡Î¡À¡Ï¡°¡²\
1794 ¡Æ£á£â£ã£ä£å£æ£ç£è£é£ê£ë£ì£í£î£ï\
1795 £ð£ñ£ò£ó£ô£õ£ö£÷£ø£ù£ú¡Ð¡Ã¡Ñ¡Á¢£";
1799 * Prepare Bigtile or 2-bytes character attr/char pairs
1801 void bigtile_attr(char *cp, byte *ap, char *cp2, byte *ap2)
1803 if ((*ap & 0x80) && (*cp & 0x80))
1811 if (isprint(*cp) || *cp == 127)
1813 *ap2 = (*ap) | 0xf0;
1814 *cp2 = ascii_to_zenkaku[2*(*cp-' ') + 1];
1815 *cp = ascii_to_zenkaku[2*(*cp-' ')];
1826 * Calculate panel colum of a location in the map
1828 static int panel_col_of(int col)
1830 col -= panel_col_min;
1831 if (use_bigtile) col *= 2;
1837 * Moves the cursor to a given MAP (y,x) location
1839 void move_cursor_relative(int row, int col)
1841 /* Real co-ords convert to screen positions */
1842 row -= panel_row_prt;
1845 Term_gotoxy(panel_col_of(col), row);
1851 * Place an attr/char pair at the given map coordinate, if legal.
1853 void print_rel(char c, byte a, int y, int x)
1858 /* Only do "legal" locations */
1859 if (panel_contains(y, x))
1861 /* Hack -- fake monochrome */
1862 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
1864 if (world_monster) a = TERM_DARK;
1865 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
1866 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
1867 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1870 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
1872 /* Draw the char using the attr */
1873 Term_draw(panel_col_of(x), y-panel_row_prt, a, c);
1875 Term_draw(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
1884 * Memorize interesting viewable object/features in the given grid
1886 * This function should only be called on "legal" grids.
1888 * This function will memorize the object and/or feature in the given
1889 * grid, if they are (1) viewable and (2) interesting. Note that all
1890 * objects are interesting, all terrain features except floors (and
1891 * invisible traps) are interesting, and floors (and invisible traps)
1892 * are interesting sometimes (depending on various options involving
1893 * the illumination of floor grids).
1895 * The automatic memorization of all objects and non-floor terrain
1896 * features as soon as they are displayed allows incredible amounts
1897 * of optimization in various places, especially "map_info()".
1899 * Note that the memorization of objects is completely separate from
1900 * the memorization of terrain features, preventing annoying floor
1901 * memorization when a detected object is picked up from a dark floor,
1902 * and object memorization when an object is dropped into a floor grid
1903 * which is memorized but out-of-sight.
1905 * This function should be called every time the "memorization" of
1906 * a grid (or the object in a grid) is called into question, such
1907 * as when an object is created in a grid, when a terrain feature
1908 * "changes" from "floor" to "non-floor", when any grid becomes
1909 * "illuminated" or "viewable", and when a "floor" grid becomes
1912 * Note the relatively efficient use of this function by the various
1913 * "update_view()" and "update_lite()" calls, to allow objects and
1914 * terrain features to be memorized (and drawn) whenever they become
1915 * viewable or illuminated in any way, but not when they "maintain"
1916 * or "lose" their previous viewability or illumination.
1918 * Note the butchered "internal" version of "player_can_see_bold()",
1919 * optimized primarily for the most common cases, that is, for the
1920 * non-marked floor grids.
1922 void note_spot(int y, int x)
1924 cave_type *c_ptr = &cave[y][x];
1926 s16b this_o_idx, next_o_idx = 0;
1930 /* Feature code (applying "mimic" field) */
1931 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
1934 /* Blind players see nothing */
1935 if (p_ptr->blind) return;
1937 /* Analyze non-torch-lit grids */
1938 if (!(c_ptr->info & (CAVE_LITE)))
1940 /* Require line of sight to the grid */
1941 if (!(c_ptr->info & (CAVE_VIEW))) return;
1943 if (p_ptr->pclass != CLASS_NINJA)
1945 /* Require "perma-lite" of the grid */
1946 if (!(c_ptr->info & (CAVE_GLOW | CAVE_MNLT))) return;
1951 /* Hack -- memorize objects */
1952 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1954 object_type *o_ptr = &o_list[this_o_idx];
1956 /* Acquire next object */
1957 next_o_idx = o_ptr->next_o_idx;
1959 /* Memorize objects */
1960 o_ptr->marked |= OM_FOUND;
1964 /* Hack -- memorize grids */
1965 if (!(c_ptr->info & (CAVE_MARK)))
1967 if (p_ptr->pclass == CLASS_NINJA)
1969 c_ptr->info |= (CAVE_MARK);
1971 /* Handle floor grids first */
1972 if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
1974 /* Option -- memorize all torch-lit floors */
1975 if (view_torch_grids && (c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1978 c_ptr->info |= (CAVE_MARK);
1981 /* Option -- memorize all perma-lit floors */
1982 else if (view_perma_grids && (c_ptr->info & (CAVE_GLOW)))
1985 c_ptr->info |= (CAVE_MARK);
1989 /* Memorize normal grids */
1990 else if (cave_floor_grid(c_ptr))
1993 c_ptr->info |= (CAVE_MARK);
1996 /* Memorize torch-lit walls */
1997 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
2000 c_ptr->info |= (CAVE_MARK);
2003 /* Memorize certain non-torch-lit wall grids */
2008 /* Hack -- move one grid towards player */
2009 yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
2010 xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
2012 /* Check for "local" illumination */
2013 if (cave[yy][xx].info & (CAVE_GLOW))
2016 c_ptr->info |= (CAVE_MARK);
2023 void display_dungeon(void)
2029 #ifdef USE_TRANSPARENCY
2032 #endif /* USE_TRANSPARENCY */
2034 for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
2036 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
2038 if (in_bounds2(y, x))
2041 #ifdef USE_TRANSPARENCY
2042 /* Examine the grid */
2043 map_info(y, x, &a, &c, &ta, &tc);
2044 #else /* USE_TRANSPARENCY */
2045 /* Examine the grid */
2046 map_info(y, x, &a, &c);
2047 #endif /* USE_TRANSPARENCY */
2049 /* Hack -- fake monochrome */
2050 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2052 if (world_monster) a = TERM_DARK;
2053 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2054 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2055 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2058 #ifdef USE_TRANSPARENCY
2059 /* Hack -- Queue it */
2060 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2061 #else /* USE_TRANSPARENCY */
2062 /* Hack -- Queue it */
2063 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2064 #endif /* USE_TRANSPARENCY */
2069 /* Clear out-of-bound tiles */
2071 /* Access darkness */
2072 feature_type *f_ptr = &f_info[FEAT_NONE];
2080 #ifdef USE_TRANSPARENCY
2081 /* Hack -- Queue it */
2082 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
2083 #else /* USE_TRANSPARENCY */
2084 /* Hack -- Queue it */
2085 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c);
2086 #endif /* USE_TRANSPARENCY */
2094 * Redraw (on the screen) a given MAP location
2096 * This function should only be called on "legal" grids
2098 void lite_spot(int y, int x)
2100 /* Redraw if on screen */
2101 if (panel_contains(y, x) && in_bounds2(y, x))
2106 #ifdef USE_TRANSPARENCY
2110 /* Examine the grid */
2111 map_info(y, x, &a, &c, &ta, &tc);
2112 #else /* USE_TRANSPARENCY */
2113 /* Examine the grid */
2114 map_info(y, x, &a, &c);
2115 #endif /* USE_TRANSPARENCY */
2117 /* Hack -- fake monochrome */
2118 if (!use_graphics || streq(ANGBAND_SYS, "ibm"))
2120 if (world_monster) a = TERM_DARK;
2121 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2122 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2123 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2127 if (use_bigtile && !(a & 0x80) && (isprint(c) || c == 127))
2129 /* Term_queue_chars ¤ÏÁ´³ÑASCIIÃÏ·Á¤òÀµ¤·¤¯update¤¹¤ë¡£ */
2130 Term_queue_chars(panel_col_of(x), y-panel_row_prt, 2, a, &ascii_to_zenkaku[2*(c-' ')]);
2135 #ifdef USE_TRANSPARENCY
2136 /* Hack -- Queue it */
2137 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
2139 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1, 0, 0);
2140 #else /* USE_TRANSPARENCY */
2141 /* Hack -- Queue it */
2142 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
2144 Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, 255, -1);
2145 #endif /* USE_TRANSPARENCY */
2147 /* Update sub-windows */
2148 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2154 * Prints the map of the dungeon
2156 * Note that, for efficiency, we contain an "optimized" version
2157 * of both "lite_spot()" and "print_rel()", and that we use the
2158 * "lite_spot()" function to display the player grid, if needed.
2166 s16b xmin, xmax, ymin, ymax;
2170 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2173 Term_get_size(&wid, &hgt);
2175 /* Remove map offset */
2179 /* Access the cursor state */
2180 (void)Term_get_cursor(&v);
2182 /* Hide the cursor */
2183 (void)Term_set_cursor(0);
2186 xmin = (0 < panel_col_min) ? panel_col_min : 0;
2187 xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
2188 ymin = (0 < panel_row_min) ? panel_row_min : 0;
2189 ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
2191 /* Bottom section of screen */
2192 for (y = 1; y <= ymin - panel_row_prt; y++)
2194 /* Erase the section */
2195 Term_erase(COL_MAP, y, wid);
2198 /* Top section of screen */
2199 for (y = ymax - panel_row_prt; y <= hgt; y++)
2201 /* Erase the section */
2202 Term_erase(COL_MAP, y, wid);
2206 for (y = ymin; y <= ymax; y++)
2208 /* Scan the columns of row "y" */
2209 for (x = xmin; x <= xmax; x++)
2214 #ifdef USE_TRANSPARENCY
2218 /* Determine what is there */
2219 map_info(y, x, &a, &c, &ta, &tc);
2221 /* Determine what is there */
2222 map_info(y, x, &a, &c);
2225 /* Hack -- fake monochrome */
2226 if (fake_monochrome)
2228 if (world_monster) a = TERM_DARK;
2229 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2230 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2231 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2234 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2236 /* Efficiency -- Redraw that grid of the map */
2237 #ifdef USE_TRANSPARENCY
2238 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
2239 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2, 0, 0);
2241 Term_queue_char(panel_col_of(x), y-panel_row_prt, a, c);
2242 if (use_bigtile) Term_queue_char(panel_col_of(x)+1, y-panel_row_prt, a2, c2);
2247 /* Display player */
2250 /* Restore the cursor */
2251 (void)Term_set_cursor(v);
2257 * print project path
2259 void prt_path(int y, int x)
2264 int default_color = TERM_SLATE;
2265 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2267 if (!display_path) return;
2268 if (-1 == project_length)
2271 /* Get projection path */
2272 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
2275 p_ptr->redraw |= (PR_MAP);
2281 for (i = 0; i < path_n; i++)
2283 int ny = GRID_Y(path_g[i]);
2284 int nx = GRID_X(path_g[i]);
2286 if (panel_contains(ny, nx))
2288 byte a2, a = default_color;
2291 #ifdef USE_TRANSPARENCY
2296 if (cave[ny][nx].m_idx && m_list[cave[ny][nx].m_idx].ml)
2298 /* Determine what is there */
2299 #ifdef USE_TRANSPARENCY
2300 map_info(ny, nx, &a, &c, &ta, &tc);
2302 map_info(ny, nx, &a, &c);
2306 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2308 else if (a == default_color)
2312 if (fake_monochrome)
2314 if (world_monster) a = TERM_DARK;
2315 else if (p_ptr->invuln || world_player) a = TERM_WHITE;
2316 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) a = TERM_WHITE;
2317 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2321 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
2323 /* Hack -- Queue it */
2324 #ifdef USE_TRANSPARENCY
2325 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
2326 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2, 0, 0);
2328 Term_queue_char(panel_col_of(nx), ny-panel_row_prt, a, c);
2329 if (use_bigtile) Term_queue_char(panel_col_of(nx)+1, ny-panel_row_prt, a, c2);
2334 if ((cave[ny][nx].info & CAVE_MARK) && !cave_floor_bold(ny, nx)) break;
2337 if (nx == x && ny == y) default_color = TERM_L_DARK;
2342 static cptr simplify_list[][2] =
2349 {"^Amulet of ", "\""},
2350 {"^Scroll of ", "?"},
2351 {"^Scroll titled ", "?"},
2352 {"^Wand of " , "-"},
2354 {"^Staff of " , "_"},
2355 {"^Potion of ", "!"},
2367 static void display_shortened_item_name(object_type *o_ptr, int y)
2374 object_desc(buf, o_ptr, FALSE, 0);
2375 attr = tval_to_attr[o_ptr->tval % 128];
2381 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
2383 strcpy(buf, "something strange");
2387 for (c = buf; *c; c++)
2390 for (i = 0; simplify_list[i][1]; i++)
2392 cptr org_w = simplify_list[i][0];
2402 if (!strncmp(c, org_w, strlen(org_w)))
2405 cptr tmp = simplify_list[i][1];
2408 tmp = c + strlen(org_w);
2418 /* Ⱦ³Ñ 12 ʸ»úʬ¤ÇÀÚ¤ë */
2424 if(len + 2 > 12) break;
2431 if(len + 1 > 12) break;
2437 Term_putstr(0, y, 12, attr, buf);
2441 * Display a "small-scale" map of the dungeon in the active Term
2443 void display_map(int *cy, int *cx)
2460 /* Save lighting effects */
2461 bool old_view_special_lite = view_special_lite;
2462 bool old_view_granite_lite = view_granite_lite;
2464 bool fake_monochrome = (!use_graphics || streq(ANGBAND_SYS, "ibm"));
2466 int hgt, wid, yrat, xrat;
2468 int **match_autopick_yx;
2469 object_type ***object_autopick_yx;
2472 Term_get_size(&wid, &hgt);
2475 if (use_bigtile) wid /= 2;
2477 yrat = (cur_hgt + hgt - 1) / hgt;
2478 xrat = (cur_wid + wid - 1) / wid;
2480 /* Disable lighting effects */
2481 view_special_lite = FALSE;
2482 view_granite_lite = FALSE;
2484 /* Allocate the maps */
2485 C_MAKE(ma, (hgt + 2), byte_ptr);
2486 C_MAKE(mc, (hgt + 2), char_ptr);
2487 C_MAKE(mp, (hgt + 2), byte_ptr);
2488 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2489 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2491 /* Allocate and wipe each line map */
2492 for (y = 0; y < (hgt + 2); y++)
2494 /* Allocate one row each array */
2495 C_MAKE(ma[y], (wid + 2), byte);
2496 C_MAKE(mc[y], (wid + 2), char);
2497 C_MAKE(mp[y], (wid + 2), byte);
2498 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2499 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2501 for (x = 0; x < wid + 2; ++x)
2503 match_autopick_yx[y][x] = -1;
2504 object_autopick_yx[y][x] = NULL;
2507 ma[y][x] = TERM_WHITE;
2515 /* Allocate the maps */
2516 C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
2517 C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
2518 C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
2520 /* Allocate and wipe each line map */
2521 for (y = 0; y < (cur_hgt + 2); y++)
2523 /* Allocate one row each array */
2524 C_MAKE(bigma[y], (cur_wid + 2), byte);
2525 C_MAKE(bigmc[y], (cur_wid + 2), char);
2526 C_MAKE(bigmp[y], (cur_wid + 2), byte);
2528 for (x = 0; x < cur_wid + 2; ++x)
2531 bigma[y][x] = TERM_WHITE;
2539 /* Fill in the map */
2540 for (i = 0; i < cur_wid; ++i)
2542 for (j = 0; j < cur_hgt; ++j)
2552 /* Extract the current attr/char at that map location */
2553 #ifdef USE_TRANSPARENCY
2554 map_info(j, i, &ta, &tc, &ta, &tc);
2555 #else /* USE_TRANSPARENCY */
2556 map_info(j, i, &ta, &tc);
2557 #endif /* USE_TRANSPARENCY */
2559 /* Extract the priority */
2562 if(match_autopick!=-1
2563 && (match_autopick_yx[y][x] == -1
2564 || match_autopick_yx[y][x] > match_autopick))
2566 match_autopick_yx[y][x] = match_autopick;
2567 object_autopick_yx[y][x] = autopick_obj;
2571 /* Save the char, attr and priority */
2572 bigmc[j+1][i+1] = tc;
2573 bigma[j+1][i+1] = ta;
2574 bigmp[j+1][i+1] = tp;
2578 for (j = 0; j < cur_hgt; ++j)
2580 for (i = 0; i < cur_wid; ++i)
2586 tc = bigmc[j+1][i+1];
2587 ta = bigma[j+1][i+1];
2588 tp = bigmp[j+1][i+1];
2590 /* rare feature has more priority */
2596 for (t = 0; t < 8; t++)
2598 if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2599 ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2609 /* Save the char, attr and priority */
2622 /* Draw the corners */
2623 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2625 /* Draw the horizontal edges */
2626 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2628 /* Draw the vertical edges */
2629 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2632 /* Display each map line in order */
2633 for (y = 0; y < hgt + 2; ++y)
2635 /* Start a new line */
2636 Term_gotoxy(COL_MAP, y);
2638 /* Display the line */
2639 for (x = 0; x < wid + 2; ++x)
2644 /* Hack -- fake monochrome */
2645 if (fake_monochrome)
2647 if (world_monster) ta = TERM_DARK;
2648 else if (p_ptr->invuln || world_player) ta = TERM_WHITE;
2649 else if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] == MUSIC_INVULN)) ta = TERM_WHITE;
2650 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2653 if (use_bigtile) bigtile_attr(&tc, &ta, &c2, &a2);
2655 /* Add the character */
2657 if (use_bigtile) Term_addch(a2, c2);
2662 for (y = 1; y < hgt + 1; ++y)
2664 match_autopick = -1;
2665 for (x = 1; x <= wid; x++){
2666 if (match_autopick_yx[y][x] != -1 &&
2667 (match_autopick > match_autopick_yx[y][x] ||
2668 match_autopick == -1)){
2669 match_autopick = match_autopick_yx[y][x];
2670 autopick_obj = object_autopick_yx[y][x];
2674 /* Clear old display */
2675 Term_putstr(0, y, 12, 0, " ");
2677 if (match_autopick != -1)
2679 display_shortened_item_name(autopick_obj, y);
2682 char buf[13] = "\0";
2683 strncpy(buf,autopick_list[match_autopick].name,12);
2691 /* Player location */
2692 (*cy) = py / yrat + 1 + ROW_MAP;
2694 (*cx) = px / xrat + 1 + COL_MAP;
2696 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2698 /* Restore lighting effects */
2699 view_special_lite = old_view_special_lite;
2700 view_granite_lite = old_view_granite_lite;
2702 /* Free each line map */
2703 for (y = 0; y < (hgt + 2); y++)
2705 /* Free one row each array */
2706 C_FREE(ma[y], (wid + 2), byte);
2707 C_FREE(mc[y], (wid + 2), char);
2708 C_FREE(mp[y], (wid + 2), byte);
2709 C_FREE(match_autopick_yx[y], (wid + 2), int);
2710 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2713 /* Free each line map */
2714 C_FREE(ma, (hgt + 2), byte_ptr);
2715 C_FREE(mc, (hgt + 2), char_ptr);
2716 C_FREE(mp, (hgt + 2), byte_ptr);
2717 C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2718 C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2720 /* Free each line map */
2721 for (y = 0; y < (cur_hgt + 2); y++)
2723 /* Free one row each array */
2724 C_FREE(bigma[y], (cur_wid + 2), byte);
2725 C_FREE(bigmc[y], (cur_wid + 2), char);
2726 C_FREE(bigmp[y], (cur_wid + 2), byte);
2729 /* Free each line map */
2730 C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2731 C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2732 C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2737 * Display a "small-scale" map of the dungeon for the player
2739 * Currently, the "player" is displayed on the map. XXX XXX XXX
2741 void do_cmd_view_map(void)
2746 /* Save the screen */
2751 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2753 prt("Please wait...", 0, 0);
2759 /* Clear the screen */
2762 display_autopick = 0;
2764 /* Display the map */
2765 display_map(&cy, &cx);
2768 if(max_autopick && !p_ptr->wild_mode)
2770 display_autopick = ITEM_DISPLAY;
2777 int wid, hgt, row_message;
2779 Term_get_size(&wid, &hgt);
2780 row_message = hgt - 1;
2783 put_str("²¿¤«¥¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2785 put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2788 /* Hilite the player */
2789 move_cursor(cy, cx);
2794 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2796 flag = DONT_AUTOPICK;
2798 flag = DO_AUTODESTROY;
2800 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2806 if (~display_autopick & flag)
2807 display_autopick |= flag;
2809 display_autopick &= ~flag;
2810 /* Display the map */
2811 display_map(&cy, &cx);
2814 display_autopick = 0;
2820 put_str("²¿¤«¥¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2822 put_str("Hit any key to continue", 23, 30);
2823 #endif /* Hilite the player */
2824 move_cursor(cy, cx);
2829 /* Restore the screen */
2838 * Some comments on the cave grid flags. -BEN-
2841 * One of the major bottlenecks in previous versions of Angband was in
2842 * the calculation of "line of sight" from the player to various grids,
2843 * such as monsters. This was such a nasty bottleneck that a lot of
2844 * silly things were done to reduce the dependancy on "line of sight",
2845 * for example, you could not "see" any grids in a lit room until you
2846 * actually entered the room, and there were all kinds of bizarre grid
2847 * flags to enable this behavior. This is also why the "call light"
2848 * spells always lit an entire room.
2850 * The code below provides functions to calculate the "field of view"
2851 * for the player, which, once calculated, provides extremely fast
2852 * calculation of "line of sight from the player", and to calculate
2853 * the "field of torch lite", which, again, once calculated, provides
2854 * extremely fast calculation of "which grids are lit by the player's
2855 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2856 * "GRID_LITE", as appropriate, these functions maintain an array for
2857 * each of these two flags, each array containing the locations of all
2858 * of the grids marked with the appropriate flag, which can be used to
2859 * very quickly scan through all of the grids in a given set.
2861 * To allow more "semantically valid" field of view semantics, whenever
2862 * the field of view (or the set of torch lit grids) changes, all of the
2863 * grids in the field of view (or the set of torch lit grids) are "drawn"
2864 * so that changes in the world will become apparent as soon as possible.
2865 * This has been optimized so that only grids which actually "change" are
2866 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2867 * of the grids which are entering or leaving the relevent set of grids.
2869 * These new methods are so efficient that the old nasty code was removed.
2871 * Note that there is no reason to "update" the "viewable space" unless
2872 * the player "moves", or walls/doors are created/destroyed, and there
2873 * is no reason to "update" the "torch lit grids" unless the field of
2874 * view changes, or the "light radius" changes. This means that when
2875 * the player is resting, or digging, or doing anything that does not
2876 * involve movement or changing the state of the dungeon, there is no
2877 * need to update the "view" or the "lite" regions, which is nice.
2879 * Note that the calls to the nasty "los()" function have been reduced
2880 * to a bare minimum by the use of the new "field of view" calculations.
2882 * I wouldn't be surprised if slight modifications to the "update_view()"
2883 * function would allow us to determine "reverse line-of-sight" as well
2884 * as "normal line-of-sight", which would allow monsters to use a more
2885 * "correct" calculation to determine if they can "see" the player. For
2886 * now, monsters simply "cheat" somewhat and assume that if the player
2887 * has "line of sight" to the monster, then the monster can "pretend"
2888 * that it has "line of sight" to the player.
2891 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2892 * grid and maintains an array of all "CAVE_LITE" grids.
2894 * This set of grids is the complete set of all grids which are lit by
2895 * the players light source, which allows the "player_can_see_bold()"
2896 * function to work very quickly.
2898 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2899 * fact, the player (unless blind) can always "see" all grids which are
2900 * marked as "CAVE_LITE", unless they are "off screen".
2903 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2904 * grid and maintains an array of all "CAVE_VIEW" grids.
2906 * This set of grids is the complete set of all grids within line of sight
2907 * of the player, allowing the "player_has_los_bold()" macro to work very
2911 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2912 * temporary internal flag to mark those grids which are not only in view,
2913 * but which are also "easily" in line of sight of the player. This flag
2914 * is always cleared when we are done.
2917 * The current "update_lite()" and "update_view()" algorithms use the
2918 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2919 * to keep track of which grids were previously marked as "CAVE_LITE" or
2920 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2922 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2923 * for various other purposes, such as spreading lite or darkness during
2924 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2927 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2928 * in some way permanently lit. However, for the player to "see" anything
2929 * in the grid, as determined by "player_can_see()", the player must not be
2930 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2931 * grids, even if marked as "perma lit", are only illuminated if they touch
2932 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2935 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2936 * that even if the player cannot "see" the grid, he "knows" the terrain in
2937 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2938 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2939 * or when one of the "memorize floor grids" options induces memorization.
2941 * Objects are "memorized" in a different way, using a special "marked" flag
2942 * on the object itself, which is set when an object is observed or detected.
2945 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2946 * and should be illuminated by "lite room" and "darkness" spells.
2949 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2950 * and should be unavailable for "teleportation" destinations.
2953 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2954 * which is observed, and the "view_torch_grids" allows the player to memorize
2955 * every torch-lit grid. The player will always memorize important walls,
2956 * doors, stairs, and other terrain features, as well as any "detected" grids.
2958 * Note that the new "update_view()" method allows, among other things, a room
2959 * to be "partially" seen as the player approaches it, with a growing cone of
2960 * floor appearing as the player gets closer to the door. Also, by not turning
2961 * on the "memorize perma-lit grids" option, the player will only "see" those
2962 * floor grids which are actually in line of sight.
2964 * And my favorite "plus" is that you can now use a special option to draw the
2965 * "floors" in the "viewable region" brightly (actually, to draw the *other*
2966 * grids dimly), providing a "pretty" effect as the player runs around, and
2967 * to efficiently display the "torch lite" in a special color.
2970 * Some comments on the "update_view()" algorithm...
2972 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2973 * and only has to call "los()" on the borderline cases. The major axes/diags
2974 * even terminate early when they hit walls. I need to find a quick way
2975 * to "terminate" the other scans.
2977 * Note that in the worst case (a big empty area with say 5% scattered walls),
2978 * each of the 1500 or so nearby grids is checked once, most of them getting
2979 * an "instant" rating, and only a small portion requiring a call to "los()".
2981 * The only time that the algorithm appears to be "noticeably" too slow is
2982 * when running, and this is usually only important in town, since the town
2983 * provides about the worst scenario possible, with large open regions and
2984 * a few scattered obstructions. There is a special "efficiency" option to
2985 * allow the player to reduce his field of view in town, if needed.
2987 * In the "best" case (say, a normal stretch of corridor), the algorithm
2988 * makes one check for each viewable grid, and makes no calls to "los()".
2989 * So running in corridors is very fast, and if a lot of monsters are
2990 * nearby, it is much faster than the old methods.
2992 * Note that resting, most normal commands, and several forms of running,
2993 * plus all commands executed near large groups of monsters, are strictly
2994 * more efficient with "update_view()" that with the old "compute los() on
2995 * demand" method, primarily because once the "field of view" has been
2996 * calculated, it does not have to be recalculated until the player moves
2997 * (or a wall or door is created or destroyed).
2999 * Note that we no longer have to do as many "los()" checks, since once the
3000 * "view" region has been built, very few things cause it to be "changed"
3001 * (player movement, and the opening/closing of doors, changes in wall status).
3002 * Note that door/wall changes are only relevant when the door/wall itself is
3003 * in the "view" region.
3005 * The algorithm seems to only call "los()" from zero to ten times, usually
3006 * only when coming down a corridor into a room, or standing in a room, just
3007 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
3008 * we will be reducing the calls to "los()".
3010 * I am thinking in terms of an algorithm that "walks" from the central point
3011 * out to the maximal "distance", at each point, determining the "view" code
3012 * (above). For each grid not on a major axis or diagonal, the "view" code
3013 * depends on the "cave_floor_bold()" and "view" of exactly two other grids
3014 * (the one along the nearest diagonal, and the one next to that one, see
3015 * "update_view_aux()"...).
3017 * We "memorize" the viewable space array, so that at the cost of under 3000
3018 * bytes, we reduce the time taken by "forget_view()" to one assignment for
3019 * each grid actually in the "viewable space". And for another 3000 bytes,
3020 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
3021 * are also used by other routines, thus reducing the cost to almost nothing.
3023 * A similar thing is done for "forget_lite()" in which case the savings are
3024 * much less, but save us from doing bizarre maintenance checking.
3026 * In the worst "normal" case (in the middle of the town), the reachable space
3027 * actually reaches to more than half of the largest possible "circle" of view,
3028 * or about 800 grids, and in the worse case (in the middle of a dungeon level
3029 * where all the walls have been removed), the reachable space actually reaches
3030 * the theoretical maximum size of just under 1500 grids.
3032 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
3033 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
3034 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
3035 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
3036 * entire possible space (including initialization) in one step per grid. If
3037 * we do the "clearing" as a separate step (and use an array of "view" grids),
3038 * then the clearing will take as many steps as grids that were viewed, and the
3039 * algorithm will be able to "stop" scanning at various points.
3040 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
3051 * Actually erase the entire "lite" array, redrawing every grid
3053 void forget_lite(void)
3057 /* None to forget */
3058 if (!lite_n) return;
3060 /* Clear them all */
3061 for (i = 0; i < lite_n; i++)
3066 /* Forget "LITE" flag */
3067 cave[y][x].info &= ~(CAVE_LITE);
3081 * This macro allows us to efficiently add a grid to the "lite" array,
3082 * note that we are never called for illegal grids, or for grids which
3083 * have already been placed into the "lite" array, and we are never
3084 * called when the "lite" array is full.
3086 #define cave_lite_hack(Y,X) \
3088 if (!(cave[Y][X].info & (CAVE_LITE))) { \
3089 cave[Y][X].info |= (CAVE_LITE); \
3090 lite_y[lite_n] = (Y); \
3091 lite_x[lite_n] = (X); \
3097 * Update the set of grids "illuminated" by the player's lite.
3099 * This routine needs to use the results of "update_view()"
3101 * Note that "blindness" does NOT affect "torch lite". Be careful!
3103 * We optimize most lites (all non-artifact lites) by using "obvious"
3104 * facts about the results of "small" lite radius, and we attempt to
3105 * list the "nearby" grids before the more "distant" ones in the
3106 * array of torch-lit grids.
3108 * We assume that "radius zero" lite is in fact no lite at all.
3110 * Torch Lantern Artifacts
3120 void update_lite(void)
3122 int i, x, y, min_x, max_x, min_y, max_y;
3123 int p = p_ptr->cur_lite;
3125 /*** Special case ***/
3127 /* Hack -- Player has no lite */
3130 /* Forget the old lite */
3133 /* Draw the player */
3138 /*** Save the old "lite" grids for later ***/
3140 /* Clear them all */
3141 for (i = 0; i < lite_n; i++)
3146 /* Mark the grid as not "lite" */
3147 cave[y][x].info &= ~(CAVE_LITE);
3149 /* Mark the grid as "seen" */
3150 cave[y][x].info |= (CAVE_TEMP);
3152 /* Add it to the "seen" set */
3162 /*** Collect the new "lite" grids ***/
3164 /* Radius 1 -- torch radius */
3168 cave_lite_hack(py, px);
3171 cave_lite_hack(py+1, px);
3172 cave_lite_hack(py-1, px);
3173 cave_lite_hack(py, px+1);
3174 cave_lite_hack(py, px-1);
3176 /* Diagonal grids */
3177 cave_lite_hack(py+1, px+1);
3178 cave_lite_hack(py+1, px-1);
3179 cave_lite_hack(py-1, px+1);
3180 cave_lite_hack(py-1, px-1);
3183 /* Radius 2 -- lantern radius */
3186 /* South of the player */
3187 if (cave_floor_bold(py+1, px))
3189 cave_lite_hack(py+2, px);
3190 cave_lite_hack(py+2, px+1);
3191 cave_lite_hack(py+2, px-1);
3194 /* North of the player */
3195 if (cave_floor_bold(py-1, px))
3197 cave_lite_hack(py-2, px);
3198 cave_lite_hack(py-2, px+1);
3199 cave_lite_hack(py-2, px-1);
3202 /* East of the player */
3203 if (cave_floor_bold(py, px+1))
3205 cave_lite_hack(py, px+2);
3206 cave_lite_hack(py+1, px+2);
3207 cave_lite_hack(py-1, px+2);
3210 /* West of the player */
3211 if (cave_floor_bold(py, px-1))
3213 cave_lite_hack(py, px-2);
3214 cave_lite_hack(py+1, px-2);
3215 cave_lite_hack(py-1, px-2);
3219 /* Radius 3+ -- artifact radius */
3224 /* Paranoia -- see "LITE_MAX" */
3227 /* South-East of the player */
3228 if (cave_floor_bold(py+1, px+1))
3230 cave_lite_hack(py+2, px+2);
3233 /* South-West of the player */
3234 if (cave_floor_bold(py+1, px-1))
3236 cave_lite_hack(py+2, px-2);
3239 /* North-East of the player */
3240 if (cave_floor_bold(py-1, px+1))
3242 cave_lite_hack(py-2, px+2);
3245 /* North-West of the player */
3246 if (cave_floor_bold(py-1, px-1))
3248 cave_lite_hack(py-2, px-2);
3253 if (min_y < 0) min_y = 0;
3257 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
3261 if (min_x < 0) min_x = 0;
3265 if (max_x > cur_wid-1) max_x = cur_wid-1;
3267 /* Scan the maximal box */
3268 for (y = min_y; y <= max_y; y++)
3270 for (x = min_x; x <= max_x; x++)
3272 int dy = (py > y) ? (py - y) : (y - py);
3273 int dx = (px > x) ? (px - x) : (x - px);
3275 /* Skip the "central" grids (above) */
3276 if ((dy <= 2) && (dx <= 2)) continue;
3278 /* Hack -- approximate the distance */
3279 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
3281 /* Skip distant grids */
3282 if (d > p) continue;
3284 /* Viewable, nearby, grids get "torch lit" */
3285 if (player_has_los_bold(y, x))
3287 /* This grid is "torch lit" */
3288 cave_lite_hack(y, x);
3295 /*** Complete the algorithm ***/
3297 /* Draw the new grids */
3298 for (i = 0; i < lite_n; i++)
3303 /* Update fresh grids */
3304 if (cave[y][x].info & (CAVE_TEMP)) continue;
3313 /* Clear them all */
3314 for (i = 0; i < temp_n; i++)
3319 /* No longer in the array */
3320 cave[y][x].info &= ~(CAVE_TEMP);
3322 /* Update stale grids */
3323 if (cave[y][x].info & (CAVE_LITE)) continue;
3334 static bool mon_invis;
3337 * Add a square to the changes array
3339 static void mon_lite_hack(int y, int x)
3344 if (!in_bounds2(y, x)) return;
3346 c_ptr = &cave[y][x];
3348 /* Want a unlit square in view of the player */
3349 if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3351 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3352 if (!cave_floor_grid(c_ptr) && mon_invis) return;
3354 /* Save this square */
3355 if (temp_n < TEMP_MAX)
3363 c_ptr->info |= CAVE_MNLT;
3370 * Update squares illuminated by monsters.
3372 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3373 * denote squares illuminated by monsters.
3375 * The CAVE_TEMP flag is used to store the state during the
3376 * updating. Only squares in view of the player, whos state
3377 * changes are drawn via lite_spot().
3379 void update_mon_lite(void)
3388 /* Clear all monster lit squares */
3389 for (i = 0; i < mon_lite_n; i++)
3392 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3395 c_ptr->info |= (CAVE_TEMP);
3397 /* Clear monster illumination flag */
3398 c_ptr->info &= ~(CAVE_MNLT);
3401 /* Empty temp list of new squares to lite up */
3404 /* Loop through monsters, adding newly lit squares to changes list */
3405 for (i = 1; i < m_max; i++)
3407 monster_type *m_ptr = &m_list[i];
3408 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3410 /* Skip dead monsters */
3411 if (!m_ptr->r_idx) continue;
3413 /* Is it too far away? */
3414 if (m_ptr->cdis > ((d_info[dungeon_type].flags1 & DF1_DARKNESS) ? MAX_SIGHT / 2 + 1 : MAX_SIGHT + 3)) continue;
3416 /* Get lite radius */
3419 /* Note the radii are cumulative */
3420 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3421 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3423 /* Exit if has no light */
3425 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3427 if (world_monster) continue;
3429 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3431 /* Access the location */
3435 /* Is the monster visible? */
3436 mon_invis = !(cave[fy][fx].info & CAVE_VIEW);
3438 /* The square it is on */
3439 mon_lite_hack(fy, fx);
3441 /* Adjacent squares */
3442 mon_lite_hack(fy + 1, fx);
3443 mon_lite_hack(fy - 1, fx);
3444 mon_lite_hack(fy, fx + 1);
3445 mon_lite_hack(fy, fx - 1);
3446 mon_lite_hack(fy + 1, fx + 1);
3447 mon_lite_hack(fy + 1, fx - 1);
3448 mon_lite_hack(fy - 1, fx + 1);
3449 mon_lite_hack(fy - 1, fx - 1);
3454 /* South of the monster */
3455 if (cave_floor_bold(fy + 1, fx))
3457 mon_lite_hack(fy + 2, fx + 1);
3458 mon_lite_hack(fy + 2, fx);
3459 mon_lite_hack(fy + 2, fx - 1);
3461 c_ptr = &cave[fy + 2][fx];
3464 if ((rad == 3) && cave_floor_grid(c_ptr))
3466 mon_lite_hack(fy + 3, fx + 1);
3467 mon_lite_hack(fy + 3, fx);
3468 mon_lite_hack(fy + 3, fx - 1);
3472 /* North of the monster */
3473 if (cave_floor_bold(fy - 1, fx))
3475 mon_lite_hack(fy - 2, fx + 1);
3476 mon_lite_hack(fy - 2, fx);
3477 mon_lite_hack(fy - 2, fx - 1);
3479 c_ptr = &cave[fy - 2][fx];
3482 if ((rad == 3) && cave_floor_grid(c_ptr))
3484 mon_lite_hack(fy - 3, fx + 1);
3485 mon_lite_hack(fy - 3, fx);
3486 mon_lite_hack(fy - 3, fx - 1);
3490 /* East of the monster */
3491 if (cave_floor_bold(fy, fx + 1))
3493 mon_lite_hack(fy + 1, fx + 2);
3494 mon_lite_hack(fy, fx + 2);
3495 mon_lite_hack(fy - 1, fx + 2);
3497 c_ptr = &cave[fy][fx + 2];
3500 if ((rad == 3) && cave_floor_grid(c_ptr))
3502 mon_lite_hack(fy + 1, fx + 3);
3503 mon_lite_hack(fy, fx + 3);
3504 mon_lite_hack(fy - 1, fx + 3);
3508 /* West of the monster */
3509 if (cave_floor_bold(fy, fx - 1))
3511 mon_lite_hack(fy + 1, fx - 2);
3512 mon_lite_hack(fy, fx - 2);
3513 mon_lite_hack(fy - 1, fx - 2);
3515 c_ptr = &cave[fy][fx - 2];
3518 if ((rad == 3) && cave_floor_grid(c_ptr))
3520 mon_lite_hack(fy + 1, fx - 3);
3521 mon_lite_hack(fy, fx - 3);
3522 mon_lite_hack(fy - 1, fx - 3);
3530 /* South-East of the monster */
3531 if (cave_floor_bold(fy + 1, fx + 1))
3533 mon_lite_hack(fy + 2, fx + 2);
3536 /* South-West of the monster */
3537 if (cave_floor_bold(fy + 1, fx - 1))
3539 mon_lite_hack(fy + 2, fx - 2);
3542 /* North-East of the monster */
3543 if (cave_floor_bold(fy - 1, fx + 1))
3545 mon_lite_hack(fy - 2, fx + 2);
3548 /* North-West of the monster */
3549 if (cave_floor_bold(fy - 1, fx - 1))
3551 mon_lite_hack(fy - 2, fx - 2);
3556 /* Save end of list of new squares */
3560 * Look at old set flags to see if there are any changes.
3562 for (i = 0; i < mon_lite_n; i++)
3567 if (!in_bounds2(fy, fx)) continue;
3570 c_ptr = &cave[fy][fx];
3572 /* It it no longer lit? */
3573 if (!(c_ptr->info & CAVE_MNLT) && player_has_los_grid(c_ptr))
3575 /* It is now unlit */
3580 /* Add to end of temp array */
3581 temp_x[temp_n] = (byte)fx;
3582 temp_y[temp_n] = (byte)fy;
3586 /* Clear the lite array */
3589 /* Copy the temp array into the lit array lighting the new squares. */
3590 for (i = 0; i < temp_n; i++)
3595 if (!in_bounds2(fy, fx)) continue;
3598 c_ptr = &cave[fy][fx];
3602 /* Clear the temp flag for the old lit grids */
3603 c_ptr->info &= ~(CAVE_TEMP);
3607 /* The is the square newly lit and visible? */
3608 if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3615 /* Save in the monster lit array */
3616 mon_lite_x[mon_lite_n] = fx;
3617 mon_lite_y[mon_lite_n] = fy;
3622 /* Finished with temp_n */
3625 p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3627 if (p_ptr->special_defense & NINJA_S_STEALTH)
3629 if (p_ptr->old_monlite != p_ptr->monlite)
3634 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3636 msg_print("Your mantle of shadow become thin.");
3642 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3644 msg_print("Your mantle of shadow restored its original darkness.");
3649 p_ptr->old_monlite = p_ptr->monlite;
3652 void clear_mon_lite(void)
3657 /* Clear all monster lit squares */
3658 for (i = 0; i < mon_lite_n; i++)
3661 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3663 /* Clear monster illumination flag */
3664 c_ptr->info &= ~(CAVE_MNLT);
3667 /* Empty the array */
3674 * Clear the viewable space
3676 void forget_view(void)
3682 /* None to forget */
3683 if (!view_n) return;
3685 /* Clear them all */
3686 for (i = 0; i < view_n; i++)
3691 /* Access the grid */
3692 c_ptr = &cave[y][x];
3694 /* Forget that the grid is viewable */
3695 c_ptr->info &= ~(CAVE_VIEW);
3697 if (!panel_contains(y, x)) continue;
3699 /* Update the screen */
3710 * This macro allows us to efficiently add a grid to the "view" array,
3711 * note that we are never called for illegal grids, or for grids which
3712 * have already been placed into the "view" array, and we are never
3713 * called when the "view" array is full.
3715 #define cave_view_hack(C,Y,X) \
3717 if (!((C)->info & (CAVE_VIEW))){\
3718 (C)->info |= (CAVE_VIEW); \
3719 view_y[view_n] = (Y); \
3720 view_x[view_n] = (X); \
3727 * Helper function for "update_view()" below
3729 * We are checking the "viewability" of grid (y,x) by the player.
3731 * This function assumes that (y,x) is legal (i.e. on the map).
3733 * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3734 * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3736 * Note that we are using the "CAVE_XTRA" field for marking grids as
3737 * "easily viewable". This bit is cleared at the end of "update_view()".
3739 * This function adds (y,x) to the "viewable set" if necessary.
3741 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3743 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3745 bool f1, f2, v1, v2, z1, z2, wall;
3749 cave_type *g1_c_ptr;
3750 cave_type *g2_c_ptr;
3752 /* Access the grids */
3753 g1_c_ptr = &cave[y1][x1];
3754 g2_c_ptr = &cave[y2][x2];
3757 /* Check for walls */
3758 f1 = (cave_floor_grid(g1_c_ptr));
3759 f2 = (cave_floor_grid(g2_c_ptr));
3761 /* Totally blocked by physical walls */
3762 if (!f1 && !f2) return (TRUE);
3765 /* Check for visibility */
3766 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3767 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3769 /* Totally blocked by "unviewable neighbors" */
3770 if (!v1 && !v2) return (TRUE);
3773 /* Access the grid */
3774 c_ptr = &cave[y][x];
3777 /* Check for walls */
3778 wall = (!cave_floor_grid(c_ptr));
3781 /* Check the "ease" of visibility */
3782 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3783 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3785 /* Hack -- "easy" plus "easy" yields "easy" */
3788 c_ptr->info |= (CAVE_XTRA);
3790 cave_view_hack(c_ptr, y, x);
3795 /* Hack -- primary "easy" yields "viewed" */
3798 cave_view_hack(c_ptr, y, x);
3803 /* Hack -- "view" plus "view" yields "view" */
3806 /* c_ptr->info |= (CAVE_XTRA); */
3808 cave_view_hack(c_ptr, y, x);
3814 /* Mega-Hack -- the "los()" function works poorly on walls */
3817 cave_view_hack(c_ptr, y, x);
3823 /* Hack -- check line of sight */
3824 if (los(py, px, y, x))
3826 cave_view_hack(c_ptr, y, x);
3832 /* Assume no line of sight. */
3839 * Calculate the viewable space
3841 * 1: Process the player
3842 * 1a: The player is always (easily) viewable
3843 * 2: Process the diagonals
3844 * 2a: The diagonals are (easily) viewable up to the first wall
3845 * 2b: But never go more than 2/3 of the "full" distance
3846 * 3: Process the main axes
3847 * 3a: The main axes are (easily) viewable up to the first wall
3848 * 3b: But never go more than the "full" distance
3849 * 4: Process sequential "strips" in each of the eight octants
3850 * 4a: Each strip runs along the previous strip
3851 * 4b: The main axes are "previous" to the first strip
3852 * 4c: Process both "sides" of each "direction" of each strip
3853 * 4c1: Each side aborts as soon as possible
3854 * 4c2: Each side tells the next strip how far it has to check
3856 * Note that the octant processing involves some pretty interesting
3857 * observations involving when a grid might possibly be viewable from
3858 * a given grid, and on the order in which the strips are processed.
3860 * Note the use of the mathematical facts shown below, which derive
3861 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3862 * hypotenuse of a right triangle is primarily determined by the length
3863 * of the longest side, when one side is small, and is strictly less
3864 * than one-and-a-half times as long as the longest side when both of
3865 * the sides are large.
3867 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3868 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3870 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3872 * These observations are important because the calculation of the actual
3873 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3874 * while for small values (up to about 20 or so), the approximations above
3875 * are correct to within an error of at most one grid or so.
3877 * Observe the use of "full" and "over" in the code below, and the use of
3878 * the specialized calculation involving "limit", all of which derive from
3879 * the observations given above. Basically, we note that the "circle" of
3880 * view is completely contained in an "octagon" whose bounds are easy to
3881 * determine, and that only a few steps are needed to derive the actual
3882 * bounds of the circle given the bounds of the octagon.
3884 * Note that by skipping all the grids in the corners of the octagon, we
3885 * place an upper limit on the number of grids in the field of view, given
3886 * that "full" is never more than 20. Of the 1681 grids in the "square" of
3887 * view, only about 1475 of these are in the "octagon" of view, and even
3888 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3889 * entries to completely contain the actual field of view.
3891 * Note also the care taken to prevent "running off the map". The use of
3892 * explicit checks on the "validity" of the "diagonal", and the fact that
3893 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3894 * use the optimized "cave_floor_bold()" macro, and to avoid the overhead
3895 * of multiple checks on the validity of grids.
3897 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3898 * "ws","wn" variables. They work like this: While travelling down the
3899 * south-bound strip just to the east of the main south axis, as soon as
3900 * we get to a grid which does not "transmit" viewing, if all of the strips
3901 * preceding us (in this case, just the main axis) had terminated at or before
3902 * the same point, then we can stop, and reset the "max distance" to ourself.
3903 * So, each strip (named by major axis plus offset, thus "se" in this case)
3904 * maintains a "blockage" variable, initialized during the main axis step,
3905 * and checks it whenever a blockage is observed. After processing each
3906 * strip as far as the previous strip told us to process, the next strip is
3907 * told not to go farther than the current strip's farthest viewable grid,
3908 * unless open space is still available. This uses the "k" variable.
3910 * Note the use of "inline" macros for efficiency. The "cave_floor_grid()"
3911 * macro is a replacement for "cave_floor_bold()" which takes a pointer to
3912 * a cave grid instead of its location. The "cave_view_hack()" macro is a
3913 * chunk of code which adds the given location to the "view" array if it
3914 * is not already there, using both the actual location and a pointer to
3915 * the cave grid. See above.
3917 * By the way, the purpose of this code is to reduce the dependancy on the
3918 * "los()" function which is slow, and, in some cases, not very accurate.
3920 * It is very possible that I am the only person who fully understands this
3921 * function, and for that I am truly sorry, but efficiency was very important
3922 * and the "simple" version of this function was just not fast enough. I am
3923 * more than willing to replace this function with a simpler one, if it is
3924 * equally efficient, and especially willing if the new function happens to
3925 * derive "reverse-line-of-sight" at the same time, since currently monsters
3926 * just use an optimized hack of "you see me, so I see you", and then use the
3927 * actual "projectable()" function to check spell attacks.
3929 void update_view(void)
3931 int n, m, d, k, y, x, z;
3933 int se, sw, ne, nw, es, en, ws, wn;
3937 int y_max = cur_hgt - 1;
3938 int x_max = cur_wid - 1;
3942 /*** Initialize ***/
3945 if (view_reduce_view && !dun_level)
3947 /* Full radius (10) */
3948 full = MAX_SIGHT / 2;
3950 /* Octagon factor (15) */
3951 over = MAX_SIGHT * 3 / 4;
3957 /* Full radius (20) */
3960 /* Octagon factor (30) */
3961 over = MAX_SIGHT * 3 / 2;
3965 /*** Step 0 -- Begin ***/
3967 /* Save the old "view" grids for later */
3968 for (n = 0; n < view_n; n++)
3973 /* Access the grid */
3974 c_ptr = &cave[y][x];
3976 /* Mark the grid as not in "view" */
3977 c_ptr->info &= ~(CAVE_VIEW);
3979 /* Mark the grid as "seen" */
3980 c_ptr->info |= (CAVE_TEMP);
3982 /* Add it to the "seen" set */
3988 /* Start over with the "view" array */
3991 /*** Step 1 -- adjacent grids ***/
3993 /* Now start on the player */
3997 /* Access the grid */
3998 c_ptr = &cave[y][x];
4000 /* Assume the player grid is easily viewable */
4001 c_ptr->info |= (CAVE_XTRA);
4003 /* Assume the player grid is viewable */
4004 cave_view_hack(c_ptr, y, x);
4007 /*** Step 2 -- Major Diagonals ***/
4012 /* Scan south-east */
4013 for (d = 1; d <= z; d++)
4015 c_ptr = &cave[y+d][x+d];
4016 c_ptr->info |= (CAVE_XTRA);
4017 cave_view_hack(c_ptr, y+d, x+d);
4018 if (!cave_floor_grid(c_ptr)) break;
4021 /* Scan south-west */
4022 for (d = 1; d <= z; d++)
4024 c_ptr = &cave[y+d][x-d];
4025 c_ptr->info |= (CAVE_XTRA);
4026 cave_view_hack(c_ptr, y+d, x-d);
4027 if (!cave_floor_grid(c_ptr)) break;
4030 /* Scan north-east */
4031 for (d = 1; d <= z; d++)
4033 c_ptr = &cave[y-d][x+d];
4034 c_ptr->info |= (CAVE_XTRA);
4035 cave_view_hack(c_ptr, y-d, x+d);
4036 if (!cave_floor_grid(c_ptr)) break;
4039 /* Scan north-west */
4040 for (d = 1; d <= z; d++)
4042 c_ptr = &cave[y-d][x-d];
4043 c_ptr->info |= (CAVE_XTRA);
4044 cave_view_hack(c_ptr, y-d, x-d);
4045 if (!cave_floor_grid(c_ptr)) break;
4049 /*** Step 3 -- major axes ***/
4052 for (d = 1; d <= full; d++)
4054 c_ptr = &cave[y+d][x];
4055 c_ptr->info |= (CAVE_XTRA);
4056 cave_view_hack(c_ptr, y+d, x);
4057 if (!cave_floor_grid(c_ptr)) break;
4060 /* Initialize the "south strips" */
4064 for (d = 1; d <= full; d++)
4066 c_ptr = &cave[y-d][x];
4067 c_ptr->info |= (CAVE_XTRA);
4068 cave_view_hack(c_ptr, y-d, x);
4069 if (!cave_floor_grid(c_ptr)) break;
4072 /* Initialize the "north strips" */
4076 for (d = 1; d <= full; d++)
4078 c_ptr = &cave[y][x+d];
4079 c_ptr->info |= (CAVE_XTRA);
4080 cave_view_hack(c_ptr, y, x+d);
4081 if (!cave_floor_grid(c_ptr)) break;
4084 /* Initialize the "east strips" */
4088 for (d = 1; d <= full; d++)
4090 c_ptr = &cave[y][x-d];
4091 c_ptr->info |= (CAVE_XTRA);
4092 cave_view_hack(c_ptr, y, x-d);
4093 if (!cave_floor_grid(c_ptr)) break;
4096 /* Initialize the "west strips" */
4100 /*** Step 4 -- Divide each "octant" into "strips" ***/
4102 /* Now check each "diagonal" (in parallel) */
4103 for (n = 1; n <= over / 2; n++)
4105 int ypn, ymn, xpn, xmn;
4108 /* Acquire the "bounds" of the maximal circle */
4110 if (z > full - n) z = full - n;
4111 while ((z + n + (n>>1)) > full) z--;
4114 /* Access the four diagonal grids */
4124 /* Maximum distance */
4125 m = MIN(z, y_max - ypn);
4128 if ((xpn <= x_max) && (n < se))
4131 for (k = n, d = 1; d <= m; d++)
4133 /* Check grid "d" in strip "n", notice "blockage" */
4134 if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
4136 if (n + d >= se) break;
4139 /* Track most distant "non-blockage" */
4146 /* Limit the next strip */
4151 if ((xmn >= 0) && (n < sw))
4154 for (k = n, d = 1; d <= m; d++)
4156 /* Check grid "d" in strip "n", notice "blockage" */
4157 if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
4159 if (n + d >= sw) break;
4162 /* Track most distant "non-blockage" */
4169 /* Limit the next strip */
4178 /* Maximum distance */
4182 if ((xpn <= x_max) && (n < ne))
4185 for (k = n, d = 1; d <= m; d++)
4187 /* Check grid "d" in strip "n", notice "blockage" */
4188 if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
4190 if (n + d >= ne) break;
4193 /* Track most distant "non-blockage" */
4200 /* Limit the next strip */
4205 if ((xmn >= 0) && (n < nw))
4208 for (k = n, d = 1; d <= m; d++)
4210 /* Check grid "d" in strip "n", notice "blockage" */
4211 if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
4213 if (n + d >= nw) break;
4216 /* Track most distant "non-blockage" */
4223 /* Limit the next strip */
4232 /* Maximum distance */
4233 m = MIN(z, x_max - xpn);
4236 if ((ypn <= x_max) && (n < es))
4239 for (k = n, d = 1; d <= m; d++)
4241 /* Check grid "d" in strip "n", notice "blockage" */
4242 if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
4244 if (n + d >= es) break;
4247 /* Track most distant "non-blockage" */
4254 /* Limit the next strip */
4259 if ((ymn >= 0) && (n < en))
4262 for (k = n, d = 1; d <= m; d++)
4264 /* Check grid "d" in strip "n", notice "blockage" */
4265 if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
4267 if (n + d >= en) break;
4270 /* Track most distant "non-blockage" */
4277 /* Limit the next strip */
4286 /* Maximum distance */
4290 if ((ypn <= y_max) && (n < ws))
4293 for (k = n, d = 1; d <= m; d++)
4295 /* Check grid "d" in strip "n", notice "blockage" */
4296 if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
4298 if (n + d >= ws) break;
4301 /* Track most distant "non-blockage" */
4308 /* Limit the next strip */
4313 if ((ymn >= 0) && (n < wn))
4316 for (k = n, d = 1; d <= m; d++)
4318 /* Check grid "d" in strip "n", notice "blockage" */
4319 if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
4321 if (n + d >= wn) break;
4324 /* Track most distant "non-blockage" */
4331 /* Limit the next strip */
4338 /*** Step 5 -- Complete the algorithm ***/
4340 /* Update all the new grids */
4341 for (n = 0; n < view_n; n++)
4346 /* Access the grid */
4347 c_ptr = &cave[y][x];
4349 /* Clear the "CAVE_XTRA" flag */
4350 c_ptr->info &= ~(CAVE_XTRA);
4352 /* Update only newly viewed grids */
4353 if (c_ptr->info & (CAVE_TEMP)) continue;
4362 /* Wipe the old grids, update as needed */
4363 for (n = 0; n < temp_n; n++)
4368 /* Access the grid */
4369 c_ptr = &cave[y][x];
4371 /* No longer in the array */
4372 c_ptr->info &= ~(CAVE_TEMP);
4374 /* Update only non-viewable grids */
4375 if (c_ptr->info & (CAVE_VIEW)) continue;
4388 * Hack -- forget the "flow" information
4390 void forget_flow(void)
4394 /* Check the entire dungeon */
4395 for (y = 0; y < cur_hgt; y++)
4397 for (x = 0; x < cur_wid; x++)
4399 /* Forget the old data */
4400 cave[y][x].dist = 0;
4401 cave[y][x].cost = 0;
4402 cave[y][x].when = 0;
4409 * Hack - speed up the update_flow algorithm by only doing
4410 * it everytime the player moves out of LOS of the last
4413 static u16b flow_x = 0;
4414 static u16b flow_y = 0;
4419 * Hack -- fill in the "cost" field of every grid that the player
4420 * can "reach" with the number of steps needed to reach that grid.
4421 * This also yields the "distance" of the player from every grid.
4423 * In addition, mark the "when" of the grids that can reach
4424 * the player with the incremented value of "flow_n".
4426 * Hack -- use the "seen" array as a "circular queue".
4428 * We do not need a priority queue because the cost from grid
4429 * to grid is always "one" and we process them in order.
4431 void update_flow(void)
4437 /* Paranoia -- make sure the array is empty */
4440 /* The last way-point is on the map */
4441 if (running && in_bounds(flow_y, flow_x))
4443 /* The way point is in sight - do not update. (Speedup) */
4444 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4447 /* Erase all of the current flow information */
4448 for (y = 0; y < cur_hgt; y++)
4450 for (x = 0; x < cur_wid; x++)
4452 cave[y][x].cost = 0;
4453 cave[y][x].dist = 0;
4457 /* Save player position */
4461 /* Add the player's grid to the queue */
4465 /* Now process the queue */
4466 while (flow_head != flow_tail)
4470 /* Extract the next entry */
4471 ty = temp_y[flow_tail];
4472 tx = temp_x[flow_tail];
4474 /* Forget that entry */
4475 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4477 /* Add the "children" */
4478 for (d = 0; d < 8; d++)
4480 int old_head = flow_head;
4481 int m = cave[ty][tx].cost + 1;
4482 int n = cave[ty][tx].dist + 1;
4485 /* Child location */
4486 y = ty + ddy_ddd[d];
4487 x = tx + ddx_ddd[d];
4489 /* Ignore player's grid */
4490 if (x == px && y == py) continue;
4492 c_ptr = &cave[y][x];
4494 if (is_closed_door(c_ptr->feat)) m += 3;
4496 /* Ignore "pre-stamped" entries */
4497 if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4499 /* Ignore "walls" and "rubble" */
4500 if ((c_ptr->feat >= FEAT_RUBBLE) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4502 /* Save the flow cost */
4503 if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4504 if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4506 /* Hack -- limit flow depth */
4507 if (n == MONSTER_FLOW_DEPTH) continue;
4509 /* Enqueue that entry */
4510 temp_y[flow_head] = y;
4511 temp_x[flow_head] = x;
4513 /* Advance the queue */
4514 if (++flow_head == TEMP_MAX) flow_head = 0;
4516 /* Hack -- notice overflow by forgetting new entry */
4517 if (flow_head == flow_tail) flow_head = old_head;
4523 static int scent_when = 0;
4526 * Characters leave scent trails for perceptive monsters to track.
4528 * Smell is rather more limited than sound. Many creatures cannot use
4529 * it at all, it doesn't extend very far outwards from the character's
4530 * current position, and monsters can use it to home in the character,
4531 * but not to run away from him.
4533 * Smell is valued according to age. When a character takes his turn,
4534 * scent is aged by one, and new scent of the current age is laid down.
4535 * Speedy characters leave more scent, true, but it also ages faster,
4536 * which makes it harder to hunt them down.
4538 * Whenever the age count loops, most of the scent trail is erased and
4539 * the age of the remainder is recalculated.
4541 void update_smell(void)
4546 /* Create a table that controls the spread of scent */
4547 const int scent_adjust[5][5] =
4556 /* Loop the age and adjust scent values when necessary */
4557 if (++scent_when == 254)
4559 /* Scan the entire dungeon */
4560 for (y = 0; y < cur_hgt; y++)
4562 for (x = 0; x < cur_wid; x++)
4564 int w = cave[y][x].when;
4565 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4574 /* Lay down new scent */
4575 for (i = 0; i < 5; i++)
4577 for (j = 0; j < 5; j++)
4581 /* Translate table to map grids */
4586 if (!in_bounds(y, x)) continue;
4588 c_ptr = &cave[y][x];
4590 /* Walls, water, and lava cannot hold scent. */
4591 if ((c_ptr->feat >= FEAT_RUBBLE) && (c_ptr->feat != FEAT_TREES) && !cave_floor_grid(c_ptr)) continue;
4593 /* Grid must not be blocked by walls from the character */
4594 if (!player_has_los_bold(y, x)) continue;
4596 /* Note grids that are too far away */
4597 if (scent_adjust[i][j] == -1) continue;
4599 /* Mark the grid with new scent */
4600 c_ptr->when = scent_when + scent_adjust[i][j];
4607 * Hack -- map the current panel (plus some) ala "magic mapping"
4609 void map_area(int range)
4617 if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4619 /* Scan that area */
4620 for (y = 1; y < cur_hgt - 1; y++)
4622 for (x = 1; x < cur_wid - 1; x++)
4624 if (distance(py, px, y, x) > range) continue;
4626 c_ptr = &cave[y][x];
4628 /* Feature code (applying "mimic" field) */
4629 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4631 /* All non-walls are "checked" */
4632 if ((feat <= FEAT_DOOR_TAIL) ||
4633 (feat == FEAT_RUBBLE) ||
4634 ((feat >= FEAT_MINOR_GLYPH) &&
4635 (feat <= FEAT_TREES)) ||
4636 (feat >= FEAT_TOWN))
4638 /* Memorize normal features */
4639 if ((feat > FEAT_INVIS) && (feat != FEAT_DIRT) && (feat != FEAT_GRASS))
4641 /* Memorize the object */
4642 c_ptr->info |= (CAVE_MARK);
4645 /* Memorize known walls */
4646 for (i = 0; i < 8; i++)
4648 c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4650 /* Feature code (applying "mimic" field) */
4651 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4653 /* Memorize walls (etc) */
4654 if ((feat >= FEAT_RUBBLE) && (feat != FEAT_DIRT) && (feat != FEAT_GRASS))
4656 /* Memorize the walls */
4657 c_ptr->info |= (CAVE_MARK);
4665 p_ptr->redraw |= (PR_MAP);
4668 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4674 * Light up the dungeon using "clairvoyance"
4676 * This function "illuminates" every grid in the dungeon, memorizes all
4677 * "objects", memorizes all grids as with magic mapping, and, under the
4678 * standard option settings (view_perma_grids but not view_torch_grids)
4679 * memorizes all floor grids too.
4681 * Note that if "view_perma_grids" is not set, we do not memorize floor
4682 * grids, since this would defeat the purpose of "view_perma_grids", not
4683 * that anyone seems to play without this option.
4685 * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4686 * since this would prevent the use of "view_torch_grids" as a method to
4687 * keep track of what grids have been observed directly.
4689 void wiz_lite(bool ninja)
4694 /* Memorize objects */
4695 for (i = 1; i < o_max; i++)
4697 object_type *o_ptr = &o_list[i];
4699 /* Skip dead objects */
4700 if (!o_ptr->k_idx) continue;
4702 /* Skip held objects */
4703 if (o_ptr->held_m_idx) continue;
4706 o_ptr->marked |= OM_FOUND;
4709 /* Scan all normal grids */
4710 for (y = 1; y < cur_hgt - 1; y++)
4712 /* Scan all normal grids */
4713 for (x = 1; x < cur_wid - 1; x++)
4715 cave_type *c_ptr = &cave[y][x];
4717 /* Feature code (applying "mimic" field) */
4718 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4720 /* Process all non-walls */
4721 if (cave_floor_bold(y, x) || (feat == FEAT_RUBBLE) || (feat == FEAT_TREES) || (feat == FEAT_MOUNTAIN))
4723 /* Scan all neighbors */
4724 for (i = 0; i < 9; i++)
4726 int yy = y + ddy_ddd[i];
4727 int xx = x + ddx_ddd[i];
4730 c_ptr = &cave[yy][xx];
4732 /* Feature code (applying "mimic" field) */
4733 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
4735 /* Memorize normal features */
4738 /* Memorize the grid */
4739 c_ptr->info |= (CAVE_MARK);
4743 if ((feat > FEAT_INVIS))
4745 /* Memorize the grid */
4746 c_ptr->info |= (CAVE_MARK);
4749 /* Perma-lite the grid */
4750 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4752 c_ptr->info |= (CAVE_GLOW);
4754 /* Normally, memorize floors (see above) */
4755 if (view_perma_grids && !view_torch_grids)
4757 /* Memorize the grid */
4758 c_ptr->info |= (CAVE_MARK);
4767 /* Update the monsters */
4768 p_ptr->update |= (PU_MONSTERS);
4771 p_ptr->redraw |= (PR_MAP);
4774 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4779 * Forget the dungeon map (ala "Thinking of Maud...").
4786 /* Forget every grid */
4787 for (y = 0; y < cur_hgt; y++)
4789 for (x = 0; x < cur_wid; x++)
4791 cave_type *c_ptr = &cave[y][x];
4793 /* Process the grid */
4794 c_ptr->info &= ~(CAVE_MARK);
4798 /* Forget all objects */
4799 for (i = 1; i < o_max; i++)
4801 object_type *o_ptr = &o_list[i];
4803 /* Skip dead objects */
4804 if (!o_ptr->k_idx) continue;
4806 /* Skip held objects */
4807 if (o_ptr->held_m_idx) continue;
4809 /* Forget the object */
4813 /* Mega-Hack -- Forget the view and lite */
4814 p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4816 /* Update the view and lite */
4817 p_ptr->update |= (PU_VIEW | PU_LITE);
4819 /* Update the monsters */
4820 p_ptr->update |= (PU_MONSTERS);
4823 p_ptr->redraw |= (PR_MAP);
4826 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4834 * Change the "feat" flag for a grid, and notice/redraw the grid
4836 void cave_set_feat(int y, int x, int feat)
4838 cave_type *c_ptr = &cave[y][x];
4840 /* Clear mimic type */
4843 /* Remove flag for mirror/glyph */
4844 c_ptr->info &= ~(CAVE_OBJECT);
4846 /* Change the feature */
4856 /* Remove a mirror */
4857 void remove_mirror(int y, int x)
4859 /* Remove the mirror */
4860 cave[y][x].info &= ~(CAVE_OBJECT);
4861 cave[y][x].mimic = 0;
4863 if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4865 cave[y][x].info &= ~(CAVE_GLOW);
4866 if( !view_torch_grids )cave[y][x].info &= ~(CAVE_MARK);
4877 * Return TRUE if there is a mirror on the grid.
4879 bool is_mirror_grid(cave_type *c_ptr)
4881 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_MIRROR)
4889 * Return TRUE if there is a mirror on the grid.
4891 bool is_glyph_grid(cave_type *c_ptr)
4893 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_GLYPH)
4901 * Return TRUE if there is a mirror on the grid.
4903 bool is_explosive_rune_grid(cave_type *c_ptr)
4905 if ((c_ptr->info & CAVE_OBJECT) && c_ptr->mimic == FEAT_MINOR_GLYPH)
4913 * Calculate "incremental motion". Used by project() and shoot().
4914 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4916 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4918 int dy, dx, dist, shift;
4920 /* Extract the distance travelled */
4921 dy = (*y < y1) ? y1 - *y : *y - y1;
4922 dx = (*x < x1) ? x1 - *x : *x - x1;
4924 /* Number of steps */
4925 dist = (dy > dx) ? dy : dx;
4927 /* We are calculating the next location */
4931 /* Calculate the total distance along each axis */
4932 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4933 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4935 /* Paranoia -- Hack -- no motion */
4936 if (!dy && !dx) return;
4939 /* Move mostly vertically */
4942 /* Extract a shift factor */
4943 shift = (dist * dx + (dy - 1) / 2) / dy;
4945 /* Sometimes move along the minor axis */
4946 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4948 /* Always move along major axis */
4949 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4952 /* Move mostly horizontally */
4955 /* Extract a shift factor */
4956 shift = (dist * dy + (dx - 1) / 2) / dx;
4958 /* Sometimes move along the minor axis */
4959 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4961 /* Always move along major axis */
4962 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4969 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4970 * at the final destination, assuming no monster gets in the way.
4972 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4974 bool projectable(int y1, int x1, int y2, int x2)
4981 /* Check the projection path */
4982 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4984 /* No grid is ever projectable from itself */
4985 if (!grid_n) return (FALSE);
4988 y = GRID_Y(grid_g[grid_n - 1]);
4989 x = GRID_X(grid_g[grid_n - 1]);
4991 /* May not end in an unrequested grid */
4992 if ((y != y2) || (x != x2)) return (FALSE);
5000 * Standard "find me a location" function
5002 * Obtains a legal location within the given distance of the initial
5003 * location, and with "los()" from the source to destination location.
5005 * This function is often called from inside a loop which searches for
5006 * locations while increasing the "d" distance.
5008 * Currently the "m" parameter is unused.
5010 void scatter(int *yp, int *xp, int y, int x, int d, int m)
5017 /* Pick a location */
5020 /* Pick a new location */
5021 ny = rand_spread(y, d);
5022 nx = rand_spread(x, d);
5024 /* Ignore annoying locations */
5025 if (!in_bounds(ny, nx)) continue;
5027 /* Ignore "excessively distant" locations */
5028 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
5030 /* Require "line of sight" */
5031 if (los(y, x, ny, nx)) break;
5034 /* Save the location */
5043 * Track a new monster
5045 void health_track(int m_idx)
5047 /* Mount monster is already tracked */
5048 if (m_idx && m_idx == p_ptr->riding) return;
5050 /* Track a new guy */
5051 p_ptr->health_who = m_idx;
5053 /* Redraw (later) */
5054 p_ptr->redraw |= (PR_HEALTH);
5060 * Hack -- track the given monster race
5062 void monster_race_track(int r_idx)
5064 /* Save this monster ID */
5065 p_ptr->monster_race_idx = r_idx;
5068 p_ptr->window |= (PW_MONSTER);
5074 * Hack -- track the given object kind
5076 void object_kind_track(int k_idx)
5078 /* Save this monster ID */
5079 p_ptr->object_kind_idx = k_idx;
5082 p_ptr->window |= (PW_OBJECT);
5088 * Something has happened to disturb the player.
5090 * The first arg indicates a major disturbance, which affects search.
5092 * The second arg is currently unused, but could induce output flush.
5094 * All disturbance cancels repeated commands, resting, and running.
5096 void disturb(int stop_search, int unused_flag)
5099 unused_flag = unused_flag;
5101 /* Cancel auto-commands */
5102 /* command_new = 0; */
5104 /* Cancel repeated commands */
5110 /* Redraw the state (later) */
5111 p_ptr->redraw |= (PR_STATE);
5114 /* Cancel Resting */
5115 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5118 set_action(ACTION_NONE);
5121 /* Cancel running */
5127 /* Check for new panel if appropriate */
5128 if (center_player && !center_running) verify_panel();
5130 /* Calculate torch radius */
5131 p_ptr->update |= (PU_TORCH);
5133 /* Update monster flow */
5134 p_ptr->update |= (PU_FLOW);
5137 /* Flush the input if requested */
5138 if (flush_disturb) flush();