OSDN Git Service

8b4119e2c2e4f2bf0123a0972cb9b14977871ef4
[hengbandforosx/hengbandosx.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
32         /* Hack -- lower limit */
33         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
34
35         /* Hack -- upper limit */
36         if (p_ptr->exp > PY_MAX_EXP) p_ptr->exp = PY_MAX_EXP;
37
38         /* Hack -- upper limit */
39         if (p_ptr->max_exp > PY_MAX_EXP) p_ptr->max_exp = PY_MAX_EXP;
40
41         /* Hack -- maintain "max" experience */
42         if (p_ptr->exp > p_ptr->max_exp) p_ptr->max_exp = p_ptr->exp;
43
44         /* Redraw experience */
45         p_ptr->redraw |= (PR_EXP);
46
47         /* Handle stuff */
48         handle_stuff();
49
50
51         /* Lose levels while possible */
52         while ((p_ptr->lev > 1) &&
53                (p_ptr->exp < ((android ? player_exp_a : player_exp)[p_ptr->lev - 2] * p_ptr->expfact / 100L)))
54         {
55                 /* Lose a level */
56                 p_ptr->lev--;
57
58                 /* Update some stuff */
59                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
60
61                 /* Redraw some stuff */
62                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
63
64                 /* Window stuff */
65                 p_ptr->window |= (PW_PLAYER);
66
67                 /* Handle stuff */
68                 handle_stuff();
69         }
70
71
72         /* Gain levels while possible */
73         while ((p_ptr->lev < PY_MAX_LEVEL) &&
74                (p_ptr->exp >= ((android ? player_exp_a : player_exp)[p_ptr->lev-1] * p_ptr->expfact / 100L)))
75         {
76                 /* Gain a level */
77                 p_ptr->lev++;
78
79                 /* Save the highest level */
80                 if (p_ptr->lev > p_ptr->max_plv)
81                 {
82                         p_ptr->max_plv = p_ptr->lev;
83
84                         if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
85                             (p_ptr->muta2 & MUT2_CHAOS_GIFT))
86                         {
87                                 level_reward = TRUE;
88                         }
89                         if (p_ptr->prace == RACE_BEASTMAN)
90                         {
91                                 if (one_in_(5)) level_mutation = TRUE;
92                         }
93                         level_inc_stat = TRUE;
94
95                         do_cmd_write_nikki(NIKKI_LEVELUP, p_ptr->lev, NULL);
96                 }
97
98                 /* Sound */
99                 sound(SOUND_LEVEL);
100
101                 /* Message */
102 #ifdef JP
103 msg_format("¥ì¥Ù¥ë %d ¤Ë¤è¤¦¤³¤½¡£", p_ptr->lev);
104 #else
105                 msg_format("Welcome to level %d.", p_ptr->lev);
106 #endif
107
108                 /* Update some stuff */
109                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
110
111                 /* Redraw some stuff */
112                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
113
114                 /* Window stuff */
115                 p_ptr->window |= (PW_PLAYER | PW_SPELL);
116
117                 /* HP¤ÈMP¤Î¾å¾ºÎ̤òɽ¼¨ */
118                 level_up = 1;
119
120                 /* Handle stuff */
121                 handle_stuff();
122
123                 level_up = 0;
124
125                 if (level_inc_stat)
126                 {
127                         if(!(p_ptr->max_plv % 10))
128                         {
129                                 int choice;
130                                 screen_save();
131                                 while(1)
132                                 {
133                                         int n;
134                                         char tmp[32];
135
136 #ifdef JP
137                                         cnv_stat(p_ptr->stat_max[0], tmp);
138                                         prt(format("        a) ÏÓÎÏ (¸½ºßÃÍ %s)", tmp), 2, 14);
139                                         cnv_stat(p_ptr->stat_max[1], tmp);
140                                         prt(format("        b) ÃÎǽ (¸½ºßÃÍ %s)", tmp), 3, 14);
141                                         cnv_stat(p_ptr->stat_max[2], tmp);
142                                         prt(format("        c) ¸­¤µ (¸½ºßÃÍ %s)", tmp), 4, 14);
143                                         cnv_stat(p_ptr->stat_max[3], tmp);
144                                         prt(format("        d) ´ïÍÑ (¸½ºßÃÍ %s)", tmp), 5, 14);
145                                         cnv_stat(p_ptr->stat_max[4], tmp);
146                                         prt(format("        e) Âѵנ(¸½ºßÃÍ %s)", tmp), 6, 14);
147                                         cnv_stat(p_ptr->stat_max[5], tmp);
148                                         prt(format("        f) Ì¥ÎÏ (¸½ºßÃÍ %s)", tmp), 7, 14);
149                                         prt("", 8, 14);
150                                         prt("        ¤É¤ÎǽÎÏÃͤò¾å¤²¤Þ¤¹¤«¡©", 1, 14);
151 #else
152                                         cnv_stat(p_ptr->stat_max[0], tmp);
153                                         prt(format("        a) Str (cur %s)", tmp), 2, 14);
154                                         cnv_stat(p_ptr->stat_max[1], tmp);
155                                         prt(format("        b) Int (cur %s)", tmp), 3, 14);
156                                         cnv_stat(p_ptr->stat_max[2], tmp);
157                                         prt(format("        c) Wis (cur %s)", tmp), 4, 14);
158                                         cnv_stat(p_ptr->stat_max[3], tmp);
159                                         prt(format("        d) Dex (cur %s)", tmp), 5, 14);
160                                         cnv_stat(p_ptr->stat_max[4], tmp);
161                                         prt(format("        e) Con (cur %s)", tmp), 6, 14);
162                                         cnv_stat(p_ptr->stat_max[5], tmp);
163                                         prt(format("        f) Chr (cur %s)", tmp), 7, 14);
164                                         prt("", 8, 14);
165                                         prt("        Which stat do you want to raise?", 1, 14);
166 #endif
167                                         while(1)
168                                         {
169                                                 choice = inkey();
170                                                 if ((choice >= 'a') && (choice <= 'f')) break;
171                                         }
172                                         for(n = 0; n < 6; n++)
173                                                 if (n != choice - 'a')
174                                                         prt("",n+2,14);
175 #ifdef JP
176                                         if (get_check("¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) break;
177 #else
178                                         if (get_check("Are you sure? ")) break;
179 #endif
180                                 }
181                                 do_inc_stat(choice - 'a');
182                                 screen_load();
183                         }
184                         else if(!(p_ptr->max_plv % 2))
185                                 do_inc_stat(randint0(6));
186                 }
187
188                 if (level_mutation)
189                 {
190 #ifdef JP
191 msg_print("¤¢¤Ê¤¿¤ÏÊѤï¤Ã¤¿µ¤¤¬¤¹¤ë...");
192 #else
193                         msg_print("You feel different...");
194 #endif
195
196                         (void)gain_random_mutation(0);
197                         level_mutation = FALSE;
198                 }
199
200                 /*
201                  * Ê󽷤ǥì¥Ù¥ë¤¬¾å¤ë¤ÈºÆµ¢Åª¤Ë check_experience() ¤¬
202                  * ¸Æ¤Ð¤ì¤ë¤Î¤Ç½çÈÖ¤òºÇ¸å¤Ë¤¹¤ë¡£
203                  */
204                 if (level_reward)
205                 {
206                         gain_level_reward(0);
207                         level_reward = FALSE;
208                 }
209
210                 /* Update some stuff */
211                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
212
213                 /* Redraw some stuff */
214                 p_ptr->redraw |= (PR_LEV | PR_TITLE);
215
216                 /* Window stuff */
217                 p_ptr->window |= (PW_PLAYER | PW_SPELL);
218
219                 /* Handle stuff */
220                 handle_stuff();
221         }
222 }
223
224
225 /*
226  * Hack -- Return the "automatic coin type" of a monster race
227  * Used to allocate proper treasure when "Creeping coins" die
228  *
229  * XXX XXX XXX Note the use of actual "monster names"
230  */
231 static int get_coin_type(int r_idx)
232 {
233         monster_race    *r_ptr = &r_info[r_idx];
234
235         /* Analyze "coin" monsters */
236         if (r_ptr->d_char == '$')
237         {
238                 /* Look for textual clues */
239                 switch (r_idx)
240                 {
241                 case MON_COPPER_COINS: return (2);
242                 case MON_SILVER_COINS: return (5);
243                 case MON_GOLD_COINS: return (10);
244                 case MON_MITHRIL_COINS: return (16);
245                 case MON_ADAMANT_COINS: return (17);
246                 }
247         }
248
249         /* Assume nothing */
250         return (0);
251 }
252
253
254 /*
255  * Hack -- determine if a template is Cloak
256  */
257 static bool kind_is_cloak(int k_idx)
258 {
259         object_kind *k_ptr = &k_info[k_idx];
260
261         /* Analyze the item type */
262         if (k_ptr->tval == TV_CLOAK)
263         {
264                 return (TRUE);
265         }
266
267         /* Assume not good */
268         return (FALSE);
269 }
270
271
272 /*
273  * Hack -- determine if a template is Polearm
274  */
275 static bool kind_is_polearm(int k_idx)
276 {
277         object_kind *k_ptr = &k_info[k_idx];
278
279         /* Analyze the item type */
280         if (k_ptr->tval == TV_POLEARM)
281         {
282                 return (TRUE);
283         }
284
285         /* Assume not good */
286         return (FALSE);
287 }
288
289
290 /*
291  * Hack -- determine if a template is Sword
292  */
293 static bool kind_is_sword(int k_idx)
294 {
295         object_kind *k_ptr = &k_info[k_idx];
296
297         /* Analyze the item type */
298         if ((k_ptr->tval == TV_SWORD) && (k_ptr->sval > 2))
299         {
300                 return (TRUE);
301         }
302
303         /* Assume not good */
304         return (FALSE);
305 }
306
307
308 /*
309  * Hack -- determine if a template is Book
310  */
311 static bool kind_is_book(int k_idx)
312 {
313         object_kind *k_ptr = &k_info[k_idx];
314
315         /* Analyze the item type */
316         if ((k_ptr->tval >= TV_LIFE_BOOK) && (k_ptr->tval <= TV_CRUSADE_BOOK))
317         {
318                 return (TRUE);
319         }
320
321         /* Assume not good */
322         return (FALSE);
323 }
324
325
326 /*
327  * Hack -- determine if a template is Good book
328  */
329 static bool kind_is_good_book(int k_idx)
330 {
331         object_kind *k_ptr = &k_info[k_idx];
332
333         /* Analyze the item type */
334         if ((k_ptr->tval >= TV_LIFE_BOOK) && (k_ptr->tval <= TV_CRUSADE_BOOK) && (k_ptr->tval != TV_ARCANE_BOOK) && (k_ptr->sval > 1))
335         {
336                 return (TRUE);
337         }
338
339         /* Assume not good */
340         return (FALSE);
341 }
342
343
344 /*
345  * Hack -- determine if a template is Armor
346  */
347 static bool kind_is_armor(int k_idx)
348 {
349         object_kind *k_ptr = &k_info[k_idx];
350
351         /* Analyze the item type */
352         if (k_ptr->tval == TV_HARD_ARMOR)
353         {
354                 return (TRUE);
355         }
356
357         /* Assume not good */
358         return (FALSE);
359 }
360
361
362 /*
363  * Check for "Quest" completion when a quest monster is killed or charmed.
364  */
365 void check_quest_completion(monster_type *m_ptr)
366 {
367         int i, j, y, x, ny, nx, i2, j2;
368
369         int quest_num;
370
371         bool create_stairs = FALSE;
372         bool reward = FALSE;
373
374         object_type forge;
375         object_type *q_ptr;
376
377         /* Get the location */
378         y = m_ptr->fy;
379         x = m_ptr->fx;
380
381         /* Inside a quest */
382         quest_num = p_ptr->inside_quest;
383
384         /* Search for an active quest on this dungeon level */
385         if (!quest_num)
386         {
387                 for (i = max_quests - 1; i > 0; i--)
388                 {
389                         /* Quest is not active */
390                         if (quest[i].status != QUEST_STATUS_TAKEN)
391                                 continue;
392
393                         /* Quest is not a dungeon quest */
394                         if (quest[i].flags & QUEST_FLAG_PRESET)
395                                 continue;
396
397                         /* Quest is not on this level */
398                         if ((quest[i].level != dun_level) &&
399                             (quest[i].type != QUEST_TYPE_KILL_ANY_LEVEL))
400                                 continue;
401
402                         /* Not a "kill monster" quest */
403                         if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) ||
404                             (quest[i].type == QUEST_TYPE_FIND_EXIT))
405                                 continue;
406
407                         /* Interesting quest */
408                         if ((quest[i].type == QUEST_TYPE_KILL_NUMBER) ||
409                             (quest[i].type == QUEST_TYPE_KILL_ALL))
410                                 break;
411
412                         /* Interesting quest */
413                         if (((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
414                              (quest[i].type == QUEST_TYPE_KILL_ANY_LEVEL) ||
415                              (quest[i].type == QUEST_TYPE_RANDOM)) &&
416                              (quest[i].r_idx == m_ptr->r_idx))
417                                 break;
418                 }
419
420                 quest_num = i;
421         }
422
423         /* Handle the current quest */
424         if (quest_num && (quest[quest_num].status == QUEST_STATUS_TAKEN))
425         {
426                 /* Current quest */
427                 i = quest_num;
428
429                 switch (quest[i].type)
430                 {
431                         case QUEST_TYPE_KILL_NUMBER:
432                         {
433                                 quest[i].cur_num++;
434
435                                 if (quest[i].cur_num >= quest[i].num_mon)
436                                 {
437                                         if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
438                                         /* completed quest */
439                                         quest[i].status = QUEST_STATUS_COMPLETED;
440                                         quest[i].complev = (byte)p_ptr->lev;
441
442                                         if (!(quest[i].flags & QUEST_FLAG_SILENT))
443                                         {
444 #ifdef JP
445 msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
446 #else
447                                                 msg_print("You just completed your quest!");
448 #endif
449
450                                                 msg_print(NULL);
451                                         }
452
453                                         quest[i].cur_num = 0;
454                                 }
455                                 break;
456                         }
457                         case QUEST_TYPE_KILL_ALL:
458                         {
459                                 int number_mon = 0;
460
461                                 if (!is_hostile(m_ptr)) break;
462
463                                 /* Count all hostile monsters */
464                                 for (i2 = 0; i2 < cur_wid; ++i2)
465                                         for (j2 = 0; j2 < cur_hgt; j2++)
466                                                 if (cave[j2][i2].m_idx > 0)
467                                                         if (is_hostile(&m_list[cave[j2][i2].m_idx])) 
468                                                                 number_mon++;
469
470                                 if ((number_mon - 1) == 0)
471                                 {
472                                         if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
473                                         /* completed */
474                                         if (quest[i].flags & QUEST_FLAG_SILENT)
475                                         {
476                                                 quest[i].status = QUEST_STATUS_FINISHED;
477                                         }
478                                         else
479                                         {
480                                                 quest[i].status = QUEST_STATUS_COMPLETED;
481                                                 quest[i].complev = (byte)p_ptr->lev;
482 #ifdef JP
483 msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
484 #else
485                                                 msg_print("You just completed your quest!");
486 #endif
487
488                                                 msg_print(NULL);
489                                         }
490                                 }
491                                 break;
492                         }
493                         case QUEST_TYPE_KILL_LEVEL:
494                         case QUEST_TYPE_RANDOM:
495                         {
496                                 /* Only count valid monsters */
497                                 if (quest[i].r_idx != m_ptr->r_idx)
498                                         break;
499
500                                 quest[i].cur_num++;
501
502                                 if (quest[i].cur_num >= quest[i].max_num)
503                                 {
504                                         if (record_fix_quest && (quest[i].type == QUEST_TYPE_KILL_LEVEL)) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
505                                         if (record_rand_quest && (quest[i].type == QUEST_TYPE_RANDOM)) do_cmd_write_nikki(NIKKI_RAND_QUEST_C, i, NULL);
506                                         /* completed quest */
507                                         quest[i].status = QUEST_STATUS_COMPLETED;
508                                         quest[i].complev = (byte)p_ptr->lev;
509                                         if (!(quest[i].flags & QUEST_FLAG_PRESET))
510                                         {
511                                                 create_stairs = TRUE;
512                                                 p_ptr->inside_quest = 0;
513                                         }
514
515                                         if (!(quest[i].flags & QUEST_FLAG_SILENT))
516                                         {
517 #ifdef JP
518 msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
519 #else
520                                                 msg_print("You just completed your quest!");
521 #endif
522
523                                                 msg_print(NULL);
524                                         }
525
526                                         /* Finish the two main quests without rewarding */
527                                         if ((i == QUEST_OBERON) || (i == QUEST_SERPENT))
528                                         {
529                                                 quest[i].status = QUEST_STATUS_FINISHED;
530                                         }
531
532                                         if (quest[i].type == QUEST_TYPE_RANDOM)
533                                         {
534                                                 reward = TRUE;
535                                                 quest[i].status = QUEST_STATUS_FINISHED;
536                                         }
537                                 }
538                                 break;
539                         }
540                         case QUEST_TYPE_KILL_ANY_LEVEL:
541                         {
542                                 quest[i].cur_num++;
543                                 if (quest[i].cur_num >= quest[i].max_num)
544                                 {
545                                         if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
546                                          /* completed quest */
547                                         quest[i].status = QUEST_STATUS_COMPLETED;
548                                         quest[i].complev = (byte)p_ptr->lev;
549
550                                         if (!(quest[i].flags & QUEST_FLAG_SILENT))
551                                         {
552 #ifdef JP
553 msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
554 #else
555                                                 msg_print("You just completed your quest!");
556 #endif
557
558                                                 msg_print(NULL);
559                                         }
560                                         quest[i].cur_num = 0;
561                                 }
562                                 break;
563                         }
564                 }
565         }
566
567         /* Create a magical staircase */
568         if (create_stairs)
569         {
570                 /* Stagger around */
571                 while (cave_perma_bold(y, x) || cave[y][x].o_idx || (cave[y][x].info & CAVE_OBJECT) )
572                 {
573                         /* Pick a location */
574                         scatter(&ny, &nx, y, x, 1, 0);
575
576                         /* Stagger */
577                         y = ny; x = nx;
578                 }
579
580                 /* Explain the staircase */
581 #ifdef JP
582 msg_print("ËâË¡¤Î³¬Ãʤ¬¸½¤ì¤¿...");
583 #else
584                 msg_print("A magical staircase appears...");
585 #endif
586
587
588                 /* Create stairs down */
589                 cave_set_feat(y, x, FEAT_MORE);
590
591                 /* Remember to update everything */
592                 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
593         }
594
595         /*
596          * Drop quest reward
597          */
598         if (reward)
599         {
600                 for (j = 0; j < (dun_level / 15)+1; j++)
601                 {
602                         /* Get local object */
603                         q_ptr = &forge;
604
605                         /* Wipe the object */
606                         object_wipe(q_ptr);
607
608                         /* Make a great object */
609                         make_object(q_ptr, AM_GOOD | AM_GREAT);
610
611                         /* Drop it in the dungeon */
612                         (void)drop_near(q_ptr, -1, y, x);
613                 }
614         }
615 }
616
617
618 /*
619  * Return monster death string
620  */
621 cptr extract_note_dies(monster_race *r_ptr)
622 {
623         /* Some monsters get "destroyed" */
624         if (!monster_living(r_ptr))
625         {
626                 int i;
627
628                 for (i = 0; i < 4; i++)
629                 {
630                         if (r_ptr->blow[i].method == RBM_EXPLODE)
631                         {
632 #ifdef JP
633                                 return "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£";
634 #else
635                                 return " explodes into tiny shreds.";
636 #endif
637                         }
638                 }
639
640 #ifdef JP
641                 return "¤òÅݤ·¤¿¡£";
642 #else
643                 return " is destroyed.";
644 #endif
645         }
646
647         /* Assume a default death */
648 #ifdef JP
649         return "¤Ï»à¤ó¤À¡£";
650 #else
651         return " dies.";
652 #endif
653 }
654
655
656 /*
657  * Handle the "death" of a monster.
658  *
659  * Disperse treasures centered at the monster location based on the
660  * various flags contained in the monster flags fields.
661  *
662  * Check for "Quest" completion when a quest monster is killed.
663  *
664  * Note that only the player can induce "monster_death()" on Uniques.
665  * Thus (for now) all Quest monsters should be Uniques.
666  *
667  * Note that monsters can now carry objects, and when a monster dies,
668  * it drops all of its objects, which may disappear in crowded rooms.
669  */
670 void monster_death(int m_idx, bool drop_item)
671 {
672         int i, j, y, x;
673
674         int dump_item = 0;
675         int dump_gold = 0;
676
677         int number = 0;
678
679         monster_type *m_ptr = &m_list[m_idx];
680
681         monster_race *r_ptr = &r_info[m_ptr->r_idx];
682
683         bool visible = (m_ptr->ml || (r_ptr->flags1 & RF1_UNIQUE));
684
685         u32b mo_mode = 0L;
686
687         bool do_gold = (!(r_ptr->flags1 & RF1_ONLY_ITEM));
688         bool do_item = (!(r_ptr->flags1 & RF1_ONLY_GOLD));
689         bool cloned = FALSE;
690         int force_coin = get_coin_type(m_ptr->r_idx);
691
692         object_type forge;
693         object_type *q_ptr;
694
695         bool drop_chosen_item = drop_item && !cloned && !p_ptr->inside_arena
696                 && !p_ptr->inside_battle && !is_pet(m_ptr);
697
698
699         if (world_monster) world_monster = FALSE;
700
701         /* Notice changes in view */
702         if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
703         {
704                 /* Update some things */
705                 p_ptr->update |= (PU_MON_LITE);
706         }
707
708         /* Get the location */
709         y = m_ptr->fy;
710         x = m_ptr->fx;
711
712         if (m_ptr->smart & SM_CLONED)
713                 cloned = TRUE;
714
715         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
716         {
717                 char m_name[80];
718
719                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
720                 do_cmd_write_nikki(NIKKI_NAMED_PET, 3, m_name);
721         }
722
723         /* Let monsters explode! */
724         for (i = 0; i < 4; i++)
725         {
726                 if (r_ptr->blow[i].method == RBM_EXPLODE)
727                 {
728                         int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
729                         int typ = mbe_info[r_ptr->blow[i].effect].explode_type;
730                         int d_dice = r_ptr->blow[i].d_dice;
731                         int d_side = r_ptr->blow[i].d_side;
732                         int damage = damroll(d_dice, d_side);
733
734                         project(m_idx, 3, y, x, damage, typ, flg, -1);
735                         break;
736                 }
737         }
738
739         if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
740         {
741                 choose_new_monster(m_idx, TRUE, MON_CHAMELEON);
742                 r_ptr = &r_info[m_ptr->r_idx];
743         }
744
745         /* Check for quest completion */
746         check_quest_completion(m_ptr);
747
748         /* Handle the possibility of player vanquishing arena combatant -KMW- */
749         if (p_ptr->inside_arena && !is_pet(m_ptr))
750         {
751                 p_ptr->exit_bldg = TRUE;
752
753                 if (p_ptr->arena_number > MAX_ARENA_MONS)
754                 {
755 #ifdef JP
756 msg_print("ÁÇÀ²¤é¤·¤¤¡ª·¯¤³¤½¿¿¤Î¾¡Íø¼Ô¤À¡£");
757 #else
758                         msg_print("You are a Genuine Champion!");
759 #endif
760                 }
761                 else
762                 {
763 #ifdef JP
764 msg_print("¾¡Íø¡ª¥Á¥ã¥ó¥Ô¥ª¥ó¤Ø¤ÎÆ»¤ò¿Ê¤ó¤Ç¤¤¤ë¡£");
765 #else
766                         msg_print("Victorious! You're on your way to becoming Champion.");
767 #endif
768                 }
769
770                 if (arena_info[p_ptr->arena_number].tval)
771                 {
772                         /* Get local object */
773                         q_ptr = &forge;
774
775                         /* Prepare to make a prize */
776                         object_prep(q_ptr, lookup_kind(arena_info[p_ptr->arena_number].tval, arena_info[p_ptr->arena_number].sval));
777
778                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
779
780                         /* Drop it in the dungeon */
781                         (void)drop_near(q_ptr, -1, y, x);
782                 }
783
784                 if (p_ptr->arena_number > MAX_ARENA_MONS) p_ptr->arena_number++;
785                 p_ptr->arena_number++;
786                 if (record_arena)
787                 {
788                         char m_name[80];
789                         
790                         /* Extract monster name */
791                         monster_desc(m_name, m_ptr, MD_IGNORE_HALLU | MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
792                         
793                         do_cmd_write_nikki(NIKKI_ARENA, p_ptr->arena_number, m_name);
794                 }
795         }
796
797         if (m_idx == p_ptr->riding)
798         {
799                 if (rakuba(-1, FALSE))
800                 {
801 #ifdef JP
802 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
803 #else
804                         msg_print("You have fallen from your riding pet.");
805 #endif
806                 }
807         }
808
809         /* Drop a dead corpse? */
810         if (one_in_(r_ptr->flags1 & RF1_UNIQUE ? 1 : 4) &&
811             ((r_ptr->flags9 & RF9_DROP_CORPSE) ||
812              (r_ptr->flags9 & RF9_DROP_SKELETON)) &&
813             !(p_ptr->inside_arena || p_ptr->inside_battle || (m_ptr->smart & SM_CLONED) || ((m_ptr->r_idx == today_mon) && is_pet(m_ptr))))
814         {
815                 /* Assume skeleton */
816                 bool corpse = FALSE;
817
818                 /*
819                  * We cannot drop a skeleton? Note, if we are in this check,
820                  * we *know* we can drop at least a corpse or a skeleton
821                  */
822                 if (!(r_ptr->flags9 & RF9_DROP_SKELETON))
823                         corpse = TRUE;
824                 else if ((r_ptr->flags9 & RF9_DROP_CORPSE) && (r_ptr->flags1 && RF1_UNIQUE))
825                         corpse = TRUE;
826
827                 /* Else, a corpse is more likely unless we did a "lot" of damage */
828                 else if (r_ptr->flags9 & RF9_DROP_CORPSE)
829                 {
830                         /* Lots of damage in one blow */
831                         if ((0 - ((m_ptr->maxhp) / 4)) > m_ptr->hp)
832                         {
833                                 if (one_in_(5)) corpse = TRUE;
834                         }
835                         else
836                         {
837                                 if (!one_in_(5)) corpse = TRUE;
838                         }
839                 }
840
841                 /* Get local object */
842                 q_ptr = &forge;
843
844                 /* Prepare to make an object */
845                 object_prep(q_ptr, lookup_kind(TV_CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
846
847                 apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
848
849                 q_ptr->pval = m_ptr->r_idx;
850
851                 /* Drop it in the dungeon */
852                 (void)drop_near(q_ptr, -1, y, x);
853         }
854
855         /* Drop objects being carried */
856         monster_drop_carried_objects(m_ptr);
857
858         if (r_ptr->flags1 & RF1_DROP_GOOD) mo_mode |= AM_GOOD;
859         if (r_ptr->flags1 & RF1_DROP_GREAT) mo_mode |= AM_GREAT;
860
861         switch (m_ptr->r_idx)
862         {
863         case MON_PINK_HORROR:
864                 /* Pink horrors are replaced with 2 Blue horrors */
865                 if (!(p_ptr->inside_arena || p_ptr->inside_battle))
866                 {
867                         bool notice = FALSE;
868
869                         for (i = 0; i < 2; i++)
870                         {
871                                 int wy = y, wx = x;
872                                 bool pet = is_pet(m_ptr);
873                                 u32b mode = 0L;
874
875                                 if (pet) mode |= PM_FORCE_PET;
876
877                                 if (summon_specific((pet ? -1 : m_idx), wy, wx, 100, SUMMON_BLUE_HORROR, mode))
878                                 {
879                                         if (player_can_see_bold(wy, wx))
880                                                 notice = TRUE;
881                                 }
882                         }
883
884                         if (notice)
885 #ifdef JP
886                                 msg_print("¥Ô¥ó¥¯¡¦¥Û¥é¡¼¤ÏʬÎö¤·¤¿¡ª");
887 #else
888                                 msg_print("The Pink horror divides!");
889 #endif
890                 }
891                 break;
892
893         case MON_BLOODLETTER:
894                 /* Bloodletters of Khorne may drop a blade of chaos */
895                 if (drop_chosen_item && (randint1(100) < 15))
896                 {
897                         /* Get local object */
898                         q_ptr = &forge;
899
900                         /* Prepare to make a Blade of Chaos */
901                         object_prep(q_ptr, lookup_kind(TV_SWORD, SV_BLADE_OF_CHAOS));
902
903                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART | mo_mode);
904
905                         /* Drop it in the dungeon */
906                         (void)drop_near(q_ptr, -1, y, x);
907                 }
908                 break;
909
910         case MON_RAAL:
911                 if (drop_chosen_item && (dun_level > 9))
912                 {
913                         /* Get local object */
914                         q_ptr = &forge;
915
916                         /* Wipe the object */
917                         object_wipe(q_ptr);
918
919                         /* Activate restriction */
920                         if ((dun_level > 49) && one_in_(5))
921                                 get_obj_num_hook = kind_is_good_book;
922                         else
923                                 get_obj_num_hook = kind_is_book;
924
925                         /* Prepare allocation table */
926                         get_obj_num_prep();
927
928                         /* Make a book */
929                         make_object(q_ptr, mo_mode);
930
931                         /* Drop it in the dungeon */
932                         (void)drop_near(q_ptr, -1, y, x);
933                 }
934                 break;
935
936         case MON_DAWN:
937                 /*
938                  * Mega^3-hack: killing a 'Warrior of the Dawn' is likely to
939                  * spawn another in the fallen one's place!
940                  */
941                 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
942                 {
943                         if (!one_in_(7))
944                         {
945                                 int wy = py, wx = px;
946                                 int attempts = 100;
947                                 bool pet = is_pet(m_ptr);
948
949                                 do
950                                 {
951                                         scatter(&wy, &wx, py, px, 20, 0);
952                                 }
953                                 while (!(in_bounds(wy, wx) && cave_floor_bold(wy, wx)) && --attempts);
954
955                                 if (attempts > 0)
956                                 {
957                                         u32b mode = 0L;
958                                         if (pet) mode |= PM_FORCE_PET;
959
960                                         if (summon_specific((pet ? -1 : m_idx), wy, wx, 100, SUMMON_DAWN, mode))
961                                         {
962                                                 if (player_can_see_bold(wy, wx))
963 #ifdef JP
964                                                         msg_print("¿·¤¿¤ÊÀï»Î¤¬¸½¤ì¤¿¡ª");
965 #else
966                                                         msg_print("A new warrior steps forth!");
967 #endif
968
969                                         }
970                                 }
971                         }
972                 }
973                 break;
974
975         case MON_UNMAKER:
976                 /* One more ultra-hack: An Unmaker goes out with a big bang! */
977                 {
978                         int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
979                         (void)project(m_idx, 6, y, x, 100, GF_CHAOS, flg, -1);
980                 }
981                 break;
982
983         case MON_UNICORN_ORD:
984         case MON_MORGOTH:
985         case MON_ONE_RING:
986                 /* Reward for "lazy" player */
987                 if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
988                 {
989                         int a_idx = 0;
990
991                         if (!drop_chosen_item) break;
992
993                         do
994                         {
995                                 switch (randint0(3))
996                                 {
997                                 case 0:
998                                         a_idx = ART_NAMAKE_HAMMER;
999                                         break;
1000                                 case 1:
1001                                         a_idx = ART_NAMAKE_BOW;
1002                                         break;
1003                                 case 2:
1004                                         a_idx = ART_NAMAKE_ARMOR;
1005                                         break;
1006                                 }
1007                         }
1008                         while (a_info[a_idx].cur_num);
1009
1010                         if (a_info[a_idx].cur_num == 0)
1011                         {
1012                                 /* Create the artifact */
1013                                 create_named_art(a_idx, y, x);
1014                                 a_info[a_idx].cur_num = 1;
1015                         }
1016                 }
1017                 break;
1018
1019         case MON_SERPENT:
1020                 if (!drop_chosen_item) break;
1021
1022                 /* Get local object */
1023                 q_ptr = &forge;
1024
1025                 /* Mega-Hack -- Prepare to make "Grond" */
1026                 object_prep(q_ptr, lookup_kind(TV_HAFTED, SV_GROND));
1027
1028                 /* Mega-Hack -- Mark this item as "Grond" */
1029                 q_ptr->name1 = ART_GROND;
1030
1031                 /* Mega-Hack -- Actually create "Grond" */
1032                 apply_magic(q_ptr, -1, AM_GOOD | AM_GREAT);
1033
1034                 /* Drop it in the dungeon */
1035                 (void)drop_near(q_ptr, -1, y, x);
1036
1037                 /* Get local object */
1038                 q_ptr = &forge;
1039
1040                 /* Mega-Hack -- Prepare to make "Chaos" */
1041                 object_prep(q_ptr, lookup_kind(TV_CROWN, SV_CHAOS));
1042
1043                 /* Mega-Hack -- Mark this item as "Chaos" */
1044                 q_ptr->name1 = ART_CHAOS;
1045
1046                 /* Mega-Hack -- Actually create "Chaos" */
1047                 apply_magic(q_ptr, -1, AM_GOOD | AM_GREAT);
1048
1049                 /* Drop it in the dungeon */
1050                 (void)drop_near(q_ptr, -1, y, x);
1051                 break;
1052
1053         case MON_B_DEATH_SWORD:
1054                 if (drop_chosen_item)
1055                 {
1056                         /* Get local object */
1057                         q_ptr = &forge;
1058
1059                         /* Prepare to make a broken sword */
1060                         object_prep(q_ptr, lookup_kind(TV_SWORD, randint1(2)));
1061
1062                         /* Drop it in the dungeon */
1063                         (void)drop_near(q_ptr, -1, y, x);
1064                 }
1065                 break;
1066
1067         case MON_A_GOLD:
1068         case MON_A_SILVER:
1069                 if (drop_chosen_item && ((m_ptr->r_idx == MON_A_GOLD) ||
1070                      ((m_ptr->r_idx == MON_A_SILVER) && !((r_ptr->r_pkills + 1) % 5))))
1071                 {
1072                         /* Get local object */
1073                         q_ptr = &forge;
1074
1075                         /* Prepare to make a Can of Toys */
1076                         object_prep(q_ptr, lookup_kind(TV_CHEST, SV_CHEST_KANDUME));
1077
1078                         apply_magic(q_ptr, object_level, AM_NO_FIXED_ART);
1079
1080                         /* Drop it in the dungeon */
1081                         (void)drop_near(q_ptr, -1, y, x);
1082                 }
1083                 break;
1084
1085         case MON_ROLENTO:
1086                 {
1087                         int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
1088                         (void)project(m_idx, 3, y, x, damroll(20, 10), GF_FIRE, flg, -1);
1089                 }
1090                 break;
1091
1092         default:
1093                 if (!drop_chosen_item) break;
1094
1095                 switch (r_ptr->d_char)
1096                 {
1097                 case '(':
1098                         if (dun_level > 0)
1099                         {
1100                                 /* Get local object */
1101                                 q_ptr = &forge;
1102
1103                                 /* Wipe the object */
1104                                 object_wipe(q_ptr);
1105
1106                                 /* Activate restriction */
1107                                 get_obj_num_hook = kind_is_cloak;
1108
1109                                 /* Prepare allocation table */
1110                                 get_obj_num_prep();
1111
1112                                 /* Make a cloak */
1113                                 make_object(q_ptr, mo_mode);
1114
1115                                 /* Drop it in the dungeon */
1116                                 (void)drop_near(q_ptr, -1, y, x);
1117                         }
1118                         break;
1119
1120                 case '/':
1121                         if (dun_level > 4)
1122                         {
1123                                 /* Get local object */
1124                                 q_ptr = &forge;
1125
1126                                 /* Wipe the object */
1127                                 object_wipe(q_ptr);
1128
1129                                 /* Activate restriction */
1130                                 get_obj_num_hook = kind_is_polearm;
1131
1132                                 /* Prepare allocation table */
1133                                 get_obj_num_prep();
1134
1135                                 /* Make a poleweapon */
1136                                 make_object(q_ptr, mo_mode);
1137
1138                                 /* Drop it in the dungeon */
1139                                 (void)drop_near(q_ptr, -1, y, x);
1140                         }
1141                         break;
1142
1143                 case '[':
1144                         if (dun_level > 19)
1145                         {
1146                                 /* Get local object */
1147                                 q_ptr = &forge;
1148
1149                                 /* Wipe the object */
1150                                 object_wipe(q_ptr);
1151
1152                                 /* Activate restriction */
1153                                 get_obj_num_hook = kind_is_armor;
1154
1155                                 /* Prepare allocation table */
1156                                 get_obj_num_prep();
1157
1158                                 /* Make a hard armor */
1159                                 make_object(q_ptr, mo_mode);
1160
1161                                 /* Drop it in the dungeon */
1162                                 (void)drop_near(q_ptr, -1, y, x);
1163                         }
1164                         break;
1165
1166                 case '|':
1167                         if (m_ptr->r_idx != MON_STORMBRINGER)
1168                         {
1169                                 /* Get local object */
1170                                 q_ptr = &forge;
1171
1172                                 /* Wipe the object */
1173                                 object_wipe(q_ptr);
1174
1175                                 /* Activate restriction */
1176                                 get_obj_num_hook = kind_is_sword;
1177
1178                                 /* Prepare allocation table */
1179                                 get_obj_num_prep();
1180
1181                                 /* Make a sword */
1182                                 make_object(q_ptr, mo_mode);
1183
1184                                 /* Drop it in the dungeon */
1185                                 (void)drop_near(q_ptr, -1, y, x);
1186                         }
1187                         break;
1188                 }
1189                 break;
1190         }
1191
1192         /* Mega-Hack -- drop fixed items */
1193         if (drop_chosen_item)
1194         {
1195                 int a_idx = 0;
1196                 int chance = 0;
1197
1198                 switch (m_ptr->r_idx)
1199                 {
1200                 case MON_OBERON:
1201                         if (one_in_(3))
1202                         {
1203                                 a_idx = ART_JUDGE;
1204                                 chance = 33;
1205                         }
1206                         else
1207                         {
1208                                 a_idx = ART_AMBER;
1209                                 chance = 50;
1210                         }
1211                         break;
1212
1213                 case MON_GHB:
1214                         a_idx = ART_GHB;
1215                         chance = 100;
1216                         break;
1217
1218                 case MON_STORMBRINGER:
1219                         a_idx = ART_STORMBRINGER;
1220                         chance = 100;
1221                         break;
1222
1223                 case MON_ECHIZEN:
1224                         a_idx = ART_CRIMSON;
1225                         chance = 50;
1226                         break;
1227
1228                 case MON_GANDALF:
1229                         a_idx = ART_ICANUS;
1230                         chance = 20;
1231                         break;
1232
1233                 case MON_OROCHI:
1234                         a_idx = ART_KUSANAGI;
1235                         chance = 25;
1236                         break;
1237
1238                 case MON_DWORKIN:
1239                         a_idx = ART_JUDGE;
1240                         chance = 20;
1241                         break;
1242
1243                 case MON_SAURON:
1244                         if (one_in_(10))
1245                         {
1246                                 a_idx = ART_POWER;
1247                                 chance = 100;
1248                         }
1249                         else
1250                         {
1251                                 a_idx = ART_AHO;
1252                                 chance = 100;
1253                         }
1254                         break;
1255
1256                 case MON_BRAND:
1257                         if (!one_in_(3))
1258                         {
1259                                 a_idx = ART_BRAND;
1260                                 chance = 25;
1261                         }
1262                         else
1263                         {
1264                                 a_idx = ART_WEREWINDLE;
1265                                 chance = 33;
1266                         }
1267                         break;
1268
1269                 case MON_CORWIN:
1270                         if (!one_in_(3))
1271                         {
1272                                 a_idx = ART_GRAYSWANDIR;
1273                                 chance = 33;
1274                         }
1275                         else
1276                         {
1277                                 a_idx = ART_CORWIN;
1278                                 chance = 33;
1279                         }
1280                         break;
1281
1282                 case MON_SURTUR:
1283                         a_idx = ART_TWILIGHT;
1284                         chance = 66;
1285                         break;
1286
1287                 case MON_SARUMAN:
1288                         a_idx = ART_ELENDIL;
1289                         chance = 33;
1290                         break;
1291
1292                 case MON_FIONA:
1293                         a_idx = ART_FIONA;
1294                         chance = 50;
1295                         break;
1296
1297                 case MON_JULIAN:
1298                         a_idx = ART_JULIAN;
1299                         chance = 45;
1300                         break;
1301
1302                 case MON_KLING:
1303                         a_idx = ART_DESTINY;
1304                         chance = 40;
1305                         break;
1306
1307                 case MON_GOEMON:
1308                         a_idx = ART_ZANTETSU;
1309                         chance = 75;
1310                         break;
1311
1312                 case MON_HAGEN:
1313                         a_idx = ART_HAGEN;
1314                         chance = 66;
1315                         break;
1316
1317                 case MON_CAINE:
1318                         a_idx = ART_CAINE;
1319                         chance = 50;
1320                         break;
1321
1322                 case MON_BULLGATES:
1323                         a_idx = ART_WINBLOWS;
1324                         chance = 66;
1325                         break;
1326
1327                 case MON_LUNGORTHIN:
1328                         a_idx = ART_CALRIS;
1329                         chance = 50;
1330                         break;
1331
1332                 case MON_JACK_SHADOWS:
1333                         a_idx = ART_JACK;
1334                         chance = 15;
1335                         break;
1336
1337                 case MON_DIO:
1338                         a_idx = ART_STONEMASK;
1339                         chance = 20;
1340                         break;
1341
1342                 case MON_BELD:
1343                         a_idx = ART_SOULCRUSH;
1344                         chance = 10;
1345                         break;
1346
1347                 case MON_PIP:
1348                         a_idx = ART_EXCALIBUR_J;
1349                         chance = 50;
1350                         break;
1351
1352                 case MON_SHUTEN:
1353                         a_idx = ART_SHUTEN_DOJI;
1354                         chance = 33;
1355                         break;
1356
1357                 case MON_GOTHMOG:
1358                         a_idx = ART_GOTHMOG;
1359                         chance = 33;
1360                         break;
1361
1362                 case MON_FUNDIN:
1363                         a_idx = ART_FUNDIN;
1364                         chance = 5;
1365                         break;
1366                 }
1367
1368                 if ((a_idx > 0) && ((randint0(100) < chance) || p_ptr->wizard))
1369                 {
1370                         if (a_info[a_idx].cur_num == 0)
1371                         {
1372                                 /* Create the artifact */
1373                                 create_named_art(a_idx, y, x);
1374                                 a_info[a_idx].cur_num = 1;
1375                         }
1376                 }
1377
1378                 if ((r_ptr->flags7 & RF7_GUARDIAN) && (d_info[dungeon_type].final_guardian == m_ptr->r_idx))
1379                 {
1380                         int k_idx = d_info[dungeon_type].final_object ? d_info[dungeon_type].final_object
1381                                 : lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
1382
1383                         if (d_info[dungeon_type].final_artifact)
1384                         {
1385                                 int a_idx = d_info[dungeon_type].final_artifact;
1386                                 if (!a_info[a_idx].cur_num)
1387                                 {
1388                                         /* Create the artifact */
1389                                         create_named_art(a_idx, y, x);
1390                                         a_info[a_idx].cur_num = 1;
1391
1392                                         /* Prevent rewarding both artifact and "default" object */
1393                                         if (!d_info[dungeon_type].final_object) k_idx = 0;
1394                                 }
1395                         }
1396
1397                         if (k_idx)
1398                         {
1399                                 /* Get local object */
1400                                 q_ptr = &forge;
1401
1402                                 /* Prepare to make a reward */
1403                                 object_prep(q_ptr, k_idx);
1404
1405                                 apply_magic(q_ptr, object_level, AM_NO_FIXED_ART | AM_GOOD);
1406
1407                                 /* Drop it in the dungeon */
1408                                 (void)drop_near(q_ptr, -1, y, x);
1409                         }
1410 #ifdef JP
1411                         msg_format("¤¢¤Ê¤¿¤Ï%s¤òÀ©ÇƤ·¤¿¡ª",d_name+d_info[dungeon_type].name);
1412 #else
1413                         msg_format("You have conquered %s!",d_name+d_info[dungeon_type].name);
1414 #endif
1415                 }
1416         }
1417
1418         /* Determine how much we can drop */
1419         if ((r_ptr->flags1 & RF1_DROP_60) && (randint0(100) < 60)) number++;
1420         if ((r_ptr->flags1 & RF1_DROP_90) && (randint0(100) < 90)) number++;
1421         if  (r_ptr->flags1 & RF1_DROP_1D2) number += damroll(1, 2);
1422         if  (r_ptr->flags1 & RF1_DROP_2D2) number += damroll(2, 2);
1423         if  (r_ptr->flags1 & RF1_DROP_3D2) number += damroll(3, 2);
1424         if  (r_ptr->flags1 & RF1_DROP_4D2) number += damroll(4, 2);
1425
1426         if (cloned && !(r_ptr->flags1 & RF1_UNIQUE))
1427                 number = 0; /* Clones drop no stuff unless Cloning Pits */
1428
1429         if (is_pet(m_ptr) || p_ptr->inside_battle || p_ptr->inside_arena)
1430                 number = 0; /* Pets drop no stuff */
1431         if (!drop_item && (r_ptr->d_char != '$')) number = 0;
1432
1433         /* Hack -- handle creeping coins */
1434         coin_type = force_coin;
1435
1436         /* Average dungeon and monster levels */
1437         object_level = (dun_level + r_ptr->level) / 2;
1438
1439         /* Drop some objects */
1440         for (j = 0; j < number; j++)
1441         {
1442                 /* Get local object */
1443                 q_ptr = &forge;
1444
1445                 /* Wipe the object */
1446                 object_wipe(q_ptr);
1447
1448                 /* Make Gold */
1449                 if (do_gold && (!do_item || (randint0(100) < 50)))
1450                 {
1451                         /* Make some gold */
1452                         if (!make_gold(q_ptr)) continue;
1453
1454                         /* XXX XXX XXX */
1455                         dump_gold++;
1456                 }
1457
1458                 /* Make Object */
1459                 else
1460                 {
1461                         /* Make an object */
1462                         if (!make_object(q_ptr, mo_mode)) continue;
1463
1464                         /* XXX XXX XXX */
1465                         dump_item++;
1466                 }
1467
1468                 /* Drop it in the dungeon */
1469                 (void)drop_near(q_ptr, -1, y, x);
1470         }
1471
1472         /* Reset the object level */
1473         object_level = base_level;
1474
1475         /* Reset "coin" type */
1476         coin_type = 0;
1477
1478
1479         /* Take note of any dropped treasure */
1480         if (visible && (dump_item || dump_gold))
1481         {
1482                 /* Take notes on treasure */
1483                 lore_treasure(m_idx, dump_item, dump_gold);
1484         }
1485
1486         /* Only process "Quest Monsters" */
1487         if (!(r_ptr->flags1 & RF1_QUESTOR)) return;
1488         if (p_ptr->inside_battle) return;
1489
1490         /* Winner? */
1491         if ((m_ptr->r_idx == MON_SERPENT) && !cloned)
1492         {
1493                 /* Total winner */
1494                 p_ptr->total_winner = TRUE;
1495
1496                 /* Redraw the "title" */
1497                 p_ptr->redraw |= (PR_TITLE);
1498
1499 #ifdef JP
1500                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¸«»ö¤ËÊѶòÈÚÅܤξ¡Íø¼Ô¤È¤Ê¤Ã¤¿¡ª");
1501 #else
1502                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "become *WINNER* of Hengband finely!");
1503 #endif
1504
1505                 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) || (p_ptr->muta2 & MUT2_CHAOS_GIFT))
1506                 {
1507 #ifdef JP
1508                         msg_format("%s¤«¤é¤ÎÀ¼¤¬¶Á¤¤¤¿¡£", chaos_patrons[p_ptr->chaos_patron]);
1509                         msg_print("¡Ø¤è¤¯¤ä¤Ã¤¿¡¢ÄêÌ¿¤Î¼Ô¤è¡ª¡Ù");
1510 #else
1511                         msg_format("The voice of %s booms out:", chaos_patrons[p_ptr->chaos_patron]);
1512                         msg_print("'Thou art donst well, mortal!'");
1513 #endif
1514                 }
1515
1516                 /* Congratulations */
1517 #ifdef JP
1518                 msg_print("*** ¤ª¤á¤Ç¤È¤¦ ***");
1519 #else
1520                 msg_print("*** CONGRATULATIONS ***");
1521 #endif
1522
1523 #ifdef JP
1524                 msg_print("¤¢¤Ê¤¿¤Ï¥²¡¼¥à¤ò¥³¥ó¥×¥ê¡¼¥È¤·¤Þ¤·¤¿¡£");
1525 #else
1526                 msg_print("You have won the game!");
1527 #endif
1528
1529 #ifdef JP
1530                 msg_print("½àÈ÷¤¬À°¤Ã¤¿¤é°úÂà(¼«»¦¥³¥Þ¥ó¥É)¤·¤Æ¤â·ë¹½¤Ç¤¹¡£");
1531 #else
1532                 msg_print("You may retire (commit suicide) when you are ready.");
1533 #endif
1534         }
1535 }
1536
1537 /*
1538  * Modify the physical damage done to the monster.
1539  * (for example when it's invulnerable or shielded)
1540  *
1541  * ToDo: Accept a damage-type to calculate the modified damage from
1542  * things like fire, frost, lightning, poison, ... attacks.
1543  *
1544  * "type" is not yet used and should be 0.
1545  */
1546 int mon_damage_mod(monster_type *m_ptr, int dam, bool is_psy_spear)
1547 {
1548         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1549
1550         if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
1551         {
1552                 dam /= 100;
1553                 if((dam == 0) && one_in_(3)) dam = 1;
1554         }
1555
1556         if (m_ptr->invulner)
1557         {
1558                 if (is_psy_spear)
1559                 {
1560                         if(!p_ptr->blind && m_ptr->ml)
1561                         {
1562 #ifdef JP
1563 msg_print("¥Ð¥ê¥¢¤òÀÚ¤êÎö¤¤¤¿¡ª");
1564 #else
1565                                 msg_print("The barrier is penetrated!");
1566 #endif
1567                         }
1568                 }
1569                 else if (!one_in_(PENETRATE_INVULNERABILITY))
1570                 {
1571                         return (0);
1572                 }
1573         }
1574         return (dam);
1575 }
1576
1577 static void get_exp_from_mon(int dam, monster_type *m_ptr)
1578 {
1579         s32b         div, new_exp, new_exp_frac;
1580         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1581         int          monnum_penarty = 0;
1582
1583         if (!m_ptr->r_idx) return;
1584         if (is_pet(m_ptr) || p_ptr->inside_battle) return;
1585         else
1586         {
1587                 u32b m_exp;
1588                 u32b m_exp_h, m_exp_l;
1589                 u32b div_h, div_l;
1590                 if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
1591                 {
1592                         monnum_penarty = r_ptr->r_pkills / 400;
1593                         if (monnum_penarty > 8) monnum_penarty = 8;
1594                 }
1595                 if (r_ptr->flags1 & RF1_UNIQUE)
1596                 {
1597                         m_exp = (long)r_ptr->mexp * r_ptr->level;
1598                         div = (p_ptr->max_plv+2);
1599                 }
1600                 else
1601                 {
1602                         m_exp = (long)r_ptr->mexp * r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed);
1603                         div = (p_ptr->max_plv+2) * SPEED_TO_ENERGY(r_ptr->speed);
1604                 }
1605                 m_exp_h = m_exp/0x10000L;
1606                 m_exp_l = m_exp%0x10000L;
1607                 m_exp_h *= dam;
1608                 m_exp_l *= dam;
1609                 m_exp_h += m_exp_l / 0x10000L;
1610                 m_exp_l %= 0x10000L;
1611
1612                 /* real monster maxhp have effect on EXP */
1613                 if(!(r_ptr->flags1 & RF1_FORCE_MAXHP))
1614                 {
1615                   u32b maxhp = m_ptr->max_maxhp*2;
1616                   m_exp_h *= maxhp;
1617                   m_exp_l *= maxhp;
1618                   m_exp_h += m_exp_l / 0x10000L;
1619                   m_exp_l %= 0x10000L;
1620
1621                   div *= r_ptr->hdice * (r_ptr->hside + 1);
1622                 }
1623                 if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE))) div *= 5;
1624                 div_h = div/0x10000L;
1625                 div_l = div%0x10000L;
1626                 div_h *= (m_ptr->max_maxhp*2);
1627                 div_l *= (m_ptr->max_maxhp*2);
1628                 div_h += div_l / 0x10000L;
1629                 div_l %= 0x10000L;
1630
1631                 while (monnum_penarty)
1632                 {
1633                         div_h *= 4;
1634                         div_l *= 4;
1635                         div_h += div_l / 0x10000L;
1636                         div_l %= 0x10000L;
1637                         monnum_penarty--;
1638                 }
1639
1640                 m_exp_l = (0x7fffffff & (m_exp_h << 16)) | m_exp_l;
1641                 m_exp_h = m_exp_h >> 15;
1642                 div_l = (0x7fffffff & (div_h << 16)) | div_l;
1643                 div_h = div_h >> 15;
1644
1645 #define M_INT_GREATER63(h1,l1,h2,l2)  ( (h1>h2)||( (h1==h2)&&(l1>=l2)))
1646 #define M_INT_SUB63(h1,l1, h2,l2) {h1-=h2;if(l1<l2){l1+=0x80000000;h1--;}l1-=l2;}
1647 #define M_INT_LSHIFT63(h1,l1) {h1=(h1<<1)|(l1>>30);l1=(l1<<1)&0x7fffffff;}
1648 #define M_INT_RSHIFT63(h1,l1) {l1=(l1>>1)|(h1<<30);h1>>=1;}
1649 #define M_INT_DIV63(h1,l1,h2,l2,result) \
1650                 do{ \
1651                   int bit=1; \
1652                   result = 0; \
1653                   while( M_INT_GREATER63(h1,l1, h2, l2) ){M_INT_LSHIFT63(h2, l2); bit<<=1;} \
1654                   for(bit>>=1; bit>=1; bit>>=1){ \
1655                     M_INT_RSHIFT63(h2, l2); \
1656                     if(M_INT_GREATER63(h1, l1, h2, l2)) \
1657                       {result|=bit;M_INT_SUB63(h1, l1, h2, l2);} \
1658                   } \
1659                 } while(0)
1660
1661                 /* Give some experience for the kill */
1662                 M_INT_DIV63(m_exp_h, m_exp_l, div_h, div_l, new_exp);
1663
1664                 /* Handle fractional experience */
1665                 /* multiply 0x10000L to remainder */
1666                 m_exp_h = (m_exp_h<<16) | (m_exp_l>>15);
1667                 m_exp_l <<= 16;
1668                 M_INT_DIV63(m_exp_h, m_exp_l, div_h, div_l, new_exp_frac);
1669                 new_exp_frac += p_ptr->exp_frac;
1670                 /* Keep track of experience */
1671                 if (new_exp_frac >= 0x10000L)
1672                 {
1673                         new_exp++;
1674                         p_ptr->exp_frac = (u16b)(new_exp_frac - 0x10000L);
1675                 }
1676                 else
1677                 {
1678                         p_ptr->exp_frac = (u16b)new_exp_frac;
1679                 }
1680
1681                 /* Gain experience */
1682                 gain_exp(new_exp);
1683         }
1684 }
1685
1686
1687
1688 /*
1689  * Decreases monsters hit points, handling monster death.
1690  *
1691  * We return TRUE if the monster has been killed (and deleted).
1692  *
1693  * We announce monster death (using an optional "death message"
1694  * if given, and a otherwise a generic killed/destroyed message).
1695  *
1696  * Only "physical attacks" can induce the "You have slain" message.
1697  * Missile and Spell attacks will induce the "dies" message, or
1698  * various "specialized" messages.  Note that "You have destroyed"
1699  * and "is destroyed" are synonyms for "You have slain" and "dies".
1700  *
1701  * Hack -- unseen monsters yield "You have killed it." message.
1702  *
1703  * Added fear (DGK) and check whether to print fear messages -CWS
1704  *
1705  * Made name, sex, and capitalization generic -BEN-
1706  *
1707  * As always, the "ghost" processing is a total hack.
1708  *
1709  * Hack -- we "delay" fear messages by passing around a "fear" flag.
1710  *
1711  * XXX XXX XXX Consider decreasing monster experience over time, say,
1712  * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
1713  * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1714  * monster worth more than subsequent monsters.  This would also need
1715  * to induce changes in the monster recall code.
1716  */
1717 bool mon_take_hit(int m_idx, int dam, bool *fear, cptr note)
1718 {
1719         monster_type    *m_ptr = &m_list[m_idx];
1720         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1721
1722         monster_type    exp_mon;
1723
1724         /* Innocent until proven otherwise */
1725         bool        innocent = TRUE, thief = FALSE;
1726         int         i;
1727         int         expdam;
1728
1729         COPY(&exp_mon, m_ptr, monster_type);
1730         if (!(r_ptr->flags7 & RF7_KILL_EXP))
1731         {
1732                 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1733                 if (r_ptr->flags6 & RF6_HEAL) expdam = (expdam+1) * 2 / 3;
1734
1735                 get_exp_from_mon(expdam, &exp_mon);
1736         }
1737
1738         /* Redraw (later) if needed */
1739         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1740         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1741
1742         /* Wake it up */
1743         m_ptr->csleep = 0;
1744
1745         if (r_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
1746
1747         /* Hack - Cancel any special player stealth magics. -LM- */
1748         if (p_ptr->special_defense & NINJA_S_STEALTH)
1749         {
1750                 set_superstealth(FALSE);
1751         }
1752
1753         /* Hurt it */
1754         m_ptr->hp -= dam;
1755
1756         /* It is dead now */
1757         if (m_ptr->hp < 0)
1758         {
1759                 char m_name[80];
1760
1761                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1762                 {
1763                         /* You might have unmasked Tanuki first time */
1764                         r_ptr = &r_info[m_ptr->r_idx];
1765                         m_ptr->ap_r_idx = m_ptr->r_idx;
1766                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1767                 }
1768
1769                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1770                 {
1771                         /* You might have unmasked Chameleon first time */
1772                         r_ptr = real_r_ptr(m_ptr);
1773                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1774                 }
1775
1776                 /* When the player kills a Unique, it stays dead */
1777                 if (r_ptr->flags1 & RF1_UNIQUE && !(m_ptr->smart & SM_CLONED))
1778                         r_ptr->max_num = 0;
1779
1780                 /* When the player kills a Nazgul, it stays dead */
1781                 if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num--;
1782
1783                 /* Recall even invisible uniques or winners */
1784                 if (m_ptr->ml || (r_ptr->flags1 & RF1_UNIQUE))
1785                 {
1786                         /* Count kills this life */
1787                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1788                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1789
1790                         /* Count kills in all lives */
1791                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1792                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1793
1794                         /* Hack -- Auto-recall */
1795                         monster_race_track(m_ptr->ap_r_idx);
1796                 }
1797
1798                 /* Extract monster name */
1799                 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1800
1801                 /* Don't kill Amberites */
1802                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1803                 {
1804                         int curses = 1 + randint1(3);
1805                         bool stop_ty = FALSE;
1806                         int count = 0;
1807
1808 #ifdef JP
1809 msg_format("%^s¤Ï¶²¤í¤·¤¤·ì¤Î¼ö¤¤¤ò¤¢¤Ê¤¿¤Ë¤«¤±¤¿¡ª", m_name);
1810 #else
1811                         msg_format("%^s puts a terrible blood curse on you!", m_name);
1812 #endif
1813
1814                         curse_equipment(100, 50);
1815
1816                         do
1817                         {
1818                                 stop_ty = activate_ty_curse(stop_ty, &count);
1819                         }
1820                         while (--curses);
1821                 }
1822
1823                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1824                 {
1825                         char line_got[1024];
1826
1827                         /* Dump a message */
1828 #ifdef JP
1829                         if (!get_rnd_line("mondeath_j.txt", m_ptr->r_idx, line_got))
1830 #else
1831                         if (!get_rnd_line("mondeath.txt", m_ptr->r_idx, line_got))
1832 #endif
1833
1834                                 msg_format("%^s %s", m_name, line_got);
1835
1836 #ifdef WORLD_SCORE
1837                         if (m_ptr->r_idx == MON_SERPENT)
1838                         {
1839                                 /* Make screen dump */
1840                                 screen_dump = make_screen_dump();
1841                         }
1842 #endif
1843                 }
1844
1845                 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1846                 {
1847                         if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
1848                         {
1849                                 chg_virtue(V_VALOUR, -1);
1850                         }
1851                         else if (r_ptr->level > dun_level)
1852                         {
1853                                 if (randint1(10) <= (r_ptr->level - dun_level))
1854                                         chg_virtue(V_VALOUR, 1);
1855                         }
1856                         if (r_ptr->level > 60)
1857                         {
1858                                 chg_virtue(V_VALOUR, 1);
1859                         }
1860                         if (r_ptr->level >= 2 * (p_ptr->lev+1))
1861                                 chg_virtue(V_VALOUR, 2);
1862                 }
1863
1864                 if ((r_ptr->flags1 & RF1_UNIQUE) && ((r_ptr->flags3 & RF3_EVIL) ||
1865                         (r_ptr->flags3 & RF3_GOOD)))
1866                         
1867                         chg_virtue(V_HARMONY, 2);
1868
1869                 if ((r_ptr->flags1 & RF1_UNIQUE) && (r_ptr->flags3 & RF3_GOOD))
1870                 {
1871                         chg_virtue(V_UNLIFE, 2);
1872                         chg_virtue(V_VITALITY, -2);
1873                 }
1874
1875                 if ((r_ptr->flags1 & RF1_UNIQUE) && one_in_(3))
1876                         chg_virtue(V_INDIVIDUALISM, -1);
1877
1878                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1879                 {
1880                         chg_virtue(V_COMPASSION, -1);
1881                 }
1882
1883                 if ((r_ptr->flags3 & RF3_GOOD) &&
1884                         ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
1885                         
1886                         chg_virtue(V_UNLIFE, 1);
1887
1888                 if (r_ptr->d_char == 'A')
1889                 {
1890                         if (r_ptr->flags1 & RF1_UNIQUE)
1891                                 chg_virtue(V_FAITH, -2);
1892                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1893                         {
1894                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1895                                 else chg_virtue(V_FAITH, 1);
1896                         }
1897                 }
1898                 else if (r_ptr->flags3 & RF3_DEMON)
1899                 {
1900                         if (r_ptr->flags1 & RF1_UNIQUE)
1901                                 chg_virtue(V_FAITH, 2);
1902                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1903                                 chg_virtue(V_FAITH, 1);
1904                 }
1905
1906                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1907                         chg_virtue(V_VITALITY, 2);
1908
1909                 if (r_ptr->r_deaths)
1910                 {
1911                         if (r_ptr->flags1 & RF1_UNIQUE)
1912                         {
1913                                 chg_virtue(V_HONOUR, 10);
1914                         }
1915                         else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
1916                         {
1917                                 chg_virtue(V_HONOUR, 1);
1918                         }
1919                 }
1920                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_pkills > 1000) && one_in_(10))
1921                 {
1922                         chg_virtue(V_VALOUR, -1);
1923                 }
1924                 
1925                 for (i = 0; i < 4; i++)
1926                 {
1927                         if(r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1928                 
1929                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1930                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1931                         
1932                                 thief = TRUE; /* Thief! */
1933                 }
1934
1935                 /* The new law says it is illegal to live in the dungeon */
1936                 if (r_ptr->level != 0) innocent = FALSE;
1937
1938                 if (thief)
1939                 {
1940                         if (r_ptr->flags1 & RF1_UNIQUE)
1941                                 chg_virtue(V_JUSTICE, 3);
1942                         else if (1+((r_ptr->level) / 10 + (2 * dun_level))
1943                                 >= randint1(100))
1944                                 
1945                                 chg_virtue(V_JUSTICE, 1);
1946                 }
1947                 else if (innocent)
1948                 {
1949                         chg_virtue (V_JUSTICE, -1);
1950                 }
1951
1952                 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)))
1953                 {
1954                         if (one_in_(4)) chg_virtue(V_NATURE, -1);
1955                 }
1956
1957                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1958                 {
1959                         char m_name[160];
1960 #ifdef JP
1961                         sprintf(m_name, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? "(¥¯¥í¡¼¥ó)" : "");
1962 #else
1963                         sprintf(m_name, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? "(Clone)" : "");
1964 #endif
1965                         do_cmd_write_nikki(NIKKI_UNIQUE, 0, m_name);
1966                 }
1967
1968                 /* Make a sound */
1969                 sound(SOUND_KILL);
1970
1971                 /* Death by Missile/Spell attack */
1972                 if (note)
1973                 {
1974                         msg_format("%^s%s", m_name, note);
1975                 }
1976
1977                 /* Death by physical attack -- invisible monster */
1978                 else if (!m_ptr->ml)
1979                 {
1980 #ifdef JP
1981                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1982                                 msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤ò»¦¤·¤¿¡£", m_name);
1983                         else
1984 msg_format("%s¤ò»¦¤·¤¿¡£", m_name);
1985 #else
1986                                 msg_format("You have killed %s.", m_name);
1987 #endif
1988
1989                 }
1990
1991                 /* Death by Physical attack -- non-living monster */
1992                 else if (!monster_living(r_ptr))
1993                 {
1994                         int i;
1995                         bool explode = FALSE;
1996
1997                         for (i = 0; i < 4; i++)
1998                         {
1999                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
2000                         }
2001
2002                         /* Special note at death */
2003                         if (explode)
2004 #ifdef JP
2005 msg_format("%s¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_name);
2006 #else
2007                                 msg_format("%s explodes into tiny shreds.", m_name);
2008 #endif
2009                         else
2010                         {
2011 #ifdef JP
2012                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2013                                         msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤òÅݤ·¤¿¡£", m_name);
2014                                 else
2015 msg_format("%s¤òÅݤ·¤¿¡£", m_name);
2016 #else
2017                                 msg_format("You have destroyed %s.", m_name);
2018 #endif
2019                         }
2020                 }
2021
2022                 /* Death by Physical attack -- living monster */
2023                 else
2024                 {
2025 #ifdef JP
2026                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2027                                 msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤òÁò¤êµî¤Ã¤¿¡£", m_name);
2028                         else
2029 msg_format("%s¤òÁò¤êµî¤Ã¤¿¡£", m_name);
2030 #else
2031                                 msg_format("You have slain %s.", m_name);
2032 #endif
2033
2034                 }
2035                 if (r_ptr->flags1 & RF1_UNIQUE && !(m_ptr->smart & SM_CLONED))
2036                 {
2037                         for (i = 0; i < MAX_KUBI; i++)
2038                         {
2039                                 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
2040                                 {
2041 #ifdef JP
2042 msg_format("%s¤Î¼ó¤Ë¤Ï¾Þ¶â¤¬¤«¤«¤Ã¤Æ¤¤¤ë¡£", m_name);
2043 #else
2044                                         msg_format("There is a price on %s's head.", m_name);
2045 #endif
2046                                         break;
2047                                 }
2048                         }
2049                 }
2050
2051                 /* Generate treasure */
2052                 monster_death(m_idx, TRUE);
2053                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
2054                 {
2055                         r_info[MON_BANORLUPART].max_num = 0;
2056                         r_info[MON_BANORLUPART].r_pkills++;
2057                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
2058                 }
2059
2060                 if (m_ptr->r_idx == MON_BANORLUPART)
2061                 {
2062                         r_info[MON_BANOR].max_num = 0;
2063                         r_info[MON_BANOR].r_pkills++;
2064                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
2065                         r_info[MON_LUPART].max_num = 0;
2066                         r_info[MON_LUPART].r_pkills++;
2067                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
2068                 }
2069
2070                 /* Mega hack : replace IKETA to BIKETAL */
2071                 if ((m_ptr->r_idx == MON_IKETA) &&
2072                     !(p_ptr->inside_arena || p_ptr->inside_battle))
2073                 {
2074                         int dummy_y = m_ptr->fy;
2075                         int dummy_x = m_ptr->fx;
2076                         u32b mode = 0L;
2077
2078                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
2079
2080                         /* Delete the monster */
2081                         delete_monster_idx(m_idx);
2082
2083                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
2084                         {
2085 #ifdef JP
2086                                 msg_print("¡Ö¥Ï¥¡¥Ã¥Ï¥Ã¥Ï¥Ã¥Ï¡ª¡ª»ä¤¬¥Ð¥¤¥±¥¿¥ë¤À¡ª¡ª¡×");
2087 #else
2088                                 msg_print("Uwa-hahaha!  *I* am Biketal!");
2089 #endif
2090                         }
2091                 }
2092                 else
2093                 {
2094                         /* Delete the monster */
2095                         delete_monster_idx(m_idx);
2096                 }
2097
2098                 /* Prevent bug of chaos patron's reward */
2099                 if (r_ptr->flags7 & RF7_KILL_EXP)
2100                         get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
2101                 else
2102                         get_exp_from_mon(((long)exp_mon.max_maxhp+1L) * 9L / 10L, &exp_mon);
2103
2104                 /* Not afraid */
2105                 (*fear) = FALSE;
2106
2107                 /* Monster is dead */
2108                 return (TRUE);
2109         }
2110
2111
2112 #ifdef ALLOW_FEAR
2113
2114         /* Mega-Hack -- Pain cancels fear */
2115         if (m_ptr->monfear && (dam > 0))
2116         {
2117                 int tmp = randint1(dam);
2118
2119                 /* Cure a little fear */
2120                 if (tmp < m_ptr->monfear)
2121                 {
2122                         /* Reduce fear */
2123                         m_ptr->monfear -= tmp;
2124                 }
2125
2126                 /* Cure all the fear */
2127                 else
2128                 {
2129                         /* Cure fear */
2130                         m_ptr->monfear = 0;
2131
2132                         /* No more fear */
2133                         (*fear) = FALSE;
2134                 }
2135         }
2136
2137         /* Sometimes a monster gets scared by damage */
2138         if (!m_ptr->monfear && !(r_ptr->flags3 & (RF3_NO_FEAR)))
2139         {
2140                 int percentage;
2141
2142                 /* Percentage of fully healthy */
2143                 percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
2144
2145                 /*
2146                  * Run (sometimes) if at 10% or less of max hit points,
2147                  * or (usually) when hit for half its current hit points
2148                  */
2149                 if ((randint1(10) >= percentage) ||
2150                     ((dam >= m_ptr->hp) && (randint0(100) < 80)))
2151                 {
2152                         /* Hack -- note fear */
2153                         (*fear) = TRUE;
2154
2155                         /* XXX XXX XXX Hack -- Add some timed fear */
2156                         m_ptr->monfear = (randint1(10) +
2157                                           (((dam >= m_ptr->hp) && (percentage > 7)) ?
2158                                            20 : ((11 - percentage) * 5)));
2159                 }
2160         }
2161
2162 #endif
2163
2164 #if 0
2165         if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
2166         {
2167                 char m_name[80];
2168
2169                 /* Extract monster name */
2170                 monster_desc(m_name, m_ptr, 0);
2171
2172                 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
2173                 if (rakuba((dam > 200) ? 200 : dam, FALSE))
2174                 {
2175 #ifdef JP
2176 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
2177 #else
2178                                 msg_format("%^s has thrown you off!", m_name);
2179 #endif
2180                 }
2181         }
2182 #endif
2183
2184         /* Not dead yet */
2185         return (FALSE);
2186 }
2187
2188
2189 /*
2190  * Get term size and calculate screen size
2191  */
2192 void get_screen_size(int *wid_p, int *hgt_p)
2193 {
2194         Term_get_size(wid_p, hgt_p);
2195         *hgt_p -= ROW_MAP + 2;
2196         *wid_p -= COL_MAP + 2;
2197         if (use_bigtile) *wid_p /= 2;
2198 }
2199
2200
2201 /*
2202  * Calculates current boundaries
2203  * Called below and from "do_cmd_locate()".
2204  */
2205 void panel_bounds_center(void)
2206 {
2207         int wid, hgt;
2208
2209         /* Get size */
2210         get_screen_size(&wid, &hgt);
2211
2212         panel_row_max = panel_row_min + hgt - 1;
2213         panel_row_prt = panel_row_min - 1;
2214         panel_col_max = panel_col_min + wid - 1;
2215         panel_col_prt = panel_col_min - 13;
2216 }
2217
2218
2219 /*
2220  * Map resizing whenever the main term changes size
2221  */
2222 void resize_map(void)
2223 {
2224         /* Only if the dungeon exists */
2225         if (!character_dungeon) return;
2226         
2227         /* Mega-Hack -- no panel yet */
2228         panel_row_max = 0;
2229         panel_col_max = 0;
2230
2231         /* Reset the panels */
2232         panel_row_min = cur_hgt;
2233         panel_col_min = cur_wid;
2234                                 
2235         verify_panel();
2236
2237         /* Update stuff */
2238         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
2239
2240         /* Forget lite/view */
2241         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
2242
2243         /* Update lite/view */
2244         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
2245
2246         /* Update monsters */
2247         p_ptr->update |= (PU_MONSTERS);
2248
2249         /* Redraw everything */
2250         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
2251
2252         /* Hack -- update */
2253         handle_stuff();
2254         
2255         /* Redraw */
2256         Term_redraw();
2257
2258         /*
2259          * Waiting command;
2260          * Place the cursor on the player
2261          */
2262         if (can_save) move_cursor_relative(py, px);
2263
2264         /* Refresh */
2265         Term_fresh();
2266 }
2267
2268 /*
2269  * Redraw a term when it is resized
2270  */
2271 void redraw_window(void)
2272 {
2273         /* Only if the dungeon exists */
2274         if (!character_dungeon) return;
2275         
2276         /* Hack - Activate term zero for the redraw */
2277         Term_activate(&term_screen[0]);
2278         
2279         /* Hack -- react to changes */
2280         Term_xtra(TERM_XTRA_REACT, 0);
2281
2282         /* Window stuff */
2283         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
2284
2285         /* Window stuff */
2286         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
2287
2288         /* Hack -- update */
2289         handle_stuff();
2290
2291         /* Redraw */
2292         Term_redraw();
2293
2294         /* Refresh */
2295         Term_fresh();
2296 }
2297
2298
2299 /*
2300  * Handle a request to change the current panel
2301  *
2302  * Return TRUE if the panel was changed.
2303  *
2304  * Also used in do_cmd_locate
2305  */
2306 bool change_panel(int dy, int dx)
2307 {
2308         int y, x;
2309         int wid, hgt;
2310
2311         /* Get size */
2312         get_screen_size(&wid, &hgt);
2313
2314         /* Apply the motion */
2315         y = panel_row_min + dy * hgt / 2;
2316         x = panel_col_min + dx * wid / 2;
2317
2318         /* Verify the row */
2319         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
2320         if (y < 0) y = 0;
2321
2322         /* Verify the col */
2323         if (x > cur_wid - wid) x = cur_wid - wid;
2324         if (x < 0) x = 0;
2325
2326         /* Handle "changes" */
2327         if ((y != panel_row_min) || (x != panel_col_min))
2328         {
2329                 /* Save the new panel info */
2330                 panel_row_min = y;
2331                 panel_col_min = x;
2332
2333                 /* Recalculate the boundaries */
2334                 panel_bounds_center();
2335
2336                 /* Update stuff */
2337                 p_ptr->update |= (PU_MONSTERS);
2338
2339                 /* Redraw map */
2340                 p_ptr->redraw |= (PR_MAP);
2341
2342                 /* Handle stuff */
2343                 handle_stuff();
2344
2345                 /* Success */
2346                 return (TRUE);
2347         }
2348
2349         /* No change */
2350         return (FALSE);
2351 }
2352
2353
2354 /*
2355  * Given an row (y) and col (x), this routine detects when a move
2356  * off the screen has occurred and figures new borders. -RAK-
2357  *
2358  * "Update" forces a "full update" to take place.
2359  *
2360  * The map is reprinted if necessary, and "TRUE" is returned.
2361  */
2362 void verify_panel(void)
2363 {
2364         int y = py;
2365         int x = px;
2366         int wid, hgt;
2367
2368         int prow_min;
2369         int pcol_min;
2370         int max_prow_min;
2371         int max_pcol_min;
2372
2373         /* Get size */
2374         get_screen_size(&wid, &hgt);
2375
2376         max_prow_min = cur_hgt - hgt;
2377         max_pcol_min = cur_wid - wid;
2378
2379         /* Bounds checking */
2380         if (max_prow_min < 0) max_prow_min = 0;
2381         if (max_pcol_min < 0) max_pcol_min = 0;
2382
2383                 /* Center on player */
2384         if (center_player && (center_running || !running))
2385         {
2386                 /* Center vertically */
2387                 prow_min = y - hgt / 2;
2388                 if (prow_min < 0) prow_min = 0;
2389                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
2390
2391                 /* Center horizontally */
2392                 pcol_min = x - wid / 2;
2393                 if (pcol_min < 0) pcol_min = 0;
2394                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2395         }
2396         else
2397         {
2398                 prow_min = panel_row_min;
2399                 pcol_min = panel_col_min;
2400
2401                 /* Scroll screen when 2 grids from top/bottom edge */
2402                 if (y > panel_row_max - 2)
2403                 {
2404                         while (y > prow_min + hgt-1 - 2)
2405                         {
2406                                 prow_min += (hgt / 2);
2407                         }
2408                 }
2409
2410                 if (y < panel_row_min + 2)
2411                 {
2412                         while (y < prow_min + 2)
2413                         {
2414                                 prow_min -= (hgt / 2);
2415                         }
2416                 }
2417
2418                 if (prow_min > max_prow_min) prow_min = max_prow_min;
2419                 if (prow_min < 0) prow_min = 0;
2420
2421                 /* Scroll screen when 4 grids from left/right edge */
2422                 if (x > panel_col_max - 4)
2423                 {
2424                         while (x > pcol_min + wid-1 - 4)
2425                         {
2426                                 pcol_min += (wid / 2);
2427                         }
2428                 }
2429                 
2430                 if (x < panel_col_min + 4)
2431                 {
2432                         while (x < pcol_min + 4)
2433                         {
2434                                 pcol_min -= (wid / 2);
2435                         }
2436                 }
2437
2438                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2439                 if (pcol_min < 0) pcol_min = 0;
2440         }
2441
2442         /* Check for "no change" */
2443         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
2444
2445         /* Save the new panel info */
2446         panel_row_min = prow_min;
2447         panel_col_min = pcol_min;
2448
2449         /* Hack -- optional disturb on "panel change" */
2450         if (disturb_panel && !center_player) disturb(0, 0);
2451
2452         /* Recalculate the boundaries */
2453         panel_bounds_center();
2454
2455         /* Update stuff */
2456         p_ptr->update |= (PU_MONSTERS);
2457
2458         /* Redraw map */
2459         p_ptr->redraw |= (PR_MAP);
2460
2461         /* Window stuff */
2462         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2463 }
2464
2465
2466 /*
2467  * Monster health description
2468  */
2469 cptr look_mon_desc(monster_type *m_ptr, u32b mode)
2470 {
2471         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2472         bool         living;
2473         int          perc;
2474         cptr desc;
2475         cptr attitude;
2476         cptr clone;
2477
2478         /* Determine if the monster is "living" */
2479         living = monster_living(ap_r_ptr);
2480
2481         /* Calculate a health "percentage" */
2482         perc = 100L * m_ptr->hp / m_ptr->maxhp;
2483
2484         /* Healthy monsters */
2485         if (m_ptr->hp >= m_ptr->maxhp)
2486         {
2487                 /* No damage */
2488 #ifdef JP
2489                 desc = living ? "̵½ý" : "̵¥À¥á¡¼¥¸";
2490 #else
2491                 desc = living ? "unhurt" : "undamaged";
2492 #endif
2493
2494         }
2495
2496         else if (perc >= 60)
2497         {
2498 #ifdef JP
2499                 desc = living ? "·Ú½ý" : "¾®¥À¥á¡¼¥¸";
2500 #else
2501                 desc = living ? "somewhat wounded" : "somewhat damaged";
2502 #endif
2503
2504         }
2505
2506         else if (perc >= 25)
2507         {
2508 #ifdef JP
2509                 desc = living ? "Éé½ý" : "Ãæ¥À¥á¡¼¥¸";
2510 #else
2511                 desc = living ? "wounded" : "damaged";
2512 #endif
2513
2514         }
2515
2516         else if (perc >= 10)
2517         {
2518 #ifdef JP
2519                 desc = living ? "½Å½ý" : "Âç¥À¥á¡¼¥¸";
2520 #else
2521                 desc = living ? "badly wounded" : "badly damaged";
2522 #endif
2523
2524         }
2525
2526         else 
2527         {
2528 #ifdef JP
2529                 desc = living ? "Ⱦ»àȾÀ¸" : "Åݤ줫¤±";
2530 #else
2531                 desc = living ? "almost dead" : "almost destroyed";
2532 #endif
2533         }
2534
2535
2536         /* Need attitude information? */
2537         if (!(mode & 0x01))
2538         {
2539                 /* Full information is not needed */
2540                 attitude = "";
2541         }
2542         else if (is_pet(m_ptr))
2543         {
2544 #ifdef JP
2545                 attitude = ", ¥Ú¥Ã¥È";
2546 #else
2547                 attitude = ", pet";
2548 #endif
2549         }
2550         else if (is_friendly(m_ptr))
2551         {
2552 #ifdef JP
2553                 attitude = ", Í§¹¥Åª";
2554 #else
2555                 attitude = ", friendly";
2556 #endif
2557         }
2558         else
2559         {
2560 #ifdef JP
2561                 attitude = "";
2562 #else
2563                 attitude = "";
2564 #endif
2565         }
2566
2567
2568         /* Clone monster? */
2569         if (m_ptr->smart & SM_CLONED)
2570         {
2571                 clone = ", clone";
2572         }
2573         else
2574         {
2575                 clone = "";
2576         }
2577
2578         /* Display monster's level --- idea borrowed from ToME */
2579         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
2580         {
2581 #ifdef JP
2582                 return format("¥ì¥Ù¥ë%d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2583 #else
2584                 return format("Level %d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2585 #endif
2586         }
2587         else 
2588         {
2589 #ifdef JP
2590                 return format("¥ì¥Ù¥ë???, %s%s%s", desc, attitude, clone);
2591 #else
2592                 return format("Level ???, %s%s%s", desc, attitude, clone);
2593 #endif
2594         }
2595 }
2596
2597
2598
2599 /*
2600  * Angband sorting algorithm -- quick sort in place
2601  *
2602  * Note that the details of the data we are sorting is hidden,
2603  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2604  * function hooks to interact with the data, which is given as
2605  * two pointers, and which may have any user-defined form.
2606  */
2607 void ang_sort_aux(vptr u, vptr v, int p, int q)
2608 {
2609         int z, a, b;
2610
2611         /* Done sort */
2612         if (p >= q) return;
2613
2614         /* Pivot */
2615         z = p;
2616
2617         /* Begin */
2618         a = p;
2619         b = q;
2620
2621         /* Partition */
2622         while (TRUE)
2623         {
2624                 /* Slide i2 */
2625                 while (!(*ang_sort_comp)(u, v, b, z)) b--;
2626
2627                 /* Slide i1 */
2628                 while (!(*ang_sort_comp)(u, v, z, a)) a++;
2629
2630                 /* Done partition */
2631                 if (a >= b) break;
2632
2633                 /* Swap */
2634                 (*ang_sort_swap)(u, v, a, b);
2635
2636                 /* Advance */
2637                 a++, b--;
2638         }
2639
2640         /* Recurse left side */
2641         ang_sort_aux(u, v, p, b);
2642
2643         /* Recurse right side */
2644         ang_sort_aux(u, v, b+1, q);
2645 }
2646
2647
2648 /*
2649  * Angband sorting algorithm -- quick sort in place
2650  *
2651  * Note that the details of the data we are sorting is hidden,
2652  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2653  * function hooks to interact with the data, which is given as
2654  * two pointers, and which may have any user-defined form.
2655  */
2656 void ang_sort(vptr u, vptr v, int n)
2657 {
2658         /* Sort the array */
2659         ang_sort_aux(u, v, 0, n-1);
2660 }
2661
2662
2663
2664 /*** Targeting Code ***/
2665
2666
2667 /*
2668  * Determine is a monster makes a reasonable target
2669  *
2670  * The concept of "targeting" was stolen from "Morgul" (?)
2671  *
2672  * The player can target any location, or any "target-able" monster.
2673  *
2674  * Currently, a monster is "target_able" if it is visible, and if
2675  * the player can hit it with a projection, and the player is not
2676  * hallucinating.  This allows use of "use closest target" macros.
2677  *
2678  * Future versions may restrict the ability to target "trappers"
2679  * and "mimics", but the semantics is a little bit weird.
2680  */
2681 bool target_able(int m_idx)
2682 {
2683         monster_type *m_ptr = &m_list[m_idx];
2684
2685         /* Monster must be alive */
2686         if (!m_ptr->r_idx) return (FALSE);
2687
2688         /* Hack -- no targeting hallucinations */
2689         if (p_ptr->image) return (FALSE);
2690
2691         /* Monster must be visible */
2692         if (!m_ptr->ml) return (FALSE);
2693
2694         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
2695
2696         /* Monster must be projectable */
2697         if (!projectable(py, px, m_ptr->fy, m_ptr->fx)) return (FALSE);
2698
2699         /* XXX XXX XXX Hack -- Never target trappers */
2700         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
2701
2702         /* Assume okay */
2703         return (TRUE);
2704 }
2705
2706
2707
2708
2709 /*
2710  * Update (if necessary) and verify (if possible) the target.
2711  *
2712  * We return TRUE if the target is "okay" and FALSE otherwise.
2713  */
2714 bool target_okay(void)
2715 {
2716         /* Accept stationary targets */
2717         if (target_who < 0) return (TRUE);
2718
2719         /* Check moving targets */
2720         if (target_who > 0)
2721         {
2722                 /* Accept reasonable targets */
2723                 if (target_able(target_who))
2724                 {
2725                         monster_type *m_ptr = &m_list[target_who];
2726
2727                         /* Acquire monster location */
2728                         target_row = m_ptr->fy;
2729                         target_col = m_ptr->fx;
2730
2731                         /* Good target */
2732                         return (TRUE);
2733                 }
2734         }
2735
2736         /* Assume no target */
2737         return (FALSE);
2738 }
2739
2740
2741
2742 /*
2743  * Sorting hook -- comp function -- by "distance to player"
2744  *
2745  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2746  * and sort the arrays by double-distance to the player.
2747  */
2748 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
2749 {
2750         byte *x = (byte*)(u);
2751         byte *y = (byte*)(v);
2752
2753         int da, db, kx, ky;
2754
2755         /* Absolute distance components */
2756         kx = x[a]; kx -= px; kx = ABS(kx);
2757         ky = y[a]; ky -= py; ky = ABS(ky);
2758
2759         /* Approximate Double Distance to the first point */
2760         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2761
2762         /* Absolute distance components */
2763         kx = x[b]; kx -= px; kx = ABS(kx);
2764         ky = y[b]; ky -= py; ky = ABS(ky);
2765
2766         /* Approximate Double Distance to the first point */
2767         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2768
2769         /* Compare the distances */
2770         return (da <= db);
2771 }
2772
2773
2774 /*
2775  * Sorting hook -- swap function -- by "distance to player"
2776  *
2777  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2778  * and sort the arrays by distance to the player.
2779  */
2780 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
2781 {
2782         byte *x = (byte*)(u);
2783         byte *y = (byte*)(v);
2784
2785         byte temp;
2786
2787         /* Swap "x" */
2788         temp = x[a];
2789         x[a] = x[b];
2790         x[b] = temp;
2791
2792         /* Swap "y" */
2793         temp = y[a];
2794         y[a] = y[b];
2795         y[b] = temp;
2796 }
2797
2798
2799
2800 /*
2801  * Hack -- help "select" a location (see below)
2802  */
2803 static s16b target_pick(int y1, int x1, int dy, int dx)
2804 {
2805         int i, v;
2806
2807         int x2, y2, x3, y3, x4, y4;
2808
2809         int b_i = -1, b_v = 9999;
2810
2811
2812         /* Scan the locations */
2813         for (i = 0; i < temp_n; i++)
2814         {
2815                 /* Point 2 */
2816                 x2 = temp_x[i];
2817                 y2 = temp_y[i];
2818
2819                 /* Directed distance */
2820                 x3 = (x2 - x1);
2821                 y3 = (y2 - y1);
2822
2823                 /* Verify quadrant */
2824                 if (dx && (x3 * dx <= 0)) continue;
2825                 if (dy && (y3 * dy <= 0)) continue;
2826
2827                 /* Absolute distance */
2828                 x4 = ABS(x3);
2829                 y4 = ABS(y3);
2830
2831                 /* Verify quadrant */
2832                 if (dy && !dx && (x4 > y4)) continue;
2833                 if (dx && !dy && (y4 > x4)) continue;
2834
2835                 /* Approximate Double Distance */
2836                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
2837
2838                 /* XXX XXX XXX Penalize location */
2839
2840                 /* Track best */
2841                 if ((b_i >= 0) && (v >= b_v)) continue;
2842
2843                 /* Track best */
2844                 b_i = i; b_v = v;
2845         }
2846
2847         /* Result */
2848         return (b_i);
2849 }
2850
2851
2852 /*
2853  * Hack -- determine if a given location is "interesting"
2854  */
2855 static bool target_set_accept(int y, int x)
2856 {
2857         cave_type *c_ptr;
2858
2859         s16b this_o_idx, next_o_idx = 0;
2860
2861         /* Bounds */
2862         if (!(in_bounds(y, x))) return (FALSE);
2863
2864         /* Player grid is always interesting */
2865         if (player_bold(y, x)) return (TRUE);
2866
2867
2868         /* Handle hallucination */
2869         if (p_ptr->image) return (FALSE);
2870
2871
2872         /* Examine the grid */
2873         c_ptr = &cave[y][x];
2874
2875         /* Visible monsters */
2876         if (c_ptr->m_idx)
2877         {
2878                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2879
2880                 /* Visible monsters */
2881                 if (m_ptr->ml) return (TRUE);
2882         }
2883
2884         /* Scan all objects in the grid */
2885         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2886         {
2887                 object_type *o_ptr;
2888
2889                 /* Acquire object */
2890                 o_ptr = &o_list[this_o_idx];
2891
2892                 /* Acquire next object */
2893                 next_o_idx = o_ptr->next_o_idx;
2894
2895                 /* Memorized object */
2896                 if (o_ptr->marked) return (TRUE);
2897         }
2898
2899         /* Interesting memorized features */
2900         if (c_ptr->info & (CAVE_MARK))
2901         {
2902                 byte feat;
2903
2904                 /* Feature code (applying "mimic" field) */
2905                 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
2906
2907                 /* Notice glyphs */
2908                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
2909
2910                 /* Notice the Pattern */
2911                 if ((feat <= FEAT_PATTERN_XTRA2) &&
2912                     (feat >= FEAT_PATTERN_START))
2913                         return (TRUE);
2914
2915                 /* Notice doors */
2916                 if (feat == FEAT_OPEN) return (TRUE);
2917                 if (feat == FEAT_BROKEN) return (TRUE);
2918
2919                 /* Notice stairs */
2920                 if (feat == FEAT_LESS) return (TRUE);
2921                 if (feat == FEAT_MORE) return (TRUE);
2922                 if (feat == FEAT_LESS_LESS) return (TRUE);
2923                 if (feat == FEAT_MORE_MORE) return (TRUE);
2924
2925                 /* Notice shops */
2926                 if ((feat >= FEAT_SHOP_HEAD) &&
2927                     (feat <= FEAT_SHOP_TAIL)) return (TRUE);
2928
2929                 if (feat == FEAT_MUSEUM) return (TRUE);
2930
2931                 /* Notice buildings -KMW- */
2932                 if ((feat >= FEAT_BLDG_HEAD) &&
2933                     (feat <= FEAT_BLDG_TAIL)) return (TRUE);
2934
2935                 /* Notice traps */
2936                 if (is_trap(feat)) return (TRUE);
2937
2938                 /* Notice doors */
2939                 if ((feat >= FEAT_DOOR_HEAD) &&
2940                     (feat <= FEAT_DOOR_TAIL)) return (TRUE);
2941
2942 #if 0
2943                 /* Notice rubble */
2944                 /* I think FEAT_RUBBLEs should not be "interesting" */
2945                 if (feat == FEAT_RUBBLE) return (TRUE);
2946
2947                 /* Notice veins with treasure */
2948                 /* Now veins with treasure are too many */
2949                 if (feat == FEAT_MAGMA_K) return (TRUE);
2950                 if (feat == FEAT_QUARTZ_K) return (TRUE);
2951 #endif
2952
2953                 /* Notice quest features */
2954                 if (feat == FEAT_QUEST_ENTER) return (TRUE);
2955                 if (feat == FEAT_QUEST_EXIT) return (TRUE);
2956                 if (feat == FEAT_QUEST_DOWN) return (TRUE);
2957                 if (feat == FEAT_QUEST_UP) return (TRUE);
2958                 if (feat == FEAT_TOWN) return (TRUE);
2959                 if (feat == FEAT_ENTRANCE) return (TRUE);
2960         }
2961
2962         /* Nope */
2963         return (FALSE);
2964 }
2965
2966
2967 /*
2968  * Prepare the "temp" array for "target_set"
2969  *
2970  * Return the number of target_able monsters in the set.
2971  */
2972 static void target_set_prepare(int mode)
2973 {
2974         int y, x;
2975
2976         /* Reset "temp" array */
2977         temp_n = 0;
2978
2979         /* Scan the current panel */
2980         for (y = panel_row_min; y <= panel_row_max; y++)
2981         {
2982                 for (x = panel_col_min; x <= panel_col_max; x++)
2983                 {
2984                         cave_type *c_ptr;
2985
2986                         /* Require line of sight, unless "look" is "expanded" */
2987                         if (!expand_look && !player_has_los_bold(y, x)) continue;
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 = c_ptr->mimic ? c_ptr->mimic : f_info[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 }