OSDN Git Service

[Refactor] #3496 optional 型の値取得処理 value() を撤廃した その6
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 29 Oct 2023 07:57:15 +0000 (16:57 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 18 Nov 2023 10:36:08 +0000 (19:36 +0900)
src/object-enchant/vorpal-weapon.cpp
src/object-use/zapwand-execution.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 a885cf9..356a51a 100644 (file)
@@ -64,7 +64,7 @@ static void print_chainsword_noise(ItemEntity *o_ptr)
 
     const auto chainsword_noise = get_random_line(_("chainswd_j.txt", "chainswd.txt"), 0);
     if (chainsword_noise) {
-        msg_print(chainsword_noise.value());
+        msg_print(*chainsword_noise);
     }
 }
 
index 55b4ebc..3bf89a7 100644 (file)
@@ -106,7 +106,7 @@ void ObjectZapWandEntity::execute(INVENTORY_IDX i_idx)
     }
 
     sound(SOUND_ZAP);
-    auto ident = wand_effect(this->player_ptr, sval.value(), dir, false, false);
+    auto ident = wand_effect(this->player_ptr, *sval, dir, false, false);
     using Srf = StatusRecalculatingFlag;
     EnumClassFlagGroup<Srf> flags_srf = { Srf::COMBINATION, Srf::REORDER };
     if (rfu.has(Srf::AUTO_DESTRUCTION)) {
@@ -114,7 +114,7 @@ void ObjectZapWandEntity::execute(INVENTORY_IDX i_idx)
     }
 
     rfu.reset_flags(flags_srf);
-    if (!(o_ptr->is_aware())) {
+    if (!o_ptr->is_aware()) {
         chg_virtue(this->player_ptr, Virtue::PATIENCE, -1);
         chg_virtue(this->player_ptr, Virtue::CHANCE, 1);
         chg_virtue(this->player_ptr, Virtue::KNOWLEDGE, -1);
index 8e31b8c..47feb6a 100644 (file)
@@ -112,7 +112,7 @@ void wiz_enter_quest(PlayerType *player_ptr)
         return;
     }
 
-    auto q_idx = quest_num.value();
+    auto q_idx = *quest_num;
     init_flags = i2enum<init_flags_type>(INIT_SHOW_TEXT | INIT_ASSIGN);
     player_ptr->current_floor_ptr->quest_number = q_idx;
     parse_fixed_map(player_ptr, QUEST_DEFINITION_LIST, 0, 0, 0, 0);
@@ -148,7 +148,7 @@ void wiz_restore_monster_max_num(MonsterRaceId r_idx)
             return;
         }
 
-        r_idx = restore_monrace_id.value();
+        r_idx = *restore_monrace_id;
     }
 
     auto *r_ptr = &monraces_info[r_idx];
index 4c9f095..d79cebf 100644 (file)
@@ -235,7 +235,7 @@ void wiz_restore_aware_flag_of_fixed_arfifact(FixedArtifactId reset_artifact_idx
         return;
     }
 
-    artifacts.get_artifact(input_artifact_id.value()).is_generated = aware;
+    artifacts.get_artifact(*input_artifact_id).is_generated = aware;
     msg_print(message);
 }
 
@@ -260,7 +260,7 @@ void wiz_modify_item_activation(PlayerType *player_ptr)
         return;
     }
 
-    auto act_idx = act_id.value();
+    auto act_idx = *act_id;
     o_ptr->art_flags.set(TR_ACTIVATE);
     o_ptr->activation_id = act_idx;
 }
@@ -472,16 +472,15 @@ static void wiz_statistics(PlayerType *player_ptr, ItemEntity *o_ptr)
             break;
         }
 
-        const auto ch = command.value();
         BIT_FLAGS mode;
         std::string quality;
-        if (ch == 'n' || ch == 'N') {
+        if (command == 'n' || command == 'N') {
             mode = 0L;
             quality = "normal";
-        } else if (ch == 'g' || ch == 'G') {
+        } else if (command == 'g' || command == 'G') {
             mode = AM_GOOD;
             quality = "good";
-        } else if (ch == 'e' || ch == 'E') {
+        } else if (command == 'e' || command == 'E') {
             mode = AM_GOOD | AM_GREAT;
             quality = "excellent";
         } else {
@@ -491,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) {
-            rolls = rolls_opt.value();
+            rolls = *rolls_opt;
         }
 
         constexpr auto q = "Rolls: %d  Correct: %d  Matches: %d  Better: %d  Worse: %d  Other: %d";
@@ -580,8 +579,7 @@ static void wiz_reroll_item(PlayerType *player_ptr, ItemEntity *o_ptr)
             break;
         }
 
-        const auto ch = command.value();
-        if (ch == 'A' || ch == 'a') {
+        if (command == 'A' || command == 'a') {
             changed = true;
             break;
         }
@@ -591,7 +589,7 @@ static void wiz_reroll_item(PlayerType *player_ptr, ItemEntity *o_ptr)
             q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
         }
 
-        switch (tolower(ch)) {
+        switch (tolower(*command)) {
         /* Apply bad magic, but first clear object */
         case 'w':
             q_ptr->prep(o_ptr->bi_id);
@@ -674,28 +672,28 @@ static void wiz_tweak_item(PlayerType *player_ptr, ItemEntity *o_ptr)
         return;
     }
 
-    o_ptr->pval = pval.value();
+    o_ptr->pval = *pval;
     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) {
         return;
     }
 
-    o_ptr->to_a = bonus_ac.value();
+    o_ptr->to_a = *bonus_ac;
     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) {
         return;
     }
 
-    o_ptr->to_h = bonus_hit.value();
+    o_ptr->to_h = *bonus_hit;
     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) {
         return;
     }
 
-    o_ptr->to_d = bonus_damage.value();
+    o_ptr->to_d = *bonus_damage;
     wiz_display_item(player_ptr, o_ptr);
 }
 
@@ -709,15 +707,14 @@ static void wiz_quantity_item(ItemEntity *o_ptr)
         return;
     }
 
-    const auto quantity_opt = input_numerics("Quantity: ", 1, 99, o_ptr->number);
-    if (!quantity_opt) {
+    const auto quantity = input_numerics("Quantity: ", 1, 99, o_ptr->number);
+    if (!quantity) {
         return;
     }
 
-    const auto quantity = quantity_opt.value();
-    o_ptr->number = quantity;
+    o_ptr->number = *quantity;
     if (o_ptr->bi_key.tval() == ItemKindType::ROD) {
-        o_ptr->pval = o_ptr->pval * o_ptr->number / quantity;
+        o_ptr->pval = o_ptr->pval * o_ptr->number / *quantity;
     }
 }
 
@@ -755,25 +752,24 @@ void wiz_modify_item(PlayerType *player_ptr)
             break;
         }
 
-        const auto ch = command.value();
-        if (ch == 'A' || ch == 'a') {
+        if (command == 'A' || command == 'a') {
             changed = true;
             break;
         }
 
-        if (ch == 's' || ch == 'S') {
+        if (command == 's' || command == 'S') {
             wiz_statistics(player_ptr, q_ptr);
         }
 
-        if (ch == 'r' || ch == 'R') {
+        if (command == 'r' || command == 'R') {
             wiz_reroll_item(player_ptr, q_ptr);
         }
 
-        if (ch == 't' || ch == 'T') {
+        if (command == 't' || command == 'T') {
             wiz_tweak_item(player_ptr, q_ptr);
         }
 
-        if (ch == 'q' || ch == 'Q') {
+        if (command == 'q' || command == 'Q') {
             wiz_quantity_item(q_ptr);
         }
     }
@@ -874,7 +870,7 @@ WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art,
     while (true) {
         const auto pray_opt = input_string(_("何をお望み? ", "For what do you wish?"), MAX_NLEN);
         if (pray_opt) {
-            pray = pray_opt.value();
+            pray = *pray_opt;
             break;
         }
 
index 4a9ebac..c82b9ac 100644 (file)
@@ -137,12 +137,11 @@ static std::optional<short> wiz_select_tval()
         prt(format("[%c] %s", listsym[list], tvals[list].desc), row, col);
     }
 
-    const auto item_type_opt = input_command(_("アイテム種別を選んで下さい", "Get what type of object? "));
-    if (!item_type_opt) {
+    const auto item_type = input_command(_("アイテム種別を選んで下さい", "Get what type of object? "));
+    if (!item_type) {
         return std::nullopt;
     }
 
-    const auto item_type = item_type_opt.value();
     short selection;
     auto max_num = list;
     for (selection = 0; selection < max_num; selection++) {
@@ -185,10 +184,9 @@ static short wiz_select_sval(const ItemKindType tval, std::string_view tval_desc
         return 0;
     }
 
-    const auto ch = command.value();
     short selection;
     for (selection = 0; selection < max_num; selection++) {
-        if (listsym[selection] == ch) {
+        if (listsym[selection] == command) {
             break;
         }
     }
@@ -420,28 +418,26 @@ void wiz_change_status(PlayerType *player_ptr)
             return;
         }
 
-        auto stat = new_ability_score.value();
-        player_ptr->stat_cur[i] = stat;
-        player_ptr->stat_max[i] = stat;
+        player_ptr->stat_cur[i] = *new_ability_score;
+        player_ptr->stat_max[i] = *new_ability_score;
     }
 
     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) {
+    const auto proficiency = input_numerics(_("熟練度", "Proficiency"), unskilled, master, static_cast<short>(master));
+    if (!proficiency) {
         return;
     }
 
-    const auto proficiency = proficiency_opt.value();
     for (auto tval : TV_WEAPON_RANGE) {
         for (int i = 0; i < 64; i++) {
-            player_ptr->weapon_exp[tval][i] = proficiency;
+            player_ptr->weapon_exp[tval][i] = *proficiency;
         }
     }
 
     PlayerSkill(player_ptr).limit_weapon_skills_by_max_value();
     for (auto j : PLAYER_SKILL_KIND_TYPE_RANGE) {
-        player_ptr->skill_exp[j] = proficiency;
+        player_ptr->skill_exp[j] = *proficiency;
         auto short_pclass = enum2i(player_ptr->pclass);
         if (player_ptr->skill_exp[j] > class_skills_info[short_pclass].s_max[j]) {
             player_ptr->skill_exp[j] = class_skills_info[short_pclass].s_max[j];
@@ -450,11 +446,11 @@ void wiz_change_status(PlayerType *player_ptr)
 
     int k;
     for (k = 0; k < 32; k++) {
-        player_ptr->spell_exp[k] = std::min(PlayerSkill::spell_exp_at(PlayerSkillRank::MASTER), proficiency);
+        player_ptr->spell_exp[k] = std::min(PlayerSkill::spell_exp_at(PlayerSkillRank::MASTER), *proficiency);
     }
 
     for (; k < 64; k++) {
-        player_ptr->spell_exp[k] = std::min(PlayerSkill::spell_exp_at(PlayerSkillRank::EXPERT), proficiency);
+        player_ptr->spell_exp[k] = std::min(PlayerSkill::spell_exp_at(PlayerSkillRank::EXPERT), *proficiency);
     }
 
     const auto gold = input_numerics("Gold: ", 0, MAX_INT, player_ptr->au);
@@ -462,19 +458,18 @@ void wiz_change_status(PlayerType *player_ptr)
         return;
     }
 
-    player_ptr->au = gold.value();
+    player_ptr->au = *gold;
     if (PlayerRace(player_ptr).equals(PlayerRaceType::ANDROID)) {
         return;
     }
 
-    const auto experience_opt = input_numerics("Experience: ", 0, MAX_INT, player_ptr->max_exp);
-    if (!experience_opt) {
+    const auto experience = input_numerics("Experience: ", 0, MAX_INT, player_ptr->max_exp);
+    if (!experience) {
         return;
     }
 
-    const auto experience = experience_opt.value();
-    player_ptr->max_exp = experience;
-    player_ptr->exp = experience;
+    player_ptr->max_exp = *experience;
+    player_ptr->exp = *experience;
     player_ptr->exp_frac = 0;
 }
 
@@ -498,13 +493,13 @@ void wiz_create_feature(PlayerType *player_ptr)
         return;
     }
 
-    const auto f_val2 = input_numerics(_("偽装地形ID", "FeatureID"), 0, max, f_val1.value());
+    const auto f_val2 = input_numerics(_("偽装地形ID", "FeatureID"), 0, max, *f_val1);
     if (!f_val2) {
         return;
     }
 
-    cave_set_feat(player_ptr, y, x, f_val1.value());
-    grid.mimic = f_val2.value();
+    cave_set_feat(player_ptr, y, x, *f_val1);
+    grid.mimic = *f_val2;
     const auto &terrain = grid.get_terrain_mimic();
     if (terrain.flags.has(TerrainCharacteristics::RUNE_PROTECTION) || terrain.flags.has(TerrainCharacteristics::RUNE_EXPLOSION)) {
         grid.info |= CAVE_OBJECT;
@@ -528,14 +523,7 @@ static std::optional<short> select_debugging_dungeon(short initial_dungeon_id)
         return static_cast<short>(std::clamp(static_cast<int>(command_arg), DUNGEON_ANGBAND, DUNGEON_DARKNESS));
     }
 
-    while (true) {
-        const auto dungeon_id = input_numerics("Jump which dungeon", DUNGEON_ANGBAND, DUNGEON_DARKNESS, initial_dungeon_id);
-        if (!dungeon_id) {
-            return std::nullopt;
-        }
-
-        return dungeon_id.value();
-    }
+    return input_numerics("Jump which dungeon", DUNGEON_ANGBAND, DUNGEON_DARKNESS, initial_dungeon_id);
 }
 
 /*
@@ -596,8 +584,8 @@ void wiz_jump_to_dungeon(PlayerType *player_ptr)
     const auto &floor = *player_ptr->current_floor_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) {
+    const auto dungeon_id = select_debugging_dungeon(dungeon_idx);
+    if (!dungeon_id) {
         if (!is_in_dungeon) {
             return;
         }
@@ -609,8 +597,7 @@ void wiz_jump_to_dungeon(PlayerType *player_ptr)
         return;
     }
 
-    const auto dungeon_id = dungeon_id_opt.value();
-    const auto level_opt = select_debugging_floor(floor, dungeon_id);
+    const auto level_opt = select_debugging_floor(floor, *dungeon_id);
     if (!level_opt) {
         return;
     }
@@ -621,7 +608,7 @@ void wiz_jump_to_dungeon(PlayerType *player_ptr)
         do_cmd_save_game(player_ptr, true);
     }
 
-    wiz_jump_floor(player_ptr, dungeon_id, level);
+    wiz_jump_floor(player_ptr, *dungeon_id, level);
 }
 
 /*!
@@ -671,7 +658,7 @@ void wiz_reset_race(PlayerType *player_ptr)
         return;
     }
 
-    player_ptr->prace = new_race.value();
+    player_ptr->prace = *new_race;
     rp_ptr = &race_info[enum2i(player_ptr->prace)];
     change_birth_flags();
     handle_stuff(player_ptr);
@@ -688,7 +675,7 @@ void wiz_reset_class(PlayerType *player_ptr)
         return;
     }
 
-    const auto new_class_enum = new_class_opt.value();
+    const auto new_class_enum = *new_class_opt;
     const auto new_class = enum2i(new_class_enum);
     player_ptr->pclass = new_class_enum;
     cp_ptr = &class_info[new_class];
@@ -714,8 +701,8 @@ void wiz_reset_realms(PlayerType *player_ptr)
         return;
     }
 
-    player_ptr->realm1 = new_realm1.value();
-    player_ptr->realm2 = new_realm2.value();
+    player_ptr->realm1 = *new_realm1;
+    player_ptr->realm2 = *new_realm2;
     change_birth_flags();
     handle_stuff(player_ptr);
 }
@@ -776,7 +763,7 @@ void set_gametime(void)
         return;
     }
 
-    w_ptr->dungeon_turn = w_ptr->game_turn = game_time.value();
+    w_ptr->dungeon_turn = w_ptr->game_turn = *game_time;
 }
 
 /*!
index ed93c65..ac9c95e 100644 (file)
@@ -67,7 +67,7 @@ void wiz_debug_spell(PlayerType *player_ptr)
     }
 
     for (const auto &d : debug_spell_commands_list) {
-        if (spell.value() != d.command_name) {
+        if (*spell != d.command_name) {
             continue;
         }
 
@@ -81,7 +81,7 @@ void wiz_debug_spell(PlayerType *player_ptr)
                 return;
             }
 
-            (d.command_function.spell3.spell_function)(player_ptr, power.value());
+            (d.command_function.spell3.spell_function)(player_ptr, *power);
             return;
         }
         case 4: {
@@ -229,7 +229,7 @@ void wiz_summon_specific_monster(PlayerType *player_ptr, MonsterRaceId r_idx)
             return;
         }
 
-        r_idx = new_monrace_id.value();
+        r_idx = *new_monrace_id;
     }
 
     (void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
@@ -250,7 +250,7 @@ void wiz_summon_pet(PlayerType *player_ptr, MonsterRaceId r_idx)
             return;
         }
 
-        r_idx = new_monrace_id.value();
+        r_idx = *new_monrace_id;
     }
 
     (void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET);
@@ -272,7 +272,7 @@ void wiz_kill_target(PlayerType *player_ptr, int initial_dam, AttributeType effe
             return;
         }
 
-        dam = input_dam.value();
+        dam = *input_dam;
     }
 
     constexpr auto max = enum2i(AttributeType::MAX);
@@ -296,7 +296,7 @@ void wiz_kill_target(PlayerType *player_ptr, int initial_dam, AttributeType effe
             return;
         }
 
-        idx = input_effect_id.value();
+        idx = *input_effect_id;
         screen_load();
     }