OSDN Git Service

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