OSDN Git Service

[Refactor] #39970 Moved world.c/h to world/
[hengband/hengband.git] / src / cmd / cmd-pet.c
1 #include "angband.h"
2 #include "core/stuff-handler.h"
3 #include "util.h"
4
5 #include "io/write-diary.h"
6 #include "cmd/cmd-dump.h"
7 #include "floor.h"
8 #include "grid.h"
9 #include "melee.h"
10 #include "sort.h"
11 #include "player-move.h"
12 #include "player-status.h"
13 #include "player-effects.h"
14 #include "player-skill.h"
15 #include "player-class.h"
16 #include "player-damage.h"
17 #include "object-hook.h"
18 #include "monster.h"
19 #include "monster-status.h"
20 #include "cmd-pet.h"
21 #include "cmd-basic.h"
22 #include "view/display-main-window.h"
23 #include "targeting.h"
24 #include "world/world.h"
25 #include "effect/spells-effect-util.h"
26
27 int total_friends = 0;
28
29 /*!
30 * @brief プレイヤーの騎乗/下馬処理判定
31 * @param g_ptr プレイヤーの移動先マスの構造体参照ポインタ
32 * @param now_riding TRUEなら下馬処理、FALSEならば騎乗処理
33 * @return 可能ならばTRUEを返す
34 */
35 bool player_can_ride_aux(player_type *creature_ptr, grid_type *g_ptr, bool now_riding)
36 {
37         bool p_can_enter;
38         bool old_character_xtra = current_world_ptr->character_xtra;
39         MONSTER_IDX old_riding = creature_ptr->riding;
40         bool old_riding_ryoute = creature_ptr->riding_ryoute;
41         bool old_old_riding_ryoute = creature_ptr->old_riding_ryoute;
42         bool old_pf_ryoute = (creature_ptr->pet_extra_flags & PF_TWO_HANDS) ? TRUE : FALSE;
43
44         /* Hack -- prevent "icky" message */
45         current_world_ptr->character_xtra = TRUE;
46
47         if (now_riding) creature_ptr->riding = g_ptr->m_idx;
48         else
49         {
50                 creature_ptr->riding = 0;
51                 creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
52                 creature_ptr->riding_ryoute = creature_ptr->old_riding_ryoute = FALSE;
53         }
54
55         creature_ptr->update |= PU_BONUS;
56         handle_stuff(creature_ptr);
57
58         p_can_enter = player_can_enter(creature_ptr, g_ptr->feat, CEM_P_CAN_ENTER_PATTERN);
59
60         creature_ptr->riding = old_riding;
61         if (old_pf_ryoute) creature_ptr->pet_extra_flags |= (PF_TWO_HANDS);
62         else creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
63         creature_ptr->riding_ryoute = old_riding_ryoute;
64         creature_ptr->old_riding_ryoute = old_old_riding_ryoute;
65
66         creature_ptr->update |= PU_BONUS;
67         handle_stuff(creature_ptr);
68
69         current_world_ptr->character_xtra = old_character_xtra;
70
71         return p_can_enter;
72 }
73
74 /*!
75 * @brief ペットを開放するコマンドのメインルーチン
76 * @return なし
77 */
78 void do_cmd_pet_dismiss(player_type *creature_ptr)
79 {
80         monster_type *m_ptr;
81         bool all_pets = FALSE;
82         MONSTER_IDX pet_ctr;
83         int i;
84         int Dismissed = 0;
85
86         MONSTER_IDX *who;
87         u16b dummy_why;
88         int max_pet = 0;
89         bool_hack cu, cv;
90
91         cu = Term->scr->cu;
92         cv = Term->scr->cv;
93         Term->scr->cu = 0;
94         Term->scr->cv = 1;
95
96         /* Allocate the "who" array */
97         C_MAKE(who, current_world_ptr->max_m_idx, MONSTER_IDX);
98
99         /* Process the monsters (backwards) */
100         for (pet_ctr = creature_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--)
101         {
102                 if (is_pet(&creature_ptr->current_floor_ptr->m_list[pet_ctr]))
103                         who[max_pet++] = pet_ctr;
104         }
105
106         ang_sort(who, &dummy_why, max_pet, ang_sort_comp_pet_dismiss, ang_sort_swap_hook);
107
108         /* Process the monsters (backwards) */
109         for (i = 0; i < max_pet; i++)
110         {
111                 bool delete_this;
112                 GAME_TEXT friend_name[MAX_NLEN];
113                 bool kakunin;
114
115                 pet_ctr = who[i];
116                 m_ptr = &creature_ptr->current_floor_ptr->m_list[pet_ctr];
117
118                 delete_this = FALSE;
119                 kakunin = ((pet_ctr == creature_ptr->riding) || (m_ptr->nickname));
120                 monster_desc(creature_ptr, friend_name, m_ptr, MD_ASSUME_VISIBLE);
121
122                 if (!all_pets)
123                 {
124                         /* Hack -- health bar for this monster */
125                         health_track(creature_ptr, pet_ctr);
126                         handle_stuff(creature_ptr);
127
128                         msg_format(_("%sを放しますか? [Yes/No/Unnamed (%d体)]", "Dismiss %s? [Yes/No/Unnamed (%d remain)]"), friend_name, max_pet - i);
129
130                         if (m_ptr->ml)
131                                 move_cursor_relative(m_ptr->fy, m_ptr->fx);
132
133                         while (TRUE)
134                         {
135                                 char ch = inkey();
136
137                                 if (ch == 'Y' || ch == 'y')
138                                 {
139                                         delete_this = TRUE;
140
141                                         if (kakunin)
142                                         {
143                                                 msg_format(_("本当によろしいですか? (%s) ", "Are you sure? (%s) "), friend_name);
144                                                 ch = inkey();
145                                                 if (ch != 'Y' && ch != 'y')
146                                                         delete_this = FALSE;
147                                         }
148                                         break;
149                                 }
150
151                                 if (ch == 'U' || ch == 'u')
152                                 {
153                                         all_pets = TRUE;
154                                         break;
155                                 }
156
157                                 if (ch == ESCAPE || ch == 'N' || ch == 'n')
158                                         break;
159
160                                 bell();
161                         }
162                 }
163
164                 if ((all_pets && !kakunin) || (!all_pets && delete_this))
165                 {
166                         if (record_named_pet && m_ptr->nickname)
167                         {
168                                 GAME_TEXT m_name[MAX_NLEN];
169
170                                 monster_desc(creature_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
171                                 exe_write_diary(creature_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_DISMISS, m_name);
172                         }
173
174                         if (pet_ctr == creature_ptr->riding)
175                         {
176                                 msg_format(_("%sから降りた。", "You have got off %s. "), friend_name);
177
178                                 creature_ptr->riding = 0;
179
180                                 creature_ptr->update |= (PU_MONSTERS);
181                                 creature_ptr->redraw |= (PR_EXTRA | PR_UHEALTH);
182                         }
183
184                         /* HACK : Add the line to message buffer */
185                         msg_format(_("%s を放した。", "Dismissed %s."), friend_name);
186                         creature_ptr->update |= (PU_BONUS);
187                         creature_ptr->window |= (PW_MESSAGE);
188
189                         delete_monster_idx(creature_ptr, pet_ctr);
190                         Dismissed++;
191                 }
192         }
193
194         Term->scr->cu = cu;
195         Term->scr->cv = cv;
196         Term_fresh();
197
198         C_KILL(who, current_world_ptr->max_m_idx, MONSTER_IDX);
199
200 #ifdef JP
201         msg_format("%d 体のペットを放しました。", Dismissed);
202 #else
203         msg_format("You have dismissed %d pet%s.", Dismissed,
204                 (Dismissed == 1 ? "" : "s"));
205 #endif
206         if (Dismissed == 0 && all_pets)
207                 msg_print(_("'U'nnamed は、乗馬以外の名前のないペットだけを全て解放します。", "'U'nnamed means all your pets except named pets and your mount."));
208
209         handle_stuff(creature_ptr);
210 }
211
212
213
214 /*!
215 * @brief ペットから騎乗/下馬するコマンドのメインルーチン /
216 * @param force 強制的に騎乗/下馬するならばTRUE
217 * @return 騎乗/下馬できたらTRUE
218 */
219 bool do_cmd_riding(player_type *creature_ptr, bool force)
220 {
221         POSITION x, y;
222         DIRECTION dir = 0;
223         grid_type *g_ptr;
224         monster_type *m_ptr;
225
226         if (!get_direction(creature_ptr, &dir, FALSE, FALSE)) return FALSE;
227         y = creature_ptr->y + ddy[dir];
228         x = creature_ptr->x + ddx[dir];
229         g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
230
231         if (creature_ptr->special_defense & KATA_MUSOU) set_action(creature_ptr, ACTION_NONE);
232
233         if (creature_ptr->riding)
234         {
235                 /* Skip non-empty grids */
236                 if (!player_can_ride_aux(creature_ptr, g_ptr, FALSE))
237                 {
238                         msg_print(_("そちらには降りられません。", "You cannot go that direction."));
239                         return FALSE;
240                 }
241
242                 if (!pattern_seq(creature_ptr, creature_ptr->y, creature_ptr->x, y, x)) return FALSE;
243
244                 if (g_ptr->m_idx)
245                 {
246                         take_turn(creature_ptr, 100);
247
248                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
249
250                         py_attack(creature_ptr, y, x, 0);
251                         return FALSE;
252                 }
253
254                 creature_ptr->riding = 0;
255                 creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
256                 creature_ptr->riding_ryoute = creature_ptr->old_riding_ryoute = FALSE;
257         }
258         else
259         {
260                 if (cmd_limit_confused(creature_ptr)) return FALSE;
261
262                 m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
263
264                 if (!g_ptr->m_idx || !m_ptr->ml)
265                 {
266                         msg_print(_("その場所にはモンスターはいません。", "There is no monster here."));
267                         return FALSE;
268                 }
269                 if (!is_pet(m_ptr) && !force)
270                 {
271                         msg_print(_("そのモンスターはペットではありません。", "That monster is not a pet."));
272                         return FALSE;
273                 }
274                 if (!(r_info[m_ptr->r_idx].flags7 & RF7_RIDING))
275                 {
276                         msg_print(_("そのモンスターには乗れなさそうだ。", "This monster doesn't seem suitable for riding."));
277                         return FALSE;
278                 }
279
280                 if (!pattern_seq(creature_ptr, creature_ptr->y, creature_ptr->x, y, x)) return FALSE;
281
282                 if (!player_can_ride_aux(creature_ptr, g_ptr, TRUE))
283                 {
284                         /* Feature code (applying "mimic" field) */
285                         feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
286 #ifdef JP
287                         msg_format("そのモンスターは%sの%sにいる。", f_name + f_ptr->name,
288                                 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
289                                 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE))) ?
290                                 "中" : "上");
291 #else
292                         msg_format("This monster is %s the %s.",
293                                 ((!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) ||
294                                 (!have_flag(f_ptr->flags, FF_LOS) && !have_flag(f_ptr->flags, FF_TREE))) ?
295                                 "in" : "on", f_name + f_ptr->name);
296 #endif
297
298                         return FALSE;
299                 }
300                 if (r_info[m_ptr->r_idx].level > randint1((creature_ptr->skill_exp[GINOU_RIDING] / 50 + creature_ptr->lev / 2 + 20)))
301                 {
302                         msg_print(_("うまく乗れなかった。", "You failed to ride."));
303                         take_turn(creature_ptr, 100);
304                         return FALSE;
305                 }
306
307                 if (MON_CSLEEP(m_ptr))
308                 {
309                         GAME_TEXT m_name[MAX_NLEN];
310                         monster_desc(creature_ptr, m_name, m_ptr, 0);
311                         (void)set_monster_csleep(creature_ptr, g_ptr->m_idx, 0);
312                         msg_format(_("%sを起こした。", "You have woken %s up."), m_name);
313                 }
314
315                 if (creature_ptr->action == ACTION_KAMAE) set_action(creature_ptr, ACTION_NONE);
316
317                 creature_ptr->riding = g_ptr->m_idx;
318
319                 /* Hack -- remove tracked monster */
320                 if (creature_ptr->riding == creature_ptr->health_who) health_track(creature_ptr, 0);
321         }
322
323         take_turn(creature_ptr, 100);
324
325         /* Mega-Hack -- Forget the view and lite */
326         creature_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
327         creature_ptr->update |= (PU_BONUS);
328         creature_ptr->redraw |= (PR_MAP | PR_EXTRA);
329         creature_ptr->redraw |= (PR_UHEALTH);
330
331         (void)move_player_effect(creature_ptr, y, x, MPE_HANDLE_STUFF | MPE_ENERGY_USE | MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);
332
333         return TRUE;
334 }
335
336 /*!
337 * @brief ペットに名前をつけるコマンドのメインルーチン
338 * @return なし
339 */
340 static void do_name_pet(player_type *creature_ptr)
341 {
342         monster_type *m_ptr;
343         char out_val[20];
344         GAME_TEXT m_name[MAX_NLEN];
345         bool old_name = FALSE;
346         bool old_target_pet = target_pet;
347
348         target_pet = TRUE;
349         if (!target_set(creature_ptr, TARGET_KILL))
350         {
351                 target_pet = old_target_pet;
352                 return;
353         }
354
355         target_pet = old_target_pet;
356
357         if (creature_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx)
358         {
359                 m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx];
360
361                 if (!is_pet(m_ptr))
362                 {
363                         msg_print(_("そのモンスターはペットではない。", "This monster is not a pet."));
364                         return;
365                 }
366                 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
367                 {
368                         msg_print(_("そのモンスターの名前は変えられない!", "You cannot change name of this monster!"));
369                         return;
370                 }
371                 monster_desc(creature_ptr, m_name, m_ptr, 0);
372
373                 msg_format(_("%sに名前をつける。", "Name %s."), m_name);
374                 msg_print(NULL);
375
376                 /* Start with nothing */
377                 strcpy(out_val, "");
378
379                 /* Use old inscription */
380                 if (m_ptr->nickname)
381                 {
382                         /* Start with the old inscription */
383                         strcpy(out_val, quark_str(m_ptr->nickname));
384                         old_name = TRUE;
385                 }
386
387                 /* Get a new inscription (possibly empty) */
388                 if (get_string(_("名前: ", "Name: "), out_val, 15))
389                 {
390                         if (out_val[0])
391                         {
392                                 /* Save the inscription */
393                                 m_ptr->nickname = quark_add(out_val);
394                                 if (record_named_pet)
395                                 {
396                                         monster_desc(creature_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
397                                         exe_write_diary(creature_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_NAME, m_name);
398                                 }
399                         }
400                         else
401                         {
402                                 if (record_named_pet && old_name)
403                                 {
404                                         monster_desc(creature_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
405                                         exe_write_diary(creature_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_UNNAME, m_name);
406                                 }
407                                 m_ptr->nickname = 0;
408                         }
409                 }
410         }
411 }
412
413
414 /*!
415 * @brief ペットに関するコマンドリストのメインルーチン /
416 * Issue a pet command
417 * @return なし
418 */
419 void do_cmd_pet(player_type *creature_ptr)
420 {
421         COMMAND_CODE i = 0;
422         int                     num;
423         int                     powers[36];
424         concptr                 power_desc[36];
425         bool                    flag, redraw;
426         char                    choice;
427         char                    out_val[160];
428         int                     pet_ctr;
429         monster_type    *m_ptr;
430
431         PET_COMMAND_IDX mode = 0;
432
433         char buf[160];
434         char target_buf[160];
435
436         int menu_line = use_menu ? 1 : 0;
437
438         num = 0;
439
440         if (creature_ptr->wild_mode) return;
441
442         power_desc[num] = _("ペットを放す", "dismiss pets");
443         powers[num++] = PET_DISMISS;
444
445 #ifdef JP
446         sprintf(target_buf, "ペットのターゲットを指定 (現在:%s)",
447                 (creature_ptr->pet_t_m_idx ? (creature_ptr->image ? "何か奇妙な物" : (r_name + r_info[creature_ptr->current_floor_ptr->m_list[creature_ptr->pet_t_m_idx].ap_r_idx].name)) : "指定なし"));
448 #else
449         sprintf(target_buf, "specify a target of pet (now:%s)",
450                 (creature_ptr->pet_t_m_idx ? (creature_ptr->image ? "something strange" : (r_name + r_info[creature_ptr->current_floor_ptr->m_list[creature_ptr->pet_t_m_idx].ap_r_idx].name)) : "nothing"));
451 #endif
452         power_desc[num] = target_buf;
453         powers[num++] = PET_TARGET;
454         power_desc[num] = _("近くにいろ", "stay close");
455
456         if (creature_ptr->pet_follow_distance == PET_CLOSE_DIST) mode = num;
457         powers[num++] = PET_STAY_CLOSE;
458         power_desc[num] = _("ついて来い", "follow me");
459
460         if (creature_ptr->pet_follow_distance == PET_FOLLOW_DIST) mode = num;
461         powers[num++] = PET_FOLLOW_ME;
462         power_desc[num] = _("敵を見つけて倒せ", "seek and destroy");
463
464         if (creature_ptr->pet_follow_distance == PET_DESTROY_DIST) mode = num;
465         powers[num++] = PET_SEEK_AND_DESTROY;
466         power_desc[num] = _("少し離れていろ", "give me space");
467
468         if (creature_ptr->pet_follow_distance == PET_SPACE_DIST) mode = num;
469         powers[num++] = PET_ALLOW_SPACE;
470         power_desc[num] = _("離れていろ", "stay away");
471
472         if (creature_ptr->pet_follow_distance == PET_AWAY_DIST) mode = num;
473         powers[num++] = PET_STAY_AWAY;
474
475         if (creature_ptr->pet_extra_flags & PF_OPEN_DOORS)
476         {
477                 power_desc[num] = _("ドアを開ける (現在:ON)", "pets open doors (now On)");
478         }
479         else
480         {
481                 power_desc[num] = _("ドアを開ける (現在:OFF)", "pets open doors (now Off)");
482         }
483         powers[num++] = PET_OPEN_DOORS;
484
485         if (creature_ptr->pet_extra_flags & PF_PICKUP_ITEMS)
486         {
487                 power_desc[num] = _("アイテムを拾う (現在:ON)", "pets pick up items (now On)");
488         }
489         else
490         {
491                 power_desc[num] = _("アイテムを拾う (現在:OFF)", "pets pick up items (now Off)");
492         }
493         powers[num++] = PET_TAKE_ITEMS;
494
495         if (creature_ptr->pet_extra_flags & PF_TELEPORT)
496         {
497                 power_desc[num] = _("テレポート系魔法を使う (現在:ON)", "allow teleport (now On)");
498         }
499         else
500         {
501                 power_desc[num] = _("テレポート系魔法を使う (現在:OFF)", "allow teleport (now Off)");
502         }
503         powers[num++] = PET_TELEPORT;
504
505         if (creature_ptr->pet_extra_flags & PF_ATTACK_SPELL)
506         {
507                 power_desc[num] = _("攻撃魔法を使う (現在:ON)", "allow cast attack spell (now On)");
508         }
509         else
510         {
511                 power_desc[num] = _("攻撃魔法を使う (現在:OFF)", "allow cast attack spell (now Off)");
512         }
513         powers[num++] = PET_ATTACK_SPELL;
514
515         if (creature_ptr->pet_extra_flags & PF_SUMMON_SPELL)
516         {
517                 power_desc[num] = _("召喚魔法を使う (現在:ON)", "allow cast summon spell (now On)");
518         }
519         else
520         {
521                 power_desc[num] = _("召喚魔法を使う (現在:OFF)", "allow cast summon spell (now Off)");
522         }
523         powers[num++] = PET_SUMMON_SPELL;
524
525         if (creature_ptr->pet_extra_flags & PF_BALL_SPELL)
526         {
527                 power_desc[num] = _("プレイヤーを巻き込む範囲魔法を使う (現在:ON)", "allow involve player in area spell (now On)");
528         }
529         else
530         {
531                 power_desc[num] = _("プレイヤーを巻き込む範囲魔法を使う (現在:OFF)", "allow involve player in area spell (now Off)");
532         }
533         powers[num++] = PET_BALL_SPELL;
534
535         if (creature_ptr->riding)
536         {
537                 power_desc[num] = _("ペットから降りる", "get off a pet");
538         }
539         else
540         {
541                 power_desc[num] = _("ペットに乗る", "ride a pet");
542         }
543         powers[num++] = PET_RIDING;
544         power_desc[num] = _("ペットに名前をつける", "name pets");
545         powers[num++] = PET_NAME;
546
547         if (creature_ptr->riding)
548         {
549                 if ((creature_ptr->migite && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_LARM) &&
550                         object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_RARM])) ||
551                         (creature_ptr->hidarite && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_RARM) &&
552                                 object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_LARM])))
553                 {
554                         if (creature_ptr->pet_extra_flags & PF_TWO_HANDS)
555                         {
556                                 power_desc[num] = _("武器を片手で持つ", "use one hand to control the pet you are riding");
557                         }
558                         else
559                         {
560                                 power_desc[num] = _("武器を両手で持つ", "use both hands for a weapon");
561                         }
562
563                         powers[num++] = PET_TWO_HANDS;
564                 }
565                 else
566                 {
567                         switch (creature_ptr->pclass)
568                         {
569                         case CLASS_MONK:
570                         case CLASS_FORCETRAINER:
571                         case CLASS_BERSERKER:
572                                 if (empty_hands(creature_ptr, FALSE) == (EMPTY_HAND_RARM | EMPTY_HAND_LARM))
573                                 {
574                                         if (creature_ptr->pet_extra_flags & PF_TWO_HANDS)
575                                         {
576                                                 power_desc[num] = _("片手で格闘する", "use one hand to control the pet you are riding");
577                                         }
578                                         else
579                                         {
580                                                 power_desc[num] = _("両手で格闘する", "use both hands for melee");
581                                         }
582
583                                         powers[num++] = PET_TWO_HANDS;
584                                 }
585                                 else if ((empty_hands(creature_ptr, FALSE) != EMPTY_HAND_NONE) && !has_melee_weapon(creature_ptr, INVEN_RARM) && !has_melee_weapon(creature_ptr, INVEN_LARM))
586                                 {
587                                         if (creature_ptr->pet_extra_flags & PF_TWO_HANDS)
588                                         {
589                                                 power_desc[num] = _("格闘を行わない", "use one hand to control the pet you are riding");
590                                         }
591                                         else
592                                         {
593                                                 power_desc[num] = _("格闘を行う", "use one hand for melee");
594                                         }
595
596                                         powers[num++] = PET_TWO_HANDS;
597                                 }
598                                 break;
599                         }
600                 }
601         }
602
603         if (!(repeat_pull(&i) && (i >= 0) && (i < num)))
604         {
605                 flag = FALSE;
606                 redraw = FALSE;
607
608                 if (use_menu)
609                 {
610                         screen_save();
611                         strnfmt(out_val, 78, _("(コマンド、ESC=終了) コマンドを選んでください:", "(Command, ESC=exit) Choose command from menu."));
612                 }
613                 else
614                 {
615                         strnfmt(out_val, 78,
616                                 _("(コマンド %c-%c、'*'=一覧、ESC=終了) コマンドを選んでください:", "(Command %c-%c, *=List, ESC=exit) Select a command: "),
617                                 I2A(0), I2A(num - 1));
618                 }
619
620                 choice = (always_show_list || use_menu) ? ESCAPE : 1;
621
622                 /* Get a command from the user */
623                 while (!flag)
624                 {
625                         int ask = TRUE;
626
627                         if (choice == ESCAPE) choice = ' ';
628                         else if (!get_com(out_val, &choice, TRUE)) break;
629
630                         if (use_menu && (choice != ' '))
631                         {
632                                 switch (choice)
633                                 {
634                                 case '0':
635                                         screen_load();
636                                         return;
637
638                                 case '8':
639                                 case 'k':
640                                 case 'K':
641                                         menu_line += (num - 1);
642                                         break;
643
644                                 case '2':
645                                 case 'j':
646                                 case 'J':
647                                         menu_line++;
648                                         break;
649
650                                 case '4':
651                                 case 'h':
652                                 case 'H':
653                                         menu_line = 1;
654                                         break;
655
656                                 case '6':
657                                 case 'l':
658                                 case 'L':
659                                         menu_line = num;
660                                         break;
661
662                                 case 'x':
663                                 case 'X':
664                                 case '\r':
665                                 case '\n':
666                                         i = menu_line - 1;
667                                         ask = FALSE;
668                                         break;
669                                 }
670                                 if (menu_line > num) menu_line -= num;
671                         }
672
673                         /* Request redraw */
674                         if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
675                         {
676                                 /* Show the list */
677                                 if (!redraw || use_menu)
678                                 {
679                                         byte y = 1, x = 0;
680                                         PET_COMMAND_IDX ctr = 0;
681                                         redraw = TRUE;
682                                         if (!use_menu) screen_save();
683
684                                         prt("", y++, x);
685
686                                         /* Print list */
687                                         for (ctr = 0; ctr < num; ctr++)
688                                         {
689                                                 /* Letter/number for power selection */
690                                                 if (use_menu)
691                                                         sprintf(buf, "%c%s ", (ctr == mode) ? '*' : ' ', (ctr == (menu_line - 1)) ? _("》", "> ") : "  ");
692                                                 else
693                                                         sprintf(buf, "%c%c) ", (ctr == mode) ? '*' : ' ', I2A(ctr));
694
695                                                 strcat(buf, power_desc[ctr]);
696
697                                                 prt(buf, y + ctr, x);
698                                         }
699
700                                         prt("", y + MIN(ctr, 17), x);
701                                 }
702
703                                 /* Hide the list */
704                                 else
705                                 {
706                                         /* Hide list */
707                                         redraw = FALSE;
708                                         screen_load();
709                                 }
710
711                                 /* Redo asking */
712                                 continue;
713                         }
714
715                         if (!use_menu)
716                         {
717                                 /* Note verify */
718                                 ask = (isupper(choice));
719
720                                 /* Lowercase */
721                                 if (ask) choice = (char)tolower(choice);
722
723                                 /* Extract request */
724                                 i = (islower(choice) ? A2I(choice) : -1);
725                         }
726
727                         /* Totally Illegal */
728                         if ((i < 0) || (i >= num))
729                         {
730                                 bell();
731                                 continue;
732                         }
733
734                         /* Verify it */
735                         if (ask)
736                         {
737                                 /* Prompt */
738                                 strnfmt(buf, 78, _("%sを使いますか? ", "Use %s? "), power_desc[i]);
739
740                                 /* Belay that order */
741                                 if (!get_check(buf)) continue;
742                         }
743
744                         /* Stop the loop */
745                         flag = TRUE;
746                 }
747                 if (redraw) screen_load();
748
749                 /* Abort if needed */
750                 if (!flag)
751                 {
752                         free_turn(creature_ptr);
753                         return;
754                 }
755
756                 repeat_push(i);
757         }
758         switch (powers[i])
759         {
760         case PET_DISMISS: /* Dismiss pets */
761         {
762                 /* Check pets (backwards) */
763                 for (pet_ctr = creature_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--)
764                 {
765                         /* Player has pet */
766                         if (is_pet(&creature_ptr->current_floor_ptr->m_list[pet_ctr])) break;
767                 }
768
769                 if (!pet_ctr)
770                 {
771                         msg_print(_("ペットがいない!", "You have no pets!"));
772                         break;
773                 }
774                 do_cmd_pet_dismiss(creature_ptr);
775                 (void)calculate_upkeep(creature_ptr);
776                 break;
777         }
778         case PET_TARGET:
779         {
780                 project_length = -1;
781                 if (!target_set(creature_ptr, TARGET_KILL)) creature_ptr->pet_t_m_idx = 0;
782                 else
783                 {
784                         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[target_row][target_col];
785                         if (g_ptr->m_idx && (creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx].ml))
786                         {
787                                 creature_ptr->pet_t_m_idx = creature_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx;
788                                 creature_ptr->pet_follow_distance = PET_DESTROY_DIST;
789                         }
790                         else creature_ptr->pet_t_m_idx = 0;
791                 }
792                 project_length = 0;
793
794                 break;
795         }
796         /* Call pets */
797         case PET_STAY_CLOSE:
798         {
799                 creature_ptr->pet_follow_distance = PET_CLOSE_DIST;
800                 creature_ptr->pet_t_m_idx = 0;
801                 break;
802         }
803         /* "Follow Me" */
804         case PET_FOLLOW_ME:
805         {
806                 creature_ptr->pet_follow_distance = PET_FOLLOW_DIST;
807                 creature_ptr->pet_t_m_idx = 0;
808                 break;
809         }
810         /* "Seek and destoy" */
811         case PET_SEEK_AND_DESTROY:
812         {
813                 creature_ptr->pet_follow_distance = PET_DESTROY_DIST;
814                 break;
815         }
816         /* "Give me space" */
817         case PET_ALLOW_SPACE:
818         {
819                 creature_ptr->pet_follow_distance = PET_SPACE_DIST;
820                 break;
821         }
822         /* "Stay away" */
823         case PET_STAY_AWAY:
824         {
825                 creature_ptr->pet_follow_distance = PET_AWAY_DIST;
826                 break;
827         }
828         /* flag - allow pets to open doors */
829         case PET_OPEN_DOORS:
830         {
831                 if (creature_ptr->pet_extra_flags & PF_OPEN_DOORS) creature_ptr->pet_extra_flags &= ~(PF_OPEN_DOORS);
832                 else creature_ptr->pet_extra_flags |= (PF_OPEN_DOORS);
833                 break;
834         }
835         /* flag - allow pets to pickup items */
836         case PET_TAKE_ITEMS:
837         {
838                 if (creature_ptr->pet_extra_flags & PF_PICKUP_ITEMS)
839                 {
840                         creature_ptr->pet_extra_flags &= ~(PF_PICKUP_ITEMS);
841                         for (pet_ctr = creature_ptr->current_floor_ptr->m_max - 1; pet_ctr >= 1; pet_ctr--)
842                         {
843                                 m_ptr = &creature_ptr->current_floor_ptr->m_list[pet_ctr];
844
845                                 if (is_pet(m_ptr))
846                                 {
847                                         monster_drop_carried_objects(creature_ptr, m_ptr);
848                                 }
849                         }
850                 }
851                 else creature_ptr->pet_extra_flags |= (PF_PICKUP_ITEMS);
852
853                 break;
854         }
855         /* flag - allow pets to teleport */
856         case PET_TELEPORT:
857         {
858                 if (creature_ptr->pet_extra_flags & PF_TELEPORT) creature_ptr->pet_extra_flags &= ~(PF_TELEPORT);
859                 else creature_ptr->pet_extra_flags |= (PF_TELEPORT);
860                 break;
861         }
862         /* flag - allow pets to cast attack spell */
863         case PET_ATTACK_SPELL:
864         {
865                 if (creature_ptr->pet_extra_flags & PF_ATTACK_SPELL) creature_ptr->pet_extra_flags &= ~(PF_ATTACK_SPELL);
866                 else creature_ptr->pet_extra_flags |= (PF_ATTACK_SPELL);
867                 break;
868         }
869         /* flag - allow pets to cast attack spell */
870         case PET_SUMMON_SPELL:
871         {
872                 if (creature_ptr->pet_extra_flags & PF_SUMMON_SPELL) creature_ptr->pet_extra_flags &= ~(PF_SUMMON_SPELL);
873                 else creature_ptr->pet_extra_flags |= (PF_SUMMON_SPELL);
874                 break;
875         }
876         /* flag - allow pets to cast attack spell */
877         case PET_BALL_SPELL:
878         {
879                 if (creature_ptr->pet_extra_flags & PF_BALL_SPELL) creature_ptr->pet_extra_flags &= ~(PF_BALL_SPELL);
880                 else creature_ptr->pet_extra_flags |= (PF_BALL_SPELL);
881                 break;
882         }
883
884         case PET_RIDING:
885         {
886                 (void)do_cmd_riding(creature_ptr, FALSE);
887                 break;
888         }
889
890         case PET_NAME:
891         {
892                 do_name_pet(creature_ptr);
893                 break;
894         }
895
896         case PET_TWO_HANDS:
897         {
898                 if (creature_ptr->pet_extra_flags & PF_TWO_HANDS) creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
899                 else creature_ptr->pet_extra_flags |= (PF_TWO_HANDS);
900                 creature_ptr->update |= (PU_BONUS);
901                 handle_stuff(creature_ptr);
902                 break;
903         }
904         }
905 }
906
907
908 /*!
909 * @brief プレイヤーの落馬判定処理
910 * @param dam 落馬判定を発した際に受けたダメージ量
911 * @param force TRUEならば強制的に落馬する
912 * @return 実際に落馬したらTRUEを返す
913 */
914 bool rakuba(player_type *creature_ptr, HIT_POINT dam, bool force)
915 {
916         DIRECTION i;
917         POSITION y, x, oy, ox, sy = 0, sx = 0;
918         int sn = 0;
919         GAME_TEXT m_name[MAX_NLEN];
920         monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
921         monster_race *r_ptr = &r_info[m_ptr->r_idx];
922         bool fall_dam = FALSE;
923
924         if (!creature_ptr->riding) return FALSE;
925         if (creature_ptr->wild_mode) return FALSE;
926
927         if (dam >= 0 || force)
928         {
929                 if (!force)
930                 {
931                         int cur = creature_ptr->skill_exp[GINOU_RIDING];
932                         int max = s_info[creature_ptr->pclass].s_max[GINOU_RIDING];
933                         int ridinglevel = r_ptr->level;
934
935                         /* 落馬のしやすさ */
936                         int rakubalevel = r_ptr->level;
937                         if (creature_ptr->riding_ryoute) rakubalevel += 20;
938
939                         if ((cur < max) && (max > 1000) &&
940                                 (dam / 2 + ridinglevel) > (cur / 30 + 10))
941                         {
942                                 int inc = 0;
943
944                                 if (ridinglevel > (cur / 100 + 15))
945                                         inc += 1 + (ridinglevel - cur / 100 - 15);
946                                 else
947                                         inc += 1;
948
949                                 creature_ptr->skill_exp[GINOU_RIDING] = MIN(max, cur + inc);
950                         }
951
952                         /* レベルの低い乗馬からは落馬しにくい */
953                         if (randint0(dam / 2 + rakubalevel * 2) < cur / 30 + 10)
954                         {
955                                 if ((((creature_ptr->pclass == CLASS_BEASTMASTER) || (creature_ptr->pclass == CLASS_CAVALRY)) && !creature_ptr->riding_ryoute) || !one_in_(creature_ptr->lev*(creature_ptr->riding_ryoute ? 2 : 3) + 30))
956                                 {
957                                         return FALSE;
958                                 }
959                         }
960                 }
961
962                 /* Check around the player */
963                 for (i = 0; i < 8; i++)
964                 {
965                         grid_type *g_ptr;
966
967                         y = creature_ptr->y + ddy_ddd[i];
968                         x = creature_ptr->x + ddx_ddd[i];
969
970                         g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
971
972                         if (g_ptr->m_idx) continue;
973
974                         /* Skip non-empty grids */
975                         if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !cave_have_flag_grid(g_ptr, FF_CAN_FLY))
976                         {
977                                 if (!player_can_ride_aux(creature_ptr, g_ptr, FALSE)) continue;
978                         }
979
980                         if (cave_have_flag_grid(g_ptr, FF_PATTERN)) continue;
981
982                         /* Count "safe" grids */
983                         sn++;
984
985                         /* Randomize choice */
986                         if (randint0(sn) > 0) continue;
987
988                         /* Save the safe location */
989                         sy = y; sx = x;
990                 }
991                 if (!sn)
992                 {
993                         monster_desc(creature_ptr, m_name, m_ptr, 0);
994                         msg_format(_("%sから振り落とされそうになって、壁にぶつかった。", "You have nearly fallen from %s, but bumped into wall."), m_name);
995                         take_hit(creature_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("壁への衝突", "bumping into wall"), -1);
996                         return FALSE;
997                 }
998
999                 oy = creature_ptr->y;
1000                 ox = creature_ptr->x;
1001
1002                 creature_ptr->y = sy;
1003                 creature_ptr->x = sx;
1004
1005                 /* Redraw the old spot */
1006                 lite_spot(creature_ptr, oy, ox);
1007
1008                 /* Redraw the new spot */
1009                 lite_spot(creature_ptr, creature_ptr->y, creature_ptr->x);
1010
1011                 /* Check for new panel */
1012                 verify_panel(creature_ptr);
1013         }
1014
1015         creature_ptr->riding = 0;
1016         creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
1017         creature_ptr->riding_ryoute = creature_ptr->old_riding_ryoute = FALSE;
1018
1019         creature_ptr->update |= (PU_BONUS | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
1020         handle_stuff(creature_ptr);
1021
1022
1023         creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1024         creature_ptr->redraw |= (PR_EXTRA);
1025
1026         /* Update health track of mount */
1027         creature_ptr->redraw |= (PR_UHEALTH);
1028
1029         if (creature_ptr->levitation && !force)
1030         {
1031                 monster_desc(creature_ptr, m_name, m_ptr, 0);
1032                 msg_format(_("%sから落ちたが、空中でうまく体勢を立て直して着地した。", "You are thrown from %s, but make a good landing."), m_name);
1033         }
1034         else
1035         {
1036                 take_hit(creature_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("落馬", "Falling from riding"), -1);
1037                 fall_dam = TRUE;
1038         }
1039
1040         if (sy && !creature_ptr->is_dead)
1041                 (void)move_player_effect(creature_ptr, creature_ptr->y, creature_ptr->x, MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);
1042
1043         return fall_dam;
1044 }