From f3eef3fe6c0ef9252e3c0459fc0662fe5cc7e29a Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sat, 6 Aug 2022 18:21:47 +0300 Subject: [PATCH] Fix negative Skilldex values --- src/skilldex.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/skilldex.cc b/src/skilldex.cc index ae0a38f..10fc3ad 100644 --- a/src/skilldex.cc +++ b/src/skilldex.cc @@ -264,12 +264,25 @@ static int skilldexWindowInit() int valueY = 48; for (int index = 0; index < SKILLDEX_SKILL_COUNT; index++) { int value = skillGetValue(gDude, gSkilldexSkills[index]); - if (value == -1) { - value = 0; + + // SFALL: Fix for negative values. + // + // NOTE: Sfall's fix is different. It simply renders 0 even if + // calculated skill level is negative (which can be the case when + // playing on Hard difficulty + low Agility). For unknown reason -5 is + // the error code from `skillGetValue`, which is not handled here + // because -5 is also a legitimate skill value. + // + // TODO: Provide other error code in `skillGetValue`. + unsigned char* numbersFrmData = gSkilldexFrmData[SKILLDEX_FRM_BIG_NUMBERS]; + if (value < 0) { + // First half of the bignum.frm is white, second half is red. + numbersFrmData += gSkilldexFrmSizes[SKILLDEX_FRM_BIG_NUMBERS].width / 2; + value = -value; } int hundreds = value / 100; - blitBufferToBuffer(gSkilldexFrmData[SKILLDEX_FRM_BIG_NUMBERS] + 14 * hundreds, + blitBufferToBuffer(numbersFrmData + 14 * hundreds, 14, 24, 336, @@ -277,7 +290,7 @@ static int skilldexWindowInit() gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width); int tens = (value % 100) / 10; - blitBufferToBuffer(gSkilldexFrmData[SKILLDEX_FRM_BIG_NUMBERS] + 14 * tens, + blitBufferToBuffer(numbersFrmData + 14 * tens, 14, 24, 336, @@ -285,7 +298,7 @@ static int skilldexWindowInit() gSkilldexFrmSizes[SKILLDEX_FRM_BACKGROUND].width); int ones = (value % 100) % 10; - blitBufferToBuffer(gSkilldexFrmData[SKILLDEX_FRM_BIG_NUMBERS] + 14 * ones, + blitBufferToBuffer(numbersFrmData + 14 * ones, 14, 24, 336,