OSDN Git Service

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