OSDN Git Service

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