OSDN Git Service

fed98872be25cd0c47d933bed4d8f737a0670632
[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 "util.h"
22 #include "term.h"
23
24 #include "floor.h"
25 #include "world.h"
26 #include "object-flavor.h"
27 #include "object-hook.h"
28 #include "dungeon.h"
29 #include "floor-generate.h"
30 #include "grid.h"
31 #include "trap.h"
32 #include "rooms.h"
33 #include "monster.h"
34 #include "quest.h"
35 #include "feature.h"
36 #include "monster-status.h"
37 #include "player-status.h"
38 #include "player-effects.h"
39 #include "player-class.h"
40 #include "spells.h"
41 #include "view-mainwindow.h"
42 #include "realm-song.h"
43
44 #define MONSTER_FLOW_DEPTH 32 /*!< 敵のプレイヤーに対する移動道のりの最大値(この値以上は処理を打ち切る) / OPTION: Maximum flow depth when using "MONSTER_FLOW" */
45
46 /*
47  * Feature action flags
48  */
49 #define FAF_DESTROY     0x01
50 #define FAF_NO_DROP     0x02
51 #define FAF_CRASH_GLASS 0x04
52
53 /*!
54  * @brief 地形状態フラグテーブル /
55  * The table of features' actions
56  */
57 static const byte feature_action_flags[FF_FLAG_MAX] =
58 {
59         0, /* LOS */
60         0, /* PROJECT */
61         0, /* MOVE */
62         0, /* PLACE */
63         0, /* DROP */
64         0, /* SECRET */
65         0, /* NOTICE */
66         0, /* REMEMBER */
67         0, /* OPEN */
68         0, /* CLOSE */
69         FAF_CRASH_GLASS, /* BASH */
70         0, /* SPIKE */
71         FAF_DESTROY, /* DISARM */
72         0, /* STORE */
73         FAF_DESTROY | FAF_CRASH_GLASS, /* TUNNEL */
74         0, /* MAY_HAVE_GOLD */
75         0, /* HAS_GOLD */
76         0, /* HAS_ITEM */
77         0, /* DOOR */
78         0, /* TRAP */
79         0, /* STAIRS */
80         0, /* GLYPH */
81         0, /* LESS */
82         0, /* MORE */
83         0, /* RUN */
84         0, /* FLOOR */
85         0, /* WALL */
86         0, /* PERMANENT */
87         0, /* INNER */
88         0, /* OUTER */
89         0, /* SOLID */
90         0, /* HIT_TRAP */
91
92         0, /* BRIDGE */
93         0, /* RIVER */
94         0, /* LAKE */
95         0, /* BRIDGED */
96         0, /* COVERED */
97         0, /* GLOW */
98         0, /* ENSECRET */
99         0, /* WATER */
100         0, /* LAVA */
101         0, /* SHALLOW */
102         0, /* DEEP */
103         0, /* FILLED */
104         FAF_DESTROY | FAF_CRASH_GLASS, /* HURT_ROCK */
105         0, /* HURT_FIRE */
106         0, /* HURT_COLD */
107         0, /* HURT_ACID */
108         0, /* ICE */
109         0, /* ACID */
110         0, /* OIL */
111         0, /* XXX04 */
112         0, /* CAN_CLIMB */
113         0, /* CAN_FLY */
114         0, /* CAN_SWIM */
115         0, /* CAN_PASS */
116         0, /* CAN_OOZE */
117         0, /* CAN_DIG */
118         0, /* HIDE_ITEM */
119         0, /* HIDE_SNEAK */
120         0, /* HIDE_SWIM */
121         0, /* HIDE_DIG */
122         0, /* KILL_HUGE */
123         0, /* KILL_MOVE */
124
125         0, /* PICK_TRAP */
126         0, /* PICK_DOOR */
127         0, /* ALLOC */
128         0, /* CHEST */
129         0, /* DROP_1D2 */
130         0, /* DROP_2D2 */
131         0, /* DROP_GOOD */
132         0, /* DROP_GREAT */
133         0, /* HURT_POIS */
134         0, /* HURT_ELEC */
135         0, /* HURT_WATER */
136         0, /* HURT_BWATER */
137         0, /* USE_FEAT */
138         0, /* GET_FEAT */
139         0, /* GROUND */
140         0, /* OUTSIDE */
141         0, /* EASY_HIDE */
142         0, /* EASY_CLIMB */
143         0, /* MUST_CLIMB */
144         0, /* TREE */
145         0, /* NEED_TREE */
146         0, /* BLOOD */
147         0, /* DUST */
148         0, /* SLIME */
149         0, /* PLANT */
150         0, /* XXX2 */
151         0, /* INSTANT */
152         0, /* EXPLODE */
153         0, /* TIMED */
154         0, /* ERUPT */
155         0, /* STRIKE */
156         0, /* SPREAD */
157
158         0, /* SPECIAL */
159         FAF_DESTROY | FAF_NO_DROP | FAF_CRASH_GLASS, /* HURT_DISI */
160         0, /* QUEST_ENTER */
161         0, /* QUEST_EXIT */
162         0, /* QUEST */
163         0, /* SHAFT */
164         0, /* MOUNTAIN */
165         0, /* BLDG */
166         0, /* MINOR_GLYPH */
167         0, /* PATTERN */
168         0, /* TOWN */
169         0, /* ENTRANCE */
170         0, /* MIRROR */
171         0, /* UNPERM */
172         0, /* TELEPORTABLE */
173         0, /* CONVERT */
174         0, /* GLASS */
175 };
176
177 /*!
178  * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
179  * @param creature_ptr 配置したいクリーチャーの参照ポインタ
180  * @return 配置に成功したらTRUEを返す
181  */
182 bool new_player_spot(player_type *creature_ptr)
183 {
184         POSITION y = 0, x = 0;
185         int max_attempts = 10000;
186
187         grid_type *g_ptr;
188         feature_type *f_ptr;
189
190         while (max_attempts--)
191         {
192                 /* Pick a legal spot */
193                 y = (POSITION)rand_range(1, creature_ptr->current_floor_ptr->height - 2);
194                 x = (POSITION)rand_range(1, creature_ptr->current_floor_ptr->width - 2);
195
196                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
197
198                 /* Must be a "naked" floor grid */
199                 if (g_ptr->m_idx) continue;
200                 if (creature_ptr->current_floor_ptr->dun_level)
201                 {
202                         f_ptr = &f_info[g_ptr->feat];
203
204                         if (max_attempts > 5000) /* Rule 1 */
205                         {
206                                 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
207                         }
208                         else /* Rule 2 */
209                         {
210                                 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
211                                 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
212                         }
213
214                         /* Refuse to start on anti-teleport grids in dungeon */
215                         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
216                 }
217                 if (!player_can_enter(g_ptr->feat, 0)) continue;
218                 if (!in_bounds(creature_ptr->current_floor_ptr, y, x)) continue;
219
220                 /* Refuse to start on anti-teleport grids */
221                 if (g_ptr->info & (CAVE_ICKY)) continue;
222
223                 break;
224         }
225
226         if (max_attempts < 1) /* Should be -1, actually if we failed... */
227                 return FALSE;
228
229         /* Save the new player grid */
230         creature_ptr->y = y;
231         creature_ptr->x = x;
232
233         return TRUE;
234 }
235
236 /*!
237  * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
238  * @param y 配置したい中心マスのY座標
239  * @param x 配置したい中心マスのX座標
240  * @param num 配置したい数
241  * @return なし
242  * @details
243  * Only really called by some of the "vault" routines.
244  */
245 void vault_objects(POSITION y, POSITION x, int num)
246 {
247         int dummy = 0;
248         int i = 0, j = y, k = x;
249
250         grid_type *g_ptr;
251
252
253         /* Attempt to place 'num' objects */
254         for (; num > 0; --num)
255         {
256                 /* Try up to 11 spots looking for empty space */
257                 for (i = 0; i < 11; ++i)
258                 {
259                         /* Pick a random location */
260                         while (dummy < SAFE_MAX_ATTEMPTS)
261                         {
262                                 j = rand_spread(y, 2);
263                                 k = rand_spread(x, 3);
264                                 dummy++;
265                                 if (!in_bounds(p_ptr->current_floor_ptr, j, k)) continue;
266                                 break;
267                         }
268
269                         if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
270                         {
271                                 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
272                         }
273
274                         /* Require "clean" floor space */
275                         g_ptr = &p_ptr->current_floor_ptr->grid_array[j][k];
276                         if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
277
278                         if (randint0(100) < 75)
279                         {
280                                 place_object(j, k, 0L);
281                         }
282                         else
283                         {
284                                 place_gold(j, k);
285                         }
286
287                         /* Placement accomplished */
288                         break;
289                 }
290         }
291 }
292
293
294 /*!
295  * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
296  * @param y トラップを配置したいマスの中心Y座標
297  * @param x トラップを配置したいマスの中心X座標
298  * @param yd Y方向の配置分散マス数
299  * @param xd X方向の配置分散マス数
300  * @param num 配置したいトラップの数
301  * @return なし
302  * @details
303  * Only really called by some of the "vault" routines.
304  */
305 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
306 {
307         int i;
308
309         for (i = 0; i < num; i++)
310         {
311                 vault_trap_aux(p_ptr->current_floor_ptr, y, x, yd, xd);
312         }
313 }
314
315 /*!
316  * @brief 指定のマスを床地形に変える / Set a square to be floor.  (Includes range checking.)
317  * @param x 地形を変えたいマスのX座標
318  * @param y 地形を変えたいマスのY座標
319  * @return なし
320  */
321 void set_floor(POSITION x, POSITION y)
322 {
323         if (!in_bounds(p_ptr->current_floor_ptr, y, x))
324         {
325                 /* Out of bounds */
326                 return;
327         }
328
329         if (p_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
330         {
331                 /* A room border don't touch. */
332                 return;
333         }
334
335         /* Set to be floor if is a wall (don't touch lakes). */
336         if (is_extra_bold(p_ptr->current_floor_ptr, y, x))
337                 place_floor_bold(p_ptr->current_floor_ptr, y, x);
338 }
339
340 /*!
341  * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
342  * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
343  * @return なし
344  */
345 void place_bound_perm_wall(grid_type *g_ptr)
346 {
347         if (bound_walls_perm)
348         {
349                 /* Clear boundary mimic */
350                 g_ptr->mimic = 0;
351         }
352         else
353         {
354                 feature_type *f_ptr = &f_info[g_ptr->feat];
355
356                 /* Hack -- Decline boundary walls with known treasure  */
357                 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
358                         !have_flag(f_ptr->flags, FF_SECRET))
359                         g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
360
361                 /* Set boundary mimic */
362                 g_ptr->mimic = g_ptr->feat;
363         }
364
365         /* Add "solid" perma-wall */
366         place_solid_perm_grid(g_ptr);
367 }
368
369 /*!
370  * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
371  * @param g_ptr マス構造体の参照ポインタ
372  * @return 看破済みの罠があるならTRUEを返す。
373  */
374 bool is_known_trap(grid_type *g_ptr)
375 {
376         if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
377                 is_trap(g_ptr->feat)) return TRUE;
378         else
379                 return FALSE;
380 }
381
382
383
384 /*!
385  * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
386  * @param g_ptr マス構造体の参照ポインタ
387  * @return 隠されたドアがあるならTRUEを返す。
388  */
389 bool is_hidden_door(grid_type *g_ptr)
390 {
391         if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
392                 is_closed_door(g_ptr->feat))
393                 return TRUE;
394         else
395                 return FALSE;
396 }
397
398 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
399
400
401 /*!
402  * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
403  * @param y y座標
404  * @param x x座標
405  * @return 指定された座標に照明がかかっているならTRUEを返す。。
406  */
407 bool check_local_illumination(player_type *creature_ptr, POSITION y, POSITION x)
408 {
409         /* Hack -- move towards player */
410         POSITION yy = (y < creature_ptr->y) ? (y + 1) : (y > creature_ptr->y) ? (y - 1) : y;
411         POSITION xx = (x < creature_ptr->x) ? (x + 1) : (x > creature_ptr->x) ? (x - 1) : x;
412
413         /* Check for "local" illumination */
414
415 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
416
417         /* Check for "complex" illumination */
418         if ((feat_supports_los(get_feat_mimic(&creature_ptr->current_floor_ptr->grid_array[yy][xx])) &&
419                 (creature_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
420                 (feat_supports_los(get_feat_mimic(&creature_ptr->current_floor_ptr->grid_array[y][xx])) &&
421                 (creature_ptr->current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
422                         (feat_supports_los(get_feat_mimic(&creature_ptr->current_floor_ptr->grid_array[yy][x])) &&
423                 (creature_ptr->current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
424         {
425                 return TRUE;
426         }
427         else return FALSE;
428
429 #else /* COMPLEX_WALL_ILLUMINATION */
430
431         /* Check for "simple" illumination */
432         return (creature_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
433
434 #endif /* COMPLEX_WALL_ILLUMINATION */
435 }
436
437
438 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
439 #define update_local_illumination_aux(C, Y, X) \
440 { \
441         if (player_has_los_bold((C), (Y), (X))) \
442         { \
443                 /* Update the monster */ \
444                 if ((C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster((C), (C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
445 \
446                 /* Notice and redraw */ \
447                 note_spot((Y), (X)); \
448                 lite_spot((Y), (X)); \
449         } \
450 }
451
452 /*!
453  * @brief 指定された座標の照明状態を更新する / Update "local" illumination
454  * @param creature_ptr 視界元のクリーチャー
455  * @param y 視界先y座標
456  * @param x 視界先x座標
457  * @return なし
458  */
459 void update_local_illumination(player_type * creature_ptr, POSITION y, POSITION x)
460 {
461         int i;
462         POSITION yy, xx;
463
464         if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
465
466 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
467
468         if ((y != creature_ptr->y) && (x != creature_ptr->x))
469         {
470                 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
471                 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
472                 update_local_illumination_aux(creature_ptr, yy, xx);
473                 update_local_illumination_aux(creature_ptr, y, xx);
474                 update_local_illumination_aux(creature_ptr, yy, x);
475         }
476         else if (x != creature_ptr->x) /* y == creature_ptr->y */
477         {
478                 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
479                 for (i = -1; i <= 1; i++)
480                 {
481                         yy = y + i;
482                         update_local_illumination_aux(creature_ptr, yy, xx);
483                 }
484                 yy = y - 1;
485                 update_local_illumination_aux(creature_ptr, yy, x);
486                 yy = y + 1;
487                 update_local_illumination_aux(creature_ptr, yy, x);
488         }
489         else if (y != creature_ptr->y) /* x == creature_ptr->x */
490         {
491                 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
492                 for (i = -1; i <= 1; i++)
493                 {
494                         xx = x + i;
495                         update_local_illumination_aux(creature_ptr, yy, xx);
496                 }
497                 xx = x - 1;
498                 update_local_illumination_aux(creature_ptr, y, xx);
499                 xx = x + 1;
500                 update_local_illumination_aux(creature_ptr, y, xx);
501         }
502         else /* Player's grid */
503         {
504                 for (i = 0; i < 8; i++)
505                 {
506                         yy = y + ddy_cdd[i];
507                         xx = x + ddx_cdd[i];
508                         update_local_illumination_aux(creature_ptr, yy, xx);
509                 }
510         }
511
512 #else /* COMPLEX_WALL_ILLUMINATION */
513
514         if ((y != creature_ptr->y) && (x != creature_ptr->x))
515         {
516                 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
517                 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
518                 update_local_illumination_aux(creature_ptr, yy, xx);
519         }
520         else if (x != creature_ptr->x) /* y == creature_ptr->y */
521         {
522                 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
523                 for (i = -1; i <= 1; i++)
524                 {
525                         yy = y + i;
526                         update_local_illumination_aux(creature_ptr, yy, xx);
527                 }
528         }
529         else if (y != creature_ptr->y) /* x == creature_ptr->x */
530         {
531                 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
532                 for (i = -1; i <= 1; i++)
533                 {
534                         xx = x + i;
535                         update_local_illumination_aux(creature_ptr, yy, xx);
536                 }
537         }
538         else /* Player's grid */
539         {
540                 for (i = 0; i < 8; i++)
541                 {
542                         yy = y + ddy_cdd[i];
543                         xx = x + ddx_cdd[i];
544                         update_local_illumination_aux(creature_ptr, yy, xx);
545                 }
546         }
547
548 #endif /* COMPLEX_WALL_ILLUMINATION */
549 }
550
551
552 /*!
553  * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
554  * @return 視覚に収められていないならTRUEを返す
555  * @details player_can_see_bold()関数の返り値の否定を返している。
556  */
557 bool no_lite(void)
558 {
559         return (!player_can_see_bold(p_ptr->y, p_ptr->x));
560 }
561
562 /*
563  * Place an attr/char pair at the given map coordinate, if legal.
564  */
565 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
566 {
567         /* Only do "legal" locations */
568         if (panel_contains(y, x))
569         {
570                 /* Hack -- fake monochrome */
571                 if (!use_graphics)
572                 {
573                         if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
574                         else if (IS_INVULN(p_ptr) || p_ptr->timewalk) a = TERM_WHITE;
575                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
576                 }
577
578                 /* Draw the char using the attr */
579                 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
580         }
581 }
582
583
584 /*
585  * Memorize interesting viewable object/features in the given grid
586  *
587  * This function should only be called on "legal" grids.
588  *
589  * This function will memorize the object and/or feature in the given
590  * grid, if they are (1) viewable and (2) interesting.  Note that all
591  * objects are interesting, all terrain features except floors (and
592  * invisible traps) are interesting, and floors (and invisible traps)
593  * are interesting sometimes (depending on various options involving
594  * the illumination of floor grids).
595  *
596  * The automatic memorization of all objects and non-floor terrain
597  * features as soon as they are displayed allows incredible amounts
598  * of optimization in various places, especially "map_info()".
599  *
600  * Note that the memorization of objects is completely separate from
601  * the memorization of terrain features, preventing annoying floor
602  * memorization when a detected object is picked up from a dark floor,
603  * and object memorization when an object is dropped into a floor grid
604  * which is memorized but out-of-sight.
605  *
606  * This function should be called every time the "memorization" of
607  * a grid (or the object in a grid) is called into question, such
608  * as when an object is created in a grid, when a terrain feature
609  * "changes" from "floor" to "non-floor", when any grid becomes
610  * "illuminated" or "viewable", and when a "floor" grid becomes
611  * "torch-lit".
612  *
613  * Note the relatively efficient use of this function by the various
614  * "update_view()" and "update_lite()" calls, to allow objects and
615  * terrain features to be memorized (and drawn) whenever they become
616  * viewable or illuminated in any way, but not when they "maintain"
617  * or "lose" their previous viewability or illumination.
618  *
619  * Note the butchered "internal" version of "player_can_see_bold()",
620  * optimized primarily for the most common cases, that is, for the
621  * non-marked floor grids.
622  */
623 void note_spot(POSITION y, POSITION x)
624 {
625         grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
626         OBJECT_IDX this_o_idx, next_o_idx = 0;
627
628         /* Blind players see nothing */
629         if (p_ptr->blind) return;
630
631         /* Analyze non-torch-lit grids */
632         if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
633         {
634                 /* Require line of sight to the grid */
635                 if (!(g_ptr->info & (CAVE_VIEW))) return;
636
637                 /* Require "perma-lite" of the grid */
638                 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
639                 {
640                         /* Not Ninja */
641                         if (!p_ptr->see_nocto) return;
642                 }
643         }
644
645
646         /* Hack -- memorize objects */
647         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
648         {
649                 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
650                 next_o_idx = o_ptr->next_o_idx;
651
652                 /* Memorize objects */
653                 o_ptr->marked |= OM_FOUND;
654         }
655
656
657         /* Hack -- memorize grids */
658         if (!(g_ptr->info & (CAVE_MARK)))
659         {
660                 /* Feature code (applying "mimic" field) */
661                 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
662
663                 /* Memorize some "boring" grids */
664                 if (!have_flag(f_ptr->flags, FF_REMEMBER))
665                 {
666                         /* Option -- memorize all torch-lit floors */
667                         if (view_torch_grids &&
668                                 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
669                         {
670                                 g_ptr->info |= (CAVE_MARK);
671                         }
672
673                         /* Option -- memorize all perma-lit floors */
674                         else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
675                         {
676                                 g_ptr->info |= (CAVE_MARK);
677                         }
678                 }
679
680                 /* Memorize normal grids */
681                 else if (have_flag(f_ptr->flags, FF_LOS))
682                 {
683                         g_ptr->info |= (CAVE_MARK);
684                 }
685
686                 /* Memorize torch-lit walls */
687                 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
688                 {
689                         g_ptr->info |= (CAVE_MARK);
690                 }
691
692                 /* Memorize walls seen by noctovision of Ninja */
693                 else if (p_ptr->see_nocto)
694                 {
695                         g_ptr->info |= (CAVE_MARK);
696                 }
697
698                 /* Memorize certain non-torch-lit wall grids */
699                 else if (check_local_illumination(p_ptr, y, x))
700                 {
701                         g_ptr->info |= (CAVE_MARK);
702                 }
703         }
704
705         /* Memorize terrain of the grid */
706         g_ptr->info |= (CAVE_KNOWN);
707 }
708
709 /*
710  * Redraw (on the screen) a given MAP location
711  *
712  * This function should only be called on "legal" grids
713  */
714 void lite_spot(POSITION y, POSITION x)
715 {
716         /* Redraw if on screen */
717         if (panel_contains(y, x) && in_bounds2(p_ptr->current_floor_ptr, y, x))
718         {
719                 TERM_COLOR a;
720                 SYMBOL_CODE c;
721                 TERM_COLOR ta;
722                 SYMBOL_CODE tc;
723
724                 map_info(y, x, &a, &c, &ta, &tc);
725
726                 /* Hack -- fake monochrome */
727                 if (!use_graphics)
728                 {
729                         if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
730                         else if (IS_INVULN(p_ptr) || p_ptr->timewalk) a = TERM_WHITE;
731                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
732                 }
733
734                 /* Hack -- Queue it */
735                 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
736
737                 /* Update sub-windows */
738                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
739         }
740 }
741
742 /*
743  * Some comments on the grid flags.  -BEN-
744  *
745  *
746  * One of the major bottlenecks in previous versions of Angband was in
747  * the calculation of "line of sight" from the player to various grids,
748  * such as monsters.  This was such a nasty bottleneck that a lot of
749  * silly things were done to reduce the dependancy on "line of sight",
750  * for example, you could not "see" any grids in a lit room until you
751  * actually entered the room, and there were all kinds of bizarre grid
752  * flags to enable this behavior.  This is also why the "call light"
753  * spells always lit an entire room.
754  *
755  * The code below provides functions to calculate the "field of view"
756  * for the player, which, once calculated, provides extremely fast
757  * calculation of "line of sight from the player", and to calculate
758  * the "field of torch lite", which, again, once calculated, provides
759  * extremely fast calculation of "which grids are lit by the player's
760  * lite source".  In addition to marking grids as "GRID_VIEW" and/or
761  * "GRID_LITE", as appropriate, these functions maintain an array for
762  * each of these two flags, each array containing the locations of all
763  * of the grids marked with the appropriate flag, which can be used to
764  * very quickly scan through all of the grids in a given set.
765  *
766  * To allow more "semantically valid" field of view semantics, whenever
767  * the field of view (or the set of torch lit grids) changes, all of the
768  * grids in the field of view (or the set of torch lit grids) are "drawn"
769  * so that changes in the world will become apparent as soon as possible.
770  * This has been optimized so that only grids which actually "change" are
771  * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
772  * of the grids which are entering or leaving the relevent set of grids.
773  *
774  * These new methods are so efficient that the old nasty code was removed.
775  *
776  * Note that there is no reason to "update" the "viewable space" unless
777  * the player "moves", or walls/doors are created/destroyed, and there
778  * is no reason to "update" the "torch lit grids" unless the field of
779  * view changes, or the "light radius" changes.  This means that when
780  * the player is resting, or digging, or doing anything that does not
781  * involve movement or changing the state of the dungeon, there is no
782  * need to update the "view" or the "lite" regions, which is nice.
783  *
784  * Note that the calls to the nasty "los()" function have been reduced
785  * to a bare minimum by the use of the new "field of view" calculations.
786  *
787  * I wouldn't be surprised if slight modifications to the "update_view()"
788  * function would allow us to determine "reverse line-of-sight" as well
789  * as "normal line-of-sight", which would allow monsters to use a more
790  * "correct" calculation to determine if they can "see" the player.  For
791  * now, monsters simply "cheat" somewhat and assume that if the player
792  * has "line of sight" to the monster, then the monster can "pretend"
793  * that it has "line of sight" to the player.
794  *
795  *
796  * The "update_lite()" function maintains the "CAVE_LITE" flag for each
797  * grid and maintains an array of all "CAVE_LITE" grids.
798  *
799  * This set of grids is the complete set of all grids which are lit by
800  * the players light source, which allows the "player_can_see_bold()"
801  * function to work very quickly.
802  *
803  * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
804  * fact, the player (unless blind) can always "see" all grids which are
805  * marked as "CAVE_LITE", unless they are "off screen".
806  *
807  *
808  * The "update_view()" function maintains the "CAVE_VIEW" flag for each
809  * grid and maintains an array of all "CAVE_VIEW" grids.
810  *
811  * This set of grids is the complete set of all grids within line of sight
812  * of the player, allowing the "player_has_los_bold(p_ptr, )" macro to work very
813  * quickly.
814  *
815  *
816  * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
817  * temporary internal flag to mark those grids which are not only in view,
818  * but which are also "easily" in line of sight of the player.  This flag
819  * is always cleared when we are done.
820  *
821  *
822  * The current "update_lite()" and "update_view()" algorithms use the
823  * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
824  * to keep track of which grids were previously marked as "CAVE_LITE" or
825  * "CAVE_VIEW", which allows us to optimize the "screen updates".
826  *
827  * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
828  * for various other purposes, such as spreading lite or darkness during
829  * "lite_room()" / "unlite_room()", and for calculating monster flow.
830  *
831  *
832  * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
833  * in some way permanently lit.  However, for the player to "see" anything
834  * in the grid, as determined by "player_can_see()", the player must not be
835  * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
836  * grids, even if marked as "perma lit", are only illuminated if they touch
837  * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
838  *
839  *
840  * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
841  * that even if the player cannot "see" the grid, he "knows" the terrain in
842  * that grid.  This is used to "remember" walls/doors/stairs/floors when they
843  * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite(p_ptr, )",
844  * or when one of the "memorize floor grids" options induces memorization.
845  *
846  * Objects are "memorized" in a different way, using a special "marked" flag
847  * on the object itself, which is set when an object is observed or detected.
848  *
849  *
850  * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
851  * and should be illuminated by "lite room" and "darkness" spells.
852  *
853  *
854  * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
855  * and should be unavailable for "teleportation" destinations.
856  *
857  *
858  * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
859  * which is observed, and the "view_torch_grids" allows the player to memorize
860  * every torch-lit grid.  The player will always memorize important walls,
861  * doors, stairs, and other terrain features, as well as any "detected" grids.
862  *
863  * Note that the new "update_view()" method allows, among other things, a room
864  * to be "partially" seen as the player approaches it, with a growing cone of
865  * floor appearing as the player gets closer to the door.  Also, by not turning
866  * on the "memorize perma-lit grids" option, the player will only "see" those
867  * floor grids which are actually in line of sight.
868  *
869  * And my favorite "plus" is that you can now use a special option to draw the
870  * "floors" in the "viewable region" brightly (actually, to draw the *other*
871  * grids dimly), providing a "pretty" effect as the player runs around, and
872  * to efficiently display the "torch lite" in a special color.
873  *
874  *
875  * Some comments on the "update_view()" algorithm...
876  *
877  * The algorithm is very fast, since it spreads "obvious" grids very quickly,
878  * and only has to call "los()" on the borderline cases.  The major axes/diags
879  * even terminate early when they hit walls.  I need to find a quick way
880  * to "terminate" the other scans.
881  *
882  * Note that in the worst case (a big empty area with say 5% scattered walls),
883  * each of the 1500 or so nearby grids is checked once, most of them getting
884  * an "instant" rating, and only a small portion requiring a call to "los()".
885  *
886  * The only time that the algorithm appears to be "noticeably" too slow is
887  * when running, and this is usually only important in town, since the town
888  * provides about the worst scenario possible, with large open regions and
889  * a few scattered obstructions.  There is a special "efficiency" option to
890  * allow the player to reduce his field of view in town, if needed.
891  *
892  * In the "best" case (say, a normal stretch of corridor), the algorithm
893  * makes one check for each viewable grid, and makes no calls to "los()".
894  * So running in corridors is very fast, and if a lot of monsters are
895  * nearby, it is much faster than the old methods.
896  *
897  * Note that resting, most normal commands, and several forms of running,
898  * plus all commands executed near large groups of monsters, are strictly
899  * more efficient with "update_view()" that with the old "compute los() on
900  * demand" method, primarily because once the "field of view" has been
901  * calculated, it does not have to be recalculated until the player moves
902  * (or a wall or door is created or destroyed).
903  *
904  * Note that we no longer have to do as many "los()" checks, since once the
905  * "view" region has been built, very few things cause it to be "changed"
906  * (player movement, and the opening/closing of doors, changes in wall status).
907  * Note that door/wall changes are only relevant when the door/wall itself is
908  * in the "view" region.
909  *
910  * The algorithm seems to only call "los()" from zero to ten times, usually
911  * only when coming down a corridor into a room, or standing in a room, just
912  * misaligned with a corridor.  So if, say, there are five "nearby" monsters,
913  * we will be reducing the calls to "los()".
914  *
915  * I am thinking in terms of an algorithm that "walks" from the central point
916  * out to the maximal "distance", at each point, determining the "view" code
917  * (above).  For each grid not on a major axis or diagonal, the "view" code
918  * depends on the "cave_los_bold(p_ptr->current_floor_ptr, )" and "view" of exactly two other grids
919  * (the one along the nearest diagonal, and the one next to that one, see
920  * "update_view_aux()"...).
921  *
922  * We "memorize" the viewable space array, so that at the cost of under 3000
923  * bytes, we reduce the time taken by "forget_view()" to one assignment for
924  * each grid actually in the "viewable space".  And for another 3000 bytes,
925  * we prevent "erase + redraw" ineffiencies via the "seen" set.  These bytes
926  * are also used by other routines, thus reducing the cost to almost nothing.
927  *
928  * A similar thing is done for "forget_lite()" in which case the savings are
929  * much less, but save us from doing bizarre maintenance checking.
930  *
931  * In the worst "normal" case (in the middle of the town), the reachable space
932  * actually reaches to more than half of the largest possible "circle" of view,
933  * or about 800 grids, and in the worse case (in the middle of a dungeon level
934  * where all the walls have been removed), the reachable space actually reaches
935  * the theoretical maximum size of just under 1500 grids.
936  *
937  * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
938  * If G1 is lite, G is lite.  Else if G2 is lite, G is half.  Else if G1 and G2
939  * are both half, G is half.  Else G is dark.  It only takes 2 (or 4) bits to
940  * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
941  * entire possible space (including initialization) in one step per grid.  If
942  * we do the "clearing" as a separate step (and use an array of "view" grids),
943  * then the clearing will take as many steps as grids that were viewed, and the
944  * algorithm will be able to "stop" scanning at various points.
945  * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
946  */
947
948 /*
949  * Mega-Hack -- Delayed visual update
950  * Only used if update_view(), update_lite() or update_mon_lite() was called
951  */
952 void delayed_visual_update(void)
953 {
954         int i;
955         POSITION y, x;
956         grid_type *g_ptr;
957
958         /* Update needed grids */
959         for (i = 0; i < p_ptr->current_floor_ptr->redraw_n; i++)
960         {
961                 y = p_ptr->current_floor_ptr->redraw_y[i];
962                 x = p_ptr->current_floor_ptr->redraw_x[i];
963                 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
964
965                 /* Update only needed grids (prevent multiple updating) */
966                 if (!(g_ptr->info & CAVE_REDRAW)) continue;
967
968                 /* If required, note */
969                 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
970
971                 lite_spot(y, x);
972
973                 /* Hack -- Visual update of monster on this grid */
974                 if (g_ptr->m_idx) update_monster(p_ptr, g_ptr->m_idx, FALSE);
975
976                 /* No longer in the array */
977                 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
978         }
979
980         /* None left */
981         p_ptr->current_floor_ptr->redraw_n = 0;
982 }
983
984
985 /*
986  * Hack - speed up the update_flow algorithm by only doing
987  * it everytime the player moves out of LOS of the last
988  * "way-point".
989  */
990 static POSITION flow_x = 0;
991 static POSITION flow_y = 0;
992
993
994
995 /*
996  * Hack -- fill in the "cost" field of every grid that the player
997  * can "reach" with the number of steps needed to reach that grid.
998  * This also yields the "distance" of the player from every grid.
999  *
1000  * In addition, mark the "when" of the grids that can reach
1001  * the player with the incremented value of "flow_n".
1002  *
1003  * Hack -- use the "seen" array as a "circular queue".
1004  *
1005  * We do not need a priority queue because the cost from grid
1006  * to grid is always "one" and we process them in order.
1007  */
1008 void update_flow(player_type *subject_ptr)
1009 {
1010         POSITION x, y;
1011         DIRECTION d;
1012         int flow_head = 1;
1013         int flow_tail = 0;
1014
1015         /* Paranoia -- make sure the array is empty */
1016         if (tmp_pos.n) return;
1017
1018         /* The last way-point is on the map */
1019         if (subject_ptr->running && in_bounds(subject_ptr->current_floor_ptr, flow_y, flow_x))
1020         {
1021                 /* The way point is in sight - do not update.  (Speedup) */
1022                 if (subject_ptr->current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
1023         }
1024
1025         /* Erase all of the current flow information */
1026         for (y = 0; y < subject_ptr->current_floor_ptr->height; y++)
1027         {
1028                 for (x = 0; x < subject_ptr->current_floor_ptr->width; x++)
1029                 {
1030                         subject_ptr->current_floor_ptr->grid_array[y][x].cost = 0;
1031                         subject_ptr->current_floor_ptr->grid_array[y][x].dist = 0;
1032                 }
1033         }
1034
1035         /* Save player position */
1036         flow_y = subject_ptr->y;
1037         flow_x = subject_ptr->x;
1038
1039         /* Add the player's grid to the queue */
1040         tmp_pos.y[0] = subject_ptr->y;
1041         tmp_pos.x[0] = subject_ptr->x;
1042
1043         /* Now process the queue */
1044         while (flow_head != flow_tail)
1045         {
1046                 int ty, tx;
1047
1048                 /* Extract the next entry */
1049                 ty = tmp_pos.y[flow_tail];
1050                 tx = tmp_pos.x[flow_tail];
1051
1052                 /* Forget that entry */
1053                 if (++flow_tail == TEMP_MAX) flow_tail = 0;
1054
1055                 /* Add the "children" */
1056                 for (d = 0; d < 8; d++)
1057                 {
1058                         int old_head = flow_head;
1059                         byte_hack m = subject_ptr->current_floor_ptr->grid_array[ty][tx].cost + 1;
1060                         byte_hack n = subject_ptr->current_floor_ptr->grid_array[ty][tx].dist + 1;
1061                         grid_type *g_ptr;
1062
1063                         /* Child location */
1064                         y = ty + ddy_ddd[d];
1065                         x = tx + ddx_ddd[d];
1066
1067                         /* Ignore player's grid */
1068                         if (player_bold(subject_ptr, y, x)) continue;
1069
1070                         g_ptr = &subject_ptr->current_floor_ptr->grid_array[y][x];
1071
1072                         if (is_closed_door(g_ptr->feat)) m += 3;
1073
1074                         /* Ignore "pre-stamped" entries */
1075                         if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
1076
1077                         /* Ignore "walls" and "rubble" */
1078                         if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1079
1080                         /* Save the flow cost */
1081                         if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
1082                         if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
1083
1084                         /* Hack -- limit flow depth */
1085                         if (n == MONSTER_FLOW_DEPTH) continue;
1086
1087                         /* Enqueue that entry */
1088                         tmp_pos.y[flow_head] = y;
1089                         tmp_pos.x[flow_head] = x;
1090
1091                         /* Advance the queue */
1092                         if (++flow_head == TEMP_MAX) flow_head = 0;
1093
1094                         /* Hack -- notice overflow by forgetting new entry */
1095                         if (flow_head == flow_tail) flow_head = old_head;
1096                 }
1097         }
1098 }
1099
1100 /*
1101  * Take a feature, determine what that feature becomes
1102  * through applying the given action.
1103  */
1104 FEAT_IDX feat_state(FEAT_IDX feat, int action)
1105 {
1106         feature_type *f_ptr = &f_info[feat];
1107         int i;
1108
1109         /* Get the new feature */
1110         for (i = 0; i < MAX_FEAT_STATES; i++)
1111         {
1112                 if (f_ptr->state[i].action == action) return conv_dungeon_feat(p_ptr->current_floor_ptr, f_ptr->state[i].result);
1113         }
1114
1115         if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
1116
1117         return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(p_ptr->current_floor_ptr, f_ptr->destroyed) : feat;
1118 }
1119
1120 /*
1121  * Takes a location and action and changes the feature at that
1122  * location through applying the given action.
1123  */
1124 void cave_alter_feat(POSITION y, POSITION x, int action)
1125 {
1126         /* Set old feature */
1127         FEAT_IDX oldfeat = p_ptr->current_floor_ptr->grid_array[y][x].feat;
1128
1129         /* Get the new feat */
1130         FEAT_IDX newfeat = feat_state(oldfeat, action);
1131
1132         /* No change */
1133         if (newfeat == oldfeat) return;
1134
1135         /* Set the new feature */
1136         cave_set_feat(p_ptr->current_floor_ptr, y, x, newfeat);
1137
1138         if (!(feature_action_flags[action] & FAF_NO_DROP))
1139         {
1140                 feature_type *old_f_ptr = &f_info[oldfeat];
1141                 feature_type *f_ptr = &f_info[newfeat];
1142                 bool found = FALSE;
1143
1144                 /* Handle gold */
1145                 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
1146                 {
1147                         /* Place some gold */
1148                         place_gold(y, x);
1149                         found = TRUE;
1150                 }
1151
1152                 /* Handle item */
1153                 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - p_ptr->current_floor_ptr->dun_level / 2)))
1154                 {
1155                         /* Place object */
1156                         place_object(y, x, 0L);
1157                         found = TRUE;
1158                 }
1159
1160                 if (found && current_world_ptr->character_dungeon && player_can_see_bold(y, x))
1161                 {
1162                         msg_print(_("何かを発見した!", "You have found something!"));
1163                 }
1164         }
1165
1166         if (feature_action_flags[action] & FAF_CRASH_GLASS)
1167         {
1168                 feature_type *old_f_ptr = &f_info[oldfeat];
1169
1170                 if (have_flag(old_f_ptr->flags, FF_GLASS) && current_world_ptr->character_dungeon)
1171                 {
1172                         project(p_ptr, PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(p_ptr->current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
1173                                 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
1174                 }
1175         }
1176 }
1177
1178
1179 /* Remove a mirror */
1180 void remove_mirror(POSITION y, POSITION x)
1181 {
1182         grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1183
1184         /* Remove the mirror */
1185         g_ptr->info &= ~(CAVE_OBJECT);
1186         g_ptr->mimic = 0;
1187
1188         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
1189         {
1190                 g_ptr->info &= ~(CAVE_GLOW);
1191                 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1192                 if (g_ptr->m_idx) update_monster(p_ptr, g_ptr->m_idx, FALSE);
1193
1194                 update_local_illumination(p_ptr, y, x);
1195         }
1196
1197         note_spot(y, x);
1198
1199         lite_spot(y, x);
1200 }
1201
1202
1203 /*
1204  *  Return TRUE if there is a mirror on the grid.
1205  */
1206 bool is_mirror_grid(grid_type *g_ptr)
1207 {
1208         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
1209                 return TRUE;
1210         else
1211                 return FALSE;
1212 }
1213
1214
1215 /*
1216  *  Return TRUE if there is a mirror on the grid.
1217  */
1218 bool is_glyph_grid(grid_type *g_ptr)
1219 {
1220         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
1221                 return TRUE;
1222         else
1223                 return FALSE;
1224 }
1225
1226
1227 /*
1228  *  Return TRUE if there is a mirror on the grid.
1229  */
1230 bool is_explosive_rune_grid(grid_type *g_ptr)
1231 {
1232         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
1233                 return TRUE;
1234         else
1235                 return FALSE;
1236 }
1237
1238 /*!
1239 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
1240 * @param m_idx モンスターID
1241 * @param y 移動先Y座標
1242 * @param x 移動先X座標
1243 * @param mode オプション
1244 * @return テレポート先として妥当ならばtrue
1245 */
1246 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
1247 {
1248         monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
1249         grid_type    *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1250         feature_type *f_ptr = &f_info[g_ptr->feat];
1251
1252         /* Require "teleportable" space */
1253         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
1254
1255         if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
1256         if (player_bold(p_ptr, y, x)) return FALSE;
1257
1258         /* Hack -- no teleport onto glyph of warding */
1259         if (is_glyph_grid(g_ptr)) return FALSE;
1260         if (is_explosive_rune_grid(g_ptr)) return FALSE;
1261
1262         if (!(mode & TELEPORT_PASSIVE))
1263         {
1264                 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
1265         }
1266
1267         return TRUE;
1268 }
1269
1270 /*!
1271 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
1272 * @param y 移動先Y座標
1273 * @param x 移動先X座標
1274 * @param mode オプション
1275 * @return テレポート先として妥当ならばtrue
1276 */
1277 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
1278 {
1279         grid_type    *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1280         feature_type *f_ptr = &f_info[g_ptr->feat];
1281
1282         /* Require "teleportable" space */
1283         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
1284
1285         /* No magical teleporting into vaults and such */
1286         if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
1287
1288         if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
1289
1290         /* don't teleport on a trap. */
1291         if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
1292
1293         if (!(mode & TELEPORT_PASSIVE))
1294         {
1295                 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
1296
1297                 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
1298                 {
1299                         if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
1300                 }
1301
1302                 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN(p_ptr))
1303                 {
1304                         /* Always forbid deep lava */
1305                         if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
1306
1307                         /* Forbid shallow lava when the player don't have levitation */
1308                         if (!p_ptr->levitation) return FALSE;
1309                 }
1310
1311         }
1312
1313         return TRUE;
1314 }
1315
1316 /*!
1317  * @brief 地形は開くものであって、かつ開かれているかを返す /
1318  * Attempt to open the given chest at the given location
1319  * @param feat 地形ID
1320  * @return 開いた地形である場合TRUEを返す /  Return TRUE if the given feature is an open door
1321  */
1322 bool is_open(FEAT_IDX feat)
1323 {
1324         return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
1325 }
1326
1327 /*!
1328  * @brief プレイヤーが地形踏破可能かを返す
1329  * @param feature 判定したい地形ID
1330  * @param mode 移動に関するオプションフラグ
1331  * @return 移動可能ならばTRUEを返す
1332  */
1333 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
1334 {
1335         feature_type *f_ptr = &f_info[feature];
1336
1337         if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[p_ptr->current_floor_ptr->m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
1338
1339         if (have_flag(f_ptr->flags, FF_PATTERN))
1340         {
1341                 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
1342         }
1343
1344         if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
1345         if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
1346         if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
1347
1348         if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;
1349
1350         return TRUE;
1351 }
1352