OSDN Git Service

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