OSDN Git Service

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