OSDN Git Service

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