OSDN Git Service

Rearrange header comments to cmd*.c
[hengband/hengband.git] / src / cmd5.c
1 /*!
2  *  @file cmd5.c
3  *  @brief ¥×¥ì¥¤¥ä¡¼¤ÎËâË¡¤Ë´Ø¤¹¤ë¥³¥Þ¥ó¥É¤Î¼ÂÁõ / Spell/Prayer commands
4  *  @date 2014/01/02
5  *  @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  */
12
13
14 #include "angband.h"
15
16 cptr spell_category_name(int tval)
17 {
18         switch (tval)
19         {
20 #ifdef JP
21         case TV_HISSATSU_BOOK:
22                 return "ɬ»¦µ»";
23         case TV_LIFE_BOOK:
24                 return "µ§¤ê";
25         case TV_MUSIC_BOOK:
26                 return "²Î";
27         default:
28                 return "¼öʸ";
29 #else
30         case TV_HISSATSU_BOOK:
31                 return "art";
32         case TV_LIFE_BOOK:
33                 return "prayer";
34         case TV_MUSIC_BOOK:
35                 return "song";
36         default:
37                 return "spell";
38 #endif
39         }
40 }
41
42 /*
43  * Allow user to choose a spell/prayer from the given book.
44  *
45  * If a valid spell is chosen, saves it in '*sn' and returns TRUE
46  * If the user hits escape, returns FALSE, and set '*sn' to -1
47  * If there are no legal choices, returns FALSE, and sets '*sn' to -2
48  *
49  * The "prompt" should be "cast", "recite", or "study"
50  * The "known" should be TRUE for cast/pray, FALSE for study
51  */
52
53 bool select_the_force = FALSE;
54
55 static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm)
56 {
57         int         i;
58         int         spell = -1;
59         int         num = 0;
60         int         ask = TRUE;
61         int         need_mana;
62         byte        spells[64];
63         bool        flag, redraw, okay;
64         char        choice;
65         const magic_type  *s_ptr;
66         char        out_val[160];
67         cptr        p;
68 #ifdef JP
69         char jverb_buf[128];
70 #endif
71         int menu_line = (use_menu ? 1 : 0);
72
73 #ifdef ALLOW_REPEAT /* TNB */
74
75         /* Get the spell, if available */
76         if (repeat_pull(sn))
77         {
78                 /* Verify the spell */
79                 if (spell_okay(*sn, learned, FALSE, use_realm))
80                 {
81                         /* Success */
82                         return (TRUE);
83                 }
84         }
85
86 #endif /* ALLOW_REPEAT -- TNB */
87
88         p = spell_category_name(mp_ptr->spell_book);
89
90         /* Extract spells */
91         for (spell = 0; spell < 32; spell++)
92         {
93                 /* Check for this spell */
94                 if ((fake_spell_flags[sval] & (1L << spell)))
95                 {
96                         /* Collect this spell */
97                         spells[num++] = spell;
98                 }
99         }
100
101         /* Assume no usable spells */
102         okay = FALSE;
103
104         /* Assume no spells available */
105         (*sn) = -2;
106
107         /* Check for "okay" spells */
108         for (i = 0; i < num; i++)
109         {
110                 /* Look for "okay" spells */
111                 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
112         }
113
114         /* No "okay" spells */
115         if (!okay) return (FALSE);
116         if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
117         if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
118         if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
119
120         /* Assume cancelled */
121         *sn = (-1);
122
123         /* Nothing chosen yet */
124         flag = FALSE;
125
126         /* No redraw yet */
127         redraw = FALSE;
128
129         /* Show choices */
130         p_ptr->window |= (PW_SPELL);
131
132         /* Window stuff */
133         window_stuff();
134
135         /* Build a prompt (accept all spells) */
136 #ifdef JP
137         jverb1( prompt, jverb_buf );
138         (void) strnfmt(out_val, 78, "(%^s:%c-%c, '*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤Î%s¤ò%^s¤Þ¤¹¤«? ",
139                 p, I2A(0), I2A(num - 1), p, jverb_buf );
140 #else
141         (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
142                 p, I2A(0), I2A(num - 1), prompt, p);
143 #endif
144
145         /* Get a spell from the user */
146
147         choice = (always_show_list || use_menu) ? ESCAPE : 1;
148         while (!flag)
149         {
150                 if (choice == ESCAPE) choice = ' '; 
151                 else if (!get_com(out_val, &choice, TRUE))break;
152
153                 if (use_menu && choice != ' ')
154                 {
155                         switch (choice)
156                         {
157                                 case '0':
158                                 {
159                                         screen_load();
160                                         return FALSE;
161                                 }
162
163                                 case '8':
164                                 case 'k':
165                                 case 'K':
166                                 {
167                                         menu_line += (num - 1);
168                                         break;
169                                 }
170
171                                 case '2':
172                                 case 'j':
173                                 case 'J':
174                                 {
175                                         menu_line++;
176                                         break;
177                                 }
178
179                                 case 'x':
180                                 case 'X':
181                                 case '\r':
182                                 case '\n':
183                                 {
184                                         i = menu_line - 1;
185                                         ask = FALSE;
186                                         break;
187                                 }
188                         }
189                         if (menu_line > num) menu_line -= num;
190                         /* Display a list of spells */
191                         print_spells(menu_line, spells, num, 1, 15, use_realm);
192                         if (ask) continue;
193                 }
194                 else
195                 {
196                         /* Request redraw */
197                         if ((choice == ' ') || (choice == '*') || (choice == '?'))
198                         {
199                                 /* Show the list */
200                                 if (!redraw)
201                                 {
202                                         /* Show list */
203                                         redraw = TRUE;
204
205                                         /* Save the screen */
206                                         screen_save();
207
208                                         /* Display a list of spells */
209                                         print_spells(menu_line, spells, num, 1, 15, use_realm);
210                                 }
211
212                                 /* Hide the list */
213                                 else
214                                 {
215                                         if (use_menu) continue;
216
217                                         /* Hide list */
218                                         redraw = FALSE;
219
220                                         /* Restore the screen */
221                                         screen_load();
222                                 }
223
224                                 /* Redo asking */
225                                 continue;
226                         }
227
228
229                         /* Note verify */
230                         ask = (isupper(choice));
231
232                         /* Lowercase */
233                         if (ask) choice = tolower(choice);
234
235                         /* Extract request */
236                         i = (islower(choice) ? A2I(choice) : -1);
237                 }
238
239                 /* Totally Illegal */
240                 if ((i < 0) || (i >= num))
241                 {
242                         bell();
243                         continue;
244                 }
245
246                 /* Save the spell index */
247                 spell = spells[i];
248
249                 /* Require "okay" spells */
250                 if (!spell_okay(spell, learned, FALSE, use_realm))
251                 {
252                         bell();
253 #ifdef JP
254                         msg_format("¤½¤Î%s¤ò%s¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£", p, prompt);
255 #else
256                         msg_format("You may not %s that %s.", prompt, p);
257 #endif
258
259                         continue;
260                 }
261
262                 /* Verify it */
263                 if (ask)
264                 {
265                         char tmp_val[160];
266
267                         /* Access the spell */
268                         if (!is_magic(use_realm))
269                         {
270                                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
271                         }
272                         else
273                         {
274                                 s_ptr = &mp_ptr->info[use_realm - 1][spell];
275                         }
276
277                         /* Extract mana consumption rate */
278                         if (use_realm == REALM_HISSATSU)
279                         {
280                                 need_mana = s_ptr->smana;
281                         }
282                         else
283                         {
284                                 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
285                         }
286
287                         /* Prompt */
288 #ifdef JP
289                         jverb1( prompt, jverb_buf );
290                         /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½¤ËÂбþ */
291                         (void) strnfmt(tmp_val, 78, "%s(MP%d, ¼ºÇÔΨ%d%%)¤ò%s¤Þ¤¹¤«? ",
292                                 do_spell(use_realm, spell, SPELL_NAME), need_mana,
293                                        spell_chance(spell, use_realm),jverb_buf);
294 #else
295                         (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
296                                 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
297                                 spell_chance(spell, use_realm));
298 #endif
299
300
301                         /* Belay that order */
302                         if (!get_check(tmp_val)) continue;
303                 }
304
305                 /* Stop the loop */
306                 flag = TRUE;
307         }
308
309
310         /* Restore the screen */
311         if (redraw) screen_load();
312
313
314         /* Show choices */
315         p_ptr->window |= (PW_SPELL);
316
317         /* Window stuff */
318         window_stuff();
319
320
321         /* Abort if needed */
322         if (!flag) return FALSE;
323
324         /* Save the choice */
325         (*sn) = spell;
326
327 #ifdef ALLOW_REPEAT /* TNB */
328
329         repeat_push(*sn);
330
331 #endif /* ALLOW_REPEAT -- TNB */
332
333         /* Success */
334         return TRUE;
335 }
336
337
338 static bool item_tester_learn_spell(object_type *o_ptr)
339 {
340         s32b choices = realm_choices2[p_ptr->pclass];
341
342         if (p_ptr->pclass == CLASS_PRIEST)
343         {
344                 if (is_good_realm(p_ptr->realm1))
345                 {
346                         choices &= ~(CH_DEATH | CH_DAEMON);
347                 }
348                 else
349                 {
350                         choices &= ~(CH_LIFE | CH_CRUSADE);
351                 }
352         }
353
354         if ((o_ptr->tval < TV_LIFE_BOOK) || (o_ptr->tval > (TV_LIFE_BOOK + MAX_REALM - 1))) return (FALSE);
355         if ((o_ptr->tval == TV_MUSIC_BOOK) && (p_ptr->pclass == CLASS_BARD)) return (TRUE);
356         else if (!is_magic(tval2realm(o_ptr->tval))) return FALSE;
357         if ((REALM1_BOOK == o_ptr->tval) || (REALM2_BOOK == o_ptr->tval)) return (TRUE);
358         if (choices & (0x0001 << (tval2realm(o_ptr->tval) - 1))) return (TRUE);
359         return (FALSE);
360 }
361
362
363 static bool player_has_no_spellbooks(void)
364 {
365         int         i;
366         object_type *o_ptr;
367
368         for (i = 0; i < INVEN_PACK; i++)
369         {
370                 o_ptr = &inventory[i];
371                 if (o_ptr->k_idx && check_book_realm(o_ptr->tval, o_ptr->sval)) return FALSE;
372         }
373
374         for (i = cave[py][px].o_idx; i; i = o_ptr->next_o_idx)
375         {
376                 o_ptr = &o_list[i];
377                 if (o_ptr->k_idx && (o_ptr->marked & OM_FOUND) && check_book_realm(o_ptr->tval, o_ptr->sval)) return FALSE;
378         }
379
380         return TRUE;
381 }
382
383
384 static void confirm_use_force(bool browse_only)
385 {
386         int  item;
387         char which;
388
389 #ifdef ALLOW_REPEAT
390
391         /* Get the item index */
392         if (repeat_pull(&item) && (item == INVEN_FORCE))
393         {
394                 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
395                 return;
396         }
397
398 #endif /* ALLOW_REPEAT */
399
400         /* Show the prompt */
401 #ifdef JP
402         prt("('w'Îýµ¤½Ñ, ESC) 'w'¤«ESC¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤¡£ ", 0, 0);
403 #else
404         prt("(w for the Force, ESC) Hit 'w' or ESC. ", 0, 0);
405 #endif
406
407         while (1)
408         {
409                 /* Get a key */
410                 which = inkey();
411
412                 if (which == ESCAPE) break;
413                 else if (which == 'w')
414                 {
415
416 #ifdef ALLOW_REPEAT
417
418                         repeat_push(INVEN_FORCE);
419
420 #endif /* ALLOW_REPEAT */
421
422                         break;
423                 }
424         }
425
426         /* Clear the prompt line */
427         prt("", 0, 0);
428
429         if (which == 'w')
430         {
431                 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
432         }
433 }
434
435
436 /*
437  * Peruse the spells/prayers in a book
438  *
439  * Note that *all* spells in the book are listed
440  *
441  * Note that browsing is allowed while confused or blind,
442  * and in the dark, primarily to allow browsing in stores.
443  */
444 void do_cmd_browse(void)
445 {
446         int             item, sval, use_realm = 0, j, line;
447         int             spell = -1;
448         int             num = 0;
449
450         byte            spells[64];
451         char            temp[62*4];
452
453         object_type     *o_ptr;
454
455         cptr q, s;
456
457         /* Warriors are illiterate */
458         if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
459         {
460 #ifdef JP
461                 msg_print("ËܤòÆɤळ¤È¤¬¤Ç¤­¤Ê¤¤¡ª");
462 #else
463                 msg_print("You cannot read books!");
464 #endif
465
466                 return;
467         }
468
469         if (p_ptr->special_defense & KATA_MUSOU)
470         {
471                 set_action(ACTION_NONE);
472         }
473
474         if (p_ptr->pclass == CLASS_FORCETRAINER)
475         {
476                 if (player_has_no_spellbooks())
477                 {
478                         confirm_use_force(TRUE);
479                         return;
480                 }
481                 select_the_force = TRUE;
482         }
483
484         /* Restrict choices to "useful" books */
485         if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
486         else item_tester_hook = item_tester_learn_spell;
487
488         /* Get an item */
489 #ifdef JP
490         q = "¤É¤ÎËܤòÆɤߤޤ¹¤«? ";
491 #else
492         q = "Browse which book? ";
493 #endif
494
495 #ifdef JP
496         s = "Æɤá¤ëËܤ¬¤Ê¤¤¡£";
497 #else
498         s = "You have no books that you can read.";
499 #endif
500
501         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
502         {
503                 select_the_force = FALSE;
504                 return;
505         }
506         select_the_force = FALSE;
507
508         if (item == INVEN_FORCE) /* the_force */
509         {
510                 do_cmd_mind_browse();
511                 return;
512         }
513
514         /* Get the item (in the pack) */
515         else if (item >= 0)
516         {
517                 o_ptr = &inventory[item];
518         }
519
520         /* Get the item (on the floor) */
521         else
522         {
523                 o_ptr = &o_list[0 - item];
524         }
525
526         /* Access the item's sval */
527         sval = o_ptr->sval;
528
529         use_realm = tval2realm(o_ptr->tval);
530
531         /* Track the object kind */
532         object_kind_track(o_ptr->k_idx);
533
534         /* Hack -- Handle stuff */
535         handle_stuff();
536
537
538         /* Extract spells */
539         for (spell = 0; spell < 32; spell++)
540         {
541                 /* Check for this spell */
542                 if ((fake_spell_flags[sval] & (1L << spell)))
543                 {
544                         /* Collect this spell */
545                         spells[num++] = spell;
546                 }
547         }
548
549
550         /* Save the screen */
551         screen_save();
552
553         /* Clear the top line */
554         prt("", 0, 0);
555
556         /* Keep browsing spells.  Exit browsing on cancel. */
557         while(TRUE)
558         {
559                 /* Ask for a spell, allow cancel */
560 #ifdef JP
561                 if (!get_spell(&spell, "Æɤà", o_ptr->sval, TRUE, use_realm))
562 #else
563                 if (!get_spell(&spell, "browse", o_ptr->sval, TRUE, use_realm))
564 #endif
565                 {
566                         /* If cancelled, leave immediately. */
567                         if (spell == -1) break;
568
569                         /* Display a list of spells */
570                         print_spells(0, spells, num, 1, 15, use_realm);
571
572                         /* Notify that there's nothing to see, and wait. */
573                         if (use_realm == REALM_HISSATSU)
574 #ifdef JP
575                                 prt("Æɤá¤ëµ»¤¬¤Ê¤¤¡£", 0, 0);
576 #else
577                                 prt("No techniques to browse.", 0, 0);
578 #endif
579                         else
580 #ifdef JP
581                                 prt("Æɤá¤ë¼öʸ¤¬¤Ê¤¤¡£", 0, 0);
582 #else
583                                 prt("No spells to browse.", 0, 0);
584 #endif
585                         (void)inkey();
586
587
588                         /* Restore the screen */
589                         screen_load();
590
591                         return;
592                 }
593
594                 /* Clear lines, position cursor  (really should use strlen here) */
595                 Term_erase(14, 14, 255);
596                 Term_erase(14, 13, 255);
597                 Term_erase(14, 12, 255);
598                 Term_erase(14, 11, 255);
599
600                 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
601
602                 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
603                 {
604                         prt(&temp[j], line, 15);
605                         line++;
606                 }
607         }
608
609         /* Restore the screen */
610         screen_load();
611 }
612
613
614 static void change_realm2(int next_realm)
615 {
616         int i, j = 0;
617         char tmp[80];
618
619         for (i = 0; i < 64; i++)
620         {
621                 p_ptr->spell_order[j] = p_ptr->spell_order[i];
622                 if (p_ptr->spell_order[i] < 32) j++;
623         }
624         for (; j < 64; j++)
625                 p_ptr->spell_order[j] = 99;
626
627         for (i = 32; i < 64; i++)
628         {
629                 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
630         }
631         p_ptr->spell_learned2 = 0L;
632         p_ptr->spell_worked2 = 0L;
633         p_ptr->spell_forgotten2 = 0L;
634
635 #ifdef JP
636         sprintf(tmp,"ËâË¡¤ÎÎΰè¤ò%s¤«¤é%s¤ËÊѹ¹¤·¤¿¡£", realm_names[p_ptr->realm2], realm_names[next_realm]);
637 #else
638         sprintf(tmp,"change magic realm from %s to %s.", realm_names[p_ptr->realm2], realm_names[next_realm]);
639 #endif
640         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
641         p_ptr->old_realm |= 1 << (p_ptr->realm2-1);
642         p_ptr->realm2 = next_realm;
643
644         p_ptr->notice |= (PN_REORDER);
645         p_ptr->update |= (PU_SPELLS);
646         handle_stuff();
647
648         /* Load an autopick preference file */
649         autopick_load_pref(FALSE);
650 }
651
652
653 /*
654  * Study a book to gain a new spell/prayer
655  */
656 void do_cmd_study(void)
657 {
658         int     i, item, sval;
659         int     increment = 0;
660         bool    learned = FALSE;
661
662         /* Spells of realm2 will have an increment of +32 */
663         int     spell = -1;
664
665         cptr p = spell_category_name(mp_ptr->spell_book);
666
667         object_type *o_ptr;
668
669         cptr q, s;
670
671         if (!p_ptr->realm1)
672         {
673 #ifdef JP
674 msg_print("ËܤòÆɤळ¤È¤¬¤Ç¤­¤Ê¤¤¡ª");
675 #else
676                 msg_print("You cannot read books!");
677 #endif
678
679                 return;
680         }
681
682         if (p_ptr->blind || no_lite())
683         {
684 #ifdef JP
685 msg_print("Ìܤ¬¸«¤¨¤Ê¤¤¡ª");
686 #else
687                 msg_print("You cannot see!");
688 #endif
689
690                 return;
691         }
692
693         if (p_ptr->confused)
694         {
695 #ifdef JP
696 msg_print("º®Í𤷤Ƥ¤¤ÆÆɤá¤Ê¤¤¡ª");
697 #else
698                 msg_print("You are too confused!");
699 #endif
700
701                 return;
702         }
703
704         if (!(p_ptr->new_spells))
705         {
706 #ifdef JP
707 msg_format("¿·¤·¤¤%s¤ò³Ð¤¨¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡ª", p);
708 #else
709                 msg_format("You cannot learn any new %ss!", p);
710 #endif
711
712                 return;
713         }
714
715         if (p_ptr->special_defense & KATA_MUSOU)
716         {
717                 set_action(ACTION_NONE);
718         }
719
720 #ifdef JP
721         if( p_ptr->new_spells < 10 ){
722                 msg_format("¤¢¤È %d ¤Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
723         }else{
724                 msg_format("¤¢¤È %d ¸Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
725         }
726 #else
727         msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
728                 (p_ptr->new_spells == 1?"":"s"));
729 #endif
730
731         msg_print(NULL);
732
733
734         /* Restrict choices to "useful" books */
735         if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
736         else item_tester_hook = item_tester_learn_spell;
737
738         /* Get an item */
739 #ifdef JP
740 q = "¤É¤ÎËܤ«¤é³Ø¤Ó¤Þ¤¹¤«? ";
741 #else
742         q = "Study which book? ";
743 #endif
744
745 #ifdef JP
746 s = "Æɤá¤ëËܤ¬¤Ê¤¤¡£";
747 #else
748         s = "You have no books that you can read.";
749 #endif
750
751         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
752
753         /* Get the item (in the pack) */
754         if (item >= 0)
755         {
756                 o_ptr = &inventory[item];
757         }
758
759         /* Get the item (on the floor) */
760         else
761         {
762                 o_ptr = &o_list[0 - item];
763         }
764
765         /* Access the item's sval */
766         sval = o_ptr->sval;
767
768         if (o_ptr->tval == REALM2_BOOK) increment = 32;
769         else if (o_ptr->tval != REALM1_BOOK)
770         {
771 #ifdef JP
772                 if (!get_check("ËÜÅö¤ËËâË¡¤ÎÎΰè¤òÊѹ¹¤·¤Þ¤¹¤«¡©")) return;
773 #else
774                 if (!get_check("Really, change magic realm? ")) return;
775 #endif
776                 change_realm2(tval2realm(o_ptr->tval));
777                 increment = 32;
778         }
779
780         /* Track the object kind */
781         object_kind_track(o_ptr->k_idx);
782
783         /* Hack -- Handle stuff */
784         handle_stuff();
785
786         /* Mage -- Learn a selected spell */
787         if (mp_ptr->spell_book != TV_LIFE_BOOK)
788         {
789                 /* Ask for a spell, allow cancel */
790 #ifdef JP
791                 if (!get_spell(&spell, "³Ø¤Ö", sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1)
792                         && (spell == -1)) return;
793 #else
794                 if (!get_spell(&spell, "study", sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1)
795                         && (spell == -1)) return;
796 #endif
797
798         }
799
800         /* Priest -- Learn a random prayer */
801         else
802         {
803                 int k = 0;
804
805                 int gift = -1;
806
807                 /* Extract spells */
808                 for (spell = 0; spell < 32; spell++)
809                 {
810                         /* Check spells in the book */
811                         if ((fake_spell_flags[sval] & (1L << spell)))
812                         {
813                                 /* Skip non "okay" prayers */
814                                 if (!spell_okay(spell, FALSE, TRUE,
815                                         (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
816
817                                 /* Hack -- Prepare the randomizer */
818                                 k++;
819
820                                 /* Hack -- Apply the randomizer */
821                                 if (one_in_(k)) gift = spell;
822                         }
823                 }
824
825                 /* Accept gift */
826                 spell = gift;
827         }
828
829         /* Nothing to study */
830         if (spell < 0)
831         {
832                 /* Message */
833 #ifdef JP
834 msg_format("¤½¤ÎËܤˤϳؤ֤٤­%s¤¬¤Ê¤¤¡£", p);
835 #else
836                 msg_format("You cannot learn any %ss in that book.", p);
837 #endif
838
839
840                 /* Abort */
841                 return;
842         }
843
844
845         if (increment) spell += increment;
846
847         /* Learn the spell */
848         if (spell < 32)
849         {
850                 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
851                 else p_ptr->spell_learned1 |= (1L << spell);
852         }
853         else
854         {
855                 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
856                 else p_ptr->spell_learned2 |= (1L << (spell - 32));
857         }
858
859         if (learned)
860         {
861                 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
862                 int old_exp = p_ptr->spell_exp[spell];
863                 int new_rank = EXP_LEVEL_UNSKILLED;
864                 cptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell%32, SPELL_NAME);
865
866                 if (old_exp >= max_exp)
867                 {
868 #ifdef JP
869                         msg_format("¤½¤Î%s¤Ï´°Á´¤Ë»È¤¤¤³¤Ê¤»¤ë¤Î¤Ç³Ø¤ÖɬÍפϤʤ¤¡£", p);
870 #else
871                         msg_format("You don't need to study this %s anymore.", p);
872 #endif
873                         return;
874                 }
875 #ifdef JP
876                 if (!get_check(format("%s¤Î%s¤ò¤µ¤é¤Ë³Ø¤Ó¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©", name, p)))
877 #else
878                 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
879 #endif
880                 {
881                         return;
882                 }
883                 else if (old_exp >= SPELL_EXP_EXPERT)
884                 {
885                         p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
886                         new_rank = EXP_LEVEL_MASTER;
887                 }
888                 else if (old_exp >= SPELL_EXP_SKILLED)
889                 {
890                         if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
891                         else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
892                         new_rank = EXP_LEVEL_EXPERT;
893                 }
894                 else if (old_exp >= SPELL_EXP_BEGINNER)
895                 {
896                         p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
897                         new_rank = EXP_LEVEL_SKILLED;
898                 }
899                 else
900                 {
901                         p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
902                         new_rank = EXP_LEVEL_BEGINNER;
903                 }
904 #ifdef JP
905                 msg_format("%s¤Î½ÏÎýÅÙ¤¬%s¤Ë¾å¤¬¤Ã¤¿¡£", name, exp_level_str[new_rank]);
906 #else
907                 msg_format("Your proficiency of %s is now %s rank.", name, exp_level_str[new_rank]);
908 #endif
909         }
910         else
911         {
912                 /* Find the next open entry in "p_ptr->spell_order[]" */
913                 for (i = 0; i < 64; i++)
914                 {
915                         /* Stop at the first empty space */
916                         if (p_ptr->spell_order[i] == 99) break;
917                 }
918
919                 /* Add the spell to the known list */
920                 p_ptr->spell_order[i++] = spell;
921
922                 /* Mention the result */
923 #ifdef JP
924                 /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½¤ËÂбþ */
925                 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
926                 {
927                         msg_format("%s¤ò³Ø¤ó¤À¡£",
928                                     do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
929                 }
930                 else
931                 {
932                         msg_format("%s¤Î%s¤ò³Ø¤ó¤À¡£",
933                                     do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME) ,p);
934                 }
935 #else
936                 msg_format("You have learned the %s of %s.",
937                         p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
938 #endif
939         }
940
941         /* Take a turn */
942         energy_use = 100;
943
944         switch (mp_ptr->spell_book)
945         {
946         case TV_LIFE_BOOK:
947                 chg_virtue(V_FAITH, 1);
948                 break;
949         case TV_DEATH_BOOK:
950                 chg_virtue(V_UNLIFE, 1);
951                 break;
952         case TV_NATURE_BOOK:
953                 chg_virtue(V_NATURE, 1);
954                 break;
955         default:
956                 chg_virtue(V_KNOWLEDGE, 1);
957                 break;
958         }
959
960         /* Sound */
961         sound(SOUND_STUDY);
962
963         /* One less spell available */
964         p_ptr->learned_spells++;
965 #if 0
966         /* Message if needed */
967         if (p_ptr->new_spells)
968         {
969                 /* Message */
970 #ifdef JP
971                 if (p_ptr->new_spells < 10) msg_format("¤¢¤È %d ¤Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
972                 else msg_format("¤¢¤È %d ¸Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
973 #else
974                 msg_format("You can learn %d more %s%s.", p_ptr->new_spells, p,
975                            (p_ptr->new_spells != 1) ? "s" : "");
976 #endif
977         }
978 #endif
979
980         /* Update Study */
981         p_ptr->update |= (PU_SPELLS);
982         update_stuff();
983
984         /* Redraw object recall */
985         p_ptr->window |= (PW_OBJECT);
986 }
987
988
989 static void wild_magic(int spell)
990 {
991         int counter = 0;
992         int type = SUMMON_BIZARRE1 + randint0(6);
993
994         if (type < SUMMON_BIZARRE1) type = SUMMON_BIZARRE1;
995         else if (type > SUMMON_BIZARRE6) type = SUMMON_BIZARRE6;
996
997         switch (randint1(spell) + randint1(8) + 1)
998         {
999         case 1:
1000         case 2:
1001         case 3:
1002                 teleport_player(10, TELEPORT_PASSIVE);
1003                 break;
1004         case 4:
1005         case 5:
1006         case 6:
1007                 teleport_player(100, TELEPORT_PASSIVE);
1008                 break;
1009         case 7:
1010         case 8:
1011                 teleport_player(200, TELEPORT_PASSIVE);
1012                 break;
1013         case 9:
1014         case 10:
1015         case 11:
1016                 unlite_area(10, 3);
1017                 break;
1018         case 12:
1019         case 13:
1020         case 14:
1021                 lite_area(damroll(2, 3), 2);
1022                 break;
1023         case 15:
1024                 destroy_doors_touch();
1025                 break;
1026         case 16: case 17:
1027                 wall_breaker();
1028         case 18:
1029                 sleep_monsters_touch();
1030                 break;
1031         case 19:
1032         case 20:
1033                 trap_creation(py, px);
1034                 break;
1035         case 21:
1036         case 22:
1037                 door_creation();
1038                 break;
1039         case 23:
1040         case 24:
1041         case 25:
1042                 aggravate_monsters(0);
1043                 break;
1044         case 26:
1045                 earthquake(py, px, 5);
1046                 break;
1047         case 27:
1048         case 28:
1049                 (void)gain_random_mutation(0);
1050                 break;
1051         case 29:
1052         case 30:
1053                 apply_disenchant(1);
1054                 break;
1055         case 31:
1056                 lose_all_info();
1057                 break;
1058         case 32:
1059                 fire_ball(GF_CHAOS, 0, spell + 5, 1 + (spell / 10));
1060                 break;
1061         case 33:
1062                 wall_stone();
1063                 break;
1064         case 34:
1065         case 35:
1066                 while (counter++ < 8)
1067                 {
1068                         (void)summon_specific(0, py, px, (dun_level * 3) / 2, type, (PM_ALLOW_GROUP | PM_NO_PET));
1069                 }
1070                 break;
1071         case 36:
1072         case 37:
1073                 activate_hi_summon(py, px, FALSE);
1074                 break;
1075         case 38:
1076                 (void)summon_cyber(-1, py, px);
1077                 break;
1078         default:
1079                 {
1080                         int count = 0;
1081                         (void)activate_ty_curse(FALSE, &count);
1082                         break;
1083                 }
1084         }
1085
1086         return;
1087 }
1088
1089
1090 /*
1091  * Cast a spell
1092  */
1093 void do_cmd_cast(void)
1094 {
1095         int     item, sval, spell, realm;
1096         int     chance;
1097         int     increment = 0;
1098         int     use_realm;
1099         int     need_mana;
1100
1101         cptr prayer;
1102
1103         object_type     *o_ptr;
1104
1105         const magic_type *s_ptr;
1106
1107         cptr q, s;
1108
1109         bool over_exerted = FALSE;
1110
1111         /* Require spell ability */
1112         if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1113         {
1114 #ifdef JP
1115                 msg_print("¼öʸ¤ò¾§¤¨¤é¤ì¤Ê¤¤¡ª");
1116 #else
1117                 msg_print("You cannot cast spells!");
1118 #endif
1119
1120                 return;
1121         }
1122
1123         /* Require lite */
1124         if (p_ptr->blind || no_lite())
1125         {
1126                 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1127                 else
1128                 {
1129 #ifdef JP
1130                         msg_print("Ìܤ¬¸«¤¨¤Ê¤¤¡ª");
1131 #else
1132                         msg_print("You cannot see!");
1133 #endif
1134                         flush();
1135                 }
1136                 return;
1137         }
1138
1139         /* Not when confused */
1140         if (p_ptr->confused)
1141         {
1142 #ifdef JP
1143                 msg_print("º®Í𤷤Ƥ¤¤Æ¾§¤¨¤é¤ì¤Ê¤¤¡ª");
1144 #else
1145                 msg_print("You are too confused!");
1146 #endif
1147                 flush();
1148                 return;
1149         }
1150
1151         /* Hex */
1152         if (p_ptr->realm1 == REALM_HEX)
1153         {
1154                 if (hex_spell_fully())
1155                 {
1156                         bool flag = FALSE;
1157 #ifdef JP
1158                         msg_print("¤³¤ì°Ê¾å¿·¤·¤¤¼öʸ¤ò±Ó¾§¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£");
1159 #else
1160                         msg_print("Can not spell new spells more.");
1161 #endif
1162                         flush();
1163                         if (p_ptr->lev >= 35) flag = stop_hex_spell();
1164                         if (!flag) return;
1165                 }
1166         }
1167
1168         if (p_ptr->pclass == CLASS_FORCETRAINER)
1169         {
1170                 if (player_has_no_spellbooks())
1171                 {
1172                         confirm_use_force(FALSE);
1173                         return;
1174                 }
1175                 select_the_force = TRUE;
1176         }
1177
1178         prayer = spell_category_name(mp_ptr->spell_book);
1179
1180         /* Restrict choices to spell books */
1181         item_tester_tval = mp_ptr->spell_book;
1182
1183         /* Get an item */
1184 #ifdef JP
1185         q = "¤É¤Î¼öʸ½ñ¤ò»È¤¤¤Þ¤¹¤«? ";
1186 #else
1187         q = "Use which book? ";
1188 #endif
1189
1190 #ifdef JP
1191         s = "¼öʸ½ñ¤¬¤Ê¤¤¡ª";
1192 #else
1193         s = "You have no spell books!";
1194 #endif
1195
1196         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
1197         {
1198                 select_the_force = FALSE;
1199                 return;
1200         }
1201         select_the_force = FALSE;
1202
1203         if (item == INVEN_FORCE) /* the_force */
1204         {
1205                 do_cmd_mind();
1206                 return;
1207         }
1208
1209         /* Get the item (in the pack) */
1210         else if (item >= 0)
1211         {
1212                 o_ptr = &inventory[item];
1213         }
1214
1215         /* Get the item (on the floor) */
1216         else
1217         {
1218                 o_ptr = &o_list[0 - item];
1219         }
1220
1221         /* Access the item's sval */
1222         sval = o_ptr->sval;
1223
1224         if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1225
1226
1227         /* Track the object kind */
1228         object_kind_track(o_ptr->k_idx);
1229
1230         /* Hack -- Handle stuff */
1231         handle_stuff();
1232
1233         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1234                 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1235         else if (increment) realm = p_ptr->realm2;
1236         else realm = p_ptr->realm1;
1237
1238         /* Ask for a spell */
1239 #ifdef JP
1240         if (!get_spell(&spell,  
1241                                 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "±Ó¾§¤¹¤ë" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "²Î¤¦" : "¾§¤¨¤ë"), 
1242                        sval, TRUE, realm))
1243         {
1244                 if (spell == -2) msg_format("¤½¤ÎËܤˤÏÃΤäƤ¤¤ë%s¤¬¤Ê¤¤¡£", prayer);
1245                 return;
1246         }
1247 #else
1248         if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1249                 sval, TRUE, realm))
1250         {
1251                 if (spell == -2)
1252                         msg_format("You don't know any %ss in that book.", prayer);
1253                 return;
1254         }
1255 #endif
1256
1257
1258         use_realm = tval2realm(o_ptr->tval);
1259
1260         /* Hex */
1261         if (use_realm == REALM_HEX)
1262         {
1263                 if (hex_spelling(spell))
1264                 {
1265 #ifdef JP
1266                         msg_print("¤½¤Î¼öʸ¤Ï¤¹¤Ç¤Ë±Ó¾§Ãæ¤À¡£");
1267 #else
1268                         msg_print("You are already casting it.");
1269 #endif
1270                         return;
1271                 }
1272         }
1273
1274         if (!is_magic(use_realm))
1275         {
1276                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1277         }
1278         else
1279         {
1280                 s_ptr = &mp_ptr->info[realm - 1][spell];
1281         }
1282
1283         /* Extract mana consumption rate */
1284         need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1285
1286         /* Verify "dangerous" spells */
1287         if (need_mana > p_ptr->csp)
1288         {
1289                 if (flush_failure) flush();
1290
1291                 /* Warning */
1292 #ifdef JP
1293 msg_format("¤½¤Î%s¤ò%s¤Î¤Ë½½Ê¬¤Ê¥Þ¥¸¥Ã¥¯¥Ý¥¤¥ó¥È¤¬¤Ê¤¤¡£",prayer,
1294  ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "±Ó¾§¤¹¤ë" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "²Î¤¦" : "¾§¤¨¤ë"));
1295 #else
1296                 msg_format("You do not have enough mana to %s this %s.",
1297                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1298                         prayer);
1299 #endif
1300
1301
1302                 if (!over_exert) return;
1303
1304                 /* Verify */
1305 #ifdef JP
1306                 if (!get_check_strict("¤½¤ì¤Ç¤âÄ©À路¤Þ¤¹¤«? ", CHECK_OKAY_CANCEL)) return;
1307 #else
1308                 if (!get_check_strict("Attempt it anyway? ", CHECK_OKAY_CANCEL)) return;
1309 #endif
1310
1311         }
1312
1313         /* Spell failure chance */
1314         chance = spell_chance(spell, use_realm);
1315
1316         /* Sufficient mana */
1317         if (need_mana <= p_ptr->csp)
1318         {
1319                 /* Use some mana */
1320                 p_ptr->csp -= need_mana;
1321         }
1322         else over_exerted = TRUE;
1323
1324         /* Redraw mana */
1325         p_ptr->redraw |= (PR_MANA);
1326
1327         /* Failed spell */
1328         if (randint0(100) < chance)
1329         {
1330                 if (flush_failure) flush();
1331
1332 #ifdef JP
1333 msg_format("%s¤ò¤¦¤Þ¤¯¾§¤¨¤é¤ì¤Ê¤«¤Ã¤¿¡ª", prayer);
1334 #else
1335                 msg_format("You failed to get the %s off!", prayer);
1336 #endif
1337
1338                 sound(SOUND_FAIL);
1339
1340                 switch (realm)
1341                 {
1342                 case REALM_LIFE:
1343                         if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1344                         break;
1345                 case REALM_DEATH:
1346                         if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1347                         break;
1348                 case REALM_NATURE:
1349                         if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1350                         break;
1351                 case REALM_DAEMON:
1352                         if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1353                         break;
1354                 case REALM_CRUSADE:
1355                         if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1356                         break;
1357                 case REALM_HEX:
1358                         if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1359                         break;
1360                 default:
1361                         if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1362                         break;
1363                 }
1364
1365                 /* Failure casting may activate some side effect */
1366                 do_spell(realm, spell, SPELL_FAIL);
1367
1368
1369                 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1370                 {
1371 #ifdef JP
1372 msg_print("¥«¥ª¥¹Åª¤Ê¸ú²Ì¤òȯÀ¸¤·¤¿¡ª");
1373 #else
1374                         msg_print("You produce a chaotic effect!");
1375 #endif
1376
1377                         wild_magic(spell);
1378                 }
1379                 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1380                 {
1381                         if ((sval == 3) && one_in_(2))
1382                         {
1383                                 sanity_blast(0, TRUE);
1384                         }
1385                         else
1386                         {
1387 #ifdef JP
1388                                 msg_print("Äˤ¤¡ª");
1389 #else
1390                                 msg_print("It hurts!");
1391 #endif
1392
1393 #ifdef JP
1394                                 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), "°Å¹õËâË¡¤ÎµÕή", -1);
1395 #else
1396                                 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), "a miscast Death spell", -1);
1397 #endif
1398
1399                                 if ((spell > 15) && one_in_(6) && !p_ptr->hold_life)
1400                                         lose_exp(spell * 250);
1401                         }
1402                 }
1403                 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1404                 {
1405 #ifdef JP
1406 msg_print("¤¤¤ä¤Ê²»¤¬¶Á¤¤¤¿");
1407 #else
1408 msg_print("An infernal sound echoed.");
1409 #endif
1410
1411                         aggravate_monsters(0);
1412                 }
1413                 if (randint1(100) >= chance)
1414                         chg_virtue(V_CHANCE,-1);
1415         }
1416
1417         /* Process spell */
1418         else
1419         {
1420                 /* Canceled spells cost neither a turn nor mana */
1421                 if (!do_spell(realm, spell, SPELL_CAST)) return;
1422
1423                 if (randint1(100) < chance)
1424                         chg_virtue(V_CHANCE,1);
1425
1426                 /* A spell was cast */
1427                 if (!(increment ?
1428                     (p_ptr->spell_worked2 & (1L << spell)) :
1429                     (p_ptr->spell_worked1 & (1L << spell)))
1430                     && (p_ptr->pclass != CLASS_SORCERER)
1431                     && (p_ptr->pclass != CLASS_RED_MAGE))
1432                 {
1433                         int e = s_ptr->sexp;
1434
1435                         /* The spell worked */
1436                         if (realm == p_ptr->realm1)
1437                         {
1438                                 p_ptr->spell_worked1 |= (1L << spell);
1439                         }
1440                         else
1441                         {
1442                                 p_ptr->spell_worked2 |= (1L << spell);
1443                         }
1444
1445                         /* Gain experience */
1446                         gain_exp(e * s_ptr->slevel);
1447
1448                         /* Redraw object recall */
1449                         p_ptr->window |= (PW_OBJECT);
1450
1451                         switch (realm)
1452                         {
1453                         case REALM_LIFE:
1454                                 chg_virtue(V_TEMPERANCE, 1);
1455                                 chg_virtue(V_COMPASSION, 1);
1456                                 chg_virtue(V_VITALITY, 1);
1457                                 chg_virtue(V_DILIGENCE, 1);
1458                                 break;
1459                         case REALM_DEATH:
1460                                 chg_virtue(V_UNLIFE, 1);
1461                                 chg_virtue(V_JUSTICE, -1);
1462                                 chg_virtue(V_FAITH, -1);
1463                                 chg_virtue(V_VITALITY, -1);
1464                                 break;
1465                         case REALM_DAEMON:
1466                                 chg_virtue(V_JUSTICE, -1);
1467                                 chg_virtue(V_FAITH, -1);
1468                                 chg_virtue(V_HONOUR, -1);
1469                                 chg_virtue(V_TEMPERANCE, -1);
1470                                 break;
1471                         case REALM_CRUSADE:
1472                                 chg_virtue(V_FAITH, 1);
1473                                 chg_virtue(V_JUSTICE, 1);
1474                                 chg_virtue(V_SACRIFICE, 1);
1475                                 chg_virtue(V_HONOUR, 1);
1476                                 break;
1477                         case REALM_NATURE:
1478                                 chg_virtue(V_NATURE, 1);
1479                                 chg_virtue(V_HARMONY, 1);
1480                                 break;
1481                         case REALM_HEX:
1482                                 chg_virtue(V_JUSTICE, -1);
1483                                 chg_virtue(V_FAITH, -1);
1484                                 chg_virtue(V_HONOUR, -1);
1485                                 chg_virtue(V_COMPASSION, -1);
1486                                 break;
1487                         default:
1488                                 chg_virtue(V_KNOWLEDGE, 1);
1489                                 break;
1490                         }
1491                 }
1492                 switch (realm)
1493                 {
1494                 case REALM_LIFE:
1495                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1496                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1497                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1498                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1499                         break;
1500                 case REALM_DEATH:
1501                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1502                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1503                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1504                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1505                         break;
1506                 case REALM_DAEMON:
1507                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1508                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1509                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1510                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1511                         break;
1512                 case REALM_CRUSADE:
1513                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1514                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1515                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1516                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1517                         break;
1518                 case REALM_NATURE:
1519                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1520                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1521                         break;
1522                 case REALM_HEX:
1523                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1524                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1525                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1526                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1527                         break;
1528                 }
1529                 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1530                 {
1531                         s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0)+spell];
1532                         s16b exp_gain = 0;
1533
1534                         if (cur_exp < SPELL_EXP_BEGINNER)
1535                                 exp_gain += 60;
1536                         else if (cur_exp < SPELL_EXP_SKILLED)
1537                         {
1538                                 if ((dun_level > 4) && ((dun_level + 10) > p_ptr->lev))
1539                                         exp_gain = 8;
1540                         }
1541                         else if (cur_exp < SPELL_EXP_EXPERT)
1542                         {
1543                                 if (((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel))
1544                                         exp_gain = 2;
1545                         }
1546                         else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1547                         {
1548                                 if (((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel))
1549                                         exp_gain = 1;
1550                         }
1551                         p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1552                 }
1553         }
1554
1555         /* Take a turn */
1556         energy_use = 100;
1557
1558
1559         /* Over-exert the player */
1560         if(over_exerted)
1561         {
1562                 int oops = need_mana;
1563
1564                 /* No mana left */
1565                 p_ptr->csp = 0;
1566                 p_ptr->csp_frac = 0;
1567
1568                 /* Message */
1569 #ifdef JP
1570 msg_print("Àº¿À¤ò½¸Ã椷¤¹¤®¤Æµ¤¤ò¼º¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
1571 #else
1572                 msg_print("You faint from the effort!");
1573 #endif
1574
1575
1576                 /* Hack -- Bypass free action */
1577                 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1578
1579                 switch (realm)
1580                 {
1581                 case REALM_LIFE:
1582                         chg_virtue(V_VITALITY, -10);
1583                         break;
1584                 case REALM_DEATH:
1585                         chg_virtue(V_UNLIFE, -10);
1586                         break;
1587                 case REALM_DAEMON:
1588                         chg_virtue(V_JUSTICE, 10);
1589                         break;
1590                 case REALM_NATURE:
1591                         chg_virtue(V_NATURE, -10);
1592                         break;
1593                 case REALM_CRUSADE:
1594                         chg_virtue(V_JUSTICE, -10);
1595                         break;
1596                 case REALM_HEX:
1597                         chg_virtue(V_COMPASSION, 10);
1598                         break;
1599                 default:
1600                         chg_virtue(V_KNOWLEDGE, -10);
1601                         break;
1602                 }
1603
1604                 /* Damage CON (possibly permanently) */
1605                 if (randint0(100) < 50)
1606                 {
1607                         bool perm = (randint0(100) < 25);
1608
1609                         /* Message */
1610 #ifdef JP
1611 msg_print("ÂΤò°­¤¯¤·¤Æ¤·¤Þ¤Ã¤¿¡ª");
1612 #else
1613                         msg_print("You have damaged your health!");
1614 #endif
1615
1616
1617                         /* Reduce constitution */
1618                         (void)dec_stat(A_CON, 15 + randint1(10), perm);
1619                 }
1620         }
1621
1622         /* Window stuff */
1623         p_ptr->window |= (PW_PLAYER);
1624         p_ptr->window |= (PW_SPELL);
1625 }
1626
1627
1628 static bool ang_sort_comp_pet_dismiss(vptr u, vptr v, int a, int b)
1629 {
1630         u16b *who = (u16b*)(u);
1631
1632         int w1 = who[a];
1633         int w2 = who[b];
1634
1635         monster_type *m_ptr1 = &m_list[w1];
1636         monster_type *m_ptr2 = &m_list[w2];
1637         monster_race *r_ptr1 = &r_info[m_ptr1->r_idx];
1638         monster_race *r_ptr2 = &r_info[m_ptr2->r_idx];
1639
1640         /* Unused */
1641         (void)v;
1642
1643         if (w1 == p_ptr->riding) return TRUE;
1644         if (w2 == p_ptr->riding) return FALSE;
1645
1646         if (m_ptr1->nickname && !m_ptr2->nickname) return TRUE;
1647         if (m_ptr2->nickname && !m_ptr1->nickname) return FALSE;
1648
1649         if (!m_ptr1->parent_m_idx && m_ptr2->parent_m_idx) return TRUE;
1650         if (!m_ptr2->parent_m_idx && m_ptr1->parent_m_idx) return FALSE;
1651
1652         if ((r_ptr1->flags1 & RF1_UNIQUE) && !(r_ptr2->flags1 & RF1_UNIQUE)) return TRUE;
1653         if ((r_ptr2->flags1 & RF1_UNIQUE) && !(r_ptr1->flags1 & RF1_UNIQUE)) return FALSE;
1654
1655         if (r_ptr1->level > r_ptr2->level) return TRUE;
1656         if (r_ptr2->level > r_ptr1->level) return FALSE;
1657
1658         if (m_ptr1->hp > m_ptr2->hp) return TRUE;
1659         if (m_ptr2->hp > m_ptr1->hp) return FALSE;
1660         
1661         return w1 <= w2;
1662 }
1663
1664 void check_pets_num_and_align(monster_type *m_ptr, bool inc)
1665 {
1666         s32b old_friend_align = friend_align;
1667         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1668
1669         if (inc)
1670         {
1671                 total_friends++;
1672                 if (r_ptr->flags3 & RF3_GOOD) friend_align += r_ptr->level;
1673                 if (r_ptr->flags3 & RF3_EVIL) friend_align -= r_ptr->level;
1674         }
1675         else
1676         {
1677                 total_friends--;
1678                 if (r_ptr->flags3 & RF3_GOOD) friend_align -= r_ptr->level;
1679                 if (r_ptr->flags3 & RF3_EVIL) friend_align += r_ptr->level;
1680         }
1681
1682         if (old_friend_align != friend_align) p_ptr->update |= (PU_BONUS);
1683 }
1684
1685 int calculate_upkeep(void)
1686 {
1687         s32b old_friend_align = friend_align;
1688         int m_idx;
1689         bool have_a_unique = FALSE;
1690         s32b total_friend_levels = 0;
1691
1692         total_friends = 0;
1693         friend_align = 0;
1694
1695         for (m_idx = m_max - 1; m_idx >=1; m_idx--)
1696         {
1697                 monster_type *m_ptr;
1698                 monster_race *r_ptr;
1699                 
1700                 m_ptr = &m_list[m_idx];
1701                 if (!m_ptr->r_idx) continue;
1702                 r_ptr = &r_info[m_ptr->r_idx];
1703
1704                 if (is_pet(m_ptr))
1705                 {
1706                         total_friends++;
1707                         if (r_ptr->flags1 & RF1_UNIQUE)
1708                         {
1709                                 if (p_ptr->pclass == CLASS_CAVALRY)
1710                                 {
1711                                         if (p_ptr->riding == m_idx)
1712                                                 total_friend_levels += (r_ptr->level+5)*2;
1713                                         else if (!have_a_unique && (r_info[m_ptr->r_idx].flags7 & RF7_RIDING))
1714                                                 total_friend_levels += (r_ptr->level+5)*7/2;
1715                                         else
1716                                                 total_friend_levels += (r_ptr->level+5)*10;
1717                                         have_a_unique = TRUE;
1718                                 }
1719                                 else
1720                                         total_friend_levels += (r_ptr->level+5)*10;
1721                         }
1722                         else
1723                                 total_friend_levels += r_ptr->level;
1724
1725                         /* Determine pet alignment */
1726                         if (r_ptr->flags3 & RF3_GOOD) friend_align += r_ptr->level;
1727                         if (r_ptr->flags3 & RF3_EVIL) friend_align -= r_ptr->level;
1728                 }
1729         }
1730         if (old_friend_align != friend_align) p_ptr->update |= (PU_BONUS);
1731         if (total_friends)
1732         {
1733                 int upkeep_factor;
1734                 upkeep_factor = (total_friend_levels - (p_ptr->lev * 80 / (cp_ptr->pet_upkeep_div)));
1735                 if (upkeep_factor < 0) upkeep_factor = 0;
1736                 if (upkeep_factor > 1000) upkeep_factor = 1000;
1737                 return upkeep_factor;
1738         }
1739         else
1740                 return 0;
1741 }
1742
1743 void do_cmd_pet_dismiss(void)
1744 {
1745         monster_type    *m_ptr;
1746         bool            all_pets = FALSE;
1747         int pet_ctr, i;
1748         int Dismissed = 0;
1749
1750         u16b *who;
1751         u16b dummy_why;
1752         int max_pet = 0;
1753         int cu, cv;
1754
1755         cu = Term->scr->cu;
1756         cv = Term->scr->cv;
1757         Term->scr->cu = 0;
1758         Term->scr->cv = 1;
1759
1760         /* Allocate the "who" array */
1761         C_MAKE(who, max_m_idx, u16b);
1762
1763         /* Process the monsters (backwards) */
1764         for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
1765         {
1766                 if (is_pet(&m_list[pet_ctr]))
1767                         who[max_pet++] = pet_ctr;
1768         }
1769
1770         /* Select the sort method */
1771         ang_sort_comp = ang_sort_comp_pet_dismiss;
1772         ang_sort_swap = ang_sort_swap_hook;
1773
1774         ang_sort(who, &dummy_why, max_pet);
1775
1776         /* Process the monsters (backwards) */
1777         for (i = 0; i < max_pet; i++)
1778         {
1779                 bool delete_this;
1780                 char friend_name[80];
1781                 bool kakunin;
1782
1783                 /* Access the monster */
1784                 pet_ctr = who[i];
1785                 m_ptr = &m_list[pet_ctr];
1786
1787                 delete_this = FALSE;
1788                 kakunin = ((pet_ctr == p_ptr->riding) || (m_ptr->nickname));
1789                 monster_desc(friend_name, m_ptr, MD_ASSUME_VISIBLE);
1790
1791                 if (!all_pets)
1792                 {
1793                         /* Hack -- health bar for this monster */
1794                         health_track(pet_ctr);
1795
1796                         /* Hack -- handle stuff */
1797                         handle_stuff();
1798                         
1799                         msg_format(_("%s¤òÊü¤·¤Þ¤¹¤«¡© [Yes/No/Unnamed (%dÂÎ)]","Dismiss %s? [Yes/No/Unnamed (%d remain)]"), friend_name, max_pet - i);
1800                         
1801                         if (m_ptr->ml)
1802                                 move_cursor_relative(m_ptr->fy, m_ptr->fx);
1803
1804                         while (TRUE)
1805                         {
1806                                 char ch = inkey();
1807
1808                                 if (ch == 'Y' || ch == 'y')
1809                                 {
1810                                         delete_this = TRUE;
1811
1812                                         if (kakunin)
1813                                         {
1814                                                 msg_format(_("ËÜÅö¤Ë¤è¤í¤·¤¤¤Ç¤¹¤«¡© (%s) ","Are you sure? (%s) "), friend_name);
1815                                                 ch = inkey();
1816                                                 if (ch != 'Y' && ch != 'y')
1817                                                         delete_this = FALSE;
1818                                         }
1819                                         break;
1820                                 }
1821
1822                                 if (ch == 'U' || ch == 'u')
1823                                 {
1824                                         all_pets = TRUE;
1825                                         break;
1826                                 }
1827
1828                                 if (ch == ESCAPE || ch == 'N' || ch == 'n')
1829                                         break;
1830
1831                                 bell();
1832                         }
1833                 }
1834
1835                 if ((all_pets && !kakunin) || (!all_pets && delete_this))
1836                 {
1837                         if (record_named_pet && m_ptr->nickname)
1838                         {
1839                                 char m_name[80];
1840
1841                                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1842                                 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_DISMISS, m_name);
1843                         }
1844
1845                         if (pet_ctr == p_ptr->riding)
1846                         {
1847                                 msg_format(_("%s¤«¤é¹ß¤ê¤¿¡£","You have got off %s. "), friend_name);
1848
1849                                 p_ptr->riding = 0;
1850
1851                                 /* Update the monsters */
1852                                 p_ptr->update |= (PU_BONUS | PU_MONSTERS);
1853                                 p_ptr->redraw |= (PR_EXTRA | PR_UHEALTH);
1854                         }
1855
1856                         /* HACK : Add the line to message buffer */
1857                         msg_format(_("%s ¤òÊü¤·¤¿¡£","Dismissed %s."), friend_name);
1858                         p_ptr->window |= (PW_MESSAGE);
1859                         window_stuff();
1860
1861                         delete_monster_idx(pet_ctr);
1862                         Dismissed++;
1863                 }
1864         }
1865
1866         Term->scr->cu = cu;
1867         Term->scr->cv = cv;
1868         Term_fresh();
1869
1870         C_KILL(who, max_m_idx, u16b);
1871
1872 #ifdef JP
1873         msg_format("%d ÂΤΥڥåȤòÊü¤·¤Þ¤·¤¿¡£", Dismissed);
1874 #else
1875         msg_format("You have dismissed %d pet%s.", Dismissed,
1876                    (Dismissed == 1 ? "" : "s"));
1877 #endif
1878         if (Dismissed == 0 && all_pets)
1879 #ifdef JP
1880                 msg_print("'U'nnamed ¤Ï¡¢¾èÇϰʳ°¤Î̾Á°¤Î¤Ê¤¤¥Ú¥Ã¥È¤À¤±¤òÁ´¤Æ²òÊü¤·¤Þ¤¹¡£");
1881 #else
1882                 msg_print("'U'nnamed means all your pets except named pets and your mount.");
1883 #endif
1884 }
1885
1886 static bool player_can_ride_aux(cave_type *c_ptr, bool now_riding)
1887 {
1888         bool p_can_enter;
1889         bool old_character_xtra = character_xtra;
1890         int  old_riding = p_ptr->riding;
1891         bool old_riding_ryoute = p_ptr->riding_ryoute;
1892         bool old_old_riding_ryoute = p_ptr->old_riding_ryoute;
1893         bool old_pf_ryoute = (p_ptr->pet_extra_flags & PF_RYOUTE) ? TRUE : FALSE;
1894
1895         /* Hack -- prevent "icky" message */
1896         character_xtra = TRUE;
1897
1898         if (now_riding) p_ptr->riding = c_ptr->m_idx;
1899         else
1900         {
1901                 p_ptr->riding = 0;
1902                 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
1903                 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
1904         }
1905
1906         calc_bonuses();
1907
1908         p_can_enter = player_can_enter(c_ptr->feat, CEM_P_CAN_ENTER_PATTERN);
1909
1910         p_ptr->riding = old_riding;
1911         if (old_pf_ryoute) p_ptr->pet_extra_flags |= (PF_RYOUTE);
1912         else p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
1913         p_ptr->riding_ryoute = old_riding_ryoute;
1914         p_ptr->old_riding_ryoute = old_old_riding_ryoute;
1915
1916         calc_bonuses();
1917
1918         character_xtra = old_character_xtra;
1919
1920         return p_can_enter;
1921 }
1922
1923 bool rakuba(int dam, bool force)
1924 {
1925         int i, y, x, oy, ox;
1926         int sn = 0, sy = 0, sx = 0;
1927         char m_name[80];
1928         monster_type *m_ptr = &m_list[p_ptr->riding];
1929         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1930         bool fall_dam = FALSE;
1931
1932         if (!p_ptr->riding) return FALSE;
1933         if (p_ptr->wild_mode) return FALSE;
1934
1935         if (dam >= 0 || force)
1936         {
1937                 if (!force)
1938                 {
1939                         int cur = p_ptr->skill_exp[GINOU_RIDING];
1940                         int max = s_info[p_ptr->pclass].s_max[GINOU_RIDING];
1941                         int ridinglevel = r_ptr->level;
1942
1943                         /* ÍîÇϤΤ·¤ä¤¹¤µ */
1944                         int rakubalevel = r_ptr->level;
1945                         if (p_ptr->riding_ryoute) rakubalevel += 20;
1946
1947                         if ((cur < max) && (max > 1000) &&
1948                             (dam / 2 + ridinglevel) > (cur / 30 + 10))
1949                         {
1950                                 int inc = 0;
1951
1952                                 if (ridinglevel > (cur / 100 + 15))
1953                                         inc += 1 + (ridinglevel - cur / 100 - 15);
1954                                 else
1955                                         inc += 1;
1956
1957                                 p_ptr->skill_exp[GINOU_RIDING] = MIN(max, cur + inc);
1958                         }
1959
1960                         /* ¥ì¥Ù¥ë¤ÎÄ㤤¾èÇϤ«¤é¤ÏÍîÇϤ·¤Ë¤¯¤¤ */
1961                         if (randint0(dam / 2 + rakubalevel * 2) < cur / 30 + 10)
1962                         {
1963                                 if ((((p_ptr->pclass == CLASS_BEASTMASTER) || (p_ptr->pclass == CLASS_CAVALRY)) && !p_ptr->riding_ryoute) || !one_in_(p_ptr->lev*(p_ptr->riding_ryoute ? 2 : 3) + 30))
1964                                 {
1965                                         return FALSE;
1966                                 }
1967                         }
1968                 }
1969
1970                 /* Check around the player */
1971                 for (i = 0; i < 8; i++)
1972                 {
1973                         cave_type *c_ptr;
1974
1975                         /* Access the location */
1976                         y = py + ddy_ddd[i];
1977                         x = px + ddx_ddd[i];
1978
1979                         c_ptr = &cave[y][x];
1980
1981                         if (c_ptr->m_idx) continue;
1982
1983                         /* Skip non-empty grids */
1984                         if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !cave_have_flag_grid(c_ptr, FF_CAN_FLY))
1985                         {
1986                                 if (!player_can_ride_aux(c_ptr, FALSE)) continue;
1987                         }
1988
1989                         if (cave_have_flag_grid(c_ptr, FF_PATTERN)) continue;
1990
1991                         /* Count "safe" grids */
1992                         sn++;
1993
1994                         /* Randomize choice */
1995                         if (randint0(sn) > 0) continue;
1996
1997                         /* Save the safe location */
1998                         sy = y; sx = x;
1999                 }
2000                 if (!sn)
2001                 {
2002                         monster_desc(m_name, m_ptr, 0);
2003 #ifdef JP
2004 msg_format("%s¤«¤é¿¶¤êÍî¤È¤µ¤ì¤½¤¦¤Ë¤Ê¤Ã¤Æ¡¢Êɤˤ֤Ĥ«¤Ã¤¿¡£",m_name);
2005                         take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "Êɤؤξ×ÆÍ", -1);
2006 #else
2007                         msg_format("You have nearly fallen from %s, but bumped into wall.",m_name);
2008                         take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "bumping into wall", -1);
2009 #endif
2010                         return FALSE;
2011                 }
2012
2013                 oy = py;
2014                 ox = px;
2015
2016                 py = sy;
2017                 px = sx;
2018
2019                 /* Redraw the old spot */
2020                 lite_spot(oy, ox);
2021
2022                 /* Redraw the new spot */
2023                 lite_spot(py, px);
2024
2025                 /* Check for new panel */
2026                 verify_panel();
2027         }
2028
2029         p_ptr->riding = 0;
2030         p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
2031         p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
2032
2033         calc_bonuses();
2034
2035         p_ptr->update |= (PU_BONUS);
2036
2037         /* Update stuff */
2038         p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
2039
2040         /* Window stuff */
2041         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2042
2043         p_ptr->redraw |= (PR_EXTRA);
2044
2045         /* Update health track of mount */
2046         p_ptr->redraw |= (PR_UHEALTH);
2047
2048         if (p_ptr->levitation && !force)
2049         {
2050                 monster_desc(m_name, m_ptr, 0);
2051 #ifdef JP
2052                 msg_format("%s¤«¤éÍî¤Á¤¿¤¬¡¢¶õÃæ¤Ç¤¦¤Þ¤¯ÂÎÀª¤òΩ¤Æľ¤·¤ÆÃåÃϤ·¤¿¡£",m_name);
2053 #else
2054                 msg_format("You are thrown from %s, but make a good landing.",m_name);
2055 #endif
2056         }
2057         else
2058         {
2059 #ifdef JP
2060                 take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "ÍîÇÏ", -1);
2061 #else
2062                 take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "Falling from riding", -1);
2063 #endif
2064                 fall_dam = TRUE;
2065         }
2066
2067         /* Move the player */
2068         if (sy && !p_ptr->is_dead)
2069                 (void)move_player_effect(py, px, MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);
2070
2071         return fall_dam;
2072 }
2073
2074 bool do_riding(bool force)
2075 {
2076         int x, y, dir = 0;
2077         cave_type *c_ptr;
2078         monster_type *m_ptr;
2079
2080         if (!get_rep_dir2(&dir)) return FALSE;
2081         y = py + ddy[dir];
2082         x = px + ddx[dir];
2083         c_ptr = &cave[y][x];
2084
2085         if (p_ptr->special_defense & KATA_MUSOU) set_action(ACTION_NONE);
2086
2087         if (p_ptr->riding)
2088         {
2089                 /* Skip non-empty grids */
2090                 if (!player_can_ride_aux(c_ptr, FALSE))
2091                 {
2092 #ifdef JP
2093                         msg_print("¤½¤Á¤é¤Ë¤Ï¹ß¤ê¤é¤ì¤Þ¤»¤ó¡£");
2094 #else
2095                         msg_print("You cannot go to that direction.");
2096 #endif
2097                         return FALSE;
2098                 }
2099
2100                 if (!pattern_seq(py, px, y, x)) return FALSE;
2101
2102                 if (c_ptr->m_idx)
2103                 {
2104                         /* Take a turn */
2105                         energy_use = 100;
2106
2107                         /* Message */
2108 #ifdef JP
2109                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2110 #else
2111                         msg_print("There is a monster in the way!");
2112 #endif
2113
2114                         py_attack(y, x, 0);
2115                         return FALSE;
2116                 }
2117
2118                 p_ptr->riding = 0;
2119                 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
2120                 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
2121         }
2122         else
2123         {
2124                 if (p_ptr->confused)
2125                 {
2126 #ifdef JP
2127                         msg_print("º®Í𤷤Ƥ¤¤Æ¾è¤ì¤Ê¤¤¡ª");
2128 #else
2129                         msg_print("You are too confused!");
2130 #endif
2131                         return FALSE;
2132                 }
2133
2134                 m_ptr = &m_list[c_ptr->m_idx];
2135
2136                 if (!c_ptr->m_idx || !m_ptr->ml)
2137                 {
2138 #ifdef JP
2139                         msg_print("¤½¤Î¾ì½ê¤Ë¤Ï¥â¥ó¥¹¥¿¡¼¤Ï¤¤¤Þ¤»¤ó¡£");
2140 #else
2141                         msg_print("Here is no monster.");
2142 #endif
2143
2144                         return FALSE;
2145                 }
2146                 if (!is_pet(m_ptr) && !force)
2147                 {
2148 #ifdef JP
2149                         msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ï¥Ú¥Ã¥È¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£");
2150 #else
2151                         msg_print("That monster is not a pet.");
2152 #endif
2153
2154                         return FALSE;
2155                 }
2156                 if (!(r_info[m_ptr->r_idx].flags7 & RF7_RIDING))
2157                 {
2158 #ifdef JP
2159                         msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ë¤Ï¾è¤ì¤Ê¤µ¤½¤¦¤À¡£");
2160 #else
2161                         msg_print("This monster doesn't seem suitable for riding.");
2162 #endif
2163
2164                         return FALSE;
2165                 }
2166
2167                 if (!pattern_seq(py, px, y, x)) return FALSE;
2168
2169                 if (!player_can_ride_aux(c_ptr, TRUE))
2170                 {
2171                         /* Feature code (applying "mimic" field) */
2172                         feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
2173 #ifdef JP
2174                         msg_format("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ï%s¤Î%s¤Ë¤¤¤ë¡£", f_name + f_ptr->name,
2175                                    ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
2176                                     (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE))) ?
2177                                    "Ãæ" : "¾å");
2178 #else
2179                         msg_format("This monster is %s the %s.",
2180                                    ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
2181                                     (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE))) ?
2182                                    "in" : "on", f_name + f_ptr->name);
2183 #endif
2184
2185                         return FALSE;
2186                 }
2187                 if (r_info[m_ptr->r_idx].level > randint1((p_ptr->skill_exp[GINOU_RIDING] / 50 + p_ptr->lev / 2 + 20)))
2188                 {
2189 #ifdef JP
2190                         msg_print("¤¦¤Þ¤¯¾è¤ì¤Ê¤«¤Ã¤¿¡£");
2191 #else
2192                         msg_print("You failed to ride.");
2193 #endif
2194
2195                         energy_use = 100;
2196
2197                         return FALSE;
2198                 }
2199
2200                 if (MON_CSLEEP(m_ptr))
2201                 {
2202                         char m_name[80];
2203                         monster_desc(m_name, m_ptr, 0);
2204                         (void)set_monster_csleep(c_ptr->m_idx, 0);
2205 #ifdef JP
2206                         msg_format("%s¤òµ¯¤³¤·¤¿¡£", m_name);
2207 #else
2208                         msg_format("You have waked %s up.", m_name);
2209 #endif
2210                 }
2211
2212                 if (p_ptr->action == ACTION_KAMAE) set_action(ACTION_NONE);
2213
2214                 p_ptr->riding = c_ptr->m_idx;
2215
2216                 /* Hack -- remove tracked monster */
2217                 if (p_ptr->riding == p_ptr->health_who) health_track(0);
2218         }
2219
2220         energy_use = 100;
2221
2222         /* Mega-Hack -- Forget the view and lite */
2223         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
2224
2225         /* Update the monsters */
2226         p_ptr->update |= (PU_BONUS);
2227
2228         /* Redraw map */
2229         p_ptr->redraw |= (PR_MAP | PR_EXTRA);
2230
2231         p_ptr->redraw |= (PR_UHEALTH);
2232
2233         /* Move the player */
2234         (void)move_player_effect(y, x, MPE_HANDLE_STUFF | MPE_ENERGY_USE | MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);
2235
2236         return TRUE;
2237 }
2238
2239 static void do_name_pet(void)
2240 {
2241         monster_type *m_ptr;
2242         char out_val[20];
2243         char m_name[80];
2244         bool old_name = FALSE;
2245         bool old_target_pet = target_pet;
2246
2247         target_pet = TRUE;
2248         if (!target_set(TARGET_KILL))
2249         {
2250                 target_pet = old_target_pet;
2251                 return;
2252         }
2253         target_pet = old_target_pet;
2254
2255         if (cave[target_row][target_col].m_idx)
2256         {
2257                 m_ptr = &m_list[cave[target_row][target_col].m_idx];
2258
2259                 if (!is_pet(m_ptr))
2260                 {
2261                         /* Message */
2262 #ifdef JP
2263                         msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ï¥Ú¥Ã¥È¤Ç¤Ï¤Ê¤¤¡£");
2264 #else
2265                         msg_format("This monster is not a pet.");
2266 #endif
2267                         return;
2268                 }
2269                 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2270                 {
2271 #ifdef JP
2272                         msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Î̾Á°¤ÏÊѤ¨¤é¤ì¤Ê¤¤¡ª");
2273 #else
2274                         msg_format("You cannot change name of this monster!");
2275 #endif
2276                         return;
2277                 }
2278                 monster_desc(m_name, m_ptr, 0);
2279
2280                 /* Message */
2281 #ifdef JP
2282                 msg_format("%s¤Ë̾Á°¤ò¤Ä¤±¤ë¡£", m_name);
2283 #else
2284                 msg_format("Name %s.", m_name);
2285 #endif
2286
2287                 msg_print(NULL);
2288
2289                 /* Start with nothing */
2290                 strcpy(out_val, "");
2291
2292                 /* Use old inscription */
2293                 if (m_ptr->nickname)
2294                 {
2295                         /* Start with the old inscription */
2296                         strcpy(out_val, quark_str(m_ptr->nickname));
2297                         old_name = TRUE;
2298                 }
2299
2300                 /* Get a new inscription (possibly empty) */
2301 #ifdef JP
2302                 if (get_string("̾Á°: ", out_val, 15))
2303 #else
2304                 if (get_string("Name: ", out_val, 15))
2305 #endif
2306
2307                 {
2308                         if (out_val[0])
2309                         {
2310                                 /* Save the inscription */
2311                                 m_ptr->nickname = quark_add(out_val);
2312                                 if (record_named_pet)
2313                                 {
2314                                         char m_name[80];
2315
2316                                         monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
2317                                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_NAME, m_name);
2318                                 }
2319                         }
2320                         else
2321                         {
2322                                 if (record_named_pet && old_name)
2323                                 {
2324                                         char m_name[80];
2325
2326                                         monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
2327                                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_UNNAME, m_name);
2328                                 }
2329                                 m_ptr->nickname = 0;
2330                         }
2331                 }
2332         }
2333 }
2334
2335 /*
2336  * Issue a pet command
2337  */
2338 void do_cmd_pet(void)
2339 {
2340         int                     i = 0;
2341         int                     num;
2342         int                     powers[36];
2343         cptr                    power_desc[36];
2344         bool                    flag, redraw;
2345         char                    choice;
2346         char                    out_val[160];
2347         int                     pet_ctr;
2348         monster_type    *m_ptr;
2349
2350         int mode = 0;
2351
2352         char buf[160];
2353         char target_buf[160];
2354
2355         int menu_line = use_menu ? 1 : 0;
2356
2357         num = 0;
2358
2359 #ifdef JP
2360         power_desc[num] = "¥Ú¥Ã¥È¤òÊü¤¹";
2361 #else
2362         power_desc[num] = "dismiss pets";
2363 #endif
2364
2365         powers[num++] = PET_DISMISS;
2366
2367 #ifdef JP
2368         sprintf(target_buf, "¥Ú¥Ã¥È¤Î¥¿¡¼¥²¥Ã¥È¤ò»ØÄê (¸½ºß¡§%s)",
2369                 (pet_t_m_idx ? (p_ptr->image ? "²¿¤«´ñ̯¤Êʪ" : (r_name + r_info[m_list[pet_t_m_idx].ap_r_idx].name)) : "»ØÄê¤Ê¤·"));
2370 #else
2371         sprintf(target_buf, "specify a target of pet (now:%s)",
2372                 (pet_t_m_idx ? (p_ptr->image ? "something strange" : (r_name + r_info[m_list[pet_t_m_idx].ap_r_idx].name)) : "nothing"));
2373 #endif
2374         power_desc[num] = target_buf;
2375
2376         powers[num++] = PET_TARGET;
2377
2378 #ifdef JP
2379         power_desc[num] = "¶á¤¯¤Ë¤¤¤í";
2380 #else
2381         power_desc[num] = "stay close";
2382 #endif
2383
2384         if (p_ptr->pet_follow_distance == PET_CLOSE_DIST) mode = num;
2385         powers[num++] = PET_STAY_CLOSE;
2386
2387 #ifdef JP
2388         power_desc[num] = "¤Ä¤¤¤ÆÍ褤";
2389 #else
2390         power_desc[num] = "follow me";
2391 #endif
2392
2393         if (p_ptr->pet_follow_distance == PET_FOLLOW_DIST) mode = num;
2394         powers[num++] = PET_FOLLOW_ME;
2395
2396 #ifdef JP
2397         power_desc[num] = "Ũ¤ò¸«¤Ä¤±¤ÆÅݤ»";
2398 #else
2399         power_desc[num] = "seek and destroy";
2400 #endif
2401
2402         if (p_ptr->pet_follow_distance == PET_DESTROY_DIST) mode = num;
2403         powers[num++] = PET_SEEK_AND_DESTROY;
2404
2405 #ifdef JP
2406         power_desc[num] = "¾¯¤·Î¥¤ì¤Æ¤¤¤í";
2407 #else
2408         power_desc[num] = "give me space";
2409 #endif
2410
2411         if (p_ptr->pet_follow_distance == PET_SPACE_DIST) mode = num;
2412         powers[num++] = PET_ALLOW_SPACE;
2413
2414 #ifdef JP
2415         power_desc[num] = "Î¥¤ì¤Æ¤¤¤í";
2416 #else
2417         power_desc[num] = "stay away";
2418 #endif
2419
2420         if (p_ptr->pet_follow_distance == PET_AWAY_DIST) mode = num;
2421         powers[num++] = PET_STAY_AWAY;
2422
2423         if (p_ptr->pet_extra_flags & PF_OPEN_DOORS)
2424         {
2425 #ifdef JP
2426                 power_desc[num] = "¥É¥¢¤ò³«¤±¤ë (¸½ºß:ON)";
2427 #else
2428                 power_desc[num] = "pets open doors (now On)";
2429 #endif
2430         }
2431         else
2432         {
2433 #ifdef JP
2434                 power_desc[num] = "¥É¥¢¤ò³«¤±¤ë (¸½ºß:OFF)";
2435 #else
2436                 power_desc[num] = "pets open doors (now Off)";
2437 #endif
2438         }
2439         powers[num++] = PET_OPEN_DOORS;
2440
2441         if (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)
2442         {
2443 #ifdef JP
2444                 power_desc[num] = "¥¢¥¤¥Æ¥à¤ò½¦¤¦ (¸½ºß:ON)";
2445 #else
2446                 power_desc[num] = "pets pick up items (now On)";
2447 #endif
2448         }
2449         else
2450         {
2451 #ifdef JP
2452                 power_desc[num] = "¥¢¥¤¥Æ¥à¤ò½¦¤¦ (¸½ºß:OFF)";
2453 #else
2454                 power_desc[num] = "pets pick up items (now Off)";
2455 #endif
2456         }
2457         powers[num++] = PET_TAKE_ITEMS;
2458
2459         if (p_ptr->pet_extra_flags & PF_TELEPORT)
2460         {
2461 #ifdef JP
2462                 power_desc[num] = "¥Æ¥ì¥Ý¡¼¥È·ÏËâË¡¤ò»È¤¦ (¸½ºß:ON)";
2463 #else
2464                 power_desc[num] = "allow teleport (now On)";
2465 #endif
2466         }
2467         else
2468         {
2469 #ifdef JP
2470                 power_desc[num] = "¥Æ¥ì¥Ý¡¼¥È·ÏËâË¡¤ò»È¤¦ (¸½ºß:OFF)";
2471 #else
2472                 power_desc[num] = "allow teleport (now Off)";
2473 #endif
2474         }
2475         powers[num++] = PET_TELEPORT;
2476
2477         if (p_ptr->pet_extra_flags & PF_ATTACK_SPELL)
2478         {
2479 #ifdef JP
2480                 power_desc[num] = "¹¶·âËâË¡¤ò»È¤¦ (¸½ºß:ON)";
2481 #else
2482                 power_desc[num] = "allow cast attack spell (now On)";
2483 #endif
2484         }
2485         else
2486         {
2487 #ifdef JP
2488                 power_desc[num] = "¹¶·âËâË¡¤ò»È¤¦ (¸½ºß:OFF)";
2489 #else
2490                 power_desc[num] = "allow cast attack spell (now Off)";
2491 #endif
2492         }
2493         powers[num++] = PET_ATTACK_SPELL;
2494
2495         if (p_ptr->pet_extra_flags & PF_SUMMON_SPELL)
2496         {
2497 #ifdef JP
2498                 power_desc[num] = "¾¤´­ËâË¡¤ò»È¤¦ (¸½ºß:ON)";
2499 #else
2500                 power_desc[num] = "allow cast summon spell (now On)";
2501 #endif
2502         }
2503         else
2504         {
2505 #ifdef JP
2506                 power_desc[num] = "¾¤´­ËâË¡¤ò»È¤¦ (¸½ºß:OFF)";
2507 #else
2508                 power_desc[num] = "allow cast summon spell (now Off)";
2509 #endif
2510         }
2511         powers[num++] = PET_SUMMON_SPELL;
2512
2513         if (p_ptr->pet_extra_flags & PF_BALL_SPELL)
2514         {
2515 #ifdef JP
2516                 power_desc[num] = "¥×¥ì¥¤¥ä¡¼¤ò´¬¤­¹þ¤àÈÏ°ÏËâË¡¤ò»È¤¦ (¸½ºß:ON)";
2517 #else
2518                 power_desc[num] = "allow involve player in area spell (now On)";
2519 #endif
2520         }
2521         else
2522         {
2523 #ifdef JP
2524                 power_desc[num] = "¥×¥ì¥¤¥ä¡¼¤ò´¬¤­¹þ¤àÈÏ°ÏËâË¡¤ò»È¤¦ (¸½ºß:OFF)";
2525 #else
2526                 power_desc[num] = "allow involve player in area spell (now Off)";
2527 #endif
2528         }
2529         powers[num++] = PET_BALL_SPELL;
2530
2531         if (p_ptr->riding)
2532         {
2533 #ifdef JP
2534                 power_desc[num] = "¥Ú¥Ã¥È¤«¤é¹ß¤ê¤ë";
2535 #else
2536                 power_desc[num] = "get off a pet";
2537 #endif
2538         }
2539         else
2540         {
2541 #ifdef JP
2542                 power_desc[num] = "¥Ú¥Ã¥È¤Ë¾è¤ë";
2543 #else
2544                 power_desc[num] = "ride a pet";
2545 #endif
2546         }
2547         powers[num++] = PET_RIDING;
2548
2549 #ifdef JP
2550         power_desc[num] = "¥Ú¥Ã¥È¤Ë̾Á°¤ò¤Ä¤±¤ë";
2551 #else
2552         power_desc[num] = "name pets";
2553 #endif
2554
2555         powers[num++] = PET_NAME;
2556
2557         if (p_ptr->riding)
2558         {
2559                 if ((p_ptr->migite && (empty_hands(FALSE) == EMPTY_HAND_LARM) &&
2560                      object_allow_two_hands_wielding(&inventory[INVEN_RARM])) ||
2561                     (p_ptr->hidarite && (empty_hands(FALSE) == EMPTY_HAND_RARM) &&
2562                          object_allow_two_hands_wielding(&inventory[INVEN_LARM])))
2563                 {
2564                         if (p_ptr->pet_extra_flags & PF_RYOUTE)
2565                         {
2566 #ifdef JP
2567                                 power_desc[num] = "Éð´ï¤òÊÒ¼ê¤Ç»ý¤Ä";
2568 #else
2569                                 power_desc[num] = "use one hand to control a riding pet";
2570 #endif
2571                         }
2572                         else
2573                         {
2574 #ifdef JP
2575                                 power_desc[num] = "Éð´ï¤òξ¼ê¤Ç»ý¤Ä";
2576 #else
2577                                 power_desc[num] = "use both hands for a weapon";
2578 #endif
2579                         }
2580
2581                         powers[num++] = PET_RYOUTE;
2582                 }
2583                 else
2584                 {
2585                         switch (p_ptr->pclass)
2586                         {
2587                         case CLASS_MONK:
2588                         case CLASS_FORCETRAINER:
2589                         case CLASS_BERSERKER:
2590                                 if (empty_hands(FALSE) == (EMPTY_HAND_RARM | EMPTY_HAND_LARM))
2591                                 {
2592                                         if (p_ptr->pet_extra_flags & PF_RYOUTE)
2593                                         {
2594 #ifdef JP
2595                                                 power_desc[num] = "ÊÒ¼ê¤Ç³ÊÆ®¤¹¤ë";
2596 #else
2597                                                 power_desc[num] = "use one hand to control a riding pet";
2598 #endif
2599                                         }
2600                                         else
2601                                         {
2602 #ifdef JP
2603                                                 power_desc[num] = "ξ¼ê¤Ç³ÊÆ®¤¹¤ë";
2604 #else
2605                                                 power_desc[num] = "use both hands for melee";
2606 #endif
2607                                         }
2608
2609                                         powers[num++] = PET_RYOUTE;
2610                                 }
2611                                 else if ((empty_hands(FALSE) != EMPTY_HAND_NONE) && !buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM))
2612                                 {
2613                                         if (p_ptr->pet_extra_flags & PF_RYOUTE)
2614                                         {
2615 #ifdef JP
2616                                                 power_desc[num] = "³ÊÆ®¤ò¹Ô¤ï¤Ê¤¤";
2617 #else
2618                                                 power_desc[num] = "use one hand to control a riding pet";
2619 #endif
2620                                         }
2621                                         else
2622                                         {
2623 #ifdef JP
2624                                                 power_desc[num] = "³ÊÆ®¤ò¹Ô¤¦";
2625 #else
2626                                                 power_desc[num] = "use one hand for melee";
2627 #endif
2628                                         }
2629
2630                                         powers[num++] = PET_RYOUTE;
2631                                 }
2632                                 break;
2633                         }
2634                 }
2635         }
2636
2637 #ifdef ALLOW_REPEAT
2638         if (!(repeat_pull(&i) && (i >= 0) && (i < num)))
2639         {
2640 #endif /* ALLOW_REPEAT */
2641
2642         /* Nothing chosen yet */
2643         flag = FALSE;
2644
2645         /* No redraw yet */
2646         redraw = FALSE;
2647
2648         if (use_menu)
2649         {
2650                 /* Save the screen */
2651                 screen_save();
2652
2653                 /* Build a prompt */
2654 #ifdef JP
2655                 strnfmt(out_val, 78, "(¥³¥Þ¥ó¥É¡¢ESC=½ªÎ») ¥³¥Þ¥ó¥É¤òÁª¤ó¤Ç¤¯¤À¤µ¤¤:");
2656 #else
2657                 strnfmt(out_val, 78, "(Command, ESC=exit) Choose command from menu.");
2658 #endif
2659         }
2660         else
2661         {
2662                 /* Build a prompt */
2663                 strnfmt(out_val, 78,
2664 #ifdef JP
2665                         "(¥³¥Þ¥ó¥É %c-%c¡¢'*'=°ìÍ÷¡¢ESC=½ªÎ») ¥³¥Þ¥ó¥É¤òÁª¤ó¤Ç¤¯¤À¤µ¤¤:",
2666 #else
2667                         "(Command %c-%c, *=List, ESC=exit) Select a command: ",
2668 #endif
2669                         I2A(0), I2A(num - 1));
2670         }
2671
2672         choice = (always_show_list || use_menu) ? ESCAPE : 1;
2673
2674         /* Get a command from the user */
2675         while (!flag)
2676         {
2677                 int ask = TRUE;
2678
2679                 if (choice == ESCAPE) choice = ' ';
2680                 else if (!get_com(out_val, &choice, TRUE)) break;
2681
2682                 if (use_menu && (choice != ' '))
2683                 {
2684                         switch (choice)
2685                         {
2686                         case '0':
2687                                 screen_load();
2688                                 return;
2689
2690                         case '8':
2691                         case 'k':
2692                         case 'K':
2693                                 menu_line += (num - 1);
2694                                 break;
2695
2696                         case '2':
2697                         case 'j':
2698                         case 'J':
2699                                 menu_line++;
2700                                 break;
2701
2702                         case '4':
2703                         case 'h':
2704                         case 'H':
2705                                 menu_line = 1;
2706                                 break;
2707
2708                         case '6':
2709                         case 'l':
2710                         case 'L':
2711                                 menu_line = num;
2712                                 break;
2713
2714                         case 'x':
2715                         case 'X':
2716                         case '\r':
2717                         case '\n':
2718                                 i = menu_line - 1;
2719                                 ask = FALSE;
2720                                 break;
2721                         }
2722                         if (menu_line > num) menu_line -= num;
2723                 }
2724
2725                 /* Request redraw */
2726                 if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
2727                 {
2728                         /* Show the list */
2729                         if (!redraw || use_menu)
2730                         {
2731                                 byte y = 1, x = 0;
2732                                 int ctr = 0;
2733
2734                                 /* Show list */
2735                                 redraw = TRUE;
2736
2737                                 /* Save the screen */
2738                                 if (!use_menu) screen_save();
2739
2740                                 prt("", y++, x);
2741
2742                                 /* Print list */
2743                                 for (ctr = 0; ctr < num; ctr++)
2744                                 {
2745                                         /* Letter/number for power selection */
2746 #ifdef JP
2747                                         if (use_menu) sprintf(buf, "%c%s ", (ctr == mode) ? '*' : ' ', (ctr == (menu_line - 1)) ? "¡Õ" : "  ");
2748 #else
2749                                         if (use_menu) sprintf(buf, "%c%s ", (ctr == mode) ? '*' : ' ', (ctr == (menu_line - 1)) ? "> " : "  ");
2750 #endif
2751                                         else sprintf(buf, "%c%c) ", (ctr == mode) ? '*' : ' ', I2A(ctr));
2752
2753                                         strcat(buf, power_desc[ctr]);
2754
2755                                         prt(buf, y + ctr, x);
2756                                 }
2757
2758                                 prt("", y + MIN(ctr, 17), x);
2759                         }
2760
2761                         /* Hide the list */
2762                         else
2763                         {
2764                                 /* Hide list */
2765                                 redraw = FALSE;
2766
2767                                 /* Restore the screen */
2768                                 screen_load();
2769                         }
2770
2771                         /* Redo asking */
2772                         continue;
2773                 }
2774
2775                 if (!use_menu)
2776                 {
2777                         /* Note verify */
2778                         ask = (isupper(choice));
2779
2780                         /* Lowercase */
2781                         if (ask) choice = tolower(choice);
2782
2783                         /* Extract request */
2784                         i = (islower(choice) ? A2I(choice) : -1);
2785                 }
2786
2787                 /* Totally Illegal */
2788                 if ((i < 0) || (i >= num))
2789                 {
2790                         bell();
2791                         continue;
2792                 }
2793
2794                 /* Verify it */
2795                 if (ask)
2796                 {
2797                         /* Prompt */
2798 #ifdef JP
2799                         strnfmt(buf, 78, "%s¤ò»È¤¤¤Þ¤¹¤«¡© ", power_desc[i]);
2800 #else
2801                         strnfmt(buf, 78, "Use %s? ", power_desc[i]);
2802 #endif
2803
2804                         /* Belay that order */
2805                         if (!get_check(buf)) continue;
2806                 }
2807
2808                 /* Stop the loop */
2809                 flag = TRUE;
2810         }
2811
2812         /* Restore the screen */
2813         if (redraw) screen_load();
2814
2815         /* Abort if needed */
2816         if (!flag)
2817         {
2818                 energy_use = 0;
2819                 return;
2820         }
2821
2822 #ifdef ALLOW_REPEAT
2823         repeat_push(i);
2824         }
2825 #endif /* ALLOW_REPEAT */
2826
2827         switch (powers[i])
2828         {
2829                 case PET_DISMISS: /* Dismiss pets */
2830                 {
2831                         /* Check pets (backwards) */
2832                         for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
2833                         {
2834                                 /* Player has pet */
2835                                 if (is_pet(&m_list[pet_ctr])) break;
2836                         }
2837
2838                         if (!pet_ctr)
2839                         {
2840 #ifdef JP
2841                                 msg_print("¥Ú¥Ã¥È¤¬¤¤¤Ê¤¤¡ª");
2842 #else
2843                                 msg_print("You have no pets!");
2844 #endif
2845                                 break;
2846                         }
2847                         do_cmd_pet_dismiss();
2848                         (void)calculate_upkeep();
2849                         break;
2850                 }
2851                 case PET_TARGET:
2852                 {
2853                         project_length = -1;
2854                         if (!target_set(TARGET_KILL)) pet_t_m_idx = 0;
2855                         else
2856                         {
2857                                 cave_type *c_ptr = &cave[target_row][target_col];
2858                                 if (c_ptr->m_idx && (m_list[c_ptr->m_idx].ml))
2859                                 {
2860                                         pet_t_m_idx = cave[target_row][target_col].m_idx;
2861                                         p_ptr->pet_follow_distance = PET_DESTROY_DIST;
2862                                 }
2863                                 else pet_t_m_idx = 0;
2864                         }
2865                         project_length = 0;
2866
2867                         break;
2868                 }
2869                 /* Call pets */
2870                 case PET_STAY_CLOSE:
2871                 {
2872                         p_ptr->pet_follow_distance = PET_CLOSE_DIST;
2873                         pet_t_m_idx = 0;
2874                         break;
2875                 }
2876                 /* "Follow Me" */
2877                 case PET_FOLLOW_ME:
2878                 {
2879                         p_ptr->pet_follow_distance = PET_FOLLOW_DIST;
2880                         pet_t_m_idx = 0;
2881                         break;
2882                 }
2883                 /* "Seek and destoy" */
2884                 case PET_SEEK_AND_DESTROY:
2885                 {
2886                         p_ptr->pet_follow_distance = PET_DESTROY_DIST;
2887                         break;
2888                 }
2889                 /* "Give me space" */
2890                 case PET_ALLOW_SPACE:
2891                 {
2892                         p_ptr->pet_follow_distance = PET_SPACE_DIST;
2893                         break;
2894                 }
2895                 /* "Stay away" */
2896                 case PET_STAY_AWAY:
2897                 {
2898                         p_ptr->pet_follow_distance = PET_AWAY_DIST;
2899                         break;
2900                 }
2901                 /* flag - allow pets to open doors */
2902                 case PET_OPEN_DOORS:
2903                 {
2904                         if (p_ptr->pet_extra_flags & PF_OPEN_DOORS) p_ptr->pet_extra_flags &= ~(PF_OPEN_DOORS);
2905                         else p_ptr->pet_extra_flags |= (PF_OPEN_DOORS);
2906                         break;
2907                 }
2908                 /* flag - allow pets to pickup items */
2909                 case PET_TAKE_ITEMS:
2910                 {
2911                         if (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)
2912                         {
2913                                 p_ptr->pet_extra_flags &= ~(PF_PICKUP_ITEMS);
2914                                 for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
2915                                 {
2916                                         /* Access the monster */
2917                                         m_ptr = &m_list[pet_ctr];
2918
2919                                         if (is_pet(m_ptr))
2920                                         {
2921                                                 monster_drop_carried_objects(m_ptr);
2922                                         }
2923                                 }
2924                         }
2925                         else p_ptr->pet_extra_flags |= (PF_PICKUP_ITEMS);
2926
2927                         break;
2928                 }
2929                 /* flag - allow pets to teleport */
2930                 case PET_TELEPORT:
2931                 {
2932                         if (p_ptr->pet_extra_flags & PF_TELEPORT) p_ptr->pet_extra_flags &= ~(PF_TELEPORT);
2933                         else p_ptr->pet_extra_flags |= (PF_TELEPORT);
2934                         break;
2935                 }
2936                 /* flag - allow pets to cast attack spell */
2937                 case PET_ATTACK_SPELL:
2938                 {
2939                         if (p_ptr->pet_extra_flags & PF_ATTACK_SPELL) p_ptr->pet_extra_flags &= ~(PF_ATTACK_SPELL);
2940                         else p_ptr->pet_extra_flags |= (PF_ATTACK_SPELL);
2941                         break;
2942                 }
2943                 /* flag - allow pets to cast attack spell */
2944                 case PET_SUMMON_SPELL:
2945                 {
2946                         if (p_ptr->pet_extra_flags & PF_SUMMON_SPELL) p_ptr->pet_extra_flags &= ~(PF_SUMMON_SPELL);
2947                         else p_ptr->pet_extra_flags |= (PF_SUMMON_SPELL);
2948                         break;
2949                 }
2950                 /* flag - allow pets to cast attack spell */
2951                 case PET_BALL_SPELL:
2952                 {
2953                         if (p_ptr->pet_extra_flags & PF_BALL_SPELL) p_ptr->pet_extra_flags &= ~(PF_BALL_SPELL);
2954                         else p_ptr->pet_extra_flags |= (PF_BALL_SPELL);
2955                         break;
2956                 }
2957
2958                 case PET_RIDING:
2959                 {
2960                         (void)do_riding(FALSE);
2961                         break;
2962                 }
2963
2964                 case PET_NAME:
2965                 {
2966                         do_name_pet();
2967                         break;
2968                 }
2969
2970                 case PET_RYOUTE:
2971                 {
2972                         if (p_ptr->pet_extra_flags & PF_RYOUTE) p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
2973                         else p_ptr->pet_extra_flags |= (PF_RYOUTE);
2974                         p_ptr->update |= (PU_BONUS);
2975                         handle_stuff();
2976                         break;
2977                 }
2978         }
2979 }