OSDN Git Service

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