From 1bb12b1bfba3a524e93f862f4673f3ee465a1930 Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Sat, 3 Apr 2021 21:39:17 -0300 Subject: [PATCH] :recycle: Refactor 'HasRoomForGold' function for readability/robustness --- SourceX/qol.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SourceX/qol.cpp b/SourceX/qol.cpp index 27c13f911..3dbc18d1e 100644 --- a/SourceX/qol.cpp +++ b/SourceX/qol.cpp @@ -183,9 +183,19 @@ bool HasRoomForGold() { for (int i = 0; i < NUM_INV_GRID_ELEM; i++) { int idx = plr[myplr].InvGrid[i]; - if (idx == 0 || (idx > 0 && plr[myplr].InvList[idx - 1]._itype == ITYPE_GOLD && plr[myplr].InvList[idx - 1]._ivalue < MaxGold)) { + + // Secondary item cell. No need to check those as we'll go through the main item cells anyway. + if (idx < 0) + continue; + + // Empty cell. 1x1 space available. + if (idx == 0) + return true; + + // Main item cell. Potentially a gold pile so check it. + auto item = plr[myplr].InvList[idx - 1]; + if (item._itype == ITYPE_GOLD && item._ivalue < MaxGold) return true; - } } return false;