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         if (m_ptr->csleep)
1718         {
1719                 /* Wake it up */
1720                 m_ptr->csleep = 0;
1721                 if (!need_mproc(m_ptr)) mproc_remove(m_ptr->mproc_idx);
1722                 if (r_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
1723         }
1724
1725         /* Hack - Cancel any special player stealth magics. -LM- */
1726         if (p_ptr->special_defense & NINJA_S_STEALTH)
1727         {
1728                 set_superstealth(FALSE);
1729         }
1730
1731         /* Hurt it */
1732         m_ptr->hp -= dam;
1733
1734         /* It is dead now */
1735         if (m_ptr->hp < 0)
1736         {
1737                 char m_name[80];
1738
1739                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1740                 {
1741                         /* You might have unmasked Tanuki first time */
1742                         r_ptr = &r_info[m_ptr->r_idx];
1743                         m_ptr->ap_r_idx = m_ptr->r_idx;
1744                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1745                 }
1746
1747                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1748                 {
1749                         /* You might have unmasked Chameleon first time */
1750                         r_ptr = real_r_ptr(m_ptr);
1751                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1752                 }
1753
1754                 if (!(m_ptr->smart & SM_CLONED))
1755                 {
1756                         /* When the player kills a Unique, it stays dead */
1757                         if (r_ptr->flags1 & RF1_UNIQUE)
1758                         {
1759                                 r_ptr->max_num = 0;
1760
1761                                 /* Mega-Hack -- Banor & Lupart */
1762                                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1763                                 {
1764                                         r_info[MON_BANORLUPART].max_num = 0;
1765                                         r_info[MON_BANORLUPART].r_pkills++;
1766                                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1767                                 }
1768                                 else if (m_ptr->r_idx == MON_BANORLUPART)
1769                                 {
1770                                         r_info[MON_BANOR].max_num = 0;
1771                                         r_info[MON_BANOR].r_pkills++;
1772                                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1773                                         r_info[MON_LUPART].max_num = 0;
1774                                         r_info[MON_LUPART].r_pkills++;
1775                                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1776                                 }
1777                         }
1778
1779                         /* When the player kills a Nazgul, it stays dead */
1780                         else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1781                 }
1782
1783                 /* Recall even invisible uniques or winners */
1784                 if (m_ptr->ml || (r_ptr->flags1 & RF1_UNIQUE))
1785                 {
1786                         /* Count kills this life */
1787                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1788                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1789
1790                         /* Count kills in all lives */
1791                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1792                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1793
1794                         /* Hack -- Auto-recall */
1795                         monster_race_track(m_ptr->ap_r_idx);
1796                 }
1797
1798                 /* Extract monster name */
1799                 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1800
1801                 /* Don't kill Amberites */
1802                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1803                 {
1804                         int curses = 1 + randint1(3);
1805                         bool stop_ty = FALSE;
1806                         int count = 0;
1807
1808 #ifdef JP
1809 msg_format("%^s¤Ï¶²¤í¤·¤¤·ì¤Î¼ö¤¤¤ò¤¢¤Ê¤¿¤Ë¤«¤±¤¿¡ª", m_name);
1810 #else
1811                         msg_format("%^s puts a terrible blood curse on you!", m_name);
1812 #endif
1813
1814                         curse_equipment(100, 50);
1815
1816                         do
1817                         {
1818                                 stop_ty = activate_ty_curse(stop_ty, &count);
1819                         }
1820                         while (--curses);
1821                 }
1822
1823                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1824                 {
1825                         char line_got[1024];
1826
1827                         /* Dump a message */
1828 #ifdef JP
1829                         if (!get_rnd_line("mondeath_j.txt", m_ptr->r_idx, line_got))
1830 #else
1831                         if (!get_rnd_line("mondeath.txt", m_ptr->r_idx, line_got))
1832 #endif
1833
1834                                 msg_format("%^s %s", m_name, line_got);
1835
1836 #ifdef WORLD_SCORE
1837                         if (m_ptr->r_idx == MON_SERPENT)
1838                         {
1839                                 /* Make screen dump */
1840                                 screen_dump = make_screen_dump();
1841                         }
1842 #endif
1843                 }
1844
1845                 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1846                 {
1847                         if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
1848                         {
1849                                 chg_virtue(V_VALOUR, -1);
1850                         }
1851                         else if (r_ptr->level > dun_level)
1852                         {
1853                                 if (randint1(10) <= (r_ptr->level - dun_level))
1854                                         chg_virtue(V_VALOUR, 1);
1855                         }
1856                         if (r_ptr->level > 60)
1857                         {
1858                                 chg_virtue(V_VALOUR, 1);
1859                         }
1860                         if (r_ptr->level >= 2 * (p_ptr->lev+1))
1861                                 chg_virtue(V_VALOUR, 2);
1862                 }
1863
1864                 if (r_ptr->flags1 & RF1_UNIQUE)
1865                 {
1866                         if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1867
1868                         if (r_ptr->flags3 & RF3_GOOD)
1869                         {
1870                                 chg_virtue(V_UNLIFE, 2);
1871                                 chg_virtue(V_VITALITY, -2);
1872                         }
1873
1874                         if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1875                 }
1876
1877                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1878                 {
1879                         chg_virtue(V_COMPASSION, -1);
1880                 }
1881
1882                 if ((r_ptr->flags3 & RF3_GOOD) &&
1883                         ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
1884                         chg_virtue(V_UNLIFE, 1);
1885
1886                 if (r_ptr->d_char == 'A')
1887                 {
1888                         if (r_ptr->flags1 & RF1_UNIQUE)
1889                                 chg_virtue(V_FAITH, -2);
1890                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1891                         {
1892                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1893                                 else chg_virtue(V_FAITH, 1);
1894                         }
1895                 }
1896                 else if (r_ptr->flags3 & RF3_DEMON)
1897                 {
1898                         if (r_ptr->flags1 & RF1_UNIQUE)
1899                                 chg_virtue(V_FAITH, 2);
1900                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1901                                 chg_virtue(V_FAITH, 1);
1902                 }
1903
1904                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1905                         chg_virtue(V_VITALITY, 2);
1906
1907                 if (r_ptr->r_deaths)
1908                 {
1909                         if (r_ptr->flags1 & RF1_UNIQUE)
1910                         {
1911                                 chg_virtue(V_HONOUR, 10);
1912                         }
1913                         else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
1914                         {
1915                                 chg_virtue(V_HONOUR, 1);
1916                         }
1917                 }
1918                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_pkills > 1000) && one_in_(10))
1919                 {
1920                         chg_virtue(V_VALOUR, -1);
1921                 }
1922
1923                 for (i = 0; i < 4; i++)
1924                 {
1925                         if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1926
1927                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1928                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1929
1930                                 thief = TRUE; /* Thief! */
1931                 }
1932
1933                 /* The new law says it is illegal to live in the dungeon */
1934                 if (r_ptr->level != 0) innocent = FALSE;
1935
1936                 if (thief)
1937                 {
1938                         if (r_ptr->flags1 & RF1_UNIQUE)
1939                                 chg_virtue(V_JUSTICE, 3);
1940                         else if (1+((r_ptr->level) / 10 + (2 * dun_level))
1941                                 >= randint1(100))
1942                                 chg_virtue(V_JUSTICE, 1);
1943                 }
1944                 else if (innocent)
1945                 {
1946                         chg_virtue (V_JUSTICE, -1);
1947                 }
1948
1949                 if ((r_ptr->flags3 & RF3_ANIMAL) && !(r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags4 & ~(RF4_NOMAGIC_MASK))  && !(r_ptr->flags5 & ~(RF5_NOMAGIC_MASK)) && !(r_ptr->flags6 & ~(RF6_NOMAGIC_MASK)))
1950                 {
1951                         if (one_in_(4)) chg_virtue(V_NATURE, -1);
1952                 }
1953
1954                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
1955                 {
1956                         char note_buf[160];
1957 #ifdef JP
1958                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? "(¥¯¥í¡¼¥ó)" : "");
1959 #else
1960                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? "(Clone)" : "");
1961 #endif
1962                         do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
1963                 }
1964
1965                 /* Make a sound */
1966                 sound(SOUND_KILL);
1967
1968                 /* Death by Missile/Spell attack */
1969                 if (note)
1970                 {
1971                         msg_format("%^s%s", m_name, note);
1972                 }
1973
1974                 /* Death by physical attack -- invisible monster */
1975                 else if (!m_ptr->ml)
1976                 {
1977 #ifdef JP
1978                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1979                                 msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤ò»¦¤·¤¿¡£", m_name);
1980                         else
1981 msg_format("%s¤ò»¦¤·¤¿¡£", m_name);
1982 #else
1983                                 msg_format("You have killed %s.", m_name);
1984 #endif
1985
1986                 }
1987
1988                 /* Death by Physical attack -- non-living monster */
1989                 else if (!monster_living(r_ptr))
1990                 {
1991                         int i;
1992                         bool explode = FALSE;
1993
1994                         for (i = 0; i < 4; i++)
1995                         {
1996                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1997                         }
1998
1999                         /* Special note at death */
2000                         if (explode)
2001 #ifdef JP
2002 msg_format("%s¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_name);
2003 #else
2004                                 msg_format("%s explodes into tiny shreds.", m_name);
2005 #endif
2006                         else
2007                         {
2008 #ifdef JP
2009                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2010                                         msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤òÅݤ·¤¿¡£", m_name);
2011                                 else
2012 msg_format("%s¤òÅݤ·¤¿¡£", m_name);
2013 #else
2014                                 msg_format("You have destroyed %s.", m_name);
2015 #endif
2016                         }
2017                 }
2018
2019                 /* Death by Physical attack -- living monster */
2020                 else
2021                 {
2022 #ifdef JP
2023                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2024                                 msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤òÁò¤êµî¤Ã¤¿¡£", m_name);
2025                         else
2026 msg_format("%s¤òÁò¤êµî¤Ã¤¿¡£", m_name);
2027 #else
2028                                 msg_format("You have slain %s.", m_name);
2029 #endif
2030
2031                 }
2032                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
2033                 {
2034                         for (i = 0; i < MAX_KUBI; i++)
2035                         {
2036                                 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
2037                                 {
2038 #ifdef JP
2039 msg_format("%s¤Î¼ó¤Ë¤Ï¾Þ¶â¤¬¤«¤«¤Ã¤Æ¤¤¤ë¡£", m_name);
2040 #else
2041                                         msg_format("There is a price on %s's head.", m_name);
2042 #endif
2043                                         break;
2044                                 }
2045                         }
2046                 }
2047
2048                 /* Generate treasure */
2049                 monster_death(m_idx, TRUE);
2050
2051                 /* Mega hack : replace IKETA to BIKETAL */
2052                 if ((m_ptr->r_idx == MON_IKETA) &&
2053                     !(p_ptr->inside_arena || p_ptr->inside_battle))
2054                 {
2055                         int dummy_y = m_ptr->fy;
2056                         int dummy_x = m_ptr->fx;
2057                         u32b mode = 0L;
2058
2059                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
2060
2061                         /* Delete the monster */
2062                         delete_monster_idx(m_idx);
2063
2064                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
2065                         {
2066 #ifdef JP
2067                                 msg_print("¡Ö¥Ï¥¡¥Ã¥Ï¥Ã¥Ï¥Ã¥Ï¡ª¡ª»ä¤¬¥Ð¥¤¥±¥¿¥ë¤À¡ª¡ª¡×");
2068 #else
2069                                 msg_print("Uwa-hahaha!  *I* am Biketal!");
2070 #endif
2071                         }
2072                 }
2073                 else
2074                 {
2075                         /* Delete the monster */
2076                         delete_monster_idx(m_idx);
2077                 }
2078
2079                 /* Prevent bug of chaos patron's reward */
2080                 if (r_ptr->flags7 & RF7_KILL_EXP)
2081                         get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
2082                 else
2083                         get_exp_from_mon(((long)exp_mon.max_maxhp+1L) * 9L / 10L, &exp_mon);
2084
2085                 /* Not afraid */
2086                 (*fear) = FALSE;
2087
2088                 /* Monster is dead */
2089                 return (TRUE);
2090         }
2091
2092
2093 #ifdef ALLOW_FEAR
2094
2095         /* Mega-Hack -- Pain cancels fear */
2096         if (m_ptr->monfear && (dam > 0))
2097         {
2098                 int tmp = randint1(dam);
2099
2100                 /* Cure a little fear */
2101                 if (tmp < m_ptr->monfear)
2102                 {
2103                         /* Reduce fear */
2104                         m_ptr->monfear -= tmp;
2105                 }
2106
2107                 /* Cure all the fear */
2108                 else
2109                 {
2110                         /* Cure fear */
2111                         m_ptr->monfear = 0;
2112                         if (!need_mproc(m_ptr)) mproc_remove(m_ptr->mproc_idx);
2113
2114                         /* No more fear */
2115                         (*fear) = FALSE;
2116                 }
2117         }
2118
2119         /* Sometimes a monster gets scared by damage */
2120         if (!m_ptr->monfear && !(r_ptr->flags3 & (RF3_NO_FEAR)))
2121         {
2122                 int percentage;
2123
2124                 /* Percentage of fully healthy */
2125                 percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
2126
2127                 /*
2128                  * Run (sometimes) if at 10% or less of max hit points,
2129                  * or (usually) when hit for half its current hit points
2130                  */
2131                 if ((randint1(10) >= percentage) ||
2132                     ((dam >= m_ptr->hp) && (randint0(100) < 80)))
2133                 {
2134                         /* Hack -- note fear */
2135                         (*fear) = TRUE;
2136
2137                         if (!m_ptr->mproc_idx) mproc_add(m_idx);
2138
2139                         /* XXX XXX XXX Hack -- Add some timed fear */
2140                         m_ptr->monfear = (randint1(10) +
2141                                           (((dam >= m_ptr->hp) && (percentage > 7)) ?
2142                                            20 : ((11 - percentage) * 5)));
2143                 }
2144         }
2145
2146 #endif
2147
2148 #if 0
2149         if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
2150         {
2151                 char m_name[80];
2152
2153                 /* Extract monster name */
2154                 monster_desc(m_name, m_ptr, 0);
2155
2156                 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
2157                 if (rakuba((dam > 200) ? 200 : dam, FALSE))
2158                 {
2159 #ifdef JP
2160 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
2161 #else
2162                                 msg_format("%^s has thrown you off!", m_name);
2163 #endif
2164                 }
2165         }
2166 #endif
2167
2168         /* Not dead yet */
2169         return (FALSE);
2170 }
2171
2172
2173 /*
2174  * Get term size and calculate screen size
2175  */
2176 void get_screen_size(int *wid_p, int *hgt_p)
2177 {
2178         Term_get_size(wid_p, hgt_p);
2179         *hgt_p -= ROW_MAP + 2;
2180         *wid_p -= COL_MAP + 2;
2181         if (use_bigtile) *wid_p /= 2;
2182 }
2183
2184
2185 /*
2186  * Calculates current boundaries
2187  * Called below and from "do_cmd_locate()".
2188  */
2189 void panel_bounds_center(void)
2190 {
2191         int wid, hgt;
2192
2193         /* Get size */
2194         get_screen_size(&wid, &hgt);
2195
2196         panel_row_max = panel_row_min + hgt - 1;
2197         panel_row_prt = panel_row_min - 1;
2198         panel_col_max = panel_col_min + wid - 1;
2199         panel_col_prt = panel_col_min - 13;
2200 }
2201
2202
2203 /*
2204  * Map resizing whenever the main term changes size
2205  */
2206 void resize_map(void)
2207 {
2208         /* Only if the dungeon exists */
2209         if (!character_dungeon) return;
2210         
2211         /* Mega-Hack -- no panel yet */
2212         panel_row_max = 0;
2213         panel_col_max = 0;
2214
2215         /* Reset the panels */
2216         panel_row_min = cur_hgt;
2217         panel_col_min = cur_wid;
2218                                 
2219         verify_panel();
2220
2221         /* Update stuff */
2222         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
2223
2224         /* Forget lite/view */
2225         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
2226
2227         /* Update lite/view */
2228         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
2229
2230         /* Update monsters */
2231         p_ptr->update |= (PU_MONSTERS);
2232
2233         /* Redraw everything */
2234         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
2235
2236         /* Hack -- update */
2237         handle_stuff();
2238         
2239         /* Redraw */
2240         Term_redraw();
2241
2242         /*
2243          * Waiting command;
2244          * Place the cursor on the player
2245          */
2246         if (can_save) move_cursor_relative(py, px);
2247
2248         /* Refresh */
2249         Term_fresh();
2250 }
2251
2252 /*
2253  * Redraw a term when it is resized
2254  */
2255 void redraw_window(void)
2256 {
2257         /* Only if the dungeon exists */
2258         if (!character_dungeon) return;
2259         
2260         /* Hack - Activate term zero for the redraw */
2261         Term_activate(&term_screen[0]);
2262         
2263         /* Hack -- react to changes */
2264         Term_xtra(TERM_XTRA_REACT, 0);
2265
2266         /* Window stuff */
2267         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
2268
2269         /* Window stuff */
2270         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
2271
2272         /* Hack -- update */
2273         handle_stuff();
2274
2275         /* Redraw */
2276         Term_redraw();
2277
2278         /* Refresh */
2279         Term_fresh();
2280 }
2281
2282
2283 /*
2284  * Handle a request to change the current panel
2285  *
2286  * Return TRUE if the panel was changed.
2287  *
2288  * Also used in do_cmd_locate
2289  */
2290 bool change_panel(int dy, int dx)
2291 {
2292         int y, x;
2293         int wid, hgt;
2294
2295         /* Get size */
2296         get_screen_size(&wid, &hgt);
2297
2298         /* Apply the motion */
2299         y = panel_row_min + dy * hgt / 2;
2300         x = panel_col_min + dx * wid / 2;
2301
2302         /* Verify the row */
2303         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
2304         if (y < 0) y = 0;
2305
2306         /* Verify the col */
2307         if (x > cur_wid - wid) x = cur_wid - wid;
2308         if (x < 0) x = 0;
2309
2310         /* Handle "changes" */
2311         if ((y != panel_row_min) || (x != panel_col_min))
2312         {
2313                 /* Save the new panel info */
2314                 panel_row_min = y;
2315                 panel_col_min = x;
2316
2317                 /* Recalculate the boundaries */
2318                 panel_bounds_center();
2319
2320                 /* Update stuff */
2321                 p_ptr->update |= (PU_MONSTERS);
2322
2323                 /* Redraw map */
2324                 p_ptr->redraw |= (PR_MAP);
2325
2326                 /* Handle stuff */
2327                 handle_stuff();
2328
2329                 /* Success */
2330                 return (TRUE);
2331         }
2332
2333         /* No change */
2334         return (FALSE);
2335 }
2336
2337
2338 /*
2339  * Given an row (y) and col (x), this routine detects when a move
2340  * off the screen has occurred and figures new borders. -RAK-
2341  *
2342  * "Update" forces a "full update" to take place.
2343  *
2344  * The map is reprinted if necessary, and "TRUE" is returned.
2345  */
2346 void verify_panel(void)
2347 {
2348         int y = py;
2349         int x = px;
2350         int wid, hgt;
2351
2352         int prow_min;
2353         int pcol_min;
2354         int max_prow_min;
2355         int max_pcol_min;
2356
2357         /* Get size */
2358         get_screen_size(&wid, &hgt);
2359
2360         max_prow_min = cur_hgt - hgt;
2361         max_pcol_min = cur_wid - wid;
2362
2363         /* Bounds checking */
2364         if (max_prow_min < 0) max_prow_min = 0;
2365         if (max_pcol_min < 0) max_pcol_min = 0;
2366
2367                 /* Center on player */
2368         if (center_player && (center_running || !running))
2369         {
2370                 /* Center vertically */
2371                 prow_min = y - hgt / 2;
2372                 if (prow_min < 0) prow_min = 0;
2373                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
2374
2375                 /* Center horizontally */
2376                 pcol_min = x - wid / 2;
2377                 if (pcol_min < 0) pcol_min = 0;
2378                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2379         }
2380         else
2381         {
2382                 prow_min = panel_row_min;
2383                 pcol_min = panel_col_min;
2384
2385                 /* Scroll screen when 2 grids from top/bottom edge */
2386                 if (y > panel_row_max - 2)
2387                 {
2388                         while (y > prow_min + hgt-1 - 2)
2389                         {
2390                                 prow_min += (hgt / 2);
2391                         }
2392                 }
2393
2394                 if (y < panel_row_min + 2)
2395                 {
2396                         while (y < prow_min + 2)
2397                         {
2398                                 prow_min -= (hgt / 2);
2399                         }
2400                 }
2401
2402                 if (prow_min > max_prow_min) prow_min = max_prow_min;
2403                 if (prow_min < 0) prow_min = 0;
2404
2405                 /* Scroll screen when 4 grids from left/right edge */
2406                 if (x > panel_col_max - 4)
2407                 {
2408                         while (x > pcol_min + wid-1 - 4)
2409                         {
2410                                 pcol_min += (wid / 2);
2411                         }
2412                 }
2413                 
2414                 if (x < panel_col_min + 4)
2415                 {
2416                         while (x < pcol_min + 4)
2417                         {
2418                                 pcol_min -= (wid / 2);
2419                         }
2420                 }
2421
2422                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2423                 if (pcol_min < 0) pcol_min = 0;
2424         }
2425
2426         /* Check for "no change" */
2427         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
2428
2429         /* Save the new panel info */
2430         panel_row_min = prow_min;
2431         panel_col_min = pcol_min;
2432
2433         /* Hack -- optional disturb on "panel change" */
2434         if (disturb_panel && !center_player) disturb(0, 0);
2435
2436         /* Recalculate the boundaries */
2437         panel_bounds_center();
2438
2439         /* Update stuff */
2440         p_ptr->update |= (PU_MONSTERS);
2441
2442         /* Redraw map */
2443         p_ptr->redraw |= (PR_MAP);
2444
2445         /* Window stuff */
2446         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2447 }
2448
2449
2450 /*
2451  * Monster health description
2452  */
2453 cptr look_mon_desc(monster_type *m_ptr, u32b mode)
2454 {
2455         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2456         bool         living;
2457         int          perc;
2458         cptr desc;
2459         cptr attitude;
2460         cptr clone;
2461
2462         /* Determine if the monster is "living" */
2463         living = monster_living(ap_r_ptr);
2464
2465         /* Calculate a health "percentage" */
2466         perc = 100L * m_ptr->hp / m_ptr->maxhp;
2467
2468         /* Healthy monsters */
2469         if (m_ptr->hp >= m_ptr->maxhp)
2470         {
2471                 /* No damage */
2472 #ifdef JP
2473                 desc = living ? "̵½ý" : "̵¥À¥á¡¼¥¸";
2474 #else
2475                 desc = living ? "unhurt" : "undamaged";
2476 #endif
2477
2478         }
2479
2480         else if (perc >= 60)
2481         {
2482 #ifdef JP
2483                 desc = living ? "·Ú½ý" : "¾®¥À¥á¡¼¥¸";
2484 #else
2485                 desc = living ? "somewhat wounded" : "somewhat damaged";
2486 #endif
2487
2488         }
2489
2490         else if (perc >= 25)
2491         {
2492 #ifdef JP
2493                 desc = living ? "Éé½ý" : "Ãæ¥À¥á¡¼¥¸";
2494 #else
2495                 desc = living ? "wounded" : "damaged";
2496 #endif
2497
2498         }
2499
2500         else if (perc >= 10)
2501         {
2502 #ifdef JP
2503                 desc = living ? "½Å½ý" : "Âç¥À¥á¡¼¥¸";
2504 #else
2505                 desc = living ? "badly wounded" : "badly damaged";
2506 #endif
2507
2508         }
2509
2510         else 
2511         {
2512 #ifdef JP
2513                 desc = living ? "Ⱦ»àȾÀ¸" : "Åݤ줫¤±";
2514 #else
2515                 desc = living ? "almost dead" : "almost destroyed";
2516 #endif
2517         }
2518
2519
2520         /* Need attitude information? */
2521         if (!(mode & 0x01))
2522         {
2523                 /* Full information is not needed */
2524                 attitude = "";
2525         }
2526         else if (is_pet(m_ptr))
2527         {
2528 #ifdef JP
2529                 attitude = ", ¥Ú¥Ã¥È";
2530 #else
2531                 attitude = ", pet";
2532 #endif
2533         }
2534         else if (is_friendly(m_ptr))
2535         {
2536 #ifdef JP
2537                 attitude = ", Í§¹¥Åª";
2538 #else
2539                 attitude = ", friendly";
2540 #endif
2541         }
2542         else
2543         {
2544 #ifdef JP
2545                 attitude = "";
2546 #else
2547                 attitude = "";
2548 #endif
2549         }
2550
2551
2552         /* Clone monster? */
2553         if (m_ptr->smart & SM_CLONED)
2554         {
2555                 clone = ", clone";
2556         }
2557         else
2558         {
2559                 clone = "";
2560         }
2561
2562         /* Display monster's level --- idea borrowed from ToME */
2563         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
2564         {
2565 #ifdef JP
2566                 return format("¥ì¥Ù¥ë%d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2567 #else
2568                 return format("Level %d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2569 #endif
2570         }
2571         else 
2572         {
2573 #ifdef JP
2574                 return format("¥ì¥Ù¥ë???, %s%s%s", desc, attitude, clone);
2575 #else
2576                 return format("Level ???, %s%s%s", desc, attitude, clone);
2577 #endif
2578         }
2579 }
2580
2581
2582
2583 /*
2584  * Angband sorting algorithm -- quick sort in place
2585  *
2586  * Note that the details of the data we are sorting is hidden,
2587  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2588  * function hooks to interact with the data, which is given as
2589  * two pointers, and which may have any user-defined form.
2590  */
2591 void ang_sort_aux(vptr u, vptr v, int p, int q)
2592 {
2593         int z, a, b;
2594
2595         /* Done sort */
2596         if (p >= q) return;
2597
2598         /* Pivot */
2599         z = p;
2600
2601         /* Begin */
2602         a = p;
2603         b = q;
2604
2605         /* Partition */
2606         while (TRUE)
2607         {
2608                 /* Slide i2 */
2609                 while (!(*ang_sort_comp)(u, v, b, z)) b--;
2610
2611                 /* Slide i1 */
2612                 while (!(*ang_sort_comp)(u, v, z, a)) a++;
2613
2614                 /* Done partition */
2615                 if (a >= b) break;
2616
2617                 /* Swap */
2618                 (*ang_sort_swap)(u, v, a, b);
2619
2620                 /* Advance */
2621                 a++, b--;
2622         }
2623
2624         /* Recurse left side */
2625         ang_sort_aux(u, v, p, b);
2626
2627         /* Recurse right side */
2628         ang_sort_aux(u, v, b+1, q);
2629 }
2630
2631
2632 /*
2633  * Angband sorting algorithm -- quick sort in place
2634  *
2635  * Note that the details of the data we are sorting is hidden,
2636  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2637  * function hooks to interact with the data, which is given as
2638  * two pointers, and which may have any user-defined form.
2639  */
2640 void ang_sort(vptr u, vptr v, int n)
2641 {
2642         /* Sort the array */
2643         ang_sort_aux(u, v, 0, n-1);
2644 }
2645
2646
2647
2648 /*** Targeting Code ***/
2649
2650
2651 /*
2652  * Determine is a monster makes a reasonable target
2653  *
2654  * The concept of "targeting" was stolen from "Morgul" (?)
2655  *
2656  * The player can target any location, or any "target-able" monster.
2657  *
2658  * Currently, a monster is "target_able" if it is visible, and if
2659  * the player can hit it with a projection, and the player is not
2660  * hallucinating.  This allows use of "use closest target" macros.
2661  *
2662  * Future versions may restrict the ability to target "trappers"
2663  * and "mimics", but the semantics is a little bit weird.
2664  */
2665 bool target_able(int m_idx)
2666 {
2667         monster_type *m_ptr = &m_list[m_idx];
2668
2669         /* Monster must be alive */
2670         if (!m_ptr->r_idx) return (FALSE);
2671
2672         /* Hack -- no targeting hallucinations */
2673         if (p_ptr->image) return (FALSE);
2674
2675         /* Monster must be visible */
2676         if (!m_ptr->ml) return (FALSE);
2677
2678         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
2679
2680         /* Monster must be projectable */
2681         if (!projectable(py, px, m_ptr->fy, m_ptr->fx)) return (FALSE);
2682
2683         /* XXX XXX XXX Hack -- Never target trappers */
2684         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
2685
2686         /* Assume okay */
2687         return (TRUE);
2688 }
2689
2690
2691
2692
2693 /*
2694  * Update (if necessary) and verify (if possible) the target.
2695  *
2696  * We return TRUE if the target is "okay" and FALSE otherwise.
2697  */
2698 bool target_okay(void)
2699 {
2700         /* Accept stationary targets */
2701         if (target_who < 0) return (TRUE);
2702
2703         /* Check moving targets */
2704         if (target_who > 0)
2705         {
2706                 /* Accept reasonable targets */
2707                 if (target_able(target_who))
2708                 {
2709                         monster_type *m_ptr = &m_list[target_who];
2710
2711                         /* Acquire monster location */
2712                         target_row = m_ptr->fy;
2713                         target_col = m_ptr->fx;
2714
2715                         /* Good target */
2716                         return (TRUE);
2717                 }
2718         }
2719
2720         /* Assume no target */
2721         return (FALSE);
2722 }
2723
2724
2725
2726 /*
2727  * Sorting hook -- comp function -- by "distance to player"
2728  *
2729  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2730  * and sort the arrays by double-distance to the player.
2731  */
2732 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
2733 {
2734         byte *x = (byte*)(u);
2735         byte *y = (byte*)(v);
2736
2737         int da, db, kx, ky;
2738
2739         /* Absolute distance components */
2740         kx = x[a]; kx -= px; kx = ABS(kx);
2741         ky = y[a]; ky -= py; ky = ABS(ky);
2742
2743         /* Approximate Double Distance to the first point */
2744         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2745
2746         /* Absolute distance components */
2747         kx = x[b]; kx -= px; kx = ABS(kx);
2748         ky = y[b]; ky -= py; ky = ABS(ky);
2749
2750         /* Approximate Double Distance to the first point */
2751         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2752
2753         /* Compare the distances */
2754         return (da <= db);
2755 }
2756
2757
2758 /*
2759  * Sorting hook -- swap function -- by "distance to player"
2760  *
2761  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2762  * and sort the arrays by distance to the player.
2763  */
2764 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
2765 {
2766         byte *x = (byte*)(u);
2767         byte *y = (byte*)(v);
2768
2769         byte temp;
2770
2771         /* Swap "x" */
2772         temp = x[a];
2773         x[a] = x[b];
2774         x[b] = temp;
2775
2776         /* Swap "y" */
2777         temp = y[a];
2778         y[a] = y[b];
2779         y[b] = temp;
2780 }
2781
2782
2783
2784 /*
2785  * Hack -- help "select" a location (see below)
2786  */
2787 static s16b target_pick(int y1, int x1, int dy, int dx)
2788 {
2789         int i, v;
2790
2791         int x2, y2, x3, y3, x4, y4;
2792
2793         int b_i = -1, b_v = 9999;
2794
2795
2796         /* Scan the locations */
2797         for (i = 0; i < temp_n; i++)
2798         {
2799                 /* Point 2 */
2800                 x2 = temp_x[i];
2801                 y2 = temp_y[i];
2802
2803                 /* Directed distance */
2804                 x3 = (x2 - x1);
2805                 y3 = (y2 - y1);
2806
2807                 /* Verify quadrant */
2808                 if (dx && (x3 * dx <= 0)) continue;
2809                 if (dy && (y3 * dy <= 0)) continue;
2810
2811                 /* Absolute distance */
2812                 x4 = ABS(x3);
2813                 y4 = ABS(y3);
2814
2815                 /* Verify quadrant */
2816                 if (dy && !dx && (x4 > y4)) continue;
2817                 if (dx && !dy && (y4 > x4)) continue;
2818
2819                 /* Approximate Double Distance */
2820                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
2821
2822                 /* XXX XXX XXX Penalize location */
2823
2824                 /* Track best */
2825                 if ((b_i >= 0) && (v >= b_v)) continue;
2826
2827                 /* Track best */
2828                 b_i = i; b_v = v;
2829         }
2830
2831         /* Result */
2832         return (b_i);
2833 }
2834
2835
2836 /*
2837  * Hack -- determine if a given location is "interesting"
2838  */
2839 static bool target_set_accept(int y, int x)
2840 {
2841         cave_type *c_ptr;
2842
2843         s16b this_o_idx, next_o_idx = 0;
2844
2845         /* Bounds */
2846         if (!(in_bounds(y, x))) return (FALSE);
2847
2848         /* Player grid is always interesting */
2849         if (player_bold(y, x)) return (TRUE);
2850
2851
2852         /* Handle hallucination */
2853         if (p_ptr->image) return (FALSE);
2854
2855
2856         /* Examine the grid */
2857         c_ptr = &cave[y][x];
2858
2859         /* Visible monsters */
2860         if (c_ptr->m_idx)
2861         {
2862                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2863
2864                 /* Visible monsters */
2865                 if (m_ptr->ml) return (TRUE);
2866         }
2867
2868         /* Scan all objects in the grid */
2869         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2870         {
2871                 object_type *o_ptr;
2872
2873                 /* Acquire object */
2874                 o_ptr = &o_list[this_o_idx];
2875
2876                 /* Acquire next object */
2877                 next_o_idx = o_ptr->next_o_idx;
2878
2879                 /* Memorized object */
2880                 if (o_ptr->marked & OM_FOUND) return (TRUE);
2881         }
2882
2883         /* Interesting memorized features */
2884         if (c_ptr->info & (CAVE_MARK))
2885         {
2886                 /* Notice object features */
2887                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
2888
2889                 /* Feature code (applying "mimic" field) */
2890                 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
2891         }
2892
2893         /* Nope */
2894         return (FALSE);
2895 }
2896
2897
2898 /*
2899  * Prepare the "temp" array for "target_set"
2900  *
2901  * Return the number of target_able monsters in the set.
2902  */
2903 static void target_set_prepare(int mode)
2904 {
2905         int y, x;
2906
2907         /* Reset "temp" array */
2908         temp_n = 0;
2909
2910         /* Scan the current panel */
2911         for (y = panel_row_min; y <= panel_row_max; y++)
2912         {
2913                 for (x = panel_col_min; x <= panel_col_max; x++)
2914                 {
2915                         cave_type *c_ptr;
2916
2917                         /* Require "interesting" contents */
2918                         if (!target_set_accept(y, x)) continue;
2919
2920                         c_ptr = &cave[y][x];
2921
2922                         /* Require target_able monsters for "TARGET_KILL" */
2923                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
2924
2925                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
2926
2927                         /* Save the location */
2928                         temp_x[temp_n] = x;
2929                         temp_y[temp_n] = y;
2930                         temp_n++;
2931                 }
2932         }
2933
2934         /* Set the sort hooks */
2935         ang_sort_comp = ang_sort_comp_distance;
2936         ang_sort_swap = ang_sort_swap_distance;
2937
2938         /* Sort the positions */
2939         ang_sort(temp_x, temp_y, temp_n);
2940
2941         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
2942         {
2943                 byte tmp;
2944
2945                 tmp = temp_y[0];
2946                 temp_y[0] = temp_y[1];
2947                 temp_y[1] = tmp;
2948                 tmp = temp_x[0];
2949                 temp_x[0] = temp_x[1];
2950                 temp_x[1] = tmp;
2951         }
2952 }
2953
2954
2955 /*
2956  * Evaluate number of kill needed to gain level
2957  */
2958 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
2959 {
2960         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2961         u32b num;
2962         s32b exp_mon, exp_adv;
2963         u32b exp_mon_frac, exp_adv_frac;
2964
2965         if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
2966         {
2967                 sprintf(buf,"**");
2968                 return;
2969         }
2970         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
2971         {
2972                 if (!p_ptr->wizard)
2973                 {
2974                         sprintf(buf,"??");
2975                         return;
2976                 }
2977         }
2978
2979
2980         /* The monster's experience point (assuming average monster speed) */
2981         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
2982         exp_mon_frac = 0;
2983         s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
2984
2985
2986         /* Total experience value for next level */
2987         exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
2988         exp_adv_frac = 0;
2989         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
2990
2991         /* Experience value need to get */
2992         s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
2993
2994
2995         /* You need to kill at least one monster to get any experience */
2996         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
2997         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
2998
2999         /* Extract number of monsters needed */
3000         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
3001
3002         /* If 999 or more monsters needed, only display "999". */
3003         num = MIN(999, exp_adv_frac);
3004
3005         /* Display the number */
3006         sprintf(buf,"%03ld", num);
3007 }
3008
3009
3010 /*
3011  * Examine a grid, return a keypress.
3012  *
3013  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
3014  * indicates that the "space" key should scan through the contents
3015  * of the grid, instead of simply returning immediately.  This lets
3016  * the "look" command get complete information, without making the
3017  * "target" command annoying.
3018  *
3019  * The "info" argument contains the "commands" which should be shown
3020  * inside the "[xxx]" text.  This string must never be empty, or grids
3021  * containing monsters will be displayed with an extra comma.
3022  *
3023  * Note that if a monster is in the grid, we update both the monster
3024  * recall info and the health bar info to track that monster.
3025  *
3026  * Eventually, we may allow multiple objects per grid, or objects
3027  * and terrain features in the same grid. XXX XXX XXX
3028  *
3029  * This function must handle blindness/hallucination.
3030  */
3031 static int target_set_aux(int y, int x, int mode, cptr info)
3032 {
3033         cave_type *c_ptr = &cave[y][x];
3034         s16b this_o_idx, next_o_idx = 0;
3035         cptr s1 = "", s2 = "", s3 = "", x_info = "";
3036         bool boring = TRUE;
3037         s16b feat;
3038         feature_type *f_ptr;
3039         int query = '\001';
3040         char out_val[MAX_NLEN+80];
3041
3042 #ifdef ALLOW_EASY_FLOOR
3043         int floor_list[23], floor_num = 0;
3044
3045         /* Scan all objects in the grid */
3046         if (easy_floor)
3047         {
3048                 floor_num = scan_floor(floor_list, y, x, 0x02);
3049
3050                 if (floor_num)
3051                 {
3052 #ifdef JP
3053                         x_info = "xʪ ";
3054 #else
3055                         x_info = "x,";
3056 #endif
3057                 }
3058         }
3059
3060 #endif /* ALLOW_EASY_FLOOR */
3061
3062         /* Hack -- under the player */
3063         if (player_bold(y, x))
3064         {
3065                 /* Description */
3066 #ifdef JP
3067                 s1 = "¤¢¤Ê¤¿¤Ï";
3068                 s2 = "¤Î¾å";
3069                 s3 = "¤Ë¤¤¤ë";
3070 #else
3071                 s1 = "You are ";
3072
3073                 /* Preposition */
3074                 s2 = "on ";
3075 #endif
3076         }
3077         else
3078         {
3079 #ifdef JP
3080                 s1 = "¥¿¡¼¥²¥Ã¥È:";
3081 #else
3082                 s1 = "Target:";
3083 #endif
3084         }
3085
3086         /* Hack -- hallucination */
3087         if (p_ptr->image)
3088         {
3089 #ifdef JP
3090                 cptr name = "²¿¤«´ñ̯¤Êʪ";
3091 #else
3092                 cptr name = "something strange";
3093 #endif
3094
3095
3096                 /* Display a message */
3097 #ifdef JP
3098                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
3099 #else
3100                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3101 #endif
3102
3103                 prt(out_val, 0, 0);
3104                 move_cursor_relative(y, x);
3105                 query = inkey();
3106
3107                 /* Stop on everything but "return" */
3108                 if ((query != '\r') && (query != '\n')) return query;
3109
3110                 /* Repeat forever */
3111                 return 0;
3112         }
3113
3114
3115         /* Actual monsters */
3116         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
3117         {
3118                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
3119                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3120                 char m_name[80];
3121                 bool recall = FALSE;
3122
3123                 /* Not boring */
3124                 boring = FALSE;
3125
3126                 /* Get the monster name ("a kobold") */
3127                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
3128
3129                 /* Hack -- track this monster race */
3130                 monster_race_track(m_ptr->ap_r_idx);
3131
3132                 /* Hack -- health bar for this monster */
3133                 health_track(c_ptr->m_idx);
3134
3135                 /* Hack -- handle stuff */
3136                 handle_stuff();
3137
3138                 /* Interact */
3139                 while (1)
3140                 {
3141                         char acount[10];
3142
3143                         /* Recall */
3144                         if (recall)
3145                         {
3146                                 /* Save */
3147                                 screen_save();
3148
3149                                 /* Recall on screen */
3150                                 screen_roff(m_ptr->ap_r_idx, 0);
3151
3152                                 /* Hack -- Complete the prompt (again) */
3153 #ifdef JP
3154                                 Term_addstr(-1, TERM_WHITE, format("  [r»× %s%s]", x_info, info));
3155 #else
3156                                 Term_addstr(-1, TERM_WHITE, format("  [r,%s%s]", x_info, info));
3157 #endif
3158
3159                                 /* Command */
3160                                 query = inkey();
3161
3162                                 /* Restore */
3163                                 screen_load();
3164
3165                                 /* Normal commands */
3166                                 if (query != 'r') break;
3167
3168                                 /* Toggle recall */
3169                                 recall = FALSE;
3170
3171                                 /* Cleare recall text and repeat */
3172                                 continue;
3173                         }
3174
3175                         /*** Normal ***/
3176
3177                         /* Describe, and prompt for recall */
3178                         evaluate_monster_exp(acount, m_ptr);
3179
3180 #ifdef JP
3181                         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);
3182 #else
3183                         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);
3184 #endif
3185
3186                         prt(out_val, 0, 0);
3187
3188                         /* Place cursor */
3189                         move_cursor_relative(y, x);
3190
3191                         /* Command */
3192                         query = inkey();
3193
3194                         /* Normal commands */
3195                         if (query != 'r') break;
3196
3197                         /* Toggle recall */
3198                         recall = TRUE;
3199                 }
3200
3201                 /* Always stop at "normal" keys */
3202                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3203
3204                 /* Sometimes stop at "space" key */
3205                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3206
3207                 /* Change the intro */
3208 #ifdef JP
3209                 s1 = "¤½¤ì¤Ï";
3210 #else
3211                 s1 = "It is ";
3212 #endif
3213
3214
3215                 /* Hack -- take account of gender */
3216 #ifdef JP
3217                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = "Èà½÷¤Ï";
3218 #else
3219                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = "She is ";
3220 #endif
3221
3222 #ifdef JP
3223                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = "Èà¤Ï";
3224 #else
3225                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = "He is ";
3226 #endif
3227
3228
3229                 /* Use a preposition */
3230 #ifdef JP
3231                 s2 = "¤ò";
3232                 s3 = "»ý¤Ã¤Æ¤¤¤ë";
3233 #else
3234                 s2 = "carrying ";
3235 #endif
3236
3237
3238                 /* Scan all objects being carried */
3239                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3240                 {
3241                         char o_name[MAX_NLEN];
3242
3243                         object_type *o_ptr;
3244
3245                         /* Acquire object */
3246                         o_ptr = &o_list[this_o_idx];
3247
3248                         /* Acquire next object */
3249                         next_o_idx = o_ptr->next_o_idx;
3250
3251                         /* Obtain an object description */
3252                         object_desc(o_name, o_ptr, 0);
3253
3254                         /* Describe the object */
3255 #ifdef JP
3256                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3257 #else
3258                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3259 #endif
3260
3261                         prt(out_val, 0, 0);
3262                         move_cursor_relative(y, x);
3263                         query = inkey();
3264
3265                         /* Always stop at "normal" keys */
3266                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3267
3268                         /* Sometimes stop at "space" key */
3269                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3270
3271                         /* Change the intro */
3272 #ifdef JP
3273                         s2 = "¤ò¤Þ¤¿";
3274 #else
3275                         s2 = "also carrying ";
3276 #endif
3277                 }
3278
3279                 /* Use a preposition */
3280 #ifdef JP
3281                 s2 = "¤Î¾å";
3282                 s3 = "¤Ë¤¤¤ë";
3283 #else
3284                 s2 = "on ";
3285 #endif
3286         }
3287
3288
3289 #ifdef ALLOW_EASY_FLOOR
3290         if (floor_num)
3291         {
3292                 int min_width = 0;
3293
3294                 while (1)
3295                 {
3296                         if (floor_num == 1)
3297                         {
3298                                 char o_name[MAX_NLEN];
3299
3300                                 object_type *o_ptr;
3301
3302                                 /* Acquire object */
3303                                 o_ptr = &o_list[floor_list[0]];
3304
3305                                 /* Describe the object */
3306                                 object_desc(o_name, o_ptr, 0);
3307
3308                                 /* Message */
3309 #ifdef JP
3310                                 sprintf(out_val, "%s%s%s%s[%s]",
3311                                         s1, o_name, s2, s3, info);
3312 #else
3313                                 sprintf(out_val, "%s%s%s%s [%s]",
3314                                         s1, s2, s3, o_name, info);
3315 #endif
3316
3317                                 prt(out_val, 0, 0);
3318                                 move_cursor_relative(y, x);
3319
3320                                 /* Command */
3321                                 query = inkey();
3322
3323                                 /* End this grid */
3324                                 return query;
3325                         }
3326
3327                         /* Provide one cushion before item listing  */
3328                         if (boring)
3329                         {
3330                                 /* Display rough information about items */
3331 #ifdef JP
3332                                 sprintf(out_val, "%s %d¸Ä¤Î¥¢¥¤¥Æ¥à%s%s ['x'¤Ç°ìÍ÷, %s]",
3333                                         s1, floor_num, s2, s3, info);
3334 #else
3335                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]",
3336                                         s1, s2, s3, floor_num, info);
3337 #endif
3338
3339                                 prt(out_val, 0, 0);
3340                                 move_cursor_relative(y, x);
3341
3342                                 /* Command */
3343                                 query = inkey();
3344
3345                                 /* No request for listing */
3346                                 if (query != 'x' && query != ' ') return query;
3347                         }
3348
3349
3350                         /** Display list of items **/
3351
3352                         /* Continue scrolling list if requested */
3353                         while (1)
3354                         {
3355                                 int i, o_idx;
3356
3357                                 /* Save screen */
3358                                 screen_save();
3359
3360                                 /* Display */
3361                                 (void)show_floor(0, y, x, &min_width);
3362
3363                                 /* Prompt */
3364 #ifdef JP
3365                                 sprintf(out_val, "%s %d¸Ä¤Î¥¢¥¤¥Æ¥à%s%s [Enter¤Ç¼¡¤Ø, %s]",
3366                                         s1, floor_num, s2, s3, info);
3367 #else
3368                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]",
3369                                         s1, s2, s3, floor_num, info);
3370 #endif
3371                                 prt(out_val, 0, 0);
3372
3373
3374                                 /* Wait */
3375                                 query = inkey();
3376
3377                                 /* Load screen */
3378                                 screen_load();
3379
3380                                 /* Exit unless 'Enter' */
3381                                 if (query != '\n' && query != '\r')
3382                                 {
3383                                         return query;
3384                                 }
3385
3386                                 /* Get the object being moved. */
3387                                 o_idx = c_ptr->o_idx;
3388  
3389                                 /* Only rotate a pile of two or more objects. */
3390                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
3391
3392                                 /* Remove the first object from the list. */
3393                                 excise_object_idx(o_idx);
3394
3395                                 /* Find end of the list. */
3396                                 i = c_ptr->o_idx;
3397                                 while (o_list[i].next_o_idx)
3398                                         i = o_list[i].next_o_idx;
3399
3400                                 /* Add after the last object. */
3401                                 o_list[i].next_o_idx = o_idx;
3402
3403                                 /* Loop and re-display the list */
3404                         }
3405                 }
3406
3407                 /* NOTREACHED */
3408         }
3409 #endif /* ALLOW_EASY_FLOOR */
3410
3411
3412         /* Scan all objects in the grid */
3413         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3414         {
3415                 object_type *o_ptr;
3416
3417                 /* Acquire object */
3418                 o_ptr = &o_list[this_o_idx];
3419
3420                 /* Acquire next object */
3421                 next_o_idx = o_ptr->next_o_idx;
3422
3423                 /* Describe it */
3424                 if (o_ptr->marked & OM_FOUND)
3425                 {
3426                         char o_name[MAX_NLEN];
3427
3428                         /* Not boring */
3429                         boring = FALSE;
3430
3431                         /* Obtain an object description */
3432                         object_desc(o_name, o_ptr, 0);
3433
3434                         /* Describe the object */
3435 #ifdef JP
3436                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3437 #else
3438                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3439 #endif
3440
3441                         prt(out_val, 0, 0);
3442                         move_cursor_relative(y, x);
3443                         query = inkey();
3444
3445                         /* Always stop at "normal" keys */
3446                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3447
3448                         /* Sometimes stop at "space" key */
3449                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
3450
3451                         /* Change the intro */
3452 #ifdef JP
3453                         s1 = "¤½¤ì¤Ï";
3454 #else
3455                         s1 = "It is ";
3456 #endif
3457
3458
3459                         /* Plurals */
3460 #ifdef JP
3461                         if (o_ptr->number != 1) s1 = "¤½¤ì¤é¤Ï";
3462 #else
3463                         if (o_ptr->number != 1) s1 = "They are ";
3464 #endif
3465
3466
3467                         /* Preposition */
3468 #ifdef JP
3469                         s2 = "¤Î¾å";
3470                         s3 = "¤Ë¸«¤¨¤ë";
3471 #else
3472                         s2 = "on ";
3473 #endif
3474
3475                 }
3476         }
3477
3478
3479         /* Feature code (applying "mimic" field) */
3480         feat = get_feat_mimic(c_ptr);
3481
3482         /* Require knowledge about grid, or ability to see grid */
3483         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
3484         {
3485                 /* Forget feature */
3486                 feat = FEAT_NONE;
3487         }
3488
3489         f_ptr = &f_info[feat];
3490
3491         /* Terrain feature if needed */
3492         if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
3493         {
3494                 cptr name;
3495
3496                 /* Hack -- special handling for building doors */
3497                 if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
3498                 {
3499                         name = building[f_ptr->power].name;
3500                 }
3501                 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
3502                 {
3503 #ifdef JP
3504                         name = format("%s(%d³¬ÁêÅö)", d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3505 #else
3506                         name = format("%s(level %d)", d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3507 #endif
3508                 }
3509                 else if (have_flag(f_ptr->flags, FF_TOWN))
3510                 {
3511                         name = town[c_ptr->special].name;
3512                 }
3513                 else if (p_ptr->wild_mode && (feat == FEAT_FLOOR))
3514                 {
3515 #ifdef JP
3516                         name = "ƻ";
3517 #else
3518                         name = "road";
3519 #endif
3520                 }
3521                 else
3522                 {
3523                         name = f_name + f_ptr->name;
3524                 }
3525
3526
3527                 /* Pick a prefix */
3528                 if (*s2 &&
3529                     ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
3530                      (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
3531                      have_flag(f_ptr->flags, FF_TOWN)))
3532                 {
3533 #ifdef JP
3534                         s2 = "¤ÎÃæ";
3535 #else
3536                         s2 = "in ";
3537 #endif
3538                 }
3539
3540                 /* Hack -- special introduction for store & building doors -KMW- */
3541                 if (have_flag(f_ptr->flags, FF_STORE) ||
3542                     (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
3543                     have_flag(f_ptr->flags, FF_ENTRANCE))
3544                 {
3545 #ifdef JP
3546                         s2 = "¤ÎÆþ¸ý";
3547 #else
3548                         s3 = "";
3549 #endif
3550                 }
3551 #ifndef JP
3552                 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
3553                          have_flag(f_ptr->flags, FF_TOWN) ||
3554                          have_flag(f_ptr->flags, FF_SHALLOW) ||
3555                          have_flag(f_ptr->flags, FF_DEEP))
3556                 {
3557                         s3 ="";
3558                 }
3559                 else
3560                 {
3561                         /* Pick proper indefinite article */
3562                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
3563                 }
3564 #endif
3565
3566                 /* Display a message */
3567                 if (p_ptr->wizard)
3568                 {
3569                         char f_idx_str[32];
3570                         if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
3571                         else sprintf(f_idx_str, "%d", c_ptr->feat);
3572 #ifdef JP
3573                         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);
3574 #else
3575                         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);
3576 #endif
3577                 }
3578                 else
3579 #ifdef JP
3580                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
3581 #else
3582                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3583 #endif
3584
3585                 prt(out_val, 0, 0);
3586                 move_cursor_relative(y, x);
3587                 query = inkey();
3588
3589                 /* Always stop at "normal" keys */
3590                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
3591         }
3592
3593         /* Stop on everything but "return" */
3594         if ((query != '\r') && (query != '\n')) return query;
3595
3596         /* Repeat forever */
3597         return 0;
3598 }
3599
3600
3601 /*
3602  * Handle "target" and "look".
3603  *
3604  * Note that this code can be called from "get_aim_dir()".
3605  *
3606  * All locations must be on the current panel.  Consider the use of
3607  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
3608  * some form of "scrolling" the map around the cursor.  XXX XXX XXX
3609  * That is, consider the possibility of "auto-scrolling" the screen
3610  * while the cursor moves around.  This may require changes in the
3611  * "update_mon()" code to allow "visibility" even if off panel, and
3612  * may require dynamic recalculation of the "temp" grid set.
3613  *
3614  * Hack -- targeting/observing an "outer border grid" may induce
3615  * problems, so this is not currently allowed.
3616  *
3617  * The player can use the direction keys to move among "interesting"
3618  * grids in a heuristic manner, or the "space", "+", and "-" keys to
3619  * move through the "interesting" grids in a sequential manner, or
3620  * can enter "location" mode, and use the direction keys to move one
3621  * grid at a time in any direction.  The "t" (set target) command will
3622  * only target a monster (as opposed to a location) if the monster is
3623  * target_able and the "interesting" mode is being used.
3624  *
3625  * The current grid is described using the "look" method above, and
3626  * a new command may be entered at any time, but note that if the
3627  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
3628  * where "space" has no obvious meaning) then "space" will scan
3629  * through the description of the current grid until done, instead
3630  * of immediately jumping to the next "interesting" grid.  This
3631  * allows the "target" command to retain its old semantics.
3632  *
3633  * The "*", "+", and "-" keys may always be used to jump immediately
3634  * to the next (or previous) interesting grid, in the proper mode.
3635  *
3636  * The "return" key may always be used to scan through a complete
3637  * grid description (forever).
3638  *
3639  * This command will cancel any old target, even if used from
3640  * inside the "look" command.
3641  */
3642 bool target_set(int mode)
3643 {
3644         int             i, d, m, t, bd;
3645         int             y = py;
3646         int             x = px;
3647
3648         bool    done = FALSE;
3649
3650         bool    flag = TRUE;
3651
3652         char    query;
3653
3654         char    info[80];
3655
3656         cave_type               *c_ptr;
3657
3658         int wid, hgt;
3659
3660
3661         /* Get size */
3662         get_screen_size(&wid, &hgt);
3663
3664         /* Cancel target */
3665         target_who = 0;
3666
3667
3668         /* Cancel tracking */
3669         /* health_track(0); */
3670
3671
3672         /* Prepare the "temp" array */
3673         target_set_prepare(mode);
3674
3675         /* Start near the player */
3676         m = 0;
3677
3678         /* Interact */
3679         while (!done)
3680         {
3681                 /* Interesting grids */
3682                 if (flag && temp_n)
3683                 {
3684                         y = temp_y[m];
3685                         x = temp_x[m];
3686
3687                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3688
3689                         /* Access */
3690                         c_ptr = &cave[y][x];
3691
3692                         /* Allow target */
3693                         if (target_able(c_ptr->m_idx))
3694                         {
3695 #ifdef JP
3696 strcpy(info, "q»ß t·è p¼« o¸½ +¼¡ -Á°");
3697 #else
3698                                 strcpy(info, "q,t,p,o,+,-,<dir>");
3699 #endif
3700
3701                         }
3702
3703                         /* Dis-allow target */
3704                         else
3705                         {
3706 #ifdef JP
3707 strcpy(info, "q»ß p¼« o¸½ +¼¡ -Á°");
3708 #else
3709                                 strcpy(info, "q,p,o,+,-,<dir>");
3710 #endif
3711
3712                         }
3713
3714                         /* Describe and Prompt */
3715                         while (!(query = target_set_aux(y, x, mode, info)));
3716
3717                         /* Cancel tracking */
3718                         /* health_track(0); */
3719
3720                         /* Assume no "direction" */
3721                         d = 0;
3722
3723                         if (use_menu)
3724                         {
3725                                 if (query == '\r') query = 't';
3726                         }  
3727
3728                         /* Analyze */
3729                         switch (query)
3730                         {
3731                                 case ESCAPE:
3732                                 case 'q':
3733                                 {
3734                                         done = TRUE;
3735                                         break;
3736                                 }
3737
3738                                 case 't':
3739                                 case '.':
3740                                 case '5':
3741                                 case '0':
3742                                 {
3743                                         if (target_able(c_ptr->m_idx))
3744                                         {
3745                                                 health_track(c_ptr->m_idx);
3746                                                 target_who = c_ptr->m_idx;
3747                                                 target_row = y;
3748                                                 target_col = x;
3749                                                 done = TRUE;
3750                                         }
3751                                         else
3752                                         {
3753                                                 bell();
3754                                         }
3755                                         break;
3756                                 }
3757
3758                                 case ' ':
3759                                 case '*':
3760                                 case '+':
3761                                 {
3762                                         if (++m == temp_n)
3763                                         {
3764                                                 m = 0;
3765                                                 if (!expand_list) done = TRUE;
3766                                         }
3767                                         break;
3768                                 }
3769
3770                                 case '-':
3771                                 {
3772                                         if (m-- == 0)
3773                                         {
3774                                                 m = temp_n - 1;
3775                                                 if (!expand_list) done = TRUE;
3776                                         }
3777                                         break;
3778                                 }
3779
3780                                 case 'p':
3781                                 {
3782                                         /* Recenter the map around the player */
3783                                         verify_panel();
3784
3785                                         /* Update stuff */
3786                                         p_ptr->update |= (PU_MONSTERS);
3787
3788                                         /* Redraw map */
3789                                         p_ptr->redraw |= (PR_MAP);
3790
3791                                         /* Window stuff */
3792                                         p_ptr->window |= (PW_OVERHEAD);
3793
3794                                         /* Handle stuff */
3795                                         handle_stuff();
3796
3797                                         /* Recalculate interesting grids */
3798                                         target_set_prepare(mode);
3799
3800                                         y = py;
3801                                         x = px;
3802                                 }
3803
3804                                 case 'o':
3805                                 {
3806                                         flag = FALSE;
3807                                         break;
3808                                 }
3809
3810                                 case 'm':
3811                                 {
3812                                         break;
3813                                 }
3814
3815                                 default:
3816                                 {
3817                                         /* Extract the action (if any) */
3818                                         d = get_keymap_dir(query);
3819
3820                                         if (!d) bell();
3821                                         break;
3822                                 }
3823                         }
3824
3825                         /* Hack -- move around */
3826                         if (d)
3827                         {
3828                                 /* Modified to scroll to monster */
3829                                 int y2 = panel_row_min;
3830                                 int x2 = panel_col_min;
3831
3832                                 /* Find a new monster */
3833                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
3834
3835                                 /* Request to target past last interesting grid */
3836                                 while (flag && (i < 0))
3837                                 {
3838                                         /* Note the change */
3839                                         if (change_panel(ddy[d], ddx[d]))
3840                                         {
3841                                                 int v = temp_y[m];
3842                                                 int u = temp_x[m];
3843
3844                                                 /* Recalculate interesting grids */
3845                                                 target_set_prepare(mode);
3846
3847                                                 /* Look at interesting grids */
3848                                                 flag = TRUE;
3849
3850                                                 /* Find a new monster */
3851                                                 i = target_pick(v, u, ddy[d], ddx[d]);
3852
3853                                                 /* Use that grid */
3854                                                 if (i >= 0) m = i;
3855                                         }
3856
3857                                         /* Nothing interesting */
3858                                         else
3859                                         {
3860                                                 int dx = ddx[d];
3861                                                 int dy = ddy[d];
3862
3863                                                 /* Restore previous position */
3864                                                 panel_row_min = y2;
3865                                                 panel_col_min = x2;
3866                                                 panel_bounds_center();
3867
3868                                                 /* Update stuff */
3869                                                 p_ptr->update |= (PU_MONSTERS);
3870
3871                                                 /* Redraw map */
3872                                                 p_ptr->redraw |= (PR_MAP);
3873
3874                                                 /* Window stuff */
3875                                                 p_ptr->window |= (PW_OVERHEAD);
3876
3877                                                 /* Handle stuff */
3878                                                 handle_stuff();
3879
3880                                                 /* Recalculate interesting grids */
3881                                                 target_set_prepare(mode);
3882
3883                                                 /* Look at boring grids */
3884                                                 flag = FALSE;
3885
3886                                                 /* Move */
3887                                                 x += dx;
3888                                                 y += dy;
3889
3890                                                 /* Do not move horizontally if unnecessary */
3891                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3892                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
3893                                                 {
3894                                                         dx = 0;
3895                                                 }
3896
3897                                                 /* Do not move vertically if unnecessary */
3898                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3899                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
3900                                                 {
3901                                                         dy = 0;
3902                                                 }
3903
3904                                                 /* Apply the motion */
3905                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
3906                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
3907                                                 {
3908                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
3909                                                 }
3910
3911                                                 /* Slide into legality */
3912                                                 if (x >= cur_wid-1) x = cur_wid - 2;
3913                                                 else if (x <= 0) x = 1;
3914
3915                                                 /* Slide into legality */
3916                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
3917                                                 else if (y <= 0) y = 1;
3918                                         }
3919                                 }
3920
3921                                 /* Use that grid */
3922                                 m = i;
3923                         }
3924                 }
3925
3926                 /* Arbitrary grids */
3927                 else
3928                 {
3929                         bool move_fast = FALSE;
3930
3931                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3932
3933                         /* Access */
3934                         c_ptr = &cave[y][x];
3935
3936                         /* Default prompt */
3937 #ifdef JP
3938 strcpy(info, "q»ß t·è p¼« m¶á +¼¡ -Á°");
3939 #else
3940                         strcpy(info, "q,t,p,m,+,-,<dir>");
3941 #endif
3942
3943
3944                         /* Describe and Prompt (enable "TARGET_LOOK") */
3945                         while (!(query = target_set_aux(y, x, mode | TARGET_LOOK, info)));
3946
3947                         /* Cancel tracking */
3948                         /* health_track(0); */
3949
3950                         /* Assume no direction */
3951                         d = 0;
3952
3953                         if (use_menu)
3954                         {
3955                                 if (query == '\r') query = 't';
3956                         }  
3957
3958                         /* Analyze the keypress */
3959                         switch (query)
3960                         {
3961                                 case ESCAPE:
3962                                 case 'q':
3963                                 {
3964                                         done = TRUE;
3965                                         break;
3966                                 }
3967
3968                                 case 't':
3969                                 case '.':
3970                                 case '5':
3971                                 case '0':
3972                                 {
3973                                         target_who = -1;
3974                                         target_row = y;
3975                                         target_col = x;
3976                                         done = TRUE;
3977                                         break;
3978                                 }
3979
3980                                 case 'p':
3981                                 {
3982                                         /* Recenter the map around the player */
3983                                         verify_panel();
3984
3985                                         /* Update stuff */
3986                                         p_ptr->update |= (PU_MONSTERS);
3987
3988                                         /* Redraw map */
3989                                         p_ptr->redraw |= (PR_MAP);
3990
3991                                         /* Window stuff */
3992                                         p_ptr->window |= (PW_OVERHEAD);
3993
3994                                         /* Handle stuff */
3995                                         handle_stuff();
3996
3997                                         /* Recalculate interesting grids */
3998                                         target_set_prepare(mode);
3999
4000                                         y = py;
4001                                         x = px;
4002                                 }
4003
4004                                 case 'o':
4005                                 {
4006                                         break;
4007                                 }
4008
4009                                 case ' ':
4010                                 case '*':
4011                                 case '+':
4012                                 case '-':
4013                                 case 'm':
4014                                 {
4015                                         flag = TRUE;
4016
4017                                         m = 0;
4018                                         bd = 999;
4019
4020                                         /* Pick a nearby monster */
4021                                         for (i = 0; i < temp_n; i++)
4022                                         {
4023                                                 t = distance(y, x, temp_y[i], temp_x[i]);
4024
4025                                                 /* Pick closest */
4026                                                 if (t < bd)
4027                                                 {
4028                                                         m = i;
4029                                                         bd = t;
4030                                                 }
4031                                         }
4032
4033                                         /* Nothing interesting */
4034                                         if (bd == 999) flag = FALSE;
4035
4036                                         break;
4037                                 }
4038
4039                                 default:
4040                                 {
4041                                         /* Extract the action (if any) */
4042                                         d = get_keymap_dir(query);
4043
4044                                         /* XTRA HACK MOVEFAST */
4045                                         if (isupper(query)) move_fast = TRUE;
4046
4047                                         if (!d) bell();
4048                                         break;
4049                                 }
4050                         }
4051
4052                         /* Handle "direction" */
4053                         if (d)
4054                         {
4055                                 int dx = ddx[d];
4056                                 int dy = ddy[d];
4057
4058                                 /* XTRA HACK MOVEFAST */
4059                                 if (move_fast)
4060                                 {
4061                                         int mag = MIN(wid / 2, hgt / 2);
4062                                         x += dx * mag;
4063                                         y += dy * mag;
4064                                 }
4065                                 else
4066                                 {
4067                                         x += dx;
4068                                         y += dy;
4069                                 }
4070
4071                                 /* Do not move horizontally if unnecessary */
4072                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4073                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4074                                 {
4075                                         dx = 0;
4076                                 }
4077
4078                                 /* Do not move vertically if unnecessary */
4079                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4080                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4081                                 {
4082                                         dy = 0;
4083                                 }
4084
4085                                 /* Apply the motion */
4086                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
4087                                          (x >= panel_col_min + wid) || (x < panel_col_min))
4088                                 {
4089                                         if (change_panel(dy, dx)) target_set_prepare(mode);
4090                                 }
4091
4092                                 /* Slide into legality */
4093                                 if (x >= cur_wid-1) x = cur_wid - 2;
4094                                 else if (x <= 0) x = 1;
4095
4096                                 /* Slide into legality */
4097                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4098                                 else if (y <= 0) y = 1;
4099                         }
4100                 }
4101         }
4102
4103         /* Forget */
4104         temp_n = 0;
4105
4106         /* Clear the top line */
4107         prt("", 0, 0);
4108
4109         /* Recenter the map around the player */
4110         verify_panel();
4111
4112         /* Update stuff */
4113         p_ptr->update |= (PU_MONSTERS);
4114
4115         /* Redraw map */
4116         p_ptr->redraw |= (PR_MAP);
4117
4118         /* Window stuff */
4119         p_ptr->window |= (PW_OVERHEAD);
4120
4121         /* Handle stuff */
4122         handle_stuff();
4123
4124         /* Failure to set target */
4125         if (!target_who) return (FALSE);
4126
4127         /* Success */
4128         return (TRUE);
4129 }
4130
4131
4132 /*
4133  * Get an "aiming direction" from the user.
4134  *
4135  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
4136  * "0" for "current target", and "-1" for "entry aborted".
4137  *
4138  * Note that "Force Target", if set, will pre-empt user interaction,
4139  * if there is a usable target already set.
4140  *
4141  * Note that confusion over-rides any (explicit?) user choice.
4142  */
4143 bool get_aim_dir(int *dp)
4144 {
4145         int             dir;
4146
4147         char    command;
4148
4149         cptr    p;
4150
4151         /* Initialize */
4152         (*dp) = 0;
4153
4154         /* Global direction */
4155         dir = command_dir;
4156
4157         /* Hack -- auto-target if requested */
4158         if (use_old_target && target_okay()) dir = 5;
4159
4160 #ifdef ALLOW_REPEAT /* TNB */
4161
4162         if (repeat_pull(dp))
4163         {
4164                 /* Confusion? */
4165
4166                 /* Verify */
4167                 if (!(*dp == 5 && !target_okay()))
4168                 {
4169 /*                      return (TRUE); */
4170                         dir = *dp;
4171                 }
4172         }
4173
4174 #endif /* ALLOW_REPEAT -- TNB */
4175
4176         /* Ask until satisfied */
4177         while (!dir)
4178         {
4179                 /* Choose a prompt */
4180                 if (!target_okay())
4181                 {
4182 #ifdef JP
4183 p = "Êý¸þ ('*'¤Ç¥¿¡¼¥²¥Ã¥ÈÁªÂò, ESC¤ÇÃæÃÇ)? ";
4184 #else
4185                         p = "Direction ('*' to choose a target, Escape to cancel)? ";
4186 #endif
4187
4188                 }
4189                 else
4190                 {
4191 #ifdef JP
4192 p = "Êý¸þ ('5'¤Ç¥¿¡¼¥²¥Ã¥È¤Ø, '*'¤Ç¥¿¡¼¥²¥Ã¥ÈºÆÁªÂò, ESC¤ÇÃæÃÇ)? ";
4193 #else
4194                         p = "Direction ('5' for target, '*' to re-target, Escape to cancel)? ";
4195 #endif
4196
4197                 }
4198
4199                 /* Get a command (or Cancel) */
4200                 if (!get_com(p, &command, TRUE)) break;
4201
4202                 if (use_menu)
4203                 {
4204                         if (command == '\r') command = 't';
4205                 }  
4206
4207                 /* Convert various keys to "standard" keys */
4208                 switch (command)
4209                 {
4210                         /* Use current target */
4211                         case 'T':
4212                         case 't':
4213                         case '.':
4214                         case '5':
4215                         case '0':
4216                         {
4217                                 dir = 5;
4218                                 break;
4219                         }
4220
4221                         /* Set new target */
4222                         case '*':
4223                         case ' ':
4224                         case '\r':
4225                         {
4226                                 if (target_set(TARGET_KILL)) dir = 5;
4227                                 break;
4228                         }
4229
4230                         default:
4231                         {
4232                                 /* Extract the action (if any) */
4233                                 dir = get_keymap_dir(command);
4234
4235                                 break;
4236                         }
4237                 }
4238
4239                 /* Verify requested targets */
4240                 if ((dir == 5) && !target_okay()) dir = 0;
4241
4242                 /* Error */
4243                 if (!dir) bell();
4244         }
4245
4246         /* No direction */
4247         if (!dir)
4248         {
4249                 project_length = 0; /* reset to default */
4250                 return (FALSE);
4251         }
4252
4253         /* Save the direction */
4254         command_dir = dir;
4255
4256         /* Check for confusion */
4257         if (p_ptr->confused)
4258         {
4259                 /* XXX XXX XXX */
4260                 /* Random direction */
4261                 dir = ddd[randint0(8)];
4262         }
4263
4264         /* Notice confusion */
4265         if (command_dir != dir)
4266         {
4267                 /* Warn the user */
4268 #ifdef JP
4269 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4270 #else
4271                 msg_print("You are confused.");
4272 #endif
4273
4274         }
4275
4276         /* Save direction */
4277         (*dp) = dir;
4278
4279 #ifdef ALLOW_REPEAT /* TNB */
4280
4281 /*      repeat_push(dir); */
4282         repeat_push(command_dir);
4283
4284 #endif /* ALLOW_REPEAT -- TNB */
4285
4286         /* A "valid" direction was entered */
4287         return (TRUE);
4288 }
4289
4290
4291
4292 /*
4293  * Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
4294  * and place it into "command_dir", unless we already have one.
4295  *
4296  * This function should be used for all "repeatable" commands, such as
4297  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
4298  * as all commands which must reference a grid adjacent to the player,
4299  * and which may not reference the grid under the player.  Note that,
4300  * for example, it is no longer possible to "disarm" or "open" chests
4301  * in the same grid as the player.
4302  *
4303  * Direction "5" is illegal and will (cleanly) abort the command.
4304  *
4305  * This function tracks and uses the "global direction", and uses
4306  * that as the "desired direction", to which "confusion" is applied.
4307  */
4308 bool get_rep_dir(int *dp, bool under)
4309 {
4310         int dir;
4311
4312         /* Initialize */
4313         (*dp) = 0;
4314
4315         /* Global direction */
4316         dir = command_dir;
4317
4318 #ifdef ALLOW_REPEAT /* TNB */
4319
4320         if (repeat_pull(dp))
4321         {
4322                 dir = *dp;
4323 /*              return (TRUE); */
4324         }
4325
4326 #endif /* ALLOW_REPEAT -- TNB */
4327
4328         /* Get a direction */
4329         while (!dir)
4330         {
4331                 char ch;
4332
4333                 /* Get a command (or Cancel) */
4334 #ifdef JP
4335 if (!get_com("Êý¸þ (ESC¤ÇÃæÃÇ)? ", &ch, TRUE)) break;
4336 #else
4337                 if (!get_com("Direction (Escape to cancel)? ", &ch, TRUE)) break;
4338 #endif
4339
4340
4341                 /* Look up the direction */
4342                 dir = get_keymap_dir(ch);
4343
4344                 /* Oops */
4345                 if (!dir) bell();
4346         }
4347
4348         /* Prevent weirdness */
4349         if ((dir == 5) && (!under)) dir = 0;
4350
4351         /* Aborted */
4352         if (!dir) return (FALSE);
4353
4354         /* Save desired direction */
4355         command_dir = dir;
4356
4357         /* Apply "confusion" */
4358         if (p_ptr->confused)
4359         {
4360                 /* Standard confusion */
4361                 if (randint0(100) < 75)
4362                 {
4363                         /* Random direction */
4364                         dir = ddd[randint0(8)];
4365                 }
4366         }
4367         else if (p_ptr->riding)
4368         {
4369                 monster_type *m_ptr = &m_list[p_ptr->riding];
4370                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4371
4372                 if (m_ptr->confused)
4373                 {
4374                         /* Standard confusion */
4375                         if (randint0(100) < 75)
4376                         {
4377                                 /* Random direction */
4378                                 dir = ddd[randint0(8)];
4379                         }
4380                 }
4381                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
4382                 {
4383                         /* Random direction */
4384                         dir = ddd[randint0(8)];
4385                 }
4386                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
4387                 {
4388                         /* Random direction */
4389                         dir = ddd[randint0(8)];
4390                 }
4391         }
4392
4393         /* Notice confusion */
4394         if (command_dir != dir)
4395         {
4396                 if (p_ptr->confused)
4397                 {
4398                         /* Warn the user */
4399 #ifdef JP
4400 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4401 #else
4402                         msg_print("You are confused.");
4403 #endif
4404                 }
4405                 else
4406                 {
4407                         char m_name[80];
4408                         monster_type *m_ptr = &m_list[p_ptr->riding];
4409
4410                         monster_desc(m_name, m_ptr, 0);
4411                         if (m_ptr->confused)
4412                         {
4413 #ifdef JP
4414 msg_format("%s¤Ïº®Í𤷤Ƥ¤¤ë¡£", m_name);
4415 #else
4416  msg_format("%^s is confusing.", m_name);
4417
4418 #endif
4419                         }
4420                         else
4421                         {
4422 #ifdef JP
4423 msg_format("%s¤Ï»×¤¤Ä̤ê¤ËÆ°¤¤¤Æ¤¯¤ì¤Ê¤¤¡£", m_name);
4424 #else
4425 msg_format("You cannot control %s.", m_name);
4426 #endif
4427                         }
4428                 }
4429         }
4430
4431         /* Save direction */
4432         (*dp) = dir;
4433
4434 #ifdef ALLOW_REPEAT /* TNB */
4435
4436 /*      repeat_push(dir); */
4437         repeat_push(command_dir);
4438
4439 #endif /* ALLOW_REPEAT -- TNB */
4440
4441         /* Success */
4442         return (TRUE);
4443 }
4444
4445
4446 bool get_rep_dir2(int *dp)
4447 {
4448         int dir;
4449
4450         /* Initialize */
4451         (*dp) = 0;
4452
4453         /* Global direction */
4454         dir = command_dir;
4455
4456 #ifdef ALLOW_REPEAT /* TNB */
4457
4458         if (repeat_pull(dp))
4459         {
4460                 dir = *dp;
4461 /*              return (TRUE); */
4462         }
4463
4464 #endif /* ALLOW_REPEAT -- TNB */
4465
4466         /* Get a direction */
4467         while (!dir)
4468         {
4469                 char ch;
4470
4471                 /* Get a command (or Cancel) */
4472 #ifdef JP
4473 if (!get_com("Êý¸þ (ESC¤ÇÃæÃÇ)? ", &ch, TRUE)) break;
4474 #else
4475                 if (!get_com("Direction (Escape to cancel)? ", &ch, TRUE)) break;
4476 #endif
4477
4478
4479                 /* Look up the direction */
4480                 dir = get_keymap_dir(ch);
4481
4482                 /* Oops */
4483                 if (!dir) bell();
4484         }
4485
4486         /* Prevent weirdness */
4487         if (dir == 5) dir = 0;
4488
4489         /* Aborted */
4490         if (!dir) return (FALSE);
4491
4492         /* Save desired direction */
4493         command_dir = dir;
4494
4495         /* Apply "confusion" */
4496         if (p_ptr->confused)
4497         {
4498                 /* Standard confusion */
4499                 if (randint0(100) < 75)
4500                 {
4501                         /* Random direction */
4502                         dir = ddd[randint0(8)];
4503                 }
4504         }
4505
4506         /* Notice confusion */
4507         if (command_dir != dir)
4508         {
4509                 /* Warn the user */
4510 #ifdef JP
4511 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4512 #else
4513                 msg_print("You are confused.");
4514 #endif
4515
4516         }
4517
4518         /* Save direction */
4519         (*dp) = dir;
4520
4521 #ifdef ALLOW_REPEAT /* TNB */
4522
4523 /*      repeat_push(dir); */
4524         repeat_push(command_dir);
4525
4526 #endif /* ALLOW_REPEAT -- TNB */
4527
4528         /* Success */
4529         return (TRUE);
4530 }
4531
4532
4533 void gain_level_reward(int chosen_reward)
4534 {
4535         object_type *q_ptr;
4536         object_type forge;
4537         char        wrath_reason[32] = "";
4538         int         nasty_chance = 6;
4539         int         dummy = 0, dummy2 = 0;
4540         int         type, effect;
4541         cptr        reward = NULL;
4542         char o_name[MAX_NLEN];
4543
4544         int count = 0;
4545
4546         if (!chosen_reward)
4547         {
4548                 if (multi_rew) return;
4549                 else multi_rew = TRUE;
4550         }
4551
4552
4553         if (p_ptr->lev == 13) nasty_chance = 2;
4554         else if (!(p_ptr->lev % 13)) nasty_chance = 3;
4555         else if (!(p_ptr->lev % 14)) nasty_chance = 12;
4556
4557         if (one_in_(nasty_chance))
4558                 type = randint1(20); /* Allow the 'nasty' effects */
4559         else
4560                 type = randint1(15) + 5; /* Or disallow them */
4561
4562         if (type < 1) type = 1;
4563         if (type > 20) type = 20;
4564         type--;
4565
4566
4567 #ifdef JP
4568 sprintf(wrath_reason, "%s¤ÎÅܤê",
4569                 chaos_patrons[p_ptr->chaos_patron]);
4570 #else
4571         sprintf(wrath_reason, "the Wrath of %s",
4572                 chaos_patrons[p_ptr->chaos_patron]);
4573 #endif
4574
4575
4576         effect = chaos_rewards[p_ptr->chaos_patron][type];
4577
4578         if (one_in_(6) && !chosen_reward)
4579         {
4580 #ifdef JP
4581 msg_format("%^s¤ÏË«Èþ¤È¤·¤Æ¤¢¤Ê¤¿¤òÆÍÁ³ÊÑ°Û¤µ¤»¤¿¡£",
4582                         chaos_patrons[p_ptr->chaos_patron]);
4583 #else
4584                 msg_format("%^s rewards you with a mutation!",
4585                         chaos_patrons[p_ptr->chaos_patron]);
4586 #endif
4587
4588                 (void)gain_random_mutation(0);
4589 #ifdef JP
4590                 reward = "ÊÑ°Û¤·¤¿¡£";
4591 #else
4592                 reward = "mutation";
4593 #endif
4594         }
4595         else
4596         {
4597         switch (chosen_reward ? chosen_reward : effect)
4598         {
4599                 case REW_POLY_SLF:
4600 #ifdef JP
4601 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4602                                 chaos_patrons[p_ptr->chaos_patron]);
4603 #else
4604                         msg_format("The voice of %s booms out:",
4605                                 chaos_patrons[p_ptr->chaos_patron]);
4606 #endif
4607
4608 #ifdef JP
4609 msg_print("¡ÖÆò¡¢¿·¤¿¤Ê¤ë»Ñ¤òɬÍפȤ»¤ê¡ª¡×");
4610 #else
4611                         msg_print("'Thou needst a new form, mortal!'");
4612 #endif
4613
4614                         do_poly_self();
4615 #ifdef JP
4616                         reward = "ÊÑ°Û¤·¤¿¡£";
4617 #else
4618                         reward = "polymorphing";
4619 #endif
4620                         break;
4621                 case REW_GAIN_EXP:
4622 #ifdef JP
4623 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4624                                 chaos_patrons[p_ptr->chaos_patron]);
4625 #else
4626                         msg_format("The voice of %s booms out:",
4627                                 chaos_patrons[p_ptr->chaos_patron]);
4628 #endif
4629
4630 #ifdef JP
4631 msg_print("¡ÖÆò¤ÏÎɤ¯¹Ô¤¤¤¿¤ê¡ªÂ³¤±¤è¡ª¡×");
4632 #else
4633                         msg_print("'Well done, mortal! Lead on!'");
4634 #endif
4635
4636                         if (p_ptr->prace == RACE_ANDROID)
4637                         {
4638 #ifdef JP
4639                                 msg_print("¤·¤«¤·²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
4640 #else
4641                                 msg_print("But, nothing happen.");
4642 #endif
4643                         }
4644                         else if (p_ptr->exp < PY_MAX_EXP)
4645                         {
4646                                 s32b ee = (p_ptr->exp / 2) + 10;
4647                                 if (ee > 100000L) ee = 100000L;
4648 #ifdef JP
4649 msg_print("¹¹¤Ë·Ð¸³¤òÀѤó¤À¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
4650 #else
4651                                 msg_print("You feel more experienced.");
4652 #endif
4653
4654                                 gain_exp(ee);
4655 #ifdef JP
4656                                 reward = "·Ð¸³ÃͤòÆÀ¤¿";
4657 #else
4658                                 reward = "experience";
4659 #endif
4660                         }
4661                         break;
4662                 case REW_LOSE_EXP:
4663 #ifdef JP
4664 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4665                                 chaos_patrons[p_ptr->chaos_patron]);
4666 #else
4667                         msg_format("The voice of %s booms out:",
4668                                 chaos_patrons[p_ptr->chaos_patron]);
4669 #endif
4670
4671 #ifdef JP
4672 msg_print("¡Ö²¼Ëͤ衢Æò¤½¤ì¤ËÃͤ»¤º¡£¡×");
4673 #else
4674                         msg_print("'Thou didst not deserve that, slave.'");
4675 #endif
4676
4677                         if (p_ptr->prace == RACE_ANDROID)
4678                         {
4679 #ifdef JP
4680                                 msg_print("¤·¤«¤·²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
4681 #else
4682                                 msg_print("But, nothing happen.");
4683 #endif
4684                         }
4685                         else
4686                         {
4687                                 lose_exp(p_ptr->exp / 6);
4688 #ifdef JP
4689                                 reward = "·Ð¸³Ãͤò¼º¤Ã¤¿¡£";
4690 #else
4691                                 reward = "losing experience";
4692 #endif
4693                         }
4694                         break;
4695                 case REW_GOOD_OBJ:
4696 #ifdef JP
4697 msg_format("%s¤ÎÀ¼¤¬¤µ¤µ¤ä¤¤¤¿:",
4698                                 chaos_patrons[p_ptr->chaos_patron]);
4699 #else
4700                         msg_format("The voice of %s whispers:",
4701                                 chaos_patrons[p_ptr->chaos_patron]);
4702 #endif
4703
4704 #ifdef JP
4705 msg_print("¡Ö²æ¤¬Í¿¤¨¤·Êª¤ò¸­ÌÀ¤Ë»È¤¦¤Ù¤·¡£¡×");
4706 #else
4707                         msg_print("'Use my gift wisely.'");
4708 #endif
4709
4710                         acquirement(py, px, 1, FALSE, FALSE);
4711 #ifdef JP
4712                         reward = "¾å¼Á¤Ê¥¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4713 #else
4714                         reward = "a good item";
4715 #endif
4716                         break;
4717                 case REW_GREA_OBJ:
4718 #ifdef JP
4719 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4720                                 chaos_patrons[p_ptr->chaos_patron]);
4721 #else
4722                         msg_format("The voice of %s booms out:",
4723                                 chaos_patrons[p_ptr->chaos_patron]);
4724 #endif
4725
4726 #ifdef JP
4727 msg_print("¡Ö²æ¤¬Í¿¤¨¤·Êª¤ò¸­ÌÀ¤Ë»È¤¦¤Ù¤·¡£¡×");
4728 #else
4729                         msg_print("'Use my gift wisely.'");
4730 #endif
4731
4732                         acquirement(py, px, 1, TRUE, FALSE);
4733 #ifdef JP
4734                         reward = "¹âµéÉʤΥ¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4735 #else
4736                         reward = "an excellent item";
4737 #endif
4738                         break;
4739                 case REW_CHAOS_WP:
4740 #ifdef JP
4741 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4742                                 chaos_patrons[p_ptr->chaos_patron]);
4743 #else
4744                         msg_format("The voice of %s booms out:",
4745                                 chaos_patrons[p_ptr->chaos_patron]);
4746 #endif
4747
4748 #ifdef JP
4749 msg_print("¡ÖÆò¤Î¹Ô¤¤¤Ïµ®¤­·õ¤ËÃͤ»¤ê¡£¡×");
4750 #else
4751                         msg_print("'Thy deed hath earned thee a worthy blade.'");
4752 #endif
4753
4754                         /* Get local object */
4755                         q_ptr = &forge;
4756                         dummy = TV_SWORD;
4757                         switch (randint1(p_ptr->lev))
4758                         {
4759                                 case 0: case 1:
4760                                         dummy2 = SV_DAGGER;
4761                                         break;
4762                                 case 2: case 3:
4763                                         dummy2 = SV_MAIN_GAUCHE;
4764                                         break;
4765                                 case 4:
4766                                         dummy2 = SV_TANTO;
4767                                         break;
4768                                 case 5: case 6:
4769                                         dummy2 = SV_RAPIER;
4770                                         break;
4771                                 case 7: case 8:
4772                                         dummy2 = SV_SMALL_SWORD;
4773                                         break;
4774                                 case 9: case 10:
4775                                         dummy2 = SV_BASILLARD;
4776                                         break;
4777                                 case 11: case 12: case 13:
4778                                         dummy2 = SV_SHORT_SWORD;
4779                                         break;
4780                                 case 14: case 15:
4781                                         dummy2 = SV_SABRE;
4782                                         break;
4783                                 case 16: case 17:
4784                                         dummy2 = SV_CUTLASS;
4785                                         break;
4786                                 case 18:
4787                                         dummy2 = SV_WAKIZASHI;
4788                                         break;
4789                                 case 19:
4790                                         dummy2 = SV_KHOPESH;
4791                                         break;
4792                                 case 20:
4793                                         dummy2 = SV_TULWAR;
4794                                         break;
4795                                 case 21:
4796                                         dummy2 = SV_BROAD_SWORD;
4797                                         break;
4798                                 case 22: case 23:
4799                                         dummy2 = SV_LONG_SWORD;
4800                                         break;
4801                                 case 24: case 25:
4802                                         dummy2 = SV_SCIMITAR;
4803                                         break;
4804                                 case 26:
4805                                         dummy2 = SV_NINJATO;
4806                                         break;
4807                                 case 27:
4808                                         dummy2 = SV_KATANA;
4809                                         break;
4810                                 case 28: case 29:
4811                                         dummy2 = SV_BASTARD_SWORD;
4812                                         break;
4813                                 case 30:
4814                                         dummy2 = SV_GREAT_SCIMITAR;
4815                                         break;
4816                                 case 31:
4817                                         dummy2 = SV_CLAYMORE;
4818                                         break;
4819                                 case 32:
4820                                         dummy2 = SV_ESPADON;
4821                                         break;
4822                                 case 33:
4823                                         dummy2 = SV_TWO_HANDED_SWORD;
4824                                         break;
4825                                 case 34:
4826                                         dummy2 = SV_FLAMBERGE;
4827                                         break;
4828                                 case 35:
4829                                         dummy2 = SV_NO_DACHI;
4830                                         break;
4831                                 case 36:
4832                                         dummy2 = SV_EXECUTIONERS_SWORD;
4833                                         break;
4834                                 case 37:
4835                                         dummy2 = SV_ZWEIHANDER;
4836                                         break;
4837                                 case 38:
4838                                         dummy2 = SV_HAYABUSA;
4839                                         break;
4840                                 default:
4841                                         dummy2 = SV_BLADE_OF_CHAOS;
4842                         }
4843
4844                         object_prep(q_ptr, lookup_kind(dummy, dummy2));
4845                         q_ptr->to_h = 3 + randint1(dun_level) % 10;
4846                         q_ptr->to_d = 3 + randint1(dun_level) % 10;
4847                         one_resistance(q_ptr);
4848                         q_ptr->name2 = EGO_CHAOTIC;
4849
4850                         /* Drop it in the dungeon */
4851                         (void)drop_near(q_ptr, -1, py, px);
4852 #ifdef JP
4853                         reward = "(º®ÆÙ)¤ÎÉð´ï¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4854 #else
4855                         reward = "chaos weapon";
4856 #endif
4857                         break;
4858                 case REW_GOOD_OBS:
4859 #ifdef JP
4860 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4861                                 chaos_patrons[p_ptr->chaos_patron]);
4862 #else
4863                         msg_format("The voice of %s booms out:",
4864                                 chaos_patrons[p_ptr->chaos_patron]);
4865 #endif
4866
4867 #ifdef JP
4868 msg_print("¡ÖÆò¤Î¹Ô¤¤¤Ïµ®¤­Ê󤤤ËÃͤ»¤ê¡£¡×");
4869 #else
4870                         msg_print("'Thy deed hath earned thee a worthy reward.'");
4871 #endif
4872
4873                         acquirement(py, px, randint1(2) + 1, FALSE, FALSE);
4874 #ifdef JP
4875                         reward = "¾å¼Á¤Ê¥¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4876 #else
4877                         reward = "good items";
4878 #endif
4879                         break;
4880                 case REW_GREA_OBS:
4881 #ifdef JP
4882 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4883                                 chaos_patrons[p_ptr->chaos_patron]);
4884 #else
4885                         msg_format("The voice of %s booms out:",
4886                                 chaos_patrons[p_ptr->chaos_patron]);
4887 #endif
4888
4889 #ifdef JP
4890 msg_print("¡Ö²¼Ëͤ衢Æò¤Î¸¥¿È¤Ø¤Î²æ¤¬Àˤ·¤ß̵¤­Ê󤤤ò¸«¤ë¤¬¤è¤¤¡£¡×");
4891 #else
4892                         msg_print("'Behold, mortal, how generously I reward thy loyalty.'");
4893 #endif
4894
4895                         acquirement(py, px, randint1(2) + 1, TRUE, FALSE);
4896 #ifdef JP
4897                         reward = "¹âµéÉʤΥ¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4898 #else
4899                         reward = "excellent items";
4900 #endif
4901                         break;
4902                 case REW_TY_CURSE:
4903 #ifdef JP
4904 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
4905                                 chaos_patrons[p_ptr->chaos_patron]);
4906 #else
4907                         msg_format("The voice of %s thunders:",
4908                                 chaos_patrons[p_ptr->chaos_patron]);
4909 #endif
4910
4911 #ifdef JP
4912 msg_print("¡Ö²¼Ëͤ衢ÆòÐþËý¤Ê¤ê¡£¡×");
4913 #else
4914                         msg_print("'Thou art growing arrogant, mortal.'");
4915 #endif
4916
4917                         (void)activate_ty_curse(FALSE, &count);
4918 #ifdef JP
4919                         reward = "²Ò¡¹¤·¤¤¼ö¤¤¤ò¤«¤±¤é¤ì¤¿¡£";
4920 #else
4921                         reward = "cursing";
4922 #endif
4923                         break;
4924                 case REW_SUMMON_M:
4925 #ifdef JP
4926 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4927                                 chaos_patrons[p_ptr->chaos_patron]);
4928 #else
4929                         msg_format("The voice of %s booms out:",
4930                                 chaos_patrons[p_ptr->chaos_patron]);
4931 #endif
4932
4933 #ifdef JP
4934 msg_print("¡Ö²æ¤¬²¼Ëͤ¿¤Á¤è¡¢¤«¤ÎÐþËý¤Ê¤ë¼Ô¤òÅݤ¹¤Ù¤·¡ª¡×");
4935 #else
4936                         msg_print("'My pets, destroy the arrogant mortal!'");
4937 #endif
4938
4939                         for (dummy = 0; dummy < randint1(5) + 1; dummy++)
4940                         {
4941                                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
4942                         }
4943 #ifdef JP
4944                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
4945 #else
4946                         reward = "summoning hostile monsters";
4947 #endif
4948                         break;
4949                 case REW_H_SUMMON:
4950 #ifdef JP
4951 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4952                                 chaos_patrons[p_ptr->chaos_patron]);
4953 #else
4954                         msg_format("The voice of %s booms out:",
4955                                 chaos_patrons[p_ptr->chaos_patron]);
4956 #endif
4957
4958 #ifdef JP
4959 msg_print("¡ÖÆò¡¢¤è¤ê¶¯¤­Å¨¤òɬÍפȤ»¤ê¡ª¡×");
4960 #else
4961                         msg_print("'Thou needst worthier opponents!'");
4962 #endif
4963
4964                         activate_hi_summon(py, px, FALSE);
4965 #ifdef JP
4966                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
4967 #else
4968                         reward = "summoning many hostile monsters";
4969 #endif
4970                         break;
4971                 case REW_DO_HAVOC:
4972 #ifdef JP
4973 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4974                                 chaos_patrons[p_ptr->chaos_patron]);
4975 #else
4976                         msg_format("The voice of %s booms out:",
4977                                 chaos_patrons[p_ptr->chaos_patron]);
4978 #endif
4979
4980 #ifdef JP
4981 msg_print("¡Ö»à¤ÈÇ˲õ¤³¤½²æ¤¬´î¤Ó¤Ê¤ê¡ª¡×");
4982 #else
4983                         msg_print("'Death and destruction! This pleaseth me!'");
4984 #endif
4985
4986                         call_chaos();
4987 #ifdef JP
4988                         reward = "¥«¥ª¥¹¤ÎÎϤ¬±²´¬¤¤¤¿¡£";
4989 #else
4990                         reward = "calling chaos";
4991 #endif
4992                         break;
4993                 case REW_GAIN_ABL:
4994 #ifdef JP
4995 msg_format("%s¤ÎÀ¼¤¬ÌĤê¶Á¤¤¤¿:",
4996                                 chaos_patrons[p_ptr->chaos_patron]);
4997 #else
4998                         msg_format("The voice of %s rings out:",
4999                                 chaos_patrons[p_ptr->chaos_patron]);
5000 #endif
5001
5002 #ifdef JP
5003 msg_print("¡Öα¤Þ¤ë¤Î¤À¡¢²¼Ëͤ衣;¤¬Æò¤ÎÆùÂΤòÃ䨤󡣡×");
5004 #else
5005                         msg_print("'Stay, mortal, and let me mold thee.'");
5006 #endif
5007
5008                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
5009                                 do_inc_stat(chaos_stats[p_ptr->chaos_patron]);
5010                         else
5011                                 do_inc_stat(randint0(6));
5012 #ifdef JP
5013                         reward = "ǽÎÏÃͤ¬¾å¤¬¤Ã¤¿¡£";
5014 #else
5015                         reward = "increasing a stat";
5016 #endif
5017                         break;
5018                 case REW_LOSE_ABL:
5019 #ifdef JP
5020 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5021                                 chaos_patrons[p_ptr->chaos_patron]);
5022 #else
5023                         msg_format("The voice of %s booms out:",
5024                                 chaos_patrons[p_ptr->chaos_patron]);
5025 #endif
5026
5027 #ifdef JP
5028 msg_print("¡Ö²¼Ëͤ衢;¤ÏÆò¤ËË°¤ß¤¿¤ê¡£¡×");
5029 #else
5030                         msg_print("'I grow tired of thee, mortal.'");
5031 #endif
5032
5033                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
5034                                 do_dec_stat(chaos_stats[p_ptr->chaos_patron]);
5035                         else
5036                                 (void)do_dec_stat(randint0(6));
5037 #ifdef JP
5038                         reward = "ǽÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5039 #else
5040                         reward = "decreasing a stat";
5041 #endif
5042                         break;
5043                 case REW_RUIN_ABL:
5044 #ifdef JP
5045 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5046                                 chaos_patrons[p_ptr->chaos_patron]);
5047 #else
5048                         msg_format("The voice of %s thunders:",
5049                                 chaos_patrons[p_ptr->chaos_patron]);
5050 #endif
5051
5052 #ifdef JP
5053 msg_print("¡ÖÆò¡¢¸¬µõ¤¿¤ë¤³¤È¤ò³Ø¤Ö¤Ù¤·¡ª¡×");
5054 msg_print("¤¢¤Ê¤¿¤Ï°ÊÁ°¤è¤ê¼å¤¯¤Ê¤Ã¤¿¡ª");
5055 #else
5056                         msg_print("'Thou needst a lesson in humility, mortal!'");
5057                         msg_print("You feel less powerful!");
5058 #endif
5059
5060                         for (dummy = 0; dummy < 6; dummy++)
5061                         {
5062                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5063                         }
5064 #ifdef JP
5065                         reward = "Á´Ç½ÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5066 #else
5067                         reward = "decreasing all stats";
5068 #endif
5069                         break;
5070                 case REW_POLY_WND:
5071 #ifdef JP
5072 msg_format("%s¤ÎÎϤ¬¿¨¤ì¤ë¤Î¤ò´¶¤¸¤¿¡£",
5073 #else
5074                         msg_format("You feel the power of %s touch you.",
5075 #endif
5076
5077                                 chaos_patrons[p_ptr->chaos_patron]);
5078                         do_poly_wounds();
5079 #ifdef JP
5080                         reward = "½ý¤¬ÊѲ½¤·¤¿¡£";
5081 #else
5082                         reward = "polymorphing wounds";
5083 #endif
5084                         break;
5085                 case REW_AUGM_ABL:
5086 #ifdef JP
5087 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5088                                 chaos_patrons[p_ptr->chaos_patron]);
5089 #else
5090                         msg_format("The voice of %s booms out:",
5091                                 chaos_patrons[p_ptr->chaos_patron]);
5092 #endif
5093
5094 #ifdef JP
5095 msg_print("¡Ö²æ¤¬¤µ¤µ¤ä¤«¤Ê¤ë»òʪ¤ò¼õ¤±¤È¤ë¤¬¤è¤¤¡ª¡×");
5096 #else
5097                         msg_print("'Receive this modest gift from me!'");
5098 #endif
5099
5100                         for (dummy = 0; dummy < 6; dummy++)
5101                         {
5102                                 (void)do_inc_stat(dummy);
5103                         }
5104 #ifdef JP
5105                         reward = "Á´Ç½ÎÏÃͤ¬¾å¤¬¤Ã¤¿¡£";
5106 #else
5107                         reward = "increasing all stats";
5108 #endif
5109                         break;
5110                 case REW_HURT_LOT:
5111 #ifdef JP
5112 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5113                                 chaos_patrons[p_ptr->chaos_patron]);
5114 #else
5115                         msg_format("The voice of %s booms out:",
5116                                 chaos_patrons[p_ptr->chaos_patron]);
5117 #endif
5118
5119 #ifdef JP
5120 msg_print("¡Ö¶ì¤·¤à¤¬¤è¤¤¡¢ÌµÇ½¤Ê¶ò¤«¼Ô¤è¡ª¡×");
5121 #else
5122                         msg_print("'Suffer, pathetic fool!'");
5123 #endif
5124
5125                         fire_ball(GF_DISINTEGRATE, 0, p_ptr->lev * 4, 4);
5126                         take_hit(DAMAGE_NOESCAPE, p_ptr->lev * 4, wrath_reason, -1);
5127 #ifdef JP
5128                         reward = "ʬ²ò¤Îµå¤¬È¯À¸¤·¤¿¡£";
5129 #else
5130                         reward = "generating disintegration ball";
5131 #endif
5132                         break;
5133            case REW_HEAL_FUL:
5134 #ifdef JP
5135 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5136                                 chaos_patrons[p_ptr->chaos_patron]);
5137 #else
5138                         msg_format("The voice of %s booms out:",
5139                                 chaos_patrons[p_ptr->chaos_patron]);
5140 #endif
5141
5142 #ifdef JP
5143 msg_print("¡Öᴤ뤬¤è¤¤¡¢²æ¤¬²¼Ëͤ衪¡×");
5144 #else
5145                         msg_print("'Rise, my servant!'");
5146 #endif
5147
5148                         restore_level();
5149                         (void)set_poisoned(0);
5150                         (void)set_blind(0);
5151                         (void)set_confused(0);
5152                         (void)set_image(0);
5153                         (void)set_stun(0);
5154                         (void)set_cut(0);
5155                         hp_player(5000);
5156                         for (dummy = 0; dummy < 6; dummy++)
5157                         {
5158                                 (void)do_res_stat(dummy);
5159                         }
5160 #ifdef JP
5161                         reward = "ÂÎÎϤ¬²óÉü¤·¤¿¡£";
5162 #else
5163                         reward = "healing";
5164 #endif
5165                         break;
5166                 case REW_CURSE_WP:
5167                         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
5168 #ifdef JP
5169 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5170                                 chaos_patrons[p_ptr->chaos_patron]);
5171 #else
5172                         msg_format("The voice of %s booms out:",
5173                                 chaos_patrons[p_ptr->chaos_patron]);
5174 #endif
5175
5176 #ifdef JP
5177 msg_print("¡ÖÆò¡¢Éð´ï¤ËÍê¤ë¤³¤È¤Ê¤«¤ì¡£¡×");
5178 #else
5179                         msg_print("'Thou reliest too much on thy weapon.'");
5180 #endif
5181
5182                         dummy = INVEN_RARM;
5183                         if (buki_motteruka(INVEN_LARM))
5184                         {
5185                                 dummy = INVEN_LARM;
5186                                 if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
5187                         }
5188                         object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
5189                         (void)curse_weapon(FALSE, dummy);
5190 #ifdef JP
5191                         reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5192 #else
5193                         reward = format("destroying %s", o_name);
5194 #endif
5195                         break;
5196                 case REW_CURSE_AR:
5197                         if (!inventory[INVEN_BODY].k_idx) break;
5198 #ifdef JP
5199 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5200                                 chaos_patrons[p_ptr->chaos_patron]);
5201 #else
5202                         msg_format("The voice of %s booms out:",
5203                                 chaos_patrons[p_ptr->chaos_patron]);
5204 #endif
5205
5206 #ifdef JP
5207 msg_print("¡ÖÆò¡¢Ëɶñ¤ËÍê¤ë¤³¤È¤Ê¤«¤ì¡£¡×");
5208 #else
5209                         msg_print("'Thou reliest too much on thine equipment.'");
5210 #endif
5211
5212                         object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
5213                         (void)curse_armor();
5214 #ifdef JP
5215                         reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5216 #else
5217                         reward = format("destroying %s", o_name);
5218 #endif
5219                         break;
5220                 case REW_PISS_OFF:
5221 #ifdef JP
5222 msg_format("%s¤ÎÀ¼¤¬¤µ¤µ¤ä¤¤¤¿:",
5223                                 chaos_patrons[p_ptr->chaos_patron]);
5224 #else
5225                         msg_format("The voice of %s whispers:",
5226                                 chaos_patrons[p_ptr->chaos_patron]);
5227 #endif
5228
5229 #ifdef JP
5230 msg_print("¡Ö²æ¤òÅܤꤷ¤á¤¿ºá¤ò½þ¤¦¤Ù¤·¡£¡×");
5231 #else
5232                         msg_print("'Now thou shalt pay for annoying me.'");
5233 #endif
5234
5235                         switch (randint1(4))
5236                         {
5237                                 case 1:
5238                                         (void)activate_ty_curse(FALSE, &count);
5239 #ifdef JP
5240                                         reward = "²Ò¡¹¤·¤¤¼ö¤¤¤ò¤«¤±¤é¤ì¤¿¡£";
5241 #else
5242                                         reward = "cursing";
5243 #endif
5244                                         break;
5245                                 case 2:
5246                                         activate_hi_summon(py, px, FALSE);
5247 #ifdef JP
5248                                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
5249 #else
5250                                         reward = "summoning hostile monsters";
5251 #endif
5252                                         break;
5253                                 case 3:
5254                                         if (one_in_(2))
5255                                         {
5256                                                 if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
5257                                                 dummy = INVEN_RARM;
5258                                                 if (buki_motteruka(INVEN_LARM))
5259                                                 {
5260                                                         dummy = INVEN_LARM;
5261                                                         if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
5262                                                 }
5263                                                 object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
5264                                                 (void)curse_weapon(FALSE, dummy);
5265 #ifdef JP
5266                                                 reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5267 #else
5268                                                 reward = format("destroying %s", o_name);
5269 #endif
5270                                         }
5271                                         else
5272                                         {
5273                                                 if (!inventory[INVEN_BODY].k_idx) break;
5274                                                 object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
5275                                                 (void)curse_armor();
5276 #ifdef JP
5277                                                 reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5278 #else
5279                                                 reward = format("destroying %s", o_name);
5280 #endif
5281                                         }
5282                                         break;
5283                                 default:
5284                                         for (dummy = 0; dummy < 6; dummy++)
5285                                         {
5286                                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5287                                         }
5288 #ifdef JP
5289                                         reward = "Á´Ç½ÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5290 #else
5291                                         reward = "decreasing all stats";
5292 #endif
5293                                         break;
5294                         }
5295                         break;
5296                 case REW_WRATH:
5297 #ifdef JP
5298 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5299 #else
5300                         msg_format("The voice of %s thunders:",
5301 #endif
5302
5303                                 chaos_patrons[p_ptr->chaos_patron]);
5304 #ifdef JP
5305 msg_print("¡Ö»à¤Ì¤¬¤è¤¤¡¢²¼Ëͤ衪¡×");
5306 #else
5307                         msg_print("'Die, mortal!'");
5308 #endif
5309
5310                         take_hit(DAMAGE_LOSELIFE, p_ptr->lev * 4, wrath_reason, -1);
5311                         for (dummy = 0; dummy < 6; dummy++)
5312                         {
5313                                 (void)dec_stat(dummy, 10 + randint1(15), FALSE);
5314                         }
5315                         activate_hi_summon(py, px, FALSE);
5316                         (void)activate_ty_curse(FALSE, &count);
5317                         if (one_in_(2))
5318                         {
5319                                 dummy = 0;
5320
5321                                 if (buki_motteruka(INVEN_RARM))
5322                                 {
5323                                         dummy = INVEN_RARM;
5324                                         if (buki_motteruka(INVEN_LARM) && one_in_(2)) dummy = INVEN_LARM;
5325                                 }
5326                                 else if (buki_motteruka(INVEN_LARM)) dummy = INVEN_LARM;
5327
5328                                 if (dummy) (void)curse_weapon(FALSE, dummy);
5329                         }
5330                         if (one_in_(2)) (void)curse_armor();
5331                         break;
5332                 case REW_DESTRUCT:
5333 #ifdef JP
5334 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5335                                 chaos_patrons[p_ptr->chaos_patron]);
5336 #else
5337                         msg_format("The voice of %s booms out:",
5338                                 chaos_patrons[p_ptr->chaos_patron]);
5339 #endif
5340
5341 #ifdef JP
5342 msg_print("¡Ö»à¤ÈÇ˲õ¤³¤½²æ¤¬´î¤Ó¤Ê¤ê¡ª¡×");
5343 #else
5344                         msg_print("'Death and destruction! This pleaseth me!'");
5345 #endif
5346
5347                         (void)destroy_area(py, px, 25, FALSE);
5348 #ifdef JP
5349                         reward = "¥À¥ó¥¸¥ç¥ó¤¬*Ç˲õ*¤µ¤ì¤¿¡£";
5350 #else
5351                         reward = "*destruct*ing dungeon";
5352 #endif
5353                         break;
5354                 case REW_GENOCIDE:
5355 #ifdef JP
5356 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5357                                 chaos_patrons[p_ptr->chaos_patron]);
5358 #else
5359                         msg_format("The voice of %s booms out:",
5360                                 chaos_patrons[p_ptr->chaos_patron]);
5361 #endif
5362
5363 #ifdef JP
5364 msg_print("¡Ö²æ¡¢Æò¤ÎŨ¤òËõ»¦¤»¤ó¡ª¡×");
5365 #else
5366                         msg_print("'Let me relieve thee of thine oppressors!'");
5367 #endif
5368
5369                         (void)symbol_genocide(0, FALSE);
5370 #ifdef JP
5371                         reward = "¥â¥ó¥¹¥¿¡¼¤¬Ëõ»¦¤µ¤ì¤¿¡£";
5372 #else
5373                         reward = "genociding monsters";
5374 #endif
5375                         break;
5376                 case REW_MASS_GEN:
5377 #ifdef JP
5378 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5379                                 chaos_patrons[p_ptr->chaos_patron]);
5380 #else
5381                         msg_format("The voice of %s booms out:",
5382                                 chaos_patrons[p_ptr->chaos_patron]);
5383 #endif
5384
5385 #ifdef JP
5386 msg_print("¡Ö²æ¡¢Æò¤ÎŨ¤òËõ»¦¤»¤ó¡ª¡×");
5387 #else
5388                         msg_print("'Let me relieve thee of thine oppressors!'");
5389 #endif
5390
5391                         (void)mass_genocide(0, FALSE);
5392 #ifdef JP
5393                         reward = "¥â¥ó¥¹¥¿¡¼¤¬Ëõ»¦¤µ¤ì¤¿¡£";
5394 #else
5395                         reward = "genociding nearby monsters";
5396 #endif
5397                         break;
5398                 case REW_DISPEL_C:
5399 #ifdef JP
5400 msg_format("%s¤ÎÎϤ¬Å¨¤ò¹¶·â¤¹¤ë¤Î¤ò´¶¤¸¤¿¡ª",
5401                                 chaos_patrons[p_ptr->chaos_patron]);
5402 #else
5403                         msg_format("You can feel the power of %s assault your enemies!",
5404                                 chaos_patrons[p_ptr->chaos_patron]);
5405 #endif
5406
5407                         (void)dispel_monsters(p_ptr->lev * 4);
5408                         break;
5409                 case REW_IGNORE:
5410 #ifdef JP
5411 msg_format("%s¤Ï¤¢¤Ê¤¿¤ò̵»ë¤·¤¿¡£",
5412                                 chaos_patrons[p_ptr->chaos_patron]);
5413 #else
5414                         msg_format("%s ignores you.",
5415                                 chaos_patrons[p_ptr->chaos_patron]);
5416 #endif
5417
5418                         break;
5419                 case REW_SER_DEMO:
5420 #ifdef JP
5421 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ°­Ëâ¤Î»È¤¤¤ò¤è¤³¤·¤¿¡ª",chaos_patrons[p_ptr->chaos_patron]);
5422 #else
5423                         msg_format("%s rewards you with a demonic servant!",chaos_patrons[p_ptr->chaos_patron]);
5424 #endif
5425
5426                         if (!summon_specific(-1, py, px, dun_level, SUMMON_DEMON, PM_FORCE_PET))
5427 #ifdef JP
5428 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5429 #else
5430                                 msg_print("Nobody ever turns up...");
5431 #endif
5432                         else
5433 #ifdef JP
5434                                 reward = "°­Ë⤬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5435 #else
5436                                 reward = "a demonic servant";
5437 #endif
5438
5439                         break;
5440                 case REW_SER_MONS:
5441 #ifdef JP
5442 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ»È¤¤¤ò¤è¤³¤·¤¿¡ª",chaos_patrons[p_ptr->chaos_patron]);
5443 #else
5444                         msg_format("%s rewards you with a servant!",chaos_patrons[p_ptr->chaos_patron]);
5445 #endif
5446
5447                         if (!summon_specific(-1, py, px, dun_level, 0, PM_FORCE_PET))
5448 #ifdef JP
5449 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5450 #else
5451                                 msg_print("Nobody ever turns up...");
5452 #endif
5453                         else
5454 #ifdef JP
5455                                 reward = "¥â¥ó¥¹¥¿¡¼¤¬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5456 #else
5457                                 reward = "a servant";
5458 #endif
5459
5460                         break;
5461                 case REW_SER_UNDE:
5462 #ifdef JP
5463 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ¥¢¥ó¥Ç¥Ã¥É¤Î»È¤¤¤ò¤è¤³¤·¤¿¡£",chaos_patrons[p_ptr->chaos_patron]);
5464 #else
5465                         msg_format("%s rewards you with an undead servant!",chaos_patrons[p_ptr->chaos_patron]);
5466 #endif
5467
5468                         if (!summon_specific(-1, py, px, dun_level, SUMMON_UNDEAD, PM_FORCE_PET))
5469 #ifdef JP
5470 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5471 #else
5472                                 msg_print("Nobody ever turns up...");
5473 #endif
5474                         else
5475 #ifdef JP
5476                                 reward = "¥¢¥ó¥Ç¥Ã¥É¤¬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5477 #else
5478                                 reward = "an undead servant";
5479 #endif
5480
5481                         break;
5482                 default:
5483 #ifdef JP
5484 msg_format("%s¤ÎÀ¼¤¬¤É¤â¤Ã¤¿:",
5485 #else
5486                         msg_format("The voice of %s stammers:",
5487 #endif
5488
5489                                 chaos_patrons[p_ptr->chaos_patron]);
5490 #ifdef JP
5491 msg_format("¡Ö¤¢¡¼¡¢¤¢¡¼¡¢Åú¤¨¤Ï %d/%d¡£¼ÁÌä¤Ï²¿¡©¡×", type, effect);
5492 #else
5493                         msg_format("'Uh... uh... the answer's %d/%d, what's the question?'", type, effect);
5494 #endif
5495
5496         }
5497         }
5498         if (reward)
5499         {
5500 #ifdef JP
5501                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format("¥Ñ¥È¥í¥ó¤ÎÊó½·¤Ç%s", reward));
5502 #else
5503                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format("The patron rewards you with %s.", reward));
5504 #endif
5505         }
5506 }
5507
5508
5509 /*
5510  * old -- from PsiAngband.
5511  */
5512 bool tgt_pt(int *x_ptr, int *y_ptr)
5513 {
5514         char ch = 0;
5515         int d, x, y;
5516         bool success = FALSE;
5517
5518         int wid, hgt;
5519
5520         /* Get size */
5521         get_screen_size(&wid, &hgt);
5522
5523         x = px;
5524         y = py;
5525
5526 #ifdef JP
5527 msg_print("¾ì½ê¤òÁª¤ó¤Ç¥¹¥Ú¡¼¥¹¥­¡¼¤ò²¡¤·¤Æ²¼¤µ¤¤¡£");
5528 #else
5529         msg_print("Select a point and press space.");
5530 #endif
5531         msg_flag = FALSE; /* prevents "-more-" message. */
5532
5533         while ((ch != ESCAPE) && !success)
5534         {
5535                 bool move_fast = FALSE;
5536
5537                 move_cursor_relative(y, x);
5538                 ch = inkey();
5539                 switch (ch)
5540                 {
5541                 case ESCAPE:
5542                         break;
5543                 case ' ':
5544                 case 't':
5545                 case '.':
5546                 case '5':
5547                 case '0':
5548                         /* illegal place */
5549                         if (player_bold(y, x)) ch = 0;
5550
5551                         /* okay place */
5552                         else success = TRUE;
5553
5554                         break;
5555                 default:
5556                         /* Look up the direction */
5557                         d = get_keymap_dir(ch);
5558
5559                         /* XTRA HACK MOVEFAST */
5560                         if (isupper(ch)) move_fast = TRUE;
5561
5562                         /* Handle "direction" */
5563                         if (d)
5564                         {
5565                                 int dx = ddx[d];
5566                                 int dy = ddy[d];
5567
5568                                 /* XTRA HACK MOVEFAST */
5569                                 if (move_fast)
5570                                 {
5571                                         int mag = MIN(wid / 2, hgt / 2);
5572                                         x += dx * mag;
5573                                         y += dy * mag;
5574                                 }
5575                                 else
5576                                 {
5577                                         x += dx;
5578                                         y += dy;
5579                                 }
5580
5581                                 /* Do not move horizontally if unnecessary */
5582                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
5583                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
5584                                 {
5585                                         dx = 0;
5586                                 }
5587
5588                                 /* Do not move vertically if unnecessary */
5589                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
5590                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
5591                                 {
5592                                         dy = 0;
5593                                 }
5594
5595                                 /* Apply the motion */
5596                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
5597                                          (x >= panel_col_min + wid) || (x < panel_col_min))
5598                                 {
5599                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
5600                                         change_panel(dy, dx);
5601                                 }
5602
5603                                 /* Slide into legality */
5604                                 if (x >= cur_wid-1) x = cur_wid - 2;
5605                                 else if (x <= 0) x = 1;
5606
5607                                 /* Slide into legality */
5608                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
5609                                 else if (y <= 0) y = 1;
5610
5611                         }
5612                         break;
5613                 }
5614         }
5615
5616         /* Clear the top line */
5617         prt("", 0, 0);
5618
5619         /* Recenter the map around the player */
5620         verify_panel();
5621
5622         /* Update stuff */
5623         p_ptr->update |= (PU_MONSTERS);
5624
5625         /* Redraw map */
5626         p_ptr->redraw |= (PR_MAP);
5627
5628         /* Window stuff */
5629         p_ptr->window |= (PW_OVERHEAD);
5630
5631         /* Handle stuff */
5632         handle_stuff();
5633
5634         *x_ptr = x;
5635         *y_ptr = y;
5636         return success;
5637 }
5638
5639
5640 bool get_hack_dir(int *dp)
5641 {
5642         int             dir;
5643         cptr    p;
5644         char    command;
5645
5646
5647         /* Initialize */
5648         (*dp) = 0;
5649
5650         /* Global direction */
5651         dir = 0;
5652
5653         /* (No auto-targeting) */
5654
5655         /* Ask until satisfied */
5656         while (!dir)
5657         {
5658                 /* Choose a prompt */
5659                 if (!target_okay())
5660                 {
5661 #ifdef JP
5662 p = "Êý¸þ ('*'¤Ç¥¿¡¼¥²¥Ã¥ÈÁªÂò, ESC¤ÇÃæÃÇ)? ";
5663 #else
5664                         p = "Direction ('*' to choose a target, Escape to cancel)? ";
5665 #endif
5666
5667                 }
5668                 else
5669                 {
5670 #ifdef JP
5671 p = "Êý¸þ ('5'¤Ç¥¿¡¼¥²¥Ã¥È¤Ø, '*'¤Ç¥¿¡¼¥²¥Ã¥ÈºÆÁªÂò, ESC¤ÇÃæÃÇ)? ";
5672 #else
5673                         p = "Direction ('5' for target, '*' to re-target, Escape to cancel)? ";
5674 #endif
5675
5676                 }
5677
5678                 /* Get a command (or Cancel) */
5679                 if (!get_com(p, &command, TRUE)) break;
5680
5681                 if (use_menu)
5682                 {
5683                         if (command == '\r') command = 't';
5684                 }  
5685
5686                 /* Convert various keys to "standard" keys */
5687                 switch (command)
5688                 {
5689                         /* Use current target */
5690                         case 'T':
5691                         case 't':
5692                         case '.':
5693                         case '5':
5694                         case '0':
5695                         {
5696                                 dir = 5;
5697                                 break;
5698                         }
5699
5700                         /* Set new target */
5701                         case '*':
5702                         case ' ':
5703                         case '\r':
5704                         {
5705                                 if (target_set(TARGET_KILL)) dir = 5;
5706                                 break;
5707                         }
5708
5709                         default:
5710                         {
5711                                 /* Look up the direction */
5712                                 dir = get_keymap_dir(command);
5713
5714                                 break;
5715                         }
5716                 }
5717
5718                 /* Verify requested targets */
5719                 if ((dir == 5) && !target_okay()) dir = 0;
5720
5721                 /* Error */
5722                 if (!dir) bell();
5723         }
5724
5725         /* No direction */
5726         if (!dir) return (FALSE);
5727
5728         /* Save the direction */
5729         command_dir = dir;
5730
5731         /* Check for confusion */
5732         if (p_ptr->confused)
5733         {
5734                 /* XXX XXX XXX */
5735                 /* Random direction */
5736                 dir = ddd[randint0(8)];
5737         }
5738
5739         /* Notice confusion */
5740         if (command_dir != dir)
5741         {
5742                 /* Warn the user */
5743 #ifdef JP
5744 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
5745 #else
5746                 msg_print("You are confused.");
5747 #endif
5748
5749         }
5750
5751         /* Save direction */
5752         (*dp) = dir;
5753
5754         /* A "valid" direction was entered */
5755         return (TRUE);
5756 }
5757
5758
5759 /*
5760  * ¥¨¥Í¥ë¥®¡¼¤ÎÁý²ÃÎÌ10d5¤ò®¤¯·×»»¤¹¤ë¤¿¤á¤Î´Ø¿ô
5761  */
5762
5763 #define Go_no_JuuJou 5*5*5*5*5*5*5*5*5*5
5764
5765 s16b gain_energy(void)
5766 {
5767         int i;
5768         s32b energy_result = 10;
5769         s32b tmp;
5770
5771         tmp = randint0(Go_no_JuuJou);
5772
5773         for (i = 0; i < 9; i ++){
5774                 energy_result += tmp % 5;
5775                 tmp /= 5;
5776         }
5777
5778         return (s16b)(energy_result + tmp);
5779 }
5780
5781
5782 /*
5783  * Return bow energy 
5784  */
5785 s16b bow_energy(int sval)
5786 {
5787         int energy = 100;
5788
5789         /* Analyze the launcher */
5790         switch (sval)
5791         {
5792                 /* Sling and ammo */
5793                 case SV_SLING:
5794                 {
5795                         energy = 8000;
5796                         break;
5797                 }
5798
5799                 /* Short Bow and Arrow */
5800                 case SV_SHORT_BOW:
5801                 {
5802                         energy = 10000;
5803                         break;
5804                 }
5805
5806                 /* Long Bow and Arrow */
5807                 case SV_LONG_BOW:
5808                 {
5809                         energy = 10000;
5810                         break;
5811                 }
5812
5813                 /* Bow of irresponsiblity and Arrow */
5814                 case SV_NAMAKE_BOW:
5815                 {
5816                         energy = 7777;
5817                         break;
5818                 }
5819
5820                 /* Light Crossbow and Bolt */
5821                 case SV_LIGHT_XBOW:
5822                 {
5823                         energy = 12000;
5824                         break;
5825                 }
5826
5827                 /* Heavy Crossbow and Bolt */
5828                 case SV_HEAVY_XBOW:
5829                 {
5830                         energy = 13333;
5831                         break;
5832                 }
5833         }
5834
5835         return (energy);
5836 }
5837
5838
5839 /*
5840  * Return bow tmul
5841  */
5842 int bow_tmul(int sval)
5843 {
5844         int tmul = 0;
5845
5846         /* Analyze the launcher */
5847         switch (sval)
5848         {
5849                 /* Sling and ammo */
5850                 case SV_SLING:
5851                 {
5852                         tmul = 2;
5853                         break;
5854                 }
5855
5856                 /* Short Bow and Arrow */
5857                 case SV_SHORT_BOW:
5858                 {
5859                         tmul = 2;
5860                         break;
5861                 }
5862
5863                 /* Long Bow and Arrow */
5864                 case SV_LONG_BOW:
5865                 {
5866                         tmul = 3;
5867                         break;
5868                 }
5869
5870                 /* Bow of irresponsiblity and Arrow */
5871                 case SV_NAMAKE_BOW:
5872                 {
5873                         tmul = 3;
5874                         break;
5875                 }
5876
5877                 /* Light Crossbow and Bolt */
5878                 case SV_LIGHT_XBOW:
5879                 {
5880                         tmul = 3;
5881                         break;
5882                 }
5883
5884                 /* Heavy Crossbow and Bolt */
5885                 case SV_HEAVY_XBOW:
5886                 {
5887                         tmul = 4;
5888                         break;
5889                 }
5890         }
5891
5892         return (tmul);
5893 }
5894
5895 /*
5896  * Return alignment title
5897  */
5898 cptr your_alignment(void)
5899 {
5900 #ifdef JP
5901         if (p_ptr->align > 150) return "ÂçÁ±";
5902         else if (p_ptr->align > 50) return "ÃæÁ±";
5903         else if (p_ptr->align > 10) return "¾®Á±";
5904         else if (p_ptr->align > -11) return "ÃæΩ";
5905         else if (p_ptr->align > -51) return "¾®°­";
5906         else if (p_ptr->align > -151) return "Ãæ°­";
5907         else return "Âç°­";
5908 #else
5909         if (p_ptr->align > 150) return "Lawful";
5910         else if (p_ptr->align > 50) return "Good";
5911         else if (p_ptr->align > 10) return "Neutral Good";
5912         else if (p_ptr->align > -11) return "Neutral";
5913         else if (p_ptr->align > -51) return "Neutral Evil";
5914         else if (p_ptr->align > -151) return "Evil";
5915         else return "Chaotic";
5916 #endif
5917 }
5918
5919
5920 /*
5921  * Return proficiency level of weapons and misc. skills (except riding)
5922  */
5923 int weapon_exp_level(int weapon_exp)
5924 {
5925         if (weapon_exp < WEAPON_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5926         else if (weapon_exp < WEAPON_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5927         else if (weapon_exp < WEAPON_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5928         else if (weapon_exp < WEAPON_EXP_MASTER) return EXP_LEVEL_EXPERT;
5929         else return EXP_LEVEL_MASTER;
5930 }
5931
5932
5933 /*
5934  * Return proficiency level of riding
5935  */
5936 int riding_exp_level(int riding_exp)
5937 {
5938         if (riding_exp < RIDING_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5939         else if (riding_exp < RIDING_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5940         else if (riding_exp < RIDING_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5941         else if (riding_exp < RIDING_EXP_MASTER) return EXP_LEVEL_EXPERT;
5942         else return EXP_LEVEL_MASTER;
5943 }
5944
5945
5946 /*
5947  * Return proficiency level of spells
5948  */
5949 int spell_exp_level(int spell_exp)
5950 {
5951         if (spell_exp < SPELL_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5952         else if (spell_exp < SPELL_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5953         else if (spell_exp < SPELL_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5954         else if (spell_exp < SPELL_EXP_MASTER) return EXP_LEVEL_EXPERT;
5955         else return EXP_LEVEL_MASTER;
5956 }