OSDN Git Service

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