OSDN Git Service

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