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"
32 static byte display_autopick; /*!< 自動拾い状態の設定フラグ */
33 static int match_autopick;
34 static object_type *autopick_obj; /*!< 各種自動拾い処理時に使うオブジェクトポインタ */
35 static int feat_priority; /*!< マップ縮小表示時に表示すべき地形の優先度を保管する */
39 * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
40 * @return 配置に成功したらTRUEを返す
42 bool new_player_spot(void)
44 POSITION y = 0, x = 0;
45 int max_attempts = 10000;
50 /* Place the player */
51 while (max_attempts--)
53 /* Pick a legal spot */
54 y = (POSITION)rand_range(1, current_floor_ptr->height - 2);
55 x = (POSITION)rand_range(1, current_floor_ptr->width - 2);
57 g_ptr = ¤t_floor_ptr->grid_array[y][x];
59 /* Must be a "naked" floor grid */
60 if (g_ptr->m_idx) continue;
61 if (current_floor_ptr->dun_level)
63 f_ptr = &f_info[g_ptr->feat];
65 if (max_attempts > 5000) /* Rule 1 */
67 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
71 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
72 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
75 /* Refuse to start on anti-teleport grids in dungeon */
76 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
78 if (!player_can_enter(g_ptr->feat, 0)) continue;
79 if (!in_bounds(y, x)) continue;
81 /* Refuse to start on anti-teleport grids */
82 if (g_ptr->info & (CAVE_ICKY)) continue;
87 if (max_attempts < 1) /* Should be -1, actually if we failed... */
90 /* Save the new player grid */
100 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
101 * @param y 配置を試みたいマスのY座標
102 * @param x 配置を試みたいマスのX座標
105 void place_random_stairs(POSITION y, POSITION x)
107 bool up_stairs = TRUE;
108 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)
487 if (!in_bounds(y, x)) return;
490 if (cave_have_flag_bold(y, x, FF_WALL)) return;
492 /* Ignore room grids */
493 if (current_floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
495 /* Occasional door (if allowed) */
496 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS))
499 place_random_door(y, x, FALSE);
505 * @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
506 * @param x1 長方形の左端X座標(-1)
507 * @param x2 長方形の右端X座標(+1)
508 * @param y1 長方形の上端Y座標(-1)
509 * @param y2 長方形の下端Y座標(+1)
513 void place_floor(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
517 /* Place a full floor under the room */
518 for (y = y1 - 1; y <= y2 + 1; y++)
520 for (x = x1 - 1; x <= x2 + 1; x++)
522 place_floor_bold(y, x);
523 add_cave_info(y, x, CAVE_ROOM);
524 if (light) add_cave_info(y, x, CAVE_GLOW);
531 * @brief 長方形の部屋を生成する / Make an empty square room, only floor and wall grids
532 * @param x1 長方形の左端X座標(-1)
533 * @param x2 長方形の右端X座標(+1)
534 * @param y1 長方形の上端Y座標(-1)
535 * @param y2 長方形の下端Y座標(+1)
539 void place_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2, bool light)
543 place_floor(x1, x2, y1, y2, light);
545 /* Walls around the room */
546 for (y = y1 - 1; y <= y2 + 1; y++)
548 place_outer_bold(y, x1 - 1);
549 place_outer_bold(y, x2 + 1);
551 for (x = x1 - 1; x <= x2 + 1; x++)
553 place_outer_bold(y1 - 1, x);
554 place_outer_bold(y2 + 1, x);
560 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
561 * @param y 配置したい中心マスのY座標
562 * @param x 配置したい中心マスのX座標
566 * Only really called by some of the "vault" routines.
568 void vault_objects(POSITION y, POSITION x, int num)
571 int i = 0, j = y, k = x;
576 /* Attempt to place 'num' objects */
577 for (; num > 0; --num)
579 /* Try up to 11 spots looking for empty space */
580 for (i = 0; i < 11; ++i)
582 /* Pick a random location */
583 while (dummy < SAFE_MAX_ATTEMPTS)
585 j = rand_spread(y, 2);
586 k = rand_spread(x, 3);
588 if (!in_bounds(j, k)) continue;
592 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
594 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
597 /* Require "clean" floor space */
598 g_ptr = ¤t_floor_ptr->grid_array[j][k];
599 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
601 if (randint0(100) < 75)
603 place_object(j, k, 0L);
610 /* Placement accomplished */
617 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
618 * @param y トラップを配置したいマスの中心Y座標
619 * @param x トラップを配置したいマスの中心X座標
620 * @param yd Y方向の配置分散マス数
621 * @param xd X方向の配置分散マス数
624 * Only really called by some of the "vault" routines.
626 void vault_trap_aux(POSITION y, POSITION x, POSITION yd, POSITION xd)
628 int count = 0, y1 = y, x1 = x;
634 for (count = 0; count <= 5; count++)
637 while (dummy < SAFE_MAX_ATTEMPTS)
639 y1 = rand_spread(y, yd);
640 x1 = rand_spread(x, xd);
642 if (!in_bounds(y1, x1)) continue;
646 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
648 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
651 /* Require "naked" floor grids */
652 g_ptr = ¤t_floor_ptr->grid_array[y1][x1];
653 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
663 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
664 * @param y トラップを配置したいマスの中心Y座標
665 * @param x トラップを配置したいマスの中心X座標
666 * @param yd Y方向の配置分散マス数
667 * @param xd X方向の配置分散マス数
668 * @param num 配置したいトラップの数
671 * Only really called by some of the "vault" routines.
673 void vault_traps(POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
677 for (i = 0; i < num; i++)
679 vault_trap_aux(y, x, yd, xd);
684 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
685 * @param y1 モンスターを配置したいマスの中心Y座標
686 * @param x1 モンスターを配置したいマスの中心X座標
687 * @param num 配置したいモンスターの数
690 * Only really called by some of the "vault" routines.
692 void vault_monsters(POSITION y1, POSITION x1, int num)
698 /* Try to summon "num" monsters "near" the given location */
699 for (k = 0; k < num; k++)
701 /* Try nine locations */
702 for (i = 0; i < 9; i++)
706 /* Pick a nearby location */
707 scatter(&y, &x, y1, x1, d, 0);
709 /* Require "empty" floor grids */
710 g_ptr = ¤t_floor_ptr->grid_array[y][x];
711 if (!cave_empty_grid(g_ptr)) continue;
713 /* Place the monster (allow groups) */
714 current_floor_ptr->monster_level = current_floor_ptr->base_level + 2;
715 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
716 current_floor_ptr->monster_level = current_floor_ptr->base_level;
722 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
723 * @param x チェックするマスのX座標
724 * @param y チェックするマスのY座標
725 * @return 床系地形ならばTRUE
727 bool get_is_floor(POSITION x, POSITION y)
729 if (!in_bounds(y, x))
735 /* Do the real check */
736 if (is_floor_bold(y, x)) return (TRUE);
742 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
743 * @param x 地形を変えたいマスのX座標
744 * @param y 地形を変えたいマスのY座標
747 void set_floor(POSITION x, POSITION y)
749 if (!in_bounds(y, x))
755 if (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM)
757 /* A room border don't touch. */
761 /* Set to be floor if is a wall (don't touch lakes). */
762 if (is_extra_bold(y, x))
763 place_floor_bold(y, x);
767 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
768 * @param g_ptr 永久壁を配置したいマス構造体の参照ポインタ
771 void place_bound_perm_wall(grid_type *g_ptr)
773 if (bound_walls_perm)
775 /* Clear boundary mimic */
780 feature_type *f_ptr = &f_info[g_ptr->feat];
782 /* Hack -- Decline boundary walls with known treasure */
783 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
784 !have_flag(f_ptr->flags, FF_SECRET))
785 g_ptr->feat = feat_state(g_ptr->feat, FF_ENSECRET);
787 /* Set boundary mimic */
788 g_ptr->mimic = g_ptr->feat;
791 /* Add "solid" perma-wall */
792 place_solid_perm_grid(g_ptr);
797 * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
804 POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
806 POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
807 POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
809 /* Squared distance */
810 POSITION target = (dy * dy) + (dx * dx);
812 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
813 POSITION d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
818 if (!dy || !dx) return d;
822 /* Approximate error */
823 err = (target - d * d) / (2 * d);
825 /* No error - we are done */
828 /* Adjust distance */
837 * @brief マスに看破済みの罠があるかの判定を行う。 / Return TRUE if the given grid is a known trap
838 * @param g_ptr マス構造体の参照ポインタ
839 * @return 看破済みの罠があるならTRUEを返す。
841 bool is_known_trap(grid_type *g_ptr)
843 if (!g_ptr->mimic && !cave_have_flag_grid(g_ptr, FF_SECRET) &&
844 is_trap(g_ptr->feat)) return TRUE;
852 * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
853 * @param g_ptr マス構造体の参照ポインタ
854 * @return 隠されたドアがあるならTRUEを返す。
856 bool is_hidden_door(grid_type *g_ptr)
858 if ((g_ptr->mimic || cave_have_flag_grid(g_ptr, FF_SECRET)) &&
859 is_closed_door(g_ptr->feat))
866 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
871 * @return LOSが通っているならTRUEを返す。
873 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
874 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
876 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
878 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
879 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
880 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
882 * We assume that the "mathematical corner" of a non-floor tile does not\n
883 * block line of sight.\n
885 * Because this function uses (short) ints for all calculations, overflow may\n
886 * occur if dx and dy exceed 90.\n
888 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
889 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
890 * we can use integer arithmetic.\n
892 * We travel from start to finish along the longer axis, starting at the border\n
893 * between the first and second tiles, where the y offset = .5 * slope, taking\n
894 * into account the scale factor. See below.\n
896 * Also note that this function and the "move towards target" code do NOT\n
897 * share the same properties. Thus, you can see someone, target them, and\n
898 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
899 * by clever choice of target locations, you can sometimes throw a "curve".\n
901 * Note that "line of sight" is not "reflexive" in all cases.\n
903 * Use the "projectable()" routine to test "spell/missile line of sight".\n
905 * Use the "update_view()" function to determine player line-of-sight.\n
907 bool los(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
927 /* Slope, or 1/Slope, of LOS */
931 /* Extract the offset */
935 /* Extract the absolute offset */
940 /* Handle adjacent (or identical) grids */
941 if ((ax < 2) && (ay < 2)) return TRUE;
944 /* Paranoia -- require "safe" origin */
945 /* if (!in_bounds(y1, x1)) return FALSE; */
946 /* if (!in_bounds(y2, x2)) return FALSE; */
949 /* Directly South/North */
952 /* South -- check for walls */
955 for (ty = y1 + 1; ty < y2; ty++)
957 if (!cave_los_bold(ty, x1)) return FALSE;
961 /* North -- check for walls */
964 for (ty = y1 - 1; ty > y2; ty--)
966 if (!cave_los_bold(ty, x1)) return FALSE;
974 /* Directly East/West */
977 /* East -- check for walls */
980 for (tx = x1 + 1; tx < x2; tx++)
982 if (!cave_los_bold(y1, tx)) return FALSE;
986 /* West -- check for walls */
989 for (tx = x1 - 1; tx > x2; tx--)
991 if (!cave_los_bold(y1, tx)) return FALSE;
1000 /* Extract some signs */
1001 sx = (dx < 0) ? -1 : 1;
1002 sy = (dy < 0) ? -1 : 1;
1005 /* Vertical "knights" */
1010 if (cave_los_bold(y1 + sy, x1)) return TRUE;
1014 /* Horizontal "knights" */
1019 if (cave_los_bold(y1, x1 + sx)) return TRUE;
1024 /* Calculate scale factor div 2 */
1027 /* Calculate scale factor */
1031 /* Travel horizontally */
1034 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
1040 /* Consider the special case where slope == 1. */
1051 /* Note (below) the case (qy == f2), where */
1052 /* the LOS exactly meets the corner of a tile. */
1055 if (!cave_los_bold(ty, tx)) return FALSE;
1066 if (!cave_los_bold(ty, tx)) return FALSE;
1079 /* Travel vertically */
1082 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
1098 /* Note (below) the case (qx == f2), where */
1099 /* the LOS exactly meets the corner of a tile. */
1102 if (!cave_los_bold(ty, tx)) return FALSE;
1113 if (!cave_los_bold(ty, tx)) return FALSE;
1130 #define COMPLEX_WALL_ILLUMINATION /*!< 照明状態を壁により影響を受ける、より複雑な判定に切り替えるマクロ */
1134 * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
1137 * @return 指定された座標に照明がかかっているならTRUEを返す。。
1139 static bool check_local_illumination(POSITION y, POSITION x)
1141 /* Hack -- move towards player */
1142 POSITION yy = (y < p_ptr->y) ? (y + 1) : (y > p_ptr->y) ? (y - 1) : y;
1143 POSITION xx = (x < p_ptr->x) ? (x + 1) : (x > p_ptr->x) ? (x - 1) : x;
1145 /* Check for "local" illumination */
1147 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1149 /* Check for "complex" illumination */
1150 if ((feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][xx])) &&
1151 (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) ||
1152 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[y][xx])) &&
1153 (current_floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) ||
1154 (feat_supports_los(get_feat_mimic(¤t_floor_ptr->grid_array[yy][x])) &&
1155 (current_floor_ptr->grid_array[yy][x].info & CAVE_GLOW)))
1161 #else /* COMPLEX_WALL_ILLUMINATION */
1163 /* Check for "simple" illumination */
1164 return (current_floor_ptr->grid_array[yy][xx].info & CAVE_GLOW) ? TRUE : FALSE;
1166 #endif /* COMPLEX_WALL_ILLUMINATION */
1170 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
1171 #define update_local_illumination_aux(Y, X) \
1173 if (player_has_los_bold((Y), (X))) \
1175 /* Update the monster */ \
1176 if (current_floor_ptr->grid_array[(Y)][(X)].m_idx) update_monster(current_floor_ptr->grid_array[(Y)][(X)].m_idx, FALSE); \
1178 /* Notice and redraw */ \
1179 note_spot((Y), (X)); \
1180 lite_spot((Y), (X)); \
1185 * @brief 指定された座標の照明状態を更新する / Update "local" illumination
1190 void update_local_illumination(POSITION y, POSITION x)
1195 if (!in_bounds(y, x)) return;
1197 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
1199 if ((y != p_ptr->y) && (x != p_ptr->x))
1201 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1202 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1203 update_local_illumination_aux(yy, xx);
1204 update_local_illumination_aux(y, xx);
1205 update_local_illumination_aux(yy, x);
1207 else if (x != p_ptr->x) /* y == p_ptr->y */
1209 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1210 for (i = -1; i <= 1; i++)
1213 update_local_illumination_aux(yy, xx);
1216 update_local_illumination_aux(yy, x);
1218 update_local_illumination_aux(yy, x);
1220 else if (y != p_ptr->y) /* x == p_ptr->x */
1222 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1223 for (i = -1; i <= 1; i++)
1226 update_local_illumination_aux(yy, xx);
1229 update_local_illumination_aux(y, xx);
1231 update_local_illumination_aux(y, xx);
1233 else /* Player's grid */
1235 for (i = 0; i < 8; i++)
1237 yy = y + ddy_cdd[i];
1238 xx = x + ddx_cdd[i];
1239 update_local_illumination_aux(yy, xx);
1243 #else /* COMPLEX_WALL_ILLUMINATION */
1245 if ((y != p_ptr->y) && (x != p_ptr->x))
1247 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1248 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1249 update_local_illumination_aux(yy, xx);
1251 else if (x != p_ptr->x) /* y == p_ptr->y */
1253 xx = (x < p_ptr->x) ? (x - 1) : (x + 1);
1254 for (i = -1; i <= 1; i++)
1257 update_local_illumination_aux(yy, xx);
1260 else if (y != p_ptr->y) /* x == p_ptr->x */
1262 yy = (y < p_ptr->y) ? (y - 1) : (y + 1);
1263 for (i = -1; i <= 1; i++)
1266 update_local_illumination_aux(yy, xx);
1269 else /* Player's grid */
1271 for (i = 0; i < 8; i++)
1273 yy = y + ddy_cdd[i];
1274 xx = x + ddx_cdd[i];
1275 update_local_illumination_aux(yy, xx);
1279 #endif /* COMPLEX_WALL_ILLUMINATION */
1284 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
1287 * @return 視覚に収められる状態ならTRUEを返す
1289 * He must have vision, illumination, and line of sight.\n
1291 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
1292 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
1294 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
1295 * that a wall is visible from any direction. That would be odd. Except\n
1296 * under wizard light, which might make sense. Thus, for walls, we require\n
1297 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
1298 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
1299 * in line of sight of the player.\n
1301 * This extra check is expensive, but it provides a more "correct" semantics.\n
1303 * Note that we should not run this check on walls which are "outer walls" of\n
1304 * the dungeon, or we will induce a memory fault, but actually verifying all\n
1305 * of the locations would be extremely expensive.\n
1307 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
1308 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
1309 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
1310 * and the player has more important things on his mind when he is attacking a\n
1311 * monster vault. It is annoying, but an extremely important optimization.\n
1313 * Note that "glowing walls" are only considered to be "illuminated" if the\n
1314 * grid which is next to the wall in the direction of the player is also a\n
1315 * "glowing" grid. This prevents the player from being able to "see" the\n
1316 * walls of illuminated rooms from a corridor outside the room.\n
1318 bool player_can_see_bold(POSITION y, POSITION x)
1322 /* Blind players see nothing */
1323 if (p_ptr->blind) return FALSE;
1325 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1327 /* Note that "torch-lite" yields "illumination" */
1328 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) return TRUE;
1330 /* Require line of sight to the grid */
1331 if (!player_has_los_bold(y, x)) return FALSE;
1333 /* Noctovision of Ninja */
1334 if (p_ptr->see_nocto) return TRUE;
1336 /* Require "perma-lite" of the grid */
1337 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) return FALSE;
1339 /* Feature code (applying "mimic" field) */
1340 /* Floors are simple */
1341 if (feat_supports_los(get_feat_mimic(g_ptr))) return TRUE;
1343 /* Check for "local" illumination */
1344 return check_local_illumination(y, x);
1348 * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
1349 * @return 視覚に収められていないならTRUEを返す
1350 * @details player_can_see_bold()関数の返り値の否定を返している。
1354 return (!player_can_see_bold(p_ptr->y, p_ptr->x));
1359 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
1362 * @return 各種の変更が可能ならTRUEを返す。
1364 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
1366 bool cave_valid_bold(POSITION y, POSITION x)
1368 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1369 OBJECT_IDX this_o_idx, next_o_idx = 0;
1371 /* Forbid perma-grids */
1372 if (cave_perma_grid(g_ptr)) return (FALSE);
1375 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1378 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1380 /* Acquire next object */
1381 next_o_idx = o_ptr->next_o_idx;
1383 /* Forbid artifact grids */
1384 if (object_is_artifact(o_ptr)) return (FALSE);
1395 * 一般的にモンスターシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal monster codes
1397 static char image_monster_hack[] = \
1398 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
1401 * 一般的にオブジェクトシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal object codes
1403 static char image_object_hack[] = "?/|\\\"!$()_-=[]{},~";
1406 * @brief モンスターの表示を幻覚状態に差し替える / Mega-Hack -- Hallucinatory monster
1411 static void image_monster(TERM_COLOR *ap, SYMBOL_CODE *cp)
1413 /* Random symbol from set above */
1416 monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
1418 *cp = r_ptr->x_char;
1419 *ap = r_ptr->x_attr;
1424 *cp = (one_in_(25) ?
1425 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
1426 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
1434 * @brief オブジェクトの表示を幻覚状態に差し替える / Hallucinatory object
1439 static void image_object(TERM_COLOR *ap, SYMBOL_CODE *cp)
1443 object_kind *k_ptr = &k_info[randint1(max_k_idx - 1)];
1445 *cp = k_ptr->x_char;
1446 *ap = k_ptr->x_attr;
1450 int n = sizeof(image_object_hack) - 1;
1452 *cp = image_object_hack[randint0(n)];
1461 * @brief オブジェクト&モンスターの表示を幻覚状態に差し替える / Hack -- Random hallucination
1466 static void image_random(TERM_COLOR *ap, SYMBOL_CODE *cp)
1468 /* Normally, assume monsters */
1469 if (randint0(100) < 75)
1471 image_monster(ap, cp);
1474 /* Otherwise, assume objects */
1477 image_object(ap, cp);
1482 * 照明の表現を行うための色合いの関係を{暗闇時, 照明時} で定義する /
1483 * This array lists the effects of "brightness" on various "base" colours.\n
1485 * This is used to do dynamic lighting effects in ascii :-)\n
1486 * At the moment, only the various "floor" tiles are affected.\n
1488 * The layout of the array is [x][0] = light and [x][1] = dark.\n
1490 static TERM_COLOR lighting_colours[16][2] =
1493 {TERM_L_DARK, TERM_DARK},
1496 {TERM_YELLOW, TERM_SLATE},
1499 {TERM_WHITE, TERM_L_DARK},
1502 {TERM_L_UMBER, TERM_UMBER},
1505 {TERM_RED, TERM_RED},
1508 {TERM_L_GREEN, TERM_GREEN},
1511 {TERM_BLUE, TERM_BLUE},
1514 {TERM_L_UMBER, TERM_RED},
1517 {TERM_SLATE, TERM_L_DARK},
1520 {TERM_WHITE, TERM_SLATE},
1523 {TERM_L_RED, TERM_BLUE},
1526 {TERM_YELLOW, TERM_ORANGE},
1529 {TERM_L_RED, TERM_L_RED},
1532 {TERM_L_GREEN, TERM_GREEN},
1535 {TERM_L_BLUE, TERM_L_BLUE},
1538 {TERM_L_UMBER, TERM_UMBER}
1545 void apply_default_feat_lighting(TERM_COLOR f_attr[F_LIT_MAX], SYMBOL_CODE f_char[F_LIT_MAX])
1547 TERM_COLOR s_attr = f_attr[F_LIT_STANDARD];
1548 SYMBOL_CODE s_char = f_char[F_LIT_STANDARD];
1551 if (is_ascii_graphics(s_attr)) /* For ASCII */
1553 f_attr[F_LIT_LITE] = lighting_colours[s_attr & 0x0f][0];
1554 f_attr[F_LIT_DARK] = lighting_colours[s_attr & 0x0f][1];
1555 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_char[i] = s_char;
1557 else /* For tile graphics */
1559 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) f_attr[i] = s_attr;
1560 f_char[F_LIT_LITE] = s_char + 2;
1561 f_char[F_LIT_DARK] = s_char + 1;
1567 * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
1569 #define darkened_grid(C) \
1570 ((((C)->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && \
1575 * @brief Mコマンドによる縮小マップの表示を行う / Extract the attr/char to display at the given (legal) map location
1577 * Basically, we "paint" the chosen attr/char in several passes, starting\n
1578 * with any known "terrain features" (defaulting to darkness), then adding\n
1579 * any known "objects", and finally, adding any known "monsters". This\n
1580 * is not the fastest method but since most of the calls to this function\n
1581 * are made for grids with no monsters or objects, it is fast enough.\n
1583 * Note that this function, if used on the grid containing the "player",\n
1584 * will return the attr/char of the grid underneath the player, and not\n
1585 * the actual player attr/char itself, allowing a lot of optimization\n
1586 * in various "display" functions.\n
1588 * Note that the "zero" entry in the feature/object/monster arrays are\n
1589 * used to provide "special" attr/char codes, with "monster zero" being\n
1590 * used for the player attr/char, "object zero" being used for the "stack"\n
1591 * attr/char, and "feature zero" being used for the "nothing" attr/char,\n
1592 * though this function makes use of only "feature zero".\n
1594 * Note that monsters can have some "special" flags, including "ATTR_MULTI",\n
1595 * which means their color changes, and "ATTR_CLEAR", which means they take\n
1596 * the color of whatever is under them, and "CHAR_CLEAR", which means that\n
1597 * they take the symbol of whatever is under them. Technically, the flag\n
1598 * "CHAR_MULTI" is supposed to indicate that a monster looks strange when\n
1599 * examined, but this flag is currently ignored.\n
1601 * Currently, we do nothing with multi-hued objects, because there are\n
1602 * not any. If there were, they would have to set "shimmer_objects"\n
1603 * when they were created, and then new "shimmer" code in "dungeon.c"\n
1604 * would have to be created handle the "shimmer" effect, and the code\n
1605 * in "current_floor_ptr->grid_array.c" would have to be updated to create the shimmer effect.\n
1607 * Note the effects of hallucination. Objects always appear as random\n
1608 * "objects", monsters as random "monsters", and normal grids occasionally\n
1609 * appear as random "monsters" or "objects", but note that these random\n
1610 * "monsters" and "objects" are really just "colored ascii symbols".\n
1612 * Note that "floors" and "invisible traps" (and "zero" features) are\n
1613 * drawn as "floors" using a special check for optimization purposes,\n
1614 * and these are the only features which get drawn using the special\n
1615 * lighting effects activated by "view_special_lite".\n
1617 * Note the use of the "mimic" field in the "terrain feature" processing,\n
1618 * which allows any feature to "pretend" to be another feature. This is\n
1619 * used to "hide" secret doors, and to make all "doors" appear the same,\n
1620 * and all "walls" appear the same, and "hidden" treasure stay hidden.\n
1621 * It is possible to use this field to make a feature "look" like a floor,\n
1622 * but the "special lighting effects" for floors will not be used.\n
1624 * Note the use of the new "terrain feature" information. Note that the\n
1625 * assumption that all interesting "objects" and "terrain features" are\n
1626 * memorized allows extremely optimized processing below. Note the use\n
1627 * of separate flags on objects to mark them as memorized allows a grid\n
1628 * to have memorized "terrain" without granting knowledge of any object\n
1629 * which may appear in that grid.\n
1631 * Note the efficient code used to determine if a "floor" grid is\n
1632 * "memorized" or "viewable" by the player, where the test for the\n
1633 * grid being "viewable" is based on the facts that (1) the grid\n
1634 * must be "lit" (torch-lit or perma-lit), (2) the grid must be in\n
1635 * line of sight, and (3) the player must not be blind, and uses the\n
1636 * assumption that all torch-lit grids are in line of sight.\n
1638 * Note that floors (and invisible traps) are the only grids which are\n
1639 * not memorized when seen, so only these grids need to check to see if\n
1640 * the grid is "viewable" to the player (if it is not memorized). Since\n
1641 * most non-memorized grids are in fact walls, this induces *massive*\n
1642 * efficiency, at the cost of *forcing* the memorization of non-floor\n
1643 * grids when they are first seen. Note that "invisible traps" are\n
1644 * always treated exactly like "floors", which prevents "cheating".\n
1646 * Note the "special lighting effects" which can be activated for floor\n
1647 * grids using the "view_special_lite" option (for "white" floor grids),\n
1648 * causing certain grids to be displayed using special colors. If the\n
1649 * player is "blind", we will use "dark gray", else if the grid is lit\n
1650 * by the torch, and the "view_yellow_lite" option is set, we will use\n
1651 * "yellow", else if the grid is "dark", we will use "dark gray", else\n
1652 * if the grid is not "viewable", and the "view_bright_lite" option is\n
1653 * set, and the we will use "slate" (gray). We will use "white" for all\n
1654 * other cases, in particular, for illuminated viewable floor grids.\n
1656 * Note the "special lighting effects" which can be activated for wall\n
1657 * grids using the "view_granite_lite" option (for "white" wall grids),\n
1658 * causing certain grids to be displayed using special colors. If the\n
1659 * player is "blind", we will use "dark gray", else if the grid is lit\n
1660 * by the torch, and the "view_yellow_lite" option is set, we will use\n
1661 * "yellow", else if the "view_bright_lite" option is set, and the grid\n
1662 * is not "viewable", or is "dark", or is glowing, but not when viewed\n
1663 * from the player's current location, we will use "slate" (gray). We\n
1664 * will use "white" for all other cases, in particular, for correctly\n
1665 * illuminated viewable wall grids.\n
1667 * Note that, when "view_granite_lite" is set, we use an inline version\n
1668 * of the "player_can_see_bold()" function to check the "viewability" of\n
1669 * grids when the "view_bright_lite" option is set, and we do NOT use\n
1670 * any special colors for "dark" wall grids, since this would allow the\n
1671 * player to notice the walls of illuminated rooms from a hallway that\n
1672 * happened to run beside the room. The alternative, by the way, would\n
1673 * be to prevent the generation of hallways next to rooms, but this\n
1674 * would still allow problems when digging towards a room.\n
1676 * Note that bizarre things must be done when the "attr" and/or "char"\n
1677 * codes have the "high-bit" set, since these values are used to encode\n
1678 * various "special" pictures in some versions, and certain situations,\n
1679 * such as "multi-hued" or "clear" monsters, cause the attr/char codes\n
1680 * to be "scrambled" in various ways.\n
1682 * Note that eventually we may use the "&" symbol for embedded treasure,\n
1683 * and use the "*" symbol to indicate multiple objects, though this will\n
1684 * have to wait for Angband 2.8.0 or later. Note that currently, this\n
1685 * is not important, since only one object or terrain feature is allowed\n
1686 * in each grid. If needed, "k_info[0]" will hold the "stack" attr/char.\n
1688 * Note the assumption that doing "x_ptr = &x_info[x]" plus a few of\n
1689 * "x_ptr->xxx", is quicker than "x_info[x].xxx", if this is incorrect\n
1690 * then a whole lot of code should be changed... XXX XXX\n
1692 void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp)
1694 /* Get the current_floor_ptr->grid_array */
1695 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1697 OBJECT_IDX this_o_idx, next_o_idx = 0;
1699 /* Feature code (applying "mimic" field) */
1700 FEAT_IDX feat = get_feat_mimic(g_ptr);
1703 feature_type *f_ptr = &f_info[feat];
1708 /* Boring grids (floors, etc) */
1709 if (!have_flag(f_ptr->flags, FF_REMEMBER))
1712 * Handle Memorized or visible floor
1714 * No visual when blinded.
1715 * (to prevent strange effects on darkness breath)
1717 * - Can see grids with CAVE_MARK.
1718 * - Can see grids with CAVE_LITE or CAVE_MNLT.
1719 * (Such grids also have CAVE_VIEW)
1720 * - Can see grids with CAVE_VIEW unless darkened by monsters.
1722 if (!p_ptr->blind &&
1723 ((g_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT)) ||
1724 ((g_ptr->info & CAVE_VIEW) && (((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || p_ptr->see_nocto))))
1726 /* Normal attr/char */
1727 a = f_ptr->x_attr[F_LIT_STANDARD];
1728 c = f_ptr->x_char[F_LIT_STANDARD];
1730 if (p_ptr->wild_mode)
1732 /* Special lighting effects */
1733 /* Handle "night" */
1734 if (view_special_lite && !is_daytime())
1736 /* Use a darkened colour/tile */
1737 a = f_ptr->x_attr[F_LIT_DARK];
1738 c = f_ptr->x_char[F_LIT_DARK];
1742 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1743 else if (darkened_grid(g_ptr))
1745 /* Unsafe grid -- idea borrowed from Unangband */
1746 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1748 /* Access darkness */
1749 f_ptr = &f_info[feat];
1751 /* Char and attr of darkness */
1752 a = f_ptr->x_attr[F_LIT_STANDARD];
1753 c = f_ptr->x_char[F_LIT_STANDARD];
1756 /* Special lighting effects */
1757 else if (view_special_lite)
1759 /* Handle "torch-lit" grids */
1760 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1763 if (view_yellow_lite)
1765 /* Use a brightly lit colour/tile */
1766 a = f_ptr->x_attr[F_LIT_LITE];
1767 c = f_ptr->x_char[F_LIT_LITE];
1771 /* Handle "dark" grids */
1772 else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1774 /* Use a darkened colour/tile */
1775 a = f_ptr->x_attr[F_LIT_DARK];
1776 c = f_ptr->x_char[F_LIT_DARK];
1779 /* Handle "out-of-sight" grids */
1780 else if (!(g_ptr->info & CAVE_VIEW))
1783 if (view_bright_lite)
1785 /* Use a darkened colour/tile */
1786 a = f_ptr->x_attr[F_LIT_DARK];
1787 c = f_ptr->x_char[F_LIT_DARK];
1796 /* Unsafe grid -- idea borrowed from Unangband */
1797 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1799 /* Access darkness */
1800 f_ptr = &f_info[feat];
1802 /* Normal attr/char */
1803 a = f_ptr->x_attr[F_LIT_STANDARD];
1804 c = f_ptr->x_char[F_LIT_STANDARD];
1808 /* Interesting grids (non-floors) */
1811 /* Memorized grids */
1812 if (g_ptr->info & CAVE_MARK)
1814 /* Normal attr/char */
1815 a = f_ptr->x_attr[F_LIT_STANDARD];
1816 c = f_ptr->x_char[F_LIT_STANDARD];
1818 if (p_ptr->wild_mode)
1820 /* Special lighting effects */
1821 /* Handle "blind" or "night" */
1822 if (view_granite_lite && (p_ptr->blind || !is_daytime()))
1824 /* Use a darkened colour/tile */
1825 a = f_ptr->x_attr[F_LIT_DARK];
1826 c = f_ptr->x_char[F_LIT_DARK];
1830 /* Mega-Hack -- Handle "in-sight" and "darkened" grids */
1831 else if (darkened_grid(g_ptr) && !p_ptr->blind)
1833 if (have_flag(f_ptr->flags, FF_LOS) && have_flag(f_ptr->flags, FF_PROJECT))
1835 /* Unsafe grid -- idea borrowed from Unangband */
1836 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1838 /* Access darkness */
1839 f_ptr = &f_info[feat];
1841 /* Char and attr of darkness */
1842 a = f_ptr->x_attr[F_LIT_STANDARD];
1843 c = f_ptr->x_char[F_LIT_STANDARD];
1845 else if (view_granite_lite && view_bright_lite)
1847 /* Use a darkened colour/tile */
1848 a = f_ptr->x_attr[F_LIT_DARK];
1849 c = f_ptr->x_char[F_LIT_DARK];
1853 /* Special lighting effects */
1854 else if (view_granite_lite)
1856 /* Handle "blind" */
1859 /* Use a darkened colour/tile */
1860 a = f_ptr->x_attr[F_LIT_DARK];
1861 c = f_ptr->x_char[F_LIT_DARK];
1864 /* Handle "torch-lit" grids */
1865 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
1868 if (view_yellow_lite)
1870 /* Use a brightly lit colour/tile */
1871 a = f_ptr->x_attr[F_LIT_LITE];
1872 c = f_ptr->x_char[F_LIT_LITE];
1876 /* Handle "view_bright_lite" */
1877 else if (view_bright_lite)
1880 if (!(g_ptr->info & CAVE_VIEW))
1882 /* Use a darkened colour/tile */
1883 a = f_ptr->x_attr[F_LIT_DARK];
1884 c = f_ptr->x_char[F_LIT_DARK];
1888 else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
1890 /* Use a darkened colour/tile */
1891 a = f_ptr->x_attr[F_LIT_DARK];
1892 c = f_ptr->x_char[F_LIT_DARK];
1895 /* Not glowing correctly */
1896 else if (!have_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(y, x))
1898 /* Use a darkened colour/tile */
1899 a = f_ptr->x_attr[F_LIT_DARK];
1900 c = f_ptr->x_char[F_LIT_DARK];
1909 /* Unsafe grid -- idea borrowed from Unangband */
1910 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
1912 /* Access feature */
1913 f_ptr = &f_info[feat];
1915 /* Normal attr/char */
1916 a = f_ptr->x_attr[F_LIT_STANDARD];
1917 c = f_ptr->x_char[F_LIT_STANDARD];
1921 if (feat_priority == -1) feat_priority = f_ptr->priority;
1923 /* Save the terrain info for the transparency effects */
1931 /* Hack -- rare random hallucination, except on outer dungeon walls */
1937 image_random(ap, cp);
1942 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1945 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1947 /* Acquire next object */
1948 next_o_idx = o_ptr->next_o_idx;
1950 /* Memorized objects */
1951 if (o_ptr->marked & OM_FOUND)
1953 if (display_autopick)
1957 match_autopick = is_autopick(o_ptr);
1958 if (match_autopick == -1)
1961 act = autopick_list[match_autopick].action;
1963 if ((act & DO_DISPLAY) && (act & display_autopick))
1965 autopick_obj = o_ptr;
1969 match_autopick = -1;
1974 (*cp) = object_char(o_ptr);
1977 (*ap) = object_attr(o_ptr);
1981 /* Hack -- hallucination */
1982 if (p_ptr->image) image_object(ap, cp);
1989 /* Handle monsters */
1990 if (g_ptr->m_idx && display_autopick == 0)
1992 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
1994 /* Visible monster */
1997 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
2005 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
2006 * flags are always unseen.
2008 if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
2014 /* Hallucinatory monster */
2015 image_monster(ap, cp);
2020 /* Monster attr/char */
2024 /* Normal monsters */
2025 if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR
2026 | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND)))
2028 /* Desired monster attr/char */
2034 * Monsters with both CHAR_CLEAR and ATTR_CLEAR
2035 * flags are always unseen.
2037 else if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR))
2044 /*** Monster's attr ***/
2045 if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics)
2050 else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics)
2052 /* Multi-hued attr */
2053 if (r_ptr->flags2 & RF2_ATTR_ANY) *ap = randint1(15);
2054 else switch (randint1(7))
2056 case 1: *ap = TERM_RED; break;
2057 case 2: *ap = TERM_L_RED; break;
2058 case 3: *ap = TERM_WHITE; break;
2059 case 4: *ap = TERM_L_GREEN; break;
2060 case 5: *ap = TERM_BLUE; break;
2061 case 6: *ap = TERM_L_DARK; break;
2062 case 7: *ap = TERM_GREEN; break;
2065 else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics)
2067 /* Use semi-random attr (usually mimics' colors vary) */
2068 *ap = g_ptr->m_idx % 15 + 1;
2076 /*** Monster's char ***/
2077 if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics)
2082 else if (r_ptr->flags1 & RF1_SHAPECHANGER)
2086 monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
2087 *cp = tmp_r_ptr->x_char;
2088 *ap = tmp_r_ptr->x_attr;
2092 *cp = (one_in_(25) ?
2093 image_object_hack[randint0(sizeof(image_object_hack) - 1)] :
2094 image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
2107 /* Handle "player" */
2108 if (player_bold(y, x))
2110 monster_race *r_ptr = &r_info[0];
2111 *ap = r_ptr->x_attr;
2112 *cp = r_ptr->x_char;
2119 * Calculate panel colum of a location in the map
2121 static int panel_col_of(int col)
2123 col -= panel_col_min;
2124 if (use_bigtile) col *= 2;
2130 * Moves the cursor to a given MAP (y,x) location
2132 void move_cursor_relative(int row, int col)
2134 /* Real co-ords convert to screen positions */
2135 row -= panel_row_prt;
2138 Term_gotoxy(panel_col_of(col), row);
2144 * Place an attr/char pair at the given map coordinate, if legal.
2146 void print_rel(SYMBOL_CODE c, TERM_COLOR a, TERM_LEN y, TERM_LEN x)
2148 /* Only do "legal" locations */
2149 if (panel_contains(y, x))
2151 /* Hack -- fake monochrome */
2154 if (world_monster) a = TERM_DARK;
2155 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2156 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2159 /* Draw the char using the attr */
2160 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
2169 * Memorize interesting viewable object/features in the given grid
2171 * This function should only be called on "legal" grids.
2173 * This function will memorize the object and/or feature in the given
2174 * grid, if they are (1) viewable and (2) interesting. Note that all
2175 * objects are interesting, all terrain features except floors (and
2176 * invisible traps) are interesting, and floors (and invisible traps)
2177 * are interesting sometimes (depending on various options involving
2178 * the illumination of floor grids).
2180 * The automatic memorization of all objects and non-floor terrain
2181 * features as soon as they are displayed allows incredible amounts
2182 * of optimization in various places, especially "map_info()".
2184 * Note that the memorization of objects is completely separate from
2185 * the memorization of terrain features, preventing annoying floor
2186 * memorization when a detected object is picked up from a dark floor,
2187 * and object memorization when an object is dropped into a floor grid
2188 * which is memorized but out-of-sight.
2190 * This function should be called every time the "memorization" of
2191 * a grid (or the object in a grid) is called into question, such
2192 * as when an object is created in a grid, when a terrain feature
2193 * "changes" from "floor" to "non-floor", when any grid becomes
2194 * "illuminated" or "viewable", and when a "floor" grid becomes
2197 * Note the relatively efficient use of this function by the various
2198 * "update_view()" and "update_lite()" calls, to allow objects and
2199 * terrain features to be memorized (and drawn) whenever they become
2200 * viewable or illuminated in any way, but not when they "maintain"
2201 * or "lose" their previous viewability or illumination.
2203 * Note the butchered "internal" version of "player_can_see_bold()",
2204 * optimized primarily for the most common cases, that is, for the
2205 * non-marked floor grids.
2207 void note_spot(POSITION y, POSITION x)
2209 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2210 OBJECT_IDX this_o_idx, next_o_idx = 0;
2212 /* Blind players see nothing */
2213 if (p_ptr->blind) return;
2215 /* Analyze non-torch-lit grids */
2216 if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT)))
2218 /* Require line of sight to the grid */
2219 if (!(g_ptr->info & (CAVE_VIEW))) return;
2221 /* Require "perma-lite" of the grid */
2222 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
2225 if (!p_ptr->see_nocto) return;
2230 /* Hack -- memorize objects */
2231 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2233 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
2235 /* Acquire next object */
2236 next_o_idx = o_ptr->next_o_idx;
2238 /* Memorize objects */
2239 o_ptr->marked |= OM_FOUND;
2243 /* Hack -- memorize grids */
2244 if (!(g_ptr->info & (CAVE_MARK)))
2246 /* Feature code (applying "mimic" field) */
2247 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
2249 /* Memorize some "boring" grids */
2250 if (!have_flag(f_ptr->flags, FF_REMEMBER))
2252 /* Option -- memorize all torch-lit floors */
2253 if (view_torch_grids &&
2254 ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || p_ptr->see_nocto))
2256 g_ptr->info |= (CAVE_MARK);
2259 /* Option -- memorize all perma-lit floors */
2260 else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW))
2262 g_ptr->info |= (CAVE_MARK);
2266 /* Memorize normal grids */
2267 else if (have_flag(f_ptr->flags, FF_LOS))
2269 g_ptr->info |= (CAVE_MARK);
2272 /* Memorize torch-lit walls */
2273 else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
2275 g_ptr->info |= (CAVE_MARK);
2278 /* Memorize walls seen by noctovision of Ninja */
2279 else if (p_ptr->see_nocto)
2281 g_ptr->info |= (CAVE_MARK);
2284 /* Memorize certain non-torch-lit wall grids */
2285 else if (check_local_illumination(y, x))
2287 g_ptr->info |= (CAVE_MARK);
2291 /* Memorize terrain of the grid */
2292 g_ptr->info |= (CAVE_KNOWN);
2296 void display_dungeon(void)
2303 SYMBOL_CODE tc = '\0';
2305 for (x = p_ptr->x - Term->wid / 2 + 1; x <= p_ptr->x + Term->wid / 2; x++)
2307 for (y = p_ptr->y - Term->hgt / 2 + 1; y <= p_ptr->y + Term->hgt / 2; y++)
2309 if (in_bounds2(y, x))
2312 /* Examine the grid */
2313 map_info(y, x, &a, &c, &ta, &tc);
2315 /* Hack -- fake monochrome */
2318 if (world_monster) a = TERM_DARK;
2319 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2320 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2323 /* Hack -- Queue it */
2324 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
2328 /* Clear out-of-bound tiles */
2330 /* Access darkness */
2331 feature_type *f_ptr = &f_info[feat_none];
2334 a = f_ptr->x_attr[F_LIT_STANDARD];
2337 c = f_ptr->x_char[F_LIT_STANDARD];
2339 /* Hack -- Queue it */
2340 Term_queue_char(x - p_ptr->x + Term->wid / 2 - 1, y - p_ptr->y + Term->hgt / 2 - 1, a, c, ta, tc);
2348 * Redraw (on the screen) a given MAP location
2350 * This function should only be called on "legal" grids
2352 void lite_spot(POSITION y, POSITION x)
2354 /* Redraw if on screen */
2355 if (panel_contains(y, x) && in_bounds2(y, x))
2363 /* Examine the grid */
2364 map_info(y, x, &a, &c, &ta, &tc);
2366 /* Hack -- fake monochrome */
2369 if (world_monster) a = TERM_DARK;
2370 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2371 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2374 /* Hack -- Queue it */
2375 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
2377 /* Update sub-windows */
2378 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2384 * Prints the map of the dungeon
2386 * Note that, for efficiency, we contain an "optimized" version
2387 * of both "lite_spot()" and "print_rel()", and that we use the
2388 * "lite_spot()" function to display the player grid, if needed.
2396 POSITION xmin, xmax, ymin, ymax;
2400 Term_get_size(&wid, &hgt);
2402 /* Remove map offset */
2406 /* Access the cursor state */
2407 (void)Term_get_cursor(&v);
2409 /* Hide the cursor */
2410 (void)Term_set_cursor(0);
2413 xmin = (0 < panel_col_min) ? panel_col_min : 0;
2414 xmax = (current_floor_ptr->width - 1 > panel_col_max) ? panel_col_max : current_floor_ptr->width - 1;
2415 ymin = (0 < panel_row_min) ? panel_row_min : 0;
2416 ymax = (current_floor_ptr->height - 1 > panel_row_max) ? panel_row_max : current_floor_ptr->height - 1;
2418 /* Bottom section of screen */
2419 for (y = 1; y <= ymin - panel_row_prt; y++)
2421 /* Erase the section */
2422 Term_erase(COL_MAP, y, wid);
2425 /* Top section of screen */
2426 for (y = ymax - panel_row_prt; y <= hgt; y++)
2428 /* Erase the section */
2429 Term_erase(COL_MAP, y, wid);
2433 for (y = ymin; y <= ymax; y++)
2435 /* Scan the columns of row "y" */
2436 for (x = xmin; x <= xmax; x++)
2444 /* Determine what is there */
2445 map_info(y, x, &a, &c, &ta, &tc);
2447 /* Hack -- fake monochrome */
2450 if (world_monster) a = TERM_DARK;
2451 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2452 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2455 /* Efficiency -- Redraw that grid of the map */
2456 Term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
2460 /* Display player */
2461 lite_spot(p_ptr->y, p_ptr->x);
2463 /* Restore the cursor */
2464 (void)Term_set_cursor(v);
2470 * print project path
2472 void prt_path(POSITION y, POSITION x)
2477 byte_hack default_color = TERM_SLATE;
2479 if (!display_path) return;
2480 if (-1 == project_length)
2483 /* Get projection path */
2484 path_n = project_path(path_g, (project_length ? project_length : MAX_RANGE), p_ptr->y, p_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
2486 p_ptr->redraw |= (PR_MAP);
2490 for (i = 0; i < path_n; i++)
2492 POSITION ny = GRID_Y(path_g[i]);
2493 POSITION nx = GRID_X(path_g[i]);
2494 grid_type *g_ptr = ¤t_floor_ptr->grid_array[ny][nx];
2496 if (panel_contains(ny, nx))
2498 TERM_COLOR a = default_color;
2501 TERM_COLOR ta = default_color;
2504 if (g_ptr->m_idx && current_floor_ptr->m_list[g_ptr->m_idx].ml)
2506 /* Determine what is there */
2507 map_info(ny, nx, &a, &c, &ta, &tc);
2509 if (!is_ascii_graphics(a))
2511 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
2513 else if (a == default_color)
2519 if (world_monster) a = TERM_DARK;
2520 else if (IS_INVULN() || p_ptr->timewalk) a = TERM_WHITE;
2521 else if (p_ptr->wraith_form) a = TERM_L_DARK;
2526 /* Hack -- Queue it */
2527 Term_queue_bigchar(panel_col_of(nx), ny - panel_row_prt, a, c, ta, tc);
2531 if ((g_ptr->info & CAVE_MARK) && !cave_have_flag_grid(g_ptr, FF_PROJECT)) break;
2534 if (nx == x && ny == y) default_color = TERM_L_DARK;
2539 static concptr simplify_list[][2] =
2546 {"^Amulet of ", "\""},
2547 {"^Scroll of ", "?"},
2548 {"^Scroll titled ", "?"},
2549 {"^Wand of " , "-"},
2551 {"^Staff of " , "_"},
2552 {"^Potion of ", "!"},
2564 static void display_shortened_item_name(object_type *o_ptr, int y)
2571 object_desc(buf, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NAME_ONLY));
2572 attr = tval_to_attr[o_ptr->tval % 128];
2577 strcpy(buf, _("何か奇妙な物", "something strange"));
2580 for (c = buf; *c; c++)
2583 for (i = 0; simplify_list[i][1]; i++)
2585 concptr org_w = simplify_list[i][0];
2595 if (!strncmp(c, org_w, strlen(org_w)))
2598 concptr tmp = simplify_list[i][1];
2601 tmp = c + strlen(org_w);
2617 if (len + 2 > 12) break;
2624 if (len + 1 > 12) break;
2630 Term_putstr(0, y, 12, attr, buf);
2634 * Display a "small-scale" map of the dungeon in the active Term
2636 void display_map(int *cy, int *cx)
2646 SYMBOL_CODE **bigmc;
2653 /* Save lighting effects */
2654 bool old_view_special_lite = view_special_lite;
2655 bool old_view_granite_lite = view_granite_lite;
2657 TERM_LEN hgt, wid, yrat, xrat;
2659 int **match_autopick_yx;
2660 object_type ***object_autopick_yx;
2662 Term_get_size(&wid, &hgt);
2665 if (use_bigtile) wid /= 2;
2667 yrat = (current_floor_ptr->height + hgt - 1) / hgt;
2668 xrat = (current_floor_ptr->width + wid - 1) / wid;
2670 /* Disable lighting effects */
2671 view_special_lite = FALSE;
2672 view_granite_lite = FALSE;
2674 /* Allocate the maps */
2675 C_MAKE(ma, (hgt + 2), TERM_COLOR *);
2676 C_MAKE(mc, (hgt + 2), char_ptr);
2677 C_MAKE(mp, (hgt + 2), byte_ptr);
2678 C_MAKE(match_autopick_yx, (hgt + 2), sint_ptr);
2679 C_MAKE(object_autopick_yx, (hgt + 2), object_type **);
2681 /* Allocate and wipe each line map */
2682 for (y = 0; y < (hgt + 2); y++)
2684 /* Allocate one row each array */
2685 C_MAKE(ma[y], (wid + 2), TERM_COLOR);
2686 C_MAKE(mc[y], (wid + 2), char);
2687 C_MAKE(mp[y], (wid + 2), byte);
2688 C_MAKE(match_autopick_yx[y], (wid + 2), int);
2689 C_MAKE(object_autopick_yx[y], (wid + 2), object_type *);
2691 for (x = 0; x < wid + 2; ++x)
2693 match_autopick_yx[y][x] = -1;
2694 object_autopick_yx[y][x] = NULL;
2697 ma[y][x] = TERM_WHITE;
2705 /* Allocate the maps */
2706 C_MAKE(bigma, (current_floor_ptr->height + 2), TERM_COLOR *);
2707 C_MAKE(bigmc, (current_floor_ptr->height + 2), char_ptr);
2708 C_MAKE(bigmp, (current_floor_ptr->height + 2), byte_ptr);
2710 /* Allocate and wipe each line map */
2711 for (y = 0; y < (current_floor_ptr->height + 2); y++)
2713 /* Allocate one row each array */
2714 C_MAKE(bigma[y], (current_floor_ptr->width + 2), TERM_COLOR);
2715 C_MAKE(bigmc[y], (current_floor_ptr->width + 2), char);
2716 C_MAKE(bigmp[y], (current_floor_ptr->width + 2), byte);
2718 for (x = 0; x < current_floor_ptr->width + 2; ++x)
2721 bigma[y][x] = TERM_WHITE;
2729 /* Fill in the map */
2730 for (i = 0; i < current_floor_ptr->width; ++i)
2732 for (j = 0; j < current_floor_ptr->height; ++j)
2737 match_autopick = -1;
2738 autopick_obj = NULL;
2741 /* Extract the current attr/char at that map location */
2742 map_info(j, i, &ta, &tc, &ta, &tc);
2744 /* Extract the priority */
2745 tp = (byte_hack)feat_priority;
2747 if (match_autopick != -1
2748 && (match_autopick_yx[y][x] == -1
2749 || match_autopick_yx[y][x] > match_autopick))
2751 match_autopick_yx[y][x] = match_autopick;
2752 object_autopick_yx[y][x] = autopick_obj;
2756 /* Save the char, attr and priority */
2757 bigmc[j + 1][i + 1] = tc;
2758 bigma[j + 1][i + 1] = ta;
2759 bigmp[j + 1][i + 1] = tp;
2763 for (j = 0; j < current_floor_ptr->height; ++j)
2765 for (i = 0; i < current_floor_ptr->width; ++i)
2770 tc = bigmc[j + 1][i + 1];
2771 ta = bigma[j + 1][i + 1];
2772 tp = bigmp[j + 1][i + 1];
2774 /* rare feature has more priority */
2780 for (t = 0; t < 8; t++)
2782 if (tc == bigmc[j + 1 + ddy_cdd[t]][i + 1 + ddx_cdd[t]] &&
2783 ta == bigma[j + 1 + ddy_cdd[t]][i + 1 + ddx_cdd[t]])
2793 /* Save the char, attr and priority */
2806 /* Draw the corners */
2807 mc[0][0] = mc[0][x] = mc[y][0] = mc[y][x] = '+';
2809 /* Draw the horizontal edges */
2810 for (x = 1; x <= wid; x++) mc[0][x] = mc[y][x] = '-';
2812 /* Draw the vertical edges */
2813 for (y = 1; y <= hgt; y++) mc[y][0] = mc[y][x] = '|';
2816 /* Display each map line in order */
2817 for (y = 0; y < hgt + 2; ++y)
2819 /* Start a new line */
2820 Term_gotoxy(COL_MAP, y);
2822 /* Display the line */
2823 for (x = 0; x < wid + 2; ++x)
2828 /* Hack -- fake monochrome */
2831 if (world_monster) ta = TERM_DARK;
2832 else if (IS_INVULN() || p_ptr->timewalk) ta = TERM_WHITE;
2833 else if (p_ptr->wraith_form) ta = TERM_L_DARK;
2836 /* Add the character */
2837 Term_add_bigch(ta, tc);
2842 for (y = 1; y < hgt + 1; ++y)
2844 match_autopick = -1;
2845 for (x = 1; x <= wid; x++) {
2846 if (match_autopick_yx[y][x] != -1 &&
2847 (match_autopick > match_autopick_yx[y][x] ||
2848 match_autopick == -1)) {
2849 match_autopick = match_autopick_yx[y][x];
2850 autopick_obj = object_autopick_yx[y][x];
2854 /* Clear old display */
2855 Term_putstr(0, y, 12, 0, " ");
2857 if (match_autopick != -1)
2859 display_shortened_item_name(autopick_obj, y);
2862 char buf[13] = "\0";
2863 strncpy(buf, autopick_list[match_autopick].name, 12);
2871 /* Player location */
2872 (*cy) = p_ptr->y / yrat + 1 + ROW_MAP;
2874 (*cx) = p_ptr->x / xrat + 1 + COL_MAP;
2876 (*cx) = (p_ptr->x / xrat + 1) * 2 + COL_MAP;
2878 /* Restore lighting effects */
2879 view_special_lite = old_view_special_lite;
2880 view_granite_lite = old_view_granite_lite;
2882 /* Free each line map */
2883 for (y = 0; y < (hgt + 2); y++)
2885 /* Free one row each array */
2886 C_KILL(ma[y], (wid + 2), TERM_COLOR);
2887 C_KILL(mc[y], (wid + 2), SYMBOL_CODE);
2888 C_KILL(mp[y], (wid + 2), byte);
2889 C_KILL(match_autopick_yx[y], (wid + 2), int);
2890 C_KILL(object_autopick_yx[y], (wid + 2), object_type *);
2893 /* Free each line map */
2894 C_KILL(ma, (hgt + 2), TERM_COLOR *);
2895 C_KILL(mc, (hgt + 2), char_ptr);
2896 C_KILL(mp, (hgt + 2), byte_ptr);
2897 C_KILL(match_autopick_yx, (hgt + 2), sint_ptr);
2898 C_KILL(object_autopick_yx, (hgt + 2), object_type **);
2900 /* Free each line map */
2901 for (y = 0; y < (current_floor_ptr->height + 2); y++)
2903 /* Free one row each array */
2904 C_KILL(bigma[y], (current_floor_ptr->width + 2), TERM_COLOR);
2905 C_KILL(bigmc[y], (current_floor_ptr->width + 2), SYMBOL_CODE);
2906 C_KILL(bigmp[y], (current_floor_ptr->width + 2), byte);
2909 /* Free each line map */
2910 C_KILL(bigma, (current_floor_ptr->height + 2), TERM_COLOR *);
2911 C_KILL(bigmc, (current_floor_ptr->height + 2), char_ptr);
2912 C_KILL(bigmp, (current_floor_ptr->height + 2), byte_ptr);
2917 * Display a "small-scale" map of the dungeon for the player
2919 * Currently, the "player" is displayed on the map.
2921 void do_cmd_view_map(void)
2927 prt(_("お待ち下さい...", "Please wait..."), 0, 0);
2932 display_autopick = 0;
2934 /* Display the map */
2935 display_map(&cy, &cx);
2938 if (max_autopick && !p_ptr->wild_mode)
2940 display_autopick = ITEM_DISPLAY;
2947 int wid, hgt, row_message;
2949 Term_get_size(&wid, &hgt);
2950 row_message = hgt - 1;
2952 put_str(_("何かキーを押してください('M':拾う 'N':放置 'D':M+N 'K':壊すアイテムを表示)",
2953 " Hit M, N(for ~), K(for !), or D(same as M+N) to display auto-picker items."), row_message, 1);
2955 /* Hilite the player */
2956 move_cursor(cy, cx);
2961 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2963 flag = DONT_AUTOPICK;
2965 flag = DO_AUTODESTROY;
2967 flag = (DO_AUTOPICK | DO_QUERY_AUTOPICK | DONT_AUTOPICK);
2973 if (~display_autopick & flag)
2974 display_autopick |= flag;
2976 display_autopick &= ~flag;
2977 /* Display the map */
2978 display_map(&cy, &cx);
2981 display_autopick = 0;
2986 put_str(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"), 23, 30);
2987 /* Hilite the player */
2988 move_cursor(cy, cx);
3000 * Some comments on the grid flags. -BEN-
3003 * One of the major bottlenecks in previous versions of Angband was in
3004 * the calculation of "line of sight" from the player to various grids,
3005 * such as monsters. This was such a nasty bottleneck that a lot of
3006 * silly things were done to reduce the dependancy on "line of sight",
3007 * for example, you could not "see" any grids in a lit room until you
3008 * actually entered the room, and there were all kinds of bizarre grid
3009 * flags to enable this behavior. This is also why the "call light"
3010 * spells always lit an entire room.
3012 * The code below provides functions to calculate the "field of view"
3013 * for the player, which, once calculated, provides extremely fast
3014 * calculation of "line of sight from the player", and to calculate
3015 * the "field of torch lite", which, again, once calculated, provides
3016 * extremely fast calculation of "which grids are lit by the player's
3017 * lite source". In addition to marking grids as "GRID_VIEW" and/or
3018 * "GRID_LITE", as appropriate, these functions maintain an array for
3019 * each of these two flags, each array containing the locations of all
3020 * of the grids marked with the appropriate flag, which can be used to
3021 * very quickly scan through all of the grids in a given set.
3023 * To allow more "semantically valid" field of view semantics, whenever
3024 * the field of view (or the set of torch lit grids) changes, all of the
3025 * grids in the field of view (or the set of torch lit grids) are "drawn"
3026 * so that changes in the world will become apparent as soon as possible.
3027 * This has been optimized so that only grids which actually "change" are
3028 * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
3029 * of the grids which are entering or leaving the relevent set of grids.
3031 * These new methods are so efficient that the old nasty code was removed.
3033 * Note that there is no reason to "update" the "viewable space" unless
3034 * the player "moves", or walls/doors are created/destroyed, and there
3035 * is no reason to "update" the "torch lit grids" unless the field of
3036 * view changes, or the "light radius" changes. This means that when
3037 * the player is resting, or digging, or doing anything that does not
3038 * involve movement or changing the state of the dungeon, there is no
3039 * need to update the "view" or the "lite" regions, which is nice.
3041 * Note that the calls to the nasty "los()" function have been reduced
3042 * to a bare minimum by the use of the new "field of view" calculations.
3044 * I wouldn't be surprised if slight modifications to the "update_view()"
3045 * function would allow us to determine "reverse line-of-sight" as well
3046 * as "normal line-of-sight", which would allow monsters to use a more
3047 * "correct" calculation to determine if they can "see" the player. For
3048 * now, monsters simply "cheat" somewhat and assume that if the player
3049 * has "line of sight" to the monster, then the monster can "pretend"
3050 * that it has "line of sight" to the player.
3053 * The "update_lite()" function maintains the "CAVE_LITE" flag for each
3054 * grid and maintains an array of all "CAVE_LITE" grids.
3056 * This set of grids is the complete set of all grids which are lit by
3057 * the players light source, which allows the "player_can_see_bold()"
3058 * function to work very quickly.
3060 * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
3061 * fact, the player (unless blind) can always "see" all grids which are
3062 * marked as "CAVE_LITE", unless they are "off screen".
3065 * The "update_view()" function maintains the "CAVE_VIEW" flag for each
3066 * grid and maintains an array of all "CAVE_VIEW" grids.
3068 * This set of grids is the complete set of all grids within line of sight
3069 * of the player, allowing the "player_has_los_bold()" macro to work very
3073 * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
3074 * temporary internal flag to mark those grids which are not only in view,
3075 * but which are also "easily" in line of sight of the player. This flag
3076 * is always cleared when we are done.
3079 * The current "update_lite()" and "update_view()" algorithms use the
3080 * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
3081 * to keep track of which grids were previously marked as "CAVE_LITE" or
3082 * "CAVE_VIEW", which allows us to optimize the "screen updates".
3084 * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
3085 * for various other purposes, such as spreading lite or darkness during
3086 * "lite_room()" / "unlite_room()", and for calculating monster flow.
3089 * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
3090 * in some way permanently lit. However, for the player to "see" anything
3091 * in the grid, as determined by "player_can_see()", the player must not be
3092 * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
3093 * grids, even if marked as "perma lit", are only illuminated if they touch
3094 * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
3097 * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
3098 * that even if the player cannot "see" the grid, he "knows" the terrain in
3099 * that grid. This is used to "remember" walls/doors/stairs/floors when they
3100 * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
3101 * or when one of the "memorize floor grids" options induces memorization.
3103 * Objects are "memorized" in a different way, using a special "marked" flag
3104 * on the object itself, which is set when an object is observed or detected.
3107 * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
3108 * and should be illuminated by "lite room" and "darkness" spells.
3111 * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
3112 * and should be unavailable for "teleportation" destinations.
3115 * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
3116 * which is observed, and the "view_torch_grids" allows the player to memorize
3117 * every torch-lit grid. The player will always memorize important walls,
3118 * doors, stairs, and other terrain features, as well as any "detected" grids.
3120 * Note that the new "update_view()" method allows, among other things, a room
3121 * to be "partially" seen as the player approaches it, with a growing cone of
3122 * floor appearing as the player gets closer to the door. Also, by not turning
3123 * on the "memorize perma-lit grids" option, the player will only "see" those
3124 * floor grids which are actually in line of sight.
3126 * And my favorite "plus" is that you can now use a special option to draw the
3127 * "floors" in the "viewable region" brightly (actually, to draw the *other*
3128 * grids dimly), providing a "pretty" effect as the player runs around, and
3129 * to efficiently display the "torch lite" in a special color.
3132 * Some comments on the "update_view()" algorithm...
3134 * The algorithm is very fast, since it spreads "obvious" grids very quickly,
3135 * and only has to call "los()" on the borderline cases. The major axes/diags
3136 * even terminate early when they hit walls. I need to find a quick way
3137 * to "terminate" the other scans.
3139 * Note that in the worst case (a big empty area with say 5% scattered walls),
3140 * each of the 1500 or so nearby grids is checked once, most of them getting
3141 * an "instant" rating, and only a small portion requiring a call to "los()".
3143 * The only time that the algorithm appears to be "noticeably" too slow is
3144 * when running, and this is usually only important in town, since the town
3145 * provides about the worst scenario possible, with large open regions and
3146 * a few scattered obstructions. There is a special "efficiency" option to
3147 * allow the player to reduce his field of view in town, if needed.
3149 * In the "best" case (say, a normal stretch of corridor), the algorithm
3150 * makes one check for each viewable grid, and makes no calls to "los()".
3151 * So running in corridors is very fast, and if a lot of monsters are
3152 * nearby, it is much faster than the old methods.
3154 * Note that resting, most normal commands, and several forms of running,
3155 * plus all commands executed near large groups of monsters, are strictly
3156 * more efficient with "update_view()" that with the old "compute los() on
3157 * demand" method, primarily because once the "field of view" has been
3158 * calculated, it does not have to be recalculated until the player moves
3159 * (or a wall or door is created or destroyed).
3161 * Note that we no longer have to do as many "los()" checks, since once the
3162 * "view" region has been built, very few things cause it to be "changed"
3163 * (player movement, and the opening/closing of doors, changes in wall status).
3164 * Note that door/wall changes are only relevant when the door/wall itself is
3165 * in the "view" region.
3167 * The algorithm seems to only call "los()" from zero to ten times, usually
3168 * only when coming down a corridor into a room, or standing in a room, just
3169 * misaligned with a corridor. So if, say, there are five "nearby" monsters,
3170 * we will be reducing the calls to "los()".
3172 * I am thinking in terms of an algorithm that "walks" from the central point
3173 * out to the maximal "distance", at each point, determining the "view" code
3174 * (above). For each grid not on a major axis or diagonal, the "view" code
3175 * depends on the "cave_los_bold()" and "view" of exactly two other grids
3176 * (the one along the nearest diagonal, and the one next to that one, see
3177 * "update_view_aux()"...).
3179 * We "memorize" the viewable space array, so that at the cost of under 3000
3180 * bytes, we reduce the time taken by "forget_view()" to one assignment for
3181 * each grid actually in the "viewable space". And for another 3000 bytes,
3182 * we prevent "erase + redraw" ineffiencies via the "seen" set. These bytes
3183 * are also used by other routines, thus reducing the cost to almost nothing.
3185 * A similar thing is done for "forget_lite()" in which case the savings are
3186 * much less, but save us from doing bizarre maintenance checking.
3188 * In the worst "normal" case (in the middle of the town), the reachable space
3189 * actually reaches to more than half of the largest possible "circle" of view,
3190 * or about 800 grids, and in the worse case (in the middle of a dungeon level
3191 * where all the walls have been removed), the reachable space actually reaches
3192 * the theoretical maximum size of just under 1500 grids.
3194 * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
3195 * If G1 is lite, G is lite. Else if G2 is lite, G is half. Else if G1 and G2
3196 * are both half, G is half. Else G is dark. It only takes 2 (or 4) bits to
3197 * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
3198 * entire possible space (including initialization) in one step per grid. If
3199 * we do the "clearing" as a separate step (and use an array of "view" grids),
3200 * then the clearing will take as many steps as grids that were viewed, and the
3201 * algorithm will be able to "stop" scanning at various points.
3202 * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
3213 * Actually erase the entire "lite" array, redrawing every grid
3215 void forget_lite(void)
3219 /* None to forget */
3220 if (!lite_n) return;
3222 /* Clear them all */
3223 for (i = 0; i < lite_n; i++)
3228 /* Forget "LITE" flag */
3229 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
3231 /* lite_spot(y, x); Perhaps don't need? */
3240 * For delayed visual update
3242 #define cave_note_and_redraw_later(C,Y,X) \
3244 (C)->info |= CAVE_NOTE; \
3245 cave_redraw_later((C), (Y), (X)); \
3250 * For delayed visual update
3252 #define cave_redraw_later(C,Y,X) \
3254 if (!((C)->info & CAVE_REDRAW)) \
3256 (C)->info |= CAVE_REDRAW; \
3257 redraw_y[redraw_n] = (Y); \
3258 redraw_x[redraw_n++] = (X); \
3264 * This macro allows us to efficiently add a grid to the "lite" array,
3265 * note that we are never called for illegal grids, or for grids which
3266 * have already been placed into the "lite" array, and we are never
3267 * called when the "lite" array is full.
3269 #define cave_lite_hack(Y,X) \
3271 if (!(current_floor_ptr->grid_array[Y][X].info & (CAVE_LITE))) \
3273 current_floor_ptr->grid_array[Y][X].info |= (CAVE_LITE); \
3274 lite_y[lite_n] = (Y); \
3275 lite_x[lite_n++] = (X); \
3281 * Update the set of grids "illuminated" by the player's lite.
3283 * This routine needs to use the results of "update_view()"
3285 * Note that "blindness" does NOT affect "torch lite". Be careful!
3287 * We optimize most lites (all non-artifact lites) by using "obvious"
3288 * facts about the results of "small" lite radius, and we attempt to
3289 * list the "nearby" grids before the more "distant" ones in the
3290 * array of torch-lit grids.
3292 * We assume that "radius zero" lite is in fact no lite at all.
3294 * Torch Lantern Artifacts
3304 void update_lite(void)
3307 POSITION x, y, min_x, max_x, min_y, max_y;
3308 int p = p_ptr->cur_lite;
3311 /*** Special case ***/
3314 /* Hack -- Player has no lite */
3317 /* Forget the old lite */
3318 /* forget_lite(); Perhaps don't need? */
3320 /* Add it to later visual update */
3321 cave_redraw_later(¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
3325 /*** Save the old "lite" grids for later ***/
3327 /* Clear them all */
3328 for (i = 0; i < lite_n; i++)
3333 /* Mark the grid as not "lite" */
3334 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
3336 /* Mark the grid as "seen" */
3337 current_floor_ptr->grid_array[y][x].info |= (CAVE_TEMP);
3339 /* Add it to the "seen" set */
3349 /*** Collect the new "lite" grids ***/
3351 /* Radius 1 -- torch radius */
3355 cave_lite_hack(p_ptr->y, p_ptr->x);
3358 cave_lite_hack(p_ptr->y + 1, p_ptr->x);
3359 cave_lite_hack(p_ptr->y - 1, p_ptr->x);
3360 cave_lite_hack(p_ptr->y, p_ptr->x + 1);
3361 cave_lite_hack(p_ptr->y, p_ptr->x - 1);
3363 /* Diagonal grids */
3364 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 1);
3365 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 1);
3366 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 1);
3367 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 1);
3370 /* Radius 2 -- lantern radius */
3373 /* South of the player */
3374 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
3376 cave_lite_hack(p_ptr->y + 2, p_ptr->x);
3377 cave_lite_hack(p_ptr->y + 2, p_ptr->x + 1);
3378 cave_lite_hack(p_ptr->y + 2, p_ptr->x - 1);
3381 /* North of the player */
3382 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
3384 cave_lite_hack(p_ptr->y - 2, p_ptr->x);
3385 cave_lite_hack(p_ptr->y - 2, p_ptr->x + 1);
3386 cave_lite_hack(p_ptr->y - 2, p_ptr->x - 1);
3389 /* East of the player */
3390 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
3392 cave_lite_hack(p_ptr->y, p_ptr->x + 2);
3393 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 2);
3394 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 2);
3397 /* West of the player */
3398 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
3400 cave_lite_hack(p_ptr->y, p_ptr->x - 2);
3401 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 2);
3402 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 2);
3406 /* Radius 3+ -- artifact radius */
3411 /* Paranoia -- see "LITE_MAX" */
3414 /* South-East of the player */
3415 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
3417 cave_lite_hack(p_ptr->y + 2, p_ptr->x + 2);
3420 /* South-West of the player */
3421 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
3423 cave_lite_hack(p_ptr->y + 2, p_ptr->x - 2);
3426 /* North-East of the player */
3427 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
3429 cave_lite_hack(p_ptr->y - 2, p_ptr->x + 2);
3432 /* North-West of the player */
3433 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
3435 cave_lite_hack(p_ptr->y - 2, p_ptr->x - 2);
3439 min_y = p_ptr->y - p;
3440 if (min_y < 0) min_y = 0;
3443 max_y = p_ptr->y + p;
3444 if (max_y > current_floor_ptr->height - 1) max_y = current_floor_ptr->height - 1;
3447 min_x = p_ptr->x - p;
3448 if (min_x < 0) min_x = 0;
3451 max_x = p_ptr->x + p;
3452 if (max_x > current_floor_ptr->width - 1) max_x = current_floor_ptr->width - 1;
3454 /* Scan the maximal box */
3455 for (y = min_y; y <= max_y; y++)
3457 for (x = min_x; x <= max_x; x++)
3459 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
3460 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
3462 /* Skip the "central" grids (above) */
3463 if ((dy <= 2) && (dx <= 2)) continue;
3465 /* Hack -- approximate the distance */
3466 d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
3468 /* Skip distant grids */
3469 if (d > p) continue;
3471 /* Viewable, nearby, grids get "torch lit" */
3472 if (current_floor_ptr->grid_array[y][x].info & CAVE_VIEW)
3474 /* This grid is "torch lit" */
3475 cave_lite_hack(y, x);
3482 /*** Complete the algorithm ***/
3484 /* Draw the new grids */
3485 for (i = 0; i < lite_n; i++)
3490 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3492 /* Update fresh grids */
3493 if (g_ptr->info & (CAVE_TEMP)) continue;
3495 /* Add it to later visual update */
3496 cave_note_and_redraw_later(g_ptr, y, x);
3499 /* Clear them all */
3500 for (i = 0; i < temp_n; i++)
3505 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3507 /* No longer in the array */
3508 g_ptr->info &= ~(CAVE_TEMP);
3510 /* Update stale grids */
3511 if (g_ptr->info & (CAVE_LITE)) continue;
3513 /* Add it to later visual update */
3514 cave_redraw_later(g_ptr, y, x);
3520 /* Mega-Hack -- Visual update later */
3521 p_ptr->update |= (PU_DELAY_VIS);
3525 static bool mon_invis;
3526 static POSITION mon_fy, mon_fx;
3529 * Add a square to the changes array
3531 static void mon_lite_hack(POSITION y, POSITION x)
3537 /* We trust this grid is in bounds */
3538 /* if (!in_bounds2(y, x)) return; */
3540 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3542 /* Want a unlit square in view of the player */
3543 if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
3545 if (!cave_los_grid(g_ptr))
3547 /* Hack -- Prevent monster lite leakage in walls */
3549 /* Horizontal walls between player and a monster */
3550 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
3552 dpf = p_ptr->y - mon_fy;
3554 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
3556 /* Only first wall viewed from mid-x is lit */
3559 if (!cave_los_bold(y, x + 1)) return;
3561 else if (x > midpoint)
3563 if (!cave_los_bold(y, x - 1)) return;
3566 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3567 else if (mon_invis) return;
3570 /* Vertical walls between player and a monster */
3571 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
3573 dpf = p_ptr->x - mon_fx;
3575 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
3577 /* Only first wall viewed from mid-y is lit */
3580 if (!cave_los_bold(y + 1, x)) return;
3582 else if (y > midpoint)
3584 if (!cave_los_bold(y - 1, x)) return;
3587 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3588 else if (mon_invis) return;
3592 /* We trust temp_n does not exceed TEMP_MAX */
3595 if (!(g_ptr->info & CAVE_MNDK))
3597 /* Save this square */
3606 /* No longer dark */
3607 g_ptr->info &= ~(CAVE_MNDK);
3611 g_ptr->info |= CAVE_MNLT;
3616 * Add a square to the changes array
3618 static void mon_dark_hack(POSITION y, POSITION x)
3621 int midpoint, dpf, d;
3623 /* We trust this grid is in bounds */
3624 /* if (!in_bounds2(y, x)) return; */
3626 g_ptr = ¤t_floor_ptr->grid_array[y][x];
3628 /* Want a unlit and undarkened square in view of the player */
3629 if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
3631 if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
3633 /* Hack -- Prevent monster dark lite leakage in walls */
3635 /* Horizontal walls between player and a monster */
3636 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
3638 dpf = p_ptr->y - mon_fy;
3640 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
3642 /* Only first wall viewed from mid-x is lit */
3645 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
3647 else if (x > midpoint)
3649 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
3652 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3653 else if (mon_invis) return;
3656 /* Vertical walls between player and a monster */
3657 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
3659 dpf = p_ptr->x - mon_fx;
3661 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
3663 /* Only first wall viewed from mid-y is lit */
3666 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
3668 else if (y > midpoint)
3670 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
3673 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
3674 else if (mon_invis) return;
3678 /* We trust temp_n does not exceed TEMP_MAX */
3680 /* Save this square */
3686 g_ptr->info |= CAVE_MNDK;
3691 * Update squares illuminated or darkened by monsters.
3693 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
3694 * denote squares illuminated by monsters.
3696 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
3697 * updating. Only squares in view of the player, whos state
3698 * changes are drawn via lite_spot().
3700 void update_mon_lite(void)
3706 void(*add_mon_lite)(POSITION, POSITION);
3711 /* Non-Ninja player in the darkness */
3712 int dis_lim = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
3713 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
3715 /* Clear all monster lit squares */
3716 for (i = 0; i < mon_lite_n; i++)
3719 g_ptr = ¤t_floor_ptr->grid_array[mon_lite_y[i]][mon_lite_x[i]];
3721 /* Set temp or xtra flag */
3722 g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
3724 /* Clear monster illumination flag */
3725 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
3728 /* Empty temp list of new squares to lite up */
3731 /* If a monster stops time, don't process */
3734 monster_type *m_ptr;
3735 monster_race *r_ptr;
3737 /* Loop through monsters, adding newly lit squares to changes list */
3738 for (i = 1; i < m_max; i++)
3740 m_ptr = ¤t_floor_ptr->m_list[i];
3741 r_ptr = &r_info[m_ptr->r_idx];
3743 /* Skip dead monsters */
3744 if (!m_ptr->r_idx) continue;
3746 /* Is it too far away? */
3747 if (m_ptr->cdis > dis_lim) continue;
3749 /* Get lite radius */
3752 /* Note the radii are cumulative */
3753 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
3754 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
3755 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
3756 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
3758 /* Exit if has no light */
3762 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;
3763 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
3764 add_mon_lite = mon_lite_hack;
3769 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!current_floor_ptr->dun_level && !is_daytime()))) continue;
3770 add_mon_lite = mon_dark_hack;
3771 f_flag = FF_PROJECT;
3772 rad = -rad; /* Use absolute value */
3775 /* Access the location */
3779 /* Is the monster visible? */
3780 mon_invis = !(current_floor_ptr->grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
3782 /* The square it is on */
3783 add_mon_lite(mon_fy, mon_fx);
3785 /* Adjacent squares */
3786 add_mon_lite(mon_fy + 1, mon_fx);
3787 add_mon_lite(mon_fy - 1, mon_fx);
3788 add_mon_lite(mon_fy, mon_fx + 1);
3789 add_mon_lite(mon_fy, mon_fx - 1);
3790 add_mon_lite(mon_fy + 1, mon_fx + 1);
3791 add_mon_lite(mon_fy + 1, mon_fx - 1);
3792 add_mon_lite(mon_fy - 1, mon_fx + 1);
3793 add_mon_lite(mon_fy - 1, mon_fx - 1);
3798 /* South of the monster */
3799 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
3801 add_mon_lite(mon_fy + 2, mon_fx + 1);
3802 add_mon_lite(mon_fy + 2, mon_fx);
3803 add_mon_lite(mon_fy + 2, mon_fx - 1);
3805 g_ptr = ¤t_floor_ptr->grid_array[mon_fy + 2][mon_fx];
3808 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3810 add_mon_lite(mon_fy + 3, mon_fx + 1);
3811 add_mon_lite(mon_fy + 3, mon_fx);
3812 add_mon_lite(mon_fy + 3, mon_fx - 1);
3816 /* North of the monster */
3817 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
3819 add_mon_lite(mon_fy - 2, mon_fx + 1);
3820 add_mon_lite(mon_fy - 2, mon_fx);
3821 add_mon_lite(mon_fy - 2, mon_fx - 1);
3823 g_ptr = ¤t_floor_ptr->grid_array[mon_fy - 2][mon_fx];
3826 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3828 add_mon_lite(mon_fy - 3, mon_fx + 1);
3829 add_mon_lite(mon_fy - 3, mon_fx);
3830 add_mon_lite(mon_fy - 3, mon_fx - 1);
3834 /* East of the monster */
3835 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
3837 add_mon_lite(mon_fy + 1, mon_fx + 2);
3838 add_mon_lite(mon_fy, mon_fx + 2);
3839 add_mon_lite(mon_fy - 1, mon_fx + 2);
3841 g_ptr = ¤t_floor_ptr->grid_array[mon_fy][mon_fx + 2];
3844 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3846 add_mon_lite(mon_fy + 1, mon_fx + 3);
3847 add_mon_lite(mon_fy, mon_fx + 3);
3848 add_mon_lite(mon_fy - 1, mon_fx + 3);
3852 /* West of the monster */
3853 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
3855 add_mon_lite(mon_fy + 1, mon_fx - 2);
3856 add_mon_lite(mon_fy, mon_fx - 2);
3857 add_mon_lite(mon_fy - 1, mon_fx - 2);
3859 g_ptr = ¤t_floor_ptr->grid_array[mon_fy][mon_fx - 2];
3862 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
3864 add_mon_lite(mon_fy + 1, mon_fx - 3);
3865 add_mon_lite(mon_fy, mon_fx - 3);
3866 add_mon_lite(mon_fy - 1, mon_fx - 3);
3874 /* South-East of the monster */
3875 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
3877 add_mon_lite(mon_fy + 2, mon_fx + 2);
3880 /* South-West of the monster */
3881 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
3883 add_mon_lite(mon_fy + 2, mon_fx - 2);
3886 /* North-East of the monster */
3887 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
3889 add_mon_lite(mon_fy - 2, mon_fx + 2);
3892 /* North-West of the monster */
3893 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
3895 add_mon_lite(mon_fy - 2, mon_fx - 2);
3901 /* Save end of list of new squares */
3905 * Look at old set flags to see if there are any changes.
3907 for (i = 0; i < mon_lite_n; i++)
3912 /* We trust this grid is in bounds */
3915 g_ptr = ¤t_floor_ptr->grid_array[fy][fx];
3917 if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
3919 /* It it no longer lit? */
3920 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
3922 /* It is now unlit */
3923 /* Add it to later visual update */
3924 cave_note_and_redraw_later(g_ptr, fy, fx);
3927 else /* Pervious darkened */
3929 /* It it no longer darken? */
3930 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
3932 /* It is now undarken */
3933 /* Add it to later visual update */
3934 cave_note_and_redraw_later(g_ptr, fy, fx);
3938 /* Add to end of temp array */
3939 temp_x[temp_n] = fx;
3940 temp_y[temp_n] = fy;
3944 /* Clear the lite array */
3947 /* Copy the temp array into the lit array lighting the new squares. */
3948 for (i = 0; i < end_temp; i++)
3953 /* We trust this grid is in bounds */
3956 g_ptr = ¤t_floor_ptr->grid_array[fy][fx];
3958 if (g_ptr->info & CAVE_MNLT) /* Lit */
3960 /* The is the square newly lit and visible? */
3961 if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
3964 /* Add it to later visual update */
3965 cave_note_and_redraw_later(g_ptr, fy, fx);
3970 /* The is the square newly darkened and visible? */
3971 if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
3973 /* It is now darkened */
3974 /* Add it to later visual update */
3975 cave_note_and_redraw_later(g_ptr, fy, fx);
3979 /* Save in the monster lit or darkened array */
3980 mon_lite_x[mon_lite_n] = fx;
3981 mon_lite_y[mon_lite_n] = fy;
3985 /* Clear the temp flag for the old lit or darken grids */
3986 for (i = end_temp; i < temp_n; i++)
3988 /* We trust this grid is in bounds */
3990 current_floor_ptr->grid_array[temp_y[i]][temp_x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
3993 /* Finished with temp_n */
3996 /* Mega-Hack -- Visual update later */
3997 p_ptr->update |= (PU_DELAY_VIS);
3999 p_ptr->monlite = (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
4001 if (p_ptr->special_defense & NINJA_S_STEALTH)
4003 if (p_ptr->old_monlite != p_ptr->monlite)
4007 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
4011 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
4015 p_ptr->old_monlite = p_ptr->monlite;
4018 void clear_mon_lite(void)
4023 /* Clear all monster lit squares */
4024 for (i = 0; i < mon_lite_n; i++)
4027 g_ptr = ¤t_floor_ptr->grid_array[mon_lite_y[i]][mon_lite_x[i]];
4029 /* Clear monster illumination flag */
4030 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
4033 /* Empty the array */
4040 * Clear the viewable space
4042 void forget_view(void)
4048 /* None to forget */
4049 if (!view_n) return;
4051 /* Clear them all */
4052 for (i = 0; i < view_n; i++)
4054 POSITION y = view_y[i];
4055 POSITION x = view_x[i];
4056 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4058 /* Forget that the grid is viewable */
4059 g_ptr->info &= ~(CAVE_VIEW);
4061 /* if (!panel_contains(y, x)) continue; */
4063 /* Update the screen */
4064 /* lite_spot(y, x); Perhaps don't need? */
4074 * This macro allows us to efficiently add a grid to the "view" array,
4075 * note that we are never called for illegal grids, or for grids which
4076 * have already been placed into the "view" array, and we are never
4077 * called when the "view" array is full.
4079 #define cave_view_hack(C,Y,X) \
4081 if (!((C)->info & (CAVE_VIEW))){\
4082 (C)->info |= (CAVE_VIEW); \
4083 view_y[view_n] = (Y); \
4084 view_x[view_n] = (X); \
4091 * Helper function for "update_view()" below
4093 * We are checking the "viewability" of grid (y,x) by the player.
4095 * This function assumes that (y,x) is legal (i.e. on the map).
4097 * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
4098 * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
4100 * Note that we are using the "CAVE_XTRA" field for marking grids as
4101 * "easily viewable". This bit is cleared at the end of "update_view()".
4103 * This function adds (y,x) to the "viewable set" if necessary.
4105 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
4107 static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
4109 bool f1, f2, v1, v2, z1, z2, wall;
4113 grid_type *g1_c_ptr;
4114 grid_type *g2_c_ptr;
4116 /* Access the grids */
4117 g1_c_ptr = ¤t_floor_ptr->grid_array[y1][x1];
4118 g2_c_ptr = ¤t_floor_ptr->grid_array[y2][x2];
4121 /* Check for walls */
4122 f1 = (cave_los_grid(g1_c_ptr));
4123 f2 = (cave_los_grid(g2_c_ptr));
4125 /* Totally blocked by physical walls */
4126 if (!f1 && !f2) return (TRUE);
4129 /* Check for visibility */
4130 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
4131 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
4133 /* Totally blocked by "unviewable neighbors" */
4134 if (!v1 && !v2) return (TRUE);
4136 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4139 /* Check for walls */
4140 wall = (!cave_los_grid(g_ptr));
4143 /* Check the "ease" of visibility */
4144 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
4145 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
4147 /* Hack -- "easy" plus "easy" yields "easy" */
4150 g_ptr->info |= (CAVE_XTRA);
4152 cave_view_hack(g_ptr, y, x);
4157 /* Hack -- primary "easy" yields "viewed" */
4160 cave_view_hack(g_ptr, y, x);
4165 /* Hack -- "view" plus "view" yields "view" */
4168 /* g_ptr->info |= (CAVE_XTRA); */
4170 cave_view_hack(g_ptr, y, x);
4176 /* Mega-Hack -- the "los()" function works poorly on walls */
4179 cave_view_hack(g_ptr, y, x);
4185 /* Hack -- check line of sight */
4186 if (los(p_ptr->y, p_ptr->x, y, x))
4188 cave_view_hack(g_ptr, y, x);
4194 /* Assume no line of sight. */
4201 * Calculate the viewable space
4203 * 1: Process the player
4204 * 1a: The player is always (easily) viewable
4205 * 2: Process the diagonals
4206 * 2a: The diagonals are (easily) viewable up to the first wall
4207 * 2b: But never go more than 2/3 of the "full" distance
4208 * 3: Process the main axes
4209 * 3a: The main axes are (easily) viewable up to the first wall
4210 * 3b: But never go more than the "full" distance
4211 * 4: Process sequential "strips" in each of the eight octants
4212 * 4a: Each strip runs along the previous strip
4213 * 4b: The main axes are "previous" to the first strip
4214 * 4c: Process both "sides" of each "direction" of each strip
4215 * 4c1: Each side aborts as soon as possible
4216 * 4c2: Each side tells the next strip how far it has to check
4218 * Note that the octant processing involves some pretty interesting
4219 * observations involving when a grid might possibly be viewable from
4220 * a given grid, and on the order in which the strips are processed.
4222 * Note the use of the mathematical facts shown below, which derive
4223 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
4224 * hypotenuse of a right triangle is primarily determined by the length
4225 * of the longest side, when one side is small, and is strictly less
4226 * than one-and-a-half times as long as the longest side when both of
4227 * the sides are large.
4229 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
4230 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
4232 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
4234 * These observations are important because the calculation of the actual
4235 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
4236 * while for small values (up to about 20 or so), the approximations above
4237 * are correct to within an error of at most one grid or so.
4239 * Observe the use of "full" and "over" in the code below, and the use of
4240 * the specialized calculation involving "limit", all of which derive from
4241 * the observations given above. Basically, we note that the "circle" of
4242 * view is completely contained in an "octagon" whose bounds are easy to
4243 * determine, and that only a few steps are needed to derive the actual
4244 * bounds of the circle given the bounds of the octagon.
4246 * Note that by skipping all the grids in the corners of the octagon, we
4247 * place an upper limit on the number of grids in the field of view, given
4248 * that "full" is never more than 20. Of the 1681 grids in the "square" of
4249 * view, only about 1475 of these are in the "octagon" of view, and even
4250 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
4251 * entries to completely contain the actual field of view.
4253 * Note also the care taken to prevent "running off the map". The use of
4254 * explicit checks on the "validity" of the "diagonal", and the fact that
4255 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
4256 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
4257 * of multiple checks on the validity of grids.
4259 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
4260 * "ws","wn" variables. They work like this: While travelling down the
4261 * south-bound strip just to the east of the main south axis, as soon as
4262 * we get to a grid which does not "transmit" viewing, if all of the strips
4263 * preceding us (in this case, just the main axis) had terminated at or before
4264 * the same point, then we can stop, and reset the "max distance" to ourself.
4265 * So, each strip (named by major axis plus offset, thus "se" in this case)
4266 * maintains a "blockage" variable, initialized during the main axis step,
4267 * and checks it whenever a blockage is observed. After processing each
4268 * strip as far as the previous strip told us to process, the next strip is
4269 * told not to go farther than the current strip's farthest viewable grid,
4270 * unless open space is still available. This uses the "k" variable.
4272 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
4273 * macro is a replacement for "cave_los_bold()" which takes a pointer to
4274 * a grid instead of its location. The "cave_view_hack()" macro is a
4275 * chunk of code which adds the given location to the "view" array if it
4276 * is not already there, using both the actual location and a pointer to
4277 * the grid. See above.
4279 * By the way, the purpose of this code is to reduce the dependancy on the
4280 * "los()" function which is slow, and, in some cases, not very accurate.
4282 * It is very possible that I am the only person who fully understands this
4283 * function, and for that I am truly sorry, but efficiency was very important
4284 * and the "simple" version of this function was just not fast enough. I am
4285 * more than willing to replace this function with a simpler one, if it is
4286 * equally efficient, and especially willing if the new function happens to
4287 * derive "reverse-line-of-sight" at the same time, since currently monsters
4288 * just use an optimized hack of "you see me, so I see you", and then use the
4289 * actual "projectable()" function to check spell attacks.
4291 void update_view(void)
4296 int se, sw, ne, nw, es, en, ws, wn;
4300 POSITION y_max = current_floor_ptr->height - 1;
4301 POSITION x_max = current_floor_ptr->width - 1;
4305 /*** Initialize ***/
4308 if (view_reduce_view && !current_floor_ptr->dun_level)
4310 /* Full radius (10) */
4311 full = MAX_SIGHT / 2;
4313 /* Octagon factor (15) */
4314 over = MAX_SIGHT * 3 / 4;
4320 /* Full radius (20) */
4323 /* Octagon factor (30) */
4324 over = MAX_SIGHT * 3 / 2;
4328 /*** Step 0 -- Begin ***/
4330 /* Save the old "view" grids for later */
4331 for (n = 0; n < view_n; n++)
4335 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4337 /* Mark the grid as not in "view" */
4338 g_ptr->info &= ~(CAVE_VIEW);
4340 /* Mark the grid as "seen" */
4341 g_ptr->info |= (CAVE_TEMP);
4343 /* Add it to the "seen" set */
4349 /* Start over with the "view" array */
4352 /*** Step 1 -- adjacent grids ***/
4354 /* Now start on the player */
4357 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4359 /* Assume the player grid is easily viewable */
4360 g_ptr->info |= (CAVE_XTRA);
4362 /* Assume the player grid is viewable */
4363 cave_view_hack(g_ptr, y, x);
4366 /*** Step 2 -- Major Diagonals ***/
4371 /* Scan south-east */
4372 for (d = 1; d <= z; d++)
4374 g_ptr = ¤t_floor_ptr->grid_array[y + d][x + d];
4375 g_ptr->info |= (CAVE_XTRA);
4376 cave_view_hack(g_ptr, y + d, x + d);
4377 if (!cave_los_grid(g_ptr)) break;
4380 /* Scan south-west */
4381 for (d = 1; d <= z; d++)
4383 g_ptr = ¤t_floor_ptr->grid_array[y + d][x - d];
4384 g_ptr->info |= (CAVE_XTRA);
4385 cave_view_hack(g_ptr, y + d, x - d);
4386 if (!cave_los_grid(g_ptr)) break;
4389 /* Scan north-east */
4390 for (d = 1; d <= z; d++)
4392 g_ptr = ¤t_floor_ptr->grid_array[y - d][x + d];
4393 g_ptr->info |= (CAVE_XTRA);
4394 cave_view_hack(g_ptr, y - d, x + d);
4395 if (!cave_los_grid(g_ptr)) break;
4398 /* Scan north-west */
4399 for (d = 1; d <= z; d++)
4401 g_ptr = ¤t_floor_ptr->grid_array[y - d][x - d];
4402 g_ptr->info |= (CAVE_XTRA);
4403 cave_view_hack(g_ptr, y - d, x - d);
4404 if (!cave_los_grid(g_ptr)) break;
4407 /*** Step 3 -- major axes ***/
4410 for (d = 1; d <= full; d++)
4412 g_ptr = ¤t_floor_ptr->grid_array[y + d][x];
4413 g_ptr->info |= (CAVE_XTRA);
4414 cave_view_hack(g_ptr, y + d, x);
4415 if (!cave_los_grid(g_ptr)) break;
4418 /* Initialize the "south strips" */
4422 for (d = 1; d <= full; d++)
4424 g_ptr = ¤t_floor_ptr->grid_array[y - d][x];
4425 g_ptr->info |= (CAVE_XTRA);
4426 cave_view_hack(g_ptr, y - d, x);
4427 if (!cave_los_grid(g_ptr)) break;
4430 /* Initialize the "north strips" */
4434 for (d = 1; d <= full; d++)
4436 g_ptr = ¤t_floor_ptr->grid_array[y][x + d];
4437 g_ptr->info |= (CAVE_XTRA);
4438 cave_view_hack(g_ptr, y, x + d);
4439 if (!cave_los_grid(g_ptr)) break;
4442 /* Initialize the "east strips" */
4446 for (d = 1; d <= full; d++)
4448 g_ptr = ¤t_floor_ptr->grid_array[y][x - d];
4449 g_ptr->info |= (CAVE_XTRA);
4450 cave_view_hack(g_ptr, y, x - d);
4451 if (!cave_los_grid(g_ptr)) break;
4454 /* Initialize the "west strips" */
4458 /*** Step 4 -- Divide each "octant" into "strips" ***/
4460 /* Now check each "diagonal" (in parallel) */
4461 for (n = 1; n <= over / 2; n++)
4463 POSITION ypn, ymn, xpn, xmn;
4465 /* Acquire the "bounds" of the maximal circle */
4467 if (z > full - n) z = full - n;
4468 while ((z + n + (n >> 1)) > full) z--;
4471 /* Access the four diagonal grids */
4481 /* Maximum distance */
4482 m = MIN(z, y_max - ypn);
4485 if ((xpn <= x_max) && (n < se))
4488 for (k = n, d = 1; d <= m; d++)
4490 /* Check grid "d" in strip "n", notice "blockage" */
4491 if (update_view_aux(ypn + d, xpn, ypn + d - 1, xpn - 1, ypn + d - 1, xpn))
4493 if (n + d >= se) break;
4496 /* Track most distant "non-blockage" */
4503 /* Limit the next strip */
4508 if ((xmn >= 0) && (n < sw))
4511 for (k = n, d = 1; d <= m; d++)
4513 /* Check grid "d" in strip "n", notice "blockage" */
4514 if (update_view_aux(ypn + d, xmn, ypn + d - 1, xmn + 1, ypn + d - 1, xmn))
4516 if (n + d >= sw) break;
4519 /* Track most distant "non-blockage" */
4526 /* Limit the next strip */
4535 /* Maximum distance */
4539 if ((xpn <= x_max) && (n < ne))
4542 for (k = n, d = 1; d <= m; d++)
4544 /* Check grid "d" in strip "n", notice "blockage" */
4545 if (update_view_aux(ymn - d, xpn, ymn - d + 1, xpn - 1, ymn - d + 1, xpn))
4547 if (n + d >= ne) break;
4550 /* Track most distant "non-blockage" */
4557 /* Limit the next strip */
4562 if ((xmn >= 0) && (n < nw))
4565 for (k = n, d = 1; d <= m; d++)
4567 /* Check grid "d" in strip "n", notice "blockage" */
4568 if (update_view_aux(ymn - d, xmn, ymn - d + 1, xmn + 1, ymn - d + 1, xmn))
4570 if (n + d >= nw) break;
4573 /* Track most distant "non-blockage" */
4580 /* Limit the next strip */
4589 /* Maximum distance */
4590 m = MIN(z, x_max - xpn);
4593 if ((ypn <= x_max) && (n < es))
4596 for (k = n, d = 1; d <= m; d++)
4598 /* Check grid "d" in strip "n", notice "blockage" */
4599 if (update_view_aux(ypn, xpn + d, ypn - 1, xpn + d - 1, ypn, xpn + d - 1))
4601 if (n + d >= es) break;
4604 /* Track most distant "non-blockage" */
4611 /* Limit the next strip */
4616 if ((ymn >= 0) && (n < en))
4619 for (k = n, d = 1; d <= m; d++)
4621 /* Check grid "d" in strip "n", notice "blockage" */
4622 if (update_view_aux(ymn, xpn + d, ymn + 1, xpn + d - 1, ymn, xpn + d - 1))
4624 if (n + d >= en) break;
4627 /* Track most distant "non-blockage" */
4634 /* Limit the next strip */
4643 /* Maximum distance */
4647 if ((ypn <= y_max) && (n < ws))
4650 for (k = n, d = 1; d <= m; d++)
4652 /* Check grid "d" in strip "n", notice "blockage" */
4653 if (update_view_aux(ypn, xmn - d, ypn - 1, xmn - d + 1, ypn, xmn - d + 1))
4655 if (n + d >= ws) break;
4658 /* Track most distant "non-blockage" */
4665 /* Limit the next strip */
4670 if ((ymn >= 0) && (n < wn))
4673 for (k = n, d = 1; d <= m; d++)
4675 /* Check grid "d" in strip "n", notice "blockage" */
4676 if (update_view_aux(ymn, xmn - d, ymn + 1, xmn - d + 1, ymn, xmn - d + 1))
4678 if (n + d >= wn) break;
4681 /* Track most distant "non-blockage" */
4688 /* Limit the next strip */
4695 /*** Step 5 -- Complete the algorithm ***/
4697 /* Update all the new grids */
4698 for (n = 0; n < view_n; n++)
4702 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4704 /* Clear the "CAVE_XTRA" flag */
4705 g_ptr->info &= ~(CAVE_XTRA);
4707 /* Update only newly viewed grids */
4708 if (g_ptr->info & (CAVE_TEMP)) continue;
4710 /* Add it to later visual update */
4711 cave_note_and_redraw_later(g_ptr, y, x);
4714 /* Wipe the old grids, update as needed */
4715 for (n = 0; n < temp_n; n++)
4719 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4721 /* No longer in the array */
4722 g_ptr->info &= ~(CAVE_TEMP);
4724 /* Update only non-viewable grids */
4725 if (g_ptr->info & (CAVE_VIEW)) continue;
4727 /* Add it to later visual update */
4728 cave_redraw_later(g_ptr, y, x);
4734 /* Mega-Hack -- Visual update later */
4735 p_ptr->update |= (PU_DELAY_VIS);
4740 * Mega-Hack -- Delayed visual update
4741 * Only used if update_view(), update_lite() or update_mon_lite() was called
4743 void delayed_visual_update(void)
4749 /* Update needed grids */
4750 for (i = 0; i < redraw_n; i++)
4754 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4756 /* Update only needed grids (prevent multiple updating) */
4757 if (!(g_ptr->info & CAVE_REDRAW)) continue;
4759 /* If required, note */
4760 if (g_ptr->info & CAVE_NOTE) note_spot(y, x);
4764 /* Hack -- Visual update of monster on this grid */
4765 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
4767 /* No longer in the array */
4768 g_ptr->info &= ~(CAVE_NOTE | CAVE_REDRAW);
4777 * Hack -- forget the "flow" information
4779 void forget_flow(void)
4783 /* Check the entire dungeon */
4784 for (y = 0; y < current_floor_ptr->height; y++)
4786 for (x = 0; x < current_floor_ptr->width; x++)
4788 /* Forget the old data */
4789 current_floor_ptr->grid_array[y][x].dist = 0;
4790 current_floor_ptr->grid_array[y][x].cost = 0;
4791 current_floor_ptr->grid_array[y][x].when = 0;
4798 * Hack - speed up the update_flow algorithm by only doing
4799 * it everytime the player moves out of LOS of the last
4802 static POSITION flow_x = 0;
4803 static POSITION flow_y = 0;
4808 * Hack -- fill in the "cost" field of every grid that the player
4809 * can "reach" with the number of steps needed to reach that grid.
4810 * This also yields the "distance" of the player from every grid.
4812 * In addition, mark the "when" of the grids that can reach
4813 * the player with the incremented value of "flow_n".
4815 * Hack -- use the "seen" array as a "circular queue".
4817 * We do not need a priority queue because the cost from grid
4818 * to grid is always "one" and we process them in order.
4820 void update_flow(void)
4827 /* Paranoia -- make sure the array is empty */
4830 /* The last way-point is on the map */
4831 if (running && in_bounds(flow_y, flow_x))
4833 /* The way point is in sight - do not update. (Speedup) */
4834 if (current_floor_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) return;
4837 /* Erase all of the current flow information */
4838 for (y = 0; y < current_floor_ptr->height; y++)
4840 for (x = 0; x < current_floor_ptr->width; x++)
4842 current_floor_ptr->grid_array[y][x].cost = 0;
4843 current_floor_ptr->grid_array[y][x].dist = 0;
4847 /* Save player position */
4851 /* Add the player's grid to the queue */
4852 temp_y[0] = p_ptr->y;
4853 temp_x[0] = p_ptr->x;
4855 /* Now process the queue */
4856 while (flow_head != flow_tail)
4860 /* Extract the next entry */
4861 ty = temp_y[flow_tail];
4862 tx = temp_x[flow_tail];
4864 /* Forget that entry */
4865 if (++flow_tail == TEMP_MAX) flow_tail = 0;
4867 /* Add the "children" */
4868 for (d = 0; d < 8; d++)
4870 int old_head = flow_head;
4871 byte_hack m = current_floor_ptr->grid_array[ty][tx].cost + 1;
4872 byte_hack n = current_floor_ptr->grid_array[ty][tx].dist + 1;
4875 /* Child location */
4876 y = ty + ddy_ddd[d];
4877 x = tx + ddx_ddd[d];
4879 /* Ignore player's grid */
4880 if (player_bold(y, x)) continue;
4882 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4884 if (is_closed_door(g_ptr->feat)) m += 3;
4886 /* Ignore "pre-stamped" entries */
4887 if (g_ptr->dist != 0 && g_ptr->dist <= n && g_ptr->cost <= m) continue;
4889 /* Ignore "walls" and "rubble" */
4890 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
4892 /* Save the flow cost */
4893 if (g_ptr->cost == 0 || g_ptr->cost > m) g_ptr->cost = m;
4894 if (g_ptr->dist == 0 || g_ptr->dist > n) g_ptr->dist = n;
4896 /* Hack -- limit flow depth */
4897 if (n == MONSTER_FLOW_DEPTH) continue;
4899 /* Enqueue that entry */
4900 temp_y[flow_head] = y;
4901 temp_x[flow_head] = x;
4903 /* Advance the queue */
4904 if (++flow_head == TEMP_MAX) flow_head = 0;
4906 /* Hack -- notice overflow by forgetting new entry */
4907 if (flow_head == flow_tail) flow_head = old_head;
4913 static int scent_when = 0;
4916 * Characters leave scent trails for perceptive monsters to track.
4918 * Smell is rather more limited than sound. Many creatures cannot use
4919 * it at all, it doesn't extend very far outwards from the character's
4920 * current position, and monsters can use it to home in the character,
4921 * but not to run away from him.
4923 * Smell is valued according to age. When a character takes his current_world_ptr->game_turn,
4924 * scent is aged by one, and new scent of the current age is laid down.
4925 * Speedy characters leave more scent, true, but it also ages faster,
4926 * which makes it harder to hunt them down.
4928 * Whenever the age count loops, most of the scent trail is erased and
4929 * the age of the remainder is recalculated.
4931 void update_smell(void)
4936 /* Create a table that controls the spread of scent */
4937 const int scent_adjust[5][5] =
4946 /* Loop the age and adjust scent values when necessary */
4947 if (++scent_when == 254)
4949 /* Scan the entire dungeon */
4950 for (y = 0; y < current_floor_ptr->height; y++)
4952 for (x = 0; x < current_floor_ptr->width; x++)
4954 int w = current_floor_ptr->grid_array[y][x].when;
4955 current_floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
4964 /* Lay down new scent */
4965 for (i = 0; i < 5; i++)
4967 for (j = 0; j < 5; j++)
4971 /* Translate table to map grids */
4972 y = i + p_ptr->y - 2;
4973 x = j + p_ptr->x - 2;
4976 if (!in_bounds(y, x)) continue;
4978 g_ptr = ¤t_floor_ptr->grid_array[y][x];
4980 /* Walls, water, and lava cannot hold scent. */
4981 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(g_ptr->feat)) continue;
4983 /* Grid must not be blocked by walls from the character */
4984 if (!player_has_los_bold(y, x)) continue;
4986 /* Note grids that are too far away */
4987 if (scent_adjust[i][j] == -1) continue;
4989 /* Mark the grid with new scent */
4990 g_ptr->when = scent_when + scent_adjust[i][j];
4997 * Hack -- map the current panel (plus some) ala "magic mapping"
4999 void map_area(POSITION range)
5005 feature_type *f_ptr;
5007 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) range /= 3;
5009 /* Scan that area */
5010 for (y = 1; y < current_floor_ptr->height - 1; y++)
5012 for (x = 1; x < current_floor_ptr->width - 1; x++)
5014 if (distance(p_ptr->y, p_ptr->x, y, x) > range) continue;
5016 g_ptr = ¤t_floor_ptr->grid_array[y][x];
5018 /* Memorize terrain of the grid */
5019 g_ptr->info |= (CAVE_KNOWN);
5021 /* Feature code (applying "mimic" field) */
5022 feat = get_feat_mimic(g_ptr);
5023 f_ptr = &f_info[feat];
5025 /* All non-walls are "checked" */
5026 if (!have_flag(f_ptr->flags, FF_WALL))
5028 /* Memorize normal features */
5029 if (have_flag(f_ptr->flags, FF_REMEMBER))
5031 /* Memorize the object */
5032 g_ptr->info |= (CAVE_MARK);
5035 /* Memorize known walls */
5036 for (i = 0; i < 8; i++)
5038 g_ptr = ¤t_floor_ptr->grid_array[y + ddy_ddd[i]][x + ddx_ddd[i]];
5040 /* Feature code (applying "mimic" field) */
5041 feat = get_feat_mimic(g_ptr);
5042 f_ptr = &f_info[feat];
5044 /* Memorize walls (etc) */
5045 if (have_flag(f_ptr->flags, FF_REMEMBER))
5047 /* Memorize the walls */
5048 g_ptr->info |= (CAVE_MARK);
5055 p_ptr->redraw |= (PR_MAP);
5057 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
5062 * Change the "feat" flag for a grid, and notice/redraw the grid
5064 void cave_set_feat(POSITION y, POSITION x, FEAT_IDX feat)
5066 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5067 feature_type *f_ptr = &f_info[feat];
5068 bool old_los, old_mirror;
5070 if (!character_dungeon)
5072 /* Clear mimic type */
5075 /* Change the feature */
5078 /* Hack -- glow the GLOW terrain */
5079 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
5084 for (i = 0; i < 9; i++)
5086 yy = y + ddy_ddd[i];
5087 xx = x + ddx_ddd[i];
5088 if (!in_bounds2(yy, xx)) continue;
5089 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
5096 old_los = cave_have_flag_bold(y, x, FF_LOS);
5097 old_mirror = is_mirror_grid(g_ptr);
5099 /* Clear mimic type */
5102 /* Change the feature */
5105 /* Remove flag for mirror/glyph */
5106 g_ptr->info &= ~(CAVE_OBJECT);
5108 if (old_mirror && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
5110 g_ptr->info &= ~(CAVE_GLOW);
5111 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
5113 update_local_illumination(y, x);
5116 /* Check for change to boring grid */
5117 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
5118 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
5124 /* Check if los has changed */
5125 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
5128 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
5130 update_local_illumination(y, x);
5132 #endif /* COMPLEX_WALL_ILLUMINATION */
5134 /* Update the visuals */
5135 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
5138 /* Hack -- glow the GLOW terrain */
5139 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
5145 for (i = 0; i < 9; i++)
5147 yy = y + ddy_ddd[i];
5148 xx = x + ddx_ddd[i];
5149 if (!in_bounds2(yy, xx)) continue;
5150 cc_ptr = ¤t_floor_ptr->grid_array[yy][xx];
5151 cc_ptr->info |= CAVE_GLOW;
5153 if (player_has_los_grid(cc_ptr))
5155 if (cc_ptr->m_idx) update_monster(cc_ptr->m_idx, FALSE);
5162 update_local_illumination(yy, xx);
5165 if (p_ptr->special_defense & NINJA_S_STEALTH)
5167 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
5173 FEAT_IDX conv_dungeon_feat(FEAT_IDX newfeat)
5175 feature_type *f_ptr = &f_info[newfeat];
5177 if (have_flag(f_ptr->flags, FF_CONVERT))
5179 switch (f_ptr->subtype)
5181 case CONVERT_TYPE_FLOOR:
5182 return feat_ground_type[randint0(100)];
5183 case CONVERT_TYPE_WALL:
5184 return feat_wall_type[randint0(100)];
5185 case CONVERT_TYPE_INNER:
5186 return feat_wall_inner;
5187 case CONVERT_TYPE_OUTER:
5188 return feat_wall_outer;
5189 case CONVERT_TYPE_SOLID:
5190 return feat_wall_solid;
5191 case CONVERT_TYPE_STREAM1:
5192 return d_info[p_ptr->dungeon_idx].stream1;
5193 case CONVERT_TYPE_STREAM2:
5194 return d_info[p_ptr->dungeon_idx].stream2;
5199 else return newfeat;
5204 * Take a feature, determine what that feature becomes
5205 * through applying the given action.
5207 FEAT_IDX feat_state(FEAT_IDX feat, int action)
5209 feature_type *f_ptr = &f_info[feat];
5212 /* Get the new feature */
5213 for (i = 0; i < MAX_FEAT_STATES; i++)
5215 if (f_ptr->state[i].action == action) return conv_dungeon_feat(f_ptr->state[i].result);
5218 if (have_flag(f_ptr->flags, FF_PERMANENT)) return feat;
5220 return (feature_action_flags[action] & FAF_DESTROY) ? conv_dungeon_feat(f_ptr->destroyed) : feat;
5224 * Takes a location and action and changes the feature at that
5225 * location through applying the given action.
5227 void cave_alter_feat(POSITION y, POSITION x, int action)
5229 /* Set old feature */
5230 FEAT_IDX oldfeat = current_floor_ptr->grid_array[y][x].feat;
5232 /* Get the new feat */
5233 FEAT_IDX newfeat = feat_state(oldfeat, action);
5236 if (newfeat == oldfeat) return;
5238 /* Set the new feature */
5239 cave_set_feat(y, x, newfeat);
5241 if (!(feature_action_flags[action] & FAF_NO_DROP))
5243 feature_type *old_f_ptr = &f_info[oldfeat];
5244 feature_type *f_ptr = &f_info[newfeat];
5248 if (have_flag(old_f_ptr->flags, FF_HAS_GOLD) && !have_flag(f_ptr->flags, FF_HAS_GOLD))
5250 /* Place some gold */
5256 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)))
5259 place_object(y, x, 0L);
5263 if (found && character_dungeon && player_can_see_bold(y, x))
5265 msg_print(_("何かを発見した!", "You have found something!"));
5269 if (feature_action_flags[action] & FAF_CRASH_GLASS)
5271 feature_type *old_f_ptr = &f_info[oldfeat];
5273 if (have_flag(old_f_ptr->flags, FF_GLASS) && character_dungeon)
5275 project(PROJECT_WHO_GLASS_SHARDS, 1, y, x, MIN(current_floor_ptr->dun_level, 100) / 4, GF_SHARDS,
5276 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
5282 /* Remove a mirror */
5283 void remove_mirror(POSITION y, POSITION x)
5285 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5287 /* Remove the mirror */
5288 g_ptr->info &= ~(CAVE_OBJECT);
5291 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)
5293 g_ptr->info &= ~(CAVE_GLOW);
5294 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
5295 if (g_ptr->m_idx) update_monster(g_ptr->m_idx, FALSE);
5297 update_local_illumination(y, x);
5307 * Return TRUE if there is a mirror on the grid.
5309 bool is_mirror_grid(grid_type *g_ptr)
5311 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MIRROR))
5319 * Return TRUE if there is a mirror on the grid.
5321 bool is_glyph_grid(grid_type *g_ptr)
5323 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_GLYPH))
5331 * Return TRUE if there is a mirror on the grid.
5333 bool is_explosive_rune_grid(grid_type *g_ptr)
5335 if ((g_ptr->info & CAVE_OBJECT) && have_flag(f_info[g_ptr->mimic].flags, FF_MINOR_GLYPH))
5343 * Calculate "incremental motion". Used by project() and shoot().
5344 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
5346 void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
5348 POSITION dy, dx, dist, shift;
5350 /* Extract the distance travelled */
5351 dy = (*y < y1) ? y1 - *y : *y - y1;
5352 dx = (*x < x1) ? x1 - *x : *x - x1;
5354 /* Number of steps */
5355 dist = (dy > dx) ? dy : dx;
5357 /* We are calculating the next location */
5361 /* Calculate the total distance along each axis */
5362 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
5363 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
5365 /* Paranoia -- Hack -- no motion */
5366 if (!dy && !dx) return;
5369 /* Move mostly vertically */
5372 /* Extract a shift factor */
5373 shift = (dist * dx + (dy - 1) / 2) / dy;
5375 /* Sometimes move along the minor axis */
5376 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
5378 /* Always move along major axis */
5379 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
5382 /* Move mostly horizontally */
5385 /* Extract a shift factor */
5386 shift = (dist * dy + (dx - 1) / 2) / dx;
5388 /* Sometimes move along the minor axis */
5389 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
5391 /* Always move along major axis */
5392 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
5399 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
5400 * at the final destination, assuming no monster gets in the way.
5402 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
5404 bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
5411 /* Check the projection path */
5412 grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
5414 /* Identical grid */
5415 if (!grid_n) return TRUE;
5418 y = GRID_Y(grid_g[grid_n - 1]);
5419 x = GRID_X(grid_g[grid_n - 1]);
5421 /* May not end in an unrequested grid */
5422 if ((y != y2) || (x != x2)) return (FALSE);
5430 * Standard "find me a location" function
5432 * Obtains a legal location within the given distance of the initial
5433 * location, and with "los()" from the source to destination location.
5435 * This function is often called from inside a loop which searches for
5436 * locations while increasing the "d" distance.
5438 * Currently the "m" parameter is unused.
5440 void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
5444 /* Pick a location */
5447 /* Pick a new location */
5448 ny = rand_spread(y, d);
5449 nx = rand_spread(x, d);
5451 /* Ignore annoying locations */
5452 if (!in_bounds(ny, nx)) continue;
5454 /* Ignore "excessively distant" locations */
5455 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
5457 if (mode & PROJECT_LOS)
5459 if (los(y, x, ny, nx)) break;
5463 if (projectable(y, x, ny, nx)) break;
5468 /* Save the location */
5477 * Track a new monster
5479 void health_track(MONSTER_IDX m_idx)
5481 /* Mount monster is already tracked */
5482 if (m_idx && m_idx == p_ptr->riding) return;
5484 /* Track a new guy */
5485 p_ptr->health_who = m_idx;
5487 /* Redraw (later) */
5488 p_ptr->redraw |= (PR_HEALTH);
5494 * Hack -- track the given monster race
5496 void monster_race_track(MONRACE_IDX r_idx)
5498 /* Save this monster ID */
5499 p_ptr->monster_race_idx = r_idx;
5501 p_ptr->window |= (PW_MONSTER);
5507 * Hack -- track the given object kind
5509 void object_kind_track(KIND_OBJECT_IDX k_idx)
5511 /* Save this monster ID */
5512 p_ptr->object_kind_idx = k_idx;
5514 p_ptr->window |= (PW_OBJECT);
5520 * Something has happened to disturb the player.
5522 * The first arg indicates a major disturbance, which affects search.
5524 * The second arg is currently unused, but could induce output flush.
5526 * All disturbance cancels repeated commands, resting, and running.
5528 void disturb(bool stop_search, bool stop_travel)
5532 stop_travel = stop_travel;
5535 /* Cancel auto-commands */
5536 /* command_new = 0; */
5538 /* Cancel repeated commands */
5544 /* Redraw the state (later) */
5545 p_ptr->redraw |= (PR_STATE);
5548 /* Cancel Resting */
5549 if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
5552 set_action(ACTION_NONE);
5555 /* Cancel running */
5561 /* Check for new panel if appropriate */
5562 if (center_player && !center_running) verify_panel();
5564 /* Calculate torch radius */
5565 p_ptr->update |= (PU_TORCH);
5567 /* Update monster flow */
5568 p_ptr->update |= (PU_FLOW);
5577 /* Check for new panel if appropriate */
5578 if (center_player && !center_running) verify_panel();
5580 /* Calculate torch radius */
5581 p_ptr->update |= (PU_TORCH);
5585 /* Flush the input if requested */
5586 if (flush_disturb) flush();
5591 * Glow deep lava and building entrances in the floor
5593 void glow_deep_lava_and_bldg(void)
5595 POSITION y, x, yy, xx;
5599 /* Not in the darkness dungeon */
5600 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) return;
5602 for (y = 0; y < current_floor_ptr->height; y++)
5604 for (x = 0; x < current_floor_ptr->width; x++)
5606 g_ptr = ¤t_floor_ptr->grid_array[y][x];
5608 /* Feature code (applying "mimic" field) */
5610 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_GLOW))
5612 for (i = 0; i < 9; i++)
5614 yy = y + ddy_ddd[i];
5615 xx = x + ddx_ddd[i];
5616 if (!in_bounds2(yy, xx)) continue;
5617 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
5623 /* Update the view and lite */
5624 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
5626 p_ptr->redraw |= (PR_MAP);
5630 * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
5631 * @param m_idx モンスターID
5635 * @return テレポート先として妥当ならばtrue
5637 bool cave_monster_teleportable_bold(MONSTER_IDX m_idx, POSITION y, POSITION x, BIT_FLAGS mode)
5639 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
5640 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5641 feature_type *f_ptr = &f_info[g_ptr->feat];
5643 /* Require "teleportable" space */
5644 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5646 if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) return FALSE;
5647 if (player_bold(y, x)) return FALSE;
5649 /* Hack -- no teleport onto glyph of warding */
5650 if (is_glyph_grid(g_ptr)) return FALSE;
5651 if (is_explosive_rune_grid(g_ptr)) return FALSE;
5653 if (!(mode & TELEPORT_PASSIVE))
5655 if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
5662 * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
5666 * @return テレポート先として妥当ならばtrue
5668 bool cave_player_teleportable_bold(POSITION y, POSITION x, BIT_FLAGS mode)
5670 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
5671 feature_type *f_ptr = &f_info[g_ptr->feat];
5673 /* Require "teleportable" space */
5674 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
5676 /* No magical teleporting into vaults and such */
5677 if (!(mode & TELEPORT_NONMAGICAL) && (g_ptr->info & CAVE_ICKY)) return FALSE;
5679 if (g_ptr->m_idx && (g_ptr->m_idx != p_ptr->riding)) return FALSE;
5681 /* don't teleport on a trap. */
5682 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) return FALSE;
5684 if (!(mode & TELEPORT_PASSIVE))
5686 if (!player_can_enter(g_ptr->feat, 0)) return FALSE;
5688 if (have_flag(f_ptr->flags, FF_WATER) && have_flag(f_ptr->flags, FF_DEEP))
5690 if (!p_ptr->levitation && !p_ptr->can_swim) return FALSE;
5693 if (have_flag(f_ptr->flags, FF_LAVA) && !p_ptr->immune_fire && !IS_INVULN())
5695 /* Always forbid deep lava */
5696 if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
5698 /* Forbid shallow lava when the player don't have levitation */
5699 if (!p_ptr->levitation) return FALSE;
5708 * @brief 地形は開くものであって、かつ開かれているかを返す /
5709 * Attempt to open the given chest at the given location
5711 * @return 開いた地形である場合TRUEを返す / Return TRUE if the given feature is an open door
5713 bool is_open(FEAT_IDX feat)
5715 return have_flag(f_info[feat].flags, FF_CLOSE) && (feat != feat_state(feat, FF_CLOSE));