OSDN Git Service

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