OSDN Git Service

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