From dd5e4509b89d44c0fd5a5705f2a4b9e358dc878c Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 23 Sep 2024 18:37:14 +0200 Subject: [PATCH 1/6] unify printing item info --- Source/inv.cpp | 6 +---- Source/items.cpp | 58 +++++++++----------------------------------- Source/items.h | 1 - Source/qol/stash.cpp | 6 +---- 4 files changed, 14 insertions(+), 57 deletions(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index 02384c43bc4..d12dac237c4 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -1916,11 +1916,7 @@ int8_t CheckInvHLight() } else { InfoColor = pi->getTextColor(); InfoString = pi->getName(); - if (pi->_iIdentified) { - PrintItemDetails(*pi); - } else { - PrintItemDur(*pi); - } + PrintItemDetails(*pi); } return rv; diff --git a/Source/items.cpp b/Source/items.cpp index 2c7effdee29..f377f3ce5fd 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4117,56 +4117,22 @@ void PrintItemDetails(const Item &item) if (item._iMiscId == IMISC_STAFF && item._iMaxCharges != 0) { AddInfoBoxString(fmt::format(fmt::runtime(_("Charges: {:d}/{:d}")), item._iCharges, item._iMaxCharges)); } - if (item._iPrePower != -1) { - AddInfoBoxString(PrintItemPower(item._iPrePower, item)); - } - if (item._iSufPower != -1) { - AddInfoBoxString(PrintItemPower(item._iSufPower, item)); - } - if (item._iMagical == ITEM_QUALITY_UNIQUE) { - AddInfoBoxString(_("unique item")); - ShowUniqueItemInfoBox = true; - curruitem = item; - } - PrintItemInfo(item); -} - -void PrintItemDur(const Item &item) -{ - if (HeadlessMode) - return; - - if (item._iClass == ICLASS_WEAPON) { - if (item._iMinDam == item._iMaxDam) { - if (item._iMaxDur == DUR_INDESTRUCTIBLE) - AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d} Indestructible")), item._iMinDam)); - else - AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d} Dur: {:d}/{:d}")), item._iMinDam, item._iDurability, item._iMaxDur)); - } else { - if (item._iMaxDur == DUR_INDESTRUCTIBLE) - AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d}-{:d} Indestructible")), item._iMinDam, item._iMaxDam)); - else - AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d}-{:d} Dur: {:d}/{:d}")), item._iMinDam, item._iMaxDam, item._iDurability, item._iMaxDur)); + if (item._iIdentified) { + if (item._iPrePower != -1) { + AddInfoBoxString(PrintItemPower(item._iPrePower, item)); } - if (item._iMiscId == IMISC_STAFF && item._iMaxCharges > 0) { - AddInfoBoxString(fmt::format(fmt::runtime(_("Charges: {:d}/{:d}")), item._iCharges, item._iMaxCharges)); + if (item._iSufPower != -1) { + AddInfoBoxString(PrintItemPower(item._iSufPower, item)); } - if (item._iMagical != ITEM_QUALITY_NORMAL) - AddInfoBoxString(_("Not Identified")); - } - if (item._iClass == ICLASS_ARMOR) { - if (item._iMaxDur == DUR_INDESTRUCTIBLE) - AddInfoBoxString(fmt::format(fmt::runtime(_("armor: {:d} Indestructible")), item._iAC)); - else - AddInfoBoxString(fmt::format(fmt::runtime(_("armor: {:d} Dur: {:d}/{:d}")), item._iAC, item._iDurability, item._iMaxDur)); - if (item._iMagical != ITEM_QUALITY_NORMAL) - AddInfoBoxString(_("Not Identified")); - if (item._iMiscId == IMISC_STAFF && item._iMaxCharges > 0) { - AddInfoBoxString(fmt::format(fmt::runtime(_("Charges: {:d}/{:d}")), item._iCharges, item._iMaxCharges)); + if (item._iMagical == ITEM_QUALITY_UNIQUE) { + AddInfoBoxString(_("unique item")); + ShowUniqueItemInfoBox = true; + curruitem = item; } - } - if (IsAnyOf(item._itype, ItemType::Ring, ItemType::Amulet)) + } else { AddInfoBoxString(_("Not Identified")); + } + PrintItemInfo(item); } diff --git a/Source/items.h b/Source/items.h index 014f90e415f..a7c081c3fa6 100644 --- a/Source/items.h +++ b/Source/items.h @@ -544,7 +544,6 @@ bool DoOil(Player &player, int cii); [[nodiscard]] StringOrView PrintItemPower(char plidx, const Item &item); void DrawUniqueInfo(const Surface &out); void PrintItemDetails(const Item &item); -void PrintItemDur(const Item &item); void UseItem(Player &player, item_misc_id Mid, SpellID spellID, int spellFrom); bool UseItemOpensHive(const Item &item, Point position); bool UseItemOpensGrave(const Item &item, Point position); diff --git a/Source/qol/stash.cpp b/Source/qol/stash.cpp index c4a5320871f..2de0885ec1a 100644 --- a/Source/qol/stash.cpp +++ b/Source/qol/stash.cpp @@ -447,11 +447,7 @@ uint16_t CheckStashHLight(Point mousePosition) InfoColor = item.getTextColor(); InfoString = item.getName(); - if (item._iIdentified) { - PrintItemDetails(item); - } else { - PrintItemDur(item); - } + PrintItemDetails(item); return itemId; } From 49d6246d0800f39984deb7a2af32ce377991e9fd Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 23 Sep 2024 18:42:25 +0200 Subject: [PATCH 2/6] show real AC --- Source/items.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index f377f3ce5fd..8bf8f89c836 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4109,10 +4109,14 @@ void PrintItemDetails(const Item &item) } } if (item._iClass == ICLASS_ARMOR) { + int realAC = item._iAC; + if (item._iIdentified) { + realAC += GetBonusAC(item); + } if (item._iMaxDur == DUR_INDESTRUCTIBLE) - AddInfoBoxString(fmt::format(fmt::runtime(_("armor: {:d} Indestructible")), item._iAC)); + AddInfoBoxString(fmt::format(fmt::runtime(_("armor: {:d} Indestructible")), realAC)); else - AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "armor: {:d} Dur: {:d}/{:d}")), item._iAC, item._iDurability, item._iMaxDur)); + AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "armor: {:d} Dur: {:d}/{:d}")), realAC, item._iDurability, item._iMaxDur)); } if (item._iMiscId == IMISC_STAFF && item._iMaxCharges != 0) { AddInfoBoxString(fmt::format(fmt::runtime(_("Charges: {:d}/{:d}")), item._iCharges, item._iMaxCharges)); From d1e8442eab9894e210213ab8831840f2f575ed1f Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 23 Sep 2024 19:49:22 +0200 Subject: [PATCH 3/6] add hotkey for showing base stat --- Source/diablo.cpp | 7 +++++++ Source/items.cpp | 3 ++- Source/items.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index e50b62433bd..c84b70dbb12 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1792,6 +1792,13 @@ void InitKeymapActions() SDLK_RCTRL, nullptr, [] { ToggleItemLabelHighlight(); }); + sgOptions.Keymapper.AddAction( + "Show Base Stats", + N_("Show item base stats"), + N_("Shows item base armor/damage without including bonuses"), + SDLK_LCTRL, + [] { showItemBaseStats = true; }, + [] { showItemBaseStats = false; }); sgOptions.Keymapper.AddAction( "Toggle Automap", N_("Toggle automap"), diff --git a/Source/items.cpp b/Source/items.cpp index 8bf8f89c836..3b5a055e554 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -58,6 +58,7 @@ bool ShowUniqueItemInfoBox; CornerStoneStruct CornerStone; bool UniqueItemFlags[128]; int MaxGold = GOLD_MAX_LIMIT; +bool showItemBaseStats = false; /** Maps from item_cursor_graphic to in-memory item type. */ int8_t ItemCAnimTbl[] = { @@ -4110,7 +4111,7 @@ void PrintItemDetails(const Item &item) } if (item._iClass == ICLASS_ARMOR) { int realAC = item._iAC; - if (item._iIdentified) { + if (!showItemBaseStats && item._iIdentified) { realAC += GetBonusAC(item); } if (item._iMaxDur == DUR_INDESTRUCTIBLE) diff --git a/Source/items.h b/Source/items.h index a7c081c3fa6..04f7361b680 100644 --- a/Source/items.h +++ b/Source/items.h @@ -483,6 +483,7 @@ extern int8_t dItem[MAXDUNX][MAXDUNY]; extern bool ShowUniqueItemInfoBox; extern CornerStoneStruct CornerStone; extern DVL_API_FOR_TEST bool UniqueItemFlags[128]; +extern bool showItemBaseStats; uint8_t GetOutlineColor(const Item &item, bool checkReq); bool IsItemAvailable(int i); From ba9ebb215fc64e35236af438b87f99714c03e152 Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 23 Sep 2024 20:26:40 +0200 Subject: [PATCH 4/6] display true dmg --- Source/items.cpp | 28 +++++++--------------------- Source/items.h | 28 ++++++++++++++++++++++++++++ Source/stores.cpp | 15 +++++++++++---- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 3b5a055e554..027c41805e8 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -43,7 +43,6 @@ #include "utils/format_int.hpp" #include "utils/language.h" #include "utils/log.hpp" -#include "utils/math.h" #include "utils/str_case.hpp" #include "utils/str_cat.hpp" #include "utils/utf8.hpp" @@ -2472,20 +2471,6 @@ void InitItems() initItemGetRecords(); } -int GetBonusAC(const Item &item) -{ - if (item._iPLAC != 0) { - int tempAc = item._iAC; - tempAc *= item._iPLAC; - tempAc /= 100; - if (tempAc == 0) - tempAc = math::Sign(item._iPLAC); - return tempAc; - } - - return 0; -} - void CalcPlrDamage(Player &player, int minDamage, int maxDamage) { const uint8_t playerLevel = player.getCharacterLevel(); @@ -2817,7 +2802,7 @@ void CalcPlrItemVals(Player &player, bool loadgfx) if (item._iMagical == ITEM_QUALITY_NORMAL || item._iIdentified) { dam += item._iPLDam; toHit += item._iPLToHit; - bonusAc += GetBonusAC(item); + bonusAc += item.getBonusAC(); flags |= item._iFlags; damAcFlags |= item._iDamAcFlags; strength += item._iPLStr; @@ -4097,22 +4082,23 @@ void PrintItemDetails(const Item &item) return; if (item._iClass == ICLASS_WEAPON) { + std::pair realDamage = item.getFinalDamage(showItemBaseStats || !item._iIdentified); if (item._iMinDam == item._iMaxDam) { if (item._iMaxDur == DUR_INDESTRUCTIBLE) - AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d} Indestructible")), item._iMinDam)); + AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d} Indestructible")), realDamage.first)); else - AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "damage: {:d} Dur: {:d}/{:d}")), item._iMinDam, item._iDurability, item._iMaxDur)); + AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "damage: {:d} Dur: {:d}/{:d}")), realDamage.first, item._iDurability, item._iMaxDur)); } else { if (item._iMaxDur == DUR_INDESTRUCTIBLE) - AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d}-{:d} Indestructible")), item._iMinDam, item._iMaxDam)); + AddInfoBoxString(fmt::format(fmt::runtime(_("damage: {:d}-{:d} Indestructible")), realDamage.first, realDamage.second)); else - AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "damage: {:d}-{:d} Dur: {:d}/{:d}")), item._iMinDam, item._iMaxDam, item._iDurability, item._iMaxDur)); + AddInfoBoxString(fmt::format(fmt::runtime(_(/* TRANSLATORS: Dur: is durability */ "damage: {:d}-{:d} Dur: {:d}/{:d}")), realDamage.first, realDamage.second, item._iDurability, item._iMaxDur)); } } if (item._iClass == ICLASS_ARMOR) { int realAC = item._iAC; if (!showItemBaseStats && item._iIdentified) { - realAC += GetBonusAC(item); + realAC += item.getBonusAC(); } if (item._iMaxDur == DUR_INDESTRUCTIBLE) AddInfoBoxString(fmt::format(fmt::runtime(_("armor: {:d} Indestructible")), realAC)); diff --git a/Source/items.h b/Source/items.h index 04f7361b680..76933ed8743 100644 --- a/Source/items.h +++ b/Source/items.h @@ -15,6 +15,7 @@ #include "engine/point.hpp" #include "itemdat.h" #include "monster.h" +#include "utils/math.h" #include "utils/string_or_view.hpp" namespace devilution { @@ -420,6 +421,33 @@ struct Item { return _iSeed == seed && IDidx == itemIndex && _iCreateInfo == createInfo; } + int getBonusAC() const + { + if (_iPLAC != 0) { + int tempAc = _iAC; + tempAc *= _iPLAC; + tempAc /= 100; + if (tempAc == 0) + tempAc = math::Sign(_iPLAC); + return tempAc; + } + + return 0; + } + + std::pair getFinalDamage(bool baseDamage) const + { + int minDmg = _iMinDam; + int maxDmg = _iMaxDam; + if (!baseDamage) { + minDmg += minDmg * _iPLDam / 100; + maxDmg += maxDmg * _iPLDam / 100; + minDmg += _iPLDamMod; + maxDmg += _iPLDamMod; + } + return { minDmg, maxDmg }; + } + UiFlags getTextColor() const { switch (_iMagical) { diff --git a/Source/stores.cpp b/Source/stores.cpp index 588eec54595..07cb5798233 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -305,10 +305,17 @@ void PrintStoreItem(const Item &item, int l, UiFlags flags, bool cursIndent = fa } if (item._itype != ItemType::Misc) { - if (item._iClass == ICLASS_WEAPON) - productLine = fmt::format(fmt::runtime(_("Damage: {:d}-{:d} ")), item._iMinDam, item._iMaxDam); - else if (item._iClass == ICLASS_ARMOR) - productLine = fmt::format(fmt::runtime(_("Armor: {:d} ")), item._iAC); + if (item._iClass == ICLASS_WEAPON) { + std::pair realDamage = item.getFinalDamage(showItemBaseStats || !item._iIdentified); + productLine = fmt::format(fmt::runtime(_("Damage: {:d}-{:d} ")), realDamage.first, realDamage.second); + } + else if (item._iClass == ICLASS_ARMOR) { + int realAC = item._iAC; + if (!showItemBaseStats && item._iIdentified) { + realAC += item.getBonusAC(); + } + productLine = fmt::format(fmt::runtime(_("Armor: {:d} ")), realAC); + } if (item._iMaxDur != DUR_INDESTRUCTIBLE && item._iMaxDur != 0) productLine += fmt::format(fmt::runtime(_("Dur: {:d}/{:d}")), item._iDurability, item._iMaxDur); else From dc9f94dee908c30235b665daf4afe53ab38a6f26 Mon Sep 17 00:00:00 2001 From: qndel Date: Mon, 23 Sep 2024 20:38:02 +0200 Subject: [PATCH 5/6] clang pls --- Source/stores.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/stores.cpp b/Source/stores.cpp index 07cb5798233..8ac8540cc57 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -308,8 +308,7 @@ void PrintStoreItem(const Item &item, int l, UiFlags flags, bool cursIndent = fa if (item._iClass == ICLASS_WEAPON) { std::pair realDamage = item.getFinalDamage(showItemBaseStats || !item._iIdentified); productLine = fmt::format(fmt::runtime(_("Damage: {:d}-{:d} ")), realDamage.first, realDamage.second); - } - else if (item._iClass == ICLASS_ARMOR) { + } else if (item._iClass == ICLASS_ARMOR) { int realAC = item._iAC; if (!showItemBaseStats && item._iIdentified) { realAC += item.getBonusAC(); From dedf3b35cf3c18def189ad44b27d8ff8f62a175d Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 24 Sep 2024 01:18:19 +0200 Subject: [PATCH 6/6] stop displaying not identified on white items --- Source/items.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 027c41805e8..1d47f655aaf 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -4108,20 +4108,22 @@ void PrintItemDetails(const Item &item) if (item._iMiscId == IMISC_STAFF && item._iMaxCharges != 0) { AddInfoBoxString(fmt::format(fmt::runtime(_("Charges: {:d}/{:d}")), item._iCharges, item._iMaxCharges)); } - if (item._iIdentified) { - if (item._iPrePower != -1) { - AddInfoBoxString(PrintItemPower(item._iPrePower, item)); - } - if (item._iSufPower != -1) { - AddInfoBoxString(PrintItemPower(item._iSufPower, item)); - } - if (item._iMagical == ITEM_QUALITY_UNIQUE) { - AddInfoBoxString(_("unique item")); - ShowUniqueItemInfoBox = true; - curruitem = item; + if (item._iMagical != ITEM_QUALITY_NORMAL) { + if (item._iIdentified) { + if (item._iPrePower != -1) { + AddInfoBoxString(PrintItemPower(item._iPrePower, item)); + } + if (item._iSufPower != -1) { + AddInfoBoxString(PrintItemPower(item._iSufPower, item)); + } + if (item._iMagical == ITEM_QUALITY_UNIQUE) { + AddInfoBoxString(_("unique item")); + ShowUniqueItemInfoBox = true; + curruitem = item; + } + } else { + AddInfoBoxString(_("Not Identified")); } - } else { - AddInfoBoxString(_("Not Identified")); } PrintItemInfo(item);