OSDN Git Service

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