OSDN Git Service

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