4 * @brief グリッドの実装 / low level dungeon routines -BEN-
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
9 * This software may be copied and distributed for educational, research,\n
10 * and not for profit purposes provided that this copyright and statement\n
11 * are included in all such copies. Other copyrights may also apply.\n
13 * Support for Adam Bolt's tileset, lighting and transparency effects\n
14 * by Robert Ruehlmann (rr9@angband.org)\n
16 * 2013 Deskull Doxygen向けのコメント整理\n
26 #include "object-flavor.h"
27 #include "object-hook.h"
29 #include "floor-generate.h"
36 #include "monster-status.h"
37 #include "player-status.h"
38 #include "player-effects.h"
39 #include "player-class.h"
41 #include "view-mainwindow.h"
42 #include "realm-song.h"
44 #define MONSTER_FLOW_DEPTH 32 /*!< 敵のプレイヤーに対する移動道のりの最大値(この値以上は処理を打ち切る) / OPTION: Maximum flow depth when using "MONSTER_FLOW" */
47 * Feature action flags
49 #define FAF_DESTROY 0x01
50 #define FAF_NO_DROP 0x02
51 #define FAF_CRASH_GLASS 0x04
54 * @brief 地形状態フラグテーブル /
55 * The table of features' actions
57 static const byte feature_action_flags[FF_FLAG_MAX] =
69 FAF_CRASH_GLASS, /* BASH */
71 FAF_DESTROY, /* DISARM */
73 FAF_DESTROY | FAF_CRASH_GLASS, /* TUNNEL */
74 0, /* MAY_HAVE_GOLD */
104 FAF_DESTROY | FAF_CRASH_GLASS, /* HURT_ROCK */
159 FAF_DESTROY | FAF_NO_DROP | FAF_CRASH_GLASS, /* HURT_DISI */
172 0, /* TELEPORTABLE */
178 * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
179 * @param creature_ptr 配置したいクリーチャーの参照ポインタ
180 * @return 配置に成功したらTRUEを返す
182 bool new_player_spot(player_type *creature_ptr)
184 POSITION y = 0, x = 0;
185 int max_attempts = 10000;
190 while (max_attempts--)
192 /* Pick a legal spot */
193 y = (POSITION)rand_range(1, creature_ptr->current_floor_ptr->height - 2);
194 x = (POSITION)rand_range(1, creature_ptr->current_floor_ptr->width - 2);
196 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
198 /* Must be a "naked" floor grid */
199 if (g_ptr->m_idx) continue;
200 if (creature_ptr->current_floor_ptr->dun_level)
202 f_ptr = &f_info[g_ptr->feat];
204 if (max_attempts > 5000) /* Rule 1 */
206 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
210 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
211 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
214 /* Refuse to start on anti-teleport grids in dungeon */
215 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
217 if (!player_can_enter(g_ptr->feat, 0)) continue;
218 if (!in_bounds(creature_ptr->current_floor_ptr, y, x)) continue;
220 /* Refuse to start on anti-teleport grids */
221 if (g_ptr->info & (CAVE_ICKY)) continue;
226 if (max_attempts < 1) /* Should be -1, actually if we failed... */
229 /* Save the new player grid */
239 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
240 * @param y 配置を試みたいマスのY座標
241 * @param x 配置を試みたいマスのX座標
244 void place_random_stairs(POSITION y, POSITION x)
246 bool up_stairs = TRUE;
247 bool down_stairs = TRUE;
249 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
250 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
252 if (!p_ptr->current_floor_ptr->dun_level) up_stairs = FALSE;
253 if (ironman_downward) up_stairs = FALSE;
254 if (p_ptr->current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
255 if (quest_number(p_ptr->current_floor_ptr->dun_level) && (p_ptr->current_floor_ptr->dun_level > 1)) down_stairs = FALSE;
257 /* We can't place both */
258 if (down_stairs && up_stairs)
260 /* Choose a staircase randomly */
261 if (randint0(100) < 50) up_stairs = FALSE;
262 else down_stairs = FALSE;
265 /* Place the stairs */
266 if (up_stairs) set_cave_feat(p_ptr->current_floor_ptr, y, x, feat_up_stair);
267 else if (down_stairs) set_cave_feat(p_ptr->current_floor_ptr, y, x, feat_down_stair);
271 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
272 * @param y ドアの配置を試みたいマスのY座標
273 * @param x ドアの配置を試みたいマスのX座標
274 * @param room 部屋に接している場合向けのドア生成か否か
277 void place_random_door(POSITION y, POSITION x, bool room)
280 FEAT_IDX feat = feat_none;
281 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
283 /* Initialize mimic info */
286 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
288 place_floor_bold(y, x);
292 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
293 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
294 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
296 /* Choose an object */
297 tmp = randint0(1000);
299 /* Open doors (300/1000) */
302 /* Create open door */
303 feat = feat_door[type].open;
306 /* Broken doors (100/1000) */
309 /* Create broken door */
310 feat = feat_door[type].broken;
313 /* Secret doors (200/1000) */
316 /* Create secret door */
317 place_closed_door(y, x, type);
319 if (type != DOOR_CURTAIN)
321 /* Hide. If on the edge of room, use outer wall. */
322 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
324 /* Floor type terrain cannot hide a door */
325 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
327 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
329 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
336 /* Closed, locked, or stuck doors (400/1000) */
337 else place_closed_door(y, x, type);
341 if (feat != feat_none)
343 set_cave_feat(p_ptr->current_floor_ptr, y, x, feat);
347 place_floor_bold(y, x);
351 delete_monster(y, x);
355 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
356 * @param y ドアの配置を試みたいマスのY座標
357 * @param x ドアの配置を試みたいマスのX座標
358 * @param type ドアの地形ID
361 void place_closed_door(POSITION y, POSITION x, int type)
364 FEAT_IDX feat = feat_none;
366 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
368 place_floor_bold(y, x);
372 /* Choose an object */
375 /* Closed doors (300/400) */
378 /* Create closed door */
379 feat = feat_door[type].closed;
382 /* Locked doors (99/400) */
385 /* Create locked door */
386 feat = feat_locked_door_random(type);
389 /* Stuck doors (1/400) */
392 /* Create jammed door */
393 feat = feat_jammed_door_random(type);
396 if (feat != feat_none)
398 cave_set_feat(y, x, feat);
400 /* Now it is not floor */
401 p_ptr->current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
405 place_floor_bold(y, x);
410 * Routine used by the random vault creators to add a door to a location
411 * Note that range checking has to be done in the calling routine.
413 * The doors must be INSIDE the allocated region.
415 void add_door(POSITION x, POSITION y)
417 /* Need to have a wall in the center square */
418 if (!is_outer_bold(p_ptr->current_floor_ptr, y, x)) return;
429 if (is_floor_bold(p_ptr->current_floor_ptr, y - 1, x) && is_floor_bold(p_ptr->current_floor_ptr, y + 1, x) &&
430 (is_outer_bold(p_ptr->current_floor_ptr, y, x - 1) && is_outer_bold(p_ptr->current_floor_ptr, y, x + 1)))
433 place_secret_door(p_ptr->current_floor_ptr, y, x, DOOR_DEFAULT);
435 /* set boundarys so don't get wide doors */
436 place_solid_bold(y, x - 1);
437 place_solid_bold(y, x + 1);
446 * where x = don't care
449 if (is_outer_bold(p_ptr->current_floor_ptr, y - 1, x) && is_outer_bold(p_ptr->current_floor_ptr, y + 1, x) &&
450 is_floor_bold(p_ptr->current_floor_ptr, y, x - 1) && is_floor_bold(p_ptr->current_floor_ptr, y, x + 1))
453 place_secret_door(p_ptr->current_floor_ptr, y, x, DOOR_DEFAULT);
455 /* set boundarys so don't get wide doors */
456 place_solid_bold(y - 1, x);
457 place_solid_bold(y + 1, x);
462 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
463 * @param y1 基準となるマスのY座標
464 * @param x1 基準となるマスのX座標
466 * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y1, x1)"
468 * XXX XXX This routine currently only counts actual "empty floor"\n
469 * grids which are not in rooms. We might want to also count stairs,\n
470 * open doors, closed doors, etc.
472 static int next_to_corr(POSITION y1, POSITION x1)
479 /* Scan adjacent grids */
480 for (i = 0; i < 4; i++)
484 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
486 /* Skip non floors */
487 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
489 /* Skip non "empty floor" grids */
490 if (!is_floor_grid(g_ptr))
493 /* Skip grids inside rooms */
494 if (g_ptr->info & (CAVE_ROOM)) continue;
496 /* Count these grids */
500 /* Return the number of corridors */
505 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
506 * @param y 判定を行いたいマスのY座標
507 * @param x 判定を行いたいマスのX座標
508 * @return ドアを設置可能ならばTRUEを返す
509 * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y1, x1)"
512 * Assumes "in_bounds(p_ptr->current_floor_ptr, y, x)"\n
514 static bool possible_doorway(POSITION y, POSITION x)
516 /* Count the adjacent corridors */
517 if (next_to_corr(y, x) >= 2)
520 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
521 cave_have_flag_bold(y + 1, x, FF_WALL))
526 /* Check Horizontal */
527 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
528 cave_have_flag_bold(y, x + 1, FF_WALL))
539 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
540 * @param y 設置を行いたいマスのY座標
541 * @param x 設置を行いたいマスのX座標
544 void try_door(POSITION y, POSITION x)
545 { if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
548 if (cave_have_flag_bold(y, x, FF_WALL)) return;
550 /* Ignore room grids */
551 if (p_ptr->current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
553 /* Occasional door (if allowed) */
554 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
557 place_random_door(y, x, FALSE);
563 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
564 * @param x1 長方形の左端X座標(-1)
565 * @param x2 長方形の右端X座標(+1)
566 * @param y1 長方形の上端Y座標(-1)
567 * @param y2 長方形の下端Y座標(+1)
571 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
575 /* Place a full floor under the room */
576 for (y = y1 - 1; y <= y2 + 1; y++)
578 for (x = x1 - 1; x <= x2 + 1; x++)
580 place_floor_bold(y, x);
581 add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_ROOM);
582 if (light) add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_GLOW);
589 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
590 * @param x1 長方形の左端X座標(-1)
591 * @param x2 長方形の右端X座標(+1)
592 * @param y1 長方形の上端Y座標(-1)
593 * @param y2 長方形の下端Y座標(+1)
597 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
601 place_floor(x1, x2, y1, y2, light);
603 /* Walls around the room */
604 for (y = y1 - 1; y <= y2 + 1; y++)
606 place_outer_bold(y, x1 - 1);
607 place_outer_bold(y, x2 + 1);
609 for (x = x1 - 1; x <= x2 + 1; x++)
611 place_outer_bold(y1 - 1, x);
612 place_outer_bold(y2 + 1, x);
618 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
619 * @param y 配置したい中心マスのY座標
620 * @param x 配置したい中心マスのX座標
624 * Only really called by some of the "vault" routines.
626 void vault_objects(POSITION y, POSITION x, int num)
629 int i = 0, j = y, k = x;
634 /* Attempt to place 'num' objects */
635 for (; num > 0; --num)
637 /* Try up to 11 spots looking for empty space */
638 for (i = 0; i < 11; ++i)
640 /* Pick a random location */
641 while (dummy < SAFE_MAX_ATTEMPTS)
643 j = rand_spread(y, 2);
644 k = rand_spread(x, 3);
646 if (!in_bounds(p_ptr->current_floor_ptr, j, k)) continue;
650 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
652 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
655 /* Require "clean" floor space */
656 g_ptr = &p_ptr->current_floor_ptr->grid_array[j][k];
657 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
659 if (randint0(100) < 75)
661 place_object(j, k, 0L);
668 /* Placement accomplished */
675 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
676 * @param y トラップを配置したいマスの中心Y座標
677 * @param x トラップを配置したいマスの中心X座標
678 * @param yd Y方向の配置分散マス数
679 * @param xd X方向の配置分散マス数
682 * Only really called by some of the "vault" routines.
684 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
686 int count = 0, y1 = y, x1 = x;
692 for (count = 0; count <= 5; count++)
695 while (dummy < SAFE_MAX_ATTEMPTS)
697 y1 = rand_spread(y, yd);
698 x1 = rand_spread(x, xd);
700 if (!in_bounds(p_ptr->current_floor_ptr, y1, x1)) continue;
704 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
706 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
709 /* Require "naked" floor grids */
710 g_ptr = &p_ptr->current_floor_ptr->grid_array[y1][x1];
711 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
721 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
722 * @param y トラップを配置したいマスの中心Y座標
723 * @param x トラップを配置したいマスの中心X座標
724 * @param yd Y方向の配置分散マス数
725 * @param xd X方向の配置分散マス数
726 * @param num 配置したいトラップの数
729 * Only really called by some of the "vault" routines.
731 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
735 for (i = 0; i < num; i++)
737 vault_trap_aux(y, x, yd, xd);
742 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
743 * @param y1 モンスターを配置したいマスの中心Y座標
744 * @param x1 モンスターを配置したいマスの中心X座標
745 * @param num 配置したいモンスターの数
748 * Only really called by some of the "vault" routines.
750 void vault_monsters(POSITION y1, POSITION x1, int num)
756 /* Try to summon "num" monsters "near" the given location */
757 for (k = 0; k < num; k++)
759 /* Try nine locations */
760 for (i = 0; i < 9; i++)
764 /* Pick a nearby location */
765 scatter(&y, &x, y1, x1, d, 0);
767 /* Require "empty" floor grids */
768 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
769 if (!cave_empty_grid(g_ptr)) continue;
771 /* Place the monster (allow groups) */
772 p_ptr->current_floor_ptr->monster_level = p_ptr->current_floor_ptr->base_level + 2;
773 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
774 p_ptr->current_floor_ptr->monster_level = p_ptr->current_floor_ptr->base_level;
780 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
781 * @param x チェックするマスのX座標
782 * @param y チェックするマスのY座標
783 * @return 床系地形ならばTRUE
785 bool get_is_floor(POSITION x, POSITION y)
787 if (!in_bounds(p_ptr->current_floor_ptr, y, x))
793 /* Do the real check */
794 if (is_floor_bold(p_ptr->current_floor_ptr, y, x)) return (TRUE);
800 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
801 * @param x 地形を変えたいマスのX座標
802 * @param y 地形を変えたいマスのY座標
805 void set_floor(POSITION x, POSITION y)
807 if (!in_bounds(p_ptr->current_floor_ptr, y, x))
813 if (p_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
815 /* A room border don't touch. */
819 /* Set to be floor if is a wall (don't touch lakes). */
820 if (is_extra_bold(p_ptr->current_floor_ptr, y, x))
821 place_floor_bold(y, x);
825 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
826 * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
829 void place_bound_perm_wall(grid_type *g_ptr)
831 if (bound_walls_perm)
833 /* Clear boundary mimic */
838 feature_type *f_ptr = &f_info[g_ptr->feat];
840 /* Hack -- Decline boundary walls with known treasure */
841 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
842 !have_flag(f_ptr->flags, FF_SECRET))
843 g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
845 /* Set boundary mimic */
846 g_ptr->mimic = g_ptr->feat;
849 /* Add "solid" perma-wall */
850 place_solid_perm_grid(g_ptr);
854 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
855 * @param g_ptr マス構造体の参照ポインタ
856 * @return 看破済みの罠があるならTRUEを返す。
858 bool is_known_trap(grid_type *g_ptr)
860 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
861 is_trap(g_ptr->feat)) return TRUE;
869 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
870 * @param g_ptr マス構造体の参照ポインタ
871 * @return 隠されたドアがあるならTRUEを返す。
873 bool is_hidden_door(grid_type *g_ptr)
875 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
876 is_closed_door(g_ptr->feat))
882 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
886 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
889 * @return 指定された座標に照明がかかっているならTRUEを返す。。
891 bool check_local_illumination(POSITION y, POSITION x)
893 /* Hack -- move towards player */
894 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
895 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
897 /* Check for "local" illumination */
899 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
901 /* Check for "complex" illumination */
902 if ((feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[yy][xx])) &&
903 (p_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
904 (feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[y][xx])) &&
905 (p_ptr->current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
906 (feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[yy][x])) &&
907 (p_ptr->current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
913 #else /* COMPLEX_WALL_ILLUMINATION */
915 /* Check for "simple" illumination */
916 return (p_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
918 #endif /* COMPLEX_WALL_ILLUMINATION */
922 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
923 #define update_local_illumination_aux(C, Y, X) \
925 if (player_has_los_bold((C), (Y), (X))) \
927 /* Update the monster */ \
928 if ((C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster((C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
930 /* Notice and redraw */ \
931 note_spot((Y), (X)); \
932 lite_spot((Y), (X)); \
937 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
938 * @param creature_ptr 視界元のクリーチャー
943 void update_local_illumination(player_type * creature_ptr, POSITION y, POSITION x)
948 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
950 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
952 if ((y != creature_ptr->y) && (x != creature_ptr->x))
954 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
955 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
956 update_local_illumination_aux(creature_ptr, yy, xx);
957 update_local_illumination_aux(creature_ptr, y, xx);
958 update_local_illumination_aux(creature_ptr, yy, x);
960 else if (x != creature_ptr->x) /* y == creature_ptr->y */
962 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
963 for (i = -1; i <= 1; i++)
966 update_local_illumination_aux(creature_ptr, yy, xx);
969 update_local_illumination_aux(creature_ptr, yy, x);
971 update_local_illumination_aux(creature_ptr, yy, x);
973 else if (y != creature_ptr->y) /* x == creature_ptr->x */
975 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
976 for (i = -1; i <= 1; i++)
979 update_local_illumination_aux(creature_ptr, yy, xx);
982 update_local_illumination_aux(creature_ptr, y, xx);
984 update_local_illumination_aux(creature_ptr, y, xx);
986 else /* Player's grid */
988 for (i = 0; i < 8; i++)
992 update_local_illumination_aux(creature_ptr, yy, xx);
996 #else /* COMPLEX_WALL_ILLUMINATION */
998 if ((y != creature_ptr->y) && (x != creature_ptr->x))
1000 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
1001 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
1002 update_local_illumination_aux(creature_ptr, yy, xx);
1004 else if (x != creature_ptr->x) /* y == creature_ptr->y */
1006 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
1007 for (i = -1; i <= 1; i++)
1010 update_local_illumination_aux(creature_ptr, yy, xx);
1013 else if (y != creature_ptr->y) /* x == creature_ptr->x */
1015 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
1016 for (i = -1; i <= 1; i++)
1019 update_local_illumination_aux(creature_ptr, yy, xx);
1022 else /* Player's grid */
1024 for (i = 0; i < 8; i++)
1026 yy = y + ddy_cdd[i];
1027 xx = x + ddx_cdd[i];
1028 update_local_illumination_aux(creature_ptr, yy, xx);
1032 #endif /* COMPLEX_WALL_ILLUMINATION */
1037 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
1038 * @return 視覚に収められていないならTRUEを返す
1039 * @details player_can_see_bold()関数の返り値の否定を返している。
1043 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
1048 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
1051 * @return 各種の変更が可能ならTRUEを返す。
1053 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
1055 bool cave_valid_bold(POSITION y, POSITION x)
1057 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1058 OBJECT_IDX this_o_idx, next_o_idx = 0;
1060 /* Forbid perma-grids */
1061 if (cave_perma_grid(g_ptr)) return (FALSE);
1064 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1067 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
1068 next_o_idx = o_ptr->next_o_idx;
1070 /* Forbid artifact grids */
1071 if (object_is_artifact(o_ptr)) return (FALSE);
1081 * Place an attr/char pair at the given map coordinate, if legal.
1083 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
1085 /* Only do "legal" locations */
1086 if (panel_contains(y, x))
1088 /* Hack -- fake monochrome */
1091 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1092 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1093 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1096 /* Draw the char using the attr */
1097 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
1106 * Memorize interesting viewable object/features in the given grid
1108 * This function should only be called on "legal" grids.
1110 * This function will memorize the object and/or feature in the given
1111 * grid, if they are (1) viewable and (2) interesting. Note that all
1112 * objects are interesting, all terrain features except floors (and
1113 * invisible traps) are interesting, and floors (and invisible traps)
1114 * are interesting sometimes (depending on various options involving
1115 * the illumination of floor grids).
1117 * The automatic memorization of all objects and non-floor terrain
1118 * features as soon as they are displayed allows incredible amounts
1119 * of optimization in various places, especially "map_info()".
1121 * Note that the memorization of objects is completely separate from
1122 * the memorization of terrain features, preventing annoying floor
1123 * memorization when a detected object is picked up from a dark floor,
1124 * and object memorization when an object is dropped into a floor grid
1125 * which is memorized but out-of-sight.
1127 * This function should be called every time the "memorization" of
1128 * a grid (or the object in a grid) is called into question, such
1129 * as when an object is created in a grid, when a terrain feature
1130 * "changes" from "floor" to "non-floor", when any grid becomes
1131 * "illuminated" or "viewable", and when a "floor" grid becomes
1134 * Note the relatively efficient use of this function by the various
1135 * "update_view()" and "update_lite()" calls, to allow objects and
1136 * terrain features to be memorized (and drawn) whenever they become
1137 * viewable or illuminated in any way, but not when they "maintain"
1138 * or "lose" their previous viewability or illumination.
1140 * Note the butchered "internal" version of "player_can_see_bold()",
1141 * optimized primarily for the most common cases, that is, for the
1142 * non-marked floor grids.
1144 void note_spot(POSITION y, POSITION x)
1146 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1147 OBJECT_IDX this_o_idx, next_o_idx = 0;
1149 /* Blind players see nothing */
1150 if (p_ptr->blind) return;
1152 /* Analyze non-torch-lit grids */
1153 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1155 /* Require line of sight to the grid */
1156 if (!(g_ptr->info & (CAVE_VIEW))) return;
1158 /* Require "perma-lite" of the grid */
1159 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1162 if (!p_ptr->see_nocto) return;
1167 /* Hack -- memorize objects */
1168 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1170 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
1171 next_o_idx = o_ptr->next_o_idx;
1173 /* Memorize objects */
1174 o_ptr->marked |= OM_FOUND;
1178 /* Hack -- memorize grids */
1179 if (!(g_ptr->info & (CAVE_MARK)))
1181 /* Feature code (applying "mimic" field) */
1182 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
1184 /* Memorize some "boring" grids */
1185 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1187 /* Option -- memorize all torch-lit floors */
1188 if (view_torch_grids &&
1189 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1191 g_ptr->info |= (CAVE_MARK);
1194 /* Option -- memorize all perma-lit floors */
1195 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1197 g_ptr->info |= (CAVE_MARK);
1201 /* Memorize normal grids */
1202 else if (have_flag(f_ptr->flags, FF_LOS))
1204 g_ptr->info |= (CAVE_MARK);
1207 /* Memorize torch-lit walls */
1208 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1210 g_ptr->info |= (CAVE_MARK);
1213 /* Memorize walls seen by noctovision of Ninja */
1214 else if (p_ptr->see_nocto)
1216 g_ptr->info |= (CAVE_MARK);
1219 /* Memorize certain non-torch-lit wall grids */
1220 else if (check_local_illumination(y, x))
1222 g_ptr->info |= (CAVE_MARK);
1226 /* Memorize terrain of the grid */
1227 g_ptr->info |= (CAVE_KNOWN);
1231 * Redraw (on the screen) a given MAP location
1233 * This function should only be called on "legal" grids
1235 void lite_spot(POSITION y, POSITION x)
1237 /* Redraw if on screen */
1238 if (panel_contains(y, x) && in_bounds2(p_ptr->current_floor_ptr, y, x))
1245 map_info(y, x, &a, &c, &ta, &tc);
1247 /* Hack -- fake monochrome */
1250 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1251 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1252 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1255 /* Hack -- Queue it */
1256 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
1258 /* Update sub-windows */
1259 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1264 * Some comments on the grid flags. -BEN-
1267 * One of the major bottlenecks in previous versions of Angband was in
1268 * the calculation of "line of sight" from the player to various grids,
1269 * such as monsters. This was such a nasty bottleneck that a lot of
1270 * silly things were done to reduce the dependancy on "line of sight",
1271 * for example, you could not "see" any grids in a lit room until you
1272 * actually entered the room, and there were all kinds of bizarre grid
1273 * flags to enable this behavior. This is also why the "call light"
1274 * spells always lit an entire room.
1276 * The code below provides functions to calculate the "field of view"
1277 * for the player, which, once calculated, provides extremely fast
1278 * calculation of "line of sight from the player", and to calculate
1279 * the "field of torch lite", which, again, once calculated, provides
1280 * extremely fast calculation of "which grids are lit by the player's
1281 * lite source". In addition to marking grids as "GRID_VIEW" and/or
1282 * "GRID_LITE", as appropriate, these functions maintain an array for
1283 * each of these two flags, each array containing the locations of all
1284 * of the grids marked with the appropriate flag, which can be used to
1285 * very quickly scan through all of the grids in a given set.
1287 * To allow more "semantically valid" field of view semantics, whenever
1288 * the field of view (or the set of torch lit grids) changes, all of the
1289 * grids in the field of view (or the set of torch lit grids) are "drawn"
1290 * so that changes in the world will become apparent as soon as possible.
1291 * This has been optimized so that only grids which actually "change" are
1292 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
1293 * of the grids which are entering or leaving the relevent set of grids.
1295 * These new methods are so efficient that the old nasty code was removed.
1297 * Note that there is no reason to "update" the "viewable space" unless
1298 * the player "moves", or walls/doors are created/destroyed, and there
1299 * is no reason to "update" the "torch lit grids" unless the field of
1300 * view changes, or the "light radius" changes. This means that when
1301 * the player is resting, or digging, or doing anything that does not
1302 * involve movement or changing the state of the dungeon, there is no
1303 * need to update the "view" or the "lite" regions, which is nice.
1305 * Note that the calls to the nasty "los()" function have been reduced
1306 * to a bare minimum by the use of the new "field of view" calculations.
1308 * I wouldn't be surprised if slight modifications to the "update_view()"
1309 * function would allow us to determine "reverse line-of-sight" as well
1310 * as "normal line-of-sight", which would allow monsters to use a more
1311 * "correct" calculation to determine if they can "see" the player. For
1312 * now, monsters simply "cheat" somewhat and assume that if the player
1313 * has "line of sight" to the monster, then the monster can "pretend"
1314 * that it has "line of sight" to the player.
1317 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
1318 * grid and maintains an array of all "CAVE_LITE" grids.
1320 * This set of grids is the complete set of all grids which are lit by
1321 * the players light source, which allows the "player_can_see_bold()"
1322 * function to work very quickly.
1324 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
1325 * fact, the player (unless blind) can always "see" all grids which are
1326 * marked as "CAVE_LITE", unless they are "off screen".
1329 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
1330 * grid and maintains an array of all "CAVE_VIEW" grids.
1332 * This set of grids is the complete set of all grids within line of sight
1333 * of the player, allowing the "player_has_los_bold(p_ptr, )" macro to work very
1337 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
1338 * temporary internal flag to mark those grids which are not only in view,
1339 * but which are also "easily" in line of sight of the player. This flag
1340 * is always cleared when we are done.
1343 * The current "update_lite()" and "update_view()" algorithms use the
1344 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
1345 * to keep track of which grids were previously marked as "CAVE_LITE" or
1346 * "CAVE_VIEW", which allows us to optimize the "screen updates".
1348 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
1349 * for various other purposes, such as spreading lite or darkness during
1350 * "lite_room()" / "unlite_room()", and for calculating monster flow.
1353 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
1354 * in some way permanently lit. However, for the player to "see" anything
1355 * in the grid, as determined by "player_can_see()", the player must not be
1356 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
1357 * grids, even if marked as "perma lit", are only illuminated if they touch
1358 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
1361 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
1362 * that even if the player cannot "see" the grid, he "knows" the terrain in
1363 * that grid. This is used to "remember" walls/doors/stairs/floors when they
1364 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite(p_ptr, )",
1365 * or when one of the "memorize floor grids" options induces memorization.
1367 * Objects are "memorized" in a different way, using a special "marked" flag
1368 * on the object itself, which is set when an object is observed or detected.
1371 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
1372 * and should be illuminated by "lite room" and "darkness" spells.
1375 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
1376 * and should be unavailable for "teleportation" destinations.
1379 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
1380 * which is observed, and the "view_torch_grids" allows the player to memorize
1381 * every torch-lit grid. The player will always memorize important walls,
1382 * doors, stairs, and other terrain features, as well as any "detected" grids.
1384 * Note that the new "update_view()" method allows, among other things, a room
1385 * to be "partially" seen as the player approaches it, with a growing cone of
1386 * floor appearing as the player gets closer to the door. Also, by not turning
1387 * on the "memorize perma-lit grids" option, the player will only "see" those
1388 * floor grids which are actually in line of sight.
1390 * And my favorite "plus" is that you can now use a special option to draw the
1391 * "floors" in the "viewable region" brightly (actually, to draw the *other*
1392 * grids dimly), providing a "pretty" effect as the player runs around, and
1393 * to efficiently display the "torch lite" in a special color.
1396 * Some comments on the "update_view()" algorithm...
1398 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
1399 * and only has to call "los()" on the borderline cases. The major axes/diags
1400 * even terminate early when they hit walls. I need to find a quick way
1401 * to "terminate" the other scans.
1403 * Note that in the worst case (a big empty area with say 5% scattered walls),
1404 * each of the 1500 or so nearby grids is checked once, most of them getting
1405 * an "instant" rating, and only a small portion requiring a call to "los()".
1407 * The only time that the algorithm appears to be "noticeably" too slow is
1408 * when running, and this is usually only important in town, since the town
1409 * provides about the worst scenario possible, with large open regions and
1410 * a few scattered obstructions. There is a special "efficiency" option to
1411 * allow the player to reduce his field of view in town, if needed.
1413 * In the "best" case (say, a normal stretch of corridor), the algorithm
1414 * makes one check for each viewable grid, and makes no calls to "los()".
1415 * So running in corridors is very fast, and if a lot of monsters are
1416 * nearby, it is much faster than the old methods.
1418 * Note that resting, most normal commands, and several forms of running,
1419 * plus all commands executed near large groups of monsters, are strictly
1420 * more efficient with "update_view()" that with the old "compute los() on
1421 * demand" method, primarily because once the "field of view" has been
1422 * calculated, it does not have to be recalculated until the player moves
1423 * (or a wall or door is created or destroyed).
1425 * Note that we no longer have to do as many "los()" checks, since once the
1426 * "view" region has been built, very few things cause it to be "changed"
1427 * (player movement, and the opening/closing of doors, changes in wall status).
1428 * Note that door/wall changes are only relevant when the door/wall itself is
1429 * in the "view" region.
1431 * The algorithm seems to only call "los()" from zero to ten times, usually
1432 * only when coming down a corridor into a room, or standing in a room, just
1433 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
1434 * we will be reducing the calls to "los()".
1436 * I am thinking in terms of an algorithm that "walks" from the central point
1437 * out to the maximal "distance", at each point, determining the "view" code
1438 * (above). For each grid not on a major axis or diagonal, the "view" code
1439 * depends on the "cave_los_bold(p_ptr->current_floor_ptr, )" and "view" of exactly two other grids
1440 * (the one along the nearest diagonal, and the one next to that one, see
1441 * "update_view_aux()"...).
1443 * We "memorize" the viewable space array, so that at the cost of under 3000
1444 * bytes, we reduce the time taken by "forget_view()" to one assignment for
1445 * each grid actually in the "viewable space". And for another 3000 bytes,
1446 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
1447 * are also used by other routines, thus reducing the cost to almost nothing.
1449 * A similar thing is done for "forget_lite()" in which case the savings are
1450 * much less, but save us from doing bizarre maintenance checking.
1452 * In the worst "normal" case (in the middle of the town), the reachable space
1453 * actually reaches to more than half of the largest possible "circle" of view,
1454 * or about 800 grids, and in the worse case (in the middle of a dungeon level
1455 * where all the walls have been removed), the reachable space actually reaches
1456 * the theoretical maximum size of just under 1500 grids.
1458 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
1459 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
1460 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
1461 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
1462 * entire possible space (including initialization) in one step per grid. If
1463 * we do the "clearing" as a separate step (and use an array of "view" grids),
1464 * then the clearing will take as many steps as grids that were viewed, and the
1465 * algorithm will be able to "stop" scanning at various points.
1466 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
1470 * Mega-Hack -- Delayed visual update
1471 * Only used if update_view(), update_lite() or update_mon_lite() was called
1473 void delayed_visual_update(void)
1479 /* Update needed grids */
1480 for (i = 0; i < p_ptr->current_floor_ptr->redraw_n; i++)
1482 y = p_ptr->current_floor_ptr->redraw_y[i];
1483 x = p_ptr->current_floor_ptr->redraw_x[i];
1484 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1486 /* Update only needed grids (prevent multiple updating) */
1487 if (!(g_ptr->info & CAVE_REDRAW)) continue;
1489 /* If required, note */
1490 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
1494 /* Hack -- Visual update of monster on this grid */
1495 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1497 /* No longer in the array */
1498 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
1502 p_ptr->current_floor_ptr->redraw_n = 0;
1507 * Hack - speed up the update_flow algorithm by only doing
1508 * it everytime the player moves out of LOS of the last
1511 static POSITION flow_x = 0;
1512 static POSITION flow_y = 0;
1517 * Hack -- fill in the "cost" field of every grid that the player
1518 * can "reach" with the number of steps needed to reach that grid.
1519 * This also yields the "distance" of the player from every grid.
1521 * In addition, mark the "when" of the grids that can reach
1522 * the player with the incremented value of "flow_n".
1524 * Hack -- use the "seen" array as a "circular queue".
1526 * We do not need a priority queue because the cost from grid
1527 * to grid is always "one" and we process them in order.
1529 void update_flow(void)
1536 /* Paranoia -- make sure the array is empty */
1537 if (tmp_pos.n) return;
1539 /* The last way-point is on the map */
1540 if (p_ptr->running && in_bounds(p_ptr->current_floor_ptr, flow_y, flow_x))
1542 /* The way point is in sight - do not update. (Speedup) */
1543 if (p_ptr->current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
1546 /* Erase all of the current flow information */
1547 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
1549 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
1551 p_ptr->current_floor_ptr->grid_array[y][x].cost = 0;
1552 p_ptr->current_floor_ptr->grid_array[y][x].dist = 0;
1556 /* Save player position */
1560 /* Add the player's grid to the queue */
1561 tmp_pos.y[0] = p_ptr->y;
1562 tmp_pos.x[0] = p_ptr->x;
1564 /* Now process the queue */
1565 while (flow_head != flow_tail)
1569 /* Extract the next entry */
1570 ty = tmp_pos.y[flow_tail];
1571 tx = tmp_pos.x[flow_tail];
1573 /* Forget that entry */
1574 if (++flow_tail == TEMP_MAX) flow_tail = 0;
1576 /* Add the "children" */
1577 for (d = 0; d < 8; d++)
1579 int old_head = flow_head;
1580 byte_hack m = p_ptr->current_floor_ptr->grid_array[ty][tx].cost + 1;
1581 byte_hack n = p_ptr->current_floor_ptr->grid_array[ty][tx].dist + 1;
1584 /* Child location */
1585 y = ty + ddy_ddd[d];
1586 x = tx + ddx_ddd[d];
1588 /* Ignore player's grid */
1589 if (player_bold(p_ptr, y, x)) continue;
1591 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1593 if (is_closed_door(g_ptr->feat)) m += 3;
1595 /* Ignore "pre-stamped" entries */
1596 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
1598 /* Ignore "walls" and "rubble" */
1599 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1601 /* Save the flow cost */
1602 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
1603 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
1605 /* Hack -- limit flow depth */
1606 if (n == MONSTER_FLOW_DEPTH) continue;
1608 /* Enqueue that entry */
1609 tmp_pos.y[flow_head] = y;
1610 tmp_pos.x[flow_head] = x;
1612 /* Advance the queue */
1613 if (++flow_head == TEMP_MAX) flow_head = 0;
1615 /* Hack -- notice overflow by forgetting new entry */
1616 if (flow_head == flow_tail) flow_head = old_head;
1622 * Change the "feat" flag for a grid, and notice/redraw the grid
1624 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
1626 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1627 feature_type *f_ptr = &f_info[feat];
1628 bool old_los, old_mirror;
1630 if (!current_world_ptr->character_dungeon)
1632 /* Clear mimic type */
1635 /* Change the feature */
1638 /* Hack -- glow the GLOW terrain */
1639 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1644 for (i = 0; i < 9; i++)
1646 yy = y + ddy_ddd[i];
1647 xx = x + ddx_ddd[i];
1648 if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
1649 p_ptr->current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
1656 old_los = cave_have_flag_bold(y, x, FF_LOS);
1657 old_mirror = is_mirror_grid(g_ptr);
1659 /* Clear mimic type */
1662 /* Change the feature */
1665 /* Remove flag for mirror/glyph */
1666 g_ptr->info &= ~(CAVE_OBJECT);
1668 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1670 g_ptr->info &= ~(CAVE_GLOW);
1671 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1673 update_local_illumination(p_ptr, y, x);
1676 /* Check for change to boring grid */
1677 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1678 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1683 /* Check if los has changed */
1684 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
1687 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1689 update_local_illumination(p_ptr, y, x);
1691 #endif /* COMPLEX_WALL_ILLUMINATION */
1693 /* Update the visuals */
1694 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
1697 /* Hack -- glow the GLOW terrain */
1698 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1704 for (i = 0; i < 9; i++)
1706 yy = y + ddy_ddd[i];
1707 xx = x + ddx_ddd[i];
1708 if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
1709 cc_ptr = &p_ptr->current_floor_ptr->grid_array[yy][xx];
1710 cc_ptr->info |= CAVE_GLOW;
1712 if (player_has_los_grid(cc_ptr))
1714 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
1721 update_local_illumination(p_ptr, yy, xx);
1724 if (p_ptr->special_defense & NINJA_S_STEALTH)
1726 if (p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(p_ptr, FALSE);
1731 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
1733 feature_type *f_ptr = &f_info[newfeat];
1735 if (have_flag(f_ptr->flags, FF_CONVERT))
1737 switch (f_ptr->subtype)
1739 case CONVERT_TYPE_FLOOR:
1740 return feat_ground_type[randint0(100)];
1741 case CONVERT_TYPE_WALL:
1742 return feat_wall_type[randint0(100)];
1743 case CONVERT_TYPE_INNER:
1744 return feat_wall_inner;
1745 case CONVERT_TYPE_OUTER:
1746 return feat_wall_outer;
1747 case CONVERT_TYPE_SOLID:
1748 return feat_wall_solid;
1749 case CONVERT_TYPE_STREAM1:
1750 return d_info[p_ptr->dungeon_idx].stream1;
1751 case CONVERT_TYPE_STREAM2:
1752 return d_info[p_ptr->dungeon_idx].stream2;
1757 else return newfeat;
1762 * Take a feature, determine what that feature becomes
1763 * through applying the given action.
1765 FEAT_IDX feat_state(FEAT_IDX feat, int action)
1767 feature_type *f_ptr = &f_info[feat];
1770 /* Get the new feature */
1771 for (i = 0; i < MAX_FEAT_STATES; i++)
1773 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
1776 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
1778 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
1782 * Takes a location and action and changes the feature at that
1783 * location through applying the given action.
1785 void cave_alter_feat(POSITION y, POSITION x, int action)
1787 /* Set old feature */
1788 FEAT_IDX oldfeat = p_ptr->current_floor_ptr->grid_array[y][x].feat;
1790 /* Get the new feat */
1791 FEAT_IDX newfeat = feat_state(oldfeat, action);
1794 if (newfeat == oldfeat) return;
1796 /* Set the new feature */
1797 cave_set_feat(y, x, newfeat);
1799 if (!(feature_action_flags[action] & FAF_NO_DROP))
1801 feature_type *old_f_ptr = &f_info[oldfeat];
1802 feature_type *f_ptr = &f_info[newfeat];
1806 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
1808 /* Place some gold */
1814 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - p_ptr->current_floor_ptr->dun_level / 2)))
1817 place_object(y, x, 0L);
1821 if (found && current_world_ptr->character_dungeon && player_can_see_bold(y, x))
1823 msg_print(_("何かを発見した!", "You have found something!"));
1827 if (feature_action_flags[action] & FAF_CRASH_GLASS)
1829 feature_type *old_f_ptr = &f_info[oldfeat];
1831 if (have_flag(old_f_ptr->flags, FF_GLASS) && current_world_ptr->character_dungeon)
1833 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(p_ptr->current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
1834 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
1840 /* Remove a mirror */
1841 void remove_mirror(POSITION y, POSITION x)
1843 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1845 /* Remove the mirror */
1846 g_ptr->info &= ~(CAVE_OBJECT);
1849 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
1851 g_ptr->info &= ~(CAVE_GLOW);
1852 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1853 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1855 update_local_illumination(p_ptr, y, x);
1865 * Return TRUE if there is a mirror on the grid.
1867 bool is_mirror_grid(grid_type *g_ptr)
1869 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
1877 * Return TRUE if there is a mirror on the grid.
1879 bool is_glyph_grid(grid_type *g_ptr)
1881 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
1889 * Return TRUE if there is a mirror on the grid.
1891 bool is_explosive_rune_grid(grid_type *g_ptr)
1893 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
1900 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
1901 * @param m_idx モンスターID
1905 * @return テレポート先として妥当ならばtrue
1907 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
1909 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
1910 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1911 feature_type *f_ptr = &f_info[g_ptr->feat];
1913 /* Require "teleportable" space */
1914 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
1916 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
1917 if (player_bold(p_ptr, y, x)) return FALSE;
1919 /* Hack -- no teleport onto glyph of warding */
1920 if (is_glyph_grid(g_ptr)) return FALSE;
1921 if (is_explosive_rune_grid(g_ptr)) return FALSE;
1923 if (!(mode & TELEPORT_PASSIVE))
1925 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
1932 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
1936 * @return テレポート先として妥当ならばtrue
1938 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
1940 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1941 feature_type *f_ptr = &f_info[g_ptr->feat];
1943 /* Require "teleportable" space */
1944 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
1946 /* No magical teleporting into vaults and such */
1947 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
1949 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
1951 /* don't teleport on a trap. */
1952 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
1954 if (!(mode & TELEPORT_PASSIVE))
1956 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
1958 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
1960 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
1963 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
1965 /* Always forbid deep lava */
1966 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
1968 /* Forbid shallow lava when the player don't have levitation */
1969 if (!p_ptr->levitation) return FALSE;
1978 * @brief 地形は開くものであって、かつ開かれているかを返す /
1979 * Attempt to open the given chest at the given location
1981 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
1983 bool is_open(FEAT_IDX feat)
1985 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
1989 * @brief プレイヤーが地形踏破可能かを返す
1990 * @param feature 判定したい地形ID
1991 * @param mode 移動に関するオプションフラグ
1992 * @return 移動可能ならばTRUEを返す
1994 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
1996 feature_type *f_ptr = &f_info[feature];
1998 if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[p_ptr->current_floor_ptr->m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
2000 if (have_flag(f_ptr->flags, FF_PATTERN))
2002 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
2005 if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
2006 if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
2007 if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
2009 if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;