OSDN Git Service

[Refactor] #3496 optional 型の存在判定 has_value() を撤廃した その3
authorHourier <66951241+Hourier@users.noreply.github.com>
Thu, 9 Nov 2023 11:54:24 +0000 (20:54 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Thu, 9 Nov 2023 11:54:24 +0000 (20:54 +0900)
15 files changed:
src/market/arena.cpp
src/market/building-monster.cpp
src/market/play-gamble.cpp
src/mind/mind-archer.cpp
src/mind/mind-blue-mage.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-floor/monster-move.cpp
src/monster/monster-damage.cpp
src/monster/monster-describer.cpp
src/mutation/mutation-processor.cpp
src/net/http-client.cpp

index 1951063..d4e3859 100644 (file)
@@ -330,7 +330,7 @@ bool monster_arena_comm(PlayerType *player_ptr)
     maxbet = std::min(maxbet, player_ptr->au);
     constexpr auto prompt = _("賭け金?", "Your wager? ");
     const auto wager_opt = input_integer(prompt, 1, maxbet, 1);
-    if (!wager_opt.has_value()) {
+    if (!wager_opt) {
         screen_load();
         return false;
     }
index ae46ae2..3308c0e 100644 (file)
@@ -36,7 +36,7 @@ bool research_mon(PlayerType *player_ptr)
     constexpr auto prompt = _("モンスターの文字を入力して下さい(記号 or ^A全,^Uユ,^N非ユ,^M名前):",
         "Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): ");
     const auto sym_opt = input_command(prompt, false);
-    if (!sym_opt.has_value()) {
+    if (!sym_opt) {
         screen_load();
         return false;
     }
@@ -63,7 +63,7 @@ bool research_mon(PlayerType *player_ptr)
     } else if (sym == KTRL('M')) {
         all = true;
         const auto monster_name_opt = input_string(_("名前(英語の場合小文字で可)", "Enter name:"), MAX_MONSTER_NAME);
-        if (!monster_name_opt.has_value()) {
+        if (!monster_name_opt) {
             screen_load();
             return false;
         }
index 5158b46..a64f6c4 100644 (file)
@@ -40,7 +40,7 @@ void gamble_comm(PlayerType *player_ptr, int cmd)
     maxbet = std::min(maxbet, player_ptr->au);
     constexpr auto prompt = _("賭け金?", "Your wager ?");
     const auto wager_opt = input_integer(prompt, 1, maxbet, 1);
-    if (!wager_opt.has_value()) {
+    if (!wager_opt) {
         msg_print(nullptr);
         screen_load();
         return;
@@ -121,7 +121,7 @@ void gamble_comm(PlayerType *player_ptr, int cmd)
             prt("--------------------------------", 8, 3);
             while (true) {
                 const auto choice_opt = input_integer(_("何番?", "Pick a number"), 0, 9);
-                if (!choice_opt.has_value()) {
+                if (!choice_opt) {
                     continue;
                 }
 
index 983ac1d..e4090d1 100644 (file)
@@ -63,7 +63,7 @@ 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.has_value()) {
+        if (!command) {
             return false;
         }
 
index 6ee84f8..03ffa6f 100644 (file)
@@ -36,7 +36,7 @@ bool do_cmd_cast_learned(PlayerType *player_ptr)
     }
 
     auto selected_spell = get_learned_power(player_ptr);
-    if (!selected_spell.has_value()) {
+    if (!selected_spell) {
         return false;
     }
 
index bdeda77..c92a0d5 100644 (file)
@@ -726,7 +726,7 @@ static bool get_element_power(PlayerType *player_ptr, SPELL_IDX *sn, bool only_b
             choice = ' ';
         } else {
             const auto new_choice = input_command(prompt, true);
-            if (!new_choice.has_value()) {
+            if (!new_choice) {
                 break;
             }
 
index 9aedbbe..2f48b0a 100644 (file)
@@ -149,7 +149,7 @@ bool MindPowerGetter::decide_mind_choice(std::string_view prompt, const bool onl
             this->choice = ' ';
         } else {
             const auto command = input_command(prompt, true);
-            if (!command.has_value()) {
+            if (!command) {
                 break;
             }
 
index 64e448f..35a63b6 100644 (file)
@@ -296,7 +296,7 @@ static int get_snipe_power(PlayerType *player_ptr, COMMAND_CODE *sn, bool only_b
             choice = ' ';
         } else {
             const auto new_choice = input_command(prompt);
-            if (!new_choice.has_value()) {
+            if (!new_choice) {
                 break;
             }
 
index dd5797f..5fd4e61 100644 (file)
@@ -232,7 +232,7 @@ static COMMAND_CODE choose_essence(void)
             }
 
             const auto new_choice = input_command(_("何を付加しますか:", "Command :"), true);
-            if (!new_choice.has_value()) {
+            if (!new_choice) {
                 screen_load();
                 return 0;
             }
@@ -347,7 +347,7 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
 
             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.has_value()) {
+            if (!command) {
                 break;
             }
 
@@ -480,7 +480,7 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
         } else if (o_ptr->pval == 0) {
             const auto limit = std::min(5, smith.get_addable_count(effect, o_ptr));
             const auto num_enchants = input_numerics<short>(prompt, 1, limit, 1);
-            if (!num_enchants.has_value()) {
+            if (!num_enchants) {
                 return;
             }
 
@@ -491,7 +491,7 @@ static void add_essence(PlayerType *player_ptr, SmithCategoryType mode)
     } else if (effect == SmithEffectType::SLAY_GLOVE) {
         const auto max_val = player_ptr->lev / 7 + 3;
         const auto num_enchants = input_numerics(prompt, 1, max_val, 1);
-        if (!num_enchants.has_value()) {
+        if (!num_enchants) {
             return;
         }
 
@@ -631,7 +631,7 @@ void do_cmd_kaji(PlayerType *player_ptr, bool only_browse)
                     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.has_value()) {
+                    if (!command) {
                         screen_load();
                         return;
                     }
index 5932ca6..e05018c 100644 (file)
@@ -425,7 +425,7 @@ bool alloc_horde(PlayerType *player_ptr, POSITION y, POSITION x, summon_specific
     get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
 
     auto r_idx = select_horde_leader_r_idx(player_ptr);
-    if (!r_idx.has_value()) {
+    if (!r_idx) {
         return false;
     }
 
index 68cac1f..3260a11 100644 (file)
@@ -562,7 +562,7 @@ void process_speak_sound(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION oy,
     }
 
     const auto monmessage = get_random_line(filename.data(), enum2i(monster.ap_r_idx));
-    if (monmessage.has_value()) {
+    if (monmessage) {
         msg_format(_("%s^%s", "%s^ %s"), m_name.data(), monmessage->data());
     }
 }
index 3129be0..14da949 100644 (file)
@@ -277,7 +277,7 @@ void MonsterDamageProcessor::dying_scream(std::string_view m_name)
     }
 
     const auto death_mes = get_random_line(_("mondeath_j.txt", "mondeath.txt"), enum2i(m_ptr->r_idx));
-    if (death_mes.has_value()) {
+    if (death_mes) {
         msg_format("%s^ %s", m_name.data(), death_mes->data());
     }
 
index f767535..5bb1473 100644 (file)
@@ -137,7 +137,7 @@ static std::string get_describing_monster_name(const MonsterEntity &monster, con
     if (one_in_(2)) {
         constexpr auto filename = _("silly_j.txt", "silly.txt");
         const auto silly_name = get_random_line(filename, enum2i(monster.r_idx));
-        if (silly_name.has_value()) {
+        if (silly_name) {
             return silly_name.value();
         }
     }
@@ -191,7 +191,7 @@ static std::optional<std::string> get_fake_monster_name(const PlayerType &player
 static std::string describe_non_pet(const PlayerType &player, const MonsterEntity &monster, const std::string &name, const BIT_FLAGS mode)
 {
     const auto fake_name = get_fake_monster_name(player, monster, name, mode);
-    if (fake_name.has_value()) {
+    if (fake_name) {
         return fake_name.value();
     }
 
@@ -242,12 +242,12 @@ static std::string add_cameleon_name(const MonsterEntity &monster, const BIT_FLA
 std::string monster_desc(PlayerType *player_ptr, const MonsterEntity *m_ptr, BIT_FLAGS mode)
 {
     const auto pronoun = decide_monster_personal_pronoun(*m_ptr, mode);
-    if (pronoun.has_value()) {
+    if (pronoun) {
         return pronoun.value();
     }
 
     const auto pronoun_self = get_monster_self_pronoun(*m_ptr, mode);
-    if (pronoun_self.has_value()) {
+    if (pronoun_self) {
         return pronoun_self.value();
     }
 
index 9a1be34..9f216d1 100644 (file)
@@ -66,7 +66,7 @@ static int get_hack_dir(PlayerType *player_ptr)
                            ? _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ")
                            : _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
         const auto command_opt = input_command(p, true);
-        if (!command_opt.has_value()) {
+        if (!command_opt) {
             break;
         }
 
index 8f53f35..c3ed6da 100644 (file)
@@ -14,7 +14,7 @@ namespace {
 
     void setup_http_option(libcurl::EasySession &session, const std::optional<std::string> &user_agent)
     {
-        if (user_agent.has_value()) {
+        if (user_agent) {
             session.setopt(CURLOPT_USERAGENT, user_agent->data());
         }