OSDN Git Service

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