OSDN Git Service

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