OSDN Git Service

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