OSDN Git Service

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