OSDN Git Service

[Refactor] #40413 Separated display-messages.c/h from util.c/h
[hengband/hengband.git] / src / io / targeting.c
1 /*!
2  * @brief 雑多なその他の処理2 / effects of various "objects"
3  * @date 2014/02/06
4  * @author
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.
10  */
11
12 #include "io/targeting.h"
13 #include "cmd-action/cmd-pet.h"
14 #include "cmd-building/cmd-building.h"
15 #include "core/sort.h"
16 #include "core/stuff-handler.h"
17 #include "info-reader/fixed-map-parser.h"
18 #include "dungeon/dungeon.h"
19 #include "dungeon/quest.h"
20 #include "effect/spells-effect-util.h"
21 #include "floor/floor-events.h"
22 #include "floor/floor-object.h"
23 #include "floor/floor-town.h"
24 #include "floor/floor.h"
25 #include "game-option/cheat-options.h"
26 #include "game-option/disturbance-options.h"
27 #include "game-option/game-play-options.h"
28 #include "game-option/input-options.h"
29 #include "game-option/map-screen-options.h"
30 #include "grid/feature.h"
31 #include "grid/grid.h"
32 #include "inventory/player-inventory.h"
33 #include "io/input-key-acceptor.h"
34 #include "main/sound-of-music.h"
35 #include "monster-race/race-flags1.h"
36 #include "monster-race/monster-race-hook.h"
37 #include "monster/monster-describer.h"
38 #include "monster/monster-description-types.h"
39 #include "monster/monster-flag-types.h"
40 #include "monster/monster-info.h"
41 #include "monster/monster-status.h"
42 #include "monster/monster-update.h"
43 #include "monster/smart-learn-types.h"
44 #include "object-enchant/object-curse.h"
45 #include "object/object-flavor.h"
46 #include "object/object-kind-hook.h"
47 #include "object/object-mark-types.h"
48 #include "player/player-move.h"
49 #include "player/player-race-types.h"
50 #include "player/player-status.h"
51 #include "spell/spells-summon.h"
52 #include "system/building-type-definition.h"
53 #include "system/system-variables.h"
54 #include "term/term-color-types.h"
55 #include "view/display-main-window.h"
56 #include "view/display-messages.h"
57 #include "view/display-lore.h"
58 #include "view/display-monster-status.h"
59 #include "world/world.h"
60
61  /*!
62   * @brief コンソール上におけるマップ表示の左上位置を返す /
63   * Calculates current boundaries Called below and from "do_cmd_locate()".
64   * @return なし
65   */
66 void panel_bounds_center(void)
67 {
68         TERM_LEN wid, hgt;
69
70         get_screen_size(&wid, &hgt);
71
72         panel_row_max = panel_row_min + hgt - 1;
73         panel_row_prt = panel_row_min - 1;
74         panel_col_max = panel_col_min + wid - 1;
75         panel_col_prt = panel_col_min - 13;
76 }
77
78 /*!
79  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
80  * @param creature_ptr プレーヤーへの参照ポインタ
81  * @param y 変更先のフロアY座標
82  * @param x 変更先のフロアX座標
83  * @details
84  * Handle a request to change the current panel
85  * Return TRUE if the panel was changed.
86  * Also used in do_cmd_locate
87  * @return 実際に再描画が必要だった場合TRUEを返す
88  */
89 static bool change_panel_xy(player_type *creature_ptr, POSITION y, POSITION x)
90 {
91         POSITION dy = 0, dx = 0;
92         TERM_LEN wid, hgt;
93         get_screen_size(&wid, &hgt);
94
95         if (y < panel_row_min) dy = -1;
96         if (y > panel_row_max) dy = 1;
97         if (x < panel_col_min) dx = -1;
98         if (x > panel_col_max) dx = 1;
99
100         if (!dy && !dx) return FALSE;
101
102         return change_panel(creature_ptr, dy, dx);
103 }
104
105
106 /*!
107  * @brief マップ描画のフォーカスを当てるべき座標を更新する
108  * @param creature_ptr プレーヤーへの参照ポインタ
109  * @details
110  * Given an row (y) and col (x), this routine detects when a move
111  * off the screen has occurred and figures new borders. -RAK-
112  * "Update" forces a "full update" to take place.
113  * The map is reprinted if necessary, and "TRUE" is returned.
114  * @return 実際に再描画が必要だった場合TRUEを返す
115  */
116 void verify_panel(player_type *creature_ptr)
117 {
118         POSITION y = creature_ptr->y;
119         POSITION x = creature_ptr->x;
120         TERM_LEN wid, hgt;
121
122         get_screen_size(&wid, &hgt);
123
124         int max_prow_min = creature_ptr->current_floor_ptr->height - hgt;
125         int max_pcol_min = creature_ptr->current_floor_ptr->width - wid;
126
127         /* Bounds checking */
128         int prow_min;
129         int pcol_min;
130         if (max_prow_min < 0) max_prow_min = 0;
131         if (max_pcol_min < 0) max_pcol_min = 0;
132
133         /* Center on player */
134         if (center_player && (center_running || !creature_ptr->running))
135         {
136                 /* Center vertically */
137                 prow_min = y - hgt / 2;
138                 if (prow_min < 0) prow_min = 0;
139                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
140
141                 /* Center horizontally */
142                 pcol_min = x - wid / 2;
143                 if (pcol_min < 0) pcol_min = 0;
144                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
145         }
146         else
147         {
148                 prow_min = panel_row_min;
149                 pcol_min = panel_col_min;
150
151                 /* Scroll screen when 2 grids from top/bottom edge */
152                 if (y > panel_row_max - 2)
153                 {
154                         while (y > prow_min + hgt - 1 - 2)
155                         {
156                                 prow_min += (hgt / 2);
157                         }
158                 }
159
160                 if (y < panel_row_min + 2)
161                 {
162                         while (y < prow_min + 2)
163                         {
164                                 prow_min -= (hgt / 2);
165                         }
166                 }
167
168                 if (prow_min > max_prow_min) prow_min = max_prow_min;
169                 if (prow_min < 0) prow_min = 0;
170
171                 /* Scroll screen when 4 grids from left/right edge */
172                 if (x > panel_col_max - 4)
173                 {
174                         while (x > pcol_min + wid - 1 - 4)
175                         {
176                                 pcol_min += (wid / 2);
177                         }
178                 }
179
180                 if (x < panel_col_min + 4)
181                 {
182                         while (x < pcol_min + 4)
183                         {
184                                 pcol_min -= (wid / 2);
185                         }
186                 }
187
188                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
189                 if (pcol_min < 0) pcol_min = 0;
190         }
191
192         /* Check for "no change" */
193         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
194
195         /* Save the new panel info */
196         panel_row_min = prow_min;
197         panel_col_min = pcol_min;
198
199         /* Hack -- optional disturb on "panel change" */
200         if (disturb_panel && !center_player) disturb(creature_ptr, FALSE, FALSE);
201
202         panel_bounds_center();
203
204         creature_ptr->update |= (PU_MONSTERS);
205         creature_ptr->redraw |= (PR_MAP);
206         creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
207 }
208
209
210 /*
211  * Determine is a monster makes a reasonable target
212  *
213  * The concept of "targeting" was stolen from "Morgul" (?)
214  *
215  * The player can target any location, or any "target-able" monster.
216  *
217  * Currently, a monster is "target_able" if it is visible, and if
218  * the player can hit it with a projection, and the player is not
219  * hallucinating.  This allows use of "use closest target" macros.
220  *
221  * Future versions may restrict the ability to target "trappers"
222  * and "mimics", but the semantics is a little bit weird.
223  */
224 bool target_able(player_type *creature_ptr, MONSTER_IDX m_idx)
225 {
226         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
227         monster_type *m_ptr = &floor_ptr->m_list[m_idx];
228
229         /* Monster must be alive */
230         if (!monster_is_valid(m_ptr)) return FALSE;
231
232         /* Hack -- no targeting hallucinations */
233         if (creature_ptr->image) return FALSE;
234
235         /* Monster must be visible */
236         if (!m_ptr->ml) return FALSE;
237
238         if (creature_ptr->riding && (creature_ptr->riding == m_idx)) return TRUE;
239
240         /* Monster must be projectable */
241         if (!projectable(creature_ptr, creature_ptr->y, creature_ptr->x, m_ptr->fy, m_ptr->fx)) return FALSE;
242
243         /* Hack -- Never target trappers */
244         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return FALSE; */
245
246         /* Assume okay */
247         return TRUE;
248 }
249
250
251 /*
252  * Targetting variables
253  */
254 MONSTER_IDX target_who;
255 POSITION target_col;
256 POSITION target_row;
257
258 /*
259  * Update (if necessary) and verify (if possible) the target.
260  *
261  * We return TRUE if the target is "okay" and FALSE otherwise.
262  */
263 bool target_okay(player_type *creature_ptr)
264 {
265         /* Accept stationary targets */
266         if (target_who < 0) return TRUE;
267
268         /* Check moving targets */
269         if (target_who <= 0) return FALSE;
270
271         /* Accept reasonable targets */
272         if (!target_able(creature_ptr, target_who)) return FALSE;
273
274         monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[target_who];
275
276         /* Acquire monster location */
277         target_row = m_ptr->fy;
278         target_col = m_ptr->fx;
279
280         /* Good target */
281         return TRUE;
282 }
283
284
285 /*
286  * Hack -- help "select" a location (see below)
287  */
288 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
289 {
290         /* Scan the locations */
291         POSITION_IDX b_i = -1, b_v = 9999;
292         for (POSITION_IDX i = 0; i < tmp_pos.n; i++)
293         {
294                 /* Point 2 */
295                 POSITION x2 = tmp_pos.x[i];
296                 POSITION y2 = tmp_pos.y[i];
297
298                 /* Directed distance */
299                 POSITION x3 = (x2 - x1);
300                 POSITION y3 = (y2 - y1);
301
302                 /* Verify quadrant */
303                 if (dx && (x3 * dx <= 0)) continue;
304                 if (dy && (y3 * dy <= 0)) continue;
305
306                 POSITION x4 = ABS(x3);
307                 POSITION y4 = ABS(y3);
308
309                 /* Verify quadrant */
310                 if (dy && !dx && (x4 > y4)) continue;
311                 if (dx && !dy && (y4 > x4)) continue;
312
313                 /* Approximate Double Distance */
314                 POSITION_IDX v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
315
316                 /* Penalize location */
317                 if ((b_i >= 0) && (v >= b_v)) continue;
318                 b_i = i; b_v = v;
319         }
320
321         return b_i;
322 }
323
324
325 /*
326  * Hack -- determine if a given location is "interesting"
327  */
328 static bool target_set_accept(player_type *creature_ptr, POSITION y, POSITION x)
329 {
330         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
331         if (!(in_bounds(floor_ptr, y, x))) return FALSE;
332
333         /* Player grid is always interesting */
334         if (player_bold(creature_ptr, y, x)) return TRUE;
335
336         if (creature_ptr->image) return FALSE;
337
338         grid_type *g_ptr;
339         g_ptr = &floor_ptr->grid_array[y][x];
340
341         /* Visible monsters */
342         if (g_ptr->m_idx)
343         {
344                 monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
345
346                 /* Visible monsters */
347                 if (m_ptr->ml) return TRUE;
348         }
349
350         /* Scan all objects in the grid */
351         OBJECT_IDX next_o_idx = 0;
352         for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
353         {
354                 object_type *o_ptr;
355                 o_ptr = &floor_ptr->o_list[this_o_idx];
356                 next_o_idx = o_ptr->next_o_idx;
357
358                 /* Memorized object */
359                 if (o_ptr->marked & OM_FOUND) return TRUE;
360         }
361
362         /* Interesting memorized features */
363         if (g_ptr->info & (CAVE_MARK))
364         {
365                 /* Notice object features */
366                 if (g_ptr->info & CAVE_OBJECT) return TRUE;
367
368                 /* Feature code (applying "mimic" field) */
369                 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_NOTICE)) return TRUE;
370         }
371
372         return FALSE;
373 }
374
375
376 /*
377  * Prepare the "temp" array for "target_set"
378  *
379  * Return the number of target_able monsters in the set.
380  */
381 static void target_set_prepare(player_type *creature_ptr, BIT_FLAGS mode)
382 {
383         POSITION min_hgt, max_hgt, min_wid, max_wid;
384         if (mode & TARGET_KILL)
385         {
386                 /* Inner range */
387                 min_hgt = MAX((creature_ptr->y - MAX_RANGE), 0);
388                 max_hgt = MIN((creature_ptr->y + MAX_RANGE), creature_ptr->current_floor_ptr->height - 1);
389                 min_wid = MAX((creature_ptr->x - MAX_RANGE), 0);
390                 max_wid = MIN((creature_ptr->x + MAX_RANGE), creature_ptr->current_floor_ptr->width - 1);
391         }
392         else /* not targetting */
393         {
394                 /* Inner panel */
395                 min_hgt = panel_row_min;
396                 max_hgt = panel_row_max;
397                 min_wid = panel_col_min;
398                 max_wid = panel_col_max;
399         }
400
401         /* Reset "temp" array */
402         tmp_pos.n = 0;
403
404         /* Scan the current panel */
405         for (POSITION y = min_hgt; y <= max_hgt; y++)
406         {
407                 for (POSITION x = min_wid; x <= max_wid; x++)
408                 {
409                         grid_type *g_ptr;
410
411                         /* Require "interesting" contents */
412                         if (!target_set_accept(creature_ptr, y, x)) continue;
413
414                         g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
415
416                         /* Require target_able monsters for "TARGET_KILL" */
417                         if ((mode & (TARGET_KILL)) && !target_able(creature_ptr, g_ptr->m_idx)) continue;
418
419                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx])) continue;
420
421                         /* Save the location */
422                         tmp_pos.x[tmp_pos.n] = x;
423                         tmp_pos.y[tmp_pos.n] = y;
424                         tmp_pos.n++;
425                 }
426         }
427
428         /* Set the sort hooks */
429         if (mode & (TARGET_KILL))
430         {
431                 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
432         }
433         else
434         {
435                 ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_importance, ang_sort_swap_distance);
436         }
437
438         if (creature_ptr->riding == 0 || !target_pet || (tmp_pos.n <= 1) || !(mode & (TARGET_KILL)))
439                 return;
440
441         POSITION tmp = tmp_pos.y[0];
442         tmp_pos.y[0] = tmp_pos.y[1];
443         tmp_pos.y[1] = tmp;
444         tmp = tmp_pos.x[0];
445         tmp_pos.x[0] = tmp_pos.x[1];
446         tmp_pos.x[1] = tmp;
447 }
448
449
450 void target_set_prepare_look(player_type *creature_ptr)
451 {
452         target_set_prepare(creature_ptr, TARGET_LOOK);
453 }
454
455
456 /*
457  * Evaluate number of kill needed to gain level
458  */
459 static void evaluate_monster_exp(player_type *creature_ptr, char *buf, monster_type *m_ptr)
460 {
461         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
462         u32b num;
463         s32b exp_mon, exp_adv;
464         u32b exp_mon_frac, exp_adv_frac;
465
466         if ((creature_ptr->lev >= PY_MAX_LEVEL) || (creature_ptr->prace == RACE_ANDROID))
467         {
468                 sprintf(buf, "**");
469                 return;
470         }
471         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
472         {
473                 if (!current_world_ptr->wizard)
474                 {
475                         sprintf(buf, "??");
476                         return;
477                 }
478         }
479
480         /* The monster's experience point (assuming average monster speed) */
481         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
482         exp_mon_frac = 0;
483         s64b_div(&exp_mon, &exp_mon_frac, 0, (creature_ptr->max_plv + 2));
484
485
486         /* Total experience value for next level */
487         exp_adv = player_exp[creature_ptr->lev - 1] * creature_ptr->expfact;
488         exp_adv_frac = 0;
489         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
490
491         /* Experience value need to get */
492         s64b_sub(&exp_adv, &exp_adv_frac, creature_ptr->exp, creature_ptr->exp_frac);
493
494
495         /* You need to kill at least one monster to get any experience */
496         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
497         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
498
499         /* Extract number of monsters needed */
500         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
501
502         /* If 999 or more monsters needed, only display "999". */
503         num = MIN(999, exp_adv_frac);
504
505         /* Display the number */
506         sprintf(buf, "%03ld", (long int)num);
507 }
508
509
510 bool show_gold_on_floor = FALSE;
511
512 /*
513  * Examine a grid, return a keypress.
514  *
515  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
516  * indicates that the "space" key should scan through the contents
517  * of the grid, instead of simply returning immediately.  This lets
518  * the "look" command get complete information, without making the
519  * "target" command annoying.
520  *
521  * The "info" argument contains the "commands" which should be shown
522  * inside the "[xxx]" text.  This string must never be empty, or grids
523  * containing monsters will be displayed with an extra comma.
524  *
525  * Note that if a monster is in the grid, we update both the monster
526  * recall info and the health bar info to track that monster.
527  *
528  * Eventually, we may allow multiple objects per grid, or objects
529  * and terrain features in the same grid.
530  *
531  * This function must handle blindness/hallucination.
532  */
533 static char target_set_aux(player_type *subject_ptr, POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
534 {
535         OBJECT_IDX next_o_idx = 0;
536         concptr s1 = "", s2 = "", s3 = "", x_info = "";
537         bool boring = TRUE;
538         FEAT_IDX feat;
539         feature_type *f_ptr;
540         char query = '\001';
541         char out_val[MAX_NLEN + 80];
542         OBJECT_IDX floor_list[23];
543         ITEM_NUMBER floor_num = 0;
544
545         /* Scan all objects in the grid */
546         if (easy_floor)
547         {
548                 floor_num = scan_floor(subject_ptr, floor_list, y, x, 0x02, 0);
549
550                 if (floor_num)
551                 {
552                         x_info = _("x物 ", "x,");
553                 }
554         }
555
556         /* Hack -- under the player */
557         if (player_bold(subject_ptr, y, x))
558         {
559 #ifdef JP
560                 s1 = "あなたは";
561                 s2 = "の上";
562                 s3 = "にいる";
563 #else
564                 s1 = "You are ";
565                 s2 = "on ";
566 #endif
567         }
568         else
569         {
570                 s1 = _("ターゲット:", "Target:");
571         }
572
573         /* Hack -- hallucination */
574         if (subject_ptr->image)
575         {
576                 concptr name = _("何か奇妙な物", "something strange");
577
578                 /* Display a message */
579 #ifdef JP
580                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
581 #else
582                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
583 #endif
584
585                 prt(out_val, 0, 0);
586                 move_cursor_relative(y, x);
587                 query = inkey();
588
589                 /* Stop on everything but "return" */
590                 if ((query != '\r') && (query != '\n')) return query;
591
592                 /* Repeat forever */
593                 return 0;
594         }
595
596         /* Actual monsters */
597         grid_type *g_ptr = &subject_ptr->current_floor_ptr->grid_array[y][x];
598         if (g_ptr->m_idx && subject_ptr->current_floor_ptr->m_list[g_ptr->m_idx].ml)
599         {
600                 monster_type *m_ptr = &subject_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
601                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
602                 GAME_TEXT m_name[MAX_NLEN];
603                 bool recall = FALSE;
604
605                 /* Not boring */
606                 boring = FALSE;
607
608                 monster_desc(subject_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
609                 monster_race_track(subject_ptr, m_ptr->ap_r_idx);
610                 health_track(subject_ptr, g_ptr->m_idx);
611                 handle_stuff(subject_ptr);
612
613                 /* Interact */
614                 while (TRUE)
615                 {
616                         char acount[10];
617
618                         if (recall)
619                         {
620                                 screen_save();
621
622                                 /* Recall on screen */
623                                 screen_roff(subject_ptr, m_ptr->ap_r_idx, 0);
624
625                                 /* Hack -- Complete the prompt (again) */
626                                 Term_addstr(-1, TERM_WHITE, format(_("  [r思 %s%s]", "  [r,%s%s]"), x_info, info));
627
628                                 query = inkey();
629
630                                 screen_load();
631
632                                 /* Normal commands */
633                                 if (query != 'r') break;
634
635                                 recall = FALSE;
636
637                                 /* Cleare recall text and repeat */
638                                 continue;
639                         }
640
641                         /*** Normal ***/
642
643                         /* Describe, and prompt for recall */
644                         evaluate_monster_exp(subject_ptr, acount, m_ptr);
645
646 #ifdef JP
647                         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);
648 #else
649                         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);
650 #endif
651
652                         prt(out_val, 0, 0);
653
654                         /* Place cursor */
655                         move_cursor_relative(y, x);
656
657                         query = inkey();
658
659                         /* Normal commands */
660                         if (query != 'r') break;
661
662                         recall = TRUE;
663                 }
664
665                 /* Always stop at "normal" keys */
666                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
667
668                 /* Sometimes stop at "space" key */
669                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
670
671                 /* Change the intro */
672                 s1 = _("それは", "It is ");
673
674                 /* Hack -- take account of gender */
675                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
676                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
677
678                 /* Use a preposition */
679 #ifdef JP
680                 s2 = "を";
681                 s3 = "持っている";
682 #else
683                 s2 = "carrying ";
684 #endif
685
686                 /* Scan all objects being carried */
687                 for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
688                 {
689                         GAME_TEXT o_name[MAX_NLEN];
690
691                         object_type *o_ptr;
692                         o_ptr = &subject_ptr->current_floor_ptr->o_list[this_o_idx];
693                         next_o_idx = o_ptr->next_o_idx;
694
695                         object_desc(subject_ptr, o_name, o_ptr, 0);
696
697 #ifdef JP
698                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
699 #else
700                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
701 #endif
702
703                         prt(out_val, 0, 0);
704                         move_cursor_relative(y, x);
705                         query = inkey();
706
707                         /* Always stop at "normal" keys */
708                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
709
710                         /* Sometimes stop at "space" key */
711                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
712
713                         /* Change the intro */
714                         s2 = _("をまた", "also carrying ");
715                 }
716
717                 /* Use a preposition */
718 #ifdef JP
719                 s2 = "の上";
720                 s3 = "にいる";
721 #else
722                 s2 = "on ";
723 #endif
724         }
725
726         if (floor_num)
727         {
728                 int min_width = 0;
729
730                 while (TRUE)
731                 {
732                         if (floor_num == 1)
733                         {
734                                 GAME_TEXT o_name[MAX_NLEN];
735
736                                 object_type *o_ptr;
737                                 o_ptr = &subject_ptr->current_floor_ptr->o_list[floor_list[0]];
738
739                                 object_desc(subject_ptr, o_name, o_ptr, 0);
740
741 #ifdef JP
742                                 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
743 #else
744                                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
745 #endif
746
747                                 prt(out_val, 0, 0);
748                                 move_cursor_relative(y, x);
749
750                                 query = inkey();
751
752                                 /* End this grid */
753                                 return query;
754                         }
755
756                         /* Provide one cushion before item listing  */
757                         if (boring)
758                         {
759                                 /* Display rough information about items */
760 #ifdef JP
761                                 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
762 #else
763                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
764 #endif
765
766                                 prt(out_val, 0, 0);
767                                 move_cursor_relative(y, x);
768
769                                 query = inkey();
770
771                                 /* No request for listing */
772                                 if (query != 'x' && query != ' ') return query;
773                         }
774
775
776                         /** Display list of items **/
777
778                         /* Continue scrolling list if requested */
779                         while (TRUE)
780                         {
781                                 int i;
782                                 OBJECT_IDX o_idx;
783                                 screen_save();
784
785                                 /* Display */
786                                 show_gold_on_floor = TRUE;
787                                 (void)show_floor(subject_ptr, 0, y, x, &min_width, 0);
788                                 show_gold_on_floor = FALSE;
789
790                                 /* Prompt */
791 #ifdef JP
792                                 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
793 #else
794                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
795 #endif
796                                 prt(out_val, 0, 0);
797
798                                 query = inkey();
799                                 screen_load();
800
801                                 /* Exit unless 'Enter' */
802                                 if (query != '\n' && query != '\r')
803                                 {
804                                         return query;
805                                 }
806
807                                 /* Get the object being moved. */
808                                 o_idx = g_ptr->o_idx;
809
810                                 /* Only rotate a pile of two or more objects. */
811                                 if (!(o_idx && subject_ptr->current_floor_ptr->o_list[o_idx].next_o_idx)) continue;
812
813                                 /* Remove the first object from the list. */
814                                 excise_object_idx(subject_ptr->current_floor_ptr, o_idx);
815
816                                 /* Find end of the list. */
817                                 i = g_ptr->o_idx;
818                                 while (subject_ptr->current_floor_ptr->o_list[i].next_o_idx)
819                                         i = subject_ptr->current_floor_ptr->o_list[i].next_o_idx;
820
821                                 /* Add after the last object. */
822                                 subject_ptr->current_floor_ptr->o_list[i].next_o_idx = o_idx;
823
824                                 /* Loop and re-display the list */
825                         }
826                 }
827
828                 /* NOTREACHED */
829         }
830
831         /* Scan all objects in the grid */
832         for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
833         {
834                 object_type *o_ptr;
835                 o_ptr = &subject_ptr->current_floor_ptr->o_list[this_o_idx];
836                 next_o_idx = o_ptr->next_o_idx;
837
838                 if (o_ptr->marked & OM_FOUND)
839                 {
840                         GAME_TEXT o_name[MAX_NLEN];
841
842                         /* Not boring */
843                         boring = FALSE;
844
845                         object_desc(subject_ptr, o_name, o_ptr, 0);
846
847 #ifdef JP
848                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
849 #else
850                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
851 #endif
852
853                         prt(out_val, 0, 0);
854                         move_cursor_relative(y, x);
855                         query = inkey();
856
857                         /* Always stop at "normal" keys */
858                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
859
860                         /* Sometimes stop at "space" key */
861                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
862
863                         /* Change the intro */
864                         s1 = _("それは", "It is ");
865
866                         /* Plurals */
867                         if (o_ptr->number != 1) s1 = _("それらは", "They are ");
868
869                         /* Preposition */
870 #ifdef JP
871                         s2 = "の上";
872                         s3 = "に見える";
873 #else
874                         s2 = "on ";
875 #endif
876
877                 }
878         }
879
880         /* Feature code (applying "mimic" field) */
881         feat = get_feat_mimic(g_ptr);
882
883         /* Require knowledge about grid, or ability to see grid */
884         if (!(g_ptr->info & CAVE_MARK) && !player_can_see_bold(subject_ptr, y, x))
885         {
886                 /* Forget feature */
887                 feat = feat_none;
888         }
889
890         f_ptr = &f_info[feat];
891
892         /* Terrain feature if needed */
893         if (!boring && !have_flag(f_ptr->flags, FF_REMEMBER))
894         {
895                 if ((query != '\r') && (query != '\n')) return query;
896                 return 0;
897         }
898
899         /* Hack -- special handling for quest entrances */
900         concptr name;
901         if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
902         {
903                 /* Set the quest number temporary */
904                 IDX old_quest = subject_ptr->current_floor_ptr->inside_quest;
905                 int j;
906
907                 /* Clear the text */
908                 for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
909                 quest_text_line = 0;
910
911                 subject_ptr->current_floor_ptr->inside_quest = g_ptr->special;
912
913                 /* Get the quest text */
914                 init_flags = INIT_NAME_ONLY;
915
916                 parse_fixed_map(subject_ptr, "q_info.txt", 0, 0, 0, 0);
917
918                 name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"),
919                         quest[g_ptr->special].name, quest[g_ptr->special].level);
920
921                 /* Reset the old quest number */
922                 subject_ptr->current_floor_ptr->inside_quest = old_quest;
923         }
924
925         /* Hack -- special handling for building doors */
926         else if (have_flag(f_ptr->flags, FF_BLDG) && !subject_ptr->current_floor_ptr->inside_arena)
927         {
928                 name = building[f_ptr->subtype].name;
929         }
930         else if (have_flag(f_ptr->flags, FF_ENTRANCE))
931         {
932                 name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[g_ptr->special].text, d_info[g_ptr->special].mindepth);
933         }
934         else if (have_flag(f_ptr->flags, FF_TOWN))
935         {
936                 name = town_info[g_ptr->special].name;
937         }
938         else if (subject_ptr->wild_mode && (feat == feat_floor))
939         {
940                 name = _("道", "road");
941         }
942         else
943         {
944                 name = f_name + f_ptr->name;
945         }
946
947         /* Pick a prefix */
948         if (*s2 &&
949                 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
950                 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
951                         have_flag(f_ptr->flags, FF_TOWN)))
952         {
953                 s2 = _("の中", "in ");
954         }
955
956         /* Hack -- special introduction for store & building doors -KMW- */
957         if (have_flag(f_ptr->flags, FF_STORE) ||
958                 have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
959                 (have_flag(f_ptr->flags, FF_BLDG) && !subject_ptr->current_floor_ptr->inside_arena) ||
960                 have_flag(f_ptr->flags, FF_ENTRANCE))
961         {
962                 s2 = _("の入口", "");
963         }
964 #ifdef JP
965 #else
966         else if (have_flag(f_ptr->flags, FF_FLOOR) ||
967                 have_flag(f_ptr->flags, FF_TOWN) ||
968                 have_flag(f_ptr->flags, FF_SHALLOW) ||
969                 have_flag(f_ptr->flags, FF_DEEP))
970         {
971                 s3 = "";
972         }
973         else
974         {
975                 /* Pick proper indefinite article */
976                 s3 = (is_a_vowel(name[0])) ? "an " : "a ";
977         }
978 #endif
979
980         /* Display a message */
981         if (current_world_ptr->wizard)
982         {
983                 char f_idx_str[32];
984                 if (g_ptr->mimic) sprintf(f_idx_str, "%d/%d", g_ptr->feat, g_ptr->mimic);
985                 else sprintf(f_idx_str, "%d", g_ptr->feat);
986 #ifdef JP
987                 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, g_ptr->when, (int)y, (int)x, travel.cost[y][x]);
988 #else
989                 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, (int)x);
990 #endif
991         }
992         else
993 #ifdef JP
994                 sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
995 #else
996                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
997 #endif
998
999         prt(out_val, 0, 0);
1000         move_cursor_relative(y, x);
1001         query = inkey();
1002
1003         if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
1004         return 0;
1005 }
1006
1007
1008 /*
1009  * Handle "target" and "look".
1010  *
1011  * Note that this code can be called from "get_aim_dir()".
1012  *
1013  * All locations must be on the current panel.  Consider the use of
1014  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
1015  * some form of "scrolling" the map around the cursor.
1016  * That is, consider the possibility of "auto-scrolling" the screen
1017  * while the cursor moves around.  This may require changes in the
1018  * "update_monster()" code to allow "visibility" even if off panel, and
1019  * may require dynamic recalculation of the "temp" grid set.
1020  *
1021  * Hack -- targeting/observing an "outer border grid" may induce
1022  * problems, so this is not currently allowed.
1023  *
1024  * The player can use the direction keys to move among "interesting"
1025  * grids in a heuristic manner, or the "space", "+", and "-" keys to
1026  * move through the "interesting" grids in a sequential manner, or
1027  * can enter "location" mode, and use the direction keys to move one
1028  * grid at a time in any direction.  The "t" (set target) command will
1029  * only target a monster (as opposed to a location) if the monster is
1030  * target_able and the "interesting" mode is being used.
1031  *
1032  * The current grid is described using the "look" method above, and
1033  * a new command may be entered at any time, but note that if the
1034  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
1035  * where "space" has no obvious meaning) then "space" will scan
1036  * through the description of the current grid until done, instead
1037  * of immediately jumping to the next "interesting" grid.  This
1038  * allows the "target" command to retain its old semantics.
1039  *
1040  * The "*", "+", and "-" keys may always be used to jump immediately
1041  * to the next (or previous) interesting grid, in the proper mode.
1042  *
1043  * The "return" key may always be used to scan through a complete
1044  * grid description (forever).
1045  *
1046  * This command will cancel any old target, even if used from
1047  * inside the "look" command.
1048  */
1049 bool target_set(player_type *creature_ptr, BIT_FLAGS mode)
1050 {
1051         int i, d, t, bd;
1052         POSITION y = creature_ptr->y;
1053         POSITION x = creature_ptr->x;
1054
1055         bool done = FALSE;
1056         bool flag = TRUE;
1057         char query;
1058         char info[80];
1059         char same_key;
1060         grid_type *g_ptr;
1061         TERM_LEN wid, hgt;
1062
1063         get_screen_size(&wid, &hgt);
1064
1065         /* Cancel target */
1066         target_who = 0;
1067
1068         if (rogue_like_commands)
1069         {
1070                 same_key = 'x';
1071         }
1072         else
1073         {
1074                 same_key = 'l';
1075         }
1076
1077         /* Prepare the "temp" array */
1078         target_set_prepare(creature_ptr, mode);
1079
1080         /* Start near the player */
1081         int m = 0;
1082
1083         /* Interact */
1084         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1085         while (!done)
1086         {
1087                 /* Interesting grids */
1088                 if (flag && tmp_pos.n)
1089                 {
1090                         y = tmp_pos.y[m];
1091                         x = tmp_pos.x[m];
1092
1093                         /* Set forcus */
1094                         change_panel_xy(creature_ptr, y, x);
1095
1096                         if (!(mode & TARGET_LOOK)) print_path(creature_ptr, y, x);
1097
1098                         /* Access */
1099                         g_ptr = &floor_ptr->grid_array[y][x];
1100
1101                         /* Allow target */
1102                         if (target_able(creature_ptr, g_ptr->m_idx))
1103                         {
1104                                 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
1105                         }
1106
1107                         /* Dis-allow target */
1108                         else
1109                         {
1110                                 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
1111                         }
1112
1113                         if (cheat_sight)
1114                         {
1115                                 char cheatinfo[30];
1116                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
1117                                         los(creature_ptr, creature_ptr->y, creature_ptr->x, y, x), projectable(creature_ptr, creature_ptr->y, creature_ptr->x, y, x));
1118                                 strcat(info, cheatinfo);
1119                         }
1120
1121                         /* Describe and Prompt */
1122                         while (TRUE)
1123                         {
1124                                 query = target_set_aux(creature_ptr, y, x, mode, info);
1125                                 if (query)break;
1126                         }
1127
1128                         /* Assume no "direction" */
1129                         d = 0;
1130
1131                         if (use_menu)
1132                         {
1133                                 if (query == '\r') query = 't';
1134                         }
1135
1136                         /* Analyze */
1137                         switch (query)
1138                         {
1139                         case ESCAPE:
1140                         case 'q':
1141                         {
1142                                 done = TRUE;
1143                                 break;
1144                         }
1145
1146                         case 't':
1147                         case '.':
1148                         case '5':
1149                         case '0':
1150                         {
1151                                 if (target_able(creature_ptr, g_ptr->m_idx))
1152                                 {
1153                                         health_track(creature_ptr, g_ptr->m_idx);
1154                                         target_who = g_ptr->m_idx;
1155                                         target_row = y;
1156                                         target_col = x;
1157                                         done = TRUE;
1158                                 }
1159                                 else
1160                                 {
1161                                         bell();
1162                                 }
1163                                 break;
1164                         }
1165
1166                         case ' ':
1167                         case '*':
1168                         case '+':
1169                         {
1170                                 if (++m == tmp_pos.n)
1171                                 {
1172                                         m = 0;
1173                                         if (!expand_list) done = TRUE;
1174                                 }
1175                                 break;
1176                         }
1177
1178                         case '-':
1179                         {
1180                                 if (m-- == 0)
1181                                 {
1182                                         m = tmp_pos.n - 1;
1183                                         if (!expand_list) done = TRUE;
1184                                 }
1185                                 break;
1186                         }
1187
1188                         case 'p':
1189                         {
1190                                 /* Recenter the map around the player */
1191                                 verify_panel(creature_ptr);
1192                                 creature_ptr->update |= (PU_MONSTERS);
1193                                 creature_ptr->redraw |= (PR_MAP);
1194                                 creature_ptr->window |= (PW_OVERHEAD);
1195                                 handle_stuff(creature_ptr);
1196
1197                                 /* Recalculate interesting grids */
1198                                 target_set_prepare(creature_ptr, mode);
1199
1200                                 y = creature_ptr->y;
1201                                 x = creature_ptr->x;
1202                         }
1203                                 /* Fall through */
1204
1205                         case 'o':
1206                         {
1207                                 flag = FALSE;
1208                                 break;
1209                         }
1210
1211                         case 'm':
1212                         {
1213                                 break;
1214                         }
1215
1216                         default:
1217                         {
1218                                 if (query == same_key)
1219                                 {
1220                                         if (++m == tmp_pos.n)
1221                                         {
1222                                                 m = 0;
1223                                                 if (!expand_list) done = TRUE;
1224                                         }
1225                                 }
1226                                 else
1227                                 {
1228                                         /* Extract the action (if any) */
1229                                         d = get_keymap_dir(query);
1230
1231                                         if (!d) bell();
1232                                         break;
1233                                 }
1234                         }
1235                         }
1236                         /* Hack -- move around */
1237                         if (d)
1238                         {
1239                                 /* Modified to scroll to monster */
1240                                 POSITION y2 = panel_row_min;
1241                                 POSITION x2 = panel_col_min;
1242
1243                                 /* Find a new monster */
1244                                 i = target_pick(tmp_pos.y[m], tmp_pos.x[m], ddy[d], ddx[d]);
1245
1246                                 /* Request to target past last interesting grid */
1247                                 while (flag && (i < 0))
1248                                 {
1249                                         /* Note the change */
1250                                         if (change_panel(creature_ptr, ddy[d], ddx[d]))
1251                                         {
1252                                                 int v = tmp_pos.y[m];
1253                                                 int u = tmp_pos.x[m];
1254
1255                                                 /* Recalculate interesting grids */
1256                                                 target_set_prepare(creature_ptr, mode);
1257
1258                                                 /* Look at interesting grids */
1259                                                 flag = TRUE;
1260
1261                                                 /* Find a new monster */
1262                                                 i = target_pick(v, u, ddy[d], ddx[d]);
1263
1264                                                 /* Use that grid */
1265                                                 if (i >= 0) m = i;
1266                                                 continue;
1267                                         }
1268
1269                                         /* Nothing interesting */
1270                                         POSITION dx = ddx[d];
1271                                         POSITION dy = ddy[d];
1272
1273                                         /* Restore previous position */
1274                                         panel_row_min = y2;
1275                                         panel_col_min = x2;
1276                                         panel_bounds_center();
1277
1278                                         creature_ptr->update |= (PU_MONSTERS);
1279                                         creature_ptr->redraw |= (PR_MAP);
1280                                         creature_ptr->window |= (PW_OVERHEAD);
1281                                         handle_stuff(creature_ptr);
1282
1283                                         /* Recalculate interesting grids */
1284                                         target_set_prepare(creature_ptr, mode);
1285
1286                                         /* Look at boring grids */
1287                                         flag = FALSE;
1288
1289                                         /* Move */
1290                                         x += dx;
1291                                         y += dy;
1292
1293                                         /* Do not move horizontally if unnecessary */
1294                                         if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1295                                                 ((x > panel_col_min + wid / 2) && (dx < 0)))
1296                                         {
1297                                                 dx = 0;
1298                                         }
1299
1300                                         /* Do not move vertically if unnecessary */
1301                                         if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1302                                                 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1303                                         {
1304                                                 dy = 0;
1305                                         }
1306
1307                                         /* Apply the motion */
1308                                         if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1309                                                 (x >= panel_col_min + wid) || (x < panel_col_min))
1310                                         {
1311                                                 if (change_panel(creature_ptr, dy, dx)) target_set_prepare(creature_ptr, mode);
1312                                         }
1313
1314                                         /* Slide into legality */
1315                                         if (x >= floor_ptr->width - 1) x = floor_ptr->width - 2;
1316                                         else if (x <= 0) x = 1;
1317
1318                                         /* Slide into legality */
1319                                         if (y >= floor_ptr->height - 1) y = floor_ptr->height - 2;
1320                                         else if (y <= 0) y = 1;
1321                                 }
1322
1323                                 /* Use that grid */
1324                                 m = i;
1325                         }
1326
1327                         continue;
1328                 }
1329
1330                 /* Arbitrary grids */
1331
1332                 bool move_fast = FALSE;
1333
1334                 if (!(mode & TARGET_LOOK)) print_path(creature_ptr, y, x);
1335
1336                 /* Access */
1337                 g_ptr = &floor_ptr->grid_array[y][x];
1338
1339                 /* Default prompt */
1340                 strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
1341
1342                 if (cheat_sight)
1343                 {
1344                         char cheatinfo[100];
1345                         sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d, SPECIAL:%d",
1346                                 los(creature_ptr, creature_ptr->y, creature_ptr->x, y, x),
1347                                 projectable(creature_ptr, creature_ptr->y, creature_ptr->x, y, x), g_ptr->special);
1348                         strcat(info, cheatinfo);
1349                 }
1350
1351                 /* Describe and Prompt (enable "TARGET_LOOK") */
1352                 while ((query = target_set_aux(creature_ptr, y, x, mode | TARGET_LOOK, info)) == 0);
1353
1354                 /* Assume no direction */
1355                 d = 0;
1356
1357                 if (use_menu)
1358                 {
1359                         if (query == '\r') query = 't';
1360                 }
1361
1362                 /* Analyze the keypress */
1363                 switch (query)
1364                 {
1365                 case ESCAPE:
1366                 case 'q':
1367                 {
1368                         done = TRUE;
1369                         break;
1370                 }
1371
1372                 case 't':
1373                 case '.':
1374                 case '5':
1375                 case '0':
1376                 {
1377                         target_who = -1;
1378                         target_row = y;
1379                         target_col = x;
1380                         done = TRUE;
1381                         break;
1382                 }
1383
1384                 case 'p':
1385                 {
1386                         /* Recenter the map around the player */
1387                         verify_panel(creature_ptr);
1388                         creature_ptr->update |= (PU_MONSTERS);
1389                         creature_ptr->redraw |= (PR_MAP);
1390                         creature_ptr->window |= (PW_OVERHEAD);
1391                         handle_stuff(creature_ptr);
1392
1393                         /* Recalculate interesting grids */
1394                         target_set_prepare(creature_ptr, mode);
1395
1396                         y = creature_ptr->y;
1397                         x = creature_ptr->x;
1398                 }
1399
1400                 case 'o':
1401                 {
1402                         break;
1403                 }
1404
1405                 case ' ':
1406                 case '*':
1407                 case '+':
1408                 case '-':
1409                 case 'm':
1410                 {
1411                         flag = TRUE;
1412
1413                         m = 0;
1414                         bd = 999;
1415
1416                         /* Pick a nearby monster */
1417                         for (i = 0; i < tmp_pos.n; i++)
1418                         {
1419                                 t = distance(y, x, tmp_pos.y[i], tmp_pos.x[i]);
1420
1421                                 /* Pick closest */
1422                                 if (t < bd)
1423                                 {
1424                                         m = i;
1425                                         bd = t;
1426                                 }
1427                         }
1428
1429                         /* Nothing interesting */
1430                         if (bd == 999) flag = FALSE;
1431
1432                         break;
1433                 }
1434
1435                 default:
1436                 {
1437                         /* Extract the action (if any) */
1438                         d = get_keymap_dir(query);
1439
1440                         /* XTRA HACK MOVEFAST */
1441                         if (isupper(query)) move_fast = TRUE;
1442
1443                         if (!d) bell();
1444                         break;
1445                 }
1446                 }
1447
1448                 /* Handle "direction" */
1449                 if (d)
1450                 {
1451                         POSITION dx = ddx[d];
1452                         POSITION dy = ddy[d];
1453
1454                         /* XTRA HACK MOVEFAST */
1455                         if (move_fast)
1456                         {
1457                                 int mag = MIN(wid / 2, hgt / 2);
1458                                 x += dx * mag;
1459                                 y += dy * mag;
1460                         }
1461                         else
1462                         {
1463                                 x += dx;
1464                                 y += dy;
1465                         }
1466
1467                         /* Do not move horizontally if unnecessary */
1468                         if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
1469                                 ((x > panel_col_min + wid / 2) && (dx < 0)))
1470                         {
1471                                 dx = 0;
1472                         }
1473
1474                         /* Do not move vertically if unnecessary */
1475                         if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
1476                                 ((y > panel_row_min + hgt / 2) && (dy < 0)))
1477                         {
1478                                 dy = 0;
1479                         }
1480
1481                         /* Apply the motion */
1482                         if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
1483                                 (x >= panel_col_min + wid) || (x < panel_col_min))
1484                         {
1485                                 if (change_panel(creature_ptr, dy, dx)) target_set_prepare(creature_ptr, mode);
1486                         }
1487
1488                         /* Slide into legality */
1489                         if (x >= floor_ptr->width - 1) x = floor_ptr->width - 2;
1490                         else if (x <= 0) x = 1;
1491
1492                         /* Slide into legality */
1493                         if (y >= floor_ptr->height - 1) y = floor_ptr->height - 2;
1494                         else if (y <= 0) y = 1;
1495                 }
1496         }
1497
1498         /* Forget */
1499         tmp_pos.n = 0;
1500
1501         /* Clear the top line */
1502         prt("", 0, 0);
1503
1504         /* Recenter the map around the player */
1505         verify_panel(creature_ptr);
1506         creature_ptr->update |= (PU_MONSTERS);
1507         creature_ptr->redraw |= (PR_MAP);
1508         creature_ptr->window |= (PW_OVERHEAD);
1509         handle_stuff(creature_ptr);
1510
1511         return target_who != 0;
1512 }
1513
1514
1515 /*
1516  * Get an "aiming direction" from the user.
1517  *
1518  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
1519  * "0" for "current target", and "-1" for "entry aborted".
1520  *
1521  * Note that "Force Target", if set, will pre-empt user interaction,
1522  * if there is a usable target already set.
1523  *
1524  * Note that confusion over-rides any (explicit?) user choice.
1525  */
1526 bool get_aim_dir(player_type *creature_ptr, DIRECTION *dp)
1527 {
1528         /* Global direction */
1529         DIRECTION dir = command_dir;
1530
1531         /* Hack -- auto-target if requested */
1532         if (use_old_target && target_okay(creature_ptr)) dir = 5;
1533
1534         COMMAND_CODE code;
1535         if (repeat_pull(&code))
1536         {
1537                 /* Confusion? */
1538
1539                 /* Verify */
1540                 if (!(code == 5 && !target_okay(creature_ptr)))
1541                 {
1542                         /*                      return TRUE; */
1543                         dir = (DIRECTION)code;
1544                 }
1545         }
1546
1547         *dp = (DIRECTION)code;
1548
1549         /* Ask until satisfied */
1550         char command;
1551         while (!dir)
1552         {
1553                 /* Choose a prompt */
1554                 concptr p;
1555                 if (!target_okay(creature_ptr))
1556                 {
1557                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
1558                 }
1559                 else
1560                 {
1561                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
1562                 }
1563
1564                 /* Get a command (or Cancel) */
1565                 if (!get_com(p, &command, TRUE)) break;
1566
1567                 if (use_menu)
1568                 {
1569                         if (command == '\r') command = 't';
1570                 }
1571
1572                 /* Convert various keys to "standard" keys */
1573                 switch (command)
1574                 {
1575                         /* Use current target */
1576                 case 'T':
1577                 case 't':
1578                 case '.':
1579                 case '5':
1580                 case '0':
1581                 {
1582                         dir = 5;
1583                         break;
1584                 }
1585
1586                 /* Set new target */
1587                 case '*':
1588                 case ' ':
1589                 case '\r':
1590                 {
1591                         if (target_set(creature_ptr, TARGET_KILL)) dir = 5;
1592                         break;
1593                 }
1594
1595                 default:
1596                 {
1597                         /* Extract the action (if any) */
1598                         dir = get_keymap_dir(command);
1599
1600                         break;
1601                 }
1602                 }
1603
1604                 /* Verify requested targets */
1605                 if ((dir == 5) && !target_okay(creature_ptr)) dir = 0;
1606
1607                 /* Error */
1608                 if (!dir) bell();
1609         }
1610
1611         /* No direction */
1612         if (!dir)
1613         {
1614                 project_length = 0; /* reset to default */
1615                 return FALSE;
1616         }
1617
1618         /* Save the direction */
1619         command_dir = dir;
1620
1621         /* Check for confusion */
1622         if (creature_ptr->confused)
1623         {
1624                 /* Random direction */
1625                 dir = ddd[randint0(8)];
1626         }
1627
1628         /* Notice confusion */
1629         if (command_dir != dir)
1630         {
1631                 /* Warn the user */
1632                 msg_print(_("あなたは混乱している。", "You are confused."));
1633         }
1634
1635         /* Save direction */
1636         (*dp) = dir;
1637
1638         repeat_push((COMMAND_CODE)command_dir);
1639         return TRUE;
1640 }
1641
1642
1643 bool get_direction(player_type *creature_ptr, DIRECTION *dp, bool allow_under, bool with_steed)
1644 {
1645         /* Global direction */
1646         DIRECTION dir = command_dir;
1647
1648         COMMAND_CODE code;
1649         if (repeat_pull(&code))
1650         {
1651                 dir = (DIRECTION)code;
1652                 /*              return TRUE; */
1653         }
1654
1655         *dp = (DIRECTION)code;
1656
1657         concptr prompt;
1658         if (allow_under)
1659         {
1660                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1661         }
1662         else
1663         {
1664                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1665         }
1666
1667         /* Get a direction */
1668         while (!dir)
1669         {
1670                 char ch;
1671
1672                 /* Get a command (or Cancel) */
1673                 if (!get_com(prompt, &ch, TRUE)) break;
1674
1675                 /* Look down */
1676                 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1677                 {
1678                         dir = 5;
1679                 }
1680                 else
1681                 {
1682                         /* Look up the direction */
1683                         dir = get_keymap_dir(ch);
1684
1685                         if (!dir) bell();
1686                 }
1687         }
1688
1689         /* Prevent weirdness */
1690         if ((dir == 5) && (!allow_under)) dir = 0;
1691
1692         /* Aborted */
1693         if (!dir) return FALSE;
1694
1695         /* Save desired direction */
1696         command_dir = dir;
1697
1698         /* Apply "confusion" */
1699         if (creature_ptr->confused)
1700         {
1701                 /* Standard confusion */
1702                 if (randint0(100) < 75)
1703                 {
1704                         /* Random direction */
1705                         dir = ddd[randint0(8)];
1706                 }
1707         }
1708         else if (creature_ptr->riding && with_steed)
1709         {
1710                 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1711                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1712
1713                 if (monster_confused_remaining(m_ptr))
1714                 {
1715                         /* Standard confusion */
1716                         if (randint0(100) < 75)
1717                         {
1718                                 /* Random direction */
1719                                 dir = ddd[randint0(8)];
1720                         }
1721                 }
1722                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1723                 {
1724                         /* Random direction */
1725                         dir = ddd[randint0(8)];
1726                 }
1727                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1728                 {
1729                         /* Random direction */
1730                         dir = ddd[randint0(8)];
1731                 }
1732         }
1733
1734         /* Notice confusion */
1735         if (command_dir != dir)
1736         {
1737                 if (creature_ptr->confused)
1738                 {
1739                         /* Warn the user */
1740                         msg_print(_("あなたは混乱している。", "You are confused."));
1741                 }
1742                 else
1743                 {
1744                         GAME_TEXT m_name[MAX_NLEN];
1745                         monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1746
1747                         monster_desc(creature_ptr, m_name, m_ptr, 0);
1748                         if (monster_confused_remaining(m_ptr))
1749                         {
1750                                 msg_format(_("%sは混乱している。", "%^s is confused."), m_name);
1751                         }
1752                         else
1753                         {
1754                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1755                         }
1756                 }
1757         }
1758
1759         *dp = dir;
1760         repeat_push((COMMAND_CODE)command_dir);
1761         return TRUE;
1762 }
1763
1764
1765 /*
1766  * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
1767  * and place it into "command_dir", unless we already have one.
1768  *
1769  * This function should be used for all "repeatable" commands, such as
1770  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
1771  * as all commands which must reference a grid adjacent to the player,
1772  * and which may not reference the grid under the player.  Note that,
1773  * for example, it is no longer possible to "disarm" or "open" chests
1774  * in the same grid as the player.
1775  *
1776  * Direction "5" is illegal and will (cleanly) abort the command.
1777  *
1778  * This function tracks and uses the "global direction", and uses
1779  * that as the "desired direction", to which "confusion" is applied.
1780  */
1781 bool get_rep_dir(player_type *creature_ptr, DIRECTION *dp, bool under)
1782 {
1783         /* Global direction */
1784         DIRECTION dir = command_dir;
1785
1786         COMMAND_CODE code;
1787         if (repeat_pull(&code))
1788         {
1789                 dir = (DIRECTION)code;
1790                 /*              return TRUE; */
1791         }
1792
1793         *dp = (DIRECTION)code;
1794
1795         concptr prompt;
1796         if (under)
1797         {
1798                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
1799         }
1800         else
1801         {
1802                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
1803         }
1804
1805         /* Get a direction */
1806         while (!dir)
1807         {
1808                 char ch;
1809
1810                 /* Get a command (or Cancel) */
1811                 if (!get_com(prompt, &ch, TRUE)) break;
1812
1813                 /* Look down */
1814                 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
1815                 {
1816                         dir = 5;
1817                 }
1818                 else
1819                 {
1820                         /* Look up the direction */
1821                         dir = get_keymap_dir(ch);
1822
1823                         if (!dir) bell();
1824                 }
1825         }
1826
1827         /* Prevent weirdness */
1828         if ((dir == 5) && (!under)) dir = 0;
1829
1830         /* Aborted */
1831         if (!dir) return FALSE;
1832
1833         /* Save desired direction */
1834         command_dir = dir;
1835
1836         /* Apply "confusion" */
1837         if (creature_ptr->confused)
1838         {
1839                 /* Standard confusion */
1840                 if (randint0(100) < 75)
1841                 {
1842                         /* Random direction */
1843                         dir = ddd[randint0(8)];
1844                 }
1845         }
1846         else if (creature_ptr->riding)
1847         {
1848                 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1849                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1850
1851                 if (monster_confused_remaining(m_ptr))
1852                 {
1853                         /* Standard confusion */
1854                         if (randint0(100) < 75)
1855                         {
1856                                 /* Random direction */
1857                                 dir = ddd[randint0(8)];
1858                         }
1859                 }
1860                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
1861                 {
1862                         /* Random direction */
1863                         dir = ddd[randint0(8)];
1864                 }
1865                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
1866                 {
1867                         /* Random direction */
1868                         dir = ddd[randint0(8)];
1869                 }
1870         }
1871
1872         /* Notice confusion */
1873         if (command_dir != dir)
1874         {
1875                 if (creature_ptr->confused)
1876                 {
1877                         /* Warn the user */
1878                         msg_print(_("あなたは混乱している。", "You are confused."));
1879                 }
1880                 else
1881                 {
1882                         GAME_TEXT m_name[MAX_NLEN];
1883                         monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1884
1885                         monster_desc(creature_ptr, m_name, m_ptr, 0);
1886                         if (monster_confused_remaining(m_ptr))
1887                         {
1888                                 msg_format(_("%sは混乱している。", "%^s is confused."), m_name);
1889                         }
1890                         else
1891                         {
1892                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
1893                         }
1894                 }
1895         }
1896
1897         *dp = dir;
1898         repeat_push((COMMAND_CODE)command_dir);
1899         return TRUE;
1900 }
1901
1902
1903 /*
1904  * XAngband: determine if a given location is "interesting"
1905  * based on target_set_accept function.
1906  */
1907 static bool tgt_pt_accept(player_type *creature_ptr, POSITION y, POSITION x)
1908 {
1909         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1910         if (!(in_bounds(floor_ptr, y, x))) return FALSE;
1911
1912         /* Player grid is always interesting */
1913         if ((y == creature_ptr->y) && (x == creature_ptr->x)) return TRUE;
1914
1915         if (creature_ptr->image) return FALSE;
1916
1917         grid_type *g_ptr;
1918         g_ptr = &floor_ptr->grid_array[y][x];
1919
1920         /* Interesting memorized features */
1921         if (!(g_ptr->info & (CAVE_MARK))) return FALSE;
1922
1923         /* Notice stairs */
1924         if (cave_have_flag_grid(g_ptr, FF_LESS)) return TRUE;
1925         if (cave_have_flag_grid(g_ptr, FF_MORE)) return TRUE;
1926
1927         /* Notice quest features */
1928         if (cave_have_flag_grid(g_ptr, FF_QUEST_ENTER)) return TRUE;
1929         if (cave_have_flag_grid(g_ptr, FF_QUEST_EXIT)) return TRUE;
1930
1931         return FALSE;
1932 }
1933
1934
1935 /*
1936  * XAngband: Prepare the "temp" array for "tget_pt"
1937  * based on target_set_prepare funciton.
1938  */
1939 static void tgt_pt_prepare(player_type *creature_ptr)
1940 {
1941         tmp_pos.n = 0;
1942
1943         if (!expand_list) return;
1944
1945         /* Scan the current panel */
1946         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1947         for (POSITION y = 1; y < floor_ptr->height; y++)
1948         {
1949                 for (POSITION x = 1; x < floor_ptr->width; x++)
1950                 {
1951                         /* Require "interesting" contents */
1952                         if (!tgt_pt_accept(creature_ptr, y, x)) continue;
1953
1954                         /* Save the location */
1955                         tmp_pos.x[tmp_pos.n] = x;
1956                         tmp_pos.y[tmp_pos.n] = y;
1957                         tmp_pos.n++;
1958                 }
1959         }
1960
1961         ang_sort(tmp_pos.x, tmp_pos.y, tmp_pos.n, ang_sort_comp_distance, ang_sort_swap_distance);
1962 }
1963
1964
1965 /*
1966  * old -- from PsiAngband.
1967  */
1968 bool tgt_pt(player_type *creature_ptr, POSITION *x_ptr, POSITION *y_ptr)
1969 {
1970         TERM_LEN wid, hgt;
1971         get_screen_size(&wid, &hgt);
1972
1973         POSITION x = creature_ptr->x;
1974         POSITION y = creature_ptr->y;
1975
1976         if (expand_list) tgt_pt_prepare(creature_ptr);
1977
1978         msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
1979         msg_flag = FALSE; /* prevents "-more-" message. */
1980
1981         char ch = 0;
1982         int n = 0;
1983         bool success = FALSE;
1984         while ((ch != ESCAPE) && !success)
1985         {
1986                 bool move_fast = FALSE;
1987
1988                 move_cursor_relative(y, x);
1989                 ch = inkey();
1990                 switch (ch)
1991                 {
1992                 case ESCAPE:
1993                         break;
1994                 case ' ':
1995                 case 't':
1996                 case '.':
1997                 case '5':
1998                 case '0':
1999                         /* illegal place */
2000                         if (player_bold(creature_ptr, y, x)) ch = 0;
2001
2002                         /* okay place */
2003                         else success = TRUE;
2004
2005                         break;
2006
2007                         /* XAngband: Move cursor to stairs */
2008                 case '>':
2009                 case '<':
2010                 {
2011                         if (!expand_list || !tmp_pos.n) break;
2012
2013                         int dx, dy;
2014                         int cx = (panel_col_min + panel_col_max) / 2;
2015                         int cy = (panel_row_min + panel_row_max) / 2;
2016
2017                         n++;
2018
2019                         /* Skip stairs which have defferent distance */
2020                         for (; n < tmp_pos.n; ++n)
2021                         {
2022                                 grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[tmp_pos.y[n]][tmp_pos.x[n]];
2023
2024                                 if (cave_have_flag_grid(g_ptr, FF_STAIRS) &&
2025                                         cave_have_flag_grid(g_ptr, ch == '>' ? FF_MORE : FF_LESS))
2026                                 {
2027                                         /* Found */
2028                                         break;
2029                                 }
2030                         }
2031
2032                         if (n == tmp_pos.n)     /* Loop out taget list */
2033                         {
2034                                 n = 0;
2035                                 y = creature_ptr->y;
2036                                 x = creature_ptr->x;
2037                                 verify_panel(creature_ptr);     /* Move cursor to player */
2038
2039                                 creature_ptr->update |= (PU_MONSTERS);
2040
2041                                 creature_ptr->redraw |= (PR_MAP);
2042
2043                                 creature_ptr->window |= (PW_OVERHEAD);
2044                                 handle_stuff(creature_ptr);
2045                         }
2046                         else    /* move cursor to next stair and change panel */
2047                         {
2048                                 y = tmp_pos.y[n];
2049                                 x = tmp_pos.x[n];
2050
2051                                 dy = 2 * (y - cy) / hgt;
2052                                 dx = 2 * (x - cx) / wid;
2053                                 if (dy || dx) change_panel(creature_ptr, dy, dx);
2054                         }
2055
2056                         break;
2057                 }
2058
2059                 default:
2060                 {
2061                         /* Look up the direction */
2062                         int d = get_keymap_dir(ch);
2063
2064                         /* XTRA HACK MOVEFAST */
2065                         if (isupper(ch)) move_fast = TRUE;
2066
2067                         /* Handle "direction" */
2068                         if (d == 0) break;
2069
2070                         int dx = ddx[d];
2071                         int dy = ddy[d];
2072
2073                         /* XTRA HACK MOVEFAST */
2074                         if (move_fast)
2075                         {
2076                                 int mag = MIN(wid / 2, hgt / 2);
2077                                 x += dx * mag;
2078                                 y += dy * mag;
2079                         }
2080                         else
2081                         {
2082                                 x += dx;
2083                                 y += dy;
2084                         }
2085
2086                         /* Do not move horizontally if unnecessary */
2087                         if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2088                                 ((x > panel_col_min + wid / 2) && (dx < 0)))
2089                         {
2090                                 dx = 0;
2091                         }
2092
2093                         /* Do not move vertically if unnecessary */
2094                         if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2095                                 ((y > panel_row_min + hgt / 2) && (dy < 0)))
2096                         {
2097                                 dy = 0;
2098                         }
2099
2100                         /* Apply the motion */
2101                         if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2102                                 (x >= panel_col_min + wid) || (x < panel_col_min))
2103                         {
2104                                 change_panel(creature_ptr, dy, dx);
2105                         }
2106
2107                         /* Slide into legality */
2108                         if (x >= creature_ptr->current_floor_ptr->width - 1) x = creature_ptr->current_floor_ptr->width - 2;
2109                         else if (x <= 0) x = 1;
2110
2111                         /* Slide into legality */
2112                         if (y >= creature_ptr->current_floor_ptr->height - 1) y = creature_ptr->current_floor_ptr->height - 2;
2113                         else if (y <= 0) y = 1;
2114
2115                         break;
2116                 }
2117                 }
2118         }
2119
2120         prt("", 0, 0);
2121         verify_panel(creature_ptr);
2122         creature_ptr->update |= (PU_MONSTERS);
2123         creature_ptr->redraw |= (PR_MAP);
2124         creature_ptr->window |= (PW_OVERHEAD);
2125         handle_stuff(creature_ptr);
2126
2127         *x_ptr = x;
2128         *y_ptr = y;
2129         return success;
2130 }
2131
2132
2133 bool get_hack_dir(player_type *creature_ptr, DIRECTION *dp)
2134 {
2135         *dp = 0;
2136
2137         /* Ask until satisfied */
2138         char command;
2139         DIRECTION dir = 0;
2140         while (!dir)
2141         {
2142                 /* Choose a prompt */
2143                 concptr p;
2144                 if (!target_okay(creature_ptr))
2145                 {
2146                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2147                 }
2148                 else
2149                 {
2150                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2151                 }
2152
2153                 /* Get a command (or Cancel) */
2154                 if (!get_com(p, &command, TRUE)) break;
2155
2156                 if (use_menu)
2157                 {
2158                         if (command == '\r') command = 't';
2159                 }
2160
2161                 /* Convert various keys to "standard" keys */
2162                 switch (command)
2163                 {
2164                         /* Use current target */
2165                 case 'T':
2166                 case 't':
2167                 case '.':
2168                 case '5':
2169                 case '0':
2170                 {
2171                         dir = 5;
2172                         break;
2173                 }
2174
2175                 /* Set new target */
2176                 case '*':
2177                 case ' ':
2178                 case '\r':
2179                 {
2180                         if (target_set(creature_ptr, TARGET_KILL)) dir = 5;
2181                         break;
2182                 }
2183
2184                 default:
2185                 {
2186                         /* Look up the direction */
2187                         dir = get_keymap_dir(command);
2188
2189                         break;
2190                 }
2191                 }
2192
2193                 /* Verify requested targets */
2194                 if ((dir == 5) && !target_okay(creature_ptr)) dir = 0;
2195
2196                 /* Error */
2197                 if (!dir) bell();
2198         }
2199
2200         if (!dir) return FALSE;
2201
2202         /* Save the direction */
2203         command_dir = dir;
2204
2205         /* Check for confusion */
2206         if (creature_ptr->confused)
2207         {
2208                 /* Random direction */
2209                 dir = ddd[randint0(8)];
2210         }
2211
2212         /* Notice confusion */
2213         if (command_dir != dir)
2214         {
2215                 /* Warn the user */
2216                 msg_print(_("あなたは混乱している。", "You are confused."));
2217         }
2218
2219         *dp = dir;
2220         return TRUE;
2221 }