OSDN Git Service

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