From cef42d47a8ae5f2d98127f150eba19be0e2c57dd Mon Sep 17 00:00:00 2001 From: ephphatha Date: Thu, 31 Mar 2022 23:09:43 +1100 Subject: [PATCH] Add function to get current grid --- Source/qol/stash.cpp | 4 ++-- Source/qol/stash.h | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index e39050c71..2c4126dfd 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -132,7 +132,7 @@ void CheckStashPaste(Point cursorPosition) } else { stashIndex = it - 1; cn = SwapItem(Stash.stashList[stashIndex], player.HoldItem); - for (auto &row : Stash.stashGrids[Stash.GetPage()]) { + for (auto &row : Stash.GetCurrentGrid()) { for (auto &itemId : row) { if (itemId == it) itemId = 0; @@ -502,7 +502,7 @@ bool UseStashItem(uint16_t c) void StashStruct::RemoveStashItem(uint16_t iv) { // Iterate through stashGrid and remove every reference to item - for (auto &row : Stash.stashGrids[Stash.GetPage()]) { + for (auto &row : Stash.GetCurrentGrid()) { for (uint16_t &itemId : row) { if (itemId - 1 == iv) { itemId = 0; diff --git a/Source/qol/stash.h b/Source/qol/stash.h index 42b04f548..d4105ecdf 100644 --- a/Source/qol/stash.h +++ b/Source/qol/stash.h @@ -17,7 +17,8 @@ namespace devilution { class StashStruct { public: void RemoveStashItem(uint16_t iv); - std::map, 10>> stashGrids; + using StashGrid = std::array, 10>; + std::map stashGrids; std::vector stashList; int gold; bool dirty = false; @@ -27,6 +28,11 @@ public: return page; } + StashGrid &GetCurrentGrid() + { + return stashGrids[GetPage()]; + } + void SetPage(unsigned newPage); void NextPage(unsigned offset = 1); void PreviousPage(unsigned offset = 1);