From 1eddd7fed036ecc73aa87e2deea71c3614c5db79 Mon Sep 17 00:00:00 2001 From: Richard Wheeler <2762690+zephyris@users.noreply.github.com> Date: Sat, 8 Mar 2025 22:47:27 +0000 Subject: [PATCH] Fix: Improve manager face randomisation --- src/company_manager_face.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/company_manager_face.h b/src/company_manager_face.h index c36a629c4e..02544cf4a2 100644 --- a/src/company_manager_face.h +++ b/src/company_manager_face.h @@ -117,8 +117,7 @@ inline void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFac /** * Increase/Decrease the company manager's face variable by the given amount. - * If the new value greater than the max value for this variable it will be set to 0. - * Or is it negative (< 0) it will be set to max value. + * The value wraps around to stay in the valid range. * * @param cmf the company manager face to write the bits to * @param cmfv the company manager face variable to write the data of @@ -132,11 +131,10 @@ inline void IncreaseCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManag int8_t val = GetCompanyManagerFaceBits(cmf, cmfv, ge) + amount; // the new value for the cmfv /* scales the new value to the correct scope */ - if (val >= _cmf_info[cmfv].valid_values[ge]) { - val = 0; - } else if (val < 0) { - val = _cmf_info[cmfv].valid_values[ge] - 1; + while (val < 0) { + val += _cmf_info[cmfv].valid_values[ge]; } + val %= _cmf_info[cmfv].valid_values[ge]; SetCompanyManagerFaceBits(cmf, cmfv, ge, val); // save the new value }