OSDN Git Service

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