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