2 * @brief 雑多なその他の処理2 / effects of various "objects"
5 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
6 * This software may be copied and distributed for educational, research, and\n
7 * not for profit purposes provided that this copyright and statement are\n
8 * included in all such copies.\n
9 * 2014 Deskull rearranged comment for Doxygen.
12 #include "io/targeting.h"
13 #include "action/travel-execution.h"
14 #include "cmd-action/cmd-pet.h"
15 #include "cmd-building/cmd-building.h"
16 #include "core/asking-player.h"
17 #include "core/disturbance.h"
18 #include "core/player-redraw-types.h"
19 #include "core/player-update-types.h"
20 #include "core/stuff-handler.h"
21 #include "core/window-redrawer.h"
22 #include "dungeon/dungeon.h"
23 #include "dungeon/quest.h"
24 #include "effect/spells-effect-util.h"
25 #include "flavor/flavor-describer.h"
26 #include "floor/cave.h"
27 #include "floor/floor-events.h"
28 #include "floor/floor-object.h"
29 #include "floor/floor-town.h"
30 #include "floor/floor.h"
31 #include "floor/object-scanner.h"
32 #include "game-option/cheat-options.h"
33 #include "game-option/disturbance-options.h"
34 #include "game-option/game-play-options.h"
35 #include "game-option/input-options.h"
36 #include "game-option/keymap-directory-getter.h"
37 #include "game-option/map-screen-options.h"
38 #include "grid/feature.h"
39 #include "grid/grid.h"
40 #include "info-reader/fixed-map-parser.h"
41 #include "io/command-repeater.h"
42 #include "io/cursor.h"
43 #include "io/input-key-acceptor.h"
44 #include "io/input-key-requester.h"
45 #include "io/screen-util.h"
46 #include "main/sound-of-music.h"
47 #include "monster-race/monster-race-hook.h"
48 #include "monster-race/monster-race.h"
49 #include "monster-race/race-flags1.h"
50 #include "monster/monster-describer.h"
51 #include "monster/monster-description-types.h"
52 #include "monster/monster-flag-types.h"
53 #include "monster/monster-info.h"
54 #include "monster/monster-status.h"
55 #include "monster/monster-update.h"
56 #include "monster/smart-learn-types.h"
57 #include "object-enchant/object-curse.h"
58 #include "object/object-kind-hook.h"
59 #include "object/object-mark-types.h"
60 #include "player/player-race-types.h"
61 #include "player/player-status.h"
62 #include "spell/spells-summon.h"
63 #include "system/building-type-definition.h"
64 #include "system/floor-type-definition.h"
65 #include "system/system-variables.h"
66 #include "term/screen-processor.h"
67 #include "term/term-color-types.h"
68 #include "util/bit-flags-calculator.h"
69 #include "util/int-char-converter.h"
70 #include "util/sort.h"
71 #include "view/display-lore.h"
72 #include "view/display-messages.h"
73 #include "view/display-monster-status.h"
74 #include "window/main-window-util.h"
75 #include "world/world.h"
78 #include "locale/english.h"
82 * @brief コンソール上におけるマップ表示の左上位置を返す /
83 * Calculates current boundaries Called below and from "do_cmd_locate()".
86 void panel_bounds_center(void)
89 get_screen_size(&wid, &hgt);
90 panel_row_max = panel_row_min + hgt - 1;
91 panel_row_prt = panel_row_min - 1;
92 panel_col_max = panel_col_min + wid - 1;
93 panel_col_prt = panel_col_min - 13;
97 * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
98 * @param creature_ptr プレーヤーへの参照ポインタ
100 * @param x 変更先のフロアX座標
102 * Handle a request to change the current panel
103 * Return TRUE if the panel was changed.
104 * Also used in do_cmd_locate
105 * @return 実際に再描画が必要だった場合TRUEを返す
107 static bool change_panel_xy(player_type *creature_ptr, POSITION y, POSITION x)
109 POSITION dy = 0, dx = 0;
111 get_screen_size(&wid, &hgt);
112 if (y < panel_row_min)
115 if (y > panel_row_max)
118 if (x < panel_col_min)
121 if (x > panel_col_max)
127 return change_panel(creature_ptr, dy, dx);
131 * @brief マップ描画のフォーカスを当てるべき座標を更新する
132 * @param creature_ptr プレーヤーへの参照ポインタ
134 * Given an row (y) and col (x), this routine detects when a move
135 * off the screen has occurred and figures new borders. -RAK-
136 * "Update" forces a "full update" to take place.
137 * The map is reprinted if necessary, and "TRUE" is returned.
138 * @return 実際に再描画が必要だった場合TRUEを返す
140 void verify_panel(player_type *creature_ptr)
142 POSITION y = creature_ptr->y;
143 POSITION x = creature_ptr->x;
145 get_screen_size(&wid, &hgt);
146 int max_prow_min = creature_ptr->current_floor_ptr->height - hgt;
147 int max_pcol_min = creature_ptr->current_floor_ptr->width - wid;
148 if (max_prow_min < 0)
150 if (max_pcol_min < 0)
155 if (center_player && (center_running || !creature_ptr->running)) {
156 prow_min = y - hgt / 2;
159 else if (prow_min > max_prow_min)
160 prow_min = max_prow_min;
162 pcol_min = x - wid / 2;
165 else if (pcol_min > max_pcol_min)
166 pcol_min = max_pcol_min;
168 prow_min = panel_row_min;
169 pcol_min = panel_col_min;
170 if (y > panel_row_max - 2)
171 while (y > prow_min + hgt - 1 - 2)
172 prow_min += (hgt / 2);
174 if (y < panel_row_min + 2)
175 while (y < prow_min + 2)
176 prow_min -= (hgt / 2);
178 if (prow_min > max_prow_min)
179 prow_min = max_prow_min;
184 if (x > panel_col_max - 4)
185 while (x > pcol_min + wid - 1 - 4)
186 pcol_min += (wid / 2);
188 if (x < panel_col_min + 4)
189 while (x < pcol_min + 4)
190 pcol_min -= (wid / 2);
192 if (pcol_min > max_pcol_min)
193 pcol_min = max_pcol_min;
199 if ((prow_min == panel_row_min) && (pcol_min == panel_col_min))
202 panel_row_min = prow_min;
203 panel_col_min = pcol_min;
204 if (disturb_panel && !center_player)
205 disturb(creature_ptr, FALSE, FALSE);
207 panel_bounds_center();
208 creature_ptr->update |= (PU_MONSTERS);
209 creature_ptr->redraw |= (PR_MAP);
210 creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
214 * Determine is a monster makes a reasonable target
216 * The concept of "targeting" was stolen from "Morgul" (?)
218 * The player can target any location, or any "target-able" monster.
220 * Currently, a monster is "target_able" if it is visible, and if
221 * the player can hit it with a projection, and the player is not
222 * hallucinating. This allows use of "use closest target" macros.
224 * Future versions may restrict the ability to target "trappers"
225 * and "mimics", but the semantics is a little bit weird.
227 bool target_able(player_type *creature_ptr, MONSTER_IDX m_idx)
229 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
230 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
231 if (!monster_is_valid(m_ptr))
234 if (creature_ptr->image)
240 if (creature_ptr->riding && (creature_ptr->riding == m_idx))
243 if (!projectable(creature_ptr, creature_ptr->y, creature_ptr->x, m_ptr->fy, m_ptr->fx))
249 /* Targetting variables */
250 MONSTER_IDX target_who;
255 * Update (if necessary) and verify (if possible) the target.
256 * We return TRUE if the target is "okay" and FALSE otherwise.
258 bool target_okay(player_type *creature_ptr)
266 if (!target_able(creature_ptr, target_who))
269 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[target_who];
270 target_row = m_ptr->fy;
271 target_col = m_ptr->fx;
276 * Help "select" a location (see below)
278 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
280 POSITION_IDX b_i = -1, b_v = 9999;
281 for (POSITION_IDX i = 0; i < tmp_pos.n; i++) {
282 POSITION x2 = tmp_pos.x[i];
283 POSITION y2 = tmp_pos.y[i];
284 POSITION x3 = (x2 - x1);
285 POSITION y3 = (y2 - y1);
286 if (dx && (x3 * dx <= 0))
289 if (dy && (y3 * dy <= 0))
292 POSITION x4 = ABS(x3);
293 POSITION y4 = ABS(y3);
294 if (dy && !dx && (x4 > y4))
297 if (dx && !dy && (y4 > x4))
300 POSITION_IDX v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
301 if ((b_i >= 0) && (v >= b_v))
312 * Determine if a given location is "interesting"
314 static bool target_set_accept(player_type *creature_ptr, POSITION y, POSITION x)
316 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
317 if (!(in_bounds(floor_ptr, y, x)))
320 if (player_bold(creature_ptr, y, x))
323 if (creature_ptr->image)
327 g_ptr = &floor_ptr->grid_array[y][x];
329 monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
334 OBJECT_IDX next_o_idx = 0;
335 for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
337 o_ptr = &floor_ptr->o_list[this_o_idx];
338 next_o_idx = o_ptr->next_o_idx;
339 if (o_ptr->marked & OM_FOUND)
343 if (g_ptr->info & (CAVE_MARK)) {
344 if (g_ptr->info & CAVE_OBJECT)
347 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE))
355 * Prepare the "temp" array for "target_set"
357 * Return the number of target_able monsters in the set.
359 static void target_set_prepare(player_type *creature_ptr, BIT_FLAGS mode)
361 POSITION min_hgt, max_hgt, min_wid, max_wid;
362 if (mode & TARGET_KILL) {
363 min_hgt = MAX((creature_ptr->y - get_max_range(creature_ptr)), 0);
364 max_hgt = MIN((creature_ptr->y + get_max_range(creature_ptr)), creature_ptr->current_floor_ptr->height - 1);
365 min_wid = MAX((creature_ptr->x - get_max_range(creature_ptr)), 0);
366 max_wid = MIN((creature_ptr->x + get_max_range(creature_ptr)), creature_ptr->current_floor_ptr->width - 1);
368 min_hgt = panel_row_min;
369 max_hgt = panel_row_max;
370 min_wid = panel_col_min;
371 max_wid = panel_col_max;
375 for (POSITION y = min_hgt; y <= max_hgt; y++) {
376 for (POSITION x = min_wid; x <= max_wid; x++) {
378 if (!target_set_accept(creature_ptr, y, x))
381 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
382 if ((mode & (TARGET_KILL)) && !target_able(creature_ptr, g_ptr->m_idx))
385 if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx]))
388 tmp_pos.x[tmp_pos.n] = x;
389 tmp_pos.y[tmp_pos.n] = y;
394 if (mode & (TARGET_KILL)) {
395 ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
397 ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
400 if (creature_ptr->riding == 0 || !target_pet || (tmp_pos.n <= 1) || !(mode & (TARGET_KILL)))
403 POSITION tmp = tmp_pos.y[0];
404 tmp_pos.y[0] = tmp_pos.y[1];
407 tmp_pos.x[0] = tmp_pos.x[1];
411 void target_set_prepare_look(player_type *creature_ptr) { target_set_prepare(creature_ptr, TARGET_LOOK); }
414 * Evaluate number of kill needed to gain level
416 static void evaluate_monster_exp(player_type *creature_ptr, char *buf, monster_type *m_ptr)
418 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
419 if ((creature_ptr->lev >= PY_MAX_LEVEL) || (creature_ptr->prace == RACE_ANDROID)) {
424 if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE)) {
425 if (!current_world_ptr->wizard) {
431 s32b exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
432 u32b exp_mon_frac = 0;
433 s64b_div(&exp_mon, &exp_mon_frac, 0, (creature_ptr->max_plv + 2));
435 s32b exp_adv = player_exp[creature_ptr->lev - 1] * creature_ptr->expfact;
436 u32b exp_adv_frac = 0;
437 s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
439 s64b_sub(&exp_adv, &exp_adv_frac, creature_ptr->exp, creature_ptr->exp_frac);
441 s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
442 s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
444 s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
446 u32b num = MIN(999, exp_adv_frac);
447 sprintf(buf, "%03ld", (long int)num);
450 bool show_gold_on_floor = FALSE;
453 * Examine a grid, return a keypress.
455 * The "mode" argument contains the "TARGET_LOOK" bit flag, which
456 * indicates that the "space" key should scan through the contents
457 * of the grid, instead of simply returning immediately. This lets
458 * the "look" command get complete information, without making the
459 * "target" command annoying.
461 * The "info" argument contains the "commands" which should be shown
462 * inside the "[xxx]" text. This string must never be empty, or grids
463 * containing monsters will be displayed with an extra comma.
465 * Note that if a monster is in the grid, we update both the monster
466 * recall info and the health bar info to track that monster.
468 * Eventually, we may allow multiple objects per grid, or objects
469 * and terrain features in the same grid.
471 * This function must handle blindness/hallucination.
473 static char target_set_aux(player_type *subject_ptr, POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
475 OBJECT_IDX next_o_idx = 0;
476 concptr s1 = "", s2 = "", s3 = "", x_info = "";
481 char out_val[MAX_NLEN + 80];
482 OBJECT_IDX floor_list[23];
483 ITEM_NUMBER floor_num = 0;
485 floor_num = scan_floor_items(subject_ptr, floor_list, y, x, 0x02, 0);
488 x_info = _("x物 ", "x,");
492 if (player_bold(subject_ptr, y, x)) {
502 s1 = _("ターゲット:", "Target:");
505 if (subject_ptr->image) {
506 concptr name = _("何か奇妙な物", "something strange");
508 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
510 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
513 move_cursor_relative(y, x);
515 if ((query != '\r') && (query != '\n'))
521 grid_type *g_ptr = &subject_ptr->current_floor_ptr->grid_array[y][x];
522 if (g_ptr->m_idx && subject_ptr->current_floor_ptr->m_list[g_ptr->m_idx].ml) {
523 monster_type *m_ptr = &subject_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
524 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
525 GAME_TEXT m_name[MAX_NLEN];
528 monster_race_track(subject_ptr, m_ptr->ap_r_idx);
529 health_track(subject_ptr, g_ptr->m_idx);
530 handle_stuff(subject_ptr);
535 screen_roff(subject_ptr, m_ptr->ap_r_idx, 0);
536 term_addstr(-1, TERM_WHITE, format(_(" [r思 %s%s]", " [r,%s%s]"), x_info, info));
546 evaluate_monster_exp(subject_ptr, acount, m_ptr);
548 sprintf(out_val, "[%s]%s%s(%s)%s%s [r思 %s%s]", acount, s1, m_name, look_mon_desc(m_ptr, 0x01), s2, s3, x_info, info);
550 sprintf(out_val, "[%s]%s%s%s%s(%s) [r, %s%s]", acount, s1, s2, s3, m_name, look_mon_desc(m_ptr, 0x01), x_info, info);
553 move_cursor_relative(y, x);
561 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x'))
564 if ((query == ' ') && !(mode & (TARGET_LOOK)))
567 s1 = _("それは", "It is ");
568 if (ap_r_ptr->flags1 & (RF1_FEMALE))
569 s1 = _("彼女は", "She is ");
570 else if (ap_r_ptr->flags1 & (RF1_MALE))
571 s1 = _("彼は", "He is ");
580 for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) {
581 GAME_TEXT o_name[MAX_NLEN];
583 o_ptr = &subject_ptr->current_floor_ptr->o_list[this_o_idx];
584 next_o_idx = o_ptr->next_o_idx;
585 describe_flavor(subject_ptr, o_name, o_ptr, 0);
587 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
589 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
592 move_cursor_relative(y, x);
594 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x'))
597 if ((query == ' ') && !(mode & (TARGET_LOOK)))
600 s2 = _("をまた", "also carrying ");
614 if (floor_num == 1) {
615 GAME_TEXT o_name[MAX_NLEN];
617 o_ptr = &subject_ptr->current_floor_ptr->o_list[floor_list[0]];
618 describe_flavor(subject_ptr, o_name, o_ptr, 0);
620 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
622 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
625 move_cursor_relative(y, x);
632 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
634 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
637 move_cursor_relative(y, x);
639 if (query != 'x' && query != ' ')
647 show_gold_on_floor = TRUE;
648 (void)show_floor_items(subject_ptr, 0, y, x, &min_width, 0);
649 show_gold_on_floor = FALSE;
651 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
653 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
658 if (query != '\n' && query != '\r')
661 o_idx = g_ptr->o_idx;
662 if (!(o_idx && subject_ptr->current_floor_ptr->o_list[o_idx].next_o_idx))
665 excise_object_idx(subject_ptr->current_floor_ptr, o_idx);
667 while (subject_ptr->current_floor_ptr->o_list[i].next_o_idx)
668 i = subject_ptr->current_floor_ptr->o_list[i].next_o_idx;
670 subject_ptr->current_floor_ptr->o_list[i].next_o_idx = o_idx;
675 for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
677 o_ptr = &subject_ptr->current_floor_ptr->o_list[this_o_idx];
678 next_o_idx = o_ptr->next_o_idx;
679 if (o_ptr->marked & OM_FOUND) {
680 GAME_TEXT o_name[MAX_NLEN];
682 describe_flavor(subject_ptr, o_name, o_ptr, 0);
684 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
686 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
689 move_cursor_relative(y, x);
691 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x'))
694 if ((query == ' ') && !(mode & TARGET_LOOK))
697 s1 = _("それは", "It is ");
698 if (o_ptr->number != 1)
699 s1 = _("それらは", "They are ");
710 feat = get_feat_mimic(g_ptr);
711 if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(subject_ptr, y, x))
714 f_ptr = &f_info[feat];
715 if (!boring && !have_flag(f_ptr->flags, FF_REMEMBER)) {
716 if ((query != '\r') && (query != '\n'))
723 if (have_flag(f_ptr->flags, FF_QUEST_ENTER)) {
724 IDX old_quest = subject_ptr->current_floor_ptr->inside_quest;
725 for (int j = 0; j < 10; j++)
726 quest_text[j][0] = '\0';
729 subject_ptr->current_floor_ptr->inside_quest = g_ptr->special;
730 init_flags = INIT_NAME_ONLY;
731 parse_fixed_map(subject_ptr, "q_info.txt", 0, 0, 0, 0);
732 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"), quest[g_ptr->special].name, quest[g_ptr->special].level);
733 subject_ptr->current_floor_ptr->inside_quest = old_quest;
734 } else if (have_flag(f_ptr->flags, FF_BLDG) && !subject_ptr->current_floor_ptr->inside_arena) {
735 name = building[f_ptr->subtype].name;
736 } else if (have_flag(f_ptr->flags, FF_ENTRANCE)) {
737 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
738 } else if (have_flag(f_ptr->flags, FF_TOWN)) {
739 name = town_info[g_ptr->special].name;
740 } else if (subject_ptr->wild_mode && (feat == feat_floor)) {
741 name = _("道", "road");
743 name = f_name + f_ptr->name;
747 && ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY))
748 || (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) || have_flag(f_ptr->flags, FF_TOWN))) {
752 if (have_flag(f_ptr->flags, FF_STORE) || have_flag(f_ptr->flags, FF_QUEST_ENTER)
753 || (have_flag(f_ptr->flags, FF_BLDG) && !subject_ptr->current_floor_ptr->inside_arena) || have_flag(f_ptr->flags, FF_ENTRANCE))
757 else if (have_flag(f_ptr->flags, FF_FLOOR) || have_flag(f_ptr->flags, FF_TOWN) || have_flag(f_ptr->flags, FF_SHALLOW) || have_flag(f_ptr->flags, FF_DEEP))
760 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
763 if (current_world_ptr->wizard) {
766 sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
768 sprintf(f_idx_str, "%d", g_ptr->feat);
771 sprintf(out_val, "%s%s%s%s[%s] %x %s %d %d %d (%d,%d) %d", s1, name, s2, s3, info, (unsigned int)g_ptr->info, f_idx_str, g_ptr->dist, g_ptr->cost,
772 g_ptr->when, (int)y, (int)x, travel.cost[y][x]);
774 sprintf(out_val, "%s%s%s%s [%s] %x %s %d %d %d (%d,%d)", s1, s2, s3, name, info, g_ptr->info, f_idx_str, g_ptr->dist, g_ptr->cost, g_ptr->when, (int)y,
779 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
781 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
785 move_cursor_relative(y, x);
787 if ((query != '\r') && (query != '\n') && (query != ' '))
794 * Handle "target" and "look".
796 bool target_set(player_type *creature_ptr, BIT_FLAGS mode)
799 POSITION y = creature_ptr->y;
800 POSITION x = creature_ptr->x;
807 get_screen_size(&wid, &hgt);
809 const char same_key = rogue_like_commands ? 'x' : 'l';
810 target_set_prepare(creature_ptr, mode);
812 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
814 if (flag && tmp_pos.n) {
817 change_panel_xy(creature_ptr, y, x);
818 if (!(mode & TARGET_LOOK))
819 print_path(creature_ptr, y, x);
821 g_ptr = &floor_ptr->grid_array[y][x];
822 if (target_able(creature_ptr, g_ptr->m_idx))
823 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
825 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
829 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d", los(creature_ptr, creature_ptr->y, creature_ptr->x, y, x),
830 projectable(creature_ptr, creature_ptr->y, creature_ptr->x, y, x));
831 strcat(info, cheatinfo);
835 query = target_set_aux(creature_ptr, y, x, mode, info);
856 if (!target_able(creature_ptr, g_ptr->m_idx)) {
861 health_track(creature_ptr, g_ptr->m_idx);
862 target_who = g_ptr->m_idx;
871 if (++m == tmp_pos.n) {
889 verify_panel(creature_ptr);
890 creature_ptr->update |= (PU_MONSTERS);
891 creature_ptr->redraw |= (PR_MAP);
892 creature_ptr->window |= (PW_OVERHEAD);
893 handle_stuff(creature_ptr);
894 target_set_prepare(creature_ptr, mode);
905 if (query == same_key) {
906 if (++m == tmp_pos.n) {
912 d = get_keymap_dir(query);
922 POSITION y2 = panel_row_min;
923 POSITION x2 = panel_col_min;
924 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
925 while (flag && (i < 0)) {
926 if (change_panel(creature_ptr, ddy[d], ddx[d])) {
927 int v = tmp_pos.y[m];
928 int u = tmp_pos.x[m];
929 target_set_prepare(creature_ptr, mode);
931 i = target_pick(v, u, ddy[d], ddx[d]);
938 POSITION dx = ddx[d];
939 POSITION dy = ddy[d];
942 panel_bounds_center();
943 creature_ptr->update |= (PU_MONSTERS);
944 creature_ptr->redraw |= (PR_MAP);
945 creature_ptr->window |= (PW_OVERHEAD);
946 handle_stuff(creature_ptr);
947 target_set_prepare(creature_ptr, mode);
951 if (((x < panel_col_min + wid / 2) && (dx > 0)) || ((x > panel_col_min + wid / 2) && (dx < 0)))
954 if (((y < panel_row_min + hgt / 2) && (dy > 0)) || ((y > panel_row_min + hgt / 2) && (dy < 0)))
957 if ((y >= panel_row_min + hgt) || (y < panel_row_min) || (x >= panel_col_min + wid) || (x < panel_col_min)) {
958 if (change_panel(creature_ptr, dy, dx))
959 target_set_prepare(creature_ptr, mode);
962 if (x >= floor_ptr->width - 1)
963 x = floor_ptr->width - 2;
967 if (y >= floor_ptr->height - 1)
968 y = floor_ptr->height - 2;
979 bool move_fast = FALSE;
980 if (!(mode & TARGET_LOOK))
981 print_path(creature_ptr, y, x);
983 g_ptr = &floor_ptr->grid_array[y][x];
984 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
987 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d, SPECIAL:%d", los(creature_ptr, creature_ptr->y, creature_ptr->x, y, x),
988 projectable(creature_ptr, creature_ptr->y, creature_ptr->x, y, x), g_ptr->special);
989 strcat(info, cheatinfo);
992 /* Describe and Prompt (enable "TARGET_LOOK") */
993 while ((query = target_set_aux(creature_ptr, y, x, mode | TARGET_LOOK, info)) == 0)
997 if (use_menu && (query == '\r'))
1015 verify_panel(creature_ptr);
1016 creature_ptr->update |= (PU_MONSTERS);
1017 creature_ptr->redraw |= (PR_MAP);
1018 creature_ptr->window |= (PW_OVERHEAD);
1019 handle_stuff(creature_ptr);
1020 target_set_prepare(creature_ptr, mode);
1021 y = creature_ptr->y;
1022 x = creature_ptr->x;
1033 for (i = 0; i < tmp_pos.n; i++) {
1034 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1047 d = get_keymap_dir(query);
1058 POSITION dx = ddx[d];
1059 POSITION dy = ddy[d];
1061 int mag = MIN(wid / 2, hgt / 2);
1069 if (((x < panel_col_min + wid / 2) && (dx > 0)) || ((x > panel_col_min + wid / 2) && (dx < 0)))
1072 if (((y < panel_row_min + hgt / 2) && (dy > 0)) || ((y > panel_row_min + hgt / 2) && (dy < 0)))
1075 if ((y >= panel_row_min + hgt) || (y < panel_row_min) || (x >= panel_col_min + wid) || (x < panel_col_min)) {
1076 if (change_panel(creature_ptr, dy, dx))
1077 target_set_prepare(creature_ptr, mode);
1080 if (x >= floor_ptr->width - 1)
1081 x = floor_ptr->width - 2;
1085 if (y >= floor_ptr->height - 1)
1086 y = floor_ptr->height - 2;
1094 verify_panel(creature_ptr);
1095 creature_ptr->update |= (PU_MONSTERS);
1096 creature_ptr->redraw |= (PR_MAP);
1097 creature_ptr->window |= (PW_OVERHEAD);
1098 handle_stuff(creature_ptr);
1099 return target_who != 0;
1103 * Get an "aiming direction" from the user.
1105 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1106 * "0" for "current target", and "-1" for "entry aborted".
1108 * Note that "Force Target", if set, will pre-empt user interaction,
1109 * if there is a usable target already set.
1111 * Note that confusion over-rides any (explicit?) user choice.
1113 bool get_aim_dir(player_type *creature_ptr, DIRECTION *dp)
1115 DIRECTION dir = command_dir;
1116 if (use_old_target && target_okay(creature_ptr))
1120 if (repeat_pull(&code))
1121 if (!(code == 5 && !target_okay(creature_ptr)))
1122 dir = (DIRECTION)code;
1124 *dp = (DIRECTION)code;
1128 if (!target_okay(creature_ptr))
1129 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1131 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
1133 if (!get_com(p, &command, TRUE))
1136 if (use_menu && (command == '\r'))
1150 if (target_set(creature_ptr, TARGET_KILL))
1155 dir = get_keymap_dir(command);
1159 if ((dir == 5) && !target_okay(creature_ptr))
1172 if (creature_ptr->confused)
1173 dir = ddd[randint0(8)];
1175 if (command_dir != dir)
1176 msg_print(_("あなたは混乱している。", "You are confused."));
1179 repeat_push((COMMAND_CODE)command_dir);
1183 bool get_direction(player_type *creature_ptr, DIRECTION *dp, bool allow_under, bool with_steed)
1185 DIRECTION dir = command_dir;
1187 if (repeat_pull(&code))
1188 dir = (DIRECTION)code;
1190 *dp = (DIRECTION)code;
1191 concptr prompt = allow_under ? _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ")
1192 : _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1196 if (!get_com(prompt, &ch, TRUE))
1199 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.'))) {
1204 dir = get_keymap_dir(ch);
1209 if ((dir == 5) && (!allow_under))
1216 if (creature_ptr->confused) {
1217 if (randint0(100) < 75) {
1218 dir = ddd[randint0(8)];
1220 } else if (creature_ptr->riding && with_steed) {
1221 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1222 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1223 if (monster_confused_remaining(m_ptr)) {
1224 if (randint0(100) < 75)
1225 dir = ddd[randint0(8)];
1226 } else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1227 dir = ddd[randint0(8)];
1228 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1229 dir = ddd[randint0(8)];
1232 if (command_dir != dir) {
1233 if (creature_ptr->confused) {
1234 msg_print(_("あなたは混乱している。", "You are confused."));
1236 GAME_TEXT m_name[MAX_NLEN];
1237 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1239 monster_desc(creature_ptr, m_name, m_ptr, 0);
1240 if (monster_confused_remaining(m_ptr)) {
1241 msg_format(_("%sは混乱している。", "%^s is confused."), m_name);
1243 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1249 repeat_push((COMMAND_CODE)command_dir);
1254 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
1255 * and place it into "command_dir", unless we already have one.
1257 * This function should be used for all "repeatable" commands, such as
1258 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
1259 * as all commands which must reference a grid adjacent to the player,
1260 * and which may not reference the grid under the player. Note that,
1261 * for example, it is no longer possible to "disarm" or "open" chests
1262 * in the same grid as the player.
1264 * Direction "5" is illegal and will (cleanly) abort the command.
1266 * This function tracks and uses the "global direction", and uses
1267 * that as the "desired direction", to which "confusion" is applied.
1269 bool get_rep_dir(player_type *creature_ptr, DIRECTION *dp, bool under)
1271 DIRECTION dir = command_dir;
1273 if (repeat_pull(&code))
1274 dir = (DIRECTION)code;
1276 *dp = (DIRECTION)code;
1278 = under ? _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ") : _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1281 if (!get_com(prompt, &ch, TRUE))
1284 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.'))) {
1289 dir = get_keymap_dir(ch);
1294 if ((dir == 5) && (!under))
1301 if (creature_ptr->confused) {
1302 if (randint0(100) < 75)
1303 dir = ddd[randint0(8)];
1304 } else if (creature_ptr->riding) {
1305 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1306 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1307 if (monster_confused_remaining(m_ptr)) {
1308 if (randint0(100) < 75)
1309 dir = ddd[randint0(8)];
1310 } else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1311 dir = ddd[randint0(8)];
1312 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1313 dir = ddd[randint0(8)];
1316 if (command_dir != dir) {
1317 if (creature_ptr->confused) {
1318 msg_print(_("あなたは混乱している。", "You are confused."));
1320 GAME_TEXT m_name[MAX_NLEN];
1321 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1322 monster_desc(creature_ptr, m_name, m_ptr, 0);
1323 if (monster_confused_remaining(m_ptr))
1324 msg_format(_("%sは混乱している。", "%^s is confused."), m_name);
1326 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1331 repeat_push((COMMAND_CODE)command_dir);
1336 * XAngband: determine if a given location is "interesting"
1337 * based on target_set_accept function.
1339 static bool tgt_pt_accept(player_type *creature_ptr, POSITION y, POSITION x)
1341 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1342 if (!(in_bounds(floor_ptr, y, x)))
1345 if ((y == creature_ptr->y) && (x == creature_ptr->x))
1348 if (creature_ptr->image)
1352 g_ptr = &floor_ptr->grid_array[y][x];
1353 if (!(g_ptr->info & (CAVE_MARK)))
1356 if (cave_have_flag_grid(g_ptr, FF_LESS) || cave_have_flag_grid(g_ptr, FF_MORE) || cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)
1357 || cave_have_flag_grid(g_ptr, FF_QUEST_EXIT))
1364 * XAngband: Prepare the "temp" array for "tget_pt"
1365 * based on target_set_prepare funciton.
1367 static void tgt_pt_prepare(player_type *creature_ptr)
1373 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1374 for (POSITION y = 1; y < floor_ptr->height; y++) {
1375 for (POSITION x = 1; x < floor_ptr->width; x++) {
1376 if (!tgt_pt_accept(creature_ptr, y, x))
1379 tmp_pos.x[tmp_pos.n] = x;
1380 tmp_pos.y[tmp_pos.n] = y;
1385 ang_sort(creature_ptr, tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
1389 * old -- from PsiAngband.
1391 bool tgt_pt(player_type *creature_ptr, POSITION *x_ptr, POSITION *y_ptr)
1394 get_screen_size(&wid, &hgt);
1396 POSITION x = creature_ptr->x;
1397 POSITION y = creature_ptr->y;
1399 tgt_pt_prepare(creature_ptr);
1401 msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
1406 bool success = FALSE;
1407 while ((ch != ESCAPE) && !success) {
1408 bool move_fast = FALSE;
1409 move_cursor_relative(y, x);
1419 if (player_bold(creature_ptr, y, x))
1427 if (!expand_list || !tmp_pos.n)
1431 int cx = (panel_col_min + panel_col_max) / 2;
1432 int cy = (panel_row_min + panel_row_max) / 2;
1434 for (; n < tmp_pos.n; ++n) {
1435 grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
1436 if (cave_have_flag_grid(g_ptr, FF_STAIRS) && cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
1440 if (n == tmp_pos.n) {
1442 y = creature_ptr->y;
1443 x = creature_ptr->x;
1444 verify_panel(creature_ptr);
1445 creature_ptr->update |= PU_MONSTERS;
1446 creature_ptr->redraw |= PR_MAP;
1447 creature_ptr->window |= PW_OVERHEAD;
1448 handle_stuff(creature_ptr);
1452 dy = 2 * (y - cy) / hgt;
1453 dx = 2 * (x - cx) / wid;
1455 change_panel(creature_ptr, dy, dx);
1461 int d = get_keymap_dir(ch);
1471 int mag = MIN(wid / 2, hgt / 2);
1479 if (((x < panel_col_min + wid / 2) && (dx > 0)) || ((x > panel_col_min + wid / 2) && (dx < 0)))
1482 if (((y < panel_row_min + hgt / 2) && (dy > 0)) || ((y > panel_row_min + hgt / 2) && (dy < 0)))
1485 if ((y >= panel_row_min + hgt) || (y < panel_row_min) || (x >= panel_col_min + wid) || (x < panel_col_min))
1486 change_panel(creature_ptr, dy, dx);
1488 if (x >= creature_ptr->current_floor_ptr->width - 1)
1489 x = creature_ptr->current_floor_ptr->width - 2;
1493 if (y >= creature_ptr->current_floor_ptr->height - 1)
1494 y = creature_ptr->current_floor_ptr->height - 2;
1504 verify_panel(creature_ptr);
1505 creature_ptr->update |= (PU_MONSTERS);
1506 creature_ptr->redraw |= (PR_MAP);
1507 creature_ptr->window |= (PW_OVERHEAD);
1508 handle_stuff(creature_ptr);
1514 bool get_hack_dir(player_type *creature_ptr, DIRECTION *dp)
1520 concptr p = target_okay(creature_ptr)
1521 ? _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ")
1522 : _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1523 if (!get_com(p, &command, TRUE))
1526 if (use_menu && (command == '\r'))
1540 if (target_set(creature_ptr, TARGET_KILL))
1545 dir = get_keymap_dir(command);
1549 if ((dir == 5) && !target_okay(creature_ptr))
1560 if (creature_ptr->confused)
1561 dir = ddd[randint0(8)];
1563 if (command_dir != dir)
1564 msg_print(_("あなたは混乱している。", "You are confused."));
1571 * @briefプレイヤーの攻撃射程(マス) / Maximum range (spells, etc)
1572 * @param creature_ptr プレーヤーへの参照ポインタ
1575 int get_max_range(player_type *creature_ptr) { return creature_ptr->phase_out ? 36 : 18; }