?? game.c
字號:
/* * "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 */#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <string.h>#include <stdlib.h>#include <stdio.h>#ifdef USE_PERL#include "buildperl.h"#endif#include "platform.h"#include "cache1d.h"#include "pragmas.h"#include "display.h"#include "build.h"#include "engine.h"#include "names.h"#define TIMERINTSPERSECOND PLATFORM_TIMER_HZ #define MOVESPERSECOND 40#define TICSPERFRAME 3#define MOVEFIFOSIZ 256#define EYEHEIGHT (32<<8) /* Normally (32<<8), (51<<8) to make mirrors happy *//* KenBuild-specific networking functions. */void initmultiplayers(char damultioption, char dacomrateoption, char dapriority);void uninitmultiplayers(void);void sendlogon(void);void sendlogoff(void);short getpacket(short *otherconnectindex, char *bufptr);void sendpacket(short otherconnectindex, unsigned char *bufptr, short messleng);int getoutputcirclesize(void);/* * Not interested in implementing these sound functions in a * platform-independent manner for KenBuild. Anyone? --ryan. */#if (defined PLATFORM_DOS)void initsb(char dadigistat, char damusistat, long dasamplerate, char danumspeakers, char dabytespersample, char daintspersec, char daquality);void uninitsb(void);int loadsong(char *filename);void musicon(void);void musicoff(void);void wsayfollow(char *dafilename, long dafreq, long davol, long *daxplc, long *dayplc, char followstat);void wsay(char *dafilename, long dafreq, long volume1, long volume2);void preparesndbuf(void);void setears(long daposx, long daposy, long daxvect, long dayvect);#else /* stubs for non-DOS platforms... */#ifndef __FILE__#define __FILE__ "game.c"#endif#ifndef __LINE__#define __LINE__ -1#endifstatic int audio_disabled = 0;void initsb(char dadigistat, char damusistat, long dasamplerate, char danumspeakers, char dabytespersample, char daintspersec, char daquality){#if 0 audio_disabled = (SDL_Init(SDL_INIT_AUDIO) == -1); if (audio_disabled) { fprintf(stderr, "BUILDSDL: SDL_Init(SDL_INIT_AUDIO) failed!\n"); fprintf(stderr, "BUILDSDL: SDL_GetError() says \"%s\".\n", SDL_GetError()); fprintf(stderr, "BUILDSDL: We'll continue without sound.\n"); audio_disabled = 1; return; } /* if */#else audio_disabled = 1; fprintf(stderr, "%s, line %d; initsb(): STUB.\n", __FILE__, __LINE__);#endif} /* initsb */void uninitsb(void){ fprintf(stderr, "%s, line %d; uninitsb(): STUB.\n", __FILE__, __LINE__);} /* uninitsb */int loadsong(char *filename){ fprintf(stderr, "%s, line %d; loadsong(): STUB.\n", __FILE__, __LINE__); return 0;} /* loadsong */void musicon(void){ fprintf(stderr, "%s, line %d; musicon(): STUB.\n", __FILE__, __LINE__);} /* musicon */void musicoff(void){ fprintf(stderr, "%s, line %d; musicoff(): STUB.\n", __FILE__, __LINE__);} /* musicoff */void wsayfollow(char *dafilename, long dafreq, long davol, long *daxplc, long *dayplc, char followstat){ fprintf(stderr, "%s, line %d; wsayfollow(): STUB.\n", __FILE__, __LINE__);} /* wsayfollow */void wsay(char *dafilename, long dafreq, long volume1, long volume2){ fprintf(stderr, "%s, line %d; wsay(): STUB.\n", __FILE__, __LINE__);} /* wsay */void preparesndbuf(void){ fprintf(stderr,"%s, line %d; preparesndbuf(): STUB.\n", __FILE__, __LINE__);} /* preparesndbuf */void setears(long daposx, long daposy, long daxvect, long dayvect){/* fprintf(stderr, "%s, line %d; setears(): STUB.\n", __FILE__, __LINE__); */} /* setears */#endif /* !defined PLATFORM_DOS *//*************************************************************************** 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;void __interrupt __far timerhandler(void);#define KEYFIFOSIZ 64void __interrupt __far keyhandler(void);volatile char keystatus[256], keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend;volatile char readch, oldreadch, extended, keytemp;static long fvel, svel, avel;static long fvel2, svel2, avel2;#define NUMOPTIONS 8#define NUMKEYS 19static long vesares[13][2] = { {320,200},{360,200},{320,240},{360,240},{320,400}, {360,400},{640,350},{640,400},{640,480},{800,600}, {1024,768},{1280,1024},{1600,1200}};static char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0};static char keys[NUMKEYS] ={ 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, 0x1e,0x2c,0xd1,0xc9,0x33,0x34, 0x9c,0x1c,0xd,0xc,0xf,};static long digihz[7] = {6000,8000,11025,16000,22050,32000,44100};static char frame2draw[MAXPLAYERS];static long frameskipcnt[MAXPLAYERS];#define LAVASIZ 128#define LAVALOGSIZ 7#define LAVAMAXDROPS 32static 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 short numplayers, myconnectindex;extern short 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 13static 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], _sync[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 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 1024static long numinterpolations = 0, startofdynamicinterpolations = 0;static long oldipos[MAXINTERPOLATIONS];static long bakipos[MAXINTERPOLATIONS];static long *curipos[MAXINTERPOLATIONS];extern long cachecount, transarea;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, brightness = 0;static short screensize, screensizeflag = 0;static short neartagsector, neartagwall, neartagsprite;static long lockclock, neartagdist, neartaghitdist;extern long frameplace, pageoffset, ydim16;static long globhiz, globloz, globhihit, globlohit;/* volatile long stereomode = 0; */extern long stereowidth, stereopixelwidth;extern volatile long activepage; /* Over the shoulder mode variables */static long cameradist = -1, cameraang = 0, cameraclock = 0; /* Board animation variables */#define MAXMIRRORS 64static 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,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -