OSDN Git Service

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