External iterators for player items

Implements external iterators for player items.
This commit is contained in:
Gleb Mazovetskiy 2021-08-27 14:01:01 +01:00 committed by Anders Jenbo
commit 032eaf7491
4 changed files with 300 additions and 31 deletions

View file

@ -2169,32 +2169,4 @@ bool DropItemBeforeTrig()
return true;
}
/**
* @brief Invokes f for each non-empty item of the given player; covering equipped, inventory and belt items.
* @param player Player with equipped, inventory and belt items.
* @param f Function to invoke on each non-empty item of the player.
*/
void ForEachInventoryItem(PlayerStruct &player, ItemFunc f)
{
// Equipped items.
for (auto &item : player.InvBody) {
if (!item.isEmpty()) {
f(item);
}
}
// Inventory items.
for (int i = 0; i < player._pNumInv; i++) {
auto &item = player.InvList[i];
if (!item.isEmpty()) {
f(item);
}
}
// Belt items.
for (auto &item : player.SpdList) {
if (!item.isEmpty()) {
f(item);
}
}
}
} // namespace devilution