OSDN Git Service

[Refactor] #3496 optional 型の値取得処理 value() を撤廃した その4
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 29 Oct 2023 07:35:58 +0000 (16:35 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 18 Nov 2023 10:35:55 +0000 (19:35 +0900)
12 files changed:
src/blue-magic/learnt-power-getter.cpp
src/cmd-visual/cmd-visuals.cpp
src/flavor/named-item-describer.cpp
src/main-win.cpp
src/mind/mind-archer.cpp
src/mind/mind-elementalist.cpp
src/mind/mind-power-getter.cpp
src/mind/mind-sniper.cpp
src/mind/mind-weaponsmith.cpp
src/monster-floor/monster-generator.cpp
src/monster/monster-describer.cpp
src/mutation/mutation-processor.cpp

index 70d41fb..21cdcc3 100644 (file)
@@ -128,7 +128,7 @@ static std::optional<BlueMagicType> select_blue_magic_kind_by_symbol()
             return std::nullopt;
         }
 
-        switch (command.value()) {
+        switch (*command) {
         case 'A':
         case 'a':
             return BlueMagicType::BOLT;
@@ -376,7 +376,7 @@ static std::optional<MonsterAbilityType> select_learnt_spells_by_symbol(PlayerTy
                 break;
             }
 
-            choice = choice_opt.value();
+            choice = *choice_opt;
         }
 
         if (first_show_list || (choice == ' ') || (choice == '*') || (choice == '?')) {
@@ -435,17 +435,16 @@ static std::optional<MonsterAbilityType> select_learnt_spells_by_menu(PlayerType
     while (!selected_spell) {
         describe_blue_magic_name(player_ptr, menu_line, bluemage_data, spells);
 
-        const auto choice_opt = input_command(prompt, true);
-        if (!choice_opt) {
+        const auto choice = input_command(prompt, true);
+        if (!choice) {
             break;
         }
 
-        const auto choice = choice_opt.value();
         if (choice == '0') {
             break;
         }
 
-        if (!switch_blue_magic_choice(choice, menu_line, bluemage_data, spells)) {
+        if (!switch_blue_magic_choice(*choice, menu_line, bluemage_data, spells)) {
             continue;
         }
 
index c36c537..0ab1046 100644 (file)
@@ -45,7 +45,7 @@ static std::optional<T> input_new_visual_id(int i, T initial_visual_id, int max)
             return std::nullopt;
         }
 
-        return static_cast<T>(new_visual_id.value());
+        return static_cast<T>(*new_visual_id);
     }
 
     if (isupper(i)) {
index 2cc6c89..a1da453 100644 (file)
@@ -93,7 +93,7 @@ static std::string describe_unique_name_before_body_ja(const ItemEntity &item, c
     }
 
     if (item.is_random_artifact()) {
-        const std::string_view name_sv = item.randart_name.value();
+        const std::string_view name_sv = *item.randart_name;
 
         /* '『' から始まらない伝説のアイテムの名前は最初に付加する */
         /* 英語版のセーブファイルから来た 'of XXX' は,「XXXの」と表示する */
@@ -102,7 +102,7 @@ static std::string describe_unique_name_before_body_ja(const ItemEntity &item, c
             ss << name_sv.substr(3) << "の";
             return ss.str();
         } else if (!name_sv.starts_with("『") && !name_sv.starts_with("《") && !name_sv.starts_with('\'')) {
-            return item.randart_name.value();
+            return *item.randart_name;
         }
     }
 
@@ -129,7 +129,7 @@ static std::optional<std::string> describe_random_artifact_name_after_body_ja(co
         return std::nullopt;
     }
 
-    const std::string_view name_sv = item.randart_name.value();
+    const std::string_view name_sv = *item.randart_name;
     if (name_sv.starts_with("『") || name_sv.starts_with("《")) {
         return item.randart_name;
     }
index 0ad6c45..d7549ef 100644 (file)
@@ -1605,7 +1605,7 @@ static void process_menus(PlayerType *player_ptr, WORD wCmd)
             ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
             const auto &filename = get_open_filename(&ofn, ANGBAND_DIR_SAVE, savefile, MAIN_WIN_MAX_PATH);
             if (filename) {
-                savefile = filename.value();
+                savefile = *filename;
                 validate_file(savefile);
                 game_in_progress = true;
             }
@@ -1675,7 +1675,7 @@ static void process_menus(PlayerType *player_ptr, WORD wCmd)
             ofn.Flags = OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
             const auto &filename = get_open_filename(&ofn, ANGBAND_DIR_USER, savefile, MAIN_WIN_MAX_PATH);
             if (filename) {
-                savefile = filename.value();
+                savefile = *filename;
                 prepare_browse_movie_without_path_build(savefile);
                 movie_in_progress = true;
             }
@@ -1962,7 +1962,7 @@ static void process_menus(PlayerType *player_ptr, WORD wCmd)
         ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
         const auto &filename = get_open_filename(&ofn, "", wallpaper_path, MAIN_WIN_MAX_PATH);
         if (filename) {
-            wallpaper_path = filename.value();
+            wallpaper_path = *filename;
             change_bg_mode(bg_mode::BG_ONE, true, true);
         }
         break;
index e4090d1..133d913 100644 (file)
@@ -62,12 +62,11 @@ static bool select_ammo_creation_type(ammo_creation_type &type, PLAYER_LEVEL ple
     }
 
     while (type == AMMO_NONE) {
-        const auto command = input_command(prompt, true);
-        if (!command) {
+        const auto ch = input_command(prompt, true);
+        if (!ch) {
             return false;
         }
 
-        const auto ch = command.value();
         if (ch == 'S' || ch == 's') {
             type = AMMO_SHOT;
             break;
index c92a0d5..e8388dd 100644 (file)
@@ -730,7 +730,7 @@ static bool get_element_power(PlayerType *player_ptr, SPELL_IDX *sn, bool only_b
                 break;
             }
 
-            choice = new_choice.value();
+            choice = *new_choice;
         }
 
         auto should_redraw_cursor = true;
index 2f48b0a..3fbed74 100644 (file)
@@ -153,7 +153,7 @@ bool MindPowerGetter::decide_mind_choice(std::string_view prompt, const bool onl
                 break;
             }
 
-            this->choice = command.value();
+            this->choice = *command;
         }
 
         if (!interpret_mind_key_input(only_browse)) {
index 35a63b6..d956272 100644 (file)
@@ -300,7 +300,7 @@ static int get_snipe_power(PlayerType *player_ptr, COMMAND_CODE *sn, bool only_b
                 break;
             }
 
-            choice = new_choice.value();
+            choice = *new_choice;
         }
 
         /* Request redraw */
index 5fd4e61..5ede516 100644 (file)
@@ -237,7 +237,7 @@ static COMMAND_CODE choose_essence(void)
                 return 0;
             }
 
-            choice = new_choice.value();
+            choice = *new_choice;
             if (isupper(choice)) {
                 choice = (char)tolower(choice);
             }
@@ -346,15 +346,14 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
             display_smith_effect_list(smith, smith_effect_list, menu_line, page * effect_num_per_page, effect_num_per_page);
 
             const auto page_effect_num = std::min<int>(effect_num_per_page, smith_effect_list.size() - (page * effect_num_per_page));
-            const auto command = input_command(prompt);
-            if (!command) {
+            const auto choice = input_command(prompt);
+            if (!choice) {
                 break;
             }
 
-            const auto choice = command.value();
             auto should_redraw_cursor = true;
             if (use_menu) {
-                switch (choice) {
+                switch (*choice) {
                 case '0': {
                     screen_load();
                     return;
@@ -419,7 +418,7 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
             }
 
             if (!use_menu) {
-                i = A2I(choice);
+                i = A2I(*choice);
             }
 
             effect_idx = page * effect_num_per_page + i;
@@ -484,7 +483,7 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
                 return;
             }
 
-            o_ptr->pval = num_enchants.value();
+            o_ptr->pval = *num_enchants;
         }
 
         add_essence_count = o_ptr->pval;
@@ -495,7 +494,7 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
             return;
         }
 
-        add_essence_count = num_enchants.value();
+        add_essence_count = *num_enchants;
     }
 
     msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence * add_essence_count);
@@ -630,14 +629,13 @@ void do_cmd_kaji(PlayerType *player_ptr, bool only_browse)
                     prt(_("  d) エッセンス付加", "  d) Add essence"), 5, 14);
                     prt(_("  e) 武器/防具強化", "  e) Enchant weapon/armor"), 6, 14);
                     std::string prompt = _(format("どの能力を%sますか:", only_browse ? "調べ" : "使い"), "Command :");
-                    const auto command = input_command(prompt, true);
-                    if (!command) {
+                    const auto choice = input_command(prompt, true);
+                    if (!choice) {
                         screen_load();
                         return;
                     }
 
-                    const auto choice = command.value();
-                    switch (choice) {
+                    switch (*choice) {
                     case 'A':
                     case 'a':
                         mode = 1;
index 48ceaef..08b06e6 100644 (file)
@@ -455,7 +455,7 @@ bool alloc_horde(PlayerType *player_ptr, POSITION y, POSITION x, summon_specific
         return true;
     }
 
-    auto *r_ptr = &monraces_info[r_idx.value()];
+    auto *r_ptr = &monraces_info[*r_idx];
     if (floor_ptr->m_list[m_idx].mflag2.has(MonsterConstantFlagType::CHAMELEON)) {
         r_ptr = &monraces_info[floor_ptr->m_list[m_idx].r_idx];
     }
index 5bb1473..aa23fc7 100644 (file)
@@ -138,7 +138,7 @@ static std::string get_describing_monster_name(const MonsterEntity &monster, con
         constexpr auto filename = _("silly_j.txt", "silly.txt");
         const auto silly_name = get_random_line(filename, enum2i(monster.r_idx));
         if (silly_name) {
-            return silly_name.value();
+            return *silly_name;
         }
     }
 
@@ -192,7 +192,7 @@ static std::string describe_non_pet(const PlayerType &player, const MonsterEntit
 {
     const auto fake_name = get_fake_monster_name(player, monster, name, mode);
     if (fake_name) {
-        return fake_name.value();
+        return *fake_name;
     }
 
     if (any_bits(mode, MD_INDEF_VISIBLE)) {
@@ -243,12 +243,12 @@ std::string monster_desc(PlayerType *player_ptr, const MonsterEntity *m_ptr, BIT
 {
     const auto pronoun = decide_monster_personal_pronoun(*m_ptr, mode);
     if (pronoun) {
-        return pronoun.value();
+        return *pronoun;
     }
 
     const auto pronoun_self = get_monster_self_pronoun(*m_ptr, mode);
     if (pronoun_self) {
-        return pronoun_self.value();
+        return *pronoun_self;
     }
 
     const auto is_hallucinated = player_ptr->effects()->hallucination()->is_hallucinated();
index 9f216d1..a64c140 100644 (file)
@@ -70,7 +70,7 @@ static int get_hack_dir(PlayerType *player_ptr)
             break;
         }
 
-        auto command = command_opt.value();
+        auto command = *command_opt;
         if (use_menu && (command == '\r')) {
             command = 't';
         }