OSDN Git Service

[Refactor] #39963 Changed header inclusion from realm*.h to realm/realm*.h
[hengband/hengband.git] / src / cmd / cmd-basic.c
1 /*!
2  *  @file cmd2.c
3  *  @brief プレイヤーのコマンド処理2 / Movement commands (part 2)
4  *  @date 2014/01/02
5  *  @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  */
12
13 #include "angband.h"
14 #include "main/music-definitions-table.h"
15 #include "main/sound-definitions-table.h"
16 #include "core.h"
17 #include "gameterm.h"
18
19 #include "io/write-diary.h"
20 #include "cmd/cmd-dump.h"
21 #include "cmd/cmd-save.h"
22 #include "chest.h"
23 #include "trap.h"
24 #include "dungeon.h"
25 #include "melee.h"
26 #include "object-hook.h"
27 #include "monster-status.h"
28 #include "quest.h"
29 #include "artifact.h"
30 #include "avatar.h"
31 #include "player-status.h"
32 #include "realm/realm-hex.h"
33 #include "geometry.h"
34 #include "wild.h"
35 #include "grid.h"
36 #include "player-move.h"
37 #include "player-effects.h"
38 #include "player-personality.h"
39 #include "player-inventory.h"
40 #include "object/object-kind.h"
41 #include "object-broken.h"
42 #include "object-flavor.h"
43 #include "shoot.h"
44 #include "snipe.h"
45
46 #include "cmd-basic.h"
47 #include "dungeon-file.h"
48 #include "files.h"
49
50 #include "view/display-main-window.h"
51 #include "targeting.h"
52 #include "world.h"
53
54 /*!
55  * @brief フロア脱出時に出戻りが不可能だった場合に警告を加える処理
56  * @param down_stair TRUEならば階段を降りる処理、FALSEなら階段を昇る処理による内容
57  * @return フロア移動を実際に行うならTRUE、キャンセルする場合はFALSE
58  */
59 static bool confirm_leave_level(player_type *creature_ptr, bool down_stair)
60 {
61         quest_type *q_ptr = &quest[creature_ptr->current_floor_ptr->inside_quest];
62
63         /* Confirm leaving from once only quest */
64         if (confirm_quest && creature_ptr->current_floor_ptr->inside_quest &&
65             (q_ptr->type == QUEST_TYPE_RANDOM ||
66              (q_ptr->flags & QUEST_FLAG_ONCE &&
67                                                 q_ptr->status != QUEST_STATUS_COMPLETED) ||
68                  (q_ptr->flags & QUEST_FLAG_TOWER &&
69                                                 ((q_ptr->status != QUEST_STATUS_STAGE_COMPLETED) ||
70                                                  (down_stair && (quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED))))))
71         {
72                 msg_print(_("この階を一度去ると二度と戻って来られません。", "You can't come back here once you leave this floor."));
73                 if (get_check(_("本当にこの階を去りますか?", "Really leave this floor? "))) return TRUE;
74         }
75         else
76         {
77                 return TRUE;
78         }
79         return FALSE;
80 }
81
82 /*!
83  * @brief 魔法系コマンドが制限されているかを返す。
84  * @return 魔法系コマンドを使用可能ならFALSE、不可能ならば理由をメッセージ表示してTRUEを返す。
85  */
86 bool cmd_limit_cast(player_type *creature_ptr)
87 {
88         if (creature_ptr->current_floor_ptr->dun_level && (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
89         {
90                 msg_print(_("ダンジョンが魔法を吸収した!", "The dungeon absorbs all attempted magic!"));
91                 msg_print(NULL);
92                 return TRUE;
93         }
94         else if (creature_ptr->anti_magic)
95         {
96                 msg_print(_("反魔法バリアが魔法を邪魔した!", "An anti-magic shell disrupts your magic!"));
97                 return TRUE;
98         }
99         else if (creature_ptr->shero)
100         {
101                 msg_format(_("狂戦士化していて頭が回らない!", "You cannot think directly!"));
102                 return TRUE;
103         }
104         else
105                 return FALSE;
106 }
107
108 bool cmd_limit_confused(player_type *creature_ptr)
109 {
110         if (creature_ptr->confused)
111         {
112                 msg_print(_("混乱していてできない!", "You are too confused!"));
113                 return TRUE;
114         }
115         return FALSE;
116 }
117
118 bool cmd_limit_image(player_type *creature_ptr)
119 {
120         if (creature_ptr->image)
121         {
122                 msg_print(_("幻覚が見えて集中できない!", "Your hallucinations prevent you from concentrating!"));
123                 return TRUE;
124         }
125         return FALSE;
126 }
127
128 bool cmd_limit_stun(player_type *creature_ptr)
129 {
130         if (creature_ptr->stun)
131         {
132                 msg_print(_("頭が朦朧としていて集中できない!", "You are too stunned!"));
133                 return TRUE;
134         }
135         return FALSE;
136 }
137
138 bool cmd_limit_arena(player_type *creature_ptr)
139 {
140         if (creature_ptr->current_floor_ptr->inside_arena)
141         {
142                 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
143                 msg_print(NULL);
144                 return TRUE;
145         }
146         return FALSE;
147 }
148
149 bool cmd_limit_blind(player_type *creature_ptr)
150 {
151         if (creature_ptr->blind)
152         {
153                 msg_print(_("目が見えない。", "You can't see anything."));
154                 return TRUE;
155         }
156         if (no_lite(creature_ptr))
157         {
158                 msg_print(_("明かりがないので見えない。", "You have no light."));
159                 return TRUE;
160         }
161         return FALSE;
162 }
163
164 bool cmd_limit_time_walk(player_type *creature_ptr)
165 {
166         if (creature_ptr->timewalk)
167         {
168                 if (flush_failure) flush();
169                 msg_print(_("止まった時の中ではうまく働かないようだ。", "It shows no reaction."));
170                 sound(SOUND_FAIL);
171                 return TRUE;
172         }
173         return FALSE;
174 }
175
176 /*!
177  * @brief 階段を使って階層を昇る処理 / Go up one level
178  * @return なし
179  */
180 void do_cmd_go_up(player_type *creature_ptr)
181 {
182         bool go_up = FALSE;
183
184         /* Player grid */
185         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
186         feature_type *f_ptr = &f_info[g_ptr->feat];
187
188         int up_num = 0;
189
190         if (creature_ptr->special_defense & KATA_MUSOU)
191         {
192                 set_action(creature_ptr, ACTION_NONE);
193         }
194
195         /* Verify stairs */
196         if (!have_flag(f_ptr->flags, FF_LESS))
197         {
198                 msg_print(_("ここには上り階段が見当たらない。", "I see no up staircase here."));
199                 return;
200         }
201
202         /* Quest up stairs */
203         if (have_flag(f_ptr->flags, FF_QUEST))
204         {
205                 if (!confirm_leave_level(creature_ptr, FALSE)) return;
206         
207                 /* Success */
208                 if (IS_ECHIZEN(creature_ptr))
209                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
210                 else
211                         msg_print(_("上の階に登った。", "You enter the up staircase."));
212
213                 leave_quest_check(creature_ptr);
214
215                 creature_ptr->current_floor_ptr->inside_quest = g_ptr->special;
216
217                 /* Activate the quest */
218                 if (!quest[creature_ptr->current_floor_ptr->inside_quest].status)
219                 {
220                         if (quest[creature_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
221                         {
222                                 init_flags = INIT_ASSIGN;
223                                 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
224                         }
225                         quest[creature_ptr->current_floor_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
226                 }
227
228                 /* Leaving a quest */
229                 if (!creature_ptr->current_floor_ptr->inside_quest)
230                 {
231                         creature_ptr->current_floor_ptr->dun_level = 0;
232                 }
233                 creature_ptr->leaving = TRUE;
234
235                 creature_ptr->oldpx = 0;
236                 creature_ptr->oldpy = 0;
237                 
238                 take_turn(creature_ptr, 100);
239
240                 /* End the command */
241                 return;
242         }
243
244         if (!creature_ptr->current_floor_ptr->dun_level)
245         {
246                 go_up = TRUE;
247         }
248         else
249         {
250                 go_up = confirm_leave_level(creature_ptr, FALSE);
251         }
252
253         if (!go_up) return;
254
255         take_turn(creature_ptr, 100);
256
257         if (autosave_l) do_cmd_save_game(creature_ptr, TRUE);
258
259         /* For a random quest */
260         if (creature_ptr->current_floor_ptr->inside_quest &&
261             quest[creature_ptr->current_floor_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
262         {
263                 leave_quest_check(creature_ptr);
264
265                 creature_ptr->current_floor_ptr->inside_quest = 0;
266         }
267
268         /* For a fixed quest */
269         if (creature_ptr->current_floor_ptr->inside_quest &&
270             quest[creature_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
271         {
272                 leave_quest_check(creature_ptr);
273
274                 creature_ptr->current_floor_ptr->inside_quest = g_ptr->special;
275                 creature_ptr->current_floor_ptr->dun_level = 0;
276                 up_num = 0;
277         }
278
279         /* For normal dungeon and random quest */
280         else
281         {
282                 /* New depth */
283                 if (have_flag(f_ptr->flags, FF_SHAFT))
284                 {
285                         /* Create a way back */
286                         prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_UP | CFM_SHAFT);
287
288                         up_num = 2;
289                 }
290                 else
291                 {
292                         /* Create a way back */
293                         prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_UP);
294
295                         up_num = 1;
296                 }
297
298                 /* Get out from current dungeon */
299                 if (creature_ptr->current_floor_ptr->dun_level - up_num < d_info[creature_ptr->dungeon_idx].mindepth)
300                         up_num = creature_ptr->current_floor_ptr->dun_level;
301         }
302         if (record_stair) exe_write_diary(creature_ptr, DIARY_STAIR, 0-up_num, _("階段を上った", "climbed up the stairs to"));
303
304         /* Success */
305         if (IS_ECHIZEN(creature_ptr))
306                 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
307         else if (up_num == creature_ptr->current_floor_ptr->dun_level)
308                 msg_print(_("地上に戻った。", "You go back to the surface."));
309         else
310                 msg_print(_("階段を上って新たなる迷宮へと足を踏み入れた。", "You enter a maze of up staircases."));
311         creature_ptr->leaving = TRUE;
312 }
313
314
315 /*!
316  * @brief 階段を使って階層を降りる処理 / Go down one level
317  * @param creature_ptr プレーヤーへの参照ポインタ
318  * @return なし
319  */
320 void do_cmd_go_down(player_type *creature_ptr)
321 {
322         bool fall_trap = FALSE;
323         int down_num = 0;
324
325         if (creature_ptr->special_defense & KATA_MUSOU)
326         {
327                 set_action(creature_ptr, ACTION_NONE);
328         }
329
330         /* Verify stairs */
331         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
332         feature_type *f_ptr = &f_info[g_ptr->feat];
333         if (!have_flag(f_ptr->flags, FF_MORE))
334         {
335                 msg_print(_("ここには下り階段が見当たらない。", "I see no down staircase here."));
336                 return;
337         }
338
339         if (have_flag(f_ptr->flags, FF_TRAP)) fall_trap = TRUE;
340
341         /* Quest entrance */
342         if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
343         {
344                 do_cmd_quest(creature_ptr);
345                 return;
346         }
347
348         /* Quest down stairs */
349         if (have_flag(f_ptr->flags, FF_QUEST))
350         {
351                 /* Confirm Leaving */
352                 if(!confirm_leave_level(creature_ptr, TRUE)) return;
353                 
354                 if (IS_ECHIZEN(creature_ptr))
355                         msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
356                 else
357                         msg_print(_("下の階に降りた。", "You enter the down staircase."));
358
359                 leave_quest_check(creature_ptr);
360                 leave_tower_check(creature_ptr);
361
362                 creature_ptr->current_floor_ptr->inside_quest = g_ptr->special;
363
364                 /* Activate the quest */
365                 if (!quest[creature_ptr->current_floor_ptr->inside_quest].status)
366                 {
367                         if (quest[creature_ptr->current_floor_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
368                         {
369                                 init_flags = INIT_ASSIGN;
370                                 process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
371                         }
372                         quest[creature_ptr->current_floor_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
373                 }
374
375                 /* Leaving a quest */
376                 if (!creature_ptr->current_floor_ptr->inside_quest)
377                 {
378                         creature_ptr->current_floor_ptr->dun_level = 0;
379                 }
380                 creature_ptr->leaving = TRUE;
381                 creature_ptr->oldpx = 0;
382                 creature_ptr->oldpy = 0;
383                 
384                 take_turn(creature_ptr, 100);
385                 return;
386         }
387
388         DUNGEON_IDX target_dungeon = 0;
389
390         if (!creature_ptr->current_floor_ptr->dun_level)
391         {
392                 target_dungeon = have_flag(f_ptr->flags, FF_ENTRANCE) ? g_ptr->special : DUNGEON_ANGBAND;
393
394                 if (ironman_downward && (target_dungeon != DUNGEON_ANGBAND))
395                 {
396                         msg_print(_("ダンジョンの入口は塞がれている!", "The entrance of this dungeon is closed!"));
397                         return;
398                 }
399                 if (!max_dlv[target_dungeon])
400                 {
401                         msg_format(_("ここには%sの入り口(%d階相当)があります", "There is the entrance of %s (Danger level: %d)"),
402                                 d_name + d_info[target_dungeon].name, d_info[target_dungeon].mindepth);
403                         if (!get_check(_("本当にこのダンジョンに入りますか?", "Do you really get in this dungeon? "))) return;
404                 }
405
406                 /* Save old player position */
407                 creature_ptr->oldpx = creature_ptr->x;
408                 creature_ptr->oldpy = creature_ptr->y;
409                 creature_ptr->dungeon_idx = target_dungeon;
410
411                 /*
412                  * Clear all saved floors
413                  * and create a first saved floor
414                  */
415                 prepare_change_floor_mode(creature_ptr, CFM_FIRST_FLOOR);
416         }
417
418         take_turn(creature_ptr, 100);
419
420         if (autosave_l) do_cmd_save_game(creature_ptr, TRUE);
421
422         /* Go down */
423         if (have_flag(f_ptr->flags, FF_SHAFT)) down_num += 2;
424         else down_num += 1;
425
426         if (!creature_ptr->current_floor_ptr->dun_level)
427         {
428                 /* Enter the dungeon just now */
429                 creature_ptr->enter_dungeon = TRUE;
430                 down_num = d_info[creature_ptr->dungeon_idx].mindepth;
431         }
432
433         if (record_stair)
434         {
435                 if (fall_trap) exe_write_diary(creature_ptr, DIARY_STAIR, down_num, _("落とし戸に落ちた", "fell through a trap door"));
436                 else exe_write_diary(creature_ptr, DIARY_STAIR, down_num, _("階段を下りた", "climbed down the stairs to"));
437         }
438
439         if (fall_trap)
440         {
441                 msg_print(_("わざと落とし戸に落ちた。", "You deliberately jump through the trap door."));
442         }
443         else
444         {
445                 /* Success */
446                 if (target_dungeon)
447                 {
448                         msg_format(_("%sへ入った。", "You entered %s."), d_text + d_info[creature_ptr->dungeon_idx].text);
449                 }
450                 else
451                 {
452                         if (IS_ECHIZEN(creature_ptr))
453                                 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
454                         else
455                                 msg_print(_("階段を下りて新たなる迷宮へと足を踏み入れた。", "You enter a maze of down staircases."));
456                 }
457         }
458
459         creature_ptr->leaving = TRUE;
460
461         if (fall_trap)
462         {
463                 prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
464                 return;
465         }
466         
467         /* Create a way back */
468         if (have_flag(f_ptr->flags, FF_SHAFT))
469         {
470                 prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_DOWN | CFM_SHAFT);
471         }
472         else
473         {
474                 prepare_change_floor_mode(creature_ptr, CFM_SAVE_FLOORS | CFM_DOWN);
475         }
476 }
477
478
479 /*!
480  * @brief 探索コマンドのメインルーチン / Simple command to "search" for one turn
481  * @return なし
482  */
483 void do_cmd_search(player_type * creature_ptr)
484 {
485         /* Allow repeated command */
486         if (command_arg)
487         {
488                 /* Set repeat count */
489                 command_rep = command_arg - 1;
490                 creature_ptr->redraw |= (PR_STATE);
491
492                 /* Cancel the arg */
493                 command_arg = 0;
494         }
495
496         take_turn(creature_ptr, 100);
497         search(creature_ptr);
498 }
499
500
501 /*!
502  * @brief 該当のマスに存在している箱のオブジェクトIDを返す。
503  * @param y 走査対象にしたいマスのY座標
504  * @param x 走査対象にしたいマスのX座標
505  * @param trapped TRUEならばトラップが存在する箱のみ、FALSEならば空でない箱全てを対象にする
506  * @return 箱が存在する場合そのオブジェクトID、存在しない場合0を返す。
507  */
508 static OBJECT_IDX chest_check(floor_type *floor_ptr, POSITION y, POSITION x, bool trapped)
509 {
510         grid_type *g_ptr = &floor_ptr->grid_array[y][x];
511         OBJECT_IDX this_o_idx, next_o_idx = 0;
512
513         /* Scan all objects in the grid */
514         for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
515         {
516                 object_type *o_ptr;
517
518                 o_ptr = &floor_ptr->o_list[this_o_idx];
519                 next_o_idx = o_ptr->next_o_idx;
520
521                 /* Skip unknown chests XXX XXX */
522                 /* if (!(o_ptr->marked & OM_FOUND)) continue; */
523
524                 /* Check for non empty chest */
525                 if ((o_ptr->tval == TV_CHEST) &&
526                         (((!trapped) && (o_ptr->pval)) || /* non empty */
527                         ((trapped) && (o_ptr->pval > 0)))) /* trapped only */
528                 {
529                         return (this_o_idx);
530                 }
531         }
532
533         return 0;
534 }
535
536 /*!
537  * @brief 箱を開ける実行処理 /
538  * Attempt to open the given chest at the given location
539  * @param y 箱の存在するマスのY座標
540  * @param x 箱の存在するマスのX座標
541  * @param o_idx 箱のオブジェクトID
542  * @return 箱が開かなかった場合TRUE / Returns TRUE if repeated commands may continue
543  * @details
544  * Assume there is no monster blocking the destination
545  */
546 static bool exe_open_chest(player_type *creature_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
547 {
548         bool flag = TRUE;
549         bool more = FALSE;
550         object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[o_idx];
551
552         take_turn(creature_ptr, 100);
553
554         /* Attempt to unlock it */
555         if (o_ptr->pval > 0)
556         {
557                 /* Assume locked, and thus not open */
558                 flag = FALSE;
559
560                 /* Get the "disarm" factor */
561                 int i = creature_ptr->skill_dis;
562
563                 /* Penalize some conditions */
564                 if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
565                 if (creature_ptr->confused || creature_ptr->image) i = i / 10;
566
567                 /* Extract the difficulty */
568                 int j = i - o_ptr->pval;
569
570                 /* Always have a small chance of success */
571                 if (j < 2) j = 2;
572
573                 /* Success -- May still have traps */
574                 if (randint0(100) < j)
575                 {
576                         msg_print(_("鍵をはずした。", "You have picked the lock."));
577                         gain_exp(creature_ptr, 1);
578                         flag = TRUE;
579                 }
580
581                 /* Failure -- Keep trying */
582                 else
583                 {
584                         /* We may continue repeating */
585                         more = TRUE;
586                         if (flush_failure) flush();
587                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
588
589                 }
590         }
591
592         /* Allowed to open */
593         if (flag)
594         {
595                 /* Apply chest traps, if any */
596                 chest_trap(creature_ptr, y, x, o_idx);
597
598                 /* Let the Chest drop items */
599                 chest_death(creature_ptr, FALSE, y, x, o_idx);
600         }
601
602         return more;
603 }
604
605 /*!
606  * @brief プレイヤーの周辺9マスに該当する地形がいくつあるかを返す /
607  * Attempt to open the given chest at the given location
608  * @param y 該当する地形の中から1つのY座標を返す参照ポインタ
609  * @param x 該当する地形の中から1つのX座標を返す参照ポインタ
610  * @param test 地形条件を判定するための関数ポインタ
611  * @param under TRUEならばプレイヤーの直下の座標も走査対象にする
612  * @return 該当する地形の数
613  * @details Return the number of features around (or under) the character.
614  * Usually look for doors and floor traps.
615  */
616 static int count_dt(player_type *creature_ptr, POSITION *y, POSITION *x, bool (*test)(player_type*, FEAT_IDX feat), bool under)
617 {
618         /* Check around (and under) the character */
619         int count = 0;
620         for (DIRECTION d = 0; d < 9; d++)
621         {
622                 grid_type *g_ptr;
623                 FEAT_IDX feat;
624
625                 /* if not searching under player continue */
626                 if ((d == 8) && !under) continue;
627
628                 /* Extract adjacent (legal) location */
629                 POSITION yy = creature_ptr->y + ddy_ddd[d];
630                 POSITION xx = creature_ptr->x + ddx_ddd[d];
631
632                 /* Get the creature_ptr->current_floor_ptr->grid_array */
633                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[yy][xx];
634
635                 /* Must have knowledge */
636                 if (!(g_ptr->info & (CAVE_MARK))) continue;
637
638                 /* Feature code (applying "mimic" field) */
639                 feat = get_feat_mimic(g_ptr);
640
641                 /* Not looking for this feature */
642                 if (!((*test)(creature_ptr, feat))) continue;
643
644                 /* OK */
645                 ++count;
646
647                 /* Remember the location. Only useful if only one match */
648                 *y = yy;
649                 *x = xx;
650         }
651
652         /* All done */
653         return count;
654 }
655
656
657 /*!
658  * @brief プレイヤーの周辺9マスに箱のあるマスがいくつあるかを返す /
659  * Return the number of chests around (or under) the character.
660  * @param y 該当するマスの中から1つのY座標を返す参照ポインタ
661  * @param x 該当するマスの中から1つのX座標を返す参照ポインタ
662  * @param trapped TRUEならばトラップの存在が判明している箱のみ対象にする
663  * @return 該当する地形の数
664  * @details
665  * If requested, count only trapped chests.
666  */
667 static int count_chests(player_type *creature_ptr, POSITION *y, POSITION *x, bool trapped)
668 {
669         /* Check around (and under) the character */
670         int count = 0;
671         for (DIRECTION d = 0; d < 9; d++)
672         {
673                 /* Extract adjacent (legal) location */
674                 POSITION yy = creature_ptr->y + ddy_ddd[d];
675                 POSITION xx = creature_ptr->x + ddx_ddd[d];
676
677                 /* No (visible) chest is there */
678                 OBJECT_IDX o_idx = chest_check(creature_ptr->current_floor_ptr, yy, xx, FALSE);
679                 if (!o_idx) continue;
680
681                 /* Grab the object */
682                 object_type *o_ptr;
683                 o_ptr = &creature_ptr->current_floor_ptr->o_list[o_idx];
684
685                 /* Already open */
686                 if (o_ptr->pval == 0) continue;
687
688                 /* No (known) traps here */
689                 if (trapped && (!object_is_known(o_ptr) ||
690                         !chest_traps[o_ptr->pval])) continue;
691
692                 /* OK */
693                 ++count;
694
695                 /* Remember the location. Only useful if only one match */
696                 *y = yy;
697                 *x = xx;
698         }
699
700         /* All done */
701         return count;
702 }
703
704
705
706 /*!
707  * @brief 「開ける」動作コマンドのサブルーチン /
708  * Perform the basic "open" command on doors
709  * @param y 対象を行うマスのY座標
710  * @param x 対象を行うマスのX座標
711  * @return 実際に処理が行われた場合TRUEを返す。
712  * @details
713  * Assume destination is a closed/locked/jammed door
714  * Assume there is no monster blocking the destination
715  * Returns TRUE if repeated commands may continue
716  */
717 static bool exe_open(player_type *creature_ptr, POSITION y, POSITION x)
718 {
719         /* Get requested grid */
720         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
721         feature_type *f_ptr = &f_info[g_ptr->feat];
722         bool more = FALSE;
723
724         take_turn(creature_ptr, 100);
725
726         /* Seeing true feature code (ignore mimic) */
727
728         /* Jammed door */
729         if (!have_flag(f_ptr->flags, FF_OPEN))
730         {
731                 /* Stuck */
732                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(g_ptr)].name);
733                 return more;
734         }
735
736         if (!f_ptr->power)
737         {
738                 cave_alter_feat(creature_ptr, y, x, FF_OPEN);
739                 sound(SOUND_OPENDOOR);
740                 return more;
741         }
742         
743         /* Disarm factor */
744         int i = creature_ptr->skill_dis;
745
746         /* Penalize some conditions */
747         if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
748         if (creature_ptr->confused || creature_ptr->image) i = i / 10;
749
750         /* Extract the difficulty */
751         int j = f_ptr->power;
752         j = i - (j * 4);
753
754         /* Always have a small chance of success */
755         if (j < 2) j = 2;
756
757         if (randint0(100) >= j)
758         {
759                 if (flush_failure) flush();
760                 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
761                 more = TRUE;
762         }
763
764         msg_print(_("鍵をはずした。", "You have picked the lock."));
765
766         /* Open the door */
767         cave_alter_feat(creature_ptr, y, x, FF_OPEN);
768
769         sound(SOUND_OPENDOOR);
770
771         /* Experience */
772         gain_exp(creature_ptr, 1);
773         return more;
774 }
775
776 /*!
777  * @brief 「開ける」コマンドのメインルーチン /
778  * Open a closed/locked/jammed door or a closed/locked chest.
779  * @return なし
780  * @details
781  * Unlocking a locked door/chest is worth one experience point.
782  */
783 void do_cmd_open(player_type *creature_ptr)
784 {
785         POSITION y, x;
786         DIRECTION dir;
787         OBJECT_IDX o_idx;
788
789         bool more = FALSE;
790
791         if (creature_ptr->wild_mode) return;
792
793         if (creature_ptr->special_defense & KATA_MUSOU)
794         {
795                 set_action(creature_ptr, ACTION_NONE);
796         }
797
798         /* Option: Pick a direction */
799         if (easy_open)
800         {
801                 int num_doors, num_chests;
802
803                 num_doors = count_dt(creature_ptr, &y, &x, is_closed_door, FALSE);
804                 num_chests = count_chests(creature_ptr, &y, &x, FALSE);
805                 if (num_doors || num_chests)
806                 {
807                         bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
808                             (num_chests > 1);
809                         if (!too_many) command_dir = coords_to_dir(creature_ptr, y, x);
810                 }
811         }
812
813         /* Allow repeated command */
814         if (command_arg)
815         {
816                 /* Set repeat count */
817                 command_rep = command_arg - 1;
818                 creature_ptr->redraw |= (PR_STATE);
819
820                 /* Cancel the arg */
821                 command_arg = 0;
822         }
823
824         /* Get a "repeated" direction */
825         if (get_rep_dir(creature_ptr, &dir, TRUE))
826         {
827                 FEAT_IDX feat;
828                 grid_type *g_ptr;
829
830                 /* Get requested location */
831                 y = creature_ptr->y + ddy[dir];
832                 x = creature_ptr->x + ddx[dir];
833
834                 /* Get requested grid */
835                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
836
837                 /* Feature code (applying "mimic" field) */
838                 feat = get_feat_mimic(g_ptr);
839
840                 /* Check for chest */
841                 o_idx = chest_check(creature_ptr->current_floor_ptr, y, x, FALSE);
842
843                 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
844                 {
845                         msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
846                 }
847                 else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx)
848                 {
849                         take_turn(creature_ptr, 100);
850                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
851                         py_attack(creature_ptr, y, x, 0);
852                 }
853                 else if (o_idx)
854                 {
855                         more = exe_open_chest(creature_ptr, y, x, o_idx);
856                 }
857                 else
858                 {
859                         more = exe_open(creature_ptr, y, x);
860                 }
861         }
862
863         /* Cancel repeat unless we may continue */
864         if (!more) disturb(creature_ptr, FALSE, FALSE);
865 }
866
867
868
869 /*
870  * todo 常にFALSEを返している
871  * @brief 「閉じる」動作コマンドのサブルーチン /
872  * Perform the basic "close" command
873  * @param y 対象を行うマスのY座標
874  * @param x 対象を行うマスのX座標
875  * @return 実際に処理が行われた場合TRUEを返す。
876  * @details
877  * Assume destination is an open/broken door
878  * Assume there is no monster blocking the destination
879  * Returns TRUE if repeated commands may continue
880  */
881 static bool exe_close(player_type *creature_ptr, POSITION y, POSITION x)
882 {
883         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
884         FEAT_IDX old_feat = g_ptr->feat;
885         bool more = FALSE;
886
887         take_turn(creature_ptr, 100);
888
889         /* Seeing true feature code (ignore mimic) */
890
891         /* Open door */
892         if (!have_flag(f_info[old_feat].flags, FF_CLOSE))
893         {
894                 return more;
895         }
896         
897         s16b closed_feat = feat_state(creature_ptr, old_feat, FF_CLOSE);
898
899         /* Hack -- object in the way */
900         if ((g_ptr->o_idx || (g_ptr->info & CAVE_OBJECT)) &&
901                 (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
902         {
903                 msg_print(_("何かがつっかえて閉まらない。", "Something prevents it from closing."));
904         }
905         else
906         {
907                 /* Close the door */
908                 cave_alter_feat(creature_ptr, y, x, FF_CLOSE);
909
910                 /* Broken door */
911                 if (old_feat == g_ptr->feat)
912                 {
913                         msg_print(_("ドアは壊れてしまっている。", "The door appears to be broken."));
914                 }
915                 else
916                 {
917                         sound(SOUND_SHUTDOOR);
918                 }
919         }
920
921         return more;
922 }
923
924
925 /*!
926  * @brief 「閉じる」コマンドのメインルーチン /
927  * Close an open door.
928  * @return なし
929  * @details
930  * Unlocking a locked door/chest is worth one experience point.
931  */
932 void do_cmd_close(player_type *creature_ptr)
933 {
934         POSITION y, x;
935         DIRECTION dir;
936
937         bool more = FALSE;
938
939         if (creature_ptr->wild_mode) return;
940
941         if (creature_ptr->special_defense & KATA_MUSOU)
942         {
943                 set_action(creature_ptr, ACTION_NONE);
944         }
945
946         /* Option: Pick a direction */
947         if (easy_open)
948         {
949                 /* Count open doors */
950                 if (count_dt(creature_ptr, &y, &x, is_open, FALSE) == 1)
951                 {
952                         command_dir = coords_to_dir(creature_ptr, y, x);
953                 }
954         }
955
956         /* Allow repeated command */
957         if (command_arg)
958         {
959                 /* Set repeat count */
960                 command_rep = command_arg - 1;
961                 creature_ptr->redraw |= (PR_STATE);
962
963                 /* Cancel the arg */
964                 command_arg = 0;
965         }
966
967         /* Get a "repeated" direction */
968         if (get_rep_dir(creature_ptr, &dir, FALSE))
969         {
970                 grid_type *g_ptr;
971                 FEAT_IDX feat;
972
973                 y = creature_ptr->y + ddy[dir];
974                 x = creature_ptr->x + ddx[dir];
975                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
976
977                 /* Feature code (applying "mimic" field) */
978                 feat = get_feat_mimic(g_ptr);
979
980                 /* Require open/broken door */
981                 if (!have_flag(f_info[feat].flags, FF_CLOSE))
982                 {
983                         msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
984                 }
985
986                 /* Monster in the way */
987                 else if (g_ptr->m_idx)
988                 {
989                         take_turn(creature_ptr, 100);
990
991                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
992
993                         /* Attack */
994                         py_attack(creature_ptr, y, x, 0);
995                 }
996
997                 /* Close the door */
998                 else
999                 {
1000                         /* Close the door */
1001                         more = exe_close(creature_ptr, y, x);
1002                 }
1003         }
1004
1005         /* Cancel repeat unless we may continue */
1006         if (!more) disturb(creature_ptr, FALSE, FALSE);
1007 }
1008
1009
1010 /*!
1011  * @brief 「掘る」コマンドを該当のマスに行えるかの判定と結果メッセージの表示 /
1012  * Determine if a given grid may be "tunneled"
1013  * @param y 対象を行うマスのY座標
1014  * @param x 対象を行うマスのX座標
1015  * @return 
1016  */
1017 static bool do_cmd_tunnel_test(floor_type *floor_ptr, POSITION y, POSITION x)
1018 {
1019         grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1020
1021         /* Must have knowledge */
1022         if (!(g_ptr->info & CAVE_MARK))
1023         {
1024                 msg_print(_("そこには何も見当たらない。", "You see nothing there."));
1025
1026                 return FALSE;
1027         }
1028
1029         /* Must be a wall/door/etc */
1030         if (!cave_have_flag_grid(g_ptr, FF_TUNNEL))
1031         {
1032                 msg_print(_("そこには掘るものが見当たらない。", "You see nothing there to tunnel."));
1033
1034                 return FALSE;
1035         }
1036
1037         return TRUE;
1038 }
1039
1040
1041 /*!
1042  * @brief 「掘る」動作コマンドのサブルーチン /
1043  * Perform the basic "tunnel" command
1044  * @param y 対象を行うマスのY座標
1045  * @param x 対象を行うマスのX座標
1046  * @return 実際に処理が行われた場合TRUEを返す。
1047  * @details
1048  * Assumes that no monster is blocking the destination
1049  * Do not use twall anymore
1050  * Returns TRUE if repeated commands may continue
1051  */
1052 static bool exe_tunnel(player_type *creature_ptr, POSITION y, POSITION x)
1053 {
1054         grid_type *g_ptr;
1055         feature_type *f_ptr, *mimic_f_ptr;
1056         int power;
1057         concptr name;
1058         bool more = FALSE;
1059
1060         /* Verify legality */
1061         if (!do_cmd_tunnel_test(creature_ptr->current_floor_ptr, y, x)) return FALSE;
1062
1063         take_turn(creature_ptr, 100);
1064
1065         g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1066         f_ptr = &f_info[g_ptr->feat];
1067         power = f_ptr->power;
1068
1069         /* Feature code (applying "mimic" field) */
1070         mimic_f_ptr = &f_info[get_feat_mimic(g_ptr)];
1071
1072         name = f_name + mimic_f_ptr->name;
1073
1074         sound(SOUND_DIG);
1075
1076         if (have_flag(f_ptr->flags, FF_PERMANENT))
1077         {
1078                 /* Titanium */
1079                 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1080                 {
1081                         msg_print(_("この岩は硬すぎて掘れないようだ。", "This seems to be permanent rock."));
1082                 }
1083
1084                 /* Map border (mimiccing Permanent wall) */
1085                 else
1086                 {
1087                         msg_print(_("そこは掘れない!", "You can't tunnel through that!"));
1088                 }
1089         }
1090
1091         /* Dig or tunnel */
1092         else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1093         {
1094                 /* Dig */
1095                 if (creature_ptr->skill_dig > randint0(20 * power))
1096                 {
1097                         msg_format(_("%sをくずした。", "You have removed the %s."), name);
1098
1099                         /* Remove the feature */
1100                         cave_alter_feat(creature_ptr, y, x, FF_TUNNEL);
1101                         creature_ptr->update |= (PU_FLOW);
1102                 }
1103                 else
1104                 {
1105                         /* Message, keep digging */
1106                         msg_format(_("%sをくずしている。", "You dig into the %s."), name);
1107                         
1108                         more = TRUE;
1109                 }
1110         }
1111
1112         else
1113         {
1114                 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1115
1116                 /* Tunnel */
1117                 if (creature_ptr->skill_dig > power + randint0(40 * power))
1118                 {
1119                         if (tree) msg_format(_("%sを切り払った。", "You have cleared away the %s."), name);
1120                         else
1121                         {
1122                                 msg_print(_("穴を掘り終えた。", "You have finished the tunnel."));
1123                                 creature_ptr->update |= (PU_FLOW);
1124                         }
1125                         
1126                         if (have_flag(f_ptr->flags, FF_GLASS)) sound(SOUND_GLASS);
1127
1128                         /* Remove the feature */
1129                         cave_alter_feat(creature_ptr, y, x, FF_TUNNEL);
1130
1131                         chg_virtue(creature_ptr, V_DILIGENCE, 1);
1132                         chg_virtue(creature_ptr, V_NATURE, -1);
1133                 }
1134
1135                 /* Keep trying */
1136                 else
1137                 {
1138                         if (tree)
1139                         {
1140                                 /* We may continue chopping */
1141                                 msg_format(_("%sを切っている。", "You chop away at the %s."), name);
1142                                 /* Occasional Search XXX XXX */
1143                                 if (randint0(100) < 25) search(creature_ptr);
1144                         }
1145                         else
1146                         {
1147                                 /* We may continue tunelling */
1148                                 msg_format(_("%sに穴を掘っている。", "You tunnel into the %s."), name);
1149                         }
1150
1151                         more = TRUE;
1152                 }
1153         }
1154
1155         if (is_hidden_door(creature_ptr, g_ptr))
1156         {
1157                 /* Occasional Search XXX XXX */
1158                 if (randint0(100) < 25) search(creature_ptr);
1159         }
1160
1161         return more;
1162 }
1163
1164
1165 /*!
1166  * @brief 「掘る」動作コマンドのメインルーチン /
1167  * Tunnels through "walls" (including rubble and closed doors)
1168  * @return なし
1169  * @details
1170  * <pre>
1171  * Note that you must tunnel in order to hit invisible monsters
1172  * in walls, though moving into walls still takes a turn anyway.
1173  *
1174  * Digging is very difficult without a "digger" weapon, but can be
1175  * accomplished by strong players using heavy weapons.
1176  * </pre>
1177  */
1178 void do_cmd_tunnel(player_type *creature_ptr)
1179 {
1180         POSITION y, x;
1181         DIRECTION dir;
1182         grid_type *g_ptr;
1183         FEAT_IDX feat;
1184
1185         bool more = FALSE;
1186
1187         if (creature_ptr->special_defense & KATA_MUSOU)
1188         {
1189                 set_action(creature_ptr, ACTION_NONE);
1190         }
1191
1192         /* Allow repeated command */
1193         if (command_arg)
1194         {
1195                 /* Set repeat count */
1196                 command_rep = command_arg - 1;
1197                 creature_ptr->redraw |= (PR_STATE);
1198
1199                 /* Cancel the arg */
1200                 command_arg = 0;
1201         }
1202
1203         /* Get a direction to tunnel, or Abort */
1204         if (get_rep_dir(creature_ptr, &dir,FALSE))
1205         {
1206                 /* Get location */
1207                 y = creature_ptr->y + ddy[dir];
1208                 x = creature_ptr->x + ddx[dir];
1209
1210                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1211
1212                 /* Feature code (applying "mimic" field) */
1213                 feat = get_feat_mimic(g_ptr);
1214
1215                 /* No tunnelling through doors */
1216                 if (have_flag(f_info[feat].flags, FF_DOOR))
1217                 {
1218                         msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
1219                 }
1220
1221                 /* No tunnelling through most features */
1222                 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1223                 {
1224                         msg_print(_("そこは掘れない。", "You can't tunnel through that."));
1225                 }
1226
1227                 /* A monster is in the way */
1228                 else if (g_ptr->m_idx)
1229                 {
1230                         take_turn(creature_ptr, 100);
1231                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1232
1233                         /* Attack */
1234                         py_attack(creature_ptr, y, x, 0);
1235                 }
1236
1237                 /* Try digging */
1238                 else
1239                 {
1240                         /* Tunnel through walls */
1241                         more = exe_tunnel(creature_ptr, y, x);
1242                 }
1243         }
1244
1245         /* Cancel repetition unless we can continue */
1246         if (!more) disturb(creature_ptr, FALSE, FALSE);
1247 }
1248
1249 /*!
1250  * @brief 移動処理による簡易な「開く」処理 /
1251  * easy_open_door --
1252  * @return 開く処理が実際に試みられた場合TRUEを返す
1253  * @details
1254  * <pre>
1255  *      If there is a jammed/closed/locked door at the given location,
1256  *      then attempt to unlock/open it. Return TRUE if an attempt was
1257  *      made (successful or not), otherwise return FALSE.
1258  *
1259  *      The code here should be nearly identical to that in
1260  *      do_cmd_open_test() and exe_open().
1261  * </pre>
1262  */
1263 bool easy_open_door(player_type *creature_ptr, POSITION y, POSITION x)
1264 {
1265         int i, j;
1266
1267         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1268         feature_type *f_ptr = &f_info[g_ptr->feat];
1269
1270         /* Must be a closed door */
1271         if (!is_closed_door(creature_ptr, g_ptr->feat))
1272         {
1273                 return FALSE;
1274         }
1275
1276         /* Jammed door */
1277         if (!have_flag(f_ptr->flags, FF_OPEN))
1278         {
1279                 /* Stuck */
1280                 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1281
1282         }
1283
1284         /* Locked door */
1285         else if (f_ptr->power)
1286         {
1287                 /* Disarm factor */
1288                 i = creature_ptr->skill_dis;
1289
1290                 /* Penalize some conditions */
1291                 if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
1292                 if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1293
1294                 /* Extract the lock power */
1295                 j = f_ptr->power;
1296
1297                 /* Extract the difficulty */
1298                 j = i - (j * 4);
1299
1300                 /* Always have a small chance of success */
1301                 if (j < 2) j = 2;
1302
1303                 /* Success */
1304                 if (randint0(100) < j)
1305                 {
1306                         msg_print(_("鍵をはずした。", "You have picked the lock."));
1307
1308                         /* Open the door */
1309                         cave_alter_feat(creature_ptr, y, x, FF_OPEN);
1310
1311                         sound(SOUND_OPENDOOR);
1312
1313                         /* Experience */
1314                         gain_exp(creature_ptr, 1);
1315                 }
1316
1317                 /* Failure */
1318                 else
1319                 {
1320                         /* Failure */
1321                         if (flush_failure) flush();
1322
1323                         msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1324
1325                 }
1326         }
1327
1328         /* Closed door */
1329         else
1330         {
1331                 /* Open the door */
1332                 cave_alter_feat(creature_ptr, y, x, FF_OPEN);
1333
1334                 sound(SOUND_OPENDOOR);
1335         }
1336
1337         return TRUE;
1338 }
1339
1340 /*!
1341  * @brief 箱のトラップを解除する実行処理 /
1342  * Perform the basic "disarm" command
1343  * @param y 解除を行うマスのY座標
1344  * @param x 解除を行うマスのX座標
1345  * @param o_idx 箱のオブジェクトID
1346  * @return ターンを消費する処理が行われた場合TRUEを返す
1347  * @details
1348  * <pre>
1349  * Assume destination is a visible trap
1350  * Assume there is no monster blocking the destination
1351  * Returns TRUE if repeated commands may continue
1352  * </pre>
1353  */
1354 static bool exe_disarm_chest(player_type *creature_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
1355 {
1356         int i, j;
1357         bool more = FALSE;
1358         object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[o_idx];
1359
1360         take_turn(creature_ptr, 100);
1361
1362         /* Get the "disarm" factor */
1363         i = creature_ptr->skill_dis;
1364
1365         /* Penalize some conditions */
1366         if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
1367         if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1368
1369         /* Extract the difficulty */
1370         j = i - o_ptr->pval;
1371
1372         /* Always have a small chance of success */
1373         if (j < 2) j = 2;
1374
1375         /* Must find the trap first. */
1376         if (!object_is_known(o_ptr))
1377         {
1378                 msg_print(_("トラップが見あたらない。", "I don't see any traps."));
1379
1380         }
1381
1382         /* Already disarmed/unlocked */
1383         else if (o_ptr->pval <= 0)
1384         {
1385                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1386         }
1387
1388         /* No traps to find. */
1389         else if (!chest_traps[o_ptr->pval])
1390         {
1391                 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1392         }
1393
1394         /* Success (get a lot of experience) */
1395         else if (randint0(100) < j)
1396         {
1397                 msg_print(_("箱に仕掛けられていたトラップを解除した。", "You have disarmed the chest."));
1398                 gain_exp(creature_ptr, o_ptr->pval);
1399                 o_ptr->pval = (0 - o_ptr->pval);
1400         }
1401
1402         /* Failure -- Keep trying */
1403         else if ((i > 5) && (randint1(i) > 5))
1404         {
1405                 /* We may keep trying */
1406                 more = TRUE;
1407                 if (flush_failure) flush();
1408                 msg_print(_("箱のトラップ解除に失敗した。", "You failed to disarm the chest."));
1409         }
1410
1411         /* Failure -- Set off the trap */
1412         else
1413         {
1414                 msg_print(_("トラップを作動させてしまった!", "You set off a trap!"));
1415                 sound(SOUND_FAIL);
1416                 chest_trap(creature_ptr, y, x, o_idx);
1417         }
1418
1419         return (more);
1420 }
1421
1422
1423 /*!
1424  * @brief 箱のトラップを解除するコマンドのサブルーチン /
1425  * Perform the basic "disarm" command
1426  * @param y 解除を行うマスのY座標
1427  * @param x 解除を行うマスのX座標
1428  * @param dir プレイヤーからみた方向ID
1429  * @return ターンを消費する処理が行われた場合TRUEを返す
1430  * @details
1431  * <pre>
1432  * Assume destination is a visible trap
1433  * Assume there is no monster blocking the destination
1434  * Returns TRUE if repeated commands may continue
1435  * </pre>
1436  */
1437
1438 bool exe_disarm(player_type *creature_ptr, POSITION y, POSITION x, DIRECTION dir)
1439 {
1440         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1441
1442         /* Get feature */
1443         feature_type *f_ptr = &f_info[g_ptr->feat];
1444
1445         /* Access trap name */
1446         concptr name = (f_name + f_ptr->name);
1447
1448         /* Extract trap "power" */
1449         int power = f_ptr->power;
1450         bool more = FALSE;
1451
1452         /* Get the "disarm" factor */
1453         int i = creature_ptr->skill_dis;
1454         int j;
1455
1456         take_turn(creature_ptr, 100);
1457
1458         /* Penalize some conditions */
1459         if (creature_ptr->blind || no_lite(creature_ptr)) i = i / 10;
1460         if (creature_ptr->confused || creature_ptr->image) i = i / 10;
1461
1462         /* Extract the difficulty */
1463         j = i - power;
1464
1465         /* Always have a small chance of success */
1466         if (j < 2) j = 2;
1467
1468         /* Success */
1469         if (randint0(100) < j)
1470         {
1471                 msg_format(_("%sを解除した。", "You have disarmed the %s."), name);
1472                 
1473                 /* Reward */
1474                 gain_exp(creature_ptr, power);
1475
1476                 /* Remove the trap */
1477                 cave_alter_feat(creature_ptr, y, x, FF_DISARM);
1478
1479                 /* Move the player onto the trap */
1480                 move_player(creature_ptr, dir, easy_disarm, FALSE);
1481         }
1482
1483         /* Failure -- Keep trying */
1484         else if ((i > 5) && (randint1(i) > 5))
1485         {
1486                 /* Failure */
1487                 if (flush_failure) flush();
1488
1489                 msg_format(_("%sの解除に失敗した。", "You failed to disarm the %s."), name);
1490
1491                 /* We may keep trying */
1492                 more = TRUE;
1493         }
1494
1495         /* Failure -- Set off the trap */
1496         else
1497         {
1498                 msg_format(_("%sを作動させてしまった!", "You set off the %s!"), name);
1499                 /* Move the player onto the trap */
1500                 move_player(creature_ptr, dir, easy_disarm, FALSE);
1501         }
1502
1503         return (more);
1504 }
1505
1506
1507 /*!
1508  * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
1509  * Disarms a trap, or chest
1510  * @return なし
1511  */
1512 void do_cmd_disarm(player_type *creature_ptr)
1513 {
1514         POSITION y, x;
1515         DIRECTION dir;
1516         OBJECT_IDX o_idx;
1517
1518         bool more = FALSE;
1519
1520         if (creature_ptr->wild_mode) return;
1521
1522         if (creature_ptr->special_defense & KATA_MUSOU)
1523         {
1524                 set_action(creature_ptr, ACTION_NONE);
1525         }
1526
1527         /* Option: Pick a direction */
1528         if (easy_disarm)
1529         {
1530                 int num_traps, num_chests;
1531
1532                 /* Count visible traps */
1533                 num_traps = count_dt(creature_ptr, &y, &x, is_trap, TRUE);
1534
1535                 /* Count chests (trapped) */
1536                 num_chests = count_chests(creature_ptr, &y, &x, TRUE);
1537
1538                 /* See if only one target */
1539                 if (num_traps || num_chests)
1540                 {
1541                         bool too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
1542                         if (!too_many) command_dir = coords_to_dir(creature_ptr, y, x);
1543                 }
1544         }
1545         
1546         /* Allow repeated command */
1547         if (command_arg)
1548         {
1549                 /* Set repeat count */
1550                 command_rep = command_arg - 1;
1551                 creature_ptr->redraw |= (PR_STATE);
1552
1553                 /* Cancel the arg */
1554                 command_arg = 0;
1555         }
1556
1557         /* Get a direction (or abort) */
1558         if (get_rep_dir(creature_ptr, &dir,TRUE))
1559         {
1560                 grid_type *g_ptr;
1561                 FEAT_IDX feat;
1562
1563                 y = creature_ptr->y + ddy[dir];
1564                 x = creature_ptr->x + ddx[dir];
1565                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1566
1567                 /* Feature code (applying "mimic" field) */
1568                 feat = get_feat_mimic(g_ptr);
1569
1570                 /* Check for chests */
1571                 o_idx = chest_check(creature_ptr->current_floor_ptr, y, x, TRUE);
1572
1573                 /* Disarm a trap */
1574                 if (!is_trap(creature_ptr, feat) && !o_idx)
1575                 {
1576                         msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
1577                 }
1578
1579                 /* Monster in the way */
1580                 else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx)
1581                 {
1582                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1583
1584                         /* Attack */
1585                         py_attack(creature_ptr, y, x, 0);
1586                 }
1587
1588                 /* Disarm chest */
1589                 else if (o_idx)
1590                 {
1591                         more = exe_disarm_chest(creature_ptr, y, x, o_idx);
1592                 }
1593
1594                 /* Disarm trap */
1595                 else
1596                 {
1597                         more = exe_disarm(creature_ptr, y, x, dir);
1598                 }
1599         }
1600
1601         /* Cancel repeat unless told not to */
1602         if (!more) disturb(creature_ptr, FALSE, FALSE);
1603 }
1604
1605
1606 /*!
1607  * @brief 「打ち破る」動作コマンドのサブルーチン /
1608  * Perform the basic "bash" command
1609  * @param y 対象を行うマスのY座標
1610  * @param x 対象を行うマスのX座標
1611  * @param dir プレイヤーから見たターゲットの方角ID
1612  * @return 実際に処理が行われた場合TRUEを返す。
1613  * @details
1614  * <pre>
1615  * Assume destination is a closed/locked/jammed door
1616  * Assume there is no monster blocking the destination
1617  * Returns TRUE if repeated commands may continue
1618  * </pre>
1619  */
1620 static bool do_cmd_bash_aux(player_type *creature_ptr, POSITION y, POSITION x, DIRECTION dir)
1621 {
1622         grid_type       *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1623
1624         /* Get feature */
1625         feature_type *f_ptr = &f_info[g_ptr->feat];
1626
1627         /* Hack -- Bash power based on strength */
1628         /* (Ranges from 3 to 20 to 100 to 200) */
1629         int bash = adj_str_blow[creature_ptr->stat_ind[A_STR]];
1630
1631         /* Extract door power */
1632         int temp = f_ptr->power;
1633
1634         bool            more = FALSE;
1635
1636         concptr name = f_name + f_info[get_feat_mimic(g_ptr)].name;
1637
1638         take_turn(creature_ptr, 100);
1639
1640         msg_format(_("%sに体当たりをした!", "You smash into the %s!"), name);
1641
1642         /* Compare bash power to door power */
1643         temp = (bash - (temp * 10));
1644
1645         if (creature_ptr->pclass == CLASS_BERSERKER) temp *= 2;
1646
1647         /* Hack -- always have a chance */
1648         if (temp < 1) temp = 1;
1649
1650         /* Hack -- attempt to bash down the door */
1651         if (randint0(100) < temp)
1652         {
1653                 msg_format(_("%sを壊した!", "The %s crashes open!"), name);
1654
1655                 sound(have_flag(f_ptr->flags, FF_GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
1656
1657                 /* Break down the door */
1658                 if ((randint0(100) < 50) || (feat_state(creature_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS))
1659                 {
1660                         cave_alter_feat(creature_ptr, y, x, FF_BASH);
1661                 }
1662
1663                 /* Open the door */
1664                 else
1665                 {
1666                         cave_alter_feat(creature_ptr, y, x, FF_OPEN);
1667                 }
1668
1669                 /* Hack -- Fall through the door */
1670                 move_player(creature_ptr, dir, FALSE, FALSE);
1671         }
1672
1673         /* Saving throw against stun */
1674         else if (randint0(100) < adj_dex_safe[creature_ptr->stat_ind[A_DEX]] +
1675                  creature_ptr->lev)
1676         {
1677                 msg_format(_("この%sは頑丈だ。", "The %s holds firm."), name);
1678
1679                 /* Allow repeated bashing */
1680                 more = TRUE;
1681         }
1682
1683         /* High dexterity yields coolness */
1684         else
1685         {
1686                 msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
1687
1688                 /* Hack -- Lose balance ala paralysis */
1689                 (void)set_paralyzed(creature_ptr, creature_ptr->paralyzed + 2 + randint0(2));
1690         }
1691
1692         return (more);
1693 }
1694
1695
1696 /*!
1697  * @brief 「打ち破る」動作コマンドのメインルーチン /
1698  * Bash open a door, success based on character strength
1699  * @return なし
1700  * @details
1701  * <pre>
1702  * For a closed door, pval is positive if locked; negative if stuck.
1703  *
1704  * For an open door, pval is positive for a broken door.
1705  *
1706  * A closed door can be opened - harder if locked. Any door might be
1707  * bashed open (and thereby broken). Bashing a door is (potentially)
1708  * faster! You move into the door way. To open a stuck door, it must
1709  * be bashed. A closed door can be jammed (see do_cmd_spike()).
1710  *
1711  * Creatures can also open or bash doors, see elsewhere.
1712  * </pre>
1713  */
1714 void do_cmd_bash(player_type *creature_ptr)
1715 {
1716         POSITION y, x;
1717         DIRECTION dir;
1718         grid_type *g_ptr;
1719         bool more = FALSE;
1720
1721         if (creature_ptr->wild_mode) return;
1722
1723         if (creature_ptr->special_defense & KATA_MUSOU)
1724         {
1725                 set_action(creature_ptr, ACTION_NONE);
1726         }
1727
1728         /* Allow repeated command */
1729         if (command_arg)
1730         {
1731                 /* Set repeat count */
1732                 command_rep = command_arg - 1;
1733                 creature_ptr->redraw |= (PR_STATE);
1734
1735                 /* Cancel the arg */
1736                 command_arg = 0;
1737         }
1738
1739         /* Get a "repeated" direction */
1740         if (get_rep_dir(creature_ptr, &dir,FALSE))
1741         {
1742                 FEAT_IDX feat;
1743
1744                 /* Bash location */
1745                 y = creature_ptr->y + ddy[dir];
1746                 x = creature_ptr->x + ddx[dir];
1747
1748                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1749
1750                 /* Feature code (applying "mimic" field) */
1751                 feat = get_feat_mimic(g_ptr);
1752
1753                 /* Nothing useful */
1754                 if (!have_flag(f_info[feat].flags, FF_BASH))
1755                 {
1756                         msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
1757                 }
1758
1759                 /* Monster in the way */
1760                 else if (g_ptr->m_idx)
1761                 {
1762                         take_turn(creature_ptr, 100);
1763
1764                         msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1765
1766                         /* Attack */
1767                         py_attack(creature_ptr, y, x, 0);
1768                 }
1769
1770                 /* Bash a closed door */
1771                 else
1772                 {
1773                         /* Bash the door */
1774                         more = do_cmd_bash_aux(creature_ptr, y, x, dir);
1775                 }
1776         }
1777
1778         /* Unless valid action taken, cancel bash */
1779         if (!more) disturb(creature_ptr, FALSE, FALSE);
1780 }
1781
1782
1783 /*!
1784  * @brief 特定のマスに影響を及ぼすための汎用的コマンド
1785  * @return なし
1786  * @details
1787  * <pre>
1788  * Manipulate an adjacent grid in some way
1789  *
1790  * Attack monsters, tunnel through walls, disarm traps, open doors.
1791  *
1792  * Consider confusion 
1793  *
1794  * This command must always take a turn, to prevent free detection
1795  * of invisible monsters.
1796  * </pre>
1797  */
1798 void do_cmd_alter(player_type *creature_ptr)
1799 {
1800         POSITION y, x;
1801         DIRECTION dir;
1802         grid_type *g_ptr;
1803         bool more = FALSE;
1804
1805         if (creature_ptr->special_defense & KATA_MUSOU)
1806         {
1807                 set_action(creature_ptr, ACTION_NONE);
1808         }
1809
1810         /* Allow repeated command */
1811         if (command_arg)
1812         {
1813                 /* Set repeat count */
1814                 command_rep = command_arg - 1;
1815                 creature_ptr->redraw |= (PR_STATE);
1816
1817                 /* Cancel the arg */
1818                 command_arg = 0;
1819         }
1820
1821         /* Get a direction */
1822         if (get_rep_dir(creature_ptr, &dir,TRUE))
1823         {
1824                 FEAT_IDX feat;
1825                 feature_type *f_ptr;
1826
1827                 y = creature_ptr->y + ddy[dir];
1828                 x = creature_ptr->x + ddx[dir];
1829
1830                 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1831
1832                 /* Feature code (applying "mimic" field) */
1833                 feat = get_feat_mimic(g_ptr);
1834                 f_ptr = &f_info[feat];
1835
1836                 take_turn(creature_ptr, 100);
1837
1838                 if (g_ptr->m_idx)
1839                 {
1840                         py_attack(creature_ptr, y, x, 0);
1841                 }
1842
1843                 /* Locked doors */
1844                 else if (have_flag(f_ptr->flags, FF_OPEN))
1845                 {
1846                         more = exe_open(creature_ptr, y, x);
1847                 }
1848
1849                 /* Bash jammed doors */
1850                 else if (have_flag(f_ptr->flags, FF_BASH))
1851                 {
1852                         more = do_cmd_bash_aux(creature_ptr, y, x, dir);
1853                 }
1854
1855                 /* Tunnel through walls */
1856                 else if (have_flag(f_ptr->flags, FF_TUNNEL))
1857                 {
1858                         more = exe_tunnel(creature_ptr, y, x);
1859                 }
1860
1861                 /* Close open doors */
1862                 else if (have_flag(f_ptr->flags, FF_CLOSE))
1863                 {
1864                         more = exe_close(creature_ptr, y, x);
1865                 }
1866
1867                 /* Disarm traps */
1868                 else if (have_flag(f_ptr->flags, FF_DISARM))
1869                 {
1870                         more = exe_disarm(creature_ptr, y, x, dir);
1871                 }
1872
1873                 else
1874                 {
1875                         msg_print(_("何もない空中を攻撃した。", "You attack the empty air."));
1876                 }
1877         }
1878
1879         /* Cancel repetition unless we can continue */
1880         if (!more) disturb(creature_ptr, FALSE, FALSE);
1881 }
1882
1883
1884
1885 /*!
1886  * @brief 「くさびを打つ」ために必要なオブジェクトを所持しているかどうかの判定を返す /
1887  * Find the index of some "spikes", if possible.
1888  * @param ip くさびとして打てるオブジェクトのID
1889  * @return オブジェクトがある場合TRUEを返す
1890  * @details
1891  * <pre>
1892  * Let user choose a pile of spikes, perhaps?
1893  * </pre>
1894  */
1895 static bool get_spike(player_type *creature_ptr, INVENTORY_IDX *ip)
1896 {
1897         INVENTORY_IDX i;
1898
1899         /* Check every item in the pack */
1900         for (i = 0; i < INVEN_PACK; i++)
1901         {
1902                 object_type *o_ptr = &creature_ptr->inventory_list[i];
1903                 if (!o_ptr->k_idx) continue;
1904
1905                 /* Check the "tval" code */
1906                 if (o_ptr->tval == TV_SPIKE)
1907                 {
1908                         /* Save the spike index */
1909                         (*ip) = i;
1910
1911                         /* Success */
1912                         return TRUE;
1913                 }
1914         }
1915
1916         return FALSE;
1917 }
1918
1919
1920 /*!
1921  * @brief 「くさびを打つ」動作コマンドのメインルーチン /
1922  * Jam a closed door with a spike
1923  * @param creature_ptr プレーヤーへの参照ポインタ
1924  * @return なし
1925  * @details
1926  * <pre>
1927  * This command may NOT be repeated
1928  * </pre>
1929  */
1930 void do_cmd_spike(player_type *creature_ptr)
1931 {
1932         DIRECTION dir;
1933
1934         if (creature_ptr->wild_mode) return;
1935         if (creature_ptr->special_defense & KATA_MUSOU)
1936         {
1937                 set_action(creature_ptr, ACTION_NONE);
1938         }
1939
1940         /* Get a "repeated" direction */
1941         if (!get_rep_dir(creature_ptr, &dir, FALSE)) return;
1942
1943         POSITION y = creature_ptr->y + ddy[dir];
1944         POSITION x = creature_ptr->x + ddx[dir];
1945         grid_type *g_ptr;
1946         g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
1947
1948         /* Feature code (applying "mimic" field) */
1949         FEAT_IDX feat = get_feat_mimic(g_ptr);
1950
1951         /* Require closed door */
1952         INVENTORY_IDX item;
1953         if (!have_flag(f_info[feat].flags, FF_SPIKE))
1954         {
1955                 msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
1956         }
1957
1958         /* Get a spike */
1959         else if (!get_spike(creature_ptr, &item))
1960         {
1961                 msg_print(_("くさびを持っていない!", "You have no spikes!"));
1962         }
1963
1964         /* Is a monster in the way? */
1965         else if (g_ptr->m_idx)
1966         {
1967                 take_turn(creature_ptr, 100);
1968
1969                 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1970
1971                 /* Attack */
1972                 py_attack(creature_ptr, y, x, 0);
1973         }
1974
1975         /* Go for it */
1976         else
1977         {
1978                 take_turn(creature_ptr, 100);
1979
1980                 /* Successful jamming */
1981                 msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_name + f_info[feat].name);
1982                 cave_alter_feat(creature_ptr, y, x, FF_SPIKE);
1983
1984                 vary_item(creature_ptr, item, -1);
1985         }
1986 }
1987
1988
1989 /*!
1990  * @brief 「歩く」動作コマンドのメインルーチン /
1991  * Support code for the "Walk" and "Jump" commands
1992  * @param creature_ptr プレーヤーへの参照ポインタ
1993  * @param pickup アイテムの自動拾いを行うならTRUE
1994  * @return なし
1995  */
1996 void do_cmd_walk(player_type *creature_ptr, bool pickup)
1997 {
1998         /* Allow repeated command */
1999         if (command_arg)
2000         {
2001                 /* Set repeat count */
2002                 command_rep = command_arg - 1;
2003                 creature_ptr->redraw |= (PR_STATE);
2004
2005                 /* Cancel the arg */
2006                 command_arg = 0;
2007         }
2008
2009         /* Get a "repeated" direction */
2010         bool more = FALSE;
2011         DIRECTION dir;
2012         if (get_rep_dir(creature_ptr, &dir, FALSE))
2013         {
2014                 take_turn(creature_ptr, 100);
2015
2016                 if ((dir != 5) && (creature_ptr->special_defense & KATA_MUSOU))
2017                 {
2018                         set_action(creature_ptr, ACTION_NONE);
2019                 }
2020
2021                 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2022                 if (creature_ptr->wild_mode) creature_ptr->energy_use *= ((MAX_HGT + MAX_WID) / 2);
2023                 if (creature_ptr->action == ACTION_HAYAGAKE) creature_ptr->energy_use = creature_ptr->energy_use * (45-(creature_ptr->lev/2)) / 100;
2024
2025                 /* Actually move the character */
2026                 move_player(creature_ptr, dir, pickup, FALSE);
2027
2028                 /* Allow more walking */
2029                 more = TRUE;
2030         }
2031
2032         /* Hack again -- Is there a special encounter ??? */
2033         if (creature_ptr->wild_mode && !cave_have_flag_bold(creature_ptr->current_floor_ptr, creature_ptr->y, creature_ptr->x, FF_TOWN))
2034         {
2035                 int tmp = 120 + creature_ptr->lev*10 - wilderness[creature_ptr->y][creature_ptr->x].level + 5;
2036                 if (tmp < 1) 
2037                         tmp = 1;
2038                 if (((wilderness[creature_ptr->y][creature_ptr->x].level + 5) > (creature_ptr->lev / 2)) && randint0(tmp) < (21-creature_ptr->skill_stl))
2039                 {
2040                         /* Inform the player of his horrible fate :=) */
2041                         msg_print(_("襲撃だ!", "You are ambushed !"));
2042
2043                         /* Go into large wilderness view */
2044                         creature_ptr->oldpy = randint1(MAX_HGT-2);
2045                         creature_ptr->oldpx = randint1(MAX_WID-2);
2046                         change_wild_mode(creature_ptr, TRUE);
2047
2048                         /* Give first move to monsters */
2049                         take_turn(creature_ptr, 100);
2050
2051                 }
2052         }
2053
2054         /* Cancel repeat unless we may continue */
2055         if (!more) disturb(creature_ptr, FALSE, FALSE);
2056 }
2057
2058
2059 /*!
2060  * @brief 「走る」動作コマンドのメインルーチン /
2061  * Start running.
2062  * @param creature_ptr プレーヤーへの参照ポインタ
2063  * @return なし
2064  */
2065 void do_cmd_run(player_type *creature_ptr)
2066 {
2067         DIRECTION dir;
2068         if (cmd_limit_confused(creature_ptr)) return;
2069
2070         if (creature_ptr->special_defense & KATA_MUSOU)
2071         {
2072                 set_action(creature_ptr, ACTION_NONE);
2073         }
2074
2075         /* Get a "repeated" direction */
2076         if (get_rep_dir(creature_ptr, &dir,FALSE))
2077         {
2078                 /* Hack -- Set the run counter */
2079                 creature_ptr->running = (command_arg ? command_arg : 1000);
2080
2081                 /* First step */
2082                 run_step(creature_ptr, dir);
2083         }
2084 }
2085
2086
2087 /*!
2088  * @brief 「留まる」動作コマンドのメインルーチン /
2089  * Stay still.  Search.  Enter stores.
2090  * Pick up treasure if "pickup" is true.
2091  * @param creature_ptr プレーヤーへの参照ポインタ
2092  * @param pickup アイテムの自動拾いを行うならTRUE
2093  * @return なし
2094  */
2095 void do_cmd_stay(player_type *creature_ptr, bool pickup)
2096 {
2097         u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2098
2099         /* Allow repeated command */
2100         if (command_arg)
2101         {
2102                 /* Set repeat count */
2103                 command_rep = command_arg - 1;
2104                 creature_ptr->redraw |= (PR_STATE);
2105
2106                 /* Cancel the arg */
2107                 command_arg = 0;
2108         }
2109
2110         take_turn(creature_ptr, 100);
2111
2112         if (pickup) mpe_mode |= MPE_DO_PICKUP;
2113         (void)move_player_effect(creature_ptr, creature_ptr->y, creature_ptr->x, mpe_mode);
2114 }
2115
2116
2117 /*!
2118  * @brief 「休む」動作コマンドのメインルーチン /
2119  * Resting allows a player to safely restore his hp     -RAK-
2120  * @param creature_ptr プレーヤーへの参照ポインタ
2121  * @return なし
2122  */
2123 void do_cmd_rest(player_type *creature_ptr)
2124 {
2125         set_action(creature_ptr, ACTION_NONE);
2126
2127         if ((creature_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(creature_ptr) || INTERUPTING_SONG_EFFECT(creature_ptr)))
2128         {
2129                 stop_singing(creature_ptr);
2130         }
2131
2132         if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
2133
2134         /* Prompt for time if needed */
2135         if (command_arg <= 0)
2136         {
2137                 concptr p = _("休憩 (0-9999, '*' で HP/MP全快, '&' で必要なだけ): ", 
2138                                    "Rest (0-9999, '*' for HP/SP, '&' as needed): ");
2139
2140 char out_val[80];
2141
2142                 /* Default */
2143                 strcpy(out_val, "&");
2144
2145                 /* Ask for duration */
2146                 if (!get_string(p, out_val, 4)) return;
2147
2148                 /* Rest until done */
2149                 if (out_val[0] == '&')
2150                 {
2151                         command_arg = COMMAND_ARG_REST_UNTIL_DONE;
2152                 }
2153
2154                 /* Rest a lot */
2155                 else if (out_val[0] == '*')
2156                 {
2157                         command_arg = COMMAND_ARG_REST_FULL_HEALING;
2158                 }
2159
2160                 /* Rest some */
2161                 else
2162                 {
2163                         command_arg = (COMMAND_ARG)atoi(out_val);
2164                         if (command_arg <= 0) return;
2165                 }
2166         }
2167
2168         if (command_arg > 9999) command_arg = 9999;
2169
2170         if (creature_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(creature_ptr, FALSE);
2171
2172         /* Take a turn (?) */
2173         take_turn(creature_ptr, 100);
2174
2175         /* The sin of sloth */
2176         if (command_arg > 100) chg_virtue(creature_ptr, V_DILIGENCE, -1);
2177         
2178         /* Why are you sleeping when there's no need?  WAKE UP!*/
2179         if ((creature_ptr->chp == creature_ptr->mhp) &&
2180             (creature_ptr->csp == creature_ptr->msp) &&
2181             !creature_ptr->blind && !creature_ptr->confused &&
2182             !creature_ptr->poisoned && !creature_ptr->afraid &&
2183             !creature_ptr->stun && !creature_ptr->cut &&
2184             !creature_ptr->slow && !creature_ptr->paralyzed &&
2185             !creature_ptr->image && !creature_ptr->word_recall &&
2186             !creature_ptr->alter_reality)
2187                         chg_virtue(creature_ptr, V_DILIGENCE, -1);
2188
2189         /* Save the rest code */
2190         creature_ptr->resting = command_arg;
2191         creature_ptr->action = ACTION_REST;
2192         creature_ptr->update |= (PU_BONUS);
2193         update_creature(creature_ptr);
2194
2195         creature_ptr->redraw |= (PR_STATE);
2196         update_output(creature_ptr);
2197
2198         Term_fresh();
2199 }
2200
2201
2202
2203 /*
2204  * todo Doxygenの加筆求む
2205  * @brief 射撃処理のメインルーチン
2206  * @param creature_ptr プレーヤーへの参照ポインタ
2207  * @param snipe_type ???
2208  * @return なし
2209  */
2210 void do_cmd_fire(player_type *creature_ptr, SPELL_IDX snipe_type)
2211 {
2212         OBJECT_IDX item;
2213         object_type *j_ptr, *ammo_ptr;
2214         concptr q, s;
2215
2216         if(creature_ptr->wild_mode) return;
2217
2218         creature_ptr->is_fired = FALSE; /* not fired yet */
2219
2220         /* Get the "bow" (if any) */
2221         j_ptr = &creature_ptr->inventory_list[INVEN_BOW];
2222
2223         /* Require a launcher */
2224         if (!j_ptr->tval)
2225         {
2226                 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
2227                 flush();
2228                 return;
2229         }
2230
2231         if (j_ptr->sval == SV_CRIMSON)
2232         {
2233                 msg_print(_("この武器は発動して使うもののようだ。", "It's already activated."));
2234                 flush();
2235                 return;
2236         }
2237
2238         if (j_ptr->sval == SV_HARP)
2239         {
2240                 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
2241                 flush();
2242                 return;
2243         }
2244
2245
2246         if (creature_ptr->special_defense & KATA_MUSOU)
2247         {
2248                 set_action(creature_ptr, ACTION_NONE);
2249         }
2250
2251         q = _("どれを撃ちますか? ", "Fire which item? ");
2252         s = _("発射されるアイテムがありません。", "You have nothing to fire.");
2253
2254         ammo_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), creature_ptr->tval_ammo);
2255         if (!ammo_ptr)
2256         {
2257                 flush();
2258                 return;
2259         }
2260
2261         /* Fire the item */
2262         exe_fire(creature_ptr, item, j_ptr, snipe_type);
2263
2264         if (!creature_ptr->is_fired || creature_ptr->pclass != CLASS_SNIPER) return;
2265
2266         /* Sniper actions after some shootings */
2267         if (snipe_type == SP_AWAY)
2268         {
2269                 teleport_player(creature_ptr, 10 + (creature_ptr->concent * 2), 0L);
2270         }
2271
2272         if (snipe_type == SP_FINAL)
2273         {
2274                 msg_print(_("射撃の反動が体を襲った。", "The weapon's recoil stuns you. "));
2275                 (void)set_slow(creature_ptr, creature_ptr->slow + randint0(7) + 7, FALSE);
2276                 (void)set_stun(creature_ptr, creature_ptr->stun + randint1(25));
2277         }
2278 }
2279
2280
2281 /*!
2282  * @brief 投射処理メインルーチン /
2283  * Throw an object from the pack or floor.
2284  * @param mult 威力の倍率
2285  * @param creature_ptr プレーヤーへの参照ポインタ
2286  * @param boomerang ブーメラン処理ならばTRUE
2287  * @param shuriken 忍者の手裏剣処理ならばTRUE
2288  * @return ターンを消費した場合TRUEを返す
2289  * @details
2290  * <pre>
2291  * Note: "unseen" monsters are very hard to hit.
2292  *
2293  * Should throwing a weapon do full damage?  Should it allow the magic
2294  * to hit bonus of the weapon to have an effect?  Should it ever cause
2295  * the item to be destroyed?  Should it do any damage at all?
2296  * </pre>
2297  */
2298 bool do_cmd_throw(player_type *creature_ptr, int mult, bool boomerang, OBJECT_IDX shuriken)
2299 {
2300         DIRECTION dir;
2301         OBJECT_IDX item;
2302         int i;
2303         POSITION y, x, ty, tx, prev_y, prev_x;
2304         POSITION ny[19], nx[19];
2305         int chance, tdam, tdis;
2306         int mul, div, dd, ds;
2307         int cur_dis, visible;
2308         PERCENTAGE j;
2309
2310         object_type forge;
2311         object_type *q_ptr;
2312         object_type *o_ptr;
2313
2314         bool hit_body = FALSE;
2315         bool hit_wall = FALSE;
2316         bool equiped_item = FALSE;
2317         bool return_when_thrown = FALSE;
2318
2319         GAME_TEXT o_name[MAX_NLEN];
2320
2321         int msec = delay_factor * delay_factor * delay_factor;
2322
2323         BIT_FLAGS flgs[TR_FLAG_SIZE];
2324         concptr q, s;
2325         bool come_back = FALSE;
2326         bool do_drop = TRUE;
2327
2328         if (creature_ptr->wild_mode) return FALSE;
2329
2330         if (creature_ptr->special_defense & KATA_MUSOU)
2331         {
2332                 set_action(creature_ptr, ACTION_NONE);
2333         }
2334
2335         if (shuriken >= 0)
2336         {
2337                 item = shuriken;
2338                 o_ptr = &creature_ptr->inventory_list[item];
2339         }
2340         else if (boomerang)
2341         {
2342                 if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM))
2343                 {
2344                         item_tester_hook = item_tester_hook_boomerang;
2345                         q = _("どの武器を投げますか? ", "Throw which item? ");
2346                         s = _("投げる武器がない。", "You have nothing to throw.");
2347                         o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP), 0);
2348                         if (!o_ptr)
2349                         {
2350                                 flush();
2351                                 return FALSE;
2352                         }
2353                 }
2354                 else if (has_melee_weapon(creature_ptr, INVEN_LARM))
2355                 {
2356                         item = INVEN_LARM;
2357                         o_ptr = &creature_ptr->inventory_list[item];
2358                 }
2359                 else
2360                 {
2361                         item = INVEN_RARM;
2362                         o_ptr = &creature_ptr->inventory_list[item];
2363                 }
2364         }
2365         else
2366         {
2367                 q = _("どのアイテムを投げますか? ", "Throw which item? ");
2368                 s = _("投げるアイテムがない。", "You have nothing to throw.");
2369                 o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP), 0);
2370                 if (!o_ptr)
2371                 {
2372                         flush();
2373                         return FALSE;
2374                 }
2375         }
2376
2377         /* Item is cursed */
2378         if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
2379         {
2380                 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
2381                 return FALSE;
2382         }
2383
2384         if (creature_ptr->current_floor_ptr->inside_arena && !boomerang)
2385         {
2386                 if (o_ptr->tval != TV_SPIKE)
2387                 {
2388                         msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
2389                         msg_print(NULL);
2390
2391                         return FALSE;
2392                 }
2393         }
2394
2395         q_ptr = &forge;
2396         object_copy(q_ptr, o_ptr);
2397
2398         /* Extract the thrown object's flags. */
2399         object_flags(q_ptr, flgs);
2400         torch_flags(q_ptr, flgs);
2401
2402         /* Distribute the charges of rods/wands between the stacks */
2403         distribute_charges(o_ptr, q_ptr, 1);
2404
2405         /* Single object */
2406         q_ptr->number = 1;
2407
2408         object_desc(creature_ptr, o_name, q_ptr, OD_OMIT_PREFIX);
2409
2410         if (creature_ptr->mighty_throw) mult += 3;
2411
2412         /* Extract a "distance multiplier" */
2413         /* Changed for 'launcher' mutation */
2414         mul = 10 + 2 * (mult - 1);
2415
2416         /* Enforce a minimum "weight" of one pound */
2417         div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
2418         if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
2419
2420         /* Hack -- Distance -- Reward strength, penalize weight */
2421         tdis = (adj_str_blow[creature_ptr->stat_ind[A_STR]] + 20) * mul / div;
2422
2423         /* Max distance of 10-18 */
2424         if (tdis > mul) tdis = mul;
2425
2426         if (shuriken >= 0)
2427         {
2428                 ty = randint0(101) - 50 + creature_ptr->y;
2429                 tx = randint0(101) - 50 + creature_ptr->x;
2430         }
2431         else
2432         {
2433                 project_length = tdis + 1;
2434
2435                 /* Get a direction (or cancel) */
2436                 if (!get_aim_dir(creature_ptr, &dir)) return FALSE;
2437
2438                 /* Predict the "target" location */
2439                 tx = creature_ptr->x + 99 * ddx[dir];
2440                 ty = creature_ptr->y + 99 * ddy[dir];
2441
2442                 /* Check for "target request" */
2443                 if ((dir == 5) && target_okay(creature_ptr))
2444                 {
2445                         tx = target_col;
2446                         ty = target_row;
2447                 }
2448
2449                 project_length = 0;  /* reset to default */
2450         }
2451
2452         if ((q_ptr->name1 == ART_MJOLLNIR) ||
2453             (q_ptr->name1 == ART_AEGISFANG) || boomerang)
2454                 return_when_thrown = TRUE;
2455
2456         if (item >= 0)
2457         {
2458                 inven_item_increase(creature_ptr, item, -1);
2459                 if (!return_when_thrown)
2460                         inven_item_describe(creature_ptr, item);
2461                 inven_item_optimize(creature_ptr, item);
2462         }
2463         else
2464         {
2465                 floor_item_increase(creature_ptr->current_floor_ptr, 0 - item, -1);
2466                 floor_item_optimize(creature_ptr, 0 - item);
2467         }
2468
2469         if (item >= INVEN_RARM)
2470         {
2471                 equiped_item = TRUE;
2472                 creature_ptr->redraw |= (PR_EQUIPPY);
2473         }
2474
2475         take_turn(creature_ptr, 100);
2476
2477         /* Rogue and Ninja gets bonus */
2478         if ((creature_ptr->pclass == CLASS_ROGUE) || (creature_ptr->pclass == CLASS_NINJA))
2479                 creature_ptr->energy_use -= creature_ptr->lev;
2480
2481         /* Start at the player */
2482         y = creature_ptr->y;
2483         x = creature_ptr->x;
2484
2485         handle_stuff(creature_ptr);
2486
2487         if ((creature_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
2488         else shuriken = FALSE;
2489
2490         /* Chance of hitting */
2491         if (have_flag(flgs, TR_THROW)) chance = ((creature_ptr->skill_tht) +
2492                 ((creature_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
2493         else chance = (creature_ptr->skill_tht + (creature_ptr->to_h_b * BTH_PLUS_ADJ));
2494
2495         if (shuriken) chance *= 2;
2496
2497         prev_y = y;
2498         prev_x = x;
2499
2500         /* Travel until stopped */
2501         for (cur_dis = 0; cur_dis <= tdis; )
2502         {
2503                 /* Hack -- Stop at the target */
2504                 if ((y == ty) && (x == tx)) break;
2505
2506                 /* Calculate the new location (see "project()") */
2507                 ny[cur_dis] = y;
2508                 nx[cur_dis] = x;
2509                 mmove2(&ny[cur_dis], &nx[cur_dis], creature_ptr->y, creature_ptr->x, ty, tx);
2510
2511                 /* Stopped by walls/doors */
2512                 if (!cave_have_flag_bold(creature_ptr->current_floor_ptr, ny[cur_dis], nx[cur_dis], FF_PROJECT))
2513                 {
2514                         hit_wall = TRUE;
2515                         if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !creature_ptr->current_floor_ptr->grid_array[ny[cur_dis]][nx[cur_dis]].m_idx) break;
2516                 }
2517
2518                 /* The player can see the (on screen) missile */
2519                 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(creature_ptr, ny[cur_dis], nx[cur_dis]))
2520                 {
2521                         SYMBOL_CODE c = object_char(q_ptr);
2522                         TERM_COLOR a = object_attr(q_ptr);
2523
2524                         /* Draw, Hilite, Fresh, Pause, Erase */
2525                         print_rel(creature_ptr, c, a, ny[cur_dis], nx[cur_dis]);
2526                         move_cursor_relative(ny[cur_dis], nx[cur_dis]);
2527                         Term_fresh();
2528                         Term_xtra(TERM_XTRA_DELAY, msec);
2529                         lite_spot(creature_ptr, ny[cur_dis], nx[cur_dis]);
2530                         Term_fresh();
2531                 }
2532
2533                 /* The player cannot see the missile */
2534                 else
2535                 {
2536                         /* Pause anyway, for consistancy */
2537                         Term_xtra(TERM_XTRA_DELAY, msec);
2538                 }
2539
2540                 prev_y = y;
2541                 prev_x = x;
2542
2543                 /* Save the new location */
2544                 x = nx[cur_dis];
2545                 y = ny[cur_dis];
2546
2547                 /* Advance the distance */
2548                 cur_dis++;
2549
2550                 /* Monster here, Try to hit it */
2551                 if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx)
2552                 {
2553                         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
2554                         monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
2555                         GAME_TEXT m_name[MAX_NLEN];
2556                         monster_name(creature_ptr, g_ptr->m_idx, m_name);
2557
2558                         /* Check the visibility */
2559                         visible = m_ptr->ml;
2560
2561                         /* Note the collision */
2562                         hit_body = TRUE;
2563
2564                         /* Did we hit it (penalize range) */
2565                         if (test_hit_fire(creature_ptr, chance - cur_dis, m_ptr, m_ptr->ml, o_name))
2566                         {
2567                                 bool fear = FALSE;
2568
2569                                 /* Handle unseen monster */
2570                                 if (!visible)
2571                                 {
2572                                         /* Invisible monster */
2573                                         msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
2574                                 }
2575
2576                                 /* Handle visible monster */
2577                                 else
2578                                 {
2579                                         msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
2580
2581                                         if (m_ptr->ml)
2582                                         {
2583                                                 if (!creature_ptr->image) monster_race_track(creature_ptr, m_ptr->ap_r_idx);
2584                                                 health_track(creature_ptr, g_ptr->m_idx);
2585                                         }
2586                                 }
2587
2588                                 /* Hack -- Base damage from thrown object */
2589                                 dd = q_ptr->dd;
2590                                 ds = q_ptr->ds;
2591                                 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
2592                                 tdam = damroll(dd, ds);
2593                                 /* Apply special damage */
2594                                 tdam = tot_dam_aux(creature_ptr, q_ptr, tdam, m_ptr, 0, TRUE);
2595                                 tdam = critical_shot(creature_ptr, q_ptr->weight, q_ptr->to_h, 0, tdam);
2596                                 if (q_ptr->to_d > 0)
2597                                         tdam += q_ptr->to_d;
2598                                 else
2599                                         tdam += -q_ptr->to_d;
2600
2601                                 if (boomerang)
2602                                 {
2603                                         tdam *= (mult+creature_ptr->num_blow[item - INVEN_RARM]);
2604                                         tdam += creature_ptr->to_d_m;
2605                                 }
2606                                 else if (have_flag(flgs, TR_THROW))
2607                                 {
2608                                         tdam *= (3+mult);
2609                                         tdam += creature_ptr->to_d_m;
2610                                 }
2611                                 else
2612                                 {
2613                                         tdam *= mult;
2614                                 }
2615                                 if (shuriken)
2616                                 {
2617                                         tdam += ((creature_ptr->lev+30)*(creature_ptr->lev+30)-900)/55;
2618                                 }
2619
2620                                 /* No negative damage */
2621                                 if (tdam < 0) tdam = 0;
2622
2623                                 /* Modify the damage */
2624                                 tdam = mon_damage_mod(creature_ptr, m_ptr, tdam, FALSE);
2625
2626                                 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
2627                                         tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
2628
2629                                 /* Hit the monster, check for death */
2630                                 if (mon_take_hit(creature_ptr, g_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr))))
2631                                 {
2632                                         /* Dead monster */
2633                                 }
2634
2635                                 /* No death */
2636                                 else
2637                                 {
2638                                         message_pain(creature_ptr, g_ptr->m_idx, tdam);
2639
2640                                         /* Anger the monster */
2641                                         if ((tdam > 0) && !object_is_potion(q_ptr))
2642                                                 anger_monster(creature_ptr, m_ptr);
2643
2644                                         if (fear && m_ptr->ml)
2645                                         {
2646                                                 sound(SOUND_FLEE);
2647                                                 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
2648                                         }
2649                                 }
2650                         }
2651
2652                         /* Stop looking */
2653                         break;
2654                 }
2655         }
2656
2657         /* decrease toach's fuel */
2658         if (hit_body) torch_lost_fuel(q_ptr);
2659
2660         /* Chance of breakage (during attacks) */
2661         j = (hit_body ? breakage_chance(creature_ptr, q_ptr, creature_ptr->pclass == CLASS_ARCHER, 0) : 0);
2662
2663         /* Figurines transform */
2664         if ((q_ptr->tval == TV_FIGURINE) && !(creature_ptr->current_floor_ptr->inside_arena))
2665         {
2666                 j = 100;
2667
2668                 if (!(summon_named_creature(creature_ptr, 0, y, x, q_ptr->pval, !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
2669                         msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
2670                 else if (object_is_cursed(q_ptr))
2671                         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
2672
2673         }
2674
2675         /* Potions smash open */
2676         if (object_is_potion(q_ptr))
2677         {
2678                 if (hit_body || hit_wall || (randint1(100) < j))
2679                 {
2680                         msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
2681
2682                         if (potion_smash_effect(creature_ptr, 0, y, x, q_ptr->k_idx))
2683                         {
2684                                 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx];
2685                                 if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx && is_friendly(m_ptr) && !MON_INVULNER(m_ptr))
2686                                 {
2687                                         GAME_TEXT m_name[MAX_NLEN];
2688                                         monster_desc(creature_ptr, m_name, m_ptr, 0);
2689                                         msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
2690                                         set_hostile(creature_ptr, &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx]);
2691                                 }
2692                         }
2693                         do_drop = FALSE;
2694                 }
2695                 else
2696                 {
2697                         j = 0;
2698                 }
2699         }
2700
2701         if (return_when_thrown)
2702         {
2703                 int back_chance = randint1(30)+20+((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
2704                 char o2_name[MAX_NLEN];
2705                 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
2706
2707                 j = -1;
2708                 if (boomerang) back_chance += 4+randint1(5);
2709                 if (super_boomerang) back_chance += 100;
2710                 object_desc(creature_ptr, o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2711
2712                 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
2713                 {
2714                         for (i = cur_dis - 1; i > 0; i--)
2715                         {
2716                                 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(creature_ptr, ny[i], nx[i]))
2717                                 {
2718                                         char c = object_char(q_ptr);
2719                                         byte a = object_attr(q_ptr);
2720
2721                                         /* Draw, Hilite, Fresh, Pause, Erase */
2722                                         print_rel(creature_ptr, c, a, ny[i], nx[i]);
2723                                         move_cursor_relative(ny[i], nx[i]);
2724                                         Term_fresh();
2725                                         Term_xtra(TERM_XTRA_DELAY, msec);
2726                                         lite_spot(creature_ptr, ny[i], nx[i]);
2727                                         Term_fresh();
2728                                 }
2729                                 else
2730                                 {
2731                                         /* Pause anyway, for consistancy */
2732                                         Term_xtra(TERM_XTRA_DELAY, msec);
2733                                 }
2734                         }
2735                         if((back_chance > 37) && !creature_ptr->blind && (item >= 0))
2736                         {
2737                                 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
2738                                 come_back = TRUE;
2739                         }
2740                         else
2741                         {
2742                                 if (item >= 0)
2743                                 {
2744                                         msg_format(_("%sを受け損ねた!", "%s comes back, but you can't catch!"), o2_name);
2745                                 }
2746                                 else
2747                                 {
2748                                         msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
2749                                 }
2750                                 y = creature_ptr->y;
2751                                 x = creature_ptr->x;
2752                         }
2753                 }
2754                 else
2755                 {
2756                         msg_format(_("%sが返ってこなかった!", "%s doesn't come back!"), o2_name);
2757                 }
2758         }
2759
2760         if (come_back)
2761         {
2762                 if (item == INVEN_RARM || item == INVEN_LARM)
2763                 {
2764                         /* Access the wield slot */
2765                         o_ptr = &creature_ptr->inventory_list[item];
2766
2767                         /* Wear the new stuff */
2768                         object_copy(o_ptr, q_ptr);
2769
2770                         creature_ptr->total_weight += q_ptr->weight;
2771
2772                         /* Increment the equip counter by hand */
2773                         creature_ptr->equip_cnt++;
2774
2775                         creature_ptr->update |= (PU_BONUS | PU_TORCH | PU_MANA);
2776                         creature_ptr->window |= (PW_EQUIP);
2777                 }
2778                 else
2779                 {
2780                         inven_carry(creature_ptr, q_ptr);
2781                 }
2782                 do_drop = FALSE;
2783         }
2784         else if (equiped_item)
2785         {
2786                 verify_equip_slot(creature_ptr, item);
2787                 calc_android_exp(creature_ptr);
2788         }
2789
2790         if (do_drop)
2791         {
2792                 if (cave_have_flag_bold(creature_ptr->current_floor_ptr, y, x, FF_PROJECT))
2793                 {
2794                         (void)drop_near(creature_ptr, q_ptr, j, y, x);
2795                 }
2796                 else
2797                 {
2798                         (void)drop_near(creature_ptr, q_ptr, j, prev_y, prev_x);
2799                 }
2800         }
2801
2802         return TRUE;
2803 }
2804
2805 /*!
2806  * @brief 自殺するコマンドのメインルーチン
2807  * Hack -- commit suicide
2808  * @return なし
2809  * @details
2810  */
2811 void do_cmd_suicide(player_type *creature_ptr)
2812 {
2813         int i;
2814
2815         /* Flush input */
2816         flush();
2817
2818         /* Verify Retirement */
2819         if (current_world_ptr->total_winner)
2820         {
2821                 /* Verify */
2822                 if (!get_check_strict(_("引退しますか? ", "Do you want to retire? "), CHECK_NO_HISTORY)) return;
2823         }
2824
2825         /* Verify Suicide */
2826         else
2827         {
2828                 /* Verify */
2829                 if (!get_check(_("本当に自殺しますか?", "Do you really want to commit suicide? "))) return;
2830         }
2831
2832         if (!current_world_ptr->noscore)
2833         {
2834                 /* Special Verification for suicide */
2835                 prt(_("確認のため '@' を押して下さい。", "Please verify SUICIDE by typing the '@' sign: "), 0, 0);
2836
2837                 flush();
2838                 i = inkey();
2839                 prt("", 0, 0);
2840                 if (i != '@') return;
2841
2842                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
2843         }
2844
2845         /* Initialize "last message" buffer */
2846         if (creature_ptr->last_message) string_free(creature_ptr->last_message);
2847         creature_ptr->last_message = NULL;
2848
2849         /* Hack -- Note *winning* message */
2850         if (current_world_ptr->total_winner && last_words)
2851         {
2852                 char buf[1024] = "";
2853                 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WINNER);
2854                 do
2855                 {
2856                         while (!get_string(_("*勝利*メッセージ: ", "*Winning* message: "), buf, sizeof buf));
2857                 } while (!get_check_strict(_("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
2858
2859                 if (buf[0])
2860                 {
2861                         creature_ptr->last_message = string_make(buf);
2862                         msg_print(creature_ptr->last_message);
2863                 }
2864         }
2865
2866         /* Stop playing */
2867         creature_ptr->playing = FALSE;
2868
2869         /* Kill the player */
2870         creature_ptr->is_dead = TRUE;
2871         creature_ptr->leaving = TRUE;
2872
2873         if (!current_world_ptr->total_winner)
2874         {
2875                 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, _("ダンジョンの探索に絶望して自殺した。", "gave up all hope to commit suicide."));
2876                 exe_write_diary(creature_ptr, DIARY_GAMESTART, 1, _("-------- ゲームオーバー --------", "--------   Game  Over   --------"));
2877                 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, "\n\n\n\n");
2878         }
2879
2880         /* Cause of death */
2881         (void)strcpy(creature_ptr->died_from, _("途中終了", "Quitting"));
2882 }