OSDN Git Service

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