From b7dfcf5ed517777a96e9f62bf37b0abbcebc7adc Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 28 Sep 2018 01:49:17 +0200 Subject: [PATCH] Clean up CheckPlrSpell (#339) --- Source/control.cpp | 2 +- Source/inv.cpp | 18 ++-- Source/inv.h | 6 +- Source/msg.cpp | 8 +- Source/msg.h | 8 +- Source/player.cpp | 210 ++++++++++++++++----------------------------- Source/spells.cpp | 8 +- structs.h | 2 +- 8 files changed, 99 insertions(+), 163 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 00056384a..6a572a216 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -424,7 +424,7 @@ void __cdecl DrawSpellList() int v17; // [esp+Ch] [ebp-34h] __int32 xp; // [esp+10h] [ebp-30h] __int32 yp; // [esp+14h] [ebp-2Ch] - unsigned char *v20; // [esp+18h] [ebp-28h] + BOOL *v20; // [esp+18h] [ebp-28h] __int32 nCel; // [esp+1Ch] [ebp-24h] int v22; // [esp+20h] [ebp-20h] __int32 v23; // [esp+24h] [ebp-1Ch] diff --git a/Source/inv.cpp b/Source/inv.cpp index c18089d8d..0aa8f502a 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -2,7 +2,7 @@ #include "../types.h" -int invflag; +BOOL invflag; void *pInvCels; int drawsbarflag; // idb int sgdwLastTime; // check name @@ -3029,7 +3029,7 @@ LABEL_8: CalcPlrScrolls(p); } -bool __cdecl UseScroll() +BOOL __cdecl UseScroll() { int v0; // eax int v1; // esi @@ -3039,7 +3039,7 @@ bool __cdecl UseScroll() int *v5; // ecx if ( pcurs != CURSOR_HAND || leveltype == DTYPE_TOWN && !*(_DWORD *)&spelldata[plr[myplr]._pRSpell].sTownSpell ) - return 0; + return FALSE; v0 = myplr; v1 = 0; v2 = plr[myplr]._pNumInv; @@ -3053,7 +3053,7 @@ LABEL_11: ++v4; v5 += 92; if ( v4 >= MAXBELTITEMS ) - return 0; + return FALSE; } } else @@ -3067,7 +3067,7 @@ LABEL_11: goto LABEL_11; } } - return 1; + return TRUE; } // 5BB1ED: using guessed type char leveltype; @@ -3090,12 +3090,12 @@ void __fastcall UseStaffCharge(int pnum) } } -bool __cdecl UseStaff() +BOOL __cdecl UseStaff() { int v0; // eax - bool result; // al + BOOL result; // al - result = 0; + result = FALSE; if ( pcurs == CURSOR_HAND ) { v0 = myplr; @@ -3104,7 +3104,7 @@ bool __cdecl UseStaff() && plr[v0].InvBody[4]._iSpell == plr[v0]._pRSpell && plr[v0].InvBody[4]._iCharges > 0 ) { - result = 1; + result = TRUE; } } return result; diff --git a/Source/inv.h b/Source/inv.h index 3a67572b3..b7aa17c04 100644 --- a/Source/inv.h +++ b/Source/inv.h @@ -2,7 +2,7 @@ #ifndef __INV_H__ #define __INV_H__ -extern int invflag; +extern BOOL invflag; extern void *pInvCels; extern int drawsbarflag; // idb extern int sgdwLastTime; // check name @@ -39,9 +39,9 @@ int __fastcall InvPutItem(int pnum, int x, int y); int __fastcall SyncPutItem(int pnum, int x, int y, int idx, int icreateinfo, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, unsigned int ibuff); int __cdecl CheckInvHLight(); void __fastcall RemoveScroll(int pnum); -bool __cdecl UseScroll(); +BOOL __cdecl UseScroll(); void __fastcall UseStaffCharge(int pnum); -bool __cdecl UseStaff(); +BOOL __cdecl UseStaff(); void __cdecl StartGoldDrop(); int __fastcall UseInvItem(int pnum, int cii); void __cdecl DoTelekinesis(); diff --git a/Source/msg.cpp b/Source/msg.cpp index 2998b53e3..96cb8e65a 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -945,7 +945,7 @@ void __fastcall NetSendCmdLoc(BOOL bHiPri, unsigned char bCmd, unsigned char x, NetSendLoPri((unsigned char *)&cmd, 3u); } -void __fastcall NetSendCmdLocParam1(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, int wParam1) +void __fastcall NetSendCmdLocParam1(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, unsigned short wParam1) { TCmdLocParam1 cmd; // [esp+0h] [ebp-8h] @@ -959,7 +959,7 @@ void __fastcall NetSendCmdLocParam1(BOOL bHiPri, unsigned char bCmd, unsigned ch NetSendLoPri((unsigned char *)&cmd, 5u); } -void __fastcall NetSendCmdLocParam2(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, int wParam1, int wParam2) +void __fastcall NetSendCmdLocParam2(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, unsigned short wParam1, unsigned short wParam2) { TCmdLocParam2 cmd; // [esp+0h] [ebp-8h] @@ -974,7 +974,7 @@ void __fastcall NetSendCmdLocParam2(BOOL bHiPri, unsigned char bCmd, unsigned ch NetSendLoPri((unsigned char *)&cmd, 7u); } -void __fastcall NetSendCmdLocParam3(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, int wParam1, int wParam2, int wParam3) +void __fastcall NetSendCmdLocParam3(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, unsigned short wParam1, unsigned short wParam2, unsigned short wParam3) { TCmdLocParam3 cmd; // [esp+0h] [ebp-Ch] @@ -1015,7 +1015,7 @@ void __fastcall NetSendCmdParam2(BOOL bHiPri, unsigned char bCmd, unsigned short NetSendLoPri((unsigned char *)&cmd, 5u); } -void __fastcall NetSendCmdParam3(BOOL bHiPri, unsigned char bCmd, unsigned short wParam1, unsigned short wParam2, int wParam3) +void __fastcall NetSendCmdParam3(BOOL bHiPri, unsigned char bCmd, unsigned short wParam1, unsigned short wParam2, unsigned short wParam3) { TCmdParam3 cmd; // [esp+0h] [ebp-8h] diff --git a/Source/msg.h b/Source/msg.h index c5569495b..455bc0e84 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -50,12 +50,12 @@ void __cdecl DeltaLoadLevel(); void __fastcall NetSendCmd(BOOL bHiPri, unsigned char bCmd); void __fastcall NetSendCmdGolem(unsigned char mx, unsigned char my, unsigned char dir, unsigned char menemy, int hp, int cl); void __fastcall NetSendCmdLoc(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y); -void __fastcall NetSendCmdLocParam1(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, int wParam1); -void __fastcall NetSendCmdLocParam2(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, int wParam1, int wParam2); -void __fastcall NetSendCmdLocParam3(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, int wParam1, int wParam2, int wParam3); +void __fastcall NetSendCmdLocParam1(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, unsigned short wParam1); +void __fastcall NetSendCmdLocParam2(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, unsigned short wParam1, unsigned short wParam2); +void __fastcall NetSendCmdLocParam3(BOOL bHiPri, unsigned char bCmd, unsigned char x, unsigned char y, unsigned short wParam1, unsigned short wParam2, unsigned short wParam3); void __fastcall NetSendCmdParam1(BOOL bHiPri, unsigned char bCmd, unsigned short wParam1); void __fastcall NetSendCmdParam2(BOOL bHiPri, unsigned char bCmd, unsigned short wParam1, unsigned short wParam2); -void __fastcall NetSendCmdParam3(BOOL bHiPri, unsigned char bCmd, unsigned short wParam1, unsigned short wParam2, int wParam3); +void __fastcall NetSendCmdParam3(BOOL bHiPri, unsigned char bCmd, unsigned short wParam1, unsigned short wParam2, unsigned short wParam3); void __fastcall NetSendCmdQuest(BOOL bHiPri, unsigned char q); void __fastcall NetSendCmdGItem(BOOL bHiPri, unsigned char bCmd, unsigned char mast, unsigned char pnum, int ii); void __fastcall NetSendCmdGItem2(unsigned char usonly, unsigned char bCmd, unsigned char mast, unsigned char pnum, struct TCmdGItem *p); diff --git a/Source/player.cpp b/Source/player.cpp index 00ce53421..15f73081c 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3676,149 +3676,85 @@ void __fastcall MakePlrPath(int pnum, int xx, int yy, BOOL endspace) void __fastcall CheckPlrSpell() { - int v0; // ecx - int v1; // eax - int v2; // edx - char v3; // al - int v4; // ecx - char v5; // al - int v6; // eax - int v7; // edx - int v8; // esi - int v9; // ST10_4 - int v10; // eax - int v11; // eax - int v12; // eax - int v13; // ST10_4 - int v14; // eax - char v15; // al - - v0 = myplr; - if ( (unsigned int)myplr >= 4 ) - { + if ( (DWORD)myplr >= MAX_PLRS ) { TermMsg("CheckPlrSpell: illegal player %d", myplr); - v0 = myplr; } - v1 = 21720 * v0; - v2 = plr[v0]._pRSpell; - if ( v2 != -1 ) - { - if ( leveltype == DTYPE_TOWN && !*(_DWORD *)&spelldata[v2].sTownSpell ) - { - v5 = *((_BYTE *)&plr[0]._pClass + v1); - switch ( v5 ) - { - case PC_WARRIOR: - v4 = PS_WARR27; - goto LABEL_53; - case PC_ROGUE: - v4 = PS_ROGUE27; - goto LABEL_53; - case PC_SORCERER: - v4 = PS_MAGE27; - goto LABEL_53; - } - return; - } - if ( pcurs != CURSOR_HAND - || MouseY >= 352 - || (chrflag && MouseX < 320 || invflag && MouseX > 320) - && v2 != 2 - && v2 != 5 - && v2 != 26 - && v2 != 9 - && v2 != 27 ) - { - return; - } - _LOBYTE(v1) = *((_BYTE *)&plr[0]._pRSplType + v1); - if ( (v1 & 0x80u) != 0 ) - goto LABEL_46; - if ( (char)v1 <= 1 ) - { - v6 = CheckSpell(v0, v2, v1, 0); + + int rspell = plr[myplr]._pRSpell; + if ( rspell == SPL_INVALID ) { + if ( plr[myplr]._pClass == PC_WARRIOR ) { + PlaySFX(PS_WARR34); + } else if ( plr[myplr]._pClass == PC_ROGUE ) { + PlaySFX(PS_ROGUE34); + } else if ( plr[myplr]._pClass == PC_SORCERER ) { + PlaySFX(PS_MAGE34); } - else - { - if ( (_BYTE)v1 != 2 ) - { - if ( (_BYTE)v1 == 3 ) - { - v6 = UseStaff(); - goto LABEL_36; - } -LABEL_46: - if ( _LOBYTE(plr[v0]._pRSplType) == 1 ) - { - v15 = plr[v0]._pClass; - switch ( v15 ) - { - case PC_WARRIOR: - v4 = PS_WARR35; - goto LABEL_53; - case PC_ROGUE: - v4 = PS_ROGUE35; - goto LABEL_53; - case PC_SORCERER: - v4 = PS_MAGE35; - goto LABEL_53; - } - } - return; - } - v6 = UseScroll(); + return; + } + + if ( leveltype == DTYPE_TOWN && !spelldata[rspell].sTownSpell ) { + if ( plr[myplr]._pClass == PC_WARRIOR ) { + PlaySFX(PS_WARR27); + } else if ( plr[myplr]._pClass == PC_ROGUE ) { + PlaySFX(PS_ROGUE27); + } else if ( plr[myplr]._pClass == PC_SORCERER ) { + PlaySFX(PS_MAGE27); } -LABEL_36: - v0 = myplr; - if ( v6 ) - { - v7 = plr[myplr]._pRSpell; - if ( v7 == 6 ) - { - v8 = GetDirection(plr[myplr].WorldX, plr[myplr].WorldY, cursmx, cursmy); - v9 = GetSpellLevel(myplr, plr[myplr]._pRSpell); - v10 = 21720 * myplr; - _LOWORD(v10) = plr[myplr]._pRSpell; - NetSendCmdLocParam3(1u, CMD_SPELLXYD, cursmx, cursmy, v10, v8, v9); - } - else if ( pcursmonst == -1 ) - { - if ( pcursplr == -1 ) - { - v13 = GetSpellLevel(myplr, v7); - v14 = 21720 * myplr; - _LOWORD(v14) = plr[myplr]._pRSpell; - NetSendCmdLocParam2(1u, CMD_SPELLXY, cursmx, cursmy, v14, v13); - } - else - { - v12 = GetSpellLevel(myplr, v7); - NetSendCmdParam3(1u, CMD_SPELLPID, pcursplr, plr[myplr]._pRSpell, v12); - } - } - else - { - v11 = GetSpellLevel(myplr, v7); - NetSendCmdParam3(1u, CMD_SPELLID, pcursmonst, plr[myplr]._pRSpell, v11); - } - return; + return; + } + + if ( pcurs != CURSOR_HAND + || MouseY >= 352 + || (chrflag && MouseX < 320 || invflag && MouseX > 320) + && rspell != SPL_HEAL + && rspell != SPL_IDENTIFY + && rspell != SPL_REPAIR + && rspell != SPL_INFRA + && rspell != SPL_RECHARGE + ) { + return; + } + + BOOL addflag = FALSE; + switch ( plr[myplr]._pRSplType ) { + case RSPLTYPE_SKILL: + case RSPLTYPE_SPELL: + addflag = CheckSpell(myplr, rspell, plr[myplr]._pRSplType, FALSE); + break; + case RSPLTYPE_SCROLL: + addflag = UseScroll(); + break; + case RSPLTYPE_CHARGES: + addflag = UseStaff(); + break; + } + + if ( addflag ) { + if ( plr[myplr]._pRSpell == SPL_FIREWALL ) { + int sd = GetDirection(plr[myplr].WorldX, plr[myplr].WorldY, cursmx, cursmy); + int sl = GetSpellLevel(myplr, plr[myplr]._pRSpell); + NetSendCmdLocParam3(TRUE, CMD_SPELLXYD, cursmx, cursmy, plr[myplr]._pRSpell, sd, sl); + } else if ( pcursmonst != -1 ) { + int sl = GetSpellLevel(myplr, plr[myplr]._pRSpell); + NetSendCmdParam3(TRUE, CMD_SPELLID, pcursmonst, plr[myplr]._pRSpell, sl); + } else if ( pcursplr != -1 ) { + int sl = GetSpellLevel(myplr, plr[myplr]._pRSpell); + NetSendCmdParam3(TRUE, CMD_SPELLPID, pcursplr, plr[myplr]._pRSpell, sl); + } else {//145 + int sl = GetSpellLevel(myplr, plr[myplr]._pRSpell); + NetSendCmdLocParam2(TRUE, CMD_SPELLXY, cursmx, cursmy, plr[myplr]._pRSpell, sl); } - goto LABEL_46; + return; } - v3 = *((_BYTE *)&plr[0]._pClass + v1); - switch ( v3 ) - { - case PC_WARRIOR: - v4 = PS_WARR34; -LABEL_53: - PlaySFX(v4); - return; - case PC_ROGUE: - v4 = PS_ROGUE34; - goto LABEL_53; - case PC_SORCERER: - v4 = PS_MAGE34; - goto LABEL_53; + + if ( plr[myplr]._pRSplType == RSPLTYPE_SPELL ) { + if ( plr[myplr]._pClass == PC_WARRIOR ) { + PlaySFX(PS_WARR35); + } else if ( plr[myplr]._pClass == PC_ROGUE ) { + PlaySFX(PS_ROGUE35); + } else if ( plr[myplr]._pClass == PC_SORCERER ) { + PlaySFX(PS_MAGE35); + } } } // 4B8CC2: using guessed type char pcursplr; diff --git a/Source/spells.cpp b/Source/spells.cpp index 1f786f12c..67c565134 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -140,13 +140,13 @@ BOOL __fastcall CheckSpell(int id, int sn, BYTE st, BOOL manaonly) { #ifdef _DEBUG if ( debug_mode_key_inverted_v ) - return true; + return TRUE; #endif - BOOL result = true; + BOOL result = TRUE; if ( !manaonly && pcurs != 1 ) { - result = false; + result = FALSE; } else { @@ -154,7 +154,7 @@ BOOL __fastcall CheckSpell(int id, int sn, BYTE st, BOOL manaonly) { if ( GetSpellLevel(id, sn) <= 0 ) { - result = false; + result = FALSE; } else { diff --git a/structs.h b/structs.h index 4f24f6c6b..c84b9308d 100644 --- a/structs.h +++ b/structs.h @@ -1066,7 +1066,7 @@ struct SpellData int sBookLvl; int sStaffLvl; int sTargeted; - unsigned char sTownSpell; + BOOL sTownSpell; int sMinInt; unsigned char sSFX; unsigned char sMissiles[3];