OSDN Git Service

[Refactor] #3722 terrains_info[] へアクセスしている周辺のコードを参照を使う形にまとめた その24
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 28 Oct 2023 11:54:09 +0000 (20:54 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Tue, 7 Nov 2023 12:11:39 +0000 (21:11 +0900)
src/action/movement-execution.cpp
src/action/run-execution.cpp
src/floor/cave.cpp
src/floor/floor-streams.cpp
src/floor/pattern-walk.cpp
src/monster/monster-util.cpp
src/player/player-status.cpp
src/spell-kind/spells-floor.cpp

index 6b0ccdc..16d5bd6 100644 (file)
@@ -233,7 +233,9 @@ void exe_movement(PlayerType *player_ptr, DIRECTION dir, bool do_pickup, bool br
             can_move = false;
             disturb(player_ptr, false, true);
         } else if (terrain.flags.has_not(TerrainCharacteristics::WATER) && riding_r_ptr->feature_flags.has(MonsterFeatureType::AQUATIC)) {
-            msg_print(_(format("%sから上がれない。", terrains_info[floor.grid_array[player_ptr->y][player_ptr->x].get_feat_mimic()].name.data()), "Can't land."));
+            constexpr auto fmt = _("%sから上がれない。", "Can't land from %s.");
+            const auto p_pos = player_ptr->get_position();
+            msg_format(fmt, terrains_info[floor.get_grid(p_pos).get_feat_mimic()].name.data());
             energy.reset_player_turn();
             can_move = false;
             disturb(player_ptr, false, true);
index d05296f..9c2f4e1 100644 (file)
@@ -68,7 +68,7 @@ static bool see_wall(PlayerType *player_ptr, DIRECTION dir, POSITION y, POSITION
         return false;
     }
 
-    int16_t feat = grid.get_feat_mimic();
+    const auto feat = grid.get_feat_mimic();
     const auto &terrain = terrains_info[feat];
     if (!player_can_enter(player_ptr, feat, 0)) {
         return terrain.flags.has_not(TerrainCharacteristics::DOOR);
@@ -200,12 +200,14 @@ static bool see_nothing(PlayerType *player_ptr, DIRECTION dir, POSITION y, POSIT
  */
 static bool run_test(PlayerType *player_ptr)
 {
-    DIRECTION prev_dir = find_prevdir;
-    int max = (prev_dir & 0x01) + 1;
-    auto *floor_ptr = player_ptr->current_floor_ptr;
-    if ((disturb_trap_detect || alert_trap_detect) && player_ptr->dtrap && !(floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_IN_DETECT)) {
+    const auto prev_dir = find_prevdir;
+    const auto max = (prev_dir & 0x01) + 1;
+    const auto &floor = *player_ptr->current_floor_ptr;
+    const auto p_pos = player_ptr->get_position();
+    const auto &p_grid = floor.get_grid(p_pos);
+    if ((disturb_trap_detect || alert_trap_detect) && player_ptr->dtrap && !(p_grid.info & CAVE_IN_DETECT)) {
         player_ptr->dtrap = false;
-        if (!(floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_UNSAFE)) {
+        if (!(p_grid.info & CAVE_UNSAFE)) {
             if (alert_trap_detect) {
                 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
             }
@@ -217,34 +219,31 @@ static bool run_test(PlayerType *player_ptr)
         }
     }
 
-    DIRECTION check_dir = 0;
-    int option = 0, option2 = 0;
-    for (int i = -max; i <= max; i++) {
-        DIRECTION new_dir = cycle[chome[prev_dir] + i];
-        int row = player_ptr->y + ddy[new_dir];
-        int col = player_ptr->x + ddx[new_dir];
-        Grid *g_ptr;
-        g_ptr = &floor_ptr->grid_array[row][col];
-        FEAT_IDX feat = g_ptr->get_feat_mimic();
-        const auto &terrain = terrains_info[feat];
-        if (g_ptr->m_idx) {
-            auto *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
-            if (m_ptr->ml) {
+    auto check_dir = 0;
+    auto option = 0;
+    auto option2 = 0;
+    for (auto i = -max; i <= max; i++) {
+        int new_dir = cycle[chome[prev_dir] + i];
+        const Pos2D pos(player_ptr->y + ddy[new_dir], player_ptr->x + ddx[new_dir]);
+        const auto &grid = floor.get_grid(pos);
+        const auto &terrain = terrains_info[grid.get_feat_mimic()];
+        if (grid.m_idx) {
+            const auto &monster = floor.m_list[grid.m_idx];
+            if (monster.ml) {
                 return true;
             }
         }
 
-        for (const auto this_o_idx : g_ptr->o_idx_list) {
-            ItemEntity *o_ptr;
-            o_ptr = &floor_ptr->o_list[this_o_idx];
-            if (o_ptr->marked.has(OmType::FOUND)) {
+        for (const auto this_o_idx : grid.o_idx_list) {
+            const auto &item = floor.o_list[this_o_idx];
+            if (item.marked.has(OmType::FOUND)) {
                 return true;
             }
         }
 
-        bool inv = true;
-        if (g_ptr->is_mark()) {
-            bool notice = terrain.flags.has(TerrainCharacteristics::NOTICE);
+        auto inv = true;
+        if (grid.is_mark()) {
+            auto notice = terrain.flags.has(TerrainCharacteristics::NOTICE);
             if (notice && terrain.flags.has(TerrainCharacteristics::MOVE)) {
                 if (find_ignore_doors && terrain.flags.has_all_of({ TerrainCharacteristics::DOOR, TerrainCharacteristics::CLOSE })) {
                     notice = false;
@@ -264,7 +263,7 @@ static bool run_test(PlayerType *player_ptr)
             inv = false;
         }
 
-        if (!inv && see_wall(player_ptr, 0, row, col)) {
+        if (!inv && see_wall(player_ptr, 0, pos.y, pos.x)) {
             if (find_openarea) {
                 if (i < 0) {
                     find_breakright = true;
index b4c611c..b55c2ca 100644 (file)
@@ -74,7 +74,8 @@ bool is_cave_empty_bold2(PlayerType *player_ptr, int y, int x)
 
 bool cave_has_flag_bold(const FloorType *floor_ptr, int y, int x, TerrainCharacteristics f_idx)
 {
-    return terrains_info[floor_ptr->grid_array[y][x].feat].flags.has(f_idx);
+    const Pos2D pos(y, x);
+    return terrains_info[floor_ptr->get_grid(pos).feat].flags.has(f_idx);
 }
 
 /*
index c186085..5f8a1b0 100644 (file)
@@ -174,10 +174,8 @@ static void recursive_river(FloorType *floor_ptr, POSITION x1, POSITION y1, POSI
  */
 void add_river(FloorType *floor_ptr, dun_data_type *dd_ptr)
 {
-    POSITION y2, x2;
-    POSITION y1 = 0, x1 = 0;
-    POSITION wid;
-    FEAT_IDX feat1 = 0, feat2 = 0;
+    short feat1 = 0;
+    short feat2 = 0;
 
     const auto &dungeon = floor_ptr->get_dungeon_definition();
 
@@ -187,10 +185,9 @@ void add_river(FloorType *floor_ptr, dun_data_type *dd_ptr)
         feat2 = feat_shallow_water;
     } else /* others */
     {
-        FEAT_IDX select_deep_feat[10];
-        FEAT_IDX select_shallow_feat[10];
-        int select_id_max = 0, selected;
-
+        short select_deep_feat[10]{};
+        short select_shallow_feat[10]{};
+        auto select_id_max = 0;
         if (dungeon.flags.has(DungeonFeatureType::LAVA_RIVER)) {
             select_deep_feat[select_id_max] = feat_deep_lava;
             select_shallow_feat[select_id_max] = feat_shallow_lava;
@@ -208,7 +205,7 @@ void add_river(FloorType *floor_ptr, dun_data_type *dd_ptr)
         }
 
         if (select_id_max > 0) {
-            selected = randint0(select_id_max);
+            const auto selected = randint0(select_id_max);
             feat1 = select_deep_feat[selected];
             feat2 = select_shallow_feat[selected];
         } else {
@@ -229,10 +226,12 @@ void add_river(FloorType *floor_ptr, dun_data_type *dd_ptr)
     }
 
     /* Hack -- Choose starting point */
-    y2 = randint1(floor_ptr->height / 2 - 2) + floor_ptr->height / 2;
-    x2 = randint1(floor_ptr->width / 2 - 2) + floor_ptr->width / 2;
+    const auto y2 = randint1(floor_ptr->height / 2 - 2) + floor_ptr->height / 2;
+    const auto x2 = randint1(floor_ptr->width / 2 - 2) + floor_ptr->width / 2;
 
     /* Hack -- Choose ending point somewhere on boundary */
+    auto y1 = 0;
+    auto x1 = 0;
     switch (randint1(4)) {
     case 1: {
         /* top boundary */
@@ -261,7 +260,7 @@ void add_river(FloorType *floor_ptr, dun_data_type *dd_ptr)
     }
 
     constexpr auto width_rivers = 2;
-    wid = randint1(width_rivers);
+    const auto wid = randint1(width_rivers);
     recursive_river(floor_ptr, x1, y1, x2, y2, feat1, feat2, wid);
 
     /* Hack - Save the location as a "room" */
index affa4f0..c9165dd 100644 (file)
@@ -109,7 +109,8 @@ void pattern_teleport(PlayerType *player_ptr)
 bool pattern_effect(PlayerType *player_ptr)
 {
     auto *floor_ptr = player_ptr->current_floor_ptr;
-    if (!pattern_tile(floor_ptr, player_ptr->y, player_ptr->x)) {
+    const auto p_pos = player_ptr->get_position();
+    if (!pattern_tile(floor_ptr, p_pos.y, p_pos.x)) {
         return false;
     }
 
@@ -118,7 +119,7 @@ bool pattern_effect(PlayerType *player_ptr)
         wreck_the_pattern(player_ptr);
     }
 
-    int pattern_type = terrains_info[floor_ptr->grid_array[player_ptr->y][player_ptr->x].feat].subtype;
+    int pattern_type = terrains_info[floor_ptr->get_grid(p_pos).feat].subtype;
     switch (pattern_type) {
     case PATTERN_TILE_END:
         (void)BadStatusSetter(player_ptr).hallucination(0);
index 5821e07..91d426d 100644 (file)
@@ -218,7 +218,8 @@ monsterrace_hook_type get_monster_hook(PlayerType *player_ptr)
  */
 monsterrace_hook_type get_monster_hook2(PlayerType *player_ptr, POSITION y, POSITION x)
 {
-    const auto &terrain = terrains_info[player_ptr->current_floor_ptr->grid_array[y][x].feat];
+    const Pos2D pos(y, x);
+    const auto &terrain = terrains_info[player_ptr->current_floor_ptr->get_grid(pos).feat];
     if (terrain.flags.has(TerrainCharacteristics::WATER)) {
         return terrain.flags.has(TerrainCharacteristics::DEEP) ? (monsterrace_hook_type)mon_hook_deep_water : (monsterrace_hook_type)mon_hook_shallow_water;
     }
index b4aa1a3..c8fadd6 100644 (file)
@@ -2831,7 +2831,8 @@ bool player_place(PlayerType *player_ptr, POSITION y, POSITION x)
 void wreck_the_pattern(PlayerType *player_ptr)
 {
     auto *floor_ptr = player_ptr->current_floor_ptr;
-    int pattern_type = terrains_info[floor_ptr->grid_array[player_ptr->y][player_ptr->x].feat].subtype;
+    const auto p_pos = player_ptr->get_position();
+    int pattern_type = terrains_info[floor_ptr->get_grid(p_pos).feat].subtype;
     if (pattern_type == PATTERN_TILE_WRECKED) {
         return;
     }
@@ -2843,13 +2844,14 @@ void wreck_the_pattern(PlayerType *player_ptr)
         take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(10, 8), _("パターン損壊", "corrupting the Pattern"));
     }
 
-    int to_ruin = randint1(45) + 35;
+    auto to_ruin = randint1(45) + 35;
     while (to_ruin--) {
-        POSITION r_y, r_x;
-        scatter(player_ptr, &r_y, &r_x, player_ptr->y, player_ptr->x, 4, PROJECT_NONE);
-
-        if (pattern_tile(floor_ptr, r_y, r_x) && (terrains_info[floor_ptr->grid_array[r_y][r_x].feat].subtype != PATTERN_TILE_WRECKED)) {
-            cave_set_feat(player_ptr, r_y, r_x, feat_pattern_corrupted);
+        int y;
+        int x;
+        scatter(player_ptr, &y, &x, player_ptr->y, player_ptr->x, 4, PROJECT_NONE);
+        const Pos2D pos(y, x);
+        if (pattern_tile(floor_ptr, pos.y, pos.x) && (terrains_info[floor_ptr->get_grid(pos).feat].subtype != PATTERN_TILE_WRECKED)) {
+            cave_set_feat(player_ptr, pos.y, pos.x, feat_pattern_corrupted);
         }
     }
 
index 9d5a049..7f13400 100644 (file)
@@ -435,24 +435,22 @@ bool destroy_area(PlayerType *player_ptr, const POSITION y1, const POSITION x1,
     }
 
     /* Process "re-glowing" */
-    for (POSITION y = (y1 - r); y <= (y1 + r); y++) {
-        for (POSITION x = (x1 - r); x <= (x1 + r); x++) {
-            if (!in_bounds(&floor, y, x)) {
+    for (auto y = (y1 - r); y <= (y1 + r); y++) {
+        for (auto x = (x1 - r); x <= (x1 + r); x++) {
+            const Pos2D pos(y, x);
+            if (!in_bounds(&floor, pos.y, pos.x)) {
                 continue;
             }
 
-            /* Extract the distance */
-            int k = distance(y1, x1, y, x);
-
             /* Stay in the circle of death */
+            auto k = distance(y1, x1, pos.y, pos.x);
             if (k > r) {
                 continue;
             }
-            Grid *g_ptr;
-            g_ptr = &floor.grid_array[y][x];
 
-            if (g_ptr->is_mirror()) {
-                g_ptr->info |= CAVE_GLOW;
+            auto &grid = floor.get_grid(pos);
+            if (grid.is_mirror()) {
+                grid.info |= CAVE_GLOW;
                 continue;
             }
 
@@ -460,19 +458,15 @@ bool destroy_area(PlayerType *player_ptr, const POSITION y1, const POSITION x1,
                 continue;
             }
 
-            DIRECTION i;
-            POSITION yy, xx;
-            Grid *cc_ptr;
-
-            for (i = 0; i < 9; i++) {
-                yy = y + ddy_ddd[i];
-                xx = x + ddx_ddd[i];
-                if (!in_bounds2(&floor, yy, xx)) {
+            for (auto i = 0; i < 9; i++) {
+                const Pos2D pos_neighbor(pos.y + ddy_ddd[i], pos.x + ddx_ddd[i]);
+                if (!in_bounds2(&floor, pos_neighbor.y, pos_neighbor.x)) {
                     continue;
                 }
-                cc_ptr = &floor.grid_array[yy][xx];
-                if (terrains_info[cc_ptr->get_feat_mimic()].flags.has(TerrainCharacteristics::GLOW)) {
-                    g_ptr->info |= CAVE_GLOW;
+
+                const auto &grid_neighbor = floor.get_grid(pos_neighbor);
+                if (terrains_info[grid_neighbor.get_feat_mimic()].flags.has(TerrainCharacteristics::GLOW)) {
+                    grid.info |= CAVE_GLOW;
                     break;
                 }
             }