OSDN Git Service

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