OSDN Git Service

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