OSDN Git Service

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