OSDN Git Service

[Refactor] #37353 突然変異処理の宣言のいくつかを新規 mutation.h へ移動。 / Move declaration for mutation...
[hengbandforosx/hengbandosx.git] / src / xtra2.c
1 /*!
2  * @file xtra2.c
3  * @brief 雑多なその他の処理2 / effects of various "objects"
4  * @date 2014/02/06
5  * @author
6  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
7  * This software may be copied and distributed for educational, research, and\n
8  * not for profit purposes provided that this copyright and statement are\n
9  * included in all such copies.\n
10  * 2014 Deskull rearranged comment for Doxygen.
11  */
12
13
14 #include "angband.h"
15 #include "cmd-pet.h"
16 #include "object-curse.h"
17 #include "monster.h"
18 #include "monsterrace-hook.h"
19 #include "objectkind-hook.h"
20 #include "sort.h"
21 #include "projection.h"
22 #include "spells-summon.h"
23 #include "patron.h"
24 #include "mutation.h"
25
26 #define REWARD_CHANCE 10
27
28
29 /*!
30  * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
31  * Advance experience levels and print experience
32  * @return なし
33  */
34 void check_experience(void)
35 {
36         bool level_reward = FALSE;
37         bool level_mutation = FALSE;
38         bool level_inc_stat = FALSE;
39         bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
40         PLAYER_LEVEL old_lev = p_ptr->lev;
41
42         /* Hack -- lower limit */
43         if (p_ptr->exp < 0) p_ptr->exp = 0;
44         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
45         if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
46
47         /* Hack -- upper limit */
48         if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
49         if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
50         if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
51
52         /* Hack -- maintain "max" experience */
53         if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
54
55         /* Hack -- maintain "max max" experience */
56         if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
57
58         /* Redraw experience */
59         p_ptr->redraw |= (PR_EXP);
60         handle_stuff();
61
62
63         /* Lose levels while possible */
64         while ((p_ptr->lev > 1) &&
65                (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
66         {
67                 /* Lose a level */
68                 p_ptr->lev--;
69                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
70                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
71                 p_ptr->window |= (PW_PLAYER);
72                 handle_stuff();
73         }
74
75
76         /* Gain levels while possible */
77         while ((p_ptr->lev < PY_MAX_LEVEL) &&
78                (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
79         {
80                 /* Gain a level */
81                 p_ptr->lev++;
82
83                 /* Save the highest level */
84                 if (p_ptr->lev > p_ptr->max_plv)
85                 {
86                         p_ptr->max_plv = p_ptr->lev;
87
88                         if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
89                             (p_ptr->muta2 & MUT2_CHAOS_GIFT))
90                         {
91                                 level_reward = TRUE;
92                         }
93                         if (p_ptr->prace == RACE_BEASTMAN)
94                         {
95                                 if (one_in_(5)) level_mutation = TRUE;
96                         }
97                         level_inc_stat = TRUE;
98
99                         do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
100                 }
101
102                 sound(SOUND_LEVEL);
103
104                 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
105
106                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
107                 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
108                 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
109
110                 /* HPとMPの上昇量を表示 */
111                 level_up = 1;
112                 handle_stuff();
113
114                 level_up = 0;
115
116                 if (level_inc_stat)
117                 {
118                         if(!(p_ptr->max_plv % 10))
119                         {
120                                 int choice;
121                                 screen_save();
122                                 while(1)
123                                 {
124                                         int n;
125                                         char tmp[32];
126
127                                         cnv_stat(p_ptr->stat_max[0], tmp);
128                                         prt(format(_("        a) 腕力 (現在値 %s)", "        a) Str (cur %s)"), tmp), 2, 14);
129                                         cnv_stat(p_ptr->stat_max[1], tmp);
130                                         prt(format(_("        b) 知能 (現在値 %s)", "        a) Int (cur %s)"), tmp), 3, 14);
131                                         cnv_stat(p_ptr->stat_max[2], tmp);
132                                         prt(format(_("        c) 賢さ (現在値 %s)", "        a) Wis (cur %s)"), tmp), 4, 14);
133                                         cnv_stat(p_ptr->stat_max[3], tmp);
134                                         prt(format(_("        d) 器用 (現在値 %s)", "        a) Dex (cur %s)"), tmp), 5, 14);
135                                         cnv_stat(p_ptr->stat_max[4], tmp);
136                                         prt(format(_("        e) 耐久 (現在値 %s)", "        a) Con (cur %s)"), tmp), 6, 14);
137                                         cnv_stat(p_ptr->stat_max[5], tmp);
138                                         prt(format(_("        f) 魅力 (現在値 %s)", "        a) Chr (cur %s)"), tmp), 7, 14);
139
140                                         prt("", 8, 14);
141                                         prt(_("        どの能力値を上げますか?", "        Which stat do you want to raise?"), 1, 14);
142
143                                         while(1)
144                                         {
145                                                 choice = inkey();
146                                                 if ((choice >= 'a') && (choice <= 'f')) break;
147                                         }
148                                         for(n = 0; n < A_MAX; n++)
149                                                 if (n != choice - 'a')
150                                                         prt("",n+2,14);
151                                         if (get_check(_("よろしいですか?", "Are you sure? "))) break;
152                                 }
153                                 do_inc_stat(choice - 'a');
154                                 screen_load();
155                         }
156                         else if(!(p_ptr->max_plv % 2))
157                                 do_inc_stat(randint0(6));
158                 }
159
160                 if (level_mutation)
161                 {
162                         msg_print(_("あなたは変わった気がする...", "You feel different..."));
163                         (void)gain_random_mutation(0);
164                         level_mutation = FALSE;
165                 }
166
167                 /*
168                  * 報酬でレベルが上ると再帰的に check_experience() が
169                  * 呼ばれるので順番を最後にする。
170                  */
171                 if (level_reward)
172                 {
173                         gain_level_reward(0);
174                         level_reward = FALSE;
175                 }
176
177                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
178                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
179                 p_ptr->window |= (PW_PLAYER | PW_SPELL);
180                 handle_stuff();
181         }
182
183         /* Load an autopick preference file */
184         if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
185 }
186
187
188
189 /*!
190  * @brief クエストを達成状態にする /
191  * @param quest_num 達成状態にしたいクエストのID
192  * @return なし
193  */
194 void complete_quest(QUEST_IDX quest_num)
195 {
196         quest_type* const q_ptr = &quest[quest_num];
197
198         switch (q_ptr->type)
199         {
200         case QUEST_TYPE_RANDOM:
201                 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
202                 break;
203         default:
204                 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
205                 break;
206         }
207
208         q_ptr->status = QUEST_STATUS_COMPLETED;
209         q_ptr->complev = p_ptr->lev;
210         update_playtime();
211         q_ptr->comptime = playtime;
212
213         if (!(q_ptr->flags & QUEST_FLAG_SILENT))
214         {
215                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
216                 msg_print(_("クエストを達成した!", "You just completed your quest!"));
217                 msg_print(NULL);
218         }
219 }
220
221 /*!
222  * @brief 現在フロアに残っている敵モンスターの数を返す /
223  * @return 現在の敵モンスターの数
224  */
225 static MONSTER_NUMBER count_all_hostile_monsters(void)
226 {
227         POSITION x, y;
228         MONSTER_NUMBER number_mon = 0;
229
230         for (x = 0; x < cur_wid; ++ x)
231         {
232                 for (y = 0; y < cur_hgt; ++ y)
233                 {
234                         MONSTER_IDX m_idx = cave[y][x].m_idx;
235
236                         if (m_idx > 0 && is_hostile(&m_list[m_idx]))
237                         {
238                                 ++number_mon;
239                         }
240                 }
241         }
242
243         return number_mon;
244 }
245
246 /*!
247  * @brief 特定の敵を倒した際にクエスト達成処理 /
248  * Check for "Quest" completion when a quest monster is killed or charmed.
249  * @param m_ptr 撃破したモンスターの構造体参照ポインタ
250  * @return なし
251  */
252 void check_quest_completion(monster_type *m_ptr)
253 {
254         POSITION y, x;
255         QUEST_IDX quest_num;
256
257         bool create_stairs = FALSE;
258         bool reward = FALSE;
259
260         object_type forge;
261         object_type *o_ptr;
262
263         y = m_ptr->fy;
264         x = m_ptr->fx;
265
266         /* Inside a quest */
267         quest_num = p_ptr->inside_quest;
268
269         /* Search for an active quest on this dungeon level */
270         if (!quest_num)
271         {
272                 QUEST_IDX i;
273
274                 for (i = max_q_idx - 1; i > 0; i--)
275                 {
276                         quest_type* const q_ptr = &quest[i];
277                         
278                         /* Quest is not active */
279                         if (q_ptr->status != QUEST_STATUS_TAKEN)
280                                 continue;
281
282                         /* Quest is not a dungeon quest */
283                         if (q_ptr->flags & QUEST_FLAG_PRESET)
284                                 continue;
285
286                         /* Quest is not on this level */
287                         if ((q_ptr->level != dun_level) &&
288                             (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
289                                 continue;
290
291                         /* Not a "kill monster" quest */
292                         if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
293                             (q_ptr->type == QUEST_TYPE_FIND_EXIT))
294                                 continue;
295
296                         /* Interesting quest */
297                         if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
298                             (q_ptr->type == QUEST_TYPE_TOWER) ||
299                             (q_ptr->type == QUEST_TYPE_KILL_ALL))
300                                 break;
301
302                         /* Interesting quest */
303                         if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
304                              (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
305                              (q_ptr->type == QUEST_TYPE_RANDOM)) &&
306                              (q_ptr->r_idx == m_ptr->r_idx))
307                                 break;
308                 }
309
310                 quest_num = i;
311         }
312
313         /* Handle the current quest */
314         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
315         {
316                 /* Current quest */
317                 quest_type* const q_ptr = &quest[quest_num];
318
319                 switch (q_ptr->type)
320                 {
321                         case QUEST_TYPE_KILL_NUMBER:
322                         {
323                                 q_ptr->cur_num++;
324
325                                 if (q_ptr->cur_num >= q_ptr->num_mon)
326                                 {
327                                         complete_quest(quest_num);
328
329                                         q_ptr->cur_num = 0;
330                                 }
331                                 break;
332                         }
333                         case QUEST_TYPE_KILL_ALL:
334                         {
335                                 if (!is_hostile(m_ptr)) break;
336
337                                 if (count_all_hostile_monsters() == 1)
338                                 {
339                                         if (q_ptr->flags & QUEST_FLAG_SILENT)
340                                         {
341                                                 q_ptr->status = QUEST_STATUS_FINISHED;
342                                         }
343                                         else
344                                         {
345                                                 complete_quest(quest_num);
346                                         }
347                                 }
348                                 break;
349                         }
350                         case QUEST_TYPE_KILL_LEVEL:
351                         case QUEST_TYPE_RANDOM:
352                         {
353                                 /* Only count valid monsters */
354                                 if (q_ptr->r_idx != m_ptr->r_idx)
355                                         break;
356
357                                 q_ptr->cur_num++;
358
359                                 if (q_ptr->cur_num >= q_ptr->max_num)
360                                 {
361                                         complete_quest(quest_num);
362
363                                         if (!(q_ptr->flags & QUEST_FLAG_PRESET))
364                                         {
365                                                 create_stairs = TRUE;
366                                                 p_ptr->inside_quest = 0;
367                                         }
368
369                                         /* Finish the two main quests without rewarding */
370                                         if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
371                                         {
372                                                 q_ptr->status = QUEST_STATUS_FINISHED;
373                                         }
374
375                                         if (q_ptr->type == QUEST_TYPE_RANDOM)
376                                         {
377                                                 reward = TRUE;
378                                                 q_ptr->status = QUEST_STATUS_FINISHED;
379                                         }
380                                 }
381                                 break;
382                         }
383                         case QUEST_TYPE_KILL_ANY_LEVEL:
384                         {
385                                 q_ptr->cur_num++;
386                                 if (q_ptr->cur_num >= q_ptr->max_num)
387                                 {
388                                         complete_quest(quest_num);
389                                         q_ptr->cur_num = 0;
390                                 }
391                                 break;
392                         }
393                         case QUEST_TYPE_TOWER:
394                         {
395                                 if (!is_hostile(m_ptr)) break;
396
397                                 if (count_all_hostile_monsters() == 1)
398                                 {
399                                         q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
400
401                                         if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
402                                            (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
403                                            (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
404                                         {
405
406                                                 complete_quest(QUEST_TOWER1);
407                                         }
408                                 }
409                                 break;
410                         }
411                 }
412         }
413
414         /* Create a magical staircase */
415         if (create_stairs)
416         {
417                 POSITION ny, nx;
418
419                 /* Stagger around */
420                 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT) )
421                 {
422                         /* Pick a location */
423                         scatter(&ny, &nx, y, x, 1, 0);
424
425                         /* Stagger */
426                         y = ny; x = nx;
427                 }
428
429                 /* Explain the staircase */
430                 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
431
432                 /* Create stairs down */
433                 cave_set_feat(y, x, feat_down_stair);
434
435                 /* Remember to update everything */
436                 p_ptr->update |= (PU_FLOW);
437         }
438
439         /*
440          * Drop quest reward
441          */
442         if (reward)
443         {
444                 int i;
445
446                 for (i = 0; i < (dun_level / 15)+1; i++)
447                 {
448                         o_ptr = &forge;
449                         object_wipe(o_ptr);
450
451                         /* Make a great object */
452                         make_object(o_ptr, AM_GOOD | AM_GREAT);
453                         (void)drop_near(o_ptr, -1, y, x);
454                 }
455         }
456 }
457
458 /*!
459  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
460  * Check for "Quest" completion when a quest monster is killed or charmed.
461  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
462  * @return なし
463  */
464 void check_find_art_quest_completion(object_type *o_ptr)
465 {
466         QUEST_IDX i;
467         /* Check if completed a quest */
468         for (i = 0; i < max_q_idx; i++)
469         {
470                 if((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
471                         (quest[i].status == QUEST_STATUS_TAKEN) &&
472                         (quest[i].k_idx == o_ptr->name1))
473                 {
474                         complete_quest(i);
475                 }
476         }
477 }
478
479
480 /*!
481  * @brief モンスターを撃破した際の述語メッセージを返す /
482  * Return monster death string
483  * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
484  * @return 撃破されたモンスターの述語
485  */
486 concptr extract_note_dies(MONRACE_IDX r_idx)
487 {
488         monster_race *r_ptr = &r_info[r_idx];
489         /* Some monsters get "destroyed" */
490         if (!monster_living(r_idx))
491         {
492                 int i;
493
494                 for (i = 0; i < 4; i++)
495                 {
496                         if (r_ptr->blow[i].method == RBM_EXPLODE)
497                         {
498                                 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
499                         }
500                 }
501                 return _("を倒した。", " is destroyed.");
502         }
503
504         /* Assume a default death */
505         return _("は死んだ。", " dies.");
506 }
507
508
509 /*!
510  * @brief モンスターに与えたダメージの修正処理 /
511  * Modify the physical damage done to the monster.
512  * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
513  * @param dam ダメージ基本値
514  * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
515  * @return 修正を行った結果のダメージ量
516  * @details
517  * <pre>
518  * (for example when it's invulnerable or shielded)
519  * ToDo: Accept a damage-type to calculate the modified damage from
520  * things like fire, frost, lightning, poison, ... attacks.
521  * "type" is not yet used and should be 0.
522  * </pre>
523  */
524 HIT_POINT mon_damage_mod(monster_type *m_ptr, HIT_POINT dam, bool is_psy_spear)
525 {
526         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
527
528         if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
529         {
530                 dam /= 100;
531                 if ((dam == 0) && one_in_(3)) dam = 1;
532         }
533
534         if (MON_INVULNER(m_ptr))
535         {
536                 if (is_psy_spear)
537                 {
538                         if (!p_ptr->blind && is_seen(m_ptr))
539                         {
540                                 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
541                         }
542                 }
543                 else if (!one_in_(PENETRATE_INVULNERABILITY))
544                 {
545                         return (0);
546                 }
547         }
548         return (dam);
549 }
550
551
552 /*!
553  * @brief モンスターに与えたダメージを元に経験値を加算する /
554  * Calculate experience point to be get
555  * @param dam 与えたダメージ量
556  * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
557  * @return なし
558  * @details
559  * <pre>
560  * Even the 64 bit operation is not big enough to avoid overflaw
561  * unless we carefully choose orders of multiplication and division.
562  * Get the coefficient first, and multiply (potentially huge) base
563  * experience point of a monster later.
564  * </pre>
565  */
566 static void get_exp_from_mon(HIT_POINT dam, monster_type *m_ptr)
567 {
568         monster_race *r_ptr = &r_info[m_ptr->r_idx];
569
570         s32b new_exp;
571         u32b new_exp_frac;
572         s32b div_h;
573         u32b div_l;
574
575         if (!m_ptr->r_idx) return;
576         if (is_pet(m_ptr) || p_ptr->inside_battle) return;
577
578         /*
579          * - Ratio of monster's level to player's level effects
580          * - Varying speed effects
581          * - Get a fraction in proportion of damage point
582          */
583         new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
584         new_exp_frac = 0;
585         div_h = 0L;
586         div_l = (p_ptr->max_plv+2) * SPEED_TO_ENERGY(r_ptr->speed);
587
588         /* Use (average maxhp * 2) as a denominator */
589         if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
590                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
591         else
592                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
593
594         /* Special penalty in the wilderness */
595         if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
596                 s64b_mul(&div_h, &div_l, 0, 5);
597
598         /* Do division first to prevent overflaw */
599         s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
600
601         /* Special penalty for mutiply-monster */
602         if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
603         {
604                 int monnum_penarty = r_ptr->r_akills / 400;
605                 if (monnum_penarty > 8) monnum_penarty = 8;
606
607                 while (monnum_penarty--)
608                 {
609                         /* Divide by 4 */
610                         s64b_RSHIFT(new_exp, new_exp_frac, 2);
611                 }
612         }
613         
614         /* Special penalty for rest_and_shoot exp scum */
615         if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0))
616         {
617                 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
618                 if (over_damage > 32) over_damage = 32;
619
620                 while (over_damage--)
621                 {
622                         /* 9/10 for once */
623                         s64b_mul(&new_exp, &new_exp_frac, 0, 9);
624                         s64b_div(&new_exp, &new_exp_frac, 0, 10);
625                 }
626         }
627
628         /* Finally multiply base experience point of the monster */
629         s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
630
631         /* Gain experience */
632         gain_exp_64(new_exp, new_exp_frac);
633 }
634
635
636 /*!
637  * @brief モンスターのHPをダメージに応じて減算する /
638  * Decreases monsters hit points, handling monster death.
639  * @param dam 与えたダメージ量
640  * @param m_idx ダメージを与えたモンスターのID
641  * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
642  * @param note モンスターが倒された際の特別なメッセージ述語
643  * @return なし
644  * @details
645  * <pre>
646  * We return TRUE if the monster has been killed (and deleted).
647  * We announce monster death (using an optional "death message"
648  * if given, and a otherwise a generic killed/destroyed message).
649  * Only "physical attacks" can induce the "You have slain" message.
650  * Missile and Spell attacks will induce the "dies" message, or
651  * various "specialized" messages.  Note that "You have destroyed"
652  * and "is destroyed" are synonyms for "You have slain" and "dies".
653  * Hack -- unseen monsters yield "You have killed it." message.
654  * Added fear (DGK) and check whether to print fear messages -CWS
655  * Made name, sex, and capitalization generic -BEN-
656  * As always, the "ghost" processing is a total hack.
657  * Hack -- we "delay" fear messages by passing around a "fear" flag.
658  * Consider decreasing monster experience over time, say,
659  * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
660  * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
661  * monster worth more than subsequent monsters.  This would also need
662  * to induce changes in the monster recall code.
663  * </pre>
664  */
665 bool mon_take_hit(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, concptr note)
666 {
667         monster_type *m_ptr = &m_list[m_idx];
668         monster_race *r_ptr = &r_info[m_ptr->r_idx];
669         monster_type exp_mon;
670
671         /* Innocent until proven otherwise */
672         bool innocent = TRUE, thief = FALSE;
673         int i;
674         HIT_POINT expdam;
675
676         (void)COPY(&exp_mon, m_ptr, monster_type);
677         
678         expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
679
680         get_exp_from_mon(expdam, &exp_mon);
681
682         /* Genocided by chaos patron */
683         if (!m_ptr->r_idx) m_idx = 0;
684         
685         /* Redraw (later) if needed */
686         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
687         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
688
689         (void)set_monster_csleep(m_idx, 0);
690
691         /* Hack - Cancel any special player stealth magics. -LM- */
692         if (p_ptr->special_defense & NINJA_S_STEALTH)
693         {
694                 set_superstealth(FALSE);
695         }
696
697         /* Genocided by chaos patron */
698         if (!m_idx) return TRUE;
699         
700         m_ptr->hp -= dam;
701         m_ptr->dealt_damage += dam;
702
703         if(m_ptr->dealt_damage > m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
704
705         if (p_ptr->wizard)
706         {
707                 msg_format( _("合計%d/%dのダメージを与えた。","You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
708         }
709
710         /* It is dead now */
711         if (m_ptr->hp < 0)
712         {
713                 GAME_TEXT m_name[MAX_NLEN];
714
715                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
716                 {
717                         /* You might have unmasked Tanuki first time */
718                         r_ptr = &r_info[m_ptr->r_idx];
719                         m_ptr->ap_r_idx = m_ptr->r_idx;
720                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
721                 }
722
723                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
724                 {
725                         /* You might have unmasked Chameleon first time */
726                         r_ptr = real_r_ptr(m_ptr);
727                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
728                 }
729
730                 if (!(m_ptr->smart & SM_CLONED))
731                 {
732                         /* When the player kills a Unique, it stays dead */
733                         if (r_ptr->flags1 & RF1_UNIQUE)
734                         {
735                                 r_ptr->max_num = 0;
736
737                                 /* Mega-Hack -- Banor & Lupart */
738                                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
739                                 {
740                                         r_info[MON_BANORLUPART].max_num = 0;
741                                         r_info[MON_BANORLUPART].r_pkills++;
742                                         r_info[MON_BANORLUPART].r_akills++;
743                                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
744                                 }
745                                 else if (m_ptr->r_idx == MON_BANORLUPART)
746                                 {
747                                         r_info[MON_BANOR].max_num = 0;
748                                         r_info[MON_BANOR].r_pkills++;
749                                         r_info[MON_BANOR].r_akills++;
750                                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
751                                         r_info[MON_LUPART].max_num = 0;
752                                         r_info[MON_LUPART].r_pkills++;
753                                         r_info[MON_LUPART].r_akills++;
754                                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
755                                 }
756                         }
757
758                         /* When the player kills a Nazgul, it stays dead */
759                         else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
760                 }
761
762                 /* Count all monsters killed */
763                 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
764
765                 /* Recall even invisible uniques or winners */
766                 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
767                 {
768                         /* Count kills this life */
769                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
770                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
771
772                         /* Count kills in all lives */
773                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
774                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
775
776                         /* Hack -- Auto-recall */
777                         monster_race_track(m_ptr->ap_r_idx);
778                 }
779
780                 /* Extract monster name */
781                 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
782
783                 /* Don't kill Amberites */
784                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
785                 {
786                         int curses = 1 + randint1(3);
787                         bool stop_ty = FALSE;
788                         int count = 0;
789
790                         msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
791                         curse_equipment(100, 50);
792
793                         do
794                         {
795                                 stop_ty = activate_ty_curse(stop_ty, &count);
796                         }
797                         while (--curses);
798                 }
799
800                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
801                 {
802                         char line_got[1024];
803                         if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
804                         {
805                                 msg_format("%^s %s", m_name, line_got);
806                         }
807
808 #ifdef WORLD_SCORE
809                         if (m_ptr->r_idx == MON_SERPENT)
810                         {
811                                 screen_dump = make_screen_dump();
812                         }
813 #endif
814                 }
815
816                 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
817                 {
818                         if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
819                         {
820                                 chg_virtue(V_VALOUR, -1);
821                         }
822                         else if (r_ptr->level > dun_level)
823                         {
824                                 if (randint1(10) <= (r_ptr->level - dun_level))
825                                         chg_virtue(V_VALOUR, 1);
826                         }
827                         if (r_ptr->level > 60)
828                         {
829                                 chg_virtue(V_VALOUR, 1);
830                         }
831                         if (r_ptr->level >= 2 * (p_ptr->lev+1))
832                                 chg_virtue(V_VALOUR, 2);
833                 }
834
835                 if (r_ptr->flags1 & RF1_UNIQUE)
836                 {
837                         if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
838
839                         if (r_ptr->flags3 & RF3_GOOD)
840                         {
841                                 chg_virtue(V_UNLIFE, 2);
842                                 chg_virtue(V_VITALITY, -2);
843                         }
844
845                         if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
846                 }
847
848                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
849                 {
850                         chg_virtue(V_COMPASSION, -1);
851                 }
852
853                 if ((r_ptr->flags3 & RF3_GOOD) && ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
854                         chg_virtue(V_UNLIFE, 1);
855
856                 if (r_ptr->d_char == 'A')
857                 {
858                         if (r_ptr->flags1 & RF1_UNIQUE)
859                                 chg_virtue(V_FAITH, -2);
860                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
861                         {
862                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
863                                 else chg_virtue(V_FAITH, 1);
864                         }
865                 }
866                 else if (r_ptr->flags3 & RF3_DEMON)
867                 {
868                         if (r_ptr->flags1 & RF1_UNIQUE)
869                                 chg_virtue(V_FAITH, 2);
870                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
871                                 chg_virtue(V_FAITH, 1);
872                 }
873
874                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
875                         chg_virtue(V_VITALITY, 2);
876
877                 if (r_ptr->r_deaths)
878                 {
879                         if (r_ptr->flags1 & RF1_UNIQUE)
880                         {
881                                 chg_virtue(V_HONOUR, 10);
882                         }
883                         else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
884                         {
885                                 chg_virtue(V_HONOUR, 1);
886                         }
887                 }
888                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
889                 {
890                         chg_virtue(V_VALOUR, -1);
891                 }
892
893                 for (i = 0; i < 4; i++)
894                 {
895                         if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
896
897                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
898                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
899
900                                 thief = TRUE; /* Thief! */
901                 }
902
903                 /* The new law says it is illegal to live in the dungeon */
904                 if (r_ptr->level != 0) innocent = FALSE;
905
906                 if (thief)
907                 {
908                         if (r_ptr->flags1 & RF1_UNIQUE)
909                                 chg_virtue(V_JUSTICE, 3);
910                         else if (1+((r_ptr->level) / 10 + (2 * dun_level)) >= randint1(100))
911                                 chg_virtue(V_JUSTICE, 1);
912                 }
913                 else if (innocent)
914                 {
915                         chg_virtue (V_JUSTICE, -1);
916                 }
917
918                 if ((r_ptr->flags3 & RF3_ANIMAL) && !(r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags4 & ~(RF4_NOMAGIC_MASK))  && !(r_ptr->a_ability_flags1 & ~(RF5_NOMAGIC_MASK)) && !(r_ptr->a_ability_flags2 & ~(RF6_NOMAGIC_MASK)))
919                 {
920                         if (one_in_(4)) chg_virtue(V_NATURE, -1);
921                 }
922
923                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
924                 {
925                         char note_buf[160];
926                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? _("(クローン)", "(Clone)") : "");
927                         do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
928                 }
929
930                 /* Make a sound */
931                 sound(SOUND_KILL);
932
933                 /* Death by Missile/Spell attack */
934                 if (note)
935                 {
936                         msg_format("%^s%s", m_name, note);
937                 }
938
939                 /* Death by physical attack -- invisible monster */
940                 else if (!m_ptr->ml)
941                 {
942 #ifdef JP
943                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
944                                 msg_format("せっかくだから%sを殺した。", m_name);
945                         else
946                                 msg_format("%sを殺した。", m_name);
947 #else
948                                 msg_format("You have killed %s.", m_name);
949 #endif
950
951                 }
952
953                 /* Death by Physical attack -- non-living monster */
954                 else if (!monster_living(m_ptr->r_idx))
955                 {
956                         bool explode = FALSE;
957
958                         for (i = 0; i < 4; i++)
959                         {
960                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
961                         }
962
963                         /* Special note at death */
964                         if (explode)
965                                 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
966                         else
967                         {
968 #ifdef JP
969                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
970                                         msg_format("せっかくだから%sを倒した。", m_name);
971                                 else
972                                 msg_format("%sを倒した。", m_name);
973 #else
974                                 msg_format("You have destroyed %s.", m_name);
975 #endif
976                         }
977                 }
978
979                 /* Death by Physical attack -- living monster */
980                 else
981                 {
982 #ifdef JP
983                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
984                                 msg_format("せっかくだから%sを葬り去った。", m_name);
985                         else
986                                 msg_format("%sを葬り去った。", m_name);
987 #else
988                                 msg_format("You have slain %s.", m_name);
989 #endif
990
991                 }
992                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
993                 {
994                         for (i = 0; i < MAX_KUBI; i++)
995                         {
996                                 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
997                                 {
998                                         msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
999                                         break;
1000                                 }
1001                         }
1002                 }
1003
1004                 /* Generate treasure */
1005                 monster_death(m_idx, TRUE);
1006
1007                 /* Mega hack : replace IKETA to BIKETAL */
1008                 if ((m_ptr->r_idx == MON_IKETA) && !(p_ptr->inside_arena || p_ptr->inside_battle))
1009                 {
1010                         POSITION dummy_y = m_ptr->fy;
1011                         POSITION dummy_x = m_ptr->fx;
1012                         BIT_FLAGS mode = 0L;
1013                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1014                         delete_monster_idx(m_idx);
1015                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
1016                         {
1017                                 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha!  *I* am Biketal!"));
1018                         }
1019                 }
1020                 else
1021                 {
1022                         delete_monster_idx(m_idx);
1023                 }
1024
1025                 get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
1026
1027                 /* Not afraid */
1028                 (*fear) = FALSE;
1029
1030                 /* Monster is dead */
1031                 return (TRUE);
1032         }
1033
1034
1035 #ifdef ALLOW_FEAR
1036
1037         /* Mega-Hack -- Pain cancels fear */
1038         if (MON_MONFEAR(m_ptr) && (dam > 0))
1039         {
1040                 /* Cure fear */
1041                 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
1042                 {
1043                         /* No more fear */
1044                         (*fear) = FALSE;
1045                 }
1046         }
1047
1048         /* Sometimes a monster gets scared by damage */
1049         if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
1050         {
1051                 /* Percentage of fully healthy */
1052                 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
1053
1054                 /*
1055                  * Run (sometimes) if at 10% or less of max hit points,
1056                  * or (usually) when hit for half its current hit points
1057                  */
1058                 if ((randint1(10) >= percentage) || ((dam >= m_ptr->hp) && (randint0(100) < 80)))
1059                 {
1060                         /* Hack -- note fear */
1061                         (*fear) = TRUE;
1062
1063                         /* Hack -- Add some timed fear */
1064                         (void)set_monster_monfear(m_idx, (randint1(10) +
1065                                           (((dam >= m_ptr->hp) && (percentage > 7)) ?
1066                                            20 : ((11 - percentage) * 5))));
1067                 }
1068         }
1069
1070 #endif
1071
1072         /* Not dead yet */
1073         return (FALSE);
1074 }
1075
1076
1077 /*!
1078  * @brief 現在のコンソール表示の縦横を返す。 /
1079  * Get term size and calculate screen size
1080  * @param wid_p コンソールの表示幅文字数を返す
1081  * @param hgt_p コンソールの表示行数を返す
1082  * @return なし
1083  */
1084 void get_screen_size(TERM_LEN *wid_p, TERM_LEN *hgt_p)
1085 {
1086         Term_get_size(wid_p, hgt_p);
1087         *hgt_p -= ROW_MAP + 2;
1088         *wid_p -= COL_MAP + 2;
1089         if (use_bigtile) *wid_p /= 2;
1090 }
1091
1092
1093 /*!
1094  * @brief コンソール上におけるマップ表示の左上位置を返す /
1095  * Calculates current boundaries Called below and from "do_cmd_locate()".
1096  * @return なし
1097  */
1098 void panel_bounds_center(void)
1099 {
1100         TERM_LEN wid, hgt;
1101
1102         get_screen_size(&wid, &hgt);
1103
1104         panel_row_max = panel_row_min + hgt - 1;
1105         panel_row_prt = panel_row_min - 1;
1106         panel_col_max = panel_col_min + wid - 1;
1107         panel_col_prt = panel_col_min - 13;
1108 }
1109
1110
1111 /*!
1112  * @brief コンソールのリサイズに合わせてマップを再描画する /
1113  * Map resizing whenever the main term changes size
1114  * @return なし
1115  */
1116 void resize_map(void)
1117 {
1118         /* Only if the dungeon exists */
1119         if (!character_dungeon) return;
1120         
1121         /* Mega-Hack -- no panel yet */
1122         panel_row_max = 0;
1123         panel_col_max = 0;
1124
1125         /* Reset the panels */
1126         panel_row_min = cur_hgt;
1127         panel_col_min = cur_wid;
1128                                 
1129         verify_panel();
1130
1131         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
1132         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1133         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1134         p_ptr->update |= (PU_MONSTERS);
1135         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
1136
1137         handle_stuff();
1138         Term_redraw();
1139
1140         /*
1141          * Waiting command;
1142          * Place the cursor on the player
1143          */
1144         if (can_save) move_cursor_relative(p_ptr->y, p_ptr->x);
1145
1146         Term_fresh();
1147 }
1148
1149 /*!
1150  * @brief コンソールを再描画する /
1151  * Redraw a term when it is resized
1152  * @return なし
1153  */
1154 void redraw_window(void)
1155 {
1156         /* Only if the dungeon exists */
1157         if (!character_dungeon) return;
1158
1159         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1160         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
1161
1162         handle_stuff();
1163         Term_redraw();
1164 }
1165
1166
1167 /*!
1168  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
1169  * @param dy 変更先のフロアY座標
1170  * @param dx 変更先のフロアX座標
1171  * Handle a request to change the current panel
1172  * Return TRUE if the panel was changed.
1173  * Also used in do_cmd_locate
1174  * @return 実際に再描画が必要だった場合TRUEを返す
1175  */
1176 bool change_panel(POSITION dy, POSITION dx)
1177 {
1178         POSITION y, x;
1179         TERM_LEN wid, hgt;
1180
1181         get_screen_size(&wid, &hgt);
1182
1183         /* Apply the motion */
1184         y = panel_row_min + dy * hgt / 2;
1185         x = panel_col_min + dx * wid / 2;
1186
1187         /* Verify the row */
1188         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
1189         if (y < 0) y = 0;
1190
1191         /* Verify the col */
1192         if (x > cur_wid - wid) x = cur_wid - wid;
1193         if (x < 0) x = 0;
1194
1195         /* Handle "changes" */
1196         if ((y != panel_row_min) || (x != panel_col_min))
1197         {
1198                 /* Save the new panel info */
1199                 panel_row_min = y;
1200                 panel_col_min = x;
1201
1202                 /* Recalculate the boundaries */
1203                 panel_bounds_center();
1204
1205                 p_ptr->update |= (PU_MONSTERS);
1206                 p_ptr->redraw |= (PR_MAP);
1207                 handle_stuff();
1208
1209                 /* Success */
1210                 return (TRUE);
1211         }
1212
1213         /* No change */
1214         return (FALSE);
1215 }
1216
1217 /*!
1218  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
1219  * @param y 変更先のフロアY座標
1220  * @param x 変更先のフロアX座標
1221  * @details
1222  * Handle a request to change the current panel
1223  * Return TRUE if the panel was changed.
1224  * Also used in do_cmd_locate
1225  * @return 実際に再描画が必要だった場合TRUEを返す
1226  */
1227 static bool change_panel_xy(POSITION y, POSITION x)
1228 {
1229         POSITION dy = 0, dx = 0;
1230         TERM_LEN wid, hgt;
1231
1232         get_screen_size(&wid, &hgt);
1233
1234         if (y < panel_row_min) dy = -1;
1235         if (y > panel_row_max) dy = 1;
1236         if (x < panel_col_min) dx = -1;
1237         if (x > panel_col_max) dx = 1;
1238
1239         if (!dy && !dx) return (FALSE);
1240
1241         return change_panel(dy, dx);
1242 }
1243
1244
1245 /*!
1246  * @brief マップ描画のフォーカスを当てるべき座標を更新する
1247  * @details
1248  * Given an row (y) and col (x), this routine detects when a move
1249  * off the screen has occurred and figures new borders. -RAK-
1250  * "Update" forces a "full update" to take place.
1251  * The map is reprinted if necessary, and "TRUE" is returned.
1252  * @return 実際に再描画が必要だった場合TRUEを返す
1253  */
1254 void verify_panel(void)
1255 {
1256         POSITION y = p_ptr->y;
1257         POSITION x = p_ptr->x;
1258         TERM_LEN wid, hgt;
1259
1260         int prow_min;
1261         int pcol_min;
1262         int max_prow_min;
1263         int max_pcol_min;
1264
1265         get_screen_size(&wid, &hgt);
1266
1267         max_prow_min = cur_hgt - hgt;
1268         max_pcol_min = cur_wid - wid;
1269
1270         /* Bounds checking */
1271         if (max_prow_min < 0) max_prow_min = 0;
1272         if (max_pcol_min < 0) max_pcol_min = 0;
1273
1274                 /* Center on player */
1275         if (center_player && (center_running || !running))
1276         {
1277                 /* Center vertically */
1278                 prow_min = y - hgt / 2;
1279                 if (prow_min < 0) prow_min = 0;
1280                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
1281
1282                 /* Center horizontally */
1283                 pcol_min = x - wid / 2;
1284                 if (pcol_min < 0) pcol_min = 0;
1285                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1286         }
1287         else
1288         {
1289                 prow_min = panel_row_min;
1290                 pcol_min = panel_col_min;
1291
1292                 /* Scroll screen when 2 grids from top/bottom edge */
1293                 if (y > panel_row_max - 2)
1294                 {
1295                         while (y > prow_min + hgt-1 - 2)
1296                         {
1297                                 prow_min += (hgt / 2);
1298                         }
1299                 }
1300
1301                 if (y < panel_row_min + 2)
1302                 {
1303                         while (y < prow_min + 2)
1304                         {
1305                                 prow_min -= (hgt / 2);
1306                         }
1307                 }
1308
1309                 if (prow_min > max_prow_min) prow_min = max_prow_min;
1310                 if (prow_min < 0) prow_min = 0;
1311
1312                 /* Scroll screen when 4 grids from left/right edge */
1313                 if (x > panel_col_max - 4)
1314                 {
1315                         while (x > pcol_min + wid-1 - 4)
1316                         {
1317                                 pcol_min += (wid / 2);
1318                         }
1319                 }
1320                 
1321                 if (x < panel_col_min + 4)
1322                 {
1323                         while (x < pcol_min + 4)
1324                         {
1325                                 pcol_min -= (wid / 2);
1326                         }
1327                 }
1328
1329                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
1330                 if (pcol_min < 0) pcol_min = 0;
1331         }
1332
1333         /* Check for "no change" */
1334         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
1335
1336         /* Save the new panel info */
1337         panel_row_min = prow_min;
1338         panel_col_min = pcol_min;
1339
1340         /* Hack -- optional disturb on "panel change" */
1341         if (disturb_panel && !center_player) disturb(FALSE, FALSE);
1342
1343         /* Recalculate the boundaries */
1344         panel_bounds_center();
1345
1346         p_ptr->update |= (PU_MONSTERS);
1347         p_ptr->redraw |= (PR_MAP);
1348         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1349 }
1350
1351
1352 /*
1353  * Monster health description
1354  */
1355 concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
1356 {
1357         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1358         bool living;
1359         int perc;
1360         concptr desc;
1361         concptr attitude;
1362         concptr clone;
1363
1364         /* Determine if the monster is "living" */
1365         living = monster_living(m_ptr->ap_r_idx);
1366
1367         /* Calculate a health "percentage" */
1368         perc = m_ptr->maxhp > 0 ? 100L * m_ptr->hp / m_ptr->maxhp : 0;
1369
1370         /* Healthy monsters */
1371         if (m_ptr->hp >= m_ptr->maxhp)
1372         {
1373                 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
1374         }
1375
1376         else if (perc >= 60)
1377         {
1378                 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
1379         }
1380
1381         else if (perc >= 25)
1382         {
1383                 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
1384         }
1385
1386         else if (perc >= 10)
1387         {
1388                 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
1389         }
1390
1391         else 
1392         {
1393                 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
1394         }
1395
1396         /* Need attitude information? */
1397         if (!(mode & 0x01))
1398         {
1399                 /* Full information is not needed */
1400                 attitude = "";
1401         }
1402         else if (is_pet(m_ptr))
1403         {
1404                 attitude = _(", ペット", ", pet");
1405         }
1406         else if (is_friendly(m_ptr))
1407         {
1408                 attitude = _(", 友好的", ", friendly");
1409         }
1410         else
1411         {
1412                 attitude = _("", "");
1413         }
1414
1415         /* Clone monster? */
1416         if (m_ptr->smart & SM_CLONED)
1417         {
1418                 clone = ", clone";
1419         }
1420         else
1421         {
1422                 clone = "";
1423         }
1424
1425         /* Display monster's level --- idea borrowed from ToME */
1426         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
1427         {
1428                 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
1429         }
1430         else 
1431         {
1432                 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
1433         }
1434
1435 }
1436
1437
1438
1439 /*** Targeting Code ***/
1440
1441
1442 /*
1443  * Determine is a monster makes a reasonable target
1444  *
1445  * The concept of "targeting" was stolen from "Morgul" (?)
1446  *
1447  * The player can target any location, or any "target-able" monster.
1448  *
1449  * Currently, a monster is "target_able" if it is visible, and if
1450  * the player can hit it with a projection, and the player is not
1451  * hallucinating.  This allows use of "use closest target" macros.
1452  *
1453  * Future versions may restrict the ability to target "trappers"
1454  * and "mimics", but the semantics is a little bit weird.
1455  */
1456 bool target_able(MONSTER_IDX m_idx)
1457 {
1458         monster_type *m_ptr = &m_list[m_idx];
1459
1460         /* Monster must be alive */
1461         if (!m_ptr->r_idx) return (FALSE);
1462
1463         /* Hack -- no targeting hallucinations */
1464         if (p_ptr->image) return (FALSE);
1465
1466         /* Monster must be visible */
1467         if (!m_ptr->ml) return (FALSE);
1468
1469         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
1470
1471         /* Monster must be projectable */
1472         if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
1473
1474         /* Hack -- Never target trappers */
1475         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
1476
1477         /* Assume okay */
1478         return (TRUE);
1479 }
1480
1481
1482
1483
1484 /*
1485  * Update (if necessary) and verify (if possible) the target.
1486  *
1487  * We return TRUE if the target is "okay" and FALSE otherwise.
1488  */
1489 bool target_okay(void)
1490 {
1491         /* Accept stationary targets */
1492         if (target_who < 0) return (TRUE);
1493
1494         /* Check moving targets */
1495         if (target_who > 0)
1496         {
1497                 /* Accept reasonable targets */
1498                 if (target_able(target_who))
1499                 {
1500                         monster_type *m_ptr = &m_list[target_who];
1501
1502                         /* Acquire monster location */
1503                         target_row = m_ptr->fy;
1504                         target_col = m_ptr->fx;
1505
1506                         /* Good target */
1507                         return (TRUE);
1508                 }
1509         }
1510
1511         /* Assume no target */
1512         return (FALSE);
1513 }
1514
1515
1516 /*
1517  * Sorting hook -- comp function -- by "distance to player"
1518  *
1519  * We use "u" and "v" to point to arrays of "x" and "y" positions,
1520  * and sort the arrays by double-distance to the player.
1521  */
1522 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
1523 {
1524         POSITION *x = (POSITION*)(u);
1525         POSITION *y = (POSITION*)(v);
1526
1527         POSITION da, db, kx, ky;
1528
1529         /* Absolute distance components */
1530         kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
1531         ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
1532
1533         /* Approximate Double Distance to the first point */
1534         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
1535
1536         /* Absolute distance components */
1537         kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
1538         ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
1539
1540         /* Approximate Double Distance to the first point */
1541         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
1542
1543         /* Compare the distances */
1544         return (da <= db);
1545 }
1546
1547
1548 /*
1549  * Sorting hook -- comp function -- by importance level of grids
1550  *
1551  * We use "u" and "v" to point to arrays of "x" and "y" positions,
1552  * and sort the arrays by level of monster
1553  */
1554 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
1555 {
1556         POSITION *x = (POSITION*)(u);
1557         POSITION *y = (POSITION*)(v);
1558         cave_type *ca_ptr = &cave[y[a]][x[a]];
1559         cave_type *cb_ptr = &cave[y[b]][x[b]];
1560         monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
1561         monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
1562         monster_race *ap_ra_ptr, *ap_rb_ptr;
1563
1564         /* The player grid */
1565         if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
1566         if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
1567
1568         /* Extract monster race */
1569         if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
1570         else ap_ra_ptr = NULL;
1571         if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
1572         else ap_rb_ptr = NULL;
1573
1574         if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
1575         if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
1576
1577         /* Compare two monsters */
1578         if (ap_ra_ptr && ap_rb_ptr)
1579         {
1580                 /* Unique monsters first */
1581                 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
1582                 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
1583
1584                 /* Shadowers first (あやしい影) */
1585                 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
1586                 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
1587
1588                 /* Unknown monsters first */
1589                 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
1590                 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
1591
1592                 /* Higher level monsters first (if known) */
1593                 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
1594                 {
1595                         if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
1596                         if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
1597                 }
1598
1599                 /* Sort by index if all conditions are same */
1600                 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
1601                 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
1602         }
1603
1604         /* An object get higher priority */
1605         if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
1606         if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
1607
1608         /* Priority from the terrain */
1609         if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
1610         if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
1611
1612         /* If all conditions are same, compare distance */
1613         return ang_sort_comp_distance(u, v, a, b);
1614 }
1615
1616
1617 /*
1618  * Sorting hook -- swap function -- by "distance to player"
1619  *
1620  * We use "u" and "v" to point to arrays of "x" and "y" positions,
1621  * and sort the arrays by distance to the player.
1622  */
1623 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
1624 {
1625         POSITION *x = (POSITION*)(u);
1626         POSITION *y = (POSITION*)(v);
1627
1628         POSITION temp;
1629
1630         /* Swap "x" */
1631         temp = x[a];
1632         x[a] = x[b];
1633         x[b] = temp;
1634
1635         /* Swap "y" */
1636         temp = y[a];
1637         y[a] = y[b];
1638         y[b] = temp;
1639 }
1640
1641
1642
1643 /*
1644  * Hack -- help "select" a location (see below)
1645  */
1646 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
1647 {
1648         POSITION_IDX i, v;
1649         POSITION x2, y2, x3, y3, x4, y4;
1650         POSITION_IDX b_i = -1, b_v = 9999;
1651
1652
1653         /* Scan the locations */
1654         for (i = 0; i < temp_n; i++)
1655         {
1656                 /* Point 2 */
1657                 x2 = temp_x[i];
1658                 y2 = temp_y[i];
1659
1660                 /* Directed distance */
1661                 x3 = (x2 - x1);
1662                 y3 = (y2 - y1);
1663
1664                 /* Verify quadrant */
1665                 if (dx && (x3 * dx <= 0)) continue;
1666                 if (dy && (y3 * dy <= 0)) continue;
1667
1668                 /* Absolute distance */
1669                 x4 = ABS(x3);
1670                 y4 = ABS(y3);
1671
1672                 /* Verify quadrant */
1673                 if (dy && !dx && (x4 > y4)) continue;
1674                 if (dx && !dy && (y4 > x4)) continue;
1675
1676                 /* Approximate Double Distance */
1677                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
1678
1679                 /* Penalize location */
1680
1681                 /* Track best */
1682                 if ((b_i >= 0) && (v >= b_v)) continue;
1683
1684                 /* Track best */
1685                 b_i = i; b_v = v;
1686         }
1687         return (b_i);
1688 }
1689
1690
1691 /*
1692  * Hack -- determine if a given location is "interesting"
1693  */
1694 static bool target_set_accept(POSITION y, POSITION x)
1695 {
1696         cave_type *c_ptr;
1697         OBJECT_IDX this_o_idx, next_o_idx = 0;
1698
1699         /* Bounds */
1700         if (!(in_bounds(y, x))) return (FALSE);
1701
1702         /* Player grid is always interesting */
1703         if (player_bold(y, x)) return (TRUE);
1704
1705         /* Handle hallucination */
1706         if (p_ptr->image) return (FALSE);
1707
1708         /* Examine the grid */
1709         c_ptr = &cave[y][x];
1710
1711         /* Visible monsters */
1712         if (c_ptr->m_idx)
1713         {
1714                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1715
1716                 /* Visible monsters */
1717                 if (m_ptr->ml) return (TRUE);
1718         }
1719
1720         /* Scan all objects in the grid */
1721         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1722         {
1723                 object_type *o_ptr;
1724                 o_ptr = &o_list[this_o_idx];
1725
1726                 /* Acquire next object */
1727                 next_o_idx = o_ptr->next_o_idx;
1728
1729                 /* Memorized object */
1730                 if (o_ptr->marked & OM_FOUND) return (TRUE);
1731         }
1732
1733         /* Interesting memorized features */
1734         if (c_ptr->info & (CAVE_MARK))
1735         {
1736                 /* Notice object features */
1737                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
1738
1739                 /* Feature code (applying "mimic" field) */
1740                 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
1741         }
1742
1743         return (FALSE);
1744 }
1745
1746
1747 /*
1748  * Prepare the "temp" array for "target_set"
1749  *
1750  * Return the number of target_able monsters in the set.
1751  */
1752 static void target_set_prepare(BIT_FLAGS mode)
1753 {
1754         POSITION y, x;
1755         POSITION min_hgt, max_hgt, min_wid, max_wid;
1756
1757         if (mode & TARGET_KILL)
1758         {
1759                 /* Inner range */
1760                 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
1761                 max_hgt = MIN((p_ptr->y + MAX_RANGE), cur_hgt - 1);
1762                 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
1763                 max_wid = MIN((p_ptr->x + MAX_RANGE), cur_wid - 1);
1764         }
1765         else /* not targetting */
1766         {
1767                 /* Inner panel */
1768                 min_hgt = panel_row_min;
1769                 max_hgt = panel_row_max;
1770                 min_wid = panel_col_min;
1771                 max_wid = panel_col_max;
1772         }
1773
1774         /* Reset "temp" array */
1775         temp_n = 0;
1776
1777         /* Scan the current panel */
1778         for (y = min_hgt; y <= max_hgt; y++)
1779         {
1780                 for (x = min_wid; x <= max_wid; x++)
1781                 {
1782                         cave_type *c_ptr;
1783
1784                         /* Require "interesting" contents */
1785                         if (!target_set_accept(y, x)) continue;
1786
1787                         c_ptr = &cave[y][x];
1788
1789                         /* Require target_able monsters for "TARGET_KILL" */
1790                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
1791
1792                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
1793
1794                         /* Save the location */
1795                         temp_x[temp_n] = x;
1796                         temp_y[temp_n] = y;
1797                         temp_n++;
1798                 }
1799         }
1800
1801         /* Set the sort hooks */
1802         if (mode & (TARGET_KILL))
1803         {
1804                 /* Target the nearest monster for shooting */
1805                 ang_sort_comp = ang_sort_comp_distance;
1806                 ang_sort_swap = ang_sort_swap_distance;
1807         }
1808         else
1809         {
1810                 /* Look important grids first in Look command */
1811                 ang_sort_comp = ang_sort_comp_importance;
1812                 ang_sort_swap = ang_sort_swap_distance;
1813         }
1814
1815         /* Sort the positions */
1816         ang_sort(temp_x, temp_y, temp_n);
1817
1818         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
1819         {
1820                 POSITION tmp;
1821
1822                 tmp = temp_y[0];
1823                 temp_y[0] = temp_y[1];
1824                 temp_y[1] = tmp;
1825                 tmp = temp_x[0];
1826                 temp_x[0] = temp_x[1];
1827                 temp_x[1] = tmp;
1828         }
1829 }
1830
1831 void target_set_prepare_look(void){
1832         target_set_prepare(TARGET_LOOK);
1833 }
1834
1835
1836 /*
1837  * Evaluate number of kill needed to gain level
1838  */
1839 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
1840 {
1841         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1842         u32b num;
1843         s32b exp_mon, exp_adv;
1844         u32b exp_mon_frac, exp_adv_frac;
1845
1846         if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
1847         {
1848                 sprintf(buf,"**");
1849                 return;
1850         }
1851         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
1852         {
1853                 if (!p_ptr->wizard)
1854                 {
1855                         sprintf(buf,"??");
1856                         return;
1857                 }
1858         }
1859
1860
1861         /* The monster's experience point (assuming average monster speed) */
1862         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
1863         exp_mon_frac = 0;
1864         s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
1865
1866
1867         /* Total experience value for next level */
1868         exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
1869         exp_adv_frac = 0;
1870         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
1871
1872         /* Experience value need to get */
1873         s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
1874
1875
1876         /* You need to kill at least one monster to get any experience */
1877         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1878         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
1879
1880         /* Extract number of monsters needed */
1881         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
1882
1883         /* If 999 or more monsters needed, only display "999". */
1884         num = MIN(999, exp_adv_frac);
1885
1886         /* Display the number */
1887         sprintf(buf,"%03ld", (long int)num);
1888 }
1889
1890
1891 bool show_gold_on_floor = FALSE;
1892
1893 /*
1894  * Examine a grid, return a keypress.
1895  *
1896  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
1897  * indicates that the "space" key should scan through the contents
1898  * of the grid, instead of simply returning immediately.  This lets
1899  * the "look" command get complete information, without making the
1900  * "target" command annoying.
1901  *
1902  * The "info" argument contains the "commands" which should be shown
1903  * inside the "[xxx]" text.  This string must never be empty, or grids
1904  * containing monsters will be displayed with an extra comma.
1905  *
1906  * Note that if a monster is in the grid, we update both the monster
1907  * recall info and the health bar info to track that monster.
1908  *
1909  * Eventually, we may allow multiple objects per grid, or objects
1910  * and terrain features in the same grid. 
1911  *
1912  * This function must handle blindness/hallucination.
1913  */
1914 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, concptr info)
1915 {
1916         cave_type *c_ptr = &cave[y][x];
1917         OBJECT_IDX this_o_idx, next_o_idx = 0;
1918         concptr s1 = "", s2 = "", s3 = "", x_info = "";
1919         bool boring = TRUE;
1920         FEAT_IDX feat;
1921         feature_type *f_ptr;
1922         char query = '\001';
1923         char out_val[MAX_NLEN+80];
1924         OBJECT_IDX floor_list[23];
1925         ITEM_NUMBER floor_num = 0;
1926
1927         /* Scan all objects in the grid */
1928         if (easy_floor)
1929         {
1930                 floor_num = scan_floor(floor_list, y, x, 0x02);
1931
1932                 if (floor_num)
1933                 {
1934                         x_info = _("x物 ", "x,");
1935                 }
1936         }
1937
1938         /* Hack -- under the player */
1939         if (player_bold(y, x))
1940         {
1941 #ifdef JP
1942                 s1 = "あなたは";
1943                 s2 = "の上";
1944                 s3 = "にいる";
1945 #else
1946                 s1 = "You are ";
1947                 s2 = "on ";
1948 #endif
1949         }
1950         else
1951         {
1952                 s1 = _("ターゲット:", "Target:");
1953         }
1954
1955         /* Hack -- hallucination */
1956         if (p_ptr->image)
1957         {
1958                 concptr name = _("何か奇妙な物", "something strange");
1959
1960                 /* Display a message */
1961 #ifdef JP
1962                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
1963 #else
1964                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
1965 #endif
1966
1967                 prt(out_val, 0, 0);
1968                 move_cursor_relative(y, x);
1969                 query = inkey();
1970
1971                 /* Stop on everything but "return" */
1972                 if ((query != '\r') && (query != '\n')) return query;
1973
1974                 /* Repeat forever */
1975                 return 0;
1976         }
1977
1978
1979         /* Actual monsters */
1980         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
1981         {
1982                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
1983                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1984                 GAME_TEXT m_name[MAX_NLEN];
1985                 bool recall = FALSE;
1986
1987                 /* Not boring */
1988                 boring = FALSE;
1989
1990                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1991                 monster_race_track(m_ptr->ap_r_idx);
1992                 health_track(c_ptr->m_idx);
1993                 handle_stuff();
1994
1995                 /* Interact */
1996                 while (1)
1997                 {
1998                         char acount[10];
1999
2000                         /* Recall */
2001                         if (recall)
2002                         {
2003                                 screen_save();
2004
2005                                 /* Recall on screen */
2006                                 screen_roff(m_ptr->ap_r_idx, 0);
2007
2008                                 /* Hack -- Complete the prompt (again) */
2009                                 Term_addstr(-1, TERM_WHITE, format(_("  [r思 %s%s]", "  [r,%s%s]"), x_info, info));
2010
2011                                 /* Command */
2012                                 query = inkey();
2013
2014                                 screen_load();
2015
2016                                 /* Normal commands */
2017                                 if (query != 'r') break;
2018
2019                                 /* Toggle recall */
2020                                 recall = FALSE;
2021
2022                                 /* Cleare recall text and repeat */
2023                                 continue;
2024                         }
2025
2026                         /*** Normal ***/
2027
2028                         /* Describe, and prompt for recall */
2029                         evaluate_monster_exp(acount, m_ptr);
2030
2031 #ifdef JP
2032                         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);
2033 #else
2034                         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);
2035 #endif
2036
2037                         prt(out_val, 0, 0);
2038
2039                         /* Place cursor */
2040                         move_cursor_relative(y, x);
2041
2042                         /* Command */
2043                         query = inkey();
2044
2045                         /* Normal commands */
2046                         if (query != 'r') break;
2047
2048                         /* Toggle recall */
2049                         recall = TRUE;
2050                 }
2051
2052                 /* Always stop at "normal" keys */
2053                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2054
2055                 /* Sometimes stop at "space" key */
2056                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2057
2058                 /* Change the intro */
2059                 s1 = _("それは", "It is ");
2060
2061                 /* Hack -- take account of gender */
2062                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
2063                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
2064
2065                 /* Use a preposition */
2066 #ifdef JP
2067                 s2 = "を";
2068                 s3 = "持っている";
2069 #else
2070                 s2 = "carrying ";
2071 #endif
2072
2073
2074                 /* Scan all objects being carried */
2075                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
2076                 {
2077                         GAME_TEXT o_name[MAX_NLEN];
2078
2079                         object_type *o_ptr;
2080                         o_ptr = &o_list[this_o_idx];
2081
2082                         /* Acquire next object */
2083                         next_o_idx = o_ptr->next_o_idx;
2084
2085                         /* Obtain an object description */
2086                         object_desc(o_name, o_ptr, 0);
2087
2088 #ifdef JP
2089                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2090 #else
2091                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2092 #endif
2093
2094                         prt(out_val, 0, 0);
2095                         move_cursor_relative(y, x);
2096                         query = inkey();
2097
2098                         /* Always stop at "normal" keys */
2099                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2100
2101                         /* Sometimes stop at "space" key */
2102                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2103
2104                         /* Change the intro */
2105                         s2 = _("をまた", "also carrying ");
2106                 }
2107
2108                 /* Use a preposition */
2109 #ifdef JP
2110                 s2 = "の上";
2111                 s3 = "にいる";
2112 #else
2113                 s2 = "on ";
2114 #endif
2115         }
2116
2117         if (floor_num)
2118         {
2119                 int min_width = 0;
2120
2121                 while (1)
2122                 {
2123                         if (floor_num == 1)
2124                         {
2125                                 GAME_TEXT o_name[MAX_NLEN];
2126
2127                                 object_type *o_ptr;
2128                                 o_ptr = &o_list[floor_list[0]];
2129
2130                                 object_desc(o_name, o_ptr, 0);
2131
2132 #ifdef JP
2133                                 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2134 #else
2135                                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2136 #endif
2137
2138                                 prt(out_val, 0, 0);
2139                                 move_cursor_relative(y, x);
2140
2141                                 /* Command */
2142                                 query = inkey();
2143
2144                                 /* End this grid */
2145                                 return query;
2146                         }
2147
2148                         /* Provide one cushion before item listing  */
2149                         if (boring)
2150                         {
2151                                 /* Display rough information about items */
2152 #ifdef JP
2153                                 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
2154 #else
2155                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
2156 #endif
2157
2158                                 prt(out_val, 0, 0);
2159                                 move_cursor_relative(y, x);
2160
2161                                 /* Command */
2162                                 query = inkey();
2163
2164                                 /* No request for listing */
2165                                 if (query != 'x' && query != ' ') return query;
2166                         }
2167
2168
2169                         /** Display list of items **/
2170
2171                         /* Continue scrolling list if requested */
2172                         while (1)
2173                         {
2174                                 int i;
2175                                 OBJECT_IDX o_idx;
2176                                 screen_save();
2177
2178                                 /* Display */
2179                                 show_gold_on_floor = TRUE;
2180                                 (void)show_floor(0, y, x, &min_width);
2181                                 show_gold_on_floor = FALSE;
2182
2183                                 /* Prompt */
2184 #ifdef JP
2185                                 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
2186 #else
2187                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
2188 #endif
2189                                 prt(out_val, 0, 0);
2190
2191                                 query = inkey();
2192                                 screen_load();
2193
2194                                 /* Exit unless 'Enter' */
2195                                 if (query != '\n' && query != '\r')
2196                                 {
2197                                         return query;
2198                                 }
2199
2200                                 /* Get the object being moved. */
2201                                 o_idx = c_ptr->o_idx;
2202  
2203                                 /* Only rotate a pile of two or more objects. */
2204                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
2205
2206                                 /* Remove the first object from the list. */
2207                                 excise_object_idx(o_idx);
2208
2209                                 /* Find end of the list. */
2210                                 i = c_ptr->o_idx;
2211                                 while (o_list[i].next_o_idx)
2212                                         i = o_list[i].next_o_idx;
2213
2214                                 /* Add after the last object. */
2215                                 o_list[i].next_o_idx = o_idx;
2216
2217                                 /* Loop and re-display the list */
2218                         }
2219                 }
2220
2221                 /* NOTREACHED */
2222         }
2223
2224         /* Scan all objects in the grid */
2225         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2226         {
2227                 object_type *o_ptr;
2228                 o_ptr = &o_list[this_o_idx];
2229
2230                 /* Acquire next object */
2231                 next_o_idx = o_ptr->next_o_idx;
2232
2233                 if (o_ptr->marked & OM_FOUND)
2234                 {
2235                         GAME_TEXT o_name[MAX_NLEN];
2236
2237                         /* Not boring */
2238                         boring = FALSE;
2239
2240                         /* Obtain an object description */
2241                         object_desc(o_name, o_ptr, 0);
2242
2243 #ifdef JP
2244                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
2245 #else
2246                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
2247 #endif
2248
2249                         prt(out_val, 0, 0);
2250                         move_cursor_relative(y, x);
2251                         query = inkey();
2252
2253                         /* Always stop at "normal" keys */
2254                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2255
2256                         /* Sometimes stop at "space" key */
2257                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
2258
2259                         /* Change the intro */
2260                         s1 = _("それは", "It is ");
2261
2262                         /* Plurals */
2263                         if (o_ptr->number != 1) s1 = _("それらは", "They are ");
2264
2265                         /* Preposition */
2266 #ifdef JP
2267                         s2 = "の上";
2268                         s3 = "に見える";
2269 #else
2270                         s2 = "on ";
2271 #endif
2272
2273                 }
2274         }
2275
2276
2277         /* Feature code (applying "mimic" field) */
2278         feat = get_feat_mimic(c_ptr);
2279
2280         /* Require knowledge about grid, or ability to see grid */
2281         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
2282         {
2283                 /* Forget feature */
2284                 feat = feat_none;
2285         }
2286
2287         f_ptr = &f_info[feat];
2288
2289         /* Terrain feature if needed */
2290         if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
2291         {
2292                 concptr name;
2293
2294                 /* Hack -- special handling for quest entrances */
2295                 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
2296                 {
2297                         /* Set the quest number temporary */
2298                         IDX old_quest = p_ptr->inside_quest;
2299                         int j;
2300
2301                         /* Clear the text */
2302                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
2303                         quest_text_line = 0;
2304
2305                         p_ptr->inside_quest = c_ptr->special;
2306
2307                         /* Get the quest text */
2308                         init_flags = INIT_NAME_ONLY;
2309
2310                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
2311
2312                         name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"), 
2313                                                 quest[c_ptr->special].name, quest[c_ptr->special].level);
2314
2315                         /* Reset the old quest number */
2316                         p_ptr->inside_quest = old_quest;
2317                 }
2318
2319                 /* Hack -- special handling for building doors */
2320                 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
2321                 {
2322                         name = building[f_ptr->subtype].name;
2323                 }
2324                 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
2325                 {
2326                         name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
2327                 }
2328                 else if (have_flag(f_ptr->flags, FF_TOWN))
2329                 {
2330                         name = town[c_ptr->special].name;
2331                 }
2332                 else if (p_ptr->wild_mode && (feat == feat_floor))
2333                 {
2334                         name = _("道", "road");
2335                 }
2336                 else
2337                 {
2338                         name = f_name + f_ptr->name;
2339                 }
2340
2341
2342                 /* Pick a prefix */
2343                 if (*s2 &&
2344                     ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
2345                      (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
2346                      have_flag(f_ptr->flags, FF_TOWN)))
2347                 {
2348                         s2 = _("の中", "in ");
2349                 }
2350
2351                 /* Hack -- special introduction for store & building doors -KMW- */
2352                 if (have_flag(f_ptr->flags, FF_STORE) ||
2353                     have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
2354                     (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
2355                     have_flag(f_ptr->flags, FF_ENTRANCE))
2356                 {
2357                         s2 = _("の入口", "");
2358                 }
2359 #ifndef JP
2360                 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
2361                          have_flag(f_ptr->flags, FF_TOWN) ||
2362                          have_flag(f_ptr->flags, FF_SHALLOW) ||
2363                          have_flag(f_ptr->flags, FF_DEEP))
2364                 {
2365                         s3 ="";
2366                 }
2367                 else
2368                 {
2369                         /* Pick proper indefinite article */
2370                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
2371                 }
2372 #endif
2373
2374                 /* Display a message */
2375                 if (p_ptr->wizard)
2376                 {
2377                         char f_idx_str[32];
2378                         if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
2379                         else sprintf(f_idx_str, "%d", c_ptr->feat);
2380 #ifdef JP
2381                         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]);
2382 #else
2383                         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);
2384 #endif
2385                 }
2386                 else
2387 #ifdef JP
2388                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
2389 #else
2390                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
2391 #endif
2392
2393                 prt(out_val, 0, 0);
2394                 move_cursor_relative(y, x);
2395                 query = inkey();
2396
2397                 /* Always stop at "normal" keys */
2398                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
2399         }
2400
2401         /* Stop on everything but "return" */
2402         if ((query != '\r') && (query != '\n')) return query;
2403
2404         /* Repeat forever */
2405         return 0;
2406 }
2407
2408
2409 /*
2410  * Handle "target" and "look".
2411  *
2412  * Note that this code can be called from "get_aim_dir()".
2413  *
2414  * All locations must be on the current panel.  Consider the use of
2415  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
2416  * some form of "scrolling" the map around the cursor.  
2417  * That is, consider the possibility of "auto-scrolling" the screen
2418  * while the cursor moves around.  This may require changes in the
2419  * "update_monster()" code to allow "visibility" even if off panel, and
2420  * may require dynamic recalculation of the "temp" grid set.
2421  *
2422  * Hack -- targeting/observing an "outer border grid" may induce
2423  * problems, so this is not currently allowed.
2424  *
2425  * The player can use the direction keys to move among "interesting"
2426  * grids in a heuristic manner, or the "space", "+", and "-" keys to
2427  * move through the "interesting" grids in a sequential manner, or
2428  * can enter "location" mode, and use the direction keys to move one
2429  * grid at a time in any direction.  The "t" (set target) command will
2430  * only target a monster (as opposed to a location) if the monster is
2431  * target_able and the "interesting" mode is being used.
2432  *
2433  * The current grid is described using the "look" method above, and
2434  * a new command may be entered at any time, but note that if the
2435  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
2436  * where "space" has no obvious meaning) then "space" will scan
2437  * through the description of the current grid until done, instead
2438  * of immediately jumping to the next "interesting" grid.  This
2439  * allows the "target" command to retain its old semantics.
2440  *
2441  * The "*", "+", and "-" keys may always be used to jump immediately
2442  * to the next (or previous) interesting grid, in the proper mode.
2443  *
2444  * The "return" key may always be used to scan through a complete
2445  * grid description (forever).
2446  *
2447  * This command will cancel any old target, even if used from
2448  * inside the "look" command.
2449  */
2450 bool target_set(BIT_FLAGS mode)
2451 {
2452         int i, d, m, t, bd;
2453         POSITION y = p_ptr->y;
2454         POSITION x = p_ptr->x;
2455
2456         bool done = FALSE;
2457         bool flag = TRUE;
2458         char query;
2459         char info[80];
2460         char same_key;
2461         cave_type *c_ptr;
2462         TERM_LEN wid, hgt;
2463         
2464         get_screen_size(&wid, &hgt);
2465
2466         /* Cancel target */
2467         target_who = 0;
2468
2469         if (rogue_like_commands)
2470         {
2471                 same_key = 'x';
2472         }
2473         else
2474         {
2475                 same_key = 'l';
2476         }
2477
2478         /* Prepare the "temp" array */
2479         target_set_prepare(mode);
2480
2481         /* Start near the player */
2482         m = 0;
2483
2484         /* Interact */
2485         while (!done)
2486         {
2487                 /* Interesting grids */
2488                 if (flag && temp_n)
2489                 {
2490                         y = temp_y[m];
2491                         x = temp_x[m];
2492
2493                         /* Set forcus */
2494                         change_panel_xy(y, x);
2495
2496                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
2497
2498                         /* Access */
2499                         c_ptr = &cave[y][x];
2500
2501                         /* Allow target */
2502                         if (target_able(c_ptr->m_idx))
2503                         {
2504                                 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
2505                         }
2506
2507                         /* Dis-allow target */
2508                         else
2509                         {
2510                                 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
2511                         }
2512
2513                         if (cheat_sight)
2514                         {
2515                                 char cheatinfo[30];
2516                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
2517                                         los(p_ptr->y, p_ptr->x, y, x), projectable(p_ptr->y, p_ptr->x, y, x));
2518                                 strcat(info, cheatinfo);
2519                         }
2520                         
2521                         /* Describe and Prompt */
2522                         while (TRUE){
2523                                 query = target_set_aux(y, x, mode, info);
2524                                 if(query)break;
2525                         }
2526
2527                         /* Assume no "direction" */
2528                         d = 0;
2529
2530                         if (use_menu)
2531                         {
2532                                 if (query == '\r') query = 't';
2533                         }  
2534
2535                         /* Analyze */
2536                         switch (query)
2537                         {
2538                                 case ESCAPE:
2539                                 case 'q':
2540                                 {
2541                                         done = TRUE;
2542                                         break;
2543                                 }
2544
2545                                 case 't':
2546                                 case '.':
2547                                 case '5':
2548                                 case '0':
2549                                 {
2550                                         if (target_able(c_ptr->m_idx))
2551                                         {
2552                                                 health_track(c_ptr->m_idx);
2553                                                 target_who = c_ptr->m_idx;
2554                                                 target_row = y;
2555                                                 target_col = x;
2556                                                 done = TRUE;
2557                                         }
2558                                         else
2559                                         {
2560                                                 bell();
2561                                         }
2562                                         break;
2563                                 }
2564
2565                                 case ' ':
2566                                 case '*':
2567                                 case '+':
2568                                 {
2569                                         if (++m == temp_n)
2570                                         {
2571                                                 m = 0;
2572                                                 if (!expand_list) done = TRUE;
2573                                         }
2574                                         break;
2575                                 }
2576
2577                                 case '-':
2578                                 {
2579                                         if (m-- == 0)
2580                                         {
2581                                                 m = temp_n - 1;
2582                                                 if (!expand_list) done = TRUE;
2583                                         }
2584                                         break;
2585                                 }
2586
2587                                 case 'p':
2588                                 {
2589                                         /* Recenter the map around the player */
2590                                         verify_panel();
2591                                         p_ptr->update |= (PU_MONSTERS);
2592                                         p_ptr->redraw |= (PR_MAP);
2593                                         p_ptr->window |= (PW_OVERHEAD);
2594                                         handle_stuff();
2595
2596                                         /* Recalculate interesting grids */
2597                                         target_set_prepare(mode);
2598
2599                                         y = p_ptr->y;
2600                                         x = p_ptr->x;
2601                                 }
2602
2603                                 case 'o':
2604                                 {
2605                                         flag = FALSE;
2606                                         break;
2607                                 }
2608
2609                                 case 'm':
2610                                 {
2611                                         break;
2612                                 }
2613
2614                                 default:
2615                                 {
2616                                         if(query == same_key)
2617                                         {
2618                                                 if (++m == temp_n)
2619                                                 {
2620                                                         m = 0;
2621                                                         if (!expand_list) done = TRUE;
2622                                                 }
2623                                         }
2624                                         else
2625                                         {
2626                                                 /* Extract the action (if any) */
2627                                                 d = get_keymap_dir(query);
2628
2629                                                 if (!d) bell();
2630                                                 break;
2631                                         }
2632                                 }
2633                         }
2634                         /* Hack -- move around */
2635                         if (d)
2636                         {
2637                                 /* Modified to scroll to monster */
2638                                 POSITION y2 = panel_row_min;
2639                                 POSITION x2 = panel_col_min;
2640
2641                                 /* Find a new monster */
2642                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
2643
2644                                 /* Request to target past last interesting grid */
2645                                 while (flag && (i < 0))
2646                                 {
2647                                         /* Note the change */
2648                                         if (change_panel(ddy[d], ddx[d]))
2649                                         {
2650                                                 int v = temp_y[m];
2651                                                 int u = temp_x[m];
2652
2653                                                 /* Recalculate interesting grids */
2654                                                 target_set_prepare(mode);
2655
2656                                                 /* Look at interesting grids */
2657                                                 flag = TRUE;
2658
2659                                                 /* Find a new monster */
2660                                                 i = target_pick(v, u, ddy[d], ddx[d]);
2661
2662                                                 /* Use that grid */
2663                                                 if (i >= 0) m = i;
2664                                         }
2665
2666                                         /* Nothing interesting */
2667                                         else
2668                                         {
2669                                                 POSITION dx = ddx[d];
2670                                                 POSITION dy = ddy[d];
2671
2672                                                 /* Restore previous position */
2673                                                 panel_row_min = y2;
2674                                                 panel_col_min = x2;
2675                                                 panel_bounds_center();
2676
2677                                                 p_ptr->update |= (PU_MONSTERS);
2678                                                 p_ptr->redraw |= (PR_MAP);
2679                                                 p_ptr->window |= (PW_OVERHEAD);
2680                                                 handle_stuff();
2681
2682                                                 /* Recalculate interesting grids */
2683                                                 target_set_prepare(mode);
2684
2685                                                 /* Look at boring grids */
2686                                                 flag = FALSE;
2687
2688                                                 /* Move */
2689                                                 x += dx;
2690                                                 y += dy;
2691
2692                                                 /* Do not move horizontally if unnecessary */
2693                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2694                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
2695                                                 {
2696                                                         dx = 0;
2697                                                 }
2698
2699                                                 /* Do not move vertically if unnecessary */
2700                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2701                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
2702                                                 {
2703                                                         dy = 0;
2704                                                 }
2705
2706                                                 /* Apply the motion */
2707                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
2708                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
2709                                                 {
2710                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
2711                                                 }
2712
2713                                                 /* Slide into legality */
2714                                                 if (x >= cur_wid-1) x = cur_wid - 2;
2715                                                 else if (x <= 0) x = 1;
2716
2717                                                 /* Slide into legality */
2718                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
2719                                                 else if (y <= 0) y = 1;
2720                                         }
2721                                 }
2722
2723                                 /* Use that grid */
2724                                 m = i;
2725                         }
2726                 }
2727
2728                 /* Arbitrary grids */
2729                 else
2730                 {
2731                         bool move_fast = FALSE;
2732
2733                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
2734
2735                         /* Access */
2736                         c_ptr = &cave[y][x];
2737
2738                         /* Default prompt */
2739                         strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
2740
2741                         if (cheat_sight)
2742                         {
2743                                 char cheatinfo[30];
2744                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
2745                                         los(p_ptr->y, p_ptr->x, y, x),
2746                                         projectable(p_ptr->y, p_ptr->x, y, x));
2747                                 strcat(info, cheatinfo);
2748                         }
2749
2750                         /* Describe and Prompt (enable "TARGET_LOOK") */
2751                         while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
2752
2753                         /* Assume no direction */
2754                         d = 0;
2755
2756                         if (use_menu)
2757                         {
2758                                 if (query == '\r') query = 't';
2759                         }  
2760
2761                         /* Analyze the keypress */
2762                         switch (query)
2763                         {
2764                                 case ESCAPE:
2765                                 case 'q':
2766                                 {
2767                                         done = TRUE;
2768                                         break;
2769                                 }
2770
2771                                 case 't':
2772                                 case '.':
2773                                 case '5':
2774                                 case '0':
2775                                 {
2776                                         target_who = -1;
2777                                         target_row = y;
2778                                         target_col = x;
2779                                         done = TRUE;
2780                                         break;
2781                                 }
2782
2783                                 case 'p':
2784                                 {
2785                                         /* Recenter the map around the player */
2786                                         verify_panel();
2787                                         p_ptr->update |= (PU_MONSTERS);
2788                                         p_ptr->redraw |= (PR_MAP);
2789                                         p_ptr->window |= (PW_OVERHEAD);
2790                                         handle_stuff();
2791
2792                                         /* Recalculate interesting grids */
2793                                         target_set_prepare(mode);
2794
2795                                         y = p_ptr->y;
2796                                         x = p_ptr->x;
2797                                 }
2798
2799                                 case 'o':
2800                                 {
2801                                         break;
2802                                 }
2803
2804                                 case ' ':
2805                                 case '*':
2806                                 case '+':
2807                                 case '-':
2808                                 case 'm':
2809                                 {
2810                                         flag = TRUE;
2811
2812                                         m = 0;
2813                                         bd = 999;
2814
2815                                         /* Pick a nearby monster */
2816                                         for (i = 0; i < temp_n; i++)
2817                                         {
2818                                                 t = distance(y, x, temp_y[i], temp_x[i]);
2819
2820                                                 /* Pick closest */
2821                                                 if (t < bd)
2822                                                 {
2823                                                         m = i;
2824                                                         bd = t;
2825                                                 }
2826                                         }
2827
2828                                         /* Nothing interesting */
2829                                         if (bd == 999) flag = FALSE;
2830
2831                                         break;
2832                                 }
2833
2834                                 default:
2835                                 {
2836                                         /* Extract the action (if any) */
2837                                         d = get_keymap_dir(query);
2838
2839                                         /* XTRA HACK MOVEFAST */
2840                                         if (isupper(query)) move_fast = TRUE;
2841
2842                                         if (!d) bell();
2843                                         break;
2844                                 }
2845                         }
2846
2847                         /* Handle "direction" */
2848                         if (d)
2849                         {
2850                                 POSITION dx = ddx[d];
2851                                 POSITION dy = ddy[d];
2852
2853                                 /* XTRA HACK MOVEFAST */
2854                                 if (move_fast)
2855                                 {
2856                                         int mag = MIN(wid / 2, hgt / 2);
2857                                         x += dx * mag;
2858                                         y += dy * mag;
2859                                 }
2860                                 else
2861                                 {
2862                                         x += dx;
2863                                         y += dy;
2864                                 }
2865
2866                                 /* Do not move horizontally if unnecessary */
2867                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
2868                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
2869                                 {
2870                                         dx = 0;
2871                                 }
2872
2873                                 /* Do not move vertically if unnecessary */
2874                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
2875                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
2876                                 {
2877                                         dy = 0;
2878                                 }
2879
2880                                 /* Apply the motion */
2881                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
2882                                          (x >= panel_col_min + wid) || (x < panel_col_min))
2883                                 {
2884                                         if (change_panel(dy, dx)) target_set_prepare(mode);
2885                                 }
2886
2887                                 /* Slide into legality */
2888                                 if (x >= cur_wid-1) x = cur_wid - 2;
2889                                 else if (x <= 0) x = 1;
2890
2891                                 /* Slide into legality */
2892                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
2893                                 else if (y <= 0) y = 1;
2894                         }
2895                 }
2896         }
2897
2898         /* Forget */
2899         temp_n = 0;
2900
2901         /* Clear the top line */
2902         prt("", 0, 0);
2903
2904         /* Recenter the map around the player */
2905         verify_panel();
2906         p_ptr->update |= (PU_MONSTERS);
2907         p_ptr->redraw |= (PR_MAP);
2908         p_ptr->window |= (PW_OVERHEAD);
2909         handle_stuff();
2910
2911         /* Failure to set target */
2912         if (!target_who) return (FALSE);
2913
2914         /* Success */
2915         return (TRUE);
2916 }
2917
2918
2919 /*
2920  * Get an "aiming direction" from the user.
2921  *
2922  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
2923  * "0" for "current target", and "-1" for "entry aborted".
2924  *
2925  * Note that "Force Target", if set, will pre-empt user interaction,
2926  * if there is a usable target already set.
2927  *
2928  * Note that confusion over-rides any (explicit?) user choice.
2929  */
2930 bool get_aim_dir(DIRECTION *dp)
2931 {
2932         DIRECTION dir;
2933         char    command;
2934         concptr p;
2935         COMMAND_CODE code;
2936
2937         (*dp) = 0;
2938
2939         /* Global direction */
2940         dir = command_dir;
2941
2942         /* Hack -- auto-target if requested */
2943         if (use_old_target && target_okay()) dir = 5;
2944
2945         if (repeat_pull(&code))
2946         {
2947                 /* Confusion? */
2948
2949                 /* Verify */
2950                 if (!(code == 5 && !target_okay()))
2951                 {
2952 /*                      return (TRUE); */
2953                         dir = (DIRECTION)code;
2954                 }
2955         }
2956         *dp = (DIRECTION)code;
2957
2958         /* Ask until satisfied */
2959         while (!dir)
2960         {
2961                 /* Choose a prompt */
2962                 if (!target_okay())
2963                 {
2964                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
2965                 }
2966                 else
2967                 {
2968                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
2969                 }
2970
2971                 /* Get a command (or Cancel) */
2972                 if (!get_com(p, &command, TRUE)) break;
2973
2974                 if (use_menu)
2975                 {
2976                         if (command == '\r') command = 't';
2977                 }  
2978
2979                 /* Convert various keys to "standard" keys */
2980                 switch (command)
2981                 {
2982                         /* Use current target */
2983                         case 'T':
2984                         case 't':
2985                         case '.':
2986                         case '5':
2987                         case '0':
2988                         {
2989                                 dir = 5;
2990                                 break;
2991                         }
2992
2993                         /* Set new target */
2994                         case '*':
2995                         case ' ':
2996                         case '\r':
2997                         {
2998                                 if (target_set(TARGET_KILL)) dir = 5;
2999                                 break;
3000                         }
3001
3002                         default:
3003                         {
3004                                 /* Extract the action (if any) */
3005                                 dir = get_keymap_dir(command);
3006
3007                                 break;
3008                         }
3009                 }
3010
3011                 /* Verify requested targets */
3012                 if ((dir == 5) && !target_okay()) dir = 0;
3013
3014                 /* Error */
3015                 if (!dir) bell();
3016         }
3017
3018         /* No direction */
3019         if (!dir)
3020         {
3021                 project_length = 0; /* reset to default */
3022                 return (FALSE);
3023         }
3024
3025         /* Save the direction */
3026         command_dir = dir;
3027
3028         /* Check for confusion */
3029         if (p_ptr->confused)
3030         {
3031                 /* Random direction */
3032                 dir = ddd[randint0(8)];
3033         }
3034
3035         /* Notice confusion */
3036         if (command_dir != dir)
3037         {
3038                 /* Warn the user */
3039                 msg_print(_("あなたは混乱している。", "You are confused."));
3040         }
3041
3042         /* Save direction */
3043         (*dp) = dir;
3044
3045 /*      repeat_push(dir); */
3046         repeat_push((COMMAND_CODE)command_dir);
3047
3048         /* A "valid" direction was entered */
3049         return (TRUE);
3050 }
3051
3052
3053 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
3054 {
3055         DIRECTION dir;
3056         concptr prompt;
3057         COMMAND_CODE code;
3058
3059         (*dp) = 0;
3060
3061         /* Global direction */
3062         dir = command_dir;
3063
3064         if (repeat_pull(&code))
3065         {
3066                 dir = (DIRECTION)code;
3067                 /*              return (TRUE); */
3068         }
3069         *dp = (DIRECTION)code;
3070
3071         if (allow_under)
3072         {
3073                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3074         }
3075         else
3076         {
3077                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3078         }
3079
3080         /* Get a direction */
3081         while (!dir)
3082         {
3083                 char ch;
3084
3085                 /* Get a command (or Cancel) */
3086                 if (!get_com(prompt, &ch, TRUE)) break;
3087
3088                 /* Look down */
3089                 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3090                 {
3091                         dir = 5;
3092                 }
3093                 else
3094                 {
3095                         /* Look up the direction */
3096                         dir = get_keymap_dir(ch);
3097
3098                         if (!dir) bell();
3099                 }
3100         }
3101
3102         /* Prevent weirdness */
3103         if ((dir == 5) && (!allow_under)) dir = 0;
3104
3105         /* Aborted */
3106         if (!dir) return (FALSE);
3107
3108         /* Save desired direction */
3109         command_dir = dir;
3110
3111         /* Apply "confusion" */
3112         if (p_ptr->confused)
3113         {
3114                 /* Standard confusion */
3115                 if (randint0(100) < 75)
3116                 {
3117                         /* Random direction */
3118                         dir = ddd[randint0(8)];
3119                 }
3120         }
3121         else if (p_ptr->riding && with_steed)
3122         {
3123                 monster_type *m_ptr = &m_list[p_ptr->riding];
3124                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3125
3126                 if (MON_CONFUSED(m_ptr))
3127                 {
3128                         /* Standard confusion */
3129                         if (randint0(100) < 75)
3130                         {
3131                                 /* Random direction */
3132                                 dir = ddd[randint0(8)];
3133                         }
3134                 }
3135                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3136                 {
3137                         /* Random direction */
3138                         dir = ddd[randint0(8)];
3139                 }
3140                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3141                 {
3142                         /* Random direction */
3143                         dir = ddd[randint0(8)];
3144                 }
3145         }
3146
3147         /* Notice confusion */
3148         if (command_dir != dir)
3149         {
3150                 if (p_ptr->confused)
3151                 {
3152                         /* Warn the user */
3153                         msg_print(_("あなたは混乱している。", "You are confused."));
3154                 }
3155                 else
3156                 {
3157                         GAME_TEXT m_name[MAX_NLEN];
3158                         monster_type *m_ptr = &m_list[p_ptr->riding];
3159
3160                         monster_desc(m_name, m_ptr, 0);
3161                         if (MON_CONFUSED(m_ptr))
3162                         {
3163                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3164                         }
3165                         else
3166                         {
3167                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3168                         }
3169                 }
3170         }
3171
3172         /* Save direction */
3173         (*dp) = dir;
3174
3175         /*      repeat_push(dir); */
3176         repeat_push((COMMAND_CODE)command_dir);
3177
3178         /* Success */
3179         return (TRUE);
3180 }
3181
3182 /*
3183  * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
3184  * and place it into "command_dir", unless we already have one.
3185  *
3186  * This function should be used for all "repeatable" commands, such as
3187  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
3188  * as all commands which must reference a grid adjacent to the player,
3189  * and which may not reference the grid under the player.  Note that,
3190  * for example, it is no longer possible to "disarm" or "open" chests
3191  * in the same grid as the player.
3192  *
3193  * Direction "5" is illegal and will (cleanly) abort the command.
3194  *
3195  * This function tracks and uses the "global direction", and uses
3196  * that as the "desired direction", to which "confusion" is applied.
3197  */
3198 bool get_rep_dir(DIRECTION *dp, bool under)
3199 {
3200         DIRECTION dir;
3201         concptr prompt;
3202         COMMAND_CODE code;
3203
3204         (*dp) = 0;
3205
3206         /* Global direction */
3207         dir = command_dir;
3208
3209         if (repeat_pull(&code))
3210         {
3211                 dir = (DIRECTION)code;
3212 /*              return (TRUE); */
3213         }
3214         *dp = (DIRECTION)code;
3215
3216         if (under)
3217         {
3218                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
3219         }
3220         else
3221         {
3222                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
3223         }
3224         
3225         /* Get a direction */
3226         while (!dir)
3227         {
3228                 char ch;
3229
3230                 /* Get a command (or Cancel) */
3231                 if (!get_com(prompt, &ch, TRUE)) break;
3232
3233                 /* Look down */
3234                 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
3235                 {
3236                         dir = 5;
3237                 }
3238                 else
3239                 {
3240                         /* Look up the direction */
3241                         dir = get_keymap_dir(ch);
3242
3243                         if (!dir) bell();
3244                 }
3245         }
3246
3247         /* Prevent weirdness */
3248         if ((dir == 5) && (!under)) dir = 0;
3249
3250         /* Aborted */
3251         if (!dir) return (FALSE);
3252
3253         /* Save desired direction */
3254         command_dir = dir;
3255
3256         /* Apply "confusion" */
3257         if (p_ptr->confused)
3258         {
3259                 /* Standard confusion */
3260                 if (randint0(100) < 75)
3261                 {
3262                         /* Random direction */
3263                         dir = ddd[randint0(8)];
3264                 }
3265         }
3266         else if (p_ptr->riding)
3267         {
3268                 monster_type *m_ptr = &m_list[p_ptr->riding];
3269                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3270
3271                 if (MON_CONFUSED(m_ptr))
3272                 {
3273                         /* Standard confusion */
3274                         if (randint0(100) < 75)
3275                         {
3276                                 /* Random direction */
3277                                 dir = ddd[randint0(8)];
3278                         }
3279                 }
3280                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
3281                 {
3282                         /* Random direction */
3283                         dir = ddd[randint0(8)];
3284                 }
3285                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
3286                 {
3287                         /* Random direction */
3288                         dir = ddd[randint0(8)];
3289                 }
3290         }
3291
3292         /* Notice confusion */
3293         if (command_dir != dir)
3294         {
3295                 if (p_ptr->confused)
3296                 {
3297                         /* Warn the user */
3298                         msg_print(_("あなたは混乱している。", "You are confused."));
3299                 }
3300                 else
3301                 {
3302                         GAME_TEXT m_name[MAX_NLEN];
3303                         monster_type *m_ptr = &m_list[p_ptr->riding];
3304
3305                         monster_desc(m_name, m_ptr, 0);
3306                         if (MON_CONFUSED(m_ptr))
3307                         {
3308                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
3309                         }
3310                         else
3311                         {
3312                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
3313                         }
3314                 }
3315         }
3316
3317         /* Save direction */
3318         (*dp) = dir;
3319
3320 /*      repeat_push(dir); */
3321         repeat_push((COMMAND_CODE)command_dir);
3322
3323         /* Success */
3324         return (TRUE);
3325 }
3326
3327
3328 /*
3329  * XAngband: determine if a given location is "interesting"
3330  * based on target_set_accept function.
3331  */
3332 static bool tgt_pt_accept(POSITION y, POSITION x)
3333 {
3334         cave_type *c_ptr;
3335
3336         /* Bounds */
3337         if (!(in_bounds(y, x))) return (FALSE);
3338
3339         /* Player grid is always interesting */
3340         if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
3341
3342         /* Handle hallucination */
3343         if (p_ptr->image) return (FALSE);
3344
3345         /* Examine the grid */
3346         c_ptr = &cave[y][x];
3347
3348         /* Interesting memorized features */
3349         if (c_ptr->info & (CAVE_MARK))
3350         {
3351                 /* Notice stairs */
3352                 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
3353                 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
3354
3355                 /* Notice quest features */
3356                 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
3357                 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
3358         }
3359
3360         return (FALSE);
3361 }
3362
3363
3364 /*
3365  * XAngband: Prepare the "temp" array for "tget_pt"
3366  * based on target_set_prepare funciton.
3367  */
3368 static void tgt_pt_prepare(void)
3369 {
3370         POSITION y, x;
3371
3372         /* Reset "temp" array */
3373         temp_n = 0;
3374
3375         if (!expand_list) return;
3376
3377         /* Scan the current panel */
3378         for (y = 1; y < cur_hgt; y++)
3379         {
3380                 for (x = 1; x < cur_wid; x++)
3381                 {
3382                         /* Require "interesting" contents */
3383                         if (!tgt_pt_accept(y, x)) continue;
3384
3385                         /* Save the location */
3386                         temp_x[temp_n] = x;
3387                         temp_y[temp_n] = y;
3388                         temp_n++;
3389                 }
3390         }
3391
3392         /* Target the nearest monster for shooting */
3393         ang_sort_comp = ang_sort_comp_distance;
3394         ang_sort_swap = ang_sort_swap_distance;
3395
3396         /* Sort the positions */
3397         ang_sort(temp_x, temp_y, temp_n);
3398 }
3399
3400 /*
3401  * old -- from PsiAngband.
3402  */
3403 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
3404 {
3405         char ch = 0;
3406         int d, n = 0;
3407         POSITION x, y;
3408         bool success = FALSE;
3409
3410         TERM_LEN wid, hgt;
3411
3412         get_screen_size(&wid, &hgt);
3413
3414         x = p_ptr->x;
3415         y = p_ptr->y;
3416
3417         if (expand_list) 
3418         {
3419                 tgt_pt_prepare();
3420         }
3421
3422         msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
3423         msg_flag = FALSE; /* prevents "-more-" message. */
3424
3425         while ((ch != ESCAPE) && !success)
3426         {
3427                 bool move_fast = FALSE;
3428
3429                 move_cursor_relative(y, x);
3430                 ch = inkey();
3431                 switch (ch)
3432                 {
3433                 case ESCAPE:
3434                         break;
3435                 case ' ':
3436                 case 't':
3437                 case '.':
3438                 case '5':
3439                 case '0':
3440                         /* illegal place */
3441                         if (player_bold(y, x)) ch = 0;
3442
3443                         /* okay place */
3444                         else success = TRUE;
3445
3446                         break;
3447
3448                 /* XAngband: Move cursor to stairs */
3449                 case '>':
3450                 case '<':
3451                         if (expand_list && temp_n)
3452                         {
3453                                 int dx, dy;
3454                                 int cx = (panel_col_min + panel_col_max) / 2;
3455                                 int cy = (panel_row_min + panel_row_max) / 2;
3456
3457                                 n++;
3458
3459                                 /* Skip stairs which have defferent distance */
3460                                 for (; n < temp_n; ++ n)
3461                                 {
3462                                         cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
3463
3464                                         if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
3465                                             cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
3466                                         {
3467                                                 /* Found */
3468                                                 break;
3469                                         }
3470                                 }
3471
3472                                 if (n == temp_n)        /* Loop out taget list */
3473                                 {
3474                                         n = 0;
3475                                         y = p_ptr->y;
3476                                         x = p_ptr->x;
3477                                         verify_panel(); /* Move cursor to player */
3478
3479                                         p_ptr->update |= (PU_MONSTERS);
3480
3481                                         p_ptr->redraw |= (PR_MAP);
3482
3483                                         p_ptr->window |= (PW_OVERHEAD);
3484                                         handle_stuff();
3485                                 }
3486                                 else    /* move cursor to next stair and change panel */
3487                                 {
3488                                         y = temp_y[n];
3489                                         x = temp_x[n];
3490
3491                                         dy = 2 * (y - cy) / hgt;
3492                                         dx = 2 * (x - cx) / wid;
3493                                         if (dy || dx) change_panel(dy, dx);
3494                                 }
3495                         }
3496                         break;
3497
3498                 default:
3499                         /* Look up the direction */
3500                         d = get_keymap_dir(ch);
3501
3502                         /* XTRA HACK MOVEFAST */
3503                         if (isupper(ch)) move_fast = TRUE;
3504
3505                         /* Handle "direction" */
3506                         if (d)
3507                         {
3508                                 int dx = ddx[d];
3509                                 int dy = ddy[d];
3510
3511                                 /* XTRA HACK MOVEFAST */
3512                                 if (move_fast)
3513                                 {
3514                                         int mag = MIN(wid / 2, hgt / 2);
3515                                         x += dx * mag;
3516                                         y += dy * mag;
3517                                 }
3518                                 else
3519                                 {
3520                                         x += dx;
3521                                         y += dy;
3522                                 }
3523
3524                                 /* Do not move horizontally if unnecessary */
3525                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3526                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
3527                                 {
3528                                         dx = 0;
3529                                 }
3530
3531                                 /* Do not move vertically if unnecessary */
3532                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3533                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
3534                                 {
3535                                         dy = 0;
3536                                 }
3537
3538                                 /* Apply the motion */
3539                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
3540                                          (x >= panel_col_min + wid) || (x < panel_col_min))
3541                                 {
3542                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
3543                                         change_panel(dy, dx);
3544                                 }
3545
3546                                 /* Slide into legality */
3547                                 if (x >= cur_wid-1) x = cur_wid - 2;
3548                                 else if (x <= 0) x = 1;
3549
3550                                 /* Slide into legality */
3551                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
3552                                 else if (y <= 0) y = 1;
3553
3554                         }
3555                         break;
3556                 }
3557         }
3558
3559         /* Clear the top line */
3560         prt("", 0, 0);
3561
3562         /* Recenter the map around the player */
3563         verify_panel();
3564
3565         p_ptr->update |= (PU_MONSTERS);
3566
3567         p_ptr->redraw |= (PR_MAP);
3568
3569         p_ptr->window |= (PW_OVERHEAD);
3570         handle_stuff();
3571
3572         *x_ptr = x;
3573         *y_ptr = y;
3574         return success;
3575 }
3576
3577
3578 bool get_hack_dir(DIRECTION *dp)
3579 {
3580         DIRECTION dir;
3581         concptr    p;
3582         char    command;
3583
3584         (*dp) = 0;
3585
3586         /* Global direction */
3587         dir = 0;
3588
3589         /* (No auto-targeting) */
3590
3591         /* Ask until satisfied */
3592         while (!dir)
3593         {
3594                 /* Choose a prompt */
3595                 if (!target_okay())
3596                 {
3597                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
3598                 }
3599                 else
3600                 {
3601                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
3602                 }
3603
3604                 /* Get a command (or Cancel) */
3605                 if (!get_com(p, &command, TRUE)) break;
3606
3607                 if (use_menu)
3608                 {
3609                         if (command == '\r') command = 't';
3610                 }  
3611
3612                 /* Convert various keys to "standard" keys */
3613                 switch (command)
3614                 {
3615                         /* Use current target */
3616                         case 'T':
3617                         case 't':
3618                         case '.':
3619                         case '5':
3620                         case '0':
3621                         {
3622                                 dir = 5;
3623                                 break;
3624                         }
3625
3626                         /* Set new target */
3627                         case '*':
3628                         case ' ':
3629                         case '\r':
3630                         {
3631                                 if (target_set(TARGET_KILL)) dir = 5;
3632                                 break;
3633                         }
3634
3635                         default:
3636                         {
3637                                 /* Look up the direction */
3638                                 dir = get_keymap_dir(command);
3639
3640                                 break;
3641                         }
3642                 }
3643
3644                 /* Verify requested targets */
3645                 if ((dir == 5) && !target_okay()) dir = 0;
3646
3647                 /* Error */
3648                 if (!dir) bell();
3649         }
3650
3651         /* No direction */
3652         if (!dir) return (FALSE);
3653
3654         /* Save the direction */
3655         command_dir = dir;
3656
3657         /* Check for confusion */
3658         if (p_ptr->confused)
3659         {
3660                 /* Random direction */
3661                 dir = ddd[randint0(8)];
3662         }
3663
3664         /* Notice confusion */
3665         if (command_dir != dir)
3666         {
3667                 /* Warn the user */
3668                 msg_print(_("あなたは混乱している。", "You are confused."));
3669         }
3670
3671         /* Save direction */
3672         (*dp) = dir;
3673
3674         /* A "valid" direction was entered */
3675         return (TRUE);
3676 }
3677
3678
3679 /*!
3680  * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
3681  * @param sval 射撃武器のアイテム副分類ID 
3682  * @return 消費する基本エネルギー
3683  */
3684 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
3685 {
3686         ENERGY energy = 10000;
3687
3688         /* Analyze the launcher */
3689         switch (sval)
3690         {
3691                 /* Sling and ammo */
3692                 case SV_SLING:
3693                 {
3694                         energy = 8000;
3695                         break;
3696                 }
3697
3698                 /* Short Bow and Arrow */
3699                 case SV_SHORT_BOW:
3700                 {
3701                         energy = 10000;
3702                         break;
3703                 }
3704
3705                 /* Long Bow and Arrow */
3706                 case SV_LONG_BOW:
3707                 {
3708                         energy = 10000;
3709                         break;
3710                 }
3711
3712                 /* Bow of irresponsiblity and Arrow */
3713                 case SV_NAMAKE_BOW:
3714                 {
3715                         energy = 7777;
3716                         break;
3717                 }
3718
3719                 /* Light Crossbow and Bolt */
3720                 case SV_LIGHT_XBOW:
3721                 {
3722                         energy = 12000;
3723                         break;
3724                 }
3725
3726                 /* Heavy Crossbow and Bolt */
3727                 case SV_HEAVY_XBOW:
3728                 {
3729                         energy = 13333;
3730                         break;
3731                 }
3732         }
3733
3734         return (energy);
3735 }
3736
3737
3738 /*
3739  * Return bow tmul
3740  */
3741 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
3742 {
3743         int tmul = 0;
3744
3745         /* Analyze the launcher */
3746         switch (sval)
3747         {
3748                 /* Sling and ammo */
3749                 case SV_SLING:
3750                 {
3751                         tmul = 2;
3752                         break;
3753                 }
3754
3755                 /* Short Bow and Arrow */
3756                 case SV_SHORT_BOW:
3757                 {
3758                         tmul = 2;
3759                         break;
3760                 }
3761
3762                 /* Long Bow and Arrow */
3763                 case SV_LONG_BOW:
3764                 {
3765                         tmul = 3;
3766                         break;
3767                 }
3768
3769                 /* Bow of irresponsiblity and Arrow */
3770                 case SV_NAMAKE_BOW:
3771                 {
3772                         tmul = 3;
3773                         break;
3774                 }
3775
3776                 /* Light Crossbow and Bolt */
3777                 case SV_LIGHT_XBOW:
3778                 {
3779                         tmul = 3;
3780                         break;
3781                 }
3782
3783                 /* Heavy Crossbow and Bolt */
3784                 case SV_HEAVY_XBOW:
3785                 {
3786                         tmul = 4;
3787                         break;
3788                 }
3789         }
3790
3791         return (tmul);
3792 }
3793
3794
3795 /*
3796  * Display a rumor and apply its effects
3797  */
3798
3799 IDX rumor_num(char *zz, IDX max_idx)
3800 {
3801         if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
3802         return (IDX)atoi(zz);
3803 }
3804
3805 concptr rumor_bind_name(char *base, concptr fullname)
3806 {
3807         char *s, *v;
3808
3809         s = strstr(base, "{Name}");
3810         if (s)
3811         {
3812                 s[0] = '\0';
3813                 v = format("%s%s%s", base, fullname, (s + 6));
3814         }
3815         else
3816         {
3817                 v = base;
3818         }
3819
3820         return v;
3821 }
3822
3823 void display_rumor(bool ex)
3824 {
3825         errr err;
3826         int section = 0;
3827         char Rumor[1024];
3828
3829         if (ex)
3830         {
3831                 if (randint0(3) == 0) section = 1;
3832         }
3833
3834         err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
3835                         get_rnd_line("rumors.txt", section, Rumor));
3836         if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
3837
3838         err = TRUE;
3839
3840         if (strncmp(Rumor, "R:", 2) == 0)
3841         {
3842                 char *zz[4];
3843                 concptr rumor_msg = NULL;
3844                 concptr rumor_eff_format = NULL;
3845                 char fullname[1024] = "";
3846
3847                 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
3848                 {
3849                         if (strcmp(zz[0], "ARTIFACT") == 0)
3850                         {
3851                                 IDX a_idx, k_idx;
3852                                 object_type forge;
3853                                 object_type *q_ptr = &forge;
3854                                 artifact_type *a_ptr;
3855
3856                                 while (1)
3857                                 {
3858                                         a_idx = rumor_num(zz[1], max_a_idx);
3859
3860                                         a_ptr = &a_info[a_idx];
3861                                         if (a_ptr->name) break;
3862                                 }
3863
3864                                 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
3865                                 object_prep(q_ptr, k_idx);
3866                                 q_ptr->name1 = a_idx;
3867                                 q_ptr->ident = IDENT_STORE;
3868                                 object_desc(fullname, q_ptr, OD_NAME_ONLY);
3869                         }
3870                         else if  (strcmp(zz[0], "MONSTER") == 0)
3871                         {
3872                                 MONRACE_IDX r_idx;
3873                                 monster_race *r_ptr;
3874
3875                                 while(1)
3876                                 {
3877                                         r_idx = rumor_num(zz[1], max_r_idx);
3878                                         r_ptr = &r_info[r_idx];
3879                                         if (r_ptr->name) break;
3880                                 }
3881
3882                                 strcpy(fullname, r_name + r_ptr->name);
3883
3884                                 /* Remember this monster */
3885                                 if (!r_ptr->r_sights)
3886                                 {
3887                                         r_ptr->r_sights++;
3888                                 }
3889                         }
3890                         else if (strcmp(zz[0], "DUNGEON") == 0)
3891                         {
3892                                 DUNGEON_IDX d_idx;
3893                                 dungeon_info_type *d_ptr;
3894
3895                                 while (1)
3896                                 {
3897                                         d_idx = rumor_num(zz[1], max_d_idx);
3898                                         d_ptr = &d_info[d_idx];
3899                                         if (d_ptr->name) break;
3900                                 }
3901
3902                                 strcpy(fullname, d_name + d_ptr->name);
3903
3904                                 if (!max_dlv[d_idx])
3905                                 {
3906                                         max_dlv[d_idx] = d_ptr->mindepth;
3907                                         rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
3908                                 }
3909                         }
3910                         else if  (strcmp(zz[0], "TOWN") == 0)
3911                         {
3912                                 IDX t_idx;
3913                                 s32b visit;
3914
3915                                 while(1)
3916                                 {
3917                                         t_idx = rumor_num(zz[1], NO_TOWN);
3918                                         if (town[t_idx].name) break;
3919                                 }
3920
3921                                 strcpy(fullname, town[t_idx].name);
3922
3923                                 visit = (1L << (t_idx - 1));
3924                                 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
3925                                 {
3926                                         p_ptr->visit |= visit;
3927                                         rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
3928                                 }
3929                         }
3930
3931                         rumor_msg = rumor_bind_name(zz[2], fullname);
3932                         msg_print(rumor_msg);
3933                         if (rumor_eff_format)
3934                         {
3935                                 msg_print(NULL);
3936                                 msg_format(rumor_eff_format, fullname);
3937                         }
3938                         err = FALSE;
3939                 }
3940         /* error */
3941         if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
3942         }
3943                         else
3944         {
3945                 msg_format("%s", Rumor);
3946         }
3947 }