OSDN Git Service

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