OSDN Git Service

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