OSDN Git Service

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