OSDN Git Service

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