OSDN Git Service

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