diff --git a/Source/inv.cpp b/Source/inv.cpp index 0c3729bd2..6cf415c48 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -235,7 +235,7 @@ bool CanEquip(const Item &item) */ bool CanWield(Player &player, const Item &item) { - if (!CanEquip(item) || (item._iLoc != ILOC_ONEHAND && item._iLoc != ILOC_TWOHAND)) + if (!CanEquip(item) || IsNoneOf(item._iLoc, ILOC_ONEHAND, ILOC_TWOHAND)) return false; Item &leftHandItem = player.InvBody[INVLOC_HAND_LEFT]; @@ -254,7 +254,7 @@ bool CanWield(Player &player, const Item &item) // Barbarian can wield two handed swords and maces in one hand, so we allow equiping any sword/mace as long as his occupied // hand has a shield (i.e. no dual wielding allowed) if (player._pClass == HeroClass::Barbarian) { - if (occupiedHand._itype == ITYPE_SHIELD && (item._itype == ITYPE_SWORD || item._itype == ITYPE_MACE)) + if (occupiedHand._itype == ITYPE_SHIELD && IsAnyOf(item._itype, ITYPE_SWORD, ITYPE_MACE)) return true; } @@ -262,10 +262,10 @@ bool CanWield(Player &player, const Item &item) // slot is another one-handed weapon. if (player._pClass == HeroClass::Bard) { bool occupiedHandIsOneHandedSwordOrMace = occupiedHand._iLoc == ILOC_ONEHAND - && (occupiedHand._itype == ITYPE_SWORD || occupiedHand._itype == ITYPE_MACE); + && IsAnyOf(occupiedHand._itype, ITYPE_SWORD, ITYPE_MACE); bool weaponToEquipIsOneHandedSwordOrMace = item._iLoc == ILOC_ONEHAND - && (item._itype == ITYPE_SWORD || item._itype == ITYPE_MACE); + && IsAnyOf(item._itype, ITYPE_SWORD, ITYPE_MACE); if (occupiedHandIsOneHandedSwordOrMace && weaponToEquipIsOneHandedSwordOrMace) { return true; @@ -397,7 +397,7 @@ void CheckInvPaste(int pnum, Point cursorPosition) if (il == ILOC_ONEHAND && player.HoldItem._iLoc == ILOC_TWOHAND) { if (player._pClass == HeroClass::Barbarian - && (player.HoldItem._itype == ITYPE_SWORD || player.HoldItem._itype == ITYPE_MACE)) + && IsAnyOf(player.HoldItem._itype, ITYPE_SWORD, ITYPE_MACE)) il = ILOC_ONEHAND; else il = ILOC_TWOHAND; @@ -460,7 +460,7 @@ void CheckInvPaste(int pnum, Point cursorPosition) if (!done) return; - if (il != ILOC_UNEQUIPABLE && il != ILOC_BELT && !player.HoldItem._iStatFlag) { + if (IsNoneOf(il, ILOC_UNEQUIPABLE, ILOC_BELT) && !player.HoldItem._iStatFlag) { done = false; player.Say(HeroSpeech::ICantUseThisYet); } @@ -908,7 +908,7 @@ void CheckNaKrulNotes(Player &player) int idx = player.HoldItem.IDidx; _item_indexes notes[] = { IDI_NOTE1, IDI_NOTE2, IDI_NOTE3 }; - if (idx != IDI_NOTE1 && idx != IDI_NOTE2 && idx != IDI_NOTE3) { + if (IsNoneOf(idx, IDI_NOTE1, IDI_NOTE2, IDI_NOTE3)) { return; } @@ -1052,7 +1052,7 @@ bool PutItem(Player &player, Point &position) bool CanUseStaff(Item &staff, spell_id spell) { return !staff.isEmpty() - && (staff._iMiscId == IMISC_STAFF || staff._iMiscId == IMISC_UNIQUE) + && IsAnyOf(staff._iMiscId, IMISC_STAFF, IMISC_UNIQUE) && staff._iSpell == spell && staff._iCharges > 0; } @@ -1163,8 +1163,7 @@ void DrawInv(const Surface &out) if (slot == INVLOC_HAND_LEFT) { if (myPlayer.InvBody[slot]._iLoc == ILOC_TWOHAND) { if (myPlayer._pClass != HeroClass::Barbarian - || (myPlayer.InvBody[slot]._itype != ITYPE_SWORD - && myPlayer.InvBody[slot]._itype != ITYPE_MACE)) { + || IsNoneOf(myPlayer.InvBody[slot]._itype, ITYPE_SWORD, ITYPE_MACE)) { InvDrawSlotBack(out, GetPanelPosition(UiPanels::Inventory, slotPos[INVLOC_HAND_RIGHT]), { slotSize[INVLOC_HAND_RIGHT].width * InventorySlotSizeInPixels.width, slotSize[INVLOC_HAND_RIGHT].height * InventorySlotSizeInPixels.height }); LightTableIndex = 0; cel_transparency_active = true; @@ -1861,7 +1860,7 @@ int8_t CheckInvHLight() } else if (r >= SLOTXY_HAND_RIGHT_FIRST && r <= SLOTXY_HAND_RIGHT_LAST) { pi = &myPlayer.InvBody[INVLOC_HAND_LEFT]; if (pi->isEmpty() || pi->_iLoc != ILOC_TWOHAND - || (myPlayer._pClass == HeroClass::Barbarian && (myPlayer.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD || myPlayer.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_MACE))) { + || (myPlayer._pClass == HeroClass::Barbarian && IsAnyOf(myPlayer.InvBody[INVLOC_HAND_LEFT]._itype, ITYPE_SWORD, ITYPE_MACE))) { rv = INVLOC_HAND_RIGHT; pi = &myPlayer.InvBody[rv]; } else { @@ -1910,7 +1909,7 @@ void RemoveScroll(Player &player) { for (int i = 0; i < player._pNumInv; i++) { if (!player.InvList[i].isEmpty() - && (player.InvList[i]._iMiscId == IMISC_SCROLL || player.InvList[i]._iMiscId == IMISC_SCROLLT) + && IsAnyOf(player.InvList[i]._iMiscId, IMISC_SCROLL, IMISC_SCROLLT) && player.InvList[i]._iSpell == player._pSpell) { player.RemoveInvItem(i); player.CalcScrolls(); @@ -1919,7 +1918,7 @@ void RemoveScroll(Player &player) } for (int i = 0; i < MAXBELTITEMS; i++) { if (!player.SpdList[i].isEmpty() - && (player.SpdList[i]._iMiscId == IMISC_SCROLL || player.SpdList[i]._iMiscId == IMISC_SCROLLT) + && IsAnyOf(player.SpdList[i]._iMiscId, IMISC_SCROLL, IMISC_SCROLLT) && player.SpdList[i]._iSpell == player._pSpell) { player.RemoveSpdBarItem(i); player.CalcScrolls(); @@ -1940,14 +1939,14 @@ bool UseScroll() for (int i = 0; i < myPlayer._pNumInv; i++) { if (!myPlayer.InvList[i].isEmpty() - && (myPlayer.InvList[i]._iMiscId == IMISC_SCROLL || myPlayer.InvList[i]._iMiscId == IMISC_SCROLLT) + && IsAnyOf(myPlayer.InvList[i]._iMiscId, IMISC_SCROLL, IMISC_SCROLLT) && myPlayer.InvList[i]._iSpell == myPlayer._pRSpell) { return true; } } for (auto &item : myPlayer.SpdList) { if (!item.isEmpty() - && (item._iMiscId == IMISC_SCROLL || item._iMiscId == IMISC_SCROLLT) + && IsAnyOf(item._iMiscId, IMISC_SCROLL, IMISC_SCROLLT) && item._iSpell == myPlayer._pRSpell) { return true; } diff --git a/Source/items.cpp b/Source/items.cpp index 85f5e01bb..a114d7f61 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2254,9 +2254,7 @@ void SpawnOnePremium(int i, int plvl, int playerId) case ITYPE_HARMOR: { const auto *const mostValuablePlayerArmor = player.GetMostValuableItem( [](const Item &item) { - return item._itype == ITYPE_LARMOR - || item._itype == ITYPE_MARMOR - || item._itype == ITYPE_HARMOR; + return IsAnyOf(item._itype, ITYPE_LARMOR, ITYPE_MARMOR, ITYPE_HARMOR); }); itemValue = mostValuablePlayerArmor == nullptr ? 0 : mostValuablePlayerArmor->_iIvalue; @@ -2301,7 +2299,7 @@ void SpawnOnePremium(int i, int plvl, int playerId) bool WitchItemOk(int i) { - if (AllItemsList[i].itype != ITYPE_MISC && AllItemsList[i].itype != ITYPE_STAFF) + if (IsNoneOf(AllItemsList[i].itype, ITYPE_MISC, ITYPE_STAFF)) return false; if (AllItemsList[i].iMiscId == IMISC_MANA) return false; @@ -2406,7 +2404,7 @@ void RecreateBoyItem(Item &item, int lvl, int iseed) void RecreateWitchItem(Item &item, int idx, int lvl, int iseed) { - if (idx == IDI_MANA || idx == IDI_FULLMANA || idx == IDI_PORTAL) { + if (IsAnyOf(idx, IDI_MANA, IDI_FULLMANA, IDI_PORTAL)) { GetItemAttrs(item, idx, lvl); } else if (gbIsHellfire && idx >= 114 && idx <= 117) { SetRndSeed(iseed); @@ -2432,7 +2430,7 @@ void RecreateWitchItem(Item &item, int idx, int lvl, int iseed) void RecreateHealerItem(Item &item, int idx, int lvl, int iseed) { - if (idx == IDI_HEAL || idx == IDI_FULLHEAL || idx == IDI_RESURRECT) { + if (IsAnyOf(idx, IDI_HEAL, IDI_FULLHEAL, IDI_RESURRECT)) { GetItemAttrs(item, idx, lvl); } else { SetRndSeed(iseed); @@ -2530,7 +2528,7 @@ bool IsItemAvailable(int i) if (gbIsSpawn) { if (i >= 62 && i <= 71) return false; // Medium and heavy armors - if (i == 105 || i == 107 || i == 108 || i == 110 || i == 111 || i == 113) + if (IsAnyOf(i, 105, 107, 108, 110, 111, 113)) return false; // Unavailable scrolls } @@ -2549,7 +2547,7 @@ bool IsItemAvailable(int i) || ( // Bard items are technically Hellfire-exclusive // but are just normal items with adjusted stats. - sgOptions.Gameplay.bTestBard && (i == IDI_BARDSWORD || i == IDI_BARDDAGGER)); + sgOptions.Gameplay.bTestBard && IsAnyOf(i, IDI_BARDSWORD, IDI_BARDDAGGER)); } BYTE GetOutlineColor(const Item &item, bool checkReq) @@ -2805,7 +2803,7 @@ void CalcPlrItemVals(Player &player, bool loadgfx) player._pIAC -= player.InvBody[INVLOC_HAND_LEFT]._iAC / 2; else if (player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD) player._pIAC -= player.InvBody[INVLOC_HAND_RIGHT]._iAC / 2; - } else if (player.InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_STAFF && player.InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_STAFF && player.InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_BOW && player.InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_BOW) { + } else if (IsNoneOf(player.InvBody[INVLOC_HAND_LEFT]._itype, ITYPE_STAFF, ITYPE_BOW) && IsNoneOf(player.InvBody[INVLOC_HAND_RIGHT]._itype, ITYPE_STAFF, ITYPE_BOW)) { player._pDamageMod += player._pLevel * player._pVitality / 100; } player._pIAC += player._pLevel / 4; @@ -2848,7 +2846,7 @@ void CalcPlrItemVals(Player &player, bool loadgfx) } else if (player._pClass == HeroClass::Barbarian) { vadd += vadd; vadd += (vadd / 4); - } else if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Monk || player._pClass == HeroClass::Bard) { + } else if (IsAnyOf(player._pClass, HeroClass::Rogue, HeroClass::Monk, HeroClass::Bard)) { vadd += vadd / 2; } ihp += (vadd << 6); // BUGFIX: blood boil can cause negative shifts here (see line 757) @@ -2856,7 +2854,7 @@ void CalcPlrItemVals(Player &player, bool loadgfx) if (player._pClass == HeroClass::Sorcerer) { madd *= 2; } - if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Monk) { + if (IsAnyOf(player._pClass, HeroClass::Rogue, HeroClass::Monk)) { madd += madd / 2; } else if (player._pClass == HeroClass::Bard) { madd += (madd / 4) + (madd / 2); @@ -4229,7 +4227,7 @@ void PrintItemDur(Item *x) AddPanelString(tempstr); } } - if (x->_itype == ITYPE_RING || x->_itype == ITYPE_AMULET) + if (IsAnyOf(x->_itype, ITYPE_RING, ITYPE_AMULET)) AddPanelString(_("Not Identified")); PrintItemInfo(*x); } @@ -4243,9 +4241,9 @@ void UseItem(int p, item_misc_id mid, spell_id spl) case IMISC_FOOD: { int j = player._pMaxHP >> 8; int l = ((j / 2) + GenerateRnd(j)) << 6; - if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) + if (IsAnyOf(player._pClass, HeroClass::Warrior, HeroClass::Barbarian)) l *= 2; - if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Monk || player._pClass == HeroClass::Bard) + if (IsAnyOf(player._pClass, HeroClass::Rogue, HeroClass::Monk, HeroClass::Bard)) l += l / 2; player._pHitPoints = std::min(player._pHitPoints + l, player._pMaxHP); player._pHPBase = std::min(player._pHPBase + l, player._pMaxHPBase); @@ -4261,7 +4259,7 @@ void UseItem(int p, item_misc_id mid, spell_id spl) int l = ((j / 2) + GenerateRnd(j)) << 6; if (player._pClass == HeroClass::Sorcerer) l *= 2; - if (player._pClass == HeroClass::Rogue || player._pClass == HeroClass::Monk || player._pClass == HeroClass::Bard) + if (IsAnyOf(player._pClass, HeroClass::Rogue, HeroClass::Monk, HeroClass::Bard)) l += l / 2; if ((player._pIFlags & ISPL_NOMANA) == 0) { player._pMana = std::min(player._pMana + l, player._pMaxMana); @@ -4301,7 +4299,7 @@ void UseItem(int p, item_misc_id mid, spell_id spl) case IMISC_REJUV: { int j = player._pMaxHP >> 8; int l = ((j / 2) + GenerateRnd(j)) << 6; - if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) + if (IsAnyOf(player._pClass, HeroClass::Warrior, HeroClass::Barbarian)) l *= 2; if (player._pClass == HeroClass::Rogue) l += l / 2; @@ -4630,9 +4628,7 @@ void SpawnBoy(int lvl) case ITYPE_HARMOR: { const auto *const mostValuablePlayerArmor = myPlayer.GetMostValuableItem( [](const Item &item) { - return item._itype == ITYPE_LARMOR - || item._itype == ITYPE_MARMOR - || item._itype == ITYPE_HARMOR; + return IsAnyOf(item._itype, ITYPE_LARMOR, ITYPE_MARMOR, ITYPE_HARMOR); }); ivalue = mostValuablePlayerArmor == nullptr ? 0 : mostValuablePlayerArmor->_iIvalue; @@ -4661,27 +4657,27 @@ void SpawnBoy(int lvl) if (count < 200) { switch (pc) { case HeroClass::Warrior: - if (itemType == ITYPE_BOW || itemType == ITYPE_STAFF) + if (IsAnyOf(itemType, ITYPE_BOW, ITYPE_STAFF)) ivalue = INT_MAX; break; case HeroClass::Rogue: - if (itemType == ITYPE_SWORD || itemType == ITYPE_STAFF || itemType == ITYPE_AXE || itemType == ITYPE_MACE || itemType == ITYPE_SHIELD) + if (IsAnyOf(itemType, ITYPE_SWORD, ITYPE_STAFF, ITYPE_AXE, ITYPE_MACE, ITYPE_SHIELD)) ivalue = INT_MAX; break; case HeroClass::Sorcerer: - if (itemType == ITYPE_STAFF || itemType == ITYPE_AXE || itemType == ITYPE_BOW || itemType == ITYPE_MACE) + if (IsAnyOf(itemType, ITYPE_STAFF, ITYPE_AXE, ITYPE_BOW, ITYPE_MACE)) ivalue = INT_MAX; break; case HeroClass::Monk: - if (itemType == ITYPE_BOW || itemType == ITYPE_MARMOR || itemType == ITYPE_SHIELD || itemType == ITYPE_MACE) + if (IsAnyOf(itemType, ITYPE_BOW, ITYPE_MARMOR, ITYPE_SHIELD, ITYPE_MACE)) ivalue = INT_MAX; break; case HeroClass::Bard: - if (itemType == ITYPE_AXE || itemType == ITYPE_MACE || itemType == ITYPE_STAFF) + if (IsAnyOf(itemType, ITYPE_AXE, ITYPE_MACE, ITYPE_STAFF)) ivalue = INT_MAX; break; case HeroClass::Barbarian: - if (itemType == ITYPE_BOW || itemType == ITYPE_STAFF) + if (IsAnyOf(itemType, ITYPE_BOW, ITYPE_STAFF)) ivalue = INT_MAX; break; }