OSDN Git Service

5875a607e92c91de6e90435f46fec2e142865499
[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         /* Hack -- handle creeping coins */
1517         coin_type = force_coin;
1518
1519         /* Average dungeon and monster levels */
1520         object_level = (dun_level + r_ptr->level) / 2;
1521
1522         /* Drop some objects */
1523         for (j = 0; j < number; j++)
1524         {
1525                 /* Get local object */
1526                 q_ptr = &forge;
1527
1528                 /* Wipe the object */
1529                 object_wipe(q_ptr);
1530
1531                 /* Make Gold */
1532                 if (do_gold && (!do_item || (randint0(100) < 50)))
1533                 {
1534                         /* Make some gold */
1535                         if (!make_gold(q_ptr)) continue;
1536
1537                         /* XXX XXX XXX */
1538                         dump_gold++;
1539                 }
1540
1541                 /* Make Object */
1542                 else
1543                 {
1544                         /* Make an object */
1545                         if (!make_object(q_ptr, mo_mode)) continue;
1546
1547                         /* XXX XXX XXX */
1548                         dump_item++;
1549                 }
1550
1551                 /* Drop it in the dungeon */
1552                 (void)drop_near(q_ptr, -1, y, x);
1553         }
1554
1555         /* Reset the object level */
1556         object_level = base_level;
1557
1558         /* Reset "coin" type */
1559         coin_type = 0;
1560
1561
1562         /* Take note of any dropped treasure */
1563         if (visible && (dump_item || dump_gold))
1564         {
1565                 /* Take notes on treasure */
1566                 lore_treasure(m_idx, dump_item, dump_gold);
1567         }
1568
1569         /* Only process "Quest Monsters" */
1570         if (!(r_ptr->flags1 & RF1_QUESTOR)) return;
1571         if (p_ptr->inside_battle) return;
1572
1573         /* Winner? */
1574         if ((m_ptr->r_idx == MON_SERPENT) && !cloned)
1575         {
1576                 /* Total winner */
1577                 p_ptr->total_winner = TRUE;
1578
1579                 /* Redraw the "title" */
1580                 p_ptr->redraw |= (PR_TITLE);
1581
1582 #ifdef JP
1583                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¸«»ö¤ËÊѶòÈÚÅܤξ¡Íø¼Ô¤È¤Ê¤Ã¤¿¡ª");
1584 #else
1585                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "become *WINNER* of Hengband finely!");
1586 #endif
1587
1588                 if ((p_ptr->pclass == CLASS_CHAOS_WARRIOR) || (p_ptr->muta2 & MUT2_CHAOS_GIFT))
1589                 {
1590 #ifdef JP
1591                         msg_format("%s¤«¤é¤ÎÀ¼¤¬¶Á¤¤¤¿¡£", chaos_patrons[p_ptr->chaos_patron]);
1592                         msg_print("¡Ø¤è¤¯¤ä¤Ã¤¿¡¢ÄêÌ¿¤Î¼Ô¤è¡ª¡Ù");
1593 #else
1594                         msg_format("The voice of %s booms out:", chaos_patrons[p_ptr->chaos_patron]);
1595                         msg_print("'Thou art donst well, mortal!'");
1596 #endif
1597                 }
1598
1599                 /* Congratulations */
1600 #ifdef JP
1601                 msg_print("*** ¤ª¤á¤Ç¤È¤¦ ***");
1602 #else
1603                 msg_print("*** CONGRATULATIONS ***");
1604 #endif
1605
1606 #ifdef JP
1607                 msg_print("¤¢¤Ê¤¿¤Ï¥²¡¼¥à¤ò¥³¥ó¥×¥ê¡¼¥È¤·¤Þ¤·¤¿¡£");
1608 #else
1609                 msg_print("You have won the game!");
1610 #endif
1611
1612 #ifdef JP
1613                 msg_print("½àÈ÷¤¬À°¤Ã¤¿¤é°úÂà(¼«»¦¥³¥Þ¥ó¥É)¤·¤Æ¤â·ë¹½¤Ç¤¹¡£");
1614 #else
1615                 msg_print("You may retire (commit suicide) when you are ready.");
1616 #endif
1617         }
1618 }
1619
1620 /*
1621  * Modify the physical damage done to the monster.
1622  * (for example when it's invulnerable or shielded)
1623  *
1624  * ToDo: Accept a damage-type to calculate the modified damage from
1625  * things like fire, frost, lightning, poison, ... attacks.
1626  *
1627  * "type" is not yet used and should be 0.
1628  */
1629 int mon_damage_mod(monster_type *m_ptr, int dam, bool is_psy_spear)
1630 {
1631         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1632
1633         if ((r_ptr->flagsr & RFR_RES_ALL) && dam > 0)
1634         {
1635                 dam /= 100;
1636                 if ((dam == 0) && one_in_(3)) dam = 1;
1637         }
1638
1639         if (MON_INVULNER(m_ptr))
1640         {
1641                 if (is_psy_spear)
1642                 {
1643                         if (!p_ptr->blind && is_seen(m_ptr))
1644                         {
1645 #ifdef JP
1646                                 msg_print("¥Ð¥ê¥¢¤òÀÚ¤êÎö¤¤¤¿¡ª");
1647 #else
1648                                 msg_print("The barrier is penetrated!");
1649 #endif
1650                         }
1651                 }
1652                 else if (!one_in_(PENETRATE_INVULNERABILITY))
1653                 {
1654                         return (0);
1655                 }
1656         }
1657         return (dam);
1658 }
1659
1660
1661 /*
1662  * Calculate experience point to be get
1663  *
1664  * Even the 64 bit operation is not big enough to avoid overflaw
1665  * unless we carefully choose orders of multiplication and division.
1666  *
1667  * Get the coefficient first, and multiply (potentially huge) base
1668  * experience point of a monster later.
1669  */
1670 static void get_exp_from_mon(int dam, monster_type *m_ptr)
1671 {
1672         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1673
1674         s32b new_exp;
1675         u32b new_exp_frac;
1676         s32b div_h;
1677         u32b div_l;
1678
1679         if (!m_ptr->r_idx) return;
1680         if (is_pet(m_ptr) || p_ptr->inside_battle) return;
1681
1682         /*
1683          * - Ratio of monster's level to player's level effects
1684          * - Varying speed effects
1685          * - Get a fraction in proportion of damage point
1686          */
1687         new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * dam;
1688         new_exp_frac = 0;
1689         div_h = 0L;
1690         div_l = (p_ptr->max_plv+2) * SPEED_TO_ENERGY(r_ptr->speed);
1691
1692         /* Use (average maxhp * 2) as a denominator */
1693         if (!(r_ptr->flags1 & RF1_FORCE_MAXHP))
1694                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * (r_ptr->hside + 1));
1695         else
1696                 s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * r_ptr->hside * 2);
1697
1698         /* Special penalty in the wilderness */
1699         if (!dun_level && (!(r_ptr->flags8 & RF8_WILD_ONLY) || !(r_ptr->flags1 & RF1_UNIQUE)))
1700                 s64b_mul(&div_h, &div_l, 0, 5);
1701
1702         /* Do division first to prevent overflaw */
1703         s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
1704
1705         /* Special penalty for mutiply-monster */
1706         if ((r_ptr->flags2 & RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN))
1707         {
1708                 int monnum_penarty = r_ptr->r_akills / 400;
1709                 if (monnum_penarty > 8) monnum_penarty = 8;
1710
1711                 while (monnum_penarty--)
1712                 {
1713                         /* Divide by 4 */
1714                         s64b_RSHIFT(new_exp, new_exp_frac, 2);
1715                 }
1716         }
1717
1718         /* Finally multiply base experience point of the monster */
1719         s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
1720
1721         /* Gain experience */
1722         gain_exp_64(new_exp, new_exp_frac);
1723 }
1724
1725
1726 /*
1727  * Decreases monsters hit points, handling monster death.
1728  *
1729  * We return TRUE if the monster has been killed (and deleted).
1730  *
1731  * We announce monster death (using an optional "death message"
1732  * if given, and a otherwise a generic killed/destroyed message).
1733  *
1734  * Only "physical attacks" can induce the "You have slain" message.
1735  * Missile and Spell attacks will induce the "dies" message, or
1736  * various "specialized" messages.  Note that "You have destroyed"
1737  * and "is destroyed" are synonyms for "You have slain" and "dies".
1738  *
1739  * Hack -- unseen monsters yield "You have killed it." message.
1740  *
1741  * Added fear (DGK) and check whether to print fear messages -CWS
1742  *
1743  * Made name, sex, and capitalization generic -BEN-
1744  *
1745  * As always, the "ghost" processing is a total hack.
1746  *
1747  * Hack -- we "delay" fear messages by passing around a "fear" flag.
1748  *
1749  * XXX XXX XXX Consider decreasing monster experience over time, say,
1750  * by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))"
1751  * instead of simply "(m_exp * m_lev) / (p_lev)", to make the first
1752  * monster worth more than subsequent monsters.  This would also need
1753  * to induce changes in the monster recall code.
1754  */
1755 bool mon_take_hit(int m_idx, int dam, bool *fear, cptr note)
1756 {
1757         monster_type    *m_ptr = &m_list[m_idx];
1758         monster_race    *r_ptr = &r_info[m_ptr->r_idx];
1759
1760         monster_type    exp_mon;
1761
1762         /* Innocent until proven otherwise */
1763         bool        innocent = TRUE, thief = FALSE;
1764         int         i;
1765         int         expdam;
1766
1767         COPY(&exp_mon, m_ptr, monster_type);
1768         if (!(r_ptr->flags7 & RF7_KILL_EXP))
1769         {
1770                 expdam = (m_ptr->hp > dam) ? dam : m_ptr->hp;
1771                 if (r_ptr->flags6 & RF6_HEAL) expdam = (expdam+1) * 2 / 3;
1772
1773                 get_exp_from_mon(expdam, &exp_mon);
1774
1775                 /* Genocided by chaos patron */
1776                 if (!m_ptr->r_idx) m_idx = 0;
1777         }
1778
1779         /* Redraw (later) if needed */
1780         if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1781         if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1782
1783         /* Wake it up */
1784         (void)set_monster_csleep(m_idx, 0);
1785
1786         /* Hack - Cancel any special player stealth magics. -LM- */
1787         if (p_ptr->special_defense & NINJA_S_STEALTH)
1788         {
1789                 set_superstealth(FALSE);
1790         }
1791
1792         /* Genocided by chaos patron */
1793         if (!m_idx) return TRUE;
1794
1795         /* Hurt it */
1796         m_ptr->hp -= dam;
1797
1798         /* It is dead now */
1799         if (m_ptr->hp < 0)
1800         {
1801                 char m_name[80];
1802
1803                 if (r_info[m_ptr->r_idx].flags7 & RF7_TANUKI)
1804                 {
1805                         /* You might have unmasked Tanuki first time */
1806                         r_ptr = &r_info[m_ptr->r_idx];
1807                         m_ptr->ap_r_idx = m_ptr->r_idx;
1808                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1809                 }
1810
1811                 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
1812                 {
1813                         /* You might have unmasked Chameleon first time */
1814                         r_ptr = real_r_ptr(m_ptr);
1815                         if (r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
1816                 }
1817
1818                 if (!(m_ptr->smart & SM_CLONED))
1819                 {
1820                         /* When the player kills a Unique, it stays dead */
1821                         if (r_ptr->flags1 & RF1_UNIQUE)
1822                         {
1823                                 r_ptr->max_num = 0;
1824
1825                                 /* Mega-Hack -- Banor & Lupart */
1826                                 if ((m_ptr->r_idx == MON_BANOR) || (m_ptr->r_idx == MON_LUPART))
1827                                 {
1828                                         r_info[MON_BANORLUPART].max_num = 0;
1829                                         r_info[MON_BANORLUPART].r_pkills++;
1830                                         r_info[MON_BANORLUPART].r_akills++;
1831                                         if (r_info[MON_BANORLUPART].r_tkills < MAX_SHORT) r_info[MON_BANORLUPART].r_tkills++;
1832                                 }
1833                                 else if (m_ptr->r_idx == MON_BANORLUPART)
1834                                 {
1835                                         r_info[MON_BANOR].max_num = 0;
1836                                         r_info[MON_BANOR].r_pkills++;
1837                                         r_info[MON_BANOR].r_akills++;
1838                                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
1839                                         r_info[MON_LUPART].max_num = 0;
1840                                         r_info[MON_LUPART].r_pkills++;
1841                                         r_info[MON_LUPART].r_akills++;
1842                                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
1843                                 }
1844                         }
1845
1846                         /* When the player kills a Nazgul, it stays dead */
1847                         else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num--;
1848                 }
1849
1850                 /* Count all monsters killed */
1851                 if (r_ptr->r_akills < MAX_SHORT) r_ptr->r_akills++;
1852
1853                 /* Recall even invisible uniques or winners */
1854                 if ((m_ptr->ml && !p_ptr->image) || (r_ptr->flags1 & RF1_UNIQUE))
1855                 {
1856                         /* Count kills this life */
1857                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) r_info[MON_KAGE].r_pkills++;
1858                         else if (r_ptr->r_pkills < MAX_SHORT) r_ptr->r_pkills++;
1859
1860                         /* Count kills in all lives */
1861                         if ((m_ptr->mflag2 & MFLAG2_KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) r_info[MON_KAGE].r_tkills++;
1862                         else if (r_ptr->r_tkills < MAX_SHORT) r_ptr->r_tkills++;
1863
1864                         /* Hack -- Auto-recall */
1865                         monster_race_track(m_ptr->ap_r_idx);
1866                 }
1867
1868                 /* Extract monster name */
1869                 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
1870
1871                 /* Don't kill Amberites */
1872                 if ((r_ptr->flags3 & RF3_AMBERITE) && one_in_(2))
1873                 {
1874                         int curses = 1 + randint1(3);
1875                         bool stop_ty = FALSE;
1876                         int count = 0;
1877
1878 #ifdef JP
1879 msg_format("%^s¤Ï¶²¤í¤·¤¤·ì¤Î¼ö¤¤¤ò¤¢¤Ê¤¿¤Ë¤«¤±¤¿¡ª", m_name);
1880 #else
1881                         msg_format("%^s puts a terrible blood curse on you!", m_name);
1882 #endif
1883
1884                         curse_equipment(100, 50);
1885
1886                         do
1887                         {
1888                                 stop_ty = activate_ty_curse(stop_ty, &count);
1889                         }
1890                         while (--curses);
1891                 }
1892
1893                 if (r_ptr->flags2 & RF2_CAN_SPEAK)
1894                 {
1895                         char line_got[1024];
1896
1897                         /* Dump a message */
1898 #ifdef JP
1899                         if (!get_rnd_line("mondeath_j.txt", m_ptr->r_idx, line_got))
1900 #else
1901                         if (!get_rnd_line("mondeath.txt", m_ptr->r_idx, line_got))
1902 #endif
1903
1904                                 msg_format("%^s %s", m_name, line_got);
1905
1906 #ifdef WORLD_SCORE
1907                         if (m_ptr->r_idx == MON_SERPENT)
1908                         {
1909                                 /* Make screen dump */
1910                                 screen_dump = make_screen_dump();
1911                         }
1912 #endif
1913                 }
1914
1915                 if (!(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1916                 {
1917                         if (!dun_level && !ambush_flag && !p_ptr->inside_arena)
1918                         {
1919                                 chg_virtue(V_VALOUR, -1);
1920                         }
1921                         else if (r_ptr->level > dun_level)
1922                         {
1923                                 if (randint1(10) <= (r_ptr->level - dun_level))
1924                                         chg_virtue(V_VALOUR, 1);
1925                         }
1926                         if (r_ptr->level > 60)
1927                         {
1928                                 chg_virtue(V_VALOUR, 1);
1929                         }
1930                         if (r_ptr->level >= 2 * (p_ptr->lev+1))
1931                                 chg_virtue(V_VALOUR, 2);
1932                 }
1933
1934                 if (r_ptr->flags1 & RF1_UNIQUE)
1935                 {
1936                         if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)) chg_virtue(V_HARMONY, 2);
1937
1938                         if (r_ptr->flags3 & RF3_GOOD)
1939                         {
1940                                 chg_virtue(V_UNLIFE, 2);
1941                                 chg_virtue(V_VITALITY, -2);
1942                         }
1943
1944                         if (one_in_(3)) chg_virtue(V_INDIVIDUALISM, -1);
1945                 }
1946
1947                 if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER)
1948                 {
1949                         chg_virtue(V_COMPASSION, -1);
1950                 }
1951
1952                 if ((r_ptr->flags3 & RF3_GOOD) &&
1953                         ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100)))
1954                         chg_virtue(V_UNLIFE, 1);
1955
1956                 if (r_ptr->d_char == 'A')
1957                 {
1958                         if (r_ptr->flags1 & RF1_UNIQUE)
1959                                 chg_virtue(V_FAITH, -2);
1960                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1961                         {
1962                                 if (r_ptr->flags3 & RF3_GOOD) chg_virtue(V_FAITH, -1);
1963                                 else chg_virtue(V_FAITH, 1);
1964                         }
1965                 }
1966                 else if (r_ptr->flags3 & RF3_DEMON)
1967                 {
1968                         if (r_ptr->flags1 & RF1_UNIQUE)
1969                                 chg_virtue(V_FAITH, 2);
1970                         else if ((r_ptr->level) / 10 + (3 * dun_level) >= randint1(100))
1971                                 chg_virtue(V_FAITH, 1);
1972                 }
1973
1974                 if ((r_ptr->flags3 & RF3_UNDEAD) && (r_ptr->flags1 & RF1_UNIQUE))
1975                         chg_virtue(V_VITALITY, 2);
1976
1977                 if (r_ptr->r_deaths)
1978                 {
1979                         if (r_ptr->flags1 & RF1_UNIQUE)
1980                         {
1981                                 chg_virtue(V_HONOUR, 10);
1982                         }
1983                         else if ((r_ptr->level) / 10 + (2 * dun_level) >= randint1(100))
1984                         {
1985                                 chg_virtue(V_HONOUR, 1);
1986                         }
1987                 }
1988                 if ((r_ptr->flags2 & RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10))
1989                 {
1990                         chg_virtue(V_VALOUR, -1);
1991                 }
1992
1993                 for (i = 0; i < 4; i++)
1994                 {
1995                         if (r_ptr->blow[i].d_dice != 0) innocent = FALSE; /* Murderer! */
1996
1997                         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM)
1998                                 || (r_ptr->blow[i].effect == RBE_EAT_GOLD))
1999
2000                                 thief = TRUE; /* Thief! */
2001                 }
2002
2003                 /* The new law says it is illegal to live in the dungeon */
2004                 if (r_ptr->level != 0) innocent = FALSE;
2005
2006                 if (thief)
2007                 {
2008                         if (r_ptr->flags1 & RF1_UNIQUE)
2009                                 chg_virtue(V_JUSTICE, 3);
2010                         else if (1+((r_ptr->level) / 10 + (2 * dun_level))
2011                                 >= randint1(100))
2012                                 chg_virtue(V_JUSTICE, 1);
2013                 }
2014                 else if (innocent)
2015                 {
2016                         chg_virtue (V_JUSTICE, -1);
2017                 }
2018
2019                 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)))
2020                 {
2021                         if (one_in_(4)) chg_virtue(V_NATURE, -1);
2022                 }
2023
2024                 if ((r_ptr->flags1 & RF1_UNIQUE) && record_destroy_uniq)
2025                 {
2026                         char note_buf[160];
2027 #ifdef JP
2028                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? "(¥¯¥í¡¼¥ó)" : "");
2029 #else
2030                         sprintf(note_buf, "%s%s", r_name + r_ptr->name, (m_ptr->smart & SM_CLONED) ? "(Clone)" : "");
2031 #endif
2032                         do_cmd_write_nikki(NIKKI_UNIQUE, 0, note_buf);
2033                 }
2034
2035                 /* Make a sound */
2036                 sound(SOUND_KILL);
2037
2038                 /* Death by Missile/Spell attack */
2039                 if (note)
2040                 {
2041                         msg_format("%^s%s", m_name, note);
2042                 }
2043
2044                 /* Death by physical attack -- invisible monster */
2045                 else if (!m_ptr->ml)
2046                 {
2047 #ifdef JP
2048                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2049                                 msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤ò»¦¤·¤¿¡£", m_name);
2050                         else
2051 msg_format("%s¤ò»¦¤·¤¿¡£", m_name);
2052 #else
2053                                 msg_format("You have killed %s.", m_name);
2054 #endif
2055
2056                 }
2057
2058                 /* Death by Physical attack -- non-living monster */
2059                 else if (!monster_living(r_ptr))
2060                 {
2061                         int i;
2062                         bool explode = FALSE;
2063
2064                         for (i = 0; i < 4; i++)
2065                         {
2066                                 if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE;
2067                         }
2068
2069                         /* Special note at death */
2070                         if (explode)
2071 #ifdef JP
2072                                 msg_format("%s¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_name);
2073 #else
2074                                 msg_format("%^s explodes into tiny shreds.", m_name);
2075 #endif
2076                         else
2077                         {
2078 #ifdef JP
2079                                 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2080                                         msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤òÅݤ·¤¿¡£", m_name);
2081                                 else
2082 msg_format("%s¤òÅݤ·¤¿¡£", m_name);
2083 #else
2084                                 msg_format("You have destroyed %s.", m_name);
2085 #endif
2086                         }
2087                 }
2088
2089                 /* Death by Physical attack -- living monster */
2090                 else
2091                 {
2092 #ifdef JP
2093                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
2094                                 msg_format("¤»¤Ã¤«¤¯¤À¤«¤é%s¤òÁò¤êµî¤Ã¤¿¡£", m_name);
2095                         else
2096 msg_format("%s¤òÁò¤êµî¤Ã¤¿¡£", m_name);
2097 #else
2098                                 msg_format("You have slain %s.", m_name);
2099 #endif
2100
2101                 }
2102                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(m_ptr->smart & SM_CLONED) && !vanilla_town)
2103                 {
2104                         for (i = 0; i < MAX_KUBI; i++)
2105                         {
2106                                 if ((kubi_r_idx[i] == m_ptr->r_idx) && !(m_ptr->mflag2 & MFLAG2_CHAMELEON))
2107                                 {
2108 #ifdef JP
2109 msg_format("%s¤Î¼ó¤Ë¤Ï¾Þ¶â¤¬¤«¤«¤Ã¤Æ¤¤¤ë¡£", m_name);
2110 #else
2111                                         msg_format("There is a price on %s's head.", m_name);
2112 #endif
2113                                         break;
2114                                 }
2115                         }
2116                 }
2117
2118                 /* Generate treasure */
2119                 monster_death(m_idx, TRUE);
2120
2121                 /* Mega hack : replace IKETA to BIKETAL */
2122                 if ((m_ptr->r_idx == MON_IKETA) &&
2123                     !(p_ptr->inside_arena || p_ptr->inside_battle))
2124                 {
2125                         int dummy_y = m_ptr->fy;
2126                         int dummy_x = m_ptr->fx;
2127                         u32b mode = 0L;
2128
2129                         if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
2130
2131                         /* Delete the monster */
2132                         delete_monster_idx(m_idx);
2133
2134                         if (summon_named_creature(0, dummy_y, dummy_x, MON_BIKETAL, mode))
2135                         {
2136 #ifdef JP
2137                                 msg_print("¡Ö¥Ï¥¡¥Ã¥Ï¥Ã¥Ï¥Ã¥Ï¡ª¡ª»ä¤¬¥Ð¥¤¥±¥¿¥ë¤À¡ª¡ª¡×");
2138 #else
2139                                 msg_print("Uwa-hahaha!  *I* am Biketal!");
2140 #endif
2141                         }
2142                 }
2143                 else
2144                 {
2145                         /* Delete the monster */
2146                         delete_monster_idx(m_idx);
2147                 }
2148
2149                 /* Prevent bug of chaos patron's reward */
2150                 if (r_ptr->flags7 & RF7_KILL_EXP)
2151                         get_exp_from_mon((long)exp_mon.max_maxhp*2, &exp_mon);
2152                 else
2153                         get_exp_from_mon(((long)exp_mon.max_maxhp+1L) * 9L / 10L, &exp_mon);
2154
2155                 /* Not afraid */
2156                 (*fear) = FALSE;
2157
2158                 /* Monster is dead */
2159                 return (TRUE);
2160         }
2161
2162
2163 #ifdef ALLOW_FEAR
2164
2165         /* Mega-Hack -- Pain cancels fear */
2166         if (MON_MONFEAR(m_ptr) && (dam > 0))
2167         {
2168                 /* Cure fear */
2169                 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam)))
2170                 {
2171                         /* No more fear */
2172                         (*fear) = FALSE;
2173                 }
2174         }
2175
2176         /* Sometimes a monster gets scared by damage */
2177         if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & (RF3_NO_FEAR)))
2178         {
2179                 /* Percentage of fully healthy */
2180                 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
2181
2182                 /*
2183                  * Run (sometimes) if at 10% or less of max hit points,
2184                  * or (usually) when hit for half its current hit points
2185                  */
2186                 if ((randint1(10) >= percentage) ||
2187                     ((dam >= m_ptr->hp) && (randint0(100) < 80)))
2188                 {
2189                         /* Hack -- note fear */
2190                         (*fear) = TRUE;
2191
2192                         /* XXX XXX XXX Hack -- Add some timed fear */
2193                         (void)set_monster_monfear(m_idx, (randint1(10) +
2194                                           (((dam >= m_ptr->hp) && (percentage > 7)) ?
2195                                            20 : ((11 - percentage) * 5))));
2196                 }
2197         }
2198
2199 #endif
2200
2201 #if 0
2202         if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
2203         {
2204                 char m_name[80];
2205
2206                 /* Extract monster name */
2207                 monster_desc(m_name, m_ptr, 0);
2208
2209                 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
2210                 if (rakuba((dam > 200) ? 200 : dam, FALSE))
2211                 {
2212 #ifdef JP
2213 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
2214 #else
2215                                 msg_format("%^s has thrown you off!", m_name);
2216 #endif
2217                 }
2218         }
2219 #endif
2220
2221         /* Not dead yet */
2222         return (FALSE);
2223 }
2224
2225
2226 /*
2227  * Get term size and calculate screen size
2228  */
2229 void get_screen_size(int *wid_p, int *hgt_p)
2230 {
2231         Term_get_size(wid_p, hgt_p);
2232         *hgt_p -= ROW_MAP + 2;
2233         *wid_p -= COL_MAP + 2;
2234         if (use_bigtile) *wid_p /= 2;
2235 }
2236
2237
2238 /*
2239  * Calculates current boundaries
2240  * Called below and from "do_cmd_locate()".
2241  */
2242 void panel_bounds_center(void)
2243 {
2244         int wid, hgt;
2245
2246         /* Get size */
2247         get_screen_size(&wid, &hgt);
2248
2249         panel_row_max = panel_row_min + hgt - 1;
2250         panel_row_prt = panel_row_min - 1;
2251         panel_col_max = panel_col_min + wid - 1;
2252         panel_col_prt = panel_col_min - 13;
2253 }
2254
2255
2256 /*
2257  * Map resizing whenever the main term changes size
2258  */
2259 void resize_map(void)
2260 {
2261         /* Only if the dungeon exists */
2262         if (!character_dungeon) return;
2263         
2264         /* Mega-Hack -- no panel yet */
2265         panel_row_max = 0;
2266         panel_col_max = 0;
2267
2268         /* Reset the panels */
2269         panel_row_min = cur_hgt;
2270         panel_col_min = cur_wid;
2271                                 
2272         verify_panel();
2273
2274         /* Update stuff */
2275         p_ptr->update |= (PU_TORCH | PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
2276
2277         /* Forget lite/view */
2278         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
2279
2280         /* Update lite/view */
2281         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
2282
2283         /* Update monsters */
2284         p_ptr->update |= (PU_MONSTERS);
2285
2286         /* Redraw everything */
2287         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
2288
2289         /* Hack -- update */
2290         handle_stuff();
2291         
2292         /* Redraw */
2293         Term_redraw();
2294
2295         /*
2296          * Waiting command;
2297          * Place the cursor on the player
2298          */
2299         if (can_save) move_cursor_relative(py, px);
2300
2301         /* Refresh */
2302         Term_fresh();
2303 }
2304
2305 /*
2306  * Redraw a term when it is resized
2307  */
2308 void redraw_window(void)
2309 {
2310         /* Only if the dungeon exists */
2311         if (!character_dungeon) return;
2312
2313         /* Window stuff */
2314         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
2315
2316         /* Window stuff */
2317         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
2318
2319         /* Hack -- update */
2320         handle_stuff();
2321
2322         /* Redraw */
2323         Term_redraw();
2324 }
2325
2326
2327 /*
2328  * Handle a request to change the current panel
2329  *
2330  * Return TRUE if the panel was changed.
2331  *
2332  * Also used in do_cmd_locate
2333  */
2334 bool change_panel(int dy, int dx)
2335 {
2336         int y, x;
2337         int wid, hgt;
2338
2339         /* Get size */
2340         get_screen_size(&wid, &hgt);
2341
2342         /* Apply the motion */
2343         y = panel_row_min + dy * hgt / 2;
2344         x = panel_col_min + dx * wid / 2;
2345
2346         /* Verify the row */
2347         if (y > cur_hgt - hgt) y = cur_hgt - hgt;
2348         if (y < 0) y = 0;
2349
2350         /* Verify the col */
2351         if (x > cur_wid - wid) x = cur_wid - wid;
2352         if (x < 0) x = 0;
2353
2354         /* Handle "changes" */
2355         if ((y != panel_row_min) || (x != panel_col_min))
2356         {
2357                 /* Save the new panel info */
2358                 panel_row_min = y;
2359                 panel_col_min = x;
2360
2361                 /* Recalculate the boundaries */
2362                 panel_bounds_center();
2363
2364                 /* Update stuff */
2365                 p_ptr->update |= (PU_MONSTERS);
2366
2367                 /* Redraw map */
2368                 p_ptr->redraw |= (PR_MAP);
2369
2370                 /* Handle stuff */
2371                 handle_stuff();
2372
2373                 /* Success */
2374                 return (TRUE);
2375         }
2376
2377         /* No change */
2378         return (FALSE);
2379 }
2380
2381
2382 /*
2383  * Given an row (y) and col (x), this routine detects when a move
2384  * off the screen has occurred and figures new borders. -RAK-
2385  *
2386  * "Update" forces a "full update" to take place.
2387  *
2388  * The map is reprinted if necessary, and "TRUE" is returned.
2389  */
2390 void verify_panel(void)
2391 {
2392         int y = py;
2393         int x = px;
2394         int wid, hgt;
2395
2396         int prow_min;
2397         int pcol_min;
2398         int max_prow_min;
2399         int max_pcol_min;
2400
2401         /* Get size */
2402         get_screen_size(&wid, &hgt);
2403
2404         max_prow_min = cur_hgt - hgt;
2405         max_pcol_min = cur_wid - wid;
2406
2407         /* Bounds checking */
2408         if (max_prow_min < 0) max_prow_min = 0;
2409         if (max_pcol_min < 0) max_pcol_min = 0;
2410
2411                 /* Center on player */
2412         if (center_player && (center_running || !running))
2413         {
2414                 /* Center vertically */
2415                 prow_min = y - hgt / 2;
2416                 if (prow_min < 0) prow_min = 0;
2417                 else if (prow_min > max_prow_min) prow_min = max_prow_min;
2418
2419                 /* Center horizontally */
2420                 pcol_min = x - wid / 2;
2421                 if (pcol_min < 0) pcol_min = 0;
2422                 else if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2423         }
2424         else
2425         {
2426                 prow_min = panel_row_min;
2427                 pcol_min = panel_col_min;
2428
2429                 /* Scroll screen when 2 grids from top/bottom edge */
2430                 if (y > panel_row_max - 2)
2431                 {
2432                         while (y > prow_min + hgt-1 - 2)
2433                         {
2434                                 prow_min += (hgt / 2);
2435                         }
2436                 }
2437
2438                 if (y < panel_row_min + 2)
2439                 {
2440                         while (y < prow_min + 2)
2441                         {
2442                                 prow_min -= (hgt / 2);
2443                         }
2444                 }
2445
2446                 if (prow_min > max_prow_min) prow_min = max_prow_min;
2447                 if (prow_min < 0) prow_min = 0;
2448
2449                 /* Scroll screen when 4 grids from left/right edge */
2450                 if (x > panel_col_max - 4)
2451                 {
2452                         while (x > pcol_min + wid-1 - 4)
2453                         {
2454                                 pcol_min += (wid / 2);
2455                         }
2456                 }
2457                 
2458                 if (x < panel_col_min + 4)
2459                 {
2460                         while (x < pcol_min + 4)
2461                         {
2462                                 pcol_min -= (wid / 2);
2463                         }
2464                 }
2465
2466                 if (pcol_min > max_pcol_min) pcol_min = max_pcol_min;
2467                 if (pcol_min < 0) pcol_min = 0;
2468         }
2469
2470         /* Check for "no change" */
2471         if ((prow_min == panel_row_min) && (pcol_min == panel_col_min)) return;
2472
2473         /* Save the new panel info */
2474         panel_row_min = prow_min;
2475         panel_col_min = pcol_min;
2476
2477         /* Hack -- optional disturb on "panel change" */
2478         if (disturb_panel && !center_player) disturb(0, 0);
2479
2480         /* Recalculate the boundaries */
2481         panel_bounds_center();
2482
2483         /* Update stuff */
2484         p_ptr->update |= (PU_MONSTERS);
2485
2486         /* Redraw map */
2487         p_ptr->redraw |= (PR_MAP);
2488
2489         /* Window stuff */
2490         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2491 }
2492
2493
2494 /*
2495  * Monster health description
2496  */
2497 cptr look_mon_desc(monster_type *m_ptr, u32b mode)
2498 {
2499         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2500         bool         living;
2501         int          perc;
2502         cptr desc;
2503         cptr attitude;
2504         cptr clone;
2505
2506         /* Determine if the monster is "living" */
2507         living = monster_living(ap_r_ptr);
2508
2509         /* Calculate a health "percentage" */
2510         perc = 100L * m_ptr->hp / m_ptr->maxhp;
2511
2512         /* Healthy monsters */
2513         if (m_ptr->hp >= m_ptr->maxhp)
2514         {
2515                 /* No damage */
2516 #ifdef JP
2517                 desc = living ? "̵½ý" : "̵¥À¥á¡¼¥¸";
2518 #else
2519                 desc = living ? "unhurt" : "undamaged";
2520 #endif
2521
2522         }
2523
2524         else if (perc >= 60)
2525         {
2526 #ifdef JP
2527                 desc = living ? "·Ú½ý" : "¾®¥À¥á¡¼¥¸";
2528 #else
2529                 desc = living ? "somewhat wounded" : "somewhat damaged";
2530 #endif
2531
2532         }
2533
2534         else if (perc >= 25)
2535         {
2536 #ifdef JP
2537                 desc = living ? "Éé½ý" : "Ãæ¥À¥á¡¼¥¸";
2538 #else
2539                 desc = living ? "wounded" : "damaged";
2540 #endif
2541
2542         }
2543
2544         else if (perc >= 10)
2545         {
2546 #ifdef JP
2547                 desc = living ? "½Å½ý" : "Âç¥À¥á¡¼¥¸";
2548 #else
2549                 desc = living ? "badly wounded" : "badly damaged";
2550 #endif
2551
2552         }
2553
2554         else 
2555         {
2556 #ifdef JP
2557                 desc = living ? "Ⱦ»àȾÀ¸" : "Åݤ줫¤±";
2558 #else
2559                 desc = living ? "almost dead" : "almost destroyed";
2560 #endif
2561         }
2562
2563
2564         /* Need attitude information? */
2565         if (!(mode & 0x01))
2566         {
2567                 /* Full information is not needed */
2568                 attitude = "";
2569         }
2570         else if (is_pet(m_ptr))
2571         {
2572 #ifdef JP
2573                 attitude = ", ¥Ú¥Ã¥È";
2574 #else
2575                 attitude = ", pet";
2576 #endif
2577         }
2578         else if (is_friendly(m_ptr))
2579         {
2580 #ifdef JP
2581                 attitude = ", Í§¹¥Åª";
2582 #else
2583                 attitude = ", friendly";
2584 #endif
2585         }
2586         else
2587         {
2588 #ifdef JP
2589                 attitude = "";
2590 #else
2591                 attitude = "";
2592 #endif
2593         }
2594
2595
2596         /* Clone monster? */
2597         if (m_ptr->smart & SM_CLONED)
2598         {
2599                 clone = ", clone";
2600         }
2601         else
2602         {
2603                 clone = "";
2604         }
2605
2606         /* Display monster's level --- idea borrowed from ToME */
2607         if (ap_r_ptr->r_tkills && !(m_ptr->mflag2 & MFLAG2_KAGE))
2608         {
2609 #ifdef JP
2610                 return format("¥ì¥Ù¥ë%d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2611 #else
2612                 return format("Level %d, %s%s%s", ap_r_ptr->level, desc, attitude, clone);
2613 #endif
2614         }
2615         else 
2616         {
2617 #ifdef JP
2618                 return format("¥ì¥Ù¥ë???, %s%s%s", desc, attitude, clone);
2619 #else
2620                 return format("Level ???, %s%s%s", desc, attitude, clone);
2621 #endif
2622         }
2623 }
2624
2625
2626
2627 /*
2628  * Angband sorting algorithm -- quick sort in place
2629  *
2630  * Note that the details of the data we are sorting is hidden,
2631  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2632  * function hooks to interact with the data, which is given as
2633  * two pointers, and which may have any user-defined form.
2634  */
2635 void ang_sort_aux(vptr u, vptr v, int p, int q)
2636 {
2637         int z, a, b;
2638
2639         /* Done sort */
2640         if (p >= q) return;
2641
2642         /* Pivot */
2643         z = p;
2644
2645         /* Begin */
2646         a = p;
2647         b = q;
2648
2649         /* Partition */
2650         while (TRUE)
2651         {
2652                 /* Slide i2 */
2653                 while (!(*ang_sort_comp)(u, v, b, z)) b--;
2654
2655                 /* Slide i1 */
2656                 while (!(*ang_sort_comp)(u, v, z, a)) a++;
2657
2658                 /* Done partition */
2659                 if (a >= b) break;
2660
2661                 /* Swap */
2662                 (*ang_sort_swap)(u, v, a, b);
2663
2664                 /* Advance */
2665                 a++, b--;
2666         }
2667
2668         /* Recurse left side */
2669         ang_sort_aux(u, v, p, b);
2670
2671         /* Recurse right side */
2672         ang_sort_aux(u, v, b+1, q);
2673 }
2674
2675
2676 /*
2677  * Angband sorting algorithm -- quick sort in place
2678  *
2679  * Note that the details of the data we are sorting is hidden,
2680  * and we rely on the "ang_sort_comp()" and "ang_sort_swap()"
2681  * function hooks to interact with the data, which is given as
2682  * two pointers, and which may have any user-defined form.
2683  */
2684 void ang_sort(vptr u, vptr v, int n)
2685 {
2686         /* Sort the array */
2687         ang_sort_aux(u, v, 0, n-1);
2688 }
2689
2690
2691
2692 /*** Targeting Code ***/
2693
2694
2695 /*
2696  * Determine is a monster makes a reasonable target
2697  *
2698  * The concept of "targeting" was stolen from "Morgul" (?)
2699  *
2700  * The player can target any location, or any "target-able" monster.
2701  *
2702  * Currently, a monster is "target_able" if it is visible, and if
2703  * the player can hit it with a projection, and the player is not
2704  * hallucinating.  This allows use of "use closest target" macros.
2705  *
2706  * Future versions may restrict the ability to target "trappers"
2707  * and "mimics", but the semantics is a little bit weird.
2708  */
2709 bool target_able(int m_idx)
2710 {
2711         monster_type *m_ptr = &m_list[m_idx];
2712
2713         /* Monster must be alive */
2714         if (!m_ptr->r_idx) return (FALSE);
2715
2716         /* Hack -- no targeting hallucinations */
2717         if (p_ptr->image) return (FALSE);
2718
2719         /* Monster must be visible */
2720         if (!m_ptr->ml) return (FALSE);
2721
2722         if (p_ptr->riding && (p_ptr->riding == m_idx)) return (TRUE);
2723
2724         /* Monster must be projectable */
2725         if (!projectable(py, px, m_ptr->fy, m_ptr->fx)) return (FALSE);
2726
2727         /* XXX XXX XXX Hack -- Never target trappers */
2728         /* if (CLEAR_ATTR && (CLEAR_CHAR)) return (FALSE); */
2729
2730         /* Assume okay */
2731         return (TRUE);
2732 }
2733
2734
2735
2736
2737 /*
2738  * Update (if necessary) and verify (if possible) the target.
2739  *
2740  * We return TRUE if the target is "okay" and FALSE otherwise.
2741  */
2742 bool target_okay(void)
2743 {
2744         /* Accept stationary targets */
2745         if (target_who < 0) return (TRUE);
2746
2747         /* Check moving targets */
2748         if (target_who > 0)
2749         {
2750                 /* Accept reasonable targets */
2751                 if (target_able(target_who))
2752                 {
2753                         monster_type *m_ptr = &m_list[target_who];
2754
2755                         /* Acquire monster location */
2756                         target_row = m_ptr->fy;
2757                         target_col = m_ptr->fx;
2758
2759                         /* Good target */
2760                         return (TRUE);
2761                 }
2762         }
2763
2764         /* Assume no target */
2765         return (FALSE);
2766 }
2767
2768
2769 /*
2770  * Sorting hook -- comp function -- by "distance to player"
2771  *
2772  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2773  * and sort the arrays by double-distance to the player.
2774  */
2775 static bool ang_sort_comp_distance(vptr u, vptr v, int a, int b)
2776 {
2777         byte *x = (byte*)(u);
2778         byte *y = (byte*)(v);
2779
2780         int da, db, kx, ky;
2781
2782         /* Absolute distance components */
2783         kx = x[a]; kx -= px; kx = ABS(kx);
2784         ky = y[a]; ky -= py; ky = ABS(ky);
2785
2786         /* Approximate Double Distance to the first point */
2787         da = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2788
2789         /* Absolute distance components */
2790         kx = x[b]; kx -= px; kx = ABS(kx);
2791         ky = y[b]; ky -= py; ky = ABS(ky);
2792
2793         /* Approximate Double Distance to the first point */
2794         db = ((kx > ky) ? (kx + kx + ky) : (ky + ky + kx));
2795
2796         /* Compare the distances */
2797         return (da <= db);
2798 }
2799
2800
2801 /*
2802  * Sorting hook -- comp function -- by importance level of grids
2803  *
2804  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2805  * and sort the arrays by level of monster
2806  */
2807 static bool ang_sort_comp_importance(vptr u, vptr v, int a, int b)
2808 {
2809         byte *x = (byte*)(u);
2810         byte *y = (byte*)(v);
2811         cave_type *ca_ptr = &cave[y[a]][x[a]];
2812         cave_type *cb_ptr = &cave[y[b]][x[b]];
2813         monster_type *ma_ptr = &m_list[ca_ptr->m_idx];
2814         monster_type *mb_ptr = &m_list[cb_ptr->m_idx];
2815         monster_race *ap_ra_ptr, *ap_rb_ptr;
2816
2817         /* The player grid */
2818         if (y[a] == py && x[a] == px) return TRUE;
2819         if (y[b] == py && x[b] == px) return FALSE;
2820
2821         /* Extract monster race */
2822         if (ca_ptr->m_idx && ma_ptr->ml) ap_ra_ptr = &r_info[ma_ptr->ap_r_idx];
2823         else ap_ra_ptr = NULL;
2824         if (cb_ptr->m_idx && mb_ptr->ml) ap_rb_ptr = &r_info[mb_ptr->ap_r_idx];
2825         else ap_rb_ptr = NULL;
2826
2827         if (ap_ra_ptr && !ap_rb_ptr) return TRUE;
2828         if (!ap_ra_ptr && ap_rb_ptr) return FALSE;
2829
2830         /* Compare two monsters */
2831         if (ap_ra_ptr && ap_rb_ptr)
2832         {
2833                 /* Unique monsters first */
2834                 if ((ap_ra_ptr->flags1 & RF1_UNIQUE) && !(ap_rb_ptr->flags1 & RF1_UNIQUE)) return TRUE;
2835                 if (!(ap_ra_ptr->flags1 & RF1_UNIQUE) && (ap_rb_ptr->flags1 & RF1_UNIQUE)) return FALSE;
2836
2837                 /* Shadowers first (¤¢¤ä¤·¤¤±Æ) */
2838                 if ((ma_ptr->mflag2 & MFLAG2_KAGE) && !(mb_ptr->mflag2 & MFLAG2_KAGE)) return TRUE;
2839                 if (!(ma_ptr->mflag2 & MFLAG2_KAGE) && (mb_ptr->mflag2 & MFLAG2_KAGE)) return FALSE;
2840
2841                 /* Unknown monsters first */
2842                 if (!ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills) return TRUE;
2843                 if (ap_ra_ptr->r_tkills && !ap_rb_ptr->r_tkills) return FALSE;
2844
2845                 /* Higher level monsters first (if known) */
2846                 if (ap_ra_ptr->r_tkills && ap_rb_ptr->r_tkills)
2847                 {
2848                         if (ap_ra_ptr->level > ap_rb_ptr->level) return TRUE;
2849                         if (ap_ra_ptr->level < ap_rb_ptr->level) return FALSE;
2850                 }
2851
2852                 /* Sort by index if all conditions are same */
2853                 if (ma_ptr->ap_r_idx > mb_ptr->ap_r_idx) return TRUE;
2854                 if (ma_ptr->ap_r_idx < mb_ptr->ap_r_idx) return FALSE;
2855         }
2856
2857         /* An object get higher priority */
2858         if (cave[y[a]][x[a]].o_idx && !cave[y[b]][x[b]].o_idx) return TRUE;
2859         if (!cave[y[a]][x[a]].o_idx && cave[y[b]][x[b]].o_idx) return FALSE;
2860
2861         /* Priority from the terrain */
2862         if (f_info[ca_ptr->feat].priority > f_info[cb_ptr->feat].priority) return TRUE;
2863         if (f_info[ca_ptr->feat].priority < f_info[cb_ptr->feat].priority) return FALSE;
2864
2865         /* If all conditions are same, compare distance */
2866         return ang_sort_comp_distance(u, v, a, b);
2867 }
2868
2869
2870 /*
2871  * Sorting hook -- swap function -- by "distance to player"
2872  *
2873  * We use "u" and "v" to point to arrays of "x" and "y" positions,
2874  * and sort the arrays by distance to the player.
2875  */
2876 static void ang_sort_swap_distance(vptr u, vptr v, int a, int b)
2877 {
2878         byte *x = (byte*)(u);
2879         byte *y = (byte*)(v);
2880
2881         byte temp;
2882
2883         /* Swap "x" */
2884         temp = x[a];
2885         x[a] = x[b];
2886         x[b] = temp;
2887
2888         /* Swap "y" */
2889         temp = y[a];
2890         y[a] = y[b];
2891         y[b] = temp;
2892 }
2893
2894
2895
2896 /*
2897  * Hack -- help "select" a location (see below)
2898  */
2899 static s16b target_pick(int y1, int x1, int dy, int dx)
2900 {
2901         int i, v;
2902
2903         int x2, y2, x3, y3, x4, y4;
2904
2905         int b_i = -1, b_v = 9999;
2906
2907
2908         /* Scan the locations */
2909         for (i = 0; i < temp_n; i++)
2910         {
2911                 /* Point 2 */
2912                 x2 = temp_x[i];
2913                 y2 = temp_y[i];
2914
2915                 /* Directed distance */
2916                 x3 = (x2 - x1);
2917                 y3 = (y2 - y1);
2918
2919                 /* Verify quadrant */
2920                 if (dx && (x3 * dx <= 0)) continue;
2921                 if (dy && (y3 * dy <= 0)) continue;
2922
2923                 /* Absolute distance */
2924                 x4 = ABS(x3);
2925                 y4 = ABS(y3);
2926
2927                 /* Verify quadrant */
2928                 if (dy && !dx && (x4 > y4)) continue;
2929                 if (dx && !dy && (y4 > x4)) continue;
2930
2931                 /* Approximate Double Distance */
2932                 v = ((x4 > y4) ? (x4 + x4 + y4) : (y4 + y4 + x4));
2933
2934                 /* XXX XXX XXX Penalize location */
2935
2936                 /* Track best */
2937                 if ((b_i >= 0) && (v >= b_v)) continue;
2938
2939                 /* Track best */
2940                 b_i = i; b_v = v;
2941         }
2942
2943         /* Result */
2944         return (b_i);
2945 }
2946
2947
2948 /*
2949  * Hack -- determine if a given location is "interesting"
2950  */
2951 static bool target_set_accept(int y, int x)
2952 {
2953         cave_type *c_ptr;
2954
2955         s16b this_o_idx, next_o_idx = 0;
2956
2957         /* Bounds */
2958         if (!(in_bounds(y, x))) return (FALSE);
2959
2960         /* Player grid is always interesting */
2961         if (player_bold(y, x)) return (TRUE);
2962
2963
2964         /* Handle hallucination */
2965         if (p_ptr->image) return (FALSE);
2966
2967
2968         /* Examine the grid */
2969         c_ptr = &cave[y][x];
2970
2971         /* Visible monsters */
2972         if (c_ptr->m_idx)
2973         {
2974                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
2975
2976                 /* Visible monsters */
2977                 if (m_ptr->ml) return (TRUE);
2978         }
2979
2980         /* Scan all objects in the grid */
2981         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2982         {
2983                 object_type *o_ptr;
2984
2985                 /* Acquire object */
2986                 o_ptr = &o_list[this_o_idx];
2987
2988                 /* Acquire next object */
2989                 next_o_idx = o_ptr->next_o_idx;
2990
2991                 /* Memorized object */
2992                 if (o_ptr->marked & OM_FOUND) return (TRUE);
2993         }
2994
2995         /* Interesting memorized features */
2996         if (c_ptr->info & (CAVE_MARK))
2997         {
2998                 /* Notice object features */
2999                 if (c_ptr->info & CAVE_OBJECT) return (TRUE);
3000
3001                 /* Feature code (applying "mimic" field) */
3002                 if (have_flag(f_info[get_feat_mimic(c_ptr)].flags, FF_NOTICE)) return TRUE;
3003         }
3004
3005         /* Nope */
3006         return (FALSE);
3007 }
3008
3009
3010 /*
3011  * Prepare the "temp" array for "target_set"
3012  *
3013  * Return the number of target_able monsters in the set.
3014  */
3015 static void target_set_prepare(int mode)
3016 {
3017         int y, x;
3018
3019         /* Reset "temp" array */
3020         temp_n = 0;
3021
3022         /* Scan the current panel */
3023         for (y = panel_row_min; y <= panel_row_max; y++)
3024         {
3025                 for (x = panel_col_min; x <= panel_col_max; x++)
3026                 {
3027                         cave_type *c_ptr;
3028
3029                         /* Require "interesting" contents */
3030                         if (!target_set_accept(y, x)) continue;
3031
3032                         c_ptr = &cave[y][x];
3033
3034                         /* Require target_able monsters for "TARGET_KILL" */
3035                         if ((mode & (TARGET_KILL)) && !target_able(c_ptr->m_idx)) continue;
3036
3037                         if ((mode & (TARGET_KILL)) && !target_pet && is_pet(&m_list[c_ptr->m_idx])) continue;
3038
3039                         /* Save the location */
3040                         temp_x[temp_n] = x;
3041                         temp_y[temp_n] = y;
3042                         temp_n++;
3043                 }
3044         }
3045
3046         /* Set the sort hooks */
3047         if (mode & (TARGET_KILL))
3048         {
3049                 /* Target the nearest monster for shooting */
3050                 ang_sort_comp = ang_sort_comp_distance;
3051                 ang_sort_swap = ang_sort_swap_distance;
3052         }
3053         else
3054         {
3055                 /* Look important grids first in Look command */
3056                 ang_sort_comp = ang_sort_comp_importance;
3057                 ang_sort_swap = ang_sort_swap_distance;
3058         }
3059
3060         /* Sort the positions */
3061         ang_sort(temp_x, temp_y, temp_n);
3062
3063         if (p_ptr->riding && target_pet && (temp_n > 1) && (mode & (TARGET_KILL)))
3064         {
3065                 byte tmp;
3066
3067                 tmp = temp_y[0];
3068                 temp_y[0] = temp_y[1];
3069                 temp_y[1] = tmp;
3070                 tmp = temp_x[0];
3071                 temp_x[0] = temp_x[1];
3072                 temp_x[1] = tmp;
3073         }
3074 }
3075
3076
3077 /*
3078  * Evaluate number of kill needed to gain level
3079  */
3080 static void evaluate_monster_exp(char *buf, monster_type *m_ptr)
3081 {
3082         monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3083         u32b num;
3084         s32b exp_mon, exp_adv;
3085         u32b exp_mon_frac, exp_adv_frac;
3086
3087         if ((p_ptr->lev >= PY_MAX_LEVEL) || (p_ptr->prace == RACE_ANDROID))
3088         {
3089                 sprintf(buf,"**");
3090                 return;
3091         }
3092         else if (!ap_r_ptr->r_tkills || (m_ptr->mflag2 & MFLAG2_KAGE))
3093         {
3094                 if (!p_ptr->wizard)
3095                 {
3096                         sprintf(buf,"??");
3097                         return;
3098                 }
3099         }
3100
3101
3102         /* The monster's experience point (assuming average monster speed) */
3103         exp_mon = ap_r_ptr->mexp * ap_r_ptr->level;
3104         exp_mon_frac = 0;
3105         s64b_div(&exp_mon, &exp_mon_frac, 0, (p_ptr->max_plv + 2));
3106
3107
3108         /* Total experience value for next level */
3109         exp_adv = player_exp[p_ptr->lev -1] * p_ptr->expfact;
3110         exp_adv_frac = 0;
3111         s64b_div(&exp_adv, &exp_adv_frac, 0, 100);
3112
3113         /* Experience value need to get */
3114         s64b_sub(&exp_adv, &exp_adv_frac, p_ptr->exp, p_ptr->exp_frac);
3115
3116
3117         /* You need to kill at least one monster to get any experience */
3118         s64b_add(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
3119         s64b_sub(&exp_adv, &exp_adv_frac, 0, 1);
3120
3121         /* Extract number of monsters needed */
3122         s64b_div(&exp_adv, &exp_adv_frac, exp_mon, exp_mon_frac);
3123
3124         /* If 999 or more monsters needed, only display "999". */
3125         num = MIN(999, exp_adv_frac);
3126
3127         /* Display the number */
3128         sprintf(buf,"%03ld", (long int)num);
3129 }
3130
3131
3132 bool show_gold_on_floor = FALSE;
3133
3134 /*
3135  * Examine a grid, return a keypress.
3136  *
3137  * The "mode" argument contains the "TARGET_LOOK" bit flag, which
3138  * indicates that the "space" key should scan through the contents
3139  * of the grid, instead of simply returning immediately.  This lets
3140  * the "look" command get complete information, without making the
3141  * "target" command annoying.
3142  *
3143  * The "info" argument contains the "commands" which should be shown
3144  * inside the "[xxx]" text.  This string must never be empty, or grids
3145  * containing monsters will be displayed with an extra comma.
3146  *
3147  * Note that if a monster is in the grid, we update both the monster
3148  * recall info and the health bar info to track that monster.
3149  *
3150  * Eventually, we may allow multiple objects per grid, or objects
3151  * and terrain features in the same grid. XXX XXX XXX
3152  *
3153  * This function must handle blindness/hallucination.
3154  */
3155 static int target_set_aux(int y, int x, int mode, cptr info)
3156 {
3157         cave_type *c_ptr = &cave[y][x];
3158         s16b this_o_idx, next_o_idx = 0;
3159         cptr s1 = "", s2 = "", s3 = "", x_info = "";
3160         bool boring = TRUE;
3161         s16b feat;
3162         feature_type *f_ptr;
3163         int query = '\001';
3164         char out_val[MAX_NLEN+80];
3165
3166 #ifdef ALLOW_EASY_FLOOR
3167         int floor_list[23], floor_num = 0;
3168
3169         /* Scan all objects in the grid */
3170         if (easy_floor)
3171         {
3172                 floor_num = scan_floor(floor_list, y, x, 0x02);
3173
3174                 if (floor_num)
3175                 {
3176 #ifdef JP
3177                         x_info = "xʪ ";
3178 #else
3179                         x_info = "x,";
3180 #endif
3181                 }
3182         }
3183
3184 #endif /* ALLOW_EASY_FLOOR */
3185
3186         /* Hack -- under the player */
3187         if (player_bold(y, x))
3188         {
3189                 /* Description */
3190 #ifdef JP
3191                 s1 = "¤¢¤Ê¤¿¤Ï";
3192                 s2 = "¤Î¾å";
3193                 s3 = "¤Ë¤¤¤ë";
3194 #else
3195                 s1 = "You are ";
3196
3197                 /* Preposition */
3198                 s2 = "on ";
3199 #endif
3200         }
3201         else
3202         {
3203 #ifdef JP
3204                 s1 = "¥¿¡¼¥²¥Ã¥È:";
3205 #else
3206                 s1 = "Target:";
3207 #endif
3208         }
3209
3210         /* Hack -- hallucination */
3211         if (p_ptr->image)
3212         {
3213 #ifdef JP
3214                 cptr name = "²¿¤«´ñ̯¤Êʪ";
3215 #else
3216                 cptr name = "something strange";
3217 #endif
3218
3219
3220                 /* Display a message */
3221 #ifdef JP
3222                 sprintf(out_val, "%s%s%s%s [%s]", s1, name, s2, s3, info);
3223 #else
3224                 sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3225 #endif
3226
3227                 prt(out_val, 0, 0);
3228                 move_cursor_relative(y, x);
3229                 query = inkey();
3230
3231                 /* Stop on everything but "return" */
3232                 if ((query != '\r') && (query != '\n')) return query;
3233
3234                 /* Repeat forever */
3235                 return 0;
3236         }
3237
3238
3239         /* Actual monsters */
3240         if (c_ptr->m_idx && m_list[c_ptr->m_idx].ml)
3241         {
3242                 monster_type *m_ptr = &m_list[c_ptr->m_idx];
3243                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3244                 char m_name[80];
3245                 bool recall = FALSE;
3246
3247                 /* Not boring */
3248                 boring = FALSE;
3249
3250                 /* Get the monster name ("a kobold") */
3251                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
3252
3253                 /* Hack -- track this monster race */
3254                 monster_race_track(m_ptr->ap_r_idx);
3255
3256                 /* Hack -- health bar for this monster */
3257                 health_track(c_ptr->m_idx);
3258
3259                 /* Hack -- handle stuff */
3260                 handle_stuff();
3261
3262                 /* Interact */
3263                 while (1)
3264                 {
3265                         char acount[10];
3266
3267                         /* Recall */
3268                         if (recall)
3269                         {
3270                                 /* Save */
3271                                 screen_save();
3272
3273                                 /* Recall on screen */
3274                                 screen_roff(m_ptr->ap_r_idx, 0);
3275
3276                                 /* Hack -- Complete the prompt (again) */
3277 #ifdef JP
3278                                 Term_addstr(-1, TERM_WHITE, format("  [r»× %s%s]", x_info, info));
3279 #else
3280                                 Term_addstr(-1, TERM_WHITE, format("  [r,%s%s]", x_info, info));
3281 #endif
3282
3283                                 /* Command */
3284                                 query = inkey();
3285
3286                                 /* Restore */
3287                                 screen_load();
3288
3289                                 /* Normal commands */
3290                                 if (query != 'r') break;
3291
3292                                 /* Toggle recall */
3293                                 recall = FALSE;
3294
3295                                 /* Cleare recall text and repeat */
3296                                 continue;
3297                         }
3298
3299                         /*** Normal ***/
3300
3301                         /* Describe, and prompt for recall */
3302                         evaluate_monster_exp(acount, m_ptr);
3303
3304 #ifdef JP
3305                         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);
3306 #else
3307                         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);
3308 #endif
3309
3310                         prt(out_val, 0, 0);
3311
3312                         /* Place cursor */
3313                         move_cursor_relative(y, x);
3314
3315                         /* Command */
3316                         query = inkey();
3317
3318                         /* Normal commands */
3319                         if (query != 'r') break;
3320
3321                         /* Toggle recall */
3322                         recall = TRUE;
3323                 }
3324
3325                 /* Always stop at "normal" keys */
3326                 if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3327
3328                 /* Sometimes stop at "space" key */
3329                 if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3330
3331                 /* Change the intro */
3332 #ifdef JP
3333                 s1 = "¤½¤ì¤Ï";
3334 #else
3335                 s1 = "It is ";
3336 #endif
3337
3338
3339                 /* Hack -- take account of gender */
3340 #ifdef JP
3341                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = "Èà½÷¤Ï";
3342 #else
3343                 if (ap_r_ptr->flags1 & (RF1_FEMALE)) s1 = "She is ";
3344 #endif
3345
3346 #ifdef JP
3347                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = "Èà¤Ï";
3348 #else
3349                 else if (ap_r_ptr->flags1 & (RF1_MALE)) s1 = "He is ";
3350 #endif
3351
3352
3353                 /* Use a preposition */
3354 #ifdef JP
3355                 s2 = "¤ò";
3356                 s3 = "»ý¤Ã¤Æ¤¤¤ë";
3357 #else
3358                 s2 = "carrying ";
3359 #endif
3360
3361
3362                 /* Scan all objects being carried */
3363                 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3364                 {
3365                         char o_name[MAX_NLEN];
3366
3367                         object_type *o_ptr;
3368
3369                         /* Acquire object */
3370                         o_ptr = &o_list[this_o_idx];
3371
3372                         /* Acquire next object */
3373                         next_o_idx = o_ptr->next_o_idx;
3374
3375                         /* Obtain an object description */
3376                         object_desc(o_name, o_ptr, 0);
3377
3378                         /* Describe the object */
3379 #ifdef JP
3380                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3381 #else
3382                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3383 #endif
3384
3385                         prt(out_val, 0, 0);
3386                         move_cursor_relative(y, x);
3387                         query = inkey();
3388
3389                         /* Always stop at "normal" keys */
3390                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3391
3392                         /* Sometimes stop at "space" key */
3393                         if ((query == ' ') && !(mode & (TARGET_LOOK))) return query;
3394
3395                         /* Change the intro */
3396 #ifdef JP
3397                         s2 = "¤ò¤Þ¤¿";
3398 #else
3399                         s2 = "also carrying ";
3400 #endif
3401                 }
3402
3403                 /* Use a preposition */
3404 #ifdef JP
3405                 s2 = "¤Î¾å";
3406                 s3 = "¤Ë¤¤¤ë";
3407 #else
3408                 s2 = "on ";
3409 #endif
3410         }
3411
3412
3413 #ifdef ALLOW_EASY_FLOOR
3414         if (floor_num)
3415         {
3416                 int min_width = 0;
3417
3418                 while (1)
3419                 {
3420                         if (floor_num == 1)
3421                         {
3422                                 char o_name[MAX_NLEN];
3423
3424                                 object_type *o_ptr;
3425
3426                                 /* Acquire object */
3427                                 o_ptr = &o_list[floor_list[0]];
3428
3429                                 /* Describe the object */
3430                                 object_desc(o_name, o_ptr, 0);
3431
3432                                 /* Message */
3433 #ifdef JP
3434                                 sprintf(out_val, "%s%s%s%s[%s]",
3435                                         s1, o_name, s2, s3, info);
3436 #else
3437                                 sprintf(out_val, "%s%s%s%s [%s]",
3438                                         s1, s2, s3, o_name, info);
3439 #endif
3440
3441                                 prt(out_val, 0, 0);
3442                                 move_cursor_relative(y, x);
3443
3444                                 /* Command */
3445                                 query = inkey();
3446
3447                                 /* End this grid */
3448                                 return query;
3449                         }
3450
3451                         /* Provide one cushion before item listing  */
3452                         if (boring)
3453                         {
3454                                 /* Display rough information about items */
3455 #ifdef JP
3456                                 sprintf(out_val, "%s %d¸Ä¤Î¥¢¥¤¥Æ¥à%s%s ['x'¤Ç°ìÍ÷, %s]",
3457                                         s1, floor_num, s2, s3, info);
3458 #else
3459                                 sprintf(out_val, "%s%s%sa pile of %d items [x,%s]",
3460                                         s1, s2, s3, floor_num, info);
3461 #endif
3462
3463                                 prt(out_val, 0, 0);
3464                                 move_cursor_relative(y, x);
3465
3466                                 /* Command */
3467                                 query = inkey();
3468
3469                                 /* No request for listing */
3470                                 if (query != 'x' && query != ' ') return query;
3471                         }
3472
3473
3474                         /** Display list of items **/
3475
3476                         /* Continue scrolling list if requested */
3477                         while (1)
3478                         {
3479                                 int i, o_idx;
3480
3481                                 /* Save screen */
3482                                 screen_save();
3483
3484                                 /* Display */
3485                                 show_gold_on_floor = TRUE;
3486                                 (void)show_floor(0, y, x, &min_width);
3487                                 show_gold_on_floor = FALSE;
3488
3489                                 /* Prompt */
3490 #ifdef JP
3491                                 sprintf(out_val, "%s %d¸Ä¤Î¥¢¥¤¥Æ¥à%s%s [Enter¤Ç¼¡¤Ø, %s]",
3492                                         s1, floor_num, s2, s3, info);
3493 #else
3494                                 sprintf(out_val, "%s%s%sa pile of %d items [Enter,%s]",
3495                                         s1, s2, s3, floor_num, info);
3496 #endif
3497                                 prt(out_val, 0, 0);
3498
3499
3500                                 /* Wait */
3501                                 query = inkey();
3502
3503                                 /* Load screen */
3504                                 screen_load();
3505
3506                                 /* Exit unless 'Enter' */
3507                                 if (query != '\n' && query != '\r')
3508                                 {
3509                                         return query;
3510                                 }
3511
3512                                 /* Get the object being moved. */
3513                                 o_idx = c_ptr->o_idx;
3514  
3515                                 /* Only rotate a pile of two or more objects. */
3516                                 if (!(o_idx && o_list[o_idx].next_o_idx)) continue;
3517
3518                                 /* Remove the first object from the list. */
3519                                 excise_object_idx(o_idx);
3520
3521                                 /* Find end of the list. */
3522                                 i = c_ptr->o_idx;
3523                                 while (o_list[i].next_o_idx)
3524                                         i = o_list[i].next_o_idx;
3525
3526                                 /* Add after the last object. */
3527                                 o_list[i].next_o_idx = o_idx;
3528
3529                                 /* Loop and re-display the list */
3530                         }
3531                 }
3532
3533                 /* NOTREACHED */
3534         }
3535 #endif /* ALLOW_EASY_FLOOR */
3536
3537
3538         /* Scan all objects in the grid */
3539         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3540         {
3541                 object_type *o_ptr;
3542
3543                 /* Acquire object */
3544                 o_ptr = &o_list[this_o_idx];
3545
3546                 /* Acquire next object */
3547                 next_o_idx = o_ptr->next_o_idx;
3548
3549                 /* Describe it */
3550                 if (o_ptr->marked & OM_FOUND)
3551                 {
3552                         char o_name[MAX_NLEN];
3553
3554                         /* Not boring */
3555                         boring = FALSE;
3556
3557                         /* Obtain an object description */
3558                         object_desc(o_name, o_ptr, 0);
3559
3560                         /* Describe the object */
3561 #ifdef JP
3562                         sprintf(out_val, "%s%s%s%s[%s]", s1, o_name, s2, s3, info);
3563 #else
3564                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, o_name, info);
3565 #endif
3566
3567                         prt(out_val, 0, 0);
3568                         move_cursor_relative(y, x);
3569                         query = inkey();
3570
3571                         /* Always stop at "normal" keys */
3572                         if ((query != '\r') && (query != '\n') && (query != ' ') && (query != 'x')) return query;
3573
3574                         /* Sometimes stop at "space" key */
3575                         if ((query == ' ') && !(mode & TARGET_LOOK)) return query;
3576
3577                         /* Change the intro */
3578 #ifdef JP
3579                         s1 = "¤½¤ì¤Ï";
3580 #else
3581                         s1 = "It is ";
3582 #endif
3583
3584
3585                         /* Plurals */
3586 #ifdef JP
3587                         if (o_ptr->number != 1) s1 = "¤½¤ì¤é¤Ï";
3588 #else
3589                         if (o_ptr->number != 1) s1 = "They are ";
3590 #endif
3591
3592
3593                         /* Preposition */
3594 #ifdef JP
3595                         s2 = "¤Î¾å";
3596                         s3 = "¤Ë¸«¤¨¤ë";
3597 #else
3598                         s2 = "on ";
3599 #endif
3600
3601                 }
3602         }
3603
3604
3605         /* Feature code (applying "mimic" field) */
3606         feat = get_feat_mimic(c_ptr);
3607
3608         /* Require knowledge about grid, or ability to see grid */
3609         if (!(c_ptr->info & CAVE_MARK) && !player_can_see_bold(y, x))
3610         {
3611                 /* Forget feature */
3612                 feat = feat_none;
3613         }
3614
3615         f_ptr = &f_info[feat];
3616
3617         /* Terrain feature if needed */
3618         if (boring || have_flag(f_ptr->flags, FF_REMEMBER))
3619         {
3620                 cptr name;
3621
3622                 /* Hack -- special handling for quest entrances */
3623                 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
3624                 {
3625                         /* Set the quest number temporary */
3626                         int old_quest = p_ptr->inside_quest;
3627                         int j;
3628
3629                         /* Clear the text */
3630                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
3631                         quest_text_line = 0;
3632
3633                         p_ptr->inside_quest = c_ptr->special;
3634
3635                         /* Get the quest text */
3636                         init_flags = INIT_SHOW_TEXT;
3637
3638                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3639
3640 #ifdef JP
3641                         name = format("¥¯¥¨¥¹¥È¡Ö%s¡×(%d³¬ÁêÅö)", quest[c_ptr->special].name, quest[c_ptr->special].level);
3642 #else
3643                         name = format("the entrance to the quest '%s'(level %d)", quest[c_ptr->special].name, quest[c_ptr->special].level);
3644 #endif
3645
3646                         /* Reset the old quest number */
3647                         p_ptr->inside_quest = old_quest;
3648                 }
3649
3650                 /* Hack -- special handling for building doors */
3651                 else if (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena)
3652                 {
3653                         name = building[f_ptr->subtype].name;
3654                 }
3655                 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
3656                 {
3657 #ifdef JP
3658                         name = format("%s(%d³¬ÁêÅö)", d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3659 #else
3660                         name = format("%s(level %d)", d_text + d_info[c_ptr->special].text, d_info[c_ptr->special].mindepth);
3661 #endif
3662                 }
3663                 else if (have_flag(f_ptr->flags, FF_TOWN))
3664                 {
3665                         name = town[c_ptr->special].name;
3666                 }
3667                 else if (p_ptr->wild_mode && (feat == feat_floor))
3668                 {
3669 #ifdef JP
3670                         name = "ƻ";
3671 #else
3672                         name = "road";
3673 #endif
3674                 }
3675                 else
3676                 {
3677                         name = f_name + f_ptr->name;
3678                 }
3679
3680
3681                 /* Pick a prefix */
3682                 if (*s2 &&
3683                     ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
3684                      (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE)) ||
3685                      have_flag(f_ptr->flags, FF_TOWN)))
3686                 {
3687 #ifdef JP
3688                         s2 = "¤ÎÃæ";
3689 #else
3690                         s2 = "in ";
3691 #endif
3692                 }
3693
3694                 /* Hack -- special introduction for store & building doors -KMW- */
3695                 if (have_flag(f_ptr->flags, FF_STORE) ||
3696                     have_flag(f_ptr->flags, FF_QUEST_ENTER) ||
3697                     (have_flag(f_ptr->flags, FF_BLDG) && !p_ptr->inside_arena) ||
3698                     have_flag(f_ptr->flags, FF_ENTRANCE))
3699                 {
3700 #ifdef JP
3701                         s2 = "¤ÎÆþ¸ý";
3702 #else
3703                         s3 = "";
3704 #endif
3705                 }
3706 #ifndef JP
3707                 else if (have_flag(f_ptr->flags, FF_FLOOR) ||
3708                          have_flag(f_ptr->flags, FF_TOWN) ||
3709                          have_flag(f_ptr->flags, FF_SHALLOW) ||
3710                          have_flag(f_ptr->flags, FF_DEEP))
3711                 {
3712                         s3 ="";
3713                 }
3714                 else
3715                 {
3716                         /* Pick proper indefinite article */
3717                         s3 = (is_a_vowel(name[0])) ? "an " : "a ";
3718                 }
3719 #endif
3720
3721                 /* Display a message */
3722                 if (p_ptr->wizard)
3723                 {
3724                         char f_idx_str[32];
3725                         if (c_ptr->mimic) sprintf(f_idx_str, "%d/%d", c_ptr->feat, c_ptr->mimic);
3726                         else sprintf(f_idx_str, "%d", c_ptr->feat);
3727 #ifdef JP
3728                         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);
3729 #else
3730                         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);
3731 #endif
3732                 }
3733                 else
3734 #ifdef JP
3735                         sprintf(out_val, "%s%s%s%s[%s]", s1, name, s2, s3, info);
3736 #else
3737                         sprintf(out_val, "%s%s%s%s [%s]", s1, s2, s3, name, info);
3738 #endif
3739
3740                 prt(out_val, 0, 0);
3741                 move_cursor_relative(y, x);
3742                 query = inkey();
3743
3744                 /* Always stop at "normal" keys */
3745                 if ((query != '\r') && (query != '\n') && (query != ' ')) return query;
3746         }
3747
3748         /* Stop on everything but "return" */
3749         if ((query != '\r') && (query != '\n')) return query;
3750
3751         /* Repeat forever */
3752         return 0;
3753 }
3754
3755
3756 /*
3757  * Handle "target" and "look".
3758  *
3759  * Note that this code can be called from "get_aim_dir()".
3760  *
3761  * All locations must be on the current panel.  Consider the use of
3762  * "panel_bounds()" to allow "off-panel" targets, perhaps by using
3763  * some form of "scrolling" the map around the cursor.  XXX XXX XXX
3764  * That is, consider the possibility of "auto-scrolling" the screen
3765  * while the cursor moves around.  This may require changes in the
3766  * "update_mon()" code to allow "visibility" even if off panel, and
3767  * may require dynamic recalculation of the "temp" grid set.
3768  *
3769  * Hack -- targeting/observing an "outer border grid" may induce
3770  * problems, so this is not currently allowed.
3771  *
3772  * The player can use the direction keys to move among "interesting"
3773  * grids in a heuristic manner, or the "space", "+", and "-" keys to
3774  * move through the "interesting" grids in a sequential manner, or
3775  * can enter "location" mode, and use the direction keys to move one
3776  * grid at a time in any direction.  The "t" (set target) command will
3777  * only target a monster (as opposed to a location) if the monster is
3778  * target_able and the "interesting" mode is being used.
3779  *
3780  * The current grid is described using the "look" method above, and
3781  * a new command may be entered at any time, but note that if the
3782  * "TARGET_LOOK" bit flag is set (or if we are in "location" mode,
3783  * where "space" has no obvious meaning) then "space" will scan
3784  * through the description of the current grid until done, instead
3785  * of immediately jumping to the next "interesting" grid.  This
3786  * allows the "target" command to retain its old semantics.
3787  *
3788  * The "*", "+", and "-" keys may always be used to jump immediately
3789  * to the next (or previous) interesting grid, in the proper mode.
3790  *
3791  * The "return" key may always be used to scan through a complete
3792  * grid description (forever).
3793  *
3794  * This command will cancel any old target, even if used from
3795  * inside the "look" command.
3796  */
3797 bool target_set(int mode)
3798 {
3799         int             i, d, m, t, bd;
3800         int             y = py;
3801         int             x = px;
3802
3803         bool    done = FALSE;
3804
3805         bool    flag = TRUE;
3806
3807         char    query;
3808
3809         char    info[80];
3810
3811         cave_type               *c_ptr;
3812
3813         int wid, hgt;
3814
3815
3816         /* Get size */
3817         get_screen_size(&wid, &hgt);
3818
3819         /* Cancel target */
3820         target_who = 0;
3821
3822
3823         /* Cancel tracking */
3824         /* health_track(0); */
3825
3826
3827         /* Prepare the "temp" array */
3828         target_set_prepare(mode);
3829
3830         /* Start near the player */
3831         m = 0;
3832
3833         /* Interact */
3834         while (!done)
3835         {
3836                 /* Interesting grids */
3837                 if (flag && temp_n)
3838                 {
3839                         y = temp_y[m];
3840                         x = temp_x[m];
3841
3842                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
3843
3844                         /* Access */
3845                         c_ptr = &cave[y][x];
3846
3847                         /* Allow target */
3848                         if (target_able(c_ptr->m_idx))
3849                         {
3850 #ifdef JP
3851 strcpy(info, "q»ß t·è p¼« o¸½ +¼¡ -Á°");
3852 #else
3853                                 strcpy(info, "q,t,p,o,+,-,<dir>");
3854 #endif
3855
3856                         }
3857
3858                         /* Dis-allow target */
3859                         else
3860                         {
3861 #ifdef JP
3862 strcpy(info, "q»ß p¼« o¸½ +¼¡ -Á°");
3863 #else
3864                                 strcpy(info, "q,p,o,+,-,<dir>");
3865 #endif
3866
3867                         }
3868
3869                         /* Describe and Prompt */
3870                         while (!(query = target_set_aux(y, x, mode, info)));
3871
3872                         /* Cancel tracking */
3873                         /* health_track(0); */
3874
3875                         /* Assume no "direction" */
3876                         d = 0;
3877
3878                         if (use_menu)
3879                         {
3880                                 if (query == '\r') query = 't';
3881                         }  
3882
3883                         /* Analyze */
3884                         switch (query)
3885                         {
3886                                 case ESCAPE:
3887                                 case 'q':
3888                                 {
3889                                         done = TRUE;
3890                                         break;
3891                                 }
3892
3893                                 case 't':
3894                                 case '.':
3895                                 case '5':
3896                                 case '0':
3897                                 {
3898                                         if (target_able(c_ptr->m_idx))
3899                                         {
3900                                                 health_track(c_ptr->m_idx);
3901                                                 target_who = c_ptr->m_idx;
3902                                                 target_row = y;
3903                                                 target_col = x;
3904                                                 done = TRUE;
3905                                         }
3906                                         else
3907                                         {
3908                                                 bell();
3909                                         }
3910                                         break;
3911                                 }
3912
3913                                 case ' ':
3914                                 case '*':
3915                                 case '+':
3916                                 {
3917                                         if (++m == temp_n)
3918                                         {
3919                                                 m = 0;
3920                                                 if (!expand_list) done = TRUE;
3921                                         }
3922                                         break;
3923                                 }
3924
3925                                 case '-':
3926                                 {
3927                                         if (m-- == 0)
3928                                         {
3929                                                 m = temp_n - 1;
3930                                                 if (!expand_list) done = TRUE;
3931                                         }
3932                                         break;
3933                                 }
3934
3935                                 case 'p':
3936                                 {
3937                                         /* Recenter the map around the player */
3938                                         verify_panel();
3939
3940                                         /* Update stuff */
3941                                         p_ptr->update |= (PU_MONSTERS);
3942
3943                                         /* Redraw map */
3944                                         p_ptr->redraw |= (PR_MAP);
3945
3946                                         /* Window stuff */
3947                                         p_ptr->window |= (PW_OVERHEAD);
3948
3949                                         /* Handle stuff */
3950                                         handle_stuff();
3951
3952                                         /* Recalculate interesting grids */
3953                                         target_set_prepare(mode);
3954
3955                                         y = py;
3956                                         x = px;
3957                                 }
3958
3959                                 case 'o':
3960                                 {
3961                                         flag = FALSE;
3962                                         break;
3963                                 }
3964
3965                                 case 'm':
3966                                 {
3967                                         break;
3968                                 }
3969
3970                                 default:
3971                                 {
3972                                         /* Extract the action (if any) */
3973                                         d = get_keymap_dir(query);
3974
3975                                         if (!d) bell();
3976                                         break;
3977                                 }
3978                         }
3979
3980                         /* Hack -- move around */
3981                         if (d)
3982                         {
3983                                 /* Modified to scroll to monster */
3984                                 int y2 = panel_row_min;
3985                                 int x2 = panel_col_min;
3986
3987                                 /* Find a new monster */
3988                                 i = target_pick(temp_y[m], temp_x[m], ddy[d], ddx[d]);
3989
3990                                 /* Request to target past last interesting grid */
3991                                 while (flag && (i < 0))
3992                                 {
3993                                         /* Note the change */
3994                                         if (change_panel(ddy[d], ddx[d]))
3995                                         {
3996                                                 int v = temp_y[m];
3997                                                 int u = temp_x[m];
3998
3999                                                 /* Recalculate interesting grids */
4000                                                 target_set_prepare(mode);
4001
4002                                                 /* Look at interesting grids */
4003                                                 flag = TRUE;
4004
4005                                                 /* Find a new monster */
4006                                                 i = target_pick(v, u, ddy[d], ddx[d]);
4007
4008                                                 /* Use that grid */
4009                                                 if (i >= 0) m = i;
4010                                         }
4011
4012                                         /* Nothing interesting */
4013                                         else
4014                                         {
4015                                                 int dx = ddx[d];
4016                                                 int dy = ddy[d];
4017
4018                                                 /* Restore previous position */
4019                                                 panel_row_min = y2;
4020                                                 panel_col_min = x2;
4021                                                 panel_bounds_center();
4022
4023                                                 /* Update stuff */
4024                                                 p_ptr->update |= (PU_MONSTERS);
4025
4026                                                 /* Redraw map */
4027                                                 p_ptr->redraw |= (PR_MAP);
4028
4029                                                 /* Window stuff */
4030                                                 p_ptr->window |= (PW_OVERHEAD);
4031
4032                                                 /* Handle stuff */
4033                                                 handle_stuff();
4034
4035                                                 /* Recalculate interesting grids */
4036                                                 target_set_prepare(mode);
4037
4038                                                 /* Look at boring grids */
4039                                                 flag = FALSE;
4040
4041                                                 /* Move */
4042                                                 x += dx;
4043                                                 y += dy;
4044
4045                                                 /* Do not move horizontally if unnecessary */
4046                                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4047                                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4048                                                 {
4049                                                         dx = 0;
4050                                                 }
4051
4052                                                 /* Do not move vertically if unnecessary */
4053                                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4054                                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4055                                                 {
4056                                                         dy = 0;
4057                                                 }
4058
4059                                                 /* Apply the motion */
4060                                                 if ((y >= panel_row_min+hgt) || (y < panel_row_min) ||
4061                                                     (x >= panel_col_min+wid) || (x < panel_col_min))
4062                                                 {
4063                                                         if (change_panel(dy, dx)) target_set_prepare(mode);
4064                                                 }
4065
4066                                                 /* Slide into legality */
4067                                                 if (x >= cur_wid-1) x = cur_wid - 2;
4068                                                 else if (x <= 0) x = 1;
4069
4070                                                 /* Slide into legality */
4071                                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4072                                                 else if (y <= 0) y = 1;
4073                                         }
4074                                 }
4075
4076                                 /* Use that grid */
4077                                 m = i;
4078                         }
4079                 }
4080
4081                 /* Arbitrary grids */
4082                 else
4083                 {
4084                         bool move_fast = FALSE;
4085
4086                         if (!(mode & TARGET_LOOK)) prt_path(y, x);
4087
4088                         /* Access */
4089                         c_ptr = &cave[y][x];
4090
4091                         /* Default prompt */
4092 #ifdef JP
4093 strcpy(info, "q»ß t·è p¼« m¶á +¼¡ -Á°");
4094 #else
4095                         strcpy(info, "q,t,p,m,+,-,<dir>");
4096 #endif
4097
4098
4099                         /* Describe and Prompt (enable "TARGET_LOOK") */
4100                         while (!(query = target_set_aux(y, x, mode | TARGET_LOOK, info)));
4101
4102                         /* Cancel tracking */
4103                         /* health_track(0); */
4104
4105                         /* Assume no direction */
4106                         d = 0;
4107
4108                         if (use_menu)
4109                         {
4110                                 if (query == '\r') query = 't';
4111                         }  
4112
4113                         /* Analyze the keypress */
4114                         switch (query)
4115                         {
4116                                 case ESCAPE:
4117                                 case 'q':
4118                                 {
4119                                         done = TRUE;
4120                                         break;
4121                                 }
4122
4123                                 case 't':
4124                                 case '.':
4125                                 case '5':
4126                                 case '0':
4127                                 {
4128                                         target_who = -1;
4129                                         target_row = y;
4130                                         target_col = x;
4131                                         done = TRUE;
4132                                         break;
4133                                 }
4134
4135                                 case 'p':
4136                                 {
4137                                         /* Recenter the map around the player */
4138                                         verify_panel();
4139
4140                                         /* Update stuff */
4141                                         p_ptr->update |= (PU_MONSTERS);
4142
4143                                         /* Redraw map */
4144                                         p_ptr->redraw |= (PR_MAP);
4145
4146                                         /* Window stuff */
4147                                         p_ptr->window |= (PW_OVERHEAD);
4148
4149                                         /* Handle stuff */
4150                                         handle_stuff();
4151
4152                                         /* Recalculate interesting grids */
4153                                         target_set_prepare(mode);
4154
4155                                         y = py;
4156                                         x = px;
4157                                 }
4158
4159                                 case 'o':
4160                                 {
4161                                         break;
4162                                 }
4163
4164                                 case ' ':
4165                                 case '*':
4166                                 case '+':
4167                                 case '-':
4168                                 case 'm':
4169                                 {
4170                                         flag = TRUE;
4171
4172                                         m = 0;
4173                                         bd = 999;
4174
4175                                         /* Pick a nearby monster */
4176                                         for (i = 0; i < temp_n; i++)
4177                                         {
4178                                                 t = distance(y, x, temp_y[i], temp_x[i]);
4179
4180                                                 /* Pick closest */
4181                                                 if (t < bd)
4182                                                 {
4183                                                         m = i;
4184                                                         bd = t;
4185                                                 }
4186                                         }
4187
4188                                         /* Nothing interesting */
4189                                         if (bd == 999) flag = FALSE;
4190
4191                                         break;
4192                                 }
4193
4194                                 default:
4195                                 {
4196                                         /* Extract the action (if any) */
4197                                         d = get_keymap_dir(query);
4198
4199                                         /* XTRA HACK MOVEFAST */
4200                                         if (isupper(query)) move_fast = TRUE;
4201
4202                                         if (!d) bell();
4203                                         break;
4204                                 }
4205                         }
4206
4207                         /* Handle "direction" */
4208                         if (d)
4209                         {
4210                                 int dx = ddx[d];
4211                                 int dy = ddy[d];
4212
4213                                 /* XTRA HACK MOVEFAST */
4214                                 if (move_fast)
4215                                 {
4216                                         int mag = MIN(wid / 2, hgt / 2);
4217                                         x += dx * mag;
4218                                         y += dy * mag;
4219                                 }
4220                                 else
4221                                 {
4222                                         x += dx;
4223                                         y += dy;
4224                                 }
4225
4226                                 /* Do not move horizontally if unnecessary */
4227                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
4228                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
4229                                 {
4230                                         dx = 0;
4231                                 }
4232
4233                                 /* Do not move vertically if unnecessary */
4234                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
4235                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
4236                                 {
4237                                         dy = 0;
4238                                 }
4239
4240                                 /* Apply the motion */
4241                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
4242                                          (x >= panel_col_min + wid) || (x < panel_col_min))
4243                                 {
4244                                         if (change_panel(dy, dx)) target_set_prepare(mode);
4245                                 }
4246
4247                                 /* Slide into legality */
4248                                 if (x >= cur_wid-1) x = cur_wid - 2;
4249                                 else if (x <= 0) x = 1;
4250
4251                                 /* Slide into legality */
4252                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
4253                                 else if (y <= 0) y = 1;
4254                         }
4255                 }
4256         }
4257
4258         /* Forget */
4259         temp_n = 0;
4260
4261         /* Clear the top line */
4262         prt("", 0, 0);
4263
4264         /* Recenter the map around the player */
4265         verify_panel();
4266
4267         /* Update stuff */
4268         p_ptr->update |= (PU_MONSTERS);
4269
4270         /* Redraw map */
4271         p_ptr->redraw |= (PR_MAP);
4272
4273         /* Window stuff */
4274         p_ptr->window |= (PW_OVERHEAD);
4275
4276         /* Handle stuff */
4277         handle_stuff();
4278
4279         /* Failure to set target */
4280         if (!target_who) return (FALSE);
4281
4282         /* Success */
4283         return (TRUE);
4284 }
4285
4286
4287 /*
4288  * Get an "aiming direction" from the user.
4289  *
4290  * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
4291  * "0" for "current target", and "-1" for "entry aborted".
4292  *
4293  * Note that "Force Target", if set, will pre-empt user interaction,
4294  * if there is a usable target already set.
4295  *
4296  * Note that confusion over-rides any (explicit?) user choice.
4297  */
4298 bool get_aim_dir(int *dp)
4299 {
4300         int             dir;
4301
4302         char    command;
4303
4304         cptr    p;
4305
4306         /* Initialize */
4307         (*dp) = 0;
4308
4309         /* Global direction */
4310         dir = command_dir;
4311
4312         /* Hack -- auto-target if requested */
4313         if (use_old_target && target_okay()) dir = 5;
4314
4315 #ifdef ALLOW_REPEAT /* TNB */
4316
4317         if (repeat_pull(dp))
4318         {
4319                 /* Confusion? */
4320
4321                 /* Verify */
4322                 if (!(*dp == 5 && !target_okay()))
4323                 {
4324 /*                      return (TRUE); */
4325                         dir = *dp;
4326                 }
4327         }
4328
4329 #endif /* ALLOW_REPEAT -- TNB */
4330
4331         /* Ask until satisfied */
4332         while (!dir)
4333         {
4334                 /* Choose a prompt */
4335                 if (!target_okay())
4336                 {
4337 #ifdef JP
4338 p = "Êý¸þ ('*'¤Ç¥¿¡¼¥²¥Ã¥ÈÁªÂò, ESC¤ÇÃæÃÇ)? ";
4339 #else
4340                         p = "Direction ('*' to choose a target, Escape to cancel)? ";
4341 #endif
4342
4343                 }
4344                 else
4345                 {
4346 #ifdef JP
4347 p = "Êý¸þ ('5'¤Ç¥¿¡¼¥²¥Ã¥È¤Ø, '*'¤Ç¥¿¡¼¥²¥Ã¥ÈºÆÁªÂò, ESC¤ÇÃæÃÇ)? ";
4348 #else
4349                         p = "Direction ('5' for target, '*' to re-target, Escape to cancel)? ";
4350 #endif
4351
4352                 }
4353
4354                 /* Get a command (or Cancel) */
4355                 if (!get_com(p, &command, TRUE)) break;
4356
4357                 if (use_menu)
4358                 {
4359                         if (command == '\r') command = 't';
4360                 }  
4361
4362                 /* Convert various keys to "standard" keys */
4363                 switch (command)
4364                 {
4365                         /* Use current target */
4366                         case 'T':
4367                         case 't':
4368                         case '.':
4369                         case '5':
4370                         case '0':
4371                         {
4372                                 dir = 5;
4373                                 break;
4374                         }
4375
4376                         /* Set new target */
4377                         case '*':
4378                         case ' ':
4379                         case '\r':
4380                         {
4381                                 if (target_set(TARGET_KILL)) dir = 5;
4382                                 break;
4383                         }
4384
4385                         default:
4386                         {
4387                                 /* Extract the action (if any) */
4388                                 dir = get_keymap_dir(command);
4389
4390                                 break;
4391                         }
4392                 }
4393
4394                 /* Verify requested targets */
4395                 if ((dir == 5) && !target_okay()) dir = 0;
4396
4397                 /* Error */
4398                 if (!dir) bell();
4399         }
4400
4401         /* No direction */
4402         if (!dir)
4403         {
4404                 project_length = 0; /* reset to default */
4405                 return (FALSE);
4406         }
4407
4408         /* Save the direction */
4409         command_dir = dir;
4410
4411         /* Check for confusion */
4412         if (p_ptr->confused)
4413         {
4414                 /* XXX XXX XXX */
4415                 /* Random direction */
4416                 dir = ddd[randint0(8)];
4417         }
4418
4419         /* Notice confusion */
4420         if (command_dir != dir)
4421         {
4422                 /* Warn the user */
4423 #ifdef JP
4424 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4425 #else
4426                 msg_print("You are confused.");
4427 #endif
4428
4429         }
4430
4431         /* Save direction */
4432         (*dp) = dir;
4433
4434 #ifdef ALLOW_REPEAT /* TNB */
4435
4436 /*      repeat_push(dir); */
4437         repeat_push(command_dir);
4438
4439 #endif /* ALLOW_REPEAT -- TNB */
4440
4441         /* A "valid" direction was entered */
4442         return (TRUE);
4443 }
4444
4445
4446
4447 /*
4448  * Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
4449  * and place it into "command_dir", unless we already have one.
4450  *
4451  * This function should be used for all "repeatable" commands, such as
4452  * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
4453  * as all commands which must reference a grid adjacent to the player,
4454  * and which may not reference the grid under the player.  Note that,
4455  * for example, it is no longer possible to "disarm" or "open" chests
4456  * in the same grid as the player.
4457  *
4458  * Direction "5" is illegal and will (cleanly) abort the command.
4459  *
4460  * This function tracks and uses the "global direction", and uses
4461  * that as the "desired direction", to which "confusion" is applied.
4462  */
4463 bool get_rep_dir(int *dp, bool under)
4464 {
4465         int dir;
4466
4467         /* Initialize */
4468         (*dp) = 0;
4469
4470         /* Global direction */
4471         dir = command_dir;
4472
4473 #ifdef ALLOW_REPEAT /* TNB */
4474
4475         if (repeat_pull(dp))
4476         {
4477                 dir = *dp;
4478 /*              return (TRUE); */
4479         }
4480
4481 #endif /* ALLOW_REPEAT -- TNB */
4482
4483         /* Get a direction */
4484         while (!dir)
4485         {
4486                 char ch;
4487
4488                 /* Get a command (or Cancel) */
4489 #ifdef JP
4490 if (!get_com("Êý¸þ (ESC¤ÇÃæÃÇ)? ", &ch, TRUE)) break;
4491 #else
4492                 if (!get_com("Direction (Escape to cancel)? ", &ch, TRUE)) break;
4493 #endif
4494
4495
4496                 /* Look up the direction */
4497                 dir = get_keymap_dir(ch);
4498
4499                 /* Oops */
4500                 if (!dir) bell();
4501         }
4502
4503         /* Prevent weirdness */
4504         if ((dir == 5) && (!under)) dir = 0;
4505
4506         /* Aborted */
4507         if (!dir) return (FALSE);
4508
4509         /* Save desired direction */
4510         command_dir = dir;
4511
4512         /* Apply "confusion" */
4513         if (p_ptr->confused)
4514         {
4515                 /* Standard confusion */
4516                 if (randint0(100) < 75)
4517                 {
4518                         /* Random direction */
4519                         dir = ddd[randint0(8)];
4520                 }
4521         }
4522         else if (p_ptr->riding)
4523         {
4524                 monster_type *m_ptr = &m_list[p_ptr->riding];
4525                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4526
4527                 if (MON_CONFUSED(m_ptr))
4528                 {
4529                         /* Standard confusion */
4530                         if (randint0(100) < 75)
4531                         {
4532                                 /* Random direction */
4533                                 dir = ddd[randint0(8)];
4534                         }
4535                 }
4536                 else if ((r_ptr->flags1 & RF1_RAND_50) && (r_ptr->flags1 & RF1_RAND_25) && (randint0(100) < 50))
4537                 {
4538                         /* Random direction */
4539                         dir = ddd[randint0(8)];
4540                 }
4541                 else if ((r_ptr->flags1 & RF1_RAND_50) && (randint0(100) < 25))
4542                 {
4543                         /* Random direction */
4544                         dir = ddd[randint0(8)];
4545                 }
4546         }
4547
4548         /* Notice confusion */
4549         if (command_dir != dir)
4550         {
4551                 if (p_ptr->confused)
4552                 {
4553                         /* Warn the user */
4554 #ifdef JP
4555 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4556 #else
4557                         msg_print("You are confused.");
4558 #endif
4559                 }
4560                 else
4561                 {
4562                         char m_name[80];
4563                         monster_type *m_ptr = &m_list[p_ptr->riding];
4564
4565                         monster_desc(m_name, m_ptr, 0);
4566                         if (MON_CONFUSED(m_ptr))
4567                         {
4568 #ifdef JP
4569 msg_format("%s¤Ïº®Í𤷤Ƥ¤¤ë¡£", m_name);
4570 #else
4571  msg_format("%^s is confusing.", m_name);
4572
4573 #endif
4574                         }
4575                         else
4576                         {
4577 #ifdef JP
4578 msg_format("%s¤Ï»×¤¤Ä̤ê¤ËÆ°¤¤¤Æ¤¯¤ì¤Ê¤¤¡£", m_name);
4579 #else
4580 msg_format("You cannot control %s.", m_name);
4581 #endif
4582                         }
4583                 }
4584         }
4585
4586         /* Save direction */
4587         (*dp) = dir;
4588
4589 #ifdef ALLOW_REPEAT /* TNB */
4590
4591 /*      repeat_push(dir); */
4592         repeat_push(command_dir);
4593
4594 #endif /* ALLOW_REPEAT -- TNB */
4595
4596         /* Success */
4597         return (TRUE);
4598 }
4599
4600
4601 bool get_rep_dir2(int *dp)
4602 {
4603         int dir;
4604
4605         /* Initialize */
4606         (*dp) = 0;
4607
4608         /* Global direction */
4609         dir = command_dir;
4610
4611 #ifdef ALLOW_REPEAT /* TNB */
4612
4613         if (repeat_pull(dp))
4614         {
4615                 dir = *dp;
4616 /*              return (TRUE); */
4617         }
4618
4619 #endif /* ALLOW_REPEAT -- TNB */
4620
4621         /* Get a direction */
4622         while (!dir)
4623         {
4624                 char ch;
4625
4626                 /* Get a command (or Cancel) */
4627 #ifdef JP
4628 if (!get_com("Êý¸þ (ESC¤ÇÃæÃÇ)? ", &ch, TRUE)) break;
4629 #else
4630                 if (!get_com("Direction (Escape to cancel)? ", &ch, TRUE)) break;
4631 #endif
4632
4633
4634                 /* Look up the direction */
4635                 dir = get_keymap_dir(ch);
4636
4637                 /* Oops */
4638                 if (!dir) bell();
4639         }
4640
4641         /* Prevent weirdness */
4642         if (dir == 5) dir = 0;
4643
4644         /* Aborted */
4645         if (!dir) return (FALSE);
4646
4647         /* Save desired direction */
4648         command_dir = dir;
4649
4650         /* Apply "confusion" */
4651         if (p_ptr->confused)
4652         {
4653                 /* Standard confusion */
4654                 if (randint0(100) < 75)
4655                 {
4656                         /* Random direction */
4657                         dir = ddd[randint0(8)];
4658                 }
4659         }
4660
4661         /* Notice confusion */
4662         if (command_dir != dir)
4663         {
4664                 /* Warn the user */
4665 #ifdef JP
4666 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
4667 #else
4668                 msg_print("You are confused.");
4669 #endif
4670
4671         }
4672
4673         /* Save direction */
4674         (*dp) = dir;
4675
4676 #ifdef ALLOW_REPEAT /* TNB */
4677
4678 /*      repeat_push(dir); */
4679         repeat_push(command_dir);
4680
4681 #endif /* ALLOW_REPEAT -- TNB */
4682
4683         /* Success */
4684         return (TRUE);
4685 }
4686
4687
4688 void gain_level_reward(int chosen_reward)
4689 {
4690         object_type *q_ptr;
4691         object_type forge;
4692         char        wrath_reason[32] = "";
4693         int         nasty_chance = 6;
4694         int         dummy = 0, dummy2 = 0;
4695         int         type, effect;
4696         cptr        reward = NULL;
4697         char o_name[MAX_NLEN];
4698
4699         int count = 0;
4700
4701         if (!chosen_reward)
4702         {
4703                 if (multi_rew) return;
4704                 else multi_rew = TRUE;
4705         }
4706
4707
4708         if (p_ptr->lev == 13) nasty_chance = 2;
4709         else if (!(p_ptr->lev % 13)) nasty_chance = 3;
4710         else if (!(p_ptr->lev % 14)) nasty_chance = 12;
4711
4712         if (one_in_(nasty_chance))
4713                 type = randint1(20); /* Allow the 'nasty' effects */
4714         else
4715                 type = randint1(15) + 5; /* Or disallow them */
4716
4717         if (type < 1) type = 1;
4718         if (type > 20) type = 20;
4719         type--;
4720
4721
4722 #ifdef JP
4723 sprintf(wrath_reason, "%s¤ÎÅܤê",
4724                 chaos_patrons[p_ptr->chaos_patron]);
4725 #else
4726         sprintf(wrath_reason, "the Wrath of %s",
4727                 chaos_patrons[p_ptr->chaos_patron]);
4728 #endif
4729
4730
4731         effect = chaos_rewards[p_ptr->chaos_patron][type];
4732
4733         if (one_in_(6) && !chosen_reward)
4734         {
4735 #ifdef JP
4736 msg_format("%^s¤ÏË«Èþ¤È¤·¤Æ¤¢¤Ê¤¿¤òÆÍÁ³ÊÑ°Û¤µ¤»¤¿¡£",
4737                         chaos_patrons[p_ptr->chaos_patron]);
4738 #else
4739                 msg_format("%^s rewards you with a mutation!",
4740                         chaos_patrons[p_ptr->chaos_patron]);
4741 #endif
4742
4743                 (void)gain_random_mutation(0);
4744 #ifdef JP
4745                 reward = "ÊÑ°Û¤·¤¿¡£";
4746 #else
4747                 reward = "mutation";
4748 #endif
4749         }
4750         else
4751         {
4752         switch (chosen_reward ? chosen_reward : effect)
4753         {
4754                 case REW_POLY_SLF:
4755 #ifdef JP
4756 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4757                                 chaos_patrons[p_ptr->chaos_patron]);
4758 #else
4759                         msg_format("The voice of %s booms out:",
4760                                 chaos_patrons[p_ptr->chaos_patron]);
4761 #endif
4762
4763 #ifdef JP
4764 msg_print("¡ÖÆò¡¢¿·¤¿¤Ê¤ë»Ñ¤òɬÍפȤ»¤ê¡ª¡×");
4765 #else
4766                         msg_print("'Thou needst a new form, mortal!'");
4767 #endif
4768
4769                         do_poly_self();
4770 #ifdef JP
4771                         reward = "ÊÑ°Û¤·¤¿¡£";
4772 #else
4773                         reward = "polymorphing";
4774 #endif
4775                         break;
4776                 case REW_GAIN_EXP:
4777 #ifdef JP
4778 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4779                                 chaos_patrons[p_ptr->chaos_patron]);
4780 #else
4781                         msg_format("The voice of %s booms out:",
4782                                 chaos_patrons[p_ptr->chaos_patron]);
4783 #endif
4784
4785 #ifdef JP
4786 msg_print("¡ÖÆò¤ÏÎɤ¯¹Ô¤¤¤¿¤ê¡ªÂ³¤±¤è¡ª¡×");
4787 #else
4788                         msg_print("'Well done, mortal! Lead on!'");
4789 #endif
4790
4791                         if (p_ptr->prace == RACE_ANDROID)
4792                         {
4793 #ifdef JP
4794                                 msg_print("¤·¤«¤·²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
4795 #else
4796                                 msg_print("But, nothing happen.");
4797 #endif
4798                         }
4799                         else if (p_ptr->exp < PY_MAX_EXP)
4800                         {
4801                                 s32b ee = (p_ptr->exp / 2) + 10;
4802                                 if (ee > 100000L) ee = 100000L;
4803 #ifdef JP
4804 msg_print("¹¹¤Ë·Ð¸³¤òÀѤó¤À¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
4805 #else
4806                                 msg_print("You feel more experienced.");
4807 #endif
4808
4809                                 gain_exp(ee);
4810 #ifdef JP
4811                                 reward = "·Ð¸³ÃͤòÆÀ¤¿";
4812 #else
4813                                 reward = "experience";
4814 #endif
4815                         }
4816                         break;
4817                 case REW_LOSE_EXP:
4818 #ifdef JP
4819 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4820                                 chaos_patrons[p_ptr->chaos_patron]);
4821 #else
4822                         msg_format("The voice of %s booms out:",
4823                                 chaos_patrons[p_ptr->chaos_patron]);
4824 #endif
4825
4826 #ifdef JP
4827 msg_print("¡Ö²¼Ëͤ衢Æò¤½¤ì¤ËÃͤ»¤º¡£¡×");
4828 #else
4829                         msg_print("'Thou didst not deserve that, slave.'");
4830 #endif
4831
4832                         if (p_ptr->prace == RACE_ANDROID)
4833                         {
4834 #ifdef JP
4835                                 msg_print("¤·¤«¤·²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
4836 #else
4837                                 msg_print("But, nothing happen.");
4838 #endif
4839                         }
4840                         else
4841                         {
4842                                 lose_exp(p_ptr->exp / 6);
4843 #ifdef JP
4844                                 reward = "·Ð¸³Ãͤò¼º¤Ã¤¿¡£";
4845 #else
4846                                 reward = "losing experience";
4847 #endif
4848                         }
4849                         break;
4850                 case REW_GOOD_OBJ:
4851 #ifdef JP
4852 msg_format("%s¤ÎÀ¼¤¬¤µ¤µ¤ä¤¤¤¿:",
4853                                 chaos_patrons[p_ptr->chaos_patron]);
4854 #else
4855                         msg_format("The voice of %s whispers:",
4856                                 chaos_patrons[p_ptr->chaos_patron]);
4857 #endif
4858
4859 #ifdef JP
4860 msg_print("¡Ö²æ¤¬Í¿¤¨¤·Êª¤ò¸­ÌÀ¤Ë»È¤¦¤Ù¤·¡£¡×");
4861 #else
4862                         msg_print("'Use my gift wisely.'");
4863 #endif
4864
4865                         acquirement(py, px, 1, FALSE, FALSE);
4866 #ifdef JP
4867                         reward = "¾å¼Á¤Ê¥¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4868 #else
4869                         reward = "a good item";
4870 #endif
4871                         break;
4872                 case REW_GREA_OBJ:
4873 #ifdef JP
4874 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4875                                 chaos_patrons[p_ptr->chaos_patron]);
4876 #else
4877                         msg_format("The voice of %s booms out:",
4878                                 chaos_patrons[p_ptr->chaos_patron]);
4879 #endif
4880
4881 #ifdef JP
4882 msg_print("¡Ö²æ¤¬Í¿¤¨¤·Êª¤ò¸­ÌÀ¤Ë»È¤¦¤Ù¤·¡£¡×");
4883 #else
4884                         msg_print("'Use my gift wisely.'");
4885 #endif
4886
4887                         acquirement(py, px, 1, TRUE, FALSE);
4888 #ifdef JP
4889                         reward = "¹âµéÉʤΥ¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
4890 #else
4891                         reward = "an excellent item";
4892 #endif
4893                         break;
4894                 case REW_CHAOS_WP:
4895 #ifdef JP
4896 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
4897                                 chaos_patrons[p_ptr->chaos_patron]);
4898 #else
4899                         msg_format("The voice of %s booms out:",
4900                                 chaos_patrons[p_ptr->chaos_patron]);
4901 #endif
4902
4903 #ifdef JP
4904 msg_print("¡ÖÆò¤Î¹Ô¤¤¤Ïµ®¤­·õ¤ËÃͤ»¤ê¡£¡×");
4905 #else
4906                         msg_print("'Thy deed hath earned thee a worthy blade.'");
4907 #endif
4908
4909                         /* Get local object */
4910                         q_ptr = &forge;
4911                         dummy = TV_SWORD;
4912                         switch (randint1(p_ptr->lev))
4913                         {
4914                                 case 0: case 1:
4915                                         dummy2 = SV_DAGGER;
4916                                         break;
4917                                 case 2: case 3:
4918                                         dummy2 = SV_MAIN_GAUCHE;
4919                                         break;
4920                                 case 4:
4921                                         dummy2 = SV_TANTO;
4922                                         break;
4923                                 case 5: case 6:
4924                                         dummy2 = SV_RAPIER;
4925                                         break;
4926                                 case 7: case 8:
4927                                         dummy2 = SV_SMALL_SWORD;
4928                                         break;
4929                                 case 9: case 10:
4930                                         dummy2 = SV_BASILLARD;
4931                                         break;
4932                                 case 11: case 12: case 13:
4933                                         dummy2 = SV_SHORT_SWORD;
4934                                         break;
4935                                 case 14: case 15:
4936                                         dummy2 = SV_SABRE;
4937                                         break;
4938                                 case 16: case 17:
4939                                         dummy2 = SV_CUTLASS;
4940                                         break;
4941                                 case 18:
4942                                         dummy2 = SV_WAKIZASHI;
4943                                         break;
4944                                 case 19:
4945                                         dummy2 = SV_KHOPESH;
4946                                         break;
4947                                 case 20:
4948                                         dummy2 = SV_TULWAR;
4949                                         break;
4950                                 case 21:
4951                                         dummy2 = SV_BROAD_SWORD;
4952                                         break;
4953                                 case 22: case 23:
4954                                         dummy2 = SV_LONG_SWORD;
4955                                         break;
4956                                 case 24: case 25:
4957                                         dummy2 = SV_SCIMITAR;
4958                                         break;
4959                                 case 26:
4960                                         dummy2 = SV_NINJATO;
4961                                         break;
4962                                 case 27:
4963                                         dummy2 = SV_KATANA;
4964                                         break;
4965                                 case 28: case 29:
4966                                         dummy2 = SV_BASTARD_SWORD;
4967                                         break;
4968                                 case 30:
4969                                         dummy2 = SV_GREAT_SCIMITAR;
4970                                         break;
4971                                 case 31:
4972                                         dummy2 = SV_CLAYMORE;
4973                                         break;
4974                                 case 32:
4975                                         dummy2 = SV_ESPADON;
4976                                         break;
4977                                 case 33:
4978                                         dummy2 = SV_TWO_HANDED_SWORD;
4979                                         break;
4980                                 case 34:
4981                                         dummy2 = SV_FLAMBERGE;
4982                                         break;
4983                                 case 35:
4984                                         dummy2 = SV_NO_DACHI;
4985                                         break;
4986                                 case 36:
4987                                         dummy2 = SV_EXECUTIONERS_SWORD;
4988                                         break;
4989                                 case 37:
4990                                         dummy2 = SV_ZWEIHANDER;
4991                                         break;
4992                                 case 38:
4993                                         dummy2 = SV_HAYABUSA;
4994                                         break;
4995                                 default:
4996                                         dummy2 = SV_BLADE_OF_CHAOS;
4997                         }
4998
4999                         object_prep(q_ptr, lookup_kind(dummy, dummy2));
5000                         q_ptr->to_h = 3 + randint1(dun_level) % 10;
5001                         q_ptr->to_d = 3 + randint1(dun_level) % 10;
5002                         one_resistance(q_ptr);
5003                         q_ptr->name2 = EGO_CHAOTIC;
5004
5005                         /* Drop it in the dungeon */
5006                         (void)drop_near(q_ptr, -1, py, px);
5007 #ifdef JP
5008                         reward = "(º®ÆÙ)¤ÎÉð´ï¤ò¼ê¤ËÆþ¤ì¤¿¡£";
5009 #else
5010                         reward = "chaos weapon";
5011 #endif
5012                         break;
5013                 case REW_GOOD_OBS:
5014 #ifdef JP
5015 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5016                                 chaos_patrons[p_ptr->chaos_patron]);
5017 #else
5018                         msg_format("The voice of %s booms out:",
5019                                 chaos_patrons[p_ptr->chaos_patron]);
5020 #endif
5021
5022 #ifdef JP
5023 msg_print("¡ÖÆò¤Î¹Ô¤¤¤Ïµ®¤­Ê󤤤ËÃͤ»¤ê¡£¡×");
5024 #else
5025                         msg_print("'Thy deed hath earned thee a worthy reward.'");
5026 #endif
5027
5028                         acquirement(py, px, randint1(2) + 1, FALSE, FALSE);
5029 #ifdef JP
5030                         reward = "¾å¼Á¤Ê¥¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
5031 #else
5032                         reward = "good items";
5033 #endif
5034                         break;
5035                 case REW_GREA_OBS:
5036 #ifdef JP
5037 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5038                                 chaos_patrons[p_ptr->chaos_patron]);
5039 #else
5040                         msg_format("The voice of %s booms out:",
5041                                 chaos_patrons[p_ptr->chaos_patron]);
5042 #endif
5043
5044 #ifdef JP
5045 msg_print("¡Ö²¼Ëͤ衢Æò¤Î¸¥¿È¤Ø¤Î²æ¤¬Àˤ·¤ß̵¤­Ê󤤤ò¸«¤ë¤¬¤è¤¤¡£¡×");
5046 #else
5047                         msg_print("'Behold, mortal, how generously I reward thy loyalty.'");
5048 #endif
5049
5050                         acquirement(py, px, randint1(2) + 1, TRUE, FALSE);
5051 #ifdef JP
5052                         reward = "¹âµéÉʤΥ¢¥¤¥Æ¥à¤ò¼ê¤ËÆþ¤ì¤¿¡£";
5053 #else
5054                         reward = "excellent items";
5055 #endif
5056                         break;
5057                 case REW_TY_CURSE:
5058 #ifdef JP
5059 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5060                                 chaos_patrons[p_ptr->chaos_patron]);
5061 #else
5062                         msg_format("The voice of %s thunders:",
5063                                 chaos_patrons[p_ptr->chaos_patron]);
5064 #endif
5065
5066 #ifdef JP
5067 msg_print("¡Ö²¼Ëͤ衢ÆòÐþËý¤Ê¤ê¡£¡×");
5068 #else
5069                         msg_print("'Thou art growing arrogant, mortal.'");
5070 #endif
5071
5072                         (void)activate_ty_curse(FALSE, &count);
5073 #ifdef JP
5074                         reward = "²Ò¡¹¤·¤¤¼ö¤¤¤ò¤«¤±¤é¤ì¤¿¡£";
5075 #else
5076                         reward = "cursing";
5077 #endif
5078                         break;
5079                 case REW_SUMMON_M:
5080 #ifdef JP
5081 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5082                                 chaos_patrons[p_ptr->chaos_patron]);
5083 #else
5084                         msg_format("The voice of %s booms out:",
5085                                 chaos_patrons[p_ptr->chaos_patron]);
5086 #endif
5087
5088 #ifdef JP
5089 msg_print("¡Ö²æ¤¬²¼Ëͤ¿¤Á¤è¡¢¤«¤ÎÐþËý¤Ê¤ë¼Ô¤òÅݤ¹¤Ù¤·¡ª¡×");
5090 #else
5091                         msg_print("'My pets, destroy the arrogant mortal!'");
5092 #endif
5093
5094                         for (dummy = 0; dummy < randint1(5) + 1; dummy++)
5095                         {
5096                                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
5097                         }
5098 #ifdef JP
5099                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
5100 #else
5101                         reward = "summoning hostile monsters";
5102 #endif
5103                         break;
5104                 case REW_H_SUMMON:
5105 #ifdef JP
5106 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5107                                 chaos_patrons[p_ptr->chaos_patron]);
5108 #else
5109                         msg_format("The voice of %s booms out:",
5110                                 chaos_patrons[p_ptr->chaos_patron]);
5111 #endif
5112
5113 #ifdef JP
5114 msg_print("¡ÖÆò¡¢¤è¤ê¶¯¤­Å¨¤òɬÍפȤ»¤ê¡ª¡×");
5115 #else
5116                         msg_print("'Thou needst worthier opponents!'");
5117 #endif
5118
5119                         activate_hi_summon(py, px, FALSE);
5120 #ifdef JP
5121                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
5122 #else
5123                         reward = "summoning many hostile monsters";
5124 #endif
5125                         break;
5126                 case REW_DO_HAVOC:
5127 #ifdef JP
5128 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5129                                 chaos_patrons[p_ptr->chaos_patron]);
5130 #else
5131                         msg_format("The voice of %s booms out:",
5132                                 chaos_patrons[p_ptr->chaos_patron]);
5133 #endif
5134
5135 #ifdef JP
5136 msg_print("¡Ö»à¤ÈÇ˲õ¤³¤½²æ¤¬´î¤Ó¤Ê¤ê¡ª¡×");
5137 #else
5138                         msg_print("'Death and destruction! This pleaseth me!'");
5139 #endif
5140
5141                         call_chaos();
5142 #ifdef JP
5143                         reward = "¥«¥ª¥¹¤ÎÎϤ¬±²´¬¤¤¤¿¡£";
5144 #else
5145                         reward = "calling chaos";
5146 #endif
5147                         break;
5148                 case REW_GAIN_ABL:
5149 #ifdef JP
5150 msg_format("%s¤ÎÀ¼¤¬ÌĤê¶Á¤¤¤¿:",
5151                                 chaos_patrons[p_ptr->chaos_patron]);
5152 #else
5153                         msg_format("The voice of %s rings out:",
5154                                 chaos_patrons[p_ptr->chaos_patron]);
5155 #endif
5156
5157 #ifdef JP
5158 msg_print("¡Öα¤Þ¤ë¤Î¤À¡¢²¼Ëͤ衣;¤¬Æò¤ÎÆùÂΤòÃ䨤󡣡×");
5159 #else
5160                         msg_print("'Stay, mortal, and let me mold thee.'");
5161 #endif
5162
5163                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
5164                                 do_inc_stat(chaos_stats[p_ptr->chaos_patron]);
5165                         else
5166                                 do_inc_stat(randint0(6));
5167 #ifdef JP
5168                         reward = "ǽÎÏÃͤ¬¾å¤¬¤Ã¤¿¡£";
5169 #else
5170                         reward = "increasing a stat";
5171 #endif
5172                         break;
5173                 case REW_LOSE_ABL:
5174 #ifdef JP
5175 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5176                                 chaos_patrons[p_ptr->chaos_patron]);
5177 #else
5178                         msg_format("The voice of %s booms out:",
5179                                 chaos_patrons[p_ptr->chaos_patron]);
5180 #endif
5181
5182 #ifdef JP
5183 msg_print("¡Ö²¼Ëͤ衢;¤ÏÆò¤ËË°¤ß¤¿¤ê¡£¡×");
5184 #else
5185                         msg_print("'I grow tired of thee, mortal.'");
5186 #endif
5187
5188                         if (one_in_(3) && !(chaos_stats[p_ptr->chaos_patron] < 0))
5189                                 do_dec_stat(chaos_stats[p_ptr->chaos_patron]);
5190                         else
5191                                 (void)do_dec_stat(randint0(6));
5192 #ifdef JP
5193                         reward = "ǽÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5194 #else
5195                         reward = "decreasing a stat";
5196 #endif
5197                         break;
5198                 case REW_RUIN_ABL:
5199 #ifdef JP
5200 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5201                                 chaos_patrons[p_ptr->chaos_patron]);
5202 #else
5203                         msg_format("The voice of %s thunders:",
5204                                 chaos_patrons[p_ptr->chaos_patron]);
5205 #endif
5206
5207 #ifdef JP
5208 msg_print("¡ÖÆò¡¢¸¬µõ¤¿¤ë¤³¤È¤ò³Ø¤Ö¤Ù¤·¡ª¡×");
5209 msg_print("¤¢¤Ê¤¿¤Ï°ÊÁ°¤è¤ê¼å¤¯¤Ê¤Ã¤¿¡ª");
5210 #else
5211                         msg_print("'Thou needst a lesson in humility, mortal!'");
5212                         msg_print("You feel less powerful!");
5213 #endif
5214
5215                         for (dummy = 0; dummy < 6; dummy++)
5216                         {
5217                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5218                         }
5219 #ifdef JP
5220                         reward = "Á´Ç½ÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5221 #else
5222                         reward = "decreasing all stats";
5223 #endif
5224                         break;
5225                 case REW_POLY_WND:
5226 #ifdef JP
5227 msg_format("%s¤ÎÎϤ¬¿¨¤ì¤ë¤Î¤ò´¶¤¸¤¿¡£",
5228 #else
5229                         msg_format("You feel the power of %s touch you.",
5230 #endif
5231
5232                                 chaos_patrons[p_ptr->chaos_patron]);
5233                         do_poly_wounds();
5234 #ifdef JP
5235                         reward = "½ý¤¬ÊѲ½¤·¤¿¡£";
5236 #else
5237                         reward = "polymorphing wounds";
5238 #endif
5239                         break;
5240                 case REW_AUGM_ABL:
5241 #ifdef JP
5242 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5243                                 chaos_patrons[p_ptr->chaos_patron]);
5244 #else
5245                         msg_format("The voice of %s booms out:",
5246                                 chaos_patrons[p_ptr->chaos_patron]);
5247 #endif
5248
5249 #ifdef JP
5250 msg_print("¡Ö²æ¤¬¤µ¤µ¤ä¤«¤Ê¤ë»òʪ¤ò¼õ¤±¤È¤ë¤¬¤è¤¤¡ª¡×");
5251 #else
5252                         msg_print("'Receive this modest gift from me!'");
5253 #endif
5254
5255                         for (dummy = 0; dummy < 6; dummy++)
5256                         {
5257                                 (void)do_inc_stat(dummy);
5258                         }
5259 #ifdef JP
5260                         reward = "Á´Ç½ÎÏÃͤ¬¾å¤¬¤Ã¤¿¡£";
5261 #else
5262                         reward = "increasing all stats";
5263 #endif
5264                         break;
5265                 case REW_HURT_LOT:
5266 #ifdef JP
5267 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5268                                 chaos_patrons[p_ptr->chaos_patron]);
5269 #else
5270                         msg_format("The voice of %s booms out:",
5271                                 chaos_patrons[p_ptr->chaos_patron]);
5272 #endif
5273
5274 #ifdef JP
5275 msg_print("¡Ö¶ì¤·¤à¤¬¤è¤¤¡¢ÌµÇ½¤Ê¶ò¤«¼Ô¤è¡ª¡×");
5276 #else
5277                         msg_print("'Suffer, pathetic fool!'");
5278 #endif
5279
5280                         fire_ball(GF_DISINTEGRATE, 0, p_ptr->lev * 4, 4);
5281                         take_hit(DAMAGE_NOESCAPE, p_ptr->lev * 4, wrath_reason, -1);
5282 #ifdef JP
5283                         reward = "ʬ²ò¤Îµå¤¬È¯À¸¤·¤¿¡£";
5284 #else
5285                         reward = "generating disintegration ball";
5286 #endif
5287                         break;
5288            case REW_HEAL_FUL:
5289 #ifdef JP
5290 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5291                                 chaos_patrons[p_ptr->chaos_patron]);
5292 #else
5293                         msg_format("The voice of %s booms out:",
5294                                 chaos_patrons[p_ptr->chaos_patron]);
5295 #endif
5296
5297 #ifdef JP
5298 msg_print("¡Öᴤ뤬¤è¤¤¡¢²æ¤¬²¼Ëͤ衪¡×");
5299 #else
5300                         msg_print("'Rise, my servant!'");
5301 #endif
5302
5303                         restore_level();
5304                         (void)set_poisoned(0);
5305                         (void)set_blind(0);
5306                         (void)set_confused(0);
5307                         (void)set_image(0);
5308                         (void)set_stun(0);
5309                         (void)set_cut(0);
5310                         hp_player(5000);
5311                         for (dummy = 0; dummy < 6; dummy++)
5312                         {
5313                                 (void)do_res_stat(dummy);
5314                         }
5315 #ifdef JP
5316                         reward = "ÂÎÎϤ¬²óÉü¤·¤¿¡£";
5317 #else
5318                         reward = "healing";
5319 #endif
5320                         break;
5321                 case REW_CURSE_WP:
5322                         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
5323 #ifdef JP
5324 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5325                                 chaos_patrons[p_ptr->chaos_patron]);
5326 #else
5327                         msg_format("The voice of %s booms out:",
5328                                 chaos_patrons[p_ptr->chaos_patron]);
5329 #endif
5330
5331 #ifdef JP
5332 msg_print("¡ÖÆò¡¢Éð´ï¤ËÍê¤ë¤³¤È¤Ê¤«¤ì¡£¡×");
5333 #else
5334                         msg_print("'Thou reliest too much on thy weapon.'");
5335 #endif
5336
5337                         dummy = INVEN_RARM;
5338                         if (buki_motteruka(INVEN_LARM))
5339                         {
5340                                 dummy = INVEN_LARM;
5341                                 if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
5342                         }
5343                         object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
5344                         (void)curse_weapon(FALSE, dummy);
5345 #ifdef JP
5346                         reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5347 #else
5348                         reward = format("destroying %s", o_name);
5349 #endif
5350                         break;
5351                 case REW_CURSE_AR:
5352                         if (!inventory[INVEN_BODY].k_idx) break;
5353 #ifdef JP
5354 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5355                                 chaos_patrons[p_ptr->chaos_patron]);
5356 #else
5357                         msg_format("The voice of %s booms out:",
5358                                 chaos_patrons[p_ptr->chaos_patron]);
5359 #endif
5360
5361 #ifdef JP
5362 msg_print("¡ÖÆò¡¢Ëɶñ¤ËÍê¤ë¤³¤È¤Ê¤«¤ì¡£¡×");
5363 #else
5364                         msg_print("'Thou reliest too much on thine equipment.'");
5365 #endif
5366
5367                         object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
5368                         (void)curse_armor();
5369 #ifdef JP
5370                         reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5371 #else
5372                         reward = format("destroying %s", o_name);
5373 #endif
5374                         break;
5375                 case REW_PISS_OFF:
5376 #ifdef JP
5377 msg_format("%s¤ÎÀ¼¤¬¤µ¤µ¤ä¤¤¤¿:",
5378                                 chaos_patrons[p_ptr->chaos_patron]);
5379 #else
5380                         msg_format("The voice of %s whispers:",
5381                                 chaos_patrons[p_ptr->chaos_patron]);
5382 #endif
5383
5384 #ifdef JP
5385 msg_print("¡Ö²æ¤òÅܤꤷ¤á¤¿ºá¤ò½þ¤¦¤Ù¤·¡£¡×");
5386 #else
5387                         msg_print("'Now thou shalt pay for annoying me.'");
5388 #endif
5389
5390                         switch (randint1(4))
5391                         {
5392                                 case 1:
5393                                         (void)activate_ty_curse(FALSE, &count);
5394 #ifdef JP
5395                                         reward = "²Ò¡¹¤·¤¤¼ö¤¤¤ò¤«¤±¤é¤ì¤¿¡£";
5396 #else
5397                                         reward = "cursing";
5398 #endif
5399                                         break;
5400                                 case 2:
5401                                         activate_hi_summon(py, px, FALSE);
5402 #ifdef JP
5403                                         reward = "¥â¥ó¥¹¥¿¡¼¤ò¾¤´­¤µ¤ì¤¿¡£";
5404 #else
5405                                         reward = "summoning hostile monsters";
5406 #endif
5407                                         break;
5408                                 case 3:
5409                                         if (one_in_(2))
5410                                         {
5411                                                 if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM)) break;
5412                                                 dummy = INVEN_RARM;
5413                                                 if (buki_motteruka(INVEN_LARM))
5414                                                 {
5415                                                         dummy = INVEN_LARM;
5416                                                         if (buki_motteruka(INVEN_RARM) && one_in_(2)) dummy = INVEN_RARM;
5417                                                 }
5418                                                 object_desc(o_name, &inventory[dummy], OD_NAME_ONLY);
5419                                                 (void)curse_weapon(FALSE, dummy);
5420 #ifdef JP
5421                                                 reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5422 #else
5423                                                 reward = format("destroying %s", o_name);
5424 #endif
5425                                         }
5426                                         else
5427                                         {
5428                                                 if (!inventory[INVEN_BODY].k_idx) break;
5429                                                 object_desc(o_name, &inventory[INVEN_BODY], OD_NAME_ONLY);
5430                                                 (void)curse_armor();
5431 #ifdef JP
5432                                                 reward = format("%s¤¬Ç˲õ¤µ¤ì¤¿¡£", o_name);
5433 #else
5434                                                 reward = format("destroying %s", o_name);
5435 #endif
5436                                         }
5437                                         break;
5438                                 default:
5439                                         for (dummy = 0; dummy < 6; dummy++)
5440                                         {
5441                                                 (void)dec_stat(dummy, 10 + randint1(15), TRUE);
5442                                         }
5443 #ifdef JP
5444                                         reward = "Á´Ç½ÎÏÃͤ¬²¼¤¬¤Ã¤¿¡£";
5445 #else
5446                                         reward = "decreasing all stats";
5447 #endif
5448                                         break;
5449                         }
5450                         break;
5451                 case REW_WRATH:
5452 #ifdef JP
5453 msg_format("%s¤ÎÀ¼¤¬¹ì¤­ÅϤä¿:",
5454 #else
5455                         msg_format("The voice of %s thunders:",
5456 #endif
5457
5458                                 chaos_patrons[p_ptr->chaos_patron]);
5459 #ifdef JP
5460 msg_print("¡Ö»à¤Ì¤¬¤è¤¤¡¢²¼Ëͤ衪¡×");
5461 #else
5462                         msg_print("'Die, mortal!'");
5463 #endif
5464
5465                         take_hit(DAMAGE_LOSELIFE, p_ptr->lev * 4, wrath_reason, -1);
5466                         for (dummy = 0; dummy < 6; dummy++)
5467                         {
5468                                 (void)dec_stat(dummy, 10 + randint1(15), FALSE);
5469                         }
5470                         activate_hi_summon(py, px, FALSE);
5471                         (void)activate_ty_curse(FALSE, &count);
5472                         if (one_in_(2))
5473                         {
5474                                 dummy = 0;
5475
5476                                 if (buki_motteruka(INVEN_RARM))
5477                                 {
5478                                         dummy = INVEN_RARM;
5479                                         if (buki_motteruka(INVEN_LARM) && one_in_(2)) dummy = INVEN_LARM;
5480                                 }
5481                                 else if (buki_motteruka(INVEN_LARM)) dummy = INVEN_LARM;
5482
5483                                 if (dummy) (void)curse_weapon(FALSE, dummy);
5484                         }
5485                         if (one_in_(2)) (void)curse_armor();
5486                         break;
5487                 case REW_DESTRUCT:
5488 #ifdef JP
5489 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5490                                 chaos_patrons[p_ptr->chaos_patron]);
5491 #else
5492                         msg_format("The voice of %s booms out:",
5493                                 chaos_patrons[p_ptr->chaos_patron]);
5494 #endif
5495
5496 #ifdef JP
5497 msg_print("¡Ö»à¤ÈÇ˲õ¤³¤½²æ¤¬´î¤Ó¤Ê¤ê¡ª¡×");
5498 #else
5499                         msg_print("'Death and destruction! This pleaseth me!'");
5500 #endif
5501
5502                         (void)destroy_area(py, px, 25, FALSE);
5503 #ifdef JP
5504                         reward = "¥À¥ó¥¸¥ç¥ó¤¬*Ç˲õ*¤µ¤ì¤¿¡£";
5505 #else
5506                         reward = "*destruct*ing dungeon";
5507 #endif
5508                         break;
5509                 case REW_GENOCIDE:
5510 #ifdef JP
5511 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5512                                 chaos_patrons[p_ptr->chaos_patron]);
5513 #else
5514                         msg_format("The voice of %s booms out:",
5515                                 chaos_patrons[p_ptr->chaos_patron]);
5516 #endif
5517
5518 #ifdef JP
5519 msg_print("¡Ö²æ¡¢Æò¤ÎŨ¤òËõ»¦¤»¤ó¡ª¡×");
5520 #else
5521                         msg_print("'Let me relieve thee of thine oppressors!'");
5522 #endif
5523
5524                         (void)symbol_genocide(0, FALSE);
5525 #ifdef JP
5526                         reward = "¥â¥ó¥¹¥¿¡¼¤¬Ëõ»¦¤µ¤ì¤¿¡£";
5527 #else
5528                         reward = "genociding monsters";
5529 #endif
5530                         break;
5531                 case REW_MASS_GEN:
5532 #ifdef JP
5533 msg_format("%s¤ÎÀ¼¤¬¶Á¤­ÅϤä¿:",
5534                                 chaos_patrons[p_ptr->chaos_patron]);
5535 #else
5536                         msg_format("The voice of %s booms out:",
5537                                 chaos_patrons[p_ptr->chaos_patron]);
5538 #endif
5539
5540 #ifdef JP
5541 msg_print("¡Ö²æ¡¢Æò¤ÎŨ¤òËõ»¦¤»¤ó¡ª¡×");
5542 #else
5543                         msg_print("'Let me relieve thee of thine oppressors!'");
5544 #endif
5545
5546                         (void)mass_genocide(0, FALSE);
5547 #ifdef JP
5548                         reward = "¥â¥ó¥¹¥¿¡¼¤¬Ëõ»¦¤µ¤ì¤¿¡£";
5549 #else
5550                         reward = "genociding nearby monsters";
5551 #endif
5552                         break;
5553                 case REW_DISPEL_C:
5554 #ifdef JP
5555 msg_format("%s¤ÎÎϤ¬Å¨¤ò¹¶·â¤¹¤ë¤Î¤ò´¶¤¸¤¿¡ª",
5556                                 chaos_patrons[p_ptr->chaos_patron]);
5557 #else
5558                         msg_format("You can feel the power of %s assault your enemies!",
5559                                 chaos_patrons[p_ptr->chaos_patron]);
5560 #endif
5561
5562                         (void)dispel_monsters(p_ptr->lev * 4);
5563                         break;
5564                 case REW_IGNORE:
5565 #ifdef JP
5566 msg_format("%s¤Ï¤¢¤Ê¤¿¤ò̵»ë¤·¤¿¡£",
5567                                 chaos_patrons[p_ptr->chaos_patron]);
5568 #else
5569                         msg_format("%s ignores you.",
5570                                 chaos_patrons[p_ptr->chaos_patron]);
5571 #endif
5572
5573                         break;
5574                 case REW_SER_DEMO:
5575 #ifdef JP
5576 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ°­Ëâ¤Î»È¤¤¤ò¤è¤³¤·¤¿¡ª",chaos_patrons[p_ptr->chaos_patron]);
5577 #else
5578                         msg_format("%s rewards you with a demonic servant!",chaos_patrons[p_ptr->chaos_patron]);
5579 #endif
5580
5581                         if (!summon_specific(-1, py, px, dun_level, SUMMON_DEMON, PM_FORCE_PET))
5582 #ifdef JP
5583 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5584 #else
5585                                 msg_print("Nobody ever turns up...");
5586 #endif
5587                         else
5588 #ifdef JP
5589                                 reward = "°­Ë⤬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5590 #else
5591                                 reward = "a demonic servant";
5592 #endif
5593
5594                         break;
5595                 case REW_SER_MONS:
5596 #ifdef JP
5597 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ»È¤¤¤ò¤è¤³¤·¤¿¡ª",chaos_patrons[p_ptr->chaos_patron]);
5598 #else
5599                         msg_format("%s rewards you with a servant!",chaos_patrons[p_ptr->chaos_patron]);
5600 #endif
5601
5602                         if (!summon_specific(-1, py, px, dun_level, 0, PM_FORCE_PET))
5603 #ifdef JP
5604 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5605 #else
5606                                 msg_print("Nobody ever turns up...");
5607 #endif
5608                         else
5609 #ifdef JP
5610                                 reward = "¥â¥ó¥¹¥¿¡¼¤¬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5611 #else
5612                                 reward = "a servant";
5613 #endif
5614
5615                         break;
5616                 case REW_SER_UNDE:
5617 #ifdef JP
5618 msg_format("%s¤ÏË«Èþ¤È¤·¤Æ¥¢¥ó¥Ç¥Ã¥É¤Î»È¤¤¤ò¤è¤³¤·¤¿¡£",chaos_patrons[p_ptr->chaos_patron]);
5619 #else
5620                         msg_format("%s rewards you with an undead servant!",chaos_patrons[p_ptr->chaos_patron]);
5621 #endif
5622
5623                         if (!summon_specific(-1, py, px, dun_level, SUMMON_UNDEAD, PM_FORCE_PET))
5624 #ifdef JP
5625 msg_print("²¿¤â¸½¤ì¤Ê¤«¤Ã¤¿...");
5626 #else
5627                                 msg_print("Nobody ever turns up...");
5628 #endif
5629                         else
5630 #ifdef JP
5631                                 reward = "¥¢¥ó¥Ç¥Ã¥É¤¬¥Ú¥Ã¥È¤Ë¤Ê¤Ã¤¿¡£";
5632 #else
5633                                 reward = "an undead servant";
5634 #endif
5635
5636                         break;
5637                 default:
5638 #ifdef JP
5639 msg_format("%s¤ÎÀ¼¤¬¤É¤â¤Ã¤¿:",
5640 #else
5641                         msg_format("The voice of %s stammers:",
5642 #endif
5643
5644                                 chaos_patrons[p_ptr->chaos_patron]);
5645 #ifdef JP
5646 msg_format("¡Ö¤¢¡¼¡¢¤¢¡¼¡¢Åú¤¨¤Ï %d/%d¡£¼ÁÌä¤Ï²¿¡©¡×", type, effect);
5647 #else
5648                         msg_format("'Uh... uh... the answer's %d/%d, what's the question?'", type, effect);
5649 #endif
5650
5651         }
5652         }
5653         if (reward)
5654         {
5655 #ifdef JP
5656                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format("¥Ñ¥È¥í¥ó¤ÎÊó½·¤Ç%s", reward));
5657 #else
5658                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, format("The patron rewards you with %s.", reward));
5659 #endif
5660         }
5661 }
5662
5663
5664 /*
5665  * XAngband: determine if a given location is "interesting"
5666  * based on target_set_accept function.
5667  */
5668 static bool tgt_pt_accept(int y, int x)
5669 {
5670         cave_type *c_ptr;
5671
5672         /* Bounds */
5673         if (!(in_bounds(y, x))) return (FALSE);
5674
5675         /* Player grid is always interesting */
5676         if ((y == py) && (x == px)) return (TRUE);
5677
5678         /* Handle hallucination */
5679         if (p_ptr->image) return (FALSE);
5680
5681         /* Examine the grid */
5682         c_ptr = &cave[y][x];
5683
5684         /* Interesting memorized features */
5685         if (c_ptr->info & (CAVE_MARK))
5686         {
5687                 /* Notice stairs */
5688                 if (cave_have_flag_grid(c_ptr, FF_LESS)) return (TRUE);
5689                 if (cave_have_flag_grid(c_ptr, FF_MORE)) return (TRUE);
5690
5691                 /* Notice quest features */
5692                 if (cave_have_flag_grid(c_ptr, FF_QUEST_ENTER)) return (TRUE);
5693                 if (cave_have_flag_grid(c_ptr, FF_QUEST_EXIT)) return (TRUE);
5694         }
5695
5696         /* Nope */
5697         return (FALSE);
5698 }
5699
5700
5701 /*
5702  * XAngband: Prepare the "temp" array for "tget_pt"
5703  * based on target_set_prepare funciton.
5704  */
5705 static void tgt_pt_prepare(void)
5706 {
5707         int y, x;
5708
5709         /* Reset "temp" array */
5710         temp_n = 0;
5711
5712         if (!expand_list) return;
5713
5714         /* Scan the current panel */
5715         for (y = 1; y < cur_hgt; y++)
5716         {
5717                 for (x = 1; x < cur_wid; x++)
5718                 {
5719                         /* Require "interesting" contents */
5720                         if (!tgt_pt_accept(y, x)) continue;
5721
5722                         /* Save the location */
5723                         temp_x[temp_n] = x;
5724                         temp_y[temp_n] = y;
5725                         temp_n++;
5726                 }
5727         }
5728
5729         /* Target the nearest monster for shooting */
5730         ang_sort_comp = ang_sort_comp_distance;
5731         ang_sort_swap = ang_sort_swap_distance;
5732
5733         /* Sort the positions */
5734         ang_sort(temp_x, temp_y, temp_n);
5735 }
5736
5737 /*
5738  * old -- from PsiAngband.
5739  */
5740 bool tgt_pt(int *x_ptr, int *y_ptr)
5741 {
5742         char ch = 0;
5743         int d, x, y, n;
5744         bool success = FALSE;
5745
5746         int wid, hgt;
5747
5748         /* Get size */
5749         get_screen_size(&wid, &hgt);
5750
5751         x = px;
5752         y = py;
5753
5754         if (expand_list) 
5755         {
5756                 tgt_pt_prepare();
5757                 n = 0;
5758         }
5759
5760 #ifdef JP
5761         msg_print("¾ì½ê¤òÁª¤ó¤Ç¥¹¥Ú¡¼¥¹¥­¡¼¤ò²¡¤·¤Æ²¼¤µ¤¤¡£");
5762 #else
5763         msg_print("Select a point and press space.");
5764 #endif
5765         msg_flag = FALSE; /* prevents "-more-" message. */
5766
5767         while ((ch != ESCAPE) && !success)
5768         {
5769                 bool move_fast = FALSE;
5770
5771                 move_cursor_relative(y, x);
5772                 ch = inkey();
5773                 switch (ch)
5774                 {
5775                 case ESCAPE:
5776                         break;
5777                 case ' ':
5778                 case 't':
5779                 case '.':
5780                 case '5':
5781                 case '0':
5782                         /* illegal place */
5783                         if (player_bold(y, x)) ch = 0;
5784
5785                         /* okay place */
5786                         else success = TRUE;
5787
5788                         break;
5789
5790                 /* XAngband: Move cursor to stairs */
5791                 case '>':
5792                 case '<':
5793                         if (expand_list && temp_n)
5794                         {
5795                                 int dx, dy;
5796                                 int cx = (panel_col_min + panel_col_max) / 2;
5797                                 int cy = (panel_row_min + panel_row_max) / 2;
5798
5799                                 n++;
5800
5801                                 while(n < temp_n)       /* Skip stairs which have defferent distance */
5802                                 {
5803                                         cave_type *c_ptr = &cave[temp_y[n]][temp_x[n]];
5804
5805                                         if (ch == '>')
5806                                         {
5807                                                 if (cave_have_flag_grid(c_ptr, FF_LESS) ||
5808                                                         cave_have_flag_grid(c_ptr, FF_QUEST_ENTER))
5809                                                         n++;
5810                                                 else
5811                                                         break;
5812                                         }
5813                                         else /* if (ch == '<') */
5814                                         {
5815                                                 if (cave_have_flag_grid(c_ptr, FF_MORE) ||
5816                                                         cave_have_flag_grid(c_ptr, FF_QUEST_EXIT))
5817                                                         n++;
5818                                                 else
5819                                                         break;
5820                                         }
5821                                 }
5822
5823                                 if (n == temp_n)        /* Loop out taget list */
5824                                 {
5825                                         n = 0;
5826                                         y = py;
5827                                         x = px;
5828                                         verify_panel(); /* Move cursor to player */
5829
5830                                         /* Update stuff */
5831                                         p_ptr->update |= (PU_MONSTERS);
5832
5833                                         /* Redraw map */
5834                                         p_ptr->redraw |= (PR_MAP);
5835
5836                                         /* Window stuff */
5837                                         p_ptr->window |= (PW_OVERHEAD);
5838
5839                                         /* Handle stuff */
5840                                         handle_stuff();
5841                                 }
5842                                 else    /* move cursor to next stair and change panel */
5843                                 {
5844                                         y = temp_y[n];
5845                                         x = temp_x[n];
5846
5847                                         dy = 2 * (y - cy) / hgt;
5848                                         dx = 2 * (x - cx) / wid;
5849                                         if (dy || dx) change_panel(dy, dx);
5850                                 }
5851                         }
5852                         break;
5853
5854                 default:
5855                         /* Look up the direction */
5856                         d = get_keymap_dir(ch);
5857
5858                         /* XTRA HACK MOVEFAST */
5859                         if (isupper(ch)) move_fast = TRUE;
5860
5861                         /* Handle "direction" */
5862                         if (d)
5863                         {
5864                                 int dx = ddx[d];
5865                                 int dy = ddy[d];
5866
5867                                 /* XTRA HACK MOVEFAST */
5868                                 if (move_fast)
5869                                 {
5870                                         int mag = MIN(wid / 2, hgt / 2);
5871                                         x += dx * mag;
5872                                         y += dy * mag;
5873                                 }
5874                                 else
5875                                 {
5876                                         x += dx;
5877                                         y += dy;
5878                                 }
5879
5880                                 /* Do not move horizontally if unnecessary */
5881                                 if (((x < panel_col_min + wid / 2) && (dx > 0)) ||
5882                                          ((x > panel_col_min + wid / 2) && (dx < 0)))
5883                                 {
5884                                         dx = 0;
5885                                 }
5886
5887                                 /* Do not move vertically if unnecessary */
5888                                 if (((y < panel_row_min + hgt / 2) && (dy > 0)) ||
5889                                          ((y > panel_row_min + hgt / 2) && (dy < 0)))
5890                                 {
5891                                         dy = 0;
5892                                 }
5893
5894                                 /* Apply the motion */
5895                                 if ((y >= panel_row_min + hgt) || (y < panel_row_min) ||
5896                                          (x >= panel_col_min + wid) || (x < panel_col_min))
5897                                 {
5898                                         /* if (change_panel(dy, dx)) target_set_prepare(mode); */
5899                                         change_panel(dy, dx);
5900                                 }
5901
5902                                 /* Slide into legality */
5903                                 if (x >= cur_wid-1) x = cur_wid - 2;
5904                                 else if (x <= 0) x = 1;
5905
5906                                 /* Slide into legality */
5907                                 if (y >= cur_hgt-1) y = cur_hgt- 2;
5908                                 else if (y <= 0) y = 1;
5909
5910                         }
5911                         break;
5912                 }
5913         }
5914
5915         /* Clear the top line */
5916         prt("", 0, 0);
5917
5918         /* Recenter the map around the player */
5919         verify_panel();
5920
5921         /* Update stuff */
5922         p_ptr->update |= (PU_MONSTERS);
5923
5924         /* Redraw map */
5925         p_ptr->redraw |= (PR_MAP);
5926
5927         /* Window stuff */
5928         p_ptr->window |= (PW_OVERHEAD);
5929
5930         /* Handle stuff */
5931         handle_stuff();
5932
5933         *x_ptr = x;
5934         *y_ptr = y;
5935         return success;
5936 }
5937
5938
5939 bool get_hack_dir(int *dp)
5940 {
5941         int             dir;
5942         cptr    p;
5943         char    command;
5944
5945
5946         /* Initialize */
5947         (*dp) = 0;
5948
5949         /* Global direction */
5950         dir = 0;
5951
5952         /* (No auto-targeting) */
5953
5954         /* Ask until satisfied */
5955         while (!dir)
5956         {
5957                 /* Choose a prompt */
5958                 if (!target_okay())
5959                 {
5960 #ifdef JP
5961 p = "Êý¸þ ('*'¤Ç¥¿¡¼¥²¥Ã¥ÈÁªÂò, ESC¤ÇÃæÃÇ)? ";
5962 #else
5963                         p = "Direction ('*' to choose a target, Escape to cancel)? ";
5964 #endif
5965
5966                 }
5967                 else
5968                 {
5969 #ifdef JP
5970 p = "Êý¸þ ('5'¤Ç¥¿¡¼¥²¥Ã¥È¤Ø, '*'¤Ç¥¿¡¼¥²¥Ã¥ÈºÆÁªÂò, ESC¤ÇÃæÃÇ)? ";
5971 #else
5972                         p = "Direction ('5' for target, '*' to re-target, Escape to cancel)? ";
5973 #endif
5974
5975                 }
5976
5977                 /* Get a command (or Cancel) */
5978                 if (!get_com(p, &command, TRUE)) break;
5979
5980                 if (use_menu)
5981                 {
5982                         if (command == '\r') command = 't';
5983                 }  
5984
5985                 /* Convert various keys to "standard" keys */
5986                 switch (command)
5987                 {
5988                         /* Use current target */
5989                         case 'T':
5990                         case 't':
5991                         case '.':
5992                         case '5':
5993                         case '0':
5994                         {
5995                                 dir = 5;
5996                                 break;
5997                         }
5998
5999                         /* Set new target */
6000                         case '*':
6001                         case ' ':
6002                         case '\r':
6003                         {
6004                                 if (target_set(TARGET_KILL)) dir = 5;
6005                                 break;
6006                         }
6007
6008                         default:
6009                         {
6010                                 /* Look up the direction */
6011                                 dir = get_keymap_dir(command);
6012
6013                                 break;
6014                         }
6015                 }
6016
6017                 /* Verify requested targets */
6018                 if ((dir == 5) && !target_okay()) dir = 0;
6019
6020                 /* Error */
6021                 if (!dir) bell();
6022         }
6023
6024         /* No direction */
6025         if (!dir) return (FALSE);
6026
6027         /* Save the direction */
6028         command_dir = dir;
6029
6030         /* Check for confusion */
6031         if (p_ptr->confused)
6032         {
6033                 /* XXX XXX XXX */
6034                 /* Random direction */
6035                 dir = ddd[randint0(8)];
6036         }
6037
6038         /* Notice confusion */
6039         if (command_dir != dir)
6040         {
6041                 /* Warn the user */
6042 #ifdef JP
6043 msg_print("¤¢¤Ê¤¿¤Ïº®Í𤷤Ƥ¤¤ë¡£");
6044 #else
6045                 msg_print("You are confused.");
6046 #endif
6047
6048         }
6049
6050         /* Save direction */
6051         (*dp) = dir;
6052
6053         /* A "valid" direction was entered */
6054         return (TRUE);
6055 }
6056
6057
6058 /*
6059  * ¥¨¥Í¥ë¥®¡¼¤ÎÁý²ÃÎÌ10d5¤ò®¤¯·×»»¤¹¤ë¤¿¤á¤Î´Ø¿ô
6060  */
6061
6062 #define Go_no_JuuJou 5*5*5*5*5*5*5*5*5*5
6063
6064 s16b gain_energy(void)
6065 {
6066         int i;
6067         s32b energy_result = 10;
6068         s32b tmp;
6069
6070         tmp = randint0(Go_no_JuuJou);
6071
6072         for (i = 0; i < 9; i ++){
6073                 energy_result += tmp % 5;
6074                 tmp /= 5;
6075         }
6076
6077         return (s16b)(energy_result + tmp);
6078 }
6079
6080
6081 /*
6082  * Return bow energy 
6083  */
6084 s16b bow_energy(int sval)
6085 {
6086         int energy = 100;
6087
6088         /* Analyze the launcher */
6089         switch (sval)
6090         {
6091                 /* Sling and ammo */
6092                 case SV_SLING:
6093                 {
6094                         energy = 8000;
6095                         break;
6096                 }
6097
6098                 /* Short Bow and Arrow */
6099                 case SV_SHORT_BOW:
6100                 {
6101                         energy = 10000;
6102                         break;
6103                 }
6104
6105                 /* Long Bow and Arrow */
6106                 case SV_LONG_BOW:
6107                 {
6108                         energy = 10000;
6109                         break;
6110                 }
6111
6112                 /* Bow of irresponsiblity and Arrow */
6113                 case SV_NAMAKE_BOW:
6114                 {
6115                         energy = 7777;
6116                         break;
6117                 }
6118
6119                 /* Light Crossbow and Bolt */
6120                 case SV_LIGHT_XBOW:
6121                 {
6122                         energy = 12000;
6123                         break;
6124                 }
6125
6126                 /* Heavy Crossbow and Bolt */
6127                 case SV_HEAVY_XBOW:
6128                 {
6129                         energy = 13333;
6130                         break;
6131                 }
6132         }
6133
6134         return (energy);
6135 }
6136
6137
6138 /*
6139  * Return bow tmul
6140  */
6141 int bow_tmul(int sval)
6142 {
6143         int tmul = 0;
6144
6145         /* Analyze the launcher */
6146         switch (sval)
6147         {
6148                 /* Sling and ammo */
6149                 case SV_SLING:
6150                 {
6151                         tmul = 2;
6152                         break;
6153                 }
6154
6155                 /* Short Bow and Arrow */
6156                 case SV_SHORT_BOW:
6157                 {
6158                         tmul = 2;
6159                         break;
6160                 }
6161
6162                 /* Long Bow and Arrow */
6163                 case SV_LONG_BOW:
6164                 {
6165                         tmul = 3;
6166                         break;
6167                 }
6168
6169                 /* Bow of irresponsiblity and Arrow */
6170                 case SV_NAMAKE_BOW:
6171                 {
6172                         tmul = 3;
6173                         break;
6174                 }
6175
6176                 /* Light Crossbow and Bolt */
6177                 case SV_LIGHT_XBOW:
6178                 {
6179                         tmul = 3;
6180                         break;
6181                 }
6182
6183                 /* Heavy Crossbow and Bolt */
6184                 case SV_HEAVY_XBOW:
6185                 {
6186                         tmul = 4;
6187                         break;
6188                 }
6189         }
6190
6191         return (tmul);
6192 }
6193
6194 /*
6195  * Return alignment title
6196  */
6197 cptr your_alignment(void)
6198 {
6199 #ifdef JP
6200         if (p_ptr->align > 150) return "ÂçÁ±";
6201         else if (p_ptr->align > 50) return "ÃæÁ±";
6202         else if (p_ptr->align > 10) return "¾®Á±";
6203         else if (p_ptr->align > -11) return "ÃæΩ";
6204         else if (p_ptr->align > -51) return "¾®°­";
6205         else if (p_ptr->align > -151) return "Ãæ°­";
6206         else return "Âç°­";
6207 #else
6208         if (p_ptr->align > 150) return "Lawful";
6209         else if (p_ptr->align > 50) return "Good";
6210         else if (p_ptr->align > 10) return "Neutral Good";
6211         else if (p_ptr->align > -11) return "Neutral";
6212         else if (p_ptr->align > -51) return "Neutral Evil";
6213         else if (p_ptr->align > -151) return "Evil";
6214         else return "Chaotic";
6215 #endif
6216 }
6217
6218
6219 /*
6220  * Return proficiency level of weapons and misc. skills (except riding)
6221  */
6222 int weapon_exp_level(int weapon_exp)
6223 {
6224         if (weapon_exp < WEAPON_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
6225         else if (weapon_exp < WEAPON_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
6226         else if (weapon_exp < WEAPON_EXP_EXPERT) return EXP_LEVEL_SKILLED;
6227         else if (weapon_exp < WEAPON_EXP_MASTER) return EXP_LEVEL_EXPERT;
6228         else return EXP_LEVEL_MASTER;
6229 }
6230
6231
6232 /*
6233  * Return proficiency level of riding
6234  */
6235 int riding_exp_level(int riding_exp)
6236 {
6237         if (riding_exp < RIDING_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
6238         else if (riding_exp < RIDING_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
6239         else if (riding_exp < RIDING_EXP_EXPERT) return EXP_LEVEL_SKILLED;
6240         else if (riding_exp < RIDING_EXP_MASTER) return EXP_LEVEL_EXPERT;
6241         else return EXP_LEVEL_MASTER;
6242 }
6243
6244
6245 /*
6246  * Return proficiency level of spells
6247  */
6248 int spell_exp_level(int spell_exp)
6249 {
6250         if (spell_exp < SPELL_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
6251         else if (spell_exp < SPELL_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
6252         else if (spell_exp < SPELL_EXP_EXPERT) return EXP_LEVEL_SKILLED;
6253         else if (spell_exp < SPELL_EXP_MASTER) return EXP_LEVEL_EXPERT;
6254         else return EXP_LEVEL_MASTER;
6255 }