OSDN Git Service

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