OSDN Git Service

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