OSDN Git Service

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