OSDN Git Service

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