OSDN Git Service

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