OSDN Git Service

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