OSDN Git Service

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