OSDN Git Service

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