OSDN Git Service

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