3 * @brief プレイヤーのコマンド処理2 / Movement commands (part 2)
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
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.
25 #include "object-hook.h"
27 #include "spells-summon.h"
28 #include "spells-status.h"
30 #include "monster-status.h"
34 #include "player-status.h"
35 #include "realm-hex.h"
36 #include "realm-song.h"
41 #include "player-move.h"
42 #include "player-effects.h"
43 #include "player-class.h"
44 #include "player-personality.h"
45 #include "objectkind.h"
46 #include "object-broken.h"
47 #include "object-flavor.h"
51 #include "cmd-basic.h"
53 #include "floor-save.h"
54 #include "dungeon-file.h"
57 #include "view-mainwindow.h"
58 #include "targeting.h"
61 * @brief フロア脱出時に出戻りが不可能だった場合に警告を加える処理
62 * @param down_stair TRUEならば階段を降りる処理、FALSEなら階段を昇る処理による内容
63 * @return フロア移動を実際に行うならTRUE、キャンセルする場合はFALSE
65 static bool confirm_leave_level(player_type *creature_ptr, bool down_stair)
67 quest_type *q_ptr = &quest[creature_ptr->inside_quest];
69 /* Confirm leaving from once only quest */
70 if (confirm_quest && creature_ptr->inside_quest &&
71 (q_ptr->type == QUEST_TYPE_RANDOM ||
72 (q_ptr->flags & QUEST_FLAG_ONCE &&
73 q_ptr->status != QUEST_STATUS_COMPLETED) ||
74 (q_ptr->flags & QUEST_FLAG_TOWER &&
75 ((q_ptr->status != QUEST_STATUS_STAGE_COMPLETED) ||
76 (down_stair && (quest[QUEST_TOWER1].status != QUEST_STATUS_COMPLETED))))))
78 msg_print(_("この階を一度去ると二度と戻って来られません。", "You can't come back here once you leave this floor."));
79 if (get_check(_("本当にこの階を去りますか?", "Really leave this floor? "))) return TRUE;
89 * @brief 魔法系コマンドが制限されているかを返す。
90 * @return 魔法系コマンドを使用可能ならFALSE、不可能ならば理由をメッセージ表示してTRUEを返す。
92 bool cmd_limit_cast(player_type *creature_ptr)
94 if (current_floor_ptr->dun_level && (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
96 msg_print(_("ダンジョンが魔法を吸収した!", "The dungeon absorbs all attempted magic!"));
100 else if (creature_ptr->anti_magic)
102 msg_print(_("反魔法バリアが魔法を邪魔した!", "An anti-magic shell disrupts your magic!"));
105 else if (creature_ptr->shero)
107 msg_format(_("狂戦士化していて頭が回らない!", "You cannot think directly!"));
114 bool cmd_limit_confused(player_type *creature_ptr)
116 if (creature_ptr->confused)
118 msg_print(_("混乱していてできない!", "You are too confused!"));
124 bool cmd_limit_image(player_type *creature_ptr)
126 if (creature_ptr->image)
128 msg_print(_("幻覚が見えて集中できない!", "You are too hallucinated!"));
134 bool cmd_limit_stun(player_type *creature_ptr)
136 if (creature_ptr->stun)
138 msg_print(_("頭が朦朧としていて集中できない!", "You are too stuned!"));
144 bool cmd_limit_arena(player_type *creature_ptr)
146 if (creature_ptr->inside_arena)
148 msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
155 bool cmd_limit_blind(player_type *creature_ptr)
157 if (creature_ptr->blind)
159 msg_print(_("目が見えない。", "You can't see anything."));
164 msg_print(_("明かりがないので見えない。", "You have no light."));
170 bool cmd_limit_time_walk(player_type *creature_ptr)
172 if (creature_ptr->timewalk)
174 if (flush_failure) flush();
175 msg_print(_("止まった時の中ではうまく働かないようだ。", "It shows no reaction."));
183 * @brief 階段を使って階層を昇る処理 / Go up one level
186 void do_cmd_go_up(player_type *creature_ptr)
191 grid_type *g_ptr = ¤t_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
192 feature_type *f_ptr = &f_info[g_ptr->feat];
196 if (creature_ptr->special_defense & KATA_MUSOU)
198 set_action(ACTION_NONE);
202 if (!have_flag(f_ptr->flags, FF_LESS))
204 msg_print(_("ここには上り階段が見当たらない。", "I see no up staircase here."));
208 /* Quest up stairs */
209 if (have_flag(f_ptr->flags, FF_QUEST))
211 if (!confirm_leave_level(creature_ptr, FALSE)) return;
214 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
215 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
217 msg_print(_("上の階に登った。", "You enter the up staircase."));
221 creature_ptr->inside_quest = g_ptr->special;
223 /* Activate the quest */
224 if (!quest[creature_ptr->inside_quest].status)
226 if (quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
228 init_flags = INIT_ASSIGN;
229 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
231 quest[creature_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
234 /* Leaving a quest */
235 if (!creature_ptr->inside_quest)
237 current_floor_ptr->dun_level = 0;
239 creature_ptr->leaving = TRUE;
241 creature_ptr->oldpx = 0;
242 creature_ptr->oldpy = 0;
244 take_turn(creature_ptr, 100);
246 /* End the command */
250 if (!current_floor_ptr->dun_level)
256 go_up = confirm_leave_level(creature_ptr, FALSE);
261 take_turn(creature_ptr, 100);
263 if (autosave_l) do_cmd_save_game(TRUE);
265 /* For a random quest */
266 if (creature_ptr->inside_quest &&
267 quest[creature_ptr->inside_quest].type == QUEST_TYPE_RANDOM)
271 creature_ptr->inside_quest = 0;
274 /* For a fixed quest */
275 if (creature_ptr->inside_quest &&
276 quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
280 creature_ptr->inside_quest = g_ptr->special;
281 current_floor_ptr->dun_level = 0;
285 /* For normal dungeon and random quest */
289 if (have_flag(f_ptr->flags, FF_SHAFT))
291 /* Create a way back */
292 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP | CFM_SHAFT);
298 /* Create a way back */
299 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_UP);
304 /* Get out from current dungeon */
305 if (current_floor_ptr->dun_level - up_num < d_info[creature_ptr->dungeon_idx].mindepth)
306 up_num = current_floor_ptr->dun_level;
308 if (record_stair) do_cmd_write_nikki(NIKKI_STAIR, 0-up_num, _("階段を上った", "climbed up the stairs to"));
311 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
312 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
313 else if (up_num == current_floor_ptr->dun_level)
314 msg_print(_("地上に戻った。", "You go back to the surface."));
316 msg_print(_("階段を上って新たなる迷宮へと足を踏み入れた。", "You enter a maze of up staircases."));
317 creature_ptr->leaving = TRUE;
322 * @brief 階段を使って階層を降りる処理 / Go down one level
325 void do_cmd_go_down(player_type *creature_ptr)
328 grid_type *g_ptr = ¤t_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
329 feature_type *f_ptr = &f_info[g_ptr->feat];
331 bool fall_trap = FALSE;
334 if (creature_ptr->special_defense & KATA_MUSOU)
336 set_action(ACTION_NONE);
340 if (!have_flag(f_ptr->flags, FF_MORE))
342 msg_print(_("ここには下り階段が見当たらない。", "I see no down staircase here."));
346 if (have_flag(f_ptr->flags, FF_TRAP)) fall_trap = TRUE;
349 if (have_flag(f_ptr->flags, FF_QUEST_ENTER))
354 /* Quest down stairs */
355 else if (have_flag(f_ptr->flags, FF_QUEST))
357 /* Confirm Leaving */
358 if(!confirm_leave_level(creature_ptr, TRUE)) return;
360 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
361 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
363 msg_print(_("下の階に降りた。", "You enter the down staircase."));
368 creature_ptr->inside_quest = g_ptr->special;
370 /* Activate the quest */
371 if (!quest[creature_ptr->inside_quest].status)
373 if (quest[creature_ptr->inside_quest].type != QUEST_TYPE_RANDOM)
375 init_flags = INIT_ASSIGN;
376 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
378 quest[creature_ptr->inside_quest].status = QUEST_STATUS_TAKEN;
381 /* Leaving a quest */
382 if (!creature_ptr->inside_quest)
384 current_floor_ptr->dun_level = 0;
386 creature_ptr->leaving = TRUE;
387 creature_ptr->oldpx = 0;
388 creature_ptr->oldpy = 0;
390 take_turn(creature_ptr, 100);
395 DUNGEON_IDX target_dungeon = 0;
397 if (!current_floor_ptr->dun_level)
399 target_dungeon = have_flag(f_ptr->flags, FF_ENTRANCE) ? g_ptr->special : DUNGEON_ANGBAND;
401 if (ironman_downward && (target_dungeon != DUNGEON_ANGBAND))
403 msg_print(_("ダンジョンの入口は塞がれている!", "The entrance of this dungeon is closed!"));
406 if (!max_dlv[target_dungeon])
408 msg_format(_("ここには%sの入り口(%d階相当)があります", "There is the entrance of %s (Danger level: %d)"),
409 d_name+d_info[target_dungeon].name, d_info[target_dungeon].mindepth);
410 if (!get_check(_("本当にこのダンジョンに入りますか?", "Do you really get in this dungeon? "))) return;
413 /* Save old player position */
414 creature_ptr->oldpx = creature_ptr->x;
415 creature_ptr->oldpy = creature_ptr->y;
416 creature_ptr->dungeon_idx = target_dungeon;
419 * Clear all saved floors
420 * and create a first saved floor
422 prepare_change_floor_mode(CFM_FIRST_FLOOR);
425 take_turn(creature_ptr, 100);
427 if (autosave_l) do_cmd_save_game(TRUE);
430 if (have_flag(f_ptr->flags, FF_SHAFT)) down_num += 2;
433 if (!current_floor_ptr->dun_level)
435 /* Enter the dungeon just now */
436 creature_ptr->enter_dungeon = TRUE;
437 down_num = d_info[creature_ptr->dungeon_idx].mindepth;
442 if (fall_trap) do_cmd_write_nikki(NIKKI_STAIR, down_num, _("落とし戸に落ちた", "fell through a trap door"));
443 else do_cmd_write_nikki(NIKKI_STAIR, down_num, _("階段を下りた", "climbed down the stairs to"));
448 msg_print(_("わざと落とし戸に落ちた。", "You deliberately jump through the trap door."));
455 msg_format(_("%sへ入った。", "You entered %s."), d_text + d_info[creature_ptr->dungeon_idx].text);
459 if ((creature_ptr->pseikaku == SEIKAKU_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
460 msg_print(_("なんだこの階段は!", "What's this STAIRWAY!"));
462 msg_print(_("階段を下りて新たなる迷宮へと足を踏み入れた。", "You enter a maze of down staircases."));
466 creature_ptr->leaving = TRUE;
470 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
474 if (have_flag(f_ptr->flags, FF_SHAFT))
476 /* Create a way back */
477 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_SHAFT);
481 /* Create a way back */
482 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN);
490 * @brief 探索コマンドのメインルーチン / Simple command to "search" for one current_world_ptr->game_turn
493 void do_cmd_search(player_type * creature_ptr)
495 /* Allow repeated command */
498 /* Set repeat count */
499 command_rep = command_arg - 1;
500 creature_ptr->redraw |= (PR_STATE);
505 take_turn(creature_ptr, 100);
507 search(creature_ptr);
512 * @brief 該当のマスに存在している箱のオブジェクトIDを返す。
513 * @param y 走査対象にしたいマスのY座標
514 * @param x 走査対象にしたいマスのX座標
515 * @param trapped TRUEならばトラップが存在する箱のみ、FALSEならば空でない箱全てを対象にする
516 * @return 箱が存在する場合そのオブジェクトID、存在しない場合0を返す。
518 static OBJECT_IDX chest_check(POSITION y, POSITION x, bool trapped)
520 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
521 OBJECT_IDX this_o_idx, next_o_idx = 0;
523 /* Scan all objects in the grid */
524 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
528 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
529 next_o_idx = o_ptr->next_o_idx;
531 /* Skip unknown chests XXX XXX */
532 /* if (!(o_ptr->marked & OM_FOUND)) continue; */
534 /* Check for non empty chest */
535 if ((o_ptr->tval == TV_CHEST) &&
536 (((!trapped) && (o_ptr->pval)) || /* non empty */
537 ((trapped) && (o_ptr->pval > 0)))) /* trapped only */
546 * @brief 箱を開けるコマンドのメインルーチン /
547 * Attempt to open the given chest at the given location
548 * @param y 箱の存在するマスのY座標
549 * @param x 箱の存在するマスのX座標
550 * @param o_idx 箱のオブジェクトID
551 * @return 箱が開かなかった場合TRUE / Returns TRUE if repeated commands may continue
553 * Assume there is no monster blocking the destination
555 static bool do_cmd_open_chest(POSITION y, POSITION x, OBJECT_IDX o_idx)
560 object_type *o_ptr = ¤t_floor_ptr->o_list[o_idx];
562 take_turn(p_ptr, 100);
564 /* Attempt to unlock it */
567 /* Assume locked, and thus not open */
570 /* Get the "disarm" factor */
571 i = p_ptr->skill_dis;
573 /* Penalize some conditions */
574 if (p_ptr->blind || no_lite()) i = i / 10;
575 if (p_ptr->confused || p_ptr->image) i = i / 10;
577 /* Extract the difficulty */
580 /* Always have a small chance of success */
583 /* Success -- May still have traps */
584 if (randint0(100) < j)
586 msg_print(_("鍵をはずした。", "You have picked the lock."));
591 /* Failure -- Keep trying */
594 /* We may continue repeating */
596 if (flush_failure) flush();
597 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
602 /* Allowed to open */
605 /* Apply chest traps, if any */
606 chest_trap(y, x, o_idx);
608 /* Let the Chest drop items */
609 chest_death(FALSE, y, x, o_idx);
615 * @brief プレイヤーの周辺9マスに該当する地形がいくつあるかを返す /
616 * Attempt to open the given chest at the given location
617 * @param y 該当する地形の中から1つのY座標を返す参照ポインタ
618 * @param x 該当する地形の中から1つのX座標を返す参照ポインタ
619 * @param test 地形条件を判定するための関数ポインタ
620 * @param under TRUEならばプレイヤーの直下の座標も走査対象にする
622 * @details Return the number of features around (or under) the character.
623 * Usually look for doors and floor traps.
625 static int count_dt(POSITION *y, POSITION *x, bool (*test)(FEAT_IDX feat), bool under)
631 /* Count how many matches */
634 /* Check around (and under) the character */
635 for (d = 0; d < 9; d++)
640 /* if not searching under player continue */
641 if ((d == 8) && !under) continue;
643 /* Extract adjacent (legal) location */
644 yy = p_ptr->y + ddy_ddd[d];
645 xx = p_ptr->x + ddx_ddd[d];
647 /* Get the current_floor_ptr->grid_array */
648 g_ptr = ¤t_floor_ptr->grid_array[yy][xx];
650 /* Must have knowledge */
651 if (!(g_ptr->info & (CAVE_MARK))) continue;
653 /* Feature code (applying "mimic" field) */
654 feat = get_feat_mimic(g_ptr);
656 /* Not looking for this feature */
657 if (!((*test)(feat))) continue;
662 /* Remember the location. Only useful if only one match */
673 * @brief プレイヤーの周辺9マスに箱のあるマスがいくつあるかを返す /
674 * Return the number of chests around (or under) the character.
675 * @param y 該当するマスの中から1つのY座標を返す参照ポインタ
676 * @param x 該当するマスの中から1つのX座標を返す参照ポインタ
677 * @param trapped TRUEならばトラップの存在が判明している箱のみ対象にする
680 * If requested, count only trapped chests.
682 static int count_chests(player_type *creature_ptr, POSITION *y, POSITION *x, bool trapped)
689 /* Count how many matches */
692 /* Check around (and under) the character */
693 for (d = 0; d < 9; d++)
695 /* Extract adjacent (legal) location */
696 POSITION yy = creature_ptr->y + ddy_ddd[d];
697 POSITION xx = creature_ptr->x + ddx_ddd[d];
699 /* No (visible) chest is there */
700 if ((o_idx = chest_check(yy, xx, FALSE)) == 0) continue;
702 /* Grab the object */
703 o_ptr = ¤t_floor_ptr->o_list[o_idx];
706 if (o_ptr->pval == 0) continue;
708 /* No (known) traps here */
709 if (trapped && (!object_is_known(o_ptr) ||
710 !chest_traps[o_ptr->pval])) continue;
715 /* Remember the location. Only useful if only one match */
727 * @brief 「開ける」動作コマンドのサブルーチン /
728 * Perform the basic "open" command on doors
729 * @param y 対象を行うマスのY座標
730 * @param x 対象を行うマスのX座標
731 * @return 実際に処理が行われた場合TRUEを返す。
733 * Assume destination is a closed/locked/jammed door
734 * Assume there is no monster blocking the destination
735 * Returns TRUE if repeated commands may continue
737 static bool do_cmd_open_aux(POSITION y, POSITION x)
741 /* Get requested grid */
742 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
743 feature_type *f_ptr = &f_info[g_ptr->feat];
746 take_turn(p_ptr, 100);
748 /* Seeing true feature code (ignore mimic) */
751 if (!have_flag(f_ptr->flags, FF_OPEN))
754 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(g_ptr)].name);
758 else if (f_ptr->power)
761 i = p_ptr->skill_dis;
763 /* Penalize some conditions */
764 if (p_ptr->blind || no_lite()) i = i / 10;
765 if (p_ptr->confused || p_ptr->image) i = i / 10;
767 /* Extract the lock power */
770 /* Extract the difficulty */
773 /* Always have a small chance of success */
777 if (randint0(100) < j)
779 msg_print(_("鍵をはずした。", "You have picked the lock."));
782 cave_alter_feat(y, x, FF_OPEN);
784 sound(SOUND_OPENDOOR);
794 if (flush_failure) flush();
796 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
798 /* We may keep trying */
807 cave_alter_feat(y, x, FF_OPEN);
809 sound(SOUND_OPENDOOR);
815 * @brief 「開ける」コマンドのメインルーチン /
816 * Open a closed/locked/jammed door or a closed/locked chest.
819 * Unlocking a locked door/chest is worth one experience point.
821 void do_cmd_open(player_type *creature_ptr)
829 if (creature_ptr->wild_mode) return;
831 if (creature_ptr->special_defense & KATA_MUSOU)
833 set_action(ACTION_NONE);
836 /* Option: Pick a direction */
839 int num_doors, num_chests;
841 num_doors = count_dt(&y, &x, is_closed_door, FALSE);
842 num_chests = count_chests(creature_ptr, &y, &x, FALSE);
843 if (num_doors || num_chests)
845 bool too_many = (num_doors && num_chests) || (num_doors > 1) ||
847 if (!too_many) command_dir = coords_to_dir(y, x);
851 /* Allow repeated command */
854 /* Set repeat count */
855 command_rep = command_arg - 1;
856 creature_ptr->redraw |= (PR_STATE);
862 /* Get a "repeated" direction */
863 if (get_rep_dir(&dir, TRUE))
868 /* Get requested location */
869 y = creature_ptr->y + ddy[dir];
870 x = creature_ptr->x + ddx[dir];
872 /* Get requested grid */
873 g_ptr = ¤t_floor_ptr->grid_array[y][x];
875 /* Feature code (applying "mimic" field) */
876 feat = get_feat_mimic(g_ptr);
878 /* Check for chest */
879 o_idx = chest_check(y, x, FALSE);
881 if (!have_flag(f_info[feat].flags, FF_OPEN) && !o_idx)
883 msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
885 else if (g_ptr->m_idx && creature_ptr->riding != g_ptr->m_idx)
887 take_turn(creature_ptr, 100);
888 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
893 more = do_cmd_open_chest(y, x, o_idx);
897 more = do_cmd_open_aux(y, x);
901 /* Cancel repeat unless we may continue */
902 if (!more) disturb(FALSE, FALSE);
908 * @brief 「閉じる」動作コマンドのサブルーチン /
909 * Perform the basic "close" command
910 * @param y 対象を行うマスのY座標
911 * @param x 対象を行うマスのX座標
912 * @return 実際に処理が行われた場合TRUEを返す。
914 * Assume destination is an open/broken door
915 * Assume there is no monster blocking the destination
916 * Returns TRUE if repeated commands may continue
918 static bool do_cmd_close_aux(POSITION y, POSITION x)
920 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
921 FEAT_IDX old_feat = g_ptr->feat;
924 take_turn(p_ptr, 100);
926 /* Seeing true feature code (ignore mimic) */
929 if (have_flag(f_info[old_feat].flags, FF_CLOSE))
931 s16b closed_feat = feat_state(old_feat, FF_CLOSE);
933 /* Hack -- object in the way */
934 if ((g_ptr->o_idx || (g_ptr->info & CAVE_OBJECT)) &&
935 (closed_feat != old_feat) && !have_flag(f_info[closed_feat].flags, FF_DROP))
937 msg_print(_("何かがつっかえて閉まらない。", "There seems stuck."));
942 cave_alter_feat(y, x, FF_CLOSE);
945 if (old_feat == g_ptr->feat)
947 msg_print(_("ドアは壊れてしまっている。", "The door appears to be broken."));
951 sound(SOUND_SHUTDOOR);
960 * @brief 「閉じる」コマンドのメインルーチン /
961 * Close an open door.
964 * Unlocking a locked door/chest is worth one experience point.
966 void do_cmd_close(void)
973 if (p_ptr->wild_mode) return;
975 if (p_ptr->special_defense & KATA_MUSOU)
977 set_action(ACTION_NONE);
980 /* Option: Pick a direction */
983 /* Count open doors */
984 if (count_dt(&y, &x, is_open, FALSE) == 1)
986 command_dir = coords_to_dir(y, x);
990 /* Allow repeated command */
993 /* Set repeat count */
994 command_rep = command_arg - 1;
995 p_ptr->redraw |= (PR_STATE);
1001 /* Get a "repeated" direction */
1002 if (get_rep_dir(&dir, FALSE))
1007 y = p_ptr->y + ddy[dir];
1008 x = p_ptr->x + ddx[dir];
1009 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1011 /* Feature code (applying "mimic" field) */
1012 feat = get_feat_mimic(g_ptr);
1014 /* Require open/broken door */
1015 if (!have_flag(f_info[feat].flags, FF_CLOSE))
1017 msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
1020 /* Monster in the way */
1021 else if (g_ptr->m_idx)
1023 take_turn(p_ptr, 100);
1025 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1031 /* Close the door */
1034 /* Close the door */
1035 more = do_cmd_close_aux(y, x);
1039 /* Cancel repeat unless we may continue */
1040 if (!more) disturb(FALSE, FALSE);
1045 * @brief 「掘る」コマンドを該当のマスに行えるかの判定と結果メッセージの表示 /
1046 * Determine if a given grid may be "tunneled"
1047 * @param y 対象を行うマスのY座標
1048 * @param x 対象を行うマスのX座標
1051 static bool do_cmd_tunnel_test(POSITION y, POSITION x)
1053 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1055 /* Must have knowledge */
1056 if (!(g_ptr->info & CAVE_MARK))
1058 msg_print(_("そこには何も見当たらない。", "You see nothing there."));
1063 /* Must be a wall/door/etc */
1064 if (!cave_have_flag_grid(g_ptr, FF_TUNNEL))
1066 msg_print(_("そこには掘るものが見当たらない。", "You see nothing there to tunnel."));
1076 * @brief 「掘る」動作コマンドのサブルーチン /
1077 * Perform the basic "tunnel" command
1078 * @param y 対象を行うマスのY座標
1079 * @param x 対象を行うマスのX座標
1080 * @return 実際に処理が行われた場合TRUEを返す。
1082 * Assumes that no monster is blocking the destination
1083 * Do not use twall anymore
1084 * Returns TRUE if repeated commands may continue
1086 static bool do_cmd_tunnel_aux(POSITION y, POSITION x)
1089 feature_type *f_ptr, *mimic_f_ptr;
1094 /* Verify legality */
1095 if (!do_cmd_tunnel_test(y, x)) return (FALSE);
1097 take_turn(p_ptr, 100);
1099 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1100 f_ptr = &f_info[g_ptr->feat];
1101 power = f_ptr->power;
1103 /* Feature code (applying "mimic" field) */
1104 mimic_f_ptr = &f_info[get_feat_mimic(g_ptr)];
1106 name = f_name + mimic_f_ptr->name;
1110 if (have_flag(f_ptr->flags, FF_PERMANENT))
1113 if (have_flag(mimic_f_ptr->flags, FF_PERMANENT))
1115 msg_print(_("この岩は硬すぎて掘れないようだ。", "This seems to be permanent rock."));
1118 /* Map border (mimiccing Permanent wall) */
1121 msg_print(_("そこは掘れない!", "You can't tunnel through that!"));
1126 else if (have_flag(f_ptr->flags, FF_CAN_DIG))
1129 if (p_ptr->skill_dig > randint0(20 * power))
1131 msg_format(_("%sをくずした。", "You have removed the %s."), name);
1133 /* Remove the feature */
1134 cave_alter_feat(y, x, FF_TUNNEL);
1135 p_ptr->update |= (PU_FLOW);
1139 /* Message, keep digging */
1140 msg_format(_("%sをくずしている。", "You dig into the %s."), name);
1148 bool tree = have_flag(mimic_f_ptr->flags, FF_TREE);
1151 if (p_ptr->skill_dig > power + randint0(40 * power))
1153 if (tree) msg_format(_("%sを切り払った。", "You have cleared away the %s."), name);
1156 msg_print(_("穴を掘り終えた。", "You have finished the tunnel."));
1157 p_ptr->update |= (PU_FLOW);
1160 if (have_flag(f_ptr->flags, FF_GLASS)) sound(SOUND_GLASS);
1162 /* Remove the feature */
1163 cave_alter_feat(y, x, FF_TUNNEL);
1165 chg_virtue(V_DILIGENCE, 1);
1166 chg_virtue(V_NATURE, -1);
1174 /* We may continue chopping */
1175 msg_format(_("%sを切っている。", "You chop away at the %s."), name);
1176 /* Occasional Search XXX XXX */
1177 if (randint0(100) < 25) search(p_ptr);
1181 /* We may continue tunelling */
1182 msg_format(_("%sに穴を掘っている。", "You tunnel into the %s."), name);
1189 if (is_hidden_door(g_ptr))
1191 /* Occasional Search XXX XXX */
1192 if (randint0(100) < 25) search(p_ptr);
1199 * @brief 「掘る」動作コマンドのメインルーチン /
1200 * Tunnels through "walls" (including rubble and closed doors)
1204 * Note that you must tunnel in order to hit invisible monsters
1205 * in walls, though moving into walls still takes a current_world_ptr->game_turn anyway.
1207 * Digging is very difficult without a "digger" weapon, but can be
1208 * accomplished by strong players using heavy weapons.
1211 void do_cmd_tunnel(void)
1220 if (p_ptr->special_defense & KATA_MUSOU)
1222 set_action(ACTION_NONE);
1225 /* Allow repeated command */
1228 /* Set repeat count */
1229 command_rep = command_arg - 1;
1230 p_ptr->redraw |= (PR_STATE);
1232 /* Cancel the arg */
1236 /* Get a direction to tunnel, or Abort */
1237 if (get_rep_dir(&dir,FALSE))
1240 y = p_ptr->y + ddy[dir];
1241 x = p_ptr->x + ddx[dir];
1243 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1245 /* Feature code (applying "mimic" field) */
1246 feat = get_feat_mimic(g_ptr);
1248 /* No tunnelling through doors */
1249 if (have_flag(f_info[feat].flags, FF_DOOR))
1251 msg_print(_("ドアは掘れない。", "You cannot tunnel through doors."));
1254 /* No tunnelling through most features */
1255 else if (!have_flag(f_info[feat].flags, FF_TUNNEL))
1257 msg_print(_("そこは掘れない。", "You can't tunnel through that."));
1260 /* A monster is in the way */
1261 else if (g_ptr->m_idx)
1263 take_turn(p_ptr, 100);
1265 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1274 /* Tunnel through walls */
1275 more = do_cmd_tunnel_aux(y, x);
1279 /* Cancel repetition unless we can continue */
1280 if (!more) disturb(FALSE, FALSE);
1284 * @brief 移動処理による簡易な「開く」処理 /
1286 * @return 開く処理が実際に試みられた場合TRUEを返す
1289 * If there is a jammed/closed/locked door at the given location,
1290 * then attempt to unlock/open it. Return TRUE if an attempt was
1291 * made (successful or not), otherwise return FALSE.
1293 * The code here should be nearly identical to that in
1294 * do_cmd_open_test() and do_cmd_open_aux().
1297 bool easy_open_door(POSITION y, POSITION x)
1301 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1302 feature_type *f_ptr = &f_info[g_ptr->feat];
1304 /* Must be a closed door */
1305 if (!is_closed_door(g_ptr->feat))
1311 if (!have_flag(f_ptr->flags, FF_OPEN))
1314 msg_format(_("%sはがっちりと閉じられているようだ。", "The %s appears to be stuck."), f_name + f_info[get_feat_mimic(g_ptr)].name);
1319 else if (f_ptr->power)
1322 i = p_ptr->skill_dis;
1324 /* Penalize some conditions */
1325 if (p_ptr->blind || no_lite()) i = i / 10;
1326 if (p_ptr->confused || p_ptr->image) i = i / 10;
1328 /* Extract the lock power */
1331 /* Extract the difficulty */
1334 /* Always have a small chance of success */
1338 if (randint0(100) < j)
1340 msg_print(_("鍵をはずした。", "You have picked the lock."));
1343 cave_alter_feat(y, x, FF_OPEN);
1345 sound(SOUND_OPENDOOR);
1355 if (flush_failure) flush();
1357 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
1366 cave_alter_feat(y, x, FF_OPEN);
1368 sound(SOUND_OPENDOOR);
1374 * @brief 箱のトラップを解除するコマンドのメインルーチン /
1375 * Perform the basic "disarm" command
1376 * @param y 解除を行うマスのY座標
1377 * @param x 解除を行うマスのX座標
1378 * @param o_idx 箱のオブジェクトID
1379 * @return ターンを消費する処理が行われた場合TRUEを返す
1382 * Assume destination is a visible trap
1383 * Assume there is no monster blocking the destination
1384 * Returns TRUE if repeated commands may continue
1387 static bool do_cmd_disarm_chest(POSITION y, POSITION x, OBJECT_IDX o_idx)
1391 object_type *o_ptr = ¤t_floor_ptr->o_list[o_idx];
1393 take_turn(p_ptr, 100);
1395 /* Get the "disarm" factor */
1396 i = p_ptr->skill_dis;
1398 /* Penalize some conditions */
1399 if (p_ptr->blind || no_lite()) i = i / 10;
1400 if (p_ptr->confused || p_ptr->image) i = i / 10;
1402 /* Extract the difficulty */
1403 j = i - o_ptr->pval;
1405 /* Always have a small chance of success */
1408 /* Must find the trap first. */
1409 if (!object_is_known(o_ptr))
1411 msg_print(_("トラップが見あたらない。", "I don't see any traps."));
1415 /* Already disarmed/unlocked */
1416 else if (o_ptr->pval <= 0)
1418 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1421 /* No traps to find. */
1422 else if (!chest_traps[o_ptr->pval])
1424 msg_print(_("箱にはトラップが仕掛けられていない。", "The chest is not trapped."));
1427 /* Success (get a lot of experience) */
1428 else if (randint0(100) < j)
1430 msg_print(_("箱に仕掛けられていたトラップを解除した。", "You have disarmed the chest."));
1431 gain_exp(o_ptr->pval);
1432 o_ptr->pval = (0 - o_ptr->pval);
1435 /* Failure -- Keep trying */
1436 else if ((i > 5) && (randint1(i) > 5))
1438 /* We may keep trying */
1440 if (flush_failure) flush();
1441 msg_print(_("箱のトラップ解除に失敗した。", "You failed to disarm the chest."));
1444 /* Failure -- Set off the trap */
1447 msg_print(_("トラップを作動させてしまった!", "You set off a trap!"));
1449 chest_trap(y, x, o_idx);
1456 * @brief 箱のトラップを解除するコマンドのサブルーチン /
1457 * Perform the basic "disarm" command
1458 * @param y 解除を行うマスのY座標
1459 * @param x 解除を行うマスのX座標
1460 * @param dir プレイヤーからみた方向ID
1461 * @return ターンを消費する処理が行われた場合TRUEを返す
1464 * Assume destination is a visible trap
1465 * Assume there is no monster blocking the destination
1466 * Returns TRUE if repeated commands may continue
1470 bool do_cmd_disarm_aux(POSITION y, POSITION x, DIRECTION dir)
1472 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1475 feature_type *f_ptr = &f_info[g_ptr->feat];
1477 /* Access trap name */
1478 concptr name = (f_name + f_ptr->name);
1480 /* Extract trap "power" */
1481 int power = f_ptr->power;
1484 /* Get the "disarm" factor */
1485 int i = p_ptr->skill_dis;
1488 take_turn(p_ptr, 100);
1490 /* Penalize some conditions */
1491 if (p_ptr->blind || no_lite()) i = i / 10;
1492 if (p_ptr->confused || p_ptr->image) i = i / 10;
1494 /* Extract the difficulty */
1497 /* Always have a small chance of success */
1501 if (randint0(100) < j)
1503 msg_format(_("%sを解除した。", "You have disarmed the %s."), name);
1508 /* Remove the trap */
1509 cave_alter_feat(y, x, FF_DISARM);
1511 /* Move the player onto the trap */
1512 move_player(dir, easy_disarm, FALSE);
1515 /* Failure -- Keep trying */
1516 else if ((i > 5) && (randint1(i) > 5))
1519 if (flush_failure) flush();
1521 msg_format(_("%sの解除に失敗した。", "You failed to disarm the %s."), name);
1523 /* We may keep trying */
1527 /* Failure -- Set off the trap */
1530 msg_format(_("%sを作動させてしまった!", "You set off the %s!"), name);
1531 /* Move the player onto the trap */
1532 move_player(dir, easy_disarm, FALSE);
1539 * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
1540 * Disarms a trap, or chest
1543 void do_cmd_disarm(void)
1551 if (p_ptr->wild_mode) return;
1553 if (p_ptr->special_defense & KATA_MUSOU)
1555 set_action(ACTION_NONE);
1558 /* Option: Pick a direction */
1561 int num_traps, num_chests;
1563 /* Count visible traps */
1564 num_traps = count_dt(&y, &x, is_trap, TRUE);
1566 /* Count chests (trapped) */
1567 num_chests = count_chests(p_ptr, &y, &x, TRUE);
1569 /* See if only one target */
1570 if (num_traps || num_chests)
1572 bool too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
1573 if (!too_many) command_dir = coords_to_dir(y, x);
1578 /* Allow repeated command */
1581 /* Set repeat count */
1582 command_rep = command_arg - 1;
1583 p_ptr->redraw |= (PR_STATE);
1585 /* Cancel the arg */
1589 /* Get a direction (or abort) */
1590 if (get_rep_dir(&dir,TRUE))
1595 y = p_ptr->y + ddy[dir];
1596 x = p_ptr->x + ddx[dir];
1597 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1599 /* Feature code (applying "mimic" field) */
1600 feat = get_feat_mimic(g_ptr);
1602 /* Check for chests */
1603 o_idx = chest_check(y, x, TRUE);
1606 if (!is_trap(feat) && !o_idx)
1608 msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
1611 /* Monster in the way */
1612 else if (g_ptr->m_idx && p_ptr->riding != g_ptr->m_idx)
1614 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1623 more = do_cmd_disarm_chest(y, x, o_idx);
1629 more = do_cmd_disarm_aux(y, x, dir);
1633 /* Cancel repeat unless told not to */
1634 if (!more) disturb(FALSE, FALSE);
1639 * @brief 「打ち破る」動作コマンドのサブルーチン /
1640 * Perform the basic "bash" command
1641 * @param y 対象を行うマスのY座標
1642 * @param x 対象を行うマスのX座標
1643 * @param dir プレイヤーから見たターゲットの方角ID
1644 * @return 実際に処理が行われた場合TRUEを返す。
1647 * Assume destination is a closed/locked/jammed door
1648 * Assume there is no monster blocking the destination
1649 * Returns TRUE if repeated commands may continue
1652 static bool do_cmd_bash_aux(POSITION y, POSITION x, DIRECTION dir)
1654 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1657 feature_type *f_ptr = &f_info[g_ptr->feat];
1659 /* Hack -- Bash power based on strength */
1660 /* (Ranges from 3 to 20 to 100 to 200) */
1661 int bash = adj_str_blow[p_ptr->stat_ind[A_STR]];
1663 /* Extract door power */
1664 int temp = f_ptr->power;
1668 concptr name = f_name + f_info[get_feat_mimic(g_ptr)].name;
1670 take_turn(p_ptr, 100);
1672 msg_format(_("%sに体当たりをした!", "You smash into the %s!"), name);
1674 /* Compare bash power to door power */
1675 temp = (bash - (temp * 10));
1677 if (p_ptr->pclass == CLASS_BERSERKER) temp *= 2;
1679 /* Hack -- always have a chance */
1680 if (temp < 1) temp = 1;
1682 /* Hack -- attempt to bash down the door */
1683 if (randint0(100) < temp)
1685 msg_format(_("%sを壊した!", "The %s crashes open!"), name);
1687 sound(have_flag(f_ptr->flags, FF_GLASS) ? SOUND_GLASS : SOUND_OPENDOOR);
1689 /* Break down the door */
1690 if ((randint0(100) < 50) || (feat_state(g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS))
1692 cave_alter_feat(y, x, FF_BASH);
1698 cave_alter_feat(y, x, FF_OPEN);
1701 /* Hack -- Fall through the door */
1702 move_player(dir, FALSE, FALSE);
1705 /* Saving throw against stun */
1706 else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
1709 msg_format(_("この%sは頑丈だ。", "The %s holds firm."), name);
1711 /* Allow repeated bashing */
1715 /* High dexterity yields coolness */
1718 msg_print(_("体のバランスをくずしてしまった。", "You are off-balance."));
1720 /* Hack -- Lose balance ala paralysis */
1721 (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
1728 * @brief 「打ち破る」動作コマンドのメインルーチン /
1729 * Bash open a door, success based on character strength
1733 * For a closed door, pval is positive if locked; negative if stuck.
1735 * For an open door, pval is positive for a broken door.
1737 * A closed door can be opened - harder if locked. Any door might be
1738 * bashed open (and thereby broken). Bashing a door is (potentially)
1739 * faster! You move into the door way. To open a stuck door, it must
1740 * be bashed. A closed door can be jammed (see do_cmd_spike()).
1742 * Creatures can also open or bash doors, see elsewhere.
1745 void do_cmd_bash(void)
1751 if (p_ptr->wild_mode) return;
1753 if (p_ptr->special_defense & KATA_MUSOU)
1755 set_action(ACTION_NONE);
1758 /* Allow repeated command */
1761 /* Set repeat count */
1762 command_rep = command_arg - 1;
1763 p_ptr->redraw |= (PR_STATE);
1765 /* Cancel the arg */
1769 /* Get a "repeated" direction */
1770 if (get_rep_dir(&dir,FALSE))
1775 y = p_ptr->y + ddy[dir];
1776 x = p_ptr->x + ddx[dir];
1778 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1780 /* Feature code (applying "mimic" field) */
1781 feat = get_feat_mimic(g_ptr);
1783 /* Nothing useful */
1784 if (!have_flag(f_info[feat].flags, FF_BASH))
1786 msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
1789 /* Monster in the way */
1790 else if (g_ptr->m_idx)
1792 take_turn(p_ptr, 100);
1794 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
1800 /* Bash a closed door */
1804 more = do_cmd_bash_aux(y, x, dir);
1808 /* Unless valid action taken, cancel bash */
1809 if (!more) disturb(FALSE, FALSE);
1814 * @brief 特定のマスに影響を及ぼすための汎用的コマンド
1818 * Manipulate an adjacent grid in some way
1820 * Attack monsters, tunnel through walls, disarm traps, open doors.
1822 * Consider confusion
1824 * This command must always take a current_world_ptr->game_turn, to prevent free detection
1825 * of invisible monsters.
1828 void do_cmd_alter(void)
1835 if (p_ptr->special_defense & KATA_MUSOU)
1837 set_action(ACTION_NONE);
1840 /* Allow repeated command */
1843 /* Set repeat count */
1844 command_rep = command_arg - 1;
1845 p_ptr->redraw |= (PR_STATE);
1847 /* Cancel the arg */
1851 /* Get a direction */
1852 if (get_rep_dir(&dir,TRUE))
1855 feature_type *f_ptr;
1857 y = p_ptr->y + ddy[dir];
1858 x = p_ptr->x + ddx[dir];
1860 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1862 /* Feature code (applying "mimic" field) */
1863 feat = get_feat_mimic(g_ptr);
1864 f_ptr = &f_info[feat];
1866 take_turn(p_ptr, 100);
1874 else if (have_flag(f_ptr->flags, FF_OPEN))
1876 more = do_cmd_open_aux(y, x);
1879 /* Bash jammed doors */
1880 else if (have_flag(f_ptr->flags, FF_BASH))
1882 more = do_cmd_bash_aux(y, x, dir);
1885 /* Tunnel through walls */
1886 else if (have_flag(f_ptr->flags, FF_TUNNEL))
1888 more = do_cmd_tunnel_aux(y, x);
1891 /* Close open doors */
1892 else if (have_flag(f_ptr->flags, FF_CLOSE))
1894 more = do_cmd_close_aux(y, x);
1898 else if (have_flag(f_ptr->flags, FF_DISARM))
1900 more = do_cmd_disarm_aux(y, x, dir);
1905 msg_print(_("何もない空中を攻撃した。", "You attack the empty air."));
1909 /* Cancel repetition unless we can continue */
1910 if (!more) disturb(FALSE, FALSE);
1916 * @brief 「くさびを打つ」ために必要なオブジェクトがあるかどうかの判定を返す /
1917 * Find the index of some "spikes", if possible.
1918 * @param ip くさびとして打てるオブジェクトのID
1919 * @return オブジェクトがある場合TRUEを返す
1922 * Let user choose a pile of spikes, perhaps?
1925 static bool get_spike(INVENTORY_IDX *ip)
1929 /* Check every item in the pack */
1930 for (i = 0; i < INVEN_PACK; i++)
1932 object_type *o_ptr = &p_ptr->inventory_list[i];
1933 if (!o_ptr->k_idx) continue;
1935 /* Check the "tval" code */
1936 if (o_ptr->tval == TV_SPIKE)
1938 /* Save the spike index */
1951 * @brief 「くさびを打つ」動作コマンドのメインルーチン /
1952 * Jam a closed door with a spike
1956 * This command may NOT be repeated
1959 void do_cmd_spike(void)
1963 if (p_ptr->wild_mode) return;
1965 if (p_ptr->special_defense & KATA_MUSOU)
1967 set_action(ACTION_NONE);
1970 /* Get a "repeated" direction */
1971 if (get_rep_dir(&dir, FALSE))
1978 y = p_ptr->y + ddy[dir];
1979 x = p_ptr->x + ddx[dir];
1980 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1982 /* Feature code (applying "mimic" field) */
1983 feat = get_feat_mimic(g_ptr);
1985 /* Require closed door */
1986 if (!have_flag(f_info[feat].flags, FF_SPIKE))
1988 msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
1992 else if (!get_spike(&item))
1994 msg_print(_("くさびを持っていない!", "You have no spikes!"));
1997 /* Is a monster in the way? */
1998 else if (g_ptr->m_idx)
2000 take_turn(p_ptr, 100);
2002 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
2011 take_turn(p_ptr, 100);
2013 /* Successful jamming */
2014 msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), f_name + f_info[feat].name);
2015 cave_alter_feat(y, x, FF_SPIKE);
2017 /* Use up, and describe, a single spike, from the bottom */
2018 inven_item_increase(item, -1);
2019 inven_item_describe(item);
2020 inven_item_optimize(item);
2028 * @brief 「歩く」動作コマンドのメインルーチン /
2029 * Support code for the "Walk" and "Jump" commands
2030 * @param pickup アイテムの自動拾いを行うならTRUE
2033 void do_cmd_walk(bool pickup)
2040 /* Allow repeated command */
2043 /* Set repeat count */
2044 command_rep = command_arg - 1;
2045 p_ptr->redraw |= (PR_STATE);
2047 /* Cancel the arg */
2051 /* Get a "repeated" direction */
2052 if (get_rep_dir(&dir, FALSE))
2054 take_turn(p_ptr, 100);
2056 if ((dir != 5) && (p_ptr->special_defense & KATA_MUSOU))
2058 set_action(ACTION_NONE);
2061 /* Hack -- In small scale wilderness it takes MUCH more time to move */
2062 if (p_ptr->wild_mode) p_ptr->energy_use *= ((MAX_HGT + MAX_WID) / 2);
2063 if (p_ptr->action == ACTION_HAYAGAKE) p_ptr->energy_use = p_ptr->energy_use * (45-(p_ptr->lev/2)) / 100;
2065 /* Actually move the character */
2066 move_player(dir, pickup, FALSE);
2068 /* Allow more walking */
2072 /* Hack again -- Is there a special encounter ??? */
2073 if (p_ptr->wild_mode && !cave_have_flag_bold(p_ptr->y, p_ptr->x, FF_TOWN))
2075 int tmp = 120 + p_ptr->lev*10 - wilderness[p_ptr->y][p_ptr->x].level + 5;
2078 if (((wilderness[p_ptr->y][p_ptr->x].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
2080 /* Inform the player of his horrible fate :=) */
2081 msg_print(_("襲撃だ!", "You are ambushed !"));
2083 /* Go into large wilderness view */
2084 p_ptr->oldpy = randint1(MAX_HGT-2);
2085 p_ptr->oldpx = randint1(MAX_WID-2);
2086 change_wild_mode(TRUE);
2088 /* Give first move to monsters */
2089 take_turn(p_ptr, 100);
2094 /* Cancel repeat unless we may continue */
2095 if (!more) disturb(FALSE, FALSE);
2100 * @brief 「走る」動作コマンドのメインルーチン /
2104 void do_cmd_run(void)
2107 if (cmd_limit_confused(p_ptr)) return;
2109 if (p_ptr->special_defense & KATA_MUSOU)
2111 set_action(ACTION_NONE);
2114 /* Get a "repeated" direction */
2115 if (get_rep_dir(&dir,FALSE))
2117 /* Hack -- Set the run counter */
2118 p_ptr->running = (command_arg ? command_arg : 1000);
2127 * @brief 「留まる」動作コマンドのメインルーチン /
2128 * Stay still. Search. Enter stores.
2129 * Pick up treasure if "pickup" is true.
2130 * @param pickup アイテムの自動拾いを行うならTRUE
2133 void do_cmd_stay(bool pickup)
2135 u32b mpe_mode = MPE_STAYING | MPE_ENERGY_USE;
2137 /* Allow repeated command */
2140 /* Set repeat count */
2141 command_rep = command_arg - 1;
2142 p_ptr->redraw |= (PR_STATE);
2144 /* Cancel the arg */
2148 take_turn(p_ptr, 100);
2150 if (pickup) mpe_mode |= MPE_DO_PICKUP;
2151 (void)move_player_effect(p_ptr->y, p_ptr->x, mpe_mode);
2156 * @brief 「休む」動作コマンドのメインルーチン /
2157 * Resting allows a player to safely restore his hp -RAK-
2160 void do_cmd_rest(void)
2163 set_action(ACTION_NONE);
2165 if ((p_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(p_ptr) || INTERUPTING_SONG_EFFECT(p_ptr)))
2167 stop_singing(p_ptr);
2171 if (hex_spelling_any()) stop_hex_spell_all();
2173 /* Prompt for time if needed */
2174 if (command_arg <= 0)
2176 concptr p = _("休憩 (0-9999, '*' で HP/MP全快, '&' で必要なだけ): ",
2177 "Rest (0-9999, '*' for HP/SP, '&' as needed): ");
2183 strcpy(out_val, "&");
2185 /* Ask for duration */
2186 if (!get_string(p, out_val, 4)) return;
2188 /* Rest until done */
2189 if (out_val[0] == '&')
2191 command_arg = COMMAND_ARG_REST_UNTIL_DONE;
2195 else if (out_val[0] == '*')
2197 command_arg = COMMAND_ARG_REST_FULL_HEALING;
2203 command_arg = (COMMAND_ARG)atoi(out_val);
2204 if (command_arg <= 0) return;
2208 if (command_arg > 9999) command_arg = 9999;
2210 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
2212 /* Take a current_world_ptr->game_turn (?) */
2213 take_turn(p_ptr, 100);
2215 /* The sin of sloth */
2216 if (command_arg > 100) chg_virtue(V_DILIGENCE, -1);
2218 /* Why are you sleeping when there's no need? WAKE UP!*/
2219 if ((p_ptr->chp == p_ptr->mhp) &&
2220 (p_ptr->csp == p_ptr->msp) &&
2221 !p_ptr->blind && !p_ptr->confused &&
2222 !p_ptr->poisoned && !p_ptr->afraid &&
2223 !p_ptr->stun && !p_ptr->cut &&
2224 !p_ptr->slow && !p_ptr->paralyzed &&
2225 !p_ptr->image && !p_ptr->word_recall &&
2226 !p_ptr->alter_reality)
2227 chg_virtue(V_DILIGENCE, -1);
2229 /* Save the rest code */
2230 p_ptr->resting = command_arg;
2231 p_ptr->action = ACTION_REST;
2232 p_ptr->update |= (PU_BONUS);
2233 update_creature(p_ptr);
2235 p_ptr->redraw |= (PR_STATE);
2244 * @brief 射撃処理のメインルーチン
2247 void do_cmd_fire(SPELL_IDX snipe_type)
2250 object_type *j_ptr, *ammo_ptr;
2253 if(p_ptr->wild_mode) return;
2255 p_ptr->is_fired = FALSE; /* not fired yet */
2257 /* Get the "bow" (if any) */
2258 j_ptr = &p_ptr->inventory_list[INVEN_BOW];
2260 /* Require a launcher */
2263 msg_print(_("射撃用の武器を持っていない。", "You have nothing to fire with."));
2268 if (j_ptr->sval == SV_CRIMSON)
2270 msg_print(_("この武器は発動して使うもののようだ。", "Do activate."));
2275 if (j_ptr->sval == SV_HARP)
2277 msg_print(_("この武器で射撃はできない。", "It's not for firing."));
2283 if (p_ptr->special_defense & KATA_MUSOU)
2285 set_action(ACTION_NONE);
2288 q = _("どれを撃ちますか? ", "Fire which item? ");
2289 s = _("発射されるアイテムがありません。", "You have nothing to fire.");
2291 ammo_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR), p_ptr->tval_ammo);
2299 exe_fire(item, j_ptr, snipe_type);
2301 if (!p_ptr->is_fired || p_ptr->pclass != CLASS_SNIPER) return;
2303 /* Sniper actions after some shootings */
2304 if (snipe_type == SP_AWAY)
2306 teleport_player(10 + (p_ptr->concent * 2), 0L);
2308 if (snipe_type == SP_FINAL)
2310 msg_print(_("射撃の反動が体を襲った。", "A reactionary of shooting attacked you. "));
2311 (void)set_slow(p_ptr->slow + randint0(7) + 7, FALSE);
2312 (void)set_stun(p_ptr->stun + randint1(25));
2318 * @brief 投射処理メインルーチン /
2319 * Throw an object from the pack or floor.
2321 * @param boomerang ブーメラン処理ならばTRUE
2322 * @param shuriken 忍者の手裏剣処理ならばTRUE
2323 * @return ターンを消費した場合TRUEを返す
2326 * Note: "unseen" monsters are very hard to hit.
2328 * Should throwing a weapon do full damage? Should it allow the magic
2329 * to hit bonus of the weapon to have an effect? Should it ever cause
2330 * the item to be destroyed? Should it do any damage at all?
2333 bool do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
2338 POSITION y, x, ty, tx, prev_y, prev_x;
2339 POSITION ny[19], nx[19];
2340 int chance, tdam, tdis;
2341 int mul, div, dd, ds;
2342 int cur_dis, visible;
2349 bool hit_body = FALSE;
2350 bool hit_wall = FALSE;
2351 bool equiped_item = FALSE;
2352 bool return_when_thrown = FALSE;
2354 GAME_TEXT o_name[MAX_NLEN];
2356 int msec = delay_factor * delay_factor * delay_factor;
2358 BIT_FLAGS flgs[TR_FLAG_SIZE];
2360 bool come_back = FALSE;
2361 bool do_drop = TRUE;
2363 if (p_ptr->wild_mode) return FALSE;
2365 if (p_ptr->special_defense & KATA_MUSOU)
2367 set_action(ACTION_NONE);
2373 o_ptr = &p_ptr->inventory_list[item];
2377 if (has_melee_weapon(INVEN_RARM) && has_melee_weapon(INVEN_LARM))
2379 item_tester_hook = item_tester_hook_boomerang;
2380 q = _("どの武器を投げますか? ", "Throw which item? ");
2381 s = _("投げる武器がない。", "You have nothing to throw.");
2382 o_ptr = choose_object(&item, q, s, (USE_EQUIP), 0);
2389 else if (has_melee_weapon(INVEN_LARM))
2392 o_ptr = &p_ptr->inventory_list[item];
2397 o_ptr = &p_ptr->inventory_list[item];
2402 q = _("どのアイテムを投げますか? ", "Throw which item? ");
2403 s = _("投げるアイテムがない。", "You have nothing to throw.");
2404 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP), 0);
2412 /* Item is cursed */
2413 if (object_is_cursed(o_ptr) && (item >= INVEN_RARM))
2415 msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
2419 if (p_ptr->inside_arena && !boomerang)
2421 if (o_ptr->tval != TV_SPIKE)
2423 msg_print(_("アリーナではアイテムを使えない!", "You're in the arena now. This is hand-to-hand!"));
2431 object_copy(q_ptr, o_ptr);
2433 /* Extract the thrown object's flags. */
2434 object_flags(q_ptr, flgs);
2435 torch_flags(q_ptr, flgs);
2437 /* Distribute the charges of rods/wands between the stacks */
2438 distribute_charges(o_ptr, q_ptr, 1);
2443 object_desc(o_name, q_ptr, OD_OMIT_PREFIX);
2445 if (p_ptr->mighty_throw) mult += 3;
2447 /* Extract a "distance multiplier" */
2448 /* Changed for 'launcher' mutation */
2449 mul = 10 + 2 * (mult - 1);
2451 /* Enforce a minimum "weight" of one pound */
2452 div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
2453 if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
2455 /* Hack -- Distance -- Reward strength, penalize weight */
2456 tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
2458 /* Max distance of 10-18 */
2459 if (tdis > mul) tdis = mul;
2463 ty = randint0(101) - 50 + p_ptr->y;
2464 tx = randint0(101) - 50 + p_ptr->x;
2468 project_length = tdis + 1;
2470 /* Get a direction (or cancel) */
2471 if (!get_aim_dir(&dir)) return FALSE;
2473 /* Predict the "target" location */
2474 tx = p_ptr->x + 99 * ddx[dir];
2475 ty = p_ptr->y + 99 * ddy[dir];
2477 /* Check for "target request" */
2478 if ((dir == 5) && target_okay())
2484 project_length = 0; /* reset to default */
2487 if ((q_ptr->name1 == ART_MJOLLNIR) ||
2488 (q_ptr->name1 == ART_AEGISFANG) || boomerang)
2489 return_when_thrown = TRUE;
2491 /* Reduce and describe p_ptr->inventory_list */
2494 inven_item_increase(item, -1);
2495 if (!return_when_thrown)
2496 inven_item_describe(item);
2497 inven_item_optimize(item);
2500 /* Reduce and describe floor item */
2503 floor_item_increase(0 - item, -1);
2504 floor_item_optimize(0 - item);
2506 if (item >= INVEN_RARM)
2508 equiped_item = TRUE;
2509 p_ptr->redraw |= (PR_EQUIPPY);
2512 take_turn(p_ptr, 100);
2514 /* Rogue and Ninja gets bonus */
2515 if ((p_ptr->pclass == CLASS_ROGUE) || (p_ptr->pclass == CLASS_NINJA))
2516 p_ptr->energy_use -= p_ptr->lev;
2518 /* Start at the player */
2524 if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
2525 else shuriken = FALSE;
2527 /* Chance of hitting */
2528 if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
2529 ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
2530 else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
2532 if (shuriken) chance *= 2;
2537 /* Travel until stopped */
2538 for (cur_dis = 0; cur_dis <= tdis; )
2540 /* Hack -- Stop at the target */
2541 if ((y == ty) && (x == tx)) break;
2543 /* Calculate the new location (see "project()") */
2546 mmove2(&ny[cur_dis], &nx[cur_dis], p_ptr->y, p_ptr->x, ty, tx);
2548 /* Stopped by walls/doors */
2549 if (!cave_have_flag_bold(ny[cur_dis], nx[cur_dis], FF_PROJECT))
2552 if ((q_ptr->tval == TV_FIGURINE) || object_is_potion(q_ptr) || !current_floor_ptr->grid_array[ny[cur_dis]][nx[cur_dis]].m_idx) break;
2555 /* The player can see the (on screen) missile */
2556 if (panel_contains(ny[cur_dis], nx[cur_dis]) && player_can_see_bold(ny[cur_dis], nx[cur_dis]))
2558 SYMBOL_CODE c = object_char(q_ptr);
2559 TERM_COLOR a = object_attr(q_ptr);
2561 /* Draw, Hilite, Fresh, Pause, Erase */
2562 print_rel(c, a, ny[cur_dis], nx[cur_dis]);
2563 move_cursor_relative(ny[cur_dis], nx[cur_dis]);
2565 Term_xtra(TERM_XTRA_DELAY, msec);
2566 lite_spot(ny[cur_dis], nx[cur_dis]);
2570 /* The player cannot see the missile */
2573 /* Pause anyway, for consistancy */
2574 Term_xtra(TERM_XTRA_DELAY, msec);
2580 /* Save the new location */
2584 /* Advance the distance */
2587 /* Monster here, Try to hit it */
2588 if (current_floor_ptr->grid_array[y][x].m_idx)
2590 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2591 monster_type *m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
2592 GAME_TEXT m_name[MAX_NLEN];
2593 monster_name(g_ptr->m_idx, m_name);
2595 /* Check the visibility */
2596 visible = m_ptr->ml;
2598 /* Note the collision */
2601 /* Did we hit it (penalize range) */
2602 if (test_hit_fire(chance - cur_dis, m_ptr, m_ptr->ml, o_name))
2606 /* Handle unseen monster */
2609 /* Invisible monster */
2610 msg_format(_("%sが敵を捕捉した。", "The %s finds a mark."), o_name);
2613 /* Handle visible monster */
2616 msg_format(_("%sが%sに命中した。", "The %s hits %s."), o_name, m_name);
2620 if (!p_ptr->image) monster_race_track(m_ptr->ap_r_idx);
2621 health_track(g_ptr->m_idx);
2625 /* Hack -- Base damage from thrown object */
2628 torch_dice(q_ptr, &dd, &ds); /* throwing a torch */
2629 tdam = damroll(dd, ds);
2630 /* Apply special damage */
2631 tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0, TRUE);
2632 tdam = critical_shot(q_ptr->weight, q_ptr->to_h, 0, tdam);
2633 if (q_ptr->to_d > 0)
2634 tdam += q_ptr->to_d;
2636 tdam += -q_ptr->to_d;
2640 tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
2641 tdam += p_ptr->to_d_m;
2643 else if (have_flag(flgs, TR_THROW))
2646 tdam += p_ptr->to_d_m;
2654 tdam += ((p_ptr->lev+30)*(p_ptr->lev+30)-900)/55;
2657 /* No negative damage */
2658 if (tdam < 0) tdam = 0;
2660 /* Modify the damage */
2661 tdam = mon_damage_mod(m_ptr, tdam, FALSE);
2663 msg_format_wizard(CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"),
2664 tdam, m_ptr->hp - tdam, m_ptr->maxhp, m_ptr->max_maxhp);
2666 /* Hit the monster, check for death */
2667 if (mon_take_hit(g_ptr->m_idx, tdam, &fear, extract_note_dies(real_r_idx(m_ptr))))
2675 message_pain(g_ptr->m_idx, tdam);
2677 /* Anger the monster */
2678 if ((tdam > 0) && !object_is_potion(q_ptr))
2679 anger_monster(m_ptr);
2681 if (fear && m_ptr->ml)
2684 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
2694 /* decrease toach's fuel */
2695 if (hit_body) torch_lost_fuel(q_ptr);
2697 /* Chance of breakage (during attacks) */
2698 j = (hit_body ? breakage_chance(q_ptr, 0) : 0);
2700 /* Figurines transform */
2701 if ((q_ptr->tval == TV_FIGURINE) && !(p_ptr->inside_arena))
2705 if (!(summon_named_creature(0, y, x, q_ptr->pval, !(object_is_cursed(q_ptr)) ? PM_FORCE_PET : 0L)))
2706 msg_print(_("人形は捻じ曲がり砕け散ってしまった!", "The Figurine writhes and then shatters."));
2707 else if (object_is_cursed(q_ptr))
2708 msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
2712 /* Potions smash open */
2713 if (object_is_potion(q_ptr))
2715 if (hit_body || hit_wall || (randint1(100) < j))
2717 msg_format(_("%sは砕け散った!", "The %s shatters!"), o_name);
2719 if (potion_smash_effect(0, y, x, q_ptr->k_idx))
2721 monster_type *m_ptr = ¤t_floor_ptr->m_list[current_floor_ptr->grid_array[y][x].m_idx];
2722 if (current_floor_ptr->grid_array[y][x].m_idx && is_friendly(m_ptr) && !MON_INVULNER(m_ptr))
2724 GAME_TEXT m_name[MAX_NLEN];
2725 monster_desc(m_name, m_ptr, 0);
2726 msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
2727 set_hostile(¤t_floor_ptr->m_list[current_floor_ptr->grid_array[y][x].m_idx]);
2738 if (return_when_thrown)
2740 int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
2741 char o2_name[MAX_NLEN];
2742 bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
2745 if (boomerang) back_chance += 4+randint1(5);
2746 if (super_boomerang) back_chance += 100;
2747 object_desc(o2_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2749 if((back_chance > 30) && (!one_in_(100) || super_boomerang))
2751 for (i = cur_dis - 1; i > 0; i--)
2753 if (panel_contains(ny[i], nx[i]) && player_can_see_bold(ny[i], nx[i]))
2755 char c = object_char(q_ptr);
2756 byte a = object_attr(q_ptr);
2758 /* Draw, Hilite, Fresh, Pause, Erase */
2759 print_rel(c, a, ny[i], nx[i]);
2760 move_cursor_relative(ny[i], nx[i]);
2762 Term_xtra(TERM_XTRA_DELAY, msec);
2763 lite_spot(ny[i], nx[i]);
2768 /* Pause anyway, for consistancy */
2769 Term_xtra(TERM_XTRA_DELAY, msec);
2772 if((back_chance > 37) && !p_ptr->blind && (item >= 0))
2774 msg_format(_("%sが手元に返ってきた。", "%s comes back to you."), o2_name);
2781 msg_format(_("%sを受け損ねた!", "%s backs, but you can't catch!"), o2_name);
2785 msg_format(_("%sが返ってきた。", "%s comes back."), o2_name);
2793 msg_format(_("%sが返ってこなかった!", "%s doesn't back!"), o2_name);
2799 if (item == INVEN_RARM || item == INVEN_LARM)
2801 /* Access the wield slot */
2802 o_ptr = &p_ptr->inventory_list[item];
2804 /* Wear the new stuff */
2805 object_copy(o_ptr, q_ptr);
2807 p_ptr->total_weight += q_ptr->weight;
2809 /* Increment the equip counter by hand */
2812 p_ptr->update |= (PU_BONUS | PU_TORCH | PU_MANA);
2813 p_ptr->window |= (PW_EQUIP);
2821 else if (equiped_item)
2829 if (cave_have_flag_bold(y, x, FF_PROJECT))
2831 (void)drop_near(q_ptr, j, y, x);
2835 (void)drop_near(q_ptr, j, prev_y, prev_x);
2843 * @brief 自殺するコマンドのメインルーチン
2844 * Hack -- commit suicide
2848 void do_cmd_suicide(void)
2855 /* Verify Retirement */
2856 if (p_ptr->total_winner)
2859 if (!get_check_strict(_("引退しますか? ", "Do you want to retire? "), CHECK_NO_HISTORY)) return;
2862 /* Verify Suicide */
2866 if (!get_check(_("本当に自殺しますか?", "Do you really want to commit suicide? "))) return;
2870 if (!p_ptr->noscore)
2872 /* Special Verification for suicide */
2873 prt(_("確認のため '@' を押して下さい。", "Please verify SUICIDE by typing the '@' sign: "), 0, 0);
2878 if (i != '@') return;
2880 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
2883 /* Initialize "last message" buffer */
2884 if (p_ptr->last_message) string_free(p_ptr->last_message);
2885 p_ptr->last_message = NULL;
2887 /* Hack -- Note *winning* message */
2888 if (p_ptr->total_winner && last_words)
2890 char buf[1024] = "";
2891 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_WINNER);
2894 while (!get_string(_("*勝利*メッセージ: ", "*Winning* message: "), buf, sizeof buf));
2895 } while (!get_check_strict(_("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
2899 p_ptr->last_message = string_make(buf);
2900 msg_print(p_ptr->last_message);
2905 p_ptr->playing = FALSE;
2907 /* Kill the player */
2908 p_ptr->is_dead = TRUE;
2909 p_ptr->leaving = TRUE;
2911 if (!p_ptr->total_winner)
2913 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("ダンジョンの探索に絶望して自殺した。", "give up all hope to commit suicide."));
2914 do_cmd_write_nikki(NIKKI_GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
2915 do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n");
2918 /* Cause of death */
2919 (void)strcpy(p_ptr->died_from, _("途中終了", "Quitting"));