OSDN Git Service

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