OSDN Git Service

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