Skip to content

Commit

Permalink
Decompose more magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
AJenbo committed Oct 25, 2019
1 parent 8570d3b commit 92ab05e
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 226 deletions.
124 changes: 62 additions & 62 deletions Source/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ char SpellITbl[MAX_SPELLS] = {
39, 42, 41, 40, 10, 36, 30
};
int PanBtnPos[8][5] = {
{ 9, 361, 71, 19, 1 },
{ 9, 387, 71, 19, 0 },
{ 9, 427, 71, 19, 1 },
{ 9, 453, 71, 19, 0 },
{ 560, 361, 71, 19, 1 },
{ 560, 387, 71, 19, 0 },
{ 87, 443, 33, 32, 1 },
{ 527, 443, 33, 32, 1 }
{ PANEL_LEFT + 9, PANEL_TOP + 9, 71, 19, 1 }, // char button
{ PANEL_LEFT + 9, PANEL_TOP + 35, 71, 19, 0 }, // quests button
{ PANEL_LEFT + 9, PANEL_TOP + 75, 71, 19, 1 }, // map button
{ PANEL_LEFT + 9, PANEL_TOP + 101, 71, 19, 0 }, // menu button
{ PANEL_LEFT + 560, PANEL_TOP + 9, 71, 19, 1 }, // inv button
{ PANEL_LEFT + 560, PANEL_TOP + 35, 71, 19, 0 }, // spells button
{ PANEL_LEFT + 87, PANEL_TOP + 91, 33, 32, 1 }, // chat button
{ PANEL_LEFT + 527, PANEL_TOP + 91, 33, 32, 1 }, // friendly fire button
};
char *PanBtnHotKey[8] = { "'c'", "'q'", "Tab", "Esc", "'i'", "'b'", "Enter", NULL };
char *PanBtnStr[8] = {
Expand Down Expand Up @@ -382,9 +382,9 @@ void DrawSpell()
st = RSPLTYPE_INVALID;
SetSpellTrans(st);
if (spl != SPL_INVALID)
DrawSpellCel(629, 631, pSpellCels, SpellITbl[spl], 56);
DrawSpellCel(PANEL_X + 565, PANEL_Y + 119, pSpellCels, SpellITbl[spl], 56);
else
DrawSpellCel(629, 631, pSpellCels, 27, 56);
DrawSpellCel(PANEL_X + 565, PANEL_Y + 119, pSpellCels, 27, 56);
}

void DrawSpellList()
Expand Down Expand Up @@ -879,7 +879,7 @@ void DrawPanelBox(int x, int y, int w, int h, int sx, int sy)
/// ASSERT: assert(gpBuffer);

nSrcOff = x + PANEL_WIDTH * y;
nDstOff = sx + BUFFER_WIDTH * sy + (SCREEN_WIDTH - PANEL_WIDTH) / 2;
nDstOff = sx + BUFFER_WIDTH * sy + PANEL_LEFT;

#ifdef USE_ASM
__asm {
Expand Down Expand Up @@ -950,14 +950,14 @@ void DrawPanelBox(int x, int y, int w, int h, int sx, int sy)
/**
* Draws parts of the flasks that are on the panel
*/
void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int c, int r)
void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy)
{
int nSrcOff, nDstOff, w;

/// ASSERT: assert(gpBuffer);

nSrcOff = 88 * min;
nDstOff = c + BUFFER_WIDTH * r;
nDstOff = sx + BUFFER_WIDTH * sy;
w = max - min;

#ifdef USE_ASM
Expand Down Expand Up @@ -1058,9 +1058,9 @@ void UpdateLifeFlask()
else if (filled < 0)
filled = 0;
if (filled != 69)
SetFlaskHeight(pLifeBuff, 16, 85 - filled, 96 + SCREEN_X, 352 + SCREEN_Y);
SetFlaskHeight(pLifeBuff, 16, 85 - filled, 96 + PANEL_X, PANEL_Y);
if (filled)
DrawPanelBox(96, 85 - filled, 88, filled, 96 + SCREEN_X, 421 + SCREEN_Y - filled);
DrawPanelBox(96, 85 - filled, 88, filled, 96 + PANEL_X, PANEL_Y + 69 - filled);
}

void DrawManaFlask()
Expand Down Expand Up @@ -1115,9 +1115,9 @@ void UpdateManaFlask()
if (filled > 69)
filled = 69;
if (filled != 69)
SetFlaskHeight(pManaBuff, 16, 85 - filled, 96 + SCREEN_X + 368, 352 + SCREEN_Y);
SetFlaskHeight(pManaBuff, 16, 85 - filled, 96 + PANEL_X + 368, PANEL_Y);
if (filled)
DrawPanelBox(96 + 368, 85 - filled, 88, filled, 96 + SCREEN_X + 368, 421 + SCREEN_Y - filled);
DrawPanelBox(96 + 368, 85 - filled, 88, filled, 96 + PANEL_X + 368, PANEL_Y + 69 - filled);

DrawSpell();
}
Expand Down Expand Up @@ -1208,7 +1208,7 @@ void InitControlPan()

void ClearCtrlPan()
{
DrawPanelBox(0, sgbPlrTalkTbl + 16, PANEL_WIDTH, PANEL_HEIGHT, 64, 512);
DrawPanelBox(0, sgbPlrTalkTbl + 16, PANEL_WIDTH, PANEL_HEIGHT, PANEL_X, PANEL_Y);
DrawInfoBox();
}

Expand All @@ -1218,16 +1218,16 @@ void DrawCtrlPan()

for (i = 0; i < 6; i++) {
if (!panbtn[i])
DrawPanelBox(PanBtnPos[i][0], PanBtnPos[i][1] - 336, 71, 20, PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y);
DrawPanelBox(PanBtnPos[i][0] - PANEL_LEFT, PanBtnPos[i][1] - (PANEL_TOP - 16), 71, 20, PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + SCREEN_Y);
else
CelDraw(PanBtnPos[i][0] + SCREEN_X, PanBtnPos[i][1] + SCREEN_Y + 18, pPanelButtons, i + 1, 71);
CelDraw(PanBtnPos[i][0] + PANEL_X, PanBtnPos[i][1] + (PANEL_Y - 334), pPanelButtons, i + 1, 71);
}
if (numpanbtns == 8) {
CelDraw(87 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[6] + 1, 33);
CelDraw(87 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[6] + 1, 33);
if (FriendlyMode)
CelDraw(527 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[7] + 3, 33);
CelDraw(527 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[7] + 3, 33);
else
CelDraw(527 + SCREEN_X, 474 + SCREEN_Y, pMultiBtns, panbtn[7] + 5, 33);
CelDraw(527 + PANEL_X, 122 + PANEL_Y, pMultiBtns, panbtn[7] + 5, 33);
}
}

Expand Down Expand Up @@ -1297,7 +1297,7 @@ void DoPanBtn()
}
}
}
if (!spselflag && MouseX >= 565 && MouseX < 621 && MouseY >= 416 && MouseY < 472) {
if (!spselflag && MouseX >= 565 + PANEL_LEFT && MouseX < 621 + PANEL_LEFT && MouseY >= 64 + PANEL_TOP && MouseY < 120 + PANEL_TOP) {
DoSpeedBook();
gamemenu_off();
}
Expand Down Expand Up @@ -1366,7 +1366,7 @@ void CheckPanelInfo()
pinfoflag = TRUE;
}
}
if (!spselflag && MouseX >= 565 && MouseX < 621 && MouseY >= 416 && MouseY < 472) {
if (!spselflag && MouseX >= 565 + PANEL_LEFT && MouseX < 621 + PANEL_LEFT && MouseY >= 64 + PANEL_TOP && MouseY < 120 + PANEL_TOP) {
strcpy(infostr, "Select current spell button");
infoclr = COL_WHITE;
panelflag = TRUE;
Expand Down Expand Up @@ -1428,7 +1428,7 @@ void CheckPanelInfo()
}
}
}
if (MouseX > 190 && MouseX < 437 && MouseY > 356 && MouseY < 385)
if (MouseX > 190 + PANEL_LEFT && MouseX < 437 + PANEL_LEFT && MouseY > 4 + PANEL_TOP && MouseY < 33 + PANEL_TOP)
pcursinvitem = CheckInvHLight();
}

Expand Down Expand Up @@ -1548,7 +1548,7 @@ void DrawInfoBox()
{
int nGold;

DrawPanelBox(177, 62, 288, 60, 241, 558);
DrawPanelBox(177, 62, 288, 60, PANEL_X + 177, PANEL_Y + 46);
if (!panelflag && !trigflag && pcursinvitem == -1 && !spselflag) {
infostr[0] = '\0';
infoclr = COL_WHITE;
Expand Down Expand Up @@ -1634,13 +1634,13 @@ void control_print_info_str(int y, char *str, BOOL center, int lines)
int strWidth, lineOffset, lineStart;

lineOffset = 0;
lineStart = lineOffsets[lines][y] + (SCREEN_WIDTH - PANEL_WIDTH) / 2;
lineStart = lineOffsets[lines][y] + PANEL_LEFT;
if (center == 1) {
strWidth = 0;
tmp = str;
while (*tmp) {
c = gbFontTransTbl[(BYTE)*tmp++];
strWidth += fontkern[fontframe[c]] + 1;
strWidth += fontkern[fontframe[c]] + 2;
}
if (strWidth < 288)
lineOffset = (288 - strWidth) >> 1;
Expand Down Expand Up @@ -1943,13 +1943,13 @@ void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base)

void CheckLvlBtn()
{
if (!lvlbtndown && MouseX >= 40 && MouseX <= 81 && MouseY >= 313 && MouseY <= 335)
if (!lvlbtndown && MouseX >= 40 + PANEL_LEFT && MouseX <= 81 + PANEL_LEFT && MouseY >= -39 + PANEL_TOP && MouseY <= -17 + PANEL_TOP)
lvlbtndown = TRUE;
}

void ReleaseLvlBtn()
{
if (MouseX >= 40 && MouseX <= 81 && MouseY >= 313 && MouseY <= 335)
if (MouseX >= 40 + PANEL_LEFT && MouseX <= 81 + PANEL_LEFT && MouseY >= -39 + PANEL_TOP && MouseY <= -17 + PANEL_TOP)
chrflag = TRUE;
lvlbtndown = FALSE;
}
Expand All @@ -1961,7 +1961,7 @@ void DrawLevelUpIcon()
if (!stextflag) {
nCel = lvlbtndown ? 3 : 2;
ADD_PlrStringXY(0, 303, 120, "Level Up", COL_WHITE);
CelDraw(40 + SCREEN_X, 335 + SCREEN_Y, pChrButtons, nCel, 41);
CelDraw(40 + PANEL_X, -17 + PANEL_Y, pChrButtons, nCel, 41);
}
}

Expand Down Expand Up @@ -2044,9 +2044,9 @@ void DrawDurIcon()
int x1, x2, x3, x4;

if (!chrflag && !questlog || !invflag && !sbookflag) {
x1 = 656;
x1 = 592 + PANEL_X;
if (invflag || sbookflag)
x1 = 336;
x1 = 272 + PANEL_X;
p = &plr[myplr];
x2 = DrawDurIcon4Item(&p->InvBody[INVLOC_HEAD], x1, 4);
x3 = DrawDurIcon4Item(&p->InvBody[INVLOC_CHEST], x2, 3);
Expand Down Expand Up @@ -2086,7 +2086,7 @@ int DrawDurIcon4Item(ItemStruct *pItem, int x, int c)
}
if (pItem->_iDurability > 2)
c += 8;
CelDraw(x, 335 + SCREEN_Y, pDurIcons, c, 32);
CelDraw(x, -17 + PANEL_Y, pDurIcons, c, 32);
return x - 40;
}

Expand Down Expand Up @@ -2198,8 +2198,8 @@ void DrawSpellBook()
char st;
unsigned __int64 spl;

CelDraw(PANEL_RIGHT, 351 + SCREEN_Y, pSpellBkCel, 1, 320);
CelDraw(PANEL_RIGHT + 76 * sbooktab + 7, 348 + SCREEN_Y, pSBkBtnCel, sbooktab + 1, 76);
CelDraw(RIGHT_PANEL_X, 351 + SCREEN_Y, pSpellBkCel, 1, 320);
CelDraw(RIGHT_PANEL_X + 76 * sbooktab + 7, 348 + SCREEN_Y, pSBkBtnCel, sbooktab + 1, 76);

spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells;

Expand All @@ -2209,10 +2209,10 @@ void DrawSpellBook()
if (sn != -1 && spl & (__int64)1 << (sn - 1)) {
st = GetSBookTrans(sn, TRUE);
SetSpellTrans(st);
DrawSpellCel(SCREEN_WIDTH - 320 + 75, yp, pSBkIconCels, SpellITbl[sn], 37);
DrawSpellCel(RIGHT_PANEL + 75, yp, pSBkIconCels, SpellITbl[sn], 37);
if (sn == plr[myplr]._pRSpell && st == plr[myplr]._pRSplType) {
SetSpellTrans(RSPLTYPE_SKILL);
DrawSpellCel(SCREEN_WIDTH - 320 + 75, yp, pSBkIconCels, 43, 37);
DrawSpellCel(RIGHT_PANEL + 75, yp, pSBkIconCels, 43, 37);
}
PrintSBookStr(10, yp - 23, FALSE, spelldata[sn].sNameText, COL_WHITE);
switch (GetSBookTrans(sn, FALSE)) {
Expand Down Expand Up @@ -2257,7 +2257,7 @@ void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col)
char *tmp;
int screen_x, line, width;

width = PitchTbl[y] + x + SCREEN_WIDTH - 320 + 120;
width = PitchTbl[y] + x + RIGHT_PANEL + 120;
line = 0;
if (cjustflag) {
screen_x = 0;
Expand Down Expand Up @@ -2288,7 +2288,7 @@ void CheckSBook()
char st;
unsigned __int64 spl;

if (MouseX >= 331 && MouseX < 368 && MouseY >= 18 && MouseY < 314) {
if (MouseX >= RIGHT_PANEL + 11 && MouseX < RIGHT_PANEL + 48 && MouseY >= 18 && MouseY < 314) {
spl = plr[myplr]._pMemSpells | plr[myplr]._pISpells | plr[myplr]._pAblSpells;
sn = SpellPages[sbooktab][(MouseY - 18) / 43];
if (sn != -1 && spl & (__int64)1 << (sn - 1)) {
Expand All @@ -2304,8 +2304,8 @@ void CheckSBook()
drawpanflag = 255;
}
}
if (MouseX >= 327 && MouseX < 633 && MouseY >= 320 && MouseY < 349) { /// BUGFIX: change `< 633` to `< 631`
sbooktab = (MouseX - 327) / 76;
if (MouseX >= RIGHT_PANEL + 7 && MouseX < RIGHT_PANEL + 313 && MouseY >= 320 && MouseY < 349) { /// BUGFIX: change `< 313` to `< 311`
sbooktab = (MouseX - (RIGHT_PANEL + 7)) / 76;
}
}

Expand Down Expand Up @@ -2428,20 +2428,20 @@ void DrawTalkPan()
if (!talkflag)
return;

DrawPanelBox(175, sgbPlrTalkTbl + 20, 294, 5, 239, 516);
DrawPanelBox(175, sgbPlrTalkTbl + 20, 294, 5, PANEL_X + 175, PANEL_Y + 4);
off = 0;
for (i = 293; i > 283; off++, i--) {
DrawPanelBox((off >> 1) + 175, sgbPlrTalkTbl + off + 25, i, 1, (off >> 1) + 239, off + 521);
DrawPanelBox((off >> 1) + 175, sgbPlrTalkTbl + off + 25, i, 1, (off >> 1) + PANEL_X + 175, off + PANEL_Y + 9);
}
DrawPanelBox(185, sgbPlrTalkTbl + 35, 274, 30, 249, 531);
DrawPanelBox(180, sgbPlrTalkTbl + 65, 284, 5, 244, 561);
DrawPanelBox(185, sgbPlrTalkTbl + 35, 274, 30, PANEL_X + 185, PANEL_Y + 19);
DrawPanelBox(180, sgbPlrTalkTbl + 65, 284, 5, PANEL_X + 180, PANEL_Y + 49);
for (i = 0; i < 10; i++) {
DrawPanelBox(180, sgbPlrTalkTbl + i + 70, i + 284, 1, 244, i + 566);
DrawPanelBox(180, sgbPlrTalkTbl + i + 70, i + 284, 1, PANEL_X + 180, i + PANEL_Y + 54);
}
DrawPanelBox(170, sgbPlrTalkTbl + 80, 310, 55, 234, 576);
DrawPanelBox(170, sgbPlrTalkTbl + 80, 310, 55, PANEL_X + 170, PANEL_Y + 64);
msg = sgszTalkMsg;
for (i = 0; i < 39; i += 13) {
msg = control_print_talk_msg(msg, 0, i, &x, 0);
msg = control_print_talk_msg(msg, 0 + PANEL_LEFT, i, &x, 0);
if (!msg)
break;
}
Expand All @@ -2460,7 +2460,7 @@ void DrawTalkPan()
nCel = 4;
else
nCel = 3;
CelDraw(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61);
CelDraw(172 + PANEL_X, 84 + 18 * talk_btn + PANEL_Y, pTalkBtns, nCel, 61);
}
} else {
color = COL_RED;
Expand All @@ -2470,10 +2470,10 @@ void DrawTalkPan()
nCel = 1;
if (talkbtndown[talk_btn])
nCel += 4;
CelDraw(172 + SCREEN_X, 436 + 18 * talk_btn + SCREEN_Y, pTalkBtns, nCel, 61);
CelDraw(172 + PANEL_X, 84 + 18 * talk_btn + PANEL_Y, pTalkBtns, nCel, 61);
}
if (plr[i].plractive) {
control_print_talk_msg(plr[i]._pName, 46, 60 + talk_btn * 18, &x, color);
control_print_talk_msg(plr[i]._pName, 46 + PANEL_LEFT, 60 + talk_btn * 18, &x, color);
}

talk_btn++;
Expand All @@ -2487,12 +2487,12 @@ char *control_print_talk_msg(char *msg, int x, int y, int *nOffset, int color)

x += 264;
width = x;
*nOffset = PitchTbl[y + 534] + x;
*nOffset = PitchTbl[y + 182 + PANEL_TOP] + x;
while (*msg) {

c = fontframe[gbFontTransTbl[(BYTE)*msg]];
width += fontkern[c] + 1;
if (width > 514)
if (width > 514 + PANEL_LEFT)
return msg;
msg++;
if (c) {
Expand All @@ -2510,20 +2510,20 @@ BOOL control_check_talk_btn()
if (!talkflag)
return FALSE;

if (MouseX < 172)
if (MouseX < 172 + PANEL_LEFT)
return FALSE;
if (MouseY < 421)
if (MouseY < 69 + PANEL_TOP)
return FALSE;
if (MouseX > 233)
if (MouseX > 233 + PANEL_LEFT)
return FALSE;
if (MouseY > 475)
if (MouseY > 123 + PANEL_TOP)
return FALSE;

for (i = 0; i < sizeof(talkbtndown) / sizeof(talkbtndown[0]); i++) {
talkbtndown[i] = FALSE;
}

talkbtndown[(MouseY - 421) / 18] = TRUE;
talkbtndown[(MouseY - (69 + PANEL_TOP)) / 18] = TRUE;

return TRUE;
}
Expand All @@ -2535,8 +2535,8 @@ void control_release_talk_btn()
if (talkflag) {
for (i = 0; i < sizeof(talkbtndown) / sizeof(talkbtndown[0]); i++)
talkbtndown[i] = FALSE;
if (MouseX >= 172 && MouseY >= 421 && MouseX <= 233 && MouseY <= 475) {
off = (MouseY - 421) / 18;
if (MouseX >= 172 + PANEL_LEFT && MouseY >= 421 + PANEL_LEFT && MouseX <= -119 + PANEL_TOP && MouseY <= 123 + PANEL_TOP) {
off = (MouseY - (69 + PANEL_TOP)) / 18;

for (p = 0; p < MAX_PLRS && off != -1; p++) {
if (p != myplr)
Expand Down
2 changes: 1 addition & 1 deletion Source/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void AddPanelString(char *str, BOOL just);
void ClearPanel();
void DrawPanelBox(int x, int y, int w, int h, int sx, int sy);
void InitPanelStr();
void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int c, int r);
void SetFlaskHeight(BYTE *pCelBuff, int min, int max, int sx, int sy);
void DrawFlask(BYTE *pCelBuff, int w, int nSrcOff, BYTE *pBuff, int nDstOff, int h);
void DrawLifeFlask();
void UpdateLifeFlask();
Expand Down
Loading

0 comments on commit 92ab05e

Please sign in to comment.