OSDN Git Service

[Refactor] path_g を projection_path クラスに変更
authorSlimebreath6078 <slimebreath6078@yahoo.co.jp>
Wed, 16 Mar 2022 10:23:33 +0000 (19:23 +0900)
committerSlimebreath6078 <slimebreath6078@yahoo.co.jp>
Sun, 20 Mar 2022 03:56:47 +0000 (12:56 +0900)
シーカーレイ、スーパーレイはコード簡略化するために別の処理が必要なのでこのコミットでは行わない

src/combat/shoot.cpp
src/effect/effect-processor.cpp
src/io/cursor.cpp
src/mind/mind-ninja.cpp
src/mspell/mspell-checker.cpp
src/mspell/mspell-judgement.cpp
src/spell-kind/spells-fetcher.cpp
src/spell/range-calc.cpp
src/spell/range-calc.h
src/target/projection-path-calculator.cpp

index d54cc9f..3fcc532 100644 (file)
@@ -502,8 +502,6 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ObjectType *j_ptr, SPE
 
     GAME_TEXT o_name[MAX_NLEN];
 
-    uint16_t path_g[512]; /* For calcuration of path length */
-
     /* STICK TO */
     bool stick_to = false;
 
@@ -591,7 +589,8 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ObjectType *j_ptr, SPE
     }
 
     /* Get projection path length */
-    tdis = projection_path(player_ptr, path_g, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU) - 1;
+    projection_path path_g(player_ptr, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU);
+    tdis = path_g.path_num() - 1;
 
     project_length = 0; /* reset to default */
 
index 6f34bbc..6ac4060 100644 (file)
@@ -68,7 +68,6 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX who, POSITION ra
     bool blind = player_ptr->blind != 0;
     bool old_hide = false;
     int path_n = 0;
-    uint16_t path_g[512];
     int grids = 0;
     POSITION gx[1024];
     POSITION gy[1024];
@@ -138,18 +137,16 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX who, POSITION ra
     }
 
     /* Calculate the projection path */
-    path_n = projection_path(player_ptr, path_g, (project_length ? project_length : get_max_range(player_ptr)), y1, x1, y2, x2, flag);
+    projection_path path_g(player_ptr, (project_length ? project_length : get_max_range(player_ptr)), y1, x1, y2, x2, flag);
     handle_stuff(player_ptr);
 
-    int k;
+    int k = 0;
     auto oy = y1;
     auto ox = x1;
     auto visual = false;
     POSITION gm_rad = rad;
     bool see_s_msg = true;
-    for (k = 0; k < path_n; ++k) {
-        POSITION ny = get_grid_y(path_g[k]);
-        POSITION nx = get_grid_x(path_g[k]);
+    for (const auto &[ny, nx] : path_g) {
         if (flag & PROJECT_DISI) {
             if (cave_stop_disintegration(player_ptr->current_floor_ptr, ny, nx) && (rad > 0)) {
                 break;
@@ -199,6 +196,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX who, POSITION ra
 
         oy = ny;
         ox = nx;
+        k++;
     }
 
     path_n = k;
@@ -233,7 +231,7 @@ ProjectResult project(PlayerType *player_ptr, const MONSTER_IDX who, POSITION ra
          */
         if (breath) {
             flag &= ~(PROJECT_HIDE);
-            breath_shape(player_ptr, path_g, path_n, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, by, bx, typ);
+            breath_shape(player_ptr, path_g, path_g.path_num(), &grids, gx, gy, gm, &gm_rad, rad, y1, x1, by, bx, typ);
         } else {
             for (auto dist = 0; dist <= rad; dist++) {
                 for (auto y = by - dist; y <= by + dist; y++) {
index 0f9c6cb..e889a1a 100644 (file)
@@ -37,7 +37,6 @@ void move_cursor_relative(int row, int col)
  */
 void print_path(PlayerType *player_ptr, POSITION y, POSITION x)
 {
-    uint16_t path_g[512];
     byte default_color = TERM_SLATE;
 
     if (!display_path || (project_length == -1)) {
@@ -45,13 +44,10 @@ void print_path(PlayerType *player_ptr, POSITION y, POSITION x)
     }
 
     auto *floor_ptr = player_ptr->current_floor_ptr;
-    int path_n = projection_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);
+    projection_path path_g(player_ptr, (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++) {
-        POSITION ny = get_grid_y(path_g[i]);
-        POSITION nx = get_grid_x(path_g[i]);
+    for (const auto &[ny, nx] : path_g) {
         auto *g_ptr = &floor_ptr->grid_array[ny][nx];
         if (panel_contains(ny, nx)) {
             TERM_COLOR a = default_color;
index 92c6530..c931f50 100644 (file)
@@ -157,10 +157,9 @@ bool rush_attack(PlayerType *player_ptr, bool *mdeath)
         tm_idx = floor_ptr->grid_array[ty][tx].m_idx;
     }
 
-    uint16_t path_g[32];
-    int path_n = projection_path(player_ptr, path_g, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_STOP | PROJECT_KILL);
+    projection_path path_g(player_ptr, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_STOP | PROJECT_KILL);
     project_length = 0;
-    if (!path_n) {
+    if (path_g.path_num() == 0) {
         return true;
     }
 
@@ -168,12 +167,9 @@ bool rush_attack(PlayerType *player_ptr, bool *mdeath)
     tx = player_ptr->x;
     bool tmp_mdeath = false;
     bool moved = false;
-    for (int i = 0; i < path_n; i++) {
+    for (const auto &[ny, nx] : path_g) {
         monster_type *m_ptr;
 
-        int ny = get_grid_y(path_g[i]);
-        int nx = get_grid_x(path_g[i]);
-
         if (is_cave_empty_bold(player_ptr, ny, nx) && player_can_enter(player_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) {
             ty = ny;
             tx = nx;
index 817285f..e42dd39 100644 (file)
@@ -156,23 +156,18 @@ bool raise_possible(PlayerType *player_ptr, monster_type *m_ptr)
 bool clean_shot(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_friend)
 {
     auto *floor_ptr = player_ptr->current_floor_ptr;
-    uint16_t grid_g[512];
-    int grid_n = projection_path(player_ptr, grid_g, get_max_range(player_ptr), y1, x1, y2, x2, 0);
-    if (!grid_n) {
+    projection_path grid_g(player_ptr, get_max_range(player_ptr), y1, x1, y2, x2, 0);
+    if (grid_g.path_num() == 0) {
         return false;
     }
 
-    POSITION y = get_grid_y(grid_g[grid_n - 1]);
-    POSITION x = get_grid_x(grid_g[grid_n - 1]);
-    if ((y != y2) || (x != x2)) {
+    const auto [last_y, last_x] = grid_g.back();
+    if ((last_y != y2) || (last_x != x2)) {
         return false;
     }
 
-    for (int i = 0; i < grid_n; i++) {
-        y = get_grid_y(grid_g[i]);
-        x = get_grid_x(grid_g[i]);
-
-        if ((floor_ptr->grid_array[y][x].m_idx > 0) && !((y == y2) && (x == x2))) {
+    for (const auto &[y, x] : grid_g) {
+        if ((floor_ptr->grid_array[y][x].m_idx > 0) && (y != y2 || x != x2)) {
             auto *m_ptr = &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx];
             if (is_friend == is_pet(m_ptr)) {
                 return false;
index 3e1f2ca..d800bf7 100644 (file)
 bool direct_beam(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, monster_type *m_ptr)
 {
     auto *floor_ptr = player_ptr->current_floor_ptr;
-    uint16_t grid_g[512];
-    int grid_n = projection_path(player_ptr, grid_g, get_max_range(player_ptr), y1, x1, y2, x2, PROJECT_THRU);
-    if (!grid_n) {
+    projection_path grid_g(player_ptr, get_max_range(player_ptr), y1, x1, y2, x2, PROJECT_THRU);
+    if (grid_g.path_num()) {
         return false;
     }
 
     bool hit2 = false;
-    POSITION y, x;
     bool is_friend = is_pet(m_ptr);
-    for (int i = 0; i < grid_n; i++) {
-        y = get_grid_y(grid_g[i]);
-        x = get_grid_x(grid_g[i]);
-
+    for (const auto &[y, x] : grid_g) {
         if (y == y2 && x == x2) {
             hit2 = true;
         } else if (is_friend && floor_ptr->grid_array[y][x].m_idx > 0 && !are_enemies(player_ptr, m_ptr, &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx])) {
@@ -111,15 +106,11 @@ bool breath_direct(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2
         break;
     }
 
-    uint16_t grid_g[512];
-    int grid_n = projection_path(player_ptr, grid_g, get_max_range(player_ptr), y1, x1, y2, x2, flg);
-    int i;
+    projection_path grid_g(player_ptr, get_max_range(player_ptr), y1, x1, y2, x2, flg);
+    int i = 0;
     POSITION y = y1;
     POSITION x = x1;
-    for (i = 0; i < grid_n; ++i) {
-        int ny = get_grid_y(grid_g[i]);
-        int nx = get_grid_x(grid_g[i]);
-
+    for (const auto &[ny, nx] : grid_g) {
         if (flg & PROJECT_DISI) {
             if (cave_stop_disintegration(player_ptr->current_floor_ptr, ny, nx)) {
                 break;
@@ -136,12 +127,12 @@ bool breath_direct(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2
 
         y = ny;
         x = nx;
+        i++;
     }
 
-    grid_n = i;
     bool hit2 = false;
     bool hityou = false;
-    if (!grid_n) {
+    if (i == 0) {
         if (flg & PROJECT_DISI) {
             if (in_disintegration_range(player_ptr->current_floor_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) {
                 hit2 = true;
@@ -169,7 +160,7 @@ bool breath_direct(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2
         POSITION gx[1024], gy[1024];
         POSITION gm[32];
         POSITION gm_rad = rad;
-        breath_shape(player_ptr, grid_g, grid_n, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, y, x, typ);
+        breath_shape(player_ptr, grid_g, grid_g.path_num(), &grids, gx, gy, gm, &gm_rad, rad, y1, x1, y, x, typ);
         for (i = 0; i < grids; i++) {
             y = gy[i];
             x = gx[i];
@@ -204,19 +195,16 @@ bool breath_direct(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2
  */
 void get_project_point(PlayerType *player_ptr, POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT_FLAGS flg)
 {
-    uint16_t path_g[128];
-    int path_n = projection_path(player_ptr, path_g, get_max_range(player_ptr), sy, sx, *ty, *tx, flg);
+    projection_path path_g(player_ptr, get_max_range(player_ptr), sy, sx, *ty, *tx, flg);
     *ty = sy;
     *tx = sx;
-    for (int i = 0; i < path_n; i++) {
-        sy = get_grid_y(path_g[i]);
-        sx = get_grid_x(path_g[i]);
-        if (!cave_has_flag_bold(player_ptr->current_floor_ptr, sy, sx, FloorFeatureType::PROJECT)) {
+    for (const auto &[y, x] : path_g) {
+        if (!cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, FloorFeatureType::PROJECT)) {
             break;
         }
 
-        *ty = sy;
-        *tx = sx;
+        *ty = y;
+        *tx = x;
     }
 }
 
index 0ca737b..1e87792 100644 (file)
@@ -119,9 +119,6 @@ bool fetch_monster(PlayerType *player_ptr)
     monster_type *m_ptr;
     MONSTER_IDX m_idx;
     GAME_TEXT m_name[MAX_NLEN];
-    int i;
-    int path_n;
-    uint16_t path_g[512];
     POSITION ty, tx;
 
     if (!target_set(player_ptr, TARGET_KILL)) {
@@ -145,11 +142,9 @@ bool fetch_monster(PlayerType *player_ptr)
     m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
     monster_desc(player_ptr, m_name, m_ptr, 0);
     msg_format(_("%sを引き戻した。", "You pull back %s."), m_name);
-    path_n = projection_path(player_ptr, path_g, get_max_range(player_ptr), target_row, target_col, player_ptr->y, player_ptr->x, 0);
+    projection_path path_g(player_ptr, get_max_range(player_ptr), target_row, target_col, player_ptr->y, player_ptr->x, 0);
     ty = target_row, tx = target_col;
-    for (i = 1; i < path_n; i++) {
-        POSITION ny = get_grid_y(path_g[i]);
-        POSITION nx = get_grid_x(path_g[i]);
+    for (const auto &[ny, nx] : path_g) {
         auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
 
         if (in_bounds(player_ptr->current_floor_ptr, ny, nx) && is_cave_empty_bold(player_ptr, ny, nx) && !g_ptr->is_object() && !pattern_tile(player_ptr->current_floor_ptr, ny, nx)) {
index b0ec0be..17907c8 100644 (file)
@@ -198,7 +198,7 @@ bool in_disintegration_range(floor_type *floor_ptr, POSITION y1, POSITION x1, PO
 /*
  * breath shape
  */
-void breath_shape(PlayerType *player_ptr, uint16_t *path_g, int dist, int *pgrids, POSITION *gx, POSITION *gy, POSITION *gm, POSITION *pgm_rad, POSITION rad, POSITION y1, POSITION x1, POSITION y2, POSITION x2, AttributeType typ)
+void breath_shape(PlayerType *player_ptr, const projection_path &path, int dist, int *pgrids, POSITION *gx, POSITION *gy, POSITION *gm, POSITION *pgm_rad, POSITION rad, POSITION y1, POSITION x1, POSITION y2, POSITION x2, AttributeType typ)
 {
     POSITION by = y1;
     POSITION bx = x1;
@@ -212,8 +212,7 @@ void breath_shape(PlayerType *player_ptr, uint16_t *path_g, int dist, int *pgrid
     auto *floor_ptr = player_ptr->current_floor_ptr;
     while (bdis <= mdis) {
         if ((0 < dist) && (path_n < dist)) {
-            POSITION ny = get_grid_y(path_g[path_n]);
-            POSITION nx = get_grid_x(path_g[path_n]);
+            const auto [ny, nx] = path[path_n];
             POSITION nd = distance(ny, nx, y1, x1);
 
             if (bdis >= nd) {
index 77c05f6..fb17e3e 100644 (file)
@@ -5,6 +5,7 @@
 
 struct floor_type;
 class PlayerType;
+class projection_path;
 bool in_disintegration_range(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2);
-void breath_shape(PlayerType *player_ptr, uint16_t *path_g, int dist, int *pgrids, POSITION *gx, POSITION *gy, POSITION *gm, POSITION *pgm_rad, POSITION rad, POSITION y1, POSITION x1, POSITION y2, POSITION x2, AttributeType typ);
+void breath_shape(PlayerType *player_ptr, const projection_path &path, int dist, int *pgrids, POSITION *gx, POSITION *gy, POSITION *gm, POSITION *pgm_rad, POSITION rad, POSITION y1, POSITION x1, POSITION y2, POSITION x2, AttributeType typ);
 POSITION dist_to_line(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2);
index e1f5425..132a409 100644 (file)
@@ -285,14 +285,12 @@ projection_path::projection_path(PlayerType *player_ptr, POSITION range, POSITIO
  */
 bool projectable(PlayerType *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
 {
-    uint16_t grid_g[512];
-    int grid_n = projection_path(player_ptr, grid_g, (project_length ? project_length : get_max_range(player_ptr)), y1, x1, y2, x2, 0);
-    if (!grid_n) {
+    projection_path grid_g(player_ptr, (project_length ? project_length : get_max_range(player_ptr)), y1, x1, y2, x2, 0);
+    if (grid_g.path_num() == 0) {
         return true;
     }
 
-    POSITION y = get_grid_y(grid_g[grid_n - 1]);
-    POSITION x = get_grid_x(grid_g[grid_n - 1]);
+    const auto [y, x] = grid_g.back();
     if ((y != y2) || (x != x2)) {
         return false;
     }