OSDN Git Service

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