From 5f288cbd43baf6e236f131a5619b8df193d5af5c Mon Sep 17 00:00:00 2001 From: thebigMuh Date: Sun, 18 Apr 2021 22:22:03 +0200 Subject: [PATCH] Fixes small AC malus of less than 1 resulting in a bonus of 1 AC --- Source/items.cpp | 3 ++- Source/utils/math.h | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Source/utils/math.h diff --git a/Source/items.cpp b/Source/items.cpp index d4b4b1bd3..e62a2cf26 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -16,6 +16,7 @@ #include "options.h" #include "stores.h" #include "utils/language.h" +#include "utils/math.h" namespace devilution { @@ -600,7 +601,7 @@ void CalcPlrItemVals(int p, bool Loadgfx) tmpac *= itm->_iPLAC; tmpac /= 100; if (tmpac == 0) - tmpac = 1; + tmpac = math::Sign(itm->_iPLAC); bac += tmpac; } iflgs |= itm->_iFlags; diff --git a/Source/utils/math.h b/Source/utils/math.h new file mode 100644 index 000000000..6cb2b97f3 --- /dev/null +++ b/Source/utils/math.h @@ -0,0 +1,24 @@ +/** +* @file math.h +* +* Math utility functions +*/ +#pragma once + +namespace devilution { +namespace math { + +/** + * @brief Compute sign of t + * @tparam T Any arithmetic type + * @param t Value to compute sign of + * @return -1 if t < 0, 1 if t > 0, 0 if t == 0 +*/ +template +int Sign(T t) +{ + return (t > T(0)) - (t < T(0)); +} + +} // namespace math +} // namespace devilution