OSDN Git Service

[Refactor] #40514 calc_to_hit_bow() と calc_to_hit_bow_display() を統合. / 
authordeskull <deskull@users.sourceforge.jp>
Sat, 15 Aug 2020 04:19:12 +0000 (13:19 +0900)
committerdeskull <deskull@users.sourceforge.jp>
Sat, 15 Aug 2020 04:30:50 +0000 (13:30 +0900)
Merged calc_to_hit_bow () and calc_to_hit_bow_display ().

src/player/player-status.c

index eac6b2f..bad7baa 100644 (file)
@@ -140,8 +140,7 @@ static void calc_to_damage_display(player_type *creature_ptr, INVENTORY_IDX slot
 static void calc_to_hit(player_type *creature_ptr, INVENTORY_IDX slot);
 static void calc_to_hit_display(player_type *creature_ptr, INVENTORY_IDX slot);
 
-static s16b calc_to_hit_bow(player_type *creature_ptr);
-static void calc_to_hit_bow_display(player_type *creature_ptr);
+static s16b calc_to_hit_bow(player_type *creature_ptr, bool is_true_value);
 
 static void calc_to_damage_misc(player_type *creature_ptr);
 static void calc_to_hit_misc(player_type *creature_ptr);
@@ -510,8 +509,8 @@ void calc_bonuses(player_type *creature_ptr)
     calc_to_hit(creature_ptr, INVEN_LARM);
     calc_to_hit_display(creature_ptr, INVEN_RARM);
     calc_to_hit_display(creature_ptr, INVEN_LARM);
-    creature_ptr->to_h_b = calc_to_hit_bow(creature_ptr);
-    calc_to_hit_bow_display(creature_ptr);
+    creature_ptr->to_h_b = calc_to_hit_bow(creature_ptr, TRUE);
+    creature_ptr->dis_to_h_b = calc_to_hit_bow(creature_ptr, FALSE);
     calc_to_damage_misc(creature_ptr);
     calc_to_hit_misc(creature_ptr);
     creature_ptr->skill_dig = calc_skill_dig(creature_ptr);
@@ -3593,11 +3592,14 @@ static void calc_to_hit_display(player_type *creature_ptr, INVENTORY_IDX slot)
     creature_ptr->dis_to_h[id] -= calc_double_weapon_penalty(creature_ptr, slot);
 }
 
-static s16b calc_to_hit_bow(player_type *creature_ptr)
+static s16b calc_to_hit_bow(player_type *creature_ptr, bool is_true_value)
 {
     s16b pow = 0;
 
-    for (int i = INVEN_RARM; i < INVEN_TOTAL; i++) {
+    pow += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
+    pow += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
+
+    for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
         object_type *o_ptr;
         BIT_FLAGS flgs[TR_FLAG_SIZE];
         o_ptr = &creature_ptr->inventory_list[i];
@@ -3642,9 +3644,6 @@ static s16b calc_to_hit_bow(player_type *creature_ptr)
         pow -= 12;
     }
 
-    pow += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
-    pow += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
-
     creature_ptr->hold = adj_str_hold[creature_ptr->stat_ind[A_STR]];
     object_type *o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
 
@@ -3661,7 +3660,7 @@ static s16b calc_to_hit_bow(player_type *creature_ptr)
     }
 
        // 武器以外の装備による修正
-    for (int i = INVEN_RARM; i < INVEN_TOTAL; i++) {
+    for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
         int bonus_to_h;
         o_ptr = &creature_ptr->inventory_list[i];
         if (!o_ptr->k_idx || o_ptr->tval == TV_CAPTURE || (i == INVEN_RARM && has_melee_weapon(creature_ptr, i))
@@ -3675,89 +3674,13 @@ static s16b calc_to_hit_bow(player_type *creature_ptr)
                 bonus_to_h = (o_ptr->to_h + 1) / 2;
         }
 
-        pow += (s16b)bonus_to_h;
+        if (is_true_value || object_is_known(o_ptr))
+               pow += (s16b)bonus_to_h;
     }
 
        return pow;
 }
 
-static void calc_to_hit_bow_display(player_type *creature_ptr)
-{
-    creature_ptr->dis_to_h_b = 0;
-    creature_ptr->dis_to_h_b += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
-    creature_ptr->dis_to_h_b += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
-
-    for (int i = INVEN_RARM; i < INVEN_TOTAL; i++) {
-        object_type *o_ptr;
-        BIT_FLAGS flgs[TR_FLAG_SIZE];
-        o_ptr = &creature_ptr->inventory_list[i];
-        if (!o_ptr->k_idx)
-            continue;
-        object_flags(creature_ptr, o_ptr, flgs);
-
-        if (object_is_fully_known(o_ptr)) {
-            if (o_ptr->curse_flags & TRC_LOW_MELEE) {
-                if (o_ptr->curse_flags & TRC_HEAVY_CURSE) {
-                    creature_ptr->dis_to_h_b -= 15;
-                } else {
-                    creature_ptr->dis_to_h_b -= 5;
-                }
-            }
-        }
-    }
-
-    if (creature_ptr->stun > 50) {
-        creature_ptr->dis_to_h_b -= 20;
-    } else if (creature_ptr->stun) {
-        creature_ptr->dis_to_h_b -= 5;
-    }
-
-    if (is_blessed(creature_ptr)) {
-        creature_ptr->dis_to_h_b += 10;
-    }
-
-    if (is_hero(creature_ptr)) {
-        creature_ptr->dis_to_h_b += 12;
-    }
-
-    if (creature_ptr->shero) {
-        creature_ptr->dis_to_h_b -= 12;
-    }
-
-    object_type *o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
-
-    if (creature_ptr->heavy_shoot) {
-        creature_ptr->dis_to_h_b += 2 * (creature_ptr->hold - o_ptr->weight / 10);
-    }
-
-    if (o_ptr->k_idx) {
-        if (o_ptr->k_idx && !creature_ptr->heavy_shoot) {
-            if ((creature_ptr->pclass == CLASS_SNIPER) && (creature_ptr->tval_ammo == TV_BOLT)) {
-                creature_ptr->dis_to_h_b += (10 + (creature_ptr->lev / 5));
-            }
-        }
-    }
-
-       // 武器以外の装備による修正
-    for (int i = INVEN_RARM; i < INVEN_TOTAL; i++) {
-        int bonus_to_h;
-        o_ptr = &creature_ptr->inventory_list[i];
-        if (!o_ptr->k_idx || o_ptr->tval == TV_CAPTURE || (i == INVEN_RARM && has_melee_weapon(creature_ptr, i))
-            || (i == INVEN_LARM && has_melee_weapon(creature_ptr, i)) || i == INVEN_BOW)
-            continue;
-
-        bonus_to_h = o_ptr->to_h;
-
-        if (creature_ptr->pclass == CLASS_NINJA) {
-            if (o_ptr->to_h > 0)
-                bonus_to_h = (o_ptr->to_h + 1) / 2;
-        }
-
-        if (object_is_known(o_ptr))
-            creature_ptr->dis_to_h_b += (s16b)bonus_to_h;
-    }
-}
-
 static void calc_to_damage_misc(player_type *creature_ptr)
 {
     object_type *o_ptr;