OSDN Git Service

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