OSDN Git Service

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