OSDN Git Service

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