OSDN Git Service

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