OSDN Git Service

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