OSDN Git Service

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