OSDN Git Service

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