OSDN Git Service

[Refactor] #3358 三項演算子の山をswitch に差し替えた
[hengbandforosx/hengbandosx.git] / src / spell-realm / spells-craft.cpp
index fae3f31..cedfc9a 100644 (file)
@@ -1,8 +1,6 @@
 #include "spell-realm/spells-craft.h"
 #include "avatar/avatar.h"
 #include "core/disturbance.h"
-#include "core/player-redraw-types.h"
-#include "core/player-update-types.h"
 #include "core/stuff-handler.h"
 #include "flavor/flavor-describer.h"
 #include "flavor/object-flavor-types.h"
@@ -19,8 +17,9 @@
 #include "racial/racial-android.h"
 #include "spell/spells-object.h"
 #include "sv-definition/sv-protector-types.h"
-#include "system/object-type-definition.h"
+#include "system/item-entity.h"
 #include "system/player-type-definition.h"
+#include "system/redrawing-flags-updater.h"
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
 #include "view/display-messages.h"
  * @param v 継続時間
  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
  */
-bool set_ele_attack(player_type *player_ptr, uint32_t attack_type, TIME_EFFECT v)
+bool set_ele_attack(PlayerType *player_ptr, uint32_t attack_type, TIME_EFFECT v)
 {
-    v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
+    v = (v > 10000) ? 10000 : (v < 0) ? 0
+                                      : v;
 
     if ((player_ptr->special_attack & (ATTACK_ACID)) && (attack_type != ATTACK_ACID)) {
         player_ptr->special_attack &= ~(ATTACK_ACID);
@@ -63,31 +63,39 @@ bool set_ele_attack(player_type *player_ptr, uint32_t attack_type, TIME_EFFECT v
     if ((v) && (attack_type)) {
         player_ptr->special_attack |= (attack_type);
         player_ptr->ele_attack = v;
-#ifdef JP
-        msg_format("%sで攻撃できるようになった!",
-            ((attack_type == ATTACK_ACID)
-                    ? "酸"
-                    : ((attack_type == ATTACK_ELEC)
-                            ? "電撃"
-                            : ((attack_type == ATTACK_FIRE) ? "火炎"
-                                                            : ((attack_type == ATTACK_COLD) ? "冷気" : ((attack_type == ATTACK_POIS) ? "毒" : "(なし)"))))));
-#else
-        msg_format("For a while, the blows you deal will %s",
-            ((attack_type == ATTACK_ACID)
-                    ? "melt with acid!"
-                    : ((attack_type == ATTACK_ELEC)
-                            ? "shock your foes!"
-                            : ((attack_type == ATTACK_FIRE)
-                                    ? "burn with fire!"
-                                    : ((attack_type == ATTACK_COLD) ? "chill to the bone!"
-                                                                    : ((attack_type == ATTACK_POIS) ? "poison your enemies!" : "do nothing special."))))));
-#endif
+        std::string element;
+        switch (attack_type) {
+        case ATTACK_ACID:
+            element = _("酸", "melt with acid!");
+            break;
+        case ATTACK_ELEC:
+            element = _("電撃", "shock your foes!");
+            break;
+        case ATTACK_FIRE:
+            element = _("火炎", "burn with fire!");
+            break;
+        case ATTACK_COLD:
+            element = _("冷気", "chill to the bone!");
+            break;
+        case ATTACK_POIS:
+            element = _("毒", "poison your enemies!");
+            break;
+        default: // @todo 本来はruntime_error を飛ばすべきだが、既存コードと同じように動くことを優先した.
+            element = _("(なし)", "do nothing special.");
+            break;
+        }
+
+        constexpr auto mes = _("%sで攻撃できるようになった!", "For a while, the blows you deal will %s");
+        msg_format(mes, element.data());
     }
 
-    if (disturb_state)
+    if (disturb_state) {
         disturb(player_ptr, false, false);
-    player_ptr->redraw |= (PR_STATUS);
-    player_ptr->update |= (PU_BONUS);
+    }
+
+    auto &rfu = RedrawingFlagsUpdater::get_instance();
+    rfu.set_flag(MainWindowRedrawingFlag::TIMED_EFFECT);
+    rfu.set_flag(StatusRecalculatingFlag::BONUS);
     handle_stuff(player_ptr);
 
     return true;
@@ -99,9 +107,10 @@ bool set_ele_attack(player_type *player_ptr, uint32_t attack_type, TIME_EFFECT v
  * @param v 継続時間
  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
  */
-bool set_ele_immune(player_type *player_ptr, uint32_t immune_type, TIME_EFFECT v)
+bool set_ele_immune(PlayerType *player_ptr, uint32_t immune_type, TIME_EFFECT v)
 {
-    v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
+    v = (v > 10000) ? 10000 : (v < 0) ? 0
+                                      : v;
 
     if ((player_ptr->special_defense & (DEFENSE_ACID)) && (immune_type != DEFENSE_ACID)) {
         player_ptr->special_defense &= ~(DEFENSE_ACID);
@@ -131,22 +140,38 @@ bool set_ele_immune(player_type *player_ptr, uint32_t immune_type, TIME_EFFECT v
     if ((v) && (immune_type)) {
         player_ptr->special_defense |= (immune_type);
         player_ptr->ele_immune = v;
-        msg_format(_("%sの攻撃を受けつけなくなった!", "For a while, you are immune to %s"),
-            ((immune_type == DEFENSE_ACID)
-                    ? _("酸", "acid!")
-                    : ((immune_type == DEFENSE_ELEC)
-                            ? _("電撃", "electricity!")
-                            : ((immune_type == DEFENSE_FIRE)
-                                    ? _("火炎", "fire!")
-                                    : ((immune_type == DEFENSE_COLD)
-                                            ? _("冷気", "cold!")
-                                            : ((immune_type == DEFENSE_POIS) ? _("毒", "poison!") : _("(なし)", "nothing special.")))))));
+        std::string element;
+        switch (immune_type) {
+        case ATTACK_ACID:
+            element = _("酸", "acid!");
+            break;
+        case ATTACK_ELEC:
+            element = _("電撃", "electricity!");
+            break;
+        case ATTACK_FIRE:
+            element = _("火炎", "fire!");
+            break;
+        case ATTACK_COLD:
+            element = _("冷気", "cold!");
+            break;
+        case ATTACK_POIS:
+            element = _("毒", "poison!");
+            break;
+        default: // @todo 本来はruntime_error を飛ばすべきだが、既存コードと同じように動くことを優先した.
+            element = _("(なし)", "nothing special.");
+            break;
+        }
+
+        msg_format(_("%sの攻撃を受けつけなくなった!", "For a while, you are immune to %s"), element.data());
     }
 
-    if (disturb_state)
+    if (disturb_state) {
         disturb(player_ptr, false, false);
-    player_ptr->redraw |= (PR_STATUS);
-    player_ptr->update |= (PU_BONUS);
+    }
+
+    auto &rfu = RedrawingFlagsUpdater::get_instance();
+    rfu.set_flag(MainWindowRedrawingFlag::TIMED_EFFECT);
+    rfu.set_flag(StatusRecalculatingFlag::BONUS);
     handle_stuff(player_ptr);
 
     return true;
@@ -155,7 +180,7 @@ bool set_ele_immune(player_type *player_ptr, uint32_t immune_type, TIME_EFFECT v
 /*
  * Choose a warrior-mage elemental attack. -LM-
  */
-bool choose_ele_attack(player_type *player_ptr)
+bool choose_ele_attack(PlayerType *player_ptr)
 {
     if (!has_melee_weapon(player_ptr, INVEN_MAIN_HAND) && !has_melee_weapon(player_ptr, INVEN_SUB_HAND)) {
         msg_format(_("武器を持たないと魔法剣は使えない。", "You cannot use temporary branding with no weapon."));
@@ -166,25 +191,29 @@ bool choose_ele_attack(player_type *player_ptr)
     int num = (player_ptr->lev - 20) / 5;
     c_prt(TERM_RED, _("        a) 焼棄", "        a) Fire Brand"), 2, 14);
 
-    if (num >= 2)
+    if (num >= 2) {
         c_prt(TERM_L_WHITE, _("        b) 凍結", "        b) Cold Brand"), 3, 14);
-    else
+    } else {
         prt("", 3, 14);
+    }
 
-    if (num >= 3)
+    if (num >= 3) {
         c_prt(TERM_GREEN, _("        c) 毒殺", "        c) Poison Brand"), 4, 14);
-    else
+    } else {
         prt("", 4, 14);
+    }
 
-    if (num >= 4)
+    if (num >= 4) {
         c_prt(TERM_L_DARK, _("        d) 溶解", "        d) Acid Brand"), 5, 14);
-    else
+    } else {
         prt("", 5, 14);
+    }
 
-    if (num >= 5)
+    if (num >= 5) {
         c_prt(TERM_BLUE, _("        e) 電撃", "        e) Elec Brand"), 6, 14);
-    else
+    } else {
         prt("", 6, 14);
+    }
 
     prt("", 7, 14);
     prt("", 8, 14);
@@ -195,17 +224,17 @@ bool choose_ele_attack(player_type *player_ptr)
 
     char choice = inkey();
 
-    if ((choice == 'a') || (choice == 'A'))
+    if ((choice == 'a') || (choice == 'A')) {
         set_ele_attack(player_ptr, ATTACK_FIRE, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
-    else if (((choice == 'b') || (choice == 'B')) && (num >= 2))
+    } else if (((choice == 'b') || (choice == 'B')) && (num >= 2)) {
         set_ele_attack(player_ptr, ATTACK_COLD, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
-    else if (((choice == 'c') || (choice == 'C')) && (num >= 3))
+    } else if (((choice == 'c') || (choice == 'C')) && (num >= 3)) {
         set_ele_attack(player_ptr, ATTACK_POIS, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
-    else if (((choice == 'd') || (choice == 'D')) && (num >= 4))
+    } else if (((choice == 'd') || (choice == 'D')) && (num >= 4)) {
         set_ele_attack(player_ptr, ATTACK_ACID, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
-    else if (((choice == 'e') || (choice == 'E')) && (num >= 5))
+    } else if (((choice == 'e') || (choice == 'E')) && (num >= 5)) {
         set_ele_attack(player_ptr, ATTACK_ELEC, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
-    else {
+    else {
         msg_print(_("魔法剣を使うのをやめた。", "You cancel the temporary branding."));
         screen_load();
         return false;
@@ -217,7 +246,7 @@ bool choose_ele_attack(player_type *player_ptr)
 /*
  * Choose a elemental immune. -LM-
  */
-bool choose_ele_immune(player_type *player_ptr, TIME_EFFECT immune_turn)
+bool choose_ele_immune(PlayerType *player_ptr, TIME_EFFECT immune_turn)
 {
     screen_save();
 
@@ -236,15 +265,15 @@ bool choose_ele_immune(player_type *player_ptr, TIME_EFFECT immune_turn)
 
     char choice = inkey();
 
-    if ((choice == 'a') || (choice == 'A'))
+    if ((choice == 'a') || (choice == 'A')) {
         set_ele_immune(player_ptr, DEFENSE_FIRE, immune_turn);
-    else if ((choice == 'b') || (choice == 'B'))
+    } else if ((choice == 'b') || (choice == 'B')) {
         set_ele_immune(player_ptr, DEFENSE_COLD, immune_turn);
-    else if ((choice == 'c') || (choice == 'C'))
+    } else if ((choice == 'c') || (choice == 'C')) {
         set_ele_immune(player_ptr, DEFENSE_ACID, immune_turn);
-    else if ((choice == 'd') || (choice == 'D'))
+    } else if ((choice == 'd') || (choice == 'D')) {
         set_ele_immune(player_ptr, DEFENSE_ELEC, immune_turn);
-    else {
+    else {
         msg_print(_("免疫を付けるのをやめた。", "You cancel the temporary immunity."));
         screen_load();
         return false;
@@ -259,40 +288,40 @@ bool choose_ele_immune(player_type *player_ptr, TIME_EFFECT immune_turn)
  * pulish shield
  * @return ターン消費を要する処理を行ったならばTRUEを返す
  */
-bool pulish_shield(player_type *player_ptr)
+bool pulish_shield(PlayerType *player_ptr)
 {
-    concptr q = _("どの盾を磨きますか?", "Polish which shield? ");
-    concptr s = _("磨く盾がありません。", "You have no shield to polish.");
-
-    OBJECT_IDX item;
-    object_type *o_ptr = choose_object(player_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT, TvalItemTester(TV_SHIELD));
-    if (o_ptr == nullptr)
+    const auto q = _("どの盾を磨きますか?", "Polish which shield? ");
+    const auto s = _("磨く盾がありません。", "You have no shield to polish.");
+    const auto options = USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT;
+    short item;
+    auto *o_ptr = choose_object(player_ptr, &item, q, s, options, TvalItemTester(ItemKindType::SHIELD));
+    if (o_ptr == nullptr) {
         return false;
+    }
 
-    GAME_TEXT o_name[MAX_NLEN];
-    describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX | OD_NAME_ONLY);
-
-    bool is_pulish_successful = o_ptr->k_idx && !o_ptr->is_artifact() && !o_ptr->is_ego();
+    const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX | OD_NAME_ONLY);
+    auto is_pulish_successful = o_ptr->is_valid() && !o_ptr->is_fixed_or_random_artifact() && !o_ptr->is_ego();
     is_pulish_successful &= !o_ptr->is_cursed();
-    is_pulish_successful &= (o_ptr->sval != SV_MIRROR_SHIELD);
+    is_pulish_successful &= (o_ptr->bi_key.sval() != SV_MIRROR_SHIELD);
     if (is_pulish_successful) {
 #ifdef JP
-        msg_format("%sは輝いた!", o_name);
+        msg_format("%sは輝いた!", item_name.data());
 #else
-        msg_format("%s %s shine%s!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
+        msg_format("%s %s shine%s!", ((item >= 0) ? "Your" : "The"), item_name.data(), ((o_ptr->number > 1) ? "" : "s"));
 #endif
-        o_ptr->name2 = EGO_REFLECTION;
-        enchant_equipment(player_ptr, o_ptr, randint0(3) + 4, ENCH_TOAC);
+        o_ptr->ego_idx = EgoType::REFLECTION;
+        enchant_equipment(o_ptr, randint0(3) + 4, ENCH_TOAC);
         o_ptr->discount = 99;
-        chg_virtue(player_ptr, V_ENCHANT, 2);
+        chg_virtue(player_ptr, Virtue::ENCHANT, 2);
         return true;
     }
 
-    if (flush_failure)
+    if (flush_failure) {
         flush();
+    }
 
     msg_print(_("失敗した。", "Failed."));
-    chg_virtue(player_ptr, V_ENCHANT, -2);
+    chg_virtue(player_ptr, Virtue::ENCHANT, -2);
     calc_android_exp(player_ptr);
     return false;
 }