OSDN Git Service

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