OSDN Git Service

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