OSDN Git Service

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