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
22 #include "projection.h"
23 #include "object-hook.h"
31 #include "monster-status.h"
32 #include "player-status.h"
34 static byte display_autopick; /*!< 自動拾い状態の設定フラグ */
35 static int match_autopick;
36 static object_type *autopick_obj; /*!< 各種自動拾い処理時に使うオブジェクトポインタ */
37 static int feat_priority; /*!< マップ縮小表示時に表示すべき地形の優先度を保管する */
41 * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
42 * @return 配置に成功したらTRUEを返す
44 bool new_player_spot(void)
46 POSITION y = 0, x = 0;
47 int max_attempts = 10000;
52 /* Place the player */
53 while (max_attempts--)
55 /* Pick a legal spot */
56 y = (POSITION)rand_range(1, current_floor_ptr->height - 2);
57 x = (POSITION)rand_range(1, current_floor_ptr->width - 2);
59 g_ptr = ¤t_floor_ptr->grid_array[y][x];
61 /* Must be a "naked" floor grid */
62 if (g_ptr->m_idx) continue;
63 if (current_floor_ptr->dun_level)
65 f_ptr = &f_info[g_ptr->feat];
67 if (max_attempts > 5000) /* Rule 1 */
69 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
73 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
74 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
77 /* Refuse to start on anti-teleport grids in dungeon */
78 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
80 if (!player_can_enter(g_ptr->feat, 0)) continue;
81 if (!in_bounds(y, x)) continue;
83 /* Refuse to start on anti-teleport grids */
84 if (g_ptr->info & (CAVE_ICKY)) continue;
89 if (max_attempts < 1) /* Should be -1, actually if we failed... */
92 /* Save the new player grid */
102 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
103 * @param y 配置を試みたいマスのY座標
104 * @param x 配置を試みたいマスのX座標
107 void place_random_stairs(POSITION y, POSITION x)
109 bool up_stairs = TRUE;
110 bool down_stairs = TRUE;
112 g_ptr = ¤t_floor_ptr->grid_array[y][x];
113 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
116 if (!current_floor_ptr->dun_level) up_stairs = FALSE;
119 if (ironman_downward) up_stairs = FALSE;
122 if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
125 if (quest_number(current_floor_ptr->dun_level) && (current_floor_ptr->dun_level > 1)) down_stairs = FALSE;
127 /* We can't place both */
128 if (down_stairs && up_stairs)
130 /* Choose a staircase randomly */
131 if (randint0(100) < 50) up_stairs = FALSE;
132 else down_stairs = FALSE;
135 /* Place the stairs */
136 if (up_stairs) place_up_stairs(y, x);
137 else if (down_stairs) place_down_stairs(y, x);
141 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
142 * @param y ドアの配置を試みたいマスのY座標
143 * @param x ドアの配置を試みたいマスのX座標
144 * @param room 部屋に接している場合向けのドア生成か否か
147 void place_random_door(POSITION y, POSITION x, bool room)
150 FEAT_IDX feat = feat_none;
151 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
153 /* Initialize mimic info */
156 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
158 place_floor_bold(y, x);
162 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
163 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
164 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
166 /* Choose an object */
167 tmp = randint0(1000);
169 /* Open doors (300/1000) */
172 /* Create open door */
173 feat = feat_door[type].open;
176 /* Broken doors (100/1000) */
179 /* Create broken door */
180 feat = feat_door[type].broken;
183 /* Secret doors (200/1000) */
186 /* Create secret door */
187 place_closed_door(y, x, type);
189 if (type != DOOR_CURTAIN)
191 /* Hide. If on the edge of room, use outer wall. */
192 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
194 /* Floor type terrain cannot hide a door */
195 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
197 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
199 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
206 /* Closed, locked, or stuck doors (400/1000) */
207 else place_closed_door(y, x, type);
211 if (feat != feat_none)
213 set_cave_feat(y, x, feat);
217 place_floor_bold(y, x);
221 delete_monster(y, x);
225 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
226 * @param y ドアの配置を試みたいマスのY座標
227 * @param x ドアの配置を試みたいマスのX座標
228 * @param type ドアの地形ID
231 void place_closed_door(POSITION y, POSITION x, int type)
234 FEAT_IDX feat = feat_none;
236 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
238 place_floor_bold(y, x);
242 /* Choose an object */
245 /* Closed doors (300/400) */
248 /* Create closed door */
249 feat = feat_door[type].closed;
252 /* Locked doors (99/400) */
255 /* Create locked door */
256 feat = feat_locked_door_random(type);
259 /* Stuck doors (1/400) */
262 /* Create jammed door */
263 feat = feat_jammed_door_random(type);
266 if (feat != feat_none)
268 cave_set_feat(y, x, feat);
270 /* Now it is not floor */
271 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
275 place_floor_bold(y, x);
280 * @brief 鍵のかかったドアを配置する
281 * @param y 配置したいフロアのY座標
282 * @param x 配置したいフロアのX座標
285 void place_locked_door(POSITION y, POSITION x)
287 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
289 place_floor_bold(y, x);
293 set_cave_feat(y, x, feat_locked_door_random((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
294 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
295 delete_monster(y, x);
302 * @param y 配置したいフロアのY座標
303 * @param x 配置したいフロアのX座標
304 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
307 void place_secret_door(POSITION y, POSITION x, int type)
309 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
311 place_floor_bold(y, x);
315 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
317 if (type == DOOR_DEFAULT)
319 type = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
320 one_in_((d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
321 ((d_info[p_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
324 /* Create secret door */
325 place_closed_door(y, x, type);
327 if (type != DOOR_CURTAIN)
329 /* Hide by inner wall because this is used in rooms only */
330 g_ptr->mimic = feat_wall_inner;
332 /* Floor type terrain cannot hide a door */
333 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
335 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
337 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
343 g_ptr->info &= ~(CAVE_FLOOR);
344 delete_monster(y, x);
349 * Routine used by the random vault creators to add a door to a location
350 * Note that range checking has to be done in the calling routine.
352 * The doors must be INSIDE the allocated region.
354 void add_door(POSITION x, POSITION y)
356 /* Need to have a wall in the center square */
357 if (!is_outer_bold(y, x)) return;
368 if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
369 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
372 place_secret_door(y, x, DOOR_DEFAULT);
374 /* set boundarys so don't get wide doors */
375 place_solid_bold(y, x - 1);
376 place_solid_bold(y, x + 1);
385 * where x = don't care
388 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
389 is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
392 place_secret_door(y, x, DOOR_DEFAULT);
394 /* set boundarys so don't get wide doors */
395 place_solid_bold(y - 1, x);
396 place_solid_bold(y + 1, x);
401 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
402 * @param y1 基準となるマスのY座標
403 * @param x1 基準となるマスのX座標
405 * @note Assumes "in_bounds(y1, x1)"
407 * XXX XXX This routine currently only counts actual "empty floor"\n
408 * grids which are not in rooms. We might want to also count stairs,\n
409 * open doors, closed doors, etc.
411 static int next_to_corr(POSITION y1, POSITION x1)
418 /* Scan adjacent grids */
419 for (i = 0; i < 4; i++)
421 /* Extract the location */
424 g_ptr = ¤t_floor_ptr->grid_array[y][x];
426 /* Skip non floors */
427 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
429 /* Skip non "empty floor" grids */
430 if (!is_floor_grid(g_ptr))
433 /* Skip grids inside rooms */
434 if (g_ptr->info & (CAVE_ROOM)) continue;
436 /* Count these grids */
440 /* Return the number of corridors */
445 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
446 * @param y 判定を行いたいマスのY座標
447 * @param x 判定を行いたいマスのX座標
448 * @return ドアを設置可能ならばTRUEを返す
449 * @note Assumes "in_bounds(y1, x1)"
452 * Assumes "in_bounds(y, x)"\n
454 static bool possible_doorway(POSITION y, POSITION x)
456 /* Count the adjacent corridors */
457 if (next_to_corr(y, x) >= 2)
460 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
461 cave_have_flag_bold(y + 1, x, FF_WALL))
466 /* Check Horizontal */
467 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
468 cave_have_flag_bold(y, x + 1, FF_WALL))
479 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
480 * @param y 設置を行いたいマスのY座標
481 * @param x 設置を行いたいマスのX座標
484 void try_door(POSITION y, POSITION x)
485 { if (!in_bounds(y, x)) return;
488 if (cave_have_flag_bold(y, x, FF_WALL)) return;
490 /* Ignore room grids */
491 if (current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
493 /* Occasional door (if allowed) */
494 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
497 place_random_door(y, x, FALSE);
503 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
504 * @param x1 長方形の左端X座標(-1)
505 * @param x2 長方形の右端X座標(+1)
506 * @param y1 長方形の上端Y座標(-1)
507 * @param y2 長方形の下端Y座標(+1)
511 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
515 /* Place a full floor under the room */
516 for (y = y1 - 1; y <= y2 + 1; y++)
518 for (x = x1 - 1; x <= x2 + 1; x++)
520 place_floor_bold(y, x);
521 add_cave_info(y, x, CAVE_ROOM);
522 if (light) add_cave_info(y, x, CAVE_GLOW);
529 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
530 * @param x1 長方形の左端X座標(-1)
531 * @param x2 長方形の右端X座標(+1)
532 * @param y1 長方形の上端Y座標(-1)
533 * @param y2 長方形の下端Y座標(+1)
537 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
541 place_floor(x1, x2, y1, y2, light);
543 /* Walls around the room */
544 for (y = y1 - 1; y <= y2 + 1; y++)
546 place_outer_bold(y, x1 - 1);
547 place_outer_bold(y, x2 + 1);
549 for (x = x1 - 1; x <= x2 + 1; x++)
551 place_outer_bold(y1 - 1, x);
552 place_outer_bold(y2 + 1, x);
558 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
559 * @param y 配置したい中心マスのY座標
560 * @param x 配置したい中心マスのX座標
564 * Only really called by some of the "vault" routines.
566 void vault_objects(POSITION y, POSITION x, int num)
569 int i = 0, j = y, k = x;
574 /* Attempt to place 'num' objects */
575 for (; num > 0; --num)
577 /* Try up to 11 spots looking for empty space */
578 for (i = 0; i < 11; ++i)
580 /* Pick a random location */
581 while (dummy < SAFE_MAX_ATTEMPTS)
583 j = rand_spread(y, 2);
584 k = rand_spread(x, 3);
586 if (!in_bounds(j, k)) continue;
590 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
592 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
595 /* Require "clean" floor space */
596 g_ptr = ¤t_floor_ptr->grid_array[j][k];
597 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
599 if (randint0(100) < 75)
601 place_object(j, k, 0L);
608 /* Placement accomplished */
615 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
616 * @param y トラップを配置したいマスの中心Y座標
617 * @param x トラップを配置したいマスの中心X座標
618 * @param yd Y方向の配置分散マス数
619 * @param xd X方向の配置分散マス数
622 * Only really called by some of the "vault" routines.
624 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
626 int count = 0, y1 = y, x1 = x;
632 for (count = 0; count <= 5; count++)
635 while (dummy < SAFE_MAX_ATTEMPTS)
637 y1 = rand_spread(y, yd);
638 x1 = rand_spread(x, xd);
640 if (!in_bounds(y1, x1)) continue;
644 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
646 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
649 /* Require "naked" floor grids */
650 g_ptr = ¤t_floor_ptr->grid_array[y1][x1];
651 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
661 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
662 * @param y トラップを配置したいマスの中心Y座標
663 * @param x トラップを配置したいマスの中心X座標
664 * @param yd Y方向の配置分散マス数
665 * @param xd X方向の配置分散マス数
666 * @param num 配置したいトラップの数
669 * Only really called by some of the "vault" routines.
671 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
675 for (i = 0; i < num; i++)
677 vault_trap_aux(y, x, yd, xd);
682 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
683 * @param y1 モンスターを配置したいマスの中心Y座標
684 * @param x1 モンスターを配置したいマスの中心X座標
685 * @param num 配置したいモンスターの数
688 * Only really called by some of the "vault" routines.
690 void vault_monsters(POSITION y1, POSITION x1, int num)
696 /* Try to summon "num" monsters "near" the given location */
697 for (k = 0; k < num; k++)
699 /* Try nine locations */
700 for (i = 0; i < 9; i++)
704 /* Pick a nearby location */
705 scatter(&y, &x, y1, x1, d, 0);
707 /* Require "empty" floor grids */
708 g_ptr = ¤t_floor_ptr->grid_array[y][x];
709 if (!cave_empty_grid(g_ptr)) continue;
711 /* Place the monster (allow groups) */
712 current_floor_ptr->monster_level = current_floor_ptr->base_level + 2;
713 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
714 current_floor_ptr->monster_level = current_floor_ptr->base_level;
720 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
721 * @param x チェックするマスのX座標
722 * @param y チェックするマスのY座標
723 * @return 床系地形ならばTRUE
725 bool get_is_floor(POSITION x, POSITION y)
727 if (!in_bounds(y, x))
733 /* Do the real check */
734 if (is_floor_bold(y, x)) return (TRUE);
740 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
741 * @param x 地形を変えたいマスのX座標
742 * @param y 地形を変えたいマスのY座標
745 void set_floor(POSITION x, POSITION y)
747 if (!in_bounds(y, x))
753 if (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
755 /* A room border don't touch. */
759 /* Set to be floor if is a wall (don't touch lakes). */
760 if (is_extra_bold(y, x))
761 place_floor_bold(y, x);
765 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
766 * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
769 void place_bound_perm_wall(grid_type *g_ptr)
771 if (bound_walls_perm)
773 /* Clear boundary mimic */
778 feature_type *f_ptr = &f_info[g_ptr->feat];
780 /* Hack -- Decline boundary walls with known treasure */
781 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
782 !have_flag(f_ptr->flags, FF_SECRET))
783 g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
785 /* Set boundary mimic */
786 g_ptr->mimic = g_ptr->feat;
789 /* Add "solid" perma-wall */
790 place_solid_perm_grid(g_ptr);
795 * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
802 POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
804 POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
805 POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
807 /* Squared distance */
808 POSITION target = (dy * dy) + (dx * dx);
810 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
811 POSITION d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
816 if (!dy || !dx) return d;
820 /* Approximate error */
821 err = (target - d * d) / (2 * d);
823 /* No error - we are done */
826 /* Adjust distance */
835 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
836 * @param g_ptr マス構造体の参照ポインタ
837 * @return 看破済みの罠があるならTRUEを返す。
839 bool is_known_trap(grid_type *g_ptr)
841 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
842 is_trap(g_ptr->feat)) return TRUE;
850 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
851 * @param g_ptr マス構造体の参照ポインタ
852 * @return 隠されたドアがあるならTRUEを返す。
854 bool is_hidden_door(grid_type *g_ptr)
856 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
857 is_closed_door(g_ptr->feat))
864 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
869 * @return LOSが通っているならTRUEを返す。
871 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
872 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
874 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
876 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
877 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
878 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
880 * We assume that the "mathematical corner" of a non-floor tile does not\n
881 * block line of sight.\n
883 * Because this function uses (short) ints for all calculations, overflow may\n
884 * occur if dx and dy exceed 90.\n
886 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
887 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
888 * we can use integer arithmetic.\n
890 * We travel from start to finish along the longer axis, starting at the border\n
891 * between the first and second tiles, where the y offset = .5 * slope, taking\n
892 * into account the scale factor. See below.\n
894 * Also note that this function and the "move towards target" code do NOT\n
895 * share the same properties. Thus, you can see someone, target them, and\n
896 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
897 * by clever choice of target locations, you can sometimes throw a "curve".\n
899 * Note that "line of sight" is not "reflexive" in all cases.\n
901 * Use the "projectable()" routine to test "spell/missile line of sight".\n
903 * Use the "update_view()" function to determine player line-of-sight.\n
905 bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
925 /* Slope, or 1/Slope, of LOS */
929 /* Extract the offset */
933 /* Extract the absolute offset */
938 /* Handle adjacent (or identical) grids */
939 if ((ax < 2) && (ay < 2)) return TRUE;
942 /* Paranoia -- require "safe" origin */
943 /* if (!in_bounds(y1, x1)) return FALSE; */
944 /* if (!in_bounds(y2, x2)) return FALSE; */
947 /* Directly South/North */
950 /* South -- check for walls */
953 for (ty = y1 + 1; ty < y2; ty++)
955 if (!cave_los_bold(ty, x1)) return FALSE;
959 /* North -- check for walls */
962 for (ty = y1 - 1; ty > y2; ty--)
964 if (!cave_los_bold(ty, x1)) return FALSE;
972 /* Directly East/West */
975 /* East -- check for walls */
978 for (tx = x1 + 1; tx < x2; tx++)
980 if (!cave_los_bold(y1, tx)) return FALSE;
984 /* West -- check for walls */
987 for (tx = x1 - 1; tx > x2; tx--)
989 if (!cave_los_bold(y1, tx)) return FALSE;
998 /* Extract some signs */
999 sx = (dx < 0) ? -1 : 1;
1000 sy = (dy < 0) ? -1 : 1;
1003 /* Vertical "knights" */
1008 if (cave_los_bold(y1 + sy, x1)) return TRUE;
1012 /* Horizontal "knights" */
1017 if (cave_los_bold(y1, x1 + sx)) return TRUE;
1022 /* Calculate scale factor div 2 */
1025 /* Calculate scale factor */
1029 /* Travel horizontally */
1032 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
1038 /* Consider the special case where slope == 1. */
1049 /* Note (below) the case (qy == f2), where */
1050 /* the LOS exactly meets the corner of a tile. */
1053 if (!cave_los_bold(ty, tx)) return FALSE;
1064 if (!cave_los_bold(ty, tx)) return FALSE;
1077 /* Travel vertically */
1080 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
1096 /* Note (below) the case (qx == f2), where */
1097 /* the LOS exactly meets the corner of a tile. */
1100 if (!cave_los_bold(ty, tx)) return FALSE;
1111 if (!cave_los_bold(ty, tx)) return FALSE;
1128 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
1132 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
1135 * @return 指定された座標に照明がかかっているならTRUEを返す。。
1137 static bool check_local_illumination(POSITION y, POSITION x)
1139 /* Hack -- move towards player */
1140 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
1141 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
1143 /* Check for "local" illumination */
1145 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1147 /* Check for "complex" illumination */
1148 if ((feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][xx])) &&
1149 (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
1150 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[y][xx])) &&
1151 (current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
1152 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][x])) &&
1153 (current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
1159 #else /* COMPLEX_WALL_ILLUMINATION */
1161 /* Check for "simple" illumination */
1162 return (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
1164 #endif /* COMPLEX_WALL_ILLUMINATION */
1168 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
1169 #define update_local_illumination_aux(Y, X) \
1171 if (player_has_los_bold((Y), (X))) \
1173 /* Update the monster */ \
1174 if (current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster(current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
1176 /* Notice and redraw */ \
1177 note_spot((Y), (X)); \
1178 lite_spot((Y), (X)); \
1183 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
1188 void update_local_illumination(POSITION y, POSITION x)
1193 if (!in_bounds(y, x)) return;
1195 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1197 if ((y != p_ptr->y) && (x != p_ptr->x))
1199 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1200 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1201 update_local_illumination_aux(yy, xx);
1202 update_local_illumination_aux(y, xx);
1203 update_local_illumination_aux(yy, x);
1205 else if (x != p_ptr->x) /* y == p_ptr->y */
1207 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1208 for (i = -1; i <= 1; i++)
1211 update_local_illumination_aux(yy, xx);
1214 update_local_illumination_aux(yy, x);
1216 update_local_illumination_aux(yy, x);
1218 else if (y != p_ptr->y) /* x == p_ptr->x */
1220 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1221 for (i = -1; i <= 1; i++)
1224 update_local_illumination_aux(yy, xx);
1227 update_local_illumination_aux(y, xx);
1229 update_local_illumination_aux(y, xx);
1231 else /* Player's grid */
1233 for (i = 0; i < 8; i++)
1235 yy = y + ddy_cdd[i];
1236 xx = x + ddx_cdd[i];
1237 update_local_illumination_aux(yy, xx);
1241 #else /* COMPLEX_WALL_ILLUMINATION */
1243 if ((y != p_ptr->y) && (x != p_ptr->x))
1245 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1246 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1247 update_local_illumination_aux(yy, xx);
1249 else if (x != p_ptr->x) /* y == p_ptr->y */
1251 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1252 for (i = -1; i <= 1; i++)
1255 update_local_illumination_aux(yy, xx);
1258 else if (y != p_ptr->y) /* x == p_ptr->x */
1260 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1261 for (i = -1; i <= 1; i++)
1264 update_local_illumination_aux(yy, xx);
1267 else /* Player's grid */
1269 for (i = 0; i < 8; i++)
1271 yy = y + ddy_cdd[i];
1272 xx = x + ddx_cdd[i];
1273 update_local_illumination_aux(yy, xx);
1277 #endif /* COMPLEX_WALL_ILLUMINATION */
1282 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
1285 * @return 視覚に収められる状態ならTRUEを返す
1287 * He must have vision, illumination, and line of sight.\n
1289 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
1290 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
1292 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
1293 * that a wall is visible from any direction. That would be odd. Except\n
1294 * under wizard light, which might make sense. Thus, for walls, we require\n
1295 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
1296 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
1297 * in line of sight of the player.\n
1299 * This extra check is expensive, but it provides a more "correct" semantics.\n
1301 * Note that we should not run this check on walls which are "outer walls" of\n
1302 * the dungeon, or we will induce a memory fault, but actually verifying all\n
1303 * of the locations would be extremely expensive.\n
1305 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
1306 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
1307 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
1308 * and the player has more important things on his mind when he is attacking a\n
1309 * monster vault. It is annoying, but an extremely important optimization.\n
1311 * Note that "glowing walls" are only considered to be "illuminated" if the\n
1312 * grid which is next to the wall in the direction of the player is also a\n
1313 * "glowing" grid. This prevents the player from being able to "see" the\n
1314 * walls of illuminated rooms from a corridor outside the room.\n
1316 bool player_can_see_bold(POSITION y, POSITION x)
1320 /* Blind players see nothing */
1321 if (p_ptr->blind) return FALSE;
1323 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1325 /* Note that "torch-lite" yields "illumination" */
1326 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
1328 /* Require line of sight to the grid */
1329 if (!player_has_los_bold(y, x)) return FALSE;
1331 /* Noctovision of Ninja */
1332 if (p_ptr->see_nocto) return TRUE;
1334 /* Require "perma-lite" of the grid */
1335 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
1337 /* Feature code (applying "mimic" field) */
1338 /* Floors are simple */
1339 if (feat_supports_los(get_feat_mimic(g_ptr))) return TRUE;
1341 /* Check for "local" illumination */
1342 return check_local_illumination(y, x);
1346 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
1347 * @return 視覚に収められていないならTRUEを返す
1348 * @details player_can_see_bold()関数の返り値の否定を返している。
1352 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
1357 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
1360 * @return 各種の変更が可能ならTRUEを返す。
1362 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
1364 bool cave_valid_bold(POSITION y, POSITION x)
1366 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1367 OBJECT_IDX this_o_idx, next_o_idx = 0;
1369 /* Forbid perma-grids */
1370 if (cave_perma_grid(g_ptr)) return (FALSE);
1373 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1376 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1377 next_o_idx = o_ptr->next_o_idx;
1379 /* Forbid artifact grids */
1380 if (object_is_artifact(o_ptr)) return (FALSE);
1391 * 一般的にモンスターシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal monster codes
1393 static char image_monster_hack[] = \
1394 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
1397 * 一般的にオブジェクトシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal object codes
1399 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
1402 * @brief モンスターの表示を幻覚状態に差し替える / Mega-Hack -- Hallucinatory monster
1407 static void image_monster(TERM_COLOR *ap, SYMBOL_CODE *cp)
1409 /* Random symbol from set above */
1412 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
1414 *cp = r_ptr->x_char;
1415 *ap = r_ptr->x_attr;
1420 *cp = (one_in_(25) ?
1421 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1422 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1430 * @brief オブジェクトの表示を幻覚状態に差し替える / Hallucinatory object
1435 static void image_object(TERM_COLOR *ap, SYMBOL_CODE *cp)
1439 object_kind *k_ptr = &k_info[randint1(max_k_idx - 1)];
1441 *cp = k_ptr->x_char;
1442 *ap = k_ptr->x_attr;
1446 int n = sizeof(image_object_hack) - 1;
1448 *cp = image_object_hack[randint0(n)];
1457 * @brief オブジェクト&モンスターの表示を幻覚状態に差し替える / Hack -- Random hallucination
1462 static void image_random(TERM_COLOR *ap, SYMBOL_CODE *cp)
1464 /* Normally, assume monsters */
1465 if (randint0(100) < 75)
1467 image_monster(ap, cp);
1470 /* Otherwise, assume objects */
1473 image_object(ap, cp);
1478 * 照明の表現を行うための色合いの関係を{暗闇時, 照明時} で定義する /
1479 * This array lists the effects of "brightness" on various "base" colours.\n
1481 * This is used to do dynamic lighting effects in ascii :-)\n
1482 * At the moment, only the various "floor" tiles are affected.\n
1484 * The layout of the array is [x][0] = light and [x][1] = dark.\n
1486 static TERM_COLOR lighting_colours[16][2] =
1489 {TERM_L_DARK, TERM_DARK},
1492 {TERM_YELLOW, TERM_SLATE},
1495 {TERM_WHITE, TERM_L_DARK},
1498 {TERM_L_UMBER, TERM_UMBER},
1501 {TERM_RED, TERM_RED},
1504 {TERM_L_GREEN, TERM_GREEN},
1507 {TERM_BLUE, TERM_BLUE},
1510 {TERM_L_UMBER, TERM_RED},
1513 {TERM_SLATE, TERM_L_DARK},
1516 {TERM_WHITE, TERM_SLATE},
1519 {TERM_L_RED, TERM_BLUE},
1522 {TERM_YELLOW, TERM_ORANGE},
1525 {TERM_L_RED, TERM_L_RED},
1528 {TERM_L_GREEN, TERM_GREEN},
1531 {TERM_L_BLUE, TERM_L_BLUE},
1534 {TERM_L_UMBER, TERM_UMBER}
1541 void apply_default_feat_lighting(TERM_COLOR f_attr[F_LIT_MAX], SYMBOL_CODE f_char[F_LIT_MAX])
1543 TERM_COLOR s_attr = f_attr[F_LIT_STANDARD];
1544 SYMBOL_CODE s_char = f_char[F_LIT_STANDARD];
1547 if (is_ascii_graphics(s_attr)) /* For ASCII */
1549 f_attr[F_LIT_LITE] = lighting_colours[s_attr & 0x0f][0];
1550 f_attr[F_LIT_DARK] = lighting_colours[s_attr & 0x0f][1];
1551 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_char[i] = s_char;
1553 else /* For tile graphics */
1555 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_attr[i] = s_attr;
1556 f_char[F_LIT_LITE] = s_char + 2;
1557 f_char[F_LIT_DARK] = s_char + 1;
1563 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
1565 #define darkened_grid(C) \
1566 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
1571 * @brief Mコマンドによる縮小マップの表示を行う / Extract the attr/char to display at the given (legal) map location
1573 * Basically, we "paint" the chosen attr/char in several passes, starting\n
1574 * with any known "terrain features" (defaulting to darkness), then adding\n
1575 * any known "objects", and finally, adding any known "monsters". This\n
1576 * is not the fastest method but since most of the calls to this function\n
1577 * are made for grids with no monsters or objects, it is fast enough.\n
1579 * Note that this function, if used on the grid containing the "player",\n
1580 * will return the attr/char of the grid underneath the player, and not\n
1581 * the actual player attr/char itself, allowing a lot of optimization\n
1582 * in various "display" functions.\n
1584 * Note that the "zero" entry in the feature/object/monster arrays are\n
1585 * used to provide "special" attr/char codes, with "monster zero" being\n
1586 * used for the player attr/char, "object zero" being used for the "stack"\n
1587 * attr/char, and "feature zero" being used for the "nothing" attr/char,\n
1588 * though this function makes use of only "feature zero".\n
1590 * Note that monsters can have some "special" flags, including "ATTR_MULTI",\n
1591 * which means their color changes, and "ATTR_CLEAR", which means they take\n
1592 * the color of whatever is under them, and "CHAR_CLEAR", which means that\n
1593 * they take the symbol of whatever is under them. Technically, the flag\n
1594 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when\n
1595 * examined, but this flag is currently ignored.\n
1597 * Currently, we do nothing with multi-hued objects, because there are\n
1598 * not any. If there were, they would have to set "shimmer_objects"\n
1599 * when they were created, and then new "shimmer" code in "dungeon.c"\n
1600 * would have to be created handle the "shimmer" effect, and the code\n
1601 * in "current_floor_ptr->grid_array.c" would have to be updated to create the shimmer effect.\n
1603 * Note the effects of hallucination. Objects always appear as random\n
1604 * "objects", monsters as random "monsters", and normal grids occasionally\n
1605 * appear as random "monsters" or "objects", but note that these random\n
1606 * "monsters" and "objects" are really just "colored ascii symbols".\n
1608 * Note that "floors" and "invisible traps" (and "zero" features) are\n
1609 * drawn as "floors" using a special check for optimization purposes,\n
1610 * and these are the only features which get drawn using the special\n
1611 * lighting effects activated by "view_special_lite".\n
1613 * Note the use of the "mimic" field in the "terrain feature" processing,\n
1614 * which allows any feature to "pretend" to be another feature. This is\n
1615 * used to "hide" secret doors, and to make all "doors" appear the same,\n
1616 * and all "walls" appear the same, and "hidden" treasure stay hidden.\n
1617 * It is possible to use this field to make a feature "look" like a floor,\n
1618 * but the "special lighting effects" for floors will not be used.\n
1620 * Note the use of the new "terrain feature" information. Note that the\n
1621 * assumption that all interesting "objects" and "terrain features" are\n
1622 * memorized allows extremely optimized processing below. Note the use\n
1623 * of separate flags on objects to mark them as memorized allows a grid\n
1624 * to have memorized "terrain" without granting knowledge of any object\n
1625 * which may appear in that grid.\n
1627 * Note the efficient code used to determine if a "floor" grid is\n
1628 * "memorized" or "viewable" by the player, where the test for the\n
1629 * grid being "viewable" is based on the facts that (1) the grid\n
1630 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in\n
1631 * line of sight, and (3) the player must not be blind, and uses the\n
1632 * assumption that all torch-lit grids are in line of sight.\n
1634 * Note that floors (and invisible traps) are the only grids which are\n
1635 * not memorized when seen, so only these grids need to check to see if\n
1636 * the grid is "viewable" to the player (if it is not memorized). Since\n
1637 * most non-memorized grids are in fact walls, this induces *massive*\n
1638 * efficiency, at the cost of *forcing* the memorization of non-floor\n
1639 * grids when they are first seen. Note that "invisible traps" are\n
1640 * always treated exactly like "floors", which prevents "cheating".\n
1642 * Note the "special lighting effects" which can be activated for floor\n
1643 * grids using the "view_special_lite" option (for "white" floor grids),\n
1644 * causing certain grids to be displayed using special colors. If the\n
1645 * player is "blind", we will use "dark gray", else if the grid is lit\n
1646 * by the torch, and the "view_yellow_lite" option is set, we will use\n
1647 * "yellow", else if the grid is "dark", we will use "dark gray", else\n
1648 * if the grid is not "viewable", and the "view_bright_lite" option is\n
1649 * set, and the we will use "slate" (gray). We will use "white" for all\n
1650 * other cases, in particular, for illuminated viewable floor grids.\n
1652 * Note the "special lighting effects" which can be activated for wall\n
1653 * grids using the "view_granite_lite" option (for "white" wall grids),\n
1654 * causing certain grids to be displayed using special colors. If the\n
1655 * player is "blind", we will use "dark gray", else if the grid is lit\n
1656 * by the torch, and the "view_yellow_lite" option is set, we will use\n
1657 * "yellow", else if the "view_bright_lite" option is set, and the grid\n
1658 * is not "viewable", or is "dark", or is glowing, but not when viewed\n
1659 * from the player's current location, we will use "slate" (gray). We\n
1660 * will use "white" for all other cases, in particular, for correctly\n
1661 * illuminated viewable wall grids.\n
1663 * Note that, when "view_granite_lite" is set, we use an inline version\n
1664 * of the "player_can_see_bold()" function to check the "viewability" of\n
1665 * grids when the "view_bright_lite" option is set, and we do NOT use\n
1666 * any special colors for "dark" wall grids, since this would allow the\n
1667 * player to notice the walls of illuminated rooms from a hallway that\n
1668 * happened to run beside the room. The alternative, by the way, would\n
1669 * be to prevent the generation of hallways next to rooms, but this\n
1670 * would still allow problems when digging towards a room.\n
1672 * Note that bizarre things must be done when the "attr" and/or "char"\n
1673 * codes have the "high-bit" set, since these values are used to encode\n
1674 * various "special" pictures in some versions, and certain situations,\n
1675 * such as "multi-hued" or "clear" monsters, cause the attr/char codes\n
1676 * to be "scrambled" in various ways.\n
1678 * Note that eventually we may use the "&" symbol for embedded treasure,\n
1679 * and use the "*" symbol to indicate multiple objects, though this will\n
1680 * have to wait for Angband 2.8.0 or later. Note that currently, this\n
1681 * is not important, since only one object or terrain feature is allowed\n
1682 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.\n
1684 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of\n
1685 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect\n
1686 * then a whole lot of code should be changed... XXX XXX\n
1688 void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp)
1690 /* Get the current_floor_ptr->grid_array */
1691 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1693 OBJECT_IDX this_o_idx, next_o_idx = 0;
1695 /* Feature code (applying "mimic" field) */
1696 FEAT_IDX feat = get_feat_mimic(g_ptr);
1699 feature_type *f_ptr = &f_info[feat];
1704 /* Boring grids (floors, etc) */
1705 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1708 * Handle Memorized or visible floor
1710 * No visual when blinded.
1711 * (to prevent strange effects on darkness breath)
1713 * - Can see grids with CAVE_MARK.
1714 * - Can see grids with CAVE_LITE or CAVE_MNLT.
1715 * (Such grids also have CAVE_VIEW)
1716 * - Can see grids with CAVE_VIEW unless darkened by monsters.
1718 if (!p_ptr->blind &&
1719 ((g_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
1720 ((g_ptr->info & CAVE_VIEW) && (((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
1722 /* Normal attr/char */
1723 a = f_ptr->x_attr[F_LIT_STANDARD];
1724 c = f_ptr->x_char[F_LIT_STANDARD];
1726 if (p_ptr->wild_mode)
1728 /* Special lighting effects */
1729 /* Handle "night" */
1730 if (view_special_lite && !is_daytime())
1732 /* Use a darkened colour/tile */
1733 a = f_ptr->x_attr[F_LIT_DARK];
1734 c = f_ptr->x_char[F_LIT_DARK];
1738 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1739 else if (darkened_grid(g_ptr))
1741 /* Unsafe grid -- idea borrowed from Unangband */
1742 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1744 /* Access darkness */
1745 f_ptr = &f_info[feat];
1747 /* Char and attr of darkness */
1748 a = f_ptr->x_attr[F_LIT_STANDARD];
1749 c = f_ptr->x_char[F_LIT_STANDARD];
1752 /* Special lighting effects */
1753 else if (view_special_lite)
1755 /* Handle "torch-lit" grids */
1756 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1759 if (view_yellow_lite)
1761 /* Use a brightly lit colour/tile */
1762 a = f_ptr->x_attr[F_LIT_LITE];
1763 c = f_ptr->x_char[F_LIT_LITE];
1767 /* Handle "dark" grids */
1768 else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1770 /* Use a darkened colour/tile */
1771 a = f_ptr->x_attr[F_LIT_DARK];
1772 c = f_ptr->x_char[F_LIT_DARK];
1775 /* Handle "out-of-sight" grids */
1776 else if (!(g_ptr->info & CAVE_VIEW))
1779 if (view_bright_lite)
1781 /* Use a darkened colour/tile */
1782 a = f_ptr->x_attr[F_LIT_DARK];
1783 c = f_ptr->x_char[F_LIT_DARK];
1792 /* Unsafe grid -- idea borrowed from Unangband */
1793 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1795 /* Access darkness */
1796 f_ptr = &f_info[feat];
1798 /* Normal attr/char */
1799 a = f_ptr->x_attr[F_LIT_STANDARD];
1800 c = f_ptr->x_char[F_LIT_STANDARD];
1804 /* Interesting grids (non-floors) */
1807 /* Memorized grids */
1808 if (g_ptr->info & CAVE_MARK)
1810 /* Normal attr/char */
1811 a = f_ptr->x_attr[F_LIT_STANDARD];
1812 c = f_ptr->x_char[F_LIT_STANDARD];
1814 if (p_ptr->wild_mode)
1816 /* Special lighting effects */
1817 /* Handle "blind" or "night" */
1818 if (view_granite_lite && (p_ptr->blind || !is_daytime()))
1820 /* Use a darkened colour/tile */
1821 a = f_ptr->x_attr[F_LIT_DARK];
1822 c = f_ptr->x_char[F_LIT_DARK];
1826 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1827 else if (darkened_grid(g_ptr) && !p_ptr->blind)
1829 if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
1831 /* Unsafe grid -- idea borrowed from Unangband */
1832 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1834 /* Access darkness */
1835 f_ptr = &f_info[feat];
1837 /* Char and attr of darkness */
1838 a = f_ptr->x_attr[F_LIT_STANDARD];
1839 c = f_ptr->x_char[F_LIT_STANDARD];
1841 else if (view_granite_lite && view_bright_lite)
1843 /* Use a darkened colour/tile */
1844 a = f_ptr->x_attr[F_LIT_DARK];
1845 c = f_ptr->x_char[F_LIT_DARK];
1849 /* Special lighting effects */
1850 else if (view_granite_lite)
1852 /* Handle "blind" */
1855 /* Use a darkened colour/tile */
1856 a = f_ptr->x_attr[F_LIT_DARK];
1857 c = f_ptr->x_char[F_LIT_DARK];
1860 /* Handle "torch-lit" grids */
1861 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1864 if (view_yellow_lite)
1866 /* Use a brightly lit colour/tile */
1867 a = f_ptr->x_attr[F_LIT_LITE];
1868 c = f_ptr->x_char[F_LIT_LITE];
1872 /* Handle "view_bright_lite" */
1873 else if (view_bright_lite)
1876 if (!(g_ptr->info & CAVE_VIEW))
1878 /* Use a darkened colour/tile */
1879 a = f_ptr->x_attr[F_LIT_DARK];
1880 c = f_ptr->x_char[F_LIT_DARK];
1884 else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1886 /* Use a darkened colour/tile */
1887 a = f_ptr->x_attr[F_LIT_DARK];
1888 c = f_ptr->x_char[F_LIT_DARK];
1891 /* Not glowing correctly */
1892 else if (!have_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(y, x))
1894 /* Use a darkened colour/tile */
1895 a = f_ptr->x_attr[F_LIT_DARK];
1896 c = f_ptr->x_char[F_LIT_DARK];
1905 /* Unsafe grid -- idea borrowed from Unangband */
1906 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1908 /* Access feature */
1909 f_ptr = &f_info[feat];
1911 /* Normal attr/char */
1912 a = f_ptr->x_attr[F_LIT_STANDARD];
1913 c = f_ptr->x_char[F_LIT_STANDARD];
1917 if (feat_priority == -1) feat_priority = f_ptr->priority;
1919 /* Save the terrain info for the transparency effects */
1927 /* Hack -- rare random hallucination, except on outer dungeon walls */
1932 image_random(ap, cp);
1937 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1940 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1941 next_o_idx = o_ptr->next_o_idx;
1943 /* Memorized objects */
1944 if (o_ptr->marked & OM_FOUND)
1946 if (display_autopick)
1950 match_autopick = is_autopick(o_ptr);
1951 if (match_autopick == -1)
1954 act = autopick_list[match_autopick].action;
1956 if ((act & DO_DISPLAY) && (act & display_autopick))
1958 autopick_obj = o_ptr;
1962 match_autopick = -1;
1967 (*cp) = object_char(o_ptr);
1970 (*ap) = object_attr(o_ptr);
1974 /* Hack -- hallucination */
1975 if (p_ptr->image) image_object(ap, cp);
1982 /* Handle monsters */
1983 if (g_ptr->m_idx && display_autopick == 0)
1985 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
1987 /* Visible monster */
1990 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1998 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
1999 * flags are always unseen.
2001 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
2007 image_monster(ap, cp);
2012 /* Monster attr/char */
2016 /* Normal monsters */
2017 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
2018 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
2020 /* Desired monster attr/char */
2026 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
2027 * flags are always unseen.
2029 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
2036 /*** Monster's attr ***/
2037 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
2042 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
2044 /* Multi-hued attr */
2045 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
2046 else switch (randint1(7))
2048 case 1: *ap = TERM_RED; break;
2049 case 2: *ap = TERM_L_RED; break;
2050 case 3: *ap = TERM_WHITE; break;
2051 case 4: *ap = TERM_L_GREEN; break;
2052 case 5: *ap = TERM_BLUE; break;
2053 case 6: *ap = TERM_L_DARK; break;
2054 case 7: *ap = TERM_GREEN; break;
2057 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
2059 /* Use semi-random attr (usually mimics' colors vary) */
2060 *ap = g_ptr->m_idx % 15 + 1;
2068 /*** Monster's char ***/
2069 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
2074 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
2078 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
2079 *cp = tmp_r_ptr->x_char;
2080 *ap = tmp_r_ptr->x_attr;
2084 *cp = (one_in_(25) ?
2085 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
2086 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
2099 /* Handle "player" */
2100 if (player_bold(y, x))
2102 monster_race *r_ptr = &r_info[0];
2103 *ap = r_ptr->x_attr;
2104 *cp = r_ptr->x_char;
2111 * Calculate panel colum of a location in the map
2113 static int panel_col_of(int col)
2115 col -= panel_col_min;
2116 if (use_bigtile) col *= 2;
2122 * Moves the cursor to a given MAP (y,x) location
2124 void move_cursor_relative(int row, int col)
2126 /* Real co-ords convert to screen positions */
2127 row -= panel_row_prt;
2130 Term_gotoxy(panel_col_of(col), row);
2136 * Place an attr/char pair at the given map coordinate, if legal.
2138 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
2140 /* Only do "legal" locations */
2141 if (panel_contains(y, x))
2143 /* Hack -- fake monochrome */
2146 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2147 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2148 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2151 /* Draw the char using the attr */
2152 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
2161 * Memorize interesting viewable object/features in the given grid
2163 * This function should only be called on "legal" grids.
2165 * This function will memorize the object and/or feature in the given
2166 * grid, if they are (1) viewable and (2) interesting. Note that all
2167 * objects are interesting, all terrain features except floors (and
2168 * invisible traps) are interesting, and floors (and invisible traps)
2169 * are interesting sometimes (depending on various options involving
2170 * the illumination of floor grids).
2172 * The automatic memorization of all objects and non-floor terrain
2173 * features as soon as they are displayed allows incredible amounts
2174 * of optimization in various places, especially "map_info()".
2176 * Note that the memorization of objects is completely separate from
2177 * the memorization of terrain features, preventing annoying floor
2178 * memorization when a detected object is picked up from a dark floor,
2179 * and object memorization when an object is dropped into a floor grid
2180 * which is memorized but out-of-sight.
2182 * This function should be called every time the "memorization" of
2183 * a grid (or the object in a grid) is called into question, such
2184 * as when an object is created in a grid, when a terrain feature
2185 * "changes" from "floor" to "non-floor", when any grid becomes
2186 * "illuminated" or "viewable", and when a "floor" grid becomes
2189 * Note the relatively efficient use of this function by the various
2190 * "update_view()" and "update_lite()" calls, to allow objects and
2191 * terrain features to be memorized (and drawn) whenever they become
2192 * viewable or illuminated in any way, but not when they "maintain"
2193 * or "lose" their previous viewability or illumination.
2195 * Note the butchered "internal" version of "player_can_see_bold()",
2196 * optimized primarily for the most common cases, that is, for the
2197 * non-marked floor grids.
2199 void note_spot(POSITION y, POSITION x)
2201 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2202 OBJECT_IDX this_o_idx, next_o_idx = 0;
2204 /* Blind players see nothing */
2205 if (p_ptr->blind) return;
2207 /* Analyze non-torch-lit grids */
2208 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
2210 /* Require line of sight to the grid */
2211 if (!(g_ptr->info & (CAVE_VIEW))) return;
2213 /* Require "perma-lite" of the grid */
2214 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
2217 if (!p_ptr->see_nocto) return;
2222 /* Hack -- memorize objects */
2223 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2225 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
2226 next_o_idx = o_ptr->next_o_idx;
2228 /* Memorize objects */
2229 o_ptr->marked |= OM_FOUND;
2233 /* Hack -- memorize grids */
2234 if (!(g_ptr->info & (CAVE_MARK)))
2236 /* Feature code (applying "mimic" field) */
2237 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
2239 /* Memorize some "boring" grids */
2240 if (!have_flag(f_ptr->flags, FF_REMEMBER))
2242 /* Option -- memorize all torch-lit floors */
2243 if (view_torch_grids &&
2244 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
2246 g_ptr->info |= (CAVE_MARK);
2249 /* Option -- memorize all perma-lit floors */
2250 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
2252 g_ptr->info |= (CAVE_MARK);
2256 /* Memorize normal grids */
2257 else if (have_flag(f_ptr->flags, FF_LOS))
2259 g_ptr->info |= (CAVE_MARK);
2262 /* Memorize torch-lit walls */
2263 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
2265 g_ptr->info |= (CAVE_MARK);
2268 /* Memorize walls seen by noctovision of Ninja */
2269 else if (p_ptr->see_nocto)
2271 g_ptr->info |= (CAVE_MARK);
2274 /* Memorize certain non-torch-lit wall grids */
2275 else if (check_local_illumination(y, x))
2277 g_ptr->info |= (CAVE_MARK);
2281 /* Memorize terrain of the grid */
2282 g_ptr->info |= (CAVE_KNOWN);
2286 void display_dungeon(void)
2293 SYMBOL_CODE tc = '\0';
2295 for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
2297 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
2299 if (in_bounds2(y, x))
2301 map_info(y, x, &a, &c, &ta, &tc);
2303 /* Hack -- fake monochrome */
2306 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2307 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2308 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2311 /* Hack -- Queue it */
2312 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
2316 /* Clear out-of-bound tiles */
2318 /* Access darkness */
2319 feature_type *f_ptr = &f_info[feat_none];
2322 a = f_ptr->x_attr[F_LIT_STANDARD];
2325 c = f_ptr->x_char[F_LIT_STANDARD];
2327 /* Hack -- Queue it */
2328 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
2336 * Redraw (on the screen) a given MAP location
2338 * This function should only be called on "legal" grids
2340 void lite_spot(POSITION y, POSITION x)
2342 /* Redraw if on screen */
2343 if (panel_contains(y, x) && in_bounds2(y, x))
2350 map_info(y, x, &a, &c, &ta, &tc);
2352 /* Hack -- fake monochrome */
2355 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2356 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2357 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2360 /* Hack -- Queue it */
2361 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
2363 /* Update sub-windows */
2364 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2370 * Prints the map of the dungeon
2372 * Note that, for efficiency, we contain an "optimized" version
2373 * of both "lite_spot()" and "print_rel()", and that we use the
2374 * "lite_spot()" function to display the player grid, if needed.
2382 POSITION xmin, xmax, ymin, ymax;
2386 Term_get_size(&wid, &hgt);
2388 /* Remove map offset */
2392 /* Access the cursor state */
2393 (void)Term_get_cursor(&v);
2395 /* Hide the cursor */
2396 (void)Term_set_cursor(0);
2399 xmin = (0 < panel_col_min) ? panel_col_min : 0;
2400 xmax = (current_floor_ptr->width - 1 > panel_col_max) ? panel_col_max : current_floor_ptr->width - 1;
2401 ymin = (0 < panel_row_min) ? panel_row_min : 0;
2402 ymax = (current_floor_ptr->height - 1 > panel_row_max) ? panel_row_max : current_floor_ptr->height - 1;
2404 /* Bottom section of screen */
2405 for (y = 1; y <= ymin - panel_row_prt; y++)
2407 /* Erase the section */
2408 Term_erase(COL_MAP, y, wid);
2411 /* Top section of screen */
2412 for (y = ymax - panel_row_prt; y <= hgt; y++)
2414 /* Erase the section */
2415 Term_erase(COL_MAP, y, wid);
2419 for (y = ymin; y <= ymax; y++)
2421 /* Scan the columns of row "y" */
2422 for (x = xmin; x <= xmax; x++)
2430 /* Determine what is there */
2431 map_info(y, x, &a, &c, &ta, &tc);
2433 /* Hack -- fake monochrome */
2436 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2437 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2438 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2441 /* Efficiency -- Redraw that grid of the map */
2442 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
2446 /* Display player */
2447 lite_spot(p_ptr->y, p_ptr->x);
2449 /* Restore the cursor */
2450 (void)Term_set_cursor(v);
2456 * print project path
2458 void prt_path(POSITION y, POSITION x)
2463 byte_hack default_color = TERM_SLATE;
2465 if (!display_path) return;
2466 if (-1 == project_length)
2469 /* Get projection path */
2470 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
2472 p_ptr->redraw |= (PR_MAP);
2476 for (i = 0; i < path_n; i++)
2478 POSITION ny = GRID_Y(path_g[i]);
2479 POSITION nx = GRID_X(path_g[i]);
2480 grid_type *g_ptr = ¤t_floor_ptr->grid_array[ny][nx];
2482 if (panel_contains(ny, nx))
2484 TERM_COLOR a = default_color;
2487 TERM_COLOR ta = default_color;
2490 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
2492 /* Determine what is there */
2493 map_info(ny, nx, &a, &c, &ta, &tc);
2495 if (!is_ascii_graphics(a))
2497 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2499 else if (a == default_color)
2505 if (current_world_ptr->timewalk_m_idx) a = TERM_DARK;
2506 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2507 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2512 /* Hack -- Queue it */
2513 Term_queue_bigchar(panel_col_of(nx), ny - panel_row_prt, a, c, ta, tc);
2517 if ((g_ptr->info & CAVE_MARK) && !cave_have_flag_grid(g_ptr, FF_PROJECT)) break;
2520 if (nx == x && ny == y) default_color = TERM_L_DARK;
2525 static concptr simplify_list[][2] =
2532 {"^Amulet of ", "\""},
2533 {"^Scroll of ", "?"},
2534 {"^Scroll titled ", "?"},
2535 {"^Wand of " , "-"},
2537 {"^Staff of " , "_"},
2538 {"^Potion of ", "!"},
2550 static void display_shortened_item_name(object_type *o_ptr, int y)
2557 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
2558 attr = tval_to_attr[o_ptr->tval % 128];
2563 strcpy(buf, _("何か奇妙な物", "something strange"));
2566 for (c = buf; *c; c++)
2569 for (i = 0; simplify_list[i][1]; i++)
2571 concptr org_w = simplify_list[i][0];
2581 if (!strncmp(c, org_w, strlen(org_w)))
2584 concptr tmp = simplify_list[i][1];
2587 tmp = c + strlen(org_w);
2603 if (len + 2 > 12) break;
2610 if (len + 1 > 12) break;
2616 Term_putstr(0, y, 12, attr, buf);
2620 * Display a "small-scale" map of the dungeon in the active Term
2622 void display_map(int *cy, int *cx)
2632 SYMBOL_CODE **bigmc;
2639 /* Save lighting effects */
2640 bool old_view_special_lite = view_special_lite;
2641 bool old_view_granite_lite = view_granite_lite;
2643 TERM_LEN hgt, wid, yrat, xrat;
2645 int **match_autopick_yx;
2646 object_type ***object_autopick_yx;
2648 Term_get_size(&wid, &hgt);
2651 if (use_bigtile) wid /= 2;
2653 yrat = (current_floor_ptr->height + hgt - 1) / hgt;
2654 xrat = (current_floor_ptr->width + wid - 1) / wid;
2656 /* Disable lighting effects */
2657 view_special_lite = FALSE;
2658 view_granite_lite = FALSE;
2660 /* Allocate the maps */
2661 C_MAKE(ma, (hgt + 2), TERM_COLOR *);
2662 C_MAKE(mc, (hgt + 2), char_ptr);
2663 C_MAKE(mp, (hgt + 2), byte_ptr);
2664 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2665 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2667 /* Allocate and wipe each line map */
2668 for (y = 0; y < (hgt + 2); y++)
2670 /* Allocate one row each array */
2671 C_MAKE(ma[y], (wid + 2), TERM_COLOR);
2672 C_MAKE(mc[y], (wid + 2), char);
2673 C_MAKE(mp[y], (wid + 2), byte);
2674 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2675 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2677 for (x = 0; x < wid + 2; ++x)
2679 match_autopick_yx[y][x] = -1;
2680 object_autopick_yx[y][x] = NULL;
2683 ma[y][x] = TERM_WHITE;
2691 /* Allocate the maps */
2692 C_MAKE(bigma, (current_floor_ptr->height + 2), TERM_COLOR *);
2693 C_MAKE(bigmc, (current_floor_ptr->height + 2), char_ptr);
2694 C_MAKE(bigmp, (current_floor_ptr->height + 2), byte_ptr);
2696 /* Allocate and wipe each line map */
2697 for (y = 0; y < (current_floor_ptr->height + 2); y++)
2699 /* Allocate one row each array */
2700 C_MAKE(bigma[y], (current_floor_ptr->width + 2), TERM_COLOR);
2701 C_MAKE(bigmc[y], (current_floor_ptr->width + 2), char);
2702 C_MAKE(bigmp[y], (current_floor_ptr->width + 2), byte);
2704 for (x = 0; x < current_floor_ptr->width + 2; ++x)
2707 bigma[y][x] = TERM_WHITE;
2715 /* Fill in the map */
2716 for (i = 0; i < current_floor_ptr->width; ++i)
2718 for (j = 0; j < current_floor_ptr->height; ++j)
2723 match_autopick = -1;
2724 autopick_obj = NULL;
2727 /* Extract the current attr/char at that map location */
2728 map_info(j, i, &ta, &tc, &ta, &tc);
2730 /* Extract the priority */
2731 tp = (byte_hack)feat_priority;
2733 if (match_autopick != -1
2734 && (match_autopick_yx[y][x] == -1
2735 || match_autopick_yx[y][x] > match_autopick))
2737 match_autopick_yx[y][x] = match_autopick;
2738 object_autopick_yx[y][x] = autopick_obj;
2742 /* Save the char, attr and priority */
2743 bigmc[j + 1][i + 1] = tc;
2744 bigma[j + 1][i + 1] = ta;
2745 bigmp[j + 1][i + 1] = tp;
2749 for (j = 0; j < current_floor_ptr->height; ++j)
2751 for (i = 0; i < current_floor_ptr->width; ++i)
2756 tc = bigmc[j + 1][i + 1];
2757 ta = bigma[j + 1][i + 1];
2758 tp = bigmp[j + 1][i + 1];
2760 /* rare feature has more priority */
2766 for (t = 0; t < 8; t++)
2768 if (tc == bigmc[j + 1 + ddy_cdd[t]][i + 1 + ddx_cdd[t]] &&
2769 ta == bigma[j + 1 + ddy_cdd[t]][i + 1 + ddx_cdd[t]])
2779 /* Save the char, attr and priority */
2792 /* Draw the corners */
2793 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2795 /* Draw the horizontal edges */
2796 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2798 /* Draw the vertical edges */
2799 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2802 /* Display each map line in order */
2803 for (y = 0; y < hgt + 2; ++y)
2805 /* Start a new line */
2806 Term_gotoxy(COL_MAP, y);
2808 /* Display the line */
2809 for (x = 0; x < wid + 2; ++x)
2814 /* Hack -- fake monochrome */
2817 if (current_world_ptr->timewalk_m_idx) ta = TERM_DARK;
2818 else if (IS_INVULN() || p_ptr->timewalk) ta = TERM_WHITE;
2819 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2822 /* Add the character */
2823 Term_add_bigch(ta, tc);
2828 for (y = 1; y < hgt + 1; ++y)
2830 match_autopick = -1;
2831 for (x = 1; x <= wid; x++) {
2832 if (match_autopick_yx[y][x] != -1 &&
2833 (match_autopick > match_autopick_yx[y][x] ||
2834 match_autopick == -1)) {
2835 match_autopick = match_autopick_yx[y][x];
2836 autopick_obj = object_autopick_yx[y][x];
2840 /* Clear old display */
2841 Term_putstr(0, y, 12, 0, " ");
2843 if (match_autopick != -1)
2845 display_shortened_item_name(autopick_obj, y);
2848 char buf[13] = "\0";
2849 strncpy(buf, autopick_list[match_autopick].name, 12);
2857 /* Player location */
2858 (*cy) = p_ptr->y / yrat + 1 + ROW_MAP;
2860 (*cx) = p_ptr->x / xrat + 1 + COL_MAP;
2862 (*cx) = (p_ptr->x / xrat + 1) * 2 + COL_MAP;
2864 /* Restore lighting effects */
2865 view_special_lite = old_view_special_lite;
2866 view_granite_lite = old_view_granite_lite;
2868 /* Free each line map */
2869 for (y = 0; y < (hgt + 2); y++)
2871 /* Free one row each array */
2872 C_KILL(ma[y], (wid + 2), TERM_COLOR);
2873 C_KILL(mc[y], (wid + 2), SYMBOL_CODE);
2874 C_KILL(mp[y], (wid + 2), byte);
2875 C_KILL(match_autopick_yx[y], (wid + 2), int);
2876 C_KILL(object_autopick_yx[y], (wid + 2), object_type *);
2879 /* Free each line map */
2880 C_KILL(ma, (hgt + 2), TERM_COLOR *);
2881 C_KILL(mc, (hgt + 2), char_ptr);
2882 C_KILL(mp, (hgt + 2), byte_ptr);
2883 C_KILL(match_autopick_yx, (hgt + 2), sint_ptr);
2884 C_KILL(object_autopick_yx, (hgt + 2), object_type **);
2886 /* Free each line map */
2887 for (y = 0; y < (current_floor_ptr->height + 2); y++)
2889 /* Free one row each array */
2890 C_KILL(bigma[y], (current_floor_ptr->width + 2), TERM_COLOR);
2891 C_KILL(bigmc[y], (current_floor_ptr->width + 2), SYMBOL_CODE);
2892 C_KILL(bigmp[y], (current_floor_ptr->width + 2), byte);
2895 /* Free each line map */
2896 C_KILL(bigma, (current_floor_ptr->height + 2), TERM_COLOR *);
2897 C_KILL(bigmc, (current_floor_ptr->height + 2), char_ptr);
2898 C_KILL(bigmp, (current_floor_ptr->height + 2), byte_ptr);
2903 * Display a "small-scale" map of the dungeon for the player
2905 * Currently, the "player" is displayed on the map.
2907 void do_cmd_view_map(void)
2913 prt(_("お待ち下さい...", "Please wait..."), 0, 0);
2918 display_autopick = 0;
2920 /* Display the map */
2921 display_map(&cy, &cx);
2924 if (max_autopick && !p_ptr->wild_mode)
2926 display_autopick = ITEM_DISPLAY;
2933 int wid, hgt, row_message;
2935 Term_get_size(&wid, &hgt);
2936 row_message = hgt - 1;
2938 put_str(_("何かキーを押してください('M':拾う 'N':放置 'D':M+N 'K':壊すアイテムを表示)",
2939 " Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items."), row_message, 1);
2941 /* Hilite the player */
2942 move_cursor(cy, cx);
2947 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2949 flag = DONT_AUTOPICK;
2951 flag = DO_AUTODESTROY;
2953 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2959 if (~display_autopick & flag)
2960 display_autopick |= flag;
2962 display_autopick &= ~flag;
2963 /* Display the map */
2964 display_map(&cy, &cx);
2967 display_autopick = 0;
2972 put_str(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"), 23, 30);
2973 /* Hilite the player */
2974 move_cursor(cy, cx);
2986 * Some comments on the grid flags. -BEN-
2989 * One of the major bottlenecks in previous versions of Angband was in
2990 * the calculation of "line of sight" from the player to various grids,
2991 * such as monsters. This was such a nasty bottleneck that a lot of
2992 * silly things were done to reduce the dependancy on "line of sight",
2993 * for example, you could not "see" any grids in a lit room until you
2994 * actually entered the room, and there were all kinds of bizarre grid
2995 * flags to enable this behavior. This is also why the "call light"
2996 * spells always lit an entire room.
2998 * The code below provides functions to calculate the "field of view"
2999 * for the player, which, once calculated, provides extremely fast
3000 * calculation of "line of sight from the player", and to calculate
3001 * the "field of torch lite", which, again, once calculated, provides
3002 * extremely fast calculation of "which grids are lit by the player's
3003 * lite source". In addition to marking grids as "GRID_VIEW" and/or
3004 * "GRID_LITE", as appropriate, these functions maintain an array for
3005 * each of these two flags, each array containing the locations of all
3006 * of the grids marked with the appropriate flag, which can be used to
3007 * very quickly scan through all of the grids in a given set.
3009 * To allow more "semantically valid" field of view semantics, whenever
3010 * the field of view (or the set of torch lit grids) changes, all of the
3011 * grids in the field of view (or the set of torch lit grids) are "drawn"
3012 * so that changes in the world will become apparent as soon as possible.
3013 * This has been optimized so that only grids which actually "change" are
3014 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
3015 * of the grids which are entering or leaving the relevent set of grids.
3017 * These new methods are so efficient that the old nasty code was removed.
3019 * Note that there is no reason to "update" the "viewable space" unless
3020 * the player "moves", or walls/doors are created/destroyed, and there
3021 * is no reason to "update" the "torch lit grids" unless the field of
3022 * view changes, or the "light radius" changes. This means that when
3023 * the player is resting, or digging, or doing anything that does not
3024 * involve movement or changing the state of the dungeon, there is no
3025 * need to update the "view" or the "lite" regions, which is nice.
3027 * Note that the calls to the nasty "los()" function have been reduced
3028 * to a bare minimum by the use of the new "field of view" calculations.
3030 * I wouldn't be surprised if slight modifications to the "update_view()"
3031 * function would allow us to determine "reverse line-of-sight" as well
3032 * as "normal line-of-sight", which would allow monsters to use a more
3033 * "correct" calculation to determine if they can "see" the player. For
3034 * now, monsters simply "cheat" somewhat and assume that if the player
3035 * has "line of sight" to the monster, then the monster can "pretend"
3036 * that it has "line of sight" to the player.
3039 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
3040 * grid and maintains an array of all "CAVE_LITE" grids.
3042 * This set of grids is the complete set of all grids which are lit by
3043 * the players light source, which allows the "player_can_see_bold()"
3044 * function to work very quickly.
3046 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
3047 * fact, the player (unless blind) can always "see" all grids which are
3048 * marked as "CAVE_LITE", unless they are "off screen".
3051 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
3052 * grid and maintains an array of all "CAVE_VIEW" grids.
3054 * This set of grids is the complete set of all grids within line of sight
3055 * of the player, allowing the "player_has_los_bold()" macro to work very
3059 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
3060 * temporary internal flag to mark those grids which are not only in view,
3061 * but which are also "easily" in line of sight of the player. This flag
3062 * is always cleared when we are done.
3065 * The current "update_lite()" and "update_view()" algorithms use the
3066 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
3067 * to keep track of which grids were previously marked as "CAVE_LITE" or
3068 * "CAVE_VIEW", which allows us to optimize the "screen updates".
3070 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
3071 * for various other purposes, such as spreading lite or darkness during
3072 * "lite_room()" / "unlite_room()", and for calculating monster flow.
3075 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
3076 * in some way permanently lit. However, for the player to "see" anything
3077 * in the grid, as determined by "player_can_see()", the player must not be
3078 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
3079 * grids, even if marked as "perma lit", are only illuminated if they touch
3080 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
3083 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
3084 * that even if the player cannot "see" the grid, he "knows" the terrain in
3085 * that grid. This is used to "remember" walls/doors/stairs/floors when they
3086 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
3087 * or when one of the "memorize floor grids" options induces memorization.
3089 * Objects are "memorized" in a different way, using a special "marked" flag
3090 * on the object itself, which is set when an object is observed or detected.
3093 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
3094 * and should be illuminated by "lite room" and "darkness" spells.
3097 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
3098 * and should be unavailable for "teleportation" destinations.
3101 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
3102 * which is observed, and the "view_torch_grids" allows the player to memorize
3103 * every torch-lit grid. The player will always memorize important walls,
3104 * doors, stairs, and other terrain features, as well as any "detected" grids.
3106 * Note that the new "update_view()" method allows, among other things, a room
3107 * to be "partially" seen as the player approaches it, with a growing cone of
3108 * floor appearing as the player gets closer to the door. Also, by not turning
3109 * on the "memorize perma-lit grids" option, the player will only "see" those
3110 * floor grids which are actually in line of sight.
3112 * And my favorite "plus" is that you can now use a special option to draw the
3113 * "floors" in the "viewable region" brightly (actually, to draw the *other*
3114 * grids dimly), providing a "pretty" effect as the player runs around, and
3115 * to efficiently display the "torch lite" in a special color.
3118 * Some comments on the "update_view()" algorithm...
3120 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
3121 * and only has to call "los()" on the borderline cases. The major axes/diags
3122 * even terminate early when they hit walls. I need to find a quick way
3123 * to "terminate" the other scans.
3125 * Note that in the worst case (a big empty area with say 5% scattered walls),
3126 * each of the 1500 or so nearby grids is checked once, most of them getting
3127 * an "instant" rating, and only a small portion requiring a call to "los()".
3129 * The only time that the algorithm appears to be "noticeably" too slow is
3130 * when running, and this is usually only important in town, since the town
3131 * provides about the worst scenario possible, with large open regions and
3132 * a few scattered obstructions. There is a special "efficiency" option to
3133 * allow the player to reduce his field of view in town, if needed.
3135 * In the "best" case (say, a normal stretch of corridor), the algorithm
3136 * makes one check for each viewable grid, and makes no calls to "los()".
3137 * So running in corridors is very fast, and if a lot of monsters are
3138 * nearby, it is much faster than the old methods.
3140 * Note that resting, most normal commands, and several forms of running,
3141 * plus all commands executed near large groups of monsters, are strictly
3142 * more efficient with "update_view()" that with the old "compute los() on
3143 * demand" method, primarily because once the "field of view" has been
3144 * calculated, it does not have to be recalculated until the player moves
3145 * (or a wall or door is created or destroyed).
3147 * Note that we no longer have to do as many "los()" checks, since once the
3148 * "view" region has been built, very few things cause it to be "changed"
3149 * (player movement, and the opening/closing of doors, changes in wall status).
3150 * Note that door/wall changes are only relevant when the door/wall itself is
3151 * in the "view" region.
3153 * The algorithm seems to only call "los()" from zero to ten times, usually
3154 * only when coming down a corridor into a room, or standing in a room, just
3155 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
3156 * we will be reducing the calls to "los()".
3158 * I am thinking in terms of an algorithm that "walks" from the central point
3159 * out to the maximal "distance", at each point, determining the "view" code
3160 * (above). For each grid not on a major axis or diagonal, the "view" code
3161 * depends on the "cave_los_bold()" and "view" of exactly two other grids
3162 * (the one along the nearest diagonal, and the one next to that one, see
3163 * "update_view_aux()"...).
3165 * We "memorize" the viewable space array, so that at the cost of under 3000
3166 * bytes, we reduce the time taken by "forget_view()" to one assignment for
3167 * each grid actually in the "viewable space". And for another 3000 bytes,
3168 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
3169 * are also used by other routines, thus reducing the cost to almost nothing.
3171 * A similar thing is done for "forget_lite()" in which case the savings are
3172 * much less, but save us from doing bizarre maintenance checking.
3174 * In the worst "normal" case (in the middle of the town), the reachable space
3175 * actually reaches to more than half of the largest possible "circle" of view,
3176 * or about 800 grids, and in the worse case (in the middle of a dungeon level
3177 * where all the walls have been removed), the reachable space actually reaches
3178 * the theoretical maximum size of just under 1500 grids.
3180 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
3181 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
3182 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
3183 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
3184 * entire possible space (including initialization) in one step per grid. If
3185 * we do the "clearing" as a separate step (and use an array of "view" grids),
3186 * then the clearing will take as many steps as grids that were viewed, and the
3187 * algorithm will be able to "stop" scanning at various points.
3188 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
3199 * Actually erase the entire "lite" array, redrawing every grid
3201 void forget_lite(void)
3206 /* None to forget */
3207 if (!current_floor_ptr->lite_n) return;
3209 /* Clear them all */
3210 for (i = 0; i < current_floor_ptr->lite_n; i++)
3212 y = current_floor_ptr->lite_y[i];
3213 x = current_floor_ptr->lite_x[i];
3215 /* Forget "LITE" flag */
3216 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
3218 /* lite_spot(y, x); Perhaps don't need? */
3222 current_floor_ptr->lite_n = 0;
3227 * For delayed visual update
3229 #define cave_note_and_redraw_later(C,Y,X) \
3231 (C)->info |= CAVE_NOTE; \
3232 cave_redraw_later((C), (Y), (X)); \
3237 * For delayed visual update
3239 #define cave_redraw_later(C,Y,X) \
3241 if (!((C)->info & CAVE_REDRAW)) \
3243 (C)->info |= CAVE_REDRAW; \
3244 current_floor_ptr->redraw_y[current_floor_ptr->redraw_n] = (Y); \
3245 current_floor_ptr->redraw_x[current_floor_ptr->redraw_n++] = (X); \
3251 * This macro allows us to efficiently add a grid to the "lite" array,
3252 * note that we are never called for illegal grids, or for grids which
3253 * have already been placed into the "lite" array, and we are never
3254 * called when the "lite" array is full.
3256 #define cave_lite_hack(Y,X) \
3258 if (!(current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
3260 current_floor_ptr->grid_array[Y][X].info |= (CAVE_LITE); \
3261 current_floor_ptr->lite_y[current_floor_ptr->lite_n] = (Y); \
3262 current_floor_ptr->lite_x[current_floor_ptr->lite_n++] = (X); \
3268 * Update the set of grids "illuminated" by the player's lite.
3270 * This routine needs to use the results of "update_view()"
3272 * Note that "blindness" does NOT affect "torch lite". Be careful!
3274 * We optimize most lites (all non-artifact lites) by using "obvious"
3275 * facts about the results of "small" lite radius, and we attempt to
3276 * list the "nearby" grids before the more "distant" ones in the
3277 * array of torch-lit grids.
3279 * We assume that "radius zero" lite is in fact no lite at all.
3281 * Torch Lantern Artifacts
3291 void update_lite(void)
3294 POSITION x, y, min_x, max_x, min_y, max_y;
3295 POSITION p = p_ptr->cur_lite;
3298 /*** Special case ***/
3301 /* Hack -- Player has no lite */
3304 /* Forget the old lite */
3305 /* forget_lite(); Perhaps don't need? */
3307 /* Add it to later visual update */
3308 cave_redraw_later(¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
3312 /*** Save the old "lite" grids for later ***/
3314 /* Clear them all */
3315 for (i = 0; i < current_floor_ptr->lite_n; i++)
3317 y = current_floor_ptr->lite_y[i];
3318 x = current_floor_ptr->lite_x[i];
3320 /* Mark the grid as not "lite" */
3321 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
3323 /* Mark the grid as "seen" */
3324 current_floor_ptr->grid_array[y][x].info |= (CAVE_TEMP);
3326 /* Add it to the "seen" set */
3327 tmp_pos.y[tmp_pos.n] = y;
3328 tmp_pos.x[tmp_pos.n] = x;
3333 current_floor_ptr->lite_n = 0;
3336 /*** Collect the new "lite" grids ***/
3338 /* Radius 1 -- torch radius */
3342 cave_lite_hack(p_ptr->y, p_ptr->x);
3345 cave_lite_hack(p_ptr->y + 1, p_ptr->x);
3346 cave_lite_hack(p_ptr->y - 1, p_ptr->x);
3347 cave_lite_hack(p_ptr->y, p_ptr->x + 1);
3348 cave_lite_hack(p_ptr->y, p_ptr->x - 1);
3350 /* Diagonal grids */
3351 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 1);
3352 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 1);
3353 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 1);
3354 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 1);
3357 /* Radius 2 -- lantern radius */
3360 /* South of the player */
3361 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
3363 cave_lite_hack(p_ptr->y + 2, p_ptr->x);
3364 cave_lite_hack(p_ptr->y + 2, p_ptr->x + 1);
3365 cave_lite_hack(p_ptr->y + 2, p_ptr->x - 1);
3368 /* North of the player */
3369 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
3371 cave_lite_hack(p_ptr->y - 2, p_ptr->x);
3372 cave_lite_hack(p_ptr->y - 2, p_ptr->x + 1);
3373 cave_lite_hack(p_ptr->y - 2, p_ptr->x - 1);
3376 /* East of the player */
3377 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
3379 cave_lite_hack(p_ptr->y, p_ptr->x + 2);
3380 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 2);
3381 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 2);
3384 /* West of the player */
3385 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
3387 cave_lite_hack(p_ptr->y, p_ptr->x - 2);
3388 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 2);
3389 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 2);
3393 /* Radius 3+ -- artifact radius */
3398 /* Paranoia -- see "LITE_MAX" */
3401 /* South-East of the player */
3402 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
3404 cave_lite_hack(p_ptr->y + 2, p_ptr->x + 2);
3407 /* South-West of the player */
3408 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
3410 cave_lite_hack(p_ptr->y + 2, p_ptr->x - 2);
3413 /* North-East of the player */
3414 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
3416 cave_lite_hack(p_ptr->y - 2, p_ptr->x + 2);
3419 /* North-West of the player */
3420 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
3422 cave_lite_hack(p_ptr->y - 2, p_ptr->x - 2);
3426 min_y = p_ptr->y - p;
3427 if (min_y < 0) min_y = 0;
3430 max_y = p_ptr->y + p;
3431 if (max_y > current_floor_ptr->height - 1) max_y = current_floor_ptr->height - 1;
3434 min_x = p_ptr->x - p;
3435 if (min_x < 0) min_x = 0;
3438 max_x = p_ptr->x + p;
3439 if (max_x > current_floor_ptr->width - 1) max_x = current_floor_ptr->width - 1;
3441 /* Scan the maximal box */
3442 for (y = min_y; y <= max_y; y++)
3444 for (x = min_x; x <= max_x; x++)
3446 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
3447 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
3449 /* Skip the "central" grids (above) */
3450 if ((dy <= 2) && (dx <= 2)) continue;
3452 /* Hack -- approximate the distance */
3453 d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
3455 /* Skip distant grids */
3456 if (d > p) continue;
3458 /* Viewable, nearby, grids get "torch lit" */
3459 if (current_floor_ptr->grid_array[y][x].info & CAVE_VIEW)
3461 /* This grid is "torch lit" */
3462 cave_lite_hack(y, x);
3469 /*** Complete the algorithm ***/
3471 /* Draw the new grids */
3472 for (i = 0; i < current_floor_ptr->lite_n; i++)
3474 y = current_floor_ptr->lite_y[i];
3475 x = current_floor_ptr->lite_x[i];
3477 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3479 /* Update fresh grids */
3480 if (g_ptr->info & (CAVE_TEMP)) continue;
3482 /* Add it to later visual update */
3483 cave_note_and_redraw_later(g_ptr, y, x);
3486 /* Clear them all */
3487 for (i = 0; i < tmp_pos.n; i++)
3492 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3494 /* No longer in the array */
3495 g_ptr->info &= ~(CAVE_TEMP);
3497 /* Update stale grids */
3498 if (g_ptr->info & (CAVE_LITE)) continue;
3500 /* Add it to later visual update */
3501 cave_redraw_later(g_ptr, y, x);
3507 /* Mega-Hack -- Visual update later */
3508 p_ptr->update |= (PU_DELAY_VIS);
3512 static bool mon_invis;
3513 static POSITION mon_fy, mon_fx;
3516 * Add a square to the changes array
3518 static void mon_lite_hack(POSITION y, POSITION x)
3524 /* We trust this grid is in bounds */
3525 /* if (!in_bounds2(y, x)) return; */
3527 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3529 /* Want a unlit square in view of the player */
3530 if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3532 if (!cave_los_grid(g_ptr))
3534 /* Hack -- Prevent monster lite leakage in walls */
3536 /* Horizontal walls between player and a monster */
3537 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
3539 dpf = p_ptr->y - mon_fy;
3541 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
3543 /* Only first wall viewed from mid-x is lit */
3546 if (!cave_los_bold(y, x + 1)) return;
3548 else if (x > midpoint)
3550 if (!cave_los_bold(y, x - 1)) return;
3553 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3554 else if (mon_invis) return;
3557 /* Vertical walls between player and a monster */
3558 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
3560 dpf = p_ptr->x - mon_fx;
3562 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
3564 /* Only first wall viewed from mid-y is lit */
3567 if (!cave_los_bold(y + 1, x)) return;
3569 else if (y > midpoint)
3571 if (!cave_los_bold(y - 1, x)) return;
3574 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3575 else if (mon_invis) return;
3579 /* We trust tmp_pos.n does not exceed TEMP_MAX */
3582 if (!(g_ptr->info & CAVE_MNDK))
3584 /* Save this square */
3585 tmp_pos.x[tmp_pos.n] = x;
3586 tmp_pos.y[tmp_pos.n] = y;
3593 /* No longer dark */
3594 g_ptr->info &= ~(CAVE_MNDK);
3598 g_ptr->info |= CAVE_MNLT;
3603 * Add a square to the changes array
3605 static void mon_dark_hack(POSITION y, POSITION x)
3608 int midpoint, dpf, d;
3610 /* We trust this grid is in bounds */
3611 /* if (!in_bounds2(y, x)) return; */
3613 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3615 /* Want a unlit and undarkened square in view of the player */
3616 if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
3618 if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
3620 /* Hack -- Prevent monster dark lite leakage in walls */
3622 /* Horizontal walls between player and a monster */
3623 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
3625 dpf = p_ptr->y - mon_fy;
3627 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
3629 /* Only first wall viewed from mid-x is lit */
3632 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
3634 else if (x > midpoint)
3636 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
3639 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3640 else if (mon_invis) return;
3643 /* Vertical walls between player and a monster */
3644 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
3646 dpf = p_ptr->x - mon_fx;
3648 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
3650 /* Only first wall viewed from mid-y is lit */
3653 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
3655 else if (y > midpoint)
3657 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
3660 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3661 else if (mon_invis) return;
3665 /* We trust tmp_pos.n does not exceed TEMP_MAX */
3667 /* Save this square */
3668 tmp_pos.x[tmp_pos.n] = x;
3669 tmp_pos.y[tmp_pos.n] = y;
3673 g_ptr->info |= CAVE_MNDK;
3678 * Update squares illuminated or darkened by monsters.
3680 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3681 * denote squares illuminated by monsters.
3683 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
3684 * updating. Only squares in view of the player, whos state
3685 * changes are drawn via lite_spot().
3687 void update_mon_lite(void)
3693 void(*add_mon_lite)(POSITION, POSITION);
3698 /* Non-Ninja player in the darkness */
3699 int dis_lim = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
3700 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
3702 /* Clear all monster lit squares */
3703 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
3706 g_ptr = ¤t_floor_ptr->grid_array[current_floor_ptr->mon_lite_y[i]][current_floor_ptr->mon_lite_x[i]];
3708 /* Set temp or xtra flag */
3709 g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
3711 /* Clear monster illumination flag */
3712 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3715 /* Empty temp list of new squares to lite up */
3718 /* If a monster stops time, don't process */
3719 if (!current_world_ptr->timewalk_m_idx)
3721 monster_type *m_ptr;
3722 monster_race *r_ptr;
3724 /* Loop through monsters, adding newly lit squares to changes list */
3725 for (i = 1; i < m_max; i++)
3727 m_ptr = ¤t_floor_ptr->m_list[i];
3728 r_ptr = &r_info[m_ptr->r_idx];
3729 if (!monster_is_valid(m_ptr)) continue;
3731 /* Is it too far away? */
3732 if (m_ptr->cdis > dis_lim) continue;
3734 /* Get lite radius */
3737 /* Note the radii are cumulative */
3738 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3739 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3740 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3741 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3743 /* Exit if has no light */
3747 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;
3748 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
3749 add_mon_lite = mon_lite_hack;
3754 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!current_floor_ptr->dun_level && !is_daytime()))) continue;
3755 add_mon_lite = mon_dark_hack;
3756 f_flag = FF_PROJECT;
3757 rad = -rad; /* Use absolute value */
3763 /* Is the monster visible? */
3764 mon_invis = !(current_floor_ptr->grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
3766 /* The square it is on */
3767 add_mon_lite(mon_fy, mon_fx);
3769 /* Adjacent squares */
3770 add_mon_lite(mon_fy + 1, mon_fx);
3771 add_mon_lite(mon_fy - 1, mon_fx);
3772 add_mon_lite(mon_fy, mon_fx + 1);
3773 add_mon_lite(mon_fy, mon_fx - 1);
3774 add_mon_lite(mon_fy + 1, mon_fx + 1);
3775 add_mon_lite(mon_fy + 1, mon_fx - 1);
3776 add_mon_lite(mon_fy - 1, mon_fx + 1);
3777 add_mon_lite(mon_fy - 1, mon_fx - 1);
3782 /* South of the monster */
3783 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
3785 add_mon_lite(mon_fy + 2, mon_fx + 1);
3786 add_mon_lite(mon_fy + 2, mon_fx);
3787 add_mon_lite(mon_fy + 2, mon_fx - 1);
3789 g_ptr = ¤t_floor_ptr->grid_array[mon_fy + 2][mon_fx];
3792 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3794 add_mon_lite(mon_fy + 3, mon_fx + 1);
3795 add_mon_lite(mon_fy + 3, mon_fx);
3796 add_mon_lite(mon_fy + 3, mon_fx - 1);
3800 /* North of the monster */
3801 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
3803 add_mon_lite(mon_fy - 2, mon_fx + 1);
3804 add_mon_lite(mon_fy - 2, mon_fx);
3805 add_mon_lite(mon_fy - 2, mon_fx - 1);
3807 g_ptr = ¤t_floor_ptr->grid_array[mon_fy - 2][mon_fx];
3810 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3812 add_mon_lite(mon_fy - 3, mon_fx + 1);
3813 add_mon_lite(mon_fy - 3, mon_fx);
3814 add_mon_lite(mon_fy - 3, mon_fx - 1);
3818 /* East of the monster */
3819 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
3821 add_mon_lite(mon_fy + 1, mon_fx + 2);
3822 add_mon_lite(mon_fy, mon_fx + 2);
3823 add_mon_lite(mon_fy - 1, mon_fx + 2);
3825 g_ptr = ¤t_floor_ptr->grid_array[mon_fy][mon_fx + 2];
3828 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3830 add_mon_lite(mon_fy + 1, mon_fx + 3);
3831 add_mon_lite(mon_fy, mon_fx + 3);
3832 add_mon_lite(mon_fy - 1, mon_fx + 3);
3836 /* West of the monster */
3837 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
3839 add_mon_lite(mon_fy + 1, mon_fx - 2);
3840 add_mon_lite(mon_fy, mon_fx - 2);
3841 add_mon_lite(mon_fy - 1, mon_fx - 2);
3843 g_ptr = ¤t_floor_ptr->grid_array[mon_fy][mon_fx - 2];
3846 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3848 add_mon_lite(mon_fy + 1, mon_fx - 3);
3849 add_mon_lite(mon_fy, mon_fx - 3);
3850 add_mon_lite(mon_fy - 1, mon_fx - 3);
3858 /* South-East of the monster */
3859 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
3861 add_mon_lite(mon_fy + 2, mon_fx + 2);
3864 /* South-West of the monster */
3865 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
3867 add_mon_lite(mon_fy + 2, mon_fx - 2);
3870 /* North-East of the monster */
3871 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
3873 add_mon_lite(mon_fy - 2, mon_fx + 2);
3876 /* North-West of the monster */
3877 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
3879 add_mon_lite(mon_fy - 2, mon_fx - 2);
3885 /* Save end of list of new squares */
3886 end_temp = tmp_pos.n;
3889 * Look at old set flags to see if there are any changes.
3891 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
3893 fx = current_floor_ptr->mon_lite_x[i];
3894 fy = current_floor_ptr->mon_lite_y[i];
3896 /* We trust this grid is in bounds */
3899 g_ptr = ¤t_floor_ptr->grid_array[fy][fx];
3901 if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
3903 /* It it no longer lit? */
3904 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3906 /* It is now unlit */
3907 /* Add it to later visual update */
3908 cave_note_and_redraw_later(g_ptr, fy, fx);
3911 else /* Pervious darkened */
3913 /* It it no longer darken? */
3914 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3916 /* It is now undarken */
3917 /* Add it to later visual update */
3918 cave_note_and_redraw_later(g_ptr, fy, fx);
3922 /* Add to end of temp array */
3923 tmp_pos.x[tmp_pos.n] = fx;
3924 tmp_pos.y[tmp_pos.n] = fy;
3928 /* Clear the lite array */
3929 current_floor_ptr->mon_lite_n = 0;
3931 /* Copy the temp array into the lit array lighting the new squares. */
3932 for (i = 0; i < end_temp; i++)
3937 /* We trust this grid is in bounds */
3940 g_ptr = ¤t_floor_ptr->grid_array[fy][fx];
3942 if (g_ptr->info & CAVE_MNLT) /* Lit */
3944 /* The is the square newly lit and visible? */
3945 if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3948 /* Add it to later visual update */
3949 cave_note_and_redraw_later(g_ptr, fy, fx);
3954 /* The is the square newly darkened and visible? */
3955 if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3957 /* It is now darkened */
3958 /* Add it to later visual update */
3959 cave_note_and_redraw_later(g_ptr, fy, fx);
3963 /* Save in the monster lit or darkened array */
3964 current_floor_ptr->mon_lite_x[current_floor_ptr->mon_lite_n] = fx;
3965 current_floor_ptr->mon_lite_y[current_floor_ptr->mon_lite_n] = fy;
3966 current_floor_ptr->mon_lite_n++;
3969 /* Clear the temp flag for the old lit or darken grids */
3970 for (i = end_temp; i < tmp_pos.n; i++)
3972 /* We trust this grid is in bounds */
3974 current_floor_ptr->grid_array[tmp_pos.y[i]][tmp_pos.x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3977 /* Finished with tmp_pos.n */
3980 /* Mega-Hack -- Visual update later */
3981 p_ptr->update |= (PU_DELAY_VIS);
3983 p_ptr->monlite = (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
3985 if (p_ptr->special_defense & NINJA_S_STEALTH)
3987 if (p_ptr->old_monlite != p_ptr->monlite)
3991 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
3995 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
3999 p_ptr->old_monlite = p_ptr->monlite;
4002 void clear_mon_lite(void)
4007 /* Clear all monster lit squares */
4008 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
4011 g_ptr = ¤t_floor_ptr->grid_array[current_floor_ptr->mon_lite_y[i]][current_floor_ptr->mon_lite_x[i]];
4013 /* Clear monster illumination flag */
4014 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
4017 /* Empty the array */
4018 current_floor_ptr->mon_lite_n = 0;
4024 * Clear the viewable space
4026 void forget_view(void)
4032 /* None to forget */
4033 if (!current_floor_ptr->view_n) return;
4035 /* Clear them all */
4036 for (i = 0; i < current_floor_ptr->view_n; i++)
4038 POSITION y = current_floor_ptr->view_y[i];
4039 POSITION x = current_floor_ptr->view_x[i];
4040 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4042 /* Forget that the grid is viewable */
4043 g_ptr->info &= ~(CAVE_VIEW);
4045 /* if (!panel_contains(y, x)) continue; */
4047 /* Update the screen */
4048 /* lite_spot(y, x); Perhaps don't need? */
4052 current_floor_ptr->view_n = 0;
4058 * This macro allows us to efficiently add a grid to the "view" array,
4059 * note that we are never called for illegal grids, or for grids which
4060 * have already been placed into the "view" array, and we are never
4061 * called when the "view" array is full.
4063 #define cave_view_hack(C,Y,X) \
4065 if (!((C)->info & (CAVE_VIEW))){\
4066 (C)->info |= (CAVE_VIEW); \
4067 current_floor_ptr->view_y[current_floor_ptr->view_n] = (Y); \
4068 current_floor_ptr->view_x[current_floor_ptr->view_n] = (X); \
4069 current_floor_ptr->view_n++;}\
4075 * Helper function for "update_view()" below
4077 * We are checking the "viewability" of grid (y,x) by the player.
4079 * This function assumes that (y,x) is legal (i.e. on the map).
4081 * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
4082 * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
4084 * Note that we are using the "CAVE_XTRA" field for marking grids as
4085 * "easily viewable". This bit is cleared at the end of "update_view()".
4087 * This function adds (y,x) to the "viewable set" if necessary.
4089 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
4091 static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4093 bool f1, f2, v1, v2, z1, z2, wall;
4097 grid_type *g1_c_ptr;
4098 grid_type *g2_c_ptr;
4100 /* Access the grids */
4101 g1_c_ptr = ¤t_floor_ptr->grid_array[y1][x1];
4102 g2_c_ptr = ¤t_floor_ptr->grid_array[y2][x2];
4105 /* Check for walls */
4106 f1 = (cave_los_grid(g1_c_ptr));
4107 f2 = (cave_los_grid(g2_c_ptr));
4109 /* Totally blocked by physical walls */
4110 if (!f1 && !f2) return (TRUE);
4113 /* Check for visibility */
4114 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
4115 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
4117 /* Totally blocked by "unviewable neighbors" */
4118 if (!v1 && !v2) return (TRUE);
4120 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4123 /* Check for walls */
4124 wall = (!cave_los_grid(g_ptr));
4127 /* Check the "ease" of visibility */
4128 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
4129 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
4131 /* Hack -- "easy" plus "easy" yields "easy" */
4134 g_ptr->info |= (CAVE_XTRA);
4136 cave_view_hack(g_ptr, y, x);
4141 /* Hack -- primary "easy" yields "viewed" */
4144 cave_view_hack(g_ptr, y, x);
4149 /* Hack -- "view" plus "view" yields "view" */
4152 /* g_ptr->info |= (CAVE_XTRA); */
4154 cave_view_hack(g_ptr, y, x);
4160 /* Mega-Hack -- the "los()" function works poorly on walls */
4163 cave_view_hack(g_ptr, y, x);
4169 /* Hack -- check line of sight */
4170 if (los(p_ptr->y, p_ptr->x, y, x))
4172 cave_view_hack(g_ptr, y, x);
4178 /* Assume no line of sight. */
4185 * Calculate the viewable space
4187 * 1: Process the player
4188 * 1a: The player is always (easily) viewable
4189 * 2: Process the diagonals
4190 * 2a: The diagonals are (easily) viewable up to the first wall
4191 * 2b: But never go more than 2/3 of the "full" distance
4192 * 3: Process the main axes
4193 * 3a: The main axes are (easily) viewable up to the first wall
4194 * 3b: But never go more than the "full" distance
4195 * 4: Process sequential "strips" in each of the eight octants
4196 * 4a: Each strip runs along the previous strip
4197 * 4b: The main axes are "previous" to the first strip
4198 * 4c: Process both "sides" of each "direction" of each strip
4199 * 4c1: Each side aborts as soon as possible
4200 * 4c2: Each side tells the next strip how far it has to check
4202 * Note that the octant processing involves some pretty interesting
4203 * observations involving when a grid might possibly be viewable from
4204 * a given grid, and on the order in which the strips are processed.
4206 * Note the use of the mathematical facts shown below, which derive
4207 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
4208 * hypotenuse of a right triangle is primarily determined by the length
4209 * of the longest side, when one side is small, and is strictly less
4210 * than one-and-a-half times as long as the longest side when both of
4211 * the sides are large.
4213 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
4214 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
4216 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
4218 * These observations are important because the calculation of the actual
4219 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
4220 * while for small values (up to about 20 or so), the approximations above
4221 * are correct to within an error of at most one grid or so.
4223 * Observe the use of "full" and "over" in the code below, and the use of
4224 * the specialized calculation involving "limit", all of which derive from
4225 * the observations given above. Basically, we note that the "circle" of
4226 * view is completely contained in an "octagon" whose bounds are easy to
4227 * determine, and that only a few steps are needed to derive the actual
4228 * bounds of the circle given the bounds of the octagon.
4230 * Note that by skipping all the grids in the corners of the octagon, we
4231 * place an upper limit on the number of grids in the field of view, given
4232 * that "full" is never more than 20. Of the 1681 grids in the "square" of
4233 * view, only about 1475 of these are in the "octagon" of view, and even
4234 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
4235 * entries to completely contain the actual field of view.
4237 * Note also the care taken to prevent "running off the map". The use of
4238 * explicit checks on the "validity" of the "diagonal", and the fact that
4239 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
4240 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
4241 * of multiple checks on the validity of grids.
4243 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
4244 * "ws","wn" variables. They work like this: While travelling down the
4245 * south-bound strip just to the east of the main south axis, as soon as
4246 * we get to a grid which does not "transmit" viewing, if all of the strips
4247 * preceding us (in this case, just the main axis) had terminated at or before
4248 * the same point, then we can stop, and reset the "max distance" to ourself.
4249 * So, each strip (named by major axis plus offset, thus "se" in this case)
4250 * maintains a "blockage" variable, initialized during the main axis step,
4251 * and checks it whenever a blockage is observed. After processing each
4252 * strip as far as the previous strip told us to process, the next strip is
4253 * told not to go farther than the current strip's farthest viewable grid,
4254 * unless open space is still available. This uses the "k" variable.
4256 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
4257 * macro is a replacement for "cave_los_bold()" which takes a pointer to
4258 * a grid instead of its location. The "cave_view_hack()" macro is a
4259 * chunk of code which adds the given location to the "view" array if it
4260 * is not already there, using both the actual location and a pointer to
4261 * the grid. See above.
4263 * By the way, the purpose of this code is to reduce the dependancy on the
4264 * "los()" function which is slow, and, in some cases, not very accurate.
4266 * It is very possible that I am the only person who fully understands this
4267 * function, and for that I am truly sorry, but efficiency was very important
4268 * and the "simple" version of this function was just not fast enough. I am
4269 * more than willing to replace this function with a simpler one, if it is
4270 * equally efficient, and especially willing if the new function happens to
4271 * derive "reverse-line-of-sight" at the same time, since currently monsters
4272 * just use an optimized hack of "you see me, so I see you", and then use the
4273 * actual "projectable()" function to check spell attacks.
4275 void update_view(void)
4280 int se, sw, ne, nw, es, en, ws, wn;
4284 POSITION y_max = current_floor_ptr->height - 1;
4285 POSITION x_max = current_floor_ptr->width - 1;
4289 /*** Initialize ***/
4292 if (view_reduce_view && !current_floor_ptr->dun_level)
4294 /* Full radius (10) */
4295 full = MAX_SIGHT / 2;
4297 /* Octagon factor (15) */
4298 over = MAX_SIGHT * 3 / 4;
4304 /* Full radius (20) */
4307 /* Octagon factor (30) */
4308 over = MAX_SIGHT * 3 / 2;
4312 /*** Step 0 -- Begin ***/
4314 /* Save the old "view" grids for later */
4315 for (n = 0; n < current_floor_ptr->view_n; n++)
4317 y = current_floor_ptr->view_y[n];
4318 x = current_floor_ptr->view_x[n];
4319 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4321 /* Mark the grid as not in "view" */
4322 g_ptr->info &= ~(CAVE_VIEW);
4324 /* Mark the grid as "seen" */
4325 g_ptr->info |= (CAVE_TEMP);
4327 /* Add it to the "seen" set */
4328 tmp_pos.y[tmp_pos.n] = y;
4329 tmp_pos.x[tmp_pos.n] = x;
4333 /* Start over with the "view" array */
4334 current_floor_ptr->view_n = 0;
4336 /*** Step 1 -- adjacent grids ***/
4338 /* Now start on the player */
4341 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4343 /* Assume the player grid is easily viewable */
4344 g_ptr->info |= (CAVE_XTRA);
4346 /* Assume the player grid is viewable */
4347 cave_view_hack(g_ptr, y, x);
4350 /*** Step 2 -- Major Diagonals ***/
4355 /* Scan south-east */
4356 for (d = 1; d <= z; d++)
4358 g_ptr = ¤t_floor_ptr->grid_array[y + d][x + d];
4359 g_ptr->info |= (CAVE_XTRA);
4360 cave_view_hack(g_ptr, y + d, x + d);
4361 if (!cave_los_grid(g_ptr)) break;
4364 /* Scan south-west */
4365 for (d = 1; d <= z; d++)
4367 g_ptr = ¤t_floor_ptr->grid_array[y + d][x - d];
4368 g_ptr->info |= (CAVE_XTRA);
4369 cave_view_hack(g_ptr, y + d, x - d);
4370 if (!cave_los_grid(g_ptr)) break;
4373 /* Scan north-east */
4374 for (d = 1; d <= z; d++)
4376 g_ptr = ¤t_floor_ptr->grid_array[y - d][x + d];
4377 g_ptr->info |= (CAVE_XTRA);
4378 cave_view_hack(g_ptr, y - d, x + d);
4379 if (!cave_los_grid(g_ptr)) break;
4382 /* Scan north-west */
4383 for (d = 1; d <= z; d++)
4385 g_ptr = ¤t_floor_ptr->grid_array[y - d][x - d];
4386 g_ptr->info |= (CAVE_XTRA);
4387 cave_view_hack(g_ptr, y - d, x - d);
4388 if (!cave_los_grid(g_ptr)) break;
4391 /*** Step 3 -- major axes ***/
4394 for (d = 1; d <= full; d++)
4396 g_ptr = ¤t_floor_ptr->grid_array[y + d][x];
4397 g_ptr->info |= (CAVE_XTRA);
4398 cave_view_hack(g_ptr, y + d, x);
4399 if (!cave_los_grid(g_ptr)) break;
4402 /* Initialize the "south strips" */
4406 for (d = 1; d <= full; d++)
4408 g_ptr = ¤t_floor_ptr->grid_array[y - d][x];
4409 g_ptr->info |= (CAVE_XTRA);
4410 cave_view_hack(g_ptr, y - d, x);
4411 if (!cave_los_grid(g_ptr)) break;
4414 /* Initialize the "north strips" */
4418 for (d = 1; d <= full; d++)
4420 g_ptr = ¤t_floor_ptr->grid_array[y][x + d];
4421 g_ptr->info |= (CAVE_XTRA);
4422 cave_view_hack(g_ptr, y, x + d);
4423 if (!cave_los_grid(g_ptr)) break;
4426 /* Initialize the "east strips" */
4430 for (d = 1; d <= full; d++)
4432 g_ptr = ¤t_floor_ptr->grid_array[y][x - d];
4433 g_ptr->info |= (CAVE_XTRA);
4434 cave_view_hack(g_ptr, y, x - d);
4435 if (!cave_los_grid(g_ptr)) break;
4438 /* Initialize the "west strips" */
4442 /*** Step 4 -- Divide each "octant" into "strips" ***/
4444 /* Now check each "diagonal" (in parallel) */
4445 for (n = 1; n <= over / 2; n++)
4447 POSITION ypn, ymn, xpn, xmn;
4449 /* Acquire the "bounds" of the maximal circle */
4451 if (z > full - n) z = full - n;
4452 while ((z + n + (n >> 1)) > full) z--;
4455 /* Access the four diagonal grids */
4465 /* Maximum distance */
4466 m = MIN(z, y_max - ypn);
4469 if ((xpn <= x_max) && (n < se))
4472 for (k = n, d = 1; d <= m; d++)
4474 /* Check grid "d" in strip "n", notice "blockage" */
4475 if (update_view_aux(ypn + d, xpn, ypn + d - 1, xpn - 1, ypn + d - 1, xpn))
4477 if (n + d >= se) break;
4480 /* Track most distant "non-blockage" */
4487 /* Limit the next strip */
4492 if ((xmn >= 0) && (n < sw))
4495 for (k = n, d = 1; d <= m; d++)
4497 /* Check grid "d" in strip "n", notice "blockage" */
4498 if (update_view_aux(ypn + d, xmn, ypn + d - 1, xmn + 1, ypn + d - 1, xmn))
4500 if (n + d >= sw) break;
4503 /* Track most distant "non-blockage" */
4510 /* Limit the next strip */
4519 /* Maximum distance */
4523 if ((xpn <= x_max) && (n < ne))
4526 for (k = n, d = 1; d <= m; d++)
4528 /* Check grid "d" in strip "n", notice "blockage" */
4529 if (update_view_aux(ymn - d, xpn, ymn - d + 1, xpn - 1, ymn - d + 1, xpn))
4531 if (n + d >= ne) break;
4534 /* Track most distant "non-blockage" */
4541 /* Limit the next strip */
4546 if ((xmn >= 0) && (n < nw))
4549 for (k = n, d = 1; d <= m; d++)
4551 /* Check grid "d" in strip "n", notice "blockage" */
4552 if (update_view_aux(ymn - d, xmn, ymn - d + 1, xmn + 1, ymn - d + 1, xmn))
4554 if (n + d >= nw) break;
4557 /* Track most distant "non-blockage" */
4564 /* Limit the next strip */
4573 /* Maximum distance */
4574 m = MIN(z, x_max - xpn);
4577 if ((ypn <= x_max) && (n < es))
4580 for (k = n, d = 1; d <= m; d++)
4582 /* Check grid "d" in strip "n", notice "blockage" */
4583 if (update_view_aux(ypn, xpn + d, ypn - 1, xpn + d - 1, ypn, xpn + d - 1))
4585 if (n + d >= es) break;
4588 /* Track most distant "non-blockage" */
4595 /* Limit the next strip */
4600 if ((ymn >= 0) && (n < en))
4603 for (k = n, d = 1; d <= m; d++)
4605 /* Check grid "d" in strip "n", notice "blockage" */
4606 if (update_view_aux(ymn, xpn + d, ymn + 1, xpn + d - 1, ymn, xpn + d - 1))
4608 if (n + d >= en) break;
4611 /* Track most distant "non-blockage" */
4618 /* Limit the next strip */
4627 /* Maximum distance */
4631 if ((ypn <= y_max) && (n < ws))
4634 for (k = n, d = 1; d <= m; d++)
4636 /* Check grid "d" in strip "n", notice "blockage" */
4637 if (update_view_aux(ypn, xmn - d, ypn - 1, xmn - d + 1, ypn, xmn - d + 1))
4639 if (n + d >= ws) break;
4642 /* Track most distant "non-blockage" */
4649 /* Limit the next strip */
4654 if ((ymn >= 0) && (n < wn))
4657 for (k = n, d = 1; d <= m; d++)
4659 /* Check grid "d" in strip "n", notice "blockage" */
4660 if (update_view_aux(ymn, xmn - d, ymn + 1, xmn - d + 1, ymn, xmn - d + 1))
4662 if (n + d >= wn) break;
4665 /* Track most distant "non-blockage" */
4672 /* Limit the next strip */
4679 /*** Step 5 -- Complete the algorithm ***/
4681 /* Update all the new grids */
4682 for (n = 0; n < current_floor_ptr->view_n; n++)
4684 y = current_floor_ptr->view_y[n];
4685 x = current_floor_ptr->view_x[n];
4686 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4688 /* Clear the "CAVE_XTRA" flag */
4689 g_ptr->info &= ~(CAVE_XTRA);
4691 /* Update only newly viewed grids */
4692 if (g_ptr->info & (CAVE_TEMP)) continue;
4694 /* Add it to later visual update */
4695 cave_note_and_redraw_later(g_ptr, y, x);
4698 /* Wipe the old grids, update as needed */
4699 for (n = 0; n < tmp_pos.n; n++)
4703 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4705 /* No longer in the array */
4706 g_ptr->info &= ~(CAVE_TEMP);
4708 /* Update only non-viewable grids */
4709 if (g_ptr->info & (CAVE_VIEW)) continue;
4711 /* Add it to later visual update */
4712 cave_redraw_later(g_ptr, y, x);
4718 /* Mega-Hack -- Visual update later */
4719 p_ptr->update |= (PU_DELAY_VIS);
4724 * Mega-Hack -- Delayed visual update
4725 * Only used if update_view(), update_lite() or update_mon_lite() was called
4727 void delayed_visual_update(void)
4733 /* Update needed grids */
4734 for (i = 0; i < current_floor_ptr->redraw_n; i++)
4736 y = current_floor_ptr->redraw_y[i];
4737 x = current_floor_ptr->redraw_x[i];
4738 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4740 /* Update only needed grids (prevent multiple updating) */
4741 if (!(g_ptr->info & CAVE_REDRAW)) continue;
4743 /* If required, note */
4744 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
4748 /* Hack -- Visual update of monster on this grid */
4749 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
4751 /* No longer in the array */
4752 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4756 current_floor_ptr->redraw_n = 0;
4761 * Hack -- forget the "flow" information
4763 void forget_flow(void)
4767 /* Check the entire dungeon */
4768 for (y = 0; y < current_floor_ptr->height; y++)
4770 for (x = 0; x < current_floor_ptr->width; x++)
4772 /* Forget the old data */
4773 current_floor_ptr->grid_array[y][x].dist = 0;
4774 current_floor_ptr->grid_array[y][x].cost = 0;
4775 current_floor_ptr->grid_array[y][x].when = 0;
4782 * Hack - speed up the update_flow algorithm by only doing
4783 * it everytime the player moves out of LOS of the last
4786 static POSITION flow_x = 0;
4787 static POSITION flow_y = 0;
4792 * Hack -- fill in the "cost" field of every grid that the player
4793 * can "reach" with the number of steps needed to reach that grid.
4794 * This also yields the "distance" of the player from every grid.
4796 * In addition, mark the "when" of the grids that can reach
4797 * the player with the incremented value of "flow_n".
4799 * Hack -- use the "seen" array as a "circular queue".
4801 * We do not need a priority queue because the cost from grid
4802 * to grid is always "one" and we process them in order.
4804 void update_flow(void)
4811 /* Paranoia -- make sure the array is empty */
4812 if (tmp_pos.n) return;
4814 /* The last way-point is on the map */
4815 if (running && in_bounds(flow_y, flow_x))
4817 /* The way point is in sight - do not update. (Speedup) */
4818 if (current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
4821 /* Erase all of the current flow information */
4822 for (y = 0; y < current_floor_ptr->height; y++)
4824 for (x = 0; x < current_floor_ptr->width; x++)
4826 current_floor_ptr->grid_array[y][x].cost = 0;
4827 current_floor_ptr->grid_array[y][x].dist = 0;
4831 /* Save player position */
4835 /* Add the player's grid to the queue */
4836 tmp_pos.y[0] = p_ptr->y;
4837 tmp_pos.x[0] = p_ptr->x;
4839 /* Now process the queue */
4840 while (flow_head != flow_tail)
4844 /* Extract the next entry */
4845 ty = tmp_pos.y[flow_tail];
4846 tx = tmp_pos.x[flow_tail];
4848 /* Forget that entry */
4849 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4851 /* Add the "children" */
4852 for (d = 0; d < 8; d++)
4854 int old_head = flow_head;
4855 byte_hack m = current_floor_ptr->grid_array[ty][tx].cost + 1;
4856 byte_hack n = current_floor_ptr->grid_array[ty][tx].dist + 1;
4859 /* Child location */
4860 y = ty + ddy_ddd[d];
4861 x = tx + ddx_ddd[d];
4863 /* Ignore player's grid */
4864 if (player_bold(y, x)) continue;
4866 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4868 if (is_closed_door(g_ptr->feat)) m += 3;
4870 /* Ignore "pre-stamped" entries */
4871 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
4873 /* Ignore "walls" and "rubble" */
4874 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
4876 /* Save the flow cost */
4877 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
4878 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
4880 /* Hack -- limit flow depth */
4881 if (n == MONSTER_FLOW_DEPTH) continue;
4883 /* Enqueue that entry */
4884 tmp_pos.y[flow_head] = y;
4885 tmp_pos.x[flow_head] = x;
4887 /* Advance the queue */
4888 if (++flow_head == TEMP_MAX) flow_head = 0;
4890 /* Hack -- notice overflow by forgetting new entry */
4891 if (flow_head == flow_tail) flow_head = old_head;
4897 static int scent_when = 0;
4900 * Characters leave scent trails for perceptive monsters to track.
4902 * Smell is rather more limited than sound. Many creatures cannot use
4903 * it at all, it doesn't extend very far outwards from the character's
4904 * current position, and monsters can use it to home in the character,
4905 * but not to run away from him.
4907 * Smell is valued according to age. When a character takes his current_world_ptr->game_turn,
4908 * scent is aged by one, and new scent of the current age is laid down.
4909 * Speedy characters leave more scent, true, but it also ages faster,
4910 * which makes it harder to hunt them down.
4912 * Whenever the age count loops, most of the scent trail is erased and
4913 * the age of the remainder is recalculated.
4915 void update_smell(void)
4920 /* Create a table that controls the spread of scent */
4921 const int scent_adjust[5][5] =
4930 /* Loop the age and adjust scent values when necessary */
4931 if (++scent_when == 254)
4933 /* Scan the entire dungeon */
4934 for (y = 0; y < current_floor_ptr->height; y++)
4936 for (x = 0; x < current_floor_ptr->width; x++)
4938 int w = current_floor_ptr->grid_array[y][x].when;
4939 current_floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
4948 /* Lay down new scent */
4949 for (i = 0; i < 5; i++)
4951 for (j = 0; j < 5; j++)
4955 /* Translate table to map grids */
4956 y = i + p_ptr->y - 2;
4957 x = j + p_ptr->x - 2;
4960 if (!in_bounds(y, x)) continue;
4962 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4964 /* Walls, water, and lava cannot hold scent. */
4965 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
4967 /* Grid must not be blocked by walls from the character */
4968 if (!player_has_los_bold(y, x)) continue;
4970 /* Note grids that are too far away */
4971 if (scent_adjust[i][j] == -1) continue;
4973 /* Mark the grid with new scent */
4974 g_ptr->when = scent_when + scent_adjust[i][j];
4981 * Hack -- map the current panel (plus some) ala "magic mapping"
4983 void map_area(POSITION range)
4989 feature_type *f_ptr;
4991 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) range /= 3;
4993 /* Scan that area */
4994 for (y = 1; y < current_floor_ptr->height - 1; y++)
4996 for (x = 1; x < current_floor_ptr->width - 1; x++)
4998 if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
5000 g_ptr = ¤t_floor_ptr->grid_array[y][x];
5002 /* Memorize terrain of the grid */
5003 g_ptr->info |= (CAVE_KNOWN);
5005 /* Feature code (applying "mimic" field) */
5006 feat = get_feat_mimic(g_ptr);
5007 f_ptr = &f_info[feat];
5009 /* All non-walls are "checked" */
5010 if (!have_flag(f_ptr->flags, FF_WALL))
5012 /* Memorize normal features */
5013 if (have_flag(f_ptr->flags, FF_REMEMBER))
5015 /* Memorize the object */
5016 g_ptr->info |= (CAVE_MARK);
5019 /* Memorize known walls */
5020 for (i = 0; i < 8; i++)
5022 g_ptr = ¤t_floor_ptr->grid_array[y + ddy_ddd[i]][x + ddx_ddd[i]];
5024 /* Feature code (applying "mimic" field) */
5025 feat = get_feat_mimic(g_ptr);
5026 f_ptr = &f_info[feat];
5028 /* Memorize walls (etc) */
5029 if (have_flag(f_ptr->flags, FF_REMEMBER))
5031 /* Memorize the walls */
5032 g_ptr->info |= (CAVE_MARK);
5039 p_ptr->redraw |= (PR_MAP);
5041 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
5046 * Change the "feat" flag for a grid, and notice/redraw the grid
5048 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
5050 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5051 feature_type *f_ptr = &f_info[feat];
5052 bool old_los, old_mirror;
5054 if (!character_dungeon)
5056 /* Clear mimic type */
5059 /* Change the feature */
5062 /* Hack -- glow the GLOW terrain */
5063 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
5068 for (i = 0; i < 9; i++)
5070 yy = y + ddy_ddd[i];
5071 xx = x + ddx_ddd[i];
5072 if (!in_bounds2(yy, xx)) continue;
5073 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
5080 old_los = cave_have_flag_bold(y, x, FF_LOS);
5081 old_mirror = is_mirror_grid(g_ptr);
5083 /* Clear mimic type */
5086 /* Change the feature */
5089 /* Remove flag for mirror/glyph */
5090 g_ptr->info &= ~(CAVE_OBJECT);
5092 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
5094 g_ptr->info &= ~(CAVE_GLOW);
5095 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
5097 update_local_illumination(y, x);
5100 /* Check for change to boring grid */
5101 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
5102 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
5108 /* Check if los has changed */
5109 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
5112 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
5114 update_local_illumination(y, x);
5116 #endif /* COMPLEX_WALL_ILLUMINATION */
5118 /* Update the visuals */
5119 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
5122 /* Hack -- glow the GLOW terrain */
5123 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
5129 for (i = 0; i < 9; i++)
5131 yy = y + ddy_ddd[i];
5132 xx = x + ddx_ddd[i];
5133 if (!in_bounds2(yy, xx)) continue;
5134 cc_ptr = ¤t_floor_ptr->grid_array[yy][xx];
5135 cc_ptr->info |= CAVE_GLOW;
5137 if (player_has_los_grid(cc_ptr))
5139 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
5146 update_local_illumination(yy, xx);
5149 if (p_ptr->special_defense & NINJA_S_STEALTH)
5151 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
5157 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
5159 feature_type *f_ptr = &f_info[newfeat];
5161 if (have_flag(f_ptr->flags, FF_CONVERT))
5163 switch (f_ptr->subtype)
5165 case CONVERT_TYPE_FLOOR:
5166 return feat_ground_type[randint0(100)];
5167 case CONVERT_TYPE_WALL:
5168 return feat_wall_type[randint0(100)];
5169 case CONVERT_TYPE_INNER:
5170 return feat_wall_inner;
5171 case CONVERT_TYPE_OUTER:
5172 return feat_wall_outer;
5173 case CONVERT_TYPE_SOLID:
5174 return feat_wall_solid;
5175 case CONVERT_TYPE_STREAM1:
5176 return d_info[p_ptr->dungeon_idx].stream1;
5177 case CONVERT_TYPE_STREAM2:
5178 return d_info[p_ptr->dungeon_idx].stream2;
5183 else return newfeat;
5188 * Take a feature, determine what that feature becomes
5189 * through applying the given action.
5191 FEAT_IDX feat_state(FEAT_IDX feat, int action)
5193 feature_type *f_ptr = &f_info[feat];
5196 /* Get the new feature */
5197 for (i = 0; i < MAX_FEAT_STATES; i++)
5199 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
5202 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
5204 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
5208 * Takes a location and action and changes the feature at that
5209 * location through applying the given action.
5211 void cave_alter_feat(POSITION y, POSITION x, int action)
5213 /* Set old feature */
5214 FEAT_IDX oldfeat = current_floor_ptr->grid_array[y][x].feat;
5216 /* Get the new feat */
5217 FEAT_IDX newfeat = feat_state(oldfeat, action);
5220 if (newfeat == oldfeat) return;
5222 /* Set the new feature */
5223 cave_set_feat(y, x, newfeat);
5225 if (!(feature_action_flags[action] & FAF_NO_DROP))
5227 feature_type *old_f_ptr = &f_info[oldfeat];
5228 feature_type *f_ptr = &f_info[newfeat];
5232 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
5234 /* Place some gold */
5240 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)))
5243 place_object(y, x, 0L);
5247 if (found && character_dungeon && player_can_see_bold(y, x))
5249 msg_print(_("何かを発見した!", "You have found something!"));
5253 if (feature_action_flags[action] & FAF_CRASH_GLASS)
5255 feature_type *old_f_ptr = &f_info[oldfeat];
5257 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
5259 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
5260 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
5266 /* Remove a mirror */
5267 void remove_mirror(POSITION y, POSITION x)
5269 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5271 /* Remove the mirror */
5272 g_ptr->info &= ~(CAVE_OBJECT);
5275 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
5277 g_ptr->info &= ~(CAVE_GLOW);
5278 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
5279 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
5281 update_local_illumination(y, x);
5291 * Return TRUE if there is a mirror on the grid.
5293 bool is_mirror_grid(grid_type *g_ptr)
5295 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
5303 * Return TRUE if there is a mirror on the grid.
5305 bool is_glyph_grid(grid_type *g_ptr)
5307 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
5315 * Return TRUE if there is a mirror on the grid.
5317 bool is_explosive_rune_grid(grid_type *g_ptr)
5319 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
5327 * Calculate "incremental motion". Used by project() and shoot().
5328 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
5330 void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
5332 POSITION dy, dx, dist, shift;
5334 /* Extract the distance travelled */
5335 dy = (*y < y1) ? y1 - *y : *y - y1;
5336 dx = (*x < x1) ? x1 - *x : *x - x1;
5338 /* Number of steps */
5339 dist = (dy > dx) ? dy : dx;
5341 /* We are calculating the next location */
5345 /* Calculate the total distance along each axis */
5346 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
5347 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
5349 /* Paranoia -- Hack -- no motion */
5350 if (!dy && !dx) return;
5353 /* Move mostly vertically */
5356 /* Extract a shift factor */
5357 shift = (dist * dx + (dy - 1) / 2) / dy;
5359 /* Sometimes move along the minor axis */
5360 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
5362 /* Always move along major axis */
5363 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
5366 /* Move mostly horizontally */
5369 /* Extract a shift factor */
5370 shift = (dist * dy + (dx - 1) / 2) / dx;
5372 /* Sometimes move along the minor axis */
5373 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
5375 /* Always move along major axis */
5376 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
5383 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
5384 * at the final destination, assuming no monster gets in the way.
5386 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
5388 bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
5395 /* Check the projection path */
5396 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
5398 /* Identical grid */
5399 if (!grid_n) return TRUE;
5402 y = GRID_Y(grid_g[grid_n - 1]);
5403 x = GRID_X(grid_g[grid_n - 1]);
5405 /* May not end in an unrequested grid */
5406 if ((y != y2) || (x != x2)) return (FALSE);
5414 * Standard "find me a location" function
5416 * Obtains a legal location within the given distance of the initial
5417 * location, and with "los()" from the source to destination location.
5419 * This function is often called from inside a loop which searches for
5420 * locations while increasing the "d" distance.
5422 * Currently the "m" parameter is unused.
5424 void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
5428 /* Pick a location */
5431 /* Pick a new location */
5432 ny = rand_spread(y, d);
5433 nx = rand_spread(x, d);
5435 /* Ignore annoying locations */
5436 if (!in_bounds(ny, nx)) continue;
5438 /* Ignore "excessively distant" locations */
5439 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
5441 if (mode & PROJECT_LOS)
5443 if (los(y, x, ny, nx)) break;
5447 if (projectable(y, x, ny, nx)) break;
5452 /* Save the location */
5461 * Track a new monster
5463 void health_track(MONSTER_IDX m_idx)
5465 /* Mount monster is already tracked */
5466 if (m_idx && m_idx == p_ptr->riding) return;
5468 /* Track a new guy */
5469 p_ptr->health_who = m_idx;
5471 /* Redraw (later) */
5472 p_ptr->redraw |= (PR_HEALTH);
5478 * Hack -- track the given monster race
5480 void monster_race_track(MONRACE_IDX r_idx)
5482 /* Save this monster ID */
5483 p_ptr->monster_race_idx = r_idx;
5485 p_ptr->window |= (PW_MONSTER);
5491 * Hack -- track the given object kind
5493 void object_kind_track(KIND_OBJECT_IDX k_idx)
5495 /* Save this monster ID */
5496 p_ptr->object_kind_idx = k_idx;
5498 p_ptr->window |= (PW_OBJECT);
5504 * Glow deep lava and building entrances in the floor
5506 void glow_deep_lava_and_bldg(void)
5508 POSITION y, x, yy, xx;
5512 /* Not in the darkness dungeon */
5513 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) return;
5515 for (y = 0; y < current_floor_ptr->height; y++)
5517 for (x = 0; x < current_floor_ptr->width; x++)
5519 g_ptr = ¤t_floor_ptr->grid_array[y][x];
5521 /* Feature code (applying "mimic" field) */
5523 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_GLOW))
5525 for (i = 0; i < 9; i++)
5527 yy = y + ddy_ddd[i];
5528 xx = x + ddx_ddd[i];
5529 if (!in_bounds2(yy, xx)) continue;
5530 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
5536 /* Update the view and lite */
5537 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
5539 p_ptr->redraw |= (PR_MAP);
5543 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
5544 * @param m_idx モンスターID
5548 * @return テレポート先として妥当ならばtrue
5550 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
5552 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
5553 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5554 feature_type *f_ptr = &f_info[g_ptr->feat];
5556 /* Require "teleportable" space */
5557 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5559 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
5560 if (player_bold(y, x)) return FALSE;
5562 /* Hack -- no teleport onto glyph of warding */
5563 if (is_glyph_grid(g_ptr)) return FALSE;
5564 if (is_explosive_rune_grid(g_ptr)) return FALSE;
5566 if (!(mode & TELEPORT_PASSIVE))
5568 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
5575 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
5579 * @return テレポート先として妥当ならばtrue
5581 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
5583 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5584 feature_type *f_ptr = &f_info[g_ptr->feat];
5586 /* Require "teleportable" space */
5587 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5589 /* No magical teleporting into vaults and such */
5590 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
5592 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
5594 /* don't teleport on a trap. */
5595 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
5597 if (!(mode & TELEPORT_PASSIVE))
5599 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
5601 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
5603 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
5606 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
5608 /* Always forbid deep lava */
5609 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
5611 /* Forbid shallow lava when the player don't have levitation */
5612 if (!p_ptr->levitation) return FALSE;
5621 * @brief 地形は開くものであって、かつ開かれているかを返す /
5622 * Attempt to open the given chest at the given location
5624 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
5626 bool is_open(FEAT_IDX feat)
5628 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));