OSDN Git Service

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