OSDN Git Service

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