OSDN Git Service

Merge pull request #36 from taotao54321/fix-wrong-evasion-message
[hengbandforosx/hengbandosx.git] / src / cmd-action / cmd-pet.c
1 #include "cmd-action/cmd-pet.h"
2 #include "action/action-limited.h"
3 #include "cmd-action/cmd-attack.h"
4 #include "cmd-io/cmd-dump.h"
5 #include "core/asking-player.h"
6 #include "core/player-redraw-types.h"
7 #include "core/player-update-types.h"
8 #include "core/stuff-handler.h"
9 #include "core/window-redrawer.h"
10 #include "effect/spells-effect-util.h"
11 #include "floor/pattern-walk.h"
12 #include "game-option/input-options.h"
13 #include "game-option/play-record-options.h"
14 #include "game-option/text-display-options.h"
15 #include "game-option/map-screen-options.h"
16 #include "grid/feature.h"
17 #include "grid/grid.h"
18 #include "inventory/inventory-slot-types.h"
19 #include "io/command-repeater.h"
20 #include "io/cursor.h"
21 #include "io/input-key-acceptor.h"
22 #include "io/input-key-requester.h"
23 #include "io/write-diary.h"
24 #include "main/sound-of-music.h"
25 #include "monster-floor/monster-object.h"
26 #include "monster-floor/monster-remover.h"
27 #include "monster-race/monster-race.h"
28 #include "monster-race/race-flags1.h"
29 #include "monster-race/race-flags7.h"
30 #include "monster/monster-describer.h"
31 #include "monster/monster-description-types.h"
32 #include "monster/monster-info.h"
33 #include "monster/monster-status-setter.h"
34 #include "monster/monster-status.h"
35 #include "monster/smart-learn-types.h"
36 #include "object-hook/hook-weapon.h"
37 #include "pet/pet-util.h"
38 #include "player/attack-defense-types.h"
39 #include "player/player-class.h"
40 #include "player/player-damage.h"
41 #include "player/player-move.h"
42 #include "player/player-skill.h"
43 #include "player/player-status-flags.h"
44 #include "player/player-status.h"
45 #include "player/special-defense-types.h"
46 #include "status/action-setter.h"
47 #include "system/floor-type-definition.h"
48 #include "target/target-checker.h"
49 #include "target/target-getter.h"
50 #include "target/target-setter.h"
51 #include "target/target-types.h"
52 #include "term/screen-processor.h"
53 #include "util/bit-flags-calculator.h"
54 #include "util/int-char-converter.h"
55 #include "util/quarks.h"
56 #include "util/sort.h"
57 #include "view/display-messages.h"
58 #include "world/world.h"
59
60 int total_friends = 0;
61
62 /*!
63  * @brief ペットを開放するコマンドのメインルーチン
64  * @return なし
65  */
66 void do_cmd_pet_dismiss(player_type *creature_ptr)
67 {
68     monster_type *m_ptr;
69     bool all_pets = FALSE;
70     MONSTER_IDX pet_ctr;
71     int i;
72     int Dismissed = 0;
73
74     MONSTER_IDX *who;
75     u16b dummy_why;
76     int max_pet = 0;
77     bool cu, cv;
78
79     cu = Term->scr->cu;
80     cv = Term->scr->cv;
81     Term->scr->cu = 0;
82     Term->scr->cv = 1;
83
84     /* Allocate the "who" array */
85     C_MAKE(who, current_world_ptr->max_m_idx, MONSTER_IDX);
86
87     /* Process the monsters (backwards) */
88     for (pet_ctr = creature_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--) {
89         if (is_pet(&creature_ptr->current_floor_ptr->m_list[pet_ctr]))
90             who[max_pet++] = pet_ctr;
91     }
92
93     ang_sort(creature_ptr, who, &dummy_why, max_pet, ang_sort_comp_pet_dismiss, ang_sort_swap_hook);
94
95     /* Process the monsters (backwards) */
96     for (i = 0; i < max_pet; i++) {
97         bool delete_this;
98         GAME_TEXT friend_name[MAX_NLEN];
99         bool kakunin;
100
101         pet_ctr = who[i];
102         m_ptr = &creature_ptr->current_floor_ptr->m_list[pet_ctr];
103
104         delete_this = FALSE;
105         kakunin = ((pet_ctr == creature_ptr->riding) || (m_ptr->nickname));
106         monster_desc(creature_ptr, friend_name, m_ptr, MD_ASSUME_VISIBLE);
107
108         if (!all_pets) {
109             /* Hack -- health bar for this monster */
110             health_track(creature_ptr, pet_ctr);
111             handle_stuff(creature_ptr);
112
113             msg_format(_("%sを放しますか? [Yes/No/Unnamed (%d体)]", "Dismiss %s? [Yes/No/Unnamed (%d remain)]"), friend_name, max_pet - i);
114
115             if (m_ptr->ml)
116                 move_cursor_relative(m_ptr->fy, m_ptr->fx);
117
118             while (TRUE) {
119                 char ch = inkey();
120
121                 if (ch == 'Y' || ch == 'y') {
122                     delete_this = TRUE;
123
124                     if (kakunin) {
125                         msg_format(_("本当によろしいですか? (%s) ", "Are you sure? (%s) "), friend_name);
126                         ch = inkey();
127                         if (ch != 'Y' && ch != 'y')
128                             delete_this = FALSE;
129                     }
130                     break;
131                 }
132
133                 if (ch == 'U' || ch == 'u') {
134                     all_pets = TRUE;
135                     break;
136                 }
137
138                 if (ch == ESCAPE || ch == 'N' || ch == 'n')
139                     break;
140
141                 bell();
142             }
143         }
144
145         if ((all_pets && !kakunin) || (!all_pets && delete_this)) {
146             if (record_named_pet && m_ptr->nickname) {
147                 GAME_TEXT m_name[MAX_NLEN];
148
149                 monster_desc(creature_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
150                 exe_write_diary(creature_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_DISMISS, m_name);
151             }
152
153             if (pet_ctr == creature_ptr->riding) {
154                 msg_format(_("%sから降りた。", "You dismount from %s. "), friend_name);
155
156                 creature_ptr->riding = 0;
157
158                 creature_ptr->update |= (PU_MONSTERS);
159                 creature_ptr->redraw |= (PR_EXTRA | PR_UHEALTH);
160             }
161
162             /* HACK : Add the line to message buffer */
163             msg_format(_("%s を放した。", "Dismissed %s."), friend_name);
164             creature_ptr->update |= (PU_BONUS);
165             creature_ptr->window_flags |= (PW_MESSAGE);
166
167             delete_monster_idx(creature_ptr, pet_ctr);
168             Dismissed++;
169         }
170     }
171
172     Term->scr->cu = cu;
173     Term->scr->cv = cv;
174     if (fresh_after)
175         term_fresh();
176
177     C_KILL(who, current_world_ptr->max_m_idx, MONSTER_IDX);
178
179 #ifdef JP
180     msg_format("%d 体のペットを放しました。", Dismissed);
181 #else
182     msg_format("You have dismissed %d pet%s.", Dismissed, (Dismissed == 1 ? "" : "s"));
183 #endif
184     if (Dismissed == 0 && all_pets)
185         msg_print(_("'U'nnamed は、乗馬以外の名前のないペットだけを全て解放します。", "'U'nnamed means all your pets except named pets and your mount."));
186
187     handle_stuff(creature_ptr);
188 }
189
190 /*!
191  * @brief ペットから騎乗/下馬するコマンドのメインルーチン /
192  * @param force 強制的に騎乗/下馬するならばTRUE
193  * @return 騎乗/下馬できたらTRUE
194  */
195 bool do_cmd_riding(player_type *creature_ptr, bool force)
196 {
197     POSITION x, y;
198     DIRECTION dir = 0;
199     grid_type *g_ptr;
200     monster_type *m_ptr;
201
202     if (!get_direction(creature_ptr, &dir, FALSE, FALSE))
203         return FALSE;
204     y = creature_ptr->y + ddy[dir];
205     x = creature_ptr->x + ddx[dir];
206     g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
207
208     if (creature_ptr->special_defense & KATA_MUSOU)
209         set_action(creature_ptr, ACTION_NONE);
210
211     if (creature_ptr->riding) {
212         /* Skip non-empty grids */
213         if (!can_player_ride_pet(creature_ptr, g_ptr, FALSE)) {
214             msg_print(_("そちらには降りられません。", "You cannot go that direction."));
215             return FALSE;
216         }
217
218         if (!pattern_seq(creature_ptr, creature_ptr->y, creature_ptr->x, y, x))
219             return FALSE;
220
221         if (g_ptr->m_idx) {
222             take_turn(creature_ptr, 100);
223
224             msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
225
226             do_cmd_attack(creature_ptr, y, x, 0);
227             return FALSE;
228         }
229
230         creature_ptr->riding = 0;
231         creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
232         creature_ptr->riding_ryoute = creature_ptr->old_riding_ryoute = FALSE;
233     } else {
234         if (cmd_limit_confused(creature_ptr))
235             return FALSE;
236
237         m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
238
239         if (!g_ptr->m_idx || !m_ptr->ml) {
240             msg_print(_("その場所にはモンスターはいません。", "There is no monster here."));
241             return FALSE;
242         }
243         if (!is_pet(m_ptr) && !force) {
244             msg_print(_("そのモンスターはペットではありません。", "That monster is not a pet."));
245             return FALSE;
246         }
247         if (!(r_info[m_ptr->r_idx].flags7 & RF7_RIDING)) {
248             msg_print(_("そのモンスターには乗れなさそうだ。", "This monster doesn't seem suitable for riding."));
249             return FALSE;
250         }
251
252         if (!pattern_seq(creature_ptr, creature_ptr->y, creature_ptr->x, y, x))
253             return FALSE;
254
255         if (!can_player_ride_pet(creature_ptr, g_ptr, TRUE)) {
256             /* Feature code (applying "mimic" field) */
257             feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
258 #ifdef JP
259             msg_format("そのモンスターは%sの%sにいる。", f_name + f_ptr->name,
260                 ((!has_flag(f_ptr->flags, FF_MOVE) && !has_flag(f_ptr->flags, FF_CAN_FLY))
261                     || (!has_flag(f_ptr->flags, FF_LOS) && !has_flag(f_ptr->flags, FF_TREE)))
262                     ? "中"
263                     : "上");
264 #else
265             msg_format("This monster is %s the %s.",
266                 ((!has_flag(f_ptr->flags, FF_MOVE) && !has_flag(f_ptr->flags, FF_CAN_FLY))
267                     || (!has_flag(f_ptr->flags, FF_LOS) && !has_flag(f_ptr->flags, FF_TREE)))
268                     ? "in"
269                     : "on",
270                 f_name + f_ptr->name);
271 #endif
272
273             return FALSE;
274         }
275         if (r_info[m_ptr->r_idx].level > randint1((creature_ptr->skill_exp[GINOU_RIDING] / 50 + creature_ptr->lev / 2 + 20))) {
276             msg_print(_("うまく乗れなかった。", "You failed to ride."));
277             take_turn(creature_ptr, 100);
278             return FALSE;
279         }
280
281         if (monster_csleep_remaining(m_ptr)) {
282             GAME_TEXT m_name[MAX_NLEN];
283             monster_desc(creature_ptr, m_name, m_ptr, 0);
284             (void)set_monster_csleep(creature_ptr, g_ptr->m_idx, 0);
285             msg_format(_("%sを起こした。", "You have woken %s up."), m_name);
286         }
287
288         if (creature_ptr->action == ACTION_KAMAE)
289             set_action(creature_ptr, ACTION_NONE);
290
291         creature_ptr->riding = g_ptr->m_idx;
292
293         /* Hack -- remove tracked monster */
294         if (creature_ptr->riding == creature_ptr->health_who)
295             health_track(creature_ptr, 0);
296     }
297
298     take_turn(creature_ptr, 100);
299
300     /* Mega-Hack -- Forget the view and lite */
301     creature_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
302     creature_ptr->update |= (PU_BONUS);
303     creature_ptr->redraw |= (PR_MAP | PR_EXTRA);
304     creature_ptr->redraw |= (PR_UHEALTH);
305
306     (void)move_player_effect(creature_ptr, y, x, MPE_HANDLE_STUFF | MPE_ENERGY_USE | MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);
307
308     return TRUE;
309 }
310
311 /*!
312  * @brief ペットに名前をつけるコマンドのメインルーチン
313  * @return なし
314  */
315 static void do_name_pet(player_type *creature_ptr)
316 {
317     monster_type *m_ptr;
318     char out_val[20];
319     GAME_TEXT m_name[MAX_NLEN];
320     bool old_name = FALSE;
321     bool old_target_pet = target_pet;
322
323     target_pet = TRUE;
324     if (!target_set(creature_ptr, TARGET_KILL)) {
325         target_pet = old_target_pet;
326         return;
327     }
328
329     target_pet = old_target_pet;
330
331     if (creature_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx) {
332         m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx];
333
334         if (!is_pet(m_ptr)) {
335             msg_print(_("そのモンスターはペットではない。", "This monster is not a pet."));
336             return;
337         }
338         if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE) {
339             msg_print(_("そのモンスターの名前は変えられない!", "You cannot change the name of this monster!"));
340             return;
341         }
342         monster_desc(creature_ptr, m_name, m_ptr, 0);
343
344         msg_format(_("%sに名前をつける。", "Name %s."), m_name);
345         msg_print(NULL);
346
347         /* Start with nothing */
348         strcpy(out_val, "");
349
350         /* Use old inscription */
351         if (m_ptr->nickname) {
352             /* Start with the old inscription */
353             strcpy(out_val, quark_str(m_ptr->nickname));
354             old_name = TRUE;
355         }
356
357         /* Get a new inscription (possibly empty) */
358         if (get_string(_("名前: ", "Name: "), out_val, 15)) {
359             if (out_val[0]) {
360                 /* Save the inscription */
361                 m_ptr->nickname = quark_add(out_val);
362                 if (record_named_pet) {
363                     monster_desc(creature_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
364                     exe_write_diary(creature_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_NAME, m_name);
365                 }
366             } else {
367                 if (record_named_pet && old_name) {
368                     monster_desc(creature_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
369                     exe_write_diary(creature_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_UNNAME, m_name);
370                 }
371                 m_ptr->nickname = 0;
372             }
373         }
374     }
375 }
376
377 /*!
378  * @brief ペットに関するコマンドリストのメインルーチン /
379  * Issue a pet command
380  * @return なし
381  */
382 void do_cmd_pet(player_type *creature_ptr)
383 {
384     COMMAND_CODE i = 0;
385     int num;
386     int powers[36];
387     concptr power_desc[36];
388     bool flag, redraw;
389     char choice;
390     char out_val[160];
391     int pet_ctr;
392     monster_type *m_ptr;
393
394     PET_COMMAND_IDX mode = 0;
395
396     char buf[160];
397     char target_buf[160];
398
399     int menu_line = use_menu ? 1 : 0;
400
401     num = 0;
402
403     if (creature_ptr->wild_mode)
404         return;
405
406     power_desc[num] = _("ペットを放す", "dismiss pets");
407     powers[num++] = PET_DISMISS;
408
409 #ifdef JP
410     sprintf(target_buf, "ペットのターゲットを指定 (現在:%s)",
411         (creature_ptr->pet_t_m_idx
412                 ? (creature_ptr->image ? "何か奇妙な物" : (r_name + r_info[creature_ptr->current_floor_ptr->m_list[creature_ptr->pet_t_m_idx].ap_r_idx].name))
413                 : "指定なし"));
414 #else
415     sprintf(target_buf, "specify a target of pet (now:%s)",
416         (creature_ptr->pet_t_m_idx ? (
417              creature_ptr->image ? "something strange" : (r_name + r_info[creature_ptr->current_floor_ptr->m_list[creature_ptr->pet_t_m_idx].ap_r_idx].name))
418                                    : "nothing"));
419 #endif
420     power_desc[num] = target_buf;
421     powers[num++] = PET_TARGET;
422     power_desc[num] = _("近くにいろ", "stay close");
423
424     if (creature_ptr->pet_follow_distance == PET_CLOSE_DIST)
425         mode = num;
426     powers[num++] = PET_STAY_CLOSE;
427     power_desc[num] = _("ついて来い", "follow me");
428
429     if (creature_ptr->pet_follow_distance == PET_FOLLOW_DIST)
430         mode = num;
431     powers[num++] = PET_FOLLOW_ME;
432     power_desc[num] = _("敵を見つけて倒せ", "seek and destroy");
433
434     if (creature_ptr->pet_follow_distance == PET_DESTROY_DIST)
435         mode = num;
436     powers[num++] = PET_SEEK_AND_DESTROY;
437     power_desc[num] = _("少し離れていろ", "give me space");
438
439     if (creature_ptr->pet_follow_distance == PET_SPACE_DIST)
440         mode = num;
441     powers[num++] = PET_ALLOW_SPACE;
442     power_desc[num] = _("離れていろ", "stay away");
443
444     if (creature_ptr->pet_follow_distance == PET_AWAY_DIST)
445         mode = num;
446     powers[num++] = PET_STAY_AWAY;
447
448     if (creature_ptr->pet_extra_flags & PF_OPEN_DOORS) {
449         power_desc[num] = _("ドアを開ける (現在:ON)", "pets open doors (now On)");
450     } else {
451         power_desc[num] = _("ドアを開ける (現在:OFF)", "pets open doors (now Off)");
452     }
453     powers[num++] = PET_OPEN_DOORS;
454
455     if (creature_ptr->pet_extra_flags & PF_PICKUP_ITEMS) {
456         power_desc[num] = _("アイテムを拾う (現在:ON)", "pets pick up items (now On)");
457     } else {
458         power_desc[num] = _("アイテムを拾う (現在:OFF)", "pets pick up items (now Off)");
459     }
460     powers[num++] = PET_TAKE_ITEMS;
461
462     if (creature_ptr->pet_extra_flags & PF_TELEPORT) {
463         power_desc[num] = _("テレポート系魔法を使う (現在:ON)", "allow teleport (now On)");
464     } else {
465         power_desc[num] = _("テレポート系魔法を使う (現在:OFF)", "allow teleport (now Off)");
466     }
467     powers[num++] = PET_TELEPORT;
468
469     if (creature_ptr->pet_extra_flags & PF_ATTACK_SPELL) {
470         power_desc[num] = _("攻撃魔法を使う (現在:ON)", "allow cast attack spell (now On)");
471     } else {
472         power_desc[num] = _("攻撃魔法を使う (現在:OFF)", "allow cast attack spell (now Off)");
473     }
474     powers[num++] = PET_ATTACK_SPELL;
475
476     if (creature_ptr->pet_extra_flags & PF_SUMMON_SPELL) {
477         power_desc[num] = _("召喚魔法を使う (現在:ON)", "allow cast summon spell (now On)");
478     } else {
479         power_desc[num] = _("召喚魔法を使う (現在:OFF)", "allow cast summon spell (now Off)");
480     }
481     powers[num++] = PET_SUMMON_SPELL;
482
483     if (creature_ptr->pet_extra_flags & PF_BALL_SPELL) {
484         power_desc[num] = _("プレイヤーを巻き込む範囲魔法を使う (現在:ON)", "allow involve player in area spell (now On)");
485     } else {
486         power_desc[num] = _("プレイヤーを巻き込む範囲魔法を使う (現在:OFF)", "allow involve player in area spell (now Off)");
487     }
488     powers[num++] = PET_BALL_SPELL;
489
490     if (creature_ptr->riding) {
491         power_desc[num] = _("ペットから降りる", "get off a pet");
492     } else {
493         power_desc[num] = _("ペットに乗る", "ride a pet");
494     }
495     powers[num++] = PET_RIDING;
496     power_desc[num] = _("ペットに名前をつける", "name pets");
497     powers[num++] = PET_NAME;
498
499     if (creature_ptr->riding) {
500         if ((can_attack_with_main_hand(creature_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_SUB)
501                 && object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_MAIN_HAND]))
502             || (can_attack_with_sub_hand(creature_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_MAIN)
503                 && object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_SUB_HAND]))) {
504             if (creature_ptr->pet_extra_flags & PF_TWO_HANDS) {
505                 power_desc[num] = _("武器を片手で持つ", "use one hand to control the pet you are riding");
506             } else {
507                 power_desc[num] = _("武器を両手で持つ", "use both hands for a weapon");
508             }
509
510             powers[num++] = PET_TWO_HANDS;
511         } else {
512             switch (creature_ptr->pclass) {
513             case CLASS_MONK:
514             case CLASS_FORCETRAINER:
515             case CLASS_BERSERKER:
516                 if (empty_hands(creature_ptr, FALSE) == (EMPTY_HAND_MAIN | EMPTY_HAND_SUB)) {
517                     if (creature_ptr->pet_extra_flags & PF_TWO_HANDS) {
518                         power_desc[num] = _("片手で格闘する", "use one hand to control the pet you are riding");
519                     } else {
520                         power_desc[num] = _("両手で格闘する", "use both hands for melee");
521                     }
522
523                     powers[num++] = PET_TWO_HANDS;
524                 } else if ((empty_hands(creature_ptr, FALSE) != EMPTY_HAND_NONE) && !has_melee_weapon(creature_ptr, INVEN_MAIN_HAND)
525                     && !has_melee_weapon(creature_ptr, INVEN_SUB_HAND)) {
526                     if (creature_ptr->pet_extra_flags & PF_TWO_HANDS) {
527                         power_desc[num] = _("格闘を行わない", "use one hand to control the pet you are riding");
528                     } else {
529                         power_desc[num] = _("格闘を行う", "use one hand for melee");
530                     }
531
532                     powers[num++] = PET_TWO_HANDS;
533                 }
534                 break;
535             }
536         }
537     }
538
539     if (!(repeat_pull(&i) && (i >= 0) && (i < num))) {
540         flag = FALSE;
541         redraw = FALSE;
542
543         if (use_menu) {
544             screen_save();
545             strnfmt(out_val, 78, _("(コマンド、ESC=終了) コマンドを選んでください:", "(Command, ESC=exit) Choose command from menu."));
546         } else {
547             strnfmt(out_val, 78, _("(コマンド %c-%c、'*'=一覧、ESC=終了) コマンドを選んでください:", "(Command %c-%c, *=List, ESC=exit) Select a command: "),
548                 I2A(0), I2A(num - 1));
549         }
550
551         choice = (always_show_list || use_menu) ? ESCAPE : 1;
552
553         /* Get a command from the user */
554         while (!flag) {
555             int ask = TRUE;
556
557             if (choice == ESCAPE)
558                 choice = ' ';
559             else if (!get_com(out_val, &choice, TRUE))
560                 break;
561
562             if (use_menu && (choice != ' ')) {
563                 switch (choice) {
564                 case '0':
565                     screen_load();
566                     return;
567
568                 case '8':
569                 case 'k':
570                 case 'K':
571                     menu_line += (num - 1);
572                     break;
573
574                 case '2':
575                 case 'j':
576                 case 'J':
577                     menu_line++;
578                     break;
579
580                 case '4':
581                 case 'h':
582                 case 'H':
583                     menu_line = 1;
584                     break;
585
586                 case '6':
587                 case 'l':
588                 case 'L':
589                     menu_line = num;
590                     break;
591
592                 case 'x':
593                 case 'X':
594                 case '\r':
595                 case '\n':
596                     i = menu_line - 1;
597                     ask = FALSE;
598                     break;
599                 }
600                 if (menu_line > num)
601                     menu_line -= num;
602             }
603
604             /* Request redraw */
605             if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask)) {
606                 /* Show the list */
607                 if (!redraw || use_menu) {
608                     byte y = 1, x = 0;
609                     PET_COMMAND_IDX ctr = 0;
610                     redraw = TRUE;
611                     if (!use_menu)
612                         screen_save();
613
614                     prt("", y++, x);
615
616                     /* Print list */
617                     for (ctr = 0; ctr < num; ctr++) {
618                         /* Letter/number for power selection */
619                         if (use_menu)
620                             sprintf(buf, "%c%s ", (ctr == mode) ? '*' : ' ', (ctr == (menu_line - 1)) ? _("》", "> ") : "  ");
621                         else
622                             sprintf(buf, "%c%c) ", (ctr == mode) ? '*' : ' ', I2A(ctr));
623
624                         strcat(buf, power_desc[ctr]);
625
626                         prt(buf, y + ctr, x);
627                     }
628
629                     prt("", y + MIN(ctr, 17), x);
630                 }
631
632                 /* Hide the list */
633                 else {
634                     /* Hide list */
635                     redraw = FALSE;
636                     screen_load();
637                 }
638
639                 /* Redo asking */
640                 continue;
641             }
642
643             if (!use_menu) {
644                 /* Note verify */
645                 ask = (isupper(choice));
646
647                 /* Lowercase */
648                 if (ask)
649                     choice = (char)tolower(choice);
650
651                 /* Extract request */
652                 i = (islower(choice) ? A2I(choice) : -1);
653             }
654
655             /* Totally Illegal */
656             if ((i < 0) || (i >= num)) {
657                 bell();
658                 continue;
659             }
660
661             /* Verify it */
662             if (ask) {
663                 /* Prompt */
664                 strnfmt(buf, 78, _("%sを使いますか? ", "Use %s? "), power_desc[i]);
665
666                 /* Belay that order */
667                 if (!get_check(buf))
668                     continue;
669             }
670
671             /* Stop the loop */
672             flag = TRUE;
673         }
674         if (redraw)
675             screen_load();
676
677         /* Abort if needed */
678         if (!flag) {
679             free_turn(creature_ptr);
680             return;
681         }
682
683         repeat_push(i);
684     }
685     switch (powers[i]) {
686     case PET_DISMISS: /* Dismiss pets */
687     {
688         /* Check pets (backwards) */
689         for (pet_ctr = creature_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--) {
690             /* Player has pet */
691             if (is_pet(&creature_ptr->current_floor_ptr->m_list[pet_ctr]))
692                 break;
693         }
694
695         if (!pet_ctr) {
696             msg_print(_("ペットがいない!", "You have no pets!"));
697             break;
698         }
699         do_cmd_pet_dismiss(creature_ptr);
700         (void)calculate_upkeep(creature_ptr);
701         break;
702     }
703     case PET_TARGET: {
704         project_length = -1;
705         if (!target_set(creature_ptr, TARGET_KILL))
706             creature_ptr->pet_t_m_idx = 0;
707         else {
708             grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[target_row][target_col];
709             if (g_ptr->m_idx && (creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx].ml)) {
710                 creature_ptr->pet_t_m_idx = creature_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx;
711                 creature_ptr->pet_follow_distance = PET_DESTROY_DIST;
712             } else
713                 creature_ptr->pet_t_m_idx = 0;
714         }
715         project_length = 0;
716
717         break;
718     }
719     /* Call pets */
720     case PET_STAY_CLOSE: {
721         creature_ptr->pet_follow_distance = PET_CLOSE_DIST;
722         creature_ptr->pet_t_m_idx = 0;
723         break;
724     }
725     /* "Follow Me" */
726     case PET_FOLLOW_ME: {
727         creature_ptr->pet_follow_distance = PET_FOLLOW_DIST;
728         creature_ptr->pet_t_m_idx = 0;
729         break;
730     }
731     /* "Seek and destoy" */
732     case PET_SEEK_AND_DESTROY: {
733         creature_ptr->pet_follow_distance = PET_DESTROY_DIST;
734         break;
735     }
736     /* "Give me space" */
737     case PET_ALLOW_SPACE: {
738         creature_ptr->pet_follow_distance = PET_SPACE_DIST;
739         break;
740     }
741     /* "Stay away" */
742     case PET_STAY_AWAY: {
743         creature_ptr->pet_follow_distance = PET_AWAY_DIST;
744         break;
745     }
746     /* flag - allow pets to open doors */
747     case PET_OPEN_DOORS: {
748         if (creature_ptr->pet_extra_flags & PF_OPEN_DOORS)
749             creature_ptr->pet_extra_flags &= ~(PF_OPEN_DOORS);
750         else
751             creature_ptr->pet_extra_flags |= (PF_OPEN_DOORS);
752         break;
753     }
754     /* flag - allow pets to pickup items */
755     case PET_TAKE_ITEMS: {
756         if (creature_ptr->pet_extra_flags & PF_PICKUP_ITEMS) {
757             creature_ptr->pet_extra_flags &= ~(PF_PICKUP_ITEMS);
758             for (pet_ctr = creature_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--) {
759                 m_ptr = &creature_ptr->current_floor_ptr->m_list[pet_ctr];
760
761                 if (is_pet(m_ptr)) {
762                     monster_drop_carried_objects(creature_ptr, m_ptr);
763                 }
764             }
765         } else
766             creature_ptr->pet_extra_flags |= (PF_PICKUP_ITEMS);
767
768         break;
769     }
770     /* flag - allow pets to teleport */
771     case PET_TELEPORT: {
772         if (creature_ptr->pet_extra_flags & PF_TELEPORT)
773             creature_ptr->pet_extra_flags &= ~(PF_TELEPORT);
774         else
775             creature_ptr->pet_extra_flags |= (PF_TELEPORT);
776         break;
777     }
778     /* flag - allow pets to cast attack spell */
779     case PET_ATTACK_SPELL: {
780         if (creature_ptr->pet_extra_flags & PF_ATTACK_SPELL)
781             creature_ptr->pet_extra_flags &= ~(PF_ATTACK_SPELL);
782         else
783             creature_ptr->pet_extra_flags |= (PF_ATTACK_SPELL);
784         break;
785     }
786     /* flag - allow pets to cast attack spell */
787     case PET_SUMMON_SPELL: {
788         if (creature_ptr->pet_extra_flags & PF_SUMMON_SPELL)
789             creature_ptr->pet_extra_flags &= ~(PF_SUMMON_SPELL);
790         else
791             creature_ptr->pet_extra_flags |= (PF_SUMMON_SPELL);
792         break;
793     }
794     /* flag - allow pets to cast attack spell */
795     case PET_BALL_SPELL: {
796         if (creature_ptr->pet_extra_flags & PF_BALL_SPELL)
797             creature_ptr->pet_extra_flags &= ~(PF_BALL_SPELL);
798         else
799             creature_ptr->pet_extra_flags |= (PF_BALL_SPELL);
800         break;
801     }
802
803     case PET_RIDING: {
804         (void)do_cmd_riding(creature_ptr, FALSE);
805         break;
806     }
807
808     case PET_NAME: {
809         do_name_pet(creature_ptr);
810         break;
811     }
812
813     case PET_TWO_HANDS: {
814         if (creature_ptr->pet_extra_flags & PF_TWO_HANDS)
815             creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
816         else
817             creature_ptr->pet_extra_flags |= (PF_TWO_HANDS);
818         creature_ptr->update |= (PU_BONUS);
819         handle_stuff(creature_ptr);
820         break;
821     }
822     }
823 }