OSDN Git Service

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