From 504cbf9b88a9b58eb5b45999e29498a9e9de22d8 Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 2 Jul 2006 17:33:49 +0000 Subject: [PATCH] Fix building with Watcom and move the KenBuild test game stuff out of the engine source git-svn-id: https://svn.eduke32.com/eduke32@201 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/Makefile | 21 +- polymer/build/Makefile.deps | 16 +- polymer/build/Makefile.msvc | 15 +- polymer/build/Makefile.watcom | 20 +- .../{src => game}/StartupWinController.game.m | 0 polymer/build/game/bstub.c | 564 ++ polymer/build/game/game.c | 6290 +++++++++++++++++ polymer/build/{include => game}/game.h | 0 polymer/build/{src => game}/jfaud_sound.cpp | 9 +- polymer/build/{include => game}/names.h | 0 polymer/build/game/startgtk.game.c | 545 ++ polymer/build/game/startwin.game.c | 422 ++ polymer/build/{src => game}/startwin.game.h | 0 polymer/build/include/pragmas.h | 402 +- polymer/build/src/bstub.c | 574 -- polymer/build/src/game.c | 6290 ----------------- polymer/build/src/polymost.c | 12 +- polymer/build/src/startgtk.game.c | 545 -- polymer/build/src/startwin.game.c | 422 -- polymer/build/watcomhax/cerrno | 1 + polymer/build/watcomhax/cmath | 2 + polymer/build/watcomhax/cstdarg | 1 + polymer/build/watcomhax/cstdio | 1 + polymer/build/watcomhax/cstdlib | 1 + polymer/build/watcomhax/cstring | 1 + polymer/build/watcomhax/ctime | 1 + polymer/eduke32/Makefile.msvc | 10 +- polymer/eduke32/Makefile.watcom | 26 +- polymer/eduke32/source/jfaud_sounds.cpp | 907 ++- polymer/eduke32/watcomhax/cerrno | 1 + polymer/eduke32/watcomhax/cmath | 2 + polymer/eduke32/watcomhax/cstdarg | 1 + polymer/eduke32/watcomhax/cstdio | 1 + polymer/eduke32/watcomhax/cstdlib | 1 + polymer/eduke32/watcomhax/cstring | 1 + polymer/eduke32/watcomhax/ctime | 1 + 36 files changed, 8554 insertions(+), 8552 deletions(-) rename polymer/build/{src => game}/StartupWinController.game.m (100%) create mode 100755 polymer/build/game/bstub.c create mode 100755 polymer/build/game/game.c rename polymer/build/{include => game}/game.h (100%) mode change 100644 => 100755 rename polymer/build/{src => game}/jfaud_sound.cpp (93%) mode change 100644 => 100755 rename polymer/build/{include => game}/names.h (100%) mode change 100644 => 100755 create mode 100755 polymer/build/game/startgtk.game.c create mode 100755 polymer/build/game/startwin.game.c rename polymer/build/{src => game}/startwin.game.h (100%) delete mode 100644 polymer/build/src/bstub.c delete mode 100644 polymer/build/src/game.c delete mode 100755 polymer/build/src/startgtk.game.c delete mode 100755 polymer/build/src/startwin.game.c create mode 100755 polymer/build/watcomhax/cerrno create mode 100755 polymer/build/watcomhax/cmath create mode 100755 polymer/build/watcomhax/cstdarg create mode 100755 polymer/build/watcomhax/cstdio create mode 100755 polymer/build/watcomhax/cstdlib create mode 100755 polymer/build/watcomhax/cstring create mode 100755 polymer/build/watcomhax/ctime create mode 100755 polymer/eduke32/watcomhax/cerrno create mode 100755 polymer/eduke32/watcomhax/cmath create mode 100755 polymer/eduke32/watcomhax/cstdarg create mode 100755 polymer/eduke32/watcomhax/cstdio create mode 100755 polymer/eduke32/watcomhax/cstdlib create mode 100755 polymer/eduke32/watcomhax/cstring create mode 100755 polymer/eduke32/watcomhax/ctime diff --git a/polymer/build/Makefile b/polymer/build/Makefile index a2dcce32e..861d8a6bc 100644 --- a/polymer/build/Makefile +++ b/polymer/build/Makefile @@ -35,6 +35,7 @@ FMODROOTWIN=c:/sdks/fmodapi374win/api # build locations - OBJ gets overridden to the game-specific objects dir OBJ?=obj.gnu/ SRC=src/ +GAME=game/ RSRC=rsrc/ INC=include/ @@ -60,8 +61,9 @@ AR=ar RANLIB=ranlib OURCFLAGS=$(debug) -W -Wall -Wimplicit -Wno-char-subscripts -Wno-unused \ -funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS \ - -DKSFORBUILD -I$(INC:/=) -I../jfaud/src + -DKSFORBUILD -I$(INC:/=) OURCXXFLAGS=-fno-exceptions -fno-rtti +GAMECFLAGS=-I../jfaud/inc -I$(GAME) LIBS= GAMELIBS=../jfaud/libjfaud.a #../jfaud/mpadec/libmpadec/libmpadec.a ASFLAGS=-s #-g @@ -179,7 +181,7 @@ endif UTILS=kextract$(EXESUFFIX) kgroup$(EXESUFFIX) transpal$(EXESUFFIX) wad2art$(EXESUFFIX) wad2map$(EXESUFFIX) -all: game$(EXESUFFIX) build$(EXESUFFIX) $(OBJ)$(ENGINELIB) $(OBJ)$(EDITORLIB) +all: testgame$(EXESUFFIX) build$(EXESUFFIX) $(OBJ)$(ENGINELIB) $(OBJ)$(EDITORLIB) utils: $(UTILS) enginelib: $(OBJ)$(ENGINELIB) @@ -192,7 +194,7 @@ $(OBJ)$(EDITORLIB): $(EDITOROBJS) $(AR) rc $@ $^ $(RANLIB) $@ -game$(EXESUFFIX): $(GAMEEXEOBJS) +testgame$(EXESUFFIX): $(GAMEEXEOBJS) $(CC) $(CFLAGS) $(OURCFLAGS) -o $@ $^ $(GAMELIBS) $(LIBS) $(STDCPPLIB) build$(EXESUFFIX): $(EDITOREXEOBJS) @@ -231,11 +233,8 @@ $(OBJ)%.$o: $(SRC)%.c $(OBJ)%.$o: $(SRC)%.cpp $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@ 2>&1 -$(OBJ)%.$o: $(SRC)tmp/%.c - $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@ 2>&1 - $(OBJ)%.$o: $(SRC)misc/%.rc - $(RC) -i $< -o $@ --include-dir=$(INC) --include-dir=$(SRC) + $(RC) -i $< -o $@ --include-dir=$(INC) --include-dir=$(SRC) --include-dir=$(GAME) $(OBJ)%.$o: $(SRC)util/%.c $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@ 2>&1 @@ -243,6 +242,12 @@ $(OBJ)%.$o: $(SRC)util/%.c $(OBJ)%.$o: $(RSRC)%.c $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@ 2>&1 +$(OBJ)%.$o: $(GAME)%.c + $(CC) $(CFLAGS) $(OURCFLAGS) $(GAMECFLAGS) -c $< -o $@ 2>&1 + +$(OBJ)%.$o: $(GAME)%.cpp + $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) $(GAMECFLAGS) -c $< -o $@ 2>&1 + $(OBJ)game_banner.$o: $(RSRC)game_banner.c $(OBJ)editor_banner.$o: $(RSRC)editor_banner.c $(RSRC)game_banner.c: $(RSRC)game.bmp @@ -264,7 +269,7 @@ endif veryclean: clean ifeq ($(PLATFORM),DARWIN) else - -rm -f $(ENGINELIB) $(EDITORLIB) game$(EXESUFFIX) build$(EXESUFFIX) $(UTILS) + -rm -f $(ENGINELIB) $(EDITORLIB) testgame$(EXESUFFIX) build$(EXESUFFIX) $(UTILS) endif .PHONY: fixlineends diff --git a/polymer/build/Makefile.deps b/polymer/build/Makefile.deps index 42c008ac9..aa333df09 100644 --- a/polymer/build/Makefile.deps +++ b/polymer/build/Makefile.deps @@ -3,17 +3,14 @@ $(OBJ)a-c.$o: $(SRC)a-c.c $(INC)a.h $(OBJ)a.$o: $(SRC)a.$(asm) $(OBJ)baselayer.$o: $(SRC)baselayer.c $(INC)compat.h $(INC)baselayer.h $(INC)build.h $(INC)osd.h -$(OBJ)bstub.$o: $(SRC)bstub.c $(INC)compat.h $(INC)a.h $(INC)build.h $(INC)pragmas.h $(INC)baselayer.h $(INC)names.h $(INC)osd.h $(INC)cache1d.h $(INC)editor.h $(OBJ)build.$o: $(SRC)build.c $(INC)build.h $(INC)pragmas.h $(INC)compat.h $(INC)baselayer.h $(INC)editor.h $(OBJ)cache1d.$o: $(SRC)cache1d.c $(INC)compat.h $(INC)cache1d.h $(INC)pragmas.h $(INC)baselayer.h $(OBJ)compat.$o: $(SRC)compat.c $(INC)compat.h $(OBJ)config.$o: $(SRC)config.c $(INC)compat.h $(INC)osd.h $(INC)editor.h $(OBJ)crc32.$o: $(SRC)crc32.c $(INC)crc32.h $(OBJ)defs.$o: $(SRC)defs.c $(INC)build.h $(INC)baselayer.h $(INC)scriptfile.h $(INC)compat.h -$(OBJ)engine.$o: $(SRC)engine.c $(SRC)polymost.c $(SRC)polymer.c $(INC)kplib.h $(SRC)hightile.c $(SRC)mdsprite.c $(INC)md4.h $(INC)lzf.h $(INC)lzwnew.h $(INC)compat.h $(INC)build.h $(INC)pragmas.h $(INC)cache1d.h $(INC)a.h $(INC)osd.h $(INC)baselayer.h -$(OBJ)game.$o: $(SRC)game.c $(INC)compat.h $(INC)build.h $(INC)names.h $(INC)pragmas.h $(INC)cache1d.h $(INC)game.h $(INC)osd.h $(INC)baselayer.h +$(OBJ)engine.$o: $(SRC)engine.c $(SRC)polymost.c $(INC)kplib.h $(SRC)hightile.c $(SRC)mdsprite.c $(INC)md4.h $(INC)lzf.h $(INC)lzwnew.h $(INC)compat.h $(INC)build.h $(INC)pragmas.h $(INC)cache1d.h $(INC)a.h $(INC)osd.h $(INC)baselayer.h $(OBJ)glbuild.$o: $(SRC)glbuild.c $(INC)glbuild.h $(INC)baselayer.h -$(OBJ)jfaud_sound.$o: $(SRC)jfaud_sound.cpp $(INC)osd.h $(INC)compat.h $(INC)cache1d.h $(OBJ)kplib.$o: $(SRC)kplib.c $(INC)compat.h $(OBJ)lzf_c.$o: $(SRC)lzf_c.c $(SRC)lzfP.h $(OBJ)lzf_d.$o: $(SRC)lzf_d.c $(SRC)lzfP.h @@ -30,12 +27,17 @@ $(OBJ)winlayer.$o: $(SRC)winlayer.c $(INC)compat.h $(INC)winlayer.h $(INC)basela $(OBJ)gtkbits.$o: $(SRC)gtkbits.c $(INC)baselayer.h $(INC)build.h $(INC)dynamicgtk.h $(OBJ)dynamicgtk.$o: $(SRC)dynamicgtk.c $(INC)dynamicgtk.h -$(OBJ)gameres.$(res): $(SRC)misc/gameres.rc $(SRC)startwin.game.h +# KenBuild test game +$(OBJ)game.$o: $(GAME)game.c $(INC)compat.h $(INC)build.h $(GAME)names.h $(INC)pragmas.h $(INC)cache1d.h $(GAME)game.h $(INC)osd.h $(INC)baselayer.h +$(OBJ)bstub.$o: $(GAME)bstub.c $(INC)compat.h $(INC)a.h $(INC)build.h $(INC)pragmas.h $(INC)baselayer.h $(GAME)names.h $(INC)osd.h $(INC)cache1d.h $(INC)editor.h +$(OBJ)jfaud_sound.$o: $(GAME)jfaud_sound.cpp $(INC)osd.h $(INC)compat.h $(INC)cache1d.h +$(OBJ)startwin.game.$o: $(GAME)startwin.game.c $(INC)build.h $(INC)editor.h $(INC)winlayer.h $(INC)compat.h $(GAME)startwin.game.h +$(OBJ)startgtk.game.$o: $(GAME)startgtk.game.c $(INC)baselayer.h $(INC)build.h $(INC)compat.h + +$(OBJ)gameres.$(res): $(SRC)misc/gameres.rc $(GAME)startwin.game.h $(OBJ)buildres.$(res): $(SRC)misc/buildres.rc $(INC)startwin.editor.h $(OBJ)startwin.editor.$o: $(SRC)startwin.editor.c $(INC)build.h $(INC)editor.h $(INC)winlayer.h $(INC)compat.h $(INC)startwin.editor.h -$(OBJ)startwin.game.$o: $(SRC)startwin.game.c $(INC)build.h $(INC)editor.h $(INC)winlayer.h $(INC)compat.h $(SRC)startwin.game.h $(OBJ)startgtk.editor.$o: $(SRC)startgtk.editor.c $(INC)baselayer.h $(INC)build.h $(INC)editor.h $(INC)compat.h -$(OBJ)startgtk.game.$o: $(SRC)startgtk.game.c $(INC)baselayer.h $(INC)build.h $(INC)compat.h $(OBJ)game_icon.$o: $(RSRC)game_icon.c $(OBJ)build_icon.$o: $(RSRC)build_icon.c diff --git a/polymer/build/Makefile.msvc b/polymer/build/Makefile.msvc index bddf00f1a..00e3c32e5 100644 --- a/polymer/build/Makefile.msvc +++ b/polymer/build/Makefile.msvc @@ -4,6 +4,7 @@ !endif SRC=src\ # +GAME=game\ # !ifndef OBJ OBJ=obj.msc\ # !endif @@ -47,6 +48,7 @@ AS=ml RC=rc LINK=link /opt:nowin98 /opt:ref /nologo CFLAGS=$(CFLAGS) /nologo /MD /J $(flags_cl) $(TARGETOPTS) /I$(INC) /I$(DXROOT)\include /I$(FMODROOT)\inc +GAMECFLAGS=/I$(GAME) LIBS=fmodvc.lib #opengl32.lib ASFLAGS=/nologo /coff EXESUFFIX=.exe @@ -87,7 +89,7 @@ EDITOREXEOBJS=$(OBJ)bstub.$o \ $(OBJ)$(ENGINELIB) RENDERTYPE=WIN -LIBS=$(LIBS) user32.lib gdi32.lib shell32.lib dxguid.lib wsock32.lib +LIBS=$(LIBS) user32.lib gdi32.lib shell32.lib dxguid.lib wsock32.lib comctl32.lib CFLAGS=$(CFLAGS) /DRENDERTYPE$(RENDERTYPE)=1 # RULES @@ -103,11 +105,20 @@ CFLAGS=$(CFLAGS) /DRENDERTYPE$(RENDERTYPE)=1 $(CC) /c $(CFLAGS) /Fo$@ $< {$(SRC)misc}.rc{$(OBJ)}.$(res): - $(RC) /fo$@ /r $< + $(RC) /i$(INC) /i$(GAME) /fo$@ /r $< {$(SRC)}.c{$(OBJ)}.$o: $(CC) /c $(CFLAGS) /Fo$@ $< +{$(SRC)}.cpp{$(OBJ)}.$o: + $(CC) /c $(CFLAGS) /Fo$@ $< + +{$(GAME)}.c{$(OBJ)}.$o: + $(CC) /c $(CFLAGS) $(GAMECFLAGS) /Fo$@ $< + +{$(GAME)}.cpp{$(OBJ)}.$o: + $(CC) /c $(CFLAGS) $(GAMECFLAGS) /Fo$@ $< + # TARGETS UTILS=kextract$(EXESUFFIX) kgroup$(EXESUFFIX) transpal$(EXESUFFIX) wad2map$(EXESUFFIX) wad2map$(EXESUFFIX) diff --git a/polymer/build/Makefile.watcom b/polymer/build/Makefile.watcom index 4ba0b6275..45b3e6aa0 100644 --- a/polymer/build/Makefile.watcom +++ b/polymer/build/Makefile.watcom @@ -5,6 +5,7 @@ !endif SRC=src\ +GAME=game\ !ifndef OBJ OBJ=obj.watcom\ !endif @@ -21,7 +22,6 @@ ENGINELIB=engine.lib EDITORLIB=build.lib DXROOT=c:\sdks\directx\dx7 -FMODROOT=c:\sdks\fmodapi374win\api !ifdef __LOADDLL__ ! loaddll wcc386 wccd386 @@ -37,11 +37,13 @@ FMODROOT=c:\sdks\fmodapi374win\api TARGETOPTS=#-dUSE_A_C #-dNOASM CC=wcc386 +CXX=wpp386 AS=wasm RC=wrc -CFLAGS+= -5r -s -orb -fp5 $(TARGETOPTS) -d2 -dRENDERTYPEWIN=1 & - -i=$(INC) -i=$(DXROOT)\include -i=$(FMODROOT)\inc -LIBS=dxguid.lib wsock32.lib fmodwc.lib #opengl32.lib +CFLAGS+= -zq -5r -s -orb -fp5 $(TARGETOPTS) -d2 -dRENDERTYPEWIN=1 & + -i=watcomhax -i=$(INC) -i=$(SRC) -i=$(DXROOT)\include -i=..\jfaud\inc +GAMECFLAGS=-i=$(GAME) +LIBS=dxguid.lib wsock32.lib ..\jfaud\jfaud.lib winmm.lib #opengl32.lib ASFLAGS=# -d1 EXESUFFIX=.exe @@ -69,7 +71,7 @@ EDITOROBJS=$(OBJ)build.$o & $(OBJ)startwin.editor.$o GAMEEXEOBJS=$(OBJ)game.$o & - $(OBJ)sound.$o & + $(OBJ)jfaud_sound.$o & $(OBJ)config.$o & $(OBJ)startwin.game.$o @@ -80,7 +82,9 @@ EDITOREXEOBJS=$(OBJ)bstub.$o .wasm: $(SRC) .c: $(SRC) -.c: $(SRC)tmp/ +.cpp: $(SRC) +.c: $(GAME) +.cpp: $(GAME) .c: $(SRC)util/ .rc: $(SRC)misc/ @@ -89,9 +93,11 @@ EDITOREXEOBJS=$(OBJ)bstub.$o .c.$o: $(CC) $(CFLAGS) -fo=$(OBJ).$o $[@ +.cpp.$o: + $(CXX) $(CFLAGS) $(GAMECFLAGS) -fo=$(OBJ).$o $[@ .rc.$(res): - $(RC) -fo=$^*.$(res) -r $[@ + $(RC) -i=$(SRC) -i=$(INC) -i=$(GAME) -fo=$^*.$(res) -r $[@ # TARGETS UTILS=kextract$(EXESUFFIX) kgroup$(EXESUFFIX) transpal$(EXESUFFIX) wad2art$(EXESUFFIX) wad2map$(EXESUFFIX) diff --git a/polymer/build/src/StartupWinController.game.m b/polymer/build/game/StartupWinController.game.m similarity index 100% rename from polymer/build/src/StartupWinController.game.m rename to polymer/build/game/StartupWinController.game.m diff --git a/polymer/build/game/bstub.c b/polymer/build/game/bstub.c new file mode 100755 index 000000000..d8a33a8eb --- /dev/null +++ b/polymer/build/game/bstub.c @@ -0,0 +1,564 @@ +// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman +// Ken Silverman's official web site: "http://www.advsys.net/ken" +// See the included license file "BUILDLIC.TXT" for license info. +// +// This file has been modified from Ken Silverman's original release +// by Jonathon Fowler (jonof@edgenetwk.com) + +#include "compat.h" +#include "a.h" +#include "build.h" +#include "editor.h" +#include "pragmas.h" +#include "baselayer.h" +#include "names.h" +#include "osd.h" +#include "cache1d.h" + + +static char tempbuf[256]; + +#define NUMOPTIONS 9 +char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0,0}; +char keys[NUMBUILDKEYS] = +{ + 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, + 0x1e,0x2c,0xd1,0xc9,0x33,0x34, + 0x9c,0x1c,0xd,0xc,0xf,0x45 +}; + + + +//static long hang = 0; +//static long rollangle = 0; + +//Detecting 2D / 3D mode: +// qsetmode is 200 in 3D mode +// qsetmode is 350/480 in 2D mode +// +//You can read these variables when F5-F8 is pressed in 3D mode only: +// +// If (searchstat == 0) WALL searchsector=sector, searchwall=wall +// If (searchstat == 1) CEILING searchsector=sector +// If (searchstat == 2) FLOOR searchsector=sector +// If (searchstat == 3) SPRITE searchsector=sector, searchwall=sprite +// If (searchstat == 4) MASKED WALL searchsector=sector, searchwall=wall +// +// searchsector is the sector of the selected item for all 5 searchstat's +// +// searchwall is undefined if searchstat is 1 or 2 +// searchwall is the wall if searchstat = 0 or 4 +// searchwall is the sprite if searchstat = 3 (Yeah, I know - it says wall, +// but trust me, it's the sprite number) + +long averagefps; +#define AVERAGEFRAMES 32 +static unsigned long frameval[AVERAGEFRAMES]; +static long framecnt = 0; + +char *defsfilename = "kenbuild.def"; +char *startwin_labeltext = "Starting Build Editor..."; +int nextvoxid = 0; + +int ExtInit(void) +{ + long i, rv = 0; + + /*printf("------------------------------------------------------------------------------\n"); + printf(" BUILD.EXE copyright(c) 1996 by Ken Silverman. You are granted the\n"); + printf(" right to use this software for your personal use only. This is a\n"); + printf(" special version to be used with \"Happy Fun KenBuild\" and may not work\n"); + printf(" properly with other Build engine games. Please refer to license.doc\n"); + printf(" for distribution rights\n"); + printf("------------------------------------------------------------------------------\n"); + getch(); + */ + + initgroupfile("stuff.dat"); + bpp = 8; + if (loadsetup("build.cfg") < 0) initprintf("Configuration file not found, using defaults.\n"), rv = 1; + Bmemcpy((void *)buildkeys,(void *)keys,NUMBUILDKEYS); //Trick to make build use setup.dat keys + if (option[4] > 0) option[4] = 0; + if (initengine()) { + wm_msgbox("Build Engine Initialisation Error", + "There was a problem initialising the Build engine: %s", engineerrstr); + return -1; + } + initinput(); + initmouse(); + + //You can load your own palette lookup tables here if you just + //copy the right code! + for(i=0;i<256;i++) + tempbuf[i] = ((i+32)&255); //remap colors for screwy palette sectors + makepalookup(16,tempbuf,0,0,0,1); + + kensplayerheight = 32; + zmode = 0; + defaultspritecstat = 0; + pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; + +#ifdef SUPERBUILD + tiletovox[PLAYER] = nextvoxid++; + tiletovox[BROWNMONSTER] = nextvoxid++; +#endif + +#ifdef _WIN32 +// allowtaskswitching(0); +#endif + return rv; +} + +void ExtUnInit(void) +{ + uninitgroupfile(); + writesetup("build.cfg"); +} + +//static long daviewingrange, daaspect, horizval1, horizval2; +void ExtPreCheckKeys(void) +{ + long /*cosang, sinang, dx, dy, mindx,*/ i, j, k; + + if (keystatus[0x3e]) //F4 - screen re-size + { + keystatus[0x3e] = 0; + + //cycle through all vesa modes, then screen-buffer mode + if (keystatus[0x2a]|keystatus[0x36]) { + setgamemode(!fullscreen, xdim, ydim, bpp); + } else { + + //cycle through all modes + j=-1; + + // work out a mask to select the mode + for (i=0; i> 3) + (xdim >> 4) + (xdim >> 6)) & (~7); + dy = (ydim + (ydim >> 3) + (ydim >> 4) + (ydim >> 6)) & (~7); + i = scale(320,ydim,xdim); + + if (waloff[4094] == 0) allocache(&waloff[4094],/*240L*384L*/dx*dy,&walock[4094]); + setviewtotile(4094,/*240L,384L*/dy,dx); + + cosang = sintable[(hang+512)&2047]; + sinang = sintable[hang&2047]; + + dx = dmulscale1(320,cosang,i,sinang); mindx = dx; + dy = dmulscale1(-i,cosang,320,sinang); + horizval1 = dy*(320>>1)/dx-1; + + dx = dmulscale1(320,cosang,-i,sinang); mindx = min(dx,mindx); + dy = dmulscale1(i,cosang,320,sinang); + horizval2 = dy*(320>>1)/dx+1; + + daviewingrange = scale(65536,16384*(xdim>>1),mindx-16); + daaspect = scale(daviewingrange,scale(320,tilesizx[4094],tilesizy[4094]),horizval2+6-horizval1); + setaspect(daviewingrange,scale(daaspect,ydim*320,xdim*i)); + horiz = 100-divscale15(horizval1+horizval2,daviewingrange); + } +#endif +} + +#ifdef SUPERBUILD +#define MAXVOXMIPS 5 +extern char *voxoff[][MAXVOXMIPS]; +void ExtAnalyzeSprites(void) +{ + long i, *longptr; + spritetype *tspr; + + for(i=0,tspr=&tsprite[0];ipicnum] >= 0) + { + switch(tspr->picnum) + { + case PLAYER: + if (!voxoff[ tiletovox[PLAYER] ][0]) { + if (qloadkvx(tiletovox[PLAYER],"voxel000.kvx")) { + tiletovox[PLAYER] = -1; + break; + } + } + //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; + longptr = (long *)voxoff[ tiletovox[PLAYER] ][0]; + tspr->xrepeat = scale(tspr->xrepeat,56,longptr[2]); + tspr->yrepeat = scale(tspr->yrepeat,56,longptr[2]); + tspr->shade -= 6; + break; + case BROWNMONSTER: + if (!voxoff[ tiletovox[BROWNMONSTER] ][0]) { + if (qloadkvx(tiletovox[BROWNMONSTER],"voxel001.kvx")) { + tiletovox[BROWNMONSTER] = -1; + break; + } + } + //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; + break; + } + } + + tspr->shade += 6; + if (sector[tspr->sectnum].ceilingstat&1) + tspr->shade += sector[tspr->sectnum].ceilingshade; + else + tspr->shade += sector[tspr->sectnum].floorshade; + } +} +#endif + +void ExtCheckKeys(void) +{ + long i;//, p, y, dx, dy, cosang, sinang, bufplc, tsizy, tsizyup15; + long j; + + if (qsetmode == 200) //In 3D mode + { +#if 0 + if (hang != 0) + { + bufplc = waloff[4094]+(mulscale16(horiz-100,xdimenscale)+(tilesizx[4094]>>1))*tilesizy[4094]; + setviewback(); + cosang = sintable[(hang+512)&2047]; + sinang = sintable[hang&2047]; + dx = dmulscale1(xdim,cosang,ydim,sinang); + dy = dmulscale1(-ydim,cosang,xdim,sinang); + + begindrawing(); + tsizy = tilesizy[4094]; + tsizyup15 = (tsizy<<15); + dx = mulscale14(dx,daviewingrange); + dy = mulscale14(dy,daaspect); + sinang = mulscale14(sinang,daviewingrange); + cosang = mulscale14(cosang,daaspect); + p = ylookup[windowy1]+frameplace+windowx2+1; + for(y=windowy1;y<=windowy2;y++) + { + i = divscale16(tsizyup15,dx); + stretchhline(0,(xdim>>1)*i+tsizyup15,xdim>>2,i,mulscale32(i,dy)*tsizy+bufplc,p); + dx -= sinang; dy += cosang; p += ylookup[1]; + } + walock[4094] = 1; + + Bsprintf(tempbuf,"%d",(hang*180)>>10); + printext256(0L,8L,31,-1,tempbuf,1); + enddrawing(); + } +#endif + if (keystatus[0xa]) setaspect(viewingrange+(viewingrange>>8),yxaspect+(yxaspect>>8)); + if (keystatus[0xb]) setaspect(viewingrange-(viewingrange>>8),yxaspect-(yxaspect>>8)); + if (keystatus[0xc]) setaspect(viewingrange,yxaspect-(yxaspect>>8)); + if (keystatus[0xd]) setaspect(viewingrange,yxaspect+(yxaspect>>8)); + //if (keystatus[0x38]) setrollangle(rollangle+=((keystatus[0x2a]|keystatus[0x36])*6+2)); + //if (keystatus[0xb8]) setrollangle(rollangle-=((keystatus[0x2a]|keystatus[0x36])*6+2)); + //if (keystatus[0x1d]|keystatus[0x9d]) setrollangle(rollangle=0); + + begindrawing(); + + i = frameval[framecnt&(AVERAGEFRAMES-1)]; + j = frameval[framecnt&(AVERAGEFRAMES-1)] = getticks(); framecnt++; + if (i != j) averagefps = ((mul3(averagefps)+((AVERAGEFRAMES*1000)/(j-i)) )>>2); + Bsprintf(tempbuf,"%ld",averagefps); + printext256(0L,0L,31,-1,tempbuf,1); + + enddrawing(); + editinput(); + } + else + { + } +} + +void ExtCleanUp(void) +{ +} + +void ExtPreLoadMap(void) +{ +} + +void ExtLoadMap(const char *mapname) +{ + char title[256]; + Bsprintf(title, "BUILD by Ken Silverman - %s", mapname); + wm_setapptitle(title); +} + +void ExtPreSaveMap(void) +{ +} + +void ExtSaveMap(const char *mapname) +{ +} + +const char *ExtGetSectorCaption(short sectnum) +{ + if ((sector[sectnum].lotag|sector[sectnum].hitag) == 0) + { + tempbuf[0] = 0; + } + else + { + Bsprintf(tempbuf,"%hu,%hu",(unsigned short)sector[sectnum].hitag, + (unsigned short)sector[sectnum].lotag); + } + return(tempbuf); +} + +const char *ExtGetWallCaption(short wallnum) +{ + if ((wall[wallnum].lotag|wall[wallnum].hitag) == 0) + { + tempbuf[0] = 0; + } + else + { + Bsprintf(tempbuf,"%hu,%hu",(unsigned short)wall[wallnum].hitag, + (unsigned short)wall[wallnum].lotag); + } + return(tempbuf); +} + +const char *ExtGetSpriteCaption(short spritenum) +{ + if ((sprite[spritenum].lotag|sprite[spritenum].hitag) == 0) + { + tempbuf[0] = 0; + } + else + { + Bsprintf(tempbuf,"%hu,%hu",(unsigned short)sprite[spritenum].hitag, + (unsigned short)sprite[spritenum].lotag); + } + return(tempbuf); +} + +//printext16 parameters: +//printext16(long xpos, long ypos, short col, short backcol, +// char name[82], char fontsize) +// xpos 0-639 (top left) +// ypos 0-479 (top left) +// col 0-15 +// backcol 0-15, -1 is transparent background +// name +// fontsize 0=8*8, 1=3*5 + +//drawline16 parameters: +// drawline16(long x1, long y1, long x2, long y2, char col) +// x1, x2 0-639 +// y1, y2 0-143 (status bar is 144 high, origin is top-left of STATUS BAR) +// col 0-15 + +void ExtShowSectorData(short sectnum) //F5 +{ + int i; + if (qsetmode == 200) //In 3D mode + { + } + else + { + begindrawing(); + clearmidstatbar16(); //Clear middle of status bar + + Bsprintf(tempbuf,"Sector %d",sectnum); + printext16(8,ydim16+32,11,-1,tempbuf,0); + + printext16(8,ydim16+48,11,-1,"8*8 font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",0); + printext16(8,ydim16+56,11,-1,"3*5 font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",1); + + i=ydim16; ydim16=ydim; + drawline16(320,i+68,344,i+80,4); //Draw house + drawline16(344,i+80,344,i+116,4); + drawline16(344,i+116,296,i+116,4); + drawline16(296,i+116,296,i+80,4); + drawline16(296,i+80,320,i+68,4); + ydim16=i; + enddrawing(); + } +} + +void ExtShowWallData(short wallnum) //F6 +{ + if (qsetmode == 200) //In 3D mode + { + } + else + { + begindrawing(); + clearmidstatbar16(); //Clear middle of status bar + + Bsprintf(tempbuf,"Wall %d",wallnum); + printext16(8,ydim16+32,11,-1,tempbuf,0); + enddrawing(); + } +} + +void ExtShowSpriteData(short spritenum) //F6 +{ + if (qsetmode == 200) //In 3D mode + { + } + else + { + begindrawing(); + clearmidstatbar16(); //Clear middle of status bar + + Bsprintf(tempbuf,"Sprite %d",spritenum); + printext16(8,ydim16+32,11,-1,tempbuf,0); + enddrawing(); + } +} + +void ExtEditSectorData(short sectnum) //F7 +{ + short nickdata; + + if (qsetmode == 200) //In 3D mode + { + //Ceiling + if (searchstat == 1) + sector[searchsector].ceilingpicnum++; //Just a stupid example + + //Floor + if (searchstat == 2) + sector[searchsector].floorshade++; //Just a stupid example + } + else //In 2D mode + { + Bsprintf(tempbuf,"Sector (%d) Nick's variable: ",sectnum); + nickdata = 0; + nickdata = getnumber16(tempbuf,nickdata,65536L,0); + + printmessage16(""); //Clear message box (top right of status bar) + ExtShowSectorData(sectnum); + } +} + +void ExtEditWallData(short wallnum) //F8 +{ + short nickdata; + + if (qsetmode == 200) //In 3D mode + { + } + else + { + Bsprintf(tempbuf,"Wall (%d) Nick's variable: ",wallnum); + nickdata = 0; + nickdata = getnumber16(tempbuf,nickdata,65536L,0); + + printmessage16(""); //Clear message box (top right of status bar) + ExtShowWallData(wallnum); + } +} + +void ExtEditSpriteData(short spritenum) //F8 +{ + short nickdata; + + if (qsetmode == 200) //In 3D mode + { + } + else + { + Bsprintf(tempbuf,"Sprite (%d) Nick's variable: ",spritenum); + nickdata = 0; + nickdata = getnumber16(tempbuf,nickdata,65536L,0); + printmessage16(""); + + printmessage16(""); //Clear message box (top right of status bar) + ExtShowSpriteData(spritenum); + } +} + +void faketimerhandler(void) +{ + sampletimer(); +} + + //Just thought you might want my getnumber16 code +/* +getnumber16(char namestart[80], short num, long maxnumber) +{ + char buffer[80]; + long j, k, n, danum, oldnum; + + danum = (long)num; + oldnum = danum; + while ((keystatus[0x1c] != 2) && (keystatus[0x1] == 0)) //Enter, ESC + { + sprintf(&buffer,"%s%ld_ ",namestart,danum); + printmessage16(buffer); + + for(j=2;j<=11;j++) //Scan numbers 0-9 + if (keystatus[j] > 0) + { + keystatus[j] = 0; + k = j-1; + if (k == 10) k = 0; + n = (danum*10)+k; + if (n < maxnumber) danum = n; + } + if (keystatus[0xe] > 0) // backspace + { + danum /= 10; + keystatus[0xe] = 0; + } + if (keystatus[0x1c] == 1) //L. enter + { + oldnum = danum; + keystatus[0x1c] = 2; + asksave = 1; + } + } + keystatus[0x1c] = 0; + keystatus[0x1] = 0; + return((short)oldnum); +} +*/ + +/* + * vim:ts=4: + */ + diff --git a/polymer/build/game/game.c b/polymer/build/game/game.c new file mode 100755 index 000000000..d4b8e6b0d --- /dev/null +++ b/polymer/build/game/game.c @@ -0,0 +1,6290 @@ +// Ken Silverman's official web site: "http://www.advsys.net/ken" +// See the included license file "BUILDLIC.TXT" for license info. +// +// This file has been modified from Ken Silverman's original release +// by Jonathon Fowler (jonof@edgenetwk.com) + +#include "compat.h" +#include "build.h" +#include "names.h" +#include "pragmas.h" +#include "cache1d.h" +#include "game.h" +#include "osd.h" +#include "mmulti.h" + +#include "baselayer.h" + +#define TIMERINTSPERSECOND 140 //280 +#define MOVESPERSECOND 40 +#define TICSPERFRAME 3 +#define MOVEFIFOSIZ 256 +#define EYEHEIGHT (32<<8) //Normally (32<<8), (51<<8) to make mirrors happy + +// declared in sound.c +void initsb(char,char,long,char,char,char,char); +void uninitsb(void); +void setears(long,long,long,long); +void wsayfollow(char *,long,long,long *,long *,char); +void wsay(char *,long,long,long); +void loadwaves(void); +void loadsong(char *); +void musicon(void); +void musicoff(void); +void refreshaudio(void); + +// declared in config.c +int loadsetup(const char *); +int writesetup(const char *); + + +/*************************************************************************** + KEN'S TAG DEFINITIONS: (Please define your own tags for your games) + + sector[?].lotag = 0 Normal sector + sector[?].lotag = 1 If you are on a sector with this tag, then all sectors + with same hi tag as this are operated. Once. + sector[?].lotag = 2 Same as sector[?].tag = 1 but this is retriggable. + sector[?].lotag = 3 A really stupid sector that really does nothing now. + sector[?].lotag = 4 A sector where you are put closer to the floor + (such as the slime in DOOM1.DAT) + sector[?].lotag = 5 A really stupid sector that really does nothing now. + sector[?].lotag = 6 A normal door - instead of pressing D, you tag the + sector with a 6. The reason I make you edit doors + this way is so that can program the doors + yourself. + sector[?].lotag = 7 A door the goes down to open. + sector[?].lotag = 8 A door that opens horizontally in the middle. + sector[?].lotag = 9 A sliding door that opens vertically in the middle. + -Example of the advantages of not using BSP tree. + sector[?].lotag = 10 A warping sector with floor and walls that shade. + sector[?].lotag = 11 A sector with all walls that do X-panning. + sector[?].lotag = 12 A sector with walls using the dragging function. + sector[?].lotag = 13 A sector with some swinging doors in it. + sector[?].lotag = 14 A revolving door sector. + sector[?].lotag = 15 A subway track. + sector[?].lotag = 16 A true double-sliding door. + + wall[?].lotag = 0 Normal wall + wall[?].lotag = 1 Y-panning wall + wall[?].lotag = 2 Switch - If you flip it, then all sectors with same hi + tag as this are operated. + wall[?].lotag = 3 Marked wall to detemine starting dir. (sector tag 12) + wall[?].lotag = 4 Mark on the shorter wall closest to the pivot point + of a swinging door. (sector tag 13) + wall[?].lotag = 5 Mark where a subway should stop. (sector tag 15) + wall[?].lotag = 6 Mark for true double-sliding doors (sector tag 16) + wall[?].lotag = 7 Water fountain + wall[?].lotag = 8 Bouncy wall! + + sprite[?].lotag = 0 Normal sprite + sprite[?].lotag = 1 If you press space bar on an AL, and the AL is tagged + with a 1, he will turn evil. + sprite[?].lotag = 2 When this sprite is operated, a bomb is shot at its + position. + sprite[?].lotag = 3 Rotating sprite. + sprite[?].lotag = 4 Sprite switch. + sprite[?].lotag = 5 Basketball hoop score. + +KEN'S STATUS DEFINITIONS: (Please define your own statuses for your games) + status = 0 Inactive sprite + status = 1 Active monster sprite + status = 2 Monster that becomes active only when it sees you + status = 3 Smoke on the wall for chainguns + status = 4 Splashing sprites (When you shoot slime) + status = 5 Explosion! + status = 6 Travelling bullet + status = 7 Bomb sprial-out explosion + status = 8 Player! + status = 9 EVILALGRAVE shrinking list + status = 10 EVILAL list + status = 11 Sprite respawning list + status = 12 Sprite which does not respawn (Andy's addition) + status = MAXSTATUS Non-existent sprite (this will be true for your + code also) +**************************************************************************/ + +typedef struct +{ + long x, y, z; +} point3d; + +typedef struct +{ + signed char fvel, svel, avel; + short bits; +} input; + +static long screentilt = 0, oscreentilt = 0; + + +static long fvel, svel, avel; +static long fvel2, svel2, avel2; + +#define NUMOPTIONS 8 +#define NUMKEYS 19 +char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0}; +char keys[NUMKEYS] = +{ + 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, + 0x1e,0x2c,0xd1,0xc9,0x33,0x34, + 0x9c,0x1c,0xd,0xc,0xf +}; +long xdimgame = 320, ydimgame = 200, bppgame = 8, xdim2d = 640, ydim2d = 480; // JBF 20050318: config.c expects to find these +long forcesetup = 1; + +static long digihz[8] = {6000,8000,11025,16000,22050,32000,44100,48000}; + +static char frame2draw[MAXPLAYERS]; +static long frameskipcnt[MAXPLAYERS]; + +#define LAVASIZ 128 +#define LAVALOGSIZ 7 +#define LAVAMAXDROPS 32 +static char lavabakpic[(LAVASIZ+4)*(LAVASIZ+4)], lavainc[LAVASIZ]; +static long lavanumdrops, lavanumframes; +static long lavadropx[LAVAMAXDROPS], lavadropy[LAVAMAXDROPS]; +static long lavadropsiz[LAVAMAXDROPS], lavadropsizlookup[LAVAMAXDROPS]; +static long lavaradx[24][96], lavarady[24][96], lavaradcnt[32]; + + //Shared player variables +static long posx[MAXPLAYERS], posy[MAXPLAYERS], posz[MAXPLAYERS]; +static long horiz[MAXPLAYERS], zoom[MAXPLAYERS], hvel[MAXPLAYERS]; +static short ang[MAXPLAYERS], cursectnum[MAXPLAYERS], ocursectnum[MAXPLAYERS]; +static short playersprite[MAXPLAYERS], deaths[MAXPLAYERS]; +static long lastchaingun[MAXPLAYERS]; +static long health[MAXPLAYERS], flytime[MAXPLAYERS]; +static short oflags[MAXPLAYERS]; +static short numbombs[MAXPLAYERS]; +static short numgrabbers[MAXPLAYERS]; // Andy did this +static short nummissiles[MAXPLAYERS]; // Andy did this +static char dimensionmode[MAXPLAYERS]; +static char revolvedoorstat[MAXPLAYERS]; +static short revolvedoorang[MAXPLAYERS], revolvedoorrotang[MAXPLAYERS]; +static long revolvedoorx[MAXPLAYERS], revolvedoory[MAXPLAYERS]; + + //ENGINE CONTROLLED MULTIPLAYER VARIABLES: +extern long numplayers, myconnectindex; +extern long connecthead, connectpoint2[MAXPLAYERS]; //Player linked list variables (indeces, not connection numbers) + +static long nummoves; +// Bug: NUMSTATS used to be equal to the greatest tag number, +// so that the last statrate[] entry was random memory junk +// because stats 0-NUMSTATS required NUMSTATS+1 bytes. -Andy +#define NUMSTATS 13 +static signed char statrate[NUMSTATS] = {-1,0,-1,0,0,0,1,3,0,3,15,-1,-1}; + + //Input structures +static char networkmode; //0 is 2(n-1) mode, 1 is n(n-1) mode +static long locselectedgun, locselectedgun2; +static input loc, oloc, loc2; +static input ffsync[MAXPLAYERS], osync[MAXPLAYERS], ssync[MAXPLAYERS]; + //Input faketimerhandler -> movethings fifo +static long movefifoplc, movefifoend[MAXPLAYERS]; +static input baksync[MOVEFIFOSIZ][MAXPLAYERS]; + //Game recording variables +static long reccnt, recstat = 1; +static input recsync[16384][2]; + +//static long myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter = 1; +static signed char otherlag[MAXPLAYERS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; +static long averagelag[MAXPLAYERS] = {512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512}; + +static long fakemovefifoplc; +static long myx, myy, myz, omyx, omyy, omyz, myzvel; +static long myhoriz, omyhoriz; +static short myang, omyang, mycursectnum; +static long myxbak[MOVEFIFOSIZ], myybak[MOVEFIFOSIZ], myzbak[MOVEFIFOSIZ]; +static long myhorizbak[MOVEFIFOSIZ]; +static short myangbak[MOVEFIFOSIZ]; + + //MULTI.OBJ sync state variables +extern char syncstate; + //GAME.C sync state variables +static char syncstat, syncval[MOVEFIFOSIZ], othersyncval[MOVEFIFOSIZ]; +static long syncvaltottail, syncvalhead, othersyncvalhead, syncvaltail; + +static char detailmode = 0, ready2send = 0; +static long ototalclock = 0, gotlastpacketclock = 0, smoothratio; +static long oposx[MAXPLAYERS], oposy[MAXPLAYERS], oposz[MAXPLAYERS]; +static long ohoriz[MAXPLAYERS], ozoom[MAXPLAYERS]; +static short oang[MAXPLAYERS]; + +static point3d osprite[MAXSPRITES]; + +#define MAXINTERPOLATIONS 1024 +static long numinterpolations = 0, startofdynamicinterpolations = 0; +static long oldipos[MAXINTERPOLATIONS]; +static long bakipos[MAXINTERPOLATIONS]; +static long *curipos[MAXINTERPOLATIONS]; + +extern long cachecount; + +static char playerreadyflag[MAXPLAYERS]; + + //Miscellaneous variables +static char packbuf[MAXXDIM]; +static char tempbuf[MAXXDIM], boardfilename[80]; +static short tempshort[MAXSECTORS]; +static short screenpeek = 0, oldmousebstatus = 0; +short brightness = 0; +static short screensize, screensizeflag = 0; +static short neartagsector, neartagwall, neartagsprite; +static long lockclock, neartagdist, neartaghitdist; +extern long pageoffset, ydim16; +static long globhiz, globloz, globhihit, globlohit; + + //Over the shoulder mode variables +static long cameradist = -1, cameraang = 0, cameraclock = 0; + + //Board animation variables +#define MAXMIRRORS 64 +static short mirrorwall[MAXMIRRORS], mirrorsector[MAXMIRRORS], mirrorcnt; +static short floormirrorsector[64], floormirrorcnt; +static short turnspritelist[16], turnspritecnt; +static short warpsectorlist[64], warpsectorcnt; +static short xpanningsectorlist[16], xpanningsectorcnt; +static short ypanningwalllist[64], ypanningwallcnt; +static short floorpanninglist[64], floorpanningcnt; +static short dragsectorlist[16], dragxdir[16], dragydir[16], dragsectorcnt; +static long dragx1[16], dragy1[16], dragx2[16], dragy2[16], dragfloorz[16]; +static short swingcnt, swingwall[32][5], swingsector[32]; +static short swingangopen[32], swingangclosed[32], swingangopendir[32]; +static short swingang[32], swinganginc[32]; +static long swingx[32][8], swingy[32][8]; +static short revolvesector[4], revolveang[4], revolvecnt; +static long revolvex[4][16], revolvey[4][16]; +static long revolvepivotx[4], revolvepivoty[4]; +static short subwaytracksector[4][128], subwaynumsectors[4], subwaytrackcnt; +static long subwaystop[4][8], subwaystopcnt[4]; +static long subwaytrackx1[4], subwaytracky1[4]; +static long subwaytrackx2[4], subwaytracky2[4]; +static long subwayx[4], subwaygoalstop[4], subwayvel[4], subwaypausetime[4]; +static short waterfountainwall[MAXPLAYERS], waterfountaincnt[MAXPLAYERS]; +static short slimesoundcnt[MAXPLAYERS]; + + //Variables that let you type messages to other player +static char getmessage[162], getmessageleng; +static long getmessagetimeoff; +static char typemessage[162], typemessageleng = 0, typemode = 0; +/* +static char scantoasc[128] = +{ + 0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0, + 'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s', + 'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v', + 'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0, + 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', + '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; +static char scantoascwithshift[128] = +{ + 0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0, + 'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S', + 'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V', + 'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0, + 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', + '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +}; +*/ + + //These variables are for animating x, y, or z-coordinates of sectors, + //walls, or sprites (They are NOT to be used for changing the [].picnum's) + //See the setanimation(), and getanimategoal() functions for more details. +#define MAXANIMATES 512 +static long *animateptr[MAXANIMATES], animategoal[MAXANIMATES]; +static long animatevel[MAXANIMATES], animateacc[MAXANIMATES], animatecnt = 0; + +#if defined(POLYMOST) && defined(USE_OPENGL) + //These parameters are in exact order of sprite structure in BUILD.H +#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2, \ + clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2, \ + xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \ +{ \ + spritetype *spr2; \ + newspriteindex2 = insertsprite(sectnum2,statnum2); \ + spr2 = &sprite[newspriteindex2]; \ + spr2->x = x2; spr2->y = y2; spr2->z = z2; \ + spr2->cstat = cstat2; spr2->shade = shade2; \ + spr2->pal = pal2; spr2->clipdist = clipdist2; \ + spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2; \ + spr2->xoffset = xoffset2; spr2->yoffset = yoffset2; \ + spr2->picnum = picnum2; spr2->ang = ang2; \ + spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2; \ + spr2->owner = owner2; \ + spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2; \ + copybuf(&spr2->x,&osprite[newspriteindex2].x,3); \ + show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7)); \ + if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7))) \ + show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7)); \ + clearbufbyte(&spriteext[newspriteindex2], sizeof(spriteexttype), 0); \ +} +#else +#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2, \ + clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2, \ + xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \ +{ \ + spritetype *spr2; \ + newspriteindex2 = insertsprite(sectnum2,statnum2); \ + spr2 = &sprite[newspriteindex2]; \ + spr2->x = x2; spr2->y = y2; spr2->z = z2; \ + spr2->cstat = cstat2; spr2->shade = shade2; \ + spr2->pal = pal2; spr2->clipdist = clipdist2; \ + spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2; \ + spr2->xoffset = xoffset2; spr2->yoffset = yoffset2; \ + spr2->picnum = picnum2; spr2->ang = ang2; \ + spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2; \ + spr2->owner = owner2; \ + spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2; \ + copybuf(&spr2->x,&osprite[newspriteindex2].x,3); \ + show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7)); \ + if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7))) \ + show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7)); \ +} +#endif + +int nextvoxid = 0; + +static int osdcmd_restartvid(const osdfuncparm_t *parm) +{ + resetvideomode(); + if (setgamemode(fullscreen,xdim,ydim,bpp)) + OSD_Printf("restartvid: Reset failed...\n"); + + return OSDCMD_OK; +} + +static int osdcmd_vidmode(const osdfuncparm_t *parm) +{ + long newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen; + + if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP; + + switch (parm->numparms) { + case 1: // bpp switch + newbpp = Batol(parm->parms[0]); + break; + case 2: // res switch + newx = Batol(parm->parms[0]); + newy = Batol(parm->parms[1]); + break; + case 3: // res & bpp switch + case 4: + newx = Batol(parm->parms[0]); + newy = Batol(parm->parms[1]); + newbpp = Batol(parm->parms[2]); + if (parm->numparms == 4) + newfullscreen = (Batol(parm->parms[3]) != 0); + break; + } + + if (setgamemode(newfullscreen,newx,newy,newbpp)) + OSD_Printf("vidmode: Mode change failed!\n"); + screensize = xdim+1; + return OSDCMD_OK; +} + +extern int startwin_run(void); + +long app_main(long argc, char *argv[]) +{ + long cmdsetup = 0, i, j, k, l, fil, waitplayers, x1, y1, x2, y2; + long other, packleng, netparm; + +#ifdef USE_OPENGL + OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid); + OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode); +#endif + + wm_setapptitle("KenBuild by Ken Silverman"); + + Bstrcpy(boardfilename, "nukeland.map"); + j = 0; netparm = argc; + for (i=1;i= 2); + + pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; + + loadpics("tiles000.art",1048576); //Load artwork +#ifdef SUPERBUILD + if (!qloadkvx(nextvoxid,"voxel000.kvx")) + tiletovox[PLAYER] = nextvoxid++; + if (!qloadkvx(nextvoxid,"voxel001.kvx")) + tiletovox[BROWNMONSTER] = nextvoxid++; +#endif + if (!loaddefinitionsfile("kenbuild.def")) initprintf("Definitions file loaded.\n"); + + //Here's an example of TRUE ornamented walls + //The allocatepermanenttile should be called right after loadpics + //Since it resets the tile cache for each call. + if (allocatepermanenttile(SLIME,128,128) == 0) //If enough memory + { + printf("Not enough memory for slime!\n"); + exit(0); + } + if (allocatepermanenttile(MAXTILES-1,64,64) != 0) //If enough memory + { + //My face with an explosion written over it + copytilepiece(KENPICTURE,0,0,64,64,MAXTILES-1,0,0); + copytilepiece(EXPLOSION,0,0,64,64,MAXTILES-1,0,0); + } + + initlava(); + + for(j=0;j<256;j++) + tempbuf[j] = ((j+32)&255); //remap colors for screwy palette sectors + makepalookup(16,tempbuf,0,0,0,1); + + for(j=0;j<256;j++) tempbuf[j] = j; + makepalookup(17,tempbuf,24,24,24,1); + + for(j=0;j<256;j++) tempbuf[j] = j; //(j&31)+32; + makepalookup(18,tempbuf,8,8,48,1); + + prepareboard(boardfilename); //Load board + + initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,((option[7]&2)>0)+1,60,option[7]&1); + //if (Bstrcmp(boardfilename,"klab.map") == 0) + // loadsong("klabsong.kdm"); + //else + loadsong("neatsong.ogg"); + musicon(); + + /* + if (option[4] > 0) + { + x1 = ((xdim-screensize)>>1); + x2 = x1+screensize-1; + y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + y2 = y1 + scale(screensize,ydim-32,xdim)-1; + + drawtilebackground(0L,0L,BACKGROUND,8,x1,y1,x2,y2,0); + + sendlogon(); + + if (option[4] < 5) waitplayers = 2; else waitplayers = option[4]-3; + while (numplayers < waitplayers) + { + sprintf(tempbuf,"%ld of %ld players in...",numplayers,waitplayers); + printext256(68L,84L,31,0,tempbuf,0); + nextpage(); + + if (getpacket(&other,packbuf) > 0) + if (packbuf[0] == 255) + keystatus[1] = 1; + + if (handleevents()) { + if (quitevent) { + keystatus[1] = 1; + quitevent = 0; + } + } + + if (keystatus[1]) + { + sendlogoff(); //Signing off + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + exit(0); + } + } + screenpeek = myconnectindex; + + if (numplayers <= 3) + networkmode = 1; + else + networkmode = 0; + + j = 1; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (myconnectindex == i) break; + j++; + } + sprintf(getmessage,"Player %ld",j); + if (networkmode == 0) + { + if (j == 1) Bstrcat(getmessage," (Master)"); + else Bstrcat(getmessage," (Slave)"); + } else + Bstrcat(getmessage," (Even)"); + getmessageleng = Bstrlen(getmessage); + getmessagetimeoff = totalclock+120; + } + */ + screenpeek = myconnectindex; + reccnt = 0; + for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); + + waitforeverybody(); + totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0; + + ready2send = 1; + drawscreen(screenpeek,65536L); + + while (!keystatus[1]) //Main loop starts here + { + if (handleevents()) { + if (quitevent) { + keystatus[1] = 1; + quitevent = 0; + } + } + + refreshaudio(); + OSD_DispatchQueued(); + + // backslash (useful only with KDM) +// if (keystatus[0x2b]) { keystatus[0x2b] = 0; preparesndbuf(); } + + if ((networkmode == 1) || (myconnectindex != connecthead)) + while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings(); + + getpackets(); + + if (typemode == 0) //if normal game keys active + { + if ((keystatus[0x2a]&keystatus[0x36]&keystatus[0x13]) > 0) //Sh.Sh.R (replay) + { + keystatus[0x13] = 0; + playback(); + } + + if (keystatus[0x26]&(keystatus[0x1d]|keystatus[0x9d])) //Load game + { + keystatus[0x26] = 0; + loadgame(); + drawstatusbar(screenpeek); // Andy did this + } + + if (keystatus[0x1f]&(keystatus[0x1d]|keystatus[0x9d])) //Save game + { + keystatus[0x1f] = 0; + savegame(); + } + } + + if ((networkmode == 0) || (option[4] == 0)) + { + while (movefifoplc != movefifoend[0]) domovethings(); + } + else + { + j = connecthead; + if (j == myconnectindex) j = connectpoint2[j]; + averagelag[j] = ((averagelag[j]*7+(((movefifoend[myconnectindex]-movefifoend[j]+otherlag[j]+2)&255)<<8))>>3); + j = max(averagelag[j]>>9,1); + while (((movefifoend[myconnectindex]-movefifoplc)&(MOVEFIFOSIZ-1)) > j) + { + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (movefifoplc == movefifoend[i]) break; + if (i >= 0) break; + if (myconnectindex != connecthead) + { + k = ((movefifoend[myconnectindex]-movefifoend[connecthead]-otherlag[connecthead]+128)&255); + if (k > 128+1) ototalclock++; + if (k < 128-1) ototalclock--; + } + domovethings(); + } + } + i = (totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND)); + + drawscreen(screenpeek,i); + } + + sendlogoff(); //Signing off + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + + return(0); +} + +void operatesector(short dasector) +{ //Door code + long i, j, k, s, nexti, good, cnt, datag; + long dax, day, daz, dax2, day2, daz2, centx, centy; + short startwall, endwall, wallfind[2]; + + datag = sector[dasector].lotag; + + startwall = sector[dasector].wallptr; + endwall = startwall + sector[dasector].wallnum; + centx = 0L, centy = 0L; + for(i=startwall;i= 0) //If door already moving, reverse its direction + { + if (datag == 8) + daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); + else + daz = sector[dasector].floorz; + + if (animategoal[i] == daz) + animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz; + else + animategoal[i] = daz; + animatevel[i] = 0; + } + else //else insert the door's ceiling on the animation list + { + if (sector[dasector].ceilingz == sector[dasector].floorz) + daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz; + else + { + if (datag == 8) + daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); + else + daz = sector[dasector].floorz; + } + if ((j = setanimation(§or[dasector].ceilingz,daz,6L,6L)) >= 0) + wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,¢x,¢y,0); + } + } + //Simple door that moves down + if ((datag == 7) || (datag == 8)) //If the sector in front's elevator + { + i = getanimationgoal((long)§or[dasector].floorz); + if (i >= 0) //If elevator already moving, reverse its direction + { + if (datag == 8) + daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); + else + daz = sector[dasector].ceilingz; + + if (animategoal[i] == daz) + animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz; + else + animategoal[i] = daz; + animatevel[i] = 0; + } + else //else insert the elevator's ceiling on the animation list + { + if (sector[dasector].floorz == sector[dasector].ceilingz) + daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz; + else + { + if (datag == 8) + daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); + else + daz = sector[dasector].ceilingz; + } + if ((j = setanimation(§or[dasector].floorz,daz,6L,6L)) >= 0) + wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,¢x,¢y,0); + } + } + + if (datag == 9) //Smooshy-wall sideways double-door + { + //find any points with either same x or same y coordinate + // as center (centx, centy) - should be 2 points found. + wallfind[0] = -1; + wallfind[1] = -1; + for(i=startwall;i>1)-wall[wallfind[j]].x; + day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y; + if (dax2 != 0) + { + dax2 = wall[wall[wall[wallfind[j]].point2].point2].x; + dax2 -= wall[wall[wallfind[j]].point2].x; + setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L); + setanimation(&wall[i].x,wall[i].x+dax2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L); + } + else if (day2 != 0) + { + day2 = wall[wall[wall[wallfind[j]].point2].point2].y; + day2 -= wall[wall[wallfind[j]].point2].y; + setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L); + setanimation(&wall[i].y,wall[i].y+day2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L); + } + } + else + { + i = wallfind[j]-1; if (i < startwall) i = endwall-1; + dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x; + day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y; + if (dax2 != 0) + { + setanimation(&wall[wallfind[j]].x,centx,4L,0L); + setanimation(&wall[i].x,centx+dax2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].x,centx+dax2,4L,0L); + } + else if (day2 != 0) + { + setanimation(&wall[wallfind[j]].y,centy,4L,0L); + setanimation(&wall[i].y,centy+day2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].y,centy+day2,4L,0L); + } + } + } + wsayfollow("updowndr.wav",4096L-256L,256L,¢x,¢y,0); + wsayfollow("updowndr.wav",4096L+256L,256L,¢x,¢y,0); + } + + if (datag == 13) //Swinging door + { + for(i=0;i>1) == centx) && (((wall[wallfind[j]].y+wall[wall[wallfind[j]].point2].y)>>1) == centy)) + { //door was closed + //find what direction door should open + i = wallfind[j]-1; if (i < startwall) i = endwall-1; + dax2 = wall[i].x-wall[wallfind[j]].x; + day2 = wall[i].y-wall[wallfind[j]].y; + if (dax2 != 0) + { + dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x; + dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x; + setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L); + setanimation(&wall[i].x,wall[i].x+dax2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L); + setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L); + } + else if (day2 != 0) + { + day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y; + day2 -= wall[wall[wall[wallfind[j]].point2].point2].y; + setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L); + setanimation(&wall[i].y,wall[i].y+day2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L); + setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L); + } + } + else + { //door was not closed + i = wallfind[j]-1; if (i < startwall) i = endwall-1; + dax2 = wall[i].x-wall[wallfind[j]].x; + day2 = wall[i].y-wall[wallfind[j]].y; + if (dax2 != 0) + { + setanimation(&wall[wallfind[j]].x,centx,4L,0L); + setanimation(&wall[i].x,centx+dax2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L); + setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L); + } + else if (day2 != 0) + { + setanimation(&wall[wallfind[j]].y,centy,4L,0L); + setanimation(&wall[i].y,centy+day2,4L,0L); + setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L); + setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L); + } + } + } + wsayfollow("updowndr.wav",4096L-64L,256L,¢x,¢y,0); + wsayfollow("updowndr.wav",4096L+64L,256L,¢x,¢y,0); + } +} + +void operatesprite(short dasprite) +{ + long datag; + + datag = sprite[dasprite].lotag; + + if (datag == 2) //A sprite that shoots a bomb + { + shootgun(dasprite, + sprite[dasprite].x,sprite[dasprite].y,sprite[dasprite].z, + sprite[dasprite].ang,100L,sprite[dasprite].sectnum,2); + } +} + +long changehealth(short snum, short deltahealth) +{ + long dax, day; + short good, k, startwall, endwall, s; + + if (health[snum] > 0) + { + health[snum] += deltahealth; + if (health[snum] > 999) health[snum] = 999; + + if (health[snum] <= 0) + { + health[snum] = -1; + wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + sprite[playersprite[snum]].picnum = SKELETON; + } + + if ((snum == screenpeek) && (screensize <= xdim)) + { + if (health[snum] > 0) + sprintf(tempbuf,"Health:%3ld",health[snum]); + else + sprintf(tempbuf,"YOU STINK!"); + + printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80); + } + } + return(health[snum] <= 0); //You were just injured +} + +void changenumbombs(short snum, short deltanumbombs) { // Andy did this + numbombs[snum] += deltanumbombs; + if (numbombs[snum] > 999) numbombs[snum] = 999; + if (numbombs[snum] <= 0) { + wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + numbombs[snum] = 0; + } + + if ((snum == screenpeek) && (screensize <= xdim)) { + sprintf(tempbuf,"B:%3d",numbombs[snum]); + printext(8L,(ydim - 28L),tempbuf,ALPHABET,80); + } +} + +void changenummissiles(short snum, short deltanummissiles) { // Andy did this + nummissiles[snum] += deltanummissiles; + if (nummissiles[snum] > 999) nummissiles[snum] = 999; + if (nummissiles[snum] <= 0) { + wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + nummissiles[snum] = 0; + } + + if ((snum == screenpeek) && (screensize <= xdim)) { + sprintf(tempbuf,"M:%3d",nummissiles[snum]); + printext(8L,(ydim - 20L),tempbuf,ALPHABET,80); + } +} + +void changenumgrabbers(short snum, short deltanumgrabbers) { // Andy did this + numgrabbers[snum] += deltanumgrabbers; + if (numgrabbers[snum] > 999) numgrabbers[snum] = 999; + if (numgrabbers[snum] <= 0) { + wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + numgrabbers[snum] = 0; + } + + if ((snum == screenpeek) && (screensize <= xdim)) { + sprintf(tempbuf,"G:%3d",numgrabbers[snum]); + printext(8L,(ydim - 12L),tempbuf,ALPHABET,80); + } +} + +static long ostatusflytime = 0x80000000; +void drawstatusflytime(short snum) { // Andy did this + long nstatusflytime; + + if ((snum == screenpeek) && (screensize <= xdim)) { + nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120); + if (nstatusflytime > 1000) nstatusflytime = 1000; + else if (nstatusflytime < 0) nstatusflytime = 0; + if (nstatusflytime != ostatusflytime) { + if (nstatusflytime > 999) sprintf(tempbuf,"FT:BIG"); + else sprintf(tempbuf,"FT:%3ld",nstatusflytime); + printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80); + ostatusflytime = nstatusflytime; + } + } +} + +void drawstatusbar(short snum) { // Andy did this + long nstatusflytime; + + if ((snum == screenpeek) && (screensize <= xdim)) { + Bsprintf(tempbuf,"Deaths:%d",deaths[snum]); + printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-16,tempbuf,ALPHABET,80); + Bsprintf(tempbuf,"Health:%3ld",health[snum]); + printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80); + + Bsprintf(tempbuf,"B:%3d",numbombs[snum]); + printext(8L,(ydim - 28L),tempbuf,ALPHABET,80); + Bsprintf(tempbuf,"M:%3d",nummissiles[snum]); + printext(8L,(ydim - 20L),tempbuf,ALPHABET,80); + Bsprintf(tempbuf,"G:%3d",numgrabbers[snum]); + printext(8L,(ydim - 12L),tempbuf,ALPHABET,80); + + nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120); + if (nstatusflytime < 0) { + Bsprintf(tempbuf,"FT: 0"); + ostatusflytime = 0; + } + else if (nstatusflytime > 999) { + Bsprintf(tempbuf,"FT:BIG"); + ostatusflytime = 999; + } + else { + Bsprintf(tempbuf,"FT:%3ld",nstatusflytime); + ostatusflytime = nstatusflytime; + } + printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80); + } +} + +void prepareboard(char *daboardfilename) +{ + short startwall, endwall, dasector; + long i, j, k=0, s, dax, day, daz, dax2, day2; + + getmessageleng = 0; + typemessageleng = 0; + + randomseed = 17L; + + //Clear (do)animation's list + animatecnt = 0; + typemode = 0; + locselectedgun = 0; + locselectedgun2 = 0; + + if (loadboard(daboardfilename,0,&posx[0],&posy[0],&posz[0],&ang[0],&cursectnum[0]) == -1) + { + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + printf("Board not found\n"); + exit(0); + } else { + char *fp; + + strcpy(tempbuf, daboardfilename); + fp = strrchr(tempbuf,'.'); + if (fp) *fp = 0; + strcat(tempbuf,".mhk"); + + loadmaphack(tempbuf); + } + + setup3dscreen(); + + for(i=0;i dax2) dax2 = wall[j].x; + if (wall[j].y > day2) day2 = wall[j].y; + if (wall[j].lotag == 3) k = j; + } + if (wall[k].x == dax) dragxdir[dragsectorcnt] = -16; + if (wall[k].y == day) dragydir[dragsectorcnt] = -16; + if (wall[k].x == dax2) dragxdir[dragsectorcnt] = 16; + if (wall[k].y == day2) dragydir[dragsectorcnt] = 16; + + dasector = wall[startwall].nextsector; + dragx1[dragsectorcnt] = 0x7fffffff; + dragy1[dragsectorcnt] = 0x7fffffff; + dragx2[dragsectorcnt] = 0x80000000; + dragy2[dragsectorcnt] = 0x80000000; + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + for(j=startwall;j dragx2[dragsectorcnt]) dragx2[dragsectorcnt] = wall[j].x; + if (wall[j].y > dragy2[dragsectorcnt]) dragy2[dragsectorcnt] = wall[j].y; + + setinterpolation(§or[dasector].floorz); + setinterpolation(&wall[j].x); + setinterpolation(&wall[j].y); + setinterpolation(&wall[wall[j].nextwall].x); + setinterpolation(&wall[wall[j].nextwall].y); + } + + dragx1[dragsectorcnt] += (wall[sector[i].wallptr].x-dax); + dragy1[dragsectorcnt] += (wall[sector[i].wallptr].y-day); + dragx2[dragsectorcnt] -= (dax2-wall[sector[i].wallptr].x); + dragy2[dragsectorcnt] -= (day2-wall[sector[i].wallptr].y); + + dragfloorz[dragsectorcnt] = sector[i].floorz; + + dragsectorlist[dragsectorcnt++] = i; + break; + case 13: + startwall = sector[i].wallptr; + endwall = startwall+sector[i].wallnum; + for(j=startwall;j dax2) dax2 = wall[j].x; + if (wall[j].y > day2) day2 = wall[j].y; + } + for(j=startwall;j dax) && (wall[j].y > day) && (wall[j].x < dax2) && (wall[j].y < day2)) + { + subwayx[subwaytrackcnt] = wall[j].x; + } + else + { + subwaystop[subwaytrackcnt][subwaystopcnt[subwaytrackcnt]] = wall[j].x; + subwaystopcnt[subwaytrackcnt]++; + } + } + } + + for(j=1;j subwaytrackx1[subwaytrackcnt]) + if (wall[startwall].y > subwaytracky1[subwaytrackcnt]) + if (wall[startwall].x < subwaytrackx2[subwaytrackcnt]) + if (wall[startwall].y < subwaytracky2[subwaytrackcnt]) + { + if (sector[j].floorz != sector[i].floorz) + { + sector[j].ceilingstat |= 64; + sector[j].floorstat |= 64; + } + subwaytracksector[subwaytrackcnt][subwaynumsectors[subwaytrackcnt]] = j; + subwaynumsectors[subwaytrackcnt]++; + } + } + + subwayvel[subwaytrackcnt] = 64; + subwaypausetime[subwaytrackcnt] = 720; + + startwall = sector[i].wallptr; + endwall = startwall+sector[i].wallnum; + for(k=startwall;k subwaytrackx1[subwaytrackcnt]) + if (wall[k].y > subwaytracky1[subwaytrackcnt]) + if (wall[k].x < subwaytrackx2[subwaytrackcnt]) + if (wall[k].y < subwaytracky2[subwaytrackcnt]) + setinterpolation(&wall[k].x); + + for(j=1;j=0;k=nextspritesect[k]) + if (statrate[sprite[k].statnum] < 0) + setinterpolation(&sprite[k].x); + } + + + subwaytrackcnt++; + break; + } + if (sector[i].floorpicnum == FLOORMIRROR) + floormirrorsector[mirrorcnt++] = i; + //if (sector[i].ceilingpicnum == FLOORMIRROR) floormirrorsector[mirrorcnt++] = i; //SOS + } + + //Scan wall tags + + mirrorcnt = 0; + tilesizx[MIRROR] = 0; + tilesizy[MIRROR] = 0; + for(i=0;i= 0) && (wall[i].overpicnum == MIRROR) && (wall[i].cstat&32)) + { + if ((sector[s].floorstat&1) == 0) + { + wall[i].overpicnum = MIRRORLABEL+mirrorcnt; + sector[s].ceilingpicnum = MIRRORLABEL+mirrorcnt; + sector[s].floorpicnum = MIRRORLABEL+mirrorcnt; + sector[s].floorstat |= 1; + mirrorwall[mirrorcnt] = i; + mirrorsector[mirrorcnt] = s; + mirrorcnt++; + } + else + wall[i].overpicnum = sector[s].ceilingpicnum; + } + } + + //Invalidate textures in sector behind mirror + for(i=0;i=0;i--) copybuf(&sprite[i].x,&osprite[i].x,3); + + searchmap(cursectnum[connecthead]); + + lockclock = 0; + ototalclock = 0; + gotlastpacketclock = 0; + + screensize = xdim; + dax = ((xdim-screensize)>>1); + dax2 = dax+screensize-1; + day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + day2 = day + scale(screensize,ydim-32,xdim)-1; + setview(dax,day,dax2,day2); + + startofdynamicinterpolations = numinterpolations; + + /* + for(i=connecthead;i>=0;i=connectpoint2[i]) myminlag[i] = 0; + otherminlag = mymaxlag = 0; + */ +} + +void checktouchsprite(short snum, short sectnum) +{ + long i, nexti; + + if ((sectnum < 0) || (sectnum >= numsectors)) return; + + for(i=headspritesect[sectnum];i>=0;i=nexti) + { + nexti = nextspritesect[i]; + if (sprite[i].cstat&0x8000) continue; + if ((klabs(posx[snum]-sprite[i].x)+klabs(posy[snum]-sprite[i].y) < 512) && (klabs((posz[snum]>>8)-((sprite[i].z>>8)-(tilesizy[sprite[i].picnum]>>1))) <= 40)) + { + switch(sprite[i].picnum) + { + case COIN: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0); + changehealth(snum,5); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*60; + changespritestat((short)i,11); + } + break; + case DIAMONDS: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + changehealth(snum,15); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*120; + changespritestat((short)i,11); + } + break; + case COINSTACK: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + changehealth(snum,25); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*180; + changespritestat((short)i,11); + } + break; + case GIFTBOX: + wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0); + changehealth(snum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case CANNON: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (snum == myconnectindex) keystatus[4] = 1; + changenumbombs(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case LAUNCHER: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (snum == myconnectindex) keystatus[5] = 1; + changenummissiles(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case GRABCANNON: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (snum == myconnectindex) keystatus[6] = 1; + changenumgrabbers(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case AIRPLANE: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (flytime[snum] < lockclock) flytime[snum] = lockclock; + flytime[snum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat); + drawstatusflytime(snum); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + } + } + } +} + +void checkgrabbertouchsprite(short snum, short sectnum) // Andy did this +{ + long i, nexti; + short onum; + + if ((sectnum < 0) || (sectnum >= numsectors)) return; + onum = (sprite[snum].owner & (MAXSPRITES - 1)); + + for(i=headspritesect[sectnum];i>=0;i=nexti) + { + nexti = nextspritesect[i]; + if (sprite[i].cstat&0x8000) continue; + if ((klabs(sprite[snum].x-sprite[i].x)+klabs(sprite[snum].y-sprite[i].y) < 512) && (klabs((sprite[snum].z>>8)-((sprite[i].z>>8)-(tilesizy[sprite[i].picnum]>>1))) <= 40)) + { + switch(sprite[i].picnum) + { + case COIN: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0); + changehealth(onum,5); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*60; + changespritestat((short)i,11); + } + break; + case DIAMONDS: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + changehealth(onum,15); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*120; + changespritestat((short)i,11); + } + break; + case COINSTACK: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + changehealth(onum,25); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*180; + changespritestat((short)i,11); + } + break; + case GIFTBOX: + wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0); + changehealth(onum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case CANNON: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (onum == myconnectindex) keystatus[4] = 1; + changenumbombs(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case LAUNCHER: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (onum == myconnectindex) keystatus[5] = 1; + changenummissiles(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case GRABCANNON: + wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (onum == myconnectindex) keystatus[6] = 1; + changenumgrabbers(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + case AIRPLANE: + wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (flytime[snum] < lockclock) flytime[snum] = lockclock; + flytime[onum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat); + drawstatusflytime(onum); + if (sprite[i].statnum == 12) deletesprite((short)i); + else { + sprite[i].cstat |= 0x8000; + sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); + changespritestat((short)i,11); + } + break; + } + } + } +} + +void shootgun(short snum, long x, long y, long z, + short daang, long dahoriz, short dasectnum, char guntype) +{ + short hitsect, hitwall, hitsprite, daang2; + long i, j, daz2, hitx, hity, hitz; + + switch(guntype) + { + case 0: //Shoot chain gun + daang2 = ((daang + (krand()&31)-16)&2047); + daz2 = ((100-dahoriz)*2000) + ((krand()-32768)>>1); + + hitscan(x,y,z,dasectnum, //Start position + sintable[(daang2+512)&2047], //X vector of 3D ang + sintable[daang2&2047], //Y vector of 3D ang + daz2, //Z vector of 3D ang + &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); + + if (wall[hitwall].picnum == KENPICTURE) + { + if (waloff[MAXTILES-1] != 0) wall[hitwall].picnum = MAXTILES-1; + wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&wall[hitwall].x,&wall[hitwall].y,0); + } + else if (((hitwall < 0) && (hitsprite < 0) && (hitz >= z) && ((sector[hitsect].floorpicnum == SLIME) || (sector[hitsect].floorpicnum == FLOORMIRROR))) || ((hitwall >= 0) && (wall[hitwall].picnum == SLIME))) + { //If you shoot slime, make a splash + wsayfollow("splash.wav",4096L+(krand()&511)-256,256L,&hitx,&hity,0); + spawnsprite(j,hitx,hity,hitz,2,0,0,32,64,64,0,0,SPLASH,daang, + 0,0,0,snum+4096,hitsect,4,63,0,0); //63=time left for splash + } + else + { + wsayfollow("shoot.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); + + if ((hitsprite >= 0) && (sprite[hitsprite].statnum < MAXSTATUS)) + switch(sprite[hitsprite].picnum) + { + case BROWNMONSTER: + if (sprite[hitsprite].lotag > 0) sprite[hitsprite].lotag -= 10; + if (sprite[hitsprite].lotag > 0) + { + wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&hitx,&hity,0); + if (sprite[hitsprite].lotag <= 25) + sprite[hitsprite].cstat |= 2; + } + else + { + wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); + sprite[hitsprite].z += ((tilesizy[sprite[hitsprite].picnum]*sprite[hitsprite].yrepeat)<<1); + sprite[hitsprite].picnum = GIFTBOX; + sprite[hitsprite].cstat &= ~0x83; //Should not clip, foot-z + changespritestat(hitsprite,12); + + spawnsprite(j,hitx,hity,hitz+(32<<8),0,-4,0,32,64,64, + 0,0,EXPLOSION,daang,0,0,0,snum+4096, + hitsect,5,31,0,0); + } + break; + case EVILAL: + wsayfollow("blowup.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); + sprite[hitsprite].picnum = EVILALGRAVE; + sprite[hitsprite].cstat = 0; + sprite[hitsprite].xvel = (krand()&255)-128; + sprite[hitsprite].yvel = (krand()&255)-128; + sprite[hitsprite].zvel = (krand()&4095)-3072; + changespritestat(hitsprite,9); + + spawnsprite(j,hitx,hity,hitz+(32<<8),0,-4,0,32,64,64,0, + 0,EXPLOSION,daang,0,0,0,snum+4096,hitsect,5,31,0,0); + //31=time left for explosion + + break; + case PLAYER: + for(j=connecthead;j>=0;j=connectpoint2[j]) + if (playersprite[j] == hitsprite) + { + wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); + changehealth(j,-10); + break; + } + break; + } + + spawnsprite(j,hitx,hity,hitz+(8<<8),2,-4,0,32,16,16,0,0, + EXPLOSION,daang,0,0,0,snum+4096,hitsect,3,63,0,0); + + //Sprite starts out with center exactly on wall. + //This moves it back enough to see it at all angles. + movesprite((short)j,-(((long)sintable[(512+daang)&2047]*TICSPERFRAME)<<4),-(((long)sintable[daang]*TICSPERFRAME)<<4),0L,4L<<8,4L<<8,CLIPMASK1); + } + break; + case 1: //Shoot silver sphere bullet + spawnsprite(j,x,y,z,1+128,0,0,16,64,64,0,0,BULLET,daang, + sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5, + (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); + wsayfollow("shoot2.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1); + break; + case 2: //Shoot bomb + spawnsprite(j,x,y,z,128,0,0,12,16,16,0,0,BOMB,daang, + sintable[(daang+512)&2047]*5>>8,sintable[daang&2047]*5>>8, + (80-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); + wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1); + break; + case 3: //Shoot missile (Andy did this) + spawnsprite(j,x,y,z,1+128,0,0,16,32,32,0,0,MISSILE,daang, + sintable[(daang+512)&2047]>>4,sintable[daang&2047]>>4, + (100-dahoriz)<<7,snum+4096,dasectnum,6,0,0,0); + wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1); + break; + case 4: //Shoot grabber (Andy did this) + spawnsprite(j,x,y,z,1+128,0,0,16,64,64,0,0,GRABBER,daang, + sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5, + (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); + wsayfollow("shoot4.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1); + break; + } +} + +#define MAXVOXMIPS 5 +extern char *voxoff[][MAXVOXMIPS]; +void analyzesprites(long dax, long day) +{ + long i, j=0, k, *intptr; + point3d *ospr; + spritetype *tspr; + + //This function is called between drawrooms() and drawmasks() + //It has a list of possible sprites that may be drawn on this frame + + for(i=0,tspr=&tsprite[0];ipicnum] >= 0) + switch(tspr->picnum) + { + case PLAYER: + // //Get which of the 8 angles of the sprite to draw (0-7) + // //k ranges from 0-7 + //k = getangle(tspr->x-dax,tspr->y-day); + //k = (((tspr->ang+3072+128-k)&2047)>>8)&7; + // //This guy has only 5 pictures for 8 angles (3 are x-flipped) + //if (k <= 4) + //{ + // tspr->picnum += (k<<2); + // tspr->cstat &= ~4; //clear x-flipping bit + //} + //else + //{ + // tspr->picnum += ((8-k)<<2); + // tspr->cstat |= 4; //set x-flipping bit + //} + + if ((tspr->cstat&2) == 0) + { + //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; + intptr = (long *)voxoff[ tiletovox[PLAYER] ][0]; + tspr->xrepeat = scale(tspr->xrepeat,56,intptr[2]); + tspr->yrepeat = scale(tspr->yrepeat,56,intptr[2]); + tspr->shade -= 6; + } + break; + case BROWNMONSTER: + //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; + break; + } +#endif + + k = statrate[tspr->statnum]; + if (k >= 0) //Interpolate moving sprite + { + ospr = &osprite[tspr->owner]; + switch(k) + { + case 0: j = smoothratio; break; + case 1: j = (smoothratio>>1)+(((nummoves-tspr->owner)&1)<<15); break; + case 3: j = (smoothratio>>2)+(((nummoves-tspr->owner)&3)<<14); break; + case 7: j = (smoothratio>>3)+(((nummoves-tspr->owner)&7)<<13); break; + case 15: j = (smoothratio>>4)+(((nummoves-tspr->owner)&15)<<12); break; + } + k = tspr->x-ospr->x; tspr->x = ospr->x; + if (k != 0) tspr->x += mulscale16(k,j); + k = tspr->y-ospr->y; tspr->y = ospr->y; + if (k != 0) tspr->y += mulscale16(k,j); + k = tspr->z-ospr->z; tspr->z = ospr->z; + if (k != 0) tspr->z += mulscale16(k,j); + } + + //Don't allow close explosion sprites to be transluscent + k = tspr->statnum; + if ((k == 3) || (k == 4) || (k == 5) || (k == 7)) + if (klabs(dax-tspr->x) < 256) + if (klabs(day-tspr->y) < 256) + tspr->cstat &= ~2; + + tspr->shade += 6; + if (sector[tspr->sectnum].ceilingstat&1) + tspr->shade += sector[tspr->sectnum].ceilingshade; + else + tspr->shade += sector[tspr->sectnum].floorshade; + } +} + +void tagcode(void) +{ + long i, nexti, j, k, l, s, dax, day, daz, dax2, day2, cnt, good; + short startwall, endwall, dasector, p, oldang; + + for(p=connecthead;p>=0;p=connectpoint2[p]) + { + if (sector[cursectnum[p]].lotag == 1) + { + activatehitag(sector[cursectnum[p]].hitag); + sector[cursectnum[p]].lotag = 0; + sector[cursectnum[p]].hitag = 0; + } + if ((sector[cursectnum[p]].lotag == 2) && (cursectnum[p] != ocursectnum[p])) + activatehitag(sector[cursectnum[p]].hitag); + } + + for(i=0;i>2); + if (j >= 16) j = 31-j; + { + sector[dasector].ceilingshade = j; + sector[dasector].floorshade = j; + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + for(s=startwall;s=0;p=connectpoint2[p]) + if (sector[cursectnum[p]].lotag == 10) //warp sector + { + if (cursectnum[p] != ocursectnum[p]) + { + warpsprite(playersprite[p]); + posx[p] = sprite[playersprite[p]].x; + posy[p] = sprite[playersprite[p]].y; + posz[p] = sprite[playersprite[p]].z; + ang[p] = sprite[playersprite[p]].ang; + cursectnum[p] = sprite[playersprite[p]].sectnum; + + sprite[playersprite[p]].z += EYEHEIGHT; + + //warp(&posx[p],&posy[p],&posz[p],&ang[p],&cursectnum[p]); + //Update sprite representation of player + //setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); + //sprite[playersprite[p]].ang = ang[p]; + } + } + + for(i=0;i>2)&255); + } + + for(i=0;i>2)&255); + sector[floorpanninglist[i]].floorypanning = ((lockclock>>2)&255); + } + + for(i=0;i dragx2[i]) dragxdir[i] = -16; + if (wall[startwall].y+dragydir[i] > dragy2[i]) dragydir[i] = -16; + + for(j=startwall;j>3); + + for(p=connecthead;p>=0;p=connectpoint2[p]) + if (cursectnum[p] == dasector) + { + posx[p] += dragxdir[i]; + posy[p] += dragydir[i]; + if (p == myconnectindex) + { myx += dragxdir[i]; myy += dragydir[i]; } + //posz[p] += (sector[dasector].floorz-j); + + //Update sprite representation of player + setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); + sprite[playersprite[p]].ang = ang[p]; + } + } + + for(i=0;i=0;p=connectpoint2[p]) + if ((cursectnum[p] == swingsector[i]) || (testneighborsectors(cursectnum[p],swingsector[i]) == 1)) + { + cnt = 256; + do + { + good = 1; + + //swingangopendir is -1 if forwards, 1 is backwards + l = (swingangopendir[i] > 0); + for(k=l+3;k>=l;k--) + if (clipinsidebox(posx[p],posy[p],swingwall[i][k],128L) != 0) + { + good = 0; + break; + } + if (good == 0) + { + if (cnt == 256) + { + swinganginc[i] = -swinganginc[i]; + swingang[i] = oldang; + } + else + { + swingang[i] = ((swingang[i]-swinganginc[i])&2047); + } + for(k=1;k<=3;k++) + rotatepoint(swingx[i][0],swingy[i][0],swingx[i][k],swingy[i][k],swingang[i],&wall[swingwall[i][k]].x,&wall[swingwall[i][k]].y); + if (swingang[i] == swingangclosed[i]) + { + wsayfollow("closdoor.wav",4096L+(krand()&511)-256,256L,&swingx[i][0],&swingy[i][0],0); + swinganginc[i] = 0; + break; + } + if (swingang[i] == swingangopen[i]) + { + swinganginc[i] = 0; + break; + } + cnt--; + } + } while ((good == 0) && (cnt > 0)); + } + } + } + if (swinganginc[i] == 0) + for(j=1;j<=3;j++) + { + stopinterpolation(&wall[swingwall[i][j]].x); + stopinterpolation(&wall[swingwall[i][j]].y); + } + } + + for(i=0;i 2)) + { + dasector = subwaytracksector[i][0]; + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + for(k=startwall;k subwaytrackx1[i]) + if (wall[k].y > subwaytracky1[i]) + if (wall[k].x < subwaytrackx2[i]) + if (wall[k].y < subwaytracky2[i]) + wall[k].x += subwayvel[i]; + + for(j=1;j=0;s=nextspritesect[s]) + sprite[s].x += subwayvel[i]; + } + + for(p=connecthead;p>=0;p=connectpoint2[p]) + if (cursectnum[p] != subwaytracksector[i][0]) + if (sector[cursectnum[p]].floorz != sector[subwaytracksector[i][0]].floorz) + if (posx[p] > subwaytrackx1[i]) + if (posy[p] > subwaytracky1[i]) + if (posx[p] < subwaytrackx2[i]) + if (posy[p] < subwaytracky2[i]) + { + posx[p] += subwayvel[i]; + if (p == myconnectindex) + { myx += subwayvel[i]; } + + //Update sprite representation of player + setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); + sprite[playersprite[p]].ang = ang[p]; + } + + subwayx[i] += subwayvel[i]; + } + + j = subwayvel[i]; + k = subwaystop[i][subwaygoalstop[i]] - subwayx[i]; + if (k > 0) + { + if (k > 4096) + { + if (subwayvel[i] < 256) subwayvel[i]++; + } + else + subwayvel[i] = (k>>4)+1; + } + else if (k < 0) + { + if (k < -4096) + { + if (subwayvel[i] > -256) subwayvel[i]--; + } + else + subwayvel[i] = (k>>4)-1; + } + if ((j < 0) && (subwayvel[i] >= 0)) subwayvel[i] = -1; + if ((j > 0) && (subwayvel[i] <= 0)) subwayvel[i] = 1; + + if ((subwayvel[i] <= 2) && (subwayvel[i] >= -2) && (klabs(k) < 2048)) + { + //Open / close doors + if ((subwaypausetime[i] == 720) || ((subwaypausetime[i] >= 120) && (subwaypausetime[i]-TICSPERFRAME < 120))) + activatehitag(sector[subwaytracksector[i][0]].hitag); + + subwaypausetime[i] -= TICSPERFRAME; + if (subwaypausetime[i] < 0) + { + subwaypausetime[i] = 720; + if (subwayvel[i] < 0) + { + subwaygoalstop[i]--; + if (subwaygoalstop[i] < 0) + { + subwaygoalstop[i] = 1; + subwayvel[i] = 1; + } + } + else if (subwayvel[i] > 0) + { + subwaygoalstop[i]++; + if (subwaygoalstop[i] >= subwaystopcnt[i]) + { + subwaygoalstop[i] = subwaystopcnt[i]-2; + subwayvel[i] = -1; + } + } + } + } + } +} + +void statuslistcode(void) +{ + short p, target, hitobject, daang, osectnum, movestat; + long i, nexti, j, nextj, k, l, dax, day, daz, dist, ox, oy, mindist; + long doubvel, xvect, yvect; + + //Go through active BROWNMONSTER list + for(i=headspritestat[1];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + k = krand(); + + //Choose a target player + mindist = 0x7fffffff; target = connecthead; + for(p=connecthead;p>=0;p=connectpoint2[p]) + { + dist = klabs(sprite[i].x-posx[p])+klabs(sprite[i].y-posy[p]); + if (dist < mindist) mindist = dist, target = p; + } + + //brown monster decides to shoot bullet + if ((k&63) == 23) + { + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 0) + { + if ((k&0xf00) == 0xb00) changespritestat(i,2); + } + else + { + wsayfollow("monshoot.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); + + doubvel = (TICSPERFRAME<<((ssync[target].bits&256)>0)); + xvect = 0, yvect = 0; + if (ssync[target].fvel != 0) + { + xvect += ((((long)ssync[target].fvel)*doubvel*(long)sintable[(ang[target]+512)&2047])>>3); + yvect += ((((long)ssync[target].fvel)*doubvel*(long)sintable[ang[target]&2047])>>3); + } + if (ssync[target].svel != 0) + { + xvect += ((((long)ssync[target].svel)*doubvel*(long)sintable[ang[target]&2047])>>3); + yvect += ((((long)ssync[target].svel)*doubvel*(long)sintable[(ang[target]+1536)&2047])>>3); + } + + ox = posx[target]; oy = posy[target]; + + //distance is j + j = ksqrt((ox-sprite[i].x)*(ox-sprite[i].x)+(oy-sprite[i].y)*(oy-sprite[i].y)); + + switch((sprite[i].extra>>11)&3) + { + case 1: j = -(j>>1); break; + case 3: j = 0; break; + case 0: case 2: break; + } + sprite[i].extra += 2048; + + //rate is (TICSPERFRAME<<19) + xvect = scale(xvect,j,TICSPERFRAME<<19); + yvect = scale(yvect,j,TICSPERFRAME<<19); + clipmove(&ox,&oy,&posz[target],&cursectnum[target],xvect<<14,yvect<<14,128L,4<<8,4<<8,CLIPMASK0); + ox -= sprite[i].x; + oy -= sprite[i].y; + + daang = ((getangle(ox,oy)+(krand()&7)-4)&2047); + + dax = (sintable[(daang+512)&2047]>>6); + day = (sintable[daang&2047]>>6); + daz = 0; + if (ox != 0) + daz = scale(dax,posz[target]+(8<<8)-sprite[i].z,ox); + else if (oy != 0) + daz = scale(day,posz[target]+(8<<8)-sprite[i].z,oy); + + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,128,0,0, + 16,sprite[i].xrepeat,sprite[i].yrepeat,0,0,BULLET,daang,dax,day,daz,i,sprite[i].sectnum,6,0,0,0); + + sprite[i].extra &= (~2047); + } + } + + //Move brown monster + dax = sprite[i].x; //Back up old x&y if stepping off cliff + day = sprite[i].y; + + doubvel = max(mulscale7(sprite[i].xrepeat,sprite[i].yrepeat),4); + + osectnum = sprite[i].sectnum; + movestat = movesprite((short)i,(long)sintable[(sprite[i].ang+512)&2047]*doubvel,(long)sintable[sprite[i].ang]*doubvel,0L,4L<<8,4L<<8,CLIPMASK0); + if (globloz > sprite[i].z+(48<<8)) + { sprite[i].x = dax; sprite[i].y = day; movestat = 1; } + else + sprite[i].z = globloz-((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); + + if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) + { warpsprite((short)i); movestat = 0; } + + if ((movestat != 0) || ((k&63) == 1)) + { + if (sprite[i].ang == (sprite[i].extra&2047)) + { + daang = (getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y)&2047); + daang = ((daang+(krand()&1023)-512)&2047); + sprite[i].extra = ((sprite[i].extra&(~2047))|daang); + } + if ((sprite[i].extra-sprite[i].ang)&1024) + { + sprite[i].ang = ((sprite[i].ang-32)&2047); + if (!((sprite[i].extra-sprite[i].ang)&1024)) sprite[i].ang = (sprite[i].extra&2047); + } + else + { + sprite[i].ang = ((sprite[i].ang+32)&2047); + if (((sprite[i].extra-sprite[i].ang)&1024)) sprite[i].ang = (sprite[i].extra&2047); + } + } + } + + for(i=headspritestat[10];i>=0;i=nexti) //EVILAL list + { + nexti = nextspritestat[i]; + + if (sprite[i].yrepeat < 38) continue; + if (sprite[i].yrepeat < 64) + { + sprite[i].xrepeat++; + sprite[i].yrepeat++; + continue; + } + + if ((nummoves-i)&statrate[10]) continue; + + //Choose a target player + mindist = 0x7fffffff; target = connecthead; + for(p=connecthead;p>=0;p=connectpoint2[p]) + { + dist = klabs(sprite[i].x-posx[p])+klabs(sprite[i].y-posy[p]); + if (dist < mindist) mindist = dist, target = p; + } + + k = (krand()&255); + + if ((sprite[i].lotag&32) && (k < 48)) //Al decides to reproduce + { + l = 0; + if ((sprite[i].lotag&64) && (k < 2)) //Give him a chance to reproduce without seeing you + l = 1; + else if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1) + l = 1; + if (l != 0) + { + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].cstat,sprite[i].shade,sprite[i].pal, + sprite[i].clipdist,38,38,sprite[i].xoffset,sprite[i].yoffset,sprite[i].picnum,krand()&2047,0,0,0,i, + sprite[i].sectnum,10,sprite[i].lotag,sprite[i].hitag,sprite[i].extra); + switch(krand()&31) //Mutations! + { + case 0: sprite[i].cstat ^= 2; break; + case 1: sprite[i].cstat ^= 512; break; + case 2: sprite[i].shade++; break; + case 3: sprite[i].shade--; break; + case 4: sprite[i].pal ^= 16; break; + case 5: case 6: case 7: sprite[i].lotag ^= (1<<(krand()&7)); break; + case 8: sprite[i].lotag = (krand()&255); break; + } + } + } + if (k >= 208+((sprite[i].lotag&128)>>2)) //Al decides to shoot bullet + { + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1) + { + wsayfollow("zipguns.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); + + spawnsprite(j,sprite[i].x,sprite[i].y, + sector[sprite[i].sectnum].floorz-(24<<8), + 0,0,0,16,32,32,0,0,BULLET, + (getangle(posx[target]-sprite[j].x, + posy[target]-sprite[j].y)+(krand()&15)-8)&2047, + sintable[(sprite[j].ang+512)&2047]>>6, + sintable[sprite[j].ang&2047]>>6, + ((posz[target]+(8<<8)-sprite[j].z)<<8) / + (ksqrt((posx[target]-sprite[j].x) * + (posx[target]-sprite[j].x) + + (posy[target]-sprite[j].y) * + (posy[target]-sprite[j].y))+1), + i,sprite[i].sectnum,6,0,0,0); + } + } + + //Move Al + l = (((sprite[i].lotag&3)+2)<<8); + if (sprite[i].lotag&4) l = -l; + dax = sintable[(sprite[i].ang+512)&2047]*l; + day = sintable[sprite[i].ang]*l; + + osectnum = sprite[i].sectnum; + movestat = movesprite((short)i,dax,day,0L,-8L<<8,-8L<<8,CLIPMASK0); + sprite[i].z = globloz; + if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) + { + warpsprite((short)i); + movestat = 0; + } + + if (sprite[i].lotag&16) + { + if (((k&124) >= 120) && (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1)) + sprite[i].ang = getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y); + else + sprite[i].ang = (krand()&2047); + } + + if (movestat != 0) + { + if ((k&2) && (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1)) + sprite[i].ang = getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y); + else + sprite[i].ang = (krand()&2047); + + if ((movestat&49152) == 49152) + if (sprite[movestat&16383].picnum == EVILAL) + if ((k&31) >= 30) + { + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[i].picnum = EVILALGRAVE; + sprite[i].cstat = 0; + sprite[i].xvel = (krand()&255)-128; + sprite[i].yvel = (krand()&255)-128; + sprite[i].zvel = (krand()&4095)-3072; + changespritestat(i,9); + } + + if (sprite[i].lotag&8) + if ((k&31) >= 30) + { + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[i].picnum = EVILALGRAVE; + sprite[i].cstat = 0; + sprite[i].xvel = (krand()&255)-128; + sprite[i].yvel = (krand()&255)-128; + sprite[i].zvel = (krand()&4095)-3072; + changespritestat(i,9); + } + + if (movestat == -1) + { + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[i].picnum = EVILALGRAVE; + sprite[i].cstat = 0; + sprite[i].xvel = (krand()&255)-128; + sprite[i].yvel = (krand()&255)-128; + sprite[i].zvel = (krand()&4095)-3072; + changespritestat(i,9); + } + } + } + + //Go through travelling bullet sprites + for(i=headspritestat[6];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + if ((nummoves-i)&statrate[6]) continue; + + //If the sprite is a bullet then... + if ((sprite[i].picnum == BULLET) || (sprite[i].picnum == GRABBER) || (sprite[i].picnum == MISSILE) || (sprite[i].picnum == BOMB)) + { + dax = ((((long)sprite[i].xvel)*TICSPERFRAME)<<12); + day = ((((long)sprite[i].yvel)*TICSPERFRAME)<<12); + daz = ((((long)sprite[i].zvel)*TICSPERFRAME)>>2); + if (sprite[i].picnum == BOMB) daz = 0; + + osectnum = sprite[i].sectnum; + hitobject = movesprite((short)i,dax,day,daz,4L<<8,4L<<8,CLIPMASK1); + if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) + { + warpsprite((short)i); + hitobject = 0; + } + + if (sprite[i].picnum == GRABBER) { // Andy did this (& Ken) !Homing! + checkgrabbertouchsprite(i,sprite[i].sectnum); + l = 0x7fffffff; + for (j = connecthead; j >= 0; j = connectpoint2[j]) // Players + if (j != (sprite[i].owner & (MAXSPRITES - 1))) + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,posx[j],posy[j],posz[j],cursectnum[j])) { + k = ksqrt(sqr(posx[j] - sprite[i].x) + sqr(posy[j] - sprite[i].y) + (sqr(posz[j] - sprite[i].z) >> 8)); + if (k < l) { + l = k; + dax = (posx[j] - sprite[i].x); + day = (posy[j] - sprite[i].y); + daz = (posz[j] - sprite[i].z); + } + } + for(j = headspritestat[1]; j >= 0; j = nextj) { // Active monsters + nextj = nextspritestat[j]; + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z,sprite[j].sectnum)) { + k = ksqrt(sqr(sprite[j].x - sprite[i].x) + sqr(sprite[j].y - sprite[i].y) + (sqr(sprite[j].z - sprite[i].z) >> 8)); + if (k < l) { + l = k; + dax = (sprite[j].x - sprite[i].x); + day = (sprite[j].y - sprite[i].y); + daz = (sprite[j].z - sprite[i].z); + } + } + } + for(j = headspritestat[2]; j >= 0; j = nextj) { // Inactive monsters + nextj = nextspritestat[j]; + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z,sprite[j].sectnum)) { + k = ksqrt(sqr(sprite[j].x - sprite[i].x) + sqr(sprite[j].y - sprite[i].y) + (sqr(sprite[j].z - sprite[i].z) >> 8)); + if (k < l) { + l = k; + dax = (sprite[j].x - sprite[i].x); + day = (sprite[j].y - sprite[i].y); + daz = (sprite[j].z - sprite[i].z); + } + } + } + if (l != 0x7fffffff) { + sprite[i].xvel = (divscale7(dax,l) + sprite[i].xvel); // 1/5 of velocity is homing, 4/5 is momentum + sprite[i].yvel = (divscale7(day,l) + sprite[i].yvel); // 1/5 of velocity is homing, 4/5 is momentum + sprite[i].zvel = (divscale7(daz,l) + sprite[i].zvel); // 1/5 of velocity is homing, 4/5 is momentum + l = ksqrt((sprite[i].xvel * sprite[i].xvel) + (sprite[i].yvel * sprite[i].yvel) + ((sprite[i].zvel * sprite[i].zvel) >> 8)); + sprite[i].xvel = divscale9(sprite[i].xvel,l); + sprite[i].yvel = divscale9(sprite[i].yvel,l); + sprite[i].zvel = divscale9(sprite[i].zvel,l); + sprite[i].ang = getangle(sprite[i].xvel,sprite[i].yvel); + } + } + + if (sprite[i].picnum == BOMB) + { + j = sprite[i].sectnum; + if ((sector[j].floorstat&2) && (sprite[i].z > globloz-(8<<8))) + { + k = sector[j].wallptr; + daang = getangle(wall[wall[k].point2].x-wall[k].x,wall[wall[k].point2].y-wall[k].y); + sprite[i].xvel += mulscale22(sintable[(daang+1024)&2047],sector[j].floorheinum); + sprite[i].yvel += mulscale22(sintable[(daang+512)&2047],sector[j].floorheinum); + } + } + + if (sprite[i].picnum == BOMB) + { + sprite[i].z += sprite[i].zvel; + sprite[i].zvel += (TICSPERFRAME<<7); + if (sprite[i].z < globhiz+(tilesizy[BOMB]<<6)) + { + sprite[i].z = globhiz+(tilesizy[BOMB]<<6); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + if (sprite[i].z > globloz-(tilesizy[BOMB]<<6)) + { + sprite[i].z = globloz-(tilesizy[BOMB]<<6); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + dax = sprite[i].xvel; day = sprite[i].yvel; + dist = dax*dax+day*day; + if (dist < 512) + { + bombexplode(i); + goto bulletisdeletedskip; + } + if (dist < 4096) + { + sprite[i].xrepeat = ((4096+2048)*16) / (dist+2048); + sprite[i].yrepeat = sprite[i].xrepeat; + sprite[i].xoffset = (krand()&15)-8; + sprite[i].yoffset = (krand()&15)-8; + } + if (mulscale30(krand(),dist) == 0) + { + sprite[i].xvel -= ksgn(sprite[i].xvel); + sprite[i].yvel -= ksgn(sprite[i].yvel); + sprite[i].zvel -= ksgn(sprite[i].zvel); + } + } + + //Check for bouncy objects before killing bullet + if ((hitobject&0xc000) == 16384) //Bullet hit a ceiling/floor + { + k = sector[hitobject&(MAXSECTORS-1)].wallptr; l = wall[k].point2; + daang = getangle(wall[l].x-wall[k].x,wall[l].y-wall[k].y); + + getzsofslope(hitobject&(MAXSECTORS-1),sprite[i].x,sprite[i].y,&k,&l); + if (sprite[i].z < ((k+l)>>1)) k = sector[hitobject&(MAXSECTORS-1)].ceilingheinum; + else k = sector[hitobject&(MAXSECTORS-1)].floorheinum; + + dax = mulscale14(k,sintable[(daang)&2047]); + day = mulscale14(k,sintable[(daang+1536)&2047]); + daz = 4096; + + k = sprite[i].xvel*dax+sprite[i].yvel*day+mulscale4(sprite[i].zvel,daz); + l = dax*dax+day*day+daz*daz; + if ((klabs(k)>>14) < l) + { + k = divscale17(k,l); + sprite[i].xvel -= mulscale16(dax,k); + sprite[i].yvel -= mulscale16(day,k); + sprite[i].zvel -= mulscale12(daz,k); + } + wsayfollow("bouncy.wav",4096L+(krand()&127)-64,255,&sprite[i].x,&sprite[i].y,1); + hitobject = 0; + sprite[i].owner = -1; //Bullet turns evil! + } + else if ((hitobject&0xc000) == 32768) //Bullet hit a wall + { + if (wall[hitobject&4095].lotag == 8) + { + dax = sprite[i].xvel; day = sprite[i].yvel; + if ((sprite[i].picnum != BOMB) || (dax*dax+day*day >= 512)) + { + k = (hitobject&4095); l = wall[k].point2; + j = getangle(wall[l].x-wall[k].x,wall[l].y-wall[k].y)+512; + + //k = cos(ang) * sin(ang) * 2 + k = mulscale13(sintable[(j+512)&2047],sintable[j&2047]); + //l = cos(ang * 2) + l = sintable[((j<<1)+512)&2047]; + + ox = sprite[i].xvel; oy = sprite[i].yvel; + dax = -ox; day = -oy; + sprite[i].xvel = dmulscale14(day,k,dax,l); + sprite[i].yvel = dmulscale14(dax,k,-day,l); + + if (sprite[i].picnum == BOMB) + { + sprite[i].xvel -= (sprite[i].xvel>>3); + sprite[i].yvel -= (sprite[i].yvel>>3); + sprite[i].zvel -= (sprite[i].zvel>>3); + } + ox -= sprite[i].xvel; oy -= sprite[i].yvel; + dist = ((ox*ox+oy*oy)>>8); + wsayfollow("bouncy.wav",4096L+(krand()&127)-64,min(dist,256),&sprite[i].x,&sprite[i].y,1); + hitobject = 0; + sprite[i].owner = -1; //Bullet turns evil! + } + } + } + else if ((hitobject&0xc000) == 49152) //Bullet hit a sprite + { + if (sprite[hitobject&4095].picnum == BOUNCYMAT) + { + if ((sprite[hitobject&4095].cstat&48) == 0) + { + sprite[i].xvel = -sprite[i].xvel; + sprite[i].yvel = -sprite[i].yvel; + sprite[i].zvel = -sprite[i].zvel; + dist = 255; + } + else if ((sprite[hitobject&4095].cstat&48) == 16) + { + j = sprite[hitobject&4095].ang; + + //k = cos(ang) * sin(ang) * 2 + k = mulscale13(sintable[(j+512)&2047],sintable[j&2047]); + //l = cos(ang * 2) + l = sintable[((j<<1)+512)&2047]; + + ox = sprite[i].xvel; oy = sprite[i].yvel; + dax = -ox; day = -oy; + sprite[i].xvel = dmulscale14(day,k,dax,l); + sprite[i].yvel = dmulscale14(dax,k,-day,l); + + ox -= sprite[i].xvel; oy -= sprite[i].yvel; + dist = ((ox*ox+oy*oy)>>8); + } + sprite[i].owner = -1; //Bullet turns evil! + wsayfollow("bouncy.wav",4096L+(krand()&127)-64,min(dist,256),&sprite[i].x,&sprite[i].y,1); + hitobject = 0; + } + } + + if (hitobject != 0) + { + if ((sprite[i].picnum == MISSILE) || (sprite[i].picnum == BOMB)) + { + if ((hitobject&0xc000) == 49152) + if (sprite[hitobject&4095].lotag == 5) //Basketball hoop + { + wsayfollow("niceshot.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + deletesprite((short)i); + goto bulletisdeletedskip; + } + + bombexplode(i); + goto bulletisdeletedskip; + } + + if ((hitobject&0xc000) == 16384) //Hits a ceiling / floor + { + wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + deletesprite((short)i); + goto bulletisdeletedskip; + } + else if ((hitobject&0xc000) == 32768) //Bullet hit a wall + { + if (wall[hitobject&4095].picnum == KENPICTURE) + { + if (waloff[MAXTILES-1] != 0) + wall[hitobject&4095].picnum = MAXTILES-1; + wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); //Ken says, "Hello... how are you today!" + } + else + wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + + deletesprite((short)i); + goto bulletisdeletedskip; + } + else if ((hitobject&0xc000) == 49152) //Bullet hit a sprite + { + if ((sprite[hitobject&4095].lotag == 5) && (sprite[i].picnum == GRABBER)) { // Basketball hoop (Andy's addition) + wsayfollow("niceshot.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + switch (krand() & 63) { + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: + sprite[i].picnum = COIN; break; + case 10: case 11: case 12: case 13: case 14: case 15: case 16: + sprite[i].picnum = DIAMONDS; break; + case 17: case 18: case 19: + sprite[i].picnum = COINSTACK; break; + case 20: case 21: case 22: case 23: + sprite[i].picnum = GIFTBOX; break; + case 24: case 25: + sprite[i].picnum = GRABCANNON; break; + case 26: case 27: + sprite[i].picnum = LAUNCHER; break; + case 28: case 29: case 30: + sprite[i].picnum = CANNON; break; + case 31: + sprite[i].picnum = AIRPLANE; break; + default: + deletesprite((short)i); + goto bulletisdeletedskip; + } + sprite[i].xvel = sprite[i].yvel = sprite[i].zvel = 0; + sprite[i].cstat &= ~0x83; //Should not clip, foot-z + changespritestat(i,12); + goto bulletisdeletedskip; + } + + //Check if bullet hit a player & find which player it was... + if (sprite[hitobject&4095].picnum == PLAYER) + for(j=connecthead;j>=0;j=connectpoint2[j]) + if (sprite[i].owner != j+4096) + if (playersprite[j] == (hitobject&4095)) + { + wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + if (sprite[i].picnum == GRABBER) { // Andy did this + k = ((sprite[i].xrepeat * sprite[i].yrepeat) * 3) >> 9; + changehealth((sprite[i].owner - 4096),k); + changehealth(j,-k); + } + else changehealth(j,-mulscale8(sprite[i].xrepeat,sprite[i].yrepeat)); + deletesprite((short)i); + goto bulletisdeletedskip; + } + + //Check if bullet hit any monsters... + j = (hitobject&4095); //j is the spritenum that the bullet (spritenum i) hit + if (sprite[i].owner != j) + { + switch(sprite[j].picnum) + { + case BROWNMONSTER: + if (sprite[j].lotag > 0) { + if (sprite[i].picnum == GRABBER) { // Andy did this + k = ((sprite[i].xrepeat * sprite[i].yrepeat) * 3) >> 9; + changehealth((sprite[i].owner - 4096),k); + sprite[j].lotag -= k; + } + sprite[j].lotag -= mulscale8(sprite[i].xrepeat,sprite[i].yrepeat); + } + if (sprite[j].lotag > 0) + { + if (sprite[j].lotag <= 25) sprite[j].cstat |= 2; + wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&sprite[i].x,&sprite[i].y,1); + } + else + { + wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[j].z += ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1); + sprite[j].picnum = GIFTBOX; + sprite[j].cstat &= ~0x83; //Should not clip, foot-z + + spawnsprite(k,sprite[j].x,sprite[j].y,sprite[j].z, + 0,-4,0,32,64,64,0,0,EXPLOSION,sprite[j].ang, + 0,0,0,j,sprite[j].sectnum,5,31,0,0); + //31=Time left for explosion to stay + + changespritestat(j,12); + } + deletesprite((short)i); + goto bulletisdeletedskip; + case EVILAL: + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[j].picnum = EVILALGRAVE; + sprite[j].cstat = 0; + sprite[j].xvel = (krand()&255)-128; + sprite[j].yvel = (krand()&255)-128; + sprite[j].zvel = (krand()&4095)-3072; + changespritestat(j,9); + + deletesprite((short)i); + goto bulletisdeletedskip; + case AL: + wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + sprite[j].xrepeat += 2; + sprite[j].yrepeat += 2; + if (sprite[j].yrepeat >= 38) + { + sprite[j].picnum = EVILAL; + //sprite[j].cstat |= 2; //Make him transluscent + changespritestat(j,10); + } + deletesprite((short)i); + goto bulletisdeletedskip; + default: + wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + deletesprite((short)i); + goto bulletisdeletedskip; + } + } + } + } + } +bulletisdeletedskip: continue; + } + + //Go through monster waiting for you list + for(i=headspritestat[2];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + if ((nummoves-i)&15) continue; + + //Use dot product to see if monster's angle is towards a player + for(p=connecthead;p>=0;p=connectpoint2[p]) + if (sintable[(sprite[i].ang+512)&2047]*(posx[p]-sprite[i].x) + sintable[sprite[i].ang&2047]*(posy[p]-sprite[i].y) >= 0) + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[p],posy[p],posz[p],cursectnum[p]) == 1) + { + changespritestat(i,1); + //if (sprite[i].lotag == 100) + //{ + wsayfollow("iseeyou.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); + // sprite[i].lotag = 99; + //} + } + } + + //Go through smoke sprites + for(i=headspritestat[3];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + sprite[i].z -= (TICSPERFRAME<<6); + sprite[i].lotag -= TICSPERFRAME; + if (sprite[i].lotag < 0) deletesprite(i); + } + + //Go through splash sprites + for(i=headspritestat[4];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + sprite[i].lotag -= TICSPERFRAME; + sprite[i].picnum = SPLASH + ((63-sprite[i].lotag)>>4); + if (sprite[i].lotag < 0) deletesprite(i); + } + + //Go through explosion sprites + for(i=headspritestat[5];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + sprite[i].lotag -= TICSPERFRAME; + if (sprite[i].lotag < 0) deletesprite(i); + } + + //Go through bomb spriral-explosion sprites + for(i=headspritestat[7];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + sprite[i].xrepeat = (sprite[i].lotag>>2); + sprite[i].yrepeat = (sprite[i].lotag>>2); + sprite[i].lotag -= (TICSPERFRAME<<2); + if (sprite[i].lotag < 0) { deletesprite(i); continue; } + + if ((nummoves-i)&statrate[7]) continue; + + sprite[i].x += ((sprite[i].xvel*TICSPERFRAME)>>2); + sprite[i].y += ((sprite[i].yvel*TICSPERFRAME)>>2); + sprite[i].z += ((sprite[i].zvel*TICSPERFRAME)>>2); + + sprite[i].zvel += (TICSPERFRAME<<9); + if (sprite[i].z < sector[sprite[i].sectnum].ceilingz+(4<<8)) + { + sprite[i].z = sector[sprite[i].sectnum].ceilingz+(4<<8); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + if (sprite[i].z > sector[sprite[i].sectnum].floorz-(4<<8)) + { + sprite[i].z = sector[sprite[i].sectnum].floorz-(4<<8); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + } + + //EVILALGRAVE shrinking list + for(i=headspritestat[9];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + sprite[i].xrepeat = (sprite[i].lotag>>2); + sprite[i].yrepeat = (sprite[i].lotag>>2); + sprite[i].lotag -= TICSPERFRAME; + if (sprite[i].lotag < 0) { deletesprite(i); continue; } + + if ((nummoves-i)&statrate[9]) continue; + + sprite[i].x += (sprite[i].xvel*TICSPERFRAME); + sprite[i].y += (sprite[i].yvel*TICSPERFRAME); + sprite[i].z += (sprite[i].zvel*TICSPERFRAME); + + sprite[i].zvel += (TICSPERFRAME<<8); + if (sprite[i].z < sector[sprite[i].sectnum].ceilingz) + { + sprite[i].z = sector[sprite[i].sectnum].ceilingz; + sprite[i].xvel -= (sprite[i].xvel>>2); + sprite[i].yvel -= (sprite[i].yvel>>2); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + if (sprite[i].z > sector[sprite[i].sectnum].floorz) + { + sprite[i].z = sector[sprite[i].sectnum].floorz; + sprite[i].xvel -= (sprite[i].xvel>>2); + sprite[i].yvel -= (sprite[i].yvel>>2); + sprite[i].zvel = -(sprite[i].zvel>>1); + } + } + + //Re-spawning sprite list + for(i=headspritestat[11];i>=0;i=nexti) + { + nexti = nextspritestat[i]; + + sprite[i].extra -= TICSPERFRAME; + if (sprite[i].extra < 0) + { + wsayfollow("warp.wav",6144L+(krand()&127)-64,128L,&sprite[i].x,&sprite[i].y,0); + sprite[i].cstat &= ~0x8000; + sprite[i].extra = -1; + changespritestat((short)i,0); + } + } +} + +void activatehitag(short dahitag) +{ + long i, nexti; + + for(i=0;i=0;i=nexti) + { + nexti = nextspritestat[i]; + if (sprite[i].hitag == dahitag) operatesprite(i); + } +} + +void bombexplode(long i) +{ + long j, nextj, k, daang, dax, day, dist; + + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,0,-4,0, + 32,64,64,0,0,EXPLOSION,sprite[i].ang, + 0,0,0,sprite[i].owner,sprite[i].sectnum,5,31,0,0); + //31=Time left for explosion to stay + + for(k=0;k<12;k++) + { + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z+(8<<8),2,-4,0, + 32,24,24,0,0,EXPLOSION,sprite[i].ang, + (krand()>>7)-256,(krand()>>7)-256,(krand()>>2)-8192, + sprite[i].owner,sprite[i].sectnum,7,96,0,0); + //96=Time left for smoke to be alive + } + + for(j=connecthead;j>=0;j=connectpoint2[j]) + { + dist = (posx[j]-sprite[i].x)*(posx[j]-sprite[i].x); + dist += (posy[j]-sprite[i].y)*(posy[j]-sprite[i].y); + dist += ((posz[j]-sprite[i].z)>>4)*((posz[j]-sprite[i].z)>>4); + if (dist < 4194304) + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[j],posy[j],posz[j],cursectnum[j]) == 1) + { + k = ((32768/((dist>>16)+4))>>5); + if (j == myconnectindex) + { + daang = getangle(posx[j]-sprite[i].x,posy[j]-sprite[i].y); + dax = ((k*sintable[(daang+512)&2047])>>14); + day = ((k*sintable[daang&2047])>>14); + fvel += ((dax*sintable[(ang[j]+512)&2047]+day*sintable[ang[j]&2047])>>14); + svel += ((day*sintable[(ang[j]+512)&2047]-dax*sintable[ang[j]&2047])>>14); + } + changehealth(j,-k); //if changehealth returns 1, you're dead + } + } + + for(k=1;k<=2;k++) //Check for hurting monsters + { + for(j=headspritestat[k];j>=0;j=nextj) + { + nextj = nextspritestat[j]; + + dist = (sprite[j].x-sprite[i].x)*(sprite[j].x-sprite[i].x); + dist += (sprite[j].y-sprite[i].y)*(sprite[j].y-sprite[i].y); + dist += ((sprite[j].z-sprite[i].z)>>4)*((sprite[j].z-sprite[i].z)>>4); + if (dist >= 4194304) continue; + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z-(tilesizy[sprite[j].picnum]<<7),sprite[j].sectnum) == 0) + continue; + if (sprite[j].picnum == BROWNMONSTER) + { + sprite[j].z += ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1); + sprite[j].picnum = GIFTBOX; + sprite[j].cstat &= ~0x83; //Should not clip, foot-z + changespritestat(j,12); + } + } + } + + for(j=headspritestat[10];j>=0;j=nextj) //Check for EVILAL's + { + nextj = nextspritestat[j]; + + dist = (sprite[j].x-sprite[i].x)*(sprite[j].x-sprite[i].x); + dist += (sprite[j].y-sprite[i].y)*(sprite[j].y-sprite[i].y); + dist += ((sprite[j].z-sprite[i].z)>>4)*((sprite[j].z-sprite[i].z)>>4); + if (dist >= 4194304) continue; + if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z-(tilesizy[sprite[j].picnum]<<7),sprite[j].sectnum) == 0) + continue; + + sprite[j].picnum = EVILALGRAVE; + sprite[j].cstat = 0; + sprite[j].xvel = (krand()&255)-128; + sprite[j].yvel = (krand()&255)-128; + sprite[j].zvel = (krand()&4095)-3072; + changespritestat(j,9); + } + + wsayfollow("blowup.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); + deletesprite((short)i); +} + +void processinput(short snum) +{ + long oldposx, oldposy, nexti; + long i, j, k, doubvel, xvect, yvect, goalz; + long dax, day, dax2, day2, odax, oday, odax2, oday2; + short startwall, endwall; + char *ptr; + + //SHARED KEYS: + //Movement code + if ((ssync[snum].fvel|ssync[snum].svel) != 0) + { + doubvel = (TICSPERFRAME<<((ssync[snum].bits&256)>0)); + + xvect = 0, yvect = 0; + if (ssync[snum].fvel != 0) + { + xvect += ((((long)ssync[snum].fvel)*doubvel*(long)sintable[(ang[snum]+512)&2047])>>3); + yvect += ((((long)ssync[snum].fvel)*doubvel*(long)sintable[ang[snum]&2047])>>3); + } + if (ssync[snum].svel != 0) + { + xvect += ((((long)ssync[snum].svel)*doubvel*(long)sintable[ang[snum]&2047])>>3); + yvect += ((((long)ssync[snum].svel)*doubvel*(long)sintable[(ang[snum]+1536)&2047])>>3); + } + if (flytime[snum] > lockclock) { xvect += xvect; yvect += yvect; } // DOuble flying speed + clipmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],xvect,yvect,128L,4<<8,4<<8,CLIPMASK0); + revolvedoorstat[snum] = 1; + } + else + { + revolvedoorstat[snum] = 0; + } + + sprite[playersprite[snum]].cstat &= ~1; + //Push player away from walls if clipmove doesn't work + if (pushmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],128L,4<<8,4<<8,CLIPMASK0) < 0) + changehealth(snum,-1000); //If this screws up, then instant death!!! + + // Getzrange returns the highest and lowest z's for an entire box, + // NOT just a point. This prevents you from falling off cliffs + // when you step only slightly over the cliff. + getzrange(posx[snum],posy[snum],posz[snum],cursectnum[snum],&globhiz,&globhihit,&globloz,&globlohit,128L,CLIPMASK0); + sprite[playersprite[snum]].cstat |= 1; + + if (ssync[snum].avel != 0) //ang += avel * constant + { //ENGINE calculates avel for you + doubvel = TICSPERFRAME; + if ((ssync[snum].bits&256) > 0) //Lt. shift makes turn velocity 50% faster + doubvel += (TICSPERFRAME>>1); + ang[snum] += ((((long)ssync[snum].avel)*doubvel)>>4); + ang[snum] &= 2047; + } + + if (health[snum] < 0) + { + health[snum] -= TICSPERFRAME; + if (health[snum] <= -160) + { + hvel[snum] = 0; + if (snum == myconnectindex) + fvel = 0, svel = 0, avel = 0, keystatus[3] = 1; + + deaths[snum]++; + health[snum] = 100; + numbombs[snum] = 0; + numgrabbers[snum] = 0; + nummissiles[snum] = 0; + flytime[snum] = 0; + + findrandomspot(&posx[snum],&posy[snum],&cursectnum[snum]); + posz[snum] = getflorzofslope(cursectnum[snum],posx[snum],posy[snum])-(1<<8); + horiz[snum] = 100; + ang[snum] = (krand()&2047); + + sprite[playersprite[snum]].x = posx[snum]; + sprite[playersprite[snum]].y = posy[snum]; + sprite[playersprite[snum]].z = posz[snum]+EYEHEIGHT; + sprite[playersprite[snum]].picnum = PLAYER; + sprite[playersprite[snum]].ang = ang[snum]; + sprite[playersprite[snum]].xrepeat = 64; + sprite[playersprite[snum]].yrepeat = 64; + changespritesect(playersprite[snum],cursectnum[snum]); + + drawstatusbar(snum); // Andy did this + + i = playersprite[snum]; + wsayfollow("zipguns.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); + for(k=0;k<16;k++) + { + spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z+(8<<8),2,-4,0, + 32,24,24,0,0,EXPLOSION,sprite[i].ang, + (krand()&511)-256,(krand()&511)-256,(krand()&16384)-8192, + sprite[i].owner,sprite[i].sectnum,7,96,0,0); + //96=Time left for smoke to be alive + } + } + else + { + sprite[playersprite[snum]].xrepeat = max(((128+health[snum])>>1),0); + sprite[playersprite[snum]].yrepeat = max(((128+health[snum])>>1),0); + + hvel[snum] += (TICSPERFRAME<<2); + horiz[snum] = max(horiz[snum]-4,0); + posz[snum] += hvel[snum]; + if (posz[snum] > globloz-(4<<8)) + { + posz[snum] = globloz-(4<<8); + horiz[snum] = min(horiz[snum]+5,200); + hvel[snum] = 0; + } + } + } + + if (((ssync[snum].bits&8) > 0) && (horiz[snum] > 100-(200>>1))) horiz[snum] -= 4; //- + if (((ssync[snum].bits&4) > 0) && (horiz[snum] < 100+(200>>1))) horiz[snum] += 4; //+ + + goalz = globloz-EYEHEIGHT; + if (sector[cursectnum[snum]].lotag == 4) //slime sector + if ((globlohit&0xc000) != 49152) //You're not on a sprite + { + goalz = globloz-(8<<8); + if (posz[snum] >= goalz-(2<<8)) + { + clipmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],-TICSPERFRAME<<14,-TICSPERFRAME<<14,128L,4<<8,4<<8,CLIPMASK0); + + if (slimesoundcnt[snum] >= 0) + { + slimesoundcnt[snum] -= TICSPERFRAME; + while (slimesoundcnt[snum] < 0) + { + slimesoundcnt[snum] += 120; + wsayfollow("slime.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + } + } + } + } + if (goalz < globhiz+(16<<8)) //ceiling&floor too close + goalz = ((globloz+globhiz)>>1); + //goalz += mousz; + if (health[snum] >= 0) + { + if ((ssync[snum].bits&1) > 0) //A (stand high) + { + if (flytime[snum] <= lockclock) + { + if (posz[snum] >= globloz-(32<<8)) + { + goalz -= (16<<8); + if (ssync[snum].bits&256) goalz -= (24<<8); + } + } + else + { + hvel[snum] -= 192; + if (ssync[snum].bits&256) hvel[snum] -= 192; + } + } + if ((ssync[snum].bits&2) > 0) //Z (stand low) + { + if (flytime[snum] <= lockclock) + { + goalz += (12<<8); + if (ssync[snum].bits&256) goalz += (12<<8); + } + else + { + hvel[snum] += 192; + if (ssync[snum].bits&256) hvel[snum] += 192; + } + } + } + + if (flytime[snum] <= lockclock) + { + if (posz[snum] < goalz) + hvel[snum] += (TICSPERFRAME<<4); + else + hvel[snum] = (((goalz-posz[snum])*TICSPERFRAME)>>5); + } + else + { + hvel[snum] -= (hvel[snum]>>2); + hvel[snum] -= ksgn(hvel[snum]); + } + + posz[snum] += hvel[snum]; + if (posz[snum] > globloz-(4<<8)) posz[snum] = globloz-(4<<8), hvel[snum] = 0; + if (posz[snum] < globhiz+(4<<8)) posz[snum] = globhiz+(4<<8), hvel[snum] = 0; + + if (dimensionmode[snum] != 3) + { + if (((ssync[snum].bits&32) > 0) && (zoom[snum] > 48)) zoom[snum] -= (zoom[snum]>>4); + if (((ssync[snum].bits&16) > 0) && (zoom[snum] < 4096)) zoom[snum] += (zoom[snum]>>4); + } + + //Update sprite representation of player + // -should be after movement, but before shooting code + setsprite(playersprite[snum],posx[snum],posy[snum],posz[snum]+EYEHEIGHT); + sprite[playersprite[snum]].ang = ang[snum]; + + if (health[snum] >= 0) + { + if ((cursectnum[snum] < 0) || (cursectnum[snum] >= numsectors)) + { //How did you get in the wrong sector? + wsayfollow("ouch.wav",4096L+(krand()&127)-64,64L,&posx[snum],&posy[snum],1); + changehealth(snum,-TICSPERFRAME); + } + else if (globhiz+(8<<8) > globloz) + { //Ceiling and floor are smooshing you! + wsayfollow("ouch.wav",4096L+(krand()&127)-64,64L,&posx[snum],&posy[snum],1); + changehealth(snum,-TICSPERFRAME); + } + } + + if ((waterfountainwall[snum] >= 0) && (health[snum] >= 0)) + if ((wall[neartagwall].lotag != 7) || ((ssync[snum].bits&1024) == 0)) + { + i = waterfountainwall[snum]; + if (wall[i].overpicnum == USEWATERFOUNTAIN) + wall[i].overpicnum = WATERFOUNTAIN; + else if (wall[i].picnum == USEWATERFOUNTAIN) + wall[i].picnum = WATERFOUNTAIN; + + waterfountainwall[snum] = -1; + } + + if ((ssync[snum].bits&1024) > 0) //Space bar + { + //Continuous triggers... + + neartag(posx[snum],posy[snum],posz[snum],cursectnum[snum],ang[snum],&neartagsector,&neartagwall,&neartagsprite,&neartaghitdist,1024L,3); + if (neartagsector == -1) + { + i = cursectnum[snum]; + if ((sector[i].lotag|sector[i].hitag) != 0) + neartagsector = i; + } + + if (wall[neartagwall].lotag == 7) //Water fountain + { + if (wall[neartagwall].overpicnum == WATERFOUNTAIN) + { + wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + wall[neartagwall].overpicnum = USEWATERFOUNTAIN; + waterfountainwall[snum] = neartagwall; + } + else if (wall[neartagwall].picnum == WATERFOUNTAIN) + { + wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + wall[neartagwall].picnum = USEWATERFOUNTAIN; + waterfountainwall[snum] = neartagwall; + } + + if (waterfountainwall[snum] >= 0) + { + waterfountaincnt[snum] -= TICSPERFRAME; + while (waterfountaincnt[snum] < 0) + { + waterfountaincnt[snum] += 120; + wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); + changehealth(snum,2); + } + } + } + + //1-time triggers... + if ((oflags[snum]&1024) == 0) + { + if (neartagsector >= 0) + if (sector[neartagsector].hitag == 0) + operatesector(neartagsector); + + if (neartagwall >= 0) + if (wall[neartagwall].lotag == 2) //Switch + { + activatehitag(wall[neartagwall].hitag); + + j = wall[neartagwall].overpicnum; + if (j == SWITCH1ON) //1-time switch + { + wall[neartagwall].overpicnum = GIFTBOX; + wall[neartagwall].lotag = 0; + wall[neartagwall].hitag = 0; + } + if (j == GIFTBOX) //1-time switch + { + wall[neartagwall].overpicnum = SWITCH1ON; + wall[neartagwall].lotag = 0; + wall[neartagwall].hitag = 0; + } + if (j == SWITCH2ON) wall[neartagwall].overpicnum = SWITCH2OFF; + if (j == SWITCH2OFF) wall[neartagwall].overpicnum = SWITCH2ON; + if (j == SWITCH3ON) wall[neartagwall].overpicnum = SWITCH3OFF; + if (j == SWITCH3OFF) wall[neartagwall].overpicnum = SWITCH3ON; + + i = wall[neartagwall].point2; + dax = ((wall[neartagwall].x+wall[i].x)>>1); + day = ((wall[neartagwall].y+wall[i].y)>>1); + wsayfollow("switch.wav",4096L+(krand()&255)-128,256L,&dax,&day,0); + } + + if (neartagsprite >= 0) + { + if (sprite[neartagsprite].lotag == 1) + { //if you're shoving innocent little AL around, he gets mad! + if (sprite[neartagsprite].picnum == AL) + { + sprite[neartagsprite].picnum = EVILAL; + sprite[neartagsprite].cstat |= 2; //Make him transluscent + sprite[neartagsprite].xrepeat = 38; + sprite[neartagsprite].yrepeat = 38; + changespritestat(neartagsprite,10); + } + } + if (sprite[neartagsprite].lotag == 4) + { + activatehitag(sprite[neartagsprite].hitag); + + j = sprite[neartagsprite].picnum; + if (j == SWITCH1ON) //1-time switch + { + sprite[neartagsprite].picnum = GIFTBOX; + sprite[neartagsprite].lotag = 0; + sprite[neartagsprite].hitag = 0; + } + if (j == GIFTBOX) //1-time switch + { + sprite[neartagsprite].picnum = SWITCH1ON; + sprite[neartagsprite].lotag = 0; + sprite[neartagsprite].hitag = 0; + } + if (j == SWITCH2ON) sprite[neartagsprite].picnum = SWITCH2OFF; + if (j == SWITCH2OFF) sprite[neartagsprite].picnum = SWITCH2ON; + if (j == SWITCH3ON) sprite[neartagsprite].picnum = SWITCH3OFF; + if (j == SWITCH3OFF) sprite[neartagsprite].picnum = SWITCH3ON; + + dax = sprite[neartagsprite].x; + day = sprite[neartagsprite].y; + wsayfollow("switch.wav",4096L+(krand()&255)-128,256L,&dax,&day,0); + } + } + } + } + + if ((ssync[snum].bits & 2048) > 0) { // Shoot a bullet + if ((numbombs[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 2) && (myconnectindex == snum)) + locselectedgun = 0; + if ((nummissiles[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 3) && (myconnectindex == snum)) + locselectedgun = 1; + if ((numgrabbers[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 4) && (myconnectindex == snum)) + locselectedgun = 1; + + if ((health[snum] >= 0) || ((krand() & 127) > -health[snum])) + switch((ssync[snum].bits >> 13) & 7) { + case 0: + if (lockclock > lastchaingun[snum]+8) { + lastchaingun[snum] = lockclock; + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],0); + } + break; + case 1: + if ((oflags[snum] & 2048) == 0) + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],1); + break; + case 2: + if ((oflags[snum] & 2048) == 0) + if (numbombs[snum] > 0) { + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],2); + changenumbombs(snum,-1); + } + break; + case 3: + if ((oflags[snum] & 2048) == 0) + if (nummissiles[snum] > 0) { + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],3); + changenummissiles(snum,-1); + } + break; + case 4: + if ((oflags[snum] & 2048) == 0) + if (numgrabbers[snum] > 0) { + shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],4); + changenumgrabbers(snum,-1); + } + break; + } + } + + if ((ssync[snum].bits&4096) > (oflags[snum]&4096)) //Keypad enter + { + dimensionmode[snum]++; + if (dimensionmode[snum] > 3) dimensionmode[snum] = 1; + } + + oflags[snum] = ssync[snum].bits; +} + +void view(short snum, long *vx, long *vy, long *vz, short *vsectnum, short ang, long horiz) +{ + spritetype *sp; + long i, nx, ny, nz, hx, hy, hz, hitx, hity, hitz; + short bakcstat, hitsect, hitwall, hitsprite, daang; + + nx = (sintable[(ang+1536)&2047]>>4); + ny = (sintable[(ang+1024)&2047]>>4); + nz = (horiz-100)*128; + + sp = &sprite[snum]; + + bakcstat = sp->cstat; + sp->cstat &= (short)~0x101; + + updatesectorz(*vx,*vy,*vz,vsectnum); + hitscan(*vx,*vy,*vz,*vsectnum,nx,ny,nz,&hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); + hx = hitx-(*vx); hy = hity-(*vy); + if (klabs(nx)+klabs(ny) > klabs(hx)+klabs(hy)) + { + *vsectnum = hitsect; + if (hitwall >= 0) + { + daang = getangle(wall[wall[hitwall].point2].x-wall[hitwall].x, + wall[wall[hitwall].point2].y-wall[hitwall].y); + + i = nx*sintable[daang]+ny*sintable[(daang+1536)&2047]; + if (klabs(nx) > klabs(ny)) hx -= mulscale28(nx,i); + else hy -= mulscale28(ny,i); + } + else if (hitsprite < 0) + { + if (klabs(nx) > klabs(ny)) hx -= (nx>>5); + else hy -= (ny>>5); + } + if (klabs(nx) > klabs(ny)) i = divscale16(hx,nx); + else i = divscale16(hy,ny); + if (i < cameradist) cameradist = i; + } + *vx = (*vx)+mulscale16(nx,cameradist); + *vy = (*vy)+mulscale16(ny,cameradist); + *vz = (*vz)+mulscale16(nz,cameradist); + + updatesectorz(*vx,*vy,*vz,vsectnum); + + sp->cstat = bakcstat; +} + +#if 0 // JBF: now in the engine +void updatesectorz(long x, long y, long z, short *sectnum) +{ + walltype *wal; + long i, j, cz, fz; + + getzsofslope(*sectnum,x,y,&cz,&fz); + if ((z >= cz) && (z <= fz)) + if (inside(x,y,*sectnum) != 0) return; + + if ((*sectnum >= 0) && (*sectnum < numsectors)) + { + wal = &wall[sector[*sectnum].wallptr]; + j = sector[*sectnum].wallnum; + do + { + i = wal->nextsector; + if (i >= 0) + { + getzsofslope(i,x,y,&cz,&fz); + if ((z >= cz) && (z <= fz)) + if (inside(x,y,(short)i) == 1) + { *sectnum = i; return; } + } + wal++; j--; + } while (j != 0); + } + + for(i=numsectors-1;i>=0;i--) + { + getzsofslope(i,x,y,&cz,&fz); + if ((z >= cz) && (z <= fz)) + if (inside(x,y,(short)i) == 1) + { *sectnum = i; return; } + } + + *sectnum = -1; +} +#endif + +void drawscreen(short snum, long dasmoothratio) +{ + long i, j, k=0, l, charsperline, tempint; + long x1, y1, x2, y2, ox1, oy1, ox2, oy2, dist, maxdist; + long cposx, cposy, cposz, choriz, czoom, tposx, tposy; + long tiltlock, *intptr, ovisibility, oparallaxvisibility; + short cang, tang, csect; + char ch, *ptr, *ptr2, *ptr3, *ptr4; + spritetype *tspr; + + smoothratio = max(min(dasmoothratio,65536),0); + + dointerpolations(); + + if ((snum == myconnectindex) && ((networkmode == 1) || (myconnectindex != connecthead))) + { + cposx = omyx+mulscale16(myx-omyx,smoothratio); + cposy = omyy+mulscale16(myy-omyy,smoothratio); + cposz = omyz+mulscale16(myz-omyz,smoothratio); + choriz = omyhoriz+mulscale16(myhoriz-omyhoriz,smoothratio); + cang = omyang+mulscale16((long)(((myang+1024-omyang)&2047)-1024),smoothratio); + } + else + { + cposx = oposx[snum]+mulscale16(posx[snum]-oposx[snum],smoothratio); + cposy = oposy[snum]+mulscale16(posy[snum]-oposy[snum],smoothratio); + cposz = oposz[snum]+mulscale16(posz[snum]-oposz[snum],smoothratio); + choriz = ohoriz[snum]+mulscale16(horiz[snum]-ohoriz[snum],smoothratio); + cang = oang[snum]+mulscale16(((ang[snum]+1024-oang[snum])&2047)-1024,smoothratio); + } + czoom = ozoom[snum]+mulscale16(zoom[snum]-ozoom[snum],smoothratio); + + setears(cposx,cposy,(long)sintable[(cang+512)&2047]<<14,(long)sintable[cang&2047]<<14); + + if (dimensionmode[myconnectindex] == 3) + { + tempint = screensize; + + if (((loc.bits&32) > (screensizeflag&32)) && (screensize > 64)) + { + ox1 = ((xdim-screensize)>>1); + ox2 = ox1+screensize-1; + oy1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + oy2 = oy1 + scale(screensize,ydim-32,xdim)-1; + screensize -= (screensize>>3); + + if (tempint > xdim) + { + screensize = xdim; + + flushperms(); + + rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + i = ((xdim-320)>>1); + while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + i = ((xdim-320)>>1)+320; + while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8; + if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4; + + drawstatusbar(screenpeek); // Andy did this + } + + x1 = ((xdim-screensize)>>1); + x2 = x1+screensize-1; + y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + y2 = y1 + scale(screensize,ydim-32,xdim)-1; + setview(x1,y1,x2,y2); + + // (ox1,oy1)⁄ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø + // ≥ (x1,y1) ≥ + // ≥ ⁄ƒƒƒƒƒø ≥ + // ≥ ≥ ≥ ≥ + // ≥ ¿ƒƒƒƒƒŸ ≥ + // ≥ (x2,y2) ≥ + // ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ(ox2,oy2) + + drawtilebackground(0L,0L,BACKGROUND,8,ox1,oy1,x1-1,oy2,0); + drawtilebackground(0L,0L,BACKGROUND,8,x2+1,oy1,ox2,oy2,0); + drawtilebackground(0L,0L,BACKGROUND,8,x1,oy1,x2,y1-1,0); + drawtilebackground(0L,0L,BACKGROUND,8,x1,y2+1,x2,oy2,0); + } + if (((loc.bits&16) > (screensizeflag&16)) && (screensize <= xdim)) + { + screensize += (screensize>>3); + if ((screensize > xdim) && (tempint == xdim)) + { + screensize = xdim+1; + x1 = 0; y1 = 0; + x2 = xdim-1; y2 = ydim-1; + } + else + { + if (screensize > xdim) screensize = xdim; + x1 = ((xdim-screensize)>>1); + x2 = x1+screensize-1; + y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + y2 = y1 + scale(screensize,ydim-32,xdim)-1; + } + setview(x1,y1,x2,y2); + } + screensizeflag = loc.bits; + } + + if (dimensionmode[snum] != 2) + { + if ((numplayers > 1) && (option[4] == 0)) + { + //Do not draw other views constantly if they're staying still + //It's a shame this trick will only work in screen-buffer mode + //At least screen-buffer mode covers all the HI hi-res modes + //if (vidoption == 2) + //{ + for(i=connecthead;i>=0;i=connectpoint2[i]) frame2draw[i] = 0; + frame2draw[snum] = 1; + + //2-1,3-1,4-2 + //5-2,6-2,7-2,8-3,9-3,10-3,11-3,12-4,13-4,14-4,15-4,16-5 + x1 = posx[snum]; y1 = posy[snum]; + for(j=(numplayers>>2)+1;j>0;j--) + { + maxdist = 0x80000000; + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (frame2draw[i] == 0) + { + x2 = posx[i]-x1; y2 = posy[i]-y1; + dist = dmulscale12(x2,x2,y2,y2); + + if (dist < 64) dist = 16384; + else if (dist > 16384) dist = 64; + else dist = 1048576 / dist; + + dist *= frameskipcnt[i]; + + //Increase frame rate if screen is moving + if ((posx[i] != oposx[i]) || (posy[i] != oposy[i]) || + (posz[i] != oposz[i]) || (ang[i] != oang[i]) || + (horiz[i] != ohoriz[i])) dist += dist; + + if (dist > maxdist) maxdist = dist, k = i; + } + + for(i=connecthead;i>=0;i=connectpoint2[i]) + frameskipcnt[i] += (frameskipcnt[i]>>3)+1; + frameskipcnt[k] = 0; + + frame2draw[k] = 1; + } + //} + //else + //{ + // for(i=connecthead;i>=0;i=connectpoint2[i]) frame2draw[i] = 1; + //} + + for(i=connecthead,j=0;i>=0;i=connectpoint2[i],j++) + if (frame2draw[i] != 0) + { + if (numplayers <= 4) + { + switch(j) + { + case 0: setview(0,0,(xdim>>1)-1,(ydim>>1)-1); break; + case 1: setview((xdim>>1),0,xdim-1,(ydim>>1)-1); break; + case 2: setview(0,(ydim>>1),(xdim>>1)-1,ydim-1); break; + case 3: setview((xdim>>1),(ydim>>1),xdim-1,ydim-1); break; + } + } + else + { + switch(j) + { + case 0: setview(0,0,(xdim>>2)-1,(ydim>>2)-1); break; + case 1: setview(xdim>>2,0,(xdim>>1)-1,(ydim>>2)-1); break; + case 2: setview(xdim>>1,0,xdim-(xdim>>2)-1,(ydim>>2)-1); break; + case 3: setview(xdim-(xdim>>2),0,xdim-1,(ydim>>2)-1); break; + case 4: setview(0,ydim>>2,(xdim>>2)-1,(ydim>>1)-1); break; + case 5: setview(xdim>>2,ydim>>2,(xdim>>1)-1,(ydim>>1)-1); break; + case 6: setview(xdim>>1,ydim>>2,xdim-(xdim>>2)-1,(ydim>>1)-1); break; + case 7: setview(xdim-(xdim>>2),ydim>>2,xdim-1,(ydim>>1)-1); break; + case 8: setview(0,ydim>>1,(xdim>>2)-1,ydim-(ydim>>2)-1); break; + case 9: setview(xdim>>2,ydim>>1,(xdim>>1)-1,ydim-(ydim>>2)-1); break; + case 10: setview(xdim>>1,ydim>>1,xdim-(xdim>>2)-1,ydim-(ydim>>2)-1); break; + case 11: setview(xdim-(xdim>>2),ydim>>1,xdim-1,ydim-(ydim>>2)-1); break; + case 12: setview(0,ydim-(ydim>>2),(xdim>>2)-1,ydim-1); break; + case 13: setview(xdim>>2,ydim-(ydim>>2),(xdim>>1)-1,ydim-1); break; + case 14: setview(xdim>>1,ydim-(ydim>>2),xdim-(xdim>>2)-1,ydim-1); break; + case 15: setview(xdim-(xdim>>2),ydim-(ydim>>2),xdim-1,ydim-1); break; + } + } + + if (i == snum) + { + sprite[playersprite[snum]].cstat |= 0x8000; + drawrooms(cposx,cposy,cposz,cang,choriz,cursectnum[i]); + sprite[playersprite[snum]].cstat &= ~0x8000; + analyzesprites(cposx,cposy); + } + else + { + sprite[playersprite[i]].cstat |= 0x8000; + drawrooms(posx[i],posy[i],posz[i],ang[i],horiz[i],cursectnum[i]); + sprite[playersprite[i]].cstat &= ~0x8000; + analyzesprites(posx[i],posy[i]); + } + drawmasks(); + if ((numgrabbers[i] > 0) || (nummissiles[i] > 0) || (numbombs[i] > 0)) + rotatesprite(160<<16,184L<<16,65536,0,GUNONBOTTOM,sector[cursectnum[i]].floorshade,0,2,windowx1,windowy1,windowx2,windowy2); + + if (lockclock < 384) + { + if (lockclock < 128) + rotatesprite(320<<15,200<<15,lockclock<<9,lockclock<<4,DEMOSIGN,(128-lockclock)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); + else if (lockclock < 256) + rotatesprite(320<<15,200<<15,65536,0,DEMOSIGN,0,0,2,windowx1,windowy1,windowx2,windowy2); + else + rotatesprite(320<<15,200<<15,(384-lockclock)<<9,lockclock<<4,DEMOSIGN,(lockclock-256)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); + } + + if (health[i] <= 0) + rotatesprite(320<<15,200<<15,(-health[i])<<11,(-health[i])<<5,NO,0,0,2,windowx1,windowy1,windowx2,windowy2); + } + } + else + { + //Init for screen rotation + if (getrendermode() == 0) { // JBF 20031220 + tiltlock = screentilt; + if ((tiltlock) || (detailmode)) + { + walock[MAXTILES-2] = 255; + if (waloff[MAXTILES-2] == 0) + allocache(&waloff[MAXTILES-2],320L*320L,&walock[MAXTILES-2]); + if ((tiltlock&1023) == 0) + setviewtotile(MAXTILES-2,200L>>detailmode,320L>>detailmode); + else + setviewtotile(MAXTILES-2,320L>>detailmode,320L>>detailmode); + if ((tiltlock&1023) == 512) + { //Block off unscreen section of 90¯ tilted screen + j = ((320-60)>>detailmode); + for(i=(60>>detailmode)-1;i>=0;i--) + { + startumost[i] = 1; startumost[i+j] = 1; + startdmost[i] = 0; startdmost[i+j] = 0; + } + } + + i = (tiltlock&511); if (i > 256) i = 512-i; + i = sintable[i+512]*8 + sintable[i]*5L; + setaspect(i>>1,yxaspect); + } + } else { + tiltlock = screentilt; + // Ken loves to interpolate + setrollangle(oscreentilt + mulscale16(((screentilt-oscreentilt+1024)&2047)-1024,smoothratio)); + } + + if ((gotpic[FLOORMIRROR>>3]&(1<<(FLOORMIRROR&7))) > 0) + { + dist = 0x7fffffff; i = 0; + for(k=floormirrorcnt-1;k>=0;k--) + { + j = klabs(wall[sector[floormirrorsector[k]].wallptr].x-cposx); + j += klabs(wall[sector[floormirrorsector[k]].wallptr].y-cposy); + if (j < dist) dist = j, i = k; + } + + //if (cposz > sector[floormirrorsector[i]].ceilingz) i = 1-i; //SOS + + j = floormirrorsector[i]; + + if (cameradist < 0) sprite[playersprite[snum]].cstat |= 0x8000; + drawrooms(cposx,cposy,(sector[j].floorz<<1)-cposz,cang,201-choriz,j); //SOS + //drawrooms(cposx,cposy,cposz,cang,choriz,j+MAXSECTORS); //SOS + sprite[playersprite[snum]].cstat &= ~0x8000; + analyzesprites(cposx,cposy); + drawmasks(); + + //Temp horizon + if (getrendermode() == 0) { + l = scale(choriz-100,windowx2-windowx1,320)+((windowy1+windowy2)>>1); + begindrawing(); //{{{ + for(y1=windowy1,y2=windowy2;y1>2,31)<<8); + ptr4 = palookup[18]; + ptr4 += (min(klabs(y2-l)>>2,31)<<8); + + j = sintable[((y2+totalclock)<<6)&2047]; + j += sintable[((y2-totalclock)<<7)&2047]; + j >>= 14; + + //ptr2 += j; + + //for(x1=windowx1;x1<=windowx2;x1++) + // { ch = ptr[x1]; ptr[x1] = ptr3[ptr2[x1]]; ptr2[x1] = ptr4[ch]; } + + ox1 = windowx1-min(j,0); + ox2 = windowx2-max(j,0); + + for(x1=windowx1;x1>3] &= ~(1<<(FLOORMIRROR&7)); + } + + if (gotpic[DAYSKY>>3]&(1<<(DAYSKY&7))) + { + gotpic[DAYSKY>>3] &= ~(1<<(DAYSKY&7)); + pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; + } + else if (gotpic[NIGHTSKY>>3]&(1<<(NIGHTSKY&7))) + { + gotpic[NIGHTSKY>>3] &= ~(1<<(NIGHTSKY&7)); + pskyoff[0] = 0; pskyoff[1] = 0; pskyoff[2] = 0; pskyoff[3] = 0; + pskyoff[4] = 0; pskyoff[5] = 0; pskyoff[6] = 0; pskyoff[7] = 0; + pskybits = 3; + } + + + //Over the shoulder mode + csect = cursectnum[snum]; + if (cameradist >= 0) + { + cang += cameraang; + view(playersprite[snum],&cposx,&cposy,&cposz,&csect,cang,choriz); + } + + //WARNING! Assuming (MIRRORLABEL&31) = 0 and MAXMIRRORS = 64 + intptr = (long *)&gotpic[MIRRORLABEL>>3]; // CHECK! + if (intptr[0]|intptr[1]) + for(i=MAXMIRRORS-1;i>=0;i--) + if (gotpic[(i+MIRRORLABEL)>>3]&(1<<(i&7))) + { + gotpic[(i+MIRRORLABEL)>>3] &= ~(1<<(i&7)); + + //Prepare drawrooms for drawing mirror and calculate reflected + //position into tposx, tposy, and tang (tposz == cposz) + //Must call preparemirror before drawrooms and + // completemirror after drawrooms + preparemirror(cposx,cposy,cposz,cang,choriz, + mirrorwall[i],mirrorsector[i],&tposx,&tposy,&tang); + + ovisibility = visibility; + oparallaxvisibility = parallaxvisibility; + visibility <<= 1; + parallaxvisibility <<= 1; + ptr = palookup[0]; palookup[0] = palookup[17]; palookup[17] = ptr; + + drawrooms(tposx,tposy,cposz,tang,choriz,mirrorsector[i]|MAXSECTORS); + for(j=0,tspr=&tsprite[0];jcstat&48) == 0) tspr->cstat |= 4; + analyzesprites(tposx,tposy); + drawmasks(); + + ptr = palookup[0]; palookup[0] = palookup[17]; palookup[17] = ptr; + visibility = ovisibility; + parallaxvisibility = oparallaxvisibility; + + completemirror(); //Reverse screen x-wise in this function + + break; + } + + if (cameradist < 0) sprite[playersprite[snum]].cstat |= 0x8000; + drawrooms(cposx,cposy,cposz,cang,choriz,csect); + sprite[playersprite[snum]].cstat &= ~0x8000; + analyzesprites(cposx,cposy); + drawmasks(); + + //Finish for screen rotation + if (getrendermode() == 0) { // JBF 20031220 + if ((tiltlock) || (detailmode)) + { + setviewback(); + i = (tiltlock&511); if (i > 256) i = 512-i; + i = sintable[i+512]*8 + sintable[i]*5L; + if (detailmode == 0) i >>= 1; + rotatesprite(320<<15,200<<15,i,tiltlock+512,MAXTILES-2,0,0,2+4+64,windowx1,windowy1,windowx2,windowy2); + walock[MAXTILES-2] = 1; + } + } + + if (((numgrabbers[screenpeek] > 0) || (nummissiles[screenpeek] > 0) || (numbombs[screenpeek] > 0)) && (cameradist < 0)) + { + //Reset startdmost to bottom of screen + if ((windowx1 == 0) && (windowx2 == 319) && (yxaspect == 65536) && (tiltlock == 0)) + { + x1 = 160L-(tilesizx[GUNONBOTTOM]>>1); y1 = windowy2+1; + for(i=0;i>2,0,1+2,windowx1,windowy1,windowx2,windowy2); + else if (lockclock < 256) + rotatesprite(320<<15,200<<15,65536,0,DEMOSIGN,0,0,2,windowx1,windowy1,windowx2,windowy2); + else + rotatesprite(320<<15,200<<15,(384-lockclock)<<9,lockclock<<4,DEMOSIGN,(lockclock-256)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); + } + + if (health[screenpeek] <= 0) + rotatesprite(320<<15,200<<15,(-health[screenpeek])<<11,(-health[screenpeek])<<5,NO,0,0,2,windowx1,windowy1,windowx2,windowy2); + } + } + + //Only animate lava if its picnum is on screen + //gotpic is a bit array where the tile number's bit is set + //whenever it is drawn (ceilings, walls, sprites, etc.) + if ((gotpic[SLIME>>3]&(1<<(SLIME&7))) > 0) + { + gotpic[SLIME>>3] &= ~(1<<(SLIME&7)); + if (waloff[SLIME] != 0) { + movelava((char *)waloff[SLIME]); + invalidatetile(SLIME,0,1); // JBF 20031228 + } + } + + if ((show2dsector[cursectnum[snum]>>3]&(1<<(cursectnum[snum]&7))) == 0) + searchmap(cursectnum[snum]); + + if (dimensionmode[snum] != 3) + { + //Move back pivot point + i = scale(czoom,screensize,320); + if (dimensionmode[snum] == 2) + { + clearview(0L); //Clear screen to specified color + drawmapview(cposx,cposy,i,cang); + } + drawoverheadmap(cposx,cposy,i,cang); + } + + if (typemode != 0) + { + charsperline = 40; + //if (dimensionmode[snum] == 2) charsperline = 80; + + for(i=0;i<=typemessageleng;i+=charsperline) + { + for(j=0;j 0) + { + charsperline = 40; + //if (dimensionmode[snum] == 2) charsperline = 80; + + for(i=0;i<=getmessageleng;i+=charsperline) + { + for(j=0;j getmessagetimeoff) + getmessageleng = 0; + } + if ((numplayers >= 2) && (screenpeek != myconnectindex)) + { + j = 1; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i == screenpeek) break; + j++; + } + Bsprintf(tempbuf,"(Player %ld's view)",j); + printext256((xdim>>1)-(Bstrlen(tempbuf)<<2),0,24,-1,tempbuf,0); + } + + if (syncstat != 0) printext256(68L,84L,31,0,"OUT OF SYNC!",0); + if (syncstate != 0) printext256(68L,92L,31,0,"Missed Network packet!",0); + +// //Uncomment this to test cache locks +//extern long cacnum; +//typedef struct { long *hand, leng; char *lock; } cactype; +//extern cactype cac[]; +// +// j = 0; +// for(i=0;i= 200) +// { +// Bsprintf(tempbuf,"Locked- %ld: Leng:%ld, Lock:%ld",i,cac[i].leng,*cac[i].lock); +// printext256(0L,j,31,-1,tempbuf,1); j += 6; +// } + + nextpage(); // send completed frame to display + + while (totalclock >= ototalclock+(TIMERINTSPERSECOND/MOVESPERSECOND)) + faketimerhandler(); + + if (keystatus[0x3f]) //F5 + { + keystatus[0x3f] = 0; + detailmode ^= 1; + //setrendermode(3); + } + if (keystatus[0x58]) //F12 + { + keystatus[0x58] = 0; + screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); + } + if (keystatus[0x3e]) //F4 - screen re-size + { + keystatus[0x3e] = 0; + + if (keystatus[0x2a]|keystatus[0x36]) { + setgamemode(!fullscreen, xdim, ydim, bpp); + } else { + + //cycle through all modes + j=-1; + + // work out a mask to select the mode + for (i=0; i 8) brightness = 0; + setbrightness(brightness,(char *)&palette[0],0); + } + + if (option[4] == 0) //Single player only keys + { + if (keystatus[0xd2]) //Insert - Insert player + { + keystatus[0xd2] = 0; + if (numplayers < MAXPLAYERS) + { + connectpoint2[numplayers-1] = numplayers; + connectpoint2[numplayers] = -1; + + movefifoend[numplayers] = movefifoend[0]; //HACK 01/05/2000 + + initplayersprite(numplayers); + + clearallviews(0L); //Clear screen to specified color + + numplayers++; + } + } + if (keystatus[0xd3]) //Delete - Delete player + { + keystatus[0xd3] = 0; + if (numplayers > 1) + { + numplayers--; + connectpoint2[numplayers-1] = -1; + + deletesprite(playersprite[numplayers]); + playersprite[numplayers] = -1; + + if (myconnectindex >= numplayers) myconnectindex = 0; + if (screenpeek >= numplayers) screenpeek = 0; + + if (numplayers < 2) + setup3dscreen(); + else + clearallviews(0L); //Clear screen to specified color + } + } + if (keystatus[0x46]) //Scroll Lock + { + keystatus[0x46] = 0; + + myconnectindex = connectpoint2[myconnectindex]; + if (myconnectindex < 0) myconnectindex = connecthead; + screenpeek = myconnectindex; + } + } + + restoreinterpolations(); +} + +void movethings(void) +{ + long i; + + gotlastpacketclock = totalclock; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + copybufbyte(&ffsync[i],&baksync[movefifoend[i]][i],sizeof(input)); + movefifoend[i] = ((movefifoend[i]+1)&(MOVEFIFOSIZ-1)); + } +} + +void fakedomovethings(void) +{ + input *syn; + long i, j, k, doubvel, xvect, yvect, goalz; + short bakcstat; + + syn = (input *)&baksync[fakemovefifoplc][myconnectindex]; + + omyx = myx; + omyy = myy; + omyz = myz; + omyang = myang; + omyhoriz = myhoriz; + + bakcstat = sprite[playersprite[myconnectindex]].cstat; + sprite[playersprite[myconnectindex]].cstat &= ~0x101; + + if ((syn->fvel|syn->svel) != 0) + { + doubvel = (TICSPERFRAME<<((syn->bits&256)>0)); + + xvect = 0, yvect = 0; + if (syn->fvel != 0) + { + xvect += ((((long)syn->fvel)*doubvel*(long)sintable[(myang+512)&2047])>>3); + yvect += ((((long)syn->fvel)*doubvel*(long)sintable[myang&2047])>>3); + } + if (syn->svel != 0) + { + xvect += ((((long)syn->svel)*doubvel*(long)sintable[myang&2047])>>3); + yvect += ((((long)syn->svel)*doubvel*(long)sintable[(myang+1536)&2047])>>3); + } + if (flytime[myconnectindex] > lockclock) { xvect += xvect; yvect += yvect; } // DOuble flying speed + clipmove(&myx,&myy,&myz,&mycursectnum,xvect,yvect,128L,4<<8,4<<8,CLIPMASK0); + } + + pushmove(&myx,&myy,&myz,&mycursectnum,128L,4<<8,4<<8,CLIPMASK0); + getzrange(myx,myy,myz,mycursectnum,&globhiz,&globhihit,&globloz,&globlohit,128L,CLIPMASK0); + + if (syn->avel != 0) //ang += avel * constant + { //ENGINE calculates avel for you + doubvel = TICSPERFRAME; + if ((syn->bits&256) > 0) //Lt. shift makes turn velocity 50% faster + doubvel += (TICSPERFRAME>>1); + myang += ((((long)syn->avel)*doubvel)>>4); + myang &= 2047; + } + + if (((syn->bits&8) > 0) && (myhoriz > 100-(200>>1))) myhoriz -= 4; //- + if (((syn->bits&4) > 0) && (myhoriz < 100+(200>>1))) myhoriz += 4; //+ + + goalz = globloz-EYEHEIGHT; + if (sector[mycursectnum].lotag == 4) //slime sector + if ((globlohit&0xc000) != 49152) //You're not on a sprite + { + goalz = globloz-(8<<8); + if (myz >= goalz-(2<<8)) + clipmove(&myx,&myy,&myz,&mycursectnum,-TICSPERFRAME<<14,-TICSPERFRAME<<14,128L,4<<8,4<<8,CLIPMASK0); + } + if (goalz < globhiz+(16<<8)) //ceiling&floor too close + goalz = ((globloz+globhiz)>>1); + + if (health[myconnectindex] >= 0) + { + if ((syn->bits&1) > 0) //A (stand high) + { + if (flytime[myconnectindex] <= lockclock) + { + if (myz >= globloz-(32<<8)) + { + goalz -= (16<<8); + if (syn->bits&256) goalz -= (24<<8); + } + } + else + { + myzvel -= 192; + if (syn->bits&256) myzvel -= 192; + } + } + if ((syn->bits&2) > 0) //Z (stand low) + { + if (flytime[myconnectindex] <= lockclock) + { + goalz += (12<<8); + if (syn->bits&256) goalz += (12<<8); + } + else + { + myzvel += 192; + if (syn->bits&256) myzvel += 192; + } + } + } + + if (flytime[myconnectindex] <= lockclock) + { + if (myz < goalz) + myzvel += (TICSPERFRAME<<4); + else + myzvel = (((goalz-myz)*TICSPERFRAME)>>5); + } + else + { + myzvel -= (myzvel>>2); + myzvel -= ksgn(myzvel); + } + + myz += myzvel; + if (myz > globloz-(4<<8)) myz = globloz-(4<<8), myzvel = 0; + if (myz < globhiz+(4<<8)) myz = globhiz+(4<<8), myzvel = 0; + + sprite[playersprite[myconnectindex]].cstat = bakcstat; + + myxbak[fakemovefifoplc] = myx; + myybak[fakemovefifoplc] = myy; + myzbak[fakemovefifoplc] = myz; + myangbak[fakemovefifoplc] = myang; + myhorizbak[fakemovefifoplc] = myhoriz; + fakemovefifoplc = (fakemovefifoplc+1)&(MOVEFIFOSIZ-1); +} + + //Prediction correction +void fakedomovethingscorrect(void) +{ + long i; + + if ((networkmode == 0) && (myconnectindex == connecthead)) return; + + i = ((movefifoplc-1)&(MOVEFIFOSIZ-1)); + + if ((posx[myconnectindex] == myxbak[i]) && + (posy[myconnectindex] == myybak[i]) && + (posz[myconnectindex] == myzbak[i]) && + (horiz[myconnectindex] == myhorizbak[i]) && + (ang[myconnectindex] == myangbak[i])) + return; + + //Re-start fakedomovethings back to place of error + myx = omyx = posx[myconnectindex]; + myy = omyy = posy[myconnectindex]; + myz = omyz = posz[myconnectindex]; myzvel = hvel[myconnectindex]; + myang = omyang = ang[myconnectindex]; + mycursectnum = mycursectnum; + myhoriz = omyhoriz = horiz[myconnectindex]; + + fakemovefifoplc = movefifoplc; + while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings(); +} + +void domovethings(void) +{ + short i, j, startwall, endwall; + spritetype *spr; + walltype *wal; + point3d *ospr; + + nummoves++; + + for(i=connecthead;i>=0;i=connectpoint2[i]) + copybufbyte(&baksync[movefifoplc][i],&ssync[i],sizeof(input)); + movefifoplc = ((movefifoplc+1)&(MOVEFIFOSIZ-1)); + + if (option[4] != 0) + { + syncval[syncvalhead] = (char)(randomseed&255); + syncvalhead = ((syncvalhead+1)&(MOVEFIFOSIZ-1)); + } + + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + oposx[i] = posx[i]; + oposy[i] = posy[i]; + oposz[i] = posz[i]; + ohoriz[i] = horiz[i]; + ozoom[i] = zoom[i]; + oang[i] = ang[i]; + } + + for(i=NUMSTATS-1;i>=0;i--) + if (statrate[i] >= 0) + for(j=headspritestat[i];j>=0;j=nextspritestat[j]) + if (((nummoves-j)&statrate[i]) == 0) + copybuf(&sprite[j].x,&osprite[j].x,3); + + for(i=connecthead;i>=0;i=connectpoint2[i]) + ocursectnum[i] = cursectnum[i]; + + updateinterpolations(); + + if ((numplayers <= 2) && (recstat == 1)) + { + j = 0; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + copybufbyte(&ssync[i],&recsync[reccnt][j],sizeof(input)); + j++; + } + reccnt++; if (reccnt > 16383) reccnt = 16383; + } + + lockclock += TICSPERFRAME; + drawstatusflytime(screenpeek); // Andy did this + + if (cameradist >= 0) + { + cameradist = min(cameradist+((totalclock-cameraclock)<<10),65536); + if (keystatus[0x52]) //0 + cameraang -= ((totalclock-cameraclock)<<(2+(keystatus[0x2a]|keystatus[0x36]))); + if (keystatus[0x53]) //. + cameraang += ((totalclock-cameraclock)<<(2+(keystatus[0x2a]|keystatus[0x36]))); + cameraclock = totalclock; + } + + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + processinput(i); //Move player + + checktouchsprite(i,cursectnum[i]); //Pick up coins + startwall = sector[cursectnum[i]].wallptr; + endwall = startwall + sector[cursectnum[i]].wallnum; + for(j=startwall,wal=&wall[j];jnextsector >= 0) checktouchsprite(i,wal->nextsector); + } + + doanimations(); + tagcode(); //Door code, moving sector code, other stuff + statuslistcode(); //Monster / bullet code / explosions + + fakedomovethingscorrect(); + + checkmasterslaveswitch(); +} + +void getinput(void) +{ + char ch, keystate, *ptr; + long i, j, k; + long mousx, mousy, bstatus; + + if (typemode == 0) //if normal game keys active + { + if (keystatus[keys[15]]) + { + keystatus[keys[15]] = 0; + + screenpeek = connectpoint2[screenpeek]; + if (screenpeek < 0) screenpeek = connecthead; + drawstatusbar(screenpeek); // Andy did this + } + + for(i=7;i>=0;i--) + if (keystatus[i+2]) + { keystatus[i+2] = 0; locselectedgun = i; break; } + } + + + //KEYTIMERSTUFF + if (!keystatus[keys[5]]) + { + if (keystatus[keys[2]]) avel = max(avel-16*TICSPERFRAME,-128); + if (keystatus[keys[3]]) avel = min(avel+16*TICSPERFRAME,127); + } + else + { + if (keystatus[keys[2]]) svel = min(svel+8*TICSPERFRAME,127); + if (keystatus[keys[3]]) svel = max(svel-8*TICSPERFRAME,-128); + } + if (keystatus[keys[0]]) fvel = min(fvel+8*TICSPERFRAME,127); + if (keystatus[keys[1]]) fvel = max(fvel-8*TICSPERFRAME,-128); + if (keystatus[keys[12]]) svel = min(svel+8*TICSPERFRAME,127); + if (keystatus[keys[13]]) svel = max(svel-8*TICSPERFRAME,-128); + + if (avel < 0) avel = min(avel+12*TICSPERFRAME,0); + if (avel > 0) avel = max(avel-12*TICSPERFRAME,0); + if (svel < 0) svel = min(svel+2*TICSPERFRAME,0); + if (svel > 0) svel = max(svel-2*TICSPERFRAME,0); + if (fvel < 0) fvel = min(fvel+2*TICSPERFRAME,0); + if (fvel > 0) fvel = max(fvel-2*TICSPERFRAME,0); + + if ((option[4] == 0) && (numplayers >= 2)) + { + if (!keystatus[0x4f]) + { + if (keystatus[0x4b]) avel2 = max(avel2-16*TICSPERFRAME,-128); + if (keystatus[0x4d]) avel2 = min(avel2+16*TICSPERFRAME,127); + } + else + { + if (keystatus[0x4b]) svel2 = min(svel2+8*TICSPERFRAME,127); + if (keystatus[0x4d]) svel2 = max(svel2-8*TICSPERFRAME,-128); + } + if (keystatus[0x48]) fvel2 = min(fvel2+8*TICSPERFRAME,127); + if (keystatus[0x4c]) fvel2 = max(fvel2-8*TICSPERFRAME,-128); + + if (avel2 < 0) avel2 = min(avel2+12*TICSPERFRAME,0); + if (avel2 > 0) avel2 = max(avel2-12*TICSPERFRAME,0); + if (svel2 < 0) svel2 = min(svel2+2*TICSPERFRAME,0); + if (svel2 > 0) svel2 = max(svel2-2*TICSPERFRAME,0); + if (fvel2 < 0) fvel2 = min(fvel2+2*TICSPERFRAME,0); + if (fvel2 > 0) fvel2 = max(fvel2-2*TICSPERFRAME,0); + } + + oscreentilt = screentilt; + if (keystatus[0x1a]) screentilt += ((4*TICSPERFRAME)<<(keystatus[0x2a]|keystatus[0x36])); + if (keystatus[0x1b]) screentilt -= ((4*TICSPERFRAME)<<(keystatus[0x2a]|keystatus[0x36])); + + i = (TICSPERFRAME<<1); + while ((screentilt != 0) && (i > 0)) + { screentilt = ((screentilt+ksgn(screentilt-1024))&2047); i--; } + if (keystatus[0x28]) screentilt = 1536; + + + loc.fvel = min(max(fvel,-128+8),127-8); + loc.svel = min(max(svel,-128+8),127-8); + loc.avel = min(max(avel,-128+16),127-16); + + getmousevalues(&mousx,&mousy,&bstatus); + loc.avel = min(max(loc.avel+(mousx<<3),-128),127); + loc.fvel = min(max(loc.fvel-(mousy<<3),-128),127); + + loc.bits = (locselectedgun<<13); + if (typemode == 0) //if normal game keys active + { + loc.bits |= (keystatus[0x32]<<9); //M (be master) + loc.bits |= ((keystatus[keys[14]]==1)<<12); //Map mode + } + loc.bits |= keystatus[keys[8]]; //Stand high + loc.bits |= (keystatus[keys[9]]<<1); //Stand low + loc.bits |= (keystatus[keys[16]]<<4); //Zoom in + loc.bits |= (keystatus[keys[17]]<<5); //Zoom out + loc.bits |= (keystatus[keys[4]]<<8); //Run + loc.bits |= (keystatus[keys[10]]<<2); //Look up + loc.bits |= (keystatus[keys[11]]<<3); //Look down + loc.bits |= ((keystatus[keys[7]]==1)<<10); //Space + loc.bits |= ((keystatus[keys[6]]==1)<<11); //Shoot + loc.bits |= (((bstatus&6)>(oldmousebstatus&6))<<10); //Space + loc.bits |= (((bstatus&1)>(oldmousebstatus&1))<<11); //Shoot + + oldmousebstatus = bstatus; + if (((loc.bits&2048) > 0) && (locselectedgun == 0)) + oldmousebstatus &= ~1; //Allow continous fire with mouse for chain gun + + //PRIVATE KEYS: +/* if (keystatus[0xb7]) //Printscreen + { + keystatus[0xb7] = 0; + printscreeninterrupt(); + } +*/ + if (keystatus[0x2f]) //V + { + keystatus[0x2f] = 0; + if (cameradist < 0) cameradist = 0; else cameradist = -1; + cameraang = 0; + } + + if (typemode == 0) //if normal game keys active + { + if (keystatus[0x19]) //P + { + keystatus[0x19] = 0; + parallaxtype++; + if (parallaxtype > 2) parallaxtype = 0; + } + if (keystatus[0x38]|keystatus[0xb8]) //ALT + { + if (keystatus[0x4a]) // Keypad - + visibility = min(visibility+(visibility>>3),16384); + if (keystatus[0x4e]) // Keypad + + visibility = max(visibility-(visibility>>3),128); + } + + if (keystatus[keys[18]]) //Typing mode + { + keystatus[keys[18]] = 0; + typemode = 1; + bflushchars(); + keyfifoplc = keyfifoend; //Reset keyboard fifo + } + } + else + { + while ((ch = bgetchar())) + { + if (ch == 8) //Backspace + { + if (typemessageleng == 0) { typemode = 0; break; } + typemessageleng--; + } + else if (ch == 9) // tab + { + keystatus[0xf] = 0; + typemode = 0; + break; + } + else if (ch == 13) //Either ENTER + { + keystatus[0x1c] = 0; keystatus[0x9c] = 0; + if (typemessageleng > 0) + { + packbuf[0] = 2; //Sending text is message type 4 + for(j=typemessageleng-1;j>=0;j--) + packbuf[j+1] = typemessage[j]; + + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (i != myconnectindex) + sendpacket(i,packbuf,typemessageleng+1); + + typemessageleng = 0; + } + typemode = 0; + break; + } + else if ((typemessageleng < 159) && (ch >= 32) && (ch < 128)) + { + typemessage[typemessageleng++] = ch; + } + } + } +} + +void initplayersprite(short snum) +{ + long i; + + if (playersprite[snum] >= 0) return; + + spawnsprite(playersprite[snum],posx[snum],posy[snum],posz[snum]+EYEHEIGHT, + 1+256,0,snum,32,64,64,0,0,PLAYER,ang[snum],0,0,0,snum+4096, + cursectnum[snum],8,0,0,0); + + switch(snum) + { + case 1: for(i=0;i<32;i++) tempbuf[i+192] = i+128; break; //green->red + case 2: for(i=0;i<32;i++) tempbuf[i+192] = i+32; break; //green->blue + case 3: for(i=0;i<32;i++) tempbuf[i+192] = i+224; break; //green->pink + case 4: for(i=0;i<32;i++) tempbuf[i+192] = i+64; break; //green->brown + case 5: for(i=0;i<32;i++) tempbuf[i+192] = i+96; break; + case 6: for(i=0;i<32;i++) tempbuf[i+192] = i+160; break; + case 7: for(i=0;i<32;i++) tempbuf[i+192] = i+192; break; + default: for(i=0;i<256;i++) tempbuf[i] = i; break; + } + makepalookup(snum,tempbuf,0,0,0,1); +} + +void playback(void) +{ + long i, j, k; + + ready2send = 0; + recstat = 0; i = reccnt; + while (!keystatus[1]) + { + if (handleevents()) { + if (quitevent) { + keystatus[1] = 1; + quitevent = 0; + } + } + + refreshaudio(); + + while (totalclock >= lockclock+TICSPERFRAME) + { + sampletimer(); + if (i >= reccnt) + { + prepareboard(boardfilename); + for(i=connecthead;i>=0;i=connectpoint2[i]) + initplayersprite((short)i); + totalclock = 0; + i = 0; + } + + k = 0; + for(j=connecthead;j>=0;j=connectpoint2[j]) + { + copybufbyte(&recsync[i][k],&ffsync[j],sizeof(input)); + k++; + } + movethings(); domovethings(); + i++; + } + drawscreen(screenpeek,(totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND))); + + if (keystatus[keys[15]]) + { + keystatus[keys[15]] = 0; + screenpeek = connectpoint2[screenpeek]; + if (screenpeek < 0) screenpeek = connecthead; + drawstatusbar(screenpeek); // Andy did this + } + if (keystatus[keys[14]]) + { + keystatus[keys[14]] = 0; + dimensionmode[screenpeek]++; + if (dimensionmode[screenpeek] > 3) dimensionmode[screenpeek] = 1; + } + } + + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + exit(0); +} + +void setup3dscreen(void) +{ + long i, dax, day, dax2, day2; + + i = setgamemode(fullscreen,xdimgame,ydimgame,bppgame); + if (i < 0) + { + printf("Error setting video mode.\n"); + sendlogoff(); + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + exit(0); + } + + //Make that ugly pink into black in case it ever shows up! + i = 0L; + setpalette(255,1,(char *)&i); + //outp(0x3c8,255); outp(0x3c9,0); outp(0x3c9,0); outp(0x3c9,0); + + screensize = xdim; + if (screensize > xdim) + { + dax = 0; day = 0; + dax2 = xdim-1; day2 = ydim-1; + } + else + { + dax = ((xdim-screensize)>>1); + dax2 = dax+screensize-1; + day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); + day2 = day + scale(screensize,ydim-32,xdim)-1; + setview(dax,day,dax2,day2); + } + + flushperms(); + + if (screensize < xdim) + drawtilebackground(0L,0L,BACKGROUND,8,0L,0L,xdim-1L,ydim-1L,0); //Draw background + + if (screensize <= xdim) + { + rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + i = ((xdim-320)>>1); + while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); + i = ((xdim-320)>>1)+320; + while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8; + if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4; + + drawstatusbar(screenpeek); // Andy did this + } +} + +void findrandomspot(long *x, long *y, short *sectnum) +{ + short startwall, endwall, s, dasector; + long dax, day, daz, minx, maxx, miny, maxy, cnt; + + for(cnt=256;cnt>=0;cnt--) + { + do + { + dasector = mulscale16(krand(),numsectors); + } while ((sector[dasector].ceilingz+(8<<8) >= sector[dasector].floorz) || ((sector[dasector].lotag|sector[dasector].hitag) != 0) || ((sector[dasector].floorstat&1) != 0)); + + startwall = sector[dasector].wallptr; + endwall = startwall+sector[dasector].wallnum; + if (endwall <= startwall) continue; + + dax = 0L; + day = 0L; + minx = 0x7fffffff; maxx = 0x80000000; + miny = 0x7fffffff; maxy = 0x80000000; + + for(s=startwall;s maxx) maxx = wall[s].x; + if (wall[s].y < miny) miny = wall[s].y; + if (wall[s].y > maxy) maxy = wall[s].y; + } + + if ((maxx-minx <= 256) || (maxy-miny <= 256)) continue; + + dax /= (endwall-startwall); + day /= (endwall-startwall); + + if (inside(dax,day,dasector) == 0) continue; + + daz = sector[dasector].floorz-(32<<8); + if (pushmove(&dax,&day,&daz,&dasector,128L,4<<8,4<<8,CLIPMASK0) < 0) continue; + + *x = dax; *y = day; *sectnum = dasector; + return; + } +} + +void warp(long *x, long *y, long *z, short *daang, short *dasector) +{ + short startwall, endwall, s; + long i, j, dax, day, ox, oy; + + ox = *x; oy = *y; + + for(i=0;i= warpsectorcnt) i = 0; + } while (sector[warpsectorlist[i]].hitag != j); + *dasector = warpsectorlist[i]; + break; + } + + //Find center of sector + startwall = sector[*dasector].wallptr; + endwall = startwall+sector[*dasector].wallnum; + dax = 0L, day = 0L; + for(s=startwall;s= 0) + i = s; + } + *x = dax / (endwall-startwall); + *y = day / (endwall-startwall); + *z = sector[*dasector].floorz-(32<<8); + updatesector(*x,*y,dasector); + dax = ((wall[i].x+wall[wall[i].point2].x)>>1); + day = ((wall[i].y+wall[wall[i].point2].y)>>1); + *daang = getangle(dax-*x,day-*y); + + wsayfollow("warp.wav",3072L+(krand()&127)-64,192L,&ox,&oy,0); + wsayfollow("warp.wav",4096L+(krand()&127)-64,256L,x,y,0); +} + +void warpsprite(short spritenum) +{ + short dasectnum; + + dasectnum = sprite[spritenum].sectnum; + warp(&sprite[spritenum].x,&sprite[spritenum].y,&sprite[spritenum].z, + &sprite[spritenum].ang,&dasectnum); + + copybuf(&sprite[spritenum].x,&osprite[spritenum].x,3); + changespritesect(spritenum,dasectnum); + + show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7)); + if (show2dsector[dasectnum>>3]&(1<<(dasectnum&7))) + show2dsprite[spritenum>>3] |= (1<<(spritenum&7)); +} + +void initlava(void) +{ + long x, y, z, r; + + for(z=0;z<32;z++) lavaradcnt[z] = 0; + for(x=-16;x<=16;x++) + for(y=-16;y<=16;y++) + { + r = ksqrt(x*x + y*y); + lavaradx[r][lavaradcnt[r]] = x; + lavarady[r][lavaradcnt[r]] = y; + lavaradcnt[r]++; + } + + for(z=0;z<16;z++) + lavadropsizlookup[z] = 8 / (ksqrt(z)+1); + + for(z=0;z>4)&7)-4)+12; + + lavanumdrops = 0; + lavanumframes = 0; +} + +#if defined(__WATCOMC__) && !defined(NOASM) +#pragma aux addlava =\ + "mov al, byte ptr [ebx-133]",\ + "mov dl, byte ptr [ebx-1]",\ + "add al, byte ptr [ebx-132]",\ + "add dl, byte ptr [ebx+131]",\ + "add al, byte ptr [ebx-131]",\ + "add dl, byte ptr [ebx+132]",\ + "add al, byte ptr [ebx+1]",\ + "add al, dl",\ + parm [ebx]\ + modify exact [eax edx] +long addlava(long); +#elif defined(_MSC_VER) && !defined(NOASM) +inline long addlava(long b) +{ + _asm { + mov ebx, b + mov al, byte ptr [ebx-133] + mov dl, byte ptr [ebx-1] + add al, byte ptr [ebx-132] + add dl, byte ptr [ebx+131] + add al, byte ptr [ebx-131] + add dl, byte ptr [ebx+132] + add al, byte ptr [ebx+1] + add al, dl + } +} +#elif defined(__GNUC__) && defined(__i386__) && !defined(NOASM) +inline long addlava(long b) +{ + long r; + __asm__ __volatile__ ( + "movb -133(%%ebx), %%al\n\t" + "movb -1(%%ebx), %%dl\n\t" + "addb -132(%%ebx), %%al\n\t" + "addb 131(%%ebx), %%dl\n\t" + "addb -131(%%ebx), %%al\n\t" + "addb 132(%%ebx), %%dl\n\t" + "addb 1(%%ebx), %%al\n\t" + "addb %%dl, %%al" + : "=a" (r) : "b" (b) + : "dx" + ); + return r; +} +#else +inline long addlava(long bx) +{ + char *b = (char *)bx; + return b[-133] + b[-132] + b[-131] + b[1] + b[-1] + b[131] + b[132]; +} +#endif + +void movelava(char *dapic) +{ + long i, j, x, y, z, zz, dalavadropsiz, dadropsizlookup; + long dalavax, dalavay, *ptr, *ptr2; + + for(z=min(LAVAMAXDROPS-lavanumdrops-1,3);z>=0;z--) + { + lavadropx[lavanumdrops] = (Brand()&(LAVASIZ-1)); + lavadropy[lavanumdrops] = (Brand()&(LAVASIZ-1)); + lavadropsiz[lavanumdrops] = 1; + lavanumdrops++; + } + + for(z=lavanumdrops-1;z>=0;z--) + { + dadropsizlookup = lavadropsizlookup[lavadropsiz[z]]*(((z&1)<<1)-1); + dalavadropsiz = lavadropsiz[z]; + dalavax = lavadropx[z]; dalavay = lavadropy[z]; + for(zz=lavaradcnt[lavadropsiz[z]]-1;zz>=0;zz--) + { + i = (((lavaradx[dalavadropsiz][zz]+dalavax)&(LAVASIZ-1))< 10) + { + lavanumdrops--; + lavadropx[z] = lavadropx[lavanumdrops]; + lavadropy[z] = lavadropy[lavanumdrops]; + lavadropsiz[z] = lavadropsiz[lavanumdrops]; + } + } + + //Back up dapic with 1 pixel extra on each boundary + //(to prevent anding for wrap-around) + ptr = (long *)dapic; + ptr2 = (long *)((LAVASIZ+4)+1+((long)lavabakpic)); + for(x=0;x>2);y>0;y--) *ptr2++ = ((*ptr++)&0x1f1f1f1f); + ptr2++; + } + for(y=0;y>3)+ + ((addlava(y+1)&0xf8)<<5)+ + ((addlava(y+2)&0xf8)<<13)+ + ((addlava(y+3)&0xf8)<<21)+ + 0xc2c2c2c2; + } + } + + lavanumframes++; +} + +void doanimations(void) +{ + long i, j; + + for(i=animatecnt-1;i>=0;i--) + { + j = *animateptr[i]; + + if (j < animategoal[i]) + j = min(j+animatevel[i]*TICSPERFRAME,animategoal[i]); + else + j = max(j-animatevel[i]*TICSPERFRAME,animategoal[i]); + animatevel[i] += animateacc[i]; + + *animateptr[i] = j; + + if (j == animategoal[i]) + { + animatecnt--; + if (i != animatecnt) + { + stopinterpolation(animateptr[i]); + animateptr[i] = animateptr[animatecnt]; + animategoal[i] = animategoal[animatecnt]; + animatevel[i] = animatevel[animatecnt]; + animateacc[i] = animateacc[animatecnt]; + } + } + } +} + +long getanimationgoal(long animptr) +{ + long i; + + for(i=animatecnt-1;i>=0;i--) + if ((long *)animptr == animateptr[i]) return(i); + return(-1); +} + +long setanimation(long *animptr, long thegoal, long thevel, long theacc) +{ + long i, j; + + if (animatecnt >= MAXANIMATES) return(-1); + + j = animatecnt; + for(i=animatecnt-1;i>=0;i--) + if (animptr == animateptr[i]) + { j = i; break; } + + setinterpolation(animptr); + + animateptr[j] = animptr; + animategoal[j] = thegoal; + animatevel[j] = thevel; + animateacc[j] = theacc; + if (j == animatecnt) animatecnt++; + return(j); +} + +void checkmasterslaveswitch(void) +{ + long i, j; + + if (option[4] == 0) return; + + j = 0; + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (ssync[i].bits&512) j++; + if (j != 1) return; + + i = connecthead; + for(j=connectpoint2[i];j>=0;j=connectpoint2[j]) + { + if (ssync[j].bits&512) + { + connectpoint2[i] = connectpoint2[j]; + connectpoint2[j] = connecthead; + connecthead = (short)j; + + oloc.fvel = loc.fvel+1; + oloc.svel = loc.svel+1; + oloc.avel = loc.avel+1; + oloc.bits = loc.bits+1; + for(i=0;i=0;i=connectpoint2[i]) + { + if (myconnectindex == i) break; + j++; + } + if (j == 1) + Bstrcpy(getmessage,"Player 1 (Master)"); + else + Bsprintf(getmessage,"Player %ld (Slave)",j); + getmessageleng = Bstrlen(getmessage); + getmessagetimeoff = totalclock+120; + + return; + } + i = j; + } +} + + +long testneighborsectors(short sect1, short sect2) +{ + short i, startwall, num1, num2; + + num1 = sector[sect1].wallnum; + num2 = sector[sect2].wallnum; + if (num1 < num2) //Traverse walls of sector with fewest walls (for speed) + { + startwall = sector[sect1].wallptr; + for(i=num1-1;i>=0;i--) + if (wall[i+startwall].nextsector == sect2) + return(1); + } + else + { + startwall = sector[sect2].wallptr; + for(i=num2-1;i>=0;i--) + if (wall[i+startwall].nextsector == sect1) + return(1); + } + return(0); +} + +long loadgame(void) +{ + long i; + long fil; + + if ((fil = kopen4load("save0000.gam",0)) == -1) return(-1); + + kdfread(&numplayers,4,1,fil); + kdfread(&myconnectindex,4,1,fil); + kdfread(&connecthead,4,1,fil); + kdfread(connectpoint2,4,MAXPLAYERS,fil); + + //Make sure palookups get set, sprites will get overwritten later + for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); + + kdfread(posx,4,MAXPLAYERS,fil); + kdfread(posy,4,MAXPLAYERS,fil); + kdfread(posz,4,MAXPLAYERS,fil); + kdfread(horiz,4,MAXPLAYERS,fil); + kdfread(zoom,4,MAXPLAYERS,fil); + kdfread(hvel,4,MAXPLAYERS,fil); + kdfread(ang,2,MAXPLAYERS,fil); + kdfread(cursectnum,2,MAXPLAYERS,fil); + kdfread(ocursectnum,2,MAXPLAYERS,fil); + kdfread(playersprite,2,MAXPLAYERS,fil); + kdfread(deaths,2,MAXPLAYERS,fil); + kdfread(lastchaingun,4,MAXPLAYERS,fil); + kdfread(health,4,MAXPLAYERS,fil); + kdfread(numgrabbers,2,MAXPLAYERS,fil); + kdfread(nummissiles,2,MAXPLAYERS,fil); + kdfread(numbombs,2,MAXPLAYERS,fil); + kdfread(flytime,4,MAXPLAYERS,fil); + kdfread(oflags,2,MAXPLAYERS,fil); + kdfread(dimensionmode,1,MAXPLAYERS,fil); + kdfread(revolvedoorstat,1,MAXPLAYERS,fil); + kdfread(revolvedoorang,2,MAXPLAYERS,fil); + kdfread(revolvedoorrotang,2,MAXPLAYERS,fil); + kdfread(revolvedoorx,4,MAXPLAYERS,fil); + kdfread(revolvedoory,4,MAXPLAYERS,fil); + + kdfread(&numsectors,2,1,fil); + kdfread(sector,sizeof(sectortype),numsectors,fil); + kdfread(&numwalls,2,1,fil); + kdfread(wall,sizeof(walltype),numwalls,fil); + //Store all sprites (even holes) to preserve indeces + kdfread(sprite,sizeof(spritetype),MAXSPRITES,fil); + kdfread(headspritesect,2,MAXSECTORS+1,fil); + kdfread(prevspritesect,2,MAXSPRITES,fil); + kdfread(nextspritesect,2,MAXSPRITES,fil); + kdfread(headspritestat,2,MAXSTATUS+1,fil); + kdfread(prevspritestat,2,MAXSPRITES,fil); + kdfread(nextspritestat,2,MAXSPRITES,fil); + + kdfread(&fvel,4,1,fil); + kdfread(&svel,4,1,fil); + kdfread(&avel,4,1,fil); + + kdfread(&locselectedgun,4,1,fil); + kdfread(&loc.fvel,1,1,fil); + kdfread(&oloc.fvel,1,1,fil); + kdfread(&loc.svel,1,1,fil); + kdfread(&oloc.svel,1,1,fil); + kdfread(&loc.avel,1,1,fil); + kdfread(&oloc.avel,1,1,fil); + kdfread(&loc.bits,2,1,fil); + kdfread(&oloc.bits,2,1,fil); + + kdfread(&locselectedgun2,4,1,fil); + kdfread(&loc2.fvel,sizeof(input),1,fil); + + kdfread(ssync,sizeof(input),MAXPLAYERS,fil); + kdfread(osync,sizeof(input),MAXPLAYERS,fil); + + kdfread(boardfilename,1,80,fil); + kdfread(&screenpeek,2,1,fil); + kdfread(&oldmousebstatus,2,1,fil); + kdfread(&brightness,2,1,fil); + kdfread(&neartagsector,2,1,fil); + kdfread(&neartagwall,2,1,fil); + kdfread(&neartagsprite,2,1,fil); + kdfread(&lockclock,4,1,fil); + kdfread(&neartagdist,4,1,fil); + kdfread(&neartaghitdist,4,1,fil); + + kdfread(turnspritelist,2,16,fil); + kdfread(&turnspritecnt,2,1,fil); + kdfread(warpsectorlist,2,16,fil); + kdfread(&warpsectorcnt,2,1,fil); + kdfread(xpanningsectorlist,2,16,fil); + kdfread(&xpanningsectorcnt,2,1,fil); + kdfread(ypanningwalllist,2,64,fil); + kdfread(&ypanningwallcnt,2,1,fil); + kdfread(floorpanninglist,2,64,fil); + kdfread(&floorpanningcnt,2,1,fil); + kdfread(dragsectorlist,2,16,fil); + kdfread(dragxdir,2,16,fil); + kdfread(dragydir,2,16,fil); + kdfread(&dragsectorcnt,2,1,fil); + kdfread(dragx1,4,16,fil); + kdfread(dragy1,4,16,fil); + kdfread(dragx2,4,16,fil); + kdfread(dragy2,4,16,fil); + kdfread(dragfloorz,4,16,fil); + kdfread(&swingcnt,2,1,fil); + kdfread(swingwall,2,32*5,fil); + kdfread(swingsector,2,32,fil); + kdfread(swingangopen,2,32,fil); + kdfread(swingangclosed,2,32,fil); + kdfread(swingangopendir,2,32,fil); + kdfread(swingang,2,32,fil); + kdfread(swinganginc,2,32,fil); + kdfread(swingx,4,32*8,fil); + kdfread(swingy,4,32*8,fil); + kdfread(revolvesector,2,4,fil); + kdfread(revolveang,2,4,fil); + kdfread(&revolvecnt,2,1,fil); + kdfread(revolvex,4,4*16,fil); + kdfread(revolvey,4,4*16,fil); + kdfread(revolvepivotx,4,4,fil); + kdfread(revolvepivoty,4,4,fil); + kdfread(subwaytracksector,2,4*128,fil); + kdfread(subwaynumsectors,2,4,fil); + kdfread(&subwaytrackcnt,2,1,fil); + kdfread(subwaystop,4,4*8,fil); + kdfread(subwaystopcnt,4,4,fil); + kdfread(subwaytrackx1,4,4,fil); + kdfread(subwaytracky1,4,4,fil); + kdfread(subwaytrackx2,4,4,fil); + kdfread(subwaytracky2,4,4,fil); + kdfread(subwayx,4,4,fil); + kdfread(subwaygoalstop,4,4,fil); + kdfread(subwayvel,4,4,fil); + kdfread(subwaypausetime,4,4,fil); + kdfread(waterfountainwall,2,MAXPLAYERS,fil); + kdfread(waterfountaincnt,2,MAXPLAYERS,fil); + kdfread(slimesoundcnt,2,MAXPLAYERS,fil); + + //Warning: only works if all pointers are in sector structures! + kdfread(animateptr,4,MAXANIMATES,fil); + for(i=MAXANIMATES-1;i>=0;i--) + animateptr[i] = (long *)(animateptr[i]+((long)sector)); + + kdfread(animategoal,4,MAXANIMATES,fil); + kdfread(animatevel,4,MAXANIMATES,fil); + kdfread(animateacc,4,MAXANIMATES,fil); + kdfread(&animatecnt,4,1,fil); + + kdfread(&totalclock,4,1,fil); + kdfread(&numframes,4,1,fil); + kdfread(&randomseed,4,1,fil); + kdfread(&numpalookups,2,1,fil); + + kdfread(&visibility,4,1,fil); + kdfread(¶llaxvisibility,4,1,fil); + kdfread(¶llaxtype,1,1,fil); + kdfread(¶llaxyoffs,4,1,fil); + kdfread(pskyoff,2,MAXPSKYTILES,fil); + kdfread(&pskybits,2,1,fil); + + kdfread(&mirrorcnt,2,1,fil); + kdfread(mirrorwall,2,mirrorcnt,fil); + kdfread(mirrorsector,2,mirrorcnt,fil); + + //I should save off interpolation list, but they're pointers :( + numinterpolations = 0; + startofdynamicinterpolations = 0; + + kclose(fil); + + for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); + + totalclock = lockclock; + ototalclock = lockclock; + + Bstrcpy(getmessage,"Game loaded."); + getmessageleng = Bstrlen(getmessage); + getmessagetimeoff = totalclock+360+(getmessageleng<<4); + return(0); +} + +long savegame(void) +{ + long i; + BFILE *fil; + + if ((fil = Bfopen("save0000.gam","wb")) == 0) return(-1); + + dfwrite(&numplayers,4,1,fil); + dfwrite(&myconnectindex,4,1,fil); + dfwrite(&connecthead,4,1,fil); + dfwrite(connectpoint2,4,MAXPLAYERS,fil); + + dfwrite(posx,4,MAXPLAYERS,fil); + dfwrite(posy,4,MAXPLAYERS,fil); + dfwrite(posz,4,MAXPLAYERS,fil); + dfwrite(horiz,4,MAXPLAYERS,fil); + dfwrite(zoom,4,MAXPLAYERS,fil); + dfwrite(hvel,4,MAXPLAYERS,fil); + dfwrite(ang,2,MAXPLAYERS,fil); + dfwrite(cursectnum,2,MAXPLAYERS,fil); + dfwrite(ocursectnum,2,MAXPLAYERS,fil); + dfwrite(playersprite,2,MAXPLAYERS,fil); + dfwrite(deaths,2,MAXPLAYERS,fil); + dfwrite(lastchaingun,4,MAXPLAYERS,fil); + dfwrite(health,4,MAXPLAYERS,fil); + dfwrite(numgrabbers,2,MAXPLAYERS,fil); + dfwrite(nummissiles,2,MAXPLAYERS,fil); + dfwrite(numbombs,2,MAXPLAYERS,fil); + dfwrite(flytime,4,MAXPLAYERS,fil); + dfwrite(oflags,2,MAXPLAYERS,fil); + dfwrite(dimensionmode,1,MAXPLAYERS,fil); + dfwrite(revolvedoorstat,1,MAXPLAYERS,fil); + dfwrite(revolvedoorang,2,MAXPLAYERS,fil); + dfwrite(revolvedoorrotang,2,MAXPLAYERS,fil); + dfwrite(revolvedoorx,4,MAXPLAYERS,fil); + dfwrite(revolvedoory,4,MAXPLAYERS,fil); + + dfwrite(&numsectors,2,1,fil); + dfwrite(sector,sizeof(sectortype),numsectors,fil); + dfwrite(&numwalls,2,1,fil); + dfwrite(wall,sizeof(walltype),numwalls,fil); + //Store all sprites (even holes) to preserve indeces + dfwrite(sprite,sizeof(spritetype),MAXSPRITES,fil); + dfwrite(headspritesect,2,MAXSECTORS+1,fil); + dfwrite(prevspritesect,2,MAXSPRITES,fil); + dfwrite(nextspritesect,2,MAXSPRITES,fil); + dfwrite(headspritestat,2,MAXSTATUS+1,fil); + dfwrite(prevspritestat,2,MAXSPRITES,fil); + dfwrite(nextspritestat,2,MAXSPRITES,fil); + + dfwrite(&fvel,4,1,fil); + dfwrite(&svel,4,1,fil); + dfwrite(&avel,4,1,fil); + + dfwrite(&locselectedgun,4,1,fil); + dfwrite(&loc.fvel,1,1,fil); + dfwrite(&oloc.fvel,1,1,fil); + dfwrite(&loc.svel,1,1,fil); + dfwrite(&oloc.svel,1,1,fil); + dfwrite(&loc.avel,1,1,fil); + dfwrite(&oloc.avel,1,1,fil); + dfwrite(&loc.bits,2,1,fil); + dfwrite(&oloc.bits,2,1,fil); + + dfwrite(&locselectedgun2,4,1,fil); + dfwrite(&loc2.fvel,sizeof(input),1,fil); + + dfwrite(ssync,sizeof(input),MAXPLAYERS,fil); + dfwrite(osync,sizeof(input),MAXPLAYERS,fil); + + dfwrite(boardfilename,1,80,fil); + dfwrite(&screenpeek,2,1,fil); + dfwrite(&oldmousebstatus,2,1,fil); + dfwrite(&brightness,2,1,fil); + dfwrite(&neartagsector,2,1,fil); + dfwrite(&neartagwall,2,1,fil); + dfwrite(&neartagsprite,2,1,fil); + dfwrite(&lockclock,4,1,fil); + dfwrite(&neartagdist,4,1,fil); + dfwrite(&neartaghitdist,4,1,fil); + + dfwrite(turnspritelist,2,16,fil); + dfwrite(&turnspritecnt,2,1,fil); + dfwrite(warpsectorlist,2,16,fil); + dfwrite(&warpsectorcnt,2,1,fil); + dfwrite(xpanningsectorlist,2,16,fil); + dfwrite(&xpanningsectorcnt,2,1,fil); + dfwrite(ypanningwalllist,2,64,fil); + dfwrite(&ypanningwallcnt,2,1,fil); + dfwrite(floorpanninglist,2,64,fil); + dfwrite(&floorpanningcnt,2,1,fil); + dfwrite(dragsectorlist,2,16,fil); + dfwrite(dragxdir,2,16,fil); + dfwrite(dragydir,2,16,fil); + dfwrite(&dragsectorcnt,2,1,fil); + dfwrite(dragx1,4,16,fil); + dfwrite(dragy1,4,16,fil); + dfwrite(dragx2,4,16,fil); + dfwrite(dragy2,4,16,fil); + dfwrite(dragfloorz,4,16,fil); + dfwrite(&swingcnt,2,1,fil); + dfwrite(swingwall,2,32*5,fil); + dfwrite(swingsector,2,32,fil); + dfwrite(swingangopen,2,32,fil); + dfwrite(swingangclosed,2,32,fil); + dfwrite(swingangopendir,2,32,fil); + dfwrite(swingang,2,32,fil); + dfwrite(swinganginc,2,32,fil); + dfwrite(swingx,4,32*8,fil); + dfwrite(swingy,4,32*8,fil); + dfwrite(revolvesector,2,4,fil); + dfwrite(revolveang,2,4,fil); + dfwrite(&revolvecnt,2,1,fil); + dfwrite(revolvex,4,4*16,fil); + dfwrite(revolvey,4,4*16,fil); + dfwrite(revolvepivotx,4,4,fil); + dfwrite(revolvepivoty,4,4,fil); + dfwrite(subwaytracksector,2,4*128,fil); + dfwrite(subwaynumsectors,2,4,fil); + dfwrite(&subwaytrackcnt,2,1,fil); + dfwrite(subwaystop,4,4*8,fil); + dfwrite(subwaystopcnt,4,4,fil); + dfwrite(subwaytrackx1,4,4,fil); + dfwrite(subwaytracky1,4,4,fil); + dfwrite(subwaytrackx2,4,4,fil); + dfwrite(subwaytracky2,4,4,fil); + dfwrite(subwayx,4,4,fil); + dfwrite(subwaygoalstop,4,4,fil); + dfwrite(subwayvel,4,4,fil); + dfwrite(subwaypausetime,4,4,fil); + dfwrite(waterfountainwall,2,MAXPLAYERS,fil); + dfwrite(waterfountaincnt,2,MAXPLAYERS,fil); + dfwrite(slimesoundcnt,2,MAXPLAYERS,fil); + + //Warning: only works if all pointers are in sector structures! + for(i=MAXANIMATES-1;i>=0;i--) + animateptr[i] = (long *)(animateptr[i]-((long)sector)); + dfwrite(animateptr,4,MAXANIMATES,fil); + for(i=MAXANIMATES-1;i>=0;i--) + animateptr[i] = (long *)(animateptr[i]+((long)sector)); + + dfwrite(animategoal,4,MAXANIMATES,fil); + dfwrite(animatevel,4,MAXANIMATES,fil); + dfwrite(animateacc,4,MAXANIMATES,fil); + dfwrite(&animatecnt,4,1,fil); + + dfwrite(&totalclock,4,1,fil); + dfwrite(&numframes,4,1,fil); + dfwrite(&randomseed,4,1,fil); + dfwrite(&numpalookups,2,1,fil); + + dfwrite(&visibility,4,1,fil); + dfwrite(¶llaxvisibility,4,1,fil); + dfwrite(¶llaxtype,1,1,fil); + dfwrite(¶llaxyoffs,4,1,fil); + dfwrite(pskyoff,2,MAXPSKYTILES,fil); + dfwrite(&pskybits,2,1,fil); + + dfwrite(&mirrorcnt,2,1,fil); + dfwrite(mirrorwall,2,mirrorcnt,fil); + dfwrite(mirrorsector,2,mirrorcnt,fil); + + Bfclose(fil); + + Bstrcpy(getmessage,"Game saved."); + getmessageleng = Bstrlen(getmessage); + getmessagetimeoff = totalclock+360+(getmessageleng<<4); + return(0); +} + +void faketimerhandler(void) +{ + short other, packbufleng; + long i, j, k, l; + + sampletimer(); + if ((totalclock < ototalclock+(TIMERINTSPERSECOND/MOVESPERSECOND)) || (ready2send == 0)) return; + ototalclock += (TIMERINTSPERSECOND/MOVESPERSECOND); + + getpackets(); + if (getoutputcirclesize() >= 16) return; + getinput(); + + /* + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (i != myconnectindex) + { + k = (movefifoend[myconnectindex]-1)-movefifoend[i]; + myminlag[i] = min(myminlag[i],k); + mymaxlag = max(mymaxlag,k); + } + + if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0) + { + i = mymaxlag-bufferjitter; mymaxlag = 0; + if (i > 0) bufferjitter += ((2+i)>>2); + else if (i < 0) bufferjitter -= ((2-i)>>2); + } + */ + + if (networkmode == 1) + { + packbuf[2] = 0; j = 3; + if (loc.fvel != oloc.fvel) packbuf[j++] = loc.fvel, packbuf[2] |= 1; + if (loc.svel != oloc.svel) packbuf[j++] = loc.svel, packbuf[2] |= 2; + if (loc.avel != oloc.avel) packbuf[j++] = loc.avel, packbuf[2] |= 4; + if ((loc.bits^oloc.bits)&0x00ff) packbuf[j++] = (loc.bits&255), packbuf[2] |= 8; + if ((loc.bits^oloc.bits)&0xff00) packbuf[j++] = ((loc.bits>>8)&255), packbuf[2] |= 16; + copybufbyte(&loc,&oloc,sizeof(input)); + + copybufbyte(&loc,&baksync[movefifoend[myconnectindex]][myconnectindex],sizeof(input)); + movefifoend[myconnectindex] = ((movefifoend[myconnectindex]+1)&(MOVEFIFOSIZ-1)); + + for(i=connecthead;i>=0;i=connectpoint2[i]) + if (i != myconnectindex) + { + packbuf[0] = 17; + packbuf[1] = (char)((movefifoend[myconnectindex]-movefifoend[i])&(MOVEFIFOSIZ-1)); + + k = j; + if ((myconnectindex == connecthead) || ((i == connecthead) && (myconnectindex == connectpoint2[connecthead]))) + { + while (syncvalhead != syncvaltail) + { + packbuf[j++] = syncval[syncvaltail]; + syncvaltail = ((syncvaltail+1)&(MOVEFIFOSIZ-1)); + } + } + sendpacket(i,packbuf,j); + j = k; + } + + gotlastpacketclock = totalclock; + return; + } + + //MASTER (or 1 player game) + if ((myconnectindex == connecthead) || (option[4] == 0)) + { + copybufbyte(&loc,&ffsync[myconnectindex],sizeof(input)); + + if (option[4] != 0) + { + packbuf[0] = 0; + j = ((numplayers+1)>>1)+1; + for(k=1;k=0;i=connectpoint2[i]) + { + l = 0; + if (ffsync[i].fvel != osync[i].fvel) packbuf[j++] = ffsync[i].fvel, l |= 1; + if (ffsync[i].svel != osync[i].svel) packbuf[j++] = ffsync[i].svel, l |= 2; + if (ffsync[i].avel != osync[i].avel) packbuf[j++] = ffsync[i].avel, l |= 4; + if (ffsync[i].bits != osync[i].bits) + { + packbuf[j++] = (ffsync[i].bits&255); + packbuf[j++] = ((ffsync[i].bits>>8)&255); + l |= 8; + } + packbuf[k>>3] |= (l<<(k&7)); + k += 4; + + copybufbyte(&ffsync[i],&osync[i],sizeof(input)); + } + + while (syncvalhead != syncvaltail) + { + packbuf[j++] = syncval[syncvaltail]; + syncvaltail = ((syncvaltail+1)&(MOVEFIFOSIZ-1)); + } + + for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) + sendpacket(i,packbuf,j); + } + else if (numplayers >= 2) + { + if (keystatus[0xb5]) + { + keystatus[0xb5] = 0; + locselectedgun2++; if (locselectedgun2 >= 3) locselectedgun2 = 0; + } + + //Second player on 1 computer mode + loc2.fvel = min(max(fvel2,-128+8),127-8); + loc2.svel = min(max(svel2,-128+8),127-8); + loc2.avel = min(max(avel2,-128+16),127-16); + loc2.bits = (locselectedgun2<<13); + loc2.bits |= keystatus[0x45]; //Stand high + loc2.bits |= (keystatus[0x47]<<1); //Stand low + loc2.bits |= (1<<8); //Run + loc2.bits |= (keystatus[0x49]<<2); //Look up + loc2.bits |= (keystatus[0x37]<<3); //Look down + loc2.bits |= (keystatus[0x50]<<10); //Space + loc2.bits |= (keystatus[0x52]<<11); //Shoot + + other = connectpoint2[myconnectindex]; + if (other < 0) other = connecthead; + + copybufbyte(&loc2,&ffsync[other],sizeof(input)); + } + movethings(); //Move EVERYTHING (you too!) + } + else //I am a SLAVE + { + packbuf[0] = 1; packbuf[1] = 0; j = 2; + if (loc.fvel != oloc.fvel) packbuf[j++] = loc.fvel, packbuf[1] |= 1; + if (loc.svel != oloc.svel) packbuf[j++] = loc.svel, packbuf[1] |= 2; + if (loc.avel != oloc.avel) packbuf[j++] = loc.avel, packbuf[1] |= 4; + if ((loc.bits^oloc.bits)&0x00ff) packbuf[j++] = (loc.bits&255), packbuf[1] |= 8; + if ((loc.bits^oloc.bits)&0xff00) packbuf[j++] = ((loc.bits>>8)&255), packbuf[1] |= 16; + copybufbyte(&loc,&oloc,sizeof(input)); + sendpacket(connecthead,packbuf,j); + } +} + +void getpackets(void) +{ + long i, j, k, l; + long other, packbufleng, movecnt; + + if (option[4] == 0) return; + + movecnt = 0; + while ((packbufleng = getpacket(&other,packbuf)) > 0) + { + switch(packbuf[0]) + { + case 0: //[0] (receive master sync buffer) + j = ((numplayers+1)>>1)+1; k = (1<<3); + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + l = (packbuf[k>>3]>>(k&7)); + if (l&1) ffsync[i].fvel = packbuf[j++]; + if (l&2) ffsync[i].svel = packbuf[j++]; + if (l&4) ffsync[i].avel = packbuf[j++]; + if (l&8) + { + ffsync[i].bits = ((short)packbuf[j])+(((short)packbuf[j+1])<<8); + j += 2; + } + k += 4; + } + + while (j != packbufleng) + { + othersyncval[othersyncvalhead] = packbuf[j++]; + othersyncvalhead = ((othersyncvalhead+1)&(MOVEFIFOSIZ-1)); + } + if ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)) + { + syncstat = 0; + do + { + syncstat |= (syncval[syncvaltottail]^othersyncval[syncvaltottail]); + syncvaltottail = ((syncvaltottail+1)&(MOVEFIFOSIZ-1)); + } while ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)); + } + + movethings(); //Move all players and sprites + movecnt++; + break; + case 1: //[1] (receive slave sync buffer) + j = 2; k = packbuf[1]; + if (k&1) ffsync[other].fvel = packbuf[j++]; + if (k&2) ffsync[other].svel = packbuf[j++]; + if (k&4) ffsync[other].avel = packbuf[j++]; + if (k&8) ffsync[other].bits = ((ffsync[other].bits&0xff00)|((short)packbuf[j++])); + if (k&16) ffsync[other].bits = ((ffsync[other].bits&0x00ff)|(((short)packbuf[j++])<<8)); + break; + case 2: + getmessageleng = packbufleng-1; + for(j=getmessageleng-1;j>=0;j--) getmessage[j] = packbuf[j+1]; + getmessagetimeoff = totalclock+360+(getmessageleng<<4); + wsay("getstuff.wav",8192L,63L,63L); //Added 12/2004 + break; + case 3: + wsay("getstuff.wav",4096L,63L,63L); + break; + /* + case 5: + playerreadyflag[other] = packbuf[1]; + if ((other == connecthead) && (packbuf[1] == 2)) + sendpacket(connecthead,packbuf,2); + break; + */ + case 250: + playerreadyflag[other]++; + break; + case 17: + j = 3; k = packbuf[2]; + if (k&1) ffsync[other].fvel = packbuf[j++]; + if (k&2) ffsync[other].svel = packbuf[j++]; + if (k&4) ffsync[other].avel = packbuf[j++]; + if (k&8) ffsync[other].bits = ((ffsync[other].bits&0xff00)|((short)packbuf[j++])); + if (k&16) ffsync[other].bits = ((ffsync[other].bits&0x00ff)|(((short)packbuf[j++])<<8)); + otherlag[other] = packbuf[1]; + + copybufbyte(&ffsync[other],&baksync[movefifoend[other]][other],sizeof(input)); + movefifoend[other] = ((movefifoend[other]+1)&(MOVEFIFOSIZ-1)); + + while (j != packbufleng) + { + othersyncval[othersyncvalhead] = packbuf[j++]; + othersyncvalhead = ((othersyncvalhead+1)&(MOVEFIFOSIZ-1)); + } + if ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)) + { + syncstat = 0; + do + { + syncstat |= (syncval[syncvaltottail]^othersyncval[syncvaltottail]); + syncvaltottail = ((syncvaltottail+1)&(MOVEFIFOSIZ-1)); + } while ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)); + } + + break; + case 255: //[255] (logout) + keystatus[1] = 1; + break; + } + } + if ((networkmode == 0) && (myconnectindex != connecthead) && ((movecnt&1) == 0)) + { + if (rand()&1) ototalclock += (TICSPERFRAME>>1); + else ototalclock -= (TICSPERFRAME>>1); + } +} + +void drawoverheadmap(long cposx, long cposy, long czoom, short cang) +{ + long i, j, k, l=0, x1, y1, x2=0, y2=0, x3, y3, x4, y4, ox, oy, xoff, yoff; + long dax, day, cosang, sinang, xspan, yspan, sprx, spry; + long xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang; + long xvect, yvect, xvect2, yvect2; + char col; + walltype *wal, *wal2; + spritetype *spr; + + xvect = sintable[(-cang)&2047] * czoom; + yvect = sintable[(1536-cang)&2047] * czoom; + xvect2 = mulscale16(xvect,yxaspect); + yvect2 = mulscale16(yvect,yxaspect); + + //Draw red lines + for(i=0;inextwall; if (k < 0) continue; + + if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue; + if ((k > j) && ((show2dwall[k>>3]&(1<<(k&7))) > 0)) continue; + + if (sector[wal->nextsector].ceilingz == z1) + if (sector[wal->nextsector].floorz == z2) + if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) continue; + + col = 152; + + if (dimensionmode[screenpeek] == 2) + { + if (sector[i].floorz != sector[i].ceilingz) + if (sector[wal->nextsector].floorz != sector[wal->nextsector].ceilingz) + if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) + if (sector[i].floorz == sector[wal->nextsector].floorz) continue; + if (sector[i].floorpicnum != sector[wal->nextsector].floorpicnum) continue; + if (sector[i].floorshade != sector[wal->nextsector].floorshade) continue; + col = 12; + } + + ox = wal->x-cposx; oy = wal->y-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); + y1 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); + + wal2 = &wall[wal->point2]; + ox = wal2->x-cposx; oy = wal2->y-cposy; + x2 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); + y2 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); + + drawline256(x1,y1,x2,y2,col); + } + } + + //Draw sprites + k = playersprite[screenpeek]; + for(i=0;i=0;j=nextspritesect[j]) + if ((show2dsprite[j>>3]&(1<<(j&7))) > 0) + { + spr = &sprite[j]; if (spr->cstat&0x8000) continue; + col = 56; + if (spr->cstat&1) col = 248; + if (j == k) col = 31; + + k = statrate[spr->statnum]; + sprx = spr->x; + spry = spr->y; + if (k >= 0) + { + switch(k) + { + case 0: l = smoothratio; break; + case 1: l = (smoothratio>>1)+(((nummoves-j)&1)<<15); break; + case 3: l = (smoothratio>>2)+(((nummoves-j)&3)<<14); break; + case 7: l = (smoothratio>>3)+(((nummoves-j)&7)<<13); break; + case 15: l = (smoothratio>>4)+(((nummoves-j)&15)<<12); break; + } + sprx = osprite[j].x+mulscale16(sprx-osprite[j].x,l); + spry = osprite[j].y+mulscale16(spry-osprite[j].y,l); + } + + switch (spr->cstat&48) + { + case 0: + ox = sprx-cposx; oy = spry-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect); + y1 = dmulscale16(oy,xvect2,ox,yvect2); + + if (dimensionmode[screenpeek] == 1) + { + ox = (sintable[(spr->ang+512)&2047]>>7); + oy = (sintable[(spr->ang)&2047]>>7); + x2 = dmulscale16(ox,xvect,-oy,yvect); + y2 = dmulscale16(oy,xvect,ox,yvect); + + if (j == playersprite[screenpeek]) + { + x2 = 0L; + y2 = -(czoom<<5); + } + + x3 = mulscale16(x2,yxaspect); + y3 = mulscale16(y2,yxaspect); + + drawline256(x1-x2+(xdim<<11),y1-y3+(ydim<<11), + x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); + drawline256(x1-y2+(xdim<<11),y1+x3+(ydim<<11), + x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); + drawline256(x1+y2+(xdim<<11),y1-x3+(ydim<<11), + x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); + } + else + { + if (((gotsector[i>>3]&(1<<(i&7))) > 0) && (czoom > 96)) + { + daang = (spr->ang-cang)&2047; + if (j == playersprite[screenpeek]) { x1 = 0; y1 = 0; daang = 0; } + rotatesprite((x1<<4)+(xdim<<15),(y1<<4)+(ydim<<15),mulscale16(czoom*spr->yrepeat,yxaspect),daang,spr->picnum,spr->shade,spr->pal,(spr->cstat&2)>>1,windowx1,windowy1,windowx2,windowy2); + } + } + break; + case 16: + x1 = sprx; y1 = spry; + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + if ((spr->cstat&4) > 0) xoff = -xoff; + k = spr->ang; l = spr->xrepeat; + dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; + l = tilesizx[tilenum]; k = (l>>1)+xoff; + x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); + y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); + + ox = x1-cposx; oy = y1-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect); + y1 = dmulscale16(oy,xvect2,ox,yvect2); + + ox = x2-cposx; oy = y2-cposy; + x2 = dmulscale16(ox,xvect,-oy,yvect); + y2 = dmulscale16(oy,xvect2,ox,yvect2); + + drawline256(x1+(xdim<<11),y1+(ydim<<11), + x2+(xdim<<11),y2+(ydim<<11),col); + + break; + case 32: + if (dimensionmode[screenpeek] == 1) + { + tilenum = spr->picnum; + xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); + yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); + if ((spr->cstat&4) > 0) xoff = -xoff; + if ((spr->cstat&8) > 0) yoff = -yoff; + + k = spr->ang; + cosang = sintable[(k+512)&2047]; sinang = sintable[k]; + xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; + yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; + + dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; + x1 = sprx + dmulscale16(sinang,dax,cosang,day); + y1 = spry + dmulscale16(sinang,day,-cosang,dax); + l = xspan*xrepeat; + x2 = x1 - mulscale16(sinang,l); + y2 = y1 + mulscale16(cosang,l); + l = yspan*yrepeat; + k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k; + k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k; + + ox = x1-cposx; oy = y1-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect); + y1 = dmulscale16(oy,xvect2,ox,yvect2); + + ox = x2-cposx; oy = y2-cposy; + x2 = dmulscale16(ox,xvect,-oy,yvect); + y2 = dmulscale16(oy,xvect2,ox,yvect2); + + ox = x3-cposx; oy = y3-cposy; + x3 = dmulscale16(ox,xvect,-oy,yvect); + y3 = dmulscale16(oy,xvect2,ox,yvect2); + + ox = x4-cposx; oy = y4-cposy; + x4 = dmulscale16(ox,xvect,-oy,yvect); + y4 = dmulscale16(oy,xvect2,ox,yvect2); + + drawline256(x1+(xdim<<11),y1+(ydim<<11), + x2+(xdim<<11),y2+(ydim<<11),col); + + drawline256(x2+(xdim<<11),y2+(ydim<<11), + x3+(xdim<<11),y3+(ydim<<11),col); + + drawline256(x3+(xdim<<11),y3+(ydim<<11), + x4+(xdim<<11),y4+(ydim<<11),col); + + drawline256(x4+(xdim<<11),y4+(ydim<<11), + x1+(xdim<<11),y1+(ydim<<11),col); + + } + break; + } + } + + //Draw white lines + for(i=0;inextwall >= 0) continue; + + if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue; + + if (tilesizx[wal->picnum] == 0) continue; + if (tilesizy[wal->picnum] == 0) continue; + + if (j == k) + { x1 = x2; y1 = y2; } + else + { + ox = wal->x-cposx; oy = wal->y-cposy; + x1 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); + y1 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); + } + + k = wal->point2; wal2 = &wall[k]; + ox = wal2->x-cposx; oy = wal2->y-cposy; + x2 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); + y2 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); + + drawline256(x1,y1,x2,y2,24); + } + } +} + + //New movesprite using getzrange. Note that I made the getzrange + //parameters global (&globhiz,&globhihit,&globloz,&globlohit) so they + //don't need to be passed everywhere. Also this should make this + //movesprite function compatible with the older movesprite functions. +long movesprite(short spritenum, long dx, long dy, long dz, long ceildist, long flordist, long clipmask) +{ + long daz, zoffs, tempint; + short retval, dasectnum, datempshort; + spritetype *spr; + + spr = &sprite[spritenum]; + + if ((spr->cstat&128) == 0) + zoffs = -((tilesizy[spr->picnum]*spr->yrepeat)<<1); + else + zoffs = 0; + + dasectnum = spr->sectnum; //Can't modify sprite sectors directly becuase of linked lists + daz = spr->z+zoffs; //Must do this if not using the new centered centering (of course) + retval = clipmove(&spr->x,&spr->y,&daz,&dasectnum,dx,dy, + ((long)spr->clipdist)<<2,ceildist,flordist,clipmask); + + if (dasectnum < 0) retval = -1; + + if ((dasectnum != spr->sectnum) && (dasectnum >= 0)) + changespritesect(spritenum,dasectnum); + + //Set the blocking bit to 0 temporarly so getzrange doesn't pick up + //its own sprite + datempshort = spr->cstat; spr->cstat &= ~1; + getzrange(spr->x,spr->y,spr->z-1,spr->sectnum, + &globhiz,&globhihit,&globloz,&globlohit, + ((long)spr->clipdist)<<2,clipmask); + spr->cstat = datempshort; + + daz = spr->z+zoffs + dz; + if ((daz <= globhiz) || (daz > globloz)) + { + if (retval != 0) return(retval); + return(16384+dasectnum); + } + spr->z = daz-zoffs; + return(retval); +} + + +void waitforeverybody () +{ + long i; + if (numplayers < 2) return; + packbuf[0] = 250; + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (i != myconnectindex) sendpacket(i,packbuf,1); + if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master + } + playerreadyflag[myconnectindex]++; + while (1) + { + handleevents(); + refreshaudio(); + + drawrooms(posx[myconnectindex],posy[myconnectindex],posz[myconnectindex],ang[myconnectindex],horiz[myconnectindex],cursectnum[myconnectindex]); + if (!networkmode) Bsprintf(tempbuf,"Master/slave mode"); + else Bsprintf(tempbuf,"Peer-peer mode"); + printext256((xdim>>1)-(strlen(tempbuf)<<2),(ydim>>1)-24,31,0,tempbuf,0); + Bsprintf(tempbuf,"Waiting for players"); + printext256((xdim>>1)-(strlen(tempbuf)<<2),(ydim>>1)-16,31,0,tempbuf,0); + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (playerreadyflag[i] < playerreadyflag[myconnectindex]) + { + //slaves in M/S mode only wait for master + if ((!networkmode) && (myconnectindex != connecthead) && (i != connecthead)) + { + Bsprintf(tempbuf,"Player %ld",i); + printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,15,0,tempbuf,0); + } + else + { + Bsprintf(tempbuf,"Player %ld NOT ready",i); + printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,127,0,tempbuf,0); + } + } + else + { + Bsprintf(tempbuf,"Player %ld ready",i); + printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,31,0,tempbuf,0); + } + if (i == myconnectindex) + { + Bsprintf(tempbuf,"You->"); + printext256((xdim>>1)-(26<<2),(ydim>>1)+i*8,95,0,tempbuf,0); + } + } + nextpage(); + + + if (quitevent || keystatus[1]) { + sendlogoff(); //Signing off + musicoff(); + uninitmultiplayers(); + uninittimer(); + uninitinput(); + uninitengine(); + uninitsb(); + uninitgroupfile(); + exit(0); + } + + getpackets(); + + for(i=connecthead;i>=0;i=connectpoint2[i]) + { + if (playerreadyflag[i] < playerreadyflag[myconnectindex]) break; + if ((!networkmode) && (myconnectindex != connecthead)) { i = -1; break; } //slaves in M/S mode only wait for master + } + if (i < 0) return; + } +} + + +void searchmap(short startsector) +{ + long i, j, dasect, splc, send, startwall, endwall; + short dapic; + walltype *wal; + + if ((startsector < 0) || (startsector >= numsectors)) return; + for(i=0;i<(MAXSECTORS>>3);i++) show2dsector[i] = 0; + for(i=0;i<(MAXWALLS>>3);i++) show2dwall[i] = 0; + for(i=0;i<(MAXSPRITES>>3);i++) show2dsprite[i] = 0; + + automapping = 0; + + //Search your area recursively & set all show2dsector/show2dwalls + tempshort[0] = startsector; + show2dsector[startsector>>3] |= (1<<(startsector&7)); + dapic = sector[startsector].ceilingpicnum; + if (waloff[dapic] == 0) loadtile(dapic); + dapic = sector[startsector].floorpicnum; + if (waloff[dapic] == 0) loadtile(dapic); + for(splc=0,send=1;splc>3] |= (1<<(i&7)); + dapic = wall[i].picnum; + if (waloff[dapic] == 0) loadtile(dapic); + dapic = wall[i].overpicnum; + if (((dapic&0xfffff000) == 0) && (waloff[dapic] == 0)) loadtile(dapic); + + j = wal->nextsector; + if ((j >= 0) && ((show2dsector[j>>3]&(1<<(j&7))) == 0)) + { + show2dsector[j>>3] |= (1<<(j&7)); + + dapic = sector[j].ceilingpicnum; + if (waloff[dapic] == 0) loadtile(dapic); + dapic = sector[j].floorpicnum; + if (waloff[dapic] == 0) loadtile(dapic); + + tempshort[send++] = (short)j; + } + } + + for(i=headspritesect[dasect];i>=0;i=nextspritesect[i]) + { + show2dsprite[i>>3] |= (1<<(i&7)); + dapic = sprite[i].picnum; + if (waloff[dapic] == 0) loadtile(dapic); + } + } +} + +void setinterpolation(long *posptr) +{ + long i; + + if (numinterpolations >= MAXINTERPOLATIONS) return; + for(i=numinterpolations-1;i>=0;i--) + if (curipos[i] == posptr) return; + curipos[numinterpolations] = posptr; + oldipos[numinterpolations] = *posptr; + numinterpolations++; +} + +void stopinterpolation(long *posptr) +{ + long i; + + for(i=numinterpolations-1;i>=startofdynamicinterpolations;i--) + if (curipos[i] == posptr) + { + numinterpolations--; + oldipos[i] = oldipos[numinterpolations]; + bakipos[i] = bakipos[numinterpolations]; + curipos[i] = curipos[numinterpolations]; + } +} + +void updateinterpolations(void) //Stick at beginning of domovethings +{ + long i; + + for(i=numinterpolations-1;i>=0;i--) oldipos[i] = *curipos[i]; +} + +void dointerpolations(void) //Stick at beginning of drawscreen +{ + long i, j, odelta, ndelta; + + ndelta = 0; j = 0; + for(i=numinterpolations-1;i>=0;i--) + { + bakipos[i] = *curipos[i]; + odelta = ndelta; ndelta = (*curipos[i])-oldipos[i]; + if (odelta != ndelta) j = mulscale16(ndelta,smoothratio); + *curipos[i] = oldipos[i]+j; + } +} + +void restoreinterpolations(void) //Stick at end of drawscreen +{ + long i; + + for(i=numinterpolations-1;i>=0;i--) *curipos[i] = bakipos[i]; +} + +void printext(long x, long y, char *buffer, short tilenum, char invisiblecol) +{ + long i; + char ch; + + for(i=0;buffer[i]!=0;i++) + { + ch = buffer[i]; + rotatesprite((x-((8&15)<<3))<<16,(y-((8>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+64+128,x,y,x+7,y+7); + rotatesprite((x-((ch&15)<<3))<<16,(y-((ch>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+128,x,y,x+7,y+7); + x += 8; + } +} + +void drawtilebackground (long thex, long they, short tilenum, + signed char shade, long cx1, long cy1, + long cx2, long cy2, char dapalnum) +{ + long x, y, xsiz, ysiz, tx1, ty1, tx2, ty2; + + xsiz = tilesizx[tilenum]; tx1 = cx1/xsiz; tx2 = cx2/xsiz; + ysiz = tilesizy[tilenum]; ty1 = cy1/ysiz; ty2 = cy2/ysiz; + + for(x=tx1;x<=tx2;x++) + for(y=ty1;y<=ty2;y++) + rotatesprite(x*xsiz<<16,y*ysiz<<16,65536L,0,tilenum,shade,dapalnum,8+16+64+128,cx1,cy1,cx2,cy2); +} + + +/* + * vim:ts=4:sw=4: + */ diff --git a/polymer/build/include/game.h b/polymer/build/game/game.h old mode 100644 new mode 100755 similarity index 100% rename from polymer/build/include/game.h rename to polymer/build/game/game.h diff --git a/polymer/build/src/jfaud_sound.cpp b/polymer/build/game/jfaud_sound.cpp old mode 100644 new mode 100755 similarity index 93% rename from polymer/build/src/jfaud_sound.cpp rename to polymer/build/game/jfaud_sound.cpp index 5dcbf285d..d52ea32db --- a/polymer/build/src/jfaud_sound.cpp +++ b/polymer/build/game/jfaud_sound.cpp @@ -262,9 +262,8 @@ void setears(long daposx, long daposy, long daxvect, long dayvect) mixer = jfaud->GetWave(); if (!mixer) return; - mixer->SetListenerPosition((float)daposx/UNITSPERMTR, 0.0, (float)-daposy/UNITSPERMTR); - mixer->SetListenerOrientation((float)daxvect/UNITSPERMTR, 0.0, (float)-dayvect/UNITSPERMTR, - 0.0, 1.0, 0.0); + mixer->SetListenerPosition((float)daposx/UNITSPERMTR, 0.0, (float)daposy/UNITSPERMTR); + mixer->SetListenerOrientation((float)daxvect/UNITSPERMTR, 0.0, (float)dayvect/UNITSPERMTR, 0.0, 1.0, 0.0); } static int storehandle(JFAudMixerChannel *handle, long *daxplc, long *dayplc) @@ -311,7 +310,7 @@ void wsayfollow(char *dafilename, long dafreq, long davol, long *daxplc, long *d handl->SetPitch((float)dafreq / 4096.0); handl->SetGain((float)davol / 256.0); - handl->SetPosition((float)(*daxplc) / UNITSPERMTR, 0.0, (float)(-*dayplc) / UNITSPERMTR); + handl->SetPosition((float)(*daxplc) / UNITSPERMTR, 0.0, (float)(*dayplc) / UNITSPERMTR); handl->SetFollowListener(false); handl->SetRolloff(1.0); @@ -373,7 +372,7 @@ void refreshaudio(void) sfxchans[i].handle->SetPosition( (float)(*sfxchans[i].posx)/UNITSPERMTR, 0.0, - (float)(-*sfxchans[i].posy)/UNITSPERMTR); + (float)(*sfxchans[i].posy)/UNITSPERMTR); } jfaud->Update(); } diff --git a/polymer/build/include/names.h b/polymer/build/game/names.h old mode 100644 new mode 100755 similarity index 100% rename from polymer/build/include/names.h rename to polymer/build/game/names.h diff --git a/polymer/build/game/startgtk.game.c b/polymer/build/game/startgtk.game.c new file mode 100755 index 000000000..96033c6ad --- /dev/null +++ b/polymer/build/game/startgtk.game.c @@ -0,0 +1,545 @@ +/* NOTE: Glade will generate code for a dialogue box which you should + * then patch into this file whenever you make a change to the Glade + * template. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifndef LINKED_GTK +# include "dynamicgtk.h" +#endif + +#include "baselayer.h" +#include "compat.h" +#include "build.h" + +#define TAB_CONFIG 0 +#define TAB_MESSAGES 1 + +static struct { + int fullscreen; + int xdim3d, ydim3d, bpp3d; + int forcesetup; +} settings; + +extern int gtkenabled; + +static GtkWidget *startwin = NULL; +static int retval = -1, mode = TAB_MESSAGES; + +// -- SUPPORT FUNCTIONS ------------------------------------------------------- + +#define GLADE_HOOKUP_OBJECT(component,widget,name) \ + g_object_set_data_full (G_OBJECT (component), name, \ + gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) + +#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ + g_object_set_data (G_OBJECT (component), name, widget) + +#define lookup_widget(x,w) \ + (GtkWidget*) g_object_get_data(G_OBJECT(x), w) + +static GdkPixbuf *load_banner(void) +{ + extern const GdkPixdata startbanner_pixdata; + return gdk_pixbuf_from_pixdata(&startbanner_pixdata, FALSE, NULL); +} + +static void SetPage(int n) +{ + if (!gtkenabled || !startwin) return; + mode = n; + gtk_notebook_set_current_page(GTK_NOTEBOOK(lookup_widget(startwin,"tabs")), n); + + // each control in the config page vertical layout plus the start button should be made (in)sensitive + if (n == TAB_CONFIG) n = TRUE; else n = FALSE; + gtk_widget_set_sensitive(lookup_widget(startwin,"startbutton"), n); + gtk_container_foreach(GTK_CONTAINER(lookup_widget(startwin,"configvlayout")), + (GtkCallback)gtk_widget_set_sensitive, (gpointer)n); +} + +static void on_vmode3dcombo_changed(GtkComboBox *, gpointer); +static void PopulateForm(void) +{ + int mode3d, i; + GtkListStore *modes3d; + GtkTreeIter iter; + GtkComboBox *box3d; + char buf[64]; + + mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); + if (mode3d < 0) { + int i, cd[] = { 32, 24, 16, 15, 8, 0 }; + for (i=0; cd[i]; ) { if (cd[i] >= settings.bpp3d) i++; else break; } + for ( ; cd[i]; i++) { + mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); + if (mode3d < 0) continue; + settings.bpp3d = cd[i]; + break; + } + } + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"fullscreencheck")), settings.fullscreen); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"alwaysshowcheck")), settings.forcesetup); + + box3d = GTK_COMBO_BOX(lookup_widget(startwin,"vmode3dcombo")); + modes3d = GTK_LIST_STORE(gtk_combo_box_get_model(box3d)); + gtk_list_store_clear(modes3d); + + for (i=0; i aptr) + gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1); +#if GTK_CHECK_VERSION(2,6,0) + gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE); +#else + { + GtkTextIter iter2 = enditer; + gtk_text_iter_backward_cursor_position(&iter2); + //FIXME: this seems be deleting one too many chars somewhere! + if (!gtk_text_iter_equal(&iter2, &enditer)) + gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE); + } +#endif + aptr = ++bptr; + break; + case 0: + if (bptr > aptr) + gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)); + aptr = bptr; + break; + case '\r': // FIXME + default: + bptr++; + break; + } + } + + mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1); + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0); + gtk_text_buffer_delete_mark(textbuffer, mark); + + return 0; +} + +int startwin_settitle(const char *title) +{ + if (!gtkenabled) return 0; + if (!startwin) return 1; + gtk_window_set_title (GTK_WINDOW (startwin), title); + return 0; +} + +int startwin_idle(void *s) +{ + if (!gtkenabled) return 0; + //if (!startwin) return 1; + gtk_main_iteration_do (FALSE); + return 0; +} + +extern int xdimgame, ydimgame, bppgame, forcesetup; + +int startwin_run(void) +{ + if (!gtkenabled) return 0; + if (!startwin) return 1; + + SetPage(TAB_CONFIG); + + settings.fullscreen = fullscreen; + settings.xdim3d = xdimgame; + settings.ydim3d = ydimgame; + settings.bpp3d = bppgame; + settings.forcesetup = forcesetup; + PopulateForm(); + + gtk_main(); + + SetPage(TAB_MESSAGES); + if (retval) { + fullscreen = settings.fullscreen; + xdimgame = settings.xdim3d; + ydimgame = settings.ydim3d; + bppgame = settings.bpp3d; + forcesetup = settings.forcesetup; + } + + return retval; +} + diff --git a/polymer/build/game/startwin.game.c b/polymer/build/game/startwin.game.c new file mode 100755 index 000000000..ea1ddb119 --- /dev/null +++ b/polymer/build/game/startwin.game.c @@ -0,0 +1,422 @@ +#ifndef RENDERTYPEWIN +#error Only for Windows +#endif + +#include "build.h" +#include "winlayer.h" +#include "compat.h" + +#define WIN32_LEAN_AND_MEAN +#include +#include +#define _WIN32_IE 0x0300 +#include +#include + +#include "startwin.game.h" + +#define TAB_CONFIG 0 +#define TAB_MESSAGES 1 + +static struct { + int fullscreen; + int xdim3d, ydim3d, bpp3d; + int forcesetup; +} settings; + +static HWND startupdlg = NULL; +static HWND pages[2] = { NULL, NULL}; +static int done = -1, mode = TAB_CONFIG; + +static void PopulateForm(void) +{ + int i,j; + char buf[64]; + int mode3d; + HWND hwnd3d; + + hwnd3d = GetDlgItem(pages[TAB_CONFIG], IDC3DVMODE); + + mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); + if (mode3d < 0) { + int cd[] = { 32, 24, 16, 15, 8, 0 }; + for (i=0; cd[i]; ) { if (cd[i] >= settings.bpp3d) i++; else break; } + for ( ; cd[i]; i++) { + mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); + if (mode3d < 0) continue; + settings.bpp3d = cd[i]; + break; + } + } + + Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), (settings.fullscreen ? BST_CHECKED : BST_UNCHECKED)); + Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED)); + + ComboBox_ResetContent(hwnd3d); + for (i=0; iidFrom != WIN_STARTWIN_TABCTL) break; + cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); + switch (nmhdr->code) { + case TCN_SELCHANGING: { + if (cur < 0 || !pages[cur]) break; + ShowWindow(pages[cur],SW_HIDE); + return TRUE; + } + case TCN_SELCHANGE: { + if (cur < 0 || !pages[cur]) break; + ShowWindow(pages[cur],SW_SHOW); + return TRUE; + } + } + break; + } + + case WM_CLOSE: + if (mode == TAB_CONFIG) done = 0; + else quitevent++; + return TRUE; + + case WM_DESTROY: + if (hbmp) { + DeleteObject(hbmp); + hbmp = NULL; + } + + if (pages[TAB_CONFIG]) { + DestroyWindow(pages[TAB_CONFIG]); + pages[TAB_CONFIG] = NULL; + } + + startupdlg = NULL; + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case WIN_STARTWIN_CANCEL: + if (mode == TAB_CONFIG) done = 0; + else quitevent++; + return TRUE; + case WIN_STARTWIN_START: done = 1; return TRUE; + } + return FALSE; + + case WM_CTLCOLORSTATIC: + if ((HWND)lParam == pages[TAB_MESSAGES]) + return (BOOL)GetSysColorBrush(COLOR_WINDOW); + break; + + default: break; + } + + return FALSE; +} + + +int startwin_open(void) +{ + INITCOMMONCONTROLSEX icc; + if (startupdlg) return 1; + icc.dwSize = sizeof(icc); + icc.dwICC = ICC_TAB_CLASSES; + InitCommonControlsEx(&icc); + startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); + if (startupdlg) { + SetPage(TAB_MESSAGES); + EnableConfig(0); + return 0; + } + return -1; +} + +int startwin_close(void) +{ + if (!startupdlg) return 1; + DestroyWindow(startupdlg); + startupdlg = NULL; + return 0; +} + +int startwin_puts(const char *buf) +{ + const char *p = NULL, *q = NULL; + char workbuf[1024]; + static int newline = 0; + int curlen, linesbefore, linesafter; + HWND edctl; + int vis; + + if (!startupdlg) return 1; + + edctl = pages[TAB_MESSAGES]; + if (!edctl) return -1; + + vis = ((int)SendMessage(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL), TCM_GETCURSEL,0,0) == TAB_MESSAGES); + + if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); + curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); + SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); + linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); + p = buf; + while (*p) { + if (newline) { + SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); + newline = 0; + } + q = p; + while (*q && *q != '\n') q++; + memcpy(workbuf, p, q-p); + if (*q == '\n') { + if (!q[1]) { + newline = 1; + workbuf[q-p] = 0; + } else { + workbuf[q-p] = '\r'; + workbuf[q-p+1] = '\n'; + workbuf[q-p+2] = 0; + } + p = q+1; + } else { + workbuf[q-p] = 0; + p = q; + } + SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); + } + linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); + SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); + if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); + return 0; +} + +int startwin_settitle(const char *str) +{ + if (!startupdlg) return 1; + SetWindowText(startupdlg, str); + return 0; +} + +int startwin_idle(void *v) +{ + if (!startupdlg || !IsWindow(startupdlg)) return 0; + if (IsDialogMessage(startupdlg, (MSG*)v)) return 1; + return 0; +} + +extern int xdimgame, ydimgame, bppgame, forcesetup; + +int startwin_run(void) +{ + MSG msg; + if (!startupdlg) return 1; + + done = -1; + + SetPage(TAB_CONFIG); + EnableConfig(1); + + settings.fullscreen = fullscreen; + settings.xdim3d = xdimgame; + settings.ydim3d = ydimgame; + settings.bpp3d = bppgame; + settings.forcesetup = forcesetup; + PopulateForm(); + + while (done < 0) { + switch (GetMessage(&msg, NULL, 0,0)) { + case 0: done = 1; break; + case -1: return -1; + default: + if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; + TranslateMessage(&msg); + DispatchMessage(&msg); + break; + } + } + + SetPage(TAB_MESSAGES); + EnableConfig(0); + if (done) { + fullscreen = settings.fullscreen; + xdimgame = settings.xdim3d; + ydimgame = settings.ydim3d; + bppgame = settings.bpp3d; + forcesetup = settings.forcesetup; + } + + return done; +} + diff --git a/polymer/build/src/startwin.game.h b/polymer/build/game/startwin.game.h similarity index 100% rename from polymer/build/src/startwin.game.h rename to polymer/build/game/startwin.game.h diff --git a/polymer/build/include/pragmas.h b/polymer/build/include/pragmas.h index 9b4afa429..df0684af3 100644 --- a/polymer/build/include/pragmas.h +++ b/polymer/build/include/pragmas.h @@ -5,6 +5,10 @@ #ifndef __pragmas_h__ #define __pragmas_h__ +#ifdef __cplusplus +extern "C" { +#endif + extern long dmval; #if defined(__GNUC__) && defined(__i386__) && !defined(NOASM) @@ -1071,251 +1075,252 @@ void copybufreverse(void *S, void *D, long c); // //{{{ +long sqr(long); #pragma aux sqr =\ "imul eax, eax",\ parm nomemory [eax]\ modify exact [eax]\ value [eax] -long sqr(long); +long scale(long,long,long); #pragma aux scale =\ "imul edx",\ "idiv ecx",\ parm nomemory [eax][edx][ecx]\ modify exact [eax edx] -long scale(long,long,long); +long mulscale(long,long,long); #pragma aux mulscale =\ "imul edx",\ "shrd eax, edx, cl",\ parm nomemory [eax][edx][ecx]\ modify exact [eax edx] -long mulscale(long,long,long); +long mulscale1(long,long); #pragma aux mulscale1 =\ "imul edx",\ "shrd eax, edx, 1",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale1(long,long); +long mulscale2(long,long); #pragma aux mulscale2 =\ "imul edx",\ "shrd eax, edx, 2",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale2(long,long); +long mulscale3(long,long); #pragma aux mulscale3 =\ "imul edx",\ "shrd eax, edx, 3",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale3(long,long); +long mulscale4(long,long); #pragma aux mulscale4 =\ "imul edx",\ "shrd eax, edx, 4",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale4(long,long); +long mulscale5(long,long); #pragma aux mulscale5 =\ "imul edx",\ "shrd eax, edx, 5",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale5(long,long); +long mulscale6(long,long); #pragma aux mulscale6 =\ "imul edx",\ "shrd eax, edx, 6",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale6(long,long); +long mulscale7(long,long); #pragma aux mulscale7 =\ "imul edx",\ "shrd eax, edx, 7",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale7(long,long); +long mulscale8(long,long); #pragma aux mulscale8 =\ "imul edx",\ "shrd eax, edx, 8",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale8(long,long); +long mulscale9(long,long); #pragma aux mulscale9 =\ "imul edx",\ "shrd eax, edx, 9",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale9(long,long); +long mulscale10(long,long); #pragma aux mulscale10 =\ "imul edx",\ "shrd eax, edx, 10",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale10(long,long); +long mulscale11(long,long); #pragma aux mulscale11 =\ "imul edx",\ "shrd eax, edx, 11",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale11(long,long); +long mulscale12(long,long); #pragma aux mulscale12 =\ "imul edx",\ "shrd eax, edx, 12",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale12(long,long); +long mulscale13(long,long); #pragma aux mulscale13 =\ "imul edx",\ "shrd eax, edx, 13",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale13(long,long); +long mulscale14(long,long); #pragma aux mulscale14 =\ "imul edx",\ "shrd eax, edx, 14",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale14(long,long); +long mulscale15(long,long); #pragma aux mulscale15 =\ "imul edx",\ "shrd eax, edx, 15",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale15(long,long); +long mulscale16(long,long); #pragma aux mulscale16 =\ "imul edx",\ "shrd eax, edx, 16",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale16(long,long); +long mulscale17(long,long); #pragma aux mulscale17 =\ "imul edx",\ "shrd eax, edx, 17",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale17(long,long); +long mulscale18(long,long); #pragma aux mulscale18 =\ "imul edx",\ "shrd eax, edx, 18",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale18(long,long); +long mulscale19(long,long); #pragma aux mulscale19 =\ "imul edx",\ "shrd eax, edx, 19",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale19(long,long); +long mulscale20(long,long); #pragma aux mulscale20 =\ "imul edx",\ "shrd eax, edx, 20",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale20(long,long); +long mulscale21(long,long); #pragma aux mulscale21 =\ "imul edx",\ "shrd eax, edx, 21",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale21(long,long); +long mulscale22(long,long); #pragma aux mulscale22 =\ "imul edx",\ "shrd eax, edx, 22",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale22(long,long); +long mulscale23(long,long); #pragma aux mulscale23 =\ "imul edx",\ "shrd eax, edx, 23",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale23(long,long); +long mulscale24(long,long); #pragma aux mulscale24 =\ "imul edx",\ "shrd eax, edx, 24",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale24(long,long); +long mulscale25(long,long); #pragma aux mulscale25 =\ "imul edx",\ "shrd eax, edx, 25",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale25(long,long); +long mulscale26(long,long); #pragma aux mulscale26 =\ "imul edx",\ "shrd eax, edx, 26",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale26(long,long); +long mulscale27(long,long); #pragma aux mulscale27 =\ "imul edx",\ "shrd eax, edx, 27",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale27(long,long); +long mulscale28(long,long); #pragma aux mulscale28 =\ "imul edx",\ "shrd eax, edx, 28",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale28(long,long); +long mulscale29(long,long); #pragma aux mulscale29 =\ "imul edx",\ "shrd eax, edx, 29",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale29(long,long); +long mulscale30(long,long); #pragma aux mulscale30 =\ "imul edx",\ "shrd eax, edx, 30",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale30(long,long); +long mulscale31(long,long); #pragma aux mulscale31 =\ "imul edx",\ "shrd eax, edx, 31",\ parm nomemory [eax][edx]\ modify exact [eax edx] -long mulscale31(long,long); +long mulscale32(long,long); #pragma aux mulscale32 =\ "imul edx",\ parm nomemory [eax][edx]\ modify exact [eax edx]\ value [edx] -long mulscale32(long,long); +long dmulscale(long,long,long,long,long); #pragma aux dmulscale =\ "imul edx",\ "mov ebx, eax",\ @@ -1327,8 +1332,8 @@ long mulscale32(long,long); "shrd eax, edx, cl",\ parm nomemory [eax][edx][esi][edi][ecx]\ modify exact [eax ebx edx esi] -long dmulscale(long,long,long,long,long); +long dmulscale1(long,long,long,long); #pragma aux dmulscale1 =\ "imul edx",\ "mov ebx, eax",\ @@ -1340,8 +1345,8 @@ long dmulscale(long,long,long,long,long); "shrd eax, edx, 1",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale1(long,long,long,long); +long dmulscale2(long,long,long,long); #pragma aux dmulscale2 =\ "imul edx",\ "mov ebx, eax",\ @@ -1353,8 +1358,8 @@ long dmulscale1(long,long,long,long); "shrd eax, edx, 2",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale2(long,long,long,long); +long dmulscale3(long,long,long,long); #pragma aux dmulscale3 =\ "imul edx",\ "mov ebx, eax",\ @@ -1366,8 +1371,8 @@ long dmulscale2(long,long,long,long); "shrd eax, edx, 3",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale3(long,long,long,long); +long dmulscale4(long,long,long,long); #pragma aux dmulscale4 =\ "imul edx",\ "mov ebx, eax",\ @@ -1379,8 +1384,8 @@ long dmulscale3(long,long,long,long); "shrd eax, edx, 4",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale4(long,long,long,long); +long dmulscale5(long,long,long,long); #pragma aux dmulscale5 =\ "imul edx",\ "mov ebx, eax",\ @@ -1392,8 +1397,8 @@ long dmulscale4(long,long,long,long); "shrd eax, edx, 5",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale5(long,long,long,long); +long dmulscale6(long,long,long,long); #pragma aux dmulscale6 =\ "imul edx",\ "mov ebx, eax",\ @@ -1405,8 +1410,8 @@ long dmulscale5(long,long,long,long); "shrd eax, edx, 6",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale6(long,long,long,long); +long dmulscale7(long,long,long,long); #pragma aux dmulscale7 =\ "imul edx",\ "mov ebx, eax",\ @@ -1418,8 +1423,8 @@ long dmulscale6(long,long,long,long); "shrd eax, edx, 7",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale7(long,long,long,long); +long dmulscale8(long,long,long,long); #pragma aux dmulscale8 =\ "imul edx",\ "mov ebx, eax",\ @@ -1431,8 +1436,8 @@ long dmulscale7(long,long,long,long); "shrd eax, edx, 8",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale8(long,long,long,long); +long dmulscale9(long,long,long,long); #pragma aux dmulscale9 =\ "imul edx",\ "mov ebx, eax",\ @@ -1444,8 +1449,8 @@ long dmulscale8(long,long,long,long); "shrd eax, edx, 9",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale9(long,long,long,long); +long dmulscale10(long,long,long,long); #pragma aux dmulscale10 =\ "imul edx",\ "mov ebx, eax",\ @@ -1457,8 +1462,8 @@ long dmulscale9(long,long,long,long); "shrd eax, edx, 10",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale10(long,long,long,long); +long dmulscale11(long,long,long,long); #pragma aux dmulscale11 =\ "imul edx",\ "mov ebx, eax",\ @@ -1470,8 +1475,8 @@ long dmulscale10(long,long,long,long); "shrd eax, edx, 11",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale11(long,long,long,long); +long dmulscale12(long,long,long,long); #pragma aux dmulscale12 =\ "imul edx",\ "mov ebx, eax",\ @@ -1483,8 +1488,8 @@ long dmulscale11(long,long,long,long); "shrd eax, edx, 12",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale12(long,long,long,long); +long dmulscale13(long,long,long,long); #pragma aux dmulscale13 =\ "imul edx",\ "mov ebx, eax",\ @@ -1496,8 +1501,8 @@ long dmulscale12(long,long,long,long); "shrd eax, edx, 13",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale13(long,long,long,long); +long dmulscale14(long,long,long,long); #pragma aux dmulscale14 =\ "imul edx",\ "mov ebx, eax",\ @@ -1509,8 +1514,8 @@ long dmulscale13(long,long,long,long); "shrd eax, edx, 14",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale14(long,long,long,long); +long dmulscale15(long,long,long,long); #pragma aux dmulscale15 =\ "imul edx",\ "mov ebx, eax",\ @@ -1522,8 +1527,8 @@ long dmulscale14(long,long,long,long); "shrd eax, edx, 15",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale15(long,long,long,long); +long dmulscale16(long,long,long,long); #pragma aux dmulscale16 =\ "imul edx",\ "mov ebx, eax",\ @@ -1535,8 +1540,8 @@ long dmulscale15(long,long,long,long); "shrd eax, edx, 16",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale16(long,long,long,long); +long dmulscale17(long,long,long,long); #pragma aux dmulscale17 =\ "imul edx",\ "mov ebx, eax",\ @@ -1548,8 +1553,8 @@ long dmulscale16(long,long,long,long); "shrd eax, edx, 17",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale17(long,long,long,long); +long dmulscale18(long,long,long,long); #pragma aux dmulscale18 =\ "imul edx",\ "mov ebx, eax",\ @@ -1561,8 +1566,8 @@ long dmulscale17(long,long,long,long); "shrd eax, edx, 18",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale18(long,long,long,long); +long dmulscale19(long,long,long,long); #pragma aux dmulscale19 =\ "imul edx",\ "mov ebx, eax",\ @@ -1574,8 +1579,8 @@ long dmulscale18(long,long,long,long); "shrd eax, edx, 19",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale19(long,long,long,long); +long dmulscale20(long,long,long,long); #pragma aux dmulscale20 =\ "imul edx",\ "mov ebx, eax",\ @@ -1587,8 +1592,8 @@ long dmulscale19(long,long,long,long); "shrd eax, edx, 20",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale20(long,long,long,long); +long dmulscale21(long,long,long,long); #pragma aux dmulscale21 =\ "imul edx",\ "mov ebx, eax",\ @@ -1600,8 +1605,8 @@ long dmulscale20(long,long,long,long); "shrd eax, edx, 21",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale21(long,long,long,long); +long dmulscale22(long,long,long,long); #pragma aux dmulscale22 =\ "imul edx",\ "mov ebx, eax",\ @@ -1613,8 +1618,8 @@ long dmulscale21(long,long,long,long); "shrd eax, edx, 22",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale22(long,long,long,long); +long dmulscale23(long,long,long,long); #pragma aux dmulscale23 =\ "imul edx",\ "mov ebx, eax",\ @@ -1626,8 +1631,8 @@ long dmulscale22(long,long,long,long); "shrd eax, edx, 23",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale23(long,long,long,long); +long dmulscale24(long,long,long,long); #pragma aux dmulscale24 =\ "imul edx",\ "mov ebx, eax",\ @@ -1639,8 +1644,8 @@ long dmulscale23(long,long,long,long); "shrd eax, edx, 24",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale24(long,long,long,long); +long dmulscale25(long,long,long,long); #pragma aux dmulscale25 =\ "imul edx",\ "mov ebx, eax",\ @@ -1652,8 +1657,8 @@ long dmulscale24(long,long,long,long); "shrd eax, edx, 25",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale25(long,long,long,long); +long dmulscale26(long,long,long,long); #pragma aux dmulscale26 =\ "imul edx",\ "mov ebx, eax",\ @@ -1665,8 +1670,8 @@ long dmulscale25(long,long,long,long); "shrd eax, edx, 26",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale26(long,long,long,long); +long dmulscale27(long,long,long,long); #pragma aux dmulscale27 =\ "imul edx",\ "mov ebx, eax",\ @@ -1678,8 +1683,8 @@ long dmulscale26(long,long,long,long); "shrd eax, edx, 27",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale27(long,long,long,long); +long dmulscale28(long,long,long,long); #pragma aux dmulscale28 =\ "imul edx",\ "mov ebx, eax",\ @@ -1691,8 +1696,8 @@ long dmulscale27(long,long,long,long); "shrd eax, edx, 28",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale28(long,long,long,long); +long dmulscale29(long,long,long,long); #pragma aux dmulscale29 =\ "imul edx",\ "mov ebx, eax",\ @@ -1704,8 +1709,8 @@ long dmulscale28(long,long,long,long); "shrd eax, edx, 29",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale29(long,long,long,long); +long dmulscale30(long,long,long,long); #pragma aux dmulscale30 =\ "imul edx",\ "mov ebx, eax",\ @@ -1717,8 +1722,8 @@ long dmulscale29(long,long,long,long); "shrd eax, edx, 30",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale30(long,long,long,long); +long dmulscale31(long,long,long,long); #pragma aux dmulscale31 =\ "imul edx",\ "mov ebx, eax",\ @@ -1730,8 +1735,8 @@ long dmulscale30(long,long,long,long); "shrd eax, edx, 31",\ parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi] -long dmulscale31(long,long,long,long); +long dmulscale32(long,long,long,long); #pragma aux dmulscale32 =\ "imul edx",\ "mov ebx, eax",\ @@ -1743,8 +1748,8 @@ long dmulscale31(long,long,long,long); parm nomemory [eax][edx][esi][edi]\ modify exact [eax ebx edx esi]\ value [edx] -long dmulscale32(long,long,long,long); +long tmulscale1(long,long,long,long,long,long); #pragma aux tmulscale1 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1759,8 +1764,8 @@ long dmulscale32(long,long,long,long); "shrd eax, edx, 1",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale1(long,long,long,long,long,long); +long tmulscale2(long,long,long,long,long,long); #pragma aux tmulscale2 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1775,8 +1780,8 @@ long tmulscale1(long,long,long,long,long,long); "shrd eax, edx, 2",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale2(long,long,long,long,long,long); +long tmulscale3(long,long,long,long,long,long); #pragma aux tmulscale3 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1791,8 +1796,8 @@ long tmulscale2(long,long,long,long,long,long); "shrd eax, edx, 3",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale3(long,long,long,long,long,long); +long tmulscale4(long,long,long,long,long,long); #pragma aux tmulscale4 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1807,8 +1812,8 @@ long tmulscale3(long,long,long,long,long,long); "shrd eax, edx, 4",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale4(long,long,long,long,long,long); +long tmulscale5(long,long,long,long,long,long); #pragma aux tmulscale5 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1823,8 +1828,8 @@ long tmulscale4(long,long,long,long,long,long); "shrd eax, edx, 5",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale5(long,long,long,long,long,long); +long tmulscale6(long,long,long,long,long,long); #pragma aux tmulscale6 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1839,8 +1844,8 @@ long tmulscale5(long,long,long,long,long,long); "shrd eax, edx, 6",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale6(long,long,long,long,long,long); +long tmulscale7(long,long,long,long,long,long); #pragma aux tmulscale7 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1855,8 +1860,8 @@ long tmulscale6(long,long,long,long,long,long); "shrd eax, edx, 7",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale7(long,long,long,long,long,long); +long tmulscale8(long,long,long,long,long,long); #pragma aux tmulscale8 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1871,8 +1876,8 @@ long tmulscale7(long,long,long,long,long,long); "shrd eax, edx, 8",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale8(long,long,long,long,long,long); +long tmulscale9(long,long,long,long,long,long); #pragma aux tmulscale9 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1887,8 +1892,8 @@ long tmulscale8(long,long,long,long,long,long); "shrd eax, edx, 9",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale9(long,long,long,long,long,long); +long tmulscale10(long,long,long,long,long,long); #pragma aux tmulscale10 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1903,8 +1908,8 @@ long tmulscale9(long,long,long,long,long,long); "shrd eax, edx, 10",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale10(long,long,long,long,long,long); +long tmulscale11(long,long,long,long,long,long); #pragma aux tmulscale11 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1919,8 +1924,8 @@ long tmulscale10(long,long,long,long,long,long); "shrd eax, edx, 11",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale11(long,long,long,long,long,long); +long tmulscale12(long,long,long,long,long,long); #pragma aux tmulscale12 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1935,8 +1940,8 @@ long tmulscale11(long,long,long,long,long,long); "shrd eax, edx, 12",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale12(long,long,long,long,long,long); +long tmulscale13(long,long,long,long,long,long); #pragma aux tmulscale13 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1951,8 +1956,8 @@ long tmulscale12(long,long,long,long,long,long); "shrd eax, edx, 13",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale13(long,long,long,long,long,long); +long tmulscale14(long,long,long,long,long,long); #pragma aux tmulscale14 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1967,8 +1972,8 @@ long tmulscale13(long,long,long,long,long,long); "shrd eax, edx, 14",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale14(long,long,long,long,long,long); +long tmulscale15(long,long,long,long,long,long); #pragma aux tmulscale15 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1983,8 +1988,8 @@ long tmulscale14(long,long,long,long,long,long); "shrd eax, edx, 15",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale15(long,long,long,long,long,long); +long tmulscale16(long,long,long,long,long,long); #pragma aux tmulscale16 =\ "imul edx",\ "xchg eax, ebx",\ @@ -1999,8 +2004,8 @@ long tmulscale15(long,long,long,long,long,long); "shrd eax, edx, 16",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale16(long,long,long,long,long,long); +long tmulscale17(long,long,long,long,long,long); #pragma aux tmulscale17 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2015,8 +2020,8 @@ long tmulscale16(long,long,long,long,long,long); "shrd eax, edx, 17",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale17(long,long,long,long,long,long); +long tmulscale18(long,long,long,long,long,long); #pragma aux tmulscale18 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2031,8 +2036,8 @@ long tmulscale17(long,long,long,long,long,long); "shrd eax, edx, 18",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale18(long,long,long,long,long,long); +long tmulscale19(long,long,long,long,long,long); #pragma aux tmulscale19 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2047,8 +2052,8 @@ long tmulscale18(long,long,long,long,long,long); "shrd eax, edx, 19",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale19(long,long,long,long,long,long); +long tmulscale20(long,long,long,long,long,long); #pragma aux tmulscale20 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2063,8 +2068,8 @@ long tmulscale19(long,long,long,long,long,long); "shrd eax, edx, 20",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale20(long,long,long,long,long,long); +long tmulscale21(long,long,long,long,long,long); #pragma aux tmulscale21 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2079,8 +2084,8 @@ long tmulscale20(long,long,long,long,long,long); "shrd eax, edx, 21",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale21(long,long,long,long,long,long); +long tmulscale22(long,long,long,long,long,long); #pragma aux tmulscale22 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2095,8 +2100,8 @@ long tmulscale21(long,long,long,long,long,long); "shrd eax, edx, 22",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale22(long,long,long,long,long,long); +long tmulscale23(long,long,long,long,long,long); #pragma aux tmulscale23 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2111,8 +2116,8 @@ long tmulscale22(long,long,long,long,long,long); "shrd eax, edx, 23",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale23(long,long,long,long,long,long); +long tmulscale24(long,long,long,long,long,long); #pragma aux tmulscale24 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2127,8 +2132,8 @@ long tmulscale23(long,long,long,long,long,long); "shrd eax, edx, 24",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale24(long,long,long,long,long,long); +long tmulscale25(long,long,long,long,long,long); #pragma aux tmulscale25 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2143,8 +2148,8 @@ long tmulscale24(long,long,long,long,long,long); "shrd eax, edx, 25",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale25(long,long,long,long,long,long); +long tmulscale26(long,long,long,long,long,long); #pragma aux tmulscale26 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2159,8 +2164,8 @@ long tmulscale25(long,long,long,long,long,long); "shrd eax, edx, 26",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale26(long,long,long,long,long,long); +long tmulscale27(long,long,long,long,long,long); #pragma aux tmulscale27 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2175,8 +2180,8 @@ long tmulscale26(long,long,long,long,long,long); "shrd eax, edx, 27",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale27(long,long,long,long,long,long); +long tmulscale28(long,long,long,long,long,long); #pragma aux tmulscale28 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2191,8 +2196,8 @@ long tmulscale27(long,long,long,long,long,long); "shrd eax, edx, 28",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale28(long,long,long,long,long,long); +long tmulscale29(long,long,long,long,long,long); #pragma aux tmulscale29 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2207,8 +2212,8 @@ long tmulscale28(long,long,long,long,long,long); "shrd eax, edx, 29",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale29(long,long,long,long,long,long); +long tmulscale30(long,long,long,long,long,long); #pragma aux tmulscale30 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2223,8 +2228,8 @@ long tmulscale29(long,long,long,long,long,long); "shrd eax, edx, 30",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale30(long,long,long,long,long,long); +long tmulscale31(long,long,long,long,long,long); #pragma aux tmulscale31 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2239,8 +2244,8 @@ long tmulscale30(long,long,long,long,long,long); "shrd eax, edx, 31",\ parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx] -long tmulscale31(long,long,long,long,long,long); +long tmulscale32(long,long,long,long,long,long); #pragma aux tmulscale32 =\ "imul edx",\ "xchg eax, ebx",\ @@ -2255,8 +2260,8 @@ long tmulscale31(long,long,long,long,long,long); parm nomemory [eax][edx][ebx][ecx][esi][edi]\ modify exact [eax ebx ecx edx]\ value [edx] -long tmulscale32(long,long,long,long,long,long); +long boundmulscale(long,long,long); #pragma aux boundmulscale =\ "imul ebx",\ "mov ebx, edx",\ @@ -2275,8 +2280,8 @@ long tmulscale32(long,long,long,long,long,long); "skipboundit:",\ parm nomemory [eax][ebx][ecx]\ modify exact [eax ebx edx] -long boundmulscale(long,long,long); +long divscale(long,long,long); #pragma aux divscale =\ "mov edx, eax",\ "shl eax, cl",\ @@ -2285,16 +2290,16 @@ long boundmulscale(long,long,long); "idiv ebx",\ parm nomemory [eax][ebx][ecx]\ modify exact [eax ecx edx] -long divscale(long,long,long); +long divscale1(long,long); #pragma aux divscale1 =\ "add eax, eax",\ "sbb edx, edx",\ "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale1(long,long); +long divscale2(long,long); #pragma aux divscale2 =\ "mov edx, eax",\ "sar edx, 30",\ @@ -2302,8 +2307,8 @@ long divscale1(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale2(long,long); +long divscale3(long,long); #pragma aux divscale3 =\ "mov edx, eax",\ "sar edx, 29",\ @@ -2311,8 +2316,8 @@ long divscale2(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale3(long,long); +long divscale4(long,long); #pragma aux divscale4 =\ "mov edx, eax",\ "sar edx, 28",\ @@ -2320,8 +2325,8 @@ long divscale3(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale4(long,long); +long divscale5(long,long); #pragma aux divscale5 =\ "mov edx, eax",\ "sar edx, 27",\ @@ -2329,8 +2334,8 @@ long divscale4(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale5(long,long); +long divscale6(long,long); #pragma aux divscale6 =\ "mov edx, eax",\ "sar edx, 26",\ @@ -2338,8 +2343,8 @@ long divscale5(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale6(long,long); +long divscale7(long,long); #pragma aux divscale7 =\ "mov edx, eax",\ "sar edx, 25",\ @@ -2347,8 +2352,8 @@ long divscale6(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale7(long,long); +long divscale8(long,long); #pragma aux divscale8 =\ "mov edx, eax",\ "sar edx, 24",\ @@ -2356,8 +2361,8 @@ long divscale7(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale8(long,long); +long divscale9(long,long); #pragma aux divscale9 =\ "mov edx, eax",\ "sar edx, 23",\ @@ -2365,8 +2370,8 @@ long divscale8(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale9(long,long); +long divscale10(long,long); #pragma aux divscale10 =\ "mov edx, eax",\ "sar edx, 22",\ @@ -2374,8 +2379,8 @@ long divscale9(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale10(long,long); +long divscale11(long,long); #pragma aux divscale11 =\ "mov edx, eax",\ "sar edx, 21",\ @@ -2383,8 +2388,8 @@ long divscale10(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale11(long,long); +long divscale12(long,long); #pragma aux divscale12 =\ "mov edx, eax",\ "sar edx, 20",\ @@ -2392,8 +2397,8 @@ long divscale11(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale12(long,long); +long divscale13(long,long); #pragma aux divscale13 =\ "mov edx, eax",\ "sar edx, 19",\ @@ -2401,8 +2406,8 @@ long divscale12(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale13(long,long); +long divscale14(long,long); #pragma aux divscale14 =\ "mov edx, eax",\ "sar edx, 18",\ @@ -2410,8 +2415,8 @@ long divscale13(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale14(long,long); +long divscale15(long,long); #pragma aux divscale15 =\ "mov edx, eax",\ "sar edx, 17",\ @@ -2419,8 +2424,8 @@ long divscale14(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale15(long,long); +long divscale16(long,long); #pragma aux divscale16 =\ "mov edx, eax",\ "sar edx, 16",\ @@ -2428,8 +2433,8 @@ long divscale15(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale16(long,long); +long divscale17(long,long); #pragma aux divscale17 =\ "mov edx, eax",\ "sar edx, 15",\ @@ -2437,8 +2442,8 @@ long divscale16(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale17(long,long); +long divscale18(long,long); #pragma aux divscale18 =\ "mov edx, eax",\ "sar edx, 14",\ @@ -2446,8 +2451,8 @@ long divscale17(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale18(long,long); +long divscale19(long,long); #pragma aux divscale19 =\ "mov edx, eax",\ "sar edx, 13",\ @@ -2455,8 +2460,8 @@ long divscale18(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale19(long,long); +long divscale20(long,long); #pragma aux divscale20 =\ "mov edx, eax",\ "sar edx, 12",\ @@ -2464,8 +2469,8 @@ long divscale19(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale20(long,long); +long divscale21(long,long); #pragma aux divscale21 =\ "mov edx, eax",\ "sar edx, 11",\ @@ -2473,8 +2478,8 @@ long divscale20(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale21(long,long); +long divscale22(long,long); #pragma aux divscale22 =\ "mov edx, eax",\ "sar edx, 10",\ @@ -2482,8 +2487,8 @@ long divscale21(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale22(long,long); +long divscale23(long,long); #pragma aux divscale23 =\ "mov edx, eax",\ "sar edx, 9",\ @@ -2491,8 +2496,8 @@ long divscale22(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale23(long,long); +long divscale24(long,long); #pragma aux divscale24 =\ "mov edx, eax",\ "sar edx, 8",\ @@ -2500,8 +2505,8 @@ long divscale23(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale24(long,long); +long divscale25(long,long); #pragma aux divscale25 =\ "mov edx, eax",\ "sar edx, 7",\ @@ -2509,8 +2514,8 @@ long divscale24(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale25(long,long); +long divscale26(long,long); #pragma aux divscale26 =\ "mov edx, eax",\ "sar edx, 6",\ @@ -2518,8 +2523,8 @@ long divscale25(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale26(long,long); +long divscale27(long,long); #pragma aux divscale27 =\ "mov edx, eax",\ "sar edx, 5",\ @@ -2527,8 +2532,8 @@ long divscale26(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale27(long,long); +long divscale28(long,long); #pragma aux divscale28 =\ "mov edx, eax",\ "sar edx, 4",\ @@ -2536,8 +2541,8 @@ long divscale27(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale28(long,long); +long divscale29(long,long); #pragma aux divscale29 =\ "mov edx, eax",\ "sar edx, 3",\ @@ -2545,8 +2550,8 @@ long divscale28(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale29(long,long); +long divscale30(long,long); #pragma aux divscale30 =\ "mov edx, eax",\ "sar edx, 2",\ @@ -2554,8 +2559,8 @@ long divscale29(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale30(long,long); +long divscale31(long,long); #pragma aux divscale31 =\ "mov edx, eax",\ "sar edx, 1",\ @@ -2563,45 +2568,45 @@ long divscale30(long,long); "idiv ebx",\ parm nomemory [eax][ebx]\ modify exact [eax edx] -long divscale31(long,long); +long divscale32(long,long); #pragma aux divscale32 =\ "xor eax, eax",\ "idiv ebx",\ parm nomemory [edx][ebx]\ modify exact [eax edx] -long divscale32(long,long); +long readpixel(void*); #pragma aux readpixel =\ "mov al, byte ptr [edi]",\ parm nomemory [edi]\ modify exact [eax] -long readpixel(void*); +long drawpixel(void*,long); #pragma aux drawpixel =\ "mov byte ptr [edi], al",\ parm [edi][eax]\ modify exact -long drawpixel(void*,long); +long drawpixels(void*,long); #pragma aux drawpixels =\ "mov word ptr [edi], ax",\ parm [edi][eax]\ modify exact -long drawpixels(void*,long); +long drawpixelses(void*,long); #pragma aux drawpixelses =\ "mov dword ptr [edi], eax",\ parm [edi][eax]\ modify exact -long drawpixelses(void*,long); +long clearbuf(void*,long,long); #pragma aux clearbuf =\ "rep stosd",\ parm [edi][ecx][eax]\ modify exact [edi ecx] -long clearbuf(void*,long,long); +long clearbufbyte(void*,long,long); #pragma aux clearbufbyte =\ "cmp ecx, 4",\ "jae longcopy",\ @@ -2631,14 +2636,14 @@ long clearbuf(void*,long,long); "endit:",\ parm [edi][ecx][eax]\ modify [ebx] -long clearbufbyte(void*,long,long); +long copybuf(void*,void*,long); #pragma aux copybuf =\ "rep movsd",\ parm [esi][edi][ecx]\ modify exact [ecx esi edi] -long copybuf(void*,void*,long); +long copybufbyte(void*,void*,long); #pragma aux copybufbyte =\ "cmp ecx, 4",\ "jae longcopy",\ @@ -2668,8 +2673,8 @@ long copybuf(void*,void*,long); "endit:",\ parm [esi][edi][ecx]\ modify [ebx] -long copybufbyte(void*,void*,long); +long copybufreverse(void*,void*,long); #pragma aux copybufreverse =\ "shr ecx, 1",\ "jnc skipit1",\ @@ -2695,8 +2700,8 @@ long copybufbyte(void*,void*,long); "jnz begloop",\ "endloop:",\ parm [esi][edi][ecx] -long copybufreverse(void*,void*,long); +long qinterpolatedown16(long,long,long,long); #pragma aux qinterpolatedown16 =\ "mov ebx, ecx",\ "shr ecx, 1",\ @@ -2717,8 +2722,8 @@ long copybufreverse(void*,void*,long); "skipbegqcalc2:",\ parm [eax][ecx][edx][esi]\ modify exact [eax ebx ecx edx edi] -long qinterpolatedown16(long,long,long,long); +long qinterpolatedown16short(long,long,long,long); #pragma aux qinterpolatedown16short =\ "test ecx, ecx",\ "jz endit",\ @@ -2752,24 +2757,24 @@ long qinterpolatedown16(long,long,long,long); "endit:",\ parm [eax][ecx][edx][esi]\ modify exact [eax ebx ecx edx edi] -long qinterpolatedown16short(long,long,long,long); +long mul3(long); #pragma aux mul3 =\ "lea eax, [eax+eax*2]",\ parm nomemory [eax] -long mul3(long); +long mul5(long); #pragma aux mul5 =\ "lea eax, [eax+eax*4]",\ parm nomemory [eax] -long mul5(long); +long mul9(long); #pragma aux mul9 =\ "lea eax, [eax+eax*8]",\ parm nomemory [eax] -long mul9(long); //returns eax/ebx, dmval = eax%edx; +long divmod(long,long); #pragma aux divmod =\ "xor edx, edx",\ "div ebx",\ @@ -2777,9 +2782,9 @@ long mul9(long); parm [eax][ebx]\ modify exact [eax edx]\ value [eax] -long divmod(long,long); //returns eax%ebx, dmval = eax/edx; +long moddiv(long,long); #pragma aux moddiv =\ "xor edx, edx",\ "div ebx",\ @@ -2787,16 +2792,16 @@ long divmod(long,long); parm [eax][ebx]\ modify exact [eax edx]\ value [edx] -long moddiv(long,long); +long klabs(long); #pragma aux klabs =\ "test eax, eax",\ "jns skipnegate",\ "neg eax",\ "skipnegate:",\ parm nomemory [eax] -long klabs(long); +long ksgn(long); #pragma aux ksgn =\ "add ebx, ebx",\ "sbb eax, eax",\ @@ -2804,9 +2809,9 @@ long klabs(long); "adc al, 0",\ parm nomemory [ebx]\ modify exact [eax ebx] -long ksgn(long); //eax = (unsigned min)umin(eax,ebx) +long umin(long,long); #pragma aux umin =\ "sub eax, ebx",\ "sbb ecx, ecx",\ @@ -2814,9 +2819,9 @@ long ksgn(long); "add eax, ebx",\ parm nomemory [eax][ebx]\ modify exact [eax ecx] -long umin(long,long); //eax = (unsigned max)umax(eax,ebx) +long umax(long,long); #pragma aux umax =\ "sub eax, ebx",\ "sbb ecx, ecx",\ @@ -2825,8 +2830,8 @@ long umin(long,long); "add eax, ebx",\ parm nomemory [eax][ebx]\ modify exact [eax ecx] -long umax(long,long); +long kmin(long,long); #pragma aux kmin =\ "cmp eax, ebx",\ "jl skipit",\ @@ -2834,8 +2839,8 @@ long umax(long,long); "skipit:",\ parm nomemory [eax][ebx]\ modify exact [eax] -long kmin(long,long); +long kmax(long,long); #pragma aux kmax =\ "cmp eax, ebx",\ "jg skipit",\ @@ -2843,8 +2848,8 @@ long kmin(long,long); "skipit:",\ parm nomemory [eax][ebx]\ modify exact [eax] -long kmax(long,long); +long swapchar(void*,void*); #pragma aux swapchar =\ "mov cl, [eax]",\ "mov ch, [ebx]",\ @@ -2852,8 +2857,8 @@ long kmax(long,long); "mov [eax], ch",\ parm [eax][ebx]\ modify exact [ecx] -long swapchar(void*,void*); +long swapshort(void*,void*); #pragma aux swapshort =\ "mov cx, [eax]",\ "mov dx, [ebx]",\ @@ -2861,8 +2866,8 @@ long swapchar(void*,void*); "mov [eax], dx",\ parm [eax][ebx]\ modify exact [ecx edx] -long swapshort(void*,void*); +long swaplong(void*,void*); #pragma aux swaplong =\ "mov ecx, [eax]",\ "mov edx, [ebx]",\ @@ -2870,8 +2875,8 @@ long swapshort(void*,void*); "mov [eax], edx",\ parm [eax][ebx]\ modify exact [ecx edx] -long swaplong(void*,void*); +long swapbuf4(void*,void*,long); #pragma aux swapbuf4 =\ "begswap:",\ "mov esi, [eax]",\ @@ -2884,8 +2889,8 @@ long swaplong(void*,void*); "jnz short begswap",\ parm [eax][ebx][ecx]\ modify exact [eax ebx ecx esi edi] -long swapbuf4(void*,void*,long); +long swap64bit(void*,void*); #pragma aux swap64bit =\ "mov ecx, [eax]",\ "mov edx, [ebx]",\ @@ -2897,10 +2902,10 @@ long swapbuf4(void*,void*,long); "mov [eax+4], edx",\ parm [eax][ebx]\ modify exact [ecx edx] -long swap64bit(void*,void*); //swapchar2(ptr1,ptr2,xsiz); is the same as: //swapchar(ptr1,ptr2); swapchar(ptr1+1,ptr2+xsiz); +long swapchar2(void*,void*,long); #pragma aux swapchar2 =\ "add esi, ebx",\ "mov cx, [eax]",\ @@ -2911,7 +2916,6 @@ long swap64bit(void*,void*); "mov [eax], dx",\ parm [eax][ebx][esi]\ modify exact [ecx edx esi] -long swapchar2(void*,void*,long); //}}} #elif defined(_MSC_VER) && !defined(NOASM) // __WATCOMC__ @@ -2951,11 +2955,9 @@ static __inline long mulscale(long a, long d, long c) #define MULSCALE(x) \ static __inline long mulscale##x (long a, long d) \ { \ - _asm { \ - mov eax, a \ - imul d \ - shrd eax, edx, x \ - } \ + _asm mov eax, a \ + _asm imul d \ + _asm shrd eax, edx, x \ } MULSCALE(1) MULSCALE(2) MULSCALE(3) MULSCALE(4) @@ -2995,17 +2997,15 @@ static __inline long dmulscale(long a, long d, long S, long D, long c) #define DMULSCALE(x) \ static __inline long dmulscale##x (long a, long d, long S, long D) \ { \ - _asm { \ - mov eax, a \ - imul d \ - mov ebx, eax \ - mov eax, S \ - mov esi, edx \ - imul D \ - add eax, ebx \ - adc edx, esi \ - shrd eax, edx, x \ - } \ + _asm mov eax, a \ + _asm imul d \ + _asm mov ebx, eax \ + _asm mov eax, S \ + _asm mov esi, edx \ + _asm imul D \ + _asm add eax, ebx \ + _asm adc edx, esi \ + _asm shrd eax, edx, x \ } DMULSCALE(1) DMULSCALE(2) DMULSCALE(3) DMULSCALE(4) @@ -3035,22 +3035,20 @@ static __inline long dmulscale32(long a, long d, long S, long D) #define TMULSCALE(x) \ static __inline long tmulscale##x (long a, long d, long b, long c, long S, long D) \ { \ - _asm { \ - mov eax, a \ - mov ebx, b \ - imul d \ - xchg eax, ebx \ - mov ecx, c \ - xchg edx, ecx \ - imul edx \ - add ebx, eax \ - adc ecx, edx \ - mov eax, S \ - imul D \ - add eax, ebx \ - adc edx, ecx \ - shrd eax, edx, x \ - } \ + _asm mov eax, a \ + _asm mov ebx, b \ + _asm imul d \ + _asm xchg eax, ebx \ + _asm mov ecx, c \ + _asm xchg edx, ecx \ + _asm imul edx \ + _asm add ebx, eax \ + _asm adc ecx, edx \ + _asm mov eax, S \ + _asm imul D \ + _asm add eax, ebx \ + _asm adc edx, ecx \ + _asm shrd eax, edx, x \ } TMULSCALE(1) TMULSCALE(2) TMULSCALE(3) TMULSCALE(4) @@ -3153,13 +3151,11 @@ static __inline long divscale3(long a, long b) #define DIVSCALE(x,y) \ static __inline long divscale##y(long a, long b) \ { \ - _asm { \ - mov eax, a \ - mov edx, eax \ - sar edx, x \ - shl eax, y \ - idiv b \ - } \ + _asm mov eax, a \ + _asm mov edx, eax \ + _asm sar edx, x \ + _asm shl eax, y \ + _asm idiv b \ } DIVSCALE(28,4) DIVSCALE(27,5) DIVSCALE(26,6) DIVSCALE(25,7) @@ -3729,5 +3725,9 @@ void copybufreverse(void *S, void *D, long c); #endif +#ifdef __cplusplus +} +#endif + #endif // __pragmas_h__ diff --git a/polymer/build/src/bstub.c b/polymer/build/src/bstub.c deleted file mode 100644 index b26e5d391..000000000 --- a/polymer/build/src/bstub.c +++ /dev/null @@ -1,574 +0,0 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file has been modified from Ken Silverman's original release -// by Jonathon Fowler (jonof@edgenetwk.com) - -#include "compat.h" -#include "a.h" -#include "build.h" -#include "editor.h" -#include "pragmas.h" -#include "baselayer.h" -#include "names.h" -#include "osd.h" -#include "cache1d.h" - - -static char tempbuf[256]; - -#define NUMOPTIONS 9 -char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0,0}; -char keys[NUMBUILDKEYS] = - { - 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, - 0x1e,0x2c,0xd1,0xc9,0x33,0x34, - 0x9c,0x1c,0xd,0xc,0xf,0x45 - }; - - - -//static long hang = 0; -//static long rollangle = 0; - -//Detecting 2D / 3D mode: -// qsetmode is 200 in 3D mode -// qsetmode is 350/480 in 2D mode -// -//You can read these variables when F5-F8 is pressed in 3D mode only: -// -// If (searchstat == 0) WALL searchsector=sector, searchwall=wall -// If (searchstat == 1) CEILING searchsector=sector -// If (searchstat == 2) FLOOR searchsector=sector -// If (searchstat == 3) SPRITE searchsector=sector, searchwall=sprite -// If (searchstat == 4) MASKED WALL searchsector=sector, searchwall=wall -// -// searchsector is the sector of the selected item for all 5 searchstat's -// -// searchwall is undefined if searchstat is 1 or 2 -// searchwall is the wall if searchstat = 0 or 4 -// searchwall is the sprite if searchstat = 3 (Yeah, I know - it says wall, -// but trust me, it's the sprite number) - -long averagefps; -#define AVERAGEFRAMES 32 -static unsigned long frameval[AVERAGEFRAMES]; -static long framecnt = 0; - -char *defsfilename = "kenbuild.def"; -char *startwin_labeltext = "Starting Build Editor..."; -int nextvoxid = 0; - -int ExtPreInit(int *argc,char ***argv) -{ - return 0; -} - -int ExtInit(void) -{ - long i, rv = 0; - - /*printf("------------------------------------------------------------------------------\n"); - printf(" BUILD.EXE copyright(c) 1996 by Ken Silverman. You are granted the\n"); - printf(" right to use this software for your personal use only. This is a\n"); - printf(" special version to be used with \"Happy Fun KenBuild\" and may not work\n"); - printf(" properly with other Build engine games. Please refer to license.doc\n"); - printf(" for distribution rights\n"); - printf("------------------------------------------------------------------------------\n"); - getch(); - */ - - initgroupfile("stuff.dat"); - bpp = 8; - if (loadsetup("build.cfg") < 0) initprintf("Configuration file not found, using defaults.\n"), rv = 1; - Bmemcpy((void *)buildkeys,(void *)keys,NUMBUILDKEYS); //Trick to make build use setup.dat keys - if (option[4] > 0) option[4] = 0; - if (initengine()) { - wm_msgbox("Build Engine Initialisation Error", - "There was a problem initialising the Build engine: %s", engineerrstr); - return -1; - } - initinput(); - initmouse(); - - //You can load your own palette lookup tables here if you just - //copy the right code! - for(i=0;i<256;i++) - tempbuf[i] = ((i+32)&255); //remap colors for screwy palette sectors - makepalookup(16,tempbuf,0,0,0,1); - - kensplayerheight = 32; - zmode = 0; - defaultspritecstat = 0; - pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; - -#ifdef SUPERBUILD - tiletovox[PLAYER] = nextvoxid++; - tiletovox[BROWNMONSTER] = nextvoxid++; -#endif - -#ifdef _WIN32 - // allowtaskswitching(0); -#endif - return rv; -} - -void ExtUnInit(void) -{ - uninitgroupfile(); - writesetup("build.cfg"); -} - -void ExtSetupSpecialSpriteCols(void) -{ - return; -} - -//static long daviewingrange, daaspect, horizval1, horizval2; -void ExtPreCheckKeys(void) -{ - long /*cosang, sinang, dx, dy, mindx,*/ i, j, k; - - if (keystatus[0x3e]) //F4 - screen re-size - { - keystatus[0x3e] = 0; - - //cycle through all vesa modes, then screen-buffer mode - if (keystatus[0x2a]|keystatus[0x36]) { - setgamemode(!fullscreen, xdim, ydim, bpp); - } else { - - //cycle through all modes - j=-1; - - // work out a mask to select the mode - for (i=0; i> 3) + (xdim >> 4) + (xdim >> 6)) & (~7); - dy = (ydim + (ydim >> 3) + (ydim >> 4) + (ydim >> 6)) & (~7); - i = scale(320,ydim,xdim); - - if (waloff[4094] == 0) allocache(&waloff[4094],/*240L*384L*/dx*dy,&walock[4094]); - setviewtotile(4094,/*240L,384L*/dy,dx); - - cosang = sintable[(hang+512)&2047]; - sinang = sintable[hang&2047]; - - dx = dmulscale1(320,cosang,i,sinang); mindx = dx; - dy = dmulscale1(-i,cosang,320,sinang); - horizval1 = dy*(320>>1)/dx-1; - - dx = dmulscale1(320,cosang,-i,sinang); mindx = min(dx,mindx); - dy = dmulscale1(i,cosang,320,sinang); - horizval2 = dy*(320>>1)/dx+1; - - daviewingrange = scale(65536,16384*(xdim>>1),mindx-16); - daaspect = scale(daviewingrange,scale(320,tilesizx[4094],tilesizy[4094]),horizval2+6-horizval1); - setaspect(daviewingrange,scale(daaspect,ydim*320,xdim*i)); - horiz = 100-divscale15(horizval1+horizval2,daviewingrange); - } -#endif -} - -#ifdef SUPERBUILD -#define MAXVOXMIPS 5 -extern char *voxoff[][MAXVOXMIPS]; -void ExtAnalyzeSprites(void) -{ - long i, *longptr; - spritetype *tspr; - - for(i=0,tspr=&tsprite[0];ipicnum] >= 0) - { - switch(tspr->picnum) - { - case PLAYER: - if (!voxoff[ tiletovox[PLAYER] ][0]) { - if (qloadkvx(tiletovox[PLAYER],"voxel000.kvx")) { - tiletovox[PLAYER] = -1; - break; - } - } - //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; - longptr = (long *)voxoff[ tiletovox[PLAYER] ][0]; - tspr->xrepeat = scale(tspr->xrepeat,56,longptr[2]); - tspr->yrepeat = scale(tspr->yrepeat,56,longptr[2]); - tspr->shade -= 6; - break; - case BROWNMONSTER: - if (!voxoff[ tiletovox[BROWNMONSTER] ][0]) { - if (qloadkvx(tiletovox[BROWNMONSTER],"voxel001.kvx")) { - tiletovox[BROWNMONSTER] = -1; - break; - } - } - //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; - break; - } - } - - tspr->shade += 6; - if (sector[tspr->sectnum].ceilingstat&1) - tspr->shade += sector[tspr->sectnum].ceilingshade; - else - tspr->shade += sector[tspr->sectnum].floorshade; - } -} -#endif - -void ExtCheckKeys(void) -{ - long i;//, p, y, dx, dy, cosang, sinang, bufplc, tsizy, tsizyup15; - long j; - - if (qsetmode == 200) //In 3D mode - { -#if 0 - if (hang != 0) - { - bufplc = waloff[4094]+(mulscale16(horiz-100,xdimenscale)+(tilesizx[4094]>>1))*tilesizy[4094]; - setviewback(); - cosang = sintable[(hang+512)&2047]; - sinang = sintable[hang&2047]; - dx = dmulscale1(xdim,cosang,ydim,sinang); - dy = dmulscale1(-ydim,cosang,xdim,sinang); - - begindrawing(); - tsizy = tilesizy[4094]; - tsizyup15 = (tsizy<<15); - dx = mulscale14(dx,daviewingrange); - dy = mulscale14(dy,daaspect); - sinang = mulscale14(sinang,daviewingrange); - cosang = mulscale14(cosang,daaspect); - p = ylookup[windowy1]+frameplace+windowx2+1; - for(y=windowy1;y<=windowy2;y++) - { - i = divscale16(tsizyup15,dx); - stretchhline(0,(xdim>>1)*i+tsizyup15,xdim>>2,i,mulscale32(i,dy)*tsizy+bufplc,p); - dx -= sinang; dy += cosang; p += ylookup[1]; - } - walock[4094] = 1; - - Bsprintf(tempbuf,"%d",(hang*180)>>10); - printext256(0L,8L,31,-1,tempbuf,1); - enddrawing(); - } -#endif - if (keystatus[0xa]) setaspect(viewingrange+(viewingrange>>8),yxaspect+(yxaspect>>8)); - if (keystatus[0xb]) setaspect(viewingrange-(viewingrange>>8),yxaspect-(yxaspect>>8)); - if (keystatus[0xc]) setaspect(viewingrange,yxaspect-(yxaspect>>8)); - if (keystatus[0xd]) setaspect(viewingrange,yxaspect+(yxaspect>>8)); - //if (keystatus[0x38]) setrollangle(rollangle+=((keystatus[0x2a]|keystatus[0x36])*6+2)); - //if (keystatus[0xb8]) setrollangle(rollangle-=((keystatus[0x2a]|keystatus[0x36])*6+2)); - //if (keystatus[0x1d]|keystatus[0x9d]) setrollangle(rollangle=0); - - begindrawing(); - - i = frameval[framecnt&(AVERAGEFRAMES-1)]; - j = frameval[framecnt&(AVERAGEFRAMES-1)] = getticks(); framecnt++; - if (i != j) averagefps = ((mul3(averagefps)+((AVERAGEFRAMES*1000)/(j-i)) )>>2); - Bsprintf(tempbuf,"%ld",averagefps); - printext256(0L,0L,31,-1,tempbuf,1); - - enddrawing(); - editinput(); - } - else - { - } -} - -void ExtCleanUp(void) -{ -} - -void ExtPreLoadMap(void) -{ -} - -void ExtLoadMap(const char *mapname) -{ - char title[256]; - Bsprintf(title, "BUILD by Ken Silverman - %s", mapname); - wm_setapptitle(title); -} - -void ExtPreSaveMap(void) -{ -} - -void ExtSaveMap(const char *mapname) -{ -} - -const char *ExtGetSectorCaption(short sectnum) -{ - if ((sector[sectnum].lotag|sector[sectnum].hitag) == 0) - { - tempbuf[0] = 0; - } - else - { - Bsprintf(tempbuf,"%hu,%hu",(unsigned short)sector[sectnum].hitag, - (unsigned short)sector[sectnum].lotag); - } - return(tempbuf); -} - -const char *ExtGetWallCaption(short wallnum) -{ - if ((wall[wallnum].lotag|wall[wallnum].hitag) == 0) - { - tempbuf[0] = 0; - } - else - { - Bsprintf(tempbuf,"%hu,%hu",(unsigned short)wall[wallnum].hitag, - (unsigned short)wall[wallnum].lotag); - } - return(tempbuf); -} - -const char *ExtGetSpriteCaption(short spritenum) -{ - if ((sprite[spritenum].lotag|sprite[spritenum].hitag) == 0) - { - tempbuf[0] = 0; - } - else - { - Bsprintf(tempbuf,"%hu,%hu",(unsigned short)sprite[spritenum].hitag, - (unsigned short)sprite[spritenum].lotag); - } - return(tempbuf); -} - -//printext16 parameters: -//printext16(long xpos, long ypos, short col, short backcol, -// char name[82], char fontsize) -// xpos 0-639 (top left) -// ypos 0-479 (top left) -// col 0-15 -// backcol 0-15, -1 is transparent background -// name -// fontsize 0=8*8, 1=3*5 - -//drawline16 parameters: -// drawline16(long x1, long y1, long x2, long y2, char col) -// x1, x2 0-639 -// y1, y2 0-143 (status bar is 144 high, origin is top-left of STATUS BAR) -// col 0-15 - -void ExtShowSectorData(short sectnum) //F5 -{ - int i; - if (qsetmode == 200) //In 3D mode - { - } - else - { - begindrawing(); - clearmidstatbar16(); //Clear middle of status bar - - Bsprintf(tempbuf,"Sector %d",sectnum); - printext16(8,ydim16+32,11,-1,tempbuf,0); - - printext16(8,ydim16+48,11,-1,"8*8 font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",0); - printext16(8,ydim16+56,11,-1,"3*5 font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789",1); - - i=ydim16; ydim16=ydim; - drawline16(320,i+68,344,i+80,4); //Draw house - drawline16(344,i+80,344,i+116,4); - drawline16(344,i+116,296,i+116,4); - drawline16(296,i+116,296,i+80,4); - drawline16(296,i+80,320,i+68,4); - ydim16=i; - enddrawing(); - } -} - -void ExtShowWallData(short wallnum) //F6 -{ - if (qsetmode == 200) //In 3D mode - { - } - else - { - begindrawing(); - clearmidstatbar16(); //Clear middle of status bar - - Bsprintf(tempbuf,"Wall %d",wallnum); - printext16(8,ydim16+32,11,-1,tempbuf,0); - enddrawing(); - } -} - -void ExtShowSpriteData(short spritenum) //F6 -{ - if (qsetmode == 200) //In 3D mode - { - } - else - { - begindrawing(); - clearmidstatbar16(); //Clear middle of status bar - - Bsprintf(tempbuf,"Sprite %d",spritenum); - printext16(8,ydim16+32,11,-1,tempbuf,0); - enddrawing(); - } -} - -void ExtEditSectorData(short sectnum) //F7 -{ - short nickdata; - - if (qsetmode == 200) //In 3D mode - { - //Ceiling - if (searchstat == 1) - sector[searchsector].ceilingpicnum++; //Just a stupid example - - //Floor - if (searchstat == 2) - sector[searchsector].floorshade++; //Just a stupid example - } - else //In 2D mode - { - Bsprintf(tempbuf,"Sector (%d) Nick's variable: ",sectnum); - nickdata = 0; - nickdata = getnumber16(tempbuf,nickdata,65536L,0); - - printmessage16(""); //Clear message box (top right of status bar) - ExtShowSectorData(sectnum); - } -} - -void ExtEditWallData(short wallnum) //F8 -{ - short nickdata; - - if (qsetmode == 200) //In 3D mode - { - } - else - { - Bsprintf(tempbuf,"Wall (%d) Nick's variable: ",wallnum); - nickdata = 0; - nickdata = getnumber16(tempbuf,nickdata,65536L,0); - - printmessage16(""); //Clear message box (top right of status bar) - ExtShowWallData(wallnum); - } -} - -void ExtEditSpriteData(short spritenum) //F8 -{ - short nickdata; - - if (qsetmode == 200) //In 3D mode - { - } - else - { - Bsprintf(tempbuf,"Sprite (%d) Nick's variable: ",spritenum); - nickdata = 0; - nickdata = getnumber16(tempbuf,nickdata,65536L,0); - printmessage16(""); - - printmessage16(""); //Clear message box (top right of status bar) - ExtShowSpriteData(spritenum); - } -} - -void faketimerhandler(void) -{ - sampletimer(); -} - -//Just thought you might want my getnumber16 code -/* -getnumber16(char namestart[80], short num, long maxnumber) -{ - char buffer[80]; - long j, k, n, danum, oldnum; - - danum = (long)num; - oldnum = danum; - while ((keystatus[0x1c] != 2) && (keystatus[0x1] == 0)) //Enter, ESC - { - sprintf(&buffer,"%s%ld_ ",namestart,danum); - printmessage16(buffer); - - for(j=2;j<=11;j++) //Scan numbers 0-9 - if (keystatus[j] > 0) - { - keystatus[j] = 0; - k = j-1; - if (k == 10) k = 0; - n = (danum*10)+k; - if (n < maxnumber) danum = n; - } - if (keystatus[0xe] > 0) // backspace - { - danum /= 10; - keystatus[0xe] = 0; - } - if (keystatus[0x1c] == 1) //L. enter - { - oldnum = danum; - keystatus[0x1c] = 2; - asksave = 1; - } - } - keystatus[0x1c] = 0; - keystatus[0x1] = 0; - return((short)oldnum); -} -*/ - -/* - * vim:ts=4: - */ - diff --git a/polymer/build/src/game.c b/polymer/build/src/game.c deleted file mode 100644 index 531274157..000000000 --- a/polymer/build/src/game.c +++ /dev/null @@ -1,6290 +0,0 @@ -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file has been modified from Ken Silverman's original release -// by Jonathon Fowler (jonof@edgenetwk.com) - -#include "compat.h" -#include "build.h" -#include "names.h" -#include "pragmas.h" -#include "cache1d.h" -#include "game.h" -#include "osd.h" -#include "mmulti.h" - -#include "baselayer.h" - -#define TIMERINTSPERSECOND 140 //280 -#define MOVESPERSECOND 40 -#define TICSPERFRAME 3 -#define MOVEFIFOSIZ 256 -#define EYEHEIGHT (32<<8) //Normally (32<<8), (51<<8) to make mirrors happy - -// declared in sound.c -void initsb(char,char,long,char,char,char,char); -void uninitsb(void); -void setears(long,long,long,long); -void wsayfollow(char *,long,long,long *,long *,char); -void wsay(char *,long,long,long); -void loadwaves(void); -void loadsong(char *); -void musicon(void); -void musicoff(void); -void refreshaudio(void); - -// declared in config.c -int loadsetup(const char *); -int writesetup(const char *); - - -/*************************************************************************** - KEN'S TAG DEFINITIONS: (Please define your own tags for your games) - - sector[?].lotag = 0 Normal sector - sector[?].lotag = 1 If you are on a sector with this tag, then all sectors - with same hi tag as this are operated. Once. - sector[?].lotag = 2 Same as sector[?].tag = 1 but this is retriggable. - sector[?].lotag = 3 A really stupid sector that really does nothing now. - sector[?].lotag = 4 A sector where you are put closer to the floor - (such as the slime in DOOM1.DAT) - sector[?].lotag = 5 A really stupid sector that really does nothing now. - sector[?].lotag = 6 A normal door - instead of pressing D, you tag the - sector with a 6. The reason I make you edit doors - this way is so that can program the doors - yourself. - sector[?].lotag = 7 A door the goes down to open. - sector[?].lotag = 8 A door that opens horizontally in the middle. - sector[?].lotag = 9 A sliding door that opens vertically in the middle. - -Example of the advantages of not using BSP tree. - sector[?].lotag = 10 A warping sector with floor and walls that shade. - sector[?].lotag = 11 A sector with all walls that do X-panning. - sector[?].lotag = 12 A sector with walls using the dragging function. - sector[?].lotag = 13 A sector with some swinging doors in it. - sector[?].lotag = 14 A revolving door sector. - sector[?].lotag = 15 A subway track. - sector[?].lotag = 16 A true double-sliding door. - - wall[?].lotag = 0 Normal wall - wall[?].lotag = 1 Y-panning wall - wall[?].lotag = 2 Switch - If you flip it, then all sectors with same hi - tag as this are operated. - wall[?].lotag = 3 Marked wall to detemine starting dir. (sector tag 12) - wall[?].lotag = 4 Mark on the shorter wall closest to the pivot point - of a swinging door. (sector tag 13) - wall[?].lotag = 5 Mark where a subway should stop. (sector tag 15) - wall[?].lotag = 6 Mark for true double-sliding doors (sector tag 16) - wall[?].lotag = 7 Water fountain - wall[?].lotag = 8 Bouncy wall! - - sprite[?].lotag = 0 Normal sprite - sprite[?].lotag = 1 If you press space bar on an AL, and the AL is tagged - with a 1, he will turn evil. - sprite[?].lotag = 2 When this sprite is operated, a bomb is shot at its - position. - sprite[?].lotag = 3 Rotating sprite. - sprite[?].lotag = 4 Sprite switch. - sprite[?].lotag = 5 Basketball hoop score. - -KEN'S STATUS DEFINITIONS: (Please define your own statuses for your games) - status = 0 Inactive sprite - status = 1 Active monster sprite - status = 2 Monster that becomes active only when it sees you - status = 3 Smoke on the wall for chainguns - status = 4 Splashing sprites (When you shoot slime) - status = 5 Explosion! - status = 6 Travelling bullet - status = 7 Bomb sprial-out explosion - status = 8 Player! - status = 9 EVILALGRAVE shrinking list - status = 10 EVILAL list - status = 11 Sprite respawning list - status = 12 Sprite which does not respawn (Andy's addition) - status = MAXSTATUS Non-existent sprite (this will be true for your - code also) -**************************************************************************/ - -typedef struct -{ - long x, y, z; -} point3d; - -typedef struct -{ - signed char fvel, svel, avel; - short bits; -} input; - -static long screentilt = 0, oscreentilt = 0; - - -static long fvel, svel, avel; -static long fvel2, svel2, avel2; - -#define NUMOPTIONS 8 -#define NUMKEYS 19 -char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0}; -char keys[NUMKEYS] = - { - 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, - 0x1e,0x2c,0xd1,0xc9,0x33,0x34, - 0x9c,0x1c,0xd,0xc,0xf - }; -long xdimgame = 320, ydimgame = 200, bppgame = 8, xdim2d = 640, ydim2d = 480; // JBF 20050318: config.c expects to find these -long forcesetup = 1; - -static long digihz[8] = {6000,8000,11025,16000,22050,32000,44100,48000}; - -static char frame2draw[MAXPLAYERS]; -static long frameskipcnt[MAXPLAYERS]; - -#define LAVASIZ 128 -#define LAVALOGSIZ 7 -#define LAVAMAXDROPS 32 -static char lavabakpic[(LAVASIZ+4)*(LAVASIZ+4)], lavainc[LAVASIZ]; -static long lavanumdrops, lavanumframes; -static long lavadropx[LAVAMAXDROPS], lavadropy[LAVAMAXDROPS]; -static long lavadropsiz[LAVAMAXDROPS], lavadropsizlookup[LAVAMAXDROPS]; -static long lavaradx[24][96], lavarady[24][96], lavaradcnt[32]; - -//Shared player variables -static long posx[MAXPLAYERS], posy[MAXPLAYERS], posz[MAXPLAYERS]; -static long horiz[MAXPLAYERS], zoom[MAXPLAYERS], hvel[MAXPLAYERS]; -static short ang[MAXPLAYERS], cursectnum[MAXPLAYERS], ocursectnum[MAXPLAYERS]; -static short playersprite[MAXPLAYERS], deaths[MAXPLAYERS]; -static long lastchaingun[MAXPLAYERS]; -static long health[MAXPLAYERS], flytime[MAXPLAYERS]; -static short oflags[MAXPLAYERS]; -static short numbombs[MAXPLAYERS]; -static short numgrabbers[MAXPLAYERS]; // Andy did this -static short nummissiles[MAXPLAYERS]; // Andy did this -static char dimensionmode[MAXPLAYERS]; -static char revolvedoorstat[MAXPLAYERS]; -static short revolvedoorang[MAXPLAYERS], revolvedoorrotang[MAXPLAYERS]; -static long revolvedoorx[MAXPLAYERS], revolvedoory[MAXPLAYERS]; - -//ENGINE CONTROLLED MULTIPLAYER VARIABLES: -extern long numplayers, myconnectindex; -extern long connecthead, connectpoint2[MAXPLAYERS]; //Player linked list variables (indeces, not connection numbers) - -static long nummoves; -// Bug: NUMSTATS used to be equal to the greatest tag number, -// so that the last statrate[] entry was random memory junk -// because stats 0-NUMSTATS required NUMSTATS+1 bytes. -Andy -#define NUMSTATS 13 -static signed char statrate[NUMSTATS] = {-1,0,-1,0,0,0,1,3,0,3,15,-1,-1}; - -//Input structures -static char networkmode; //0 is 2(n-1) mode, 1 is n(n-1) mode -static long locselectedgun, locselectedgun2; -static input loc, oloc, loc2; -static input ffsync[MAXPLAYERS], osync[MAXPLAYERS], ssync[MAXPLAYERS]; -//Input faketimerhandler -> movethings fifo -static long movefifoplc, movefifoend[MAXPLAYERS]; -static input baksync[MOVEFIFOSIZ][MAXPLAYERS]; -//Game recording variables -static long reccnt, recstat = 1; -static input recsync[16384][2]; - -//static long myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter = 1; -static signed char otherlag[MAXPLAYERS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; -static long averagelag[MAXPLAYERS] = {512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512}; - -static long fakemovefifoplc; -static long myx, myy, myz, omyx, omyy, omyz, myzvel; -static long myhoriz, omyhoriz; -static short myang, omyang, mycursectnum; -static long myxbak[MOVEFIFOSIZ], myybak[MOVEFIFOSIZ], myzbak[MOVEFIFOSIZ]; -static long myhorizbak[MOVEFIFOSIZ]; -static short myangbak[MOVEFIFOSIZ]; - -//MULTI.OBJ sync state variables -extern char syncstate; -//GAME.C sync state variables -static char syncstat, syncval[MOVEFIFOSIZ], othersyncval[MOVEFIFOSIZ]; -static long syncvaltottail, syncvalhead, othersyncvalhead, syncvaltail; - -static char detailmode = 0, ready2send = 0; -static long ototalclock = 0, gotlastpacketclock = 0, smoothratio; -static long oposx[MAXPLAYERS], oposy[MAXPLAYERS], oposz[MAXPLAYERS]; -static long ohoriz[MAXPLAYERS], ozoom[MAXPLAYERS]; -static short oang[MAXPLAYERS]; - -static point3d osprite[MAXSPRITES]; - -#define MAXINTERPOLATIONS 1024 -static long numinterpolations = 0, startofdynamicinterpolations = 0; -static long oldipos[MAXINTERPOLATIONS]; -static long bakipos[MAXINTERPOLATIONS]; -static long *curipos[MAXINTERPOLATIONS]; - -extern long cachecount; - -static char playerreadyflag[MAXPLAYERS]; - -//Miscellaneous variables -static char packbuf[MAXXDIM]; -static char tempbuf[MAXXDIM], boardfilename[80]; -static short tempshort[MAXSECTORS]; -static short screenpeek = 0, oldmousebstatus = 0; -short brightness = 0; -static short screensize, screensizeflag = 0; -static short neartagsector, neartagwall, neartagsprite; -static long lockclock, neartagdist, neartaghitdist; -extern long pageoffset, ydim16; -static long globhiz, globloz, globhihit, globlohit; - -//Over the shoulder mode variables -static long cameradist = -1, cameraang = 0, cameraclock = 0; - -//Board animation variables -#define MAXMIRRORS 64 -static short mirrorwall[MAXMIRRORS], mirrorsector[MAXMIRRORS], mirrorcnt; -static short floormirrorsector[64], floormirrorcnt; -static short turnspritelist[16], turnspritecnt; -static short warpsectorlist[64], warpsectorcnt; -static short xpanningsectorlist[16], xpanningsectorcnt; -static short ypanningwalllist[64], ypanningwallcnt; -static short floorpanninglist[64], floorpanningcnt; -static short dragsectorlist[16], dragxdir[16], dragydir[16], dragsectorcnt; -static long dragx1[16], dragy1[16], dragx2[16], dragy2[16], dragfloorz[16]; -static short swingcnt, swingwall[32][5], swingsector[32]; -static short swingangopen[32], swingangclosed[32], swingangopendir[32]; -static short swingang[32], swinganginc[32]; -static long swingx[32][8], swingy[32][8]; -static short revolvesector[4], revolveang[4], revolvecnt; -static long revolvex[4][16], revolvey[4][16]; -static long revolvepivotx[4], revolvepivoty[4]; -static short subwaytracksector[4][128], subwaynumsectors[4], subwaytrackcnt; -static long subwaystop[4][8], subwaystopcnt[4]; -static long subwaytrackx1[4], subwaytracky1[4]; -static long subwaytrackx2[4], subwaytracky2[4]; -static long subwayx[4], subwaygoalstop[4], subwayvel[4], subwaypausetime[4]; -static short waterfountainwall[MAXPLAYERS], waterfountaincnt[MAXPLAYERS]; -static short slimesoundcnt[MAXPLAYERS]; - -//Variables that let you type messages to other player -static char getmessage[162], getmessageleng; -static long getmessagetimeoff; -static char typemessage[162], typemessageleng = 0, typemode = 0; -/* -static char scantoasc[128] = -{ - 0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0, - 'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s', - 'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v', - 'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0, - 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', - '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; -static char scantoascwithshift[128] = -{ - 0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0, - 'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S', - 'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V', - 'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0, - 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', - '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; -*/ - -//These variables are for animating x, y, or z-coordinates of sectors, -//walls, or sprites (They are NOT to be used for changing the [].picnum's) -//See the setanimation(), and getanimategoal() functions for more details. -#define MAXANIMATES 512 -static long *animateptr[MAXANIMATES], animategoal[MAXANIMATES]; -static long animatevel[MAXANIMATES], animateacc[MAXANIMATES], animatecnt = 0; - -#if defined(POLYMOST) && defined(USE_OPENGL) -//These parameters are in exact order of sprite structure in BUILD.H -#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2, \ - clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2, \ - xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \ -{ \ - spritetype *spr2; \ - newspriteindex2 = insertsprite(sectnum2,statnum2); \ - spr2 = &sprite[newspriteindex2]; \ - spr2->x = x2; spr2->y = y2; spr2->z = z2; \ - spr2->cstat = cstat2; spr2->shade = shade2; \ - spr2->pal = pal2; spr2->clipdist = clipdist2; \ - spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2; \ - spr2->xoffset = xoffset2; spr2->yoffset = yoffset2; \ - spr2->picnum = picnum2; spr2->ang = ang2; \ - spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2; \ - spr2->owner = owner2; \ - spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2; \ - copybuf(&spr2->x,&osprite[newspriteindex2].x,3); \ - show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7)); \ - if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7))) \ - show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7)); \ - clearbufbyte(&spriteext[newspriteindex2], sizeof(spriteexttype), 0); \ -} -#else -#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2, \ - clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2, \ - xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \ -{ \ - spritetype *spr2; \ - newspriteindex2 = insertsprite(sectnum2,statnum2); \ - spr2 = &sprite[newspriteindex2]; \ - spr2->x = x2; spr2->y = y2; spr2->z = z2; \ - spr2->cstat = cstat2; spr2->shade = shade2; \ - spr2->pal = pal2; spr2->clipdist = clipdist2; \ - spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2; \ - spr2->xoffset = xoffset2; spr2->yoffset = yoffset2; \ - spr2->picnum = picnum2; spr2->ang = ang2; \ - spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2; \ - spr2->owner = owner2; \ - spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2; \ - copybuf(&spr2->x,&osprite[newspriteindex2].x,3); \ - show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7)); \ - if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7))) \ - show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7)); \ -} -#endif - -int nextvoxid = 0; - -static int osdcmd_restartvid(const osdfuncparm_t *parm) -{ - resetvideomode(); - if (setgamemode(fullscreen,xdim,ydim,bpp)) - OSD_Printf("restartvid: Reset failed...\n"); - - return OSDCMD_OK; -} - -static int osdcmd_vidmode(const osdfuncparm_t *parm) -{ - long newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen; - - if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP; - - switch (parm->numparms) { - case 1: // bpp switch - newbpp = Batol(parm->parms[0]); - break; - case 2: // res switch - newx = Batol(parm->parms[0]); - newy = Batol(parm->parms[1]); - break; - case 3: // res & bpp switch - case 4: - newx = Batol(parm->parms[0]); - newy = Batol(parm->parms[1]); - newbpp = Batol(parm->parms[2]); - if (parm->numparms == 4) - newfullscreen = (Batol(parm->parms[3]) != 0); - break; - } - - if (setgamemode(newfullscreen,newx,newy,newbpp)) - OSD_Printf("vidmode: Mode change failed!\n"); - screensize = xdim+1; - return OSDCMD_OK; -} - -extern int startwin_run(void); - -long app_main(long argc, char *argv[]) -{ - long cmdsetup = 0, i, j, k, l, fil, waitplayers, x1, y1, x2, y2; - long other, packleng, netparm; - -#ifdef USE_OPENGL - OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid); - OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode); -#endif - - wm_setapptitle("KenBuild by Ken Silverman"); - - Bstrcpy(boardfilename, "nukeland.map"); - j = 0; netparm = argc; - for (i=1;i= 2); - - pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; - - loadpics("tiles000.art",1048576); //Load artwork -#ifdef SUPERBUILD - if (!qloadkvx(nextvoxid,"voxel000.kvx")) - tiletovox[PLAYER] = nextvoxid++; - if (!qloadkvx(nextvoxid,"voxel001.kvx")) - tiletovox[BROWNMONSTER] = nextvoxid++; -#endif - if (!loaddefinitionsfile("kenbuild.def")) initprintf("Definitions file loaded.\n"); - - //Here's an example of TRUE ornamented walls - //The allocatepermanenttile should be called right after loadpics - //Since it resets the tile cache for each call. - if (allocatepermanenttile(SLIME,128,128) == 0) //If enough memory - { - printf("Not enough memory for slime!\n"); - exit(0); - } - if (allocatepermanenttile(MAXTILES-1,64,64) != 0) //If enough memory - { - //My face with an explosion written over it - copytilepiece(KENPICTURE,0,0,64,64,MAXTILES-1,0,0); - copytilepiece(EXPLOSION,0,0,64,64,MAXTILES-1,0,0); - } - - initlava(); - - for(j=0;j<256;j++) - tempbuf[j] = ((j+32)&255); //remap colors for screwy palette sectors - makepalookup(16,tempbuf,0,0,0,1); - - for(j=0;j<256;j++) tempbuf[j] = j; - makepalookup(17,tempbuf,24,24,24,1); - - for(j=0;j<256;j++) tempbuf[j] = j; //(j&31)+32; - makepalookup(18,tempbuf,8,8,48,1); - - prepareboard(boardfilename); //Load board - - initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,((option[7]&2)>0)+1,60,option[7]&1); - //if (Bstrcmp(boardfilename,"klab.map") == 0) - // loadsong("klabsong.kdm"); - //else - loadsong("neatsong.ogg"); - musicon(); - - /* - if (option[4] > 0) - { - x1 = ((xdim-screensize)>>1); - x2 = x1+screensize-1; - y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - y2 = y1 + scale(screensize,ydim-32,xdim)-1; - - drawtilebackground(0L,0L,BACKGROUND,8,x1,y1,x2,y2,0); - - sendlogon(); - - if (option[4] < 5) waitplayers = 2; else waitplayers = option[4]-3; - while (numplayers < waitplayers) - { - sprintf(tempbuf,"%ld of %ld players in...",numplayers,waitplayers); - printext256(68L,84L,31,0,tempbuf,0); - nextpage(); - - if (getpacket(&other,packbuf) > 0) - if (packbuf[0] == 255) - keystatus[1] = 1; - - if (handleevents()) { - if (quitevent) { - keystatus[1] = 1; - quitevent = 0; - } - } - - if (keystatus[1]) - { - sendlogoff(); //Signing off - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - exit(0); - } - } - screenpeek = myconnectindex; - - if (numplayers <= 3) - networkmode = 1; - else - networkmode = 0; - - j = 1; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (myconnectindex == i) break; - j++; - } - sprintf(getmessage,"Player %ld",j); - if (networkmode == 0) - { - if (j == 1) Bstrcat(getmessage," (Master)"); - else Bstrcat(getmessage," (Slave)"); - } else - Bstrcat(getmessage," (Even)"); - getmessageleng = Bstrlen(getmessage); - getmessagetimeoff = totalclock+120; - } - */ - screenpeek = myconnectindex; - reccnt = 0; - for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); - - waitforeverybody(); - totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0; - - ready2send = 1; - drawscreen(screenpeek,65536L); - - while (!keystatus[1]) //Main loop starts here - { - if (handleevents()) { - if (quitevent) { - keystatus[1] = 1; - quitevent = 0; - } - } - - refreshaudio(); - OSD_DispatchQueued(); - - // backslash (useful only with KDM) - // if (keystatus[0x2b]) { keystatus[0x2b] = 0; preparesndbuf(); } - - if ((networkmode == 1) || (myconnectindex != connecthead)) - while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings(); - - getpackets(); - - if (typemode == 0) //if normal game keys active - { - if ((keystatus[0x2a]&keystatus[0x36]&keystatus[0x13]) > 0) //Sh.Sh.R (replay) - { - keystatus[0x13] = 0; - playback(); - } - - if (keystatus[0x26]&(keystatus[0x1d]|keystatus[0x9d])) //Load game - { - keystatus[0x26] = 0; - loadgame(); - drawstatusbar(screenpeek); // Andy did this - } - - if (keystatus[0x1f]&(keystatus[0x1d]|keystatus[0x9d])) //Save game - { - keystatus[0x1f] = 0; - savegame(); - } - } - - if ((networkmode == 0) || (option[4] == 0)) - { - while (movefifoplc != movefifoend[0]) domovethings(); - } - else - { - j = connecthead; - if (j == myconnectindex) j = connectpoint2[j]; - averagelag[j] = ((averagelag[j]*7+(((movefifoend[myconnectindex]-movefifoend[j]+otherlag[j]+2)&255)<<8))>>3); - j = max(averagelag[j]>>9,1); - while (((movefifoend[myconnectindex]-movefifoplc)&(MOVEFIFOSIZ-1)) > j) - { - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (movefifoplc == movefifoend[i]) break; - if (i >= 0) break; - if (myconnectindex != connecthead) - { - k = ((movefifoend[myconnectindex]-movefifoend[connecthead]-otherlag[connecthead]+128)&255); - if (k > 128+1) ototalclock++; - if (k < 128-1) ototalclock--; - } - domovethings(); - } - } - i = (totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND)); - - drawscreen(screenpeek,i); - } - - sendlogoff(); //Signing off - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - - return(0); -} - -void operatesector(short dasector) -{ //Door code - long i, j, k, s, nexti, good, cnt, datag; - long dax, day, daz, dax2, day2, daz2, centx, centy; - short startwall, endwall, wallfind[2]; - - datag = sector[dasector].lotag; - - startwall = sector[dasector].wallptr; - endwall = startwall + sector[dasector].wallnum; - centx = 0L, centy = 0L; - for(i=startwall;i= 0) //If door already moving, reverse its direction - { - if (datag == 8) - daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); - else - daz = sector[dasector].floorz; - - if (animategoal[i] == daz) - animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz; - else - animategoal[i] = daz; - animatevel[i] = 0; - } - else //else insert the door's ceiling on the animation list - { - if (sector[dasector].ceilingz == sector[dasector].floorz) - daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz; - else - { - if (datag == 8) - daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); - else - daz = sector[dasector].floorz; - } - if ((j = setanimation(§or[dasector].ceilingz,daz,6L,6L)) >= 0) - wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,¢x,¢y,0); - } - } - //Simple door that moves down - if ((datag == 7) || (datag == 8)) //If the sector in front's elevator - { - i = getanimationgoal((long)§or[dasector].floorz); - if (i >= 0) //If elevator already moving, reverse its direction - { - if (datag == 8) - daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); - else - daz = sector[dasector].ceilingz; - - if (animategoal[i] == daz) - animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz; - else - animategoal[i] = daz; - animatevel[i] = 0; - } - else //else insert the elevator's ceiling on the animation list - { - if (sector[dasector].floorz == sector[dasector].ceilingz) - daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz; - else - { - if (datag == 8) - daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1); - else - daz = sector[dasector].ceilingz; - } - if ((j = setanimation(§or[dasector].floorz,daz,6L,6L)) >= 0) - wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,¢x,¢y,0); - } - } - - if (datag == 9) //Smooshy-wall sideways double-door - { - //find any points with either same x or same y coordinate - // as center (centx, centy) - should be 2 points found. - wallfind[0] = -1; - wallfind[1] = -1; - for(i=startwall;i>1)-wall[wallfind[j]].x; - day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y; - if (dax2 != 0) - { - dax2 = wall[wall[wall[wallfind[j]].point2].point2].x; - dax2 -= wall[wall[wallfind[j]].point2].x; - setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L); - setanimation(&wall[i].x,wall[i].x+dax2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L); - } - else if (day2 != 0) - { - day2 = wall[wall[wall[wallfind[j]].point2].point2].y; - day2 -= wall[wall[wallfind[j]].point2].y; - setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L); - setanimation(&wall[i].y,wall[i].y+day2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L); - } - } - else - { - i = wallfind[j]-1; if (i < startwall) i = endwall-1; - dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x; - day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y; - if (dax2 != 0) - { - setanimation(&wall[wallfind[j]].x,centx,4L,0L); - setanimation(&wall[i].x,centx+dax2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].x,centx+dax2,4L,0L); - } - else if (day2 != 0) - { - setanimation(&wall[wallfind[j]].y,centy,4L,0L); - setanimation(&wall[i].y,centy+day2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].y,centy+day2,4L,0L); - } - } - } - wsayfollow("updowndr.wav",4096L-256L,256L,¢x,¢y,0); - wsayfollow("updowndr.wav",4096L+256L,256L,¢x,¢y,0); - } - - if (datag == 13) //Swinging door - { - for(i=0;i>1) == centx) && (((wall[wallfind[j]].y+wall[wall[wallfind[j]].point2].y)>>1) == centy)) - { //door was closed - //find what direction door should open - i = wallfind[j]-1; if (i < startwall) i = endwall-1; - dax2 = wall[i].x-wall[wallfind[j]].x; - day2 = wall[i].y-wall[wallfind[j]].y; - if (dax2 != 0) - { - dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x; - dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x; - setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L); - setanimation(&wall[i].x,wall[i].x+dax2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L); - setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L); - } - else if (day2 != 0) - { - day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y; - day2 -= wall[wall[wall[wallfind[j]].point2].point2].y; - setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L); - setanimation(&wall[i].y,wall[i].y+day2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L); - setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L); - } - } - else - { //door was not closed - i = wallfind[j]-1; if (i < startwall) i = endwall-1; - dax2 = wall[i].x-wall[wallfind[j]].x; - day2 = wall[i].y-wall[wallfind[j]].y; - if (dax2 != 0) - { - setanimation(&wall[wallfind[j]].x,centx,4L,0L); - setanimation(&wall[i].x,centx+dax2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L); - setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L); - } - else if (day2 != 0) - { - setanimation(&wall[wallfind[j]].y,centy,4L,0L); - setanimation(&wall[i].y,centy+day2,4L,0L); - setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L); - setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L); - } - } - } - wsayfollow("updowndr.wav",4096L-64L,256L,¢x,¢y,0); - wsayfollow("updowndr.wav",4096L+64L,256L,¢x,¢y,0); - } -} - -void operatesprite(short dasprite) -{ - long datag; - - datag = sprite[dasprite].lotag; - - if (datag == 2) //A sprite that shoots a bomb - { - shootgun(dasprite, - sprite[dasprite].x,sprite[dasprite].y,sprite[dasprite].z, - sprite[dasprite].ang,100L,sprite[dasprite].sectnum,2); - } -} - -long changehealth(short snum, short deltahealth) -{ - long dax, day; - short good, k, startwall, endwall, s; - - if (health[snum] > 0) - { - health[snum] += deltahealth; - if (health[snum] > 999) health[snum] = 999; - - if (health[snum] <= 0) - { - health[snum] = -1; - wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - sprite[playersprite[snum]].picnum = SKELETON; - } - - if ((snum == screenpeek) && (screensize <= xdim)) - { - if (health[snum] > 0) - sprintf(tempbuf,"Health:%3ld",health[snum]); - else - sprintf(tempbuf,"YOU STINK!"); - - printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80); - } - } - return(health[snum] <= 0); //You were just injured -} - -void changenumbombs(short snum, short deltanumbombs) { // Andy did this - numbombs[snum] += deltanumbombs; - if (numbombs[snum] > 999) numbombs[snum] = 999; - if (numbombs[snum] <= 0) { - wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - numbombs[snum] = 0; - } - - if ((snum == screenpeek) && (screensize <= xdim)) { - sprintf(tempbuf,"B:%3d",numbombs[snum]); - printext(8L,(ydim - 28L),tempbuf,ALPHABET,80); - } -} - -void changenummissiles(short snum, short deltanummissiles) { // Andy did this - nummissiles[snum] += deltanummissiles; - if (nummissiles[snum] > 999) nummissiles[snum] = 999; - if (nummissiles[snum] <= 0) { - wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - nummissiles[snum] = 0; - } - - if ((snum == screenpeek) && (screensize <= xdim)) { - sprintf(tempbuf,"M:%3d",nummissiles[snum]); - printext(8L,(ydim - 20L),tempbuf,ALPHABET,80); - } -} - -void changenumgrabbers(short snum, short deltanumgrabbers) { // Andy did this - numgrabbers[snum] += deltanumgrabbers; - if (numgrabbers[snum] > 999) numgrabbers[snum] = 999; - if (numgrabbers[snum] <= 0) { - wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - numgrabbers[snum] = 0; - } - - if ((snum == screenpeek) && (screensize <= xdim)) { - sprintf(tempbuf,"G:%3d",numgrabbers[snum]); - printext(8L,(ydim - 12L),tempbuf,ALPHABET,80); - } -} - -static long ostatusflytime = 0x80000000; -void drawstatusflytime(short snum) { // Andy did this - long nstatusflytime; - - if ((snum == screenpeek) && (screensize <= xdim)) { - nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120); - if (nstatusflytime > 1000) nstatusflytime = 1000; - else if (nstatusflytime < 0) nstatusflytime = 0; - if (nstatusflytime != ostatusflytime) { - if (nstatusflytime > 999) sprintf(tempbuf,"FT:BIG"); - else sprintf(tempbuf,"FT:%3ld",nstatusflytime); - printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80); - ostatusflytime = nstatusflytime; - } - } -} - -void drawstatusbar(short snum) { // Andy did this - long nstatusflytime; - - if ((snum == screenpeek) && (screensize <= xdim)) { - Bsprintf(tempbuf,"Deaths:%d",deaths[snum]); - printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-16,tempbuf,ALPHABET,80); - Bsprintf(tempbuf,"Health:%3ld",health[snum]); - printext((xdim>>1)-(Bstrlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80); - - Bsprintf(tempbuf,"B:%3d",numbombs[snum]); - printext(8L,(ydim - 28L),tempbuf,ALPHABET,80); - Bsprintf(tempbuf,"M:%3d",nummissiles[snum]); - printext(8L,(ydim - 20L),tempbuf,ALPHABET,80); - Bsprintf(tempbuf,"G:%3d",numgrabbers[snum]); - printext(8L,(ydim - 12L),tempbuf,ALPHABET,80); - - nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120); - if (nstatusflytime < 0) { - Bsprintf(tempbuf,"FT: 0"); - ostatusflytime = 0; - } - else if (nstatusflytime > 999) { - Bsprintf(tempbuf,"FT:BIG"); - ostatusflytime = 999; - } - else { - Bsprintf(tempbuf,"FT:%3ld",nstatusflytime); - ostatusflytime = nstatusflytime; - } - printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80); - } -} - -void prepareboard(char *daboardfilename) -{ - short startwall, endwall, dasector; - long i, j, k=0, s, dax, day, daz, dax2, day2; - - getmessageleng = 0; - typemessageleng = 0; - - randomseed = 17L; - - //Clear (do)animation's list - animatecnt = 0; - typemode = 0; - locselectedgun = 0; - locselectedgun2 = 0; - - if (loadboard(daboardfilename,0,&posx[0],&posy[0],&posz[0],&ang[0],&cursectnum[0]) == -1) - { - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - printf("Board not found\n"); - exit(0); - } else { - char *fp; - - strcpy(tempbuf, daboardfilename); - fp = strrchr(tempbuf,'.'); - if (fp) *fp = 0; - strcat(tempbuf,".mhk"); - - loadmaphack(tempbuf); - } - - setup3dscreen(); - - for(i=0;i dax2) dax2 = wall[j].x; - if (wall[j].y > day2) day2 = wall[j].y; - if (wall[j].lotag == 3) k = j; - } - if (wall[k].x == dax) dragxdir[dragsectorcnt] = -16; - if (wall[k].y == day) dragydir[dragsectorcnt] = -16; - if (wall[k].x == dax2) dragxdir[dragsectorcnt] = 16; - if (wall[k].y == day2) dragydir[dragsectorcnt] = 16; - - dasector = wall[startwall].nextsector; - dragx1[dragsectorcnt] = 0x7fffffff; - dragy1[dragsectorcnt] = 0x7fffffff; - dragx2[dragsectorcnt] = 0x80000000; - dragy2[dragsectorcnt] = 0x80000000; - startwall = sector[dasector].wallptr; - endwall = startwall+sector[dasector].wallnum; - for(j=startwall;j dragx2[dragsectorcnt]) dragx2[dragsectorcnt] = wall[j].x; - if (wall[j].y > dragy2[dragsectorcnt]) dragy2[dragsectorcnt] = wall[j].y; - - setinterpolation(§or[dasector].floorz); - setinterpolation(&wall[j].x); - setinterpolation(&wall[j].y); - setinterpolation(&wall[wall[j].nextwall].x); - setinterpolation(&wall[wall[j].nextwall].y); - } - - dragx1[dragsectorcnt] += (wall[sector[i].wallptr].x-dax); - dragy1[dragsectorcnt] += (wall[sector[i].wallptr].y-day); - dragx2[dragsectorcnt] -= (dax2-wall[sector[i].wallptr].x); - dragy2[dragsectorcnt] -= (day2-wall[sector[i].wallptr].y); - - dragfloorz[dragsectorcnt] = sector[i].floorz; - - dragsectorlist[dragsectorcnt++] = i; - break; - case 13: - startwall = sector[i].wallptr; - endwall = startwall+sector[i].wallnum; - for(j=startwall;j dax2) dax2 = wall[j].x; - if (wall[j].y > day2) day2 = wall[j].y; - } - for(j=startwall;j dax) && (wall[j].y > day) && (wall[j].x < dax2) && (wall[j].y < day2)) - { - subwayx[subwaytrackcnt] = wall[j].x; - } - else - { - subwaystop[subwaytrackcnt][subwaystopcnt[subwaytrackcnt]] = wall[j].x; - subwaystopcnt[subwaytrackcnt]++; - } - } - } - - for(j=1;j subwaytrackx1[subwaytrackcnt]) - if (wall[startwall].y > subwaytracky1[subwaytrackcnt]) - if (wall[startwall].x < subwaytrackx2[subwaytrackcnt]) - if (wall[startwall].y < subwaytracky2[subwaytrackcnt]) - { - if (sector[j].floorz != sector[i].floorz) - { - sector[j].ceilingstat |= 64; - sector[j].floorstat |= 64; - } - subwaytracksector[subwaytrackcnt][subwaynumsectors[subwaytrackcnt]] = j; - subwaynumsectors[subwaytrackcnt]++; - } - } - - subwayvel[subwaytrackcnt] = 64; - subwaypausetime[subwaytrackcnt] = 720; - - startwall = sector[i].wallptr; - endwall = startwall+sector[i].wallnum; - for(k=startwall;k subwaytrackx1[subwaytrackcnt]) - if (wall[k].y > subwaytracky1[subwaytrackcnt]) - if (wall[k].x < subwaytrackx2[subwaytrackcnt]) - if (wall[k].y < subwaytracky2[subwaytrackcnt]) - setinterpolation(&wall[k].x); - - for(j=1;j=0;k=nextspritesect[k]) - if (statrate[sprite[k].statnum] < 0) - setinterpolation(&sprite[k].x); - } - - - subwaytrackcnt++; - break; - } - if (sector[i].floorpicnum == FLOORMIRROR) - floormirrorsector[mirrorcnt++] = i; - //if (sector[i].ceilingpicnum == FLOORMIRROR) floormirrorsector[mirrorcnt++] = i; //SOS - } - - //Scan wall tags - - mirrorcnt = 0; - tilesizx[MIRROR] = 0; - tilesizy[MIRROR] = 0; - for(i=0;i= 0) && (wall[i].overpicnum == MIRROR) && (wall[i].cstat&32)) - { - if ((sector[s].floorstat&1) == 0) - { - wall[i].overpicnum = MIRRORLABEL+mirrorcnt; - sector[s].ceilingpicnum = MIRRORLABEL+mirrorcnt; - sector[s].floorpicnum = MIRRORLABEL+mirrorcnt; - sector[s].floorstat |= 1; - mirrorwall[mirrorcnt] = i; - mirrorsector[mirrorcnt] = s; - mirrorcnt++; - } - else - wall[i].overpicnum = sector[s].ceilingpicnum; - } - } - - //Invalidate textures in sector behind mirror - for(i=0;i=0;i--) copybuf(&sprite[i].x,&osprite[i].x,3); - - searchmap(cursectnum[connecthead]); - - lockclock = 0; - ototalclock = 0; - gotlastpacketclock = 0; - - screensize = xdim; - dax = ((xdim-screensize)>>1); - dax2 = dax+screensize-1; - day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - day2 = day + scale(screensize,ydim-32,xdim)-1; - setview(dax,day,dax2,day2); - - startofdynamicinterpolations = numinterpolations; - - /* - for(i=connecthead;i>=0;i=connectpoint2[i]) myminlag[i] = 0; - otherminlag = mymaxlag = 0; - */ -} - -void checktouchsprite(short snum, short sectnum) -{ - long i, nexti; - - if ((sectnum < 0) || (sectnum >= numsectors)) return; - - for(i=headspritesect[sectnum];i>=0;i=nexti) - { - nexti = nextspritesect[i]; - if (sprite[i].cstat&0x8000) continue; - if ((klabs(posx[snum]-sprite[i].x)+klabs(posy[snum]-sprite[i].y) < 512) && (klabs((posz[snum]>>8)-((sprite[i].z>>8)-(tilesizy[sprite[i].picnum]>>1))) <= 40)) - { - switch(sprite[i].picnum) - { - case COIN: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0); - changehealth(snum,5); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*60; - changespritestat((short)i,11); - } - break; - case DIAMONDS: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - changehealth(snum,15); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*120; - changespritestat((short)i,11); - } - break; - case COINSTACK: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - changehealth(snum,25); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*180; - changespritestat((short)i,11); - } - break; - case GIFTBOX: - wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0); - changehealth(snum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case CANNON: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (snum == myconnectindex) keystatus[4] = 1; - changenumbombs(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case LAUNCHER: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (snum == myconnectindex) keystatus[5] = 1; - changenummissiles(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case GRABCANNON: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (snum == myconnectindex) keystatus[6] = 1; - changenumgrabbers(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case AIRPLANE: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (flytime[snum] < lockclock) flytime[snum] = lockclock; - flytime[snum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat); - drawstatusflytime(snum); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - } - } - } -} - -void checkgrabbertouchsprite(short snum, short sectnum) // Andy did this -{ - long i, nexti; - short onum; - - if ((sectnum < 0) || (sectnum >= numsectors)) return; - onum = (sprite[snum].owner & (MAXSPRITES - 1)); - - for(i=headspritesect[sectnum];i>=0;i=nexti) - { - nexti = nextspritesect[i]; - if (sprite[i].cstat&0x8000) continue; - if ((klabs(sprite[snum].x-sprite[i].x)+klabs(sprite[snum].y-sprite[i].y) < 512) && (klabs((sprite[snum].z>>8)-((sprite[i].z>>8)-(tilesizy[sprite[i].picnum]>>1))) <= 40)) - { - switch(sprite[i].picnum) - { - case COIN: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0); - changehealth(onum,5); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*60; - changespritestat((short)i,11); - } - break; - case DIAMONDS: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - changehealth(onum,15); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*120; - changespritestat((short)i,11); - } - break; - case COINSTACK: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - changehealth(onum,25); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*180; - changespritestat((short)i,11); - } - break; - case GIFTBOX: - wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0); - changehealth(onum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case CANNON: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (onum == myconnectindex) keystatus[4] = 1; - changenumbombs(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case LAUNCHER: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (onum == myconnectindex) keystatus[5] = 1; - changenummissiles(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case GRABCANNON: - wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (onum == myconnectindex) keystatus[6] = 1; - changenumgrabbers(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1)); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - case AIRPLANE: - wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (flytime[snum] < lockclock) flytime[snum] = lockclock; - flytime[onum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat); - drawstatusflytime(onum); - if (sprite[i].statnum == 12) deletesprite((short)i); - else { - sprite[i].cstat |= 0x8000; - sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat); - changespritestat((short)i,11); - } - break; - } - } - } -} - -void shootgun(short snum, long x, long y, long z, - short daang, long dahoriz, short dasectnum, char guntype) -{ - short hitsect, hitwall, hitsprite, daang2; - long i, j, daz2, hitx, hity, hitz; - - switch(guntype) - { - case 0: //Shoot chain gun - daang2 = ((daang + (krand()&31)-16)&2047); - daz2 = ((100-dahoriz)*2000) + ((krand()-32768)>>1); - - hitscan(x,y,z,dasectnum, //Start position - sintable[(daang2+512)&2047], //X vector of 3D ang - sintable[daang2&2047], //Y vector of 3D ang - daz2, //Z vector of 3D ang - &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); - - if (wall[hitwall].picnum == KENPICTURE) - { - if (waloff[MAXTILES-1] != 0) wall[hitwall].picnum = MAXTILES-1; - wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&wall[hitwall].x,&wall[hitwall].y,0); - } - else if (((hitwall < 0) && (hitsprite < 0) && (hitz >= z) && ((sector[hitsect].floorpicnum == SLIME) || (sector[hitsect].floorpicnum == FLOORMIRROR))) || ((hitwall >= 0) && (wall[hitwall].picnum == SLIME))) - { //If you shoot slime, make a splash - wsayfollow("splash.wav",4096L+(krand()&511)-256,256L,&hitx,&hity,0); - spawnsprite(j,hitx,hity,hitz,2,0,0,32,64,64,0,0,SPLASH,daang, - 0,0,0,snum+4096,hitsect,4,63,0,0); //63=time left for splash - } - else - { - wsayfollow("shoot.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); - - if ((hitsprite >= 0) && (sprite[hitsprite].statnum < MAXSTATUS)) - switch(sprite[hitsprite].picnum) - { - case BROWNMONSTER: - if (sprite[hitsprite].lotag > 0) sprite[hitsprite].lotag -= 10; - if (sprite[hitsprite].lotag > 0) - { - wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&hitx,&hity,0); - if (sprite[hitsprite].lotag <= 25) - sprite[hitsprite].cstat |= 2; - } - else - { - wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); - sprite[hitsprite].z += ((tilesizy[sprite[hitsprite].picnum]*sprite[hitsprite].yrepeat)<<1); - sprite[hitsprite].picnum = GIFTBOX; - sprite[hitsprite].cstat &= ~0x83; //Should not clip, foot-z - changespritestat(hitsprite,12); - - spawnsprite(j,hitx,hity,hitz+(32<<8),0,-4,0,32,64,64, - 0,0,EXPLOSION,daang,0,0,0,snum+4096, - hitsect,5,31,0,0); - } - break; - case EVILAL: - wsayfollow("blowup.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); - sprite[hitsprite].picnum = EVILALGRAVE; - sprite[hitsprite].cstat = 0; - sprite[hitsprite].xvel = (krand()&255)-128; - sprite[hitsprite].yvel = (krand()&255)-128; - sprite[hitsprite].zvel = (krand()&4095)-3072; - changespritestat(hitsprite,9); - - spawnsprite(j,hitx,hity,hitz+(32<<8),0,-4,0,32,64,64,0, - 0,EXPLOSION,daang,0,0,0,snum+4096,hitsect,5,31,0,0); - //31=time left for explosion - - break; - case PLAYER: - for(j=connecthead;j>=0;j=connectpoint2[j]) - if (playersprite[j] == hitsprite) - { - wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&hitx,&hity,0); - changehealth(j,-10); - break; - } - break; - } - - spawnsprite(j,hitx,hity,hitz+(8<<8),2,-4,0,32,16,16,0,0, - EXPLOSION,daang,0,0,0,snum+4096,hitsect,3,63,0,0); - - //Sprite starts out with center exactly on wall. - //This moves it back enough to see it at all angles. - movesprite((short)j,-(((long)sintable[(512+daang)&2047]*TICSPERFRAME)<<4),-(((long)sintable[daang]*TICSPERFRAME)<<4),0L,4L<<8,4L<<8,CLIPMASK1); - } - break; - case 1: //Shoot silver sphere bullet - spawnsprite(j,x,y,z,1+128,0,0,16,64,64,0,0,BULLET,daang, - sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5, - (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); - wsayfollow("shoot2.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1); - break; - case 2: //Shoot bomb - spawnsprite(j,x,y,z,128,0,0,12,16,16,0,0,BOMB,daang, - sintable[(daang+512)&2047]*5>>8,sintable[daang&2047]*5>>8, - (80-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); - wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1); - break; - case 3: //Shoot missile (Andy did this) - spawnsprite(j,x,y,z,1+128,0,0,16,32,32,0,0,MISSILE,daang, - sintable[(daang+512)&2047]>>4,sintable[daang&2047]>>4, - (100-dahoriz)<<7,snum+4096,dasectnum,6,0,0,0); - wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1); - break; - case 4: //Shoot grabber (Andy did this) - spawnsprite(j,x,y,z,1+128,0,0,16,64,64,0,0,GRABBER,daang, - sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5, - (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0); - wsayfollow("shoot4.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1); - break; - } -} - -#define MAXVOXMIPS 5 -extern char *voxoff[][MAXVOXMIPS]; -void analyzesprites(long dax, long day) -{ - long i, j=0, k, *intptr; - point3d *ospr; - spritetype *tspr; - - //This function is called between drawrooms() and drawmasks() - //It has a list of possible sprites that may be drawn on this frame - - for(i=0,tspr=&tsprite[0];ipicnum] >= 0) - switch(tspr->picnum) - { - case PLAYER: - // //Get which of the 8 angles of the sprite to draw (0-7) - // //k ranges from 0-7 - //k = getangle(tspr->x-dax,tspr->y-day); - //k = (((tspr->ang+3072+128-k)&2047)>>8)&7; - // //This guy has only 5 pictures for 8 angles (3 are x-flipped) - //if (k <= 4) - //{ - // tspr->picnum += (k<<2); - // tspr->cstat &= ~4; //clear x-flipping bit - //} - //else - //{ - // tspr->picnum += ((8-k)<<2); - // tspr->cstat |= 4; //set x-flipping bit - //} - - if ((tspr->cstat&2) == 0) - { - //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; - intptr = (long *)voxoff[ tiletovox[PLAYER] ][0]; - tspr->xrepeat = scale(tspr->xrepeat,56,intptr[2]); - tspr->yrepeat = scale(tspr->yrepeat,56,intptr[2]); - tspr->shade -= 6; - } - break; - case BROWNMONSTER: - //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum]; - break; - } -#endif - - k = statrate[tspr->statnum]; - if (k >= 0) //Interpolate moving sprite - { - ospr = &osprite[tspr->owner]; - switch(k) - { - case 0: j = smoothratio; break; - case 1: j = (smoothratio>>1)+(((nummoves-tspr->owner)&1)<<15); break; - case 3: j = (smoothratio>>2)+(((nummoves-tspr->owner)&3)<<14); break; - case 7: j = (smoothratio>>3)+(((nummoves-tspr->owner)&7)<<13); break; - case 15: j = (smoothratio>>4)+(((nummoves-tspr->owner)&15)<<12); break; - } - k = tspr->x-ospr->x; tspr->x = ospr->x; - if (k != 0) tspr->x += mulscale16(k,j); - k = tspr->y-ospr->y; tspr->y = ospr->y; - if (k != 0) tspr->y += mulscale16(k,j); - k = tspr->z-ospr->z; tspr->z = ospr->z; - if (k != 0) tspr->z += mulscale16(k,j); - } - - //Don't allow close explosion sprites to be transluscent - k = tspr->statnum; - if ((k == 3) || (k == 4) || (k == 5) || (k == 7)) - if (klabs(dax-tspr->x) < 256) - if (klabs(day-tspr->y) < 256) - tspr->cstat &= ~2; - - tspr->shade += 6; - if (sector[tspr->sectnum].ceilingstat&1) - tspr->shade += sector[tspr->sectnum].ceilingshade; - else - tspr->shade += sector[tspr->sectnum].floorshade; - } -} - -void tagcode(void) -{ - long i, nexti, j, k, l, s, dax, day, daz, dax2, day2, cnt, good; - short startwall, endwall, dasector, p, oldang; - - for(p=connecthead;p>=0;p=connectpoint2[p]) - { - if (sector[cursectnum[p]].lotag == 1) - { - activatehitag(sector[cursectnum[p]].hitag); - sector[cursectnum[p]].lotag = 0; - sector[cursectnum[p]].hitag = 0; - } - if ((sector[cursectnum[p]].lotag == 2) && (cursectnum[p] != ocursectnum[p])) - activatehitag(sector[cursectnum[p]].hitag); - } - - for(i=0;i>2); - if (j >= 16) j = 31-j; - { - sector[dasector].ceilingshade = j; - sector[dasector].floorshade = j; - startwall = sector[dasector].wallptr; - endwall = startwall+sector[dasector].wallnum; - for(s=startwall;s=0;p=connectpoint2[p]) - if (sector[cursectnum[p]].lotag == 10) //warp sector - { - if (cursectnum[p] != ocursectnum[p]) - { - warpsprite(playersprite[p]); - posx[p] = sprite[playersprite[p]].x; - posy[p] = sprite[playersprite[p]].y; - posz[p] = sprite[playersprite[p]].z; - ang[p] = sprite[playersprite[p]].ang; - cursectnum[p] = sprite[playersprite[p]].sectnum; - - sprite[playersprite[p]].z += EYEHEIGHT; - - //warp(&posx[p],&posy[p],&posz[p],&ang[p],&cursectnum[p]); - //Update sprite representation of player - //setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); - //sprite[playersprite[p]].ang = ang[p]; - } - } - - for(i=0;i>2)&255); - } - - for(i=0;i>2)&255); - sector[floorpanninglist[i]].floorypanning = ((lockclock>>2)&255); - } - - for(i=0;i dragx2[i]) dragxdir[i] = -16; - if (wall[startwall].y+dragydir[i] > dragy2[i]) dragydir[i] = -16; - - for(j=startwall;j>3); - - for(p=connecthead;p>=0;p=connectpoint2[p]) - if (cursectnum[p] == dasector) - { - posx[p] += dragxdir[i]; - posy[p] += dragydir[i]; - if (p == myconnectindex) - { myx += dragxdir[i]; myy += dragydir[i]; } - //posz[p] += (sector[dasector].floorz-j); - - //Update sprite representation of player - setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); - sprite[playersprite[p]].ang = ang[p]; - } - } - - for(i=0;i=0;p=connectpoint2[p]) - if ((cursectnum[p] == swingsector[i]) || (testneighborsectors(cursectnum[p],swingsector[i]) == 1)) - { - cnt = 256; - do - { - good = 1; - - //swingangopendir is -1 if forwards, 1 is backwards - l = (swingangopendir[i] > 0); - for(k=l+3;k>=l;k--) - if (clipinsidebox(posx[p],posy[p],swingwall[i][k],128L) != 0) - { - good = 0; - break; - } - if (good == 0) - { - if (cnt == 256) - { - swinganginc[i] = -swinganginc[i]; - swingang[i] = oldang; - } - else - { - swingang[i] = ((swingang[i]-swinganginc[i])&2047); - } - for(k=1;k<=3;k++) - rotatepoint(swingx[i][0],swingy[i][0],swingx[i][k],swingy[i][k],swingang[i],&wall[swingwall[i][k]].x,&wall[swingwall[i][k]].y); - if (swingang[i] == swingangclosed[i]) - { - wsayfollow("closdoor.wav",4096L+(krand()&511)-256,256L,&swingx[i][0],&swingy[i][0],0); - swinganginc[i] = 0; - break; - } - if (swingang[i] == swingangopen[i]) - { - swinganginc[i] = 0; - break; - } - cnt--; - } - } while ((good == 0) && (cnt > 0)); - } - } - } - if (swinganginc[i] == 0) - for(j=1;j<=3;j++) - { - stopinterpolation(&wall[swingwall[i][j]].x); - stopinterpolation(&wall[swingwall[i][j]].y); - } - } - - for(i=0;i 2)) - { - dasector = subwaytracksector[i][0]; - startwall = sector[dasector].wallptr; - endwall = startwall+sector[dasector].wallnum; - for(k=startwall;k subwaytrackx1[i]) - if (wall[k].y > subwaytracky1[i]) - if (wall[k].x < subwaytrackx2[i]) - if (wall[k].y < subwaytracky2[i]) - wall[k].x += subwayvel[i]; - - for(j=1;j=0;s=nextspritesect[s]) - sprite[s].x += subwayvel[i]; - } - - for(p=connecthead;p>=0;p=connectpoint2[p]) - if (cursectnum[p] != subwaytracksector[i][0]) - if (sector[cursectnum[p]].floorz != sector[subwaytracksector[i][0]].floorz) - if (posx[p] > subwaytrackx1[i]) - if (posy[p] > subwaytracky1[i]) - if (posx[p] < subwaytrackx2[i]) - if (posy[p] < subwaytracky2[i]) - { - posx[p] += subwayvel[i]; - if (p == myconnectindex) - { myx += subwayvel[i]; } - - //Update sprite representation of player - setsprite(playersprite[p],posx[p],posy[p],posz[p]+EYEHEIGHT); - sprite[playersprite[p]].ang = ang[p]; - } - - subwayx[i] += subwayvel[i]; - } - - j = subwayvel[i]; - k = subwaystop[i][subwaygoalstop[i]] - subwayx[i]; - if (k > 0) - { - if (k > 4096) - { - if (subwayvel[i] < 256) subwayvel[i]++; - } - else - subwayvel[i] = (k>>4)+1; - } - else if (k < 0) - { - if (k < -4096) - { - if (subwayvel[i] > -256) subwayvel[i]--; - } - else - subwayvel[i] = (k>>4)-1; - } - if ((j < 0) && (subwayvel[i] >= 0)) subwayvel[i] = -1; - if ((j > 0) && (subwayvel[i] <= 0)) subwayvel[i] = 1; - - if ((subwayvel[i] <= 2) && (subwayvel[i] >= -2) && (klabs(k) < 2048)) - { - //Open / close doors - if ((subwaypausetime[i] == 720) || ((subwaypausetime[i] >= 120) && (subwaypausetime[i]-TICSPERFRAME < 120))) - activatehitag(sector[subwaytracksector[i][0]].hitag); - - subwaypausetime[i] -= TICSPERFRAME; - if (subwaypausetime[i] < 0) - { - subwaypausetime[i] = 720; - if (subwayvel[i] < 0) - { - subwaygoalstop[i]--; - if (subwaygoalstop[i] < 0) - { - subwaygoalstop[i] = 1; - subwayvel[i] = 1; - } - } - else if (subwayvel[i] > 0) - { - subwaygoalstop[i]++; - if (subwaygoalstop[i] >= subwaystopcnt[i]) - { - subwaygoalstop[i] = subwaystopcnt[i]-2; - subwayvel[i] = -1; - } - } - } - } - } -} - -void statuslistcode(void) -{ - short p, target, hitobject, daang, osectnum, movestat; - long i, nexti, j, nextj, k, l, dax, day, daz, dist, ox, oy, mindist; - long doubvel, xvect, yvect; - - //Go through active BROWNMONSTER list - for(i=headspritestat[1];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - k = krand(); - - //Choose a target player - mindist = 0x7fffffff; target = connecthead; - for(p=connecthead;p>=0;p=connectpoint2[p]) - { - dist = klabs(sprite[i].x-posx[p])+klabs(sprite[i].y-posy[p]); - if (dist < mindist) mindist = dist, target = p; - } - - //brown monster decides to shoot bullet - if ((k&63) == 23) - { - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 0) - { - if ((k&0xf00) == 0xb00) changespritestat(i,2); - } - else - { - wsayfollow("monshoot.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); - - doubvel = (TICSPERFRAME<<((ssync[target].bits&256)>0)); - xvect = 0, yvect = 0; - if (ssync[target].fvel != 0) - { - xvect += ((((long)ssync[target].fvel)*doubvel*(long)sintable[(ang[target]+512)&2047])>>3); - yvect += ((((long)ssync[target].fvel)*doubvel*(long)sintable[ang[target]&2047])>>3); - } - if (ssync[target].svel != 0) - { - xvect += ((((long)ssync[target].svel)*doubvel*(long)sintable[ang[target]&2047])>>3); - yvect += ((((long)ssync[target].svel)*doubvel*(long)sintable[(ang[target]+1536)&2047])>>3); - } - - ox = posx[target]; oy = posy[target]; - - //distance is j - j = ksqrt((ox-sprite[i].x)*(ox-sprite[i].x)+(oy-sprite[i].y)*(oy-sprite[i].y)); - - switch((sprite[i].extra>>11)&3) - { - case 1: j = -(j>>1); break; - case 3: j = 0; break; - case 0: case 2: break; - } - sprite[i].extra += 2048; - - //rate is (TICSPERFRAME<<19) - xvect = scale(xvect,j,TICSPERFRAME<<19); - yvect = scale(yvect,j,TICSPERFRAME<<19); - clipmove(&ox,&oy,&posz[target],&cursectnum[target],xvect<<14,yvect<<14,128L,4<<8,4<<8,CLIPMASK0); - ox -= sprite[i].x; - oy -= sprite[i].y; - - daang = ((getangle(ox,oy)+(krand()&7)-4)&2047); - - dax = (sintable[(daang+512)&2047]>>6); - day = (sintable[daang&2047]>>6); - daz = 0; - if (ox != 0) - daz = scale(dax,posz[target]+(8<<8)-sprite[i].z,ox); - else if (oy != 0) - daz = scale(day,posz[target]+(8<<8)-sprite[i].z,oy); - - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,128,0,0, - 16,sprite[i].xrepeat,sprite[i].yrepeat,0,0,BULLET,daang,dax,day,daz,i,sprite[i].sectnum,6,0,0,0); - - sprite[i].extra &= (~2047); - } - } - - //Move brown monster - dax = sprite[i].x; //Back up old x&y if stepping off cliff - day = sprite[i].y; - - doubvel = max(mulscale7(sprite[i].xrepeat,sprite[i].yrepeat),4); - - osectnum = sprite[i].sectnum; - movestat = movesprite((short)i,(long)sintable[(sprite[i].ang+512)&2047]*doubvel,(long)sintable[sprite[i].ang]*doubvel,0L,4L<<8,4L<<8,CLIPMASK0); - if (globloz > sprite[i].z+(48<<8)) - { sprite[i].x = dax; sprite[i].y = day; movestat = 1; } - else - sprite[i].z = globloz-((tilesizy[sprite[i].picnum]*sprite[i].yrepeat)<<1); - - if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) - { warpsprite((short)i); movestat = 0; } - - if ((movestat != 0) || ((k&63) == 1)) - { - if (sprite[i].ang == (sprite[i].extra&2047)) - { - daang = (getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y)&2047); - daang = ((daang+(krand()&1023)-512)&2047); - sprite[i].extra = ((sprite[i].extra&(~2047))|daang); - } - if ((sprite[i].extra-sprite[i].ang)&1024) - { - sprite[i].ang = ((sprite[i].ang-32)&2047); - if (!((sprite[i].extra-sprite[i].ang)&1024)) sprite[i].ang = (sprite[i].extra&2047); - } - else - { - sprite[i].ang = ((sprite[i].ang+32)&2047); - if (((sprite[i].extra-sprite[i].ang)&1024)) sprite[i].ang = (sprite[i].extra&2047); - } - } - } - - for(i=headspritestat[10];i>=0;i=nexti) //EVILAL list - { - nexti = nextspritestat[i]; - - if (sprite[i].yrepeat < 38) continue; - if (sprite[i].yrepeat < 64) - { - sprite[i].xrepeat++; - sprite[i].yrepeat++; - continue; - } - - if ((nummoves-i)&statrate[10]) continue; - - //Choose a target player - mindist = 0x7fffffff; target = connecthead; - for(p=connecthead;p>=0;p=connectpoint2[p]) - { - dist = klabs(sprite[i].x-posx[p])+klabs(sprite[i].y-posy[p]); - if (dist < mindist) mindist = dist, target = p; - } - - k = (krand()&255); - - if ((sprite[i].lotag&32) && (k < 48)) //Al decides to reproduce - { - l = 0; - if ((sprite[i].lotag&64) && (k < 2)) //Give him a chance to reproduce without seeing you - l = 1; - else if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1) - l = 1; - if (l != 0) - { - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].cstat,sprite[i].shade,sprite[i].pal, - sprite[i].clipdist,38,38,sprite[i].xoffset,sprite[i].yoffset,sprite[i].picnum,krand()&2047,0,0,0,i, - sprite[i].sectnum,10,sprite[i].lotag,sprite[i].hitag,sprite[i].extra); - switch(krand()&31) //Mutations! - { - case 0: sprite[i].cstat ^= 2; break; - case 1: sprite[i].cstat ^= 512; break; - case 2: sprite[i].shade++; break; - case 3: sprite[i].shade--; break; - case 4: sprite[i].pal ^= 16; break; - case 5: case 6: case 7: sprite[i].lotag ^= (1<<(krand()&7)); break; - case 8: sprite[i].lotag = (krand()&255); break; - } - } - } - if (k >= 208+((sprite[i].lotag&128)>>2)) //Al decides to shoot bullet - { - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1) - { - wsayfollow("zipguns.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); - - spawnsprite(j,sprite[i].x,sprite[i].y, - sector[sprite[i].sectnum].floorz-(24<<8), - 0,0,0,16,32,32,0,0,BULLET, - (getangle(posx[target]-sprite[j].x, - posy[target]-sprite[j].y)+(krand()&15)-8)&2047, - sintable[(sprite[j].ang+512)&2047]>>6, - sintable[sprite[j].ang&2047]>>6, - ((posz[target]+(8<<8)-sprite[j].z)<<8) / - (ksqrt((posx[target]-sprite[j].x) * - (posx[target]-sprite[j].x) + - (posy[target]-sprite[j].y) * - (posy[target]-sprite[j].y))+1), - i,sprite[i].sectnum,6,0,0,0); - } - } - - //Move Al - l = (((sprite[i].lotag&3)+2)<<8); - if (sprite[i].lotag&4) l = -l; - dax = sintable[(sprite[i].ang+512)&2047]*l; - day = sintable[sprite[i].ang]*l; - - osectnum = sprite[i].sectnum; - movestat = movesprite((short)i,dax,day,0L,-8L<<8,-8L<<8,CLIPMASK0); - sprite[i].z = globloz; - if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) - { - warpsprite((short)i); - movestat = 0; - } - - if (sprite[i].lotag&16) - { - if (((k&124) >= 120) && (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1)) - sprite[i].ang = getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y); - else - sprite[i].ang = (krand()&2047); - } - - if (movestat != 0) - { - if ((k&2) && (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[target],posy[target],posz[target],cursectnum[target]) == 1)) - sprite[i].ang = getangle(posx[target]-sprite[i].x,posy[target]-sprite[i].y); - else - sprite[i].ang = (krand()&2047); - - if ((movestat&49152) == 49152) - if (sprite[movestat&16383].picnum == EVILAL) - if ((k&31) >= 30) - { - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[i].picnum = EVILALGRAVE; - sprite[i].cstat = 0; - sprite[i].xvel = (krand()&255)-128; - sprite[i].yvel = (krand()&255)-128; - sprite[i].zvel = (krand()&4095)-3072; - changespritestat(i,9); - } - - if (sprite[i].lotag&8) - if ((k&31) >= 30) - { - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[i].picnum = EVILALGRAVE; - sprite[i].cstat = 0; - sprite[i].xvel = (krand()&255)-128; - sprite[i].yvel = (krand()&255)-128; - sprite[i].zvel = (krand()&4095)-3072; - changespritestat(i,9); - } - - if (movestat == -1) - { - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[i].picnum = EVILALGRAVE; - sprite[i].cstat = 0; - sprite[i].xvel = (krand()&255)-128; - sprite[i].yvel = (krand()&255)-128; - sprite[i].zvel = (krand()&4095)-3072; - changespritestat(i,9); - } - } - } - - //Go through travelling bullet sprites - for(i=headspritestat[6];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - if ((nummoves-i)&statrate[6]) continue; - - //If the sprite is a bullet then... - if ((sprite[i].picnum == BULLET) || (sprite[i].picnum == GRABBER) || (sprite[i].picnum == MISSILE) || (sprite[i].picnum == BOMB)) - { - dax = ((((long)sprite[i].xvel)*TICSPERFRAME)<<12); - day = ((((long)sprite[i].yvel)*TICSPERFRAME)<<12); - daz = ((((long)sprite[i].zvel)*TICSPERFRAME)>>2); - if (sprite[i].picnum == BOMB) daz = 0; - - osectnum = sprite[i].sectnum; - hitobject = movesprite((short)i,dax,day,daz,4L<<8,4L<<8,CLIPMASK1); - if ((sprite[i].sectnum != osectnum) && (sector[sprite[i].sectnum].lotag == 10)) - { - warpsprite((short)i); - hitobject = 0; - } - - if (sprite[i].picnum == GRABBER) { // Andy did this (& Ken) !Homing! - checkgrabbertouchsprite(i,sprite[i].sectnum); - l = 0x7fffffff; - for (j = connecthead; j >= 0; j = connectpoint2[j]) // Players - if (j != (sprite[i].owner & (MAXSPRITES - 1))) - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,posx[j],posy[j],posz[j],cursectnum[j])) { - k = ksqrt(sqr(posx[j] - sprite[i].x) + sqr(posy[j] - sprite[i].y) + (sqr(posz[j] - sprite[i].z) >> 8)); - if (k < l) { - l = k; - dax = (posx[j] - sprite[i].x); - day = (posy[j] - sprite[i].y); - daz = (posz[j] - sprite[i].z); - } - } - for(j = headspritestat[1]; j >= 0; j = nextj) { // Active monsters - nextj = nextspritestat[j]; - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z,sprite[j].sectnum)) { - k = ksqrt(sqr(sprite[j].x - sprite[i].x) + sqr(sprite[j].y - sprite[i].y) + (sqr(sprite[j].z - sprite[i].z) >> 8)); - if (k < l) { - l = k; - dax = (sprite[j].x - sprite[i].x); - day = (sprite[j].y - sprite[i].y); - daz = (sprite[j].z - sprite[i].z); - } - } - } - for(j = headspritestat[2]; j >= 0; j = nextj) { // Inactive monsters - nextj = nextspritestat[j]; - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z,sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z,sprite[j].sectnum)) { - k = ksqrt(sqr(sprite[j].x - sprite[i].x) + sqr(sprite[j].y - sprite[i].y) + (sqr(sprite[j].z - sprite[i].z) >> 8)); - if (k < l) { - l = k; - dax = (sprite[j].x - sprite[i].x); - day = (sprite[j].y - sprite[i].y); - daz = (sprite[j].z - sprite[i].z); - } - } - } - if (l != 0x7fffffff) { - sprite[i].xvel = (divscale7(dax,l) + sprite[i].xvel); // 1/5 of velocity is homing, 4/5 is momentum - sprite[i].yvel = (divscale7(day,l) + sprite[i].yvel); // 1/5 of velocity is homing, 4/5 is momentum - sprite[i].zvel = (divscale7(daz,l) + sprite[i].zvel); // 1/5 of velocity is homing, 4/5 is momentum - l = ksqrt((sprite[i].xvel * sprite[i].xvel) + (sprite[i].yvel * sprite[i].yvel) + ((sprite[i].zvel * sprite[i].zvel) >> 8)); - sprite[i].xvel = divscale9(sprite[i].xvel,l); - sprite[i].yvel = divscale9(sprite[i].yvel,l); - sprite[i].zvel = divscale9(sprite[i].zvel,l); - sprite[i].ang = getangle(sprite[i].xvel,sprite[i].yvel); - } - } - - if (sprite[i].picnum == BOMB) - { - j = sprite[i].sectnum; - if ((sector[j].floorstat&2) && (sprite[i].z > globloz-(8<<8))) - { - k = sector[j].wallptr; - daang = getangle(wall[wall[k].point2].x-wall[k].x,wall[wall[k].point2].y-wall[k].y); - sprite[i].xvel += mulscale22(sintable[(daang+1024)&2047],sector[j].floorheinum); - sprite[i].yvel += mulscale22(sintable[(daang+512)&2047],sector[j].floorheinum); - } - } - - if (sprite[i].picnum == BOMB) - { - sprite[i].z += sprite[i].zvel; - sprite[i].zvel += (TICSPERFRAME<<7); - if (sprite[i].z < globhiz+(tilesizy[BOMB]<<6)) - { - sprite[i].z = globhiz+(tilesizy[BOMB]<<6); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - if (sprite[i].z > globloz-(tilesizy[BOMB]<<6)) - { - sprite[i].z = globloz-(tilesizy[BOMB]<<6); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - dax = sprite[i].xvel; day = sprite[i].yvel; - dist = dax*dax+day*day; - if (dist < 512) - { - bombexplode(i); - goto bulletisdeletedskip; - } - if (dist < 4096) - { - sprite[i].xrepeat = ((4096+2048)*16) / (dist+2048); - sprite[i].yrepeat = sprite[i].xrepeat; - sprite[i].xoffset = (krand()&15)-8; - sprite[i].yoffset = (krand()&15)-8; - } - if (mulscale30(krand(),dist) == 0) - { - sprite[i].xvel -= ksgn(sprite[i].xvel); - sprite[i].yvel -= ksgn(sprite[i].yvel); - sprite[i].zvel -= ksgn(sprite[i].zvel); - } - } - - //Check for bouncy objects before killing bullet - if ((hitobject&0xc000) == 16384) //Bullet hit a ceiling/floor - { - k = sector[hitobject&(MAXSECTORS-1)].wallptr; l = wall[k].point2; - daang = getangle(wall[l].x-wall[k].x,wall[l].y-wall[k].y); - - getzsofslope(hitobject&(MAXSECTORS-1),sprite[i].x,sprite[i].y,&k,&l); - if (sprite[i].z < ((k+l)>>1)) k = sector[hitobject&(MAXSECTORS-1)].ceilingheinum; - else k = sector[hitobject&(MAXSECTORS-1)].floorheinum; - - dax = mulscale14(k,sintable[(daang)&2047]); - day = mulscale14(k,sintable[(daang+1536)&2047]); - daz = 4096; - - k = sprite[i].xvel*dax+sprite[i].yvel*day+mulscale4(sprite[i].zvel,daz); - l = dax*dax+day*day+daz*daz; - if ((klabs(k)>>14) < l) - { - k = divscale17(k,l); - sprite[i].xvel -= mulscale16(dax,k); - sprite[i].yvel -= mulscale16(day,k); - sprite[i].zvel -= mulscale12(daz,k); - } - wsayfollow("bouncy.wav",4096L+(krand()&127)-64,255,&sprite[i].x,&sprite[i].y,1); - hitobject = 0; - sprite[i].owner = -1; //Bullet turns evil! - } - else if ((hitobject&0xc000) == 32768) //Bullet hit a wall - { - if (wall[hitobject&4095].lotag == 8) - { - dax = sprite[i].xvel; day = sprite[i].yvel; - if ((sprite[i].picnum != BOMB) || (dax*dax+day*day >= 512)) - { - k = (hitobject&4095); l = wall[k].point2; - j = getangle(wall[l].x-wall[k].x,wall[l].y-wall[k].y)+512; - - //k = cos(ang) * sin(ang) * 2 - k = mulscale13(sintable[(j+512)&2047],sintable[j&2047]); - //l = cos(ang * 2) - l = sintable[((j<<1)+512)&2047]; - - ox = sprite[i].xvel; oy = sprite[i].yvel; - dax = -ox; day = -oy; - sprite[i].xvel = dmulscale14(day,k,dax,l); - sprite[i].yvel = dmulscale14(dax,k,-day,l); - - if (sprite[i].picnum == BOMB) - { - sprite[i].xvel -= (sprite[i].xvel>>3); - sprite[i].yvel -= (sprite[i].yvel>>3); - sprite[i].zvel -= (sprite[i].zvel>>3); - } - ox -= sprite[i].xvel; oy -= sprite[i].yvel; - dist = ((ox*ox+oy*oy)>>8); - wsayfollow("bouncy.wav",4096L+(krand()&127)-64,min(dist,256),&sprite[i].x,&sprite[i].y,1); - hitobject = 0; - sprite[i].owner = -1; //Bullet turns evil! - } - } - } - else if ((hitobject&0xc000) == 49152) //Bullet hit a sprite - { - if (sprite[hitobject&4095].picnum == BOUNCYMAT) - { - if ((sprite[hitobject&4095].cstat&48) == 0) - { - sprite[i].xvel = -sprite[i].xvel; - sprite[i].yvel = -sprite[i].yvel; - sprite[i].zvel = -sprite[i].zvel; - dist = 255; - } - else if ((sprite[hitobject&4095].cstat&48) == 16) - { - j = sprite[hitobject&4095].ang; - - //k = cos(ang) * sin(ang) * 2 - k = mulscale13(sintable[(j+512)&2047],sintable[j&2047]); - //l = cos(ang * 2) - l = sintable[((j<<1)+512)&2047]; - - ox = sprite[i].xvel; oy = sprite[i].yvel; - dax = -ox; day = -oy; - sprite[i].xvel = dmulscale14(day,k,dax,l); - sprite[i].yvel = dmulscale14(dax,k,-day,l); - - ox -= sprite[i].xvel; oy -= sprite[i].yvel; - dist = ((ox*ox+oy*oy)>>8); - } - sprite[i].owner = -1; //Bullet turns evil! - wsayfollow("bouncy.wav",4096L+(krand()&127)-64,min(dist,256),&sprite[i].x,&sprite[i].y,1); - hitobject = 0; - } - } - - if (hitobject != 0) - { - if ((sprite[i].picnum == MISSILE) || (sprite[i].picnum == BOMB)) - { - if ((hitobject&0xc000) == 49152) - if (sprite[hitobject&4095].lotag == 5) //Basketball hoop - { - wsayfollow("niceshot.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); - goto bulletisdeletedskip; - } - - bombexplode(i); - goto bulletisdeletedskip; - } - - if ((hitobject&0xc000) == 16384) //Hits a ceiling / floor - { - wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); - goto bulletisdeletedskip; - } - else if ((hitobject&0xc000) == 32768) //Bullet hit a wall - { - if (wall[hitobject&4095].picnum == KENPICTURE) - { - if (waloff[MAXTILES-1] != 0) - wall[hitobject&4095].picnum = MAXTILES-1; - wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); //Ken says, "Hello... how are you today!" - } - else - wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - - deletesprite((short)i); - goto bulletisdeletedskip; - } - else if ((hitobject&0xc000) == 49152) //Bullet hit a sprite - { - if ((sprite[hitobject&4095].lotag == 5) && (sprite[i].picnum == GRABBER)) { // Basketball hoop (Andy's addition) - wsayfollow("niceshot.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - switch (krand() & 63) { -case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: - sprite[i].picnum = COIN; break; -case 10: case 11: case 12: case 13: case 14: case 15: case 16: - sprite[i].picnum = DIAMONDS; break; - case 17: case 18: case 19: - sprite[i].picnum = COINSTACK; break; - case 20: case 21: case 22: case 23: - sprite[i].picnum = GIFTBOX; break; - case 24: case 25: - sprite[i].picnum = GRABCANNON; break; - case 26: case 27: - sprite[i].picnum = LAUNCHER; break; - case 28: case 29: case 30: - sprite[i].picnum = CANNON; break; - case 31: - sprite[i].picnum = AIRPLANE; break; - default: - deletesprite((short)i); - goto bulletisdeletedskip; - } - sprite[i].xvel = sprite[i].yvel = sprite[i].zvel = 0; - sprite[i].cstat &= ~0x83; //Should not clip, foot-z - changespritestat(i,12); - goto bulletisdeletedskip; - } - - //Check if bullet hit a player & find which player it was... - if (sprite[hitobject&4095].picnum == PLAYER) - for(j=connecthead;j>=0;j=connectpoint2[j]) - if (sprite[i].owner != j+4096) - if (playersprite[j] == (hitobject&4095)) - { - wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - if (sprite[i].picnum == GRABBER) { // Andy did this - k = ((sprite[i].xrepeat * sprite[i].yrepeat) * 3) >> 9; - changehealth((sprite[i].owner - 4096),k); - changehealth(j,-k); - } - else changehealth(j,-mulscale8(sprite[i].xrepeat,sprite[i].yrepeat)); - deletesprite((short)i); - goto bulletisdeletedskip; - } - - //Check if bullet hit any monsters... - j = (hitobject&4095); //j is the spritenum that the bullet (spritenum i) hit - if (sprite[i].owner != j) - { - switch(sprite[j].picnum) - { - case BROWNMONSTER: - if (sprite[j].lotag > 0) { - if (sprite[i].picnum == GRABBER) { // Andy did this - k = ((sprite[i].xrepeat * sprite[i].yrepeat) * 3) >> 9; - changehealth((sprite[i].owner - 4096),k); - sprite[j].lotag -= k; - } - sprite[j].lotag -= mulscale8(sprite[i].xrepeat,sprite[i].yrepeat); - } - if (sprite[j].lotag > 0) - { - if (sprite[j].lotag <= 25) sprite[j].cstat |= 2; - wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&sprite[i].x,&sprite[i].y,1); - } - else - { - wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[j].z += ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1); - sprite[j].picnum = GIFTBOX; - sprite[j].cstat &= ~0x83; //Should not clip, foot-z - - spawnsprite(k,sprite[j].x,sprite[j].y,sprite[j].z, - 0,-4,0,32,64,64,0,0,EXPLOSION,sprite[j].ang, - 0,0,0,j,sprite[j].sectnum,5,31,0,0); - //31=Time left for explosion to stay - - changespritestat(j,12); - } - deletesprite((short)i); - goto bulletisdeletedskip; - case EVILAL: - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[j].picnum = EVILALGRAVE; - sprite[j].cstat = 0; - sprite[j].xvel = (krand()&255)-128; - sprite[j].yvel = (krand()&255)-128; - sprite[j].zvel = (krand()&4095)-3072; - changespritestat(j,9); - - deletesprite((short)i); - goto bulletisdeletedskip; - case AL: - wsayfollow("blowup.wav",5144L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - sprite[j].xrepeat += 2; - sprite[j].yrepeat += 2; - if (sprite[j].yrepeat >= 38) - { - sprite[j].picnum = EVILAL; - //sprite[j].cstat |= 2; //Make him transluscent - changespritestat(j,10); - } - deletesprite((short)i); - goto bulletisdeletedskip; - default: - wsayfollow("bullseye.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); - goto bulletisdeletedskip; - } - } - } - } - } -bulletisdeletedskip: continue; - } - - //Go through monster waiting for you list - for(i=headspritestat[2];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - if ((nummoves-i)&15) continue; - - //Use dot product to see if monster's angle is towards a player - for(p=connecthead;p>=0;p=connectpoint2[p]) - if (sintable[(sprite[i].ang+512)&2047]*(posx[p]-sprite[i].x) + sintable[sprite[i].ang&2047]*(posy[p]-sprite[i].y) >= 0) - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[p],posy[p],posz[p],cursectnum[p]) == 1) - { - changespritestat(i,1); - //if (sprite[i].lotag == 100) - //{ - wsayfollow("iseeyou.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); - // sprite[i].lotag = 99; - //} - } - } - - //Go through smoke sprites - for(i=headspritestat[3];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - sprite[i].z -= (TICSPERFRAME<<6); - sprite[i].lotag -= TICSPERFRAME; - if (sprite[i].lotag < 0) deletesprite(i); - } - - //Go through splash sprites - for(i=headspritestat[4];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - sprite[i].lotag -= TICSPERFRAME; - sprite[i].picnum = SPLASH + ((63-sprite[i].lotag)>>4); - if (sprite[i].lotag < 0) deletesprite(i); - } - - //Go through explosion sprites - for(i=headspritestat[5];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - sprite[i].lotag -= TICSPERFRAME; - if (sprite[i].lotag < 0) deletesprite(i); - } - - //Go through bomb spriral-explosion sprites - for(i=headspritestat[7];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - sprite[i].xrepeat = (sprite[i].lotag>>2); - sprite[i].yrepeat = (sprite[i].lotag>>2); - sprite[i].lotag -= (TICSPERFRAME<<2); - if (sprite[i].lotag < 0) { deletesprite(i); continue; } - - if ((nummoves-i)&statrate[7]) continue; - - sprite[i].x += ((sprite[i].xvel*TICSPERFRAME)>>2); - sprite[i].y += ((sprite[i].yvel*TICSPERFRAME)>>2); - sprite[i].z += ((sprite[i].zvel*TICSPERFRAME)>>2); - - sprite[i].zvel += (TICSPERFRAME<<9); - if (sprite[i].z < sector[sprite[i].sectnum].ceilingz+(4<<8)) - { - sprite[i].z = sector[sprite[i].sectnum].ceilingz+(4<<8); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - if (sprite[i].z > sector[sprite[i].sectnum].floorz-(4<<8)) - { - sprite[i].z = sector[sprite[i].sectnum].floorz-(4<<8); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - } - - //EVILALGRAVE shrinking list - for(i=headspritestat[9];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - sprite[i].xrepeat = (sprite[i].lotag>>2); - sprite[i].yrepeat = (sprite[i].lotag>>2); - sprite[i].lotag -= TICSPERFRAME; - if (sprite[i].lotag < 0) { deletesprite(i); continue; } - - if ((nummoves-i)&statrate[9]) continue; - - sprite[i].x += (sprite[i].xvel*TICSPERFRAME); - sprite[i].y += (sprite[i].yvel*TICSPERFRAME); - sprite[i].z += (sprite[i].zvel*TICSPERFRAME); - - sprite[i].zvel += (TICSPERFRAME<<8); - if (sprite[i].z < sector[sprite[i].sectnum].ceilingz) - { - sprite[i].z = sector[sprite[i].sectnum].ceilingz; - sprite[i].xvel -= (sprite[i].xvel>>2); - sprite[i].yvel -= (sprite[i].yvel>>2); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - if (sprite[i].z > sector[sprite[i].sectnum].floorz) - { - sprite[i].z = sector[sprite[i].sectnum].floorz; - sprite[i].xvel -= (sprite[i].xvel>>2); - sprite[i].yvel -= (sprite[i].yvel>>2); - sprite[i].zvel = -(sprite[i].zvel>>1); - } - } - - //Re-spawning sprite list - for(i=headspritestat[11];i>=0;i=nexti) - { - nexti = nextspritestat[i]; - - sprite[i].extra -= TICSPERFRAME; - if (sprite[i].extra < 0) - { - wsayfollow("warp.wav",6144L+(krand()&127)-64,128L,&sprite[i].x,&sprite[i].y,0); - sprite[i].cstat &= ~0x8000; - sprite[i].extra = -1; - changespritestat((short)i,0); - } - } -} - -void activatehitag(short dahitag) -{ - long i, nexti; - - for(i=0;i=0;i=nexti) - { - nexti = nextspritestat[i]; - if (sprite[i].hitag == dahitag) operatesprite(i); - } -} - -void bombexplode(long i) -{ - long j, nextj, k, daang, dax, day, dist; - - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z,0,-4,0, - 32,64,64,0,0,EXPLOSION,sprite[i].ang, - 0,0,0,sprite[i].owner,sprite[i].sectnum,5,31,0,0); - //31=Time left for explosion to stay - - for(k=0;k<12;k++) - { - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z+(8<<8),2,-4,0, - 32,24,24,0,0,EXPLOSION,sprite[i].ang, - (krand()>>7)-256,(krand()>>7)-256,(krand()>>2)-8192, - sprite[i].owner,sprite[i].sectnum,7,96,0,0); - //96=Time left for smoke to be alive - } - - for(j=connecthead;j>=0;j=connectpoint2[j]) - { - dist = (posx[j]-sprite[i].x)*(posx[j]-sprite[i].x); - dist += (posy[j]-sprite[i].y)*(posy[j]-sprite[i].y); - dist += ((posz[j]-sprite[i].z)>>4)*((posz[j]-sprite[i].z)>>4); - if (dist < 4194304) - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,posx[j],posy[j],posz[j],cursectnum[j]) == 1) - { - k = ((32768/((dist>>16)+4))>>5); - if (j == myconnectindex) - { - daang = getangle(posx[j]-sprite[i].x,posy[j]-sprite[i].y); - dax = ((k*sintable[(daang+512)&2047])>>14); - day = ((k*sintable[daang&2047])>>14); - fvel += ((dax*sintable[(ang[j]+512)&2047]+day*sintable[ang[j]&2047])>>14); - svel += ((day*sintable[(ang[j]+512)&2047]-dax*sintable[ang[j]&2047])>>14); - } - changehealth(j,-k); //if changehealth returns 1, you're dead - } - } - - for(k=1;k<=2;k++) //Check for hurting monsters - { - for(j=headspritestat[k];j>=0;j=nextj) - { - nextj = nextspritestat[j]; - - dist = (sprite[j].x-sprite[i].x)*(sprite[j].x-sprite[i].x); - dist += (sprite[j].y-sprite[i].y)*(sprite[j].y-sprite[i].y); - dist += ((sprite[j].z-sprite[i].z)>>4)*((sprite[j].z-sprite[i].z)>>4); - if (dist >= 4194304) continue; - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z-(tilesizy[sprite[j].picnum]<<7),sprite[j].sectnum) == 0) - continue; - if (sprite[j].picnum == BROWNMONSTER) - { - sprite[j].z += ((tilesizy[sprite[j].picnum]*sprite[j].yrepeat)<<1); - sprite[j].picnum = GIFTBOX; - sprite[j].cstat &= ~0x83; //Should not clip, foot-z - changespritestat(j,12); - } - } - } - - for(j=headspritestat[10];j>=0;j=nextj) //Check for EVILAL's - { - nextj = nextspritestat[j]; - - dist = (sprite[j].x-sprite[i].x)*(sprite[j].x-sprite[i].x); - dist += (sprite[j].y-sprite[i].y)*(sprite[j].y-sprite[i].y); - dist += ((sprite[j].z-sprite[i].z)>>4)*((sprite[j].z-sprite[i].z)>>4); - if (dist >= 4194304) continue; - if (cansee(sprite[i].x,sprite[i].y,sprite[i].z-(tilesizy[sprite[i].picnum]<<7),sprite[i].sectnum,sprite[j].x,sprite[j].y,sprite[j].z-(tilesizy[sprite[j].picnum]<<7),sprite[j].sectnum) == 0) - continue; - - sprite[j].picnum = EVILALGRAVE; - sprite[j].cstat = 0; - sprite[j].xvel = (krand()&255)-128; - sprite[j].yvel = (krand()&255)-128; - sprite[j].zvel = (krand()&4095)-3072; - changespritestat(j,9); - } - - wsayfollow("blowup.wav",3840L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0); - deletesprite((short)i); -} - -void processinput(short snum) -{ - long oldposx, oldposy, nexti; - long i, j, k, doubvel, xvect, yvect, goalz; - long dax, day, dax2, day2, odax, oday, odax2, oday2; - short startwall, endwall; - char *ptr; - - //SHARED KEYS: - //Movement code - if ((ssync[snum].fvel|ssync[snum].svel) != 0) - { - doubvel = (TICSPERFRAME<<((ssync[snum].bits&256)>0)); - - xvect = 0, yvect = 0; - if (ssync[snum].fvel != 0) - { - xvect += ((((long)ssync[snum].fvel)*doubvel*(long)sintable[(ang[snum]+512)&2047])>>3); - yvect += ((((long)ssync[snum].fvel)*doubvel*(long)sintable[ang[snum]&2047])>>3); - } - if (ssync[snum].svel != 0) - { - xvect += ((((long)ssync[snum].svel)*doubvel*(long)sintable[ang[snum]&2047])>>3); - yvect += ((((long)ssync[snum].svel)*doubvel*(long)sintable[(ang[snum]+1536)&2047])>>3); - } - if (flytime[snum] > lockclock) { xvect += xvect; yvect += yvect; } // DOuble flying speed - clipmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],xvect,yvect,128L,4<<8,4<<8,CLIPMASK0); - revolvedoorstat[snum] = 1; - } - else - { - revolvedoorstat[snum] = 0; - } - - sprite[playersprite[snum]].cstat &= ~1; - //Push player away from walls if clipmove doesn't work - if (pushmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],128L,4<<8,4<<8,CLIPMASK0) < 0) - changehealth(snum,-1000); //If this screws up, then instant death!!! - - // Getzrange returns the highest and lowest z's for an entire box, - // NOT just a point. This prevents you from falling off cliffs - // when you step only slightly over the cliff. - getzrange(posx[snum],posy[snum],posz[snum],cursectnum[snum],&globhiz,&globhihit,&globloz,&globlohit,128L,CLIPMASK0); - sprite[playersprite[snum]].cstat |= 1; - - if (ssync[snum].avel != 0) //ang += avel * constant - { //ENGINE calculates avel for you - doubvel = TICSPERFRAME; - if ((ssync[snum].bits&256) > 0) //Lt. shift makes turn velocity 50% faster - doubvel += (TICSPERFRAME>>1); - ang[snum] += ((((long)ssync[snum].avel)*doubvel)>>4); - ang[snum] &= 2047; - } - - if (health[snum] < 0) - { - health[snum] -= TICSPERFRAME; - if (health[snum] <= -160) - { - hvel[snum] = 0; - if (snum == myconnectindex) - fvel = 0, svel = 0, avel = 0, keystatus[3] = 1; - - deaths[snum]++; - health[snum] = 100; - numbombs[snum] = 0; - numgrabbers[snum] = 0; - nummissiles[snum] = 0; - flytime[snum] = 0; - - findrandomspot(&posx[snum],&posy[snum],&cursectnum[snum]); - posz[snum] = getflorzofslope(cursectnum[snum],posx[snum],posy[snum])-(1<<8); - horiz[snum] = 100; - ang[snum] = (krand()&2047); - - sprite[playersprite[snum]].x = posx[snum]; - sprite[playersprite[snum]].y = posy[snum]; - sprite[playersprite[snum]].z = posz[snum]+EYEHEIGHT; - sprite[playersprite[snum]].picnum = PLAYER; - sprite[playersprite[snum]].ang = ang[snum]; - sprite[playersprite[snum]].xrepeat = 64; - sprite[playersprite[snum]].yrepeat = 64; - changespritesect(playersprite[snum],cursectnum[snum]); - - drawstatusbar(snum); // Andy did this - - i = playersprite[snum]; - wsayfollow("zipguns.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,1); - for(k=0;k<16;k++) - { - spawnsprite(j,sprite[i].x,sprite[i].y,sprite[i].z+(8<<8),2,-4,0, - 32,24,24,0,0,EXPLOSION,sprite[i].ang, - (krand()&511)-256,(krand()&511)-256,(krand()&16384)-8192, - sprite[i].owner,sprite[i].sectnum,7,96,0,0); - //96=Time left for smoke to be alive - } - } - else - { - sprite[playersprite[snum]].xrepeat = max(((128+health[snum])>>1),0); - sprite[playersprite[snum]].yrepeat = max(((128+health[snum])>>1),0); - - hvel[snum] += (TICSPERFRAME<<2); - horiz[snum] = max(horiz[snum]-4,0); - posz[snum] += hvel[snum]; - if (posz[snum] > globloz-(4<<8)) - { - posz[snum] = globloz-(4<<8); - horiz[snum] = min(horiz[snum]+5,200); - hvel[snum] = 0; - } - } - } - - if (((ssync[snum].bits&8) > 0) && (horiz[snum] > 100-(200>>1))) horiz[snum] -= 4; //- - if (((ssync[snum].bits&4) > 0) && (horiz[snum] < 100+(200>>1))) horiz[snum] += 4; //+ - - goalz = globloz-EYEHEIGHT; - if (sector[cursectnum[snum]].lotag == 4) //slime sector - if ((globlohit&0xc000) != 49152) //You're not on a sprite - { - goalz = globloz-(8<<8); - if (posz[snum] >= goalz-(2<<8)) - { - clipmove(&posx[snum],&posy[snum],&posz[snum],&cursectnum[snum],-TICSPERFRAME<<14,-TICSPERFRAME<<14,128L,4<<8,4<<8,CLIPMASK0); - - if (slimesoundcnt[snum] >= 0) - { - slimesoundcnt[snum] -= TICSPERFRAME; - while (slimesoundcnt[snum] < 0) - { - slimesoundcnt[snum] += 120; - wsayfollow("slime.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - } - } - } - } - if (goalz < globhiz+(16<<8)) //ceiling&floor too close - goalz = ((globloz+globhiz)>>1); - //goalz += mousz; - if (health[snum] >= 0) - { - if ((ssync[snum].bits&1) > 0) //A (stand high) - { - if (flytime[snum] <= lockclock) - { - if (posz[snum] >= globloz-(32<<8)) - { - goalz -= (16<<8); - if (ssync[snum].bits&256) goalz -= (24<<8); - } - } - else - { - hvel[snum] -= 192; - if (ssync[snum].bits&256) hvel[snum] -= 192; - } - } - if ((ssync[snum].bits&2) > 0) //Z (stand low) - { - if (flytime[snum] <= lockclock) - { - goalz += (12<<8); - if (ssync[snum].bits&256) goalz += (12<<8); - } - else - { - hvel[snum] += 192; - if (ssync[snum].bits&256) hvel[snum] += 192; - } - } - } - - if (flytime[snum] <= lockclock) - { - if (posz[snum] < goalz) - hvel[snum] += (TICSPERFRAME<<4); - else - hvel[snum] = (((goalz-posz[snum])*TICSPERFRAME)>>5); - } - else - { - hvel[snum] -= (hvel[snum]>>2); - hvel[snum] -= ksgn(hvel[snum]); - } - - posz[snum] += hvel[snum]; - if (posz[snum] > globloz-(4<<8)) posz[snum] = globloz-(4<<8), hvel[snum] = 0; - if (posz[snum] < globhiz+(4<<8)) posz[snum] = globhiz+(4<<8), hvel[snum] = 0; - - if (dimensionmode[snum] != 3) - { - if (((ssync[snum].bits&32) > 0) && (zoom[snum] > 48)) zoom[snum] -= (zoom[snum]>>4); - if (((ssync[snum].bits&16) > 0) && (zoom[snum] < 4096)) zoom[snum] += (zoom[snum]>>4); - } - - //Update sprite representation of player - // -should be after movement, but before shooting code - setsprite(playersprite[snum],posx[snum],posy[snum],posz[snum]+EYEHEIGHT); - sprite[playersprite[snum]].ang = ang[snum]; - - if (health[snum] >= 0) - { - if ((cursectnum[snum] < 0) || (cursectnum[snum] >= numsectors)) - { //How did you get in the wrong sector? - wsayfollow("ouch.wav",4096L+(krand()&127)-64,64L,&posx[snum],&posy[snum],1); - changehealth(snum,-TICSPERFRAME); - } - else if (globhiz+(8<<8) > globloz) - { //Ceiling and floor are smooshing you! - wsayfollow("ouch.wav",4096L+(krand()&127)-64,64L,&posx[snum],&posy[snum],1); - changehealth(snum,-TICSPERFRAME); - } - } - - if ((waterfountainwall[snum] >= 0) && (health[snum] >= 0)) - if ((wall[neartagwall].lotag != 7) || ((ssync[snum].bits&1024) == 0)) - { - i = waterfountainwall[snum]; - if (wall[i].overpicnum == USEWATERFOUNTAIN) - wall[i].overpicnum = WATERFOUNTAIN; - else if (wall[i].picnum == USEWATERFOUNTAIN) - wall[i].picnum = WATERFOUNTAIN; - - waterfountainwall[snum] = -1; - } - - if ((ssync[snum].bits&1024) > 0) //Space bar - { - //Continuous triggers... - - neartag(posx[snum],posy[snum],posz[snum],cursectnum[snum],ang[snum],&neartagsector,&neartagwall,&neartagsprite,&neartaghitdist,1024L,3); - if (neartagsector == -1) - { - i = cursectnum[snum]; - if ((sector[i].lotag|sector[i].hitag) != 0) - neartagsector = i; - } - - if (wall[neartagwall].lotag == 7) //Water fountain - { - if (wall[neartagwall].overpicnum == WATERFOUNTAIN) - { - wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - wall[neartagwall].overpicnum = USEWATERFOUNTAIN; - waterfountainwall[snum] = neartagwall; - } - else if (wall[neartagwall].picnum == WATERFOUNTAIN) - { - wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - wall[neartagwall].picnum = USEWATERFOUNTAIN; - waterfountainwall[snum] = neartagwall; - } - - if (waterfountainwall[snum] >= 0) - { - waterfountaincnt[snum] -= TICSPERFRAME; - while (waterfountaincnt[snum] < 0) - { - waterfountaincnt[snum] += 120; - wsayfollow("water.wav",4096L+(krand()&127)-64,256L,&posx[snum],&posy[snum],1); - changehealth(snum,2); - } - } - } - - //1-time triggers... - if ((oflags[snum]&1024) == 0) - { - if (neartagsector >= 0) - if (sector[neartagsector].hitag == 0) - operatesector(neartagsector); - - if (neartagwall >= 0) - if (wall[neartagwall].lotag == 2) //Switch - { - activatehitag(wall[neartagwall].hitag); - - j = wall[neartagwall].overpicnum; - if (j == SWITCH1ON) //1-time switch - { - wall[neartagwall].overpicnum = GIFTBOX; - wall[neartagwall].lotag = 0; - wall[neartagwall].hitag = 0; - } - if (j == GIFTBOX) //1-time switch - { - wall[neartagwall].overpicnum = SWITCH1ON; - wall[neartagwall].lotag = 0; - wall[neartagwall].hitag = 0; - } - if (j == SWITCH2ON) wall[neartagwall].overpicnum = SWITCH2OFF; - if (j == SWITCH2OFF) wall[neartagwall].overpicnum = SWITCH2ON; - if (j == SWITCH3ON) wall[neartagwall].overpicnum = SWITCH3OFF; - if (j == SWITCH3OFF) wall[neartagwall].overpicnum = SWITCH3ON; - - i = wall[neartagwall].point2; - dax = ((wall[neartagwall].x+wall[i].x)>>1); - day = ((wall[neartagwall].y+wall[i].y)>>1); - wsayfollow("switch.wav",4096L+(krand()&255)-128,256L,&dax,&day,0); - } - - if (neartagsprite >= 0) - { - if (sprite[neartagsprite].lotag == 1) - { //if you're shoving innocent little AL around, he gets mad! - if (sprite[neartagsprite].picnum == AL) - { - sprite[neartagsprite].picnum = EVILAL; - sprite[neartagsprite].cstat |= 2; //Make him transluscent - sprite[neartagsprite].xrepeat = 38; - sprite[neartagsprite].yrepeat = 38; - changespritestat(neartagsprite,10); - } - } - if (sprite[neartagsprite].lotag == 4) - { - activatehitag(sprite[neartagsprite].hitag); - - j = sprite[neartagsprite].picnum; - if (j == SWITCH1ON) //1-time switch - { - sprite[neartagsprite].picnum = GIFTBOX; - sprite[neartagsprite].lotag = 0; - sprite[neartagsprite].hitag = 0; - } - if (j == GIFTBOX) //1-time switch - { - sprite[neartagsprite].picnum = SWITCH1ON; - sprite[neartagsprite].lotag = 0; - sprite[neartagsprite].hitag = 0; - } - if (j == SWITCH2ON) sprite[neartagsprite].picnum = SWITCH2OFF; - if (j == SWITCH2OFF) sprite[neartagsprite].picnum = SWITCH2ON; - if (j == SWITCH3ON) sprite[neartagsprite].picnum = SWITCH3OFF; - if (j == SWITCH3OFF) sprite[neartagsprite].picnum = SWITCH3ON; - - dax = sprite[neartagsprite].x; - day = sprite[neartagsprite].y; - wsayfollow("switch.wav",4096L+(krand()&255)-128,256L,&dax,&day,0); - } - } - } - } - - if ((ssync[snum].bits & 2048) > 0) { // Shoot a bullet - if ((numbombs[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 2) && (myconnectindex == snum)) - locselectedgun = 0; - if ((nummissiles[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 3) && (myconnectindex == snum)) - locselectedgun = 1; - if ((numgrabbers[snum] == 0) && (((ssync[snum].bits >> 13) & 7) == 4) && (myconnectindex == snum)) - locselectedgun = 1; - - if ((health[snum] >= 0) || ((krand() & 127) > -health[snum])) - switch((ssync[snum].bits >> 13) & 7) { - case 0: - if (lockclock > lastchaingun[snum]+8) { - lastchaingun[snum] = lockclock; - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],0); - } - break; - case 1: - if ((oflags[snum] & 2048) == 0) - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],1); - break; - case 2: - if ((oflags[snum] & 2048) == 0) - if (numbombs[snum] > 0) { - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],2); - changenumbombs(snum,-1); - } - break; - case 3: - if ((oflags[snum] & 2048) == 0) - if (nummissiles[snum] > 0) { - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],3); - changenummissiles(snum,-1); - } - break; - case 4: - if ((oflags[snum] & 2048) == 0) - if (numgrabbers[snum] > 0) { - shootgun(snum,posx[snum],posy[snum],posz[snum],ang[snum],horiz[snum],cursectnum[snum],4); - changenumgrabbers(snum,-1); - } - break; - } - } - - if ((ssync[snum].bits&4096) > (oflags[snum]&4096)) //Keypad enter - { - dimensionmode[snum]++; - if (dimensionmode[snum] > 3) dimensionmode[snum] = 1; - } - - oflags[snum] = ssync[snum].bits; -} - -void view(short snum, long *vx, long *vy, long *vz, short *vsectnum, short ang, long horiz) -{ - spritetype *sp; - long i, nx, ny, nz, hx, hy, hz, hitx, hity, hitz; - short bakcstat, hitsect, hitwall, hitsprite, daang; - - nx = (sintable[(ang+1536)&2047]>>4); - ny = (sintable[(ang+1024)&2047]>>4); - nz = (horiz-100)*128; - - sp = &sprite[snum]; - - bakcstat = sp->cstat; - sp->cstat &= (short)~0x101; - - updatesectorz(*vx,*vy,*vz,vsectnum); - hitscan(*vx,*vy,*vz,*vsectnum,nx,ny,nz,&hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1); - hx = hitx-(*vx); hy = hity-(*vy); - if (klabs(nx)+klabs(ny) > klabs(hx)+klabs(hy)) - { - *vsectnum = hitsect; - if (hitwall >= 0) - { - daang = getangle(wall[wall[hitwall].point2].x-wall[hitwall].x, - wall[wall[hitwall].point2].y-wall[hitwall].y); - - i = nx*sintable[daang]+ny*sintable[(daang+1536)&2047]; - if (klabs(nx) > klabs(ny)) hx -= mulscale28(nx,i); - else hy -= mulscale28(ny,i); - } - else if (hitsprite < 0) - { - if (klabs(nx) > klabs(ny)) hx -= (nx>>5); - else hy -= (ny>>5); - } - if (klabs(nx) > klabs(ny)) i = divscale16(hx,nx); - else i = divscale16(hy,ny); - if (i < cameradist) cameradist = i; - } - *vx = (*vx)+mulscale16(nx,cameradist); - *vy = (*vy)+mulscale16(ny,cameradist); - *vz = (*vz)+mulscale16(nz,cameradist); - - updatesectorz(*vx,*vy,*vz,vsectnum); - - sp->cstat = bakcstat; -} - -#if 0 // JBF: now in the engine -void updatesectorz(long x, long y, long z, short *sectnum) -{ - walltype *wal; - long i, j, cz, fz; - - getzsofslope(*sectnum,x,y,&cz,&fz); - if ((z >= cz) && (z <= fz)) - if (inside(x,y,*sectnum) != 0) return; - - if ((*sectnum >= 0) && (*sectnum < numsectors)) - { - wal = &wall[sector[*sectnum].wallptr]; - j = sector[*sectnum].wallnum; - do - { - i = wal->nextsector; - if (i >= 0) - { - getzsofslope(i,x,y,&cz,&fz); - if ((z >= cz) && (z <= fz)) - if (inside(x,y,(short)i) == 1) - { *sectnum = i; return; } - } - wal++; j--; - } while (j != 0); - } - - for(i=numsectors-1;i>=0;i--) - { - getzsofslope(i,x,y,&cz,&fz); - if ((z >= cz) && (z <= fz)) - if (inside(x,y,(short)i) == 1) - { *sectnum = i; return; } - } - - *sectnum = -1; -} -#endif - -void drawscreen(short snum, long dasmoothratio) -{ - long i, j, k=0, l, charsperline, tempint; - long x1, y1, x2, y2, ox1, oy1, ox2, oy2, dist, maxdist; - long cposx, cposy, cposz, choriz, czoom, tposx, tposy; - long tiltlock, *intptr, ovisibility, oparallaxvisibility; - short cang, tang, csect; - char ch, *ptr, *ptr2, *ptr3, *ptr4; - spritetype *tspr; - - smoothratio = max(min(dasmoothratio,65536),0); - - dointerpolations(); - - if ((snum == myconnectindex) && ((networkmode == 1) || (myconnectindex != connecthead))) - { - cposx = omyx+mulscale16(myx-omyx,smoothratio); - cposy = omyy+mulscale16(myy-omyy,smoothratio); - cposz = omyz+mulscale16(myz-omyz,smoothratio); - choriz = omyhoriz+mulscale16(myhoriz-omyhoriz,smoothratio); - cang = omyang+mulscale16((long)(((myang+1024-omyang)&2047)-1024),smoothratio); - } - else - { - cposx = oposx[snum]+mulscale16(posx[snum]-oposx[snum],smoothratio); - cposy = oposy[snum]+mulscale16(posy[snum]-oposy[snum],smoothratio); - cposz = oposz[snum]+mulscale16(posz[snum]-oposz[snum],smoothratio); - choriz = ohoriz[snum]+mulscale16(horiz[snum]-ohoriz[snum],smoothratio); - cang = oang[snum]+mulscale16(((ang[snum]+1024-oang[snum])&2047)-1024,smoothratio); - } - czoom = ozoom[snum]+mulscale16(zoom[snum]-ozoom[snum],smoothratio); - - setears(cposx,cposy,(long)sintable[(cang+512)&2047]<<14,(long)sintable[cang&2047]<<14); - - if (dimensionmode[myconnectindex] == 3) - { - tempint = screensize; - - if (((loc.bits&32) > (screensizeflag&32)) && (screensize > 64)) - { - ox1 = ((xdim-screensize)>>1); - ox2 = ox1+screensize-1; - oy1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - oy2 = oy1 + scale(screensize,ydim-32,xdim)-1; - screensize -= (screensize>>3); - - if (tempint > xdim) - { - screensize = xdim; - - flushperms(); - - rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - i = ((xdim-320)>>1); - while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - i = ((xdim-320)>>1)+320; - while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8; - if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4; - - drawstatusbar(screenpeek); // Andy did this - } - - x1 = ((xdim-screensize)>>1); - x2 = x1+screensize-1; - y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - y2 = y1 + scale(screensize,ydim-32,xdim)-1; - setview(x1,y1,x2,y2); - - // (ox1,oy1)⁄ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø - // ≥ (x1,y1) ≥ - // ≥ ⁄ƒƒƒƒƒø ≥ - // ≥ ≥ ≥ ≥ - // ≥ ¿ƒƒƒƒƒŸ ≥ - // ≥ (x2,y2) ≥ - // ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ(ox2,oy2) - - drawtilebackground(0L,0L,BACKGROUND,8,ox1,oy1,x1-1,oy2,0); - drawtilebackground(0L,0L,BACKGROUND,8,x2+1,oy1,ox2,oy2,0); - drawtilebackground(0L,0L,BACKGROUND,8,x1,oy1,x2,y1-1,0); - drawtilebackground(0L,0L,BACKGROUND,8,x1,y2+1,x2,oy2,0); - } - if (((loc.bits&16) > (screensizeflag&16)) && (screensize <= xdim)) - { - screensize += (screensize>>3); - if ((screensize > xdim) && (tempint == xdim)) - { - screensize = xdim+1; - x1 = 0; y1 = 0; - x2 = xdim-1; y2 = ydim-1; - } - else - { - if (screensize > xdim) screensize = xdim; - x1 = ((xdim-screensize)>>1); - x2 = x1+screensize-1; - y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - y2 = y1 + scale(screensize,ydim-32,xdim)-1; - } - setview(x1,y1,x2,y2); - } - screensizeflag = loc.bits; - } - - if (dimensionmode[snum] != 2) - { - if ((numplayers > 1) && (option[4] == 0)) - { - //Do not draw other views constantly if they're staying still - //It's a shame this trick will only work in screen-buffer mode - //At least screen-buffer mode covers all the HI hi-res modes - //if (vidoption == 2) - //{ - for(i=connecthead;i>=0;i=connectpoint2[i]) frame2draw[i] = 0; - frame2draw[snum] = 1; - - //2-1,3-1,4-2 - //5-2,6-2,7-2,8-3,9-3,10-3,11-3,12-4,13-4,14-4,15-4,16-5 - x1 = posx[snum]; y1 = posy[snum]; - for(j=(numplayers>>2)+1;j>0;j--) - { - maxdist = 0x80000000; - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (frame2draw[i] == 0) - { - x2 = posx[i]-x1; y2 = posy[i]-y1; - dist = dmulscale12(x2,x2,y2,y2); - - if (dist < 64) dist = 16384; - else if (dist > 16384) dist = 64; - else dist = 1048576 / dist; - - dist *= frameskipcnt[i]; - - //Increase frame rate if screen is moving - if ((posx[i] != oposx[i]) || (posy[i] != oposy[i]) || - (posz[i] != oposz[i]) || (ang[i] != oang[i]) || - (horiz[i] != ohoriz[i])) dist += dist; - - if (dist > maxdist) maxdist = dist, k = i; - } - - for(i=connecthead;i>=0;i=connectpoint2[i]) - frameskipcnt[i] += (frameskipcnt[i]>>3)+1; - frameskipcnt[k] = 0; - - frame2draw[k] = 1; - } - //} - //else - //{ - // for(i=connecthead;i>=0;i=connectpoint2[i]) frame2draw[i] = 1; - //} - - for(i=connecthead,j=0;i>=0;i=connectpoint2[i],j++) - if (frame2draw[i] != 0) - { - if (numplayers <= 4) - { - switch(j) - { - case 0: setview(0,0,(xdim>>1)-1,(ydim>>1)-1); break; - case 1: setview((xdim>>1),0,xdim-1,(ydim>>1)-1); break; - case 2: setview(0,(ydim>>1),(xdim>>1)-1,ydim-1); break; - case 3: setview((xdim>>1),(ydim>>1),xdim-1,ydim-1); break; - } - } - else - { - switch(j) - { - case 0: setview(0,0,(xdim>>2)-1,(ydim>>2)-1); break; - case 1: setview(xdim>>2,0,(xdim>>1)-1,(ydim>>2)-1); break; - case 2: setview(xdim>>1,0,xdim-(xdim>>2)-1,(ydim>>2)-1); break; - case 3: setview(xdim-(xdim>>2),0,xdim-1,(ydim>>2)-1); break; - case 4: setview(0,ydim>>2,(xdim>>2)-1,(ydim>>1)-1); break; - case 5: setview(xdim>>2,ydim>>2,(xdim>>1)-1,(ydim>>1)-1); break; - case 6: setview(xdim>>1,ydim>>2,xdim-(xdim>>2)-1,(ydim>>1)-1); break; - case 7: setview(xdim-(xdim>>2),ydim>>2,xdim-1,(ydim>>1)-1); break; - case 8: setview(0,ydim>>1,(xdim>>2)-1,ydim-(ydim>>2)-1); break; - case 9: setview(xdim>>2,ydim>>1,(xdim>>1)-1,ydim-(ydim>>2)-1); break; - case 10: setview(xdim>>1,ydim>>1,xdim-(xdim>>2)-1,ydim-(ydim>>2)-1); break; - case 11: setview(xdim-(xdim>>2),ydim>>1,xdim-1,ydim-(ydim>>2)-1); break; - case 12: setview(0,ydim-(ydim>>2),(xdim>>2)-1,ydim-1); break; - case 13: setview(xdim>>2,ydim-(ydim>>2),(xdim>>1)-1,ydim-1); break; - case 14: setview(xdim>>1,ydim-(ydim>>2),xdim-(xdim>>2)-1,ydim-1); break; - case 15: setview(xdim-(xdim>>2),ydim-(ydim>>2),xdim-1,ydim-1); break; - } - } - - if (i == snum) - { - sprite[playersprite[snum]].cstat |= 0x8000; - drawrooms(cposx,cposy,cposz,cang,choriz,cursectnum[i]); - sprite[playersprite[snum]].cstat &= ~0x8000; - analyzesprites(cposx,cposy); - } - else - { - sprite[playersprite[i]].cstat |= 0x8000; - drawrooms(posx[i],posy[i],posz[i],ang[i],horiz[i],cursectnum[i]); - sprite[playersprite[i]].cstat &= ~0x8000; - analyzesprites(posx[i],posy[i]); - } - drawmasks(); - if ((numgrabbers[i] > 0) || (nummissiles[i] > 0) || (numbombs[i] > 0)) - rotatesprite(160<<16,184L<<16,65536,0,GUNONBOTTOM,sector[cursectnum[i]].floorshade,0,2,windowx1,windowy1,windowx2,windowy2); - - if (lockclock < 384) - { - if (lockclock < 128) - rotatesprite(320<<15,200<<15,lockclock<<9,lockclock<<4,DEMOSIGN,(128-lockclock)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); - else if (lockclock < 256) - rotatesprite(320<<15,200<<15,65536,0,DEMOSIGN,0,0,2,windowx1,windowy1,windowx2,windowy2); - else - rotatesprite(320<<15,200<<15,(384-lockclock)<<9,lockclock<<4,DEMOSIGN,(lockclock-256)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); - } - - if (health[i] <= 0) - rotatesprite(320<<15,200<<15,(-health[i])<<11,(-health[i])<<5,NO,0,0,2,windowx1,windowy1,windowx2,windowy2); - } - } - else - { - //Init for screen rotation - if (getrendermode() == 0) { // JBF 20031220 - tiltlock = screentilt; - if ((tiltlock) || (detailmode)) - { - walock[MAXTILES-2] = 255; - if (waloff[MAXTILES-2] == 0) - allocache(&waloff[MAXTILES-2],320L*320L,&walock[MAXTILES-2]); - if ((tiltlock&1023) == 0) - setviewtotile(MAXTILES-2,200L>>detailmode,320L>>detailmode); - else - setviewtotile(MAXTILES-2,320L>>detailmode,320L>>detailmode); - if ((tiltlock&1023) == 512) - { //Block off unscreen section of 90¯ tilted screen - j = ((320-60)>>detailmode); - for(i=(60>>detailmode)-1;i>=0;i--) - { - startumost[i] = 1; startumost[i+j] = 1; - startdmost[i] = 0; startdmost[i+j] = 0; - } - } - - i = (tiltlock&511); if (i > 256) i = 512-i; - i = sintable[i+512]*8 + sintable[i]*5L; - setaspect(i>>1,yxaspect); - } - } else { - tiltlock = screentilt; - // Ken loves to interpolate - setrollangle(oscreentilt + mulscale16(((screentilt-oscreentilt+1024)&2047)-1024,smoothratio)); - } - - if ((gotpic[FLOORMIRROR>>3]&(1<<(FLOORMIRROR&7))) > 0) - { - dist = 0x7fffffff; i = 0; - for(k=floormirrorcnt-1;k>=0;k--) - { - j = klabs(wall[sector[floormirrorsector[k]].wallptr].x-cposx); - j += klabs(wall[sector[floormirrorsector[k]].wallptr].y-cposy); - if (j < dist) dist = j, i = k; - } - - //if (cposz > sector[floormirrorsector[i]].ceilingz) i = 1-i; //SOS - - j = floormirrorsector[i]; - - if (cameradist < 0) sprite[playersprite[snum]].cstat |= 0x8000; - drawrooms(cposx,cposy,(sector[j].floorz<<1)-cposz,cang,201-choriz,j); //SOS - //drawrooms(cposx,cposy,cposz,cang,choriz,j+MAXSECTORS); //SOS - sprite[playersprite[snum]].cstat &= ~0x8000; - analyzesprites(cposx,cposy); - drawmasks(); - - //Temp horizon - if (getrendermode() == 0) { - l = scale(choriz-100,windowx2-windowx1,320)+((windowy1+windowy2)>>1); - begindrawing(); //{{{ - for(y1=windowy1,y2=windowy2;y1>2,31)<<8); - ptr4 = palookup[18]; - ptr4 += (min(klabs(y2-l)>>2,31)<<8); - - j = sintable[((y2+totalclock)<<6)&2047]; - j += sintable[((y2-totalclock)<<7)&2047]; - j >>= 14; - - //ptr2 += j; - - //for(x1=windowx1;x1<=windowx2;x1++) - // { ch = ptr[x1]; ptr[x1] = ptr3[ptr2[x1]]; ptr2[x1] = ptr4[ch]; } - - ox1 = windowx1-min(j,0); - ox2 = windowx2-max(j,0); - - for(x1=windowx1;x1>3] &= ~(1<<(FLOORMIRROR&7)); - } - - if (gotpic[DAYSKY>>3]&(1<<(DAYSKY&7))) - { - gotpic[DAYSKY>>3] &= ~(1<<(DAYSKY&7)); - pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1; - } - else if (gotpic[NIGHTSKY>>3]&(1<<(NIGHTSKY&7))) - { - gotpic[NIGHTSKY>>3] &= ~(1<<(NIGHTSKY&7)); - pskyoff[0] = 0; pskyoff[1] = 0; pskyoff[2] = 0; pskyoff[3] = 0; - pskyoff[4] = 0; pskyoff[5] = 0; pskyoff[6] = 0; pskyoff[7] = 0; - pskybits = 3; - } - - - //Over the shoulder mode - csect = cursectnum[snum]; - if (cameradist >= 0) - { - cang += cameraang; - view(playersprite[snum],&cposx,&cposy,&cposz,&csect,cang,choriz); - } - - //WARNING! Assuming (MIRRORLABEL&31) = 0 and MAXMIRRORS = 64 - intptr = (long *)&gotpic[MIRRORLABEL>>3]; // CHECK! - if (intptr[0]|intptr[1]) - for(i=MAXMIRRORS-1;i>=0;i--) - if (gotpic[(i+MIRRORLABEL)>>3]&(1<<(i&7))) - { - gotpic[(i+MIRRORLABEL)>>3] &= ~(1<<(i&7)); - - //Prepare drawrooms for drawing mirror and calculate reflected - //position into tposx, tposy, and tang (tposz == cposz) - //Must call preparemirror before drawrooms and - // completemirror after drawrooms - preparemirror(cposx,cposy,cposz,cang,choriz, - mirrorwall[i],mirrorsector[i],&tposx,&tposy,&tang); - - ovisibility = visibility; - oparallaxvisibility = parallaxvisibility; - visibility <<= 1; - parallaxvisibility <<= 1; - ptr = palookup[0]; palookup[0] = palookup[17]; palookup[17] = ptr; - - drawrooms(tposx,tposy,cposz,tang,choriz,mirrorsector[i]|MAXSECTORS); - for(j=0,tspr=&tsprite[0];jcstat&48) == 0) tspr->cstat |= 4; - analyzesprites(tposx,tposy); - drawmasks(); - - ptr = palookup[0]; palookup[0] = palookup[17]; palookup[17] = ptr; - visibility = ovisibility; - parallaxvisibility = oparallaxvisibility; - - completemirror(); //Reverse screen x-wise in this function - - break; - } - - if (cameradist < 0) sprite[playersprite[snum]].cstat |= 0x8000; - drawrooms(cposx,cposy,cposz,cang,choriz,csect); - sprite[playersprite[snum]].cstat &= ~0x8000; - analyzesprites(cposx,cposy); - drawmasks(); - - //Finish for screen rotation - if (getrendermode() == 0) { // JBF 20031220 - if ((tiltlock) || (detailmode)) - { - setviewback(); - i = (tiltlock&511); if (i > 256) i = 512-i; - i = sintable[i+512]*8 + sintable[i]*5L; - if (detailmode == 0) i >>= 1; - rotatesprite(320<<15,200<<15,i,tiltlock+512,MAXTILES-2,0,0,2+4+64,windowx1,windowy1,windowx2,windowy2); - walock[MAXTILES-2] = 1; - } - } - - if (((numgrabbers[screenpeek] > 0) || (nummissiles[screenpeek] > 0) || (numbombs[screenpeek] > 0)) && (cameradist < 0)) - { - //Reset startdmost to bottom of screen - if ((windowx1 == 0) && (windowx2 == 319) && (yxaspect == 65536) && (tiltlock == 0)) - { - x1 = 160L-(tilesizx[GUNONBOTTOM]>>1); y1 = windowy2+1; - for(i=0;i>2,0,1+2,windowx1,windowy1,windowx2,windowy2); - else if (lockclock < 256) - rotatesprite(320<<15,200<<15,65536,0,DEMOSIGN,0,0,2,windowx1,windowy1,windowx2,windowy2); - else - rotatesprite(320<<15,200<<15,(384-lockclock)<<9,lockclock<<4,DEMOSIGN,(lockclock-256)>>2,0,1+2,windowx1,windowy1,windowx2,windowy2); - } - - if (health[screenpeek] <= 0) - rotatesprite(320<<15,200<<15,(-health[screenpeek])<<11,(-health[screenpeek])<<5,NO,0,0,2,windowx1,windowy1,windowx2,windowy2); - } - } - - //Only animate lava if its picnum is on screen - //gotpic is a bit array where the tile number's bit is set - //whenever it is drawn (ceilings, walls, sprites, etc.) - if ((gotpic[SLIME>>3]&(1<<(SLIME&7))) > 0) - { - gotpic[SLIME>>3] &= ~(1<<(SLIME&7)); - if (waloff[SLIME] != 0) { - movelava((char *)waloff[SLIME]); - invalidatetile(SLIME,0,1); // JBF 20031228 - } - } - - if ((show2dsector[cursectnum[snum]>>3]&(1<<(cursectnum[snum]&7))) == 0) - searchmap(cursectnum[snum]); - - if (dimensionmode[snum] != 3) - { - //Move back pivot point - i = scale(czoom,screensize,320); - if (dimensionmode[snum] == 2) - { - clearview(0L); //Clear screen to specified color - drawmapview(cposx,cposy,i,cang); - } - drawoverheadmap(cposx,cposy,i,cang); - } - - if (typemode != 0) - { - charsperline = 40; - //if (dimensionmode[snum] == 2) charsperline = 80; - - for(i=0;i<=typemessageleng;i+=charsperline) - { - for(j=0;j 0) - { - charsperline = 40; - //if (dimensionmode[snum] == 2) charsperline = 80; - - for(i=0;i<=getmessageleng;i+=charsperline) - { - for(j=0;j getmessagetimeoff) - getmessageleng = 0; - } - if ((numplayers >= 2) && (screenpeek != myconnectindex)) - { - j = 1; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (i == screenpeek) break; - j++; - } - Bsprintf(tempbuf,"(Player %ld's view)",j); - printext256((xdim>>1)-(Bstrlen(tempbuf)<<2),0,24,-1,tempbuf,0); - } - - if (syncstat != 0) printext256(68L,84L,31,0,"OUT OF SYNC!",0); - if (syncstate != 0) printext256(68L,92L,31,0,"Missed Network packet!",0); - - // //Uncomment this to test cache locks - //extern long cacnum; - //typedef struct { long *hand, leng; char *lock; } cactype; - //extern cactype cac[]; - // - // j = 0; - // for(i=0;i= 200) - // { - // Bsprintf(tempbuf,"Locked- %ld: Leng:%ld, Lock:%ld",i,cac[i].leng,*cac[i].lock); - // printext256(0L,j,31,-1,tempbuf,1); j += 6; - // } - - nextpage(); // send completed frame to display - - while (totalclock >= ototalclock+(TIMERINTSPERSECOND/MOVESPERSECOND)) - faketimerhandler(); - - if (keystatus[0x3f]) //F5 - { - keystatus[0x3f] = 0; - detailmode ^= 1; - //setrendermode(3); - } - if (keystatus[0x58]) //F12 - { - keystatus[0x58] = 0; - screencapture("captxxxx.tga",keystatus[0x2a]|keystatus[0x36]); - } - if (keystatus[0x3e]) //F4 - screen re-size - { - keystatus[0x3e] = 0; - - if (keystatus[0x2a]|keystatus[0x36]) { - setgamemode(!fullscreen, xdim, ydim, bpp); - } else { - - //cycle through all modes - j=-1; - - // work out a mask to select the mode - for (i=0; i 8) brightness = 0; - setbrightness(brightness,(char *)&palette[0],0); - } - - if (option[4] == 0) //Single player only keys - { - if (keystatus[0xd2]) //Insert - Insert player - { - keystatus[0xd2] = 0; - if (numplayers < MAXPLAYERS) - { - connectpoint2[numplayers-1] = numplayers; - connectpoint2[numplayers] = -1; - - movefifoend[numplayers] = movefifoend[0]; //HACK 01/05/2000 - - initplayersprite(numplayers); - - clearallviews(0L); //Clear screen to specified color - - numplayers++; - } - } - if (keystatus[0xd3]) //Delete - Delete player - { - keystatus[0xd3] = 0; - if (numplayers > 1) - { - numplayers--; - connectpoint2[numplayers-1] = -1; - - deletesprite(playersprite[numplayers]); - playersprite[numplayers] = -1; - - if (myconnectindex >= numplayers) myconnectindex = 0; - if (screenpeek >= numplayers) screenpeek = 0; - - if (numplayers < 2) - setup3dscreen(); - else - clearallviews(0L); //Clear screen to specified color - } - } - if (keystatus[0x46]) //Scroll Lock - { - keystatus[0x46] = 0; - - myconnectindex = connectpoint2[myconnectindex]; - if (myconnectindex < 0) myconnectindex = connecthead; - screenpeek = myconnectindex; - } - } - - restoreinterpolations(); -} - -void movethings(void) -{ - long i; - - gotlastpacketclock = totalclock; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - copybufbyte(&ffsync[i],&baksync[movefifoend[i]][i],sizeof(input)); - movefifoend[i] = ((movefifoend[i]+1)&(MOVEFIFOSIZ-1)); - } -} - -void fakedomovethings(void) -{ - input *syn; - long i, j, k, doubvel, xvect, yvect, goalz; - short bakcstat; - - syn = (input *)&baksync[fakemovefifoplc][myconnectindex]; - - omyx = myx; - omyy = myy; - omyz = myz; - omyang = myang; - omyhoriz = myhoriz; - - bakcstat = sprite[playersprite[myconnectindex]].cstat; - sprite[playersprite[myconnectindex]].cstat &= ~0x101; - - if ((syn->fvel|syn->svel) != 0) - { - doubvel = (TICSPERFRAME<<((syn->bits&256)>0)); - - xvect = 0, yvect = 0; - if (syn->fvel != 0) - { - xvect += ((((long)syn->fvel)*doubvel*(long)sintable[(myang+512)&2047])>>3); - yvect += ((((long)syn->fvel)*doubvel*(long)sintable[myang&2047])>>3); - } - if (syn->svel != 0) - { - xvect += ((((long)syn->svel)*doubvel*(long)sintable[myang&2047])>>3); - yvect += ((((long)syn->svel)*doubvel*(long)sintable[(myang+1536)&2047])>>3); - } - if (flytime[myconnectindex] > lockclock) { xvect += xvect; yvect += yvect; } // DOuble flying speed - clipmove(&myx,&myy,&myz,&mycursectnum,xvect,yvect,128L,4<<8,4<<8,CLIPMASK0); - } - - pushmove(&myx,&myy,&myz,&mycursectnum,128L,4<<8,4<<8,CLIPMASK0); - getzrange(myx,myy,myz,mycursectnum,&globhiz,&globhihit,&globloz,&globlohit,128L,CLIPMASK0); - - if (syn->avel != 0) //ang += avel * constant - { //ENGINE calculates avel for you - doubvel = TICSPERFRAME; - if ((syn->bits&256) > 0) //Lt. shift makes turn velocity 50% faster - doubvel += (TICSPERFRAME>>1); - myang += ((((long)syn->avel)*doubvel)>>4); - myang &= 2047; - } - - if (((syn->bits&8) > 0) && (myhoriz > 100-(200>>1))) myhoriz -= 4; //- - if (((syn->bits&4) > 0) && (myhoriz < 100+(200>>1))) myhoriz += 4; //+ - - goalz = globloz-EYEHEIGHT; - if (sector[mycursectnum].lotag == 4) //slime sector - if ((globlohit&0xc000) != 49152) //You're not on a sprite - { - goalz = globloz-(8<<8); - if (myz >= goalz-(2<<8)) - clipmove(&myx,&myy,&myz,&mycursectnum,-TICSPERFRAME<<14,-TICSPERFRAME<<14,128L,4<<8,4<<8,CLIPMASK0); - } - if (goalz < globhiz+(16<<8)) //ceiling&floor too close - goalz = ((globloz+globhiz)>>1); - - if (health[myconnectindex] >= 0) - { - if ((syn->bits&1) > 0) //A (stand high) - { - if (flytime[myconnectindex] <= lockclock) - { - if (myz >= globloz-(32<<8)) - { - goalz -= (16<<8); - if (syn->bits&256) goalz -= (24<<8); - } - } - else - { - myzvel -= 192; - if (syn->bits&256) myzvel -= 192; - } - } - if ((syn->bits&2) > 0) //Z (stand low) - { - if (flytime[myconnectindex] <= lockclock) - { - goalz += (12<<8); - if (syn->bits&256) goalz += (12<<8); - } - else - { - myzvel += 192; - if (syn->bits&256) myzvel += 192; - } - } - } - - if (flytime[myconnectindex] <= lockclock) - { - if (myz < goalz) - myzvel += (TICSPERFRAME<<4); - else - myzvel = (((goalz-myz)*TICSPERFRAME)>>5); - } - else - { - myzvel -= (myzvel>>2); - myzvel -= ksgn(myzvel); - } - - myz += myzvel; - if (myz > globloz-(4<<8)) myz = globloz-(4<<8), myzvel = 0; - if (myz < globhiz+(4<<8)) myz = globhiz+(4<<8), myzvel = 0; - - sprite[playersprite[myconnectindex]].cstat = bakcstat; - - myxbak[fakemovefifoplc] = myx; - myybak[fakemovefifoplc] = myy; - myzbak[fakemovefifoplc] = myz; - myangbak[fakemovefifoplc] = myang; - myhorizbak[fakemovefifoplc] = myhoriz; - fakemovefifoplc = (fakemovefifoplc+1)&(MOVEFIFOSIZ-1); -} - -//Prediction correction -void fakedomovethingscorrect(void) -{ - long i; - - if ((networkmode == 0) && (myconnectindex == connecthead)) return; - - i = ((movefifoplc-1)&(MOVEFIFOSIZ-1)); - - if ((posx[myconnectindex] == myxbak[i]) && - (posy[myconnectindex] == myybak[i]) && - (posz[myconnectindex] == myzbak[i]) && - (horiz[myconnectindex] == myhorizbak[i]) && - (ang[myconnectindex] == myangbak[i])) - return; - - //Re-start fakedomovethings back to place of error - myx = omyx = posx[myconnectindex]; - myy = omyy = posy[myconnectindex]; - myz = omyz = posz[myconnectindex]; myzvel = hvel[myconnectindex]; - myang = omyang = ang[myconnectindex]; - mycursectnum = mycursectnum; - myhoriz = omyhoriz = horiz[myconnectindex]; - - fakemovefifoplc = movefifoplc; - while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings(); -} - -void domovethings(void) -{ - short i, j, startwall, endwall; - spritetype *spr; - walltype *wal; - point3d *ospr; - - nummoves++; - - for(i=connecthead;i>=0;i=connectpoint2[i]) - copybufbyte(&baksync[movefifoplc][i],&ssync[i],sizeof(input)); - movefifoplc = ((movefifoplc+1)&(MOVEFIFOSIZ-1)); - - if (option[4] != 0) - { - syncval[syncvalhead] = (char)(randomseed&255); - syncvalhead = ((syncvalhead+1)&(MOVEFIFOSIZ-1)); - } - - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - oposx[i] = posx[i]; - oposy[i] = posy[i]; - oposz[i] = posz[i]; - ohoriz[i] = horiz[i]; - ozoom[i] = zoom[i]; - oang[i] = ang[i]; - } - - for(i=NUMSTATS-1;i>=0;i--) - if (statrate[i] >= 0) - for(j=headspritestat[i];j>=0;j=nextspritestat[j]) - if (((nummoves-j)&statrate[i]) == 0) - copybuf(&sprite[j].x,&osprite[j].x,3); - - for(i=connecthead;i>=0;i=connectpoint2[i]) - ocursectnum[i] = cursectnum[i]; - - updateinterpolations(); - - if ((numplayers <= 2) && (recstat == 1)) - { - j = 0; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - copybufbyte(&ssync[i],&recsync[reccnt][j],sizeof(input)); - j++; - } - reccnt++; if (reccnt > 16383) reccnt = 16383; - } - - lockclock += TICSPERFRAME; - drawstatusflytime(screenpeek); // Andy did this - - if (cameradist >= 0) - { - cameradist = min(cameradist+((totalclock-cameraclock)<<10),65536); - if (keystatus[0x52]) //0 - cameraang -= ((totalclock-cameraclock)<<(2+(keystatus[0x2a]|keystatus[0x36]))); - if (keystatus[0x53]) //. - cameraang += ((totalclock-cameraclock)<<(2+(keystatus[0x2a]|keystatus[0x36]))); - cameraclock = totalclock; - } - - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - processinput(i); //Move player - - checktouchsprite(i,cursectnum[i]); //Pick up coins - startwall = sector[cursectnum[i]].wallptr; - endwall = startwall + sector[cursectnum[i]].wallnum; - for(j=startwall,wal=&wall[j];jnextsector >= 0) checktouchsprite(i,wal->nextsector); - } - - doanimations(); - tagcode(); //Door code, moving sector code, other stuff - statuslistcode(); //Monster / bullet code / explosions - - fakedomovethingscorrect(); - - checkmasterslaveswitch(); -} - -void getinput(void) -{ - char ch, keystate, *ptr; - long i, j, k; - long mousx, mousy, bstatus; - - if (typemode == 0) //if normal game keys active - { - if (keystatus[keys[15]]) - { - keystatus[keys[15]] = 0; - - screenpeek = connectpoint2[screenpeek]; - if (screenpeek < 0) screenpeek = connecthead; - drawstatusbar(screenpeek); // Andy did this - } - - for(i=7;i>=0;i--) - if (keystatus[i+2]) - { keystatus[i+2] = 0; locselectedgun = i; break; } - } - - - //KEYTIMERSTUFF - if (!keystatus[keys[5]]) - { - if (keystatus[keys[2]]) avel = max(avel-16*TICSPERFRAME,-128); - if (keystatus[keys[3]]) avel = min(avel+16*TICSPERFRAME,127); - } - else - { - if (keystatus[keys[2]]) svel = min(svel+8*TICSPERFRAME,127); - if (keystatus[keys[3]]) svel = max(svel-8*TICSPERFRAME,-128); - } - if (keystatus[keys[0]]) fvel = min(fvel+8*TICSPERFRAME,127); - if (keystatus[keys[1]]) fvel = max(fvel-8*TICSPERFRAME,-128); - if (keystatus[keys[12]]) svel = min(svel+8*TICSPERFRAME,127); - if (keystatus[keys[13]]) svel = max(svel-8*TICSPERFRAME,-128); - - if (avel < 0) avel = min(avel+12*TICSPERFRAME,0); - if (avel > 0) avel = max(avel-12*TICSPERFRAME,0); - if (svel < 0) svel = min(svel+2*TICSPERFRAME,0); - if (svel > 0) svel = max(svel-2*TICSPERFRAME,0); - if (fvel < 0) fvel = min(fvel+2*TICSPERFRAME,0); - if (fvel > 0) fvel = max(fvel-2*TICSPERFRAME,0); - - if ((option[4] == 0) && (numplayers >= 2)) - { - if (!keystatus[0x4f]) - { - if (keystatus[0x4b]) avel2 = max(avel2-16*TICSPERFRAME,-128); - if (keystatus[0x4d]) avel2 = min(avel2+16*TICSPERFRAME,127); - } - else - { - if (keystatus[0x4b]) svel2 = min(svel2+8*TICSPERFRAME,127); - if (keystatus[0x4d]) svel2 = max(svel2-8*TICSPERFRAME,-128); - } - if (keystatus[0x48]) fvel2 = min(fvel2+8*TICSPERFRAME,127); - if (keystatus[0x4c]) fvel2 = max(fvel2-8*TICSPERFRAME,-128); - - if (avel2 < 0) avel2 = min(avel2+12*TICSPERFRAME,0); - if (avel2 > 0) avel2 = max(avel2-12*TICSPERFRAME,0); - if (svel2 < 0) svel2 = min(svel2+2*TICSPERFRAME,0); - if (svel2 > 0) svel2 = max(svel2-2*TICSPERFRAME,0); - if (fvel2 < 0) fvel2 = min(fvel2+2*TICSPERFRAME,0); - if (fvel2 > 0) fvel2 = max(fvel2-2*TICSPERFRAME,0); - } - - oscreentilt = screentilt; - if (keystatus[0x1a]) screentilt += ((4*TICSPERFRAME)<<(keystatus[0x2a]|keystatus[0x36])); - if (keystatus[0x1b]) screentilt -= ((4*TICSPERFRAME)<<(keystatus[0x2a]|keystatus[0x36])); - - i = (TICSPERFRAME<<1); - while ((screentilt != 0) && (i > 0)) - { screentilt = ((screentilt+ksgn(screentilt-1024))&2047); i--; } - if (keystatus[0x28]) screentilt = 1536; - - - loc.fvel = min(max(fvel,-128+8),127-8); - loc.svel = min(max(svel,-128+8),127-8); - loc.avel = min(max(avel,-128+16),127-16); - - getmousevalues(&mousx,&mousy,&bstatus); - loc.avel = min(max(loc.avel+(mousx<<3),-128),127); - loc.fvel = min(max(loc.fvel-(mousy<<3),-128),127); - - loc.bits = (locselectedgun<<13); - if (typemode == 0) //if normal game keys active - { - loc.bits |= (keystatus[0x32]<<9); //M (be master) - loc.bits |= ((keystatus[keys[14]]==1)<<12); //Map mode - } - loc.bits |= keystatus[keys[8]]; //Stand high - loc.bits |= (keystatus[keys[9]]<<1); //Stand low - loc.bits |= (keystatus[keys[16]]<<4); //Zoom in - loc.bits |= (keystatus[keys[17]]<<5); //Zoom out - loc.bits |= (keystatus[keys[4]]<<8); //Run - loc.bits |= (keystatus[keys[10]]<<2); //Look up - loc.bits |= (keystatus[keys[11]]<<3); //Look down - loc.bits |= ((keystatus[keys[7]]==1)<<10); //Space - loc.bits |= ((keystatus[keys[6]]==1)<<11); //Shoot - loc.bits |= (((bstatus&6)>(oldmousebstatus&6))<<10); //Space - loc.bits |= (((bstatus&1)>(oldmousebstatus&1))<<11); //Shoot - - oldmousebstatus = bstatus; - if (((loc.bits&2048) > 0) && (locselectedgun == 0)) - oldmousebstatus &= ~1; //Allow continous fire with mouse for chain gun - - //PRIVATE KEYS: - /* if (keystatus[0xb7]) //Printscreen - { - keystatus[0xb7] = 0; - printscreeninterrupt(); - } - */ - if (keystatus[0x2f]) //V - { - keystatus[0x2f] = 0; - if (cameradist < 0) cameradist = 0; else cameradist = -1; - cameraang = 0; - } - - if (typemode == 0) //if normal game keys active - { - if (keystatus[0x19]) //P - { - keystatus[0x19] = 0; - parallaxtype++; - if (parallaxtype > 2) parallaxtype = 0; - } - if (keystatus[0x38]|keystatus[0xb8]) //ALT - { - if (keystatus[0x4a]) // Keypad - - visibility = min(visibility+(visibility>>3),16384); - if (keystatus[0x4e]) // Keypad + - visibility = max(visibility-(visibility>>3),128); - } - - if (keystatus[keys[18]]) //Typing mode - { - keystatus[keys[18]] = 0; - typemode = 1; - bflushchars(); - keyfifoplc = keyfifoend; //Reset keyboard fifo - } - } - else - { - while ((ch = bgetchar())) - { - if (ch == 8) //Backspace - { - if (typemessageleng == 0) { typemode = 0; break; } - typemessageleng--; - } - else if (ch == 9) // tab - { - keystatus[0xf] = 0; - typemode = 0; - break; - } - else if (ch == 13) //Either ENTER - { - keystatus[0x1c] = 0; keystatus[0x9c] = 0; - if (typemessageleng > 0) - { - packbuf[0] = 2; //Sending text is message type 4 - for(j=typemessageleng-1;j>=0;j--) - packbuf[j+1] = typemessage[j]; - - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (i != myconnectindex) - sendpacket(i,packbuf,typemessageleng+1); - - typemessageleng = 0; - } - typemode = 0; - break; - } - else if ((typemessageleng < 159) && (ch >= 32) && (ch < 128)) - { - typemessage[typemessageleng++] = ch; - } - } - } -} - -void initplayersprite(short snum) -{ - long i; - - if (playersprite[snum] >= 0) return; - - spawnsprite(playersprite[snum],posx[snum],posy[snum],posz[snum]+EYEHEIGHT, - 1+256,0,snum,32,64,64,0,0,PLAYER,ang[snum],0,0,0,snum+4096, - cursectnum[snum],8,0,0,0); - - switch(snum) - { - case 1: for(i=0;i<32;i++) tempbuf[i+192] = i+128; break; //green->red - case 2: for(i=0;i<32;i++) tempbuf[i+192] = i+32; break; //green->blue - case 3: for(i=0;i<32;i++) tempbuf[i+192] = i+224; break; //green->pink - case 4: for(i=0;i<32;i++) tempbuf[i+192] = i+64; break; //green->brown - case 5: for(i=0;i<32;i++) tempbuf[i+192] = i+96; break; - case 6: for(i=0;i<32;i++) tempbuf[i+192] = i+160; break; - case 7: for(i=0;i<32;i++) tempbuf[i+192] = i+192; break; - default: for(i=0;i<256;i++) tempbuf[i] = i; break; - } - makepalookup(snum,tempbuf,0,0,0,1); -} - -void playback(void) -{ - long i, j, k; - - ready2send = 0; - recstat = 0; i = reccnt; - while (!keystatus[1]) - { - if (handleevents()) { - if (quitevent) { - keystatus[1] = 1; - quitevent = 0; - } - } - - refreshaudio(); - - while (totalclock >= lockclock+TICSPERFRAME) - { - sampletimer(); - if (i >= reccnt) - { - prepareboard(boardfilename); - for(i=connecthead;i>=0;i=connectpoint2[i]) - initplayersprite((short)i); - totalclock = 0; - i = 0; - } - - k = 0; - for(j=connecthead;j>=0;j=connectpoint2[j]) - { - copybufbyte(&recsync[i][k],&ffsync[j],sizeof(input)); - k++; - } - movethings(); domovethings(); - i++; - } - drawscreen(screenpeek,(totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND))); - - if (keystatus[keys[15]]) - { - keystatus[keys[15]] = 0; - screenpeek = connectpoint2[screenpeek]; - if (screenpeek < 0) screenpeek = connecthead; - drawstatusbar(screenpeek); // Andy did this - } - if (keystatus[keys[14]]) - { - keystatus[keys[14]] = 0; - dimensionmode[screenpeek]++; - if (dimensionmode[screenpeek] > 3) dimensionmode[screenpeek] = 1; - } - } - - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - exit(0); -} - -void setup3dscreen(void) -{ - long i, dax, day, dax2, day2; - - i = setgamemode(fullscreen,xdimgame,ydimgame,bppgame); - if (i < 0) - { - printf("Error setting video mode.\n"); - sendlogoff(); - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - exit(0); - } - - //Make that ugly pink into black in case it ever shows up! - i = 0L; - setpalette(255,1,(char *)&i); - //outp(0x3c8,255); outp(0x3c9,0); outp(0x3c9,0); outp(0x3c9,0); - - screensize = xdim; - if (screensize > xdim) - { - dax = 0; day = 0; - dax2 = xdim-1; day2 = ydim-1; - } - else - { - dax = ((xdim-screensize)>>1); - dax2 = dax+screensize-1; - day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1); - day2 = day + scale(screensize,ydim-32,xdim)-1; - setview(dax,day,dax2,day2); - } - - flushperms(); - - if (screensize < xdim) - drawtilebackground(0L,0L,BACKGROUND,8,0L,0L,xdim-1L,ydim-1L,0); //Draw background - - if (screensize <= xdim) - { - rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - i = ((xdim-320)>>1); - while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L); - i = ((xdim-320)>>1)+320; - while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8; - if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4; - - drawstatusbar(screenpeek); // Andy did this - } -} - -void findrandomspot(long *x, long *y, short *sectnum) -{ - short startwall, endwall, s, dasector; - long dax, day, daz, minx, maxx, miny, maxy, cnt; - - for(cnt=256;cnt>=0;cnt--) - { - do - { - dasector = mulscale16(krand(),numsectors); - } while ((sector[dasector].ceilingz+(8<<8) >= sector[dasector].floorz) || ((sector[dasector].lotag|sector[dasector].hitag) != 0) || ((sector[dasector].floorstat&1) != 0)); - - startwall = sector[dasector].wallptr; - endwall = startwall+sector[dasector].wallnum; - if (endwall <= startwall) continue; - - dax = 0L; - day = 0L; - minx = 0x7fffffff; maxx = 0x80000000; - miny = 0x7fffffff; maxy = 0x80000000; - - for(s=startwall;s maxx) maxx = wall[s].x; - if (wall[s].y < miny) miny = wall[s].y; - if (wall[s].y > maxy) maxy = wall[s].y; - } - - if ((maxx-minx <= 256) || (maxy-miny <= 256)) continue; - - dax /= (endwall-startwall); - day /= (endwall-startwall); - - if (inside(dax,day,dasector) == 0) continue; - - daz = sector[dasector].floorz-(32<<8); - if (pushmove(&dax,&day,&daz,&dasector,128L,4<<8,4<<8,CLIPMASK0) < 0) continue; - - *x = dax; *y = day; *sectnum = dasector; - return; - } -} - -void warp(long *x, long *y, long *z, short *daang, short *dasector) -{ - short startwall, endwall, s; - long i, j, dax, day, ox, oy; - - ox = *x; oy = *y; - - for(i=0;i= warpsectorcnt) i = 0; - } while (sector[warpsectorlist[i]].hitag != j); - *dasector = warpsectorlist[i]; - break; - } - - //Find center of sector - startwall = sector[*dasector].wallptr; - endwall = startwall+sector[*dasector].wallnum; - dax = 0L, day = 0L; - for(s=startwall;s= 0) - i = s; - } - *x = dax / (endwall-startwall); - *y = day / (endwall-startwall); - *z = sector[*dasector].floorz-(32<<8); - updatesector(*x,*y,dasector); - dax = ((wall[i].x+wall[wall[i].point2].x)>>1); - day = ((wall[i].y+wall[wall[i].point2].y)>>1); - *daang = getangle(dax-*x,day-*y); - - wsayfollow("warp.wav",3072L+(krand()&127)-64,192L,&ox,&oy,0); - wsayfollow("warp.wav",4096L+(krand()&127)-64,256L,x,y,0); -} - -void warpsprite(short spritenum) -{ - short dasectnum; - - dasectnum = sprite[spritenum].sectnum; - warp(&sprite[spritenum].x,&sprite[spritenum].y,&sprite[spritenum].z, - &sprite[spritenum].ang,&dasectnum); - - copybuf(&sprite[spritenum].x,&osprite[spritenum].x,3); - changespritesect(spritenum,dasectnum); - - show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7)); - if (show2dsector[dasectnum>>3]&(1<<(dasectnum&7))) - show2dsprite[spritenum>>3] |= (1<<(spritenum&7)); -} - -void initlava(void) -{ - long x, y, z, r; - - for(z=0;z<32;z++) lavaradcnt[z] = 0; - for(x=-16;x<=16;x++) - for(y=-16;y<=16;y++) - { - r = ksqrt(x*x + y*y); - lavaradx[r][lavaradcnt[r]] = x; - lavarady[r][lavaradcnt[r]] = y; - lavaradcnt[r]++; - } - - for(z=0;z<16;z++) - lavadropsizlookup[z] = 8 / (ksqrt(z)+1); - - for(z=0;z>4)&7)-4)+12; - - lavanumdrops = 0; - lavanumframes = 0; -} - -#if defined(__WATCOMC__) && !defined(NOASM) -#pragma aux addlava =\ - "mov al, byte ptr [ebx-133]",\ - "mov dl, byte ptr [ebx-1]",\ - "add al, byte ptr [ebx-132]",\ - "add dl, byte ptr [ebx+131]",\ - "add al, byte ptr [ebx-131]",\ - "add dl, byte ptr [ebx+132]",\ - "add al, byte ptr [ebx+1]",\ - "add al, dl",\ - parm [ebx]\ - modify exact [eax edx] -long addlava(long); -#elif defined(_MSC_VER) && !defined(NOASM) -inline long addlava(long b) -{ - _asm { - mov ebx, b - mov al, byte ptr [ebx-133] - mov dl, byte ptr [ebx-1] - add al, byte ptr [ebx-132] - add dl, byte ptr [ebx+131] - add al, byte ptr [ebx-131] - add dl, byte ptr [ebx+132] - add al, byte ptr [ebx+1] - add al, dl - } - } -#elif defined(__GNUC__) && defined(__i386__) && !defined(NOASM) -inline long addlava(long b) -{ - long r; - __asm__ __volatile__ ( - "movb -133(%%ebx), %%al\n\t" - "movb -1(%%ebx), %%dl\n\t" - "addb -132(%%ebx), %%al\n\t" - "addb 131(%%ebx), %%dl\n\t" - "addb -131(%%ebx), %%al\n\t" - "addb 132(%%ebx), %%dl\n\t" - "addb 1(%%ebx), %%al\n\t" - "addb %%dl, %%al" - : "=a" (r) : "b" (b) - : "dx" - ); - return r; -} -#else -inline long addlava(long bx) -{ - char *b = (char *)bx; - return b[-133] + b[-132] + b[-131] + b[1] + b[-1] + b[131] + b[132]; -} -#endif - -void movelava(char *dapic) -{ - long i, j, x, y, z, zz, dalavadropsiz, dadropsizlookup; - long dalavax, dalavay, *ptr, *ptr2; - - for(z=min(LAVAMAXDROPS-lavanumdrops-1,3);z>=0;z--) - { - lavadropx[lavanumdrops] = (Brand()&(LAVASIZ-1)); - lavadropy[lavanumdrops] = (Brand()&(LAVASIZ-1)); - lavadropsiz[lavanumdrops] = 1; - lavanumdrops++; - } - - for(z=lavanumdrops-1;z>=0;z--) - { - dadropsizlookup = lavadropsizlookup[lavadropsiz[z]]*(((z&1)<<1)-1); - dalavadropsiz = lavadropsiz[z]; - dalavax = lavadropx[z]; dalavay = lavadropy[z]; - for(zz=lavaradcnt[lavadropsiz[z]]-1;zz>=0;zz--) - { - i = (((lavaradx[dalavadropsiz][zz]+dalavax)&(LAVASIZ-1))< 10) - { - lavanumdrops--; - lavadropx[z] = lavadropx[lavanumdrops]; - lavadropy[z] = lavadropy[lavanumdrops]; - lavadropsiz[z] = lavadropsiz[lavanumdrops]; - } - } - - //Back up dapic with 1 pixel extra on each boundary - //(to prevent anding for wrap-around) - ptr = (long *)dapic; - ptr2 = (long *)((LAVASIZ+4)+1+((long)lavabakpic)); - for(x=0;x>2);y>0;y--) *ptr2++ = ((*ptr++)&0x1f1f1f1f); - ptr2++; - } - for(y=0;y>3)+ - ((addlava(y+1)&0xf8)<<5)+ - ((addlava(y+2)&0xf8)<<13)+ - ((addlava(y+3)&0xf8)<<21)+ - 0xc2c2c2c2; - } - } - - lavanumframes++; -} - -void doanimations(void) -{ - long i, j; - - for(i=animatecnt-1;i>=0;i--) - { - j = *animateptr[i]; - - if (j < animategoal[i]) - j = min(j+animatevel[i]*TICSPERFRAME,animategoal[i]); - else - j = max(j-animatevel[i]*TICSPERFRAME,animategoal[i]); - animatevel[i] += animateacc[i]; - - *animateptr[i] = j; - - if (j == animategoal[i]) - { - animatecnt--; - if (i != animatecnt) - { - stopinterpolation(animateptr[i]); - animateptr[i] = animateptr[animatecnt]; - animategoal[i] = animategoal[animatecnt]; - animatevel[i] = animatevel[animatecnt]; - animateacc[i] = animateacc[animatecnt]; - } - } - } -} - -long getanimationgoal(long animptr) -{ - long i; - - for(i=animatecnt-1;i>=0;i--) - if ((long *)animptr == animateptr[i]) return(i); - return(-1); -} - -long setanimation(long *animptr, long thegoal, long thevel, long theacc) -{ - long i, j; - - if (animatecnt >= MAXANIMATES) return(-1); - - j = animatecnt; - for(i=animatecnt-1;i>=0;i--) - if (animptr == animateptr[i]) - { j = i; break; } - - setinterpolation(animptr); - - animateptr[j] = animptr; - animategoal[j] = thegoal; - animatevel[j] = thevel; - animateacc[j] = theacc; - if (j == animatecnt) animatecnt++; - return(j); -} - -void checkmasterslaveswitch(void) -{ - long i, j; - - if (option[4] == 0) return; - - j = 0; - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (ssync[i].bits&512) j++; - if (j != 1) return; - - i = connecthead; - for(j=connectpoint2[i];j>=0;j=connectpoint2[j]) - { - if (ssync[j].bits&512) - { - connectpoint2[i] = connectpoint2[j]; - connectpoint2[j] = connecthead; - connecthead = (short)j; - - oloc.fvel = loc.fvel+1; - oloc.svel = loc.svel+1; - oloc.avel = loc.avel+1; - oloc.bits = loc.bits+1; - for(i=0;i=0;i=connectpoint2[i]) - { - if (myconnectindex == i) break; - j++; - } - if (j == 1) - Bstrcpy(getmessage,"Player 1 (Master)"); - else - Bsprintf(getmessage,"Player %ld (Slave)",j); - getmessageleng = Bstrlen(getmessage); - getmessagetimeoff = totalclock+120; - - return; - } - i = j; - } -} - - -long testneighborsectors(short sect1, short sect2) -{ - short i, startwall, num1, num2; - - num1 = sector[sect1].wallnum; - num2 = sector[sect2].wallnum; - if (num1 < num2) //Traverse walls of sector with fewest walls (for speed) - { - startwall = sector[sect1].wallptr; - for(i=num1-1;i>=0;i--) - if (wall[i+startwall].nextsector == sect2) - return(1); - } - else - { - startwall = sector[sect2].wallptr; - for(i=num2-1;i>=0;i--) - if (wall[i+startwall].nextsector == sect1) - return(1); - } - return(0); -} - -long loadgame(void) -{ - long i; - long fil; - - if ((fil = kopen4load("save0000.gam",0)) == -1) return(-1); - - kdfread(&numplayers,4,1,fil); - kdfread(&myconnectindex,4,1,fil); - kdfread(&connecthead,4,1,fil); - kdfread(connectpoint2,4,MAXPLAYERS,fil); - - //Make sure palookups get set, sprites will get overwritten later - for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); - - kdfread(posx,4,MAXPLAYERS,fil); - kdfread(posy,4,MAXPLAYERS,fil); - kdfread(posz,4,MAXPLAYERS,fil); - kdfread(horiz,4,MAXPLAYERS,fil); - kdfread(zoom,4,MAXPLAYERS,fil); - kdfread(hvel,4,MAXPLAYERS,fil); - kdfread(ang,2,MAXPLAYERS,fil); - kdfread(cursectnum,2,MAXPLAYERS,fil); - kdfread(ocursectnum,2,MAXPLAYERS,fil); - kdfread(playersprite,2,MAXPLAYERS,fil); - kdfread(deaths,2,MAXPLAYERS,fil); - kdfread(lastchaingun,4,MAXPLAYERS,fil); - kdfread(health,4,MAXPLAYERS,fil); - kdfread(numgrabbers,2,MAXPLAYERS,fil); - kdfread(nummissiles,2,MAXPLAYERS,fil); - kdfread(numbombs,2,MAXPLAYERS,fil); - kdfread(flytime,4,MAXPLAYERS,fil); - kdfread(oflags,2,MAXPLAYERS,fil); - kdfread(dimensionmode,1,MAXPLAYERS,fil); - kdfread(revolvedoorstat,1,MAXPLAYERS,fil); - kdfread(revolvedoorang,2,MAXPLAYERS,fil); - kdfread(revolvedoorrotang,2,MAXPLAYERS,fil); - kdfread(revolvedoorx,4,MAXPLAYERS,fil); - kdfread(revolvedoory,4,MAXPLAYERS,fil); - - kdfread(&numsectors,2,1,fil); - kdfread(sector,sizeof(sectortype),numsectors,fil); - kdfread(&numwalls,2,1,fil); - kdfread(wall,sizeof(walltype),numwalls,fil); - //Store all sprites (even holes) to preserve indeces - kdfread(sprite,sizeof(spritetype),MAXSPRITES,fil); - kdfread(headspritesect,2,MAXSECTORS+1,fil); - kdfread(prevspritesect,2,MAXSPRITES,fil); - kdfread(nextspritesect,2,MAXSPRITES,fil); - kdfread(headspritestat,2,MAXSTATUS+1,fil); - kdfread(prevspritestat,2,MAXSPRITES,fil); - kdfread(nextspritestat,2,MAXSPRITES,fil); - - kdfread(&fvel,4,1,fil); - kdfread(&svel,4,1,fil); - kdfread(&avel,4,1,fil); - - kdfread(&locselectedgun,4,1,fil); - kdfread(&loc.fvel,1,1,fil); - kdfread(&oloc.fvel,1,1,fil); - kdfread(&loc.svel,1,1,fil); - kdfread(&oloc.svel,1,1,fil); - kdfread(&loc.avel,1,1,fil); - kdfread(&oloc.avel,1,1,fil); - kdfread(&loc.bits,2,1,fil); - kdfread(&oloc.bits,2,1,fil); - - kdfread(&locselectedgun2,4,1,fil); - kdfread(&loc2.fvel,sizeof(input),1,fil); - - kdfread(ssync,sizeof(input),MAXPLAYERS,fil); - kdfread(osync,sizeof(input),MAXPLAYERS,fil); - - kdfread(boardfilename,1,80,fil); - kdfread(&screenpeek,2,1,fil); - kdfread(&oldmousebstatus,2,1,fil); - kdfread(&brightness,2,1,fil); - kdfread(&neartagsector,2,1,fil); - kdfread(&neartagwall,2,1,fil); - kdfread(&neartagsprite,2,1,fil); - kdfread(&lockclock,4,1,fil); - kdfread(&neartagdist,4,1,fil); - kdfread(&neartaghitdist,4,1,fil); - - kdfread(turnspritelist,2,16,fil); - kdfread(&turnspritecnt,2,1,fil); - kdfread(warpsectorlist,2,16,fil); - kdfread(&warpsectorcnt,2,1,fil); - kdfread(xpanningsectorlist,2,16,fil); - kdfread(&xpanningsectorcnt,2,1,fil); - kdfread(ypanningwalllist,2,64,fil); - kdfread(&ypanningwallcnt,2,1,fil); - kdfread(floorpanninglist,2,64,fil); - kdfread(&floorpanningcnt,2,1,fil); - kdfread(dragsectorlist,2,16,fil); - kdfread(dragxdir,2,16,fil); - kdfread(dragydir,2,16,fil); - kdfread(&dragsectorcnt,2,1,fil); - kdfread(dragx1,4,16,fil); - kdfread(dragy1,4,16,fil); - kdfread(dragx2,4,16,fil); - kdfread(dragy2,4,16,fil); - kdfread(dragfloorz,4,16,fil); - kdfread(&swingcnt,2,1,fil); - kdfread(swingwall,2,32*5,fil); - kdfread(swingsector,2,32,fil); - kdfread(swingangopen,2,32,fil); - kdfread(swingangclosed,2,32,fil); - kdfread(swingangopendir,2,32,fil); - kdfread(swingang,2,32,fil); - kdfread(swinganginc,2,32,fil); - kdfread(swingx,4,32*8,fil); - kdfread(swingy,4,32*8,fil); - kdfread(revolvesector,2,4,fil); - kdfread(revolveang,2,4,fil); - kdfread(&revolvecnt,2,1,fil); - kdfread(revolvex,4,4*16,fil); - kdfread(revolvey,4,4*16,fil); - kdfread(revolvepivotx,4,4,fil); - kdfread(revolvepivoty,4,4,fil); - kdfread(subwaytracksector,2,4*128,fil); - kdfread(subwaynumsectors,2,4,fil); - kdfread(&subwaytrackcnt,2,1,fil); - kdfread(subwaystop,4,4*8,fil); - kdfread(subwaystopcnt,4,4,fil); - kdfread(subwaytrackx1,4,4,fil); - kdfread(subwaytracky1,4,4,fil); - kdfread(subwaytrackx2,4,4,fil); - kdfread(subwaytracky2,4,4,fil); - kdfread(subwayx,4,4,fil); - kdfread(subwaygoalstop,4,4,fil); - kdfread(subwayvel,4,4,fil); - kdfread(subwaypausetime,4,4,fil); - kdfread(waterfountainwall,2,MAXPLAYERS,fil); - kdfread(waterfountaincnt,2,MAXPLAYERS,fil); - kdfread(slimesoundcnt,2,MAXPLAYERS,fil); - - //Warning: only works if all pointers are in sector structures! - kdfread(animateptr,4,MAXANIMATES,fil); - for(i=MAXANIMATES-1;i>=0;i--) - animateptr[i] = (long *)(animateptr[i]+((long)sector)); - - kdfread(animategoal,4,MAXANIMATES,fil); - kdfread(animatevel,4,MAXANIMATES,fil); - kdfread(animateacc,4,MAXANIMATES,fil); - kdfread(&animatecnt,4,1,fil); - - kdfread(&totalclock,4,1,fil); - kdfread(&numframes,4,1,fil); - kdfread(&randomseed,4,1,fil); - kdfread(&numpalookups,2,1,fil); - - kdfread(&visibility,4,1,fil); - kdfread(¶llaxvisibility,4,1,fil); - kdfread(¶llaxtype,1,1,fil); - kdfread(¶llaxyoffs,4,1,fil); - kdfread(pskyoff,2,MAXPSKYTILES,fil); - kdfread(&pskybits,2,1,fil); - - kdfread(&mirrorcnt,2,1,fil); - kdfread(mirrorwall,2,mirrorcnt,fil); - kdfread(mirrorsector,2,mirrorcnt,fil); - - //I should save off interpolation list, but they're pointers :( - numinterpolations = 0; - startofdynamicinterpolations = 0; - - kclose(fil); - - for(i=connecthead;i>=0;i=connectpoint2[i]) initplayersprite((short)i); - - totalclock = lockclock; - ototalclock = lockclock; - - Bstrcpy(getmessage,"Game loaded."); - getmessageleng = Bstrlen(getmessage); - getmessagetimeoff = totalclock+360+(getmessageleng<<4); - return(0); -} - -long savegame(void) -{ - long i; - BFILE *fil; - - if ((fil = Bfopen("save0000.gam","wb")) == 0) return(-1); - - dfwrite(&numplayers,4,1,fil); - dfwrite(&myconnectindex,4,1,fil); - dfwrite(&connecthead,4,1,fil); - dfwrite(connectpoint2,4,MAXPLAYERS,fil); - - dfwrite(posx,4,MAXPLAYERS,fil); - dfwrite(posy,4,MAXPLAYERS,fil); - dfwrite(posz,4,MAXPLAYERS,fil); - dfwrite(horiz,4,MAXPLAYERS,fil); - dfwrite(zoom,4,MAXPLAYERS,fil); - dfwrite(hvel,4,MAXPLAYERS,fil); - dfwrite(ang,2,MAXPLAYERS,fil); - dfwrite(cursectnum,2,MAXPLAYERS,fil); - dfwrite(ocursectnum,2,MAXPLAYERS,fil); - dfwrite(playersprite,2,MAXPLAYERS,fil); - dfwrite(deaths,2,MAXPLAYERS,fil); - dfwrite(lastchaingun,4,MAXPLAYERS,fil); - dfwrite(health,4,MAXPLAYERS,fil); - dfwrite(numgrabbers,2,MAXPLAYERS,fil); - dfwrite(nummissiles,2,MAXPLAYERS,fil); - dfwrite(numbombs,2,MAXPLAYERS,fil); - dfwrite(flytime,4,MAXPLAYERS,fil); - dfwrite(oflags,2,MAXPLAYERS,fil); - dfwrite(dimensionmode,1,MAXPLAYERS,fil); - dfwrite(revolvedoorstat,1,MAXPLAYERS,fil); - dfwrite(revolvedoorang,2,MAXPLAYERS,fil); - dfwrite(revolvedoorrotang,2,MAXPLAYERS,fil); - dfwrite(revolvedoorx,4,MAXPLAYERS,fil); - dfwrite(revolvedoory,4,MAXPLAYERS,fil); - - dfwrite(&numsectors,2,1,fil); - dfwrite(sector,sizeof(sectortype),numsectors,fil); - dfwrite(&numwalls,2,1,fil); - dfwrite(wall,sizeof(walltype),numwalls,fil); - //Store all sprites (even holes) to preserve indeces - dfwrite(sprite,sizeof(spritetype),MAXSPRITES,fil); - dfwrite(headspritesect,2,MAXSECTORS+1,fil); - dfwrite(prevspritesect,2,MAXSPRITES,fil); - dfwrite(nextspritesect,2,MAXSPRITES,fil); - dfwrite(headspritestat,2,MAXSTATUS+1,fil); - dfwrite(prevspritestat,2,MAXSPRITES,fil); - dfwrite(nextspritestat,2,MAXSPRITES,fil); - - dfwrite(&fvel,4,1,fil); - dfwrite(&svel,4,1,fil); - dfwrite(&avel,4,1,fil); - - dfwrite(&locselectedgun,4,1,fil); - dfwrite(&loc.fvel,1,1,fil); - dfwrite(&oloc.fvel,1,1,fil); - dfwrite(&loc.svel,1,1,fil); - dfwrite(&oloc.svel,1,1,fil); - dfwrite(&loc.avel,1,1,fil); - dfwrite(&oloc.avel,1,1,fil); - dfwrite(&loc.bits,2,1,fil); - dfwrite(&oloc.bits,2,1,fil); - - dfwrite(&locselectedgun2,4,1,fil); - dfwrite(&loc2.fvel,sizeof(input),1,fil); - - dfwrite(ssync,sizeof(input),MAXPLAYERS,fil); - dfwrite(osync,sizeof(input),MAXPLAYERS,fil); - - dfwrite(boardfilename,1,80,fil); - dfwrite(&screenpeek,2,1,fil); - dfwrite(&oldmousebstatus,2,1,fil); - dfwrite(&brightness,2,1,fil); - dfwrite(&neartagsector,2,1,fil); - dfwrite(&neartagwall,2,1,fil); - dfwrite(&neartagsprite,2,1,fil); - dfwrite(&lockclock,4,1,fil); - dfwrite(&neartagdist,4,1,fil); - dfwrite(&neartaghitdist,4,1,fil); - - dfwrite(turnspritelist,2,16,fil); - dfwrite(&turnspritecnt,2,1,fil); - dfwrite(warpsectorlist,2,16,fil); - dfwrite(&warpsectorcnt,2,1,fil); - dfwrite(xpanningsectorlist,2,16,fil); - dfwrite(&xpanningsectorcnt,2,1,fil); - dfwrite(ypanningwalllist,2,64,fil); - dfwrite(&ypanningwallcnt,2,1,fil); - dfwrite(floorpanninglist,2,64,fil); - dfwrite(&floorpanningcnt,2,1,fil); - dfwrite(dragsectorlist,2,16,fil); - dfwrite(dragxdir,2,16,fil); - dfwrite(dragydir,2,16,fil); - dfwrite(&dragsectorcnt,2,1,fil); - dfwrite(dragx1,4,16,fil); - dfwrite(dragy1,4,16,fil); - dfwrite(dragx2,4,16,fil); - dfwrite(dragy2,4,16,fil); - dfwrite(dragfloorz,4,16,fil); - dfwrite(&swingcnt,2,1,fil); - dfwrite(swingwall,2,32*5,fil); - dfwrite(swingsector,2,32,fil); - dfwrite(swingangopen,2,32,fil); - dfwrite(swingangclosed,2,32,fil); - dfwrite(swingangopendir,2,32,fil); - dfwrite(swingang,2,32,fil); - dfwrite(swinganginc,2,32,fil); - dfwrite(swingx,4,32*8,fil); - dfwrite(swingy,4,32*8,fil); - dfwrite(revolvesector,2,4,fil); - dfwrite(revolveang,2,4,fil); - dfwrite(&revolvecnt,2,1,fil); - dfwrite(revolvex,4,4*16,fil); - dfwrite(revolvey,4,4*16,fil); - dfwrite(revolvepivotx,4,4,fil); - dfwrite(revolvepivoty,4,4,fil); - dfwrite(subwaytracksector,2,4*128,fil); - dfwrite(subwaynumsectors,2,4,fil); - dfwrite(&subwaytrackcnt,2,1,fil); - dfwrite(subwaystop,4,4*8,fil); - dfwrite(subwaystopcnt,4,4,fil); - dfwrite(subwaytrackx1,4,4,fil); - dfwrite(subwaytracky1,4,4,fil); - dfwrite(subwaytrackx2,4,4,fil); - dfwrite(subwaytracky2,4,4,fil); - dfwrite(subwayx,4,4,fil); - dfwrite(subwaygoalstop,4,4,fil); - dfwrite(subwayvel,4,4,fil); - dfwrite(subwaypausetime,4,4,fil); - dfwrite(waterfountainwall,2,MAXPLAYERS,fil); - dfwrite(waterfountaincnt,2,MAXPLAYERS,fil); - dfwrite(slimesoundcnt,2,MAXPLAYERS,fil); - - //Warning: only works if all pointers are in sector structures! - for(i=MAXANIMATES-1;i>=0;i--) - animateptr[i] = (long *)(animateptr[i]-((long)sector)); - dfwrite(animateptr,4,MAXANIMATES,fil); - for(i=MAXANIMATES-1;i>=0;i--) - animateptr[i] = (long *)(animateptr[i]+((long)sector)); - - dfwrite(animategoal,4,MAXANIMATES,fil); - dfwrite(animatevel,4,MAXANIMATES,fil); - dfwrite(animateacc,4,MAXANIMATES,fil); - dfwrite(&animatecnt,4,1,fil); - - dfwrite(&totalclock,4,1,fil); - dfwrite(&numframes,4,1,fil); - dfwrite(&randomseed,4,1,fil); - dfwrite(&numpalookups,2,1,fil); - - dfwrite(&visibility,4,1,fil); - dfwrite(¶llaxvisibility,4,1,fil); - dfwrite(¶llaxtype,1,1,fil); - dfwrite(¶llaxyoffs,4,1,fil); - dfwrite(pskyoff,2,MAXPSKYTILES,fil); - dfwrite(&pskybits,2,1,fil); - - dfwrite(&mirrorcnt,2,1,fil); - dfwrite(mirrorwall,2,mirrorcnt,fil); - dfwrite(mirrorsector,2,mirrorcnt,fil); - - Bfclose(fil); - - Bstrcpy(getmessage,"Game saved."); - getmessageleng = Bstrlen(getmessage); - getmessagetimeoff = totalclock+360+(getmessageleng<<4); - return(0); -} - -void faketimerhandler(void) -{ - short other, packbufleng; - long i, j, k, l; - - sampletimer(); - if ((totalclock < ototalclock+(TIMERINTSPERSECOND/MOVESPERSECOND)) || (ready2send == 0)) return; - ototalclock += (TIMERINTSPERSECOND/MOVESPERSECOND); - - getpackets(); - if (getoutputcirclesize() >= 16) return; - getinput(); - - /* - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (i != myconnectindex) - { - k = (movefifoend[myconnectindex]-1)-movefifoend[i]; - myminlag[i] = min(myminlag[i],k); - mymaxlag = max(mymaxlag,k); - } - - if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0) - { - i = mymaxlag-bufferjitter; mymaxlag = 0; - if (i > 0) bufferjitter += ((2+i)>>2); - else if (i < 0) bufferjitter -= ((2-i)>>2); - } - */ - - if (networkmode == 1) - { - packbuf[2] = 0; j = 3; - if (loc.fvel != oloc.fvel) packbuf[j++] = loc.fvel, packbuf[2] |= 1; - if (loc.svel != oloc.svel) packbuf[j++] = loc.svel, packbuf[2] |= 2; - if (loc.avel != oloc.avel) packbuf[j++] = loc.avel, packbuf[2] |= 4; - if ((loc.bits^oloc.bits)&0x00ff) packbuf[j++] = (loc.bits&255), packbuf[2] |= 8; - if ((loc.bits^oloc.bits)&0xff00) packbuf[j++] = ((loc.bits>>8)&255), packbuf[2] |= 16; - copybufbyte(&loc,&oloc,sizeof(input)); - - copybufbyte(&loc,&baksync[movefifoend[myconnectindex]][myconnectindex],sizeof(input)); - movefifoend[myconnectindex] = ((movefifoend[myconnectindex]+1)&(MOVEFIFOSIZ-1)); - - for(i=connecthead;i>=0;i=connectpoint2[i]) - if (i != myconnectindex) - { - packbuf[0] = 17; - packbuf[1] = (char)((movefifoend[myconnectindex]-movefifoend[i])&(MOVEFIFOSIZ-1)); - - k = j; - if ((myconnectindex == connecthead) || ((i == connecthead) && (myconnectindex == connectpoint2[connecthead]))) - { - while (syncvalhead != syncvaltail) - { - packbuf[j++] = syncval[syncvaltail]; - syncvaltail = ((syncvaltail+1)&(MOVEFIFOSIZ-1)); - } - } - sendpacket(i,packbuf,j); - j = k; - } - - gotlastpacketclock = totalclock; - return; - } - - //MASTER (or 1 player game) - if ((myconnectindex == connecthead) || (option[4] == 0)) - { - copybufbyte(&loc,&ffsync[myconnectindex],sizeof(input)); - - if (option[4] != 0) - { - packbuf[0] = 0; - j = ((numplayers+1)>>1)+1; - for(k=1;k=0;i=connectpoint2[i]) - { - l = 0; - if (ffsync[i].fvel != osync[i].fvel) packbuf[j++] = ffsync[i].fvel, l |= 1; - if (ffsync[i].svel != osync[i].svel) packbuf[j++] = ffsync[i].svel, l |= 2; - if (ffsync[i].avel != osync[i].avel) packbuf[j++] = ffsync[i].avel, l |= 4; - if (ffsync[i].bits != osync[i].bits) - { - packbuf[j++] = (ffsync[i].bits&255); - packbuf[j++] = ((ffsync[i].bits>>8)&255); - l |= 8; - } - packbuf[k>>3] |= (l<<(k&7)); - k += 4; - - copybufbyte(&ffsync[i],&osync[i],sizeof(input)); - } - - while (syncvalhead != syncvaltail) - { - packbuf[j++] = syncval[syncvaltail]; - syncvaltail = ((syncvaltail+1)&(MOVEFIFOSIZ-1)); - } - - for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - sendpacket(i,packbuf,j); - } - else if (numplayers >= 2) - { - if (keystatus[0xb5]) - { - keystatus[0xb5] = 0; - locselectedgun2++; if (locselectedgun2 >= 3) locselectedgun2 = 0; - } - - //Second player on 1 computer mode - loc2.fvel = min(max(fvel2,-128+8),127-8); - loc2.svel = min(max(svel2,-128+8),127-8); - loc2.avel = min(max(avel2,-128+16),127-16); - loc2.bits = (locselectedgun2<<13); - loc2.bits |= keystatus[0x45]; //Stand high - loc2.bits |= (keystatus[0x47]<<1); //Stand low - loc2.bits |= (1<<8); //Run - loc2.bits |= (keystatus[0x49]<<2); //Look up - loc2.bits |= (keystatus[0x37]<<3); //Look down - loc2.bits |= (keystatus[0x50]<<10); //Space - loc2.bits |= (keystatus[0x52]<<11); //Shoot - - other = connectpoint2[myconnectindex]; - if (other < 0) other = connecthead; - - copybufbyte(&loc2,&ffsync[other],sizeof(input)); - } - movethings(); //Move EVERYTHING (you too!) - } - else //I am a SLAVE - { - packbuf[0] = 1; packbuf[1] = 0; j = 2; - if (loc.fvel != oloc.fvel) packbuf[j++] = loc.fvel, packbuf[1] |= 1; - if (loc.svel != oloc.svel) packbuf[j++] = loc.svel, packbuf[1] |= 2; - if (loc.avel != oloc.avel) packbuf[j++] = loc.avel, packbuf[1] |= 4; - if ((loc.bits^oloc.bits)&0x00ff) packbuf[j++] = (loc.bits&255), packbuf[1] |= 8; - if ((loc.bits^oloc.bits)&0xff00) packbuf[j++] = ((loc.bits>>8)&255), packbuf[1] |= 16; - copybufbyte(&loc,&oloc,sizeof(input)); - sendpacket(connecthead,packbuf,j); - } -} - -void getpackets(void) -{ - long i, j, k, l; - long other, packbufleng, movecnt; - - if (option[4] == 0) return; - - movecnt = 0; - while ((packbufleng = getpacket(&other,packbuf)) > 0) - { - switch(packbuf[0]) - { - case 0: //[0] (receive master sync buffer) - j = ((numplayers+1)>>1)+1; k = (1<<3); - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - l = (packbuf[k>>3]>>(k&7)); - if (l&1) ffsync[i].fvel = packbuf[j++]; - if (l&2) ffsync[i].svel = packbuf[j++]; - if (l&4) ffsync[i].avel = packbuf[j++]; - if (l&8) - { - ffsync[i].bits = ((short)packbuf[j])+(((short)packbuf[j+1])<<8); - j += 2; - } - k += 4; - } - - while (j != packbufleng) - { - othersyncval[othersyncvalhead] = packbuf[j++]; - othersyncvalhead = ((othersyncvalhead+1)&(MOVEFIFOSIZ-1)); - } - if ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)) - { - syncstat = 0; - do - { - syncstat |= (syncval[syncvaltottail]^othersyncval[syncvaltottail]); - syncvaltottail = ((syncvaltottail+1)&(MOVEFIFOSIZ-1)); - } while ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)); - } - - movethings(); //Move all players and sprites - movecnt++; - break; - case 1: //[1] (receive slave sync buffer) - j = 2; k = packbuf[1]; - if (k&1) ffsync[other].fvel = packbuf[j++]; - if (k&2) ffsync[other].svel = packbuf[j++]; - if (k&4) ffsync[other].avel = packbuf[j++]; - if (k&8) ffsync[other].bits = ((ffsync[other].bits&0xff00)|((short)packbuf[j++])); - if (k&16) ffsync[other].bits = ((ffsync[other].bits&0x00ff)|(((short)packbuf[j++])<<8)); - break; - case 2: - getmessageleng = packbufleng-1; - for(j=getmessageleng-1;j>=0;j--) getmessage[j] = packbuf[j+1]; - getmessagetimeoff = totalclock+360+(getmessageleng<<4); - wsay("getstuff.wav",8192L,63L,63L); //Added 12/2004 - break; - case 3: - wsay("getstuff.wav",4096L,63L,63L); - break; - /* - case 5: - playerreadyflag[other] = packbuf[1]; - if ((other == connecthead) && (packbuf[1] == 2)) - sendpacket(connecthead,packbuf,2); - break; - */ - case 250: - playerreadyflag[other]++; - break; - case 17: - j = 3; k = packbuf[2]; - if (k&1) ffsync[other].fvel = packbuf[j++]; - if (k&2) ffsync[other].svel = packbuf[j++]; - if (k&4) ffsync[other].avel = packbuf[j++]; - if (k&8) ffsync[other].bits = ((ffsync[other].bits&0xff00)|((short)packbuf[j++])); - if (k&16) ffsync[other].bits = ((ffsync[other].bits&0x00ff)|(((short)packbuf[j++])<<8)); - otherlag[other] = packbuf[1]; - - copybufbyte(&ffsync[other],&baksync[movefifoend[other]][other],sizeof(input)); - movefifoend[other] = ((movefifoend[other]+1)&(MOVEFIFOSIZ-1)); - - while (j != packbufleng) - { - othersyncval[othersyncvalhead] = packbuf[j++]; - othersyncvalhead = ((othersyncvalhead+1)&(MOVEFIFOSIZ-1)); - } - if ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)) - { - syncstat = 0; - do - { - syncstat |= (syncval[syncvaltottail]^othersyncval[syncvaltottail]); - syncvaltottail = ((syncvaltottail+1)&(MOVEFIFOSIZ-1)); - } while ((syncvalhead != syncvaltottail) && (othersyncvalhead != syncvaltottail)); - } - - break; - case 255: //[255] (logout) - keystatus[1] = 1; - break; - } - } - if ((networkmode == 0) && (myconnectindex != connecthead) && ((movecnt&1) == 0)) - { - if (rand()&1) ototalclock += (TICSPERFRAME>>1); - else ototalclock -= (TICSPERFRAME>>1); - } -} - -void drawoverheadmap(long cposx, long cposy, long czoom, short cang) -{ - long i, j, k, l=0, x1, y1, x2=0, y2=0, x3, y3, x4, y4, ox, oy, xoff, yoff; - long dax, day, cosang, sinang, xspan, yspan, sprx, spry; - long xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang; - long xvect, yvect, xvect2, yvect2; - char col; - walltype *wal, *wal2; - spritetype *spr; - - xvect = sintable[(-cang)&2047] * czoom; - yvect = sintable[(1536-cang)&2047] * czoom; - xvect2 = mulscale16(xvect,yxaspect); - yvect2 = mulscale16(yvect,yxaspect); - - //Draw red lines - for(i=0;inextwall; if (k < 0) continue; - - if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue; - if ((k > j) && ((show2dwall[k>>3]&(1<<(k&7))) > 0)) continue; - - if (sector[wal->nextsector].ceilingz == z1) - if (sector[wal->nextsector].floorz == z2) - if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) continue; - - col = 152; - - if (dimensionmode[screenpeek] == 2) - { - if (sector[i].floorz != sector[i].ceilingz) - if (sector[wal->nextsector].floorz != sector[wal->nextsector].ceilingz) - if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) - if (sector[i].floorz == sector[wal->nextsector].floorz) continue; - if (sector[i].floorpicnum != sector[wal->nextsector].floorpicnum) continue; - if (sector[i].floorshade != sector[wal->nextsector].floorshade) continue; - col = 12; - } - - ox = wal->x-cposx; oy = wal->y-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); - y1 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); - - wal2 = &wall[wal->point2]; - ox = wal2->x-cposx; oy = wal2->y-cposy; - x2 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); - y2 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); - - drawline256(x1,y1,x2,y2,col); - } - } - - //Draw sprites - k = playersprite[screenpeek]; - for(i=0;i=0;j=nextspritesect[j]) - if ((show2dsprite[j>>3]&(1<<(j&7))) > 0) - { - spr = &sprite[j]; if (spr->cstat&0x8000) continue; - col = 56; - if (spr->cstat&1) col = 248; - if (j == k) col = 31; - - k = statrate[spr->statnum]; - sprx = spr->x; - spry = spr->y; - if (k >= 0) - { - switch(k) - { - case 0: l = smoothratio; break; - case 1: l = (smoothratio>>1)+(((nummoves-j)&1)<<15); break; - case 3: l = (smoothratio>>2)+(((nummoves-j)&3)<<14); break; - case 7: l = (smoothratio>>3)+(((nummoves-j)&7)<<13); break; - case 15: l = (smoothratio>>4)+(((nummoves-j)&15)<<12); break; - } - sprx = osprite[j].x+mulscale16(sprx-osprite[j].x,l); - spry = osprite[j].y+mulscale16(spry-osprite[j].y,l); - } - - switch (spr->cstat&48) - { - case 0: - ox = sprx-cposx; oy = spry-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect); - y1 = dmulscale16(oy,xvect2,ox,yvect2); - - if (dimensionmode[screenpeek] == 1) - { - ox = (sintable[(spr->ang+512)&2047]>>7); - oy = (sintable[(spr->ang)&2047]>>7); - x2 = dmulscale16(ox,xvect,-oy,yvect); - y2 = dmulscale16(oy,xvect,ox,yvect); - - if (j == playersprite[screenpeek]) - { - x2 = 0L; - y2 = -(czoom<<5); - } - - x3 = mulscale16(x2,yxaspect); - y3 = mulscale16(y2,yxaspect); - - drawline256(x1-x2+(xdim<<11),y1-y3+(ydim<<11), - x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); - drawline256(x1-y2+(xdim<<11),y1+x3+(ydim<<11), - x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); - drawline256(x1+y2+(xdim<<11),y1-x3+(ydim<<11), - x1+x2+(xdim<<11),y1+y3+(ydim<<11),col); - } - else - { - if (((gotsector[i>>3]&(1<<(i&7))) > 0) && (czoom > 96)) - { - daang = (spr->ang-cang)&2047; - if (j == playersprite[screenpeek]) { x1 = 0; y1 = 0; daang = 0; } - rotatesprite((x1<<4)+(xdim<<15),(y1<<4)+(ydim<<15),mulscale16(czoom*spr->yrepeat,yxaspect),daang,spr->picnum,spr->shade,spr->pal,(spr->cstat&2)>>1,windowx1,windowy1,windowx2,windowy2); - } - } - break; - case 16: - x1 = sprx; y1 = spry; - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - if ((spr->cstat&4) > 0) xoff = -xoff; - k = spr->ang; l = spr->xrepeat; - dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l; - l = tilesizx[tilenum]; k = (l>>1)+xoff; - x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l); - y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l); - - ox = x1-cposx; oy = y1-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect); - y1 = dmulscale16(oy,xvect2,ox,yvect2); - - ox = x2-cposx; oy = y2-cposy; - x2 = dmulscale16(ox,xvect,-oy,yvect); - y2 = dmulscale16(oy,xvect2,ox,yvect2); - - drawline256(x1+(xdim<<11),y1+(ydim<<11), - x2+(xdim<<11),y2+(ydim<<11),col); - - break; - case 32: - if (dimensionmode[screenpeek] == 1) - { - tilenum = spr->picnum; - xoff = (long)((signed char)((picanm[tilenum]>>8)&255))+((long)spr->xoffset); - yoff = (long)((signed char)((picanm[tilenum]>>16)&255))+((long)spr->yoffset); - if ((spr->cstat&4) > 0) xoff = -xoff; - if ((spr->cstat&8) > 0) yoff = -yoff; - - k = spr->ang; - cosang = sintable[(k+512)&2047]; sinang = sintable[k]; - xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat; - yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat; - - dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat; - x1 = sprx + dmulscale16(sinang,dax,cosang,day); - y1 = spry + dmulscale16(sinang,day,-cosang,dax); - l = xspan*xrepeat; - x2 = x1 - mulscale16(sinang,l); - y2 = y1 + mulscale16(cosang,l); - l = yspan*yrepeat; - k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k; - k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k; - - ox = x1-cposx; oy = y1-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect); - y1 = dmulscale16(oy,xvect2,ox,yvect2); - - ox = x2-cposx; oy = y2-cposy; - x2 = dmulscale16(ox,xvect,-oy,yvect); - y2 = dmulscale16(oy,xvect2,ox,yvect2); - - ox = x3-cposx; oy = y3-cposy; - x3 = dmulscale16(ox,xvect,-oy,yvect); - y3 = dmulscale16(oy,xvect2,ox,yvect2); - - ox = x4-cposx; oy = y4-cposy; - x4 = dmulscale16(ox,xvect,-oy,yvect); - y4 = dmulscale16(oy,xvect2,ox,yvect2); - - drawline256(x1+(xdim<<11),y1+(ydim<<11), - x2+(xdim<<11),y2+(ydim<<11),col); - - drawline256(x2+(xdim<<11),y2+(ydim<<11), - x3+(xdim<<11),y3+(ydim<<11),col); - - drawline256(x3+(xdim<<11),y3+(ydim<<11), - x4+(xdim<<11),y4+(ydim<<11),col); - - drawline256(x4+(xdim<<11),y4+(ydim<<11), - x1+(xdim<<11),y1+(ydim<<11),col); - - } - break; - } - } - - //Draw white lines - for(i=0;inextwall >= 0) continue; - - if ((show2dwall[j>>3]&(1<<(j&7))) == 0) continue; - - if (tilesizx[wal->picnum] == 0) continue; - if (tilesizy[wal->picnum] == 0) continue; - - if (j == k) - { x1 = x2; y1 = y2; } - else - { - ox = wal->x-cposx; oy = wal->y-cposy; - x1 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); - y1 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); - } - - k = wal->point2; wal2 = &wall[k]; - ox = wal2->x-cposx; oy = wal2->y-cposy; - x2 = dmulscale16(ox,xvect,-oy,yvect)+(xdim<<11); - y2 = dmulscale16(oy,xvect2,ox,yvect2)+(ydim<<11); - - drawline256(x1,y1,x2,y2,24); - } - } -} - -//New movesprite using getzrange. Note that I made the getzrange -//parameters global (&globhiz,&globhihit,&globloz,&globlohit) so they -//don't need to be passed everywhere. Also this should make this -//movesprite function compatible with the older movesprite functions. -long movesprite(short spritenum, long dx, long dy, long dz, long ceildist, long flordist, long clipmask) -{ - long daz, zoffs, tempint; - short retval, dasectnum, datempshort; - spritetype *spr; - - spr = &sprite[spritenum]; - - if ((spr->cstat&128) == 0) - zoffs = -((tilesizy[spr->picnum]*spr->yrepeat)<<1); - else - zoffs = 0; - - dasectnum = spr->sectnum; //Can't modify sprite sectors directly becuase of linked lists - daz = spr->z+zoffs; //Must do this if not using the new centered centering (of course) - retval = clipmove(&spr->x,&spr->y,&daz,&dasectnum,dx,dy, - ((long)spr->clipdist)<<2,ceildist,flordist,clipmask); - - if (dasectnum < 0) retval = -1; - - if ((dasectnum != spr->sectnum) && (dasectnum >= 0)) - changespritesect(spritenum,dasectnum); - - //Set the blocking bit to 0 temporarly so getzrange doesn't pick up - //its own sprite - datempshort = spr->cstat; spr->cstat &= ~1; - getzrange(spr->x,spr->y,spr->z-1,spr->sectnum, - &globhiz,&globhihit,&globloz,&globlohit, - ((long)spr->clipdist)<<2,clipmask); - spr->cstat = datempshort; - - daz = spr->z+zoffs + dz; - if ((daz <= globhiz) || (daz > globloz)) - { - if (retval != 0) return(retval); - return(16384+dasectnum); - } - spr->z = daz-zoffs; - return(retval); -} - - -void waitforeverybody () -{ - long i; - if (numplayers < 2) return; - packbuf[0] = 250; - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (i != myconnectindex) sendpacket(i,packbuf,1); - if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master - } - playerreadyflag[myconnectindex]++; - while (1) - { - handleevents(); - refreshaudio(); - - drawrooms(posx[myconnectindex],posy[myconnectindex],posz[myconnectindex],ang[myconnectindex],horiz[myconnectindex],cursectnum[myconnectindex]); - if (!networkmode) Bsprintf(tempbuf,"Master/slave mode"); - else Bsprintf(tempbuf,"Peer-peer mode"); - printext256((xdim>>1)-(strlen(tempbuf)<<2),(ydim>>1)-24,31,0,tempbuf,0); - Bsprintf(tempbuf,"Waiting for players"); - printext256((xdim>>1)-(strlen(tempbuf)<<2),(ydim>>1)-16,31,0,tempbuf,0); - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (playerreadyflag[i] < playerreadyflag[myconnectindex]) - { - //slaves in M/S mode only wait for master - if ((!networkmode) && (myconnectindex != connecthead) && (i != connecthead)) - { - Bsprintf(tempbuf,"Player %ld",i); - printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,15,0,tempbuf,0); - } - else - { - Bsprintf(tempbuf,"Player %ld NOT ready",i); - printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,127,0,tempbuf,0); - } - } - else - { - Bsprintf(tempbuf,"Player %ld ready",i); - printext256((xdim>>1)-(16<<2),(ydim>>1)+i*8,31,0,tempbuf,0); - } - if (i == myconnectindex) - { - Bsprintf(tempbuf,"You->"); - printext256((xdim>>1)-(26<<2),(ydim>>1)+i*8,95,0,tempbuf,0); - } - } - nextpage(); - - - if (quitevent || keystatus[1]) { - sendlogoff(); //Signing off - musicoff(); - uninitmultiplayers(); - uninittimer(); - uninitinput(); - uninitengine(); - uninitsb(); - uninitgroupfile(); - exit(0); - } - - getpackets(); - - for(i=connecthead;i>=0;i=connectpoint2[i]) - { - if (playerreadyflag[i] < playerreadyflag[myconnectindex]) break; - if ((!networkmode) && (myconnectindex != connecthead)) { i = -1; break; } //slaves in M/S mode only wait for master - } - if (i < 0) return; - } -} - - -void searchmap(short startsector) -{ - long i, j, dasect, splc, send, startwall, endwall; - short dapic; - walltype *wal; - - if ((startsector < 0) || (startsector >= numsectors)) return; - for(i=0;i<(MAXSECTORS>>3);i++) show2dsector[i] = 0; - for(i=0;i<(MAXWALLS>>3);i++) show2dwall[i] = 0; - for(i=0;i<(MAXSPRITES>>3);i++) show2dsprite[i] = 0; - - automapping = 0; - - //Search your area recursively & set all show2dsector/show2dwalls - tempshort[0] = startsector; - show2dsector[startsector>>3] |= (1<<(startsector&7)); - dapic = sector[startsector].ceilingpicnum; - if (waloff[dapic] == 0) loadtile(dapic); - dapic = sector[startsector].floorpicnum; - if (waloff[dapic] == 0) loadtile(dapic); - for(splc=0,send=1;splc>3] |= (1<<(i&7)); - dapic = wall[i].picnum; - if (waloff[dapic] == 0) loadtile(dapic); - dapic = wall[i].overpicnum; - if (((dapic&0xfffff000) == 0) && (waloff[dapic] == 0)) loadtile(dapic); - - j = wal->nextsector; - if ((j >= 0) && ((show2dsector[j>>3]&(1<<(j&7))) == 0)) - { - show2dsector[j>>3] |= (1<<(j&7)); - - dapic = sector[j].ceilingpicnum; - if (waloff[dapic] == 0) loadtile(dapic); - dapic = sector[j].floorpicnum; - if (waloff[dapic] == 0) loadtile(dapic); - - tempshort[send++] = (short)j; - } - } - - for(i=headspritesect[dasect];i>=0;i=nextspritesect[i]) - { - show2dsprite[i>>3] |= (1<<(i&7)); - dapic = sprite[i].picnum; - if (waloff[dapic] == 0) loadtile(dapic); - } - } -} - -void setinterpolation(long *posptr) -{ - long i; - - if (numinterpolations >= MAXINTERPOLATIONS) return; - for(i=numinterpolations-1;i>=0;i--) - if (curipos[i] == posptr) return; - curipos[numinterpolations] = posptr; - oldipos[numinterpolations] = *posptr; - numinterpolations++; -} - -void stopinterpolation(long *posptr) -{ - long i; - - for(i=numinterpolations-1;i>=startofdynamicinterpolations;i--) - if (curipos[i] == posptr) - { - numinterpolations--; - oldipos[i] = oldipos[numinterpolations]; - bakipos[i] = bakipos[numinterpolations]; - curipos[i] = curipos[numinterpolations]; - } -} - -void updateinterpolations(void) //Stick at beginning of domovethings -{ - long i; - - for(i=numinterpolations-1;i>=0;i--) oldipos[i] = *curipos[i]; -} - -void dointerpolations(void) //Stick at beginning of drawscreen -{ - long i, j, odelta, ndelta; - - ndelta = 0; j = 0; - for(i=numinterpolations-1;i>=0;i--) - { - bakipos[i] = *curipos[i]; - odelta = ndelta; ndelta = (*curipos[i])-oldipos[i]; - if (odelta != ndelta) j = mulscale16(ndelta,smoothratio); - *curipos[i] = oldipos[i]+j; - } -} - -void restoreinterpolations(void) //Stick at end of drawscreen -{ - long i; - - for(i=numinterpolations-1;i>=0;i--) *curipos[i] = bakipos[i]; -} - -void printext(long x, long y, char *buffer, short tilenum, char invisiblecol) -{ - long i; - char ch; - - for(i=0;buffer[i]!=0;i++) - { - ch = buffer[i]; - rotatesprite((x-((8&15)<<3))<<16,(y-((8>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+64+128,x,y,x+7,y+7); - rotatesprite((x-((ch&15)<<3))<<16,(y-((ch>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+128,x,y,x+7,y+7); - x += 8; - } -} - -void drawtilebackground (long thex, long they, short tilenum, - signed char shade, long cx1, long cy1, - long cx2, long cy2, char dapalnum) -{ - long x, y, xsiz, ysiz, tx1, ty1, tx2, ty2; - - xsiz = tilesizx[tilenum]; tx1 = cx1/xsiz; tx2 = cx2/xsiz; - ysiz = tilesizy[tilenum]; ty1 = cy1/ysiz; ty2 = cy2/ysiz; - - for(x=tx1;x<=tx2;x++) - for(y=ty1;y<=ty2;y++) - rotatesprite(x*xsiz<<16,y*ysiz<<16,65536L,0,tilenum,shade,dapalnum,8+16+64+128,cx1,cy1,cx2,cy2); -} - - -/* - * vim:ts=4:sw=4: - */ diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index 2e23aa05c..8afc3636f 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -82,7 +82,7 @@ static double dxb1[MAXWALLSB], dxb2[MAXWALLSB]; #define USEZBUFFER 1 //1:use zbuffer (slow, nice sprite rendering), 0:no zbuffer (fast, bad sprite rendering) #define LINTERPSIZ 4 //log2 of interpolation size. 4:pretty fast&acceptable quality, 0:best quality/slow! #define DEPTHDEBUG 0 //1:render distance instead of texture, for debugging only!, 0:default -#define FOGSCALE 0.0000700 +#define FOGSCALE 0.0000768 #define PI 3.14159265358979323 static double gyxscale, gxyaspect, gviewxrange, ghalfx, grhalfxdown10, grhalfxdown10x, ghoriz; @@ -3020,7 +3020,7 @@ static void polymost_drawalls (long bunch) if (((cy0 < ocy0) || (cy1 < ocy1)) && (!((sec->ceilingstat§or[nextsectnum].ceilingstat)&1))) { - globalpicnum = wal->picnum; globalshade = (wal->shade+2); globalpal = (long)((unsigned char)wal->pal); + globalpicnum = wal->picnum; globalshade = wal->shade; globalpal = (long)((unsigned char)wal->pal); if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); if (!(wal->cstat&4)) i = sector[nextsectnum].ceilingz; else i = sec->ceilingz; @@ -3056,7 +3056,7 @@ static void polymost_drawalls (long bunch) gux += (float)(nwal->xpanning-wal->xpanning)*gdx; guy += (float)(nwal->xpanning-wal->xpanning)*gdy; } - globalpicnum = nwal->picnum; globalshade = (nwal->shade+2); globalpal = (long)((unsigned char)nwal->pal); + globalpicnum = nwal->picnum; globalshade = nwal->shade; globalpal = (long)((unsigned char)nwal->pal); if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); if (!(nwal->cstat&4)) i = sector[nextsectnum].floorz; else i = sec->ceilingz; @@ -3087,7 +3087,7 @@ static void polymost_drawalls (long bunch) if ((nextsectnum < 0) || (wal->cstat&32)) //White/1-way wall { if (nextsectnum < 0) globalpicnum = wal->picnum; else globalpicnum = wal->overpicnum; - globalshade = (wal->shade+2); globalpal = (long)((unsigned char)wal->pal); + globalshade = wal->shade; globalpal = (long)((unsigned char)wal->pal); if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,wallnum+16384); if (nextsectnum >= 0) { if (!(wal->cstat&4)) i = nextsec->ceilingz; else i = sec->ceilingz; } @@ -3289,7 +3289,7 @@ void polymost_drawrooms () ghalfx = (double)halfxdimen; grhalfxdown10 = 1.0/(((double)ghalfx)*1024); ghoriz = (double)globalhoriz; - gvisibility = ((float)globalvisibility)*gxyaspect*FOGSCALE; + gvisibility = ((float)globalvisibility)*FOGSCALE; //global cos/sin height angle r = (double)((ydimen>>1)-ghoriz); @@ -3483,7 +3483,7 @@ void polymost_drawmaskwall (long damaskwallcnt) globalpicnum = wal->overpicnum; if ((unsigned long)globalpicnum >= MAXTILES) globalpicnum = 0; if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,(short)thewall[z]+16384); - globalshade = (long)(wal->shade+2); + globalshade = (long)wal->shade; globalpal = (long)((unsigned char)wal->pal); globalorientation = (long)wal->cstat; diff --git a/polymer/build/src/startgtk.game.c b/polymer/build/src/startgtk.game.c deleted file mode 100755 index c173f0c4f..000000000 --- a/polymer/build/src/startgtk.game.c +++ /dev/null @@ -1,545 +0,0 @@ -/* NOTE: Glade will generate code for a dialogue box which you should - * then patch into this file whenever you make a change to the Glade - * template. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#ifndef LINKED_GTK -# include "dynamicgtk.h" -#endif - -#include "baselayer.h" -#include "compat.h" -#include "build.h" - -#define TAB_CONFIG 0 -#define TAB_MESSAGES 1 - -static struct { - int fullscreen; - int xdim3d, ydim3d, bpp3d; - int forcesetup; -} settings; - -extern int gtkenabled; - -static GtkWidget *startwin = NULL; -static int retval = -1, mode = TAB_MESSAGES; - -// -- SUPPORT FUNCTIONS ------------------------------------------------------- - -#define GLADE_HOOKUP_OBJECT(component,widget,name) \ - g_object_set_data_full (G_OBJECT (component), name, \ - gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) - -#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ - g_object_set_data (G_OBJECT (component), name, widget) - -#define lookup_widget(x,w) \ - (GtkWidget*) g_object_get_data(G_OBJECT(x), w) - -static GdkPixbuf *load_banner(void) -{ - extern const GdkPixdata startbanner_pixdata; - return gdk_pixbuf_from_pixdata(&startbanner_pixdata, FALSE, NULL); -} - -static void SetPage(int n) -{ - if (!gtkenabled || !startwin) return; - mode = n; - gtk_notebook_set_current_page(GTK_NOTEBOOK(lookup_widget(startwin,"tabs")), n); - - // each control in the config page vertical layout plus the start button should be made (in)sensitive - if (n == TAB_CONFIG) n = TRUE; else n = FALSE; - gtk_widget_set_sensitive(lookup_widget(startwin,"startbutton"), n); - gtk_container_foreach(GTK_CONTAINER(lookup_widget(startwin,"configvlayout")), - (GtkCallback)gtk_widget_set_sensitive, (gpointer)n); -} - -static void on_vmode3dcombo_changed(GtkComboBox *, gpointer); -static void PopulateForm(void) -{ - int mode3d, i; - GtkListStore *modes3d; - GtkTreeIter iter; - GtkComboBox *box3d; - char buf[64]; - - mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); - if (mode3d < 0) { - int i, cd[] = { 32, 24, 16, 15, 8, 0 }; - for (i=0; cd[i]; ) { if (cd[i] >= settings.bpp3d) i++; else break; } - for ( ; cd[i]; i++) { - mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); - if (mode3d < 0) continue; - settings.bpp3d = cd[i]; - break; - } - } - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"fullscreencheck")), settings.fullscreen); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"alwaysshowcheck")), settings.forcesetup); - - box3d = GTK_COMBO_BOX(lookup_widget(startwin,"vmode3dcombo")); - modes3d = GTK_LIST_STORE(gtk_combo_box_get_model(box3d)); - gtk_list_store_clear(modes3d); - - for (i=0; i aptr) - gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1); -#if GTK_CHECK_VERSION(2,6,0) - gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE); -#else - { - GtkTextIter iter2 = enditer; - gtk_text_iter_backward_cursor_position(&iter2); - //FIXME: this seems be deleting one too many chars somewhere! - if (!gtk_text_iter_equal(&iter2, &enditer)) - gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE); - } -#endif - aptr = ++bptr; - break; - case 0: - if (bptr > aptr) - gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)); - aptr = bptr; - break; - case '\r': // FIXME - default: - bptr++; - break; - } - } - - mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1); - gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0); - gtk_text_buffer_delete_mark(textbuffer, mark); - - return 0; -} - -int startwin_settitle(const char *title) -{ - if (!gtkenabled) return 0; - if (!startwin) return 1; - gtk_window_set_title (GTK_WINDOW (startwin), title); - return 0; -} - -int startwin_idle(void *s) -{ - if (!gtkenabled) return 0; - //if (!startwin) return 1; - gtk_main_iteration_do (FALSE); - return 0; -} - -extern int xdimgame, ydimgame, bppgame, forcesetup; - -int startwin_run(void) -{ - if (!gtkenabled) return 0; - if (!startwin) return 1; - - SetPage(TAB_CONFIG); - - settings.fullscreen = fullscreen; - settings.xdim3d = xdimgame; - settings.ydim3d = ydimgame; - settings.bpp3d = bppgame; - settings.forcesetup = forcesetup; - PopulateForm(); - - gtk_main(); - - SetPage(TAB_MESSAGES); - if (retval) { - fullscreen = settings.fullscreen; - xdimgame = settings.xdim3d; - ydimgame = settings.ydim3d; - bppgame = settings.bpp3d; - forcesetup = settings.forcesetup; - } - - return retval; -} - diff --git a/polymer/build/src/startwin.game.c b/polymer/build/src/startwin.game.c deleted file mode 100755 index b8b2d200f..000000000 --- a/polymer/build/src/startwin.game.c +++ /dev/null @@ -1,422 +0,0 @@ -#ifndef RENDERTYPEWIN -#error Only for Windows -#endif - -#include "build.h" -#include "winlayer.h" -#include "compat.h" - -#define WIN32_LEAN_AND_MEAN -#include -#include -#define _WIN32_IE 0x0300 -#include -#include - -#include "startwin.game.h" - -#define TAB_CONFIG 0 -#define TAB_MESSAGES 1 - -static struct { - int fullscreen; - int xdim3d, ydim3d, bpp3d; - int forcesetup; -} settings; - -static HWND startupdlg = NULL; -static HWND pages[2] = { NULL, NULL}; -static int done = -1, mode = TAB_CONFIG; - -static void PopulateForm(void) -{ - int i,j; - char buf[64]; - int mode3d; - HWND hwnd3d; - - hwnd3d = GetDlgItem(pages[TAB_CONFIG], IDC3DVMODE); - - mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); - if (mode3d < 0) { - int cd[] = { 32, 24, 16, 15, 8, 0 }; - for (i=0; cd[i]; ) { if (cd[i] >= settings.bpp3d) i++; else break; } - for ( ; cd[i]; i++) { - mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); - if (mode3d < 0) continue; - settings.bpp3d = cd[i]; - break; - } - } - - Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), (settings.fullscreen ? BST_CHECKED : BST_UNCHECKED)); - Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED)); - - ComboBox_ResetContent(hwnd3d); - for (i=0; iidFrom != WIN_STARTWIN_TABCTL) break; - cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); - switch (nmhdr->code) { - case TCN_SELCHANGING: { - if (cur < 0 || !pages[cur]) break; - ShowWindow(pages[cur],SW_HIDE); - return TRUE; - } - case TCN_SELCHANGE: { - if (cur < 0 || !pages[cur]) break; - ShowWindow(pages[cur],SW_SHOW); - return TRUE; - } - } - break; - } - - case WM_CLOSE: - if (mode == TAB_CONFIG) done = 0; - else quitevent++; - return TRUE; - - case WM_DESTROY: - if (hbmp) { - DeleteObject(hbmp); - hbmp = NULL; - } - - if (pages[TAB_CONFIG]) { - DestroyWindow(pages[TAB_CONFIG]); - pages[TAB_CONFIG] = NULL; - } - - startupdlg = NULL; - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case WIN_STARTWIN_CANCEL: - if (mode == TAB_CONFIG) done = 0; - else quitevent++; - return TRUE; - case WIN_STARTWIN_START: done = 1; return TRUE; - } - return FALSE; - - case WM_CTLCOLORSTATIC: - if ((HWND)lParam == pages[TAB_MESSAGES]) - return (BOOL)GetSysColorBrush(COLOR_WINDOW); - break; - - default: break; - } - - return FALSE; -} - - -int startwin_open(void) -{ - INITCOMMONCONTROLSEX icc; - if (startupdlg) return 1; - icc.dwSize = sizeof(icc); - icc.dwICC = ICC_TAB_CLASSES; - InitCommonControlsEx(&icc); - startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); - if (startupdlg) { - SetPage(TAB_MESSAGES); - EnableConfig(0); - return 0; - } - return -1; -} - -int startwin_close(void) -{ - if (!startupdlg) return 1; - DestroyWindow(startupdlg); - startupdlg = NULL; - return 0; -} - -int startwin_puts(const char *buf) -{ - const char *p = NULL, *q = NULL; - char workbuf[1024]; - static int newline = 0; - int curlen, linesbefore, linesafter; - HWND edctl; - int vis; - - if (!startupdlg) return 1; - - edctl = pages[TAB_MESSAGES]; - if (!edctl) return -1; - - vis = ((int)SendMessage(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL), TCM_GETCURSEL,0,0) == TAB_MESSAGES); - - if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); - curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); - SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); - linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); - p = buf; - while (*p) { - if (newline) { - SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); - newline = 0; - } - q = p; - while (*q && *q != '\n') q++; - memcpy(workbuf, p, q-p); - if (*q == '\n') { - if (!q[1]) { - newline = 1; - workbuf[q-p] = 0; - } else { - workbuf[q-p] = '\r'; - workbuf[q-p+1] = '\n'; - workbuf[q-p+2] = 0; - } - p = q+1; - } else { - workbuf[q-p] = 0; - p = q; - } - SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); - } - linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); - SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); - if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); - return 0; -} - -int startwin_settitle(const char *str) -{ - if (!startupdlg) return 1; - SetWindowText(startupdlg, str); - return 0; -} - -int startwin_idle(void *v) -{ - if (!startupdlg || !IsWindow(startupdlg)) return 0; - if (IsDialogMessage(startupdlg, (MSG*)v)) return 1; - return 0; -} - -extern int xdimgame, ydimgame, bppgame, forcesetup; - -int startwin_run(void) -{ - MSG msg; - if (!startupdlg) return 1; - - done = -1; - - SetPage(TAB_CONFIG); - EnableConfig(1); - - settings.fullscreen = fullscreen; - settings.xdim3d = xdimgame; - settings.ydim3d = ydimgame; - settings.bpp3d = bppgame; - settings.forcesetup = forcesetup; - PopulateForm(); - - while (done < 0) { - switch (GetMessage(&msg, NULL, 0,0)) { - case 0: done = 1; break; - case -1: return -1; - default: - if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; - TranslateMessage(&msg); - DispatchMessage(&msg); - break; - } - } - - SetPage(TAB_MESSAGES); - EnableConfig(0); - if (done) { - fullscreen = settings.fullscreen; - xdimgame = settings.xdim3d; - ydimgame = settings.ydim3d; - bppgame = settings.bpp3d; - forcesetup = settings.forcesetup; - } - - return done; -} - diff --git a/polymer/build/watcomhax/cerrno b/polymer/build/watcomhax/cerrno new file mode 100755 index 000000000..edcc29d2c --- /dev/null +++ b/polymer/build/watcomhax/cerrno @@ -0,0 +1 @@ +#include diff --git a/polymer/build/watcomhax/cmath b/polymer/build/watcomhax/cmath new file mode 100755 index 000000000..2911680c7 --- /dev/null +++ b/polymer/build/watcomhax/cmath @@ -0,0 +1,2 @@ +#include +#define M_PI 3.14159265358979323846 diff --git a/polymer/build/watcomhax/cstdarg b/polymer/build/watcomhax/cstdarg new file mode 100755 index 000000000..8942a2e77 --- /dev/null +++ b/polymer/build/watcomhax/cstdarg @@ -0,0 +1 @@ +#include diff --git a/polymer/build/watcomhax/cstdio b/polymer/build/watcomhax/cstdio new file mode 100755 index 000000000..bfcdbf0e9 --- /dev/null +++ b/polymer/build/watcomhax/cstdio @@ -0,0 +1 @@ +#include diff --git a/polymer/build/watcomhax/cstdlib b/polymer/build/watcomhax/cstdlib new file mode 100755 index 000000000..9ada8e59c --- /dev/null +++ b/polymer/build/watcomhax/cstdlib @@ -0,0 +1 @@ +#include diff --git a/polymer/build/watcomhax/cstring b/polymer/build/watcomhax/cstring new file mode 100755 index 000000000..8e69c1fc0 --- /dev/null +++ b/polymer/build/watcomhax/cstring @@ -0,0 +1 @@ +#include diff --git a/polymer/build/watcomhax/ctime b/polymer/build/watcomhax/ctime new file mode 100755 index 000000000..23b073712 --- /dev/null +++ b/polymer/build/watcomhax/ctime @@ -0,0 +1 @@ +#include diff --git a/polymer/eduke32/Makefile.msvc b/polymer/eduke32/Makefile.msvc index 1b4b388ef..2b66c52d9 100644 --- a/polymer/eduke32/Makefile.msvc +++ b/polymer/eduke32/Makefile.msvc @@ -30,11 +30,11 @@ CC=cl AS=ml LINK=link /opt:nowin98 /nologo /opt:ref CFLAGS= /MD /J /nologo $(flags_cl) \ - /I$(INC) /I$(EINC) /I$(SRC)jmact /I$(SRC)jaudiolib /I..\jfaud\src \ + /I$(INC) /I$(EINC) /I$(SRC)jmact /I$(SRC)jaudiolib /I..\jfaud\inc \ /DNOCOPYPROTECT $(ENGINEOPTS) \ /I$(DXROOT)\include /DRENDERTYPEWIN=1 -LIBS=user32.lib gdi32.lib shell32.lib dxguid.lib winmm.lib wsock32.lib \ - ..\jfaud\jfaud.lib ..\jfaud\mpadec\mpadec.lib /NODEFAULTLIB:libFLAC.lib \ +LIBS=user32.lib gdi32.lib shell32.lib dxguid.lib winmm.lib wsock32.lib comctl32.lib \ + ..\jfaud\jfaud.lib /NODEFAULTLIB:libFLAC.lib \ #opengl32.lib ASFLAGS=/nologo /coff ASFLAGS=/nologo /coff @@ -86,7 +86,7 @@ AUDIOLIBOBJ=$(AUDIOLIB_JFAUD) $(OBJ)osdcmds.$o \ $(JMACTOBJ) \ $(AUDIOLIBOBJ) \ - $(OBJ)winbits.$o $(OBJ)gameres.res + $(OBJ)winbits.$o $(OBJ)gameres.res $(OBJ)startwin.game.$o EDITOROBJS=$(OBJ)astub.$o \ $(OBJ)buildres.res @@ -117,7 +117,7 @@ EDITOROBJS=$(OBJ)astub.$o \ $(CC) /c $(CFLAGS) /Fo$@ $< {$(SRC)misc}.rc{$(OBJ)}.res: - $(RC) /fo$@ /r $< + $(RC) /i$(EINC) /i$(SRC) /fo$@ /r $< # TARGETS diff --git a/polymer/eduke32/Makefile.watcom b/polymer/eduke32/Makefile.watcom index 6431ed470..8af0e5acf 100644 --- a/polymer/eduke32/Makefile.watcom +++ b/polymer/eduke32/Makefile.watcom @@ -20,10 +20,11 @@ DXROOT=c:\sdks\msc\dx7 ENGINEOPTS=-dSUPERBUILD -dPOLYMOST -dUSE_OPENGL CC=wcc386 -CFLAGS= -5r -s -orb -fp5 -d2 -db & - -i=$(INC) -i=$(EINC) -i=$(SRC)jmact -i=$(SRC)jaudiolib -i=$(DXROOT)\include & - -dRENDERTYPEWIN=1 -dNOCOPYPROTECT $(ENGINEOPTS) -LIBS=winmm.lib wsock32.lib dxguid.lib #opengl32.lib +CXX=wpp386 +CFLAGS= -zq -5r -s -orb -fp5 -d2 -db & + -i=watcomhax -i=$(INC) -i=$(EINC) -i=$(SRC)jmact -i=$(SRC)jaudiolib -i=$(DXROOT)\include & + -dRENDERTYPEWIN=1 -dNOCOPYPROTECT $(ENGINEOPTS) -i=..\jfaud\inc +LIBS=wsock32.lib dxguid.lib ..\jfaud\jfaud.lib winmm.lib #opengl32.lib WASMFLAGS=-d1 EXESUFFIX=.exe @@ -35,9 +36,9 @@ JMACTOBJ=$(OBJ)util_lib.$o & $(OBJ)mathutil.$o & $(OBJ)scriplib.$o -#JAUDIOLIB_FX=$(OBJ)jaudiolib_fxstub.$o -#JAUDIOLIB_MUSIC=$(OBJ)jaudiolib_musicstub.$o -#JAUDIOLIB_FX=$(OBJ)jaudiolib_fx_fmod.$o +JAUDIOLIB_FX_STUB=$(OBJ)jaudiolib_fxstub.$o +JAUDIOLIB_MUSIC_STUB=$(OBJ)jaudiolib_musicstub.$o +JAUDIOLIB_JFAUD=$(OBJ)jfaud_sounds.$o JAUDIOLIB_FX=$(OBJ)mv_mix.$o & $(OBJ)mv_mix16.$o & $(OBJ)mvreverb.$o & @@ -49,7 +50,9 @@ JAUDIOLIB_FX=$(OBJ)mv_mix.$o & JAUDIOLIB_MUSIC=$(OBJ)midi.$o & $(OBJ)mpu401.$o & $(OBJ)music.$o -JAUDIOLIBOBJ=$(JAUDIOLIB_MUSIC) $(JAUDIOLIB_FX) +#JAUDIOLIBOBJ=$(JAUDIOLIB_MUSIC) $(JAUDIOLIB_FX) $(OBJ)sounds.$o +#JAUDIOLIBOBJ=$(JAUDIOLIB_MUSIC_STUB) $(JAUDIOLIB_FX_STUB) $(OBJ)sounds.$o +JAUDIOLIBOBJ=$(JAUDIOLIB_JFAUD) GAMEOBJS=$(OBJ)game.$o & $(OBJ)actors.$o & @@ -63,7 +66,6 @@ GAMEOBJS=$(OBJ)game.$o & $(OBJ)premap.$o & $(OBJ)savegame.$o & $(OBJ)sector.$o & - $(OBJ)sounds.$o & $(OBJ)rts.$o & $(OBJ)config.$o & $(OBJ)animlib.$o & @@ -71,6 +73,7 @@ GAMEOBJS=$(OBJ)game.$o & $(OBJ)osdfuncs.$o & $(OBJ)osdcmds.$o & $(OBJ)winbits.$o & + $(OBJ)startwin.game.$o & $(JMACTOBJ) & $(JAUDIOLIBOBJ) @@ -82,6 +85,7 @@ EDITOROBJS=$(OBJ)astub.$o .wasm: $(SRC) .wasm: $(SRC)jaudiolib/ .c: $(SRC) +.cpp: $(SRC) .c: $(SRC)jmact/ .c: $(SRC)jaudiolib/ .c: $(SRC)util/ @@ -92,9 +96,11 @@ EDITOROBJS=$(OBJ)astub.$o .c.$o: $(CC) $(CFLAGS) -fo=$(OBJ).$o $[@ +.cpp.$o: + $(CXX) $(CFLAGS) -fo=$(OBJ).$o $[@ .rc.res: - wrc -fo=$^*.res -r $[@ + wrc -i=$(EINC) -i=$(SRC) -fo=$^*.res -r $[@ # TARGETS diff --git a/polymer/eduke32/source/jfaud_sounds.cpp b/polymer/eduke32/source/jfaud_sounds.cpp index 08aca40bb..803224fbf 100644 --- a/polymer/eduke32/source/jfaud_sounds.cpp +++ b/polymer/eduke32/source/jfaud_sounds.cpp @@ -28,7 +28,7 @@ extern "C" { # include "winlayer.h" #endif #include "osd.h" - long numenvsnds; +long numenvsnds; } typedef uint64 uint64_t; @@ -46,59 +46,59 @@ typedef uint64 uint64_t; #define SOUNDM_NICE 64 // Added for JFDuke3D so JFAud doesn't use nearest filtering for the sound #define SOUNDM_PLAYER 128 -#define UNITSPERMETRE 1024.0 +#define UNITSPERMETRE 512.0 #include class KenFile : public JFAudFile { private: - int fh; + int fh; public: - KenFile(const char *filename, const char *subfilename) - : JFAudFile(filename, subfilename) - { - fh = kopen4load(const_cast(filename), 0); - } + KenFile(const char *filename, const char *subfilename) + : JFAudFile(filename, subfilename) + { + fh = kopen4load(const_cast(filename), 0); + } - virtual ~KenFile() - { - if (fh >= 0) kclose(fh); - } + virtual ~KenFile() + { + if (fh >= 0) kclose(fh); + } -virtual bool IsOpen(void) const { return fh >= 0; } + virtual bool IsOpen(void) const { return fh >= 0; } - virtual long Read(long nbytes, void *buf) - { - if (fh < 0) return -1; - return kread(fh, buf, nbytes); - } - virtual long Seek(long pos, SeekFrom where) - { - int when; - if (fh < 0) return -1; - switch (where) { - case JFAudFile::Set: when = SEEK_SET; break; - case JFAudFile::Cur: when = SEEK_CUR; break; - case JFAudFile::End: when = SEEK_END; break; - default: return -1; - } - return klseek(fh, pos, when); - } - virtual long Tell(void) const - { - if (fh < 0) return -1; - return klseek(fh, 0, SEEK_CUR); - } - virtual long Length(void) const - { - if (fh < 0) return -1; - return kfilelength(fh); - } + virtual long Read(long nbytes, void *buf) + { + if (fh < 0) return -1; + return kread(fh, buf, nbytes); + } + virtual long Seek(long pos, SeekFrom where) + { + int when; + if (fh < 0) return -1; + switch (where) { + case JFAudFile::Set: when = SEEK_SET; break; + case JFAudFile::Cur: when = SEEK_CUR; break; + case JFAudFile::End: when = SEEK_END; break; + default: return -1; + } + return klseek(fh, pos, when); + } + virtual long Tell(void) const + { + if (fh < 0) return -1; + return klseek(fh, 0, SEEK_CUR); + } + virtual long Length(void) const + { + if (fh < 0) return -1; + return kfilelength(fh); + } }; static JFAudFile *openfile(const char *fn, const char *subfn) { - return static_cast(new KenFile(fn,subfn)); + return static_cast(new KenFile(fn,subfn)); } static void logfunc(const char *s) { initprintf("jfaud: %s", s); } @@ -108,31 +108,31 @@ static void logfunc(const char *s) { initprintf("jfaud: %s", s); } static float pitchtable[PITCHRANGE*PITCHSTEPS*2+1]; static void buildpitchtable(void) { - int i,j; - - for (i=-PITCHRANGE*PITCHSTEPS; i<=PITCHRANGE*PITCHSTEPS; i++) { - pitchtable[i+PITCHRANGE*PITCHSTEPS] = pow(1.0005777895, (1200.0/PITCHSTEPS)*(float)i); - } + int i,j; + + for (i=-PITCHRANGE*PITCHSTEPS; i<=PITCHRANGE*PITCHSTEPS; i++) { + pitchtable[i+PITCHRANGE*PITCHSTEPS] = pow(1.0005777895, (1200.0/PITCHSTEPS)*(float)i); + } } static float translatepitch(int p) { - float t; - int x; - x = (p * PITCHSTEPS / 1200) + PITCHRANGE*PITCHSTEPS; - if (x < 0) x = 0; - else if (x > (int)(sizeof(pitchtable)/sizeof(float))) x = sizeof(pitchtable)/sizeof(float); - t = pitchtable[x]; - /*if (t > 2.0) { - initprintf("translatepitch(%d) > 2.0\n", p); - t = 2.0; - }*/ - return t; + float t; + int x; + x = (p * PITCHSTEPS / 1200) + PITCHRANGE*PITCHSTEPS; + if (x < 0) x = 0; + else if (x > (int)(sizeof(pitchtable)/sizeof(float))) x = sizeof(pitchtable)/sizeof(float); + t = pitchtable[x]; + /*if (t > 2.0) { + initprintf("translatepitch(%d) > 2.0\n", p); + t = 2.0; + }*/ + return t; } typedef struct { - JFAudMixerChannel *chan; - int owner; // sprite number - int soundnum; // sound number + JFAudMixerChannel *chan; + int owner; // sprite number + int soundnum; // sound number } SoundChannel; static SoundChannel *chans = NULL; @@ -143,9 +143,9 @@ static bool havemidi = false, havewave = false; static void stopcallback(int r) { - jfaud->FreeSound(chans[r].chan); - chans[r].chan = NULL; - chans[r].owner = -1; + jfaud->FreeSound(chans[r].chan); + chans[r].chan = NULL; + chans[r].owner = -1; } void testcallback(unsigned long num) @@ -154,85 +154,86 @@ void testcallback(unsigned long num) static int keephandle(JFAudMixerChannel *handle, int soundnum, int owner) { - int i, freeh=-1; - for (i=NumVoices-1;i>=0;i--) { - if ((!chans[i].chan || !jfaud->IsValidSound(chans[i].chan)) && freeh<0) freeh=i; - else if (chans[i].chan == handle) { freeh=i; break; } - } - if (freeh<0) { - initprintf("Warning: keephandle() exhausted handle space!\n"); - return -1; - } + int i, freeh=-1; + for (i=NumVoices-1;i>=0;i--) { + if ((!chans[i].chan || !jfaud->IsValidSound(chans[i].chan)) && freeh<0) freeh=i; + else if (chans[i].chan == handle) { freeh=i; break; } + } + if (freeh<0) { + initprintf("Warning: keephandle() exhausted handle space!\n"); + return -1; + } - chans[freeh].chan = handle; - chans[freeh].soundnum = soundnum; - chans[freeh].owner = owner; - - return freeh; + chans[freeh].chan = handle; + chans[freeh].soundnum = soundnum; + chans[freeh].owner = owner; + + return freeh; } void SoundStartup(void) { - int i; + int i; - if (FXDevice < 0) return; + if (FXDevice < 0) return; - if (jfaud) return; - buildpitchtable(); + if (jfaud) return; + buildpitchtable(); - JFAud_SetLogFunc(logfunc); + JFAud_SetLogFunc(logfunc); - jfaud = new JFAud(); - if (!jfaud) return; + jfaud = new JFAud(); + if (!jfaud) return; - jfaud->SetUserOpenFunc(openfile); + jfaud->SetUserOpenFunc(openfile); #ifdef _WIN32 - jfaud->SetWindowHandle((void*)win_gethwnd()); + jfaud->SetWindowHandle((void*)win_gethwnd()); #endif - havewave = havemidi = false; - if (!jfaud->InitWave("software", NumVoices, MixRate)) { - delete jfaud; - jfaud = NULL; - return; - } + havewave = havemidi = false; + if (!jfaud->InitWave("software", NumVoices, MixRate)) { + delete jfaud; + jfaud = NULL; + return; + } - { - // the engine will take 60% of the system memory size for cache1d if there - // is less than the 16MB asked for in loadpics(), so we'll - // take 30% of what's left for the sound cache if that happened, or - // 50% of the system memory sans the 16MB maximum otherwise - unsigned k; - if (Bgetsysmemsize() <= MAXCACHE1DSIZE) - k = Bgetsysmemsize()/100*30; - else - k = Bgetsysmemsize()/100*50 - MAXCACHE1DSIZE; - jfaud->SetCacheItemAge(24*120); // 24 movements per second, 120 seconds max lifetime - } + { + // the engine will take 60% of the system memory size for cache1d if there + // is less than the 16MB asked for in loadpics(), so we'll + // take 30% of what's left for the sound cache if that happened, or + // 50% of the system memory sans the 16MB maximum otherwise + unsigned k; + if (Bgetsysmemsize() <= MAXCACHE1DSIZE) + k = Bgetsysmemsize()/100*30; + else + k = Bgetsysmemsize()/100*50 - MAXCACHE1DSIZE; + jfaud->SetCacheSize(k,k/2); + jfaud->SetCacheItemAge(24*120); // 24 movements per second, 120 seconds max lifetime + } + + chans = new SoundChannel[NumVoices]; + if (!chans) { + delete jfaud; + jfaud = NULL; + return; + } - chans = new SoundChannel[NumVoices]; - if (!chans) { - delete jfaud; - jfaud = NULL; - return; - } + havewave = true; - havewave = true; - - for (i=NumVoices-1; i>=0; i--) { - chans[i].owner = -1; - } - - if (jfaud->InitMIDI(NULL)) havemidi = true; + for (i=NumVoices-1; i>=0; i--) { + chans[i].owner = -1; + } + + if (jfaud->InitMIDI(NULL)) havemidi = true; } void SoundShutdown(void) { - if (jfaud) delete jfaud; - if (chans) delete [] chans; - jfaud = NULL; - chans = NULL; - havewave = havemidi = false; + if (jfaud) delete jfaud; + if (chans) delete [] chans; + jfaud = NULL; + chans = NULL; + havewave = havemidi = false; } void MusicStartup(void) @@ -245,391 +246,357 @@ void MusicShutdown(void) void AudioUpdate(void) { - int i; + int i; - if (!jfaud) return; - if (havewave) - for (i=NumVoices-1; i>=0; i--) { - if (chans[i].chan && !jfaud->IsValidSound(chans[i].chan)) - chans[i].chan = NULL; - } - jfaud->Update(false); + if (!jfaud) return; + if (havewave) + for (i=NumVoices-1; i>=0; i--) { + if (chans[i].chan && !jfaud->IsValidSound(chans[i].chan)) + chans[i].chan = NULL; + } + jfaud->Update(false); // don't age the cache here } static char menunum = 0; void intomenusounds(void) { - short i; - short menusnds[] = { - LASERTRIP_EXPLODE, DUKE_GRUNT, DUKE_LAND_HURT, - CHAINGUN_FIRE, SQUISHED, KICK_HIT, - PISTOL_RICOCHET, PISTOL_BODYHIT, PISTOL_FIRE, - SHOTGUN_FIRE, BOS1_WALK, RPG_EXPLODE, - PIPEBOMB_BOUNCE, PIPEBOMB_EXPLODE, NITEVISION_ONOFF, - RPG_SHOOT, SELECT_WEAPON - }; - sound(menusnds[menunum++]); - menunum %= sizeof(menusnds)/sizeof(menusnds[0]); + short i; + short menusnds[] = { + LASERTRIP_EXPLODE, DUKE_GRUNT, DUKE_LAND_HURT, + CHAINGUN_FIRE, SQUISHED, KICK_HIT, + PISTOL_RICOCHET, PISTOL_BODYHIT, PISTOL_FIRE, + SHOTGUN_FIRE, BOS1_WALK, RPG_EXPLODE, + PIPEBOMB_BOUNCE, PIPEBOMB_EXPLODE, NITEVISION_ONOFF, + RPG_SHOOT, SELECT_WEAPON + }; + sound(menusnds[menunum++]); + menunum %= sizeof(menusnds)/sizeof(menusnds[0]); } void playmusic(char *fn) { - char dafn[BMAX_PATH], *dotpos; - int i; - const char *extns[] = { ".ogg",".mp3",".mid", NULL }; + char dafn[BMAX_PATH], *dotpos; + int i; + const char *extns[] = { ".ogg",".mp3",".mid", NULL }; - if (!MusicToggle) return; - if (!jfaud) return; + if (!MusicToggle) return; + if (!jfaud) return; - dotpos = Bstrrchr(fn,'.'); - if (dotpos && Bstrcasecmp(dotpos,".mid")) { - // has extension but isn't midi - jfaud->PlayMusic(fn, NULL); - } else { - Bstrcpy(dafn,fn); - dotpos = Bstrrchr(dafn,'.'); - if (!dotpos) dotpos = dafn+strlen(dafn); + dotpos = Bstrrchr(fn,'.'); + if (dotpos && Bstrcasecmp(dotpos,".mid")) { + // has extension but isn't midi + jfaud->PlayMusic(fn, NULL); + } else { + Bstrcpy(dafn,fn); + dotpos = Bstrrchr(dafn,'.'); + if (!dotpos) dotpos = dafn+strlen(dafn); - for (i=0; extns[i]; i++) { - Bstrcpy(dotpos, extns[i]); - if (jfaud->PlayMusic(dafn, NULL)) return; - } - } + for (i=0; extns[i]; i++) { + Bstrcpy(dotpos, extns[i]); + if (jfaud->PlayMusic(dafn, NULL)) return; + } + } } char loadsound(unsigned short num) { return 1; } int isspritemakingsound(short i, int num) // if num<0, check if making any sound at all { - int j,n=0; - - if (!jfaud || !havewave) return 0; - for (j=NumVoices-1; j>=0; j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; - if (chans[j].owner == i) - if (num < 0 || chans[j].soundnum == num) n++; - } - return n; + int j,n=0; + + if (!jfaud || !havewave) return 0; + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; + if (chans[j].owner == i) + if (num < 0 || chans[j].soundnum == num) n++; + } + return n; } -int issoundplaying(short i, int num) +int issoundplaying(int num) { - int j,n=0; - - if (!jfaud || !havewave) return 0; - for (j=NumVoices-1; j>=0; j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; - if (chans[j].soundnum == num) n++; - } - - return n; + int j,n=0; + + if (!jfaud || !havewave) return 0; + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; + if (chans[j].soundnum == num) n++; + } + + return n; } int xyzsound(short num, short i, long x, long y, long z) { - JFAudMixerChannel *chan; - int r, global = 0; - float gain = 1.0, pitch = 1.0; - int sndist; + JFAudMixerChannel *chan; + int r, global = 0; + float gain = 1.0, pitch = 1.0; - if (!jfaud || !havewave || - num >= NUM_SOUNDS || - ((soundm[num] & SOUNDM_PARENT) && ud.lockout) || // parental mode - SoundToggle == 0 || - (ps[myconnectindex].timebeforeexit > 0 && ps[myconnectindex].timebeforeexit <= 26*3) || - (ps[myconnectindex].gm & MODE_MENU) - ) return -1; + if (!jfaud || !havewave || + num >= NUM_SOUNDS || + ((soundm[num] & SOUNDM_PARENT) && ud.lockout) || // parental mode + SoundToggle == 0 || + (ps[myconnectindex].timebeforeexit > 0 && ps[myconnectindex].timebeforeexit <= 26*3) || + (ps[myconnectindex].gm & MODE_MENU) + ) return -1; - if (soundm[num] & SOUNDM_PLAYER) { - sound(num); - return 0; - } + if (soundm[num] & SOUNDM_PLAYER) { + sound(num); + return 0; + } + + if (soundm[num] & SOUNDM_DUKE) { + // Duke speech, one at a time only + int j; + + if (VoiceToggle == 0 || + (ud.multimode > 1 && PN == APLAYER && sprite[i].yvel != screenpeek && ud.coop != 1) + ) return -1; - if (soundm[num] & SOUNDM_DUKE) { - // Duke speech, one at a time only - int j; + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || chans[j].owner < 0) continue; + if (soundm[ chans[j].soundnum ] & SOUNDM_DUKE) return -1; + } + } + + // XXX: here goes musicandsfx ranging. This will change the refdist. + + { + int ps = soundps[num], pe = soundpe[num], cx; + cx = labs(pe-ps); + if (cx) { + if (ps < pe) pitch = translatepitch(ps + rand()%cx); + else pitch = translatepitch(pe + rand()%cx); + } else pitch = translatepitch(ps); + } + + //gain += soundvo[num]; + if (PN != MUSICANDSFX && + !cansee(ps[screenpeek].oposx,ps[screenpeek].oposy,ps[screenpeek].oposz-(24<<8), + ps[screenpeek].cursectnum,SX,SY,SZ-(24<<8),SECT) ) + gain *= 1.0/32.0; + + switch(num) + { + case PIPEBOMB_EXPLODE: + case LASERTRIP_EXPLODE: + case RPG_EXPLODE: + gain = 1.0; + global = 1; + if (sector[ps[screenpeek].cursectnum].lotag == 2) pitch -= translatepitch(1024); + break; + default: + if(sector[ps[screenpeek].cursectnum].lotag == 2 && (soundm[num]&SOUNDM_DUKE) == 0) + pitch = translatepitch(-768); + //if( sndist > 31444 && PN != MUSICANDSFX) + // return -1; + break; + } - if (VoiceToggle == 0 || - (ud.multimode > 1 && PN == APLAYER && sprite[i].yvel != screenpeek && ud.coop != 1) - ) return -1; - - for (j=NumVoices-1; j>=0; j--) { - if (!chans[j].chan || chans[j].owner < 0) continue; - if (soundm[ chans[j].soundnum ] & SOUNDM_DUKE) return -1; - } - } - - // XXX: here goes musicandsfx ranging. This will change the refdist. - - { - int ps = soundps[num], pe = soundpe[num], cx; - cx = klabs(pe-ps); - if (cx) { - if (ps < pe) pitch = translatepitch(ps + rand()%cx); - else pitch = translatepitch(pe + rand()%cx); - } else pitch = translatepitch(ps); - } - - sndist = FindDistance3D((ps[screenpeek].oposx-SX),(ps[screenpeek].oposy-SY),(ps[screenpeek].oposz-SZ)>>4); - - if( i >= 0 && (soundm[num]&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9 ) - sndist = divscale14(sndist,(SHT+1)); - - sndist += soundvo[num]; - if(sndist < 0) sndist = 0; - - //gain += soundvo[num]; - if (sndist && PN != MUSICANDSFX && - !cansee(ps[screenpeek].oposx,ps[screenpeek].oposy,ps[screenpeek].oposz-(24<<8), - ps[screenpeek].cursectnum,SX,SY,SZ-(24<<8),SECT) ) - gain *= 0.4; - - switch(num) - { - case PIPEBOMB_EXPLODE: - case LASERTRIP_EXPLODE: - case RPG_EXPLODE: - gain = 1.0; - global = 1; - if (sector[ps[screenpeek].cursectnum].lotag == 2) pitch -= translatepitch(1024); - break; - default: - if(sector[ps[screenpeek].cursectnum].lotag == 2 && (soundm[num]&SOUNDM_DUKE) == 0) - pitch = translatepitch(-768); - //if( sndist > 31444 && PN != MUSICANDSFX) - // return -1; - break; - } - if(ps[screenpeek].sound_pitch) - pitch = translatepitch(ps[screenpeek].sound_pitch); - /* - // XXX: this is shit - if( Sound[num].num > 0 && PN != MUSICANDSFX ) - { - if( SoundOwner[num][0].i == i ) stopsound(num); - else if( Sound[num].num > 1 ) stopsound(num); - else if( badguy(&sprite[i]) && sprite[i].extra <= 0 ) stopsound(num); - } - */ - - chan = jfaud->PlaySound(sounds[num], NULL, soundpr[num]); - if (!chan) return -1; - - if(ps[screenpeek].sound_pitch) - pitch = translatepitch(ps[screenpeek].sound_pitch); - - chan->SetGain(gain*(FXVolume/252.0)); - chan->SetPitch(pitch); - chan->SetLoop(soundm[num] & SOUNDM_LOOP); - if (soundm[num] & SOUNDM_GLOBAL) global = 1; - chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); - - if (PN == APLAYER && sprite[i].yvel == screenpeek) { - chan->SetRolloff(0.0); - chan->SetFollowListener(true); - chan->SetPosition(0.0, 0.0, 0.0); - } else { - chan->SetRolloff(global ? 0.0 : 0.2); - chan->SetFollowListener(false); - chan->SetPosition((float)x/UNITSPERMETRE, (float)(-z>>4)/UNITSPERMETRE, (float)y/UNITSPERMETRE); - } - - r = keephandle(chan, num, i); - if (r >= 0) chan->SetStopCallback(stopcallback, r); - chan->Play(); - - return 0; +/* + // XXX: this is shit + if( Sound[num].num > 0 && PN != MUSICANDSFX ) + { + if( SoundOwner[num][0].i == i ) stopsound(num); + else if( Sound[num].num > 1 ) stopsound(num); + else if( badguy(&sprite[i]) && sprite[i].extra <= 0 ) stopsound(num); + } +*/ + + chan = jfaud->PlaySound(sounds[num], NULL, soundpr[num]); + if (!chan) return -1; + + chan->SetGain(gain); + chan->SetPitch(pitch); + chan->SetLoop(soundm[num] & SOUNDM_LOOP); + if (soundm[num] & SOUNDM_GLOBAL) global = 1; + chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); + + if (PN == APLAYER && sprite[i].yvel == screenpeek) { + chan->SetRolloff(0.0); + chan->SetFollowListener(true); + chan->SetPosition(0.0, 0.0, 0.0); + } else { + chan->SetRolloff(global ? 0.0 : 1.0); + chan->SetFollowListener(false); + chan->SetPosition((float)x/UNITSPERMETRE, (float)(-z>>4)/UNITSPERMETRE, (float)y/UNITSPERMETRE); + } + + r = keephandle(chan, num, i); + if (r >= 0) chan->SetStopCallback(stopcallback, r); + chan->Play(); + + return 0; } void sound(short num) { - JFAudMixerChannel *chan; - int r; - float pitch = 1.0; + JFAudMixerChannel *chan; + int r; + float pitch = 1.0; - if (!jfaud || !havewave || - num >= NUM_SOUNDS || - SoundToggle == 0 || - ((soundm[num] & SOUNDM_DUKE) && VoiceToggle == 0) || - ((soundm[num] & SOUNDM_PARENT) && ud.lockout) // parental mode - ) return; + if (!jfaud || !havewave || + num >= NUM_SOUNDS || + SoundToggle == 0 || + ((soundm[num] & SOUNDM_DUKE) && VoiceToggle == 0) || + ((soundm[num] & SOUNDM_PARENT) && ud.lockout) // parental mode + ) return; - { - int ps = soundps[num], pe = soundpe[num], cx; - cx = klabs(pe-ps); - if (cx) { - if (ps < pe) pitch = translatepitch(ps + rand()%cx); - else pitch = translatepitch(pe + rand()%cx); - } else pitch = translatepitch(ps); - } + { + int ps = soundps[num], pe = soundpe[num], cx; + cx = labs(pe-ps); + if (cx) { + if (ps < pe) pitch = translatepitch(ps + rand()%cx); + else pitch = translatepitch(pe + rand()%cx); + } else pitch = translatepitch(ps); + } + + chan = jfaud->PlaySound(sounds[num], NULL, soundpr[num]); + if (!chan) return; - if(ps[screenpeek].sound_pitch) - pitch = translatepitch(ps[screenpeek].sound_pitch); + chan->SetGain(1.0); + chan->SetPitch(pitch); + chan->SetLoop(soundm[num] & SOUNDM_LOOP); + chan->SetRolloff(0.0); + chan->SetFollowListener(true); + chan->SetPosition(0.0, 0.0, 0.0); + chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); - chan = jfaud->PlaySound(sounds[num], NULL, soundpr[num]); - if (!chan) return; - - if(ps[screenpeek].sound_pitch) - pitch = translatepitch(ps[screenpeek].sound_pitch); - - chan->SetGain(FXVolume/252.0); - chan->SetPitch(pitch); - chan->SetLoop(soundm[num] & SOUNDM_LOOP); - chan->SetRolloff(0.0); - chan->SetFollowListener(true); - chan->SetPosition(0.0, 0.0, 0.0); - chan->SetFilter((soundm[num]&SOUNDM_NICE) ? JFAudMixerChannel::Filter4Point : JFAudMixerChannel::FilterNearest); - - r = keephandle(chan, num, -1); - if (r >= 0) chan->SetStopCallback(stopcallback, r); - chan->Play(); + r = keephandle(chan, num, -1); + if (r >= 0) chan->SetStopCallback(stopcallback, r); + chan->Play(); } int spritesound(unsigned short num, short i) { - if (num >= NUM_SOUNDS) return -1; - return xyzsound(num,i,SX,SY,SZ); + if (num >= NUM_SOUNDS) return -1; + return xyzsound(num,i,SX,SY,SZ); } void stopsound(short num) { - int j; - - if (!jfaud || !havewave) return; - for (j=NumVoices-1;j>=0;j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].soundnum != num) continue; - - jfaud->FreeSound(chans[j].chan); - chans[j].chan = NULL; - chans[j].owner = -1; - } + int j; + + if (!jfaud || !havewave) return; + for (j=NumVoices-1;j>=0;j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].soundnum != num) continue; + + jfaud->FreeSound(chans[j].chan); + chans[j].chan = NULL; + chans[j].owner = -1; + } } void stopspritesound(short num, short i) { - int j; - - if (!jfaud || !havewave) return; - for (j=NumVoices-1;j>=0;j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner != i || chans[j].soundnum != num) continue; - - jfaud->FreeSound(chans[j].chan); - chans[j].chan = NULL; - chans[j].owner = -1; - return; - } + int j; + + if (!jfaud || !havewave) return; + for (j=NumVoices-1;j>=0;j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner != i || chans[j].soundnum != num) continue; + + jfaud->FreeSound(chans[j].chan); + chans[j].chan = NULL; + chans[j].owner = -1; + return; + } } void stopenvsound(short num, short i) { - int j; + int j; + + if (!jfaud || !havewave) return; + for (j=NumVoices-1;j>=0;j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner != i) continue; - if (!jfaud || !havewave) return; - for (j=NumVoices-1;j>=0;j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner != i) continue; - - jfaud->FreeSound(chans[j].chan); - chans[j].chan = NULL; - chans[j].owner = -1; - } + jfaud->FreeSound(chans[j].chan); + chans[j].chan = NULL; + chans[j].owner = -1; + } } void pan3dsound(void) { - JFAudMixer *mix; - int j, global; - short i; - long cx, cy, cz, sx,sy,sz; - short ca,cs; - float gain; + JFAudMixer *mix; + int j, global; + short i; + long cx, cy, cz, sx,sy,sz; + short ca,cs; + float gain; - numenvsnds = 0; - if (!jfaud || !havewave) return; - mix = jfaud->GetWave(); - if (!mix) return; + numenvsnds = 0; + if (!jfaud || !havewave) return; + mix = jfaud->GetWave(); + if (!mix) return; - jfaud->AgeCache(); + jfaud->AgeCache(); + + if(ud.camerasprite == -1) { + cx = ps[screenpeek].oposx; + cy = ps[screenpeek].oposy; + cz = ps[screenpeek].oposz; + cs = ps[screenpeek].cursectnum; + ca = ps[screenpeek].ang+ps[screenpeek].look_ang; + } else { + cx = sprite[ud.camerasprite].x; + cy = sprite[ud.camerasprite].y; + cz = sprite[ud.camerasprite].z; + cs = sprite[ud.camerasprite].sectnum; + ca = sprite[ud.camerasprite].ang; + } - if(ud.camerasprite == -1) { - cx = ps[screenpeek].oposx; - cy = ps[screenpeek].oposy; - cz = ps[screenpeek].oposz; - cs = ps[screenpeek].cursectnum; - ca = ps[screenpeek].ang+ps[screenpeek].look_ang; - } else { - cx = sprite[ud.camerasprite].x; - cy = sprite[ud.camerasprite].y; - cz = sprite[ud.camerasprite].z; - cs = sprite[ud.camerasprite].sectnum; - ca = sprite[ud.camerasprite].ang; - } + mix->SetListenerPosition((float)cx/UNITSPERMETRE, (float)(-cz>>4)/UNITSPERMETRE, (float)cy/UNITSPERMETRE); + mix->SetListenerOrientation((float)sintable[(ca+512)&2047]/16384.0, 0.0, (float)sintable[ca&2047]/16384.0, + 0.0, 1.0, 0.0); + + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner < 0) continue; - mix->SetListenerPosition((float)cx/UNITSPERMETRE, (float)(-cz>>4)/UNITSPERMETRE, (float)cy/UNITSPERMETRE); - mix->SetListenerOrientation((float)sintable[(ca+512)&2047]/16384.0, 0.0, (float)sintable[ca&2047]/16384.0, - 0.0, 1.0, 0.0); + global = 0; + gain = 1.0; + i = chans[j].owner; - for (j=NumVoices-1; j>=0; j--) { - int sndist; - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan) || chans[j].owner < 0) continue; + sx = sprite[i].x; + sy = sprite[i].y; + sz = sprite[i].z; - global = 0; - gain = 1.0; - i = chans[j].owner; - - sx = sprite[i].x; - sy = sprite[i].y; - sz = sprite[i].z; - - if( PN == APLAYER && sprite[i].yvel == screenpeek) - { - sndist = 0; - } - else - { - sndist = FindDistance3D((cx-sx),(cy-sy),(cz-sz)>>4); - if( i >= 0 && (soundm[j]&16) == 0 && PN == MUSICANDSFX && SLT < 999 && (sector[SECT].lotag&0xff) < 9 ) - sndist = divscale14(sndist,(SHT+1)); - } - - sndist += soundvo[j]; - if(sndist < 0) sndist = 0; - - //gain += soundvo[num]; - if (sndist && PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,sx,sy,sz-(24<<8),SECT) ) - gain *= 0.4; - - if(PN == MUSICANDSFX && SLT < 999) numenvsnds++; - if( soundm[ chans[j].soundnum ]&SOUNDM_GLOBAL ) global = 1; - - switch(chans[j].soundnum) { - case PIPEBOMB_EXPLODE: - case LASERTRIP_EXPLODE: - case RPG_EXPLODE: - gain = 1.0; - global = 1; - break; - default: - //if( sndist > 31444 && PN != MUSICANDSFX) { - // stopsound(j); - // continue; - //} - break; - } - - // A sound may move from player-relative 3D if the viewpoint shifts from the player - // through a viewscreen or viewpoint switching - chans[j].chan->SetGain(gain*(FXVolume/252.0)); - if (PN == APLAYER && sprite[i].yvel == screenpeek) { - chans[j].chan->SetRolloff(0.0); - chans[j].chan->SetFollowListener(true); - chans[j].chan->SetPosition(0.0, 0.0, 0.0); - } else { - chans[j].chan->SetRolloff(global ? 0.0 : 0.1); - chans[j].chan->SetFollowListener(false); - chans[j].chan->SetPosition((float)sx/UNITSPERMETRE, (float)(-sz>>4)/UNITSPERMETRE, (float)sy/UNITSPERMETRE); - } - } + //gain += soundvo[num]; + if (PN != MUSICANDSFX && !cansee(cx,cy,cz-(24<<8),cs,sx,sy,sz-(24<<8),SECT) ) + gain *= 1.0/32.0; + + if(PN == MUSICANDSFX && SLT < 999) numenvsnds++; + if( soundm[ chans[j].soundnum ]&SOUNDM_GLOBAL ) global = 1; + + switch(chans[j].soundnum) { + case PIPEBOMB_EXPLODE: + case LASERTRIP_EXPLODE: + case RPG_EXPLODE: + gain = 1.0; + global = 1; + break; + default: + //if( sndist > 31444 && PN != MUSICANDSFX) { + // stopsound(j); + // continue; + //} + break; + } + + // A sound may move from player-relative 3D if the viewpoint shifts from the player + // through a viewscreen or viewpoint switching + chans[j].chan->SetGain(gain); + if (PN == APLAYER && sprite[i].yvel == screenpeek) { + chans[j].chan->SetRolloff(0.0); + chans[j].chan->SetFollowListener(true); + chans[j].chan->SetPosition(0.0, 0.0, 0.0); + } else { + chans[j].chan->SetRolloff(global ? 0.0 : 1.0); + chans[j].chan->SetFollowListener(false); + chans[j].chan->SetPosition((float)sx/UNITSPERMETRE, (float)(-sz>>4)/UNITSPERMETRE, (float)sy/UNITSPERMETRE); + } + } } void clearsoundlocks(void) @@ -654,49 +621,49 @@ void FX_SetReverbDelay( int delay ) int FX_VoiceAvailable( int priority ) { - int j; - - if (!jfaud) return 0; - for (j=NumVoices-1;j>=0;j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) return 1; - } - return 0; + int j; + + if (!jfaud) return 0; + for (j=NumVoices-1;j>=0;j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) return 1; + } + return 0; } int FX_PlayVOC3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ) + int priority, unsigned long callbackval ) { - printf("FX_PlayVOC3D()\n"); - return 0; + printf("FX_PlayVOC3D()\n"); + return 0; } int FX_PlayWAV3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ) + int priority, unsigned long callbackval ) { - printf("FX_PlayWAV3D()\n"); - return 0; + printf("FX_PlayWAV3D()\n"); + return 0; } int FX_StopSound( int handle ) { - printf("FX_StopSound()\n"); - return 0; + printf("FX_StopSound()\n"); + return 0; } int FX_StopAllSounds( void ) { - int j; + int j; + + if (!jfaud || !havewave) return 0; + for (j=NumVoices-1; j>=0; j--) { + if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; - if (!jfaud || !havewave) return 0; - for (j=NumVoices-1; j>=0; j--) { - if (!chans[j].chan || !jfaud->IsValidSound(chans[j].chan)) continue; + jfaud->FreeSound(chans[j].chan); + chans[j].chan = NULL; + chans[j].owner = -1; + } - jfaud->FreeSound(chans[j].chan); - chans[j].chan = NULL; - chans[j].owner = -1; - } - - return 0; + return 0; } void MUSIC_SetVolume( int volume ) @@ -705,18 +672,18 @@ void MUSIC_SetVolume( int volume ) void MUSIC_Pause( void ) { - if (jfaud) jfaud->PauseMusic(true); + if (jfaud) jfaud->PauseMusic(true); } void MUSIC_Continue( void ) { - if (jfaud) jfaud->PauseMusic(false); + if (jfaud) jfaud->PauseMusic(false); } int MUSIC_StopSong( void ) { - if (jfaud) jfaud->StopMusic(); - return 0; + if (jfaud) jfaud->StopMusic(); + return 0; } void MUSIC_RegisterTimbreBank( unsigned char *timbres ) diff --git a/polymer/eduke32/watcomhax/cerrno b/polymer/eduke32/watcomhax/cerrno new file mode 100755 index 000000000..edcc29d2c --- /dev/null +++ b/polymer/eduke32/watcomhax/cerrno @@ -0,0 +1 @@ +#include diff --git a/polymer/eduke32/watcomhax/cmath b/polymer/eduke32/watcomhax/cmath new file mode 100755 index 000000000..2911680c7 --- /dev/null +++ b/polymer/eduke32/watcomhax/cmath @@ -0,0 +1,2 @@ +#include +#define M_PI 3.14159265358979323846 diff --git a/polymer/eduke32/watcomhax/cstdarg b/polymer/eduke32/watcomhax/cstdarg new file mode 100755 index 000000000..8942a2e77 --- /dev/null +++ b/polymer/eduke32/watcomhax/cstdarg @@ -0,0 +1 @@ +#include diff --git a/polymer/eduke32/watcomhax/cstdio b/polymer/eduke32/watcomhax/cstdio new file mode 100755 index 000000000..bfcdbf0e9 --- /dev/null +++ b/polymer/eduke32/watcomhax/cstdio @@ -0,0 +1 @@ +#include diff --git a/polymer/eduke32/watcomhax/cstdlib b/polymer/eduke32/watcomhax/cstdlib new file mode 100755 index 000000000..9ada8e59c --- /dev/null +++ b/polymer/eduke32/watcomhax/cstdlib @@ -0,0 +1 @@ +#include diff --git a/polymer/eduke32/watcomhax/cstring b/polymer/eduke32/watcomhax/cstring new file mode 100755 index 000000000..8e69c1fc0 --- /dev/null +++ b/polymer/eduke32/watcomhax/cstring @@ -0,0 +1 @@ +#include diff --git a/polymer/eduke32/watcomhax/ctime b/polymer/eduke32/watcomhax/ctime new file mode 100755 index 000000000..23b073712 --- /dev/null +++ b/polymer/eduke32/watcomhax/ctime @@ -0,0 +1 @@ +#include