From 760a2d5e0d9dc12a01938895ef422cbb444d1fde Mon Sep 17 00:00:00 2001 From: aperturesecurity Date: Tue, 23 Oct 2018 21:27:13 +0300 Subject: [PATCH] Fixed the LSHIFT button . I had to Stubb Diablo.cpp --- CMakeLists.txt | 6 +- Source/diablo.cpp | 8 + Source/diablo.h | 3 + Source/player.cpp | 3273 +++++++++++++++++++++++--------------- Stub/diablo.cpp | 2327 +++++++++++++++++++++++++++ Stub/miniwin.h | 1 + Stub/miniwin_msg_sdl.cpp | 23 +- Stub/miniwin_sdl.cpp | 1 - Stub/sound.cpp | 11 +- 9 files changed, 4390 insertions(+), 1263 deletions(-) create mode 100644 Stub/diablo.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index be18a52ba..77ec42ee9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,13 +42,13 @@ set(SOURCES Source/cursor.cpp Source/dead.cpp Source/debug.cpp - Source/diablo.cpp +# Source/diablo.cpp Source/doom.cpp Source/drlg_l1.cpp Source/drlg_l2.cpp Source/drlg_l3.cpp Source/drlg_l4.cpp -# Source/effects.cpp +# Source/effects.cpp Source/encrypt.cpp Source/engine.cpp Source/error.cpp @@ -112,6 +112,7 @@ set(ORIGINAL_SOURCES Source/nthread.cpp Source/restrict.cpp Source/sound.cpp + Source/diablo.cpp ) set(STUB_SOURCES @@ -136,6 +137,7 @@ set(STUB_SOURCES Stub/effects.cpp Stub/sdlrender.cpp Stub/SDL_FontCache.cpp + Stub/diablo.cpp 3rdParty/StormLib/src/FileStream.cpp 3rdParty/StormLib/src/SBaseCommon.cpp diff --git a/Source/diablo.cpp b/Source/diablo.cpp index cfa9a23d5..3a05f9048 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -2189,6 +2189,9 @@ void __fastcall game_loop(bool bStartup) // 525650: using guessed type int gbRunGame; // 679660: using guessed type char gbMaxPlayers; + +bool CUSTOM_SDL_KEY_LSHIFT; + void __cdecl game_logic() { if ( PauseMode != 2 ) @@ -2223,6 +2226,11 @@ void __cdecl game_logic() ProcessItems(); ProcessMissiles(); } + + + + + #ifdef _DEBUG if ( debug_mode_key_inverted_v ) { diff --git a/Source/diablo.h b/Source/diablo.h index e15c8543a..ed351057e 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -34,6 +34,9 @@ extern int PauseMode; // weak extern int sgnTimeoutCurs; extern char sgbMouseDown; // weak extern int color_cycle_timer; // weak +extern bool CUSTOM_SDL_KEY_LSHIFT; + + void __cdecl diablo_cpp_init(); void __cdecl FreeGameMem(); diff --git a/Source/player.cpp b/Source/player.cpp index b03c31ac0..dde9f1b2d 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -7,101 +7,99 @@ int plr_lframe_size; // idb int plr_wframe_size; // idb UCHAR plr_gfx_flag = 0; int player_cpp_init_value; // weak -int plr_aframe_size; // idb +int plr_aframe_size; // idb int myplr; PlayerStruct plr[MAX_PLRS]; int plr_fframe_size; // idb int plr_qframe_size; // idb -int deathflag; // idb +int deathflag; // idb int plr_hframe_size; // idb int plr_bframe_size; // idb UCHAR plr_gfx_bflag = 0; int plr_sframe_size; // idb -int deathdelay; // weak +int deathdelay; // weak int plr_dframe_size; // idb #endif const int player_inf = 0x7F800000; // weak -const char ArmourChar[4] = { 'L', 'M', 'H', 0 }; -const char WepChar[10] = { 'N', 'U', 'S', 'D', 'B', 'A', 'M', 'H', 'T', 0 }; -const char CharChar[4] = { 'W', 'R', 'S', 0 }; +const char ArmourChar[4] = {'L', 'M', 'H', 0}; +const char WepChar[10] = {'N', 'U', 'S', 'D', 'B', 'A', 'M', 'H', 'T', 0}; +const char CharChar[4] = {'W', 'R', 'S', 0}; /* data */ -int plrxoff[9] = { 0, 2, 0, 2, 1, 0, 1, 2, 1 }; -int plryoff[9] = { 0, 2, 2, 0, 1, 1, 0, 1, 2 }; -int plrxoff2[9] = { 0, 1, 0, 1, 2, 0, 1, 2, 2 }; -int plryoff2[9] = { 0, 0, 1, 1, 0, 2, 2, 1, 2 }; +int plrxoff[9] = {0, 2, 0, 2, 1, 0, 1, 2, 1}; +int plryoff[9] = {0, 2, 2, 0, 1, 1, 0, 1, 2}; +int plrxoff2[9] = {0, 1, 0, 1, 2, 0, 1, 2, 2}; +int plryoff2[9] = {0, 0, 1, 1, 0, 2, 2, 1, 2}; char PlrGFXAnimLens[3][11] = -{ - { 10, 16, 8, 2, 20, 20, 6, 20, 8, 9, 14 }, - { 8, 18, 8, 4, 20, 16, 7, 20, 8, 10, 12 }, - { 8, 16, 8, 6, 20, 12, 8, 20, 8, 12, 8 } -}; -int PWVel[4][3] = { { 2048, 1024, 512 }, { 2048, 1024, 512 }, { 2048, 1024, 512 }, { 8, 8, 8 } }; -int StrengthTbl[3] = { 30, 20, 15 }; -int MagicTbl[3] = { 10, 15, 35 }; -int DexterityTbl[3] = { 20, 30, 15 }; -int VitalityTbl[3] = { 25, 20, 20 }; -int ToBlkTbl[3] = { 30, 20, 10 }; -char *ClassStrTblOld[3] = { "Warrior", "Rogue", "Sorceror" }; // unused -int MaxStats[3][4] = { { 250, 50, 60, 100 }, { 55, 70, 250, 80 }, { 45, 250, 85, 80 } }; + { + {10, 16, 8, 2, 20, 20, 6, 20, 8, 9, 14}, + {8, 18, 8, 4, 20, 16, 7, 20, 8, 10, 12}, + {8, 16, 8, 6, 20, 12, 8, 20, 8, 12, 8}}; +int PWVel[4][3] = {{2048, 1024, 512}, {2048, 1024, 512}, {2048, 1024, 512}, {8, 8, 8}}; +int StrengthTbl[3] = {30, 20, 15}; +int MagicTbl[3] = {10, 15, 35}; +int DexterityTbl[3] = {20, 30, 15}; +int VitalityTbl[3] = {25, 20, 20}; +int ToBlkTbl[3] = {30, 20, 10}; +char *ClassStrTblOld[3] = {"Warrior", "Rogue", "Sorceror"}; // unused +int MaxStats[3][4] = {{250, 50, 60, 100}, {55, 70, 250, 80}, {45, 250, 85, 80}}; int ExpLvlsTbl[51] = -{ - 0, - 2000, - 4620, - 8040, - 12489, - 18258, - 25712, - 35309, - 47622, - 63364, - 83419, - 108879, - 141086, - 181683, - 231075, - 313656, - 424067, - 571190, - 766569, - 1025154, - 1366227, - 1814568, - 2401895, - 3168651, - 4166200, - 5459523, - 7130496, - 9281874, - 12042092, - 15571031, - 20066900, - 25774405, - 32994399, - 42095202, - 53525811, - 67831218, - 85670061, - 107834823, - 135274799, - 169122009, - 210720231, - 261657253, - 323800420, - 399335440, - 490808349, - 601170414, - 733825617, - 892680222, - 1082908612, - 1310707109, - 1583495809 -}; -char *ClassStrTbl[3] = { "Warrior", "Rogue", "Sorceror" }; -unsigned char fix[9] = { 0u, 0u, 3u, 3u, 3u, 6u, 6u, 6u, 8u }; /* PM_ChangeLightOff local type */ + { + 0, + 2000, + 4620, + 8040, + 12489, + 18258, + 25712, + 35309, + 47622, + 63364, + 83419, + 108879, + 141086, + 181683, + 231075, + 313656, + 424067, + 571190, + 766569, + 1025154, + 1366227, + 1814568, + 2401895, + 3168651, + 4166200, + 5459523, + 7130496, + 9281874, + 12042092, + 15571031, + 20066900, + 25774405, + 32994399, + 42095202, + 53525811, + 67831218, + 85670061, + 107834823, + 135274799, + 169122009, + 210720231, + 261657253, + 323800420, + 399335440, + 490808349, + 601170414, + 733825617, + 892680222, + 1082908612, + 1310707109, + 1583495809}; +char *ClassStrTbl[3] = {"Warrior", "Rogue", "Sorceror"}; +unsigned char fix[9] = {0u, 0u, 3u, 3u, 3u, 6u, 6u, 6u, 8u}; /* PM_ChangeLightOff local type */ struct player_cpp_init { @@ -115,14 +113,16 @@ struct player_cpp_init void __fastcall SetPlayerGPtrs(UCHAR *pData, UCHAR **pAnim) { - for ( int i = 0; i < 8; i++ ) { + for (int i = 0; i < 8; i++) + { pAnim[i] = pData + ((DWORD *)pData)[i]; } } void __fastcall LoadPlrGFX(int pnum, player_graphic gfxflag) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("LoadPlrGFX: illegal player %d", pnum); } @@ -135,91 +135,104 @@ void __fastcall LoadPlrGFX(int pnum, player_graphic gfxflag) UCHAR *pData; UCHAR *pAnim; - for (DWORD i = 1; i <= PFILE_NONDEATH; i <<= 1) { - if ( !(i & gfxflag) ) { + for (DWORD i = 1; i <= PFILE_NONDEATH; i <<= 1) + { + if (!(i & gfxflag)) + { continue; } - switch ( i ) { - case PFILE_STAND: - szCel = "AS"; - if ( leveltype == DTYPE_TOWN ) { - szCel = "ST"; - } - pData = p->_pNData; - pAnim = (UCHAR *)p->_pNAnim; - break; - case PFILE_WALK: - szCel = "AW"; - if ( leveltype == DTYPE_TOWN ) { - szCel = "WL"; - } - pData = p->_pWData; - pAnim = (UCHAR *)p->_pWAnim; - break; - case PFILE_ATTACK: - if ( leveltype == DTYPE_TOWN ) { - continue; - } - szCel = "AT"; - pData = p->_pAData; - pAnim = (UCHAR *)p->_pAAnim; - break; - case PFILE_HIT: - if ( leveltype == DTYPE_TOWN ) { - continue; - } - szCel = "HT"; - pData = p->_pHData; - pAnim = (UCHAR *)p->_pHAnim; - break; - case PFILE_LIGHTNING: - if ( leveltype == DTYPE_TOWN ) { - continue; - } - szCel = "LM"; - pData = p->_pLData; - pAnim = (UCHAR *)p->_pLAnim; - break; - case PFILE_FIRE: - if ( leveltype == DTYPE_TOWN ) { - continue; - } - szCel = "FM"; - pData = p->_pFData; - pAnim = (UCHAR *)p->_pFAnim; - break; - case PFILE_MAGIC: - if ( leveltype == DTYPE_TOWN ) { - continue; - } - szCel = "QM"; - pData = p->_pTData; - pAnim = (UCHAR *)p->_pTAnim; - break; - case PFILE_DEATH: - if ( p->_pgfxnum & 0xF ) { - continue; - } - szCel = "DT"; - pData = p->_pDData; - pAnim = (UCHAR *)p->_pDAnim; - break; - case PFILE_BLOCK: - if ( leveltype == DTYPE_TOWN ) { - continue; - } - if ( !p->_pBlockFlag ) { - continue; - } + switch (i) + { + case PFILE_STAND: + szCel = "AS"; + if (leveltype == DTYPE_TOWN) + { + szCel = "ST"; + } + pData = p->_pNData; + pAnim = (UCHAR *)p->_pNAnim; + break; + case PFILE_WALK: + szCel = "AW"; + if (leveltype == DTYPE_TOWN) + { + szCel = "WL"; + } + pData = p->_pWData; + pAnim = (UCHAR *)p->_pWAnim; + break; + case PFILE_ATTACK: + if (leveltype == DTYPE_TOWN) + { + continue; + } + szCel = "AT"; + pData = p->_pAData; + pAnim = (UCHAR *)p->_pAAnim; + break; + case PFILE_HIT: + if (leveltype == DTYPE_TOWN) + { + continue; + } + szCel = "HT"; + pData = p->_pHData; + pAnim = (UCHAR *)p->_pHAnim; + break; + case PFILE_LIGHTNING: + if (leveltype == DTYPE_TOWN) + { + continue; + } + szCel = "LM"; + pData = p->_pLData; + pAnim = (UCHAR *)p->_pLAnim; + break; + case PFILE_FIRE: + if (leveltype == DTYPE_TOWN) + { + continue; + } + szCel = "FM"; + pData = p->_pFData; + pAnim = (UCHAR *)p->_pFAnim; + break; + case PFILE_MAGIC: + if (leveltype == DTYPE_TOWN) + { + continue; + } + szCel = "QM"; + pData = p->_pTData; + pAnim = (UCHAR *)p->_pTAnim; + break; + case PFILE_DEATH: + if (p->_pgfxnum & 0xF) + { + continue; + } + szCel = "DT"; + pData = p->_pDData; + pAnim = (UCHAR *)p->_pDAnim; + break; + case PFILE_BLOCK: + if (leveltype == DTYPE_TOWN) + { + continue; + } + if (!p->_pBlockFlag) + { + continue; + } - szCel = "BL"; - pData = p->_pBData; - pAnim = (UCHAR *)p->_pBAnim; - break; - default: - TermMsg("PLR:2"); - break; + szCel = "BL"; + pData = p->_pBData; + pAnim = (UCHAR *)p->_pBAnim; + break; + default: + TermMsg("PLR:2"); + break; } sprintf(pszName, "PlrGFX\\%s\\%s\\%s%s.CL2", cs, prefix, prefix, szCel); @@ -232,81 +245,101 @@ void __fastcall LoadPlrGFX(int pnum, player_graphic gfxflag) void __fastcall InitPlayerGFX(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("InitPlayerGFX: illegal player %d", pnum); } - if ( plr[pnum]._pHitPoints >> 6 == 0 ) { + if (plr[pnum]._pHitPoints >> 6 == 0) + { plr[pnum]._pgfxnum = 0; LoadPlrGFX(pnum, PFILE_DEATH); - } else { + } + else + { LoadPlrGFX(pnum, PFILE_NONDEATH); } } void __fastcall InitPlrGFXMem(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("InitPlrGFXMem: illegal player %d", pnum); } - if ( !(plr_gfx_flag & 0x1) ) {//STAND + if (!(plr_gfx_flag & 0x1)) + { //STAND plr_gfx_flag |= 0x1; - if ( GetPlrGFXSize("ST") > GetPlrGFXSize("AS") ) { - plr_sframe_size = GetPlrGFXSize("ST");//TOWN - } else { - plr_sframe_size = GetPlrGFXSize("AS");//DUNGION + if (GetPlrGFXSize("ST") > GetPlrGFXSize("AS")) + { + plr_sframe_size = GetPlrGFXSize("ST"); //TOWN + } + else + { + plr_sframe_size = GetPlrGFXSize("AS"); //DUNGION } } plr[pnum]._pNData = DiabloAllocPtr(plr_sframe_size); - if ( !(plr_gfx_flag & 0x2) ) {//WALK + if (!(plr_gfx_flag & 0x2)) + { //WALK plr_gfx_flag |= 0x2; - if ( GetPlrGFXSize("WL") > GetPlrGFXSize("AW") ) { - plr_wframe_size = GetPlrGFXSize("WL");//TOWN - } else { - plr_wframe_size = GetPlrGFXSize("AW");//DUNGION + if (GetPlrGFXSize("WL") > GetPlrGFXSize("AW")) + { + plr_wframe_size = GetPlrGFXSize("WL"); //TOWN + } + else + { + plr_wframe_size = GetPlrGFXSize("AW"); //DUNGION } } plr[pnum]._pWData = DiabloAllocPtr(plr_wframe_size); - if ( !(plr_gfx_flag & 0x4) ) {//ATTACK + if (!(plr_gfx_flag & 0x4)) + { //ATTACK plr_gfx_flag |= 0x4; plr_aframe_size = GetPlrGFXSize("AT"); } - plr[pnum]._pAData = DiabloAllocPtr(plr_aframe_size); + plr[pnum]._pAData = DiabloAllocPtr(plr_aframe_size); - if ( !(plr_gfx_flag & 0x8) ) {//HIT + if (!(plr_gfx_flag & 0x8)) + { //HIT plr_gfx_flag |= 0x8; plr_hframe_size = GetPlrGFXSize("HT"); } plr[pnum]._pHData = DiabloAllocPtr(plr_hframe_size); - if ( !(plr_gfx_flag & 0x10) ) {//LIGHTNING + if (!(plr_gfx_flag & 0x10)) + { //LIGHTNING plr_gfx_flag |= 0x10; plr_lframe_size = GetPlrGFXSize("LM"); } plr[pnum]._pLData = DiabloAllocPtr(plr_lframe_size); - if ( !(plr_gfx_flag & 0x20) ) {//FIRE + if (!(plr_gfx_flag & 0x20)) + { //FIRE plr_gfx_flag |= 0x20; plr_fframe_size = GetPlrGFXSize("FM"); } plr[pnum]._pFData = DiabloAllocPtr(plr_fframe_size); - if ( !(plr_gfx_flag & 0x40) ) {//MAGIC + if (!(plr_gfx_flag & 0x40)) + { //MAGIC plr_gfx_flag |= 0x40; plr_qframe_size = GetPlrGFXSize("QM"); } plr[pnum]._pTData = DiabloAllocPtr(plr_qframe_size); - if ( !(plr_gfx_flag & 0x80) ) {//DEATH + if (!(plr_gfx_flag & 0x80)) + { //DEATH plr_gfx_flag |= 0x80; plr_dframe_size = GetPlrGFXSize("DT"); } plr[pnum]._pDData = DiabloAllocPtr(plr_dframe_size); - if ( !(plr_gfx_bflag & 0x1) ) {//BLOCK + if (!(plr_gfx_bflag & 0x1)) + { //BLOCK plr_gfx_bflag |= 0x1; plr_bframe_size = GetPlrGFXSize("BL"); } @@ -319,23 +352,28 @@ void __fastcall InitPlrGFXMem(int pnum) DWORD __fastcall GetPlrGFXSize(char *szCel) { - char prefix[16]; // [esp+10Ch] [ebp-24h] + 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] + void *file; // [esp+124h] [ebp-Ch] + DWORD size = 0; // [esp+11Ch] [ebp-14h] DWORD result = 0; int a = 0; int w = 0; - for (int c = 0; c < sizeof(ClassStrTbl) / sizeof(ClassStrTbl[0]); c++) { - for (a = 0; ArmourChar[a]; a++) { - for (w = 0; WepChar[w]; w++) { + for (int c = 0; c < sizeof(ClassStrTbl) / sizeof(ClassStrTbl[0]); c++) + { + for (a = 0; ArmourChar[a]; a++) + { + for (w = 0; WepChar[w]; w++) + { sprintf(prefix, "%c%c%c", CharChar[c], ArmourChar[a], WepChar[w]); sprintf(pszName, "PlrGFX\\%s\\%s\\%s%s.CL2", ClassStrTbl[c], prefix, prefix, szCel); - if ( WOpenFile(pszName, &file, TRUE) ) { + if (WOpenFile(pszName, &file, TRUE)) + { size = WGetFileSize(file, 0); WCloseFile(file); - if ( result <= size ) { + if (result <= size) + { result = size; } } @@ -350,7 +388,8 @@ void __fastcall FreePlayerGFX(int pnum) { void *ptr; - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("FreePlayerGFX: illegal player %d", pnum); } @@ -386,7 +425,8 @@ void __fastcall FreePlayerGFX(int pnum) void __fastcall NewPlrAnim(int pnum, unsigned char *Peq, int numFrames, int Delay, int width) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("NewPlrAnim: illegal player %d", pnum); } @@ -401,7 +441,8 @@ void __fastcall NewPlrAnim(int pnum, unsigned char *Peq, int numFrames, int Dela void __fastcall ClearPlrPVars(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("ClearPlrPVars: illegal player %d", pnum); } @@ -417,7 +458,8 @@ void __fastcall ClearPlrPVars(int pnum) void __fastcall SetPlrAnims(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SetPlrAnims: illegal player %d", pnum); } @@ -431,12 +473,15 @@ void __fastcall SetPlrAnims(int pnum) plr[pnum]._pDWidth = 128; plr[pnum]._pBWidth = 96; - if ( leveltype == DTYPE_TOWN ) { + if (leveltype == DTYPE_TOWN) + { plr[pnum]._pNFrames = PlrGFXAnimLens[pc][7]; plr[pnum]._pWFrames = PlrGFXAnimLens[pc][8]; plr[pnum]._pDFrames = PlrGFXAnimLens[pc][4]; plr[pnum]._pSFrames = PlrGFXAnimLens[pc][5]; - } else { + } + else + { plr[pnum]._pNFrames = PlrGFXAnimLens[pc][0]; plr[pnum]._pWFrames = PlrGFXAnimLens[pc][2]; plr[pnum]._pAFrames = PlrGFXAnimLens[pc][1]; @@ -445,46 +490,68 @@ void __fastcall SetPlrAnims(int pnum) plr[pnum]._pDFrames = PlrGFXAnimLens[pc][4]; plr[pnum]._pBFrames = PlrGFXAnimLens[pc][3]; plr[pnum]._pAFNum = PlrGFXAnimLens[pc][9]; - } plr[pnum]._pSFNum = PlrGFXAnimLens[pc][10]; int gn = plr[pnum]._pgfxnum & 0xF; - if ( pc == PC_WARRIOR ) { - if ( gn == 4 ) { - if ( leveltype != DTYPE_TOWN ) { + if (pc == PC_WARRIOR) + { + if (gn == 4) + { + if (leveltype != DTYPE_TOWN) + { plr[pnum]._pNFrames = 8; } plr[pnum]._pAWidth = 96; plr[pnum]._pAFNum = 11; - } else if ( gn == 5 ) { + } + else if (gn == 5) + { plr[pnum]._pAFrames = 20; plr[pnum]._pAFNum = 10; - } else if ( gn == 8 ) { + } + else if (gn == 8) + { plr[pnum]._pAFrames = 16; plr[pnum]._pAFNum = 11; } - } else if ( pc == PC_ROGUE ) { - if ( gn == 5 ) { + } + else if (pc == PC_ROGUE) + { + if (gn == 5) + { plr[pnum]._pAFrames = 22; plr[pnum]._pAFNum = 13; - } else if ( gn == 4 ) { + } + else if (gn == 4) + { plr[pnum]._pAFrames = 12; plr[pnum]._pAFNum = 7; - } else if ( gn == 8 ) { + } + else if (gn == 8) + { plr[pnum]._pAFrames = 16; plr[pnum]._pAFNum = 11; } - } else if ( pc == PC_SORCERER ) { + } + else if (pc == PC_SORCERER) + { plr[pnum]._pSWidth = 128; - if ( gn == 0 ) { + if (gn == 0) + { plr[pnum]._pAFrames = 20; - } else if ( gn == 1 ) { + } + else if (gn == 1) + { plr[pnum]._pAFNum = 9; - } else if ( gn == 4 ) { + } + else if (gn == 4) + { plr[pnum]._pAFrames = 20; plr[pnum]._pAFNum = 16; - } else if ( gn == 5 ) { + } + else if (gn == 5) + { plr[pnum]._pAFrames = 24; plr[pnum]._pAFNum = 16; } @@ -521,34 +588,39 @@ void __fastcall CreatePlayer(int pnum, char c) ClearPlrRVars(&plr[pnum]); SetRndSeed(GetTickCount()); - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("CreatePlayer: illegal player %d", pnum); } plr[pnum]._pClass = c; char val = StrengthTbl[c]; - if ( val < 0 ) { + if (val < 0) + { val = 0; } plr[pnum]._pStrength = val; plr[pnum]._pBaseStr = val; val = MagicTbl[c]; - if ( val < 0 ) { + if (val < 0) + { val = 0; } plr[pnum]._pMagic = val; plr[pnum]._pBaseMag = val; val = DexterityTbl[c]; - if ( val < 0 ) { + if (val < 0) + { val = 0; } plr[pnum]._pDexterity = val; plr[pnum]._pBaseDex = val; val = VitalityTbl[c]; - if ( val < 0 ) { + if (val < 0) + { val = 0; } plr[pnum]._pVitality = val; @@ -560,20 +632,24 @@ void __fastcall CreatePlayer(int pnum, char c) plr[pnum].pLvlLoad = 0; plr[pnum].pDiabloKillLevel = 0; - if ( c == PC_ROGUE ) { + if (c == PC_ROGUE) + { plr[pnum]._pDamageMod = plr[pnum]._pLevel * (plr[pnum]._pStrength + plr[pnum]._pDexterity) / 200; - } else { + } + else + { plr[pnum]._pDamageMod = plr[pnum]._pStrength * plr[pnum]._pLevel / 100; } plr[pnum]._pBaseToBlk = ToBlkTbl[c]; - plr[pnum]._pHitPoints = (val + 10) << 6; - if ( c == PC_WARRIOR ) { + if (c == PC_WARRIOR) + { plr[pnum]._pHitPoints *= 2; } - if ( c == PC_ROGUE ) { + if (c == PC_ROGUE) + { plr[pnum]._pHitPoints += plr[pnum]._pHitPoints >> 1; } @@ -583,10 +659,12 @@ void __fastcall CreatePlayer(int pnum, char c) plr[pnum]._pMaxHPBase = hp; plr[pnum]._pMana = plr[pnum]._pMagic << 6; - if ( c == PC_SORCERER ) { + if (c == PC_SORCERER) + { plr[pnum]._pMana *= 2; } - if ( c == PC_ROGUE ) { + if (c == PC_ROGUE) + { plr[pnum]._pMana += plr[pnum]._pMana >> 1; } @@ -607,50 +685,68 @@ void __fastcall CreatePlayer(int pnum, char c) plr[pnum]._pLightRad = 10; plr[pnum]._pInfraFlag = 0; - if ( c == PC_WARRIOR ) { + if (c == PC_WARRIOR) + { plr[pnum]._pAblSpells64 = (__int64)1 << (SPL_REPAIR - 1); - } else if ( c == PC_ROGUE ) { + } + else if (c == PC_ROGUE) + { plr[pnum]._pAblSpells64 = (__int64)1 << (SPL_DISARM - 1); - } else if ( c == PC_SORCERER ) { + } + else if (c == PC_SORCERER) + { plr[pnum]._pAblSpells64 = (__int64)1 << (SPL_RECHARGE - 1); } - if ( c == PC_SORCERER) { + if (c == PC_SORCERER) + { plr[pnum]._pMemSpells64 = 1; - } else { + } + else + { plr[pnum]._pMemSpells64 = 0; } int i; - for ( i = 0; i < sizeof(plr[pnum]._pSplLvl); i++ ) { + for (i = 0; i < sizeof(plr[pnum]._pSplLvl); i++) + { plr[pnum]._pSplLvl[i] = 0; } plr[pnum]._pSpellFlags = 0; - if ( plr[pnum]._pClass == PC_SORCERER ) { + if (plr[pnum]._pClass == PC_SORCERER) + { plr[pnum]._pSplLvl[1] = 2; } // interestingly, only the first three hotkeys are reset // TODO: BUGFIX: clear all 4 hotkeys instead of 3 (demo leftover) - for ( i = 0; i < 3; i++ ) { + for (i = 0; i < 3; i++) + { plr[pnum]._pSplHotKey[i] = -1; } - if ( c == PC_WARRIOR ) { + if (c == PC_WARRIOR) + { plr[pnum]._pgfxnum = 3; - } else if ( c == PC_ROGUE ) { + } + else if (c == PC_ROGUE) + { plr[pnum]._pgfxnum = 4; - } else if ( c == PC_SORCERER ) { + } + else if (c == PC_SORCERER) + { plr[pnum]._pgfxnum = 8; } - for ( i = 0; i < sizeof(plr[pnum]._pLvlVisited); i++ ) { + for (i = 0; i < sizeof(plr[pnum]._pLvlVisited); i++) + { plr[pnum]._pLvlVisited[i] = 0; } - for ( i = 0; i < 10; i++ ) { + for (i = 0; i < 10; i++) + { plr[pnum]._pSLvlVisited[i] = 0; // TODO double check size of _pSLvlVisited } @@ -668,19 +764,13 @@ void __fastcall CreatePlayer(int pnum, char c) int __fastcall CalcStatDiff(int pnum) { int c = plr[pnum]._pClass; - return MaxStats[c][ATTRIB_STR] - - plr[pnum]._pBaseStr - + MaxStats[c][ATTRIB_MAG] - - plr[pnum]._pBaseMag - + MaxStats[c][ATTRIB_DEX] - - plr[pnum]._pBaseDex - + MaxStats[c][ATTRIB_VIT] - - plr[pnum]._pBaseVit; + return MaxStats[c][ATTRIB_STR] - plr[pnum]._pBaseStr + MaxStats[c][ATTRIB_MAG] - plr[pnum]._pBaseMag + MaxStats[c][ATTRIB_DEX] - plr[pnum]._pBaseDex + MaxStats[c][ATTRIB_VIT] - plr[pnum]._pBaseVit; } void __fastcall NextPlrLevel(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("NextPlrLevel: illegal player %d", pnum); } @@ -689,9 +779,12 @@ void __fastcall NextPlrLevel(int pnum) plr[pnum]._pMaxLvl++; - if ( CalcStatDiff(pnum) < 5 ) { + if (CalcStatDiff(pnum) < 5) + { plr[pnum]._pStatPts = CalcStatDiff(pnum); - } else { + } + else + { plr[pnum]._pStatPts += 5; } @@ -700,7 +793,8 @@ void __fastcall NextPlrLevel(int pnum) char c = plr[pnum]._pClass; int hp = c == PC_SORCERER ? 64 : 128; - if ( gbMaxPlayers == 1 ) { + if (gbMaxPlayers == 1) + { hp++; } plr[pnum]._pMaxHP += hp; @@ -708,23 +802,27 @@ void __fastcall NextPlrLevel(int pnum) plr[pnum]._pMaxHPBase += hp; plr[pnum]._pHPBase = plr[pnum]._pMaxHPBase; - if ( pnum == myplr ) { + if (pnum == myplr) + { drawhpflag = TRUE; } int mana = c != PC_WARRIOR ? 128 : 64; - if ( gbMaxPlayers == 1 ) { + if (gbMaxPlayers == 1) + { mana++; } plr[pnum]._pMaxMana += mana; plr[pnum]._pMaxManaBase += mana; - if ( !(plr[pnum]._pIFlags & ISPL_NOMANA) ) { + if (!(plr[pnum]._pIFlags & ISPL_NOMANA)) + { plr[pnum]._pMana = plr[pnum]._pMaxMana; plr[pnum]._pManaBase = plr[pnum]._pMaxManaBase; } - if ( pnum == myplr ) { + if (pnum == myplr) + { drawmanaflag = TRUE; } } @@ -732,58 +830,71 @@ void __fastcall NextPlrLevel(int pnum) void __fastcall AddPlrExperience(int pnum, int lvl, int exp) { - if ( pnum != myplr ) { + if (pnum != myplr) + { return; } - if ( (DWORD)myplr >= MAX_PLRS ) { + if ((DWORD)myplr >= MAX_PLRS) + { TermMsg("AddPlrExperience: illegal player %d", myplr); } - if ( plr[myplr]._pHitPoints <= 0 ) { + if (plr[myplr]._pHitPoints <= 0) + { return; } // Adjust xp based on difference in level between player and monster exp *= 1 + ((double)lvl - plr[pnum]._pLevel) / 10; - if ( exp < 0 ) { + if (exp < 0) + { exp = 0; } // Prevent power leveling - if ( gbMaxPlayers > 1 ) { + if (gbMaxPlayers > 1) + { int powerLvlCap = plr[pnum]._pLevel < 0 ? 0 : plr[pnum]._pLevel; - if ( powerLvlCap >= 50 ) { + if (powerLvlCap >= 50) + { powerLvlCap = 50; } // cap to 1/20 of current levels xp - if ( exp >= ExpLvlsTbl[powerLvlCap] / 20 ) { + if (exp >= ExpLvlsTbl[powerLvlCap] / 20) + { exp = ExpLvlsTbl[powerLvlCap] / 20; } // cap to 200 * current level int expCap = 200 * powerLvlCap; - if ( exp >= expCap ) { + if (exp >= expCap) + { exp = expCap; } } plr[pnum]._pExperience += exp; - if ( (DWORD)plr[pnum]._pExperience > MAXEXP ) { + if ((DWORD)plr[pnum]._pExperience > MAXEXP) + { plr[pnum]._pExperience = MAXEXP; } - if ( plr[pnum]._pExperience >= ExpLvlsTbl[49] ) { + if (plr[pnum]._pExperience >= ExpLvlsTbl[49]) + { plr[pnum]._pLevel = 50; return; } // Increase player level if applicable int newLvl = 0; - while ( plr[pnum]._pExperience >= ExpLvlsTbl[newLvl] ) { + while (plr[pnum]._pExperience >= ExpLvlsTbl[newLvl]) + { newLvl++; } - if ( newLvl != plr[pnum]._pLevel ) { - for ( int i = newLvl - plr[pnum]._pLevel; i > 0; i--) { + if (newLvl != plr[pnum]._pLevel) + { + for (int i = newLvl - plr[pnum]._pLevel; i > 0; i--) + { NextPlrLevel(pnum); } } @@ -795,40 +906,49 @@ void __fastcall AddPlrExperience(int pnum, int lvl, int exp) void __fastcall AddPlrMonstExper(int lvl, int exp, char pmask) { int totplrs = 0; - for (int i = 0; i < MAX_PLRS; i++ ) { - if ( (1 << i) & pmask ) { + for (int i = 0; i < MAX_PLRS; i++) + { + if ((1 << i) & pmask) + { totplrs++; } } - if ( totplrs && (1 << myplr) & pmask ) { + if (totplrs && (1 << myplr) & pmask) + { AddPlrExperience(myplr, lvl, exp / totplrs); } } void __fastcall InitPlayer(int pnum, BOOL FirstTime) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("InitPlayer: illegal player %d", pnum); } ClearPlrRVars(&plr[pnum]); - if ( FirstTime ) { + if (FirstTime) + { plr[pnum]._pRSpell = SPL_INVALID; plr[pnum]._pSBkSpell = SPL_INVALID; plr[pnum]._pSpell = SPL_INVALID; plr[pnum]._pRSplType = RSPLTYPE_INVALID; plr[pnum]._pSplType = RSPLTYPE_INVALID; - if ((plr[pnum]._pgfxnum & 0xF) == 4) { + if ((plr[pnum]._pgfxnum & 0xF) == 4) + { plr[pnum]._pwtype = TRUE; - } else { + } + else + { plr[pnum]._pwtype = FALSE; } plr[pnum].pManaShield = 0; } - if ( plr[pnum].plrlevel == currlevel || leveldebug ) { + if (plr[pnum].plrlevel == currlevel || leveldebug) + { SetPlrAnims(pnum); @@ -839,12 +959,15 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime) ClearPlrPVars(pnum); - if ( plr[pnum]._pHitPoints >> 6 > 0 ) { + if (plr[pnum]._pHitPoints >> 6 > 0) + { plr[pnum]._pmode = PM_STAND; NewPlrAnim(pnum, plr[pnum]._pNAnim[0], plr[pnum]._pNFrames, 3, plr[pnum]._pNWidth); plr[pnum]._pAnimFrame = random(2, plr[pnum]._pNFrames - 1) + 1; plr[pnum]._pAnimCnt = random(2, 3); - } else { + } + else + { plr[pnum]._pmode = PM_DEATH; NewPlrAnim(pnum, plr[pnum]._pDAnim[0], plr[pnum]._pDFrames, 1, plr[pnum]._pDWidth); plr[pnum]._pAnimFrame = plr[pnum]._pAnimLen - 1; @@ -854,18 +977,23 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime) plr[pnum]._pdir = 0; plr[pnum]._peflag = 0; - if ( pnum == myplr ) { - if ( !FirstTime || currlevel ) { + if (pnum == myplr) + { + if (!FirstTime || currlevel) + { plr[pnum].WorldX = ViewX; plr[pnum].WorldY = ViewY; } plr[pnum]._ptargx = plr[pnum].WorldX; plr[pnum]._ptargy = plr[pnum].WorldY; - } else { + } + else + { plr[pnum]._ptargx = plr[pnum].WorldX; plr[pnum]._ptargy = plr[pnum].WorldY; DWORD i; - for ( i = 0; i < 8 && !PosOkPlayer(pnum, plrxoff2[i] + plr[pnum].WorldX, plryoff2[i] + plr[pnum].WorldY); ++i ); + for (i = 0; i < 8 && !PosOkPlayer(pnum, plrxoff2[i] + plr[pnum].WorldX, plryoff2[i] + plr[pnum].WorldY); ++i) + ; plr[pnum].WorldX += plrxoff2[i]; plr[pnum].WorldY += plryoff2[i]; } @@ -875,30 +1003,41 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime) plr[pnum].walkpath[0] = WALK_NONE; plr[pnum].destAction = ACTION_NONE; - if ( pnum == myplr ) { + if (pnum == myplr) + { plr[pnum]._plid = AddLight(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum]._pLightRad); - } else { + } + else + { plr[pnum]._plid = WALK_NONE; } plr[pnum]._pvid = AddVision(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum]._pLightRad, pnum == myplr); } - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { plr[pnum]._pAblSpells64 = 1 << (SPL_REPAIR - 1); - } else if ( plr[pnum]._pClass == PC_ROGUE ) { + } + else if (plr[pnum]._pClass == PC_ROGUE) + { plr[pnum]._pAblSpells64 = 1 << (SPL_DISARM - 1); - } else if ( plr[pnum]._pClass == PC_SORCERER ) { + } + else if (plr[pnum]._pClass == PC_SORCERER) + { plr[pnum]._pAblSpells64 = 1 << (SPL_RECHARGE - 1); } #ifdef _DEBUG - if ( debug_mode_dollar_sign && FirstTime ) { + if (debug_mode_dollar_sign && FirstTime) + { plr[pnum]._pMemSpells64 |= 1 << (SPL_TELEPORT - 1); - if ( !plr[myplr]._pSplLvl[SPL_TELEPORT] ) { + if (!plr[myplr]._pSplLvl[SPL_TELEPORT]) + { plr[myplr]._pSplLvl[SPL_TELEPORT] = 1; } } - if ( debug_mode_key_inverted_v && FirstTime ) { + if (debug_mode_key_inverted_v && FirstTime) + { plr[pnum]._pMemSpells64 = SPL_INVALID; } #endif @@ -906,7 +1045,8 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime) plr[pnum]._pNextExper = ExpLvlsTbl[plr[pnum]._pLevel]; plr[pnum]._pInvincible = FALSE; - if ( pnum == myplr ) { + if (pnum == myplr) + { deathdelay = 0; deathflag = 0; ScrollInfo._sxoff = 0; @@ -920,7 +1060,8 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime) void __cdecl InitMultiView() { - if ( (DWORD)myplr >= MAX_PLRS ) { + if ((DWORD)myplr >= MAX_PLRS) + { TermMsg("InitPlayer: illegal player %d", myplr); } @@ -930,7 +1071,8 @@ void __cdecl InitMultiView() void __fastcall InitPlayerLoc(int pnum, BOOL flag) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("InitPlayer: illegal player %d", pnum); } @@ -940,18 +1082,22 @@ void __fastcall InitPlayerLoc(int pnum, BOOL flag) USHORT *pieces = (USHORT *)dpiece_defs_map_1 + 16 * gendung_get_dpiece_num_from_coord(x, y); int i; - for ( i = 2; i < 10; i++ ) { + for (i = 2; i < 10; i++) + { bitflags |= pieces[i]; } - if ( bitflags | nSolidTable[dPiece[x][y]] | dArch[x][y] ) { + if (bitflags | nSolidTable[dPiece[x][y]] | dArch[x][y]) + { plr[pnum]._peflag = 1; } - else { + else + { plr[pnum]._peflag = 0; } - if ( flag != 1 || plr[pnum]._peflag != 1 ) { + if (flag != 1 || plr[pnum]._peflag != 1) + { return; } @@ -960,11 +1106,13 @@ void __fastcall InitPlayerLoc(int pnum, BOOL flag) bitflags = 0; pieces = (USHORT *)dpiece_defs_map_1 + 16 * gendung_get_dpiece_num_from_coord(x, y); - for ( i = 2; i < 10; i++ ) { + for (i = 2; i < 10; i++) + { bitflags |= pieces[i]; } - if ( bitflags | dArch[x][y] ) { + if (bitflags | dArch[x][y]) + { return; } @@ -973,18 +1121,21 @@ void __fastcall InitPlayerLoc(int pnum, BOOL flag) bitflags = 0; pieces = (USHORT *)dpiece_defs_map_1 + 16 * gendung_get_dpiece_num_from_coord(x, y); - for ( i = 2; i < 10; i++ ) { + for (i = 2; i < 10; i++) + { bitflags |= pieces[i]; } - if ( bitflags | dArch[x][y] ) { + if (bitflags | dArch[x][y]) + { plr[pnum]._peflag = 2; } } BOOL __fastcall SolidLoc(int x, int y) { - if ( x < 0 || y < 0 || x >= MAXDUNX || y >= MAXDUNY ) { + if (x < 0 || y < 0 || x >= MAXDUNX || y >= MAXDUNY) + { return FALSE; } @@ -993,23 +1144,27 @@ BOOL __fastcall SolidLoc(int x, int y) BOOL __fastcall PlrDirOK(int pnum, int dir) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PlrDirOK: illegal player %d", pnum); } int px = plr[pnum].WorldX + offset_x[dir]; int py = plr[pnum].WorldY + offset_y[dir]; - if ( px < 0 || !dPiece[px][py] || !PosOkPlayer(pnum, px, py) ) { + if (px < 0 || !dPiece[px][py] || !PosOkPlayer(pnum, px, py)) + { return FALSE; } BOOL isOk = TRUE; - if ( dir == DIR_E ) { + if (dir == DIR_E) + { isOk = !SolidLoc(px, py + 1) && !(dFlags[px][py + 1] & DFLAG_PLAYER); } - if ( isOk && dir == DIR_W ) { + if (isOk && dir == DIR_W) + { isOk = !SolidLoc(px + 1, py) && !(dFlags[px + 1][py] & DFLAG_PLAYER); } @@ -1018,8 +1173,10 @@ BOOL __fastcall PlrDirOK(int pnum, int dir) void __fastcall PlrClrTrans(int x, int y) { - for ( int i = y - 1; i <= y + 1; i++ ) { - for ( int j = x - 1; j <= x + 1; j++ ) { + for (int i = y - 1; i <= y + 1; i++) + { + for (int j = x - 1; j <= x + 1; j++) + { TransList[dung_map[j][i]] = 0; } } @@ -1027,12 +1184,18 @@ void __fastcall PlrClrTrans(int x, int y) void __fastcall PlrDoTrans(int x, int y) { - if ( leveltype != DTYPE_CATHEDRAL && leveltype != DTYPE_CATACOMBS ) { + if (leveltype != DTYPE_CATHEDRAL && leveltype != DTYPE_CATACOMBS) + { TransList[1] = 1; - } else { - for ( int i = y - 1; i <= y + 1; i++ ) { - for ( int j = x - 1; j <= x + 1; j++ ) { - if ( !nSolidTable[dPiece[j][i]] && dung_map[j][i] ) { + } + else + { + for (int i = y - 1; i <= y + 1; i++) + { + for (int j = x - 1; j <= x + 1; j++) + { + if (!nSolidTable[dPiece[j][i]] && dung_map[j][i]) + { TransList[dung_map[j][i]] = 1; } } @@ -1043,7 +1206,8 @@ void __fastcall PlrDoTrans(int x, int y) void __fastcall SetPlayerOld(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SetPlayerOld: illegal player %d", pnum); } @@ -1053,7 +1217,8 @@ void __fastcall SetPlayerOld(int pnum) void __fastcall FixPlayerLocation(int pnum, int dir) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("FixPlayerLocation: illegal player %d", pnum); } @@ -1065,7 +1230,8 @@ void __fastcall FixPlayerLocation(int pnum, int dir) plr[pnum]._pyoff = 0; InitPlayerLoc(pnum, FALSE); plr[pnum]._pdir = dir; - if ( pnum == myplr ) { + if (pnum == myplr) + { ScrollInfo._sxoff = 0; ScrollInfo._syoff = 0; ScrollInfo._sdir = 0; @@ -1076,12 +1242,15 @@ void __fastcall FixPlayerLocation(int pnum, int dir) void __fastcall StartStand(int pnum, int dir) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartStand: illegal player %d", pnum); } - if ( !plr[pnum]._pInvincible || plr[pnum]._pHitPoints || pnum != myplr ) { - if ( !(plr[pnum]._pGFXLoad & PFILE_STAND) ) { + if (!plr[pnum]._pInvincible || plr[pnum]._pHitPoints || pnum != myplr) + { + if (!(plr[pnum]._pGFXLoad & PFILE_STAND)) + { LoadPlrGFX(pnum, PFILE_STAND); } @@ -1091,14 +1260,17 @@ void __fastcall StartStand(int pnum, int dir) FixPlrWalkTags(pnum); dPlayer[plr[pnum].WorldX][plr[pnum].WorldY] = pnum + 1; SetPlayerOld(pnum); - } else { + } + else + { SyncPlrKill(pnum, -1); } } void __fastcall StartWalkStand(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartWalkStand: illegal player %d", pnum); } @@ -1110,7 +1282,8 @@ void __fastcall StartWalkStand(int pnum) InitPlayerLoc(pnum, 0); - if ( pnum == myplr ) { + if (pnum == myplr) + { ScrollInfo._sxoff = 0; ScrollInfo._syoff = 0; ScrollInfo._sdir = 0; @@ -1121,24 +1294,24 @@ void __fastcall StartWalkStand(int pnum) void __fastcall PM_ChangeLightOff(int pnum) { - int v1; // esi - int v2; // esi - signed int v3; // ebx - int v4; // edi - int v5; // edx + int v1; // esi + int v2; // esi + signed int v3; // ebx + int v4; // edi + int v5; // edx LightListStruct *v6; // eax - int v7; // ecx - int v8; // edx - signed int v9; // edi - int v10; // ebx - int v11; // edx - int v12; // ecx - int v13; // ebp - int ly; // [esp+10h] [ebp-Ch] - int lx; // [esp+18h] [ebp-4h] + int v7; // ecx + int v8; // edx + signed int v9; // edi + int v10; // ebx + int v11; // edx + int v12; // ecx + int v13; // ebp + int ly; // [esp+10h] [ebp-Ch] + int lx; // [esp+18h] [ebp-4h] v1 = pnum; - if ( (unsigned int)pnum >= MAX_PLRS ) + if ((unsigned int)pnum >= MAX_PLRS) TermMsg("PM_ChangeLightOff: illegal player %d", pnum); v2 = v1; v3 = -1; @@ -1147,7 +1320,7 @@ void __fastcall PM_ChangeLightOff(int pnum) v6 = &LightList[plr[v2]._plid]; v7 = v4 + v5; v8 = v5 - v4; - if ( v7 >= 0 ) + if (v7 >= 0) { v9 = 1; } @@ -1156,7 +1329,7 @@ void __fastcall PM_ChangeLightOff(int pnum) v9 = -1; v7 = -v7; } - if ( v8 >= 0 ) + if (v8 >= 0) v3 = 1; else v8 = -v8; @@ -1166,13 +1339,14 @@ void __fastcall PM_ChangeLightOff(int pnum) lx = v9 * (v7 >> 3); v12 = 8 * v6->_lx; v13 = v11 + v6->_yoff; - if ( abs(lx - v6->_xoff) >= 3 || abs(ly - v13) >= 3 ) + if (abs(lx - v6->_xoff) >= 3 || abs(ly - v13) >= 3) ChangeLightOff(plr[v2]._plid, lx, v10); } void __fastcall PM_ChangeOffset(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_ChangeOffset: illegal player %d", pnum); } @@ -1185,7 +1359,8 @@ void __fastcall PM_ChangeOffset(int pnum) plr[pnum]._pxoff = plr[pnum]._pVar6 >> 8; plr[pnum]._pyoff = plr[pnum]._pVar7 >> 8; - if ( pnum == myplr && ScrollInfo._sdir ) { + if (pnum == myplr && ScrollInfo._sdir) + { ScrollInfo._sxoff += px - plr[pnum]._pxoff; ScrollInfo._syoff += py - plr[pnum]._pyoff; } @@ -1194,11 +1369,13 @@ void __fastcall PM_ChangeOffset(int pnum) void __fastcall StartWalk(int pnum, int xvel, int yvel, int xadd, int yadd, int EndDir, int sdir) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartWalk: illegal player %d", pnum); } - if ( plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr ) { + if (plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr) + { SyncPlrKill(pnum, -1); return; } @@ -1208,14 +1385,16 @@ void __fastcall StartWalk(int pnum, int xvel, int yvel, int xadd, int yadd, int int px = xadd + plr[pnum].WorldX; int py = yadd + plr[pnum].WorldY; - if ( !PlrDirOK(pnum, EndDir) ) { + if (!PlrDirOK(pnum, EndDir)) + { return; } plr[pnum]._px = px; plr[pnum]._py = py; - if ( pnum == myplr ) { + if (pnum == myplr) + { ScrollInfo._sdx = plr[pnum].WorldX - ViewX; ScrollInfo._sdy = plr[pnum].WorldY - ViewY; } @@ -1230,7 +1409,8 @@ void __fastcall StartWalk(int pnum, int xvel, int yvel, int xadd, int yadd, int plr[pnum]._pVar2 = yadd; plr[pnum]._pVar3 = EndDir; - if ( !(plr[pnum]._pGFXLoad & PFILE_WALK) ) { + if (!(plr[pnum]._pGFXLoad & PFILE_WALK)) + { LoadPlrGFX(pnum, PFILE_WALK); } NewPlrAnim(pnum, plr[pnum]._pWAnim[EndDir], plr[pnum]._pWFrames, 0, plr[pnum]._pWWidth); @@ -1242,19 +1422,28 @@ void __fastcall StartWalk(int pnum, int xvel, int yvel, int xadd, int yadd, int InitPlayerLoc(pnum, FALSE); - if ( pnum != myplr ) { + if (pnum != myplr) + { return; } - if ( zoomflag ) { - if ( abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3 ) { + if (zoomflag) + { + if (abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3) + { ScrollInfo._sdir = 0; - } else { + } + else + { ScrollInfo._sdir = sdir; } - } else if ( abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2 ) { + } + else if (abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2) + { ScrollInfo._sdir = 0; - } else { + } + else + { ScrollInfo._sdir = sdir; } } @@ -1262,11 +1451,13 @@ void __fastcall StartWalk(int pnum, int xvel, int yvel, int xadd, int yadd, int void __fastcall StartWalk2(int pnum, int xvel, int yvel, int xoff, int yoff, int xadd, int yadd, int EndDir, int sdir) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartWalk2: illegal player %d", pnum); } - if ( plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr ) { + if (plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr) + { SyncPlrKill(pnum, -1); return; } @@ -1275,14 +1466,16 @@ void __fastcall StartWalk2(int pnum, int xvel, int yvel, int xoff, int yoff, int int px = xadd + plr[pnum].WorldX; int py = yadd + plr[pnum].WorldY; - if ( !PlrDirOK(pnum, EndDir) ) { + if (!PlrDirOK(pnum, EndDir)) + { return; } plr[pnum]._px = px; plr[pnum]._py = py; - if ( pnum == myplr ) { + if (pnum == myplr) + { ScrollInfo._sdx = plr[pnum].WorldX - ViewX; ScrollInfo._sdy = plr[pnum].WorldY - ViewY; } @@ -1306,7 +1499,8 @@ void __fastcall StartWalk2(int pnum, int xvel, int yvel, int xoff, int yoff, int plr[pnum]._pVar7 = yoff << 8; plr[pnum]._pVar3 = EndDir; - if ( !(plr[pnum]._pGFXLoad & PFILE_WALK) ) { + if (!(plr[pnum]._pGFXLoad & PFILE_WALK)) + { LoadPlrGFX(pnum, PFILE_WALK); } NewPlrAnim(pnum, plr[pnum]._pWAnim[EndDir], plr[pnum]._pWFrames, 0, plr[pnum]._pWWidth); @@ -1314,25 +1508,37 @@ void __fastcall StartWalk2(int pnum, int xvel, int yvel, int xoff, int yoff, int plr[pnum]._pdir = EndDir; plr[pnum]._pVar8 = 0; - if ( EndDir == DIR_SE ) { + if (EndDir == DIR_SE) + { InitPlayerLoc(pnum, TRUE); - } else { + } + else + { InitPlayerLoc(pnum, FALSE); } - if ( pnum != myplr ) { + if (pnum != myplr) + { return; } - if ( zoomflag ) { - if ( abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3 ) { + if (zoomflag) + { + if (abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3) + { ScrollInfo._sdir = 0; - } else { + } + else + { ScrollInfo._sdir = sdir; } - } else if ( abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2 ) { + } + else if (abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2) + { ScrollInfo._sdir = 0; - } else { + } + else + { ScrollInfo._sdir = sdir; } } @@ -1340,11 +1546,13 @@ void __fastcall StartWalk2(int pnum, int xvel, int yvel, int xoff, int yoff, int void __fastcall StartWalk3(int pnum, int xvel, int yvel, int xoff, int yoff, int xadd, int yadd, int mapx, int mapy, int EndDir, int sdir) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartWalk3: illegal player %d", pnum); } - if ( plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr ) { + if (plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr) + { SyncPlrKill(pnum, -1); return; } @@ -1355,14 +1563,16 @@ void __fastcall StartWalk3(int pnum, int xvel, int yvel, int xoff, int yoff, int int x = mapx + plr[pnum].WorldX; int y = mapy + plr[pnum].WorldY; - if ( !PlrDirOK(pnum, EndDir) ) { + if (!PlrDirOK(pnum, EndDir)) + { return; } plr[pnum]._px = px; plr[pnum]._py = py; - if ( pnum == myplr ) { + if (pnum == myplr) + { ScrollInfo._sdx = plr[pnum].WorldX - ViewX; ScrollInfo._sdy = plr[pnum].WorldY - ViewY; } @@ -1375,7 +1585,8 @@ void __fastcall StartWalk3(int pnum, int xvel, int yvel, int xoff, int yoff, int plr[pnum]._pxoff = xoff; plr[pnum]._pyoff = yoff; - if ( leveltype ) { + if (leveltype) + { ChangeLightXY(plr[pnum]._plid, x, y); PM_ChangeLightOff(pnum); } @@ -1389,7 +1600,8 @@ void __fastcall StartWalk3(int pnum, int xvel, int yvel, int xoff, int yoff, int plr[pnum]._pVar7 = yoff << 8; plr[pnum]._pVar3 = EndDir; - if ( !(plr[pnum]._pGFXLoad & PFILE_WALK) ) { + if (!(plr[pnum]._pGFXLoad & PFILE_WALK)) + { LoadPlrGFX(pnum, PFILE_WALK); } NewPlrAnim(pnum, plr[pnum]._pWAnim[EndDir], plr[pnum]._pWFrames, 0, plr[pnum]._pWWidth); @@ -1399,19 +1611,28 @@ void __fastcall StartWalk3(int pnum, int xvel, int yvel, int xoff, int yoff, int InitPlayerLoc(pnum, 0); - if ( pnum != myplr ) { + if (pnum != myplr) + { return; } - if ( zoomflag ) { - if ( abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3 ) { + if (zoomflag) + { + if (abs(ScrollInfo._sdx) >= 3 || abs(ScrollInfo._sdy) >= 3) + { ScrollInfo._sdir = 0; - } else { + } + else + { ScrollInfo._sdir = sdir; } - } else if ( abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2 ) { + } + else if (abs(ScrollInfo._sdx) >= 2 || abs(ScrollInfo._sdy) >= 2) + { ScrollInfo._sdir = 0; - } else { + } + else + { ScrollInfo._sdir = sdir; } } @@ -1420,16 +1641,19 @@ void __fastcall StartWalk3(int pnum, int xvel, int yvel, int xoff, int yoff, int void __fastcall StartAttack(int pnum, int d) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartAttack: illegal player %d", pnum); } - if ( plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr ) { + if (plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr) + { SyncPlrKill(pnum, -1); return; } - if ( !(plr[pnum]._pGFXLoad & PFILE_ATTACK) ) { + if (!(plr[pnum]._pGFXLoad & PFILE_ATTACK)) + { LoadPlrGFX(pnum, PFILE_ATTACK); } @@ -1441,16 +1665,19 @@ void __fastcall StartAttack(int pnum, int d) void __fastcall StartRangeAttack(int pnum, int d, int cx, int cy) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartRangeAttack: illegal player %d", pnum); } - if ( plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr ) { + if (plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr) + { SyncPlrKill(pnum, -1); return; } - if ( !(plr[pnum]._pGFXLoad & PFILE_ATTACK) ) { + if (!(plr[pnum]._pGFXLoad & PFILE_ATTACK)) + { LoadPlrGFX(pnum, PFILE_ATTACK); } NewPlrAnim(pnum, plr[pnum]._pAAnim[d], plr[pnum]._pAFrames, 0, plr[pnum]._pAWidth); @@ -1464,18 +1691,21 @@ void __fastcall StartRangeAttack(int pnum, int d, int cx, int cy) void __fastcall StartPlrBlock(int pnum, int dir) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartPlrBlock: illegal player %d", pnum); } - if ( plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr ) { + if (plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr) + { SyncPlrKill(pnum, -1); return; } PlaySfxLoc(IS_ISWORD, plr[pnum].WorldX, plr[pnum].WorldY); - if ( !(plr[pnum]._pGFXLoad & PFILE_BLOCK) ) { + if (!(plr[pnum]._pGFXLoad & PFILE_BLOCK)) + { LoadPlrGFX(pnum, PFILE_BLOCK); } NewPlrAnim(pnum, plr[pnum]._pBAnim[dir], plr[pnum]._pBFrames, 2, plr[pnum]._pBWidth); @@ -1487,35 +1717,40 @@ void __fastcall StartPlrBlock(int pnum, int dir) void __fastcall StartSpell(int pnum, int d, int cx, int cy) { - if ( (DWORD)pnum >= MAX_PLRS ) + if ((DWORD)pnum >= MAX_PLRS) TermMsg("StartSpell: illegal player %d", pnum); - if ( plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr ) { + if (plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr) + { SyncPlrKill(pnum, -1); return; } - if ( leveltype != DTYPE_TOWN ) { - switch ( spelldata[plr[pnum]._pSpell].sType ) + if (leveltype != DTYPE_TOWN) + { + switch (spelldata[plr[pnum]._pSpell].sType) { - case STYPE_FIRE: - if ( !(plr[pnum]._pGFXLoad & PFILE_FIRE) ) { - LoadPlrGFX(pnum, PFILE_FIRE); - } - NewPlrAnim(pnum, plr[pnum]._pFAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth); - break; - case STYPE_LIGHTNING: - if ( !(plr[pnum]._pGFXLoad & PFILE_LIGHTNING) ) { - LoadPlrGFX(pnum, PFILE_LIGHTNING); - } - NewPlrAnim(pnum, plr[pnum]._pLAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth); - break; - case STYPE_MAGIC: - if ( !(plr[pnum]._pGFXLoad & PFILE_MAGIC) ) { - LoadPlrGFX(pnum, PFILE_MAGIC); - } - NewPlrAnim(pnum, plr[pnum]._pTAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth); - break; + case STYPE_FIRE: + if (!(plr[pnum]._pGFXLoad & PFILE_FIRE)) + { + LoadPlrGFX(pnum, PFILE_FIRE); + } + NewPlrAnim(pnum, plr[pnum]._pFAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth); + break; + case STYPE_LIGHTNING: + if (!(plr[pnum]._pGFXLoad & PFILE_LIGHTNING)) + { + LoadPlrGFX(pnum, PFILE_LIGHTNING); + } + NewPlrAnim(pnum, plr[pnum]._pLAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth); + break; + case STYPE_MAGIC: + if (!(plr[pnum]._pGFXLoad & PFILE_MAGIC)) + { + LoadPlrGFX(pnum, PFILE_MAGIC); + } + NewPlrAnim(pnum, plr[pnum]._pTAnim[d], plr[pnum]._pSFrames, 0, plr[pnum]._pSWidth); + break; } } @@ -1535,7 +1770,8 @@ void __fastcall StartSpell(int pnum, int d, int cx, int cy) void __fastcall FixPlrWalkTags(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("FixPlrWalkTags: illegal player %d", pnum); } @@ -1543,15 +1779,19 @@ void __fastcall FixPlrWalkTags(int pnum) int pn = -(pnum + 1); int dx = plr[pnum]._poldx; int dy = plr[pnum]._poldy; - for ( int y = dy - 1; y <= dy + 1; y++ ) { - for ( int x = dx - 1; x <= dx + 1; x++ ) { - if ( x >= 0 && x < MAXDUNX && y >= 0 && y < MAXDUNY && (dPlayer[x][y] == pp || dPlayer[x][y] == pn) ) { + for (int y = dy - 1; y <= dy + 1; y++) + { + for (int x = dx - 1; x <= dx + 1; x++) + { + if (x >= 0 && x < MAXDUNX && y >= 0 && y < MAXDUNY && (dPlayer[x][y] == pp || dPlayer[x][y] == pn)) + { dPlayer[x][y] = 0; } } } - if ( dx >= 0 && dx < MAXDUNX - 1 && dy >= 0 && dy < MAXDUNY -1 ) { + if (dx >= 0 && dx < MAXDUNX - 1 && dy >= 0 && dy < MAXDUNY - 1) + { dFlags[dx + 1][dy] &= ~DFLAG_PLAYER; dFlags[dx][dy + 1] &= ~DFLAG_PLAYER; } @@ -1563,42 +1803,51 @@ void __fastcall RemovePlrFromMap(int pnum) int pp = pnum + 1; int pn = -(pnum + 1); - for(y = 1; y < MAXDUNY; y++) - for(x = 1; x < MAXDUNX; x++) - if(dPlayer[x][y-1] == pn || dPlayer[x-1][y] == pn) - if(dFlags[x][y] & DFLAG_PLAYER) + for (y = 1; y < MAXDUNY; y++) + for (x = 1; x < MAXDUNX; x++) + if (dPlayer[x][y - 1] == pn || dPlayer[x - 1][y] == pn) + if (dFlags[x][y] & DFLAG_PLAYER) dFlags[x][y] &= ~DFLAG_PLAYER; - for(y = 0; y < MAXDUNY; y++) - for(x = 0; x < MAXDUNX; x++) - if(dPlayer[x][y] == pp || dPlayer[x][y] == pn) + for (y = 0; y < MAXDUNY; y++) + for (x = 0; x < MAXDUNX; x++) + if (dPlayer[x][y] == pp || dPlayer[x][y] == pn) dPlayer[x][y] = 0; } void __fastcall StartPlrHit(int pnum, int dam, BOOL forcehit) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartPlrHit: illegal player %d", pnum); } - if ( plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr ) { + if (plr[pnum]._pInvincible && !plr[pnum]._pHitPoints && pnum == myplr) + { SyncPlrKill(pnum, -1); return; } - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { PlaySfxLoc(PS_WARR69, plr[pnum].WorldX, plr[pnum].WorldY); - } else if ( plr[pnum]._pClass == PC_ROGUE ) { + } + else if (plr[pnum]._pClass == PC_ROGUE) + { PlaySfxLoc(PS_ROGUE69, plr[pnum].WorldX, plr[pnum].WorldY); - } else if ( plr[pnum]._pClass == PC_SORCERER ) { + } + else if (plr[pnum]._pClass == PC_SORCERER) + { PlaySfxLoc(PS_MAGE69, plr[pnum].WorldX, plr[pnum].WorldY); } drawhpflag = TRUE; - if ( dam >> 6 >= plr[pnum]._pLevel || forcehit ) { + if (dam >> 6 >= plr[pnum]._pLevel || forcehit) + { int dir = plr[pnum]._pdir; - if ( !(plr[pnum]._pGFXLoad & PFILE_HIT) ) { + if (!(plr[pnum]._pGFXLoad & PFILE_HIT)) + { LoadPlrGFX(pnum, PFILE_HIT); } NewPlrAnim(pnum, plr[pnum]._pHAnim[dir], plr[pnum]._pHFrames, 0, plr[pnum]._pHWidth); @@ -1615,14 +1864,14 @@ void __fastcall StartPlrHit(int pnum, int dam, BOOL forcehit) void __fastcall RespawnDeadItem(ItemStruct *itm, int x, int y) { ItemStruct *v3; // ebx - int v4; // eax - int i; // ST10_4 + int v4; // eax + int i; // ST10_4 //unsigned int v6; // ecx v3 = itm; - if ( numitems < MAXITEMS ) + if (numitems < MAXITEMS) { - if ( FindGetItem(itm->IDidx, itm->_iCreateInfo, itm->_iSeed) >= 0 ) + if (FindGetItem(itm->IDidx, itm->_iCreateInfo, itm->_iSeed) >= 0) { DrawInvMsg("A duplicate item has been detected. Destroying duplicate..."); SyncGetItem(x, y, v3->IDidx, v3->_iCreateInfo, v3->_iSeed); @@ -1645,35 +1894,45 @@ void __fastcall RespawnDeadItem(ItemStruct *itm, int x, int y) void __fastcall StartPlayerKill(int pnum, int earflag) { - if ( plr[pnum]._pHitPoints <= 0 && plr[pnum]._pmode == PM_DEATH ) { + if (plr[pnum]._pHitPoints <= 0 && plr[pnum]._pmode == PM_DEATH) + { return; } - if ( myplr == pnum ) { + if (myplr == pnum) + { NetSendCmdParam1(TRUE, CMD_PLRDEAD, earflag); } BOOL diablolevel = gbMaxPlayers > 1 && plr[pnum].plrlevel == 16; - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartPlayerKill: illegal player %d", pnum); } - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { PlaySfxLoc(PS_DEAD, plr[pnum].WorldX, plr[pnum].WorldY); // BUGFIX: should use `PS_WARR71` like other classes - } else if ( plr[pnum]._pClass == PC_ROGUE ) { + } + else if (plr[pnum]._pClass == PC_ROGUE) + { PlaySfxLoc(PS_ROGUE71, plr[pnum].WorldX, plr[pnum].WorldY); - } else if ( plr[pnum]._pClass == PC_SORCERER ) { + } + else if (plr[pnum]._pClass == PC_SORCERER) + { PlaySfxLoc(PS_MAGE71, plr[pnum].WorldX, plr[pnum].WorldY); } - if ( plr[pnum]._pgfxnum ) { + if (plr[pnum]._pgfxnum) + { plr[pnum]._pgfxnum = 0; plr[pnum]._pGFXLoad = 0; SetPlrAnims(pnum); } - if ( !(plr[pnum]._pGFXLoad & PFILE_DEATH) ) { + if (!(plr[pnum]._pGFXLoad & PFILE_DEATH)) + { LoadPlrGFX(pnum, PFILE_DEATH); } @@ -1687,40 +1946,53 @@ void __fastcall StartPlayerKill(int pnum, int earflag) plr[pnum]._pVar8 = 1; int i; - if ( pnum != myplr && !earflag && !diablolevel ) { - for ( i = 0; i < NUM_INVLOC; i++ ) { + if (pnum != myplr && !earflag && !diablolevel) + { + for (i = 0; i < NUM_INVLOC; i++) + { plr[pnum].InvBody[i]._itype = ITYPE_NONE; } CalcPlrInv(pnum, 0); } - if ( plr[pnum].plrlevel == currlevel ) { + if (plr[pnum].plrlevel == currlevel) + { FixPlayerLocation(pnum, plr[pnum]._pdir); RemovePlrFromMap(pnum); dFlags[plr[pnum].WorldX][plr[pnum].WorldY] |= DFLAG_DEAD_PLAYER; SetPlayerOld(pnum); - if ( pnum == myplr ) { + if (pnum == myplr) + { drawhpflag = TRUE; deathdelay = 30; - if ( pcurs >= CURSOR_FIRSTITEM ) { + if (pcurs >= CURSOR_FIRSTITEM) + { PlrDeadItem(pnum, &plr[pnum].HoldItem, 0, 0); SetCursor(CURSOR_HAND); } - if ( !diablolevel ) { + if (!diablolevel) + { DropHalfPlayersGold(pnum); - if ( earflag != -1 ) { - if ( earflag != 0 ) { + if (earflag != -1) + { + if (earflag != 0) + { ItemStruct ear; SetPlrHandItem(&ear, IDI_EAR); sprintf(ear._iName, "Ear of %s", plr[pnum]._pName); - if ( plr[pnum]._pClass == PC_SORCERER ) { + if (plr[pnum]._pClass == PC_SORCERER) + { ear._iCurs = ICURS_EAR_SORCEROR; - } else if ( plr[pnum]._pClass == PC_WARRIOR ) { + } + else if (plr[pnum]._pClass == PC_WARRIOR) + { ear._iCurs = ICURS_EAR_WARRIOR; - } else if ( plr[pnum]._pClass == PC_ROGUE ) { + } + else if (plr[pnum]._pClass == PC_ROGUE) + { ear._iCurs = ICURS_EAR_ROGUE; } @@ -1728,13 +2000,17 @@ void __fastcall StartPlayerKill(int pnum, int earflag) ear._iSeed = plr[pnum]._pName[2] << 24 | plr[pnum]._pName[3] << 16 | plr[pnum]._pName[4] << 8 | plr[pnum]._pName[5]; ear._ivalue = plr[pnum]._pLevel; - if ( FindGetItem(IDI_EAR, ear._iCreateInfo, ear._iSeed) == -1 ) { + if (FindGetItem(IDI_EAR, ear._iCreateInfo, ear._iSeed) == -1) + { PlrDeadItem(pnum, &ear, 0, 0); } - } else { + } + else + { ItemStruct *pi = &plr[pnum].InvBody[0]; i = NUM_INVLOC; - while ( i != 0 ) { + while (i != 0) + { i--; int pdd = (i + plr[pnum]._pdir) & 7; PlrDeadItem(pnum, pi, offset_x[pdd], offset_y[pdd]); @@ -1754,39 +2030,39 @@ void __fastcall StartPlayerKill(int pnum, int earflag) void __fastcall PlrDeadItem(int pnum, struct ItemStruct *itm, int xx, int yy) { - int v4; // edi - int v5; // edi - int v6; // esi - int v7; // ebx - int v8; // eax - int v9; // ST04_4 + int v4; // edi + int v5; // edi + int v6; // esi + int v7; // ebx + int v8; // eax + int v9; // ST04_4 ItemStruct *v10; // esi - int v11; // eax - int v12; // ebx - int v13; // esi + int v11; // eax + int v12; // ebx + int v13; // esi //int v14; // eax - int v15; // edx + int v15; // edx unsigned char v16; // [esp-8h] [ebp-24h] unsigned char v17; // [esp-4h] [ebp-20h] - int x; // [esp+Ch] [ebp-10h] + int x; // [esp+Ch] [ebp-10h] ItemStruct *pItem; // [esp+10h] [ebp-Ch] - int v20; // [esp+14h] [ebp-8h] - int v21; // [esp+14h] [ebp-8h] - int v22; // [esp+18h] [ebp-4h] - int xxa; // [esp+24h] [ebp+8h] - int yya; // [esp+28h] [ebp+Ch] + int v20; // [esp+14h] [ebp-8h] + int v21; // [esp+14h] [ebp-8h] + int v22; // [esp+18h] [ebp-4h] + int xxa; // [esp+24h] [ebp+8h] + int yya; // [esp+28h] [ebp+Ch] pItem = itm; v4 = pnum; - if ( itm->_itype != -1 ) + if (itm->_itype != -1) { - if ( (unsigned int)pnum >= MAX_PLRS ) + if ((unsigned int)pnum >= MAX_PLRS) TermMsg("PlrDeadItem: illegal player %d", pnum); v5 = v4; v6 = yy + plr[v5].WorldY; v7 = xx + plr[v5].WorldX; v20 = yy + plr[v5].WorldY; - if ( (xx || yy) && (v8 = ItemSpaceOk(v7, v6), v8) ) + if ((xx || yy) && (v8 = ItemSpaceOk(v7, v6), v8)) { v9 = v6; v10 = pItem; @@ -1798,27 +2074,27 @@ void __fastcall PlrDeadItem(int pnum, struct ItemStruct *itm, int xx, int yy) { yya = -1; xxa = 1; - while ( 1 ) + while (1) { v11 = yya; v21 = yya; -LABEL_14: - if ( v11 <= xxa ) + LABEL_14: + if (v11 <= xxa) break; ++xxa; - if ( --yya <= -50 ) + if (--yya <= -50) return; } v12 = v21 + plr[v5].WorldY; v22 = yya; - while ( 1 ) + while (1) { v13 = v22 + plr[v5].WorldX; x = v22 + plr[v5].WorldX; //_LOBYTE(v14) = ItemSpaceOk(v13, v12); - if ( ItemSpaceOk(v13, v12) ) + if (ItemSpaceOk(v13, v12)) break; - if ( ++v22 > xxa ) + if (++v22 > xxa) { v11 = ++v21; goto LABEL_14; @@ -1837,15 +2113,19 @@ LABEL_14: void __fastcall DropHalfPlayersGold(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("DropHalfPlayersGold: illegal player %d", pnum); } int i; int hGold = plr[pnum]._pGold >> 1; - for ( i = 0; i < MAXBELTITEMS && hGold > 0; i++ ) { - if ( plr[pnum].SpdList[i]._itype == ITYPE_GOLD && plr[pnum].SpdList[i]._ivalue != 5000 ) { - if ( hGold < plr[pnum].SpdList[i]._ivalue ) { + for (i = 0; i < MAXBELTITEMS && hGold > 0; i++) + { + if (plr[pnum].SpdList[i]._itype == ITYPE_GOLD && plr[pnum].SpdList[i]._ivalue != 5000) + { + if (hGold < plr[pnum].SpdList[i]._ivalue) + { plr[pnum].SpdList[i]._ivalue -= hGold; SetSpdbarGoldCurs(pnum, i); SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); @@ -1854,7 +2134,9 @@ void __fastcall DropHalfPlayersGold(int pnum) plr[pnum].HoldItem._ivalue = hGold; PlrDeadItem(pnum, &plr[pnum].HoldItem, 0, 0); hGold = 0; - } else { + } + else + { hGold -= plr[pnum].SpdList[i]._ivalue; RemoveSpdBarItem(pnum, i); SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); @@ -1866,10 +2148,14 @@ void __fastcall DropHalfPlayersGold(int pnum) } } } - if ( hGold > 0 ) { - for ( i = 0; i < MAXBELTITEMS && hGold > 0; i++ ) { - if ( plr[pnum].SpdList[i]._itype == ITYPE_GOLD ) { - if ( hGold < plr[pnum].SpdList[i]._ivalue ) { + if (hGold > 0) + { + for (i = 0; i < MAXBELTITEMS && hGold > 0; i++) + { + if (plr[pnum].SpdList[i]._itype == ITYPE_GOLD) + { + if (hGold < plr[pnum].SpdList[i]._ivalue) + { plr[pnum].SpdList[i]._ivalue -= hGold; SetSpdbarGoldCurs(pnum, i); SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); @@ -1878,7 +2164,9 @@ void __fastcall DropHalfPlayersGold(int pnum) plr[pnum].HoldItem._ivalue = hGold; PlrDeadItem(pnum, &plr[pnum].HoldItem, 0, 0); hGold = 0; - } else { + } + else + { hGold -= plr[pnum].SpdList[i]._ivalue; RemoveSpdBarItem(pnum, i); SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); @@ -1892,10 +2180,14 @@ void __fastcall DropHalfPlayersGold(int pnum) } } drawpanflag = 255; - if ( hGold > 0 ) { - for ( i = 0; i < plr[pnum]._pNumInv && hGold > 0; i++ ) { - if ( plr[pnum].InvList[i]._itype == ITYPE_GOLD && plr[pnum].InvList[i]._ivalue != 5000 ) { - if ( hGold < plr[pnum].InvList[i]._ivalue ) { + if (hGold > 0) + { + for (i = 0; i < plr[pnum]._pNumInv && hGold > 0; i++) + { + if (plr[pnum].InvList[i]._itype == ITYPE_GOLD && plr[pnum].InvList[i]._ivalue != 5000) + { + if (hGold < plr[pnum].InvList[i]._ivalue) + { plr[pnum].InvList[i]._ivalue -= hGold; SetGoldCurs(pnum, i); SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); @@ -1904,7 +2196,9 @@ void __fastcall DropHalfPlayersGold(int pnum) plr[pnum].HoldItem._ivalue = hGold; PlrDeadItem(pnum, &plr[pnum].HoldItem, 0, 0); hGold = 0; - } else { + } + else + { hGold -= plr[pnum].InvList[i]._ivalue; RemoveInvItem(pnum, i); SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); @@ -1917,10 +2211,14 @@ void __fastcall DropHalfPlayersGold(int pnum) } } } - if ( hGold > 0 ) { - for ( i = 0; i < plr[pnum]._pNumInv && hGold > 0; i++ ) { - if ( plr[pnum].InvList[i]._itype == ITYPE_GOLD ) { - if ( hGold < plr[pnum].InvList[i]._ivalue ) { + if (hGold > 0) + { + for (i = 0; i < plr[pnum]._pNumInv && hGold > 0; i++) + { + if (plr[pnum].InvList[i]._itype == ITYPE_GOLD) + { + if (hGold < plr[pnum].InvList[i]._ivalue) + { plr[pnum].InvList[i]._ivalue -= hGold; SetGoldCurs(pnum, i); SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); @@ -1929,7 +2227,9 @@ void __fastcall DropHalfPlayersGold(int pnum) plr[pnum].HoldItem._ivalue = hGold; PlrDeadItem(pnum, &plr[pnum].HoldItem, 0, 0); hGold = 0; - } else { + } + else + { hGold -= plr[pnum].InvList[i]._ivalue; RemoveInvItem(pnum, i); SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD); @@ -1948,15 +2248,19 @@ void __fastcall DropHalfPlayersGold(int pnum) void __fastcall SyncPlrKill(int pnum, int earflag) { - if ( plr[pnum]._pHitPoints == 0 && currlevel == 0 ) { + if (plr[pnum]._pHitPoints == 0 && currlevel == 0) + { SetPlayerHitPoints(pnum, 64); return; } - for ( int i = 0; i < nummissiles; i++ ) { + for (int i = 0; i < nummissiles; i++) + { int ma = missileactive[i]; - if ( missile[ma]._mitype == MIS_MANASHIELD && missile[ma]._misource == pnum && missile[ma]._miDelFlag == 0 ) { - if ( earflag != -1 ) { + if (missile[ma]._mitype == MIS_MANASHIELD && missile[ma]._misource == pnum && missile[ma]._miDelFlag == 0) + { + if (earflag != -1) + { missile[ma]._miVar8 = earflag; } @@ -1970,7 +2274,8 @@ void __fastcall SyncPlrKill(int pnum, int earflag) void __fastcall RemovePlrMissiles(int pnum) { - if ( currlevel != 0 && pnum == myplr && (monster[myplr]._mx != 1 || monster[myplr]._my != 0 ) ) { + if (currlevel != 0 && pnum == myplr && (monster[myplr]._mx != 1 || monster[myplr]._my != 0)) + { 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; @@ -1978,16 +2283,20 @@ void __fastcall RemovePlrMissiles(int pnum) DeleteMonsterList(); } - for ( int mi = 0; mi < nummissiles; mi++ ) { + for (int mi = 0; mi < nummissiles; mi++) + { int am = missileactive[mi]; - if ( missile[am]._mitype == MIS_STONE && missile[am]._misource == pnum ) { + if (missile[am]._mitype == MIS_STONE && missile[am]._misource == pnum) + { monster[missile[am]._miVar2]._mmode = missile[am]._miVar1; } - if ( missile[am]._mitype == MIS_MANASHIELD && missile[am]._misource == pnum ) { + if (missile[am]._mitype == MIS_MANASHIELD && missile[am]._misource == pnum) + { ClearMissileSpot(am); DeleteMissile(am, mi); } - if ( missile[am]._mitype == MIS_ETHEREALIZE && missile[am]._misource == pnum ) { + if (missile[am]._mitype == MIS_ETHEREALIZE && missile[am]._misource == pnum) + { ClearMissileSpot(am); DeleteMissile(am, mi); } @@ -1997,16 +2306,20 @@ void __fastcall RemovePlrMissiles(int pnum) void __fastcall InitLevelChange(int pnum) { RemovePlrMissiles(pnum); - if ( pnum == myplr && qtextflag ) { + if (pnum == myplr && qtextflag) + { qtextflag = 0; sfx_stop(); } RemovePlrFromMap(pnum); SetPlayerOld(pnum); - if ( pnum == myplr ) { + if (pnum == myplr) + { dPlayer[plr[myplr].WorldX][plr[myplr].WorldY] = myplr + 1; - } else { + } + else + { plr[pnum]._pLvlVisited[plr[pnum].plrlevel] = 1; } @@ -2014,7 +2327,8 @@ void __fastcall InitLevelChange(int pnum) plr[pnum].destAction = ACTION_NONE; plr[pnum]._pLvlChanging = 1; - if ( pnum == myplr ) { + if (pnum == myplr) + { plr[pnum].pLvlLoad = 10; } } @@ -2024,38 +2338,42 @@ void __fastcall StartNewLvl(int pnum, int fom, int lvl) { InitLevelChange(pnum); - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("StartNewLvl: illegal player %d", pnum); } - switch ( fom ) { - case WM_DIABNEXTLVL: - case WM_DIABPREVLVL: - plr[pnum].plrlevel = lvl; - break; - case WM_DIABRTNLVL: - case WM_DIABTOWNWARP: - plr[pnum].plrlevel = lvl; - break; - case WM_DIABSETLVL: - setlvlnum = lvl; - break; - case WM_DIABTWARPUP: - plr[myplr].pTownWarps |= 1 << (leveltype - 2); - plr[pnum].plrlevel = lvl; - break; - case WM_DIABRETOWN: - break; - default: - TermMsg("StartNewLvl"); - break; - } - - if ( pnum == myplr ) { + switch (fom) + { + case WM_DIABNEXTLVL: + case WM_DIABPREVLVL: + plr[pnum].plrlevel = lvl; + break; + case WM_DIABRTNLVL: + case WM_DIABTOWNWARP: + plr[pnum].plrlevel = lvl; + break; + case WM_DIABSETLVL: + setlvlnum = lvl; + break; + case WM_DIABTWARPUP: + plr[myplr].pTownWarps |= 1 << (leveltype - 2); + plr[pnum].plrlevel = lvl; + break; + case WM_DIABRETOWN: + break; + default: + TermMsg("StartNewLvl"); + break; + } + + if (pnum == myplr) + { plr[pnum]._pmode = PM_NEWLVL; plr[pnum]._pInvincible = TRUE; PostMessage(ghMainWnd, fom, 0, 0); - if ( gbMaxPlayers > 1 ) { + if (gbMaxPlayers > 1) + { NetSendCmdParam2(TRUE, CMD_NEWLVL, fom, lvl); } } @@ -2067,7 +2385,8 @@ void __fastcall StartNewLvl(int pnum, int fom, int lvl) void __fastcall RestartTownLvl(int pnum) { InitLevelChange(pnum); - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("RestartTownLvl: illegal player %d", pnum); } @@ -2081,7 +2400,8 @@ void __fastcall RestartTownLvl(int pnum) CalcPlrInv(pnum, FALSE); - if ( pnum == myplr ) { + if (pnum == myplr) + { plr[pnum]._pmode = PM_NEWLVL; plr[pnum]._pInvincible = TRUE; PostMessage(ghMainWnd, WM_DIABRETOWN, 0, 0); @@ -2092,15 +2412,20 @@ void __fastcall StartWarpLvl(int pnum, int pidx) { InitLevelChange(pnum); - if ( gbMaxPlayers != 1 ) { - if ( plr[pnum].plrlevel != 0 ) { + if (gbMaxPlayers != 1) + { + if (plr[pnum].plrlevel != 0) + { plr[pnum].plrlevel = 0; - } else { + } + else + { plr[pnum].plrlevel = portal[pidx].level; } } - if ( pnum == myplr ) { + if (pnum == myplr) + { SetCurrentPortal(pidx); plr[pnum]._pmode = PM_NEWLVL; plr[pnum]._pInvincible = TRUE; @@ -2116,46 +2441,53 @@ BOOL __fastcall PM_DoStand(int pnum) BOOL __fastcall PM_DoWalk(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoWalk: illegal player %d", pnum); } - if ( plr[pnum]._pAnimFrame == 3 - || (plr[pnum]._pWFrames == 8 && plr[pnum]._pAnimFrame == 7) - || (plr[pnum]._pWFrames != 8 && plr[pnum]._pAnimFrame == 4) - ) { + if (plr[pnum]._pAnimFrame == 3 || (plr[pnum]._pWFrames == 8 && plr[pnum]._pAnimFrame == 7) || (plr[pnum]._pWFrames != 8 && plr[pnum]._pAnimFrame == 4)) + { PlaySfxLoc(PS_WALK1, plr[pnum].WorldX, plr[pnum].WorldY); } int vel = 8; - if ( currlevel ) { + if (currlevel) + { vel = PWVel[3][plr[pnum]._pClass]; } - if ( plr[pnum]._pVar8 == vel ) { + if (plr[pnum]._pVar8 == vel) + { dPlayer[plr[pnum].WorldX][plr[pnum].WorldY] = 0; plr[pnum].WorldX += plr[pnum]._pVar1; plr[pnum].WorldY += plr[pnum]._pVar2; dPlayer[plr[pnum].WorldX][plr[pnum].WorldY] = pnum + 1; - if ( leveltype != DTYPE_TOWN ) { + if (leveltype != DTYPE_TOWN) + { ChangeLightXY(plr[pnum]._plid, plr[pnum].WorldX, plr[pnum].WorldY); ChangeVisionXY(plr[pnum]._pvid, plr[pnum].WorldX, plr[pnum].WorldY); } - if ( pnum == myplr && ScrollInfo._sdir ) { + if (pnum == myplr && ScrollInfo._sdir) + { ViewX = plr[pnum].WorldX - ScrollInfo._sdx; ViewY = plr[pnum].WorldY - ScrollInfo._sdy; } - if ( plr[pnum].walkpath[0] != WALK_NONE ) { + if (plr[pnum].walkpath[0] != WALK_NONE) + { StartWalkStand(pnum); - } else { + } + else + { StartStand(pnum, plr[pnum]._pVar3); } ClearPlrPVars(pnum); - if ( leveltype != DTYPE_TOWN ) { + if (leveltype != DTYPE_TOWN) + { ChangeLightOff(plr[pnum]._plid, 0, 0); } @@ -2164,49 +2496,55 @@ BOOL __fastcall PM_DoWalk(int pnum) PM_ChangeOffset(pnum); return FALSE; - } // 5BB1ED: using guessed type char leveltype; BOOL __fastcall PM_DoWalk2(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoWalk2: illegal player %d", pnum); } - if ( plr[pnum]._pAnimFrame == 3 - || (plr[pnum]._pWFrames == 8 && plr[pnum]._pAnimFrame == 7) - || (plr[pnum]._pWFrames != 8 && plr[pnum]._pAnimFrame == 4) - ) { + if (plr[pnum]._pAnimFrame == 3 || (plr[pnum]._pWFrames == 8 && plr[pnum]._pAnimFrame == 7) || (plr[pnum]._pWFrames != 8 && plr[pnum]._pAnimFrame == 4)) + { PlaySfxLoc(PS_WALK1, plr[pnum].WorldX, plr[pnum].WorldY); } int vel = 8; - if ( currlevel ) { + if (currlevel) + { vel = PWVel[3][plr[pnum]._pClass]; } - if ( plr[pnum]._pVar8 == vel ) { + if (plr[pnum]._pVar8 == vel) + { dPlayer[plr[pnum]._pVar1][plr[pnum]._pVar2] = 0; - if ( leveltype != DTYPE_TOWN ) { + if (leveltype != DTYPE_TOWN) + { ChangeLightXY(plr[pnum]._plid, plr[pnum].WorldX, plr[pnum].WorldY); ChangeVisionXY(plr[pnum]._pvid, plr[pnum].WorldX, plr[pnum].WorldY); } - if ( pnum == myplr && ScrollInfo._sdir ) { + if (pnum == myplr && ScrollInfo._sdir) + { ViewX = plr[pnum].WorldX - ScrollInfo._sdx; ViewY = plr[pnum].WorldY - ScrollInfo._sdy; } - if ( plr[pnum].walkpath[0] != WALK_NONE ) { + if (plr[pnum].walkpath[0] != WALK_NONE) + { StartWalkStand(pnum); - } else { + } + else + { StartStand(pnum, plr[pnum]._pVar3); } ClearPlrPVars(pnum); - if ( leveltype != DTYPE_TOWN ) { + if (leveltype != DTYPE_TOWN) + { ChangeLightOff(plr[pnum]._plid, 0, 0); } @@ -2220,48 +2558,55 @@ BOOL __fastcall PM_DoWalk2(int pnum) BOOL __fastcall PM_DoWalk3(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoWalk3: illegal player %d", pnum); } - if ( plr[pnum]._pAnimFrame == 3 - || (plr[pnum]._pWFrames == 8 && plr[pnum]._pAnimFrame == 7) - || (plr[pnum]._pWFrames != 8 && plr[pnum]._pAnimFrame == 4) - ) { + if (plr[pnum]._pAnimFrame == 3 || (plr[pnum]._pWFrames == 8 && plr[pnum]._pAnimFrame == 7) || (plr[pnum]._pWFrames != 8 && plr[pnum]._pAnimFrame == 4)) + { PlaySfxLoc(PS_WALK1, plr[pnum].WorldX, plr[pnum].WorldY); } int vel = 8; - if ( currlevel ) { + if (currlevel) + { vel = PWVel[3][plr[pnum]._pClass]; } - if ( plr[pnum]._pVar8 == vel ) { + if (plr[pnum]._pVar8 == vel) + { dPlayer[plr[pnum].WorldX][plr[pnum].WorldY] = 0; dFlags[plr[pnum]._pVar4][plr[pnum]._pVar5] &= ~DFLAG_PLAYER; plr[pnum].WorldX = plr[pnum]._pVar1; plr[pnum].WorldY = plr[pnum]._pVar2; dPlayer[plr[pnum]._pVar1][plr[pnum]._pVar2] = pnum + 1; - if ( leveltype != DTYPE_TOWN ) { + if (leveltype != DTYPE_TOWN) + { ChangeLightXY(plr[pnum]._plid, plr[pnum]._pVar1, plr[pnum]._pVar2); ChangeVisionXY(plr[pnum]._pvid, plr[pnum].WorldX, plr[pnum].WorldY); } - if ( pnum == myplr && ScrollInfo._sdir ) { + if (pnum == myplr && ScrollInfo._sdir) + { ViewX = plr[pnum].WorldX - ScrollInfo._sdx; ViewY = plr[pnum].WorldY - ScrollInfo._sdy; } - if ( plr[pnum].walkpath[0] != WALK_NONE ) { + if (plr[pnum].walkpath[0] != WALK_NONE) + { StartWalkStand(pnum); - } else { + } + else + { StartStand(pnum, plr[pnum]._pVar3); } ClearPlrPVars(pnum); - if ( leveltype != DTYPE_TOWN ) { + if (leveltype != DTYPE_TOWN) + { ChangeLightOff(plr[pnum]._plid, 0, 0); } @@ -2275,25 +2620,31 @@ BOOL __fastcall PM_DoWalk3(int pnum) BOOL __fastcall WeaponDur(int pnum, int durrnd) { - if ( pnum != myplr ) { + if (pnum != myplr) + { return FALSE; } - if ( random(3, durrnd) != 0 ) { + if (random(3, durrnd) != 0) + { return FALSE; } - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("WeaponDur: illegal player %d", pnum); } - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_NONE && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON ) { - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE ) { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype != ITYPE_NONE && plr[pnum].InvBody[INVLOC_HAND_LEFT]._iClass == ICLASS_WEAPON) + { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE) + { return FALSE; } plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability--; - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == 0) { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == 0) + { NetSendCmdDelItem(TRUE, INVLOC_HAND_LEFT); plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE; CalcPlrInv(pnum, TRUE); @@ -2301,13 +2652,16 @@ BOOL __fastcall WeaponDur(int pnum, int durrnd) } } - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_NONE && plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iClass == ICLASS_WEAPON ) { - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == DUR_INDESTRUCTIBLE ) { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype != ITYPE_NONE && plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iClass == ICLASS_WEAPON) + { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == DUR_INDESTRUCTIBLE) + { return FALSE; } plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability--; - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == 0 ) { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) + { NetSendCmdDelItem(TRUE, INVLOC_HAND_RIGHT); plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE; CalcPlrInv(pnum, TRUE); @@ -2315,13 +2669,16 @@ BOOL __fastcall WeaponDur(int pnum, int durrnd) } } - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_NONE && plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD ) { - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == DUR_INDESTRUCTIBLE ) { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_NONE && plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD) + { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == DUR_INDESTRUCTIBLE) + { return FALSE; } plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability--; - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == 0 ) { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) + { NetSendCmdDelItem(TRUE, INVLOC_HAND_RIGHT); plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE; CalcPlrInv(pnum, TRUE); @@ -2329,13 +2686,16 @@ BOOL __fastcall WeaponDur(int pnum, int durrnd) } } - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_NONE && plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SHIELD ) { - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE ) { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_NONE && plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SHIELD) + { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE) + { return FALSE; } plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability--; - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == 0 ) { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == 0) + { NetSendCmdDelItem(TRUE, INVLOC_HAND_LEFT); plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE; CalcPlrInv(pnum, TRUE); @@ -2348,170 +2708,218 @@ BOOL __fastcall WeaponDur(int pnum, int durrnd) BOOL __fastcall PlrHitMonst(int pnum, int m) { - if ( (DWORD)m >= MAXMONSTERS ) { + if ((DWORD)m >= MAXMONSTERS) + { TermMsg("PlrHitMonst: illegal monster %d", m); } - if ( (monster[m]._mhitpoints >> 6) <= 0 ) { + if ((monster[m]._mhitpoints >> 6) <= 0) + { return FALSE; } - if ( monster[m].MType->mtype == MT_ILLWEAV && monster[m]._mgoal == 2 ) { + if (monster[m].MType->mtype == MT_ILLWEAV && monster[m]._mgoal == 2) + { return FALSE; } - if ( monster[m]._mmode == MM_CHARGE ) { + if (monster[m]._mmode == MM_CHARGE) + { return FALSE; } - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PlrHitMonst: illegal player %d", pnum); } BOOL rv = FALSE; int hit = random(4, 100); - if ( monster[m]._mmode == MM_STONE ) { + if (monster[m]._mmode == MM_STONE) + { hit = 0; } int hper = (plr[pnum]._pDexterity >> 1) + plr[pnum]._pLevel + 50 - (monster[m].mArmorClass - plr[pnum]._pIEnAc); - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { hper += 20; } hper += plr[pnum]._pIBonusToHit; - if ( hper < 5 ) { + if (hper < 5) + { hper = 5; } - if ( hper > 95 ) { + if (hper > 95) + { hper = 95; } BOOL ret; - if ( CheckMonsterHit(m, &ret) ) { + if (CheckMonsterHit(m, &ret)) + { return ret; } #ifdef _DEBUG - if ( hit < hper || debug_mode_key_inverted_v || debug_mode_dollar_sign ) { + if (hit < hper || debug_mode_key_inverted_v || debug_mode_dollar_sign) + { #else - if ( hit < hper ) { + if (hit < hper) + { #endif int mind = plr[pnum]._pIMinDam; int maxd = random(5, plr[pnum]._pIMaxDam - mind + 1); int dam = maxd + mind; dam += plr[pnum]._pDamageMod + plr[pnum]._pIBonusDamMod + dam * plr[pnum]._pIBonusDam / 100; - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { int lvl = plr[pnum]._pLevel; - if ( random(6, 100) < lvl ) { + if (random(6, 100) < lvl) + { dam *= 2; } } int phanditype = ITYPE_NONE; - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD || plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SWORD ) { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD || plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SWORD) + { phanditype = ITYPE_SWORD; } - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_MACE || plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_MACE ) { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_MACE || plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_MACE) + { phanditype = ITYPE_MACE; } int mClass = monster[m].MData->mMonstClass; - switch (mClass ) { - case MC_UNDEAD: - if ( phanditype == ITYPE_SWORD ) { - dam -= dam >> 1; - } - if ( phanditype == ITYPE_MACE ) { - dam += dam >> 1; - } - break; - case MC_ANIMAL: - if ( phanditype == ITYPE_MACE ) { - dam -= dam >> 1; - } - if ( phanditype == ITYPE_SWORD ) { - dam += dam >> 1; - } - break; + switch (mClass) + { + case MC_UNDEAD: + if (phanditype == ITYPE_SWORD) + { + dam -= dam >> 1; + } + if (phanditype == ITYPE_MACE) + { + dam += dam >> 1; + } + break; + case MC_ANIMAL: + if (phanditype == ITYPE_MACE) + { + dam -= dam >> 1; + } + if (phanditype == ITYPE_SWORD) + { + dam += dam >> 1; + } + break; } - if ( plr[pnum]._pIFlags & ISPL_3XDAMVDEM && monster[m].MData->mMonstClass == MC_DEMON ) { + if (plr[pnum]._pIFlags & ISPL_3XDAMVDEM && monster[m].MData->mMonstClass == MC_DEMON) + { dam *= 3; } int skdam = dam << 6; - if ( pnum == myplr ) { + if (pnum == myplr) + { monster[m]._mhitpoints -= skdam; } int tac; - if ( plr[pnum]._pIFlags & ISPL_RNDSTEALLIFE ) { + if (plr[pnum]._pIFlags & ISPL_RNDSTEALLIFE) + { tac = random(7, skdam >> 3); plr[pnum]._pHitPoints += tac; - if ( plr[pnum]._pHitPoints > plr[pnum]._pMaxHP ) { + if (plr[pnum]._pHitPoints > plr[pnum]._pMaxHP) + { plr[pnum]._pHitPoints = plr[pnum]._pMaxHP; } plr[pnum]._pHPBase += tac; - if ( plr[pnum]._pHPBase > plr[pnum]._pMaxHPBase ) { + if (plr[pnum]._pHPBase > plr[pnum]._pMaxHPBase) + { plr[pnum]._pHPBase = plr[pnum]._pMaxHPBase; } drawhpflag = TRUE; } - if ( plr[pnum]._pIFlags & (ISPL_STEALMANA_3 | ISPL_STEALMANA_5) && !(plr[pnum]._pIFlags & ISPL_NOMANA) ) { - if ( plr[pnum]._pIFlags & ISPL_STEALMANA_3 ) { + if (plr[pnum]._pIFlags & (ISPL_STEALMANA_3 | ISPL_STEALMANA_5) && !(plr[pnum]._pIFlags & ISPL_NOMANA)) + { + if (plr[pnum]._pIFlags & ISPL_STEALMANA_3) + { tac = 3 * skdam / 100; } - if ( plr[pnum]._pIFlags & ISPL_STEALMANA_5 ) { + if (plr[pnum]._pIFlags & ISPL_STEALMANA_5) + { tac = 5 * skdam / 100; } plr[pnum]._pMana += tac; - if ( plr[pnum]._pMana > plr[pnum]._pMaxMana ) { + if (plr[pnum]._pMana > plr[pnum]._pMaxMana) + { plr[pnum]._pMana = plr[pnum]._pMaxMana; } plr[pnum]._pManaBase += tac; - if ( plr[pnum]._pManaBase > plr[pnum]._pMaxManaBase ) { + if (plr[pnum]._pManaBase > plr[pnum]._pMaxManaBase) + { plr[pnum]._pManaBase = plr[pnum]._pMaxManaBase; } drawmanaflag = 1; } - if ( plr[pnum]._pIFlags & (ISPL_STEALLIFE_3 | ISPL_STEALLIFE_5) ) { - if ( plr[pnum]._pIFlags & ISPL_STEALLIFE_3 ) { + if (plr[pnum]._pIFlags & (ISPL_STEALLIFE_3 | ISPL_STEALLIFE_5)) + { + if (plr[pnum]._pIFlags & ISPL_STEALLIFE_3) + { tac = 3 * skdam / 100; } - if ( plr[pnum]._pIFlags & ISPL_STEALLIFE_5 ) { + if (plr[pnum]._pIFlags & ISPL_STEALLIFE_5) + { tac = 5 * skdam / 100; } plr[pnum]._pHitPoints += tac; - if ( plr[pnum]._pHitPoints > plr[pnum]._pMaxHP ) { + if (plr[pnum]._pHitPoints > plr[pnum]._pMaxHP) + { plr[pnum]._pHitPoints = plr[pnum]._pMaxHP; } plr[pnum]._pHPBase += tac; - if ( plr[pnum]._pHPBase > plr[pnum]._pMaxHPBase ) { + if (plr[pnum]._pHPBase > plr[pnum]._pMaxHPBase) + { plr[pnum]._pHPBase = plr[pnum]._pMaxHPBase; } drawhpflag = TRUE; } - if ( plr[pnum]._pIFlags & ISPL_NOHEALPLR ) { + if (plr[pnum]._pIFlags & ISPL_NOHEALPLR) + { monster[m]._mFlags |= 8; } #ifdef _DEBUG - if ( debug_mode_dollar_sign || debug_mode_key_inverted_v ) { + if (debug_mode_dollar_sign || debug_mode_key_inverted_v) + { monster[m]._mhitpoints = 0; /* double check */ } #endif - if ( (monster[m]._mhitpoints >> 6) <= 0) { - if ( monster[m]._mmode == MM_STONE ) { + if ((monster[m]._mhitpoints >> 6) <= 0) + { + if (monster[m]._mmode == MM_STONE) + { M_StartKill(m, pnum); monster[m]._mmode = MM_STONE; - } else { + } + else + { M_StartKill(m, pnum); } - } else { - if ( monster[m]._mmode == MM_STONE ) { + } + else + { + if (monster[m]._mmode == MM_STONE) + { M_StartHit(m, pnum, skdam); monster[m]._mmode = MM_STONE; - } else { - if ( plr[pnum]._pIFlags & ISPL_KNOCKBACK ) { + } + else + { + if (plr[pnum]._pIFlags & ISPL_KNOCKBACK) + { M_GetKnockback(m); } M_StartHit(m, pnum, skdam); @@ -2525,21 +2933,25 @@ BOOL __fastcall PlrHitMonst(int pnum, int m) BOOL __fastcall PlrHitPlr(int pnum, char p) { - if ( (DWORD)p >= MAX_PLRS ) { + if ((DWORD)p >= MAX_PLRS) + { TermMsg("PlrHitPlr: illegal target player %d", p); } BOOL rv = FALSE; - if ( plr[p]._pInvincible ) { + if (plr[p]._pInvincible) + { return rv; } - if ( plr[p]._pSpellFlags & 1 ) { + if (plr[p]._pSpellFlags & 1) + { return rv; } - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PlrHitPlr: illegal attacking player %d", pnum); } @@ -2547,62 +2959,80 @@ BOOL __fastcall PlrHitPlr(int pnum, char p) int hper = (plr[pnum]._pDexterity >> 1) + plr[pnum]._pLevel + 50 - (plr[p]._pIBonusAC + plr[p]._pIAC + plr[p]._pDexterity / 5); - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { hper += 20; } hper += plr[pnum]._pIBonusToHit; - if ( hper < 5 ) { + if (hper < 5) + { hper = 5; } - if ( hper > 95 ) { + if (hper > 95) + { hper = 95; } int blk; - if ( (plr[p]._pmode == PM_STAND || plr[p]._pmode == PM_ATTACK) && plr[p]._pBlockFlag ) { + if ((plr[p]._pmode == PM_STAND || plr[p]._pmode == PM_ATTACK) && plr[p]._pBlockFlag) + { blk = random(5, 100); - } else { + } + else + { blk = 100; } int blkper = plr[p]._pDexterity + plr[p]._pBaseToBlk + (plr[p]._pLevel << 1) - (plr[pnum]._pLevel << 1); - if ( blkper < 0 ) { + if (blkper < 0) + { blkper = 0; } - if ( blkper > 100 ) { + if (blkper > 100) + { blkper = 100; } - if ( hit < hper ) { - if ( blk < blkper ) { + if (hit < hper) + { + if (blk < blkper) + { int dir = GetDirection(plr[p].WorldX, plr[p].WorldY, plr[pnum].WorldX, plr[pnum].WorldY); StartPlrBlock(p, dir); - } else { + } + else + { int mind = plr[pnum]._pIMinDam; int maxd = random(5, plr[pnum]._pIMaxDam - mind + 1); int dam = maxd + mind; dam += plr[pnum]._pDamageMod + plr[pnum]._pIBonusDamMod + dam * plr[pnum]._pIBonusDam / 100; - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { int lvl = plr[pnum]._pLevel; - if ( random(6, 100) < lvl) { + if (random(6, 100) < lvl) + { dam *= 2; } } int skdam = dam << 6; - if ( plr[pnum]._pIFlags & ISPL_RNDSTEALLIFE ) { + if (plr[pnum]._pIFlags & ISPL_RNDSTEALLIFE) + { int tac = random(7, skdam >> 3); plr[pnum]._pHitPoints += tac; - if ( plr[pnum]._pHitPoints > plr[pnum]._pMaxHP ) { + if (plr[pnum]._pHitPoints > plr[pnum]._pMaxHP) + { plr[pnum]._pHitPoints = plr[pnum]._pMaxHP; } plr[pnum]._pHPBase += tac; - if ( plr[pnum]._pHPBase > plr[pnum]._pMaxHPBase ) { + if (plr[pnum]._pHPBase > plr[pnum]._pMaxHPBase) + { plr[pnum]._pHPBase = plr[pnum]._pMaxHPBase; } drawhpflag = TRUE; } - if ( pnum == myplr ) { + if (pnum == myplr) + { NetSendCmdDamage(TRUE, p, skdam); } StartPlrHit(p, skdam, FALSE); @@ -2618,13 +3048,17 @@ BOOL __fastcall PlrHitObj(int pnum, int mx, int my) { int oi; - if ( dObject[mx][my] > 0 ) { + if (dObject[mx][my] > 0) + { oi = dObject[mx][my] - 1; - } else { + } + else + { oi = -dObject[mx][my] - 1; } - if ( object[oi]._oBreak == 1 ) { + if (object[oi]._oBreak == 1) + { BreakObject(pnum, oi); return TRUE; } @@ -2634,85 +3068,114 @@ BOOL __fastcall PlrHitObj(int pnum, int mx, int my) BOOL __fastcall PM_DoAttack(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoAttack: illegal player %d", pnum); } int frame = plr[pnum]._pAnimFrame; - if ( plr[pnum]._pIFlags & ISPL_QUICKATTACK && frame == 1 ) { + if (plr[pnum]._pIFlags & ISPL_QUICKATTACK && frame == 1) + { plr[pnum]._pAnimFrame++; } - if ( plr[pnum]._pIFlags & ISPL_FASTATTACK && (frame == 1 || frame == 3) ) { + if (plr[pnum]._pIFlags & ISPL_FASTATTACK && (frame == 1 || frame == 3)) + { plr[pnum]._pAnimFrame++; } - if ( plr[pnum]._pIFlags & ISPL_FASTERATTACK && (frame == 1 || frame == 3 || frame == 5) ) { + if (plr[pnum]._pIFlags & ISPL_FASTERATTACK && (frame == 1 || frame == 3 || frame == 5)) + { plr[pnum]._pAnimFrame++; } - if ( plr[pnum]._pIFlags & ISPL_FASTESTATTACK && (frame == 1 || frame == 4) ) { + if (plr[pnum]._pIFlags & ISPL_FASTESTATTACK && (frame == 1 || frame == 4)) + { plr[pnum]._pAnimFrame += 2; } - if ( plr[pnum]._pAnimFrame == plr[pnum]._pAFNum - 1 ) { + if (plr[pnum]._pAnimFrame == plr[pnum]._pAFNum - 1) + { PlaySfxLoc(PS_SWING, plr[pnum].WorldX, plr[pnum].WorldY); } - if ( plr[pnum]._pAnimFrame == plr[pnum]._pAFNum ) { + if (plr[pnum]._pAnimFrame == plr[pnum]._pAFNum) + { int dir = plr[pnum]._pdir; int dx = plr[pnum].WorldX + offset_x[dir]; int dy = plr[pnum].WorldY + offset_y[dir]; int m; - if (dMonster[dx][dy]) { - if ( dMonster[dx][dy] > 0 ) { + if (dMonster[dx][dy]) + { + if (dMonster[dx][dy] > 0) + { m = dMonster[dx][dy] - 1; - } else { + } + else + { m = -(dMonster[dx][dy] + 1); } - if ( CanTalkToMonst(m) ) { + if (CanTalkToMonst(m)) + { plr[pnum]._pVar1 = 0; return FALSE; } } - if ( plr[pnum]._pIFlags & ISPL_FIREDAM ) { + if (plr[pnum]._pIFlags & ISPL_FIREDAM) + { AddMissile(dx, dy, 1, 0, 0, MIS_WEAPEXP, 0, pnum, 0, 0); } - if ( plr[pnum]._pIFlags & ISPL_LIGHTDAM ) { + if (plr[pnum]._pIFlags & ISPL_LIGHTDAM) + { AddMissile(dx, dy, 2, 0, 0, MIS_WEAPEXP, 0, pnum, 0, 0); } BOOL didhit = FALSE; - if ( dMonster[dx][dy] ) { + if (dMonster[dx][dy]) + { m = dMonster[dx][dy]; - if ( dMonster[dx][dy] > 0 ) { + if (dMonster[dx][dy] > 0) + { m = dMonster[dx][dy] - 1; - } else { + } + else + { m = -(dMonster[dx][dy] + 1); } didhit = PlrHitMonst(pnum, m); - } else if ( dPlayer[dx][dy] && !FriendlyMode ) { + } + else if (dPlayer[dx][dy] && !FriendlyMode) + { UCHAR p = dPlayer[dx][dy]; - if ( dPlayer[dx][dy] > 0 ) { + if (dPlayer[dx][dy] > 0) + { p = dPlayer[dx][dy] - 1; - } else { + } + else + { p = -(dPlayer[dx][dy] + 1); } didhit = PlrHitPlr(pnum, p); - } else if ( dObject[dx][dy] > 0 ) { + } + else if (dObject[dx][dy] > 0) + { didhit = PlrHitObj(pnum, dx, dy); } - if ( didhit && WeaponDur(pnum, 30) ) { + if (didhit && WeaponDur(pnum, 30)) + { StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); return TRUE; } } - if ( plr[pnum]._pAnimFrame == plr[pnum]._pAFrames ) { + if (plr[pnum]._pAnimFrame == plr[pnum]._pAFrames) + { StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); return TRUE; - } else { + } + else + { return FALSE; } } @@ -2720,24 +3183,30 @@ BOOL __fastcall PM_DoAttack(int pnum) BOOL __fastcall PM_DoRangeAttack(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoRangeAttack: illegal player %d", pnum); } int origFrame = plr[pnum]._pAnimFrame; - if ( plr[pnum]._pIFlags & ISPL_QUICKATTACK && origFrame == 1 ) { + if (plr[pnum]._pIFlags & ISPL_QUICKATTACK && origFrame == 1) + { plr[pnum]._pAnimFrame++; } - if ( plr[pnum]._pIFlags & ISPL_FASTATTACK && (origFrame == 1 || origFrame == 3) ) { + if (plr[pnum]._pIFlags & ISPL_FASTATTACK && (origFrame == 1 || origFrame == 3)) + { plr[pnum]._pAnimFrame++; } - if ( plr[pnum]._pAnimFrame == plr[pnum]._pAFNum ) { + if (plr[pnum]._pAnimFrame == plr[pnum]._pAFNum) + { int mistype = MIS_ARROW; - if ( plr[pnum]._pIFlags & ISPL_FIRE_ARROWS ) { + if (plr[pnum]._pIFlags & ISPL_FIRE_ARROWS) + { mistype = MIS_FARROW; } - if ( plr[pnum]._pIFlags & ISPL_LIGHT_ARROWS ) { + if (plr[pnum]._pIFlags & ISPL_LIGHT_ARROWS) + { mistype = MIS_LARROW; } AddMissile( @@ -2750,54 +3219,65 @@ BOOL __fastcall PM_DoRangeAttack(int pnum) 0, pnum, 4, - 0 - ); + 0); PlaySfxLoc(PS_BFIRE, plr[pnum].WorldX, plr[pnum].WorldY); - if ( WeaponDur(pnum, 40) ) { + if (WeaponDur(pnum, 40)) + { StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); return TRUE; } } - if ( plr[pnum]._pAnimFrame >= plr[pnum]._pAFrames ) { + if (plr[pnum]._pAnimFrame >= plr[pnum]._pAFrames) + { StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); return TRUE; - } else { + } + else + { return FALSE; } } void __fastcall ShieldDur(int pnum) { - if ( pnum != myplr ) { + if (pnum != myplr) + { return; } - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("ShieldDur: illegal player %d", pnum); } - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SHIELD ) { - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE ) { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SHIELD) + { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == DUR_INDESTRUCTIBLE) + { return; } plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability--; - if ( plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == 0 ) { + if (plr[pnum].InvBody[INVLOC_HAND_LEFT]._iDurability == 0) + { NetSendCmdDelItem(TRUE, INVLOC_HAND_LEFT); plr[pnum].InvBody[INVLOC_HAND_LEFT]._itype = ITYPE_NONE; CalcPlrInv(pnum, TRUE); } } - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD ) { - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability != DUR_INDESTRUCTIBLE ) { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD) + { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability != DUR_INDESTRUCTIBLE) + { plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability--; - if ( plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == 0 ) { + if (plr[pnum].InvBody[INVLOC_HAND_RIGHT]._iDurability == 0) + { NetSendCmdDelItem(TRUE, INVLOC_HAND_RIGHT); plr[pnum].InvBody[INVLOC_HAND_RIGHT]._itype = ITYPE_NONE; CalcPlrInv(pnum, TRUE); @@ -2808,19 +3288,23 @@ void __fastcall ShieldDur(int pnum) BOOL __fastcall PM_DoBlock(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoBlock: illegal player %d", pnum); } - if ( plr[pnum]._pIFlags & ISPL_FASTBLOCK && plr[pnum]._pAnimFrame != 1 ) { + if (plr[pnum]._pIFlags & ISPL_FASTBLOCK && plr[pnum]._pAnimFrame != 1) + { plr[pnum]._pAnimFrame = plr[pnum]._pBFrames; } - if ( plr[pnum]._pAnimFrame >= plr[pnum]._pBFrames ) { + if (plr[pnum]._pAnimFrame >= plr[pnum]._pBFrames) + { StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); - if ( !random(3, 10) ) { + if (!random(3, 10)) + { ShieldDur(pnum); } return TRUE; @@ -2831,11 +3315,12 @@ BOOL __fastcall PM_DoBlock(int pnum) BOOL __fastcall PM_DoSpell(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoSpell: illegal player %d", pnum); } - if ( plr[pnum]._pVar8 == plr[pnum]._pSFNum ) + if (plr[pnum]._pVar8 == plr[pnum]._pSFNum) { CastSpell( pnum, @@ -2845,24 +3330,24 @@ BOOL __fastcall PM_DoSpell(int pnum) plr[pnum]._pVar1, plr[pnum]._pVar2, FALSE, - plr[pnum]._pVar4 - ); - - if ( !plr[pnum]._pSplFrom ) { - if ( plr[pnum]._pRSplType == RSPLTYPE_SCROLL) { - if ( !(plr[pnum]._pScrlSpells64 - & (unsigned __int64)1 << (plr[pnum]._pRSpell - 1)) - ) { + plr[pnum]._pVar4); + + if (!plr[pnum]._pSplFrom) + { + if (plr[pnum]._pRSplType == RSPLTYPE_SCROLL) + { + if (!(plr[pnum]._pScrlSpells64 & (unsigned __int64)1 << (plr[pnum]._pRSpell - 1))) + { plr[pnum]._pRSpell = SPL_INVALID; plr[pnum]._pRSplType = RSPLTYPE_INVALID; drawpanflag = 255; } } - if ( plr[pnum]._pRSplType == RSPLTYPE_CHARGES) { - if ( !(plr[pnum]._pISpells64 - & (unsigned __int64)1 << (plr[pnum]._pRSpell - 1)) - ) { + if (plr[pnum]._pRSplType == RSPLTYPE_CHARGES) + { + if (!(plr[pnum]._pISpells64 & (unsigned __int64)1 << (plr[pnum]._pRSpell - 1))) + { plr[pnum]._pRSpell = SPL_INVALID; plr[pnum]._pRSplType = RSPLTYPE_INVALID; drawpanflag = 255; @@ -2873,13 +3358,17 @@ BOOL __fastcall PM_DoSpell(int pnum) plr[pnum]._pVar8++; - if ( leveltype == DTYPE_TOWN ) { - if ( plr[pnum]._pVar8 > plr[pnum]._pSFrames ) { + if (leveltype == DTYPE_TOWN) + { + if (plr[pnum]._pVar8 > plr[pnum]._pSFrames) + { StartWalkStand(pnum); ClearPlrPVars(pnum); return TRUE; } - } else if ( plr[pnum]._pAnimFrame == plr[pnum]._pSFrames ) { + } + else if (plr[pnum]._pAnimFrame == plr[pnum]._pSFrames) + { StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); return TRUE; @@ -2892,25 +3381,31 @@ BOOL __fastcall PM_DoSpell(int pnum) BOOL __fastcall PM_DoGotHit(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoGotHit: illegal player %d", pnum); } int frame = plr[pnum]._pAnimFrame; - if ( plr[pnum]._pIFlags & ISPL_FASTRECOVER && frame == 3 ) { + if (plr[pnum]._pIFlags & ISPL_FASTRECOVER && frame == 3) + { plr[pnum]._pAnimFrame++; } - if ( plr[pnum]._pIFlags & ISPL_FASTERRECOVER && (frame == 3 || frame == 5) ) { + if (plr[pnum]._pIFlags & ISPL_FASTERRECOVER && (frame == 3 || frame == 5)) + { plr[pnum]._pAnimFrame++; } - if ( plr[pnum]._pIFlags & ISPL_FASTESTRECOVER && (frame == 1 || frame == 3 || frame == 5) ) { + if (plr[pnum]._pIFlags & ISPL_FASTESTRECOVER && (frame == 1 || frame == 3 || frame == 5)) + { plr[pnum]._pAnimFrame++; } - if ( plr[pnum]._pAnimFrame >= plr[pnum]._pHFrames ) { + if (plr[pnum]._pAnimFrame >= plr[pnum]._pHFrames) + { StartStand(pnum, plr[pnum]._pdir); ClearPlrPVars(pnum); - if ( random(3, 4) ) { + if (random(3, 4)) + { ArmorDur(pnum); } @@ -2922,45 +3417,58 @@ BOOL __fastcall PM_DoGotHit(int pnum) void __fastcall ArmorDur(int pnum) { - if ( pnum != myplr ) { + if (pnum != myplr) + { return; } - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("ArmorDur: illegal player %d", pnum); } PlayerStruct *p = &plr[pnum]; - if ( p->InvBody[INVLOC_CHEST]._itype == ITYPE_NONE && p->InvBody[INVLOC_HEAD]._itype == ITYPE_NONE ) { + if (p->InvBody[INVLOC_CHEST]._itype == ITYPE_NONE && p->InvBody[INVLOC_HEAD]._itype == ITYPE_NONE) + { return; } int a = random(8, 3); - if ( p->InvBody[INVLOC_CHEST]._itype != ITYPE_NONE && p->InvBody[INVLOC_HEAD]._itype == ITYPE_NONE ) { + if (p->InvBody[INVLOC_CHEST]._itype != ITYPE_NONE && p->InvBody[INVLOC_HEAD]._itype == ITYPE_NONE) + { a = 1; } - if ( p->InvBody[INVLOC_CHEST]._itype == ITYPE_NONE && p->InvBody[INVLOC_HEAD]._itype != ITYPE_NONE ) { + if (p->InvBody[INVLOC_CHEST]._itype == ITYPE_NONE && p->InvBody[INVLOC_HEAD]._itype != ITYPE_NONE) + { a = 0; } ItemStruct *pi; - if ( a != 0 ) { + if (a != 0) + { pi = &p->InvBody[INVLOC_CHEST]; - } else { + } + else + { pi = &p->InvBody[INVLOC_HEAD]; } - if ( pi->_iDurability == DUR_INDESTRUCTIBLE ) { + if (pi->_iDurability == DUR_INDESTRUCTIBLE) + { return; } pi->_iDurability--; - if ( pi->_iDurability != 0 ) { + if (pi->_iDurability != 0) + { return; } - if ( a != 0 ) { + if (a != 0) + { NetSendCmdDelItem(TRUE, INVLOC_CHEST); - } else { + } + else + { NetSendCmdDelItem(TRUE, INVLOC_HEAD); } pi->_itype = ITYPE_NONE; @@ -2969,16 +3477,21 @@ void __fastcall ArmorDur(int pnum) BOOL __fastcall PM_DoDeath(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PM_DoDeath: illegal player %d", pnum); } - if ( plr[pnum]._pVar8 >= 2 * plr[pnum]._pDFrames ) { - if ( deathdelay > 1 && pnum == myplr ) { + if (plr[pnum]._pVar8 >= 2 * plr[pnum]._pDFrames) + { + if (deathdelay > 1 && pnum == myplr) + { deathdelay--; - if ( deathdelay == 1 ) { + if (deathdelay == 1) + { deathflag = 1; - if ( gbMaxPlayers == 1 ) { + if (gbMaxPlayers == 1) + { gamemenu_previous(); } } @@ -2989,7 +3502,8 @@ BOOL __fastcall PM_DoDeath(int pnum) dFlags[plr[pnum].WorldX][plr[pnum].WorldY] |= DFLAG_DEAD_PLAYER; } - if ( plr[pnum]._pVar8 < 100 ) { + if (plr[pnum]._pVar8 < 100) + { plr[pnum]._pVar8++; } @@ -3013,39 +3527,53 @@ void __fastcall CheckNewPath(int pnum) int xvel; int yvel; - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("CheckNewPath: illegal player %d", pnum); } - if ( plr[pnum].destAction == ACTION_ATTACKMON ) { + if (plr[pnum].destAction == ACTION_ATTACKMON) + { MakePlrPath(pnum, monster[plr[pnum].destParam1]._mfutx, monster[plr[pnum].destParam1]._mfuty, FALSE); } - if ( plr[pnum].destAction == ACTION_ATTACKPLR ) { + if (plr[pnum].destAction == ACTION_ATTACKPLR) + { MakePlrPath(pnum, plr[plr[pnum].destParam1]._px, plr[plr[pnum].destParam1]._py, FALSE); } - if ( plr[pnum].walkpath[0] != WALK_NONE) { - if ( plr[pnum]._pmode == PM_STAND ) { - if ( pnum == myplr ) { - if ( plr[pnum].destAction == ACTION_ATTACKMON || plr[pnum].destAction == ACTION_ATTACKPLR ) { + if (plr[pnum].walkpath[0] != WALK_NONE) + { + if (plr[pnum]._pmode == PM_STAND) + { + if (pnum == myplr) + { + if (plr[pnum].destAction == ACTION_ATTACKMON || plr[pnum].destAction == ACTION_ATTACKPLR) + { i = plr[pnum].destParam1; - if ( plr[pnum].destAction == ACTION_ATTACKMON ) { + if (plr[pnum].destAction == ACTION_ATTACKMON) + { x = abs(plr[pnum]._px - monster[i]._mfutx); y = abs(plr[pnum]._py - monster[i]._mfuty); d = GetDirection(plr[pnum]._px, plr[pnum]._py, monster[i]._mfutx, monster[i]._mfuty); - } else { + } + else + { x = abs(plr[pnum]._px - plr[i]._px); y = abs(plr[pnum]._py - plr[i]._py); d = GetDirection(plr[pnum]._px, plr[pnum]._py, plr[i]._px, plr[i]._py); } - if ( x < 2 && y < 2 ) { + if (x < 2 && y < 2) + { ClrPlrPath(pnum); - if ( monster[i].mtalkmsg && monster[i].mtalkmsg != QUEST_VILE14 ) { + if (monster[i].mtalkmsg && monster[i].mtalkmsg != QUEST_VILE14) + { TalktoMonster(i); - } else { + } + else + { StartAttack(pnum, d); } plr[pnum].destAction = ACTION_NONE; @@ -3053,50 +3581,56 @@ void __fastcall CheckNewPath(int pnum) } } - if ( currlevel != 0 ) { + if (currlevel != 0) + { xvel3 = PWVel[plr[pnum]._pClass][0]; xvel = PWVel[plr[pnum]._pClass][1]; yvel = PWVel[plr[pnum]._pClass][2]; - } else { + } + else + { xvel3 = 2048; xvel = 1024; yvel = 512; } - switch ( plr[pnum].walkpath[0] ) { - case WALK_N: - StartWalk(pnum, 0, -xvel, -1, -1, DIR_N, SDIR_N); - break; - case WALK_NE: - StartWalk(pnum, xvel, -yvel, 0, -1, DIR_NE, SDIR_NE); - break; - case WALK_E: - StartWalk3(pnum, xvel3, 0, -32, -16, 1, -1, 1, 0, DIR_E, SDIR_E); - break; - case WALK_SE: - StartWalk2(pnum, xvel, yvel, -32, -16, 1, 0, DIR_SE, SDIR_SE); - break; - case WALK_S: - StartWalk2(pnum, 0, xvel, 0, -32, 1, 1, DIR_S, SDIR_S); - break; - case WALK_SW: - StartWalk2(pnum, -xvel, yvel, 32, -16, 0, 1, DIR_SW, SDIR_SW); - break; - case WALK_W: - StartWalk3(pnum, -xvel3, 0, 32, -16, -1, 1, 0, 1, DIR_W, SDIR_W); - break; - case WALK_NW: - StartWalk(pnum, -xvel, -yvel, -1, 0, DIR_NW, SDIR_NW); - break; + switch (plr[pnum].walkpath[0]) + { + case WALK_N: + StartWalk(pnum, 0, -xvel, -1, -1, DIR_N, SDIR_N); + break; + case WALK_NE: + StartWalk(pnum, xvel, -yvel, 0, -1, DIR_NE, SDIR_NE); + break; + case WALK_E: + StartWalk3(pnum, xvel3, 0, -32, -16, 1, -1, 1, 0, DIR_E, SDIR_E); + break; + case WALK_SE: + StartWalk2(pnum, xvel, yvel, -32, -16, 1, 0, DIR_SE, SDIR_SE); + break; + case WALK_S: + StartWalk2(pnum, 0, xvel, 0, -32, 1, 1, DIR_S, SDIR_S); + break; + case WALK_SW: + StartWalk2(pnum, -xvel, yvel, 32, -16, 0, 1, DIR_SW, SDIR_SW); + break; + case WALK_W: + StartWalk3(pnum, -xvel3, 0, 32, -16, -1, 1, 0, 1, DIR_W, SDIR_W); + break; + case WALK_NW: + StartWalk(pnum, -xvel, -yvel, -1, 0, DIR_NW, SDIR_NW); + break; } - for ( i = 1; i < 25; i++ ) { + for (i = 1; i < 25; i++) + { plr[pnum].walkpath[i - 1] = plr[pnum].walkpath[i]; } plr[pnum].walkpath[24] = WALK_NONE; - if ( plr[pnum]._pmode == PM_STAND ) { + if (plr[pnum]._pmode == PM_STAND) + { StartStand(pnum, plr[pnum]._pdir); plr[pnum].destAction = ACTION_NONE; } @@ -3104,143 +3638,170 @@ void __fastcall CheckNewPath(int pnum) return; } - if ( plr[pnum].destAction == ACTION_NONE ) { + if (plr[pnum].destAction == ACTION_NONE) + { return; } - if ( plr[pnum]._pmode == PM_STAND ) { - switch ( plr[pnum].destAction ) { - case ACTION_ATTACK: - d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum].destParam1, plr[pnum].destParam2); - StartAttack(pnum, d); - break; - case ACTION_ATTACKMON: - i = plr[pnum].destParam1; - x = abs(plr[pnum].WorldX - monster[i]._mfutx); - y = abs(plr[pnum].WorldY - monster[i]._mfuty); - if ( x <= 1 && y <= 1 ) { - d = GetDirection(plr[pnum]._px, plr[pnum]._py, monster[i]._mfutx, monster[i]._mfuty); - if ( monster[i].mtalkmsg && monster[i].mtalkmsg != QUEST_VILE14 ) { - TalktoMonster(i); - } else { - StartAttack(pnum, d); - } - } - break; - case ACTION_ATTACKPLR: - i = plr[pnum].destParam1; - x = abs(plr[pnum].WorldX - plr[i]._px); - y = abs(plr[pnum].WorldY - plr[i]._py); - if ( x <= 1 && y <= 1 ) { - d = GetDirection(plr[pnum]._px, plr[pnum]._py, plr[i]._px, plr[i]._py); - StartAttack(pnum, d); - } - break; - case ACTION_RATTACK: - d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum].destParam1, plr[pnum].destParam2); - StartRangeAttack(pnum, d, plr[pnum].destParam1, plr[pnum].destParam2); - break; - case ACTION_RATTACKMON: - i = plr[pnum].destParam1; + if (plr[pnum]._pmode == PM_STAND) + { + switch (plr[pnum].destAction) + { + case ACTION_ATTACK: + d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum].destParam1, plr[pnum].destParam2); + StartAttack(pnum, d); + break; + case ACTION_ATTACKMON: + i = plr[pnum].destParam1; + x = abs(plr[pnum].WorldX - monster[i]._mfutx); + y = abs(plr[pnum].WorldY - monster[i]._mfuty); + if (x <= 1 && y <= 1) + { d = GetDirection(plr[pnum]._px, plr[pnum]._py, monster[i]._mfutx, monster[i]._mfuty); - if ( monster[i].mtalkmsg && monster[i].mtalkmsg != QUEST_VILE14 ) { + if (monster[i].mtalkmsg && monster[i].mtalkmsg != QUEST_VILE14) + { TalktoMonster(i); - } else { - StartRangeAttack(pnum, d, monster[i]._mfutx, monster[i]._mfuty); } - break; - case ACTION_RATTACKPLR: - i = plr[pnum].destParam1; + else + { + StartAttack(pnum, d); + } + } + break; + case ACTION_ATTACKPLR: + i = plr[pnum].destParam1; + x = abs(plr[pnum].WorldX - plr[i]._px); + y = abs(plr[pnum].WorldY - plr[i]._py); + if (x <= 1 && y <= 1) + { d = GetDirection(plr[pnum]._px, plr[pnum]._py, plr[i]._px, plr[i]._py); - StartRangeAttack(pnum, d, plr[i]._px, plr[i]._py); - break; - case ACTION_SPELL: - d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum].destParam1, plr[pnum].destParam2); - StartSpell(pnum, d, plr[pnum].destParam1, plr[pnum].destParam2); - plr[pnum]._pVar4 = plr[pnum].destParam3; - break; - case ACTION_SPELLWALL: - StartSpell(pnum, plr[pnum].destParam3, plr[pnum].destParam1, plr[pnum].destParam2); - plr[pnum]._pVar3 = plr[pnum].destParam3; - plr[pnum]._pVar4 = plr[pnum].destParam4; - break; - case ACTION_SPELLMON: - i = plr[pnum].destParam1; - d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, monster[i]._mfutx, monster[i]._mfuty); - StartSpell(pnum, d, monster[i]._mfutx, monster[i]._mfuty); - plr[pnum]._pVar4 = plr[pnum].destParam2; - break; - case ACTION_SPELLPLR: - i = plr[pnum].destParam1; - d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[i]._px, plr[i]._py); - StartSpell(pnum, d, plr[i]._px, plr[i]._py); - plr[pnum]._pVar4 = plr[pnum].destParam2; - break; - case ACTION_OPERATE: - i = plr[pnum].destParam1; - x = abs(plr[pnum].WorldX - object[i]._ox); - y = abs(plr[pnum].WorldY - object[i]._oy); - if ( y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i ) { - y = abs(plr[pnum].WorldY - object[i]._oy + 1); + StartAttack(pnum, d); + } + break; + case ACTION_RATTACK: + d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum].destParam1, plr[pnum].destParam2); + StartRangeAttack(pnum, d, plr[pnum].destParam1, plr[pnum].destParam2); + break; + case ACTION_RATTACKMON: + i = plr[pnum].destParam1; + d = GetDirection(plr[pnum]._px, plr[pnum]._py, monster[i]._mfutx, monster[i]._mfuty); + if (monster[i].mtalkmsg && monster[i].mtalkmsg != QUEST_VILE14) + { + TalktoMonster(i); + } + else + { + StartRangeAttack(pnum, d, monster[i]._mfutx, monster[i]._mfuty); + } + break; + case ACTION_RATTACKPLR: + i = plr[pnum].destParam1; + d = GetDirection(plr[pnum]._px, plr[pnum]._py, plr[i]._px, plr[i]._py); + StartRangeAttack(pnum, d, plr[i]._px, plr[i]._py); + break; + case ACTION_SPELL: + d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum].destParam1, plr[pnum].destParam2); + StartSpell(pnum, d, plr[pnum].destParam1, plr[pnum].destParam2); + plr[pnum]._pVar4 = plr[pnum].destParam3; + break; + case ACTION_SPELLWALL: + StartSpell(pnum, plr[pnum].destParam3, plr[pnum].destParam1, plr[pnum].destParam2); + plr[pnum]._pVar3 = plr[pnum].destParam3; + plr[pnum]._pVar4 = plr[pnum].destParam4; + break; + case ACTION_SPELLMON: + i = plr[pnum].destParam1; + d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, monster[i]._mfutx, monster[i]._mfuty); + StartSpell(pnum, d, monster[i]._mfutx, monster[i]._mfuty); + plr[pnum]._pVar4 = plr[pnum].destParam2; + break; + case ACTION_SPELLPLR: + i = plr[pnum].destParam1; + d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[i]._px, plr[i]._py); + StartSpell(pnum, d, plr[i]._px, plr[i]._py); + plr[pnum]._pVar4 = plr[pnum].destParam2; + break; + case ACTION_OPERATE: + i = plr[pnum].destParam1; + x = abs(plr[pnum].WorldX - object[i]._ox); + y = abs(plr[pnum].WorldY - object[i]._oy); + if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i) + { + y = abs(plr[pnum].WorldY - object[i]._oy + 1); + } + if (x <= 1 && y <= 1) + { + if (object[i]._oBreak == 1) + { + d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, object[i]._ox, object[i]._oy); + StartAttack(pnum, d); } - if ( x <= 1 && y <= 1 ) { - if ( object[i]._oBreak == 1 ) { - d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, object[i]._ox, object[i]._oy); - StartAttack(pnum, d); - } else { - OperateObject(pnum, i, FALSE); - } + else + { + OperateObject(pnum, i, FALSE); } - break; - case ACTION_DISARM: - i = plr[pnum].destParam1; - x = abs(plr[pnum].WorldX - object[i]._ox); - y = abs(plr[pnum].WorldY - object[i]._oy); - if ( y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i ) { - y = abs(plr[pnum].WorldY - object[i]._oy + 1); + } + break; + case ACTION_DISARM: + i = plr[pnum].destParam1; + x = abs(plr[pnum].WorldX - object[i]._ox); + y = abs(plr[pnum].WorldY - object[i]._oy); + if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i) + { + y = abs(plr[pnum].WorldY - object[i]._oy + 1); + } + if (x <= 1 && y <= 1) + { + if (object[i]._oBreak == 1) + { + d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, object[i]._ox, object[i]._oy); + StartAttack(pnum, d); } - if ( x <= 1 && y <= 1 ) { - if ( object[i]._oBreak == 1 ) { - d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, object[i]._ox, object[i]._oy); - StartAttack(pnum, d); - } else { - TryDisarm(pnum, i); - OperateObject(pnum, i, FALSE); - } + else + { + TryDisarm(pnum, i); + OperateObject(pnum, i, FALSE); } - break; - case ACTION_OPERATETK: + } + break; + case ACTION_OPERATETK: + i = plr[pnum].destParam1; + if (object[i]._oBreak != 1) + { + OperateObject(pnum, i, TRUE); + } + break; + case ACTION_PICKUPITEM: + if (pnum == myplr) + { i = plr[pnum].destParam1; - if ( object[i]._oBreak != 1 ) { - OperateObject(pnum, i, TRUE); - } - break; - case ACTION_PICKUPITEM: - if ( pnum == myplr ) { - i = plr[pnum].destParam1; - x = abs(plr[pnum].WorldX - item[i]._ix); - y = abs(plr[pnum].WorldY - item[i]._iy); - if ( x <= 1 && y <= 1 && pcurs == 1 && !item[i]._iRequest ) { - NetSendCmdGItem(TRUE, CMD_REQUESTGITEM, myplr, myplr, i); - item[i]._iRequest = TRUE; - } - } - break; - case ACTION_PICKUPAITEM: - if ( pnum == myplr ) { - i = plr[pnum].destParam1; - x = abs(plr[pnum].WorldX - item[i]._ix); - y = abs(plr[pnum].WorldY - item[i]._iy); - if ( x <= 1 && y <= 1 && pcurs == 1 ) { - NetSendCmdGItem(TRUE, CMD_REQUESTAGITEM, myplr, myplr, i); - } + x = abs(plr[pnum].WorldX - item[i]._ix); + y = abs(plr[pnum].WorldY - item[i]._iy); + if (x <= 1 && y <= 1 && pcurs == 1 && !item[i]._iRequest) + { + NetSendCmdGItem(TRUE, CMD_REQUESTGITEM, myplr, myplr, i); + item[i]._iRequest = TRUE; } - break; - case ACTION_TALK: - if ( pnum == myplr ) { - TalkToTowner(pnum, plr[pnum].destParam1); + } + break; + case ACTION_PICKUPAITEM: + if (pnum == myplr) + { + i = plr[pnum].destParam1; + x = abs(plr[pnum].WorldX - item[i]._ix); + y = abs(plr[pnum].WorldY - item[i]._iy); + if (x <= 1 && y <= 1 && pcurs == 1) + { + NetSendCmdGItem(TRUE, CMD_REQUESTAGITEM, myplr, myplr, i); } - break; + } + break; + case ACTION_TALK: + if (pnum == myplr) + { + TalkToTowner(pnum, plr[pnum].destParam1); + } + break; } FixPlayerLocation(pnum, plr[pnum]._pdir); @@ -3249,58 +3810,79 @@ void __fastcall CheckNewPath(int pnum) return; } - if ( plr[pnum]._pmode == PM_ATTACK && plr[pnum]._pAnimFrame > plr[myplr]._pAFNum ) { - if ( plr[pnum].destAction == ACTION_ATTACK ) { + if (plr[pnum]._pmode == PM_ATTACK && plr[pnum]._pAnimFrame > plr[myplr]._pAFNum) + { + if (plr[pnum].destAction == ACTION_ATTACK) + { d = GetDirection(plr[pnum]._px, plr[pnum]._py, plr[pnum].destParam1, plr[pnum].destParam2); StartAttack(pnum, d); plr[pnum].destAction = ACTION_NONE; - } else if ( plr[pnum].destAction == ACTION_ATTACKMON ) { + } + else if (plr[pnum].destAction == ACTION_ATTACKMON) + { i = plr[pnum].destParam1; x = abs(plr[pnum].WorldX - monster[i]._mfutx); y = abs(plr[pnum].WorldY - monster[i]._mfuty); - if ( x <= 1 && y <= 1 ) { + if (x <= 1 && y <= 1) + { d = GetDirection(plr[pnum]._px, plr[pnum]._py, monster[i]._mfutx, monster[i]._mfuty); StartAttack(pnum, d); } plr[pnum].destAction = ACTION_NONE; - } else if ( plr[pnum].destAction == ACTION_ATTACKPLR ) { + } + else if (plr[pnum].destAction == ACTION_ATTACKPLR) + { i = plr[pnum].destParam1; x = abs(plr[pnum].WorldX - plr[i]._px); y = abs(plr[pnum].WorldY - plr[i]._py); - if ( x <= 1 && y <= 1 ) { + if (x <= 1 && y <= 1) + { d = GetDirection(plr[pnum]._px, plr[pnum]._py, plr[i]._px, plr[i]._py); StartAttack(pnum, d); } plr[pnum].destAction = ACTION_NONE; - } else if ( plr[pnum].destAction == ACTION_OPERATE ) { + } + else if (plr[pnum].destAction == ACTION_OPERATE) + { i = plr[pnum].destParam1; x = abs(plr[pnum].WorldX - object[i]._ox); y = abs(plr[pnum].WorldY - object[i]._oy); - if ( y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i ) { + if (y > 1 && dObject[object[i]._ox][object[i]._oy - 1] == -1 - i) + { y = abs(plr[pnum].WorldY - object[i]._oy + 1); } - if ( x <= 1 && y <= 1 ) { - if ( object[i]._oBreak == 1 ) { + if (x <= 1 && y <= 1) + { + if (object[i]._oBreak == 1) + { d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, object[i]._ox, object[i]._oy); StartAttack(pnum, d); - } else { + } + else + { OperateObject(pnum, i, FALSE); } } } } - if ( plr[pnum]._pmode == PM_RATTACK && plr[pnum]._pAnimFrame > plr[myplr]._pAFNum ) { - if ( plr[pnum].destAction == ACTION_RATTACK ) { + if (plr[pnum]._pmode == PM_RATTACK && plr[pnum]._pAnimFrame > plr[myplr]._pAFNum) + { + if (plr[pnum].destAction == ACTION_RATTACK) + { d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum].destParam1, plr[pnum].destParam2); StartRangeAttack(pnum, d, plr[pnum].destParam1, plr[pnum].destParam2); plr[pnum].destAction = ACTION_NONE; - } else if ( plr[pnum].destAction == ACTION_RATTACKMON ) { + } + else if (plr[pnum].destAction == ACTION_RATTACKMON) + { i = plr[pnum].destParam1; d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, monster[i]._mfutx, monster[i]._mfuty); StartRangeAttack(pnum, d, monster[i]._mfutx, monster[i]._mfuty); plr[pnum].destAction = ACTION_NONE; - } else if ( plr[pnum].destAction == ACTION_RATTACKPLR ) { + } + else if (plr[pnum].destAction == ACTION_RATTACKPLR) + { i = plr[pnum].destParam1; d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[i]._px, plr[i]._py); StartRangeAttack(pnum, d, plr[i]._px, plr[i]._py); @@ -3308,17 +3890,23 @@ void __fastcall CheckNewPath(int pnum) } } - if ( plr[pnum]._pmode == PM_SPELL && plr[pnum]._pAnimFrame > plr[pnum]._pSFNum ) { - if ( plr[pnum].destAction == ACTION_SPELL ) { + if (plr[pnum]._pmode == PM_SPELL && plr[pnum]._pAnimFrame > plr[pnum]._pSFNum) + { + if (plr[pnum].destAction == ACTION_SPELL) + { d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum].destParam1, plr[pnum].destParam2); StartSpell(pnum, d, plr[pnum].destParam1, plr[pnum].destParam2); plr[pnum].destAction = ACTION_NONE; - } else if ( plr[pnum].destAction == ACTION_SPELLMON ) { + } + else if (plr[pnum].destAction == ACTION_SPELLMON) + { i = plr[pnum].destParam1; d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, monster[i]._mfutx, monster[i]._mfuty); StartSpell(pnum, d, monster[i]._mfutx, monster[i]._mfuty); plr[pnum].destAction = ACTION_NONE; - } else if ( plr[pnum].destAction == ACTION_SPELLPLR ) { + } + else if (plr[pnum].destAction == ACTION_SPELLPLR) + { i = plr[pnum].destParam1; d = GetDirection(plr[pnum].WorldX, plr[pnum].WorldY, plr[i]._px, plr[i]._py); StartSpell(pnum, d, plr[i]._px, plr[i]._py); @@ -3329,19 +3917,26 @@ void __fastcall CheckNewPath(int pnum) BOOL __fastcall PlrDeathModeOK(int pnum) { - if ( pnum != myplr ) { + if (pnum != myplr) + { return TRUE; } - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("PlrDeathModeOK: illegal player %d", pnum); } - if (plr[pnum]._pmode == PM_DEATH) { + if (plr[pnum]._pmode == PM_DEATH) + { return TRUE; - } else if (plr[pnum]._pmode == PM_QUIT) { + } + else if (plr[pnum]._pmode == PM_QUIT) + { return TRUE; - } else if (plr[pnum]._pmode == PM_NEWLVL) { + } + else if (plr[pnum]._pmode == PM_NEWLVL) + { return TRUE; } @@ -3352,44 +3947,54 @@ void __cdecl ValidatePlayer() { __int64 msk = 0; - if ( (DWORD)myplr >= MAX_PLRS ) { + if ((DWORD)myplr >= MAX_PLRS) + { TermMsg("ValidatePlayer: illegal player %d", myplr); } - if ( plr[myplr]._pLevel > 50 ) + if (plr[myplr]._pLevel > 50) plr[myplr]._pLevel = 50; - if ( plr[myplr]._pExperience > plr[myplr]._pNextExper ) + if (plr[myplr]._pExperience > plr[myplr]._pNextExper) plr[myplr]._pExperience = plr[myplr]._pNextExper; int gt = 0; - for ( int i = 0; i < plr[myplr]._pNumInv; i++ ) { - if ( plr[myplr].InvList[i]._itype == ITYPE_GOLD ) { - if ( plr[myplr].InvList[i]._ivalue > 5000 ) { + for (int i = 0; i < plr[myplr]._pNumInv; i++) + { + if (plr[myplr].InvList[i]._itype == ITYPE_GOLD) + { + if (plr[myplr].InvList[i]._ivalue > 5000) + { plr[myplr].InvList[i]._ivalue = 5000; } gt += plr[myplr].InvList[i]._ivalue; } } - if ( gt != plr[myplr]._pGold ) + if (gt != plr[myplr]._pGold) plr[myplr]._pGold = gt; int pc = plr[myplr]._pClass; - if ( plr[myplr]._pBaseStr > MaxStats[pc][ATTRIB_STR] ) { + if (plr[myplr]._pBaseStr > MaxStats[pc][ATTRIB_STR]) + { plr[myplr]._pBaseStr = MaxStats[pc][ATTRIB_STR]; } - if ( plr[myplr]._pBaseMag > MaxStats[pc][ATTRIB_MAG] ) { + if (plr[myplr]._pBaseMag > MaxStats[pc][ATTRIB_MAG]) + { plr[myplr]._pBaseMag = MaxStats[pc][ATTRIB_MAG]; } - if ( plr[myplr]._pBaseDex > MaxStats[pc][ATTRIB_DEX] ) { + if (plr[myplr]._pBaseDex > MaxStats[pc][ATTRIB_DEX]) + { plr[myplr]._pBaseDex = MaxStats[pc][ATTRIB_DEX]; } - if ( plr[myplr]._pBaseVit > MaxStats[pc][ATTRIB_VIT] ) { + if (plr[myplr]._pBaseVit > MaxStats[pc][ATTRIB_VIT]) + { plr[myplr]._pBaseVit = MaxStats[pc][ATTRIB_VIT]; } - for ( int b = 1; b < MAX_SPELLS; b++) { - if ( spelldata[b].sBookLvl != -1 ) { + for (int b = 1; b < MAX_SPELLS; b++) + { + if (spelldata[b].sBookLvl != -1) + { msk |= (__int64)1 << (b - 1); - if ( plr[myplr]._pSplLvl[b] > 15 ) + if (plr[myplr]._pSplLvl[b] > 15) plr[myplr]._pSplLvl[b] = 15; } } @@ -3399,41 +4004,52 @@ void __cdecl ValidatePlayer() void __cdecl ProcessPlayers() { - if ( (DWORD)myplr >= MAX_PLRS ) { + if ((DWORD)myplr >= MAX_PLRS) + { TermMsg("ProcessPlayers: illegal player %d", myplr); } - if ( plr[myplr].pLvlLoad > 0 ) { + if (plr[myplr].pLvlLoad > 0) + { plr[myplr].pLvlLoad--; } - if ( sfxdelay > 0 ) { + if (sfxdelay > 0) + { sfxdelay--; - if ( sfxdelay == 0 ) { + if (sfxdelay == 0) + { PlaySFX(sfxdnum); } } ValidatePlayer(); - for ( int pnum = 0; pnum < MAX_PLRS; pnum++ ) { - if ( plr[pnum].plractive && currlevel == plr[pnum].plrlevel && (pnum == myplr || !plr[pnum]._pLvlChanging) ) { + for (int pnum = 0; pnum < MAX_PLRS; pnum++) + { + if (plr[pnum].plractive && currlevel == plr[pnum].plrlevel && (pnum == myplr || !plr[pnum]._pLvlChanging)) + { CheckCheatStats(pnum); - if ( !PlrDeathModeOK(pnum) && (plr[pnum]._pHitPoints >> 6) <= 0 ) { + if (!PlrDeathModeOK(pnum) && (plr[pnum]._pHitPoints >> 6) <= 0) + { SyncPlrKill(pnum, -1); } - if ( pnum == myplr ) { - if ( (plr[pnum]._pIFlags & ISPL_DRAINLIFE) && currlevel ) { + if (pnum == myplr) + { + if ((plr[pnum]._pIFlags & ISPL_DRAINLIFE) && currlevel) + { plr[pnum]._pHitPoints -= 4; plr[pnum]._pHPBase -= 4; - if ( (plr[pnum]._pHitPoints >> 6) <= 0 ) { + if ((plr[pnum]._pHitPoints >> 6) <= 0) + { SyncPlrKill(pnum, 0); } drawhpflag = TRUE; } - if ( plr[pnum]._pIFlags & ISPL_NOMANA && plr[pnum]._pManaBase > 0 ) { + if (plr[pnum]._pIFlags & ISPL_NOMANA && plr[pnum]._pManaBase > 0) + { plr[pnum]._pManaBase -= plr[pnum]._pMana; plr[pnum]._pMana = 0; drawmanaflag = TRUE; @@ -3441,50 +4057,54 @@ void __cdecl ProcessPlayers() } BOOL tplayer = FALSE; - do { - switch ( plr[pnum]._pmode ) { - case PM_STAND: - tplayer = PM_DoStand(pnum); - break; - case PM_WALK: - tplayer = PM_DoWalk(pnum); - break; - case PM_WALK2: - tplayer = PM_DoWalk2(pnum); - break; - case PM_WALK3: - tplayer = PM_DoWalk3(pnum); - break; - case PM_ATTACK: - tplayer = PM_DoAttack(pnum); - break; - case PM_RATTACK: - tplayer = PM_DoRangeAttack(pnum); - break; - case PM_BLOCK: - tplayer = PM_DoBlock(pnum); - break; - case PM_SPELL: - tplayer = PM_DoSpell(pnum); - break; - case PM_GOTHIT: - tplayer = PM_DoGotHit(pnum); - break; - case PM_DEATH: - tplayer = PM_DoDeath(pnum); - break; - case PM_NEWLVL: - tplayer = PM_DoNewLvl(pnum); - break; + do + { + switch (plr[pnum]._pmode) + { + case PM_STAND: + tplayer = PM_DoStand(pnum); + break; + case PM_WALK: + tplayer = PM_DoWalk(pnum); + break; + case PM_WALK2: + tplayer = PM_DoWalk2(pnum); + break; + case PM_WALK3: + tplayer = PM_DoWalk3(pnum); + break; + case PM_ATTACK: + tplayer = PM_DoAttack(pnum); + break; + case PM_RATTACK: + tplayer = PM_DoRangeAttack(pnum); + break; + case PM_BLOCK: + tplayer = PM_DoBlock(pnum); + break; + case PM_SPELL: + tplayer = PM_DoSpell(pnum); + break; + case PM_GOTHIT: + tplayer = PM_DoGotHit(pnum); + break; + case PM_DEATH: + tplayer = PM_DoDeath(pnum); + break; + case PM_NEWLVL: + tplayer = PM_DoNewLvl(pnum); + break; } CheckNewPath(pnum); - } while ( tplayer ); + } while (tplayer); plr[pnum]._pAnimCnt++; - if ( plr[pnum]._pAnimCnt > plr[pnum]._pAnimDelay ) { + if (plr[pnum]._pAnimCnt > plr[pnum]._pAnimDelay) + { plr[pnum]._pAnimCnt = 0; plr[pnum]._pAnimFrame++; - if ( plr[pnum]._pAnimFrame > plr[pnum]._pAnimLen ) { + if (plr[pnum]._pAnimFrame > plr[pnum]._pAnimLen) + { plr[pnum]._pAnimFrame = 1; } } @@ -3495,34 +4115,41 @@ void __cdecl ProcessPlayers() void __fastcall CheckCheatStats(int pnum) { - if ( plr[pnum]._pStrength > 750 ) { + if (plr[pnum]._pStrength > 750) + { plr[pnum]._pStrength = 750; } - if ( plr[pnum]._pDexterity > 750 ) { + if (plr[pnum]._pDexterity > 750) + { plr[pnum]._pDexterity = 750; } - if ( plr[pnum]._pMagic > 750 ) { + if (plr[pnum]._pMagic > 750) + { plr[pnum]._pMagic = 750; } - if ( plr[pnum]._pVitality > 750 ) { + if (plr[pnum]._pVitality > 750) + { plr[pnum]._pVitality = 750; } - if ( plr[pnum]._pHitPoints > 128000 ) { + if (plr[pnum]._pHitPoints > 128000) + { plr[pnum]._pHitPoints = 128000; } - if ( plr[pnum]._pMana > 128000 ) { + if (plr[pnum]._pMana > 128000) + { plr[pnum]._pMana = 128000; } } void __fastcall ClrPlrPath(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("ClrPlrPath: illegal player %d", pnum); } @@ -3532,102 +4159,122 @@ void __fastcall ClrPlrPath(int pnum) BOOL __fastcall PosOkPlayer(int pnum, int px, int py) { BOOL PosOK = FALSE; - if ( px >= 0 && px < MAXDUNX && py >= 0 && py < MAXDUNY && - !SolidLoc(px, py) && dPiece[px][py] ) { + if (px >= 0 && px < MAXDUNX && py >= 0 && py < MAXDUNY && + !SolidLoc(px, py) && dPiece[px][py]) + { - if ( dPlayer[px][py] ) { + if (dPlayer[px][py]) + { DWORD p; - if ( dPlayer[px][py] > 0 ) { + if (dPlayer[px][py] > 0) + { p = dPlayer[px][py] - 1; - } else { + } + else + { p = -(dPlayer[px][py] + 1); } - if ( p != pnum && p < MAX_PLRS && plr[p]._pHitPoints ) { - return FALSE; + if (p != pnum && p < MAX_PLRS && plr[p]._pHitPoints) + { + return FALSE; } } - if ( dMonster[px][py] ) { - if ( !currlevel ) { + if (dMonster[px][py]) + { + if (!currlevel) + { return FALSE; } - if ( dMonster[px][py] <= 0 ) { + if (dMonster[px][py] <= 0) + { return FALSE; } - if ( (monster[dMonster[px][py] - 1]._mhitpoints >> 6) > 0 ) { + if ((monster[dMonster[px][py] - 1]._mhitpoints >> 6) > 0) + { return FALSE; } - } + } - if ( dObject[px][py] ) { + if (dObject[px][py]) + { char bv; - if ( dObject[px][py] > 0 ) { + if (dObject[px][py] > 0) + { bv = dObject[px][py] - 1; - } else { + } + else + { bv = -(dObject[px][py] + 1); } - if ( object[bv]._oSolidFlag ) { - return FALSE; + if (object[bv]._oSolidFlag) + { + return FALSE; } } PosOK = TRUE; } - if ( !PosOK ) + if (!PosOK) return FALSE; return TRUE; } void __fastcall MakePlrPath(int pnum, int xx, int yy, BOOL endspace) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("MakePlrPath: illegal player %d", pnum); } plr[pnum]._ptargx = xx; plr[pnum]._ptargy = yy; - if ( plr[pnum]._px == xx && plr[pnum]._py == yy ) { + if (plr[pnum]._px == xx && plr[pnum]._py == yy) + { return; } int path = FindPath(PosOkPlayer, pnum, plr[pnum]._px, plr[pnum]._py, xx, yy, plr[pnum].walkpath); - if ( !path ) { + if (!path) + { return; } - if ( !endspace ) { + if (!endspace) + { path--; - switch ( plr[pnum].walkpath[path] ) { - case WALK_NE: - yy++; - break; - case WALK_NW: - xx++; - break; - case WALK_SE: - xx--; - break; - case WALK_SW: - yy--; - break; - case WALK_N: - xx++; - yy++; - break; - case WALK_E: - xx--; - yy++; - break; - case WALK_S: - xx--; - yy--; - break; - case WALK_W: - xx++; - yy--; - break; + switch (plr[pnum].walkpath[path]) + { + case WALK_NE: + yy++; + break; + case WALK_NW: + xx++; + break; + case WALK_SE: + xx--; + break; + case WALK_SW: + yy--; + break; + case WALK_N: + xx++; + yy++; + break; + case WALK_E: + xx--; + yy++; + break; + case WALK_S: + xx--; + yy--; + break; + case WALK_W: + xx++; + yy--; + break; } plr[pnum]._ptargx = xx; @@ -3639,83 +4286,104 @@ void __fastcall MakePlrPath(int pnum, int xx, int yy, BOOL endspace) void __fastcall CheckPlrSpell() { - if ( (DWORD)myplr >= MAX_PLRS ) { + if ((DWORD)myplr >= MAX_PLRS) + { TermMsg("CheckPlrSpell: illegal player %d", myplr); } int rspell = plr[myplr]._pRSpell; - if ( rspell == SPL_INVALID ) { - if ( plr[myplr]._pClass == PC_WARRIOR ) { + if (rspell == SPL_INVALID) + { + if (plr[myplr]._pClass == PC_WARRIOR) + { PlaySFX(PS_WARR34); - } else if ( plr[myplr]._pClass == PC_ROGUE ) { + } + else if (plr[myplr]._pClass == PC_ROGUE) + { PlaySFX(PS_ROGUE34); - } else if ( plr[myplr]._pClass == PC_SORCERER ) { + } + else if (plr[myplr]._pClass == PC_SORCERER) + { PlaySFX(PS_MAGE34); } return; } - if ( leveltype == DTYPE_TOWN && !spelldata[rspell].sTownSpell ) { - if ( plr[myplr]._pClass == PC_WARRIOR ) { + if (leveltype == DTYPE_TOWN && !spelldata[rspell].sTownSpell) + { + if (plr[myplr]._pClass == PC_WARRIOR) + { PlaySFX(PS_WARR27); - } else if ( plr[myplr]._pClass == PC_ROGUE ) { + } + else if (plr[myplr]._pClass == PC_ROGUE) + { PlaySFX(PS_ROGUE27); - } else if ( plr[myplr]._pClass == PC_SORCERER ) { + } + else if (plr[myplr]._pClass == PC_SORCERER) + { PlaySFX(PS_MAGE27); } 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 - ) { + 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 ) { + 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 ) { + } + else if (pcursmonst != -1) + { int sl = GetSpellLevel(myplr, plr[myplr]._pRSpell); NetSendCmdParam3(TRUE, CMD_SPELLID, pcursmonst, plr[myplr]._pRSpell, sl); - } else if ( pcursplr != -1 ) { + } + else if (pcursplr != -1) + { int sl = GetSpellLevel(myplr, plr[myplr]._pRSpell); NetSendCmdParam3(TRUE, CMD_SPELLPID, pcursplr, plr[myplr]._pRSpell, sl); - } else {//145 + } + else + { //145 int sl = GetSpellLevel(myplr, plr[myplr]._pRSpell); NetSendCmdLocParam2(TRUE, CMD_SPELLXY, cursmx, cursmy, plr[myplr]._pRSpell, sl); } return; } - if ( plr[myplr]._pRSplType == RSPLTYPE_SPELL ) { - if ( plr[myplr]._pClass == PC_WARRIOR ) { + if (plr[myplr]._pRSplType == RSPLTYPE_SPELL) + { + if (plr[myplr]._pClass == PC_WARRIOR) + { PlaySFX(PS_WARR35); - } else if ( plr[myplr]._pClass == PC_ROGUE ) { + } + else if (plr[myplr]._pClass == PC_ROGUE) + { PlaySFX(PS_ROGUE35); - } else if ( plr[myplr]._pClass == PC_SORCERER ) { + } + else if (plr[myplr]._pClass == PC_SORCERER) + { PlaySFX(PS_MAGE35); } } @@ -3725,53 +4393,59 @@ void __fastcall CheckPlrSpell() void __fastcall SyncPlrAnim(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SyncPlrAnim: illegal player %d", pnum); } int dir = plr[pnum]._pdir; - switch ( plr[pnum]._pmode ) { - case PM_BLOCK: - plr[pnum]._pAnimData = plr[pnum]._pBAnim[dir]; - break; - case PM_GOTHIT: - plr[pnum]._pAnimData = plr[pnum]._pHAnim[dir]; - break; - case PM_DEATH: - plr[pnum]._pAnimData = plr[pnum]._pDAnim[dir]; - break; - case PM_SPELL: - int sType; - if ( pnum == myplr ) { - sType = spelldata[plr[pnum]._pSpell].sType; - } else { - sType = STYPE_FIRE; - } - if ( sType == STYPE_FIRE ) - plr[pnum]._pAnimData = plr[pnum]._pFAnim[dir]; - if ( sType == STYPE_LIGHTNING ) - plr[pnum]._pAnimData = plr[pnum]._pLAnim[dir]; - if ( sType == STYPE_MAGIC ) { - plr[pnum]._pAnimData = plr[pnum]._pTAnim[dir]; - } - break; - case PM_STAND: - case PM_NEWLVL: - case PM_QUIT: - plr[pnum]._pAnimData = plr[pnum]._pNAnim[dir]; - break; - case PM_WALK: - case PM_WALK2: - case PM_WALK3: - plr[pnum]._pAnimData = plr[pnum]._pWAnim[dir]; - break; - case PM_ATTACK: - case PM_RATTACK: - plr[pnum]._pAnimData = plr[pnum]._pAAnim[dir]; - break; - default: - TermMsg("SyncPlrAnim"); - break; + switch (plr[pnum]._pmode) + { + case PM_BLOCK: + plr[pnum]._pAnimData = plr[pnum]._pBAnim[dir]; + break; + case PM_GOTHIT: + plr[pnum]._pAnimData = plr[pnum]._pHAnim[dir]; + break; + case PM_DEATH: + plr[pnum]._pAnimData = plr[pnum]._pDAnim[dir]; + break; + case PM_SPELL: + int sType; + if (pnum == myplr) + { + sType = spelldata[plr[pnum]._pSpell].sType; + } + else + { + sType = STYPE_FIRE; + } + if (sType == STYPE_FIRE) + plr[pnum]._pAnimData = plr[pnum]._pFAnim[dir]; + if (sType == STYPE_LIGHTNING) + plr[pnum]._pAnimData = plr[pnum]._pLAnim[dir]; + if (sType == STYPE_MAGIC) + { + plr[pnum]._pAnimData = plr[pnum]._pTAnim[dir]; + } + break; + case PM_STAND: + case PM_NEWLVL: + case PM_QUIT: + plr[pnum]._pAnimData = plr[pnum]._pNAnim[dir]; + break; + case PM_WALK: + case PM_WALK2: + case PM_WALK3: + plr[pnum]._pAnimData = plr[pnum]._pWAnim[dir]; + break; + case PM_ATTACK: + case PM_RATTACK: + plr[pnum]._pAnimData = plr[pnum]._pAAnim[dir]; + break; + default: + TermMsg("SyncPlrAnim"); + break; } } @@ -3780,42 +4454,51 @@ void __fastcall SyncInitPlrPos(int pnum) plr[pnum]._ptargx = plr[pnum].WorldX; plr[pnum]._ptargy = plr[pnum].WorldY; - if ( gbMaxPlayers == 1 || plr[pnum].plrlevel != currlevel ) { + if (gbMaxPlayers == 1 || plr[pnum].plrlevel != currlevel) + { return; } int x; int y; - for ( DWORD i = 0; i < 8; i++ ) { + for (DWORD i = 0; i < 8; i++) + { x = plr[pnum].WorldX + plrxoff2[i]; y = plr[pnum].WorldY + plryoff2[i]; - if ( PosOkPlayer(pnum, x, y) ) { - break; + if (PosOkPlayer(pnum, x, y)) + { + break; } - } + } - if ( !PosOkPlayer(pnum, x, y) ) { + if (!PosOkPlayer(pnum, x, y)) + { BOOL posOk = FALSE; int xx; int yy; - for ( int range = 1; range < 50 && !posOk; range++ ) { - for ( yy = -range; yy <= range && !posOk; yy++ ) { + for (int range = 1; range < 50 && !posOk; range++) + { + for (yy = -range; yy <= range && !posOk; yy++) + { y = yy + plr[pnum].WorldY; - for ( xx = -range; xx <= range && !posOk; xx++ ) { + for (xx = -range; xx <= range && !posOk; xx++) + { x = xx + plr[pnum].WorldX; - if ( PosOkPlayer(pnum, x, y) && !PosOkPortal(currlevel, x, y) ) { + if (PosOkPlayer(pnum, x, y) && !PosOkPortal(currlevel, x, y)) + { posOk = TRUE; + } } } } - } } plr[pnum].WorldX = x; plr[pnum].WorldY = y; dPlayer[x][y] = pnum + 1; - if ( pnum == myplr ) { + if (pnum == myplr) + { plr[pnum]._px = x; plr[pnum]._py = y; plr[pnum]._ptargx = x; @@ -3828,7 +4511,8 @@ void __fastcall SyncInitPlrPos(int pnum) void __fastcall SyncInitPlr(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SyncInitPlr: illegal player %d", pnum); } @@ -3838,88 +4522,116 @@ void __fastcall SyncInitPlr(int pnum) void __fastcall CheckStats(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("CheckStats: illegal player %d", pnum); } int c; - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { c = PC_WARRIOR; - } else if ( plr[pnum]._pClass == PC_ROGUE ) { + } + else if (plr[pnum]._pClass == PC_ROGUE) + { c = PC_ROGUE; - } else if ( plr[pnum]._pClass == PC_SORCERER ) { + } + else if (plr[pnum]._pClass == PC_SORCERER) + { c = PC_SORCERER; } - for (int i = 0; i < 4; i++ ) { - switch (i) { - case ATTRIB_STR: - if ( plr[pnum]._pBaseStr > MaxStats[c][ATTRIB_STR] ) { - plr[pnum]._pBaseStr = MaxStats[c][ATTRIB_STR]; - } else if ( plr[pnum]._pBaseStr < 0 ) { - plr[pnum]._pBaseStr = 0; - } - break; - case ATTRIB_MAG: - if ( plr[pnum]._pBaseMag > MaxStats[c][ATTRIB_MAG] ) { - plr[pnum]._pBaseMag = MaxStats[c][ATTRIB_MAG]; - } else if ( plr[pnum]._pBaseMag < 0 ) { - plr[pnum]._pBaseMag = 0; - } - break; - case ATTRIB_DEX: - if ( plr[pnum]._pBaseDex > MaxStats[c][ATTRIB_DEX] ) { - plr[pnum]._pBaseDex = MaxStats[c][ATTRIB_DEX]; - } else if ( plr[pnum]._pBaseDex < 0 ) { - plr[pnum]._pBaseDex = 0; - } - break; - case ATTRIB_VIT: - if ( plr[pnum]._pBaseVit > MaxStats[c][ATTRIB_VIT] ) { - plr[pnum]._pBaseVit = MaxStats[c][ATTRIB_VIT]; - } else if ( plr[pnum]._pBaseVit < 0 ) { - plr[pnum]._pBaseVit = 0; - } - break; + for (int i = 0; i < 4; i++) + { + switch (i) + { + case ATTRIB_STR: + if (plr[pnum]._pBaseStr > MaxStats[c][ATTRIB_STR]) + { + plr[pnum]._pBaseStr = MaxStats[c][ATTRIB_STR]; + } + else if (plr[pnum]._pBaseStr < 0) + { + plr[pnum]._pBaseStr = 0; + } + break; + case ATTRIB_MAG: + if (plr[pnum]._pBaseMag > MaxStats[c][ATTRIB_MAG]) + { + plr[pnum]._pBaseMag = MaxStats[c][ATTRIB_MAG]; + } + else if (plr[pnum]._pBaseMag < 0) + { + plr[pnum]._pBaseMag = 0; + } + break; + case ATTRIB_DEX: + if (plr[pnum]._pBaseDex > MaxStats[c][ATTRIB_DEX]) + { + plr[pnum]._pBaseDex = MaxStats[c][ATTRIB_DEX]; + } + else if (plr[pnum]._pBaseDex < 0) + { + plr[pnum]._pBaseDex = 0; + } + break; + case ATTRIB_VIT: + if (plr[pnum]._pBaseVit > MaxStats[c][ATTRIB_VIT]) + { + plr[pnum]._pBaseVit = MaxStats[c][ATTRIB_VIT]; + } + else if (plr[pnum]._pBaseVit < 0) + { + plr[pnum]._pBaseVit = 0; + } + break; } } } void __fastcall ModifyPlrStr(int pnum, int l) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("ModifyPlrStr: illegal player %d", pnum); } int max = MaxStats[plr[pnum]._pClass][ATTRIB_STR]; - if ( plr[pnum]._pBaseStr + l > max ) { + if (plr[pnum]._pBaseStr + l > max) + { l = max - plr[pnum]._pBaseStr; } plr[pnum]._pStrength += l; plr[pnum]._pBaseStr += l; - if ( plr[pnum]._pClass == PC_ROGUE ) { + if (plr[pnum]._pClass == PC_ROGUE) + { plr[pnum]._pDamageMod = plr[pnum]._pLevel * (plr[pnum]._pStrength + plr[pnum]._pDexterity) / 200; - } else { + } + else + { plr[pnum]._pDamageMod = plr[pnum]._pLevel * plr[pnum]._pStrength / 100; } CalcPlrInv(pnum, TRUE); - if ( pnum == myplr ) { + if (pnum == myplr) + { NetSendCmdParam1(FALSE, CMD_SETSTR, plr[pnum]._pBaseStr); //60 } } void __fastcall ModifyPlrMag(int pnum, int l) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("ModifyPlrMag: illegal player %d", pnum); } int max = MaxStats[plr[pnum]._pClass][ATTRIB_MAG]; - if ( plr[pnum]._pBaseMag + l > max ) { + if (plr[pnum]._pBaseMag + l > max) + { l = max - plr[pnum]._pBaseMag; } @@ -3927,32 +4639,37 @@ void __fastcall ModifyPlrMag(int pnum, int l) plr[pnum]._pBaseMag += l; int ms = l << 6; - if ( plr[pnum]._pClass == PC_SORCERER ) { + if (plr[pnum]._pClass == PC_SORCERER) + { ms *= 2; } plr[pnum]._pMaxManaBase += ms; plr[pnum]._pMaxMana += ms; - if ( !(plr[pnum]._pIFlags & ISPL_NOMANA) ) { + if (!(plr[pnum]._pIFlags & ISPL_NOMANA)) + { plr[pnum]._pManaBase += ms; plr[pnum]._pMana += ms; } CalcPlrInv(pnum, TRUE); - if ( pnum == myplr ) { + if (pnum == myplr) + { NetSendCmdParam1(FALSE, CMD_SETMAG, plr[pnum]._pBaseMag); } } void __fastcall ModifyPlrDex(int pnum, int l) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("ModifyPlrDex: illegal player %d", pnum); } int max = MaxStats[plr[pnum]._pClass][ATTRIB_DEX]; - if ( plr[pnum]._pBaseDex + l > max ) { + if (plr[pnum]._pBaseDex + l > max) + { l = max - plr[pnum]._pBaseDex; } @@ -3960,23 +4677,27 @@ void __fastcall ModifyPlrDex(int pnum, int l) plr[pnum]._pBaseDex += l; CalcPlrInv(pnum, TRUE); - if ( plr[pnum]._pClass == PC_ROGUE ) { + if (plr[pnum]._pClass == PC_ROGUE) + { plr[pnum]._pDamageMod = plr[pnum]._pLevel * (plr[pnum]._pDexterity + plr[pnum]._pStrength) / 200; } - if ( pnum == myplr ) { + if (pnum == myplr) + { NetSendCmdParam1(FALSE, CMD_SETDEX, plr[pnum]._pBaseDex); } } void __fastcall ModifyPlrVit(int pnum, int l) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("ModifyPlrVit: illegal player %d", pnum); } int max = MaxStats[plr[pnum]._pClass][ATTRIB_VIT]; - if ( plr[pnum]._pBaseVit + l > max ) { + if (plr[pnum]._pBaseVit + l > max) + { l = max - plr[pnum]._pBaseVit; } @@ -3984,7 +4705,8 @@ void __fastcall ModifyPlrVit(int pnum, int l) plr[pnum]._pBaseVit += l; int ms = l << 6; - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { ms *= 2; } @@ -3995,28 +4717,32 @@ void __fastcall ModifyPlrVit(int pnum, int l) CalcPlrInv(pnum, TRUE); - if ( pnum == myplr ) { + if (pnum == myplr) + { NetSendCmdParam1(FALSE, CMD_SETVIT, plr[pnum]._pBaseVit); } } void __fastcall SetPlayerHitPoints(int pnum, int newhp) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SetPlayerHitPoints: illegal player %d", pnum); } plr[pnum]._pHitPoints = newhp; plr[pnum]._pHPBase = newhp + plr[pnum]._pMaxHPBase - plr[pnum]._pMaxHP; - if ( pnum == myplr ) { + if (pnum == myplr) + { drawhpflag = TRUE; } } void __fastcall SetPlrStr(int pnum, int v) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SetPlrStr: illegal player %d", pnum); } @@ -4024,9 +4750,12 @@ void __fastcall SetPlrStr(int pnum, int v) CalcPlrInv(pnum, TRUE); int dm; - if ( plr[pnum]._pClass == PC_ROGUE ) { + if (plr[pnum]._pClass == PC_ROGUE) + { dm = plr[pnum]._pLevel * (plr[pnum]._pStrength + plr[pnum]._pDexterity) / 200; - } else { + } + else + { dm = plr[pnum]._pLevel * plr[pnum]._pStrength / 100; } @@ -4035,14 +4764,16 @@ void __fastcall SetPlrStr(int pnum, int v) void __fastcall SetPlrMag(int pnum, int v) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SetPlrMag: illegal player %d", pnum); } plr[pnum]._pBaseMag = v; int m = v << 6; - if ( plr[pnum]._pClass == PC_SORCERER ) { + if (plr[pnum]._pClass == PC_SORCERER) + { m *= 2; } @@ -4053,7 +4784,8 @@ void __fastcall SetPlrMag(int pnum, int v) void __fastcall SetPlrDex(int pnum, int v) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SetPlrDex: illegal player %d", pnum); } @@ -4061,9 +4793,12 @@ void __fastcall SetPlrDex(int pnum, int v) CalcPlrInv(pnum, TRUE); int dm; - if ( plr[pnum]._pClass == PC_ROGUE ) { + if (plr[pnum]._pClass == PC_ROGUE) + { dm = plr[pnum]._pLevel * (plr[pnum]._pStrength + plr[pnum]._pDexterity) / 200; - } else { + } + else + { dm = plr[pnum]._pStrength * plr[pnum]._pLevel / 100; } @@ -4072,14 +4807,16 @@ void __fastcall SetPlrDex(int pnum, int v) void __fastcall SetPlrVit(int pnum, int v) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("SetPlrVit: illegal player %d", pnum); } plr[pnum]._pBaseVit = v; int hp = v << 6; - if ( plr[pnum]._pClass == PC_WARRIOR ) { + if (plr[pnum]._pClass == PC_WARRIOR) + { hp *= 2; } @@ -4090,7 +4827,8 @@ void __fastcall SetPlrVit(int pnum, int v) void __fastcall InitDungMsgs(int pnum) { - if ( (DWORD)pnum >= MAX_PLRS ) { + if ((DWORD)pnum >= MAX_PLRS) + { TermMsg("InitDungMsgs: illegal player %d", pnum); } @@ -4099,57 +4837,90 @@ void __fastcall InitDungMsgs(int pnum) void __cdecl PlayDungMsgs() { - if ( (DWORD)myplr >= MAX_PLRS ) { + if ((DWORD)myplr >= MAX_PLRS) + { TermMsg("PlayDungMsgs: illegal player %d", myplr); } - if ( currlevel == 1 && !plr[myplr]._pLvlVisited[1] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_CATHEDRAL) ) { + if (currlevel == 1 && !plr[myplr]._pLvlVisited[1] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_CATHEDRAL)) + { sfxdelay = 40; - if ( plr[myplr]._pClass == PC_WARRIOR ) { + if (plr[myplr]._pClass == PC_WARRIOR) + { sfxdnum = PS_WARR97; - } else if ( plr[myplr]._pClass == PC_ROGUE ) { + } + else if (plr[myplr]._pClass == PC_ROGUE) + { sfxdnum = PS_ROGUE97; - } else if ( plr[myplr]._pClass == PC_SORCERER ) { + } + else if (plr[myplr]._pClass == PC_SORCERER) + { sfxdnum = PS_MAGE97; } plr[myplr].pDungMsgs = plr[myplr].pDungMsgs | DMSG_CATHEDRAL; - } else if ( currlevel == 5 && !plr[myplr]._pLvlVisited[5] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_CATACOMBS) ) { + } + else if (currlevel == 5 && !plr[myplr]._pLvlVisited[5] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_CATACOMBS)) + { sfxdelay = 40; - if ( plr[myplr]._pClass == PC_WARRIOR ) { + if (plr[myplr]._pClass == PC_WARRIOR) + { sfxdnum = PS_WARR96B; - } else if ( plr[myplr]._pClass == PC_ROGUE ) { + } + else if (plr[myplr]._pClass == PC_ROGUE) + { sfxdnum = PS_ROGUE96; - } else if ( plr[myplr]._pClass == PC_SORCERER ) { + } + else if (plr[myplr]._pClass == PC_SORCERER) + { sfxdnum = PS_MAGE96; } plr[myplr].pDungMsgs |= DMSG_CATACOMBS; - } else if ( currlevel == 9 && !plr[myplr]._pLvlVisited[9] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_CAVES) ) { + } + else if (currlevel == 9 && !plr[myplr]._pLvlVisited[9] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_CAVES)) + { sfxdelay = 40; - if ( plr[myplr]._pClass == PC_WARRIOR ) { + if (plr[myplr]._pClass == PC_WARRIOR) + { sfxdnum = PS_WARR98; - } else if ( plr[myplr]._pClass == PC_ROGUE ) { + } + else if (plr[myplr]._pClass == PC_ROGUE) + { sfxdnum = PS_ROGUE98; - } else if ( plr[myplr]._pClass == PC_SORCERER ) { + } + else if (plr[myplr]._pClass == PC_SORCERER) + { sfxdnum = PS_MAGE98; } plr[myplr].pDungMsgs |= DMSG_CAVES; - } else if ( currlevel == 13 && !plr[myplr]._pLvlVisited[13] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_HELL) ) { + } + else if (currlevel == 13 && !plr[myplr]._pLvlVisited[13] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_HELL)) + { sfxdelay = 40; - if ( plr[myplr]._pClass == PC_WARRIOR ) { + if (plr[myplr]._pClass == PC_WARRIOR) + { sfxdnum = PS_WARR99; - } else if ( plr[myplr]._pClass == PC_ROGUE ) { + } + else if (plr[myplr]._pClass == PC_ROGUE) + { sfxdnum = PS_ROGUE99; - } else if ( plr[myplr]._pClass == PC_SORCERER ) { + } + else if (plr[myplr]._pClass == PC_SORCERER) + { sfxdnum = PS_MAGE99; } plr[myplr].pDungMsgs |= DMSG_HELL; - } else if ( currlevel == 16 && !plr[myplr]._pLvlVisited[15] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_DIABLO) ) { + } + else if (currlevel == 16 && !plr[myplr]._pLvlVisited[15] && gbMaxPlayers == 1 && !(plr[myplr].pDungMsgs & DMSG_DIABLO)) + { sfxdelay = 40; - if ( plr[myplr]._pClass == PC_WARRIOR || plr[myplr]._pClass == PC_ROGUE || plr[myplr]._pClass == PC_SORCERER ) { + if (plr[myplr]._pClass == PC_WARRIOR || plr[myplr]._pClass == PC_ROGUE || plr[myplr]._pClass == PC_SORCERER) + { sfxdnum = PS_DIABLVLINT; } plr[myplr].pDungMsgs |= DMSG_DIABLO; - } else { + } + else + { sfxdelay = 0; } } diff --git a/Stub/diablo.cpp b/Stub/diablo.cpp new file mode 100644 index 000000000..5c66984df --- /dev/null +++ b/Stub/diablo.cpp @@ -0,0 +1,2327 @@ +//HEADER_GOES_HERE + +#include "../types.h" + + + +#include "miniwin_sdl.h" +#include "stubs.h" + + + +#ifndef NO_GLOBALS +int diablo_cpp_init_value; // weak + +HWND ghMainWnd; +int glMid1Seed[NUMLEVELS]; +int glMid2Seed[NUMLEVELS]; +int gnLevelTypeTbl[NUMLEVELS]; +int MouseY; // idb +int MouseX; // idb +bool gbGameLoopStartup; // idb +int glSeedTbl[NUMLEVELS]; +int gbRunGame; // weak +int glMid3Seed[NUMLEVELS]; +int gbRunGameResult; // weak +int zoomflag; // weak +int gbProcessPlayers; // weak +int glEndSeed[NUMLEVELS]; +int dword_5256E8; // weak +HINSTANCE ghInst; // idb +int DebugMonsters[10]; +char cineflag; // weak +int drawpanflag; // weak +int visiondebug; // weak +int scrollflag; /* unused */ +BOOL light4flag; +int leveldebug; // weak +int monstdebug; // weak +int trigdebug; /* unused */ +int setseed; // weak +int debugmonsttypes; // weak +int PauseMode; // weak +int sgnTimeoutCurs; +char sgbMouseDown; // weak +int color_cycle_timer; // weak +#endif + +int diablo_inf = 0x7F800000; // weak + +/* rdata */ + +int fullscreen = 1; // weak +#ifdef _DEBUG +int showintrodebug = 1; +int questdebug = -1; +int debug_mode_key_s; +int debug_mode_key_w; +int debug_mode_key_inverted_v; +int debug_mode_dollar_sign; +int debug_mode_key_d; +int debug_mode_key_i; +int dbgplr; +int dbgqst; +int dbgmon; +int arrowdebug; +int frameflag; +int frameend; +int framerate; +int framestart; +#endif +BOOL FriendlyMode = TRUE; +char *spszMsgTbl[4] = +{ + "I need help! Come Here!", + "Follow me.", + "Here's something for you.", + "Now you DIE!" +}; // weak +char *spszMsgKeyTbl[4] = { "F9", "F10", "F11", "F12" }; // weak + +struct diablo_cpp_init +{ + diablo_cpp_init() + { + diablo_cpp_init_value = diablo_inf; + } +} _diablo_cpp_init; +// 479BF8: using guessed type int diablo_inf; +// 525514: using guessed type int diablo_cpp_init_value; + +void __cdecl FreeGameMem() +{ + void *v0; // ecx + void *v1; // ecx + void *v2; // ecx + void *v3; // ecx + void *v4; // ecx + + music_stop(); + v0 = pDungeonCels; + pDungeonCels = 0; + mem_free_dbg(v0); + v1 = pMegaTiles; + pMegaTiles = 0; + mem_free_dbg(v1); + v2 = pLevelPieces; + pLevelPieces = 0; + mem_free_dbg(v2); + v3 = level_special_cel; + level_special_cel = 0; + mem_free_dbg(v3); + v4 = pSpeedCels; + pSpeedCels = 0; + mem_free_dbg(v4); + FreeMissiles(); + FreeMonsters(); + FreeObjectGFX(); + //FreeEffects(); // Not Working Yet.... + FreeTownerGFX(); +} + +int __fastcall diablo_init_menu(int a1, int bSinglePlayer) +{ + int v2; // esi + int v3; // edi + int v4; // ecx + int pfExitProgram; // [esp+Ch] [ebp-4h] + + v2 = bSinglePlayer; + v3 = a1; + byte_678640 = 1; + while ( 1 ) + { + pfExitProgram = 0; + dword_5256E8 = 0; + if ( !NetInit(v2, &pfExitProgram) ) + break; + byte_678640 = 0; + if ( (v3 || !gbValidSaveFile) + && (InitLevels(), InitQuests(), InitPortals(), InitDungMsgs(myplr), !gbValidSaveFile) + || (v4 = WM_DIABLOADGAME, !dword_5256E8) ) + { + v4 = WM_DIABNEWGAME; + } + run_game_loop(v4); + NetClose(); + pfile_create_player_description(0, 0); + if ( !gbRunGameResult ) + goto LABEL_11; + } + gbRunGameResult = pfExitProgram == 0; +LABEL_11: + SNetDestroy(); + return gbRunGameResult; +} +// 525698: using guessed type int gbRunGameResult; +// 5256E8: using guessed type int dword_5256E8; +// 678640: using guessed type char byte_678640; + +void __fastcall run_game_loop(int uMsg) +{ + //int v3; // eax + bool v5; // zf + //int v6; // eax + signed int v7; // [esp+8h] [ebp-24h] + WNDPROC saveProc; // [esp+Ch] [ebp-20h] + struct tagMSG msg; // [esp+10h] [ebp-1Ch] + + nthread_ignore_mutex(1); + start_game(uMsg); + saveProc = SetWindowProc(GM_Game); + control_update_life_mana(); + msg_process_net_packets(); + gbRunGame = 1; + gbProcessPlayers = 1; + gbRunGameResult = 1; + drawpanflag = 255; + DrawAndBlit(); + PaletteFadeIn(8); + drawpanflag = 255; + gbGameLoopStartup = 1; + nthread_ignore_mutex(0); + while ( gbRunGame ) + { + diablo_color_cyc_logic(); + if ( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) + { + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); + while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) + { + if ( msg.message == WM_QUIT ) + { + gbRunGameResult = 0; + gbRunGame = 0; + break; + } + TranslateMessage(&msg); + DispatchMessage(&msg); + } + if ( !gbRunGame || (v7 = 1, !nthread_has_500ms_passed()) ) + v7 = 0; + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); + v5 = v7 == 0; + } + else + { + //_LOBYTE(v6) = nthread_has_500ms_passed(); + v5 = nthread_has_500ms_passed() == 0; + } + if ( !v5 ) + { + multi_process_network_packets(); + game_loop(gbGameLoopStartup); + msgcmd_send_chat(); + gbGameLoopStartup = 0; + DrawAndBlit(); + } +#ifdef SLEEP + Sleep(1); +#endif + } + if ( (unsigned char)gbMaxPlayers > 1u ) + pfile_write_hero(); + pfile_flush_W(); + PaletteFadeOut(8); + SetCursor(0); + ClearScreenBuffer(); + drawpanflag = 255; + scrollrt_draw_game_screen(1); + SetWindowProc(saveProc); + free_game(); + if ( cineflag ) + { + cineflag = 0; + DoEnding(); + } +} +// 525650: using guessed type int gbRunGame; +// 525698: using guessed type int gbRunGameResult; +// 5256A0: using guessed type int gbProcessPlayers; +// 525718: using guessed type char cineflag; +// 52571C: using guessed type int drawpanflag; +// 679660: using guessed type char gbMaxPlayers; + +void __fastcall start_game(int uMsg) +{ + cineflag = 0; + zoomflag = 1; + InitCursor(); + InitLightTable(); + LoadDebugGFX(); + music_stop(); + ShowProgress(uMsg); + gmenu_init_menu(); + InitLevelCursor(); + sgnTimeoutCurs = 0; + sgbMouseDown = 0; + track_repeat_walk(0); +} +// 52569C: using guessed type int zoomflag; +// 525718: using guessed type char cineflag; +// 525748: using guessed type char sgbMouseDown; + +void __cdecl free_game() +{ + int i; // esi + + FreeControlPan(); + FreeInvGFX(); + FreeGMenu(); + FreeQuestText(); + FreeStoreMem(); + + for(i = 0; i < MAX_PLRS; i++) + FreePlayerGFX(i); + + FreeItemGFX(); + FreeCursor(); + FreeLightTable(); + FreeDebugGFX(); + FreeGameMem(); +} + +bool __cdecl diablo_get_not_running() +{ + SetLastError(0); + CreateEvent(NULL, FALSE, FALSE, "DiabloEvent"); + return GetLastError() != ERROR_ALREADY_EXISTS; +} + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ + HINSTANCE v4; // esi + char Filename[260]; // [esp+8h] [ebp-10Ch] + char value_name[8]; // [esp+10Ch] [ebp-8h] + + v4 = hInstance; +#ifndef DEBUGGER + diablo_reload_process(hInstance); +#endif + ghInst = v4; + if ( RestrictedTest() ) + ErrOkDlg(IDD_DIALOG10, 0, "C:\\Src\\Diablo\\Source\\DIABLO.CPP", 877); + if ( ReadOnlyTest() ) + { + if ( !GetModuleFileName(ghInst, Filename, 0x104u) ) + *Filename = '\0'; + DirErrorDlg(Filename); + } + ShowCursor(FALSE); + srand(GetTickCount()); + InitHash(); + exception_get_filter(); + if ( !diablo_find_window("DIABLO") && diablo_get_not_running() ) + { + diablo_init_screen(); + diablo_parse_flags(lpCmdLine); + init_create_window(nCmdShow); + sound_init(); + UiInitialize(); +#ifdef _DEBUG + if ( showintrodebug ) + play_movie("gendata\\logo.smk", 1); +#else + play_movie("gendata\\logo.smk", 1); +#endif + strcpy(value_name, "Intro"); + if ( !SRegLoadValue("Diablo", value_name, 0, (int *)&hInstance) ) + hInstance = (HINSTANCE)1; + if ( hInstance ) + play_movie("gendata\\diablo1.smk", 1); + SRegSaveValue("Diablo", value_name, 0, 0); +#ifdef _DEBUG + if ( showintrodebug ) + { + UiTitleDialog(7); + BlackPalette(); + } +#else + UiTitleDialog(7); + BlackPalette(); +#endif + mainmenu_loop(); + UiDestroy(); + SaveGamma(); + if ( ghMainWnd ) + { +#ifndef FASTER + Sleep(300); +#endif + DestroyWindow(ghMainWnd); + } + } + return 0; +} + +void __fastcall diablo_parse_flags(char *args) +{ +#ifdef _DEBUG + int n; // edi + int v15; // eax +#endif + while ( *args ) + { + for ( ; isspace(*args); ++args ) + ; + if ( !_strcmpi("dd_emulate", args) ) + { + gbEmulate = 1; + args += strlen("dd_emulate"); + } + else if ( !_strcmpi("dd_backbuf", args) ) + { + gbBackBuf = 1; + args += strlen("dd_backbuf"); + } + else if ( !_strcmpi("ds_noduplicates", args) ) + { + gbDupSounds = 0; + args += strlen("ds_noduplicates"); + } + else + { +#ifdef _DEBUG + switch ( tolower(*args++) ) + { + case '^': // god mod with all spells as skills + debug_mode_key_inverted_v = 1; + break; + case '$': // demi-god + debug_mode_dollar_sign = 1; + break; + /*case 'b': // enable drop log + debug_mode_key_b = 1; + break;*/ + case 'd': // no startup video+??? + showintrodebug = 0; + debug_mode_key_d = 1; + break; + case 'f': // draw fps + EnableFrameCount(); + break; + case 'i': // disable network timeout + debug_mode_key_i = 1; + break; + /*case 'j': // : init trigger at level + for ( ; isspace(*args); ++args ) + ; + for ( n = 0; isdigit(*args); n = v15 + 10 * n - 48 ) + v15 = *args++; + debug_mode_key_J_trigger = n; + break;*/ + case 'l': // : start in level as type + setlevel = 0; + for ( leveldebug = 1; isspace(*args); ++args ) + ; + for ( n = 0; isdigit(*args); n = v15 + 10 * n - 48 ) + v15 = *args++; + for ( leveltype = n; isspace(*args); ++args ) + ; + for ( n = 0; isdigit(*args); n = v15 + 10 * n - 48 ) + v15 = *args++; + currlevel = n; + plr[0].plrlevel = n; + break; + case 'm': // : add debug monster, up to 10 allowed + for ( monstdebug = 1; isspace(*args); ++args ) + ; + for ( n = 0; isdigit(*args); n = v15 + 10 * n - 48 ) + v15 = *args++; + DebugMonsters[debugmonsttypes++] = n; + break; + case 'n': // disable startup video + showintrodebug = 0; + break; + case 'q': // : force a certain quest + for ( ; isspace(*args); ++args ) + ; + for ( n = 0; isdigit(*args); n = v15 + 10 * n - 48 ) + v15 = *args++; + questdebug = n; + break; + case 'r': // : set map seed to + for ( ; isspace(*args); ++args ) + ; + for ( n = 0; isdigit(*args); n = v15 + 10 * n - 48 ) + v15 = *args++; + setseed = n; + break; + case 's': // unused + debug_mode_key_s = 1; + break; + case 't': // : sets current quest level + leveldebug = 1; + for ( setlevel = 1; isspace(*args); ++args ) + ; + for ( n = 0; isdigit(*args); n = v15 + 10 * n - 48 ) + v15 = *args++; + setlvlnum = n; + break; + case 'v': // draw yellow debug tiles + visiondebug = 1; + break; + case 'w': // rest of the cheats, some only in town + debug_mode_key_w = 1; + break; + case 'x': + fullscreen = 0; + break; + default: + break; + } +#else + tolower(*args++); +#endif + } + } +} +// 4A22D6: using guessed type char gbDupSounds; +// 52A548: using guessed type char gbBackBuf; +// 52A549: using guessed type char gbEmulate; + +void __cdecl diablo_init_screen() +{ + int v0; // ecx + int *v1; // eax + + v0 = 0; + MouseX = 320; + MouseY = 240; + ScrollInfo._sdx = 0; + ScrollInfo._sdy = 0; + ScrollInfo._sxoff = 0; + ScrollInfo._syoff = 0; + ScrollInfo._sdir = 0; + v1 = screen_y_times_768; + do + { + *v1 = v0; + ++v1; + v0 += 768; + } + while ( (signed int)v1 < (signed int)&screen_y_times_768[1024] ); + ClrDiabloMsg(); +} +// 69CEFC: using guessed type int scrollrt_cpp_init_value; + +BOOL __fastcall diablo_find_window(LPCSTR lpClassName) +{ + HWND result; // eax + HWND v2; // esi + HWND v3; // eax + HWND v4; // edi + + result = FindWindow(lpClassName, 0); + v2 = result; + if ( !result ) + return 0; + + v3 = GetLastActivePopup(result); + if ( v3 ) + v2 = v3; + v4 = GetTopWindow(v2); + if ( !v4 ) + v4 = v2; + SetForegroundWindow(v2); + SetFocus(v4); + return 1; +} + +void __fastcall diablo_reload_process(HMODULE hModule) +{ + char *i; // eax + DWORD dwSize; // esi + BOOL v3; // edi + _DWORD *v4; // eax + _DWORD *v5; // esi + HWND v6; // eax + char Name[276]; // [esp+Ch] [ebp-29Ch] + char Filename[260]; // [esp+120h] [ebp-188h] + STARTUPINFOA si; // [esp+224h] [ebp-84h] + SYSTEM_INFO sinf; // [esp+268h] [ebp-40h] + PROCESS_INFORMATION pi; // [esp+28Ch] [ebp-1Ch] + DWORD dwProcessId; // [esp+29Ch] [ebp-Ch] + HANDLE hMap; // [esp+2A0h] [ebp-8h] + HWND hWnd; // [esp+2A4h] [ebp-4h] + + *Filename = empty_string; + memset(Filename + 1, 0, sizeof(Filename) - 1); +// *(_WORD *)&Filename[257] = 0; +// Filename[259] = 0; + GetModuleFileName(hModule, Filename, 0x104u); + wsprintf(Name, "Reload-%s", Filename); + for ( i = Name; *i; ++i ) + { + if ( *i == '\\' ) + *i = '/'; + } + GetSystemInfo(&sinf); + dwSize = sinf.dwPageSize; + if ( sinf.dwPageSize < 4096 ) + dwSize = 4096; + hMap = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, SEC_COMMIT|PAGE_READWRITE, 0, dwSize, Name); + v3 = GetLastError() != ERROR_ALREADY_EXISTS; + if ( hMap ) + { + v4 = (unsigned int *)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, dwSize); + v5 = v4; + if ( v4 ) + { + if ( v3 ) + { + *v4 = -1; + v4[1] = 0; + memset(&si, 0, sizeof(si)); + si.cb = sizeof(si); + CreateProcess(Filename, NULL, NULL, NULL, FALSE, CREATE_NEW_PROCESS_GROUP, NULL, NULL, &si, &pi); + WaitForInputIdle(pi.hProcess, 0xFFFFFFFF); + CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); + while ( *v5 < 0 ) + Sleep(1000); + UnmapViewOfFile(v5); + CloseHandle(hMap); + ExitProcess(0); + } + if ( InterlockedIncrement((long *)v4) ) + { + v6 = GetForegroundWindow(); + do + { + hWnd = v6; + v6 = GetWindow(v6, 3u); + } + while ( v6 ); + while ( 1 ) + { + GetWindowThreadProcessId(hWnd, &dwProcessId); + if ( dwProcessId == v5[1] ) + break; + hWnd = GetWindow(hWnd, 2u); + if ( !hWnd ) + goto LABEL_23; + } + SetForegroundWindow(hWnd); +LABEL_23: + UnmapViewOfFile(v5); + CloseHandle(hMap); + ExitProcess(0); + } + v5[1] = GetCurrentProcessId(); + } + } +} + +int __cdecl PressEscKey() +{ + int result; // eax + + result = 0; + if ( doomflag ) + { + doom_close(); + result = 1; + } + if ( helpflag ) + { + helpflag = 0; + result = 1; + } + if ( qtextflag ) + { + qtextflag = 0; + sfx_stop(); + } + else + { + if ( !stextflag ) + goto LABEL_10; + STextESC(); + } + result = 1; +LABEL_10: + if ( msgflag ) + { + msgdelay = 0; + result = 1; + } + if ( talkflag ) + { + control_reset_talk(); + result = 1; + } + if ( dropGoldFlag ) + { + control_drop_gold(VK_ESCAPE); + result = 1; + } + if ( spselflag ) + { + spselflag = 0; + result = 1; + } + return result; +} +// 4B84DC: using guessed type int dropGoldFlag; +// 4B8960: using guessed type int talkflag; +// 4B8C98: using guessed type int spselflag; +// 52575C: using guessed type int doomflag; +// 52B9F0: using guessed type char msgdelay; +// 52B9F1: using guessed type char msgflag; +// 646D00: using guessed type char qtextflag; +// 6AA705: using guessed type char stextflag; + +LRESULT __stdcall DisableInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + bool v5; // zf + + if ( uMsg <= WM_LBUTTONDOWN ) + { + if ( uMsg != WM_LBUTTONDOWN ) + { + if ( uMsg >= WM_KEYFIRST + && (uMsg <= WM_CHAR + || uMsg == WM_SYSKEYDOWN + || uMsg == WM_SYSCOMMAND + || uMsg == WM_MOUSEFIRST) ) + { + return 0; + } + return MainWndProc(hWnd, uMsg, wParam, lParam); + } + if ( !sgbMouseDown ) + { + sgbMouseDown = 1; +LABEL_21: + SetCapture(hWnd); + return 0; + } + return 0; + } + if ( uMsg == WM_LBUTTONUP ) + { + v5 = sgbMouseDown == 1; + goto LABEL_23; + } + if ( uMsg != WM_RBUTTONDOWN ) + { + if ( uMsg != WM_RBUTTONUP ) + { + if ( uMsg == WM_CAPTURECHANGED ) + { + if ( hWnd != (HWND)lParam ) + sgbMouseDown = 0; + return 0; + } + return MainWndProc(hWnd, uMsg, wParam, lParam); + } + v5 = sgbMouseDown == 2; +LABEL_23: + if ( v5 ) + { + sgbMouseDown = 0; + ReleaseCapture(); + } + return 0; + } + if ( !sgbMouseDown ) + { + sgbMouseDown = 2; + goto LABEL_21; + } + return 0; +} +// 525748: using guessed type char sgbMouseDown; + +LRESULT __stdcall GM_Game(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + if ( uMsg > WM_LBUTTONDOWN ) + { + if ( uMsg == WM_LBUTTONUP ) + { + MouseX = (unsigned short)lParam; + MouseY = (unsigned int)lParam >> 16; + if ( sgbMouseDown != 1 ) + return 0; + sgbMouseDown = 0; + LeftMouseUp(); + track_repeat_walk(0); + } + else + { + if ( uMsg == WM_RBUTTONDOWN ) + { + MouseX = (unsigned short)lParam; + MouseY = (unsigned int)lParam >> 16; + if ( !sgbMouseDown ) + { + sgbMouseDown = 2; + SetCapture(hWnd); + RightMouseDown(); + } + return 0; + } + if ( uMsg != WM_RBUTTONUP ) + { + if ( uMsg == WM_CAPTURECHANGED ) + { + if ( hWnd != (HWND)lParam ) + { + sgbMouseDown = 0; + track_repeat_walk(0); + } + } + else if ( uMsg > WM_DIAB && uMsg <= WM_DIABRETOWN ) + { + if ( (unsigned char)gbMaxPlayers > 1u ) + pfile_write_hero(); + nthread_ignore_mutex(1); + PaletteFadeOut(8); + FreeMonsterSnd(); + music_stop(); + track_repeat_walk(0); + sgbMouseDown = 0; + ReleaseCapture(); + ShowProgress(uMsg); + drawpanflag = 255; + DrawAndBlit(); + if ( gbRunGame ) + PaletteFadeIn(8); + nthread_ignore_mutex(0); + gbGameLoopStartup = 1; + return 0; + } + return MainWndProc(hWnd, uMsg, wParam, lParam); + } + MouseX = (unsigned short)lParam; + MouseY = (unsigned int)lParam >> 16; + if ( sgbMouseDown != 2 ) + return 0; + sgbMouseDown = 0; + } + ReleaseCapture(); + return 0; + } + switch ( uMsg ) + { + case WM_LBUTTONDOWN: + MouseX = (unsigned short)lParam; + MouseY = (unsigned int)lParam >> 16; + if ( !sgbMouseDown ) + { + sgbMouseDown = 1; + SetCapture(hWnd); + track_repeat_walk(LeftMouseDown(wParam)); + } + return 0; + case WM_KEYFIRST: + PressKey(wParam); + return 0; + case WM_KEYUP: + ReleaseKey(wParam); + return 0; + case WM_CHAR: + PressChar(wParam); + return 0; + case WM_SYSKEYDOWN: + if ( PressSysKey(wParam) ) + return 0; + return MainWndProc(hWnd, uMsg, wParam, lParam); + case WM_SYSCOMMAND: + if ( wParam == SC_CLOSE ) + { + gbRunGame = 0; + gbRunGameResult = 0; + return 0; + } + return MainWndProc(hWnd, uMsg, wParam, lParam); + } + if ( uMsg != WM_MOUSEFIRST ) + return MainWndProc(hWnd, uMsg, wParam, lParam); + MouseX = (unsigned short)lParam; + MouseY = (unsigned int)lParam >> 16; + gmenu_on_mouse_move((unsigned short)lParam); + return 0; +} +// 525650: using guessed type int gbRunGame; +// 525698: using guessed type int gbRunGameResult; +// 52571C: using guessed type int drawpanflag; +// 525748: using guessed type char sgbMouseDown; +// 679660: using guessed type char gbMaxPlayers; + +bool __fastcall LeftMouseDown(int a1) +{ + int v1; // edi + int v3; // eax + bool v6; // zf + int v7; // ecx + int v8; // eax + unsigned char v9; // dl + unsigned char v11; // dl + unsigned short v12; // ax + unsigned char v13; // dl + unsigned short v15; // [esp-8h] [ebp-10h] + + v1 = a1; + +const Uint8 *keystate = SDL_GetKeyboardState(NULL); + +if (keystate[SDL_SCANCODE_LSHIFT]) { + printf("LSHIFT PRESSED\n"); + v1 = 5 ; + } + + + + + + if ( gmenu_left_mouse(1) || control_check_talk_btn() || sgnTimeoutCurs ) + return 0; + if ( deathflag ) + { + control_check_btn_press(); + return 0; + } + if ( PauseMode == 2 ) + return 0; + if ( doomflag ) + { + doom_close(); + return 0; + } + if ( spselflag ) + { + SetSpell(); + return 0; + } + if ( stextflag ) + { + CheckStoreBtn(); + return 0; + } + if ( MouseY >= 352 ) + { + if ( !talkflag && !dropGoldFlag ) + { + if ( !gmenu_exception() ) + CheckInvScrn(); + } + DoPanBtn(); + if ( pcurs <= 1 || pcurs >= 12 ) + return 0; + goto LABEL_48; + } + if ( gmenu_exception() || TryIconCurs() ) + return 0; + if ( questlog && MouseX > 32 && MouseX < 288 && MouseY > 32 && MouseY < 308 ) + { + QuestlogESC(); + return 0; + } + if ( qtextflag ) + { + qtextflag = 0; + sfx_stop(); + return 0; + } + if ( chrflag && MouseX < 320 ) + { + CheckChrBtns(); + return 0; + } + if ( invflag && MouseX > 320 ) + { + if ( !dropGoldFlag ) + CheckInvItem(); + return 0; + } + if ( sbookflag && MouseX > 320 ) + { + CheckSBook(); + return 0; + } + if ( pcurs >= CURSOR_FIRSTITEM ) + { + if ( !TryInvPut() ) + return 0; + NetSendCmdPItem(1u, CMD_PUTITEM, cursmx, cursmy); +LABEL_48: + SetCursor(CURSOR_HAND); + return 0; + } + v3 = 21720 * myplr; + if ( plr[myplr]._pStatPts && !spselflag ) + CheckLvlBtn(); + if ( lvlbtndown ) + return 0; + if ( leveltype != DTYPE_TOWN ) + { + v7 = abs(plr[myplr].WorldX - cursmx) < 2 && abs(plr[myplr].WorldY - cursmy) < 2; + _HIWORD(v8) = _HIWORD(pcurs); + if ( pcursitem != -1 && pcurs == 1 && v1 != 5 ) + { + _LOWORD(v8) = pcursitem; + NetSendCmdLocParam1(1u, (invflag == 0) + CMD_GOTOGETITEM, cursmx, cursmy, v8); +LABEL_96: + if ( pcursitem != -1 ) + return 0; + v6 = pcursobj == -1; + goto LABEL_98; + } + if ( pcursobj != -1 ) + { + if ( v1 != 5 || v7 && object[pcursobj]._oBreak == 1 ) + { + NetSendCmdLocParam1(1u, (pcurs == 5) + CMD_OPOBJXY, cursmx, cursmy, pcursobj); + goto LABEL_95; + } + } + if ( plr[myplr]._pwtype == 1 ) + { + if ( v1 == 5 ) + { + v9 = CMD_RATTACKXY; +LABEL_84: + NetSendCmdLoc(1u, v9, cursmx, cursmy); + goto LABEL_95; + } + if ( pcursmonst != -1 ) + { + v15 = pcursmonst; + if ( !CanTalkToMonst(pcursmonst) ) + { + v11 = CMD_RATTACKID; +LABEL_89: + NetSendCmdParam1(1u, v11, v15); + goto LABEL_96; + } +LABEL_88: + v11 = CMD_ATTACKID; + goto LABEL_89; + } + _LOBYTE(v12) = pcursplr; + if ( pcursplr == -1 || FriendlyMode ) + goto LABEL_96; + v13 = CMD_RATTACKPID; + } + else + { + if ( v1 == 5 ) + { + if ( pcursmonst == -1 || !CanTalkToMonst(pcursmonst) ) + { + v9 = CMD_SATTACKXY; + goto LABEL_84; + } + v12 = pcursmonst; + v13 = CMD_ATTACKID; +LABEL_94: + NetSendCmdParam1(1u, v13, v12); +LABEL_95: + if ( v1 == 5 ) + return 0; + goto LABEL_96; + } + if ( pcursmonst != -1 ) + { + v15 = pcursmonst; + goto LABEL_88; + } + _LOBYTE(v12) = pcursplr; + if ( pcursplr == -1 || FriendlyMode ) + goto LABEL_96; + v13 = CMD_ATTACKPID; + } + v12 = (char)v12; + goto LABEL_94; + } + if ( pcursitem != -1 && pcurs == 1 ) + { + _LOWORD(v3) = pcursitem; + NetSendCmdLocParam1(1u, (invflag == 0) + CMD_GOTOGETITEM, cursmx, cursmy, v3); + } + if ( pcursmonst != -1 ) + NetSendCmdLocParam1(1u, CMD_TALKXY, cursmx, cursmy, pcursmonst); + v6 = pcursitem == -1; +LABEL_98: + if ( v6 && pcursmonst == -1 && pcursplr == -1 ) + return 1; + return 0; +} +// 484368: using guessed type int FriendlyMode; +// 4B84DC: using guessed type int dropGoldFlag; +// 4B851C: using guessed type int lvlbtndown; +// 4B8960: using guessed type int talkflag; +// 4B8968: using guessed type int sbookflag; +// 4B8C98: using guessed type int spselflag; +// 4B8CC0: using guessed type char pcursitem; +// 4B8CC1: using guessed type char pcursobj; +// 4B8CC2: using guessed type char pcursplr; +// 525740: using guessed type int PauseMode; +// 52575C: using guessed type int doomflag; +// 5BB1ED: using guessed type char leveltype; +// 646D00: using guessed type char qtextflag; +// 69BD04: using guessed type int questlog; +// 6AA705: using guessed type char stextflag; + +bool __cdecl TryIconCurs() +{ + unsigned char v0; // dl + int v1; // edx + int v2; // eax + int v3; // eax + int v4; // ST0C_4 + int v5; // eax + + switch ( pcurs ) + { + case CURSOR_RESURRECT: + v0 = CMD_RESURRECT; +LABEL_3: + NetSendCmdParam1(1u, v0, pcursplr); + return 1; + case CURSOR_HEALOTHER: + v0 = CMD_HEALOTHER; + goto LABEL_3; + case CURSOR_TELEKINESIS: + DoTelekinesis(); + return 1; + case CURSOR_IDENTIFY: + if ( pcursinvitem != -1 ) + { + CheckIdentify(myplr, pcursinvitem); + return 1; + } +LABEL_26: + SetCursor(CURSOR_HAND); + return 1; + case CURSOR_REPAIR: + if ( pcursinvitem != -1 ) + { + DoRepair(myplr, pcursinvitem); + return 1; + } + goto LABEL_26; + case CURSOR_RECHARGE: + if ( pcursinvitem != -1 ) + { + DoRecharge(myplr, pcursinvitem); + return 1; + } + goto LABEL_26; + case CURSOR_TELEPORT: + v1 = plr[myplr]._pTSpell; + if ( pcursmonst == -1 ) + { + if ( pcursplr == -1 ) + { + v4 = GetSpellLevel(myplr, v1); + v5 = 21720 * myplr; + _LOWORD(v5) = plr[myplr]._pTSpell; + NetSendCmdLocParam2(1u, CMD_TSPELLXY, cursmx, cursmy, v5, v4); + } + else + { + v3 = GetSpellLevel(myplr, v1); + NetSendCmdParam3(1u, CMD_TSPELLPID, pcursplr, plr[myplr]._pTSpell, v3); + } + } + else + { + v2 = GetSpellLevel(myplr, v1); + NetSendCmdParam3(1u, CMD_TSPELLID, pcursmonst, plr[myplr]._pTSpell, v2); + } + goto LABEL_26; + } + if ( pcurs == CURSOR_DISARM && pcursobj == -1 ) + goto LABEL_26; + return 0; +} +// 4B8CB8: using guessed type char pcursinvitem; +// 4B8CC1: using guessed type char pcursobj; +// 4B8CC2: using guessed type char pcursplr; + +void __cdecl LeftMouseUp() +{ + gmenu_left_mouse(0); + control_release_talk_btn(); + if ( panbtndown ) + CheckBtnUp(); + if ( chrbtnactive ) + ReleaseChrBtns(); + if ( lvlbtndown ) + ReleaseLvlBtn(); + if ( stextflag ) + ReleaseStoreBtn(); +} +// 4B851C: using guessed type int lvlbtndown; +// 4B87A8: using guessed type int chrbtnactive; +// 4B8C90: using guessed type int panbtndown; +// 6AA705: using guessed type char stextflag; + +void __cdecl RightMouseDown() +{ + if ( !gmenu_exception() && sgnTimeoutCurs == CURSOR_NONE && PauseMode != 2 && !plr[myplr]._pInvincible ) + { + if ( doomflag ) + { + doom_close(); + } + else if ( !stextflag ) + { + if ( spselflag ) + { + SetSpell(); + } + else if ( MouseY >= 352 + || (!sbookflag || MouseX <= 320) + && !TryIconCurs() + && (pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem)) ) + { + if ( pcurs == 1 ) + { + if ( pcursinvitem == -1 || !UseInvItem(myplr, pcursinvitem) ) + CheckPlrSpell(); + } + else if ( pcurs > 1 && pcurs < 12 ) + { + SetCursor(CURSOR_HAND); + } + } + } + } +} +// 4B8968: using guessed type int sbookflag; +// 4B8C98: using guessed type int spselflag; +// 4B8CB8: using guessed type char pcursinvitem; +// 525740: using guessed type int PauseMode; +// 52575C: using guessed type int doomflag; +// 6AA705: using guessed type char stextflag; + +bool __fastcall PressSysKey(int wParam) +{ + if ( gmenu_exception() || wParam != VK_F10 ) + return 0; + diablo_hotkey_msg(1); + return 1; +} + +void __fastcall diablo_hotkey_msg(int dwMsg) +{ + int v1; // esi + char *v2; // eax + char Filename[260]; // [esp+4h] [ebp-154h] + char ReturnedString[80]; // [esp+108h] [ebp-50h] + + v1 = dwMsg; + if ( gbMaxPlayers != 1 ) + { + if ( !GetModuleFileName(ghInst, Filename, 0x104u) ) + TermMsg("Can't get program name"); + v2 = strrchr(Filename, '\\'); + if ( v2 ) + *v2 = 0; + strcat(Filename, "\\Diablo.ini"); + GetPrivateProfileString("NetMsg", spszMsgKeyTbl[v1], spszMsgTbl[v1], ReturnedString, 0x50u, Filename); + NetSendCmdString(-1, ReturnedString); + } +} +// 48436C: using guessed type char *spszMsgTbl[4]; +// 48437C: using guessed type char *spszMsgKeyTbl[4]; +// 679660: using guessed type char gbMaxPlayers; + +void __fastcall ReleaseKey(int vkey) +{ + if ( vkey == VK_SNAPSHOT ) + CaptureScreen(); +} + +void __fastcall PressKey(int vkey) +{ + int v1; // esi + int v2; // ecx + int v3; // ecx + signed int v4; // eax + + v1 = vkey; + if ( !gmenu_presskeys(vkey) && !control_presskeys(v1) ) + { + if ( !deathflag ) + goto LABEL_113; + if ( sgnTimeoutCurs == CURSOR_NONE ) + { + if ( v1 == VK_F9 ) + diablo_hotkey_msg(0); + if ( v1 == VK_F10 ) + diablo_hotkey_msg(1); + if ( v1 == VK_F11 ) + diablo_hotkey_msg(2); + if ( v1 == VK_F12 ) + diablo_hotkey_msg(3); + if ( v1 == VK_RETURN ) + control_type_message(); + if ( v1 == VK_ESCAPE ) + { +LABEL_113: + if ( v1 == VK_ESCAPE ) + { + if ( !PressEscKey() ) + { + track_repeat_walk(0); + gamemenu_previous(); + } + return; + } + if ( sgnTimeoutCurs == CURSOR_NONE && !dropGoldFlag ) + { + if ( v1 == VK_PAUSE ) + { + diablo_pause_game(); + return; + } + if ( PauseMode != 2 ) + { + switch ( v1 ) + { + case VK_RETURN: + if ( stextflag ) + { + STextEnter(); + } + else if ( questlog ) + { + QuestlogEnter(); + } + else + { + control_type_message(); + } + return; + case VK_F1: + if ( helpflag ) + { + helpflag = 0; + return; + } + if ( stextflag ) + { + ClearPanel(); + AddPanelString("No help available", 1); + AddPanelString("while in stores", 1); + track_repeat_walk(0); + return; + } + invflag = 0; + chrflag = 0; + sbookflag = 0; + spselflag = 0; + if ( qtextflag && leveltype == DTYPE_TOWN) + { + qtextflag = 0; + sfx_stop(); + } + questlog = 0; + automapflag = 0; + msgdelay = 0; + gamemenu_off(); + DisplayHelp(); +LABEL_110: + doom_close(); + return; +#ifdef _DEBUG + case VK_F3: + if ( pcursitem != -1 ) + { + sprintf(tempstr, "IDX = %i : Seed = %i : CF = %i", item[pcursitem].IDidx, item[pcursitem]._iSeed, item[pcursitem]._iCreateInfo); + NetSendCmdString(1 << myplr, tempstr); + } + sprintf(tempstr, "Numitems : %i", numitems); + NetSendCmdString(1 << myplr, tempstr); + return; + case VK_F4: + PrintDebugQuest(); + return; +#endif + case VK_F5: + v2 = 0; + goto LABEL_48; + case VK_F6: + v2 = 1; + goto LABEL_48; + case VK_F7: + v2 = 2; + goto LABEL_48; + case VK_F8: + v2 = 3; +LABEL_48: + if ( spselflag ) + SetSpeedSpell(v2); + else + ToggleSpell(v2); + return; + case VK_F9: + v3 = 0; +LABEL_59: + diablo_hotkey_msg(v3); + return; + case VK_F10: + v3 = 1; + goto LABEL_59; + case VK_F11: + v3 = 2; + goto LABEL_59; + case VK_F12: + v3 = 3; + goto LABEL_59; + case VK_UP: + if ( stextflag ) + { + STextUp(); + } + else if ( questlog ) + { + QuestlogUp(); + } + else if ( helpflag ) + { + HelpScrollUp(); + } + else if ( automapflag ) + { + AutomapUp(); + } + return; + case VK_DOWN: + if ( stextflag ) + { + STextDown(); + } + else if ( questlog ) + { + QuestlogDown(); + } + else if ( helpflag ) + { + HelpScrollDown(); + } + else if ( automapflag ) + { + AutomapDown(); + } + return; + case VK_PRIOR: + if ( stextflag ) + STextPrior(); + return; + case VK_NEXT: + if ( stextflag ) + STextNext(); + return; + case VK_LEFT: + if ( automapflag && !talkflag ) + AutomapLeft(); + return; + case VK_RIGHT: + if ( automapflag && !talkflag ) + AutomapRight(); + return; + case VK_TAB: + DoAutoMap(); + return; + case VK_SPACE: + if ( !chrflag ) + { + if ( !invflag ) + { +LABEL_106: + helpflag = 0; + invflag = 0; + chrflag = 0; + sbookflag = 0; + spselflag = 0; + if ( qtextflag && leveltype == DTYPE_TOWN ) + { + qtextflag = 0; + sfx_stop(); + } + questlog = 0; + automapflag = 0; + msgdelay = 0; + gamemenu_off(); + goto LABEL_110; + } + v4 = MouseX; + if ( MouseX >= 480 || MouseY >= 352 ) + { +LABEL_101: + if ( !invflag && chrflag && v4 > 160 && MouseY < 352 ) + SetCursorPos(v4 - 160, MouseY); + goto LABEL_106; + } + SetCursorPos(MouseX + 160, MouseY); + } + v4 = MouseX; + goto LABEL_101; + } + } + } + } + } + } +} +// 4B84DC: using guessed type int dropGoldFlag; +// 4B8960: using guessed type int talkflag; +// 4B8968: using guessed type int sbookflag; +// 4B8C98: using guessed type int spselflag; +// 525740: using guessed type int PauseMode; +// 52B9F0: using guessed type char msgdelay; +// 5BB1ED: using guessed type char leveltype; +// 646D00: using guessed type char qtextflag; +// 69BD04: using guessed type int questlog; +// 6AA705: using guessed type char stextflag; + +void __cdecl diablo_pause_game() +{ + if ( (unsigned char)gbMaxPlayers <= 1u ) + { + if ( PauseMode ) + { + PauseMode = 0; + } + else + { + PauseMode = 2; + FreeMonsterSnd(); + track_repeat_walk(0); + } + drawpanflag = 255; + } +} +// 52571C: using guessed type int drawpanflag; +// 525740: using guessed type int PauseMode; +// 679660: using guessed type char gbMaxPlayers; + +void __fastcall PressChar(int vkey) +{ + int v1; // ebx + BOOL v4; // ecx + int v5; // ecx + int v6; // eax + BOOL v7; // ecx + int v9; // ecx + int v10; // eax + int v11; // eax + int v12; // eax + int v13; // eax + int v14; // eax + int v15; // eax + int v16; // eax + int v18; // [esp-4h] [ebp-8h] + + v1 = vkey; + if ( !gmenu_exception() && !control_talk_last_key(v1) && sgnTimeoutCurs == CURSOR_NONE && !deathflag ) + { + if ( (_BYTE)v1 == 'p' || (_BYTE)v1 == 'P' ) + { + diablo_pause_game(); + } + else if ( PauseMode != 2 ) + { + if ( doomflag ) + { + doom_close(); + return; + } + if ( dropGoldFlag ) + { + control_drop_gold(v1); + return; + } + switch ( v1 ) + { + case '!': + case '1': + v9 = myplr; + v10 = plr[myplr].SpdList[0]._itype; + if ( v10 != -1 && v10 != 11 ) + { + v18 = 47; + goto LABEL_72; + } + return; + case '#': + case '3': + v9 = myplr; + v12 = plr[myplr].SpdList[2]._itype; + if ( v12 != -1 && v12 != 11 ) + { + v18 = 49; + goto LABEL_72; + } + return; + case '$': + case '4': + v9 = myplr; + v13 = plr[myplr].SpdList[3]._itype; + if ( v13 != -1 && v13 != 11 ) + { + v18 = 50; + goto LABEL_72; + } + return; + case '%': + case '5': + v9 = myplr; + v14 = plr[myplr].SpdList[4]._itype; + if ( v14 != -1 && v14 != 11 ) + { + v18 = 51; + goto LABEL_72; + } + return; + case '&': + case '7': + v9 = myplr; + v16 = plr[myplr].SpdList[6]._itype; + if ( v16 != -1 && v16 != 11 ) + { + v18 = 53; + goto LABEL_72; + } + return; + case '*': + case '8': +#ifdef _DEBUG + if ( debug_mode_key_inverted_v || debug_mode_key_w ) + { + NetSendCmd(1, CMD_CHEAT_EXPERIENCE); + return; + } +#endif + v9 = myplr; + if ( plr[myplr].SpdList[7]._itype != -1 + && plr[myplr].SpdList[7]._itype != 11 ) + { + v18 = 54; + goto LABEL_72; + } + return; + case '+': + case '=': + if ( automapflag ) + AutomapZoomIn(); + return; + case '-': + case '_': + if ( automapflag ) + AutomapZoomOut(); + return; + case '2': + case '@': + v9 = myplr; + v11 = plr[myplr].SpdList[1]._itype; + if ( v11 != -1 && v11 != 11 ) + { + v18 = 48; + goto LABEL_72; + } + return; + case '6': + case '^': + v9 = myplr; + v15 = plr[myplr].SpdList[5]._itype; + if ( v15 != -1 && v15 != 11 ) + { + v18 = 52; +LABEL_72: + UseInvItem(v9, v18); + } + return; + case 'B': + case 'b': + if ( !stextflag ) + { + invflag = 0; + sbookflag = sbookflag == 0; + } + return; + case 'C': + case 'c': + if ( !stextflag ) + { + questlog = 0; + v7 = chrflag == 0; + chrflag = chrflag == 0; + if ( !v7 || invflag ) + goto LABEL_18; + goto LABEL_24; + } + return; + case 'F': + case 'f': + IncreaseGamma(); + return; + case 'G': + case 'g': + DecreaseGamma(); + return; + case 'I': + case 'i': + if ( stextflag ) + return; + sbookflag = 0; + v4 = invflag == 0; + invflag = invflag == 0; + if ( !v4 || chrflag ) + { +LABEL_24: + if ( MouseX < 480 ) + { + v5 = MouseY; + if ( MouseY < 352 ) + { + v6 = MouseX + 160; + goto LABEL_27; + } + } + } + else + { +LABEL_18: + if ( MouseX > 160 ) + { + v5 = MouseY; + if ( MouseY < 352 ) + { + v6 = MouseX - 160; +LABEL_27: + SetCursorPos(v6, v5); + return; + } + } + } + break; + case 'Q': + case 'q': + if ( !stextflag ) + { + chrflag = 0; + if ( questlog ) + questlog = 0; + else + StartQuestlog(); + } + return; + case 'S': + case 's': + if ( !stextflag ) + { + invflag = 0; + if ( spselflag ) + spselflag = 0; + else + DoSpeedBook(); + track_repeat_walk(0); + } + return; + case 'V': + NetSendCmdString(1 << myplr, gszVersionNumber); + return; + case 'v': + NetSendCmdString(1 << myplr, gszProductName); + return; + case 'Z': + case 'z': + zoomflag = zoomflag == 0; + return; +#ifdef _DEBUG + case ')': + case '0': + if ( debug_mode_key_inverted_v ) + { + if ( arrowdebug > 2 ) + arrowdebug = 0; + if ( !arrowdebug ) + { + plr[myplr]._pIFlags &= ~ISPL_FIRE_ARROWS; + plr[myplr]._pIFlags &= ~ISPL_LIGHT_ARROWS; + } + if ( arrowdebug == 1 ) + plr[myplr]._pIFlags |= ISPL_FIRE_ARROWS; + if ( arrowdebug == 2 ) + plr[myplr]._pIFlags |= ISPL_LIGHT_ARROWS; + arrowdebug++; + } + return; + case ':': + if ( !currlevel && debug_mode_key_w ) + SetAllSpellsCheat(); + return; + case '[': + if ( !currlevel && debug_mode_key_w ) + TakeGoldCheat(); + return; + case ']': + if ( !currlevel && debug_mode_key_w ) + MaxSpellsCheat(); + return; + case 'a': + if ( debug_mode_key_inverted_v ) + { + spelldata[SPL_TELEPORT].sTownSpell = TRUE; + plr[myplr]._pSplLvl[plr[myplr]._pSpell]++; + } + return; + case 'D': + PrintDebugPlayer(1); + return; + case 'd': + PrintDebugPlayer(0); + return; + case 'e': + if ( debug_mode_key_d ) + { + sprintf(tempstr, "EFlag = %i", plr[myplr]._peflag); + NetSendCmdString(1 << myplr, tempstr); + } + return; + case 'L': + case 'l': + if ( debug_mode_key_inverted_v ) + ToggleLighting(); + return; + case 'M': + NextDebugMonster(); + return; + case 'm': + GetDebugMonster(); + return; + case 'R': + case 'r': + sprintf(tempstr, "seed = %i", glSeedTbl[currlevel]); + NetSendCmdString(1 << myplr, tempstr); + sprintf(tempstr, "Mid1 = %i : Mid2 = %i : Mid3 = %i", glMid1Seed[currlevel], glMid2Seed[currlevel], glMid3Seed[currlevel]); + NetSendCmdString(1 << myplr, tempstr); + sprintf(tempstr, "End = %i", glEndSeed[currlevel]); + NetSendCmdString(1 << myplr, tempstr); + return; + case 'T': + case 't': + if ( debug_mode_key_inverted_v ) + { + sprintf(tempstr, "PX = %i PY = %i", plr[myplr].WorldX, plr[myplr].WorldY); + NetSendCmdString(1 << myplr, tempstr); + sprintf(tempstr, "CX = %i CY = %i DP = %i", cursmx, cursmy, dungeon[cursmx][cursmy]); + NetSendCmdString(1 << myplr, tempstr); + } + return; + case '|': + if ( !currlevel && debug_mode_key_w ) + GiveGoldCheat(); + return; + case '~': + if ( !currlevel && debug_mode_key_w ) + StoresCheat(); + return; +#endif + default: + return; + } + } + } +} +// 4B84DC: using guessed type int dropGoldFlag; +// 4B8968: using guessed type int sbookflag; +// 4B8C98: using guessed type int spselflag; +// 52569C: using guessed type int zoomflag; +// 525740: using guessed type int PauseMode; +// 52575C: using guessed type int doomflag; +// 69BD04: using guessed type int questlog; +// 6AA705: using guessed type char stextflag; + +void __cdecl LoadLvlGFX() +{ + switch(leveltype) + { + case DTYPE_TOWN: + pDungeonCels = LoadFileInMem("Levels\\TownData\\Town.CEL", 0); + pMegaTiles = LoadFileInMem("Levels\\TownData\\Town.TIL", 0); + pLevelPieces = LoadFileInMem("Levels\\TownData\\Town.MIN", 0); + level_special_cel = LoadFileInMem("Levels\\TownData\\TownS.CEL", 0); + break; + case DTYPE_CATHEDRAL: + pDungeonCels = LoadFileInMem("Levels\\L1Data\\L1.CEL", 0); + pMegaTiles = LoadFileInMem("Levels\\L1Data\\L1.TIL", 0); + pLevelPieces = LoadFileInMem("Levels\\L1Data\\L1.MIN", 0); + level_special_cel = LoadFileInMem("Levels\\L1Data\\L1S.CEL", 0); + break; + case DTYPE_CATACOMBS: + pDungeonCels = LoadFileInMem("Levels\\L2Data\\L2.CEL", 0); + pMegaTiles = LoadFileInMem("Levels\\L2Data\\L2.TIL", 0); + pLevelPieces = LoadFileInMem("Levels\\L2Data\\L2.MIN", 0); + level_special_cel = LoadFileInMem("Levels\\L2Data\\L2S.CEL", 0); + break; + case DTYPE_CAVES: + pDungeonCels = LoadFileInMem("Levels\\L3Data\\L3.CEL", 0); + pMegaTiles = LoadFileInMem("Levels\\L3Data\\L3.TIL", 0); + pLevelPieces = LoadFileInMem("Levels\\L3Data\\L3.MIN", 0); + level_special_cel = LoadFileInMem("Levels\\L1Data\\L1S.CEL", 0); + break; + case DTYPE_HELL: + pDungeonCels = LoadFileInMem("Levels\\L4Data\\L4.CEL", 0); + pMegaTiles = LoadFileInMem("Levels\\L4Data\\L4.TIL", 0); + pLevelPieces = LoadFileInMem("Levels\\L4Data\\L4.MIN", 0); + level_special_cel = LoadFileInMem("Levels\\L2Data\\L2S.CEL", 0); + break; + default: + TermMsg("LoadLvlGFX"); + return; + } +} +// 5BB1ED: using guessed type char leveltype; + +void __cdecl LoadAllGFX() +{ + pSpeedCels = DiabloAllocPtr(0x100000); + IncProgress(); + IncProgress(); + InitObjectGFX(); + IncProgress(); + InitMissileGFX(); + IncProgress(); +} + +void __fastcall CreateLevel(int lvldir) +{ + int hnd; // cl + + switch ( leveltype ) + { + case DTYPE_TOWN: + CreateTown(lvldir); + InitTownTriggers(); + hnd = 0; + break; + case DTYPE_CATHEDRAL: + CreateL5Dungeon(glSeedTbl[currlevel], lvldir); + InitL1Triggers(); + Freeupstairs(); + hnd = 1; + break; + case DTYPE_CATACOMBS: + CreateL2Dungeon(glSeedTbl[currlevel], lvldir); + InitL2Triggers(); + Freeupstairs(); + hnd = 2; + break; + case DTYPE_CAVES: + CreateL3Dungeon(glSeedTbl[currlevel], lvldir); + InitL3Triggers(); + Freeupstairs(); + hnd = 3; + break; + case DTYPE_HELL: + CreateL4Dungeon(glSeedTbl[currlevel], lvldir); + InitL4Triggers(); + Freeupstairs(); + hnd = 4; + break; + default: + TermMsg("CreateLevel"); + return; + } + + LoadRndLvlPal(hnd); +} +// 5BB1ED: using guessed type char leveltype; + +void __fastcall LoadGameLevel(BOOL firstflag, int lvldir) +{ + int v2; // ebp + bool visited; // edx + int i; // ecx + int j; // eax + + v2 = 0; + if ( setseed ) + glSeedTbl[currlevel] = setseed; + music_stop(); + SetCursor(CURSOR_HAND); + SetRndSeed(glSeedTbl[currlevel]); + IncProgress(); + MakeLightTable(); + LoadLvlGFX(); + IncProgress(); + if ( firstflag ) + { + InitInv(); + InitItemGFX(); + InitQuestText(); + + if ( gbMaxPlayers ) + { + for(i = 0; i < gbMaxPlayers; i++) + InitPlrGFXMem(i); + } + + InitStores(); + InitAutomapOnce(); + InitHelp(); + } + SetRndSeed(glSeedTbl[currlevel]); + if ( leveltype == DTYPE_TOWN) + SetupTownStores(); + IncProgress(); + InitAutomap(); + if ( leveltype != DTYPE_TOWN && lvldir != 4 ) + { + InitLighting(); + InitVision(); + } + InitLevelMonsters(); + IncProgress(); + if ( !setlevel ) + { + CreateLevel(lvldir); + IncProgress(); + FillSolidBlockTbls(); + SetRndSeed(glSeedTbl[currlevel]); + if ( leveltype != DTYPE_TOWN ) + { + GetLevelMTypes(); + InitThemes(); + LoadAllGFX(); + } + else + { + InitMissileGFX(); + } + IncProgress(); + if ( lvldir == 3 ) + GetReturnLvlPos(); + if ( lvldir == 5 ) + GetPortalLvlPos(); + IncProgress(); + + for(i = 0; i < MAX_PLRS; i++) + { + if ( plr[i].plractive ) + { + if ( currlevel == plr[i].plrlevel ) + { + InitPlayerGFX(v2); + if ( lvldir != 4 ) + InitPlayer(v2, firstflag); + } + } + ++v2; + } + + PlayDungMsgs(); + InitMultiView(); + IncProgress(); + + visited = 0; + if ( gbMaxPlayers > 0 ) + { + for(i = 0; i < gbMaxPlayers; i++) + { + if ( plr[i].plractive ) + visited = visited || plr[i]._pLvlVisited[currlevel]; + } + } + SetRndSeed(glSeedTbl[currlevel]); + if ( leveltype != DTYPE_TOWN) + { + if ( firstflag || lvldir == 4 || !plr[myplr]._pLvlVisited[currlevel] || gbMaxPlayers != 1 ) + { + HoldThemeRooms(); + glMid1Seed[currlevel] = GetRndSeed(); + InitMonsters(); + glMid2Seed[currlevel] = GetRndSeed(); + InitObjects(); + InitItems(); + CreateThemeRooms(); + glMid3Seed[currlevel] = GetRndSeed(); + InitMissiles(); + InitDead(); + glEndSeed[currlevel] = GetRndSeed(); + if ( gbMaxPlayers != 1 ) + DeltaLoadLevel(); + IncProgress(); + SavePreLighting(); + goto LABEL_55; + } + InitMonsters(); + InitMissiles(); + InitDead(); + IncProgress(); + LoadLevel(); +LABEL_54: + IncProgress(); +LABEL_55: + if ( gbMaxPlayers == 1 ) + ResyncQuests(); + else + ResyncMPQuests(); + goto LABEL_72; + } + + for(i = 0; i < 112; i++) + { + for(j = 0; j < 112; j++) + dFlags[i][j] |= DFLAG_LIT; + } + + InitTowners(); + InitItems(); + InitMissiles(); + IncProgress(); + if ( !firstflag && lvldir != 4 && plr[myplr]._pLvlVisited[currlevel] ) + { + if ( gbMaxPlayers != 1 ) + goto LABEL_53; + LoadLevel(); + } + if ( gbMaxPlayers == 1 ) + goto LABEL_54; +LABEL_53: + DeltaLoadLevel(); + goto LABEL_54; + } + pSpeedCels = DiabloAllocPtr(0x100000); + LoadSetMap(); + IncProgress(); + GetLevelMTypes(); + InitMonsters(); + InitMissileGFX(); + InitDead(); + FillSolidBlockTbls(); + IncProgress(); + if ( lvldir == 5 ) + GetPortalLvlPos(); + + for(i = 0; i < MAX_PLRS; i++) + { + if ( plr[i].plractive ) + { + if ( currlevel == plr[i].plrlevel ) + { + InitPlayerGFX(v2); + if ( lvldir != 4 ) + InitPlayer(v2, firstflag); + } + } + ++v2; + } + + InitMultiView(); + IncProgress(); + if ( firstflag || lvldir == 4 || !plr[myplr]._pSLvlVisited[(unsigned char)setlvlnum] ) + { + InitItems(); + SavePreLighting(); + } + else + { + LoadLevel(); + } + InitMissiles(); + IncProgress(); +LABEL_72: + SyncPortals(); + + for(i = 0; i < MAX_PLRS; i++) + { + if ( plr[i].plractive && plr[i].plrlevel == currlevel && (!plr[i]._pLvlChanging || i == myplr) ) + { + if ( plr[i]._pHitPoints <= 0 ) + dFlags[plr[i].WorldX][plr[i].WorldY] |= DFLAG_DEAD_PLAYER; + else if ( gbMaxPlayers == 1 ) + dPlayer[plr[i].WorldX][plr[i].WorldY] = i + 1; + else + SyncInitPlrPos(i); + } + } + + if ( leveltype != DTYPE_TOWN ) + SetDungeonMicros(); + InitLightMax(); + IncProgress(); + IncProgress(); + if ( firstflag ) + { + InitControlPan(); + IncProgress(); + } + if ( leveltype != DTYPE_TOWN) + { + ProcessLightList(); + ProcessVisionList(); + } + music_start((unsigned char)leveltype); + //do + // _LOBYTE(v19) = IncProgress(); + while ( !IncProgress() ); + if ( setlevel && setlvlnum == SL_SKELKING && quests[QTYPE_KING]._qactive == 2 ) + PlaySFX(USFX_SKING1); +} +// 525738: using guessed type int setseed; +// 5BB1ED: using guessed type char leveltype; +// 5CCB10: using guessed type char setlvlnum; +// 5CF31D: using guessed type char setlevel; +// 679660: using guessed type char gbMaxPlayers; + +void __fastcall game_loop(bool bStartup) +{ + int v1; // ecx + int v2; // esi + + v1 = bStartup != 0 ? 0x39 : 0; + v2 = v1 + 3; + if ( v1 != -3 ) + { + while ( 1 ) + { + --v2; + if ( !multi_handle_delta() ) + break; + timeout_cursor(0); + game_logic(); + if ( gbRunGame ) + { + if ( gbMaxPlayers != 1 ) + { + if ( nthread_has_500ms_passed() ) + { + if ( v2 ) + continue; + } + } + } + return; + } + timeout_cursor(1); + } +} +// 525650: using guessed type int gbRunGame; +// 679660: using guessed type char gbMaxPlayers; + + +bool CUSTOM_SDL_KEY_LSHIFT; + +void __cdecl game_logic() +{ + if ( PauseMode != 2 ) + { + if ( PauseMode == 1 ) + PauseMode = 2; + if ( gbMaxPlayers == 1 && gmenu_exception() ) + { + drawpanflag |= 1u; + } + else + { + if ( !gmenu_exception() && sgnTimeoutCurs == CURSOR_NONE ) + { + CheckCursMove(); + track_process(); + } + if ( gbProcessPlayers ) + ProcessPlayers(); + if ( leveltype != DTYPE_TOWN ) + { + ProcessMonsters(); + ProcessObjects(); + ProcessMissiles(); + ProcessItems(); + ProcessLightList(); + ProcessVisionList(); + } + else + { + ProcessTowners(); + ProcessItems(); + ProcessMissiles(); + } + + + + + +#ifdef _DEBUG + if ( debug_mode_key_inverted_v ) + { + if ( GetAsyncKeyState(VK_SHIFT) & 0x8000 ) + ScrollView(); + } +#endif + sound_update(); + ClearPlrMsg(); + CheckTriggers(); + CheckQuests(); + drawpanflag |= 1u; + pfile_update(0); + } + } +} +// 5256A0: using guessed type int gbProcessPlayers; +// 525718: using guessed type char cineflag; +// 52571C: using guessed type int drawpanflag; +// 525740: using guessed type int PauseMode; +// 5BB1ED: using guessed type char leveltype; +// 679660: using guessed type char gbMaxPlayers; + +void __fastcall timeout_cursor(bool bTimeout) +{ + if ( bTimeout ) + { + if ( sgnTimeoutCurs == CURSOR_NONE && !sgbMouseDown ) + { + sgnTimeoutCurs = pcurs; + multi_net_ping(); + ClearPanel(); + AddPanelString("-- Network timeout --", 1); + AddPanelString("-- Waiting for players --", 1); + SetCursor(CURSOR_HOURGLASS); + drawpanflag = 255; + } + scrollrt_draw_game_screen(1); + } + else if ( sgnTimeoutCurs ) + { + SetCursor(sgnTimeoutCurs); + sgnTimeoutCurs = 0; + ClearPanel(); + drawpanflag = 255; + } +} +// 52571C: using guessed type int drawpanflag; +// 525748: using guessed type char sgbMouseDown; + +void __cdecl diablo_color_cyc_logic() +{ + DWORD v0; // eax + + v0 = GetTickCount(); + if ( v0 - color_cycle_timer >= 0x32 ) + { + color_cycle_timer = v0; + if ( palette_get_colour_cycling() ) + { + if ( leveltype == DTYPE_HELL ) + { + lighting_color_cycling(); + } + else if ( leveltype == DTYPE_CAVES ) + { + if ( fullscreen ) + palette_update_caves(); + } + } + } +} +// 484364: using guessed type int fullscreen; +// 52574C: using guessed type int color_cycle_timer; +// 5BB1ED: using guessed type char leveltype; diff --git a/Stub/miniwin.h b/Stub/miniwin.h index c315f1a21..ebdc36ca8 100644 --- a/Stub/miniwin.h +++ b/Stub/miniwin.h @@ -99,6 +99,7 @@ typedef LONG_PTR LRESULT; // typedef void *HANDLE; #define INVALID_HANDLE ((HANDLE)-1) +#define HFILE_ERROR ((HFILE)-1) typedef HANDLE HWND, HGDIOBJ, HMODULE, HDC, HRGN, HINSTANCE, HPALETTE, HFILE, HCURSOR; diff --git a/Stub/miniwin_msg_sdl.cpp b/Stub/miniwin_msg_sdl.cpp index 8e8c32946..52a642a3b 100644 --- a/Stub/miniwin_msg_sdl.cpp +++ b/Stub/miniwin_msg_sdl.cpp @@ -9,10 +9,22 @@ #include "../types.h" #include "stubs.h" + +PlayerStruct *PlayerS; + + + + + + static std::deque message_queue; static int translate_sdl_key(SDL_Keysym key) { + + + + int sym = key.sym; switch (sym) { case SDLK_ESCAPE: @@ -63,13 +75,18 @@ static int translate_sdl_key(SDL_Keysym key) return VK_OEM_PERIOD; case SDLK_COMMA: return VK_OEM_COMMA; - - case SDLK_LSHIFT: + +// case SDLK_LSHIFT: +// printf("Fooooooo\n"); + //PlayerS._pmode = 5; + // +// return VK_SHIFT; case SDLK_RSHIFT: // Not handled yet return -1; default: + if (sym >= SDLK_a && sym <= SDLK_z) { return 'A' + (sym - SDLK_a); } else if (sym >= SDLK_0 && sym <= SDLK_9) { @@ -77,6 +94,8 @@ static int translate_sdl_key(SDL_Keysym key) } else if (sym >= SDLK_F1 && sym <= SDLK_F12) { return VK_F1 + (sym - SDLK_F1); } + CUSTOM_SDL_KEY_LSHIFT = 0; + DUMMY_PRINT("unknown key: name=%s sym=0x%X scan=%d mod=0x%X", SDL_GetKeyName(sym), sym, key.scancode, key.mod); return -1; diff --git a/Stub/miniwin_sdl.cpp b/Stub/miniwin_sdl.cpp index 35bcb1a25..d771b980a 100644 --- a/Stub/miniwin_sdl.cpp +++ b/Stub/miniwin_sdl.cpp @@ -62,7 +62,6 @@ static int translate_sdl_key(SDL_Keysym key) return VK_OEM_COMMA; case SDLK_LSHIFT: - printf("LEFT SHIFT\n"); return VK_LSHIFT; case SDLK_RSHIFT: // Not handled yet diff --git a/Stub/sound.cpp b/Stub/sound.cpp index 2dfbd3dee..783142975 100644 --- a/Stub/sound.cpp +++ b/Stub/sound.cpp @@ -180,19 +180,16 @@ TSnd *__fastcall sound_file_load(char *path) int nrread; void *file; - SFileOpenFile(path, &file); +//This opens the file and reads it, makes Mix_chunk pointer to it. +//Once this is done the pointer is stored TSnd Struct + SFileOpenFile(path, &file); bytestoread = (int)SFileGetFileSize((HANDLE)file, 0); MSFXBuffer = DiabloAllocPtr(bytestoread); SFileReadFile(file, (char *)MSFXBuffer, bytestoread, (unsigned long *)&nrread, 0); - SDL_RWops *rw = SDL_RWFromMem(MSFXBuffer, bytestoread); - - - - - Mix_Chunk *SoundFX = Mix_LoadWAV_RW(rw, 1); + Mix_Chunk *SoundFX = Mix_LoadWAV_RW(rw, 1);