OSDN Git Service

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