OSDN Git Service

Merge pull request #3311 from habu1010/feature/implement-rand-choice-function-no...
[hengbandforosx/hengbandosx.git] / src / cmd-io / cmd-floor.cpp
1 #include "cmd-io/cmd-floor.h"
2 #include "core/asking-player.h"
3 #include "core/player-redraw-types.h"
4 #include "core/stuff-handler.h"
5 #include "core/window-redrawer.h"
6 #include "floor/geometry.h"
7 #include "game-option/keymap-directory-getter.h"
8 #include "io/cursor.h"
9 #include "io/screen-util.h"
10 #include "main/sound-of-music.h"
11 #include "system/player-type-definition.h"
12 #include "system/redrawing-flags-updater.h"
13 #include "target/target-checker.h"
14 #include "target/target-setter.h"
15 #include "target/target-types.h"
16 #include "term/z-form.h"
17 #include "util/bit-flags-calculator.h"
18 #include "view/display-messages.h"
19 #include "window/main-window-util.h"
20
21 /*!
22  * @brief ターゲットを設定するコマンドのメインルーチン
23  * Target command
24  */
25 void do_cmd_target(PlayerType *player_ptr)
26 {
27     if (player_ptr->wild_mode) {
28         return;
29     }
30
31     if (target_set(player_ptr, TARGET_KILL)) {
32         msg_print(_("ターゲット決定。", "Target Selected."));
33     } else {
34         msg_print(_("ターゲット解除。", "Target Aborted."));
35     }
36 }
37
38 /*!
39  * @brief 周囲を見渡すコマンドのメインルーチン
40  * Look command
41  */
42 void do_cmd_look(PlayerType *player_ptr)
43 {
44     set_bits(player_ptr->window_flags, PW_SIGHT_MONSTERS | PW_FLOOR_ITEMS);
45     handle_stuff(player_ptr);
46     if (target_set(player_ptr, TARGET_LOOK)) {
47         msg_print(_("ターゲット決定。", "Target Selected."));
48     }
49 }
50
51 /*!
52  * @brief 位置を確認するコマンドのメインルーチン
53  * Allow the player to examine other sectors on the map
54  */
55 void do_cmd_locate(PlayerType *player_ptr)
56 {
57     const char *dirstrings[3][3] = {
58         { _("北西", " northwest of"), _("北", " north of"), _("北東", " northeast of") },
59         { _("西", " west of"), _("真上", ""), _("東", " east of") },
60         { _("南西", " southwest of"), _("南", " south of"), _("南東", " southeast of") },
61     };
62     DIRECTION dir;
63     POSITION y1, x1;
64     TERM_LEN wid, hgt;
65     get_screen_size(&wid, &hgt);
66     POSITION y2 = y1 = panel_row_min;
67     POSITION x2 = x1 = panel_col_min;
68     constexpr auto fmt = _("マップ位置 [%d(%02d),%d(%02d)] (プレイヤーの%s)  方向?", "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?");
69     while (true) {
70         std::string_view dirstring = dirstrings[(y2 < y1) ? 0 : ((y2 > y1) ? 2 : 1)][(x2 < x1) ? 0 : ((x2 > x1) ? 2 : 1)];
71         std::string out_val = format(fmt, y2 / (hgt / 2), y2 % (hgt / 2), x2 / (wid / 2), x2 % (wid / 2), dirstring.data());
72
73         dir = 0;
74         while (!dir) {
75             char command;
76             if (!get_com(out_val, &command, true)) {
77                 break;
78             }
79
80             dir = get_keymap_dir(command);
81             if (!dir) {
82                 bell();
83             }
84         }
85
86         if (!dir) {
87             break;
88         }
89
90         if (change_panel(player_ptr, ddy[dir], ddx[dir])) {
91             y2 = panel_row_min;
92             x2 = panel_col_min;
93         }
94     }
95
96     verify_panel(player_ptr);
97     auto &rfu = RedrawingFlagsUpdater::get_instance();
98     rfu.set_flag(StatusRedrawingFlag::MONSTER_STATUSES);
99     player_ptr->redraw |= PR_MAP;
100     player_ptr->window_flags |= PW_OVERHEAD | PW_DUNGEON;
101     handle_stuff(player_ptr);
102 }