From 14a7759fc9edc3f7266df0031cb4c8023559c904 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Tue, 18 Apr 2023 20:42:45 +0900 Subject: [PATCH] [Refactor] #3133 Reshaped object_similar_part() --- src/object/object-stack.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/object/object-stack.cpp b/src/object/object-stack.cpp index 8ec9a9c31..4ecbb51bd 100644 --- a/src/object/object-stack.cpp +++ b/src/object/object-stack.cpp @@ -16,6 +16,7 @@ #include "sv-definition/sv-other-types.h" #include "system/baseitem-info.h" #include "system/item-entity.h" +#include "util/bit-flags-calculator.h" /*! * @brief 魔法棒やロッドのスロット分割時に使用回数を分配する / @@ -80,18 +81,17 @@ void reduce_charges(ItemEntity *o_ptr, int amt) */ int object_similar_part(const ItemEntity *o_ptr, const ItemEntity *j_ptr) { - const int max_stack_size = 99; - int max_num = max_stack_size; if (o_ptr->bi_id != j_ptr->bi_id) { return 0; } + constexpr auto max_stack_size = 99; + auto max_num = max_stack_size; switch (o_ptr->bi_key.tval()) { case ItemKindType::CHEST: case ItemKindType::CARD: - case ItemKindType::CAPTURE: { + case ItemKindType::CAPTURE: return 0; - } case ItemKindType::STATUE: { const auto o_sval = o_ptr->bi_key.sval(); const auto j_sval = j_ptr->bi_key.sval(); @@ -102,20 +102,18 @@ int object_similar_part(const ItemEntity *o_ptr, const ItemEntity *j_ptr) break; } case ItemKindType::FIGURINE: - case ItemKindType::CORPSE: { + case ItemKindType::CORPSE: if (o_ptr->pval != j_ptr->pval) { return 0; } break; - } case ItemKindType::FOOD: case ItemKindType::POTION: - case ItemKindType::SCROLL: { + case ItemKindType::SCROLL: break; - } - case ItemKindType::STAFF: { - if ((!(o_ptr->ident & (IDENT_EMPTY)) && !o_ptr->is_known()) || (!(j_ptr->ident & (IDENT_EMPTY)) && !j_ptr->is_known())) { + case ItemKindType::STAFF: + if ((none_bits(o_ptr->ident, IDENT_EMPTY) && !o_ptr->is_known()) || (none_bits(j_ptr->ident, IDENT_EMPTY) && !j_ptr->is_known())) { return 0; } @@ -124,18 +122,15 @@ int object_similar_part(const ItemEntity *o_ptr, const ItemEntity *j_ptr) } break; - } - case ItemKindType::WAND: { + case ItemKindType::WAND: if ((!(o_ptr->ident & (IDENT_EMPTY)) && !o_ptr->is_known()) || (!(j_ptr->ident & (IDENT_EMPTY)) && !j_ptr->is_known())) { return 0; } break; - } - case ItemKindType::ROD: { + case ItemKindType::ROD: max_num = std::min(max_num, MAX_SHORT / baseitems_info[o_ptr->bi_id].pval); break; - } case ItemKindType::GLOVES: if (o_ptr->is_glove_same_temper(j_ptr)) { return 0; @@ -193,14 +188,13 @@ int object_similar_part(const ItemEntity *o_ptr, const ItemEntity *j_ptr) } break; - default: { + default: if (!o_ptr->is_known() || !j_ptr->is_known()) { return 0; } break; } - } if (o_ptr->art_flags != j_ptr->art_flags) { return 0; @@ -209,7 +203,8 @@ int object_similar_part(const ItemEntity *o_ptr, const ItemEntity *j_ptr) if (o_ptr->curse_flags != j_ptr->curse_flags) { return 0; } - if ((o_ptr->ident & (IDENT_BROKEN)) != (j_ptr->ident & (IDENT_BROKEN))) { + + if (any_bits(o_ptr->ident, IDENT_BROKEN) != any_bits(j_ptr->ident, IDENT_BROKEN)) { return 0; } @@ -220,6 +215,7 @@ int object_similar_part(const ItemEntity *o_ptr, const ItemEntity *j_ptr) if (!stack_force_notes && (o_ptr->inscription != j_ptr->inscription)) { return 0; } + if (!stack_force_costs && (o_ptr->discount != j_ptr->discount)) { return 0; } -- 2.11.0