OSDN Git Service

[Refactor] #3230 PlayerType::update に関わる処理を、RedrawingFlagsUpdaterに集約した
[hengbandforosx/hengbandosx.git] / src / cmd-io / cmd-floor.cpp
index e6baf84..d3a11d4 100644 (file)
 #include "io/screen-util.h"
 #include "main/sound-of-music.h"
 #include "system/player-type-definition.h"
+#include "system/redrawing-flags-updater.h"
 #include "target/target-checker.h"
 #include "target/target-setter.h"
 #include "target/target-types.h"
+#include "term/z-form.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 #include "window/main-window-util.h"
 /*!
  * @brief ターゲットを設定するコマンドのメインルーチン
  * Target command
- * @return なし
  */
-void do_cmd_target(player_type *creature_ptr)
+void do_cmd_target(PlayerType *player_ptr)
 {
-    if (creature_ptr->wild_mode)
+    if (player_ptr->wild_mode) {
         return;
+    }
 
-    if (target_set(creature_ptr, TARGET_KILL))
+    if (target_set(player_ptr, TARGET_KILL)) {
         msg_print(_("ターゲット決定。", "Target Selected."));
-    else
+    } else {
         msg_print(_("ターゲット解除。", "Target Aborted."));
+    }
 }
 
 /*!
  * @brief 周囲を見渡すコマンドのメインルーチン
  * Look command
- * @return なし
  */
-void do_cmd_look(player_type *creature_ptr)
+void do_cmd_look(PlayerType *player_ptr)
 {
-    set_bits(creature_ptr->window_flags, PW_MONSTER_LIST | PW_FLOOR_ITEM_LIST);
-    handle_stuff(creature_ptr);
-    if (target_set(creature_ptr, TARGET_LOOK))
+    set_bits(player_ptr->window_flags, PW_SIGHT_MONSTERS | PW_FLOOR_ITEMS);
+    handle_stuff(player_ptr);
+    if (target_set(player_ptr, TARGET_LOOK)) {
         msg_print(_("ターゲット決定。", "Target Selected."));
+    }
 }
 
 /*!
  * @brief 位置を確認するコマンドのメインルーチン
  * Allow the player to examine other sectors on the map
- * @return なし
  */
-void do_cmd_locate(player_type *creature_ptr)
+void do_cmd_locate(PlayerType *player_ptr)
 {
+    const char *dirstrings[3][3] = {
+        { _("北西", " northwest of"), _("北", " north of"), _("北東", " northeast of") },
+        { _("西", " west of"), _("真上", ""), _("東", " east of") },
+        { _("南西", " southwest of"), _("南", " south of"), _("南東", " southeast of") },
+    };
     DIRECTION dir;
     POSITION y1, x1;
-    GAME_TEXT tmp_val[80];
-    GAME_TEXT out_val[MAX_MONSTER_NAME];
     TERM_LEN wid, hgt;
     get_screen_size(&wid, &hgt);
     POSITION y2 = y1 = panel_row_min;
     POSITION x2 = x1 = panel_col_min;
-    while (TRUE) {
-        if ((y2 == y1) && (x2 == x1))
-            strcpy(tmp_val, _("真上", "\0"));
-        else
-            sprintf(tmp_val, "%s%s", ((y2 < y1) ? _("北", " North") : (y2 > y1) ? _("南", " South") : ""),
-                ((x2 < x1) ? _("西", " West") : (x2 > x1) ? _("東", " East") : ""));
-
-        sprintf(out_val, _("マップ位置 [%d(%02d),%d(%02d)] (プレイヤーの%s)  方向?", "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?"),
-            y2 / (hgt / 2), y2 % (hgt / 2), x2 / (wid / 2), x2 % (wid / 2), tmp_val);
+    constexpr auto fmt = _("マップ位置 [%d(%02d),%d(%02d)] (プレイヤーの%s)  方向?", "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?");
+    while (true) {
+        std::string_view dirstring = dirstrings[(y2 < y1) ? 0 : ((y2 > y1) ? 2 : 1)][(x2 < x1) ? 0 : ((x2 > x1) ? 2 : 1)];
+        std::string out_val = format(fmt, y2 / (hgt / 2), y2 % (hgt / 2), x2 / (wid / 2), x2 % (wid / 2), dirstring.data());
 
         dir = 0;
         while (!dir) {
             char command;
-            if (!get_com(out_val, &command, TRUE))
+            if (!get_com(out_val, &command, true)) {
                 break;
+            }
 
             dir = get_keymap_dir(command);
-            if (!dir)
+            if (!dir) {
                 bell();
+            }
         }
 
-        if (!dir)
+        if (!dir) {
             break;
+        }
 
-        if (change_panel(creature_ptr, ddy[dir], ddx[dir])) {
+        if (change_panel(player_ptr, ddy[dir], ddx[dir])) {
             y2 = panel_row_min;
             x2 = panel_col_min;
         }
     }
 
-    verify_panel(creature_ptr);
-    creature_ptr->update |= PU_MONSTERS;
-    creature_ptr->redraw |= PR_MAP;
-    creature_ptr->window_flags |= PW_OVERHEAD | PW_DUNGEON;
-    handle_stuff(creature_ptr);
+    verify_panel(player_ptr);
+    auto &rfu = RedrawingFlagsUpdater::get_instance();
+    rfu.set_flag(StatusRedrawingFlag::MONSTER_STATUSES);
+    player_ptr->redraw |= PR_MAP;
+    player_ptr->window_flags |= PW_OVERHEAD | PW_DUNGEON;
+    handle_stuff(player_ptr);
 }