OSDN Git Service

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