OSDN Git Service

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