OSDN Git Service

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