OSDN Git Service

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