OSDN Git Service

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