OSDN Git Service

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