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