OSDN Git Service

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