Browse Source

Use the size of the AllItemsList vector instead of IDI_LAST for getting how many items are there

pull/8137/head
Andrettin 7 months ago committed by Anders Jenbo
parent
commit
528c1ad0e6
  1. 6
      Source/items.cpp
  2. 4
      Source/lua/modules/dev/items.cpp
  3. 1
      Source/lua/modules/items.cpp
  4. 2
      Source/pack.cpp
  5. 4
      test/items_test.cpp

6
Source/items.cpp

@ -1351,8 +1351,8 @@ _item_indexes GetItemIndexForDroppableItem(bool considerDropRate, tl::function_r
ril.clear(); ril.clear();
unsigned cumulativeWeight = 0; unsigned cumulativeWeight = 0;
for (std::underlying_type_t<_item_indexes> i = IDI_GOLD; i <= IDI_LAST; i++) { for (size_t i = 0; i < AllItemsList.size(); i++) {
if (!IsItemAvailable(i)) if (!IsItemAvailable(static_cast<int>(i)))
continue; continue;
const ItemData &item = AllItemsList[i]; const ItemData &item = AllItemsList[i];
if (item.dropRate == 0) if (item.dropRate == 0)
@ -2369,7 +2369,7 @@ std::string GetTranslatedItemNameMagical(const Item &item, bool hellfireItem, bo
bool IsItemAvailable(int i) bool IsItemAvailable(int i)
{ {
if (i < 0 || i > IDI_LAST) if (i < 0 || i >= static_cast<int>(AllItemsList.size()))
return false; return false;
if (gbIsSpawn) { if (gbIsSpawn) {

4
Source/lua/modules/dev/items.cpp

@ -135,8 +135,8 @@ std::string DebugSpawnUniqueItem(std::string itemName)
if (!foundUnique) return "No unique item found!"; if (!foundUnique) return "No unique item found!";
_item_indexes uniqueBaseIndex = IDI_GOLD; _item_indexes uniqueBaseIndex = IDI_GOLD;
for (std::underlying_type_t<_item_indexes> j = IDI_GOLD; j <= IDI_LAST; j++) { for (size_t j = 0; j < AllItemsList.size(); j++) {
if (!IsItemAvailable(j)) if (!IsItemAvailable(static_cast<int>(j)))
continue; continue;
if (AllItemsList[j].iItemId == uniqueItem.UIItemId) { if (AllItemsList[j].iItemId == uniqueItem.UIItemId) {
uniqueBaseIndex = static_cast<_item_indexes>(j); uniqueBaseIndex = static_cast<_item_indexes>(j);

1
Source/lua/modules/items.cpp

@ -346,7 +346,6 @@ void RegisterItemIndexEnum(sol::state_view &lua)
{ "RuneOfStone", IDI_RUNEOFSTONE }, { "RuneOfStone", IDI_RUNEOFSTONE },
{ "SorcererDiablo", IDI_SORCERER_DIABLO }, { "SorcererDiablo", IDI_SORCERER_DIABLO },
{ "ArenaPotion", IDI_ARENAPOT }, { "ArenaPotion", IDI_ARENAPOT },
{ "Last", IDI_LAST },
{ "None", IDI_NONE }, { "None", IDI_NONE },
}); });
} }

2
Source/pack.cpp

@ -436,7 +436,7 @@ bool UnPackNetItem(const Player &player, const ItemNetPack &packedItem, Item &it
{ {
item = {}; item = {};
const _item_indexes idx = static_cast<_item_indexes>(SDL_SwapLE16(packedItem.def.wIndx)); const _item_indexes idx = static_cast<_item_indexes>(SDL_SwapLE16(packedItem.def.wIndx));
if (idx < 0 || idx > IDI_LAST) if (idx < 0 || idx >= static_cast<_item_indexes>(AllItemsList.size()))
return true; return true;
if (idx == IDI_EAR) { if (idx == IDI_EAR) {
RecreateEar(item, SDL_SwapLE16(packedItem.ear.wCI), SDL_SwapLE32(packedItem.ear.dwSeed), packedItem.ear.bCursval, packedItem.ear.heroname); RecreateEar(item, SDL_SwapLE16(packedItem.ear.wCI), SDL_SwapLE32(packedItem.ear.dwSeed), packedItem.ear.bCursval, packedItem.ear.heroname);

4
test/items_test.cpp

@ -62,8 +62,8 @@ void GenerateAllUniques(bool hellfire, const size_t expectedUniques)
continue; continue;
_item_indexes uniqueBaseIndex = IDI_GOLD; _item_indexes uniqueBaseIndex = IDI_GOLD;
for (std::underlying_type_t<_item_indexes> j = IDI_GOLD; j <= IDI_LAST; j++) { for (size_t j = 0; j < AllItemsList.size(); j++) {
if (!IsItemAvailable(j)) if (!IsItemAvailable(static_cast<int>(j)))
continue; continue;
if (AllItemsList[j].iItemId != uniqueItem.UIItemId) if (AllItemsList[j].iItemId != uniqueItem.UIItemId)
continue; continue;

Loading…
Cancel
Save