OSDN Git Service

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