From a229b1b8b19d609c5b40da747ca7fa46b92d297b Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Thu, 25 Dec 2025 23:25:50 -0500 Subject: [PATCH 1/4] Refactor OperateShrineWeird --- Source/objects.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 859c7374b..ee1924705 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2365,27 +2365,38 @@ void OperateShrineWeird(Player &player) if (&player != MyPlayer) return; - if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && player.InvBody[INVLOC_HAND_LEFT]._itype != ItemType::Shield) - player.InvBody[INVLOC_HAND_LEFT]._iMaxDam++; - if (!player.InvBody[INVLOC_HAND_RIGHT].isEmpty() && player.InvBody[INVLOC_HAND_RIGHT]._itype != ItemType::Shield) - player.InvBody[INVLOC_HAND_RIGHT]._iMaxDam++; + constexpr int MaxDamMin = 0; + constexpr int MaxDamMax = 255; - for (Item &item : InventoryPlayerItemsRange { player }) { + auto isWeaponType = [](const Item &item) { switch (item._itype) { case ItemType::Sword: case ItemType::Axe: case ItemType::Bow: case ItemType::Mace: case ItemType::Staff: - item._iMaxDam++; - break; + return true; default: - break; + return false; } + }; + + auto bumpMaxDamClamped = [](Item &item) { + item._iMaxDam = std::clamp(item._iMaxDam + 1, MaxDamMin, MaxDamMax); + }; + + if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && player.InvBody[INVLOC_HAND_LEFT]._itype != ItemType::Shield) + bumpMaxDamClamped(player.InvBody[INVLOC_HAND_LEFT]); + + if (!player.InvBody[INVLOC_HAND_RIGHT].isEmpty() && player.InvBody[INVLOC_HAND_RIGHT]._itype != ItemType::Shield) + bumpMaxDamClamped(player.InvBody[INVLOC_HAND_RIGHT]); + + for (Item &item : InventoryPlayerItemsRange { player }) { + if (isWeaponType(item)) + bumpMaxDamClamped(item); } CalcPlrInv(player, true); - InitDiabloMsg(EMSG_SHRINE_WEIRD); } From 864e193ee1e88bd273d97242516b55d15d9da78f Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Thu, 25 Dec 2025 23:32:06 -0500 Subject: [PATCH 2/4] Update objects.cpp --- Source/objects.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index ee1924705..99cad1e7b 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2365,10 +2365,10 @@ void OperateShrineWeird(Player &player) if (&player != MyPlayer) return; - constexpr int MaxDamMin = 0; - constexpr int MaxDamMax = 255; + constexpr int MinDam = 0; + constexpr int MaxDam = 255; - auto isWeaponType = [](const Item &item) { + auto isWeapon = [](const Item &item) { switch (item._itype) { case ItemType::Sword: case ItemType::Axe: @@ -2381,19 +2381,21 @@ void OperateShrineWeird(Player &player) } }; - auto bumpMaxDamClamped = [](Item &item) { - item._iMaxDam = std::clamp(item._iMaxDam + 1, MaxDamMin, MaxDamMax); + auto bumpMaxDam = [](Item &item) { + item._iMaxDam = std::clamp(item._iMaxDam + 1, MinDam, MaxDam); }; - if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && player.InvBody[INVLOC_HAND_LEFT]._itype != ItemType::Shield) - bumpMaxDamClamped(player.InvBody[INVLOC_HAND_LEFT]); + Item &left = player.InvBody[INVLOC_HAND_LEFT]; + if (!left.isEmpty() && left._itype != ItemType::Shield) + bumpMaxDam(left); - if (!player.InvBody[INVLOC_HAND_RIGHT].isEmpty() && player.InvBody[INVLOC_HAND_RIGHT]._itype != ItemType::Shield) - bumpMaxDamClamped(player.InvBody[INVLOC_HAND_RIGHT]); + Item &right = player.InvBody[INVLOC_HAND_RIGHT]; + if (!right.isEmpty() && right._itype != ItemType::Shield) + bumpMaxDam(right); for (Item &item : InventoryPlayerItemsRange { player }) { - if (isWeaponType(item)) - bumpMaxDamClamped(item); + if (isWeapon(item)) + bumpMaxDam(item); } CalcPlrInv(player, true); From 8d51475c7d93fe9e6efd70fc871e9ca48432b29d Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Thu, 25 Dec 2025 23:35:18 -0500 Subject: [PATCH 3/4] 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 99cad1e7b..0e7e4e68f 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2381,7 +2381,7 @@ void OperateShrineWeird(Player &player) } }; - auto bumpMaxDam = [](Item &item) { + auto bumpMaxDam = [MinDam, MaxDam](Item &item) { item._iMaxDam = std::clamp(item._iMaxDam + 1, MinDam, MaxDam); }; From e35b82dd4560d789f09a50d2b22b1fd943f3258a Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Fri, 26 Dec 2025 01:53:33 -0500 Subject: [PATCH 4/4] Update objects.cpp --- Source/objects.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 0e7e4e68f..650d0b296 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) @@ -2365,9 +2370,6 @@ void OperateShrineWeird(Player &player) if (&player != MyPlayer) return; - constexpr int MinDam = 0; - constexpr int MaxDam = 255; - auto isWeapon = [](const Item &item) { switch (item._itype) { case ItemType::Sword: @@ -2381,8 +2383,8 @@ void OperateShrineWeird(Player &player) } }; - auto bumpMaxDam = [MinDam, MaxDam](Item &item) { - item._iMaxDam = std::clamp(item._iMaxDam + 1, MinDam, MaxDam); + auto bumpMaxDam = [&](Item &item) { + item._iMaxDam = ClampU8(item._iMaxDam + 1); }; Item &left = player.InvBody[INVLOC_HAND_LEFT];