OSDN Git Service

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