OSDN Git Service

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