OSDN Git Service

7a14619ff0443b7ddbb3dd4d5c5bda510004b183
[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
238 /*!
239  * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
240  * @param y ドアの配置を試みたいマスのY座標
241  * @param x ドアの配置を試みたいマスのX座標
242  * @param room 部屋に接している場合向けのドア生成か否か
243  * @return なし
244  */
245 void place_random_door(POSITION y, POSITION x, bool room)
246 {
247         int tmp, type;
248         FEAT_IDX feat = feat_none;
249         grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
250
251         /* Initialize mimic info */
252         g_ptr->mimic = 0;
253
254         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
255         {
256                 place_floor_bold(p_ptr->current_floor_ptr, y, x);
257                 return;
258         }
259
260         type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
261                 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
262                 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
263
264         /* Choose an object */
265         tmp = randint0(1000);
266
267         /* Open doors (300/1000) */
268         if (tmp < 300)
269         {
270                 /* Create open door */
271                 feat = feat_door[type].open;
272         }
273
274         /* Broken doors (100/1000) */
275         else if (tmp < 400)
276         {
277                 /* Create broken door */
278                 feat = feat_door[type].broken;
279         }
280
281         /* Secret doors (200/1000) */
282         else if (tmp < 600)
283         {
284                 /* Create secret door */
285                 place_closed_door(y, x, type);
286
287                 if (type != DOOR_CURTAIN)
288                 {
289                         /* Hide. If on the edge of room, use outer wall. */
290                         g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
291
292                         /* Floor type terrain cannot hide a door */
293                         if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
294                         {
295                                 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
296                                 {
297                                         g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
298                                 }
299                                 g_ptr->mimic = 0;
300                         }
301                 }
302         }
303
304         /* Closed, locked, or stuck doors (400/1000) */
305         else place_closed_door(y, x, type);
306
307         if (tmp < 400)
308         {
309                 if (feat != feat_none)
310                 {
311                         set_cave_feat(p_ptr->current_floor_ptr, y, x, feat);
312                 }
313                 else
314                 {
315                         place_floor_bold(p_ptr->current_floor_ptr, y, x);
316                 }
317         }
318
319         delete_monster(y, x);
320 }
321
322 /*!
323  * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
324  * @param y ドアの配置を試みたいマスのY座標
325  * @param x ドアの配置を試みたいマスのX座標
326  * @param type ドアの地形ID
327  * @return なし
328  */
329 void place_closed_door(POSITION y, POSITION x, int type)
330 {
331         int tmp;
332         FEAT_IDX feat = feat_none;
333
334         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
335         {
336                 place_floor_bold(p_ptr->current_floor_ptr, y, x);
337                 return;
338         }
339
340         /* Choose an object */
341         tmp = randint0(400);
342
343         /* Closed doors (300/400) */
344         if (tmp < 300)
345         {
346                 /* Create closed door */
347                 feat = feat_door[type].closed;
348         }
349
350         /* Locked doors (99/400) */
351         else if (tmp < 399)
352         {
353                 /* Create locked door */
354                 feat = feat_locked_door_random(type);
355         }
356
357         /* Stuck doors (1/400) */
358         else
359         {
360                 /* Create jammed door */
361                 feat = feat_jammed_door_random(type);
362         }
363
364         if (feat != feat_none)
365         {
366                 cave_set_feat(y, x, feat);
367
368                 /* Now it is not floor */
369                 p_ptr->current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
370         }
371         else
372         {
373                 place_floor_bold(p_ptr->current_floor_ptr, y, x);
374         }
375 }
376
377 /*!
378 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
379 * @param y1 基準となるマスのY座標
380 * @param x1 基準となるマスのX座標
381 * @return 通路の数
382 * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y1, x1)"
383 * @details
384 * XXX XXX This routine currently only counts actual "empty floor"\n
385 * grids which are not in rooms.  We might want to also count stairs,\n
386 * open doors, closed doors, etc.
387 */
388 static int next_to_corr(POSITION y1, POSITION x1)
389 {
390         int i, k = 0;
391         POSITION y, x;
392
393         grid_type *g_ptr;
394
395         /* Scan adjacent grids */
396         for (i = 0; i < 4; i++)
397         {
398                 y = y1 + ddy_ddd[i];
399                 x = x1 + ddx_ddd[i];
400                 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
401
402                 /* Skip non floors */
403                 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
404
405                 /* Skip non "empty floor" grids */
406                 if (!is_floor_grid(g_ptr))
407                         continue;
408
409                 /* Skip grids inside rooms */
410                 if (g_ptr->info & (CAVE_ROOM)) continue;
411
412                 /* Count these grids */
413                 k++;
414         }
415
416         /* Return the number of corridors */
417         return (k);
418 }
419
420 /*!
421 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
422 * @param y 判定を行いたいマスのY座標
423 * @param x 判定を行いたいマスのX座標
424 * @return ドアを設置可能ならばTRUEを返す
425 * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y1, x1)"
426 * @details
427 * \n
428 * Assumes "in_bounds(p_ptr->current_floor_ptr, y, x)"\n
429 */
430 static bool possible_doorway(POSITION y, POSITION x)
431 {
432         /* Count the adjacent corridors */
433         if (next_to_corr(y, x) >= 2)
434         {
435                 /* Check Vertical */
436                 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
437                         cave_have_flag_bold(y + 1, x, FF_WALL))
438                 {
439                         return (TRUE);
440                 }
441
442                 /* Check Horizontal */
443                 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
444                         cave_have_flag_bold(y, x + 1, FF_WALL))
445                 {
446                         return (TRUE);
447                 }
448         }
449
450         /* No doorway */
451         return (FALSE);
452 }
453
454 /*!
455 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
456 * @param y 設置を行いたいマスのY座標
457 * @param x 設置を行いたいマスのX座標
458 * @return なし
459 */
460 void try_door(POSITION y, POSITION x)
461 {       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
462
463         /* Ignore walls */
464         if (cave_have_flag_bold(y, x, FF_WALL)) return;
465
466         /* Ignore room grids */
467         if (p_ptr->current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
468
469         /* Occasional door (if allowed) */
470         if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
471         {
472                 /* Place a door */
473                 place_random_door(y, x, FALSE);
474         }
475 }
476
477
478 /*!
479  * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
480  * @param x1 長方形の左端X座標(-1)
481  * @param x2 長方形の右端X座標(+1)
482  * @param y1 長方形の上端Y座標(-1)
483  * @param y2 長方形の下端Y座標(+1)
484  * @param light 照明の有無
485  * @return なし
486  */
487 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
488 {
489         POSITION x, y;
490
491         /* Place a full floor under the room */
492         for (y = y1 - 1; y <= y2 + 1; y++)
493         {
494                 for (x = x1 - 1; x <= x2 + 1; x++)
495                 {
496                         place_floor_bold(p_ptr->current_floor_ptr, y, x);
497                         add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_ROOM);
498                         if (light) add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_GLOW);
499                 }
500         }
501 }
502
503
504 /*!
505  * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
506  * @param x1 長方形の左端X座標(-1)
507  * @param x2 長方形の右端X座標(+1)
508  * @param y1 長方形の上端Y座標(-1)
509  * @param y2 長方形の下端Y座標(+1)
510  * @param light 照明の有無
511  * @return なし
512  */
513 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
514 {
515         POSITION y, x;
516
517         place_floor(x1, x2, y1, y2, light);
518
519         /* Walls around the room */
520         for (y = y1 - 1; y <= y2 + 1; y++)
521         {
522                 place_outer_bold(y, x1 - 1);
523                 place_outer_bold(y, x2 + 1);
524         }
525         for (x = x1 - 1; x <= x2 + 1; x++)
526         {
527                 place_outer_bold(y1 - 1, x);
528                 place_outer_bold(y2 + 1, x);
529         }
530 }
531
532
533 /*!
534  * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
535  * @param y 配置したい中心マスのY座標
536  * @param x 配置したい中心マスのX座標
537  * @param num 配置したい数
538  * @return なし
539  * @details
540  * Only really called by some of the "vault" routines.
541  */
542 void vault_objects(POSITION y, POSITION x, int num)
543 {
544         int dummy = 0;
545         int i = 0, j = y, k = x;
546
547         grid_type *g_ptr;
548
549
550         /* Attempt to place 'num' objects */
551         for (; num > 0; --num)
552         {
553                 /* Try up to 11 spots looking for empty space */
554                 for (i = 0; i < 11; ++i)
555                 {
556                         /* Pick a random location */
557                         while (dummy < SAFE_MAX_ATTEMPTS)
558                         {
559                                 j = rand_spread(y, 2);
560                                 k = rand_spread(x, 3);
561                                 dummy++;
562                                 if (!in_bounds(p_ptr->current_floor_ptr, j, k)) continue;
563                                 break;
564                         }
565
566                         if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
567                         {
568                                 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
569                         }
570
571                         /* Require "clean" floor space */
572                         g_ptr = &p_ptr->current_floor_ptr->grid_array[j][k];
573                         if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
574
575                         if (randint0(100) < 75)
576                         {
577                                 place_object(j, k, 0L);
578                         }
579                         else
580                         {
581                                 place_gold(j, k);
582                         }
583
584                         /* Placement accomplished */
585                         break;
586                 }
587         }
588 }
589
590 /*!
591  * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
592  * @param y トラップを配置したいマスの中心Y座標
593  * @param x トラップを配置したいマスの中心X座標
594  * @param yd Y方向の配置分散マス数
595  * @param xd X方向の配置分散マス数
596  * @return なし
597  * @details
598  * Only really called by some of the "vault" routines.
599  */
600 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
601 {
602         int count = 0, y1 = y, x1 = x;
603         int dummy = 0;
604
605         grid_type *g_ptr;
606
607         /* Place traps */
608         for (count = 0; count <= 5; count++)
609         {
610                 /* Get a location */
611                 while (dummy < SAFE_MAX_ATTEMPTS)
612                 {
613                         y1 = rand_spread(y, yd);
614                         x1 = rand_spread(x, xd);
615                         dummy++;
616                         if (!in_bounds(p_ptr->current_floor_ptr, y1, x1)) continue;
617                         break;
618                 }
619
620                 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
621                 {
622                         msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
623                 }
624
625                 /* Require "naked" floor grids */
626                 g_ptr = &p_ptr->current_floor_ptr->grid_array[y1][x1];
627                 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
628
629                 /* Place the trap */
630                 place_trap(p_ptr->current_floor_ptr, y1, x1);
631
632                 break;
633         }
634 }
635
636 /*!
637  * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
638  * @param y トラップを配置したいマスの中心Y座標
639  * @param x トラップを配置したいマスの中心X座標
640  * @param yd Y方向の配置分散マス数
641  * @param xd X方向の配置分散マス数
642  * @param num 配置したいトラップの数
643  * @return なし
644  * @details
645  * Only really called by some of the "vault" routines.
646  */
647 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
648 {
649         int i;
650
651         for (i = 0; i < num; i++)
652         {
653                 vault_trap_aux(y, x, yd, xd);
654         }
655 }
656
657 /*!
658  * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
659  * @param y1 モンスターを配置したいマスの中心Y座標
660  * @param x1 モンスターを配置したいマスの中心X座標
661  * @param num 配置したいモンスターの数
662  * @return なし
663  * @details
664  * Only really called by some of the "vault" routines.
665  */
666 void vault_monsters(POSITION y1, POSITION x1, int num)
667 {
668         int k, i;
669         POSITION y, x;
670         grid_type *g_ptr;
671
672         /* Try to summon "num" monsters "near" the given location */
673         for (k = 0; k < num; k++)
674         {
675                 /* Try nine locations */
676                 for (i = 0; i < 9; i++)
677                 {
678                         int d = 1;
679
680                         /* Pick a nearby location */
681                         scatter(&y, &x, y1, x1, d, 0);
682
683                         /* Require "empty" floor grids */
684                         g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
685                         if (!cave_empty_grid(g_ptr)) continue;
686
687                         /* Place the monster (allow groups) */
688                         p_ptr->current_floor_ptr->monster_level = p_ptr->current_floor_ptr->base_level + 2;
689                         (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
690                         p_ptr->current_floor_ptr->monster_level = p_ptr->current_floor_ptr->base_level;
691                 }
692         }
693 }
694
695 /*!
696  * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor.  (Includes range checking.)
697  * @param x チェックするマスのX座標
698  * @param y チェックするマスのY座標
699  * @return 床系地形ならばTRUE
700  */
701 bool get_is_floor(POSITION x, POSITION y)
702 {
703         if (!in_bounds(p_ptr->current_floor_ptr, y, x))
704         {
705                 /* Out of bounds */
706                 return (FALSE);
707         }
708
709         /* Do the real check */
710         if (is_floor_bold(p_ptr->current_floor_ptr, y, x)) return (TRUE);
711
712         return (FALSE);
713 }
714
715 /*!
716  * @brief 指定のマスを床地形に変える / Set a square to be floor.  (Includes range checking.)
717  * @param x 地形を変えたいマスのX座標
718  * @param y 地形を変えたいマスのY座標
719  * @return なし
720  */
721 void set_floor(POSITION x, POSITION y)
722 {
723         if (!in_bounds(p_ptr->current_floor_ptr, y, x))
724         {
725                 /* Out of bounds */
726                 return;
727         }
728
729         if (p_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
730         {
731                 /* A room border don't touch. */
732                 return;
733         }
734
735         /* Set to be floor if is a wall (don't touch lakes). */
736         if (is_extra_bold(p_ptr->current_floor_ptr, y, x))
737                 place_floor_bold(p_ptr->current_floor_ptr, y, x);
738 }
739
740 /*!
741  * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
742  * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
743  * @return なし
744  */
745 void place_bound_perm_wall(grid_type *g_ptr)
746 {
747         if (bound_walls_perm)
748         {
749                 /* Clear boundary mimic */
750                 g_ptr->mimic = 0;
751         }
752         else
753         {
754                 feature_type *f_ptr = &f_info[g_ptr->feat];
755
756                 /* Hack -- Decline boundary walls with known treasure  */
757                 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
758                         !have_flag(f_ptr->flags, FF_SECRET))
759                         g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
760
761                 /* Set boundary mimic */
762                 g_ptr->mimic = g_ptr->feat;
763         }
764
765         /* Add "solid" perma-wall */
766         place_solid_perm_grid(g_ptr);
767 }
768
769 /*!
770  * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
771  * @param g_ptr マス構造体の参照ポインタ
772  * @return 看破済みの罠があるならTRUEを返す。
773  */
774 bool is_known_trap(grid_type *g_ptr)
775 {
776         if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
777                 is_trap(g_ptr->feat)) return TRUE;
778         else
779                 return FALSE;
780 }
781
782
783
784 /*!
785  * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
786  * @param g_ptr マス構造体の参照ポインタ
787  * @return 隠されたドアがあるならTRUEを返す。
788  */
789 bool is_hidden_door(grid_type *g_ptr)
790 {
791         if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
792                 is_closed_door(g_ptr->feat))
793                 return TRUE;
794         else
795                 return FALSE;
796 }
797
798 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
799
800
801 /*!
802  * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
803  * @param y y座標
804  * @param x x座標
805  * @return 指定された座標に照明がかかっているならTRUEを返す。。
806  */
807 bool check_local_illumination(POSITION y, POSITION x)
808 {
809         /* Hack -- move towards player */
810         POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
811         POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
812
813         /* Check for "local" illumination */
814
815 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
816
817         /* Check for "complex" illumination */
818         if ((feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[yy][xx])) &&
819                 (p_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
820                 (feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[y][xx])) &&
821                 (p_ptr->current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
822                         (feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[yy][x])) &&
823                 (p_ptr->current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
824         {
825                 return TRUE;
826         }
827         else return FALSE;
828
829 #else /* COMPLEX_WALL_ILLUMINATION */
830
831         /* Check for "simple" illumination */
832         return (p_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
833
834 #endif /* COMPLEX_WALL_ILLUMINATION */
835 }
836
837
838 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
839 #define update_local_illumination_aux(C, Y, X) \
840 { \
841         if (player_has_los_bold((C), (Y), (X))) \
842         { \
843                 /* Update the monster */ \
844                 if ((C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster((C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
845 \
846                 /* Notice and redraw */ \
847                 note_spot((Y), (X)); \
848                 lite_spot((Y), (X)); \
849         } \
850 }
851
852 /*!
853  * @brief 指定された座標の照明状態を更新する / Update "local" illumination
854  * @param creature_ptr 視界元のクリーチャー
855  * @param y 視界先y座標
856  * @param x 視界先x座標
857  * @return なし
858  */
859 void update_local_illumination(player_type * creature_ptr, POSITION y, POSITION x)
860 {
861         int i;
862         POSITION yy, xx;
863
864         if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
865
866 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
867
868         if ((y != creature_ptr->y) && (x != creature_ptr->x))
869         {
870                 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
871                 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
872                 update_local_illumination_aux(creature_ptr, yy, xx);
873                 update_local_illumination_aux(creature_ptr, y, xx);
874                 update_local_illumination_aux(creature_ptr, yy, x);
875         }
876         else if (x != creature_ptr->x) /* y == creature_ptr->y */
877         {
878                 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
879                 for (i = -1; i <= 1; i++)
880                 {
881                         yy = y + i;
882                         update_local_illumination_aux(creature_ptr, yy, xx);
883                 }
884                 yy = y - 1;
885                 update_local_illumination_aux(creature_ptr, yy, x);
886                 yy = y + 1;
887                 update_local_illumination_aux(creature_ptr, yy, x);
888         }
889         else if (y != creature_ptr->y) /* x == creature_ptr->x */
890         {
891                 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
892                 for (i = -1; i <= 1; i++)
893                 {
894                         xx = x + i;
895                         update_local_illumination_aux(creature_ptr, yy, xx);
896                 }
897                 xx = x - 1;
898                 update_local_illumination_aux(creature_ptr, y, xx);
899                 xx = x + 1;
900                 update_local_illumination_aux(creature_ptr, y, xx);
901         }
902         else /* Player's grid */
903         {
904                 for (i = 0; i < 8; i++)
905                 {
906                         yy = y + ddy_cdd[i];
907                         xx = x + ddx_cdd[i];
908                         update_local_illumination_aux(creature_ptr, yy, xx);
909                 }
910         }
911
912 #else /* COMPLEX_WALL_ILLUMINATION */
913
914         if ((y != creature_ptr->y) && (x != creature_ptr->x))
915         {
916                 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
917                 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
918                 update_local_illumination_aux(creature_ptr, yy, xx);
919         }
920         else if (x != creature_ptr->x) /* y == creature_ptr->y */
921         {
922                 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
923                 for (i = -1; i <= 1; i++)
924                 {
925                         yy = y + i;
926                         update_local_illumination_aux(creature_ptr, yy, xx);
927                 }
928         }
929         else if (y != creature_ptr->y) /* x == creature_ptr->x */
930         {
931                 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
932                 for (i = -1; i <= 1; i++)
933                 {
934                         xx = x + i;
935                         update_local_illumination_aux(creature_ptr, yy, xx);
936                 }
937         }
938         else /* Player's grid */
939         {
940                 for (i = 0; i < 8; i++)
941                 {
942                         yy = y + ddy_cdd[i];
943                         xx = x + ddx_cdd[i];
944                         update_local_illumination_aux(creature_ptr, yy, xx);
945                 }
946         }
947
948 #endif /* COMPLEX_WALL_ILLUMINATION */
949 }
950
951
952 /*!
953  * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
954  * @return 視覚に収められていないならTRUEを返す
955  * @details player_can_see_bold()関数の返り値の否定を返している。
956  */
957 bool no_lite(void)
958 {
959         return (!player_can_see_bold(p_ptr->y, p_ptr->x));
960 }
961
962
963 /*!
964  * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
965  * @param y y座標
966  * @param x x座標
967  * @return 各種の変更が可能ならTRUEを返す。
968  * @details
969  * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
970  */
971 bool cave_valid_bold(POSITION y, POSITION x)
972 {
973         grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
974         OBJECT_IDX this_o_idx, next_o_idx = 0;
975
976         /* Forbid perma-grids */
977         if (cave_perma_grid(g_ptr)) return (FALSE);
978
979         /* Check objects */
980         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
981         {
982                 object_type *o_ptr;
983                 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
984                 next_o_idx = o_ptr->next_o_idx;
985
986                 /* Forbid artifact grids */
987                 if (object_is_artifact(o_ptr)) return (FALSE);
988         }
989
990         /* Accept */
991         return (TRUE);
992 }
993
994
995
996 /*
997  * Place an attr/char pair at the given map coordinate, if legal.
998  */
999 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
1000 {
1001         /* Only do "legal" locations */
1002         if (panel_contains(y, x))
1003         {
1004                 /* Hack -- fake monochrome */
1005                 if (!use_graphics)
1006                 {
1007                         if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1008                         else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1009                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
1010                 }
1011
1012                 /* Draw the char using the attr */
1013                 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
1014         }
1015 }
1016
1017
1018
1019
1020
1021 /*
1022  * Memorize interesting viewable object/features in the given grid
1023  *
1024  * This function should only be called on "legal" grids.
1025  *
1026  * This function will memorize the object and/or feature in the given
1027  * grid, if they are (1) viewable and (2) interesting.  Note that all
1028  * objects are interesting, all terrain features except floors (and
1029  * invisible traps) are interesting, and floors (and invisible traps)
1030  * are interesting sometimes (depending on various options involving
1031  * the illumination of floor grids).
1032  *
1033  * The automatic memorization of all objects and non-floor terrain
1034  * features as soon as they are displayed allows incredible amounts
1035  * of optimization in various places, especially "map_info()".
1036  *
1037  * Note that the memorization of objects is completely separate from
1038  * the memorization of terrain features, preventing annoying floor
1039  * memorization when a detected object is picked up from a dark floor,
1040  * and object memorization when an object is dropped into a floor grid
1041  * which is memorized but out-of-sight.
1042  *
1043  * This function should be called every time the "memorization" of
1044  * a grid (or the object in a grid) is called into question, such
1045  * as when an object is created in a grid, when a terrain feature
1046  * "changes" from "floor" to "non-floor", when any grid becomes
1047  * "illuminated" or "viewable", and when a "floor" grid becomes
1048  * "torch-lit".
1049  *
1050  * Note the relatively efficient use of this function by the various
1051  * "update_view()" and "update_lite()" calls, to allow objects and
1052  * terrain features to be memorized (and drawn) whenever they become
1053  * viewable or illuminated in any way, but not when they "maintain"
1054  * or "lose" their previous viewability or illumination.
1055  *
1056  * Note the butchered "internal" version of "player_can_see_bold()",
1057  * optimized primarily for the most common cases, that is, for the
1058  * non-marked floor grids.
1059  */
1060 void note_spot(POSITION y, POSITION x)
1061 {
1062         grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1063         OBJECT_IDX this_o_idx, next_o_idx = 0;
1064
1065         /* Blind players see nothing */
1066         if (p_ptr->blind) return;
1067
1068         /* Analyze non-torch-lit grids */
1069         if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1070         {
1071                 /* Require line of sight to the grid */
1072                 if (!(g_ptr->info & (CAVE_VIEW))) return;
1073
1074                 /* Require "perma-lite" of the grid */
1075                 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1076                 {
1077                         /* Not Ninja */
1078                         if (!p_ptr->see_nocto) return;
1079                 }
1080         }
1081
1082
1083         /* Hack -- memorize objects */
1084         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1085         {
1086                 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
1087                 next_o_idx = o_ptr->next_o_idx;
1088
1089                 /* Memorize objects */
1090                 o_ptr->marked |= OM_FOUND;
1091         }
1092
1093
1094         /* Hack -- memorize grids */
1095         if (!(g_ptr->info & (CAVE_MARK)))
1096         {
1097                 /* Feature code (applying "mimic" field) */
1098                 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
1099
1100                 /* Memorize some "boring" grids */
1101                 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1102                 {
1103                         /* Option -- memorize all torch-lit floors */
1104                         if (view_torch_grids &&
1105                                 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1106                         {
1107                                 g_ptr->info |= (CAVE_MARK);
1108                         }
1109
1110                         /* Option -- memorize all perma-lit floors */
1111                         else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1112                         {
1113                                 g_ptr->info |= (CAVE_MARK);
1114                         }
1115                 }
1116
1117                 /* Memorize normal grids */
1118                 else if (have_flag(f_ptr->flags, FF_LOS))
1119                 {
1120                         g_ptr->info |= (CAVE_MARK);
1121                 }
1122
1123                 /* Memorize torch-lit walls */
1124                 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1125                 {
1126                         g_ptr->info |= (CAVE_MARK);
1127                 }
1128
1129                 /* Memorize walls seen by noctovision of Ninja */
1130                 else if (p_ptr->see_nocto)
1131                 {
1132                         g_ptr->info |= (CAVE_MARK);
1133                 }
1134
1135                 /* Memorize certain non-torch-lit wall grids */
1136                 else if (check_local_illumination(y, x))
1137                 {
1138                         g_ptr->info |= (CAVE_MARK);
1139                 }
1140         }
1141
1142         /* Memorize terrain of the grid */
1143         g_ptr->info |= (CAVE_KNOWN);
1144 }
1145
1146 /*
1147  * Redraw (on the screen) a given MAP location
1148  *
1149  * This function should only be called on "legal" grids
1150  */
1151 void lite_spot(POSITION y, POSITION x)
1152 {
1153         /* Redraw if on screen */
1154         if (panel_contains(y, x) && in_bounds2(p_ptr->current_floor_ptr, y, x))
1155         {
1156                 TERM_COLOR a;
1157                 SYMBOL_CODE c;
1158                 TERM_COLOR ta;
1159                 SYMBOL_CODE tc;
1160
1161                 map_info(y, x, &a, &c, &ta, &tc);
1162
1163                 /* Hack -- fake monochrome */
1164                 if (!use_graphics)
1165                 {
1166                         if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1167                         else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1168                         else if (p_ptr->wraith_form) a = TERM_L_DARK;
1169                 }
1170
1171                 /* Hack -- Queue it */
1172                 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
1173
1174                 /* Update sub-windows */
1175                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1176         }
1177 }
1178
1179 /*
1180  * Some comments on the grid flags.  -BEN-
1181  *
1182  *
1183  * One of the major bottlenecks in previous versions of Angband was in
1184  * the calculation of "line of sight" from the player to various grids,
1185  * such as monsters.  This was such a nasty bottleneck that a lot of
1186  * silly things were done to reduce the dependancy on "line of sight",
1187  * for example, you could not "see" any grids in a lit room until you
1188  * actually entered the room, and there were all kinds of bizarre grid
1189  * flags to enable this behavior.  This is also why the "call light"
1190  * spells always lit an entire room.
1191  *
1192  * The code below provides functions to calculate the "field of view"
1193  * for the player, which, once calculated, provides extremely fast
1194  * calculation of "line of sight from the player", and to calculate
1195  * the "field of torch lite", which, again, once calculated, provides
1196  * extremely fast calculation of "which grids are lit by the player's
1197  * lite source".  In addition to marking grids as "GRID_VIEW" and/or
1198  * "GRID_LITE", as appropriate, these functions maintain an array for
1199  * each of these two flags, each array containing the locations of all
1200  * of the grids marked with the appropriate flag, which can be used to
1201  * very quickly scan through all of the grids in a given set.
1202  *
1203  * To allow more "semantically valid" field of view semantics, whenever
1204  * the field of view (or the set of torch lit grids) changes, all of the
1205  * grids in the field of view (or the set of torch lit grids) are "drawn"
1206  * so that changes in the world will become apparent as soon as possible.
1207  * This has been optimized so that only grids which actually "change" are
1208  * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
1209  * of the grids which are entering or leaving the relevent set of grids.
1210  *
1211  * These new methods are so efficient that the old nasty code was removed.
1212  *
1213  * Note that there is no reason to "update" the "viewable space" unless
1214  * the player "moves", or walls/doors are created/destroyed, and there
1215  * is no reason to "update" the "torch lit grids" unless the field of
1216  * view changes, or the "light radius" changes.  This means that when
1217  * the player is resting, or digging, or doing anything that does not
1218  * involve movement or changing the state of the dungeon, there is no
1219  * need to update the "view" or the "lite" regions, which is nice.
1220  *
1221  * Note that the calls to the nasty "los()" function have been reduced
1222  * to a bare minimum by the use of the new "field of view" calculations.
1223  *
1224  * I wouldn't be surprised if slight modifications to the "update_view()"
1225  * function would allow us to determine "reverse line-of-sight" as well
1226  * as "normal line-of-sight", which would allow monsters to use a more
1227  * "correct" calculation to determine if they can "see" the player.  For
1228  * now, monsters simply "cheat" somewhat and assume that if the player
1229  * has "line of sight" to the monster, then the monster can "pretend"
1230  * that it has "line of sight" to the player.
1231  *
1232  *
1233  * The "update_lite()" function maintains the "CAVE_LITE" flag for each
1234  * grid and maintains an array of all "CAVE_LITE" grids.
1235  *
1236  * This set of grids is the complete set of all grids which are lit by
1237  * the players light source, which allows the "player_can_see_bold()"
1238  * function to work very quickly.
1239  *
1240  * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
1241  * fact, the player (unless blind) can always "see" all grids which are
1242  * marked as "CAVE_LITE", unless they are "off screen".
1243  *
1244  *
1245  * The "update_view()" function maintains the "CAVE_VIEW" flag for each
1246  * grid and maintains an array of all "CAVE_VIEW" grids.
1247  *
1248  * This set of grids is the complete set of all grids within line of sight
1249  * of the player, allowing the "player_has_los_bold(p_ptr, )" macro to work very
1250  * quickly.
1251  *
1252  *
1253  * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
1254  * temporary internal flag to mark those grids which are not only in view,
1255  * but which are also "easily" in line of sight of the player.  This flag
1256  * is always cleared when we are done.
1257  *
1258  *
1259  * The current "update_lite()" and "update_view()" algorithms use the
1260  * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
1261  * to keep track of which grids were previously marked as "CAVE_LITE" or
1262  * "CAVE_VIEW", which allows us to optimize the "screen updates".
1263  *
1264  * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
1265  * for various other purposes, such as spreading lite or darkness during
1266  * "lite_room()" / "unlite_room()", and for calculating monster flow.
1267  *
1268  *
1269  * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
1270  * in some way permanently lit.  However, for the player to "see" anything
1271  * in the grid, as determined by "player_can_see()", the player must not be
1272  * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
1273  * grids, even if marked as "perma lit", are only illuminated if they touch
1274  * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
1275  *
1276  *
1277  * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
1278  * that even if the player cannot "see" the grid, he "knows" the terrain in
1279  * that grid.  This is used to "remember" walls/doors/stairs/floors when they
1280  * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite(p_ptr, )",
1281  * or when one of the "memorize floor grids" options induces memorization.
1282  *
1283  * Objects are "memorized" in a different way, using a special "marked" flag
1284  * on the object itself, which is set when an object is observed or detected.
1285  *
1286  *
1287  * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
1288  * and should be illuminated by "lite room" and "darkness" spells.
1289  *
1290  *
1291  * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
1292  * and should be unavailable for "teleportation" destinations.
1293  *
1294  *
1295  * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
1296  * which is observed, and the "view_torch_grids" allows the player to memorize
1297  * every torch-lit grid.  The player will always memorize important walls,
1298  * doors, stairs, and other terrain features, as well as any "detected" grids.
1299  *
1300  * Note that the new "update_view()" method allows, among other things, a room
1301  * to be "partially" seen as the player approaches it, with a growing cone of
1302  * floor appearing as the player gets closer to the door.  Also, by not turning
1303  * on the "memorize perma-lit grids" option, the player will only "see" those
1304  * floor grids which are actually in line of sight.
1305  *
1306  * And my favorite "plus" is that you can now use a special option to draw the
1307  * "floors" in the "viewable region" brightly (actually, to draw the *other*
1308  * grids dimly), providing a "pretty" effect as the player runs around, and
1309  * to efficiently display the "torch lite" in a special color.
1310  *
1311  *
1312  * Some comments on the "update_view()" algorithm...
1313  *
1314  * The algorithm is very fast, since it spreads "obvious" grids very quickly,
1315  * and only has to call "los()" on the borderline cases.  The major axes/diags
1316  * even terminate early when they hit walls.  I need to find a quick way
1317  * to "terminate" the other scans.
1318  *
1319  * Note that in the worst case (a big empty area with say 5% scattered walls),
1320  * each of the 1500 or so nearby grids is checked once, most of them getting
1321  * an "instant" rating, and only a small portion requiring a call to "los()".
1322  *
1323  * The only time that the algorithm appears to be "noticeably" too slow is
1324  * when running, and this is usually only important in town, since the town
1325  * provides about the worst scenario possible, with large open regions and
1326  * a few scattered obstructions.  There is a special "efficiency" option to
1327  * allow the player to reduce his field of view in town, if needed.
1328  *
1329  * In the "best" case (say, a normal stretch of corridor), the algorithm
1330  * makes one check for each viewable grid, and makes no calls to "los()".
1331  * So running in corridors is very fast, and if a lot of monsters are
1332  * nearby, it is much faster than the old methods.
1333  *
1334  * Note that resting, most normal commands, and several forms of running,
1335  * plus all commands executed near large groups of monsters, are strictly
1336  * more efficient with "update_view()" that with the old "compute los() on
1337  * demand" method, primarily because once the "field of view" has been
1338  * calculated, it does not have to be recalculated until the player moves
1339  * (or a wall or door is created or destroyed).
1340  *
1341  * Note that we no longer have to do as many "los()" checks, since once the
1342  * "view" region has been built, very few things cause it to be "changed"
1343  * (player movement, and the opening/closing of doors, changes in wall status).
1344  * Note that door/wall changes are only relevant when the door/wall itself is
1345  * in the "view" region.
1346  *
1347  * The algorithm seems to only call "los()" from zero to ten times, usually
1348  * only when coming down a corridor into a room, or standing in a room, just
1349  * misaligned with a corridor.  So if, say, there are five "nearby" monsters,
1350  * we will be reducing the calls to "los()".
1351  *
1352  * I am thinking in terms of an algorithm that "walks" from the central point
1353  * out to the maximal "distance", at each point, determining the "view" code
1354  * (above).  For each grid not on a major axis or diagonal, the "view" code
1355  * depends on the "cave_los_bold(p_ptr->current_floor_ptr, )" and "view" of exactly two other grids
1356  * (the one along the nearest diagonal, and the one next to that one, see
1357  * "update_view_aux()"...).
1358  *
1359  * We "memorize" the viewable space array, so that at the cost of under 3000
1360  * bytes, we reduce the time taken by "forget_view()" to one assignment for
1361  * each grid actually in the "viewable space".  And for another 3000 bytes,
1362  * we prevent "erase + redraw" ineffiencies via the "seen" set.  These bytes
1363  * are also used by other routines, thus reducing the cost to almost nothing.
1364  *
1365  * A similar thing is done for "forget_lite()" in which case the savings are
1366  * much less, but save us from doing bizarre maintenance checking.
1367  *
1368  * In the worst "normal" case (in the middle of the town), the reachable space
1369  * actually reaches to more than half of the largest possible "circle" of view,
1370  * or about 800 grids, and in the worse case (in the middle of a dungeon level
1371  * where all the walls have been removed), the reachable space actually reaches
1372  * the theoretical maximum size of just under 1500 grids.
1373  *
1374  * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
1375  * If G1 is lite, G is lite.  Else if G2 is lite, G is half.  Else if G1 and G2
1376  * are both half, G is half.  Else G is dark.  It only takes 2 (or 4) bits to
1377  * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
1378  * entire possible space (including initialization) in one step per grid.  If
1379  * we do the "clearing" as a separate step (and use an array of "view" grids),
1380  * then the clearing will take as many steps as grids that were viewed, and the
1381  * algorithm will be able to "stop" scanning at various points.
1382  * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
1383  */
1384
1385 /*
1386  * Mega-Hack -- Delayed visual update
1387  * Only used if update_view(), update_lite() or update_mon_lite() was called
1388  */
1389 void delayed_visual_update(void)
1390 {
1391         int i;
1392         POSITION y, x;
1393         grid_type *g_ptr;
1394
1395         /* Update needed grids */
1396         for (i = 0; i < p_ptr->current_floor_ptr->redraw_n; i++)
1397         {
1398                 y = p_ptr->current_floor_ptr->redraw_y[i];
1399                 x = p_ptr->current_floor_ptr->redraw_x[i];
1400                 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1401
1402                 /* Update only needed grids (prevent multiple updating) */
1403                 if (!(g_ptr->info & CAVE_REDRAW)) continue;
1404
1405                 /* If required, note */
1406                 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
1407
1408                 lite_spot(y, x);
1409
1410                 /* Hack -- Visual update of monster on this grid */
1411                 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1412
1413                 /* No longer in the array */
1414                 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
1415         }
1416
1417         /* None left */
1418         p_ptr->current_floor_ptr->redraw_n = 0;
1419 }
1420
1421
1422 /*
1423  * Hack - speed up the update_flow algorithm by only doing
1424  * it everytime the player moves out of LOS of the last
1425  * "way-point".
1426  */
1427 static POSITION flow_x = 0;
1428 static POSITION flow_y = 0;
1429
1430
1431
1432 /*
1433  * Hack -- fill in the "cost" field of every grid that the player
1434  * can "reach" with the number of steps needed to reach that grid.
1435  * This also yields the "distance" of the player from every grid.
1436  *
1437  * In addition, mark the "when" of the grids that can reach
1438  * the player with the incremented value of "flow_n".
1439  *
1440  * Hack -- use the "seen" array as a "circular queue".
1441  *
1442  * We do not need a priority queue because the cost from grid
1443  * to grid is always "one" and we process them in order.
1444  */
1445 void update_flow(void)
1446 {
1447         POSITION x, y;
1448         DIRECTION d;
1449         int flow_head = 1;
1450         int flow_tail = 0;
1451
1452         /* Paranoia -- make sure the array is empty */
1453         if (tmp_pos.n) return;
1454
1455         /* The last way-point is on the map */
1456         if (p_ptr->running && in_bounds(p_ptr->current_floor_ptr, flow_y, flow_x))
1457         {
1458                 /* The way point is in sight - do not update.  (Speedup) */
1459                 if (p_ptr->current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
1460         }
1461
1462         /* Erase all of the current flow information */
1463         for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
1464         {
1465                 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
1466                 {
1467                         p_ptr->current_floor_ptr->grid_array[y][x].cost = 0;
1468                         p_ptr->current_floor_ptr->grid_array[y][x].dist = 0;
1469                 }
1470         }
1471
1472         /* Save player position */
1473         flow_y = p_ptr->y;
1474         flow_x = p_ptr->x;
1475
1476         /* Add the player's grid to the queue */
1477         tmp_pos.y[0] = p_ptr->y;
1478         tmp_pos.x[0] = p_ptr->x;
1479
1480         /* Now process the queue */
1481         while (flow_head != flow_tail)
1482         {
1483                 int ty, tx;
1484
1485                 /* Extract the next entry */
1486                 ty = tmp_pos.y[flow_tail];
1487                 tx = tmp_pos.x[flow_tail];
1488
1489                 /* Forget that entry */
1490                 if (++flow_tail == TEMP_MAX) flow_tail = 0;
1491
1492                 /* Add the "children" */
1493                 for (d = 0; d < 8; d++)
1494                 {
1495                         int old_head = flow_head;
1496                         byte_hack m = p_ptr->current_floor_ptr->grid_array[ty][tx].cost + 1;
1497                         byte_hack n = p_ptr->current_floor_ptr->grid_array[ty][tx].dist + 1;
1498                         grid_type *g_ptr;
1499
1500                         /* Child location */
1501                         y = ty + ddy_ddd[d];
1502                         x = tx + ddx_ddd[d];
1503
1504                         /* Ignore player's grid */
1505                         if (player_bold(p_ptr, y, x)) continue;
1506
1507                         g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1508
1509                         if (is_closed_door(g_ptr->feat)) m += 3;
1510
1511                         /* Ignore "pre-stamped" entries */
1512                         if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
1513
1514                         /* Ignore "walls" and "rubble" */
1515                         if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1516
1517                         /* Save the flow cost */
1518                         if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
1519                         if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
1520
1521                         /* Hack -- limit flow depth */
1522                         if (n == MONSTER_FLOW_DEPTH) continue;
1523
1524                         /* Enqueue that entry */
1525                         tmp_pos.y[flow_head] = y;
1526                         tmp_pos.x[flow_head] = x;
1527
1528                         /* Advance the queue */
1529                         if (++flow_head == TEMP_MAX) flow_head = 0;
1530
1531                         /* Hack -- notice overflow by forgetting new entry */
1532                         if (flow_head == flow_tail) flow_head = old_head;
1533                 }
1534         }
1535 }
1536
1537 /*
1538  * Change the "feat" flag for a grid, and notice/redraw the grid
1539  */
1540 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
1541 {
1542         grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1543         feature_type *f_ptr = &f_info[feat];
1544         bool old_los, old_mirror;
1545
1546         if (!current_world_ptr->character_dungeon)
1547         {
1548                 /* Clear mimic type */
1549                 g_ptr->mimic = 0;
1550
1551                 /* Change the feature */
1552                 g_ptr->feat = feat;
1553
1554                 /* Hack -- glow the GLOW terrain */
1555                 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1556                 {
1557                         DIRECTION i;
1558                         POSITION yy, xx;
1559
1560                         for (i = 0; i < 9; i++)
1561                         {
1562                                 yy = y + ddy_ddd[i];
1563                                 xx = x + ddx_ddd[i];
1564                                 if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
1565                                 p_ptr->current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
1566                         }
1567                 }
1568
1569                 return;
1570         }
1571
1572         old_los = cave_have_flag_bold(y, x, FF_LOS);
1573         old_mirror = is_mirror_grid(g_ptr);
1574
1575         /* Clear mimic type */
1576         g_ptr->mimic = 0;
1577
1578         /* Change the feature */
1579         g_ptr->feat = feat;
1580
1581         /* Remove flag for mirror/glyph */
1582         g_ptr->info &= ~(CAVE_OBJECT);
1583
1584         if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1585         {
1586                 g_ptr->info &= ~(CAVE_GLOW);
1587                 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1588
1589                 update_local_illumination(p_ptr, y, x);
1590         }
1591
1592         /* Check for change to boring grid */
1593         if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1594         if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1595
1596         note_spot(y, x);
1597         lite_spot(y, x);
1598
1599         /* Check if los has changed */
1600         if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
1601         {
1602
1603 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1604
1605                 update_local_illumination(p_ptr, y, x);
1606
1607 #endif /* COMPLEX_WALL_ILLUMINATION */
1608
1609                 /* Update the visuals */
1610                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
1611         }
1612
1613         /* Hack -- glow the GLOW terrain */
1614         if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1615         {
1616                 DIRECTION i;
1617                 POSITION yy, xx;
1618                 grid_type *cc_ptr;
1619
1620                 for (i = 0; i < 9; i++)
1621                 {
1622                         yy = y + ddy_ddd[i];
1623                         xx = x + ddx_ddd[i];
1624                         if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
1625                         cc_ptr = &p_ptr->current_floor_ptr->grid_array[yy][xx];
1626                         cc_ptr->info |= CAVE_GLOW;
1627
1628                         if (player_has_los_grid(cc_ptr))
1629                         {
1630                                 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
1631
1632                                 note_spot(yy, xx);
1633
1634                                 lite_spot(yy, xx);
1635                         }
1636
1637                         update_local_illumination(p_ptr, yy, xx);
1638                 }
1639
1640                 if (p_ptr->special_defense & NINJA_S_STEALTH)
1641                 {
1642                         if (p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(p_ptr, FALSE);
1643                 }
1644         }
1645 }
1646
1647 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
1648 {
1649         feature_type *f_ptr = &f_info[newfeat];
1650
1651         if (have_flag(f_ptr->flags, FF_CONVERT))
1652         {
1653                 switch (f_ptr->subtype)
1654                 {
1655                 case CONVERT_TYPE_FLOOR:
1656                         return feat_ground_type[randint0(100)];
1657                 case CONVERT_TYPE_WALL:
1658                         return feat_wall_type[randint0(100)];
1659                 case CONVERT_TYPE_INNER:
1660                         return feat_wall_inner;
1661                 case CONVERT_TYPE_OUTER:
1662                         return feat_wall_outer;
1663                 case CONVERT_TYPE_SOLID:
1664                         return feat_wall_solid;
1665                 case CONVERT_TYPE_STREAM1:
1666                         return d_info[p_ptr->dungeon_idx].stream1;
1667                 case CONVERT_TYPE_STREAM2:
1668                         return d_info[p_ptr->dungeon_idx].stream2;
1669                 default:
1670                         return newfeat;
1671                 }
1672         }
1673         else return newfeat;
1674 }
1675
1676
1677 /*
1678  * Take a feature, determine what that feature becomes
1679  * through applying the given action.
1680  */
1681 FEAT_IDX feat_state(FEAT_IDX feat, int action)
1682 {
1683         feature_type *f_ptr = &f_info[feat];
1684         int i;
1685
1686         /* Get the new feature */
1687         for (i = 0; i < MAX_FEAT_STATES; i++)
1688         {
1689                 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
1690         }
1691
1692         if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
1693
1694         return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
1695 }
1696
1697 /*
1698  * Takes a location and action and changes the feature at that
1699  * location through applying the given action.
1700  */
1701 void cave_alter_feat(POSITION y, POSITION x, int action)
1702 {
1703         /* Set old feature */
1704         FEAT_IDX oldfeat = p_ptr->current_floor_ptr->grid_array[y][x].feat;
1705
1706         /* Get the new feat */
1707         FEAT_IDX newfeat = feat_state(oldfeat, action);
1708
1709         /* No change */
1710         if (newfeat == oldfeat) return;
1711
1712         /* Set the new feature */
1713         cave_set_feat(y, x, newfeat);
1714
1715         if (!(feature_action_flags[action] & FAF_NO_DROP))
1716         {
1717                 feature_type *old_f_ptr = &f_info[oldfeat];
1718                 feature_type *f_ptr = &f_info[newfeat];
1719                 bool found = FALSE;
1720
1721                 /* Handle gold */
1722                 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
1723                 {
1724                         /* Place some gold */
1725                         place_gold(y, x);
1726                         found = TRUE;
1727                 }
1728
1729                 /* Handle item */
1730                 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)))
1731                 {
1732                         /* Place object */
1733                         place_object(y, x, 0L);
1734                         found = TRUE;
1735                 }
1736
1737                 if (found && current_world_ptr->character_dungeon && player_can_see_bold(y, x))
1738                 {
1739                         msg_print(_("何かを発見した!", "You have found something!"));
1740                 }
1741         }
1742
1743         if (feature_action_flags[action] & FAF_CRASH_GLASS)
1744         {
1745                 feature_type *old_f_ptr = &f_info[oldfeat];
1746
1747                 if (have_flag(old_f_ptr->flags, FF_GLASS) && current_world_ptr->character_dungeon)
1748                 {
1749                         project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(p_ptr->current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
1750                                 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
1751                 }
1752         }
1753 }
1754
1755
1756 /* Remove a mirror */
1757 void remove_mirror(POSITION y, POSITION x)
1758 {
1759         grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1760
1761         /* Remove the mirror */
1762         g_ptr->info &= ~(CAVE_OBJECT);
1763         g_ptr->mimic = 0;
1764
1765         if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
1766         {
1767                 g_ptr->info &= ~(CAVE_GLOW);
1768                 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1769                 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1770
1771                 update_local_illumination(p_ptr, y, x);
1772         }
1773
1774         note_spot(y, x);
1775
1776         lite_spot(y, x);
1777 }
1778
1779
1780 /*
1781  *  Return TRUE if there is a mirror on the grid.
1782  */
1783 bool is_mirror_grid(grid_type *g_ptr)
1784 {
1785         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
1786                 return TRUE;
1787         else
1788                 return FALSE;
1789 }
1790
1791
1792 /*
1793  *  Return TRUE if there is a mirror on the grid.
1794  */
1795 bool is_glyph_grid(grid_type *g_ptr)
1796 {
1797         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
1798                 return TRUE;
1799         else
1800                 return FALSE;
1801 }
1802
1803
1804 /*
1805  *  Return TRUE if there is a mirror on the grid.
1806  */
1807 bool is_explosive_rune_grid(grid_type *g_ptr)
1808 {
1809         if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
1810                 return TRUE;
1811         else
1812                 return FALSE;
1813 }
1814
1815 /*!
1816 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
1817 * @param m_idx モンスターID
1818 * @param y 移動先Y座標
1819 * @param x 移動先X座標
1820 * @param mode オプション
1821 * @return テレポート先として妥当ならばtrue
1822 */
1823 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
1824 {
1825         monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
1826         grid_type    *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1827         feature_type *f_ptr = &f_info[g_ptr->feat];
1828
1829         /* Require "teleportable" space */
1830         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
1831
1832         if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
1833         if (player_bold(p_ptr, y, x)) return FALSE;
1834
1835         /* Hack -- no teleport onto glyph of warding */
1836         if (is_glyph_grid(g_ptr)) return FALSE;
1837         if (is_explosive_rune_grid(g_ptr)) return FALSE;
1838
1839         if (!(mode & TELEPORT_PASSIVE))
1840         {
1841                 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
1842         }
1843
1844         return TRUE;
1845 }
1846
1847 /*!
1848 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
1849 * @param y 移動先Y座標
1850 * @param x 移動先X座標
1851 * @param mode オプション
1852 * @return テレポート先として妥当ならばtrue
1853 */
1854 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
1855 {
1856         grid_type    *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1857         feature_type *f_ptr = &f_info[g_ptr->feat];
1858
1859         /* Require "teleportable" space */
1860         if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
1861
1862         /* No magical teleporting into vaults and such */
1863         if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
1864
1865         if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
1866
1867         /* don't teleport on a trap. */
1868         if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
1869
1870         if (!(mode & TELEPORT_PASSIVE))
1871         {
1872                 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
1873
1874                 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
1875                 {
1876                         if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
1877                 }
1878
1879                 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
1880                 {
1881                         /* Always forbid deep lava */
1882                         if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
1883
1884                         /* Forbid shallow lava when the player don't have levitation */
1885                         if (!p_ptr->levitation) return FALSE;
1886                 }
1887
1888         }
1889
1890         return TRUE;
1891 }
1892
1893 /*!
1894  * @brief 地形は開くものであって、かつ開かれているかを返す /
1895  * Attempt to open the given chest at the given location
1896  * @param feat 地形ID
1897  * @return 開いた地形である場合TRUEを返す /  Return TRUE if the given feature is an open door
1898  */
1899 bool is_open(FEAT_IDX feat)
1900 {
1901         return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
1902 }
1903
1904 /*!
1905  * @brief プレイヤーが地形踏破可能かを返す
1906  * @param feature 判定したい地形ID
1907  * @param mode 移動に関するオプションフラグ
1908  * @return 移動可能ならばTRUEを返す
1909  */
1910 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
1911 {
1912         feature_type *f_ptr = &f_info[feature];
1913
1914         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);
1915
1916         if (have_flag(f_ptr->flags, FF_PATTERN))
1917         {
1918                 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
1919         }
1920
1921         if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
1922         if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
1923         if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
1924
1925         if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;
1926
1927         return TRUE;
1928 }
1929