OSDN Git Service

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