OSDN Git Service

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