GAME_TEXT o_name[MAX_NLEN];
- uint16_t path_g[512]; /* For calcuration of path length */
-
/* STICK TO */
bool stick_to = false;
}
/* 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 */
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];
}
/* 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;
oy = ny;
ox = nx;
+ k++;
}
path_n = k;
*/
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++) {
*/
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)) {
}
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;
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;
}
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;
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;
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])) {
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;
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;
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];
*/
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;
}
}
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)) {
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)) {
/*
* 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;
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) {
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);
*/
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;
}