OSDN Git Service

./bootstrap 実行時に warning が出ないよう修正。
[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         /* Hex */
1149         if (p_ptr->realm1 == REALM_HEX)
1150         {
1151                 if (hex_spell_fully())
1152                 {
1153                         bool flag = FALSE;
1154 #ifdef JP
1155                         msg_print("¤³¤ì°Ê¾å¿·¤·¤¤¼öʸ¤ò±Ó¾§¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£");
1156 #else
1157                         msg_print("Can not spell new spells more.");
1158 #endif
1159                         flush();
1160                         if (p_ptr->lev >= 35) flag = stop_hex_spell();
1161                         if (!flag) return;
1162                 }
1163         }
1164
1165         if (p_ptr->pclass == CLASS_FORCETRAINER)
1166         {
1167                 if (player_has_no_spellbooks())
1168                 {
1169                         confirm_use_force(FALSE);
1170                         return;
1171                 }
1172                 select_the_force = TRUE;
1173         }
1174
1175         prayer = spell_category_name(mp_ptr->spell_book);
1176
1177         /* Restrict choices to spell books */
1178         item_tester_tval = mp_ptr->spell_book;
1179
1180         /* Get an item */
1181 #ifdef JP
1182         q = "¤É¤Î¼öʸ½ñ¤ò»È¤¤¤Þ¤¹¤«? ";
1183 #else
1184         q = "Use which book? ";
1185 #endif
1186
1187 #ifdef JP
1188         s = "¼öʸ½ñ¤¬¤Ê¤¤¡ª";
1189 #else
1190         s = "You have no spell books!";
1191 #endif
1192
1193         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
1194         {
1195                 select_the_force = FALSE;
1196                 return;
1197         }
1198         select_the_force = FALSE;
1199
1200         if (item == INVEN_FORCE) /* the_force */
1201         {
1202                 do_cmd_mind();
1203                 return;
1204         }
1205
1206         /* Get the item (in the pack) */
1207         else if (item >= 0)
1208         {
1209                 o_ptr = &inventory[item];
1210         }
1211
1212         /* Get the item (on the floor) */
1213         else
1214         {
1215                 o_ptr = &o_list[0 - item];
1216         }
1217
1218         /* Access the item's sval */
1219         sval = o_ptr->sval;
1220
1221         if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1222
1223
1224         /* Track the object kind */
1225         object_kind_track(o_ptr->k_idx);
1226
1227         /* Hack -- Handle stuff */
1228         handle_stuff();
1229
1230         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1231                 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1232         else if (increment) realm = p_ptr->realm2;
1233         else realm = p_ptr->realm1;
1234
1235         /* Ask for a spell */
1236 #ifdef JP
1237         if (!get_spell(&spell,  
1238                                 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "±Ó¾§¤¹¤ë" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "²Î¤¦" : "¾§¤¨¤ë"), 
1239                        sval, TRUE, realm))
1240         {
1241                 if (spell == -2) msg_format("¤½¤ÎËܤˤÏÃΤäƤ¤¤ë%s¤¬¤Ê¤¤¡£", prayer);
1242                 return;
1243         }
1244 #else
1245         if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1246                 sval, TRUE, realm))
1247         {
1248                 if (spell == -2)
1249                         msg_format("You don't know any %ss in that book.", prayer);
1250                 return;
1251         }
1252 #endif
1253
1254
1255         use_realm = tval2realm(o_ptr->tval);
1256
1257         /* Hex */
1258         if (use_realm == REALM_HEX)
1259         {
1260                 if (hex_spelling(spell))
1261                 {
1262 #ifdef JP
1263                         msg_print("¤½¤Î¼öʸ¤Ï¤¹¤Ç¤Ë±Ó¾§Ãæ¤À¡£");
1264 #else
1265                         msg_print("You are already casting it.");
1266 #endif
1267                         return;
1268                 }
1269         }
1270
1271         if (!is_magic(use_realm))
1272         {
1273                 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1274         }
1275         else
1276         {
1277                 s_ptr = &mp_ptr->info[realm - 1][spell];
1278         }
1279
1280         /* Extract mana consumption rate */
1281         need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1282
1283         /* Verify "dangerous" spells */
1284         if (need_mana > p_ptr->csp)
1285         {
1286                 if (flush_failure) flush();
1287
1288                 /* Warning */
1289 #ifdef JP
1290 msg_format("¤½¤Î%s¤ò%s¤Î¤Ë½½Ê¬¤Ê¥Þ¥¸¥Ã¥¯¥Ý¥¤¥ó¥È¤¬¤Ê¤¤¡£",prayer,
1291  ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "±Ó¾§¤¹¤ë" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "²Î¤¦" : "¾§¤¨¤ë"));
1292 #else
1293                 msg_format("You do not have enough mana to %s this %s.",
1294                         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1295                         prayer);
1296 #endif
1297
1298
1299                 if (!over_exert) return;
1300
1301                 /* Verify */
1302 #ifdef JP
1303                 if (!get_check_strict("¤½¤ì¤Ç¤âÄ©À路¤Þ¤¹¤«? ", CHECK_OKAY_CANCEL)) return;
1304 #else
1305                 if (!get_check_strict("Attempt it anyway? ", CHECK_OKAY_CANCEL)) return;
1306 #endif
1307
1308         }
1309
1310
1311         /* Spell failure chance */
1312         chance = spell_chance(spell, use_realm);
1313
1314         /* Failed spell */
1315         if (randint0(100) < chance)
1316         {
1317                 if (flush_failure) flush();
1318
1319 #ifdef JP
1320 msg_format("%s¤ò¤¦¤Þ¤¯¾§¤¨¤é¤ì¤Ê¤«¤Ã¤¿¡ª", prayer);
1321 #else
1322                 msg_format("You failed to get the %s off!", prayer);
1323 #endif
1324
1325                 sound(SOUND_FAIL);
1326
1327                 switch (realm)
1328                 {
1329                 case REALM_LIFE:
1330                         if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1331                         break;
1332                 case REALM_DEATH:
1333                         if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1334                         break;
1335                 case REALM_NATURE:
1336                         if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1337                         break;
1338                 case REALM_DAEMON:
1339                         if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1340                         break;
1341                 case REALM_CRUSADE:
1342                         if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1343                         break;
1344                 case REALM_HEX:
1345                         if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1346                         break;
1347                 default:
1348                         if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1349                         break;
1350                 }
1351
1352                 /* Failure casting may activate some side effect */
1353                 do_spell(realm, spell, SPELL_FAIL);
1354
1355
1356                 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1357                 {
1358 #ifdef JP
1359 msg_print("¥«¥ª¥¹Åª¤Ê¸ú²Ì¤òȯÀ¸¤·¤¿¡ª");
1360 #else
1361                         msg_print("You produce a chaotic effect!");
1362 #endif
1363
1364                         wild_magic(spell);
1365                 }
1366                 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1367                 {
1368                         if ((sval == 3) && one_in_(2))
1369                         {
1370                                 sanity_blast(0, TRUE);
1371                         }
1372                         else
1373                         {
1374 #ifdef JP
1375                                 msg_print("Äˤ¤¡ª");
1376 #else
1377                                 msg_print("It hurts!");
1378 #endif
1379
1380 #ifdef JP
1381                                 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), "°Å¹õËâË¡¤ÎµÕή", -1);
1382 #else
1383                                 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), "a miscast Death spell", -1);
1384 #endif
1385
1386                                 if ((spell > 15) && one_in_(6) && !p_ptr->hold_life)
1387                                         lose_exp(spell * 250);
1388                         }
1389                 }
1390                 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1391                 {
1392 #ifdef JP
1393 msg_print("¤¤¤ä¤Ê²»¤¬¶Á¤¤¤¿");
1394 #else
1395 msg_print("An infernal sound echoed.");
1396 #endif
1397
1398                         aggravate_monsters(0);
1399                 }
1400                 if (randint1(100) >= chance)
1401                         chg_virtue(V_CHANCE,-1);
1402         }
1403
1404         /* Process spell */
1405         else
1406         {
1407                 /* Canceled spells cost neither a turn nor mana */
1408                 if (!do_spell(realm, spell, SPELL_CAST)) return;
1409
1410                 if (randint1(100) < chance)
1411                         chg_virtue(V_CHANCE,1);
1412
1413                 /* A spell was cast */
1414                 if (!(increment ?
1415                     (p_ptr->spell_worked2 & (1L << spell)) :
1416                     (p_ptr->spell_worked1 & (1L << spell)))
1417                     && (p_ptr->pclass != CLASS_SORCERER)
1418                     && (p_ptr->pclass != CLASS_RED_MAGE))
1419                 {
1420                         int e = s_ptr->sexp;
1421
1422                         /* The spell worked */
1423                         if (realm == p_ptr->realm1)
1424                         {
1425                                 p_ptr->spell_worked1 |= (1L << spell);
1426                         }
1427                         else
1428                         {
1429                                 p_ptr->spell_worked2 |= (1L << spell);
1430                         }
1431
1432                         /* Gain experience */
1433                         gain_exp(e * s_ptr->slevel);
1434
1435                         /* Redraw object recall */
1436                         p_ptr->window |= (PW_OBJECT);
1437
1438                         switch (realm)
1439                         {
1440                         case REALM_LIFE:
1441                                 chg_virtue(V_TEMPERANCE, 1);
1442                                 chg_virtue(V_COMPASSION, 1);
1443                                 chg_virtue(V_VITALITY, 1);
1444                                 chg_virtue(V_DILIGENCE, 1);
1445                                 break;
1446                         case REALM_DEATH:
1447                                 chg_virtue(V_UNLIFE, 1);
1448                                 chg_virtue(V_JUSTICE, -1);
1449                                 chg_virtue(V_FAITH, -1);
1450                                 chg_virtue(V_VITALITY, -1);
1451                                 break;
1452                         case REALM_DAEMON:
1453                                 chg_virtue(V_JUSTICE, -1);
1454                                 chg_virtue(V_FAITH, -1);
1455                                 chg_virtue(V_HONOUR, -1);
1456                                 chg_virtue(V_TEMPERANCE, -1);
1457                                 break;
1458                         case REALM_CRUSADE:
1459                                 chg_virtue(V_FAITH, 1);
1460                                 chg_virtue(V_JUSTICE, 1);
1461                                 chg_virtue(V_SACRIFICE, 1);
1462                                 chg_virtue(V_HONOUR, 1);
1463                                 break;
1464                         case REALM_NATURE:
1465                                 chg_virtue(V_NATURE, 1);
1466                                 chg_virtue(V_HARMONY, 1);
1467                                 break;
1468                         case REALM_HEX:
1469                                 chg_virtue(V_JUSTICE, -1);
1470                                 chg_virtue(V_FAITH, -1);
1471                                 chg_virtue(V_HONOUR, -1);
1472                                 chg_virtue(V_COMPASSION, -1);
1473                                 break;
1474                         default:
1475                                 chg_virtue(V_KNOWLEDGE, 1);
1476                                 break;
1477                         }
1478                 }
1479                 switch (realm)
1480                 {
1481                 case REALM_LIFE:
1482                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1483                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1484                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1485                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1486                         break;
1487                 case REALM_DEATH:
1488                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1489                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1490                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1491                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1492                         break;
1493                 case REALM_DAEMON:
1494                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1495                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1496                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1497                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1498                         break;
1499                 case REALM_CRUSADE:
1500                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1501                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1502                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1503                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1504                         break;
1505                 case REALM_NATURE:
1506                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1507                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1508                         break;
1509                 case REALM_HEX:
1510                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1511                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1512                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1513                         if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1514                         break;
1515                 }
1516                 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1517                 {
1518                         s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0)+spell];
1519                         s16b exp_gain = 0;
1520
1521                         if (cur_exp < SPELL_EXP_BEGINNER)
1522                                 exp_gain += 60;
1523                         else if (cur_exp < SPELL_EXP_SKILLED)
1524                         {
1525                                 if ((dun_level > 4) && ((dun_level + 10) > p_ptr->lev))
1526                                         exp_gain = 8;
1527                         }
1528                         else if (cur_exp < SPELL_EXP_EXPERT)
1529                         {
1530                                 if (((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel))
1531                                         exp_gain = 2;
1532                         }
1533                         else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1534                         {
1535                                 if (((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel))
1536                                         exp_gain = 1;
1537                         }
1538                         p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1539                 }
1540         }
1541
1542         /* Take a turn */
1543         energy_use = 100;
1544
1545         /* Sufficient mana */
1546         if (need_mana <= p_ptr->csp)
1547         {
1548                 /* Use some mana */
1549                 p_ptr->csp -= need_mana;
1550         }
1551
1552         /* Over-exert the player */
1553         else
1554         {
1555                 int oops = need_mana;
1556
1557                 /* No mana left */
1558                 p_ptr->csp = 0;
1559                 p_ptr->csp_frac = 0;
1560
1561                 /* Message */
1562 #ifdef JP
1563 msg_print("Àº¿À¤ò½¸Ã椷¤¹¤®¤Æµ¤¤ò¼º¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
1564 #else
1565                 msg_print("You faint from the effort!");
1566 #endif
1567
1568
1569                 /* Hack -- Bypass free action */
1570                 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1571
1572                 switch (realm)
1573                 {
1574                 case REALM_LIFE:
1575                         chg_virtue(V_VITALITY, -10);
1576                         break;
1577                 case REALM_DEATH:
1578                         chg_virtue(V_UNLIFE, -10);
1579                         break;
1580                 case REALM_DAEMON:
1581                         chg_virtue(V_JUSTICE, 10);
1582                         break;
1583                 case REALM_NATURE:
1584                         chg_virtue(V_NATURE, -10);
1585                         break;
1586                 case REALM_CRUSADE:
1587                         chg_virtue(V_JUSTICE, -10);
1588                         break;
1589                 case REALM_HEX:
1590                         chg_virtue(V_COMPASSION, 10);
1591                         break;
1592                 default:
1593                         chg_virtue(V_KNOWLEDGE, -10);
1594                         break;
1595                 }
1596
1597                 /* Damage CON (possibly permanently) */
1598                 if (randint0(100) < 50)
1599                 {
1600                         bool perm = (randint0(100) < 25);
1601
1602                         /* Message */
1603 #ifdef JP
1604 msg_print("ÂΤò°­¤¯¤·¤Æ¤·¤Þ¤Ã¤¿¡ª");
1605 #else
1606                         msg_print("You have damaged your health!");
1607 #endif
1608
1609
1610                         /* Reduce constitution */
1611                         (void)dec_stat(A_CON, 15 + randint1(10), perm);
1612                 }
1613         }
1614
1615         /* Redraw mana */
1616         p_ptr->redraw |= (PR_MANA);
1617
1618         /* Window stuff */
1619         p_ptr->window |= (PW_PLAYER);
1620         p_ptr->window |= (PW_SPELL);
1621 }
1622
1623
1624 static bool ang_sort_comp_pet_dismiss(vptr u, vptr v, int a, int b)
1625 {
1626         u16b *who = (u16b*)(u);
1627
1628         int w1 = who[a];
1629         int w2 = who[b];
1630
1631         monster_type *m_ptr1 = &m_list[w1];
1632         monster_type *m_ptr2 = &m_list[w2];
1633         monster_race *r_ptr1 = &r_info[m_ptr1->r_idx];
1634         monster_race *r_ptr2 = &r_info[m_ptr2->r_idx];
1635
1636         /* Unused */
1637         (void)v;
1638
1639         if (w1 == p_ptr->riding) return TRUE;
1640         if (w2 == p_ptr->riding) return FALSE;
1641
1642         if (m_ptr1->nickname && !m_ptr2->nickname) return TRUE;
1643         if (m_ptr2->nickname && !m_ptr1->nickname) return FALSE;
1644
1645         if (!m_ptr1->parent_m_idx && m_ptr2->parent_m_idx) return TRUE;
1646         if (!m_ptr2->parent_m_idx && m_ptr1->parent_m_idx) return FALSE;
1647
1648         if ((r_ptr1->flags1 & RF1_UNIQUE) && !(r_ptr2->flags1 & RF1_UNIQUE)) return TRUE;
1649         if ((r_ptr2->flags1 & RF1_UNIQUE) && !(r_ptr1->flags1 & RF1_UNIQUE)) return FALSE;
1650
1651         if (r_ptr1->level > r_ptr2->level) return TRUE;
1652         if (r_ptr2->level > r_ptr1->level) return FALSE;
1653
1654         if (m_ptr1->hp > m_ptr2->hp) return TRUE;
1655         if (m_ptr2->hp > m_ptr1->hp) return FALSE;
1656         
1657         return w1 <= w2;
1658 }
1659
1660 void check_pets_num_and_align(monster_type *m_ptr, bool inc)
1661 {
1662         s32b old_friend_align = friend_align;
1663         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1664
1665         if (inc)
1666         {
1667                 total_friends++;
1668                 if (r_ptr->flags3 & RF3_GOOD) friend_align += r_ptr->level;
1669                 if (r_ptr->flags3 & RF3_EVIL) friend_align -= r_ptr->level;
1670         }
1671         else
1672         {
1673                 total_friends--;
1674                 if (r_ptr->flags3 & RF3_GOOD) friend_align -= r_ptr->level;
1675                 if (r_ptr->flags3 & RF3_EVIL) friend_align += r_ptr->level;
1676         }
1677
1678         if (old_friend_align != friend_align) p_ptr->update |= (PU_BONUS);
1679 }
1680
1681 int calculate_upkeep(void)
1682 {
1683         s32b old_friend_align = friend_align;
1684         int m_idx;
1685         bool have_a_unique = FALSE;
1686         s32b total_friend_levels = 0;
1687
1688         total_friends = 0;
1689         friend_align = 0;
1690
1691         for (m_idx = m_max - 1; m_idx >=1; m_idx--)
1692         {
1693                 monster_type *m_ptr;
1694                 monster_race *r_ptr;
1695                 
1696                 m_ptr = &m_list[m_idx];
1697                 if (!m_ptr->r_idx) continue;
1698                 r_ptr = &r_info[m_ptr->r_idx];
1699
1700                 if (is_pet(m_ptr))
1701                 {
1702                         total_friends++;
1703                         if (r_ptr->flags1 & RF1_UNIQUE)
1704                         {
1705                                 if (p_ptr->pclass == CLASS_CAVALRY)
1706                                 {
1707                                         if (p_ptr->riding == m_idx)
1708                                                 total_friend_levels += (r_ptr->level+5)*2;
1709                                         else if (!have_a_unique && (r_info[m_ptr->r_idx].flags7 & RF7_RIDING))
1710                                                 total_friend_levels += (r_ptr->level+5)*7/2;
1711                                         else
1712                                                 total_friend_levels += (r_ptr->level+5)*10;
1713                                         have_a_unique = TRUE;
1714                                 }
1715                                 else
1716                                         total_friend_levels += (r_ptr->level+5)*10;
1717                         }
1718                         else
1719                                 total_friend_levels += r_ptr->level;
1720
1721                         /* Determine pet alignment */
1722                         if (r_ptr->flags3 & RF3_GOOD) friend_align += r_ptr->level;
1723                         if (r_ptr->flags3 & RF3_EVIL) friend_align -= r_ptr->level;
1724                 }
1725         }
1726         if (old_friend_align != friend_align) p_ptr->update |= (PU_BONUS);
1727         if (total_friends)
1728         {
1729                 int upkeep_factor;
1730                 upkeep_factor = (total_friend_levels - (p_ptr->lev * 80 / (cp_ptr->pet_upkeep_div)));
1731                 if (upkeep_factor < 0) upkeep_factor = 0;
1732                 if (upkeep_factor > 1000) upkeep_factor = 1000;
1733                 return upkeep_factor;
1734         }
1735         else
1736                 return 0;
1737 }
1738
1739 void do_cmd_pet_dismiss(void)
1740 {
1741         monster_type    *m_ptr;
1742         bool            all_pets = FALSE;
1743         int pet_ctr, i;
1744         int Dismissed = 0;
1745
1746         u16b *who;
1747         u16b dummy_why;
1748         int max_pet = 0;
1749         int cu, cv;
1750
1751         cu = Term->scr->cu;
1752         cv = Term->scr->cv;
1753         Term->scr->cu = 0;
1754         Term->scr->cv = 1;
1755
1756         /* Allocate the "who" array */
1757         C_MAKE(who, max_m_idx, u16b);
1758
1759         /* Process the monsters (backwards) */
1760         for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
1761         {
1762                 if (is_pet(&m_list[pet_ctr]))
1763                         who[max_pet++] = pet_ctr;
1764         }
1765
1766         /* Select the sort method */
1767         ang_sort_comp = ang_sort_comp_pet_dismiss;
1768         ang_sort_swap = ang_sort_swap_hook;
1769
1770         ang_sort(who, &dummy_why, max_pet);
1771
1772         /* Process the monsters (backwards) */
1773         for (i = 0; i < max_pet; i++)
1774         {
1775                 bool delete_this;
1776                 char friend_name[80];
1777                 char buf[80];
1778                 bool kakunin;
1779
1780                 /* Access the monster */
1781                 pet_ctr = who[i];
1782                 m_ptr = &m_list[pet_ctr];
1783
1784                 delete_this = FALSE;
1785                 kakunin = ((pet_ctr == p_ptr->riding) || (m_ptr->nickname));
1786                 monster_desc(friend_name, m_ptr, MD_ASSUME_VISIBLE);
1787
1788                 if (!all_pets)
1789                 {
1790                         /* Hack -- health bar for this monster */
1791                         health_track(pet_ctr);
1792
1793                         /* Hack -- handle stuff */
1794                         handle_stuff();
1795
1796 #ifdef JP
1797                         sprintf(buf, "%s¤òÊü¤·¤Þ¤¹¤«¡© [Yes/No/Unnamed (%dÂÎ)]", friend_name, max_pet - i);
1798 #else
1799                         sprintf(buf, "Dismiss %s? [Yes/No/Unnamed (%d remain)]", friend_name, max_pet - i);
1800 #endif
1801                         prt(buf, 0, 0);
1802
1803                         if (m_ptr->ml)
1804                                 move_cursor_relative(m_ptr->fy, m_ptr->fx);
1805
1806                         while (TRUE)
1807                         {
1808                                 char ch = inkey();
1809
1810                                 if (ch == 'Y' || ch == 'y')
1811                                 {
1812                                         delete_this = TRUE;
1813
1814                                         if (kakunin)
1815                                         {
1816 #ifdef JP
1817                                                 sprintf(buf, "ËÜÅö¤Ë¤è¤í¤·¤¤¤Ç¤¹¤«¡© (%s) ", friend_name);
1818 #else
1819                                                 sprintf(buf, "Are you sure? (%s) ", friend_name);
1820 #endif
1821                                                 if (!get_check(buf))
1822                                                         delete_this = FALSE;
1823                                         }
1824                                         break;
1825                                 }
1826
1827                                 if (ch == 'U' || ch == 'u')
1828                                 {
1829                                         all_pets = TRUE;
1830                                         break;
1831                                 }
1832
1833                                 if (ch == ESCAPE || ch == 'N' || ch == 'n')
1834                                         break;
1835
1836                                 bell();
1837                         }
1838                 }
1839
1840                 if ((all_pets && !kakunin) || (!all_pets && delete_this))
1841                 {
1842                         if (record_named_pet && m_ptr->nickname)
1843                         {
1844                                 char m_name[80];
1845
1846                                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1847                                 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_DISMISS, m_name);
1848                         }
1849
1850                         if (pet_ctr == p_ptr->riding)
1851                         {
1852 #ifdef JP
1853                                 msg_format("%s¤«¤é¹ß¤ê¤¿¡£", friend_name);
1854 #else
1855                                 msg_format("You have got off %s. ", friend_name);
1856 #endif
1857
1858                                 p_ptr->riding = 0;
1859
1860                                 /* Update the monsters */
1861                                 p_ptr->update |= (PU_BONUS | PU_MONSTERS);
1862                                 p_ptr->redraw |= (PR_EXTRA | PR_UHEALTH);
1863                         }
1864
1865                         /* HACK : Add the line to message buffer */
1866 #ifdef JP
1867                         sprintf(buf, "%s ¤òÊü¤·¤¿¡£", friend_name);
1868 #else
1869                         sprintf(buf, "Dismissed %s.", friend_name);
1870 #endif
1871                         message_add(buf);
1872                         p_ptr->window |= (PW_MESSAGE);
1873                         window_stuff();
1874
1875                         delete_monster_idx(pet_ctr);
1876                         Dismissed++;
1877                 }
1878         }
1879
1880         Term->scr->cu = cu;
1881         Term->scr->cv = cv;
1882         Term_fresh();
1883
1884         C_KILL(who, max_m_idx, u16b);
1885
1886 #ifdef JP
1887         msg_format("%d ÂΤΥڥåȤòÊü¤·¤Þ¤·¤¿¡£", Dismissed);
1888 #else
1889         msg_format("You have dismissed %d pet%s.", Dismissed,
1890                    (Dismissed == 1 ? "" : "s"));
1891 #endif
1892         if (Dismissed == 0 && all_pets)
1893 #ifdef JP
1894                 msg_print("'U'nnamed ¤Ï¡¢¾èÇϰʳ°¤Î̾Á°¤Î¤Ê¤¤¥Ú¥Ã¥È¤À¤±¤òÁ´¤Æ²òÊü¤·¤Þ¤¹¡£");
1895 #else
1896                 msg_print("'U'nnamed means all your pets except named pets and your mount.");
1897 #endif
1898 }
1899
1900 static bool player_can_ride_aux(cave_type *c_ptr, bool now_riding)
1901 {
1902         bool p_can_enter;
1903         bool old_character_xtra = character_xtra;
1904         int  old_riding = p_ptr->riding;
1905         bool old_riding_ryoute = p_ptr->riding_ryoute;
1906         bool old_old_riding_ryoute = p_ptr->old_riding_ryoute;
1907         bool old_pf_ryoute = (p_ptr->pet_extra_flags & PF_RYOUTE) ? TRUE : FALSE;
1908
1909         /* Hack -- prevent "icky" message */
1910         character_xtra = TRUE;
1911
1912         if (now_riding) p_ptr->riding = c_ptr->m_idx;
1913         else
1914         {
1915                 p_ptr->riding = 0;
1916                 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
1917                 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
1918         }
1919
1920         calc_bonuses();
1921
1922         p_can_enter = player_can_enter(c_ptr->feat, CEM_P_CAN_ENTER_PATTERN);
1923
1924         p_ptr->riding = old_riding;
1925         if (old_pf_ryoute) p_ptr->pet_extra_flags |= (PF_RYOUTE);
1926         else p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
1927         p_ptr->riding_ryoute = old_riding_ryoute;
1928         p_ptr->old_riding_ryoute = old_old_riding_ryoute;
1929
1930         calc_bonuses();
1931
1932         character_xtra = old_character_xtra;
1933
1934         return p_can_enter;
1935 }
1936
1937 bool rakuba(int dam, bool force)
1938 {
1939         int i, y, x, oy, ox;
1940         int sn = 0, sy = 0, sx = 0;
1941         char m_name[80];
1942         monster_type *m_ptr = &m_list[p_ptr->riding];
1943         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1944         bool fall_dam = FALSE;
1945
1946         if (!p_ptr->riding) return FALSE;
1947         if (p_ptr->wild_mode) return FALSE;
1948
1949         if (dam >= 0 || force)
1950         {
1951                 if (!force)
1952                 {
1953                         int cur = p_ptr->skill_exp[GINOU_RIDING];
1954                         int max = s_info[p_ptr->pclass].s_max[GINOU_RIDING];
1955                         int ridinglevel = r_ptr->level;
1956
1957                         /* ÍîÇϤΤ·¤ä¤¹¤µ */
1958                         int rakubalevel = r_ptr->level;
1959                         if (p_ptr->riding_ryoute) rakubalevel += 20;
1960
1961                         if ((cur < max) && (max > 1000) &&
1962                             (dam / 2 + ridinglevel) > (cur / 30 + 10))
1963                         {
1964                                 int inc = 0;
1965
1966                                 if (ridinglevel > (cur / 100 + 15))
1967                                         inc += 1 + (ridinglevel - cur / 100 - 15);
1968                                 else
1969                                         inc += 1;
1970
1971                                 p_ptr->skill_exp[GINOU_RIDING] = MIN(max, cur + inc);
1972                         }
1973
1974                         /* ¥ì¥Ù¥ë¤ÎÄ㤤¾èÇϤ«¤é¤ÏÍîÇϤ·¤Ë¤¯¤¤ */
1975                         if (randint0(dam / 2 + rakubalevel * 2) < cur / 30 + 10)
1976                         {
1977                                 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))
1978                                 {
1979                                         return FALSE;
1980                                 }
1981                         }
1982                 }
1983
1984                 /* Check around the player */
1985                 for (i = 0; i < 8; i++)
1986                 {
1987                         cave_type *c_ptr;
1988
1989                         /* Access the location */
1990                         y = py + ddy_ddd[i];
1991                         x = px + ddx_ddd[i];
1992
1993                         c_ptr = &cave[y][x];
1994
1995                         if (c_ptr->m_idx) continue;
1996
1997                         /* Skip non-empty grids */
1998                         if (!cave_have_flag_grid(c_ptr, FF_MOVE) && !cave_have_flag_grid(c_ptr, FF_CAN_FLY))
1999                         {
2000                                 if (!player_can_ride_aux(c_ptr, FALSE)) continue;
2001                         }
2002
2003                         if (cave_have_flag_grid(c_ptr, FF_PATTERN)) continue;
2004
2005                         /* Count "safe" grids */
2006                         sn++;
2007
2008                         /* Randomize choice */
2009                         if (randint0(sn) > 0) continue;
2010
2011                         /* Save the safe location */
2012                         sy = y; sx = x;
2013                 }
2014                 if (!sn)
2015                 {
2016                         monster_desc(m_name, m_ptr, 0);
2017 #ifdef JP
2018 msg_format("%s¤«¤é¿¶¤êÍî¤È¤µ¤ì¤½¤¦¤Ë¤Ê¤Ã¤Æ¡¢Êɤˤ֤Ĥ«¤Ã¤¿¡£",m_name);
2019                         take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "Êɤؤξ×ÆÍ", -1);
2020 #else
2021                         msg_format("You have nearly fallen from %s, but bumped into wall.",m_name);
2022                         take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "bumping into wall", -1);
2023 #endif
2024                         return FALSE;
2025                 }
2026
2027                 oy = py;
2028                 ox = px;
2029
2030                 py = sy;
2031                 px = sx;
2032
2033                 /* Redraw the old spot */
2034                 lite_spot(oy, ox);
2035
2036                 /* Redraw the new spot */
2037                 lite_spot(py, px);
2038
2039                 /* Check for new panel */
2040                 verify_panel();
2041         }
2042
2043         p_ptr->riding = 0;
2044         p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
2045         p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
2046
2047         calc_bonuses();
2048
2049         p_ptr->update |= (PU_BONUS);
2050
2051         /* Update stuff */
2052         p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
2053
2054         /* Window stuff */
2055         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2056
2057         p_ptr->redraw |= (PR_EXTRA);
2058
2059         /* Update health track of mount */
2060         p_ptr->redraw |= (PR_UHEALTH);
2061
2062         if (p_ptr->levitation && !force)
2063         {
2064                 monster_desc(m_name, m_ptr, 0);
2065 #ifdef JP
2066                 msg_format("%s¤«¤éÍî¤Á¤¿¤¬¡¢¶õÃæ¤Ç¤¦¤Þ¤¯ÂÎÀª¤òΩ¤Æľ¤·¤ÆÃåÃϤ·¤¿¡£",m_name);
2067 #else
2068                 msg_format("You are thrown from %s, but make a good landing.",m_name);
2069 #endif
2070         }
2071         else
2072         {
2073 #ifdef JP
2074                 take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "ÍîÇÏ", -1);
2075 #else
2076                 take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "Falling from riding", -1);
2077 #endif
2078                 fall_dam = TRUE;
2079         }
2080
2081         /* Move the player */
2082         if (sy && !p_ptr->is_dead)
2083                 (void)move_player_effect(py, px, MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);
2084
2085         return fall_dam;
2086 }
2087
2088 bool do_riding(bool force)
2089 {
2090         int x, y, dir = 0;
2091         cave_type *c_ptr;
2092         monster_type *m_ptr;
2093
2094         if (!get_rep_dir2(&dir)) return FALSE;
2095         y = py + ddy[dir];
2096         x = px + ddx[dir];
2097         c_ptr = &cave[y][x];
2098
2099         if (p_ptr->special_defense & KATA_MUSOU) set_action(ACTION_NONE);
2100
2101         if (p_ptr->riding)
2102         {
2103                 /* Skip non-empty grids */
2104                 if (!player_can_ride_aux(c_ptr, FALSE))
2105                 {
2106 #ifdef JP
2107                         msg_print("¤½¤Á¤é¤Ë¤Ï¹ß¤ê¤é¤ì¤Þ¤»¤ó¡£");
2108 #else
2109                         msg_print("You cannot go to that direction.");
2110 #endif
2111                         return FALSE;
2112                 }
2113
2114                 if (!pattern_seq(py, px, y, x)) return FALSE;
2115
2116                 if (c_ptr->m_idx)
2117                 {
2118                         /* Take a turn */
2119                         energy_use = 100;
2120
2121                         /* Message */
2122 #ifdef JP
2123                         msg_print("¥â¥ó¥¹¥¿¡¼¤¬Î©¤Á¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ë¡ª");
2124 #else
2125                         msg_print("There is a monster in the way!");
2126 #endif
2127
2128                         py_attack(y, x, 0);
2129                         return FALSE;
2130                 }
2131
2132                 p_ptr->riding = 0;
2133                 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
2134                 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
2135         }
2136         else
2137         {
2138                 if (p_ptr->confused)
2139                 {
2140 #ifdef JP
2141                         msg_print("º®Í𤷤Ƥ¤¤Æ¾è¤ì¤Ê¤¤¡ª");
2142 #else
2143                         msg_print("You are too confused!");
2144 #endif
2145                         return FALSE;
2146                 }
2147
2148                 m_ptr = &m_list[c_ptr->m_idx];
2149
2150                 if (!c_ptr->m_idx || !m_ptr->ml)
2151                 {
2152 #ifdef JP
2153                         msg_print("¤½¤Î¾ì½ê¤Ë¤Ï¥â¥ó¥¹¥¿¡¼¤Ï¤¤¤Þ¤»¤ó¡£");
2154 #else
2155                         msg_print("Here is no monster.");
2156 #endif
2157
2158                         return FALSE;
2159                 }
2160                 if (!is_pet(m_ptr) && !force)
2161                 {
2162 #ifdef JP
2163                         msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ï¥Ú¥Ã¥È¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£");
2164 #else
2165                         msg_print("That monster is not a pet.");
2166 #endif
2167
2168                         return FALSE;
2169                 }
2170                 if (!(r_info[m_ptr->r_idx].flags7 & RF7_RIDING))
2171                 {
2172 #ifdef JP
2173                         msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ë¤Ï¾è¤ì¤Ê¤µ¤½¤¦¤À¡£");
2174 #else
2175                         msg_print("This monster doesn't seem suitable for riding.");
2176 #endif
2177
2178                         return FALSE;
2179                 }
2180
2181                 if (!pattern_seq(py, px, y, x)) return FALSE;
2182
2183                 if (!player_can_ride_aux(c_ptr, TRUE))
2184                 {
2185                         /* Feature code (applying "mimic" field) */
2186                         feature_type *f_ptr = &f_info[get_feat_mimic(c_ptr)];
2187 #ifdef JP
2188                         msg_format("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ï%s¤Î%s¤Ë¤¤¤ë¡£", f_name + f_ptr->name,
2189                                    ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
2190                                     (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE))) ?
2191                                    "Ãæ" : "¾å");
2192 #else
2193                         msg_format("This monster is %s the %s.",
2194                                    ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
2195                                     (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE))) ?
2196                                    "in" : "on", f_name + f_ptr->name);
2197 #endif
2198
2199                         return FALSE;
2200                 }
2201                 if (r_info[m_ptr->r_idx].level > randint1((p_ptr->skill_exp[GINOU_RIDING] / 50 + p_ptr->lev / 2 + 20)))
2202                 {
2203 #ifdef JP
2204                         msg_print("¤¦¤Þ¤¯¾è¤ì¤Ê¤«¤Ã¤¿¡£");
2205 #else
2206                         msg_print("You failed to ride.");
2207 #endif
2208
2209                         energy_use = 100;
2210
2211                         return FALSE;
2212                 }
2213
2214                 if (MON_CSLEEP(m_ptr))
2215                 {
2216                         char m_name[80];
2217                         monster_desc(m_name, m_ptr, 0);
2218                         (void)set_monster_csleep(c_ptr->m_idx, 0);
2219 #ifdef JP
2220                         msg_format("%s¤òµ¯¤³¤·¤¿¡£", m_name);
2221 #else
2222                         msg_format("You have waked %s up.", m_name);
2223 #endif
2224                 }
2225
2226                 if (p_ptr->action == ACTION_KAMAE) set_action(ACTION_NONE);
2227
2228                 p_ptr->riding = c_ptr->m_idx;
2229
2230                 /* Hack -- remove tracked monster */
2231                 if (p_ptr->riding == p_ptr->health_who) health_track(0);
2232         }
2233
2234         energy_use = 100;
2235
2236         /* Mega-Hack -- Forget the view and lite */
2237         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
2238
2239         /* Update the monsters */
2240         p_ptr->update |= (PU_BONUS);
2241
2242         /* Redraw map */
2243         p_ptr->redraw |= (PR_MAP | PR_EXTRA);
2244
2245         p_ptr->redraw |= (PR_UHEALTH);
2246
2247         /* Move the player */
2248         (void)move_player_effect(y, x, MPE_HANDLE_STUFF | MPE_ENERGY_USE | MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);
2249
2250         return TRUE;
2251 }
2252
2253 static void do_name_pet(void)
2254 {
2255         monster_type *m_ptr;
2256         char out_val[20];
2257         char m_name[80];
2258         bool old_name = FALSE;
2259         bool old_target_pet = target_pet;
2260
2261         target_pet = TRUE;
2262         if (!target_set(TARGET_KILL))
2263         {
2264                 target_pet = old_target_pet;
2265                 return;
2266         }
2267         target_pet = old_target_pet;
2268
2269         if (cave[target_row][target_col].m_idx)
2270         {
2271                 m_ptr = &m_list[cave[target_row][target_col].m_idx];
2272
2273                 if (!is_pet(m_ptr))
2274                 {
2275                         /* Message */
2276 #ifdef JP
2277                         msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ï¥Ú¥Ã¥È¤Ç¤Ï¤Ê¤¤¡£");
2278 #else
2279                         msg_format("This monster is not a pet.");
2280 #endif
2281                         return;
2282                 }
2283                 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2284                 {
2285 #ifdef JP
2286                         msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Î̾Á°¤ÏÊѤ¨¤é¤ì¤Ê¤¤¡ª");
2287 #else
2288                         msg_format("You cannot change name of this monster!");
2289 #endif
2290                         return;
2291                 }
2292                 monster_desc(m_name, m_ptr, 0);
2293
2294                 /* Message */
2295 #ifdef JP
2296                 msg_format("%s¤Ë̾Á°¤ò¤Ä¤±¤ë¡£", m_name);
2297 #else
2298                 msg_format("Name %s.", m_name);
2299 #endif
2300
2301                 msg_print(NULL);
2302
2303                 /* Start with nothing */
2304                 strcpy(out_val, "");
2305
2306                 /* Use old inscription */
2307                 if (m_ptr->nickname)
2308                 {
2309                         /* Start with the old inscription */
2310                         strcpy(out_val, quark_str(m_ptr->nickname));
2311                         old_name = TRUE;
2312                 }
2313
2314                 /* Get a new inscription (possibly empty) */
2315 #ifdef JP
2316                 if (get_string("̾Á°: ", out_val, 15))
2317 #else
2318                 if (get_string("Name: ", out_val, 15))
2319 #endif
2320
2321                 {
2322                         if (out_val[0])
2323                         {
2324                                 /* Save the inscription */
2325                                 m_ptr->nickname = quark_add(out_val);
2326                                 if (record_named_pet)
2327                                 {
2328                                         char m_name[80];
2329
2330                                         monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
2331                                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_NAME, m_name);
2332                                 }
2333                         }
2334                         else
2335                         {
2336                                 if (record_named_pet && old_name)
2337                                 {
2338                                         char m_name[80];
2339
2340                                         monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
2341                                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_UNNAME, m_name);
2342                                 }
2343                                 m_ptr->nickname = 0;
2344                         }
2345                 }
2346         }
2347 }
2348
2349 /*
2350  * Issue a pet command
2351  */
2352 void do_cmd_pet(void)
2353 {
2354         int                     i = 0;
2355         int                     num;
2356         int                     powers[36];
2357         cptr                    power_desc[36];
2358         bool                    flag, redraw;
2359         int                     ask;
2360         char                    choice;
2361         char                    out_val[160];
2362         int                     pet_ctr;
2363         monster_type    *m_ptr;
2364
2365         int mode = 0;
2366
2367         char buf[160];
2368         char target_buf[160];
2369
2370         int menu_line = use_menu ? 1 : 0;
2371
2372         num = 0;
2373
2374 #ifdef JP
2375         power_desc[num] = "¥Ú¥Ã¥È¤òÊü¤¹";
2376 #else
2377         power_desc[num] = "dismiss pets";
2378 #endif
2379
2380         powers[num++] = PET_DISMISS;
2381
2382 #ifdef JP
2383         sprintf(target_buf, "¥Ú¥Ã¥È¤Î¥¿¡¼¥²¥Ã¥È¤ò»ØÄê (¸½ºß¡§%s)",
2384                 (pet_t_m_idx ? (p_ptr->image ? "²¿¤«´ñ̯¤Êʪ" : (r_name + r_info[m_list[pet_t_m_idx].ap_r_idx].name)) : "»ØÄê¤Ê¤·"));
2385 #else
2386         sprintf(target_buf, "specify a target of pet (now:%s)",
2387                 (pet_t_m_idx ? (p_ptr->image ? "something strange" : (r_name + r_info[m_list[pet_t_m_idx].ap_r_idx].name)) : "nothing"));
2388 #endif
2389         power_desc[num] = target_buf;
2390
2391         powers[num++] = PET_TARGET;
2392
2393 #ifdef JP
2394         power_desc[num] = "¶á¤¯¤Ë¤¤¤í";
2395 #else
2396         power_desc[num] = "stay close";
2397 #endif
2398
2399         if (p_ptr->pet_follow_distance == PET_CLOSE_DIST) mode = num;
2400         powers[num++] = PET_STAY_CLOSE;
2401
2402 #ifdef JP
2403         power_desc[num] = "¤Ä¤¤¤ÆÍ褤";
2404 #else
2405         power_desc[num] = "follow me";
2406 #endif
2407
2408         if (p_ptr->pet_follow_distance == PET_FOLLOW_DIST) mode = num;
2409         powers[num++] = PET_FOLLOW_ME;
2410
2411 #ifdef JP
2412         power_desc[num] = "Ũ¤ò¸«¤Ä¤±¤ÆÅݤ»";
2413 #else
2414         power_desc[num] = "seek and destroy";
2415 #endif
2416
2417         if (p_ptr->pet_follow_distance == PET_DESTROY_DIST) mode = num;
2418         powers[num++] = PET_SEEK_AND_DESTROY;
2419
2420 #ifdef JP
2421         power_desc[num] = "¾¯¤·Î¥¤ì¤Æ¤¤¤í";
2422 #else
2423         power_desc[num] = "give me space";
2424 #endif
2425
2426         if (p_ptr->pet_follow_distance == PET_SPACE_DIST) mode = num;
2427         powers[num++] = PET_ALLOW_SPACE;
2428
2429 #ifdef JP
2430         power_desc[num] = "Î¥¤ì¤Æ¤¤¤í";
2431 #else
2432         power_desc[num] = "stay away";
2433 #endif
2434
2435         if (p_ptr->pet_follow_distance == PET_AWAY_DIST) mode = num;
2436         powers[num++] = PET_STAY_AWAY;
2437
2438         if (p_ptr->pet_extra_flags & PF_OPEN_DOORS)
2439         {
2440 #ifdef JP
2441                 power_desc[num] = "¥É¥¢¤ò³«¤±¤ë (¸½ºß:ON)";
2442 #else
2443                 power_desc[num] = "pets open doors (now On)";
2444 #endif
2445         }
2446         else
2447         {
2448 #ifdef JP
2449                 power_desc[num] = "¥É¥¢¤ò³«¤±¤ë (¸½ºß:OFF)";
2450 #else
2451                 power_desc[num] = "pets open doors (now Off)";
2452 #endif
2453         }
2454         powers[num++] = PET_OPEN_DOORS;
2455
2456         if (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)
2457         {
2458 #ifdef JP
2459                 power_desc[num] = "¥¢¥¤¥Æ¥à¤ò½¦¤¦ (¸½ºß:ON)";
2460 #else
2461                 power_desc[num] = "pets pick up items (now On)";
2462 #endif
2463         }
2464         else
2465         {
2466 #ifdef JP
2467                 power_desc[num] = "¥¢¥¤¥Æ¥à¤ò½¦¤¦ (¸½ºß:OFF)";
2468 #else
2469                 power_desc[num] = "pets pick up items (now Off)";
2470 #endif
2471         }
2472         powers[num++] = PET_TAKE_ITEMS;
2473
2474         if (p_ptr->pet_extra_flags & PF_TELEPORT)
2475         {
2476 #ifdef JP
2477                 power_desc[num] = "¥Æ¥ì¥Ý¡¼¥È·ÏËâË¡¤ò»È¤¦ (¸½ºß:ON)";
2478 #else
2479                 power_desc[num] = "allow teleport (now On)";
2480 #endif
2481         }
2482         else
2483         {
2484 #ifdef JP
2485                 power_desc[num] = "¥Æ¥ì¥Ý¡¼¥È·ÏËâË¡¤ò»È¤¦ (¸½ºß:OFF)";
2486 #else
2487                 power_desc[num] = "allow teleport (now Off)";
2488 #endif
2489         }
2490         powers[num++] = PET_TELEPORT;
2491
2492         if (p_ptr->pet_extra_flags & PF_ATTACK_SPELL)
2493         {
2494 #ifdef JP
2495                 power_desc[num] = "¹¶·âËâË¡¤ò»È¤¦ (¸½ºß:ON)";
2496 #else
2497                 power_desc[num] = "allow cast attack spell (now On)";
2498 #endif
2499         }
2500         else
2501         {
2502 #ifdef JP
2503                 power_desc[num] = "¹¶·âËâË¡¤ò»È¤¦ (¸½ºß:OFF)";
2504 #else
2505                 power_desc[num] = "allow cast attack spell (now Off)";
2506 #endif
2507         }
2508         powers[num++] = PET_ATTACK_SPELL;
2509
2510         if (p_ptr->pet_extra_flags & PF_SUMMON_SPELL)
2511         {
2512 #ifdef JP
2513                 power_desc[num] = "¾¤´­ËâË¡¤ò»È¤¦ (¸½ºß:ON)";
2514 #else
2515                 power_desc[num] = "allow cast summon spell (now On)";
2516 #endif
2517         }
2518         else
2519         {
2520 #ifdef JP
2521                 power_desc[num] = "¾¤´­ËâË¡¤ò»È¤¦ (¸½ºß:OFF)";
2522 #else
2523                 power_desc[num] = "allow cast summon spell (now Off)";
2524 #endif
2525         }
2526         powers[num++] = PET_SUMMON_SPELL;
2527
2528         if (p_ptr->pet_extra_flags & PF_BALL_SPELL)
2529         {
2530 #ifdef JP
2531                 power_desc[num] = "¥×¥ì¥¤¥ä¡¼¤ò´¬¤­¹þ¤àÈÏ°ÏËâË¡¤ò»È¤¦ (¸½ºß:ON)";
2532 #else
2533                 power_desc[num] = "allow involve player in area spell (now On)";
2534 #endif
2535         }
2536         else
2537         {
2538 #ifdef JP
2539                 power_desc[num] = "¥×¥ì¥¤¥ä¡¼¤ò´¬¤­¹þ¤àÈÏ°ÏËâË¡¤ò»È¤¦ (¸½ºß:OFF)";
2540 #else
2541                 power_desc[num] = "allow involve player in area spell (now Off)";
2542 #endif
2543         }
2544         powers[num++] = PET_BALL_SPELL;
2545
2546         if (p_ptr->riding)
2547         {
2548 #ifdef JP
2549                 power_desc[num] = "¥Ú¥Ã¥È¤«¤é¹ß¤ê¤ë";
2550 #else
2551                 power_desc[num] = "get off a pet";
2552 #endif
2553         }
2554         else
2555         {
2556 #ifdef JP
2557                 power_desc[num] = "¥Ú¥Ã¥È¤Ë¾è¤ë";
2558 #else
2559                 power_desc[num] = "ride a pet";
2560 #endif
2561         }
2562         powers[num++] = PET_RIDING;
2563
2564 #ifdef JP
2565         power_desc[num] = "¥Ú¥Ã¥È¤Ë̾Á°¤ò¤Ä¤±¤ë";
2566 #else
2567         power_desc[num] = "name pets";
2568 #endif
2569
2570         powers[num++] = PET_NAME;
2571
2572         if (p_ptr->riding)
2573         {
2574                 if ((p_ptr->migite && (empty_hands(FALSE) == EMPTY_HAND_LARM) &&
2575                      object_allow_two_hands_wielding(&inventory[INVEN_RARM])) ||
2576                     (p_ptr->hidarite && (empty_hands(FALSE) == EMPTY_HAND_RARM) &&
2577                          object_allow_two_hands_wielding(&inventory[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 both hands for a weapon";
2593 #endif
2594                         }
2595
2596                         powers[num++] = PET_RYOUTE;
2597                 }
2598                 else
2599                 {
2600                         switch (p_ptr->pclass)
2601                         {
2602                         case CLASS_MONK:
2603                         case CLASS_FORCETRAINER:
2604                         case CLASS_BERSERKER:
2605                                 if (empty_hands(FALSE) == (EMPTY_HAND_RARM | EMPTY_HAND_LARM))
2606                                 {
2607                                         if (p_ptr->pet_extra_flags & PF_RYOUTE)
2608                                         {
2609 #ifdef JP
2610                                                 power_desc[num] = "ÊÒ¼ê¤Ç³ÊÆ®¤¹¤ë";
2611 #else
2612                                                 power_desc[num] = "use one hand to control a riding pet";
2613 #endif
2614                                         }
2615                                         else
2616                                         {
2617 #ifdef JP
2618                                                 power_desc[num] = "ξ¼ê¤Ç³ÊÆ®¤¹¤ë";
2619 #else
2620                                                 power_desc[num] = "use both hands for melee";
2621 #endif
2622                                         }
2623
2624                                         powers[num++] = PET_RYOUTE;
2625                                 }
2626                                 else if ((empty_hands(FALSE) != EMPTY_HAND_NONE) && !buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM))
2627                                 {
2628                                         if (p_ptr->pet_extra_flags & PF_RYOUTE)
2629                                         {
2630 #ifdef JP
2631                                                 power_desc[num] = "³ÊÆ®¤ò¹Ô¤ï¤Ê¤¤";
2632 #else
2633                                                 power_desc[num] = "use one hand to control a riding pet";
2634 #endif
2635                                         }
2636                                         else
2637                                         {
2638 #ifdef JP
2639                                                 power_desc[num] = "³ÊÆ®¤ò¹Ô¤¦";
2640 #else
2641                                                 power_desc[num] = "use one hand for melee";
2642 #endif
2643                                         }
2644
2645                                         powers[num++] = PET_RYOUTE;
2646                                 }
2647                                 break;
2648                         }
2649                 }
2650         }
2651
2652 #ifdef ALLOW_REPEAT
2653         if (!(repeat_pull(&i) && (i >= 0) && (i < num)))
2654         {
2655 #endif /* ALLOW_REPEAT */
2656
2657         /* Nothing chosen yet */
2658         flag = FALSE;
2659
2660         /* No redraw yet */
2661         redraw = FALSE;
2662
2663         if (use_menu)
2664         {
2665                 /* Save the screen */
2666                 screen_save();
2667
2668                 /* Build a prompt */
2669 #ifdef JP
2670                 strnfmt(out_val, 78, "(¥³¥Þ¥ó¥É¡¢ESC=½ªÎ») ¥³¥Þ¥ó¥É¤òÁª¤ó¤Ç¤¯¤À¤µ¤¤:");
2671 #else
2672                 strnfmt(out_val, 78, "(Command, ESC=exit) Choose command from menu.");
2673 #endif
2674         }
2675         else
2676         {
2677                 /* Build a prompt */
2678                 strnfmt(out_val, 78,
2679 #ifdef JP
2680                         "(¥³¥Þ¥ó¥É %c-%c¡¢'*'=°ìÍ÷¡¢ESC=½ªÎ») ¥³¥Þ¥ó¥É¤òÁª¤ó¤Ç¤¯¤À¤µ¤¤:",
2681 #else
2682                         "(Command %c-%c, *=List, ESC=exit) Select a command: ",
2683 #endif
2684                         I2A(0), I2A(num - 1));
2685         }
2686
2687         choice = (always_show_list || use_menu) ? ESCAPE : 1;
2688
2689         /* Get a command from the user */
2690         while (!flag)
2691         {
2692                 if (choice == ESCAPE) choice = ' ';
2693                 else if (!get_com(out_val, &choice, TRUE)) break;
2694
2695                 if (use_menu && (choice != ' '))
2696                 {
2697                         switch (choice)
2698                         {
2699                         case '0':
2700                                 screen_load();
2701                                 return;
2702
2703                         case '8':
2704                         case 'k':
2705                         case 'K':
2706                                 menu_line += (num - 1);
2707                                 break;
2708
2709                         case '2':
2710                         case 'j':
2711                         case 'J':
2712                                 menu_line++;
2713                                 break;
2714
2715                         case '4':
2716                         case 'h':
2717                         case 'H':
2718                                 menu_line = 1;
2719                                 break;
2720
2721                         case '6':
2722                         case 'l':
2723                         case 'L':
2724                                 menu_line = num;
2725                                 break;
2726
2727                         case 'x':
2728                         case 'X':
2729                         case '\r':
2730                         case '\n':
2731                                 i = menu_line - 1;
2732                                 ask = FALSE;
2733                                 break;
2734                         }
2735                         if (menu_line > num) menu_line -= num;
2736                 }
2737
2738                 /* Request redraw */
2739                 if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
2740                 {
2741                         /* Show the list */
2742                         if (!redraw || use_menu)
2743                         {
2744                                 byte y = 1, x = 0;
2745                                 int ctr = 0;
2746
2747                                 /* Show list */
2748                                 redraw = TRUE;
2749
2750                                 /* Save the screen */
2751                                 if (!use_menu) screen_save();
2752
2753                                 prt("", y++, x);
2754
2755                                 /* Print list */
2756                                 for (ctr = 0; ctr < num; ctr++)
2757                                 {
2758                                         /* Letter/number for power selection */
2759 #ifdef JP
2760                                         if (use_menu) sprintf(buf, "%c%s ", (ctr == mode) ? '*' : ' ', (ctr == (menu_line - 1)) ? "¡Õ" : "  ");
2761 #else
2762                                         if (use_menu) sprintf(buf, "%c%s ", (ctr == mode) ? '*' : ' ', (ctr == (menu_line - 1)) ? "> " : "  ");
2763 #endif
2764                                         else sprintf(buf, "%c%c) ", (ctr == mode) ? '*' : ' ', I2A(ctr));
2765
2766                                         strcat(buf, power_desc[ctr]);
2767
2768                                         prt(buf, y + ctr, x);
2769                                 }
2770
2771                                 prt("", y + MIN(ctr, 17), x);
2772                         }
2773
2774                         /* Hide the list */
2775                         else
2776                         {
2777                                 /* Hide list */
2778                                 redraw = FALSE;
2779
2780                                 /* Restore the screen */
2781                                 screen_load();
2782                         }
2783
2784                         /* Redo asking */
2785                         continue;
2786                 }
2787
2788                 if (!use_menu)
2789                 {
2790                         /* Note verify */
2791                         ask = (isupper(choice));
2792
2793                         /* Lowercase */
2794                         if (ask) choice = tolower(choice);
2795
2796                         /* Extract request */
2797                         i = (islower(choice) ? A2I(choice) : -1);
2798                 }
2799
2800                 /* Totally Illegal */
2801                 if ((i < 0) || (i >= num))
2802                 {
2803                         bell();
2804                         continue;
2805                 }
2806
2807                 /* Verify it */
2808                 if (ask)
2809                 {
2810                         /* Prompt */
2811 #ifdef JP
2812                         strnfmt(buf, 78, "%s¤ò»È¤¤¤Þ¤¹¤«¡© ", power_desc[i]);
2813 #else
2814                         strnfmt(buf, 78, "Use %s? ", power_desc[i]);
2815 #endif
2816
2817                         /* Belay that order */
2818                         if (!get_check(buf)) continue;
2819                 }
2820
2821                 /* Stop the loop */
2822                 flag = TRUE;
2823         }
2824
2825         /* Restore the screen */
2826         if (redraw) screen_load();
2827
2828         /* Abort if needed */
2829         if (!flag)
2830         {
2831                 energy_use = 0;
2832                 return;
2833         }
2834
2835 #ifdef ALLOW_REPEAT
2836         repeat_push(i);
2837         }
2838 #endif /* ALLOW_REPEAT */
2839
2840         switch (powers[i])
2841         {
2842                 case PET_DISMISS: /* Dismiss pets */
2843                 {
2844                         /* Check pets (backwards) */
2845                         for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
2846                         {
2847                                 /* Player has pet */
2848                                 if (is_pet(&m_list[pet_ctr])) break;
2849                         }
2850
2851                         if (!pet_ctr)
2852                         {
2853 #ifdef JP
2854                                 msg_print("¥Ú¥Ã¥È¤¬¤¤¤Ê¤¤¡ª");
2855 #else
2856                                 msg_print("You have no pets!");
2857 #endif
2858                                 break;
2859                         }
2860                         do_cmd_pet_dismiss();
2861                         (void)calculate_upkeep();
2862                         break;
2863                 }
2864                 case PET_TARGET:
2865                 {
2866                         project_length = -1;
2867                         if (!target_set(TARGET_KILL)) pet_t_m_idx = 0;
2868                         else
2869                         {
2870                                 cave_type *c_ptr = &cave[target_row][target_col];
2871                                 if (c_ptr->m_idx && (m_list[c_ptr->m_idx].ml))
2872                                 {
2873                                         pet_t_m_idx = cave[target_row][target_col].m_idx;
2874                                         p_ptr->pet_follow_distance = PET_DESTROY_DIST;
2875                                 }
2876                                 else pet_t_m_idx = 0;
2877                         }
2878                         project_length = 0;
2879
2880                         break;
2881                 }
2882                 /* Call pets */
2883                 case PET_STAY_CLOSE:
2884                 {
2885                         p_ptr->pet_follow_distance = PET_CLOSE_DIST;
2886                         pet_t_m_idx = 0;
2887                         break;
2888                 }
2889                 /* "Follow Me" */
2890                 case PET_FOLLOW_ME:
2891                 {
2892                         p_ptr->pet_follow_distance = PET_FOLLOW_DIST;
2893                         pet_t_m_idx = 0;
2894                         break;
2895                 }
2896                 /* "Seek and destoy" */
2897                 case PET_SEEK_AND_DESTROY:
2898                 {
2899                         p_ptr->pet_follow_distance = PET_DESTROY_DIST;
2900                         break;
2901                 }
2902                 /* "Give me space" */
2903                 case PET_ALLOW_SPACE:
2904                 {
2905                         p_ptr->pet_follow_distance = PET_SPACE_DIST;
2906                         break;
2907                 }
2908                 /* "Stay away" */
2909                 case PET_STAY_AWAY:
2910                 {
2911                         p_ptr->pet_follow_distance = PET_AWAY_DIST;
2912                         break;
2913                 }
2914                 /* flag - allow pets to open doors */
2915                 case PET_OPEN_DOORS:
2916                 {
2917                         if (p_ptr->pet_extra_flags & PF_OPEN_DOORS) p_ptr->pet_extra_flags &= ~(PF_OPEN_DOORS);
2918                         else p_ptr->pet_extra_flags |= (PF_OPEN_DOORS);
2919                         break;
2920                 }
2921                 /* flag - allow pets to pickup items */
2922                 case PET_TAKE_ITEMS:
2923                 {
2924                         if (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)
2925                         {
2926                                 p_ptr->pet_extra_flags &= ~(PF_PICKUP_ITEMS);
2927                                 for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--)
2928                                 {
2929                                         /* Access the monster */
2930                                         m_ptr = &m_list[pet_ctr];
2931
2932                                         if (is_pet(m_ptr))
2933                                         {
2934                                                 monster_drop_carried_objects(m_ptr);
2935                                         }
2936                                 }
2937                         }
2938                         else p_ptr->pet_extra_flags |= (PF_PICKUP_ITEMS);
2939
2940                         break;
2941                 }
2942                 /* flag - allow pets to teleport */
2943                 case PET_TELEPORT:
2944                 {
2945                         if (p_ptr->pet_extra_flags & PF_TELEPORT) p_ptr->pet_extra_flags &= ~(PF_TELEPORT);
2946                         else p_ptr->pet_extra_flags |= (PF_TELEPORT);
2947                         break;
2948                 }
2949                 /* flag - allow pets to cast attack spell */
2950                 case PET_ATTACK_SPELL:
2951                 {
2952                         if (p_ptr->pet_extra_flags & PF_ATTACK_SPELL) p_ptr->pet_extra_flags &= ~(PF_ATTACK_SPELL);
2953                         else p_ptr->pet_extra_flags |= (PF_ATTACK_SPELL);
2954                         break;
2955                 }
2956                 /* flag - allow pets to cast attack spell */
2957                 case PET_SUMMON_SPELL:
2958                 {
2959                         if (p_ptr->pet_extra_flags & PF_SUMMON_SPELL) p_ptr->pet_extra_flags &= ~(PF_SUMMON_SPELL);
2960                         else p_ptr->pet_extra_flags |= (PF_SUMMON_SPELL);
2961                         break;
2962                 }
2963                 /* flag - allow pets to cast attack spell */
2964                 case PET_BALL_SPELL:
2965                 {
2966                         if (p_ptr->pet_extra_flags & PF_BALL_SPELL) p_ptr->pet_extra_flags &= ~(PF_BALL_SPELL);
2967                         else p_ptr->pet_extra_flags |= (PF_BALL_SPELL);
2968                         break;
2969                 }
2970
2971                 case PET_RIDING:
2972                 {
2973                         (void)do_riding(FALSE);
2974                         break;
2975                 }
2976
2977                 case PET_NAME:
2978                 {
2979                         do_name_pet();
2980                         break;
2981                 }
2982
2983                 case PET_RYOUTE:
2984                 {
2985                         if (p_ptr->pet_extra_flags & PF_RYOUTE) p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
2986                         else p_ptr->pet_extra_flags |= (PF_RYOUTE);
2987                         p_ptr->update |= (PU_BONUS);
2988                         handle_stuff();
2989                         break;
2990                 }
2991         }
2992 }