OSDN Git Service

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