OSDN Git Service

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