OSDN Git Service

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