OSDN Git Service

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