OSDN Git Service

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