OSDN Git Service

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