diff --git a/Source/items.cpp b/Source/items.cpp index 3eff6392f..661ac9e44 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -40,15 +40,15 @@ namespace devilution { /** Contains the items on ground in the current game. */ Item Items[MAXITEMS + 1]; -int ActiveItems[MAXITEMS]; -int ActiveItemCount; +uint8_t ActiveItems[MAXITEMS]; +uint8_t ActiveItemCount; /** * @brief Contains indexes of empty spaces in Items. * * This array effectively duplicates ActiveItems due to differences in implementation to other fixed buffers. * Eventually this can be removed and Items can be treated the same as how Missiles are tracked */ -int AvailableItems[MAXITEMS]; +uint8_t AvailableItems[MAXITEMS]; bool ShowUniqueItemInfoBox; CornerStoneStruct CornerStone; bool UniqueItemFlags[128]; @@ -2597,9 +2597,9 @@ void InitItems() item._iPostDraw = false; } - for (int i = 0; i < MAXITEMS; i++) { + for (uint8_t i = 0; i < MAXITEMS; i++) { + ActiveItems[i] = i; AvailableItems[i] = i; - ActiveItems[i] = 0; } if (!setlevel) { diff --git a/Source/items.h b/Source/items.h index 6e014ef0d..ae0bd7e6d 100644 --- a/Source/items.h +++ b/Source/items.h @@ -414,9 +414,9 @@ struct CornerStoneStruct { struct Player; extern Item Items[MAXITEMS + 1]; -extern int ActiveItems[MAXITEMS]; -extern int ActiveItemCount; -extern int AvailableItems[MAXITEMS]; +extern uint8_t ActiveItems[MAXITEMS]; +extern uint8_t ActiveItemCount; +extern uint8_t AvailableItems[MAXITEMS]; extern bool ShowUniqueItemInfoBox; extern CornerStoneStruct CornerStone; extern bool UniqueItemFlags[128]; diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index e287a14e1..5151b4e43 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -900,7 +900,7 @@ std::unordered_map LoadDroppedItems(LoadHelper &file) } file.Skip(MAXITEMS * 2 - static_cast(ActiveItemCount)); // Skip loading the rest of ActiveItems and AvailableItems, the indices are initialised below based on the number of active items - for (int i = 0; i < MAXITEMS; i++) { + for (uint8_t i = 0; i < MAXITEMS; i++) { if (i < ActiveItemCount) LoadItem(file, Items[i]); @@ -1512,13 +1512,13 @@ void SavePortal(SaveHelper *file, int i) std::unordered_map SaveDroppedItems(SaveHelper &file) { // Vanilla Diablo/Hellfire initialise the ActiveItems and AvailableItems arrays based on saved data, so write valid values for compatibility - for (int i = 0; i < MAXITEMS; i++) - file.WriteLE(i); // Strictly speaking everything from ActiveItemCount onwards is unused but no harm writing non-zero values here. - for (int i = 0; i < MAXITEMS; i++) - file.WriteLE((i + ActiveItemCount) % MAXITEMS); + for (uint8_t i = 0; i < MAXITEMS; i++) + file.WriteLE(i); // Strictly speaking everything from ActiveItemCount onwards is unused but no harm writing non-zero values here. + for (uint8_t i = 0; i < MAXITEMS; i++) + file.WriteLE((i + ActiveItemCount) % MAXITEMS); std::unordered_map itemIndexes = { { 0, 0 } }; - for (int i = 0; i < ActiveItemCount; i++) { + for (uint8_t i = 0; i < ActiveItemCount; i++) { itemIndexes[ActiveItems[i] + 1] = i + 1; SaveItem(file, Items[ActiveItems[i]]); } @@ -1534,7 +1534,7 @@ void SaveDroppedItemLocations(SaveHelper &file, const std::unordered_map(itemIndexes.at(dItem[i][j])); + file.WriteLE(itemIndexes.at(dItem[i][j])); } }