diff --git a/3rdParty/PKWare/Makefile b/3rdParty/PKWare/Makefile new file mode 100644 index 000000000..377b29a23 --- /dev/null +++ b/3rdParty/PKWare/Makefile @@ -0,0 +1,59 @@ +VC5_DIR ?= $(HOME)/DevStudio_5.10/VC + +# The $(VS6_DIR) directory is a copy of the "Microsoft Visual Studio" directory. +# +# To get a working setup on Linux or other "portable" copies of VS, +# the following DLLs have to be copied to the +# $(VS6_DIR)/VC98/Bin directory. +# +# - $(VS6_DIR)/Common/MSDev98/Bin/MSPDB60.DLL +# +# And to the $(VC5_DIR)/bin directory. +# +# - $(VC5_DIR)/SharedIDE/bin/MSDIS100.DLL +# - $(VC5_DIR)/SharedIDE/bin/MSPDB50.DLL +VS6_DIR ?= $(HOME)/VS6 + +VC6_DIR = $(VS6_DIR)/VC98 + +VC6_BIN_DIR = $(VC6_DIR)/Bin +VC6_INC_DIR = $(VC6_DIR)/Include +VC6_LIB_DIR = $(VC6_DIR)/Lib + +VC5_LIB_DIR = $(VC5_DIR)/lib + +IDE_DIR ?= $(VS6_DIR)/Common/MSDev98 +IDE_BIN_DIR = $(IDE_DIR)/bin +ifeq ($(OS),Windows_NT) + CL = $(VC6_BIN_DIR)/CL.EXE + RC = $(IDE_BIN_DIR)/RC.EXE + VC5_LINK = $(VC5_DIR)/bin/link.exe + VC6_LINK = $(VC6_BIN_DIR)/link.exe +else + CL = wine $(VC6_BIN_DIR)/CL.EXE + RC = wine $(IDE_BIN_DIR)/RC.EXE + VC5_LINK = wine $(VC5_DIR)/bin/link.exe + VC6_LINK = wine $(VC6_BIN_DIR)/link.exe +endif + +CFLAGS=/nologo /c /GX /W3 /O1 /I $(VC6_INC_DIR) /FD /MT /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /YX /Gm /Zi +LINKFLAGS=/nologo /subsystem:windows /machine:I386 /incremental:no + +VC_LINK=$(VC5_LINK) +LINKFLAGS+= /LIBPATH:$(VC5_LIB_DIR) + +all: pkware.lib + +PKWARE_SRC=$(sort $(wildcard *.cpp)) +PKWARE_OBJS=$(PKWARE_SRC:.cpp=.obj) + +pkware.lib: $(PKWARE_OBJS) + $(VC_LINK) -lib /OUT:$@ $^ /nologo + +%.obj: %.cpp + $(CL) $(CFLAGS) /Fo$@ $< + +clean: + @$(RM) -v $(PKWARE_OBJS) pkware.lib vc60.{idb,pch,pdb} + +.PHONY: clean all diff --git a/3rdParty/PKWare/Pkware.dsp b/3rdParty/PKWare/Pkware.dsp new file mode 100644 index 000000000..f3bdc2239 --- /dev/null +++ b/3rdParty/PKWare/Pkware.dsp @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="Pkware" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=Pkware - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "Pkware.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "Pkware.mak" CFG="Pkware - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Pkware - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "Pkware - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Pkware - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "WinRel" +# PROP BASE Intermediate_Dir "WinRel" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "WinRel" +# PROP Intermediate_Dir "WinRel" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "Pkware - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "WinDebug" +# PROP BASE Intermediate_Dir "WinDebug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "WinDebug" +# PROP Intermediate_Dir "WinDebug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ENDIF + +# Begin Target + +# Name "Pkware - Win32 Release" +# Name "Pkware - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\explode.cpp +# End Source File +# Begin Source File + +SOURCE=.\implode.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# End Target +# End Project diff --git a/3rdParty/Storm/Source/storm.cpp b/3rdParty/Storm/Source/storm.cpp index 583be190c..da7688b08 100644 --- a/3rdParty/Storm/Source/storm.cpp +++ b/3rdParty/Storm/Source/storm.cpp @@ -231,8 +231,8 @@ BOOLEAN __stdcall SFileSetBasePath(char *) rBool; void __cdecl SDrawRealizePalette(void) rVoid; BOOL __cdecl SVidPlayContinue(void) rBool; BOOL __stdcall SNetGetOwnerTurnsWaiting(DWORD *) rBool; -void * __stdcall SNetUnregisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)) rPVoid; -void * __stdcall SNetRegisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)) rPVoid; +BOOL __stdcall SNetUnregisterEventHandler(int,SEVTHANDLER) rPVoid; +BOOL __stdcall SNetRegisterEventHandler(int,SEVTHANDLER) rPVoid; BOOLEAN __stdcall SNetSetBasePlayer(int) rBool; int __stdcall SNetInitializeProvider(unsigned long,struct _SNETPROGRAMDATA *,struct _SNETPLAYERDATA *,struct _SNETUIDATA *,struct _SNETVERSIONDATA *) rInt; int __stdcall SNetGetProviderCaps(struct _SNETCAPS *) rInt; diff --git a/3rdParty/Storm/Source/storm.h b/3rdParty/Storm/Source/storm.h index 8a229ab0a..d066517d4 100644 --- a/3rdParty/Storm/Source/storm.h +++ b/3rdParty/Storm/Source/storm.h @@ -380,6 +380,7 @@ typedef struct _s_evt DWORD dwSize; } S_EVT, *PS_EVT; +typedef void (STORMAPI *SEVTHANDLER)(struct _SNETEVENT *); // @TODO: "type" is unknown. //HANDLE STORMAPI SNetRegisterEventHandler(int type, void (STORMAPI *sEvent)(PS_EVT)); @@ -1326,8 +1327,8 @@ BOOLEAN __stdcall SFileSetBasePath(char *); void __cdecl SDrawRealizePalette(void); BOOL __cdecl SVidPlayContinue(void); BOOL __stdcall SNetGetOwnerTurnsWaiting(DWORD *); -void * __stdcall SNetUnregisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)); -void * __stdcall SNetRegisterEventHandler(int,void (__stdcall*)(struct _SNETEVENT *)); +BOOL __stdcall SNetUnregisterEventHandler(int,SEVTHANDLER); +BOOL __stdcall SNetRegisterEventHandler(int,SEVTHANDLER); BOOLEAN __stdcall SNetSetBasePlayer(int); int __stdcall SNetInitializeProvider(unsigned long,struct _SNETPROGRAMDATA *,struct _SNETPLAYERDATA *,struct _SNETUIDATA *,struct _SNETVERSIONDATA *); int __stdcall SNetGetProviderCaps(struct _SNETCAPS *); diff --git a/DiabloUI/DiabloUI.dsp b/DiabloUI/DiabloUI.dsp index 0e411703e..1d43f3f49 100644 --- a/DiabloUI/DiabloUI.dsp +++ b/DiabloUI/DiabloUI.dsp @@ -40,6 +40,7 @@ RSC=rc.exe # PROP Use_Debug_Libraries 0 # PROP Output_Dir "WinRel" # PROP Intermediate_Dir "WinRel" +# PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c @@ -52,7 +53,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 -# ADD LINK32 ../3rdParty/Storm/Source/WinRel/Storm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /def:"diabloui.def" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /def:"diabloui.def" !ELSEIF "$(CFG)" == "DiabloUI - Win32 Debug" @@ -65,6 +66,7 @@ LINK32=link.exe # PROP Use_Debug_Libraries 1 # PROP Output_Dir "WinDebug" # PROP Intermediate_Dir "WinDebug" +# PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /O1 /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c @@ -77,7 +79,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 ../3rdParty/Storm/Source/WinDebug/Storm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /def:"diabloui.def" /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /def:"diabloui.def" /pdbtype:sept !ENDIF diff --git a/Source/automap.cpp b/Source/automap.cpp index 66191ed28..87cb7bceb 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -501,6 +501,7 @@ void DrawAutomapPlr() DrawLine(x, y, x - AutoMapYPos, y - AMPlayerX, COLOR_PLAYER); DrawLine(x - AutoMapYPos, y - AMPlayerX, x - AMPlayerX, y - AMPlayerX, COLOR_PLAYER); DrawLine(x - AutoMapYPos, y - AMPlayerX, x - AMPlayerY - AMPlayerX, y, COLOR_PLAYER); + break; } } @@ -591,7 +592,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) { automapview[xx - 1][yy] = 1; } - return; + break; case 3: if (solid) { if (GetAutomapType(xx + 1, yy, FALSE) == 0x4007) @@ -599,7 +600,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) { automapview[xx][yy - 1] = 1; } - return; + break; case 4: if (solid) { if (GetAutomapType(xx, yy + 1, FALSE) == 0x4007) @@ -614,7 +615,7 @@ void SetAutomapView(int x, int y) if (GetAutomapType(xx - 1, yy - 1, FALSE) & 0x4000) automapview[xx - 1][yy - 1] = 1; } - return; + break; case 5: if (solid) { if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) @@ -624,7 +625,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) { automapview[xx - 1][yy] = 1; } - return; + break; case 6: if (solid) { if (GetAutomapType(xx - 1, yy, FALSE) & 0x4000) @@ -634,7 +635,7 @@ void SetAutomapView(int x, int y) } else if (GetAutomapType(xx, yy - 1, FALSE) & 0x4000) { automapview[xx][yy - 1] = 1; } - return; + break; } } diff --git a/Source/control.cpp b/Source/control.cpp index fbc9fc470..8806f11a2 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -576,10 +576,6 @@ void SetSpell() plr[myplr]._pRSplType = pSplType; } } -// 4B8834: using guessed type int pSpell; -// 4B8954: using guessed type int pSplType; -// 4B8C98: using guessed type int spselflag; -// 52571C: using guessed type int drawpanflag; void SetSpeedSpell(int slot) { @@ -624,7 +620,6 @@ void ToggleSpell(int slot) drawpanflag = 255; } } -// 52571C: using guessed type int drawpanflag; void CPrintString(int nOffset, int nCel, char col) { @@ -1264,7 +1259,6 @@ void ClearCtrlPan() DrawPanelBox(0, sgbPlrTalkTbl + 16, 640, 128, 64, 512); DrawInfoBox(); } -// 4B8840: using guessed type int sgbPlrTalkTbl; void DrawCtrlPan() { @@ -1337,7 +1331,6 @@ void DoSpeedBook() SetCursorPos(X, Y); } -// 4B8C98: using guessed type int spselflag; void DoPanBtn() { @@ -1367,21 +1360,16 @@ void control_set_button_down(int btn_id) void control_check_btn_press() { - int v0; // edx - int v1; // esi - - v0 = MouseX; - v1 = MouseY; if (MouseX >= PanBtnPos[3][0] && MouseX <= PanBtnPos[3][0] + PanBtnPos[3][2] && MouseY >= PanBtnPos[3][1] && MouseY <= PanBtnPos[3][1] + PanBtnPos[3][3]) { control_set_button_down(3); } - if (v0 >= PanBtnPos[6][0] - && v0 <= PanBtnPos[6][0] + PanBtnPos[6][2] - && v1 >= PanBtnPos[6][1] - && v1 <= PanBtnPos[6][1] + PanBtnPos[6][3]) { + if (MouseX >= PanBtnPos[6][0] + && MouseX <= PanBtnPos[6][0] + PanBtnPos[6][2] + && MouseY >= PanBtnPos[6][1] + && MouseY <= PanBtnPos[6][1] + PanBtnPos[6][3]) { control_set_button_down(6); } } @@ -1397,53 +1385,34 @@ void DoAutoMap() InitDiabloMsg(EMSG_NO_AUTOMAP_IN_TOWN); } } -// 679660: using guessed type char gbMaxPlayers; void CheckPanelInfo() { - int v0; // edi - int v1; // eax - int v2; // ecx - int v3; // ecx - int v4; // edi - int v5; // eax - int *v6; // edx - int v7; // ebx - int v8; // ebx - int *v9; // eax - signed int v10; // edx - int v11; // ecx - int v12; // [esp+10h] [ebp-4h] + int i, c, v, s; - v0 = 0; panelflag = 0; ClearPanel(); - if (numpanbtns > 0) { - do { - v1 = v0; - v2 = PanBtnPos[v0][0]; - if (MouseX >= v2 && MouseX <= v2 + PanBtnPos[v1][2]) { - v3 = PanBtnPos[v1][1]; - if (MouseY >= v3 && MouseY <= v3 + PanBtnPos[v1][3]) { - if (v0 == 7) { - if (FriendlyMode) - strcpy(infostr, "Player friendly"); - else - strcpy(infostr, "Player attack"); - } else { - strcpy(infostr, PanBtnStr[v0]); - } - if (PanBtnHotKey[v0]) { - sprintf(tempstr, "Hotkey : %s", PanBtnHotKey[v0]); - AddPanelString(tempstr, 1); - } - infoclr = COL_WHITE; - panelflag = 1; - pinfoflag = TRUE; - } + for (i = 0; i < numpanbtns; i++) { + if (MouseX >= PanBtnPos[i][0] + && MouseX <= PanBtnPos[i][0] + PanBtnPos[i][2] + && MouseY >= PanBtnPos[i][1] + && MouseY <= PanBtnPos[i][1] + PanBtnPos[i][3]) { + if (i != 7) { + strcpy(infostr, PanBtnStr[i]); + } else { + if (FriendlyMode) + strcpy(infostr, "Player friendly"); + else + strcpy(infostr, "Player attack"); } - ++v0; - } while (v0 < numpanbtns); + if (PanBtnHotKey[i]) { + sprintf(tempstr, "Hotkey : %s", PanBtnHotKey[i]); + AddPanelString(tempstr, 1); + } + infoclr = COL_WHITE; + panelflag = 1; + pinfoflag = TRUE; + } } if (!spselflag && MouseX >= 565 && MouseX < 621 && MouseY >= 416 && MouseY < 472) { strcpy(infostr, "Select current spell button"); @@ -1452,62 +1421,58 @@ void CheckPanelInfo() pinfoflag = TRUE; strcpy(tempstr, "Hotkey : 's'"); AddPanelString(tempstr, 1); - v4 = plr[myplr]._pRSpell; - if (v4 != -1) { - switch (_LOBYTE(plr[myplr]._pRSplType)) { + v = plr[myplr]._pRSpell; + if (v != -1) { + switch (plr[myplr]._pRSplType) { case RSPLTYPE_SKILL: - sprintf(tempstr, "%s Skill", spelldata[v4].sSkillText); - LABEL_54: + sprintf(tempstr, "%s Skill", spelldata[v].sSkillText); AddPanelString(tempstr, 1); break; case RSPLTYPE_SPELL: - sprintf(tempstr, "%s Spell", spelldata[v4].sNameText); + sprintf(tempstr, "%s Spell", spelldata[v].sNameText); AddPanelString(tempstr, 1); - v11 = plr[myplr]._pISplLvlAdd + plr[myplr]._pSplLvl[v4]; - if (v11 < 0) - v11 = 0; - if (v11) - sprintf(tempstr, "Spell Level %i", v11); - else + c = plr[myplr]._pISplLvlAdd + plr[myplr]._pSplLvl[v]; + if (c < 0) + c = 0; + if (!c) sprintf(tempstr, "Spell Level 0 - Unusable"); - goto LABEL_54; + else + sprintf(tempstr, "Spell Level %i", c); + AddPanelString(tempstr, 1); + break; case RSPLTYPE_SCROLL: - sprintf(tempstr, "Scroll of %s", spelldata[v4].sNameText); + sprintf(tempstr, "Scroll of %s", spelldata[v].sNameText); AddPanelString(tempstr, 1); - v12 = 0; - v5 = myplr; - if (plr[myplr]._pNumInv > 0) { - v6 = &plr[v5].InvList[0]._iMiscId; - v7 = plr[myplr]._pNumInv; - do { - if (*(v6 - 53) != -1 && (*v6 == IMISC_SCROLL || *v6 == IMISC_SCROLLT) && v6[1] == v4) - ++v12; - v6 += 92; - --v7; - } while (v7); + s = 0; + for (i = 0; i < plr[myplr]._pNumInv; i++) { + if (plr[myplr].InvList[i]._itype != -1 + && (plr[myplr].InvList[i]._iMiscId == IMISC_SCROLL || plr[myplr].InvList[i]._iMiscId == IMISC_SCROLLT) + && plr[myplr].InvList[i]._iSpell == v) { + s++; + } } - v8 = v12; - v9 = &plr[v5].SpdList[0]._iMiscId; - v10 = MAXBELTITEMS; - do { - if (*(v9 - 53) != -1 && (*v9 == IMISC_SCROLL || *v9 == IMISC_SCROLLT) && v9[1] == v4) - ++v8; - v9 += 92; - --v10; - } while (v10); - if (v8 == 1) + for (i = 0; i < MAXBELTITEMS; i++) { + if (plr[myplr].SpdList[i]._itype != -1 + && (plr[myplr].SpdList[i]._iMiscId == IMISC_SCROLL || plr[myplr].SpdList[i]._iMiscId == IMISC_SCROLLT) + && plr[myplr].SpdList[i]._iSpell == v) { + s++; + } + } + if (s == 1) strcpy(tempstr, "1 Scroll"); else - sprintf(tempstr, "%i Scrolls", v8); - goto LABEL_54; + sprintf(tempstr, "%i Scrolls", s); + AddPanelString(tempstr, 1); + break; case RSPLTYPE_CHARGES: - sprintf(tempstr, "Staff of %s", spelldata[v4].sNameText); + sprintf(tempstr, "Staff of %s", spelldata[v].sNameText); AddPanelString(tempstr, 1); if (plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges == 1) strcpy(tempstr, "1 Charge"); else sprintf(tempstr, "%i Charges", plr[myplr].InvBody[INVLOC_HAND_LEFT]._iCharges); - goto LABEL_54; + AddPanelString(tempstr, 1); + break; } } } @@ -1595,10 +1560,6 @@ void CheckBtnUp() if (gamemenuOff) gamemenu_off(); } -// 484368: using guessed type int FriendlyMode; -// 4B8960: using guessed type int talkflag; -// 4B8968: using guessed type int sbookflag; -// 646D00: using guessed type char qtextflag; void FreeControlPan() { @@ -1651,9 +1612,9 @@ void DrawInfoBox() char *v10; // ebx DrawPanelBox(177, 62, 288, 60, 241, 558); - v0 = trigflag_3; + v0 = trigflag; v1 = spselflag; - if (!panelflag && !trigflag_3 && pcursinvitem == -1) { + if (!panelflag && !trigflag && pcursinvitem == -1) { if (spselflag) { LABEL_32: infoclr = COL_WHITE; @@ -1745,55 +1706,37 @@ LABEL_33: // 4B8CC1: using guessed type char pcursobj; // 4B8CC2: using guessed type char pcursplr; -void control_print_info_str(int y, char *str, BOOLEAN center, int lines) -{ - int v4; // edi - char *v5; // ebx - unsigned char v6; // cl - signed int v7; // eax - char *v8; // esi - int v9; // eax - unsigned char v10; // esi - unsigned char v11; // al - int width; // [esp+18h] [ebp+Ch] - - v4 = 0; - v5 = str; - width = lineoffset[y + 4 * lines + lines]; +void control_print_info_str(int y, char *str, BOOL center, int lines) +{ + BYTE c; + char *tmp; + int screen_x, line, nOffset; + + line = 0; + nOffset = lineoffset[y + 4 * lines + lines]; if (center == 1) { - v6 = *str; - v7 = 0; - v8 = str; - if (!*str) - goto LABEL_14; - do { - ++v8; - v7 += fontkern[fontframe[gbFontTransTbl[v6]]] + 2; - v6 = *v8; - } while (*v8); - if (v7 < 288) - LABEL_14: - v4 = (288 - v7) >> 1; - width += v4; + screen_x = 0; + tmp = str; + while (*tmp) { + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + 1; + } + if (screen_x < 288) + line = (288 - screen_x) >> 1; + nOffset += line; } - while (1) { - v11 = *v5; - if (!*v5) - break; - ++v5; - v9 = gbFontTransTbl[v11]; - _LOBYTE(v9) = fontframe[v9]; - v10 = (unsigned char)v9; - v4 += fontkern[(unsigned char)v9] + 2; - if ((_BYTE)v9) { - if (v4 < 288) { - CPrintString(width, v10, infoclr); + while (*str) { + c = gbFontTransTbl[(BYTE)*str++]; + c = fontframe[c]; + line += fontkern[c] + 2; + if (c) { + if (line < 288) { + CPrintString(nOffset, c, infoclr); } } - width += fontkern[v10] + 2; + nOffset += fontkern[c] + 2; } } -// 4B883C: using guessed type int infoclr; void PrintGameStr(int x, int y, char *str, int color) { @@ -1801,8 +1744,7 @@ void PrintGameStr(int x, int y, char *str, int color) int off; off = PitchTbl[y + 160] + x + 64; while (*str) { - c = gbFontTransTbl[(BYTE)*str]; - str++; + c = gbFontTransTbl[(BYTE)*str++]; c = fontframe[c]; if (c) CPrintString(off, c, color); @@ -2035,95 +1977,66 @@ void DrawChr() ADD_PlrStringXY(143, 332, 174, a4, a5[0]); } +/** + * @brief Identical to MY_PlrStringXY(x, y, width, pszStr, col, 1) + */ void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col) { - int v5; // eax - char *v6; // edx - unsigned char v7; // al - int v8; // esi - int v9; // edi - int v10; // ecx - unsigned char v11; // bl - unsigned char v12; // al - int v13; // ebx - int widtha; // [esp+Ch] [ebp-4h] - int widthb; // [esp+Ch] [ebp-4h] - - v5 = PitchTbl[y + 160]; - v6 = pszStr; - widtha = v5 + x + 64; - v7 = *pszStr; - v8 = width - x + 1; - v9 = 0; - v10 = 0; - if (*pszStr) { - v11 = *pszStr; - do { - ++v6; - v10 += fontkern[fontframe[gbFontTransTbl[v11]]] + 1; - v11 = *v6; - } while (*v6); - } - if (v10 < v8) - v9 = (v8 - v10) >> 1; - widthb = v9 + widtha; - while (v7) { - ++pszStr; - v12 = fontframe[gbFontTransTbl[v7]]; - v13 = v12; - v9 += fontkern[v12] + 1; - if (v12) { - if (v9 < v8) - CPrintString(widthb, v12, col); + BYTE c; + char *tmp; + int nOffset, screen_x, line, widthOffset; + + nOffset = x + PitchTbl[y + 160] + 64; + widthOffset = width - x + 1; + line = 0; + screen_x = 0; + tmp = pszStr; + while (*tmp) { + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + 1; + } + if (screen_x < widthOffset) + line = (widthOffset - screen_x) >> 1; + nOffset += line; + while (*pszStr) { + c = gbFontTransTbl[(BYTE)*pszStr++]; + c = fontframe[c]; + line += fontkern[c] + 1; + if (c) { + if (line < widthOffset) + CPrintString(nOffset, c, col); } - widthb += fontkern[v13] + 1; - v7 = *pszStr; + nOffset += fontkern[c] + 1; } } void MY_PlrStringXY(int x, int y, int width, char *pszStr, char col, int base) { - char *v6; // ebx - unsigned char v7; // al - int v8; // edx - int v9; // esi - char *v10; // edi - unsigned char v11; // cl - unsigned char v12; // al - int v13; // edi - int widtha; // [esp+Ch] [ebp-4h] - int widthb; // [esp+Ch] [ebp-4h] - int v16; // [esp+18h] [ebp+8h] - - v6 = pszStr; - widtha = PitchTbl[y + 160] + x + 64; - v7 = *pszStr; - v8 = 0; - v9 = width - x + 1; - v16 = 0; - v10 = pszStr; - if (*pszStr) { - v11 = *pszStr; - do { - ++v10; - v8 += base + fontkern[fontframe[gbFontTransTbl[v11]]]; - v11 = *v10; - } while (*v10); - } - if (v8 < v9) - v16 = (v9 - v8) >> 1; - widthb = v16 + widtha; - while (v7) { - ++v6; - v12 = fontframe[gbFontTransTbl[v7]]; - v13 = v12; - v16 += base + fontkern[v12]; - if (v12) { - if (v16 < v9) - CPrintString(widthb, v12, col); + BYTE c; + char *tmp; + int nOffset, screen_x, line, widthOffset; + + nOffset = x + PitchTbl[y + 160] + 64; + widthOffset = width - x + 1; + line = 0; + screen_x = 0; + tmp = pszStr; + while (*tmp) { + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + base; + } + if (screen_x < widthOffset) + line = (widthOffset - screen_x) >> 1; + nOffset += line; + while (*pszStr) { + c = gbFontTransTbl[(BYTE)*pszStr++]; + c = fontframe[c]; + line += fontkern[c] + base; + if (c) { + if (line < widthOffset) + CPrintString(nOffset, c, col); } - widthb += base + fontkern[v13]; - v7 = *v6; + nOffset += fontkern[c] + base; } } @@ -2265,8 +2178,6 @@ int DrawDurIcon4Item(ItemStruct *item, int x, int frame) case ITYPE_STAFF: frame = 8; break; - default: - break; } } else { frame = 1; @@ -2441,7 +2352,7 @@ void DrawSpellBook() void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col) { - BYTE nCel; + BYTE c; char *tmp; int screen_x, line, width; @@ -2451,24 +2362,22 @@ void PrintSBookStr(int x, int y, BOOL cjustflag, char *pszStr, char col) screen_x = 0; tmp = pszStr; while (*tmp) { - nCel = gbFontTransTbl[(BYTE)*tmp]; - tmp++; - screen_x += fontkern[fontframe[nCel]] + 1; + c = gbFontTransTbl[(BYTE)*tmp++]; + screen_x += fontkern[fontframe[c]] + 1; } if (screen_x < 222) line = (222 - screen_x) >> 1; width += line; } while (*pszStr) { - nCel = gbFontTransTbl[(BYTE)*pszStr]; - pszStr++; - nCel = fontframe[nCel]; - line += fontkern[nCel] + 1; - if (nCel) { + c = gbFontTransTbl[(BYTE)*pszStr++]; + c = fontframe[c]; + line += fontkern[c] + 1; + if (c) { if (line <= 222) - CPrintString(width, nCel, col); + CPrintString(width, c, col); } - width += fontkern[nCel] + 1; + width += fontkern[c] + 1; } } diff --git a/Source/control.h b/Source/control.h index f1057c839..3202ef36b 100644 --- a/Source/control.h +++ b/Source/control.h @@ -85,7 +85,7 @@ void CheckBtnUp(); void FreeControlPan(); BOOL control_WriteStringToBuffer(BYTE *str); void DrawInfoBox(); -void control_print_info_str(int y, char *str, BOOLEAN center, int lines); +void control_print_info_str(int y, char *str, BOOL center, int lines); void PrintGameStr(int x, int y, char *str, int color); void DrawChr(); void ADD_PlrStringXY(int x, int y, int width, char *pszStr, char col); diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 796b23a1b..826fb0358 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -129,7 +129,7 @@ void CheckTown() || cursmx == missile[mx]._mix - 2 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix - 1 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix && cursmy == missile[mx]._miy) { - trigflag_3 = 1; + trigflag = TRUE; ClearPanel(); strcpy(infostr, "Town Portal"); sprintf(tempstr, "from %s", plr[missile[mx]._misource]._pName); @@ -155,7 +155,7 @@ void CheckRportal() || cursmx == missile[mx]._mix - 2 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix - 1 && cursmy == missile[mx]._miy - 2 || cursmx == missile[mx]._mix && cursmy == missile[mx]._miy) { - trigflag_3 = 1; + trigflag = TRUE; ClearPanel(); strcpy(infostr, "Portal to"); if (!setlevel) @@ -263,7 +263,7 @@ void CheckCursMove() pcursplr = -1; uitemflag = 0; panelflag = 0; - trigflag_3 = 0; + trigflag = FALSE; if(plr[myplr]._pInvincible) { return; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index d003f4115..eb4462357 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1291,6 +1291,7 @@ void diablo_pause_game() // 525740: using guessed type int PauseMode; // 679660: using guessed type char gbMaxPlayers; +/* NOTE: `return` must be used instead of `break` to be bin exact as C++ */ void PressChar(int vkey) { if(gmenu_exception() || control_talk_last_key(vkey) || sgnTimeoutCurs != 0 || deathflag) { @@ -1316,11 +1317,11 @@ void PressChar(int vkey) case 'G': case 'g': DecreaseGamma(); - break; + return; case 'F': case 'f': IncreaseGamma(); - break; + return; case 'I': case 'i': if(!stextflag) { @@ -1336,7 +1337,7 @@ void PressChar(int vkey) } } } - break; + return; case 'C': case 'c': if(!stextflag) { @@ -1352,7 +1353,7 @@ void PressChar(int vkey) } } } - break; + return; case 'Q': case 'q': if(!stextflag) { @@ -1363,11 +1364,11 @@ void PressChar(int vkey) questlog = FALSE; } } - break; + return; case 'Z': case 'z': zoomflag = zoomflag == 0; - break; + return; case 'S': case 's': if(!stextflag) { @@ -1379,86 +1380,86 @@ void PressChar(int vkey) } track_repeat_walk(0); } - break; + return; case 'B': case 'b': if(!stextflag) { invflag = 0; sbookflag = sbookflag == 0; } - break; + return; case '+': case '=': if(automapflag) { AutomapZoomIn(); } - break; + return; case '-': case '_': if(automapflag) { AutomapZoomOut(); } - break; + return; case 'v': NetSendCmdString(1 << myplr, gszProductName); - break; + return; case 'V': NetSendCmdString(1 << myplr, gszVersionNumber); - break; + return; case '!': case '1': if(plr[myplr].SpdList[0]._itype != -1 && plr[myplr].SpdList[0]._itype != 11) { UseInvItem(myplr, 47); } - break; + return; case '@': case '2': if(plr[myplr].SpdList[1]._itype != -1 && plr[myplr].SpdList[1]._itype != 11) { UseInvItem(myplr, 48); } - break; + return; case '#': case '3': if(plr[myplr].SpdList[2]._itype != -1 && plr[myplr].SpdList[2]._itype != 11) { UseInvItem(myplr, 49); } - break; + return; case '$': case '4': if(plr[myplr].SpdList[3]._itype != -1 && plr[myplr].SpdList[3]._itype != 11) { UseInvItem(myplr, 50); } - break; + return; case '%': case '5': if(plr[myplr].SpdList[4]._itype != -1 && plr[myplr].SpdList[4]._itype != 11) { UseInvItem(myplr, 51); } - break; + return; case '^': case '6': if(plr[myplr].SpdList[5]._itype != -1 && plr[myplr].SpdList[5]._itype != 11) { UseInvItem(myplr, 52); } - break; + return; case '&': case '7': if(plr[myplr].SpdList[6]._itype != -1 && plr[myplr].SpdList[6]._itype != 11) { UseInvItem(myplr, 53); } - break; + return; case '*': case '8': #ifdef _DEBUG if(debug_mode_key_inverted_v || debug_mode_key_w) { NetSendCmd(TRUE, CMD_CHEAT_EXPERIENCE); - break; + return; } #endif if(plr[myplr].SpdList[7]._itype != -1 && plr[myplr].SpdList[7]._itype != 11) { UseInvItem(myplr, 54); } - break; + return; #ifdef _DEBUG case ')': case '0': @@ -1478,52 +1479,52 @@ void PressChar(int vkey) } arrowdebug++; } - break; + return; case ':': if(currlevel == 0 && debug_mode_key_w) { SetAllSpellsCheat(); } - break; + return; case '[': if(currlevel == 0 && debug_mode_key_w) { TakeGoldCheat(); } - break; + return; case ']': if(currlevel == 0 && debug_mode_key_w) { MaxSpellsCheat(); } - break; + return; case 'a': if(debug_mode_key_inverted_v) { spelldata[SPL_TELEPORT].sTownSpell = 1; plr[myplr]._pSplLvl[plr[myplr]._pSpell]++; } - break; + return; case 'D': PrintDebugPlayer(TRUE); - break; + return; case 'd': PrintDebugPlayer(FALSE); - break; + return; case 'e': if(debug_mode_key_d) { sprintf(tempstr, "EFlag = %i", plr[myplr]._peflag); NetSendCmdString(1 << myplr, tempstr); } - break; + return; case 'L': case 'l': if(debug_mode_key_inverted_v) { ToggleLighting(); } - break; + return; case 'M': NextDebugMonster(); - break; + return; case 'm': GetDebugMonster(); - break; + return; case 'R': case 'r': sprintf(tempstr, "seed = %i", glSeedTbl[currlevel]); @@ -1532,7 +1533,7 @@ void PressChar(int vkey) NetSendCmdString(1 << myplr, tempstr); sprintf(tempstr, "End = %i", glEndSeed[currlevel]); NetSendCmdString(1 << myplr, tempstr); - break; + return; case 'T': case 't': if(debug_mode_key_inverted_v) { @@ -1541,17 +1542,17 @@ void PressChar(int vkey) sprintf(tempstr, "CX = %i CY = %i DP = %i", cursmx, cursmy, dungeon[cursmx][cursmy]); NetSendCmdString(1 << myplr, tempstr); } - break; + return; case '|': if(currlevel == 0 && debug_mode_key_w) { GiveGoldCheat(); } - break; + return; case '~': if(currlevel == 0 && debug_mode_key_w) { StoresCheat(); } - break; + return; #endif } } diff --git a/Source/engine.cpp b/Source/engine.cpp index 9d38cfca8..38228976c 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -2090,234 +2090,208 @@ void engine_draw_pixel(int sx, int sy) // 52B99C: using guessed type int gbNotInView; // 69CF0C: using guessed type int gpBufEnd; +// Exact copy from https://github.com/erich666/GraphicsGems/blob/dad26f941e12c8bf1f96ea21c1c04cd2206ae7c9/gems/DoubleLine.c +// Except: +// * not in view checks +// * global variable instead of reverse flag +// * condition for pixels_left < 0 removed + /* - * Xiaolin Wu's anti-aliased line algorithm - */ +Symmetric Double Step Line Algorithm +by Brian Wyvill +from "Graphics Gems", Academic Press, 1990 +*/ + +#define GG_SWAP(A, B) \ + { \ + (A) ^= (B); \ + (B) ^= (A); \ + (A) ^= (B); \ + } +#define GG_ABSOLUTE(I, J, K) (((I) - (J)) * ((K) = (((I) - (J)) < 0 ? -1 : 1))) + void DrawLine(int x0, int y0, int x1, int y1, BYTE col) { - int i, sx, sy, dx, dy, nx, ny, xlen, ylen, pixels, remain, xy_same, line_dir, mult_2, mult_4; + int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left; + int sign_x, sign_y, step, i; + int x1_, y1_; gbPixelCol = col; gbNotInView = FALSE; - if(x0 < 0 + 64 || x0 >= 640 + 64) { + if (x0 < 0 + 64 || x0 >= 640 + 64) { gbNotInView = TRUE; } - if(x1 < 0 + 64 || x1 >= 640 + 64) { + if (x1 < 0 + 64 || x1 >= 640 + 64) { gbNotInView = TRUE; } - if(y0 < 0 + 160 || y0 >= 352 + 160) { + if (y0 < 0 + 160 || y0 >= 352 + 160) { gbNotInView = TRUE; } - if(y1 < 0 + 160 || y1 >= 352 + 160) { + if (y1 < 0 + 160 || y1 >= 352 + 160) { gbNotInView = TRUE; } - if(x1 - x0 < 0) { - nx = -1; - } else { - nx = 1; - } - xlen = nx * (x1 - x0); - - if(y1 - y0 < 0) { - ny = -1; - } else { - ny = 1; - } - ylen = ny * (y1 - y0); - - if(ny == nx) { - xy_same = 1; - } else { - xy_same = -1; - } + dx = GG_ABSOLUTE(x1, x0, sign_x); + dy = GG_ABSOLUTE(y1, y0, sign_y); + /* decide increment sign by the slope sign */ + if (sign_x == sign_y) + step = 1; + else + step = -1; - if(ylen > xlen) { - x0 ^= y0 ^= x0 ^= y0; - x1 ^= y1 ^= x1 ^= y1; - xlen ^= ylen ^= xlen ^= ylen; + if (dy > dx) { /* chooses axis of greatest movement (make + * dx) */ + GG_SWAP(x0, y0); + GG_SWAP(x1, y1); + GG_SWAP(dx, dy); gbRotateMap = TRUE; - } else { + } else gbRotateMap = FALSE; - } - - if(x0 > x1) { - sx = x1; - sy = y1; - dx = x0; - dy = y0; + /* note error check for dx==0 should be included here */ + if (x0 > x1) { /* start from the smaller coordinate */ + x = x1; + y = y1; + x1_ = x0; + y1_ = y0; } else { - sx = x0; - sy = y0; - dx = x1; - dy = y1; + x = x0; + y = y0; + x1_ = x1; + y1_ = y1; } - pixels = (xlen - 1) / 4; - remain = (xlen - 1) % 4; - engine_draw_pixel(sx, sy); - engine_draw_pixel(dx, dy); - - line_dir = (ylen << 2) - xlen - xlen; - if(line_dir < 0) { - mult_2 = ylen << 1; - mult_4 = (mult_2 << 1) - xlen; - for(i = 0; i < pixels; i++) { - sx++; - dx--; - if(mult_4 < 0) { - engine_draw_pixel(sx, sy); - sx++; - engine_draw_pixel(sx, sy); - engine_draw_pixel(dx, dy); - dx--; - engine_draw_pixel(dx, dy); - mult_4 += mult_2 + mult_2; - } else if(mult_4 < mult_2) { - engine_draw_pixel(sx, sy); - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - engine_draw_pixel(dx, dy); - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - mult_4 += line_dir; + /* Note dx=n implies 0 - n or (dx+1) pixels to be set */ + /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */ + /* In fact (dx-1)/4 as 2 pixels are already plotted */ + xend = (dx - 1) / 4; + pixels_left = (dx - 1) % 4; /* number of pixels left over at the end */ + engine_draw_pixel(x, y); + engine_draw_pixel(x1_, y1_); /* plot first two points */ + incr2 = 4 * dy - 2 * dx; + if (incr2 < 0) { /* slope less than 1/2 */ + c = 2 * dy; + incr1 = 2 * c; + D = incr1 - dx; + + for (i = 0; i < xend; i++) { /* plotting loop */ + ++x; + --x1_; + if (D < 0) { + /* pattern 1 forwards */ + engine_draw_pixel(x, y); + engine_draw_pixel(++x, y); + /* pattern 1 backwards */ + engine_draw_pixel(x1_, y1_); + engine_draw_pixel(--x1_, y1_); + D += incr1; } else { - sy += xy_same; - engine_draw_pixel(sx, sy); - sx++; - engine_draw_pixel(sx, sy); - dy -= xy_same; - engine_draw_pixel(dx, dy); - dx--; - engine_draw_pixel(dx, dy); - mult_4 += line_dir; - } - } - if(remain != 0) { - if(mult_4 < 0) { - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dx--; - engine_draw_pixel(dx, dy); - } - } else if(mult_4 < mult_2) { - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dx--; - engine_draw_pixel(dx, dy); + if (D < c) { + /* pattern 2 forwards */ + engine_draw_pixel(x, y); + engine_draw_pixel(++x, y += step); + /* pattern 2 backwards */ + engine_draw_pixel(x1_, y1_); + engine_draw_pixel(--x1_, y1_ -= step); + } else { + /* pattern 3 forwards */ + engine_draw_pixel(x, y += step); + engine_draw_pixel(++x, y); + /* pattern 3 backwards */ + engine_draw_pixel(x1_, y1_ -= step); + engine_draw_pixel(--x1_, y1_); } + D += incr2; + } + } /* end for */ + + /* plot last pattern */ + if (pixels_left) { + if (D < 0) { + engine_draw_pixel(++x, y); /* pattern 1 */ + if (pixels_left > 1) + engine_draw_pixel(++x, y); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_); } else { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); + if (D < c) { + engine_draw_pixel(++x, y); /* pattern 2 */ + if (pixels_left > 1) + engine_draw_pixel(++x, y += step); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_); + } else { + /* pattern 3 */ + engine_draw_pixel(++x, y += step); + if (pixels_left > 1) + engine_draw_pixel(++x, y); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_ -= step); } } - } - } else { - mult_2 = (ylen - xlen) << 1; - mult_4 = (mult_2 << 1) + xlen; - for(i = 0; i < pixels; i++) { - sx++; - dx--; - if(mult_4 > 0) { - sy += xy_same; - engine_draw_pixel(sx, sy); - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - dy -= xy_same; - engine_draw_pixel(dx, dy); - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - mult_4 += mult_2 + mult_2; - } else if(mult_4 < mult_2) { - engine_draw_pixel(sx, sy); - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - engine_draw_pixel(dx, dy); - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - mult_4 += line_dir; + } /* end if pixels_left */ + } + /* end slope < 1/2 */ + else { /* slope greater than 1/2 */ + c = 2 * (dy - dx); + incr1 = 2 * c; + D = incr1 + dx; + for (i = 0; i < xend; i++) { + ++x; + --x1_; + if (D > 0) { + /* pattern 4 forwards */ + engine_draw_pixel(x, y += step); + engine_draw_pixel(++x, y += step); + /* pattern 4 backwards */ + engine_draw_pixel(x1_, y1_ -= step); + engine_draw_pixel(--x1_, y1_ -= step); + D += incr1; } else { - sy += xy_same; - engine_draw_pixel(sx, sy); - sx++; - engine_draw_pixel(sx, sy); - dy -= xy_same; - engine_draw_pixel(dx, dy); - dx--; - engine_draw_pixel(dx, dy); - mult_4 += line_dir; - } - } - if(remain != 0) { - if(mult_4 > 0) { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - } - } else if(mult_4 < mult_2) { - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - dx--; - engine_draw_pixel(dx, dy); + if (D < c) { + /* pattern 2 forwards */ + engine_draw_pixel(x, y); + engine_draw_pixel(++x, y += step); + + /* pattern 2 backwards */ + engine_draw_pixel(x1_, y1_); + engine_draw_pixel(--x1_, y1_ -= step); + } else { + /* pattern 3 forwards */ + engine_draw_pixel(x, y += step); + engine_draw_pixel(++x, y); + /* pattern 3 backwards */ + engine_draw_pixel(x1_, y1_ -= step); + engine_draw_pixel(--x1_, y1_); } + D += incr2; + } + } /* end for */ + /* plot last pattern */ + if (pixels_left) { + if (D > 0) { + engine_draw_pixel(++x, y += step); /* pattern 4 */ + if (pixels_left > 1) + engine_draw_pixel(++x, y += step); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_ -= step); } else { - sy += xy_same; - sx++; - engine_draw_pixel(sx, sy); - if(remain > 1) { - sx++; - engine_draw_pixel(sx, sy); - } - if(remain > 2) { - if(mult_4 > mult_2) { - dy -= xy_same; - dx--; - engine_draw_pixel(dx, dy); - } else { - dx--; - engine_draw_pixel(dx, dy); + if (D < c) { + engine_draw_pixel(++x, y); /* pattern 2 */ + if (pixels_left > 1) + engine_draw_pixel(++x, y += step); + if (pixels_left > 2) + engine_draw_pixel(--x1_, y1_); + } else { + /* pattern 3 */ + engine_draw_pixel(++x, y += step); + if (pixels_left > 1) + engine_draw_pixel(++x, y); + if (pixels_left > 2) { + if (D > c) /* step 3 */ + engine_draw_pixel(--x1_, y1_ -= step); + else /* step 2 */ + engine_draw_pixel(--x1_, y1_); } } } diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 7fe8ca9b4..ee4583d50 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -7,8 +7,8 @@ BOOLEAN mouseNavigation; // weak void *PentSpin_cel; TMenuItem *sgpCurrItem; void *BigTGold_cel; -int dword_634474; // weak -char byte_634478; // weak +int PentSpin_tick; // weak +char PentSpin_frame; // weak void(*dword_63447C)(TMenuItem *); TMenuItem *sgpCurrentMenu; // idb void *option_cel; @@ -74,7 +74,7 @@ void FreeGMenu() void gmenu_init_menu() { - byte_634478 = 1; + PentSpin_frame = 1; sgpCurrentMenu = 0; sgpCurrItem = 0; dword_63447C = 0; @@ -87,7 +87,7 @@ void gmenu_init_menu() optbar_cel = LoadFileInMem("Data\\optbar.CEL", 0); } // 634464: using guessed type char mouseNavigation; -// 634478: using guessed type char byte_634478; +// 634478: using guessed type char PentSpin_frame; // 63448C: using guessed type int sgCurrentMenuIdx; BOOL gmenu_exception() @@ -161,29 +161,33 @@ void gmenu_up_down(BOOL isDown) void gmenu_draw() { - int v0; // edi - TMenuItem *i; // esi - DWORD v2; // eax + int y; + TMenuItem *i; + DWORD ticks; if (sgpCurrentMenu) { if (dword_63447C) dword_63447C(sgpCurrentMenu); CelDecodeOnly(236, 262, (BYTE *)sgpLogo, 1, 296); - v0 = 320; - for (i = sgpCurrentMenu; i->fnMenu; v0 += 45) { - gmenu_draw_menu_item(i, v0); - ++i; + y = 320; + i = sgpCurrentMenu; + if (sgpCurrentMenu->fnMenu) { + while (i->fnMenu) { + gmenu_draw_menu_item(i, y); + i++; + y += 45; + } } - v2 = GetTickCount(); - if ((signed int)(v2 - dword_634474) > 25) { - if (++byte_634478 == 9) - byte_634478 = 1; - dword_634474 = v2; + + ticks = GetTickCount(); + if ((int)(ticks - PentSpin_tick) > 25) { + PentSpin_frame++; + if (PentSpin_frame == 9) + PentSpin_frame = 1; + PentSpin_tick = ticks; } } } -// 634474: using guessed type int dword_634474; -// 634478: using guessed type char byte_634478; void gmenu_draw_menu_item(TMenuItem *pItem, int a2) { @@ -226,11 +230,11 @@ void gmenu_draw_menu_item(TMenuItem *pItem, int a2) gmenu_print_text(384 - (v5 >> 1), v2, v3->pszStr); if (v3 == sgpCurrItem) { v13 = v2 + 1; - CelDecodeOnly(v11 - 54, v13, (BYTE *)PentSpin_cel, (unsigned char)byte_634478, 48); - CelDecodeOnly(v11 + v5 + 4, v13, (BYTE *)PentSpin_cel, (unsigned char)byte_634478, 48); + CelDecodeOnly(v11 - 54, v13, (BYTE *)PentSpin_cel, (unsigned char)PentSpin_frame, 48); + CelDecodeOnly(v11 + v5 + 4, v13, (BYTE *)PentSpin_cel, (unsigned char)PentSpin_frame, 48); } } -// 634478: using guessed type char byte_634478; +// 634478: using guessed type char PentSpin_frame; // 69BEF8: using guessed type int light_table_index; void gmenu_clear_buffer(int x, int y, int width, int height) diff --git a/Source/init.cpp b/Source/init.cpp index 91cf3f64b..95cdd23e0 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -328,38 +328,35 @@ char *init_strip_trailing_slash(char *path) return result; } -int init_read_test_file(char *mpq_path, char *mpq_name, int flags, HANDLE *archive) +BOOL init_read_test_file(char *pszPath, char *pszArchive, int flags, HANDLE *phArchive) { - char *v4; // edi - DWORD v5; // eax - const char *v7; // ebx - const char *v8; // esi - char Buffer[MAX_PATH]; // [esp+Ch] [ebp-108h] - char *mpq_patha; // [esp+110h] [ebp-4h] - - v4 = mpq_name; - mpq_patha = mpq_path; - v5 = GetLogicalDriveStrings(sizeof(Buffer), Buffer); - if (!v5 || v5 > sizeof(Buffer)) - return 0; - while (*v4 == '\\') - ++v4; - v7 = Buffer; - if (!Buffer[0]) - return 0; - while (1) { - v8 = v7; - v7 += strlen(v7) + 1; - if (GetDriveType(v8) == DRIVE_CDROM) { - strcpy(mpq_patha, v8); - strcat(mpq_patha, v4); - if (SFileOpenArchive(mpq_patha, flags, 1, archive)) - break; + DWORD dwSize; + char *pszDrive, *pszRoot; + char szDrive[MAX_PATH]; + + dwSize = GetLogicalDriveStrings(sizeof(szDrive), szDrive); + if(dwSize == 0 || dwSize > sizeof(szDrive)) { + return FALSE; + } + + while(*pszArchive == '\\') { + pszArchive++; + } + + pszDrive = szDrive; + while(*pszDrive != '\0') { + pszRoot = pszDrive; + while(*pszDrive++ != '\0'); + if(GetDriveType(pszRoot) == DRIVE_CDROM) { + strcpy(pszPath, pszRoot); + strcat(pszPath, pszArchive); + if(SFileOpenArchive(pszPath, flags, 1, phArchive)) { + return TRUE; + } } - if (!*v7) - return 0; } - return 1; + + return FALSE; } void init_get_file_info() diff --git a/Source/init.h b/Source/init.h index cca31acf8..7b7a46ac9 100644 --- a/Source/init.h +++ b/Source/init.h @@ -25,7 +25,7 @@ void init_await_mom_parent_exit(); void init_archives(); HANDLE init_test_access(char *mpq_path, char *mpq_name, char *reg_loc, int flags, int fs); char *init_strip_trailing_slash(char *path); -int init_read_test_file(char *mpq_path, char *mpq_name, int flags, HANDLE *archive); +BOOL init_read_test_file(char *pszPath, char *pszArchive, int flags, HANDLE *phArchive); void init_get_file_info(); LRESULT __stdcall MainWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); void init_activate_window(HWND hWnd, BOOL bActive); diff --git a/Source/items.cpp b/Source/items.cpp index f9f4a20e9..8223624c6 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1992,24 +1992,23 @@ void SpawnUnique(int uid, int x, int y) { int ii, itype; - if (numitems < MAXITEMS) { - ii = itemavail[0]; - GetSuperItemSpace(x, y, itemavail[0]); - itype = 0; - itemactive[numitems] = ii; - itemavail[0] = itemavail[MAXITEMS - numitems - 1]; + if (numitems >= MAXITEMS) + return; - if (AllItemsList[0].iItemId != UniqueItemList[uid].UIItemId) { - while (AllItemsList[itype].iItemId != UniqueItemList[uid].UIItemId) { - itype++; - } - } + ii = itemavail[0]; + GetSuperItemSpace(x, y, ii); + itemavail[0] = itemavail[MAXITEMS - numitems - 1]; + itemactive[numitems] = ii; - GetItemAttrs(ii, itype, currlevel); - GetUniqueItem(ii, uid); - SetupItem(ii); - numitems++; + itype = 0; + while (AllItemsList[itype].iItemId != UniqueItemList[uid].UIItemId) { + itype++; } + + GetItemAttrs(ii, itype, currlevel); + GetUniqueItem(ii, uid); + SetupItem(ii); + numitems++; } void ItemRndDur(int ii) @@ -2356,7 +2355,7 @@ void SpawnRock() item[i]._ix = xx; item[i]._iy = yy; dItem[xx][item[i]._iy] = i + 1; - GetItemAttrs(i, 7, currlevel); + GetItemAttrs(i, IDI_ROCK, currlevel); SetupItem(i); item[i]._iSelFlag = 2; item[i]._iPostDraw = 1; @@ -2372,10 +2371,10 @@ void RespawnItem(int i, BOOL FlipFlag) it = ItemCAnimTbl[item[i]._iCurs]; item[i]._iAnimData = itemanims[it]; item[i]._iAnimLen = ItemAnimLs[it]; - item[i]._iRequest = FALSE; item[i]._iAnimWidth = 96; item[i]._iAnimWidth2 = 16; item[i]._iPostDraw = FALSE; + item[i]._iRequest = FALSE; if (FlipFlag) { item[i]._iAnimFrame = 1; item[i]._iAnimFlag = TRUE; @@ -2470,10 +2469,10 @@ void GetItemStr(int i) int nGold; if (item[i]._itype != ITYPE_GOLD) { - if (!item[i]._iIdentified) - strcpy(infostr, item[i]._iName); - else + if (item[i]._iIdentified) strcpy(infostr, item[i]._iIName); + else + strcpy(infostr, item[i]._iName); if (item[i]._iMagical == ITEM_QUALITY_MAGIC) infoclr = COL_BLUE; diff --git a/Source/lighting.cpp b/Source/lighting.cpp index e5aaa9f77..c0ea888bb 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -916,12 +916,12 @@ void MakeLightTable() *tbl++ = 0; } - for (i = 0; i < 16; i++) { - for (j = 0; j < 128; j++) { - if (j > (i + 1) * 8) { /* check */ - lightradius[i][j] = 15; + for (k = 0; k < 16; k++) { + for (l = 0; l < 128; l++) { + if (l > (k + 1) * 8) { + lightradius[k][l] = 15; } else { - lightradius[i][j] = j * 15.0 / ((i + 1) * 8.0) + 0.5; + lightradius[k][l] = l * 15.0 / ((k + 1) * 8.0) + 0.5; } } } diff --git a/Source/list.h b/Source/list.h index ae69ac0e6..9738df4dc 100644 --- a/Source/list.h +++ b/Source/list.h @@ -152,6 +152,7 @@ void TList::Insert(T *node, InsertPos pos, T *ref) break; case BEFORE: i->InsertBefore(node, reflink); + break; } } diff --git a/Source/mainmenu.cpp b/Source/mainmenu.cpp index 386a5a2f7..fa551e289 100644 --- a/Source/mainmenu.cpp +++ b/Source/mainmenu.cpp @@ -20,9 +20,9 @@ void mainmenu_refresh_music() } while (!menu_music_track_id || menu_music_track_id == 1); } -void __stdcall mainmenu_create_hero(char *name_1, char *name_2) +void __stdcall mainmenu_create_hero(int arg1, int arg2, int arg3, int arg4, char *name_1, char *name_2) { - if (UiValidPlayerName(name_1)) + if (UiValidPlayerName(name_2)) pfile_create_save_file(name_1, name_2); } diff --git a/Source/mainmenu.h b/Source/mainmenu.h index 8e7f9257a..a9155438e 100644 --- a/Source/mainmenu.h +++ b/Source/mainmenu.h @@ -5,7 +5,7 @@ extern char gszHero[16]; void mainmenu_refresh_music(); -void __stdcall mainmenu_create_hero(char *name_1, char *name_2); +void __stdcall mainmenu_create_hero(int arg1, int arg2, int arg3, int arg4, char *name_1, char *name_2); int __stdcall mainmenu_select_hero_dialog( const _SNETPROGRAMDATA *client_info, const _SNETPLAYERDATA *user_info, diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 6896ce8ad..52a35f247 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1750,7 +1750,7 @@ BOOL CheckIfTrig(int x, int y) { int i; - for (i = 0; i < trigflag_4; i++) { + for (i = 0; i < numtrigs; i++) { if ((x == trigs[i]._tx && y == trigs[i]._ty) || (abs(trigs[i]._tx - x) < 2 && abs(trigs[i]._ty - y) < 2)) return TRUE; } @@ -3188,80 +3188,90 @@ void MI_Fireball(int i) void MI_Lightctrl(int i) { - int v1; // esi - int v2; // eax - int v3; // eax - int v5; // edi - signed int v6; // ebx - signed int v7; // edx - int v8; // ecx - int v9; // eax - int v10; // [esp-10h] [ebp-24h] - int v11; // [esp-Ch] [ebp-20h] - int v12; // [esp-8h] [ebp-1Ch] - int v13; // [esp+Ch] [ebp-8h] - int ia; // [esp+10h] [ebp-4h] + int pn, dam, p, mx, my; - ia = i; - v1 = i; - v2 = missile[i]._misource; - --missile[v1]._mirange; - if (v2 == -1) { - v5 = random(81, currlevel) + 2 * currlevel; - } else if (missile[v1]._micaster) { - v5 = 2 - * ((unsigned char)monster[v2].mMinDamage - + random(80, (unsigned char)monster[v2].mMaxDamage - (unsigned char)monster[v2].mMinDamage + 1)); - } else { - v3 = random(79, plr[v2]._pLevel); - v5 = (v3 + random(79, 2) + 2) << 6; - } - missile[v1]._mitxoff += missile[v1]._mixvel; - missile[v1]._mityoff += missile[v1]._miyvel; - GetMissilePos(ia); - v6 = missile[v1]._mix; - v7 = missile[v1]._miy; - v8 = missile[v1]._misource; - v13 = missile[v1]._miy; - v9 = dPiece[missile[v1]._mix][v7]; - if (v8 != -1 || v6 != missile[v1]._misx || v7 != missile[v1]._misy) { - if (!nMissileTable[v9]) - goto LABEL_12; - missile[v1]._mirange = 0; - } - if (!nMissileTable[v9]) { - LABEL_12: - if (v6 == missile[v1]._miVar1 && v7 == missile[v1]._miVar2 || v6 <= 0 || v7 <= 0 || v6 >= MAXDUNX || v7 >= MAXDUNY) - goto LABEL_27; - if (v8 == -1) { - v12 = missile[v1]._mispllvl; - v11 = v5; - v10 = -1; + /// ASSERT: assert((DWORD)i < MAXMISSILES); + missile[i]._mirange--; + + p = missile[i]._misource; + if(p != -1) { + if(missile[i]._micaster == 0) { + dam = (random(79, 2) + random(79, plr[p]._pLevel) + 2) << 6; } else { - if (missile[v1]._micaster == 1) { - v9 = (int)monster[v8].MType; - _LOBYTE(v9) = *(_BYTE *)v9; - if ((unsigned char)v9 >= MT_STORM && (unsigned char)v9 <= MT_MAEL) { - _LOBYTE(v9) = missile[v1]._micaster; - AddMissile(v6, v7, missile[v1]._misx, missile[v1]._misy, ia, MIS_LIGHTNING2, v9, v8, v5, missile[v1]._mispllvl); - LABEL_26: - v7 = v13; - missile[v1]._miVar1 = missile[v1]._mix; - missile[v1]._miVar2 = missile[v1]._miy; - goto LABEL_27; + dam = 2 * (monster[p].mMinDamage + random(80, monster[p].mMaxDamage - monster[p].mMinDamage + 1)); + } + } else { + dam = random(81, currlevel) + 2 * currlevel; + } + + missile[i]._mitxoff += missile[i]._mixvel; + missile[i]._mityoff += missile[i]._miyvel; + GetMissilePos(i); + + mx = missile[i]._mix; + my = missile[i]._miy; + /// ASSERT: assert((DWORD)mx < MAXDUNX); + /// ASSERT: assert((DWORD)my < MAXDUNY); + pn = dPiece[mx][my]; + /// ASSERT: assert((DWORD)pn <= MAXTILES); + + if(missile[i]._misource == -1) { + if((mx != missile[i]._misx || my != missile[i]._misy) && nMissileTable[pn] != 0) { + missile[i]._mirange = 0; + } + } else if(nMissileTable[pn] != 0) { + missile[i]._mirange = 0; + } + if(nMissileTable[pn] == 0) { + if((mx != missile[i]._miVar1 || my != missile[i]._miVar2) && mx > 0 && my > 0 && mx < MAXDUNX && my < MAXDUNY) { + if(missile[i]._misource != -1) { + if(missile[i]._micaster == 1 + && monster[missile[i]._misource].MType->mtype >= MT_STORM + && monster[missile[i]._misource].MType->mtype <= MT_MAEL) { + AddMissile( + mx, + my, + missile[i]._misx, + missile[i]._misy, + i, + MIS_LIGHTNING2, + missile[i]._micaster, + missile[i]._misource, + dam, + missile[i]._mispllvl); + } else { + AddMissile( + mx, + my, + missile[i]._misx, + missile[i]._misy, + i, + MIS_LIGHTNING, + missile[i]._micaster, + missile[i]._misource, + dam, + missile[i]._mispllvl); } + } else { + AddMissile( + mx, + my, + missile[i]._misx, + missile[i]._misy, + i, + MIS_LIGHTNING, + missile[i]._micaster, + missile[i]._misource, + dam, + missile[i]._mispllvl); } - v12 = missile[v1]._mispllvl; - v11 = v5; - v10 = v8; + missile[i]._miVar1 = missile[i]._mix; + missile[i]._miVar2 = missile[i]._miy; } - _LOBYTE(v9) = missile[v1]._micaster; - AddMissile(v6, v7, missile[v1]._misx, missile[v1]._misy, ia, MIS_LIGHTNING, v9, v10, v11, v12); - goto LABEL_26; } -LABEL_27: - if (!missile[v1]._mirange || v6 <= 0 || v7 <= 0 || v6 >= MAXDUNX || v7 > MAXDUNY) - missile[v1]._miDelFlag = TRUE; + if(missile[i]._mirange == 0 || mx <= 0 || my <= 0 || mx >= MAXDUNX || my > MAXDUNY) { + missile[i]._miDelFlag = TRUE; + } } void MI_Lightning(int i) diff --git a/Source/monster.cpp b/Source/monster.cpp index 078449cb4..8e034880a 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -958,7 +958,7 @@ void InitMonsters() if (!setlevel && currlevel == 16) LoadDiabMonsts(); } - nt = trigflag_4; + nt = numtrigs; if (currlevel == 15) nt = 1; for (i = 0; i < nt; i++) { @@ -1698,6 +1698,8 @@ void M2MStartKill(int i, int mid) if ((DWORD)i >= MAXMONSTERS) { app_fatal("M2MStartKill: Invalid monster (attacker) %d", i); + } + if ((DWORD)i >= MAXMONSTERS) { /// BUGFIX: should check `mid` app_fatal("M2MStartKill: Invalid monster (killed) %d", mid); } if (!monster[i].MType) @@ -3040,173 +3042,84 @@ BOOL MAI_Path(int i) void MAI_Snake(int i) { - int esi1; // esi - MonsterStruct *esi3; // esi - BOOLEAN v3; // zf - int v4; // ecx - int v5; // eax - int v6; // ST1C_4 - int v7; // edi - int v8; // edx - int v9; // ST18_4 - int v10; // ebx - int v11; // eax - //int v12; // ST1C_4 - int v14; // eax - int v15; // eax - int v16; // ecx - int v17; // edx - int v18; // ecx - int v19; // eax - //int v20; // ST1C_4 - int v22; // eax - //int v23; // ST1C_4 - int v24; // ebx - int v26; // ecx - int v27; // eax - int v28; // ecx - int v29; // ecx - int v30; // eax - int v31; // edx - int v32; // eax - int v33; // ecx - int v34; // ecx - int v35; // eax - char pattern[6]; // [esp+4h] [ebp-1Ch] - int micaster; // [esp+Ch] [ebp-14h] - int midir; // [esp+10h] [ebp-10h] - int v1; // [esp+14h] [ebp-Ch] - int v2; // [esp+18h] [ebp-8h] - int arglist; // [esp+1Ch] [ebp-4h] + MonsterStruct *Monst; + int fx, fy, mx, my, md; + int pnum; + int tmp; - esi1 = i; - arglist = i; if ((DWORD)i >= MAXMONSTERS) app_fatal("MAI_Snake: Invalid monster %d", i); - pattern[2] = 0; - pattern[3] = -1; - pattern[4] = -1; - pattern[5] = 0; - esi3 = &monster[esi1]; - pattern[0] = 1; - pattern[1] = 1; - v3 = esi3->_mmode == MM_STAND; - micaster = esi3->_menemy; - if (v3 && esi3->_msquelch) { - v4 = esi3->_mx; - v5 = (unsigned char)esi3->_menemyy; - v6 = esi3->_lasty; - v1 = (unsigned char)esi3->_menemyx; - v7 = v4 - v1; - v8 = esi3->_my; - v9 = esi3->_lastx; - v2 = v5; - v10 = v8 - v5; - midir = GetDirection(v4, v8, v9, v6); - esi3->_mdir = midir; - if (abs(v7) < 2) { - v11 = abs(v10); - //v13 = v12; - if (v11 < 2) { - v14 = esi3->_mVar1; - if (v14 == MM_DELAY - || v14 == MM_CHARGE - || (v15 = random(105, 100), v16 = (unsigned char)esi3->_mint + 20, v15 < v16)) { - M_StartAttack(arglist); - LABEL_49: - if (esi3->_mmode == MM_STAND) - esi3->_mAnimData = esi3->MType->Anims[MA_STAND].Data[esi3->_mdir]; - return; - } - v17 = 10 - (unsigned char)esi3->_mint + random(105, 10); - v18 = arglist; - LABEL_11: - M_StartDelay(v18, v17); - goto LABEL_49; - } - } - v19 = abs(v7); - //v21 = v20; - if (v19 >= 3 || (v22 = abs(v10), v22 >= 3)) /* v21 = v23, */ - { - v24 = arglist; - } else { - v24 = arglist; - if (LineClearF1(PosOkMonst, arglist, esi3->_mx, esi3->_my, v1, v2) && esi3->_mVar1 != MM_CHARGE) { - if (AddMissile(esi3->_mx, esi3->_my, v1, v2, midir, MIS_RHINO, micaster, arglist, 0, 0) != -1) { - PlayEffect(arglist, 0); - v26 = esi3->_my + 112 * esi3->_mx; - esi3->_mmode = MM_CHARGE; - dMonster[0][v26] = -1 - v24; - } - goto LABEL_49; - } - } - if (esi3->_mVar1 != MM_DELAY) { - v27 = random(106, 100); - v28 = 2 * (unsigned char)esi3->_mint; - if (v27 < 35 - v28) { - v17 = 15 - (unsigned char)esi3->_mint + random(106, 10); - v18 = v24; - goto LABEL_11; - } - } - v29 = esi3->_mgoalvar1; - v30 = midir + pattern[v29]; - if (v30 >= 0) { - v31 = v30 - 8; - if (v30 < 8) - v31 = midir + pattern[v29]; - } else { - v31 = v30 + 8; - } - esi3->_mgoalvar1 = v29 + 1; - if (v29 + 1 > 5) - esi3->_mgoalvar1 = 0; - v32 = esi3->_mgoalvar2; - v33 = v31 - v32; - if (v31 - v32 >= 0) { - if (v33 >= 8) - v33 -= 8; - } else { - v33 += 8; - } - if (v33 <= 0) { - LABEL_47: - if (!M_DumbWalk(v24, esi3->_mgoalvar2)) - M_CallWalk2(v24, esi3->_mdir); - goto LABEL_49; - } - if (v33 >= 4) { - if (v33 == 4) { - esi3->_mgoalvar2 = v31; - goto LABEL_47; + char pattern[6] = { 1, 1, 0, -1, -1, 0 }; + Monst = monster + i; + pnum = Monst->_menemy; + if (Monst->_mmode != MM_STAND || !Monst->_msquelch) + return; + fx = Monst->_menemyx; + fy = Monst->_menemyy; + mx = Monst->_mx - fx; + my = Monst->_my - fy; + md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); + Monst->_mdir = md; + if (abs(mx) >= 2 || abs(my) >= 2) { + if (abs(mx) < 3 && abs(my) < 3 && LineClearF1(PosOkMonst, i, Monst->_mx, Monst->_my, fx, fy) && Monst->_mVar1 != MM_CHARGE) { + if (AddMissile(Monst->_mx, Monst->_my, fx, fy, md, MIS_RHINO, pnum, i, 0, 0) != -1) { + PlayEffect(i, 0); + Monst->_mmode = MM_CHARGE; + dMonster[Monst->_mx][Monst->_my] = -1 - i; } - v34 = v32 - 1; - if (v32 - 1 < 0) { - v35 = v32 + 7; - goto LABEL_46; + } else if (Monst->_mVar1 == MM_DELAY || random(106, 100) >= 35 - 2 * Monst->_mint) { + if (md + pattern[Monst->_mgoalvar1] < 0) { + tmp = md + pattern[Monst->_mgoalvar1] + 8; + } else { + tmp = md + pattern[Monst->_mgoalvar1] - 8; + if (md + pattern[Monst->_mgoalvar1] < 8) + tmp = md + pattern[Monst->_mgoalvar1]; } - if (v34 >= 8) { - v35 = v32 - 9; - goto LABEL_46; + Monst->_mgoalvar1++; + if (Monst->_mgoalvar1 > 5) + Monst->_mgoalvar1 = 0; + if (tmp - Monst->_mgoalvar2 < 0) { + md = tmp - Monst->_mgoalvar2 + 8; + } else if (tmp - Monst->_mgoalvar2 >= 8) { + md = tmp - Monst->_mgoalvar2 - 8; + } else + md = tmp - Monst->_mgoalvar2; + if (md > 0) { + if (md < 4) { + if (Monst->_mgoalvar2 + 1 < 0) { + md = Monst->_mgoalvar2 + 9; + } else if (Monst->_mgoalvar2 + 1 >= 8) { + md = Monst->_mgoalvar2 - 7; + } else + md = Monst->_mgoalvar2 + 1; + Monst->_mgoalvar2 = md; + } else if (md == 4) { + Monst->_mgoalvar2 = tmp; + } else { + if (Monst->_mgoalvar2 - 1 < 0) { + md = Monst->_mgoalvar2 + 7; + } else if (Monst->_mgoalvar2 - 1 >= 8) { + md = Monst->_mgoalvar2 - 9; + } else + md = Monst->_mgoalvar2 - 1; + Monst->_mgoalvar2 = md; + } } + if (!M_DumbWalk(i, Monst->_mgoalvar2)) + M_CallWalk2(i, Monst->_mdir); } else { - v34 = v32 + 1; - if (v32 + 1 < 0) { - v35 = v32 + 9; - LABEL_46: - esi3->_mgoalvar2 = v35; - goto LABEL_47; - } - if (v34 >= 8) { - v35 = v32 - 7; - goto LABEL_46; - } + M_StartDelay(i, 15 - Monst->_mint + random(106, 10)); } - v35 = v34; - goto LABEL_46; + } else { + if (Monst->_mVar1 == MM_DELAY + || Monst->_mVar1 == MM_CHARGE + || (random(105, 100) < Monst->_mint + 20)) { + M_StartAttack(i); + } else + M_StartDelay(i, 10 - Monst->_mint + random(105, 10)); } + if (Monst->_mmode == MM_STAND) + Monst->_mAnimData = Monst->MType->Anims[MA_STAND].Data[Monst->_mdir]; } void MAI_Bat(int i) @@ -3354,87 +3267,64 @@ void MAI_Fat(int i) void MAI_Sneak(int i) { - int v1; // edi - MonsterStruct *v2; // esi - int v3; // ebx - int v4; // ebx - int v6; // edi - int v7; // eax - //int v8; // ST04_4 - int v9; // eax - //int v10; // ST04_4 - int v11; // eax - int v12; // edi - signed int v13; // ecx - int v14; // eax - int v15; // [esp+Ch] [ebp-10h] - int arglist; // [esp+10h] [ebp-Ch] - int v17; // [esp+14h] [ebp-8h] - int md; // [esp+18h] [ebp-4h] + MonsterStruct *Monst; + int mx, my, md; + int dist, v; - v1 = i; - arglist = i; if ((DWORD)i >= MAXMONSTERS) { app_fatal("MAI_Sneak: Invalid monster %d", i); } - v2 = &monster[v1]; - if (v2->_mmode == MM_STAND) { - v3 = v2->_my; - if (dLight[v2->_mx][v3] != lightmax) { - v17 = v2->_mx - (unsigned char)v2->_menemyx; - v4 = v3 - (unsigned char)v2->_menemyy; - md = M_GetDir(v1); - v6 = 5 - (unsigned char)v2->_mint; - if (v2->_mVar1 == MM_GOTHIT) { - v2->_mgoalvar1 = 0; - _LOBYTE(v2->_mgoal) = MGOAL_RETREAT; + Monst = monster + i; + if (Monst->_mmode == MM_STAND) { + mx = Monst->_mx; + my = Monst->_my; + if (dLight[mx][my] != lightmax) { + mx -= Monst->_menemyx; + my -= Monst->_menemyy; + + md = M_GetDir(i); + dist = 5 - Monst->_mint; + if (Monst->_mVar1 == MM_GOTHIT) { + Monst->_mgoalvar1 = 0; + Monst->_mgoal = MGOAL_RETREAT; } else { - v7 = abs(v17); - //v5 = v8; - if (v7 >= v6 + 3 || (v9 = abs(v4), v9 >= v6 + 3) || v2->_mgoalvar1 > 8) /* v5 = v10, */ - { - v2->_mgoalvar1 = 0; - _LOBYTE(v2->_mgoal) = MGOAL_NORMAL; + if (abs(mx) >= dist + 3 || abs(my) >= dist + 3 || Monst->_mgoalvar1 > 8) { + Monst->_mgoalvar1 = 0; + Monst->_mgoal = MGOAL_NORMAL; } } - if (_LOBYTE(v2->_mgoal) == MGOAL_RETREAT) { - if (v2->_mFlags & MFLAG_TARGETS_MONSTER) - md = GetDirection(v2->_mx, v2->_my, plr[v2->_menemy]._pownerx, plr[v2->_menemy]._pownery); + if (Monst->_mgoal == MGOAL_RETREAT) { + if (Monst->_mFlags & MFLAG_TARGETS_MONSTER) + md = GetDirection(Monst->_mx, Monst->_my, plr[Monst->_menemy]._pownerx, plr[Monst->_menemy]._pownery); md = opposite[md]; - if (v2->MType->mtype == MT_UNSEEN) { + if (Monst->MType->mtype == MT_UNSEEN) { if (random(112, 2)) - v11 = left[md]; + md = left[md]; else - v11 = right[md]; - md = v11; + md = right[md]; } } - v2->_mdir = md; - v15 = random(112, 100); - if (abs(v17) < v6 && abs(v4) < v6 && v2->_mFlags & MFLAG_HIDDEN) { - M_StartFadein(arglist, md, FALSE); + Monst->_mdir = md; + v = random(112, 100); + if (abs(mx) < dist && abs(my) < dist && Monst->_mFlags & MFLAG_HIDDEN) { + M_StartFadein(i, md, FALSE); } else { - v12 = v6 + 1; - if (abs(v17) < v12 && abs(v4) < v12 || v2->_mFlags & MFLAG_HIDDEN) { - if (_LOBYTE(v2->_mgoal) == MGOAL_RETREAT - || (abs(v17) >= 2 || abs(v4) >= 2) - && ((v13 = v2->_mVar2, v13 > 20) && v15 < 4 * (unsigned char)v2->_mint + 14 - || ((v14 = v2->_mVar1, v14 == MM_WALK) || v14 == MM_WALK2 || v14 == MM_WALK3) - && !v13 - && v15 < 4 * (unsigned char)v2->_mint + 64)) { - ++v2->_mgoalvar1; - M_CallWalk(arglist, md); - } + if ((abs(mx) >= dist + 1 || abs(my) >= dist + 1) && !(Monst->_mFlags & MFLAG_HIDDEN)) { + M_StartFadeout(i, md, TRUE); } else { - M_StartFadeout(arglist, md, TRUE); + if (Monst->_mgoal == MGOAL_RETREAT + || (abs(mx) >= 2 || abs(my) >= 2) && (Monst->_mVar2 > 20 && v < 4 * Monst->_mint + 14 || (Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) && Monst->_mVar2 == 0 && v < 4 * Monst->_mint + 64)) { + Monst->_mgoalvar1++; + M_CallWalk(i, md); + } } } - if (v2->_mmode == MM_STAND) { - if (abs(v17) >= 2 || abs(v4) >= 2 || v15 >= 4 * (unsigned char)v2->_mint + 10) - v2->_mAnimData = v2->MType->Anims[MA_STAND].Data[md]; + if (Monst->_mmode == MM_STAND) { + if (abs(mx) >= 2 || abs(my) >= 2 || v >= 4 * Monst->_mint + 10) + Monst->_mAnimData = Monst->MType->Anims[MA_STAND].Data[md]; else - M_StartAttack(arglist); + M_StartAttack(i); } } } @@ -3606,112 +3496,60 @@ void MAI_Cleaver(int i) void MAI_Round(int i, BOOL special) { - int v2; // esi - MonsterStruct *v3; // esi - int v4; // edx - int v5; // ecx - int v6; // edi - int v7; // ebx - int v9; // eax - //int v10; // ST04_4 - int v12; // eax - //int v13; // ST04_4 - int v15; // edi - int v16; // eax - int v17; // ecx - BOOLEAN v18; // eax - //int v19; // eax - int v21; // eax - int v22; // eax - //int v23; // ST04_4 - signed int v25; // ecx - int v26; // eax - int v27; // [esp+4h] [ebp-18h] - int v28; // [esp+8h] [ebp-14h] - char *v29; // [esp+8h] [ebp-14h] - int v30; // [esp+Ch] [ebp-10h] - int md; // [esp+10h] [ebp-Ch] - int v32; // [esp+14h] [ebp-8h] - int arglist; // [esp+18h] [ebp-4h] + MonsterStruct *Monst; + int fx, fy; + int mx, my, md; + int dist, v; - v2 = i; - v27 = special; - arglist = i; if ((DWORD)i >= MAXMONSTERS) app_fatal("MAI_Round: Invalid monster %d", i); - v3 = &monster[v2]; - if (v3->_mmode == MM_STAND && v3->_msquelch) { - v4 = v3->_my; - v5 = v3->_mx; - v28 = (unsigned char)v3->_menemyy; - v6 = (unsigned char)v3->_menemyx; - v7 = v5 - v6; - v32 = v4 - v28; - md = GetDirection(v5, v4, v3->_lastx, v3->_lasty); - if (v3->_msquelch < 0xFFu) /* check sign */ - MonstCheckDoors(arglist); - v30 = random(114, 100); - if ((abs(v7) >= 2 || abs(v32) >= 2) && v3->_msquelch == -1) { - v29 = &dTransVal[v6][v28]; - if (dTransVal[v3->_mx][v3->_my] == *v29) { - if (_LOBYTE(v3->_mgoal) != MGOAL_MOVE) { - v9 = abs(v7); - //v11 = v10; - if (v9 < 4) { - v12 = abs(v32); - //v11 = v13; - if (v12 < 4) - goto LABEL_26; - } - if (random(115, 4)) - goto LABEL_26; - if (_LOBYTE(v3->_mgoal) != MGOAL_MOVE) { - v3->_mgoalvar1 = 0; - v3->_mgoalvar2 = random(116, 2); - } + Monst = monster + i; + if (Monst->_mmode == MM_STAND && Monst->_msquelch) { + fy = Monst->_menemyy; + fx = Monst->_menemyx; + mx = Monst->_mx - fx; + my = Monst->_my - fy; + md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty); + if ((BYTE)Monst->_msquelch < 255) + MonstCheckDoors(i); + v = random(114, 100); + if ((abs(mx) >= 2 || abs(my) >= 2) && Monst->_msquelch == -1 && dTransVal[Monst->_mx][Monst->_my] == dTransVal[fx][fy]) { + if (Monst->_mgoal == MGOAL_MOVE || (abs(mx) >= 4 || abs(my) >= 4) && random(115, 4) == 0) { + if (Monst->_mgoal != MGOAL_MOVE) { + Monst->_mgoalvar1 = 0; + Monst->_mgoalvar2 = random(116, 2); } - _LOBYTE(v3->_mgoal) = MGOAL_MOVE; - v15 = abs(v32); - if (abs(v7) <= v15) - v16 = abs(v32); + Monst->_mgoal = MGOAL_MOVE; + if (abs(mx) > abs(my)) + dist = abs(mx); else - v16 = abs(v7); - v17 = v3->_mgoalvar1; - v3->_mgoalvar1 = v17 + 1; - if (v17 < 2 * v16 || (v18 = DirOK(arglist, md), !v18)) { - if (dTransVal[v3->_mx][v3->_my] == *v29) { - //_LOBYTE(v19) = M_RoundWalk(arglist, md, &v3->_mgoalvar2); - if (!M_RoundWalk(arglist, md, &v3->_mgoalvar2)) { - v21 = random(125, 10); - M_StartDelay(arglist, v21 + 10); - } - goto LABEL_26; - } + dist = abs(my); + if (Monst->_mgoalvar1++ >= 2 * dist && DirOK(i, md) || dTransVal[Monst->_mx][Monst->_my] != dTransVal[fx][fy]) { + Monst->_mgoal = MGOAL_NORMAL; + } else if (!M_RoundWalk(i, md, &Monst->_mgoalvar2)) { + M_StartDelay(i, random(125, 10) + 10); } } - } - _LOBYTE(v3->_mgoal) = MGOAL_NORMAL; - LABEL_26: - if (_LOBYTE(v3->_mgoal) == MGOAL_NORMAL) { - if (abs(v7) >= 2 || (v22 = abs(v32), v22 >= 2)) /* v24 = v23, */ - { - v25 = v3->_mVar2; - if (v25 > 20 && v30 < 2 * (unsigned char)v3->_mint + 28 - || ((v26 = v3->_mVar1, v26 == MM_WALK) || v26 == MM_WALK2 || v26 == MM_WALK3) - && !v25 - && v30 < 2 * (unsigned char)v3->_mint + 78) { - M_CallWalk(arglist, md); + } else + Monst->_mgoal = MGOAL_NORMAL; + if (Monst->_mgoal == MGOAL_NORMAL) { + if (abs(mx) >= 2 || abs(my) >= 2) { + if (Monst->_mVar2 > 20 && v < 2 * Monst->_mint + 28 + || (Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3) + && Monst->_mVar2 == 0 + && v < 2 * Monst->_mint + 78) { + M_CallWalk(i, md); } - } else if (v30 < 2 * (unsigned char)v3->_mint + 23) { - v3->_mdir = md; - if (v27 && v3->_mhitpoints_mmaxhp>> 1 && random(117, 2)) - M_StartSpAttack(arglist); + } else if (v < 2 * Monst->_mint + 23) { + Monst->_mdir = md; + if (special && Monst->_mhitpoints < (Monst->_mmaxhp >> 1) && random(117, 2) != 0) + M_StartSpAttack(i); else - M_StartAttack(arglist); + M_StartAttack(i); } } - if (v3->_mmode == MM_STAND) - v3->_mAnimData = v3->MType->Anims[MA_STAND].Data[md]; + if (Monst->_mmode == MM_STAND) + Monst->_mAnimData = Monst->MType->Anims[MA_STAND].Data[md]; } } @@ -3782,138 +3620,91 @@ void MAI_AcidUniq(int i) void MAI_Scav(int i) { - int v1; // edi - int v2; // esi - unsigned char *v3; // eax - int v4; // ecx - int v5; // ecx - signed int v6; // ebx - signed int v7; // edi - int v8; // edx - int v9; // eax - BOOLEAN v10; // eax - int v11; // ebx - int v12; // edi - signed int v13; // edi - int v14; // edx - int v15; // eax - BOOLEAN v16; // eax - int v17; // eax - int v18; // eax - int arglist; // [esp+Ch] [ebp-8h] - BOOL v20; // [esp+10h] [ebp-4h] + BOOL done; + int x, y; + int _mx, _my; + MonsterStruct *Monst; + int _goalvar1; - v1 = i; - arglist = i; if ((DWORD)i >= MAXMONSTERS) app_fatal("MAI_Scav: Invalid monster %d", i); - v2 = v1; - v20 = 0; - if (monster[v1]._mmode == MM_STAND) { - if (monster[v2]._mhitpoints> 1) { - if (_LOBYTE(monster[v2]._mgoal) == MGOAL_HEALING) - goto LABEL_10; - if (monster[v2].leaderflag) { - v3 = &monster[(unsigned char)monster[v2].leader].packsize; - --*v3; - monster[v2].leaderflag = 0; + Monst = monster + i; + _mx = Monst->_mx; + _my = Monst->_my; + done = FALSE; + if (monster[i]._mmode != MM_STAND) + return; + if (Monst->_mhitpoints < (Monst->_mmaxhp >> 1) && Monst->_mgoal != MGOAL_HEALING) { + if (Monst->leaderflag) { + monster[Monst->leader].packsize--; + Monst->leaderflag = 0; + } + Monst->_mgoal = MGOAL_HEALING; + Monst->_mgoalvar3 = 10; + } + if (Monst->_mgoal == MGOAL_HEALING && Monst->_mgoalvar3 != 0) { + Monst->_mgoalvar3--; + if (dDead[Monst->_mx][Monst->_my]) { + M_StartEat(i); + if (!(Monst->_mFlags & MFLAG_NOHEAL)) + Monst->_mhitpoints += 64; + if (Monst->_mhitpoints >= (Monst->_mmaxhp >> 1) + (Monst->_mmaxhp >> 2)) { + Monst->_mgoal = MGOAL_NORMAL; + Monst->_mgoalvar1 = 0; + Monst->_mgoalvar2 = 0; } - _LOBYTE(monster[v2]._mgoal) = MGOAL_HEALING; - monster[v2]._mgoalvar3 = 10; - } - if (_LOBYTE(monster[v2]._mgoal) != MGOAL_HEALING) { - LABEL_52: - if (monster[v2]._mmode == MM_STAND) - MAI_SkelSd(arglist); - return; - } - LABEL_10: - v4 = monster[v2]._mgoalvar3; - if (v4) { - monster[v2]._mgoalvar3 = v4 - 1; - v5 = monster[v2]._my; - if (dDead[monster[v2]._mx][v5]) { - M_StartEat(v1); - if (!(monster[v2]._mFlags & MFLAG_NOHEAL)) - monster[v2]._mhitpoints += 64; - if (monster[v2]._mhitpoints >= (monster[v2]._mmaxhp >> 1) + (monster[v2]._mmaxhp >> 2)) { - _LOBYTE(monster[v2]._mgoal) = MGOAL_NORMAL; - monster[v2]._mgoalvar1 = 0; - monster[v2]._mgoalvar2 = 0; - } - } else { - if (!monster[v2]._mgoalvar1) { - v6 = arglist; - if (random(120, 2)) { - v7 = -4; - do { - if (v20) - break; - v6 = -4; - do { - if (v20) - break; - if (v7 >= 0 && v7 < MAXDUNY && v6 >= 0 && v6 < MAXDUNX) { - v8 = monster[v2]._mx; - v9 = monster[v2]._my; - v20 = dDead[v8 + v6][v9 + v7] - && (v10 = LineClearF( - CheckNoSolid, - v8, - v9, - v8 + v6, - v9 + v7), - v10); - } - ++v6; - } while (v6 <= 4); - ++v7; - } while (v7 <= 4); - v11 = v6 - 1; - v12 = v7 - 1; - } else { - v13 = 4; - do { - if (v20) - break; - v6 = 4; - do { - if (v20) - break; - if (v13 >= 0 && v13 < MAXDUNY && v6 >= 0 && v6 < MAXDUNX) { - v14 = monster[v2]._mx; - v15 = monster[v2]._my; - v20 = dDead[v14 + v6][v15 + v13] - && (v16 = LineClearF( - CheckNoSolid, - v14, - v15, - v14 + v6, - v15 + v13), - v16); - } - --v6; - } while (v6 >= -4); - --v13; - } while (v13 >= -4); - v11 = v6 + 1; - v12 = v13 + 1; + } else { + if (Monst->_mgoalvar1 == 0) { + if (random(120, 2) != 0) { + for (y = -4; y <= 4 && !done; y++) { + for (x = -4; x <= 4 && !done; x++) { + // BUGFIX: incorrect check of offset against limits of the dungeon + if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX) + continue; + done = dDead[Monst->_mx + x][Monst->_my + y] != 0 + && LineClearF( + CheckNoSolid, + Monst->_mx, + Monst->_my, + Monst->_mx + x, + Monst->_my + y); + } } - if (v20) { - monster[v2]._mgoalvar1 = monster[v2]._mx + v11 + 1; - monster[v2]._mgoalvar2 = monster[v2]._my + v12 + 1; + x--; + y--; + } else { + for (y = 4; y >= -4 && !done; y--) { + for (x = 4; x >= -4 && !done; x--) { + // BUGFIX: incorrect check of offset against limits of the dungeon + if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX) + continue; + done = dDead[Monst->_mx + x][Monst->_my + y] != 0 + && LineClearF( + CheckNoSolid, + Monst->_mx, + Monst->_my, + Monst->_mx + x, + Monst->_my + y); + } } + x++; + y++; } - v17 = monster[v2]._mgoalvar1; - if (v17) { - v18 = GetDirection(monster[v2]._mx, monster[v2]._my, v17 - 1, monster[v2]._mgoalvar2 - 1); - monster[v2]._mdir = v18; - M_CallWalk(arglist, v18); + if (done) { + Monst->_mgoalvar1 = x + Monst->_mx + 1; + Monst->_mgoalvar2 = y + Monst->_my + 1; } } + if (Monst->_mgoalvar1) { + x = Monst->_mgoalvar1 - 1; + y = Monst->_mgoalvar2 - 1; + Monst->_mdir = GetDirection(Monst->_mx, Monst->_my, x, y); + M_CallWalk(i, Monst->_mdir); + } } - goto LABEL_52; } + if (Monst->_mmode == MM_STAND) + MAI_SkelSd(i); } void MAI_Garg(int i) diff --git a/Source/multi.cpp b/Source/multi.cpp index cccf06098..f0e6ab6d2 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -17,7 +17,7 @@ BOOLEAN sgbPlayerLeftGameTbl[MAX_PLRS]; int sgbSentThisCycle; // idb BOOL gbShouldValidatePackage; BYTE gbActivePlayers; // weak -BOOLEAN gbGameDestroyed; // weak +BOOLEAN gbGameDestroyed; BOOLEAN sgbSendDeltaTbl[MAX_PLRS]; _gamedata sgGameInitInfo; char byte_678640; // weak @@ -611,35 +611,29 @@ void NetClose() nthread_cleanup(); dthread_cleanup(); tmsg_cleanup(); - multi_event_handler(0); + multi_event_handler(FALSE); SNetLeaveGame(3); msgcmd_cmd_cleanup(); if (gbMaxPlayers > 1) Sleep(2000); } -char multi_event_handler(int a1) -{ - int v1; // edi - void *(__stdcall * v2)(int, void(__stdcall *)(_SNETEVENT *)); // ebx - unsigned int v3; // esi - int v4; // eax - char *v5; // eax - - v1 = a1; - v2 = SNetRegisterEventHandler; - if (!a1) - v2 = SNetUnregisterEventHandler; - v3 = 0; - do { - v4 = (int)v2(event_types[v3], multi_handle_events); - if (!v4 && v1) { - v5 = TraceLastError(); - app_fatal("SNetRegisterEventHandler:\n%s", v5); +void multi_event_handler(BOOL add) +{ + DWORD i; + BOOL(STORMAPI * fn) + (int, SEVTHANDLER); + + if (add) + fn = SNetRegisterEventHandler; + else + fn = SNetUnregisterEventHandler; + + for (i = 0; i < 3; i++) { + if (!fn(event_types[i], multi_handle_events) && add) { + app_fatal("SNetRegisterEventHandler:\n%s", TraceLastError()); } - ++v3; - } while (v3 < 3); - return v4; + } } void __stdcall multi_handle_events(_SNETEVENT *pEvt) @@ -776,11 +770,6 @@ BOOL NetInit(BOOL bSinglePlayer, BOOL *pfExitProgram) return TRUE; } -// 6761B8: using guessed type char gbSomebodyWonGameKludge; -// 67862D: using guessed type char gbGameDestroyed; -// 678640: using guessed type char byte_678640; -// 6796E4: using guessed type char gbDeltaSender; -// 6796E8: using guessed type int sgbNetInited; void buffer_init(TBuffer *pBuf) { @@ -879,7 +868,7 @@ BOOL multi_init_multi(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info, plr[0].pBattleNet = 1; } - multi_event_handler(1); + multi_event_handler(TRUE); if (UiSelectGame(1, client_info, user_info, ui_info, &fileinfo, &playerId)) break; diff --git a/Source/multi.h b/Source/multi.h index 6e9e103e3..26330aa5f 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -43,7 +43,7 @@ void multi_handle_all_packets(int players, TPkt *packet, int a3); void multi_process_tmsgs(); void multi_send_zero_packet(int pnum, char a2, void *pbSrc, int dwLen); void NetClose(); -char multi_event_handler(int a1); +void multi_event_handler(BOOL add); void __stdcall multi_handle_events(_SNETEVENT *pEvt); BOOL NetInit(BOOL bSinglePlayer, BOOL *pfExitProgram); void buffer_init(TBuffer *pBuf); diff --git a/Source/nthread.cpp b/Source/nthread.cpp index b1947e311..ab1a3f4e6 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -27,18 +27,19 @@ static HANDLE sghThread = INVALID_HANDLE_VALUE; void nthread_terminate_game(const char *pszFcn) { - DWORD sErr; // eax + DWORD sErr; sErr = SErrGetLastError(); - if (sErr != STORM_ERROR_INVALID_PLAYER) { - if (sErr == STORM_ERROR_GAME_TERMINATED || sErr == STORM_ERROR_NOT_IN_GAME) { - gbGameDestroyed = 1; - } else { - app_fatal("%s:\n%s", pszFcn, TraceLastError()); - } + if (sErr == STORM_ERROR_INVALID_PLAYER) { + return; + } else if (sErr == STORM_ERROR_GAME_TERMINATED) { + gbGameDestroyed = TRUE; + } else if (sErr == STORM_ERROR_NOT_IN_GAME) { + gbGameDestroyed = TRUE; + } else { + app_fatal("%s:\n%s", pszFcn, TraceLastError()); } } -// 67862D: using guessed type char gbGameDestroyed; int nthread_send_and_recv_turn(int cur_turn, int turn_delta) { @@ -120,7 +121,6 @@ void nthread_set_turn_upper_bit() { turn_upper_bit = 0x80000000; } -// 679754: using guessed type int turn_upper_bit; void nthread_start(BOOL set_turn_upper_bit) { @@ -198,8 +198,8 @@ void nthread_start(BOOL set_turn_upper_bit) unsigned int __stdcall nthread_handler(void *a1) { - signed int delta; // esi - int received; // [esp+Ch] [ebp-4h] + int delta; + int received; if (nthread_should_run) { while (1) { @@ -227,8 +227,6 @@ unsigned int __stdcall nthread_handler(void *a1) } return 0; } -// 679734: using guessed type char nthread_should_run; -// 679764: using guessed type int last_tick; void nthread_cleanup() { @@ -248,11 +246,6 @@ void nthread_cleanup() sghThread = (HANDLE)-1; } } -// 679734: using guessed type char nthread_should_run; -// 679738: using guessed type int gdwTurnsInTransit; -// 67975A: using guessed type char sgbThreadIsRunning; -// 67975C: using guessed type int gdwLargestMsgSize; -// 679760: using guessed type int gdwNormalMsgSize; void nthread_ignore_mutex(BOOL bStart) { @@ -266,12 +259,11 @@ void nthread_ignore_mutex(BOOL bStart) sgbThreadIsRunning = bStart; } } -// 67975A: using guessed type char sgbThreadIsRunning; BOOL nthread_has_500ms_passed(BOOL unused) { - DWORD currentTickCount; // eax - int ticksElapsed; // ecx + DWORD currentTickCount; + int ticksElapsed; currentTickCount = GetTickCount(); ticksElapsed = currentTickCount - last_tick; @@ -281,7 +273,5 @@ BOOL nthread_has_500ms_passed(BOOL unused) } return ticksElapsed >= 0; } -// 679660: using guessed type char gbMaxPlayers; -// 679764: using guessed type int last_tick; DEVILUTION_END_NAMESPACE diff --git a/Source/objects.cpp b/Source/objects.cpp index 0720c5297..4ccf0dac8 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1269,8 +1269,8 @@ void AddWeaponRack(int i) void AddTorturedBody(int i) { object[i]._oRndSeed = GetRndSeed(); - object[i]._oPreFlag = TRUE; object[i]._oAnimFrame = random(0, 4) + 1; + object[i]._oPreFlag = TRUE; } void GetRndObjLoc(int randarea, int *xx, int *yy) @@ -1512,12 +1512,17 @@ void Obj_Circle(int i) object[i]._oAnimFrame = 2; if (object[i]._otype == OBJ_MCIRCLE2) object[i]._oAnimFrame = 4; - if (ox == 45 && oy == 47) { - object[i]._oVar6 = 2; - return; - } else if (object[i]._ox == 26 && object[i]._oy == 46) { + if (ox == 45) { + if (oy == 47) { + object[i]._oVar6 = 2; + return; + } + } + else { + if (object[i]._ox == 26 && object[i]._oy == 46) { object[i]._oVar6 = 1; return; + } } object[i]._oVar6 = 0; if (ox == 35 && object[i]._oy == 36 && object[i]._oVar5 == 3) { @@ -1574,9 +1579,9 @@ void ActivateTrapLine(int ttype, int tid) { int i, oi; - for (i = ttype; i < nobjects; i++) { + for (i = 0; i < nobjects; i++) { oi = objectactive[i]; - if (object[oi]._otype == i && object[oi]._oVar1 == tid) { + if (object[oi]._otype == ttype && object[oi]._oVar1 == tid) { object[oi]._oVar4 = 1; object[oi]._oAnimFlag = 1; object[oi]._oAnimDelay = 1; @@ -2382,7 +2387,7 @@ void ObjChangeMapResync(int x1, int y1, int x2, int y2) } } -void OperateL1Door(int pnum, int i, unsigned char sendflag) +void OperateL1Door(int pnum, int i, BOOL sendflag) { int dpx, dpy; @@ -2742,7 +2747,7 @@ void OperateSarc(int pnum, int i, BOOL sendmsg) } } -void OperateL2Door(int pnum, int i, unsigned char sendflag) +void OperateL2Door(int pnum, int i, BOOL sendflag) { int dpx, dpy; @@ -2754,7 +2759,7 @@ void OperateL2Door(int pnum, int i, unsigned char sendflag) OperateL2RDoor(pnum, i, sendflag); } -void OperateL3Door(int pnum, int i, unsigned char sendflag) +void OperateL3Door(int pnum, int i, BOOL sendflag) { int dpx, dpy; @@ -3764,37 +3769,37 @@ void OperateObject(int pnum, int i, BOOL TeleFlag) case OBJ_L1RDOOR: if (TeleFlag) { if (object[i]._otype == OBJ_L1LDOOR) - OperateL1LDoor(pnum, i, 1); + OperateL1LDoor(pnum, i, TRUE); if (object[i]._otype == OBJ_L1RDOOR) - OperateL1RDoor(pnum, i, 1); + OperateL1RDoor(pnum, i, TRUE); break; } if (pnum == myplr) - OperateL1Door(pnum, i, 1); + OperateL1Door(pnum, i, TRUE); break; case OBJ_L2LDOOR: case OBJ_L2RDOOR: if (TeleFlag) { if (object[i]._otype == OBJ_L2LDOOR) - OperateL2LDoor(pnum, i, 1); + OperateL2LDoor(pnum, i, TRUE); if (object[i]._otype == OBJ_L2RDOOR) - OperateL2RDoor(pnum, i, 1); + OperateL2RDoor(pnum, i, TRUE); break; } if (pnum == myplr) - OperateL2Door(pnum, i, 1); + OperateL2Door(pnum, i, TRUE); break; case OBJ_L3LDOOR: case OBJ_L3RDOOR: if (TeleFlag) { if (object[i]._otype == OBJ_L3LDOOR) - OperateL3LDoor(pnum, i, 1); + OperateL3LDoor(pnum, i, TRUE); if (object[i]._otype == OBJ_L3RDOOR) - OperateL3RDoor(pnum, i, 1); + OperateL3RDoor(pnum, i, TRUE); break; } if (pnum == myplr) - OperateL3Door(pnum, i, 1); + OperateL3Door(pnum, i, TRUE); break; case OBJ_LEVER: case OBJ_SWITCHSKL: diff --git a/Source/objects.h b/Source/objects.h index 0c8efcab6..2864a5a17 100644 --- a/Source/objects.h +++ b/Source/objects.h @@ -105,7 +105,7 @@ void OperateL3LDoor(int pnum, int oi, BOOL sendflag); void MonstCheckDoors(int m); void ObjChangeMap(int x1, int y1, int x2, int y2); void ObjChangeMapResync(int x1, int y1, int x2, int y2); -void OperateL1Door(int pnum, int i, unsigned char sendflag); +void OperateL1Door(int pnum, int i, BOOL sendflag); void OperateLever(int pnum, int i); void OperateBook(int pnum, int i); void OperateBookLever(int pnum, int i); @@ -116,8 +116,8 @@ void OperateInnSignChest(int pnum, int i); void OperateSlainHero(int pnum, int i, BOOL sendmsg); void OperateTrapLvr(int i); void OperateSarc(int pnum, int i, BOOL sendmsg); -void OperateL2Door(int pnum, int i, unsigned char sendflag); -void OperateL3Door(int pnum, int i, unsigned char sendflag); +void OperateL2Door(int pnum, int i, BOOL sendflag); +void OperateL3Door(int pnum, int i, BOOL sendflag); void OperatePedistal(int pnum, int i); void TryDisarm(int pnum, int i); int ItemMiscIdIdx(int imiscid); diff --git a/Source/player.cpp b/Source/player.cpp index 0b03aa443..5373e3a8d 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -2936,7 +2936,7 @@ BOOL PM_DoDeath(int pnum) if (plr[pnum]._pVar8 >= 2 * plr[pnum]._pDFrames) { if (deathdelay > 1 && pnum == myplr) { deathdelay--; - if (deathdelay) { + if (deathdelay == 1) { deathflag = TRUE; if (gbMaxPlayers == 1) { gamemenu_previous(); diff --git a/Source/quests.cpp b/Source/quests.cpp index 25f8e57e6..f97ac7172 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -302,10 +302,10 @@ void CheckQuestKill(int m, BOOL sendmsg) for (j = 0; j < 112; j++) { for (i = 0; i < 112; i++) { if (dPiece[i][j] == 370) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = 1026; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = 1026; + numtrigs++; } } } @@ -612,7 +612,7 @@ void ResyncQuests() else LoadPalette("Levels\\L3Data\\L3pfoul.pal"); - for (i = 0; i < 32; i++) + for (i = 0; i <= 32; i++) palette_update_quest_palette(i); } diff --git a/Source/stores.cpp b/Source/stores.cpp index 789ed6693..256dc3c88 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -1820,19 +1820,19 @@ void S_SmithEnter() gossipstart = QUEST_GRISWOLD2; gossipend = QUEST_GRISWOLD13; StartStore(STORE_GOSSIP); - return; + break; case 12: StartStore(STORE_SBUY); - return; + break; case 14: StartStore(STORE_SPBUY); - return; + break; case 16: StartStore(STORE_SSELL); - return; + break; case 18: StartStore(STORE_SREPAIR); - return; + break; case 20: stextflag = STORE_NONE; break; @@ -2538,20 +2538,20 @@ void S_HealerEnter() gossipstart = QUEST_PEPIN2; gossipend = QUEST_PEPIN11; StartStore(STORE_GOSSIP); - return; + break; case 14: if (plr[myplr]._pHitPoints != plr[myplr]._pMaxHP) PlaySFX(IS_CAST8); drawhpflag = TRUE; plr[myplr]._pHitPoints = plr[myplr]._pMaxHP; plr[myplr]._pHPBase = plr[myplr]._pMaxHPBase; - return; + break; case 16: StartStore(STORE_HBUY); - return; + break; case 18: stextflag = STORE_NONE; - return; + break; } } diff --git a/Source/themes.cpp b/Source/themes.cpp index 2db999226..380eda59e 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -351,7 +351,7 @@ BOOL CheckThemeRoom(int tv) { int i, j, tarea; - for (i = 0; i < trigflag_4; i++) { + for (i = 0; i < numtrigs; i++) { if (dTransVal[trigs[i]._tx][trigs[i]._ty] == tv) return FALSE; } diff --git a/Source/trigs.cpp b/Source/trigs.cpp index 63b6c0c2d..1cd52a1d1 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -2,11 +2,9 @@ DEVILUTION_BEGIN_NAMESPACE -int trigflag_0; -int trigflag_1; -int trigflag_2; -int trigflag_3; -int trigflag_4; +BOOL townwarps[3]; +BOOL trigflag; +int numtrigs; TriggerStruct trigs[MAXTRIGGERS]; int TWarpFrom; // weak @@ -91,25 +89,25 @@ int L4PentaList[33] = { void InitNoTriggers() { - trigflag_4 = 0; - trigflag_3 = 0; + numtrigs = 0; + trigflag = 0; } void InitTownTriggers() { - char v0; // bl - int v1; // eax - int v2; // eax + int i; trigs[0]._tx = 25; trigs[0]._ty = 29; trigs[0]._tmsg = WM_DIABNEXTLVL; - trigflag_4 = 1; - if (gbMaxPlayers == 4) { + + numtrigs = 1; + + if(gbMaxPlayers == MAX_PLRS) { + for(i = 0; i < sizeof(townwarps) / sizeof(townwarps[0]); i++) { + townwarps[i] = TRUE; + } trigs[1]._tx = 49; - trigflag_0 = 1; - trigflag_1 = 1; - trigflag_2 = 1; trigs[1]._ty = 21; trigs[1]._tmsg = WM_DIABTOWNWARP; trigs[1]._tlvl = 5; @@ -121,38 +119,38 @@ void InitTownTriggers() trigs[3]._ty = 80; trigs[3]._tmsg = WM_DIABTOWNWARP; trigs[3]._tlvl = 13; - trigflag_4 = 4; + numtrigs = 4; } else { - trigflag_0 = 0; - trigflag_1 = 0; - trigflag_2 = 0; - v0 = plr[myplr].pTownWarps; - if (v0 & 1) { + for(i = 0; i < 3; i++) { + townwarps[i] = FALSE; + } + if(plr[myplr].pTownWarps & 1) { trigs[1]._tx = 49; trigs[1]._ty = 21; trigs[1]._tmsg = WM_DIABTOWNWARP; trigs[1]._tlvl = 5; - trigflag_4 = 2; - trigflag_0 = 1; - } - if (v0 & 2) { - trigflag_1 = 1; - v1 = trigflag_4++; - trigs[v1]._tx = 17; - trigs[v1]._ty = 69; - trigs[v1]._tmsg = WM_DIABTOWNWARP; - trigs[v1]._tlvl = 9; - } - if (v0 & 4) { - trigflag_2 = 1; - v2 = trigflag_4++; - trigs[v2]._tx = 41; - trigs[v2]._ty = 80; - trigs[v2]._tmsg = WM_DIABTOWNWARP; - trigs[v2]._tlvl = 13; + numtrigs = 2; + townwarps[0] = TRUE; + } + if(plr[myplr].pTownWarps & 2) { + townwarps[1] = TRUE; + trigs[numtrigs]._tx = 17; + trigs[numtrigs]._ty = 69; + trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; + trigs[numtrigs]._tlvl = 9; + numtrigs++; + } + if(plr[myplr].pTownWarps & 4) { + townwarps[2] = TRUE; + trigs[numtrigs]._tx = 41; + trigs[numtrigs]._ty = 80; + trigs[numtrigs]._tmsg = WM_DIABTOWNWARP; + trigs[numtrigs]._tlvl = 13; + numtrigs++; } } - trigflag_3 = 0; + + trigflag = FALSE; } // 679660: using guessed type char gbMaxPlayers; @@ -160,120 +158,120 @@ void InitL1Triggers() { int j, i; - trigflag_4 = 0; + numtrigs = 0; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 129) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABPREVLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABPREVLVL; + numtrigs++; } if (dPiece[i][j] == 115) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; } } } - trigflag_3 = 0; + trigflag = 0; } void InitL2Triggers() { int i, j; - trigflag_4 = 0; + numtrigs = 0; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 267 && (i != quests[QTYPE_BONE]._qtx || j != quests[QTYPE_BONE]._qty)) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABPREVLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABPREVLVL; + numtrigs++; } if (dPiece[i][j] == 559) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABTWARPUP; - trigs[trigflag_4]._tlvl = 0; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABTWARPUP; + trigs[numtrigs]._tlvl = 0; + numtrigs++; } if (dPiece[i][j] == 271) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; } } } - trigflag_3 = 0; + trigflag = 0; } void InitL3Triggers() { int i, j; - trigflag_4 = 0; + numtrigs = 0; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 171) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABPREVLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABPREVLVL; + numtrigs++; } if (dPiece[i][j] == 168) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4] ._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs] ._tmsg = WM_DIABNEXTLVL; + numtrigs++; } if (dPiece[i][j] == 549) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABTWARPUP; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABTWARPUP; + numtrigs++; } } } - trigflag_3 = 0; + trigflag = 0; } void InitL4Triggers() { int i, j; - trigflag_4 = 0; + numtrigs = 0; for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 83) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABPREVLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABPREVLVL; + numtrigs++; } if (dPiece[i][j] == 422) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABTWARPUP; - trigs[trigflag_4]._tlvl = 0; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABTWARPUP; + trigs[numtrigs]._tlvl = 0; + numtrigs++; } if (dPiece[i][j] == 120) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; } } } @@ -281,20 +279,20 @@ void InitL4Triggers() for (j = 0; j < MAXDUNY; j++) { for (i = 0; i < MAXDUNX; i++) { if (dPiece[i][j] == 370 && quests[QTYPE_VB]._qactive == 3) { - trigs[trigflag_4]._tx = i; - trigs[trigflag_4]._ty = j; - trigs[trigflag_4]._tmsg = WM_DIABNEXTLVL; - trigflag_4++; + trigs[numtrigs]._tx = i; + trigs[numtrigs]._ty = j; + trigs[numtrigs]._tmsg = WM_DIABNEXTLVL; + numtrigs++; } } } - trigflag_3 = 0; + trigflag = 0; } void InitSKingTriggers() { - trigflag_3 = 0; - trigflag_4 = 1; + trigflag = 0; + numtrigs = 1; trigs[0]._tx = 82; trigs[0]._ty = 42; trigs[0]._tmsg = WM_DIABRTNLVL; @@ -302,8 +300,8 @@ void InitSKingTriggers() void InitSChambTriggers() { - trigflag_3 = 0; - trigflag_4 = 1; + trigflag = 0; + numtrigs = 1; trigs[0]._tx = 70; trigs[0]._ty = 39; trigs[0]._tmsg = WM_DIABRTNLVL; @@ -311,8 +309,8 @@ void InitSChambTriggers() void InitPWaterTriggers() { - trigflag_3 = 0; - trigflag_4 = 1; + trigflag = 0; + numtrigs = 1; trigs[0]._tx = 30; trigs[0]._ty = 83; trigs[0]._tmsg = WM_DIABRTNLVL; @@ -320,8 +318,8 @@ void InitPWaterTriggers() void InitVPTriggers() { - trigflag_3 = 0; - trigflag_4 = 1; + trigflag = 0; + numtrigs = 1; trigs[0]._tx = 35; trigs[0]._ty = 32; trigs[0]._tmsg = WM_DIABRTNLVL; @@ -340,7 +338,7 @@ BOOL ForceTownTrig() } } - if (trigflag_0) { + if (townwarps[0]) { for (j = 0; TownWarp1List[j] != -1; j++) { if (dPiece[cursmx][cursmy] == TownWarp1List[j]) { strcpy(infostr, "Down to catacombs"); @@ -351,7 +349,7 @@ BOOL ForceTownTrig() } } - if (trigflag_1) { + if (townwarps[1]) { for (k = 1199; k <= 1220; k++) { if (dPiece[cursmx][cursmy] == k) { strcpy(infostr, "Down to caves"); @@ -362,7 +360,7 @@ BOOL ForceTownTrig() } } - if (trigflag_2) { + if (townwarps[2]) { for (l = 1240; l <= 1254; l++) { if (dPiece[cursmx][cursmy] == l) { strcpy(infostr, "Down to hell"); @@ -386,7 +384,7 @@ BOOL ForceL1Trig() sprintf(infostr, "Up to level %i", currlevel - 1); else strcpy(infostr, "Up to town"); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABPREVLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -399,7 +397,7 @@ BOOL ForceL1Trig() for (i = 0; L1DownList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L1DownList[i]) { sprintf(infostr, "Down to level %i", currlevel + 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -418,7 +416,7 @@ BOOL ForceL2Trig() for (i = 0; L2UpList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L2UpList[i]) { - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABPREVLVL) { dx = abs(trigs[j]._tx - cursmx); dy = abs(trigs[j]._ty - cursmy); @@ -436,7 +434,7 @@ BOOL ForceL2Trig() for (i = 0; L2DownList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L2DownList[i]) { sprintf(infostr, "Down to level %i", currlevel + 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -449,7 +447,7 @@ BOOL ForceL2Trig() if (currlevel == 5) { for (i = 0; L2TWarpUpList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L2TWarpUpList[i]) { - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABTWARPUP) { dx = abs(trigs[j]._tx - cursmx); dy = abs(trigs[j]._ty - cursmy); @@ -475,7 +473,7 @@ BOOL ForceL3Trig() for (i = 0; L3UpList[i] != -1; ++i) { if (dPiece[cursmx][cursmy] == L3UpList[i]) { sprintf(infostr, "Up to level %i", currlevel - 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABPREVLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -488,7 +486,7 @@ BOOL ForceL3Trig() for (i = 0; L3DownList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L3DownList[i] || dPiece[cursmx + 1][cursmy] == L3DownList[i] || dPiece[cursmx + 2][cursmy] == L3DownList[i]) { sprintf(infostr, "Down to level %i", currlevel + 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -501,7 +499,7 @@ BOOL ForceL3Trig() if (currlevel == 9) { for (i = 0; L3TWarpUpList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L3TWarpUpList[i]) { - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABTWARPUP) { dx = abs(trigs[j]._tx - cursmx); dy = abs(trigs[j]._ty - cursmy); @@ -527,7 +525,7 @@ BOOL ForceL4Trig() for (i = 0; L4UpList[i] != -1; ++i) { if (dPiece[cursmx][cursmy] == L4UpList[i]) { sprintf(infostr, "Up to level %i", currlevel - 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABPREVLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -540,7 +538,7 @@ BOOL ForceL4Trig() for (i = 0; L4DownList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L4DownList[i]) { sprintf(infostr, "Down to level %i", currlevel + 1); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -553,7 +551,7 @@ BOOL ForceL4Trig() if (currlevel == 13) { for (i = 0; L4TWarpUpList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L4TWarpUpList[i]) { - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABTWARPUP) { dx = abs(trigs[j]._tx - cursmx); dy = abs(trigs[j]._ty - cursmy); @@ -573,7 +571,7 @@ BOOL ForceL4Trig() for (i = 0; L4PentaList[i] != -1; i++) { if (dPiece[cursmx][cursmy] == L4PentaList[i]) { strcpy(infostr, "Down to Diablo"); - for (j = 0; j < trigflag_4; j++) { + for (j = 0; j < numtrigs; j++) { if (trigs[j]._tmsg == WM_DIABNEXTLVL) { cursmx = trigs[j]._tx; cursmy = trigs[j]._ty; @@ -591,7 +589,7 @@ void Freeupstairs() { int i, yy, xx, tx, ty; - for (i = 0; i < trigflag_4; i++) { + for (i = 0; i < numtrigs; i++) { tx = trigs[i]._tx; ty = trigs[i]._ty; @@ -656,63 +654,49 @@ BOOL ForcePWaterTrig() void CheckTrigForce() { - int v0; // eax - int v1; // eax - - trigflag_3 = 0; - if (MouseY <= 351) { - if (setlevel) { - switch (setlvlnum) { - case SL_SKELKING: - v1 = ForceSKingTrig(); - break; - case SL_BONECHAMB: - v1 = ForceSChambTrig(); - break; - case SL_POISONWATER: - v1 = ForcePWaterTrig(); - break; - default: - return; - } - goto LABEL_23; - } - if (leveltype) { - switch (leveltype) { - case DTYPE_CATHEDRAL: - v0 = ForceL1Trig(); - break; - case DTYPE_CATACOMBS: - v0 = ForceL2Trig(); - break; - case DTYPE_CAVES: - v0 = ForceL3Trig(); - break; - case DTYPE_HELL: - v0 = ForceL4Trig(); - break; - default: - LABEL_14: - if (leveltype == DTYPE_TOWN) - goto LABEL_24; - if (trigflag_3) { - LABEL_25: - ClearPanel(); - return; - } - v1 = ForceQuests(); - LABEL_23: - trigflag_3 = v1; - LABEL_24: - if (!trigflag_3) - return; - goto LABEL_25; - } - } else { - v0 = ForceTownTrig(); + trigflag = FALSE; + + if(MouseY > 352 - 1) { + return; + } + + if(!setlevel) { + switch(leveltype) { + case DTYPE_TOWN: + trigflag = ForceTownTrig(); + break; + case DTYPE_CATHEDRAL: + trigflag = ForceL1Trig(); + break; + case DTYPE_CATACOMBS: + trigflag = ForceL2Trig(); + break; + case DTYPE_CAVES: + trigflag = ForceL3Trig(); + break; + case DTYPE_HELL: + trigflag = ForceL4Trig(); + break; + } + if(leveltype != DTYPE_TOWN && !trigflag) { + trigflag = ForceQuests(); } - trigflag_3 = v0; - goto LABEL_14; + } else { + switch(setlvlnum) { + case SL_SKELKING: + trigflag = ForceSKingTrig(); + break; + case SL_BONECHAMB: + trigflag = ForceSChambTrig(); + break; + case SL_POISONWATER: + trigflag = ForcePWaterTrig(); + break; + } + } + + if(trigflag) { + ClearPanel(); } } // 5CF31D: using guessed type char setlevel; @@ -726,7 +710,7 @@ void CheckTriggers() if (plr[myplr]._pmode) return; - for (i = 0; i < trigflag_4; i++) { + for (i = 0; i < numtrigs; i++) { if (plr[myplr].WorldX != trigs[i]._tx || plr[myplr].WorldY != trigs[i]._ty) { continue; } diff --git a/Source/trigs.h b/Source/trigs.h index 5012da61a..7fe07eac5 100644 --- a/Source/trigs.h +++ b/Source/trigs.h @@ -2,13 +2,9 @@ #ifndef __TRIGS_H__ #define __TRIGS_H__ -// The trigflag variables (0-4) here were split up from the trigflag array. -// Complete diff is part of PR #947 on Github. -extern int trigflag_0; -extern int trigflag_1; -extern int trigflag_2; -extern int trigflag_3; -extern int trigflag_4; +extern BOOL townwarps[3]; +extern BOOL trigflag; +extern int numtrigs; extern TriggerStruct trigs[MAXTRIGGERS]; extern int TWarpFrom; // weak diff --git a/SourceX/dvlnet/abstract_net.h b/SourceX/dvlnet/abstract_net.h index a69725a5b..d8f15153b 100644 --- a/SourceX/dvlnet/abstract_net.h +++ b/SourceX/dvlnet/abstract_net.h @@ -11,7 +11,6 @@ namespace dvl { namespace net { typedef std::vector buffer_t; -typedef void(*snet_event_func)(struct _SNETEVENT*); typedef unsigned long provider_t; class dvlnet_exception : public std::exception {}; @@ -27,10 +26,10 @@ public: DWORD* status) = 0; virtual bool SNetSendTurn(char* data, unsigned int size) = 0; virtual int SNetGetProviderCaps(struct _SNETCAPS* caps) = 0; - virtual void* SNetRegisterEventHandler(event_type evtype, - snet_event_func func) = 0; - virtual void* SNetUnregisterEventHandler(event_type evtype, - snet_event_func func) = 0; + virtual bool SNetRegisterEventHandler(event_type evtype, + SEVTHANDLER func) = 0; + virtual bool SNetUnregisterEventHandler(event_type evtype, + SEVTHANDLER func) = 0; virtual bool SNetLeaveGame(int type) = 0; virtual bool SNetDropPlayer(int playerid, DWORD flags) = 0; virtual bool SNetGetOwnerTurnsWaiting(DWORD *turns) = 0; diff --git a/SourceX/dvlnet/base.cpp b/SourceX/dvlnet/base.cpp index 0860a4628..08dc158b7 100644 --- a/SourceX/dvlnet/base.cpp +++ b/SourceX/dvlnet/base.cpp @@ -195,13 +195,13 @@ int base::SNetGetProviderCaps(struct _SNETCAPS* caps) return 1; } -void* base::SNetUnregisterEventHandler(event_type evtype, snet_event_func func) +bool base::SNetUnregisterEventHandler(event_type evtype, SEVTHANDLER func) { registered_handlers.erase(evtype); - return (void*)func; + return true; } -void* base::SNetRegisterEventHandler(event_type evtype, snet_event_func func) +bool base::SNetRegisterEventHandler(event_type evtype, SEVTHANDLER func) { /* engine registers handler for: @@ -212,7 +212,7 @@ void* base::SNetRegisterEventHandler(event_type evtype, snet_event_func func) (engine uses same function for all three) */ registered_handlers[evtype] = func; - return (void*)func; + return true; } bool base::SNetLeaveGame(int type) diff --git a/SourceX/dvlnet/base.h b/SourceX/dvlnet/base.h index 56be6c3db..d51e21647 100644 --- a/SourceX/dvlnet/base.h +++ b/SourceX/dvlnet/base.h @@ -32,10 +32,10 @@ public: DWORD* status); virtual bool SNetSendTurn(char* data, unsigned int size); virtual int SNetGetProviderCaps(struct _SNETCAPS* caps); - virtual void* SNetRegisterEventHandler(event_type evtype, - snet_event_func func); - virtual void* SNetUnregisterEventHandler(event_type evtype, - snet_event_func func); + virtual bool SNetRegisterEventHandler(event_type evtype, + SEVTHANDLER func); + virtual bool SNetUnregisterEventHandler(event_type evtype, + SEVTHANDLER func); virtual bool SNetLeaveGame(int type); virtual bool SNetDropPlayer(int playerid, DWORD flags); virtual bool SNetGetOwnerTurnsWaiting(DWORD *turns); @@ -46,7 +46,7 @@ public: void setup_gameinfo(buffer_t info); protected: - std::map registered_handlers; + std::map registered_handlers; buffer_t game_init_info; struct message_t { diff --git a/SourceX/dvlnet/loopback.cpp b/SourceX/dvlnet/loopback.cpp index 0cf0c380a..1efb9c99a 100644 --- a/SourceX/dvlnet/loopback.cpp +++ b/SourceX/dvlnet/loopback.cpp @@ -63,20 +63,20 @@ int loopback::SNetGetProviderCaps(struct _SNETCAPS* caps) return 1; } -void* loopback::SNetRegisterEventHandler(event_type evtype, - snet_event_func func) +bool loopback::SNetRegisterEventHandler(event_type evtype, + SEVTHANDLER func) { // not called in real singleplayer mode // not needed in pseudo multiplayer mode (?) - return this; + return true; } -void* loopback::SNetUnregisterEventHandler(event_type evtype, - snet_event_func func) +bool loopback::SNetUnregisterEventHandler(event_type evtype, + SEVTHANDLER func) { // not called in real singleplayer mode // not needed in pseudo multiplayer mode (?) - return this; + return true; } bool loopback::SNetLeaveGame(int type) diff --git a/SourceX/dvlnet/loopback.h b/SourceX/dvlnet/loopback.h index f3a5034c1..e461d07a2 100644 --- a/SourceX/dvlnet/loopback.h +++ b/SourceX/dvlnet/loopback.h @@ -24,10 +24,10 @@ public: DWORD* status); virtual bool SNetSendTurn(char* data, unsigned int size); virtual int SNetGetProviderCaps(struct _SNETCAPS* caps); - virtual void *SNetRegisterEventHandler(event_type evtype, - snet_event_func func); - virtual void *SNetUnregisterEventHandler(event_type evtype, - snet_event_func func); + virtual bool SNetRegisterEventHandler(event_type evtype, + SEVTHANDLER func); + virtual bool SNetUnregisterEventHandler(event_type evtype, + SEVTHANDLER func); virtual bool SNetLeaveGame(int type); virtual bool SNetDropPlayer(int playerid, DWORD flags); virtual bool SNetGetOwnerTurnsWaiting(DWORD *turns); diff --git a/SourceX/storm/storm_net.cpp b/SourceX/storm/storm_net.cpp index fabd846e3..963ddffff 100644 --- a/SourceX/storm/storm_net.cpp +++ b/SourceX/storm/storm_net.cpp @@ -46,12 +46,12 @@ int SNetGetProviderCaps(struct _SNETCAPS *caps) return dvlnet_inst->SNetGetProviderCaps(caps); } -void *SNetUnregisterEventHandler(int evtype, void(*func)(struct _SNETEVENT *)) +BOOL SNetUnregisterEventHandler(int evtype, SEVTHANDLER func) { return dvlnet_inst->SNetUnregisterEventHandler(*(event_type *)&evtype, func); } -void *SNetRegisterEventHandler(int evtype, void(*func)(struct _SNETEVENT *)) +BOOL SNetRegisterEventHandler(int evtype, SEVTHANDLER func) { return dvlnet_inst->SNetRegisterEventHandler(*(event_type *)&evtype, func); } diff --git a/structs.h b/structs.h index fe1cc0dff..633ba36de 100644 --- a/structs.h +++ b/structs.h @@ -1247,8 +1247,6 @@ typedef struct _uiheroinfo { // storm ////////////////////////////////////////////////// -// TPDEF PTR FCN VOID SEVTHANDLER - // TPDEF PTR FCN UCHAR SMSGIDLEPROC // TPDEF PTR FCN VOID SMSGHANDLER