OSDN Git Service

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