OSDN Git Service

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