OSDN Git Service

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