OSDN Git Service

Reactivate BOM for fxxkin' Visual Studio
[hengband/hengband.git] / src / xtra2.c
1 /*!
2  * @file xtra2.c
3  * @brief 雑多なその他の処理2 / effects of various "objects"
4  * @date 2014/02/06
5  * @author
6  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
7  * This software may be copied and distributed for educational, research, and\n
8  * not for profit purposes provided that this copyright and statement are\n
9  * included in all such copies.\n
10  * 2014 Deskull rearranged comment for Doxygen.
11  */
12
13
14 #include "angband.h"
15
16 #define REWARD_CHANCE 10
17
18
19 /*!
20  * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
21  * Advance experience levels and print experience
22  * @return なし
23  */
24 void check_experience(void)
25 {
26         bool level_reward = FALSE;
27         bool level_mutation = FALSE;
28         bool level_inc_stat = FALSE;
29         bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
30         int  old_lev = p_ptr->lev;
31
32         /* Hack -- lower limit */
33         if (p_ptr->exp < 0) p_ptr->exp = 0;
34         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
35         if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
36
37         /* Hack -- upper limit */
38         if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
39         if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
40         if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
41
42         /* Hack -- maintain "max" experience */
43         if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
44
45         /* Hack -- maintain "max max" experience */
46         if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
47
48         /* Redraw experience */
49         p_ptr->redraw |= (PR_EXP);
50
51         /* Handle stuff */
52         handle_stuff();
53
54
55         /* Lose levels while possible */
56         while ((p_ptr->lev > 1) &&
57                (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
58         {
59                 /* Lose a level */
60                 p_ptr->lev--;
61
62                 /* Update some stuff */
63                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
64
65                 /* Redraw some stuff */
66                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
67
68                 /* Window stuff */
69                 p_ptr->window |= (PW_PLAYER);
70
71                 /* Handle stuff */
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 */
103                 sound(SOUND_LEVEL);
104
105                 /* Message */
106 #ifdef JP
107 msg_format("レベル %d にようこそ。", p_ptr->lev);
108 #else
109                 msg_format("Welcome to level %d.", p_ptr->lev);
110
111 #endif
112
113                 /* Update some stuff */
114                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
115
116                 /* Redraw some stuff */
117                 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
118
119                 /* Window stuff */
120                 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
121
122                 /* HPとMPの上昇量を表示 */
123                 level_up = 1;
124
125                 /* Handle stuff */
126                 handle_stuff();
127
128                 level_up = 0;
129
130                 if (level_inc_stat)
131                 {
132                         if(!(p_ptr->max_plv % 10))
133                         {
134                                 int choice;
135                                 screen_save();
136                                 while(1)
137                                 {
138                                         int n;
139                                         char tmp[32];
140
141 #ifdef JP
142                                         cnv_stat(p_ptr->stat_max[0], tmp);
143                                         prt(format("        a) 腕力 (現在値 %s)", tmp), 2, 14);
144                                         cnv_stat(p_ptr->stat_max[1], tmp);
145                                         prt(format("        b) 知能 (現在値 %s)", tmp), 3, 14);
146                                         cnv_stat(p_ptr->stat_max[2], tmp);
147                                         prt(format("        c) 賢さ (現在値 %s)", tmp), 4, 14);
148                                         cnv_stat(p_ptr->stat_max[3], tmp);
149                                         prt(format("        d) 器用 (現在値 %s)", tmp), 5, 14);
150                                         cnv_stat(p_ptr->stat_max[4], tmp);
151                                         prt(format("        e) 耐久 (現在値 %s)", tmp), 6, 14);
152                                         cnv_stat(p_ptr->stat_max[5], tmp);
153                                         prt(format("        f) 魅力 (現在値 %s)", tmp), 7, 14);
154                                         prt("", 8, 14);
155                                         prt("        どの能力値を上げますか?", 1, 14);
156 #else
157                                         cnv_stat(p_ptr->stat_max[0], tmp);
158                                         prt(format("        a) Str (cur %s)", tmp), 2, 14);
159                                         cnv_stat(p_ptr->stat_max[1], tmp);
160                                         prt(format("        b) Int (cur %s)", tmp), 3, 14);
161                                         cnv_stat(p_ptr->stat_max[2], tmp);
162                                         prt(format("        c) Wis (cur %s)", tmp), 4, 14);
163                                         cnv_stat(p_ptr->stat_max[3], tmp);
164                                         prt(format("        d) Dex (cur %s)", tmp), 5, 14);
165                                         cnv_stat(p_ptr->stat_max[4], tmp);
166                                         prt(format("        e) Con (cur %s)", tmp), 6, 14);
167                                         cnv_stat(p_ptr->stat_max[5], tmp);
168                                         prt(format("        f) Chr (cur %s)", tmp), 7, 14);
169                                         prt("", 8, 14);
170                                         prt("        Which stat do you want to raise?", 1, 14);
171 #endif
172                                         while(1)
173                                         {
174                                                 choice = inkey();
175                                                 if ((choice >= 'a') && (choice <= 'f')) break;
176                                         }
177                                         for(n = 0; n < 6; n++)
178                                                 if (n != choice - 'a')
179                                                         prt("",n+2,14);
180                                         if (get_check(_("よろしいですか?", "Are you sure? "))) break;
181                                 }
182                                 do_inc_stat(choice - 'a');
183                                 screen_load();
184                         }
185                         else if(!(p_ptr->max_plv % 2))
186                                 do_inc_stat(randint0(6));
187                 }
188
189                 if (level_mutation)
190                 {
191                         msg_print(_("あなたは変わった気がする...", "You feel different..."));
192                         (void)gain_random_mutation(0);
193                         level_mutation = FALSE;
194                 }
195
196                 /*
197                  * 報酬でレベルが上ると再帰的に check_experience() が
198                  * 呼ばれるので順番を最後にする。
199                  */
200                 if (level_reward)
201                 {
202                         gain_level_reward(0);
203                         level_reward = FALSE;
204                 }
205
206                 /* Update some stuff */
207                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
208
209                 /* Redraw some stuff */
210                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
211
212                 /* Window stuff */
213                 p_ptr->window |= (PW_PLAYER | PW_SPELL);
214
215                 /* Handle stuff */
216                 handle_stuff();
217         }
218
219         /* Load an autopick preference file */
220         if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
221 }
222
223
224 /*!
225  * @brief モンスターを倒した際の財宝svalを返す
226  * @param r_idx 倒したモンスターの種族ID
227  * @return 財宝のsval
228  * @details
229  * Hack -- Return the "automatic coin type" of a monster race
230  * Used to allocate proper treasure when "Creeping coins" die
231  * XXX XXX XXX Note the use of actual "monster names"
232  */
233 static int get_coin_type(int r_idx)
234 {
235         /* Analyze monsters */
236         switch (r_idx)
237         {
238         case MON_COPPER_COINS: return 2;
239         case MON_SILVER_COINS: return 5;
240         case MON_GOLD_COINS: return 10;
241         case MON_MITHRIL_COINS:
242         case MON_MITHRIL_GOLEM: return 16;
243         case MON_ADAMANT_COINS: return 17;
244         }
245
246         /* Assume nothing */
247         return 0;
248 }
249
250
251 /*!
252  * @brief オブジェクトがクロークかどうかを判定する /
253  * Hack -- determine if a template is Cloak
254  * @param k_idx 判定したいオブジェクトのベースアイテムID
255  * @return オブジェクトがクロークならばTRUEを返す
256  */
257 static bool kind_is_cloak(int k_idx)
258 {
259         object_kind *k_ptr = &k_info[k_idx];
260
261         /* Analyze the item type */
262         if (k_ptr->tval == TV_CLOAK)
263         {
264                 return (TRUE);
265         }
266
267         /* Assume not good */
268         return (FALSE);
269 }
270
271
272 /*!
273  * @brief オブジェクトが竿状武器かどうかを判定する /
274  * Hack -- determine if a template is Polearm
275  * @param k_idx 判定したいオブジェクトのベースアイテムID
276  * @return オブジェクトが竿状武器ならばTRUEを返す
277  */
278 static bool kind_is_polearm(int k_idx)
279 {
280         object_kind *k_ptr = &k_info[k_idx];
281
282         /* Analyze the item type */
283         if (k_ptr->tval == TV_POLEARM)
284         {
285                 return (TRUE);
286         }
287
288         /* Assume not good */
289         return (FALSE);
290 }
291
292
293 /*!
294  * @brief オブジェクトが剣かどうかを判定する /
295  * Hack -- determine if a template is Sword
296  * @param k_idx 判定したいオブジェクトのベースアイテムID
297  * @return オブジェクトが剣ならばTRUEを返す
298  */
299 static bool kind_is_sword(int k_idx)
300 {
301         object_kind *k_ptr = &k_info[k_idx];
302
303         /* Analyze the item type */
304         if ((k_ptr->tval == TV_SWORD) && (k_ptr->sval > 2))
305         {
306                 return (TRUE);
307         }
308
309         /* Assume not good */
310         return (FALSE);
311 }
312
313
314 /*!
315  * @brief オブジェクトが魔法書かどうかを判定する /
316  * Hack -- determine if a template is Book
317  * @param k_idx 判定したいオブジェクトのベースアイテムID
318  * @return オブジェクトが魔法書ならばTRUEを返す
319  */
320 static bool kind_is_book(int k_idx)
321 {
322         object_kind *k_ptr = &k_info[k_idx];
323
324         /* Analyze the item type */
325         if ((k_ptr->tval >= TV_LIFE_BOOK) && (k_ptr->tval <= TV_CRUSADE_BOOK))
326         {
327                 return (TRUE);
328         }
329
330         /* Assume not good */
331         return (FALSE);
332 }
333
334
335 /*!
336  * @brief オブジェクトがベースアイテム時点でGOODかどうかを判定する /
337  * Hack -- determine if a template is Good book
338  * @param k_idx 判定したいオブジェクトのベースアイテムID
339  * @return オブジェクトがベースアイテム時点でGOODなアイテムならばTRUEを返す
340  */
341 static bool kind_is_good_book(int k_idx)
342 {
343         object_kind *k_ptr = &k_info[k_idx];
344
345         /* Analyze the item type */
346         if ((k_ptr->tval >= TV_LIFE_BOOK) && (k_ptr->tval <= TV_CRUSADE_BOOK) && (k_ptr->tval != TV_ARCANE_BOOK) && (k_ptr->sval > 1))
347         {
348                 return (TRUE);
349         }
350
351         /* Assume not good */
352         return (FALSE);
353 }
354
355
356 /*!
357  * @brief オブジェクトが鎧かどうかを判定する /
358  * Hack -- determine if a template is Armor
359  * @param k_idx 判定したいオブジェクトのベースアイテムID
360  * @return オブジェクトが鎧ならばTRUEを返す
361  */
362 static bool kind_is_armor(int k_idx)
363 {
364         object_kind *k_ptr = &k_info[k_idx];
365
366         /* Analyze the item type */
367         if (k_ptr->tval == TV_HARD_ARMOR)
368         {
369                 return (TRUE);
370         }
371
372         /* Assume not good */
373         return (FALSE);
374 }
375
376
377 /*!
378  * @brief オブジェクトが打撃武器かどうかを判定する /
379  * Hack -- determine if a template is hafted weapon
380  * @param k_idx 判定したいオブジェクトのベースアイテムID
381  * @return オブジェクトが打撃武器ならばTRUEを返す
382  */
383 static bool kind_is_hafted(int k_idx)
384 {
385         object_kind *k_ptr = &k_info[k_idx];
386
387         /* Analyze the item type */
388         if (k_ptr->tval == TV_HAFTED)
389         {
390                 return (TRUE);
391         }
392
393         /* Assume not good */
394         return (FALSE);
395 }
396
397 /*!
398  * @brief クエストを達成状態にする /
399  * @param quest_num 達成状態にしたいクエストのID
400  * @return なし
401  */
402 void complete_quest(int quest_num)
403 {
404         quest_type* const q_ptr = &quest[quest_num];
405
406         switch (q_ptr->type)
407         {
408         case QUEST_TYPE_RANDOM:
409                 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
410                 break;
411         default:
412                 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
413                 break;
414         }
415
416         q_ptr->status = QUEST_STATUS_COMPLETED;
417         q_ptr->complev = (byte)p_ptr->lev;
418         update_playtime();
419         q_ptr->comptime = playtime;
420
421         if (!(q_ptr->flags & QUEST_FLAG_SILENT))
422         {
423                 msg_print(_("クエストを達成した!", "You just completed your quest!"));
424                 msg_print(NULL);
425         }
426 }
427
428 /*!
429  * @brief 現在フロアに残っている敵モンスターの数を返す /
430  * @return 現在の敵モンスターの数
431  */
432 static int count_all_hostile_monsters(void)
433 {
434         int x, y;
435         int number_mon = 0;
436
437         for (x = 0; x < cur_wid; ++ x)
438         {
439                 for (y = 0; y < cur_hgt; ++ y)
440                 {
441                         int m_idx = cave[y][x].m_idx;
442
443                         if (m_idx > 0 && is_hostile(&m_list[m_idx]))
444                         {
445                                 ++ number_mon;
446                         }
447                 }
448         }
449
450         return number_mon;
451 }
452
453 /*!
454  * @brief 特定の敵を倒した際にクエスト達成処理 /
455  * Check for "Quest" completion when a quest monster is killed or charmed.
456  * @param m_ptr 撃破したモンスターの構造体参照ポインタ
457  * @return なし
458  */
459 void check_quest_completion(monster_type *m_ptr)
460 {
461         int y, x;
462
463         int quest_num;
464
465         bool create_stairs = FALSE;
466         bool reward = FALSE;
467
468         object_type forge;
469         object_type *q_ptr;
470
471         /* Get the location */
472         y = m_ptr->fy;
473         x = m_ptr->fx;
474
475         /* Inside a quest */
476         quest_num = p_ptr->inside_quest;                
477
478         /* Search for an active quest on this dungeon level */
479         if (!quest_num)
480         {
481                 int i;
482
483                 for (i = max_quests - 1; i > 0; i--)
484                 {
485                         quest_type* const q_ptr = &quest[i];
486                         
487                         /* Quest is not active */
488                         if (q_ptr->status != QUEST_STATUS_TAKEN)
489                                 continue;
490
491                         /* Quest is not a dungeon quest */
492                         if (q_ptr->flags & QUEST_FLAG_PRESET)
493                                 continue;
494
495                         /* Quest is not on this level */
496                         if ((q_ptr->level != dun_level) &&
497                             (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
498                                 continue;
499
500                         /* Not a "kill monster" quest */
501                         if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
502                             (q_ptr->type == QUEST_TYPE_FIND_EXIT))
503                                 continue;
504
505                         /* Interesting quest */
506                         if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
507                             (q_ptr->type == QUEST_TYPE_TOWER) ||
508                             (q_ptr->type == QUEST_TYPE_KILL_ALL))
509                                 break;
510
511                         /* Interesting quest */
512                         if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
513                              (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
514                              (q_ptr->type == QUEST_TYPE_RANDOM)) &&
515                              (q_ptr->r_idx == m_ptr->r_idx))
516                                 break;
517                 }
518
519                 quest_num = i;
520         }
521
522         /* Handle the current quest */
523         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
524         {
525                 /* Current quest */
526                 quest_type* const q_ptr = &quest[quest_num];
527
528                 switch (q_ptr->type)
529                 {
530                         case QUEST_TYPE_KILL_NUMBER:
531                         {
532                                 q_ptr->cur_num++;
533
534                                 if (q_ptr->cur_num >= q_ptr->num_mon)
535                                 {
536                                         complete_quest(quest_num);
537
538                                         q_ptr->cur_num = 0;
539                                 }
540                                 break;
541                         }
542                         case QUEST_TYPE_KILL_ALL:
543                         {
544                                 if (!is_hostile(m_ptr)) break;
545
546                                 if (count_all_hostile_monsters() == 1)
547                                 {
548                                         if (q_ptr->flags & QUEST_FLAG_SILENT)
549                                         {
550                                                 q_ptr->status = QUEST_STATUS_FINISHED;
551                                         }
552                                         else
553                                         {
554                                                 complete_quest(quest_num);
555                                         }
556                                 }
557                                 break;
558                         }
559                         case QUEST_TYPE_KILL_LEVEL:
560                         case QUEST_TYPE_RANDOM:
561                         {
562                                 /* Only count valid monsters */
563                                 if (q_ptr->r_idx != m_ptr->r_idx)
564                                         break;
565
566                                 q_ptr->cur_num++;
567
568                                 if (q_ptr->cur_num >= q_ptr->max_num)
569                                 {
570                                         complete_quest(quest_num);
571
572                                         if (!(q_ptr->flags & QUEST_FLAG_PRESET))
573                                         {
574                                                 create_stairs = TRUE;
575                                                 p_ptr->inside_quest = 0;
576                                         }
577
578                                         /* Finish the two main quests without rewarding */
579                                         if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
580                                         {
581                                                 q_ptr->status = QUEST_STATUS_FINISHED;
582                                         }
583
584                                         if (q_ptr->type == QUEST_TYPE_RANDOM)
585                                         {
586                                                 reward = TRUE;
587                                                 q_ptr->status = QUEST_STATUS_FINISHED;
588                                         }
589                                 }
590                                 break;
591                         }
592                         case QUEST_TYPE_KILL_ANY_LEVEL:
593                         {
594                                 q_ptr->cur_num++;
595                                 if (q_ptr->cur_num >= q_ptr->max_num)
596                                 {
597                                         complete_quest(quest_num);
598                                         q_ptr->cur_num = 0;
599                                 }
600                                 break;
601                         }
602                         case QUEST_TYPE_TOWER:
603                         {
604                                 if (!is_hostile(m_ptr)) break;
605
606                                 if (count_all_hostile_monsters() == 1)
607                                 {
608                                         q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
609
610                                         if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
611                                            (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
612                                            (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
613                                         {
614
615                                                 complete_quest(QUEST_TOWER1);
616                                         }
617                                 }
618                                 break;
619                         }
620                 }
621         }
622
623         /* Create a magical staircase */
624         if (create_stairs)
625         {
626                 int ny, nx;
627
628                 /* Stagger around */
629                 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT) )
630                 {
631                         /* Pick a location */
632                         scatter(&ny, &nx, y, x, 1, 0);
633
634                         /* Stagger */
635                         y = ny; x = nx;
636                 }
637
638                 /* Explain the staircase */
639                 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
640
641                 /* Create stairs down */
642                 cave_set_feat(y, x, feat_down_stair);
643
644                 /* Remember to update everything */
645                 p_ptr->update |= (PU_FLOW);
646         }
647
648         /*
649          * Drop quest reward
650          */
651         if (reward)
652         {
653                 int i;
654
655                 for (i = 0; i < (dun_level / 15)+1; i++)
656                 {
657                         /* Get local object */
658                         q_ptr = &forge;
659
660                         /* Wipe the object */
661                         object_wipe(q_ptr);
662
663                         /* Make a great object */
664                         make_object(q_ptr, AM_GOOD | AM_GREAT);
665
666                         /* Drop it in the dungeon */
667                         (void)drop_near(q_ptr, -1, y, x);
668                 }
669         }
670 }
671
672 /*!
673  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
674  * Check for "Quest" completion when a quest monster is killed or charmed.
675  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
676  * @return なし
677  */
678 void check_find_art_quest_completion(object_type *o_ptr)
679 {
680         int i;
681         /* Check if completed a quest */
682         for (i = 0; i < max_quests; i++)
683         {
684                 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
685                     (quest[i].status == QUEST_STATUS_TAKEN) &&
686                            (quest[i].k_idx == o_ptr->name1))
687                 {
688                         complete_quest(i);
689                 }
690         }
691 }
692
693
694 /*!
695  * @brief モンスターを撃破した際の述語メッセージを返す /
696  * Return monster death string
697  * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
698  * @return 撃破されたモンスターの述語
699  */
700 cptr extract_note_dies(monster_race *r_ptr)
701 {
702         /* Some monsters get "destroyed" */
703         if (!monster_living(r_ptr))
704         {
705                 int i;
706
707                 for (i = 0; i < 4; i++)
708                 {
709                         if (r_ptr->blow[i].method == RBM_EXPLODE)
710                         {
711                                 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
712                         }
713                 }
714                 return _("を倒した。", " is destroyed.");
715         }
716
717         /* Assume a default death */
718         return _("は死んだ。", " dies.");
719 }
720
721
722 /*!
723  * @brief モンスターが死亡した時の処理 /
724  * Handle the "death" of a monster.
725  * @param m_idx 死亡したモンスターのID
726  * @param drop_item TRUEならばモンスターのドロップ処理を行う
727  * @return 撃破されたモンスターの述語
728  * @details
729  * <pre>
730  * Disperse treasures centered at the monster location based on the
731  * various flags contained in the monster flags fields.
732  * Check for "Quest" completion when a quest monster is killed.
733  * Note that only the player can induce "monster_death()" on Uniques.
734  * Thus (for now) all Quest monsters should be Uniques.
735  * Note that monsters can now carry objects, and when a monster dies,
736  * it drops all of its objects, which may disappear in crowded rooms.
737  * </pre>
738  */
739 void monster_death(int m_idx, bool drop_item)
740 {
741         int i, j, y, x;
742
743         int dump_item = 0;
744         int dump_gold = 0;
745
746         int number = 0;
747
748         monster_type *m_ptr = &m_list[m_idx];
749
750         monster_race *r_ptr = &r_info[m_ptr->r_idx];
751
752         bool visible = ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE));
753
754         u32b mo_mode = 0L;
755
756         bool do_gold = (!(r_ptr->flags1 & RF1_ONLY_ITEM));
757         bool do_item = (!(r_ptr->flags1 & RF1_ONLY_GOLD));
758         bool cloned = (m_ptr->smart & SM_CLONED) ? TRUE : FALSE;
759         int force_coin = get_coin_type(m_ptr->r_idx);
760
761         object_type forge;
762         object_type *q_ptr;
763
764         bool drop_chosen_item = drop_item && !cloned && !p_ptr->inside_arena
765                 && !p_ptr->inside_battle && !is_pet(m_ptr);
766
767         /* The caster is dead? */
768         if (world_monster && world_monster == m_idx) world_monster = 0;
769
770         /* Notice changes in view */
771         if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
772         {
773                 /* Update some things */
774                 p_ptr->update |= (PU_MON_LITE);
775         }
776
777         /* Get the location */
778         y = m_ptr->fy;
779         x = m_ptr->fx;
780
781         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
782         {
783                 char m_name[80];
784
785                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
786                 do_cmd_write_nikki(NIKKI_NAMED_PET, 3, m_name);
787         }
788
789         /* Let monsters explode! */
790         for (i = 0; i < 4; i++)
791         {
792                 if (r_ptr->blow[i].method == RBM_EXPLODE)
793                 {
794                         int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
795                         int typ = mbe_info[r_ptr->blow[i].effect].explode_type;
796                         int d_dice = r_ptr->blow[i].d_dice;
797                         int d_side = r_ptr->blow[i].d_side;
798                         int damage = damroll(d_dice, d_side);
799
800                         project(m_idx, 3, y, x, damage, typ, flg, -1);
801                         break;
802                 }
803         }
804
805         if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
806         {
807                 choose_new_monster(m_idx, TRUE, MON_CHAMELEON);
808                 r_ptr = &r_info[m_ptr->r_idx];
809         }
810
811         /* Check for quest completion */
812         check_quest_completion(m_ptr);
813
814         /* Handle the possibility of player vanquishing arena combatant -KMW- */
815         if (p_ptr->inside_arena && !is_pet(m_ptr))
816         {
817                 p_ptr->exit_bldg = TRUE;
818
819                 if (p_ptr->arena_number > MAX_ARENA_MONS)
820                 {
821                         msg_print(_("素晴らしい!君こそ真の勝利者だ。", "You are a Genuine Champion!"));
822                 }
823                 else
824                 {
825                         msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion."));
826                 }
827
828                 if (arena_info[p_ptr->arena_number].tval)
829                 {
830                         /* Get local object */
831                         q_ptr = &forge;
832
833                         /* Prepare to make a prize */
834                         object_prep(q_ptr, lookup_kind(arena_info[p_ptr->arena_number].tval, arena_info[p_ptr->arena_number].sval));
835
836                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
837
838                         /* Drop it in the dungeon */
839                         (void)drop_near(q_ptr, -1, y, x);
840                 }
841
842                 if (p_ptr->arena_number > MAX_ARENA_MONS) p_ptr->arena_number++;
843                 p_ptr->arena_number++;
844                 if (record_arena)
845                 {
846                         char m_name[80];
847                         
848                         /* Extract monster name */
849                         monster_desc(m_name, m_ptr, MD_IGNORE_HALLU | MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
850                         
851                         do_cmd_write_nikki(NIKKI_ARENA, p_ptr->arena_number, m_name);
852                 }
853         }
854
855         if (m_idx == p_ptr->riding)
856         {
857                 if (rakuba(-1, FALSE))
858                 {
859                         msg_print(_("地面に落とされた。", "You have fallen from your riding pet."));
860                 }
861         }
862
863         /* Drop a dead corpse? */
864         if (one_in_(r_ptr->flags1 & RF1_UNIQUE ? 1 : 4) &&
865             (r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) &&
866             !(p_ptr->inside_arena || p_ptr->inside_battle || cloned || ((m_ptr->r_idx == today_mon) && is_pet(m_ptr))))
867         {
868                 /* Assume skeleton */
869                 bool corpse = FALSE;
870
871                 /*
872                  * We cannot drop a skeleton? Note, if we are in this check,
873                  * we *know* we can drop at least a corpse or a skeleton
874                  */
875                 if (!(r_ptr->flags9 & RF9_DROP_SKELETON))
876                         corpse = TRUE;
877                 else if ((r_ptr->flags9 & RF9_DROP_CORPSE) && (r_ptr->flags1 & RF1_UNIQUE))
878                         corpse = TRUE;
879
880                 /* Else, a corpse is more likely unless we did a "lot" of damage */
881                 else if (r_ptr->flags9 & RF9_DROP_CORPSE)
882                 {
883                         /* Lots of damage in one blow */
884                         if ((0 - ((m_ptr->maxhp) / 4)) > m_ptr->hp)
885                         {
886                                 if (one_in_(5)) corpse = TRUE;
887                         }
888                         else
889                         {
890                                 if (!one_in_(5)) corpse = TRUE;
891                         }
892                 }
893
894                 /* Get local object */
895                 q_ptr = &forge;
896
897                 /* Prepare to make an object */
898                 object_prep(q_ptr, lookup_kind(TV_CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
899
900                 apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
901
902                 q_ptr->pval = m_ptr->r_idx;
903
904                 /* Drop it in the dungeon */
905                 (void)drop_near(q_ptr, -1, y, x);
906         }
907
908         /* Drop objects being carried */
909         monster_drop_carried_objects(m_ptr);
910
911         if (r_ptr->flags1 & RF1_DROP_GOOD) mo_mode |= AM_GOOD;
912         if (r_ptr->flags1 & RF1_DROP_GREAT) mo_mode |= AM_GREAT;
913
914         switch (m_ptr->r_idx)
915         {
916         case MON_PINK_HORROR:
917                 /* Pink horrors are replaced with 2 Blue horrors */
918                 if (!(p_ptr->inside_arena || p_ptr->inside_battle))
919                 {
920                         bool notice = FALSE;
921
922                         for (i = 0; i < 2; i++)
923                         {
924                                 int wy = y, wx = x;
925                                 bool pet = is_pet(m_ptr);
926                                 u32b mode = 0L;
927
928                                 if (pet) mode |= PM_FORCE_PET;
929
930                                 if (summon_specific((pet ? -1 : m_idx), wy, wx, 100, SUMMON_BLUE_HORROR, mode))
931                                 {
932                                         if (player_can_see_bold(wy, wx))
933                                                 notice = TRUE;
934                                 }
935                         }
936
937                         if (notice)
938                                 msg_print(_("ピンク・ホラーは分裂した!", "The Pink horror divides!"));
939                 }
940                 break;
941
942         case MON_BLOODLETTER:
943                 /* Bloodletters of Khorne may drop a blade of chaos */
944                 if (drop_chosen_item && (randint1(100) < 15))
945                 {
946                         /* Get local object */
947                         q_ptr = &forge;
948
949                         /* Prepare to make a Blade of Chaos */
950                         object_prep(q_ptr, lookup_kind(TV_SWORD, SV_BLADE_OF_CHAOS));
951
952                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART | mo_mode);
953
954                         /* Drop it in the dungeon */
955                         (void)drop_near(q_ptr, -1, y, x);
956                 }
957                 break;
958
959         case MON_RAAL:
960                 if (drop_chosen_item && (dun_level > 9))
961                 {
962                         /* Get local object */
963                         q_ptr = &forge;
964
965                         /* Wipe the object */
966                         object_wipe(q_ptr);
967
968                         /* Activate restriction */
969                         if ((dun_level > 49) && one_in_(5))
970                                 get_obj_num_hook = kind_is_good_book;
971                         else
972                                 get_obj_num_hook = kind_is_book;
973
974                         /* Make a book */
975                         make_object(q_ptr, mo_mode);
976
977                         /* Drop it in the dungeon */
978                         (void)drop_near(q_ptr, -1, y, x);
979                 }
980                 break;
981
982         case MON_DAWN:
983                 /*
984                  * Mega^3-hack: killing a 'Warrior of the Dawn' is likely to
985                  * spawn another in the fallen one's place!
986                  */
987                 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
988                 {
989                         if (!one_in_(7))
990                         {
991                                 int wy = y, wx = x;
992                                 int attempts = 100;
993                                 bool pet = is_pet(m_ptr);
994
995                                 do
996                                 {
997                                         scatter(&wy, &wx, y, x, 20, 0);
998                                 }
999                                 while (!(in_bounds(wy, wx) && cave_empty_bold2(wy, wx)) && --attempts);
1000
1001                                 if (attempts > 0)
1002                                 {
1003                                         u32b mode = 0L;
1004                                         if (pet) mode |= PM_FORCE_PET;
1005
1006                                         if (summon_specific((pet ? -1 : m_idx), wy, wx, 100, SUMMON_DAWN, mode))
1007                                         {
1008                                                 if (player_can_see_bold(wy, wx))
1009                                                         msg_print(_("新たな戦士が現れた!", "A new warrior steps forth!"));
1010                                         }
1011                                 }
1012                         }
1013                 }
1014                 break;
1015
1016         case MON_UNMAKER:
1017                 /* One more ultra-hack: An Unmaker goes out with a big bang! */
1018                 {
1019                         int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
1020                         (void)project(m_idx, 6, y, x, 100, GF_CHAOS, flg, -1);
1021                 }
1022                 break;
1023
1024         case MON_UNICORN_ORD:
1025         case MON_MORGOTH:
1026         case MON_ONE_RING:
1027                 /* Reward for "lazy" player */
1028                 if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
1029                 {
1030                         int a_idx = 0;
1031                         artifact_type *a_ptr = NULL;
1032
1033                         if (!drop_chosen_item) break;
1034
1035                         do
1036                         {
1037                                 switch (randint0(3))
1038                                 {
1039                                 case 0:
1040                                         a_idx = ART_NAMAKE_HAMMER;
1041                                         break;
1042                                 case 1:
1043                                         a_idx = ART_NAMAKE_BOW;
1044                                         break;
1045                                 case 2:
1046                                         a_idx = ART_NAMAKE_ARMOR;
1047                                         break;
1048                                 }
1049
1050                                 a_ptr = &a_info[a_idx];
1051                         }
1052                         while (a_ptr->cur_num);
1053
1054                         /* Create the artifact */
1055                         if (create_named_art(a_idx, y, x))
1056                         {
1057                                 a_ptr->cur_num = 1;
1058
1059                                 /* Hack -- Memorize location of artifact in saved floors */
1060                                 if (character_dungeon) a_ptr->floor_id = p_ptr->floor_id;
1061                         }
1062                         else if (!preserve_mode) a_ptr->cur_num = 1;
1063                 }
1064                 break;
1065
1066         case MON_SERPENT:
1067                 if (!drop_chosen_item) break;
1068
1069                 /* Get local object */
1070                 q_ptr = &forge;
1071
1072                 /* Mega-Hack -- Prepare to make "Grond" */
1073                 object_prep(q_ptr, lookup_kind(TV_HAFTED, SV_GROND));
1074
1075                 /* Mega-Hack -- Mark this item as "Grond" */
1076                 q_ptr->name1 = ART_GROND;
1077
1078                 /* Mega-Hack -- Actually create "Grond" */
1079                 apply_magic(q_ptr, -1, AM_GOOD | AM_GREAT);
1080
1081                 /* Drop it in the dungeon */
1082                 (void)drop_near(q_ptr, -1, y, x);
1083
1084                 /* Get local object */
1085                 q_ptr = &forge;
1086
1087                 /* Mega-Hack -- Prepare to make "Chaos" */
1088                 object_prep(q_ptr, lookup_kind(TV_CROWN, SV_CHAOS));
1089
1090                 /* Mega-Hack -- Mark this item as "Chaos" */
1091                 q_ptr->name1 = ART_CHAOS;
1092
1093                 /* Mega-Hack -- Actually create "Chaos" */
1094                 apply_magic(q_ptr, -1, AM_GOOD | AM_GREAT);
1095
1096                 /* Drop it in the dungeon */
1097                 (void)drop_near(q_ptr, -1, y, x);
1098                 break;
1099
1100         case MON_B_DEATH_SWORD:
1101                 if (drop_chosen_item)
1102                 {
1103                         /* Get local object */
1104                         q_ptr = &forge;
1105
1106                         /* Prepare to make a broken sword */
1107                         object_prep(q_ptr, lookup_kind(TV_SWORD, randint1(2)));
1108
1109                         /* Drop it in the dungeon */
1110                         (void)drop_near(q_ptr, -1, y, x);
1111                 }
1112                 break;
1113
1114         case MON_A_GOLD:
1115         case MON_A_SILVER:
1116                 if (drop_chosen_item && ((m_ptr->r_idx == MON_A_GOLD) ||
1117                      ((m_ptr->r_idx == MON_A_SILVER) && (r_ptr->r_akills % 5 == 0))))
1118                 {
1119                         /* Get local object */
1120                         q_ptr = &forge;
1121
1122                         /* Prepare to make a Can of Toys */
1123                         object_prep(q_ptr, lookup_kind(TV_CHEST, SV_CHEST_KANDUME));
1124
1125                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
1126
1127                         /* Drop it in the dungeon */
1128                         (void)drop_near(q_ptr, -1, y, x);
1129                 }
1130                 break;
1131
1132         case MON_ROLENTO:
1133                 {
1134                         int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
1135                         (void)project(m_idx, 3, y, x, damroll(20, 10), GF_FIRE, flg, -1);
1136                 }
1137                 break;
1138
1139         default:
1140                 if (!drop_chosen_item) break;
1141
1142                 switch (r_ptr->d_char)
1143                 {
1144                 case '(':
1145                         if (dun_level > 0)
1146                         {
1147                                 /* Get local object */
1148                                 q_ptr = &forge;
1149
1150                                 /* Wipe the object */
1151                                 object_wipe(q_ptr);
1152
1153                                 /* Activate restriction */
1154                                 get_obj_num_hook = kind_is_cloak;
1155
1156                                 /* Make a cloak */
1157                                 make_object(q_ptr, mo_mode);
1158
1159                                 /* Drop it in the dungeon */
1160                                 (void)drop_near(q_ptr, -1, y, x);
1161                         }
1162                         break;
1163
1164                 case '/':
1165                         if (dun_level > 4)
1166                         {
1167                                 /* Get local object */
1168                                 q_ptr = &forge;
1169
1170                                 /* Wipe the object */
1171                                 object_wipe(q_ptr);
1172
1173                                 /* Activate restriction */
1174                                 get_obj_num_hook = kind_is_polearm;
1175
1176                                 /* Make a poleweapon */
1177                                 make_object(q_ptr, mo_mode);
1178
1179                                 /* Drop it in the dungeon */
1180                                 (void)drop_near(q_ptr, -1, y, x);
1181                         }
1182                         break;
1183
1184                 case '[':
1185                         if (dun_level > 19)
1186                         {
1187                                 /* Get local object */
1188                                 q_ptr = &forge;
1189
1190                                 /* Wipe the object */
1191                                 object_wipe(q_ptr);
1192
1193                                 /* Activate restriction */
1194                                 get_obj_num_hook = kind_is_armor;
1195
1196                                 /* Make a hard armor */
1197                                 make_object(q_ptr, mo_mode);
1198
1199                                 /* Drop it in the dungeon */
1200                                 (void)drop_near(q_ptr, -1, y, x);
1201                         }
1202                         break;
1203
1204                 case '\\':
1205                         if (dun_level > 4)
1206                         {
1207                                 /* Get local object */
1208                                 q_ptr = &forge;
1209
1210                                 /* Wipe the object */
1211                                 object_wipe(q_ptr);
1212
1213                                 /* Activate restriction */
1214                                 get_obj_num_hook = kind_is_hafted;
1215
1216                                 /* Make a hafted weapon */
1217                                 make_object(q_ptr, mo_mode);
1218
1219                                 /* Drop it in the dungeon */
1220                                 (void)drop_near(q_ptr, -1, y, x);
1221                         }
1222                         break;
1223
1224                 case '|':
1225                         if (m_ptr->r_idx != MON_STORMBRINGER)
1226                         {
1227                                 /* Get local object */
1228                                 q_ptr = &forge;
1229
1230                                 /* Wipe the object */
1231                                 object_wipe(q_ptr);
1232
1233                                 /* Activate restriction */
1234                                 get_obj_num_hook = kind_is_sword;
1235
1236                                 /* Make a sword */
1237                                 make_object(q_ptr, mo_mode);
1238
1239                                 /* Drop it in the dungeon */
1240                                 (void)drop_near(q_ptr, -1, y, x);
1241                         }
1242                         break;
1243                 }
1244                 break;
1245         }
1246
1247         /* Mega-Hack -- drop fixed items */
1248         if (drop_chosen_item)
1249         {
1250                 int a_idx = 0;
1251                 int chance = 0;
1252
1253                 switch (m_ptr->r_idx)
1254                 {
1255                 case MON_OBERON:
1256                         if (one_in_(3))
1257                         {
1258                                 a_idx = ART_JUDGE;
1259                                 chance = 33;
1260                         }
1261                         else
1262                         {
1263                                 a_idx = ART_AMBER;
1264                                 chance = 50;
1265                         }
1266                         break;
1267
1268                 case MON_GHB:
1269                         a_idx = ART_GHB;
1270                         chance = 100;
1271                         break;
1272
1273                 case MON_STORMBRINGER:
1274                         a_idx = ART_STORMBRINGER;
1275                         chance = 100;
1276                         break;
1277
1278                 case MON_ECHIZEN:
1279                         a_idx = ART_CRIMSON;
1280                         chance = 50;
1281                         break;
1282
1283                 case MON_GANDALF:
1284                         a_idx = ART_ICANUS;
1285                         chance = 20;
1286                         break;
1287
1288                 case MON_OROCHI:
1289                         a_idx = ART_KUSANAGI;
1290                         chance = 25;
1291                         break;
1292
1293                 case MON_DWORKIN:
1294                         a_idx = ART_JUDGE;
1295                         chance = 20;
1296                         break;
1297
1298                 case MON_SAURON:
1299                         if (one_in_(10))
1300                         {
1301                                 a_idx = ART_POWER;
1302                                 chance = 100;
1303                         }
1304                         else
1305                         {
1306                                 a_idx = ART_AHO;
1307                                 chance = 100;
1308                         }
1309                         break;
1310
1311                 case MON_BRAND:
1312                         if (!one_in_(3))
1313                         {
1314                                 a_idx = ART_BRAND;
1315                                 chance = 25;
1316                         }
1317                         else
1318                         {
1319                                 a_idx = ART_WEREWINDLE;
1320                                 chance = 33;
1321                         }
1322                         break;
1323
1324                 case MON_CORWIN:
1325                         if (!one_in_(3))
1326                         {
1327                                 a_idx = ART_GRAYSWANDIR;
1328                                 chance = 33;
1329                         }
1330                         else
1331                         {
1332                                 a_idx = ART_CORWIN;
1333                                 chance = 33;
1334                         }
1335                         break;
1336
1337                 case MON_SURTUR:
1338                         if (!one_in_(3))
1339                         {
1340                                 a_idx = ART_TWILIGHT;
1341                                 chance = 100;
1342                         }
1343                         else
1344                         {
1345                                 a_idx = ART_ORB_OF_FATE;
1346                                 chance = 100;
1347                         }
1348                         break;
1349
1350                 case MON_SARUMAN:
1351                         a_idx = ART_ELENDIL;
1352                         chance = 33;
1353                         break;
1354
1355                 case MON_FIONA:
1356                         a_idx = ART_FIONA;
1357                         chance = 50;
1358                         break;
1359
1360                 case MON_JULIAN:
1361                         a_idx = ART_JULIAN;
1362                         chance = 45;
1363                         break;
1364
1365                 case MON_KLING:
1366                         a_idx = ART_DESTINY;
1367                         chance = 40;
1368                         break;
1369
1370                 case MON_GOEMON:
1371                         a_idx = ART_ZANTETSU;
1372                         chance = 100;
1373                         break;
1374
1375                 case MON_HAGEN:
1376                         a_idx = ART_HAGEN;
1377                         chance = 66;
1378                         break;
1379
1380                 case MON_CAINE:
1381                         a_idx = ART_CAINE;
1382                         chance = 50;
1383                         break;
1384
1385                 case MON_BULLGATES:
1386                         a_idx = ART_WINBLOWS;
1387                         chance = 66;
1388                         break;
1389
1390                 case MON_LUNGORTHIN:
1391                         a_idx = ART_CALRIS;
1392                         chance = 50;
1393                         break;
1394
1395                 case MON_JACK_SHADOWS:
1396                         a_idx = ART_JACK;
1397                         chance = 15;
1398                         break;
1399
1400                 case MON_DIO:
1401                         a_idx = ART_STONEMASK;
1402                         chance = 20;
1403                         break;
1404
1405                 case MON_BELD:
1406                         a_idx = ART_SOULCRUSH;
1407                         chance = 10;
1408                         break;
1409
1410                 case MON_PIP:
1411                         a_idx = ART_EXCALIBUR_J;
1412                         chance = 50;
1413                         break;
1414
1415                 case MON_SHUTEN:
1416                         a_idx = ART_SHUTEN_DOJI;
1417                         chance = 33;
1418                         break;
1419
1420                 case MON_GOTHMOG:
1421                         a_idx = ART_GOTHMOG;
1422                         chance = 33;
1423                         break;
1424
1425                 case MON_FUNDIN:
1426                         a_idx = ART_FUNDIN;
1427                         chance = 5;
1428                         break;
1429
1430                 case MON_ROBIN_HOOD:
1431                         a_idx = ART_ROBIN_HOOD;
1432                         chance = 5;
1433                         break;
1434
1435                 case MON_KOGAN:
1436                         a_idx = ART_NANACHO;
1437                         chance = 80;
1438                         break;
1439
1440                 }
1441
1442                 if ((a_idx > 0) && ((randint0(100) < chance) || p_ptr->wizard))
1443                 {
1444                         artifact_type *a_ptr = &a_info[a_idx];
1445
1446                         if (!a_ptr->cur_num)
1447                         {
1448                                 /* Create the artifact */
1449                                 if (create_named_art(a_idx, y, x))
1450                                 {
1451                                         a_ptr->cur_num = 1;
1452
1453                                         /* Hack -- Memorize location of artifact in saved floors */
1454                                         if (character_dungeon) a_ptr->floor_id = p_ptr->floor_id;
1455                                 }
1456                                 else if (!preserve_mode) a_ptr->cur_num = 1;
1457                         }
1458                 }
1459
1460                 if ((r_ptr->flags7 & RF7_GUARDIAN) && (d_info[dungeon_type].final_guardian == m_ptr->r_idx))
1461                 {
1462                         int k_idx = d_info[dungeon_type].final_object ? d_info[dungeon_type].final_object
1463                                 : lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
1464
1465                         if (d_info[dungeon_type].final_artifact)
1466                         {
1467                                 int a_idx = d_info[dungeon_type].final_artifact;
1468                                 artifact_type *a_ptr = &a_info[a_idx];
1469
1470                                 if (!a_ptr->cur_num)
1471                                 {
1472                                         /* Create the artifact */
1473                                         if (create_named_art(a_idx, y, x))
1474                                         {
1475                                                 a_ptr->cur_num = 1;
1476
1477                                                 /* Hack -- Memorize location of artifact in saved floors */
1478                                                 if (character_dungeon) a_ptr->floor_id = p_ptr->floor_id;
1479                                         }
1480                                         else if (!preserve_mode) a_ptr->cur_num = 1;
1481
1482                                         /* Prevent rewarding both artifact and "default" object */
1483                                         if (!d_info[dungeon_type].final_object) k_idx = 0;
1484                                 }
1485                         }
1486
1487                         if (k_idx)
1488                         {
1489                                 /* Get local object */
1490                                 q_ptr = &forge;
1491
1492                                 /* Prepare to make a reward */
1493                                 object_prep(q_ptr, k_idx);
1494
1495                                 apply_magic(q_ptr, object_level, AM_NO_FIXED_ART | AM_GOOD);
1496
1497                                 /* Drop it in the dungeon */
1498                                 (void)drop_near(q_ptr, -1, y, x);
1499                         }
1500                         msg_format(_("あなたは%sを制覇した!", "You have conquered %s!"),d_name+d_info[dungeon_type].name);
1501                 }
1502         }
1503
1504         /* Determine how much we can drop */
1505         if ((r_ptr->flags1 & RF1_DROP_60) && (randint0(100) < 60)) number++;
1506         if ((r_ptr->flags1 & RF1_DROP_90) && (randint0(100) < 90)) number++;
1507         if  (r_ptr->flags1 & RF1_DROP_1D2) number += damroll(1, 2);
1508         if  (r_ptr->flags1 & RF1_DROP_2D2) number += damroll(2, 2);
1509         if  (r_ptr->flags1 & RF1_DROP_3D2) number += damroll(3, 2);
1510         if  (r_ptr->flags1 & RF1_DROP_4D2) number += damroll(4, 2);
1511
1512         if (cloned && !(r_ptr->flags1 & RF1_UNIQUE))
1513                 number = 0; /* Clones drop no stuff unless Cloning Pits */
1514
1515         if (is_pet(m_ptr) || p_ptr->inside_battle || p_ptr->inside_arena)
1516                 number = 0; /* Pets drop no stuff */
1517         if (!drop_item && (r_ptr->d_char != '$')) number = 0;
1518         
1519         if((r_ptr->flags2 & (RF2_MULTIPLY)) && (r_ptr->r_akills > 1024))
1520                 number = 0; /* Limit of Multiply monster drop */
1521
1522         /* Hack -- handle creeping coins */
1523         coin_type = force_coin;
1524
1525         /* Average dungeon and monster levels */
1526         object_level = (dun_level + r_ptr->level) / 2;
1527
1528         /* Drop some objects */
1529         for (j = 0; j < number; j++)
1530         {
1531                 /* Get local object */
1532                 q_ptr = &forge;
1533
1534                 /* Wipe the object */
1535                 object_wipe(q_ptr);
1536
1537                 /* Make Gold */
1538                 if (do_gold && (!do_item || (randint0(100) < 50)))
1539                 {
1540                         /* Make some gold */
1541                         if (!make_gold(q_ptr)) continue;
1542
1543                         /* XXX XXX XXX */
1544                         dump_gold++;
1545                 }
1546
1547                 /* Make Object */
1548                 else
1549                 {
1550                         /* Make an object */
1551                         if (!make_object(q_ptr, mo_mode)) continue;
1552
1553                         /* XXX XXX XXX */
1554                         dump_item++;
1555                 }
1556
1557                 /* Drop it in the dungeon */
1558                 (void)drop_near(q_ptr, -1, y, x);
1559         }
1560
1561         /* Reset the object level */
1562         object_level = base_level;
1563
1564         /* Reset "coin" type */
1565         coin_type = 0;
1566
1567
1568         /* Take note of any dropped treasure */
1569         if (visible && (dump_item || dump_gold))
1570         {
1571                 /* Take notes on treasure */
1572                 lore_treasure(m_idx, dump_item, dump_gold);
1573         }
1574
1575         /* Only process "Quest Monsters" */
1576         if (!(r_ptr->flags1 & RF1_QUESTOR)) return;
1577         if (p_ptr->inside_battle) return;
1578
1579         /* Winner? */
1580         if ((m_ptr->r_idx == MON_SERPENT) && !cloned)
1581         {
1582                 /* Total winner */
1583                 p_ptr->total_winner = TRUE;
1584
1585                 /* Redraw the "title" */
1586                 p_ptr->redraw |= (PR_TITLE);
1587
1588                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("見事に変愚蛮怒の勝利者となった!", "become *WINNER* of Hengband finely!"));
1589
1590                 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) || (p_ptr->muta2 & MUT2_CHAOS_GIFT))
1591                 {
1592                         msg_format(_("%sからの声が響いた。", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
1593                         msg_print(_("『よくやった、定命の者よ!』", "'Thou art donst well, mortal!'"));
1594                 }
1595
1596                 /* Congratulations */
1597                 msg_print(_("*** おめでとう ***", "*** CONGRATULATIONS ***"));
1598                 msg_print(_("あなたはゲームをコンプリートしました。", "You have won the game!"));
1599                 msg_print(_("準備が整ったら引退(自殺コマンド)しても結構です。", "You may retire (commit suicide) when you are ready."));
1600         }
1601 }
1602
1603 /*!
1604  * @brief モンスターに与えたダメージの修正処理 /
1605  * Modify the physical damage done to the monster.
1606  * @param m_ptr ダメージを受けるモンスターの構造体参照ポインタ
1607  * @param dam ダメージ基本値
1608  * @param is_psy_spear 攻撃手段が光の剣ならばTRUE
1609  * @return 修正を行った結果のダメージ量
1610  * @details
1611  * <pre>
1612  * (for example when it's invulnerable or shielded)
1613  * ToDo: Accept a damage-type to calculate the modified damage from
1614  * things like fire, frost, lightning, poison, ... attacks.
1615  * "type" is not yet used and should be 0.
1616  * </pre>
1617  */
1618 int mon_damage_mod(monster_type *m_ptr, int dam, bool is_psy_spear)
1619 {
1620         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1621
1622         if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
1623         {
1624                 dam /= 100;
1625                 if ((dam == 0) && one_in_(3)) dam = 1;
1626         }
1627
1628         if (MON_INVULNER(m_ptr))
1629         {
1630                 if (is_psy_spear)
1631                 {
1632                         if (!p_ptr->blind && is_seen(m_ptr))
1633                         {
1634                                 msg_print(_("バリアを切り裂いた!", "The barrier is penetrated!"));
1635                         }
1636                 }
1637                 else if (!one_in_(PENETRATE_INVULNERABILITY))
1638                 {
1639                         return (0);
1640                 }
1641         }
1642         return (dam);
1643 }
1644
1645
1646 /*!
1647  * @brief モンスターに与えたダメージを元に経験値を加算する /
1648  * Calculate experience point to be get
1649  * @param dam 与えたダメージ量
1650  * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
1651  * @return なし
1652  * @details
1653  * <pre>
1654  * Even the 64 bit operation is not big enough to avoid overflaw
1655  * unless we carefully choose orders of multiplication and division.
1656  * Get the coefficient first, and multiply (potentially huge) base
1657  * experience point of a monster later.
1658  * </pre>
1659  */
1660 static void get_exp_from_mon(int dam, monster_type *m_ptr)
1661 {
1662         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1663
1664         s32b new_exp;
1665         u32b new_exp_frac;
1666         s32b div_h;
1667         u32b div_l;
1668
1669         if (!m_ptr->r_idx) return;
1670         if (is_pet(m_ptr) || p_ptr->inside_battle) return;
1671
1672         /*
1673          * - Ratio of monster's level to player's level effects
1674          * - Varying speed effects
1675          * - Get a fraction in proportion of damage point
1676          */
1677         new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
1678         new_exp_frac = 0;
1679         div_h = 0L;
1680         div_l = (p_ptr->max_plv+2) * SPEED_TO_ENERGY(r_ptr->speed);
1681
1682         /* Use (average maxhp * 2) as a denominator */
1683         if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
1684                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
1685         else
1686                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
1687
1688         /* Special penalty in the wilderness */
1689         if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
1690                 s64b_mul(&div_h, &div_l, 0, 5);
1691
1692         /* Do division first to prevent overflaw */
1693         s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
1694
1695         /* Special penalty for mutiply-monster */
1696         if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
1697         {
1698                 int monnum_penarty = r_ptr->r_akills / 400;
1699                 if (monnum_penarty > 8) monnum_penarty = 8;
1700
1701                 while (monnum_penarty--)
1702                 {
1703                         /* Divide by 4 */
1704                         s64b_RSHIFT(new_exp, new_exp_frac, 2);
1705                 }
1706         }
1707         
1708         /* Special penalty for rest_and_shoot exp scum */
1709         if ((m_ptr->dealt_damage > (u32b)m_ptr->max_maxhp) && (m_ptr->hp >= 0))
1710         {
1711                 int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
1712                 if (over_damage > 32) over_damage = 32;
1713
1714                 while (over_damage--)
1715                 {
1716                         /* 9/10 for once */
1717                         s64b_mul(&new_exp, &new_exp_frac, 0, 9);
1718                         s64b_div(&new_exp, &new_exp_frac, 0, 10);
1719                 }
1720         }
1721
1722         /* Finally multiply base experience point of the monster */
1723         s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
1724
1725         /* Gain experience */
1726         gain_exp_64(new_exp, new_exp_frac);
1727 }
1728
1729
1730 /*!
1731  * @brief モンスターのHPをダメージに応じて減算する /
1732  * Decreases monsters hit points, handling monster death.
1733  * @param dam 与えたダメージ量
1734  * @param m_idx ダメージを与えたモンスターのID
1735  * @param fear ダメージによってモンスターが恐慌状態に陥ったならばTRUEを返す
1736  * @param note モンスターが倒された際の特別なメッセージ述語
1737  * @return なし
1738  * @details
1739  * <pre>
1740  * We return TRUE if the monster has been killed (and deleted).
1741  * We announce monster death (using an optional "death message"
1742  * if given, and a otherwise a generic killed/destroyed message).
1743  * Only "physical attacks" can induce the "You have slain" message.
1744  * Missile and Spell attacks will induce the "dies" message, or
1745  * various "specialized" messages.  Note that "You have destroyed"
1746  * and "is destroyed" are synonyms for "You have slain" and "dies".
1747  * Hack -- unseen monsters yield "You have killed it." message.
1748  * Added fear (DGK) and check whether to print fear messages -CWS
1749  * Made name, sex, and capitalization generic -BEN-
1750  * As always, the "ghost" processing is a total hack.
1751  * Hack -- we "delay" fear messages by passing around a "fear" flag.
1752  * XXX XXX XXX Consider decreasing monster experience over time, say,
1753  * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
1754  * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1755  * monster worth more than subsequent monsters.  This would also need
1756  * to induce changes in the monster recall code.
1757  * </pre>
1758  */
1759 bool mon_take_hit(int m_idx, int dam, bool *fear, cptr note)
1760 {
1761         monster_type    *m_ptr = &m_list[m_idx];
1762         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1763
1764         monster_type    exp_mon;
1765
1766         /* Innocent until proven otherwise */
1767         bool        innocent = TRUE, thief = FALSE;
1768         int         i;
1769         int         expdam;
1770         int                     dealt_damage;
1771
1772         (void)COPY(&exp_mon, m_ptr, monster_type);
1773         
1774         expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1775
1776         get_exp_from_mon(expdam, &exp_mon);
1777
1778         /* Genocided by chaos patron */
1779         if (!m_ptr->r_idx) m_idx = 0;
1780         
1781         /* Redraw (later) if needed */
1782         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1783         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1784
1785         /* Wake it up */
1786         (void)set_monster_csleep(m_idx, 0);
1787
1788         /* Hack - Cancel any special player stealth magics. -LM- */
1789         if (p_ptr->special_defense & NINJA_S_STEALTH)
1790         {
1791                 set_superstealth(FALSE);
1792         }
1793
1794         /* Genocided by chaos patron */
1795         if (!m_idx) return TRUE;
1796         
1797         /* Remember dealt_damage before this attack*/
1798         dealt_damage = m_ptr->dealt_damage;
1799
1800         /* Hurt it */
1801         m_ptr->hp -= dam;
1802         
1803         m_ptr->dealt_damage += dam;
1804         if(m_ptr->dealt_damage > (u32b)m_ptr->max_maxhp * 100) m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
1805         if (p_ptr->wizard)
1806         {
1807                 msg_format( _("合計%d/%dのダメージを与えた。","You do %d (out of %d) damage."),
1808                                         m_ptr->dealt_damage, m_ptr->maxhp);
1809         }
1810
1811         /* It is dead now */
1812         if (m_ptr->hp < 0)
1813         {
1814                 char m_name[80];
1815
1816                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1817                 {
1818                         /* You might have unmasked Tanuki first time */
1819                         r_ptr = &r_info[m_ptr->r_idx];
1820                         m_ptr->ap_r_idx = m_ptr->r_idx;
1821                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1822                 }
1823
1824                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1825                 {
1826                         /* You might have unmasked Chameleon first time */
1827                         r_ptr = real_r_ptr(m_ptr);
1828                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1829                 }
1830
1831                 if (!(m_ptr->smart & SM_CLONED))
1832                 {
1833                         /* When the player kills a Unique, it stays dead */
1834                         if (r_ptr->flags1 & RF1_UNIQUE)
1835                         {
1836                                 r_ptr->max_num = 0;
1837
1838                                 /* Mega-Hack -- Banor & Lupart */
1839                                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1840                                 {
1841                                         r_info[MON_BANORLUPART].max_num = 0;
1842                                         r_info[MON_BANORLUPART].r_pkills++;
1843                                         r_info[MON_BANORLUPART].r_akills++;
1844                                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1845                                 }
1846                                 else if (m_ptr->r_idx == MON_BANORLUPART)
1847                                 {
1848                                         r_info[MON_BANOR].max_num = 0;
1849                                         r_info[MON_BANOR].r_pkills++;
1850                                         r_info[MON_BANOR].r_akills++;
1851                                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1852                                         r_info[MON_LUPART].max_num = 0;
1853                                         r_info[MON_LUPART].r_pkills++;
1854                                         r_info[MON_LUPART].r_akills++;
1855                                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1856                                 }
1857                         }
1858
1859                         /* When the player kills a Nazgul, it stays dead */
1860                         else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1861                 }
1862
1863                 /* Count all monsters killed */
1864                 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1865
1866                 /* Recall even invisible uniques or winners */
1867                 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1868                 {
1869                         /* Count kills this life */
1870                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1871                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1872
1873                         /* Count kills in all lives */
1874                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1875                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1876
1877                         /* Hack -- Auto-recall */
1878                         monster_race_track(m_ptr->ap_r_idx);
1879                 }
1880
1881                 /* Extract monster name */
1882                 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1883
1884                 /* Don't kill Amberites */
1885                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1886                 {
1887                         int curses = 1 + randint1(3);
1888                         bool stop_ty = FALSE;
1889                         int count = 0;
1890
1891                         msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
1892                         curse_equipment(100, 50);
1893
1894                         do
1895                         {
1896                                 stop_ty = activate_ty_curse(stop_ty, &count);
1897                         }
1898                         while (--curses);
1899                 }
1900
1901                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1902                 {
1903                         char line_got[1024];
1904
1905                         /* Dump a message */
1906                         if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got))
1907
1908                                 msg_format("%^s %s", m_name, line_got);
1909
1910 #ifdef WORLD_SCORE
1911                         if (m_ptr->r_idx == MON_SERPENT)
1912                         {
1913                                 /* Make screen dump */
1914                                 screen_dump = make_screen_dump();
1915                         }
1916 #endif
1917                 }
1918
1919                 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1920                 {
1921                         if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
1922                         {
1923                                 chg_virtue(V_VALOUR, -1);
1924                         }
1925                         else if (r_ptr->level > dun_level)
1926                         {
1927                                 if (randint1(10) <= (r_ptr->level - dun_level))
1928                                         chg_virtue(V_VALOUR, 1);
1929                         }
1930                         if (r_ptr->level > 60)
1931                         {
1932                                 chg_virtue(V_VALOUR, 1);
1933                         }
1934                         if (r_ptr->level >= 2 * (p_ptr->lev+1))
1935                                 chg_virtue(V_VALOUR, 2);
1936                 }
1937
1938                 if (r_ptr->flags1 & RF1_UNIQUE)
1939                 {
1940                         if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1941
1942                         if (r_ptr->flags3 & RF3_GOOD)
1943                         {
1944                                 chg_virtue(V_UNLIFE, 2);
1945                                 chg_virtue(V_VITALITY, -2);
1946                         }
1947
1948                         if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1949                 }
1950
1951                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1952                 {
1953                         chg_virtue(V_COMPASSION, -1);
1954                 }
1955
1956                 if ((r_ptr->flags3 & RF3_GOOD) &&
1957                         ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
1958                         chg_virtue(V_UNLIFE, 1);
1959
1960                 if (r_ptr->d_char == 'A')
1961                 {
1962                         if (r_ptr->flags1 & RF1_UNIQUE)
1963                                 chg_virtue(V_FAITH, -2);
1964                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1965                         {
1966                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1967                                 else chg_virtue(V_FAITH, 1);
1968                         }
1969                 }
1970                 else if (r_ptr->flags3 & RF3_DEMON)
1971                 {
1972                         if (r_ptr->flags1 & RF1_UNIQUE)
1973                                 chg_virtue(V_FAITH, 2);
1974                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1975                                 chg_virtue(V_FAITH, 1);
1976                 }
1977
1978                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1979                         chg_virtue(V_VITALITY, 2);
1980
1981                 if (r_ptr->r_deaths)
1982                 {
1983                         if (r_ptr->flags1 & RF1_UNIQUE)
1984                         {
1985                                 chg_virtue(V_HONOUR, 10);
1986                         }
1987                         else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
1988                         {
1989                                 chg_virtue(V_HONOUR, 1);
1990                         }
1991                 }
1992                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1993                 {
1994                         chg_virtue(V_VALOUR, -1);
1995                 }
1996
1997                 for (i = 0; i < 4; i++)
1998                 {
1999                         if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
2000
2001                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
2002                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
2003
2004                                 thief = TRUE; /* Thief! */
2005                 }
2006
2007                 /* The new law says it is illegal to live in the dungeon */
2008                 if (r_ptr->level != 0) innocent = FALSE;
2009
2010                 if (thief)
2011                 {
2012                         if (r_ptr->flags1 & RF1_UNIQUE)
2013                                 chg_virtue(V_JUSTICE, 3);
2014                         else if (1+((r_ptr->level) / 10 + (2 * dun_level))
2015                                 >= randint1(100))
2016                                 chg_virtue(V_JUSTICE, 1);
2017                 }
2018                 else if (innocent)
2019                 {
2020                         chg_virtue (V_JUSTICE, -1);
2021                 }
2022
2023                 if ((r_ptr->flags3 & RF3_ANIMAL) && !(r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags4 & ~(RF4_NOMAGIC_MASK))  && !(r_ptr->flags5 & ~(RF5_NOMAGIC_MASK)) && !(r_ptr->flags6 & ~(RF6_NOMAGIC_MASK)))
2024                 {
2025                         if (one_in_(4)) chg_virtue(V_NATURE, -1);
2026                 }
2027
2028                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
2029                 {
2030                         char note_buf[160];
2031 #ifdef JP
2032                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? "(クローン)" : "");
2033 #else
2034                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? "(Clone)" : "");
2035 #endif
2036                         do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
2037                 }
2038
2039                 /* Make a sound */
2040                 sound(SOUND_KILL);
2041
2042                 /* Death by Missile/Spell attack */
2043                 if (note)
2044                 {
2045                         msg_format("%^s%s", m_name, note);
2046                 }
2047
2048                 /* Death by physical attack -- invisible monster */
2049                 else if (!m_ptr->ml)
2050                 {
2051 #ifdef JP
2052                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2053                                 msg_format("せっかくだから%sを殺した。", m_name);
2054                         else
2055 msg_format("%sを殺した。", m_name);
2056 #else
2057                                 msg_format("You have killed %s.", m_name);
2058 #endif
2059
2060                 }
2061
2062                 /* Death by Physical attack -- non-living monster */
2063                 else if (!monster_living(r_ptr))
2064                 {
2065                         int i;
2066                         bool explode = FALSE;
2067
2068                         for (i = 0; i < 4; i++)
2069                         {
2070                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
2071                         }
2072
2073                         /* Special note at death */
2074                         if (explode)
2075                                 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
2076                         else
2077                         {
2078 #ifdef JP
2079                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2080                                         msg_format("せっかくだから%sを倒した。", m_name);
2081                                 else
2082 msg_format("%sを倒した。", m_name);
2083 #else
2084                                 msg_format("You have destroyed %s.", m_name);
2085 #endif
2086                         }
2087                 }
2088
2089                 /* Death by Physical attack -- living monster */
2090                 else
2091                 {
2092 #ifdef JP
2093                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2094                                 msg_format("せっかくだから%sを葬り去った。", m_name);
2095                         else
2096 msg_format("%sを葬り去った。", m_name);
2097 #else
2098                                 msg_format("You have slain %s.", m_name);
2099 #endif
2100
2101                 }
2102                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
2103                 {
2104                         for (i = 0; i < MAX_KUBI; i++)
2105                         {
2106                                 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
2107                                 {
2108                                         msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
2109                                         break;
2110                                 }
2111                         }
2112                 }
2113
2114                 /* Generate treasure */
2115                 monster_death(m_idx, TRUE);
2116
2117                 /* Mega hack : replace IKETA to BIKETAL */
2118                 if ((m_ptr->r_idx == MON_IKETA) &&
2119                     !(p_ptr->inside_arena || p_ptr->inside_battle))
2120                 {
2121                         int dummy_y = m_ptr->fy;
2122                         int dummy_x = m_ptr->fx;
2123                         u32b mode = 0L;
2124
2125                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
2126
2127                         /* Delete the monster */
2128                         delete_monster_idx(m_idx);
2129
2130                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
2131                         {
2132                                 msg_print(_("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha!  *I* am Biketal!"));
2133                         }
2134                 }
2135                 else
2136                 {
2137                         /* Delete the monster */
2138                         delete_monster_idx(m_idx);
2139                 }
2140
2141                 get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
2142
2143                 /* Not afraid */
2144                 (*fear) = FALSE;
2145
2146                 /* Monster is dead */
2147                 return (TRUE);
2148         }
2149
2150
2151 #ifdef ALLOW_FEAR
2152
2153         /* Mega-Hack -- Pain cancels fear */
2154         if (MON_MONFEAR(m_ptr) && (dam > 0))
2155         {
2156                 /* Cure fear */
2157                 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
2158                 {
2159                         /* No more fear */
2160                         (*fear) = FALSE;
2161                 }
2162         }
2163
2164         /* Sometimes a monster gets scared by damage */
2165         if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
2166         {
2167                 /* Percentage of fully healthy */
2168                 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
2169
2170                 /*
2171                  * Run (sometimes) if at 10% or less of max hit points,
2172                  * or (usually) when hit for half its current hit points
2173                  */
2174                 if ((randint1(10) >= percentage) ||
2175                     ((dam >= m_ptr->hp) && (randint0(100) < 80)))
2176                 {
2177                         /* Hack -- note fear */
2178                         (*fear) = TRUE;
2179
2180                         /* XXX XXX XXX Hack -- Add some timed fear */
2181                         (void)set_monster_monfear(m_idx, (randint1(10) +
2182                                           (((dam >= m_ptr->hp) && (percentage > 7)) ?
2183                                            20 : ((11 - percentage) * 5))));
2184                 }
2185         }
2186
2187 #endif
2188
2189 #if 0
2190         if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
2191         {
2192                 char m_name[80];
2193
2194                 /* Extract monster name */
2195                 monster_desc(m_name, m_ptr, 0);
2196
2197                 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
2198                 if (rakuba((dam > 200) ? 200 : dam, FALSE))
2199                 {
2200                 msg_format(_("%^sに振り落とされた!", "%^s has thrown you off!"), m_name);
2201                 }
2202         }
2203 #endif
2204
2205         /* Not dead yet */
2206         return (FALSE);
2207 }
2208
2209
2210 /*!
2211  * @brief 現在のコンソール表示の縦横を返す。 /
2212  * Get term size and calculate screen size
2213  * @param wid_p コンソールの表示幅文字数を返す
2214  * @param hgt_p コンソールの表示行数を返す
2215  * @return なし
2216  */
2217 void get_screen_size(int *wid_p, int *hgt_p)
2218 {
2219         Term_get_size(wid_p, hgt_p);
2220         *hgt_p -= ROW_MAP + 2;
2221         *wid_p -= COL_MAP + 2;
2222         if (use_bigtile) *wid_p /= 2;
2223 }
2224
2225
2226 /*!
2227  * @brief コンソール上におけるマップ表示の左上位置を返す /
2228  * Calculates current boundaries Called below and from "do_cmd_locate()".
2229  * @return なし
2230  */
2231 void panel_bounds_center(void)
2232 {
2233         int wid, hgt;
2234
2235         /* Get size */
2236         get_screen_size(&wid, &hgt);
2237
2238         panel_row_max = panel_row_min + hgt - 1;
2239         panel_row_prt = panel_row_min - 1;
2240         panel_col_max = panel_col_min + wid - 1;
2241         panel_col_prt = panel_col_min - 13;
2242 }
2243
2244
2245 /*!
2246  * @brief コンソールのリサイズに合わせてマップを再描画する /
2247  * Map resizing whenever the main term changes size
2248  * @return なし
2249  */
2250 void resize_map(void)
2251 {
2252         /* Only if the dungeon exists */
2253         if (!character_dungeon) return;
2254         
2255         /* Mega-Hack -- no panel yet */
2256         panel_row_max = 0;
2257         panel_col_max = 0;
2258
2259         /* Reset the panels */
2260         panel_row_min = cur_hgt;
2261         panel_col_min = cur_wid;
2262                                 
2263         verify_panel();
2264
2265         /* Update stuff */
2266         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
2267
2268         /* Forget lite/view */
2269         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
2270
2271         /* Update lite/view */
2272         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
2273
2274         /* Update monsters */
2275         p_ptr->update |= (PU_MONSTERS);
2276
2277         /* Redraw everything */
2278         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
2279
2280         /* Hack -- update */
2281         handle_stuff();
2282         
2283         /* Redraw */
2284         Term_redraw();
2285
2286         /*
2287          * Waiting command;
2288          * Place the cursor on the player
2289          */
2290         if (can_save) move_cursor_relative(py, px);
2291
2292         /* Refresh */
2293         Term_fresh();
2294 }
2295
2296 /*!
2297  * @brief コンソールを再描画する /
2298  * Redraw a term when it is resized
2299  * @return なし
2300  */
2301 void redraw_window(void)
2302 {
2303         /* Only if the dungeon exists */
2304         if (!character_dungeon) return;
2305
2306         /* Window stuff */
2307         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
2308
2309         /* Window stuff */
2310         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
2311
2312         /* Hack -- update */
2313         handle_stuff();
2314
2315         /* Redraw */
2316         Term_redraw();
2317 }
2318
2319
2320 /*!
2321  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
2322  * @param dy 変更先のフロアY座標
2323  * @param dx 変更先のフロアX座標
2324  * Handle a request to change the current panel
2325  * Return TRUE if the panel was changed.
2326  * Also used in do_cmd_locate
2327  * @return 実際に再描画が必要だった場合TRUEを返す
2328  */
2329 bool change_panel(int dy, int dx)
2330 {
2331         int y, x;
2332         int wid, hgt;
2333
2334         /* Get size */
2335         get_screen_size(&wid, &hgt);
2336
2337         /* Apply the motion */
2338         y = panel_row_min + dy * hgt / 2;
2339         x = panel_col_min + dx * wid / 2;
2340
2341         /* Verify the row */
2342         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
2343         if (y < 0) y = 0;
2344
2345         /* Verify the col */
2346         if (x > cur_wid - wid) x = cur_wid - wid;
2347         if (x < 0) x = 0;
2348
2349         /* Handle "changes" */
2350         if ((y != panel_row_min) || (x != panel_col_min))
2351         {
2352                 /* Save the new panel info */
2353                 panel_row_min = y;
2354                 panel_col_min = x;
2355
2356                 /* Recalculate the boundaries */
2357                 panel_bounds_center();
2358
2359                 /* Update stuff */
2360                 p_ptr->update |= (PU_MONSTERS);
2361
2362                 /* Redraw map */
2363                 p_ptr->redraw |= (PR_MAP);
2364
2365                 /* Handle stuff */
2366                 handle_stuff();
2367
2368                 /* Success */
2369                 return (TRUE);
2370         }
2371
2372         /* No change */
2373         return (FALSE);
2374 }
2375
2376 /*!
2377  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する
2378  * @param y 変更先のフロアY座標
2379  * @param x 変更先のフロアX座標
2380  * @details
2381  * Handle a request to change the current panel
2382  * Return TRUE if the panel was changed.
2383  * Also used in do_cmd_locate
2384  * @return 実際に再描画が必要だった場合TRUEを返す
2385  */
2386 bool change_panel_xy(int y, int x)
2387 {
2388         int dy = 0, dx = 0;
2389         int wid, hgt;
2390
2391         /* Get size */
2392         get_screen_size(&wid, &hgt);
2393
2394         if (y < panel_row_min) dy = -1;
2395         if (y > panel_row_max) dy = 1;
2396         if (x < panel_col_min) dx = -1;
2397         if (x > panel_col_max) dx = 1;
2398
2399         if (!dy && !dx) return (FALSE);
2400
2401         return change_panel(dy, dx);
2402 }
2403
2404
2405 /*!
2406  * @brief マップ描画のフォーカスを当てるべき座標を更新する
2407  * @details
2408  * Given an row (y) and col (x), this routine detects when a move
2409  * off the screen has occurred and figures new borders. -RAK-
2410  * "Update" forces a "full update" to take place.
2411  * The map is reprinted if necessary, and "TRUE" is returned.
2412  * @return 実際に再描画が必要だった場合TRUEを返す
2413  */
2414 void verify_panel(void)
2415 {
2416         int y = py;
2417         int x = px;
2418         int wid, hgt;
2419
2420         int prow_min;
2421         int pcol_min;
2422         int max_prow_min;
2423         int max_pcol_min;
2424
2425         /* Get size */
2426         get_screen_size(&wid, &hgt);
2427
2428         max_prow_min = cur_hgt - hgt;
2429         max_pcol_min = cur_wid - wid;
2430
2431         /* Bounds checking */
2432         if (max_prow_min < 0) max_prow_min = 0;
2433         if (max_pcol_min < 0) max_pcol_min = 0;
2434
2435                 /* Center on player */
2436         if (center_player && (center_running || !running))
2437         {
2438                 /* Center vertically */
2439                 prow_min = y - hgt / 2;
2440                 if (prow_min < 0) prow_min = 0;
2441                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
2442
2443                 /* Center horizontally */
2444                 pcol_min = x - wid / 2;
2445                 if (pcol_min < 0) pcol_min = 0;
2446                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2447         }
2448         else
2449         {
2450                 prow_min = panel_row_min;
2451                 pcol_min = panel_col_min;
2452
2453                 /* Scroll screen when 2 grids from top/bottom edge */
2454                 if (y > panel_row_max - 2)
2455                 {
2456                         while (y > prow_min + hgt-1 - 2)
2457                         {
2458                                 prow_min += (hgt / 2);
2459                         }
2460                 }
2461
2462                 if (y < panel_row_min + 2)
2463                 {
2464                         while (y < prow_min + 2)
2465                         {
2466                                 prow_min -= (hgt / 2);
2467                         }
2468                 }
2469
2470                 if (prow_min > max_prow_min) prow_min = max_prow_min;
2471                 if (prow_min < 0) prow_min = 0;
2472
2473                 /* Scroll screen when 4 grids from left/right edge */
2474                 if (x > panel_col_max - 4)
2475                 {
2476                         while (x > pcol_min + wid-1 - 4)
2477                         {
2478                                 pcol_min += (wid / 2);
2479                         }
2480                 }
2481                 
2482                 if (x < panel_col_min + 4)
2483                 {
2484                         while (x < pcol_min + 4)
2485                         {
2486                                 pcol_min -= (wid / 2);
2487                         }
2488                 }
2489
2490                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2491                 if (pcol_min < 0) pcol_min = 0;
2492         }
2493
2494         /* Check for "no change" */
2495         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
2496
2497         /* Save the new panel info */
2498         panel_row_min = prow_min;
2499         panel_col_min = pcol_min;
2500
2501         /* Hack -- optional disturb on "panel change" */
2502         if (disturb_panel && !center_player) disturb(0, 0);
2503
2504         /* Recalculate the boundaries */
2505         panel_bounds_center();
2506
2507         /* Update stuff */
2508         p_ptr->update |= (PU_MONSTERS);
2509
2510         /* Redraw map */
2511         p_ptr->redraw |= (PR_MAP);
2512
2513         /* Window stuff */
2514         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2515 }
2516
2517
2518 /*
2519  * Monster health description
2520  */
2521 cptr look_mon_desc(monster_type *m_ptr, u32b mode)
2522 {
2523         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2524         bool         living;
2525         int          perc;
2526         cptr desc;
2527         cptr attitude;
2528         cptr clone;
2529
2530         /* Determine if the monster is "living" */
2531         living = monster_living(ap_r_ptr);
2532
2533         /* Calculate a health "percentage" */
2534         perc = 100L * m_ptr->hp / m_ptr->maxhp;
2535
2536         /* Healthy monsters */
2537         if (m_ptr->hp >= m_ptr->maxhp)
2538         {
2539                 /* No damage */
2540 #ifdef JP
2541                 desc = living ? "無傷" : "無ダメージ";
2542 #else
2543                 desc = living ? "unhurt" : "undamaged";
2544 #endif
2545
2546         }
2547
2548         else if (perc >= 60)
2549         {
2550 #ifdef JP
2551                 desc = living ? "軽傷" : "小ダメージ";
2552 #else
2553                 desc = living ? "somewhat wounded" : "somewhat damaged";
2554 #endif
2555
2556         }
2557
2558         else if (perc >= 25)
2559         {
2560 #ifdef JP
2561                 desc = living ? "負傷" : "中ダメージ";
2562 #else
2563                 desc = living ? "wounded" : "damaged";
2564 #endif
2565
2566         }
2567
2568         else if (perc >= 10)
2569         {
2570 #ifdef JP
2571                 desc = living ? "重傷" : "大ダメージ";
2572 #else
2573                 desc = living ? "badly wounded" : "badly damaged";
2574 #endif
2575
2576         }
2577
2578         else 
2579         {
2580 #ifdef JP
2581                 desc = living ? "半死半生" : "倒れかけ";
2582 #else
2583                 desc = living ? "almost dead" : "almost destroyed";
2584 #endif
2585         }
2586
2587
2588         /* Need attitude information? */
2589         if (!(mode & 0x01))
2590         {
2591                 /* Full information is not needed */
2592                 attitude = "";
2593         }
2594         else if (is_pet(m_ptr))
2595         {
2596                 attitude = _(", ペット", ", pet");
2597         }
2598         else if (is_friendly(m_ptr))
2599         {
2600                 attitude = _(", 友好的", ", friendly");
2601         }
2602         else
2603         {
2604                 attitude = _("", "");
2605         }
2606
2607
2608         /* Clone monster? */
2609         if (m_ptr->smart & SM_CLONED)
2610         {
2611                 clone = ", clone";
2612         }
2613         else
2614         {
2615                 clone = "";
2616         }
2617
2618         /* Display monster's level --- idea borrowed from ToME */
2619         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
2620         {
2621                 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
2622         }
2623         else 
2624         {
2625                 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
2626         }
2627 }
2628
2629
2630
2631 /*
2632  * Angband sorting algorithm -- quick sort in place
2633  *
2634  * Note that the details of the data we are sorting is hidden,
2635  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2636  * function hooks to interact with the data, which is given as
2637  * two pointers, and which may have any user-defined form.
2638  */
2639 void ang_sort_aux(vptr u, vptr v, int p, int q)
2640 {
2641         int z, a, b;
2642
2643         /* Done sort */
2644         if (p >= q) return;
2645
2646         /* Pivot */
2647         z = p;
2648
2649         /* Begin */
2650         a = p;
2651         b = q;
2652
2653         /* Partition */
2654         while (TRUE)
2655         {
2656                 /* Slide i2 */
2657                 while (!(*ang_sort_comp)(u, v, b, z)) b--;
2658
2659                 /* Slide i1 */
2660                 while (!(*ang_sort_comp)(u, v, z, a)) a++;
2661
2662                 /* Done partition */
2663                 if (a >= b) break;
2664
2665                 /* Swap */
2666                 (*ang_sort_swap)(u, v, a, b);
2667
2668                 /* Advance */
2669                 a++, b--;
2670         }
2671
2672         /* Recurse left side */
2673         ang_sort_aux(u, v, p, b);
2674
2675         /* Recurse right side */
2676         ang_sort_aux(u, v, b+1, q);
2677 }
2678
2679
2680 /*
2681  * Angband sorting algorithm -- quick sort in place
2682  *
2683  * Note that the details of the data we are sorting is hidden,
2684  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2685  * function hooks to interact with the data, which is given as
2686  * two pointers, and which may have any user-defined form.
2687  */
2688 void ang_sort(vptr u, vptr v, int n)
2689 {
2690         /* Sort the array */
2691         ang_sort_aux(u, v, 0, n-1);
2692 }
2693
2694
2695
2696 /*** Targeting Code ***/
2697
2698
2699 /*
2700  * Determine is a monster makes a reasonable target
2701  *
2702  * The concept of "targeting" was stolen from "Morgul" (?)
2703  *
2704  * The player can target any location, or any "target-able" monster.
2705  *
2706  * Currently, a monster is "target_able" if it is visible, and if
2707  * the player can hit it with a projection, and the player is not
2708  * hallucinating.  This allows use of "use closest target" macros.
2709  *
2710  * Future versions may restrict the ability to target "trappers"
2711  * and "mimics", but the semantics is a little bit weird.
2712  */
2713 bool target_able(int m_idx)
2714 {
2715         monster_type *m_ptr = &m_list[m_idx];
2716
2717         /* Monster must be alive */
2718         if (!m_ptr->r_idx) return (FALSE);
2719
2720         /* Hack -- no targeting hallucinations */
2721         if (p_ptr->image) return (FALSE);
2722
2723         /* Monster must be visible */
2724         if (!m_ptr->ml) return (FALSE);
2725
2726         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
2727
2728         /* Monster must be projectable */
2729         if (!projectable(py, px, m_ptr->fy, m_ptr->fx)) return (FALSE);
2730
2731         /* XXX XXX XXX Hack -- Never target trappers */
2732         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
2733
2734         /* Assume okay */
2735         return (TRUE);
2736 }
2737
2738
2739
2740
2741 /*
2742  * Update (if necessary) and verify (if possible) the target.
2743  *
2744  * We return TRUE if the target is "okay" and FALSE otherwise.
2745  */
2746 bool target_okay(void)
2747 {
2748         /* Accept stationary targets */
2749         if (target_who < 0) return (TRUE);
2750
2751         /* Check moving targets */
2752         if (target_who > 0)
2753         {
2754                 /* Accept reasonable targets */
2755                 if (target_able(target_who))
2756                 {
2757                         monster_type *m_ptr = &m_list[target_who];
2758
2759                         /* Acquire monster location */
2760                         target_row = m_ptr->fy;
2761                         target_col = m_ptr->fx;
2762
2763                         /* Good target */
2764                         return (TRUE);
2765                 }
2766         }
2767
2768         /* Assume no target */
2769         return (FALSE);
2770 }
2771
2772
2773 /*
2774  * Sorting hook -- comp function -- by "distance to player"
2775  *
2776  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2777  * and sort the arrays by double-distance to the player.
2778  */
2779 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
2780 {
2781         byte *x = (byte*)(u);
2782         byte *y = (byte*)(v);
2783
2784         int da, db, kx, ky;
2785
2786         /* Absolute distance components */
2787         kx = x[a]; kx -= px; kx = ABS(kx);
2788         ky = y[a]; ky -= py; ky = ABS(ky);
2789
2790         /* Approximate Double Distance to the first point */
2791         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2792
2793         /* Absolute distance components */
2794         kx = x[b]; kx -= px; kx = ABS(kx);
2795         ky = y[b]; ky -= py; ky = ABS(ky);
2796
2797         /* Approximate Double Distance to the first point */
2798         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2799
2800         /* Compare the distances */
2801         return (da <= db);
2802 }
2803
2804
2805 /*
2806  * Sorting hook -- comp function -- by importance level of grids
2807  *
2808  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2809  * and sort the arrays by level of monster
2810  */
2811 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
2812 {
2813         byte *x = (byte*)(u);
2814         byte *y = (byte*)(v);
2815         cave_type *ca_ptr = &cave[y[a]][x[a]];
2816         cave_type *cb_ptr = &cave[y[b]][x[b]];
2817         monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
2818         monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
2819         monster_race *ap_ra_ptr, *ap_rb_ptr;
2820
2821         /* The player grid */
2822         if (y[a] == py && x[a] == px) return TRUE;
2823         if (y[b] == py && x[b] == px) return FALSE;
2824
2825         /* Extract monster race */
2826         if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
2827         else ap_ra_ptr = NULL;
2828         if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
2829         else ap_rb_ptr = NULL;
2830
2831         if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
2832         if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
2833
2834         /* Compare two monsters */
2835         if (ap_ra_ptr && ap_rb_ptr)
2836         {
2837                 /* Unique monsters first */
2838                 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
2839                 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
2840
2841                 /* Shadowers first (あやしい影) */
2842                 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
2843                 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
2844
2845                 /* Unknown monsters first */
2846                 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
2847                 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
2848
2849                 /* Higher level monsters first (if known) */
2850                 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
2851                 {
2852                         if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
2853                         if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
2854                 }
2855
2856                 /* Sort by index if all conditions are same */
2857                 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
2858                 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
2859         }
2860
2861         /* An object get higher priority */
2862         if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
2863         if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
2864
2865         /* Priority from the terrain */
2866         if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
2867         if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
2868
2869         /* If all conditions are same, compare distance */
2870         return ang_sort_comp_distance(u, v, a, b);
2871 }
2872
2873
2874 /*
2875  * Sorting hook -- swap function -- by "distance to player"
2876  *
2877  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2878  * and sort the arrays by distance to the player.
2879  */
2880 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
2881 {
2882         byte *x = (byte*)(u);
2883         byte *y = (byte*)(v);
2884
2885         byte temp;
2886
2887         /* Swap "x" */
2888         temp = x[a];
2889         x[a] = x[b];
2890         x[b] = temp;
2891
2892         /* Swap "y" */
2893         temp = y[a];
2894         y[a] = y[b];
2895         y[b] = temp;
2896 }
2897
2898
2899
2900 /*
2901  * Hack -- help "select" a location (see below)
2902  */
2903 static s16b target_pick(int y1, int x1, int dy, int dx)
2904 {
2905         int i, v;
2906
2907         int x2, y2, x3, y3, x4, y4;
2908
2909         int b_i = -1, b_v = 9999;
2910
2911
2912         /* Scan the locations */
2913         for (i = 0; i < temp_n; i++)
2914         {
2915                 /* Point 2 */
2916                 x2 = temp_x[i];
2917                 y2 = temp_y[i];
2918
2919                 /* Directed distance */
2920                 x3 = (x2 - x1);
2921                 y3 = (y2 - y1);
2922
2923                 /* Verify quadrant */
2924                 if (dx && (x3 * dx <= 0)) continue;
2925                 if (dy && (y3 * dy <= 0)) continue;
2926
2927                 /* Absolute distance */
2928                 x4 = ABS(x3);
2929                 y4 = ABS(y3);
2930
2931                 /* Verify quadrant */
2932                 if (dy && !dx && (x4 > y4)) continue;
2933                 if (dx && !dy && (y4 > x4)) continue;
2934
2935                 /* Approximate Double Distance */
2936                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
2937
2938                 /* XXX XXX XXX Penalize location */
2939
2940                 /* Track best */
2941                 if ((b_i >= 0) && (v >= b_v)) continue;
2942
2943                 /* Track best */
2944                 b_i = i; b_v = v;
2945         }
2946
2947         /* Result */
2948         return (b_i);
2949 }
2950
2951
2952 /*
2953  * Hack -- determine if a given location is "interesting"
2954  */
2955 static bool target_set_accept(int y, int x)
2956 {
2957         cave_type *c_ptr;
2958
2959         s16b this_o_idx, next_o_idx = 0;
2960
2961         /* Bounds */
2962         if (!(in_bounds(y, x))) return (FALSE);
2963
2964         /* Player grid is always interesting */
2965         if (player_bold(y, x)) return (TRUE);
2966
2967
2968         /* Handle hallucination */
2969         if (p_ptr->image) return (FALSE);
2970
2971
2972         /* Examine the grid */
2973         c_ptr = &cave[y][x];
2974
2975         /* Visible monsters */
2976         if (c_ptr->m_idx)
2977         {
2978                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2979
2980                 /* Visible monsters */
2981                 if (m_ptr->ml) return (TRUE);
2982         }
2983
2984         /* Scan all objects in the grid */
2985         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2986         {
2987                 object_type *o_ptr;
2988
2989                 /* Acquire object */
2990                 o_ptr = &o_list[this_o_idx];
2991
2992                 /* Acquire next object */
2993                 next_o_idx = o_ptr->next_o_idx;
2994
2995                 /* Memorized object */
2996                 if (o_ptr->marked & OM_FOUND) return (TRUE);
2997         }
2998
2999         /* Interesting memorized features */
3000         if (c_ptr->info & (CAVE_MARK))
3001         {
3002                 /* Notice object features */
3003                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
3004
3005                 /* Feature code (applying "mimic" field) */
3006                 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
3007         }
3008
3009         /* Nope */
3010         return (FALSE);
3011 }
3012
3013
3014 /*
3015  * Prepare the "temp" array for "target_set"
3016  *
3017  * Return the number of target_able monsters in the set.
3018  */
3019 static void target_set_prepare(int mode)
3020 {
3021         int y, x;
3022         int min_hgt, max_hgt, min_wid, max_wid;
3023
3024         if (mode & TARGET_KILL)
3025         {
3026                 /* Inner range */
3027                 min_hgt = MAX((py - MAX_RANGE), 0);
3028                 max_hgt = MIN((py + MAX_RANGE), cur_hgt - 1);
3029                 min_wid = MAX((px - MAX_RANGE), 0);
3030                 max_wid = MIN((px + MAX_RANGE), cur_wid - 1);
3031         }
3032         else /* not targetting */
3033         {
3034                 /* Inner panel */
3035                 min_hgt = panel_row_min;
3036                 max_hgt = panel_row_max;
3037                 min_wid = panel_col_min;
3038                 max_wid = panel_col_max;
3039         }
3040
3041         /* Reset "temp" array */
3042         temp_n = 0;
3043
3044         /* Scan the current panel */
3045         for (y = min_hgt; y <= max_hgt; y++)
3046         {
3047                 for (x = min_wid; x <= max_wid; x++)
3048                 {
3049                         cave_type *c_ptr;
3050
3051                         /* Require "interesting" contents */
3052                         if (!target_set_accept(y, x)) continue;
3053
3054                         c_ptr = &cave[y][x];
3055
3056                         /* Require target_able monsters for "TARGET_KILL" */
3057                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
3058
3059                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
3060
3061                         /* Save the location */
3062                         temp_x[temp_n] = x;
3063                         temp_y[temp_n] = y;
3064                         temp_n++;
3065                 }
3066         }
3067
3068         /* Set the sort hooks */
3069         if (mode & (TARGET_KILL))
3070         {
3071                 /* Target the nearest monster for shooting */
3072                 ang_sort_comp = ang_sort_comp_distance;
3073                 ang_sort_swap = ang_sort_swap_distance;
3074         }
3075         else
3076         {
3077                 /* Look important grids first in Look command */
3078                 ang_sort_comp = ang_sort_comp_importance;
3079                 ang_sort_swap = ang_sort_swap_distance;
3080         }
3081
3082         /* Sort the positions */
3083         ang_sort(temp_x, temp_y, temp_n);
3084
3085         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
3086         {
3087                 byte tmp;
3088
3089                 tmp = temp_y[0];
3090                 temp_y[0] = temp_y[1];
3091                 temp_y[1] = tmp;
3092                 tmp = temp_x[0];
3093                 temp_x[0] = temp_x[1];
3094                 temp_x[1] = tmp;
3095         }
3096 }
3097 void target_set_prepare_look(){
3098         target_set_prepare(TARGET_LOOK);
3099 }
3100
3101
3102 /*
3103  * Evaluate number of kill needed to gain level
3104  */
3105 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
3106 {
3107         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3108         u32b num;
3109         s32b exp_mon, exp_adv;
3110         u32b exp_mon_frac, exp_adv_frac;
3111
3112         if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
3113         {
3114                 sprintf(buf,"**");
3115                 return;
3116         }
3117         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
3118         {
3119                 if (!p_ptr->wizard)
3120                 {
3121                         sprintf(buf,"??");
3122                         return;
3123                 }
3124         }
3125
3126
3127         /* The monster's experience point (assuming average monster speed) */
3128         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
3129         exp_mon_frac = 0;
3130         s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
3131
3132
3133         /* Total experience value for next level */
3134         exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
3135         exp_adv_frac = 0;
3136         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
3137
3138         /* Experience value need to get */
3139         s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
3140
3141
3142         /* You need to kill at least one monster to get any experience */
3143         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
3144         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
3145
3146         /* Extract number of monsters needed */
3147         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
3148
3149         /* If 999 or more monsters needed, only display "999". */
3150         num = MIN(999, exp_adv_frac);
3151
3152         /* Display the number */
3153         sprintf(buf,"%03ld", (long int)num);
3154 }
3155
3156
3157 bool show_gold_on_floor = FALSE;
3158
3159 /*
3160  * Examine a grid, return a keypress.
3161  *
3162  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
3163  * indicates that the "space" key should scan through the contents
3164  * of the grid, instead of simply returning immediately.  This lets
3165  * the "look" command get complete information, without making the
3166  * "target" command annoying.
3167  *
3168  * The "info" argument contains the "commands" which should be shown
3169  * inside the "[xxx]" text.  This string must never be empty, or grids
3170  * containing monsters will be displayed with an extra comma.
3171  *
3172  * Note that if a monster is in the grid, we update both the monster
3173  * recall info and the health bar info to track that monster.
3174  *
3175  * Eventually, we may allow multiple objects per grid, or objects
3176  * and terrain features in the same grid. XXX XXX XXX
3177  *
3178  * This function must handle blindness/hallucination.
3179  */
3180 static int target_set_aux(int y, int x, int mode, cptr info)
3181 {
3182         cave_type *c_ptr = &cave[y][x];
3183         s16b this_o_idx, next_o_idx = 0;
3184         cptr s1 = "", s2 = "", s3 = "", x_info = "";
3185         bool boring = TRUE;
3186         s16b feat;
3187         feature_type *f_ptr;
3188         int query = '\001';
3189         char out_val[MAX_NLEN+80];
3190
3191 #ifdef ALLOW_EASY_FLOOR
3192         int floor_list[23], floor_num = 0;
3193
3194         /* Scan all objects in the grid */
3195         if (easy_floor)
3196         {
3197                 floor_num = scan_floor(floor_list, y, x, 0x02);
3198
3199                 if (floor_num)
3200                 {
3201                         x_info = _("x物 ", "x,");
3202                 }
3203         }
3204
3205 #endif /* ALLOW_EASY_FLOOR */
3206
3207         /* Hack -- under the player */
3208         if (player_bold(y, x))
3209         {
3210                 /* Description */
3211 #ifdef JP
3212                 s1 = "あなたは";
3213                 s2 = "の上";
3214                 s3 = "にいる";
3215 #else
3216                 s1 = "You are ";
3217
3218                 /* Preposition */
3219                 s2 = "on ";
3220 #endif
3221         }
3222         else
3223         {
3224                 s1 = _("ターゲット:", "Target:");
3225         }
3226
3227         /* Hack -- hallucination */
3228         if (p_ptr->image)
3229         {
3230                 cptr name = _("何か奇妙な物", "something strange");
3231
3232                 /* Display a message */
3233 #ifdef JP
3234                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
3235 #else
3236                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3237 #endif
3238
3239                 prt(out_val, 0, 0);
3240                 move_cursor_relative(y, x);
3241                 query = inkey();
3242
3243                 /* Stop on everything but "return" */
3244                 if ((query != '\r') && (query != '\n')) return query;
3245
3246                 /* Repeat forever */
3247                 return 0;
3248         }
3249
3250
3251         /* Actual monsters */
3252         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
3253         {
3254                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
3255                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3256                 char m_name[80];
3257                 bool recall = FALSE;
3258
3259                 /* Not boring */
3260                 boring = FALSE;
3261
3262                 /* Get the monster name ("a kobold") */
3263                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
3264
3265                 /* Hack -- track this monster race */
3266                 monster_race_track(m_ptr->ap_r_idx);
3267
3268                 /* Hack -- health bar for this monster */
3269                 health_track(c_ptr->m_idx);
3270
3271                 /* Hack -- handle stuff */
3272                 handle_stuff();
3273
3274                 /* Interact */
3275                 while (1)
3276                 {
3277                         char acount[10];
3278
3279                         /* Recall */
3280                         if (recall)
3281                         {
3282                                 /* Save */
3283                                 screen_save();
3284
3285                                 /* Recall on screen */
3286                                 screen_roff(m_ptr->ap_r_idx, 0);
3287
3288                                 /* Hack -- Complete the prompt (again) */
3289                                 Term_addstr(-1, TERM_WHITE, format(_("  [r思 %s%s]", "  [r,%s%s]"), x_info, info));
3290
3291                                 /* Command */
3292                                 query = inkey();
3293
3294                                 /* Restore */
3295                                 screen_load();
3296
3297                                 /* Normal commands */
3298                                 if (query != 'r') break;
3299
3300                                 /* Toggle recall */
3301                                 recall = FALSE;
3302
3303                                 /* Cleare recall text and repeat */
3304                                 continue;
3305                         }
3306
3307                         /*** Normal ***/
3308
3309                         /* Describe, and prompt for recall */
3310                         evaluate_monster_exp(acount, m_ptr);
3311
3312 #ifdef JP
3313                         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);
3314 #else
3315                         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);
3316 #endif
3317
3318                         prt(out_val, 0, 0);
3319
3320                         /* Place cursor */
3321                         move_cursor_relative(y, x);
3322
3323                         /* Command */
3324                         query = inkey();
3325
3326                         /* Normal commands */
3327                         if (query != 'r') break;
3328
3329                         /* Toggle recall */
3330                         recall = TRUE;
3331                 }
3332
3333                 /* Always stop at "normal" keys */
3334                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3335
3336                 /* Sometimes stop at "space" key */
3337                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3338
3339                 /* Change the intro */
3340                 s1 = _("それは", "It is ");
3341
3342                 /* Hack -- take account of gender */
3343                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
3344                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
3345
3346                 /* Use a preposition */
3347 #ifdef JP
3348                 s2 = "を";
3349                 s3 = "持っている";
3350 #else
3351                 s2 = "carrying ";
3352 #endif
3353
3354
3355                 /* Scan all objects being carried */
3356                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3357                 {
3358                         char o_name[MAX_NLEN];
3359
3360                         object_type *o_ptr;
3361
3362                         /* Acquire object */
3363                         o_ptr = &o_list[this_o_idx];
3364
3365                         /* Acquire next object */
3366                         next_o_idx = o_ptr->next_o_idx;
3367
3368                         /* Obtain an object description */
3369                         object_desc(o_name, o_ptr, 0);
3370
3371                         /* Describe the object */
3372 #ifdef JP
3373                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3374 #else
3375                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3376 #endif
3377
3378                         prt(out_val, 0, 0);
3379                         move_cursor_relative(y, x);
3380                         query = inkey();
3381
3382                         /* Always stop at "normal" keys */
3383                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3384
3385                         /* Sometimes stop at "space" key */
3386                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3387
3388                         /* Change the intro */
3389                         s2 = _("をまた", "also carrying ");
3390                 }
3391
3392                 /* Use a preposition */
3393 #ifdef JP
3394                 s2 = "の上";
3395                 s3 = "にいる";
3396 #else
3397                 s2 = "on ";
3398 #endif
3399         }
3400
3401
3402 #ifdef ALLOW_EASY_FLOOR
3403         if (floor_num)
3404         {
3405                 int min_width = 0;
3406
3407                 while (1)
3408                 {
3409                         if (floor_num == 1)
3410                         {
3411                                 char o_name[MAX_NLEN];
3412
3413                                 object_type *o_ptr;
3414
3415                                 /* Acquire object */
3416                                 o_ptr = &o_list[floor_list[0]];
3417
3418                                 /* Describe the object */
3419                                 object_desc(o_name, o_ptr, 0);
3420
3421                                 /* Message */
3422 #ifdef JP
3423                                 sprintf(out_val, "%s%s%s%s[%s]",
3424                                         s1, o_name, s2, s3, info);
3425 #else
3426                                 sprintf(out_val, "%s%s%s%s [%s]",
3427                                         s1, s2, s3, o_name, info);
3428 #endif
3429
3430                                 prt(out_val, 0, 0);
3431                                 move_cursor_relative(y, x);
3432
3433                                 /* Command */
3434                                 query = inkey();
3435
3436                                 /* End this grid */
3437                                 return query;
3438                         }
3439
3440                         /* Provide one cushion before item listing  */
3441                         if (boring)
3442                         {
3443                                 /* Display rough information about items */
3444 #ifdef JP
3445                                 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]",
3446                                         s1, floor_num, s2, s3, info);
3447 #else
3448                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]",
3449                                         s1, s2, s3, floor_num, info);
3450 #endif
3451
3452                                 prt(out_val, 0, 0);
3453                                 move_cursor_relative(y, x);
3454
3455                                 /* Command */
3456                                 query = inkey();
3457
3458                                 /* No request for listing */
3459                                 if (query != 'x' && query != ' ') return query;
3460                         }
3461
3462
3463                         /** Display list of items **/
3464
3465                         /* Continue scrolling list if requested */
3466                         while (1)
3467                         {
3468                                 int i, o_idx;
3469
3470                                 /* Save screen */
3471                                 screen_save();
3472
3473                                 /* Display */
3474                                 show_gold_on_floor = TRUE;
3475                                 (void)show_floor(0, y, x, &min_width);
3476                                 show_gold_on_floor = FALSE;
3477
3478                                 /* Prompt */
3479 #ifdef JP
3480                                 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]",
3481                                         s1, floor_num, s2, s3, info);
3482 #else
3483                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]",
3484                                         s1, s2, s3, floor_num, info);
3485 #endif
3486                                 prt(out_val, 0, 0);
3487
3488
3489                                 /* Wait */
3490                                 query = inkey();
3491
3492                                 /* Load screen */
3493                                 screen_load();
3494
3495                                 /* Exit unless 'Enter' */
3496                                 if (query != '\n' && query != '\r')
3497                                 {
3498                                         return query;
3499                                 }
3500
3501                                 /* Get the object being moved. */
3502                                 o_idx = c_ptr->o_idx;
3503  
3504                                 /* Only rotate a pile of two or more objects. */
3505                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
3506
3507                                 /* Remove the first object from the list. */
3508                                 excise_object_idx(o_idx);
3509
3510                                 /* Find end of the list. */
3511                                 i = c_ptr->o_idx;
3512                                 while (o_list[i].next_o_idx)
3513                                         i = o_list[i].next_o_idx;
3514
3515                                 /* Add after the last object. */
3516                                 o_list[i].next_o_idx = o_idx;
3517
3518                                 /* Loop and re-display the list */
3519                         }
3520                 }
3521
3522                 /* NOTREACHED */
3523         }
3524 #endif /* ALLOW_EASY_FLOOR */
3525
3526
3527         /* Scan all objects in the grid */
3528         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3529         {
3530                 object_type *o_ptr;
3531
3532                 /* Acquire object */
3533                 o_ptr = &o_list[this_o_idx];
3534
3535                 /* Acquire next object */
3536                 next_o_idx = o_ptr->next_o_idx;
3537
3538                 /* Describe it */
3539                 if (o_ptr->marked & OM_FOUND)
3540                 {
3541                         char o_name[MAX_NLEN];
3542
3543                         /* Not boring */
3544                         boring = FALSE;
3545
3546                         /* Obtain an object description */
3547                         object_desc(o_name, o_ptr, 0);
3548
3549                         /* Describe the object */
3550 #ifdef JP
3551                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3552 #else
3553                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3554 #endif
3555
3556                         prt(out_val, 0, 0);
3557                         move_cursor_relative(y, x);
3558                         query = inkey();
3559
3560                         /* Always stop at "normal" keys */
3561                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3562
3563                         /* Sometimes stop at "space" key */
3564                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
3565
3566                         /* Change the intro */
3567                         s1 = _("それは", "It is ");
3568
3569                         /* Plurals */
3570                         if (o_ptr->number != 1) s1 = _("それらは", "They are ");
3571
3572                         /* Preposition */
3573 #ifdef JP
3574                         s2 = "の上";
3575                         s3 = "に見える";
3576 #else
3577                         s2 = "on ";
3578 #endif
3579
3580                 }
3581         }
3582
3583
3584         /* Feature code (applying "mimic" field) */
3585         feat = get_feat_mimic(c_ptr);
3586
3587         /* Require knowledge about grid, or ability to see grid */
3588         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
3589         {
3590                 /* Forget feature */
3591                 feat = feat_none;
3592         }
3593
3594         f_ptr = &f_info[feat];
3595
3596         /* Terrain feature if needed */
3597         if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
3598         {
3599                 cptr name;
3600
3601                 /* Hack -- special handling for quest entrances */
3602                 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
3603                 {
3604                         /* Set the quest number temporary */
3605                         int old_quest = p_ptr->inside_quest;
3606                         int j;
3607
3608                         /* Clear the text */
3609                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
3610                         quest_text_line = 0;
3611
3612                         p_ptr->inside_quest = c_ptr->special;
3613
3614                         /* Get the quest text */
3615                         init_flags = INIT_NAME_ONLY;
3616
3617                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3618
3619                         name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"), 
3620                                                 quest[c_ptr->special].name, quest[c_ptr->special].level);
3621
3622                         /* Reset the old quest number */
3623                         p_ptr->inside_quest = old_quest;
3624                 }
3625
3626                 /* Hack -- special handling for building doors */
3627                 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
3628                 {
3629                         name = building[f_ptr->subtype].name;
3630                 }
3631                 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
3632                 {
3633                         name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3634                 }
3635                 else if (have_flag(f_ptr->flags, FF_TOWN))
3636                 {
3637                         name = town[c_ptr->special].name;
3638                 }
3639                 else if (p_ptr->wild_mode && (feat == feat_floor))
3640                 {
3641                         name = _("道", "road");
3642                 }
3643                 else
3644                 {
3645                         name = f_name + f_ptr->name;
3646                 }
3647
3648
3649                 /* Pick a prefix */
3650                 if (*s2 &&
3651                     ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
3652                      (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
3653                      have_flag(f_ptr->flags, FF_TOWN)))
3654                 {
3655                         s2 = _("の中", "in ");
3656                 }
3657
3658                 /* Hack -- special introduction for store & building doors -KMW- */
3659                 if (have_flag(f_ptr->flags, FF_STORE) ||
3660                     have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
3661                     (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
3662                     have_flag(f_ptr->flags, FF_ENTRANCE))
3663                 {
3664 #ifdef JP
3665                         s2 = "の入口";
3666 #else
3667                         s3 = "";
3668 #endif
3669                 }
3670 #ifndef JP
3671                 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
3672                          have_flag(f_ptr->flags, FF_TOWN) ||
3673                          have_flag(f_ptr->flags, FF_SHALLOW) ||
3674                          have_flag(f_ptr->flags, FF_DEEP))
3675                 {
3676                         s3 ="";
3677                 }
3678                 else
3679                 {
3680                         /* Pick proper indefinite article */
3681                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
3682                 }
3683 #endif
3684
3685                 /* Display a message */
3686                 if (p_ptr->wizard)
3687                 {
3688                         char f_idx_str[32];
3689                         if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
3690                         else sprintf(f_idx_str, "%d", c_ptr->feat);
3691 #ifdef JP
3692                         sprintf(out_val, "%s%s%s%s[%s] %x %s %d %d %d (%d,%d) %d", s1, name, s2, s3, info, c_ptr->info, f_idx_str, c_ptr->dist, c_ptr->cost, c_ptr->when, y, x, travel.cost[y][x]);
3693 #else
3694                         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, y, x);
3695 #endif
3696                 }
3697                 else
3698 #ifdef JP
3699                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
3700 #else
3701                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3702 #endif
3703
3704                 prt(out_val, 0, 0);
3705                 move_cursor_relative(y, x);
3706                 query = inkey();
3707
3708                 /* Always stop at "normal" keys */
3709                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
3710         }
3711
3712         /* Stop on everything but "return" */
3713         if ((query != '\r') && (query != '\n')) return query;
3714
3715         /* Repeat forever */
3716         return 0;
3717 }
3718
3719
3720 /*
3721  * Handle "target" and "look".
3722  *
3723  * Note that this code can be called from "get_aim_dir()".
3724  *
3725  * All locations must be on the current panel.  Consider the use of
3726  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
3727  * some form of "scrolling" the map around the cursor.  XXX XXX XXX
3728  * That is, consider the possibility of "auto-scrolling" the screen
3729  * while the cursor moves around.  This may require changes in the
3730  * "update_mon()" code to allow "visibility" even if off panel, and
3731  * may require dynamic recalculation of the "temp" grid set.
3732  *
3733  * Hack -- targeting/observing an "outer border grid" may induce
3734  * problems, so this is not currently allowed.
3735  *
3736  * The player can use the direction keys to move among "interesting"
3737  * grids in a heuristic manner, or the "space", "+", and "-" keys to
3738  * move through the "interesting" grids in a sequential manner, or
3739  * can enter "location" mode, and use the direction keys to move one
3740  * grid at a time in any direction.  The "t" (set target) command will
3741  * only target a monster (as opposed to a location) if the monster is
3742  * target_able and the "interesting" mode is being used.
3743  *
3744  * The current grid is described using the "look" method above, and
3745  * a new command may be entered at any time, but note that if the
3746  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
3747  * where "space" has no obvious meaning) then "space" will scan
3748  * through the description of the current grid until done, instead
3749  * of immediately jumping to the next "interesting" grid.  This
3750  * allows the "target" command to retain its old semantics.
3751  *
3752  * The "*", "+", and "-" keys may always be used to jump immediately
3753  * to the next (or previous) interesting grid, in the proper mode.
3754  *
3755  * The "return" key may always be used to scan through a complete
3756  * grid description (forever).
3757  *
3758  * This command will cancel any old target, even if used from
3759  * inside the "look" command.
3760  */
3761 bool target_set(int mode)
3762 {
3763         int             i, d, m, t, bd;
3764         int             y = py;
3765         int             x = px;
3766
3767         bool    done = FALSE;
3768
3769         bool    flag = TRUE;
3770
3771         char    query;
3772
3773         char    info[80];
3774
3775         cave_type               *c_ptr;
3776
3777         int wid, hgt;
3778         
3779         /* Get size */
3780         get_screen_size(&wid, &hgt);
3781
3782         /* Cancel target */
3783         target_who = 0;
3784
3785
3786         /* Cancel tracking */
3787         /* health_track(0); */
3788
3789
3790         /* Prepare the "temp" array */
3791         target_set_prepare(mode);
3792
3793         /* Start near the player */
3794         m = 0;
3795
3796         /* Interact */
3797         while (!done)
3798         {
3799                 /* Interesting grids */
3800                 if (flag && temp_n)
3801                 {
3802                         y = temp_y[m];
3803                         x = temp_x[m];
3804
3805                         /* Set forcus */
3806                         change_panel_xy(y, x);
3807
3808                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3809
3810                         /* Access */
3811                         c_ptr = &cave[y][x];
3812
3813                         /* Allow target */
3814                         if (target_able(c_ptr->m_idx))
3815                         {
3816                                 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
3817                         }
3818
3819                         /* Dis-allow target */
3820                         else
3821                         {
3822                                 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
3823                         }
3824                         
3825                         /* Describe and Prompt */
3826                         while (TRUE){
3827                                 query = target_set_aux(y, x, mode, info);
3828                                 if(query)break;
3829                         }
3830
3831                         /* Cancel tracking */
3832                         /* health_track(0); */
3833
3834                         /* Assume no "direction" */
3835                         d = 0;
3836
3837                         if (use_menu)
3838                         {
3839                                 if (query == '\r') query = 't';
3840                         }  
3841
3842                         /* Analyze */
3843                         switch (query)
3844                         {
3845                                 case ESCAPE:
3846                                 case 'q':
3847                                 {
3848                                         done = TRUE;
3849                                         break;
3850                                 }
3851
3852                                 case 't':
3853                                 case '.':
3854                                 case '5':
3855                                 case '0':
3856                                 {
3857                                         if (target_able(c_ptr->m_idx))
3858                                         {
3859                                                 health_track(c_ptr->m_idx);
3860                                                 target_who = c_ptr->m_idx;
3861                                                 target_row = y;
3862                                                 target_col = x;
3863                                                 done = TRUE;
3864                                         }
3865                                         else
3866                                         {
3867                                                 bell();
3868                                         }
3869                                         break;
3870                                 }
3871
3872                                 case ' ':
3873                                 case '*':
3874                                 case '+':
3875                                 {
3876                                         if (++m == temp_n)
3877                                         {
3878                                                 m = 0;
3879                                                 if (!expand_list) done = TRUE;
3880                                         }
3881                                         break;
3882                                 }
3883
3884                                 case '-':
3885                                 {
3886                                         if (m-- == 0)
3887                                         {
3888                                                 m = temp_n - 1;
3889                                                 if (!expand_list) done = TRUE;
3890                                         }
3891                                         break;
3892                                 }
3893
3894                                 case 'p':
3895                                 {
3896                                         /* Recenter the map around the player */
3897                                         verify_panel();
3898
3899                                         /* Update stuff */
3900                                         p_ptr->update |= (PU_MONSTERS);
3901
3902                                         /* Redraw map */
3903                                         p_ptr->redraw |= (PR_MAP);
3904
3905                                         /* Window stuff */
3906                                         p_ptr->window |= (PW_OVERHEAD);
3907
3908                                         /* Handle stuff */
3909                                         handle_stuff();
3910
3911                                         /* Recalculate interesting grids */
3912                                         target_set_prepare(mode);
3913
3914                                         y = py;
3915                                         x = px;
3916                                 }
3917
3918                                 case 'o':
3919                                 {
3920                                         flag = FALSE;
3921                                         break;
3922                                 }
3923
3924                                 case 'm':
3925                                 {
3926                                         break;
3927                                 }
3928
3929                                 default:
3930                                 {
3931                                         /* Extract the action (if any) */
3932                                         d = get_keymap_dir(query);
3933
3934                                         if (!d) bell();
3935                                         break;
3936                                 }
3937                         }
3938
3939                         /* Hack -- move around */
3940                         if (d)
3941                         {
3942                                 /* Modified to scroll to monster */
3943                                 int y2 = panel_row_min;
3944                                 int x2 = panel_col_min;
3945
3946                                 /* Find a new monster */
3947                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
3948
3949                                 /* Request to target past last interesting grid */
3950                                 while (flag && (i < 0))
3951                                 {
3952                                         /* Note the change */
3953                                         if (change_panel(ddy[d], ddx[d]))
3954                                         {
3955                                                 int v = temp_y[m];
3956                                                 int u = temp_x[m];
3957
3958                                                 /* Recalculate interesting grids */
3959                                                 target_set_prepare(mode);
3960
3961                                                 /* Look at interesting grids */
3962                                                 flag = TRUE;
3963
3964                                                 /* Find a new monster */
3965                                                 i = target_pick(v, u, ddy[d], ddx[d]);
3966
3967                                                 /* Use that grid */
3968                                                 if (i >= 0) m = i;
3969                                         }
3970
3971                                         /* Nothing interesting */
3972                                         else
3973                                         {
3974                                                 int dx = ddx[d];
3975                                                 int dy = ddy[d];
3976
3977                                                 /* Restore previous position */
3978                                                 panel_row_min = y2;
3979                                                 panel_col_min = x2;
3980                                                 panel_bounds_center();
3981
3982                                                 /* Update stuff */
3983                                                 p_ptr->update |= (PU_MONSTERS);
3984
3985                                                 /* Redraw map */
3986                                                 p_ptr->redraw |= (PR_MAP);
3987
3988                                                 /* Window stuff */
3989                                                 p_ptr->window |= (PW_OVERHEAD);
3990
3991                                                 /* Handle stuff */
3992                                                 handle_stuff();
3993
3994                                                 /* Recalculate interesting grids */
3995                                                 target_set_prepare(mode);
3996
3997                                                 /* Look at boring grids */
3998                                                 flag = FALSE;
3999
4000                                                 /* Move */
4001                                                 x += dx;
4002                                                 y += dy;
4003
4004                                                 /* Do not move horizontally if unnecessary */
4005                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4006                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4007                                                 {
4008                                                         dx = 0;
4009                                                 }
4010
4011                                                 /* Do not move vertically if unnecessary */
4012                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4013                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4014                                                 {
4015                                                         dy = 0;
4016                                                 }
4017
4018                                                 /* Apply the motion */
4019                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
4020                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
4021                                                 {
4022                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
4023                                                 }
4024
4025                                                 /* Slide into legality */
4026                                                 if (x >= cur_wid-1) x = cur_wid - 2;
4027                                                 else if (x <= 0) x = 1;
4028
4029                                                 /* Slide into legality */
4030                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4031                                                 else if (y <= 0) y = 1;
4032                                         }
4033                                 }
4034
4035                                 /* Use that grid */
4036                                 m = i;
4037                         }
4038                 }
4039
4040                 /* Arbitrary grids */
4041                 else
4042                 {
4043                         bool move_fast = FALSE;
4044
4045                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
4046
4047                         /* Access */
4048                         c_ptr = &cave[y][x];
4049
4050                         /* Default prompt */
4051                         strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
4052
4053                         /* Describe and Prompt (enable "TARGET_LOOK") */
4054                         while (!(query = target_set_aux(y, x, mode | TARGET_LOOK, info)));
4055
4056                         /* Cancel tracking */
4057                         /* health_track(0); */
4058
4059                         /* Assume no direction */
4060                         d = 0;
4061
4062                         if (use_menu)
4063                         {
4064                                 if (query == '\r') query = 't';
4065                         }  
4066
4067                         /* Analyze the keypress */
4068                         switch (query)
4069                         {
4070                                 case ESCAPE:
4071                                 case 'q':
4072                                 {
4073                                         done = TRUE;
4074                                         break;
4075                                 }
4076
4077                                 case 't':
4078                                 case '.':
4079                                 case '5':
4080                                 case '0':
4081                                 {
4082                                         target_who = -1;
4083                                         target_row = y;
4084                                         target_col = x;
4085                                         done = TRUE;
4086                                         break;
4087                                 }
4088
4089                                 case 'p':
4090                                 {
4091                                         /* Recenter the map around the player */
4092                                         verify_panel();
4093
4094                                         /* Update stuff */
4095                                         p_ptr->update |= (PU_MONSTERS);
4096
4097                                         /* Redraw map */
4098                                         p_ptr->redraw |= (PR_MAP);
4099
4100                                         /* Window stuff */
4101                                         p_ptr->window |= (PW_OVERHEAD);
4102
4103                                         /* Handle stuff */
4104                                         handle_stuff();
4105
4106                                         /* Recalculate interesting grids */
4107                                         target_set_prepare(mode);
4108
4109                                         y = py;
4110                                         x = px;
4111                                 }
4112
4113                                 case 'o':
4114                                 {
4115                                         break;
4116                                 }
4117
4118                                 case ' ':
4119                                 case '*':
4120                                 case '+':
4121                                 case '-':
4122                                 case 'm':
4123                                 {
4124                                         flag = TRUE;
4125
4126                                         m = 0;
4127                                         bd = 999;
4128
4129                                         /* Pick a nearby monster */
4130                                         for (i = 0; i < temp_n; i++)
4131                                         {
4132                                                 t = distance(y, x, temp_y[i], temp_x[i]);
4133
4134                                                 /* Pick closest */
4135                                                 if (t < bd)
4136                                                 {
4137                                                         m = i;
4138                                                         bd = t;
4139                                                 }
4140                                         }
4141
4142                                         /* Nothing interesting */
4143                                         if (bd == 999) flag = FALSE;
4144
4145                                         break;
4146                                 }
4147
4148                                 default:
4149                                 {
4150                                         /* Extract the action (if any) */
4151                                         d = get_keymap_dir(query);
4152
4153                                         /* XTRA HACK MOVEFAST */
4154                                         if (isupper(query)) move_fast = TRUE;
4155
4156                                         if (!d) bell();
4157                                         break;
4158                                 }
4159                         }
4160
4161                         /* Handle "direction" */
4162                         if (d)
4163                         {
4164                                 int dx = ddx[d];
4165                                 int dy = ddy[d];
4166
4167                                 /* XTRA HACK MOVEFAST */
4168                                 if (move_fast)
4169                                 {
4170                                         int mag = MIN(wid / 2, hgt / 2);
4171                                         x += dx * mag;
4172                                         y += dy * mag;
4173                                 }
4174                                 else
4175                                 {
4176                                         x += dx;
4177                                         y += dy;
4178                                 }
4179
4180                                 /* Do not move horizontally if unnecessary */
4181                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4182                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4183                                 {
4184                                         dx = 0;
4185                                 }
4186
4187                                 /* Do not move vertically if unnecessary */
4188                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4189                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4190                                 {
4191                                         dy = 0;
4192                                 }
4193
4194                                 /* Apply the motion */
4195                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
4196                                          (x >= panel_col_min + wid) || (x < panel_col_min))
4197                                 {
4198                                         if (change_panel(dy, dx)) target_set_prepare(mode);
4199                                 }
4200
4201                                 /* Slide into legality */
4202                                 if (x >= cur_wid-1) x = cur_wid - 2;
4203                                 else if (x <= 0) x = 1;
4204
4205                                 /* Slide into legality */
4206                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4207                                 else if (y <= 0) y = 1;
4208                         }
4209                 }
4210         }
4211
4212         /* Forget */
4213         temp_n = 0;
4214
4215         /* Clear the top line */
4216         prt("", 0, 0);
4217
4218         /* Recenter the map around the player */
4219         verify_panel();
4220
4221         /* Update stuff */
4222         p_ptr->update |= (PU_MONSTERS);
4223
4224         /* Redraw map */
4225         p_ptr->redraw |= (PR_MAP);
4226
4227         /* Window stuff */
4228         p_ptr->window |= (PW_OVERHEAD);
4229
4230         /* Handle stuff */
4231         handle_stuff();
4232
4233         /* Failure to set target */
4234         if (!target_who) return (FALSE);
4235
4236         /* Success */
4237         return (TRUE);
4238 }
4239
4240
4241 /*
4242  * Get an "aiming direction" from the user.
4243  *
4244  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
4245  * "0" for "current target", and "-1" for "entry aborted".
4246  *
4247  * Note that "Force Target", if set, will pre-empt user interaction,
4248  * if there is a usable target already set.
4249  *
4250  * Note that confusion over-rides any (explicit?) user choice.
4251  */
4252 bool get_aim_dir(int *dp)
4253 {
4254         int             dir;
4255
4256         char    command;
4257
4258         cptr    p;
4259
4260         /* Initialize */
4261         (*dp) = 0;
4262
4263         /* Global direction */
4264         dir = command_dir;
4265
4266         /* Hack -- auto-target if requested */
4267         if (use_old_target && target_okay()) dir = 5;
4268
4269 #ifdef ALLOW_REPEAT /* TNB */
4270
4271         if (repeat_pull(dp))
4272         {
4273                 /* Confusion? */
4274
4275                 /* Verify */
4276                 if (!(*dp == 5 && !target_okay()))
4277                 {
4278 /*                      return (TRUE); */
4279                         dir = *dp;
4280                 }
4281         }
4282
4283 #endif /* ALLOW_REPEAT -- TNB */
4284
4285         /* Ask until satisfied */
4286         while (!dir)
4287         {
4288                 /* Choose a prompt */
4289                 if (!target_okay())
4290                 {
4291                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
4292                 }
4293                 else
4294                 {
4295                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
4296                 }
4297
4298                 /* Get a command (or Cancel) */
4299                 if (!get_com(p, &command, TRUE)) break;
4300
4301                 if (use_menu)
4302                 {
4303                         if (command == '\r') command = 't';
4304                 }  
4305
4306                 /* Convert various keys to "standard" keys */
4307                 switch (command)
4308                 {
4309                         /* Use current target */
4310                         case 'T':
4311                         case 't':
4312                         case '.':
4313                         case '5':
4314                         case '0':
4315                         {
4316                                 dir = 5;
4317                                 break;
4318                         }
4319
4320                         /* Set new target */
4321                         case '*':
4322                         case ' ':
4323                         case '\r':
4324                         {
4325                                 if (target_set(TARGET_KILL)) dir = 5;
4326                                 break;
4327                         }
4328
4329                         default:
4330                         {
4331                                 /* Extract the action (if any) */
4332                                 dir = get_keymap_dir(command);
4333
4334                                 break;
4335                         }
4336                 }
4337
4338                 /* Verify requested targets */
4339                 if ((dir == 5) && !target_okay()) dir = 0;
4340
4341                 /* Error */
4342                 if (!dir) bell();
4343         }
4344
4345         /* No direction */
4346         if (!dir)
4347         {
4348                 project_length = 0; /* reset to default */
4349                 return (FALSE);
4350         }
4351
4352         /* Save the direction */
4353         command_dir = dir;
4354
4355         /* Check for confusion */
4356         if (p_ptr->confused)
4357         {
4358                 /* XXX XXX XXX */
4359                 /* Random direction */
4360                 dir = ddd[randint0(8)];
4361         }
4362
4363         /* Notice confusion */
4364         if (command_dir != dir)
4365         {
4366                 /* Warn the user */
4367                 msg_print(_("あなたは混乱している。", "You are confused."));
4368         }
4369
4370         /* Save direction */
4371         (*dp) = dir;
4372
4373 #ifdef ALLOW_REPEAT /* TNB */
4374
4375 /*      repeat_push(dir); */
4376         repeat_push(command_dir);
4377
4378 #endif /* ALLOW_REPEAT -- TNB */
4379
4380         /* A "valid" direction was entered */
4381         return (TRUE);
4382 }
4383
4384
4385
4386 /*
4387  * Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
4388  * and place it into "command_dir", unless we already have one.
4389  *
4390  * This function should be used for all "repeatable" commands, such as
4391  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
4392  * as all commands which must reference a grid adjacent to the player,
4393  * and which may not reference the grid under the player.  Note that,
4394  * for example, it is no longer possible to "disarm" or "open" chests
4395  * in the same grid as the player.
4396  *
4397  * Direction "5" is illegal and will (cleanly) abort the command.
4398  *
4399  * This function tracks and uses the "global direction", and uses
4400  * that as the "desired direction", to which "confusion" is applied.
4401  */
4402 bool get_rep_dir(int *dp, bool under)
4403 {
4404         int dir;
4405         cptr prompt;
4406
4407         /* Initialize */
4408         (*dp) = 0;
4409
4410         /* Global direction */
4411         dir = command_dir;
4412
4413 #ifdef ALLOW_REPEAT /* TNB */
4414
4415         if (repeat_pull(dp))
4416         {
4417                 dir = *dp;
4418 /*              return (TRUE); */
4419         }
4420
4421 #endif /* ALLOW_REPEAT -- TNB */
4422
4423         if (under)
4424         {
4425                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
4426         }
4427         else
4428         {
4429                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
4430         }
4431         
4432         /* Get a direction */
4433         while (!dir)
4434         {
4435                 char ch;
4436
4437                 /* Get a command (or Cancel) */
4438                 if (!get_com(prompt, &ch, TRUE)) break;
4439
4440                 /* Look down */
4441                 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
4442                 {
4443                         dir = 5;
4444                 }
4445                 else
4446                 {
4447                         /* Look up the direction */
4448                         dir = get_keymap_dir(ch);
4449
4450                         /* Oops */
4451                         if (!dir) bell();
4452                 }
4453         }
4454
4455         /* Prevent weirdness */
4456         if ((dir == 5) && (!under)) dir = 0;
4457
4458         /* Aborted */
4459         if (!dir) return (FALSE);
4460
4461         /* Save desired direction */
4462         command_dir = dir;
4463
4464         /* Apply "confusion" */
4465         if (p_ptr->confused)
4466         {
4467                 /* Standard confusion */
4468                 if (randint0(100) < 75)
4469                 {
4470                         /* Random direction */
4471                         dir = ddd[randint0(8)];
4472                 }
4473         }
4474         else if (p_ptr->riding)
4475         {
4476                 monster_type *m_ptr = &m_list[p_ptr->riding];
4477                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4478
4479                 if (MON_CONFUSED(m_ptr))
4480                 {
4481                         /* Standard confusion */
4482                         if (randint0(100) < 75)
4483                         {
4484                                 /* Random direction */
4485                                 dir = ddd[randint0(8)];
4486                         }
4487                 }
4488                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
4489                 {
4490                         /* Random direction */
4491                         dir = ddd[randint0(8)];
4492                 }
4493                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
4494                 {
4495                         /* Random direction */
4496                         dir = ddd[randint0(8)];
4497                 }
4498         }
4499
4500         /* Notice confusion */
4501         if (command_dir != dir)
4502         {
4503                 if (p_ptr->confused)
4504                 {
4505                         /* Warn the user */
4506                         msg_print(_("あなたは混乱している。", "You are confused."));
4507                 }
4508                 else
4509                 {
4510                         char m_name[80];
4511                         monster_type *m_ptr = &m_list[p_ptr->riding];
4512
4513                         monster_desc(m_name, m_ptr, 0);
4514                         if (MON_CONFUSED(m_ptr))
4515                         {
4516                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
4517                         }
4518                         else
4519                         {
4520                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
4521                         }
4522                 }
4523         }
4524
4525         /* Save direction */
4526         (*dp) = dir;
4527
4528 #ifdef ALLOW_REPEAT /* TNB */
4529
4530 /*      repeat_push(dir); */
4531         repeat_push(command_dir);
4532
4533 #endif /* ALLOW_REPEAT -- TNB */
4534
4535         /* Success */
4536         return (TRUE);
4537 }
4538
4539
4540 bool get_rep_dir2(int *dp)
4541 {
4542         int dir;
4543
4544         /* Initialize */
4545         (*dp) = 0;
4546
4547         /* Global direction */
4548         dir = command_dir;
4549
4550 #ifdef ALLOW_REPEAT /* TNB */
4551
4552         if (repeat_pull(dp))
4553         {
4554                 dir = *dp;
4555 /*              return (TRUE); */
4556         }
4557
4558 #endif /* ALLOW_REPEAT -- TNB */
4559
4560         /* Get a direction */
4561         while (!dir)
4562         {
4563                 char ch;
4564
4565                 /* Get a command (or Cancel) */
4566                 if (!get_com(_("方向 (ESCで中断)? ", "Direction (Escape to cancel)? "), &ch, TRUE)) break;
4567
4568                 /* Look up the direction */
4569                 dir = get_keymap_dir(ch);
4570
4571                 /* Oops */
4572                 if (!dir) bell();
4573         }
4574
4575         /* Prevent weirdness */
4576         if (dir == 5) dir = 0;
4577
4578         /* Aborted */
4579         if (!dir) return (FALSE);
4580
4581         /* Save desired direction */
4582         command_dir = dir;
4583
4584         /* Apply "confusion" */
4585         if (p_ptr->confused)
4586         {
4587                 /* Standard confusion */
4588                 if (randint0(100) < 75)
4589                 {
4590                         /* Random direction */
4591                         dir = ddd[randint0(8)];
4592                 }
4593         }
4594
4595         /* Notice confusion */
4596         if (command_dir != dir)
4597         {
4598                 /* Warn the user */
4599                 msg_print(_("あなたは混乱している。", "You are confused."));
4600         }
4601
4602         /* Save direction */
4603         (*dp) = dir;
4604
4605 #ifdef ALLOW_REPEAT /* TNB */
4606
4607 /*      repeat_push(dir); */
4608         repeat_push(command_dir);
4609
4610 #endif /* ALLOW_REPEAT -- TNB */
4611
4612         /* Success */
4613         return (TRUE);
4614 }
4615
4616 void gain_level_reward(int chosen_reward)
4617 {
4618         object_type *q_ptr;
4619         object_type forge;
4620         char        wrath_reason[32] = "";
4621         int         nasty_chance = 6;
4622         int         dummy = 0, dummy2 = 0;
4623         int         type, effect;
4624         cptr        reward = NULL;
4625         char o_name[MAX_NLEN];
4626
4627         int count = 0;
4628
4629         if (!chosen_reward)
4630         {
4631                 if (multi_rew) return;
4632                 else multi_rew = TRUE;
4633         }
4634
4635
4636         if (p_ptr->lev == 13) nasty_chance = 2;
4637         else if (!(p_ptr->lev % 13)) nasty_chance = 3;
4638         else if (!(p_ptr->lev % 14)) nasty_chance = 12;
4639
4640         if (one_in_(nasty_chance))
4641                 type = randint1(20); /* Allow the 'nasty' effects */
4642         else
4643                 type = randint1(15) + 5; /* Or disallow them */
4644
4645         if (type < 1) type = 1;
4646         if (type > 20) type = 20;
4647         type--;
4648
4649
4650 #ifdef JP
4651 sprintf(wrath_reason, "%sの怒り",
4652                 chaos_patrons[p_ptr->chaos_patron]);
4653 #else
4654         sprintf(wrath_reason, "the Wrath of %s",
4655                 chaos_patrons[p_ptr->chaos_patron]);
4656 #endif
4657
4658
4659         effect = chaos_rewards[p_ptr->chaos_patron][type];
4660
4661         if (one_in_(6) && !chosen_reward)
4662         {
4663 #ifdef JP
4664 msg_format("%^sは褒美としてあなたを突然変異させた。",
4665                         chaos_patrons[p_ptr->chaos_patron]);
4666 #else
4667                 msg_format("%^s rewards you with a mutation!",
4668                         chaos_patrons[p_ptr->chaos_patron]);
4669 #endif
4670
4671                 (void)gain_random_mutation(0);
4672                 reward = _("変異した。", "mutation");
4673         }
4674         else
4675         {
4676         switch (chosen_reward ? chosen_reward : effect)
4677         {
4678                 case REW_POLY_SLF:
4679 #ifdef JP
4680 msg_format("%sの声が響き渡った:",
4681                                 chaos_patrons[p_ptr->chaos_patron]);
4682 #else
4683                         msg_format("The voice of %s booms out:",
4684                                 chaos_patrons[p_ptr->chaos_patron]);
4685 #endif
4686
4687                         msg_print(_("「汝、新たなる姿を必要とせり!」", "'Thou needst a new form, mortal!'"));
4688
4689                         do_poly_self();
4690                         reward = _("変異した。", "polymorphing");
4691                         break;
4692                 case REW_GAIN_EXP:
4693 #ifdef JP
4694 msg_format("%sの声が響き渡った:",
4695                                 chaos_patrons[p_ptr->chaos_patron]);
4696 #else
4697                         msg_format("The voice of %s booms out:",
4698                                 chaos_patrons[p_ptr->chaos_patron]);
4699 #endif
4700
4701                         msg_print(_("「汝は良く行いたり!続けよ!」", "'Well done, mortal! Lead on!'"));
4702
4703                         if (p_ptr->prace == RACE_ANDROID)
4704                         {
4705                                 msg_print(_("しかし何も起こらなかった。", "But, nothing happen."));
4706                         }
4707                         else if (p_ptr->exp < PY_MAX_EXP)
4708                         {
4709                                 s32b ee = (p_ptr->exp / 2) + 10;
4710                                 if (ee > 100000L) ee = 100000L;
4711                                 msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
4712
4713                                 gain_exp(ee);
4714                                 reward = _("経験値を得た", "experience");
4715                         }
4716                         break;
4717                 case REW_LOSE_EXP:
4718 #ifdef JP
4719 msg_format("%sの声が響き渡った:",
4720                                 chaos_patrons[p_ptr->chaos_patron]);
4721 #else
4722                         msg_format("The voice of %s booms out:",
4723                                 chaos_patrons[p_ptr->chaos_patron]);
4724 #endif
4725
4726                         msg_print(_("「下僕よ、汝それに値せず。」", "'Thou didst not deserve that, slave.'"));
4727
4728                         if (p_ptr->prace == RACE_ANDROID)
4729                         {
4730                                 msg_print(_("しかし何も起こらなかった。", "But, nothing happen."));
4731                         }
4732                         else
4733                         {
4734                                 lose_exp(p_ptr->exp / 6);
4735                                 reward = _("経験値を失った。", "losing experience");
4736                         }
4737                         break;
4738                 case REW_GOOD_OBJ:
4739 #ifdef JP
4740 msg_format("%sの声がささやいた:",
4741                                 chaos_patrons[p_ptr->chaos_patron]);
4742 #else
4743                         msg_format("The voice of %s whispers:",
4744                                 chaos_patrons[p_ptr->chaos_patron]);
4745 #endif
4746
4747                         msg_print(_("「我が与えし物を賢明に使うべし。」", "'Use my gift wisely.'"));
4748
4749                         acquirement(py, px, 1, FALSE, FALSE, FALSE);
4750                         reward = _("上質なアイテムを手に入れた。", "a good item");
4751                         break;
4752                 case REW_GREA_OBJ:
4753 #ifdef JP
4754 msg_format("%sの声が響き渡った:",
4755                                 chaos_patrons[p_ptr->chaos_patron]);
4756 #else
4757                         msg_format("The voice of %s booms out:",
4758                                 chaos_patrons[p_ptr->chaos_patron]);
4759 #endif
4760
4761                         msg_print(_("「我が与えし物を賢明に使うべし。」", "'Use my gift wisely.'"));
4762
4763                         acquirement(py, px, 1, TRUE, FALSE, FALSE);
4764                         reward = _("高級品のアイテムを手に入れた。", "an excellent item");
4765                         break;
4766                 case REW_CHAOS_WP:
4767 #ifdef JP
4768 msg_format("%sの声が響き渡った:",
4769                                 chaos_patrons[p_ptr->chaos_patron]);
4770 #else
4771                         msg_format("The voice of %s booms out:",
4772                                 chaos_patrons[p_ptr->chaos_patron]);
4773 #endif
4774
4775                         msg_print(_("「汝の行いは貴き剣に値せり。」", "'Thy deed hath earned thee a worthy blade.'"));
4776
4777                         /* Get local object */
4778                         q_ptr = &forge;
4779                         dummy = TV_SWORD;
4780                         switch (randint1(p_ptr->lev))
4781                         {
4782                                 case 0: case 1:
4783                                         dummy2 = SV_DAGGER;
4784                                         break;
4785                                 case 2: case 3:
4786                                         dummy2 = SV_MAIN_GAUCHE;
4787                                         break;
4788                                 case 4:
4789                                         dummy2 = SV_TANTO;
4790                                         break;
4791                                 case 5: case 6:
4792                                         dummy2 = SV_RAPIER;
4793                                         break;
4794                                 case 7: case 8:
4795                                         dummy2 = SV_SMALL_SWORD;
4796                                         break;
4797                                 case 9: case 10:
4798                                         dummy2 = SV_BASILLARD;
4799                                         break;
4800                                 case 11: case 12: case 13:
4801                                         dummy2 = SV_SHORT_SWORD;
4802                                         break;
4803                                 case 14: case 15:
4804                                         dummy2 = SV_SABRE;
4805                                         break;
4806                                 case 16: case 17:
4807                                         dummy2 = SV_CUTLASS;
4808                                         break;
4809                                 case 18:
4810                                         dummy2 = SV_WAKIZASHI;
4811                                         break;
4812                                 case 19:
4813                                         dummy2 = SV_KHOPESH;
4814                                         break;
4815                                 case 20:
4816                                         dummy2 = SV_TULWAR;
4817                                         break;
4818                                 case 21:
4819                                         dummy2 = SV_BROAD_SWORD;
4820                                         break;
4821                                 case 22: case 23:
4822                                         dummy2 = SV_LONG_SWORD;
4823                                         break;
4824                                 case 24: case 25:
4825                                         dummy2 = SV_SCIMITAR;
4826                                         break;
4827                                 case 26:
4828                                         dummy2 = SV_NINJATO;
4829                                         break;
4830                                 case 27:
4831                                         dummy2 = SV_KATANA;
4832                                         break;
4833                                 case 28: case 29:
4834                                         dummy2 = SV_BASTARD_SWORD;
4835                                         break;
4836                                 case 30:
4837                                         dummy2 = SV_GREAT_SCIMITAR;
4838                                         break;
4839                                 case 31:
4840                                         dummy2 = SV_CLAYMORE;
4841                                         break;
4842                                 case 32:
4843                                         dummy2 = SV_ESPADON;
4844                                         break;
4845                                 case 33:
4846                                         dummy2 = SV_TWO_HANDED_SWORD;
4847                                         break;
4848                                 case 34:
4849                                         dummy2 = SV_FLAMBERGE;
4850                                         break;
4851                                 case 35:
4852                                         dummy2 = SV_NO_DACHI;
4853                                         break;
4854                                 case 36:
4855                                         dummy2 = SV_EXECUTIONERS_SWORD;
4856                                         break;
4857                                 case 37:
4858                                         dummy2 = SV_ZWEIHANDER;
4859                                         break;
4860                                 case 38:
4861                                         dummy2 = SV_HAYABUSA;
4862                                         break;
4863                                 default:
4864                                         dummy2 = SV_BLADE_OF_CHAOS;
4865                         }
4866
4867                         object_prep(q_ptr, lookup_kind(dummy, dummy2));
4868                         q_ptr->to_h = 3 + randint1(dun_level) % 10;
4869                         q_ptr->to_d = 3 + randint1(dun_level) % 10;
4870                         one_resistance(q_ptr);
4871                         q_ptr->name2 = EGO_CHAOTIC;
4872
4873                         /* Drop it in the dungeon */
4874                         (void)drop_near(q_ptr, -1, py, px);
4875                         reward = _("(混沌)の武器を手に入れた。", "chaos weapon");
4876                         break;
4877                 case REW_GOOD_OBS:
4878 #ifdef JP
4879 msg_format("%sの声が響き渡った:",
4880                                 chaos_patrons[p_ptr->chaos_patron]);
4881 #else
4882                         msg_format("The voice of %s booms out:",
4883                                 chaos_patrons[p_ptr->chaos_patron]);
4884 #endif
4885
4886                         msg_print(_("「汝の行いは貴き報いに値せり。」", "'Thy deed hath earned thee a worthy reward.'"));
4887
4888                         acquirement(py, px, randint1(2) + 1, FALSE, FALSE, FALSE);
4889                         reward = _("上質なアイテムを手に入れた。", "good items");
4890                         break;
4891                 case REW_GREA_OBS:
4892 #ifdef JP
4893 msg_format("%sの声が響き渡った:",
4894                                 chaos_patrons[p_ptr->chaos_patron]);
4895 #else
4896                         msg_format("The voice of %s booms out:",
4897                                 chaos_patrons[p_ptr->chaos_patron]);
4898 #endif
4899
4900                         msg_print(_("「下僕よ、汝の献身への我が惜しみ無き報いを見るがよい。」", "'Behold, mortal, how generously I reward thy loyalty.'"));
4901
4902                         acquirement(py, px, randint1(2) + 1, TRUE, FALSE, FALSE);
4903                         reward = _("高級品のアイテムを手に入れた。", "excellent items");
4904                         break;
4905                 case REW_TY_CURSE:
4906 #ifdef JP
4907 msg_format("%sの声が轟き渡った:",
4908                                 chaos_patrons[p_ptr->chaos_patron]);
4909 #else
4910                         msg_format("The voice of %s thunders:",
4911                                 chaos_patrons[p_ptr->chaos_patron]);
4912 #endif
4913
4914                         msg_print(_("「下僕よ、汝傲慢なり。」", "'Thou art growing arrogant, mortal.'"));
4915
4916                         (void)activate_ty_curse(FALSE, &count);
4917                         reward = _("禍々しい呪いをかけられた。", "cursing");
4918                         break;
4919                 case REW_SUMMON_M:
4920 #ifdef JP
4921 msg_format("%sの声が響き渡った:",
4922                                 chaos_patrons[p_ptr->chaos_patron]);
4923 #else
4924                         msg_format("The voice of %s booms out:",
4925                                 chaos_patrons[p_ptr->chaos_patron]);
4926 #endif
4927
4928                         msg_print(_("「我が下僕たちよ、かの傲慢なる者を倒すべし!」", "'My pets, destroy the arrogant mortal!'"));
4929
4930                         for (dummy = 0; dummy < randint1(5) + 1; dummy++)
4931                         {
4932                                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
4933                         }
4934                         reward = _("モンスターを召喚された。", "summoning hostile monsters");
4935                         break;
4936                 case REW_H_SUMMON:
4937 #ifdef JP
4938 msg_format("%sの声が響き渡った:",
4939                                 chaos_patrons[p_ptr->chaos_patron]);
4940 #else
4941                         msg_format("The voice of %s booms out:",
4942                                 chaos_patrons[p_ptr->chaos_patron]);
4943 #endif
4944
4945                         msg_print(_("「汝、より強き敵を必要とせり!」", "'Thou needst worthier opponents!'"));
4946
4947                         activate_hi_summon(py, px, FALSE);
4948                         reward = _("モンスターを召喚された。", "summoning many hostile monsters");
4949                         break;
4950                 case REW_DO_HAVOC:
4951 #ifdef JP
4952 msg_format("%sの声が響き渡った:",
4953                                 chaos_patrons[p_ptr->chaos_patron]);
4954 #else
4955                         msg_format("The voice of %s booms out:",
4956                                 chaos_patrons[p_ptr->chaos_patron]);
4957 #endif
4958
4959                         msg_print(_("「死と破壊こそ我が喜びなり!」", "'Death and destruction! This pleaseth me!'"));
4960
4961                         call_chaos();
4962                         reward = _("カオスの力が渦巻いた。", "calling chaos");
4963                         break;
4964                 case REW_GAIN_ABL:
4965 #ifdef JP
4966 msg_format("%sの声が鳴り響いた:",
4967                                 chaos_patrons[p_ptr->chaos_patron]);
4968 #else
4969                         msg_format("The voice of %s rings out:",
4970                                 chaos_patrons[p_ptr->chaos_patron]);
4971 #endif
4972
4973                         msg_print(_("「留まるのだ、下僕よ。余が汝の肉体を鍛えん。」", "'Stay, mortal, and let me mold thee.'"));
4974
4975                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
4976                                 do_inc_stat(chaos_stats[p_ptr->chaos_patron]);
4977                         else
4978                                 do_inc_stat(randint0(6));
4979                         reward = _("能力値が上がった。", "increasing a stat");
4980                         break;
4981                 case REW_LOSE_ABL:
4982 #ifdef JP
4983 msg_format("%sの声が響き渡った:",
4984                                 chaos_patrons[p_ptr->chaos_patron]);
4985 #else
4986                         msg_format("The voice of %s booms out:",
4987                                 chaos_patrons[p_ptr->chaos_patron]);
4988 #endif
4989
4990                         msg_print(_("「下僕よ、余は汝に飽みたり。」", "'I grow tired of thee, mortal.'"));
4991
4992                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
4993                                 do_dec_stat(chaos_stats[p_ptr->chaos_patron]);
4994                         else
4995                                 (void)do_dec_stat(randint0(6));
4996                         reward = _("能力値が下がった。", "decreasing a stat");
4997                         break;
4998                 case REW_RUIN_ABL:
4999 #ifdef JP
5000 msg_format("%sの声が轟き渡った:",
5001                                 chaos_patrons[p_ptr->chaos_patron]);
5002 #else
5003                         msg_format("The voice of %s thunders:",
5004                                 chaos_patrons[p_ptr->chaos_patron]);
5005 #endif
5006
5007                         msg_print(_("「汝、謙虚たることを学ぶべし!」", "'Thou needst a lesson in humility, mortal!'"));
5008                         msg_print(_("あなたは以前より弱くなった!", "You feel less powerful!"));
5009
5010                         for (dummy = 0; dummy < 6; dummy++)
5011                         {
5012                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5013                         }
5014                         reward = _("全能力値が下がった。", "decreasing all stats");
5015                         break;
5016                 case REW_POLY_WND:
5017                         msg_format(_("%sの力が触れるのを感じた。", "You feel the power of %s touch you."),
5018
5019                                 chaos_patrons[p_ptr->chaos_patron]);
5020                         do_poly_wounds();
5021                         reward = _("傷が変化した。", "polymorphing wounds");
5022                         break;
5023                 case REW_AUGM_ABL:
5024 #ifdef JP
5025 msg_format("%sの声が響き渡った:",
5026                                 chaos_patrons[p_ptr->chaos_patron]);
5027 #else
5028                         msg_format("The voice of %s booms out:",
5029                                 chaos_patrons[p_ptr->chaos_patron]);
5030 #endif
5031
5032                         msg_print(_("「我がささやかなる賜物を受けとるがよい!」", "'Receive this modest gift from me!'"));
5033
5034                         for (dummy = 0; dummy < 6; dummy++)
5035                         {
5036                                 (void)do_inc_stat(dummy);
5037                         }
5038                         reward = _("全能力値が上がった。", "increasing all stats");
5039                         break;
5040                 case REW_HURT_LOT:
5041 #ifdef JP
5042 msg_format("%sの声が響き渡った:",
5043                                 chaos_patrons[p_ptr->chaos_patron]);
5044 #else
5045                         msg_format("The voice of %s booms out:",
5046                                 chaos_patrons[p_ptr->chaos_patron]);
5047 #endif
5048
5049                         msg_print(_("「苦しむがよい、無能な愚か者よ!」", "'Suffer, pathetic fool!'"));
5050
5051                         fire_ball(GF_DISINTEGRATE, 0, p_ptr->lev * 4, 4);
5052                         take_hit(DAMAGE_NOESCAPE, p_ptr->lev * 4, wrath_reason, -1);
5053                         reward = _("分解の球が発生した。", "generating disintegration ball");
5054                         break;
5055            case REW_HEAL_FUL:
5056 #ifdef JP
5057 msg_format("%sの声が響き渡った:",
5058                                 chaos_patrons[p_ptr->chaos_patron]);
5059 #else
5060                         msg_format("The voice of %s booms out:",
5061                                 chaos_patrons[p_ptr->chaos_patron]);
5062 #endif
5063
5064                         msg_print(_("「甦るがよい、我が下僕よ!」", "'Rise, my servant!'"));
5065
5066                         restore_level();
5067                         (void)set_poisoned(0);
5068                         (void)set_blind(0);
5069                         (void)set_confused(0);
5070                         (void)set_image(0);
5071                         (void)set_stun(0);
5072                         (void)set_cut(0);
5073                         hp_player(5000);
5074                         for (dummy = 0; dummy < 6; dummy++)
5075                         {
5076                                 (void)do_res_stat(dummy);
5077                         }
5078                         reward = _("体力が回復した。", "healing");
5079                         break;
5080                 case REW_CURSE_WP:
5081                         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
5082 #ifdef JP
5083 msg_format("%sの声が響き渡った:",
5084                                 chaos_patrons[p_ptr->chaos_patron]);
5085 #else
5086                         msg_format("The voice of %s booms out:",
5087                                 chaos_patrons[p_ptr->chaos_patron]);
5088 #endif
5089
5090                         msg_print(_("「汝、武器に頼ることなかれ。」", "'Thou reliest too much on thy weapon.'"));
5091
5092                         dummy = INVEN_RARM;
5093                         if (buki_motteruka(INVEN_LARM))
5094                         {
5095                                 dummy = INVEN_LARM;
5096                                 if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
5097                         }
5098                         object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
5099                         (void)curse_weapon(FALSE, dummy);
5100                         reward = format(_("%sが破壊された。", "destroying %s"), o_name);
5101                         break;
5102                 case REW_CURSE_AR:
5103                         if (!inventory[INVEN_BODY].k_idx) break;
5104 #ifdef JP
5105 msg_format("%sの声が響き渡った:",
5106                                 chaos_patrons[p_ptr->chaos_patron]);
5107 #else
5108                         msg_format("The voice of %s booms out:",
5109                                 chaos_patrons[p_ptr->chaos_patron]);
5110 #endif
5111
5112                         msg_print(_("「汝、防具に頼ることなかれ。」", "'Thou reliest too much on thine equipment.'"));
5113
5114                         object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
5115                         (void)curse_armor();
5116                         reward = format(_("%sが破壊された。", "destroying %s"), o_name);
5117                         break;
5118                 case REW_PISS_OFF:
5119 #ifdef JP
5120 msg_format("%sの声がささやいた:",
5121                                 chaos_patrons[p_ptr->chaos_patron]);
5122 #else
5123                         msg_format("The voice of %s whispers:",
5124                                 chaos_patrons[p_ptr->chaos_patron]);
5125 #endif
5126
5127                         msg_print(_("「我を怒りしめた罪を償うべし。」", "'Now thou shalt pay for annoying me.'"));
5128
5129                         switch (randint1(4))
5130                         {
5131                                 case 1:
5132                                         (void)activate_ty_curse(FALSE, &count);
5133                                         reward = _("禍々しい呪いをかけられた。", "cursing");
5134                                         break;
5135                                 case 2:
5136                                         activate_hi_summon(py, px, FALSE);
5137                                         reward = _("モンスターを召喚された。", "summoning hostile monsters");
5138                                         break;
5139                                 case 3:
5140                                         if (one_in_(2))
5141                                         {
5142                                                 if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
5143                                                 dummy = INVEN_RARM;
5144                                                 if (buki_motteruka(INVEN_LARM))
5145                                                 {
5146                                                         dummy = INVEN_LARM;
5147                                                         if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
5148                                                 }
5149                                                 object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
5150                                                 (void)curse_weapon(FALSE, dummy);
5151                                                 reward = format(_("%sが破壊された。", "destroying %s"), o_name);
5152                                         }
5153                                         else
5154                                         {
5155                                                 if (!inventory[INVEN_BODY].k_idx) break;
5156                                                 object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
5157                                                 (void)curse_armor();
5158                                                 reward = format(_("%sが破壊された。", "destroying %s"), o_name);
5159                                         }
5160                                         break;
5161                                 default:
5162                                         for (dummy = 0; dummy < 6; dummy++)
5163                                         {
5164                                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5165                                         }
5166                                         reward = _("全能力値が下がった。", "decreasing all stats");
5167                                         break;
5168                         }
5169                         break;
5170                 case REW_WRATH:
5171                         msg_format(_("%sの声が轟き渡った:", "The voice of %s thunders:"),
5172
5173                                 chaos_patrons[p_ptr->chaos_patron]);
5174                         msg_print(_("「死ぬがよい、下僕よ!」", "'Die, mortal!'"));
5175
5176                         take_hit(DAMAGE_LOSELIFE, p_ptr->lev * 4, wrath_reason, -1);
5177                         for (dummy = 0; dummy < 6; dummy++)
5178                         {
5179                                 (void)dec_stat(dummy, 10 + randint1(15), FALSE);
5180                         }
5181                         activate_hi_summon(py, px, FALSE);
5182                         (void)activate_ty_curse(FALSE, &count);
5183                         if (one_in_(2))
5184                         {
5185                                 dummy = 0;
5186
5187                                 if (buki_motteruka(INVEN_RARM))
5188                                 {
5189                                         dummy = INVEN_RARM;
5190                                         if (buki_motteruka(INVEN_LARM) && one_in_(2)) dummy = INVEN_LARM;
5191                                 }
5192                                 else if (buki_motteruka(INVEN_LARM)) dummy = INVEN_LARM;
5193
5194                                 if (dummy) (void)curse_weapon(FALSE, dummy);
5195                         }
5196                         if (one_in_(2)) (void)curse_armor();
5197                         break;
5198                 case REW_DESTRUCT:
5199 #ifdef JP
5200 msg_format("%sの声が響き渡った:",
5201                                 chaos_patrons[p_ptr->chaos_patron]);
5202 #else
5203                         msg_format("The voice of %s booms out:",
5204                                 chaos_patrons[p_ptr->chaos_patron]);
5205 #endif
5206
5207                         msg_print(_("「死と破壊こそ我が喜びなり!」", "'Death and destruction! This pleaseth me!'"));
5208
5209                         (void)destroy_area(py, px, 25, FALSE);
5210                         reward = _("ダンジョンが*破壊*された。", "*destruct*ing dungeon");
5211                         break;
5212                 case REW_GENOCIDE:
5213 #ifdef JP
5214 msg_format("%sの声が響き渡った:",
5215                                 chaos_patrons[p_ptr->chaos_patron]);
5216 #else
5217                         msg_format("The voice of %s booms out:",
5218                                 chaos_patrons[p_ptr->chaos_patron]);
5219 #endif
5220
5221                         msg_print(_("「我、汝の敵を抹殺せん!」", "'Let me relieve thee of thine oppressors!'"));
5222
5223                         (void)symbol_genocide(0, FALSE);
5224                         reward = _("モンスターが抹殺された。", "genociding monsters");
5225                         break;
5226                 case REW_MASS_GEN:
5227 #ifdef JP
5228 msg_format("%sの声が響き渡った:",
5229                                 chaos_patrons[p_ptr->chaos_patron]);
5230 #else
5231                         msg_format("The voice of %s booms out:",
5232                                 chaos_patrons[p_ptr->chaos_patron]);
5233 #endif
5234
5235                         msg_print(_("「我、汝の敵を抹殺せん!」", "'Let me relieve thee of thine oppressors!'"));
5236
5237                         (void)mass_genocide(0, FALSE);
5238                         reward = _("モンスターが抹殺された。", "genociding nearby monsters");
5239                         break;
5240                 case REW_DISPEL_C:
5241 #ifdef JP
5242 msg_format("%sの力が敵を攻撃するのを感じた!",
5243                                 chaos_patrons[p_ptr->chaos_patron]);
5244 #else
5245                         msg_format("You can feel the power of %s assault your enemies!",
5246                                 chaos_patrons[p_ptr->chaos_patron]);
5247 #endif
5248
5249                         (void)dispel_monsters(p_ptr->lev * 4);
5250                         break;
5251                 case REW_IGNORE:
5252 #ifdef JP
5253 msg_format("%sはあなたを無視した。",
5254                                 chaos_patrons[p_ptr->chaos_patron]);
5255 #else
5256                         msg_format("%s ignores you.",
5257                                 chaos_patrons[p_ptr->chaos_patron]);
5258 #endif
5259
5260                         break;
5261                 case REW_SER_DEMO:
5262                         msg_format(_("%sは褒美として悪魔の使いをよこした!", "%s rewards you with a demonic servant!"),chaos_patrons[p_ptr->chaos_patron]);
5263
5264                         if (!summon_specific(-1, py, px, dun_level, SUMMON_DEMON, PM_FORCE_PET))
5265                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
5266                         else
5267                                 reward = _("悪魔がペットになった。", "a demonic servant");
5268
5269                         break;
5270                 case REW_SER_MONS:
5271                         msg_format(_("%sは褒美として使いをよこした!", "%s rewards you with a servant!"),chaos_patrons[p_ptr->chaos_patron]);
5272
5273                         if (!summon_specific(-1, py, px, dun_level, 0, PM_FORCE_PET))
5274                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
5275                         else
5276                                 reward = _("モンスターがペットになった。", "a servant");
5277
5278                         break;
5279                 case REW_SER_UNDE:
5280                         msg_format(_("%sは褒美としてアンデッドの使いをよこした。", "%s rewards you with an undead servant!"),chaos_patrons[p_ptr->chaos_patron]);
5281
5282                         if (!summon_specific(-1, py, px, dun_level, SUMMON_UNDEAD, PM_FORCE_PET))
5283                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
5284                         else
5285                                 reward = _("アンデッドがペットになった。", "an undead servant");
5286
5287                         break;
5288                 default:
5289                         msg_format(_("%sの声がどもった:", "The voice of %s stammers:"),
5290
5291                                 chaos_patrons[p_ptr->chaos_patron]);
5292                         msg_format(_("「あー、あー、答えは %d/%d。質問は何?」", "'Uh... uh... the answer's %d/%d, what's the question?'"), type, effect);
5293
5294         }
5295         }
5296         if (reward)
5297         {
5298                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format(_("パトロンの報酬で%s", "The patron rewards you with %s."), reward));
5299         }
5300 }
5301
5302
5303 /*
5304  * XAngband: determine if a given location is "interesting"
5305  * based on target_set_accept function.
5306  */
5307 static bool tgt_pt_accept(int y, int x)
5308 {
5309         cave_type *c_ptr;
5310
5311         /* Bounds */
5312         if (!(in_bounds(y, x))) return (FALSE);
5313
5314         /* Player grid is always interesting */
5315         if ((y == py) && (x == px)) return (TRUE);
5316
5317         /* Handle hallucination */
5318         if (p_ptr->image) return (FALSE);
5319
5320         /* Examine the grid */
5321         c_ptr = &cave[y][x];
5322
5323         /* Interesting memorized features */
5324         if (c_ptr->info & (CAVE_MARK))
5325         {
5326                 /* Notice stairs */
5327                 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
5328                 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
5329
5330                 /* Notice quest features */
5331                 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
5332                 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
5333         }
5334
5335         /* Nope */
5336         return (FALSE);
5337 }
5338
5339
5340 /*
5341  * XAngband: Prepare the "temp" array for "tget_pt"
5342  * based on target_set_prepare funciton.
5343  */
5344 static void tgt_pt_prepare(void)
5345 {
5346         int y, x;
5347
5348         /* Reset "temp" array */
5349         temp_n = 0;
5350
5351         if (!expand_list) return;
5352
5353         /* Scan the current panel */
5354         for (y = 1; y < cur_hgt; y++)
5355         {
5356                 for (x = 1; x < cur_wid; x++)
5357                 {
5358                         /* Require "interesting" contents */
5359                         if (!tgt_pt_accept(y, x)) continue;
5360
5361                         /* Save the location */
5362                         temp_x[temp_n] = x;
5363                         temp_y[temp_n] = y;
5364                         temp_n++;
5365                 }
5366         }
5367
5368         /* Target the nearest monster for shooting */
5369         ang_sort_comp = ang_sort_comp_distance;
5370         ang_sort_swap = ang_sort_swap_distance;
5371
5372         /* Sort the positions */
5373         ang_sort(temp_x, temp_y, temp_n);
5374 }
5375
5376 /*
5377  * old -- from PsiAngband.
5378  */
5379 bool tgt_pt(int *x_ptr, int *y_ptr)
5380 {
5381         char ch = 0;
5382         int d, x, y, n;
5383         bool success = FALSE;
5384
5385         int wid, hgt;
5386
5387         /* Get size */
5388         get_screen_size(&wid, &hgt);
5389
5390         x = px;
5391         y = py;
5392
5393         if (expand_list) 
5394         {
5395                 tgt_pt_prepare();
5396                 n = 0;
5397         }
5398
5399         msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
5400         msg_flag = FALSE; /* prevents "-more-" message. */
5401
5402         while ((ch != ESCAPE) && !success)
5403         {
5404                 bool move_fast = FALSE;
5405
5406                 move_cursor_relative(y, x);
5407                 ch = inkey();
5408                 switch (ch)
5409                 {
5410                 case ESCAPE:
5411                         break;
5412                 case ' ':
5413                 case 't':
5414                 case '.':
5415                 case '5':
5416                 case '0':
5417                         /* illegal place */
5418                         if (player_bold(y, x)) ch = 0;
5419
5420                         /* okay place */
5421                         else success = TRUE;
5422
5423                         break;
5424
5425                 /* XAngband: Move cursor to stairs */
5426                 case '>':
5427                 case '<':
5428                         if (expand_list && temp_n)
5429                         {
5430                                 int dx, dy;
5431                                 int cx = (panel_col_min + panel_col_max) / 2;
5432                                 int cy = (panel_row_min + panel_row_max) / 2;
5433
5434                                 n++;
5435
5436                                 /* Skip stairs which have defferent distance */
5437                                 for (; n < temp_n; ++ n)
5438                                 {
5439                                         cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
5440
5441                                         if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
5442                                             cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
5443                                         {
5444                                                 /* Found */
5445                                                 break;
5446                                         }
5447                                 }
5448
5449                                 if (n == temp_n)        /* Loop out taget list */
5450                                 {
5451                                         n = 0;
5452                                         y = py;
5453                                         x = px;
5454                                         verify_panel(); /* Move cursor to player */
5455
5456                                         /* Update stuff */
5457                                         p_ptr->update |= (PU_MONSTERS);
5458
5459                                         /* Redraw map */
5460                                         p_ptr->redraw |= (PR_MAP);
5461
5462                                         /* Window stuff */
5463                                         p_ptr->window |= (PW_OVERHEAD);
5464
5465                                         /* Handle stuff */
5466                                         handle_stuff();
5467                                 }
5468                                 else    /* move cursor to next stair and change panel */
5469                                 {
5470                                         y = temp_y[n];
5471                                         x = temp_x[n];
5472
5473                                         dy = 2 * (y - cy) / hgt;
5474                                         dx = 2 * (x - cx) / wid;
5475                                         if (dy || dx) change_panel(dy, dx);
5476                                 }
5477                         }
5478                         break;
5479
5480                 default:
5481                         /* Look up the direction */
5482                         d = get_keymap_dir(ch);
5483
5484                         /* XTRA HACK MOVEFAST */
5485                         if (isupper(ch)) move_fast = TRUE;
5486
5487                         /* Handle "direction" */
5488                         if (d)
5489                         {
5490                                 int dx = ddx[d];
5491                                 int dy = ddy[d];
5492
5493                                 /* XTRA HACK MOVEFAST */
5494                                 if (move_fast)
5495                                 {
5496                                         int mag = MIN(wid / 2, hgt / 2);
5497                                         x += dx * mag;
5498                                         y += dy * mag;
5499                                 }
5500                                 else
5501                                 {
5502                                         x += dx;
5503                                         y += dy;
5504                                 }
5505
5506                                 /* Do not move horizontally if unnecessary */
5507                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
5508                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
5509                                 {
5510                                         dx = 0;
5511                                 }
5512
5513                                 /* Do not move vertically if unnecessary */
5514                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
5515                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
5516                                 {
5517                                         dy = 0;
5518                                 }
5519
5520                                 /* Apply the motion */
5521                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
5522                                          (x >= panel_col_min + wid) || (x < panel_col_min))
5523                                 {
5524                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
5525                                         change_panel(dy, dx);
5526                                 }
5527
5528                                 /* Slide into legality */
5529                                 if (x >= cur_wid-1) x = cur_wid - 2;
5530                                 else if (x <= 0) x = 1;
5531
5532                                 /* Slide into legality */
5533                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
5534                                 else if (y <= 0) y = 1;
5535
5536                         }
5537                         break;
5538                 }
5539         }
5540
5541         /* Clear the top line */
5542         prt("", 0, 0);
5543
5544         /* Recenter the map around the player */
5545         verify_panel();
5546
5547         /* Update stuff */
5548         p_ptr->update |= (PU_MONSTERS);
5549
5550         /* Redraw map */
5551         p_ptr->redraw |= (PR_MAP);
5552
5553         /* Window stuff */
5554         p_ptr->window |= (PW_OVERHEAD);
5555
5556         /* Handle stuff */
5557         handle_stuff();
5558
5559         *x_ptr = x;
5560         *y_ptr = y;
5561         return success;
5562 }
5563
5564
5565 bool get_hack_dir(int *dp)
5566 {
5567         int             dir;
5568         cptr    p;
5569         char    command;
5570
5571
5572         /* Initialize */
5573         (*dp) = 0;
5574
5575         /* Global direction */
5576         dir = 0;
5577
5578         /* (No auto-targeting) */
5579
5580         /* Ask until satisfied */
5581         while (!dir)
5582         {
5583                 /* Choose a prompt */
5584                 if (!target_okay())
5585                 {
5586                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
5587                 }
5588                 else
5589                 {
5590                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
5591                 }
5592
5593                 /* Get a command (or Cancel) */
5594                 if (!get_com(p, &command, TRUE)) break;
5595
5596                 if (use_menu)
5597                 {
5598                         if (command == '\r') command = 't';
5599                 }  
5600
5601                 /* Convert various keys to "standard" keys */
5602                 switch (command)
5603                 {
5604                         /* Use current target */
5605                         case 'T':
5606                         case 't':
5607                         case '.':
5608                         case '5':
5609                         case '0':
5610                         {
5611                                 dir = 5;
5612                                 break;
5613                         }
5614
5615                         /* Set new target */
5616                         case '*':
5617                         case ' ':
5618                         case '\r':
5619                         {
5620                                 if (target_set(TARGET_KILL)) dir = 5;
5621                                 break;
5622                         }
5623
5624                         default:
5625                         {
5626                                 /* Look up the direction */
5627                                 dir = get_keymap_dir(command);
5628
5629                                 break;
5630                         }
5631                 }
5632
5633                 /* Verify requested targets */
5634                 if ((dir == 5) && !target_okay()) dir = 0;
5635
5636                 /* Error */
5637                 if (!dir) bell();
5638         }
5639
5640         /* No direction */
5641         if (!dir) return (FALSE);
5642
5643         /* Save the direction */
5644         command_dir = dir;
5645
5646         /* Check for confusion */
5647         if (p_ptr->confused)
5648         {
5649                 /* XXX XXX XXX */
5650                 /* Random direction */
5651                 dir = ddd[randint0(8)];
5652         }
5653
5654         /* Notice confusion */
5655         if (command_dir != dir)
5656         {
5657                 /* Warn the user */
5658                 msg_print(_("あなたは混乱している。", "You are confused."));
5659         }
5660
5661         /* Save direction */
5662         (*dp) = dir;
5663
5664         /* A "valid" direction was entered */
5665         return (TRUE);
5666 }
5667
5668
5669 /*
5670  * エネルギーの増加量10d5を速く計算するための関数
5671  */
5672
5673 #define Go_no_JuuJou 5*5*5*5*5*5*5*5*5*5
5674
5675 s16b gain_energy(void)
5676 {
5677         int i;
5678         s32b energy_result = 10;
5679         s32b tmp;
5680
5681         tmp = randint0(Go_no_JuuJou);
5682
5683         for (i = 0; i < 9; i ++){
5684                 energy_result += tmp % 5;
5685                 tmp /= 5;
5686         }
5687
5688         return (s16b)(energy_result + tmp);
5689 }
5690
5691
5692 /*
5693  * Return bow energy 
5694  */
5695 s16b bow_energy(int sval)
5696 {
5697         int energy = 100;
5698
5699         /* Analyze the launcher */
5700         switch (sval)
5701         {
5702                 /* Sling and ammo */
5703                 case SV_SLING:
5704                 {
5705                         energy = 8000;
5706                         break;
5707                 }
5708
5709                 /* Short Bow and Arrow */
5710                 case SV_SHORT_BOW:
5711                 {
5712                         energy = 10000;
5713                         break;
5714                 }
5715
5716                 /* Long Bow and Arrow */
5717                 case SV_LONG_BOW:
5718                 {
5719                         energy = 10000;
5720                         break;
5721                 }
5722
5723                 /* Bow of irresponsiblity and Arrow */
5724                 case SV_NAMAKE_BOW:
5725                 {
5726                         energy = 7777;
5727                         break;
5728                 }
5729
5730                 /* Light Crossbow and Bolt */
5731                 case SV_LIGHT_XBOW:
5732                 {
5733                         energy = 12000;
5734                         break;
5735                 }
5736
5737                 /* Heavy Crossbow and Bolt */
5738                 case SV_HEAVY_XBOW:
5739                 {
5740                         energy = 13333;
5741                         break;
5742                 }
5743         }
5744
5745         return (energy);
5746 }
5747
5748
5749 /*
5750  * Return bow tmul
5751  */
5752 int bow_tmul(int sval)
5753 {
5754         int tmul = 0;
5755
5756         /* Analyze the launcher */
5757         switch (sval)
5758         {
5759                 /* Sling and ammo */
5760                 case SV_SLING:
5761                 {
5762                         tmul = 2;
5763                         break;
5764                 }
5765
5766                 /* Short Bow and Arrow */
5767                 case SV_SHORT_BOW:
5768                 {
5769                         tmul = 2;
5770                         break;
5771                 }
5772
5773                 /* Long Bow and Arrow */
5774                 case SV_LONG_BOW:
5775                 {
5776                         tmul = 3;
5777                         break;
5778                 }
5779
5780                 /* Bow of irresponsiblity and Arrow */
5781                 case SV_NAMAKE_BOW:
5782                 {
5783                         tmul = 3;
5784                         break;
5785                 }
5786
5787                 /* Light Crossbow and Bolt */
5788                 case SV_LIGHT_XBOW:
5789                 {
5790                         tmul = 3;
5791                         break;
5792                 }
5793
5794                 /* Heavy Crossbow and Bolt */
5795                 case SV_HEAVY_XBOW:
5796                 {
5797                         tmul = 4;
5798                         break;
5799                 }
5800         }
5801
5802         return (tmul);
5803 }
5804
5805 /*
5806  * Return alignment title
5807  */
5808 cptr your_alignment(void)
5809 {
5810 #ifdef JP
5811         if (p_ptr->align > 150) return "大善";
5812         else if (p_ptr->align > 50) return "中善";
5813         else if (p_ptr->align > 10) return "小善";
5814         else if (p_ptr->align > -11) return "中立";
5815         else if (p_ptr->align > -51) return "小悪";
5816         else if (p_ptr->align > -151) return "中悪";
5817         else return "大悪";
5818 #else
5819         if (p_ptr->align > 150) return "Lawful";
5820         else if (p_ptr->align > 50) return "Good";
5821         else if (p_ptr->align > 10) return "Neutral Good";
5822         else if (p_ptr->align > -11) return "Neutral";
5823         else if (p_ptr->align > -51) return "Neutral Evil";
5824         else if (p_ptr->align > -151) return "Evil";
5825         else return "Chaotic";
5826 #endif
5827 }
5828
5829
5830 /*
5831  * Return proficiency level of weapons and misc. skills (except riding)
5832  */
5833 int weapon_exp_level(int weapon_exp)
5834 {
5835         if (weapon_exp < WEAPON_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5836         else if (weapon_exp < WEAPON_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5837         else if (weapon_exp < WEAPON_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5838         else if (weapon_exp < WEAPON_EXP_MASTER) return EXP_LEVEL_EXPERT;
5839         else return EXP_LEVEL_MASTER;
5840 }
5841
5842
5843 /*
5844  * Return proficiency level of riding
5845  */
5846 int riding_exp_level(int riding_exp)
5847 {
5848         if (riding_exp < RIDING_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5849         else if (riding_exp < RIDING_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5850         else if (riding_exp < RIDING_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5851         else if (riding_exp < RIDING_EXP_MASTER) return EXP_LEVEL_EXPERT;
5852         else return EXP_LEVEL_MASTER;
5853 }
5854
5855
5856 /*
5857  * Return proficiency level of spells
5858  */
5859 int spell_exp_level(int spell_exp)
5860 {
5861         if (spell_exp < SPELL_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5862         else if (spell_exp < SPELL_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5863         else if (spell_exp < SPELL_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5864         else if (spell_exp < SPELL_EXP_MASTER) return EXP_LEVEL_EXPERT;
5865         else return EXP_LEVEL_MASTER;
5866 }
5867
5868
5869 /*
5870  * Display a rumor and apply its effects
5871  */
5872
5873 int rumor_num(char *zz, int max_idx)
5874 {
5875         if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
5876         return atoi(zz);
5877 }
5878
5879 cptr rumor_bind_name(char *base, cptr fullname)
5880 {
5881         char *s, *v;
5882
5883         s = strstr(base, "{Name}");
5884         if (s)
5885         {
5886                 s[0] = '\0';
5887                 v = format("%s%s%s", base, fullname, (s + 6));
5888         }
5889         else
5890         {
5891                 v = base;
5892         }
5893
5894         return v;
5895 }
5896
5897 void display_rumor(bool ex)
5898 {
5899         bool err;
5900         int section = 0;
5901         char Rumor[1024];
5902
5903         if (ex)
5904         {
5905                 if (randint0(3) == 0) section = 1;
5906         }
5907
5908         err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
5909                         get_rnd_line("rumors.txt", section, Rumor));
5910         if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
5911
5912         err = TRUE;
5913
5914         if (strncmp(Rumor, "R:", 2) == 0)
5915         {
5916                 char *zz[4];
5917                 cptr rumor_msg = NULL;
5918                 cptr rumor_eff_format = NULL;
5919                 char fullname[1024] = "";
5920
5921                 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
5922                 {
5923                         if (strcmp(zz[0], "ARTIFACT") == 0)
5924                         {
5925                                 int a_idx, k_idx;
5926                                 object_type forge;
5927                                 object_type *q_ptr = &forge;
5928                                 artifact_type *a_ptr;
5929
5930                                 while (1)
5931                                 {
5932                                         a_idx = rumor_num(zz[1], max_a_idx);
5933
5934                                         a_ptr = &a_info[a_idx];
5935                                         if (a_ptr->name) break;
5936                                 }
5937
5938                                 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
5939                                 object_prep(q_ptr, k_idx);
5940                                 q_ptr->name1 = a_idx;
5941                                 q_ptr->ident = IDENT_STORE;
5942                                 object_desc(fullname, q_ptr, OD_NAME_ONLY);
5943                         }
5944                         else if  (strcmp(zz[0], "MONSTER") == 0)
5945                         {
5946                                 int r_idx;
5947                                 monster_race *r_ptr;
5948
5949                                 while(1)
5950                                 {
5951                                         r_idx = rumor_num(zz[1], max_r_idx);
5952                                         r_ptr = &r_info[r_idx];
5953                                         if (r_ptr->name) break;
5954                                 }
5955
5956                                 strcpy(fullname, r_name + r_ptr->name);
5957
5958                                 /* Remember this monster */
5959                                 if (!r_ptr->r_sights)
5960                                 {
5961                                         r_ptr->r_sights++;
5962                                 }
5963                         }
5964                         else if  (strcmp(zz[0], "DUNGEON") == 0)
5965                         {
5966                                 int d_idx;
5967                                 dungeon_info_type *d_ptr;
5968
5969                                 while (1)
5970                                 {
5971                                         d_idx = rumor_num(zz[1], max_d_idx);
5972                                         d_ptr = &d_info[d_idx];
5973                                         if (d_ptr->name) break;
5974                                 }
5975
5976                                 strcpy(fullname, d_name + d_ptr->name);
5977
5978                                 if (!max_dlv[d_idx])
5979                                 {
5980                                         max_dlv[d_idx] = d_ptr->mindepth;
5981                                         rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
5982                                 }
5983                         }
5984                         else if  (strcmp(zz[0], "TOWN") == 0)
5985                         {
5986                                 int t_idx;
5987                                 s32b visit;
5988
5989                                 while(1)
5990                                 {
5991                                         t_idx = rumor_num(zz[1], NO_TOWN);
5992                                         if (town[t_idx].name) break;
5993                                 }
5994
5995                                 strcpy(fullname, town[t_idx].name);
5996
5997                                 visit = (1L << (t_idx - 1));
5998                                 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
5999                                 {
6000                                         p_ptr->visit |= visit;
6001                                         rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
6002                                 }
6003                         }
6004
6005                         rumor_msg = rumor_bind_name(zz[2], fullname);
6006                         msg_print(rumor_msg);
6007                         if (rumor_eff_format)
6008                         {
6009                                 msg_print(NULL);
6010                                 msg_format(rumor_eff_format, fullname);
6011                         }
6012                         err = FALSE;
6013                 }
6014         /* error */
6015         if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
6016         }
6017                         else
6018         {
6019                 msg_format("%s", Rumor);
6020         }
6021 }