OSDN Git Service

BCC++ 5.5.1で警告封じオプション -w- を外した場合のコンパイル警告の除去.
[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 & MFLAG_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 & MFLAG_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 & MFLAG_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 & MFLAG_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                         do_cmd_write_nikki(NIKKI_UNIQUE, 0, r_name + r_ptr->name);
1882
1883                 /* Make a sound */
1884                 sound(SOUND_KILL);
1885
1886                 /* Death by Missile/Spell attack */
1887                 if (note)
1888                 {
1889                         msg_format("%^s%s", m_name, note);
1890                 }
1891
1892                 /* Death by physical attack -- invisible monster */
1893                 else if (!m_ptr->ml)
1894                 {
1895 #ifdef JP
1896                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1897                                 msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤ò»¦¤·¤¿¡£", m_name);
1898                         else
1899 msg_format("%s¤ò»¦¤·¤¿¡£", m_name);
1900 #else
1901                                 msg_format("You have killed %s.", m_name);
1902 #endif
1903
1904                 }
1905
1906                 /* Death by Physical attack -- non-living monster */
1907                 else if (!monster_living(r_ptr))
1908                 {
1909                         int i;
1910                         bool explode = FALSE;
1911
1912                         for (i = 0; i < 4; i++)
1913                         {
1914                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
1915                         }
1916
1917                         /* Special note at death */
1918                         if (explode)
1919 #ifdef JP
1920 msg_format("%s¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_name);
1921 #else
1922                                 msg_format("%s explodes into tiny shreds.", m_name);
1923 #endif
1924                         else
1925                         {
1926 #ifdef JP
1927                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1928                                         msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤òÅݤ·¤¿¡£", m_name);
1929                                 else
1930 msg_format("%s¤òÅݤ·¤¿¡£", m_name);
1931 #else
1932                                 msg_format("You have destroyed %s.", m_name);
1933 #endif
1934                         }
1935                 }
1936
1937                 /* Death by Physical attack -- living monster */
1938                 else
1939                 {
1940 #ifdef JP
1941                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
1942                                 msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤òÁò¤êµî¤Ã¤¿¡£", m_name);
1943                         else
1944 msg_format("%s¤òÁò¤êµî¤Ã¤¿¡£", m_name);
1945 #else
1946                                 msg_format("You have slain %s.", m_name);
1947 #endif
1948
1949                 }
1950                 if (r_ptr->flags1 & RF1_UNIQUE && !(m_ptr->smart & SM_CLONED))
1951                 {
1952                         for (i = 0; i < MAX_KUBI; i++)
1953                         {
1954                                 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG_CHAMELEON))
1955                                 {
1956 #ifdef JP
1957 msg_format("%s¤Î¼ó¤Ë¤Ï¾Þ¶â¤¬¤«¤«¤Ã¤Æ¤¤¤ë¡£", m_name);
1958 #else
1959                                         msg_format("There is a price on %s's head.", m_name);
1960 #endif
1961                                         break;
1962                                 }
1963                         }
1964                 }
1965
1966                 if (r_ptr->flags7 & RF7_KILL_EXP)
1967                         get_exp_from_mon((long)m_ptr->max_maxhp*2, &exp_mon);
1968                 else
1969                         get_exp_from_mon(((long)m_ptr->max_maxhp+1L) * 9L / 10L, &exp_mon);
1970
1971                 /* Generate treasure */
1972                 monster_death(m_idx, TRUE);
1973                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1974                 {
1975                         r_info[MON_BANORLUPART].max_num = 0;
1976                         r_info[MON_BANORLUPART].r_pkills++;
1977                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1978                 }
1979
1980                 if (m_ptr->r_idx == MON_BANORLUPART)
1981                 {
1982                         r_info[MON_BANOR].max_num = 0;
1983                         r_info[MON_BANOR].r_pkills++;
1984                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1985                         r_info[MON_LUPART].max_num = 0;
1986                         r_info[MON_LUPART].r_pkills++;
1987                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1988                 }
1989
1990                 /* Mega hack : replace IKETA to BIKETAL */
1991                 if ((m_ptr->r_idx == MON_IKETA) &&
1992                     !(p_ptr->inside_arena || p_ptr->inside_battle))
1993                 {
1994                         int dummy_y = m_ptr->fy;
1995                         int dummy_x = m_ptr->fx;
1996                         u32b mode = 0L;
1997
1998                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
1999
2000                         /* Delete the monster */
2001                         delete_monster_idx(m_idx);
2002
2003                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
2004                         {
2005 #ifdef JP
2006                                 msg_print("¡Ö¥Ï¥¡¥Ã¥Ï¥Ã¥Ï¥Ã¥Ï¡ª¡ª»ä¤¬¥Ð¥¤¥±¥¿¥ë¤À¡ª¡ª¡×");
2007 #else
2008                                 msg_print("Uwa-hahaha!  *I* am Biketal!");
2009 #endif
2010                         }
2011                 }
2012                 else
2013                 {
2014                         /* Delete the monster */
2015                         delete_monster_idx(m_idx);
2016                 }
2017
2018                 /* Not afraid */
2019                 (*fear) = FALSE;
2020
2021                 /* Monster is dead */
2022                 return (TRUE);
2023         }
2024
2025
2026 #ifdef ALLOW_FEAR
2027
2028         /* Mega-Hack -- Pain cancels fear */
2029         if (m_ptr->monfear && (dam > 0))
2030         {
2031                 int tmp = randint1(dam);
2032
2033                 /* Cure a little fear */
2034                 if (tmp < m_ptr->monfear)
2035                 {
2036                         /* Reduce fear */
2037                         m_ptr->monfear -= tmp;
2038                 }
2039
2040                 /* Cure all the fear */
2041                 else
2042                 {
2043                         /* Cure fear */
2044                         m_ptr->monfear = 0;
2045
2046                         /* No more fear */
2047                         (*fear) = FALSE;
2048                 }
2049         }
2050
2051         /* Sometimes a monster gets scared by damage */
2052         if (!m_ptr->monfear && !(r_ptr->flags3 & (RF3_NO_FEAR)))
2053         {
2054                 int percentage;
2055
2056                 /* Percentage of fully healthy */
2057                 percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
2058
2059                 /*
2060                  * Run (sometimes) if at 10% or less of max hit points,
2061                  * or (usually) when hit for half its current hit points
2062                  */
2063                 if ((randint1(10) >= percentage) ||
2064                     ((dam >= m_ptr->hp) && (randint0(100) < 80)))
2065                 {
2066                         /* Hack -- note fear */
2067                         (*fear) = TRUE;
2068
2069                         /* XXX XXX XXX Hack -- Add some timed fear */
2070                         m_ptr->monfear = (randint1(10) +
2071                                           (((dam >= m_ptr->hp) && (percentage > 7)) ?
2072                                            20 : ((11 - percentage) * 5)));
2073                 }
2074         }
2075
2076 #endif
2077
2078 #if 0
2079         if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
2080         {
2081                 char m_name[80];
2082
2083                 /* Extract monster name */
2084                 monster_desc(m_name, m_ptr, 0);
2085
2086                 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
2087                 if (rakuba((dam > 200) ? 200 : dam, FALSE))
2088                 {
2089 #ifdef JP
2090 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
2091 #else
2092                                 msg_format("%^s has thrown you off!", m_name);
2093 #endif
2094                 }
2095         }
2096 #endif
2097
2098         /* Not dead yet */
2099         return (FALSE);
2100 }
2101
2102
2103 /*
2104  * Get term size and calculate screen size
2105  */
2106 void get_screen_size(int *wid_p, int *hgt_p)
2107 {
2108         Term_get_size(wid_p, hgt_p);
2109         *hgt_p -= ROW_MAP + 2;
2110         *wid_p -= COL_MAP + 2;
2111         if (use_bigtile) *wid_p /= 2;
2112 }
2113
2114
2115 /*
2116  * Calculates current boundaries
2117  * Called below and from "do_cmd_locate()".
2118  */
2119 void panel_bounds_center(void)
2120 {
2121         int wid, hgt;
2122
2123         /* Get size */
2124         get_screen_size(&wid, &hgt);
2125
2126         panel_row_max = panel_row_min + hgt - 1;
2127         panel_row_prt = panel_row_min - 1;
2128         panel_col_max = panel_col_min + wid - 1;
2129         panel_col_prt = panel_col_min - 13;
2130 }
2131
2132
2133 /*
2134  * Map resizing whenever the main term changes size
2135  */
2136 void resize_map(void)
2137 {
2138         /* Only if the dungeon exists */
2139         if (!character_dungeon) return;
2140         
2141         /* Mega-Hack -- no panel yet */
2142         panel_row_max = 0;
2143         panel_col_max = 0;
2144
2145         /* Reset the panels */
2146         panel_row_min = cur_hgt;
2147         panel_col_min = cur_wid;
2148                                 
2149         verify_panel();
2150
2151         /* Update stuff */
2152         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
2153
2154         /* Forget lite/view */
2155         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
2156
2157         /* Update lite/view */
2158         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
2159
2160         /* Update monsters */
2161         p_ptr->update |= (PU_MONSTERS);
2162
2163         /* Redraw everything */
2164         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
2165
2166         /* Hack -- update */
2167         handle_stuff();
2168         
2169         /* Redraw */
2170         Term_redraw();
2171
2172         /*
2173          * Waiting command;
2174          * Place the cursor on the player
2175          */
2176         if (can_save) move_cursor_relative(py, px);
2177
2178         /* Refresh */
2179         Term_fresh();
2180 }
2181
2182 /*
2183  * Redraw a term when it is resized
2184  */
2185 void redraw_window(void)
2186 {
2187         /* Only if the dungeon exists */
2188         if (!character_dungeon) return;
2189         
2190         /* Hack - Activate term zero for the redraw */
2191         Term_activate(&term_screen[0]);
2192         
2193         /* Hack -- react to changes */
2194         Term_xtra(TERM_XTRA_REACT, 0);
2195
2196         /* Window stuff */
2197         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
2198
2199         /* Window stuff */
2200         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
2201
2202         /* Hack -- update */
2203         handle_stuff();
2204
2205         /* Redraw */
2206         Term_redraw();
2207
2208         /* Refresh */
2209         Term_fresh();
2210 }
2211
2212
2213 /*
2214  * Handle a request to change the current panel
2215  *
2216  * Return TRUE if the panel was changed.
2217  *
2218  * Also used in do_cmd_locate
2219  */
2220 bool change_panel(int dy, int dx)
2221 {
2222         int y, x;
2223         int wid, hgt;
2224
2225         /* Get size */
2226         get_screen_size(&wid, &hgt);
2227
2228         /* Apply the motion */
2229         y = panel_row_min + dy * hgt / 2;
2230         x = panel_col_min + dx * wid / 2;
2231
2232         /* Verify the row */
2233         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
2234         if (y < 0) y = 0;
2235
2236         /* Verify the col */
2237         if (x > cur_wid - wid) x = cur_wid - wid;
2238         if (x < 0) x = 0;
2239
2240         /* Handle "changes" */
2241         if ((y != panel_row_min) || (x != panel_col_min))
2242         {
2243                 /* Save the new panel info */
2244                 panel_row_min = y;
2245                 panel_col_min = x;
2246
2247                 /* Recalculate the boundaries */
2248                 panel_bounds_center();
2249
2250                 /* Update stuff */
2251                 p_ptr->update |= (PU_MONSTERS);
2252
2253                 /* Redraw map */
2254                 p_ptr->redraw |= (PR_MAP);
2255
2256                 /* Handle stuff */
2257                 handle_stuff();
2258
2259                 /* Success */
2260                 return (TRUE);
2261         }
2262
2263         /* No change */
2264         return (FALSE);
2265 }
2266
2267
2268 /*
2269  * Given an row (y) and col (x), this routine detects when a move
2270  * off the screen has occurred and figures new borders. -RAK-
2271  *
2272  * "Update" forces a "full update" to take place.
2273  *
2274  * The map is reprinted if necessary, and "TRUE" is returned.
2275  */
2276 void verify_panel(void)
2277 {
2278         int y = py;
2279         int x = px;
2280         int wid, hgt;
2281
2282         int prow_min;
2283         int pcol_min;
2284         int max_prow_min;
2285         int max_pcol_min;
2286
2287         /* Get size */
2288         get_screen_size(&wid, &hgt);
2289
2290         max_prow_min = cur_hgt - hgt;
2291         max_pcol_min = cur_wid - wid;
2292
2293         /* Bounds checking */
2294         if (max_prow_min < 0) max_prow_min = 0;
2295         if (max_pcol_min < 0) max_pcol_min = 0;
2296
2297                 /* Center on player */
2298         if (center_player && (center_running || !running))
2299         {
2300                 /* Center vertically */
2301                 prow_min = y - hgt / 2;
2302                 if (prow_min < 0) prow_min = 0;
2303                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
2304
2305                 /* Center horizontally */
2306                 pcol_min = x - wid / 2;
2307                 if (pcol_min < 0) pcol_min = 0;
2308                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2309         }
2310         else
2311         {
2312                 prow_min = panel_row_min;
2313                 pcol_min = panel_col_min;
2314
2315                 /* Scroll screen when 2 grids from top/bottom edge */
2316                 if (y > panel_row_max - 2)
2317                 {
2318                         while (y > prow_min + hgt-1 - 2)
2319                         {
2320                                 prow_min += (hgt / 2);
2321                         }
2322                 }
2323
2324                 if (y < panel_row_min + 2)
2325                 {
2326                         while (y < prow_min + 2)
2327                         {
2328                                 prow_min -= (hgt / 2);
2329                         }
2330                 }
2331
2332                 if (prow_min > max_prow_min) prow_min = max_prow_min;
2333                 if (prow_min < 0) prow_min = 0;
2334
2335                 /* Scroll screen when 4 grids from left/right edge */
2336                 if (x > panel_col_max - 4)
2337                 {
2338                         while (x > pcol_min + wid-1 - 4)
2339                         {
2340                                 pcol_min += (wid / 2);
2341                         }
2342                 }
2343                 
2344                 if (x < panel_col_min + 4)
2345                 {
2346                         while (x < pcol_min + 4)
2347                         {
2348                                 pcol_min -= (wid / 2);
2349                         }
2350                 }
2351
2352                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2353                 if (pcol_min < 0) pcol_min = 0;
2354         }
2355
2356         /* Check for "no change" */
2357         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
2358
2359         /* Save the new panel info */
2360         panel_row_min = prow_min;
2361         panel_col_min = pcol_min;
2362
2363         /* Hack -- optional disturb on "panel change" */
2364         if (disturb_panel && !center_player) disturb(0, 0);
2365
2366         /* Recalculate the boundaries */
2367         panel_bounds_center();
2368
2369         /* Update stuff */
2370         p_ptr->update |= (PU_MONSTERS);
2371
2372         /* Redraw map */
2373         p_ptr->redraw |= (PR_MAP);
2374
2375         /* Window stuff */
2376         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2377 }
2378
2379
2380 /*
2381  * Monster health description
2382  */
2383 cptr look_mon_desc(int m_idx, u32b mode)
2384 {
2385         monster_type *m_ptr = &m_list[m_idx];
2386         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2387         bool         living;
2388         int          perc;
2389         cptr desc;
2390         cptr attitude;
2391         cptr clone;
2392
2393         /* Determine if the monster is "living" */
2394         living = monster_living(ap_r_ptr);
2395
2396         /* Calculate a health "percentage" */
2397         perc = 100L * m_ptr->hp / m_ptr->maxhp;
2398
2399         /* Healthy monsters */
2400         if (m_ptr->hp >= m_ptr->maxhp)
2401         {
2402                 /* No damage */
2403 #ifdef JP
2404                 desc = living ? "̵½ý" : "̵¥À¥á¡¼¥¸";
2405 #else
2406                 desc = living ? "unhurt" : "undamaged";
2407 #endif
2408
2409         }
2410
2411         else if (perc >= 60)
2412         {
2413 #ifdef JP
2414                 desc = living ? "·Ú½ý" : "¾®¥À¥á¡¼¥¸";
2415 #else
2416                 desc = living ? "somewhat wounded" : "somewhat damaged";
2417 #endif
2418
2419         }
2420
2421         else if (perc >= 25)
2422         {
2423 #ifdef JP
2424                 desc = living ? "Éé½ý" : "Ãæ¥À¥á¡¼¥¸";
2425 #else
2426                 desc = living ? "wounded" : "damaged";
2427 #endif
2428
2429         }
2430
2431         else if (perc >= 10)
2432         {
2433 #ifdef JP
2434                 desc = living ? "½Å½ý" : "Âç¥À¥á¡¼¥¸";
2435 #else
2436                 desc = living ? "badly wounded" : "badly damaged";
2437 #endif
2438
2439         }
2440
2441         else 
2442         {
2443 #ifdef JP
2444                 desc = living ? "Ⱦ»àȾÀ¸" : "Åݤ줫¤±";
2445 #else
2446                 desc = living ? "almost dead" : "almost destroyed";
2447 #endif
2448         }
2449
2450
2451         /* Need attitude information? */
2452         if (!(mode & 0x01))
2453         {
2454                 /* Full information is not needed */
2455                 attitude = "";
2456         }
2457         else if (is_pet(m_ptr))
2458         {
2459 #ifdef JP
2460                 attitude = ", ¥Ú¥Ã¥È";
2461 #else
2462                 attitude = ", pet";
2463 #endif
2464         }
2465         else if (is_friendly(m_ptr))
2466         {
2467 #ifdef JP
2468                 attitude = ", Í§¹¥Åª";
2469 #else
2470                 attitude = ", friendly";
2471 #endif
2472         }
2473         else
2474         {
2475 #ifdef JP
2476                 attitude = "";
2477 #else
2478                 attitude = "";
2479 #endif
2480         }
2481
2482
2483         /* Clone monster? */
2484         if (m_ptr->smart & SM_CLONED)
2485         {
2486                 clone = ", clone";
2487         }
2488         else
2489         {
2490                 clone = "";
2491         }
2492
2493         /* Display monster's level --- idea borrowed from ToME */
2494         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG_KAGE))
2495         {
2496 #ifdef JP
2497                 return format("¥ì¥Ù¥ë%d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2498 #else
2499                 return format("Level %d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2500 #endif
2501         }
2502         else 
2503         {
2504 #ifdef JP
2505                 return format("¥ì¥Ù¥ë???, %s%s%s", desc, attitude, clone);
2506 #else
2507                 return format("Level ???, %s%s%s", desc, attitude, clone);
2508 #endif
2509         }
2510 }
2511
2512
2513
2514 /*
2515  * Angband sorting algorithm -- quick sort in place
2516  *
2517  * Note that the details of the data we are sorting is hidden,
2518  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2519  * function hooks to interact with the data, which is given as
2520  * two pointers, and which may have any user-defined form.
2521  */
2522 void ang_sort_aux(vptr u, vptr v, int p, int q)
2523 {
2524         int z, a, b;
2525
2526         /* Done sort */
2527         if (p >= q) return;
2528
2529         /* Pivot */
2530         z = p;
2531
2532         /* Begin */
2533         a = p;
2534         b = q;
2535
2536         /* Partition */
2537         while (TRUE)
2538         {
2539                 /* Slide i2 */
2540                 while (!(*ang_sort_comp)(u, v, b, z)) b--;
2541
2542                 /* Slide i1 */
2543                 while (!(*ang_sort_comp)(u, v, z, a)) a++;
2544
2545                 /* Done partition */
2546                 if (a >= b) break;
2547
2548                 /* Swap */
2549                 (*ang_sort_swap)(u, v, a, b);
2550
2551                 /* Advance */
2552                 a++, b--;
2553         }
2554
2555         /* Recurse left side */
2556         ang_sort_aux(u, v, p, b);
2557
2558         /* Recurse right side */
2559         ang_sort_aux(u, v, b+1, q);
2560 }
2561
2562
2563 /*
2564  * Angband sorting algorithm -- quick sort in place
2565  *
2566  * Note that the details of the data we are sorting is hidden,
2567  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2568  * function hooks to interact with the data, which is given as
2569  * two pointers, and which may have any user-defined form.
2570  */
2571 void ang_sort(vptr u, vptr v, int n)
2572 {
2573         /* Sort the array */
2574         ang_sort_aux(u, v, 0, n-1);
2575 }
2576
2577
2578
2579 /*** Targeting Code ***/
2580
2581
2582 /*
2583  * Determine is a monster makes a reasonable target
2584  *
2585  * The concept of "targeting" was stolen from "Morgul" (?)
2586  *
2587  * The player can target any location, or any "target-able" monster.
2588  *
2589  * Currently, a monster is "target_able" if it is visible, and if
2590  * the player can hit it with a projection, and the player is not
2591  * hallucinating.  This allows use of "use closest target" macros.
2592  *
2593  * Future versions may restrict the ability to target "trappers"
2594  * and "mimics", but the semantics is a little bit weird.
2595  */
2596 bool target_able(int m_idx)
2597 {
2598         monster_type *m_ptr = &m_list[m_idx];
2599
2600         /* Monster must be alive */
2601         if (!m_ptr->r_idx) return (FALSE);
2602
2603         /* Hack -- no targeting hallucinations */
2604         if (p_ptr->image) return (FALSE);
2605
2606         /* Monster must be visible */
2607         if (!m_ptr->ml) return (FALSE);
2608
2609         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
2610
2611         /* Monster must be projectable */
2612         if (!projectable(py, px, m_ptr->fy, m_ptr->fx)) return (FALSE);
2613
2614         /* XXX XXX XXX Hack -- Never target trappers */
2615         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
2616
2617         /* Assume okay */
2618         return (TRUE);
2619 }
2620
2621
2622
2623
2624 /*
2625  * Update (if necessary) and verify (if possible) the target.
2626  *
2627  * We return TRUE if the target is "okay" and FALSE otherwise.
2628  */
2629 bool target_okay(void)
2630 {
2631         /* Accept stationary targets */
2632         if (target_who < 0) return (TRUE);
2633
2634         /* Check moving targets */
2635         if (target_who > 0)
2636         {
2637                 /* Accept reasonable targets */
2638                 if (target_able(target_who))
2639                 {
2640                         monster_type *m_ptr = &m_list[target_who];
2641
2642                         /* Acquire monster location */
2643                         target_row = m_ptr->fy;
2644                         target_col = m_ptr->fx;
2645
2646                         /* Good target */
2647                         return (TRUE);
2648                 }
2649         }
2650
2651         /* Assume no target */
2652         return (FALSE);
2653 }
2654
2655
2656
2657 /*
2658  * Sorting hook -- comp function -- by "distance to player"
2659  *
2660  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2661  * and sort the arrays by double-distance to the player.
2662  */
2663 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
2664 {
2665         byte *x = (byte*)(u);
2666         byte *y = (byte*)(v);
2667
2668         int da, db, kx, ky;
2669
2670         /* Absolute distance components */
2671         kx = x[a]; kx -= px; kx = ABS(kx);
2672         ky = y[a]; ky -= py; ky = ABS(ky);
2673
2674         /* Approximate Double Distance to the first point */
2675         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2676
2677         /* Absolute distance components */
2678         kx = x[b]; kx -= px; kx = ABS(kx);
2679         ky = y[b]; ky -= py; ky = ABS(ky);
2680
2681         /* Approximate Double Distance to the first point */
2682         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2683
2684         /* Compare the distances */
2685         return (da <= db);
2686 }
2687
2688
2689 /*
2690  * Sorting hook -- swap function -- by "distance to player"
2691  *
2692  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2693  * and sort the arrays by distance to the player.
2694  */
2695 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
2696 {
2697         byte *x = (byte*)(u);
2698         byte *y = (byte*)(v);
2699
2700         byte temp;
2701
2702         /* Swap "x" */
2703         temp = x[a];
2704         x[a] = x[b];
2705         x[b] = temp;
2706
2707         /* Swap "y" */
2708         temp = y[a];
2709         y[a] = y[b];
2710         y[b] = temp;
2711 }
2712
2713
2714
2715 /*
2716  * Hack -- help "select" a location (see below)
2717  */
2718 static s16b target_pick(int y1, int x1, int dy, int dx)
2719 {
2720         int i, v;
2721
2722         int x2, y2, x3, y3, x4, y4;
2723
2724         int b_i = -1, b_v = 9999;
2725
2726
2727         /* Scan the locations */
2728         for (i = 0; i < temp_n; i++)
2729         {
2730                 /* Point 2 */
2731                 x2 = temp_x[i];
2732                 y2 = temp_y[i];
2733
2734                 /* Directed distance */
2735                 x3 = (x2 - x1);
2736                 y3 = (y2 - y1);
2737
2738                 /* Verify quadrant */
2739                 if (dx && (x3 * dx <= 0)) continue;
2740                 if (dy && (y3 * dy <= 0)) continue;
2741
2742                 /* Absolute distance */
2743                 x4 = ABS(x3);
2744                 y4 = ABS(y3);
2745
2746                 /* Verify quadrant */
2747                 if (dy && !dx && (x4 > y4)) continue;
2748                 if (dx && !dy && (y4 > x4)) continue;
2749
2750                 /* Approximate Double Distance */
2751                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
2752
2753                 /* XXX XXX XXX Penalize location */
2754
2755                 /* Track best */
2756                 if ((b_i >= 0) && (v >= b_v)) continue;
2757
2758                 /* Track best */
2759                 b_i = i; b_v = v;
2760         }
2761
2762         /* Result */
2763         return (b_i);
2764 }
2765
2766
2767 /*
2768  * Hack -- determine if a given location is "interesting"
2769  */
2770 static bool target_set_accept(int y, int x)
2771 {
2772         cave_type *c_ptr;
2773
2774         s16b this_o_idx, next_o_idx = 0;
2775
2776         /* Bounds */
2777         if (!(in_bounds(y, x))) return (FALSE);
2778
2779         /* Player grid is always interesting */
2780         if ((y == py) && (x == px)) return (TRUE);
2781
2782
2783         /* Handle hallucination */
2784         if (p_ptr->image) return (FALSE);
2785
2786
2787         /* Examine the grid */
2788         c_ptr = &cave[y][x];
2789
2790         /* Visible monsters */
2791         if (c_ptr->m_idx)
2792         {
2793                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2794
2795                 /* Visible monsters */
2796                 if (m_ptr->ml) return (TRUE);
2797         }
2798
2799         /* Scan all objects in the grid */
2800         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2801         {
2802                 object_type *o_ptr;
2803
2804                 /* Acquire object */
2805                 o_ptr = &o_list[this_o_idx];
2806
2807                 /* Acquire next object */
2808                 next_o_idx = o_ptr->next_o_idx;
2809
2810                 /* Memorized object */
2811                 if (o_ptr->marked) return (TRUE);
2812         }
2813
2814         /* Interesting memorized features */
2815         if (c_ptr->info & (CAVE_MARK))
2816         {
2817                 byte feat;
2818
2819                 /* Feature code (applying "mimic" field) */
2820                 feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
2821
2822                 /* Notice glyphs */
2823                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
2824
2825                 /* Notice the Pattern */
2826                 if ((feat <= FEAT_PATTERN_XTRA2) &&
2827                     (feat >= FEAT_PATTERN_START))
2828                         return (TRUE);
2829
2830                 /* Notice doors */
2831                 if (feat == FEAT_OPEN) return (TRUE);
2832                 if (feat == FEAT_BROKEN) return (TRUE);
2833
2834                 /* Notice stairs */
2835                 if (feat == FEAT_LESS) return (TRUE);
2836                 if (feat == FEAT_MORE) return (TRUE);
2837                 if (feat == FEAT_LESS_LESS) return (TRUE);
2838                 if (feat == FEAT_MORE_MORE) return (TRUE);
2839
2840                 /* Notice shops */
2841                 if ((feat >= FEAT_SHOP_HEAD) &&
2842                     (feat <= FEAT_SHOP_TAIL)) return (TRUE);
2843
2844                 if (feat == FEAT_MUSEUM) return (TRUE);
2845
2846                 /* Notice buildings -KMW- */
2847                 if ((feat >= FEAT_BLDG_HEAD) &&
2848                     (feat <= FEAT_BLDG_TAIL)) return (TRUE);
2849
2850                 /* Notice traps */
2851                 if (is_trap(feat)) return (TRUE);
2852
2853                 /* Notice doors */
2854                 if ((feat >= FEAT_DOOR_HEAD) &&
2855                     (feat <= FEAT_DOOR_TAIL)) return (TRUE);
2856
2857 #if 0
2858                 /* Notice rubble */
2859                 /* I think FEAT_RUBBLEs should not be "interesting" */
2860                 if (feat == FEAT_RUBBLE) return (TRUE);
2861
2862                 /* Notice veins with treasure */
2863                 /* Now veins with treasure are too many */
2864                 if (feat == FEAT_MAGMA_K) return (TRUE);
2865                 if (feat == FEAT_QUARTZ_K) return (TRUE);
2866 #endif
2867
2868                 /* Notice quest features */
2869                 if (feat == FEAT_QUEST_ENTER) return (TRUE);
2870                 if (feat == FEAT_QUEST_EXIT) return (TRUE);
2871                 if (feat == FEAT_QUEST_DOWN) return (TRUE);
2872                 if (feat == FEAT_QUEST_UP) return (TRUE);
2873                 if (feat == FEAT_TOWN) return (TRUE);
2874                 if (feat == FEAT_ENTRANCE) return (TRUE);
2875         }
2876
2877         /* Nope */
2878         return (FALSE);
2879 }
2880
2881
2882 /*
2883  * Prepare the "temp" array for "target_set"
2884  *
2885  * Return the number of target_able monsters in the set.
2886  */
2887 static void target_set_prepare(int mode)
2888 {
2889         int y, x;
2890
2891         /* Reset "temp" array */
2892         temp_n = 0;
2893
2894         /* Scan the current panel */
2895         for (y = panel_row_min; y <= panel_row_max; y++)
2896         {
2897                 for (x = panel_col_min; x <= panel_col_max; x++)
2898                 {
2899                         cave_type *c_ptr;
2900
2901                         /* Require line of sight, unless "look" is "expanded" */
2902                         if (!expand_look && !player_has_los_bold(y, x)) continue;
2903
2904                         /* Require "interesting" contents */
2905                         if (!target_set_accept(y, x)) continue;
2906
2907                         c_ptr = &cave[y][x];
2908
2909                         /* Require target_able monsters for "TARGET_KILL" */
2910                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
2911
2912                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
2913
2914                         /* Save the location */
2915                         temp_x[temp_n] = x;
2916                         temp_y[temp_n] = y;
2917                         temp_n++;
2918                 }
2919         }
2920
2921         /* Set the sort hooks */
2922         ang_sort_comp = ang_sort_comp_distance;
2923         ang_sort_swap = ang_sort_swap_distance;
2924
2925         /* Sort the positions */
2926         ang_sort(temp_x, temp_y, temp_n);
2927
2928         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
2929         {
2930                 byte tmp;
2931
2932                 tmp = temp_y[0];
2933                 temp_y[0] = temp_y[1];
2934                 temp_y[1] = tmp;
2935                 tmp = temp_x[0];
2936                 temp_x[0] = temp_x[1];
2937                 temp_x[1] = tmp;
2938         }
2939 }
2940
2941
2942 /*
2943  * Evaluate number of kill needed to gain level
2944  */
2945 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
2946 {
2947 #define M_INT_GREATER(h1,l1,h2,l2)  ( (h1>h2)||( (h1==h2)&&(l1>=l2)))
2948 #define M_INT_SUB(h1,l1, h2,l2) {h1-=h2;if(l1<l2){l1+=0x10000;h1--;}l1-=l2;}
2949 #define M_INT_ADD(h1,l1, h2,l2) {h1+=h2;l1+=l2;if(l1>=0x10000L){l1&=0xFFFF;h1++;}}
2950 #define M_INT_LSHIFT(h1,l1) {h1=(h1<<1)|(l1>>15);l1=(l1<<1)&0xffff;}
2951 #define M_INT_RSHIFT(h1,l1) {l1=(l1>>1)|((h1&1)<<15);h1>>=1;}
2952 #define M_INT_MULT(h1,l1,mul,h2,l2) {l2=(l1*mul)&0xffff;h2=((l1*mul)>>16)+h1*mul;}
2953
2954         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2955
2956         u32b tmp_h,tmp_l;
2957         int bit,result;
2958         u32b exp_mon= (ap_r_ptr->mexp)*(ap_r_ptr->level);
2959         u32b exp_mon_h= exp_mon / (p_ptr->max_plv+2);
2960         u32b exp_mon_l= ((exp_mon % (p_ptr->max_plv+2))*0x10000/(p_ptr->max_plv+2))&0xFFFF;
2961         
2962         u32b exp_adv_h = player_exp[p_ptr->lev -1] * p_ptr->expfact /100;
2963         u32b exp_adv_l = ((player_exp[p_ptr->lev -1]%100) * p_ptr->expfact *0x10000/100)&0xFFFF;
2964         
2965         M_INT_SUB(exp_adv_h, exp_adv_l, p_ptr->exp, p_ptr->exp_frac);
2966         if ((p_ptr->lev>=PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
2967                 sprintf(buf,"**");
2968         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG_KAGE))
2969                 sprintf(buf,"??");
2970         else if (M_INT_GREATER(exp_mon_h, exp_mon_l, exp_adv_h, exp_adv_l))
2971                 sprintf(buf,"001");
2972         else 
2973         {
2974                 M_INT_MULT(exp_mon_h, exp_mon_l, 1000,tmp_h, tmp_l);
2975                 if( M_INT_GREATER(exp_adv_h, exp_adv_l, tmp_h, tmp_l) )
2976                         sprintf(buf,"999");
2977                 else
2978                 {
2979                         bit=1; result=0;
2980                         M_INT_ADD(exp_adv_h, exp_adv_l, exp_mon_h, exp_mon_l);
2981                         M_INT_SUB(exp_adv_h, exp_adv_l, 0, 1);
2982                         while(M_INT_GREATER(exp_adv_h, exp_adv_l, exp_mon_h,exp_mon_l))
2983                         {
2984                                 M_INT_LSHIFT(exp_mon_h,exp_mon_l);
2985                                 bit <<= 1;
2986                         }
2987                         M_INT_RSHIFT(exp_mon_h,exp_mon_l);bit>>=1;
2988                         for(;bit>=1;bit>>=1)
2989                         {
2990                                 if(M_INT_GREATER(exp_adv_h,exp_adv_l,exp_mon_h,exp_mon_l))
2991                                 {
2992                                         result |= bit;
2993                                         M_INT_SUB(exp_adv_h,exp_adv_l,exp_mon_h,exp_mon_l);
2994                                 }
2995                                 M_INT_RSHIFT(exp_mon_h,exp_mon_l); 
2996                         }
2997                         sprintf(buf,"%03d",result);
2998                 }
2999         }
3000 }
3001
3002
3003 /*
3004  * Examine a grid, return a keypress.
3005  *
3006  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
3007  * indicates that the "space" key should scan through the contents
3008  * of the grid, instead of simply returning immediately.  This lets
3009  * the "look" command get complete information, without making the
3010  * "target" command annoying.
3011  *
3012  * The "info" argument contains the "commands" which should be shown
3013  * inside the "[xxx]" text.  This string must never be empty, or grids
3014  * containing monsters will be displayed with an extra comma.
3015  *
3016  * Note that if a monster is in the grid, we update both the monster
3017  * recall info and the health bar info to track that monster.
3018  *
3019  * Eventually, we may allow multiple objects per grid, or objects
3020  * and terrain features in the same grid. XXX XXX XXX
3021  *
3022  * This function must handle blindness/hallucination.
3023  */
3024 static int target_set_aux(int y, int x, int mode, cptr info)
3025 {
3026         cave_type *c_ptr = &cave[y][x];
3027         s16b this_o_idx, next_o_idx = 0;
3028         cptr s1 = "", s2 = "", s3 = "", x_info = "";
3029         bool boring = TRUE;
3030         byte feat;
3031         int query = '\001';
3032         char out_val[MAX_NLEN+80];
3033
3034 #ifdef ALLOW_EASY_FLOOR
3035         int floor_list[23], floor_num = 0;
3036
3037         /* Scan all objects in the grid */
3038         if (easy_floor)
3039         {
3040                 floor_num = scan_floor(floor_list, y, x, 0x02);
3041
3042                 if (floor_num)
3043                 {
3044 #ifdef JP
3045                         x_info = "xʪ ";
3046 #else
3047                         x_info = "x,";
3048 #endif
3049                 }
3050         }
3051
3052 #endif /* ALLOW_EASY_FLOOR */
3053
3054         /* Hack -- under the player */
3055         if ((y == py) && (x == px))
3056         {
3057                 /* Description */
3058 #ifdef JP
3059                 s1 = "¤¢¤Ê¤¿¤Ï";
3060                 s2 = "¤Î¾å";
3061                 s3 = "¤Ë¤¤¤ë";
3062 #else
3063                 s1 = "You are ";
3064
3065                 /* Preposition */
3066                 s2 = "on ";
3067 #endif
3068         }
3069         else
3070         {
3071 #ifdef JP
3072                 s1 = "¥¿¡¼¥²¥Ã¥È:";
3073 #else
3074                 s1 = "Target:";
3075 #endif
3076         }
3077
3078         /* Hack -- hallucination */
3079         if (p_ptr->image)
3080         {
3081 #ifdef JP
3082                 cptr name = "²¿¤«´ñ̯¤Êʪ";
3083 #else
3084                 cptr name = "something strange";
3085 #endif
3086
3087
3088                 /* Display a message */
3089 #ifdef JP
3090                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
3091 #else
3092                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3093 #endif
3094
3095                 prt(out_val, 0, 0);
3096                 move_cursor_relative(y, x);
3097                 query = inkey();
3098
3099                 /* Stop on everything but "return" */
3100                 if ((query != '\r') && (query != '\n')) return query;
3101
3102                 /* Repeat forever */
3103                 return 0;
3104         }
3105
3106
3107         /* Actual monsters */
3108         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
3109         {
3110                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
3111                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3112                 char m_name[80];
3113                 bool recall = FALSE;
3114
3115                 /* Not boring */
3116                 boring = FALSE;
3117
3118                 /* Get the monster name ("a kobold") */
3119                 monster_desc(m_name, m_ptr, 0x08);
3120
3121                 /* Hack -- track this monster race */
3122                 monster_race_track(m_ptr->ap_r_idx);
3123
3124                 /* Hack -- health bar for this monster */
3125                 health_track(c_ptr->m_idx);
3126
3127                 /* Hack -- handle stuff */
3128                 handle_stuff();
3129
3130                 /* Interact */
3131                 while (1)
3132                 {
3133                         char acount[10];
3134
3135                         /* Recall */
3136                         if (recall)
3137                         {
3138                                 /* Save */
3139                                 screen_save();
3140
3141                                 /* Recall on screen */
3142                                 screen_roff(m_ptr->ap_r_idx, 0);
3143
3144                                 /* Hack -- Complete the prompt (again) */
3145 #ifdef JP
3146                                 Term_addstr(-1, TERM_WHITE, format("  [r»× %s%s]", x_info, info));
3147 #else
3148                                 Term_addstr(-1, TERM_WHITE, format("  [r,%s%s]", x_info, info));
3149 #endif
3150
3151                                 /* Command */
3152                                 query = inkey();
3153
3154                                 /* Restore */
3155                                 screen_load();
3156
3157                                 /* Normal commands */
3158                                 if (query != 'r') break;
3159
3160                                 /* Toggle recall */
3161                                 recall = FALSE;
3162
3163                                 /* Cleare recall text and repeat */
3164                                 continue;
3165                         }
3166
3167                         /*** Normal ***/
3168
3169                         /* Describe, and prompt for recall */
3170                         evaluate_monster_exp(acount, m_ptr);
3171
3172 #ifdef JP
3173                         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);
3174 #else
3175                         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);
3176 #endif
3177
3178                         prt(out_val, 0, 0);
3179
3180                         /* Place cursor */
3181                         move_cursor_relative(y, x);
3182
3183                         /* Command */
3184                         query = inkey();
3185
3186                         /* Normal commands */
3187                         if (query != 'r') break;
3188
3189                         /* Toggle recall */
3190                         recall = TRUE;
3191                 }
3192
3193                 /* Always stop at "normal" keys */
3194                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3195
3196                 /* Sometimes stop at "space" key */
3197                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3198
3199                 /* Change the intro */
3200 #ifdef JP
3201                 s1 = "¤½¤ì¤Ï";
3202 #else
3203                 s1 = "It is ";
3204 #endif
3205
3206
3207                 /* Hack -- take account of gender */
3208 #ifdef JP
3209                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = "Èà½÷¤Ï";
3210 #else
3211                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = "She is ";
3212 #endif
3213
3214 #ifdef JP
3215                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = "Èà¤Ï";
3216 #else
3217                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = "He is ";
3218 #endif
3219
3220
3221                 /* Use a preposition */
3222 #ifdef JP
3223                 s2 = "¤ò";
3224                 s3 = "»ý¤Ã¤Æ¤¤¤ë";
3225 #else
3226                 s2 = "carrying ";
3227 #endif
3228
3229
3230                 /* Scan all objects being carried */
3231                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3232                 {
3233                         char o_name[MAX_NLEN];
3234
3235                         object_type *o_ptr;
3236
3237                         /* Acquire object */
3238                         o_ptr = &o_list[this_o_idx];
3239
3240                         /* Acquire next object */
3241                         next_o_idx = o_ptr->next_o_idx;
3242
3243                         /* Obtain an object description */
3244                         object_desc(o_name, o_ptr, TRUE, 3);
3245
3246                         /* Describe the object */
3247 #ifdef JP
3248                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3249 #else
3250                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3251 #endif
3252
3253                         prt(out_val, 0, 0);
3254                         move_cursor_relative(y, x);
3255                         query = inkey();
3256
3257                         /* Always stop at "normal" keys */
3258                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3259
3260                         /* Sometimes stop at "space" key */
3261                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3262
3263                         /* Change the intro */
3264 #ifdef JP
3265                         s2 = "¤ò¤Þ¤¿";
3266 #else
3267                         s2 = "also carrying ";
3268 #endif
3269                 }
3270
3271                 /* Use a preposition */
3272 #ifdef JP
3273                 s2 = "¤Î¾å";
3274                 s3 = "¤Ë¤¤¤ë";
3275 #else
3276                 s2 = "on ";
3277 #endif
3278         }
3279
3280
3281 #ifdef ALLOW_EASY_FLOOR
3282         if (floor_num)
3283         {
3284                 int min_width = 0;
3285
3286                 while (1)
3287                 {
3288                         if (floor_num == 1)
3289                         {
3290                                 char o_name[MAX_NLEN];
3291
3292                                 object_type *o_ptr;
3293
3294                                 /* Acquire object */
3295                                 o_ptr = &o_list[floor_list[0]];
3296
3297                                 /* Describe the object */
3298                                 object_desc(o_name, o_ptr, TRUE, 3);
3299
3300                                 /* Message */
3301 #ifdef JP
3302                                 sprintf(out_val, "%s%s%s%s[%s]",
3303                                         s1, o_name, s2, s3, info);
3304 #else
3305                                 sprintf(out_val, "%s%s%s%s [%s]",
3306                                         s1, s2, s3, o_name, info);
3307 #endif
3308
3309                                 prt(out_val, 0, 0);
3310                                 move_cursor_relative(y, x);
3311
3312                                 /* Command */
3313                                 query = inkey();
3314
3315                                 /* End this grid */
3316                                 return query;
3317                         }
3318
3319                         /* Provide one cushion before item listing  */
3320                         if (boring)
3321                         {
3322                                 /* Display rough information about items */
3323 #ifdef JP
3324                                 sprintf(out_val, "%s %d¸Ä¤Î¥¢¥¤¥Æ¥à%s%s ['x'¤Ç°ìÍ÷, %s]",
3325                                         s1, floor_num, s2, s3, info);
3326 #else
3327                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]",
3328                                         s1, s2, s3, floor_num, info);
3329 #endif
3330
3331                                 prt(out_val, 0, 0);
3332                                 move_cursor_relative(y, x);
3333
3334                                 /* Command */
3335                                 query = inkey();
3336
3337                                 /* No request for listing */
3338                                 if (query != 'x' && query != ' ') return query;
3339                         }
3340
3341
3342                         /** Display list of items **/
3343
3344                         /* Continue scrolling list if requested */
3345                         while (1)
3346                         {
3347                                 int i, o_idx;
3348                                 cave_type *c_ptr;
3349
3350                                 /* Save screen */
3351                                 screen_save();
3352
3353                                 /* Display */
3354                                 (void)show_floor(0, y, x, &min_width);
3355
3356                                 /* Prompt */
3357 #ifdef JP
3358                                 sprintf(out_val, "%s %d¸Ä¤Î¥¢¥¤¥Æ¥à%s%s [Enter¤Ç¼¡¤Ø, %s]",
3359                                         s1, floor_num, s2, s3, info);
3360 #else
3361                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]",
3362                                         s1, s2, s3, floor_num, info);
3363 #endif
3364                                 prt(out_val, 0, 0);
3365
3366
3367                                 /* Wait */
3368                                 query = inkey();
3369
3370                                 /* Load screen */
3371                                 screen_load();
3372
3373                                 /* Exit unless 'Enter' */
3374                                 if (query != '\n' && query != '\r')
3375                                 {
3376                                         return query;
3377                                 }
3378
3379                                 /* Get the object being moved. */
3380                                 c_ptr = &cave[y][x];
3381                                 o_idx = c_ptr->o_idx;
3382  
3383                                 /* Only rotate a pile of two or more objects. */
3384                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
3385
3386                                 /* Remove the first object from the list. */
3387                                 excise_object_idx(o_idx);
3388
3389                                 /* Find end of the list. */
3390                                 i = c_ptr->o_idx;
3391                                 while (o_list[i].next_o_idx)
3392                                         i = o_list[i].next_o_idx;
3393
3394                                 /* Add after the last object. */
3395                                 o_list[i].next_o_idx = o_idx;
3396
3397                                 /* Loop and re-display the list */
3398                         }
3399                 }
3400
3401                 /* NOTREACHED */
3402         }
3403 #endif /* ALLOW_EASY_FLOOR */
3404
3405
3406         /* Scan all objects in the grid */
3407         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3408         {
3409                 object_type *o_ptr;
3410
3411                 /* Acquire object */
3412                 o_ptr = &o_list[this_o_idx];
3413
3414                 /* Acquire next object */
3415                 next_o_idx = o_ptr->next_o_idx;
3416
3417                 /* Describe it */
3418                 if (o_ptr->marked)
3419                 {
3420                         char o_name[MAX_NLEN];
3421
3422                         /* Not boring */
3423                         boring = FALSE;
3424
3425                         /* Obtain an object description */
3426                         object_desc(o_name, o_ptr, TRUE, 3);
3427
3428                         /* Describe the object */
3429 #ifdef JP
3430                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3431 #else
3432                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3433 #endif
3434
3435                         prt(out_val, 0, 0);
3436                         move_cursor_relative(y, x);
3437                         query = inkey();
3438
3439                         /* Always stop at "normal" keys */
3440                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3441
3442                         /* Sometimes stop at "space" key */
3443                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
3444
3445                         /* Change the intro */
3446 #ifdef JP
3447                         s1 = "¤½¤ì¤Ï";
3448 #else
3449                         s1 = "It is ";
3450 #endif
3451
3452
3453                         /* Plurals */
3454 #ifdef JP
3455                         if (o_ptr->number != 1) s1 = "¤½¤ì¤é¤Ï";
3456 #else
3457                         if (o_ptr->number != 1) s1 = "They are ";
3458 #endif
3459
3460
3461                         /* Preposition */
3462 #ifdef JP
3463                         s2 = "¤Î¾å";
3464                         s3 = "¤Ë¸«¤¨¤ë";
3465 #else
3466                         s2 = "on ";
3467 #endif
3468
3469                 }
3470         }
3471
3472
3473         /* Feature code (applying "mimic" field) */
3474         feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
3475
3476         /* Require knowledge about grid, or ability to see grid */
3477         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
3478         {
3479                 /* Forget feature */
3480                 feat = FEAT_NONE;
3481         }
3482
3483         /* Terrain feature if needed */
3484         if (boring || (feat > FEAT_INVIS))
3485         {
3486                 cptr name;
3487
3488                 /* Hack -- special handling for building doors */
3489                 if ((feat >= FEAT_BLDG_HEAD) && (feat <= FEAT_BLDG_TAIL))
3490                 {
3491                         name = building[feat - FEAT_BLDG_HEAD].name;
3492                 }
3493                 else if (feat == FEAT_ENTRANCE)
3494                 {
3495 #ifdef JP
3496                         name = format("%s(%d³¬ÁêÅö)", d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3497 #else
3498                         name = format("%s(level %d)", d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3499 #endif
3500                 }
3501                 else if (feat == FEAT_TOWN)
3502                 {
3503                         name = town[c_ptr->special].name;
3504                 }
3505                 else if (p_ptr->wild_mode && (feat == FEAT_FLOOR))
3506                 {
3507 #ifdef JP
3508                         name = "ƻ";
3509 #else
3510                         name = "road";
3511 #endif
3512                 }
3513                 else
3514                 {
3515                         name = f_name + f_info[feat].name;
3516                 }
3517
3518
3519                 /* Pick a prefix */
3520                 if (*s2 && ((feat >= FEAT_MINOR_GLYPH) &&
3521                             (feat <= FEAT_PATTERN_XTRA2)))
3522                 {
3523 #ifdef JP
3524                         s2 = "¤Î¾å";
3525 #else
3526                         s2 = "on ";
3527 #endif
3528
3529                 }
3530                 else if (*s2 && ((feat >= FEAT_DOOR_HEAD) &&
3531                                  (feat <= FEAT_PERM_SOLID)))
3532                 {
3533 #ifdef JP
3534                         s2 = "¤ÎÃæ";
3535 #else
3536                         s2 = "in ";
3537 #endif
3538
3539                 }
3540                 else if (*s2 && (feat == FEAT_TOWN))
3541                 {
3542 #ifdef JP
3543                         s2 = "¤ÎÃæ";
3544 #else
3545                         s2 = "in ";
3546 #endif
3547
3548                 }
3549
3550                 /* Hack -- special introduction for store & building doors -KMW- */
3551                 if (((feat >= FEAT_SHOP_HEAD) && (feat <= FEAT_SHOP_TAIL)) ||
3552                     ((feat >= FEAT_BLDG_HEAD) && (feat <= FEAT_BLDG_TAIL)) ||
3553                     (feat == FEAT_MUSEUM) ||
3554                     (feat == FEAT_ENTRANCE))
3555                 {
3556 #ifdef JP
3557                         s2 = "¤ÎÆþ¸ý";
3558 #else
3559                         s3 = "";
3560 #endif
3561
3562                 }
3563                 else if ((feat == FEAT_TOWN) || (feat == FEAT_FLOOR) || (feat == FEAT_DIRT) || (feat == FEAT_FLOWER))
3564                 {
3565 #ifndef JP
3566                         s3 ="";
3567 #endif
3568                 }
3569                 else
3570                 {
3571                         /* Pick proper indefinite article */
3572 #ifndef JP
3573                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
3574 #endif
3575                 }
3576
3577                 /* Display a message */
3578                 if (p_ptr->wizard)
3579 #ifdef JP
3580                         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);
3581 #else
3582                 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);
3583 #endif
3584                 else
3585 #ifdef JP
3586                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
3587 #else
3588                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3589 #endif
3590
3591                 prt(out_val, 0, 0);
3592                 move_cursor_relative(y, x);
3593                 query = inkey();
3594
3595                 /* Always stop at "normal" keys */
3596                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
3597         }
3598
3599         /* Stop on everything but "return" */
3600         if ((query != '\r') && (query != '\n')) return query;
3601
3602         /* Repeat forever */
3603         return 0;
3604 }
3605
3606
3607 /*
3608  * Handle "target" and "look".
3609  *
3610  * Note that this code can be called from "get_aim_dir()".
3611  *
3612  * All locations must be on the current panel.  Consider the use of
3613  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
3614  * some form of "scrolling" the map around the cursor.  XXX XXX XXX
3615  * That is, consider the possibility of "auto-scrolling" the screen
3616  * while the cursor moves around.  This may require changes in the
3617  * "update_mon()" code to allow "visibility" even if off panel, and
3618  * may require dynamic recalculation of the "temp" grid set.
3619  *
3620  * Hack -- targeting/observing an "outer border grid" may induce
3621  * problems, so this is not currently allowed.
3622  *
3623  * The player can use the direction keys to move among "interesting"
3624  * grids in a heuristic manner, or the "space", "+", and "-" keys to
3625  * move through the "interesting" grids in a sequential manner, or
3626  * can enter "location" mode, and use the direction keys to move one
3627  * grid at a time in any direction.  The "t" (set target) command will
3628  * only target a monster (as opposed to a location) if the monster is
3629  * target_able and the "interesting" mode is being used.
3630  *
3631  * The current grid is described using the "look" method above, and
3632  * a new command may be entered at any time, but note that if the
3633  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
3634  * where "space" has no obvious meaning) then "space" will scan
3635  * through the description of the current grid until done, instead
3636  * of immediately jumping to the next "interesting" grid.  This
3637  * allows the "target" command to retain its old semantics.
3638  *
3639  * The "*", "+", and "-" keys may always be used to jump immediately
3640  * to the next (or previous) interesting grid, in the proper mode.
3641  *
3642  * The "return" key may always be used to scan through a complete
3643  * grid description (forever).
3644  *
3645  * This command will cancel any old target, even if used from
3646  * inside the "look" command.
3647  */
3648 bool target_set(int mode)
3649 {
3650         int             i, d, m, t, bd;
3651         int             y = py;
3652         int             x = px;
3653
3654         bool    done = FALSE;
3655
3656         bool    flag = TRUE;
3657
3658         char    query;
3659
3660         char    info[80];
3661
3662         cave_type               *c_ptr;
3663
3664         int wid, hgt;
3665
3666
3667         /* Get size */
3668         get_screen_size(&wid, &hgt);
3669
3670         /* Cancel target */
3671         target_who = 0;
3672
3673
3674         /* Cancel tracking */
3675         /* health_track(0); */
3676
3677
3678         /* Prepare the "temp" array */
3679         target_set_prepare(mode);
3680
3681         /* Start near the player */
3682         m = 0;
3683
3684         /* Interact */
3685         while (!done)
3686         {
3687                 /* Interesting grids */
3688                 if (flag && temp_n)
3689                 {
3690                         y = temp_y[m];
3691                         x = temp_x[m];
3692
3693                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3694
3695                         /* Access */
3696                         c_ptr = &cave[y][x];
3697
3698                         /* Allow target */
3699                         if (target_able(c_ptr->m_idx))
3700                         {
3701 #ifdef JP
3702 strcpy(info, "q»ß t·è p¼« o¸½ +¼¡ -Á°");
3703 #else
3704                                 strcpy(info, "q,t,p,o,+,-,<dir>");
3705 #endif
3706
3707                         }
3708
3709                         /* Dis-allow target */
3710                         else
3711                         {
3712 #ifdef JP
3713 strcpy(info, "q»ß p¼« o¸½ +¼¡ -Á°");
3714 #else
3715                                 strcpy(info, "q,p,o,+,-,<dir>");
3716 #endif
3717
3718                         }
3719
3720                         /* Describe and Prompt */
3721                         while (!(query = target_set_aux(y, x, mode, info)));
3722
3723                         /* Cancel tracking */
3724                         /* health_track(0); */
3725
3726                         /* Assume no "direction" */
3727                         d = 0;
3728
3729                         if (use_menu)
3730                         {
3731                                 if (query == '\r') query = 't';
3732                         }  
3733
3734                         /* Analyze */
3735                         switch (query)
3736                         {
3737                                 case ESCAPE:
3738                                 case 'q':
3739                                 {
3740                                         done = TRUE;
3741                                         break;
3742                                 }
3743
3744                                 case 't':
3745                                 case '.':
3746                                 case '5':
3747                                 case '0':
3748                                 {
3749                                         if (target_able(c_ptr->m_idx))
3750                                         {
3751                                                 health_track(c_ptr->m_idx);
3752                                                 target_who = c_ptr->m_idx;
3753                                                 target_row = y;
3754                                                 target_col = x;
3755                                                 done = TRUE;
3756                                         }
3757                                         else
3758                                         {
3759                                                 bell();
3760                                         }
3761                                         break;
3762                                 }
3763
3764                                 case ' ':
3765                                 case '*':
3766                                 case '+':
3767                                 {
3768                                         if (++m == temp_n)
3769                                         {
3770                                                 m = 0;
3771                                                 if (!expand_list) done = TRUE;
3772                                         }
3773                                         break;
3774                                 }
3775
3776                                 case '-':
3777                                 {
3778                                         if (m-- == 0)
3779                                         {
3780                                                 m = temp_n - 1;
3781                                                 if (!expand_list) done = TRUE;
3782                                         }
3783                                         break;
3784                                 }
3785
3786                                 case 'p':
3787                                 {
3788                                         /* Recenter the map around the player */
3789                                         verify_panel();
3790
3791                                         /* Update stuff */
3792                                         p_ptr->update |= (PU_MONSTERS);
3793
3794                                         /* Redraw map */
3795                                         p_ptr->redraw |= (PR_MAP);
3796
3797                                         /* Window stuff */
3798                                         p_ptr->window |= (PW_OVERHEAD);
3799
3800                                         /* Handle stuff */
3801                                         handle_stuff();
3802
3803                                         /* Recalculate interesting grids */
3804                                         target_set_prepare(mode);
3805
3806                                         y = py;
3807                                         x = px;
3808                                 }
3809
3810                                 case 'o':
3811                                 {
3812                                         flag = FALSE;
3813                                         break;
3814                                 }
3815
3816                                 case 'm':
3817                                 {
3818                                         break;
3819                                 }
3820
3821                                 default:
3822                                 {
3823                                         /* Extract the action (if any) */
3824                                         d = get_keymap_dir(query);
3825
3826                                         if (!d) bell();
3827                                         break;
3828                                 }
3829                         }
3830
3831                         /* Hack -- move around */
3832                         if (d)
3833                         {
3834                                 /* Modified to scroll to monster */
3835                                 int y2 = panel_row_min;
3836                                 int x2 = panel_col_min;
3837
3838                                 /* Find a new monster */
3839                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
3840
3841                                 /* Request to target past last interesting grid */
3842                                 while (flag && (i < 0))
3843                                 {
3844                                         /* Note the change */
3845                                         if (change_panel(ddy[d], ddx[d]))
3846                                         {
3847                                                 int v = temp_y[m];
3848                                                 int u = temp_x[m];
3849
3850                                                 /* Recalculate interesting grids */
3851                                                 target_set_prepare(mode);
3852
3853                                                 /* Look at interesting grids */
3854                                                 flag = TRUE;
3855
3856                                                 /* Find a new monster */
3857                                                 i = target_pick(v, u, ddy[d], ddx[d]);
3858
3859                                                 /* Use that grid */
3860                                                 if (i >= 0) m = i;
3861                                         }
3862
3863                                         /* Nothing interesting */
3864                                         else
3865                                         {
3866                                                 int dx = ddx[d];
3867                                                 int dy = ddy[d];
3868
3869                                                 /* Restore previous position */
3870                                                 panel_row_min = y2;
3871                                                 panel_col_min = x2;
3872                                                 panel_bounds_center();
3873
3874                                                 /* Update stuff */
3875                                                 p_ptr->update |= (PU_MONSTERS);
3876
3877                                                 /* Redraw map */
3878                                                 p_ptr->redraw |= (PR_MAP);
3879
3880                                                 /* Window stuff */
3881                                                 p_ptr->window |= (PW_OVERHEAD);
3882
3883                                                 /* Handle stuff */
3884                                                 handle_stuff();
3885
3886                                                 /* Recalculate interesting grids */
3887                                                 target_set_prepare(mode);
3888
3889                                                 /* Look at boring grids */
3890                                                 flag = FALSE;
3891
3892                                                 /* Move */
3893                                                 x += dx;
3894                                                 y += dy;
3895
3896                                                 /* Do not move horizontally if unnecessary */
3897                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
3898                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
3899                                                 {
3900                                                         dx = 0;
3901                                                 }
3902
3903                                                 /* Do not move vertically if unnecessary */
3904                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
3905                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
3906                                                 {
3907                                                         dy = 0;
3908                                                 }
3909
3910                                                 /* Apply the motion */
3911                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
3912                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
3913                                                 {
3914                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
3915                                                 }
3916
3917                                                 /* Slide into legality */
3918                                                 if (x >= cur_wid-1) x = cur_wid - 2;
3919                                                 else if (x <= 0) x = 1;
3920
3921                                                 /* Slide into legality */
3922                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
3923                                                 else if (y <= 0) y = 1;
3924                                         }
3925                                 }
3926
3927                                 /* Use that grid */
3928                                 m = i;
3929                         }
3930                 }
3931
3932                 /* Arbitrary grids */
3933                 else
3934                 {
3935                         bool move_fast = FALSE;
3936
3937                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3938
3939                         /* Access */
3940                         c_ptr = &cave[y][x];
3941
3942                         /* Default prompt */
3943 #ifdef JP
3944 strcpy(info, "q»ß t·è p¼« m¶á +¼¡ -Á°");
3945 #else
3946                         strcpy(info, "q,t,p,m,+,-,<dir>");
3947 #endif
3948
3949
3950                         /* Describe and Prompt (enable "TARGET_LOOK") */
3951                         while (!(query = target_set_aux(y, x, mode | TARGET_LOOK, info)));
3952
3953                         /* Cancel tracking */
3954                         /* health_track(0); */
3955
3956                         /* Assume no direction */
3957                         d = 0;
3958
3959                         if (use_menu)
3960                         {
3961                                 if (query == '\r') query = 't';
3962                         }  
3963
3964                         /* Analyze the keypress */
3965                         switch (query)
3966                         {
3967                                 case ESCAPE:
3968                                 case 'q':
3969                                 {
3970                                         done = TRUE;
3971                                         break;
3972                                 }
3973
3974                                 case 't':
3975                                 case '.':
3976                                 case '5':
3977                                 case '0':
3978                                 {
3979                                         target_who = -1;
3980                                         target_row = y;
3981                                         target_col = x;
3982                                         done = TRUE;
3983                                         break;
3984                                 }
3985
3986                                 case 'p':
3987                                 {
3988                                         /* Recenter the map around the player */
3989                                         verify_panel();
3990
3991                                         /* Update stuff */
3992                                         p_ptr->update |= (PU_MONSTERS);
3993
3994                                         /* Redraw map */
3995                                         p_ptr->redraw |= (PR_MAP);
3996
3997                                         /* Window stuff */
3998                                         p_ptr->window |= (PW_OVERHEAD);
3999
4000                                         /* Handle stuff */
4001                                         handle_stuff();
4002
4003                                         /* Recalculate interesting grids */
4004                                         target_set_prepare(mode);
4005
4006                                         y = py;
4007                                         x = px;
4008                                 }
4009
4010                                 case 'o':
4011                                 {
4012                                         break;
4013                                 }
4014
4015                                 case ' ':
4016                                 case '*':
4017                                 case '+':
4018                                 case '-':
4019                                 case 'm':
4020                                 {
4021                                         flag = TRUE;
4022
4023                                         m = 0;
4024                                         bd = 999;
4025
4026                                         /* Pick a nearby monster */
4027                                         for (i = 0; i < temp_n; i++)
4028                                         {
4029                                                 t = distance(y, x, temp_y[i], temp_x[i]);
4030
4031                                                 /* Pick closest */
4032                                                 if (t < bd)
4033                                                 {
4034                                                         m = i;
4035                                                         bd = t;
4036                                                 }
4037                                         }
4038
4039                                         /* Nothing interesting */
4040                                         if (bd == 999) flag = FALSE;
4041
4042                                         break;
4043                                 }
4044
4045                                 default:
4046                                 {
4047                                         /* Extract the action (if any) */
4048                                         d = get_keymap_dir(query);
4049
4050                                         /* XTRA HACK MOVEFAST */
4051                                         if (isupper(query)) move_fast = TRUE;
4052
4053                                         if (!d) bell();
4054                                         break;
4055                                 }
4056                         }
4057
4058                         /* Handle "direction" */
4059                         if (d)
4060                         {
4061                                 int dx = ddx[d];
4062                                 int dy = ddy[d];
4063
4064                                 /* XTRA HACK MOVEFAST */
4065                                 if (move_fast)
4066                                 {
4067                                         int mag = MIN(wid / 2, hgt / 2);
4068                                         x += dx * mag;
4069                                         y += dy * mag;
4070                                 }
4071                                 else
4072                                 {
4073                                         x += dx;
4074                                         y += dy;
4075                                 }
4076
4077                                 /* Do not move horizontally if unnecessary */
4078                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4079                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4080                                 {
4081                                         dx = 0;
4082                                 }
4083
4084                                 /* Do not move vertically if unnecessary */
4085                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4086                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4087                                 {
4088                                         dy = 0;
4089                                 }
4090
4091                                 /* Apply the motion */
4092                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
4093                                          (x >= panel_col_min + wid) || (x < panel_col_min))
4094                                 {
4095                                         if (change_panel(dy, dx)) target_set_prepare(mode);
4096                                 }
4097
4098                                 /* Slide into legality */
4099                                 if (x >= cur_wid-1) x = cur_wid - 2;
4100                                 else if (x <= 0) x = 1;
4101
4102                                 /* Slide into legality */
4103                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4104                                 else if (y <= 0) y = 1;
4105                         }
4106                 }
4107         }
4108
4109         /* Forget */
4110         temp_n = 0;
4111
4112         /* Clear the top line */
4113         prt("", 0, 0);
4114
4115         /* Recenter the map around the player */
4116         verify_panel();
4117
4118         /* Update stuff */
4119         p_ptr->update |= (PU_MONSTERS);
4120
4121         /* Redraw map */
4122         p_ptr->redraw |= (PR_MAP);
4123
4124         /* Window stuff */
4125         p_ptr->window |= (PW_OVERHEAD);
4126
4127         /* Handle stuff */
4128         handle_stuff();
4129
4130         /* Failure to set target */
4131         if (!target_who) return (FALSE);
4132
4133         /* Success */
4134         return (TRUE);
4135 }
4136
4137
4138 /*
4139  * Get an "aiming direction" from the user.
4140  *
4141  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
4142  * "0" for "current target", and "-1" for "entry aborted".
4143  *
4144  * Note that "Force Target", if set, will pre-empt user interaction,
4145  * if there is a usable target already set.
4146  *
4147  * Note that confusion over-rides any (explicit?) user choice.
4148  */
4149 bool get_aim_dir(int *dp)
4150 {
4151         int             dir;
4152
4153         char    command;
4154
4155         cptr    p;
4156
4157         /* Initialize */
4158         (*dp) = 0;
4159
4160         /* Global direction */
4161         dir = command_dir;
4162
4163         /* Hack -- auto-target if requested */
4164         if (use_old_target && target_okay()) dir = 5;
4165
4166 #ifdef ALLOW_REPEAT /* TNB */
4167
4168         if (repeat_pull(dp))
4169         {
4170                 /* Confusion? */
4171
4172                 /* Verify */
4173                 if (!(*dp == 5 && !target_okay()))
4174                 {
4175 /*                      return (TRUE); */
4176                         dir = *dp;
4177                 }
4178         }
4179
4180 #endif /* ALLOW_REPEAT -- TNB */
4181
4182         /* Ask until satisfied */
4183         while (!dir)
4184         {
4185                 /* Choose a prompt */
4186                 if (!target_okay())
4187                 {
4188 #ifdef JP
4189 p = "Êý¸þ ('*'¤Ç¥¿¡¼¥²¥Ã¥ÈÁªÂò, ESC¤ÇÃæÃÇ)? ";
4190 #else
4191                         p = "Direction ('*' to choose a target, Escape to cancel)? ";
4192 #endif
4193
4194                 }
4195                 else
4196                 {
4197 #ifdef JP
4198 p = "Êý¸þ ('5'¤Ç¥¿¡¼¥²¥Ã¥È¤Ø, '*'¤Ç¥¿¡¼¥²¥Ã¥ÈºÆÁªÂò, ESC¤ÇÃæÃÇ)? ";
4199 #else
4200                         p = "Direction ('5' for target, '*' to re-target, Escape to cancel)? ";
4201 #endif
4202
4203                 }
4204
4205                 /* Get a command (or Cancel) */
4206                 if (!get_com(p, &command, TRUE)) break;
4207
4208                 if (use_menu)
4209                 {
4210                         if (command == '\r') command = 't';
4211                 }  
4212
4213                 /* Convert various keys to "standard" keys */
4214                 switch (command)
4215                 {
4216                         /* Use current target */
4217                         case 'T':
4218                         case 't':
4219                         case '.':
4220                         case '5':
4221                         case '0':
4222                         {
4223                                 dir = 5;
4224                                 break;
4225                         }
4226
4227                         /* Set new target */
4228                         case '*':
4229                         case ' ':
4230                         case '\r':
4231                         {
4232                                 if (target_set(TARGET_KILL)) dir = 5;
4233                                 break;
4234                         }
4235
4236                         default:
4237                         {
4238                                 /* Extract the action (if any) */
4239                                 dir = get_keymap_dir(command);
4240
4241                                 break;
4242                         }
4243                 }
4244
4245                 /* Verify requested targets */
4246                 if ((dir == 5) && !target_okay()) dir = 0;
4247
4248                 /* Error */
4249                 if (!dir) bell();
4250         }
4251
4252         /* No direction */
4253         if (!dir)
4254         {
4255                 project_length = 0; /* reset to default */
4256                 return (FALSE);
4257         }
4258
4259         /* Save the direction */
4260         command_dir = dir;
4261
4262         /* Check for confusion */
4263         if (p_ptr->confused)
4264         {
4265                 /* XXX XXX XXX */
4266                 /* Random direction */
4267                 dir = ddd[randint0(8)];
4268         }
4269
4270         /* Notice confusion */
4271         if (command_dir != dir)
4272         {
4273                 /* Warn the user */
4274 #ifdef JP
4275 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4276 #else
4277                 msg_print("You are confused.");
4278 #endif
4279
4280         }
4281
4282         /* Save direction */
4283         (*dp) = dir;
4284
4285 #ifdef ALLOW_REPEAT /* TNB */
4286
4287 /*      repeat_push(dir); */
4288         repeat_push(command_dir);
4289
4290 #endif /* ALLOW_REPEAT -- TNB */
4291
4292         /* A "valid" direction was entered */
4293         return (TRUE);
4294 }
4295
4296
4297
4298 /*
4299  * Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
4300  * and place it into "command_dir", unless we already have one.
4301  *
4302  * This function should be used for all "repeatable" commands, such as
4303  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
4304  * as all commands which must reference a grid adjacent to the player,
4305  * and which may not reference the grid under the player.  Note that,
4306  * for example, it is no longer possible to "disarm" or "open" chests
4307  * in the same grid as the player.
4308  *
4309  * Direction "5" is illegal and will (cleanly) abort the command.
4310  *
4311  * This function tracks and uses the "global direction", and uses
4312  * that as the "desired direction", to which "confusion" is applied.
4313  */
4314 bool get_rep_dir(int *dp, bool under)
4315 {
4316         int dir;
4317
4318         /* Initialize */
4319         (*dp) = 0;
4320
4321         /* Global direction */
4322         dir = command_dir;
4323
4324 #ifdef ALLOW_REPEAT /* TNB */
4325
4326         if (repeat_pull(dp))
4327         {
4328                 dir = *dp;
4329 /*              return (TRUE); */
4330         }
4331
4332 #endif /* ALLOW_REPEAT -- TNB */
4333
4334         /* Get a direction */
4335         while (!dir)
4336         {
4337                 char ch;
4338
4339                 /* Get a command (or Cancel) */
4340 #ifdef JP
4341 if (!get_com("Êý¸þ (ESC¤ÇÃæÃÇ)? ", &ch, TRUE)) break;
4342 #else
4343                 if (!get_com("Direction (Escape to cancel)? ", &ch, TRUE)) break;
4344 #endif
4345
4346
4347                 /* Look up the direction */
4348                 dir = get_keymap_dir(ch);
4349
4350                 /* Oops */
4351                 if (!dir) bell();
4352         }
4353
4354         /* Prevent weirdness */
4355         if ((dir == 5) && (!under)) dir = 0;
4356
4357         /* Aborted */
4358         if (!dir) return (FALSE);
4359
4360         /* Save desired direction */
4361         command_dir = dir;
4362
4363         /* Apply "confusion" */
4364         if (p_ptr->confused)
4365         {
4366                 /* Standard confusion */
4367                 if (randint0(100) < 75)
4368                 {
4369                         /* Random direction */
4370                         dir = ddd[randint0(8)];
4371                 }
4372         }
4373         else if (p_ptr->riding)
4374         {
4375                 monster_type *m_ptr = &m_list[p_ptr->riding];
4376                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4377
4378                 if (m_ptr->confused)
4379                 {
4380                         /* Standard confusion */
4381                         if (randint0(100) < 75)
4382                         {
4383                                 /* Random direction */
4384                                 dir = ddd[randint0(8)];
4385                         }
4386                 }
4387                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
4388                 {
4389                         /* Random direction */
4390                         dir = ddd[randint0(8)];
4391                 }
4392                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
4393                 {
4394                         /* Random direction */
4395                         dir = ddd[randint0(8)];
4396                 }
4397         }
4398
4399         /* Notice confusion */
4400         if (command_dir != dir)
4401         {
4402                 if (p_ptr->confused)
4403                 {
4404                         /* Warn the user */
4405 #ifdef JP
4406 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4407 #else
4408                         msg_print("You are confused.");
4409 #endif
4410                 }
4411                 else
4412                 {
4413                         char m_name[80];
4414                         monster_type *m_ptr = &m_list[p_ptr->riding];
4415
4416                         monster_desc(m_name, m_ptr, 0);
4417                         if (m_ptr->confused)
4418                         {
4419 #ifdef JP
4420 msg_format("%s¤Ïº®Í𤷤Ƥ¤¤ë¡£", m_name);
4421 #else
4422  msg_format("%^s is confusing.", m_name);
4423
4424 #endif
4425                         }
4426                         else
4427                         {
4428 #ifdef JP
4429 msg_format("%s¤Ï»×¤¤Ä̤ê¤ËÆ°¤¤¤Æ¤¯¤ì¤Ê¤¤¡£", m_name);
4430 #else
4431 msg_format("You cannot control %s.", m_name);
4432 #endif
4433                         }
4434                 }
4435         }
4436
4437         /* Save direction */
4438         (*dp) = dir;
4439
4440 #ifdef ALLOW_REPEAT /* TNB */
4441
4442 /*      repeat_push(dir); */
4443         repeat_push(command_dir);
4444
4445 #endif /* ALLOW_REPEAT -- TNB */
4446
4447         /* Success */
4448         return (TRUE);
4449 }
4450
4451
4452 bool get_rep_dir2(int *dp)
4453 {
4454         int dir;
4455
4456         /* Initialize */
4457         (*dp) = 0;
4458
4459         /* Global direction */
4460         dir = command_dir;
4461
4462 #ifdef ALLOW_REPEAT /* TNB */
4463
4464         if (repeat_pull(dp))
4465         {
4466                 dir = *dp;
4467 /*              return (TRUE); */
4468         }
4469
4470 #endif /* ALLOW_REPEAT -- TNB */
4471
4472         /* Get a direction */
4473         while (!dir)
4474         {
4475                 char ch;
4476
4477                 /* Get a command (or Cancel) */
4478 #ifdef JP
4479 if (!get_com("Êý¸þ (ESC¤ÇÃæÃÇ)? ", &ch, TRUE)) break;
4480 #else
4481                 if (!get_com("Direction (Escape to cancel)? ", &ch, TRUE)) break;
4482 #endif
4483
4484
4485                 /* Look up the direction */
4486                 dir = get_keymap_dir(ch);
4487
4488                 /* Oops */
4489                 if (!dir) bell();
4490         }
4491
4492         /* Prevent weirdness */
4493         if (dir == 5) dir = 0;
4494
4495         /* Aborted */
4496         if (!dir) return (FALSE);
4497
4498         /* Save desired direction */
4499         command_dir = dir;
4500
4501         /* Apply "confusion" */
4502         if (p_ptr->confused)
4503         {
4504                 /* Standard confusion */
4505                 if (randint0(100) < 75)
4506                 {
4507                         /* Random direction */
4508                         dir = ddd[randint0(8)];
4509                 }
4510         }
4511
4512         /* Notice confusion */
4513         if (command_dir != dir)
4514         {
4515                 /* Warn the user */
4516 #ifdef JP
4517 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4518 #else
4519                 msg_print("You are confused.");
4520 #endif
4521
4522         }
4523
4524         /* Save direction */
4525         (*dp) = dir;
4526
4527 #ifdef ALLOW_REPEAT /* TNB */
4528
4529 /*      repeat_push(dir); */
4530         repeat_push(command_dir);
4531
4532 #endif /* ALLOW_REPEAT -- TNB */
4533
4534         /* Success */
4535         return (TRUE);
4536 }
4537
4538
4539 int get_chaos_patron(void)
4540 {
4541         return ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
4542 }
4543
4544
4545 void gain_level_reward(int chosen_reward)
4546 {
4547         object_type *q_ptr;
4548         object_type forge;
4549         char        wrath_reason[32] = "";
4550         int         nasty_chance = 6;
4551         int         dummy = 0, dummy2 = 0;
4552         int         type, effect;
4553         cptr        reward = NULL;
4554         char o_name[MAX_NLEN];
4555
4556         int count = 0;
4557
4558         if (!chosen_reward)
4559         {
4560                 if (multi_rew) return;
4561                 else multi_rew = TRUE;
4562         }
4563
4564
4565         if (p_ptr->lev == 13) nasty_chance = 2;
4566         else if (!(p_ptr->lev % 13)) nasty_chance = 3;
4567         else if (!(p_ptr->lev % 14)) nasty_chance = 12;
4568
4569         if (one_in_(nasty_chance))
4570                 type = randint1(20); /* Allow the 'nasty' effects */
4571         else
4572                 type = randint1(15) + 5; /* Or disallow them */
4573
4574         if (type < 1) type = 1;
4575         if (type > 20) type = 20;
4576         type--;
4577
4578
4579 #ifdef JP
4580 sprintf(wrath_reason, "%s¤ÎÅܤê",
4581                 chaos_patrons[p_ptr->chaos_patron]);
4582 #else
4583         sprintf(wrath_reason, "the Wrath of %s",
4584                 chaos_patrons[p_ptr->chaos_patron]);
4585 #endif
4586
4587
4588         effect = chaos_rewards[p_ptr->chaos_patron][type];
4589
4590         if (one_in_(6) && !chosen_reward)
4591         {
4592 #ifdef JP
4593 msg_format("%^s¤ÏË«Èþ¤È¤·¤Æ¤¢¤Ê¤¿¤òÆÍÁ³ÊÑ°Û¤µ¤»¤¿¡£",
4594                         chaos_patrons[p_ptr->chaos_patron]);
4595 #else
4596                 msg_format("%^s rewards you with a mutation!",
4597                         chaos_patrons[p_ptr->chaos_patron]);
4598 #endif
4599
4600                 (void)gain_random_mutation(0);
4601 #ifdef JP
4602                 reward = "ÊÑ°Û¤·¤¿¡£";
4603 #else
4604                 reward = "mutation";
4605 #endif
4606         }
4607         else
4608         {
4609         switch (chosen_reward ? chosen_reward : effect)
4610         {
4611                 case REW_POLY_SLF:
4612 #ifdef JP
4613 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4614                                 chaos_patrons[p_ptr->chaos_patron]);
4615 #else
4616                         msg_format("The voice of %s booms out:",
4617                                 chaos_patrons[p_ptr->chaos_patron]);
4618 #endif
4619
4620 #ifdef JP
4621 msg_print("¡ÖÆò¡¢¿·¤¿¤Ê¤ë»Ñ¤òɬÍפȤ»¤ê¡ª¡×");
4622 #else
4623                         msg_print("'Thou needst a new form, mortal!'");
4624 #endif
4625
4626                         do_poly_self();
4627 #ifdef JP
4628                         reward = "ÊÑ°Û¤·¤¿¡£";
4629 #else
4630                         reward = "polymorphing";
4631 #endif
4632                         break;
4633                 case REW_GAIN_EXP:
4634 #ifdef JP
4635 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4636                                 chaos_patrons[p_ptr->chaos_patron]);
4637 #else
4638                         msg_format("The voice of %s booms out:",
4639                                 chaos_patrons[p_ptr->chaos_patron]);
4640 #endif
4641
4642 #ifdef JP
4643 msg_print("¡ÖÆò¤ÏÎɤ¯¹Ô¤¤¤¿¤ê¡ªÂ³¤±¤è¡ª¡×");
4644 #else
4645                         msg_print("'Well done, mortal! Lead on!'");
4646 #endif
4647
4648                         if (p_ptr->prace == RACE_ANDROID)
4649                         {
4650 #ifdef JP
4651                                 msg_print("¤·¤«¤·²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
4652 #else
4653                                 msg_print("But, nothing happen.");
4654 #endif
4655                         }
4656                         else if (p_ptr->exp < PY_MAX_EXP)
4657                         {
4658                                 s32b ee = (p_ptr->exp / 2) + 10;
4659                                 if (ee > 100000L) ee = 100000L;
4660 #ifdef JP
4661 msg_print("¹¹¤Ë·Ð¸³¤òÀѤó¤À¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
4662 #else
4663                                 msg_print("You feel more experienced.");
4664 #endif
4665
4666                                 gain_exp(ee);
4667 #ifdef JP
4668                                 reward = "·Ð¸³ÃͤòÆÀ¤¿";
4669 #else
4670                                 reward = "experience";
4671 #endif
4672                         }
4673                         break;
4674                 case REW_LOSE_EXP:
4675 #ifdef JP
4676 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4677                                 chaos_patrons[p_ptr->chaos_patron]);
4678 #else
4679                         msg_format("The voice of %s booms out:",
4680                                 chaos_patrons[p_ptr->chaos_patron]);
4681 #endif
4682
4683 #ifdef JP
4684 msg_print("¡Ö²¼Ëͤ衢Æò¤½¤ì¤ËÃͤ»¤º¡£¡×");
4685 #else
4686                         msg_print("'Thou didst not deserve that, slave.'");
4687 #endif
4688
4689                         if (p_ptr->prace == RACE_ANDROID)
4690                         {
4691 #ifdef JP
4692                                 msg_print("¤·¤«¤·²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
4693 #else
4694                                 msg_print("But, nothing happen.");
4695 #endif
4696                         }
4697                         else
4698                         {
4699                                 lose_exp(p_ptr->exp / 6);
4700 #ifdef JP
4701                                 reward = "·Ð¸³Ãͤò¼º¤Ã¤¿¡£";
4702 #else
4703                                 reward = "losing experience";
4704 #endif
4705                         }
4706                         break;
4707                 case REW_GOOD_OBJ:
4708 #ifdef JP
4709 msg_format("%s¤ÎÀ¼¤¬¤µ¤µ¤ä¤¤¤¿:",
4710                                 chaos_patrons[p_ptr->chaos_patron]);
4711 #else
4712                         msg_format("The voice of %s whispers:",
4713                                 chaos_patrons[p_ptr->chaos_patron]);
4714 #endif
4715
4716 #ifdef JP
4717 msg_print("¡Ö²æ¤¬Í¿¤¨¤·Êª¤ò¸­ÌÀ¤Ë»È¤¦¤Ù¤·¡£¡×");
4718 #else
4719                         msg_print("'Use my gift wisely.'");
4720 #endif
4721
4722                         acquirement(py, px, 1, FALSE, FALSE);
4723 #ifdef JP
4724                         reward = "¾å¼Á¤Ê¥¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4725 #else
4726                         reward = "a good item";
4727 #endif
4728                         break;
4729                 case REW_GREA_OBJ:
4730 #ifdef JP
4731 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4732                                 chaos_patrons[p_ptr->chaos_patron]);
4733 #else
4734                         msg_format("The voice of %s booms out:",
4735                                 chaos_patrons[p_ptr->chaos_patron]);
4736 #endif
4737
4738 #ifdef JP
4739 msg_print("¡Ö²æ¤¬Í¿¤¨¤·Êª¤ò¸­ÌÀ¤Ë»È¤¦¤Ù¤·¡£¡×");
4740 #else
4741                         msg_print("'Use my gift wisely.'");
4742 #endif
4743
4744                         acquirement(py, px, 1, TRUE, FALSE);
4745 #ifdef JP
4746                         reward = "¹âµéÉʤΥ¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4747 #else
4748                         reward = "an excellent item";
4749 #endif
4750                         break;
4751                 case REW_CHAOS_WP:
4752 #ifdef JP
4753 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4754                                 chaos_patrons[p_ptr->chaos_patron]);
4755 #else
4756                         msg_format("The voice of %s booms out:",
4757                                 chaos_patrons[p_ptr->chaos_patron]);
4758 #endif
4759
4760 #ifdef JP
4761 msg_print("¡ÖÆò¤Î¹Ô¤¤¤Ïµ®¤­·õ¤ËÃͤ»¤ê¡£¡×");
4762 #else
4763                         msg_print("'Thy deed hath earned thee a worthy blade.'");
4764 #endif
4765
4766                         /* Get local object */
4767                         q_ptr = &forge;
4768                         dummy = TV_SWORD;
4769                         switch (randint1(p_ptr->lev))
4770                         {
4771                                 case 0: case 1:
4772                                         dummy2 = SV_DAGGER;
4773                                         break;
4774                                 case 2: case 3:
4775                                         dummy2 = SV_MAIN_GAUCHE;
4776                                         break;
4777                                 case 4:
4778                                         dummy2 = SV_TANTO;
4779                                         break;
4780                                 case 5: case 6:
4781                                         dummy2 = SV_RAPIER;
4782                                         break;
4783                                 case 7: case 8:
4784                                         dummy2 = SV_SMALL_SWORD;
4785                                         break;
4786                                 case 9: case 10:
4787                                         dummy2 = SV_BASILLARD;
4788                                         break;
4789                                 case 11: case 12: case 13:
4790                                         dummy2 = SV_SHORT_SWORD;
4791                                         break;
4792                                 case 14: case 15:
4793                                         dummy2 = SV_SABRE;
4794                                         break;
4795                                 case 16: case 17:
4796                                         dummy2 = SV_CUTLASS;
4797                                         break;
4798                                 case 18:
4799                                         dummy2 = SV_WAKIZASHI;
4800                                         break;
4801                                 case 19:
4802                                         dummy2 = SV_KHOPESH;
4803                                         break;
4804                                 case 20:
4805                                         dummy2 = SV_TULWAR;
4806                                         break;
4807                                 case 21:
4808                                         dummy2 = SV_BROAD_SWORD;
4809                                         break;
4810                                 case 22: case 23:
4811                                         dummy2 = SV_LONG_SWORD;
4812                                         break;
4813                                 case 24: case 25:
4814                                         dummy2 = SV_SCIMITAR;
4815                                         break;
4816                                 case 26:
4817                                         dummy2 = SV_NINJATO;
4818                                         break;
4819                                 case 27:
4820                                         dummy2 = SV_KATANA;
4821                                         break;
4822                                 case 28: case 29:
4823                                         dummy2 = SV_BASTARD_SWORD;
4824                                         break;
4825                                 case 30:
4826                                         dummy2 = SV_GREAT_SCIMITAR;
4827                                         break;
4828                                 case 31:
4829                                         dummy2 = SV_CLAYMORE;
4830                                         break;
4831                                 case 32:
4832                                         dummy2 = SV_ESPADON;
4833                                         break;
4834                                 case 33:
4835                                         dummy2 = SV_TWO_HANDED_SWORD;
4836                                         break;
4837                                 case 34:
4838                                         dummy2 = SV_FLAMBERGE;
4839                                         break;
4840                                 case 35:
4841                                         dummy2 = SV_NO_DACHI;
4842                                         break;
4843                                 case 36:
4844                                         dummy2 = SV_EXECUTIONERS_SWORD;
4845                                         break;
4846                                 case 37:
4847                                         dummy2 = SV_ZWEIHANDER;
4848                                         break;
4849                                 case 38:
4850                                         dummy2 = SV_HAYABUSA;
4851                                         break;
4852                                 default:
4853                                         dummy2 = SV_BLADE_OF_CHAOS;
4854                         }
4855
4856                         object_prep(q_ptr, lookup_kind(dummy, dummy2));
4857                         q_ptr->to_h = 3 + randint1(dun_level) % 10;
4858                         q_ptr->to_d = 3 + randint1(dun_level) % 10;
4859                         one_resistance(q_ptr);
4860                         q_ptr->name2 = EGO_CHAOTIC;
4861
4862                         /* Drop it in the dungeon */
4863                         (void)drop_near(q_ptr, -1, py, px);
4864 #ifdef JP
4865                         reward = "(º®ÆÙ)¤ÎÉð´ï¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4866 #else
4867                         reward = "chaos weapon";
4868 #endif
4869                         break;
4870                 case REW_GOOD_OBS:
4871 #ifdef JP
4872 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4873                                 chaos_patrons[p_ptr->chaos_patron]);
4874 #else
4875                         msg_format("The voice of %s booms out:",
4876                                 chaos_patrons[p_ptr->chaos_patron]);
4877 #endif
4878
4879 #ifdef JP
4880 msg_print("¡ÖÆò¤Î¹Ô¤¤¤Ïµ®¤­Ê󤤤ËÃͤ»¤ê¡£¡×");
4881 #else
4882                         msg_print("'Thy deed hath earned thee a worthy reward.'");
4883 #endif
4884
4885                         acquirement(py, px, randint1(2) + 1, FALSE, FALSE);
4886 #ifdef JP
4887                         reward = "¾å¼Á¤Ê¥¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4888 #else
4889                         reward = "good items";
4890 #endif
4891                         break;
4892                 case REW_GREA_OBS:
4893 #ifdef JP
4894 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4895                                 chaos_patrons[p_ptr->chaos_patron]);
4896 #else
4897                         msg_format("The voice of %s booms out:",
4898                                 chaos_patrons[p_ptr->chaos_patron]);
4899 #endif
4900
4901 #ifdef JP
4902 msg_print("¡Ö²¼Ëͤ衢Æò¤Î¸¥¿È¤Ø¤Î²æ¤¬Àˤ·¤ß̵¤­Ê󤤤ò¸«¤ë¤¬¤è¤¤¡£¡×");
4903 #else
4904                         msg_print("'Behold, mortal, how generously I reward thy loyalty.'");
4905 #endif
4906
4907                         acquirement(py, px, randint1(2) + 1, TRUE, FALSE);
4908 #ifdef JP
4909                         reward = "¹âµéÉʤΥ¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4910 #else
4911                         reward = "excellent items";
4912 #endif
4913                         break;
4914                 case REW_TY_CURSE:
4915 #ifdef JP
4916 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
4917                                 chaos_patrons[p_ptr->chaos_patron]);
4918 #else
4919                         msg_format("The voice of %s thunders:",
4920                                 chaos_patrons[p_ptr->chaos_patron]);
4921 #endif
4922
4923 #ifdef JP
4924 msg_print("¡Ö²¼Ëͤ衢ÆòÐþËý¤Ê¤ê¡£¡×");
4925 #else
4926                         msg_print("'Thou art growing arrogant, mortal.'");
4927 #endif
4928
4929                         (void)activate_ty_curse(FALSE, &count);
4930 #ifdef JP
4931                         reward = "²Ò¡¹¤·¤¤¼ö¤¤¤ò¤«¤±¤é¤ì¤¿¡£";
4932 #else
4933                         reward = "cursing";
4934 #endif
4935                         break;
4936                 case REW_SUMMON_M:
4937 #ifdef JP
4938 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4939                                 chaos_patrons[p_ptr->chaos_patron]);
4940 #else
4941                         msg_format("The voice of %s booms out:",
4942                                 chaos_patrons[p_ptr->chaos_patron]);
4943 #endif
4944
4945 #ifdef JP
4946 msg_print("¡Ö²æ¤¬²¼Ëͤ¿¤Á¤è¡¢¤«¤ÎÐþËý¤Ê¤ë¼Ô¤òÅݤ¹¤Ù¤·¡ª¡×");
4947 #else
4948                         msg_print("'My pets, destroy the arrogant mortal!'");
4949 #endif
4950
4951                         for (dummy = 0; dummy < randint1(5) + 1; dummy++)
4952                         {
4953                                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
4954                         }
4955 #ifdef JP
4956                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
4957 #else
4958                         reward = "summoning hostile monsters";
4959 #endif
4960                         break;
4961                 case REW_H_SUMMON:
4962 #ifdef JP
4963 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4964                                 chaos_patrons[p_ptr->chaos_patron]);
4965 #else
4966                         msg_format("The voice of %s booms out:",
4967                                 chaos_patrons[p_ptr->chaos_patron]);
4968 #endif
4969
4970 #ifdef JP
4971 msg_print("¡ÖÆò¡¢¤è¤ê¶¯¤­Å¨¤òɬÍפȤ»¤ê¡ª¡×");
4972 #else
4973                         msg_print("'Thou needst worthier opponents!'");
4974 #endif
4975
4976                         activate_hi_summon(py, px, FALSE);
4977 #ifdef JP
4978                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
4979 #else
4980                         reward = "summoning many hostile monsters";
4981 #endif
4982                         break;
4983                 case REW_DO_HAVOC:
4984 #ifdef JP
4985 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4986                                 chaos_patrons[p_ptr->chaos_patron]);
4987 #else
4988                         msg_format("The voice of %s booms out:",
4989                                 chaos_patrons[p_ptr->chaos_patron]);
4990 #endif
4991
4992 #ifdef JP
4993 msg_print("¡Ö»à¤ÈÇ˲õ¤³¤½²æ¤¬´î¤Ó¤Ê¤ê¡ª¡×");
4994 #else
4995                         msg_print("'Death and destruction! This pleaseth me!'");
4996 #endif
4997
4998                         call_chaos();
4999 #ifdef JP
5000                         reward = "¥«¥ª¥¹¤ÎÎϤ¬±²´¬¤¤¤¿¡£";
5001 #else
5002                         reward = "calling chaos";
5003 #endif
5004                         break;
5005                 case REW_GAIN_ABL:
5006 #ifdef JP
5007 msg_format("%s¤ÎÀ¼¤¬ÌĤê¶Á¤¤¤¿:",
5008                                 chaos_patrons[p_ptr->chaos_patron]);
5009 #else
5010                         msg_format("The voice of %s rings out:",
5011                                 chaos_patrons[p_ptr->chaos_patron]);
5012 #endif
5013
5014 #ifdef JP
5015 msg_print("¡Öα¤Þ¤ë¤Î¤À¡¢²¼Ëͤ衣;¤¬Æò¤ÎÆùÂΤòÃ䨤󡣡×");
5016 #else
5017                         msg_print("'Stay, mortal, and let me mold thee.'");
5018 #endif
5019
5020                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
5021                                 do_inc_stat(chaos_stats[p_ptr->chaos_patron]);
5022                         else
5023                                 do_inc_stat(randint0(6));
5024 #ifdef JP
5025                         reward = "ǽÎÏÃͤ¬¾å¤¬¤Ã¤¿¡£";
5026 #else
5027                         reward = "increasing a stat";
5028 #endif
5029                         break;
5030                 case REW_LOSE_ABL:
5031 #ifdef JP
5032 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5033                                 chaos_patrons[p_ptr->chaos_patron]);
5034 #else
5035                         msg_format("The voice of %s booms out:",
5036                                 chaos_patrons[p_ptr->chaos_patron]);
5037 #endif
5038
5039 #ifdef JP
5040 msg_print("¡Ö²¼Ëͤ衢;¤ÏÆò¤ËË°¤ß¤¿¤ê¡£¡×");
5041 #else
5042                         msg_print("'I grow tired of thee, mortal.'");
5043 #endif
5044
5045                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
5046                                 do_dec_stat(chaos_stats[p_ptr->chaos_patron]);
5047                         else
5048                                 (void)do_dec_stat(randint0(6));
5049 #ifdef JP
5050                         reward = "ǽÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5051 #else
5052                         reward = "decreasing a stat";
5053 #endif
5054                         break;
5055                 case REW_RUIN_ABL:
5056 #ifdef JP
5057 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5058                                 chaos_patrons[p_ptr->chaos_patron]);
5059 #else
5060                         msg_format("The voice of %s thunders:",
5061                                 chaos_patrons[p_ptr->chaos_patron]);
5062 #endif
5063
5064 #ifdef JP
5065 msg_print("¡ÖÆò¡¢¸¬µõ¤¿¤ë¤³¤È¤ò³Ø¤Ö¤Ù¤·¡ª¡×");
5066 msg_print("¤¢¤Ê¤¿¤Ï°ÊÁ°¤è¤ê¼å¤¯¤Ê¤Ã¤¿¡ª");
5067 #else
5068                         msg_print("'Thou needst a lesson in humility, mortal!'");
5069                         msg_print("You feel less powerful!");
5070 #endif
5071
5072                         for (dummy = 0; dummy < 6; dummy++)
5073                         {
5074                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5075                         }
5076 #ifdef JP
5077                         reward = "Á´Ç½ÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5078 #else
5079                         reward = "decreasing all stats";
5080 #endif
5081                         break;
5082                 case REW_POLY_WND:
5083 #ifdef JP
5084 msg_format("%s¤ÎÎϤ¬¿¨¤ì¤ë¤Î¤ò´¶¤¸¤¿¡£",
5085 #else
5086                         msg_format("You feel the power of %s touch you.",
5087 #endif
5088
5089                                 chaos_patrons[p_ptr->chaos_patron]);
5090                         do_poly_wounds();
5091 #ifdef JP
5092                         reward = "½ý¤¬ÊѲ½¤·¤¿¡£";
5093 #else
5094                         reward = "polymorphing wounds";
5095 #endif
5096                         break;
5097                 case REW_AUGM_ABL:
5098 #ifdef JP
5099 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5100                                 chaos_patrons[p_ptr->chaos_patron]);
5101 #else
5102                         msg_format("The voice of %s booms out:",
5103                                 chaos_patrons[p_ptr->chaos_patron]);
5104 #endif
5105
5106 #ifdef JP
5107 msg_print("¡Ö²æ¤¬¤µ¤µ¤ä¤«¤Ê¤ë»òʪ¤ò¼õ¤±¤È¤ë¤¬¤è¤¤¡ª¡×");
5108 #else
5109                         msg_print("'Receive this modest gift from me!'");
5110 #endif
5111
5112                         for (dummy = 0; dummy < 6; dummy++)
5113                         {
5114                                 (void)do_inc_stat(dummy);
5115                         }
5116 #ifdef JP
5117                         reward = "Á´Ç½ÎÏÃͤ¬¾å¤¬¤Ã¤¿¡£";
5118 #else
5119                         reward = "increasing all stats";
5120 #endif
5121                         break;
5122                 case REW_HURT_LOT:
5123 #ifdef JP
5124 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5125                                 chaos_patrons[p_ptr->chaos_patron]);
5126 #else
5127                         msg_format("The voice of %s booms out:",
5128                                 chaos_patrons[p_ptr->chaos_patron]);
5129 #endif
5130
5131 #ifdef JP
5132 msg_print("¡Ö¶ì¤·¤à¤¬¤è¤¤¡¢ÌµÇ½¤Ê¶ò¤«¼Ô¤è¡ª¡×");
5133 #else
5134                         msg_print("'Suffer, pathetic fool!'");
5135 #endif
5136
5137                         fire_ball(GF_DISINTEGRATE, 0, p_ptr->lev * 4, 4);
5138                         take_hit(DAMAGE_NOESCAPE, p_ptr->lev * 4, wrath_reason, -1);
5139 #ifdef JP
5140                         reward = "ʬ²ò¤Îµå¤¬È¯À¸¤·¤¿¡£";
5141 #else
5142                         reward = "generating disintegration ball";
5143 #endif
5144                         break;
5145            case REW_HEAL_FUL:
5146 #ifdef JP
5147 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5148                                 chaos_patrons[p_ptr->chaos_patron]);
5149 #else
5150                         msg_format("The voice of %s booms out:",
5151                                 chaos_patrons[p_ptr->chaos_patron]);
5152 #endif
5153
5154 #ifdef JP
5155 msg_print("¡Öᴤ뤬¤è¤¤¡¢²æ¤¬²¼Ëͤ衪¡×");
5156 #else
5157                         msg_print("'Rise, my servant!'");
5158 #endif
5159
5160                         restore_level();
5161                         (void)set_poisoned(0);
5162                         (void)set_blind(0);
5163                         (void)set_confused(0);
5164                         (void)set_image(0);
5165                         (void)set_stun(0);
5166                         (void)set_cut(0);
5167                         hp_player(5000);
5168                         for (dummy = 0; dummy < 6; dummy++)
5169                         {
5170                                 (void)do_res_stat(dummy);
5171                         }
5172 #ifdef JP
5173                         reward = "ÂÎÎϤ¬²óÉü¤·¤¿¡£";
5174 #else
5175                         reward = "healing";
5176 #endif
5177                         break;
5178                 case REW_CURSE_WP:
5179                         if (!buki_motteruka(INVEN_RARM)) break;
5180 #ifdef JP
5181 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5182                                 chaos_patrons[p_ptr->chaos_patron]);
5183 #else
5184                         msg_format("The voice of %s booms out:",
5185                                 chaos_patrons[p_ptr->chaos_patron]);
5186 #endif
5187
5188 #ifdef JP
5189 msg_print("¡ÖÆò¡¢Éð´ï¤ËÍê¤ë¤³¤È¤Ê¤«¤ì¡£¡×");
5190 #else
5191                         msg_print("'Thou reliest too much on thy weapon.'");
5192 #endif
5193
5194                         object_desc(o_name, &inventory[INVEN_RARM], TRUE, 0);
5195                         (void)curse_weapon(FALSE, INVEN_RARM);
5196 #ifdef JP
5197                         reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5198 #else
5199                         reward = format("destroying %s", o_name);
5200 #endif
5201                         break;
5202                 case REW_CURSE_AR:
5203                         if (!inventory[INVEN_BODY].k_idx) break;
5204 #ifdef JP
5205 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5206                                 chaos_patrons[p_ptr->chaos_patron]);
5207 #else
5208                         msg_format("The voice of %s booms out:",
5209                                 chaos_patrons[p_ptr->chaos_patron]);
5210 #endif
5211
5212 #ifdef JP
5213 msg_print("¡ÖÆò¡¢Ëɶñ¤ËÍê¤ë¤³¤È¤Ê¤«¤ì¡£¡×");
5214 #else
5215                         msg_print("'Thou reliest too much on thine equipment.'");
5216 #endif
5217
5218                         object_desc(o_name, &inventory[INVEN_BODY], TRUE, 0);
5219                         (void)curse_armor();
5220 #ifdef JP
5221                         reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5222 #else
5223                         reward = format("destroying %s", o_name);
5224 #endif
5225                         break;
5226                 case REW_PISS_OFF:
5227 #ifdef JP
5228 msg_format("%s¤ÎÀ¼¤¬¤µ¤µ¤ä¤¤¤¿:",
5229                                 chaos_patrons[p_ptr->chaos_patron]);
5230 #else
5231                         msg_format("The voice of %s whispers:",
5232                                 chaos_patrons[p_ptr->chaos_patron]);
5233 #endif
5234
5235 #ifdef JP
5236 msg_print("¡Ö²æ¤òÅܤꤷ¤á¤¿ºá¤ò½þ¤¦¤Ù¤·¡£¡×");
5237 #else
5238                         msg_print("'Now thou shalt pay for annoying me.'");
5239 #endif
5240
5241                         switch (randint1(4))
5242                         {
5243                                 case 1:
5244                                         (void)activate_ty_curse(FALSE, &count);
5245 #ifdef JP
5246                                         reward = "²Ò¡¹¤·¤¤¼ö¤¤¤ò¤«¤±¤é¤ì¤¿¡£";
5247 #else
5248                                         reward = "cursing";
5249 #endif
5250                                         break;
5251                                 case 2:
5252                                         activate_hi_summon(py, px, FALSE);
5253 #ifdef JP
5254                                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
5255 #else
5256                                         reward = "summoning hostile monsters";
5257 #endif
5258                                         break;
5259                                 case 3:
5260                                         if (one_in_(2))
5261                                         {
5262                                                 if (!buki_motteruka(INVEN_RARM)) break;
5263                                                 object_desc(o_name, &inventory[INVEN_RARM], TRUE, 0);
5264                                                 (void)curse_weapon(FALSE, INVEN_RARM);
5265 #ifdef JP
5266                                                 reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5267 #else
5268                                                 reward = format("destroying %s", o_name);
5269 #endif
5270                                         }
5271                                         else
5272                                         {
5273                                                 if (!inventory[INVEN_BODY].k_idx) break;
5274                                                 object_desc(o_name, &inventory[INVEN_BODY], TRUE, 0);
5275                                                 (void)curse_armor();
5276 #ifdef JP
5277                                                 reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5278 #else
5279                                                 reward = format("destroying %s", o_name);
5280 #endif
5281                                         }
5282                                         break;
5283                                 default:
5284                                         for (dummy = 0; dummy < 6; dummy++)
5285                                         {
5286                                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5287                                         }
5288 #ifdef JP
5289                                         reward = "Á´Ç½ÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5290 #else
5291                                         reward = "decreasing all stats";
5292 #endif
5293                                         break;
5294                         }
5295                         break;
5296                 case REW_WRATH:
5297 #ifdef JP
5298 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5299 #else
5300                         msg_format("The voice of %s thunders:",
5301 #endif
5302
5303                                 chaos_patrons[p_ptr->chaos_patron]);
5304 #ifdef JP
5305 msg_print("¡Ö»à¤Ì¤¬¤è¤¤¡¢²¼Ëͤ衪¡×");
5306 #else
5307                         msg_print("'Die, mortal!'");
5308 #endif
5309
5310                         take_hit(DAMAGE_LOSELIFE, p_ptr->lev * 4, wrath_reason, -1);
5311                         for (dummy = 0; dummy < 6; dummy++)
5312                         {
5313                                 (void)dec_stat(dummy, 10 + randint1(15), FALSE);
5314                         }
5315                         activate_hi_summon(py, px, FALSE);
5316                         (void)activate_ty_curse(FALSE, &count);
5317                         if (one_in_(2)) (void)curse_weapon(FALSE, INVEN_RARM);
5318                         if (one_in_(2)) (void)curse_armor();
5319                         break;
5320                 case REW_DESTRUCT:
5321 #ifdef JP
5322 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5323                                 chaos_patrons[p_ptr->chaos_patron]);
5324 #else
5325                         msg_format("The voice of %s booms out:",
5326                                 chaos_patrons[p_ptr->chaos_patron]);
5327 #endif
5328
5329 #ifdef JP
5330 msg_print("¡Ö»à¤ÈÇ˲õ¤³¤½²æ¤¬´î¤Ó¤Ê¤ê¡ª¡×");
5331 #else
5332                         msg_print("'Death and destruction! This pleaseth me!'");
5333 #endif
5334
5335                         destroy_area(py, px, 25);
5336 #ifdef JP
5337                         reward = "¥À¥ó¥¸¥ç¥ó¤¬*Ç˲õ*¤µ¤ì¤¿¡£";
5338 #else
5339                         reward = "*destruct*ing dungeon";
5340 #endif
5341                         break;
5342                 case REW_GENOCIDE:
5343 #ifdef JP
5344 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5345                                 chaos_patrons[p_ptr->chaos_patron]);
5346 #else
5347                         msg_format("The voice of %s booms out:",
5348                                 chaos_patrons[p_ptr->chaos_patron]);
5349 #endif
5350
5351 #ifdef JP
5352 msg_print("¡Ö²æ¡¢Æò¤ÎŨ¤òËõ»¦¤»¤ó¡ª¡×");
5353 #else
5354                         msg_print("'Let me relieve thee of thine oppressors!'");
5355 #endif
5356
5357                         (void)symbol_genocide(0, FALSE);
5358 #ifdef JP
5359                         reward = "¥â¥ó¥¹¥¿¡¼¤¬Ëõ»¦¤µ¤ì¤¿¡£";
5360 #else
5361                         reward = "genociding monsters";
5362 #endif
5363                         break;
5364                 case REW_MASS_GEN:
5365 #ifdef JP
5366 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5367                                 chaos_patrons[p_ptr->chaos_patron]);
5368 #else
5369                         msg_format("The voice of %s booms out:",
5370                                 chaos_patrons[p_ptr->chaos_patron]);
5371 #endif
5372
5373 #ifdef JP
5374 msg_print("¡Ö²æ¡¢Æò¤ÎŨ¤òËõ»¦¤»¤ó¡ª¡×");
5375 #else
5376                         msg_print("'Let me relieve thee of thine oppressors!'");
5377 #endif
5378
5379                         (void)mass_genocide(0, FALSE);
5380 #ifdef JP
5381                         reward = "¥â¥ó¥¹¥¿¡¼¤¬Ëõ»¦¤µ¤ì¤¿¡£";
5382 #else
5383                         reward = "genociding nearby monsters";
5384 #endif
5385                         break;
5386                 case REW_DISPEL_C:
5387 #ifdef JP
5388 msg_format("%s¤ÎÎϤ¬Å¨¤ò¹¶·â¤¹¤ë¤Î¤ò´¶¤¸¤¿¡ª",
5389                                 chaos_patrons[p_ptr->chaos_patron]);
5390 #else
5391                         msg_format("You can feel the power of %s assault your enemies!",
5392                                 chaos_patrons[p_ptr->chaos_patron]);
5393 #endif
5394
5395                         (void)dispel_monsters(p_ptr->lev * 4);
5396                         break;
5397                 case REW_IGNORE:
5398 #ifdef JP
5399 msg_format("%s¤Ï¤¢¤Ê¤¿¤ò̵»ë¤·¤¿¡£",
5400                                 chaos_patrons[p_ptr->chaos_patron]);
5401 #else
5402                         msg_format("%s ignores you.",
5403                                 chaos_patrons[p_ptr->chaos_patron]);
5404 #endif
5405
5406                         break;
5407                 case REW_SER_DEMO:
5408 #ifdef JP
5409 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ°­Ëâ¤Î»È¤¤¤ò¤è¤³¤·¤¿¡ª",chaos_patrons[p_ptr->chaos_patron]);
5410 #else
5411                         msg_format("%s rewards you with a demonic servant!",chaos_patrons[p_ptr->chaos_patron]);
5412 #endif
5413
5414                         if (!summon_specific(-1, py, px, dun_level, SUMMON_DEMON, PM_FORCE_PET))
5415 #ifdef JP
5416 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5417 #else
5418                                 msg_print("Nobody ever turns up...");
5419 #endif
5420                         else
5421 #ifdef JP
5422                                 reward = "°­Ë⤬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5423 #else
5424                                 reward = "a demonic servant";
5425 #endif
5426
5427                         break;
5428                 case REW_SER_MONS:
5429 #ifdef JP
5430 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ»È¤¤¤ò¤è¤³¤·¤¿¡ª",chaos_patrons[p_ptr->chaos_patron]);
5431 #else
5432                         msg_format("%s rewards you with a servant!",chaos_patrons[p_ptr->chaos_patron]);
5433 #endif
5434
5435                         if (!summon_specific(-1, py, px, dun_level, 0, PM_FORCE_PET))
5436 #ifdef JP
5437 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5438 #else
5439                                 msg_print("Nobody ever turns up...");
5440 #endif
5441                         else
5442 #ifdef JP
5443                                 reward = "¥â¥ó¥¹¥¿¡¼¤¬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5444 #else
5445                                 reward = "a servant";
5446 #endif
5447
5448                         break;
5449                 case REW_SER_UNDE:
5450 #ifdef JP
5451 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ¥¢¥ó¥Ç¥Ã¥É¤Î»È¤¤¤ò¤è¤³¤·¤¿¡£",chaos_patrons[p_ptr->chaos_patron]);
5452 #else
5453                         msg_format("%s rewards you with an undead servant!",chaos_patrons[p_ptr->chaos_patron]);
5454 #endif
5455
5456                         if (!summon_specific(-1, py, px, dun_level, SUMMON_UNDEAD, PM_FORCE_PET))
5457 #ifdef JP
5458 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5459 #else
5460                                 msg_print("Nobody ever turns up...");
5461 #endif
5462                         else
5463 #ifdef JP
5464                                 reward = "¥¢¥ó¥Ç¥Ã¥É¤¬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5465 #else
5466                                 reward = "an undead servant";
5467 #endif
5468
5469                         break;
5470                 default:
5471 #ifdef JP
5472 msg_format("%s¤ÎÀ¼¤¬¤É¤â¤Ã¤¿:",
5473 #else
5474                         msg_format("The voice of %s stammers:",
5475 #endif
5476
5477                                 chaos_patrons[p_ptr->chaos_patron]);
5478 #ifdef JP
5479 msg_format("¡Ö¤¢¡¼¡¢¤¢¡¼¡¢Åú¤¨¤Ï %d/%d¡£¼ÁÌä¤Ï²¿¡©¡×", type, effect);
5480 #else
5481                         msg_format("'Uh... uh... the answer's %d/%d, what's the question?'", type, effect);
5482 #endif
5483
5484         }
5485         }
5486         if (reward)
5487         {
5488 #ifdef JP
5489                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format("¥Ñ¥È¥í¥ó¤ÎÊó½·¤Ç%s", reward));
5490 #else
5491                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format("The patron rewards you with %s.", reward));
5492 #endif
5493         }
5494 }
5495
5496
5497 /*
5498  * old -- from PsiAngband.
5499  */
5500 bool tgt_pt(int *x_ptr, int *y_ptr)
5501 {
5502         char ch = 0;
5503         int d, x, y;
5504         bool success = FALSE;
5505
5506         int wid, hgt;
5507
5508         /* Get size */
5509         get_screen_size(&wid, &hgt);
5510
5511         x = px;
5512         y = py;
5513
5514 #ifdef JP
5515 msg_print("¾ì½ê¤òÁª¤ó¤Ç¥¹¥Ú¡¼¥¹¥­¡¼¤ò²¡¤·¤Æ²¼¤µ¤¤¡£");
5516 #else
5517         msg_print("Select a point and press space.");
5518 #endif
5519         msg_flag = FALSE; /* prevents "-more-" message. */
5520
5521         while ((ch != ESCAPE) && !success)
5522         {
5523                 bool move_fast = FALSE;
5524
5525                 move_cursor_relative(y, x);
5526                 ch = inkey();
5527                 switch (ch)
5528                 {
5529                 case ESCAPE:
5530                         break;
5531                 case ' ':
5532                 case 't':
5533                 case '.':
5534                 case '5':
5535                 case '0':
5536                         /* illegal place */
5537                         if (x == px && y == py) ch = 0;
5538                         
5539                         /* okay place */
5540                         else success = TRUE;
5541
5542                         break;
5543                 default:
5544                         /* Look up the direction */
5545                         d = get_keymap_dir(ch);
5546
5547                         /* XTRA HACK MOVEFAST */
5548                         if (isupper(ch)) move_fast = TRUE;
5549
5550                         /* Handle "direction" */
5551                         if (d)
5552                         {
5553                                 int dx = ddx[d];
5554                                 int dy = ddy[d];
5555
5556                                 /* XTRA HACK MOVEFAST */
5557                                 if (move_fast)
5558                                 {
5559                                         int mag = MIN(wid / 2, hgt / 2);
5560                                         x += dx * mag;
5561                                         y += dy * mag;
5562                                 }
5563                                 else
5564                                 {
5565                                         x += dx;
5566                                         y += dy;
5567                                 }
5568
5569                                 /* Do not move horizontally if unnecessary */
5570                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
5571                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
5572                                 {
5573                                         dx = 0;
5574                                 }
5575
5576                                 /* Do not move vertically if unnecessary */
5577                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
5578                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
5579                                 {
5580                                         dy = 0;
5581                                 }
5582
5583                                 /* Apply the motion */
5584                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
5585                                          (x >= panel_col_min + wid) || (x < panel_col_min))
5586                                 {
5587                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
5588                                         change_panel(dy, dx);
5589                                 }
5590
5591                                 /* Slide into legality */
5592                                 if (x >= cur_wid-1) x = cur_wid - 2;
5593                                 else if (x <= 0) x = 1;
5594
5595                                 /* Slide into legality */
5596                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
5597                                 else if (y <= 0) y = 1;
5598
5599                         }
5600                         break;
5601                 }
5602         }
5603
5604         /* Clear the top line */
5605         prt("", 0, 0);
5606
5607         /* Recenter the map around the player */
5608         verify_panel();
5609
5610         /* Update stuff */
5611         p_ptr->update |= (PU_MONSTERS);
5612
5613         /* Redraw map */
5614         p_ptr->redraw |= (PR_MAP);
5615
5616         /* Window stuff */
5617         p_ptr->window |= (PW_OVERHEAD);
5618
5619         /* Handle stuff */
5620         handle_stuff();
5621
5622         *x_ptr = x;
5623         *y_ptr = y;
5624         return success;
5625 }
5626
5627
5628 bool get_hack_dir(int *dp)
5629 {
5630         int             dir;
5631         cptr    p;
5632         char    command;
5633
5634
5635         /* Initialize */
5636         (*dp) = 0;
5637
5638         /* Global direction */
5639         dir = 0;
5640
5641         /* (No auto-targeting) */
5642
5643         /* Ask until satisfied */
5644         while (!dir)
5645         {
5646                 /* Choose a prompt */
5647                 if (!target_okay())
5648                 {
5649 #ifdef JP
5650 p = "Êý¸þ ('*'¤Ç¥¿¡¼¥²¥Ã¥ÈÁªÂò, ESC¤ÇÃæÃÇ)? ";
5651 #else
5652                         p = "Direction ('*' to choose a target, Escape to cancel)? ";
5653 #endif
5654
5655                 }
5656                 else
5657                 {
5658 #ifdef JP
5659 p = "Êý¸þ ('5'¤Ç¥¿¡¼¥²¥Ã¥È¤Ø, '*'¤Ç¥¿¡¼¥²¥Ã¥ÈºÆÁªÂò, ESC¤ÇÃæÃÇ)? ";
5660 #else
5661                         p = "Direction ('5' for target, '*' to re-target, Escape to cancel)? ";
5662 #endif
5663
5664                 }
5665
5666                 /* Get a command (or Cancel) */
5667                 if (!get_com(p, &command, TRUE)) break;
5668
5669                 if (use_menu)
5670                 {
5671                         if (command == '\r') command = 't';
5672                 }  
5673
5674                 /* Convert various keys to "standard" keys */
5675                 switch (command)
5676                 {
5677                         /* Use current target */
5678                         case 'T':
5679                         case 't':
5680                         case '.':
5681                         case '5':
5682                         case '0':
5683                         {
5684                                 dir = 5;
5685                                 break;
5686                         }
5687
5688                         /* Set new target */
5689                         case '*':
5690                         case ' ':
5691                         case '\r':
5692                         {
5693                                 if (target_set(TARGET_KILL)) dir = 5;
5694                                 break;
5695                         }
5696
5697                         default:
5698                         {
5699                                 /* Look up the direction */
5700                                 dir = get_keymap_dir(command);
5701
5702                                 break;
5703                         }
5704                 }
5705
5706                 /* Verify requested targets */
5707                 if ((dir == 5) && !target_okay()) dir = 0;
5708
5709                 /* Error */
5710                 if (!dir) bell();
5711         }
5712
5713         /* No direction */
5714         if (!dir) return (FALSE);
5715
5716         /* Save the direction */
5717         command_dir = dir;
5718
5719         /* Check for confusion */
5720         if (p_ptr->confused)
5721         {
5722                 /* XXX XXX XXX */
5723                 /* Random direction */
5724                 dir = ddd[randint0(8)];
5725         }
5726
5727         /* Notice confusion */
5728         if (command_dir != dir)
5729         {
5730                 /* Warn the user */
5731 #ifdef JP
5732 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
5733 #else
5734                 msg_print("You are confused.");
5735 #endif
5736
5737         }
5738
5739         /* Save direction */
5740         (*dp) = dir;
5741
5742         /* A "valid" direction was entered */
5743         return (TRUE);
5744 }
5745
5746
5747 /*
5748  * ¥¨¥Í¥ë¥®¡¼¤ÎÁý²ÃÎÌ10d5¤ò®¤¯·×»»¤¹¤ë¤¿¤á¤Î´Ø¿ô
5749  */
5750
5751 #define Go_no_JuuJou 5*5*5*5*5*5*5*5*5*5
5752
5753 s16b gain_energy(void)
5754 {
5755         int i;
5756         s32b energy_result = 10;
5757         s32b tmp;
5758
5759         tmp = randint0(Go_no_JuuJou);
5760
5761         for (i = 0; i < 9; i ++){
5762                 energy_result += tmp % 5;
5763                 tmp /= 5;
5764         }
5765
5766         return (s16b)(energy_result + tmp);
5767 }
5768
5769
5770 /*
5771  * Return bow energy 
5772  */
5773 s16b bow_energy(int sval)
5774 {
5775         int energy = 100;
5776
5777         /* Analyze the launcher */
5778         switch (sval)
5779         {
5780                 /* Sling and ammo */
5781                 case SV_SLING:
5782                 {
5783                         energy = 8000;
5784                         break;
5785                 }
5786
5787                 /* Short Bow and Arrow */
5788                 case SV_SHORT_BOW:
5789                 {
5790                         energy = 10000;
5791                         break;
5792                 }
5793
5794                 /* Long Bow and Arrow */
5795                 case SV_LONG_BOW:
5796                 {
5797                         energy = 10000;
5798                         break;
5799                 }
5800
5801                 /* Bow of irresponsiblity and Arrow */
5802                 case SV_NAMAKE_BOW:
5803                 {
5804                         energy = 7777;
5805                         break;
5806                 }
5807
5808                 /* Light Crossbow and Bolt */
5809                 case SV_LIGHT_XBOW:
5810                 {
5811                         energy = 12000;
5812                         break;
5813                 }
5814
5815                 /* Heavy Crossbow and Bolt */
5816                 case SV_HEAVY_XBOW:
5817                 {
5818                         energy = 13333;
5819                         break;
5820                 }
5821         }
5822
5823         return (energy);
5824 }
5825
5826
5827 /*
5828  * Return bow tmul
5829  */
5830 int bow_tmul(int sval)
5831 {
5832         int tmul = 0;
5833
5834         /* Analyze the launcher */
5835         switch (sval)
5836         {
5837                 /* Sling and ammo */
5838                 case SV_SLING:
5839                 {
5840                         tmul = 2;
5841                         break;
5842                 }
5843
5844                 /* Short Bow and Arrow */
5845                 case SV_SHORT_BOW:
5846                 {
5847                         tmul = 2;
5848                         break;
5849                 }
5850
5851                 /* Long Bow and Arrow */
5852                 case SV_LONG_BOW:
5853                 {
5854                         tmul = 3;
5855                         break;
5856                 }
5857
5858                 /* Bow of irresponsiblity and Arrow */
5859                 case SV_NAMAKE_BOW:
5860                 {
5861                         tmul = 3;
5862                         break;
5863                 }
5864
5865                 /* Light Crossbow and Bolt */
5866                 case SV_LIGHT_XBOW:
5867                 {
5868                         tmul = 3;
5869                         break;
5870                 }
5871
5872                 /* Heavy Crossbow and Bolt */
5873                 case SV_HEAVY_XBOW:
5874                 {
5875                         tmul = 4;
5876                         break;
5877                 }
5878         }
5879
5880         return (tmul);
5881 }
5882
5883 /*
5884  * Return alignment title
5885  */
5886 cptr your_alignment(void)
5887 {
5888 #ifdef JP
5889         if (p_ptr->align > 150) return "ÂçÁ±";
5890         else if (p_ptr->align > 50) return "ÃæÁ±";
5891         else if (p_ptr->align > 10) return "¾®Á±";
5892         else if (p_ptr->align > -11) return "ÃæΩ";
5893         else if (p_ptr->align > -51) return "¾®°­";
5894         else if (p_ptr->align > -151) return "Ãæ°­";
5895         else return "Âç°­";
5896 #else
5897         if (p_ptr->align > 150) return "Lawful";
5898         else if (p_ptr->align > 50) return "Good";
5899         else if (p_ptr->align > 10) return "Neutral Good";
5900         else if (p_ptr->align > -11) return "Neutral";
5901         else if (p_ptr->align > -51) return "Neutral Evil";
5902         else if (p_ptr->align > -151) return "Evil";
5903         else return "Chaotic";
5904 #endif
5905 }
5906
5907
5908 /*
5909  * Return proficiency level of weapons and misc. skills (except riding)
5910  */
5911 int weapon_exp_level(int weapon_exp)
5912 {
5913         if (weapon_exp < WEAPON_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5914         else if (weapon_exp < WEAPON_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5915         else if (weapon_exp < WEAPON_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5916         else if (weapon_exp < WEAPON_EXP_MASTER) return EXP_LEVEL_EXPERT;
5917         else return EXP_LEVEL_MASTER;
5918 }
5919
5920
5921 /*
5922  * Return proficiency level of riding
5923  */
5924 int riding_exp_level(int riding_exp)
5925 {
5926         if (riding_exp < RIDING_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5927         else if (riding_exp < RIDING_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5928         else if (riding_exp < RIDING_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5929         else if (riding_exp < RIDING_EXP_MASTER) return EXP_LEVEL_EXPERT;
5930         else return EXP_LEVEL_MASTER;
5931 }
5932
5933
5934 /*
5935  * Return proficiency level of spells
5936  */
5937 int spell_exp_level(int spell_exp)
5938 {
5939         if (spell_exp < SPELL_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
5940         else if (spell_exp < SPELL_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
5941         else if (spell_exp < SPELL_EXP_EXPERT) return EXP_LEVEL_SKILLED;
5942         else if (spell_exp < SPELL_EXP_MASTER) return EXP_LEVEL_EXPERT;
5943         else return EXP_LEVEL_MASTER;
5944 }