OSDN Git Service

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