OSDN Git Service

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