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
23 #include "object-flavor.h"
24 #include "object-hook.h"
32 #include "monster-status.h"
33 #include "player-status.h"
35 #include "view-mainwindow.h"
37 static byte display_autopick; /*!< 自動拾い状態の設定フラグ */
38 static int match_autopick;
39 static object_type *autopick_obj; /*!< 各種自動拾い処理時に使うオブジェクトポインタ */
40 static int feat_priority; /*!< マップ縮小表示時に表示すべき地形の優先度を保管する */
44 * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
45 * @return 配置に成功したらTRUEを返す
47 bool new_player_spot(void)
49 POSITION y = 0, x = 0;
50 int max_attempts = 10000;
55 /* Place the player */
56 while (max_attempts--)
58 /* Pick a legal spot */
59 y = (POSITION)rand_range(1, current_floor_ptr->height - 2);
60 x = (POSITION)rand_range(1, current_floor_ptr->width - 2);
62 g_ptr = ¤t_floor_ptr->grid_array[y][x];
64 /* Must be a "naked" floor grid */
65 if (g_ptr->m_idx) continue;
66 if (current_floor_ptr->dun_level)
68 f_ptr = &f_info[g_ptr->feat];
70 if (max_attempts > 5000) /* Rule 1 */
72 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
76 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
77 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
80 /* Refuse to start on anti-teleport grids in dungeon */
81 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
83 if (!player_can_enter(g_ptr->feat, 0)) continue;
84 if (!in_bounds(y, x)) continue;
86 /* Refuse to start on anti-teleport grids */
87 if (g_ptr->info & (CAVE_ICKY)) continue;
92 if (max_attempts < 1) /* Should be -1, actually if we failed... */
95 /* Save the new player grid */
105 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
106 * @param y 配置を試みたいマスのY座標
107 * @param x 配置を試みたいマスのX座標
110 void place_random_stairs(POSITION y, POSITION x)
112 bool up_stairs = TRUE;
113 bool down_stairs = TRUE;
115 g_ptr = ¤t_floor_ptr->grid_array[y][x];
116 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
119 if (!current_floor_ptr->dun_level) up_stairs = FALSE;
122 if (ironman_downward) up_stairs = FALSE;
125 if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
128 if (quest_number(current_floor_ptr->dun_level) && (current_floor_ptr->dun_level > 1)) down_stairs = FALSE;
130 /* We can't place both */
131 if (down_stairs && up_stairs)
133 /* Choose a staircase randomly */
134 if (randint0(100) < 50) up_stairs = FALSE;
135 else down_stairs = FALSE;
138 /* Place the stairs */
139 if (up_stairs) place_up_stairs(y, x);
140 else if (down_stairs) place_down_stairs(y, x);
144 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
145 * @param y ドアの配置を試みたいマスのY座標
146 * @param x ドアの配置を試みたいマスのX座標
147 * @param room 部屋に接している場合向けのドア生成か否か
150 void place_random_door(POSITION y, POSITION x, bool room)
153 FEAT_IDX feat = feat_none;
154 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
156 /* Initialize mimic info */
159 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
161 place_floor_bold(y, x);
165 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
166 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
167 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
169 /* Choose an object */
170 tmp = randint0(1000);
172 /* Open doors (300/1000) */
175 /* Create open door */
176 feat = feat_door[type].open;
179 /* Broken doors (100/1000) */
182 /* Create broken door */
183 feat = feat_door[type].broken;
186 /* Secret doors (200/1000) */
189 /* Create secret door */
190 place_closed_door(y, x, type);
192 if (type != DOOR_CURTAIN)
194 /* Hide. If on the edge of room, use outer wall. */
195 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
197 /* Floor type terrain cannot hide a door */
198 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
200 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
202 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
209 /* Closed, locked, or stuck doors (400/1000) */
210 else place_closed_door(y, x, type);
214 if (feat != feat_none)
216 set_cave_feat(y, x, feat);
220 place_floor_bold(y, x);
224 delete_monster(y, x);
228 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
229 * @param y ドアの配置を試みたいマスのY座標
230 * @param x ドアの配置を試みたいマスのX座標
231 * @param type ドアの地形ID
234 void place_closed_door(POSITION y, POSITION x, int type)
237 FEAT_IDX feat = feat_none;
239 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
241 place_floor_bold(y, x);
245 /* Choose an object */
248 /* Closed doors (300/400) */
251 /* Create closed door */
252 feat = feat_door[type].closed;
255 /* Locked doors (99/400) */
258 /* Create locked door */
259 feat = feat_locked_door_random(type);
262 /* Stuck doors (1/400) */
265 /* Create jammed door */
266 feat = feat_jammed_door_random(type);
269 if (feat != feat_none)
271 cave_set_feat(y, x, feat);
273 /* Now it is not floor */
274 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
278 place_floor_bold(y, x);
283 * @brief 鍵のかかったドアを配置する
284 * @param y 配置したいフロアのY座標
285 * @param x 配置したいフロアのX座標
288 void place_locked_door(POSITION y, POSITION x)
290 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
292 place_floor_bold(y, x);
296 set_cave_feat(y, x, feat_locked_door_random((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
297 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
298 delete_monster(y, x);
305 * @param y 配置したいフロアのY座標
306 * @param x 配置したいフロアのX座標
307 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
310 void place_secret_door(POSITION y, POSITION x, int type)
312 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
314 place_floor_bold(y, x);
318 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
320 if (type == DOOR_DEFAULT)
322 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
323 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
324 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
327 /* Create secret door */
328 place_closed_door(y, x, type);
330 if (type != DOOR_CURTAIN)
332 /* Hide by inner wall because this is used in rooms only */
333 g_ptr->mimic = feat_wall_inner;
335 /* Floor type terrain cannot hide a door */
336 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
338 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
340 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
346 g_ptr->info &= ~(CAVE_FLOOR);
347 delete_monster(y, x);
352 * Routine used by the random vault creators to add a door to a location
353 * Note that range checking has to be done in the calling routine.
355 * The doors must be INSIDE the allocated region.
357 void add_door(POSITION x, POSITION y)
359 /* Need to have a wall in the center square */
360 if (!is_outer_bold(y, x)) return;
371 if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
372 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
375 place_secret_door(y, x, DOOR_DEFAULT);
377 /* set boundarys so don't get wide doors */
378 place_solid_bold(y, x - 1);
379 place_solid_bold(y, x + 1);
388 * where x = don't care
391 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
392 is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
395 place_secret_door(y, x, DOOR_DEFAULT);
397 /* set boundarys so don't get wide doors */
398 place_solid_bold(y - 1, x);
399 place_solid_bold(y + 1, x);
404 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
405 * @param y1 基準となるマスのY座標
406 * @param x1 基準となるマスのX座標
408 * @note Assumes "in_bounds(y1, x1)"
410 * XXX XXX This routine currently only counts actual "empty floor"\n
411 * grids which are not in rooms. We might want to also count stairs,\n
412 * open doors, closed doors, etc.
414 static int next_to_corr(POSITION y1, POSITION x1)
421 /* Scan adjacent grids */
422 for (i = 0; i < 4; i++)
424 /* Extract the location */
427 g_ptr = ¤t_floor_ptr->grid_array[y][x];
429 /* Skip non floors */
430 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
432 /* Skip non "empty floor" grids */
433 if (!is_floor_grid(g_ptr))
436 /* Skip grids inside rooms */
437 if (g_ptr->info & (CAVE_ROOM)) continue;
439 /* Count these grids */
443 /* Return the number of corridors */
448 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
449 * @param y 判定を行いたいマスのY座標
450 * @param x 判定を行いたいマスのX座標
451 * @return ドアを設置可能ならばTRUEを返す
452 * @note Assumes "in_bounds(y1, x1)"
455 * Assumes "in_bounds(y, x)"\n
457 static bool possible_doorway(POSITION y, POSITION x)
459 /* Count the adjacent corridors */
460 if (next_to_corr(y, x) >= 2)
463 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
464 cave_have_flag_bold(y + 1, x, FF_WALL))
469 /* Check Horizontal */
470 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
471 cave_have_flag_bold(y, x + 1, FF_WALL))
482 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
483 * @param y 設置を行いたいマスのY座標
484 * @param x 設置を行いたいマスのX座標
487 void try_door(POSITION y, POSITION x)
488 { if (!in_bounds(y, x)) return;
491 if (cave_have_flag_bold(y, x, FF_WALL)) return;
493 /* Ignore room grids */
494 if (current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
496 /* Occasional door (if allowed) */
497 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
500 place_random_door(y, x, FALSE);
506 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
507 * @param x1 長方形の左端X座標(-1)
508 * @param x2 長方形の右端X座標(+1)
509 * @param y1 長方形の上端Y座標(-1)
510 * @param y2 長方形の下端Y座標(+1)
514 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
518 /* Place a full floor under the room */
519 for (y = y1 - 1; y <= y2 + 1; y++)
521 for (x = x1 - 1; x <= x2 + 1; x++)
523 place_floor_bold(y, x);
524 add_cave_info(y, x, CAVE_ROOM);
525 if (light) add_cave_info(y, x, CAVE_GLOW);
532 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
533 * @param x1 長方形の左端X座標(-1)
534 * @param x2 長方形の右端X座標(+1)
535 * @param y1 長方形の上端Y座標(-1)
536 * @param y2 長方形の下端Y座標(+1)
540 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
544 place_floor(x1, x2, y1, y2, light);
546 /* Walls around the room */
547 for (y = y1 - 1; y <= y2 + 1; y++)
549 place_outer_bold(y, x1 - 1);
550 place_outer_bold(y, x2 + 1);
552 for (x = x1 - 1; x <= x2 + 1; x++)
554 place_outer_bold(y1 - 1, x);
555 place_outer_bold(y2 + 1, x);
561 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
562 * @param y 配置したい中心マスのY座標
563 * @param x 配置したい中心マスのX座標
567 * Only really called by some of the "vault" routines.
569 void vault_objects(POSITION y, POSITION x, int num)
572 int i = 0, j = y, k = x;
577 /* Attempt to place 'num' objects */
578 for (; num > 0; --num)
580 /* Try up to 11 spots looking for empty space */
581 for (i = 0; i < 11; ++i)
583 /* Pick a random location */
584 while (dummy < SAFE_MAX_ATTEMPTS)
586 j = rand_spread(y, 2);
587 k = rand_spread(x, 3);
589 if (!in_bounds(j, k)) continue;
593 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
595 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
598 /* Require "clean" floor space */
599 g_ptr = ¤t_floor_ptr->grid_array[j][k];
600 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
602 if (randint0(100) < 75)
604 place_object(j, k, 0L);
611 /* Placement accomplished */
618 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
619 * @param y トラップを配置したいマスの中心Y座標
620 * @param x トラップを配置したいマスの中心X座標
621 * @param yd Y方向の配置分散マス数
622 * @param xd X方向の配置分散マス数
625 * Only really called by some of the "vault" routines.
627 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
629 int count = 0, y1 = y, x1 = x;
635 for (count = 0; count <= 5; count++)
638 while (dummy < SAFE_MAX_ATTEMPTS)
640 y1 = rand_spread(y, yd);
641 x1 = rand_spread(x, xd);
643 if (!in_bounds(y1, x1)) continue;
647 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
649 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
652 /* Require "naked" floor grids */
653 g_ptr = ¤t_floor_ptr->grid_array[y1][x1];
654 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
664 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
665 * @param y トラップを配置したいマスの中心Y座標
666 * @param x トラップを配置したいマスの中心X座標
667 * @param yd Y方向の配置分散マス数
668 * @param xd X方向の配置分散マス数
669 * @param num 配置したいトラップの数
672 * Only really called by some of the "vault" routines.
674 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
678 for (i = 0; i < num; i++)
680 vault_trap_aux(y, x, yd, xd);
685 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
686 * @param y1 モンスターを配置したいマスの中心Y座標
687 * @param x1 モンスターを配置したいマスの中心X座標
688 * @param num 配置したいモンスターの数
691 * Only really called by some of the "vault" routines.
693 void vault_monsters(POSITION y1, POSITION x1, int num)
699 /* Try to summon "num" monsters "near" the given location */
700 for (k = 0; k < num; k++)
702 /* Try nine locations */
703 for (i = 0; i < 9; i++)
707 /* Pick a nearby location */
708 scatter(&y, &x, y1, x1, d, 0);
710 /* Require "empty" floor grids */
711 g_ptr = ¤t_floor_ptr->grid_array[y][x];
712 if (!cave_empty_grid(g_ptr)) continue;
714 /* Place the monster (allow groups) */
715 current_floor_ptr->monster_level = current_floor_ptr->base_level + 2;
716 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
717 current_floor_ptr->monster_level = current_floor_ptr->base_level;
723 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
724 * @param x チェックするマスのX座標
725 * @param y チェックするマスのY座標
726 * @return 床系地形ならばTRUE
728 bool get_is_floor(POSITION x, POSITION y)
730 if (!in_bounds(y, x))
736 /* Do the real check */
737 if (is_floor_bold(y, x)) return (TRUE);
743 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
744 * @param x 地形を変えたいマスのX座標
745 * @param y 地形を変えたいマスのY座標
748 void set_floor(POSITION x, POSITION y)
750 if (!in_bounds(y, x))
756 if (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
758 /* A room border don't touch. */
762 /* Set to be floor if is a wall (don't touch lakes). */
763 if (is_extra_bold(y, x))
764 place_floor_bold(y, x);
768 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
769 * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
772 void place_bound_perm_wall(grid_type *g_ptr)
774 if (bound_walls_perm)
776 /* Clear boundary mimic */
781 feature_type *f_ptr = &f_info[g_ptr->feat];
783 /* Hack -- Decline boundary walls with known treasure */
784 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
785 !have_flag(f_ptr->flags, FF_SECRET))
786 g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
788 /* Set boundary mimic */
789 g_ptr->mimic = g_ptr->feat;
792 /* Add "solid" perma-wall */
793 place_solid_perm_grid(g_ptr);
798 * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
805 POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
807 POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
808 POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
810 /* Squared distance */
811 POSITION target = (dy * dy) + (dx * dx);
813 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
814 POSITION d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
819 if (!dy || !dx) return d;
823 /* Approximate error */
824 err = (target - d * d) / (2 * d);
826 /* No error - we are done */
829 /* Adjust distance */
838 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
839 * @param g_ptr マス構造体の参照ポインタ
840 * @return 看破済みの罠があるならTRUEを返す。
842 bool is_known_trap(grid_type *g_ptr)
844 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
845 is_trap(g_ptr->feat)) return TRUE;
853 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
854 * @param g_ptr マス構造体の参照ポインタ
855 * @return 隠されたドアがあるならTRUEを返す。
857 bool is_hidden_door(grid_type *g_ptr)
859 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
860 is_closed_door(g_ptr->feat))
867 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
872 * @return LOSが通っているならTRUEを返す。
874 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
875 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
877 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
879 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
880 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
881 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
883 * We assume that the "mathematical corner" of a non-floor tile does not\n
884 * block line of sight.\n
886 * Because this function uses (short) ints for all calculations, overflow may\n
887 * occur if dx and dy exceed 90.\n
889 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
890 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
891 * we can use integer arithmetic.\n
893 * We travel from start to finish along the longer axis, starting at the border\n
894 * between the first and second tiles, where the y offset = .5 * slope, taking\n
895 * into account the scale factor. See below.\n
897 * Also note that this function and the "move towards target" code do NOT\n
898 * share the same properties. Thus, you can see someone, target them, and\n
899 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
900 * by clever choice of target locations, you can sometimes throw a "curve".\n
902 * Note that "line of sight" is not "reflexive" in all cases.\n
904 * Use the "projectable()" routine to test "spell/missile line of sight".\n
906 * Use the "update_view()" function to determine player line-of-sight.\n
908 bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
928 /* Slope, or 1/Slope, of LOS */
932 /* Extract the offset */
936 /* Extract the absolute offset */
941 /* Handle adjacent (or identical) grids */
942 if ((ax < 2) && (ay < 2)) return TRUE;
945 /* Paranoia -- require "safe" origin */
946 /* if (!in_bounds(y1, x1)) return FALSE; */
947 /* if (!in_bounds(y2, x2)) return FALSE; */
950 /* Directly South/North */
953 /* South -- check for walls */
956 for (ty = y1 + 1; ty < y2; ty++)
958 if (!cave_los_bold(ty, x1)) return FALSE;
962 /* North -- check for walls */
965 for (ty = y1 - 1; ty > y2; ty--)
967 if (!cave_los_bold(ty, x1)) return FALSE;
975 /* Directly East/West */
978 /* East -- check for walls */
981 for (tx = x1 + 1; tx < x2; tx++)
983 if (!cave_los_bold(y1, tx)) return FALSE;
987 /* West -- check for walls */
990 for (tx = x1 - 1; tx > x2; tx--)
992 if (!cave_los_bold(y1, tx)) return FALSE;
1001 /* Extract some signs */
1002 sx = (dx < 0) ? -1 : 1;
1003 sy = (dy < 0) ? -1 : 1;
1006 /* Vertical "knights" */
1011 if (cave_los_bold(y1 + sy, x1)) return TRUE;
1015 /* Horizontal "knights" */
1020 if (cave_los_bold(y1, x1 + sx)) return TRUE;
1025 /* Calculate scale factor div 2 */
1028 /* Calculate scale factor */
1032 /* Travel horizontally */
1035 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
1041 /* Consider the special case where slope == 1. */
1052 /* Note (below) the case (qy == f2), where */
1053 /* the LOS exactly meets the corner of a tile. */
1056 if (!cave_los_bold(ty, tx)) return FALSE;
1067 if (!cave_los_bold(ty, tx)) return FALSE;
1080 /* Travel vertically */
1083 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
1099 /* Note (below) the case (qx == f2), where */
1100 /* the LOS exactly meets the corner of a tile. */
1103 if (!cave_los_bold(ty, tx)) return FALSE;
1114 if (!cave_los_bold(ty, tx)) return FALSE;
1131 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
1135 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
1138 * @return 指定された座標に照明がかかっているならTRUEを返す。。
1140 static bool check_local_illumination(POSITION y, POSITION x)
1142 /* Hack -- move towards player */
1143 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
1144 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
1146 /* Check for "local" illumination */
1148 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1150 /* Check for "complex" illumination */
1151 if ((feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][xx])) &&
1152 (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
1153 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[y][xx])) &&
1154 (current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
1155 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][x])) &&
1156 (current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
1162 #else /* COMPLEX_WALL_ILLUMINATION */
1164 /* Check for "simple" illumination */
1165 return (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
1167 #endif /* COMPLEX_WALL_ILLUMINATION */
1171 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
1172 #define update_local_illumination_aux(Y, X) \
1174 if (player_has_los_bold((Y), (X))) \
1176 /* Update the monster */ \
1177 if (current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster(current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
1179 /* Notice and redraw */ \
1180 note_spot((Y), (X)); \
1181 lite_spot((Y), (X)); \
1186 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
1191 void update_local_illumination(POSITION y, POSITION x)
1196 if (!in_bounds(y, x)) return;
1198 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1200 if ((y != p_ptr->y) && (x != p_ptr->x))
1202 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1203 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1204 update_local_illumination_aux(yy, xx);
1205 update_local_illumination_aux(y, xx);
1206 update_local_illumination_aux(yy, x);
1208 else if (x != p_ptr->x) /* y == p_ptr->y */
1210 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1211 for (i = -1; i <= 1; i++)
1214 update_local_illumination_aux(yy, xx);
1217 update_local_illumination_aux(yy, x);
1219 update_local_illumination_aux(yy, x);
1221 else if (y != p_ptr->y) /* x == p_ptr->x */
1223 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1224 for (i = -1; i <= 1; i++)
1227 update_local_illumination_aux(yy, xx);
1230 update_local_illumination_aux(y, xx);
1232 update_local_illumination_aux(y, xx);
1234 else /* Player's grid */
1236 for (i = 0; i < 8; i++)
1238 yy = y + ddy_cdd[i];
1239 xx = x + ddx_cdd[i];
1240 update_local_illumination_aux(yy, xx);
1244 #else /* COMPLEX_WALL_ILLUMINATION */
1246 if ((y != p_ptr->y) && (x != p_ptr->x))
1248 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1249 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1250 update_local_illumination_aux(yy, xx);
1252 else if (x != p_ptr->x) /* y == p_ptr->y */
1254 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1255 for (i = -1; i <= 1; i++)
1258 update_local_illumination_aux(yy, xx);
1261 else if (y != p_ptr->y) /* x == p_ptr->x */
1263 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1264 for (i = -1; i <= 1; i++)
1267 update_local_illumination_aux(yy, xx);
1270 else /* Player's grid */
1272 for (i = 0; i < 8; i++)
1274 yy = y + ddy_cdd[i];
1275 xx = x + ddx_cdd[i];
1276 update_local_illumination_aux(yy, xx);
1280 #endif /* COMPLEX_WALL_ILLUMINATION */
1285 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
1288 * @return 視覚に収められる状態ならTRUEを返す
1290 * He must have vision, illumination, and line of sight.\n
1292 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
1293 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
1295 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
1296 * that a wall is visible from any direction. That would be odd. Except\n
1297 * under wizard light, which might make sense. Thus, for walls, we require\n
1298 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
1299 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
1300 * in line of sight of the player.\n
1302 * This extra check is expensive, but it provides a more "correct" semantics.\n
1304 * Note that we should not run this check on walls which are "outer walls" of\n
1305 * the dungeon, or we will induce a memory fault, but actually verifying all\n
1306 * of the locations would be extremely expensive.\n
1308 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
1309 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
1310 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
1311 * and the player has more important things on his mind when he is attacking a\n
1312 * monster vault. It is annoying, but an extremely important optimization.\n
1314 * Note that "glowing walls" are only considered to be "illuminated" if the\n
1315 * grid which is next to the wall in the direction of the player is also a\n
1316 * "glowing" grid. This prevents the player from being able to "see" the\n
1317 * walls of illuminated rooms from a corridor outside the room.\n
1319 bool player_can_see_bold(POSITION y, POSITION x)
1323 /* Blind players see nothing */
1324 if (p_ptr->blind) return FALSE;
1326 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1328 /* Note that "torch-lite" yields "illumination" */
1329 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
1331 /* Require line of sight to the grid */
1332 if (!player_has_los_bold(y, x)) return FALSE;
1334 /* Noctovision of Ninja */
1335 if (p_ptr->see_nocto) return TRUE;
1337 /* Require "perma-lite" of the grid */
1338 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
1340 /* Feature code (applying "mimic" field) */
1341 /* Floors are simple */
1342 if (feat_supports_los(get_feat_mimic(g_ptr))) return TRUE;
1344 /* Check for "local" illumination */
1345 return check_local_illumination(y, x);
1349 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
1350 * @return 視覚に収められていないならTRUEを返す
1351 * @details player_can_see_bold()関数の返り値の否定を返している。
1355 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
1360 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
1363 * @return 各種の変更が可能ならTRUEを返す。
1365 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
1367 bool cave_valid_bold(POSITION y, POSITION x)
1369 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1370 OBJECT_IDX this_o_idx, next_o_idx = 0;
1372 /* Forbid perma-grids */
1373 if (cave_perma_grid(g_ptr)) return (FALSE);
1376 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1379 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1380 next_o_idx = o_ptr->next_o_idx;
1382 /* Forbid artifact grids */
1383 if (object_is_artifact(o_ptr)) return (FALSE);
1394 * 一般的にモンスターシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal monster codes
1396 static char image_monster_hack[] = \
1397 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
1400 * 一般的にオブジェクトシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal object codes
1402 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
1405 * @brief モンスターの表示を幻覚状態に差し替える / Mega-Hack -- Hallucinatory monster
1410 static void image_monster(TERM_COLOR *ap, SYMBOL_CODE *cp)
1412 /* Random symbol from set above */
1415 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
1417 *cp = r_ptr->x_char;
1418 *ap = r_ptr->x_attr;
1423 *cp = (one_in_(25) ?
1424 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1425 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1433 * @brief オブジェクトの表示を幻覚状態に差し替える / Hallucinatory object
1438 static void image_object(TERM_COLOR *ap, SYMBOL_CODE *cp)
1442 object_kind *k_ptr = &k_info[randint1(max_k_idx - 1)];
1444 *cp = k_ptr->x_char;
1445 *ap = k_ptr->x_attr;
1449 int n = sizeof(image_object_hack) - 1;
1451 *cp = image_object_hack[randint0(n)];
1460 * @brief オブジェクト&モンスターの表示を幻覚状態に差し替える / Hack -- Random hallucination
1465 static void image_random(TERM_COLOR *ap, SYMBOL_CODE *cp)
1467 /* Normally, assume monsters */
1468 if (randint0(100) < 75)
1470 image_monster(ap, cp);
1473 /* Otherwise, assume objects */
1476 image_object(ap, cp);
1481 * 照明の表現を行うための色合いの関係を{暗闇時, 照明時} で定義する /
1482 * This array lists the effects of "brightness" on various "base" colours.\n
1484 * This is used to do dynamic lighting effects in ascii :-)\n
1485 * At the moment, only the various "floor" tiles are affected.\n
1487 * The layout of the array is [x][0] = light and [x][1] = dark.\n
1489 static TERM_COLOR lighting_colours[16][2] =
1492 {TERM_L_DARK, TERM_DARK},
1495 {TERM_YELLOW, TERM_SLATE},
1498 {TERM_WHITE, TERM_L_DARK},
1501 {TERM_L_UMBER, TERM_UMBER},
1504 {TERM_RED, TERM_RED},
1507 {TERM_L_GREEN, TERM_GREEN},
1510 {TERM_BLUE, TERM_BLUE},
1513 {TERM_L_UMBER, TERM_RED},
1516 {TERM_SLATE, TERM_L_DARK},
1519 {TERM_WHITE, TERM_SLATE},
1522 {TERM_L_RED, TERM_BLUE},
1525 {TERM_YELLOW, TERM_ORANGE},
1528 {TERM_L_RED, TERM_L_RED},
1531 {TERM_L_GREEN, TERM_GREEN},
1534 {TERM_L_BLUE, TERM_L_BLUE},
1537 {TERM_L_UMBER, TERM_UMBER}
1544 void apply_default_feat_lighting(TERM_COLOR f_attr[F_LIT_MAX], SYMBOL_CODE f_char[F_LIT_MAX])
1546 TERM_COLOR s_attr = f_attr[F_LIT_STANDARD];
1547 SYMBOL_CODE s_char = f_char[F_LIT_STANDARD];
1550 if (is_ascii_graphics(s_attr)) /* For ASCII */
1552 f_attr[F_LIT_LITE] = lighting_colours[s_attr & 0x0f][0];
1553 f_attr[F_LIT_DARK] = lighting_colours[s_attr & 0x0f][1];
1554 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_char[i] = s_char;
1556 else /* For tile graphics */
1558 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_attr[i] = s_attr;
1559 f_char[F_LIT_LITE] = s_char + 2;
1560 f_char[F_LIT_DARK] = s_char + 1;
1566 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
1568 #define darkened_grid(C) \
1569 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
1574 * @brief Mコマンドによる縮小マップの表示を行う / Extract the attr/char to display at the given (legal) map location
1576 * Basically, we "paint" the chosen attr/char in several passes, starting\n
1577 * with any known "terrain features" (defaulting to darkness), then adding\n
1578 * any known "objects", and finally, adding any known "monsters". This\n
1579 * is not the fastest method but since most of the calls to this function\n
1580 * are made for grids with no monsters or objects, it is fast enough.\n
1582 * Note that this function, if used on the grid containing the "player",\n
1583 * will return the attr/char of the grid underneath the player, and not\n
1584 * the actual player attr/char itself, allowing a lot of optimization\n
1585 * in various "display" functions.\n
1587 * Note that the "zero" entry in the feature/object/monster arrays are\n
1588 * used to provide "special" attr/char codes, with "monster zero" being\n
1589 * used for the player attr/char, "object zero" being used for the "stack"\n
1590 * attr/char, and "feature zero" being used for the "nothing" attr/char,\n
1591 * though this function makes use of only "feature zero".\n
1593 * Note that monsters can have some "special" flags, including "ATTR_MULTI",\n
1594 * which means their color changes, and "ATTR_CLEAR", which means they take\n
1595 * the color of whatever is under them, and "CHAR_CLEAR", which means that\n
1596 * they take the symbol of whatever is under them. Technically, the flag\n
1597 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when\n
1598 * examined, but this flag is currently ignored.\n
1600 * Currently, we do nothing with multi-hued objects, because there are\n
1601 * not any. If there were, they would have to set "shimmer_objects"\n
1602 * when they were created, and then new "shimmer" code in "dungeon.c"\n
1603 * would have to be created handle the "shimmer" effect, and the code\n
1604 * in "current_floor_ptr->grid_array.c" would have to be updated to create the shimmer effect.\n
1606 * Note the effects of hallucination. Objects always appear as random\n
1607 * "objects", monsters as random "monsters", and normal grids occasionally\n
1608 * appear as random "monsters" or "objects", but note that these random\n
1609 * "monsters" and "objects" are really just "colored ascii symbols".\n
1611 * Note that "floors" and "invisible traps" (and "zero" features) are\n
1612 * drawn as "floors" using a special check for optimization purposes,\n
1613 * and these are the only features which get drawn using the special\n
1614 * lighting effects activated by "view_special_lite".\n
1616 * Note the use of the "mimic" field in the "terrain feature" processing,\n
1617 * which allows any feature to "pretend" to be another feature. This is\n
1618 * used to "hide" secret doors, and to make all "doors" appear the same,\n
1619 * and all "walls" appear the same, and "hidden" treasure stay hidden.\n
1620 * It is possible to use this field to make a feature "look" like a floor,\n
1621 * but the "special lighting effects" for floors will not be used.\n
1623 * Note the use of the new "terrain feature" information. Note that the\n
1624 * assumption that all interesting "objects" and "terrain features" are\n
1625 * memorized allows extremely optimized processing below. Note the use\n
1626 * of separate flags on objects to mark them as memorized allows a grid\n
1627 * to have memorized "terrain" without granting knowledge of any object\n
1628 * which may appear in that grid.\n
1630 * Note the efficient code used to determine if a "floor" grid is\n
1631 * "memorized" or "viewable" by the player, where the test for the\n
1632 * grid being "viewable" is based on the facts that (1) the grid\n
1633 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in\n
1634 * line of sight, and (3) the player must not be blind, and uses the\n
1635 * assumption that all torch-lit grids are in line of sight.\n
1637 * Note that floors (and invisible traps) are the only grids which are\n
1638 * not memorized when seen, so only these grids need to check to see if\n
1639 * the grid is "viewable" to the player (if it is not memorized). Since\n
1640 * most non-memorized grids are in fact walls, this induces *massive*\n
1641 * efficiency, at the cost of *forcing* the memorization of non-floor\n
1642 * grids when they are first seen. Note that "invisible traps" are\n
1643 * always treated exactly like "floors", which prevents "cheating".\n
1645 * Note the "special lighting effects" which can be activated for floor\n
1646 * grids using the "view_special_lite" option (for "white" floor grids),\n
1647 * causing certain grids to be displayed using special colors. If the\n
1648 * player is "blind", we will use "dark gray", else if the grid is lit\n
1649 * by the torch, and the "view_yellow_lite" option is set, we will use\n
1650 * "yellow", else if the grid is "dark", we will use "dark gray", else\n
1651 * if the grid is not "viewable", and the "view_bright_lite" option is\n
1652 * set, and the we will use "slate" (gray). We will use "white" for all\n
1653 * other cases, in particular, for illuminated viewable floor grids.\n
1655 * Note the "special lighting effects" which can be activated for wall\n
1656 * grids using the "view_granite_lite" option (for "white" wall grids),\n
1657 * causing certain grids to be displayed using special colors. If the\n
1658 * player is "blind", we will use "dark gray", else if the grid is lit\n
1659 * by the torch, and the "view_yellow_lite" option is set, we will use\n
1660 * "yellow", else if the "view_bright_lite" option is set, and the grid\n
1661 * is not "viewable", or is "dark", or is glowing, but not when viewed\n
1662 * from the player's current location, we will use "slate" (gray). We\n
1663 * will use "white" for all other cases, in particular, for correctly\n
1664 * illuminated viewable wall grids.\n
1666 * Note that, when "view_granite_lite" is set, we use an inline version\n
1667 * of the "player_can_see_bold()" function to check the "viewability" of\n
1668 * grids when the "view_bright_lite" option is set, and we do NOT use\n
1669 * any special colors for "dark" wall grids, since this would allow the\n
1670 * player to notice the walls of illuminated rooms from a hallway that\n
1671 * happened to run beside the room. The alternative, by the way, would\n
1672 * be to prevent the generation of hallways next to rooms, but this\n
1673 * would still allow problems when digging towards a room.\n
1675 * Note that bizarre things must be done when the "attr" and/or "char"\n
1676 * codes have the "high-bit" set, since these values are used to encode\n
1677 * various "special" pictures in some versions, and certain situations,\n
1678 * such as "multi-hued" or "clear" monsters, cause the attr/char codes\n
1679 * to be "scrambled" in various ways.\n
1681 * Note that eventually we may use the "&" symbol for embedded treasure,\n
1682 * and use the "*" symbol to indicate multiple objects, though this will\n
1683 * have to wait for Angband 2.8.0 or later. Note that currently, this\n
1684 * is not important, since only one object or terrain feature is allowed\n
1685 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.\n
1687 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of\n
1688 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect\n
1689 * then a whole lot of code should be changed... XXX XXX\n
1691 void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp)
1693 /* Get the current_floor_ptr->grid_array */
1694 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1696 OBJECT_IDX this_o_idx, next_o_idx = 0;
1698 /* Feature code (applying "mimic" field) */
1699 FEAT_IDX feat = get_feat_mimic(g_ptr);
1702 feature_type *f_ptr = &f_info[feat];
1707 /* Boring grids (floors, etc) */
1708 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1711 * Handle Memorized or visible floor
1713 * No visual when blinded.
1714 * (to prevent strange effects on darkness breath)
1716 * - Can see grids with CAVE_MARK.
1717 * - Can see grids with CAVE_LITE or CAVE_MNLT.
1718 * (Such grids also have CAVE_VIEW)
1719 * - Can see grids with CAVE_VIEW unless darkened by monsters.
1721 if (!p_ptr->blind &&
1722 ((g_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
1723 ((g_ptr->info & CAVE_VIEW) && (((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
1725 /* Normal attr/char */
1726 a = f_ptr->x_attr[F_LIT_STANDARD];
1727 c = f_ptr->x_char[F_LIT_STANDARD];
1729 if (p_ptr->wild_mode)
1731 /* Special lighting effects */
1732 /* Handle "night" */
1733 if (view_special_lite && !is_daytime())
1735 /* Use a darkened colour/tile */
1736 a = f_ptr->x_attr[F_LIT_DARK];
1737 c = f_ptr->x_char[F_LIT_DARK];
1741 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1742 else if (darkened_grid(g_ptr))
1744 /* Unsafe grid -- idea borrowed from Unangband */
1745 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1747 /* Access darkness */
1748 f_ptr = &f_info[feat];
1750 /* Char and attr of darkness */
1751 a = f_ptr->x_attr[F_LIT_STANDARD];
1752 c = f_ptr->x_char[F_LIT_STANDARD];
1755 /* Special lighting effects */
1756 else if (view_special_lite)
1758 /* Handle "torch-lit" grids */
1759 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1762 if (view_yellow_lite)
1764 /* Use a brightly lit colour/tile */
1765 a = f_ptr->x_attr[F_LIT_LITE];
1766 c = f_ptr->x_char[F_LIT_LITE];
1770 /* Handle "dark" grids */
1771 else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1773 /* Use a darkened colour/tile */
1774 a = f_ptr->x_attr[F_LIT_DARK];
1775 c = f_ptr->x_char[F_LIT_DARK];
1778 /* Handle "out-of-sight" grids */
1779 else if (!(g_ptr->info & CAVE_VIEW))
1782 if (view_bright_lite)
1784 /* Use a darkened colour/tile */
1785 a = f_ptr->x_attr[F_LIT_DARK];
1786 c = f_ptr->x_char[F_LIT_DARK];
1795 /* Unsafe grid -- idea borrowed from Unangband */
1796 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1798 /* Access darkness */
1799 f_ptr = &f_info[feat];
1801 /* Normal attr/char */
1802 a = f_ptr->x_attr[F_LIT_STANDARD];
1803 c = f_ptr->x_char[F_LIT_STANDARD];
1807 /* Interesting grids (non-floors) */
1810 /* Memorized grids */
1811 if (g_ptr->info & CAVE_MARK)
1813 /* Normal attr/char */
1814 a = f_ptr->x_attr[F_LIT_STANDARD];
1815 c = f_ptr->x_char[F_LIT_STANDARD];
1817 if (p_ptr->wild_mode)
1819 /* Special lighting effects */
1820 /* Handle "blind" or "night" */
1821 if (view_granite_lite && (p_ptr->blind || !is_daytime()))
1823 /* Use a darkened colour/tile */
1824 a = f_ptr->x_attr[F_LIT_DARK];
1825 c = f_ptr->x_char[F_LIT_DARK];
1829 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1830 else if (darkened_grid(g_ptr) && !p_ptr->blind)
1832 if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
1834 /* Unsafe grid -- idea borrowed from Unangband */
1835 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1837 /* Access darkness */
1838 f_ptr = &f_info[feat];
1840 /* Char and attr of darkness */
1841 a = f_ptr->x_attr[F_LIT_STANDARD];
1842 c = f_ptr->x_char[F_LIT_STANDARD];
1844 else if (view_granite_lite && view_bright_lite)
1846 /* Use a darkened colour/tile */
1847 a = f_ptr->x_attr[F_LIT_DARK];
1848 c = f_ptr->x_char[F_LIT_DARK];
1852 /* Special lighting effects */
1853 else if (view_granite_lite)
1855 /* Handle "blind" */
1858 /* Use a darkened colour/tile */
1859 a = f_ptr->x_attr[F_LIT_DARK];
1860 c = f_ptr->x_char[F_LIT_DARK];
1863 /* Handle "torch-lit" grids */
1864 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1867 if (view_yellow_lite)
1869 /* Use a brightly lit colour/tile */
1870 a = f_ptr->x_attr[F_LIT_LITE];
1871 c = f_ptr->x_char[F_LIT_LITE];
1875 /* Handle "view_bright_lite" */
1876 else if (view_bright_lite)
1879 if (!(g_ptr->info & CAVE_VIEW))
1881 /* Use a darkened colour/tile */
1882 a = f_ptr->x_attr[F_LIT_DARK];
1883 c = f_ptr->x_char[F_LIT_DARK];
1887 else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1889 /* Use a darkened colour/tile */
1890 a = f_ptr->x_attr[F_LIT_DARK];
1891 c = f_ptr->x_char[F_LIT_DARK];
1894 /* Not glowing correctly */
1895 else if (!have_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(y, x))
1897 /* Use a darkened colour/tile */
1898 a = f_ptr->x_attr[F_LIT_DARK];
1899 c = f_ptr->x_char[F_LIT_DARK];
1908 /* Unsafe grid -- idea borrowed from Unangband */
1909 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1911 /* Access feature */
1912 f_ptr = &f_info[feat];
1914 /* Normal attr/char */
1915 a = f_ptr->x_attr[F_LIT_STANDARD];
1916 c = f_ptr->x_char[F_LIT_STANDARD];
1920 if (feat_priority == -1) feat_priority = f_ptr->priority;
1922 /* Save the terrain info for the transparency effects */
1930 /* Hack -- rare random hallucination, except on outer dungeon walls */
1935 image_random(ap, cp);
1940 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1943 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1944 next_o_idx = o_ptr->next_o_idx;
1946 /* Memorized objects */
1947 if (o_ptr->marked & OM_FOUND)
1949 if (display_autopick)
1953 match_autopick = is_autopick(o_ptr);
1954 if (match_autopick == -1)
1957 act = autopick_list[match_autopick].action;
1959 if ((act & DO_DISPLAY) && (act & display_autopick))
1961 autopick_obj = o_ptr;
1965 match_autopick = -1;
1970 (*cp) = object_char(o_ptr);
1973 (*ap) = object_attr(o_ptr);
1977 /* Hack -- hallucination */
1978 if (p_ptr->image) image_object(ap, cp);
1985 /* Handle monsters */
1986 if (g_ptr->m_idx && display_autopick == 0)
1988 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
1990 /* Visible monster */
1993 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
2001 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
2002 * flags are always unseen.
2004 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
2010 image_monster(ap, cp);
2015 /* Monster attr/char */
2019 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
2020 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
2022 /* Desired monster attr/char */
2028 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
2029 * flags are always unseen.
2031 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
2038 /*** Monster's attr ***/
2039 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
2044 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
2046 /* Multi-hued attr */
2047 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
2048 else switch (randint1(7))
2050 case 1: *ap = TERM_RED; break;
2051 case 2: *ap = TERM_L_RED; break;
2052 case 3: *ap = TERM_WHITE; break;
2053 case 4: *ap = TERM_L_GREEN; break;
2054 case 5: *ap = TERM_BLUE; break;
2055 case 6: *ap = TERM_L_DARK; break;
2056 case 7: *ap = TERM_GREEN; break;
2059 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
2061 /* Use semi-random attr (usually mimics' colors vary) */
2062 *ap = g_ptr->m_idx % 15 + 1;
2070 /*** Monster's char ***/
2071 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
2076 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
2080 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
2081 *cp = tmp_r_ptr->x_char;
2082 *ap = tmp_r_ptr->x_attr;
2086 *cp = (one_in_(25) ?
2087 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
2088 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
2101 /* Handle "player" */
2102 if (player_bold(y, x))
2104 monster_race *r_ptr = &r_info[0];
2105 *ap = r_ptr->x_attr;
2106 *cp = r_ptr->x_char;
2113 * Moves the cursor to a given MAP (y,x) location
2115 void move_cursor_relative(int row, int col)
2117 /* Real co-ords convert to screen positions */
2118 row -= panel_row_prt;
2121 Term_gotoxy(panel_col_of(col), row);
2127 * Place an attr/char pair at the given map coordinate, if legal.
2129 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
2131 /* Only do "legal" locations */
2132 if (panel_contains(y, x))
2134 /* Hack -- fake monochrome */
2137 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2138 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2139 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2142 /* Draw the char using the attr */
2143 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
2152 * Memorize interesting viewable object/features in the given grid
2154 * This function should only be called on "legal" grids.
2156 * This function will memorize the object and/or feature in the given
2157 * grid, if they are (1) viewable and (2) interesting. Note that all
2158 * objects are interesting, all terrain features except floors (and
2159 * invisible traps) are interesting, and floors (and invisible traps)
2160 * are interesting sometimes (depending on various options involving
2161 * the illumination of floor grids).
2163 * The automatic memorization of all objects and non-floor terrain
2164 * features as soon as they are displayed allows incredible amounts
2165 * of optimization in various places, especially "map_info()".
2167 * Note that the memorization of objects is completely separate from
2168 * the memorization of terrain features, preventing annoying floor
2169 * memorization when a detected object is picked up from a dark floor,
2170 * and object memorization when an object is dropped into a floor grid
2171 * which is memorized but out-of-sight.
2173 * This function should be called every time the "memorization" of
2174 * a grid (or the object in a grid) is called into question, such
2175 * as when an object is created in a grid, when a terrain feature
2176 * "changes" from "floor" to "non-floor", when any grid becomes
2177 * "illuminated" or "viewable", and when a "floor" grid becomes
2180 * Note the relatively efficient use of this function by the various
2181 * "update_view()" and "update_lite()" calls, to allow objects and
2182 * terrain features to be memorized (and drawn) whenever they become
2183 * viewable or illuminated in any way, but not when they "maintain"
2184 * or "lose" their previous viewability or illumination.
2186 * Note the butchered "internal" version of "player_can_see_bold()",
2187 * optimized primarily for the most common cases, that is, for the
2188 * non-marked floor grids.
2190 void note_spot(POSITION y, POSITION x)
2192 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2193 OBJECT_IDX this_o_idx, next_o_idx = 0;
2195 /* Blind players see nothing */
2196 if (p_ptr->blind) return;
2198 /* Analyze non-torch-lit grids */
2199 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
2201 /* Require line of sight to the grid */
2202 if (!(g_ptr->info & (CAVE_VIEW))) return;
2204 /* Require "perma-lite" of the grid */
2205 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
2208 if (!p_ptr->see_nocto) return;
2213 /* Hack -- memorize objects */
2214 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2216 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
2217 next_o_idx = o_ptr->next_o_idx;
2219 /* Memorize objects */
2220 o_ptr->marked |= OM_FOUND;
2224 /* Hack -- memorize grids */
2225 if (!(g_ptr->info & (CAVE_MARK)))
2227 /* Feature code (applying "mimic" field) */
2228 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
2230 /* Memorize some "boring" grids */
2231 if (!have_flag(f_ptr->flags, FF_REMEMBER))
2233 /* Option -- memorize all torch-lit floors */
2234 if (view_torch_grids &&
2235 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
2237 g_ptr->info |= (CAVE_MARK);
2240 /* Option -- memorize all perma-lit floors */
2241 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
2243 g_ptr->info |= (CAVE_MARK);
2247 /* Memorize normal grids */
2248 else if (have_flag(f_ptr->flags, FF_LOS))
2250 g_ptr->info |= (CAVE_MARK);
2253 /* Memorize torch-lit walls */
2254 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
2256 g_ptr->info |= (CAVE_MARK);
2259 /* Memorize walls seen by noctovision of Ninja */
2260 else if (p_ptr->see_nocto)
2262 g_ptr->info |= (CAVE_MARK);
2265 /* Memorize certain non-torch-lit wall grids */
2266 else if (check_local_illumination(y, x))
2268 g_ptr->info |= (CAVE_MARK);
2272 /* Memorize terrain of the grid */
2273 g_ptr->info |= (CAVE_KNOWN);
2277 void display_dungeon(void)
2284 SYMBOL_CODE tc = '\0';
2286 for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
2288 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
2290 if (in_bounds2(y, x))
2292 map_info(y, x, &a, &c, &ta, &tc);
2294 /* Hack -- fake monochrome */
2297 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2298 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2299 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2302 /* Hack -- Queue it */
2303 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
2307 /* Clear out-of-bound tiles */
2309 /* Access darkness */
2310 feature_type *f_ptr = &f_info[feat_none];
2313 a = f_ptr->x_attr[F_LIT_STANDARD];
2316 c = f_ptr->x_char[F_LIT_STANDARD];
2318 /* Hack -- Queue it */
2319 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
2327 * Redraw (on the screen) a given MAP location
2329 * This function should only be called on "legal" grids
2331 void lite_spot(POSITION y, POSITION x)
2333 /* Redraw if on screen */
2334 if (panel_contains(y, x) && in_bounds2(y, x))
2341 map_info(y, x, &a, &c, &ta, &tc);
2343 /* Hack -- fake monochrome */
2346 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2347 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2348 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2351 /* Hack -- Queue it */
2352 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
2354 /* Update sub-windows */
2355 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2361 * print project path
2363 void prt_path(POSITION y, POSITION x)
2368 byte_hack default_color = TERM_SLATE;
2370 if (!display_path) return;
2371 if (-1 == project_length)
2374 /* Get projection path */
2375 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
2377 p_ptr->redraw |= (PR_MAP);
2381 for (i = 0; i < path_n; i++)
2383 POSITION ny = GRID_Y(path_g[i]);
2384 POSITION nx = GRID_X(path_g[i]);
2385 grid_type *g_ptr = ¤t_floor_ptr->grid_array[ny][nx];
2387 if (panel_contains(ny, nx))
2389 TERM_COLOR a = default_color;
2392 TERM_COLOR ta = default_color;
2395 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
2397 /* Determine what is there */
2398 map_info(ny, nx, &a, &c, &ta, &tc);
2400 if (!is_ascii_graphics(a))
2402 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2404 else if (a == default_color)
2410 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2411 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2412 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2417 /* Hack -- Queue it */
2418 Term_queue_bigchar(panel_col_of(nx), ny - panel_row_prt, a, c, ta, tc);
2422 if ((g_ptr->info & CAVE_MARK) && !cave_have_flag_grid(g_ptr, FF_PROJECT)) break;
2425 if (nx == x && ny == y) default_color = TERM_L_DARK;
2430 static concptr simplify_list[][2] =
2437 {"^Amulet of ", "\""},
2438 {"^Scroll of ", "?"},
2439 {"^Scroll titled ", "?"},
2440 {"^Wand of " , "-"},
2442 {"^Staff of " , "_"},
2443 {"^Potion of ", "!"},
2455 static void display_shortened_item_name(object_type *o_ptr, int y)
2462 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
2463 attr = tval_to_attr[o_ptr->tval % 128];
2468 strcpy(buf, _("何か奇妙な物", "something strange"));
2471 for (c = buf; *c; c++)
2474 for (i = 0; simplify_list[i][1]; i++)
2476 concptr org_w = simplify_list[i][0];
2486 if (!strncmp(c, org_w, strlen(org_w)))
2489 concptr tmp = simplify_list[i][1];
2492 tmp = c + strlen(org_w);
2508 if (len + 2 > 12) break;
2515 if (len + 1 > 12) break;
2521 Term_putstr(0, y, 12, attr, buf);
2525 * Display a "small-scale" map of the dungeon in the active Term
2527 void display_map(int *cy, int *cx)
2537 SYMBOL_CODE **bigmc;
2544 /* Save lighting effects */
2545 bool old_view_special_lite = view_special_lite;
2546 bool old_view_granite_lite = view_granite_lite;
2548 TERM_LEN hgt, wid, yrat, xrat;
2550 int **match_autopick_yx;
2551 object_type ***object_autopick_yx;
2553 Term_get_size(&wid, &hgt);
2556 if (use_bigtile) wid /= 2;
2558 yrat = (current_floor_ptr->height + hgt - 1) / hgt;
2559 xrat = (current_floor_ptr->width + wid - 1) / wid;
2561 /* Disable lighting effects */
2562 view_special_lite = FALSE;
2563 view_granite_lite = FALSE;
2565 /* Allocate the maps */
2566 C_MAKE(ma, (hgt + 2), TERM_COLOR *);
2567 C_MAKE(mc, (hgt + 2), char_ptr);
2568 C_MAKE(mp, (hgt + 2), byte_ptr);
2569 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2570 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2572 /* Allocate and wipe each line map */
2573 for (y = 0; y < (hgt + 2); y++)
2575 /* Allocate one row each array */
2576 C_MAKE(ma[y], (wid + 2), TERM_COLOR);
2577 C_MAKE(mc[y], (wid + 2), char);
2578 C_MAKE(mp[y], (wid + 2), byte);
2579 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2580 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2582 for (x = 0; x < wid + 2; ++x)
2584 match_autopick_yx[y][x] = -1;
2585 object_autopick_yx[y][x] = NULL;
2588 ma[y][x] = TERM_WHITE;
2596 /* Allocate the maps */
2597 C_MAKE(bigma, (current_floor_ptr->height + 2), TERM_COLOR *);
2598 C_MAKE(bigmc, (current_floor_ptr->height + 2), char_ptr);
2599 C_MAKE(bigmp, (current_floor_ptr->height + 2), byte_ptr);
2601 /* Allocate and wipe each line map */
2602 for (y = 0; y < (current_floor_ptr->height + 2); y++)
2604 /* Allocate one row each array */
2605 C_MAKE(bigma[y], (current_floor_ptr->width + 2), TERM_COLOR);
2606 C_MAKE(bigmc[y], (current_floor_ptr->width + 2), char);
2607 C_MAKE(bigmp[y], (current_floor_ptr->width + 2), byte);
2609 for (x = 0; x < current_floor_ptr->width + 2; ++x)
2612 bigma[y][x] = TERM_WHITE;
2620 /* Fill in the map */
2621 for (i = 0; i < current_floor_ptr->width; ++i)
2623 for (j = 0; j < current_floor_ptr->height; ++j)
2628 match_autopick = -1;
2629 autopick_obj = NULL;
2632 /* Extract the current attr/char at that map location */
2633 map_info(j, i, &ta, &tc, &ta, &tc);
2635 /* Extract the priority */
2636 tp = (byte_hack)feat_priority;
2638 if (match_autopick != -1
2639 && (match_autopick_yx[y][x] == -1
2640 || match_autopick_yx[y][x] > match_autopick))
2642 match_autopick_yx[y][x] = match_autopick;
2643 object_autopick_yx[y][x] = autopick_obj;
2647 /* Save the char, attr and priority */
2648 bigmc[j + 1][i + 1] = tc;
2649 bigma[j + 1][i + 1] = ta;
2650 bigmp[j + 1][i + 1] = tp;
2654 for (j = 0; j < current_floor_ptr->height; ++j)
2656 for (i = 0; i < current_floor_ptr->width; ++i)
2661 tc = bigmc[j + 1][i + 1];
2662 ta = bigma[j + 1][i + 1];
2663 tp = bigmp[j + 1][i + 1];
2665 /* rare feature has more priority */
2671 for (t = 0; t < 8; t++)
2673 if (tc == bigmc[j + 1 + ddy_cdd[t]][i + 1 + ddx_cdd[t]] &&
2674 ta == bigma[j + 1 + ddy_cdd[t]][i + 1 + ddx_cdd[t]])
2684 /* Save the char, attr and priority */
2697 /* Draw the corners */
2698 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2700 /* Draw the horizontal edges */
2701 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2703 /* Draw the vertical edges */
2704 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2707 /* Display each map line in order */
2708 for (y = 0; y < hgt + 2; ++y)
2710 /* Start a new line */
2711 Term_gotoxy(COL_MAP, y);
2713 /* Display the line */
2714 for (x = 0; x < wid + 2; ++x)
2719 /* Hack -- fake monochrome */
2722 if (current_world_ptr->timewalk_m_idx) ta = TERM_DARK;
2723 else if (IS_INVULN() || p_ptr->timewalk) ta = TERM_WHITE;
2724 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2727 /* Add the character */
2728 Term_add_bigch(ta, tc);
2733 for (y = 1; y < hgt + 1; ++y)
2735 match_autopick = -1;
2736 for (x = 1; x <= wid; x++) {
2737 if (match_autopick_yx[y][x] != -1 &&
2738 (match_autopick > match_autopick_yx[y][x] ||
2739 match_autopick == -1)) {
2740 match_autopick = match_autopick_yx[y][x];
2741 autopick_obj = object_autopick_yx[y][x];
2745 /* Clear old display */
2746 Term_putstr(0, y, 12, 0, " ");
2748 if (match_autopick != -1)
2750 display_shortened_item_name(autopick_obj, y);
2753 char buf[13] = "\0";
2754 strncpy(buf, autopick_list[match_autopick].name, 12);
2762 /* Player location */
2763 (*cy) = p_ptr->y / yrat + 1 + ROW_MAP;
2765 (*cx) = p_ptr->x / xrat + 1 + COL_MAP;
2767 (*cx) = (p_ptr->x / xrat + 1) * 2 + COL_MAP;
2769 /* Restore lighting effects */
2770 view_special_lite = old_view_special_lite;
2771 view_granite_lite = old_view_granite_lite;
2773 /* Free each line map */
2774 for (y = 0; y < (hgt + 2); y++)
2776 /* Free one row each array */
2777 C_KILL(ma[y], (wid + 2), TERM_COLOR);
2778 C_KILL(mc[y], (wid + 2), SYMBOL_CODE);
2779 C_KILL(mp[y], (wid + 2), byte);
2780 C_KILL(match_autopick_yx[y], (wid + 2), int);
2781 C_KILL(object_autopick_yx[y], (wid + 2), object_type *);
2784 /* Free each line map */
2785 C_KILL(ma, (hgt + 2), TERM_COLOR *);
2786 C_KILL(mc, (hgt + 2), char_ptr);
2787 C_KILL(mp, (hgt + 2), byte_ptr);
2788 C_KILL(match_autopick_yx, (hgt + 2), sint_ptr);
2789 C_KILL(object_autopick_yx, (hgt + 2), object_type **);
2791 /* Free each line map */
2792 for (y = 0; y < (current_floor_ptr->height + 2); y++)
2794 /* Free one row each array */
2795 C_KILL(bigma[y], (current_floor_ptr->width + 2), TERM_COLOR);
2796 C_KILL(bigmc[y], (current_floor_ptr->width + 2), SYMBOL_CODE);
2797 C_KILL(bigmp[y], (current_floor_ptr->width + 2), byte);
2800 /* Free each line map */
2801 C_KILL(bigma, (current_floor_ptr->height + 2), TERM_COLOR *);
2802 C_KILL(bigmc, (current_floor_ptr->height + 2), char_ptr);
2803 C_KILL(bigmp, (current_floor_ptr->height + 2), byte_ptr);
2808 * Display a "small-scale" map of the dungeon for the player
2810 * Currently, the "player" is displayed on the map.
2812 void do_cmd_view_map(void)
2818 prt(_("お待ち下さい...", "Please wait..."), 0, 0);
2823 display_autopick = 0;
2825 /* Display the map */
2826 display_map(&cy, &cx);
2829 if (max_autopick && !p_ptr->wild_mode)
2831 display_autopick = ITEM_DISPLAY;
2838 int wid, hgt, row_message;
2840 Term_get_size(&wid, &hgt);
2841 row_message = hgt - 1;
2843 put_str(_("何かキーを押してください('M':拾う 'N':放置 'D':M+N 'K':壊すアイテムを表示)",
2844 " Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items."), row_message, 1);
2846 /* Hilite the player */
2847 move_cursor(cy, cx);
2852 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2854 flag = DONT_AUTOPICK;
2856 flag = DO_AUTODESTROY;
2858 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2864 if (~display_autopick & flag)
2865 display_autopick |= flag;
2867 display_autopick &= ~flag;
2868 /* Display the map */
2869 display_map(&cy, &cx);
2872 display_autopick = 0;
2877 put_str(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"), 23, 30);
2878 /* Hilite the player */
2879 move_cursor(cy, cx);
2891 * Some comments on the grid flags. -BEN-
2894 * One of the major bottlenecks in previous versions of Angband was in
2895 * the calculation of "line of sight" from the player to various grids,
2896 * such as monsters. This was such a nasty bottleneck that a lot of
2897 * silly things were done to reduce the dependancy on "line of sight",
2898 * for example, you could not "see" any grids in a lit room until you
2899 * actually entered the room, and there were all kinds of bizarre grid
2900 * flags to enable this behavior. This is also why the "call light"
2901 * spells always lit an entire room.
2903 * The code below provides functions to calculate the "field of view"
2904 * for the player, which, once calculated, provides extremely fast
2905 * calculation of "line of sight from the player", and to calculate
2906 * the "field of torch lite", which, again, once calculated, provides
2907 * extremely fast calculation of "which grids are lit by the player's
2908 * lite source". In addition to marking grids as "GRID_VIEW" and/or
2909 * "GRID_LITE", as appropriate, these functions maintain an array for
2910 * each of these two flags, each array containing the locations of all
2911 * of the grids marked with the appropriate flag, which can be used to
2912 * very quickly scan through all of the grids in a given set.
2914 * To allow more "semantically valid" field of view semantics, whenever
2915 * the field of view (or the set of torch lit grids) changes, all of the
2916 * grids in the field of view (or the set of torch lit grids) are "drawn"
2917 * so that changes in the world will become apparent as soon as possible.
2918 * This has been optimized so that only grids which actually "change" are
2919 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
2920 * of the grids which are entering or leaving the relevent set of grids.
2922 * These new methods are so efficient that the old nasty code was removed.
2924 * Note that there is no reason to "update" the "viewable space" unless
2925 * the player "moves", or walls/doors are created/destroyed, and there
2926 * is no reason to "update" the "torch lit grids" unless the field of
2927 * view changes, or the "light radius" changes. This means that when
2928 * the player is resting, or digging, or doing anything that does not
2929 * involve movement or changing the state of the dungeon, there is no
2930 * need to update the "view" or the "lite" regions, which is nice.
2932 * Note that the calls to the nasty "los()" function have been reduced
2933 * to a bare minimum by the use of the new "field of view" calculations.
2935 * I wouldn't be surprised if slight modifications to the "update_view()"
2936 * function would allow us to determine "reverse line-of-sight" as well
2937 * as "normal line-of-sight", which would allow monsters to use a more
2938 * "correct" calculation to determine if they can "see" the player. For
2939 * now, monsters simply "cheat" somewhat and assume that if the player
2940 * has "line of sight" to the monster, then the monster can "pretend"
2941 * that it has "line of sight" to the player.
2944 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
2945 * grid and maintains an array of all "CAVE_LITE" grids.
2947 * This set of grids is the complete set of all grids which are lit by
2948 * the players light source, which allows the "player_can_see_bold()"
2949 * function to work very quickly.
2951 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
2952 * fact, the player (unless blind) can always "see" all grids which are
2953 * marked as "CAVE_LITE", unless they are "off screen".
2956 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
2957 * grid and maintains an array of all "CAVE_VIEW" grids.
2959 * This set of grids is the complete set of all grids within line of sight
2960 * of the player, allowing the "player_has_los_bold()" macro to work very
2964 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
2965 * temporary internal flag to mark those grids which are not only in view,
2966 * but which are also "easily" in line of sight of the player. This flag
2967 * is always cleared when we are done.
2970 * The current "update_lite()" and "update_view()" algorithms use the
2971 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
2972 * to keep track of which grids were previously marked as "CAVE_LITE" or
2973 * "CAVE_VIEW", which allows us to optimize the "screen updates".
2975 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
2976 * for various other purposes, such as spreading lite or darkness during
2977 * "lite_room()" / "unlite_room()", and for calculating monster flow.
2980 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
2981 * in some way permanently lit. However, for the player to "see" anything
2982 * in the grid, as determined by "player_can_see()", the player must not be
2983 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
2984 * grids, even if marked as "perma lit", are only illuminated if they touch
2985 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
2988 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
2989 * that even if the player cannot "see" the grid, he "knows" the terrain in
2990 * that grid. This is used to "remember" walls/doors/stairs/floors when they
2991 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
2992 * or when one of the "memorize floor grids" options induces memorization.
2994 * Objects are "memorized" in a different way, using a special "marked" flag
2995 * on the object itself, which is set when an object is observed or detected.
2998 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
2999 * and should be illuminated by "lite room" and "darkness" spells.
3002 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
3003 * and should be unavailable for "teleportation" destinations.
3006 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
3007 * which is observed, and the "view_torch_grids" allows the player to memorize
3008 * every torch-lit grid. The player will always memorize important walls,
3009 * doors, stairs, and other terrain features, as well as any "detected" grids.
3011 * Note that the new "update_view()" method allows, among other things, a room
3012 * to be "partially" seen as the player approaches it, with a growing cone of
3013 * floor appearing as the player gets closer to the door. Also, by not turning
3014 * on the "memorize perma-lit grids" option, the player will only "see" those
3015 * floor grids which are actually in line of sight.
3017 * And my favorite "plus" is that you can now use a special option to draw the
3018 * "floors" in the "viewable region" brightly (actually, to draw the *other*
3019 * grids dimly), providing a "pretty" effect as the player runs around, and
3020 * to efficiently display the "torch lite" in a special color.
3023 * Some comments on the "update_view()" algorithm...
3025 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
3026 * and only has to call "los()" on the borderline cases. The major axes/diags
3027 * even terminate early when they hit walls. I need to find a quick way
3028 * to "terminate" the other scans.
3030 * Note that in the worst case (a big empty area with say 5% scattered walls),
3031 * each of the 1500 or so nearby grids is checked once, most of them getting
3032 * an "instant" rating, and only a small portion requiring a call to "los()".
3034 * The only time that the algorithm appears to be "noticeably" too slow is
3035 * when running, and this is usually only important in town, since the town
3036 * provides about the worst scenario possible, with large open regions and
3037 * a few scattered obstructions. There is a special "efficiency" option to
3038 * allow the player to reduce his field of view in town, if needed.
3040 * In the "best" case (say, a normal stretch of corridor), the algorithm
3041 * makes one check for each viewable grid, and makes no calls to "los()".
3042 * So running in corridors is very fast, and if a lot of monsters are
3043 * nearby, it is much faster than the old methods.
3045 * Note that resting, most normal commands, and several forms of running,
3046 * plus all commands executed near large groups of monsters, are strictly
3047 * more efficient with "update_view()" that with the old "compute los() on
3048 * demand" method, primarily because once the "field of view" has been
3049 * calculated, it does not have to be recalculated until the player moves
3050 * (or a wall or door is created or destroyed).
3052 * Note that we no longer have to do as many "los()" checks, since once the
3053 * "view" region has been built, very few things cause it to be "changed"
3054 * (player movement, and the opening/closing of doors, changes in wall status).
3055 * Note that door/wall changes are only relevant when the door/wall itself is
3056 * in the "view" region.
3058 * The algorithm seems to only call "los()" from zero to ten times, usually
3059 * only when coming down a corridor into a room, or standing in a room, just
3060 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
3061 * we will be reducing the calls to "los()".
3063 * I am thinking in terms of an algorithm that "walks" from the central point
3064 * out to the maximal "distance", at each point, determining the "view" code
3065 * (above). For each grid not on a major axis or diagonal, the "view" code
3066 * depends on the "cave_los_bold()" and "view" of exactly two other grids
3067 * (the one along the nearest diagonal, and the one next to that one, see
3068 * "update_view_aux()"...).
3070 * We "memorize" the viewable space array, so that at the cost of under 3000
3071 * bytes, we reduce the time taken by "forget_view()" to one assignment for
3072 * each grid actually in the "viewable space". And for another 3000 bytes,
3073 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
3074 * are also used by other routines, thus reducing the cost to almost nothing.
3076 * A similar thing is done for "forget_lite()" in which case the savings are
3077 * much less, but save us from doing bizarre maintenance checking.
3079 * In the worst "normal" case (in the middle of the town), the reachable space
3080 * actually reaches to more than half of the largest possible "circle" of view,
3081 * or about 800 grids, and in the worse case (in the middle of a dungeon level
3082 * where all the walls have been removed), the reachable space actually reaches
3083 * the theoretical maximum size of just under 1500 grids.
3085 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
3086 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
3087 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
3088 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
3089 * entire possible space (including initialization) in one step per grid. If
3090 * we do the "clearing" as a separate step (and use an array of "view" grids),
3091 * then the clearing will take as many steps as grids that were viewed, and the
3092 * algorithm will be able to "stop" scanning at various points.
3093 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
3104 * Actually erase the entire "lite" array, redrawing every grid
3106 void forget_lite(void)
3111 /* None to forget */
3112 if (!current_floor_ptr->lite_n) return;
3114 /* Clear them all */
3115 for (i = 0; i < current_floor_ptr->lite_n; i++)
3117 y = current_floor_ptr->lite_y[i];
3118 x = current_floor_ptr->lite_x[i];
3120 /* Forget "LITE" flag */
3121 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
3123 /* lite_spot(y, x); Perhaps don't need? */
3127 current_floor_ptr->lite_n = 0;
3132 * For delayed visual update
3134 #define cave_note_and_redraw_later(C,Y,X) \
3136 (C)->info |= CAVE_NOTE; \
3137 cave_redraw_later((C), (Y), (X)); \
3142 * For delayed visual update
3144 #define cave_redraw_later(C,Y,X) \
3146 if (!((C)->info & CAVE_REDRAW)) \
3148 (C)->info |= CAVE_REDRAW; \
3149 current_floor_ptr->redraw_y[current_floor_ptr->redraw_n] = (Y); \
3150 current_floor_ptr->redraw_x[current_floor_ptr->redraw_n++] = (X); \
3156 * This macro allows us to efficiently add a grid to the "lite" array,
3157 * note that we are never called for illegal grids, or for grids which
3158 * have already been placed into the "lite" array, and we are never
3159 * called when the "lite" array is full.
3161 #define cave_lite_hack(Y,X) \
3163 if (!(current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
3165 current_floor_ptr->grid_array[Y][X].info |= (CAVE_LITE); \
3166 current_floor_ptr->lite_y[current_floor_ptr->lite_n] = (Y); \
3167 current_floor_ptr->lite_x[current_floor_ptr->lite_n++] = (X); \
3173 * Update the set of grids "illuminated" by the player's lite.
3175 * This routine needs to use the results of "update_view()"
3177 * Note that "blindness" does NOT affect "torch lite". Be careful!
3179 * We optimize most lites (all non-artifact lites) by using "obvious"
3180 * facts about the results of "small" lite radius, and we attempt to
3181 * list the "nearby" grids before the more "distant" ones in the
3182 * array of torch-lit grids.
3184 * We assume that "radius zero" lite is in fact no lite at all.
3186 * Torch Lantern Artifacts
3196 void update_lite(void)
3199 POSITION x, y, min_x, max_x, min_y, max_y;
3200 POSITION p = p_ptr->cur_lite;
3203 /*** Special case ***/
3206 /* Hack -- Player has no lite */
3209 /* Forget the old lite */
3210 /* forget_lite(); Perhaps don't need? */
3212 /* Add it to later visual update */
3213 cave_redraw_later(¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
3217 /*** Save the old "lite" grids for later ***/
3219 /* Clear them all */
3220 for (i = 0; i < current_floor_ptr->lite_n; i++)
3222 y = current_floor_ptr->lite_y[i];
3223 x = current_floor_ptr->lite_x[i];
3225 /* Mark the grid as not "lite" */
3226 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
3228 /* Mark the grid as "seen" */
3229 current_floor_ptr->grid_array[y][x].info |= (CAVE_TEMP);
3231 /* Add it to the "seen" set */
3232 tmp_pos.y[tmp_pos.n] = y;
3233 tmp_pos.x[tmp_pos.n] = x;
3238 current_floor_ptr->lite_n = 0;
3241 /*** Collect the new "lite" grids ***/
3243 /* Radius 1 -- torch radius */
3247 cave_lite_hack(p_ptr->y, p_ptr->x);
3250 cave_lite_hack(p_ptr->y + 1, p_ptr->x);
3251 cave_lite_hack(p_ptr->y - 1, p_ptr->x);
3252 cave_lite_hack(p_ptr->y, p_ptr->x + 1);
3253 cave_lite_hack(p_ptr->y, p_ptr->x - 1);
3255 /* Diagonal grids */
3256 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 1);
3257 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 1);
3258 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 1);
3259 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 1);
3262 /* Radius 2 -- lantern radius */
3265 /* South of the player */
3266 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
3268 cave_lite_hack(p_ptr->y + 2, p_ptr->x);
3269 cave_lite_hack(p_ptr->y + 2, p_ptr->x + 1);
3270 cave_lite_hack(p_ptr->y + 2, p_ptr->x - 1);
3273 /* North of the player */
3274 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
3276 cave_lite_hack(p_ptr->y - 2, p_ptr->x);
3277 cave_lite_hack(p_ptr->y - 2, p_ptr->x + 1);
3278 cave_lite_hack(p_ptr->y - 2, p_ptr->x - 1);
3281 /* East of the player */
3282 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
3284 cave_lite_hack(p_ptr->y, p_ptr->x + 2);
3285 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 2);
3286 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 2);
3289 /* West of the player */
3290 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
3292 cave_lite_hack(p_ptr->y, p_ptr->x - 2);
3293 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 2);
3294 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 2);
3298 /* Radius 3+ -- artifact radius */
3303 /* Paranoia -- see "LITE_MAX" */
3306 /* South-East of the player */
3307 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
3309 cave_lite_hack(p_ptr->y + 2, p_ptr->x + 2);
3312 /* South-West of the player */
3313 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
3315 cave_lite_hack(p_ptr->y + 2, p_ptr->x - 2);
3318 /* North-East of the player */
3319 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
3321 cave_lite_hack(p_ptr->y - 2, p_ptr->x + 2);
3324 /* North-West of the player */
3325 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
3327 cave_lite_hack(p_ptr->y - 2, p_ptr->x - 2);
3331 min_y = p_ptr->y - p;
3332 if (min_y < 0) min_y = 0;
3335 max_y = p_ptr->y + p;
3336 if (max_y > current_floor_ptr->height - 1) max_y = current_floor_ptr->height - 1;
3339 min_x = p_ptr->x - p;
3340 if (min_x < 0) min_x = 0;
3343 max_x = p_ptr->x + p;
3344 if (max_x > current_floor_ptr->width - 1) max_x = current_floor_ptr->width - 1;
3346 /* Scan the maximal box */
3347 for (y = min_y; y <= max_y; y++)
3349 for (x = min_x; x <= max_x; x++)
3351 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
3352 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
3354 /* Skip the "central" grids (above) */
3355 if ((dy <= 2) && (dx <= 2)) continue;
3357 /* Hack -- approximate the distance */
3358 d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
3360 /* Skip distant grids */
3361 if (d > p) continue;
3363 /* Viewable, nearby, grids get "torch lit" */
3364 if (current_floor_ptr->grid_array[y][x].info & CAVE_VIEW)
3366 /* This grid is "torch lit" */
3367 cave_lite_hack(y, x);
3374 /*** Complete the algorithm ***/
3376 /* Draw the new grids */
3377 for (i = 0; i < current_floor_ptr->lite_n; i++)
3379 y = current_floor_ptr->lite_y[i];
3380 x = current_floor_ptr->lite_x[i];
3382 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3384 /* Update fresh grids */
3385 if (g_ptr->info & (CAVE_TEMP)) continue;
3387 /* Add it to later visual update */
3388 cave_note_and_redraw_later(g_ptr, y, x);
3391 /* Clear them all */
3392 for (i = 0; i < tmp_pos.n; i++)
3397 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3399 /* No longer in the array */
3400 g_ptr->info &= ~(CAVE_TEMP);
3402 /* Update stale grids */
3403 if (g_ptr->info & (CAVE_LITE)) continue;
3405 /* Add it to later visual update */
3406 cave_redraw_later(g_ptr, y, x);
3412 /* Mega-Hack -- Visual update later */
3413 p_ptr->update |= (PU_DELAY_VIS);
3417 static bool mon_invis;
3418 static POSITION mon_fy, mon_fx;
3421 * Add a square to the changes array
3423 static void mon_lite_hack(POSITION y, POSITION x)
3429 /* We trust this grid is in bounds */
3430 /* if (!in_bounds2(y, x)) return; */
3432 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3434 /* Want a unlit square in view of the player */
3435 if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3437 if (!cave_los_grid(g_ptr))
3439 /* Hack -- Prevent monster lite leakage in walls */
3441 /* Horizontal walls between player and a monster */
3442 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
3444 dpf = p_ptr->y - mon_fy;
3446 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
3448 /* Only first wall viewed from mid-x is lit */
3451 if (!cave_los_bold(y, x + 1)) return;
3453 else if (x > midpoint)
3455 if (!cave_los_bold(y, x - 1)) return;
3458 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3459 else if (mon_invis) return;
3462 /* Vertical walls between player and a monster */
3463 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
3465 dpf = p_ptr->x - mon_fx;
3467 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
3469 /* Only first wall viewed from mid-y is lit */
3472 if (!cave_los_bold(y + 1, x)) return;
3474 else if (y > midpoint)
3476 if (!cave_los_bold(y - 1, x)) return;
3479 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3480 else if (mon_invis) return;
3484 /* We trust tmp_pos.n does not exceed TEMP_MAX */
3487 if (!(g_ptr->info & CAVE_MNDK))
3489 /* Save this square */
3490 tmp_pos.x[tmp_pos.n] = x;
3491 tmp_pos.y[tmp_pos.n] = y;
3498 /* No longer dark */
3499 g_ptr->info &= ~(CAVE_MNDK);
3503 g_ptr->info |= CAVE_MNLT;
3508 * Add a square to the changes array
3510 static void mon_dark_hack(POSITION y, POSITION x)
3513 int midpoint, dpf, d;
3515 /* We trust this grid is in bounds */
3516 /* if (!in_bounds2(y, x)) return; */
3518 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3520 /* Want a unlit and undarkened square in view of the player */
3521 if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
3523 if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
3525 /* Hack -- Prevent monster dark lite leakage in walls */
3527 /* Horizontal walls between player and a monster */
3528 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
3530 dpf = p_ptr->y - mon_fy;
3532 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
3534 /* Only first wall viewed from mid-x is lit */
3537 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
3539 else if (x > midpoint)
3541 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
3544 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3545 else if (mon_invis) return;
3548 /* Vertical walls between player and a monster */
3549 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
3551 dpf = p_ptr->x - mon_fx;
3553 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
3555 /* Only first wall viewed from mid-y is lit */
3558 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
3560 else if (y > midpoint)
3562 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
3565 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3566 else if (mon_invis) return;
3570 /* We trust tmp_pos.n does not exceed TEMP_MAX */
3572 /* Save this square */
3573 tmp_pos.x[tmp_pos.n] = x;
3574 tmp_pos.y[tmp_pos.n] = y;
3578 g_ptr->info |= CAVE_MNDK;
3583 * Update squares illuminated or darkened by monsters.
3585 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3586 * denote squares illuminated by monsters.
3588 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
3589 * updating. Only squares in view of the player, whos state
3590 * changes are drawn via lite_spot().
3592 void update_mon_lite(void)
3598 void(*add_mon_lite)(POSITION, POSITION);
3603 /* Non-Ninja player in the darkness */
3604 int dis_lim = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
3605 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
3607 /* Clear all monster lit squares */
3608 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
3611 g_ptr = ¤t_floor_ptr->grid_array[current_floor_ptr->mon_lite_y[i]][current_floor_ptr->mon_lite_x[i]];
3613 /* Set temp or xtra flag */
3614 g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
3616 /* Clear monster illumination flag */
3617 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3620 /* Empty temp list of new squares to lite up */
3623 /* If a monster stops time, don't process */
3624 if (!current_world_ptr->timewalk_m_idx)
3626 monster_type *m_ptr;
3627 monster_race *r_ptr;
3629 /* Loop through monsters, adding newly lit squares to changes list */
3630 for (i = 1; i < m_max; i++)
3632 m_ptr = ¤t_floor_ptr->m_list[i];
3633 r_ptr = &r_info[m_ptr->r_idx];
3634 if (!monster_is_valid(m_ptr)) continue;
3636 /* Is it too far away? */
3637 if (m_ptr->cdis > dis_lim) continue;
3639 /* Get lite radius */
3642 /* Note the radii are cumulative */
3643 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3644 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3645 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3646 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3648 /* Exit if has no light */
3652 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (MON_CSLEEP(m_ptr) || (!current_floor_ptr->dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
3653 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
3654 add_mon_lite = mon_lite_hack;
3659 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!current_floor_ptr->dun_level && !is_daytime()))) continue;
3660 add_mon_lite = mon_dark_hack;
3661 f_flag = FF_PROJECT;
3662 rad = -rad; /* Use absolute value */
3668 /* Is the monster visible? */
3669 mon_invis = !(current_floor_ptr->grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
3671 /* The square it is on */
3672 add_mon_lite(mon_fy, mon_fx);
3674 /* Adjacent squares */
3675 add_mon_lite(mon_fy + 1, mon_fx);
3676 add_mon_lite(mon_fy - 1, mon_fx);
3677 add_mon_lite(mon_fy, mon_fx + 1);
3678 add_mon_lite(mon_fy, mon_fx - 1);
3679 add_mon_lite(mon_fy + 1, mon_fx + 1);
3680 add_mon_lite(mon_fy + 1, mon_fx - 1);
3681 add_mon_lite(mon_fy - 1, mon_fx + 1);
3682 add_mon_lite(mon_fy - 1, mon_fx - 1);
3687 /* South of the monster */
3688 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
3690 add_mon_lite(mon_fy + 2, mon_fx + 1);
3691 add_mon_lite(mon_fy + 2, mon_fx);
3692 add_mon_lite(mon_fy + 2, mon_fx - 1);
3694 g_ptr = ¤t_floor_ptr->grid_array[mon_fy + 2][mon_fx];
3697 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3699 add_mon_lite(mon_fy + 3, mon_fx + 1);
3700 add_mon_lite(mon_fy + 3, mon_fx);
3701 add_mon_lite(mon_fy + 3, mon_fx - 1);
3705 /* North of the monster */
3706 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
3708 add_mon_lite(mon_fy - 2, mon_fx + 1);
3709 add_mon_lite(mon_fy - 2, mon_fx);
3710 add_mon_lite(mon_fy - 2, mon_fx - 1);
3712 g_ptr = ¤t_floor_ptr->grid_array[mon_fy - 2][mon_fx];
3715 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3717 add_mon_lite(mon_fy - 3, mon_fx + 1);
3718 add_mon_lite(mon_fy - 3, mon_fx);
3719 add_mon_lite(mon_fy - 3, mon_fx - 1);
3723 /* East of the monster */
3724 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
3726 add_mon_lite(mon_fy + 1, mon_fx + 2);
3727 add_mon_lite(mon_fy, mon_fx + 2);
3728 add_mon_lite(mon_fy - 1, mon_fx + 2);
3730 g_ptr = ¤t_floor_ptr->grid_array[mon_fy][mon_fx + 2];
3733 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3735 add_mon_lite(mon_fy + 1, mon_fx + 3);
3736 add_mon_lite(mon_fy, mon_fx + 3);
3737 add_mon_lite(mon_fy - 1, mon_fx + 3);
3741 /* West of the monster */
3742 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
3744 add_mon_lite(mon_fy + 1, mon_fx - 2);
3745 add_mon_lite(mon_fy, mon_fx - 2);
3746 add_mon_lite(mon_fy - 1, mon_fx - 2);
3748 g_ptr = ¤t_floor_ptr->grid_array[mon_fy][mon_fx - 2];
3751 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3753 add_mon_lite(mon_fy + 1, mon_fx - 3);
3754 add_mon_lite(mon_fy, mon_fx - 3);
3755 add_mon_lite(mon_fy - 1, mon_fx - 3);
3763 /* South-East of the monster */
3764 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
3766 add_mon_lite(mon_fy + 2, mon_fx + 2);
3769 /* South-West of the monster */
3770 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
3772 add_mon_lite(mon_fy + 2, mon_fx - 2);
3775 /* North-East of the monster */
3776 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
3778 add_mon_lite(mon_fy - 2, mon_fx + 2);
3781 /* North-West of the monster */
3782 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
3784 add_mon_lite(mon_fy - 2, mon_fx - 2);
3790 /* Save end of list of new squares */
3791 end_temp = tmp_pos.n;
3794 * Look at old set flags to see if there are any changes.
3796 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
3798 fx = current_floor_ptr->mon_lite_x[i];
3799 fy = current_floor_ptr->mon_lite_y[i];
3801 /* We trust this grid is in bounds */
3804 g_ptr = ¤t_floor_ptr->grid_array[fy][fx];
3806 if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
3808 /* It it no longer lit? */
3809 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3811 /* It is now unlit */
3812 /* Add it to later visual update */
3813 cave_note_and_redraw_later(g_ptr, fy, fx);
3816 else /* Pervious darkened */
3818 /* It it no longer darken? */
3819 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3821 /* It is now undarken */
3822 /* Add it to later visual update */
3823 cave_note_and_redraw_later(g_ptr, fy, fx);
3827 /* Add to end of temp array */
3828 tmp_pos.x[tmp_pos.n] = fx;
3829 tmp_pos.y[tmp_pos.n] = fy;
3833 /* Clear the lite array */
3834 current_floor_ptr->mon_lite_n = 0;
3836 /* Copy the temp array into the lit array lighting the new squares. */
3837 for (i = 0; i < end_temp; i++)
3842 /* We trust this grid is in bounds */
3845 g_ptr = ¤t_floor_ptr->grid_array[fy][fx];
3847 if (g_ptr->info & CAVE_MNLT) /* Lit */
3849 /* The is the square newly lit and visible? */
3850 if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3853 /* Add it to later visual update */
3854 cave_note_and_redraw_later(g_ptr, fy, fx);
3859 /* The is the square newly darkened and visible? */
3860 if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3862 /* It is now darkened */
3863 /* Add it to later visual update */
3864 cave_note_and_redraw_later(g_ptr, fy, fx);
3868 /* Save in the monster lit or darkened array */
3869 current_floor_ptr->mon_lite_x[current_floor_ptr->mon_lite_n] = fx;
3870 current_floor_ptr->mon_lite_y[current_floor_ptr->mon_lite_n] = fy;
3871 current_floor_ptr->mon_lite_n++;
3874 /* Clear the temp flag for the old lit or darken grids */
3875 for (i = end_temp; i < tmp_pos.n; i++)
3877 /* We trust this grid is in bounds */
3879 current_floor_ptr->grid_array[tmp_pos.y[i]][tmp_pos.x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3882 /* Finished with tmp_pos.n */
3885 /* Mega-Hack -- Visual update later */
3886 p_ptr->update |= (PU_DELAY_VIS);
3888 p_ptr->monlite = (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
3890 if (p_ptr->special_defense & NINJA_S_STEALTH)
3892 if (p_ptr->old_monlite != p_ptr->monlite)
3896 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
3900 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
3904 p_ptr->old_monlite = p_ptr->monlite;
3907 void clear_mon_lite(void)
3912 /* Clear all monster lit squares */
3913 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
3916 g_ptr = ¤t_floor_ptr->grid_array[current_floor_ptr->mon_lite_y[i]][current_floor_ptr->mon_lite_x[i]];
3918 /* Clear monster illumination flag */
3919 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3922 /* Empty the array */
3923 current_floor_ptr->mon_lite_n = 0;
3929 * Clear the viewable space
3931 void forget_view(void)
3937 /* None to forget */
3938 if (!current_floor_ptr->view_n) return;
3940 /* Clear them all */
3941 for (i = 0; i < current_floor_ptr->view_n; i++)
3943 POSITION y = current_floor_ptr->view_y[i];
3944 POSITION x = current_floor_ptr->view_x[i];
3945 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3947 /* Forget that the grid is viewable */
3948 g_ptr->info &= ~(CAVE_VIEW);
3950 /* if (!panel_contains(y, x)) continue; */
3952 /* Update the screen */
3953 /* lite_spot(y, x); Perhaps don't need? */
3957 current_floor_ptr->view_n = 0;
3963 * This macro allows us to efficiently add a grid to the "view" array,
3964 * note that we are never called for illegal grids, or for grids which
3965 * have already been placed into the "view" array, and we are never
3966 * called when the "view" array is full.
3968 #define cave_view_hack(C,Y,X) \
3970 if (!((C)->info & (CAVE_VIEW))){\
3971 (C)->info |= (CAVE_VIEW); \
3972 current_floor_ptr->view_y[current_floor_ptr->view_n] = (Y); \
3973 current_floor_ptr->view_x[current_floor_ptr->view_n] = (X); \
3974 current_floor_ptr->view_n++;}\
3980 * Helper function for "update_view()" below
3982 * We are checking the "viewability" of grid (y,x) by the player.
3984 * This function assumes that (y,x) is legal (i.e. on the map).
3986 * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
3987 * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
3989 * Note that we are using the "CAVE_XTRA" field for marking grids as
3990 * "easily viewable". This bit is cleared at the end of "update_view()".
3992 * This function adds (y,x) to the "viewable set" if necessary.
3994 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
3996 static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
3998 bool f1, f2, v1, v2, z1, z2, wall;
4002 grid_type *g1_c_ptr;
4003 grid_type *g2_c_ptr;
4005 /* Access the grids */
4006 g1_c_ptr = ¤t_floor_ptr->grid_array[y1][x1];
4007 g2_c_ptr = ¤t_floor_ptr->grid_array[y2][x2];
4010 /* Check for walls */
4011 f1 = (cave_los_grid(g1_c_ptr));
4012 f2 = (cave_los_grid(g2_c_ptr));
4014 /* Totally blocked by physical walls */
4015 if (!f1 && !f2) return (TRUE);
4018 /* Check for visibility */
4019 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
4020 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
4022 /* Totally blocked by "unviewable neighbors" */
4023 if (!v1 && !v2) return (TRUE);
4025 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4028 /* Check for walls */
4029 wall = (!cave_los_grid(g_ptr));
4032 /* Check the "ease" of visibility */
4033 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
4034 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
4036 /* Hack -- "easy" plus "easy" yields "easy" */
4039 g_ptr->info |= (CAVE_XTRA);
4041 cave_view_hack(g_ptr, y, x);
4046 /* Hack -- primary "easy" yields "viewed" */
4049 cave_view_hack(g_ptr, y, x);
4054 /* Hack -- "view" plus "view" yields "view" */
4057 /* g_ptr->info |= (CAVE_XTRA); */
4059 cave_view_hack(g_ptr, y, x);
4065 /* Mega-Hack -- the "los()" function works poorly on walls */
4068 cave_view_hack(g_ptr, y, x);
4074 /* Hack -- check line of sight */
4075 if (los(p_ptr->y, p_ptr->x, y, x))
4077 cave_view_hack(g_ptr, y, x);
4083 /* Assume no line of sight. */
4090 * Calculate the viewable space
4092 * 1: Process the player
4093 * 1a: The player is always (easily) viewable
4094 * 2: Process the diagonals
4095 * 2a: The diagonals are (easily) viewable up to the first wall
4096 * 2b: But never go more than 2/3 of the "full" distance
4097 * 3: Process the main axes
4098 * 3a: The main axes are (easily) viewable up to the first wall
4099 * 3b: But never go more than the "full" distance
4100 * 4: Process sequential "strips" in each of the eight octants
4101 * 4a: Each strip runs along the previous strip
4102 * 4b: The main axes are "previous" to the first strip
4103 * 4c: Process both "sides" of each "direction" of each strip
4104 * 4c1: Each side aborts as soon as possible
4105 * 4c2: Each side tells the next strip how far it has to check
4107 * Note that the octant processing involves some pretty interesting
4108 * observations involving when a grid might possibly be viewable from
4109 * a given grid, and on the order in which the strips are processed.
4111 * Note the use of the mathematical facts shown below, which derive
4112 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
4113 * hypotenuse of a right triangle is primarily determined by the length
4114 * of the longest side, when one side is small, and is strictly less
4115 * than one-and-a-half times as long as the longest side when both of
4116 * the sides are large.
4118 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
4119 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
4121 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
4123 * These observations are important because the calculation of the actual
4124 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
4125 * while for small values (up to about 20 or so), the approximations above
4126 * are correct to within an error of at most one grid or so.
4128 * Observe the use of "full" and "over" in the code below, and the use of
4129 * the specialized calculation involving "limit", all of which derive from
4130 * the observations given above. Basically, we note that the "circle" of
4131 * view is completely contained in an "octagon" whose bounds are easy to
4132 * determine, and that only a few steps are needed to derive the actual
4133 * bounds of the circle given the bounds of the octagon.
4135 * Note that by skipping all the grids in the corners of the octagon, we
4136 * place an upper limit on the number of grids in the field of view, given
4137 * that "full" is never more than 20. Of the 1681 grids in the "square" of
4138 * view, only about 1475 of these are in the "octagon" of view, and even
4139 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
4140 * entries to completely contain the actual field of view.
4142 * Note also the care taken to prevent "running off the map". The use of
4143 * explicit checks on the "validity" of the "diagonal", and the fact that
4144 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
4145 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
4146 * of multiple checks on the validity of grids.
4148 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
4149 * "ws","wn" variables. They work like this: While travelling down the
4150 * south-bound strip just to the east of the main south axis, as soon as
4151 * we get to a grid which does not "transmit" viewing, if all of the strips
4152 * preceding us (in this case, just the main axis) had terminated at or before
4153 * the same point, then we can stop, and reset the "max distance" to ourself.
4154 * So, each strip (named by major axis plus offset, thus "se" in this case)
4155 * maintains a "blockage" variable, initialized during the main axis step,
4156 * and checks it whenever a blockage is observed. After processing each
4157 * strip as far as the previous strip told us to process, the next strip is
4158 * told not to go farther than the current strip's farthest viewable grid,
4159 * unless open space is still available. This uses the "k" variable.
4161 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
4162 * macro is a replacement for "cave_los_bold()" which takes a pointer to
4163 * a grid instead of its location. The "cave_view_hack()" macro is a
4164 * chunk of code which adds the given location to the "view" array if it
4165 * is not already there, using both the actual location and a pointer to
4166 * the grid. See above.
4168 * By the way, the purpose of this code is to reduce the dependancy on the
4169 * "los()" function which is slow, and, in some cases, not very accurate.
4171 * It is very possible that I am the only person who fully understands this
4172 * function, and for that I am truly sorry, but efficiency was very important
4173 * and the "simple" version of this function was just not fast enough. I am
4174 * more than willing to replace this function with a simpler one, if it is
4175 * equally efficient, and especially willing if the new function happens to
4176 * derive "reverse-line-of-sight" at the same time, since currently monsters
4177 * just use an optimized hack of "you see me, so I see you", and then use the
4178 * actual "projectable()" function to check spell attacks.
4180 void update_view(void)
4185 int se, sw, ne, nw, es, en, ws, wn;
4189 POSITION y_max = current_floor_ptr->height - 1;
4190 POSITION x_max = current_floor_ptr->width - 1;
4194 /*** Initialize ***/
4197 if (view_reduce_view && !current_floor_ptr->dun_level)
4199 /* Full radius (10) */
4200 full = MAX_SIGHT / 2;
4202 /* Octagon factor (15) */
4203 over = MAX_SIGHT * 3 / 4;
4209 /* Full radius (20) */
4212 /* Octagon factor (30) */
4213 over = MAX_SIGHT * 3 / 2;
4217 /*** Step 0 -- Begin ***/
4219 /* Save the old "view" grids for later */
4220 for (n = 0; n < current_floor_ptr->view_n; n++)
4222 y = current_floor_ptr->view_y[n];
4223 x = current_floor_ptr->view_x[n];
4224 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4226 /* Mark the grid as not in "view" */
4227 g_ptr->info &= ~(CAVE_VIEW);
4229 /* Mark the grid as "seen" */
4230 g_ptr->info |= (CAVE_TEMP);
4232 /* Add it to the "seen" set */
4233 tmp_pos.y[tmp_pos.n] = y;
4234 tmp_pos.x[tmp_pos.n] = x;
4238 /* Start over with the "view" array */
4239 current_floor_ptr->view_n = 0;
4241 /*** Step 1 -- adjacent grids ***/
4243 /* Now start on the player */
4246 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4248 /* Assume the player grid is easily viewable */
4249 g_ptr->info |= (CAVE_XTRA);
4251 /* Assume the player grid is viewable */
4252 cave_view_hack(g_ptr, y, x);
4255 /*** Step 2 -- Major Diagonals ***/
4260 /* Scan south-east */
4261 for (d = 1; d <= z; d++)
4263 g_ptr = ¤t_floor_ptr->grid_array[y + d][x + d];
4264 g_ptr->info |= (CAVE_XTRA);
4265 cave_view_hack(g_ptr, y + d, x + d);
4266 if (!cave_los_grid(g_ptr)) break;
4269 /* Scan south-west */
4270 for (d = 1; d <= z; d++)
4272 g_ptr = ¤t_floor_ptr->grid_array[y + d][x - d];
4273 g_ptr->info |= (CAVE_XTRA);
4274 cave_view_hack(g_ptr, y + d, x - d);
4275 if (!cave_los_grid(g_ptr)) break;
4278 /* Scan north-east */
4279 for (d = 1; d <= z; d++)
4281 g_ptr = ¤t_floor_ptr->grid_array[y - d][x + d];
4282 g_ptr->info |= (CAVE_XTRA);
4283 cave_view_hack(g_ptr, y - d, x + d);
4284 if (!cave_los_grid(g_ptr)) break;
4287 /* Scan north-west */
4288 for (d = 1; d <= z; d++)
4290 g_ptr = ¤t_floor_ptr->grid_array[y - d][x - d];
4291 g_ptr->info |= (CAVE_XTRA);
4292 cave_view_hack(g_ptr, y - d, x - d);
4293 if (!cave_los_grid(g_ptr)) break;
4296 /*** Step 3 -- major axes ***/
4299 for (d = 1; d <= full; d++)
4301 g_ptr = ¤t_floor_ptr->grid_array[y + d][x];
4302 g_ptr->info |= (CAVE_XTRA);
4303 cave_view_hack(g_ptr, y + d, x);
4304 if (!cave_los_grid(g_ptr)) break;
4307 /* Initialize the "south strips" */
4311 for (d = 1; d <= full; d++)
4313 g_ptr = ¤t_floor_ptr->grid_array[y - d][x];
4314 g_ptr->info |= (CAVE_XTRA);
4315 cave_view_hack(g_ptr, y - d, x);
4316 if (!cave_los_grid(g_ptr)) break;
4319 /* Initialize the "north strips" */
4323 for (d = 1; d <= full; d++)
4325 g_ptr = ¤t_floor_ptr->grid_array[y][x + d];
4326 g_ptr->info |= (CAVE_XTRA);
4327 cave_view_hack(g_ptr, y, x + d);
4328 if (!cave_los_grid(g_ptr)) break;
4331 /* Initialize the "east strips" */
4335 for (d = 1; d <= full; d++)
4337 g_ptr = ¤t_floor_ptr->grid_array[y][x - d];
4338 g_ptr->info |= (CAVE_XTRA);
4339 cave_view_hack(g_ptr, y, x - d);
4340 if (!cave_los_grid(g_ptr)) break;
4343 /* Initialize the "west strips" */
4347 /*** Step 4 -- Divide each "octant" into "strips" ***/
4349 /* Now check each "diagonal" (in parallel) */
4350 for (n = 1; n <= over / 2; n++)
4352 POSITION ypn, ymn, xpn, xmn;
4354 /* Acquire the "bounds" of the maximal circle */
4356 if (z > full - n) z = full - n;
4357 while ((z + n + (n >> 1)) > full) z--;
4360 /* Access the four diagonal grids */
4370 /* Maximum distance */
4371 m = MIN(z, y_max - ypn);
4374 if ((xpn <= x_max) && (n < se))
4377 for (k = n, d = 1; d <= m; d++)
4379 /* Check grid "d" in strip "n", notice "blockage" */
4380 if (update_view_aux(ypn + d, xpn, ypn + d - 1, xpn - 1, ypn + d - 1, xpn))
4382 if (n + d >= se) break;
4385 /* Track most distant "non-blockage" */
4392 /* Limit the next strip */
4397 if ((xmn >= 0) && (n < sw))
4400 for (k = n, d = 1; d <= m; d++)
4402 /* Check grid "d" in strip "n", notice "blockage" */
4403 if (update_view_aux(ypn + d, xmn, ypn + d - 1, xmn + 1, ypn + d - 1, xmn))
4405 if (n + d >= sw) break;
4408 /* Track most distant "non-blockage" */
4415 /* Limit the next strip */
4424 /* Maximum distance */
4428 if ((xpn <= x_max) && (n < ne))
4431 for (k = n, d = 1; d <= m; d++)
4433 /* Check grid "d" in strip "n", notice "blockage" */
4434 if (update_view_aux(ymn - d, xpn, ymn - d + 1, xpn - 1, ymn - d + 1, xpn))
4436 if (n + d >= ne) break;
4439 /* Track most distant "non-blockage" */
4446 /* Limit the next strip */
4451 if ((xmn >= 0) && (n < nw))
4454 for (k = n, d = 1; d <= m; d++)
4456 /* Check grid "d" in strip "n", notice "blockage" */
4457 if (update_view_aux(ymn - d, xmn, ymn - d + 1, xmn + 1, ymn - d + 1, xmn))
4459 if (n + d >= nw) break;
4462 /* Track most distant "non-blockage" */
4469 /* Limit the next strip */
4478 /* Maximum distance */
4479 m = MIN(z, x_max - xpn);
4482 if ((ypn <= x_max) && (n < es))
4485 for (k = n, d = 1; d <= m; d++)
4487 /* Check grid "d" in strip "n", notice "blockage" */
4488 if (update_view_aux(ypn, xpn + d, ypn - 1, xpn + d - 1, ypn, xpn + d - 1))
4490 if (n + d >= es) break;
4493 /* Track most distant "non-blockage" */
4500 /* Limit the next strip */
4505 if ((ymn >= 0) && (n < en))
4508 for (k = n, d = 1; d <= m; d++)
4510 /* Check grid "d" in strip "n", notice "blockage" */
4511 if (update_view_aux(ymn, xpn + d, ymn + 1, xpn + d - 1, ymn, xpn + d - 1))
4513 if (n + d >= en) break;
4516 /* Track most distant "non-blockage" */
4523 /* Limit the next strip */
4532 /* Maximum distance */
4536 if ((ypn <= y_max) && (n < ws))
4539 for (k = n, d = 1; d <= m; d++)
4541 /* Check grid "d" in strip "n", notice "blockage" */
4542 if (update_view_aux(ypn, xmn - d, ypn - 1, xmn - d + 1, ypn, xmn - d + 1))
4544 if (n + d >= ws) break;
4547 /* Track most distant "non-blockage" */
4554 /* Limit the next strip */
4559 if ((ymn >= 0) && (n < wn))
4562 for (k = n, d = 1; d <= m; d++)
4564 /* Check grid "d" in strip "n", notice "blockage" */
4565 if (update_view_aux(ymn, xmn - d, ymn + 1, xmn - d + 1, ymn, xmn - d + 1))
4567 if (n + d >= wn) break;
4570 /* Track most distant "non-blockage" */
4577 /* Limit the next strip */
4584 /*** Step 5 -- Complete the algorithm ***/
4586 /* Update all the new grids */
4587 for (n = 0; n < current_floor_ptr->view_n; n++)
4589 y = current_floor_ptr->view_y[n];
4590 x = current_floor_ptr->view_x[n];
4591 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4593 /* Clear the "CAVE_XTRA" flag */
4594 g_ptr->info &= ~(CAVE_XTRA);
4596 /* Update only newly viewed grids */
4597 if (g_ptr->info & (CAVE_TEMP)) continue;
4599 /* Add it to later visual update */
4600 cave_note_and_redraw_later(g_ptr, y, x);
4603 /* Wipe the old grids, update as needed */
4604 for (n = 0; n < tmp_pos.n; n++)
4608 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4610 /* No longer in the array */
4611 g_ptr->info &= ~(CAVE_TEMP);
4613 /* Update only non-viewable grids */
4614 if (g_ptr->info & (CAVE_VIEW)) continue;
4616 /* Add it to later visual update */
4617 cave_redraw_later(g_ptr, y, x);
4623 /* Mega-Hack -- Visual update later */
4624 p_ptr->update |= (PU_DELAY_VIS);
4629 * Mega-Hack -- Delayed visual update
4630 * Only used if update_view(), update_lite() or update_mon_lite() was called
4632 void delayed_visual_update(void)
4638 /* Update needed grids */
4639 for (i = 0; i < current_floor_ptr->redraw_n; i++)
4641 y = current_floor_ptr->redraw_y[i];
4642 x = current_floor_ptr->redraw_x[i];
4643 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4645 /* Update only needed grids (prevent multiple updating) */
4646 if (!(g_ptr->info & CAVE_REDRAW)) continue;
4648 /* If required, note */
4649 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
4653 /* Hack -- Visual update of monster on this grid */
4654 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
4656 /* No longer in the array */
4657 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4661 current_floor_ptr->redraw_n = 0;
4666 * Hack -- forget the "flow" information
4668 void forget_flow(void)
4672 /* Check the entire dungeon */
4673 for (y = 0; y < current_floor_ptr->height; y++)
4675 for (x = 0; x < current_floor_ptr->width; x++)
4677 /* Forget the old data */
4678 current_floor_ptr->grid_array[y][x].dist = 0;
4679 current_floor_ptr->grid_array[y][x].cost = 0;
4680 current_floor_ptr->grid_array[y][x].when = 0;
4687 * Hack - speed up the update_flow algorithm by only doing
4688 * it everytime the player moves out of LOS of the last
4691 static POSITION flow_x = 0;
4692 static POSITION flow_y = 0;
4697 * Hack -- fill in the "cost" field of every grid that the player
4698 * can "reach" with the number of steps needed to reach that grid.
4699 * This also yields the "distance" of the player from every grid.
4701 * In addition, mark the "when" of the grids that can reach
4702 * the player with the incremented value of "flow_n".
4704 * Hack -- use the "seen" array as a "circular queue".
4706 * We do not need a priority queue because the cost from grid
4707 * to grid is always "one" and we process them in order.
4709 void update_flow(void)
4716 /* Paranoia -- make sure the array is empty */
4717 if (tmp_pos.n) return;
4719 /* The last way-point is on the map */
4720 if (running && in_bounds(flow_y, flow_x))
4722 /* The way point is in sight - do not update. (Speedup) */
4723 if (current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
4726 /* Erase all of the current flow information */
4727 for (y = 0; y < current_floor_ptr->height; y++)
4729 for (x = 0; x < current_floor_ptr->width; x++)
4731 current_floor_ptr->grid_array[y][x].cost = 0;
4732 current_floor_ptr->grid_array[y][x].dist = 0;
4736 /* Save player position */
4740 /* Add the player's grid to the queue */
4741 tmp_pos.y[0] = p_ptr->y;
4742 tmp_pos.x[0] = p_ptr->x;
4744 /* Now process the queue */
4745 while (flow_head != flow_tail)
4749 /* Extract the next entry */
4750 ty = tmp_pos.y[flow_tail];
4751 tx = tmp_pos.x[flow_tail];
4753 /* Forget that entry */
4754 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4756 /* Add the "children" */
4757 for (d = 0; d < 8; d++)
4759 int old_head = flow_head;
4760 byte_hack m = current_floor_ptr->grid_array[ty][tx].cost + 1;
4761 byte_hack n = current_floor_ptr->grid_array[ty][tx].dist + 1;
4764 /* Child location */
4765 y = ty + ddy_ddd[d];
4766 x = tx + ddx_ddd[d];
4768 /* Ignore player's grid */
4769 if (player_bold(y, x)) continue;
4771 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4773 if (is_closed_door(g_ptr->feat)) m += 3;
4775 /* Ignore "pre-stamped" entries */
4776 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
4778 /* Ignore "walls" and "rubble" */
4779 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
4781 /* Save the flow cost */
4782 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
4783 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
4785 /* Hack -- limit flow depth */
4786 if (n == MONSTER_FLOW_DEPTH) continue;
4788 /* Enqueue that entry */
4789 tmp_pos.y[flow_head] = y;
4790 tmp_pos.x[flow_head] = x;
4792 /* Advance the queue */
4793 if (++flow_head == TEMP_MAX) flow_head = 0;
4795 /* Hack -- notice overflow by forgetting new entry */
4796 if (flow_head == flow_tail) flow_head = old_head;
4802 static int scent_when = 0;
4805 * Characters leave scent trails for perceptive monsters to track.
4807 * Smell is rather more limited than sound. Many creatures cannot use
4808 * it at all, it doesn't extend very far outwards from the character's
4809 * current position, and monsters can use it to home in the character,
4810 * but not to run away from him.
4812 * Smell is valued according to age. When a character takes his current_world_ptr->game_turn,
4813 * scent is aged by one, and new scent of the current age is laid down.
4814 * Speedy characters leave more scent, true, but it also ages faster,
4815 * which makes it harder to hunt them down.
4817 * Whenever the age count loops, most of the scent trail is erased and
4818 * the age of the remainder is recalculated.
4820 void update_smell(void)
4825 /* Create a table that controls the spread of scent */
4826 const int scent_adjust[5][5] =
4835 /* Loop the age and adjust scent values when necessary */
4836 if (++scent_when == 254)
4838 /* Scan the entire dungeon */
4839 for (y = 0; y < current_floor_ptr->height; y++)
4841 for (x = 0; x < current_floor_ptr->width; x++)
4843 int w = current_floor_ptr->grid_array[y][x].when;
4844 current_floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
4853 /* Lay down new scent */
4854 for (i = 0; i < 5; i++)
4856 for (j = 0; j < 5; j++)
4860 /* Translate table to map grids */
4861 y = i + p_ptr->y - 2;
4862 x = j + p_ptr->x - 2;
4865 if (!in_bounds(y, x)) continue;
4867 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4869 /* Walls, water, and lava cannot hold scent. */
4870 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
4872 /* Grid must not be blocked by walls from the character */
4873 if (!player_has_los_bold(y, x)) continue;
4875 /* Note grids that are too far away */
4876 if (scent_adjust[i][j] == -1) continue;
4878 /* Mark the grid with new scent */
4879 g_ptr->when = scent_when + scent_adjust[i][j];
4886 * Hack -- map the current panel (plus some) ala "magic mapping"
4888 void map_area(POSITION range)
4894 feature_type *f_ptr;
4896 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) range /= 3;
4898 /* Scan that area */
4899 for (y = 1; y < current_floor_ptr->height - 1; y++)
4901 for (x = 1; x < current_floor_ptr->width - 1; x++)
4903 if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
4905 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4907 /* Memorize terrain of the grid */
4908 g_ptr->info |= (CAVE_KNOWN);
4910 /* Feature code (applying "mimic" field) */
4911 feat = get_feat_mimic(g_ptr);
4912 f_ptr = &f_info[feat];
4914 /* All non-walls are "checked" */
4915 if (!have_flag(f_ptr->flags, FF_WALL))
4917 /* Memorize normal features */
4918 if (have_flag(f_ptr->flags, FF_REMEMBER))
4920 /* Memorize the object */
4921 g_ptr->info |= (CAVE_MARK);
4924 /* Memorize known walls */
4925 for (i = 0; i < 8; i++)
4927 g_ptr = ¤t_floor_ptr->grid_array[y + ddy_ddd[i]][x + ddx_ddd[i]];
4929 /* Feature code (applying "mimic" field) */
4930 feat = get_feat_mimic(g_ptr);
4931 f_ptr = &f_info[feat];
4933 /* Memorize walls (etc) */
4934 if (have_flag(f_ptr->flags, FF_REMEMBER))
4936 /* Memorize the walls */
4937 g_ptr->info |= (CAVE_MARK);
4944 p_ptr->redraw |= (PR_MAP);
4946 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4951 * Change the "feat" flag for a grid, and notice/redraw the grid
4953 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
4955 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
4956 feature_type *f_ptr = &f_info[feat];
4957 bool old_los, old_mirror;
4959 if (!character_dungeon)
4961 /* Clear mimic type */
4964 /* Change the feature */
4967 /* Hack -- glow the GLOW terrain */
4968 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
4973 for (i = 0; i < 9; i++)
4975 yy = y + ddy_ddd[i];
4976 xx = x + ddx_ddd[i];
4977 if (!in_bounds2(yy, xx)) continue;
4978 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
4985 old_los = cave_have_flag_bold(y, x, FF_LOS);
4986 old_mirror = is_mirror_grid(g_ptr);
4988 /* Clear mimic type */
4991 /* Change the feature */
4994 /* Remove flag for mirror/glyph */
4995 g_ptr->info &= ~(CAVE_OBJECT);
4997 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
4999 g_ptr->info &= ~(CAVE_GLOW);
5000 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
5002 update_local_illumination(y, x);
5005 /* Check for change to boring grid */
5006 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
5007 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
5013 /* Check if los has changed */
5014 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
5017 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
5019 update_local_illumination(y, x);
5021 #endif /* COMPLEX_WALL_ILLUMINATION */
5023 /* Update the visuals */
5024 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
5027 /* Hack -- glow the GLOW terrain */
5028 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
5034 for (i = 0; i < 9; i++)
5036 yy = y + ddy_ddd[i];
5037 xx = x + ddx_ddd[i];
5038 if (!in_bounds2(yy, xx)) continue;
5039 cc_ptr = ¤t_floor_ptr->grid_array[yy][xx];
5040 cc_ptr->info |= CAVE_GLOW;
5042 if (player_has_los_grid(cc_ptr))
5044 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
5051 update_local_illumination(yy, xx);
5054 if (p_ptr->special_defense & NINJA_S_STEALTH)
5056 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
5062 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
5064 feature_type *f_ptr = &f_info[newfeat];
5066 if (have_flag(f_ptr->flags, FF_CONVERT))
5068 switch (f_ptr->subtype)
5070 case CONVERT_TYPE_FLOOR:
5071 return feat_ground_type[randint0(100)];
5072 case CONVERT_TYPE_WALL:
5073 return feat_wall_type[randint0(100)];
5074 case CONVERT_TYPE_INNER:
5075 return feat_wall_inner;
5076 case CONVERT_TYPE_OUTER:
5077 return feat_wall_outer;
5078 case CONVERT_TYPE_SOLID:
5079 return feat_wall_solid;
5080 case CONVERT_TYPE_STREAM1:
5081 return d_info[p_ptr->dungeon_idx].stream1;
5082 case CONVERT_TYPE_STREAM2:
5083 return d_info[p_ptr->dungeon_idx].stream2;
5088 else return newfeat;
5093 * Take a feature, determine what that feature becomes
5094 * through applying the given action.
5096 FEAT_IDX feat_state(FEAT_IDX feat, int action)
5098 feature_type *f_ptr = &f_info[feat];
5101 /* Get the new feature */
5102 for (i = 0; i < MAX_FEAT_STATES; i++)
5104 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
5107 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
5109 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
5113 * Takes a location and action and changes the feature at that
5114 * location through applying the given action.
5116 void cave_alter_feat(POSITION y, POSITION x, int action)
5118 /* Set old feature */
5119 FEAT_IDX oldfeat = current_floor_ptr->grid_array[y][x].feat;
5121 /* Get the new feat */
5122 FEAT_IDX newfeat = feat_state(oldfeat, action);
5125 if (newfeat == oldfeat) return;
5127 /* Set the new feature */
5128 cave_set_feat(y, x, newfeat);
5130 if (!(feature_action_flags[action] & FAF_NO_DROP))
5132 feature_type *old_f_ptr = &f_info[oldfeat];
5133 feature_type *f_ptr = &f_info[newfeat];
5137 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
5139 /* Place some gold */
5145 if (have_flag(old_f_ptr->flags, FF_HAS_ITEM) && !have_flag(f_ptr->flags, FF_HAS_ITEM) && (randint0(100) < (15 - current_floor_ptr->dun_level / 2)))
5148 place_object(y, x, 0L);
5152 if (found && character_dungeon && player_can_see_bold(y, x))
5154 msg_print(_("何かを発見した!", "You have found something!"));
5158 if (feature_action_flags[action] & FAF_CRASH_GLASS)
5160 feature_type *old_f_ptr = &f_info[oldfeat];
5162 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
5164 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
5165 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
5171 /* Remove a mirror */
5172 void remove_mirror(POSITION y, POSITION x)
5174 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5176 /* Remove the mirror */
5177 g_ptr->info &= ~(CAVE_OBJECT);
5180 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
5182 g_ptr->info &= ~(CAVE_GLOW);
5183 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
5184 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
5186 update_local_illumination(y, x);
5196 * Return TRUE if there is a mirror on the grid.
5198 bool is_mirror_grid(grid_type *g_ptr)
5200 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
5208 * Return TRUE if there is a mirror on the grid.
5210 bool is_glyph_grid(grid_type *g_ptr)
5212 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
5220 * Return TRUE if there is a mirror on the grid.
5222 bool is_explosive_rune_grid(grid_type *g_ptr)
5224 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
5232 * Track a new monster
5234 void health_track(MONSTER_IDX m_idx)
5236 /* Mount monster is already tracked */
5237 if (m_idx && m_idx == p_ptr->riding) return;
5239 /* Track a new guy */
5240 p_ptr->health_who = m_idx;
5242 /* Redraw (later) */
5243 p_ptr->redraw |= (PR_HEALTH);
5249 * Hack -- track the given monster race
5251 void monster_race_track(MONRACE_IDX r_idx)
5253 /* Save this monster ID */
5254 p_ptr->monster_race_idx = r_idx;
5256 p_ptr->window |= (PW_MONSTER);
5262 * Hack -- track the given object kind
5264 void object_kind_track(KIND_OBJECT_IDX k_idx)
5266 /* Save this monster ID */
5267 p_ptr->object_kind_idx = k_idx;
5269 p_ptr->window |= (PW_OBJECT);
5274 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
5275 * @param m_idx モンスターID
5279 * @return テレポート先として妥当ならばtrue
5281 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
5283 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
5284 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5285 feature_type *f_ptr = &f_info[g_ptr->feat];
5287 /* Require "teleportable" space */
5288 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5290 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
5291 if (player_bold(y, x)) return FALSE;
5293 /* Hack -- no teleport onto glyph of warding */
5294 if (is_glyph_grid(g_ptr)) return FALSE;
5295 if (is_explosive_rune_grid(g_ptr)) return FALSE;
5297 if (!(mode & TELEPORT_PASSIVE))
5299 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
5306 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
5310 * @return テレポート先として妥当ならばtrue
5312 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
5314 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5315 feature_type *f_ptr = &f_info[g_ptr->feat];
5317 /* Require "teleportable" space */
5318 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5320 /* No magical teleporting into vaults and such */
5321 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
5323 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
5325 /* don't teleport on a trap. */
5326 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
5328 if (!(mode & TELEPORT_PASSIVE))
5330 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
5332 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
5334 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
5337 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
5339 /* Always forbid deep lava */
5340 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
5342 /* Forbid shallow lava when the player don't have levitation */
5343 if (!p_ptr->levitation) return FALSE;
5352 * @brief 地形は開くものであって、かつ開かれているかを返す /
5353 * Attempt to open the given chest at the given location
5355 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
5357 bool is_open(FEAT_IDX feat)
5359 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));
5363 * @brief プレイヤーが地形踏破可能かを返す
5364 * @param feature 判定したい地形ID
5365 * @param mode 移動に関するオプションフラグ
5366 * @return 移動可能ならばTRUEを返す
5368 bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
5370 feature_type *f_ptr = &f_info[feature];
5372 if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[current_floor_ptr->m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
5374 if (have_flag(f_ptr->flags, FF_PATTERN))
5376 if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
5379 if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
5380 if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
5381 if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
5383 if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;