OSDN Git Service

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