From b0d1ecc8f5b87c7af8a4ff2b56075fe49e64cbef Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 27 Nov 2022 11:04:54 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20ItemEntity::is=5Fjunk()=20=E3=81=A8?= =?utf8?q?BaseitemKey::is=5Fjunk()=20=E3=82=92=E5=AE=9A=E7=BE=A9=E3=81=97?= =?utf8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/autopick/autopick-destroyer.cpp | 2 +- src/autopick/autopick-entry.cpp | 2 +- src/system/baseitem-info.cpp | 13 +++++++++++++ src/system/baseitem-info.h | 1 + src/system/item-entity.cpp | 5 +++++ src/system/item-entity.h | 1 + 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/autopick/autopick-destroyer.cpp b/src/autopick/autopick-destroyer.cpp index 1fb3a026b..a5208c865 100644 --- a/src/autopick/autopick-destroyer.cpp +++ b/src/autopick/autopick-destroyer.cpp @@ -111,7 +111,7 @@ static bool is_opt_confirm_destroy(PlayerType *player_ptr, ItemEntity *o_ptr) } if (leave_junk) { - if ((tval == ItemKindType::SKELETON) || (tval == ItemKindType::BOTTLE) || (tval == ItemKindType::JUNK) || (tval == ItemKindType::STATUE)) { + if (o_ptr->is_junk()) { return false; } } diff --git a/src/autopick/autopick-entry.cpp b/src/autopick/autopick-entry.cpp index acdef3f91..251db3ca2 100644 --- a/src/autopick/autopick-entry.cpp +++ b/src/autopick/autopick-entry.cpp @@ -475,7 +475,7 @@ void autopick_entry_from_object(PlayerType *player_ptr, autopick_type *entry, It ADD_FLG(FLG_DEVICES); } else if (tval == ItemKindType::LITE) { ADD_FLG(FLG_LIGHTS); - } else if (tval == ItemKindType::SKELETON || tval == ItemKindType::BOTTLE || tval == ItemKindType::JUNK || tval == ItemKindType::STATUE) { + } else if (o_ptr->is_junk()) { ADD_FLG(FLG_JUNKS); } else if (tval == ItemKindType::CORPSE) { ADD_FLG(FLG_CORPSES); diff --git a/src/system/baseitem-info.cpp b/src/system/baseitem-info.cpp index 983b9842b..7a56c2ec3 100644 --- a/src/system/baseitem-info.cpp +++ b/src/system/baseitem-info.cpp @@ -498,6 +498,19 @@ bool BaseitemKey::is_lite_requiring_fuel() const } } +bool BaseitemKey::is_junk() const +{ + switch (this->type_value) { + case ItemKindType::SKELETON: + case ItemKindType::BOTTLE: + case ItemKindType::JUNK: + case ItemKindType::STATUE: + return true; + default: + return false; + } +} + bool BaseitemKey::is_mushrooms() const { if (!this->subtype_value.has_value()) { diff --git a/src/system/baseitem-info.h b/src/system/baseitem-info.h index e20ee7693..3dfc6afd8 100644 --- a/src/system/baseitem-info.h +++ b/src/system/baseitem-info.h @@ -61,6 +61,7 @@ public: int get_arrow_magnification() const; bool is_aiming_rod() const; bool is_lite_requiring_fuel() const; + bool is_junk() const; private: ItemKindType type_value; diff --git a/src/system/item-entity.cpp b/src/system/item-entity.cpp index ce50d89e6..67eaaedee 100644 --- a/src/system/item-entity.cpp +++ b/src/system/item-entity.cpp @@ -784,3 +784,8 @@ bool ItemEntity::is_lite_requiring_fuel() const { return this->bi_key.is_lite_requiring_fuel(); } + +bool ItemEntity::is_junk() const +{ + return this->bi_key.is_junk(); +} diff --git a/src/system/item-entity.h b/src/system/item-entity.h index 1aa5493e1..fb691affe 100644 --- a/src/system/item-entity.h +++ b/src/system/item-entity.h @@ -129,6 +129,7 @@ public: int get_arrow_magnification() const; bool is_aiming_rod() const; bool is_lite_requiring_fuel() const; + bool is_junk() const; private: int get_baseitem_price() const; -- 2.11.0