OSDN Git Service

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