OSDN Git Service

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