Skip to content

Commit

Permalink
convert macros to constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Nov 12, 2024
1 parent 9e61053 commit 540d7ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ void SpawnOnePremium(Item &premiumItem, int plvl, const Player &player)
GetItemBonus(player, premiumItem, plvl / 2, plvl, true, !gbIsHellfire);

if (!gbIsHellfire) {
if (premiumItem._iIvalue <= MAX_VENDOR_VALUE) {
if (premiumItem._iIvalue <= MaxVendorValue) {
break;
}
} else {
Expand Down Expand Up @@ -1995,7 +1995,7 @@ void SpawnOnePremium(Item &premiumItem, int plvl, const Player &player)
break;
}
itemValue = itemValue * 4 / 5; // avoids forced int > float > int conversion
if (premiumItem._iIvalue <= MAX_VENDOR_VALUE_HF
if (premiumItem._iIvalue <= MaxVendorValueHf
&& premiumItem._iMinStr <= strength
&& premiumItem._iMinMag <= magic
&& premiumItem._iMinDex <= dexterity
Expand Down Expand Up @@ -4371,10 +4371,10 @@ void SpawnSmith(int lvl)
{
constexpr int PinnedItemCount = 0;

int maxValue = MAX_VENDOR_VALUE;
int maxValue = MaxVendorValue;
int maxItems = 19;
if (gbIsHellfire) {
maxValue = MAX_VENDOR_VALUE_HF;
maxValue = MaxVendorValueHf;
maxItems = 24;
}

Expand Down Expand Up @@ -4442,7 +4442,7 @@ void SpawnWitch(int lvl)
int bookCount = 0;
const int pinnedBookCount = gbIsHellfire ? RandomIntLessThan(MaxPinnedBookCount) : 0;
const int itemCount = RandomIntBetween(10, gbIsHellfire ? 24 : 17);
const int maxValue = gbIsHellfire ? MAX_VENDOR_VALUE_HF : MAX_VENDOR_VALUE;
const int maxValue = gbIsHellfire ? MaxVendorValueHf : MaxVendorValue;

for (int i = 0; i < WITCH_ITEMS; i++) {
Item &item = WitchItems[i];
Expand Down Expand Up @@ -4527,7 +4527,7 @@ void SpawnBoy(int lvl)
GetItemBonus(*MyPlayer, BoyItem, lvl, 2 * lvl, true, true);

if (!gbIsHellfire) {
if (BoyItem._iIvalue > MAX_BOY_VALUE) {
if (BoyItem._iIvalue > MaxBoyValue) {
keepgoing = true; // prevent breaking the do/while loop too early by failing hellfire's condition in while
continue;
}
Expand Down Expand Up @@ -4602,7 +4602,7 @@ void SpawnBoy(int lvl)
}
} while (keepgoing
|| ((
BoyItem._iIvalue > MAX_BOY_VALUE_HF
BoyItem._iIvalue > MaxBoyValueHf
|| BoyItem._iMinStr > strength
|| BoyItem._iMinMag > magic
|| BoyItem._iMinDex > dexterity
Expand Down
8 changes: 4 additions & 4 deletions Source/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ namespace devilution {
// Item indestructible durability
#define DUR_INDESTRUCTIBLE 255

#define MAX_VENDOR_VALUE 140000
#define MAX_VENDOR_VALUE_HF 200000
#define MAX_BOY_VALUE 90000
#define MAX_BOY_VALUE_HF 200000
constexpr int MaxVendorValue = 140000;
constexpr int MaxVendorValueHf = 200000;
constexpr int MaxBoyValue = 90000;
constexpr int MaxBoyValueHf = 200000;

enum item_quality : uint8_t {
ITEM_QUALITY_NORMAL,
Expand Down
4 changes: 2 additions & 2 deletions Source/items/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ bool IsTownItemValid(uint16_t iCreateInfo, const Player &player)

bool IsShopPriceValid(const Item &item)
{
const int boyPriceLimit = gbIsHellfire ? MAX_BOY_VALUE_HF : MAX_BOY_VALUE;
const int boyPriceLimit = gbIsHellfire ? MaxBoyValueHf : MaxBoyValue;
if ((item._iCreateInfo & CF_BOY) != 0 && item._iIvalue > boyPriceLimit)
return false;

const uint16_t smithOrWitch = CF_SMITH | CF_SMITHPREMIUM | CF_WITCH;
const int smithAndWitchPriceLimit = gbIsHellfire ? MAX_VENDOR_VALUE_HF : MAX_VENDOR_VALUE;
const int smithAndWitchPriceLimit = gbIsHellfire ? MaxVendorValueHf : MaxVendorValue;
if ((item._iCreateInfo & smithOrWitch) != 0 && item._iIvalue > smithAndWitchPriceLimit)
return false;

Expand Down

0 comments on commit 540d7ed

Please sign in to comment.