OSDN Git Service

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