From 744e225618ee2b51810a3c1ce06e5f25f047ccbe Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 6 Oct 2018 00:33:58 +0200 Subject: [PATCH] Clean up player.cpp (#387) --- Source/control.cpp | 2 +- Source/diablo.cpp | 8 ++--- Source/gamemenu.cpp | 6 ++-- Source/minitext.cpp | 6 ++-- Source/monster.cpp | 10 +++---- Source/msg.cpp | 2 +- Source/player.cpp | 71 +++++++++++++++++++++++++-------------------- Source/player.h | 2 +- Source/spells.cpp | 2 +- Source/stores.cpp | 6 ++-- Source/towners.cpp | 2 +- enums.h | 1 + structs.h | 2 +- 13 files changed, 64 insertions(+), 56 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index ff6fbdd74..d1402fabe 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1674,7 +1674,7 @@ void __cdecl CheckBtnUp() DoAutoMap(); break; case PANBTN_MAINMENU: - qtextflag = 0; + qtextflag = FALSE; gamemenu_handle_previous(); v6 = 0; break; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 08624959b..8740f7e52 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -618,7 +618,7 @@ int __cdecl PressEscKey() } if ( qtextflag ) { - qtextflag = 0; + qtextflag = FALSE; sfx_stop(); } else @@ -897,7 +897,7 @@ bool __fastcall LeftMouseDown(int a1) } if ( qtextflag ) { - qtextflag = 0; + qtextflag = FALSE; sfx_stop(); return 0; } @@ -1294,7 +1294,7 @@ LABEL_113: spselflag = 0; if ( qtextflag && leveltype == DTYPE_TOWN) { - qtextflag = 0; + qtextflag = FALSE; sfx_stop(); } questlog = 0; @@ -1418,7 +1418,7 @@ LABEL_106: spselflag = 0; if ( qtextflag && leveltype == DTYPE_TOWN ) { - qtextflag = 0; + qtextflag = FALSE; sfx_stop(); } questlog = 0; diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index a3d9f33bc..24df2f6a6 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -91,10 +91,10 @@ void __cdecl gamemenu_new_game() plr[i]._pInvincible = 1; } - deathflag = 0; + deathflag = FALSE; drawpanflag = 255; scrollrt_draw_game_screen(1); - gbRunGame = 0; + gbRunGame = FALSE; gamemenu_off(); } // 525650: using guessed type int gbRunGame; @@ -120,7 +120,7 @@ void __cdecl gamemenu_load_game() LoadGame(FALSE); ClrDiabloMsg(); PaletteFadeOut(8); - deathflag = 0; + deathflag = FALSE; drawpanflag = 255; DrawAndBlit(); PaletteFadeIn(8); diff --git a/Source/minitext.cpp b/Source/minitext.cpp index fe55798f0..38d1e3d2c 100644 --- a/Source/minitext.cpp +++ b/Source/minitext.cpp @@ -60,7 +60,7 @@ void __cdecl InitQuestText() pMedTextCels = LoadFileInMem("Data\\MedTextS.CEL", 0); v0 = LoadFileInMem("Data\\TextBox.CEL", 0); - qtextflag = 0; + qtextflag = FALSE; pTextBoxCels = v0; } // 646D00: using guessed type char qtextflag; @@ -71,7 +71,7 @@ void __fastcall InitQTextMsg(int m) { questlog = 0; qtextptr = alltext[m].txtstr; - qtextflag = 1; + qtextflag = TRUE; qtexty = 500; sgLastScroll = qscroll_spd_tbl[alltext[m].txtspd - 1]; /* double check offset */ scrolltexty = sgLastScroll; @@ -314,7 +314,7 @@ LABEL_35: qtexty += 38; qtextptr = v13; if ( *v13 == 124 ) - qtextflag = 0; + qtextflag = FALSE; } // 646CF4: using guessed type int qtexty; // 646CFC: using guessed type int qtextSpd; diff --git a/Source/monster.cpp b/Source/monster.cpp index 4459d8b68..232e9b4bc 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -737,7 +737,7 @@ void __fastcall InitMonster(int i, int rd, int mtype, int x, int y) monster[i]._uniqtype = 0; monster[i]._msquelch = 0; monster[i].field_18 = 0; - monster[i]._mDelFlag = 0; + monster[i]._mDelFlag = FALSE; monster[i]._mRndSeed = GetRndSeed(); monster[i]._mAISeed = GetRndSeed(); monster[i].mWhoHit = 0; @@ -824,7 +824,7 @@ void __cdecl ClrAllMonsters() Monst->_mAnimLen = 0; Monst->_mAnimFrame = 0; Monst->_mFlags = 0; - Monst->_mDelFlag = 0; + Monst->_mDelFlag = FALSE; Monst->_menemy = random(89, gbActivePlayers); Monst->_menemyx = plr[Monst->_menemy]._px; Monst->_menemyy = plr[Monst->_menemy]._py; @@ -3874,7 +3874,7 @@ void __cdecl PrepDoEnding() gbSoundOn = sgbSaveSoundOn; gbRunGame = 0; - deathflag = 0; + deathflag = FALSE; v0 = &plr[myplr].pDiabloKillLevel; v1 = gnDifficulty + 1; cineflag = 1; @@ -3958,7 +3958,7 @@ int __fastcall M_DoDeath(int i) v10 = v3->mdeadval; AddDead(monster[v2]._mx, monster[v2]._my, v10, (direction)monster[v2]._mdir); v11 = monster[v2]._my + 112 * monster[v2]._mx; - monster[v2]._mDelFlag = 1; + monster[v2]._mDelFlag = TRUE; dMonster[0][v11] = 0; M_UpdateLeader(v1); } @@ -4032,7 +4032,7 @@ int __fastcall M_DoStone(int i) if ( !monster[v1]._mhitpoints ) { v3 = monster[v2]._mx; - monster[v2]._mDelFlag = 1; + monster[v2]._mDelFlag = TRUE; dMonster[0][monster[v2]._my + 112 * v3] = 0; } return 0; diff --git a/Source/msg.cpp b/Source/msg.cpp index 427e363ba..f5d6ba3ea 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -3620,7 +3620,7 @@ int __fastcall On_RETOWN(struct TCmd *pCmd, int pnum) { if ( pnum == myplr ) { - deathflag = 0; + deathflag = FALSE; gamemenu_off(); } RestartTownLvl(v2); diff --git a/Source/player.cpp b/Source/player.cpp index d80eabf9f..d59233751 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -11,7 +11,7 @@ int myplr; PlayerStruct plr[MAX_PLRS]; int plr_fframe_size; // idb int plr_qframe_size; // idb -int deathflag; // idb +BOOL deathflag; // idb int plr_hframe_size; // idb int plr_bframe_size; // idb UCHAR plr_gfx_bflag = 0; @@ -317,10 +317,10 @@ void __fastcall InitPlrGFXMem(int pnum) DWORD __fastcall GetPlrGFXSize(char *szCel) { - char prefix[16]; // [esp+10Ch] [ebp-24h] - char pszName[256]; // [esp+Ch] [ebp-124h] - void *file; // [esp+124h] [ebp-Ch] - DWORD size = 0; // [esp+11Ch] [ebp-14h] + char prefix[16]; + char pszName[256]; + void *file; + DWORD size = 0; DWORD result = 0; int a = 0; int w = 0; @@ -853,7 +853,7 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime) plr[pnum]._peflag = 0; if ( pnum == myplr ) { - if ( !FirstTime || currlevel ) { + if ( !FirstTime || currlevel != 0 ) { plr[pnum].WorldX = ViewX; plr[pnum].WorldY = ViewY; } @@ -905,7 +905,7 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime) plr[pnum]._pInvincible = FALSE; if ( pnum == myplr ) { - deathdelay = 0; + deathdelay = FALSE; deathflag = 0; ScrollInfo._sxoff = 0; ScrollInfo._syoff = 0; @@ -1125,8 +1125,9 @@ void __fastcall PM_ChangeLightOff(int pnum) int offx, offy; const LightListStruct *l; - if ( (DWORD)pnum >= MAX_PLRS ) + if ( (DWORD)pnum >= MAX_PLRS ) { TermMsg("PM_ChangeLightOff: illegal player %d", pnum); + } l = &LightList[plr[pnum]._plid]; ymul = -1; @@ -1135,12 +1136,14 @@ void __fastcall PM_ChangeLightOff(int pnum) if (x < 0) { xmul = -1; x = -x; - } else + } else { xmul = 1; + } if (y < 0) { y = -y; - } else + } else { ymul = 1; + } x = (x >> 3) * xmul; y = (y >> 3) * ymul; @@ -1151,6 +1154,7 @@ void __fastcall PM_ChangeLightOff(int pnum) if ( abs(lx - offx) < 3 && abs(ly - offy) < 3 ) return; + ChangeLightOff(plr[pnum]._plid, x, y); } @@ -1173,6 +1177,7 @@ void __fastcall PM_ChangeOffset(int pnum) ScrollInfo._sxoff += px - plr[pnum]._pxoff; ScrollInfo._syoff += py - plr[pnum]._pyoff; } + PM_ChangeLightOff(pnum); } @@ -1217,6 +1222,7 @@ void __fastcall StartWalk(int pnum, int xvel, int yvel, int xadd, int yadd, int if ( !(plr[pnum]._pGFXLoad & PFILE_WALK) ) { LoadPlrGFX(pnum, PFILE_WALK); } + NewPlrAnim(pnum, plr[pnum]._pWAnim[EndDir], plr[pnum]._pWFrames, 0, plr[pnum]._pWWidth); plr[pnum]._pdir = EndDir; @@ -1232,12 +1238,12 @@ void __fastcall StartWalk(int pnum, int xvel, int yvel, int xadd, int yadd, int if ( zoomflag ) { if ( abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3 ) { - ScrollInfo._sdir = 0; + ScrollInfo._sdir = SDIR_NONE; } else { ScrollInfo._sdir = sdir; } } else if ( abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2 ) { - ScrollInfo._sdir = 0; + ScrollInfo._sdir = SDIR_NONE; } else { ScrollInfo._sdir = sdir; } @@ -1310,12 +1316,12 @@ void __fastcall StartWalk2(int pnum, int xvel, int yvel, int xoff, int yoff, int if ( zoomflag ) { if ( abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3 ) { - ScrollInfo._sdir = 0; + ScrollInfo._sdir = SDIR_NONE; } else { ScrollInfo._sdir = sdir; } } else if ( abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2 ) { - ScrollInfo._sdir = 0; + ScrollInfo._sdir = SDIR_NONE; } else { ScrollInfo._sdir = sdir; } @@ -1381,7 +1387,7 @@ void __fastcall StartWalk3(int pnum, int xvel, int yvel, int xoff, int yoff, int plr[pnum]._pdir = EndDir; plr[pnum]._pVar8 = 0; - InitPlayerLoc(pnum, 0); + InitPlayerLoc(pnum, FALSE); if ( pnum != myplr ) { return; @@ -1389,12 +1395,12 @@ void __fastcall StartWalk3(int pnum, int xvel, int yvel, int xoff, int yoff, int if ( zoomflag ) { if ( abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3 ) { - ScrollInfo._sdir = 0; + ScrollInfo._sdir = SDIR_NONE; } else { ScrollInfo._sdir = sdir; } } else if ( abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2 ) { - ScrollInfo._sdir = 0; + ScrollInfo._sdir = SDIR_NONE; } else { ScrollInfo._sdir = sdir; } @@ -1667,7 +1673,7 @@ void __fastcall StartPlayerKill(int pnum, int earflag) for ( i = 0; i < NUM_INVLOC; i++ ) { plr[pnum].InvBody[i]._itype = ITYPE_NONE; } - CalcPlrInv(pnum, 0); + CalcPlrInv(pnum, FALSE); } if ( plr[pnum].plrlevel == currlevel ) { @@ -1717,7 +1723,7 @@ void __fastcall StartPlayerKill(int pnum, int earflag) pi++; } - CalcPlrInv(pnum, 0); + CalcPlrInv(pnum, FALSE); } } } @@ -1736,8 +1742,9 @@ void __fastcall PlrDeadItem(int pnum, struct ItemStruct *itm, int xx, int yy) if ( itm->_itype == ITYPE_NONE ) return; - if ( (unsigned int)pnum >= MAX_PLRS ) + if ( (DWORD)pnum >= MAX_PLRS ) { TermMsg("PlrDeadItem: illegal player %d", pnum); + } x = xx + plr[pnum].WorldX; y = yy + plr[pnum].WorldY; @@ -1903,7 +1910,7 @@ void __fastcall RemovePlrMissiles(int pnum) M_StartKill(myplr, myplr); AddDead(monster[myplr]._mx, monster[myplr]._my, monster[myplr].MType->mdeadval, (direction)monster[myplr]._mdir); dMonster[monster[myplr]._mx][monster[myplr]._my] = 0; - monster[myplr]._mDelFlag = 1; + monster[myplr]._mDelFlag = TRUE; DeleteMonsterList(); } @@ -1927,7 +1934,7 @@ void __fastcall InitLevelChange(int pnum) { RemovePlrMissiles(pnum); if ( pnum == myplr && qtextflag ) { - qtextflag = 0; + qtextflag = FALSE; sfx_stop(); } @@ -2057,7 +2064,7 @@ BOOL __fastcall PM_DoWalk(int pnum) } int vel = 8; - if ( currlevel ) { + if ( currlevel != 0 ) { vel = PWVel[3][plr[pnum]._pClass]; } @@ -2111,7 +2118,7 @@ BOOL __fastcall PM_DoWalk2(int pnum) } int vel = 8; - if ( currlevel ) { + if ( currlevel != 0 ) { vel = PWVel[3][plr[pnum]._pClass]; } @@ -2161,7 +2168,7 @@ BOOL __fastcall PM_DoWalk3(int pnum) } int vel = 8; - if ( currlevel ) { + if ( currlevel != 0 ) { vel = PWVel[3][plr[pnum]._pClass]; } @@ -2345,7 +2352,7 @@ BOOL __fastcall PlrHitMonst(int pnum, int m) } int mClass = monster[m].MData->mMonstClass; - switch (mClass ) { + switch ( mClass ) { case MC_UNDEAD: if ( phanditype == ITYPE_SWORD ) { dam -= dam >> 1; @@ -2401,7 +2408,7 @@ BOOL __fastcall PlrHitMonst(int pnum, int m) if ( plr[pnum]._pManaBase > plr[pnum]._pMaxManaBase ) { plr[pnum]._pManaBase = plr[pnum]._pMaxManaBase; } - drawmanaflag = 1; + drawmanaflag = TRUE; } if ( plr[pnum]._pIFlags & (ISPL_STEALLIFE_3 | ISPL_STEALLIFE_5) ) { if ( plr[pnum]._pIFlags & ISPL_STEALLIFE_3 ) { @@ -2905,8 +2912,8 @@ BOOL __fastcall PM_DoDeath(int pnum) if ( plr[pnum]._pVar8 >= 2 * plr[pnum]._pDFrames ) { if ( deathdelay > 1 && pnum == myplr ) { deathdelay--; - if ( deathdelay == 1 ) { - deathflag = 1; + if ( deathdelay ) { + deathflag = TRUE; if ( gbMaxPlayers == 1 ) { gamemenu_previous(); } @@ -3354,7 +3361,7 @@ void __cdecl ProcessPlayers() } if ( pnum == myplr ) { - if ( (plr[pnum]._pIFlags & ISPL_DRAINLIFE) && currlevel ) { + if ( (plr[pnum]._pIFlags & ISPL_DRAINLIFE) && currlevel != 0 ) { plr[pnum]._pHitPoints -= 4; plr[pnum]._pHPBase -= 4; if ( (plr[pnum]._pHitPoints >> 6) <= 0 ) { @@ -3477,7 +3484,7 @@ BOOL __fastcall PosOkPlayer(int pnum, int px, int py) } if ( dMonster[px][py] ) { - if ( !currlevel ) { + if ( currlevel == 0 ) { return FALSE; } if ( dMonster[px][py] <= 0 ) { @@ -3721,7 +3728,7 @@ void __fastcall SyncInitPlrPos(int pnum) if ( PosOkPlayer(pnum, x, y) ) { break; } - } + } if ( !PosOkPlayer(pnum, x, y) ) { BOOL posOk = FALSE; diff --git a/Source/player.h b/Source/player.h index c590d5a78..ea0367fde 100644 --- a/Source/player.h +++ b/Source/player.h @@ -11,7 +11,7 @@ extern int myplr; extern PlayerStruct plr[MAX_PLRS]; extern int plr_fframe_size; // idb extern int plr_qframe_size; // idb -extern int deathflag; // idb +extern BOOL deathflag; // idb extern int plr_hframe_size; // idb extern int plr_bframe_size; // idb extern UCHAR plr_gfx_bflag; diff --git a/Source/spells.cpp b/Source/spells.cpp index a2521a6df..9ac298d66 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -228,7 +228,7 @@ void __fastcall DoResurrect(int pnum, int rid) { if ( rid == myplr ) { - deathflag = 0; + deathflag = FALSE; gamemenu_off(); drawhpflag = TRUE; drawmanaflag = TRUE; diff --git a/Source/stores.cpp b/Source/stores.cpp index 74025e88b..03dbb8ec2 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -2251,7 +2251,7 @@ void __cdecl STextESC() if ( qtextflag ) { - qtextflag = 0; + qtextflag = FALSE; if ( leveltype == DTYPE_TOWN ) sfx_stop(); } @@ -4048,7 +4048,7 @@ void __cdecl STextEnter() { if ( qtextflag ) { - qtextflag = 0; + qtextflag = FALSE; if ( leveltype == DTYPE_TOWN ) sfx_stop(); } @@ -4147,7 +4147,7 @@ void __cdecl CheckStoreBtn() if ( qtextflag ) { - qtextflag = 0; + qtextflag = FALSE; if ( leveltype == DTYPE_TOWN ) sfx_stop(); } diff --git a/Source/towners.cpp b/Source/towners.cpp index eebddbded..e83882923 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -784,7 +784,7 @@ void __fastcall TownCtrlMsg(int i) towner[i]._tbtcnt = 0; if ( !towner[i]._tbtcnt ) { - qtextflag = 0; + qtextflag = FALSE; sfx_stop(); } } diff --git a/enums.h b/enums.h index f3f5472f6..ccac8b56d 100644 --- a/enums.h +++ b/enums.h @@ -1942,6 +1942,7 @@ enum direction enum _scroll_direction { + SDIR_NONE = 0x0, SDIR_N = 0x1, SDIR_NE = 0x2, SDIR_E = 0x3, diff --git a/structs.h b/structs.h index 6cdd77d19..c8d7cf217 100644 --- a/structs.h +++ b/structs.h @@ -579,7 +579,7 @@ struct MonsterStruct // note: missing field _mAFNum int _mAnimLen; int _mAnimFrame; int _meflag; - int _mDelFlag; + BOOL _mDelFlag; int _mVar1; int _mVar2; int _mVar3;