From ea8eeefc579c7197514f07401cd59a7e1b2fce09 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 27 Apr 2019 05:23:15 +0200 Subject: [PATCH] Clean up control_WriteStringToBuffer --- Source/control.cpp | 25 +++++++++++++------------ Source/control.h | 2 +- Source/items.cpp | 6 +++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 1016b9c86..3ea6d7c95 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1617,20 +1617,21 @@ void FreeControlPan() MemFreeDbg(pGBoxBuff); } -int control_WriteStringToBuffer(char *str) +BOOL control_WriteStringToBuffer(BYTE *str) { - signed int v1; // edx - unsigned char v2; // al + int k; + BYTE ichar; - v1 = 0; - do { - v2 = *str; - if (!*str) - return 1; - ++str; - v1 += fontkern[fontframe[gbFontTransTbl[v2]]]; - } while (v1 < 125); - return 0; + k = 0; + while (*str) { + ichar = gbFontTransTbl[*str]; + str++; + k += fontkern[fontframe[ichar]]; + if (k >= 125) + return FALSE; + } + + return TRUE; } void DrawInfoBox() diff --git a/Source/control.h b/Source/control.h index c760c53ce..811c6574e 100644 --- a/Source/control.h +++ b/Source/control.h @@ -83,7 +83,7 @@ void DoAutoMap(); void CheckPanelInfo(); void CheckBtnUp(); void FreeControlPan(); -int control_WriteStringToBuffer(char *str); +BOOL control_WriteStringToBuffer(BYTE *str); void DrawInfoBox(); void control_print_info_str(int y, char *str, BOOLEAN center, int lines); void PrintGameStr(int x, int y, char *str, int color); diff --git a/Source/items.cpp b/Source/items.cpp index 67151a984..b7f88c8c1 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1192,7 +1192,7 @@ void GetStaffPower(int i, int lvl, int bs, unsigned char onlygood) } v12 = ia; v13 = item[ia]._iIName; - if (!control_WriteStringToBuffer(item[ia]._iIName)) { + if (!control_WriteStringToBuffer((BYTE *)item[ia]._iIName)) { strcpy(v13, AllItemsList[item[v12].IDidx].iSName); if (v5 != -1) { sprintf(istr, "%s %s", PL_Prefix[v5].PLName, v13); @@ -1241,7 +1241,7 @@ void GetStaffSpell(int i, int lvl, unsigned char onlygood) goto LABEL_15; } sprintf(istr, "%s of %s", item[i]._iName, spelldata[bs].sNameText); - if (!control_WriteStringToBuffer(istr)) + if (!control_WriteStringToBuffer((BYTE *)istr)) sprintf(istr, "Staff of %s", spelldata[bs].sNameText); strcpy(item[i]._iName, istr); strcpy(item[i]._iIName, istr); @@ -1835,7 +1835,7 @@ void GetItemPower(int i, int minlvl, int maxlvl, int flgs, int onlygood) } } } - if (!control_WriteStringToBuffer(item[i]._iIName)) { + if (!control_WriteStringToBuffer((BYTE *)item[i]._iIName)) { strcpy(item[i]._iIName, AllItemsList[item[i].IDidx].iSName); if (preidx != -1) { sprintf(istr, "%s %s", PL_Prefix[preidx].PLName, item[i]._iIName);