OSDN Git Service

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