OSDN Git Service

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