OSDN Git Service

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