OSDN Git Service

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