From 2b9fbc9569898184c4333bada17f9b6bd47b9b42 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Thu, 25 Dec 2025 23:13:56 -0500 Subject: [PATCH 1/7] Refactor OperateShrineHidden --- Source/objects.cpp | 69 +++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 859c7374b..4a8ba8771 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2284,43 +2284,42 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) if (&player != MyPlayer) return; - int cnt = 0; - for (const auto &item : player.InvBody) { - if (!item.isEmpty()) - cnt++; + auto isEligible = [](const Item &it) { + return !it.isEmpty() + && it._iMaxDur != DUR_INDESTRUCTIBLE + && it._iMaxDur > 0; + }; + + auto clampForSave = [](Item &it) { + it._iMaxDur = std::clamp(it._iMaxDur, 1, DUR_INDESTRUCTIBLE); + it._iDurability = std::clamp(it._iDurability, 1, it._iMaxDur); + }; + + std::array eligible {}; + int eligibleCount = 0; + + for (int i = 0; i < NUM_INVLOC; i++) { + if (isEligible(player.InvBody[i])) + eligible[eligibleCount++] = i; } - if (cnt > 0) { - for (auto &item : player.InvBody) { - if (!item.isEmpty() - && item._iMaxDur != DUR_INDESTRUCTIBLE - && item._iMaxDur != 0) { - item._iDurability += 10; - item._iMaxDur += 10; - if (item._iDurability > item._iMaxDur) - item._iDurability = item._iMaxDur; - } - } - while (true) { - cnt = 0; - for (auto &item : player.InvBody) { - if (!item.isEmpty() && item._iMaxDur != DUR_INDESTRUCTIBLE && item._iMaxDur != 0) { - cnt++; - } - } - if (cnt == 0) - break; - const int r = rng.generateRnd(NUM_INVLOC); - if (player.InvBody[r].isEmpty() || player.InvBody[r]._iMaxDur == DUR_INDESTRUCTIBLE || player.InvBody[r]._iMaxDur == 0) - continue; - player.InvBody[r]._iDurability -= 20; - player.InvBody[r]._iMaxDur -= 20; - if (player.InvBody[r]._iDurability <= 0) - player.InvBody[r]._iDurability = 1; - if (player.InvBody[r]._iMaxDur <= 0) - player.InvBody[r]._iMaxDur = 1; - break; - } + if (eligibleCount == 0) { + InitDiabloMsg(EMSG_SHRINE_HIDDEN); + return; + } + + // Pick the one item that will receive the net -10 effect. + const int cursedSlot = eligible[rng.generateRnd(eligibleCount)]; + + for (int k = 0; k < eligibleCount; k++) { + Item &it = player.InvBody[eligible[k]]; + + const int delta = (eligible[k] == cursedSlot) ? -10 : +10; + + it._iMaxDur += delta; + it._iDurability += delta; + + clampForSave(it); } InitDiabloMsg(EMSG_SHRINE_HIDDEN); From b9c153c5ba4868207087f08e0cb95334713ee324 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Thu, 25 Dec 2025 23:17:51 -0500 Subject: [PATCH 2/7] Update objects.cpp --- Source/objects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 4a8ba8771..ff7782746 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2314,7 +2314,7 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) for (int k = 0; k < eligibleCount; k++) { Item &it = player.InvBody[eligible[k]]; - const int delta = (eligible[k] == cursedSlot) ? -10 : +10; + const int delta = (eligible[k] == cursedSlot) ? -10 : 10; it._iMaxDur += delta; it._iDurability += delta; From a59266782df180604e67e2b3a5a8ad271a89848b Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Thu, 25 Dec 2025 23:23:53 -0500 Subject: [PATCH 3/7] Update objects.cpp --- Source/objects.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index ff7782746..5d081ed36 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2284,15 +2284,18 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) if (&player != MyPlayer) return; + constexpr int DurMin = 1; + constexpr int DurMax = 255; + auto isEligible = [](const Item &it) { return !it.isEmpty() - && it._iMaxDur != DUR_INDESTRUCTIBLE - && it._iMaxDur > 0; + && it._iMaxDur != DurMax + && it._iMaxDur >= DurMin; }; auto clampForSave = [](Item &it) { - it._iMaxDur = std::clamp(it._iMaxDur, 1, DUR_INDESTRUCTIBLE); - it._iDurability = std::clamp(it._iDurability, 1, it._iMaxDur); + it._iMaxDur = std::clamp(it._iMaxDur, DurMin, DurMax); + it._iDurability = std::clamp(it._iDurability, DurMin, it._iMaxDur); }; std::array eligible {}; From 26eb03518c7015248ed0c76fbd2594ab1b55856f Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Thu, 25 Dec 2025 23:34:44 -0500 Subject: [PATCH 4/7] Update objects.cpp --- Source/objects.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 5d081ed36..b3bbdeff3 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2287,13 +2287,13 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) constexpr int DurMin = 1; constexpr int DurMax = 255; - auto isEligible = [](const Item &it) { + auto isEligible = [DurMin, DurMax](const Item &it) { return !it.isEmpty() && it._iMaxDur != DurMax && it._iMaxDur >= DurMin; }; - auto clampForSave = [](Item &it) { + auto clampForSave = [DurMin, DurMax](Item &it) { it._iMaxDur = std::clamp(it._iMaxDur, DurMin, DurMax); it._iDurability = std::clamp(it._iDurability, DurMin, it._iMaxDur); }; From 0f71df23e2943e30d4d6028dca59a7253c3a77ac Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Fri, 26 Dec 2025 02:04:51 -0500 Subject: [PATCH 5/7] Update objects.cpp --- Source/objects.cpp | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index b3bbdeff3..1c32b9b05 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2247,6 +2247,11 @@ void OperatePedestal(Player &player, Object &pedestal, bool sendmsg) } } +int ClampU8(int v) +{ + return std::clamp(v, 0, 255); +} + void OperateShrineMysterious(DiabloGenerator &rng, Player &player) { if (&player != MyPlayer) @@ -2284,25 +2289,12 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) if (&player != MyPlayer) return; - constexpr int DurMin = 1; - constexpr int DurMax = 255; - - auto isEligible = [DurMin, DurMax](const Item &it) { - return !it.isEmpty() - && it._iMaxDur != DurMax - && it._iMaxDur >= DurMin; - }; - - auto clampForSave = [DurMin, DurMax](Item &it) { - it._iMaxDur = std::clamp(it._iMaxDur, DurMin, DurMax); - it._iDurability = std::clamp(it._iDurability, DurMin, it._iMaxDur); - }; - std::array eligible {}; int eligibleCount = 0; for (int i = 0; i < NUM_INVLOC; i++) { - if (isEligible(player.InvBody[i])) + const Item &it = player.InvBody[i]; + if (!it.isEmpty() && it._iMaxDur > 0 && it._iMaxDur < 255) eligible[eligibleCount++] = i; } @@ -2316,13 +2308,9 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) for (int k = 0; k < eligibleCount; k++) { Item &it = player.InvBody[eligible[k]]; - const int delta = (eligible[k] == cursedSlot) ? -10 : 10; - - it._iMaxDur += delta; - it._iDurability += delta; - - clampForSave(it); + it._iMaxDur = ClampU8(it._iMaxDur + delta); + it._iDurability = ClampU8(it._iDurability + delta); } InitDiabloMsg(EMSG_SHRINE_HIDDEN); From 210118e0c77ac5b081c431cdbfc19d2d38380730 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Fri, 26 Dec 2025 02:13:47 -0500 Subject: [PATCH 6/7] Update objects.cpp --- Source/objects.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 1c32b9b05..e093df0a5 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2294,7 +2294,7 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) for (int i = 0; i < NUM_INVLOC; i++) { const Item &it = player.InvBody[i]; - if (!it.isEmpty() && it._iMaxDur > 0 && it._iMaxDur < 255) + if (!it.isEmpty() && it._iMaxDur != 0) eligible[eligibleCount++] = i; } @@ -2310,7 +2310,11 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) Item &it = player.InvBody[eligible[k]]; const int delta = (eligible[k] == cursedSlot) ? -10 : 10; it._iMaxDur = ClampU8(it._iMaxDur + delta); + if (it._iMaxDur == 0) + it._iMaxDur = 1; it._iDurability = ClampU8(it._iDurability + delta); + if (it._iDurability == 0) + it._iDurability = 1; } InitDiabloMsg(EMSG_SHRINE_HIDDEN); From ae71f821243bec8c2ecd6641550d111bedcb6530 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Fri, 26 Dec 2025 02:15:49 -0500 Subject: [PATCH 7/7] Update objects.cpp --- Source/objects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index e093df0a5..c5b52b83f 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2294,7 +2294,7 @@ void OperateShrineHidden(DiabloGenerator &rng, Player &player) for (int i = 0; i < NUM_INVLOC; i++) { const Item &it = player.InvBody[i]; - if (!it.isEmpty() && it._iMaxDur != 0) + if (!it.isEmpty() && IsNoneOf(it._iMaxDur, 0, DUR_INDESTRUCTIBLE)) eligible[eligibleCount++] = i; }