OSDN Git Service

[Refactor] #3733 optional 型の値取得処理 value() を撤廃した その3
[hengbandforosx/hengbandosx.git] / src / cmd-action / cmd-hissatsu.cpp
index 54e2d08..c042ee0 100644 (file)
@@ -1,4 +1,4 @@
-/*!
+/*!
  * @brief 剣術の実装 / Blade arts
  * @date 2014/01/17
  * @author
  */
 static int get_hissatsu_power(PlayerType *player_ptr, SPELL_IDX *sn)
 {
-    SPELL_IDX i;
     int j = 0;
     int num = 0;
     POSITION y = 1;
     POSITION x = 15;
     PLAYER_LEVEL plev = player_ptr->lev;
     char choice;
-    char out_val[160];
-    SPELL_IDX sentaku[32];
     concptr p = _("必殺剣", "special attack");
     COMMAND_CODE code;
     magic_type spell;
-    bool flag, redraw;
     int menu_line = (use_menu ? 1 : 0);
 
     /* Assume cancelled */
@@ -91,18 +87,20 @@ static int get_hissatsu_power(PlayerType *player_ptr, SPELL_IDX *sn)
         }
     }
 
-    flag = false;
-    redraw = false;
+    auto flag = false;
+    auto redraw = false;
 
+    int i;
+    int selections[32]{};
     for (i = 0; i < 32; i++) {
         if (technic_info[TECHNIC_HISSATSU][i].slevel <= PY_MAX_LEVEL) {
-            sentaku[num] = i;
+            selections[num] = i;
             num++;
         }
     }
 
     constexpr auto fmt = _("(%s^ %c-%c, '*'で一覧, ESC) どの%sを使いますか?", "(%s^s %c-%c, *=List, ESC=exit) Use which %s? ");
-    (void)strnfmt(out_val, 78, fmt, p, I2A(0), "abcdefghijklmnopqrstuvwxyz012345"[num - 1], p);
+    const auto prompt = format(fmt, p, I2A(0), "abcdefghijklmnopqrstuvwxyz012345"[num - 1], p);
 
     if (use_menu) {
         screen_save();
@@ -112,8 +110,13 @@ static int get_hissatsu_power(PlayerType *player_ptr, SPELL_IDX *sn)
     while (!flag) {
         if (choice == ESCAPE) {
             choice = ' ';
-        } else if (!get_com(out_val, &choice, false)) {
-            break;
+        } else {
+            const auto new_choice = input_command(prompt);
+            if (!new_choice) {
+                break;
+            }
+
+            choice = *new_choice;
         }
 
         auto should_redraw_cursor = true;
@@ -269,12 +272,12 @@ static int get_hissatsu_power(PlayerType *player_ptr, SPELL_IDX *sn)
         }
 
         /* Totally Illegal */
-        if ((i < 0) || (i >= 32) || !(player_ptr->spell_learned1 & (1U << sentaku[i]))) {
+        if ((i < 0) || (i >= 32) || !(player_ptr->spell_learned1 & (1U << selections[i]))) {
             bell();
             continue;
         }
 
-        j = sentaku[i];
+        j = selections[i];
 
         /* Stop the loop */
         flag = true;
@@ -283,7 +286,7 @@ static int get_hissatsu_power(PlayerType *player_ptr, SPELL_IDX *sn)
         screen_load();
     }
 
-    player_ptr->window_flags |= (PW_SPELL);
+    RedrawingFlagsUpdater::get_instance().set_flag(SubWindowRedrawingFlag::SPELL);
     handle_stuff(player_ptr);
 
     /* Abort if needed */
@@ -356,7 +359,11 @@ void do_cmd_hissatsu(PlayerType *player_ptr)
 
     auto &rfu = RedrawingFlagsUpdater::get_instance();
     rfu.set_flag(MainWindowRedrawingFlag::MP);
-    player_ptr->window_flags |= (PW_PLAYER | PW_SPELL);
+    static constexpr auto flags = {
+        SubWindowRedrawingFlag::PLAYER,
+        SubWindowRedrawingFlag::SPELL,
+    };
+    rfu.set_flags(flags);
 }
 
 /*!
@@ -383,13 +390,13 @@ void do_cmd_gain_hissatsu(PlayerType *player_ptr)
     constexpr auto q = _("どの書から学びますか? ", "Study which book? ");
     constexpr auto s = _("読める書がない。", "You have no books that you can read.");
     constexpr auto options = USE_INVEN | USE_FLOOR;
-    short item;
-    const auto *o_ptr = choose_object(player_ptr, &item, q, s, options, TvalItemTester(ItemKindType::HISSATSU_BOOK));
+    short i_idx;
+    const auto *o_ptr = choose_object(player_ptr, &i_idx, q, s, options, TvalItemTester(ItemKindType::HISSATSU_BOOK));
     if (o_ptr == nullptr) {
         return;
     }
 
-    const auto sval = o_ptr->bi_key.sval().value();
+    const auto sval = *o_ptr->bi_key.sval();
     auto gain = false;
     for (auto i = sval * 8; i < sval * 8 + 8; i++) {
         if (player_ptr->spell_learned1 & (1UL << i)) {
@@ -422,5 +429,5 @@ void do_cmd_gain_hissatsu(PlayerType *player_ptr)
         PlayerEnergy(player_ptr).set_player_turn_energy(100);
     }
 
-    RedrawingFlagsUpdater::get_instance().set_flag(StatusRedrawingFlag::SPELLS);
+    RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::SPELLS);
 }