OSDN Git Service

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