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