#include "core/player-update-types.h"
#include "core/stuff-handler.h"
#include "core/window-redrawer.h"
-#include "floor/floor.h"
+#include "floor/line-of-sight.h"
#include "game-option/cheat-options.h"
#include "game-option/game-play-options.h"
#include "game-option/input-options.h"
#include "io/screen-util.h"
#include "main/sound-of-music.h"
#include "system/floor-type-definition.h"
+#include "target/projection-path-calculator.h"
#include "target/target-checker.h"
#include "target/target-describer.h"
#include "target/target-preparation.h"
int m;
int distance;
int target_num;
+ bool move_fast;
} ts_type;
static ts_type *initialize_target_set_type(player_type *creature_ptr, ts_type *ts_ptr, target_type mode)
verify_panel(creature_ptr);
creature_ptr->update |= PU_MONSTERS;
creature_ptr->redraw |= PR_MAP;
- creature_ptr->window |= PW_OVERHEAD;
+ creature_ptr->window_flags |= PW_OVERHEAD;
handle_stuff(creature_ptr);
target_set_prepare(creature_ptr, ts_ptr->mode);
ts_ptr->y = creature_ptr->y;
return;
case 'm':
return;
- default:
- if (ts_ptr->query != rogue_like_commands ? 'x' : 'l') {
+ default: {
+ const char queried_command = rogue_like_commands ? 'x' : 'l';
+ if (ts_ptr->query != queried_command) {
ts_ptr->distance = get_keymap_dir(ts_ptr->query);
if (ts_ptr->distance == 0)
bell();
return;
}
+ }
}
static bool check_panel_changed(player_type *creature_ptr, ts_type *ts_ptr)
panel_bounds_center();
creature_ptr->update |= PU_MONSTERS;
creature_ptr->redraw |= PR_MAP;
- creature_ptr->window |= PW_OVERHEAD;
+ creature_ptr->window_flags |= PW_OVERHEAD;
handle_stuff(creature_ptr);
target_set_prepare(creature_ptr, ts_ptr->mode);
ts_ptr->flag = FALSE;
strcat(ts_ptr->info, cheatinfo);
}
-/*
- * Handle "target" and "look".
- */
-bool target_set(player_type *creature_ptr, target_type mode)
+static void switch_next_grid_command(player_type *creature_ptr, ts_type *ts_ptr)
{
- ts_type tmp_ts;
- ts_type *ts_ptr = initialize_target_set_type(creature_ptr, &tmp_ts, mode);
- target_who = 0;
- target_set_prepare(creature_ptr, mode);
+ switch (ts_ptr->query) {
+ case ESCAPE:
+ case 'q':
+ ts_ptr->done = TRUE;
+ break;
+ case 't':
+ case '.':
+ case '5':
+ case '0':
+ target_who = -1;
+ target_row = ts_ptr->y;
+ target_col = ts_ptr->x;
+ ts_ptr->done = TRUE;
+ break;
+ case 'p':
+ verify_panel(creature_ptr);
+ creature_ptr->update |= PU_MONSTERS;
+ creature_ptr->redraw |= PR_MAP;
+ creature_ptr->window_flags |= PW_OVERHEAD;
+ handle_stuff(creature_ptr);
+ target_set_prepare(creature_ptr, ts_ptr->mode);
+ ts_ptr->y = creature_ptr->y;
+ ts_ptr->x = creature_ptr->x;
+ case 'o':
+ // todo ↑元からbreakしていないがFall Throughを付けてよいか不明なので保留
+ break;
+ case ' ':
+ case '*':
+ case '+':
+ case '-':
+ case 'm': {
+ ts_ptr->flag = TRUE;
+ ts_ptr->m = 0;
+ int bd = 999;
+ for (int i = 0; i < tmp_pos.n; i++) {
+ int t = distance(ts_ptr->y, ts_ptr->x, tmp_pos.y[i], tmp_pos.x[i]);
+ if (t < bd) {
+ ts_ptr->m = i;
+ bd = t;
+ }
+ }
+
+ if (bd == 999)
+ ts_ptr->flag = FALSE;
+
+ break;
+ }
+ default:
+ ts_ptr->distance = get_keymap_dir(ts_ptr->query);
+ if (isupper(ts_ptr->query))
+ ts_ptr->move_fast = TRUE;
+
+ if (!ts_ptr->distance)
+ bell();
+
+ break;
+ }
+}
+
+static void decide_change_panel(player_type *creature_ptr, ts_type *ts_ptr)
+{
+ if (ts_ptr->distance == 0)
+ return;
+
+ POSITION dx = ddx[ts_ptr->distance];
+ POSITION dy = ddy[ts_ptr->distance];
+ if (ts_ptr->move_fast) {
+ int mag = MIN(ts_ptr->wid / 2, ts_ptr->hgt / 2);
+ ts_ptr->x += dx * mag;
+ ts_ptr->y += dy * mag;
+ } else {
+ ts_ptr->x += dx;
+ ts_ptr->y += dy;
+ }
+
+ if (((ts_ptr->x < panel_col_min + ts_ptr->wid / 2) && (dx > 0)) || ((ts_ptr->x > panel_col_min + ts_ptr->wid / 2) && (dx < 0)))
+ dx = 0;
+
+ if (((ts_ptr->y < panel_row_min + ts_ptr->hgt / 2) && (dy > 0)) || ((ts_ptr->y > panel_row_min + ts_ptr->hgt / 2) && (dy < 0)))
+ dy = 0;
+
+ if ((ts_ptr->y >= panel_row_min + ts_ptr->hgt) || (ts_ptr->y < panel_row_min) || (ts_ptr->x >= panel_col_min + ts_ptr->wid)
+ || (ts_ptr->x < panel_col_min)) {
+ if (change_panel(creature_ptr, dy, dx))
+ target_set_prepare(creature_ptr, ts_ptr->mode);
+ }
+
floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+ if (ts_ptr->x >= floor_ptr->width - 1)
+ ts_ptr->x = floor_ptr->width - 2;
+ else if (ts_ptr->x <= 0)
+ ts_ptr->x = 1;
+
+ if (ts_ptr->y >= floor_ptr->height - 1)
+ ts_ptr->y = floor_ptr->height - 2;
+ else if (ts_ptr->y <= 0)
+ ts_ptr->y = 1;
+}
+
+static void sweep_target_grids(player_type *creature_ptr, ts_type *ts_ptr)
+{
while (!ts_ptr->done) {
if (set_target_grid(creature_ptr, ts_ptr))
continue;
- bool move_fast = FALSE;
- if (!(mode & TARGET_LOOK))
+ ts_ptr->move_fast = FALSE;
+ if ((ts_ptr->mode & TARGET_LOOK) == 0)
print_path(creature_ptr, ts_ptr->y, ts_ptr->x);
- ts_ptr->g_ptr = &floor_ptr->grid_array[ts_ptr->y][ts_ptr->x];
+ ts_ptr->g_ptr = &creature_ptr->current_floor_ptr->grid_array[ts_ptr->y][ts_ptr->x];
strcpy(ts_ptr->info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
- describe_grid_wizard();
+ describe_grid_wizard(creature_ptr, ts_ptr);
/* Describe and Prompt (enable "TARGET_LOOK") */
- while ((ts_ptr->query = examine_grid(creature_ptr, ts_ptr->y, ts_ptr->x, mode | TARGET_LOOK, ts_ptr->info)) == 0)
+ while ((ts_ptr->query = examine_grid(creature_ptr, ts_ptr->y, ts_ptr->x, static_cast<target_type>(ts_ptr->mode | TARGET_LOOK), ts_ptr->info)) == 0)
;
- int d = 0;
+ ts_ptr->distance = 0;
if (use_menu && (ts_ptr->query == '\r'))
ts_ptr->query = 't';
- switch (ts_ptr->query) {
- case ESCAPE:
- case 'q':
- ts_ptr->done = TRUE;
- break;
- case 't':
- case '.':
- case '5':
- case '0':
- target_who = -1;
- target_row = ts_ptr->y;
- target_col = ts_ptr->x;
- ts_ptr->done = TRUE;
- break;
- case 'p':
- verify_panel(creature_ptr);
- creature_ptr->update |= (PU_MONSTERS);
- creature_ptr->redraw |= (PR_MAP);
- creature_ptr->window |= (PW_OVERHEAD);
- handle_stuff(creature_ptr);
- target_set_prepare(creature_ptr, mode);
- ts_ptr->y = creature_ptr->y;
- ts_ptr->x = creature_ptr->x;
- case 'o':
- break;
- case ' ':
- case '*':
- case '+':
- case '-':
- case 'm': {
- ts_ptr->flag = TRUE;
- ts_ptr->m = 0;
- int bd = 999;
- for (int i = 0; i < tmp_pos.n; i++) {
- int t = distance(ts_ptr->y, ts_ptr->x, tmp_pos.y[i], tmp_pos.x[i]);
- if (t < bd) {
- ts_ptr->m = i;
- bd = t;
- }
- }
-
- if (bd == 999)
- ts_ptr->flag = FALSE;
-
- break;
- }
- default: {
- d = get_keymap_dir(ts_ptr->query);
- if (isupper(ts_ptr->query))
- move_fast = TRUE;
-
- if (!d)
- bell();
- break;
- }
- }
-
- if (d) {
- POSITION dx = ddx[d];
- POSITION dy = ddy[d];
- if (move_fast) {
- int mag = MIN(ts_ptr->wid / 2, ts_ptr->hgt / 2);
- ts_ptr->x += dx * mag;
- ts_ptr->y += dy * mag;
- } else {
- ts_ptr->x += dx;
- ts_ptr->y += dy;
- }
-
- if (((ts_ptr->x < panel_col_min + ts_ptr->wid / 2) && (dx > 0)) || ((ts_ptr->x > panel_col_min + ts_ptr->wid / 2) && (dx < 0)))
- dx = 0;
-
- if (((ts_ptr->y < panel_row_min + ts_ptr->hgt / 2) && (dy > 0)) || ((ts_ptr->y > panel_row_min + ts_ptr->hgt / 2) && (dy < 0)))
- dy = 0;
-
- if ((ts_ptr->y >= panel_row_min + ts_ptr->hgt) || (ts_ptr->y < panel_row_min) || (ts_ptr->x >= panel_col_min + ts_ptr->wid)
- || (ts_ptr->x < panel_col_min)) {
- if (change_panel(creature_ptr, dy, dx))
- target_set_prepare(creature_ptr, mode);
- }
-
- if (ts_ptr->x >= floor_ptr->width - 1)
- ts_ptr->x = floor_ptr->width - 2;
- else if (ts_ptr->x <= 0)
- ts_ptr->x = 1;
-
- if (ts_ptr->y >= floor_ptr->height - 1)
- ts_ptr->y = floor_ptr->height - 2;
- else if (ts_ptr->y <= 0)
- ts_ptr->y = 1;
- }
+ switch_next_grid_command(creature_ptr, ts_ptr);
+ decide_change_panel(creature_ptr, ts_ptr);
}
+}
+/*
+ * Handle "target" and "look".
+ */
+bool target_set(player_type *creature_ptr, target_type mode)
+{
+ ts_type tmp_ts;
+ ts_type *ts_ptr = initialize_target_set_type(creature_ptr, &tmp_ts, mode);
+ target_who = 0;
+ target_set_prepare(creature_ptr, mode);
+ sweep_target_grids(creature_ptr, ts_ptr);
tmp_pos.n = 0;
prt("", 0, 0);
verify_panel(creature_ptr);
creature_ptr->update |= (PU_MONSTERS);
creature_ptr->redraw |= (PR_MAP);
- creature_ptr->window |= (PW_OVERHEAD);
+ creature_ptr->window_flags |= (PW_OVERHEAD);
handle_stuff(creature_ptr);
return target_who != 0;
}