OSDN Git Service

[Refactor] #2830 bow_tmul() をBaseitemKey のオブジェクトメソッドとして繰り込んだ
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 26 Nov 2022 05:24:09 +0000 (14:24 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 26 Nov 2022 05:33:11 +0000 (14:33 +0900)
src/combat/shoot.cpp
src/combat/shoot.h
src/flavor/flavor-describer.cpp
src/system/baseitem-info.cpp
src/system/baseitem-info.h
src/system/item-entity.cpp
src/system/item-entity.h
src/view/display-player-middle.cpp

index a4bf267..1257963 100644 (file)
@@ -488,14 +488,7 @@ static MULTIPLY calc_shot_damage_with_slay(
  */
 void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPELL_IDX snipe_type)
 {
-    DIRECTION dir;
-    int i;
     POSITION y, x, ny, nx, ty, tx, prev_y, prev_x;
-    int tdam_base, tdis, thits, tmul;
-    int bonus, chance;
-    int cur_dis, visible;
-    PERCENTAGE j;
-
     ItemEntity forge;
     ItemEntity *q_ptr;
     ItemEntity *o_ptr;
@@ -503,12 +496,8 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
     AttributeFlags attribute_flags{};
     attribute_flags.set(AttributeType::PLAYER_SHOOT);
 
-    bool hit_body = false;
-
-    GAME_TEXT o_name[MAX_NLEN];
-
-    /* STICK TO */
-    bool stick_to = false;
+    auto hit_body = false;
+    auto stick_to = false;
 
     /* Access the item (if in the pack) */
     if (item >= 0) {
@@ -522,27 +511,30 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
         snipe_type = SP_NONE;
     }
 
+    GAME_TEXT o_name[MAX_NLEN];
     describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
 
     /* Use the proper number of shots */
-    thits = player_ptr->num_fire;
+    auto thits = player_ptr->num_fire;
 
     /* Use a base distance */
-    tdis = 10;
+    auto tdis = 10;
 
     /* Base damage from thrown object plus launcher bonus */
-    tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
+    auto tdam_base = damroll(o_ptr->dd, o_ptr->ds) + o_ptr->to_d + j_ptr->to_d;
 
     /* Actually "fire" the object */
-    bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
+    auto bonus = (player_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
+    int chance;
+    auto weapon_exp = player_ptr->weapon_exp[j_ptr->tval][j_ptr->sval];
     if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW)) {
-        chance = (player_ptr->skill_thb + (player_ptr->weapon_exp[j_ptr->tval][j_ptr->sval] / 400 + bonus) * BTH_PLUS_ADJ);
+        chance = (player_ptr->skill_thb + (weapon_exp / 400 + bonus) * BTH_PLUS_ADJ);
     } else {
-        chance = (player_ptr->skill_thb + ((player_ptr->weapon_exp[j_ptr->tval][j_ptr->sval] - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
+        chance = (player_ptr->skill_thb + ((weapon_exp - (PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER) / 2)) / 200 + bonus) * BTH_PLUS_ADJ);
     }
 
     PlayerEnergy(player_ptr).set_player_turn_energy(j_ptr->get_bow_energy());
-    tmul = bow_tmul(j_ptr->sval);
+    auto tmul = j_ptr->get_arrow_magnification();
 
     /* Get extra "power" from "extra might" */
     if (player_ptr->xtra_might) {
@@ -567,6 +559,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
     project_length = tdis + 1;
 
     /* Get a direction (or cancel) */
+    DIRECTION dir;
     if (!get_aim_dir(player_ptr, &dir)) {
         PlayerEnergy(player_ptr).reset_player_turn();
 
@@ -609,7 +602,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
     }
 
     /* Take a (partial) turn */
-    PlayerEnergy(player_ptr).div_player_turn_energy((ENERGY)thits);
+    PlayerEnergy(player_ptr).div_player_turn_energy(thits);
     player_ptr->is_fired = true;
 
     /* Sniper - Difficult to shot twice at 1 turn */
@@ -618,7 +611,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
     }
 
     /* Sniper - Repeat shooting when double shots */
-    for (i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
+    for (auto i = 0; i < ((snipe_type == SP_DOUBLE) ? 2 : 1); i++) {
         /* Start at the player */
         y = player_ptr->y;
         x = player_ptr->x;
@@ -640,7 +633,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
         hit_body = false;
 
         /* Travel until stopped */
-        for (cur_dis = 0; cur_dis <= tdis;) {
+        for (auto cur_dis = 0; cur_dis <= tdis;) {
             grid_type *g_ptr;
 
             /* Hack -- Stop at the target */
@@ -740,7 +733,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
                 auto *r_ptr = &monraces_info[m_ptr->r_idx];
 
                 /* Check the visibility */
-                visible = m_ptr->ml;
+                auto visible = m_ptr->ml;
 
                 /* Note the collision */
                 hit_body = true;
@@ -946,7 +939,7 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
         }
 
         /* Chance of breakage (during attacks) */
-        j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
+        auto j = (hit_body ? breakage_chance(player_ptr, q_ptr, PlayerClass(player_ptr).equals(PlayerClassType::ARCHER), snipe_type) : 0);
 
         if (stick_to) {
             MONSTER_IDX m_idx = player_ptr->current_floor_ptr->grid_array[y][x].m_idx;
@@ -1115,55 +1108,6 @@ int critical_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus
     return dam;
 }
 
-/*
- * Return bow tmul
- */
-int bow_tmul(OBJECT_SUBTYPE_VALUE sval)
-{
-    int tmul = 0;
-
-    /* Analyze the launcher */
-    switch (sval) {
-        /* Sling and ammo */
-    case SV_SLING: {
-        tmul = 2;
-        break;
-    }
-
-    /* Short Bow and Arrow */
-    case SV_SHORT_BOW: {
-        tmul = 2;
-        break;
-    }
-
-    /* Long Bow and Arrow */
-    case SV_LONG_BOW: {
-        tmul = 3;
-        break;
-    }
-
-    /* Bow of irresponsiblity and Arrow */
-    case SV_NAMAKE_BOW: {
-        tmul = 3;
-        break;
-    }
-
-    /* Light Crossbow and Bolt */
-    case SV_LIGHT_XBOW: {
-        tmul = 3;
-        break;
-    }
-
-    /* Heavy Crossbow and Bolt */
-    case SV_HEAVY_XBOW: {
-        tmul = 4;
-        break;
-    }
-    }
-
-    return tmul;
-}
-
 /*!
  * @brief 射撃時クリティカルによるダメージ期待値修正計算(スナイパーの集中処理と武器経験値) / critical happens at i / 10000
  * @param player_ptr プレイヤーへの参照ポインタ
index 4d10b82..b9f4b49 100644 (file)
@@ -7,7 +7,6 @@ class ItemEntity;
 class PlayerType;
 bool test_hit_fire(PlayerType *player_ptr, int chance, MonsterEntity *m_ptr, int vis, char *o_name);
 int critical_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam);
-int bow_tmul(OBJECT_SUBTYPE_VALUE sval);
 int calc_crit_ratio_shot(PlayerType *player_ptr, int plus_ammo, int plus_bow);
 int calc_expect_crit_shot(PlayerType *player_ptr, WEIGHT weight, int plus_ammo, int plus_bow, int dam);
 int calc_expect_crit(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, bool dokubari, bool impact);
index 58fa76b..67dcef1 100644 (file)
@@ -153,7 +153,7 @@ static void describe_weapon_dice(PlayerType *player_ptr, flavor_type *flavor_ptr
 
 static void describe_bow(PlayerType *player_ptr, flavor_type *flavor_ptr)
 {
-    flavor_ptr->power = bow_tmul(flavor_ptr->o_ptr->sval);
+    flavor_ptr->power = flavor_ptr->o_ptr->get_arrow_magnification();
     if (flavor_ptr->tr_flags.has(TR_XTRA_MIGHT)) {
         flavor_ptr->power++;
     }
@@ -275,7 +275,7 @@ static void describe_bow_power(PlayerType *player_ptr, flavor_type *flavor_ptr)
     const auto *o_ptr = flavor_ptr->o_ptr;
     const auto *bow_ptr = flavor_ptr->bow_ptr;
     flavor_ptr->avgdam = o_ptr->dd * (o_ptr->ds + 1) * 10 / 2;
-    auto tmul = bow_tmul(bow_ptr->sval);
+    auto tmul = bow_ptr->get_arrow_magnification();
     if (bow_ptr->is_known()) {
         flavor_ptr->avgdam += (bow_ptr->to_d * 10);
     }
index c289f6c..da72f25 100644 (file)
 #include <set>
 #include <unordered_map>
 
+namespace {
+constexpr auto ITEM_NOT_BOW = "This item is not a bow!";
+}
+
 BaseitemKey::BaseitemKey(const ItemKindType type_value, const std::optional<int> &subtype_value)
     : type_value(type_value)
     , subtype_value(subtype_value)
@@ -411,7 +415,7 @@ bool BaseitemKey::is_rare() const
 short BaseitemKey::get_bow_energy() const
 {
     if ((this->type_value != ItemKindType::BOW) || !this->subtype_value.has_value()) {
-        throw std::logic_error("This item is not a bow!");
+        throw std::logic_error(ITEM_NOT_BOW);
     }
 
     switch (this->subtype_value.value()) {
@@ -428,6 +432,27 @@ short BaseitemKey::get_bow_energy() const
     }
 }
 
+int BaseitemKey::get_arrow_magnification() const
+{
+    if ((this->type_value != ItemKindType::BOW) || !this->subtype_value.has_value()) {
+        throw std::logic_error(ITEM_NOT_BOW);
+    }
+
+    switch (this->subtype_value.value()) {
+    case SV_SLING:
+    case SV_SHORT_BOW:
+        return 2;
+    case SV_LONG_BOW:
+    case SV_NAMAKE_BOW:
+    case SV_LIGHT_XBOW:
+        return 3;
+    case SV_HEAVY_XBOW:
+        return 4;
+    default:
+        return 0;
+    }
+}
+
 bool BaseitemKey::is_mushrooms() const
 {
     if (!this->subtype_value.has_value()) {
index 3d8b9fb..9393239 100644 (file)
@@ -58,6 +58,7 @@ public:
     bool is_wieldable_in_etheir_hand() const;
     bool is_rare() const;
     short get_bow_energy() const;
+    int get_arrow_magnification() const;
 
 private:
     ItemKindType type_value;
index 3a03703..2b50c66 100644 (file)
@@ -768,3 +768,8 @@ short ItemEntity::get_bow_energy() const
 {
     return BaseitemKey(this->tval, this->sval).get_bow_energy();
 }
+
+int ItemEntity::get_arrow_magnification() const
+{
+    return BaseitemKey(this->tval, this->sval).get_arrow_magnification();
+}
index b758a17..f1f883b 100644 (file)
@@ -127,6 +127,7 @@ public:
     bool is_wand_rod() const;
     bool is_wand_staff() const;
     short get_bow_energy() const;
+    int get_arrow_magnification() const;
 
 private:
     int get_baseitem_price() const;
index 9e99c7b..ad6526e 100644 (file)
@@ -126,7 +126,7 @@ static void display_shoot_magnification(PlayerType *player_ptr)
 {
     int tmul = 0;
     if (player_ptr->inventory_list[INVEN_BOW].bi_id) {
-        tmul = bow_tmul(player_ptr->inventory_list[INVEN_BOW].sval);
+        tmul = player_ptr->inventory_list[INVEN_BOW].get_arrow_magnification();
         if (player_ptr->xtra_might) {
             tmul++;
         }