OSDN Git Service

scatter()、ネmon_scatter()、ホlos()、rojectable()、ヒハムケケ.
[hengband/hengband.git] / src / cave.c
1 /* File: cave.c */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.
9  */
10
11 /* Purpose: low level dungeon routines -BEN- */
12
13
14 #include "angband.h"
15
16
17 /*
18  * Support for Adam Bolt's tileset, lighting and transparency effects
19  * by Robert Ruehlmann (rr9@angband.org)
20  */
21
22 static byte display_autopick;
23 static int match_autopick;
24 static object_type *autopick_obj;
25 static int feat_priority;
26
27 /*
28  * Distance between two points via Newton-Raphson technique
29  */
30 int distance (int y1, int x1, int y2, int x2)
31 {
32         int dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
33         int dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
34
35         /* Squared distance */
36         int target = (dy * dy) + (dx * dx);
37
38         /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
39         int d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
40
41         int err;
42
43         /* Simple case */
44         if (!dy || !dx) return d;
45
46         while (1)
47         {
48                 /* Approximate error */
49                 err = (target - d * d) / (2 * d);
50
51                 /* No error - we are done */
52                 if (!err) break;
53
54                 /* Adjust distance */
55                 d += err;
56         }
57
58         return d;
59 }
60
61
62 /*
63  * Return TRUE if the given feature is a trap
64  */
65 bool is_trap(int feat)
66 {
67         return have_flag(f_info[feat].flags, FF_TRAP);
68 }
69
70
71 /*
72  * Return TRUE if the given grid is a known trap
73  */
74 bool is_known_trap(cave_type *c_ptr)
75 {
76         if (!c_ptr->mimic && !have_flag(f_flags_grid(c_ptr), FF_SECRET) &&
77             is_trap(c_ptr->feat)) return TRUE;
78         else
79                 return FALSE;
80 }
81
82
83 /*
84  * Return TRUE if the given grid is a closed door
85  */
86 bool is_closed_door(int feat)
87 {
88         feature_type *f_ptr = &f_info[feat];
89
90         return (have_flag(f_ptr->flags, FF_OPEN) || have_flag(f_ptr->flags, FF_BASH)) &&
91                !have_flag(f_ptr->flags, FF_MOVE);
92 }
93
94
95 /*
96  * Return TRUE if the given grid is a hidden closed door
97  */
98 bool is_hidden_door(cave_type *c_ptr)
99 {
100         if ((c_ptr->mimic || have_flag(f_flags_grid(c_ptr), FF_SECRET)) &&
101             is_closed_door(c_ptr->feat))
102                 return TRUE;
103         else
104                 return FALSE;
105 }
106
107
108 /*
109  * A simple, fast, integer-based line-of-sight algorithm.  By Joseph Hall,
110  * 4116 Brewster Drive, Raleigh NC 27606.  Email to jnh@ecemwl.ncsu.edu.
111  *
112  * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).
113  *
114  * The LOS begins at the center of the tile (x1,y1) and ends at the center of
115  * the tile (x2,y2).  If los() is to return TRUE, all of the tiles this line
116  * passes through must be floor tiles, except for (x1,y1) and (x2,y2).
117  *
118  * We assume that the "mathematical corner" of a non-floor tile does not
119  * block line of sight.
120  *
121  * Because this function uses (short) ints for all calculations, overflow may
122  * occur if dx and dy exceed 90.
123  *
124  * Once all the degenerate cases are eliminated, the values "qx", "qy", and
125  * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that
126  * we can use integer arithmetic.
127  *
128  * We travel from start to finish along the longer axis, starting at the border
129  * between the first and second tiles, where the y offset = .5 * slope, taking
130  * into account the scale factor.  See below.
131  *
132  * Also note that this function and the "move towards target" code do NOT
133  * share the same properties.  Thus, you can see someone, target them, and
134  * then fire a bolt at them, but the bolt may hit a wall, not them.  However,
135  * by clever choice of target locations, you can sometimes throw a "curve".
136  *
137  * Note that "line of sight" is not "reflexive" in all cases.
138  *
139  * Use the "projectable()" routine to test "spell/missile line of sight".
140  *
141  * Use the "update_view()" function to determine player line-of-sight.
142  */
143 bool los(int y1, int x1, int y2, int x2)
144 {
145         /* Delta */
146         int dx, dy;
147
148         /* Absolute */
149         int ax, ay;
150
151         /* Signs */
152         int sx, sy;
153
154         /* Fractions */
155         int qx, qy;
156
157         /* Scanners */
158         int tx, ty;
159
160         /* Scale factors */
161         int f1, f2;
162
163         /* Slope, or 1/Slope, of LOS */
164         int m;
165
166
167         /* Extract the offset */
168         dy = y2 - y1;
169         dx = x2 - x1;
170
171         /* Extract the absolute offset */
172         ay = ABS(dy);
173         ax = ABS(dx);
174
175
176         /* Handle adjacent (or identical) grids */
177         if ((ax < 2) && (ay < 2)) return TRUE;
178
179
180         /* Paranoia -- require "safe" origin */
181         /* if (!in_bounds(y1, x1)) return FALSE; */
182         /* if (!in_bounds(y2, x2)) return FALSE; */
183
184
185         /* Directly South/North */
186         if (!dx)
187         {
188                 /* South -- check for walls */
189                 if (dy > 0)
190                 {
191                         for (ty = y1 + 1; ty < y2; ty++)
192                         {
193                                 if (!cave_los_bold(ty, x1)) return FALSE;
194                         }
195                 }
196
197                 /* North -- check for walls */
198                 else
199                 {
200                         for (ty = y1 - 1; ty > y2; ty--)
201                         {
202                                 if (!cave_los_bold(ty, x1)) return FALSE;
203                         }
204                 }
205
206                 /* Assume los */
207                 return TRUE;
208         }
209
210         /* Directly East/West */
211         if (!dy)
212         {
213                 /* East -- check for walls */
214                 if (dx > 0)
215                 {
216                         for (tx = x1 + 1; tx < x2; tx++)
217                         {
218                                 if (!cave_los_bold(y1, tx)) return FALSE;
219                         }
220                 }
221
222                 /* West -- check for walls */
223                 else
224                 {
225                         for (tx = x1 - 1; tx > x2; tx--)
226                         {
227                                 if (!cave_los_bold(y1, tx)) return FALSE;
228                         }
229                 }
230
231                 /* Assume los */
232                 return TRUE;
233         }
234
235
236         /* Extract some signs */
237         sx = (dx < 0) ? -1 : 1;
238         sy = (dy < 0) ? -1 : 1;
239
240
241         /* Vertical "knights" */
242         if (ax == 1)
243         {
244                 if (ay == 2)
245                 {
246                         if (cave_los_bold(y1 + sy, x1)) return TRUE;
247                 }
248         }
249
250         /* Horizontal "knights" */
251         else if (ay == 1)
252         {
253                 if (ax == 2)
254                 {
255                         if (cave_los_bold(y1, x1 + sx)) return TRUE;
256                 }
257         }
258
259
260         /* Calculate scale factor div 2 */
261         f2 = (ax * ay);
262
263         /* Calculate scale factor */
264         f1 = f2 << 1;
265
266
267         /* Travel horizontally */
268         if (ax >= ay)
269         {
270                 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
271                 qy = ay * ay;
272                 m = qy << 1;
273
274                 tx = x1 + sx;
275
276                 /* Consider the special case where slope == 1. */
277                 if (qy == f2)
278                 {
279                         ty = y1 + sy;
280                         qy -= f1;
281                 }
282                 else
283                 {
284                         ty = y1;
285                 }
286
287                 /* Note (below) the case (qy == f2), where */
288                 /* the LOS exactly meets the corner of a tile. */
289                 while (x2 - tx)
290                 {
291                         if (!cave_los_bold(ty, tx)) return FALSE;
292
293                         qy += m;
294
295                         if (qy < f2)
296                         {
297                                 tx += sx;
298                         }
299                         else if (qy > f2)
300                         {
301                                 ty += sy;
302                                 if (!cave_los_bold(ty, tx)) return FALSE;
303                                 qy -= f1;
304                                 tx += sx;
305                         }
306                         else
307                         {
308                                 ty += sy;
309                                 qy -= f1;
310                                 tx += sx;
311                         }
312                 }
313         }
314
315         /* Travel vertically */
316         else
317         {
318                 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
319                 qx = ax * ax;
320                 m = qx << 1;
321
322                 ty = y1 + sy;
323
324                 if (qx == f2)
325                 {
326                         tx = x1 + sx;
327                         qx -= f1;
328                 }
329                 else
330                 {
331                         tx = x1;
332                 }
333
334                 /* Note (below) the case (qx == f2), where */
335                 /* the LOS exactly meets the corner of a tile. */
336                 while (y2 - ty)
337                 {
338                         if (!cave_los_bold(ty, tx)) return FALSE;
339
340                         qx += m;
341
342                         if (qx < f2)
343                         {
344                                 ty += sy;
345                         }
346                         else if (qx > f2)
347                         {
348                                 tx += sx;
349                                 if (!cave_los_bold(ty, tx)) return FALSE;
350                                 qx -= f1;
351                                 ty += sy;
352                         }
353                         else
354                         {
355                                 tx += sx;
356                                 qx -= f1;
357                                 ty += sy;
358                         }
359                 }
360         }
361
362         /* Assume los */
363         return TRUE;
364 }
365
366
367
368
369
370
371 /*
372  * Check for "local" illumination
373  */
374 static bool check_local_illumination(int y, int x)
375 {
376         /* Hack -- move towards player */
377         int yy = (y < py) ? (y + 1) : (y > py) ? (y - 1) : y;
378         int xx = (x < px) ? (x + 1) : (x > px) ? (x - 1) : x;
379
380         /* Check for "local" illumination */
381         return (cave[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
382 }
383
384
385 /*
386  * Update "local" illumination
387  */
388 void update_local_illumination(int y, int x)
389 {
390         int i, yy, xx;
391
392         if (!in_bounds(y, x)) return;
393
394         if ((y != py) && (x != px))
395         {
396                 yy = (y < py) ? (y - 1) : (y + 1);
397                 xx = (x < px) ? (x - 1) : (x + 1);
398
399                 if (player_has_los_bold(yy, xx))
400                 {
401                         /* Update the monster */
402                         if (cave[yy][xx].m_idx) update_mon(cave[yy][xx].m_idx, FALSE);
403
404                         /* Notice and redraw */
405                         note_spot(yy, xx);
406                         lite_spot(yy, xx);
407                 }
408         }
409         else if (x != px) /* y == py */
410         {
411                 xx = (x < px) ? (x - 1) : (x + 1);
412
413                 for (i = -1; i <= 1; i++)
414                 {
415                         yy = y + i;
416                         if (!player_has_los_bold(yy, xx)) continue;
417
418                         /* Update the monster */
419                         if (cave[yy][xx].m_idx) update_mon(cave[yy][xx].m_idx, FALSE);
420
421                         /* Notice and redraw */
422                         note_spot(yy, xx);
423                         lite_spot(yy, xx);
424                 }
425         }
426         else if (y != py) /* x == px */
427         {
428                 yy = (y < py) ? (y - 1) : (y + 1);
429
430                 for (i = -1; i <= 1; i++)
431                 {
432                         xx = x + i;
433                         if (!player_has_los_bold(yy, xx)) continue;
434
435                         /* Update the monster */
436                         if (cave[yy][xx].m_idx) update_mon(cave[yy][xx].m_idx, FALSE);
437
438                         /* Notice and redraw */
439                         note_spot(yy, xx);
440                         lite_spot(yy, xx);
441                 }
442         }
443         else /* Player's grid */
444         {
445                 for (i = 0; i < 9; i++)
446                 {
447                         yy = y + ddy_ddd[i];
448                         xx = x + ddx_ddd[i];
449                         if (!player_has_los_bold(yy, xx)) continue;
450
451                         /* Update the monster */
452                         if (cave[yy][xx].m_idx) update_mon(cave[yy][xx].m_idx, FALSE);
453
454                         /* Notice and redraw */
455                         note_spot(yy, xx);
456                         lite_spot(yy, xx);
457                 }
458         }
459 }
460
461
462 /*
463  * Can the player "see" the given grid in detail?
464  *
465  * He must have vision, illumination, and line of sight.
466  *
467  * Note -- "CAVE_LITE" is only set if the "torch" has "los()".
468  * So, given "CAVE_LITE", we know that the grid is "fully visible".
469  *
470  * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean
471  * that a wall is visible from any direction.  That would be odd.  Except
472  * under wizard light, which might make sense.  Thus, for walls, we require
473  * not only that they be "CAVE_GLOW", but also, that they be adjacent to a
474  * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is
475  * in line of sight of the player.
476  *
477  * This extra check is expensive, but it provides a more "correct" semantics.
478  *
479  * Note that we should not run this check on walls which are "outer walls" of
480  * the dungeon, or we will induce a memory fault, but actually verifying all
481  * of the locations would be extremely expensive.
482  *
483  * Thus, to speed up the function, we assume that all "perma-walls" which are
484  * "CAVE_GLOW" are "illuminated" from all sides.  This is correct for all cases
485  * except "vaults" and the "buildings" in town.  But the town is a hack anyway,
486  * and the player has more important things on his mind when he is attacking a
487  * monster vault.  It is annoying, but an extremely important optimization.
488  *
489  * Note that "glowing walls" are only considered to be "illuminated" if the
490  * grid which is next to the wall in the direction of the player is also a
491  * "glowing" grid.  This prevents the player from being able to "see" the
492  * walls of illuminated rooms from a corridor outside the room.
493  */
494 bool player_can_see_bold(int y, int x)
495 {
496         cave_type *c_ptr;
497         s16b feat;
498
499         /* Blind players see nothing */
500         if (p_ptr->blind) return FALSE;
501
502         /* Access the cave grid */
503         c_ptr = &cave[y][x];
504
505         /* Note that "torch-lite" yields "illumination" */
506         if (c_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
507
508         /* Require line of sight to the grid */
509         if (!player_has_los_bold(y, x)) return FALSE;
510
511         /* Noctovision of Ninja */
512         if (p_ptr->see_nocto) return TRUE;
513
514         /* Require "perma-lite" of the grid */
515         if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
516
517         /* Feature code (applying "mimic" field) */
518         feat = get_feat_mimic(c_ptr);
519
520         /* Floors are simple */
521         if (feat_supports_los(feat)) return TRUE;
522
523         /* Check for "local" illumination */
524         return check_local_illumination(y, x);
525 }
526
527
528
529 /*
530  * Returns true if the player's grid is dark
531  */
532 bool no_lite(void)
533 {
534         return (!player_can_see_bold(py, px));
535 }
536
537
538
539
540 /*
541  * Determine if a given location may be "destroyed"
542  *
543  * Used by destruction spells, and for placing stairs, etc.
544  */
545 bool cave_valid_bold(int y, int x)
546 {
547         cave_type *c_ptr = &cave[y][x];
548
549         s16b this_o_idx, next_o_idx = 0;
550
551
552         /* Forbid perma-grids */
553         if (cave_perma_grid(c_ptr)) return (FALSE);
554
555         /* Check objects */
556         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
557         {
558                 object_type *o_ptr;
559
560                 /* Acquire object */
561                 o_ptr = &o_list[this_o_idx];
562
563                 /* Acquire next object */
564                 next_o_idx = o_ptr->next_o_idx;
565
566                 /* Forbid artifact grids */
567                 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
568         }
569
570         /* Accept */
571         return (TRUE);
572 }
573
574
575
576
577 /*
578  * Determine if a given location may be "destroyed"
579  *
580  * Used by destruction spells, and for placing stairs, etc.
581  */
582 bool cave_valid_grid(cave_type *c_ptr)
583 {
584         s16b this_o_idx, next_o_idx = 0;
585
586
587         /* Forbid perma-grids */
588         if (cave_perma_grid(c_ptr)) return (FALSE);
589
590         /* Check objects */
591         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
592         {
593                 object_type *o_ptr;
594
595                 /* Acquire object */
596                 o_ptr = &o_list[this_o_idx];
597
598                 /* Acquire next object */
599                 next_o_idx = o_ptr->next_o_idx;
600
601                 /* Forbid artifact grids */
602                 if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE);
603         }
604
605         /* Accept */
606         return (TRUE);
607 }
608
609
610
611
612 /*
613  * Hack -- Legal monster codes
614  */
615 static char image_monster_hack[] = \
616 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
617
618 /*
619  * Hack -- Legal object codes
620  */
621 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
622
623 /*
624  * Mega-Hack -- Hallucinatory monster
625  */
626 static void image_monster(byte *ap, char *cp)
627 {
628         /* Random symbol from set above */
629         if (use_graphics)
630         {
631                 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
632
633                 *cp = r_ptr->x_char;
634                 *ap = r_ptr->x_attr;
635         }
636         else
637         /* Text mode */
638         {
639                 *cp = (one_in_(25) ?
640                        image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
641                        image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
642
643                 /* Random color */
644                 *ap = randint1(15);
645         }
646 }
647
648
649 /*
650  * Mega-Hack -- Hallucinatory object
651  */
652 static void image_object(byte *ap, char *cp)
653 {
654         if (use_graphics)
655         {
656                 object_kind *k_ptr = &k_info[randint1(max_k_idx-1)];
657
658                 *cp = k_ptr->x_char;
659                 *ap = k_ptr->x_attr;
660         }
661         else
662         {
663                 int n = sizeof(image_object_hack) - 1;
664
665                 *cp = image_object_hack[randint0(n)];
666
667                 /* Random color */
668                 *ap = randint1(15);
669         }
670 }
671
672
673
674 /*
675  * Hack -- Random hallucination
676  */
677 static void image_random(byte *ap, char *cp)
678 {
679         /* Normally, assume monsters */
680         if (randint0(100) < 75)
681         {
682                 image_monster(ap, cp);
683         }
684
685         /* Otherwise, assume objects */
686         else
687         {
688                 image_object(ap, cp);
689         }
690 }
691
692 /*
693  * This array lists the effects of "brightness" on various "base" colours.
694  *
695  * This is used to do dynamic lighting effects in ascii :-)
696  * At the moment, only the various "floor" tiles are affected.
697  *
698  * The layout of the array is [x][0] = light and [x][1] = dark.
699  */
700
701 byte lighting_colours[16][2] =
702 {
703         /* TERM_DARK */
704         {TERM_L_DARK, TERM_DARK},
705
706         /* TERM_WHITE */
707         {TERM_YELLOW, TERM_SLATE},
708
709         /* TERM_SLATE */
710         {TERM_WHITE, TERM_L_DARK},
711
712         /* TERM_ORANGE */
713         {TERM_L_UMBER, TERM_UMBER},
714
715         /* TERM_RED */
716         {TERM_RED, TERM_RED},
717
718         /* TERM_GREEN */
719         {TERM_L_GREEN, TERM_GREEN},
720
721         /* TERM_BLUE */
722         {TERM_BLUE, TERM_BLUE},
723
724         /* TERM_UMBER */
725         {TERM_L_UMBER, TERM_RED},
726
727         /* TERM_L_DARK */
728         {TERM_SLATE, TERM_L_DARK},
729
730         /* TERM_L_WHITE */
731         {TERM_WHITE, TERM_SLATE},
732
733         /* TERM_VIOLET */
734         {TERM_L_RED, TERM_BLUE},
735
736         /* TERM_YELLOW */
737         {TERM_YELLOW, TERM_ORANGE},
738
739         /* TERM_L_RED */
740         {TERM_L_RED, TERM_L_RED},
741
742         /* TERM_L_GREEN */
743         {TERM_L_GREEN, TERM_GREEN},
744
745         /* TERM_L_BLUE */
746         {TERM_L_BLUE, TERM_L_BLUE},
747
748         /* TERM_L_UMBER */
749         {TERM_L_UMBER, TERM_UMBER}
750 };
751
752
753 /*
754  * Mega-Hack -- Partial code of map_info() for darkened grids
755  * Note: Each variable is declared in map_info().
756  *       This macro modifies "feat", "f_ptr", "c" and "a".
757  */
758 #define darkened_grid_hack() \
759 { \
760         if (feat_supports_los(feat)) \
761         { \
762                 /* Unsafe cave grid -- idea borrowed from Unangband */ \
763                 if (view_unsafe_grids && (c_ptr->info & CAVE_UNSAFE)) \
764                         feat = FEAT_UNDETECTED; \
765                 else \
766                         feat = FEAT_NONE; \
767 \
768                 /* Access darkness */ \
769                 f_ptr = &f_info[feat]; \
770 \
771                 /* Char and attr of darkness */ \
772                 c = f_ptr->x_char[F_LIT_STANDARD]; \
773                 a = f_ptr->x_attr[F_LIT_STANDARD]; \
774         } \
775         else if (view_granite_lite && view_yellow_lite) \
776         { \
777                 /* Use a darkly darkened colour/tile */ \
778                 a = f_ptr->x_attr[F_LIT_DARKDARK]; \
779                 c = f_ptr->x_char[F_LIT_DARKDARK]; \
780         } \
781 } ;
782
783
784 /* Is this grid "darkened" by monster? */
785 #define darkened_grid(C) \
786         ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
787         !p_ptr->see_nocto && !p_ptr->blind)
788
789
790 /*
791  * Extract the attr/char to display at the given (legal) map location
792  *
793  * Basically, we "paint" the chosen attr/char in several passes, starting
794  * with any known "terrain features" (defaulting to darkness), then adding
795  * any known "objects", and finally, adding any known "monsters".  This
796  * is not the fastest method but since most of the calls to this function
797  * are made for grids with no monsters or objects, it is fast enough.
798  *
799  * Note that this function, if used on the grid containing the "player",
800  * will return the attr/char of the grid underneath the player, and not
801  * the actual player attr/char itself, allowing a lot of optimization
802  * in various "display" functions.
803  *
804  * Note that the "zero" entry in the feature/object/monster arrays are
805  * used to provide "special" attr/char codes, with "monster zero" being
806  * used for the player attr/char, "object zero" being used for the "stack"
807  * attr/char, and "feature zero" being used for the "nothing" attr/char,
808  * though this function makes use of only "feature zero".
809  *
810  * Note that monsters can have some "special" flags, including "ATTR_MULTI",
811  * which means their color changes, and "ATTR_CLEAR", which means they take
812  * the color of whatever is under them, and "CHAR_CLEAR", which means that
813  * they take the symbol of whatever is under them.  Technically, the flag
814  * "CHAR_MULTI" is supposed to indicate that a monster looks strange when
815  * examined, but this flag is currently ignored.
816  *
817  * Currently, we do nothing with multi-hued objects, because there are
818  * not any.  If there were, they would have to set "shimmer_objects"
819  * when they were created, and then new "shimmer" code in "dungeon.c"
820  * would have to be created handle the "shimmer" effect, and the code
821  * in "cave.c" would have to be updated to create the shimmer effect.
822  *
823  * Note the effects of hallucination.  Objects always appear as random
824  * "objects", monsters as random "monsters", and normal grids occasionally
825  * appear as random "monsters" or "objects", but note that these random
826  * "monsters" and "objects" are really just "colored ascii symbols".
827  *
828  * Note that "floors" and "invisible traps" (and "zero" features) are
829  * drawn as "floors" using a special check for optimization purposes,
830  * and these are the only features which get drawn using the special
831  * lighting effects activated by "view_special_lite".
832  *
833  * Note the use of the "mimic" field in the "terrain feature" processing,
834  * which allows any feature to "pretend" to be another feature.  This is
835  * used to "hide" secret doors, and to make all "doors" appear the same,
836  * and all "walls" appear the same, and "hidden" treasure stay hidden.
837  * It is possible to use this field to make a feature "look" like a floor,
838  * but the "special lighting effects" for floors will not be used.
839  *
840  * Note the use of the new "terrain feature" information.  Note that the
841  * assumption that all interesting "objects" and "terrain features" are
842  * memorized allows extremely optimized processing below.  Note the use
843  * of separate flags on objects to mark them as memorized allows a grid
844  * to have memorized "terrain" without granting knowledge of any object
845  * which may appear in that grid.
846  *
847  * Note the efficient code used to determine if a "floor" grid is
848  * "memorized" or "viewable" by the player, where the test for the
849  * grid being "viewable" is based on the facts that (1) the grid
850  * must be "lit" (torch-lit or perma-lit), (2) the grid must be in
851  * line of sight, and (3) the player must not be blind, and uses the
852  * assumption that all torch-lit grids are in line of sight.
853  *
854  * Note that floors (and invisible traps) are the only grids which are
855  * not memorized when seen, so only these grids need to check to see if
856  * the grid is "viewable" to the player (if it is not memorized).  Since
857  * most non-memorized grids are in fact walls, this induces *massive*
858  * efficiency, at the cost of *forcing* the memorization of non-floor
859  * grids when they are first seen.  Note that "invisible traps" are
860  * always treated exactly like "floors", which prevents "cheating".
861  *
862  * Note the "special lighting effects" which can be activated for floor
863  * grids using the "view_special_lite" option (for "white" floor grids),
864  * causing certain grids to be displayed using special colors.  If the
865  * player is "blind", we will use "dark gray", else if the grid is lit
866  * by the torch, and the "view_yellow_lite" option is set, we will use
867  * "yellow", else if the grid is "dark", we will use "dark gray", else
868  * if the grid is not "viewable", and the "view_bright_lite" option is
869  * set, and the we will use "slate" (gray).  We will use "white" for all
870  * other cases, in particular, for illuminated viewable floor grids.
871  *
872  * Note the "special lighting effects" which can be activated for wall
873  * grids using the "view_granite_lite" option (for "white" wall grids),
874  * causing certain grids to be displayed using special colors.  If the
875  * player is "blind", we will use "dark gray", else if the grid is lit
876  * by the torch, and the "view_yellow_lite" option is set, we will use
877  * "yellow", else if the "view_bright_lite" option is set, and the grid
878  * is not "viewable", or is "dark", or is glowing, but not when viewed
879  * from the player's current location, we will use "slate" (gray).  We
880  * will use "white" for all other cases, in particular, for correctly
881  * illuminated viewable wall grids.
882  *
883  * Note that, when "view_granite_lite" is set, we use an inline version
884  * of the "player_can_see_bold()" function to check the "viewability" of
885  * grids when the "view_bright_lite" option is set, and we do NOT use
886  * any special colors for "dark" wall grids, since this would allow the
887  * player to notice the walls of illuminated rooms from a hallway that
888  * happened to run beside the room.  The alternative, by the way, would
889  * be to prevent the generation of hallways next to rooms, but this
890  * would still allow problems when digging towards a room.
891  *
892  * Note that bizarre things must be done when the "attr" and/or "char"
893  * codes have the "high-bit" set, since these values are used to encode
894  * various "special" pictures in some versions, and certain situations,
895  * such as "multi-hued" or "clear" monsters, cause the attr/char codes
896  * to be "scrambled" in various ways.
897  *
898  * Note that eventually we may use the "&" symbol for embedded treasure,
899  * and use the "*" symbol to indicate multiple objects, though this will
900  * have to wait for Angband 2.8.0 or later.  Note that currently, this
901  * is not important, since only one object or terrain feature is allowed
902  * in each grid.  If needed, "k_info[0]" will hold the "stack" attr/char.
903  *
904  * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of
905  * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect
906  * then a whole lot of code should be changed...  XXX XXX
907  */
908 void map_info(int y, int x, byte *ap, char *cp, byte *tap, char *tcp)
909 {
910         /* Get the cave */
911         cave_type *c_ptr = &cave[y][x];
912
913         s16b this_o_idx, next_o_idx = 0;
914
915         /* Feature code (applying "mimic" field) */
916         s16b feat = get_feat_mimic(c_ptr);
917
918         /* Access floor */
919         feature_type *f_ptr = &f_info[feat];
920
921         byte a;
922         byte c;
923
924         /* Boring grids (floors, etc) */
925         if (!have_flag(f_ptr->flags, FF_REMEMBER))
926         {
927                 /* Memorized (or visible) floor */
928                 if ((c_ptr->info & CAVE_MARK) ||
929                   (((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) ||
930                    ((c_ptr->info & CAVE_VIEW) &&
931                   (((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))) &&
932                    !p_ptr->blind))
933                 {
934                         /* Normal char */
935                         c = f_ptr->x_char[F_LIT_STANDARD];
936
937                         /* Normal attr */
938                         a = f_ptr->x_attr[F_LIT_STANDARD];
939
940                         if (p_ptr->wild_mode)
941                         {
942                                 /* Special lighting effects */
943                                 /* Handle "blind" */
944                                 if (view_special_lite && p_ptr->blind)
945                                 {
946                                         /* Use a darkly darkened colour/tile */
947                                         a = f_ptr->x_attr[F_LIT_DARKDARK];
948                                         c = f_ptr->x_char[F_LIT_DARKDARK];
949                                 }
950                         }
951
952                         /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
953                         else if (darkened_grid(c_ptr))
954                         {
955                                 darkened_grid_hack();
956                         }
957
958                         /* Special lighting effects */
959                         else if (view_special_lite)
960                         {
961                                 /* Handle "blind" */
962                                 if (p_ptr->blind)
963                                 {
964                                         /* Use a darkly darkened colour/tile */
965                                         a = f_ptr->x_attr[F_LIT_DARKDARK];
966                                         c = f_ptr->x_char[F_LIT_DARKDARK];
967                                 }
968
969                                 /* Handle "torch-lit" grids */
970                                 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
971                                 {
972                                         /* Torch lite */
973                                         if (view_yellow_lite)
974                                         {
975                                                 /* Use a brightly lit colour/tile */
976                                                 a = f_ptr->x_attr[F_LIT_LITE];
977                                                 c = f_ptr->x_char[F_LIT_LITE];
978                                         }
979                                 }
980
981                                 /* Handle "dark" grids */
982                                 else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
983                                 {
984                                         /* Use a darkly darkened colour/tile */
985                                         a = f_ptr->x_attr[F_LIT_DARKDARK];
986                                         c = f_ptr->x_char[F_LIT_DARKDARK];
987                                 }
988
989                                 /* Handle "out-of-sight" grids */
990                                 else if (!(c_ptr->info & CAVE_VIEW))
991                                 {
992                                         /* Special flag */
993                                         if (view_bright_lite)
994                                         {
995                                                 /* Use a darkened colour/tile */
996                                                 a = f_ptr->x_attr[F_LIT_DARK];
997                                                 c = f_ptr->x_char[F_LIT_DARK];
998                                         }
999                                 }
1000                         }
1001                 }
1002
1003                 /* Unknown */
1004                 else
1005                 {
1006                         /* Unsafe cave grid -- idea borrowed from Unangband */
1007                         if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1008                                 feat = FEAT_UNDETECTED;
1009                         else
1010                                 feat = FEAT_NONE;
1011
1012                         /* Access darkness */
1013                         f_ptr = &f_info[feat];
1014
1015                         /* Normal attr */
1016                         a = f_ptr->x_attr[F_LIT_STANDARD];
1017
1018                         /* Normal char */
1019                         c = f_ptr->x_char[F_LIT_STANDARD];
1020                 }
1021         }
1022
1023         /* Interesting grids (non-floors) */
1024         else
1025         {
1026                 /* Memorized grids */
1027                 if (c_ptr->info & CAVE_MARK)
1028                 {
1029                         /* Normal char */
1030                         c = f_ptr->x_char[F_LIT_STANDARD];
1031
1032                         /* Normal attr */
1033                         a = f_ptr->x_attr[F_LIT_STANDARD];
1034
1035                         if (p_ptr->wild_mode)
1036                         {
1037                                 /* Special lighting effects */
1038                                 /* Handle "blind" */
1039                                 if (view_granite_lite && p_ptr->blind)
1040                                 {
1041                                         /* Use a darkened colour/tile */
1042                                         a = f_ptr->x_attr[F_LIT_DARK];
1043                                         c = f_ptr->x_char[F_LIT_DARK];
1044                                 }
1045                         }
1046
1047                         /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1048                         else if (darkened_grid(c_ptr))
1049                         {
1050                                 darkened_grid_hack();
1051                         }
1052
1053                         /* Special lighting effects */
1054                         else if (view_granite_lite)
1055                         {
1056                                 /* Handle "blind" */
1057                                 if (p_ptr->blind)
1058                                 {
1059                                         /* Use a darkened colour/tile */
1060                                         a = f_ptr->x_attr[F_LIT_DARK];
1061                                         c = f_ptr->x_char[F_LIT_DARK];
1062                                 }
1063
1064                                 /* Handle "torch-lit" grids */
1065                                 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1066                                 {
1067                                         /* Torch lite */
1068                                         if (view_yellow_lite)
1069                                         {
1070                                                 /* Use a brightly lit colour/tile */
1071                                                 a = f_ptr->x_attr[F_LIT_LITE];
1072                                                 c = f_ptr->x_char[F_LIT_LITE];
1073                                         }
1074                                 }
1075
1076                                 /* Handle "view_bright_lite" */
1077                                 else if (view_bright_lite)
1078                                 {
1079                                         /* Not viewable */
1080                                         if (!(c_ptr->info & CAVE_VIEW))
1081                                         {
1082                                                 /* Use a darkened colour/tile */
1083                                                 a = f_ptr->x_attr[F_LIT_DARK];
1084                                                 c = f_ptr->x_char[F_LIT_DARK];
1085                                         }
1086
1087                                         /* Not glowing */
1088                                         else if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1089                                         {
1090                                                 /* Use a darkened colour/tile */
1091                                                 a = f_ptr->x_attr[F_LIT_DARK];
1092                                                 c = f_ptr->x_char[F_LIT_DARK];
1093                                         }
1094
1095                                         /* Not glowing correctly */
1096                                         else if (!feat_supports_los(feat) && !check_local_illumination(y, x))
1097                                         {
1098                                                 /* Use a darkened colour/tile */
1099                                                 a = f_ptr->x_attr[F_LIT_DARK];
1100                                                 c = f_ptr->x_char[F_LIT_DARK];
1101                                         }
1102                                 }
1103                         }
1104                 }
1105
1106                 /* Unknown */
1107                 else
1108                 {
1109                         /* Unsafe cave grid -- idea borrowed from Unangband */
1110                         if (view_unsafe_grids && (c_ptr->info & (CAVE_UNSAFE)))
1111                                 feat = FEAT_UNDETECTED;
1112                         else
1113                                 feat = FEAT_NONE;
1114
1115                         /* Access feature */
1116                         f_ptr = &f_info[feat];
1117
1118                         /* Normal attr */
1119                         a = f_ptr->x_attr[F_LIT_STANDARD];
1120
1121                         /* Normal char */
1122                         c = f_ptr->x_char[F_LIT_STANDARD];
1123                 }
1124         }
1125
1126         if (feat_priority == -1) feat_priority = f_ptr->priority;
1127
1128         /* Save the terrain info for the transparency effects */
1129         (*tap) = a;
1130         (*tcp) = c;
1131
1132         /* Save the info */
1133         (*ap) = a;
1134         (*cp) = c;
1135
1136         /* Hack -- rare random hallucination, except on outer dungeon walls */
1137         if (p_ptr->image)
1138         {
1139                 if (one_in_(256))
1140                 {
1141                         /* Hallucinate */
1142                         image_random(ap, cp);
1143                 }
1144         }
1145
1146         /* Objects */
1147         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1148         {
1149                 object_type *o_ptr;
1150
1151                 /* Acquire object */
1152                 o_ptr = &o_list[this_o_idx];
1153
1154                 /* Acquire next object */
1155                 next_o_idx = o_ptr->next_o_idx;
1156
1157                 /* Memorized objects */
1158                 if (o_ptr->marked)
1159                 {
1160                         if (display_autopick)
1161                         {
1162                                 byte act;
1163
1164                                 match_autopick = is_autopick(o_ptr);
1165                                 if(match_autopick == -1)
1166                                         continue;
1167
1168                                 act = autopick_list[match_autopick].action;
1169
1170                                 if ((act & DO_DISPLAY) && (act & display_autopick))
1171                                 {
1172                                         autopick_obj = o_ptr;
1173                                 }
1174                                 else
1175                                 {
1176                                         match_autopick = -1;
1177                                         continue;
1178                                 }
1179                         }
1180                         /* Normal char */
1181                         (*cp) = object_char(o_ptr);
1182
1183                         /* Normal attr */
1184                         (*ap) = object_attr(o_ptr);
1185
1186                         feat_priority = 20;
1187
1188                         /* Hack -- hallucination */
1189                         if (p_ptr->image) image_object(ap, cp);
1190
1191                         /* Done */
1192                         break;
1193                 }
1194         }
1195
1196
1197         /* Handle monsters */
1198         if (c_ptr->m_idx && display_autopick == 0 )
1199         {
1200                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1201
1202                 /* Visible monster */
1203                 if (m_ptr->ml)
1204                 {
1205                         monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1206
1207                         feat_priority = 30;
1208
1209                         /* Hallucination */
1210                         if (p_ptr->image)
1211                         {
1212                                 /*
1213                                  * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1214                                  * flags are always unseen.
1215                                  */
1216                                 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1217                                 {
1218                                         /* Do nothing */
1219                                 }
1220                                 else
1221                                 {
1222                                         /* Hallucinatory monster */
1223                                         image_monster(ap, cp);
1224                                 }
1225                         }
1226                         else
1227                         {
1228                                 /* Monster attr/char */
1229                                 a = r_ptr->x_attr;
1230                                 c = r_ptr->x_char;
1231
1232                                 /* Normal monsters */
1233                                 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
1234                                                            | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
1235                                 {
1236                                         /* Desired monster attr/char */
1237                                         *ap = a;
1238                                         *cp = c;
1239                                 }
1240
1241                                 /*
1242                                  * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1243                                  * flags are always unseen.
1244                                  */
1245                                 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
1246                                 {
1247                                         /* Do nothing */
1248                                 }
1249
1250                                 else
1251                                 {
1252                                         /***  Monster's attr  ***/
1253                                         if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
1254                                         {
1255                                                 /* Clear-attr */
1256                                                 /* Do nothing */
1257                                         }
1258                                         else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
1259                                         {
1260                                                 /* Multi-hued attr */
1261                                                 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
1262                                                 else switch (randint1(7))
1263                                                 {
1264                                                 case 1: *ap = TERM_RED;     break;
1265                                                 case 2: *ap = TERM_L_RED;   break;
1266                                                 case 3: *ap = TERM_WHITE;   break;
1267                                                 case 4: *ap = TERM_L_GREEN; break;
1268                                                 case 5: *ap = TERM_BLUE;    break;
1269                                                 case 6: *ap = TERM_L_DARK;  break;
1270                                                 case 7: *ap = TERM_GREEN;   break;
1271                                                 }
1272                                         }
1273                                         else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
1274                                         {
1275                                                 /* Use semi-random attr (usually mimics' colors vary) */
1276                                                 *ap = c_ptr->m_idx % 15 + 1;
1277                                         }
1278                                         else
1279                                         {
1280                                                 /* Normal case */
1281                                                 *ap = a;
1282                                         }
1283
1284                                         /***  Monster's char  ***/
1285                                         if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
1286                                         {
1287                                                 /* Clear-char */
1288                                                 /* Do nothing */
1289                                         }
1290                                         else if (r_ptr->flags1 & RF1_SHAPECHANGER)
1291                                         {
1292                                                 if (use_graphics)
1293                                                 {
1294                                                         monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
1295                                                         *cp = tmp_r_ptr->x_char;
1296                                                         *ap = tmp_r_ptr->x_attr;
1297                                                 }
1298                                                 else
1299                                                 {
1300                                                         *cp = (one_in_(25) ?
1301                                                                image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1302                                                                image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1303                                                 }
1304                                         }
1305                                         else
1306                                         {
1307                                                 /* Normal case */
1308                                                 *cp = c;
1309                                         }
1310                                 }
1311                         }
1312                 }
1313         }
1314
1315         /* Handle "player" */
1316         if (player_bold(y, x))
1317         {
1318                 monster_race *r_ptr = &r_info[0];
1319
1320                 /* Get the "player" attr */
1321                 *ap = r_ptr->x_attr;
1322
1323                 /* Get the "player" char */
1324                 *cp = r_ptr->x_char;
1325
1326                 feat_priority = 31;
1327         }
1328 }
1329
1330
1331 /*
1332  * Calculate panel colum of a location in the map
1333  */
1334 static int panel_col_of(int col)
1335 {
1336         col -= panel_col_min;
1337         if (use_bigtile) col *= 2;
1338         return col + 13; 
1339 }
1340
1341
1342 /*
1343  * Moves the cursor to a given MAP (y,x) location
1344  */
1345 void move_cursor_relative(int row, int col)
1346 {
1347         /* Real co-ords convert to screen positions */
1348         row -= panel_row_prt;
1349
1350         /* Go there */
1351         Term_gotoxy(panel_col_of(col), row);
1352 }
1353
1354
1355
1356 /*
1357  * Place an attr/char pair at the given map coordinate, if legal.
1358  */
1359 void print_rel(char c, byte a, int y, int x)
1360 {
1361         /* Only do "legal" locations */
1362         if (panel_contains(y, x))
1363         {
1364                 /* Hack -- fake monochrome */
1365                 if (!use_graphics)
1366                 {
1367                         if (world_monster) a = TERM_DARK;
1368                         else if (IS_INVULN() || world_player) a = TERM_WHITE;
1369                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
1370                 }
1371
1372                 /* Draw the char using the attr */
1373                 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, 0, 0);
1374         }
1375 }
1376
1377
1378
1379
1380
1381 /*
1382  * Memorize interesting viewable object/features in the given grid
1383  *
1384  * This function should only be called on "legal" grids.
1385  *
1386  * This function will memorize the object and/or feature in the given
1387  * grid, if they are (1) viewable and (2) interesting.  Note that all
1388  * objects are interesting, all terrain features except floors (and
1389  * invisible traps) are interesting, and floors (and invisible traps)
1390  * are interesting sometimes (depending on various options involving
1391  * the illumination of floor grids).
1392  *
1393  * The automatic memorization of all objects and non-floor terrain
1394  * features as soon as they are displayed allows incredible amounts
1395  * of optimization in various places, especially "map_info()".
1396  *
1397  * Note that the memorization of objects is completely separate from
1398  * the memorization of terrain features, preventing annoying floor
1399  * memorization when a detected object is picked up from a dark floor,
1400  * and object memorization when an object is dropped into a floor grid
1401  * which is memorized but out-of-sight.
1402  *
1403  * This function should be called every time the "memorization" of
1404  * a grid (or the object in a grid) is called into question, such
1405  * as when an object is created in a grid, when a terrain feature
1406  * "changes" from "floor" to "non-floor", when any grid becomes
1407  * "illuminated" or "viewable", and when a "floor" grid becomes
1408  * "torch-lit".
1409  *
1410  * Note the relatively efficient use of this function by the various
1411  * "update_view()" and "update_lite()" calls, to allow objects and
1412  * terrain features to be memorized (and drawn) whenever they become
1413  * viewable or illuminated in any way, but not when they "maintain"
1414  * or "lose" their previous viewability or illumination.
1415  *
1416  * Note the butchered "internal" version of "player_can_see_bold()",
1417  * optimized primarily for the most common cases, that is, for the
1418  * non-marked floor grids.
1419  */
1420 void note_spot(int y, int x)
1421 {
1422         cave_type *c_ptr = &cave[y][x];
1423
1424         s16b this_o_idx, next_o_idx = 0;
1425
1426
1427         /* Blind players see nothing */
1428         if (p_ptr->blind) return;
1429
1430         /* Analyze non-torch-lit grids */
1431         if (!(c_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1432         {
1433                 /* Require line of sight to the grid */
1434                 if (!(c_ptr->info & (CAVE_VIEW))) return;
1435
1436                 /* Require "perma-lite" of the grid */
1437                 if ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1438                 {
1439                         /* Not Ninja */
1440                         if (!p_ptr->see_nocto) return;
1441                 }
1442         }
1443
1444
1445         /* Hack -- memorize objects */
1446         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1447         {
1448                 object_type *o_ptr = &o_list[this_o_idx];
1449
1450                 /* Acquire next object */
1451                 next_o_idx = o_ptr->next_o_idx;
1452
1453                 /* Memorize objects */
1454                 o_ptr->marked |= OM_FOUND;
1455         }
1456
1457
1458         /* Hack -- memorize grids */
1459         if (!(c_ptr->info & (CAVE_MARK)))
1460         {
1461                 /* Feature code (applying "mimic" field) */
1462                 s16b feat = get_feat_mimic(c_ptr);
1463
1464                 /* Memorize some "boring" grids */
1465                 if (!have_flag(f_info[feat].flags, FF_REMEMBER))
1466                 {
1467                         /* Option -- memorize all torch-lit floors */
1468                         if (view_torch_grids &&
1469                             ((c_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1470                         {
1471                                 /* Memorize */
1472                                 c_ptr->info |= (CAVE_MARK);
1473                         }
1474
1475                         /* Option -- memorize all perma-lit floors */
1476                         else if (view_perma_grids && ((c_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1477                         {
1478                                 /* Memorize */
1479                                 c_ptr->info |= (CAVE_MARK);
1480                         }
1481                 }
1482
1483                 /* Memorize normal grids */
1484                 else if (feat_supports_los(feat))
1485                 {
1486                         /* Memorize */
1487                         c_ptr->info |= (CAVE_MARK);
1488                 }
1489
1490                 /* Memorize torch-lit walls */
1491                 else if (c_ptr->info & (CAVE_LITE | CAVE_MNLT))
1492                 {
1493                         /* Memorize */
1494                         c_ptr->info |= (CAVE_MARK);
1495                 }
1496
1497                 /* Memorize walls seen by noctovision of Ninja */
1498                 else if (p_ptr->see_nocto)
1499                 {
1500                         /* Memorize */
1501                         c_ptr->info |= (CAVE_MARK);
1502                 }
1503
1504                 /* Memorize certain non-torch-lit wall grids */
1505                 else if (check_local_illumination(y, x))
1506                 {
1507                         /* Memorize */
1508                         c_ptr->info |= (CAVE_MARK);
1509                 }
1510         }
1511 }
1512
1513
1514 void display_dungeon(void)
1515 {
1516         int x, y;
1517         byte a;
1518         char c;
1519
1520         byte ta;
1521         char tc;
1522
1523         for (x = px - Term->wid / 2 + 1; x <= px + Term->wid / 2; x++)
1524         {
1525                 for (y = py - Term->hgt / 2 + 1; y <= py + Term->hgt / 2; y++)
1526                 {
1527                         if (in_bounds2(y, x))
1528                         {
1529
1530                                 /* Examine the grid */
1531                                 map_info(y, x, &a, &c, &ta, &tc);
1532
1533                                 /* Hack -- fake monochrome */
1534                                 if (!use_graphics)
1535                                 {
1536                                         if (world_monster) a = TERM_DARK;
1537                                         else if (IS_INVULN() || world_player) a = TERM_WHITE;
1538                                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
1539                                 }
1540
1541                                 /* Hack -- Queue it */
1542                                 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1543                         }
1544                         else
1545                         {
1546                                 /* Clear out-of-bound tiles */
1547
1548                                 /* Access darkness */
1549                                 feature_type *f_ptr = &f_info[FEAT_NONE];
1550
1551                                 /* Normal attr */
1552                                 a = f_ptr->x_attr[F_LIT_STANDARD];
1553
1554                                 /* Normal char */
1555                                 c = f_ptr->x_char[F_LIT_STANDARD];
1556
1557                                 /* Hack -- Queue it */
1558                                 Term_queue_char(x - px + Term->wid / 2 - 1, y - py + Term->hgt / 2 - 1, a, c, ta, tc);
1559                         }
1560                 }
1561         }
1562 }
1563
1564
1565 /*
1566  * Redraw (on the screen) a given MAP location
1567  *
1568  * This function should only be called on "legal" grids
1569  */
1570 void lite_spot(int y, int x)
1571 {
1572         /* Redraw if on screen */
1573         if (panel_contains(y, x) && in_bounds2(y, x))
1574         {
1575                 byte a;
1576                 char c;
1577
1578                 byte ta;
1579                 char tc;
1580
1581                 /* Examine the grid */
1582                 map_info(y, x, &a, &c, &ta, &tc);
1583
1584                 /* Hack -- fake monochrome */
1585                 if (!use_graphics)
1586                 {
1587                         if (world_monster) a = TERM_DARK;
1588                         else if (IS_INVULN() || world_player) a = TERM_WHITE;
1589                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
1590                 }
1591
1592                 /* Hack -- Queue it */
1593                 Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1594
1595                 /* Update sub-windows */
1596                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1597         }
1598 }
1599
1600
1601 /*
1602  * Prints the map of the dungeon
1603  *
1604  * Note that, for efficiency, we contain an "optimized" version
1605  * of both "lite_spot()" and "print_rel()", and that we use the
1606  * "lite_spot()" function to display the player grid, if needed.
1607  */
1608 void prt_map(void)
1609 {
1610         int     x, y;
1611         int     v;
1612
1613         /* map bounds */
1614         s16b xmin, xmax, ymin, ymax;
1615
1616         int wid, hgt;
1617
1618         /* Get size */
1619         Term_get_size(&wid, &hgt);
1620
1621         /* Remove map offset */
1622         wid -= COL_MAP + 2;
1623         hgt -= ROW_MAP + 2;
1624
1625         /* Access the cursor state */
1626         (void)Term_get_cursor(&v);
1627
1628         /* Hide the cursor */
1629         (void)Term_set_cursor(0);
1630
1631         /* Get bounds */
1632         xmin = (0 < panel_col_min) ? panel_col_min : 0;
1633         xmax = (cur_wid - 1 > panel_col_max) ? panel_col_max : cur_wid - 1;
1634         ymin = (0 < panel_row_min) ? panel_row_min : 0;
1635         ymax = (cur_hgt - 1 > panel_row_max) ? panel_row_max : cur_hgt - 1;
1636
1637         /* Bottom section of screen */
1638         for (y = 1; y <= ymin - panel_row_prt; y++)
1639         {
1640                 /* Erase the section */
1641                 Term_erase(COL_MAP, y, wid);
1642         }
1643
1644         /* Top section of screen */
1645         for (y = ymax - panel_row_prt; y <= hgt; y++)
1646         {
1647                 /* Erase the section */
1648                 Term_erase(COL_MAP, y, wid);
1649         }
1650
1651         /* Dump the map */
1652         for (y = ymin; y <= ymax; y++)
1653         {
1654                 /* Scan the columns of row "y" */
1655                 for (x = xmin; x <= xmax; x++)
1656                 {
1657                         byte a;
1658                         char c;
1659
1660                         byte ta;
1661                         char tc;
1662
1663                         /* Determine what is there */
1664                         map_info(y, x, &a, &c, &ta, &tc);
1665
1666                         /* Hack -- fake monochrome */
1667                         if (!use_graphics)
1668                         {
1669                                 if (world_monster) a = TERM_DARK;
1670                                 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1671                                 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1672                         }
1673
1674                         /* Efficiency -- Redraw that grid of the map */
1675                         Term_queue_bigchar(panel_col_of(x), y-panel_row_prt, a, c, ta, tc);
1676                 }
1677         }
1678
1679         /* Display player */
1680         lite_spot(py, px);
1681
1682         /* Restore the cursor */
1683         (void)Term_set_cursor(v);
1684 }
1685
1686
1687
1688 /*
1689  * print project path
1690  */
1691 void prt_path(int y, int x)
1692 {
1693         int i;
1694         int path_n;
1695         u16b path_g[512];
1696         int default_color = TERM_SLATE;
1697
1698         if (!display_path) return;
1699         if (-1 == project_length)
1700                 return;
1701
1702         /* Get projection path */
1703         path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), py, px, y, x, PROJECT_PATH|PROJECT_THRU);
1704
1705         /* Redraw map */
1706         p_ptr->redraw |= (PR_MAP);
1707
1708         /* Redraw stuff */
1709         redraw_stuff();
1710
1711         /* Draw path */
1712         for (i = 0; i < path_n; i++)
1713         {
1714                 int ny = GRID_Y(path_g[i]);
1715                 int nx = GRID_X(path_g[i]);
1716                 cave_type *c_ptr = &cave[ny][nx];
1717
1718                 if (panel_contains(ny, nx))
1719                 {
1720                         byte a = default_color;
1721                         char c;
1722
1723                         byte ta;
1724                         char tc;
1725
1726                         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1727                         {
1728                                 /* Determine what is there */
1729                                 map_info(ny, nx, &a, &c, &ta, &tc);
1730
1731                                 if (!is_ascii_graphics(a))
1732                                         a = default_color;
1733                                 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1734                                         a = default_color;
1735                                 else if (a == default_color)
1736                                         a = TERM_WHITE;
1737                         }
1738
1739                         if (!use_graphics)
1740                         {
1741                                 if (world_monster) a = TERM_DARK;
1742                                 else if (IS_INVULN() || world_player) a = TERM_WHITE;
1743                                 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1744                         }
1745
1746                         c = '*';
1747
1748                         /* Hack -- Queue it */
1749                         Term_queue_bigchar(panel_col_of(nx), ny-panel_row_prt, a, c, ta, tc);
1750                 }
1751
1752                 /* Known Wall */
1753                 if ((c_ptr->info & CAVE_MARK) && !have_flag(f_flags_grid(c_ptr), FF_PROJECT)) break;
1754
1755                 /* Change color */
1756                 if (nx == x && ny == y) default_color = TERM_L_DARK;
1757         }
1758 }
1759
1760
1761 static cptr simplify_list[][2] =
1762 {
1763 #ifdef JP
1764         {"¤ÎËâË¡½ñ", ""},
1765         {NULL, NULL}
1766 #else
1767         {"^Ring of ",   "="},
1768         {"^Amulet of ", "\""},
1769         {"^Scroll of ", "?"},
1770         {"^Scroll titled ", "?"},
1771         {"^Wand of "  , "-"},
1772         {"^Rod of "   , "-"},
1773         {"^Staff of " , "_"},
1774         {"^Potion of ", "!"},
1775         {" Spellbook ",""},
1776         {"^Book of ",   ""},
1777         {" Magic [",   "["},
1778         {" Book [",    "["},
1779         {" Arts [",    "["},
1780         {"^Set of ",    ""},
1781         {"^Pair of ",   ""},
1782         {NULL, NULL}
1783 #endif
1784 };
1785
1786 static void display_shortened_item_name(object_type *o_ptr, int y)
1787 {
1788         char buf[MAX_NLEN];
1789         char *c = buf;
1790         int len = 0;
1791         byte attr;
1792
1793         object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
1794         attr = tval_to_attr[o_ptr->tval % 128];
1795
1796         if (p_ptr->image)
1797         {
1798                 attr = TERM_WHITE;
1799 #ifdef JP
1800                 strcpy(buf, "²¿¤«´ñ̯¤Êʪ");
1801 #else
1802                 strcpy(buf, "something strange");
1803 #endif
1804         }
1805
1806         for (c = buf; *c; c++)
1807         {
1808                 int i;
1809                 for (i = 0; simplify_list[i][1]; i++)
1810                 {
1811                         cptr org_w = simplify_list[i][0];
1812
1813                         if (*org_w == '^')
1814                         {
1815                                 if (c == buf)
1816                                         org_w++;
1817                                 else
1818                                         continue;
1819                         }
1820
1821                         if (!strncmp(c, org_w, strlen(org_w)))
1822                         {
1823                                 char *s = c;
1824                                 cptr tmp = simplify_list[i][1];
1825                                 while (*tmp)
1826                                         *s++ = *tmp++;
1827                                 tmp = c + strlen(org_w);
1828                                 while (*tmp)
1829                                         *s++ = *tmp++;
1830                                 *s = '\0';
1831                         }
1832                 }
1833         }
1834
1835         c = buf;
1836         len = 0;
1837         /* È¾³Ñ 12 Ê¸»úʬ¤ÇÀÚ¤ë */
1838         while(*c)
1839         {
1840 #ifdef JP
1841                 if(iskanji(*c))
1842                 {
1843                         if(len + 2 > 12) break;
1844                         c+=2;
1845                         len+=2;
1846                 }
1847                 else
1848 #endif
1849                 {
1850                         if(len + 1 > 12) break;
1851                         c++;
1852                         len++;
1853                 }
1854         }
1855         *c='\0';
1856         Term_putstr(0, y, 12, attr, buf);
1857 }
1858
1859 /*
1860  * Display a "small-scale" map of the dungeon in the active Term
1861  */
1862 void display_map(int *cy, int *cx)
1863 {
1864         int i, j, x, y;
1865
1866         byte ta;
1867         char tc;
1868
1869         byte tp;
1870
1871         byte **bigma;
1872         char **bigmc;
1873         byte **bigmp;
1874
1875         byte **ma;
1876         char **mc;
1877         byte **mp;
1878
1879         /* Save lighting effects */
1880         bool old_view_special_lite = view_special_lite;
1881         bool old_view_granite_lite = view_granite_lite;
1882
1883         int hgt, wid, yrat, xrat;
1884
1885         int **match_autopick_yx;
1886         object_type ***object_autopick_yx;
1887
1888         /* Get size */
1889         Term_get_size(&wid, &hgt);
1890         hgt -= 2;
1891         wid -= 14;
1892         if (use_bigtile) wid /= 2;
1893
1894         yrat = (cur_hgt + hgt - 1) / hgt;
1895         xrat = (cur_wid + wid - 1) / wid;
1896
1897         /* Disable lighting effects */
1898         view_special_lite = FALSE;
1899         view_granite_lite = FALSE;
1900
1901         /* Allocate the maps */
1902         C_MAKE(ma, (hgt + 2), byte_ptr);
1903         C_MAKE(mc, (hgt + 2), char_ptr);
1904         C_MAKE(mp, (hgt + 2), byte_ptr);
1905         C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
1906         C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
1907
1908         /* Allocate and wipe each line map */
1909         for (y = 0; y < (hgt + 2); y++)
1910         {
1911                 /* Allocate one row each array */
1912                 C_MAKE(ma[y], (wid + 2), byte);
1913                 C_MAKE(mc[y], (wid + 2), char);
1914                 C_MAKE(mp[y], (wid + 2), byte);
1915                 C_MAKE(match_autopick_yx[y], (wid + 2), int);
1916                 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
1917
1918                 for (x = 0; x < wid + 2; ++x)
1919                 {
1920                         match_autopick_yx[y][x] = -1;
1921                         object_autopick_yx[y][x] = NULL;
1922
1923                         /* Nothing here */
1924                         ma[y][x] = TERM_WHITE;
1925                         mc[y][x] = ' ';
1926
1927                         /* No priority */
1928                         mp[y][x] = 0;
1929                 }
1930         }
1931
1932         /* Allocate the maps */
1933         C_MAKE(bigma, (cur_hgt + 2), byte_ptr);
1934         C_MAKE(bigmc, (cur_hgt + 2), char_ptr);
1935         C_MAKE(bigmp, (cur_hgt + 2), byte_ptr);
1936
1937         /* Allocate and wipe each line map */
1938         for (y = 0; y < (cur_hgt + 2); y++)
1939         {
1940                 /* Allocate one row each array */
1941                 C_MAKE(bigma[y], (cur_wid + 2), byte);
1942                 C_MAKE(bigmc[y], (cur_wid + 2), char);
1943                 C_MAKE(bigmp[y], (cur_wid + 2), byte);
1944
1945                 for (x = 0; x < cur_wid + 2; ++x)
1946                 {
1947                         /* Nothing here */
1948                         bigma[y][x] = TERM_WHITE;
1949                         bigmc[y][x] = ' ';
1950
1951                         /* No priority */
1952                         bigmp[y][x] = 0;
1953                 }
1954         }
1955
1956         /* Fill in the map */
1957         for (i = 0; i < cur_wid; ++i)
1958         {
1959                 for (j = 0; j < cur_hgt; ++j)
1960                 {
1961                         /* Location */
1962                         x = i / xrat + 1;
1963                         y = j / yrat + 1;
1964
1965                         match_autopick=-1;
1966                         autopick_obj=NULL;
1967                         feat_priority = -1;
1968
1969                         /* Extract the current attr/char at that map location */
1970                         map_info(j, i, &ta, &tc, &ta, &tc);
1971
1972                         /* Extract the priority */
1973                         tp = feat_priority;
1974
1975                         if(match_autopick!=-1
1976                            && (match_autopick_yx[y][x] == -1
1977                                || match_autopick_yx[y][x] > match_autopick))
1978                         {
1979                                 match_autopick_yx[y][x] = match_autopick;
1980                                 object_autopick_yx[y][x] = autopick_obj;
1981                                 tp = 0x7f;
1982                         }
1983
1984                         /* Save the char, attr and priority */
1985                         bigmc[j+1][i+1] = tc;
1986                         bigma[j+1][i+1] = ta;
1987                         bigmp[j+1][i+1] = tp;
1988                 }
1989         }
1990
1991         for (j = 0; j < cur_hgt; ++j)
1992         {
1993                 for (i = 0; i < cur_wid; ++i)
1994                 {
1995                         /* Location */
1996                         x = i / xrat + 1;
1997                         y = j / yrat + 1;
1998
1999                         tc = bigmc[j+1][i+1];
2000                         ta = bigma[j+1][i+1];
2001                         tp = bigmp[j+1][i+1];
2002
2003                         /* rare feature has more priority */
2004                         if (mp[y][x] == tp)
2005                         {
2006                                 int t;
2007                                 int cnt = 0;
2008
2009                                 for (t = 0; t < 8; t++)
2010                                 {
2011                                         if (tc == bigmc[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]] &&
2012                                             ta == bigma[j+1+ddy_cdd[t]][i+1+ddx_cdd[t]])
2013                                                 cnt++;
2014                                 }
2015                                 if (cnt <= 4)
2016                                         tp++;
2017                         }
2018
2019                         /* Save "best" */
2020                         if (mp[y][x] < tp)
2021                         {
2022                                 /* Save the char, attr and priority */
2023                                 mc[y][x] = tc;
2024                                 ma[y][x] = ta;
2025                                 mp[y][x] = tp;
2026                         }
2027                 }
2028         }
2029
2030
2031         /* Corners */
2032         x = wid + 1;
2033         y = hgt + 1;
2034
2035         /* Draw the corners */
2036         mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2037
2038         /* Draw the horizontal edges */
2039         for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2040
2041         /* Draw the vertical edges */
2042         for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2043
2044
2045         /* Display each map line in order */
2046         for (y = 0; y < hgt + 2; ++y)
2047         {
2048                 /* Start a new line */
2049                 Term_gotoxy(COL_MAP, y);
2050
2051                 /* Display the line */
2052                 for (x = 0; x < wid + 2; ++x)
2053                 {
2054                         ta = ma[y][x];
2055                         tc = mc[y][x];
2056
2057                         /* Hack -- fake monochrome */
2058                         if (!use_graphics)
2059                         {
2060                                 if (world_monster) ta = TERM_DARK;
2061                                 else if (IS_INVULN() || world_player) ta = TERM_WHITE;
2062                                 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2063                         }
2064
2065                         /* Add the character */
2066                         Term_add_bigch(ta, tc);
2067                 }
2068         }
2069
2070
2071         for (y = 1; y < hgt + 1; ++y)
2072         {
2073           match_autopick = -1;
2074           for (x = 1; x <= wid; x++){
2075             if (match_autopick_yx[y][x] != -1 &&
2076                 (match_autopick > match_autopick_yx[y][x] ||
2077                  match_autopick == -1)){
2078               match_autopick = match_autopick_yx[y][x];
2079               autopick_obj = object_autopick_yx[y][x];
2080             }
2081           }
2082
2083           /* Clear old display */
2084           Term_putstr(0, y, 12, 0, "            ");
2085
2086           if (match_autopick != -1)
2087 #if 1
2088                   display_shortened_item_name(autopick_obj, y);
2089 #else
2090           {
2091                   char buf[13] = "\0";
2092                   strncpy(buf,autopick_list[match_autopick].name,12);
2093                   buf[12] = '\0';
2094                   put_str(buf,y,0); 
2095           }
2096 #endif
2097
2098         }
2099
2100         /* Player location */
2101                 (*cy) = py / yrat + 1 + ROW_MAP;
2102         if (!use_bigtile)
2103                 (*cx) = px / xrat + 1 + COL_MAP;
2104         else
2105                 (*cx) = (px / xrat + 1) * 2 + COL_MAP;
2106
2107         /* Restore lighting effects */
2108         view_special_lite = old_view_special_lite;
2109         view_granite_lite = old_view_granite_lite;
2110
2111         /* Free each line map */
2112         for (y = 0; y < (hgt + 2); y++)
2113         {
2114                 /* Free one row each array */
2115                 C_FREE(ma[y], (wid + 2), byte);
2116                 C_FREE(mc[y], (wid + 2), char);
2117                 C_FREE(mp[y], (wid + 2), byte);
2118                 C_FREE(match_autopick_yx[y], (wid + 2), int);
2119                 C_FREE(object_autopick_yx[y], (wid + 2), object_type **);
2120         }
2121
2122         /* Free each line map */
2123         C_FREE(ma, (hgt + 2), byte_ptr);
2124         C_FREE(mc, (hgt + 2), char_ptr);
2125         C_FREE(mp, (hgt + 2), byte_ptr);
2126         C_FREE(match_autopick_yx, (hgt + 2), sint_ptr);
2127         C_FREE(object_autopick_yx, (hgt + 2), object_type **);
2128
2129         /* Free each line map */
2130         for (y = 0; y < (cur_hgt + 2); y++)
2131         {
2132                 /* Free one row each array */
2133                 C_FREE(bigma[y], (cur_wid + 2), byte);
2134                 C_FREE(bigmc[y], (cur_wid + 2), char);
2135                 C_FREE(bigmp[y], (cur_wid + 2), byte);
2136         }
2137
2138         /* Free each line map */
2139         C_FREE(bigma, (cur_hgt + 2), byte_ptr);
2140         C_FREE(bigmc, (cur_hgt + 2), char_ptr);
2141         C_FREE(bigmp, (cur_hgt + 2), byte_ptr);
2142 }
2143
2144
2145 /*
2146  * Display a "small-scale" map of the dungeon for the player
2147  *
2148  * Currently, the "player" is displayed on the map.  XXX XXX XXX
2149  */
2150 void do_cmd_view_map(void)
2151 {
2152         int cy, cx;
2153
2154
2155         /* Save the screen */
2156         screen_save();
2157
2158         /* Note */
2159 #ifdef JP
2160 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
2161 #else
2162         prt("Please wait...", 0, 0);
2163 #endif
2164
2165         /* Flush */
2166         Term_fresh();
2167
2168         /* Clear the screen */
2169         Term_clear();
2170
2171         display_autopick = 0;
2172
2173         /* Display the map */
2174         display_map(&cy, &cx);
2175
2176         /* Wait for it */
2177         if(max_autopick && !p_ptr->wild_mode)
2178         {
2179                 display_autopick = ITEM_DISPLAY;
2180
2181                 while (1)
2182                 {
2183                         int i;
2184                         byte flag;
2185
2186                         int wid, hgt, row_message;
2187
2188                         Term_get_size(&wid, &hgt);
2189                         row_message = hgt - 1;
2190
2191 #ifdef JP
2192                         put_str("²¿¤«¥­¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤('M':½¦¤¦ 'N':ÊüÃÖ 'D':M+N 'K':²õ¤¹¥¢¥¤¥Æ¥à¤òɽ¼¨)", row_message, 1);
2193 #else
2194                         put_str(" Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items.", row_message, 1);
2195 #endif
2196
2197                         /* Hilite the player */
2198                         move_cursor(cy, cx);
2199
2200                         i = inkey();
2201
2202                         if ('M' == i)
2203                                 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2204                         else if ('N' == i)
2205                                 flag = DONT_AUTOPICK;
2206                         else if ('K' == i)
2207                                 flag = DO_AUTODESTROY;
2208                         else if ('D' == i)
2209                                 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2210                         else
2211                                 break;
2212
2213                         Term_fresh();
2214                         
2215                         if (~display_autopick & flag)
2216                                 display_autopick |= flag;
2217                         else
2218                                 display_autopick &= ~flag;
2219                         /* Display the map */
2220                         display_map(&cy, &cx);
2221                 }
2222                 
2223                 display_autopick = 0;
2224
2225         }
2226         else
2227         {
2228 #ifdef JP
2229                 put_str("²¿¤«¥­¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹", 23, 30);
2230 #else
2231                 put_str("Hit any key to continue", 23, 30);
2232 #endif          /* Hilite the player */
2233                 move_cursor(cy, cx);
2234                 /* Get any key */
2235                 inkey();
2236         }
2237
2238         /* Restore the screen */
2239         screen_load();
2240 }
2241
2242
2243
2244
2245
2246 /*
2247  * Some comments on the cave grid flags.  -BEN-
2248  *
2249  *
2250  * One of the major bottlenecks in previous versions of Angband was in
2251  * the calculation of "line of sight" from the player to various grids,
2252  * such as monsters.  This was such a nasty bottleneck that a lot of
2253  * silly things were done to reduce the dependancy on "line of sight",
2254  * for example, you could not "see" any grids in a lit room until you
2255  * actually entered the room, and there were all kinds of bizarre grid
2256  * flags to enable this behavior.  This is also why the "call light"
2257  * spells always lit an entire room.
2258  *
2259  * The code below provides functions to calculate the "field of view"
2260  * for the player, which, once calculated, provides extremely fast
2261  * calculation of "line of sight from the player", and to calculate
2262  * the "field of torch lite", which, again, once calculated, provides
2263  * extremely fast calculation of "which grids are lit by the player's
2264  * lite source".  In addition to marking grids as "GRID_VIEW" and/or
2265  * "GRID_LITE", as appropriate, these functions maintain an array for
2266  * each of these two flags, each array containing the locations of all
2267  * of the grids marked with the appropriate flag, which can be used to
2268  * very quickly scan through all of the grids in a given set.
2269  *
2270  * To allow more "semantically valid" field of view semantics, whenever
2271  * the field of view (or the set of torch lit grids) changes, all of the
2272  * grids in the field of view (or the set of torch lit grids) are "drawn"
2273  * so that changes in the world will become apparent as soon as possible.
2274  * This has been optimized so that only grids which actually "change" are
2275  * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2276  * of the grids which are entering or leaving the relevent set of grids.
2277  *
2278  * These new methods are so efficient that the old nasty code was removed.
2279  *
2280  * Note that there is no reason to "update" the "viewable space" unless
2281  * the player "moves", or walls/doors are created/destroyed, and there
2282  * is no reason to "update" the "torch lit grids" unless the field of
2283  * view changes, or the "light radius" changes.  This means that when
2284  * the player is resting, or digging, or doing anything that does not
2285  * involve movement or changing the state of the dungeon, there is no
2286  * need to update the "view" or the "lite" regions, which is nice.
2287  *
2288  * Note that the calls to the nasty "los()" function have been reduced
2289  * to a bare minimum by the use of the new "field of view" calculations.
2290  *
2291  * I wouldn't be surprised if slight modifications to the "update_view()"
2292  * function would allow us to determine "reverse line-of-sight" as well
2293  * as "normal line-of-sight", which would allow monsters to use a more
2294  * "correct" calculation to determine if they can "see" the player.  For
2295  * now, monsters simply "cheat" somewhat and assume that if the player
2296  * has "line of sight" to the monster, then the monster can "pretend"
2297  * that it has "line of sight" to the player.
2298  *
2299  *
2300  * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2301  * grid and maintains an array of all "CAVE_LITE" grids.
2302  *
2303  * This set of grids is the complete set of all grids which are lit by
2304  * the players light source, which allows the "player_can_see_bold()"
2305  * function to work very quickly.
2306  *
2307  * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2308  * fact, the player (unless blind) can always "see" all grids which are
2309  * marked as "CAVE_LITE", unless they are "off screen".
2310  *
2311  *
2312  * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2313  * grid and maintains an array of all "CAVE_VIEW" grids.
2314  *
2315  * This set of grids is the complete set of all grids within line of sight
2316  * of the player, allowing the "player_has_los_bold()" macro to work very
2317  * quickly.
2318  *
2319  *
2320  * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2321  * temporary internal flag to mark those grids which are not only in view,
2322  * but which are also "easily" in line of sight of the player.  This flag
2323  * is always cleared when we are done.
2324  *
2325  *
2326  * The current "update_lite()" and "update_view()" algorithms use the
2327  * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2328  * to keep track of which grids were previously marked as "CAVE_LITE" or
2329  * "CAVE_VIEW", which allows us to optimize the "screen updates".
2330  *
2331  * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2332  * for various other purposes, such as spreading lite or darkness during
2333  * "lite_room()" / "unlite_room()", and for calculating monster flow.
2334  *
2335  *
2336  * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2337  * in some way permanently lit.  However, for the player to "see" anything
2338  * in the grid, as determined by "player_can_see()", the player must not be
2339  * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2340  * grids, even if marked as "perma lit", are only illuminated if they touch
2341  * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2342  *
2343  *
2344  * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2345  * that even if the player cannot "see" the grid, he "knows" the terrain in
2346  * that grid.  This is used to "remember" walls/doors/stairs/floors when they
2347  * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2348  * or when one of the "memorize floor grids" options induces memorization.
2349  *
2350  * Objects are "memorized" in a different way, using a special "marked" flag
2351  * on the object itself, which is set when an object is observed or detected.
2352  *
2353  *
2354  * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2355  * and should be illuminated by "lite room" and "darkness" spells.
2356  *
2357  *
2358  * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
2359  * and should be unavailable for "teleportation" destinations.
2360  *
2361  *
2362  * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
2363  * which is observed, and the "view_torch_grids" allows the player to memorize
2364  * every torch-lit grid.  The player will always memorize important walls,
2365  * doors, stairs, and other terrain features, as well as any "detected" grids.
2366  *
2367  * Note that the new "update_view()" method allows, among other things, a room
2368  * to be "partially" seen as the player approaches it, with a growing cone of
2369  * floor appearing as the player gets closer to the door.  Also, by not turning
2370  * on the "memorize perma-lit grids" option, the player will only "see" those
2371  * floor grids which are actually in line of sight.
2372  *
2373  * And my favorite "plus" is that you can now use a special option to draw the
2374  * "floors" in the "viewable region" brightly (actually, to draw the *other*
2375  * grids dimly), providing a "pretty" effect as the player runs around, and
2376  * to efficiently display the "torch lite" in a special color.
2377  *
2378  *
2379  * Some comments on the "update_view()" algorithm...
2380  *
2381  * The algorithm is very fast, since it spreads "obvious" grids very quickly,
2382  * and only has to call "los()" on the borderline cases.  The major axes/diags
2383  * even terminate early when they hit walls.  I need to find a quick way
2384  * to "terminate" the other scans.
2385  *
2386  * Note that in the worst case (a big empty area with say 5% scattered walls),
2387  * each of the 1500 or so nearby grids is checked once, most of them getting
2388  * an "instant" rating, and only a small portion requiring a call to "los()".
2389  *
2390  * The only time that the algorithm appears to be "noticeably" too slow is
2391  * when running, and this is usually only important in town, since the town
2392  * provides about the worst scenario possible, with large open regions and
2393  * a few scattered obstructions.  There is a special "efficiency" option to
2394  * allow the player to reduce his field of view in town, if needed.
2395  *
2396  * In the "best" case (say, a normal stretch of corridor), the algorithm
2397  * makes one check for each viewable grid, and makes no calls to "los()".
2398  * So running in corridors is very fast, and if a lot of monsters are
2399  * nearby, it is much faster than the old methods.
2400  *
2401  * Note that resting, most normal commands, and several forms of running,
2402  * plus all commands executed near large groups of monsters, are strictly
2403  * more efficient with "update_view()" that with the old "compute los() on
2404  * demand" method, primarily because once the "field of view" has been
2405  * calculated, it does not have to be recalculated until the player moves
2406  * (or a wall or door is created or destroyed).
2407  *
2408  * Note that we no longer have to do as many "los()" checks, since once the
2409  * "view" region has been built, very few things cause it to be "changed"
2410  * (player movement, and the opening/closing of doors, changes in wall status).
2411  * Note that door/wall changes are only relevant when the door/wall itself is
2412  * in the "view" region.
2413  *
2414  * The algorithm seems to only call "los()" from zero to ten times, usually
2415  * only when coming down a corridor into a room, or standing in a room, just
2416  * misaligned with a corridor.  So if, say, there are five "nearby" monsters,
2417  * we will be reducing the calls to "los()".
2418  *
2419  * I am thinking in terms of an algorithm that "walks" from the central point
2420  * out to the maximal "distance", at each point, determining the "view" code
2421  * (above).  For each grid not on a major axis or diagonal, the "view" code
2422  * depends on the "cave_los_bold()" and "view" of exactly two other grids
2423  * (the one along the nearest diagonal, and the one next to that one, see
2424  * "update_view_aux()"...).
2425  *
2426  * We "memorize" the viewable space array, so that at the cost of under 3000
2427  * bytes, we reduce the time taken by "forget_view()" to one assignment for
2428  * each grid actually in the "viewable space".  And for another 3000 bytes,
2429  * we prevent "erase + redraw" ineffiencies via the "seen" set.  These bytes
2430  * are also used by other routines, thus reducing the cost to almost nothing.
2431  *
2432  * A similar thing is done for "forget_lite()" in which case the savings are
2433  * much less, but save us from doing bizarre maintenance checking.
2434  *
2435  * In the worst "normal" case (in the middle of the town), the reachable space
2436  * actually reaches to more than half of the largest possible "circle" of view,
2437  * or about 800 grids, and in the worse case (in the middle of a dungeon level
2438  * where all the walls have been removed), the reachable space actually reaches
2439  * the theoretical maximum size of just under 1500 grids.
2440  *
2441  * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
2442  * If G1 is lite, G is lite.  Else if G2 is lite, G is half.  Else if G1 and G2
2443  * are both half, G is half.  Else G is dark.  It only takes 2 (or 4) bits to
2444  * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
2445  * entire possible space (including initialization) in one step per grid.  If
2446  * we do the "clearing" as a separate step (and use an array of "view" grids),
2447  * then the clearing will take as many steps as grids that were viewed, and the
2448  * algorithm will be able to "stop" scanning at various points.
2449  * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
2450  */
2451
2452
2453
2454
2455
2456
2457
2458
2459 /*
2460  * Actually erase the entire "lite" array, redrawing every grid
2461  */
2462 void forget_lite(void)
2463 {
2464         int i, x, y;
2465
2466         /* None to forget */
2467         if (!lite_n) return;
2468
2469         /* Clear them all */
2470         for (i = 0; i < lite_n; i++)
2471         {
2472                 y = lite_y[i];
2473                 x = lite_x[i];
2474
2475                 /* Forget "LITE" flag */
2476                 cave[y][x].info &= ~(CAVE_LITE);
2477
2478                 /* Redraw */
2479                 /* lite_spot(y, x); Perhaps don't need? */
2480         }
2481
2482         /* None left */
2483         lite_n = 0;
2484 }
2485
2486
2487 /*
2488  * For delayed visual update
2489  */
2490 #define cave_note_and_redraw_later(C,Y,X) \
2491 {\
2492         (C)->info |= CAVE_NOTE; \
2493         cave_redraw_later((C), (Y), (X)); \
2494 }
2495
2496
2497 /*
2498  * For delayed visual update
2499  */
2500 #define cave_redraw_later(C,Y,X) \
2501 {\
2502         if (!((C)->info & CAVE_REDRAW)) \
2503         { \
2504                 (C)->info |= CAVE_REDRAW; \
2505                 redraw_y[redraw_n] = (Y); \
2506                 redraw_x[redraw_n++] = (X); \
2507         } \
2508 }
2509
2510
2511 /*
2512  * XXX XXX XXX
2513  *
2514  * This macro allows us to efficiently add a grid to the "lite" array,
2515  * note that we are never called for illegal grids, or for grids which
2516  * have already been placed into the "lite" array, and we are never
2517  * called when the "lite" array is full.
2518  */
2519 #define cave_lite_hack(Y,X) \
2520 {\
2521         if (!(cave[Y][X].info & (CAVE_LITE))) \
2522         { \
2523                 cave[Y][X].info |= (CAVE_LITE); \
2524                 lite_y[lite_n] = (Y); \
2525                 lite_x[lite_n++] = (X); \
2526         } \
2527 }
2528
2529
2530 /*
2531  * Update the set of grids "illuminated" by the player's lite.
2532  *
2533  * This routine needs to use the results of "update_view()"
2534  *
2535  * Note that "blindness" does NOT affect "torch lite".  Be careful!
2536  *
2537  * We optimize most lites (all non-artifact lites) by using "obvious"
2538  * facts about the results of "small" lite radius, and we attempt to
2539  * list the "nearby" grids before the more "distant" ones in the
2540  * array of torch-lit grids.
2541  *
2542  * We assume that "radius zero" lite is in fact no lite at all.
2543  *
2544  *     Torch     Lantern     Artifacts
2545  *     (etc)
2546  *                              ***
2547  *                 ***         *****
2548  *      ***       *****       *******
2549  *      *@*       **@**       ***@***
2550  *      ***       *****       *******
2551  *                 ***         *****
2552  *                              ***
2553  */
2554 void update_lite(void)
2555 {
2556         int i, x, y, min_x, max_x, min_y, max_y;
2557         int p = p_ptr->cur_lite;
2558         cave_type *c_ptr;
2559
2560         /*** Special case ***/
2561
2562 #if 0
2563         /* Hack -- Player has no lite */
2564         if (p <= 0)
2565         {
2566                 /* Forget the old lite */
2567                 /* forget_lite(); Perhaps don't need? */
2568
2569                 /* Add it to later visual update */
2570                 cave_redraw_later(&cave[py][px], py, px);
2571         }
2572 #endif
2573
2574         /*** Save the old "lite" grids for later ***/
2575
2576         /* Clear them all */
2577         for (i = 0; i < lite_n; i++)
2578         {
2579                 y = lite_y[i];
2580                 x = lite_x[i];
2581
2582                 /* Mark the grid as not "lite" */
2583                 cave[y][x].info &= ~(CAVE_LITE);
2584
2585                 /* Mark the grid as "seen" */
2586                 cave[y][x].info |= (CAVE_TEMP);
2587
2588                 /* Add it to the "seen" set */
2589                 temp_y[temp_n] = y;
2590                 temp_x[temp_n] = x;
2591                 temp_n++;
2592         }
2593
2594         /* None left */
2595         lite_n = 0;
2596
2597
2598         /*** Collect the new "lite" grids ***/
2599
2600         /* Radius 1 -- torch radius */
2601         if (p >= 1)
2602         {
2603                 /* Player grid */
2604                 cave_lite_hack(py, px);
2605
2606                 /* Adjacent grid */
2607                 cave_lite_hack(py+1, px);
2608                 cave_lite_hack(py-1, px);
2609                 cave_lite_hack(py, px+1);
2610                 cave_lite_hack(py, px-1);
2611
2612                 /* Diagonal grids */
2613                 cave_lite_hack(py+1, px+1);
2614                 cave_lite_hack(py+1, px-1);
2615                 cave_lite_hack(py-1, px+1);
2616                 cave_lite_hack(py-1, px-1);
2617         }
2618
2619         /* Radius 2 -- lantern radius */
2620         if (p >= 2)
2621         {
2622                 /* South of the player */
2623                 if (cave_los_bold(py + 1, px))
2624                 {
2625                         cave_lite_hack(py+2, px);
2626                         cave_lite_hack(py+2, px+1);
2627                         cave_lite_hack(py+2, px-1);
2628                 }
2629
2630                 /* North of the player */
2631                 if (cave_los_bold(py - 1, px))
2632                 {
2633                         cave_lite_hack(py-2, px);
2634                         cave_lite_hack(py-2, px+1);
2635                         cave_lite_hack(py-2, px-1);
2636                 }
2637
2638                 /* East of the player */
2639                 if (cave_los_bold(py, px + 1))
2640                 {
2641                         cave_lite_hack(py, px+2);
2642                         cave_lite_hack(py+1, px+2);
2643                         cave_lite_hack(py-1, px+2);
2644                 }
2645
2646                 /* West of the player */
2647                 if (cave_los_bold(py, px - 1))
2648                 {
2649                         cave_lite_hack(py, px-2);
2650                         cave_lite_hack(py+1, px-2);
2651                         cave_lite_hack(py-1, px-2);
2652                 }
2653         }
2654
2655         /* Radius 3+ -- artifact radius */
2656         if (p >= 3)
2657         {
2658                 int d;
2659
2660                 /* Paranoia -- see "LITE_MAX" */
2661                 if (p > 14) p = 14;
2662
2663                 /* South-East of the player */
2664                 if (cave_los_bold(py + 1, px + 1))
2665                 {
2666                         cave_lite_hack(py+2, px+2);
2667                 }
2668
2669                 /* South-West of the player */
2670                 if (cave_los_bold(py + 1, px - 1))
2671                 {
2672                         cave_lite_hack(py+2, px-2);
2673                 }
2674
2675                 /* North-East of the player */
2676                 if (cave_los_bold(py - 1, px + 1))
2677                 {
2678                         cave_lite_hack(py-2, px+2);
2679                 }
2680
2681                 /* North-West of the player */
2682                 if (cave_los_bold(py - 1, px - 1))
2683                 {
2684                         cave_lite_hack(py-2, px-2);
2685                 }
2686
2687                 /* Maximal north */
2688                 min_y = py - p;
2689                 if (min_y < 0) min_y = 0;
2690
2691                 /* Maximal south */
2692                 max_y = py + p;
2693                 if (max_y > cur_hgt-1) max_y = cur_hgt-1;
2694
2695                 /* Maximal west */
2696                 min_x = px - p;
2697                 if (min_x < 0) min_x = 0;
2698
2699                 /* Maximal east */
2700                 max_x = px + p;
2701                 if (max_x > cur_wid-1) max_x = cur_wid-1;
2702
2703                 /* Scan the maximal box */
2704                 for (y = min_y; y <= max_y; y++)
2705                 {
2706                         for (x = min_x; x <= max_x; x++)
2707                         {
2708                                 int dy = (py > y) ? (py - y) : (y - py);
2709                                 int dx = (px > x) ? (px - x) : (x - px);
2710
2711                                 /* Skip the "central" grids (above) */
2712                                 if ((dy <= 2) && (dx <= 2)) continue;
2713
2714                                 /* Hack -- approximate the distance */
2715                                 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2716
2717                                 /* Skip distant grids */
2718                                 if (d > p) continue;
2719
2720                                 /* Viewable, nearby, grids get "torch lit" */
2721                                 if (player_has_los_bold(y, x))
2722                                 {
2723                                         /* This grid is "torch lit" */
2724                                         cave_lite_hack(y, x);
2725                                 }
2726                         }
2727                 }
2728         }
2729
2730
2731         /*** Complete the algorithm ***/
2732
2733         /* Draw the new grids */
2734         for (i = 0; i < lite_n; i++)
2735         {
2736                 y = lite_y[i];
2737                 x = lite_x[i];
2738
2739                 c_ptr = &cave[y][x];
2740
2741                 /* Update fresh grids */
2742                 if (c_ptr->info & (CAVE_TEMP)) continue;
2743
2744                 /* Add it to later visual update */
2745                 cave_note_and_redraw_later(c_ptr, y, x);
2746         }
2747
2748         /* Clear them all */
2749         for (i = 0; i < temp_n; i++)
2750         {
2751                 y = temp_y[i];
2752                 x = temp_x[i];
2753
2754                 c_ptr = &cave[y][x];
2755
2756                 /* No longer in the array */
2757                 c_ptr->info &= ~(CAVE_TEMP);
2758
2759                 /* Update stale grids */
2760                 if (c_ptr->info & (CAVE_LITE)) continue;
2761
2762                 /* Add it to later visual update */
2763                 cave_redraw_later(c_ptr, y, x);
2764         }
2765
2766         /* None left */
2767         temp_n = 0;
2768
2769         /* Mega-Hack -- Visual update later */
2770         p_ptr->update |= (PU_DELAY_VIS);
2771 }
2772
2773
2774 static bool mon_invis;
2775 static s16b mon_fy, mon_fx;
2776
2777 /*
2778  * Add a square to the changes array
2779  */
2780 static void mon_lite_hack(int y, int x)
2781 {
2782         cave_type *c_ptr;
2783         int       midpoint, dpf, d;
2784
2785         /* We trust this grid is in bounds */
2786         /* if (!in_bounds2(y, x)) return; */
2787
2788         c_ptr = &cave[y][x];
2789
2790         /* Want a unlit square in view of the player */
2791         if ((c_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
2792
2793         if (!cave_los_grid(c_ptr))
2794         {
2795                 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2796                 if (mon_invis) return;
2797
2798                 /* Hack -- Prevent monster lite leakage in walls */
2799
2800                 /* Horizontal walls between player and a monster */
2801                 if (((y < py) && (y > mon_fy)) || ((y > py) && (y < mon_fy)))
2802                 {
2803                         dpf = py - mon_fy;
2804                         d = y - mon_fy;
2805                         midpoint = mon_fx + ((px - mon_fx) * ABS(d)) / ABS(dpf);
2806
2807                         /* Only first wall viewed from mid-x is lit */
2808                         if (x < midpoint)
2809                         {
2810                                 if (!cave_los_bold(y, x + 1)) return;
2811                         }
2812                         else if (x > midpoint)
2813                         {
2814                                 if (!cave_los_bold(y, x - 1)) return;
2815                         }
2816                 }
2817
2818                 /* Vertical walls between player and a monster */
2819                 if (((x < px) && (x > mon_fx)) || ((x > px) && (x < mon_fx)))
2820                 {
2821                         dpf = px - mon_fx;
2822                         d = x - mon_fx;
2823                         midpoint = mon_fy + ((py - mon_fy) * ABS(d)) / ABS(dpf);
2824
2825                         /* Only first wall viewed from mid-y is lit */
2826                         if (y < midpoint)
2827                         {
2828                                 if (!cave_los_bold(y + 1, x)) return;
2829                         }
2830                         else if (y > midpoint)
2831                         {
2832                                 if (!cave_los_bold(y - 1, x)) return;
2833                         }
2834                 }
2835         }
2836
2837         /* We trust temp_n does not exceed TEMP_MAX */
2838
2839         /* New grid */
2840         if (!(c_ptr->info & CAVE_MNDK))
2841         {
2842                 /* Save this square */
2843                 temp_x[temp_n] = x;
2844                 temp_y[temp_n] = y;
2845                 temp_n++;
2846         }
2847
2848         /* Darkened grid */
2849         else
2850         {
2851                 /* No longer dark */
2852                 c_ptr->info &= ~(CAVE_MNDK);
2853         }
2854
2855         /* Light it */
2856         c_ptr->info |= CAVE_MNLT;
2857 }
2858
2859
2860 /*
2861  * Add a square to the changes array
2862  */
2863 static void mon_dark_hack(int y, int x)
2864 {
2865         cave_type *c_ptr;
2866         int       midpoint, dpf, d;
2867
2868         /* We trust this grid is in bounds */
2869         /* if (!in_bounds2(y, x)) return; */
2870
2871         c_ptr = &cave[y][x];
2872
2873         /* Want a unlit and undarkened square in view of the player */
2874         if ((c_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
2875
2876         if (!cave_los_grid(c_ptr))
2877         {
2878                 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2879                 if (mon_invis) return;
2880
2881                 /* Hack -- Prevent monster dark lite leakage in walls */
2882
2883                 /* Horizontal walls between player and a monster */
2884                 if (((y < py) && (y > mon_fy)) || ((y > py) && (y < mon_fy)))
2885                 {
2886                         dpf = py - mon_fy;
2887                         d = y - mon_fy;
2888                         midpoint = mon_fx + ((px - mon_fx) * ABS(d)) / ABS(dpf);
2889
2890                         /* Only first wall viewed from mid-x is lit */
2891                         if (x < midpoint)
2892                         {
2893                                 if (!cave_los_bold(y, x + 1)) return;
2894                         }
2895                         else if (x > midpoint)
2896                         {
2897                                 if (!cave_los_bold(y, x - 1)) return;
2898                         }
2899                 }
2900
2901                 /* Vertical walls between player and a monster */
2902                 if (((x < px) && (x > mon_fx)) || ((x > px) && (x < mon_fx)))
2903                 {
2904                         dpf = px - mon_fx;
2905                         d = x - mon_fx;
2906                         midpoint = mon_fy + ((py - mon_fy) * ABS(d)) / ABS(dpf);
2907
2908                         /* Only first wall viewed from mid-y is lit */
2909                         if (y < midpoint)
2910                         {
2911                                 if (!cave_los_bold(y + 1, x)) return;
2912                         }
2913                         else if (y > midpoint)
2914                         {
2915                                 if (!cave_los_bold(y - 1, x)) return;
2916                         }
2917                 }
2918         }
2919
2920         /* We trust temp_n does not exceed TEMP_MAX */
2921
2922         /* Save this square */
2923         temp_x[temp_n] = x;
2924         temp_y[temp_n] = y;
2925         temp_n++;
2926
2927         /* Darken it */
2928         c_ptr->info |= CAVE_MNDK;
2929 }
2930
2931
2932 /*
2933  * Update squares illuminated or darkened by monsters.
2934  *
2935  * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
2936  * denote squares illuminated by monsters.
2937  *
2938  * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
2939  * updating.  Only squares in view of the player, whos state
2940  * changes are drawn via lite_spot().
2941  */
2942 void update_mon_lite(void)
2943 {
2944         int i, rad;
2945         cave_type *c_ptr;
2946
2947         s16b fx, fy;
2948         void (*add_mon_lite)(int, int);
2949
2950         s16b end_temp;
2951
2952         /* Non-Ninja player in the darkness */
2953         int dis_lim = ((d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
2954                 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
2955
2956         /* Clear all monster lit squares */
2957         for (i = 0; i < mon_lite_n; i++)
2958         {
2959                 /* Point to grid */
2960                 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
2961
2962                 /* Set temp or xtra flag */
2963                 c_ptr->info |= (c_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
2964
2965                 /* Clear monster illumination flag */
2966                 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
2967         }
2968
2969         /* Empty temp list of new squares to lite up */
2970         temp_n = 0;
2971
2972         /* Loop through monsters, adding newly lit squares to changes list */
2973         for (i = 1; i < m_max; i++)
2974         {
2975                 monster_type *m_ptr = &m_list[i];
2976                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2977
2978                 /* Skip dead monsters */
2979                 if (!m_ptr->r_idx) continue;
2980
2981                 /* Is it too far away? */
2982                 if (m_ptr->cdis > dis_lim) continue;
2983
2984                 /* If a monster stops time, break */
2985                 if (world_monster) break;
2986
2987                 /* Get lite radius */
2988                 rad = 0;
2989
2990                 /* Note the radii are cumulative */
2991                 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
2992                 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
2993                 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
2994                 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
2995
2996                 /* Exit if has no light */
2997                 if (!rad) continue;
2998                 else if (rad > 0)
2999                 {
3000                         if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (m_ptr->csleep || (!dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3001                         if (d_info[dungeon_type].flags1 & DF1_DARKNESS) rad = 1;
3002                         add_mon_lite = mon_lite_hack;
3003                 }
3004                 else
3005                 {
3006                         if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (m_ptr->csleep || (!dun_level && !is_daytime()))) continue;
3007                         add_mon_lite = mon_dark_hack;
3008                         rad = -rad; /* Use absolute value */
3009                 }
3010
3011                 /* Access the location */
3012                 mon_fx = m_ptr->fx;
3013                 mon_fy = m_ptr->fy;
3014
3015                 /* Is the monster visible? */
3016                 mon_invis = !(cave[mon_fy][mon_fx].info & CAVE_VIEW);
3017
3018                 /* The square it is on */
3019                 add_mon_lite(mon_fy, mon_fx);
3020
3021                 /* Adjacent squares */
3022                 add_mon_lite(mon_fy + 1, mon_fx);
3023                 add_mon_lite(mon_fy - 1, mon_fx);
3024                 add_mon_lite(mon_fy, mon_fx + 1);
3025                 add_mon_lite(mon_fy, mon_fx - 1);
3026                 add_mon_lite(mon_fy + 1, mon_fx + 1);
3027                 add_mon_lite(mon_fy + 1, mon_fx - 1);
3028                 add_mon_lite(mon_fy - 1, mon_fx + 1);
3029                 add_mon_lite(mon_fy - 1, mon_fx - 1);
3030
3031                 /* Radius 2 */
3032                 if (rad >= 2)
3033                 {
3034                         /* South of the monster */
3035                         if (cave_los_bold(mon_fy + 1, mon_fx))
3036                         {
3037                                 add_mon_lite(mon_fy + 2, mon_fx + 1);
3038                                 add_mon_lite(mon_fy + 2, mon_fx);
3039                                 add_mon_lite(mon_fy + 2, mon_fx - 1);
3040
3041                                 c_ptr = &cave[mon_fy + 2][mon_fx];
3042
3043                                 /* Radius 3 */
3044                                 if ((rad == 3) && cave_los_grid(c_ptr))
3045                                 {
3046                                         add_mon_lite(mon_fy + 3, mon_fx + 1);
3047                                         add_mon_lite(mon_fy + 3, mon_fx);
3048                                         add_mon_lite(mon_fy + 3, mon_fx - 1);
3049                                 }
3050                         }
3051
3052                         /* North of the monster */
3053                         if (cave_los_bold(mon_fy - 1, mon_fx))
3054                         {
3055                                 add_mon_lite(mon_fy - 2, mon_fx + 1);
3056                                 add_mon_lite(mon_fy - 2, mon_fx);
3057                                 add_mon_lite(mon_fy - 2, mon_fx - 1);
3058
3059                                 c_ptr = &cave[mon_fy - 2][mon_fx];
3060
3061                                 /* Radius 3 */
3062                                 if ((rad == 3) && cave_los_grid(c_ptr))
3063                                 {
3064                                         add_mon_lite(mon_fy - 3, mon_fx + 1);
3065                                         add_mon_lite(mon_fy - 3, mon_fx);
3066                                         add_mon_lite(mon_fy - 3, mon_fx - 1);
3067                                 }
3068                         }
3069
3070                         /* East of the monster */
3071                         if (cave_los_bold(mon_fy, mon_fx + 1))
3072                         {
3073                                 add_mon_lite(mon_fy + 1, mon_fx + 2);
3074                                 add_mon_lite(mon_fy, mon_fx + 2);
3075                                 add_mon_lite(mon_fy - 1, mon_fx + 2);
3076
3077                                 c_ptr = &cave[mon_fy][mon_fx + 2];
3078
3079                                 /* Radius 3 */
3080                                 if ((rad == 3) && cave_los_grid(c_ptr))
3081                                 {
3082                                         add_mon_lite(mon_fy + 1, mon_fx + 3);
3083                                         add_mon_lite(mon_fy, mon_fx + 3);
3084                                         add_mon_lite(mon_fy - 1, mon_fx + 3);
3085                                 }
3086                         }
3087
3088                         /* West of the monster */
3089                         if (cave_los_bold(mon_fy, mon_fx - 1))
3090                         {
3091                                 add_mon_lite(mon_fy + 1, mon_fx - 2);
3092                                 add_mon_lite(mon_fy, mon_fx - 2);
3093                                 add_mon_lite(mon_fy - 1, mon_fx - 2);
3094
3095                                 c_ptr = &cave[mon_fy][mon_fx - 2];
3096
3097                                 /* Radius 3 */
3098                                 if ((rad == 3) && cave_los_grid(c_ptr))
3099                                 {
3100                                         add_mon_lite(mon_fy + 1, mon_fx - 3);
3101                                         add_mon_lite(mon_fy, mon_fx - 3);
3102                                         add_mon_lite(mon_fy - 1, mon_fx - 3);
3103                                 }
3104                         }
3105                 }
3106
3107                 /* Radius 3 */
3108                 if (rad == 3)
3109                 {
3110                         /* South-East of the monster */
3111                         if (cave_los_bold(mon_fy + 1, mon_fx + 1))
3112                         {
3113                                 add_mon_lite(mon_fy + 2, mon_fx + 2);
3114                         }
3115
3116                         /* South-West of the monster */
3117                         if (cave_los_bold(mon_fy + 1, mon_fx - 1))
3118                         {
3119                                 add_mon_lite(mon_fy + 2, mon_fx - 2);
3120                         }
3121
3122                         /* North-East of the monster */
3123                         if (cave_los_bold(mon_fy - 1, mon_fx + 1))
3124                         {
3125                                 add_mon_lite(mon_fy - 2, mon_fx + 2);
3126                         }
3127
3128                         /* North-West of the monster */
3129                         if (cave_los_bold(mon_fy - 1, mon_fx - 1))
3130                         {
3131                                 add_mon_lite(mon_fy - 2, mon_fx - 2);
3132                         }
3133                 }
3134         }
3135
3136         /* Save end of list of new squares */
3137         end_temp = temp_n;
3138
3139         /*
3140          * Look at old set flags to see if there are any changes.
3141          */
3142         for (i = 0; i < mon_lite_n; i++)
3143         {
3144                 fx = mon_lite_x[i];
3145                 fy = mon_lite_y[i];
3146
3147                 /* We trust this grid is in bounds */
3148
3149                 /* Point to grid */
3150                 c_ptr = &cave[fy][fx];
3151
3152                 if (c_ptr->info & CAVE_TEMP) /* Pervious lit */
3153                 {
3154                         /* It it no longer lit? */
3155                         if ((c_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3156                         {
3157                                 /* It is now unlit */
3158                                 /* Add it to later visual update */
3159                                 cave_note_and_redraw_later(c_ptr, fy, fx);
3160                         }
3161                 }
3162                 else /* Pervious darkened */
3163                 {
3164                         /* It it no longer darken? */
3165                         if ((c_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3166                         {
3167                                 /* It is now undarken */
3168                                 /* Add it to later visual update */
3169                                 cave_note_and_redraw_later(c_ptr, fy, fx);
3170                         }
3171                 }
3172
3173                 /* Add to end of temp array */
3174                 temp_x[temp_n] = (byte)fx;
3175                 temp_y[temp_n] = (byte)fy;
3176                 temp_n++;
3177         }
3178
3179         /* Clear the lite array */
3180         mon_lite_n = 0;
3181
3182         /* Copy the temp array into the lit array lighting the new squares. */
3183         for (i = 0; i < end_temp; i++)
3184         {
3185                 fx = temp_x[i];
3186                 fy = temp_y[i];
3187
3188                 /* We trust this grid is in bounds */
3189
3190                 /* Point to grid */
3191                 c_ptr = &cave[fy][fx];
3192
3193                 if (c_ptr->info & CAVE_MNLT) /* Lit */
3194                 {
3195                         /* The is the square newly lit and visible? */
3196                         if ((c_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3197                         {
3198                                 /* It is now lit */
3199                                 /* Add it to later visual update */
3200                                 cave_note_and_redraw_later(c_ptr, fy, fx);
3201                         }
3202                 }
3203                 else /* Darkened */
3204                 {
3205                         /* The is the square newly darkened and visible? */
3206                         if ((c_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3207                         {
3208                                 /* It is now darkened */
3209                                 /* Add it to later visual update */
3210                                 cave_note_and_redraw_later(c_ptr, fy, fx);
3211                         }
3212                 }
3213
3214                 /* Save in the monster lit or darkened array */
3215                 mon_lite_x[mon_lite_n] = fx;
3216                 mon_lite_y[mon_lite_n] = fy;
3217                 mon_lite_n++;
3218         }
3219
3220         /* Clear the temp flag for the old lit or darken grids */
3221         for (i = end_temp; i < temp_n; i++)
3222         {
3223                 /* We trust this grid is in bounds */
3224
3225                 cave[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3226         }
3227
3228         /* Finished with temp_n */
3229         temp_n = 0;
3230
3231         /* Mega-Hack -- Visual update later */
3232         p_ptr->update |= (PU_DELAY_VIS);
3233
3234         p_ptr->monlite = (cave[py][px].info & CAVE_MNLT) ? TRUE : FALSE;
3235
3236         if (p_ptr->special_defense & NINJA_S_STEALTH)
3237         {
3238                 if (p_ptr->old_monlite != p_ptr->monlite)
3239                 {
3240                         if (p_ptr->monlite)
3241                         {
3242 #ifdef JP
3243                                 msg_print("±Æ¤Îʤ¤¤¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
3244 #else
3245                                 msg_print("Your mantle of shadow become thin.");
3246 #endif
3247                         }
3248                         else
3249                         {
3250 #ifdef JP
3251                                 msg_print("±Æ¤Îʤ¤¤¤¬Ç»¤¯¤Ê¤Ã¤¿¡ª");
3252 #else
3253                                 msg_print("Your mantle of shadow restored its original darkness.");
3254 #endif
3255                         }
3256                 }
3257         }
3258         p_ptr->old_monlite = p_ptr->monlite;
3259 }
3260
3261 void clear_mon_lite(void)
3262 {
3263         int i;
3264         cave_type *c_ptr;
3265
3266         /* Clear all monster lit squares */
3267         for (i = 0; i < mon_lite_n; i++)
3268         {
3269                 /* Point to grid */
3270                 c_ptr = &cave[mon_lite_y[i]][mon_lite_x[i]];
3271
3272                 /* Clear monster illumination flag */
3273                 c_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3274         }
3275
3276         /* Empty the array */
3277         mon_lite_n = 0;
3278 }
3279
3280
3281
3282 /*
3283  * Clear the viewable space
3284  */
3285 void forget_view(void)
3286 {
3287         int i;
3288
3289         cave_type *c_ptr;
3290
3291         /* None to forget */
3292         if (!view_n) return;
3293
3294         /* Clear them all */
3295         for (i = 0; i < view_n; i++)
3296         {
3297                 int y = view_y[i];
3298                 int x = view_x[i];
3299
3300                 /* Access the grid */
3301                 c_ptr = &cave[y][x];
3302
3303                 /* Forget that the grid is viewable */
3304                 c_ptr->info &= ~(CAVE_VIEW);
3305
3306                 if (!panel_contains(y, x)) continue;
3307
3308                 /* Update the screen */
3309                 /* lite_spot(y, x); Perhaps don't need? */
3310         }
3311
3312         /* None left */
3313         view_n = 0;
3314 }
3315
3316
3317
3318 /*
3319  * This macro allows us to efficiently add a grid to the "view" array,
3320  * note that we are never called for illegal grids, or for grids which
3321  * have already been placed into the "view" array, and we are never
3322  * called when the "view" array is full.
3323  */
3324 #define cave_view_hack(C,Y,X) \
3325 {\
3326     if (!((C)->info & (CAVE_VIEW))){\
3327     (C)->info |= (CAVE_VIEW); \
3328     view_y[view_n] = (Y); \
3329     view_x[view_n] = (X); \
3330     view_n++;}\
3331 }
3332
3333
3334
3335 /*
3336  * Helper function for "update_view()" below
3337  *
3338  * We are checking the "viewability" of grid (y,x) by the player.
3339  *
3340  * This function assumes that (y,x) is legal (i.e. on the map).
3341  *
3342  * Grid (y1,x1) is on the "diagonal" between (py,px) and (y,x)
3343  * Grid (y2,x2) is "adjacent", also between (py,px) and (y,x).
3344  *
3345  * Note that we are using the "CAVE_XTRA" field for marking grids as
3346  * "easily viewable".  This bit is cleared at the end of "update_view()".
3347  *
3348  * This function adds (y,x) to the "viewable set" if necessary.
3349  *
3350  * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3351  */
3352 static bool update_view_aux(int y, int x, int y1, int x1, int y2, int x2)
3353 {
3354         bool f1, f2, v1, v2, z1, z2, wall;
3355
3356         cave_type *c_ptr;
3357
3358         cave_type *g1_c_ptr;
3359         cave_type *g2_c_ptr;
3360
3361         /* Access the grids */
3362         g1_c_ptr = &cave[y1][x1];
3363         g2_c_ptr = &cave[y2][x2];
3364
3365
3366         /* Check for walls */
3367         f1 = (cave_los_grid(g1_c_ptr));
3368         f2 = (cave_los_grid(g2_c_ptr));
3369
3370         /* Totally blocked by physical walls */
3371         if (!f1 && !f2) return (TRUE);
3372
3373
3374         /* Check for visibility */
3375         v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
3376         v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
3377
3378         /* Totally blocked by "unviewable neighbors" */
3379         if (!v1 && !v2) return (TRUE);
3380
3381
3382         /* Access the grid */
3383         c_ptr = &cave[y][x];
3384
3385
3386         /* Check for walls */
3387         wall = (!cave_los_grid(c_ptr));
3388
3389
3390         /* Check the "ease" of visibility */
3391         z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
3392         z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
3393
3394         /* Hack -- "easy" plus "easy" yields "easy" */
3395         if (z1 && z2)
3396         {
3397                 c_ptr->info |= (CAVE_XTRA);
3398
3399                 cave_view_hack(c_ptr, y, x);
3400
3401                 return (wall);
3402         }
3403
3404         /* Hack -- primary "easy" yields "viewed" */
3405         if (z1)
3406         {
3407                 cave_view_hack(c_ptr, y, x);
3408
3409                 return (wall);
3410         }
3411
3412         /* Hack -- "view" plus "view" yields "view" */
3413         if (v1 && v2)
3414         {
3415                 /* c_ptr->info |= (CAVE_XTRA); */
3416
3417                 cave_view_hack(c_ptr, y, x);
3418
3419                 return (wall);
3420         }
3421
3422
3423         /* Mega-Hack -- the "los()" function works poorly on walls */
3424         if (wall)
3425         {
3426                 cave_view_hack(c_ptr, y, x);
3427
3428                 return (wall);
3429         }
3430
3431
3432         /* Hack -- check line of sight */
3433         if (los(py, px, y, x))
3434         {
3435                 cave_view_hack(c_ptr, y, x);
3436
3437                 return (wall);
3438         }
3439
3440
3441         /* Assume no line of sight. */
3442         return (TRUE);
3443 }
3444
3445
3446
3447 /*
3448  * Calculate the viewable space
3449  *
3450  *  1: Process the player
3451  *  1a: The player is always (easily) viewable
3452  *  2: Process the diagonals
3453  *  2a: The diagonals are (easily) viewable up to the first wall
3454  *  2b: But never go more than 2/3 of the "full" distance
3455  *  3: Process the main axes
3456  *  3a: The main axes are (easily) viewable up to the first wall
3457  *  3b: But never go more than the "full" distance
3458  *  4: Process sequential "strips" in each of the eight octants
3459  *  4a: Each strip runs along the previous strip
3460  *  4b: The main axes are "previous" to the first strip
3461  *  4c: Process both "sides" of each "direction" of each strip
3462  *  4c1: Each side aborts as soon as possible
3463  *  4c2: Each side tells the next strip how far it has to check
3464  *
3465  * Note that the octant processing involves some pretty interesting
3466  * observations involving when a grid might possibly be viewable from
3467  * a given grid, and on the order in which the strips are processed.
3468  *
3469  * Note the use of the mathematical facts shown below, which derive
3470  * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
3471  * hypotenuse of a right triangle is primarily determined by the length
3472  * of the longest side, when one side is small, and is strictly less
3473  * than one-and-a-half times as long as the longest side when both of
3474  * the sides are large.
3475  *
3476  *   if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
3477  *   if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
3478  *
3479  *   hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
3480  *
3481  * These observations are important because the calculation of the actual
3482  * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
3483  * while for small values (up to about 20 or so), the approximations above
3484  * are correct to within an error of at most one grid or so.
3485  *
3486  * Observe the use of "full" and "over" in the code below, and the use of
3487  * the specialized calculation involving "limit", all of which derive from
3488  * the observations given above.  Basically, we note that the "circle" of
3489  * view is completely contained in an "octagon" whose bounds are easy to
3490  * determine, and that only a few steps are needed to derive the actual
3491  * bounds of the circle given the bounds of the octagon.
3492  *
3493  * Note that by skipping all the grids in the corners of the octagon, we
3494  * place an upper limit on the number of grids in the field of view, given
3495  * that "full" is never more than 20.  Of the 1681 grids in the "square" of
3496  * view, only about 1475 of these are in the "octagon" of view, and even
3497  * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
3498  * entries to completely contain the actual field of view.
3499  *
3500  * Note also the care taken to prevent "running off the map".  The use of
3501  * explicit checks on the "validity" of the "diagonal", and the fact that
3502  * the loops are never allowed to "leave" the map, lets "update_view_aux()"
3503  * use the optimized "cave_los_bold()" macro, and to avoid the overhead
3504  * of multiple checks on the validity of grids.
3505  *
3506  * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
3507  * "ws","wn" variables.  They work like this: While travelling down the
3508  * south-bound strip just to the east of the main south axis, as soon as
3509  * we get to a grid which does not "transmit" viewing, if all of the strips
3510  * preceding us (in this case, just the main axis) had terminated at or before
3511  * the same point, then we can stop, and reset the "max distance" to ourself.
3512  * So, each strip (named by major axis plus offset, thus "se" in this case)
3513  * maintains a "blockage" variable, initialized during the main axis step,
3514  * and checks it whenever a blockage is observed.  After processing each
3515  * strip as far as the previous strip told us to process, the next strip is
3516  * told not to go farther than the current strip's farthest viewable grid,
3517  * unless open space is still available.  This uses the "k" variable.
3518  *
3519  * Note the use of "inline" macros for efficiency.  The "cave_los_grid()"
3520  * macro is a replacement for "cave_los_bold()" which takes a pointer to
3521  * a cave grid instead of its location.  The "cave_view_hack()" macro is a
3522  * chunk of code which adds the given location to the "view" array if it
3523  * is not already there, using both the actual location and a pointer to
3524  * the cave grid.  See above.
3525  *
3526  * By the way, the purpose of this code is to reduce the dependancy on the
3527  * "los()" function which is slow, and, in some cases, not very accurate.
3528  *
3529  * It is very possible that I am the only person who fully understands this
3530  * function, and for that I am truly sorry, but efficiency was very important
3531  * and the "simple" version of this function was just not fast enough.  I am
3532  * more than willing to replace this function with a simpler one, if it is
3533  * equally efficient, and especially willing if the new function happens to
3534  * derive "reverse-line-of-sight" at the same time, since currently monsters
3535  * just use an optimized hack of "you see me, so I see you", and then use the
3536  * actual "projectable()" function to check spell attacks.
3537  */
3538 void update_view(void)
3539 {
3540         int n, m, d, k, y, x, z;
3541
3542         int se, sw, ne, nw, es, en, ws, wn;
3543
3544         int full, over;
3545
3546         int y_max = cur_hgt - 1;
3547         int x_max = cur_wid - 1;
3548
3549         cave_type *c_ptr;
3550
3551         /*** Initialize ***/
3552
3553         /* Optimize */
3554         if (view_reduce_view && !dun_level)
3555         {
3556                 /* Full radius (10) */
3557                 full = MAX_SIGHT / 2;
3558
3559                 /* Octagon factor (15) */
3560                 over = MAX_SIGHT * 3 / 4;
3561         }
3562
3563         /* Normal */
3564         else
3565         {
3566                 /* Full radius (20) */
3567                 full = MAX_SIGHT;
3568
3569                 /* Octagon factor (30) */
3570                 over = MAX_SIGHT * 3 / 2;
3571         }
3572
3573
3574         /*** Step 0 -- Begin ***/
3575
3576         /* Save the old "view" grids for later */
3577         for (n = 0; n < view_n; n++)
3578         {
3579                 y = view_y[n];
3580                 x = view_x[n];
3581
3582                 /* Access the grid */
3583                 c_ptr = &cave[y][x];
3584
3585                 /* Mark the grid as not in "view" */
3586                 c_ptr->info &= ~(CAVE_VIEW);
3587
3588                 /* Mark the grid as "seen" */
3589                 c_ptr->info |= (CAVE_TEMP);
3590
3591                 /* Add it to the "seen" set */
3592                 temp_y[temp_n] = y;
3593                 temp_x[temp_n] = x;
3594                 temp_n++;
3595         }
3596
3597         /* Start over with the "view" array */
3598         view_n = 0;
3599
3600         /*** Step 1 -- adjacent grids ***/
3601
3602         /* Now start on the player */
3603         y = py;
3604         x = px;
3605
3606         /* Access the grid */
3607         c_ptr = &cave[y][x];
3608
3609         /* Assume the player grid is easily viewable */
3610         c_ptr->info |= (CAVE_XTRA);
3611
3612         /* Assume the player grid is viewable */
3613         cave_view_hack(c_ptr, y, x);
3614
3615
3616         /*** Step 2 -- Major Diagonals ***/
3617
3618         /* Hack -- Limit */
3619         z = full * 2 / 3;
3620
3621         /* Scan south-east */
3622         for (d = 1; d <= z; d++)
3623         {
3624                 c_ptr = &cave[y+d][x+d];
3625                 c_ptr->info |= (CAVE_XTRA);
3626                 cave_view_hack(c_ptr, y+d, x+d);
3627                 if (!cave_los_grid(c_ptr)) break;
3628         }
3629
3630         /* Scan south-west */
3631         for (d = 1; d <= z; d++)
3632         {
3633                 c_ptr = &cave[y+d][x-d];
3634                 c_ptr->info |= (CAVE_XTRA);
3635                 cave_view_hack(c_ptr, y+d, x-d);
3636                 if (!cave_los_grid(c_ptr)) break;
3637         }
3638
3639         /* Scan north-east */
3640         for (d = 1; d <= z; d++)
3641         {
3642                 c_ptr = &cave[y-d][x+d];
3643                 c_ptr->info |= (CAVE_XTRA);
3644                 cave_view_hack(c_ptr, y-d, x+d);
3645                 if (!cave_los_grid(c_ptr)) break;
3646         }
3647
3648         /* Scan north-west */
3649         for (d = 1; d <= z; d++)
3650         {
3651                 c_ptr = &cave[y-d][x-d];
3652                 c_ptr->info |= (CAVE_XTRA);
3653                 cave_view_hack(c_ptr, y-d, x-d);
3654                 if (!cave_los_grid(c_ptr)) break;
3655         }
3656
3657
3658         /*** Step 3 -- major axes ***/
3659
3660         /* Scan south */
3661         for (d = 1; d <= full; d++)
3662         {
3663                 c_ptr = &cave[y+d][x];
3664                 c_ptr->info |= (CAVE_XTRA);
3665                 cave_view_hack(c_ptr, y+d, x);
3666                 if (!cave_los_grid(c_ptr)) break;
3667         }
3668
3669         /* Initialize the "south strips" */
3670         se = sw = d;
3671
3672         /* Scan north */
3673         for (d = 1; d <= full; d++)
3674         {
3675                 c_ptr = &cave[y-d][x];
3676                 c_ptr->info |= (CAVE_XTRA);
3677                 cave_view_hack(c_ptr, y-d, x);
3678                 if (!cave_los_grid(c_ptr)) break;
3679         }
3680
3681         /* Initialize the "north strips" */
3682         ne = nw = d;
3683
3684         /* Scan east */
3685         for (d = 1; d <= full; d++)
3686         {
3687                 c_ptr = &cave[y][x+d];
3688                 c_ptr->info |= (CAVE_XTRA);
3689                 cave_view_hack(c_ptr, y, x+d);
3690                 if (!cave_los_grid(c_ptr)) break;
3691         }
3692
3693         /* Initialize the "east strips" */
3694         es = en = d;
3695
3696         /* Scan west */
3697         for (d = 1; d <= full; d++)
3698         {
3699                 c_ptr = &cave[y][x-d];
3700                 c_ptr->info |= (CAVE_XTRA);
3701                 cave_view_hack(c_ptr, y, x-d);
3702                 if (!cave_los_grid(c_ptr)) break;
3703         }
3704
3705         /* Initialize the "west strips" */
3706         ws = wn = d;
3707
3708
3709         /*** Step 4 -- Divide each "octant" into "strips" ***/
3710
3711         /* Now check each "diagonal" (in parallel) */
3712         for (n = 1; n <= over / 2; n++)
3713         {
3714                 int ypn, ymn, xpn, xmn;
3715
3716
3717                 /* Acquire the "bounds" of the maximal circle */
3718                 z = over - n - n;
3719                 if (z > full - n) z = full - n;
3720                 while ((z + n + (n>>1)) > full) z--;
3721
3722
3723                 /* Access the four diagonal grids */
3724                 ypn = y + n;
3725                 ymn = y - n;
3726                 xpn = x + n;
3727                 xmn = x - n;
3728
3729
3730                 /* South strip */
3731                 if (ypn < y_max)
3732                 {
3733                         /* Maximum distance */
3734                         m = MIN(z, y_max - ypn);
3735
3736                         /* East side */
3737                         if ((xpn <= x_max) && (n < se))
3738                         {
3739                                 /* Scan */
3740                                 for (k = n, d = 1; d <= m; d++)
3741                                 {
3742                                         /* Check grid "d" in strip "n", notice "blockage" */
3743                                         if (update_view_aux(ypn+d, xpn, ypn+d-1, xpn-1, ypn+d-1, xpn))
3744                                         {
3745                                                 if (n + d >= se) break;
3746                                         }
3747
3748                                         /* Track most distant "non-blockage" */
3749                                         else
3750                                         {
3751                                                 k = n + d;
3752                                         }
3753                                 }
3754
3755                                 /* Limit the next strip */
3756                                 se = k + 1;
3757                         }
3758
3759                         /* West side */
3760                         if ((xmn >= 0) && (n < sw))
3761                         {
3762                                 /* Scan */
3763                                 for (k = n, d = 1; d <= m; d++)
3764                                 {
3765                                         /* Check grid "d" in strip "n", notice "blockage" */
3766                                         if (update_view_aux(ypn+d, xmn, ypn+d-1, xmn+1, ypn+d-1, xmn))
3767                                         {
3768                                                 if (n + d >= sw) break;
3769                                         }
3770
3771                                         /* Track most distant "non-blockage" */
3772                                         else
3773                                         {
3774                                                 k = n + d;
3775                                         }
3776                                 }
3777
3778                                 /* Limit the next strip */
3779                                 sw = k + 1;
3780                         }
3781                 }
3782
3783
3784                 /* North strip */
3785                 if (ymn > 0)
3786                 {
3787                         /* Maximum distance */
3788                         m = MIN(z, ymn);
3789
3790                         /* East side */
3791                         if ((xpn <= x_max) && (n < ne))
3792                         {
3793                                 /* Scan */
3794                                 for (k = n, d = 1; d <= m; d++)
3795                                 {
3796                                         /* Check grid "d" in strip "n", notice "blockage" */
3797                                         if (update_view_aux(ymn-d, xpn, ymn-d+1, xpn-1, ymn-d+1, xpn))
3798                                         {
3799                                                 if (n + d >= ne) break;
3800                                         }
3801
3802                                         /* Track most distant "non-blockage" */
3803                                         else
3804                                         {
3805                                                 k = n + d;
3806                                         }
3807                                 }
3808
3809                                 /* Limit the next strip */
3810                                 ne = k + 1;
3811                         }
3812
3813                         /* West side */
3814                         if ((xmn >= 0) && (n < nw))
3815                         {
3816                                 /* Scan */
3817                                 for (k = n, d = 1; d <= m; d++)
3818                                 {
3819                                         /* Check grid "d" in strip "n", notice "blockage" */
3820                                         if (update_view_aux(ymn-d, xmn, ymn-d+1, xmn+1, ymn-d+1, xmn))
3821                                         {
3822                                                 if (n + d >= nw) break;
3823                                         }
3824
3825                                         /* Track most distant "non-blockage" */
3826                                         else
3827                                         {
3828                                                 k = n + d;
3829                                         }
3830                                 }
3831
3832                                 /* Limit the next strip */
3833                                 nw = k + 1;
3834                         }
3835                 }
3836
3837
3838                 /* East strip */
3839                 if (xpn < x_max)
3840                 {
3841                         /* Maximum distance */
3842                         m = MIN(z, x_max - xpn);
3843
3844                         /* South side */
3845                         if ((ypn <= x_max) && (n < es))
3846                         {
3847                                 /* Scan */
3848                                 for (k = n, d = 1; d <= m; d++)
3849                                 {
3850                                         /* Check grid "d" in strip "n", notice "blockage" */
3851                                         if (update_view_aux(ypn, xpn+d, ypn-1, xpn+d-1, ypn, xpn+d-1))
3852                                         {
3853                                                 if (n + d >= es) break;
3854                                         }
3855
3856                                         /* Track most distant "non-blockage" */
3857                                         else
3858                                         {
3859                                                 k = n + d;
3860                                         }
3861                                 }
3862
3863                                 /* Limit the next strip */
3864                                 es = k + 1;
3865                         }
3866
3867                         /* North side */
3868                         if ((ymn >= 0) && (n < en))
3869                         {
3870                                 /* Scan */
3871                                 for (k = n, d = 1; d <= m; d++)
3872                                 {
3873                                         /* Check grid "d" in strip "n", notice "blockage" */
3874                                         if (update_view_aux(ymn, xpn+d, ymn+1, xpn+d-1, ymn, xpn+d-1))
3875                                         {
3876                                                 if (n + d >= en) break;
3877                                         }
3878
3879                                         /* Track most distant "non-blockage" */
3880                                         else
3881                                         {
3882                                                 k = n + d;
3883                                         }
3884                                 }
3885
3886                                 /* Limit the next strip */
3887                                 en = k + 1;
3888                         }
3889                 }
3890
3891
3892                 /* West strip */
3893                 if (xmn > 0)
3894                 {
3895                         /* Maximum distance */
3896                         m = MIN(z, xmn);
3897
3898                         /* South side */
3899                         if ((ypn <= y_max) && (n < ws))
3900                         {
3901                                 /* Scan */
3902                                 for (k = n, d = 1; d <= m; d++)
3903                                 {
3904                                         /* Check grid "d" in strip "n", notice "blockage" */
3905                                         if (update_view_aux(ypn, xmn-d, ypn-1, xmn-d+1, ypn, xmn-d+1))
3906                                         {
3907                                                 if (n + d >= ws) break;
3908                                         }
3909
3910                                         /* Track most distant "non-blockage" */
3911                                         else
3912                                         {
3913                                                 k = n + d;
3914                                         }
3915                                 }
3916
3917                                 /* Limit the next strip */
3918                                 ws = k + 1;
3919                         }
3920
3921                         /* North side */
3922                         if ((ymn >= 0) && (n < wn))
3923                         {
3924                                 /* Scan */
3925                                 for (k = n, d = 1; d <= m; d++)
3926                                 {
3927                                         /* Check grid "d" in strip "n", notice "blockage" */
3928                                         if (update_view_aux(ymn, xmn-d, ymn+1, xmn-d+1, ymn, xmn-d+1))
3929                                         {
3930                                                 if (n + d >= wn) break;
3931                                         }
3932
3933                                         /* Track most distant "non-blockage" */
3934                                         else
3935                                         {
3936                                                 k = n + d;
3937                                         }
3938                                 }
3939
3940                                 /* Limit the next strip */
3941                                 wn = k + 1;
3942                         }
3943                 }
3944         }
3945
3946
3947         /*** Step 5 -- Complete the algorithm ***/
3948
3949         /* Update all the new grids */
3950         for (n = 0; n < view_n; n++)
3951         {
3952                 y = view_y[n];
3953                 x = view_x[n];
3954
3955                 /* Access the grid */
3956                 c_ptr = &cave[y][x];
3957
3958                 /* Clear the "CAVE_XTRA" flag */
3959                 c_ptr->info &= ~(CAVE_XTRA);
3960
3961                 /* Update only newly viewed grids */
3962                 if (c_ptr->info & (CAVE_TEMP)) continue;
3963
3964                 /* Add it to later visual update */
3965                 cave_note_and_redraw_later(c_ptr, y, x);
3966         }
3967
3968         /* Wipe the old grids, update as needed */
3969         for (n = 0; n < temp_n; n++)
3970         {
3971                 y = temp_y[n];
3972                 x = temp_x[n];
3973
3974                 /* Access the grid */
3975                 c_ptr = &cave[y][x];
3976
3977                 /* No longer in the array */
3978                 c_ptr->info &= ~(CAVE_TEMP);
3979
3980                 /* Update only non-viewable grids */
3981                 if (c_ptr->info & (CAVE_VIEW)) continue;
3982
3983                 /* Add it to later visual update */
3984                 cave_redraw_later(c_ptr, y, x);
3985         }
3986
3987         /* None left */
3988         temp_n = 0;
3989
3990         /* Mega-Hack -- Visual update later */
3991         p_ptr->update |= (PU_DELAY_VIS);
3992 }
3993
3994
3995 /*
3996  * Mega-Hack -- Delayed visual update
3997  * Only used if update_view(), update_lite() or update_mon_lite() was called
3998  */
3999 void delayed_visual_update(void)
4000 {
4001         int       i, y, x;
4002         cave_type *c_ptr;
4003
4004         /* Update needed grids */
4005         for (i = 0; i < redraw_n; i++)
4006         {
4007                 y = redraw_y[i];
4008                 x = redraw_x[i];
4009
4010                 /* Access the grid */
4011                 c_ptr = &cave[y][x];
4012
4013                 /* Update only needed grids (prevent multiple updating) */
4014                 if (!(c_ptr->info & CAVE_REDRAW)) continue;
4015
4016                 /* If required, note */
4017                 if (c_ptr->info & CAVE_NOTE) note_spot(y, x);
4018
4019                 /* Redraw */
4020                 lite_spot(y, x);
4021
4022                 /* Hack -- Visual update of monster on this grid */
4023                 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4024
4025                 /* No longer in the array */
4026                 c_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4027         }
4028
4029         /* None left */
4030         redraw_n = 0;
4031 }
4032
4033
4034 /*
4035  * Hack -- forget the "flow" information
4036  */
4037 void forget_flow(void)
4038 {
4039         int x, y;
4040
4041         /* Check the entire dungeon */
4042         for (y = 0; y < cur_hgt; y++)
4043         {
4044                 for (x = 0; x < cur_wid; x++)
4045                 {
4046                         /* Forget the old data */
4047                         cave[y][x].dist = 0;
4048                         cave[y][x].cost = 0;
4049                         cave[y][x].when = 0;
4050                 }
4051         }
4052 }
4053
4054
4055 /*
4056  * Hack - speed up the update_flow algorithm by only doing
4057  * it everytime the player moves out of LOS of the last
4058  * "way-point".
4059  */
4060 static u16b flow_x = 0;
4061 static u16b flow_y = 0;
4062
4063
4064
4065 /*
4066  * Hack -- fill in the "cost" field of every grid that the player
4067  * can "reach" with the number of steps needed to reach that grid.
4068  * This also yields the "distance" of the player from every grid.
4069  *
4070  * In addition, mark the "when" of the grids that can reach
4071  * the player with the incremented value of "flow_n".
4072  *
4073  * Hack -- use the "seen" array as a "circular queue".
4074  *
4075  * We do not need a priority queue because the cost from grid
4076  * to grid is always "one" and we process them in order.
4077  */
4078 void update_flow(void)
4079 {
4080         int x, y, d;
4081         int flow_head = 1;
4082         int flow_tail = 0;
4083
4084         /* Paranoia -- make sure the array is empty */
4085         if (temp_n) return;
4086
4087         /* The last way-point is on the map */
4088         if (running && in_bounds(flow_y, flow_x))
4089         {
4090                 /* The way point is in sight - do not update.  (Speedup) */
4091                 if (cave[flow_y][flow_x].info & CAVE_VIEW) return;
4092         }
4093
4094         /* Erase all of the current flow information */
4095         for (y = 0; y < cur_hgt; y++)
4096         {
4097                 for (x = 0; x < cur_wid; x++)
4098                 {
4099                         cave[y][x].cost = 0;
4100                         cave[y][x].dist = 0;
4101                 }
4102         }
4103
4104         /* Save player position */
4105         flow_y = py;
4106         flow_x = px;
4107
4108         /* Add the player's grid to the queue */
4109         temp_y[0] = py;
4110         temp_x[0] = px;
4111
4112         /* Now process the queue */
4113         while (flow_head != flow_tail)
4114         {
4115                 int ty, tx;
4116
4117                 /* Extract the next entry */
4118                 ty = temp_y[flow_tail];
4119                 tx = temp_x[flow_tail];
4120
4121                 /* Forget that entry */
4122                 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4123
4124                 /* Add the "children" */
4125                 for (d = 0; d < 8; d++)
4126                 {
4127                         int old_head = flow_head;
4128                         int m = cave[ty][tx].cost + 1;
4129                         int n = cave[ty][tx].dist + 1;
4130                         cave_type *c_ptr;
4131
4132                         /* Child location */
4133                         y = ty + ddy_ddd[d];
4134                         x = tx + ddx_ddd[d];
4135
4136                         /* Ignore player's grid */
4137                         if (player_bold(y, x)) continue;
4138
4139                         c_ptr = &cave[y][x];
4140
4141                         if (is_closed_door(c_ptr->feat)) m += 3;
4142
4143                         /* Ignore "pre-stamped" entries */
4144                         if (c_ptr->dist != 0 && c_ptr->dist <= n && c_ptr->cost <= m) continue;
4145
4146                         /* Ignore "walls" and "rubble" */
4147                         if (!have_flag(f_flags_grid(c_ptr), FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4148
4149                         /* Save the flow cost */
4150                         if (c_ptr->cost == 0 || c_ptr->cost > m) c_ptr->cost = m;
4151                         if (c_ptr->dist == 0 || c_ptr->dist > n) c_ptr->dist = n;
4152
4153                         /* Hack -- limit flow depth */
4154                         if (n == MONSTER_FLOW_DEPTH) continue;
4155
4156                         /* Enqueue that entry */
4157                         temp_y[flow_head] = y;
4158                         temp_x[flow_head] = x;
4159
4160                         /* Advance the queue */
4161                         if (++flow_head == TEMP_MAX) flow_head = 0;
4162
4163                         /* Hack -- notice overflow by forgetting new entry */
4164                         if (flow_head == flow_tail) flow_head = old_head;
4165                 }
4166         }
4167 }
4168
4169
4170 static int scent_when = 0;
4171
4172 /*
4173  * Characters leave scent trails for perceptive monsters to track.
4174  *
4175  * Smell is rather more limited than sound.  Many creatures cannot use 
4176  * it at all, it doesn't extend very far outwards from the character's 
4177  * current position, and monsters can use it to home in the character, 
4178  * but not to run away from him.
4179  *
4180  * Smell is valued according to age.  When a character takes his turn, 
4181  * scent is aged by one, and new scent of the current age is laid down.  
4182  * Speedy characters leave more scent, true, but it also ages faster, 
4183  * which makes it harder to hunt them down.
4184  *
4185  * Whenever the age count loops, most of the scent trail is erased and 
4186  * the age of the remainder is recalculated.
4187  */
4188 void update_smell(void)
4189 {
4190         int i, j;
4191         int y, x;
4192
4193         /* Create a table that controls the spread of scent */
4194         const int scent_adjust[5][5] = 
4195         {
4196                 { -1, 0, 0, 0,-1 },
4197                 {  0, 1, 1, 1, 0 },
4198                 {  0, 1, 2, 1, 0 },
4199                 {  0, 1, 1, 1, 0 },
4200                 { -1, 0, 0, 0,-1 },
4201         };
4202
4203         /* Loop the age and adjust scent values when necessary */
4204         if (++scent_when == 254)
4205         {
4206                 /* Scan the entire dungeon */
4207                 for (y = 0; y < cur_hgt; y++)
4208                 {
4209                         for (x = 0; x < cur_wid; x++)
4210                         {
4211                                 int w = cave[y][x].when;
4212                                 cave[y][x].when = (w > 128) ? (w - 128) : 0;
4213                         }
4214                 }
4215
4216                 /* Restart */
4217                 scent_when = 126;
4218         }
4219
4220
4221         /* Lay down new scent */
4222         for (i = 0; i < 5; i++)
4223         {
4224                 for (j = 0; j < 5; j++)
4225                 {
4226                         cave_type *c_ptr;
4227
4228                         /* Translate table to map grids */
4229                         y = i + py - 2;
4230                         x = j + px - 2;
4231
4232                         /* Check Bounds */
4233                         if (!in_bounds(y, x)) continue;
4234
4235                         c_ptr = &cave[y][x];
4236
4237                         /* Walls, water, and lava cannot hold scent. */
4238                         if (!have_flag(f_flags_grid(c_ptr), FF_MOVE) && !is_closed_door(c_ptr->feat)) continue;
4239
4240                         /* Grid must not be blocked by walls from the character */
4241                         if (!player_has_los_bold(y, x)) continue;
4242
4243                         /* Note grids that are too far away */
4244                         if (scent_adjust[i][j] == -1) continue;
4245
4246                         /* Mark the grid with new scent */
4247                         c_ptr->when = scent_when + scent_adjust[i][j];
4248                 }
4249         }
4250 }
4251
4252
4253 /*
4254  * Hack -- map the current panel (plus some) ala "magic mapping"
4255  */
4256 void map_area(int range)
4257 {
4258         int             i, x, y;
4259         cave_type       *c_ptr;
4260         s16b            feat;
4261         feature_type    *f_ptr;
4262
4263         if (d_info[dungeon_type].flags1 & DF1_DARKNESS) range /= 3;
4264
4265         /* Scan that area */
4266         for (y = 1; y < cur_hgt - 1; y++)
4267         {
4268                 for (x = 1; x < cur_wid - 1; x++)
4269                 {
4270                         if (distance(py, px, y, x) > range) continue;
4271
4272                         c_ptr = &cave[y][x];
4273
4274                         /* Feature code (applying "mimic" field) */
4275                         feat = get_feat_mimic(c_ptr);
4276                         f_ptr = &f_info[feat];
4277
4278                         /* All non-walls are "checked" */
4279                         if (!have_flag(f_ptr->flags, FF_WALL))
4280                         {
4281                                 /* Memorize normal features */
4282                                 if (have_flag(f_ptr->flags, FF_REMEMBER))
4283                                 {
4284                                         /* Memorize the object */
4285                                         c_ptr->info |= (CAVE_MARK);
4286                                 }
4287
4288                                 /* Memorize known walls */
4289                                 for (i = 0; i < 8; i++)
4290                                 {
4291                                         c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]];
4292
4293                                         /* Feature code (applying "mimic" field) */
4294                                         feat = get_feat_mimic(c_ptr);
4295                                         f_ptr = &f_info[feat];
4296
4297                                         /* Memorize walls (etc) */
4298                                         if (have_flag(f_ptr->flags, FF_REMEMBER))
4299                                         {
4300                                                 /* Memorize the walls */
4301                                                 c_ptr->info |= (CAVE_MARK);
4302                                         }
4303                                 }
4304                         }
4305                 }
4306         }
4307
4308         /* Redraw map */
4309         p_ptr->redraw |= (PR_MAP);
4310
4311         /* Window stuff */
4312         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4313 }
4314
4315
4316
4317 /*
4318  * Light up the dungeon using "clairvoyance"
4319  *
4320  * This function "illuminates" every grid in the dungeon, memorizes all
4321  * "objects", memorizes all grids as with magic mapping, and, under the
4322  * standard option settings (view_perma_grids but not view_torch_grids)
4323  * memorizes all floor grids too.
4324  *
4325  * Note that if "view_perma_grids" is not set, we do not memorize floor
4326  * grids, since this would defeat the purpose of "view_perma_grids", not
4327  * that anyone seems to play without this option.
4328  *
4329  * Note that if "view_torch_grids" is set, we do not memorize floor grids,
4330  * since this would prevent the use of "view_torch_grids" as a method to
4331  * keep track of what grids have been observed directly.
4332  */
4333 void wiz_lite(bool ninja)
4334 {
4335         int i, y, x;
4336         s16b feat;
4337         feature_type *f_ptr;
4338
4339         /* Memorize objects */
4340         for (i = 1; i < o_max; i++)
4341         {
4342                 object_type *o_ptr = &o_list[i];
4343
4344                 /* Skip dead objects */
4345                 if (!o_ptr->k_idx) continue;
4346
4347                 /* Skip held objects */
4348                 if (o_ptr->held_m_idx) continue;
4349
4350                 /* Memorize */
4351                 o_ptr->marked |= OM_FOUND;
4352         }
4353
4354         /* Scan all normal grids */
4355         for (y = 1; y < cur_hgt - 1; y++)
4356         {
4357                 /* Scan all normal grids */
4358                 for (x = 1; x < cur_wid - 1; x++)
4359                 {
4360                         cave_type *c_ptr = &cave[y][x];
4361
4362                         /* Feature code (applying "mimic" field) */
4363                         feat = get_feat_mimic(c_ptr);
4364                         f_ptr = &f_info[feat];
4365
4366                         /* Process all non-walls */
4367                         if (!have_flag(f_ptr->flags, FF_WALL))
4368                         {
4369                                 /* Scan all neighbors */
4370                                 for (i = 0; i < 9; i++)
4371                                 {
4372                                         int yy = y + ddy_ddd[i];
4373                                         int xx = x + ddx_ddd[i];
4374
4375                                         /* Get the grid */
4376                                         c_ptr = &cave[yy][xx];
4377
4378                                         /* Feature code (applying "mimic" field) */
4379                                         f_ptr = &f_info[get_feat_mimic(c_ptr)];
4380
4381                                         /* Perma-lite the grid */
4382                                         if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS) && !ninja)
4383                                         {
4384                                                 c_ptr->info |= (CAVE_GLOW);
4385                                         }
4386
4387                                         /* Memorize normal features */
4388                                         if (have_flag(f_ptr->flags, FF_REMEMBER))
4389                                         {
4390                                                 /* Memorize the grid */
4391                                                 c_ptr->info |= (CAVE_MARK);
4392                                         }
4393
4394                                         /* Perma-lit grids (newly and previously) */
4395                                         else if (c_ptr->info & CAVE_GLOW)
4396                                         {
4397                                                 /* Normally, memorize floors (see above) */
4398                                                 if (view_perma_grids && !view_torch_grids)
4399                                                 {
4400                                                         /* Memorize the grid */
4401                                                         c_ptr->info |= (CAVE_MARK);
4402                                                 }
4403                                         }
4404                                 }
4405                         }
4406                 }
4407         }
4408
4409         /* Update the monsters */
4410         p_ptr->update |= (PU_MONSTERS);
4411
4412         /* Redraw map */
4413         p_ptr->redraw |= (PR_MAP);
4414
4415         /* Window stuff */
4416         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4417 }
4418
4419
4420 /*
4421  * Forget the dungeon map (ala "Thinking of Maud...").
4422  */
4423 void wiz_dark(void)
4424 {
4425         int i, y, x;
4426
4427
4428         /* Forget every grid */
4429         for (y = 1; y < cur_hgt - 1; y++)
4430         {
4431                 for (x = 1; x < cur_wid - 1; x++)
4432                 {
4433                         cave_type *c_ptr = &cave[y][x];
4434
4435                         /* Process the grid */
4436                         c_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT);
4437                         c_ptr->info |= (CAVE_UNSAFE);
4438                 }
4439         }
4440
4441         /* Forget every grid on horizontal edge */
4442         for (x = 0; x < cur_wid; x++)
4443         {
4444                 cave[0][x].info &= ~(CAVE_MARK);
4445                 cave[cur_hgt - 1][x].info &= ~(CAVE_MARK);
4446         }
4447
4448         /* Forget every grid on vertical edge */
4449         for (y = 1; y < (cur_hgt - 1); y++)
4450         {
4451                 cave[y][0].info &= ~(CAVE_MARK);
4452                 cave[y][cur_wid - 1].info &= ~(CAVE_MARK);
4453         }
4454
4455         /* Forget all objects */
4456         for (i = 1; i < o_max; i++)
4457         {
4458                 object_type *o_ptr = &o_list[i];
4459
4460                 /* Skip dead objects */
4461                 if (!o_ptr->k_idx) continue;
4462
4463                 /* Skip held objects */
4464                 if (o_ptr->held_m_idx) continue;
4465
4466                 /* Forget the object */
4467                 o_ptr->marked = 0;
4468         }
4469
4470         /* Mega-Hack -- Forget the view and lite */
4471         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
4472
4473         /* Update the view and lite */
4474         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4475
4476         /* Update the monsters */
4477         p_ptr->update |= (PU_MONSTERS);
4478
4479         /* Redraw map */
4480         p_ptr->redraw |= (PR_MAP);
4481
4482         /* Window stuff */
4483         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4484 }
4485
4486
4487
4488
4489
4490 /*
4491  * Change the "feat" flag for a grid, and notice/redraw the grid
4492  */
4493 void cave_set_feat(int y, int x, int feat)
4494 {
4495         cave_type *c_ptr = &cave[y][x];
4496         feature_type *f_ptr = &f_info[feat];
4497
4498         if (character_dungeon && is_mirror_grid(c_ptr) && (d_info[dungeon_type].flags1 & DF1_DARKNESS))
4499         {
4500                 c_ptr->info &= ~(CAVE_GLOW);
4501                 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4502
4503                 /* Remove flag for mirror/glyph */
4504                 c_ptr->info &= ~(CAVE_OBJECT);
4505
4506                 update_local_illumination(y, x);
4507         }
4508
4509         /* Clear mimic type */
4510         c_ptr->mimic = 0;
4511
4512         /* Change the feature */
4513         c_ptr->feat = feat;
4514
4515         if (character_dungeon)
4516         {
4517                 /* Check for change to boring grid */
4518                 if (!have_flag(f_ptr->flags, FF_REMEMBER)) c_ptr->info &= ~(CAVE_MARK);
4519
4520                 /* Check for change to out of sight grid */
4521                 else if (!player_can_see_bold(y, x)) c_ptr->info &= ~(CAVE_MARK);
4522
4523                 /* Update the monster */
4524                 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4525
4526                 /* Notice */
4527                 note_spot(y, x);
4528
4529                 /* Redraw */
4530                 lite_spot(y, x);
4531         }
4532
4533         /* Hack -- glow the deep lava */
4534         if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
4535         {
4536                 int i, yy, xx;
4537                 cave_type *cc_ptr;
4538
4539                 for (i = 0; i < 9; i++)
4540                 {
4541                         yy = y + ddy_ddd[i];
4542                         xx = x + ddx_ddd[i];
4543                         if (!in_bounds2(yy, xx)) continue;
4544                         cc_ptr = &cave[yy][xx];
4545                         cc_ptr->info |= CAVE_GLOW;
4546                         if (character_dungeon)
4547                         {
4548                                 if (player_has_los_grid(cc_ptr))
4549                                 {
4550                                         /* Update the monster */
4551                                         if (cc_ptr->m_idx) update_mon(cc_ptr->m_idx, FALSE);
4552
4553                                         /* Notice */
4554                                         note_spot(yy, xx);
4555
4556                                         /* Redraw */
4557                                         lite_spot(yy, xx);
4558                                 }
4559
4560                                 update_local_illumination(yy, xx);
4561                         }
4562                 }
4563         }
4564 }
4565
4566
4567 int conv_dungeon_feat(int newfeat)
4568 {
4569         feature_type *f_ptr = &f_info[newfeat];
4570
4571         if (have_flag(f_ptr->flags, FF_CONVERT))
4572         {
4573                 switch (f_ptr->power)
4574                 {
4575                 case CONVERT_TYPE_FLOOR:
4576                         return floor_type[randint0(100)];
4577                 case CONVERT_TYPE_WALL:
4578                         return fill_type[randint0(100)];
4579                 case CONVERT_TYPE_INNER:
4580                         return feat_wall_inner;
4581                 case CONVERT_TYPE_OUTER:
4582                         return feat_wall_outer;
4583                 case CONVERT_TYPE_SOLID:
4584                         return feat_wall_solid;
4585                 case CONVERT_TYPE_STREAM1:
4586                         return d_info[dungeon_type].stream1;
4587                 case CONVERT_TYPE_STREAM2:
4588                         return d_info[dungeon_type].stream2;
4589                 default:
4590                         return newfeat;
4591                 }
4592         }
4593         else return newfeat;
4594 }
4595
4596
4597 /*
4598  * Take a feature, determine what that feature becomes
4599  * through applying the given action.
4600  */
4601 int feat_state(int feat, int action)
4602 {
4603         feature_type *f_ptr = &f_info[feat];
4604         int i;
4605
4606         /* Get the new feature */
4607         for (i = 0; i < MAX_FEAT_STATES; i++)
4608         {
4609                 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
4610         }
4611
4612         if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
4613
4614         return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
4615 }
4616
4617 /*
4618  * Takes a location and action and changes the feature at that 
4619  * location through applying the given action.
4620  */
4621 void cave_alter_feat(int y, int x, int action)
4622 {
4623         /* Set old feature */
4624         int oldfeat = cave[y][x].feat;
4625
4626         /* Get the new feat */
4627         int newfeat = feat_state(oldfeat, action);
4628
4629         /* No change */
4630         if (newfeat == oldfeat) return;
4631
4632         /* Set the new feature */
4633         cave_set_feat(y, x, newfeat);
4634
4635         if (!(feature_action_flags[action] & FAF_NO_DROP))
4636         {
4637                 feature_type *old_f_ptr = &f_info[oldfeat];
4638                 feature_type *f_ptr = &f_info[newfeat];
4639                 bool found = FALSE;
4640
4641                 /* Handle gold */
4642                 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
4643                 {
4644                         /* Place some gold */
4645                         place_gold(y, x);
4646                         found = TRUE;
4647                 }
4648
4649                 /* Handle item */
4650                 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - dun_level / 2)))
4651                 {
4652                         /* Place object */
4653                         place_object(y, x, 0L);
4654                         found = TRUE;
4655                 }
4656
4657                 if (found && character_dungeon && player_can_see_bold(y, x))
4658                 {
4659 #ifdef JP
4660                         msg_print("²¿¤«¤òȯ¸«¤·¤¿¡ª");
4661 #else
4662                         msg_print("You have found something!");
4663 #endif
4664                 }
4665         }
4666 }
4667
4668
4669 /* Remove a mirror */
4670 void remove_mirror(int y, int x)
4671 {
4672         cave_type *c_ptr = &cave[y][x];
4673
4674         /* Remove the mirror */
4675         c_ptr->info &= ~(CAVE_OBJECT);
4676         c_ptr->mimic = 0;
4677
4678         if (d_info[dungeon_type].flags1 & DF1_DARKNESS)
4679         {
4680                 c_ptr->info &= ~(CAVE_GLOW);
4681                 if (!view_torch_grids) c_ptr->info &= ~(CAVE_MARK);
4682
4683                 /* Update the monster */
4684                 if (c_ptr->m_idx) update_mon(c_ptr->m_idx, FALSE);
4685
4686                 update_local_illumination(y, x);
4687         }
4688
4689         /* Notice */
4690         note_spot(y, x);
4691
4692         /* Redraw */
4693         lite_spot(y, x);
4694 }
4695
4696
4697 /*
4698  *  Return TRUE if there is a mirror on the grid.
4699  */
4700 bool is_mirror_grid(cave_type *c_ptr)
4701 {
4702         if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MIRROR))
4703                 return TRUE;
4704         else
4705                 return FALSE;
4706 }
4707
4708
4709 /*
4710  *  Return TRUE if there is a mirror on the grid.
4711  */
4712 bool is_glyph_grid(cave_type *c_ptr)
4713 {
4714         if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_GLYPH))
4715                 return TRUE;
4716         else
4717                 return FALSE;
4718 }
4719
4720
4721 /*
4722  *  Return TRUE if there is a mirror on the grid.
4723  */
4724 bool is_explosive_rune_grid(cave_type *c_ptr)
4725 {
4726         if ((c_ptr->info & CAVE_OBJECT) && have_flag(f_info[c_ptr->mimic].flags, FF_MINOR_GLYPH))
4727                 return TRUE;
4728         else
4729                 return FALSE;
4730 }
4731
4732
4733 /*
4734  * Calculate "incremental motion". Used by project() and shoot().
4735  * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
4736  */
4737 void mmove2(int *y, int *x, int y1, int x1, int y2, int x2)
4738 {
4739         int dy, dx, dist, shift;
4740
4741         /* Extract the distance travelled */
4742         dy = (*y < y1) ? y1 - *y : *y - y1;
4743         dx = (*x < x1) ? x1 - *x : *x - x1;
4744
4745         /* Number of steps */
4746         dist = (dy > dx) ? dy : dx;
4747
4748         /* We are calculating the next location */
4749         dist++;
4750
4751
4752         /* Calculate the total distance along each axis */
4753         dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
4754         dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
4755
4756         /* Paranoia -- Hack -- no motion */
4757         if (!dy && !dx) return;
4758
4759
4760         /* Move mostly vertically */
4761         if (dy > dx)
4762         {
4763                 /* Extract a shift factor */
4764                 shift = (dist * dx + (dy - 1) / 2) / dy;
4765
4766                 /* Sometimes move along the minor axis */
4767                 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
4768
4769                 /* Always move along major axis */
4770                 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
4771         }
4772
4773         /* Move mostly horizontally */
4774         else
4775         {
4776                 /* Extract a shift factor */
4777                 shift = (dist * dy + (dx - 1) / 2) / dx;
4778
4779                 /* Sometimes move along the minor axis */
4780                 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
4781
4782                 /* Always move along major axis */
4783                 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
4784         }
4785 }
4786
4787
4788
4789 /*
4790  * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
4791  * at the final destination, assuming no monster gets in the way.
4792  *
4793  * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
4794  */
4795 bool projectable(int y1, int x1, int y2, int x2)
4796 {
4797         int y, x;
4798
4799         int grid_n = 0;
4800         u16b grid_g[512];
4801
4802         /* Check the projection path */
4803         grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
4804
4805         /* Identical grid */
4806         if (!grid_n) return TRUE;
4807
4808         /* Final grid */
4809         y = GRID_Y(grid_g[grid_n - 1]);
4810         x = GRID_X(grid_g[grid_n - 1]);
4811
4812         /* May not end in an unrequested grid */
4813         if ((y != y2) || (x != x2)) return (FALSE);
4814
4815         /* Assume okay */
4816         return (TRUE);
4817 }
4818
4819
4820 /*
4821  * Standard "find me a location" function
4822  *
4823  * Obtains a legal location within the given distance of the initial
4824  * location, and with "los()" from the source to destination location.
4825  *
4826  * This function is often called from inside a loop which searches for
4827  * locations while increasing the "d" distance.
4828  *
4829  * Currently the "m" parameter is unused.
4830  */
4831 void scatter(int *yp, int *xp, int y, int x, int d, int m)
4832 {
4833         int nx, ny;
4834
4835         /* Unused */
4836         m = m;
4837
4838         /* Pick a location */
4839         while (TRUE)
4840         {
4841                 /* Pick a new location */
4842                 ny = rand_spread(y, d);
4843                 nx = rand_spread(x, d);
4844
4845                 /* Ignore annoying locations */
4846                 if (!in_bounds(ny, nx)) continue;
4847
4848                 /* Ignore "excessively distant" locations */
4849                 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
4850
4851                 /* Require "line of projection" */
4852                 if (projectable(y, x, ny, nx)) break;
4853         }
4854
4855         /* Save the location */
4856         (*yp) = ny;
4857         (*xp) = nx;
4858 }
4859
4860
4861
4862
4863 /*
4864  * Track a new monster
4865  */
4866 void health_track(int m_idx)
4867 {
4868         /* Mount monster is already tracked */
4869         if (m_idx && m_idx == p_ptr->riding) return;
4870
4871         /* Track a new guy */
4872         p_ptr->health_who = m_idx;
4873
4874         /* Redraw (later) */
4875         p_ptr->redraw |= (PR_HEALTH);
4876 }
4877
4878
4879
4880 /*
4881  * Hack -- track the given monster race
4882  */
4883 void monster_race_track(int r_idx)
4884 {
4885         /* Save this monster ID */
4886         p_ptr->monster_race_idx = r_idx;
4887
4888         /* Window stuff */
4889         p_ptr->window |= (PW_MONSTER);
4890 }
4891
4892
4893
4894 /*
4895  * Hack -- track the given object kind
4896  */
4897 void object_kind_track(int k_idx)
4898 {
4899         /* Save this monster ID */
4900         p_ptr->object_kind_idx = k_idx;
4901
4902         /* Window stuff */
4903         p_ptr->window |= (PW_OBJECT);
4904 }
4905
4906
4907
4908 /*
4909  * Something has happened to disturb the player.
4910  *
4911  * The first arg indicates a major disturbance, which affects search.
4912  *
4913  * The second arg is currently unused, but could induce output flush.
4914  *
4915  * All disturbance cancels repeated commands, resting, and running.
4916  */
4917 void disturb(int stop_search, int unused_flag)
4918 {
4919         /* Unused */
4920         unused_flag = unused_flag;
4921
4922         /* Cancel auto-commands */
4923         /* command_new = 0; */
4924
4925         /* Cancel repeated commands */
4926         if (command_rep)
4927         {
4928                 /* Cancel */
4929                 command_rep = 0;
4930
4931                 /* Redraw the state (later) */
4932                 p_ptr->redraw |= (PR_STATE);
4933         }
4934
4935         /* Cancel Resting */
4936         if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
4937         {
4938                 /* Cancel */
4939                 set_action(ACTION_NONE);
4940         }
4941
4942         /* Cancel running */
4943         if (running)
4944         {
4945                 /* Cancel */
4946                 running = 0;
4947
4948                 /* Check for new panel if appropriate */
4949                 if (center_player && !center_running) verify_panel();
4950
4951                 /* Calculate torch radius */
4952                 p_ptr->update |= (PU_TORCH);
4953
4954                 /* Update monster flow */
4955                 p_ptr->update |= (PU_FLOW);
4956         }
4957
4958         /* Flush the input if requested */
4959         if (flush_disturb) flush();
4960 }
4961
4962
4963 /*
4964  * Glow deep lava and building entrances in the floor
4965  */
4966 void glow_deep_lava_and_bldg(void)
4967 {
4968         int y, x, i, yy, xx;
4969         cave_type *c_ptr;
4970
4971         /* Not in the darkness dungeon */
4972         if (d_info[dungeon_type].flags1 & DF1_DARKNESS) return;
4973
4974         for (y = 0; y < cur_hgt; y++)
4975         {
4976                 for (x = 0; x < cur_wid; x++)
4977                 {
4978                         c_ptr = &cave[y][x];
4979
4980                         /* Feature code (applying "mimic" field) */
4981
4982                         if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_GLOW))
4983                         {
4984                                 for (i = 0; i < 9; i++)
4985                                 {
4986                                         yy = y + ddy_ddd[i];
4987                                         xx = x + ddx_ddd[i];
4988                                         if (!in_bounds2(yy, xx)) continue;
4989                                         cave[yy][xx].info |= CAVE_GLOW;
4990                                 }
4991                         }
4992                 }
4993         }
4994
4995         /* Update the view and lite */
4996         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
4997
4998         /* Redraw map */
4999         p_ptr->redraw |= (PR_MAP);
5000 }