OSDN Git Service

[Refactor] #3681 terrains_info[] へアクセスしている周辺のコードを参照を使う形にまとめた その6
authorHourier <66951241+Hourier@users.noreply.github.com>
Wed, 1 Nov 2023 12:03:14 +0000 (21:03 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Thu, 2 Nov 2023 13:30:18 +0000 (22:30 +0900)
src/floor/cave-generator.cpp
src/floor/wild.cpp
src/grid/door.cpp

index 20dbe84..ddeb231 100644 (file)
@@ -129,16 +129,14 @@ static bool decide_tunnel_planned_site(PlayerType *player_ptr, dun_data_type *dd
 
 static void make_tunnels(PlayerType *player_ptr, dun_data_type *dd_ptr)
 {
-    for (int j = 0; j < dd_ptr->tunn_n; j++) {
-        Grid *g_ptr;
-        TerrainType *f_ptr;
-        dd_ptr->tunnel_y = dd_ptr->tunn[j].y;
-        dd_ptr->tunnel_x = dd_ptr->tunn[j].x;
-        g_ptr = &player_ptr->current_floor_ptr->grid_array[dd_ptr->tunnel_y][dd_ptr->tunnel_x];
-        f_ptr = &terrains_info[g_ptr->feat];
-        if (f_ptr->flags.has_not(TerrainCharacteristics::MOVE) || f_ptr->flags.has_none_of({ TerrainCharacteristics::WATER, TerrainCharacteristics::LAVA })) {
-            g_ptr->mimic = 0;
-            place_grid(player_ptr, g_ptr, GB_FLOOR);
+    for (auto i = 0; i < dd_ptr->tunn_n; i++) {
+        dd_ptr->tunnel_y = dd_ptr->tunn[i].y;
+        dd_ptr->tunnel_x = dd_ptr->tunn[i].x;
+        auto &grid = player_ptr->current_floor_ptr->grid_array[dd_ptr->tunnel_y][dd_ptr->tunnel_x];
+        const auto &terrain = terrains_info[grid.feat];
+        if (terrain.flags.has_not(TerrainCharacteristics::MOVE) || terrain.flags.has_none_of({ TerrainCharacteristics::WATER, TerrainCharacteristics::LAVA })) {
+            grid.mimic = 0;
+            place_grid(player_ptr, &grid, GB_FLOOR);
         }
     }
 }
@@ -294,8 +292,8 @@ static void place_bound_perm_wall(PlayerType *player_ptr, Grid *g_ptr)
         return;
     }
 
-    auto *f_ptr = &terrains_info[g_ptr->feat];
-    if (f_ptr->flags.has_any_of({ TerrainCharacteristics::HAS_GOLD, TerrainCharacteristics::HAS_ITEM }) && f_ptr->flags.has_not(TerrainCharacteristics::SECRET)) {
+    const auto &terrain = terrains_info[g_ptr->feat];
+    if (terrain.flags.has_any_of({ TerrainCharacteristics::HAS_GOLD, TerrainCharacteristics::HAS_ITEM }) && terrain.flags.has_not(TerrainCharacteristics::SECRET)) {
         g_ptr->feat = feat_state(player_ptr->current_floor_ptr, g_ptr->feat, TerrainCharacteristics::ENSECRET);
     }
 
index 292ac91..8dd9957 100644 (file)
@@ -89,7 +89,7 @@ static int16_t conv_terrain2feat[MAX_WILDERNESS];
  */
 static void set_floor_and_wall_aux(int16_t feat_type[100], const std::array<feat_prob, DUNGEON_FEAT_PROB_NUM> &prob)
 {
-    int lim[DUNGEON_FEAT_PROB_NUM];
+    std::array<int, DUNGEON_FEAT_PROB_NUM> lim{};
     lim[0] = prob[0].percent;
     for (int i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) {
         lim[i] = lim[i - 1] + prob[i].percent;
index 7517fa4..ed91d95 100644 (file)
@@ -63,10 +63,11 @@ void add_door(PlayerType *player_ptr, POSITION x, POSITION y)
  */
 void place_secret_door(PlayerType *player_ptr, POSITION y, POSITION x, int type)
 {
-    auto *floor_ptr = player_ptr->current_floor_ptr;
-    const auto &dungeon = floor_ptr->get_dungeon_definition();
+    auto &floor = *player_ptr->current_floor_ptr;
+    const Pos2D pos(y, x);
+    const auto &dungeon = floor.get_dungeon_definition();
     if (dungeon.flags.has(DungeonFeatureType::NO_DOORS)) {
-        place_bold(player_ptr, y, x, GB_FLOOR);
+        place_bold(player_ptr, pos.y, pos.x, GB_FLOOR);
         return;
     }
 
@@ -76,21 +77,21 @@ void place_secret_door(PlayerType *player_ptr, POSITION y, POSITION x, int type)
                    : (dungeon.flags.has(DungeonFeatureType::GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
     }
 
-    place_closed_door(player_ptr, y, x, type);
-    auto *g_ptr = &floor_ptr->grid_array[y][x];
+    place_closed_door(player_ptr, pos.y, pos.x, type);
+    auto &grid = floor.get_grid(pos);
     if (type != DOOR_CURTAIN) {
-        g_ptr->mimic = feat_wall_inner;
-        if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat)) {
-            if (terrains_info[g_ptr->mimic].flags.has(TerrainCharacteristics::MOVE) || terrains_info[g_ptr->mimic].flags.has(TerrainCharacteristics::CAN_FLY)) {
-                g_ptr->feat = one_in_(2) ? g_ptr->mimic : rand_choice(feat_ground_type);
+        grid.mimic = feat_wall_inner;
+        if (feat_supports_los(grid.mimic) && !feat_supports_los(grid.feat)) {
+            if (terrains_info[grid.mimic].flags.has(TerrainCharacteristics::MOVE) || terrains_info[grid.mimic].flags.has(TerrainCharacteristics::CAN_FLY)) {
+                grid.feat = one_in_(2) ? grid.mimic : rand_choice(feat_ground_type);
             }
 
-            g_ptr->mimic = 0;
+            grid.mimic = 0;
         }
     }
 
-    g_ptr->info &= ~(CAVE_FLOOR);
-    delete_monster(player_ptr, y, x);
+    grid.info &= ~(CAVE_FLOOR);
+    delete_monster(player_ptr, pos.y, pos.x);
 }
 
 /*!
@@ -122,10 +123,11 @@ void place_locked_door(PlayerType *player_ptr, POSITION y, POSITION x)
  */
 void place_random_door(PlayerType *player_ptr, POSITION y, POSITION x, bool room)
 {
-    auto *floor_ptr = player_ptr->current_floor_ptr;
-    auto *g_ptr = &floor_ptr->grid_array[y][x];
-    g_ptr->mimic = 0;
-    const auto &dungeon = floor_ptr->get_dungeon_definition();
+    const Pos2D pos(y, x);
+    auto &floor = *player_ptr->current_floor_ptr;
+    auto &grid = floor.get_grid(pos);
+    grid.mimic = 0;
+    const auto &dungeon = floor.get_dungeon_definition();
     if (dungeon.flags.has(DungeonFeatureType::NO_DOORS)) {
         place_bold(player_ptr, y, x, GB_FLOOR);
         return;
@@ -143,14 +145,14 @@ void place_random_door(PlayerType *player_ptr, POSITION y, POSITION x, bool room
         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 : rand_choice(feat_wall_type);
-            if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat)) {
-                if (terrains_info[g_ptr->mimic].flags.has(TerrainCharacteristics::MOVE) || terrains_info[g_ptr->mimic].flags.has(TerrainCharacteristics::CAN_FLY)) {
-                    g_ptr->feat = one_in_(2) ? g_ptr->mimic : rand_choice(feat_ground_type);
+            grid.mimic = room ? feat_wall_outer : rand_choice(feat_wall_type);
+            if (feat_supports_los(grid.mimic) && !feat_supports_los(grid.feat)) {
+                const auto &terrain_mimic = terrains_info[grid.mimic];
+                if (terrain_mimic.flags.has(TerrainCharacteristics::MOVE) || terrain_mimic.flags.has(TerrainCharacteristics::CAN_FLY)) {
+                    grid.feat = one_in_(2) ? grid.mimic : rand_choice(feat_ground_type);
                 }
-                g_ptr->mimic = 0;
+                grid.mimic = 0;
             }
         }
     } else {
@@ -165,7 +167,7 @@ void place_random_door(PlayerType *player_ptr, POSITION y, POSITION x, bool room
     if (feat == feat_none) {
         place_bold(player_ptr, y, x, GB_FLOOR);
     } else {
-        set_cave_feat(floor_ptr, y, x, feat);
+        set_cave_feat(&floor, y, x, feat);
     }
 
     delete_monster(player_ptr, y, x);