OSDN Git Service

[Refactor] #3496 optional 型の存在判定 has_value() を撤廃した その6
authorHourier <66951241+Hourier@users.noreply.github.com>
Thu, 9 Nov 2023 11:55:24 +0000 (20:55 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Thu, 9 Nov 2023 11:55:24 +0000 (20:55 +0900)
src/target/target-getter.cpp
src/term/z-rand.cpp
src/term/z-term.cpp
src/test/test-sha256.cpp
src/view/display-player.cpp
src/window/main-window-left-frame.cpp
src/wizard/wizard-game-modifier.cpp
src/wizard/wizard-item-modifier.cpp
src/wizard/wizard-special-process.cpp
src/wizard/wizard-spells.cpp

index ae17b19..db8c8ab 100644 (file)
@@ -57,7 +57,7 @@ bool get_aim_dir(PlayerType *player_ptr, int *dp)
         }
 
         const auto command_opt = input_command(prompt, true);
-        if (!command_opt.has_value()) {
+        if (!command_opt) {
             break;
         }
 
@@ -127,7 +127,7 @@ bool get_direction(PlayerType *player_ptr, int *dp)
     constexpr auto prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
     while (dir == 0) {
         const auto command = input_command(prompt, true);
-        if (!command.has_value()) {
+        if (!command) {
             return false;
         }
 
@@ -192,7 +192,7 @@ bool get_rep_dir(PlayerType *player_ptr, int *dp, bool under)
                               : _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
     while (dir == 0) {
         const auto command = input_command(prompt, true);
-        if (!command.has_value()) {
+        if (!command) {
             return false;
         }
 
index 2e026f6..44b31ff 100644 (file)
@@ -158,7 +158,7 @@ int32_t Rand_external(int32_t m)
 
     static std::optional<Xoshiro128StarStar> urbg_external;
 
-    if (!urbg_external.has_value()) {
+    if (!urbg_external) {
         /* Initialize with new seed */
         auto seed = static_cast<uint32_t>(time(nullptr));
         urbg_external = Xoshiro128StarStar(seed);
index c0ab1ed..1f8cf2a 100644 (file)
@@ -54,10 +54,10 @@ TermOffsetSetter::TermOffsetSetter(std::optional<TERM_LEN> x, std::optional<TERM
         return;
     }
 
-    if (x.has_value()) {
+    if (x) {
         this->term->offset_x = (x.value() > 0) ? x.value() : 0;
     }
-    if (y.has_value()) {
+    if (y) {
         this->term->offset_y = (y.value() > 0) ? y.value() : 0;
     }
 }
@@ -92,8 +92,8 @@ TermCenteredOffsetSetter::TermCenteredOffsetSetter(std::optional<TERM_LEN> width
         return;
     }
 
-    const auto offset_x = width.has_value() ? (game_term->wid - width.value()) / 2 : 0;
-    const auto offset_y = height.has_value() ? (game_term->hgt - height.value()) / 2 : 0;
+    const auto offset_x = width ? (game_term->wid - width.value()) / 2 : 0;
+    const auto offset_y = height ? (game_term->hgt - height.value()) / 2 : 0;
     this->tos.emplace(offset_x, offset_y);
 
     game_term->centered_wid = (width < game_term->wid) ? width : std::nullopt;
index 3630942..b6f1ed4 100644 (file)
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
     if (argc > 1) {
         for (auto arg : std::span(argv, argc).subspan(1)) {
             auto hash = util::SHA256::compute_filehash(arg);
-            if (!hash.has_value()) {
+            if (!hash) {
                 std::cout << "cannot open file: " << arg << std::endl;
                 continue;
             }
index 9e15600..5fcca9a 100644 (file)
@@ -244,7 +244,7 @@ static std::optional<std::string> decide_death_in_quest(PlayerType *player_ptr)
 static std::string decide_current_floor(PlayerType *player_ptr)
 {
     if (auto death_cause = search_death_cause(player_ptr);
-        death_cause.has_value() || !w_ptr->character_dungeon) {
+        death_cause || !w_ptr->character_dungeon) {
         return death_cause.value_or("");
     }
 
@@ -253,7 +253,7 @@ static std::string decide_current_floor(PlayerType *player_ptr)
         return format(_("…あなたは現在、 %s にいる。", "...Now, you are in %s."), map_name(player_ptr).data());
     }
 
-    if (auto decision = decide_death_in_quest(player_ptr); decision.has_value()) {
+    if (auto decision = decide_death_in_quest(player_ptr); decision) {
         return decision.value();
     }
 
index 1624508..e656e69 100644 (file)
@@ -379,7 +379,7 @@ void print_health(PlayerType *player_ptr, bool riding)
         term_erase(col, y, max_width);
     }
 
-    if (!monster_idx.has_value()) {
+    if (!monster_idx) {
         return;
     }
 
index aaff566..8e31b8c 100644 (file)
@@ -108,7 +108,7 @@ void wiz_enter_quest(PlayerType *player_ptr)
     auto &quest_list = QuestList::get_instance();
     const auto quest_max = enum2i(quest_list.rbegin()->first);
     const auto quest_num = input_numerics("QuestID", 0, quest_max - 1, QuestId::NONE);
-    if (!quest_num.has_value()) {
+    if (!quest_num) {
         return;
     }
 
@@ -144,7 +144,7 @@ void wiz_restore_monster_max_num(MonsterRaceId r_idx)
 {
     if (!MonsterRace(r_idx).is_valid()) {
         const auto restore_monrace_id = input_numerics("MonsterID", 1, monraces_info.size() - 1, MonsterRaceId::FILTHY_URCHIN);
-        if (!restore_monrace_id.has_value()) {
+        if (!restore_monrace_id) {
             return;
         }
 
index f1de863..4c9f095 100644 (file)
@@ -231,7 +231,7 @@ void wiz_restore_aware_flag_of_fixed_arfifact(FixedArtifactId reset_artifact_idx
     }
 
     const auto input_artifact_id = input_numerics("Artifact ID", 1, max_a_idx, FixedArtifactId::GALADRIEL_PHIAL);
-    if (!input_artifact_id.has_value()) {
+    if (!input_artifact_id) {
         return;
     }
 
@@ -256,7 +256,7 @@ void wiz_modify_item_activation(PlayerType *player_ptr)
     constexpr auto min = enum2i(RandomArtActType::NONE);
     constexpr auto max = enum2i(RandomArtActType::MAX) - 1;
     const auto act_id = input_numerics<RandomArtActType>("Activation ID", min, max);
-    if (!act_id.has_value()) {
+    if (!act_id) {
         return;
     }
 
@@ -468,7 +468,7 @@ static void wiz_statistics(PlayerType *player_ptr, ItemEntity *o_ptr)
     while (true) {
         wiz_display_item(player_ptr, o_ptr);
         const auto command = input_command(prompt);
-        if (!command.has_value()) {
+        if (!command) {
             break;
         }
 
@@ -490,7 +490,7 @@ static void wiz_statistics(PlayerType *player_ptr, ItemEntity *o_ptr)
 
         constexpr auto p = "Enter number of items to roll: ";
         const auto rolls_opt = input_numerics(p, 0, MAX_INT, rolls);
-        if (rolls_opt.has_value()) {
+        if (rolls_opt) {
             rolls = rolls_opt.value();
         }
 
@@ -570,7 +570,7 @@ static void wiz_reroll_item(PlayerType *player_ptr, ItemEntity *o_ptr)
     while (true) {
         wiz_display_item(player_ptr, q_ptr);
         const auto command = input_command(prompt);
-        if (!command.has_value()) {
+        if (!command) {
             if (q_ptr->is_fixed_artifact()) {
                 q_ptr->get_fixed_artifact().is_generated = false;
                 q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
@@ -670,28 +670,28 @@ static void wiz_tweak_item(PlayerType *player_ptr, ItemEntity *o_ptr)
     }
 
     const auto pval = input_numerics("Enter new 'pval' setting: ", -MAX_SHORT, MAX_SHORT, o_ptr->pval);
-    if (!pval.has_value()) {
+    if (!pval) {
         return;
     }
 
     o_ptr->pval = pval.value();
     wiz_display_item(player_ptr, o_ptr);
     const auto bonus_ac = input_numerics("Enter new AC Bonus setting: ", -MAX_SHORT, MAX_SHORT, o_ptr->to_a);
-    if (!bonus_ac.has_value()) {
+    if (!bonus_ac) {
         return;
     }
 
     o_ptr->to_a = bonus_ac.value();
     wiz_display_item(player_ptr, o_ptr);
     const auto bonus_hit = input_numerics("Enter new Hit Bonus setting: ", -MAX_SHORT, MAX_SHORT, o_ptr->to_h);
-    if (!bonus_hit.has_value()) {
+    if (!bonus_hit) {
         return;
     }
 
     o_ptr->to_h = bonus_hit.value();
     wiz_display_item(player_ptr, o_ptr);
     const auto bonus_damage = input_numerics("Enter new Damage Bonus setting: ", -MAX_SHORT, MAX_SHORT, o_ptr->to_d);
-    if (!bonus_damage.has_value()) {
+    if (!bonus_damage) {
         return;
     }
 
@@ -710,7 +710,7 @@ static void wiz_quantity_item(ItemEntity *o_ptr)
     }
 
     const auto quantity_opt = input_numerics("Quantity: ", 1, 99, o_ptr->number);
-    if (!quantity_opt.has_value()) {
+    if (!quantity_opt) {
         return;
     }
 
@@ -750,7 +750,7 @@ void wiz_modify_item(PlayerType *player_ptr)
     while (true) {
         wiz_display_item(player_ptr, q_ptr);
         const auto command = input_command(prompt);
-        if (!command.has_value()) {
+        if (!command) {
             changed = false;
             break;
         }
@@ -873,7 +873,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
     std::string pray;
     while (true) {
         const auto pray_opt = input_string(_("何をお望み? ", "For what do you wish?"), MAX_NLEN);
-        if (pray_opt.has_value()) {
+        if (pray_opt) {
             pray = pray_opt.value();
             break;
         }
index d4f37f5..fbe1078 100644 (file)
@@ -138,7 +138,7 @@ static std::optional<short> wiz_select_tval()
     }
 
     const auto item_type_opt = input_command(_("アイテム種別を選んで下さい", "Get what type of object? "));
-    if (!item_type_opt.has_value()) {
+    if (!item_type_opt) {
         return std::nullopt;
     }
 
@@ -181,7 +181,7 @@ static short wiz_select_sval(const ItemKindType tval, std::string_view tval_desc
     auto max_num = num;
     const auto prompt = format(_("%s群の具体的なアイテムを選んで下さい", "What Kind of %s? "), tval_description.data());
     const auto command = input_command(prompt);
-    if (!command.has_value()) {
+    if (!command) {
         return 0;
     }
 
@@ -213,7 +213,7 @@ static short wiz_create_itemtype()
 {
     term_clear();
     auto selection = wiz_select_tval();
-    if (!selection.has_value()) {
+    if (!selection) {
         return 0;
     }
 
@@ -416,7 +416,7 @@ void wiz_change_status(PlayerType *player_ptr)
         const auto max_max_ability_score = player_ptr->stat_max_max[i];
         const auto max_ability_score = player_ptr->stat_max[i];
         const auto new_ability_score = input_numerics(stat_names[i], 3, max_max_ability_score, max_ability_score);
-        if (!new_ability_score.has_value()) {
+        if (!new_ability_score) {
             return;
         }
 
@@ -428,7 +428,7 @@ void wiz_change_status(PlayerType *player_ptr)
     const auto unskilled = PlayerSkill::weapon_exp_at(PlayerSkillRank::UNSKILLED);
     const auto master = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER);
     const auto proficiency_opt = input_numerics(_("熟練度", "Proficiency"), unskilled, master, static_cast<short>(master));
-    if (!proficiency_opt.has_value()) {
+    if (!proficiency_opt) {
         return;
     }
 
@@ -458,7 +458,7 @@ void wiz_change_status(PlayerType *player_ptr)
     }
 
     const auto gold = input_numerics("Gold: ", 0, MAX_INT, player_ptr->au);
-    if (!gold.has_value()) {
+    if (!gold) {
         return;
     }
 
@@ -468,7 +468,7 @@ void wiz_change_status(PlayerType *player_ptr)
     }
 
     const auto experience_opt = input_numerics("Experience: ", 0, MAX_INT, player_ptr->max_exp);
-    if (!experience_opt.has_value()) {
+    if (!experience_opt) {
         return;
     }
 
@@ -494,12 +494,12 @@ void wiz_create_feature(PlayerType *player_ptr)
     auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
     const int max = TerrainList::get_instance().size() - 1;
     const auto f_val1 = input_numerics(_("実地形ID", "FeatureID"), 0, max, grid.feat);
-    if (!f_val1.has_value()) {
+    if (!f_val1) {
         return;
     }
 
     const auto f_val2 = input_numerics(_("偽装地形ID", "FeatureID"), 0, max, f_val1.value());
-    if (!f_val2.has_value()) {
+    if (!f_val2) {
         return;
     }
 
@@ -530,7 +530,7 @@ static std::optional<short> select_debugging_dungeon(short initial_dungeon_id)
 
     while (true) {
         const auto dungeon_id = input_numerics("Jump which dungeon", DUNGEON_ANGBAND, DUNGEON_DARKNESS, initial_dungeon_id);
-        if (!dungeon_id.has_value()) {
+        if (!dungeon_id) {
             return std::nullopt;
         }
 
@@ -597,7 +597,7 @@ void wiz_jump_to_dungeon(PlayerType *player_ptr)
     const auto is_in_dungeon = floor.is_in_dungeon();
     const auto dungeon_idx = is_in_dungeon ? floor.dungeon_idx : static_cast<short>(DUNGEON_ANGBAND);
     const auto dungeon_id_opt = select_debugging_dungeon(dungeon_idx);
-    if (!dungeon_id_opt.has_value()) {
+    if (!dungeon_id_opt) {
         if (!is_in_dungeon) {
             return;
         }
@@ -611,7 +611,7 @@ void wiz_jump_to_dungeon(PlayerType *player_ptr)
 
     const auto dungeon_id = dungeon_id_opt.value();
     const auto level_opt = select_debugging_floor(floor, dungeon_id);
-    if (!level_opt.has_value()) {
+    if (!level_opt) {
         return;
     }
 
@@ -667,7 +667,7 @@ static void change_birth_flags()
 void wiz_reset_race(PlayerType *player_ptr)
 {
     const auto new_race = input_numerics("RaceID", 0, MAX_RACES - 1, player_ptr->prace);
-    if (!new_race.has_value()) {
+    if (!new_race) {
         return;
     }
 
@@ -684,7 +684,7 @@ void wiz_reset_race(PlayerType *player_ptr)
 void wiz_reset_class(PlayerType *player_ptr)
 {
     const auto new_class_opt = input_numerics("ClassID", 0, PLAYER_CLASS_TYPE_MAX - 1, player_ptr->pclass);
-    if (!new_class_opt.has_value()) {
+    if (!new_class_opt) {
         return;
     }
 
@@ -705,12 +705,12 @@ void wiz_reset_class(PlayerType *player_ptr)
 void wiz_reset_realms(PlayerType *player_ptr)
 {
     const auto new_realm1 = input_numerics("1st Realm (None=0)", 0, MAX_REALM - 1, player_ptr->realm1);
-    if (!new_realm1.has_value()) {
+    if (!new_realm1) {
         return;
     }
 
     const auto new_realm2 = input_numerics("2nd Realm (None=0)", 0, MAX_REALM - 1, player_ptr->realm2);
-    if (!new_realm2.has_value()) {
+    if (!new_realm2) {
         return;
     }
 
@@ -772,7 +772,7 @@ void wiz_dump_options(void)
 void set_gametime(void)
 {
     const auto game_time = input_integer("Dungeon Turn", 0, w_ptr->dungeon_turn_limit - 1);
-    if (!game_time.has_value()) {
+    if (!game_time) {
         return;
     }
 
index 2cc39f1..ed93c65 100644 (file)
@@ -62,7 +62,7 @@ static const std::vector<debug_spell_command> debug_spell_commands_list = {
 void wiz_debug_spell(PlayerType *player_ptr)
 {
     const auto spell = input_string("SPELL: ", 50);
-    if (!spell.has_value()) {
+    if (!spell) {
         return;
     }
 
@@ -77,7 +77,7 @@ void wiz_debug_spell(PlayerType *player_ptr)
             return;
         case 3: {
             const auto power = input_integer("POWER", -MAX_INT, MAX_INT);
-            if (!power.has_value()) {
+            if (!power) {
                 return;
             }
 
@@ -225,7 +225,7 @@ void wiz_summon_specific_monster(PlayerType *player_ptr, MonsterRaceId r_idx)
 {
     if (!MonsterRace(r_idx).is_valid()) {
         const auto new_monrace_id = input_numerics("MonsterID", 1, monraces_info.size() - 1, MonsterRaceId::FILTHY_URCHIN);
-        if (!new_monrace_id.has_value()) {
+        if (!new_monrace_id) {
             return;
         }
 
@@ -246,7 +246,7 @@ void wiz_summon_pet(PlayerType *player_ptr, MonsterRaceId r_idx)
 {
     if (!MonsterRace(r_idx).is_valid()) {
         const auto new_monrace_id = input_numerics("MonsterID", 1, monraces_info.size() - 1, MonsterRaceId::FILTHY_URCHIN);
-        if (!new_monrace_id.has_value()) {
+        if (!new_monrace_id) {
             return;
         }
 
@@ -268,7 +268,7 @@ void wiz_kill_target(PlayerType *player_ptr, int initial_dam, AttributeType effe
     auto dam = initial_dam;
     if (dam <= 0) {
         const auto input_dam = input_integer("Damage", 1, 1000000, 1000000);
-        if (!input_dam.has_value()) {
+        if (!input_dam) {
             return;
         }
 
@@ -291,7 +291,7 @@ void wiz_kill_target(PlayerType *player_ptr, int initial_dam, AttributeType effe
         }
 
         const auto input_effect_id = input_numerics("EffectID", 1, max - 1, idx);
-        if (!input_effect_id.has_value()) {
+        if (!input_effect_id) {
             screen_load();
             return;
         }