OSDN Git Service

acce58b3c531096032fd7128acd5f61346aa8c70
[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 > (u32b)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 > (u32b)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  * @brief ¸½ºß¤Î¥³¥ó¥½¡¼¥ëɽ¼¨¤Î½Ä²£¤òÊÖ¤¹¡£ /
2316  * Get term size and calculate screen size
2317  * @param wid_p ¥³¥ó¥½¡¼¥ë¤Îɽ¼¨Éýʸ»ú¿ô¤òÊÖ¤¹
2318  * @param hgt_p ¥³¥ó¥½¡¼¥ë¤Îɽ¼¨¹Ô¿ô¤òÊÖ¤¹
2319  * @return ¤Ê¤·
2320  */
2321 void get_screen_size(int *wid_p, int *hgt_p)
2322 {
2323         Term_get_size(wid_p, hgt_p);
2324         *hgt_p -= ROW_MAP + 2;
2325         *wid_p -= COL_MAP + 2;
2326         if (use_bigtile) *wid_p /= 2;
2327 }
2328
2329
2330 /*!
2331  * @brief ¥³¥ó¥½¡¼¥ë¾å¤Ë¤ª¤±¤ë¥Þ¥Ã¥×ɽ¼¨¤Îº¸¾å°ÌÃÖ¤òÊÖ¤¹ /
2332  * Calculates current boundaries Called below and from "do_cmd_locate()".
2333  * @return ¤Ê¤·
2334  */
2335 void panel_bounds_center(void)
2336 {
2337         int wid, hgt;
2338
2339         /* Get size */
2340         get_screen_size(&wid, &hgt);
2341
2342         panel_row_max = panel_row_min + hgt - 1;
2343         panel_row_prt = panel_row_min - 1;
2344         panel_col_max = panel_col_min + wid - 1;
2345         panel_col_prt = panel_col_min - 13;
2346 }
2347
2348
2349 /*!
2350  * @brief ¥³¥ó¥½¡¼¥ë¤Î¥ê¥µ¥¤¥º¤Ë¹ç¤ï¤»¤Æ¥Þ¥Ã¥×¤òºÆÉÁ²è¤¹¤ë /
2351  * Map resizing whenever the main term changes size
2352  * @return ¤Ê¤·
2353  */
2354 void resize_map(void)
2355 {
2356         /* Only if the dungeon exists */
2357         if (!character_dungeon) return;
2358         
2359         /* Mega-Hack -- no panel yet */
2360         panel_row_max = 0;
2361         panel_col_max = 0;
2362
2363         /* Reset the panels */
2364         panel_row_min = cur_hgt;
2365         panel_col_min = cur_wid;
2366                                 
2367         verify_panel();
2368
2369         /* Update stuff */
2370         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
2371
2372         /* Forget lite/view */
2373         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
2374
2375         /* Update lite/view */
2376         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
2377
2378         /* Update monsters */
2379         p_ptr->update |= (PU_MONSTERS);
2380
2381         /* Redraw everything */
2382         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
2383
2384         /* Hack -- update */
2385         handle_stuff();
2386         
2387         /* Redraw */
2388         Term_redraw();
2389
2390         /*
2391          * Waiting command;
2392          * Place the cursor on the player
2393          */
2394         if (can_save) move_cursor_relative(py, px);
2395
2396         /* Refresh */
2397         Term_fresh();
2398 }
2399
2400 /*!
2401  * @brief ¥³¥ó¥½¡¼¥ë¤òºÆÉÁ²è¤¹¤ë /
2402  * Redraw a term when it is resized
2403  * @return ¤Ê¤·
2404  */
2405 void redraw_window(void)
2406 {
2407         /* Only if the dungeon exists */
2408         if (!character_dungeon) return;
2409
2410         /* Window stuff */
2411         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
2412
2413         /* Window stuff */
2414         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
2415
2416         /* Hack -- update */
2417         handle_stuff();
2418
2419         /* Redraw */
2420         Term_redraw();
2421 }
2422
2423
2424 /*!
2425  * @brief ¥Õ¥©¡¼¥«¥¹¤òÅö¤Æ¤ë¤Ù¤­¥Þ¥Ã¥×ÉÁ²è¤Î´ð½àºÂɸ¤ò»ØÄꤹ¤ë¡Ê¥µ¥Ö¥ë¡¼¥Á¥ó¡Ë
2426  * @param dy Êѹ¹Àè¤Î¥Õ¥í¥¢YºÂɸ
2427  * @param dx Êѹ¹Àè¤Î¥Õ¥í¥¢XºÂɸ
2428  * Handle a request to change the current panel
2429  * Return TRUE if the panel was changed.
2430  * Also used in do_cmd_locate
2431  * @return ¼ÂºÝ¤ËºÆÉÁ²è¤¬É¬ÍפÀ¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
2432  */
2433 bool change_panel(int dy, int dx)
2434 {
2435         int y, x;
2436         int wid, hgt;
2437
2438         /* Get size */
2439         get_screen_size(&wid, &hgt);
2440
2441         /* Apply the motion */
2442         y = panel_row_min + dy * hgt / 2;
2443         x = panel_col_min + dx * wid / 2;
2444
2445         /* Verify the row */
2446         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
2447         if (y < 0) y = 0;
2448
2449         /* Verify the col */
2450         if (x > cur_wid - wid) x = cur_wid - wid;
2451         if (x < 0) x = 0;
2452
2453         /* Handle "changes" */
2454         if ((y != panel_row_min) || (x != panel_col_min))
2455         {
2456                 /* Save the new panel info */
2457                 panel_row_min = y;
2458                 panel_col_min = x;
2459
2460                 /* Recalculate the boundaries */
2461                 panel_bounds_center();
2462
2463                 /* Update stuff */
2464                 p_ptr->update |= (PU_MONSTERS);
2465
2466                 /* Redraw map */
2467                 p_ptr->redraw |= (PR_MAP);
2468
2469                 /* Handle stuff */
2470                 handle_stuff();
2471
2472                 /* Success */
2473                 return (TRUE);
2474         }
2475
2476         /* No change */
2477         return (FALSE);
2478 }
2479
2480 /*!
2481  * @brief ¥Õ¥©¡¼¥«¥¹¤òÅö¤Æ¤ë¤Ù¤­¥Þ¥Ã¥×ÉÁ²è¤Î´ð½àºÂɸ¤ò»ØÄꤹ¤ë
2482  * @param y Êѹ¹Àè¤Î¥Õ¥í¥¢YºÂɸ
2483  * @param x Êѹ¹Àè¤Î¥Õ¥í¥¢XºÂɸ
2484  * @details
2485  * Handle a request to change the current panel
2486  * Return TRUE if the panel was changed.
2487  * Also used in do_cmd_locate
2488  * @return ¼ÂºÝ¤ËºÆÉÁ²è¤¬É¬ÍפÀ¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
2489  */
2490 bool change_panel_xy(int y, int x)
2491 {
2492         int dy = 0, dx = 0;
2493         int wid, hgt;
2494
2495         /* Get size */
2496         get_screen_size(&wid, &hgt);
2497
2498         if (y < panel_row_min) dy = -1;
2499         if (y > panel_row_max) dy = 1;
2500         if (x < panel_col_min) dx = -1;
2501         if (x > panel_col_max) dx = 1;
2502
2503         if (!dy && !dx) return (FALSE);
2504
2505         return change_panel(dy, dx);
2506 }
2507
2508
2509 /*!
2510  * @brief ¥Þ¥Ã¥×ÉÁ²è¤Î¥Õ¥©¡¼¥«¥¹¤òÅö¤Æ¤ë¤Ù¤­ºÂɸ¤ò¹¹¿·¤¹¤ë
2511  * @details
2512  * Given an row (y) and col (x), this routine detects when a move
2513  * off the screen has occurred and figures new borders. -RAK-
2514  * "Update" forces a "full update" to take place.
2515  * The map is reprinted if necessary, and "TRUE" is returned.
2516  * @return ¼ÂºÝ¤ËºÆÉÁ²è¤¬É¬ÍפÀ¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
2517  */
2518 void verify_panel(void)
2519 {
2520         int y = py;
2521         int x = px;
2522         int wid, hgt;
2523
2524         int prow_min;
2525         int pcol_min;
2526         int max_prow_min;
2527         int max_pcol_min;
2528
2529         /* Get size */
2530         get_screen_size(&wid, &hgt);
2531
2532         max_prow_min = cur_hgt - hgt;
2533         max_pcol_min = cur_wid - wid;
2534
2535         /* Bounds checking */
2536         if (max_prow_min < 0) max_prow_min = 0;
2537         if (max_pcol_min < 0) max_pcol_min = 0;
2538
2539                 /* Center on player */
2540         if (center_player && (center_running || !running))
2541         {
2542                 /* Center vertically */
2543                 prow_min = y - hgt / 2;
2544                 if (prow_min < 0) prow_min = 0;
2545                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
2546
2547                 /* Center horizontally */
2548                 pcol_min = x - wid / 2;
2549                 if (pcol_min < 0) pcol_min = 0;
2550                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2551         }
2552         else
2553         {
2554                 prow_min = panel_row_min;
2555                 pcol_min = panel_col_min;
2556
2557                 /* Scroll screen when 2 grids from top/bottom edge */
2558                 if (y > panel_row_max - 2)
2559                 {
2560                         while (y > prow_min + hgt-1 - 2)
2561                         {
2562                                 prow_min += (hgt / 2);
2563                         }
2564                 }
2565
2566                 if (y < panel_row_min + 2)
2567                 {
2568                         while (y < prow_min + 2)
2569                         {
2570                                 prow_min -= (hgt / 2);
2571                         }
2572                 }
2573
2574                 if (prow_min > max_prow_min) prow_min = max_prow_min;
2575                 if (prow_min < 0) prow_min = 0;
2576
2577                 /* Scroll screen when 4 grids from left/right edge */
2578                 if (x > panel_col_max - 4)
2579                 {
2580                         while (x > pcol_min + wid-1 - 4)
2581                         {
2582                                 pcol_min += (wid / 2);
2583                         }
2584                 }
2585                 
2586                 if (x < panel_col_min + 4)
2587                 {
2588                         while (x < pcol_min + 4)
2589                         {
2590                                 pcol_min -= (wid / 2);
2591                         }
2592                 }
2593
2594                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2595                 if (pcol_min < 0) pcol_min = 0;
2596         }
2597
2598         /* Check for "no change" */
2599         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
2600
2601         /* Save the new panel info */
2602         panel_row_min = prow_min;
2603         panel_col_min = pcol_min;
2604
2605         /* Hack -- optional disturb on "panel change" */
2606         if (disturb_panel && !center_player) disturb(0, 0);
2607
2608         /* Recalculate the boundaries */
2609         panel_bounds_center();
2610
2611         /* Update stuff */
2612         p_ptr->update |= (PU_MONSTERS);
2613
2614         /* Redraw map */
2615         p_ptr->redraw |= (PR_MAP);
2616
2617         /* Window stuff */
2618         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2619 }
2620
2621
2622 /*
2623  * Monster health description
2624  */
2625 cptr look_mon_desc(monster_type *m_ptr, u32b mode)
2626 {
2627         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2628         bool         living;
2629         int          perc;
2630         cptr desc;
2631         cptr attitude;
2632         cptr clone;
2633
2634         /* Determine if the monster is "living" */
2635         living = monster_living(ap_r_ptr);
2636
2637         /* Calculate a health "percentage" */
2638         perc = 100L * m_ptr->hp / m_ptr->maxhp;
2639
2640         /* Healthy monsters */
2641         if (m_ptr->hp >= m_ptr->maxhp)
2642         {
2643                 /* No damage */
2644 #ifdef JP
2645                 desc = living ? "̵½ý" : "̵¥À¥á¡¼¥¸";
2646 #else
2647                 desc = living ? "unhurt" : "undamaged";
2648 #endif
2649
2650         }
2651
2652         else if (perc >= 60)
2653         {
2654 #ifdef JP
2655                 desc = living ? "·Ú½ý" : "¾®¥À¥á¡¼¥¸";
2656 #else
2657                 desc = living ? "somewhat wounded" : "somewhat damaged";
2658 #endif
2659
2660         }
2661
2662         else if (perc >= 25)
2663         {
2664 #ifdef JP
2665                 desc = living ? "Éé½ý" : "Ãæ¥À¥á¡¼¥¸";
2666 #else
2667                 desc = living ? "wounded" : "damaged";
2668 #endif
2669
2670         }
2671
2672         else if (perc >= 10)
2673         {
2674 #ifdef JP
2675                 desc = living ? "½Å½ý" : "Âç¥À¥á¡¼¥¸";
2676 #else
2677                 desc = living ? "badly wounded" : "badly damaged";
2678 #endif
2679
2680         }
2681
2682         else 
2683         {
2684 #ifdef JP
2685                 desc = living ? "Ⱦ»àȾÀ¸" : "Åݤ줫¤±";
2686 #else
2687                 desc = living ? "almost dead" : "almost destroyed";
2688 #endif
2689         }
2690
2691
2692         /* Need attitude information? */
2693         if (!(mode & 0x01))
2694         {
2695                 /* Full information is not needed */
2696                 attitude = "";
2697         }
2698         else if (is_pet(m_ptr))
2699         {
2700 #ifdef JP
2701                 attitude = ", ¥Ú¥Ã¥È";
2702 #else
2703                 attitude = ", pet";
2704 #endif
2705         }
2706         else if (is_friendly(m_ptr))
2707         {
2708 #ifdef JP
2709                 attitude = ", Í§¹¥Åª";
2710 #else
2711                 attitude = ", friendly";
2712 #endif
2713         }
2714         else
2715         {
2716 #ifdef JP
2717                 attitude = "";
2718 #else
2719                 attitude = "";
2720 #endif
2721         }
2722
2723
2724         /* Clone monster? */
2725         if (m_ptr->smart & SM_CLONED)
2726         {
2727                 clone = ", clone";
2728         }
2729         else
2730         {
2731                 clone = "";
2732         }
2733
2734         /* Display monster's level --- idea borrowed from ToME */
2735         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
2736         {
2737 #ifdef JP
2738                 return format("¥ì¥Ù¥ë%d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2739 #else
2740                 return format("Level %d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2741 #endif
2742         }
2743         else 
2744         {
2745 #ifdef JP
2746                 return format("¥ì¥Ù¥ë???, %s%s%s", desc, attitude, clone);
2747 #else
2748                 return format("Level ???, %s%s%s", desc, attitude, clone);
2749 #endif
2750         }
2751 }
2752
2753
2754
2755 /*
2756  * Angband sorting algorithm -- quick sort in place
2757  *
2758  * Note that the details of the data we are sorting is hidden,
2759  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2760  * function hooks to interact with the data, which is given as
2761  * two pointers, and which may have any user-defined form.
2762  */
2763 void ang_sort_aux(vptr u, vptr v, int p, int q)
2764 {
2765         int z, a, b;
2766
2767         /* Done sort */
2768         if (p >= q) return;
2769
2770         /* Pivot */
2771         z = p;
2772
2773         /* Begin */
2774         a = p;
2775         b = q;
2776
2777         /* Partition */
2778         while (TRUE)
2779         {
2780                 /* Slide i2 */
2781                 while (!(*ang_sort_comp)(u, v, b, z)) b--;
2782
2783                 /* Slide i1 */
2784                 while (!(*ang_sort_comp)(u, v, z, a)) a++;
2785
2786                 /* Done partition */
2787                 if (a >= b) break;
2788
2789                 /* Swap */
2790                 (*ang_sort_swap)(u, v, a, b);
2791
2792                 /* Advance */
2793                 a++, b--;
2794         }
2795
2796         /* Recurse left side */
2797         ang_sort_aux(u, v, p, b);
2798
2799         /* Recurse right side */
2800         ang_sort_aux(u, v, b+1, q);
2801 }
2802
2803
2804 /*
2805  * Angband sorting algorithm -- quick sort in place
2806  *
2807  * Note that the details of the data we are sorting is hidden,
2808  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2809  * function hooks to interact with the data, which is given as
2810  * two pointers, and which may have any user-defined form.
2811  */
2812 void ang_sort(vptr u, vptr v, int n)
2813 {
2814         /* Sort the array */
2815         ang_sort_aux(u, v, 0, n-1);
2816 }
2817
2818
2819
2820 /*** Targeting Code ***/
2821
2822
2823 /*
2824  * Determine is a monster makes a reasonable target
2825  *
2826  * The concept of "targeting" was stolen from "Morgul" (?)
2827  *
2828  * The player can target any location, or any "target-able" monster.
2829  *
2830  * Currently, a monster is "target_able" if it is visible, and if
2831  * the player can hit it with a projection, and the player is not
2832  * hallucinating.  This allows use of "use closest target" macros.
2833  *
2834  * Future versions may restrict the ability to target "trappers"
2835  * and "mimics", but the semantics is a little bit weird.
2836  */
2837 bool target_able(int m_idx)
2838 {
2839         monster_type *m_ptr = &m_list[m_idx];
2840
2841         /* Monster must be alive */
2842         if (!m_ptr->r_idx) return (FALSE);
2843
2844         /* Hack -- no targeting hallucinations */
2845         if (p_ptr->image) return (FALSE);
2846
2847         /* Monster must be visible */
2848         if (!m_ptr->ml) return (FALSE);
2849
2850         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
2851
2852         /* Monster must be projectable */
2853         if (!projectable(py, px, m_ptr->fy, m_ptr->fx)) return (FALSE);
2854
2855         /* XXX XXX XXX Hack -- Never target trappers */
2856         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
2857
2858         /* Assume okay */
2859         return (TRUE);
2860 }
2861
2862
2863
2864
2865 /*
2866  * Update (if necessary) and verify (if possible) the target.
2867  *
2868  * We return TRUE if the target is "okay" and FALSE otherwise.
2869  */
2870 bool target_okay(void)
2871 {
2872         /* Accept stationary targets */
2873         if (target_who < 0) return (TRUE);
2874
2875         /* Check moving targets */
2876         if (target_who > 0)
2877         {
2878                 /* Accept reasonable targets */
2879                 if (target_able(target_who))
2880                 {
2881                         monster_type *m_ptr = &m_list[target_who];
2882
2883                         /* Acquire monster location */
2884                         target_row = m_ptr->fy;
2885                         target_col = m_ptr->fx;
2886
2887                         /* Good target */
2888                         return (TRUE);
2889                 }
2890         }
2891
2892         /* Assume no target */
2893         return (FALSE);
2894 }
2895
2896
2897 /*
2898  * Sorting hook -- comp function -- by "distance to player"
2899  *
2900  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2901  * and sort the arrays by double-distance to the player.
2902  */
2903 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
2904 {
2905         byte *x = (byte*)(u);
2906         byte *y = (byte*)(v);
2907
2908         int da, db, kx, ky;
2909
2910         /* Absolute distance components */
2911         kx = x[a]; kx -= px; kx = ABS(kx);
2912         ky = y[a]; ky -= py; ky = ABS(ky);
2913
2914         /* Approximate Double Distance to the first point */
2915         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2916
2917         /* Absolute distance components */
2918         kx = x[b]; kx -= px; kx = ABS(kx);
2919         ky = y[b]; ky -= py; ky = ABS(ky);
2920
2921         /* Approximate Double Distance to the first point */
2922         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2923
2924         /* Compare the distances */
2925         return (da <= db);
2926 }
2927
2928
2929 /*
2930  * Sorting hook -- comp function -- by importance level of grids
2931  *
2932  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2933  * and sort the arrays by level of monster
2934  */
2935 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
2936 {
2937         byte *x = (byte*)(u);
2938         byte *y = (byte*)(v);
2939         cave_type *ca_ptr = &cave[y[a]][x[a]];
2940         cave_type *cb_ptr = &cave[y[b]][x[b]];
2941         monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
2942         monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
2943         monster_race *ap_ra_ptr, *ap_rb_ptr;
2944
2945         /* The player grid */
2946         if (y[a] == py && x[a] == px) return TRUE;
2947         if (y[b] == py && x[b] == px) return FALSE;
2948
2949         /* Extract monster race */
2950         if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
2951         else ap_ra_ptr = NULL;
2952         if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
2953         else ap_rb_ptr = NULL;
2954
2955         if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
2956         if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
2957
2958         /* Compare two monsters */
2959         if (ap_ra_ptr && ap_rb_ptr)
2960         {
2961                 /* Unique monsters first */
2962                 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
2963                 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
2964
2965                 /* Shadowers first (¤¢¤ä¤·¤¤±Æ) */
2966                 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
2967                 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
2968
2969                 /* Unknown monsters first */
2970                 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
2971                 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
2972
2973                 /* Higher level monsters first (if known) */
2974                 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
2975                 {
2976                         if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
2977                         if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
2978                 }
2979
2980                 /* Sort by index if all conditions are same */
2981                 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
2982                 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
2983         }
2984
2985         /* An object get higher priority */
2986         if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
2987         if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
2988
2989         /* Priority from the terrain */
2990         if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
2991         if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
2992
2993         /* If all conditions are same, compare distance */
2994         return ang_sort_comp_distance(u, v, a, b);
2995 }
2996
2997
2998 /*
2999  * Sorting hook -- swap function -- by "distance to player"
3000  *
3001  * We use "u" and "v" to point to arrays of "x" and "y" positions,
3002  * and sort the arrays by distance to the player.
3003  */
3004 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
3005 {
3006         byte *x = (byte*)(u);
3007         byte *y = (byte*)(v);
3008
3009         byte temp;
3010
3011         /* Swap "x" */
3012         temp = x[a];
3013         x[a] = x[b];
3014         x[b] = temp;
3015
3016         /* Swap "y" */
3017         temp = y[a];
3018         y[a] = y[b];
3019         y[b] = temp;
3020 }
3021
3022
3023
3024 /*
3025  * Hack -- help "select" a location (see below)
3026  */
3027 static s16b target_pick(int y1, int x1, int dy, int dx)
3028 {
3029         int i, v;
3030
3031         int x2, y2, x3, y3, x4, y4;
3032
3033         int b_i = -1, b_v = 9999;
3034
3035
3036         /* Scan the locations */
3037         for (i = 0; i < temp_n; i++)
3038         {
3039                 /* Point 2 */
3040                 x2 = temp_x[i];
3041                 y2 = temp_y[i];
3042
3043                 /* Directed distance */
3044                 x3 = (x2 - x1);
3045                 y3 = (y2 - y1);
3046
3047                 /* Verify quadrant */
3048                 if (dx && (x3 * dx <= 0)) continue;
3049                 if (dy && (y3 * dy <= 0)) continue;
3050
3051                 /* Absolute distance */
3052                 x4 = ABS(x3);
3053                 y4 = ABS(y3);
3054
3055                 /* Verify quadrant */
3056                 if (dy && !dx && (x4 > y4)) continue;
3057                 if (dx && !dy && (y4 > x4)) continue;
3058
3059                 /* Approximate Double Distance */
3060                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
3061
3062                 /* XXX XXX XXX Penalize location */
3063
3064                 /* Track best */
3065                 if ((b_i >= 0) && (v >= b_v)) continue;
3066
3067                 /* Track best */
3068                 b_i = i; b_v = v;
3069         }
3070
3071         /* Result */
3072         return (b_i);
3073 }
3074
3075
3076 /*
3077  * Hack -- determine if a given location is "interesting"
3078  */
3079 static bool target_set_accept(int y, int x)
3080 {
3081         cave_type *c_ptr;
3082
3083         s16b this_o_idx, next_o_idx = 0;
3084
3085         /* Bounds */
3086         if (!(in_bounds(y, x))) return (FALSE);
3087
3088         /* Player grid is always interesting */
3089         if (player_bold(y, x)) return (TRUE);
3090
3091
3092         /* Handle hallucination */
3093         if (p_ptr->image) return (FALSE);
3094
3095
3096         /* Examine the grid */
3097         c_ptr = &cave[y][x];
3098
3099         /* Visible monsters */
3100         if (c_ptr->m_idx)
3101         {
3102                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
3103
3104                 /* Visible monsters */
3105                 if (m_ptr->ml) return (TRUE);
3106         }
3107
3108         /* Scan all objects in the grid */
3109         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3110         {
3111                 object_type *o_ptr;
3112
3113                 /* Acquire object */
3114                 o_ptr = &o_list[this_o_idx];
3115
3116                 /* Acquire next object */
3117                 next_o_idx = o_ptr->next_o_idx;
3118
3119                 /* Memorized object */
3120                 if (o_ptr->marked & OM_FOUND) return (TRUE);
3121         }
3122
3123         /* Interesting memorized features */
3124         if (c_ptr->info & (CAVE_MARK))
3125         {
3126                 /* Notice object features */
3127                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
3128
3129                 /* Feature code (applying "mimic" field) */
3130                 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
3131         }
3132
3133         /* Nope */
3134         return (FALSE);
3135 }
3136
3137
3138 /*
3139  * Prepare the "temp" array for "target_set"
3140  *
3141  * Return the number of target_able monsters in the set.
3142  */
3143 static void target_set_prepare(int mode)
3144 {
3145         int y, x;
3146         int min_hgt, max_hgt, min_wid, max_wid;
3147
3148         if (mode & TARGET_KILL)
3149         {
3150                 /* Inner range */
3151                 min_hgt = MAX((py - MAX_RANGE), 0);
3152                 max_hgt = MIN((py + MAX_RANGE), cur_hgt - 1);
3153                 min_wid = MAX((px - MAX_RANGE), 0);
3154                 max_wid = MIN((px + MAX_RANGE), cur_wid - 1);
3155         }
3156         else /* not targetting */
3157         {
3158                 /* Inner panel */
3159                 min_hgt = panel_row_min;
3160                 max_hgt = panel_row_max;
3161                 min_wid = panel_col_min;
3162                 max_wid = panel_col_max;
3163         }
3164
3165         /* Reset "temp" array */
3166         temp_n = 0;
3167
3168         /* Scan the current panel */
3169         for (y = min_hgt; y <= max_hgt; y++)
3170         {
3171                 for (x = min_wid; x <= max_wid; x++)
3172                 {
3173                         cave_type *c_ptr;
3174
3175                         /* Require "interesting" contents */
3176                         if (!target_set_accept(y, x)) continue;
3177
3178                         c_ptr = &cave[y][x];
3179
3180                         /* Require target_able monsters for "TARGET_KILL" */
3181                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
3182
3183                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
3184
3185                         /* Save the location */
3186                         temp_x[temp_n] = x;
3187                         temp_y[temp_n] = y;
3188                         temp_n++;
3189                 }
3190         }
3191
3192         /* Set the sort hooks */
3193         if (mode & (TARGET_KILL))
3194         {
3195                 /* Target the nearest monster for shooting */
3196                 ang_sort_comp = ang_sort_comp_distance;
3197                 ang_sort_swap = ang_sort_swap_distance;
3198         }
3199         else
3200         {
3201                 /* Look important grids first in Look command */
3202                 ang_sort_comp = ang_sort_comp_importance;
3203                 ang_sort_swap = ang_sort_swap_distance;
3204         }
3205
3206         /* Sort the positions */
3207         ang_sort(temp_x, temp_y, temp_n);
3208
3209         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
3210         {
3211                 byte tmp;
3212
3213                 tmp = temp_y[0];
3214                 temp_y[0] = temp_y[1];
3215                 temp_y[1] = tmp;
3216                 tmp = temp_x[0];
3217                 temp_x[0] = temp_x[1];
3218                 temp_x[1] = tmp;
3219         }
3220 }
3221 void target_set_prepare_look(){
3222         target_set_prepare(TARGET_LOOK);
3223 }
3224
3225
3226 /*
3227  * Evaluate number of kill needed to gain level
3228  */
3229 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
3230 {
3231         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3232         u32b num;
3233         s32b exp_mon, exp_adv;
3234         u32b exp_mon_frac, exp_adv_frac;
3235
3236         if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
3237         {
3238                 sprintf(buf,"**");
3239                 return;
3240         }
3241         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
3242         {
3243                 if (!p_ptr->wizard)
3244                 {
3245                         sprintf(buf,"??");
3246                         return;
3247                 }
3248         }
3249
3250
3251         /* The monster's experience point (assuming average monster speed) */
3252         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
3253         exp_mon_frac = 0;
3254         s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
3255
3256
3257         /* Total experience value for next level */
3258         exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
3259         exp_adv_frac = 0;
3260         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
3261
3262         /* Experience value need to get */
3263         s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
3264
3265
3266         /* You need to kill at least one monster to get any experience */
3267         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
3268         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
3269
3270         /* Extract number of monsters needed */
3271         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
3272
3273         /* If 999 or more monsters needed, only display "999". */
3274         num = MIN(999, exp_adv_frac);
3275
3276         /* Display the number */
3277         sprintf(buf,"%03ld", (long int)num);
3278 }
3279
3280
3281 bool show_gold_on_floor = FALSE;
3282
3283 /*
3284  * Examine a grid, return a keypress.
3285  *
3286  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
3287  * indicates that the "space" key should scan through the contents
3288  * of the grid, instead of simply returning immediately.  This lets
3289  * the "look" command get complete information, without making the
3290  * "target" command annoying.
3291  *
3292  * The "info" argument contains the "commands" which should be shown
3293  * inside the "[xxx]" text.  This string must never be empty, or grids
3294  * containing monsters will be displayed with an extra comma.
3295  *
3296  * Note that if a monster is in the grid, we update both the monster
3297  * recall info and the health bar info to track that monster.
3298  *
3299  * Eventually, we may allow multiple objects per grid, or objects
3300  * and terrain features in the same grid. XXX XXX XXX
3301  *
3302  * This function must handle blindness/hallucination.
3303  */
3304 static int target_set_aux(int y, int x, int mode, cptr info)
3305 {
3306         cave_type *c_ptr = &cave[y][x];
3307         s16b this_o_idx, next_o_idx = 0;
3308         cptr s1 = "", s2 = "", s3 = "", x_info = "";
3309         bool boring = TRUE;
3310         s16b feat;
3311         feature_type *f_ptr;
3312         int query = '\001';
3313         char out_val[MAX_NLEN+80];
3314
3315 #ifdef ALLOW_EASY_FLOOR
3316         int floor_list[23], floor_num = 0;
3317
3318         /* Scan all objects in the grid */
3319         if (easy_floor)
3320         {
3321                 floor_num = scan_floor(floor_list, y, x, 0x02);
3322
3323                 if (floor_num)
3324                 {
3325 #ifdef JP
3326                         x_info = "xʪ ";
3327 #else
3328                         x_info = "x,";
3329 #endif
3330                 }
3331         }
3332
3333 #endif /* ALLOW_EASY_FLOOR */
3334
3335         /* Hack -- under the player */
3336         if (player_bold(y, x))
3337         {
3338                 /* Description */
3339 #ifdef JP
3340                 s1 = "¤¢¤Ê¤¿¤Ï";
3341                 s2 = "¤Î¾å";
3342                 s3 = "¤Ë¤¤¤ë";
3343 #else
3344                 s1 = "You are ";
3345
3346                 /* Preposition */
3347                 s2 = "on ";
3348 #endif
3349         }
3350         else
3351         {
3352 #ifdef JP
3353                 s1 = "¥¿¡¼¥²¥Ã¥È:";
3354 #else
3355                 s1 = "Target:";
3356 #endif
3357         }
3358
3359         /* Hack -- hallucination */
3360         if (p_ptr->image)
3361         {
3362 #ifdef JP
3363                 cptr name = "²¿¤«´ñ̯¤Êʪ";
3364 #else
3365                 cptr name = "something strange";
3366 #endif
3367
3368
3369                 /* Display a message */
3370 #ifdef JP
3371                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
3372 #else
3373                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3374 #endif
3375
3376                 prt(out_val, 0, 0);
3377                 move_cursor_relative(y, x);
3378                 query = inkey();
3379
3380                 /* Stop on everything but "return" */
3381                 if ((query != '\r') && (query != '\n')) return query;
3382
3383                 /* Repeat forever */
3384                 return 0;
3385         }
3386
3387
3388         /* Actual monsters */
3389         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
3390         {
3391                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
3392                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3393                 char m_name[80];
3394                 bool recall = FALSE;
3395
3396                 /* Not boring */
3397                 boring = FALSE;
3398
3399                 /* Get the monster name ("a kobold") */
3400                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
3401
3402                 /* Hack -- track this monster race */
3403                 monster_race_track(m_ptr->ap_r_idx);
3404
3405                 /* Hack -- health bar for this monster */
3406                 health_track(c_ptr->m_idx);
3407
3408                 /* Hack -- handle stuff */
3409                 handle_stuff();
3410
3411                 /* Interact */
3412                 while (1)
3413                 {
3414                         char acount[10];
3415
3416                         /* Recall */
3417                         if (recall)
3418                         {
3419                                 /* Save */
3420                                 screen_save();
3421
3422                                 /* Recall on screen */
3423                                 screen_roff(m_ptr->ap_r_idx, 0);
3424
3425                                 /* Hack -- Complete the prompt (again) */
3426 #ifdef JP
3427                                 Term_addstr(-1, TERM_WHITE, format("  [r»× %s%s]", x_info, info));
3428 #else
3429                                 Term_addstr(-1, TERM_WHITE, format("  [r,%s%s]", x_info, info));
3430 #endif
3431
3432                                 /* Command */
3433                                 query = inkey();
3434
3435                                 /* Restore */
3436                                 screen_load();
3437
3438                                 /* Normal commands */
3439                                 if (query != 'r') break;
3440
3441                                 /* Toggle recall */
3442                                 recall = FALSE;
3443
3444                                 /* Cleare recall text and repeat */
3445                                 continue;
3446                         }
3447
3448                         /*** Normal ***/
3449
3450                         /* Describe, and prompt for recall */
3451                         evaluate_monster_exp(acount, m_ptr);
3452
3453 #ifdef JP
3454                         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);
3455 #else
3456                         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);
3457 #endif
3458
3459                         prt(out_val, 0, 0);
3460
3461                         /* Place cursor */
3462                         move_cursor_relative(y, x);
3463
3464                         /* Command */
3465                         query = inkey();
3466
3467                         /* Normal commands */
3468                         if (query != 'r') break;
3469
3470                         /* Toggle recall */
3471                         recall = TRUE;
3472                 }
3473
3474                 /* Always stop at "normal" keys */
3475                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3476
3477                 /* Sometimes stop at "space" key */
3478                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3479
3480                 /* Change the intro */
3481 #ifdef JP
3482                 s1 = "¤½¤ì¤Ï";
3483 #else
3484                 s1 = "It is ";
3485 #endif
3486
3487
3488                 /* Hack -- take account of gender */
3489 #ifdef JP
3490                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = "Èà½÷¤Ï";
3491 #else
3492                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = "She is ";
3493 #endif
3494
3495 #ifdef JP
3496                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = "Èà¤Ï";
3497 #else
3498                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = "He is ";
3499 #endif
3500
3501
3502                 /* Use a preposition */
3503 #ifdef JP
3504                 s2 = "¤ò";
3505                 s3 = "»ý¤Ã¤Æ¤¤¤ë";
3506 #else
3507                 s2 = "carrying ";
3508 #endif
3509
3510
3511                 /* Scan all objects being carried */
3512                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3513                 {
3514                         char o_name[MAX_NLEN];
3515
3516                         object_type *o_ptr;
3517
3518                         /* Acquire object */
3519                         o_ptr = &o_list[this_o_idx];
3520
3521                         /* Acquire next object */
3522                         next_o_idx = o_ptr->next_o_idx;
3523
3524                         /* Obtain an object description */
3525                         object_desc(o_name, o_ptr, 0);
3526
3527                         /* Describe the object */
3528 #ifdef JP
3529                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3530 #else
3531                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3532 #endif
3533
3534                         prt(out_val, 0, 0);
3535                         move_cursor_relative(y, x);
3536                         query = inkey();
3537
3538                         /* Always stop at "normal" keys */
3539                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3540
3541                         /* Sometimes stop at "space" key */
3542                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3543
3544                         /* Change the intro */
3545 #ifdef JP
3546                         s2 = "¤ò¤Þ¤¿";
3547 #else
3548                         s2 = "also carrying ";
3549 #endif
3550                 }
3551
3552                 /* Use a preposition */
3553 #ifdef JP
3554                 s2 = "¤Î¾å";
3555                 s3 = "¤Ë¤¤¤ë";
3556 #else
3557                 s2 = "on ";
3558 #endif
3559         }
3560
3561
3562 #ifdef ALLOW_EASY_FLOOR
3563         if (floor_num)
3564         {
3565                 int min_width = 0;
3566
3567                 while (1)
3568                 {
3569                         if (floor_num == 1)
3570                         {
3571                                 char o_name[MAX_NLEN];
3572
3573                                 object_type *o_ptr;
3574
3575                                 /* Acquire object */
3576                                 o_ptr = &o_list[floor_list[0]];
3577
3578                                 /* Describe the object */
3579                                 object_desc(o_name, o_ptr, 0);
3580
3581                                 /* Message */
3582 #ifdef JP
3583                                 sprintf(out_val, "%s%s%s%s[%s]",
3584                                         s1, o_name, s2, s3, info);
3585 #else
3586                                 sprintf(out_val, "%s%s%s%s [%s]",
3587                                         s1, s2, s3, o_name, info);
3588 #endif
3589
3590                                 prt(out_val, 0, 0);
3591                                 move_cursor_relative(y, x);
3592
3593                                 /* Command */
3594                                 query = inkey();
3595
3596                                 /* End this grid */
3597                                 return query;
3598                         }
3599
3600                         /* Provide one cushion before item listing  */
3601                         if (boring)
3602                         {
3603                                 /* Display rough information about items */
3604 #ifdef JP
3605                                 sprintf(out_val, "%s %d¸Ä¤Î¥¢¥¤¥Æ¥à%s%s ['x'¤Ç°ìÍ÷, %s]",
3606                                         s1, floor_num, s2, s3, info);
3607 #else
3608                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]",
3609                                         s1, s2, s3, floor_num, info);
3610 #endif
3611
3612                                 prt(out_val, 0, 0);
3613                                 move_cursor_relative(y, x);
3614
3615                                 /* Command */
3616                                 query = inkey();
3617
3618                                 /* No request for listing */
3619                                 if (query != 'x' && query != ' ') return query;
3620                         }
3621
3622
3623                         /** Display list of items **/
3624
3625                         /* Continue scrolling list if requested */
3626                         while (1)
3627                         {
3628                                 int i, o_idx;
3629
3630                                 /* Save screen */
3631                                 screen_save();
3632
3633                                 /* Display */
3634                                 show_gold_on_floor = TRUE;
3635                                 (void)show_floor(0, y, x, &min_width);
3636                                 show_gold_on_floor = FALSE;
3637
3638                                 /* Prompt */
3639 #ifdef JP
3640                                 sprintf(out_val, "%s %d¸Ä¤Î¥¢¥¤¥Æ¥à%s%s [Enter¤Ç¼¡¤Ø, %s]",
3641                                         s1, floor_num, s2, s3, info);
3642 #else
3643                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]",
3644                                         s1, s2, s3, floor_num, info);
3645 #endif
3646                                 prt(out_val, 0, 0);
3647
3648
3649                                 /* Wait */
3650                                 query = inkey();
3651
3652                                 /* Load screen */
3653                                 screen_load();
3654
3655                                 /* Exit unless 'Enter' */
3656                                 if (query != '\n' && query != '\r')
3657                                 {
3658                                         return query;
3659                                 }
3660
3661                                 /* Get the object being moved. */
3662                                 o_idx = c_ptr->o_idx;
3663  
3664                                 /* Only rotate a pile of two or more objects. */
3665                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
3666
3667                                 /* Remove the first object from the list. */
3668                                 excise_object_idx(o_idx);
3669
3670                                 /* Find end of the list. */
3671                                 i = c_ptr->o_idx;
3672                                 while (o_list[i].next_o_idx)
3673                                         i = o_list[i].next_o_idx;
3674
3675                                 /* Add after the last object. */
3676                                 o_list[i].next_o_idx = o_idx;
3677
3678                                 /* Loop and re-display the list */
3679                         }
3680                 }
3681
3682                 /* NOTREACHED */
3683         }
3684 #endif /* ALLOW_EASY_FLOOR */
3685
3686
3687         /* Scan all objects in the grid */
3688         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3689         {
3690                 object_type *o_ptr;
3691
3692                 /* Acquire object */
3693                 o_ptr = &o_list[this_o_idx];
3694
3695                 /* Acquire next object */
3696                 next_o_idx = o_ptr->next_o_idx;
3697
3698                 /* Describe it */
3699                 if (o_ptr->marked & OM_FOUND)
3700                 {
3701                         char o_name[MAX_NLEN];
3702
3703                         /* Not boring */
3704                         boring = FALSE;
3705
3706                         /* Obtain an object description */
3707                         object_desc(o_name, o_ptr, 0);
3708
3709                         /* Describe the object */
3710 #ifdef JP
3711                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3712 #else
3713                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3714 #endif
3715
3716                         prt(out_val, 0, 0);
3717                         move_cursor_relative(y, x);
3718                         query = inkey();
3719
3720                         /* Always stop at "normal" keys */
3721                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3722
3723                         /* Sometimes stop at "space" key */
3724                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
3725
3726                         /* Change the intro */
3727 #ifdef JP
3728                         s1 = "¤½¤ì¤Ï";
3729 #else
3730                         s1 = "It is ";
3731 #endif
3732
3733
3734                         /* Plurals */
3735 #ifdef JP
3736                         if (o_ptr->number != 1) s1 = "¤½¤ì¤é¤Ï";
3737 #else
3738                         if (o_ptr->number != 1) s1 = "They are ";
3739 #endif
3740
3741
3742                         /* Preposition */
3743 #ifdef JP
3744                         s2 = "¤Î¾å";
3745                         s3 = "¤Ë¸«¤¨¤ë";
3746 #else
3747                         s2 = "on ";
3748 #endif
3749
3750                 }
3751         }
3752
3753
3754         /* Feature code (applying "mimic" field) */
3755         feat = get_feat_mimic(c_ptr);
3756
3757         /* Require knowledge about grid, or ability to see grid */
3758         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
3759         {
3760                 /* Forget feature */
3761                 feat = feat_none;
3762         }
3763
3764         f_ptr = &f_info[feat];
3765
3766         /* Terrain feature if needed */
3767         if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
3768         {
3769                 cptr name;
3770
3771                 /* Hack -- special handling for quest entrances */
3772                 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
3773                 {
3774                         /* Set the quest number temporary */
3775                         int old_quest = p_ptr->inside_quest;
3776                         int j;
3777
3778                         /* Clear the text */
3779                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
3780                         quest_text_line = 0;
3781
3782                         p_ptr->inside_quest = c_ptr->special;
3783
3784                         /* Get the quest text */
3785                         init_flags = INIT_NAME_ONLY;
3786
3787                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3788
3789 #ifdef JP
3790                         name = format("¥¯¥¨¥¹¥È¡Ö%s¡×(%d³¬ÁêÅö)", quest[c_ptr->special].name, quest[c_ptr->special].level);
3791 #else
3792                         name = format("the entrance to the quest '%s'(level %d)", quest[c_ptr->special].name, quest[c_ptr->special].level);
3793 #endif
3794
3795                         /* Reset the old quest number */
3796                         p_ptr->inside_quest = old_quest;
3797                 }
3798
3799                 /* Hack -- special handling for building doors */
3800                 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
3801                 {
3802                         name = building[f_ptr->subtype].name;
3803                 }
3804                 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
3805                 {
3806 #ifdef JP
3807                         name = format("%s(%d³¬ÁêÅö)", d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3808 #else
3809                         name = format("%s(level %d)", d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3810 #endif
3811                 }
3812                 else if (have_flag(f_ptr->flags, FF_TOWN))
3813                 {
3814                         name = town[c_ptr->special].name;
3815                 }
3816                 else if (p_ptr->wild_mode && (feat == feat_floor))
3817                 {
3818 #ifdef JP
3819                         name = "ƻ";
3820 #else
3821                         name = "road";
3822 #endif
3823                 }
3824                 else
3825                 {
3826                         name = f_name + f_ptr->name;
3827                 }
3828
3829
3830                 /* Pick a prefix */
3831                 if (*s2 &&
3832                     ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
3833                      (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
3834                      have_flag(f_ptr->flags, FF_TOWN)))
3835                 {
3836 #ifdef JP
3837                         s2 = "¤ÎÃæ";
3838 #else
3839                         s2 = "in ";
3840 #endif
3841                 }
3842
3843                 /* Hack -- special introduction for store & building doors -KMW- */
3844                 if (have_flag(f_ptr->flags, FF_STORE) ||
3845                     have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
3846                     (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
3847                     have_flag(f_ptr->flags, FF_ENTRANCE))
3848                 {
3849 #ifdef JP
3850                         s2 = "¤ÎÆþ¸ý";
3851 #else
3852                         s3 = "";
3853 #endif
3854                 }
3855 #ifndef JP
3856                 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
3857                          have_flag(f_ptr->flags, FF_TOWN) ||
3858                          have_flag(f_ptr->flags, FF_SHALLOW) ||
3859                          have_flag(f_ptr->flags, FF_DEEP))
3860                 {
3861                         s3 ="";
3862                 }
3863                 else
3864                 {
3865                         /* Pick proper indefinite article */
3866                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
3867                 }
3868 #endif
3869
3870                 /* Display a message */
3871                 if (p_ptr->wizard)
3872                 {
3873                         char f_idx_str[32];
3874                         if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
3875                         else sprintf(f_idx_str, "%d", c_ptr->feat);
3876 #ifdef JP
3877                         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]);
3878 #else
3879                         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);
3880 #endif
3881                 }
3882                 else
3883 #ifdef JP
3884                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
3885 #else
3886                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3887 #endif
3888
3889                 prt(out_val, 0, 0);
3890                 move_cursor_relative(y, x);
3891                 query = inkey();
3892
3893                 /* Always stop at "normal" keys */
3894                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
3895         }
3896
3897         /* Stop on everything but "return" */
3898         if ((query != '\r') && (query != '\n')) return query;
3899
3900         /* Repeat forever */
3901         return 0;
3902 }
3903
3904
3905 /*
3906  * Handle "target" and "look".
3907  *
3908  * Note that this code can be called from "get_aim_dir()".
3909  *
3910  * All locations must be on the current panel.  Consider the use of
3911  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
3912  * some form of "scrolling" the map around the cursor.  XXX XXX XXX
3913  * That is, consider the possibility of "auto-scrolling" the screen
3914  * while the cursor moves around.  This may require changes in the
3915  * "update_mon()" code to allow "visibility" even if off panel, and
3916  * may require dynamic recalculation of the "temp" grid set.
3917  *
3918  * Hack -- targeting/observing an "outer border grid" may induce
3919  * problems, so this is not currently allowed.
3920  *
3921  * The player can use the direction keys to move among "interesting"
3922  * grids in a heuristic manner, or the "space", "+", and "-" keys to
3923  * move through the "interesting" grids in a sequential manner, or
3924  * can enter "location" mode, and use the direction keys to move one
3925  * grid at a time in any direction.  The "t" (set target) command will
3926  * only target a monster (as opposed to a location) if the monster is
3927  * target_able and the "interesting" mode is being used.
3928  *
3929  * The current grid is described using the "look" method above, and
3930  * a new command may be entered at any time, but note that if the
3931  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
3932  * where "space" has no obvious meaning) then "space" will scan
3933  * through the description of the current grid until done, instead
3934  * of immediately jumping to the next "interesting" grid.  This
3935  * allows the "target" command to retain its old semantics.
3936  *
3937  * The "*", "+", and "-" keys may always be used to jump immediately
3938  * to the next (or previous) interesting grid, in the proper mode.
3939  *
3940  * The "return" key may always be used to scan through a complete
3941  * grid description (forever).
3942  *
3943  * This command will cancel any old target, even if used from
3944  * inside the "look" command.
3945  */
3946 bool target_set(int mode)
3947 {
3948         int             i, d, m, t, bd;
3949         int             y = py;
3950         int             x = px;
3951
3952         bool    done = FALSE;
3953
3954         bool    flag = TRUE;
3955
3956         char    query;
3957
3958         char    info[80];
3959
3960         cave_type               *c_ptr;
3961
3962         int wid, hgt;
3963         
3964         /* Get size */
3965         get_screen_size(&wid, &hgt);
3966
3967         /* Cancel target */
3968         target_who = 0;
3969
3970
3971         /* Cancel tracking */
3972         /* health_track(0); */
3973
3974
3975         /* Prepare the "temp" array */
3976         target_set_prepare(mode);
3977
3978         /* Start near the player */
3979         m = 0;
3980
3981         /* Interact */
3982         while (!done)
3983         {
3984                 /* Interesting grids */
3985                 if (flag && temp_n)
3986                 {
3987                         y = temp_y[m];
3988                         x = temp_x[m];
3989
3990                         /* Set forcus */
3991                         change_panel_xy(y, x);
3992
3993                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3994
3995                         /* Access */
3996                         c_ptr = &cave[y][x];
3997
3998                         /* Allow target */
3999                         if (target_able(c_ptr->m_idx))
4000                         {
4001 #ifdef JP
4002 strcpy(info, "q»ß t·è p¼« o¸½ +¼¡ -Á°");
4003 #else
4004                                 strcpy(info, "q,t,p,o,+,-,<dir>");
4005 #endif
4006
4007                         }
4008
4009                         /* Dis-allow target */
4010                         else
4011                         {
4012 #ifdef JP
4013 strcpy(info, "q»ß p¼« o¸½ +¼¡ -Á°");
4014 #else
4015                                 strcpy(info, "q,p,o,+,-,<dir>");
4016 #endif
4017
4018                         }
4019                         
4020                         /* Describe and Prompt */
4021                         while (TRUE){
4022                                 query = target_set_aux(y, x, mode, info);
4023                                 if(query)break;
4024                         }
4025
4026                         /* Cancel tracking */
4027                         /* health_track(0); */
4028
4029                         /* Assume no "direction" */
4030                         d = 0;
4031
4032                         if (use_menu)
4033                         {
4034                                 if (query == '\r') query = 't';
4035                         }  
4036
4037                         /* Analyze */
4038                         switch (query)
4039                         {
4040                                 case ESCAPE:
4041                                 case 'q':
4042                                 {
4043                                         done = TRUE;
4044                                         break;
4045                                 }
4046
4047                                 case 't':
4048                                 case '.':
4049                                 case '5':
4050                                 case '0':
4051                                 {
4052                                         if (target_able(c_ptr->m_idx))
4053                                         {
4054                                                 health_track(c_ptr->m_idx);
4055                                                 target_who = c_ptr->m_idx;
4056                                                 target_row = y;
4057                                                 target_col = x;
4058                                                 done = TRUE;
4059                                         }
4060                                         else
4061                                         {
4062                                                 bell();
4063                                         }
4064                                         break;
4065                                 }
4066
4067                                 case ' ':
4068                                 case '*':
4069                                 case '+':
4070                                 {
4071                                         if (++m == temp_n)
4072                                         {
4073                                                 m = 0;
4074                                                 if (!expand_list) done = TRUE;
4075                                         }
4076                                         break;
4077                                 }
4078
4079                                 case '-':
4080                                 {
4081                                         if (m-- == 0)
4082                                         {
4083                                                 m = temp_n - 1;
4084                                                 if (!expand_list) done = TRUE;
4085                                         }
4086                                         break;
4087                                 }
4088
4089                                 case 'p':
4090                                 {
4091                                         /* Recenter the map around the player */
4092                                         verify_panel();
4093
4094                                         /* Update stuff */
4095                                         p_ptr->update |= (PU_MONSTERS);
4096
4097                                         /* Redraw map */
4098                                         p_ptr->redraw |= (PR_MAP);
4099
4100                                         /* Window stuff */
4101                                         p_ptr->window |= (PW_OVERHEAD);
4102
4103                                         /* Handle stuff */
4104                                         handle_stuff();
4105
4106                                         /* Recalculate interesting grids */
4107                                         target_set_prepare(mode);
4108
4109                                         y = py;
4110                                         x = px;
4111                                 }
4112
4113                                 case 'o':
4114                                 {
4115                                         flag = FALSE;
4116                                         break;
4117                                 }
4118
4119                                 case 'm':
4120                                 {
4121                                         break;
4122                                 }
4123
4124                                 default:
4125                                 {
4126                                         /* Extract the action (if any) */
4127                                         d = get_keymap_dir(query);
4128
4129                                         if (!d) bell();
4130                                         break;
4131                                 }
4132                         }
4133
4134                         /* Hack -- move around */
4135                         if (d)
4136                         {
4137                                 /* Modified to scroll to monster */
4138                                 int y2 = panel_row_min;
4139                                 int x2 = panel_col_min;
4140
4141                                 /* Find a new monster */
4142                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
4143
4144                                 /* Request to target past last interesting grid */
4145                                 while (flag && (i < 0))
4146                                 {
4147                                         /* Note the change */
4148                                         if (change_panel(ddy[d], ddx[d]))
4149                                         {
4150                                                 int v = temp_y[m];
4151                                                 int u = temp_x[m];
4152
4153                                                 /* Recalculate interesting grids */
4154                                                 target_set_prepare(mode);
4155
4156                                                 /* Look at interesting grids */
4157                                                 flag = TRUE;
4158
4159                                                 /* Find a new monster */
4160                                                 i = target_pick(v, u, ddy[d], ddx[d]);
4161
4162                                                 /* Use that grid */
4163                                                 if (i >= 0) m = i;
4164                                         }
4165
4166                                         /* Nothing interesting */
4167                                         else
4168                                         {
4169                                                 int dx = ddx[d];
4170                                                 int dy = ddy[d];
4171
4172                                                 /* Restore previous position */
4173                                                 panel_row_min = y2;
4174                                                 panel_col_min = x2;
4175                                                 panel_bounds_center();
4176
4177                                                 /* Update stuff */
4178                                                 p_ptr->update |= (PU_MONSTERS);
4179
4180                                                 /* Redraw map */
4181                                                 p_ptr->redraw |= (PR_MAP);
4182
4183                                                 /* Window stuff */
4184                                                 p_ptr->window |= (PW_OVERHEAD);
4185
4186                                                 /* Handle stuff */
4187                                                 handle_stuff();
4188
4189                                                 /* Recalculate interesting grids */
4190                                                 target_set_prepare(mode);
4191
4192                                                 /* Look at boring grids */
4193                                                 flag = FALSE;
4194
4195                                                 /* Move */
4196                                                 x += dx;
4197                                                 y += dy;
4198
4199                                                 /* Do not move horizontally if unnecessary */
4200                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4201                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4202                                                 {
4203                                                         dx = 0;
4204                                                 }
4205
4206                                                 /* Do not move vertically if unnecessary */
4207                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4208                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4209                                                 {
4210                                                         dy = 0;
4211                                                 }
4212
4213                                                 /* Apply the motion */
4214                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
4215                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
4216                                                 {
4217                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
4218                                                 }
4219
4220                                                 /* Slide into legality */
4221                                                 if (x >= cur_wid-1) x = cur_wid - 2;
4222                                                 else if (x <= 0) x = 1;
4223
4224                                                 /* Slide into legality */
4225                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4226                                                 else if (y <= 0) y = 1;
4227                                         }
4228                                 }
4229
4230                                 /* Use that grid */
4231                                 m = i;
4232                         }
4233                 }
4234
4235                 /* Arbitrary grids */
4236                 else
4237                 {
4238                         bool move_fast = FALSE;
4239
4240                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
4241
4242                         /* Access */
4243                         c_ptr = &cave[y][x];
4244
4245                         /* Default prompt */
4246 #ifdef JP
4247 strcpy(info, "q»ß t·è p¼« m¶á +¼¡ -Á°");
4248 #else
4249                         strcpy(info, "q,t,p,m,+,-,<dir>");
4250 #endif
4251
4252
4253                         /* Describe and Prompt (enable "TARGET_LOOK") */
4254                         while (!(query = target_set_aux(y, x, mode | TARGET_LOOK, info)));
4255
4256                         /* Cancel tracking */
4257                         /* health_track(0); */
4258
4259                         /* Assume no direction */
4260                         d = 0;
4261
4262                         if (use_menu)
4263                         {
4264                                 if (query == '\r') query = 't';
4265                         }  
4266
4267                         /* Analyze the keypress */
4268                         switch (query)
4269                         {
4270                                 case ESCAPE:
4271                                 case 'q':
4272                                 {
4273                                         done = TRUE;
4274                                         break;
4275                                 }
4276
4277                                 case 't':
4278                                 case '.':
4279                                 case '5':
4280                                 case '0':
4281                                 {
4282                                         target_who = -1;
4283                                         target_row = y;
4284                                         target_col = x;
4285                                         done = TRUE;
4286                                         break;
4287                                 }
4288
4289                                 case 'p':
4290                                 {
4291                                         /* Recenter the map around the player */
4292                                         verify_panel();
4293
4294                                         /* Update stuff */
4295                                         p_ptr->update |= (PU_MONSTERS);
4296
4297                                         /* Redraw map */
4298                                         p_ptr->redraw |= (PR_MAP);
4299
4300                                         /* Window stuff */
4301                                         p_ptr->window |= (PW_OVERHEAD);
4302
4303                                         /* Handle stuff */
4304                                         handle_stuff();
4305
4306                                         /* Recalculate interesting grids */
4307                                         target_set_prepare(mode);
4308
4309                                         y = py;
4310                                         x = px;
4311                                 }
4312
4313                                 case 'o':
4314                                 {
4315                                         break;
4316                                 }
4317
4318                                 case ' ':
4319                                 case '*':
4320                                 case '+':
4321                                 case '-':
4322                                 case 'm':
4323                                 {
4324                                         flag = TRUE;
4325
4326                                         m = 0;
4327                                         bd = 999;
4328
4329                                         /* Pick a nearby monster */
4330                                         for (i = 0; i < temp_n; i++)
4331                                         {
4332                                                 t = distance(y, x, temp_y[i], temp_x[i]);
4333
4334                                                 /* Pick closest */
4335                                                 if (t < bd)
4336                                                 {
4337                                                         m = i;
4338                                                         bd = t;
4339                                                 }
4340                                         }
4341
4342                                         /* Nothing interesting */
4343                                         if (bd == 999) flag = FALSE;
4344
4345                                         break;
4346                                 }
4347
4348                                 default:
4349                                 {
4350                                         /* Extract the action (if any) */
4351                                         d = get_keymap_dir(query);
4352
4353                                         /* XTRA HACK MOVEFAST */
4354                                         if (isupper(query)) move_fast = TRUE;
4355
4356                                         if (!d) bell();
4357                                         break;
4358                                 }
4359                         }
4360
4361                         /* Handle "direction" */
4362                         if (d)
4363                         {
4364                                 int dx = ddx[d];
4365                                 int dy = ddy[d];
4366
4367                                 /* XTRA HACK MOVEFAST */
4368                                 if (move_fast)
4369                                 {
4370                                         int mag = MIN(wid / 2, hgt / 2);
4371                                         x += dx * mag;
4372                                         y += dy * mag;
4373                                 }
4374                                 else
4375                                 {
4376                                         x += dx;
4377                                         y += dy;
4378                                 }
4379
4380                                 /* Do not move horizontally if unnecessary */
4381                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4382                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4383                                 {
4384                                         dx = 0;
4385                                 }
4386
4387                                 /* Do not move vertically if unnecessary */
4388                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4389                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4390                                 {
4391                                         dy = 0;
4392                                 }
4393
4394                                 /* Apply the motion */
4395                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
4396                                          (x >= panel_col_min + wid) || (x < panel_col_min))
4397                                 {
4398                                         if (change_panel(dy, dx)) target_set_prepare(mode);
4399                                 }
4400
4401                                 /* Slide into legality */
4402                                 if (x >= cur_wid-1) x = cur_wid - 2;
4403                                 else if (x <= 0) x = 1;
4404
4405                                 /* Slide into legality */
4406                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4407                                 else if (y <= 0) y = 1;
4408                         }
4409                 }
4410         }
4411
4412         /* Forget */
4413         temp_n = 0;
4414
4415         /* Clear the top line */
4416         prt("", 0, 0);
4417
4418         /* Recenter the map around the player */
4419         verify_panel();
4420
4421         /* Update stuff */
4422         p_ptr->update |= (PU_MONSTERS);
4423
4424         /* Redraw map */
4425         p_ptr->redraw |= (PR_MAP);
4426
4427         /* Window stuff */
4428         p_ptr->window |= (PW_OVERHEAD);
4429
4430         /* Handle stuff */
4431         handle_stuff();
4432
4433         /* Failure to set target */
4434         if (!target_who) return (FALSE);
4435
4436         /* Success */
4437         return (TRUE);
4438 }
4439
4440
4441 /*
4442  * Get an "aiming direction" from the user.
4443  *
4444  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
4445  * "0" for "current target", and "-1" for "entry aborted".
4446  *
4447  * Note that "Force Target", if set, will pre-empt user interaction,
4448  * if there is a usable target already set.
4449  *
4450  * Note that confusion over-rides any (explicit?) user choice.
4451  */
4452 bool get_aim_dir(int *dp)
4453 {
4454         int             dir;
4455
4456         char    command;
4457
4458         cptr    p;
4459
4460         /* Initialize */
4461         (*dp) = 0;
4462
4463         /* Global direction */
4464         dir = command_dir;
4465
4466         /* Hack -- auto-target if requested */
4467         if (use_old_target && target_okay()) dir = 5;
4468
4469 #ifdef ALLOW_REPEAT /* TNB */
4470
4471         if (repeat_pull(dp))
4472         {
4473                 /* Confusion? */
4474
4475                 /* Verify */
4476                 if (!(*dp == 5 && !target_okay()))
4477                 {
4478 /*                      return (TRUE); */
4479                         dir = *dp;
4480                 }
4481         }
4482
4483 #endif /* ALLOW_REPEAT -- TNB */
4484
4485         /* Ask until satisfied */
4486         while (!dir)
4487         {
4488                 /* Choose a prompt */
4489                 if (!target_okay())
4490                 {
4491 #ifdef JP
4492 p = "Êý¸þ ('*'¤Ç¥¿¡¼¥²¥Ã¥ÈÁªÂò, ESC¤ÇÃæÃÇ)? ";
4493 #else
4494                         p = "Direction ('*' to choose a target, Escape to cancel)? ";
4495 #endif
4496
4497                 }
4498                 else
4499                 {
4500 #ifdef JP
4501 p = "Êý¸þ ('5'¤Ç¥¿¡¼¥²¥Ã¥È¤Ø, '*'¤Ç¥¿¡¼¥²¥Ã¥ÈºÆÁªÂò, ESC¤ÇÃæÃÇ)? ";
4502 #else
4503                         p = "Direction ('5' for target, '*' to re-target, Escape to cancel)? ";
4504 #endif
4505
4506                 }
4507
4508                 /* Get a command (or Cancel) */
4509                 if (!get_com(p, &command, TRUE)) break;
4510
4511                 if (use_menu)
4512                 {
4513                         if (command == '\r') command = 't';
4514                 }  
4515
4516                 /* Convert various keys to "standard" keys */
4517                 switch (command)
4518                 {
4519                         /* Use current target */
4520                         case 'T':
4521                         case 't':
4522                         case '.':
4523                         case '5':
4524                         case '0':
4525                         {
4526                                 dir = 5;
4527                                 break;
4528                         }
4529
4530                         /* Set new target */
4531                         case '*':
4532                         case ' ':
4533                         case '\r':
4534                         {
4535                                 if (target_set(TARGET_KILL)) dir = 5;
4536                                 break;
4537                         }
4538
4539                         default:
4540                         {
4541                                 /* Extract the action (if any) */
4542                                 dir = get_keymap_dir(command);
4543
4544                                 break;
4545                         }
4546                 }
4547
4548                 /* Verify requested targets */
4549                 if ((dir == 5) && !target_okay()) dir = 0;
4550
4551                 /* Error */
4552                 if (!dir) bell();
4553         }
4554
4555         /* No direction */
4556         if (!dir)
4557         {
4558                 project_length = 0; /* reset to default */
4559                 return (FALSE);
4560         }
4561
4562         /* Save the direction */
4563         command_dir = dir;
4564
4565         /* Check for confusion */
4566         if (p_ptr->confused)
4567         {
4568                 /* XXX XXX XXX */
4569                 /* Random direction */
4570                 dir = ddd[randint0(8)];
4571         }
4572
4573         /* Notice confusion */
4574         if (command_dir != dir)
4575         {
4576                 /* Warn the user */
4577 #ifdef JP
4578 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4579 #else
4580                 msg_print("You are confused.");
4581 #endif
4582
4583         }
4584
4585         /* Save direction */
4586         (*dp) = dir;
4587
4588 #ifdef ALLOW_REPEAT /* TNB */
4589
4590 /*      repeat_push(dir); */
4591         repeat_push(command_dir);
4592
4593 #endif /* ALLOW_REPEAT -- TNB */
4594
4595         /* A "valid" direction was entered */
4596         return (TRUE);
4597 }
4598
4599
4600
4601 /*
4602  * Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
4603  * and place it into "command_dir", unless we already have one.
4604  *
4605  * This function should be used for all "repeatable" commands, such as
4606  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
4607  * as all commands which must reference a grid adjacent to the player,
4608  * and which may not reference the grid under the player.  Note that,
4609  * for example, it is no longer possible to "disarm" or "open" chests
4610  * in the same grid as the player.
4611  *
4612  * Direction "5" is illegal and will (cleanly) abort the command.
4613  *
4614  * This function tracks and uses the "global direction", and uses
4615  * that as the "desired direction", to which "confusion" is applied.
4616  */
4617 bool get_rep_dir(int *dp, bool under)
4618 {
4619         int dir;
4620         cptr prompt;
4621
4622         /* Initialize */
4623         (*dp) = 0;
4624
4625         /* Global direction */
4626         dir = command_dir;
4627
4628 #ifdef ALLOW_REPEAT /* TNB */
4629
4630         if (repeat_pull(dp))
4631         {
4632                 dir = *dp;
4633 /*              return (TRUE); */
4634         }
4635
4636 #endif /* ALLOW_REPEAT -- TNB */
4637
4638         if (under)
4639         {
4640                 prompt = _("Êý¸þ ('.'­¸µ, ESC¤ÇÃæÃÇ)? ", "Direction ('.' at feet, Escape to cancel)? ");
4641         }
4642         else
4643         {
4644                 prompt = _("Êý¸þ (ESC¤ÇÃæÃÇ)? ", "Direction (Escape to cancel)? ");
4645         }
4646         
4647         /* Get a direction */
4648         while (!dir)
4649         {
4650                 char ch;
4651
4652                 /* Get a command (or Cancel) */
4653                 if (!get_com(prompt, &ch, TRUE)) break;
4654
4655                 /* Look down */
4656                 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.')))
4657                 {
4658                         dir = 5;
4659                 }
4660                 else
4661                 {
4662                         /* Look up the direction */
4663                         dir = get_keymap_dir(ch);
4664
4665                         /* Oops */
4666                         if (!dir) bell();
4667                 }
4668         }
4669
4670         /* Prevent weirdness */
4671         if ((dir == 5) && (!under)) dir = 0;
4672
4673         /* Aborted */
4674         if (!dir) return (FALSE);
4675
4676         /* Save desired direction */
4677         command_dir = dir;
4678
4679         /* Apply "confusion" */
4680         if (p_ptr->confused)
4681         {
4682                 /* Standard confusion */
4683                 if (randint0(100) < 75)
4684                 {
4685                         /* Random direction */
4686                         dir = ddd[randint0(8)];
4687                 }
4688         }
4689         else if (p_ptr->riding)
4690         {
4691                 monster_type *m_ptr = &m_list[p_ptr->riding];
4692                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4693
4694                 if (MON_CONFUSED(m_ptr))
4695                 {
4696                         /* Standard confusion */
4697                         if (randint0(100) < 75)
4698                         {
4699                                 /* Random direction */
4700                                 dir = ddd[randint0(8)];
4701                         }
4702                 }
4703                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
4704                 {
4705                         /* Random direction */
4706                         dir = ddd[randint0(8)];
4707                 }
4708                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
4709                 {
4710                         /* Random direction */
4711                         dir = ddd[randint0(8)];
4712                 }
4713         }
4714
4715         /* Notice confusion */
4716         if (command_dir != dir)
4717         {
4718                 if (p_ptr->confused)
4719                 {
4720                         /* Warn the user */
4721 #ifdef JP
4722 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4723 #else
4724                         msg_print("You are confused.");
4725 #endif
4726                 }
4727                 else
4728                 {
4729                         char m_name[80];
4730                         monster_type *m_ptr = &m_list[p_ptr->riding];
4731
4732                         monster_desc(m_name, m_ptr, 0);
4733                         if (MON_CONFUSED(m_ptr))
4734                         {
4735 #ifdef JP
4736 msg_format("%s¤Ïº®Í𤷤Ƥ¤¤ë¡£", m_name);
4737 #else
4738  msg_format("%^s is confusing.", m_name);
4739
4740 #endif
4741                         }
4742                         else
4743                         {
4744 #ifdef JP
4745 msg_format("%s¤Ï»×¤¤Ä̤ê¤ËÆ°¤¤¤Æ¤¯¤ì¤Ê¤¤¡£", m_name);
4746 #else
4747 msg_format("You cannot control %s.", m_name);
4748 #endif
4749                         }
4750                 }
4751         }
4752
4753         /* Save direction */
4754         (*dp) = dir;
4755
4756 #ifdef ALLOW_REPEAT /* TNB */
4757
4758 /*      repeat_push(dir); */
4759         repeat_push(command_dir);
4760
4761 #endif /* ALLOW_REPEAT -- TNB */
4762
4763         /* Success */
4764         return (TRUE);
4765 }
4766
4767
4768 bool get_rep_dir2(int *dp)
4769 {
4770         int dir;
4771
4772         /* Initialize */
4773         (*dp) = 0;
4774
4775         /* Global direction */
4776         dir = command_dir;
4777
4778 #ifdef ALLOW_REPEAT /* TNB */
4779
4780         if (repeat_pull(dp))
4781         {
4782                 dir = *dp;
4783 /*              return (TRUE); */
4784         }
4785
4786 #endif /* ALLOW_REPEAT -- TNB */
4787
4788         /* Get a direction */
4789         while (!dir)
4790         {
4791                 char ch;
4792
4793                 /* Get a command (or Cancel) */
4794 #ifdef JP
4795 if (!get_com("Êý¸þ (ESC¤ÇÃæÃÇ)? ", &ch, TRUE)) break;
4796 #else
4797                 if (!get_com("Direction (Escape to cancel)? ", &ch, TRUE)) break;
4798 #endif
4799
4800
4801                 /* Look up the direction */
4802                 dir = get_keymap_dir(ch);
4803
4804                 /* Oops */
4805                 if (!dir) bell();
4806         }
4807
4808         /* Prevent weirdness */
4809         if (dir == 5) dir = 0;
4810
4811         /* Aborted */
4812         if (!dir) return (FALSE);
4813
4814         /* Save desired direction */
4815         command_dir = dir;
4816
4817         /* Apply "confusion" */
4818         if (p_ptr->confused)
4819         {
4820                 /* Standard confusion */
4821                 if (randint0(100) < 75)
4822                 {
4823                         /* Random direction */
4824                         dir = ddd[randint0(8)];
4825                 }
4826         }
4827
4828         /* Notice confusion */
4829         if (command_dir != dir)
4830         {
4831                 /* Warn the user */
4832 #ifdef JP
4833 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4834 #else
4835                 msg_print("You are confused.");
4836 #endif
4837
4838         }
4839
4840         /* Save direction */
4841         (*dp) = dir;
4842
4843 #ifdef ALLOW_REPEAT /* TNB */
4844
4845 /*      repeat_push(dir); */
4846         repeat_push(command_dir);
4847
4848 #endif /* ALLOW_REPEAT -- TNB */
4849
4850         /* Success */
4851         return (TRUE);
4852 }
4853
4854 void gain_level_reward(int chosen_reward)
4855 {
4856         object_type *q_ptr;
4857         object_type forge;
4858         char        wrath_reason[32] = "";
4859         int         nasty_chance = 6;
4860         int         dummy = 0, dummy2 = 0;
4861         int         type, effect;
4862         cptr        reward = NULL;
4863         char o_name[MAX_NLEN];
4864
4865         int count = 0;
4866
4867         if (!chosen_reward)
4868         {
4869                 if (multi_rew) return;
4870                 else multi_rew = TRUE;
4871         }
4872
4873
4874         if (p_ptr->lev == 13) nasty_chance = 2;
4875         else if (!(p_ptr->lev % 13)) nasty_chance = 3;
4876         else if (!(p_ptr->lev % 14)) nasty_chance = 12;
4877
4878         if (one_in_(nasty_chance))
4879                 type = randint1(20); /* Allow the 'nasty' effects */
4880         else
4881                 type = randint1(15) + 5; /* Or disallow them */
4882
4883         if (type < 1) type = 1;
4884         if (type > 20) type = 20;
4885         type--;
4886
4887
4888 #ifdef JP
4889 sprintf(wrath_reason, "%s¤ÎÅܤê",
4890                 chaos_patrons[p_ptr->chaos_patron]);
4891 #else
4892         sprintf(wrath_reason, "the Wrath of %s",
4893                 chaos_patrons[p_ptr->chaos_patron]);
4894 #endif
4895
4896
4897         effect = chaos_rewards[p_ptr->chaos_patron][type];
4898
4899         if (one_in_(6) && !chosen_reward)
4900         {
4901 #ifdef JP
4902 msg_format("%^s¤ÏË«Èþ¤È¤·¤Æ¤¢¤Ê¤¿¤òÆÍÁ³ÊÑ°Û¤µ¤»¤¿¡£",
4903                         chaos_patrons[p_ptr->chaos_patron]);
4904 #else
4905                 msg_format("%^s rewards you with a mutation!",
4906                         chaos_patrons[p_ptr->chaos_patron]);
4907 #endif
4908
4909                 (void)gain_random_mutation(0);
4910 #ifdef JP
4911                 reward = "ÊÑ°Û¤·¤¿¡£";
4912 #else
4913                 reward = "mutation";
4914 #endif
4915         }
4916         else
4917         {
4918         switch (chosen_reward ? chosen_reward : effect)
4919         {
4920                 case REW_POLY_SLF:
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("'Thou needst a new form, mortal!'");
4933 #endif
4934
4935                         do_poly_self();
4936 #ifdef JP
4937                         reward = "ÊÑ°Û¤·¤¿¡£";
4938 #else
4939                         reward = "polymorphing";
4940 #endif
4941                         break;
4942                 case REW_GAIN_EXP:
4943 #ifdef JP
4944 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4945                                 chaos_patrons[p_ptr->chaos_patron]);
4946 #else
4947                         msg_format("The voice of %s booms out:",
4948                                 chaos_patrons[p_ptr->chaos_patron]);
4949 #endif
4950
4951 #ifdef JP
4952 msg_print("¡ÖÆò¤ÏÎɤ¯¹Ô¤¤¤¿¤ê¡ªÂ³¤±¤è¡ª¡×");
4953 #else
4954                         msg_print("'Well done, mortal! Lead on!'");
4955 #endif
4956
4957                         if (p_ptr->prace == RACE_ANDROID)
4958                         {
4959 #ifdef JP
4960                                 msg_print("¤·¤«¤·²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
4961 #else
4962                                 msg_print("But, nothing happen.");
4963 #endif
4964                         }
4965                         else if (p_ptr->exp < PY_MAX_EXP)
4966                         {
4967                                 s32b ee = (p_ptr->exp / 2) + 10;
4968                                 if (ee > 100000L) ee = 100000L;
4969 #ifdef JP
4970 msg_print("¹¹¤Ë·Ð¸³¤òÀѤó¤À¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
4971 #else
4972                                 msg_print("You feel more experienced.");
4973 #endif
4974
4975                                 gain_exp(ee);
4976 #ifdef JP
4977                                 reward = "·Ð¸³ÃͤòÆÀ¤¿";
4978 #else
4979                                 reward = "experience";
4980 #endif
4981                         }
4982                         break;
4983                 case REW_LOSE_EXP:
4984 #ifdef JP
4985 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4986                                 chaos_patrons[p_ptr->chaos_patron]);
4987 #else
4988                         msg_format("The voice of %s booms out:",
4989                                 chaos_patrons[p_ptr->chaos_patron]);
4990 #endif
4991
4992 #ifdef JP
4993 msg_print("¡Ö²¼Ëͤ衢Æò¤½¤ì¤ËÃͤ»¤º¡£¡×");
4994 #else
4995                         msg_print("'Thou didst not deserve that, slave.'");
4996 #endif
4997
4998                         if (p_ptr->prace == RACE_ANDROID)
4999                         {
5000 #ifdef JP
5001                                 msg_print("¤·¤«¤·²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
5002 #else
5003                                 msg_print("But, nothing happen.");
5004 #endif
5005                         }
5006                         else
5007                         {
5008                                 lose_exp(p_ptr->exp / 6);
5009 #ifdef JP
5010                                 reward = "·Ð¸³Ãͤò¼º¤Ã¤¿¡£";
5011 #else
5012                                 reward = "losing experience";
5013 #endif
5014                         }
5015                         break;
5016                 case REW_GOOD_OBJ:
5017 #ifdef JP
5018 msg_format("%s¤ÎÀ¼¤¬¤µ¤µ¤ä¤¤¤¿:",
5019                                 chaos_patrons[p_ptr->chaos_patron]);
5020 #else
5021                         msg_format("The voice of %s whispers:",
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, FALSE, FALSE, FALSE);
5032 #ifdef JP
5033                         reward = "¾å¼Á¤Ê¥¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
5034 #else
5035                         reward = "a good item";
5036 #endif
5037                         break;
5038                 case REW_GREA_OBJ:
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("'Use my gift wisely.'");
5051 #endif
5052
5053                         acquirement(py, px, 1, TRUE, FALSE, FALSE);
5054 #ifdef JP
5055                         reward = "¹âµéÉʤΥ¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
5056 #else
5057                         reward = "an excellent item";
5058 #endif
5059                         break;
5060                 case REW_CHAOS_WP:
5061 #ifdef JP
5062 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5063                                 chaos_patrons[p_ptr->chaos_patron]);
5064 #else
5065                         msg_format("The voice of %s booms out:",
5066                                 chaos_patrons[p_ptr->chaos_patron]);
5067 #endif
5068
5069 #ifdef JP
5070 msg_print("¡ÖÆò¤Î¹Ô¤¤¤Ïµ®¤­·õ¤ËÃͤ»¤ê¡£¡×");
5071 #else
5072                         msg_print("'Thy deed hath earned thee a worthy blade.'");
5073 #endif
5074
5075                         /* Get local object */
5076                         q_ptr = &forge;
5077                         dummy = TV_SWORD;
5078                         switch (randint1(p_ptr->lev))
5079                         {
5080                                 case 0: case 1:
5081                                         dummy2 = SV_DAGGER;
5082                                         break;
5083                                 case 2: case 3:
5084                                         dummy2 = SV_MAIN_GAUCHE;
5085                                         break;
5086                                 case 4:
5087                                         dummy2 = SV_TANTO;
5088                                         break;
5089                                 case 5: case 6:
5090                                         dummy2 = SV_RAPIER;
5091                                         break;
5092                                 case 7: case 8:
5093                                         dummy2 = SV_SMALL_SWORD;
5094                                         break;
5095                                 case 9: case 10:
5096                                         dummy2 = SV_BASILLARD;
5097                                         break;
5098                                 case 11: case 12: case 13:
5099                                         dummy2 = SV_SHORT_SWORD;
5100                                         break;
5101                                 case 14: case 15:
5102                                         dummy2 = SV_SABRE;
5103                                         break;
5104                                 case 16: case 17:
5105                                         dummy2 = SV_CUTLASS;
5106                                         break;
5107                                 case 18:
5108                                         dummy2 = SV_WAKIZASHI;
5109                                         break;
5110                                 case 19:
5111                                         dummy2 = SV_KHOPESH;
5112                                         break;
5113                                 case 20:
5114                                         dummy2 = SV_TULWAR;
5115                                         break;
5116                                 case 21:
5117                                         dummy2 = SV_BROAD_SWORD;
5118                                         break;
5119                                 case 22: case 23:
5120                                         dummy2 = SV_LONG_SWORD;
5121                                         break;
5122                                 case 24: case 25:
5123                                         dummy2 = SV_SCIMITAR;
5124                                         break;
5125                                 case 26:
5126                                         dummy2 = SV_NINJATO;
5127                                         break;
5128                                 case 27:
5129                                         dummy2 = SV_KATANA;
5130                                         break;
5131                                 case 28: case 29:
5132                                         dummy2 = SV_BASTARD_SWORD;
5133                                         break;
5134                                 case 30:
5135                                         dummy2 = SV_GREAT_SCIMITAR;
5136                                         break;
5137                                 case 31:
5138                                         dummy2 = SV_CLAYMORE;
5139                                         break;
5140                                 case 32:
5141                                         dummy2 = SV_ESPADON;
5142                                         break;
5143                                 case 33:
5144                                         dummy2 = SV_TWO_HANDED_SWORD;
5145                                         break;
5146                                 case 34:
5147                                         dummy2 = SV_FLAMBERGE;
5148                                         break;
5149                                 case 35:
5150                                         dummy2 = SV_NO_DACHI;
5151                                         break;
5152                                 case 36:
5153                                         dummy2 = SV_EXECUTIONERS_SWORD;
5154                                         break;
5155                                 case 37:
5156                                         dummy2 = SV_ZWEIHANDER;
5157                                         break;
5158                                 case 38:
5159                                         dummy2 = SV_HAYABUSA;
5160                                         break;
5161                                 default:
5162                                         dummy2 = SV_BLADE_OF_CHAOS;
5163                         }
5164
5165                         object_prep(q_ptr, lookup_kind(dummy, dummy2));
5166                         q_ptr->to_h = 3 + randint1(dun_level) % 10;
5167                         q_ptr->to_d = 3 + randint1(dun_level) % 10;
5168                         one_resistance(q_ptr);
5169                         q_ptr->name2 = EGO_CHAOTIC;
5170
5171                         /* Drop it in the dungeon */
5172                         (void)drop_near(q_ptr, -1, py, px);
5173 #ifdef JP
5174                         reward = "(º®ÆÙ)¤ÎÉð´ï¤ò¼ê¤ËÆþ¤ì¤¿¡£";
5175 #else
5176                         reward = "chaos weapon";
5177 #endif
5178                         break;
5179                 case REW_GOOD_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("'Thy deed hath earned thee a worthy reward.'");
5192 #endif
5193
5194                         acquirement(py, px, randint1(2) + 1, FALSE, FALSE, FALSE);
5195 #ifdef JP
5196                         reward = "¾å¼Á¤Ê¥¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
5197 #else
5198                         reward = "good items";
5199 #endif
5200                         break;
5201                 case REW_GREA_OBS:
5202 #ifdef JP
5203 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5204                                 chaos_patrons[p_ptr->chaos_patron]);
5205 #else
5206                         msg_format("The voice of %s booms out:",
5207                                 chaos_patrons[p_ptr->chaos_patron]);
5208 #endif
5209
5210 #ifdef JP
5211 msg_print("¡Ö²¼Ëͤ衢Æò¤Î¸¥¿È¤Ø¤Î²æ¤¬Àˤ·¤ß̵¤­Ê󤤤ò¸«¤ë¤¬¤è¤¤¡£¡×");
5212 #else
5213                         msg_print("'Behold, mortal, how generously I reward thy loyalty.'");
5214 #endif
5215
5216                         acquirement(py, px, randint1(2) + 1, TRUE, FALSE, FALSE);
5217 #ifdef JP
5218                         reward = "¹âµéÉʤΥ¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
5219 #else
5220                         reward = "excellent items";
5221 #endif
5222                         break;
5223                 case REW_TY_CURSE:
5224 #ifdef JP
5225 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5226                                 chaos_patrons[p_ptr->chaos_patron]);
5227 #else
5228                         msg_format("The voice of %s thunders:",
5229                                 chaos_patrons[p_ptr->chaos_patron]);
5230 #endif
5231
5232 #ifdef JP
5233 msg_print("¡Ö²¼Ëͤ衢ÆòÐþËý¤Ê¤ê¡£¡×");
5234 #else
5235                         msg_print("'Thou art growing arrogant, mortal.'");
5236 #endif
5237
5238                         (void)activate_ty_curse(FALSE, &count);
5239 #ifdef JP
5240                         reward = "²Ò¡¹¤·¤¤¼ö¤¤¤ò¤«¤±¤é¤ì¤¿¡£";
5241 #else
5242                         reward = "cursing";
5243 #endif
5244                         break;
5245                 case REW_SUMMON_M:
5246 #ifdef JP
5247 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5248                                 chaos_patrons[p_ptr->chaos_patron]);
5249 #else
5250                         msg_format("The voice of %s booms out:",
5251                                 chaos_patrons[p_ptr->chaos_patron]);
5252 #endif
5253
5254 #ifdef JP
5255 msg_print("¡Ö²æ¤¬²¼Ëͤ¿¤Á¤è¡¢¤«¤ÎÐþËý¤Ê¤ë¼Ô¤òÅݤ¹¤Ù¤·¡ª¡×");
5256 #else
5257                         msg_print("'My pets, destroy the arrogant mortal!'");
5258 #endif
5259
5260                         for (dummy = 0; dummy < randint1(5) + 1; dummy++)
5261                         {
5262                                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
5263                         }
5264 #ifdef JP
5265                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
5266 #else
5267                         reward = "summoning hostile monsters";
5268 #endif
5269                         break;
5270                 case REW_H_SUMMON:
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("'Thou needst worthier opponents!'");
5283 #endif
5284
5285                         activate_hi_summon(py, px, FALSE);
5286 #ifdef JP
5287                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
5288 #else
5289                         reward = "summoning many hostile monsters";
5290 #endif
5291                         break;
5292                 case REW_DO_HAVOC:
5293 #ifdef JP
5294 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5295                                 chaos_patrons[p_ptr->chaos_patron]);
5296 #else
5297                         msg_format("The voice of %s booms out:",
5298                                 chaos_patrons[p_ptr->chaos_patron]);
5299 #endif
5300
5301 #ifdef JP
5302 msg_print("¡Ö»à¤ÈÇ˲õ¤³¤½²æ¤¬´î¤Ó¤Ê¤ê¡ª¡×");
5303 #else
5304                         msg_print("'Death and destruction! This pleaseth me!'");
5305 #endif
5306
5307                         call_chaos();
5308 #ifdef JP
5309                         reward = "¥«¥ª¥¹¤ÎÎϤ¬±²´¬¤¤¤¿¡£";
5310 #else
5311                         reward = "calling chaos";
5312 #endif
5313                         break;
5314                 case REW_GAIN_ABL:
5315 #ifdef JP
5316 msg_format("%s¤ÎÀ¼¤¬ÌĤê¶Á¤¤¤¿:",
5317                                 chaos_patrons[p_ptr->chaos_patron]);
5318 #else
5319                         msg_format("The voice of %s rings out:",
5320                                 chaos_patrons[p_ptr->chaos_patron]);
5321 #endif
5322
5323 #ifdef JP
5324 msg_print("¡Öα¤Þ¤ë¤Î¤À¡¢²¼Ëͤ衣;¤¬Æò¤ÎÆùÂΤòÃ䨤󡣡×");
5325 #else
5326                         msg_print("'Stay, mortal, and let me mold thee.'");
5327 #endif
5328
5329                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
5330                                 do_inc_stat(chaos_stats[p_ptr->chaos_patron]);
5331                         else
5332                                 do_inc_stat(randint0(6));
5333 #ifdef JP
5334                         reward = "ǽÎÏÃͤ¬¾å¤¬¤Ã¤¿¡£";
5335 #else
5336                         reward = "increasing a stat";
5337 #endif
5338                         break;
5339                 case REW_LOSE_ABL:
5340 #ifdef JP
5341 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5342                                 chaos_patrons[p_ptr->chaos_patron]);
5343 #else
5344                         msg_format("The voice of %s booms out:",
5345                                 chaos_patrons[p_ptr->chaos_patron]);
5346 #endif
5347
5348 #ifdef JP
5349 msg_print("¡Ö²¼Ëͤ衢;¤ÏÆò¤ËË°¤ß¤¿¤ê¡£¡×");
5350 #else
5351                         msg_print("'I grow tired of thee, mortal.'");
5352 #endif
5353
5354                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
5355                                 do_dec_stat(chaos_stats[p_ptr->chaos_patron]);
5356                         else
5357                                 (void)do_dec_stat(randint0(6));
5358 #ifdef JP
5359                         reward = "ǽÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5360 #else
5361                         reward = "decreasing a stat";
5362 #endif
5363                         break;
5364                 case REW_RUIN_ABL:
5365 #ifdef JP
5366 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5367                                 chaos_patrons[p_ptr->chaos_patron]);
5368 #else
5369                         msg_format("The voice of %s thunders:",
5370                                 chaos_patrons[p_ptr->chaos_patron]);
5371 #endif
5372
5373 #ifdef JP
5374 msg_print("¡ÖÆò¡¢¸¬µõ¤¿¤ë¤³¤È¤ò³Ø¤Ö¤Ù¤·¡ª¡×");
5375 msg_print("¤¢¤Ê¤¿¤Ï°ÊÁ°¤è¤ê¼å¤¯¤Ê¤Ã¤¿¡ª");
5376 #else
5377                         msg_print("'Thou needst a lesson in humility, mortal!'");
5378                         msg_print("You feel less powerful!");
5379 #endif
5380
5381                         for (dummy = 0; dummy < 6; dummy++)
5382                         {
5383                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5384                         }
5385 #ifdef JP
5386                         reward = "Á´Ç½ÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5387 #else
5388                         reward = "decreasing all stats";
5389 #endif
5390                         break;
5391                 case REW_POLY_WND:
5392 #ifdef JP
5393 msg_format("%s¤ÎÎϤ¬¿¨¤ì¤ë¤Î¤ò´¶¤¸¤¿¡£",
5394 #else
5395                         msg_format("You feel the power of %s touch you.",
5396 #endif
5397
5398                                 chaos_patrons[p_ptr->chaos_patron]);
5399                         do_poly_wounds();
5400 #ifdef JP
5401                         reward = "½ý¤¬ÊѲ½¤·¤¿¡£";
5402 #else
5403                         reward = "polymorphing wounds";
5404 #endif
5405                         break;
5406                 case REW_AUGM_ABL:
5407 #ifdef JP
5408 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5409                                 chaos_patrons[p_ptr->chaos_patron]);
5410 #else
5411                         msg_format("The voice of %s booms out:",
5412                                 chaos_patrons[p_ptr->chaos_patron]);
5413 #endif
5414
5415 #ifdef JP
5416 msg_print("¡Ö²æ¤¬¤µ¤µ¤ä¤«¤Ê¤ë»òʪ¤ò¼õ¤±¤È¤ë¤¬¤è¤¤¡ª¡×");
5417 #else
5418                         msg_print("'Receive this modest gift from me!'");
5419 #endif
5420
5421                         for (dummy = 0; dummy < 6; dummy++)
5422                         {
5423                                 (void)do_inc_stat(dummy);
5424                         }
5425 #ifdef JP
5426                         reward = "Á´Ç½ÎÏÃͤ¬¾å¤¬¤Ã¤¿¡£";
5427 #else
5428                         reward = "increasing all stats";
5429 #endif
5430                         break;
5431                 case REW_HURT_LOT:
5432 #ifdef JP
5433 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5434                                 chaos_patrons[p_ptr->chaos_patron]);
5435 #else
5436                         msg_format("The voice of %s booms out:",
5437                                 chaos_patrons[p_ptr->chaos_patron]);
5438 #endif
5439
5440 #ifdef JP
5441 msg_print("¡Ö¶ì¤·¤à¤¬¤è¤¤¡¢ÌµÇ½¤Ê¶ò¤«¼Ô¤è¡ª¡×");
5442 #else
5443                         msg_print("'Suffer, pathetic fool!'");
5444 #endif
5445
5446                         fire_ball(GF_DISINTEGRATE, 0, p_ptr->lev * 4, 4);
5447                         take_hit(DAMAGE_NOESCAPE, p_ptr->lev * 4, wrath_reason, -1);
5448 #ifdef JP
5449                         reward = "ʬ²ò¤Îµå¤¬È¯À¸¤·¤¿¡£";
5450 #else
5451                         reward = "generating disintegration ball";
5452 #endif
5453                         break;
5454            case REW_HEAL_FUL:
5455 #ifdef JP
5456 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5457                                 chaos_patrons[p_ptr->chaos_patron]);
5458 #else
5459                         msg_format("The voice of %s booms out:",
5460                                 chaos_patrons[p_ptr->chaos_patron]);
5461 #endif
5462
5463 #ifdef JP
5464 msg_print("¡Öᴤ뤬¤è¤¤¡¢²æ¤¬²¼Ëͤ衪¡×");
5465 #else
5466                         msg_print("'Rise, my servant!'");
5467 #endif
5468
5469                         restore_level();
5470                         (void)set_poisoned(0);
5471                         (void)set_blind(0);
5472                         (void)set_confused(0);
5473                         (void)set_image(0);
5474                         (void)set_stun(0);
5475                         (void)set_cut(0);
5476                         hp_player(5000);
5477                         for (dummy = 0; dummy < 6; dummy++)
5478                         {
5479                                 (void)do_res_stat(dummy);
5480                         }
5481 #ifdef JP
5482                         reward = "ÂÎÎϤ¬²óÉü¤·¤¿¡£";
5483 #else
5484                         reward = "healing";
5485 #endif
5486                         break;
5487                 case REW_CURSE_WP:
5488                         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
5489 #ifdef JP
5490 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5491                                 chaos_patrons[p_ptr->chaos_patron]);
5492 #else
5493                         msg_format("The voice of %s booms out:",
5494                                 chaos_patrons[p_ptr->chaos_patron]);
5495 #endif
5496
5497 #ifdef JP
5498 msg_print("¡ÖÆò¡¢Éð´ï¤ËÍê¤ë¤³¤È¤Ê¤«¤ì¡£¡×");
5499 #else
5500                         msg_print("'Thou reliest too much on thy weapon.'");
5501 #endif
5502
5503                         dummy = INVEN_RARM;
5504                         if (buki_motteruka(INVEN_LARM))
5505                         {
5506                                 dummy = INVEN_LARM;
5507                                 if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
5508                         }
5509                         object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
5510                         (void)curse_weapon(FALSE, dummy);
5511 #ifdef JP
5512                         reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5513 #else
5514                         reward = format("destroying %s", o_name);
5515 #endif
5516                         break;
5517                 case REW_CURSE_AR:
5518                         if (!inventory[INVEN_BODY].k_idx) break;
5519 #ifdef JP
5520 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5521                                 chaos_patrons[p_ptr->chaos_patron]);
5522 #else
5523                         msg_format("The voice of %s booms out:",
5524                                 chaos_patrons[p_ptr->chaos_patron]);
5525 #endif
5526
5527 #ifdef JP
5528 msg_print("¡ÖÆò¡¢Ëɶñ¤ËÍê¤ë¤³¤È¤Ê¤«¤ì¡£¡×");
5529 #else
5530                         msg_print("'Thou reliest too much on thine equipment.'");
5531 #endif
5532
5533                         object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
5534                         (void)curse_armor();
5535 #ifdef JP
5536                         reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5537 #else
5538                         reward = format("destroying %s", o_name);
5539 #endif
5540                         break;
5541                 case REW_PISS_OFF:
5542 #ifdef JP
5543 msg_format("%s¤ÎÀ¼¤¬¤µ¤µ¤ä¤¤¤¿:",
5544                                 chaos_patrons[p_ptr->chaos_patron]);
5545 #else
5546                         msg_format("The voice of %s whispers:",
5547                                 chaos_patrons[p_ptr->chaos_patron]);
5548 #endif
5549
5550 #ifdef JP
5551 msg_print("¡Ö²æ¤òÅܤꤷ¤á¤¿ºá¤ò½þ¤¦¤Ù¤·¡£¡×");
5552 #else
5553                         msg_print("'Now thou shalt pay for annoying me.'");
5554 #endif
5555
5556                         switch (randint1(4))
5557                         {
5558                                 case 1:
5559                                         (void)activate_ty_curse(FALSE, &count);
5560 #ifdef JP
5561                                         reward = "²Ò¡¹¤·¤¤¼ö¤¤¤ò¤«¤±¤é¤ì¤¿¡£";
5562 #else
5563                                         reward = "cursing";
5564 #endif
5565                                         break;
5566                                 case 2:
5567                                         activate_hi_summon(py, px, FALSE);
5568 #ifdef JP
5569                                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
5570 #else
5571                                         reward = "summoning hostile monsters";
5572 #endif
5573                                         break;
5574                                 case 3:
5575                                         if (one_in_(2))
5576                                         {
5577                                                 if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
5578                                                 dummy = INVEN_RARM;
5579                                                 if (buki_motteruka(INVEN_LARM))
5580                                                 {
5581                                                         dummy = INVEN_LARM;
5582                                                         if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
5583                                                 }
5584                                                 object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
5585                                                 (void)curse_weapon(FALSE, dummy);
5586 #ifdef JP
5587                                                 reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5588 #else
5589                                                 reward = format("destroying %s", o_name);
5590 #endif
5591                                         }
5592                                         else
5593                                         {
5594                                                 if (!inventory[INVEN_BODY].k_idx) break;
5595                                                 object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
5596                                                 (void)curse_armor();
5597 #ifdef JP
5598                                                 reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5599 #else
5600                                                 reward = format("destroying %s", o_name);
5601 #endif
5602                                         }
5603                                         break;
5604                                 default:
5605                                         for (dummy = 0; dummy < 6; dummy++)
5606                                         {
5607                                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5608                                         }
5609 #ifdef JP
5610                                         reward = "Á´Ç½ÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5611 #else
5612                                         reward = "decreasing all stats";
5613 #endif
5614                                         break;
5615                         }
5616                         break;
5617                 case REW_WRATH:
5618 #ifdef JP
5619 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5620 #else
5621                         msg_format("The voice of %s thunders:",
5622 #endif
5623
5624                                 chaos_patrons[p_ptr->chaos_patron]);
5625 #ifdef JP
5626 msg_print("¡Ö»à¤Ì¤¬¤è¤¤¡¢²¼Ëͤ衪¡×");
5627 #else
5628                         msg_print("'Die, mortal!'");
5629 #endif
5630
5631                         take_hit(DAMAGE_LOSELIFE, p_ptr->lev * 4, wrath_reason, -1);
5632                         for (dummy = 0; dummy < 6; dummy++)
5633                         {
5634                                 (void)dec_stat(dummy, 10 + randint1(15), FALSE);
5635                         }
5636                         activate_hi_summon(py, px, FALSE);
5637                         (void)activate_ty_curse(FALSE, &count);
5638                         if (one_in_(2))
5639                         {
5640                                 dummy = 0;
5641
5642                                 if (buki_motteruka(INVEN_RARM))
5643                                 {
5644                                         dummy = INVEN_RARM;
5645                                         if (buki_motteruka(INVEN_LARM) && one_in_(2)) dummy = INVEN_LARM;
5646                                 }
5647                                 else if (buki_motteruka(INVEN_LARM)) dummy = INVEN_LARM;
5648
5649                                 if (dummy) (void)curse_weapon(FALSE, dummy);
5650                         }
5651                         if (one_in_(2)) (void)curse_armor();
5652                         break;
5653                 case REW_DESTRUCT:
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("'Death and destruction! This pleaseth me!'");
5666 #endif
5667
5668                         (void)destroy_area(py, px, 25, FALSE);
5669 #ifdef JP
5670                         reward = "¥À¥ó¥¸¥ç¥ó¤¬*Ç˲õ*¤µ¤ì¤¿¡£";
5671 #else
5672                         reward = "*destruct*ing dungeon";
5673 #endif
5674                         break;
5675                 case REW_GENOCIDE:
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)symbol_genocide(0, FALSE);
5691 #ifdef JP
5692                         reward = "¥â¥ó¥¹¥¿¡¼¤¬Ëõ»¦¤µ¤ì¤¿¡£";
5693 #else
5694                         reward = "genociding monsters";
5695 #endif
5696                         break;
5697                 case REW_MASS_GEN:
5698 #ifdef JP
5699 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5700                                 chaos_patrons[p_ptr->chaos_patron]);
5701 #else
5702                         msg_format("The voice of %s booms out:",
5703                                 chaos_patrons[p_ptr->chaos_patron]);
5704 #endif
5705
5706 #ifdef JP
5707 msg_print("¡Ö²æ¡¢Æò¤ÎŨ¤òËõ»¦¤»¤ó¡ª¡×");
5708 #else
5709                         msg_print("'Let me relieve thee of thine oppressors!'");
5710 #endif
5711
5712                         (void)mass_genocide(0, FALSE);
5713 #ifdef JP
5714                         reward = "¥â¥ó¥¹¥¿¡¼¤¬Ëõ»¦¤µ¤ì¤¿¡£";
5715 #else
5716                         reward = "genociding nearby monsters";
5717 #endif
5718                         break;
5719                 case REW_DISPEL_C:
5720 #ifdef JP
5721 msg_format("%s¤ÎÎϤ¬Å¨¤ò¹¶·â¤¹¤ë¤Î¤ò´¶¤¸¤¿¡ª",
5722                                 chaos_patrons[p_ptr->chaos_patron]);
5723 #else
5724                         msg_format("You can feel the power of %s assault your enemies!",
5725                                 chaos_patrons[p_ptr->chaos_patron]);
5726 #endif
5727
5728                         (void)dispel_monsters(p_ptr->lev * 4);
5729                         break;
5730                 case REW_IGNORE:
5731 #ifdef JP
5732 msg_format("%s¤Ï¤¢¤Ê¤¿¤ò̵»ë¤·¤¿¡£",
5733                                 chaos_patrons[p_ptr->chaos_patron]);
5734 #else
5735                         msg_format("%s ignores you.",
5736                                 chaos_patrons[p_ptr->chaos_patron]);
5737 #endif
5738
5739                         break;
5740                 case REW_SER_DEMO:
5741 #ifdef JP
5742 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ°­Ëâ¤Î»È¤¤¤ò¤è¤³¤·¤¿¡ª",chaos_patrons[p_ptr->chaos_patron]);
5743 #else
5744                         msg_format("%s rewards you with a demonic servant!",chaos_patrons[p_ptr->chaos_patron]);
5745 #endif
5746
5747                         if (!summon_specific(-1, py, px, dun_level, SUMMON_DEMON, PM_FORCE_PET))
5748 #ifdef JP
5749 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5750 #else
5751                                 msg_print("Nobody ever turns up...");
5752 #endif
5753                         else
5754 #ifdef JP
5755                                 reward = "°­Ë⤬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5756 #else
5757                                 reward = "a demonic servant";
5758 #endif
5759
5760                         break;
5761                 case REW_SER_MONS:
5762 #ifdef JP
5763 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ»È¤¤¤ò¤è¤³¤·¤¿¡ª",chaos_patrons[p_ptr->chaos_patron]);
5764 #else
5765                         msg_format("%s rewards you with a servant!",chaos_patrons[p_ptr->chaos_patron]);
5766 #endif
5767
5768                         if (!summon_specific(-1, py, px, dun_level, 0, PM_FORCE_PET))
5769 #ifdef JP
5770 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5771 #else
5772                                 msg_print("Nobody ever turns up...");
5773 #endif
5774                         else
5775 #ifdef JP
5776                                 reward = "¥â¥ó¥¹¥¿¡¼¤¬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5777 #else
5778                                 reward = "a servant";
5779 #endif
5780
5781                         break;
5782                 case REW_SER_UNDE:
5783 #ifdef JP
5784 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ¥¢¥ó¥Ç¥Ã¥É¤Î»È¤¤¤ò¤è¤³¤·¤¿¡£",chaos_patrons[p_ptr->chaos_patron]);
5785 #else
5786                         msg_format("%s rewards you with an undead servant!",chaos_patrons[p_ptr->chaos_patron]);
5787 #endif
5788
5789                         if (!summon_specific(-1, py, px, dun_level, SUMMON_UNDEAD, PM_FORCE_PET))
5790 #ifdef JP
5791 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5792 #else
5793                                 msg_print("Nobody ever turns up...");
5794 #endif
5795                         else
5796 #ifdef JP
5797                                 reward = "¥¢¥ó¥Ç¥Ã¥É¤¬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5798 #else
5799                                 reward = "an undead servant";
5800 #endif
5801
5802                         break;
5803                 default:
5804 #ifdef JP
5805 msg_format("%s¤ÎÀ¼¤¬¤É¤â¤Ã¤¿:",
5806 #else
5807                         msg_format("The voice of %s stammers:",
5808 #endif
5809
5810                                 chaos_patrons[p_ptr->chaos_patron]);
5811 #ifdef JP
5812 msg_format("¡Ö¤¢¡¼¡¢¤¢¡¼¡¢Åú¤¨¤Ï %d/%d¡£¼ÁÌä¤Ï²¿¡©¡×", type, effect);
5813 #else
5814                         msg_format("'Uh... uh... the answer's %d/%d, what's the question?'", type, effect);
5815 #endif
5816
5817         }
5818         }
5819         if (reward)
5820         {
5821 #ifdef JP
5822                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format("¥Ñ¥È¥í¥ó¤ÎÊó½·¤Ç%s", reward));
5823 #else
5824                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format("The patron rewards you with %s.", reward));
5825 #endif
5826         }
5827 }
5828
5829
5830 /*
5831  * XAngband: determine if a given location is "interesting"
5832  * based on target_set_accept function.
5833  */
5834 static bool tgt_pt_accept(int y, int x)
5835 {
5836         cave_type *c_ptr;
5837
5838         /* Bounds */
5839         if (!(in_bounds(y, x))) return (FALSE);
5840
5841         /* Player grid is always interesting */
5842         if ((y == py) && (x == px)) return (TRUE);
5843
5844         /* Handle hallucination */
5845         if (p_ptr->image) return (FALSE);
5846
5847         /* Examine the grid */
5848         c_ptr = &cave[y][x];
5849
5850         /* Interesting memorized features */
5851         if (c_ptr->info & (CAVE_MARK))
5852         {
5853                 /* Notice stairs */
5854                 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
5855                 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
5856
5857                 /* Notice quest features */
5858                 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
5859                 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
5860         }
5861
5862         /* Nope */
5863         return (FALSE);
5864 }
5865
5866
5867 /*
5868  * XAngband: Prepare the "temp" array for "tget_pt"
5869  * based on target_set_prepare funciton.
5870  */
5871 static void tgt_pt_prepare(void)
5872 {
5873         int y, x;
5874
5875         /* Reset "temp" array */
5876         temp_n = 0;
5877
5878         if (!expand_list) return;
5879
5880         /* Scan the current panel */
5881         for (y = 1; y < cur_hgt; y++)
5882         {
5883                 for (x = 1; x < cur_wid; x++)
5884                 {
5885                         /* Require "interesting" contents */
5886                         if (!tgt_pt_accept(y, x)) continue;
5887
5888                         /* Save the location */
5889                         temp_x[temp_n] = x;
5890                         temp_y[temp_n] = y;
5891                         temp_n++;
5892                 }
5893         }
5894
5895         /* Target the nearest monster for shooting */
5896         ang_sort_comp = ang_sort_comp_distance;
5897         ang_sort_swap = ang_sort_swap_distance;
5898
5899         /* Sort the positions */
5900         ang_sort(temp_x, temp_y, temp_n);
5901 }
5902
5903 /*
5904  * old -- from PsiAngband.
5905  */
5906 bool tgt_pt(int *x_ptr, int *y_ptr)
5907 {
5908         char ch = 0;
5909         int d, x, y, n;
5910         bool success = FALSE;
5911
5912         int wid, hgt;
5913
5914         /* Get size */
5915         get_screen_size(&wid, &hgt);
5916
5917         x = px;
5918         y = py;
5919
5920         if (expand_list) 
5921         {
5922                 tgt_pt_prepare();
5923                 n = 0;
5924         }
5925
5926 #ifdef JP
5927         msg_print("¾ì½ê¤òÁª¤ó¤Ç¥¹¥Ú¡¼¥¹¥­¡¼¤ò²¡¤·¤Æ²¼¤µ¤¤¡£");
5928 #else
5929         msg_print("Select a point and press space.");
5930 #endif
5931         msg_flag = FALSE; /* prevents "-more-" message. */
5932
5933         while ((ch != ESCAPE) && !success)
5934         {
5935                 bool move_fast = FALSE;
5936
5937                 move_cursor_relative(y, x);
5938                 ch = inkey();
5939                 switch (ch)
5940                 {
5941                 case ESCAPE:
5942                         break;
5943                 case ' ':
5944                 case 't':
5945                 case '.':
5946                 case '5':
5947                 case '0':
5948                         /* illegal place */
5949                         if (player_bold(y, x)) ch = 0;
5950
5951                         /* okay place */
5952                         else success = TRUE;
5953
5954                         break;
5955
5956                 /* XAngband: Move cursor to stairs */
5957                 case '>':
5958                 case '<':
5959                         if (expand_list && temp_n)
5960                         {
5961                                 int dx, dy;
5962                                 int cx = (panel_col_min + panel_col_max) / 2;
5963                                 int cy = (panel_row_min + panel_row_max) / 2;
5964
5965                                 n++;
5966
5967                                 /* Skip stairs which have defferent distance */
5968                                 for (; n < temp_n; ++ n)
5969                                 {
5970                                         cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
5971
5972                                         if (cave_have_flag_grid(c_ptr, FF_STAIRS) &&
5973                                             cave_have_flag_grid(c_ptr, ch == '>' ? FF_MORE : FF_LESS))
5974                                         {
5975                                                 /* Found */
5976                                                 break;
5977                                         }
5978                                 }
5979
5980                                 if (n == temp_n)        /* Loop out taget list */
5981                                 {
5982                                         n = 0;
5983                                         y = py;
5984                                         x = px;
5985                                         verify_panel(); /* Move cursor to player */
5986
5987                                         /* Update stuff */
5988                                         p_ptr->update |= (PU_MONSTERS);
5989
5990                                         /* Redraw map */
5991                                         p_ptr->redraw |= (PR_MAP);
5992
5993                                         /* Window stuff */
5994                                         p_ptr->window |= (PW_OVERHEAD);
5995
5996                                         /* Handle stuff */
5997                                         handle_stuff();
5998                                 }
5999                                 else    /* move cursor to next stair and change panel */
6000                                 {
6001                                         y = temp_y[n];
6002                                         x = temp_x[n];
6003
6004                                         dy = 2 * (y - cy) / hgt;
6005                                         dx = 2 * (x - cx) / wid;
6006                                         if (dy || dx) change_panel(dy, dx);
6007                                 }
6008                         }
6009                         break;
6010
6011                 default:
6012                         /* Look up the direction */
6013                         d = get_keymap_dir(ch);
6014
6015                         /* XTRA HACK MOVEFAST */
6016                         if (isupper(ch)) move_fast = TRUE;
6017
6018                         /* Handle "direction" */
6019                         if (d)
6020                         {
6021                                 int dx = ddx[d];
6022                                 int dy = ddy[d];
6023
6024                                 /* XTRA HACK MOVEFAST */
6025                                 if (move_fast)
6026                                 {
6027                                         int mag = MIN(wid / 2, hgt / 2);
6028                                         x += dx * mag;
6029                                         y += dy * mag;
6030                                 }
6031                                 else
6032                                 {
6033                                         x += dx;
6034                                         y += dy;
6035                                 }
6036
6037                                 /* Do not move horizontally if unnecessary */
6038                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
6039                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
6040                                 {
6041                                         dx = 0;
6042                                 }
6043
6044                                 /* Do not move vertically if unnecessary */
6045                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
6046                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
6047                                 {
6048                                         dy = 0;
6049                                 }
6050
6051                                 /* Apply the motion */
6052                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
6053                                          (x >= panel_col_min + wid) || (x < panel_col_min))
6054                                 {
6055                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
6056                                         change_panel(dy, dx);
6057                                 }
6058
6059                                 /* Slide into legality */
6060                                 if (x >= cur_wid-1) x = cur_wid - 2;
6061                                 else if (x <= 0) x = 1;
6062
6063                                 /* Slide into legality */
6064                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
6065                                 else if (y <= 0) y = 1;
6066
6067                         }
6068                         break;
6069                 }
6070         }
6071
6072         /* Clear the top line */
6073         prt("", 0, 0);
6074
6075         /* Recenter the map around the player */
6076         verify_panel();
6077
6078         /* Update stuff */
6079         p_ptr->update |= (PU_MONSTERS);
6080
6081         /* Redraw map */
6082         p_ptr->redraw |= (PR_MAP);
6083
6084         /* Window stuff */
6085         p_ptr->window |= (PW_OVERHEAD);
6086
6087         /* Handle stuff */
6088         handle_stuff();
6089
6090         *x_ptr = x;
6091         *y_ptr = y;
6092         return success;
6093 }
6094
6095
6096 bool get_hack_dir(int *dp)
6097 {
6098         int             dir;
6099         cptr    p;
6100         char    command;
6101
6102
6103         /* Initialize */
6104         (*dp) = 0;
6105
6106         /* Global direction */
6107         dir = 0;
6108
6109         /* (No auto-targeting) */
6110
6111         /* Ask until satisfied */
6112         while (!dir)
6113         {
6114                 /* Choose a prompt */
6115                 if (!target_okay())
6116                 {
6117 #ifdef JP
6118 p = "Êý¸þ ('*'¤Ç¥¿¡¼¥²¥Ã¥ÈÁªÂò, ESC¤ÇÃæÃÇ)? ";
6119 #else
6120                         p = "Direction ('*' to choose a target, Escape to cancel)? ";
6121 #endif
6122
6123                 }
6124                 else
6125                 {
6126 #ifdef JP
6127 p = "Êý¸þ ('5'¤Ç¥¿¡¼¥²¥Ã¥È¤Ø, '*'¤Ç¥¿¡¼¥²¥Ã¥ÈºÆÁªÂò, ESC¤ÇÃæÃÇ)? ";
6128 #else
6129                         p = "Direction ('5' for target, '*' to re-target, Escape to cancel)? ";
6130 #endif
6131
6132                 }
6133
6134                 /* Get a command (or Cancel) */
6135                 if (!get_com(p, &command, TRUE)) break;
6136
6137                 if (use_menu)
6138                 {
6139                         if (command == '\r') command = 't';
6140                 }  
6141
6142                 /* Convert various keys to "standard" keys */
6143                 switch (command)
6144                 {
6145                         /* Use current target */
6146                         case 'T':
6147                         case 't':
6148                         case '.':
6149                         case '5':
6150                         case '0':
6151                         {
6152                                 dir = 5;
6153                                 break;
6154                         }
6155
6156                         /* Set new target */
6157                         case '*':
6158                         case ' ':
6159                         case '\r':
6160                         {
6161                                 if (target_set(TARGET_KILL)) dir = 5;
6162                                 break;
6163                         }
6164
6165                         default:
6166                         {
6167                                 /* Look up the direction */
6168                                 dir = get_keymap_dir(command);
6169
6170                                 break;
6171                         }
6172                 }
6173
6174                 /* Verify requested targets */
6175                 if ((dir == 5) && !target_okay()) dir = 0;
6176
6177                 /* Error */
6178                 if (!dir) bell();
6179         }
6180
6181         /* No direction */
6182         if (!dir) return (FALSE);
6183
6184         /* Save the direction */
6185         command_dir = dir;
6186
6187         /* Check for confusion */
6188         if (p_ptr->confused)
6189         {
6190                 /* XXX XXX XXX */
6191                 /* Random direction */
6192                 dir = ddd[randint0(8)];
6193         }
6194
6195         /* Notice confusion */
6196         if (command_dir != dir)
6197         {
6198                 /* Warn the user */
6199 #ifdef JP
6200 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
6201 #else
6202                 msg_print("You are confused.");
6203 #endif
6204
6205         }
6206
6207         /* Save direction */
6208         (*dp) = dir;
6209
6210         /* A "valid" direction was entered */
6211         return (TRUE);
6212 }
6213
6214
6215 /*
6216  * ¥¨¥Í¥ë¥®¡¼¤ÎÁý²ÃÎÌ10d5¤ò®¤¯·×»»¤¹¤ë¤¿¤á¤Î´Ø¿ô
6217  */
6218
6219 #define Go_no_JuuJou 5*5*5*5*5*5*5*5*5*5
6220
6221 s16b gain_energy(void)
6222 {
6223         int i;
6224         s32b energy_result = 10;
6225         s32b tmp;
6226
6227         tmp = randint0(Go_no_JuuJou);
6228
6229         for (i = 0; i < 9; i ++){
6230                 energy_result += tmp % 5;
6231                 tmp /= 5;
6232         }
6233
6234         return (s16b)(energy_result + tmp);
6235 }
6236
6237
6238 /*
6239  * Return bow energy 
6240  */
6241 s16b bow_energy(int sval)
6242 {
6243         int energy = 100;
6244
6245         /* Analyze the launcher */
6246         switch (sval)
6247         {
6248                 /* Sling and ammo */
6249                 case SV_SLING:
6250                 {
6251                         energy = 8000;
6252                         break;
6253                 }
6254
6255                 /* Short Bow and Arrow */
6256                 case SV_SHORT_BOW:
6257                 {
6258                         energy = 10000;
6259                         break;
6260                 }
6261
6262                 /* Long Bow and Arrow */
6263                 case SV_LONG_BOW:
6264                 {
6265                         energy = 10000;
6266                         break;
6267                 }
6268
6269                 /* Bow of irresponsiblity and Arrow */
6270                 case SV_NAMAKE_BOW:
6271                 {
6272                         energy = 7777;
6273                         break;
6274                 }
6275
6276                 /* Light Crossbow and Bolt */
6277                 case SV_LIGHT_XBOW:
6278                 {
6279                         energy = 12000;
6280                         break;
6281                 }
6282
6283                 /* Heavy Crossbow and Bolt */
6284                 case SV_HEAVY_XBOW:
6285                 {
6286                         energy = 13333;
6287                         break;
6288                 }
6289         }
6290
6291         return (energy);
6292 }
6293
6294
6295 /*
6296  * Return bow tmul
6297  */
6298 int bow_tmul(int sval)
6299 {
6300         int tmul = 0;
6301
6302         /* Analyze the launcher */
6303         switch (sval)
6304         {
6305                 /* Sling and ammo */
6306                 case SV_SLING:
6307                 {
6308                         tmul = 2;
6309                         break;
6310                 }
6311
6312                 /* Short Bow and Arrow */
6313                 case SV_SHORT_BOW:
6314                 {
6315                         tmul = 2;
6316                         break;
6317                 }
6318
6319                 /* Long Bow and Arrow */
6320                 case SV_LONG_BOW:
6321                 {
6322                         tmul = 3;
6323                         break;
6324                 }
6325
6326                 /* Bow of irresponsiblity and Arrow */
6327                 case SV_NAMAKE_BOW:
6328                 {
6329                         tmul = 3;
6330                         break;
6331                 }
6332
6333                 /* Light Crossbow and Bolt */
6334                 case SV_LIGHT_XBOW:
6335                 {
6336                         tmul = 3;
6337                         break;
6338                 }
6339
6340                 /* Heavy Crossbow and Bolt */
6341                 case SV_HEAVY_XBOW:
6342                 {
6343                         tmul = 4;
6344                         break;
6345                 }
6346         }
6347
6348         return (tmul);
6349 }
6350
6351 /*
6352  * Return alignment title
6353  */
6354 cptr your_alignment(void)
6355 {
6356 #ifdef JP
6357         if (p_ptr->align > 150) return "ÂçÁ±";
6358         else if (p_ptr->align > 50) return "ÃæÁ±";
6359         else if (p_ptr->align > 10) return "¾®Á±";
6360         else if (p_ptr->align > -11) return "ÃæΩ";
6361         else if (p_ptr->align > -51) return "¾®°­";
6362         else if (p_ptr->align > -151) return "Ãæ°­";
6363         else return "Âç°­";
6364 #else
6365         if (p_ptr->align > 150) return "Lawful";
6366         else if (p_ptr->align > 50) return "Good";
6367         else if (p_ptr->align > 10) return "Neutral Good";
6368         else if (p_ptr->align > -11) return "Neutral";
6369         else if (p_ptr->align > -51) return "Neutral Evil";
6370         else if (p_ptr->align > -151) return "Evil";
6371         else return "Chaotic";
6372 #endif
6373 }
6374
6375
6376 /*
6377  * Return proficiency level of weapons and misc. skills (except riding)
6378  */
6379 int weapon_exp_level(int weapon_exp)
6380 {
6381         if (weapon_exp < WEAPON_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
6382         else if (weapon_exp < WEAPON_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
6383         else if (weapon_exp < WEAPON_EXP_EXPERT) return EXP_LEVEL_SKILLED;
6384         else if (weapon_exp < WEAPON_EXP_MASTER) return EXP_LEVEL_EXPERT;
6385         else return EXP_LEVEL_MASTER;
6386 }
6387
6388
6389 /*
6390  * Return proficiency level of riding
6391  */
6392 int riding_exp_level(int riding_exp)
6393 {
6394         if (riding_exp < RIDING_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
6395         else if (riding_exp < RIDING_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
6396         else if (riding_exp < RIDING_EXP_EXPERT) return EXP_LEVEL_SKILLED;
6397         else if (riding_exp < RIDING_EXP_MASTER) return EXP_LEVEL_EXPERT;
6398         else return EXP_LEVEL_MASTER;
6399 }
6400
6401
6402 /*
6403  * Return proficiency level of spells
6404  */
6405 int spell_exp_level(int spell_exp)
6406 {
6407         if (spell_exp < SPELL_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
6408         else if (spell_exp < SPELL_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
6409         else if (spell_exp < SPELL_EXP_EXPERT) return EXP_LEVEL_SKILLED;
6410         else if (spell_exp < SPELL_EXP_MASTER) return EXP_LEVEL_EXPERT;
6411         else return EXP_LEVEL_MASTER;
6412 }
6413
6414
6415 /*
6416  * Display a rumor and apply its effects
6417  */
6418
6419 int rumor_num(char *zz, int max_idx)
6420 {
6421         if (strcmp(zz, "*") == 0) return randint1(max_idx - 1);
6422         return atoi(zz);
6423 }
6424
6425 cptr rumor_bind_name(char *base, cptr fullname)
6426 {
6427         char *s, *v;
6428
6429         s = strstr(base, "{Name}");
6430         if (s)
6431         {
6432                 s[0] = '\0';
6433                 v = format("%s%s%s", base, fullname, (s + 6));
6434         }
6435         else
6436         {
6437                 v = base;
6438         }
6439
6440         return v;
6441 }
6442
6443 void display_rumor(bool ex)
6444 {
6445         bool err;
6446         int section = 0;
6447         char Rumor[1024];
6448
6449         if (ex)
6450         {
6451                 if (randint0(3) == 0) section = 1;
6452         }
6453
6454 #ifdef JP
6455         err = get_rnd_line_jonly("rumors_j.txt", section, Rumor, 10);
6456         if (err) strcpy(Rumor, "±³¤Î±½¤â¤¢¤ë¡£");
6457 #else
6458         err = get_rnd_line("rumors.txt", section, Rumor);
6459         if (err) strcpy(Rumor, "Some rumors are wrong.");
6460 #endif
6461
6462         err = TRUE;
6463
6464         if (strncmp(Rumor, "R:", 2) == 0)
6465         {
6466                 char *zz[4];
6467                 cptr rumor_msg = NULL;
6468                 cptr rumor_eff_format = NULL;
6469                 char fullname[1024] = "";
6470
6471                 if (tokenize(Rumor + 2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
6472                 {
6473                         if (strcmp(zz[0], "ARTIFACT") == 0)
6474                         {
6475                                 int a_idx, k_idx;
6476                                 object_type forge;
6477                                 object_type *q_ptr = &forge;
6478                                 artifact_type *a_ptr;
6479
6480                                 while (1)
6481                                 {
6482                                         a_idx = rumor_num(zz[1], max_a_idx);
6483
6484                                         a_ptr = &a_info[a_idx];
6485                                         if (a_ptr->name) break;
6486                                 }
6487
6488                                 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
6489                                 object_prep(q_ptr, k_idx);
6490                                 q_ptr->name1 = a_idx;
6491                                 q_ptr->ident = IDENT_STORE;
6492                                 object_desc(fullname, q_ptr, OD_NAME_ONLY);
6493                         }
6494                         else if  (strcmp(zz[0], "MONSTER") == 0)
6495                         {
6496                                 int r_idx;
6497                                 monster_race *r_ptr;
6498
6499                                 while(1)
6500                                 {
6501                                         r_idx = rumor_num(zz[1], max_r_idx);
6502                                         r_ptr = &r_info[r_idx];
6503                                         if (r_ptr->name) break;
6504                                 }
6505
6506                                 strcpy(fullname, r_name + r_ptr->name);
6507
6508                                 /* Remember this monster */
6509                                 if (!r_ptr->r_sights)
6510                                 {
6511                                         r_ptr->r_sights++;
6512                                 }
6513                         }
6514                         else if  (strcmp(zz[0], "DUNGEON") == 0)
6515                         {
6516                                 int d_idx;
6517                                 dungeon_info_type *d_ptr;
6518
6519                                 while (1)
6520                                 {
6521                                         d_idx = rumor_num(zz[1], max_d_idx);
6522                                         d_ptr = &d_info[d_idx];
6523                                         if (d_ptr->name) break;
6524                                 }
6525
6526                                 strcpy(fullname, d_name + d_ptr->name);
6527
6528                                 if (!max_dlv[d_idx])
6529                                 {
6530                                         max_dlv[d_idx] = d_ptr->mindepth;
6531                                         rumor_eff_format = _("%s¤Ëµ¢´Ô¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£", "You can recall to %s.");
6532                                 }
6533                         }
6534                         else if  (strcmp(zz[0], "TOWN") == 0)
6535                         {
6536                                 int t_idx;
6537                                 s32b visit;
6538
6539                                 while(1)
6540                                 {
6541                                         t_idx = rumor_num(zz[1], NO_TOWN);
6542                                         if (town[t_idx].name) break;
6543                                 }
6544
6545                                 strcpy(fullname, town[t_idx].name);
6546
6547                                 visit = (1L << (t_idx - 1));
6548                                 if ((t_idx != SECRET_TOWN) && !(p_ptr->visit & visit))
6549                                 {
6550                                         p_ptr->visit |= visit;
6551                                         rumor_eff_format = _("%s¤Ë¹Ô¤Ã¤¿¤³¤È¤¬¤¢¤ëµ¤¤¬¤¹¤ë¡£", "You feel you have been to %s.");
6552                                 }
6553                         }
6554
6555                         rumor_msg = rumor_bind_name(zz[2], fullname);
6556                         msg_print(rumor_msg);
6557                         if (rumor_eff_format)
6558                         {
6559                                 msg_print(NULL);
6560                                 msg_format(rumor_eff_format, fullname);
6561                         }
6562                         err = FALSE;
6563                 }
6564         /* error */
6565 #ifdef JP
6566                 if (err) msg_print("¤³¤Î¾ðÊó¤Ï´Ö°ã¤Ã¤Æ¤¤¤ë¡£");
6567 #else
6568                 if (err) msg_print("This information is wrong.");
6569 #endif
6570         }
6571                         else
6572         {
6573                 msg_format("%s", Rumor);
6574         }
6575 }