OSDN Git Service

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