OSDN Git Service

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