OSDN Git Service

Merge branch 'master' into MERFOLK
[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 #include "monsterrace-hook.h"
18
19 #define REWARD_CHANCE 10
20
21
22 /*!
23  * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
24  * Advance experience levels and print experience
25  * @return なし
26  */
27 void check_experience(void)
28 {
29         bool level_reward = FALSE;
30         bool level_mutation = FALSE;
31         bool level_inc_stat = FALSE;
32         bool android = (p_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
33         PLAYER_LEVEL old_lev = p_ptr->lev;
34
35         /* Hack -- lower limit */
36         if (p_ptr->exp < 0) p_ptr->exp = 0;
37         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
38         if (p_ptr->max_max_exp < 0) p_ptr->max_max_exp = 0;
39
40         /* Hack -- upper limit */
41         if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
42         if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
43         if (p_ptr->max_max_exp > PY_MAX_EXP) p_ptr->max_max_exp = PY_MAX_EXP;
44
45         /* Hack -- maintain "max" experience */
46         if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
47
48         /* Hack -- maintain "max max" experience */
49         if (p_ptr->max_exp > p_ptr->max_max_exp) p_ptr->max_max_exp = p_ptr->max_exp;
50
51         /* Redraw experience */
52         p_ptr->redraw |= (PR_EXP);
53         handle_stuff();
54
55
56         /* Lose levels while possible */
57         while ((p_ptr->lev > 1) &&
58                (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
59         {
60                 /* Lose a level */
61                 p_ptr->lev--;
62                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
63                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
64                 p_ptr->window |= (PW_PLAYER);
65                 handle_stuff();
66         }
67
68
69         /* Gain levels while possible */
70         while ((p_ptr->lev < PY_MAX_LEVEL) &&
71                (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
72         {
73                 /* Gain a level */
74                 p_ptr->lev++;
75
76                 /* Save the highest level */
77                 if (p_ptr->lev > p_ptr->max_plv)
78                 {
79                         p_ptr->max_plv = p_ptr->lev;
80
81                         if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
82                             (p_ptr->muta2 & MUT2_CHAOS_GIFT))
83                         {
84                                 level_reward = TRUE;
85                         }
86                         if (p_ptr->prace == RACE_BEASTMAN)
87                         {
88                                 if (one_in_(5)) level_mutation = TRUE;
89                         }
90                         level_inc_stat = TRUE;
91
92                         do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
93                 }
94
95                 sound(SOUND_LEVEL);
96
97                 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), p_ptr->lev);
98
99                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
100                 p_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
101                 p_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
102
103                 /* HPとMPの上昇量を表示 */
104                 level_up = 1;
105                 handle_stuff();
106
107                 level_up = 0;
108
109                 if (level_inc_stat)
110                 {
111                         if(!(p_ptr->max_plv % 10))
112                         {
113                                 int choice;
114                                 screen_save();
115                                 while(1)
116                                 {
117                                         int n;
118                                         char tmp[32];
119
120 #ifdef JP
121                                         cnv_stat(p_ptr->stat_max[0], tmp);
122                                         prt(format("        a) 腕力 (現在値 %s)", tmp), 2, 14);
123                                         cnv_stat(p_ptr->stat_max[1], tmp);
124                                         prt(format("        b) 知能 (現在値 %s)", tmp), 3, 14);
125                                         cnv_stat(p_ptr->stat_max[2], tmp);
126                                         prt(format("        c) 賢さ (現在値 %s)", tmp), 4, 14);
127                                         cnv_stat(p_ptr->stat_max[3], tmp);
128                                         prt(format("        d) 器用 (現在値 %s)", tmp), 5, 14);
129                                         cnv_stat(p_ptr->stat_max[4], tmp);
130                                         prt(format("        e) 耐久 (現在値 %s)", tmp), 6, 14);
131                                         cnv_stat(p_ptr->stat_max[5], tmp);
132                                         prt(format("        f) 魅力 (現在値 %s)", tmp), 7, 14);
133                                         prt("", 8, 14);
134                                         prt("        どの能力値を上げますか?", 1, 14);
135 #else
136                                         cnv_stat(p_ptr->stat_max[0], tmp);
137                                         prt(format("        a) Str (cur %s)", tmp), 2, 14);
138                                         cnv_stat(p_ptr->stat_max[1], tmp);
139                                         prt(format("        b) Int (cur %s)", tmp), 3, 14);
140                                         cnv_stat(p_ptr->stat_max[2], tmp);
141                                         prt(format("        c) Wis (cur %s)", tmp), 4, 14);
142                                         cnv_stat(p_ptr->stat_max[3], tmp);
143                                         prt(format("        d) Dex (cur %s)", tmp), 5, 14);
144                                         cnv_stat(p_ptr->stat_max[4], tmp);
145                                         prt(format("        e) Con (cur %s)", tmp), 6, 14);
146                                         cnv_stat(p_ptr->stat_max[5], tmp);
147                                         prt(format("        f) Chr (cur %s)", tmp), 7, 14);
148                                         prt("", 8, 14);
149                                         prt("        Which stat do you want to raise?", 1, 14);
150 #endif
151                                         while(1)
152                                         {
153                                                 choice = inkey();
154                                                 if ((choice >= 'a') && (choice <= 'f')) break;
155                                         }
156                                         for(n = 0; n < 6; n++)
157                                                 if (n != choice - 'a')
158                                                         prt("",n+2,14);
159                                         if (get_check(_("よろしいですか?", "Are you sure? "))) break;
160                                 }
161                                 do_inc_stat(choice - 'a');
162                                 screen_load();
163                         }
164                         else if(!(p_ptr->max_plv % 2))
165                                 do_inc_stat(randint0(6));
166                 }
167
168                 if (level_mutation)
169                 {
170                         msg_print(_("あなたは変わった気がする...", "You feel different..."));
171                         (void)gain_random_mutation(0);
172                         level_mutation = FALSE;
173                 }
174
175                 /*
176                  * 報酬でレベルが上ると再帰的に check_experience() が
177                  * 呼ばれるので順番を最後にする。
178                  */
179                 if (level_reward)
180                 {
181                         gain_level_reward(0);
182                         level_reward = FALSE;
183                 }
184
185                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
186                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
187                 p_ptr->window |= (PW_PLAYER | PW_SPELL);
188                 handle_stuff();
189         }
190
191         /* Load an autopick preference file */
192         if (old_lev != p_ptr->lev) autopick_load_pref(FALSE);
193 }
194
195
196 /*!
197  * @brief モンスターを倒した際の財宝svalを返す
198  * @param r_idx 倒したモンスターの種族ID
199  * @return 財宝のsval
200  * @details
201  * Hack -- Return the "automatic coin type" of a monster race
202  * Used to allocate proper treasure when "Creeping coins" die
203  * Note the use of actual "monster names"
204  */
205 static int get_coin_type(MONRACE_IDX r_idx)
206 {
207         /* Analyze monsters */
208         switch (r_idx)
209         {
210                 case MON_COPPER_COINS: return 2;
211                 case MON_SILVER_COINS: return 5;
212                 case MON_GOLD_COINS: return 10;
213                 case MON_MITHRIL_COINS:
214                 case MON_MITHRIL_GOLEM: return 16;
215                 case MON_ADAMANT_COINS: return 17;
216         }
217
218         /* Assume nothing */
219         return 0;
220 }
221
222
223 /*!
224  * @brief オブジェクトがクロークかどうかを判定する /
225  * Hack -- determine if a template is Cloak
226  * @param k_idx 判定したいオブジェクトのベースアイテムID
227  * @return オブジェクトがクロークならばTRUEを返す
228  */
229 static bool kind_is_cloak(KIND_OBJECT_IDX k_idx)
230 {
231         object_kind *k_ptr = &k_info[k_idx];
232
233         /* Analyze the item type */
234         if (k_ptr->tval == TV_CLOAK)
235         {
236                 return (TRUE);
237         }
238
239         /* Assume not good */
240         return (FALSE);
241 }
242
243
244 /*!
245  * @brief オブジェクトが竿状武器かどうかを判定する /
246  * Hack -- determine if a template is Polearm
247  * @param k_idx 判定したいオブジェクトのベースアイテムID
248  * @return オブジェクトが竿状武器ならばTRUEを返す
249  */
250 static bool kind_is_polearm(KIND_OBJECT_IDX k_idx)
251 {
252         object_kind *k_ptr = &k_info[k_idx];
253
254         /* Analyze the item type */
255         if (k_ptr->tval == TV_POLEARM)
256         {
257                 return (TRUE);
258         }
259
260         /* Assume not good */
261         return (FALSE);
262 }
263
264
265 /*!
266  * @brief オブジェクトが剣かどうかを判定する /
267  * Hack -- determine if a template is Sword
268  * @param k_idx 判定したいオブジェクトのベースアイテムID
269  * @return オブジェクトが剣ならばTRUEを返す
270  */
271 static bool kind_is_sword(KIND_OBJECT_IDX k_idx)
272 {
273         object_kind *k_ptr = &k_info[k_idx];
274
275         /* Analyze the item type */
276         if ((k_ptr->tval == TV_SWORD) && (k_ptr->sval > 2))
277         {
278                 return (TRUE);
279         }
280
281         /* Assume not good */
282         return (FALSE);
283 }
284
285
286 /*!
287  * @brief オブジェクトが魔法書かどうかを判定する /
288  * Hack -- determine if a template is Book
289  * @param k_idx 判定したいオブジェクトのベースアイテムID
290  * @return オブジェクトが魔法書ならばTRUEを返す
291  */
292 static bool kind_is_book(KIND_OBJECT_IDX k_idx)
293 {
294         object_kind *k_ptr = &k_info[k_idx];
295
296         /* Analyze the item type */
297         if ((k_ptr->tval >= TV_LIFE_BOOK) && (k_ptr->tval <= TV_CRUSADE_BOOK))
298         {
299                 return (TRUE);
300         }
301
302         /* Assume not good */
303         return (FALSE);
304 }
305
306
307 /*!
308  * @brief オブジェクトがベースアイテム時点でGOODかどうかを判定する /
309  * Hack -- determine if a template is Good book
310  * @param k_idx 判定したいオブジェクトのベースアイテムID
311  * @return オブジェクトがベースアイテム時点でGOODなアイテムならばTRUEを返す
312  */
313 static bool kind_is_good_book(KIND_OBJECT_IDX k_idx)
314 {
315         object_kind *k_ptr = &k_info[k_idx];
316
317         /* Analyze the item type */
318         if ((k_ptr->tval >= TV_LIFE_BOOK) && (k_ptr->tval <= TV_CRUSADE_BOOK) && (k_ptr->tval != TV_ARCANE_BOOK) && (k_ptr->sval > 1))
319         {
320                 return (TRUE);
321         }
322
323         /* Assume not good */
324         return (FALSE);
325 }
326
327
328 /*!
329  * @brief オブジェクトが鎧かどうかを判定する /
330  * Hack -- determine if a template is Armor
331  * @param k_idx 判定したいオブジェクトのベースアイテムID
332  * @return オブジェクトが鎧ならばTRUEを返す
333  */
334 static bool kind_is_armor(KIND_OBJECT_IDX k_idx)
335 {
336         object_kind *k_ptr = &k_info[k_idx];
337
338         /* Analyze the item type */
339         if (k_ptr->tval == TV_HARD_ARMOR)
340         {
341                 return (TRUE);
342         }
343
344         /* Assume not good */
345         return (FALSE);
346 }
347
348
349 /*!
350  * @brief オブジェクトが打撃武器かどうかを判定する /
351  * Hack -- determine if a template is hafted weapon
352  * @param k_idx 判定したいオブジェクトのベースアイテムID
353  * @return オブジェクトが打撃武器ならばTRUEを返す
354  */
355 static bool kind_is_hafted(KIND_OBJECT_IDX k_idx)
356 {
357         object_kind *k_ptr = &k_info[k_idx];
358
359         /* Analyze the item type */
360         if (k_ptr->tval == TV_HAFTED)
361         {
362                 return (TRUE);
363         }
364
365         /* Assume not good */
366         return (FALSE);
367 }
368
369 /*!
370  * @brief クエストを達成状態にする /
371  * @param quest_num 達成状態にしたいクエストのID
372  * @return なし
373  */
374 void complete_quest(QUEST_IDX quest_num)
375 {
376         quest_type* const q_ptr = &quest[quest_num];
377
378         switch (q_ptr->type)
379         {
380         case QUEST_TYPE_RANDOM:
381                 if (record_rand_quest) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, quest_num, NULL);
382                 break;
383         default:
384                 if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, quest_num, NULL);
385                 break;
386         }
387
388         q_ptr->status = QUEST_STATUS_COMPLETED;
389         q_ptr->complev = (byte)p_ptr->lev;
390         update_playtime();
391         q_ptr->comptime = playtime;
392
393         if (!(q_ptr->flags & QUEST_FLAG_SILENT))
394         {
395                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_QUEST_CLEAR);
396                 msg_print(_("クエストを達成した!", "You just completed your quest!"));
397                 msg_print(NULL);
398         }
399 }
400
401 /*!
402  * @brief 現在フロアに残っている敵モンスターの数を返す /
403  * @return 現在の敵モンスターの数
404  */
405 static MONSTER_NUMBER count_all_hostile_monsters(void)
406 {
407         POSITION x, y;
408         MONSTER_NUMBER number_mon = 0;
409
410         for (x = 0; x < cur_wid; ++ x)
411         {
412                 for (y = 0; y < cur_hgt; ++ y)
413                 {
414                         MONSTER_IDX m_idx = cave[y][x].m_idx;
415
416                         if (m_idx > 0 && is_hostile(&m_list[m_idx]))
417                         {
418                                 ++number_mon;
419                         }
420                 }
421         }
422
423         return number_mon;
424 }
425
426 /*!
427  * @brief 特定の敵を倒した際にクエスト達成処理 /
428  * Check for "Quest" completion when a quest monster is killed or charmed.
429  * @param m_ptr 撃破したモンスターの構造体参照ポインタ
430  * @return なし
431  */
432 void check_quest_completion(monster_type *m_ptr)
433 {
434         POSITION y, x;
435         QUEST_IDX quest_num;
436
437         bool create_stairs = FALSE;
438         bool reward = FALSE;
439
440         object_type forge;
441         object_type *o_ptr;
442
443         /* Get the location */
444         y = m_ptr->fy;
445         x = m_ptr->fx;
446
447         /* Inside a quest */
448         quest_num = p_ptr->inside_quest;
449
450         /* Search for an active quest on this dungeon level */
451         if (!quest_num)
452         {
453                 QUEST_IDX i;
454
455                 for (i = max_q_idx - 1; i > 0; i--)
456                 {
457                         quest_type* const q_ptr = &quest[i];
458                         
459                         /* Quest is not active */
460                         if (q_ptr->status != QUEST_STATUS_TAKEN)
461                                 continue;
462
463                         /* Quest is not a dungeon quest */
464                         if (q_ptr->flags & QUEST_FLAG_PRESET)
465                                 continue;
466
467                         /* Quest is not on this level */
468                         if ((q_ptr->level != dun_level) &&
469                             (q_ptr->type != QUEST_TYPE_KILL_ANY_LEVEL))
470                                 continue;
471
472                         /* Not a "kill monster" quest */
473                         if ((q_ptr->type == QUEST_TYPE_FIND_ARTIFACT) ||
474                             (q_ptr->type == QUEST_TYPE_FIND_EXIT))
475                                 continue;
476
477                         /* Interesting quest */
478                         if ((q_ptr->type == QUEST_TYPE_KILL_NUMBER) ||
479                             (q_ptr->type == QUEST_TYPE_TOWER) ||
480                             (q_ptr->type == QUEST_TYPE_KILL_ALL))
481                                 break;
482
483                         /* Interesting quest */
484                         if (((q_ptr->type == QUEST_TYPE_KILL_LEVEL) ||
485                              (q_ptr->type == QUEST_TYPE_KILL_ANY_LEVEL) ||
486                              (q_ptr->type == QUEST_TYPE_RANDOM)) &&
487                              (q_ptr->r_idx == m_ptr->r_idx))
488                                 break;
489                 }
490
491                 quest_num = i;
492         }
493
494         /* Handle the current quest */
495         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
496         {
497                 /* Current quest */
498                 quest_type* const q_ptr = &quest[quest_num];
499
500                 switch (q_ptr->type)
501                 {
502                         case QUEST_TYPE_KILL_NUMBER:
503                         {
504                                 q_ptr->cur_num++;
505
506                                 if (q_ptr->cur_num >= q_ptr->num_mon)
507                                 {
508                                         complete_quest(quest_num);
509
510                                         q_ptr->cur_num = 0;
511                                 }
512                                 break;
513                         }
514                         case QUEST_TYPE_KILL_ALL:
515                         {
516                                 if (!is_hostile(m_ptr)) break;
517
518                                 if (count_all_hostile_monsters() == 1)
519                                 {
520                                         if (q_ptr->flags & QUEST_FLAG_SILENT)
521                                         {
522                                                 q_ptr->status = QUEST_STATUS_FINISHED;
523                                         }
524                                         else
525                                         {
526                                                 complete_quest(quest_num);
527                                         }
528                                 }
529                                 break;
530                         }
531                         case QUEST_TYPE_KILL_LEVEL:
532                         case QUEST_TYPE_RANDOM:
533                         {
534                                 /* Only count valid monsters */
535                                 if (q_ptr->r_idx != m_ptr->r_idx)
536                                         break;
537
538                                 q_ptr->cur_num++;
539
540                                 if (q_ptr->cur_num >= q_ptr->max_num)
541                                 {
542                                         complete_quest(quest_num);
543
544                                         if (!(q_ptr->flags & QUEST_FLAG_PRESET))
545                                         {
546                                                 create_stairs = TRUE;
547                                                 p_ptr->inside_quest = 0;
548                                         }
549
550                                         /* Finish the two main quests without rewarding */
551                                         if ((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT))
552                                         {
553                                                 q_ptr->status = QUEST_STATUS_FINISHED;
554                                         }
555
556                                         if (q_ptr->type == QUEST_TYPE_RANDOM)
557                                         {
558                                                 reward = TRUE;
559                                                 q_ptr->status = QUEST_STATUS_FINISHED;
560                                         }
561                                 }
562                                 break;
563                         }
564                         case QUEST_TYPE_KILL_ANY_LEVEL:
565                         {
566                                 q_ptr->cur_num++;
567                                 if (q_ptr->cur_num >= q_ptr->max_num)
568                                 {
569                                         complete_quest(quest_num);
570                                         q_ptr->cur_num = 0;
571                                 }
572                                 break;
573                         }
574                         case QUEST_TYPE_TOWER:
575                         {
576                                 if (!is_hostile(m_ptr)) break;
577
578                                 if (count_all_hostile_monsters() == 1)
579                                 {
580                                         q_ptr->status = QUEST_STATUS_STAGE_COMPLETED;
581
582                                         if((quest[QUEST_TOWER1].status == QUEST_STATUS_STAGE_COMPLETED) &&
583                                            (quest[QUEST_TOWER2].status == QUEST_STATUS_STAGE_COMPLETED) &&
584                                            (quest[QUEST_TOWER3].status == QUEST_STATUS_STAGE_COMPLETED))
585                                         {
586
587                                                 complete_quest(QUEST_TOWER1);
588                                         }
589                                 }
590                                 break;
591                         }
592                 }
593         }
594
595         /* Create a magical staircase */
596         if (create_stairs)
597         {
598                 POSITION ny, nx;
599
600                 /* Stagger around */
601                 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT) )
602                 {
603                         /* Pick a location */
604                         scatter(&ny, &nx, y, x, 1, 0);
605
606                         /* Stagger */
607                         y = ny; x = nx;
608                 }
609
610                 /* Explain the staircase */
611                 msg_print(_("魔法の階段が現れた...", "A magical staircase appears..."));
612
613                 /* Create stairs down */
614                 cave_set_feat(y, x, feat_down_stair);
615
616                 /* Remember to update everything */
617                 p_ptr->update |= (PU_FLOW);
618         }
619
620         /*
621          * Drop quest reward
622          */
623         if (reward)
624         {
625                 int i;
626
627                 for (i = 0; i < (dun_level / 15)+1; i++)
628                 {
629                         o_ptr = &forge;
630                         object_wipe(o_ptr);
631
632                         /* Make a great object */
633                         make_object(o_ptr, AM_GOOD | AM_GREAT);
634
635                         /* Drop it in the dungeon */
636                         (void)drop_near(o_ptr, -1, y, x);
637                 }
638         }
639 }
640
641 /*!
642  * @brief 特定のアーティファクトを入手した際のクエスト達成処理 /
643  * Check for "Quest" completion when a quest monster is killed or charmed.
644  * @param o_ptr 入手したオブジェクトの構造体参照ポインタ
645  * @return なし
646  */
647 void check_find_art_quest_completion(object_type *o_ptr)
648 {
649         QUEST_IDX i;
650         /* Check if completed a quest */
651         for (i = 0; i < max_q_idx; i++)
652         {
653                 if((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
654                         (quest[i].status == QUEST_STATUS_TAKEN) &&
655                         (quest[i].k_idx == o_ptr->name1))
656                 {
657                         complete_quest(i);
658                 }
659         }
660 }
661
662
663 /*!
664  * @brief モンスターを撃破した際の述語メッセージを返す /
665  * Return monster death string
666  * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
667  * @return 撃破されたモンスターの述語
668  */
669 cptr extract_note_dies(MONRACE_IDX r_idx)
670 {
671         monster_race *r_ptr = &r_info[r_idx];
672         /* Some monsters get "destroyed" */
673         if (!monster_living(r_idx))
674         {
675                 int i;
676
677                 for (i = 0; i < 4; i++)
678                 {
679                         if (r_ptr->blow[i].method == RBM_EXPLODE)
680                         {
681                                 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
682                         }
683                 }
684                 return _("を倒した。", " is destroyed.");
685         }
686
687         /* Assume a default death */
688         return _("は死んだ。", " dies.");
689 }
690
691
692 /*!
693  * @brief モンスターが死亡した時の処理 /
694  * Handle the "death" of a monster.
695  * @param m_idx 死亡したモンスターのID
696  * @param drop_item TRUEならばモンスターのドロップ処理を行う
697  * @return 撃破されたモンスターの述語
698  * @details
699  * <pre>
700  * Disperse treasures centered at the monster location based on the
701  * various flags contained in the monster flags fields.
702  * Check for "Quest" completion when a quest monster is killed.
703  * Note that only the player can induce "monster_death()" on Uniques.
704  * Thus (for now) all Quest monsters should be Uniques.
705  * Note that monsters can now carry objects, and when a monster dies,
706  * it drops all of its objects, which may disappear in crowded rooms.
707  * </pre>
708  */
709 void monster_death(MONSTER_IDX m_idx, bool drop_item)
710 {
711         int i, j;
712         POSITION y, x;
713
714         int dump_item = 0;
715         int dump_gold = 0;
716         int number = 0;
717
718         monster_type *m_ptr = &m_list[m_idx];
719         monster_race *r_ptr = &r_info[m_ptr->r_idx];
720
721         bool visible = ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE));
722
723         u32b mo_mode = 0L;
724
725         bool do_gold = (!(r_ptr->flags1 & RF1_ONLY_ITEM));
726         bool do_item = (!(r_ptr->flags1 & RF1_ONLY_GOLD));
727         bool cloned = (m_ptr->smart & SM_CLONED) ? TRUE : FALSE;
728         int force_coin = get_coin_type(m_ptr->r_idx);
729
730         object_type forge;
731         object_type *q_ptr;
732
733         bool drop_chosen_item = drop_item && !cloned && !p_ptr->inside_arena
734                 && !p_ptr->inside_battle && !is_pet(m_ptr);
735
736         /* The caster is dead? */
737         if (world_monster && world_monster == m_idx) world_monster = 0;
738
739         /* Notice changes in view */
740         if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
741         {
742                 /* Update some things */
743                 p_ptr->update |= (PU_MON_LITE);
744         }
745
746         /* Get the location */
747         y = m_ptr->fy;
748         x = m_ptr->fx;
749
750         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
751         {
752                 char m_name[80];
753
754                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
755                 do_cmd_write_nikki(NIKKI_NAMED_PET, 3, m_name);
756         }
757
758         /* Let monsters explode! */
759         for (i = 0; i < 4; i++)
760         {
761                 if (r_ptr->blow[i].method == RBM_EXPLODE)
762                 {
763                         BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
764                         EFFECT_ID typ = mbe_info[r_ptr->blow[i].effect].explode_type;
765                         DICE_NUMBER d_dice = r_ptr->blow[i].d_dice;
766                         DICE_SID d_side = r_ptr->blow[i].d_side;
767                         HIT_POINT damage = damroll(d_dice, d_side);
768
769                         project(m_idx, 3, y, x, damage, typ, flg, -1);
770                         break;
771                 }
772         }
773
774         if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
775         {
776                 choose_new_monster(m_idx, TRUE, MON_CHAMELEON);
777                 r_ptr = &r_info[m_ptr->r_idx];
778         }
779
780         /* Check for quest completion */
781         check_quest_completion(m_ptr);
782
783         /* Handle the possibility of player vanquishing arena combatant -KMW- */
784         if (p_ptr->inside_arena && !is_pet(m_ptr))
785         {
786                 p_ptr->exit_bldg = TRUE;
787
788                 if (p_ptr->arena_number > MAX_ARENA_MONS)
789                 {
790                         msg_print(_("素晴らしい!君こそ真の勝利者だ。", "You are a Genuine Champion!"));
791                 }
792                 else
793                 {
794                         msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion."));
795                 }
796
797                 if (arena_info[p_ptr->arena_number].tval)
798                 {
799                         q_ptr = &forge;
800
801                         /* Prepare to make a prize */
802                         object_prep(q_ptr, lookup_kind(arena_info[p_ptr->arena_number].tval, arena_info[p_ptr->arena_number].sval));
803                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
804
805                         /* Drop it in the dungeon */
806                         (void)drop_near(q_ptr, -1, y, x);
807                 }
808
809                 if (p_ptr->arena_number > MAX_ARENA_MONS) p_ptr->arena_number++;
810                 p_ptr->arena_number++;
811                 if (record_arena)
812                 {
813                         char m_name[80];
814                         
815                         /* Extract monster name */
816                         monster_desc(m_name, m_ptr, MD_IGNORE_HALLU | MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
817                         
818                         do_cmd_write_nikki(NIKKI_ARENA, p_ptr->arena_number, m_name);
819                 }
820         }
821
822         if (m_idx == p_ptr->riding)
823         {
824                 if (rakuba(-1, FALSE))
825                 {
826                         msg_print(_("地面に落とされた。", "You have fallen from your riding pet."));
827                 }
828         }
829
830         /* Drop a dead corpse? */
831         if (one_in_(r_ptr->flags1 & RF1_UNIQUE ? 1 : 4) &&
832             (r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) &&
833             !(p_ptr->inside_arena || p_ptr->inside_battle || cloned || ((m_ptr->r_idx == today_mon) && is_pet(m_ptr))))
834         {
835                 /* Assume skeleton */
836                 bool corpse = FALSE;
837
838                 /*
839                  * We cannot drop a skeleton? Note, if we are in this check,
840                  * we *know* we can drop at least a corpse or a skeleton
841                  */
842                 if (!(r_ptr->flags9 & RF9_DROP_SKELETON))
843                         corpse = TRUE;
844                 else if ((r_ptr->flags9 & RF9_DROP_CORPSE) && (r_ptr->flags1 & RF1_UNIQUE))
845                         corpse = TRUE;
846
847                 /* Else, a corpse is more likely unless we did a "lot" of damage */
848                 else if (r_ptr->flags9 & RF9_DROP_CORPSE)
849                 {
850                         /* Lots of damage in one blow */
851                         if ((0 - ((m_ptr->maxhp) / 4)) > m_ptr->hp)
852                         {
853                                 if (one_in_(5)) corpse = TRUE;
854                         }
855                         else
856                         {
857                                 if (!one_in_(5)) corpse = TRUE;
858                         }
859                 }
860                 q_ptr = &forge;
861
862                 /* Prepare to make an object */
863                 object_prep(q_ptr, lookup_kind(TV_CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
864
865                 apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
866
867                 q_ptr->pval = m_ptr->r_idx;
868
869                 /* Drop it in the dungeon */
870                 (void)drop_near(q_ptr, -1, y, x);
871         }
872
873         /* Drop objects being carried */
874         monster_drop_carried_objects(m_ptr);
875
876         if (r_ptr->flags1 & RF1_DROP_GOOD) mo_mode |= AM_GOOD;
877         if (r_ptr->flags1 & RF1_DROP_GREAT) mo_mode |= AM_GREAT;
878
879         switch (m_ptr->r_idx)
880         {
881         case MON_PINK_HORROR:
882                 /* Pink horrors are replaced with 2 Blue horrors */
883                 if (!(p_ptr->inside_arena || p_ptr->inside_battle))
884                 {
885                         bool notice = FALSE;
886
887                         for (i = 0; i < 2; i++)
888                         {
889                                 POSITION wy = y, wx = x;
890                                 bool pet = is_pet(m_ptr);
891                                 BIT_FLAGS mode = 0L;
892
893                                 if (pet) mode |= PM_FORCE_PET;
894
895                                 if (summon_specific((pet ? -1 : m_idx), wy, wx, 100, SUMMON_BLUE_HORROR, mode))
896                                 {
897                                         if (player_can_see_bold(wy, wx)) notice = TRUE;
898                                 }
899                         }
900
901                         if (notice) 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(m_ptr->r_idx))
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         p_ptr->redraw |= (PR_MAP);
2208         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2209 }
2210
2211
2212 /*
2213  * Monster health description
2214  */
2215 cptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode)
2216 {
2217         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2218         bool living;
2219         int perc;
2220         cptr desc;
2221         cptr attitude;
2222         cptr clone;
2223
2224         /* Determine if the monster is "living" */
2225         living = monster_living(m_ptr->ap_r_idx);
2226
2227         /* Calculate a health "percentage" */
2228         perc = 100L * m_ptr->hp / m_ptr->maxhp;
2229
2230         /* Healthy monsters */
2231         if (m_ptr->hp >= m_ptr->maxhp)
2232         {
2233                 desc = living ? _("無傷", "unhurt") : _("無ダメージ", "undamaged");
2234         }
2235
2236         else if (perc >= 60)
2237         {
2238                 desc = living ? _("軽傷", "somewhat wounded") : _("小ダメージ", "somewhat damaged");
2239         }
2240
2241         else if (perc >= 25)
2242         {
2243                 desc = living ? _("負傷", "wounded") : _("中ダメージ", "damaged");
2244         }
2245
2246         else if (perc >= 10)
2247         {
2248                 desc = living ? _("重傷", "badly wounded") : _("大ダメージ", "badly damaged");
2249         }
2250
2251         else 
2252         {
2253                 desc = living ? _("半死半生", "almost dead") : _("倒れかけ", "almost destroyed");
2254         }
2255
2256         /* Need attitude information? */
2257         if (!(mode & 0x01))
2258         {
2259                 /* Full information is not needed */
2260                 attitude = "";
2261         }
2262         else if (is_pet(m_ptr))
2263         {
2264                 attitude = _(", ペット", ", pet");
2265         }
2266         else if (is_friendly(m_ptr))
2267         {
2268                 attitude = _(", 友好的", ", friendly");
2269         }
2270         else
2271         {
2272                 attitude = _("", "");
2273         }
2274
2275         /* Clone monster? */
2276         if (m_ptr->smart & SM_CLONED)
2277         {
2278                 clone = ", clone";
2279         }
2280         else
2281         {
2282                 clone = "";
2283         }
2284
2285         /* Display monster's level --- idea borrowed from ToME */
2286         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
2287         {
2288                 return format(_("レベル%d, %s%s%s", "Level %d, %s%s%s"), ap_r_ptr->level, desc, attitude, clone);
2289         }
2290         else 
2291         {
2292                 return format(_("レベル???, %s%s%s", "Level ???, %s%s%s"), desc, attitude, clone);
2293         }
2294
2295 }
2296
2297
2298
2299 /*
2300  * Angband sorting algorithm -- quick sort in place
2301  *
2302  * Note that the details of the data we are sorting is hidden,
2303  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2304  * function hooks to interact with the data, which is given as
2305  * two pointers, and which may have any user-defined form.
2306  */
2307 void ang_sort_aux(vptr u, vptr v, int p, int q)
2308 {
2309         int z, a, b;
2310
2311         /* Done sort */
2312         if (p >= q) return;
2313
2314         /* Pivot */
2315         z = p;
2316
2317         /* Begin */
2318         a = p;
2319         b = q;
2320
2321         /* Partition */
2322         while (TRUE)
2323         {
2324                 /* Slide i2 */
2325                 while (!(*ang_sort_comp)(u, v, b, z)) b--;
2326
2327                 /* Slide i1 */
2328                 while (!(*ang_sort_comp)(u, v, z, a)) a++;
2329
2330                 /* Done partition */
2331                 if (a >= b) break;
2332
2333                 /* Swap */
2334                 (*ang_sort_swap)(u, v, a, b);
2335
2336                 /* Advance */
2337                 a++, b--;
2338         }
2339
2340         /* Recurse left side */
2341         ang_sort_aux(u, v, p, b);
2342
2343         /* Recurse right side */
2344         ang_sort_aux(u, v, b+1, q);
2345 }
2346
2347
2348 /*
2349  * Angband sorting algorithm -- quick sort in place
2350  *
2351  * Note that the details of the data we are sorting is hidden,
2352  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2353  * function hooks to interact with the data, which is given as
2354  * two pointers, and which may have any user-defined form.
2355  */
2356 void ang_sort(vptr u, vptr v, int n)
2357 {
2358         /* Sort the array */
2359         ang_sort_aux(u, v, 0, n-1);
2360 }
2361
2362
2363
2364 /*** Targeting Code ***/
2365
2366
2367 /*
2368  * Determine is a monster makes a reasonable target
2369  *
2370  * The concept of "targeting" was stolen from "Morgul" (?)
2371  *
2372  * The player can target any location, or any "target-able" monster.
2373  *
2374  * Currently, a monster is "target_able" if it is visible, and if
2375  * the player can hit it with a projection, and the player is not
2376  * hallucinating.  This allows use of "use closest target" macros.
2377  *
2378  * Future versions may restrict the ability to target "trappers"
2379  * and "mimics", but the semantics is a little bit weird.
2380  */
2381 bool target_able(MONSTER_IDX m_idx)
2382 {
2383         monster_type *m_ptr = &m_list[m_idx];
2384
2385         /* Monster must be alive */
2386         if (!m_ptr->r_idx) return (FALSE);
2387
2388         /* Hack -- no targeting hallucinations */
2389         if (p_ptr->image) return (FALSE);
2390
2391         /* Monster must be visible */
2392         if (!m_ptr->ml) return (FALSE);
2393
2394         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
2395
2396         /* Monster must be projectable */
2397         if (!projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) return (FALSE);
2398
2399         /* Hack -- Never target trappers */
2400         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
2401
2402         /* Assume okay */
2403         return (TRUE);
2404 }
2405
2406
2407
2408
2409 /*
2410  * Update (if necessary) and verify (if possible) the target.
2411  *
2412  * We return TRUE if the target is "okay" and FALSE otherwise.
2413  */
2414 bool target_okay(void)
2415 {
2416         /* Accept stationary targets */
2417         if (target_who < 0) return (TRUE);
2418
2419         /* Check moving targets */
2420         if (target_who > 0)
2421         {
2422                 /* Accept reasonable targets */
2423                 if (target_able(target_who))
2424                 {
2425                         monster_type *m_ptr = &m_list[target_who];
2426
2427                         /* Acquire monster location */
2428                         target_row = m_ptr->fy;
2429                         target_col = m_ptr->fx;
2430
2431                         /* Good target */
2432                         return (TRUE);
2433                 }
2434         }
2435
2436         /* Assume no target */
2437         return (FALSE);
2438 }
2439
2440
2441 /*
2442  * Sorting hook -- comp function -- by "distance to player"
2443  *
2444  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2445  * and sort the arrays by double-distance to the player.
2446  */
2447 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
2448 {
2449         POSITION *x = (POSITION*)(u);
2450         POSITION *y = (POSITION*)(v);
2451
2452         POSITION da, db, kx, ky;
2453
2454         /* Absolute distance components */
2455         kx = x[a]; kx -= p_ptr->x; kx = ABS(kx);
2456         ky = y[a]; ky -= p_ptr->y; ky = ABS(ky);
2457
2458         /* Approximate Double Distance to the first point */
2459         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2460
2461         /* Absolute distance components */
2462         kx = x[b]; kx -= p_ptr->x; kx = ABS(kx);
2463         ky = y[b]; ky -= p_ptr->y; ky = ABS(ky);
2464
2465         /* Approximate Double Distance to the first point */
2466         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2467
2468         /* Compare the distances */
2469         return (da <= db);
2470 }
2471
2472
2473 /*
2474  * Sorting hook -- comp function -- by importance level of grids
2475  *
2476  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2477  * and sort the arrays by level of monster
2478  */
2479 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
2480 {
2481         POSITION *x = (POSITION*)(u);
2482         POSITION *y = (POSITION*)(v);
2483         cave_type *ca_ptr = &cave[y[a]][x[a]];
2484         cave_type *cb_ptr = &cave[y[b]][x[b]];
2485         monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
2486         monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
2487         monster_race *ap_ra_ptr, *ap_rb_ptr;
2488
2489         /* The player grid */
2490         if (y[a] == p_ptr->y && x[a] == p_ptr->x) return TRUE;
2491         if (y[b] == p_ptr->y && x[b] == p_ptr->x) return FALSE;
2492
2493         /* Extract monster race */
2494         if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
2495         else ap_ra_ptr = NULL;
2496         if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
2497         else ap_rb_ptr = NULL;
2498
2499         if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
2500         if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
2501
2502         /* Compare two monsters */
2503         if (ap_ra_ptr && ap_rb_ptr)
2504         {
2505                 /* Unique monsters first */
2506                 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
2507                 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
2508
2509                 /* Shadowers first (あやしい影) */
2510                 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
2511                 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
2512
2513                 /* Unknown monsters first */
2514                 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
2515                 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
2516
2517                 /* Higher level monsters first (if known) */
2518                 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
2519                 {
2520                         if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
2521                         if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
2522                 }
2523
2524                 /* Sort by index if all conditions are same */
2525                 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
2526                 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
2527         }
2528
2529         /* An object get higher priority */
2530         if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
2531         if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
2532
2533         /* Priority from the terrain */
2534         if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
2535         if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
2536
2537         /* If all conditions are same, compare distance */
2538         return ang_sort_comp_distance(u, v, a, b);
2539 }
2540
2541
2542 /*
2543  * Sorting hook -- swap function -- by "distance to player"
2544  *
2545  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2546  * and sort the arrays by distance to the player.
2547  */
2548 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
2549 {
2550         POSITION *x = (POSITION*)(u);
2551         POSITION *y = (POSITION*)(v);
2552
2553         POSITION temp;
2554
2555         /* Swap "x" */
2556         temp = x[a];
2557         x[a] = x[b];
2558         x[b] = temp;
2559
2560         /* Swap "y" */
2561         temp = y[a];
2562         y[a] = y[b];
2563         y[b] = temp;
2564 }
2565
2566
2567
2568 /*
2569  * Hack -- help "select" a location (see below)
2570  */
2571 static POSITION_IDX target_pick(POSITION y1, POSITION x1, POSITION dy, POSITION dx)
2572 {
2573         POSITION_IDX i, v;
2574         POSITION x2, y2, x3, y3, x4, y4;
2575         POSITION_IDX b_i = -1, b_v = 9999;
2576
2577
2578         /* Scan the locations */
2579         for (i = 0; i < temp_n; i++)
2580         {
2581                 /* Point 2 */
2582                 x2 = temp_x[i];
2583                 y2 = temp_y[i];
2584
2585                 /* Directed distance */
2586                 x3 = (x2 - x1);
2587                 y3 = (y2 - y1);
2588
2589                 /* Verify quadrant */
2590                 if (dx && (x3 * dx <= 0)) continue;
2591                 if (dy && (y3 * dy <= 0)) continue;
2592
2593                 /* Absolute distance */
2594                 x4 = ABS(x3);
2595                 y4 = ABS(y3);
2596
2597                 /* Verify quadrant */
2598                 if (dy && !dx && (x4 > y4)) continue;
2599                 if (dx && !dy && (y4 > x4)) continue;
2600
2601                 /* Approximate Double Distance */
2602                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
2603
2604                 /* Penalize location */
2605
2606                 /* Track best */
2607                 if ((b_i >= 0) && (v >= b_v)) continue;
2608
2609                 /* Track best */
2610                 b_i = i; b_v = v;
2611         }
2612         return (b_i);
2613 }
2614
2615
2616 /*
2617  * Hack -- determine if a given location is "interesting"
2618  */
2619 static bool target_set_accept(POSITION y, POSITION x)
2620 {
2621         cave_type *c_ptr;
2622         OBJECT_IDX this_o_idx, next_o_idx = 0;
2623
2624         /* Bounds */
2625         if (!(in_bounds(y, x))) return (FALSE);
2626
2627         /* Player grid is always interesting */
2628         if (player_bold(y, x)) return (TRUE);
2629
2630         /* Handle hallucination */
2631         if (p_ptr->image) return (FALSE);
2632
2633         /* Examine the grid */
2634         c_ptr = &cave[y][x];
2635
2636         /* Visible monsters */
2637         if (c_ptr->m_idx)
2638         {
2639                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2640
2641                 /* Visible monsters */
2642                 if (m_ptr->ml) return (TRUE);
2643         }
2644
2645         /* Scan all objects in the grid */
2646         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2647         {
2648                 object_type *o_ptr;
2649                 o_ptr = &o_list[this_o_idx];
2650
2651                 /* Acquire next object */
2652                 next_o_idx = o_ptr->next_o_idx;
2653
2654                 /* Memorized object */
2655                 if (o_ptr->marked & OM_FOUND) return (TRUE);
2656         }
2657
2658         /* Interesting memorized features */
2659         if (c_ptr->info & (CAVE_MARK))
2660         {
2661                 /* Notice object features */
2662                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
2663
2664                 /* Feature code (applying "mimic" field) */
2665                 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
2666         }
2667
2668         return (FALSE);
2669 }
2670
2671
2672 /*
2673  * Prepare the "temp" array for "target_set"
2674  *
2675  * Return the number of target_able monsters in the set.
2676  */
2677 static void target_set_prepare(BIT_FLAGS mode)
2678 {
2679         POSITION y, x;
2680         POSITION min_hgt, max_hgt, min_wid, max_wid;
2681
2682         if (mode & TARGET_KILL)
2683         {
2684                 /* Inner range */
2685                 min_hgt = MAX((p_ptr->y - MAX_RANGE), 0);
2686                 max_hgt = MIN((p_ptr->y + MAX_RANGE), cur_hgt - 1);
2687                 min_wid = MAX((p_ptr->x - MAX_RANGE), 0);
2688                 max_wid = MIN((p_ptr->x + MAX_RANGE), cur_wid - 1);
2689         }
2690         else /* not targetting */
2691         {
2692                 /* Inner panel */
2693                 min_hgt = panel_row_min;
2694                 max_hgt = panel_row_max;
2695                 min_wid = panel_col_min;
2696                 max_wid = panel_col_max;
2697         }
2698
2699         /* Reset "temp" array */
2700         temp_n = 0;
2701
2702         /* Scan the current panel */
2703         for (y = min_hgt; y <= max_hgt; y++)
2704         {
2705                 for (x = min_wid; x <= max_wid; x++)
2706                 {
2707                         cave_type *c_ptr;
2708
2709                         /* Require "interesting" contents */
2710                         if (!target_set_accept(y, x)) continue;
2711
2712                         c_ptr = &cave[y][x];
2713
2714                         /* Require target_able monsters for "TARGET_KILL" */
2715                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
2716
2717                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
2718
2719                         /* Save the location */
2720                         temp_x[temp_n] = x;
2721                         temp_y[temp_n] = y;
2722                         temp_n++;
2723                 }
2724         }
2725
2726         /* Set the sort hooks */
2727         if (mode & (TARGET_KILL))
2728         {
2729                 /* Target the nearest monster for shooting */
2730                 ang_sort_comp = ang_sort_comp_distance;
2731                 ang_sort_swap = ang_sort_swap_distance;
2732         }
2733         else
2734         {
2735                 /* Look important grids first in Look command */
2736                 ang_sort_comp = ang_sort_comp_importance;
2737                 ang_sort_swap = ang_sort_swap_distance;
2738         }
2739
2740         /* Sort the positions */
2741         ang_sort(temp_x, temp_y, temp_n);
2742
2743         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
2744         {
2745                 POSITION tmp;
2746
2747                 tmp = temp_y[0];
2748                 temp_y[0] = temp_y[1];
2749                 temp_y[1] = tmp;
2750                 tmp = temp_x[0];
2751                 temp_x[0] = temp_x[1];
2752                 temp_x[1] = tmp;
2753         }
2754 }
2755
2756 void target_set_prepare_look(void){
2757         target_set_prepare(TARGET_LOOK);
2758 }
2759
2760
2761 /*
2762  * Evaluate number of kill needed to gain level
2763  */
2764 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
2765 {
2766         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2767         u32b num;
2768         s32b exp_mon, exp_adv;
2769         u32b exp_mon_frac, exp_adv_frac;
2770
2771         if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
2772         {
2773                 sprintf(buf,"**");
2774                 return;
2775         }
2776         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
2777         {
2778                 if (!p_ptr->wizard)
2779                 {
2780                         sprintf(buf,"??");
2781                         return;
2782                 }
2783         }
2784
2785
2786         /* The monster's experience point (assuming average monster speed) */
2787         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
2788         exp_mon_frac = 0;
2789         s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
2790
2791
2792         /* Total experience value for next level */
2793         exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
2794         exp_adv_frac = 0;
2795         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
2796
2797         /* Experience value need to get */
2798         s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
2799
2800
2801         /* You need to kill at least one monster to get any experience */
2802         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
2803         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
2804
2805         /* Extract number of monsters needed */
2806         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
2807
2808         /* If 999 or more monsters needed, only display "999". */
2809         num = MIN(999, exp_adv_frac);
2810
2811         /* Display the number */
2812         sprintf(buf,"%03ld", (long int)num);
2813 }
2814
2815
2816 bool show_gold_on_floor = FALSE;
2817
2818 /*
2819  * Examine a grid, return a keypress.
2820  *
2821  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
2822  * indicates that the "space" key should scan through the contents
2823  * of the grid, instead of simply returning immediately.  This lets
2824  * the "look" command get complete information, without making the
2825  * "target" command annoying.
2826  *
2827  * The "info" argument contains the "commands" which should be shown
2828  * inside the "[xxx]" text.  This string must never be empty, or grids
2829  * containing monsters will be displayed with an extra comma.
2830  *
2831  * Note that if a monster is in the grid, we update both the monster
2832  * recall info and the health bar info to track that monster.
2833  *
2834  * Eventually, we may allow multiple objects per grid, or objects
2835  * and terrain features in the same grid. 
2836  *
2837  * This function must handle blindness/hallucination.
2838  */
2839 static char target_set_aux(POSITION y, POSITION x, BIT_FLAGS mode, cptr info)
2840 {
2841         cave_type *c_ptr = &cave[y][x];
2842         OBJECT_IDX this_o_idx, next_o_idx = 0;
2843         cptr s1 = "", s2 = "", s3 = "", x_info = "";
2844         bool boring = TRUE;
2845         FEAT_IDX feat;
2846         feature_type *f_ptr;
2847         char query = '\001';
2848         char out_val[MAX_NLEN+80];
2849         OBJECT_IDX floor_list[23];
2850         ITEM_NUMBER floor_num = 0;
2851
2852         /* Scan all objects in the grid */
2853         if (easy_floor)
2854         {
2855                 floor_num = scan_floor(floor_list, y, x, 0x02);
2856
2857                 if (floor_num)
2858                 {
2859                         x_info = _("x物 ", "x,");
2860                 }
2861         }
2862
2863         /* Hack -- under the player */
2864         if (player_bold(y, x))
2865         {
2866                 /* Description */
2867 #ifdef JP
2868                 s1 = "あなたは";
2869                 s2 = "の上";
2870                 s3 = "にいる";
2871 #else
2872                 s1 = "You are ";
2873
2874                 /* Preposition */
2875                 s2 = "on ";
2876 #endif
2877         }
2878         else
2879         {
2880                 s1 = _("ターゲット:", "Target:");
2881         }
2882
2883         /* Hack -- hallucination */
2884         if (p_ptr->image)
2885         {
2886                 cptr name = _("何か奇妙な物", "something strange");
2887
2888                 /* Display a message */
2889 #ifdef JP
2890                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
2891 #else
2892                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
2893 #endif
2894
2895                 prt(out_val, 0, 0);
2896                 move_cursor_relative(y, x);
2897                 query = inkey();
2898
2899                 /* Stop on everything but "return" */
2900                 if ((query != '\r') && (query != '\n')) return query;
2901
2902                 /* Repeat forever */
2903                 return 0;
2904         }
2905
2906
2907         /* Actual monsters */
2908         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
2909         {
2910                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2911                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2912                 char m_name[80];
2913                 bool recall = FALSE;
2914
2915                 /* Not boring */
2916                 boring = FALSE;
2917
2918                 /* Get the monster name ("a kobold") */
2919                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
2920
2921                 /* Hack -- track this monster race */
2922                 monster_race_track(m_ptr->ap_r_idx);
2923
2924                 /* Hack -- health bar for this monster */
2925                 health_track(c_ptr->m_idx);
2926                 handle_stuff();
2927
2928                 /* Interact */
2929                 while (1)
2930                 {
2931                         char acount[10];
2932
2933                         /* Recall */
2934                         if (recall)
2935                         {
2936                                 /* Save */
2937                                 screen_save();
2938
2939                                 /* Recall on screen */
2940                                 screen_roff(m_ptr->ap_r_idx, 0);
2941
2942                                 /* Hack -- Complete the prompt (again) */
2943                                 Term_addstr(-1, TERM_WHITE, format(_("  [r思 %s%s]", "  [r,%s%s]"), x_info, info));
2944
2945                                 /* Command */
2946                                 query = inkey();
2947
2948                                 /* Restore */
2949                                 screen_load();
2950
2951                                 /* Normal commands */
2952                                 if (query != 'r') break;
2953
2954                                 /* Toggle recall */
2955                                 recall = FALSE;
2956
2957                                 /* Cleare recall text and repeat */
2958                                 continue;
2959                         }
2960
2961                         /*** Normal ***/
2962
2963                         /* Describe, and prompt for recall */
2964                         evaluate_monster_exp(acount, m_ptr);
2965
2966 #ifdef JP
2967                         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);
2968 #else
2969                         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);
2970 #endif
2971
2972                         prt(out_val, 0, 0);
2973
2974                         /* Place cursor */
2975                         move_cursor_relative(y, x);
2976
2977                         /* Command */
2978                         query = inkey();
2979
2980                         /* Normal commands */
2981                         if (query != 'r') break;
2982
2983                         /* Toggle recall */
2984                         recall = TRUE;
2985                 }
2986
2987                 /* Always stop at "normal" keys */
2988                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
2989
2990                 /* Sometimes stop at "space" key */
2991                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
2992
2993                 /* Change the intro */
2994                 s1 = _("それは", "It is ");
2995
2996                 /* Hack -- take account of gender */
2997                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = _("彼女は", "She is ");
2998                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = _("彼は", "He is ");
2999
3000                 /* Use a preposition */
3001 #ifdef JP
3002                 s2 = "を";
3003                 s3 = "持っている";
3004 #else
3005                 s2 = "carrying ";
3006 #endif
3007
3008
3009                 /* Scan all objects being carried */
3010                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3011                 {
3012                         char o_name[MAX_NLEN];
3013
3014                         object_type *o_ptr;
3015                         o_ptr = &o_list[this_o_idx];
3016
3017                         /* Acquire next object */
3018                         next_o_idx = o_ptr->next_o_idx;
3019
3020                         /* Obtain an object description */
3021                         object_desc(o_name, o_ptr, 0);
3022
3023 #ifdef JP
3024                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3025 #else
3026                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3027 #endif
3028
3029                         prt(out_val, 0, 0);
3030                         move_cursor_relative(y, x);
3031                         query = inkey();
3032
3033                         /* Always stop at "normal" keys */
3034                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3035
3036                         /* Sometimes stop at "space" key */
3037                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3038
3039                         /* Change the intro */
3040                         s2 = _("をまた", "also carrying ");
3041                 }
3042
3043                 /* Use a preposition */
3044 #ifdef JP
3045                 s2 = "の上";
3046                 s3 = "にいる";
3047 #else
3048                 s2 = "on ";
3049 #endif
3050         }
3051
3052         if (floor_num)
3053         {
3054                 int min_width = 0;
3055
3056                 while (1)
3057                 {
3058                         if (floor_num == 1)
3059                         {
3060                                 char o_name[MAX_NLEN];
3061
3062                                 object_type *o_ptr;
3063                                 o_ptr = &o_list[floor_list[0]];
3064
3065                                 object_desc(o_name, o_ptr, 0);
3066
3067 #ifdef JP
3068                                 sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3069 #else
3070                                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3071 #endif
3072
3073                                 prt(out_val, 0, 0);
3074                                 move_cursor_relative(y, x);
3075
3076                                 /* Command */
3077                                 query = inkey();
3078
3079                                 /* End this grid */
3080                                 return query;
3081                         }
3082
3083                         /* Provide one cushion before item listing  */
3084                         if (boring)
3085                         {
3086                                 /* Display rough information about items */
3087 #ifdef JP
3088                                 sprintf(out_val, "%s %d個のアイテム%s%s ['x'で一覧, %s]", s1, (int)floor_num, s2, s3, info);
3089 #else
3090                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]", s1, s2, s3, (int)floor_num, info);
3091 #endif
3092
3093                                 prt(out_val, 0, 0);
3094                                 move_cursor_relative(y, x);
3095
3096                                 /* Command */
3097                                 query = inkey();
3098
3099                                 /* No request for listing */
3100                                 if (query != 'x' && query != ' ') return query;
3101                         }
3102
3103
3104                         /** Display list of items **/
3105
3106                         /* Continue scrolling list if requested */
3107                         while (1)
3108                         {
3109                                 int i;
3110                                 OBJECT_IDX o_idx;
3111                                 screen_save();
3112
3113                                 /* Display */
3114                                 show_gold_on_floor = TRUE;
3115                                 (void)show_floor(0, y, x, &min_width);
3116                                 show_gold_on_floor = FALSE;
3117
3118                                 /* Prompt */
3119 #ifdef JP
3120                                 sprintf(out_val, "%s %d個のアイテム%s%s [Enterで次へ, %s]", s1, (int)floor_num, s2, s3, info);
3121 #else
3122                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]", s1, s2, s3, (int)floor_num, info);
3123 #endif
3124                                 prt(out_val, 0, 0);
3125
3126                                 query = inkey();
3127                                 screen_load();
3128
3129                                 /* Exit unless 'Enter' */
3130                                 if (query != '\n' && query != '\r')
3131                                 {
3132                                         return query;
3133                                 }
3134
3135                                 /* Get the object being moved. */
3136                                 o_idx = c_ptr->o_idx;
3137  
3138                                 /* Only rotate a pile of two or more objects. */
3139                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
3140
3141                                 /* Remove the first object from the list. */
3142                                 excise_object_idx(o_idx);
3143
3144                                 /* Find end of the list. */
3145                                 i = c_ptr->o_idx;
3146                                 while (o_list[i].next_o_idx)
3147                                         i = o_list[i].next_o_idx;
3148
3149                                 /* Add after the last object. */
3150                                 o_list[i].next_o_idx = o_idx;
3151
3152                                 /* Loop and re-display the list */
3153                         }
3154                 }
3155
3156                 /* NOTREACHED */
3157         }
3158
3159         /* Scan all objects in the grid */
3160         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3161         {
3162                 object_type *o_ptr;
3163                 o_ptr = &o_list[this_o_idx];
3164
3165                 /* Acquire next object */
3166                 next_o_idx = o_ptr->next_o_idx;
3167
3168                 /* Describe it */
3169                 if (o_ptr->marked & OM_FOUND)
3170                 {
3171                         char o_name[MAX_NLEN];
3172
3173                         /* Not boring */
3174                         boring = FALSE;
3175
3176                         /* Obtain an object description */
3177                         object_desc(o_name, o_ptr, 0);
3178
3179 #ifdef JP
3180                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3181 #else
3182                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3183 #endif
3184
3185                         prt(out_val, 0, 0);
3186                         move_cursor_relative(y, x);
3187                         query = inkey();
3188
3189                         /* Always stop at "normal" keys */
3190                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3191
3192                         /* Sometimes stop at "space" key */
3193                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
3194
3195                         /* Change the intro */
3196                         s1 = _("それは", "It is ");
3197
3198                         /* Plurals */
3199                         if (o_ptr->number != 1) s1 = _("それらは", "They are ");
3200
3201                         /* Preposition */
3202 #ifdef JP
3203                         s2 = "の上";
3204                         s3 = "に見える";
3205 #else
3206                         s2 = "on ";
3207 #endif
3208
3209                 }
3210         }
3211
3212
3213         /* Feature code (applying "mimic" field) */
3214         feat = get_feat_mimic(c_ptr);
3215
3216         /* Require knowledge about grid, or ability to see grid */
3217         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
3218         {
3219                 /* Forget feature */
3220                 feat = feat_none;
3221         }
3222
3223         f_ptr = &f_info[feat];
3224
3225         /* Terrain feature if needed */
3226         if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
3227         {
3228                 cptr name;
3229
3230                 /* Hack -- special handling for quest entrances */
3231                 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
3232                 {
3233                         /* Set the quest number temporary */
3234                         IDX old_quest = p_ptr->inside_quest;
3235                         int j;
3236
3237                         /* Clear the text */
3238                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
3239                         quest_text_line = 0;
3240
3241                         p_ptr->inside_quest = c_ptr->special;
3242
3243                         /* Get the quest text */
3244                         init_flags = INIT_NAME_ONLY;
3245
3246                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3247
3248                         name = format(_("クエスト「%s」(%d階相当)", "the entrance to the quest '%s'(level %d)"), 
3249                                                 quest[c_ptr->special].name, quest[c_ptr->special].level);
3250
3251                         /* Reset the old quest number */
3252                         p_ptr->inside_quest = old_quest;
3253                 }
3254
3255                 /* Hack -- special handling for building doors */
3256                 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
3257                 {
3258                         name = building[f_ptr->subtype].name;
3259                 }
3260                 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
3261                 {
3262                         name = format(_("%s(%d階相当)", "%s(level %d)"), d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3263                 }
3264                 else if (have_flag(f_ptr->flags, FF_TOWN))
3265                 {
3266                         name = town[c_ptr->special].name;
3267                 }
3268                 else if (p_ptr->wild_mode && (feat == feat_floor))
3269                 {
3270                         name = _("道", "road");
3271                 }
3272                 else
3273                 {
3274                         name = f_name + f_ptr->name;
3275                 }
3276
3277
3278                 /* Pick a prefix */
3279                 if (*s2 &&
3280                     ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
3281                      (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
3282                      have_flag(f_ptr->flags, FF_TOWN)))
3283                 {
3284                         s2 = _("の中", "in ");
3285                 }
3286
3287                 /* Hack -- special introduction for store & building doors -KMW- */
3288                 if (have_flag(f_ptr->flags, FF_STORE) ||
3289                     have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
3290                     (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
3291                     have_flag(f_ptr->flags, FF_ENTRANCE))
3292                 {
3293 #ifdef JP
3294                         s2 = "の入口";
3295 #else
3296                         s3 = "";
3297 #endif
3298                 }
3299 #ifndef JP
3300                 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
3301                          have_flag(f_ptr->flags, FF_TOWN) ||
3302                          have_flag(f_ptr->flags, FF_SHALLOW) ||
3303                          have_flag(f_ptr->flags, FF_DEEP))
3304                 {
3305                         s3 ="";
3306                 }
3307                 else
3308                 {
3309                         /* Pick proper indefinite article */
3310                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
3311                 }
3312 #endif
3313
3314                 /* Display a message */
3315                 if (p_ptr->wizard)
3316                 {
3317                         char f_idx_str[32];
3318                         if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
3319                         else sprintf(f_idx_str, "%d", c_ptr->feat);
3320 #ifdef JP
3321                         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]);
3322 #else
3323                         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);
3324 #endif
3325                 }
3326                 else
3327 #ifdef JP
3328                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
3329 #else
3330                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3331 #endif
3332
3333                 prt(out_val, 0, 0);
3334                 move_cursor_relative(y, x);
3335                 query = inkey();
3336
3337                 /* Always stop at "normal" keys */
3338                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
3339         }
3340
3341         /* Stop on everything but "return" */
3342         if ((query != '\r') && (query != '\n')) return query;
3343
3344         /* Repeat forever */
3345         return 0;
3346 }
3347
3348
3349 /*
3350  * Handle "target" and "look".
3351  *
3352  * Note that this code can be called from "get_aim_dir()".
3353  *
3354  * All locations must be on the current panel.  Consider the use of
3355  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
3356  * some form of "scrolling" the map around the cursor.  
3357  * That is, consider the possibility of "auto-scrolling" the screen
3358  * while the cursor moves around.  This may require changes in the
3359  * "update_monster()" code to allow "visibility" even if off panel, and
3360  * may require dynamic recalculation of the "temp" grid set.
3361  *
3362  * Hack -- targeting/observing an "outer border grid" may induce
3363  * problems, so this is not currently allowed.
3364  *
3365  * The player can use the direction keys to move among "interesting"
3366  * grids in a heuristic manner, or the "space", "+", and "-" keys to
3367  * move through the "interesting" grids in a sequential manner, or
3368  * can enter "location" mode, and use the direction keys to move one
3369  * grid at a time in any direction.  The "t" (set target) command will
3370  * only target a monster (as opposed to a location) if the monster is
3371  * target_able and the "interesting" mode is being used.
3372  *
3373  * The current grid is described using the "look" method above, and
3374  * a new command may be entered at any time, but note that if the
3375  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
3376  * where "space" has no obvious meaning) then "space" will scan
3377  * through the description of the current grid until done, instead
3378  * of immediately jumping to the next "interesting" grid.  This
3379  * allows the "target" command to retain its old semantics.
3380  *
3381  * The "*", "+", and "-" keys may always be used to jump immediately
3382  * to the next (or previous) interesting grid, in the proper mode.
3383  *
3384  * The "return" key may always be used to scan through a complete
3385  * grid description (forever).
3386  *
3387  * This command will cancel any old target, even if used from
3388  * inside the "look" command.
3389  */
3390 bool target_set(BIT_FLAGS mode)
3391 {
3392         int             i, d, m, t, bd;
3393         POSITION y = p_ptr->y;
3394         POSITION x = p_ptr->x;
3395
3396         bool    done = FALSE;
3397         bool    flag = TRUE;
3398         char    query;
3399         char    info[80];
3400         char    same_key;
3401
3402         cave_type               *c_ptr;
3403
3404         int wid, hgt;
3405         
3406         get_screen_size(&wid, &hgt);
3407
3408         /* Cancel target */
3409         target_who = 0;
3410
3411
3412         /* Cancel tracking */
3413         /* health_track(0); */
3414
3415         if (rogue_like_commands)
3416         {
3417                 same_key = 'x';
3418         }
3419         else
3420         {
3421                 same_key = 'l';
3422         }
3423
3424         /* Prepare the "temp" array */
3425         target_set_prepare(mode);
3426
3427         /* Start near the player */
3428         m = 0;
3429
3430         /* Interact */
3431         while (!done)
3432         {
3433                 /* Interesting grids */
3434                 if (flag && temp_n)
3435                 {
3436                         y = temp_y[m];
3437                         x = temp_x[m];
3438
3439                         /* Set forcus */
3440                         change_panel_xy(y, x);
3441
3442                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3443
3444                         /* Access */
3445                         c_ptr = &cave[y][x];
3446
3447                         /* Allow target */
3448                         if (target_able(c_ptr->m_idx))
3449                         {
3450                                 strcpy(info, _("q止 t決 p自 o現 +次 -前", "q,t,p,o,+,-,<dir>"));
3451                         }
3452
3453                         /* Dis-allow target */
3454                         else
3455                         {
3456                                 strcpy(info, _("q止 p自 o現 +次 -前", "q,p,o,+,-,<dir>"));
3457                         }
3458
3459                         if (cheat_sight)
3460                         {
3461                                 char cheatinfo[30];
3462                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
3463                                         los(p_ptr->y, p_ptr->x, y, x),
3464                                         projectable(p_ptr->y, p_ptr->x, y, x));
3465                                 strcat(info, cheatinfo);
3466                         }
3467                         
3468                         /* Describe and Prompt */
3469                         while (TRUE){
3470                                 query = target_set_aux(y, x, mode, info);
3471                                 if(query)break;
3472                         }
3473
3474                         /* Cancel tracking */
3475                         /* health_track(0); */
3476
3477                         /* Assume no "direction" */
3478                         d = 0;
3479
3480                         if (use_menu)
3481                         {
3482                                 if (query == '\r') query = 't';
3483                         }  
3484
3485                         /* Analyze */
3486                         switch (query)
3487                         {
3488                                 case ESCAPE:
3489                                 case 'q':
3490                                 {
3491                                         done = TRUE;
3492                                         break;
3493                                 }
3494
3495                                 case 't':
3496                                 case '.':
3497                                 case '5':
3498                                 case '0':
3499                                 {
3500                                         if (target_able(c_ptr->m_idx))
3501                                         {
3502                                                 health_track(c_ptr->m_idx);
3503                                                 target_who = c_ptr->m_idx;
3504                                                 target_row = y;
3505                                                 target_col = x;
3506                                                 done = TRUE;
3507                                         }
3508                                         else
3509                                         {
3510                                                 bell();
3511                                         }
3512                                         break;
3513                                 }
3514
3515                                 case ' ':
3516                                 case '*':
3517                                 case '+':
3518                                 {
3519                                         if (++m == temp_n)
3520                                         {
3521                                                 m = 0;
3522                                                 if (!expand_list) done = TRUE;
3523                                         }
3524                                         break;
3525                                 }
3526
3527                                 case '-':
3528                                 {
3529                                         if (m-- == 0)
3530                                         {
3531                                                 m = temp_n - 1;
3532                                                 if (!expand_list) done = TRUE;
3533                                         }
3534                                         break;
3535                                 }
3536
3537                                 case 'p':
3538                                 {
3539                                         /* Recenter the map around the player */
3540                                         verify_panel();
3541
3542                                         p_ptr->update |= (PU_MONSTERS);
3543
3544                                         p_ptr->redraw |= (PR_MAP);
3545
3546                                         p_ptr->window |= (PW_OVERHEAD);
3547                                         handle_stuff();
3548
3549                                         /* Recalculate interesting grids */
3550                                         target_set_prepare(mode);
3551
3552                                         y = p_ptr->y;
3553                                         x = p_ptr->x;
3554                                 }
3555
3556                                 case 'o':
3557                                 {
3558                                         flag = FALSE;
3559                                         break;
3560                                 }
3561
3562                                 case 'm':
3563                                 {
3564                                         break;
3565                                 }
3566
3567                                 default:
3568                                 {
3569                                         if(query == same_key)
3570                                         {
3571                                                 if (++m == temp_n)
3572                                                 {
3573                                                         m = 0;
3574                                                         if (!expand_list) done = TRUE;
3575                                                 }
3576                                         }
3577                                         else
3578                                         {
3579                                                 /* Extract the action (if any) */
3580                                                 d = get_keymap_dir(query);
3581
3582                                                 if (!d) bell();
3583                                                 break;
3584                                         }
3585                                 }
3586                         }
3587                         /* Hack -- move around */
3588                         if (d)
3589                         {
3590                                 /* Modified to scroll to monster */
3591                                 POSITION y2 = panel_row_min;
3592                                 POSITION x2 = panel_col_min;
3593
3594                                 /* Find a new monster */
3595                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
3596
3597                                 /* Request to target past last interesting grid */
3598                                 while (flag && (i < 0))
3599                                 {
3600                                         /* Note the change */
3601                                         if (change_panel(ddy[d], ddx[d]))
3602                                         {
3603                                                 int v = temp_y[m];
3604                                                 int u = temp_x[m];
3605
3606                                                 /* Recalculate interesting grids */
3607                                                 target_set_prepare(mode);
3608
3609                                                 /* Look at interesting grids */
3610                                                 flag = TRUE;
3611
3612                                                 /* Find a new monster */
3613                                                 i = target_pick(v, u, ddy[d], ddx[d]);
3614
3615                                                 /* Use that grid */
3616                                                 if (i >= 0) m = i;
3617                                         }
3618
3619                                         /* Nothing interesting */
3620                                         else
3621                                         {
3622                                                 int dx = ddx[d];
3623                                                 int dy = ddy[d];
3624
3625                                                 /* Restore previous position */
3626                                                 panel_row_min = y2;
3627                                                 panel_col_min = x2;
3628                                                 panel_bounds_center();
3629
3630                                                 p_ptr->update |= (PU_MONSTERS);
3631
3632                                                 p_ptr->redraw |= (PR_MAP);
3633
3634                                                 p_ptr->window |= (PW_OVERHEAD);
3635                                                 handle_stuff();
3636
3637                                                 /* Recalculate interesting grids */
3638                                                 target_set_prepare(mode);
3639
3640                                                 /* Look at boring grids */
3641                                                 flag = FALSE;
3642
3643                                                 /* Move */
3644                                                 x += dx;
3645                                                 y += dy;
3646
3647                                                 /* Do not move horizontally if unnecessary */
3648                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3649                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
3650                                                 {
3651                                                         dx = 0;
3652                                                 }
3653
3654                                                 /* Do not move vertically if unnecessary */
3655                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3656                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
3657                                                 {
3658                                                         dy = 0;
3659                                                 }
3660
3661                                                 /* Apply the motion */
3662                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
3663                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
3664                                                 {
3665                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
3666                                                 }
3667
3668                                                 /* Slide into legality */
3669                                                 if (x >= cur_wid-1) x = cur_wid - 2;
3670                                                 else if (x <= 0) x = 1;
3671
3672                                                 /* Slide into legality */
3673                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
3674                                                 else if (y <= 0) y = 1;
3675                                         }
3676                                 }
3677
3678                                 /* Use that grid */
3679                                 m = i;
3680                         }
3681                 }
3682
3683                 /* Arbitrary grids */
3684                 else
3685                 {
3686                         bool move_fast = FALSE;
3687
3688                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3689
3690                         /* Access */
3691                         c_ptr = &cave[y][x];
3692
3693                         /* Default prompt */
3694                         strcpy(info, _("q止 t決 p自 m近 +次 -前", "q,t,p,m,+,-,<dir>"));
3695
3696                         if (cheat_sight)
3697                         {
3698                                 char cheatinfo[30];
3699                                 sprintf(cheatinfo, " LOS:%d, PROJECTABLE:%d",
3700                                         los(p_ptr->y, p_ptr->x, y, x),
3701                                         projectable(p_ptr->y, p_ptr->x, y, x));
3702                                 strcat(info, cheatinfo);
3703                         }
3704
3705                         /* Describe and Prompt (enable "TARGET_LOOK") */
3706                         while ((query = target_set_aux(y, x, mode | TARGET_LOOK, info)) == 0);
3707
3708                         /* Cancel tracking */
3709                         /* health_track(0); */
3710
3711                         /* Assume no direction */
3712                         d = 0;
3713
3714                         if (use_menu)
3715                         {
3716                                 if (query == '\r') query = 't';
3717                         }  
3718
3719                         /* Analyze the keypress */
3720                         switch (query)
3721                         {
3722                                 case ESCAPE:
3723                                 case 'q':
3724                                 {
3725                                         done = TRUE;
3726                                         break;
3727                                 }
3728
3729                                 case 't':
3730                                 case '.':
3731                                 case '5':
3732                                 case '0':
3733                                 {
3734                                         target_who = -1;
3735                                         target_row = y;
3736                                         target_col = x;
3737                                         done = TRUE;
3738                                         break;
3739                                 }
3740
3741                                 case 'p':
3742                                 {
3743                                         /* Recenter the map around the player */
3744                                         verify_panel();
3745
3746                                         p_ptr->update |= (PU_MONSTERS);
3747
3748                                         p_ptr->redraw |= (PR_MAP);
3749
3750                                         p_ptr->window |= (PW_OVERHEAD);
3751                                         handle_stuff();
3752
3753                                         /* Recalculate interesting grids */
3754                                         target_set_prepare(mode);
3755
3756                                         y = p_ptr->y;
3757                                         x = p_ptr->x;
3758                                 }
3759
3760                                 case 'o':
3761                                 {
3762                                         break;
3763                                 }
3764
3765                                 case ' ':
3766                                 case '*':
3767                                 case '+':
3768                                 case '-':
3769                                 case 'm':
3770                                 {
3771                                         flag = TRUE;
3772
3773                                         m = 0;
3774                                         bd = 999;
3775
3776                                         /* Pick a nearby monster */
3777                                         for (i = 0; i < temp_n; i++)
3778                                         {
3779                                                 t = distance(y, x, temp_y[i], temp_x[i]);
3780
3781                                                 /* Pick closest */
3782                                                 if (t < bd)
3783                                                 {
3784                                                         m = i;
3785                                                         bd = t;
3786                                                 }
3787                                         }
3788
3789                                         /* Nothing interesting */
3790                                         if (bd == 999) flag = FALSE;
3791
3792                                         break;
3793                                 }
3794
3795                                 default:
3796                                 {
3797                                         /* Extract the action (if any) */
3798                                         d = get_keymap_dir(query);
3799
3800                                         /* XTRA HACK MOVEFAST */
3801                                         if (isupper(query)) move_fast = TRUE;
3802
3803                                         if (!d) bell();
3804                                         break;
3805                                 }
3806                         }
3807
3808                         /* Handle "direction" */
3809                         if (d)
3810                         {
3811                                 int dx = ddx[d];
3812                                 int dy = ddy[d];
3813
3814                                 /* XTRA HACK MOVEFAST */
3815                                 if (move_fast)
3816                                 {
3817                                         int mag = MIN(wid / 2, hgt / 2);
3818                                         x += dx * mag;
3819                                         y += dy * mag;
3820                                 }
3821                                 else
3822                                 {
3823                                         x += dx;
3824                                         y += dy;
3825                                 }
3826
3827                                 /* Do not move horizontally if unnecessary */
3828                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3829                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
3830                                 {
3831                                         dx = 0;
3832                                 }
3833
3834                                 /* Do not move vertically if unnecessary */
3835                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3836                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
3837                                 {
3838                                         dy = 0;
3839                                 }
3840
3841                                 /* Apply the motion */
3842                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
3843                                          (x >= panel_col_min + wid) || (x < panel_col_min))
3844                                 {
3845                                         if (change_panel(dy, dx)) target_set_prepare(mode);
3846                                 }
3847
3848                                 /* Slide into legality */
3849                                 if (x >= cur_wid-1) x = cur_wid - 2;
3850                                 else if (x <= 0) x = 1;
3851
3852                                 /* Slide into legality */
3853                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
3854                                 else if (y <= 0) y = 1;
3855                         }
3856                 }
3857         }
3858
3859         /* Forget */
3860         temp_n = 0;
3861
3862         /* Clear the top line */
3863         prt("", 0, 0);
3864
3865         /* Recenter the map around the player */
3866         verify_panel();
3867
3868         p_ptr->update |= (PU_MONSTERS);
3869
3870         p_ptr->redraw |= (PR_MAP);
3871
3872         p_ptr->window |= (PW_OVERHEAD);
3873         handle_stuff();
3874
3875         /* Failure to set target */
3876         if (!target_who) return (FALSE);
3877
3878         /* Success */
3879         return (TRUE);
3880 }
3881
3882
3883 /*
3884  * Get an "aiming direction" from the user.
3885  *
3886  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
3887  * "0" for "current target", and "-1" for "entry aborted".
3888  *
3889  * Note that "Force Target", if set, will pre-empt user interaction,
3890  * if there is a usable target already set.
3891  *
3892  * Note that confusion over-rides any (explicit?) user choice.
3893  */
3894 bool get_aim_dir(DIRECTION *dp)
3895 {
3896         DIRECTION dir;
3897         char    command;
3898         cptr    p;
3899         COMMAND_CODE code;
3900
3901         (*dp) = 0;
3902
3903         /* Global direction */
3904         dir = command_dir;
3905
3906         /* Hack -- auto-target if requested */
3907         if (use_old_target && target_okay()) dir = 5;
3908
3909         if (repeat_pull(&code))
3910         {
3911                 /* Confusion? */
3912
3913                 /* Verify */
3914                 if (!(code == 5 && !target_okay()))
3915                 {
3916 /*                      return (TRUE); */
3917                         dir = (DIRECTION)code;
3918                 }
3919         }
3920         *dp = (DIRECTION)code;
3921
3922         /* Ask until satisfied */
3923         while (!dir)
3924         {
3925                 /* Choose a prompt */
3926                 if (!target_okay())
3927                 {
3928                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
3929                 }
3930                 else
3931                 {
3932                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
3933                 }
3934
3935                 /* Get a command (or Cancel) */
3936                 if (!get_com(p, &command, TRUE)) break;
3937
3938                 if (use_menu)
3939                 {
3940                         if (command == '\r') command = 't';
3941                 }  
3942
3943                 /* Convert various keys to "standard" keys */
3944                 switch (command)
3945                 {
3946                         /* Use current target */
3947                         case 'T':
3948                         case 't':
3949                         case '.':
3950                         case '5':
3951                         case '0':
3952                         {
3953                                 dir = 5;
3954                                 break;
3955                         }
3956
3957                         /* Set new target */
3958                         case '*':
3959                         case ' ':
3960                         case '\r':
3961                         {
3962                                 if (target_set(TARGET_KILL)) dir = 5;
3963                                 break;
3964                         }
3965
3966                         default:
3967                         {
3968                                 /* Extract the action (if any) */
3969                                 dir = get_keymap_dir(command);
3970
3971                                 break;
3972                         }
3973                 }
3974
3975                 /* Verify requested targets */
3976                 if ((dir == 5) && !target_okay()) dir = 0;
3977
3978                 /* Error */
3979                 if (!dir) bell();
3980         }
3981
3982         /* No direction */
3983         if (!dir)
3984         {
3985                 project_length = 0; /* reset to default */
3986                 return (FALSE);
3987         }
3988
3989         /* Save the direction */
3990         command_dir = dir;
3991
3992         /* Check for confusion */
3993         if (p_ptr->confused)
3994         {
3995                 /* Random direction */
3996                 dir = ddd[randint0(8)];
3997         }
3998
3999         /* Notice confusion */
4000         if (command_dir != dir)
4001         {
4002                 /* Warn the user */
4003                 msg_print(_("あなたは混乱している。", "You are confused."));
4004         }
4005
4006         /* Save direction */
4007         (*dp) = dir;
4008
4009 /*      repeat_push(dir); */
4010         repeat_push((COMMAND_CODE)command_dir);
4011
4012         /* A "valid" direction was entered */
4013         return (TRUE);
4014 }
4015
4016
4017 bool get_direction(DIRECTION *dp, bool allow_under, bool with_steed)
4018 {
4019         DIRECTION dir;
4020         cptr prompt;
4021         COMMAND_CODE code;
4022
4023         (*dp) = 0;
4024
4025         /* Global direction */
4026         dir = command_dir;
4027
4028         if (repeat_pull(&code))
4029         {
4030                 dir = (DIRECTION)code;
4031                 /*              return (TRUE); */
4032         }
4033         *dp = (DIRECTION)code;
4034
4035         if (allow_under)
4036         {
4037                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
4038         }
4039         else
4040         {
4041                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
4042         }
4043
4044         /* Get a direction */
4045         while (!dir)
4046         {
4047                 char ch;
4048
4049                 /* Get a command (or Cancel) */
4050                 if (!get_com(prompt, &ch, TRUE)) break;
4051
4052                 /* Look down */
4053                 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.')))
4054                 {
4055                         dir = 5;
4056                 }
4057                 else
4058                 {
4059                         /* Look up the direction */
4060                         dir = get_keymap_dir(ch);
4061
4062                         if (!dir) bell();
4063                 }
4064         }
4065
4066         /* Prevent weirdness */
4067         if ((dir == 5) && (!allow_under)) dir = 0;
4068
4069         /* Aborted */
4070         if (!dir) return (FALSE);
4071
4072         /* Save desired direction */
4073         command_dir = dir;
4074
4075         /* Apply "confusion" */
4076         if (p_ptr->confused)
4077         {
4078                 /* Standard confusion */
4079                 if (randint0(100) < 75)
4080                 {
4081                         /* Random direction */
4082                         dir = ddd[randint0(8)];
4083                 }
4084         }
4085         else if (p_ptr->riding && with_steed)
4086         {
4087                 monster_type *m_ptr = &m_list[p_ptr->riding];
4088                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4089
4090                 if (MON_CONFUSED(m_ptr))
4091                 {
4092                         /* Standard confusion */
4093                         if (randint0(100) < 75)
4094                         {
4095                                 /* Random direction */
4096                                 dir = ddd[randint0(8)];
4097                         }
4098                 }
4099                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
4100                 {
4101                         /* Random direction */
4102                         dir = ddd[randint0(8)];
4103                 }
4104                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
4105                 {
4106                         /* Random direction */
4107                         dir = ddd[randint0(8)];
4108                 }
4109         }
4110
4111         /* Notice confusion */
4112         if (command_dir != dir)
4113         {
4114                 if (p_ptr->confused)
4115                 {
4116                         /* Warn the user */
4117                         msg_print(_("あなたは混乱している。", "You are confused."));
4118                 }
4119                 else
4120                 {
4121                         char m_name[80];
4122                         monster_type *m_ptr = &m_list[p_ptr->riding];
4123
4124                         monster_desc(m_name, m_ptr, 0);
4125                         if (MON_CONFUSED(m_ptr))
4126                         {
4127                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
4128                         }
4129                         else
4130                         {
4131                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
4132                         }
4133                 }
4134         }
4135
4136         /* Save direction */
4137         (*dp) = dir;
4138
4139         /*      repeat_push(dir); */
4140         repeat_push((COMMAND_CODE)command_dir);
4141
4142         /* Success */
4143         return (TRUE);
4144 }
4145
4146 /*
4147  * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
4148  * and place it into "command_dir", unless we already have one.
4149  *
4150  * This function should be used for all "repeatable" commands, such as
4151  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
4152  * as all commands which must reference a grid adjacent to the player,
4153  * and which may not reference the grid under the player.  Note that,
4154  * for example, it is no longer possible to "disarm" or "open" chests
4155  * in the same grid as the player.
4156  *
4157  * Direction "5" is illegal and will (cleanly) abort the command.
4158  *
4159  * This function tracks and uses the "global direction", and uses
4160  * that as the "desired direction", to which "confusion" is applied.
4161  */
4162 bool get_rep_dir(DIRECTION *dp, bool under)
4163 {
4164         DIRECTION dir;
4165         cptr prompt;
4166         COMMAND_CODE code;
4167
4168         (*dp) = 0;
4169
4170         /* Global direction */
4171         dir = command_dir;
4172
4173         if (repeat_pull(&code))
4174         {
4175                 dir = (DIRECTION)code;
4176 /*              return (TRUE); */
4177         }
4178         *dp = (DIRECTION)code;
4179
4180         if (under)
4181         {
4182                 prompt = _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ");
4183         }
4184         else
4185         {
4186                 prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
4187         }
4188         
4189         /* Get a direction */
4190         while (!dir)
4191         {
4192                 char ch;
4193
4194                 /* Get a command (or Cancel) */
4195                 if (!get_com(prompt, &ch, TRUE)) break;
4196
4197                 /* Look down */
4198                 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
4199                 {
4200                         dir = 5;
4201                 }
4202                 else
4203                 {
4204                         /* Look up the direction */
4205                         dir = get_keymap_dir(ch);
4206
4207                         if (!dir) bell();
4208                 }
4209         }
4210
4211         /* Prevent weirdness */
4212         if ((dir == 5) && (!under)) dir = 0;
4213
4214         /* Aborted */
4215         if (!dir) return (FALSE);
4216
4217         /* Save desired direction */
4218         command_dir = dir;
4219
4220         /* Apply "confusion" */
4221         if (p_ptr->confused)
4222         {
4223                 /* Standard confusion */
4224                 if (randint0(100) < 75)
4225                 {
4226                         /* Random direction */
4227                         dir = ddd[randint0(8)];
4228                 }
4229         }
4230         else if (p_ptr->riding)
4231         {
4232                 monster_type *m_ptr = &m_list[p_ptr->riding];
4233                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4234
4235                 if (MON_CONFUSED(m_ptr))
4236                 {
4237                         /* Standard confusion */
4238                         if (randint0(100) < 75)
4239                         {
4240                                 /* Random direction */
4241                                 dir = ddd[randint0(8)];
4242                         }
4243                 }
4244                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
4245                 {
4246                         /* Random direction */
4247                         dir = ddd[randint0(8)];
4248                 }
4249                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
4250                 {
4251                         /* Random direction */
4252                         dir = ddd[randint0(8)];
4253                 }
4254         }
4255
4256         /* Notice confusion */
4257         if (command_dir != dir)
4258         {
4259                 if (p_ptr->confused)
4260                 {
4261                         /* Warn the user */
4262                         msg_print(_("あなたは混乱している。", "You are confused."));
4263                 }
4264                 else
4265                 {
4266                         char m_name[80];
4267                         monster_type *m_ptr = &m_list[p_ptr->riding];
4268
4269                         monster_desc(m_name, m_ptr, 0);
4270                         if (MON_CONFUSED(m_ptr))
4271                         {
4272                                 msg_format(_("%sは混乱している。", "%^s is confusing."), m_name);
4273                         }
4274                         else
4275                         {
4276                                 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
4277                         }
4278                 }
4279         }
4280
4281         /* Save direction */
4282         (*dp) = dir;
4283
4284 /*      repeat_push(dir); */
4285         repeat_push((COMMAND_CODE)command_dir);
4286
4287         /* Success */
4288         return (TRUE);
4289 }
4290
4291 void gain_level_reward(int chosen_reward)
4292 {
4293         object_type *q_ptr;
4294         object_type forge;
4295         char        wrath_reason[32] = "";
4296         int         nasty_chance = 6;
4297         OBJECT_TYPE_VALUE dummy = 0;
4298         OBJECT_SUBTYPE_VALUE dummy2 = 0;
4299         int         type, effect;
4300         cptr        reward = NULL;
4301         char o_name[MAX_NLEN];
4302
4303         int count = 0;
4304
4305         if (!chosen_reward)
4306         {
4307                 if (multi_rew) return;
4308                 else multi_rew = TRUE;
4309         }
4310
4311
4312         if (p_ptr->lev == 13) nasty_chance = 2;
4313         else if (!(p_ptr->lev % 13)) nasty_chance = 3;
4314         else if (!(p_ptr->lev % 14)) nasty_chance = 12;
4315
4316         if (one_in_(nasty_chance))
4317                 type = randint1(20); /* Allow the 'nasty' effects */
4318         else
4319                 type = randint1(15) + 5; /* Or disallow them */
4320
4321         if (type < 1) type = 1;
4322         if (type > 20) type = 20;
4323         type--;
4324
4325
4326         sprintf(wrath_reason, _("%sの怒り", "the Wrath of %s"), chaos_patrons[p_ptr->chaos_patron]);
4327
4328         effect = chaos_rewards[p_ptr->chaos_patron][type];
4329
4330         if (one_in_(6) && !chosen_reward)
4331         {
4332                 msg_format(_("%^sは褒美としてあなたを突然変異させた。", "%^s rewards you with a mutation!"), chaos_patrons[p_ptr->chaos_patron]);
4333                 (void)gain_random_mutation(0);
4334                 reward = _("変異した。", "mutation");
4335         }
4336         else
4337         {
4338         switch (chosen_reward ? chosen_reward : effect)
4339         {
4340
4341                 case REW_POLY_SLF:
4342
4343                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4344                         msg_print(_("「汝、新たなる姿を必要とせり!」", "'Thou needst a new form, mortal!'"));
4345
4346                         do_poly_self();
4347                         reward = _("変異した。", "polymorphing");
4348                         break;
4349
4350                 case REW_GAIN_EXP:
4351
4352                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4353                         msg_print(_("「汝は良く行いたり!続けよ!」", "'Well done, mortal! Lead on!'"));
4354
4355                         if (p_ptr->prace == RACE_ANDROID)
4356                         {
4357                                 msg_print(_("しかし何も起こらなかった。", "But, nothing happen."));
4358                         }
4359                         else if (p_ptr->exp < PY_MAX_EXP)
4360                         {
4361                                 s32b ee = (p_ptr->exp / 2) + 10;
4362                                 if (ee > 100000L) ee = 100000L;
4363                                 msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
4364
4365                                 gain_exp(ee);
4366                                 reward = _("経験値を得た", "experience");
4367                         }
4368                         break;
4369
4370                 case REW_LOSE_EXP:
4371
4372                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4373                         msg_print(_("「下僕よ、汝それに値せず。」", "'Thou didst not deserve that, slave.'"));
4374
4375                         if (p_ptr->prace == RACE_ANDROID)
4376                         {
4377                                 msg_print(_("しかし何も起こらなかった。", "But, nothing happen."));
4378                         }
4379                         else
4380                         {
4381                                 lose_exp(p_ptr->exp / 6);
4382                                 reward = _("経験値を失った。", "losing experience");
4383                         }
4384                         break;
4385
4386                 case REW_GOOD_OBJ:
4387 #ifdef JP
4388                         msg_format("%sの声がささやいた:",
4389                                 chaos_patrons[p_ptr->chaos_patron]);
4390 #else
4391                         msg_format("The voice of %s whispers:",
4392                                 chaos_patrons[p_ptr->chaos_patron]);
4393 #endif
4394
4395                         msg_print(_("「我が与えし物を賢明に使うべし。」", "'Use my gift wisely.'"));
4396
4397                         acquirement(p_ptr->y, p_ptr->x, 1, FALSE, FALSE, FALSE);
4398                         reward = _("上質なアイテムを手に入れた。", "a good item");
4399                         break;
4400
4401                 case REW_GREA_OBJ:
4402
4403                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4404                         msg_print(_("「我が与えし物を賢明に使うべし。」", "'Use my gift wisely.'"));
4405
4406                         acquirement(p_ptr->y, p_ptr->x, 1, TRUE, FALSE, FALSE);
4407                         reward = _("高級品のアイテムを手に入れた。", "an excellent item");
4408                         break;
4409
4410                 case REW_CHAOS_WP:
4411
4412                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4413                         msg_print(_("「汝の行いは貴き剣に値せり。」", "'Thy deed hath earned thee a worthy blade.'"));
4414                         q_ptr = &forge;
4415                         dummy = TV_SWORD;
4416                         switch (randint1(p_ptr->lev))
4417                         {
4418                                 case 0: case 1:
4419                                         dummy2 = SV_DAGGER;
4420                                         break;
4421                                 case 2: case 3:
4422                                         dummy2 = SV_MAIN_GAUCHE;
4423                                         break;
4424                                 case 4:
4425                                         dummy2 = SV_TANTO;
4426                                         break;
4427                                 case 5: case 6:
4428                                         dummy2 = SV_RAPIER;
4429                                         break;
4430                                 case 7: case 8:
4431                                         dummy2 = SV_SMALL_SWORD;
4432                                         break;
4433                                 case 9: case 10:
4434                                         dummy2 = SV_BASILLARD;
4435                                         break;
4436                                 case 11: case 12: case 13:
4437                                         dummy2 = SV_SHORT_SWORD;
4438                                         break;
4439                                 case 14: case 15:
4440                                         dummy2 = SV_SABRE;
4441                                         break;
4442                                 case 16: case 17:
4443                                         dummy2 = SV_CUTLASS;
4444                                         break;
4445                                 case 18:
4446                                         dummy2 = SV_WAKIZASHI;
4447                                         break;
4448                                 case 19:
4449                                         dummy2 = SV_KHOPESH;
4450                                         break;
4451                                 case 20:
4452                                         dummy2 = SV_TULWAR;
4453                                         break;
4454                                 case 21:
4455                                         dummy2 = SV_BROAD_SWORD;
4456                                         break;
4457                                 case 22: case 23:
4458                                         dummy2 = SV_LONG_SWORD;
4459                                         break;
4460                                 case 24: case 25:
4461                                         dummy2 = SV_SCIMITAR;
4462                                         break;
4463                                 case 26:
4464                                         dummy2 = SV_NINJATO;
4465                                         break;
4466                                 case 27:
4467                                         dummy2 = SV_KATANA;
4468                                         break;
4469                                 case 28: case 29:
4470                                         dummy2 = SV_BASTARD_SWORD;
4471                                         break;
4472                                 case 30:
4473                                         dummy2 = SV_GREAT_SCIMITAR;
4474                                         break;
4475                                 case 31:
4476                                         dummy2 = SV_CLAYMORE;
4477                                         break;
4478                                 case 32:
4479                                         dummy2 = SV_ESPADON;
4480                                         break;
4481                                 case 33:
4482                                         dummy2 = SV_TWO_HANDED_SWORD;
4483                                         break;
4484                                 case 34:
4485                                         dummy2 = SV_FLAMBERGE;
4486                                         break;
4487                                 case 35:
4488                                         dummy2 = SV_NO_DACHI;
4489                                         break;
4490                                 case 36:
4491                                         dummy2 = SV_EXECUTIONERS_SWORD;
4492                                         break;
4493                                 case 37:
4494                                         dummy2 = SV_ZWEIHANDER;
4495                                         break;
4496                                 case 38:
4497                                         dummy2 = SV_HAYABUSA;
4498                                         break;
4499                                 default:
4500                                         dummy2 = SV_BLADE_OF_CHAOS;
4501                         }
4502
4503                         object_prep(q_ptr, lookup_kind(dummy, dummy2));
4504                         q_ptr->to_h = 3 + randint1(dun_level) % 10;
4505                         q_ptr->to_d = 3 + randint1(dun_level) % 10;
4506                         one_resistance(q_ptr);
4507                         q_ptr->name2 = EGO_CHAOTIC;
4508
4509                         /* Drop it in the dungeon */
4510                         (void)drop_near(q_ptr, -1, p_ptr->y, p_ptr->x);
4511                         reward = _("(混沌)の武器を手に入れた。", "chaos weapon");
4512                         break;
4513
4514                 case REW_GOOD_OBS:
4515
4516                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4517                         msg_print(_("「汝の行いは貴き報いに値せり。」", "'Thy deed hath earned thee a worthy reward.'"));
4518
4519                         acquirement(p_ptr->y, p_ptr->x, randint1(2) + 1, FALSE, FALSE, FALSE);
4520                         reward = _("上質なアイテムを手に入れた。", "good items");
4521                         break;
4522
4523                 case REW_GREA_OBS:
4524
4525                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4526                         msg_print(_("「下僕よ、汝の献身への我が惜しみ無き報いを見るがよい。」", "'Behold, mortal, how generously I reward thy loyalty.'"));
4527
4528                         acquirement(p_ptr->y, p_ptr->x, randint1(2) + 1, TRUE, FALSE, FALSE);
4529                         reward = _("高級品のアイテムを手に入れた。", "excellent items");
4530                         break;
4531
4532                 case REW_TY_CURSE:
4533 #ifdef JP
4534                         msg_format("%sの声が轟き渡った:", chaos_patrons[p_ptr->chaos_patron]);
4535 #else
4536                         msg_format("The voice of %s thunders:", chaos_patrons[p_ptr->chaos_patron]);
4537 #endif
4538
4539                         msg_print(_("「下僕よ、汝傲慢なり。」", "'Thou art growing arrogant, mortal.'"));
4540
4541                         (void)activate_ty_curse(FALSE, &count);
4542                         reward = _("禍々しい呪いをかけられた。", "cursing");
4543                         break;
4544
4545                 case REW_SUMMON_M:
4546
4547                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4548                         msg_print(_("「我が下僕たちよ、かの傲慢なる者を倒すべし!」", "'My pets, destroy the arrogant mortal!'"));
4549
4550                         for (dummy = 0; dummy < randint1(5) + 1; dummy++)
4551                         {
4552                                 (void)summon_specific(0, p_ptr->y, p_ptr->x, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
4553                         }
4554                         reward = _("モンスターを召喚された。", "summoning hostile monsters");
4555                         break;
4556
4557
4558                 case REW_H_SUMMON:
4559
4560                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4561                         msg_print(_("「汝、より強き敵を必要とせり!」", "'Thou needst worthier opponents!'"));
4562
4563                         activate_hi_summon(p_ptr->y, p_ptr->x, FALSE);
4564                         reward = _("モンスターを召喚された。", "summoning many hostile monsters");
4565                         break;
4566
4567
4568                 case REW_DO_HAVOC:
4569 #ifdef JP
4570                         msg_format("%sの声が響き渡った:",
4571                                 chaos_patrons[p_ptr->chaos_patron]);
4572 #else
4573                         msg_format("The voice of %s booms out:",
4574                                 chaos_patrons[p_ptr->chaos_patron]);
4575 #endif
4576
4577                         msg_print(_("「死と破壊こそ我が喜びなり!」", "'Death and destruction! This pleaseth me!'"));
4578
4579                         call_chaos();
4580                         reward = _("カオスの力が渦巻いた。", "calling chaos");
4581                         break;
4582
4583
4584                 case REW_GAIN_ABL:
4585 #ifdef JP
4586                         msg_format("%sの声が鳴り響いた:",
4587                                 chaos_patrons[p_ptr->chaos_patron]);
4588 #else
4589                         msg_format("The voice of %s rings out:",
4590                                 chaos_patrons[p_ptr->chaos_patron]);
4591 #endif
4592
4593                         msg_print(_("「留まるのだ、下僕よ。余が汝の肉体を鍛えん。」", "'Stay, mortal, and let me mold thee.'"));
4594
4595                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
4596                                 do_inc_stat(chaos_stats[p_ptr->chaos_patron]);
4597                         else
4598                                 do_inc_stat(randint0(6));
4599                         reward = _("能力値が上がった。", "increasing a stat");
4600                         break;
4601
4602
4603                 case REW_LOSE_ABL:
4604 #ifdef JP
4605                         msg_format("%sの声が響き渡った:",
4606                                 chaos_patrons[p_ptr->chaos_patron]);
4607 #else
4608                         msg_format("The voice of %s booms out:",
4609                                 chaos_patrons[p_ptr->chaos_patron]);
4610 #endif
4611
4612                         msg_print(_("「下僕よ、余は汝に飽みたり。」", "'I grow tired of thee, mortal.'"));
4613
4614                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
4615                                 do_dec_stat(chaos_stats[p_ptr->chaos_patron]);
4616                         else
4617                                 (void)do_dec_stat(randint0(6));
4618                         reward = _("能力値が下がった。", "decreasing a stat");
4619                         break;
4620
4621
4622                 case REW_RUIN_ABL:
4623
4624 #ifdef JP
4625                         msg_format("%sの声が轟き渡った:",
4626                                 chaos_patrons[p_ptr->chaos_patron]);
4627 #else
4628                         msg_format("The voice of %s thunders:",
4629                                 chaos_patrons[p_ptr->chaos_patron]);
4630 #endif
4631
4632                         msg_print(_("「汝、謙虚たることを学ぶべし!」", "'Thou needst a lesson in humility, mortal!'"));
4633                         msg_print(_("あなたは以前より弱くなった!", "You feel less powerful!"));
4634
4635                         for (dummy = 0; dummy < 6; dummy++)
4636                         {
4637                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
4638                         }
4639                         reward = _("全能力値が下がった。", "decreasing all stats");
4640                         break;
4641
4642                 case REW_POLY_WND:
4643
4644                         msg_format(_("%sの力が触れるのを感じた。", "You feel the power of %s touch you."),
4645                                 chaos_patrons[p_ptr->chaos_patron]);
4646                         do_poly_wounds();
4647                         reward = _("傷が変化した。", "polymorphing wounds");
4648                         break;
4649
4650                 case REW_AUGM_ABL:
4651
4652                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4653
4654                         msg_print(_("「我がささやかなる賜物を受けとるがよい!」", "'Receive this modest gift from me!'"));
4655
4656                         for (dummy = 0; dummy < 6; dummy++)
4657                         {
4658                                 (void)do_inc_stat(dummy);
4659                         }
4660                         reward = _("全能力値が上がった。", "increasing all stats");
4661                         break;
4662
4663                 case REW_HURT_LOT:
4664
4665                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4666                         msg_print(_("「苦しむがよい、無能な愚か者よ!」", "'Suffer, pathetic fool!'"));
4667
4668                         fire_ball(GF_DISINTEGRATE, 0, p_ptr->lev * 4, 4);
4669                         take_hit(DAMAGE_NOESCAPE, p_ptr->lev * 4, wrath_reason, -1);
4670                         reward = _("分解の球が発生した。", "generating disintegration ball");
4671                         break;
4672
4673                 case REW_HEAL_FUL:
4674
4675                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4676                         (void)restore_level();
4677                         (void)restore_all_status();
4678                         (void)true_healing(5000);
4679                         reward = _("体力が回復した。", "healing");
4680                         break;
4681
4682                 case REW_CURSE_WP:
4683
4684                         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
4685                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4686                         msg_print(_("「汝、武器に頼ることなかれ。」", "'Thou reliest too much on thy weapon.'"));
4687
4688                         dummy = INVEN_RARM;
4689                         if (buki_motteruka(INVEN_LARM))
4690                         {
4691                                 dummy = INVEN_LARM;
4692                                 if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
4693                         }
4694                         object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
4695                         (void)curse_weapon(FALSE, dummy);
4696                         reward = format(_("%sが破壊された。", "destroying %s"), o_name);
4697                         break;
4698
4699                 case REW_CURSE_AR:
4700
4701                         if (!inventory[INVEN_BODY].k_idx) break;
4702                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4703                         msg_print(_("「汝、防具に頼ることなかれ。」", "'Thou reliest too much on thine equipment.'"));
4704
4705                         object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
4706                         (void)curse_armor();
4707                         reward = format(_("%sが破壊された。", "destroying %s"), o_name);
4708                         break;
4709                 case REW_PISS_OFF:
4710
4711                         msg_format(_("%sの声がささやいた:", "The voice of %s whispers:"), chaos_patrons[p_ptr->chaos_patron]);
4712                         msg_print(_("「我を怒りしめた罪を償うべし。」", "'Now thou shalt pay for annoying me.'"));
4713
4714                         switch (randint1(4))
4715                         {
4716                                 case 1:
4717                                         (void)activate_ty_curse(FALSE, &count);
4718                                         reward = _("禍々しい呪いをかけられた。", "cursing");
4719                                         break;
4720                                 case 2:
4721                                         activate_hi_summon(p_ptr->y, p_ptr->x, FALSE);
4722                                         reward = _("モンスターを召喚された。", "summoning hostile monsters");
4723                                         break;
4724                                 case 3:
4725                                         if (one_in_(2))
4726                                         {
4727                                                 if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
4728                                                 dummy = INVEN_RARM;
4729                                                 if (buki_motteruka(INVEN_LARM))
4730                                                 {
4731                                                         dummy = INVEN_LARM;
4732                                                         if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
4733                                                 }
4734                                                 object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
4735                                                 (void)curse_weapon(FALSE, dummy);
4736                                                 reward = format(_("%sが破壊された。", "destroying %s"), o_name);
4737                                         }
4738                                         else
4739                                         {
4740                                                 if (!inventory[INVEN_BODY].k_idx) break;
4741                                                 object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
4742                                                 (void)curse_armor();
4743                                                 reward = format(_("%sが破壊された。", "destroying %s"), o_name);
4744                                         }
4745                                         break;
4746                                 default:
4747                                         for (dummy = 0; dummy < 6; dummy++)
4748                                         {
4749                                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
4750                                         }
4751                                         reward = _("全能力値が下がった。", "decreasing all stats");
4752                                         break;
4753                         }
4754                         break;
4755
4756                 case REW_WRATH:
4757
4758                         msg_format(_("%sの声が轟き渡った:", "The voice of %s thunders:"), chaos_patrons[p_ptr->chaos_patron]);
4759                         msg_print(_("「死ぬがよい、下僕よ!」", "'Die, mortal!'"));
4760
4761                         take_hit(DAMAGE_LOSELIFE, p_ptr->lev * 4, wrath_reason, -1);
4762                         for (dummy = 0; dummy < 6; dummy++)
4763                         {
4764                                 (void)dec_stat(dummy, 10 + randint1(15), FALSE);
4765                         }
4766                         activate_hi_summon(p_ptr->y, p_ptr->x, FALSE);
4767                         (void)activate_ty_curse(FALSE, &count);
4768                         if (one_in_(2))
4769                         {
4770                                 dummy = 0;
4771
4772                                 if (buki_motteruka(INVEN_RARM))
4773                                 {
4774                                         dummy = INVEN_RARM;
4775                                         if (buki_motteruka(INVEN_LARM) && one_in_(2)) dummy = INVEN_LARM;
4776                                 }
4777                                 else if (buki_motteruka(INVEN_LARM)) dummy = INVEN_LARM;
4778
4779                                 if (dummy) (void)curse_weapon(FALSE, dummy);
4780                         }
4781                         if (one_in_(2)) (void)curse_armor();
4782                         break;
4783
4784                 case REW_DESTRUCT:
4785
4786                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4787                         msg_print(_("「死と破壊こそ我が喜びなり!」", "'Death and destruction! This pleaseth me!'"));
4788
4789                         (void)destroy_area(p_ptr->y, p_ptr->x, 25, FALSE);
4790                         reward = _("ダンジョンが*破壊*された。", "*destruct*ing dungeon");
4791                         break;
4792
4793                 case REW_GENOCIDE:
4794
4795                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4796                         msg_print(_("「我、汝の敵を抹殺せん!」", "'Let me relieve thee of thine oppressors!'"));
4797                         (void)symbol_genocide(0, FALSE);
4798                         reward = _("モンスターが抹殺された。", "genociding monsters");
4799                         break;
4800
4801                 case REW_MASS_GEN:
4802
4803                         msg_format(_("%sの声が響き渡った:", "The voice of %s booms out:"), chaos_patrons[p_ptr->chaos_patron]);
4804                         msg_print(_("「我、汝の敵を抹殺せん!」", "'Let me relieve thee of thine oppressors!'"));
4805
4806                         (void)mass_genocide(0, FALSE);
4807                         reward = _("モンスターが抹殺された。", "genociding nearby monsters");
4808                         break;
4809
4810                 case REW_DISPEL_C:
4811
4812                         msg_format(_("%sの力が敵を攻撃するのを感じた!", "You can feel the power of %s assault your enemies!"), chaos_patrons[p_ptr->chaos_patron]);
4813                         (void)dispel_monsters(p_ptr->lev * 4);
4814                         break;
4815
4816                 case REW_IGNORE:
4817
4818                         msg_format(_("%sはあなたを無視した。", "%s ignores you."), chaos_patrons[p_ptr->chaos_patron]);
4819                         break;
4820
4821                 case REW_SER_DEMO:
4822
4823                         msg_format(_("%sは褒美として悪魔の使いをよこした!", "%s rewards you with a demonic servant!"),chaos_patrons[p_ptr->chaos_patron]);
4824
4825                         if (!summon_specific(-1, p_ptr->y, p_ptr->x, dun_level, SUMMON_DEMON, PM_FORCE_PET))
4826                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
4827                         else
4828                                 reward = _("悪魔がペットになった。", "a demonic servant");
4829
4830                         break;
4831
4832                 case REW_SER_MONS:
4833                         msg_format(_("%sは褒美として使いをよこした!", "%s rewards you with a servant!"),chaos_patrons[p_ptr->chaos_patron]);
4834
4835                         if (!summon_specific(-1, p_ptr->y, p_ptr->x, dun_level, 0, PM_FORCE_PET))
4836                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
4837                         else
4838                                 reward = _("モンスターがペットになった。", "a servant");
4839
4840                         break;
4841
4842                 case REW_SER_UNDE:
4843                         msg_format(_("%sは褒美としてアンデッドの使いをよこした。", "%s rewards you with an undead servant!"),chaos_patrons[p_ptr->chaos_patron]);
4844
4845                         if (!summon_specific(-1, p_ptr->y, p_ptr->x, dun_level, SUMMON_UNDEAD, PM_FORCE_PET))
4846                                 msg_print(_("何も現れなかった...", "Nobody ever turns up..."));
4847                         else
4848                                 reward = _("アンデッドがペットになった。", "an undead servant");
4849
4850                         break;
4851
4852                 default:
4853                         msg_format(_("%sの声がどもった:", "The voice of %s stammers:"),
4854
4855                                 chaos_patrons[p_ptr->chaos_patron]);
4856                         msg_format(_("「あー、あー、答えは %d/%d。質問は何?」", "'Uh... uh... the answer's %d/%d, what's the question?'"), type, effect);
4857
4858         }
4859         }
4860         if (reward)
4861         {
4862                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format(_("パトロンの報酬で%s", "The patron rewards you with %s."), reward));
4863         }
4864 }
4865
4866
4867 /*
4868  * XAngband: determine if a given location is "interesting"
4869  * based on target_set_accept function.
4870  */
4871 static bool tgt_pt_accept(POSITION y, POSITION x)
4872 {
4873         cave_type *c_ptr;
4874
4875         /* Bounds */
4876         if (!(in_bounds(y, x))) return (FALSE);
4877
4878         /* Player grid is always interesting */
4879         if ((y == p_ptr->y) && (x == p_ptr->x)) return (TRUE);
4880
4881         /* Handle hallucination */
4882         if (p_ptr->image) return (FALSE);
4883
4884         /* Examine the grid */
4885         c_ptr = &cave[y][x];
4886
4887         /* Interesting memorized features */
4888         if (c_ptr->info & (CAVE_MARK))
4889         {
4890                 /* Notice stairs */
4891                 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
4892                 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
4893
4894                 /* Notice quest features */
4895                 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
4896                 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
4897         }
4898
4899         return (FALSE);
4900 }
4901
4902
4903 /*
4904  * XAngband: Prepare the "temp" array for "tget_pt"
4905  * based on target_set_prepare funciton.
4906  */
4907 static void tgt_pt_prepare(void)
4908 {
4909         POSITION y, x;
4910
4911         /* Reset "temp" array */
4912         temp_n = 0;
4913
4914         if (!expand_list) return;
4915
4916         /* Scan the current panel */
4917         for (y = 1; y < cur_hgt; y++)
4918         {
4919                 for (x = 1; x < cur_wid; x++)
4920                 {
4921                         /* Require "interesting" contents */
4922                         if (!tgt_pt_accept(y, x)) continue;
4923
4924                         /* Save the location */
4925                         temp_x[temp_n] = x;
4926                         temp_y[temp_n] = y;
4927                         temp_n++;
4928                 }
4929         }
4930
4931         /* Target the nearest monster for shooting */
4932         ang_sort_comp = ang_sort_comp_distance;
4933         ang_sort_swap = ang_sort_swap_distance;
4934
4935         /* Sort the positions */
4936         ang_sort(temp_x, temp_y, temp_n);
4937 }
4938
4939 /*
4940  * old -- from PsiAngband.
4941  */
4942 bool tgt_pt(POSITION *x_ptr, POSITION *y_ptr)
4943 {
4944         char ch = 0;
4945         int d, n = 0;
4946         POSITION x, y;
4947         bool success = FALSE;
4948
4949         int wid, hgt;
4950
4951         get_screen_size(&wid, &hgt);
4952
4953         x = p_ptr->x;
4954         y = p_ptr->y;
4955
4956         if (expand_list) 
4957         {
4958                 tgt_pt_prepare();
4959         }
4960
4961         msg_print(_("場所を選んでスペースキーを押して下さい。", "Select a point and press space."));
4962         msg_flag = FALSE; /* prevents "-more-" message. */
4963
4964         while ((ch != ESCAPE) && !success)
4965         {
4966                 bool move_fast = FALSE;
4967
4968                 move_cursor_relative(y, x);
4969                 ch = inkey();
4970                 switch (ch)
4971                 {
4972                 case ESCAPE:
4973                         break;
4974                 case ' ':
4975                 case 't':
4976                 case '.':
4977                 case '5':
4978                 case '0':
4979                         /* illegal place */
4980                         if (player_bold(y, x)) ch = 0;
4981
4982                         /* okay place */
4983                         else success = TRUE;
4984
4985                         break;
4986
4987                 /* XAngband: Move cursor to stairs */
4988                 case '>':
4989                 case '<':
4990                         if (expand_list && temp_n)
4991                         {
4992                                 int dx, dy;
4993                                 int cx = (panel_col_min + panel_col_max) / 2;
4994                                 int cy = (panel_row_min + panel_row_max) / 2;
4995
4996                                 n++;
4997
4998                                 /* Skip stairs which have defferent distance */
4999                                 for (; n < temp_n; ++ n)
5000                                 {
5001                                         cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
5002
5003                                         if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
5004                                             cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
5005                                         {
5006                                                 /* Found */
5007                                                 break;
5008                                         }
5009                                 }
5010
5011                                 if (n == temp_n)        /* Loop out taget list */
5012                                 {
5013                                         n = 0;
5014                                         y = p_ptr->y;
5015                                         x = p_ptr->x;
5016                                         verify_panel(); /* Move cursor to player */
5017
5018                                         p_ptr->update |= (PU_MONSTERS);
5019
5020                                         p_ptr->redraw |= (PR_MAP);
5021
5022                                         p_ptr->window |= (PW_OVERHEAD);
5023                                         handle_stuff();
5024                                 }
5025                                 else    /* move cursor to next stair and change panel */
5026                                 {
5027                                         y = temp_y[n];
5028                                         x = temp_x[n];
5029
5030                                         dy = 2 * (y - cy) / hgt;
5031                                         dx = 2 * (x - cx) / wid;
5032                                         if (dy || dx) change_panel(dy, dx);
5033                                 }
5034                         }
5035                         break;
5036
5037                 default:
5038                         /* Look up the direction */
5039                         d = get_keymap_dir(ch);
5040
5041                         /* XTRA HACK MOVEFAST */
5042                         if (isupper(ch)) move_fast = TRUE;
5043
5044                         /* Handle "direction" */
5045                         if (d)
5046                         {
5047                                 int dx = ddx[d];
5048                                 int dy = ddy[d];
5049
5050                                 /* XTRA HACK MOVEFAST */
5051                                 if (move_fast)
5052                                 {
5053                                         int mag = MIN(wid / 2, hgt / 2);
5054                                         x += dx * mag;
5055                                         y += dy * mag;
5056                                 }
5057                                 else
5058                                 {
5059                                         x += dx;
5060                                         y += dy;
5061                                 }
5062
5063                                 /* Do not move horizontally if unnecessary */
5064                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
5065                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
5066                                 {
5067                                         dx = 0;
5068                                 }
5069
5070                                 /* Do not move vertically if unnecessary */
5071                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
5072                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
5073                                 {
5074                                         dy = 0;
5075                                 }
5076
5077                                 /* Apply the motion */
5078                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
5079                                          (x >= panel_col_min + wid) || (x < panel_col_min))
5080                                 {
5081                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
5082                                         change_panel(dy, dx);
5083                                 }
5084
5085                                 /* Slide into legality */
5086                                 if (x >= cur_wid-1) x = cur_wid - 2;
5087                                 else if (x <= 0) x = 1;
5088
5089                                 /* Slide into legality */
5090                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
5091                                 else if (y <= 0) y = 1;
5092
5093                         }
5094                         break;
5095                 }
5096         }
5097
5098         /* Clear the top line */
5099         prt("", 0, 0);
5100
5101         /* Recenter the map around the player */
5102         verify_panel();
5103
5104         p_ptr->update |= (PU_MONSTERS);
5105
5106         p_ptr->redraw |= (PR_MAP);
5107
5108         p_ptr->window |= (PW_OVERHEAD);
5109         handle_stuff();
5110
5111         *x_ptr = x;
5112         *y_ptr = y;
5113         return success;
5114 }
5115
5116
5117 bool get_hack_dir(DIRECTION *dp)
5118 {
5119         DIRECTION dir;
5120         cptr    p;
5121         char    command;
5122
5123         (*dp) = 0;
5124
5125         /* Global direction */
5126         dir = 0;
5127
5128         /* (No auto-targeting) */
5129
5130         /* Ask until satisfied */
5131         while (!dir)
5132         {
5133                 /* Choose a prompt */
5134                 if (!target_okay())
5135                 {
5136                         p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
5137                 }
5138                 else
5139                 {
5140                         p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
5141                 }
5142
5143                 /* Get a command (or Cancel) */
5144                 if (!get_com(p, &command, TRUE)) break;
5145
5146                 if (use_menu)
5147                 {
5148                         if (command == '\r') command = 't';
5149                 }  
5150
5151                 /* Convert various keys to "standard" keys */
5152                 switch (command)
5153                 {
5154                         /* Use current target */
5155                         case 'T':
5156                         case 't':
5157                         case '.':
5158                         case '5':
5159                         case '0':
5160                         {
5161                                 dir = 5;
5162                                 break;
5163                         }
5164
5165                         /* Set new target */
5166                         case '*':
5167                         case ' ':
5168                         case '\r':
5169                         {
5170                                 if (target_set(TARGET_KILL)) dir = 5;
5171                                 break;
5172                         }
5173
5174                         default:
5175                         {
5176                                 /* Look up the direction */
5177                                 dir = get_keymap_dir(command);
5178
5179                                 break;
5180                         }
5181                 }
5182
5183                 /* Verify requested targets */
5184                 if ((dir == 5) && !target_okay()) dir = 0;
5185
5186                 /* Error */
5187                 if (!dir) bell();
5188         }
5189
5190         /* No direction */
5191         if (!dir) return (FALSE);
5192
5193         /* Save the direction */
5194         command_dir = dir;
5195
5196         /* Check for confusion */
5197         if (p_ptr->confused)
5198         {
5199                 /* Random direction */
5200                 dir = ddd[randint0(8)];
5201         }
5202
5203         /* Notice confusion */
5204         if (command_dir != dir)
5205         {
5206                 /* Warn the user */
5207                 msg_print(_("あなたは混乱している。", "You are confused."));
5208         }
5209
5210         /* Save direction */
5211         (*dp) = dir;
5212
5213         /* A "valid" direction was entered */
5214         return (TRUE);
5215 }
5216
5217
5218 /*
5219  * エネルギーの増加量10d5を速く計算するための関数
5220  */
5221
5222 #define Go_no_JuuJou 5*5*5*5*5*5*5*5*5*5
5223
5224 s16b gain_energy(void)
5225 {
5226         int i;
5227         s32b energy_result = 10;
5228         s32b tmp;
5229
5230         tmp = randint0(Go_no_JuuJou);
5231
5232         for (i = 0; i < 9; i ++){
5233                 energy_result += tmp % 5;
5234                 tmp /= 5;
5235         }
5236
5237         return (s16b)(energy_result + tmp);
5238 }
5239
5240
5241 /*!
5242  * @brief 射撃武器の攻撃に必要な基本消費エネルギーを返す/Return bow energy
5243  * @param sval 射撃武器のアイテム副分類ID 
5244  * @return 消費する基本エネルギー
5245  */
5246 ENERGY bow_energy(OBJECT_SUBTYPE_VALUE sval)
5247 {
5248         ENERGY energy = 10000;
5249
5250         /* Analyze the launcher */
5251         switch (sval)
5252         {
5253                 /* Sling and ammo */
5254                 case SV_SLING:
5255                 {
5256                         energy = 8000;
5257                         break;
5258                 }
5259
5260                 /* Short Bow and Arrow */
5261                 case SV_SHORT_BOW:
5262                 {
5263                         energy = 10000;
5264                         break;
5265                 }
5266
5267                 /* Long Bow and Arrow */
5268                 case SV_LONG_BOW:
5269                 {
5270                         energy = 10000;
5271                         break;
5272                 }
5273
5274                 /* Bow of irresponsiblity and Arrow */
5275                 case SV_NAMAKE_BOW:
5276                 {
5277                         energy = 7777;
5278                         break;
5279                 }
5280
5281                 /* Light Crossbow and Bolt */
5282                 case SV_LIGHT_XBOW:
5283                 {
5284                         energy = 12000;
5285                         break;
5286                 }
5287
5288                 /* Heavy Crossbow and Bolt */
5289                 case SV_HEAVY_XBOW:
5290                 {
5291                         energy = 13333;
5292                         break;
5293                 }
5294         }
5295
5296         return (energy);
5297 }
5298
5299
5300 /*
5301  * Return bow tmul
5302  */
5303 int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
5304 {
5305         int tmul = 0;
5306
5307         /* Analyze the launcher */
5308         switch (sval)
5309         {
5310                 /* Sling and ammo */
5311                 case SV_SLING:
5312                 {
5313                         tmul = 2;
5314                         break;
5315                 }
5316
5317                 /* Short Bow and Arrow */
5318                 case SV_SHORT_BOW:
5319                 {
5320                         tmul = 2;
5321                         break;
5322                 }
5323
5324                 /* Long Bow and Arrow */
5325                 case SV_LONG_BOW:
5326                 {
5327                         tmul = 3;
5328                         break;
5329                 }
5330
5331                 /* Bow of irresponsiblity and Arrow */
5332                 case SV_NAMAKE_BOW:
5333                 {
5334                         tmul = 3;
5335                         break;
5336                 }
5337
5338                 /* Light Crossbow and Bolt */
5339                 case SV_LIGHT_XBOW:
5340                 {
5341                         tmul = 3;
5342                         break;
5343                 }
5344
5345                 /* Heavy Crossbow and Bolt */
5346                 case SV_HEAVY_XBOW:
5347                 {
5348                         tmul = 4;
5349                         break;
5350                 }
5351         }
5352
5353         return (tmul);
5354 }
5355
5356 /*
5357  * Return alignment title
5358  */
5359 cptr your_alignment(void)
5360 {
5361 #ifdef JP
5362         if (p_ptr->align > 150) return "大善";
5363         else if (p_ptr->align > 50) return "中善";
5364         else if (p_ptr->align > 10) return "小善";
5365         else if (p_ptr->align > -11) return "中立";
5366         else if (p_ptr->align > -51) return "小悪";
5367         else if (p_ptr->align > -151) return "中悪";
5368         else return "大悪";
5369 #else
5370         if (p_ptr->align > 150) return "Lawful";
5371         else if (p_ptr->align > 50) return "Good";
5372         else if (p_ptr->align > 10) return "Neutral Good";
5373         else if (p_ptr->align > -11) return "Neutral";
5374         else if (p_ptr->align > -51) return "Neutral Evil";
5375         else if (p_ptr->align > -151) return "Evil";
5376         else return "Chaotic";
5377 #endif
5378 }
5379
5380
5381 /*
5382  * Return proficiency level of weapons and misc. skills (except riding)
5383  */
5384 int weapon_exp_level(int weapon_exp)
5385 {
5386         if (weapon_exp < WEAPON_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5387         else if (weapon_exp < WEAPON_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5388         else if (weapon_exp < WEAPON_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5389         else if (weapon_exp < WEAPON_EXP_MASTER) return EXP_LEVEL_EXPERT;
5390         else return EXP_LEVEL_MASTER;
5391 }
5392
5393
5394 /*
5395  * Return proficiency level of riding
5396  */
5397 int riding_exp_level(int riding_exp)
5398 {
5399         if (riding_exp < RIDING_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5400         else if (riding_exp < RIDING_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5401         else if (riding_exp < RIDING_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5402         else if (riding_exp < RIDING_EXP_MASTER) return EXP_LEVEL_EXPERT;
5403         else return EXP_LEVEL_MASTER;
5404 }
5405
5406
5407 /*
5408  * Return proficiency level of spells
5409  */
5410 int spell_exp_level(int spell_exp)
5411 {
5412         if (spell_exp < SPELL_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5413         else if (spell_exp < SPELL_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5414         else if (spell_exp < SPELL_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5415         else if (spell_exp < SPELL_EXP_MASTER) return EXP_LEVEL_EXPERT;
5416         else return EXP_LEVEL_MASTER;
5417 }
5418
5419
5420 /*
5421  * Display a rumor and apply its effects
5422  */
5423
5424 IDX rumor_num(char *zz, IDX max_idx)
5425 {
5426         if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
5427         return (IDX)atoi(zz);
5428 }
5429
5430 cptr rumor_bind_name(char *base, cptr fullname)
5431 {
5432         char *s, *v;
5433
5434         s = strstr(base, "{Name}");
5435         if (s)
5436         {
5437                 s[0] = '\0';
5438                 v = format("%s%s%s", base, fullname, (s + 6));
5439         }
5440         else
5441         {
5442                 v = base;
5443         }
5444
5445         return v;
5446 }
5447
5448 void display_rumor(bool ex)
5449 {
5450         errr err;
5451         int section = 0;
5452         char Rumor[1024];
5453
5454         if (ex)
5455         {
5456                 if (randint0(3) == 0) section = 1;
5457         }
5458
5459         err = _(get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10),
5460                         get_rnd_line("rumors.txt", section, Rumor));
5461         if (err) strcpy(Rumor, _("嘘の噂もある。", "Some rumors are wrong."));
5462
5463         err = TRUE;
5464
5465         if (strncmp(Rumor, "R:", 2) == 0)
5466         {
5467                 char *zz[4];
5468                 cptr rumor_msg = NULL;
5469                 cptr rumor_eff_format = NULL;
5470                 char fullname[1024] = "";
5471
5472                 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
5473                 {
5474                         if (strcmp(zz[0], "ARTIFACT") == 0)
5475                         {
5476                                 IDX a_idx, k_idx;
5477                                 object_type forge;
5478                                 object_type *q_ptr = &forge;
5479                                 artifact_type *a_ptr;
5480
5481                                 while (1)
5482                                 {
5483                                         a_idx = rumor_num(zz[1], max_a_idx);
5484
5485                                         a_ptr = &a_info[a_idx];
5486                                         if (a_ptr->name) break;
5487                                 }
5488
5489                                 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
5490                                 object_prep(q_ptr, k_idx);
5491                                 q_ptr->name1 = a_idx;
5492                                 q_ptr->ident = IDENT_STORE;
5493                                 object_desc(fullname, q_ptr, OD_NAME_ONLY);
5494                         }
5495                         else if  (strcmp(zz[0], "MONSTER") == 0)
5496                         {
5497                                 MONRACE_IDX r_idx;
5498                                 monster_race *r_ptr;
5499
5500                                 while(1)
5501                                 {
5502                                         r_idx = rumor_num(zz[1], max_r_idx);
5503                                         r_ptr = &r_info[r_idx];
5504                                         if (r_ptr->name) break;
5505                                 }
5506
5507                                 strcpy(fullname, r_name + r_ptr->name);
5508
5509                                 /* Remember this monster */
5510                                 if (!r_ptr->r_sights)
5511                                 {
5512                                         r_ptr->r_sights++;
5513                                 }
5514                         }
5515                         else if (strcmp(zz[0], "DUNGEON") == 0)
5516                         {
5517                                 DUNGEON_IDX d_idx;
5518                                 dungeon_info_type *d_ptr;
5519
5520                                 while (1)
5521                                 {
5522                                         d_idx = rumor_num(zz[1], max_d_idx);
5523                                         d_ptr = &d_info[d_idx];
5524                                         if (d_ptr->name) break;
5525                                 }
5526
5527                                 strcpy(fullname, d_name + d_ptr->name);
5528
5529                                 if (!max_dlv[d_idx])
5530                                 {
5531                                         max_dlv[d_idx] = d_ptr->mindepth;
5532                                         rumor_eff_format = _("%sに帰還できるようになった。", "You can recall to %s.");
5533                                 }
5534                         }
5535                         else if  (strcmp(zz[0], "TOWN") == 0)
5536                         {
5537                                 IDX t_idx;
5538                                 s32b visit;
5539
5540                                 while(1)
5541                                 {
5542                                         t_idx = rumor_num(zz[1], NO_TOWN);
5543                                         if (town[t_idx].name) break;
5544                                 }
5545
5546                                 strcpy(fullname, town[t_idx].name);
5547
5548                                 visit = (1L << (t_idx - 1));
5549                                 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
5550                                 {
5551                                         p_ptr->visit |= visit;
5552                                         rumor_eff_format = _("%sに行ったことがある気がする。", "You feel you have been to %s.");
5553                                 }
5554                         }
5555
5556                         rumor_msg = rumor_bind_name(zz[2], fullname);
5557                         msg_print(rumor_msg);
5558                         if (rumor_eff_format)
5559                         {
5560                                 msg_print(NULL);
5561                                 msg_format(rumor_eff_format, fullname);
5562                         }
5563                         err = FALSE;
5564                 }
5565         /* error */
5566         if (err) msg_print(_("この情報は間違っている。", "This information is wrong."));
5567         }
5568                         else
5569         {
5570                 msg_format("%s", Rumor);
5571         }
5572 }