OSDN Git Service

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