OSDN Git Service

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