Skip to content

Commit

Permalink
[Refactor] #2828 '魔法棒または杖' という判定をItemEntity::is_wand_staff() 及びBaseit…
Browse files Browse the repository at this point in the history
…emKey::is_wand_staff() に繰り込んだ
  • Loading branch information
Hourier authored and sikabane-works committed Dec 22, 2023
1 parent 60799a2 commit cac0d17
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/autopick/autopick-entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ void autopick_entry_from_object(PlayerType *player_ptr, autopick_type *entry, It

if (o_ptr->is_ammo()) {
ADD_FLG(FLG_MISSILES);
} else if (o_ptr->tval == ItemKindType::SCROLL || o_ptr->tval == ItemKindType::STAFF || o_ptr->is_wand_rod()) {
} else if (o_ptr->tval == ItemKindType::SCROLL || o_ptr->is_wand_staff() || o_ptr->is_wand_rod()) {
ADD_FLG(FLG_DEVICES);
} else if (o_ptr->tval == ItemKindType::LITE) {
ADD_FLG(FLG_LIGHTS);
Expand Down
2 changes: 1 addition & 1 deletion src/cmd-item/cmd-eat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ bool exe_eat_food_type_object(PlayerType *player_ptr, ItemEntity *o_ptr)
*/
bool exe_eat_charge_of_magic_device(PlayerType *player_ptr, ItemEntity *o_ptr, INVENTORY_IDX item)
{
if (o_ptr->tval != ItemKindType::STAFF && o_ptr->tval != ItemKindType::WAND) {
if (!o_ptr->is_wand_staff()) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/flavor/flavor-describer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ static void describe_remaining(flavor_type *flavor_ptr)
return;
}

if (((flavor_ptr->o_ptr->tval == ItemKindType::STAFF) || (flavor_ptr->o_ptr->tval == ItemKindType::WAND))) {
if (flavor_ptr->o_ptr->is_wand_staff()) {
describe_charges_staff_wand(flavor_ptr);
} else if (flavor_ptr->o_ptr->tval == ItemKindType::ROD) {
describe_charges_rod(flavor_ptr);
Expand Down
5 changes: 1 addition & 4 deletions src/floor/floor-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,7 @@ OBJECT_IDX drop_near(PlayerType *player_ptr, ItemEntity *j_ptr, PERCENTAGE chanc
void floor_item_charges(FloorType *floor_ptr, INVENTORY_IDX item)
{
auto *o_ptr = &floor_ptr->o_list[item];
if ((o_ptr->tval != ItemKindType::STAFF) && (o_ptr->tval != ItemKindType::WAND)) {
return;
}
if (!o_ptr->is_known()) {
if (!o_ptr->is_wand_staff() || !o_ptr->is_known()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mind/mind-mage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool eat_magic(PlayerType *player_ptr, int power)
msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
if (o_ptr->tval == ItemKindType::ROD) {
o_ptr->timeout = k_ptr->pval * o_ptr->number;
} else if ((o_ptr->tval == ItemKindType::WAND) || (o_ptr->tval == ItemKindType::STAFF)) {
} else if (o_ptr->is_wand_staff()) {
o_ptr->pval = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/monster-attack/monster-eating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void process_eat_lite(PlayerType *player_ptr, MonsterAttackPlayer *monap_ptr)
*/
bool process_un_power(PlayerType *player_ptr, MonsterAttackPlayer *monap_ptr)
{
if (((monap_ptr->o_ptr->tval != ItemKindType::STAFF) && (monap_ptr->o_ptr->tval != ItemKindType::WAND)) || (monap_ptr->o_ptr->pval == 0)) {
if (!monap_ptr->o_ptr->is_wand_staff() || (monap_ptr->o_ptr->pval == 0)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/object-hook/hook-expendable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool item_tester_hook_eatable(PlayerType *player_ptr, const ItemEntity *o_ptr)

auto food_type = PlayerRace(player_ptr).food();
if (food_type == PlayerRaceFoodType::MANA) {
if (o_ptr->tval == ItemKindType::STAFF || o_ptr->tval == ItemKindType::WAND) {
if (o_ptr->is_wand_staff()) {
return true;
}
} else if (food_type == PlayerRaceFoodType::CORPSE) {
Expand Down
2 changes: 1 addition & 1 deletion src/spell-kind/magic-item-recharger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool recharge(PlayerType *player_ptr, int power)
msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
if ((o_ptr->tval == ItemKindType::ROD) && (o_ptr->timeout < 10000)) {
o_ptr->timeout = (o_ptr->timeout + 100) * 2;
} else if ((o_ptr->tval == ItemKindType::WAND) || (o_ptr->tval == ItemKindType::STAFF)) {
} else if (o_ptr->is_wand_staff()) {
o_ptr->pval = 0;
}
return update_player(player_ptr);
Expand Down
10 changes: 3 additions & 7 deletions src/store/store-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,13 @@ std::vector<PARAMETER_VALUE> store_same_magic_device_pvals(ItemEntity *j_ptr)
auto list = std::vector<PARAMETER_VALUE>();
for (INVENTORY_IDX i = 0; i < st_ptr->stock_num; i++) {
auto *o_ptr = &st_ptr->stock[i];
if (o_ptr == j_ptr) {
continue;
}
if (o_ptr->bi_id != j_ptr->bi_id) {
continue;
}
if (o_ptr->tval != ItemKindType::STAFF && o_ptr->tval != ItemKindType::WAND) {
if ((o_ptr == j_ptr) || (o_ptr->bi_id != j_ptr->bi_id) || !o_ptr->is_wand_staff()) {
continue;
}

list.push_back(o_ptr->pval);
}

return list;
}

Expand Down
11 changes: 11 additions & 0 deletions src/system/baseitem-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ bool BaseitemKey::is_wand_rod() const
}
}

bool BaseitemKey::is_wand_staff() const
{
switch (this->type_value) {
case ItemKindType::WAND:
case ItemKindType::STAFF:
return true;
default:
return false;
}
}

bool BaseitemKey::is_mushrooms() const
{
if (!this->subtype_value.has_value()) {
Expand Down
1 change: 1 addition & 0 deletions src/system/baseitem-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BaseitemKey {
bool has_unidentified_name() const;
bool can_recharge() const;
bool is_wand_rod() const;
bool is_wand_staff() const;

private:
ItemKindType type_value;
Expand Down
5 changes: 5 additions & 0 deletions src/system/item-entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,8 @@ bool ItemEntity::is_wand_rod() const
{
return BaseitemKey(this->tval).is_wand_rod();
}

bool ItemEntity::is_wand_staff() const
{
return BaseitemKey(this->tval).is_wand_staff();
}
1 change: 1 addition & 0 deletions src/system/item-entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ItemEntity {
bool has_unidentified_name() const;
ItemKindType get_arrow_kind() const;
bool is_wand_rod() const;
bool is_wand_staff() const;

private:
int get_baseitem_price() const;
Expand Down
7 changes: 1 addition & 6 deletions src/view/object-describer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
*/
void inven_item_charges(const ItemEntity &item)
{
const auto tval = item.tval;
if ((tval != ItemKindType::STAFF) && (tval != ItemKindType::WAND)) {
return;
}

if (!item.is_known()) {
if (!item.is_wand_staff() || !item.is_known()) {
return;
}

Expand Down

0 comments on commit cac0d17

Please sign in to comment.