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 * @return 配置に成功したらTRUEを返す
181 bool new_player_spot(void)
183 POSITION y = 0, x = 0;
184 int max_attempts = 10000;
189 while (max_attempts--)
191 /* Pick a legal spot */
192 y = (POSITION)rand_range(1, p_ptr->current_floor_ptr->height - 2);
193 x = (POSITION)rand_range(1, p_ptr->current_floor_ptr->width - 2);
195 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
197 /* Must be a "naked" floor grid */
198 if (g_ptr->m_idx) continue;
199 if (p_ptr->current_floor_ptr->dun_level)
201 f_ptr = &f_info[g_ptr->feat];
203 if (max_attempts > 5000) /* Rule 1 */
205 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
209 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
210 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
213 /* Refuse to start on anti-teleport grids in dungeon */
214 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
216 if (!player_can_enter(g_ptr->feat, 0)) continue;
217 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) continue;
219 /* Refuse to start on anti-teleport grids */
220 if (g_ptr->info & (CAVE_ICKY)) continue;
225 if (max_attempts < 1) /* Should be -1, actually if we failed... */
228 /* Save the new player grid */
238 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
239 * @param y 配置を試みたいマスのY座標
240 * @param x 配置を試みたいマスのX座標
243 void place_random_stairs(POSITION y, POSITION x)
245 bool up_stairs = TRUE;
246 bool down_stairs = TRUE;
248 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
249 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
251 if (!p_ptr->current_floor_ptr->dun_level) up_stairs = FALSE;
252 if (ironman_downward) up_stairs = FALSE;
253 if (p_ptr->current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
254 if (quest_number(p_ptr->current_floor_ptr->dun_level) && (p_ptr->current_floor_ptr->dun_level > 1)) down_stairs = FALSE;
256 /* We can't place both */
257 if (down_stairs && up_stairs)
259 /* Choose a staircase randomly */
260 if (randint0(100) < 50) up_stairs = FALSE;
261 else down_stairs = FALSE;
264 /* Place the stairs */
265 if (up_stairs) set_cave_feat(p_ptr->current_floor_ptr, y, x, feat_up_stair);
266 else if (down_stairs) set_cave_feat(p_ptr->current_floor_ptr, y, x, feat_down_stair);
270 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
271 * @param y ドアの配置を試みたいマスのY座標
272 * @param x ドアの配置を試みたいマスのX座標
273 * @param room 部屋に接している場合向けのドア生成か否か
276 void place_random_door(POSITION y, POSITION x, bool room)
279 FEAT_IDX feat = feat_none;
280 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
282 /* Initialize mimic info */
285 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
287 place_floor_bold(y, x);
291 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
292 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
293 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
295 /* Choose an object */
296 tmp = randint0(1000);
298 /* Open doors (300/1000) */
301 /* Create open door */
302 feat = feat_door[type].open;
305 /* Broken doors (100/1000) */
308 /* Create broken door */
309 feat = feat_door[type].broken;
312 /* Secret doors (200/1000) */
315 /* Create secret door */
316 place_closed_door(y, x, type);
318 if (type != DOOR_CURTAIN)
320 /* Hide. If on the edge of room, use outer wall. */
321 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
323 /* Floor type terrain cannot hide a door */
324 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
326 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
328 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
335 /* Closed, locked, or stuck doors (400/1000) */
336 else place_closed_door(y, x, type);
340 if (feat != feat_none)
342 set_cave_feat(p_ptr->current_floor_ptr, y, x, feat);
346 place_floor_bold(y, x);
350 delete_monster(y, x);
354 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
355 * @param y ドアの配置を試みたいマスのY座標
356 * @param x ドアの配置を試みたいマスのX座標
357 * @param type ドアの地形ID
360 void place_closed_door(POSITION y, POSITION x, int type)
363 FEAT_IDX feat = feat_none;
365 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
367 place_floor_bold(y, x);
371 /* Choose an object */
374 /* Closed doors (300/400) */
377 /* Create closed door */
378 feat = feat_door[type].closed;
381 /* Locked doors (99/400) */
384 /* Create locked door */
385 feat = feat_locked_door_random(type);
388 /* Stuck doors (1/400) */
391 /* Create jammed door */
392 feat = feat_jammed_door_random(type);
395 if (feat != feat_none)
397 cave_set_feat(y, x, feat);
399 /* Now it is not floor */
400 p_ptr->current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
404 place_floor_bold(y, x);
409 * Routine used by the random vault creators to add a door to a location
410 * Note that range checking has to be done in the calling routine.
412 * The doors must be INSIDE the allocated region.
414 void add_door(POSITION x, POSITION y)
416 /* Need to have a wall in the center square */
417 if (!is_outer_bold(p_ptr->current_floor_ptr, y, x)) return;
428 if (is_floor_bold(p_ptr->current_floor_ptr, y - 1, x) && is_floor_bold(p_ptr->current_floor_ptr, y + 1, x) &&
429 (is_outer_bold(p_ptr->current_floor_ptr, y, x - 1) && is_outer_bold(p_ptr->current_floor_ptr, y, x + 1)))
432 place_secret_door(p_ptr->current_floor_ptr, y, x, DOOR_DEFAULT);
434 /* set boundarys so don't get wide doors */
435 place_solid_bold(y, x - 1);
436 place_solid_bold(y, x + 1);
445 * where x = don't care
448 if (is_outer_bold(p_ptr->current_floor_ptr, y - 1, x) && is_outer_bold(p_ptr->current_floor_ptr, y + 1, x) &&
449 is_floor_bold(p_ptr->current_floor_ptr, y, x - 1) && is_floor_bold(p_ptr->current_floor_ptr, y, x + 1))
452 place_secret_door(p_ptr->current_floor_ptr, y, x, DOOR_DEFAULT);
454 /* set boundarys so don't get wide doors */
455 place_solid_bold(y - 1, x);
456 place_solid_bold(y + 1, x);
461 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
462 * @param y1 基準となるマスのY座標
463 * @param x1 基準となるマスのX座標
465 * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y1, x1)"
467 * XXX XXX This routine currently only counts actual "empty floor"\n
468 * grids which are not in rooms. We might want to also count stairs,\n
469 * open doors, closed doors, etc.
471 static int next_to_corr(POSITION y1, POSITION x1)
478 /* Scan adjacent grids */
479 for (i = 0; i < 4; i++)
483 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
485 /* Skip non floors */
486 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
488 /* Skip non "empty floor" grids */
489 if (!is_floor_grid(g_ptr))
492 /* Skip grids inside rooms */
493 if (g_ptr->info & (CAVE_ROOM)) continue;
495 /* Count these grids */
499 /* Return the number of corridors */
504 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
505 * @param y 判定を行いたいマスのY座標
506 * @param x 判定を行いたいマスのX座標
507 * @return ドアを設置可能ならばTRUEを返す
508 * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y1, x1)"
511 * Assumes "in_bounds(p_ptr->current_floor_ptr, y, x)"\n
513 static bool possible_doorway(POSITION y, POSITION x)
515 /* Count the adjacent corridors */
516 if (next_to_corr(y, x) >= 2)
519 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
520 cave_have_flag_bold(y + 1, x, FF_WALL))
525 /* Check Horizontal */
526 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
527 cave_have_flag_bold(y, x + 1, FF_WALL))
538 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
539 * @param y 設置を行いたいマスのY座標
540 * @param x 設置を行いたいマスのX座標
543 void try_door(POSITION y, POSITION x)
544 { if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
547 if (cave_have_flag_bold(y, x, FF_WALL)) return;
549 /* Ignore room grids */
550 if (p_ptr->current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
552 /* Occasional door (if allowed) */
553 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
556 place_random_door(y, x, FALSE);
562 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
563 * @param x1 長方形の左端X座標(-1)
564 * @param x2 長方形の右端X座標(+1)
565 * @param y1 長方形の上端Y座標(-1)
566 * @param y2 長方形の下端Y座標(+1)
570 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
574 /* Place a full floor under the room */
575 for (y = y1 - 1; y <= y2 + 1; y++)
577 for (x = x1 - 1; x <= x2 + 1; x++)
579 place_floor_bold(y, x);
580 add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_ROOM);
581 if (light) add_cave_info(p_ptr->current_floor_ptr, y, x, CAVE_GLOW);
588 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
589 * @param x1 長方形の左端X座標(-1)
590 * @param x2 長方形の右端X座標(+1)
591 * @param y1 長方形の上端Y座標(-1)
592 * @param y2 長方形の下端Y座標(+1)
596 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
600 place_floor(x1, x2, y1, y2, light);
602 /* Walls around the room */
603 for (y = y1 - 1; y <= y2 + 1; y++)
605 place_outer_bold(y, x1 - 1);
606 place_outer_bold(y, x2 + 1);
608 for (x = x1 - 1; x <= x2 + 1; x++)
610 place_outer_bold(y1 - 1, x);
611 place_outer_bold(y2 + 1, x);
617 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
618 * @param y 配置したい中心マスのY座標
619 * @param x 配置したい中心マスのX座標
623 * Only really called by some of the "vault" routines.
625 void vault_objects(POSITION y, POSITION x, int num)
628 int i = 0, j = y, k = x;
633 /* Attempt to place 'num' objects */
634 for (; num > 0; --num)
636 /* Try up to 11 spots looking for empty space */
637 for (i = 0; i < 11; ++i)
639 /* Pick a random location */
640 while (dummy < SAFE_MAX_ATTEMPTS)
642 j = rand_spread(y, 2);
643 k = rand_spread(x, 3);
645 if (!in_bounds(p_ptr->current_floor_ptr, j, k)) continue;
649 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
651 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
654 /* Require "clean" floor space */
655 g_ptr = &p_ptr->current_floor_ptr->grid_array[j][k];
656 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
658 if (randint0(100) < 75)
660 place_object(j, k, 0L);
667 /* Placement accomplished */
674 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
675 * @param y トラップを配置したいマスの中心Y座標
676 * @param x トラップを配置したいマスの中心X座標
677 * @param yd Y方向の配置分散マス数
678 * @param xd X方向の配置分散マス数
681 * Only really called by some of the "vault" routines.
683 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
685 int count = 0, y1 = y, x1 = x;
691 for (count = 0; count <= 5; count++)
694 while (dummy < SAFE_MAX_ATTEMPTS)
696 y1 = rand_spread(y, yd);
697 x1 = rand_spread(x, xd);
699 if (!in_bounds(p_ptr->current_floor_ptr, y1, x1)) continue;
703 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
705 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
708 /* Require "naked" floor grids */
709 g_ptr = &p_ptr->current_floor_ptr->grid_array[y1][x1];
710 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
720 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
721 * @param y トラップを配置したいマスの中心Y座標
722 * @param x トラップを配置したいマスの中心X座標
723 * @param yd Y方向の配置分散マス数
724 * @param xd X方向の配置分散マス数
725 * @param num 配置したいトラップの数
728 * Only really called by some of the "vault" routines.
730 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
734 for (i = 0; i < num; i++)
736 vault_trap_aux(y, x, yd, xd);
741 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
742 * @param y1 モンスターを配置したいマスの中心Y座標
743 * @param x1 モンスターを配置したいマスの中心X座標
744 * @param num 配置したいモンスターの数
747 * Only really called by some of the "vault" routines.
749 void vault_monsters(POSITION y1, POSITION x1, int num)
755 /* Try to summon "num" monsters "near" the given location */
756 for (k = 0; k < num; k++)
758 /* Try nine locations */
759 for (i = 0; i < 9; i++)
763 /* Pick a nearby location */
764 scatter(&y, &x, y1, x1, d, 0);
766 /* Require "empty" floor grids */
767 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
768 if (!cave_empty_grid(g_ptr)) continue;
770 /* Place the monster (allow groups) */
771 p_ptr->current_floor_ptr->monster_level = p_ptr->current_floor_ptr->base_level + 2;
772 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
773 p_ptr->current_floor_ptr->monster_level = p_ptr->current_floor_ptr->base_level;
779 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
780 * @param x チェックするマスのX座標
781 * @param y チェックするマスのY座標
782 * @return 床系地形ならばTRUE
784 bool get_is_floor(POSITION x, POSITION y)
786 if (!in_bounds(p_ptr->current_floor_ptr, y, x))
792 /* Do the real check */
793 if (is_floor_bold(p_ptr->current_floor_ptr, y, x)) return (TRUE);
799 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
800 * @param x 地形を変えたいマスのX座標
801 * @param y 地形を変えたいマスのY座標
804 void set_floor(POSITION x, POSITION y)
806 if (!in_bounds(p_ptr->current_floor_ptr, y, x))
812 if (p_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
814 /* A room border don't touch. */
818 /* Set to be floor if is a wall (don't touch lakes). */
819 if (is_extra_bold(p_ptr->current_floor_ptr, y, x))
820 place_floor_bold(y, x);
824 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
825 * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
828 void place_bound_perm_wall(grid_type *g_ptr)
830 if (bound_walls_perm)
832 /* Clear boundary mimic */
837 feature_type *f_ptr = &f_info[g_ptr->feat];
839 /* Hack -- Decline boundary walls with known treasure */
840 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
841 !have_flag(f_ptr->flags, FF_SECRET))
842 g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
844 /* Set boundary mimic */
845 g_ptr->mimic = g_ptr->feat;
848 /* Add "solid" perma-wall */
849 place_solid_perm_grid(g_ptr);
853 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
854 * @param g_ptr マス構造体の参照ポインタ
855 * @return 看破済みの罠があるならTRUEを返す。
857 bool is_known_trap(grid_type *g_ptr)
859 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
860 is_trap(g_ptr->feat)) return TRUE;
868 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
869 * @param g_ptr マス構造体の参照ポインタ
870 * @return 隠されたドアがあるならTRUEを返す。
872 bool is_hidden_door(grid_type *g_ptr)
874 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
875 is_closed_door(g_ptr->feat))
881 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
885 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
888 * @return 指定された座標に照明がかかっているならTRUEを返す。。
890 bool check_local_illumination(POSITION y, POSITION x)
892 /* Hack -- move towards player */
893 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
894 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
896 /* Check for "local" illumination */
898 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
900 /* Check for "complex" illumination */
901 if ((feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[yy][xx])) &&
902 (p_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
903 (feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[y][xx])) &&
904 (p_ptr->current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
905 (feat_supports_los(get_feat_mimic(&p_ptr->current_floor_ptr->grid_array[yy][x])) &&
906 (p_ptr->current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
912 #else /* COMPLEX_WALL_ILLUMINATION */
914 /* Check for "simple" illumination */
915 return (p_ptr->current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
917 #endif /* COMPLEX_WALL_ILLUMINATION */
921 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
922 #define update_local_illumination_aux(Y, X) \
924 if (player_has_los_bold((Y), (X))) \
926 /* Update the monster */ \
927 if (p_ptr->current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster(p_ptr->current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
929 /* Notice and redraw */ \
930 note_spot((Y), (X)); \
931 lite_spot((Y), (X)); \
936 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
937 * @param creature_ptr 視界元のクリーチャー
942 void update_local_illumination(player_type * creature_ptr, POSITION y, POSITION x)
947 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
949 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
951 if ((y != creature_ptr->y) && (x != creature_ptr->x))
953 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
954 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
955 update_local_illumination_aux(yy, xx);
956 update_local_illumination_aux(y, xx);
957 update_local_illumination_aux(yy, x);
959 else if (x != creature_ptr->x) /* y == creature_ptr->y */
961 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
962 for (i = -1; i <= 1; i++)
965 update_local_illumination_aux(yy, xx);
968 update_local_illumination_aux(yy, x);
970 update_local_illumination_aux(yy, x);
972 else if (y != creature_ptr->y) /* x == creature_ptr->x */
974 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
975 for (i = -1; i <= 1; i++)
978 update_local_illumination_aux(yy, xx);
981 update_local_illumination_aux(y, xx);
983 update_local_illumination_aux(y, xx);
985 else /* Player's grid */
987 for (i = 0; i < 8; i++)
991 update_local_illumination_aux(yy, xx);
995 #else /* COMPLEX_WALL_ILLUMINATION */
997 if ((y != creature_ptr->y) && (x != creature_ptr->x))
999 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
1000 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
1001 update_local_illumination_aux(yy, xx);
1003 else if (x != creature_ptr->x) /* y == creature_ptr->y */
1005 xx = (x < creature_ptr->x) ? (x - 1) : (x + 1);
1006 for (i = -1; i <= 1; i++)
1009 update_local_illumination_aux(yy, xx);
1012 else if (y != creature_ptr->y) /* x == creature_ptr->x */
1014 yy = (y < creature_ptr->y) ? (y - 1) : (y + 1);
1015 for (i = -1; i <= 1; i++)
1018 update_local_illumination_aux(yy, xx);
1021 else /* Player's grid */
1023 for (i = 0; i < 8; i++)
1025 yy = y + ddy_cdd[i];
1026 xx = x + ddx_cdd[i];
1027 update_local_illumination_aux(yy, xx);
1031 #endif /* COMPLEX_WALL_ILLUMINATION */
1036 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
1037 * @return 視覚に収められていないならTRUEを返す
1038 * @details player_can_see_bold()関数の返り値の否定を返している。
1042 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
1047 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
1050 * @return 各種の変更が可能ならTRUEを返す。
1052 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
1054 bool cave_valid_bold(POSITION y, POSITION x)
1056 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1057 OBJECT_IDX this_o_idx, next_o_idx = 0;
1059 /* Forbid perma-grids */
1060 if (cave_perma_grid(g_ptr)) return (FALSE);
1063 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1066 o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
1067 next_o_idx = o_ptr->next_o_idx;
1069 /* Forbid artifact grids */
1070 if (object_is_artifact(o_ptr)) return (FALSE);
1080 * Place an attr/char pair at the given map coordinate, if legal.
1082 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
1084 /* Only do "legal" locations */
1085 if (panel_contains(y, x))
1087 /* Hack -- fake monochrome */
1090 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1091 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1092 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1095 /* Draw the char using the attr */
1096 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
1105 * Memorize interesting viewable object/features in the given grid
1107 * This function should only be called on "legal" grids.
1109 * This function will memorize the object and/or feature in the given
1110 * grid, if they are (1) viewable and (2) interesting. Note that all
1111 * objects are interesting, all terrain features except floors (and
1112 * invisible traps) are interesting, and floors (and invisible traps)
1113 * are interesting sometimes (depending on various options involving
1114 * the illumination of floor grids).
1116 * The automatic memorization of all objects and non-floor terrain
1117 * features as soon as they are displayed allows incredible amounts
1118 * of optimization in various places, especially "map_info()".
1120 * Note that the memorization of objects is completely separate from
1121 * the memorization of terrain features, preventing annoying floor
1122 * memorization when a detected object is picked up from a dark floor,
1123 * and object memorization when an object is dropped into a floor grid
1124 * which is memorized but out-of-sight.
1126 * This function should be called every time the "memorization" of
1127 * a grid (or the object in a grid) is called into question, such
1128 * as when an object is created in a grid, when a terrain feature
1129 * "changes" from "floor" to "non-floor", when any grid becomes
1130 * "illuminated" or "viewable", and when a "floor" grid becomes
1133 * Note the relatively efficient use of this function by the various
1134 * "update_view()" and "update_lite()" calls, to allow objects and
1135 * terrain features to be memorized (and drawn) whenever they become
1136 * viewable or illuminated in any way, but not when they "maintain"
1137 * or "lose" their previous viewability or illumination.
1139 * Note the butchered "internal" version of "player_can_see_bold()",
1140 * optimized primarily for the most common cases, that is, for the
1141 * non-marked floor grids.
1143 void note_spot(POSITION y, POSITION x)
1145 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1146 OBJECT_IDX this_o_idx, next_o_idx = 0;
1148 /* Blind players see nothing */
1149 if (p_ptr->blind) return;
1151 /* Analyze non-torch-lit grids */
1152 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
1154 /* Require line of sight to the grid */
1155 if (!(g_ptr->info & (CAVE_VIEW))) return;
1157 /* Require "perma-lite" of the grid */
1158 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1161 if (!p_ptr->see_nocto) return;
1166 /* Hack -- memorize objects */
1167 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1169 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
1170 next_o_idx = o_ptr->next_o_idx;
1172 /* Memorize objects */
1173 o_ptr->marked |= OM_FOUND;
1177 /* Hack -- memorize grids */
1178 if (!(g_ptr->info & (CAVE_MARK)))
1180 /* Feature code (applying "mimic" field) */
1181 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
1183 /* Memorize some "boring" grids */
1184 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1186 /* Option -- memorize all torch-lit floors */
1187 if (view_torch_grids &&
1188 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
1190 g_ptr->info |= (CAVE_MARK);
1193 /* Option -- memorize all perma-lit floors */
1194 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
1196 g_ptr->info |= (CAVE_MARK);
1200 /* Memorize normal grids */
1201 else if (have_flag(f_ptr->flags, FF_LOS))
1203 g_ptr->info |= (CAVE_MARK);
1206 /* Memorize torch-lit walls */
1207 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1209 g_ptr->info |= (CAVE_MARK);
1212 /* Memorize walls seen by noctovision of Ninja */
1213 else if (p_ptr->see_nocto)
1215 g_ptr->info |= (CAVE_MARK);
1218 /* Memorize certain non-torch-lit wall grids */
1219 else if (check_local_illumination(y, x))
1221 g_ptr->info |= (CAVE_MARK);
1225 /* Memorize terrain of the grid */
1226 g_ptr->info |= (CAVE_KNOWN);
1230 * Redraw (on the screen) a given MAP location
1232 * This function should only be called on "legal" grids
1234 void lite_spot(POSITION y, POSITION x)
1236 /* Redraw if on screen */
1237 if (panel_contains(y, x) && in_bounds2(p_ptr->current_floor_ptr, y, x))
1244 map_info(y, x, &a, &c, &ta, &tc);
1246 /* Hack -- fake monochrome */
1249 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
1250 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
1251 else if (p_ptr->wraith_form) a = TERM_L_DARK;
1254 /* Hack -- Queue it */
1255 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
1257 /* Update sub-windows */
1258 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1263 * Some comments on the grid flags. -BEN-
1266 * One of the major bottlenecks in previous versions of Angband was in
1267 * the calculation of "line of sight" from the player to various grids,
1268 * such as monsters. This was such a nasty bottleneck that a lot of
1269 * silly things were done to reduce the dependancy on "line of sight",
1270 * for example, you could not "see" any grids in a lit room until you
1271 * actually entered the room, and there were all kinds of bizarre grid
1272 * flags to enable this behavior. This is also why the "call light"
1273 * spells always lit an entire room.
1275 * The code below provides functions to calculate the "field of view"
1276 * for the player, which, once calculated, provides extremely fast
1277 * calculation of "line of sight from the player", and to calculate
1278 * the "field of torch lite", which, again, once calculated, provides
1279 * extremely fast calculation of "which grids are lit by the player's
1280 * lite source". In addition to marking grids as "GRID_VIEW" and/or
1281 * "GRID_LITE", as appropriate, these functions maintain an array for
1282 * each of these two flags, each array containing the locations of all
1283 * of the grids marked with the appropriate flag, which can be used to
1284 * very quickly scan through all of the grids in a given set.
1286 * To allow more "semantically valid" field of view semantics, whenever
1287 * the field of view (or the set of torch lit grids) changes, all of the
1288 * grids in the field of view (or the set of torch lit grids) are "drawn"
1289 * so that changes in the world will become apparent as soon as possible.
1290 * This has been optimized so that only grids which actually "change" are
1291 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
1292 * of the grids which are entering or leaving the relevent set of grids.
1294 * These new methods are so efficient that the old nasty code was removed.
1296 * Note that there is no reason to "update" the "viewable space" unless
1297 * the player "moves", or walls/doors are created/destroyed, and there
1298 * is no reason to "update" the "torch lit grids" unless the field of
1299 * view changes, or the "light radius" changes. This means that when
1300 * the player is resting, or digging, or doing anything that does not
1301 * involve movement or changing the state of the dungeon, there is no
1302 * need to update the "view" or the "lite" regions, which is nice.
1304 * Note that the calls to the nasty "los()" function have been reduced
1305 * to a bare minimum by the use of the new "field of view" calculations.
1307 * I wouldn't be surprised if slight modifications to the "update_view()"
1308 * function would allow us to determine "reverse line-of-sight" as well
1309 * as "normal line-of-sight", which would allow monsters to use a more
1310 * "correct" calculation to determine if they can "see" the player. For
1311 * now, monsters simply "cheat" somewhat and assume that if the player
1312 * has "line of sight" to the monster, then the monster can "pretend"
1313 * that it has "line of sight" to the player.
1316 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
1317 * grid and maintains an array of all "CAVE_LITE" grids.
1319 * This set of grids is the complete set of all grids which are lit by
1320 * the players light source, which allows the "player_can_see_bold()"
1321 * function to work very quickly.
1323 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
1324 * fact, the player (unless blind) can always "see" all grids which are
1325 * marked as "CAVE_LITE", unless they are "off screen".
1328 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
1329 * grid and maintains an array of all "CAVE_VIEW" grids.
1331 * This set of grids is the complete set of all grids within line of sight
1332 * of the player, allowing the "player_has_los_bold()" macro to work very
1336 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
1337 * temporary internal flag to mark those grids which are not only in view,
1338 * but which are also "easily" in line of sight of the player. This flag
1339 * is always cleared when we are done.
1342 * The current "update_lite()" and "update_view()" algorithms use the
1343 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
1344 * to keep track of which grids were previously marked as "CAVE_LITE" or
1345 * "CAVE_VIEW", which allows us to optimize the "screen updates".
1347 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
1348 * for various other purposes, such as spreading lite or darkness during
1349 * "lite_room()" / "unlite_room()", and for calculating monster flow.
1352 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
1353 * in some way permanently lit. However, for the player to "see" anything
1354 * in the grid, as determined by "player_can_see()", the player must not be
1355 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
1356 * grids, even if marked as "perma lit", are only illuminated if they touch
1357 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
1360 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
1361 * that even if the player cannot "see" the grid, he "knows" the terrain in
1362 * that grid. This is used to "remember" walls/doors/stairs/floors when they
1363 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite(p_ptr, )",
1364 * or when one of the "memorize floor grids" options induces memorization.
1366 * Objects are "memorized" in a different way, using a special "marked" flag
1367 * on the object itself, which is set when an object is observed or detected.
1370 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
1371 * and should be illuminated by "lite room" and "darkness" spells.
1374 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
1375 * and should be unavailable for "teleportation" destinations.
1378 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
1379 * which is observed, and the "view_torch_grids" allows the player to memorize
1380 * every torch-lit grid. The player will always memorize important walls,
1381 * doors, stairs, and other terrain features, as well as any "detected" grids.
1383 * Note that the new "update_view()" method allows, among other things, a room
1384 * to be "partially" seen as the player approaches it, with a growing cone of
1385 * floor appearing as the player gets closer to the door. Also, by not turning
1386 * on the "memorize perma-lit grids" option, the player will only "see" those
1387 * floor grids which are actually in line of sight.
1389 * And my favorite "plus" is that you can now use a special option to draw the
1390 * "floors" in the "viewable region" brightly (actually, to draw the *other*
1391 * grids dimly), providing a "pretty" effect as the player runs around, and
1392 * to efficiently display the "torch lite" in a special color.
1395 * Some comments on the "update_view()" algorithm...
1397 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
1398 * and only has to call "los()" on the borderline cases. The major axes/diags
1399 * even terminate early when they hit walls. I need to find a quick way
1400 * to "terminate" the other scans.
1402 * Note that in the worst case (a big empty area with say 5% scattered walls),
1403 * each of the 1500 or so nearby grids is checked once, most of them getting
1404 * an "instant" rating, and only a small portion requiring a call to "los()".
1406 * The only time that the algorithm appears to be "noticeably" too slow is
1407 * when running, and this is usually only important in town, since the town
1408 * provides about the worst scenario possible, with large open regions and
1409 * a few scattered obstructions. There is a special "efficiency" option to
1410 * allow the player to reduce his field of view in town, if needed.
1412 * In the "best" case (say, a normal stretch of corridor), the algorithm
1413 * makes one check for each viewable grid, and makes no calls to "los()".
1414 * So running in corridors is very fast, and if a lot of monsters are
1415 * nearby, it is much faster than the old methods.
1417 * Note that resting, most normal commands, and several forms of running,
1418 * plus all commands executed near large groups of monsters, are strictly
1419 * more efficient with "update_view()" that with the old "compute los() on
1420 * demand" method, primarily because once the "field of view" has been
1421 * calculated, it does not have to be recalculated until the player moves
1422 * (or a wall or door is created or destroyed).
1424 * Note that we no longer have to do as many "los()" checks, since once the
1425 * "view" region has been built, very few things cause it to be "changed"
1426 * (player movement, and the opening/closing of doors, changes in wall status).
1427 * Note that door/wall changes are only relevant when the door/wall itself is
1428 * in the "view" region.
1430 * The algorithm seems to only call "los()" from zero to ten times, usually
1431 * only when coming down a corridor into a room, or standing in a room, just
1432 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
1433 * we will be reducing the calls to "los()".
1435 * I am thinking in terms of an algorithm that "walks" from the central point
1436 * out to the maximal "distance", at each point, determining the "view" code
1437 * (above). For each grid not on a major axis or diagonal, the "view" code
1438 * depends on the "cave_los_bold()" and "view" of exactly two other grids
1439 * (the one along the nearest diagonal, and the one next to that one, see
1440 * "update_view_aux()"...).
1442 * We "memorize" the viewable space array, so that at the cost of under 3000
1443 * bytes, we reduce the time taken by "forget_view()" to one assignment for
1444 * each grid actually in the "viewable space". And for another 3000 bytes,
1445 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
1446 * are also used by other routines, thus reducing the cost to almost nothing.
1448 * A similar thing is done for "forget_lite()" in which case the savings are
1449 * much less, but save us from doing bizarre maintenance checking.
1451 * In the worst "normal" case (in the middle of the town), the reachable space
1452 * actually reaches to more than half of the largest possible "circle" of view,
1453 * or about 800 grids, and in the worse case (in the middle of a dungeon level
1454 * where all the walls have been removed), the reachable space actually reaches
1455 * the theoretical maximum size of just under 1500 grids.
1457 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
1458 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
1459 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
1460 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
1461 * entire possible space (including initialization) in one step per grid. If
1462 * we do the "clearing" as a separate step (and use an array of "view" grids),
1463 * then the clearing will take as many steps as grids that were viewed, and the
1464 * algorithm will be able to "stop" scanning at various points.
1465 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
1469 * Mega-Hack -- Delayed visual update
1470 * Only used if update_view(), update_lite() or update_mon_lite() was called
1472 void delayed_visual_update(void)
1478 /* Update needed grids */
1479 for (i = 0; i < p_ptr->current_floor_ptr->redraw_n; i++)
1481 y = p_ptr->current_floor_ptr->redraw_y[i];
1482 x = p_ptr->current_floor_ptr->redraw_x[i];
1483 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1485 /* Update only needed grids (prevent multiple updating) */
1486 if (!(g_ptr->info & CAVE_REDRAW)) continue;
1488 /* If required, note */
1489 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
1493 /* Hack -- Visual update of monster on this grid */
1494 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1496 /* No longer in the array */
1497 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
1501 p_ptr->current_floor_ptr->redraw_n = 0;
1506 * Hack -- forget the "flow" information
1508 void forget_flow(void)
1512 /* Check the entire dungeon */
1513 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
1515 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
1517 /* Forget the old data */
1518 p_ptr->current_floor_ptr->grid_array[y][x].dist = 0;
1519 p_ptr->current_floor_ptr->grid_array[y][x].cost = 0;
1520 p_ptr->current_floor_ptr->grid_array[y][x].when = 0;
1527 * Hack - speed up the update_flow algorithm by only doing
1528 * it everytime the player moves out of LOS of the last
1531 static POSITION flow_x = 0;
1532 static POSITION flow_y = 0;
1537 * Hack -- fill in the "cost" field of every grid that the player
1538 * can "reach" with the number of steps needed to reach that grid.
1539 * This also yields the "distance" of the player from every grid.
1541 * In addition, mark the "when" of the grids that can reach
1542 * the player with the incremented value of "flow_n".
1544 * Hack -- use the "seen" array as a "circular queue".
1546 * We do not need a priority queue because the cost from grid
1547 * to grid is always "one" and we process them in order.
1549 void update_flow(void)
1556 /* Paranoia -- make sure the array is empty */
1557 if (tmp_pos.n) return;
1559 /* The last way-point is on the map */
1560 if (p_ptr->running && in_bounds(p_ptr->current_floor_ptr, flow_y, flow_x))
1562 /* The way point is in sight - do not update. (Speedup) */
1563 if (p_ptr->current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
1566 /* Erase all of the current flow information */
1567 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
1569 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
1571 p_ptr->current_floor_ptr->grid_array[y][x].cost = 0;
1572 p_ptr->current_floor_ptr->grid_array[y][x].dist = 0;
1576 /* Save player position */
1580 /* Add the player's grid to the queue */
1581 tmp_pos.y[0] = p_ptr->y;
1582 tmp_pos.x[0] = p_ptr->x;
1584 /* Now process the queue */
1585 while (flow_head != flow_tail)
1589 /* Extract the next entry */
1590 ty = tmp_pos.y[flow_tail];
1591 tx = tmp_pos.x[flow_tail];
1593 /* Forget that entry */
1594 if (++flow_tail == TEMP_MAX) flow_tail = 0;
1596 /* Add the "children" */
1597 for (d = 0; d < 8; d++)
1599 int old_head = flow_head;
1600 byte_hack m = p_ptr->current_floor_ptr->grid_array[ty][tx].cost + 1;
1601 byte_hack n = p_ptr->current_floor_ptr->grid_array[ty][tx].dist + 1;
1604 /* Child location */
1605 y = ty + ddy_ddd[d];
1606 x = tx + ddx_ddd[d];
1608 /* Ignore player's grid */
1609 if (player_bold(y, x)) continue;
1611 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1613 if (is_closed_door(g_ptr->feat)) m += 3;
1615 /* Ignore "pre-stamped" entries */
1616 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
1618 /* Ignore "walls" and "rubble" */
1619 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1621 /* Save the flow cost */
1622 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
1623 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
1625 /* Hack -- limit flow depth */
1626 if (n == MONSTER_FLOW_DEPTH) continue;
1628 /* Enqueue that entry */
1629 tmp_pos.y[flow_head] = y;
1630 tmp_pos.x[flow_head] = x;
1632 /* Advance the queue */
1633 if (++flow_head == TEMP_MAX) flow_head = 0;
1635 /* Hack -- notice overflow by forgetting new entry */
1636 if (flow_head == flow_tail) flow_head = old_head;
1642 static int scent_when = 0;
1645 * Characters leave scent trails for perceptive monsters to track.
1647 * Smell is rather more limited than sound. Many creatures cannot use
1648 * it at all, it doesn't extend very far outwards from the character's
1649 * current position, and monsters can use it to home in the character,
1650 * but not to run away from him.
1652 * Smell is valued according to age. When a character takes his current_world_ptr->game_turn,
1653 * scent is aged by one, and new scent of the current age is laid down.
1654 * Speedy characters leave more scent, true, but it also ages faster,
1655 * which makes it harder to hunt them down.
1657 * Whenever the age count loops, most of the scent trail is erased and
1658 * the age of the remainder is recalculated.
1660 void update_smell(void)
1665 /* Create a table that controls the spread of scent */
1666 const int scent_adjust[5][5] =
1675 /* Loop the age and adjust scent values when necessary */
1676 if (++scent_when == 254)
1678 /* Scan the entire dungeon */
1679 for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
1681 for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
1683 int w = p_ptr->current_floor_ptr->grid_array[y][x].when;
1684 p_ptr->current_floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
1693 /* Lay down new scent */
1694 for (i = 0; i < 5; i++)
1696 for (j = 0; j < 5; j++)
1700 /* Translate table to map grids */
1701 y = i + p_ptr->y - 2;
1702 x = j + p_ptr->x - 2;
1705 if (!in_bounds(p_ptr->current_floor_ptr, y, x)) continue;
1707 g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1709 /* Walls, water, and lava cannot hold scent. */
1710 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
1712 /* Grid must not be blocked by walls from the character */
1713 if (!player_has_los_bold(y, x)) continue;
1715 /* Note grids that are too far away */
1716 if (scent_adjust[i][j] == -1) continue;
1718 /* Mark the grid with new scent */
1719 g_ptr->when = scent_when + scent_adjust[i][j];
1727 * Change the "feat" flag for a grid, and notice/redraw the grid
1729 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
1731 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1732 feature_type *f_ptr = &f_info[feat];
1733 bool old_los, old_mirror;
1735 if (!current_world_ptr->character_dungeon)
1737 /* Clear mimic type */
1740 /* Change the feature */
1743 /* Hack -- glow the GLOW terrain */
1744 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1749 for (i = 0; i < 9; i++)
1751 yy = y + ddy_ddd[i];
1752 xx = x + ddx_ddd[i];
1753 if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
1754 p_ptr->current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
1761 old_los = cave_have_flag_bold(y, x, FF_LOS);
1762 old_mirror = is_mirror_grid(g_ptr);
1764 /* Clear mimic type */
1767 /* Change the feature */
1770 /* Remove flag for mirror/glyph */
1771 g_ptr->info &= ~(CAVE_OBJECT);
1773 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1775 g_ptr->info &= ~(CAVE_GLOW);
1776 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1778 update_local_illumination(p_ptr, y, x);
1781 /* Check for change to boring grid */
1782 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
1783 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1788 /* Check if los has changed */
1789 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
1792 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1794 update_local_illumination(p_ptr, y, x);
1796 #endif /* COMPLEX_WALL_ILLUMINATION */
1798 /* Update the visuals */
1799 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
1802 /* Hack -- glow the GLOW terrain */
1803 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
1809 for (i = 0; i < 9; i++)
1811 yy = y + ddy_ddd[i];
1812 xx = x + ddx_ddd[i];
1813 if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
1814 cc_ptr = &p_ptr->current_floor_ptr->grid_array[yy][xx];
1815 cc_ptr->info |= CAVE_GLOW;
1817 if (player_has_los_grid(cc_ptr))
1819 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
1826 update_local_illumination(p_ptr, yy, xx);
1829 if (p_ptr->special_defense & NINJA_S_STEALTH)
1831 if (p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(p_ptr, FALSE);
1836 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
1838 feature_type *f_ptr = &f_info[newfeat];
1840 if (have_flag(f_ptr->flags, FF_CONVERT))
1842 switch (f_ptr->subtype)
1844 case CONVERT_TYPE_FLOOR:
1845 return feat_ground_type[randint0(100)];
1846 case CONVERT_TYPE_WALL:
1847 return feat_wall_type[randint0(100)];
1848 case CONVERT_TYPE_INNER:
1849 return feat_wall_inner;
1850 case CONVERT_TYPE_OUTER:
1851 return feat_wall_outer;
1852 case CONVERT_TYPE_SOLID:
1853 return feat_wall_solid;
1854 case CONVERT_TYPE_STREAM1:
1855 return d_info[p_ptr->dungeon_idx].stream1;
1856 case CONVERT_TYPE_STREAM2:
1857 return d_info[p_ptr->dungeon_idx].stream2;
1862 else return newfeat;
1867 * Take a feature, determine what that feature becomes
1868 * through applying the given action.
1870 FEAT_IDX feat_state(FEAT_IDX feat, int action)
1872 feature_type *f_ptr = &f_info[feat];
1875 /* Get the new feature */
1876 for (i = 0; i < MAX_FEAT_STATES; i++)
1878 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
1881 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
1883 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
1887 * Takes a location and action and changes the feature at that
1888 * location through applying the given action.
1890 void cave_alter_feat(POSITION y, POSITION x, int action)
1892 /* Set old feature */
1893 FEAT_IDX oldfeat = p_ptr->current_floor_ptr->grid_array[y][x].feat;
1895 /* Get the new feat */
1896 FEAT_IDX newfeat = feat_state(oldfeat, action);
1899 if (newfeat == oldfeat) return;
1901 /* Set the new feature */
1902 cave_set_feat(y, x, newfeat);
1904 if (!(feature_action_flags[action] & FAF_NO_DROP))
1906 feature_type *old_f_ptr = &f_info[oldfeat];
1907 feature_type *f_ptr = &f_info[newfeat];
1911 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
1913 /* Place some gold */
1919 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)))
1922 place_object(y, x, 0L);
1926 if (found && current_world_ptr->character_dungeon && player_can_see_bold(y, x))
1928 msg_print(_("何かを発見した!", "You have found something!"));
1932 if (feature_action_flags[action] & FAF_CRASH_GLASS)
1934 feature_type *old_f_ptr = &f_info[oldfeat];
1936 if (have_flag(old_f_ptr->flags, FF_GLASS) && current_world_ptr->character_dungeon)
1938 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(p_ptr->current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
1939 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
1945 /* Remove a mirror */
1946 void remove_mirror(POSITION y, POSITION x)
1948 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
1950 /* Remove the mirror */
1951 g_ptr->info &= ~(CAVE_OBJECT);
1954 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
1956 g_ptr->info &= ~(CAVE_GLOW);
1957 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
1958 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
1960 update_local_illumination(p_ptr, y, x);
1970 * Return TRUE if there is a mirror on the grid.
1972 bool is_mirror_grid(grid_type *g_ptr)
1974 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
1982 * Return TRUE if there is a mirror on the grid.
1984 bool is_glyph_grid(grid_type *g_ptr)
1986 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
1994 * Return TRUE if there is a mirror on the grid.
1996 bool is_explosive_rune_grid(grid_type *g_ptr)
1998 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
2005 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
2006 * @param m_idx モンスターID
2010 * @return テレポート先として妥当ならばtrue
2012 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
2014 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
2015 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
2016 feature_type *f_ptr = &f_info[g_ptr->feat];
2018 /* Require "teleportable" space */
2019 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
2021 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
2022 if (player_bold(y, x)) return FALSE;
2024 /* Hack -- no teleport onto glyph of warding */
2025 if (is_glyph_grid(g_ptr)) return FALSE;
2026 if (is_explosive_rune_grid(g_ptr)) return FALSE;
2028 if (!(mode & TELEPORT_PASSIVE))
2030 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
2037 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
2041 * @return テレポート先として妥当ならばtrue
2043 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
2045 grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
2046 feature_type *f_ptr = &f_info[g_ptr->feat];
2048 /* Require "teleportable" space */
2049 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
2051 /* No magical teleporting into vaults and such */
2052 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
2054 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
2056 /* don't teleport on a trap. */
2057 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
2059 if (!(mode & TELEPORT_PASSIVE))
2061 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
2063 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
2065 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
2068 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
2070 /* Always forbid deep lava */
2071 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
2073 /* Forbid shallow lava when the player don't have levitation */
2074 if (!p_ptr->levitation) return FALSE;
2083 * @brief 地形は開くものであって、かつ開かれているかを返す /
2084 * Attempt to open the given chest at the given location
2086 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
2088 bool is_open(FEAT_IDX feat)
2090 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
2094 * @brief プレイヤーが地形踏破可能かを返す
2095 * @param feature 判定したい地形ID
2096 * @param mode 移動に関するオプションフラグ
2097 * @return 移動可能ならばTRUEを返す
2099 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
2101 feature_type *f_ptr = &f_info[feature];
2103 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);
2105 if (have_flag(f_ptr->flags, FF_PATTERN))
2107 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
2110 if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
2111 if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
2112 if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
2114 if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;