Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,16 @@

void AddInitItems()
{
int curlv = ItemsGetCurrlevel();
int rnd = GenerateRnd(3) + 3;
const int curlv = ItemsGetCurrlevel();
const int rnd = GenerateRnd(3) + 3;
for (int j = 0; j < rnd; j++) {
int ii = AllocateItem();
const int ii = AllocateItem();
auto &item = Items[ii];

Point position = GetRandomAvailableItemPosition();
const Point position = GetRandomAvailableItemPosition();
item.position = position;

dItem[position.x][position.y] = ii + 1;

Check warning on line 427 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:427:35 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int8_t' (aka 'signed char') is implementation-defined

item._iSeed = AdvanceRndSeed();
SetRndSeed(item._iSeed);
Expand All @@ -433,7 +433,7 @@

item._iCreateInfo = curlv | CF_PREGEN;
SetupItem(item);
item.AnimInfo.currentFrame = item.AnimInfo.numberOfFrames - 1;
item.AnimInfo.currentFrame = static_cast<int8_t>(item.AnimInfo.numberOfFrames - 1);
item._iAnimFlag = false;
item.selectionRegion = SelectionRegion::Bottom;
DeltaAddItem(ii);
Expand All @@ -456,7 +456,7 @@
break;
}

Point position = GetRandomAvailableItemPosition();
const Point position = GetRandomAvailableItemPosition();
SpawnQuestItem(id, position, 0, SelectionRegion::Bottom, false);
}

Expand Down Expand Up @@ -555,7 +555,7 @@
xx += position.x - 1;
yy += position.y - 1;
Items[inum].position = { xx, yy };
dItem[xx][yy] = inum + 1;
dItem[xx][yy] = static_cast<int8_t>(inum + 1);

return true;
}
Expand All @@ -575,20 +575,18 @@

void GetBookSpell(Item &item, int lvl)
{
int rv;

if (lvl == 0)
lvl = 1;

rv = GenerateRnd(SpellsData.size()) + 1;
int rv = GenerateRnd(static_cast<int32_t>(SpellsData.size())) + 1;

if (gbIsSpawn && lvl > 5)
lvl = 5;

int s = static_cast<int8_t>(SpellID::Firebolt);
SpellID bs = SpellID::Firebolt;
while (rv > 0) {
int sLevel = GetSpellBookLevel(static_cast<SpellID>(s));
const int sLevel = GetSpellBookLevel(static_cast<SpellID>(s));
if (sLevel != -1 && lvl >= sLevel) {
rv--;
bs = static_cast<SpellID>(s);
Expand All @@ -613,8 +611,8 @@
item._iSpell = bs;
const SpellData &spellData = GetSpellData(bs);
item._iMinMag = spellData.minInt;
item._ivalue += spellData.bookCost();
item._iIvalue += spellData.bookCost();
item._ivalue += static_cast<int32_t>(spellData.bookCost());
item._iIvalue += static_cast<int32_t>(spellData.bookCost());
switch (spellData.type()) {
case MagicType::Fire:
item._iCurs = ICURS_BOOK_RED;
Expand Down Expand Up @@ -663,34 +661,34 @@
}
}

int SaveItemPower(const Player &player, Item &item, ItemPower &power)

Check warning on line 664 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:664:5 [readability-function-cognitive-complexity]

function 'SaveItemPower' has cognitive complexity of 26 (threshold 25)
{
int r = RndPL(power.param1, power.param2);

switch (power.type) {
case IPL_TOHIT:
item._iPLToHit += r;
item._iPLToHit += static_cast<int16_t>(r);

Check warning on line 670 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:670:21 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int16_t' (aka 'short') is implementation-defined
break;
case IPL_TOHIT_CURSE:
item._iPLToHit -= r;
item._iPLToHit -= static_cast<int16_t>(r);

Check warning on line 673 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:673:21 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int16_t' (aka 'short') is implementation-defined
break;
case IPL_DAMP:
item._iPLDam += r;
item._iPLDam += static_cast<int16_t>(r);

Check warning on line 676 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:676:19 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int16_t' (aka 'short') is implementation-defined
break;
case IPL_DAMP_CURSE:
item._iPLDam -= r;
item._iPLDam -= static_cast<int16_t>(r);

Check warning on line 679 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:679:19 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int16_t' (aka 'short') is implementation-defined
break;
case IPL_DOPPELGANGER:
item._iDamAcFlags |= ItemSpecialEffectHf::Doppelganger;
[[fallthrough]];
case IPL_TOHIT_DAMP:
r = RndPL(power.param1, power.param2);
item._iPLDam += r;
item._iPLDam += static_cast<int16_t>(r);

Check warning on line 686 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:686:19 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int16_t' (aka 'short') is implementation-defined
item._iPLToHit += CalculateToHitBonus(power.param1);

Check warning on line 687 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:687:21 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int16_t' (aka 'short') is implementation-defined
break;
case IPL_TOHIT_DAMP_CURSE:
item._iPLDam -= r;
item._iPLDam -= static_cast<int16_t>(r);

Check warning on line 690 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:690:19 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int16_t' (aka 'short') is implementation-defined
item._iPLToHit += CalculateToHitBonus(-power.param1);

Check warning on line 691 in Source/items.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/items.cpp:691:21 [bugprone-narrowing-conversions]

narrowing conversion from 'int' to signed type 'int16_t' (aka 'short') is implementation-defined
break;
case IPL_ACP:
item._iPLAC += r;
Expand Down Expand Up @@ -1207,7 +1205,7 @@
int l = lvl / 2;
if (l == 0)
l = 1;
int rv = GenerateRnd(SpellsData.size()) + 1;
int rv = GenerateRnd(static_cast<int32_t>(SpellsData.size())) + 1;

if (gbIsSpawn && lvl > 10)
lvl = 10;
Expand Down Expand Up @@ -3047,7 +3045,7 @@
uint8_t ii = ActiveItems[ActiveItemCount];
ActiveItemCount++;

dItem[position.x][position.y] = ii + 1;
dItem[position.x][position.y] = static_cast<int8_t>(ii + 1);
auto &item_ = Items[ii];
item_ = std::move(item);
item_.position = position;
Expand Down Expand Up @@ -3571,7 +3569,7 @@
int ii = AllocateItem();
auto &item = Items[ii];

dItem[position.x][position.y] = ii + 1;
dItem[position.x][position.y] = static_cast<int8_t>(ii + 1);

UnPackItem(pkSItem, *MyPlayer, item, (pkSItem.dwBuff & CF_HELLFIRE) != 0);
item.position = position;
Expand Down
2 changes: 1 addition & 1 deletion Source/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,7 @@ void OperateShrineEnchanted(DiabloGenerator &rng, Player &player)
if (cnt > 1) {
int spellToReduce;
do {
spellToReduce = rng.generateRnd(SpellsData.size()) + 1;
spellToReduce = rng.generateRnd(static_cast<int32_t>(SpellsData.size())) + 1;
} while ((player._pMemSpells & GetSpellBitmask(static_cast<SpellID>(spellToReduce))) == 0);

spell = 1;
Expand Down
Loading