OSDN Git Service

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