Skip to content

Commit

Permalink
[Refactor] #2776 ItemEntity::tval/sval をBaseitemKey::bi_key として再定義した
Browse files Browse the repository at this point in the history
  • Loading branch information
Hourier committed Dec 1, 2022
1 parent e1b775c commit 8122682
Show file tree
Hide file tree
Showing 134 changed files with 990 additions and 874 deletions.
9 changes: 5 additions & 4 deletions src/action/activation-execution.cpp
Expand Up @@ -68,7 +68,8 @@ static void decide_activation_level(ae_type *ae_ptr)
return;
}

if (((ae_ptr->o_ptr->tval == ItemKindType::RING) || (ae_ptr->o_ptr->tval == ItemKindType::AMULET)) && ae_ptr->o_ptr->is_ego()) {
const auto tval = ae_ptr->o_ptr->bi_key.tval();
if (((tval == ItemKindType::RING) || (tval == ItemKindType::AMULET)) && ae_ptr->o_ptr->is_ego()) {
ae_ptr->lev = egos_info[ae_ptr->o_ptr->ego_idx].level;
}
}
Expand Down Expand Up @@ -178,10 +179,10 @@ static bool activate_artifact(PlayerType *player_ptr, ItemEntity *o_ptr)

switch (act_ptr->index) {
case RandomArtActType::BR_FIRE:
o_ptr->timeout = ((o_ptr->tval == ItemKindType::RING) && (o_ptr->sval == SV_RING_FLAMES)) ? 200 : 250;
o_ptr->timeout = o_ptr->bi_key == BaseitemKey(ItemKindType::RING, SV_RING_FLAMES) ? 200 : 250;
return true;
case RandomArtActType::BR_COLD:
o_ptr->timeout = ((o_ptr->tval == ItemKindType::RING) && (o_ptr->sval == SV_RING_ICE)) ? 200 : 250;
o_ptr->timeout = o_ptr->bi_key == BaseitemKey(ItemKindType::RING, SV_RING_ICE) ? 200 : 250;
return true;
case RandomArtActType::TERROR:
o_ptr->timeout = 3 * (player_ptr->lev + 10);
Expand All @@ -196,7 +197,7 @@ static bool activate_artifact(PlayerType *player_ptr, ItemEntity *o_ptr)

static bool activate_whistle(PlayerType *player_ptr, ae_type *ae_ptr)
{
if (ae_ptr->o_ptr->tval != ItemKindType::WHISTLE) {
if (ae_ptr->o_ptr->bi_key.tval() != ItemKindType::WHISTLE) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions src/action/open-util.cpp
Expand Up @@ -24,10 +24,10 @@ OBJECT_IDX chest_check(FloorType *floor_ptr, POSITION y, POSITION x, bool trappe
{
auto *g_ptr = &floor_ptr->grid_array[y][x];
for (const auto this_o_idx : g_ptr->o_idx_list) {
ItemEntity *o_ptr;
o_ptr = &floor_ptr->o_list[this_o_idx];
if ((o_ptr->tval == ItemKindType::CHEST) && (((!trapped) && (o_ptr->pval)) || /* non empty */
((trapped) && (o_ptr->pval > 0)))) { /* trapped only */
const auto &item = floor_ptr->o_list[this_o_idx];
const auto is_empty = trapped || (item.pval == 0);
const auto trapped_only = trapped && (item.pval > 0);
if ((item.bi_key.tval() == ItemKindType::CHEST) && (!is_empty || trapped_only)) {
return this_o_idx;
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/artifact/fixed-art-generator.cpp
Expand Up @@ -316,11 +316,7 @@ bool make_artifact(PlayerType *player_ptr, ItemEntity *o_ptr)
continue;
}

if (a_ref.bi_key.tval() != o_ptr->tval) {
continue;
}

if (a_ref.bi_key.sval() != o_ptr->sval) {
if (a_ref.bi_key != o_ptr->bi_key) {
continue;
}

Expand Down
13 changes: 7 additions & 6 deletions src/artifact/random-art-generator.cpp
Expand Up @@ -43,7 +43,7 @@

static bool weakening_artifact(ItemEntity *o_ptr)
{
const auto bi_id = lookup_baseitem_id({ o_ptr->tval, o_ptr->sval });
const auto bi_id = lookup_baseitem_id(o_ptr->bi_key);
auto *k_ptr = &baseitems_info[bi_id];
auto flgs = object_flags(o_ptr);

Expand Down Expand Up @@ -178,7 +178,8 @@ static bool decide_random_art_cursed(const bool a_scroll, ItemEntity *o_ptr)
return true;
}

if (((o_ptr->tval == ItemKindType::AMULET) || (o_ptr->tval == ItemKindType::RING)) && o_ptr->is_cursed()) {
const auto tval = o_ptr->bi_key.tval();
if (((tval == ItemKindType::AMULET) || (tval == ItemKindType::RING)) && o_ptr->is_cursed()) {
return true;
}

Expand Down Expand Up @@ -215,7 +216,7 @@ static void invest_powers(PlayerType *player_ptr, ItemEntity *o_ptr, int *powers
break;
case 3:
case 4:
if (one_in_(2) && o_ptr->is_weapon_ammo() && (o_ptr->tval != ItemKindType::BOW)) {
if (one_in_(2) && o_ptr->is_weapon_ammo() && (o_ptr->bi_key.tval() != ItemKindType::BOW)) {
if (a_cursed && !one_in_(13)) {
break;
}
Expand Down Expand Up @@ -254,7 +255,7 @@ static void strengthen_pval(ItemEntity *o_ptr)
{
if (o_ptr->art_flags.has(TR_BLOWS)) {
o_ptr->pval = randint1(2);
if ((o_ptr->tval == ItemKindType::SWORD) && (o_ptr->sval == SV_HAYABUSA)) {
if (o_ptr->bi_key == BaseitemKey(ItemKindType::SWORD, SV_HAYABUSA)) {
o_ptr->pval++;
}
} else {
Expand Down Expand Up @@ -323,7 +324,7 @@ static void invest_negative_modified_value(ItemEntity *o_ptr)

static void reset_flags_poison_needle(ItemEntity *o_ptr)
{
if ((o_ptr->tval != ItemKindType::SWORD) || (o_ptr->sval != SV_POISON_NEEDLE)) {
if (o_ptr->bi_key != BaseitemKey(ItemKindType::SWORD, SV_POISON_NEEDLE)) {
return;
}

Expand Down Expand Up @@ -466,7 +467,7 @@ bool become_random_artifact(PlayerType *player_ptr, ItemEntity *o_ptr, bool a_sc
}

invest_negative_modified_value(o_ptr);
if (((o_ptr->artifact_bias == BIAS_MAGE) || (o_ptr->artifact_bias == BIAS_INT)) && (o_ptr->tval == ItemKindType::GLOVES)) {
if (((o_ptr->artifact_bias == BIAS_MAGE) || (o_ptr->artifact_bias == BIAS_INT)) && (o_ptr->bi_key.tval() == ItemKindType::GLOVES)) {
o_ptr->art_flags.set(TR_FREE_ACT);
}

Expand Down
4 changes: 3 additions & 1 deletion src/artifact/random-art-misc.cpp
Expand Up @@ -142,7 +142,9 @@ static void invest_misc_hit_dice(ItemEntity *o_ptr)
o_ptr->art_flags.set(TR_SHOW_MODS);
HIT_PROB bonus_h = 4 + (HIT_PROB)randint1(11);
int bonus_d = 4 + (int)randint1(11);
if ((o_ptr->tval != ItemKindType::SWORD) && (o_ptr->tval != ItemKindType::POLEARM) && (o_ptr->tval != ItemKindType::HAFTED) && (o_ptr->tval != ItemKindType::DIGGING) && (o_ptr->tval != ItemKindType::GLOVES) && (o_ptr->tval != ItemKindType::RING)) {
const auto is_weapon = o_ptr->is_melee_weapon();
const auto tval = o_ptr->bi_key.tval();
if (!is_weapon && (tval != ItemKindType::GLOVES) && (tval != ItemKindType::RING)) {
bonus_h /= 2;
bonus_d /= 2;
}
Expand Down
9 changes: 6 additions & 3 deletions src/artifact/random-art-pval-investor.cpp
Expand Up @@ -76,7 +76,7 @@ static bool random_art_bias_charisma(ItemEntity *o_ptr)

static bool random_art_bias_magic_mastery(ItemEntity *o_ptr)
{
if ((o_ptr->tval != ItemKindType::GLOVES) || o_ptr->art_flags.has(TR_MAGIC_MASTERY)) {
if ((o_ptr->bi_key.tval() != ItemKindType::GLOVES) || o_ptr->art_flags.has(TR_MAGIC_MASTERY)) {
return false;
}

Expand Down Expand Up @@ -135,7 +135,10 @@ static bool switch_random_art_bias(ItemEntity *o_ptr)

static bool random_art_bias_decrease_mana(ItemEntity *o_ptr)
{
if (((o_ptr->artifact_bias != BIAS_MAGE) && (o_ptr->artifact_bias != BIAS_PRIESTLY)) || (o_ptr->tval != ItemKindType::SOFT_ARMOR) || (o_ptr->sval != SV_ROBE) || o_ptr->art_flags.has(TR_DEC_MANA) || !one_in_(3)) {
auto should_decrease = (o_ptr->artifact_bias != BIAS_MAGE) && (o_ptr->artifact_bias != BIAS_PRIESTLY);
should_decrease |= o_ptr->bi_key != BaseitemKey(ItemKindType::SOFT_ARMOR, SV_ROBE);
should_decrease |= o_ptr->art_flags.has(TR_DEC_MANA);
if (should_decrease || !one_in_(3)) {
return false;
}

Expand Down Expand Up @@ -249,7 +252,7 @@ void random_plus(ItemEntity *o_ptr)
break;
case 22:
case 23:
if (o_ptr->tval == ItemKindType::BOW) {
if (o_ptr->bi_key.tval() == ItemKindType::BOW) {
random_plus(o_ptr);
break;
}
Expand Down
14 changes: 10 additions & 4 deletions src/artifact/random-art-resistance.cpp
Expand Up @@ -176,7 +176,7 @@ static void set_bias_pois(ItemEntity *o_ptr)
/* 一定確率で再試行する */
static void set_weird_bias_aura_elec(ItemEntity *o_ptr)
{
if (o_ptr->tval >= ItemKindType::CLOAK && o_ptr->tval <= ItemKindType::HARD_ARMOR) {
if (o_ptr->can_be_aura_protector()) {
o_ptr->art_flags.set(TR_SH_ELEC);
} else {
random_resistance(o_ptr);
Expand All @@ -190,7 +190,7 @@ static void set_weird_bias_aura_elec(ItemEntity *o_ptr)
/* 一定確率で再試行する */
static void set_weird_bias_aura_fire(ItemEntity *o_ptr)
{
if (o_ptr->tval >= ItemKindType::CLOAK && o_ptr->tval <= ItemKindType::HARD_ARMOR) {
if (o_ptr->can_be_aura_protector()) {
o_ptr->art_flags.set(TR_SH_FIRE);
} else {
random_resistance(o_ptr);
Expand All @@ -204,9 +204,15 @@ static void set_weird_bias_aura_fire(ItemEntity *o_ptr)
/* 一定確率で再試行する */
static void set_weird_bias_reflection(ItemEntity *o_ptr)
{
if (o_ptr->tval == ItemKindType::SHIELD || o_ptr->tval == ItemKindType::CLOAK || o_ptr->tval == ItemKindType::HELM || o_ptr->tval == ItemKindType::HARD_ARMOR) {
switch (o_ptr->bi_key.tval()) {
case ItemKindType::SHIELD:
case ItemKindType::CLOAK:
case ItemKindType::HELM:
case ItemKindType::HARD_ARMOR:
o_ptr->art_flags.set(TR_REFLECT);
return;
default:
break;
}

random_resistance(o_ptr);
Expand All @@ -215,7 +221,7 @@ static void set_weird_bias_reflection(ItemEntity *o_ptr)
/* 一定確率で再試行する */
static void set_weird_bias_aura_cold(ItemEntity *o_ptr)
{
if (o_ptr->tval >= ItemKindType::CLOAK && o_ptr->tval <= ItemKindType::HARD_ARMOR) {
if (o_ptr->can_be_aura_protector()) {
o_ptr->art_flags.set(TR_SH_COLD);
} else {
random_resistance(o_ptr);
Expand Down
17 changes: 11 additions & 6 deletions src/artifact/random-art-slay.cpp
Expand Up @@ -13,7 +13,7 @@

static bool random_art_slay_bow(ItemEntity *o_ptr)
{
if (o_ptr->tval != ItemKindType::BOW) {
if (o_ptr->bi_key.tval() != ItemKindType::BOW) {
return false;
}

Expand Down Expand Up @@ -173,22 +173,27 @@ static bool switch_random_art_slay(ItemEntity *o_ptr)
case BIAS_MAGE:
case BIAS_INT:
return random_art_brand_magical(o_ptr);
case BIAS_PRIESTLY:
if (((o_ptr->tval == ItemKindType::SWORD) || (o_ptr->tval == ItemKindType::POLEARM)) && o_ptr->art_flags.has_not(TR_BLESSED)) {
case BIAS_PRIESTLY: {
const auto tval = o_ptr->bi_key.tval();
if (((tval == ItemKindType::SWORD) || (tval == ItemKindType::POLEARM)) && o_ptr->art_flags.has_not(TR_BLESSED)) {
o_ptr->art_flags.set(TR_BLESSED);
}

return false;
}
case BIAS_NECROMANTIC:
return random_art_slay_vampiric(o_ptr) || random_art_slay_brand_pois(o_ptr);
case BIAS_RANGER:
return random_art_slay_animal(o_ptr);
case BIAS_ROGUE:
if ((((o_ptr->tval == ItemKindType::SWORD) && (o_ptr->sval == SV_DAGGER)) || ((o_ptr->tval == ItemKindType::POLEARM) && (o_ptr->sval == SV_SPEAR))) && o_ptr->art_flags.has_not(TR_THROW)) {
case BIAS_ROGUE: {
auto is_throwable = o_ptr->bi_key == BaseitemKey(ItemKindType::SWORD, SV_DAGGER);
is_throwable |= o_ptr->bi_key == BaseitemKey(ItemKindType::POLEARM, SV_SPEAR);
if (is_throwable && o_ptr->art_flags.has_not(TR_THROW)) {
o_ptr->art_flags.set(TR_THROW);
}

return random_art_slay_brand_pois(o_ptr);
}
case BIAS_POIS:
return random_art_slay_brand_pois(o_ptr);
case BIAS_ACID:
Expand Down Expand Up @@ -311,7 +316,7 @@ void random_slay(ItemEntity *o_ptr)
break;
case 18:
case 19:
if (o_ptr->tval != ItemKindType::SWORD) {
if (o_ptr->bi_key.tval() != ItemKindType::SWORD) {
random_slay(o_ptr);
break;
}
Expand Down
19 changes: 11 additions & 8 deletions src/autopick/autopick-destroyer.cpp
Expand Up @@ -46,21 +46,23 @@ static bool is_leave_special_item(PlayerType *player_ptr, ItemEntity *o_ptr)
}

PlayerClass pc(player_ptr);
const auto &bi_key = o_ptr->bi_key;
const auto tval = bi_key.tval();
if (PlayerRace(player_ptr).equals(PlayerRaceType::BALROG)) {
auto r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
if (o_ptr->tval == ItemKindType::CORPSE && o_ptr->sval == SV_CORPSE && angband_strchr("pht", monraces_info[r_idx].d_char)) {
if (bi_key == BaseitemKey(ItemKindType::CORPSE, SV_CORPSE) && angband_strchr("pht", monraces_info[r_idx].d_char)) {
return false;
}
} else if (pc.equals(PlayerClassType::ARCHER)) {
if (o_ptr->tval == ItemKindType::SKELETON || (o_ptr->tval == ItemKindType::CORPSE && o_ptr->sval == SV_SKELETON)) {
if ((tval == ItemKindType::SKELETON) || (bi_key == BaseitemKey(ItemKindType::CORPSE, SV_SKELETON))) {
return false;
}
} else if (pc.equals(PlayerClassType::NINJA)) {
if (o_ptr->tval == ItemKindType::LITE && o_ptr->ego_idx == EgoType::LITE_DARKNESS && o_ptr->is_known()) {
if (tval == ItemKindType::LITE && o_ptr->ego_idx == EgoType::LITE_DARKNESS && o_ptr->is_known()) {
return false;
}
} else if (pc.is_tamer()) {
if (o_ptr->tval == ItemKindType::WAND && o_ptr->sval == SV_WAND_HEAL_MONSTER && o_ptr->is_aware()) {
if (bi_key == BaseitemKey(ItemKindType::WAND, SV_WAND_HEAL_MONSTER) && o_ptr->is_aware()) {
return false;
}
}
Expand Down Expand Up @@ -89,8 +91,9 @@ static bool is_opt_confirm_destroy(PlayerType *player_ptr, ItemEntity *o_ptr)
}
}

const auto tval = o_ptr->bi_key.tval();
if (leave_chest) {
if ((o_ptr->tval == ItemKindType::CHEST) && o_ptr->pval) {
if ((tval == ItemKindType::CHEST) && o_ptr->pval) {
return false;
}
}
Expand All @@ -102,13 +105,13 @@ static bool is_opt_confirm_destroy(PlayerType *player_ptr, ItemEntity *o_ptr)
}

if (leave_corpse) {
if (o_ptr->tval == ItemKindType::CORPSE) {
if (tval == ItemKindType::CORPSE) {
return false;
}
}

if (leave_junk) {
if ((o_ptr->tval == ItemKindType::SKELETON) || (o_ptr->tval == ItemKindType::BOTTLE) || (o_ptr->tval == ItemKindType::JUNK) || (o_ptr->tval == ItemKindType::STATUE)) {
if ((tval == ItemKindType::SKELETON) || (tval == ItemKindType::BOTTLE) || (tval == ItemKindType::JUNK) || (tval == ItemKindType::STATUE)) {
return false;
}
}
Expand All @@ -117,7 +120,7 @@ static bool is_opt_confirm_destroy(PlayerType *player_ptr, ItemEntity *o_ptr)
return false;
}

if (o_ptr->tval == ItemKindType::GOLD) {
if (tval == ItemKindType::GOLD) {
return false;
}

Expand Down

0 comments on commit 8122682

Please sign in to comment.