OSDN Git Service

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