OSDN Git Service

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