OSDN Git Service

[Refactor] #37353 forget_lite() を floor_event() に移動。
[hengband/hengband.git] / src / grid.c
1 
2  /*!
3   * @file grid.c
4   * @brief グリッドの実装 / low level dungeon routines -BEN-
5   * @date 2013/12/30
6   * @author
7   * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
8   *\n
9   * This software may be copied and distributed for educational, research,\n
10   * and not for profit purposes provided that this copyright and statement\n
11   * are included in all such copies.  Other copyrights may also apply.\n
12   * \n
13   * Support for Adam Bolt's tileset, lighting and transparency effects\n
14   * by Robert Ruehlmann (rr9@angband.org)\n
15   * \n
16   * 2013 Deskull Doxygen向けのコメント整理\n
17   */
18
19
20 #include "angband.h"
21 #include "floor.h"
22 #include "world.h"
23 #include "object-flavor.h"
24 #include "object-hook.h"
25 #include "generate.h"
26 #include "grid.h"
27 #include "trap.h"
28 #include "rooms.h"
29 #include "monster.h"
30 #include "quest.h"
31 #include "feature.h"
32 #include "monster-status.h"
33 #include "player-status.h"
34 #include "spells.h"
35 #include "view-mainwindow.h"
36
37 /*!
38  * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
39  * @return 配置に成功したらTRUEを返す
40  */
41 bool new_player_spot(void)
42 {
43         POSITION y = 0, x = 0;
44         int max_attempts = 10000;
45
46         grid_type *g_ptr;
47         feature_type *f_ptr;
48
49         /* Place the player */
50         while (max_attempts--)
51         {
52                 /* Pick a legal spot */
53                 y = (POSITION)rand_range(1, current_floor_ptr->height - 2);
54                 x = (POSITION)rand_range(1, current_floor_ptr->width - 2);
55
56                 g_ptr = &current_floor_ptr->grid_array[y][x];
57
58                 /* Must be a "naked" floor grid */
59                 if (g_ptr->m_idx) continue;
60                 if (current_floor_ptr->dun_level)
61                 {
62                         f_ptr = &f_info[g_ptr->feat];
63
64                         if (max_attempts > 5000) /* Rule 1 */
65                         {
66                                 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
67                         }
68                         else /* Rule 2 */
69                         {
70                                 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
71                                 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
72                         }
73
74                         /* Refuse to start on anti-teleport grids in dungeon */
75                         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
76                 }
77                 if (!player_can_enter(g_ptr->feat, 0)) continue;
78                 if (!in_bounds(y, x)) continue;
79
80                 /* Refuse to start on anti-teleport grids */
81                 if (g_ptr->info & (CAVE_ICKY)) continue;
82
83                 break;
84         }
85
86         if (max_attempts < 1) /* Should be -1, actually if we failed... */
87                 return FALSE;
88
89         /* Save the new player grid */
90         p_ptr->y = y;
91         p_ptr->x = x;
92
93         return TRUE;
94 }
95
96
97
98 /*!
99  * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
100  * @param y 配置を試みたいマスのY座標
101  * @param x 配置を試みたいマスのX座標
102  * @return なし
103  */
104 void place_random_stairs(POSITION y, POSITION x)
105 {
106         bool up_stairs = TRUE;
107         bool down_stairs = TRUE;
108         grid_type *g_ptr;
109         g_ptr = &current_floor_ptr->grid_array[y][x];
110         if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
111
112         /* Town */
113         if (!current_floor_ptr->dun_level) up_stairs = FALSE;
114
115         /* Ironman */
116         if (ironman_downward) up_stairs = FALSE;
117
118         /* Bottom */
119         if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
120
121         /* Quest-level */
122         if (quest_number(current_floor_ptr->dun_level) && (current_floor_ptr->dun_level > 1)) down_stairs = FALSE;
123
124         /* We can't place both */
125         if (down_stairs && up_stairs)
126         {
127                 /* Choose a staircase randomly */
128                 if (randint0(100) < 50) up_stairs = FALSE;
129                 else down_stairs = FALSE;
130         }
131
132         /* Place the stairs */
133         if (up_stairs) place_up_stairs(y, x);
134         else if (down_stairs) place_down_stairs(y, x);
135 }
136
137 /*!
138  * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
139  * @param y ドアの配置を試みたいマスのY座標
140  * @param x ドアの配置を試みたいマスのX座標
141  * @param room 部屋に接している場合向けのドア生成か否か
142  * @return なし
143  */
144 void place_random_door(POSITION y, POSITION x, bool room)
145 {
146         int tmp, type;
147         FEAT_IDX feat = feat_none;
148         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
149
150         /* Initialize mimic info */
151         g_ptr->mimic = 0;
152
153         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
154         {
155                 place_floor_bold(y, x);
156                 return;
157         }
158
159         type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
160                 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
161                 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
162
163         /* Choose an object */
164         tmp = randint0(1000);
165
166         /* Open doors (300/1000) */
167         if (tmp < 300)
168         {
169                 /* Create open door */
170                 feat = feat_door[type].open;
171         }
172
173         /* Broken doors (100/1000) */
174         else if (tmp < 400)
175         {
176                 /* Create broken door */
177                 feat = feat_door[type].broken;
178         }
179
180         /* Secret doors (200/1000) */
181         else if (tmp < 600)
182         {
183                 /* Create secret door */
184                 place_closed_door(y, x, type);
185
186                 if (type != DOOR_CURTAIN)
187                 {
188                         /* Hide. If on the edge of room, use outer wall. */
189                         g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
190
191                         /* Floor type terrain cannot hide a door */
192                         if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
193                         {
194                                 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
195                                 {
196                                         g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
197                                 }
198                                 g_ptr->mimic = 0;
199                         }
200                 }
201         }
202
203         /* Closed, locked, or stuck doors (400/1000) */
204         else place_closed_door(y, x, type);
205
206         if (tmp < 400)
207         {
208                 if (feat != feat_none)
209                 {
210                         set_cave_feat(y, x, feat);
211                 }
212                 else
213                 {
214                         place_floor_bold(y, x);
215                 }
216         }
217
218         delete_monster(y, x);
219 }
220
221 /*!
222  * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
223  * @param y ドアの配置を試みたいマスのY座標
224  * @param x ドアの配置を試みたいマスのX座標
225  * @param type ドアの地形ID
226  * @return なし
227  */
228 void place_closed_door(POSITION y, POSITION x, int type)
229 {
230         int tmp;
231         FEAT_IDX feat = feat_none;
232
233         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
234         {
235                 place_floor_bold(y, x);
236                 return;
237         }
238
239         /* Choose an object */
240         tmp = randint0(400);
241
242         /* Closed doors (300/400) */
243         if (tmp < 300)
244         {
245                 /* Create closed door */
246                 feat = feat_door[type].closed;
247         }
248
249         /* Locked doors (99/400) */
250         else if (tmp < 399)
251         {
252                 /* Create locked door */
253                 feat = feat_locked_door_random(type);
254         }
255
256         /* Stuck doors (1/400) */
257         else
258         {
259                 /* Create jammed door */
260                 feat = feat_jammed_door_random(type);
261         }
262
263         if (feat != feat_none)
264         {
265                 cave_set_feat(y, x, feat);
266
267                 /* Now it is not floor */
268                 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
269         }
270         else
271         {
272                 place_floor_bold(y, x);
273         }
274 }
275
276 /*!
277 * @brief 鍵のかかったドアを配置する
278 * @param y 配置したいフロアのY座標
279 * @param x 配置したいフロアのX座標
280 * @return なし
281 */
282 void place_locked_door(POSITION y, POSITION x)
283 {
284         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
285         {
286                 place_floor_bold(y, x);
287         }
288         else
289         {
290                 set_cave_feat(y, x, feat_locked_door_random((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
291                 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
292                 delete_monster(y, x);
293         }
294 }
295
296
297 /*!
298 * @brief 隠しドアを配置する
299 * @param y 配置したいフロアのY座標
300 * @param x 配置したいフロアのX座標
301 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
302 * @return なし
303 */
304 void place_secret_door(POSITION y, POSITION x, int type)
305 {
306         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
307         {
308                 place_floor_bold(y, x);
309         }
310         else
311         {
312                 grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
313
314                 if (type == DOOR_DEFAULT)
315                 {
316                         type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
317                                 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
318                                 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
319                 }
320
321                 /* Create secret door */
322                 place_closed_door(y, x, type);
323
324                 if (type != DOOR_CURTAIN)
325                 {
326                         /* Hide by inner wall because this is used in rooms only */
327                         g_ptr->mimic = feat_wall_inner;
328
329                         /* Floor type terrain cannot hide a door */
330                         if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
331                         {
332                                 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
333                                 {
334                                         g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
335                                 }
336                                 g_ptr->mimic = 0;
337                         }
338                 }
339
340                 g_ptr->info &= ~(CAVE_FLOOR);
341                 delete_monster(y, x);
342         }
343 }
344
345 /*
346  * Routine used by the random vault creators to add a door to a location
347  * Note that range checking has to be done in the calling routine.
348  *
349  * The doors must be INSIDE the allocated region.
350  */
351 void add_door(POSITION x, POSITION y)
352 {
353         /* Need to have a wall in the center square */
354         if (!is_outer_bold(y, x)) return;
355
356         /* look at:
357         *  x#x
358         *  .#.
359         *  x#x
360         *
361         *  where x=don't care
362         *  .=floor, #=wall
363         */
364
365         if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
366                 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
367         {
368                 /* secret door */
369                 place_secret_door(y, x, DOOR_DEFAULT);
370
371                 /* set boundarys so don't get wide doors */
372                 place_solid_bold(y, x - 1);
373                 place_solid_bold(y, x + 1);
374         }
375
376
377         /* look at:
378         *  x#x
379         *  .#.
380         *  x#x
381         *
382         *  where x = don't care
383         *  .=floor, #=wall
384         */
385         if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
386                 is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
387         {
388                 /* secret door */
389                 place_secret_door(y, x, DOOR_DEFAULT);
390
391                 /* set boundarys so don't get wide doors */
392                 place_solid_bold(y - 1, x);
393                 place_solid_bold(y + 1, x);
394         }
395 }
396
397 /*!
398 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
399 * @param y1 基準となるマスのY座標
400 * @param x1 基準となるマスのX座標
401 * @return 通路の数
402 * @note Assumes "in_bounds(y1, x1)"
403 * @details
404 * XXX XXX This routine currently only counts actual "empty floor"\n
405 * grids which are not in rooms.  We might want to also count stairs,\n
406 * open doors, closed doors, etc.
407 */
408 static int next_to_corr(POSITION y1, POSITION x1)
409 {
410         int i, k = 0;
411         POSITION y, x;
412
413         grid_type *g_ptr;
414
415         /* Scan adjacent grids */
416         for (i = 0; i < 4; i++)
417         {
418                 /* Extract the location */
419                 y = y1 + ddy_ddd[i];
420                 x = x1 + ddx_ddd[i];
421                 g_ptr = &current_floor_ptr->grid_array[y][x];
422
423                 /* Skip non floors */
424                 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
425
426                 /* Skip non "empty floor" grids */
427                 if (!is_floor_grid(g_ptr))
428                         continue;
429
430                 /* Skip grids inside rooms */
431                 if (g_ptr->info & (CAVE_ROOM)) continue;
432
433                 /* Count these grids */
434                 k++;
435         }
436
437         /* Return the number of corridors */
438         return (k);
439 }
440
441 /*!
442 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
443 * @param y 判定を行いたいマスのY座標
444 * @param x 判定を行いたいマスのX座標
445 * @return ドアを設置可能ならばTRUEを返す
446 * @note Assumes "in_bounds(y1, x1)"
447 * @details
448 * \n
449 * Assumes "in_bounds(y, x)"\n
450 */
451 static bool possible_doorway(POSITION y, POSITION x)
452 {
453         /* Count the adjacent corridors */
454         if (next_to_corr(y, x) >= 2)
455         {
456                 /* Check Vertical */
457                 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
458                         cave_have_flag_bold(y + 1, x, FF_WALL))
459                 {
460                         return (TRUE);
461                 }
462
463                 /* Check Horizontal */
464                 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
465                         cave_have_flag_bold(y, x + 1, FF_WALL))
466                 {
467                         return (TRUE);
468                 }
469         }
470
471         /* No doorway */
472         return (FALSE);
473 }
474
475 /*!
476 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
477 * @param y 設置を行いたいマスのY座標
478 * @param x 設置を行いたいマスのX座標
479 * @return なし
480 */
481 void try_door(POSITION y, POSITION x)
482 {       if (!in_bounds(y, x)) return;
483
484         /* Ignore walls */
485         if (cave_have_flag_bold(y, x, FF_WALL)) return;
486
487         /* Ignore room grids */
488         if (current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
489
490         /* Occasional door (if allowed) */
491         if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
492         {
493                 /* Place a door */
494                 place_random_door(y, x, FALSE);
495         }
496 }
497
498
499 /*!
500  * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
501  * @param x1 長方形の左端X座標(-1)
502  * @param x2 長方形の右端X座標(+1)
503  * @param y1 長方形の上端Y座標(-1)
504  * @param y2 長方形の下端Y座標(+1)
505  * @param light 照明の有無
506  * @return なし
507  */
508 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
509 {
510         POSITION x, y;
511
512         /* Place a full floor under the room */
513         for (y = y1 - 1; y <= y2 + 1; y++)
514         {
515                 for (x = x1 - 1; x <= x2 + 1; x++)
516                 {
517                         place_floor_bold(y, x);
518                         add_cave_info(y, x, CAVE_ROOM);
519                         if (light) add_cave_info(y, x, CAVE_GLOW);
520                 }
521         }
522 }
523
524
525 /*!
526  * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
527  * @param x1 長方形の左端X座標(-1)
528  * @param x2 長方形の右端X座標(+1)
529  * @param y1 長方形の上端Y座標(-1)
530  * @param y2 長方形の下端Y座標(+1)
531  * @param light 照明の有無
532  * @return なし
533  */
534 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
535 {
536         POSITION y, x;
537
538         place_floor(x1, x2, y1, y2, light);
539
540         /* Walls around the room */
541         for (y = y1 - 1; y <= y2 + 1; y++)
542         {
543                 place_outer_bold(y, x1 - 1);
544                 place_outer_bold(y, x2 + 1);
545         }
546         for (x = x1 - 1; x <= x2 + 1; x++)
547         {
548                 place_outer_bold(y1 - 1, x);
549                 place_outer_bold(y2 + 1, x);
550         }
551 }
552
553
554 /*!
555  * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
556  * @param y 配置したい中心マスのY座標
557  * @param x 配置したい中心マスのX座標
558  * @param num 配置したい数
559  * @return なし
560  * @details
561  * Only really called by some of the "vault" routines.
562  */
563 void vault_objects(POSITION y, POSITION x, int num)
564 {
565         int dummy = 0;
566         int i = 0, j = y, k = x;
567
568         grid_type *g_ptr;
569
570
571         /* Attempt to place 'num' objects */
572         for (; num > 0; --num)
573         {
574                 /* Try up to 11 spots looking for empty space */
575                 for (i = 0; i < 11; ++i)
576                 {
577                         /* Pick a random location */
578                         while (dummy < SAFE_MAX_ATTEMPTS)
579                         {
580                                 j = rand_spread(y, 2);
581                                 k = rand_spread(x, 3);
582                                 dummy++;
583                                 if (!in_bounds(j, k)) continue;
584                                 break;
585                         }
586
587                         if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
588                         {
589                                 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
590                         }
591
592                         /* Require "clean" floor space */
593                         g_ptr = &current_floor_ptr->grid_array[j][k];
594                         if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
595
596                         if (randint0(100) < 75)
597                         {
598                                 place_object(j, k, 0L);
599                         }
600                         else
601                         {
602                                 place_gold(j, k);
603                         }
604
605                         /* Placement accomplished */
606                         break;
607                 }
608         }
609 }
610
611 /*!
612  * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
613  * @param y トラップを配置したいマスの中心Y座標
614  * @param x トラップを配置したいマスの中心X座標
615  * @param yd Y方向の配置分散マス数
616  * @param xd X方向の配置分散マス数
617  * @return なし
618  * @details
619  * Only really called by some of the "vault" routines.
620  */
621 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
622 {
623         int count = 0, y1 = y, x1 = x;
624         int dummy = 0;
625
626         grid_type *g_ptr;
627
628         /* Place traps */
629         for (count = 0; count <= 5; count++)
630         {
631                 /* Get a location */
632                 while (dummy < SAFE_MAX_ATTEMPTS)
633                 {
634                         y1 = rand_spread(y, yd);
635                         x1 = rand_spread(x, xd);
636                         dummy++;
637                         if (!in_bounds(y1, x1)) continue;
638                         break;
639                 }
640
641                 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
642                 {
643                         msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
644                 }
645
646                 /* Require "naked" floor grids */
647                 g_ptr = &current_floor_ptr->grid_array[y1][x1];
648                 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
649
650                 /* Place the trap */
651                 place_trap(y1, x1);
652
653                 break;
654         }
655 }
656
657 /*!
658  * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
659  * @param y トラップを配置したいマスの中心Y座標
660  * @param x トラップを配置したいマスの中心X座標
661  * @param yd Y方向の配置分散マス数
662  * @param xd X方向の配置分散マス数
663  * @param num 配置したいトラップの数
664  * @return なし
665  * @details
666  * Only really called by some of the "vault" routines.
667  */
668 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
669 {
670         int i;
671
672         for (i = 0; i < num; i++)
673         {
674                 vault_trap_aux(y, x, yd, xd);
675         }
676 }
677
678 /*!
679  * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
680  * @param y1 モンスターを配置したいマスの中心Y座標
681  * @param x1 モンスターを配置したいマスの中心X座標
682  * @param num 配置したいモンスターの数
683  * @return なし
684  * @details
685  * Only really called by some of the "vault" routines.
686  */
687 void vault_monsters(POSITION y1, POSITION x1, int num)
688 {
689         int k, i;
690         POSITION y, x;
691         grid_type *g_ptr;
692
693         /* Try to summon "num" monsters "near" the given location */
694         for (k = 0; k < num; k++)
695         {
696                 /* Try nine locations */
697                 for (i = 0; i < 9; i++)
698                 {
699                         int d = 1;
700
701                         /* Pick a nearby location */
702                         scatter(&y, &x, y1, x1, d, 0);
703
704                         /* Require "empty" floor grids */
705                         g_ptr = &current_floor_ptr->grid_array[y][x];
706                         if (!cave_empty_grid(g_ptr)) continue;
707
708                         /* Place the monster (allow groups) */
709                         current_floor_ptr->monster_level = current_floor_ptr->base_level + 2;
710                         (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
711                         current_floor_ptr->monster_level = current_floor_ptr->base_level;
712                 }
713         }
714 }
715
716 /*!
717  * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor.  (Includes range checking.)
718  * @param x チェックするマスのX座標
719  * @param y チェックするマスのY座標
720  * @return 床系地形ならばTRUE
721  */
722 bool get_is_floor(POSITION x, POSITION y)
723 {
724         if (!in_bounds(y, x))
725         {
726                 /* Out of bounds */
727                 return (FALSE);
728         }
729
730         /* Do the real check */
731         if (is_floor_bold(y, x)) return (TRUE);
732
733         return (FALSE);
734 }
735
736 /*!
737  * @brief 指定のマスを床地形に変える / Set a square to be floor.  (Includes range checking.)
738  * @param x 地形を変えたいマスのX座標
739  * @param y 地形を変えたいマスのY座標
740  * @return なし
741  */
742 void set_floor(POSITION x, POSITION y)
743 {
744         if (!in_bounds(y, x))
745         {
746                 /* Out of bounds */
747                 return;
748         }
749
750         if (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
751         {
752                 /* A room border don't touch. */
753                 return;
754         }
755
756         /* Set to be floor if is a wall (don't touch lakes). */
757         if (is_extra_bold(y, x))
758                 place_floor_bold(y, x);
759 }
760
761 /*!
762  * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
763  * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
764  * @return なし
765  */
766 void place_bound_perm_wall(grid_type *g_ptr)
767 {
768         if (bound_walls_perm)
769         {
770                 /* Clear boundary mimic */
771                 g_ptr->mimic = 0;
772         }
773         else
774         {
775                 feature_type *f_ptr = &f_info[g_ptr->feat];
776
777                 /* Hack -- Decline boundary walls with known treasure  */
778                 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
779                         !have_flag(f_ptr->flags, FF_SECRET))
780                         g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
781
782                 /* Set boundary mimic */
783                 g_ptr->mimic = g_ptr->feat;
784         }
785
786         /* Add "solid" perma-wall */
787         place_solid_perm_grid(g_ptr);
788 }
789
790 /*!
791  * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
792  * @param g_ptr マス構造体の参照ポインタ
793  * @return 看破済みの罠があるならTRUEを返す。
794  */
795 bool is_known_trap(grid_type *g_ptr)
796 {
797         if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
798                 is_trap(g_ptr->feat)) return TRUE;
799         else
800                 return FALSE;
801 }
802
803
804
805 /*!
806  * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
807  * @param g_ptr マス構造体の参照ポインタ
808  * @return 隠されたドアがあるならTRUEを返す。
809  */
810 bool is_hidden_door(grid_type *g_ptr)
811 {
812         if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
813                 is_closed_door(g_ptr->feat))
814                 return TRUE;
815         else
816                 return FALSE;
817 }
818
819 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
820
821
822 /*!
823  * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
824  * @param y y座標
825  * @param x x座標
826  * @return 指定された座標に照明がかかっているならTRUEを返す。。
827  */
828 bool check_local_illumination(POSITION y, POSITION x)
829 {
830         /* Hack -- move towards player */
831         POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
832         POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
833
834         /* Check for "local" illumination */
835
836 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
837
838         /* Check for "complex" illumination */
839         if ((feat_supports_los(get_feat_mimic(&current_floor_ptr->grid_array[yy][xx])) &&
840                 (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
841                 (feat_supports_los(get_feat_mimic(&current_floor_ptr->grid_array[y][xx])) &&
842                 (current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
843                         (feat_supports_los(get_feat_mimic(&current_floor_ptr->grid_array[yy][x])) &&
844                 (current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
845         {
846                 return TRUE;
847         }
848         else return FALSE;
849
850 #else /* COMPLEX_WALL_ILLUMINATION */
851
852         /* Check for "simple" illumination */
853         return (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
854
855 #endif /* COMPLEX_WALL_ILLUMINATION */
856 }
857
858
859 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
860 #define update_local_illumination_aux(Y, X) \
861 { \
862         if (player_has_los_bold((Y), (X))) \
863         { \
864                 /* Update the monster */ \
865                 if (current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster(current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
866 \
867                 /* Notice and redraw */ \
868                 note_spot((Y), (X)); \
869                 lite_spot((Y), (X)); \
870         } \
871 }
872
873 /*!
874  * @brief 指定された座標の照明状態を更新する / Update "local" illumination
875  * @param y y座標
876  * @param x x座標
877  * @return なし
878  */
879 void update_local_illumination(POSITION y, POSITION x)
880 {
881         int i;
882         POSITION yy, xx;
883
884         if (!in_bounds(y, x)) return;
885
886 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
887
888         if ((y != p_ptr->y) && (x != p_ptr->x))
889         {
890                 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
891                 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
892                 update_local_illumination_aux(yy, xx);
893                 update_local_illumination_aux(y, xx);
894                 update_local_illumination_aux(yy, x);
895         }
896         else if (x != p_ptr->x) /* y == p_ptr->y */
897         {
898                 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
899                 for (i = -1; i <= 1; i++)
900                 {
901                         yy = y + i;
902                         update_local_illumination_aux(yy, xx);
903                 }
904                 yy = y - 1;
905                 update_local_illumination_aux(yy, x);
906                 yy = y + 1;
907                 update_local_illumination_aux(yy, x);
908         }
909         else if (y != p_ptr->y) /* x == p_ptr->x */
910         {
911                 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
912                 for (i = -1; i <= 1; i++)
913                 {
914                         xx = x + i;
915                         update_local_illumination_aux(yy, xx);
916                 }
917                 xx = x - 1;
918                 update_local_illumination_aux(y, xx);
919                 xx = x + 1;
920                 update_local_illumination_aux(y, xx);
921         }
922         else /* Player's grid */
923         {
924                 for (i = 0; i < 8; i++)
925                 {
926                         yy = y + ddy_cdd[i];
927                         xx = x + ddx_cdd[i];
928                         update_local_illumination_aux(yy, xx);
929                 }
930         }
931
932 #else /* COMPLEX_WALL_ILLUMINATION */
933
934         if ((y != p_ptr->y) && (x != p_ptr->x))
935         {
936                 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
937                 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
938                 update_local_illumination_aux(yy, xx);
939         }
940         else if (x != p_ptr->x) /* y == p_ptr->y */
941         {
942                 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
943                 for (i = -1; i <= 1; i++)
944                 {
945                         yy = y + i;
946                         update_local_illumination_aux(yy, xx);
947                 }
948         }
949         else if (y != p_ptr->y) /* x == p_ptr->x */
950         {
951                 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
952                 for (i = -1; i <= 1; i++)
953                 {
954                         xx = x + i;
955                         update_local_illumination_aux(yy, xx);
956                 }
957         }
958         else /* Player's grid */
959         {
960                 for (i = 0; i < 8; i++)
961                 {
962                         yy = y + ddy_cdd[i];
963                         xx = x + ddx_cdd[i];
964                         update_local_illumination_aux(yy, xx);
965                 }
966         }
967
968 #endif /* COMPLEX_WALL_ILLUMINATION */
969 }
970
971
972 /*!
973  * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
974  * @param y y座標
975  * @param x x座標
976  * @return 視覚に収められる状態ならTRUEを返す
977  * @details
978  * He must have vision, illumination, and line of sight.\n
979  * \n
980  * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
981  * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
982  *\n
983  * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
984  * that a wall is visible from any direction.  That would be odd.  Except\n
985  * under wizard light, which might make sense.  Thus, for walls, we require\n
986  * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
987  * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
988  * in line of sight of the player.\n
989  *\n
990  * This extra check is expensive, but it provides a more "correct" semantics.\n
991  *\n
992  * Note that we should not run this check on walls which are "outer walls" of\n
993  * the dungeon, or we will induce a memory fault, but actually verifying all\n
994  * of the locations would be extremely expensive.\n
995  *\n
996  * Thus, to speed up the function, we assume that all "perma-walls" which are\n
997  * "CAVE_GLOW" are "illuminated" from all sides.  This is correct for all cases\n
998  * except "vaults" and the "buildings" in town.  But the town is a hack anyway,\n
999  * and the player has more important things on his mind when he is attacking a\n
1000  * monster vault.  It is annoying, but an extremely important optimization.\n
1001  *\n
1002  * Note that "glowing walls" are only considered to be "illuminated" if the\n
1003  * grid which is next to the wall in the direction of the player is also a\n
1004  * "glowing" grid.  This prevents the player from being able to "see" the\n
1005  * walls of illuminated rooms from a corridor outside the room.\n
1006  */
1007 bool player_can_see_bold(POSITION y, POSITION x)
1008 {
1009         grid_type *g_ptr;
1010
1011         /* Blind players see nothing */
1012         if (p_ptr->blind) return FALSE;
1013
1014         g_ptr = &current_floor_ptr->grid_array[y][x];
1015
1016         /* Note that "torch-lite" yields "illumination" */
1017         if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
1018
1019         /* Require line of sight to the grid */
1020         if (!player_has_los_bold(y, x)) return FALSE;
1021
1022         /* Noctovision of Ninja */
1023         if (p_ptr->see_nocto) return TRUE;
1024
1025         /* Require "perma-lite" of the grid */
1026         if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
1027
1028         /* Feature code (applying "mimic" field) */
1029         /* Floors are simple */
1030         if (feat_supports_los(get_feat_mimic(g_ptr))) return TRUE;
1031
1032         /* Check for "local" illumination */
1033         return check_local_illumination(y, x);
1034 }
1035
1036 /*!
1037  * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
1038  * @return 視覚に収められていないならTRUEを返す
1039  * @details player_can_see_bold()関数の返り値の否定を返している。
1040  */
1041 bool no_lite(void)
1042 {
1043         return (!player_can_see_bold(p_ptr->y, p_ptr->x));
1044 }
1045
1046
1047 /*!
1048  * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
1049  * @param y y座標
1050  * @param x x座標
1051  * @return 各種の変更が可能ならTRUEを返す。
1052  * @details
1053  * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
1054  */
1055 bool cave_valid_bold(POSITION y, POSITION x)
1056 {
1057         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
1058         OBJECT_IDX this_o_idx, next_o_idx = 0;
1059
1060         /* Forbid perma-grids */
1061         if (cave_perma_grid(g_ptr)) return (FALSE);
1062
1063         /* Check objects */
1064         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1065         {
1066                 object_type *o_ptr;
1067                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
1068                 next_o_idx = o_ptr->next_o_idx;
1069
1070                 /* Forbid artifact grids */
1071                 if (object_is_artifact(o_ptr)) return (FALSE);
1072         }
1073
1074         /* Accept */
1075         return (TRUE);
1076 }
1077
1078 /*
1079  * Moves the cursor to a given MAP (y,x) location
1080  */
1081 void move_cursor_relative(int row, int col)
1082 {
1083         /* Real co-ords convert to screen positions */
1084         row -= panel_row_prt;
1085
1086         /* Go there */
1087         Term_gotoxy(panel_col_of(col), row);
1088 }
1089
1090
1091
1092 /*
1093  * Place an attr/char pair at the given map coordinate, if legal.
1094  */
1095 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
1096 {
1097         /* Only do "legal" locations */
1098         if (panel_contains(y, x))
1099         {
1100                 /* Hack -- fake monochrome */
1101                 if (!use_graphics)
1102                 {
1103                         if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1104                         else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1105                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
1106                 }
1107
1108                 /* Draw the char using the attr */
1109                 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
1110         }
1111 }
1112
1113
1114
1115
1116
1117 /*
1118  * Memorize interesting viewable object/features in the given grid
1119  *
1120  * This function should only be called on "legal" grids.
1121  *
1122  * This function will memorize the object and/or feature in the given
1123  * grid, if they are (1) viewable and (2) interesting.  Note that all
1124  * objects are interesting, all terrain features except floors (and
1125  * invisible traps) are interesting, and floors (and invisible traps)
1126  * are interesting sometimes (depending on various options involving
1127  * the illumination of floor grids).
1128  *
1129  * The automatic memorization of all objects and non-floor terrain
1130  * features as soon as they are displayed allows incredible amounts
1131  * of optimization in various places, especially "map_info()".
1132  *
1133  * Note that the memorization of objects is completely separate from
1134  * the memorization of terrain features, preventing annoying floor
1135  * memorization when a detected object is picked up from a dark floor,
1136  * and object memorization when an object is dropped into a floor grid
1137  * which is memorized but out-of-sight.
1138  *
1139  * This function should be called every time the "memorization" of
1140  * a grid (or the object in a grid) is called into question, such
1141  * as when an object is created in a grid, when a terrain feature
1142  * "changes" from "floor" to "non-floor", when any grid becomes
1143  * "illuminated" or "viewable", and when a "floor" grid becomes
1144  * "torch-lit".
1145  *
1146  * Note the relatively efficient use of this function by the various
1147  * "update_view()" and "update_lite()" calls, to allow objects and
1148  * terrain features to be memorized (and drawn) whenever they become
1149  * viewable or illuminated in any way, but not when they "maintain"
1150  * or "lose" their previous viewability or illumination.
1151  *
1152  * Note the butchered "internal" version of "player_can_see_bold()",
1153  * optimized primarily for the most common cases, that is, for the
1154  * non-marked floor grids.
1155  */
1156 void note_spot(POSITION y, POSITION x)
1157 {
1158         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
1159         OBJECT_IDX this_o_idx, next_o_idx = 0;
1160
1161         /* Blind players see nothing */
1162         if (p_ptr->blind) return;
1163
1164         /* Analyze non-torch-lit grids */
1165         if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1166         {
1167                 /* Require line of sight to the grid */
1168                 if (!(g_ptr->info & (CAVE_VIEW))) return;
1169
1170                 /* Require "perma-lite" of the grid */
1171                 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1172                 {
1173                         /* Not Ninja */
1174                         if (!p_ptr->see_nocto) return;
1175                 }
1176         }
1177
1178
1179         /* Hack -- memorize objects */
1180         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1181         {
1182                 object_type *o_ptr = &current_floor_ptr->o_list[this_o_idx];
1183                 next_o_idx = o_ptr->next_o_idx;
1184
1185                 /* Memorize objects */
1186                 o_ptr->marked |= OM_FOUND;
1187         }
1188
1189
1190         /* Hack -- memorize grids */
1191         if (!(g_ptr->info & (CAVE_MARK)))
1192         {
1193                 /* Feature code (applying "mimic" field) */
1194                 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
1195
1196                 /* Memorize some "boring" grids */
1197                 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1198                 {
1199                         /* Option -- memorize all torch-lit floors */
1200                         if (view_torch_grids &&
1201                                 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1202                         {
1203                                 g_ptr->info |= (CAVE_MARK);
1204                         }
1205
1206                         /* Option -- memorize all perma-lit floors */
1207                         else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1208                         {
1209                                 g_ptr->info |= (CAVE_MARK);
1210                         }
1211                 }
1212
1213                 /* Memorize normal grids */
1214                 else if (have_flag(f_ptr->flags, FF_LOS))
1215                 {
1216                         g_ptr->info |= (CAVE_MARK);
1217                 }
1218
1219                 /* Memorize torch-lit walls */
1220                 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1221                 {
1222                         g_ptr->info |= (CAVE_MARK);
1223                 }
1224
1225                 /* Memorize walls seen by noctovision of Ninja */
1226                 else if (p_ptr->see_nocto)
1227                 {
1228                         g_ptr->info |= (CAVE_MARK);
1229                 }
1230
1231                 /* Memorize certain non-torch-lit wall grids */
1232                 else if (check_local_illumination(y, x))
1233                 {
1234                         g_ptr->info |= (CAVE_MARK);
1235                 }
1236         }
1237
1238         /* Memorize terrain of the grid */
1239         g_ptr->info |= (CAVE_KNOWN);
1240 }
1241
1242
1243 void display_dungeon(void)
1244 {
1245         TERM_LEN x, y;
1246         TERM_COLOR a;
1247         SYMBOL_CODE c;
1248
1249         TERM_COLOR ta = 0;
1250         SYMBOL_CODE tc = '\0';
1251
1252         for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
1253         {
1254                 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
1255                 {
1256                         if (in_bounds2(y, x))
1257                         {
1258                                 map_info(y, x, &a, &c, &ta, &tc);
1259
1260                                 /* Hack -- fake monochrome */
1261                                 if (!use_graphics)
1262                                 {
1263                                         if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1264                                         else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1265                                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
1266                                 }
1267
1268                                 /* Hack -- Queue it */
1269                                 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1270                         }
1271                         else
1272                         {
1273                                 /* Clear out-of-bound tiles */
1274
1275                                 /* Access darkness */
1276                                 feature_type *f_ptr = &f_info[feat_none];
1277
1278                                 /* Normal attr */
1279                                 a = f_ptr->x_attr[F_LIT_STANDARD];
1280
1281                                 /* Normal char */
1282                                 c = f_ptr->x_char[F_LIT_STANDARD];
1283
1284                                 /* Hack -- Queue it */
1285                                 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
1286                         }
1287                 }
1288         }
1289 }
1290
1291
1292 /*
1293  * Redraw (on the screen) a given MAP location
1294  *
1295  * This function should only be called on "legal" grids
1296  */
1297 void lite_spot(POSITION y, POSITION x)
1298 {
1299         /* Redraw if on screen */
1300         if (panel_contains(y, x) && in_bounds2(y, x))
1301         {
1302                 TERM_COLOR a;
1303                 SYMBOL_CODE c;
1304                 TERM_COLOR ta;
1305                 SYMBOL_CODE tc;
1306
1307                 map_info(y, x, &a, &c, &ta, &tc);
1308
1309                 /* Hack -- fake monochrome */
1310                 if (!use_graphics)
1311                 {
1312                         if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1313                         else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1314                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
1315                 }
1316
1317                 /* Hack -- Queue it */
1318                 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
1319
1320                 /* Update sub-windows */
1321                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1322         }
1323 }
1324
1325
1326 /*
1327  * print project path
1328  */
1329 void prt_path(POSITION y, POSITION x)
1330 {
1331         int i;
1332         int path_n;
1333         u16b path_g[512];
1334         byte_hack default_color = TERM_SLATE;
1335
1336         if (!display_path) return;
1337         if (-1 == project_length)
1338                 return;
1339
1340         /* Get projection path */
1341         path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
1342
1343         p_ptr->redraw |= (PR_MAP);
1344         handle_stuff();
1345
1346         /* Draw path */
1347         for (i = 0; i < path_n; i++)
1348         {
1349                 POSITION ny = GRID_Y(path_g[i]);
1350                 POSITION nx = GRID_X(path_g[i]);
1351                 grid_type *g_ptr = &current_floor_ptr->grid_array[ny][nx];
1352
1353                 if (panel_contains(ny, nx))
1354                 {
1355                         TERM_COLOR a = default_color;
1356                         char c;
1357
1358                         TERM_COLOR ta = default_color;
1359                         char tc = '*';
1360
1361                         if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
1362                         {
1363                                 /* Determine what is there */
1364                                 map_info(ny, nx, &a, &c, &ta, &tc);
1365
1366                                 if (!is_ascii_graphics(a))
1367                                         a = default_color;
1368                                 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
1369                                         a = default_color;
1370                                 else if (a == default_color)
1371                                         a = TERM_WHITE;
1372                         }
1373
1374                         if (!use_graphics)
1375                         {
1376                                 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1377                                 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1378                                 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1379                         }
1380
1381                         c = '*';
1382
1383                         /* Hack -- Queue it */
1384                         Term_queue_bigchar(panel_col_of(nx), ny - panel_row_prt, a, c, ta, tc);
1385                 }
1386
1387                 /* Known Wall */
1388                 if ((g_ptr->info & CAVE_MARK) && !cave_have_flag_grid(g_ptr, FF_PROJECT)) break;
1389
1390                 /* Change color */
1391                 if (nx == x && ny == y) default_color = TERM_L_DARK;
1392         }
1393 }
1394
1395 /*
1396  * Some comments on the grid flags.  -BEN-
1397  *
1398  *
1399  * One of the major bottlenecks in previous versions of Angband was in
1400  * the calculation of "line of sight" from the player to various grids,
1401  * such as monsters.  This was such a nasty bottleneck that a lot of
1402  * silly things were done to reduce the dependancy on "line of sight",
1403  * for example, you could not "see" any grids in a lit room until you
1404  * actually entered the room, and there were all kinds of bizarre grid
1405  * flags to enable this behavior.  This is also why the "call light"
1406  * spells always lit an entire room.
1407  *
1408  * The code below provides functions to calculate the "field of view"
1409  * for the player, which, once calculated, provides extremely fast
1410  * calculation of "line of sight from the player", and to calculate
1411  * the "field of torch lite", which, again, once calculated, provides
1412  * extremely fast calculation of "which grids are lit by the player's
1413  * lite source".  In addition to marking grids as "GRID_VIEW" and/or
1414  * "GRID_LITE", as appropriate, these functions maintain an array for
1415  * each of these two flags, each array containing the locations of all
1416  * of the grids marked with the appropriate flag, which can be used to
1417  * very quickly scan through all of the grids in a given set.
1418  *
1419  * To allow more "semantically valid" field of view semantics, whenever
1420  * the field of view (or the set of torch lit grids) changes, all of the
1421  * grids in the field of view (or the set of torch lit grids) are "drawn"
1422  * so that changes in the world will become apparent as soon as possible.
1423  * This has been optimized so that only grids which actually "change" are
1424  * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
1425  * of the grids which are entering or leaving the relevent set of grids.
1426  *
1427  * These new methods are so efficient that the old nasty code was removed.
1428  *
1429  * Note that there is no reason to "update" the "viewable space" unless
1430  * the player "moves", or walls/doors are created/destroyed, and there
1431  * is no reason to "update" the "torch lit grids" unless the field of
1432  * view changes, or the "light radius" changes.  This means that when
1433  * the player is resting, or digging, or doing anything that does not
1434  * involve movement or changing the state of the dungeon, there is no
1435  * need to update the "view" or the "lite" regions, which is nice.
1436  *
1437  * Note that the calls to the nasty "los()" function have been reduced
1438  * to a bare minimum by the use of the new "field of view" calculations.
1439  *
1440  * I wouldn't be surprised if slight modifications to the "update_view()"
1441  * function would allow us to determine "reverse line-of-sight" as well
1442  * as "normal line-of-sight", which would allow monsters to use a more
1443  * "correct" calculation to determine if they can "see" the player.  For
1444  * now, monsters simply "cheat" somewhat and assume that if the player
1445  * has "line of sight" to the monster, then the monster can "pretend"
1446  * that it has "line of sight" to the player.
1447  *
1448  *
1449  * The "update_lite()" function maintains the "CAVE_LITE" flag for each
1450  * grid and maintains an array of all "CAVE_LITE" grids.
1451  *
1452  * This set of grids is the complete set of all grids which are lit by
1453  * the players light source, which allows the "player_can_see_bold()"
1454  * function to work very quickly.
1455  *
1456  * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
1457  * fact, the player (unless blind) can always "see" all grids which are
1458  * marked as "CAVE_LITE", unless they are "off screen".
1459  *
1460  *
1461  * The "update_view()" function maintains the "CAVE_VIEW" flag for each
1462  * grid and maintains an array of all "CAVE_VIEW" grids.
1463  *
1464  * This set of grids is the complete set of all grids within line of sight
1465  * of the player, allowing the "player_has_los_bold()" macro to work very
1466  * quickly.
1467  *
1468  *
1469  * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
1470  * temporary internal flag to mark those grids which are not only in view,
1471  * but which are also "easily" in line of sight of the player.  This flag
1472  * is always cleared when we are done.
1473  *
1474  *
1475  * The current "update_lite()" and "update_view()" algorithms use the
1476  * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
1477  * to keep track of which grids were previously marked as "CAVE_LITE" or
1478  * "CAVE_VIEW", which allows us to optimize the "screen updates".
1479  *
1480  * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
1481  * for various other purposes, such as spreading lite or darkness during
1482  * "lite_room()" / "unlite_room()", and for calculating monster flow.
1483  *
1484  *
1485  * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
1486  * in some way permanently lit.  However, for the player to "see" anything
1487  * in the grid, as determined by "player_can_see()", the player must not be
1488  * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
1489  * grids, even if marked as "perma lit", are only illuminated if they touch
1490  * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
1491  *
1492  *
1493  * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
1494  * that even if the player cannot "see" the grid, he "knows" the terrain in
1495  * that grid.  This is used to "remember" walls/doors/stairs/floors when they
1496  * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
1497  * or when one of the "memorize floor grids" options induces memorization.
1498  *
1499  * Objects are "memorized" in a different way, using a special "marked" flag
1500  * on the object itself, which is set when an object is observed or detected.
1501  *
1502  *
1503  * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
1504  * and should be illuminated by "lite room" and "darkness" spells.
1505  *
1506  *
1507  * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
1508  * and should be unavailable for "teleportation" destinations.
1509  *
1510  *
1511  * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
1512  * which is observed, and the "view_torch_grids" allows the player to memorize
1513  * every torch-lit grid.  The player will always memorize important walls,
1514  * doors, stairs, and other terrain features, as well as any "detected" grids.
1515  *
1516  * Note that the new "update_view()" method allows, among other things, a room
1517  * to be "partially" seen as the player approaches it, with a growing cone of
1518  * floor appearing as the player gets closer to the door.  Also, by not turning
1519  * on the "memorize perma-lit grids" option, the player will only "see" those
1520  * floor grids which are actually in line of sight.
1521  *
1522  * And my favorite "plus" is that you can now use a special option to draw the
1523  * "floors" in the "viewable region" brightly (actually, to draw the *other*
1524  * grids dimly), providing a "pretty" effect as the player runs around, and
1525  * to efficiently display the "torch lite" in a special color.
1526  *
1527  *
1528  * Some comments on the "update_view()" algorithm...
1529  *
1530  * The algorithm is very fast, since it spreads "obvious" grids very quickly,
1531  * and only has to call "los()" on the borderline cases.  The major axes/diags
1532  * even terminate early when they hit walls.  I need to find a quick way
1533  * to "terminate" the other scans.
1534  *
1535  * Note that in the worst case (a big empty area with say 5% scattered walls),
1536  * each of the 1500 or so nearby grids is checked once, most of them getting
1537  * an "instant" rating, and only a small portion requiring a call to "los()".
1538  *
1539  * The only time that the algorithm appears to be "noticeably" too slow is
1540  * when running, and this is usually only important in town, since the town
1541  * provides about the worst scenario possible, with large open regions and
1542  * a few scattered obstructions.  There is a special "efficiency" option to
1543  * allow the player to reduce his field of view in town, if needed.
1544  *
1545  * In the "best" case (say, a normal stretch of corridor), the algorithm
1546  * makes one check for each viewable grid, and makes no calls to "los()".
1547  * So running in corridors is very fast, and if a lot of monsters are
1548  * nearby, it is much faster than the old methods.
1549  *
1550  * Note that resting, most normal commands, and several forms of running,
1551  * plus all commands executed near large groups of monsters, are strictly
1552  * more efficient with "update_view()" that with the old "compute los() on
1553  * demand" method, primarily because once the "field of view" has been
1554  * calculated, it does not have to be recalculated until the player moves
1555  * (or a wall or door is created or destroyed).
1556  *
1557  * Note that we no longer have to do as many "los()" checks, since once the
1558  * "view" region has been built, very few things cause it to be "changed"
1559  * (player movement, and the opening/closing of doors, changes in wall status).
1560  * Note that door/wall changes are only relevant when the door/wall itself is
1561  * in the "view" region.
1562  *
1563  * The algorithm seems to only call "los()" from zero to ten times, usually
1564  * only when coming down a corridor into a room, or standing in a room, just
1565  * misaligned with a corridor.  So if, say, there are five "nearby" monsters,
1566  * we will be reducing the calls to "los()".
1567  *
1568  * I am thinking in terms of an algorithm that "walks" from the central point
1569  * out to the maximal "distance", at each point, determining the "view" code
1570  * (above).  For each grid not on a major axis or diagonal, the "view" code
1571  * depends on the "cave_los_bold()" and "view" of exactly two other grids
1572  * (the one along the nearest diagonal, and the one next to that one, see
1573  * "update_view_aux()"...).
1574  *
1575  * We "memorize" the viewable space array, so that at the cost of under 3000
1576  * bytes, we reduce the time taken by "forget_view()" to one assignment for
1577  * each grid actually in the "viewable space".  And for another 3000 bytes,
1578  * we prevent "erase + redraw" ineffiencies via the "seen" set.  These bytes
1579  * are also used by other routines, thus reducing the cost to almost nothing.
1580  *
1581  * A similar thing is done for "forget_lite()" in which case the savings are
1582  * much less, but save us from doing bizarre maintenance checking.
1583  *
1584  * In the worst "normal" case (in the middle of the town), the reachable space
1585  * actually reaches to more than half of the largest possible "circle" of view,
1586  * or about 800 grids, and in the worse case (in the middle of a dungeon level
1587  * where all the walls have been removed), the reachable space actually reaches
1588  * the theoretical maximum size of just under 1500 grids.
1589  *
1590  * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
1591  * If G1 is lite, G is lite.  Else if G2 is lite, G is half.  Else if G1 and G2
1592  * are both half, G is half.  Else G is dark.  It only takes 2 (or 4) bits to
1593  * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
1594  * entire possible space (including initialization) in one step per grid.  If
1595  * we do the "clearing" as a separate step (and use an array of "view" grids),
1596  * then the clearing will take as many steps as grids that were viewed, and the
1597  * algorithm will be able to "stop" scanning at various points.
1598  * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
1599  */
1600
1601
1602 /*
1603  * For delayed visual update
1604  */
1605 #define cave_note_and_redraw_later(C,Y,X) \
1606 {\
1607         (C)->info |= CAVE_NOTE; \
1608         cave_redraw_later((C), (Y), (X)); \
1609 }
1610
1611
1612  /*
1613   * For delayed visual update
1614   */
1615 #define cave_redraw_later(C,Y,X) \
1616 {\
1617         if (!((C)->info & CAVE_REDRAW)) \
1618         { \
1619                 (C)->info |= CAVE_REDRAW; \
1620                 current_floor_ptr->redraw_y[current_floor_ptr->redraw_n] = (Y); \
1621                 current_floor_ptr->redraw_x[current_floor_ptr->redraw_n++] = (X); \
1622         } \
1623 }
1624
1625
1626   /*
1627    * This macro allows us to efficiently add a grid to the "lite" array,
1628    * note that we are never called for illegal grids, or for grids which
1629    * have already been placed into the "lite" array, and we are never
1630    * called when the "lite" array is full.
1631    */
1632 #define cave_lite_hack(Y,X) \
1633 {\
1634         if (!(current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
1635         { \
1636                 current_floor_ptr->grid_array[Y][X].info |= (CAVE_LITE); \
1637                 current_floor_ptr->lite_y[current_floor_ptr->lite_n] = (Y); \
1638                 current_floor_ptr->lite_x[current_floor_ptr->lite_n++] = (X); \
1639         } \
1640 }
1641
1642
1643    /*
1644         * Update the set of grids "illuminated" by the player's lite.
1645         *
1646         * This routine needs to use the results of "update_view()"
1647         *
1648         * Note that "blindness" does NOT affect "torch lite".  Be careful!
1649         *
1650         * We optimize most lites (all non-artifact lites) by using "obvious"
1651         * facts about the results of "small" lite radius, and we attempt to
1652         * list the "nearby" grids before the more "distant" ones in the
1653         * array of torch-lit grids.
1654         *
1655         * We assume that "radius zero" lite is in fact no lite at all.
1656         *
1657         *     Torch     Lantern     Artifacts
1658         *     (etc)
1659         *                              ***
1660         *                 ***         *****
1661         *      ***       *****       *******
1662         *      *@*       **@**       ***@***
1663         *      ***       *****       *******
1664         *                 ***         *****
1665         *                              ***
1666         */
1667 void update_lite(void)
1668 {
1669         int i;
1670         POSITION x, y, min_x, max_x, min_y, max_y;
1671         POSITION p = p_ptr->cur_lite;
1672         grid_type *g_ptr;
1673
1674         /*** Special case ***/
1675
1676 #if 0
1677         /* Hack -- Player has no lite */
1678         if (p <= 0)
1679         {
1680                 /* Forget the old lite */
1681                 /* forget_lite(); Perhaps don't need? */
1682
1683                 /* Add it to later visual update */
1684                 cave_redraw_later(&current_floor_ptr->grid_array[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
1685         }
1686 #endif
1687
1688         /*** Save the old "lite" grids for later ***/
1689
1690         /* Clear them all */
1691         for (i = 0; i < current_floor_ptr->lite_n; i++)
1692         {
1693                 y = current_floor_ptr->lite_y[i];
1694                 x = current_floor_ptr->lite_x[i];
1695
1696                 /* Mark the grid as not "lite" */
1697                 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
1698
1699                 /* Mark the grid as "seen" */
1700                 current_floor_ptr->grid_array[y][x].info |= (CAVE_TEMP);
1701
1702                 /* Add it to the "seen" set */
1703                 tmp_pos.y[tmp_pos.n] = y;
1704                 tmp_pos.x[tmp_pos.n] = x;
1705                 tmp_pos.n++;
1706         }
1707
1708         /* None left */
1709         current_floor_ptr->lite_n = 0;
1710
1711
1712         /*** Collect the new "lite" grids ***/
1713
1714         /* Radius 1 -- torch radius */
1715         if (p >= 1)
1716         {
1717                 /* Player grid */
1718                 cave_lite_hack(p_ptr->y, p_ptr->x);
1719
1720                 /* Adjacent grid */
1721                 cave_lite_hack(p_ptr->y + 1, p_ptr->x);
1722                 cave_lite_hack(p_ptr->y - 1, p_ptr->x);
1723                 cave_lite_hack(p_ptr->y, p_ptr->x + 1);
1724                 cave_lite_hack(p_ptr->y, p_ptr->x - 1);
1725
1726                 /* Diagonal grids */
1727                 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 1);
1728                 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 1);
1729                 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 1);
1730                 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 1);
1731         }
1732
1733         /* Radius 2 -- lantern radius */
1734         if (p >= 2)
1735         {
1736                 /* South of the player */
1737                 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
1738                 {
1739                         cave_lite_hack(p_ptr->y + 2, p_ptr->x);
1740                         cave_lite_hack(p_ptr->y + 2, p_ptr->x + 1);
1741                         cave_lite_hack(p_ptr->y + 2, p_ptr->x - 1);
1742                 }
1743
1744                 /* North of the player */
1745                 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
1746                 {
1747                         cave_lite_hack(p_ptr->y - 2, p_ptr->x);
1748                         cave_lite_hack(p_ptr->y - 2, p_ptr->x + 1);
1749                         cave_lite_hack(p_ptr->y - 2, p_ptr->x - 1);
1750                 }
1751
1752                 /* East of the player */
1753                 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
1754                 {
1755                         cave_lite_hack(p_ptr->y, p_ptr->x + 2);
1756                         cave_lite_hack(p_ptr->y + 1, p_ptr->x + 2);
1757                         cave_lite_hack(p_ptr->y - 1, p_ptr->x + 2);
1758                 }
1759
1760                 /* West of the player */
1761                 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
1762                 {
1763                         cave_lite_hack(p_ptr->y, p_ptr->x - 2);
1764                         cave_lite_hack(p_ptr->y + 1, p_ptr->x - 2);
1765                         cave_lite_hack(p_ptr->y - 1, p_ptr->x - 2);
1766                 }
1767         }
1768
1769         /* Radius 3+ -- artifact radius */
1770         if (p >= 3)
1771         {
1772                 int d;
1773
1774                 /* Paranoia -- see "LITE_MAX" */
1775                 if (p > 14) p = 14;
1776
1777                 /* South-East of the player */
1778                 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
1779                 {
1780                         cave_lite_hack(p_ptr->y + 2, p_ptr->x + 2);
1781                 }
1782
1783                 /* South-West of the player */
1784                 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
1785                 {
1786                         cave_lite_hack(p_ptr->y + 2, p_ptr->x - 2);
1787                 }
1788
1789                 /* North-East of the player */
1790                 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
1791                 {
1792                         cave_lite_hack(p_ptr->y - 2, p_ptr->x + 2);
1793                 }
1794
1795                 /* North-West of the player */
1796                 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
1797                 {
1798                         cave_lite_hack(p_ptr->y - 2, p_ptr->x - 2);
1799                 }
1800
1801                 /* Maximal north */
1802                 min_y = p_ptr->y - p;
1803                 if (min_y < 0) min_y = 0;
1804
1805                 /* Maximal south */
1806                 max_y = p_ptr->y + p;
1807                 if (max_y > current_floor_ptr->height - 1) max_y = current_floor_ptr->height - 1;
1808
1809                 /* Maximal west */
1810                 min_x = p_ptr->x - p;
1811                 if (min_x < 0) min_x = 0;
1812
1813                 /* Maximal east */
1814                 max_x = p_ptr->x + p;
1815                 if (max_x > current_floor_ptr->width - 1) max_x = current_floor_ptr->width - 1;
1816
1817                 /* Scan the maximal box */
1818                 for (y = min_y; y <= max_y; y++)
1819                 {
1820                         for (x = min_x; x <= max_x; x++)
1821                         {
1822                                 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
1823                                 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
1824
1825                                 /* Skip the "central" grids (above) */
1826                                 if ((dy <= 2) && (dx <= 2)) continue;
1827
1828                                 /* Hack -- approximate the distance */
1829                                 d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
1830
1831                                 /* Skip distant grids */
1832                                 if (d > p) continue;
1833
1834                                 /* Viewable, nearby, grids get "torch lit" */
1835                                 if (current_floor_ptr->grid_array[y][x].info & CAVE_VIEW)
1836                                 {
1837                                         /* This grid is "torch lit" */
1838                                         cave_lite_hack(y, x);
1839                                 }
1840                         }
1841                 }
1842         }
1843
1844
1845         /*** Complete the algorithm ***/
1846
1847         /* Draw the new grids */
1848         for (i = 0; i < current_floor_ptr->lite_n; i++)
1849         {
1850                 y = current_floor_ptr->lite_y[i];
1851                 x = current_floor_ptr->lite_x[i];
1852
1853                 g_ptr = &current_floor_ptr->grid_array[y][x];
1854
1855                 /* Update fresh grids */
1856                 if (g_ptr->info & (CAVE_TEMP)) continue;
1857
1858                 /* Add it to later visual update */
1859                 cave_note_and_redraw_later(g_ptr, y, x);
1860         }
1861
1862         /* Clear them all */
1863         for (i = 0; i < tmp_pos.n; i++)
1864         {
1865                 y = tmp_pos.y[i];
1866                 x = tmp_pos.x[i];
1867
1868                 g_ptr = &current_floor_ptr->grid_array[y][x];
1869
1870                 /* No longer in the array */
1871                 g_ptr->info &= ~(CAVE_TEMP);
1872
1873                 /* Update stale grids */
1874                 if (g_ptr->info & (CAVE_LITE)) continue;
1875
1876                 /* Add it to later visual update */
1877                 cave_redraw_later(g_ptr, y, x);
1878         }
1879
1880         /* None left */
1881         tmp_pos.n = 0;
1882
1883         /* Mega-Hack -- Visual update later */
1884         p_ptr->update |= (PU_DELAY_VIS);
1885 }
1886
1887
1888 static bool mon_invis;
1889 static POSITION mon_fy, mon_fx;
1890
1891 /*
1892  * Add a square to the changes array
1893  */
1894 static void mon_lite_hack(POSITION y, POSITION x)
1895 {
1896         grid_type *g_ptr;
1897         int dpf, d;
1898         POSITION midpoint;
1899
1900         /* We trust this grid is in bounds */
1901         /* if (!in_bounds2(y, x)) return; */
1902
1903         g_ptr = &current_floor_ptr->grid_array[y][x];
1904
1905         /* Want a unlit square in view of the player */
1906         if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
1907
1908         if (!cave_los_grid(g_ptr))
1909         {
1910                 /* Hack -- Prevent monster lite leakage in walls */
1911
1912                 /* Horizontal walls between player and a monster */
1913                 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
1914                 {
1915                         dpf = p_ptr->y - mon_fy;
1916                         d = y - mon_fy;
1917                         midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
1918
1919                         /* Only first wall viewed from mid-x is lit */
1920                         if (x < midpoint)
1921                         {
1922                                 if (!cave_los_bold(y, x + 1)) return;
1923                         }
1924                         else if (x > midpoint)
1925                         {
1926                                 if (!cave_los_bold(y, x - 1)) return;
1927                         }
1928
1929                         /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1930                         else if (mon_invis) return;
1931                 }
1932
1933                 /* Vertical walls between player and a monster */
1934                 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
1935                 {
1936                         dpf = p_ptr->x - mon_fx;
1937                         d = x - mon_fx;
1938                         midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
1939
1940                         /* Only first wall viewed from mid-y is lit */
1941                         if (y < midpoint)
1942                         {
1943                                 if (!cave_los_bold(y + 1, x)) return;
1944                         }
1945                         else if (y > midpoint)
1946                         {
1947                                 if (!cave_los_bold(y - 1, x)) return;
1948                         }
1949
1950                         /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1951                         else if (mon_invis) return;
1952                 }
1953         }
1954
1955         /* We trust tmp_pos.n does not exceed TEMP_MAX */
1956
1957         /* New grid */
1958         if (!(g_ptr->info & CAVE_MNDK))
1959         {
1960                 /* Save this square */
1961                 tmp_pos.x[tmp_pos.n] = x;
1962                 tmp_pos.y[tmp_pos.n] = y;
1963                 tmp_pos.n++;
1964         }
1965
1966         /* Darkened grid */
1967         else
1968         {
1969                 /* No longer dark */
1970                 g_ptr->info &= ~(CAVE_MNDK);
1971         }
1972
1973         /* Light it */
1974         g_ptr->info |= CAVE_MNLT;
1975 }
1976
1977
1978 /*
1979  * Add a square to the changes array
1980  */
1981 static void mon_dark_hack(POSITION y, POSITION x)
1982 {
1983         grid_type *g_ptr;
1984         int       midpoint, dpf, d;
1985
1986         /* We trust this grid is in bounds */
1987         /* if (!in_bounds2(y, x)) return; */
1988
1989         g_ptr = &current_floor_ptr->grid_array[y][x];
1990
1991         /* Want a unlit and undarkened square in view of the player */
1992         if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
1993
1994         if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
1995         {
1996                 /* Hack -- Prevent monster dark lite leakage in walls */
1997
1998                 /* Horizontal walls between player and a monster */
1999                 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
2000                 {
2001                         dpf = p_ptr->y - mon_fy;
2002                         d = y - mon_fy;
2003                         midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
2004
2005                         /* Only first wall viewed from mid-x is lit */
2006                         if (x < midpoint)
2007                         {
2008                                 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
2009                         }
2010                         else if (x > midpoint)
2011                         {
2012                                 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
2013                         }
2014
2015                         /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2016                         else if (mon_invis) return;
2017                 }
2018
2019                 /* Vertical walls between player and a monster */
2020                 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
2021                 {
2022                         dpf = p_ptr->x - mon_fx;
2023                         d = x - mon_fx;
2024                         midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
2025
2026                         /* Only first wall viewed from mid-y is lit */
2027                         if (y < midpoint)
2028                         {
2029                                 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
2030                         }
2031                         else if (y > midpoint)
2032                         {
2033                                 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
2034                         }
2035
2036                         /* Hack XXX XXX - Is it a wall and monster not in LOS? */
2037                         else if (mon_invis) return;
2038                 }
2039         }
2040
2041         /* We trust tmp_pos.n does not exceed TEMP_MAX */
2042
2043         /* Save this square */
2044         tmp_pos.x[tmp_pos.n] = x;
2045         tmp_pos.y[tmp_pos.n] = y;
2046         tmp_pos.n++;
2047
2048         /* Darken it */
2049         g_ptr->info |= CAVE_MNDK;
2050 }
2051
2052
2053 /*
2054  * Update squares illuminated or darkened by monsters.
2055  *
2056  * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
2057  * denote squares illuminated by monsters.
2058  *
2059  * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
2060  * updating.  Only squares in view of the player, whos state
2061  * changes are drawn via lite_spot().
2062  */
2063 void update_mon_lite(void)
2064 {
2065         int i, rad;
2066         grid_type *g_ptr;
2067
2068         POSITION fx, fy;
2069         void(*add_mon_lite)(POSITION, POSITION);
2070         int f_flag;
2071
2072         s16b end_temp;
2073
2074         /* Non-Ninja player in the darkness */
2075         int dis_lim = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
2076                 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
2077
2078         /* Clear all monster lit squares */
2079         for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
2080         {
2081                 /* Point to grid */
2082                 g_ptr = &current_floor_ptr->grid_array[current_floor_ptr->mon_lite_y[i]][current_floor_ptr->mon_lite_x[i]];
2083
2084                 /* Set temp or xtra flag */
2085                 g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
2086
2087                 /* Clear monster illumination flag */
2088                 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
2089         }
2090
2091         /* Empty temp list of new squares to lite up */
2092         tmp_pos.n = 0;
2093
2094         /* If a monster stops time, don't process */
2095         if (!current_world_ptr->timewalk_m_idx)
2096         {
2097                 monster_type *m_ptr;
2098                 monster_race *r_ptr;
2099
2100                 /* Loop through monsters, adding newly lit squares to changes list */
2101                 for (i = 1; i < m_max; i++)
2102                 {
2103                         m_ptr = &current_floor_ptr->m_list[i];
2104                         r_ptr = &r_info[m_ptr->r_idx];
2105                         if (!monster_is_valid(m_ptr)) continue;
2106
2107                         /* Is it too far away? */
2108                         if (m_ptr->cdis > dis_lim) continue;
2109
2110                         /* Get lite radius */
2111                         rad = 0;
2112
2113                         /* Note the radii are cumulative */
2114                         if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
2115                         if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
2116                         if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
2117                         if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
2118
2119                         /* Exit if has no light */
2120                         if (!rad) continue;
2121                         else if (rad > 0)
2122                         {
2123                                 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (MON_CSLEEP(m_ptr) || (!current_floor_ptr->dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
2124                                 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
2125                                 add_mon_lite = mon_lite_hack;
2126                                 f_flag = FF_LOS;
2127                         }
2128                         else
2129                         {
2130                                 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!current_floor_ptr->dun_level && !is_daytime()))) continue;
2131                                 add_mon_lite = mon_dark_hack;
2132                                 f_flag = FF_PROJECT;
2133                                 rad = -rad; /* Use absolute value */
2134                         }
2135
2136                         mon_fx = m_ptr->fx;
2137                         mon_fy = m_ptr->fy;
2138
2139                         /* Is the monster visible? */
2140                         mon_invis = !(current_floor_ptr->grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
2141
2142                         /* The square it is on */
2143                         add_mon_lite(mon_fy, mon_fx);
2144
2145                         /* Adjacent squares */
2146                         add_mon_lite(mon_fy + 1, mon_fx);
2147                         add_mon_lite(mon_fy - 1, mon_fx);
2148                         add_mon_lite(mon_fy, mon_fx + 1);
2149                         add_mon_lite(mon_fy, mon_fx - 1);
2150                         add_mon_lite(mon_fy + 1, mon_fx + 1);
2151                         add_mon_lite(mon_fy + 1, mon_fx - 1);
2152                         add_mon_lite(mon_fy - 1, mon_fx + 1);
2153                         add_mon_lite(mon_fy - 1, mon_fx - 1);
2154
2155                         /* Radius 2 */
2156                         if (rad >= 2)
2157                         {
2158                                 /* South of the monster */
2159                                 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
2160                                 {
2161                                         add_mon_lite(mon_fy + 2, mon_fx + 1);
2162                                         add_mon_lite(mon_fy + 2, mon_fx);
2163                                         add_mon_lite(mon_fy + 2, mon_fx - 1);
2164
2165                                         g_ptr = &current_floor_ptr->grid_array[mon_fy + 2][mon_fx];
2166
2167                                         /* Radius 3 */
2168                                         if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
2169                                         {
2170                                                 add_mon_lite(mon_fy + 3, mon_fx + 1);
2171                                                 add_mon_lite(mon_fy + 3, mon_fx);
2172                                                 add_mon_lite(mon_fy + 3, mon_fx - 1);
2173                                         }
2174                                 }
2175
2176                                 /* North of the monster */
2177                                 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
2178                                 {
2179                                         add_mon_lite(mon_fy - 2, mon_fx + 1);
2180                                         add_mon_lite(mon_fy - 2, mon_fx);
2181                                         add_mon_lite(mon_fy - 2, mon_fx - 1);
2182
2183                                         g_ptr = &current_floor_ptr->grid_array[mon_fy - 2][mon_fx];
2184
2185                                         /* Radius 3 */
2186                                         if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
2187                                         {
2188                                                 add_mon_lite(mon_fy - 3, mon_fx + 1);
2189                                                 add_mon_lite(mon_fy - 3, mon_fx);
2190                                                 add_mon_lite(mon_fy - 3, mon_fx - 1);
2191                                         }
2192                                 }
2193
2194                                 /* East of the monster */
2195                                 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
2196                                 {
2197                                         add_mon_lite(mon_fy + 1, mon_fx + 2);
2198                                         add_mon_lite(mon_fy, mon_fx + 2);
2199                                         add_mon_lite(mon_fy - 1, mon_fx + 2);
2200
2201                                         g_ptr = &current_floor_ptr->grid_array[mon_fy][mon_fx + 2];
2202
2203                                         /* Radius 3 */
2204                                         if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
2205                                         {
2206                                                 add_mon_lite(mon_fy + 1, mon_fx + 3);
2207                                                 add_mon_lite(mon_fy, mon_fx + 3);
2208                                                 add_mon_lite(mon_fy - 1, mon_fx + 3);
2209                                         }
2210                                 }
2211
2212                                 /* West of the monster */
2213                                 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
2214                                 {
2215                                         add_mon_lite(mon_fy + 1, mon_fx - 2);
2216                                         add_mon_lite(mon_fy, mon_fx - 2);
2217                                         add_mon_lite(mon_fy - 1, mon_fx - 2);
2218
2219                                         g_ptr = &current_floor_ptr->grid_array[mon_fy][mon_fx - 2];
2220
2221                                         /* Radius 3 */
2222                                         if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
2223                                         {
2224                                                 add_mon_lite(mon_fy + 1, mon_fx - 3);
2225                                                 add_mon_lite(mon_fy, mon_fx - 3);
2226                                                 add_mon_lite(mon_fy - 1, mon_fx - 3);
2227                                         }
2228                                 }
2229                         }
2230
2231                         /* Radius 3 */
2232                         if (rad == 3)
2233                         {
2234                                 /* South-East of the monster */
2235                                 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
2236                                 {
2237                                         add_mon_lite(mon_fy + 2, mon_fx + 2);
2238                                 }
2239
2240                                 /* South-West of the monster */
2241                                 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
2242                                 {
2243                                         add_mon_lite(mon_fy + 2, mon_fx - 2);
2244                                 }
2245
2246                                 /* North-East of the monster */
2247                                 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
2248                                 {
2249                                         add_mon_lite(mon_fy - 2, mon_fx + 2);
2250                                 }
2251
2252                                 /* North-West of the monster */
2253                                 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
2254                                 {
2255                                         add_mon_lite(mon_fy - 2, mon_fx - 2);
2256                                 }
2257                         }
2258                 }
2259         }
2260
2261         /* Save end of list of new squares */
2262         end_temp = tmp_pos.n;
2263
2264         /*
2265          * Look at old set flags to see if there are any changes.
2266          */
2267         for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
2268         {
2269                 fx = current_floor_ptr->mon_lite_x[i];
2270                 fy = current_floor_ptr->mon_lite_y[i];
2271
2272                 /* We trust this grid is in bounds */
2273
2274                 /* Point to grid */
2275                 g_ptr = &current_floor_ptr->grid_array[fy][fx];
2276
2277                 if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
2278                 {
2279                         /* It it no longer lit? */
2280                         if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
2281                         {
2282                                 /* It is now unlit */
2283                                 /* Add it to later visual update */
2284                                 cave_note_and_redraw_later(g_ptr, fy, fx);
2285                         }
2286                 }
2287                 else /* Pervious darkened */
2288                 {
2289                         /* It it no longer darken? */
2290                         if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
2291                         {
2292                                 /* It is now undarken */
2293                                 /* Add it to later visual update */
2294                                 cave_note_and_redraw_later(g_ptr, fy, fx);
2295                         }
2296                 }
2297
2298                 /* Add to end of temp array */
2299                 tmp_pos.x[tmp_pos.n] = fx;
2300                 tmp_pos.y[tmp_pos.n] = fy;
2301                 tmp_pos.n++;
2302         }
2303
2304         /* Clear the lite array */
2305         current_floor_ptr->mon_lite_n = 0;
2306
2307         /* Copy the temp array into the lit array lighting the new squares. */
2308         for (i = 0; i < end_temp; i++)
2309         {
2310                 fx = tmp_pos.x[i];
2311                 fy = tmp_pos.y[i];
2312
2313                 /* We trust this grid is in bounds */
2314
2315                 /* Point to grid */
2316                 g_ptr = &current_floor_ptr->grid_array[fy][fx];
2317
2318                 if (g_ptr->info & CAVE_MNLT) /* Lit */
2319                 {
2320                         /* The is the square newly lit and visible? */
2321                         if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
2322                         {
2323                                 /* It is now lit */
2324                                 /* Add it to later visual update */
2325                                 cave_note_and_redraw_later(g_ptr, fy, fx);
2326                         }
2327                 }
2328                 else /* Darkened */
2329                 {
2330                         /* The is the square newly darkened and visible? */
2331                         if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
2332                         {
2333                                 /* It is now darkened */
2334                                 /* Add it to later visual update */
2335                                 cave_note_and_redraw_later(g_ptr, fy, fx);
2336                         }
2337                 }
2338
2339                 /* Save in the monster lit or darkened array */
2340                 current_floor_ptr->mon_lite_x[current_floor_ptr->mon_lite_n] = fx;
2341                 current_floor_ptr->mon_lite_y[current_floor_ptr->mon_lite_n] = fy;
2342                 current_floor_ptr->mon_lite_n++;
2343         }
2344
2345         /* Clear the temp flag for the old lit or darken grids */
2346         for (i = end_temp; i < tmp_pos.n; i++)
2347         {
2348                 /* We trust this grid is in bounds */
2349
2350                 current_floor_ptr->grid_array[tmp_pos.y[i]][tmp_pos.x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
2351         }
2352
2353         /* Finished with tmp_pos.n */
2354         tmp_pos.n = 0;
2355
2356         /* Mega-Hack -- Visual update later */
2357         p_ptr->update |= (PU_DELAY_VIS);
2358
2359         p_ptr->monlite = (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
2360
2361         if (p_ptr->special_defense & NINJA_S_STEALTH)
2362         {
2363                 if (p_ptr->old_monlite != p_ptr->monlite)
2364                 {
2365                         if (p_ptr->monlite)
2366                         {
2367                                 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
2368                         }
2369                         else
2370                         {
2371                                 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
2372                         }
2373                 }
2374         }
2375         p_ptr->old_monlite = p_ptr->monlite;
2376 }
2377
2378 void clear_mon_lite(void)
2379 {
2380         int i;
2381         grid_type *g_ptr;
2382
2383         /* Clear all monster lit squares */
2384         for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
2385         {
2386                 /* Point to grid */
2387                 g_ptr = &current_floor_ptr->grid_array[current_floor_ptr->mon_lite_y[i]][current_floor_ptr->mon_lite_x[i]];
2388
2389                 /* Clear monster illumination flag */
2390                 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
2391         }
2392
2393         /* Empty the array */
2394         current_floor_ptr->mon_lite_n = 0;
2395 }
2396
2397
2398
2399 /*
2400  * Clear the viewable space
2401  */
2402 void forget_view(void)
2403 {
2404         int i;
2405
2406         grid_type *g_ptr;
2407
2408         /* None to forget */
2409         if (!current_floor_ptr->view_n) return;
2410
2411         /* Clear them all */
2412         for (i = 0; i < current_floor_ptr->view_n; i++)
2413         {
2414                 POSITION y = current_floor_ptr->view_y[i];
2415                 POSITION x = current_floor_ptr->view_x[i];
2416                 g_ptr = &current_floor_ptr->grid_array[y][x];
2417
2418                 /* Forget that the grid is viewable */
2419                 g_ptr->info &= ~(CAVE_VIEW);
2420
2421                 /* if (!panel_contains(y, x)) continue; */
2422
2423                 /* Update the screen */
2424                 /* lite_spot(y, x); Perhaps don't need? */
2425         }
2426
2427         /* None left */
2428         current_floor_ptr->view_n = 0;
2429 }
2430
2431
2432
2433 /*
2434  * This macro allows us to efficiently add a grid to the "view" array,
2435  * note that we are never called for illegal grids, or for grids which
2436  * have already been placed into the "view" array, and we are never
2437  * called when the "view" array is full.
2438  */
2439 #define cave_view_hack(C,Y,X) \
2440 {\
2441     if (!((C)->info & (CAVE_VIEW))){\
2442     (C)->info |= (CAVE_VIEW); \
2443     current_floor_ptr->view_y[current_floor_ptr->view_n] = (Y); \
2444     current_floor_ptr->view_x[current_floor_ptr->view_n] = (X); \
2445     current_floor_ptr->view_n++;}\
2446 }
2447
2448
2449
2450  /*
2451   * Helper function for "update_view()" below
2452   *
2453   * We are checking the "viewability" of grid (y,x) by the player.
2454   *
2455   * This function assumes that (y,x) is legal (i.e. on the map).
2456   *
2457   * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
2458   * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
2459   *
2460   * Note that we are using the "CAVE_XTRA" field for marking grids as
2461   * "easily viewable".  This bit is cleared at the end of "update_view()".
2462   *
2463   * This function adds (y,x) to the "viewable set" if necessary.
2464   *
2465   * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
2466   */
2467 static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
2468 {
2469         bool f1, f2, v1, v2, z1, z2, wall;
2470
2471         grid_type *g_ptr;
2472
2473         grid_type *g1_c_ptr;
2474         grid_type *g2_c_ptr;
2475
2476         /* Access the grids */
2477         g1_c_ptr = &current_floor_ptr->grid_array[y1][x1];
2478         g2_c_ptr = &current_floor_ptr->grid_array[y2][x2];
2479
2480
2481         /* Check for walls */
2482         f1 = (cave_los_grid(g1_c_ptr));
2483         f2 = (cave_los_grid(g2_c_ptr));
2484
2485         /* Totally blocked by physical walls */
2486         if (!f1 && !f2) return (TRUE);
2487
2488
2489         /* Check for visibility */
2490         v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
2491         v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
2492
2493         /* Totally blocked by "unviewable neighbors" */
2494         if (!v1 && !v2) return (TRUE);
2495
2496         g_ptr = &current_floor_ptr->grid_array[y][x];
2497
2498
2499         /* Check for walls */
2500         wall = (!cave_los_grid(g_ptr));
2501
2502
2503         /* Check the "ease" of visibility */
2504         z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
2505         z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
2506
2507         /* Hack -- "easy" plus "easy" yields "easy" */
2508         if (z1 && z2)
2509         {
2510                 g_ptr->info |= (CAVE_XTRA);
2511
2512                 cave_view_hack(g_ptr, y, x);
2513
2514                 return (wall);
2515         }
2516
2517         /* Hack -- primary "easy" yields "viewed" */
2518         if (z1)
2519         {
2520                 cave_view_hack(g_ptr, y, x);
2521
2522                 return (wall);
2523         }
2524
2525         /* Hack -- "view" plus "view" yields "view" */
2526         if (v1 && v2)
2527         {
2528                 /* g_ptr->info |= (CAVE_XTRA); */
2529
2530                 cave_view_hack(g_ptr, y, x);
2531
2532                 return (wall);
2533         }
2534
2535
2536         /* Mega-Hack -- the "los()" function works poorly on walls */
2537         if (wall)
2538         {
2539                 cave_view_hack(g_ptr, y, x);
2540
2541                 return (wall);
2542         }
2543
2544
2545         /* Hack -- check line of sight */
2546         if (los(p_ptr->y, p_ptr->x, y, x))
2547         {
2548                 cave_view_hack(g_ptr, y, x);
2549
2550                 return (wall);
2551         }
2552
2553
2554         /* Assume no line of sight. */
2555         return (TRUE);
2556 }
2557
2558
2559
2560 /*
2561  * Calculate the viewable space
2562  *
2563  *  1: Process the player
2564  *  1a: The player is always (easily) viewable
2565  *  2: Process the diagonals
2566  *  2a: The diagonals are (easily) viewable up to the first wall
2567  *  2b: But never go more than 2/3 of the "full" distance
2568  *  3: Process the main axes
2569  *  3a: The main axes are (easily) viewable up to the first wall
2570  *  3b: But never go more than the "full" distance
2571  *  4: Process sequential "strips" in each of the eight octants
2572  *  4a: Each strip runs along the previous strip
2573  *  4b: The main axes are "previous" to the first strip
2574  *  4c: Process both "sides" of each "direction" of each strip
2575  *  4c1: Each side aborts as soon as possible
2576  *  4c2: Each side tells the next strip how far it has to check
2577  *
2578  * Note that the octant processing involves some pretty interesting
2579  * observations involving when a grid might possibly be viewable from
2580  * a given grid, and on the order in which the strips are processed.
2581  *
2582  * Note the use of the mathematical facts shown below, which derive
2583  * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
2584  * hypotenuse of a right triangle is primarily determined by the length
2585  * of the longest side, when one side is small, and is strictly less
2586  * than one-and-a-half times as long as the longest side when both of
2587  * the sides are large.
2588  *
2589  *   if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
2590  *   if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
2591  *
2592  *   hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
2593  *
2594  * These observations are important because the calculation of the actual
2595  * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
2596  * while for small values (up to about 20 or so), the approximations above
2597  * are correct to within an error of at most one grid or so.
2598  *
2599  * Observe the use of "full" and "over" in the code below, and the use of
2600  * the specialized calculation involving "limit", all of which derive from
2601  * the observations given above.  Basically, we note that the "circle" of
2602  * view is completely contained in an "octagon" whose bounds are easy to
2603  * determine, and that only a few steps are needed to derive the actual
2604  * bounds of the circle given the bounds of the octagon.
2605  *
2606  * Note that by skipping all the grids in the corners of the octagon, we
2607  * place an upper limit on the number of grids in the field of view, given
2608  * that "full" is never more than 20.  Of the 1681 grids in the "square" of
2609  * view, only about 1475 of these are in the "octagon" of view, and even
2610  * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
2611  * entries to completely contain the actual field of view.
2612  *
2613  * Note also the care taken to prevent "running off the map".  The use of
2614  * explicit checks on the "validity" of the "diagonal", and the fact that
2615  * the loops are never allowed to "leave" the map, lets "update_view_aux()"
2616  * use the optimized "cave_los_bold()" macro, and to avoid the overhead
2617  * of multiple checks on the validity of grids.
2618  *
2619  * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
2620  * "ws","wn" variables.  They work like this: While travelling down the
2621  * south-bound strip just to the east of the main south axis, as soon as
2622  * we get to a grid which does not "transmit" viewing, if all of the strips
2623  * preceding us (in this case, just the main axis) had terminated at or before
2624  * the same point, then we can stop, and reset the "max distance" to ourself.
2625  * So, each strip (named by major axis plus offset, thus "se" in this case)
2626  * maintains a "blockage" variable, initialized during the main axis step,
2627  * and checks it whenever a blockage is observed.  After processing each
2628  * strip as far as the previous strip told us to process, the next strip is
2629  * told not to go farther than the current strip's farthest viewable grid,
2630  * unless open space is still available.  This uses the "k" variable.
2631  *
2632  * Note the use of "inline" macros for efficiency.  The "cave_los_grid()"
2633  * macro is a replacement for "cave_los_bold()" which takes a pointer to
2634  * a grid instead of its location.  The "cave_view_hack()" macro is a
2635  * chunk of code which adds the given location to the "view" array if it
2636  * is not already there, using both the actual location and a pointer to
2637  * the grid.  See above.
2638  *
2639  * By the way, the purpose of this code is to reduce the dependancy on the
2640  * "los()" function which is slow, and, in some cases, not very accurate.
2641  *
2642  * It is very possible that I am the only person who fully understands this
2643  * function, and for that I am truly sorry, but efficiency was very important
2644  * and the "simple" version of this function was just not fast enough.  I am
2645  * more than willing to replace this function with a simpler one, if it is
2646  * equally efficient, and especially willing if the new function happens to
2647  * derive "reverse-line-of-sight" at the same time, since currently monsters
2648  * just use an optimized hack of "you see me, so I see you", and then use the
2649  * actual "projectable()" function to check spell attacks.
2650  */
2651 void update_view(void)
2652 {
2653         int n, m, d, k, z;
2654         POSITION y, x;
2655
2656         int se, sw, ne, nw, es, en, ws, wn;
2657
2658         int full, over;
2659
2660         POSITION y_max = current_floor_ptr->height - 1;
2661         POSITION x_max = current_floor_ptr->width - 1;
2662
2663         grid_type *g_ptr;
2664
2665         /*** Initialize ***/
2666
2667         /* Optimize */
2668         if (view_reduce_view && !current_floor_ptr->dun_level)
2669         {
2670                 /* Full radius (10) */
2671                 full = MAX_SIGHT / 2;
2672
2673                 /* Octagon factor (15) */
2674                 over = MAX_SIGHT * 3 / 4;
2675         }
2676
2677         /* Normal */
2678         else
2679         {
2680                 /* Full radius (20) */
2681                 full = MAX_SIGHT;
2682
2683                 /* Octagon factor (30) */
2684                 over = MAX_SIGHT * 3 / 2;
2685         }
2686
2687
2688         /*** Step 0 -- Begin ***/
2689
2690         /* Save the old "view" grids for later */
2691         for (n = 0; n < current_floor_ptr->view_n; n++)
2692         {
2693                 y = current_floor_ptr->view_y[n];
2694                 x = current_floor_ptr->view_x[n];
2695                 g_ptr = &current_floor_ptr->grid_array[y][x];
2696
2697                 /* Mark the grid as not in "view" */
2698                 g_ptr->info &= ~(CAVE_VIEW);
2699
2700                 /* Mark the grid as "seen" */
2701                 g_ptr->info |= (CAVE_TEMP);
2702
2703                 /* Add it to the "seen" set */
2704                 tmp_pos.y[tmp_pos.n] = y;
2705                 tmp_pos.x[tmp_pos.n] = x;
2706                 tmp_pos.n++;
2707         }
2708
2709         /* Start over with the "view" array */
2710         current_floor_ptr->view_n = 0;
2711
2712         /*** Step 1 -- adjacent grids ***/
2713
2714         /* Now start on the player */
2715         y = p_ptr->y;
2716         x = p_ptr->x;
2717         g_ptr = &current_floor_ptr->grid_array[y][x];
2718
2719         /* Assume the player grid is easily viewable */
2720         g_ptr->info |= (CAVE_XTRA);
2721
2722         /* Assume the player grid is viewable */
2723         cave_view_hack(g_ptr, y, x);
2724
2725
2726         /*** Step 2 -- Major Diagonals ***/
2727
2728         /* Hack -- Limit */
2729         z = full * 2 / 3;
2730
2731         /* Scan south-east */
2732         for (d = 1; d <= z; d++)
2733         {
2734                 g_ptr = &current_floor_ptr->grid_array[y + d][x + d];
2735                 g_ptr->info |= (CAVE_XTRA);
2736                 cave_view_hack(g_ptr, y + d, x + d);
2737                 if (!cave_los_grid(g_ptr)) break;
2738         }
2739
2740         /* Scan south-west */
2741         for (d = 1; d <= z; d++)
2742         {
2743                 g_ptr = &current_floor_ptr->grid_array[y + d][x - d];
2744                 g_ptr->info |= (CAVE_XTRA);
2745                 cave_view_hack(g_ptr, y + d, x - d);
2746                 if (!cave_los_grid(g_ptr)) break;
2747         }
2748
2749         /* Scan north-east */
2750         for (d = 1; d <= z; d++)
2751         {
2752                 g_ptr = &current_floor_ptr->grid_array[y - d][x + d];
2753                 g_ptr->info |= (CAVE_XTRA);
2754                 cave_view_hack(g_ptr, y - d, x + d);
2755                 if (!cave_los_grid(g_ptr)) break;
2756         }
2757
2758         /* Scan north-west */
2759         for (d = 1; d <= z; d++)
2760         {
2761                 g_ptr = &current_floor_ptr->grid_array[y - d][x - d];
2762                 g_ptr->info |= (CAVE_XTRA);
2763                 cave_view_hack(g_ptr, y - d, x - d);
2764                 if (!cave_los_grid(g_ptr)) break;
2765         }
2766
2767         /*** Step 3 -- major axes ***/
2768
2769         /* Scan south */
2770         for (d = 1; d <= full; d++)
2771         {
2772                 g_ptr = &current_floor_ptr->grid_array[y + d][x];
2773                 g_ptr->info |= (CAVE_XTRA);
2774                 cave_view_hack(g_ptr, y + d, x);
2775                 if (!cave_los_grid(g_ptr)) break;
2776         }
2777
2778         /* Initialize the "south strips" */
2779         se = sw = d;
2780
2781         /* Scan north */
2782         for (d = 1; d <= full; d++)
2783         {
2784                 g_ptr = &current_floor_ptr->grid_array[y - d][x];
2785                 g_ptr->info |= (CAVE_XTRA);
2786                 cave_view_hack(g_ptr, y - d, x);
2787                 if (!cave_los_grid(g_ptr)) break;
2788         }
2789
2790         /* Initialize the "north strips" */
2791         ne = nw = d;
2792
2793         /* Scan east */
2794         for (d = 1; d <= full; d++)
2795         {
2796                 g_ptr = &current_floor_ptr->grid_array[y][x + d];
2797                 g_ptr->info |= (CAVE_XTRA);
2798                 cave_view_hack(g_ptr, y, x + d);
2799                 if (!cave_los_grid(g_ptr)) break;
2800         }
2801
2802         /* Initialize the "east strips" */
2803         es = en = d;
2804
2805         /* Scan west */
2806         for (d = 1; d <= full; d++)
2807         {
2808                 g_ptr = &current_floor_ptr->grid_array[y][x - d];
2809                 g_ptr->info |= (CAVE_XTRA);
2810                 cave_view_hack(g_ptr, y, x - d);
2811                 if (!cave_los_grid(g_ptr)) break;
2812         }
2813
2814         /* Initialize the "west strips" */
2815         ws = wn = d;
2816
2817
2818         /*** Step 4 -- Divide each "octant" into "strips" ***/
2819
2820         /* Now check each "diagonal" (in parallel) */
2821         for (n = 1; n <= over / 2; n++)
2822         {
2823                 POSITION ypn, ymn, xpn, xmn;
2824
2825                 /* Acquire the "bounds" of the maximal circle */
2826                 z = over - n - n;
2827                 if (z > full - n) z = full - n;
2828                 while ((z + n + (n >> 1)) > full) z--;
2829
2830
2831                 /* Access the four diagonal grids */
2832                 ypn = y + n;
2833                 ymn = y - n;
2834                 xpn = x + n;
2835                 xmn = x - n;
2836
2837
2838                 /* South strip */
2839                 if (ypn < y_max)
2840                 {
2841                         /* Maximum distance */
2842                         m = MIN(z, y_max - ypn);
2843
2844                         /* East side */
2845                         if ((xpn <= x_max) && (n < se))
2846                         {
2847                                 /* Scan */
2848                                 for (k = n, d = 1; d <= m; d++)
2849                                 {
2850                                         /* Check grid "d" in strip "n", notice "blockage" */
2851                                         if (update_view_aux(ypn + d, xpn, ypn + d - 1, xpn - 1, ypn + d - 1, xpn))
2852                                         {
2853                                                 if (n + d >= se) break;
2854                                         }
2855
2856                                         /* Track most distant "non-blockage" */
2857                                         else
2858                                         {
2859                                                 k = n + d;
2860                                         }
2861                                 }
2862
2863                                 /* Limit the next strip */
2864                                 se = k + 1;
2865                         }
2866
2867                         /* West side */
2868                         if ((xmn >= 0) && (n < sw))
2869                         {
2870                                 /* Scan */
2871                                 for (k = n, d = 1; d <= m; d++)
2872                                 {
2873                                         /* Check grid "d" in strip "n", notice "blockage" */
2874                                         if (update_view_aux(ypn + d, xmn, ypn + d - 1, xmn + 1, ypn + d - 1, xmn))
2875                                         {
2876                                                 if (n + d >= sw) break;
2877                                         }
2878
2879                                         /* Track most distant "non-blockage" */
2880                                         else
2881                                         {
2882                                                 k = n + d;
2883                                         }
2884                                 }
2885
2886                                 /* Limit the next strip */
2887                                 sw = k + 1;
2888                         }
2889                 }
2890
2891
2892                 /* North strip */
2893                 if (ymn > 0)
2894                 {
2895                         /* Maximum distance */
2896                         m = MIN(z, ymn);
2897
2898                         /* East side */
2899                         if ((xpn <= x_max) && (n < ne))
2900                         {
2901                                 /* Scan */
2902                                 for (k = n, d = 1; d <= m; d++)
2903                                 {
2904                                         /* Check grid "d" in strip "n", notice "blockage" */
2905                                         if (update_view_aux(ymn - d, xpn, ymn - d + 1, xpn - 1, ymn - d + 1, xpn))
2906                                         {
2907                                                 if (n + d >= ne) break;
2908                                         }
2909
2910                                         /* Track most distant "non-blockage" */
2911                                         else
2912                                         {
2913                                                 k = n + d;
2914                                         }
2915                                 }
2916
2917                                 /* Limit the next strip */
2918                                 ne = k + 1;
2919                         }
2920
2921                         /* West side */
2922                         if ((xmn >= 0) && (n < nw))
2923                         {
2924                                 /* Scan */
2925                                 for (k = n, d = 1; d <= m; d++)
2926                                 {
2927                                         /* Check grid "d" in strip "n", notice "blockage" */
2928                                         if (update_view_aux(ymn - d, xmn, ymn - d + 1, xmn + 1, ymn - d + 1, xmn))
2929                                         {
2930                                                 if (n + d >= nw) break;
2931                                         }
2932
2933                                         /* Track most distant "non-blockage" */
2934                                         else
2935                                         {
2936                                                 k = n + d;
2937                                         }
2938                                 }
2939
2940                                 /* Limit the next strip */
2941                                 nw = k + 1;
2942                         }
2943                 }
2944
2945
2946                 /* East strip */
2947                 if (xpn < x_max)
2948                 {
2949                         /* Maximum distance */
2950                         m = MIN(z, x_max - xpn);
2951
2952                         /* South side */
2953                         if ((ypn <= x_max) && (n < es))
2954                         {
2955                                 /* Scan */
2956                                 for (k = n, d = 1; d <= m; d++)
2957                                 {
2958                                         /* Check grid "d" in strip "n", notice "blockage" */
2959                                         if (update_view_aux(ypn, xpn + d, ypn - 1, xpn + d - 1, ypn, xpn + d - 1))
2960                                         {
2961                                                 if (n + d >= es) break;
2962                                         }
2963
2964                                         /* Track most distant "non-blockage" */
2965                                         else
2966                                         {
2967                                                 k = n + d;
2968                                         }
2969                                 }
2970
2971                                 /* Limit the next strip */
2972                                 es = k + 1;
2973                         }
2974
2975                         /* North side */
2976                         if ((ymn >= 0) && (n < en))
2977                         {
2978                                 /* Scan */
2979                                 for (k = n, d = 1; d <= m; d++)
2980                                 {
2981                                         /* Check grid "d" in strip "n", notice "blockage" */
2982                                         if (update_view_aux(ymn, xpn + d, ymn + 1, xpn + d - 1, ymn, xpn + d - 1))
2983                                         {
2984                                                 if (n + d >= en) break;
2985                                         }
2986
2987                                         /* Track most distant "non-blockage" */
2988                                         else
2989                                         {
2990                                                 k = n + d;
2991                                         }
2992                                 }
2993
2994                                 /* Limit the next strip */
2995                                 en = k + 1;
2996                         }
2997                 }
2998
2999
3000                 /* West strip */
3001                 if (xmn > 0)
3002                 {
3003                         /* Maximum distance */
3004                         m = MIN(z, xmn);
3005
3006                         /* South side */
3007                         if ((ypn <= y_max) && (n < ws))
3008                         {
3009                                 /* Scan */
3010                                 for (k = n, d = 1; d <= m; d++)
3011                                 {
3012                                         /* Check grid "d" in strip "n", notice "blockage" */
3013                                         if (update_view_aux(ypn, xmn - d, ypn - 1, xmn - d + 1, ypn, xmn - d + 1))
3014                                         {
3015                                                 if (n + d >= ws) break;
3016                                         }
3017
3018                                         /* Track most distant "non-blockage" */
3019                                         else
3020                                         {
3021                                                 k = n + d;
3022                                         }
3023                                 }
3024
3025                                 /* Limit the next strip */
3026                                 ws = k + 1;
3027                         }
3028
3029                         /* North side */
3030                         if ((ymn >= 0) && (n < wn))
3031                         {
3032                                 /* Scan */
3033                                 for (k = n, d = 1; d <= m; d++)
3034                                 {
3035                                         /* Check grid "d" in strip "n", notice "blockage" */
3036                                         if (update_view_aux(ymn, xmn - d, ymn + 1, xmn - d + 1, ymn, xmn - d + 1))
3037                                         {
3038                                                 if (n + d >= wn) break;
3039                                         }
3040
3041                                         /* Track most distant "non-blockage" */
3042                                         else
3043                                         {
3044                                                 k = n + d;
3045                                         }
3046                                 }
3047
3048                                 /* Limit the next strip */
3049                                 wn = k + 1;
3050                         }
3051                 }
3052         }
3053
3054
3055         /*** Step 5 -- Complete the algorithm ***/
3056
3057         /* Update all the new grids */
3058         for (n = 0; n < current_floor_ptr->view_n; n++)
3059         {
3060                 y = current_floor_ptr->view_y[n];
3061                 x = current_floor_ptr->view_x[n];
3062                 g_ptr = &current_floor_ptr->grid_array[y][x];
3063
3064                 /* Clear the "CAVE_XTRA" flag */
3065                 g_ptr->info &= ~(CAVE_XTRA);
3066
3067                 /* Update only newly viewed grids */
3068                 if (g_ptr->info & (CAVE_TEMP)) continue;
3069
3070                 /* Add it to later visual update */
3071                 cave_note_and_redraw_later(g_ptr, y, x);
3072         }
3073
3074         /* Wipe the old grids, update as needed */
3075         for (n = 0; n < tmp_pos.n; n++)
3076         {
3077                 y = tmp_pos.y[n];
3078                 x = tmp_pos.x[n];
3079                 g_ptr = &current_floor_ptr->grid_array[y][x];
3080
3081                 /* No longer in the array */
3082                 g_ptr->info &= ~(CAVE_TEMP);
3083
3084                 /* Update only non-viewable grids */
3085                 if (g_ptr->info & (CAVE_VIEW)) continue;
3086
3087                 /* Add it to later visual update */
3088                 cave_redraw_later(g_ptr, y, x);
3089         }
3090
3091         /* None left */
3092         tmp_pos.n = 0;
3093
3094         /* Mega-Hack -- Visual update later */
3095         p_ptr->update |= (PU_DELAY_VIS);
3096 }
3097
3098
3099 /*
3100  * Mega-Hack -- Delayed visual update
3101  * Only used if update_view(), update_lite() or update_mon_lite() was called
3102  */
3103 void delayed_visual_update(void)
3104 {
3105         int i;
3106         POSITION y, x;
3107         grid_type *g_ptr;
3108
3109         /* Update needed grids */
3110         for (i = 0; i < current_floor_ptr->redraw_n; i++)
3111         {
3112                 y = current_floor_ptr->redraw_y[i];
3113                 x = current_floor_ptr->redraw_x[i];
3114                 g_ptr = &current_floor_ptr->grid_array[y][x];
3115
3116                 /* Update only needed grids (prevent multiple updating) */
3117                 if (!(g_ptr->info & CAVE_REDRAW)) continue;
3118
3119                 /* If required, note */
3120                 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
3121
3122                 lite_spot(y, x);
3123
3124                 /* Hack -- Visual update of monster on this grid */
3125                 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
3126
3127                 /* No longer in the array */
3128                 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
3129         }
3130
3131         /* None left */
3132         current_floor_ptr->redraw_n = 0;
3133 }
3134
3135
3136 /*
3137  * Hack -- forget the "flow" information
3138  */
3139 void forget_flow(void)
3140 {
3141         POSITION x, y;
3142
3143         /* Check the entire dungeon */
3144         for (y = 0; y < current_floor_ptr->height; y++)
3145         {
3146                 for (x = 0; x < current_floor_ptr->width; x++)
3147                 {
3148                         /* Forget the old data */
3149                         current_floor_ptr->grid_array[y][x].dist = 0;
3150                         current_floor_ptr->grid_array[y][x].cost = 0;
3151                         current_floor_ptr->grid_array[y][x].when = 0;
3152                 }
3153         }
3154 }
3155
3156
3157 /*
3158  * Hack - speed up the update_flow algorithm by only doing
3159  * it everytime the player moves out of LOS of the last
3160  * "way-point".
3161  */
3162 static POSITION flow_x = 0;
3163 static POSITION flow_y = 0;
3164
3165
3166
3167 /*
3168  * Hack -- fill in the "cost" field of every grid that the player
3169  * can "reach" with the number of steps needed to reach that grid.
3170  * This also yields the "distance" of the player from every grid.
3171  *
3172  * In addition, mark the "when" of the grids that can reach
3173  * the player with the incremented value of "flow_n".
3174  *
3175  * Hack -- use the "seen" array as a "circular queue".
3176  *
3177  * We do not need a priority queue because the cost from grid
3178  * to grid is always "one" and we process them in order.
3179  */
3180 void update_flow(void)
3181 {
3182         POSITION x, y;
3183         DIRECTION d;
3184         int flow_head = 1;
3185         int flow_tail = 0;
3186
3187         /* Paranoia -- make sure the array is empty */
3188         if (tmp_pos.n) return;
3189
3190         /* The last way-point is on the map */
3191         if (running && in_bounds(flow_y, flow_x))
3192         {
3193                 /* The way point is in sight - do not update.  (Speedup) */
3194                 if (current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
3195         }
3196
3197         /* Erase all of the current flow information */
3198         for (y = 0; y < current_floor_ptr->height; y++)
3199         {
3200                 for (x = 0; x < current_floor_ptr->width; x++)
3201                 {
3202                         current_floor_ptr->grid_array[y][x].cost = 0;
3203                         current_floor_ptr->grid_array[y][x].dist = 0;
3204                 }
3205         }
3206
3207         /* Save player position */
3208         flow_y = p_ptr->y;
3209         flow_x = p_ptr->x;
3210
3211         /* Add the player's grid to the queue */
3212         tmp_pos.y[0] = p_ptr->y;
3213         tmp_pos.x[0] = p_ptr->x;
3214
3215         /* Now process the queue */
3216         while (flow_head != flow_tail)
3217         {
3218                 int ty, tx;
3219
3220                 /* Extract the next entry */
3221                 ty = tmp_pos.y[flow_tail];
3222                 tx = tmp_pos.x[flow_tail];
3223
3224                 /* Forget that entry */
3225                 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3226
3227                 /* Add the "children" */
3228                 for (d = 0; d < 8; d++)
3229                 {
3230                         int old_head = flow_head;
3231                         byte_hack m = current_floor_ptr->grid_array[ty][tx].cost + 1;
3232                         byte_hack n = current_floor_ptr->grid_array[ty][tx].dist + 1;
3233                         grid_type *g_ptr;
3234
3235                         /* Child location */
3236                         y = ty + ddy_ddd[d];
3237                         x = tx + ddx_ddd[d];
3238
3239                         /* Ignore player's grid */
3240                         if (player_bold(y, x)) continue;
3241
3242                         g_ptr = &current_floor_ptr->grid_array[y][x];
3243
3244                         if (is_closed_door(g_ptr->feat)) m += 3;
3245
3246                         /* Ignore "pre-stamped" entries */
3247                         if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
3248
3249                         /* Ignore "walls" and "rubble" */
3250                         if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
3251
3252                         /* Save the flow cost */
3253                         if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
3254                         if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
3255
3256                         /* Hack -- limit flow depth */
3257                         if (n == MONSTER_FLOW_DEPTH) continue;
3258
3259                         /* Enqueue that entry */
3260                         tmp_pos.y[flow_head] = y;
3261                         tmp_pos.x[flow_head] = x;
3262
3263                         /* Advance the queue */
3264                         if (++flow_head == TEMP_MAX) flow_head = 0;
3265
3266                         /* Hack -- notice overflow by forgetting new entry */
3267                         if (flow_head == flow_tail) flow_head = old_head;
3268                 }
3269         }
3270 }
3271
3272
3273 static int scent_when = 0;
3274
3275 /*
3276  * Characters leave scent trails for perceptive monsters to track.
3277  *
3278  * Smell is rather more limited than sound.  Many creatures cannot use
3279  * it at all, it doesn't extend very far outwards from the character's
3280  * current position, and monsters can use it to home in the character,
3281  * but not to run away from him.
3282  *
3283  * Smell is valued according to age.  When a character takes his current_world_ptr->game_turn,
3284  * scent is aged by one, and new scent of the current age is laid down.
3285  * Speedy characters leave more scent, true, but it also ages faster,
3286  * which makes it harder to hunt them down.
3287  *
3288  * Whenever the age count loops, most of the scent trail is erased and
3289  * the age of the remainder is recalculated.
3290  */
3291 void update_smell(void)
3292 {
3293         POSITION i, j;
3294         POSITION y, x;
3295
3296         /* Create a table that controls the spread of scent */
3297         const int scent_adjust[5][5] =
3298         {
3299                 { -1, 0, 0, 0,-1 },
3300                 {  0, 1, 1, 1, 0 },
3301                 {  0, 1, 2, 1, 0 },
3302                 {  0, 1, 1, 1, 0 },
3303                 { -1, 0, 0, 0,-1 },
3304         };
3305
3306         /* Loop the age and adjust scent values when necessary */
3307         if (++scent_when == 254)
3308         {
3309                 /* Scan the entire dungeon */
3310                 for (y = 0; y < current_floor_ptr->height; y++)
3311                 {
3312                         for (x = 0; x < current_floor_ptr->width; x++)
3313                         {
3314                                 int w = current_floor_ptr->grid_array[y][x].when;
3315                                 current_floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
3316                         }
3317                 }
3318
3319                 /* Restart */
3320                 scent_when = 126;
3321         }
3322
3323
3324         /* Lay down new scent */
3325         for (i = 0; i < 5; i++)
3326         {
3327                 for (j = 0; j < 5; j++)
3328                 {
3329                         grid_type *g_ptr;
3330
3331                         /* Translate table to map grids */
3332                         y = i + p_ptr->y - 2;
3333                         x = j + p_ptr->x - 2;
3334
3335                         /* Check Bounds */
3336                         if (!in_bounds(y, x)) continue;
3337
3338                         g_ptr = &current_floor_ptr->grid_array[y][x];
3339
3340                         /* Walls, water, and lava cannot hold scent. */
3341                         if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
3342
3343                         /* Grid must not be blocked by walls from the character */
3344                         if (!player_has_los_bold(y, x)) continue;
3345
3346                         /* Note grids that are too far away */
3347                         if (scent_adjust[i][j] == -1) continue;
3348
3349                         /* Mark the grid with new scent */
3350                         g_ptr->when = scent_when + scent_adjust[i][j];
3351                 }
3352         }
3353 }
3354
3355
3356 /*
3357  * Hack -- map the current panel (plus some) ala "magic mapping"
3358  */
3359 void map_area(POSITION range)
3360 {
3361         int i;
3362         POSITION x, y;
3363         grid_type *g_ptr;
3364         FEAT_IDX feat;
3365         feature_type *f_ptr;
3366
3367         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) range /= 3;
3368
3369         /* Scan that area */
3370         for (y = 1; y < current_floor_ptr->height - 1; y++)
3371         {
3372                 for (x = 1; x < current_floor_ptr->width - 1; x++)
3373                 {
3374                         if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
3375
3376                         g_ptr = &current_floor_ptr->grid_array[y][x];
3377
3378                         /* Memorize terrain of the grid */
3379                         g_ptr->info |= (CAVE_KNOWN);
3380
3381                         /* Feature code (applying "mimic" field) */
3382                         feat = get_feat_mimic(g_ptr);
3383                         f_ptr = &f_info[feat];
3384
3385                         /* All non-walls are "checked" */
3386                         if (!have_flag(f_ptr->flags, FF_WALL))
3387                         {
3388                                 /* Memorize normal features */
3389                                 if (have_flag(f_ptr->flags, FF_REMEMBER))
3390                                 {
3391                                         /* Memorize the object */
3392                                         g_ptr->info |= (CAVE_MARK);
3393                                 }
3394
3395                                 /* Memorize known walls */
3396                                 for (i = 0; i < 8; i++)
3397                                 {
3398                                         g_ptr = &current_floor_ptr->grid_array[y + ddy_ddd[i]][x + ddx_ddd[i]];
3399
3400                                         /* Feature code (applying "mimic" field) */
3401                                         feat = get_feat_mimic(g_ptr);
3402                                         f_ptr = &f_info[feat];
3403
3404                                         /* Memorize walls (etc) */
3405                                         if (have_flag(f_ptr->flags, FF_REMEMBER))
3406                                         {
3407                                                 /* Memorize the walls */
3408                                                 g_ptr->info |= (CAVE_MARK);
3409                                         }
3410                                 }
3411                         }
3412                 }
3413         }
3414
3415         p_ptr->redraw |= (PR_MAP);
3416
3417         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3418 }
3419
3420
3421 /*
3422  * Change the "feat" flag for a grid, and notice/redraw the grid
3423  */
3424 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
3425 {
3426         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
3427         feature_type *f_ptr = &f_info[feat];
3428         bool old_los, old_mirror;
3429
3430         if (!character_dungeon)
3431         {
3432                 /* Clear mimic type */
3433                 g_ptr->mimic = 0;
3434
3435                 /* Change the feature */
3436                 g_ptr->feat = feat;
3437
3438                 /* Hack -- glow the GLOW terrain */
3439                 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
3440                 {
3441                         DIRECTION i;
3442                         POSITION yy, xx;
3443
3444                         for (i = 0; i < 9; i++)
3445                         {
3446                                 yy = y + ddy_ddd[i];
3447                                 xx = x + ddx_ddd[i];
3448                                 if (!in_bounds2(yy, xx)) continue;
3449                                 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
3450                         }
3451                 }
3452
3453                 return;
3454         }
3455
3456         old_los = cave_have_flag_bold(y, x, FF_LOS);
3457         old_mirror = is_mirror_grid(g_ptr);
3458
3459         /* Clear mimic type */
3460         g_ptr->mimic = 0;
3461
3462         /* Change the feature */
3463         g_ptr->feat = feat;
3464
3465         /* Remove flag for mirror/glyph */
3466         g_ptr->info &= ~(CAVE_OBJECT);
3467
3468         if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
3469         {
3470                 g_ptr->info &= ~(CAVE_GLOW);
3471                 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
3472
3473                 update_local_illumination(y, x);
3474         }
3475
3476         /* Check for change to boring grid */
3477         if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
3478         if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
3479
3480         note_spot(y, x);
3481         lite_spot(y, x);
3482
3483         /* Check if los has changed */
3484         if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
3485         {
3486
3487 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
3488
3489                 update_local_illumination(y, x);
3490
3491 #endif /* COMPLEX_WALL_ILLUMINATION */
3492
3493                 /* Update the visuals */
3494                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
3495         }
3496
3497         /* Hack -- glow the GLOW terrain */
3498         if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
3499         {
3500                 DIRECTION i;
3501                 POSITION yy, xx;
3502                 grid_type *cc_ptr;
3503
3504                 for (i = 0; i < 9; i++)
3505                 {
3506                         yy = y + ddy_ddd[i];
3507                         xx = x + ddx_ddd[i];
3508                         if (!in_bounds2(yy, xx)) continue;
3509                         cc_ptr = &current_floor_ptr->grid_array[yy][xx];
3510                         cc_ptr->info |= CAVE_GLOW;
3511
3512                         if (player_has_los_grid(cc_ptr))
3513                         {
3514                                 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
3515
3516                                 note_spot(yy, xx);
3517
3518                                 lite_spot(yy, xx);
3519                         }
3520
3521                         update_local_illumination(yy, xx);
3522                 }
3523
3524                 if (p_ptr->special_defense & NINJA_S_STEALTH)
3525                 {
3526                         if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
3527                 }
3528         }
3529 }
3530
3531
3532 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
3533 {
3534         feature_type *f_ptr = &f_info[newfeat];
3535
3536         if (have_flag(f_ptr->flags, FF_CONVERT))
3537         {
3538                 switch (f_ptr->subtype)
3539                 {
3540                 case CONVERT_TYPE_FLOOR:
3541                         return feat_ground_type[randint0(100)];
3542                 case CONVERT_TYPE_WALL:
3543                         return feat_wall_type[randint0(100)];
3544                 case CONVERT_TYPE_INNER:
3545                         return feat_wall_inner;
3546                 case CONVERT_TYPE_OUTER:
3547                         return feat_wall_outer;
3548                 case CONVERT_TYPE_SOLID:
3549                         return feat_wall_solid;
3550                 case CONVERT_TYPE_STREAM1:
3551                         return d_info[p_ptr->dungeon_idx].stream1;
3552                 case CONVERT_TYPE_STREAM2:
3553                         return d_info[p_ptr->dungeon_idx].stream2;
3554                 default:
3555                         return newfeat;
3556                 }
3557         }
3558         else return newfeat;
3559 }
3560
3561
3562 /*
3563  * Take a feature, determine what that feature becomes
3564  * through applying the given action.
3565  */
3566 FEAT_IDX feat_state(FEAT_IDX feat, int action)
3567 {
3568         feature_type *f_ptr = &f_info[feat];
3569         int i;
3570
3571         /* Get the new feature */
3572         for (i = 0; i < MAX_FEAT_STATES; i++)
3573         {
3574                 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
3575         }
3576
3577         if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
3578
3579         return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
3580 }
3581
3582 /*
3583  * Takes a location and action and changes the feature at that
3584  * location through applying the given action.
3585  */
3586 void cave_alter_feat(POSITION y, POSITION x, int action)
3587 {
3588         /* Set old feature */
3589         FEAT_IDX oldfeat = current_floor_ptr->grid_array[y][x].feat;
3590
3591         /* Get the new feat */
3592         FEAT_IDX newfeat = feat_state(oldfeat, action);
3593
3594         /* No change */
3595         if (newfeat == oldfeat) return;
3596
3597         /* Set the new feature */
3598         cave_set_feat(y, x, newfeat);
3599
3600         if (!(feature_action_flags[action] & FAF_NO_DROP))
3601         {
3602                 feature_type *old_f_ptr = &f_info[oldfeat];
3603                 feature_type *f_ptr = &f_info[newfeat];
3604                 bool found = FALSE;
3605
3606                 /* Handle gold */
3607                 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
3608                 {
3609                         /* Place some gold */
3610                         place_gold(y, x);
3611                         found = TRUE;
3612                 }
3613
3614                 /* Handle item */
3615                 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - current_floor_ptr->dun_level / 2)))
3616                 {
3617                         /* Place object */
3618                         place_object(y, x, 0L);
3619                         found = TRUE;
3620                 }
3621
3622                 if (found && character_dungeon && player_can_see_bold(y, x))
3623                 {
3624                         msg_print(_("何かを発見した!", "You have found something!"));
3625                 }
3626         }
3627
3628         if (feature_action_flags[action] & FAF_CRASH_GLASS)
3629         {
3630                 feature_type *old_f_ptr = &f_info[oldfeat];
3631
3632                 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
3633                 {
3634                         project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
3635                                 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
3636                 }
3637         }
3638 }
3639
3640
3641 /* Remove a mirror */
3642 void remove_mirror(POSITION y, POSITION x)
3643 {
3644         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
3645
3646         /* Remove the mirror */
3647         g_ptr->info &= ~(CAVE_OBJECT);
3648         g_ptr->mimic = 0;
3649
3650         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
3651         {
3652                 g_ptr->info &= ~(CAVE_GLOW);
3653                 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
3654                 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
3655
3656                 update_local_illumination(y, x);
3657         }
3658
3659         note_spot(y, x);
3660
3661         lite_spot(y, x);
3662 }
3663
3664
3665 /*
3666  *  Return TRUE if there is a mirror on the grid.
3667  */
3668 bool is_mirror_grid(grid_type *g_ptr)
3669 {
3670         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
3671                 return TRUE;
3672         else
3673                 return FALSE;
3674 }
3675
3676
3677 /*
3678  *  Return TRUE if there is a mirror on the grid.
3679  */
3680 bool is_glyph_grid(grid_type *g_ptr)
3681 {
3682         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
3683                 return TRUE;
3684         else
3685                 return FALSE;
3686 }
3687
3688
3689 /*
3690  *  Return TRUE if there is a mirror on the grid.
3691  */
3692 bool is_explosive_rune_grid(grid_type *g_ptr)
3693 {
3694         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
3695                 return TRUE;
3696         else
3697                 return FALSE;
3698 }
3699
3700
3701 /*
3702  * Track a new monster
3703  */
3704 void health_track(MONSTER_IDX m_idx)
3705 {
3706         /* Mount monster is already tracked */
3707         if (m_idx && m_idx == p_ptr->riding) return;
3708
3709         /* Track a new guy */
3710         p_ptr->health_who = m_idx;
3711
3712         /* Redraw (later) */
3713         p_ptr->redraw |= (PR_HEALTH);
3714 }
3715
3716
3717
3718 /*
3719  * Hack -- track the given monster race
3720  */
3721 void monster_race_track(MONRACE_IDX r_idx)
3722 {
3723         /* Save this monster ID */
3724         p_ptr->monster_race_idx = r_idx;
3725
3726         p_ptr->window |= (PW_MONSTER);
3727 }
3728
3729
3730
3731 /*
3732  * Hack -- track the given object kind
3733  */
3734 void object_kind_track(KIND_OBJECT_IDX k_idx)
3735 {
3736         /* Save this monster ID */
3737         p_ptr->object_kind_idx = k_idx;
3738
3739         p_ptr->window |= (PW_OBJECT);
3740 }
3741
3742
3743 /*!
3744 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
3745 * @param m_idx モンスターID
3746 * @param y 移動先Y座標
3747 * @param x 移動先X座標
3748 * @param mode オプション
3749 * @return テレポート先として妥当ならばtrue
3750 */
3751 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
3752 {
3753         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
3754         grid_type    *g_ptr = &current_floor_ptr->grid_array[y][x];
3755         feature_type *f_ptr = &f_info[g_ptr->feat];
3756
3757         /* Require "teleportable" space */
3758         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
3759
3760         if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
3761         if (player_bold(y, x)) return FALSE;
3762
3763         /* Hack -- no teleport onto glyph of warding */
3764         if (is_glyph_grid(g_ptr)) return FALSE;
3765         if (is_explosive_rune_grid(g_ptr)) return FALSE;
3766
3767         if (!(mode & TELEPORT_PASSIVE))
3768         {
3769                 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
3770         }
3771
3772         return TRUE;
3773 }
3774
3775 /*!
3776 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
3777 * @param y 移動先Y座標
3778 * @param x 移動先X座標
3779 * @param mode オプション
3780 * @return テレポート先として妥当ならばtrue
3781 */
3782 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
3783 {
3784         grid_type    *g_ptr = &current_floor_ptr->grid_array[y][x];
3785         feature_type *f_ptr = &f_info[g_ptr->feat];
3786
3787         /* Require "teleportable" space */
3788         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
3789
3790         /* No magical teleporting into vaults and such */
3791         if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
3792
3793         if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
3794
3795         /* don't teleport on a trap. */
3796         if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
3797
3798         if (!(mode & TELEPORT_PASSIVE))
3799         {
3800                 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
3801
3802                 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
3803                 {
3804                         if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
3805                 }
3806
3807                 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
3808                 {
3809                         /* Always forbid deep lava */
3810                         if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
3811
3812                         /* Forbid shallow lava when the player don't have levitation */
3813                         if (!p_ptr->levitation) return FALSE;
3814                 }
3815
3816         }
3817
3818         return TRUE;
3819 }
3820
3821 /*!
3822  * @brief 地形は開くものであって、かつ開かれているかを返す /
3823  * Attempt to open the given chest at the given location
3824  * @param feat 地形ID
3825  * @return 開いた地形である場合TRUEを返す /  Return TRUE if the given feature is an open door
3826  */
3827 bool is_open(FEAT_IDX feat)
3828 {
3829         return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
3830 }
3831
3832 /*!
3833  * @brief プレイヤーが地形踏破可能かを返す
3834  * @param feature 判定したい地形ID
3835  * @param mode 移動に関するオプションフラグ
3836  * @return 移動可能ならばTRUEを返す
3837  */
3838 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
3839 {
3840         feature_type *f_ptr = &f_info[feature];
3841
3842         if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[current_floor_ptr->m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
3843
3844         if (have_flag(f_ptr->flags, FF_PATTERN))
3845         {
3846                 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
3847         }
3848
3849         if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
3850         if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
3851         if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
3852
3853         if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;
3854
3855         return TRUE;
3856 }
3857