OSDN Git Service

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