OSDN Git Service

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