OSDN Git Service

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