From 68ef066dca17823ddf9b99f2de9c6e0902b0d6bf Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Thu, 19 Jan 2023 09:52:01 -0500 Subject: [PATCH] Some adjustments to item interesting strings For weapons, negative bonus is now shown as "- 2" instead of as "+ -2". For armour, the bonus is now accounted for and the numbers should match what is actually calculated in damage_pc(). Thanks to @fosnola for noticing the armour discrepancy. --- src/mathutil.hpp | 5 +++++ src/scenario/item.cpp | 28 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/mathutil.hpp b/src/mathutil.hpp index b35e05f14..a4a0fbba1 100644 --- a/src/mathutil.hpp +++ b/src/mathutil.hpp @@ -35,3 +35,8 @@ inline void move_to_zero(T& val){ if(val > 0) val--; } + +template +inline T sgn(T val) { + return val == 0 ? 0 : std::copysign(1, val); +} diff --git a/src/scenario/item.cpp b/src/scenario/item.cpp index d8ee8834b..3465bc043 100644 --- a/src/scenario/item.cpp +++ b/src/scenario/item.cpp @@ -19,6 +19,7 @@ #include "utility.hpp" #include "fileio/fileio.hpp" #include "fileio/tagfile.hpp" +#include "mathutil.hpp" #include "damage.hpp" #include "spell.hpp" @@ -90,6 +91,18 @@ short cItem::item_weight() const { return w; } +static short min_defense_bonus(short bonus) { + if(bonus == 0) return 0; + if(bonus < 0) return bonus; + return 1 + bonus / 2; +} + +static short max_defense_bonus(short bonus) { + if(bonus == 0) return 0; + if(bonus < 0) return bonus; + return bonus + bonus / 2; +} + std::string cItem::interesting_string() const { if(property) { return "Not yours."; @@ -109,17 +122,22 @@ std::string cItem::interesting_string() const { case eItemType::THROWN_MISSILE: case eItemType::BOLTS: case eItemType::MISSILE_NO_AMMO: - if(bonus != 0) - sout << "Damage: 1-" << item_level << " + " << bonus; - else sout << "Damage: 1-" << item_level; + sout << "Damage: 1-" << item_level; + if(bonus > 0) { + sout << " + " << bonus; + } else if(bonus < 0) { + sout << " - " << -bonus; + } break; case eItemType::SHIELD: case eItemType::ARMOR: case eItemType::HELM: case eItemType::GLOVES: case eItemType::SHIELD_2: - case eItemType::BOOTS: // TODO: Verify that this is displayed correctly - sout << "Blocks " << item_level + ((protection > 0) ? 1 : 0) << '-' << item_level + protection << " damage"; + case eItemType::BOOTS: + sout << "Blocks " << 1 + min_defense_bonus(bonus) + sgn(protection); + sout << '-' << max(1,item_level) + max_defense_bonus(bonus) + protection; + sout << " damage"; break; case eItemType::BOW: case eItemType::CROSSBOW: