Browse Source

Remove AvailableItems, no longer required

pull/3586/head
ephphatha 5 years ago committed by Anders Jenbo
parent
commit
b8b220311a
  1. 29
      Source/items.cpp
  2. 1
      Source/items.h
  3. 3
      Source/loadsave.cpp

29
Source/items.cpp

@ -42,13 +42,6 @@ namespace devilution {
Item Items[MAXITEMS + 1];
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
*/
uint8_t AvailableItems[MAXITEMS];
bool ShowUniqueItemInfoBox;
CornerStoneStruct CornerStone;
bool UniqueItemFlags[128];
@ -2599,7 +2592,6 @@ void InitItems()
for (uint8_t i = 0; i < MAXITEMS; i++) {
ActiveItems[i] = i;
AvailableItems[i] = i;
}
if (!setlevel) {
@ -3237,12 +3229,12 @@ bool ItemSpaceOk(Point position)
int AllocateItem()
{
int inum = AvailableItems[0];
AvailableItems[0] = AvailableItems[MAXITEMS - ActiveItemCount - 1];
ActiveItems[ActiveItemCount] = inum;
assert(ActiveItemCount < MAXITEMS);
int inum = ActiveItems[ActiveItemCount];
ActiveItemCount++;
memset(&Items[inum], 0, sizeof(*Items));
Items[inum] = {};
return inum;
}
@ -3688,13 +3680,18 @@ void RespawnItem(Item *item, bool flipFlag)
void DeleteItem(int i)
{
if (ActiveItemCount > 0)
ActiveItemCount--;
assert(i >= 0 && i < MAXITEMS && ActiveItemCount < MAXITEMS);
if (pcursitem == ActiveItems[i]) // Unselect item if player has it highlighted
pcursitem = -1;
AvailableItems[MAXITEMS - ActiveItemCount] = ActiveItems[i];
ActiveItemCount--;
if (ActiveItemCount > 0 && i != ActiveItemCount)
ActiveItems[i] = ActiveItems[ActiveItemCount];
if (i < ActiveItemCount) {
// If the deleted item was not already at the end of the active list, swap the indexes around to make the next item allocation simpler.
std::swap(ActiveItems[i], ActiveItems[ActiveItemCount]);
}
}
void ProcessItems()

1
Source/items.h

@ -416,7 +416,6 @@ struct Player;
extern Item Items[MAXITEMS + 1];
extern uint8_t ActiveItems[MAXITEMS];
extern uint8_t ActiveItemCount;
extern uint8_t AvailableItems[MAXITEMS];
extern bool ShowUniqueItemInfoBox;
extern CornerStoneStruct CornerStone;
extern bool UniqueItemFlags[128];

3
Source/loadsave.cpp

@ -904,9 +904,8 @@ std::unordered_map<uint8_t, uint8_t> LoadDroppedItems(LoadHelper &file)
if (i < ActiveItemCount)
LoadItem(file, Items[i]);
// Initialise the ActiveItems and AvailableItems arrays so the existing logic for dropping items can stay unchanged
// Initialise ActiveItems to reflect the order the items were loaded from the file
ActiveItems[i] = i;
AvailableItems[i] = (i + ActiveItemCount) % MAXITEMS;
}
return itemIndexes;

Loading…
Cancel
Save