OSDN Git Service

[Refactor] #40571 Separated target-preparation.c/h from targeting.c/h
authorHourier <hourier@users.sourceforge.jp>
Sat, 25 Jul 2020 02:21:22 +0000 (11:21 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 25 Jul 2020 02:21:22 +0000 (11:21 +0900)
19 files changed:
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/floor/floor.c
src/io/cursor.c
src/mind/mind-mirror-master.c
src/mspell/mspell-attack.c
src/mspell/mspell-checker.c
src/mspell/mspell-judgement.c
src/mspell/mspell-lite.c
src/spell-kind/spells-fetcher.c
src/spell-kind/spells-lite.c
src/spell-realm/spells-crusade.c
src/spell/process-effect.c
src/target/target-preparation.c [new file with mode: 0644]
src/target/target-preparation.h [new file with mode: 0644]
src/target/targeting.c
src/target/targeting.h
src/window/display-sub-windows.c

index 59a842e..37c9bbf 100644 (file)
     <ClCompile Include="..\..\src\store\service-checker.c" />\r
     <ClCompile Include="..\..\src\system\dungeon-data-definition.c" />\r
     <ClCompile Include="..\..\src\target\target-describer.c" />\r
+    <ClCompile Include="..\..\src\target\target-preparation.c" />\r
     <ClCompile Include="..\..\src\view\display-inventory.c" />\r
     <ClCompile Include="..\..\src\view\display-map.c" />\r
     <ClCompile Include="..\..\src\window\display-sub-window-items.c" />\r
     <ClInclude Include="..\..\src\system\dungeon-data-definition.h" />\r
     <ClInclude Include="..\..\src\system\floor-type-definition.h" />\r
     <ClInclude Include="..\..\src\target\target-describer.h" />\r
+    <ClInclude Include="..\..\src\target\target-preparation.h" />\r
     <ClInclude Include="..\..\src\target\target-types.h" />\r
     <ClInclude Include="..\..\src\term\screen-processor.h" />\r
     <ClInclude Include="..\..\src\util\bit-flags-calculator.h" />\r
index 4891b91..92da5cb 100644 (file)
     <ClCompile Include="..\..\src\target\target-describer.c">
       <Filter>target</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\target\target-preparation.c">
+      <Filter>target</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\combat\shoot.h">
     <ClInclude Include="..\..\src\target\target-describer.h">
       <Filter>target</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\target\target-preparation.h">
+      <Filter>target</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 9bdc15f..2a7bcf4 100644 (file)
@@ -731,6 +731,7 @@ hengband_SOURCES = \
        system/gamevalue.h \
        \
        target/target-describer.c target/target-describer.h \
+       target/target-preparation.c target/target-preparation.h \
        target/target-types.h \
        target/targeting.c target/targeting.h \
        \
index 84f0c0b..b4cdf69 100644 (file)
@@ -18,8 +18,8 @@
 #include "mind/mind-ninja.h"
 #include "monster-floor/monster-generator.h"
 #include "monster-floor/monster-remover.h"
-#include "monster/monster-update.h"
 #include "monster-floor/place-monster-types.h"
+#include "monster/monster-update.h"
 #include "object-enchant/special-object-flags.h"
 #include "object-hook/hook-checker.h"
 #include "object-hook/hook-enchant.h"
@@ -30,7 +30,7 @@
 #include "room/door-definition.h"
 #include "system/artifact-type-definition.h"
 #include "system/floor-type-definition.h"
-#include "target/targeting.h"
+#include "target/target-preparation.h" // todo 相互依存.
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 #include "world/world-object.h"
@@ -48,83 +48,71 @@ floor_type floor_info;
  */
 bool is_cave_empty_grid(player_type *player_ptr, grid_type *g_ptr)
 {
-       bool is_empty_grid = cave_have_flag_grid(g_ptr, FF_PLACE);
-       is_empty_grid &= g_ptr->m_idx == 0;
-       is_empty_grid &= !player_grid(player_ptr, g_ptr);
-       return is_empty_grid;
-}
-
-
-bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x)
-{
-       return cave_have_flag_bold(floor_ptr, y, x, FF_PATTERN);
+    bool is_empty_grid = cave_have_flag_grid(g_ptr, FF_PLACE);
+    is_empty_grid &= g_ptr->m_idx == 0;
+    is_empty_grid &= !player_grid(player_ptr, g_ptr);
+    return is_empty_grid;
 }
 
+bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x) { return cave_have_flag_bold(floor_ptr, y, x, FF_PATTERN); }
 
 /*!
-* @brief 鍵のかかったドアを配置する
-* @param player_ptr プレーヤーへの参照ポインタ
-* @param y 配置したいフロアのY座標
-* @param x 配置したいフロアのX座標
-* @return なし
-*/
+ * @brief 鍵のかかったドアを配置する
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param y 配置したいフロアのY座標
+ * @param x 配置したいフロアのX座標
+ * @return なし
+ */
 void place_locked_door(player_type *player_ptr, POSITION y, POSITION x)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
-       {
-               place_bold(player_ptr, y, x, GB_FLOOR);
-               return;
-       }
-
-       set_cave_feat(floor_ptr, y, x, feat_locked_door_random((d_info[player_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
-       floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
-       delete_monster(player_ptr, y, x);
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) {
+        place_bold(player_ptr, y, x, GB_FLOOR);
+        return;
+    }
+
+    set_cave_feat(floor_ptr, y, x, feat_locked_door_random((d_info[player_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
+    floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
+    delete_monster(player_ptr, y, x);
 }
 
-
 /*!
-* @brief 隠しドアを配置する
-* @param player_ptr プレーヤーへの参照ポインタ
-* @param y 配置したいフロアのY座標
-* @param x 配置したいフロアのX座標
-* @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
-* @return なし
-*/
+ * @brief 隠しドアを配置する
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param y 配置したいフロアのY座標
+ * @param x 配置したいフロアのX座標
+ * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
+ * @return なし
+ */
 void place_secret_door(player_type *player_ptr, POSITION y, POSITION x, int type)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
-       {
-               place_bold(player_ptr, y, x, GB_FLOOR);
-               return;
-       }
-
-       if (type == DOOR_DEFAULT)
-       {
-               type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
-                       one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
-                       ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
-       }
-
-       place_closed_door(player_ptr, y, x, type);
-       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
-       if (type != DOOR_CURTAIN)
-       {
-               g_ptr->mimic = feat_wall_inner;
-               if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
-               {
-                       if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
-                       {
-                               g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
-                       }
-
-                       g_ptr->mimic = 0;
-               }
-       }
-
-       g_ptr->info &= ~(CAVE_FLOOR);
-       delete_monster(player_ptr, y, x);
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) {
+        place_bold(player_ptr, y, x, GB_FLOOR);
+        return;
+    }
+
+    if (type == DOOR_DEFAULT) {
+        type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) && one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256))
+            ? DOOR_CURTAIN
+            : ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
+    }
+
+    place_closed_door(player_ptr, y, x, type);
+    grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+    if (type != DOOR_CURTAIN) {
+        g_ptr->mimic = feat_wall_inner;
+        if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat)) {
+            if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY)) {
+                g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
+            }
+
+            g_ptr->mimic = 0;
+        }
+    }
+
+    g_ptr->info &= ~(CAVE_FLOOR);
+    delete_monster(player_ptr, y, x);
 }
 
 static int scent_when = 0;
@@ -147,67 +135,61 @@ static int scent_when = 0;
  */
 void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
 {
-       /* Create a table that controls the spread of scent */
-       const int scent_adjust[5][5] =
-       {
-               { -1, 0, 0, 0,-1 },
-               {  0, 1, 1, 1, 0 },
-               {  0, 1, 2, 1, 0 },
-               {  0, 1, 1, 1, 0 },
-               { -1, 0, 0, 0,-1 },
-       };
-
-       if (++scent_when == 254)
-       {
-               for (POSITION y = 0; y < floor_ptr->height; y++)
-               {
-                       for (POSITION x = 0; x < floor_ptr->width; x++)
-                       {
-                               int w = floor_ptr->grid_array[y][x].when;
-                               floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
-                       }
-               }
-
-               scent_when = 126;
-       }
-
-       for (POSITION i = 0; i < 5; i++)
-       {
-               for (POSITION j = 0; j < 5; j++)
-               {
-                       grid_type *g_ptr;
-                       POSITION y = i + subject_ptr->y - 2;
-                       POSITION x = j + subject_ptr->x - 2;
-                       if (!in_bounds(floor_ptr, y, x)) continue;
-
-                       g_ptr = &floor_ptr->grid_array[y][x];
-                       if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(subject_ptr, g_ptr->feat)) continue;
-                       if (!player_has_los_bold(subject_ptr, y, x)) continue;
-                       if (scent_adjust[i][j] == -1) continue;
-
-                       g_ptr->when = scent_when + scent_adjust[i][j];
-               }
-       }
+    /* Create a table that controls the spread of scent */
+    const int scent_adjust[5][5] = {
+        { -1, 0, 0, 0, -1 },
+        { 0, 1, 1, 1, 0 },
+        { 0, 1, 2, 1, 0 },
+        { 0, 1, 1, 1, 0 },
+        { -1, 0, 0, 0, -1 },
+    };
+
+    if (++scent_when == 254) {
+        for (POSITION y = 0; y < floor_ptr->height; y++) {
+            for (POSITION x = 0; x < floor_ptr->width; x++) {
+                int w = floor_ptr->grid_array[y][x].when;
+                floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
+            }
+        }
+
+        scent_when = 126;
+    }
+
+    for (POSITION i = 0; i < 5; i++) {
+        for (POSITION j = 0; j < 5; j++) {
+            grid_type *g_ptr;
+            POSITION y = i + subject_ptr->y - 2;
+            POSITION x = j + subject_ptr->x - 2;
+            if (!in_bounds(floor_ptr, y, x))
+                continue;
+
+            g_ptr = &floor_ptr->grid_array[y][x];
+            if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(subject_ptr, g_ptr->feat))
+                continue;
+            if (!player_has_los_bold(subject_ptr, y, x))
+                continue;
+            if (scent_adjust[i][j] == -1)
+                continue;
+
+            g_ptr->when = scent_when + scent_adjust[i][j];
+        }
+    }
 }
 
-
 /*
  * Hack -- forget the "flow" information
  */
 void forget_flow(floor_type *floor_ptr)
 {
-       for (POSITION y = 0; y < floor_ptr->height; y++)
-       {
-               for (POSITION x = 0; x < floor_ptr->width; x++)
-               {
-                       floor_ptr->grid_array[y][x].dist = 0;
-                       floor_ptr->grid_array[y][x].cost = 0;
-                       floor_ptr->grid_array[y][x].when = 0;
-               }
-       }
+    for (POSITION y = 0; y < floor_ptr->height; y++) {
+        for (POSITION x = 0; x < floor_ptr->width; x++) {
+            floor_ptr->grid_array[y][x].dist = 0;
+            floor_ptr->grid_array[y][x].cost = 0;
+            floor_ptr->grid_array[y][x].when = 0;
+        }
+    }
 }
 
-
 /*
  * Routine used by the random vault creators to add a door to a location
  * Note that range checking has to be done in the calling routine.
@@ -216,44 +198,41 @@ void forget_flow(floor_type *floor_ptr)
  */
 void add_door(player_type *player_ptr, POSITION x, POSITION y)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       if (!is_outer_bold(floor_ptr, y, x)) return;
-
-       /* look at:
-       *  x#x
-       *  .#.
-       *  x#x
-       *
-       *  where x=don't care
-       *  .=floor, #=wall
-       */
-
-       if (is_floor_bold(floor_ptr, y - 1, x) && is_floor_bold(floor_ptr, y + 1, x) &&
-               (is_outer_bold(floor_ptr, y, x - 1) && is_outer_bold(floor_ptr, y, x + 1)))
-       {
-               place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
-               place_bold(player_ptr, y, x - 1, GB_SOLID);
-               place_bold(player_ptr, y, x + 1, GB_SOLID);
-       }
-
-       /* look at:
-       *  x#x
-       *  .#.
-       *  x#x
-       *
-       *  where x = don't care
-       *  .=floor, #=wall
-       */
-       if (is_outer_bold(floor_ptr, y - 1, x) && is_outer_bold(floor_ptr, y + 1, x) &&
-               is_floor_bold(floor_ptr, y, x - 1) && is_floor_bold(floor_ptr, y, x + 1))
-       {
-               place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
-               place_bold(player_ptr, y - 1, x, GB_SOLID);
-               place_bold(player_ptr, y + 1, x, GB_SOLID);
-       }
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    if (!is_outer_bold(floor_ptr, y, x))
+        return;
+
+    /* look at:
+     *  x#x
+     *  .#.
+     *  x#x
+     *
+     *  where x=don't care
+     *  .=floor, #=wall
+     */
+
+    if (is_floor_bold(floor_ptr, y - 1, x) && is_floor_bold(floor_ptr, y + 1, x)
+        && (is_outer_bold(floor_ptr, y, x - 1) && is_outer_bold(floor_ptr, y, x + 1))) {
+        place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
+        place_bold(player_ptr, y, x - 1, GB_SOLID);
+        place_bold(player_ptr, y, x + 1, GB_SOLID);
+    }
+
+    /* look at:
+     *  x#x
+     *  .#.
+     *  x#x
+     *
+     *  where x = don't care
+     *  .=floor, #=wall
+     */
+    if (is_outer_bold(floor_ptr, y - 1, x) && is_outer_bold(floor_ptr, y + 1, x) && is_floor_bold(floor_ptr, y, x - 1) && is_floor_bold(floor_ptr, y, x + 1)) {
+        place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
+        place_bold(player_ptr, y - 1, x, GB_SOLID);
+        place_bold(player_ptr, y + 1, x, GB_SOLID);
+    }
 }
 
-
 /*!
  * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -263,29 +242,36 @@ void add_door(player_type *player_ptr, POSITION x, POSITION y)
  */
 void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
 {
-       bool up_stairs = TRUE;
-       bool down_stairs = TRUE;
-       grid_type *g_ptr;
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       g_ptr = &floor_ptr->grid_array[y][x];
-       if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
-
-       if (!floor_ptr->dun_level) up_stairs = FALSE;
-       if (ironman_downward) up_stairs = FALSE;
-       if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
-       if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1)) down_stairs = FALSE;
-
-       if (down_stairs && up_stairs)
-       {
-               if (randint0(100) < 50) up_stairs = FALSE;
-               else down_stairs = FALSE;
-       }
-
-       if (up_stairs) set_cave_feat(floor_ptr, y, x, feat_up_stair);
-       else if (down_stairs) set_cave_feat(floor_ptr, y, x, feat_down_stair);
+    bool up_stairs = TRUE;
+    bool down_stairs = TRUE;
+    grid_type *g_ptr;
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    g_ptr = &floor_ptr->grid_array[y][x];
+    if (!is_floor_grid(g_ptr) || g_ptr->o_idx)
+        return;
+
+    if (!floor_ptr->dun_level)
+        up_stairs = FALSE;
+    if (ironman_downward)
+        up_stairs = FALSE;
+    if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth)
+        down_stairs = FALSE;
+    if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1))
+        down_stairs = FALSE;
+
+    if (down_stairs && up_stairs) {
+        if (randint0(100) < 50)
+            up_stairs = FALSE;
+        else
+            down_stairs = FALSE;
+    }
+
+    if (up_stairs)
+        set_cave_feat(floor_ptr, y, x, feat_up_stair);
+    else if (down_stairs)
+        set_cave_feat(floor_ptr, y, x, feat_down_stair);
 }
 
-
 /*!
  * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -331,177 +317,159 @@ void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
  */
 bool los(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
 {
-       POSITION dy = y2 - y1;
-       POSITION dx = x2 - x1;
-       POSITION ay = ABS(dy);
-       POSITION ax = ABS(dx);
-       if ((ax < 2) && (ay < 2)) return TRUE;
-
-       /* Directly South/North */
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       POSITION tx, ty;
-       if (!dx)
-       {
-               /* South -- check for walls */
-               if (dy > 0)
-               {
-                       for (ty = y1 + 1; ty < y2; ty++)
-                       {
-                               if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
-                       }
-               }
-
-               /* North -- check for walls */
-               else
-               {
-                       for (ty = y1 - 1; ty > y2; ty--)
-                       {
-                               if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
-                       }
-               }
-
-               /* Assume los */
-               return TRUE;
-       }
-
-       /* Directly East/West */
-       if (!dy)
-       {
-               /* East -- check for walls */
-               if (dx > 0)
-               {
-                       for (tx = x1 + 1; tx < x2; tx++)
-                       {
-                               if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
-                       }
-               }
-
-               /* West -- check for walls */
-               else
-               {
-                       for (tx = x1 - 1; tx > x2; tx--)
-                       {
-                               if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
-                       }
-               }
-
-               return TRUE;
-       }
-
-       POSITION sx = (dx < 0) ? -1 : 1;
-       POSITION sy = (dy < 0) ? -1 : 1;
-
-       if (ax == 1)
-       {
-               if (ay == 2)
-               {
-                       if (cave_los_bold(floor_ptr, y1 + sy, x1)) return TRUE;
-               }
-       }
-       else if (ay == 1)
-       {
-               if (ax == 2)
-               {
-                       if (cave_los_bold(floor_ptr, y1, x1 + sx)) return TRUE;
-               }
-       }
-
-       POSITION f2 = (ax * ay);
-       POSITION f1 = f2 << 1;
-       POSITION qy;
-       POSITION m;
-       if (ax >= ay)
-       {
-               qy = ay * ay;
-               m = qy << 1;
-               tx = x1 + sx;
-               if (qy == f2)
-               {
-                       ty = y1 + sy;
-                       qy -= f1;
-               }
-               else
-               {
-                       ty = y1;
-               }
-
-               /* Note (below) the case (qy == f2), where */
-               /* the LOS exactly meets the corner of a tile. */
-               while (x2 - tx)
-               {
-                       if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
-
-                       qy += m;
-
-                       if (qy < f2)
-                       {
-                               tx += sx;
-                               continue;
-                       }
-                       
-                       if (qy > f2)
-                       {
-                               ty += sy;
-                               if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
-                               qy -= f1;
-                               tx += sx;
-                               continue;
-                       }
-
-                       ty += sy;
-                       qy -= f1;
-                       tx += sx;
-               }
-
-               return TRUE;
-       }
-
-       /* Travel vertically */
-       POSITION qx = ax * ax;
-       m = qx << 1;
-       ty = y1 + sy;
-       if (qx == f2)
-       {
-               tx = x1 + sx;
-               qx -= f1;
-       }
-       else
-       {
-               tx = x1;
-       }
-
-       /* Note (below) the case (qx == f2), where */
-       /* the LOS exactly meets the corner of a tile. */
-       while (y2 - ty)
-       {
-               if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
-
-               qx += m;
-
-               if (qx < f2)
-               {
-                       ty += sy;
-                       continue;
-               }
-
-               if (qx > f2)
-               {
-                       tx += sx;
-                       if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
-                       qx -= f1;
-                       ty += sy;
-                       continue;
-               }
-
-               tx += sx;
-               qx -= f1;
-               ty += sy;
-       }
-
-       return TRUE;
+    POSITION dy = y2 - y1;
+    POSITION dx = x2 - x1;
+    POSITION ay = ABS(dy);
+    POSITION ax = ABS(dx);
+    if ((ax < 2) && (ay < 2))
+        return TRUE;
+
+    /* Directly South/North */
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    POSITION tx, ty;
+    if (!dx) {
+        /* South -- check for walls */
+        if (dy > 0) {
+            for (ty = y1 + 1; ty < y2; ty++) {
+                if (!cave_los_bold(floor_ptr, ty, x1))
+                    return FALSE;
+            }
+        }
+
+        /* North -- check for walls */
+        else {
+            for (ty = y1 - 1; ty > y2; ty--) {
+                if (!cave_los_bold(floor_ptr, ty, x1))
+                    return FALSE;
+            }
+        }
+
+        /* Assume los */
+        return TRUE;
+    }
+
+    /* Directly East/West */
+    if (!dy) {
+        /* East -- check for walls */
+        if (dx > 0) {
+            for (tx = x1 + 1; tx < x2; tx++) {
+                if (!cave_los_bold(floor_ptr, y1, tx))
+                    return FALSE;
+            }
+        }
+
+        /* West -- check for walls */
+        else {
+            for (tx = x1 - 1; tx > x2; tx--) {
+                if (!cave_los_bold(floor_ptr, y1, tx))
+                    return FALSE;
+            }
+        }
+
+        return TRUE;
+    }
+
+    POSITION sx = (dx < 0) ? -1 : 1;
+    POSITION sy = (dy < 0) ? -1 : 1;
+
+    if (ax == 1) {
+        if (ay == 2) {
+            if (cave_los_bold(floor_ptr, y1 + sy, x1))
+                return TRUE;
+        }
+    } else if (ay == 1) {
+        if (ax == 2) {
+            if (cave_los_bold(floor_ptr, y1, x1 + sx))
+                return TRUE;
+        }
+    }
+
+    POSITION f2 = (ax * ay);
+    POSITION f1 = f2 << 1;
+    POSITION qy;
+    POSITION m;
+    if (ax >= ay) {
+        qy = ay * ay;
+        m = qy << 1;
+        tx = x1 + sx;
+        if (qy == f2) {
+            ty = y1 + sy;
+            qy -= f1;
+        } else {
+            ty = y1;
+        }
+
+        /* Note (below) the case (qy == f2), where */
+        /* the LOS exactly meets the corner of a tile. */
+        while (x2 - tx) {
+            if (!cave_los_bold(floor_ptr, ty, tx))
+                return FALSE;
+
+            qy += m;
+
+            if (qy < f2) {
+                tx += sx;
+                continue;
+            }
+
+            if (qy > f2) {
+                ty += sy;
+                if (!cave_los_bold(floor_ptr, ty, tx))
+                    return FALSE;
+                qy -= f1;
+                tx += sx;
+                continue;
+            }
+
+            ty += sy;
+            qy -= f1;
+            tx += sx;
+        }
+
+        return TRUE;
+    }
+
+    /* Travel vertically */
+    POSITION qx = ax * ax;
+    m = qx << 1;
+    ty = y1 + sy;
+    if (qx == f2) {
+        tx = x1 + sx;
+        qx -= f1;
+    } else {
+        tx = x1;
+    }
+
+    /* Note (below) the case (qx == f2), where */
+    /* the LOS exactly meets the corner of a tile. */
+    while (y2 - ty) {
+        if (!cave_los_bold(floor_ptr, ty, tx))
+            return FALSE;
+
+        qx += m;
+
+        if (qx < f2) {
+            ty += sy;
+            continue;
+        }
+
+        if (qx > f2) {
+            tx += sx;
+            if (!cave_los_bold(floor_ptr, ty, tx))
+                return FALSE;
+            qx -= f1;
+            ty += sy;
+            continue;
+        }
+
+        tx += sx;
+        qx -= f1;
+        ty += sy;
+    }
+
+    return TRUE;
 }
 
-
 /*
  * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
  * at the final destination, assuming no monster gets in the way.
@@ -510,18 +478,19 @@ bool los(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITIO
  */
 bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
 {
-       u16b grid_g[512];
+    u16b grid_g[512];
     int grid_n = project_path(player_ptr, grid_g, (project_length ? project_length : get_max_range(player_ptr)), y1, x1, y2, x2, 0);
-       if (!grid_n) return TRUE;
+    if (!grid_n)
+        return TRUE;
 
-       POSITION y = GRID_Y(grid_g[grid_n - 1]);
-       POSITION x = GRID_X(grid_g[grid_n - 1]);
-       if ((y != y2) || (x != x2)) return FALSE;
+    POSITION y = GRID_Y(grid_g[grid_n - 1]);
+    POSITION x = GRID_X(grid_g[grid_n - 1]);
+    if ((y != y2) || (x != x2))
+        return FALSE;
 
-       return TRUE;
+    return TRUE;
 }
 
-
 /*!
  * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -534,26 +503,24 @@ bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2,
  */
 void vault_monsters(player_type *player_ptr, POSITION y1, POSITION x1, int num)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       for (int k = 0; k < num; k++)
-       {
-               for (int i = 0; i < 9; i++)
-               {
-                       int d = 1;
-                       POSITION y, x;
-                       scatter(player_ptr, &y, &x, y1, x1, d, 0);
-                       grid_type *g_ptr;
-                       g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
-                       if (!is_cave_empty_grid(player_ptr, g_ptr)) continue;
-
-                       floor_ptr->monster_level = floor_ptr->base_level + 2;
-                       (void)place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
-                       floor_ptr->monster_level = floor_ptr->base_level;
-               }
-       }
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    for (int k = 0; k < num; k++) {
+        for (int i = 0; i < 9; i++) {
+            int d = 1;
+            POSITION y, x;
+            scatter(player_ptr, &y, &x, y1, x1, d, 0);
+            grid_type *g_ptr;
+            g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
+            if (!is_cave_empty_grid(player_ptr, g_ptr))
+                continue;
+
+            floor_ptr->monster_level = floor_ptr->base_level + 2;
+            (void)place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
+            floor_ptr->monster_level = floor_ptr->base_level;
+        }
+    }
 }
 
-
 /*!
  * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -565,109 +532,107 @@ void vault_monsters(player_type *player_ptr, POSITION y1, POSITION x1, int num)
  */
 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
 {
-       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
-       if (cave_perma_grid(g_ptr)) return FALSE;
-
-       OBJECT_IDX next_o_idx = 0;
-       for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
-       {
-               object_type *o_ptr;
-               o_ptr = &floor_ptr->o_list[this_o_idx];
-               next_o_idx = o_ptr->next_o_idx;
-               if (object_is_artifact(o_ptr)) return FALSE;
-       }
-
-       return TRUE;
+    grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+    if (cave_perma_grid(g_ptr))
+        return FALSE;
+
+    OBJECT_IDX next_o_idx = 0;
+    for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
+        object_type *o_ptr;
+        o_ptr = &floor_ptr->o_list[this_o_idx];
+        next_o_idx = o_ptr->next_o_idx;
+        if (object_is_artifact(o_ptr))
+            return FALSE;
+    }
+
+    return TRUE;
 }
 
-
 /*
  * Change the "feat" flag for a grid, and notice/redraw the grid
  */
 void cave_set_feat(player_type *player_ptr, POSITION y, POSITION x, FEAT_IDX feat)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
-       feature_type *f_ptr = &f_info[feat];
-       if (!current_world_ptr->character_dungeon)
-       {
-               g_ptr->mimic = 0;
-               g_ptr->feat = feat;
-               if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
-               {
-                       for (DIRECTION i = 0; i < 9; i++)
-                       {
-                               POSITION yy = y + ddy_ddd[i];
-                               POSITION xx = x + ddx_ddd[i];
-                               if (!in_bounds2(floor_ptr, yy, xx)) continue;
-                               floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
-                       }
-               }
-
-               return;
-       }
-
-       bool old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
-       bool old_mirror = is_mirror_grid(g_ptr);
-
-       g_ptr->mimic = 0;
-       g_ptr->feat = feat;
-       g_ptr->info &= ~(CAVE_OBJECT);
-       if (old_mirror && (d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
-       {
-               g_ptr->info &= ~(CAVE_GLOW);
-               if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
-
-               update_local_illumination(player_ptr, y, x);
-       }
-
-       if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
-       if (g_ptr->m_idx) update_monster(player_ptr, g_ptr->m_idx, FALSE);
-
-       note_spot(player_ptr, y, x);
-       lite_spot(player_ptr, y, x);
-       if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
-       {
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+    feature_type *f_ptr = &f_info[feat];
+    if (!current_world_ptr->character_dungeon) {
+        g_ptr->mimic = 0;
+        g_ptr->feat = feat;
+        if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) {
+            for (DIRECTION i = 0; i < 9; i++) {
+                POSITION yy = y + ddy_ddd[i];
+                POSITION xx = x + ddx_ddd[i];
+                if (!in_bounds2(floor_ptr, yy, xx))
+                    continue;
+                floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
+            }
+        }
+
+        return;
+    }
+
+    bool old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
+    bool old_mirror = is_mirror_grid(g_ptr);
+
+    g_ptr->mimic = 0;
+    g_ptr->feat = feat;
+    g_ptr->info &= ~(CAVE_OBJECT);
+    if (old_mirror && (d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) {
+        g_ptr->info &= ~(CAVE_GLOW);
+        if (!view_torch_grids)
+            g_ptr->info &= ~(CAVE_MARK);
+
+        update_local_illumination(player_ptr, y, x);
+    }
+
+    if (!have_flag(f_ptr->flags, FF_REMEMBER))
+        g_ptr->info &= ~(CAVE_MARK);
+    if (g_ptr->m_idx)
+        update_monster(player_ptr, g_ptr->m_idx, FALSE);
+
+    note_spot(player_ptr, y, x);
+    lite_spot(player_ptr, y, x);
+    if (old_los ^ have_flag(f_ptr->flags, FF_LOS)) {
 
 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
 
-               update_local_illumination(player_ptr, y, x);
+        update_local_illumination(player_ptr, y, x);
 
 #endif /* COMPLEX_WALL_ILLUMINATION */
 
-               player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
-       }
+        player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
+    }
 
-       if (!have_flag(f_ptr->flags, FF_GLOW) || (d_info[player_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
-               return;
+    if (!have_flag(f_ptr->flags, FF_GLOW) || (d_info[player_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
+        return;
 
-       for (DIRECTION i = 0; i < 9; i++)
-       {
-               POSITION yy = y + ddy_ddd[i];
-               POSITION xx = x + ddx_ddd[i];
-               if (!in_bounds2(floor_ptr, yy, xx)) continue;
+    for (DIRECTION i = 0; i < 9; i++) {
+        POSITION yy = y + ddy_ddd[i];
+        POSITION xx = x + ddx_ddd[i];
+        if (!in_bounds2(floor_ptr, yy, xx))
+            continue;
 
-               grid_type *cc_ptr;
-               cc_ptr = &floor_ptr->grid_array[yy][xx];
-               cc_ptr->info |= CAVE_GLOW;
+        grid_type *cc_ptr;
+        cc_ptr = &floor_ptr->grid_array[yy][xx];
+        cc_ptr->info |= CAVE_GLOW;
 
-               if (player_has_los_grid(cc_ptr))
-               {
-                       if (cc_ptr->m_idx) update_monster(player_ptr, cc_ptr->m_idx, FALSE);
-                       note_spot(player_ptr, yy, xx);
-                       lite_spot(player_ptr, yy, xx);
-               }
+        if (player_has_los_grid(cc_ptr)) {
+            if (cc_ptr->m_idx)
+                update_monster(player_ptr, cc_ptr->m_idx, FALSE);
+            note_spot(player_ptr, yy, xx);
+            lite_spot(player_ptr, yy, xx);
+        }
 
-               update_local_illumination(player_ptr, yy, xx);
-       }
+        update_local_illumination(player_ptr, yy, xx);
+    }
 
-       if (player_ptr->special_defense & NINJA_S_STEALTH)
-       {
-               if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW) set_superstealth(player_ptr, FALSE);
-       }
+    if (player_ptr->special_defense & NINJA_S_STEALTH) {
+        if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW)
+            set_superstealth(player_ptr, FALSE);
+    }
 }
 
-
 /*!
  * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -678,71 +643,55 @@ void cave_set_feat(player_type *player_ptr, POSITION y, POSITION x, FEAT_IDX fea
  */
 void place_random_door(player_type *player_ptr, POSITION y, POSITION x, bool room)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
-       g_ptr->mimic = 0;
-
-       if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
-       {
-               place_bold(player_ptr, y, x, GB_FLOOR);
-               return;
-       }
-
-       int type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
-               one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
-               ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
-
-       int tmp = randint0(1000);
-       FEAT_IDX feat = feat_none;
-       if (tmp < 300)
-       {
-               feat = feat_door[type].open;
-       }
-       else if (tmp < 400)
-       {
-               feat = feat_door[type].broken;
-       }
-       else if (tmp < 600)
-       {
-               place_closed_door(player_ptr, y, x, type);
-
-               if (type != DOOR_CURTAIN)
-               {
-                       g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
-                       if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
-                       {
-                               if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
-                               {
-                                       g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
-                               }
-                               g_ptr->mimic = 0;
-                       }
-               }
-       }
-       else
-       {
-               place_closed_door(player_ptr, y, x, type);
-       }
-
-       if (tmp >= 400)
-       {
-               delete_monster(player_ptr, y, x);
-               return;
-       }
-
-       if (feat != feat_none)
-       {
-               set_cave_feat(floor_ptr, y, x, feat);
-       }
-       else
-       {
-               place_bold(player_ptr, y, x, GB_FLOOR);
-       }
-
-       delete_monster(player_ptr, y, x);
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+    g_ptr->mimic = 0;
+
+    if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) {
+        place_bold(player_ptr, y, x, GB_FLOOR);
+        return;
+    }
+
+    int type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) && one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256))
+        ? DOOR_CURTAIN
+        : ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
+
+    int tmp = randint0(1000);
+    FEAT_IDX feat = feat_none;
+    if (tmp < 300) {
+        feat = feat_door[type].open;
+    } else if (tmp < 400) {
+        feat = feat_door[type].broken;
+    } else if (tmp < 600) {
+        place_closed_door(player_ptr, y, x, type);
+
+        if (type != DOOR_CURTAIN) {
+            g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
+            if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat)) {
+                if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY)) {
+                    g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
+                }
+                g_ptr->mimic = 0;
+            }
+        }
+    } else {
+        place_closed_door(player_ptr, y, x, type);
+    }
+
+    if (tmp >= 400) {
+        delete_monster(player_ptr, y, x);
+        return;
+    }
+
+    if (feat != feat_none) {
+        set_cave_feat(floor_ptr, y, x, feat);
+    } else {
+        place_bold(player_ptr, y, x, GB_FLOOR);
+    }
+
+    delete_monster(player_ptr, y, x);
 }
 
-
 /*!
  * @brief グローバルオブジェクト配列を初期化する /
  * Delete all the items when player leaves the level
@@ -757,42 +706,38 @@ void place_random_door(player_type *player_ptr, POSITION y, POSITION x, bool roo
  */
 void wipe_o_list(floor_type *floor_ptr)
 {
-       for (int i = 1; i < floor_ptr->o_max; i++)
-       {
-               object_type *o_ptr = &floor_ptr->o_list[i];
-               if (!object_is_valid(o_ptr)) continue;
-
-               if (!current_world_ptr->character_dungeon || preserve_mode)
-               {
-                       if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
-                       {
-                               a_info[o_ptr->name1].cur_num = 0;
-                       }
-               }
-
-               if (object_is_held_monster(o_ptr))
-               {
-                       monster_type *m_ptr;
-                       m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
-                       m_ptr->hold_o_idx = 0;
-                       object_wipe(o_ptr);
-                       continue;
-               }
-
-               grid_type *g_ptr;
-               POSITION y = o_ptr->iy;
-               POSITION x = o_ptr->ix;
-
-               g_ptr = &floor_ptr->grid_array[y][x];
-               g_ptr->o_idx = 0;
-               object_wipe(o_ptr);
-       }
-
-       floor_ptr->o_max = 1;
-       floor_ptr->o_cnt = 0;
+    for (int i = 1; i < floor_ptr->o_max; i++) {
+        object_type *o_ptr = &floor_ptr->o_list[i];
+        if (!object_is_valid(o_ptr))
+            continue;
+
+        if (!current_world_ptr->character_dungeon || preserve_mode) {
+            if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr)) {
+                a_info[o_ptr->name1].cur_num = 0;
+            }
+        }
+
+        if (object_is_held_monster(o_ptr)) {
+            monster_type *m_ptr;
+            m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
+            m_ptr->hold_o_idx = 0;
+            object_wipe(o_ptr);
+            continue;
+        }
+
+        grid_type *g_ptr;
+        POSITION y = o_ptr->iy;
+        POSITION x = o_ptr->ix;
+
+        g_ptr = &floor_ptr->grid_array[y][x];
+        g_ptr->o_idx = 0;
+        object_wipe(o_ptr);
+    }
+
+    floor_ptr->o_max = 1;
+    floor_ptr->o_cnt = 0;
 }
 
-
 /*!
  * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -803,40 +748,32 @@ void wipe_o_list(floor_type *floor_ptr)
  */
 void place_closed_door(player_type *player_ptr, POSITION y, POSITION x, int type)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
-       {
-               place_bold(player_ptr, y, x, GB_FLOOR);
-               return;
-       }
-
-       int tmp = randint0(400);
-       FEAT_IDX feat = feat_none;
-       if (tmp < 300)
-       {
-               /* Create closed door */
-               feat = feat_door[type].closed;
-       }
-       else if (tmp < 399)
-       {
-               feat = feat_locked_door_random(type);
-       }
-       else
-       {
-               feat = feat_jammed_door_random(type);
-       }
-
-       if (feat == feat_none)
-       {
-               place_bold(player_ptr, y, x, GB_FLOOR);
-               return;
-       }
-
-       cave_set_feat(player_ptr, y, x, feat);
-       floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) {
+        place_bold(player_ptr, y, x, GB_FLOOR);
+        return;
+    }
+
+    int tmp = randint0(400);
+    FEAT_IDX feat = feat_none;
+    if (tmp < 300) {
+        /* Create closed door */
+        feat = feat_door[type].closed;
+    } else if (tmp < 399) {
+        feat = feat_locked_door_random(type);
+    } else {
+        feat = feat_jammed_door_random(type);
+    }
+
+    if (feat == feat_none) {
+        place_bold(player_ptr, y, x, GB_FLOOR);
+        return;
+    }
+
+    cave_set_feat(player_ptr, y, x, feat);
+    floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
 }
 
-
 /*!
  * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
  * @param y トラップを配置したいマスの中心Y座標
@@ -849,35 +786,33 @@ void place_closed_door(player_type *player_ptr, POSITION y, POSITION x, int type
  */
 void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
 {
-       grid_type *g_ptr;
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       int y1 = y, x1 = x;
-       int dummy = 0;
-       for (int count = 0; count <= 5; count++)
-       {
-               while (dummy < SAFE_MAX_ATTEMPTS)
-               {
-                       y1 = rand_spread(y, yd);
-                       x1 = rand_spread(x, xd);
-                       dummy++;
-                       if (!in_bounds(floor_ptr, y1, x1)) continue;
-                       break;
-               }
-
-               if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
-               {
-                       msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
-               }
-
-               g_ptr = &floor_ptr->grid_array[y1][x1];
-               if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
-
-               place_trap(player_ptr, y1, x1);
-               break;
-       }
+    grid_type *g_ptr;
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    int y1 = y, x1 = x;
+    int dummy = 0;
+    for (int count = 0; count <= 5; count++) {
+        while (dummy < SAFE_MAX_ATTEMPTS) {
+            y1 = rand_spread(y, yd);
+            x1 = rand_spread(x, xd);
+            dummy++;
+            if (!in_bounds(floor_ptr, y1, x1))
+                continue;
+            break;
+        }
+
+        if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room) {
+            msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
+        }
+
+        g_ptr = &floor_ptr->grid_array[y1][x1];
+        if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx)
+            continue;
+
+        place_trap(player_ptr, y1, x1);
+        break;
+    }
 }
 
-
 /*!
  * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor.  (Includes range checking.)
  * @param x チェックするマスのX座標
@@ -886,134 +821,129 @@ void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd
  */
 bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
 {
-       if (!in_bounds(floor_ptr, y, x))
-       {
-               return FALSE;
-       }
+    if (!in_bounds(floor_ptr, y, x)) {
+        return FALSE;
+    }
 
-       if (is_floor_bold(floor_ptr, y, x)) return TRUE;
+    if (is_floor_bold(floor_ptr, y, x))
+        return TRUE;
 
-       return FALSE;
+    return FALSE;
 }
 
-
 /*!
-* @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
-* @param y1 基準となるマスのY座標
-* @param x1 基準となるマスのX座標
-* @return 通路の数
-* @note Assumes "in_bounds(y1, x1)"
-* @details
-* XXX XXX This routine currently only counts actual "empty floor"\n
-* grids which are not in rooms.  We might want to also count stairs,\n
-* open doors, closed doors, etc.
-*/
+ * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
+ * @param y1 基準となるマスのY座標
+ * @param x1 基準となるマスのX座標
+ * @return 通路の数
+ * @note Assumes "in_bounds(y1, x1)"
+ * @details
+ * XXX XXX This routine currently only counts actual "empty floor"\n
+ * grids which are not in rooms.  We might want to also count stairs,\n
+ * open doors, closed doors, etc.
+ */
 static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
 {
-       int k = 0;
-       for (int i = 0; i < 4; i++)
-       {
-               POSITION y = y1 + ddy_ddd[i];
-               POSITION x = x1 + ddx_ddd[i];
-               grid_type *g_ptr;
-               g_ptr = &floor_ptr->grid_array[y][x];
-
-               if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
-               if (!is_floor_grid(g_ptr)) continue;
-               if (g_ptr->info & (CAVE_ROOM)) continue;
-
-               k++;
-       }
-
-       return k;
+    int k = 0;
+    for (int i = 0; i < 4; i++) {
+        POSITION y = y1 + ddy_ddd[i];
+        POSITION x = x1 + ddx_ddd[i];
+        grid_type *g_ptr;
+        g_ptr = &floor_ptr->grid_array[y][x];
+
+        if (cave_have_flag_grid(g_ptr, FF_WALL))
+            continue;
+        if (!is_floor_grid(g_ptr))
+            continue;
+        if (g_ptr->info & (CAVE_ROOM))
+            continue;
+
+        k++;
+    }
+
+    return k;
 }
 
 /*!
-* @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
-* @param y 判定を行いたいマスのY座標
-* @param x 判定を行いたいマスのX座標
-* @return ドアを設置可能ならばTRUEを返す
-* @note Assumes "in_bounds()"
-* @details
-* \n
-* Assumes "in_bounds()"\n
-*/
+ * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
+ * @param y 判定を行いたいマスのY座標
+ * @param x 判定を行いたいマスのX座標
+ * @return ドアを設置可能ならばTRUEを返す
+ * @note Assumes "in_bounds()"
+ * @details
+ * \n
+ * Assumes "in_bounds()"\n
+ */
 static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
 {
-       if (next_to_corr(floor_ptr, y, x) < 2) return FALSE;
-
-       /* Check Vertical */
-       if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) &&
-               cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
-       {
-               return TRUE;
-       }
-
-       /* Check Horizontal */
-       if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) &&
-               cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
-       {
-               return TRUE;
-       }
-
-       return FALSE;
-}
+    if (next_to_corr(floor_ptr, y, x) < 2)
+        return FALSE;
+
+    /* Check Vertical */
+    if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) && cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL)) {
+        return TRUE;
+    }
 
+    /* Check Horizontal */
+    if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) && cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL)) {
+        return TRUE;
+    }
+
+    return FALSE;
+}
 
 /*!
-* @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
-* @param player_ptr プレーヤーへの参照ポインタ
-* @param y 設置を行いたいマスのY座標
-* @param x 設置を行いたいマスのX座標
-* @return なし
-*/
+ * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param y 設置を行いたいマスのY座標
+ * @param x 設置を行いたいマスのX座標
+ * @return なし
+ */
 void try_door(player_type *player_ptr, POSITION y, POSITION x)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       if (!in_bounds(floor_ptr, y, x)) return;
-
-       if (cave_have_flag_bold(floor_ptr, y, x, FF_WALL)) return;
-       if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
-
-       bool can_place_door = randint0(100) < dun_tun_jct;
-       can_place_door &= possible_doorway(floor_ptr, y, x);
-       can_place_door &= (d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) == 0;
-       if (can_place_door)
-       {
-               place_random_door(player_ptr, y, x, FALSE);
-       }
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    if (!in_bounds(floor_ptr, y, x))
+        return;
+
+    if (cave_have_flag_bold(floor_ptr, y, x, FF_WALL))
+        return;
+    if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM))
+        return;
+
+    bool can_place_door = randint0(100) < dun_tun_jct;
+    can_place_door &= possible_doorway(floor_ptr, y, x);
+    can_place_door &= (d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) == 0;
+    if (can_place_door) {
+        place_random_door(player_ptr, y, x, FALSE);
+    }
 }
 
-
 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
 {
-       feature_type *f_ptr = &f_info[newfeat];
-       if (have_flag(f_ptr->flags, FF_CONVERT))
-       {
-               switch (f_ptr->subtype)
-               {
-               case CONVERT_TYPE_FLOOR:
-                       return feat_ground_type[randint0(100)];
-               case CONVERT_TYPE_WALL:
-                       return feat_wall_type[randint0(100)];
-               case CONVERT_TYPE_INNER:
-                       return feat_wall_inner;
-               case CONVERT_TYPE_OUTER:
-                       return feat_wall_outer;
-               case CONVERT_TYPE_SOLID:
-                       return feat_wall_solid;
-               case CONVERT_TYPE_STREAM1:
-                       return d_info[floor_ptr->dungeon_idx].stream1;
-               case CONVERT_TYPE_STREAM2:
-                       return d_info[floor_ptr->dungeon_idx].stream2;
-               default:
-                       return newfeat;
-               }
-       }
-       else return newfeat;
+    feature_type *f_ptr = &f_info[newfeat];
+    if (have_flag(f_ptr->flags, FF_CONVERT)) {
+        switch (f_ptr->subtype) {
+        case CONVERT_TYPE_FLOOR:
+            return feat_ground_type[randint0(100)];
+        case CONVERT_TYPE_WALL:
+            return feat_wall_type[randint0(100)];
+        case CONVERT_TYPE_INNER:
+            return feat_wall_inner;
+        case CONVERT_TYPE_OUTER:
+            return feat_wall_outer;
+        case CONVERT_TYPE_SOLID:
+            return feat_wall_solid;
+        case CONVERT_TYPE_STREAM1:
+            return d_info[floor_ptr->dungeon_idx].stream1;
+        case CONVERT_TYPE_STREAM2:
+            return d_info[floor_ptr->dungeon_idx].stream2;
+        default:
+            return newfeat;
+        }
+    } else
+        return newfeat;
 }
 
-
 /*!
  * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -1026,46 +956,40 @@ FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
  */
 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       for (; num > 0; --num)
-       {
-               int j = y, k = x;
-               int dummy = 0;
-               for (int i = 0; i < 11; ++i)
-               {
-                       while (dummy < SAFE_MAX_ATTEMPTS)
-                       {
-                               j = rand_spread(y, 2);
-                               k = rand_spread(x, 3);
-                               dummy++;
-                               if (!in_bounds(floor_ptr, j, k)) continue;
-                               break;
-                       }
-
-                       if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
-                       {
-                               msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
-                       }
-
-                       grid_type *g_ptr;
-                       g_ptr = &floor_ptr->grid_array[j][k];
-                       if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
-
-                       if (randint0(100) < 75)
-                       {
-                               place_object(player_ptr, j, k, 0L);
-                       }
-                       else
-                       {
-                               place_gold(player_ptr, j, k);
-                       }
-
-                       break;
-               }
-       }
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    for (; num > 0; --num) {
+        int j = y, k = x;
+        int dummy = 0;
+        for (int i = 0; i < 11; ++i) {
+            while (dummy < SAFE_MAX_ATTEMPTS) {
+                j = rand_spread(y, 2);
+                k = rand_spread(x, 3);
+                dummy++;
+                if (!in_bounds(floor_ptr, j, k))
+                    continue;
+                break;
+            }
+
+            if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room) {
+                msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
+            }
+
+            grid_type *g_ptr;
+            g_ptr = &floor_ptr->grid_array[j][k];
+            if (!is_floor_grid(g_ptr) || g_ptr->o_idx)
+                continue;
+
+            if (randint0(100) < 75) {
+                place_object(player_ptr, j, k, 0L);
+            } else {
+                place_gold(player_ptr, j, k);
+            }
+
+            break;
+        }
+    }
 }
 
-
 /*!
  * @brief 始点から終点への直線経路を返す /
  * Determine the path taken by a projection.
@@ -1120,211 +1044,188 @@ void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
  */
 int project_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
 {
-       if ((x1 == x2) && (y1 == y2)) return 0;
-
-       POSITION y, x;
-       POSITION ay, ax;
-       POSITION sy, sx;
-       int frac;
-       int m;
-
-       if (y2 < y1)
-       {
-               ay = (y1 - y2);
-               sy = -1;
-       }
-       else
-       {
-               ay = (y2 - y1);
-               sy = 1;
-       }
-
-       if (x2 < x1)
-       {
-               ax = (x1 - x2);
-               sx = -1;
-       }
-       else
-       {
-               ax = (x2 - x1);
-               sx = 1;
-       }
-
-       int half = (ay * ax);
-       int full = half << 1;
-
-       /* Vertical */
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       int n = 0;
-       int k = 0;
-       if (ay > ax)
-       {
-               m = ax * ax * 2;
-               y = y1 + sy;
-               x = x1;
-               frac = m;
-               if (frac > half)
-               {
-                       x += sx;
-                       frac -= full;
-                       k++;
-               }
-
-               while (TRUE)
-               {
-                       gp[n++] = GRID(y, x);
-                       if ((n + (k >> 1)) >= range) break;
-
-                       if (!(flg & (PROJECT_THRU)))
-                       {
-                               if ((x == x2) && (y == y2)) break;
-                       }
-
-                       if (flg & (PROJECT_DISI))
-                       {
-                               if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
-                       }
-                       else if (flg & (PROJECT_LOS))
-                       {
-                               if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
-                       }
-                       else if (!(flg & (PROJECT_PATH)))
-                       {
-                               if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
-                       }
-
-                       if (flg & (PROJECT_STOP))
-                       {
-                               if ((n > 0) &&
-                                       (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
-                                       break;
-                       }
-
-                       if (!in_bounds(floor_ptr, y, x)) break;
-
-                       if (m)
-                       {
-                               frac += m;
-                               if (frac > half)
-                               {
-                                       x += sx;
-                                       frac -= full;
-                                       k++;
-                               }
-                       }
-
-                       y += sy;
-               }
-
-               return n;
-       }
-
-       /* Horizontal */
-       if (ax > ay)
-       {
-               m = ay * ay * 2;
-               y = y1;
-               x = x1 + sx;
-               frac = m;
-               if (frac > half)
-               {
-                       y += sy;
-                       frac -= full;
-                       k++;
-               }
-
-               while (TRUE)
-               {
-                       gp[n++] = GRID(y, x);
-                       if ((n + (k >> 1)) >= range) break;
-
-                       if (!(flg & (PROJECT_THRU)))
-                       {
-                               if ((x == x2) && (y == y2)) break;
-                       }
-
-                       if (flg & (PROJECT_DISI))
-                       {
-                               if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
-                       }
-                       else if (flg & (PROJECT_LOS))
-                       {
-                               if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
-                       }
-                       else if (!(flg & (PROJECT_PATH)))
-                       {
-                               if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
-                       }
-
-                       if (flg & (PROJECT_STOP))
-                       {
-                               if ((n > 0) &&
-                                       (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
-                                       break;
-                       }
-
-                       if (!in_bounds(floor_ptr, y, x)) break;
-
-                       if (m)
-                       {
-                               frac += m;
-                               if (frac > half)
-                               {
-                                       y += sy;
-                                       frac -= full;
-                                       k++;
-                               }
-                       }
-
-                       x += sx;
-               }
-
-               return n;
-       }
-
-       y = y1 + sy;
-       x = x1 + sx;
-
-       while (TRUE)
-       {
-               gp[n++] = GRID(y, x);
-               if ((n + (n >> 1)) >= range) break;
-
-               if (!(flg & (PROJECT_THRU)))
-               {
-                       if ((x == x2) && (y == y2)) break;
-               }
-
-               if (flg & (PROJECT_DISI))
-               {
-                       if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
-               }
-               else if (flg & (PROJECT_LOS))
-               {
-                       if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
-               }
-               else if (!(flg & (PROJECT_PATH)))
-               {
-                       if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
-               }
-
-               if (flg & (PROJECT_STOP))
-               {
-                       if ((n > 0) &&
-                               (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
-                               break;
-               }
-
-               if (!in_bounds(floor_ptr, y, x)) break;
-
-               y += sy;
-               x += sx;
-       }
-
-       return n;
+    if ((x1 == x2) && (y1 == y2))
+        return 0;
+
+    POSITION y, x;
+    POSITION ay, ax;
+    POSITION sy, sx;
+    int frac;
+    int m;
+
+    if (y2 < y1) {
+        ay = (y1 - y2);
+        sy = -1;
+    } else {
+        ay = (y2 - y1);
+        sy = 1;
+    }
+
+    if (x2 < x1) {
+        ax = (x1 - x2);
+        sx = -1;
+    } else {
+        ax = (x2 - x1);
+        sx = 1;
+    }
+
+    int half = (ay * ax);
+    int full = half << 1;
+
+    /* Vertical */
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    int n = 0;
+    int k = 0;
+    if (ay > ax) {
+        m = ax * ax * 2;
+        y = y1 + sy;
+        x = x1;
+        frac = m;
+        if (frac > half) {
+            x += sx;
+            frac -= full;
+            k++;
+        }
+
+        while (TRUE) {
+            gp[n++] = GRID(y, x);
+            if ((n + (k >> 1)) >= range)
+                break;
+
+            if (!(flg & (PROJECT_THRU))) {
+                if ((x == x2) && (y == y2))
+                    break;
+            }
+
+            if (flg & (PROJECT_DISI)) {
+                if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
+                    break;
+            } else if (flg & (PROJECT_LOS)) {
+                if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
+                    break;
+            } else if (!(flg & (PROJECT_PATH))) {
+                if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
+                    break;
+            }
+
+            if (flg & (PROJECT_STOP)) {
+                if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                    break;
+            }
+
+            if (!in_bounds(floor_ptr, y, x))
+                break;
+
+            if (m) {
+                frac += m;
+                if (frac > half) {
+                    x += sx;
+                    frac -= full;
+                    k++;
+                }
+            }
+
+            y += sy;
+        }
+
+        return n;
+    }
+
+    /* Horizontal */
+    if (ax > ay) {
+        m = ay * ay * 2;
+        y = y1;
+        x = x1 + sx;
+        frac = m;
+        if (frac > half) {
+            y += sy;
+            frac -= full;
+            k++;
+        }
+
+        while (TRUE) {
+            gp[n++] = GRID(y, x);
+            if ((n + (k >> 1)) >= range)
+                break;
+
+            if (!(flg & (PROJECT_THRU))) {
+                if ((x == x2) && (y == y2))
+                    break;
+            }
+
+            if (flg & (PROJECT_DISI)) {
+                if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
+                    break;
+            } else if (flg & (PROJECT_LOS)) {
+                if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
+                    break;
+            } else if (!(flg & (PROJECT_PATH))) {
+                if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
+                    break;
+            }
+
+            if (flg & (PROJECT_STOP)) {
+                if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                    break;
+            }
+
+            if (!in_bounds(floor_ptr, y, x))
+                break;
+
+            if (m) {
+                frac += m;
+                if (frac > half) {
+                    y += sy;
+                    frac -= full;
+                    k++;
+                }
+            }
+
+            x += sx;
+        }
+
+        return n;
+    }
+
+    y = y1 + sy;
+    x = x1 + sx;
+
+    while (TRUE) {
+        gp[n++] = GRID(y, x);
+        if ((n + (n >> 1)) >= range)
+            break;
+
+        if (!(flg & (PROJECT_THRU))) {
+            if ((x == x2) && (y == y2))
+                break;
+        }
+
+        if (flg & (PROJECT_DISI)) {
+            if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
+                break;
+        } else if (flg & (PROJECT_LOS)) {
+            if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
+                break;
+        } else if (!(flg & (PROJECT_PATH))) {
+            if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
+                break;
+        }
+
+        if (flg & (PROJECT_STOP)) {
+            if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                break;
+        }
+
+        if (!in_bounds(floor_ptr, y, x))
+            break;
+
+        y += sy;
+        x += sx;
+    }
+
+    return n;
 }
 
-
 /*!
  * @brief 指定のマスを床地形に変える / Set a square to be floor.  (Includes range checking.)
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -1334,21 +1235,18 @@ int project_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1,
  */
 void set_floor(player_type *player_ptr, POSITION x, POSITION y)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       if (!in_bounds(floor_ptr, y, x))
-       {
-               return;
-       }
-
-       if (floor_ptr->grid_array[y][x].info & CAVE_ROOM)
-       {
-               return;
-       }
-
-       if (is_extra_bold(floor_ptr, y, x))
-               place_bold(player_ptr, y, x, GB_FLOOR);
-}
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    if (!in_bounds(floor_ptr, y, x)) {
+        return;
+    }
+
+    if (floor_ptr->grid_array[y][x].info & CAVE_ROOM) {
+        return;
+    }
 
+    if (is_extra_bold(floor_ptr, y, x))
+        place_bold(player_ptr, y, x, GB_FLOOR);
+}
 
 /*!
  * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
@@ -1365,43 +1263,44 @@ void set_floor(player_type *player_ptr, POSITION x, POSITION y)
  */
 void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
 {
-       floor_type *floor_ptr = owner_ptr->current_floor_ptr;
-       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
-       object_type forge;
-       object_type *q_ptr;
-       if (!in_bounds(floor_ptr, y, x)) return;
-       if (!cave_drop_bold(floor_ptr, y, x)) return;
-       if (g_ptr->o_idx) return;
-
-       q_ptr = &forge;
-       object_wipe(q_ptr);
-       if (!make_object(owner_ptr, q_ptr, mode)) return;
-
-       OBJECT_IDX o_idx = o_pop(floor_ptr);
-       if (o_idx == 0)
-       {
-               if (object_is_fixed_artifact(q_ptr))
-               {
-                       a_info[q_ptr->name1].cur_num = 0;
-               }
-
-               return;
-       }
-
-       object_type *o_ptr;
-       o_ptr = &floor_ptr->o_list[o_idx];
-       object_copy(o_ptr, q_ptr);
-
-       o_ptr->iy = y;
-       o_ptr->ix = x;
-       o_ptr->next_o_idx = g_ptr->o_idx;
-
-       g_ptr->o_idx = o_idx;
-       note_spot(owner_ptr, y, x);
-       lite_spot(owner_ptr, y, x);
+    floor_type *floor_ptr = owner_ptr->current_floor_ptr;
+    grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+    object_type forge;
+    object_type *q_ptr;
+    if (!in_bounds(floor_ptr, y, x))
+        return;
+    if (!cave_drop_bold(floor_ptr, y, x))
+        return;
+    if (g_ptr->o_idx)
+        return;
+
+    q_ptr = &forge;
+    object_wipe(q_ptr);
+    if (!make_object(owner_ptr, q_ptr, mode))
+        return;
+
+    OBJECT_IDX o_idx = o_pop(floor_ptr);
+    if (o_idx == 0) {
+        if (object_is_fixed_artifact(q_ptr)) {
+            a_info[q_ptr->name1].cur_num = 0;
+        }
+
+        return;
+    }
+
+    object_type *o_ptr;
+    o_ptr = &floor_ptr->o_list[o_idx];
+    object_copy(o_ptr, q_ptr);
+
+    o_ptr->iy = y;
+    o_ptr->ix = x;
+    o_ptr->next_o_idx = g_ptr->o_idx;
+
+    g_ptr->o_idx = o_idx;
+    note_spot(owner_ptr, y, x);
+    lite_spot(owner_ptr, y, x);
 }
 
-
 /*!
  * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
  * Places a treasure (Gold or Gems) at given location
@@ -1414,35 +1313,39 @@ void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode
  */
 void place_gold(player_type *player_ptr, POSITION y, POSITION x)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
-       if (!in_bounds(floor_ptr, y, x)) return;
-       if (!cave_drop_bold(floor_ptr, y, x)) return;
-       if (g_ptr->o_idx) return;
-
-       object_type forge;
-       object_type *q_ptr;
-       q_ptr = &forge;
-       object_wipe(q_ptr);
-       if (!make_gold(player_ptr, q_ptr)) return;
-
-       OBJECT_IDX o_idx = o_pop(floor_ptr);
-       if (o_idx == 0) return;
-
-       object_type *o_ptr;
-       o_ptr = &floor_ptr->o_list[o_idx];
-       object_copy(o_ptr, q_ptr);
-
-       o_ptr->iy = y;
-       o_ptr->ix = x;
-       o_ptr->next_o_idx = g_ptr->o_idx;
-
-       g_ptr->o_idx = o_idx;
-       note_spot(player_ptr, y, x);
-       lite_spot(player_ptr, y, x);
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+    if (!in_bounds(floor_ptr, y, x))
+        return;
+    if (!cave_drop_bold(floor_ptr, y, x))
+        return;
+    if (g_ptr->o_idx)
+        return;
+
+    object_type forge;
+    object_type *q_ptr;
+    q_ptr = &forge;
+    object_wipe(q_ptr);
+    if (!make_gold(player_ptr, q_ptr))
+        return;
+
+    OBJECT_IDX o_idx = o_pop(floor_ptr);
+    if (o_idx == 0)
+        return;
+
+    object_type *o_ptr;
+    o_ptr = &floor_ptr->o_list[o_idx];
+    object_copy(o_ptr, q_ptr);
+
+    o_ptr->iy = y;
+    o_ptr->ix = x;
+    o_ptr->next_o_idx = g_ptr->o_idx;
+
+    g_ptr->o_idx = o_idx;
+    note_spot(player_ptr, y, x);
+    lite_spot(player_ptr, y, x);
 }
 
-
 /*!
  * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -1452,15 +1355,16 @@ void place_gold(player_type *player_ptr, POSITION y, POSITION x)
  */
 void delete_monster(player_type *player_ptr, POSITION y, POSITION x)
 {
-       grid_type *g_ptr;
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       if (!in_bounds(floor_ptr, y, x)) return;
-
-       g_ptr = &floor_ptr->grid_array[y][x];
-       if (g_ptr->m_idx) delete_monster_idx(player_ptr, g_ptr->m_idx);
+    grid_type *g_ptr;
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    if (!in_bounds(floor_ptr, y, x))
+        return;
+
+    g_ptr = &floor_ptr->grid_array[y][x];
+    if (g_ptr->m_idx)
+        delete_monster_idx(player_ptr, g_ptr->m_idx);
 }
 
-
 /*!
  * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
  * Move an object from index i1 to index i2 in the object list
@@ -1470,49 +1374,43 @@ void delete_monster(player_type *player_ptr, POSITION y, POSITION x)
  */
 static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX i2)
 {
-       if (i1 == i2) return;
-
-       object_type *o_ptr;
-       for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
-       {
-               o_ptr = &floor_ptr->o_list[i];
-               if (!o_ptr->k_idx) continue;
-
-               if (o_ptr->next_o_idx == i1)
-               {
-                       o_ptr->next_o_idx = i2;
-               }
-       }
-
-       o_ptr = &floor_ptr->o_list[i1];
-
-       if (object_is_held_monster(o_ptr))
-       {
-               monster_type *m_ptr;
-               m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
-               if (m_ptr->hold_o_idx == i1)
-               {
-                       m_ptr->hold_o_idx = i2;
-               }
-       }
-       else
-       {
-               POSITION y = o_ptr->iy;
-               POSITION x = o_ptr->ix;
-               grid_type *g_ptr;
-               g_ptr = &floor_ptr->grid_array[y][x];
-
-               if (g_ptr->o_idx == i1)
-               {
-                       g_ptr->o_idx = i2;
-               }
-       }
-
-       floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
-       object_wipe(o_ptr);
+    if (i1 == i2)
+        return;
+
+    object_type *o_ptr;
+    for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++) {
+        o_ptr = &floor_ptr->o_list[i];
+        if (!o_ptr->k_idx)
+            continue;
+
+        if (o_ptr->next_o_idx == i1) {
+            o_ptr->next_o_idx = i2;
+        }
+    }
+
+    o_ptr = &floor_ptr->o_list[i1];
+
+    if (object_is_held_monster(o_ptr)) {
+        monster_type *m_ptr;
+        m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
+        if (m_ptr->hold_o_idx == i1) {
+            m_ptr->hold_o_idx = i2;
+        }
+    } else {
+        POSITION y = o_ptr->iy;
+        POSITION x = o_ptr->ix;
+        grid_type *g_ptr;
+        g_ptr = &floor_ptr->grid_array[y][x];
+
+        if (g_ptr->o_idx == i1) {
+            g_ptr->o_idx = i2;
+        }
+    }
+
+    floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
+    object_wipe(o_ptr);
 }
 
-
 /*!
  * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
  * Compact and Reorder the object list.
@@ -1532,66 +1430,64 @@ static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX
  */
 void compact_objects(player_type *player_ptr, int size)
 {
-       object_type *o_ptr;
-       if (size)
-       {
-               msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
-               player_ptr->redraw |= (PR_MAP);
-               player_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
-       }
-
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       for (int num = 0, cnt = 1; num < size; cnt++)
-       {
-               int cur_lev = 5 * cnt;
-               int cur_dis = 5 * (20 - cnt);
-               for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
-               {
-                       o_ptr = &floor_ptr->o_list[i];
-
-                       if (!object_is_valid(o_ptr)) continue;
-                       if (k_info[o_ptr->k_idx].level > cur_lev) continue;
-
-                       POSITION y, x;
-                       if (object_is_held_monster(o_ptr))
-                       {
-                               monster_type *m_ptr;
-                               m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
-                               y = m_ptr->fy;
-                               x = m_ptr->fx;
-
-                               if (randint0(100) < 90) continue;
-                       }
-                       else
-                       {
-                               y = o_ptr->iy;
-                               x = o_ptr->ix;
-                       }
-
-                       if ((cur_dis > 0) && (distance(player_ptr->y, player_ptr->x, y, x) < cur_dis)) continue;
-
-                       int chance = 90;
-                       if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
-                               (cnt < 1000)) chance = 100;
-
-                       if (randint0(100) < chance) continue;
-
-                       delete_object_idx(player_ptr, i);
-                       num++;
-               }
-       }
-
-       for (OBJECT_IDX i = floor_ptr->o_max - 1; i >= 1; i--)
-       {
-               o_ptr = &floor_ptr->o_list[i];
-               if (o_ptr->k_idx) continue;
-
-               compact_objects_aux(floor_ptr, floor_ptr->o_max - 1, i);
-               floor_ptr->o_max--;
-       }
+    object_type *o_ptr;
+    if (size) {
+        msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
+        player_ptr->redraw |= (PR_MAP);
+        player_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
+    }
+
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    for (int num = 0, cnt = 1; num < size; cnt++) {
+        int cur_lev = 5 * cnt;
+        int cur_dis = 5 * (20 - cnt);
+        for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++) {
+            o_ptr = &floor_ptr->o_list[i];
+
+            if (!object_is_valid(o_ptr))
+                continue;
+            if (k_info[o_ptr->k_idx].level > cur_lev)
+                continue;
+
+            POSITION y, x;
+            if (object_is_held_monster(o_ptr)) {
+                monster_type *m_ptr;
+                m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
+                y = m_ptr->fy;
+                x = m_ptr->fx;
+
+                if (randint0(100) < 90)
+                    continue;
+            } else {
+                y = o_ptr->iy;
+                x = o_ptr->ix;
+            }
+
+            if ((cur_dis > 0) && (distance(player_ptr->y, player_ptr->x, y, x) < cur_dis))
+                continue;
+
+            int chance = 90;
+            if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) && (cnt < 1000))
+                chance = 100;
+
+            if (randint0(100) < chance)
+                continue;
+
+            delete_object_idx(player_ptr, i);
+            num++;
+        }
+    }
+
+    for (OBJECT_IDX i = floor_ptr->o_max - 1; i >= 1; i--) {
+        o_ptr = &floor_ptr->o_list[i];
+        if (o_ptr->k_idx)
+            continue;
+
+        compact_objects_aux(floor_ptr, floor_ptr->o_max - 1, i);
+        floor_ptr->o_max--;
+    }
 }
 
-
 /*!
  * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
  * @param player_ptr プレーヤーへの参照ポインタ
@@ -1606,13 +1502,11 @@ void compact_objects(player_type *player_ptr, int size)
  */
 void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
 {
-       for (int i = 0; i < num; i++)
-       {
-               vault_trap_aux(player_ptr, y, x, yd, xd);
-       }
+    for (int i = 0; i < num; i++) {
+        vault_trap_aux(player_ptr, y, x, yd, xd);
+    }
 }
 
-
 /*
  * Standard "find me a location" function
  *
@@ -1626,24 +1520,26 @@ void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, P
  */
 void scatter(player_type *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
 {
-       floor_type *floor_ptr = player_ptr->current_floor_ptr;
-       POSITION nx, ny;
-       while (TRUE)
-       {
-               ny = rand_spread(y, d);
-               nx = rand_spread(x, d);
-
-               if (!in_bounds(floor_ptr, ny, nx)) continue;
-               if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
-               if (mode & PROJECT_LOS)
-               {
-                       if (los(player_ptr, y, x, ny, nx)) break;
-                       continue;
-               }
-
-               if (projectable(player_ptr, y, x, ny, nx)) break;
-       }
-
-       *yp = ny;
-       *xp = nx;
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    POSITION nx, ny;
+    while (TRUE) {
+        ny = rand_spread(y, d);
+        nx = rand_spread(x, d);
+
+        if (!in_bounds(floor_ptr, ny, nx))
+            continue;
+        if ((d > 1) && (distance(y, x, ny, nx) > d))
+            continue;
+        if (mode & PROJECT_LOS) {
+            if (los(player_ptr, y, x, ny, nx))
+                break;
+            continue;
+        }
+
+        if (projectable(player_ptr, y, x, ny, nx))
+            break;
+    }
+
+    *yp = ny;
+    *xp = nx;
 }
index 9c66529..8e991ce 100644 (file)
@@ -12,6 +12,7 @@
 #include "grid/grid.h"
 #include "io/screen-util.h"
 #include "system/floor-type-definition.h"
+#include "target/target-preparation.h"
 #include "target/targeting.h"
 #include "term/term-color-types.h"
 #include "view/display-map.h"
@@ -43,7 +44,8 @@ void print_path(player_type *player_ptr, POSITION y, POSITION x)
         return;
 
     floor_type *floor_ptr = player_ptr->current_floor_ptr;
-    int path_n = project_path(player_ptr, path_g, (project_length ? project_length : get_max_range(player_ptr)), player_ptr->y, player_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
+    int path_n = project_path(
+        player_ptr, path_g, (project_length ? project_length : get_max_range(player_ptr)), player_ptr->y, player_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
     player_ptr->redraw |= (PR_MAP);
     handle_stuff(player_ptr);
     for (int i = 0; i < path_n; i++) {
index 7e920d8..24e09f5 100644 (file)
@@ -21,6 +21,7 @@
 #include "spell/process-effect.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
+#include "target/target-preparation.h"
 #include "target/targeting.h"
 #include "term/gameterm.h"
 #include "util/bit-flags-calculator.h"
index 9924aa6..873a3b5 100644 (file)
@@ -29,7 +29,7 @@
 #include "spell-kind/spells-world.h"
 #include "spell-realm/spells-hex.h"
 #include "system/floor-type-definition.h"
-#include "target/targeting.h"
+#include "target/target-preparation.h"
 #include "view/display-messages.h"
 #include "world/world.h"
 #ifdef JP
index 2a76b61..c3a2993 100644 (file)
@@ -51,7 +51,7 @@
 #include "spell/range-calc.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
-#include "target/targeting.h"
+#include "target/target-preparation.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 #include "world/world.h"
index 6ecf649..8e87926 100644 (file)
@@ -28,7 +28,7 @@
 #include "spell/range-calc.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
-#include "target/targeting.h"
+#include "target/target-preparation.h"
 
 /*!
  * @brief モンスターが敵対モンスターにビームを当てること可能かを判定する /
index 84d9f68..0552291 100644 (file)
@@ -24,7 +24,7 @@
 #include "spell/range-calc.h"
 #include "system/floor-type-definition.h"
 #include "system/monster-type-definition.h"
-#include "target/targeting.h"
+#include "target/target-preparation.h"
 #include "util/bit-flags-calculator.h"
 
 /*!
index 1f408de..e9b2ba9 100644 (file)
@@ -15,6 +15,7 @@
 #include "monster/monster-update.h"
 #include "system/floor-type-definition.h"
 #include "system/object-type-definition.h"
+#include "target/target-preparation.h"
 #include "target/target-types.h"
 #include "target/targeting.h"
 #include "util/bit-flags-calculator.h"
index 1b34107..9fa943b 100644 (file)
@@ -17,7 +17,7 @@
 #include "spell/process-effect.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
-#include "target/targeting.h"
+#include "target/target-preparation.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 #include "world/world.h"
index 31a0535..0c30f0b 100644 (file)
@@ -19,6 +19,7 @@
 #include "spell/range-calc.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
+#include "target/target-preparation.h"
 #include "target/targeting.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
index 339b7c6..82c3cdb 100644 (file)
@@ -24,7 +24,7 @@
 #include "spell/range-calc.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
-#include "target/targeting.h"
+#include "target/target-preparation.h"
 #include "term/gameterm.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
diff --git a/src/target/target-preparation.c b/src/target/target-preparation.c
new file mode 100644 (file)
index 0000000..f575f86
--- /dev/null
@@ -0,0 +1,158 @@
+#include "target/target-preparation.h"
+#include "floor/cave.h"
+#include "floor/floor.h" // todo 相互依存.
+#include "game-option/input-options.h"
+#include "grid/feature.h"
+#include "grid/grid.h"
+#include "monster/monster-info.h"
+#include "monster/monster-status.h"
+#include "object/object-mark-types.h"
+#include "system/floor-type-definition.h"
+#include "system/object-type-definition.h"
+#include "target/target-types.h"
+#include "util/bit-flags-calculator.h"
+#include "util/sort.h"
+#include "window/main-window-util.h"
+
+/*
+ * Determine is a monster makes a reasonable target
+ *
+ * The concept of "targeting" was stolen from "Morgul" (?)
+ *
+ * The player can target any location, or any "target-able" monster.
+ *
+ * Currently, a monster is "target_able" if it is visible, and if
+ * the player can hit it with a projection, and the player is not
+ * hallucinating.  This allows use of "use closest target" macros.
+ *
+ * Future versions may restrict the ability to target "trappers"
+ * and "mimics", but the semantics is a little bit weird.
+ */
+bool target_able(player_type *creature_ptr, MONSTER_IDX m_idx)
+{
+    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+    monster_type *m_ptr = &floor_ptr->m_list[m_idx];
+    if (!monster_is_valid(m_ptr))
+        return FALSE;
+
+    if (creature_ptr->image)
+        return FALSE;
+
+    if (!m_ptr->ml)
+        return FALSE;
+
+    if (creature_ptr->riding && (creature_ptr->riding == m_idx))
+        return TRUE;
+
+    if (!projectable(creature_ptr, creature_ptr->y, creature_ptr->x, m_ptr->fy, m_ptr->fx))
+        return FALSE;
+
+    return TRUE;
+}
+
+/*!
+ * @briefプレイヤーの攻撃射程(マス) / Maximum range (spells, etc)
+ * @param creature_ptr プレーヤーへの参照ポインタ
+ * @return 射程
+ */
+int get_max_range(player_type *creature_ptr) { return creature_ptr->phase_out ? 36 : 18; }
+
+/*
+ * Determine if a given location is "interesting"
+ */
+static bool target_set_accept(player_type *creature_ptr, POSITION y, POSITION x)
+{
+    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+    if (!(in_bounds(floor_ptr, y, x)))
+        return FALSE;
+
+    if (player_bold(creature_ptr, y, x))
+        return TRUE;
+
+    if (creature_ptr->image)
+        return FALSE;
+
+    grid_type *g_ptr;
+    g_ptr = &floor_ptr->grid_array[y][x];
+    if (g_ptr->m_idx) {
+        monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
+        if (m_ptr->ml)
+            return TRUE;
+    }
+
+    OBJECT_IDX next_o_idx = 0;
+    for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
+        object_type *o_ptr;
+        o_ptr = &floor_ptr->o_list[this_o_idx];
+        next_o_idx = o_ptr->next_o_idx;
+        if (o_ptr->marked & OM_FOUND)
+            return TRUE;
+    }
+
+    if (g_ptr->info & (CAVE_MARK)) {
+        if (g_ptr->info & CAVE_OBJECT)
+            return TRUE;
+
+        if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE))
+            return TRUE;
+    }
+
+    return FALSE;
+}
+
+/*
+ * Prepare the "temp" array for "target_set"
+ *
+ * Return the number of target_able monsters in the set.
+ */
+void target_set_prepare(player_type *creature_ptr, BIT_FLAGS mode)
+{
+    POSITION min_hgt, max_hgt, min_wid, max_wid;
+    if (mode & TARGET_KILL) {
+        min_hgt = MAX((creature_ptr->y - get_max_range(creature_ptr)), 0);
+        max_hgt = MIN((creature_ptr->y + get_max_range(creature_ptr)), creature_ptr->current_floor_ptr->height - 1);
+        min_wid = MAX((creature_ptr->x - get_max_range(creature_ptr)), 0);
+        max_wid = MIN((creature_ptr->x + get_max_range(creature_ptr)), creature_ptr->current_floor_ptr->width - 1);
+    } else {
+        min_hgt = panel_row_min;
+        max_hgt = panel_row_max;
+        min_wid = panel_col_min;
+        max_wid = panel_col_max;
+    }
+
+    tmp_pos.n = 0;
+    for (POSITION y = min_hgt; y <= max_hgt; y++) {
+        for (POSITION x = min_wid; x <= max_wid; x++) {
+            grid_type *g_ptr;
+            if (!target_set_accept(creature_ptr, y, x))
+                continue;
+
+            g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
+            if ((mode & (TARGET_KILL)) && !target_able(creature_ptr, g_ptr->m_idx))
+                continue;
+
+            if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx]))
+                continue;
+
+            tmp_pos.x[tmp_pos.n] = x;
+            tmp_pos.y[tmp_pos.n] = y;
+            tmp_pos.n++;
+        }
+    }
+
+    if (mode & (TARGET_KILL)) {
+        ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
+    } else {
+        ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
+    }
+
+    if (creature_ptr->riding == 0 || !target_pet || (tmp_pos.n <= 1) || !(mode & (TARGET_KILL)))
+        return;
+
+    POSITION tmp = tmp_pos.y[0];
+    tmp_pos.y[0] = tmp_pos.y[1];
+    tmp_pos.y[1] = tmp;
+    tmp = tmp_pos.x[0];
+    tmp_pos.x[0] = tmp_pos.x[1];
+    tmp_pos.x[1] = tmp;
+}
diff --git a/src/target/target-preparation.h b/src/target/target-preparation.h
new file mode 100644 (file)
index 0000000..0efddb6
--- /dev/null
@@ -0,0 +1,7 @@
+#pragma once
+
+#include "system/angband.h"
+
+bool target_able(player_type *creature_ptr, MONSTER_IDX m_idx);
+int get_max_range(player_type *creature_ptr);
+void target_set_prepare(player_type *creature_ptr, BIT_FLAGS mode);
index ecdcee0..11df759 100644 (file)
@@ -64,6 +64,7 @@
 #include "system/floor-type-definition.h"
 #include "system/system-variables.h"
 #include "target/target-describer.h"
+#include "target/target-preparation.h"
 #include "target/target-types.h"
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
@@ -174,42 +175,6 @@ void verify_panel(player_type *creature_ptr)
     creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
 }
 
-/*
- * Determine is a monster makes a reasonable target
- *
- * The concept of "targeting" was stolen from "Morgul" (?)
- *
- * The player can target any location, or any "target-able" monster.
- *
- * Currently, a monster is "target_able" if it is visible, and if
- * the player can hit it with a projection, and the player is not
- * hallucinating.  This allows use of "use closest target" macros.
- *
- * Future versions may restrict the ability to target "trappers"
- * and "mimics", but the semantics is a little bit weird.
- */
-bool target_able(player_type *creature_ptr, MONSTER_IDX m_idx)
-{
-    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
-    monster_type *m_ptr = &floor_ptr->m_list[m_idx];
-    if (!monster_is_valid(m_ptr))
-        return FALSE;
-
-    if (creature_ptr->image)
-        return FALSE;
-
-    if (!m_ptr->ml)
-        return FALSE;
-
-    if (creature_ptr->riding && (creature_ptr->riding == m_idx))
-        return TRUE;
-
-    if (!projectable(creature_ptr, creature_ptr->y, creature_ptr->x, m_ptr->fy, m_ptr->fx))
-        return FALSE;
-
-    return TRUE;
-}
-
 /* Targetting variables */
 MONSTER_IDX target_who;
 POSITION target_col;
@@ -236,108 +201,6 @@ bool target_okay(player_type *creature_ptr)
     return TRUE;
 }
 
-/*
- * Determine if a given location is "interesting"
- */
-static bool target_set_accept(player_type *creature_ptr, POSITION y, POSITION x)
-{
-    floor_type *floor_ptr = creature_ptr->current_floor_ptr;
-    if (!(in_bounds(floor_ptr, y, x)))
-        return FALSE;
-
-    if (player_bold(creature_ptr, y, x))
-        return TRUE;
-
-    if (creature_ptr->image)
-        return FALSE;
-
-    grid_type *g_ptr;
-    g_ptr = &floor_ptr->grid_array[y][x];
-    if (g_ptr->m_idx) {
-        monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
-        if (m_ptr->ml)
-            return TRUE;
-    }
-
-    OBJECT_IDX next_o_idx = 0;
-    for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
-        object_type *o_ptr;
-        o_ptr = &floor_ptr->o_list[this_o_idx];
-        next_o_idx = o_ptr->next_o_idx;
-        if (o_ptr->marked & OM_FOUND)
-            return TRUE;
-    }
-
-    if (g_ptr->info & (CAVE_MARK)) {
-        if (g_ptr->info & CAVE_OBJECT)
-            return TRUE;
-
-        if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE))
-            return TRUE;
-    }
-
-    return FALSE;
-}
-
-/*
- * Prepare the "temp" array for "target_set"
- *
- * Return the number of target_able monsters in the set.
- */
-static void target_set_prepare(player_type *creature_ptr, BIT_FLAGS mode)
-{
-    POSITION min_hgt, max_hgt, min_wid, max_wid;
-    if (mode & TARGET_KILL) {
-        min_hgt = MAX((creature_ptr->y - get_max_range(creature_ptr)), 0);
-        max_hgt = MIN((creature_ptr->y + get_max_range(creature_ptr)), creature_ptr->current_floor_ptr->height - 1);
-        min_wid = MAX((creature_ptr->x - get_max_range(creature_ptr)), 0);
-        max_wid = MIN((creature_ptr->x + get_max_range(creature_ptr)), creature_ptr->current_floor_ptr->width - 1);
-    } else {
-        min_hgt = panel_row_min;
-        max_hgt = panel_row_max;
-        min_wid = panel_col_min;
-        max_wid = panel_col_max;
-    }
-
-    tmp_pos.n = 0;
-    for (POSITION y = min_hgt; y <= max_hgt; y++) {
-        for (POSITION x = min_wid; x <= max_wid; x++) {
-            grid_type *g_ptr;
-            if (!target_set_accept(creature_ptr, y, x))
-                continue;
-
-            g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
-            if ((mode & (TARGET_KILL)) && !target_able(creature_ptr, g_ptr->m_idx))
-                continue;
-
-            if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx]))
-                continue;
-
-            tmp_pos.x[tmp_pos.n] = x;
-            tmp_pos.y[tmp_pos.n] = y;
-            tmp_pos.n++;
-        }
-    }
-
-    if (mode & (TARGET_KILL)) {
-        ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
-    } else {
-        ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
-    }
-
-    if (creature_ptr->riding == 0 || !target_pet || (tmp_pos.n <= 1) || !(mode & (TARGET_KILL)))
-        return;
-
-    POSITION tmp = tmp_pos.y[0];
-    tmp_pos.y[0] = tmp_pos.y[1];
-    tmp_pos.y[1] = tmp;
-    tmp = tmp_pos.x[0];
-    tmp_pos.x[0] = tmp_pos.x[1];
-    tmp_pos.x[1] = tmp;
-}
-
-void target_set_prepare_look(player_type *creature_ptr) { target_set_prepare(creature_ptr, TARGET_LOOK); }
-
 /*!
  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
  * @param creature_ptr プレーヤーへの参照ポインタ
@@ -1128,10 +991,3 @@ bool tgt_pt(player_type *creature_ptr, POSITION *x_ptr, POSITION *y_ptr)
     *y_ptr = y;
     return success;
 }
-
-/*!
- * @briefプレイヤーの攻撃射程(マス) / Maximum range (spells, etc)
- * @param creature_ptr プレーヤーへの参照ポインタ
- * @return 射程
- */
-int get_max_range(player_type *creature_ptr) { return creature_ptr->phase_out ? 36 : 18; }
index 7d2f975..f8d43c9 100644 (file)
@@ -11,11 +11,8 @@ bool target_set(player_type *creature_ptr, target_type mode);
 
 void panel_bounds_center(void);
 void verify_panel(player_type *creature_ptr);
-bool target_able(player_type *creature_ptr, MONSTER_IDX m_idx);
 bool target_okay(player_type *creature_ptr);
-void target_set_prepare_look(player_type *creature_ptr);
 bool get_aim_dir(player_type *creature_ptr, DIRECTION *dp);
 bool get_direction(player_type *creature_ptr, DIRECTION *dp, bool allow_under, bool with_steed);
 bool get_rep_dir(player_type *creature_ptr, DIRECTION *dp, bool under);
 bool tgt_pt(player_type *creature_ptr, POSITION *x, POSITION *y);
-int get_max_range(player_type *creature_ptr);
index 17d9748..0dc6c63 100644 (file)
@@ -19,7 +19,8 @@
 #include "spell-kind/magic-item-recharger.h"
 #include "system/floor-type-definition.h"
 #include "system/monster-type-definition.h"
-#include "target/targeting.h"
+#include "target/target-preparation.h"
+#include "target/target-types.h"
 #include "term/gameterm.h"
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
@@ -174,14 +175,14 @@ void fix_monster_list(player_type *player_ptr)
         term_type *old = Term;
         if (!angband_term[j])
             continue;
-        if (!(window_flag[j] & (PW_MONSTER_LIST)))
+        if (!(window_flag[j] & PW_MONSTER_LIST))
             continue;
 
         term_activate(angband_term[j]);
         int w, h;
         term_get_size(&w, &h);
         term_clear();
-        target_set_prepare_look(player_ptr);
+        target_set_prepare(player_ptr, TARGET_LOOK);
         print_monster_list(player_ptr->current_floor_ptr, 0, 0, h);
         term_fresh();
         term_activate(old);