Subversion Repositories eduke32

Rev

Rev 5204 | Rev 5345 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4555 hendricks2 1
// Ken Silverman's official web site: "http://www.advsys.net/ken"
2
// See the included license file "BUILDLIC.TXT" for license info.
3
//
4
// This file has been modified from Ken Silverman's original release
5
// by Jonathon Fowler (jf@jonof.id.au)
6
 
7
#include "compat.h"
8
#include "build.h"
9
#include "names.h"
10
#include "pragmas.h"
11
#include "cache1d.h"
12
#include "game.h"
13
#include "osd.h"
14
#include "mmulti.h"
15
#include "common.h"
16
 
17
#include "renderlayer.h"
18
 
19
#include "common_game.h"
20
 
5327 hendricks2 21
const char *AppProperName = "KenBuild";
22
const char *AppTechnicalName = "testgame";
4555 hendricks2 23
 
4562 hendricks2 24
#define SETUPFILENAME "testgame.cfg"
25
char setupfilename[BMAX_PATH] = SETUPFILENAME;
26
 
4555 hendricks2 27
#define TIMERINTSPERSECOND 140 //280
28
#define MOVESPERSECOND 40
29
#define TICSPERFRAME 3
30
#define MOVEFIFOSIZ 256
31
#define EYEHEIGHT (32<<8)   //Normally (32<<8), (51<<8) to make mirrors happy
32
 
33
#define TILE_TILT           (MAXTILES-2)
34
 
35
 
36
static int32_t setsprite_eyeheight(int16_t spritenum, const vec3_t *pos) ATTRIBUTE((nonnull(2)));
37
static int32_t setsprite_eyeheight(int16_t spritenum, const vec3_t *pos)
38
{
39
    vec3_t eyepos = *pos;
40
    eyepos.z += EYEHEIGHT;
41
    return setsprite(spritenum, &eyepos);
42
}
43
 
44
 
45
// declared in sound.c
46
void initsb(char,char,int,char,char,char,char);
47
void uninitsb(void);
48
void setears(int,int,int,int);
49
void wsayfollow(char *,int,int,int *,int *,char);
50
void wsay(char *,int,int,int);
51
void loadwaves(void);
52
void loadsong(char *);
53
void musicon(void);
54
void musicoff(void);
55
void refreshaudio(void);
56
 
57
// declared in config.c
58
int loadsetup(const char *);
59
int writesetup(const char *);
60
 
61
/***************************************************************************
5327 hendricks2 62
    KEN'S TAG DEFINITIONS:      (Please define your own tags for your games)
4555 hendricks2 63
 
64
 sector[?].lotag = 0   Normal sector
65
 sector[?].lotag = 1   If you are on a sector with this tag, then all sectors
5327 hendricks2 66
                       with same hi tag as this are operated.  Once.
4555 hendricks2 67
 sector[?].lotag = 2   Same as sector[?].tag = 1 but this is retriggable.
68
 sector[?].lotag = 3   A really stupid sector that really does nothing now.
69
 sector[?].lotag = 4   A sector where you are put closer to the floor
5327 hendricks2 70
                       (such as the slime in DOOM1.DAT)
4555 hendricks2 71
 sector[?].lotag = 5   A really stupid sector that really does nothing now.
72
 sector[?].lotag = 6   A normal door - instead of pressing D, you tag the
5327 hendricks2 73
                       sector with a 6.  The reason I make you edit doors
74
                       this way is so that can program the doors
75
                       yourself.
4555 hendricks2 76
 sector[?].lotag = 7   A door the goes down to open.
77
 sector[?].lotag = 8   A door that opens horizontally in the middle.
78
 sector[?].lotag = 9   A sliding door that opens vertically in the middle.
5327 hendricks2 79
                       -Example of the advantages of not using BSP tree.
4555 hendricks2 80
 sector[?].lotag = 10  A warping sector with floor and walls that shade.
81
 sector[?].lotag = 11  A sector with all walls that do X-panning.
82
 sector[?].lotag = 12  A sector with walls using the dragging function.
83
 sector[?].lotag = 13  A sector with some swinging doors in it.
84
 sector[?].lotag = 14  A revolving door sector.
85
 sector[?].lotag = 15  A subway track.
86
 sector[?].lotag = 16  A true double-sliding door.
87
 
5327 hendricks2 88
    wall[?].lotag = 0   Normal wall
89
    wall[?].lotag = 1   Y-panning wall
90
    wall[?].lotag = 2   Switch - If you flip it, then all sectors with same hi
91
                        tag as this are operated.
92
    wall[?].lotag = 3   Marked wall to detemine starting dir. (sector tag 12)
93
    wall[?].lotag = 4   Mark on the shorter wall closest to the pivot point
94
                        of a swinging door. (sector tag 13)
95
    wall[?].lotag = 5   Mark where a subway should stop. (sector tag 15)
96
    wall[?].lotag = 6   Mark for true double-sliding doors (sector tag 16)
97
    wall[?].lotag = 7   Water fountain
98
    wall[?].lotag = 8   Bouncy wall!
4555 hendricks2 99
 
100
 sprite[?].lotag = 0   Normal sprite
101
 sprite[?].lotag = 1   If you press space bar on an AL, and the AL is tagged
5327 hendricks2 102
                       with a 1, he will turn evil.
4555 hendricks2 103
 sprite[?].lotag = 2   When this sprite is operated, a bomb is shot at its
5327 hendricks2 104
                       position.
4555 hendricks2 105
 sprite[?].lotag = 3   Rotating sprite.
106
 sprite[?].lotag = 4   Sprite switch.
107
 sprite[?].lotag = 5   Basketball hoop score.
108
 
5327 hendricks2 109
    KEN'S STATUS DEFINITIONS:  (Please define your own statuses for your games)
4555 hendricks2 110
 status = 0            Inactive sprite
111
 status = 1            Active monster sprite
112
 status = 2            Monster that becomes active only when it sees you
113
 status = 3            Smoke on the wall for chainguns
114
 status = 4            Splashing sprites (When you shoot slime)
115
 status = 5            Explosion!
116
 status = 6            Travelling bullet
117
 status = 7            Bomb sprial-out explosion
118
 status = 8            Player!
119
 status = 9            EVILALGRAVE shrinking list
120
 status = 10           EVILAL list
121
 status = 11           Sprite respawning list
122
 status = 12           Sprite which does not respawn (Andy's addition)
123
 status = MAXSTATUS    Non-existent sprite (this will be true for your
5327 hendricks2 124
                       code also)
4555 hendricks2 125
**************************************************************************/
126
 
127
typedef struct
128
{
5327 hendricks2 129
    signed char fvel, svel, avel;
130
    short bits;
4555 hendricks2 131
} input;
132
 
133
static int screentilt = 0, oscreentilt = 0;
134
 
135
 
136
static int fvel, svel, avel;
137
static int fvel2, svel2, avel2;
138
 
139
#define NUMOPTIONS 8
140
#define NUMGAMEKEYS 19
141
char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0};
142
unsigned char keys[NUMGAMEKEYS] =
143
{
5327 hendricks2 144
    0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39,
145
    0x1e,0x2c,0xd1,0xc9,0x33,0x34,
146
    0x9c,0x1c,0xd,0xc,0xf
4555 hendricks2 147
};
5327 hendricks2 148
int xdimgame = 320, ydimgame = 200, bppgame = 8, xdim2d = 640, ydim2d = 480;    // JBF 20050318: config.c expects to find these
4555 hendricks2 149
int forcesetup = 1;
150
 
151
static int digihz[8] = {6000,8000,11025,16000,22050,32000,44100,48000};
152
 
153
static char frame2draw[MAXPLAYERS];
154
static int frameskipcnt[MAXPLAYERS];
155
 
156
#define LAVASIZ 128
157
#define LAVALOGSIZ 7
158
#define LAVAMAXDROPS 32
159
static char lavabakpic[(LAVASIZ+4)*(LAVASIZ+4)], lavainc[LAVASIZ];
160
static int lavanumdrops, lavanumframes;
161
static int lavadropx[LAVAMAXDROPS], lavadropy[LAVAMAXDROPS];
162
static int lavadropsiz[LAVAMAXDROPS], lavadropsizlookup[LAVAMAXDROPS];
163
static int lavaradx[24][96], lavarady[24][96], lavaradcnt[32];
164
 
5327 hendricks2 165
//Shared player variables
4555 hendricks2 166
static vec3_t pos[MAXPLAYERS];
167
static int horiz[MAXPLAYERS], zoom[MAXPLAYERS], hvel[MAXPLAYERS];
168
static short ang[MAXPLAYERS], cursectnum[MAXPLAYERS], ocursectnum[MAXPLAYERS];
169
static short playersprite[MAXPLAYERS], deaths[MAXPLAYERS];
170
static int lastchaingun[MAXPLAYERS];
171
static int health[MAXPLAYERS], flytime[MAXPLAYERS];
172
static short oflags[MAXPLAYERS];
173
static short numbombs[MAXPLAYERS];
174
static short numgrabbers[MAXPLAYERS];   // Andy did this
175
static short nummissiles[MAXPLAYERS];   // Andy did this
176
static char dimensionmode[MAXPLAYERS];
177
static char revolvedoorstat[MAXPLAYERS];
178
static short revolvedoorang[MAXPLAYERS], revolvedoorrotang[MAXPLAYERS];
179
static int revolvedoorx[MAXPLAYERS], revolvedoory[MAXPLAYERS];
180
 
181
static int nummoves;
182
// Bug: NUMSTATS used to be equal to the greatest tag number,
183
// so that the last statrate[] entry was random memory junk
184
// because stats 0-NUMSTATS required NUMSTATS+1 bytes.   -Andy
185
#define NUMSTATS 13
186
static signed char statrate[NUMSTATS] = {-1,0,-1,0,0,0,1,3,0,3,15,-1,-1};
187
 
5327 hendricks2 188
//Input structures
4555 hendricks2 189
static char networkmode;     //0 is 2(n-1) mode, 1 is n(n-1) mode
190
static int locselectedgun, locselectedgun2;
191
static input loc, oloc, loc2;
192
static input ffsync[MAXPLAYERS], osync[MAXPLAYERS], ssync[MAXPLAYERS];
5327 hendricks2 193
//Input faketimerhandler -> movethings fifo
4555 hendricks2 194
static int movefifoplc, movefifoend[MAXPLAYERS];
195
static input baksync[MOVEFIFOSIZ][MAXPLAYERS];
5327 hendricks2 196
//Game recording variables
4555 hendricks2 197
static int reccnt, recstat = 1;
198
static input recsync[16384][2];
199
 
200
//static int myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter = 1;
201
static signed char otherlag[MAXPLAYERS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
202
static int averagelag[MAXPLAYERS] = {512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512};
203
 
204
static int fakemovefifoplc;
205
static vec3_t my, omy;
206
static int myzvel;
207
static int myhoriz, omyhoriz;
208
static short myang, omyang, mycursectnum;
209
static vec3_t mybak[MOVEFIFOSIZ];
210
static int myhorizbak[MOVEFIFOSIZ];
211
static short myangbak[MOVEFIFOSIZ];
212
 
5327 hendricks2 213
//GAME.C sync state variables
4555 hendricks2 214
static char syncstat, syncval[MOVEFIFOSIZ], othersyncval[MOVEFIFOSIZ];
215
static int syncvaltottail, syncvalhead, othersyncvalhead, syncvaltail;
216
 
217
static char detailmode = 0, ready2send = 0;
218
static int ototalclock = 0, gotlastpacketclock = 0, smoothratio;
219
static vec3_t opos[MAXPLAYERS];
220
static int ohoriz[MAXPLAYERS], ozoom[MAXPLAYERS];
221
static short oang[MAXPLAYERS];
222
 
223
static vec3_t osprite[MAXSPRITES];
224
 
225
#define MAXINTERPOLATIONS 1024
226
static int numinterpolations = 0, startofdynamicinterpolations = 0;
227
static int oldipos[MAXINTERPOLATIONS];
228
static int bakipos[MAXINTERPOLATIONS];
229
static int *curipos[MAXINTERPOLATIONS];
230
 
231
// extern int cachecount;
232
 
233
static char playerreadyflag[MAXPLAYERS];
234
 
5327 hendricks2 235
//Miscellaneous variables
4555 hendricks2 236
static unsigned char packbuf[MAXXDIM];
237
static char tempbuf[MAXXDIM];
238
static char boardfilename[BMAX_PATH];
239
static short tempshort[MAXSECTORS];
240
static short screenpeek = 0, oldmousebstatus = 0;
241
short brightness = 0;
242
static short screensize, screensizeflag = 0;
243
static short neartagsector, neartagwall, neartagsprite;
244
static int lockclock, neartagdist, neartaghitdist;
245
extern int pageoffset, ydim16;
246
static int globhiz, globloz, globhihit, globlohit;
247
 
5327 hendricks2 248
//Over the shoulder mode variables
4555 hendricks2 249
static int cameradist = -1, cameraang = 0, cameraclock = 0;
250
 
5327 hendricks2 251
//Board animation variables
4555 hendricks2 252
#define MAXMIRRORS 64
253
static short mirrorwall[MAXMIRRORS], mirrorsector[MAXMIRRORS], mirrorcnt;
254
static short floormirrorsector[64], floormirrorcnt;
255
static short turnspritelist[16], turnspritecnt;
256
static short warpsectorlist[64], warpsectorcnt;
257
static short xpanningsectorlist[16], xpanningsectorcnt;
258
static short ypanningwalllist[64], ypanningwallcnt;
259
static short floorpanninglist[64], floorpanningcnt;
260
static short dragsectorlist[16], dragxdir[16], dragydir[16], dragsectorcnt;
261
static int dragx1[16], dragy1[16], dragx2[16], dragy2[16], dragfloorz[16];
262
static short swingcnt, swingwall[32][5], swingsector[32];
263
static short swingangopen[32], swingangclosed[32], swingangopendir[32];
264
static short swingang[32], swinganginc[32];
265
static int swingx[32][8], swingy[32][8];
266
static short revolvesector[4], revolveang[4], revolvecnt;
267
static int revolvex[4][16], revolvey[4][16];
268
static int revolvepivotx[4], revolvepivoty[4];
269
static short subwaytracksector[4][128], subwaynumsectors[4], subwaytrackcnt;
270
static int subwaystop[4][8], subwaystopcnt[4];
271
static int subwaytrackx1[4], subwaytracky1[4];
272
static int subwaytrackx2[4], subwaytracky2[4];
273
static int subwayx[4], subwaygoalstop[4], subwayvel[4], subwaypausetime[4];
274
static short waterfountainwall[MAXPLAYERS], waterfountaincnt[MAXPLAYERS];
275
static short slimesoundcnt[MAXPLAYERS];
276
 
5327 hendricks2 277
//Variables that let you type messages to other player
4555 hendricks2 278
static char getmessage[162], getmessageleng;
279
static int getmessagetimeoff;
280
static char typemessage[162], typemessageleng = 0, typemode = 0;
281
#if 0
282
static char scantoasc[128] =
283
{
5327 hendricks2 284
    0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0,
285
    'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s',
286
    'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v',
287
    'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0,
288
    0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
289
    '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
290
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
291
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
4555 hendricks2 292
};
293
static char scantoascwithshift[128] =
294
{
5327 hendricks2 295
    0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0,
296
    'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S',
297
    'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V',
298
    'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0,
299
    0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
300
    '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
301
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
302
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
4555 hendricks2 303
};
304
#endif
305
 
5327 hendricks2 306
//These variables are for animating x, y, or z-coordinates of sectors,
307
//walls, or sprites (They are NOT to be used for changing the [].picnum's)
308
//See the setanimation(), and getanimategoal() functions for more details.
4555 hendricks2 309
#define MAXANIMATES 512
310
static int *animateptr[MAXANIMATES], animategoal[MAXANIMATES];
311
static int animatevel[MAXANIMATES], animateacc[MAXANIMATES], animatecnt = 0;
312
 
313
#if defined USE_OPENGL
5327 hendricks2 314
//These parameters are in exact order of sprite structure in BUILD.H
4555 hendricks2 315
#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2,        \
5327 hendricks2 316
                    clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2,     \
317
                    xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \
318
    {                                                                       \
319
        spritetype *spr2;                                                   \
320
        newspriteindex2 = insertsprite(sectnum2,statnum2);                  \
321
        spr2 = &sprite[newspriteindex2];                                    \
322
        spr2->x = x2; spr2->y = y2; spr2->z = z2;                           \
323
        spr2->cstat = cstat2; spr2->shade = shade2;                         \
324
        spr2->pal = pal2; spr2->clipdist = clipdist2;                       \
325
        spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2;                 \
326
        spr2->xoffset = xoffset2; spr2->yoffset = yoffset2;                 \
327
        spr2->picnum = picnum2; spr2->ang = ang2;                           \
328
        spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2;         \
329
        spr2->owner = owner2;                                               \
330
        spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2;   \
331
        copybuf(&spr2->x,&osprite[newspriteindex2].x,3);                    \
332
        show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7));      \
333
        if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7)))                    \
334
            show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7));   \
335
        clearbufbyte(&spriteext[newspriteindex2], sizeof(spriteext_t), 0);  \
336
    }
4555 hendricks2 337
#else
338
#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2,        \
5327 hendricks2 339
                    clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2,     \
340
                    xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \
341
    {                                                                       \
342
        spritetype *spr2;                                                   \
343
        newspriteindex2 = insertsprite(sectnum2,statnum2);                  \
344
        spr2 = &sprite[newspriteindex2];                                    \
345
        spr2->x = x2; spr2->y = y2; spr2->z = z2;                           \
346
        spr2->cstat = cstat2; spr2->shade = shade2;                         \
347
        spr2->pal = pal2; spr2->clipdist = clipdist2;                       \
348
        spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2;                 \
349
        spr2->xoffset = xoffset2; spr2->yoffset = yoffset2;                 \
350
        spr2->picnum = picnum2; spr2->ang = ang2;                           \
351
        spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2;         \
352
        spr2->owner = owner2;                                               \
353
        spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2;   \
354
        copybuf(&spr2->x,&osprite[newspriteindex2].x,3);                    \
355
        show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7));      \
356
        if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7)))                    \
357
            show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7));   \
358
    }
4555 hendricks2 359
#endif
360
 
361
int nextvoxid = 0;
362
 
363
int osdcmd_restartvid(const osdfuncparm_t *parm)
364
{
365
    UNREFERENCED_PARAMETER(parm);
366
 
5327 hendricks2 367
    resetvideomode();
368
    if (setgamemode(fullscreen,xdim,ydim,bpp))
369
        buildputs("restartvid: Reset failed...\n");
4555 hendricks2 370
 
5327 hendricks2 371
    return OSDCMD_OK;
4555 hendricks2 372
}
373
 
374
static int osdcmd_vidmode(const osdfuncparm_t *parm)
375
{
5327 hendricks2 376
    int newx = xdim, newy = ydim, newbpp = bpp, newfullscreen = fullscreen;
4555 hendricks2 377
 
5327 hendricks2 378
    if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP;
4555 hendricks2 379
 
5327 hendricks2 380
    switch (parm->numparms)
381
    {
382
    case 1:   // bpp switch
383
        newbpp = Batol(parm->parms[0]);
384
        break;
385
    case 2: // res switch
386
        newx = Batol(parm->parms[0]);
387
        newy = Batol(parm->parms[1]);
388
        break;
389
    case 3:   // res & bpp switch
390
    case 4:
391
        newx = Batol(parm->parms[0]);
392
        newy = Batol(parm->parms[1]);
393
        newbpp = Batol(parm->parms[2]);
394
        if (parm->numparms == 4)
395
            newfullscreen = (Batol(parm->parms[3]) != 0);
396
        break;
397
    }
4555 hendricks2 398
 
5327 hendricks2 399
    if (setgamemode(newfullscreen,newx,newy,newbpp))
400
        buildputs("vidmode: Mode change failed!\n");
401
    screensize = xdim+1;
402
    return OSDCMD_OK;
4555 hendricks2 403
}
404
 
5327 hendricks2 405
static int osdcmd_map(const osdfuncparm_t *parm)
406
{
407
    int i;
408
    char *dot, namebuf[BMAX_PATH+1];
4555 hendricks2 409
 
5327 hendricks2 410
    if (parm->numparms != 1) return OSDCMD_SHOWHELP;
4555 hendricks2 411
 
5327 hendricks2 412
    strncpy(namebuf, parm->parms[0], BMAX_PATH);
413
    namebuf[BMAX_PATH] = 0;
414
    dot = strrchr(namebuf, '.');
415
    if ((!dot || Bstrcasecmp(dot, ".map")) && strlen(namebuf) <= BMAX_PATH-4)
416
    {
417
        strcat(namebuf, ".map");
418
    }
4555 hendricks2 419
 
5327 hendricks2 420
    prepareboard(namebuf);
4555 hendricks2 421
 
5327 hendricks2 422
    screenpeek = myconnectindex;
423
    reccnt = 0;
424
    for (i=connecthead; i>=0; i=connectpoint2[i]) initplayersprite((short)i);
4555 hendricks2 425
 
5327 hendricks2 426
    waitforeverybody();
427
    totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0;
4555 hendricks2 428
 
5327 hendricks2 429
    ready2send = 1;
430
    drawscreen(screenpeek,65536L);
4555 hendricks2 431
 
5327 hendricks2 432
    return OSDCMD_OK;
4555 hendricks2 433
}
434
 
435
int32_t app_main(int32_t argc, const char **argv)
436
{
437
#if defined STARTUP_SETUP_WINDOW
5327 hendricks2 438
    int cmdsetup = 0;
4555 hendricks2 439
#endif
440
    int i, j, k /*, l, fil, waitplayers, x1, y1, x2, y2*/;
5327 hendricks2 441
    int /*other, packleng,*/ netparm;
4555 hendricks2 442
 
4558 hendricks2 443
    OSD_SetFunctions(
444
        NULL, NULL, NULL, NULL, NULL,
445
        COMMON_clearbackground,
446
        BGetTime,
447
        NULL
5327 hendricks2 448
        );
4555 hendricks2 449
 
4558 hendricks2 450
    OSD_SetParameters(0,2, 0,0, 4,0);
451
 
5327 hendricks2 452
    OSD_SetLogFile("testgame.log");
4558 hendricks2 453
    initprintf("%s %s %s\n", AppProperName, s_buildRev, s_buildInfo);
4555 hendricks2 454
    initprintf("Compiled %s\n", s_buildTimestamp);
455
 
456
#ifdef USE_OPENGL
5327 hendricks2 457
    OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid);
458
    OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode);
459
    OSD_RegisterFunction("map", "map [filename]: load a map", osdcmd_map);
4555 hendricks2 460
#endif
461
 
5327 hendricks2 462
    wm_setapptitle(AppProperName);
4555 hendricks2 463
 
5327 hendricks2 464
    Bstrcpy(boardfilename, "nukeland.map");
465
    j = 0; netparm = argc;
466
    for (i=1; i<argc; i++)
467
    {
468
        if ((!Bstrcasecmp("-net",argv[i])) || (!Bstrcasecmp("/net",argv[i]))) { j = 1; netparm = i; continue; }
469
        if (j)
470
        {
471
            if (argv[i][0] == '-' || argv[i][0] == '/')
4555 hendricks2 472
            {
5327 hendricks2 473
                if (((argv[i][1] == 'n') || (argv[i][1] == 'N')) && (argv[i][2] == '0')) { networkmode = 0; continue; }
474
                if (((argv[i][1] == 'n') || (argv[i][1] == 'N')) && (argv[i][2] == '1')) { networkmode = 1; continue; }
475
            }
476
            if (isvalidipaddress(argv[i])) continue;
477
        }
478
        else
479
        {
480
            if (!Bstrcasecmp(argv[i], "-setup"))
481
            {
4555 hendricks2 482
#if defined STARTUP_SETUP_WINDOW
483
                cmdsetup = 1;
484
#endif
485
            }
5327 hendricks2 486
            else
487
            {
488
                Bstrcpy(boardfilename, argv[i]);
489
                if (!Bstrrchr(boardfilename,'.')) Bstrcat(boardfilename,".map");
490
            }
491
        }
492
    }
4555 hendricks2 493
 
5327 hendricks2 494
    if ((i = loadsetup(setupfilename)) < 0)
495
        buildputs("Configuration file not found, using defaults.\n");
4562 hendricks2 496
 
497
#if defined STARTUP_SETUP_WINDOW
5327 hendricks2 498
    if (i || forcesetup || cmdsetup)
499
    {
500
        if (quitevent || !startwin_run()) return -1;
501
    }
4562 hendricks2 502
#endif
5327 hendricks2 503
    writesetup(setupfilename);
4562 hendricks2 504
 
5327 hendricks2 505
    initgroupfile(G_GrpFile());
506
    if (initengine())
507
    {
508
        buildprintf("There was a problem initialising the engine: %s.\n", engineerrstr);
509
        return -1;
510
    }
4555 hendricks2 511
 
512
    setbasepaltable(basepaltable, 1);
4564 hendricks2 513
    fillemptylookups();
4555 hendricks2 514
 
4558 hendricks2 515
    Ken_InitMultiPsky();
4555 hendricks2 516
 
5327 hendricks2 517
    initinput();
518
    if (option[3] != 0) initmouse();
519
    inittimer(TIMERINTSPERSECOND);
4555 hendricks2 520
 
5327 hendricks2 521
    //initmultiplayers(argc-netparm,&argv[netparm],option[4],option[5],0);
522
    if (initmultiplayersparms(argc-netparm,&argv[netparm]))
523
    {
524
        buildputs("Waiting for players...\n");
525
        while (initmultiplayerscycle())
526
        {
527
            handleevents();
528
            if (quitevent)
529
            {
530
                sendlogoff();         //Signing off
531
                musicoff();
532
                uninitmultiplayers();
533
                uninittimer();
534
                uninitinput();
535
                uninitengine();
536
                uninitsb();
537
                uninitgroupfile();
538
                return 0;
539
            }
540
        }
541
    }
542
    option[4] = (numplayers >= 2);
4555 hendricks2 543
 
5327 hendricks2 544
    loadpics("tiles000.art",1048576);                      //Load artwork
545
    if (!qloadkvx(nextvoxid,"voxel000.kvx"))
546
        tiletovox[PLAYER] = nextvoxid++;
547
    if (!qloadkvx(nextvoxid,"voxel001.kvx"))
548
        tiletovox[BROWNMONSTER] = nextvoxid++;
549
    if (!loaddefinitionsfile(G_DefFile())) buildputs("Definitions file loaded.\n");
4555 hendricks2 550
 
5327 hendricks2 551
    //Here's an example of TRUE ornamented walls
552
    //The allocatepermanenttile should be called right after loadpics
553
    //Since it resets the tile cache for each call.
554
    if (allocatepermanenttile(SLIME,128,128) == 0)    //If enough memory
555
    {
556
        buildputs("Not enough memory for slime!\n");
557
        exit(0);
558
    }
559
    if (allocatepermanenttile(MAXTILES-1,64,64) != 0)    //If enough memory
560
    {
561
        //My face with an explosion written over it
562
        copytilepiece(KENPICTURE,0,0,64,64,MAXTILES-1,0,0);
563
        copytilepiece(EXPLOSION,0,0,64,64,MAXTILES-1,0,0);
564
    }
4555 hendricks2 565
 
5327 hendricks2 566
    initlava();
4555 hendricks2 567
 
5327 hendricks2 568
    for (j=0; j<256; j++)
569
        tempbuf[j] = ((j+32)&255);  //remap colors for screwy palette sectors
570
    makepalookup(16,tempbuf,0,0,0,1);
4555 hendricks2 571
 
5327 hendricks2 572
    for (j=0; j<256; j++) tempbuf[j] = j;
573
    makepalookup(17,tempbuf,24,24,24,1);
4555 hendricks2 574
 
5327 hendricks2 575
    for (j=0; j<256; j++) tempbuf[j] = j; //(j&31)+32;
576
    makepalookup(18,tempbuf,8,8,48,1);
4555 hendricks2 577
 
5327 hendricks2 578
    prepareboard(boardfilename);                   //Load board
4555 hendricks2 579
 
5327 hendricks2 580
    initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,((option[7]&2)>0)+1,60,option[7]&1);
581
    //if (Bstrcmp(boardfilename,"klab.map") == 0)
582
    //   loadsong("klabsong.kdm");
583
    //else
584
    loadsong("neatsong.kdm");
585
    musicon();
4555 hendricks2 586
 
587
#if 0
5327 hendricks2 588
    if (option[4] > 0)
589
    {
590
        x1 = ((xdim-screensize)>>1);
591
        x2 = x1+screensize-1;
592
        y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1);
593
        y2 = y1 + scale(screensize,ydim-32,xdim)-1;
4555 hendricks2 594
 
5327 hendricks2 595
        drawtilebackground(/*0L,0L,*/ BACKGROUND,8,x1,y1,x2,y2,0);
4555 hendricks2 596
 
5327 hendricks2 597
        sendlogon();
4555 hendricks2 598
 
5327 hendricks2 599
        if (option[4] < 5) waitplayers = 2; else waitplayers = option[4]-3;
600
        while (numplayers < waitplayers)
601
        {
602
            sprintf(tempbuf,"%ld of %ld players in...",numplayers,waitplayers);
603
            printext256(68L,84L,31,0,tempbuf,0);
604
            nextpage();
4555 hendricks2 605
 
5327 hendricks2 606
            if (getpacket(&other,packbuf) > 0)
607
                if (packbuf[0] == 255)
608
                    keystatus[1] = 1;
4555 hendricks2 609
 
5327 hendricks2 610
            if (handleevents())
611
            {
612
                if (quitevent)
613
                {
614
                    keystatus[1] = 1;
615
                    quitevent = 0;
616
                }
617
            }
4555 hendricks2 618
 
5327 hendricks2 619
            if (keystatus[1])
620
            {
621
                sendlogoff();         //Signing off
622
                musicoff();
623
                uninitmultiplayers();
624
                uninittimer();
625
                uninitinput();
626
                uninitengine();
627
                uninitsb();
628
                uninitgroupfile();
629
                exit(0);
630
            }
631
        }
632
        screenpeek = myconnectindex;
4555 hendricks2 633
 
5327 hendricks2 634
        if (numplayers <= 3)
635
            networkmode = 1;
636
        else
637
            networkmode = 0;
4555 hendricks2 638
 
5327 hendricks2 639
        j = 1;
640
        for (i=connecthead; i>=0; i=connectpoint2[i])
641
        {
642
            if (myconnectindex == i) break;
643
            j++;
644
        }
645
        sprintf(getmessage,"Player %ld",j);
646
        if (networkmode == 0)
647
        {
648
            if (j == 1) Bstrcat(getmessage," (Master)");
649
            else Bstrcat(getmessage," (Slave)");
650
        }
651
        else
652
            Bstrcat(getmessage," (Even)");
653
        getmessageleng = Bstrlen(getmessage);
654
        getmessagetimeoff = totalclock+120;
655
    }
4555 hendricks2 656
#endif
5327 hendricks2 657
    screenpeek = myconnectindex;
658
    reccnt = 0;
659
    for (i=connecthead; i>=0; i=connectpoint2[i]) initplayersprite((short)i);
4555 hendricks2 660
 
5327 hendricks2 661
    waitforeverybody();
662
    totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0;
4555 hendricks2 663
 
5327 hendricks2 664
    ready2send = 1;
665
    drawscreen(screenpeek,65536L);
4555 hendricks2 666
 
5327 hendricks2 667
    while (!keystatus[1])       //Main loop starts here
668
    {
669
        if (handleevents())
670
        {
671
            if (quitevent)
672
            {
673
                keystatus[1] = 1;
674
                quitevent = 0;
675
            }
676
        }
4555 hendricks2 677
 
5327 hendricks2 678
        refreshaudio();
679
        OSD_DispatchQueued();
4555 hendricks2 680
 
5327 hendricks2 681
        // backslash (useful only with KDM)
4555 hendricks2 682
//      if (keystatus[0x2b]) { keystatus[0x2b] = 0; preparesndbuf(); }
683
 
5327 hendricks2 684
        if ((networkmode == 1) || (myconnectindex != connecthead))
685
            while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings();
4555 hendricks2 686
 
5327 hendricks2 687
        getpackets();
4555 hendricks2 688
 
5327 hendricks2 689
        if (typemode == 0)           //if normal game keys active
690
        {
691
            if ((keystatus[0x2a]&keystatus[0x36]&keystatus[0x13]) > 0)   //Sh.Sh.R (replay)
692
            {
693
                keystatus[0x13] = 0;
694
                playback();
695
            }
4555 hendricks2 696
 
5327 hendricks2 697
            if (keystatus[0x26]&(keystatus[0x1d]|keystatus[0x9d])) //Load game
698
            {
699
                keystatus[0x26] = 0;
700
                loadgame();
701
                drawstatusbar(screenpeek);   // Andy did this
702
            }
4555 hendricks2 703
 
5327 hendricks2 704
            if (keystatus[0x1f]&(keystatus[0x1d]|keystatus[0x9d])) //Save game
705
            {
706
                keystatus[0x1f] = 0;
707
                savegame();
708
            }
709
        }
4555 hendricks2 710
 
5327 hendricks2 711
        if ((networkmode == 0) || (option[4] == 0))
712
        {
713
            while (movefifoplc != movefifoend[0]) domovethings();
714
        }
715
        else
716
        {
717
            j = connecthead;
718
            if (j == myconnectindex) j = connectpoint2[j];
719
            averagelag[j] = ((averagelag[j]*7+(((movefifoend[myconnectindex]-movefifoend[j]+otherlag[j]+2)&255)<<8))>>3);
720
            j = max(averagelag[j]>>9,1);
721
            while (((movefifoend[myconnectindex]-movefifoplc)&(MOVEFIFOSIZ-1)) > j)
722
            {
723
                for (i=connecthead; i>=0; i=connectpoint2[i])
724
                    if (movefifoplc == movefifoend[i]) break;
725
                if (i >= 0) break;
726
                if (myconnectindex != connecthead)
727
                {
728
                    k = ((movefifoend[myconnectindex]-movefifoend[connecthead]-otherlag[connecthead]+128)&255);
729
                    if (k > 128+1) ototalclock++;
730
                    if (k < 128-1) ototalclock--;
731
                }
732
                domovethings();
733
            }
734
        }
735
        i = (totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND));
4555 hendricks2 736
 
5327 hendricks2 737
        drawscreen(screenpeek,i);
738
    }
4555 hendricks2 739
 
5327 hendricks2 740
    sendlogoff();         //Signing off
741
    musicoff();
742
    uninitmultiplayers();
743
    uninittimer();
744
    uninitinput();
745
    uninitengine();
746
    uninitsb();
747
    uninitgroupfile();
4555 hendricks2 748
 
5327 hendricks2 749
    return 0;
4555 hendricks2 750
}
751
 
752
void operatesector(short dasector)
5327 hendricks2 753
{
754
    //Door code
755
    int i, j, /*k, s, nexti, good, cnt,*/ datag;
756
    int /*dax, day,*/ daz, dax2, day2, /*daz2,*/ centx, centy;
757
    short startwall, endwall, wallfind[2];
4555 hendricks2 758
 
5327 hendricks2 759
    datag = sector[dasector].lotag;
4555 hendricks2 760
 
5327 hendricks2 761
    startwall = sector[dasector].wallptr;
762
    endwall = startwall + sector[dasector].wallnum;
763
    centx = 0L, centy = 0L;
764
    for (i=startwall; i<endwall; i++)
765
    {
766
        centx += wall[i].x;
767
        centy += wall[i].y;
768
    }
769
    centx /= (endwall-startwall);
770
    centy /= (endwall-startwall);
4555 hendricks2 771
 
5327 hendricks2 772
    //Simple door that moves up  (tag 8 is a combination of tags 6 & 7)
773
    if ((datag == 6) || (datag == 8))    //If the sector in front is a door
774
    {
775
        i = getanimationgoal(&sector[dasector].ceilingz);
776
        if (i >= 0)      //If door already moving, reverse its direction
777
        {
778
            if (datag == 8)
779
                daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
780
            else
781
                daz = sector[dasector].floorz;
4555 hendricks2 782
 
5327 hendricks2 783
            if (animategoal[i] == daz)
784
                animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;
785
            else
786
                animategoal[i] = daz;
787
            animatevel[i] = 0;
788
        }
789
        else      //else insert the door's ceiling on the animation list
790
        {
791
            if (sector[dasector].ceilingz == sector[dasector].floorz)
792
                daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;
793
            else
794
            {
795
                if (datag == 8)
796
                    daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
797
                else
798
                    daz = sector[dasector].floorz;
799
            }
800
            if ((j = setanimation(&sector[dasector].ceilingz,daz,6L,6L)) >= 0)
801
                wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);
802
        }
803
    }
804
    //Simple door that moves down
805
    if ((datag == 7) || (datag == 8)) //If the sector in front's elevator
806
    {
807
        i = getanimationgoal(&sector[dasector].floorz);
808
        if (i >= 0)      //If elevator already moving, reverse its direction
809
        {
810
            if (datag == 8)
811
                daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
812
            else
813
                daz = sector[dasector].ceilingz;
4555 hendricks2 814
 
5327 hendricks2 815
            if (animategoal[i] == daz)
816
                animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;
817
            else
818
                animategoal[i] = daz;
819
            animatevel[i] = 0;
820
        }
821
        else      //else insert the elevator's ceiling on the animation list
822
        {
823
            if (sector[dasector].floorz == sector[dasector].ceilingz)
824
                daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;
825
            else
826
            {
827
                if (datag == 8)
828
                    daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
829
                else
830
                    daz = sector[dasector].ceilingz;
831
            }
832
            if ((j = setanimation(&sector[dasector].floorz,daz,6L,6L)) >= 0)
833
                wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);
834
        }
835
    }
4555 hendricks2 836
 
5327 hendricks2 837
    if (datag == 9)   //Smooshy-wall sideways double-door
838
    {
839
        //find any points with either same x or same y coordinate
840
        //  as center (centx, centy) - should be 2 points found.
841
        wallfind[0] = -1;
842
        wallfind[1] = -1;
843
        for (i=startwall; i<endwall; i++)
844
            if ((wall[i].x == centx) || (wall[i].y == centy))
845
            {
846
                if (wallfind[0] == -1)
847
                    wallfind[0] = i;
848
                else
849
                    wallfind[1] = i;
850
            }
4555 hendricks2 851
 
5327 hendricks2 852
        for (j=0; j<2; j++)
853
        {
854
            if ((wall[wallfind[j]].x == centx) && (wall[wallfind[j]].y == centy))
855
            {
856
                //find what direction door should open by averaging the
857
                //  2 neighboring points of wallfind[0] & wallfind[1].
858
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
859
                dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;
860
                day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;
861
                if (dax2 != 0)
862
                {
863
                    dax2 = wall[wall[wall[wallfind[j]].point2].point2].x;
864
                    dax2 -= wall[wall[wallfind[j]].point2].x;
865
                    setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
866
                    setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
867
                    setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
868
                }
869
                else if (day2 != 0)
870
                {
871
                    day2 = wall[wall[wall[wallfind[j]].point2].point2].y;
872
                    day2 -= wall[wall[wallfind[j]].point2].y;
873
                    setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
874
                    setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
875
                    setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
876
                }
877
            }
878
            else
879
            {
880
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
881
                dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;
882
                day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;
883
                if (dax2 != 0)
884
                {
885
                    setanimation(&wall[wallfind[j]].x,centx,4L,0L);
886
                    setanimation(&wall[i].x,centx+dax2,4L,0L);
887
                    setanimation(&wall[wall[wallfind[j]].point2].x,centx+dax2,4L,0L);
888
                }
889
                else if (day2 != 0)
890
                {
891
                    setanimation(&wall[wallfind[j]].y,centy,4L,0L);
892
                    setanimation(&wall[i].y,centy+day2,4L,0L);
893
                    setanimation(&wall[wall[wallfind[j]].point2].y,centy+day2,4L,0L);
894
                }
895
            }
896
        }
897
        wsayfollow("updowndr.wav",4096L-256L,256L,&centx,&centy,0);
898
        wsayfollow("updowndr.wav",4096L+256L,256L,&centx,&centy,0);
899
    }
4555 hendricks2 900
 
5327 hendricks2 901
    if (datag == 13)  //Swinging door
902
    {
903
        for (i=0; i<swingcnt; i++)
904
        {
905
            if (swingsector[i] == dasector)
906
            {
907
                if (swinganginc[i] == 0)
908
                {
909
                    if (swingang[i] == swingangclosed[i])
910
                    {
911
                        swinganginc[i] = swingangopendir[i];
912
                        wsayfollow("opendoor.wav",4096L+(krand()&511)-256,256L,&centx,&centy,0);
913
                    }
914
                    else
915
                        swinganginc[i] = -swingangopendir[i];
916
                }
917
                else
918
                    swinganginc[i] = -swinganginc[i];
4555 hendricks2 919
 
5327 hendricks2 920
                for (j=1; j<=3; j++)
921
                {
922
                    setinterpolation(&wall[swingwall[i][j]].x);
923
                    setinterpolation(&wall[swingwall[i][j]].y);
924
                }
925
            }
926
        }
927
    }
4555 hendricks2 928
 
5327 hendricks2 929
    if (datag == 16)  //True sideways double-sliding door
930
    {
931
        //get 2 closest line segments to center (dax, day)
932
        wallfind[0] = -1;
933
        wallfind[1] = -1;
934
        for (i=startwall; i<endwall; i++)
935
            if (wall[i].lotag == 6)
936
            {
937
                if (wallfind[0] == -1)
938
                    wallfind[0] = i;
939
                else
940
                    wallfind[1] = i;
941
            }
4555 hendricks2 942
 
5327 hendricks2 943
        for (j=0; j<2; j++)
944
        {
945
            if ((((wall[wallfind[j]].x+wall[wall[wallfind[j]].point2].x)>>1) == centx) && (((wall[wallfind[j]].y+wall[wall[wallfind[j]].point2].y)>>1) == centy))
946
            {
947
                //door was closed
948
                //find what direction door should open
949
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
950
                dax2 = wall[i].x-wall[wallfind[j]].x;
951
                day2 = wall[i].y-wall[wallfind[j]].y;
952
                if (dax2 != 0)
953
                {
954
                    dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x;
955
                    dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x;
956
                    setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
957
                    setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
958
                    setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
959
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L);
960
                }
961
                else if (day2 != 0)
962
                {
963
                    day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y;
964
                    day2 -= wall[wall[wall[wallfind[j]].point2].point2].y;
965
                    setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
966
                    setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
967
                    setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
968
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L);
969
                }
970
            }
971
            else
972
            {
973
                //door was not closed
974
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
975
                dax2 = wall[i].x-wall[wallfind[j]].x;
976
                day2 = wall[i].y-wall[wallfind[j]].y;
977
                if (dax2 != 0)
978
                {
979
                    setanimation(&wall[wallfind[j]].x,centx,4L,0L);
980
                    setanimation(&wall[i].x,centx+dax2,4L,0L);
981
                    setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L);
982
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L);
983
                }
984
                else if (day2 != 0)
985
                {
986
                    setanimation(&wall[wallfind[j]].y,centy,4L,0L);
987
                    setanimation(&wall[i].y,centy+day2,4L,0L);
988
                    setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L);
989
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L);
990
                }
991
            }
992
        }
993
        wsayfollow("updowndr.wav",4096L-64L,256L,&centx,&centy,0);
994
        wsayfollow("updowndr.wav",4096L+64L,256L,&centx,&centy,0);
995
    }
4555 hendricks2 996
}
997
 
998
void operatesprite(short dasprite)
999
{
5327 hendricks2 1000
    int datag;
4555 hendricks2 1001
 
5327 hendricks2 1002
    datag = sprite[dasprite].lotag;
4555 hendricks2 1003
 
5327 hendricks2 1004
    if (datag == 2)    //A sprite that shoots a bomb
1005
    {
4555 hendricks2 1006
        vec3_t vector = { sprite[dasprite].x,sprite[dasprite].y,sprite[dasprite].z };
5327 hendricks2 1007
        shootgun(dasprite, &vector,
1008
                 sprite[dasprite].ang,100L,sprite[dasprite].sectnum,2);
1009
    }
4555 hendricks2 1010
}
1011
 
1012
int changehealth(short snum, short deltahealth)
1013
{
5327 hendricks2 1014
    // int dax, day;
1015
    // short good, k, startwall, endwall, s;
4555 hendricks2 1016
 
5327 hendricks2 1017
    if (health[snum] > 0)
1018
    {
1019
        health[snum] += deltahealth;
1020
        if (health[snum] > 999) health[snum] = 999;
4555 hendricks2 1021
 
5327 hendricks2 1022
        if (health[snum] <= 0)
1023
        {
1024
            health[snum] = -1;
1025
            wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1026
            sprite[playersprite[snum]].picnum = SKELETON;
1027
        }
4555 hendricks2 1028
 
5327 hendricks2 1029
        if ((snum == screenpeek) && (screensize <= xdim))
1030
        {
1031
            if (health[snum] > 0)
1032
                sprintf((char *)tempbuf,"Health:%3d",health[snum]);
1033
            else
1034
                sprintf((char *)tempbuf,"YOU STINK!");
4555 hendricks2 1035
 
5327 hendricks2 1036
            printext((xdim>>1)-(Bstrlen((char *)tempbuf)<<2),ydim-24,(char *)tempbuf,ALPHABET /*,80*/);
1037
        }
1038
    }
1039
    return health[snum] <= 0;       //You were just injured
4555 hendricks2 1040
}
1041
 
5327 hendricks2 1042
void changenumbombs(short snum, short deltanumbombs)     // Andy did this
1043
{
1044
    numbombs[snum] += deltanumbombs;
1045
    if (numbombs[snum] > 999) numbombs[snum] = 999;
1046
    if (numbombs[snum] <= 0)
1047
    {
1048
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1049
        numbombs[snum] = 0;
1050
    }
4555 hendricks2 1051
 
5327 hendricks2 1052
    if ((snum == screenpeek) && (screensize <= xdim))
1053
    {
1054
        sprintf((char *)tempbuf,"B:%3d",numbombs[snum]);
1055
        printext(8L,(ydim - 28L),(char *)tempbuf,ALPHABET /*,80*/);
1056
    }
4555 hendricks2 1057
}
1058
 
5327 hendricks2 1059
void changenummissiles(short snum, short deltanummissiles)     // Andy did this
1060
{
1061
    nummissiles[snum] += deltanummissiles;
1062
    if (nummissiles[snum] > 999) nummissiles[snum] = 999;
1063
    if (nummissiles[snum] <= 0)
1064
    {
1065
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1066
        nummissiles[snum] = 0;
1067
    }
4555 hendricks2 1068
 
5327 hendricks2 1069
    if ((snum == screenpeek) && (screensize <= xdim))
1070
    {
1071
        sprintf((char *)tempbuf,"M:%3d",nummissiles[snum]);
1072
        printext(8L,(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1073
    }
4555 hendricks2 1074
}
1075
 
5327 hendricks2 1076
void changenumgrabbers(short snum, short deltanumgrabbers)     // Andy did this
1077
{
1078
    numgrabbers[snum] += deltanumgrabbers;
1079
    if (numgrabbers[snum] > 999) numgrabbers[snum] = 999;
1080
    if (numgrabbers[snum] <= 0)
1081
    {
1082
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1083
        numgrabbers[snum] = 0;
1084
    }
4555 hendricks2 1085
 
5327 hendricks2 1086
    if ((snum == screenpeek) && (screensize <= xdim))
1087
    {
1088
        sprintf((char *)tempbuf,"G:%3d",numgrabbers[snum]);
1089
        printext(8L,(ydim - 12L),(char *)tempbuf,ALPHABET /*,80*/);
1090
    }
4555 hendricks2 1091
}
1092
 
1093
static int ostatusflytime = 0x80000000;
5327 hendricks2 1094
void drawstatusflytime(short snum)     // Andy did this
1095
{
1096
    int nstatusflytime;
4555 hendricks2 1097
 
5327 hendricks2 1098
    if ((snum == screenpeek) && (screensize <= xdim))
1099
    {
1100
        nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
1101
        if (nstatusflytime > 1000) nstatusflytime = 1000;
1102
        else if (nstatusflytime < 0) nstatusflytime = 0;
1103
        if (nstatusflytime != ostatusflytime)
1104
        {
1105
            if (nstatusflytime > 999) sprintf((char *)tempbuf,"FT:BIG");
1106
            else sprintf((char *)tempbuf,"FT:%3d",nstatusflytime);
1107
            printext((xdim - 56L),(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1108
            ostatusflytime = nstatusflytime;
1109
        }
1110
    }
4555 hendricks2 1111
}
1112
 
5327 hendricks2 1113
void drawstatusbar(short snum)     // Andy did this
1114
{
1115
    int nstatusflytime;
4555 hendricks2 1116
 
5327 hendricks2 1117
    if ((snum == screenpeek) && (screensize <= xdim))
1118
    {
1119
        sprintf((char *)tempbuf,"Deaths:%d",deaths[snum]);
1120
        printext((xdim>>1)-(strlen((char *)tempbuf)<<2),ydim-16,(char *)tempbuf,ALPHABET /*,80*/);
1121
        sprintf((char *)tempbuf,"Health:%3d",health[snum]);
1122
        printext((xdim>>1)-(strlen((char *)tempbuf)<<2),ydim-24,(char *)tempbuf,ALPHABET /*,80*/);
4555 hendricks2 1123
 
5327 hendricks2 1124
        sprintf((char *)tempbuf,"B:%3d",numbombs[snum]);
1125
        printext(8L,(ydim - 28L),(char *)tempbuf,ALPHABET /*,80*/);
1126
        sprintf((char *)tempbuf,"M:%3d",nummissiles[snum]);
1127
        printext(8L,(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1128
        sprintf((char *)tempbuf,"G:%3d",numgrabbers[snum]);
1129
        printext(8L,(ydim - 12L),(char *)tempbuf,ALPHABET /*,80*/);
4555 hendricks2 1130
 
5327 hendricks2 1131
        nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
1132
        if (nstatusflytime < 0)
1133
        {
1134
            sprintf((char *)tempbuf,"FT:  0");
1135
            ostatusflytime = 0;
1136
        }
1137
        else if (nstatusflytime > 999)
1138
        {
1139
            sprintf((char *)tempbuf,"FT:BIG");
1140
            ostatusflytime = 999;
1141
        }
1142
        else
1143
        {
1144
            sprintf((char *)tempbuf,"FT:%3d",nstatusflytime);
1145
            ostatusflytime = nstatusflytime;
1146
        }
1147
        printext((xdim - 56L),(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1148
    }
4555 hendricks2 1149
}
1150
 
1151
void prepareboard(char *daboardfilename)
1152
{
5327 hendricks2 1153
    short startwall, endwall, dasector;
1154
    int i, j, k=0, s, dax, day, /*daz,*/ dax2, day2;
4555 hendricks2 1155
 
5327 hendricks2 1156
    getmessageleng = 0;
1157
    typemessageleng = 0;
4555 hendricks2 1158
 
5327 hendricks2 1159
    randomseed = 17L;
4555 hendricks2 1160
 
5327 hendricks2 1161
    //Clear (do)animation's list
1162
    animatecnt = 0;
1163
    typemode = 0;
1164
    locselectedgun = 0;
1165
    locselectedgun2 = 0;
4555 hendricks2 1166
 
5327 hendricks2 1167
    if (loadboard(daboardfilename,0,&pos[0],&ang[0],&cursectnum[0]) == -1)
1168
    {
1169
        musicoff();
1170
        uninitmultiplayers();
1171
        uninittimer();
1172
        uninitinput();
1173
        uninitengine();
1174
        uninitsb();
1175
        uninitgroupfile();
1176
        printf("Board not found\n");
1177
        exit(0);
1178
    }
1179
    else
1180
    {
1181
        char tempfn[BMAX_PATH + 1], *fp;
4555 hendricks2 1182
 
5327 hendricks2 1183
        strncpy(tempfn, daboardfilename, BMAX_PATH);
1184
        tempfn[BMAX_PATH] = 0;
4555 hendricks2 1185
 
5327 hendricks2 1186
        fp = strrchr(tempfn,'.');
1187
        if (fp) *fp = 0;
4555 hendricks2 1188
 
5327 hendricks2 1189
        if (strlen(tempfn) <= BMAX_PATH-4)
1190
        {
1191
            strcat(tempfn,".mhk");
1192
            loadmaphack(tempfn);
1193
        }
1194
    }
4555 hendricks2 1195
 
5327 hendricks2 1196
    setup3dscreen();
4555 hendricks2 1197
 
5327 hendricks2 1198
    for (i=0; i<MAXPLAYERS; i++)
1199
    {
1200
        pos[i] = pos[0];
1201
        ang[i] = ang[0];
1202
        cursectnum[i] = cursectnum[0];
1203
        ocursectnum[i] = cursectnum[0];
1204
        horiz[i] = 100;
1205
        lastchaingun[i] = 0;
1206
        health[i] = 100;
1207
        dimensionmode[i] = 3;
1208
        numbombs[i] = 0;
1209
        numgrabbers[i] = 0;
1210
        nummissiles[i] = 0;
1211
        flytime[i] = 0L;
1212
        zoom[i] = 768L;
1213
        deaths[i] = 0L;
1214
        playersprite[i] = -1;
1215
        screensize = xdim;
4555 hendricks2 1216
 
5327 hendricks2 1217
        opos[i] = pos[0];
1218
        ohoriz[i] = horiz[0];
1219
        ozoom[i] = zoom[0];
1220
        oang[i] = ang[0];
1221
    }
4555 hendricks2 1222
 
5327 hendricks2 1223
    my = omy = pos[myconnectindex];
1224
    myhoriz = omyhoriz = horiz[myconnectindex];
1225
    myang = omyang = ang[myconnectindex];
1226
    mycursectnum = cursectnum[myconnectindex];
1227
    myzvel = 0;
4555 hendricks2 1228
 
5327 hendricks2 1229
    movefifoplc = fakemovefifoplc = 0;
1230
    syncvalhead = 0L; othersyncvalhead = 0L;
1231
    syncvaltottail = 0L; syncvaltail = 0L;
1232
    numinterpolations = 0;
4555 hendricks2 1233
 
5327 hendricks2 1234
    clearbufbyte(&oloc,sizeof(input),0L);
1235
    for (i=0; i<MAXPLAYERS; i++)
1236
    {
1237
        movefifoend[i] = 0;
1238
        clearbufbyte(&ffsync[i],sizeof(input),0L);
1239
        clearbufbyte(&ssync[i],sizeof(input),0L);
1240
        clearbufbyte(&osync[i],sizeof(input),0L);
1241
    }
4555 hendricks2 1242
 
5327 hendricks2 1243
    //Scan sector tags
4555 hendricks2 1244
 
5327 hendricks2 1245
    for (i=0; i<MAXPLAYERS; i++)
1246
    {
1247
        waterfountainwall[i] = -1;
1248
        waterfountaincnt[i] = 0;
1249
        slimesoundcnt[i] = 0;
1250
    }
1251
    warpsectorcnt = 0;      //Make a list of warping sectors
1252
    xpanningsectorcnt = 0;  //Make a list of wall x-panning sectors
1253
    floorpanningcnt = 0;    //Make a list of slime sectors
1254
    dragsectorcnt = 0;      //Make a list of moving platforms
1255
    swingcnt = 0;           //Make a list of swinging doors
1256
    revolvecnt = 0;         //Make a list of revolving doors
1257
    subwaytrackcnt = 0;     //Make a list of subways
4555 hendricks2 1258
 
5327 hendricks2 1259
    floormirrorcnt = 0;
1260
    tilesiz[FLOORMIRROR].x = 0;
1261
    tilesiz[FLOORMIRROR].y = 0;
4555 hendricks2 1262
 
5327 hendricks2 1263
    for (i=0; i<numsectors; i++)
1264
    {
1265
        switch (sector[i].lotag)
1266
        {
1267
        case 4:
1268
            floorpanninglist[floorpanningcnt++] = i;
1269
            break;
1270
        case 10:
1271
            warpsectorlist[warpsectorcnt++] = i;
1272
            break;
1273
        case 11:
1274
            xpanningsectorlist[xpanningsectorcnt++] = i;
1275
            break;
1276
        case 12:
1277
            dasector = i;
1278
            dax = 0x7fffffff;
1279
            day = 0x7fffffff;
1280
            dax2 = 0x80000000;
1281
            day2 = 0x80000000;
1282
            startwall = sector[i].wallptr;
1283
            endwall = startwall+sector[i].wallnum;
1284
            for (j=startwall; j<endwall; j++)
1285
            {
1286
                if (wall[j].x < dax) dax = wall[j].x;
1287
                if (wall[j].y < day) day = wall[j].y;
1288
                if (wall[j].x > dax2) dax2 = wall[j].x;
1289
                if (wall[j].y > day2) day2 = wall[j].y;
1290
                if (wall[j].lotag == 3) k = j;
1291
            }
1292
            if (wall[k].x == dax) dragxdir[dragsectorcnt] = -16;
1293
            if (wall[k].y == day) dragydir[dragsectorcnt] = -16;
1294
            if (wall[k].x == dax2) dragxdir[dragsectorcnt] = 16;
1295
            if (wall[k].y == day2) dragydir[dragsectorcnt] = 16;
4555 hendricks2 1296
 
5327 hendricks2 1297
            dasector = wall[startwall].nextsector;
1298
            dragx1[dragsectorcnt] = 0x7fffffff;
1299
            dragy1[dragsectorcnt] = 0x7fffffff;
1300
            dragx2[dragsectorcnt] = 0x80000000;
1301
            dragy2[dragsectorcnt] = 0x80000000;
1302
            startwall = sector[dasector].wallptr;
1303
            endwall = startwall+sector[dasector].wallnum;
1304
            for (j=startwall; j<endwall; j++)
1305
            {
1306
                if (wall[j].x < dragx1[dragsectorcnt]) dragx1[dragsectorcnt] = wall[j].x;
1307
                if (wall[j].y < dragy1[dragsectorcnt]) dragy1[dragsectorcnt] = wall[j].y;
1308
                if (wall[j].x > dragx2[dragsectorcnt]) dragx2[dragsectorcnt] = wall[j].x;
1309
                if (wall[j].y > dragy2[dragsectorcnt]) dragy2[dragsectorcnt] = wall[j].y;
4555 hendricks2 1310
 
5327 hendricks2 1311
                setinterpolation(&sector[dasector].floorz);
1312
                setinterpolation(&wall[j].x);
1313
                setinterpolation(&wall[j].y);
1314
                setinterpolation(&wall[wall[j].nextwall].x);
1315
                setinterpolation(&wall[wall[j].nextwall].y);
1316
            }
4555 hendricks2 1317
 
5327 hendricks2 1318
            dragx1[dragsectorcnt] += (wall[sector[i].wallptr].x-dax);
1319
            dragy1[dragsectorcnt] += (wall[sector[i].wallptr].y-day);
1320
            dragx2[dragsectorcnt] -= (dax2-wall[sector[i].wallptr].x);
1321
            dragy2[dragsectorcnt] -= (day2-wall[sector[i].wallptr].y);
4555 hendricks2 1322
 
5327 hendricks2 1323
            dragfloorz[dragsectorcnt] = sector[i].floorz;
4555 hendricks2 1324
 
5327 hendricks2 1325
            dragsectorlist[dragsectorcnt++] = i;
1326
            break;
1327
        case 13:
1328
            startwall = sector[i].wallptr;
1329
            endwall = startwall+sector[i].wallnum;
1330
            for (j=startwall; j<endwall; j++)
1331
            {
1332
                if (wall[j].lotag == 4)
1333
                {
1334
                    k = wall[wall[wall[wall[j].point2].point2].point2].point2;
1335
                    if ((wall[j].x == wall[k].x) && (wall[j].y == wall[k].y))
1336
                    {
1337
                        //Door opens counterclockwise
1338
                        swingwall[swingcnt][0] = j;
1339
                        swingwall[swingcnt][1] = wall[j].point2;
1340
                        swingwall[swingcnt][2] = wall[wall[j].point2].point2;
1341
                        swingwall[swingcnt][3] = wall[wall[wall[j].point2].point2].point2;
1342
                        swingangopen[swingcnt] = 1536;
1343
                        swingangclosed[swingcnt] = 0;
1344
                        swingangopendir[swingcnt] = -1;
1345
                    }
1346
                    else
1347
                    {
1348
                        //Door opens clockwise
1349
                        swingwall[swingcnt][0] = wall[j].point2;
1350
                        swingwall[swingcnt][1] = j;
1351
                        swingwall[swingcnt][2] = lastwall(j);
1352
                        swingwall[swingcnt][3] = lastwall(swingwall[swingcnt][2]);
1353
                        swingwall[swingcnt][4] = lastwall(swingwall[swingcnt][3]);
1354
                        swingangopen[swingcnt] = 512;
1355
                        swingangclosed[swingcnt] = 0;
1356
                        swingangopendir[swingcnt] = 1;
1357
                    }
1358
                    for (k=0; k<4; k++)
1359
                    {
1360
                        swingx[swingcnt][k] = wall[swingwall[swingcnt][k]].x;
1361
                        swingy[swingcnt][k] = wall[swingwall[swingcnt][k]].y;
1362
                    }
4555 hendricks2 1363
 
5327 hendricks2 1364
                    swingsector[swingcnt] = i;
1365
                    swingang[swingcnt] = swingangclosed[swingcnt];
1366
                    swinganginc[swingcnt] = 0;
1367
                    swingcnt++;
1368
                }
1369
            }
1370
            break;
1371
        case 14:
1372
            startwall = sector[i].wallptr;
1373
            endwall = startwall+sector[i].wallnum;
1374
            dax = 0L;
1375
            day = 0L;
1376
            for (j=startwall; j<endwall; j++)
1377
            {
1378
                dax += wall[j].x;
1379
                day += wall[j].y;
1380
            }
1381
            revolvepivotx[revolvecnt] = dax / (endwall-startwall);
1382
            revolvepivoty[revolvecnt] = day / (endwall-startwall);
4555 hendricks2 1383
 
5327 hendricks2 1384
            k = 0;
1385
            for (j=startwall; j<endwall; j++)
1386
            {
1387
                revolvex[revolvecnt][k] = wall[j].x;
1388
                revolvey[revolvecnt][k] = wall[j].y;
4555 hendricks2 1389
 
5327 hendricks2 1390
                setinterpolation(&wall[j].x);
1391
                setinterpolation(&wall[j].y);
1392
                setinterpolation(&wall[wall[j].nextwall].x);
1393
                setinterpolation(&wall[wall[j].nextwall].y);
4555 hendricks2 1394
 
5327 hendricks2 1395
                k++;
1396
            }
1397
            revolvesector[revolvecnt] = i;
1398
            revolveang[revolvecnt] = 0;
4555 hendricks2 1399
 
5327 hendricks2 1400
            revolvecnt++;
1401
            break;
1402
        case 15:
1403
            subwaytracksector[subwaytrackcnt][0] = i;
4555 hendricks2 1404
 
5327 hendricks2 1405
            subwaystopcnt[subwaytrackcnt] = 0;
1406
            dax = 0x7fffffff;
1407
            day = 0x7fffffff;
1408
            dax2 = 0x80000000;
1409
            day2 = 0x80000000;
1410
            startwall = sector[i].wallptr;
1411
            endwall = startwall+sector[i].wallnum;
1412
            for (j=startwall; j<endwall; j++)
1413
            {
1414
                if (wall[j].x < dax) dax = wall[j].x;
1415
                if (wall[j].y < day) day = wall[j].y;
1416
                if (wall[j].x > dax2) dax2 = wall[j].x;
1417
                if (wall[j].y > day2) day2 = wall[j].y;
1418
            }
1419
            for (j=startwall; j<endwall; j++)
1420
            {
1421
                if (wall[j].lotag == 5)
1422
                {
1423
                    if ((wall[j].x > dax) && (wall[j].y > day) && (wall[j].x < dax2) && (wall[j].y < day2))
1424
                    {
1425
                        subwayx[subwaytrackcnt] = wall[j].x;
1426
                    }
1427
                    else
1428
                    {
1429
                        subwaystop[subwaytrackcnt][subwaystopcnt[subwaytrackcnt]] = wall[j].x;
1430
                        subwaystopcnt[subwaytrackcnt]++;
1431
                    }
1432
                }
1433
            }
4555 hendricks2 1434
 
5327 hendricks2 1435
            for (j=1; j<subwaystopcnt[subwaytrackcnt]; j++)
1436
                for (k=0; k<j; k++)
1437
                    if (subwaystop[subwaytrackcnt][j] < subwaystop[subwaytrackcnt][k])
1438
                    {
1439
                        s = subwaystop[subwaytrackcnt][j];
1440
                        subwaystop[subwaytrackcnt][j] = subwaystop[subwaytrackcnt][k];
1441
                        subwaystop[subwaytrackcnt][k] = s;
1442
                    }
4555 hendricks2 1443
 
5327 hendricks2 1444
            subwaygoalstop[subwaytrackcnt] = 0;
1445
            for (j=0; j<subwaystopcnt[subwaytrackcnt]; j++)
1446
                if (klabs(subwaystop[subwaytrackcnt][j]-subwayx[subwaytrackcnt]) < klabs(subwaystop[subwaytrackcnt][subwaygoalstop[subwaytrackcnt]]-subwayx[subwaytrackcnt]))
1447
                    subwaygoalstop[subwaytrackcnt] = j;
4555 hendricks2 1448
 
5327 hendricks2 1449
            subwaytrackx1[subwaytrackcnt] = dax;
1450
            subwaytracky1[subwaytrackcnt] = day;
1451
            subwaytrackx2[subwaytrackcnt] = dax2;
1452
            subwaytracky2[subwaytrackcnt] = day2;
4555 hendricks2 1453
 
5327 hendricks2 1454
            subwaynumsectors[subwaytrackcnt] = 1;
1455
            for (j=0; j<numsectors; j++)
1456
                if (j != i)
1457
                {
1458
                    startwall = sector[j].wallptr;
1459
                    if (wall[startwall].x > subwaytrackx1[subwaytrackcnt])
1460
                        if (wall[startwall].y > subwaytracky1[subwaytrackcnt])
1461
                            if (wall[startwall].x < subwaytrackx2[subwaytrackcnt])
1462
                                if (wall[startwall].y < subwaytracky2[subwaytrackcnt])
1463
                                {
1464
                                    if (sector[j].floorz != sector[i].floorz)
1465
                                    {
1466
                                        sector[j].ceilingstat |= 64;
1467
                                        sector[j].floorstat |= 64;
1468
                                    }
1469
                                    subwaytracksector[subwaytrackcnt][subwaynumsectors[subwaytrackcnt]] = j;
1470
                                    subwaynumsectors[subwaytrackcnt]++;
1471
                                }
1472
                }
4555 hendricks2 1473
 
5327 hendricks2 1474
            subwayvel[subwaytrackcnt] = 64;
1475
            subwaypausetime[subwaytrackcnt] = 720;
4555 hendricks2 1476
 
5327 hendricks2 1477
            startwall = sector[i].wallptr;
1478
            endwall = startwall+sector[i].wallnum;
1479
            for (k=startwall; k<endwall; k++)
1480
                if (wall[k].x > subwaytrackx1[subwaytrackcnt])
1481
                    if (wall[k].y > subwaytracky1[subwaytrackcnt])
1482
                        if (wall[k].x < subwaytrackx2[subwaytrackcnt])
1483
                            if (wall[k].y < subwaytracky2[subwaytrackcnt])
1484
                                setinterpolation(&wall[k].x);
4555 hendricks2 1485
 
5327 hendricks2 1486
            for (j=1; j<subwaynumsectors[subwaytrackcnt]; j++)
1487
            {
1488
                dasector = subwaytracksector[subwaytrackcnt][j];
4555 hendricks2 1489
 
5327 hendricks2 1490
                startwall = sector[dasector].wallptr;
1491
                endwall = startwall+sector[dasector].wallnum;
1492
                for (k=startwall; k<endwall; k++)
1493
                    setinterpolation(&wall[k].x);
4555 hendricks2 1494
 
5327 hendricks2 1495
                for (k=headspritesect[dasector]; k>=0; k=nextspritesect[k])
1496
                    if (statrate[sprite[k].statnum] < 0)
1497
                        setinterpolation(&sprite[k].x);
1498
            }
4555 hendricks2 1499
 
1500
 
5327 hendricks2 1501
            subwaytrackcnt++;
1502
            break;
1503
        }
1504
        if (sector[i].floorpicnum == FLOORMIRROR)
1505
            floormirrorsector[mirrorcnt++] = i;
1506
        //if (sector[i].ceilingpicnum == FLOORMIRROR) floormirrorsector[mirrorcnt++] = i; //SOS
1507
    }
4555 hendricks2 1508
 
5327 hendricks2 1509
    //Scan wall tags
4555 hendricks2 1510
 
5327 hendricks2 1511
    mirrorcnt = 0;
1512
    tilesiz[MIRROR].x = 0;
1513
    tilesiz[MIRROR].y = 0;
1514
    for (i=0; i<MAXMIRRORS; i++)
1515
    {
1516
        tilesiz[i+MIRRORLABEL].x = 0;
1517
        tilesiz[i+MIRRORLABEL].y = 0;
1518
    }
4555 hendricks2 1519
 
5327 hendricks2 1520
    ypanningwallcnt = 0;
1521
    for (i=0; i<numwalls; i++)
1522
    {
1523
        if (wall[i].lotag == 1) ypanningwalllist[ypanningwallcnt++] = i;
1524
        s = wall[i].nextsector;
1525
        if ((s >= 0) && (wall[i].overpicnum == MIRROR) && (wall[i].cstat&32))
1526
        {
1527
            if ((sector[s].floorstat&1) == 0)
1528
            {
1529
                wall[i].overpicnum = MIRRORLABEL+mirrorcnt;
1530
                sector[s].ceilingpicnum = MIRRORLABEL+mirrorcnt;
1531
                sector[s].floorpicnum = MIRRORLABEL+mirrorcnt;
1532
                sector[s].floorstat |= 1;
1533
                mirrorwall[mirrorcnt] = i;
1534
                mirrorsector[mirrorcnt] = s;
1535
                mirrorcnt++;
1536
            }
1537
            else
1538
                wall[i].overpicnum = sector[s].ceilingpicnum;
1539
        }
1540
    }
4555 hendricks2 1541
 
5327 hendricks2 1542
    //Invalidate textures in sector behind mirror
1543
    for (i=0; i<mirrorcnt; i++)
1544
    {
1545
        k = mirrorsector[i];
1546
        startwall = sector[k].wallptr;
1547
        endwall = startwall + sector[k].wallnum;
1548
        for (j=startwall; j<endwall; j++)
1549
        {
1550
            wall[j].picnum = MIRROR;
1551
            wall[j].overpicnum = MIRROR;
1552
        }
1553
    }
4555 hendricks2 1554
 
5327 hendricks2 1555
    //Scan sprite tags&picnum's
4555 hendricks2 1556
 
5327 hendricks2 1557
    turnspritecnt = 0;
1558
    for (i=0; i<MAXSPRITES; i++)
1559
    {
1560
        if (sprite[i].lotag == 3) turnspritelist[turnspritecnt++] = i;
4555 hendricks2 1561
 
5327 hendricks2 1562
        if (sprite[i].statnum < MAXSTATUS)    //That is, if sprite exists
1563
            switch (sprite[i].picnum)
1564
            {
1565
            case BROWNMONSTER:              //All cases here put the sprite
1566
                if ((sprite[i].cstat&128) == 0)
1567
                {
1568
                    sprite[i].z -= ((tilesiz[sprite[i].picnum].y*sprite[i].yrepeat)<<1);
1569
                    sprite[i].cstat |= 128;
1570
                }
1571
                sprite[i].extra = sprite[i].ang;
1572
                sprite[i].clipdist = mulscale7(sprite[i].xrepeat,tilesiz[sprite[i].picnum].x);
1573
                if (sprite[i].statnum != 1) changespritestat(i,2);   //on waiting for you (list 2)
1574
                sprite[i].lotag = mulscale5(sprite[i].xrepeat,sprite[i].yrepeat);
1575
                sprite[i].cstat |= 0x101;    //Set the hitscan sensitivity bit
1576
                break;
1577
            case AL:
1578
                sprite[i].cstat |= 0x101;    //Set the hitscan sensitivity bit
1579
                sprite[i].lotag = 0x60;
1580
                changespritestat(i,0);
1581
                break;
1582
            case EVILAL:
1583
                sprite[i].cstat |= 0x101;    //Set the hitscan sensitivity bit
1584
                sprite[i].lotag = 0x60;
1585
                changespritestat(i,10);
1586
                break;
1587
            }
1588
    }
4555 hendricks2 1589
 
5327 hendricks2 1590
    for (i=MAXSPRITES-1; i>=0; i--) copybuf(&sprite[i].x,&osprite[i].x,3);
4555 hendricks2 1591
 
5327 hendricks2 1592
    searchmap(cursectnum[connecthead]);
4555 hendricks2 1593
 
5327 hendricks2 1594
    lockclock = 0;
1595
    ototalclock = 0;
1596
    gotlastpacketclock = 0;
4555 hendricks2 1597
 
5327 hendricks2 1598
    screensize = xdim;
1599
    dax = ((xdim-screensize)>>1);
1600
    dax2 = dax+screensize-1;
1601
    day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1);
1602
    day2 = day + scale(screensize,ydim-32,xdim)-1;
1603
    setview(dax,day,dax2,day2);
4555 hendricks2 1604
 
5327 hendricks2 1605
    startofdynamicinterpolations = numinterpolations;
4555 hendricks2 1606
 
1607
#if 0
5327 hendricks2 1608
    for (i=connecthead; i>=0; i=connectpoint2[i]) myminlag[i] = 0;
1609
    otherminlag = mymaxlag = 0;
4555 hendricks2 1610
#endif
1611
}
1612
 
1613
void checktouchsprite(short snum, short sectnum)
1614
{
5327 hendricks2 1615
    int i, nexti;
4555 hendricks2 1616
 
5327 hendricks2 1617
    if ((sectnum < 0) || (sectnum >= numsectors)) return;
4555 hendricks2 1618
 
5327 hendricks2 1619
    for (i=headspritesect[sectnum]; i>=0; i=nexti)
1620
    {
1621
        nexti = nextspritesect[i];
1622
        if (sprite[i].cstat&0x8000) continue;
1623
        if ((klabs(pos[snum].x-sprite[i].x)+klabs(pos[snum].y-sprite[i].y) < 512) && (klabs((pos[snum].z>>8)-((sprite[i].z>>8)-(tilesiz[sprite[i].picnum].y>>1))) <= 40))
1624
        {
1625
            switch (sprite[i].picnum)
1626
            {
1627
            case COIN:
1628
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0);
1629
                changehealth(snum,5);
1630
                if (sprite[i].statnum == 12) deletesprite((short)i);
1631
                else
1632
                {
1633
                    sprite[i].cstat |= 0x8000;
1634
                    sprite[i].extra = 120*60;
1635
                    changespritestat((short)i,11);
1636
                }
1637
                break;
1638
            case DIAMONDS:
1639
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1640
                changehealth(snum,15);
1641
                if (sprite[i].statnum == 12) deletesprite((short)i);
1642
                else
1643
                {
1644
                    sprite[i].cstat |= 0x8000;
1645
                    sprite[i].extra = 120*120;
1646
                    changespritestat((short)i,11);
1647
                }
1648
                break;
1649
            case COINSTACK:
1650
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1651
                changehealth(snum,25);
1652
                if (sprite[i].statnum == 12) deletesprite((short)i);
1653
                else
1654
                {
1655
                    sprite[i].cstat |= 0x8000;
1656
                    sprite[i].extra = 120*180;
1657
                    changespritestat((short)i,11);
1658
                }
1659
                break;
1660
            case GIFTBOX:
1661
                wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0);
1662
                changehealth(snum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1));
1663
                if (sprite[i].statnum == 12) deletesprite((short)i);
1664
                else
1665
                {
1666
                    sprite[i].cstat |= 0x8000;
1667
                    sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat);
1668
                    changespritestat((short)i,11);
1669
                }
1670
                break;
1671
            case CANNON:
1672
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1673
                if (snum == myconnectindex) keystatus[4] = 1;
1674
                changenumbombs(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1675
                if (sprite[i].statnum == 12) deletesprite((short)i);
1676
                else
1677
                {
1678
                    sprite[i].cstat |= 0x8000;
1679
                    sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat);
1680
                    changespritestat((short)i,11);
1681
                }
1682
                break;
1683
            case LAUNCHER:
1684
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1685
                if (snum == myconnectindex) keystatus[5] = 1;
1686
                changenummissiles(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1687
                if (sprite[i].statnum == 12) deletesprite((short)i);
1688
                else
1689
                {
1690
                    sprite[i].cstat |= 0x8000;
1691
                    sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat);
1692
                    changespritestat((short)i,11);
1693
                }
1694
                break;
1695
            case GRABCANNON:
1696
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1697
                if (snum == myconnectindex) keystatus[6] = 1;
1698
                changenumgrabbers(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1699
                if (sprite[i].statnum == 12) deletesprite((short)i);
1700
                else
1701
                {
1702
                    sprite[i].cstat |= 0x8000;
1703
                    sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat);
1704
                    changespritestat((short)i,11);
1705
                }
1706
                break;
1707
            case AIRPLANE:
1708
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1709
                if (flytime[snum] < lockclock) flytime[snum] = lockclock;
1710
                flytime[snum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat);
1711
                drawstatusflytime(snum);
1712
                if (sprite[i].statnum == 12) deletesprite((short)i);
1713
                else
1714
                {
1715
                    sprite[i].cstat |= 0x8000;
1716
                    sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat);
1717
                    changespritestat((short)i,11);
1718
                }
1719
                break;
1720
            }
1721
        }
1722
    }
4555 hendricks2 1723
}
1724
 
1725
void checkgrabbertouchsprite(short snum, short sectnum)   // Andy did this
1726
{
5327 hendricks2 1727
    int i, nexti;
1728
    short onum;
4555 hendricks2 1729
 
5327 hendricks2 1730
    if ((sectnum < 0) || (sectnum >= numsectors)) return;
1731
    onum = (sprite[snum].owner & (MAXSPRITES - 1));
4555 hendricks2 1732
 
5327 hendricks2 1733
    for (i=headspritesect[sectnum]; i>=0; i=nexti)
1734
    {
1735
        nexti = nextspritesect[i];
1736
        if (sprite[i].cstat&0x8000) continue;
1737
        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)-(tilesiz[sprite[i].picnum].y>>1))) <= 40))
1738
        {
1739
            switch (sprite[i].picnum)
1740
            {
1741
            case COIN:
1742
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0);
1743
                changehealth(onum,5);
1744
                if (sprite[i].statnum == 12) deletesprite((short)i);
1745
                else
1746
                {
1747
                    sprite[i].cstat |= 0x8000;
1748
                    sprite[i].extra = 120*60;
1749
                    changespritestat((short)i,11);
1750
                }
1751
                break;
1752
            case DIAMONDS:
1753
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1754
                changehealth(onum,15);
1755
                if (sprite[i].statnum == 12) deletesprite((short)i);
1756
                else
1757
                {
1758
                    sprite[i].cstat |= 0x8000;
1759
                    sprite[i].extra = 120*120;
1760
                    changespritestat((short)i,11);
1761
                }
1762
                break;
1763
            case COINSTACK:
1764
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1765
                changehealth(onum,25);
1766
                if (sprite[i].statnum == 12) deletesprite((short)i);
1767
                else
1768
                {
1769
                    sprite[i].cstat |= 0x8000;
1770
                    sprite[i].extra = 120*180;
1771
                    changespritestat((short)i,11);
1772
                }
1773
                break;
1774
            case GIFTBOX:
1775
                wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0);
1776
                changehealth(onum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1));
1777
                if (sprite[i].statnum == 12) deletesprite((short)i);
1778
                else
1779
                {
1780
                    sprite[i].cstat |= 0x8000;
1781
                    sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat);
1782
                    changespritestat((short)i,11);
1783
                }
1784
                break;
1785
            case CANNON:
1786
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1787
                if (onum == myconnectindex) keystatus[4] = 1;
1788
                changenumbombs(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1789
                if (sprite[i].statnum == 12) deletesprite((short)i);
1790
                else
1791
                {
1792
                    sprite[i].cstat |= 0x8000;
1793
                    sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat);
1794
                    changespritestat((short)i,11);
1795
                }
1796
                break;
1797
            case LAUNCHER:
1798
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1799
                if (onum == myconnectindex) keystatus[5] = 1;
1800
                changenummissiles(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1801
                if (sprite[i].statnum == 12) deletesprite((short)i);
1802
                else
1803
                {
1804
                    sprite[i].cstat |= 0x8000;
1805
                    sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat);
1806
                    changespritestat((short)i,11);
1807
                }
1808
                break;
1809
            case GRABCANNON:
1810
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1811
                if (onum == myconnectindex) keystatus[6] = 1;
1812
                changenumgrabbers(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1813
                if (sprite[i].statnum == 12) deletesprite((short)i);
1814
                else
1815
                {
1816
                    sprite[i].cstat |= 0x8000;
1817
                    sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat);
1818
                    changespritestat((short)i,11);
1819
                }
1820
                break;
1821
            case AIRPLANE:
1822
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1823
                if (flytime[snum] < lockclock) flytime[snum] = lockclock;
1824
                flytime[onum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat);
1825
                drawstatusflytime(onum);
1826
                if (sprite[i].statnum == 12) deletesprite((short)i);
1827
                else
1828
                {
1829
                    sprite[i].cstat |= 0x8000;
1830
                    sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat);
1831
                    changespritestat((short)i,11);
1832
                }
1833
                break;
1834
            }
1835
        }
1836
    }
4555 hendricks2 1837
}
1838
 
1839
void shootgun(short snum, const vec3_t *vector,
5327 hendricks2 1840
              short daang, int dahoriz, short dasectnum, char guntype)
4555 hendricks2 1841
{
5327 hendricks2 1842
    short daang2;
1843
    int /*i,*/ j, daz2;
4555 hendricks2 1844
    hitdata_t hitinfo;
1845
 
5327 hendricks2 1846
    switch (guntype)
1847
    {
1848
    case 0:    //Shoot chain gun
1849
        daang2 = ((daang + (krand()&31)-16)&2047);
1850
        daz2 = ((100-dahoriz)*2000) + ((krand()-32768)>>1);
4555 hendricks2 1851
 
5327 hendricks2 1852
        hitscan(vector,dasectnum,                   //Start position
1853
                sintable[(daang2+512)&2047],            //X vector of 3D ang
1854
                sintable[daang2&2047],                  //Y vector of 3D ang
1855
                daz2,                                   //Z vector of 3D ang
1856
                &hitinfo,CLIPMASK1);
4555 hendricks2 1857
 
5327 hendricks2 1858
        if (wall[hitinfo.wall].picnum == KENPICTURE)
1859
        {
1860
            if (waloff[MAXTILES-1] != 0) wall[hitinfo.wall].picnum = MAXTILES-1;
1861
            wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&wall[hitinfo.wall].x,&wall[hitinfo.wall].y,0);
1862
        }
1863
        else if (((hitinfo.wall < 0) && (hitinfo.sprite < 0) && (hitinfo.pos.z >= vector->z) && ((sector[hitinfo.sect].floorpicnum == SLIME) || (sector[hitinfo.sect].floorpicnum == FLOORMIRROR))) || ((hitinfo.wall >= 0) && (wall[hitinfo.wall].picnum == SLIME)))
1864
        {
1865
            //If you shoot slime, make a splash
1866
            wsayfollow("splash.wav",4096L+(krand()&511)-256,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1867
            spawnsprite(j,hitinfo.pos.x,hitinfo.pos.y,hitinfo.pos.z,2,0,0,32,64,64,0,0,SPLASH,daang,
1868
                        0,0,0,snum+4096,hitinfo.sect,4,63,0,0); //63=time left for splash
1869
        }
1870
        else
1871
        {
1872
            wsayfollow("shoot.wav",4096L+(krand()&127)-64,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
4555 hendricks2 1873
 
5327 hendricks2 1874
            if ((hitinfo.sprite >= 0) && (sprite[hitinfo.sprite].statnum < MAXSTATUS))
1875
                switch (sprite[hitinfo.sprite].picnum)
1876
                {
1877
                case BROWNMONSTER:
1878
                    if (sprite[hitinfo.sprite].lotag > 0) sprite[hitinfo.sprite].lotag -= 10;
1879
                    if (sprite[hitinfo.sprite].lotag > 0)
1880
                    {
1881
                        wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1882
                        if (sprite[hitinfo.sprite].lotag <= 25)
1883
                            sprite[hitinfo.sprite].cstat |= 2;
1884
                    }
1885
                    else
1886
                    {
1887
                        wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1888
                        sprite[hitinfo.sprite].z += ((tilesiz[sprite[hitinfo.sprite].picnum].y*sprite[hitinfo.sprite].yrepeat)<<1);
1889
                        sprite[hitinfo.sprite].picnum = GIFTBOX;
1890
                        sprite[hitinfo.sprite].cstat &= ~0x83;    //Should not clip, foot-z
1891
                        changespritestat(hitinfo.sprite,12);
4555 hendricks2 1892
 
5327 hendricks2 1893
                        spawnsprite(j,hitinfo.pos.x,hitinfo.pos.y,hitinfo.pos.z+(32<<8),0,-4,0,32,64,64,
1894
                                    0,0,EXPLOSION,daang,0,0,0,snum+4096,
1895
                                    hitinfo.sect,5,31,0,0);
1896
                    }
1897
                    break;
1898
                case EVILAL:
1899
                    wsayfollow("blowup.wav",4096L+(krand()&127)-64,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1900
                    sprite[hitinfo.sprite].picnum = EVILALGRAVE;
1901
                    sprite[hitinfo.sprite].cstat = 0;
1902
                    sprite[hitinfo.sprite].xvel = (krand()&255)-128;
1903
                    sprite[hitinfo.sprite].yvel = (krand()&255)-128;
1904
                    sprite[hitinfo.sprite].zvel = (krand()&4095)-3072;
1905
                    changespritestat(hitinfo.sprite,9);
4555 hendricks2 1906
 
5327 hendricks2 1907
                    spawnsprite(j,hitinfo.pos.x,hitinfo.pos.y,hitinfo.pos.z+(32<<8),0,-4,0,32,64,64,0,
1908
                                0,EXPLOSION,daang,0,0,0,snum+4096,hitinfo.sect,5,31,0,0);
1909
                    //31=time left for explosion
4555 hendricks2 1910
 
5327 hendricks2 1911
                    break;
1912
                case PLAYER:
1913
                    for (j=connecthead; j>=0; j=connectpoint2[j])
1914
                        if (playersprite[j] == hitinfo.sprite)
1915
                        {
1916
                            wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1917
                            changehealth(j,-10);
1918
                            break;
1919
                        }
1920
                    break;
1921
                }
4555 hendricks2 1922
 
5327 hendricks2 1923
            spawnsprite(j,hitinfo.pos.x,hitinfo.pos.y,hitinfo.pos.z+(8<<8),2,-4,0,32,16,16,0,0,
1924
                        EXPLOSION,daang,0,0,0,snum+4096,hitinfo.sect,3,63,0,0);
4555 hendricks2 1925
 
5327 hendricks2 1926
            //Sprite starts out with center exactly on wall.
1927
            //This moves it back enough to see it at all angles.
1928
            movesprite((short)j,-(((int)sintable[(512+daang)&2047]*TICSPERFRAME)<<4),-(((int)sintable[daang]*TICSPERFRAME)<<4),0L,4L<<8,4L<<8,CLIPMASK1);
1929
        }
1930
        break;
1931
    case 1:    //Shoot silver sphere bullet
1932
        spawnsprite(j,vector->x,vector->y,vector->z,1+128,0,0,16,64,64,0,0,BULLET,daang,
1933
                    sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5,
1934
                    (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0);
1935
        wsayfollow("shoot2.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1);
1936
        break;
1937
    case 2:    //Shoot bomb
1938
        spawnsprite(j,vector->x,vector->y,vector->z,128,0,0,12,16,16,0,0,BOMB,daang,
1939
                    sintable[(daang+512)&2047]*5>>8,sintable[daang&2047]*5>>8,
1940
                    (80-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0);
1941
        wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1);
1942
        break;
1943
    case 3:    //Shoot missile (Andy did this)
1944
        spawnsprite(j,vector->x,vector->y,vector->z,1+128,0,0,16,32,32,0,0,MISSILE,daang,
1945
                    sintable[(daang+512)&2047]>>4,sintable[daang&2047]>>4,
1946
                    (100-dahoriz)<<7,snum+4096,dasectnum,6,0,0,0);
1947
        wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1);
1948
        break;
1949
    case 4:    //Shoot grabber (Andy did this)
1950
        spawnsprite(j,vector->x,vector->y,vector->z,1+128,0,0,16,64,64,0,0,GRABBER,daang,
1951
                    sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5,
1952
                    (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0);
1953
        wsayfollow("shoot4.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1);
1954
        break;
1955
    }
4555 hendricks2 1956
}
1957
 
1958
#define MAXVOXMIPS 5
1959
extern intptr_t voxoff[][MAXVOXMIPS];
1960
void analyzesprites(int dax, int day)
1961
{
5327 hendricks2 1962
    int i, j=0, k, *intptr;
1963
    vec3_t *ospr;
1964
    spritetype *tspr;
4555 hendricks2 1965
 
5327 hendricks2 1966
    //This function is called between drawrooms() and drawmasks()
1967
    //It has a list of possible sprites that may be drawn on this frame
4555 hendricks2 1968
 
5327 hendricks2 1969
    for (i=0,tspr=&tsprite[0]; i<spritesortcnt; i++,tspr++)
1970
    {
1971
        if (usevoxels && tiletovox[tspr->picnum] >= 0)
1972
            switch (tspr->picnum)
1973
            {
1974
            case PLAYER:
1975
                //   //Get which of the 8 angles of the sprite to draw (0-7)
1976
                //   //k ranges from 0-7
1977
                //k = getangle(tspr->x-dax,tspr->y-day);
1978
                //k = (((tspr->ang+3072+128-k)&2047)>>8)&7;
1979
                //   //This guy has only 5 pictures for 8 angles (3 are x-flipped)
1980
                //if (k <= 4)
1981
                //{
1982
                //   tspr->picnum += (k<<2);
1983
                //   tspr->cstat &= ~4;   //clear x-flipping bit
1984
                //}
1985
                //else
1986
                //{
1987
                //   tspr->picnum += ((8-k)<<2);
1988
                //   tspr->cstat |= 4;    //set x-flipping bit
1989
                //}
4555 hendricks2 1990
 
5327 hendricks2 1991
                if ((tspr->cstat&2) == 0)
1992
                {
1993
                    //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum];
1994
                    intptr = (int *)voxoff[tiletovox[PLAYER]][0];
1995
                    tspr->xrepeat = scale(tspr->xrepeat,56,intptr[2]);
1996
                    tspr->yrepeat = scale(tspr->yrepeat,56,intptr[2]);
1997
                    tspr->shade -= 6;
1998
                }
1999
                break;
2000
            case BROWNMONSTER:
2001
                //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum];
2002
                break;
2003
            }
4555 hendricks2 2004
 
5327 hendricks2 2005
        k = statrate[tspr->statnum];
2006
        if (k >= 0)  //Interpolate moving sprite
2007
        {
2008
            ospr = &osprite[tspr->owner];
2009
            switch (k)
2010
            {
2011
            case 0: j = smoothratio; break;
2012
            case 1: j = (smoothratio>>1)+(((nummoves-tspr->owner)&1)<<15); break;
2013
            case 3: j = (smoothratio>>2)+(((nummoves-tspr->owner)&3)<<14); break;
2014
            case 7: j = (smoothratio>>3)+(((nummoves-tspr->owner)&7)<<13); break;
2015
            case 15: j = (smoothratio>>4)+(((nummoves-tspr->owner)&15)<<12); break;
2016
            }
2017
            k = tspr->x-ospr->x; tspr->x = ospr->x;
2018
            if (k != 0) tspr->x += mulscale16(k,j);
2019
            k = tspr->y-ospr->y; tspr->y = ospr->y;
2020
            if (k != 0) tspr->y += mulscale16(k,j);
2021
            k = tspr->z-ospr->z; tspr->z = ospr->z;
2022
            if (k != 0) tspr->z += mulscale16(k,j);
2023
        }
4555 hendricks2 2024
 
5327 hendricks2 2025
        //Don't allow close explosion sprites to be transluscent
2026
        k = tspr->statnum;
2027
        if ((k == 3) || (k == 4) || (k == 5) || (k == 7))
2028
            if (klabs(dax-tspr->x) < 256)
2029
                if (klabs(day-tspr->y) < 256)
2030
                    tspr->cstat &= ~2;
4555 hendricks2 2031
 
5327 hendricks2 2032
        tspr->shade += 6;
2033
        if (sector[tspr->sectnum].ceilingstat&1)
2034
            tspr->shade += sector[tspr->sectnum].ceilingshade;
2035
        else
2036
            tspr->shade += sector[tspr->sectnum].floorshade;
2037
    }
4555 hendricks2 2038
}
2039
 
2040
void tagcode(void)
2041
{
5327 hendricks2 2042
    int i, /*nexti,*/ j, k, l, s, dax, day, /*daz, dax2, day2,*/ cnt, good;
2043
    short startwall, endwall, dasector, p, oldang;
4555 hendricks2 2044
 
5327 hendricks2 2045
    for (p=connecthead; p>=0; p=connectpoint2[p])
2046
    {
2047
        if (sector[cursectnum[p]].lotag == 1)
2048
        {
2049
            activatehitag(sector[cursectnum[p]].hitag);
2050
            sector[cursectnum[p]].lotag = 0;
2051
            sector[cursectnum[p]].hitag = 0;
2052
        }
2053
        if ((sector[cursectnum[p]].lotag == 2) && (cursectnum[p] != ocursectnum[p]))
2054
            activatehitag(sector[cursectnum[p]].hitag);
2055
    }
4555 hendricks2 2056
 
5327 hendricks2 2057
    for (i=0; i<warpsectorcnt; i++)
2058
    {
2059
        dasector = warpsectorlist[i];
2060
        j = ((lockclock&127)>>2);
2061
        if (j >= 16) j = 31-j;
2062
        {
2063
            sector[dasector].ceilingshade = j;
2064
            sector[dasector].floorshade = j;
2065
            startwall = sector[dasector].wallptr;
2066
            endwall = startwall+sector[dasector].wallnum;
2067
            for (s=startwall; s<endwall; s++)
2068
                wall[s].shade = j;
2069
        }
2070
    }
4555 hendricks2 2071
 
5327 hendricks2 2072
    for (p=connecthead; p>=0; p=connectpoint2[p])
2073
        if (sector[cursectnum[p]].lotag == 10)  //warp sector
2074
        {
2075
            if (cursectnum[p] != ocursectnum[p])
2076
            {
2077
                warpsprite(playersprite[p]);
2078
                pos[p].x = sprite[playersprite[p]].x;
2079
                pos[p].y = sprite[playersprite[p]].y;
2080
                pos[p].z = sprite[playersprite[p]].z;
2081
                ang[p] = sprite[playersprite[p]].ang;
2082
                cursectnum[p] = sprite[playersprite[p]].sectnum;
4555 hendricks2 2083
 
5327 hendricks2 2084
                sprite[playersprite[p]].z += EYEHEIGHT;
4555 hendricks2 2085
 
5327 hendricks2 2086
                //warp(&pos[p].x,&pos[p].y,&pos[p].z,&ang[p],&cursectnum[p]);
2087
                //Update sprite representation of player
2088
                //setsprite_eyeheight(playersprite[p],&pos[p]);
2089
                //sprite[playersprite[p]].ang = ang[p];
2090
            }
2091
        }
4555 hendricks2 2092
 
5327 hendricks2 2093
    for (i=0; i<xpanningsectorcnt; i++) //animate wall x-panning sectors
2094
    {
2095
        dasector = xpanningsectorlist[i];
4555 hendricks2 2096
 
5327 hendricks2 2097
        startwall = sector[dasector].wallptr;
2098
        endwall = startwall+sector[dasector].wallnum;
2099
        for (s=startwall; s<endwall; s++)
2100
            wall[s].xpanning = ((lockclock>>2)&255);
2101
    }
4555 hendricks2 2102
 
5327 hendricks2 2103
    for (i=0; i<ypanningwallcnt; i++)
2104
        wall[ypanningwalllist[i]].ypanning = ~(lockclock&255);
4555 hendricks2 2105
 
5327 hendricks2 2106
    for (i=0; i<turnspritecnt; i++)
2107
    {
2108
        sprite[turnspritelist[i]].ang += (TICSPERFRAME<<2);
2109
        sprite[turnspritelist[i]].ang &= 2047;
2110
    }
4555 hendricks2 2111
 
5327 hendricks2 2112
    for (i=0; i<floorpanningcnt; i++) //animate floor of slime sectors
2113
    {
2114
        sector[floorpanninglist[i]].floorxpanning = ((lockclock>>2)&255);
2115
        sector[floorpanninglist[i]].floorypanning = ((lockclock>>2)&255);
2116
    }
4555 hendricks2 2117
 
5327 hendricks2 2118
    for (i=0; i<dragsectorcnt; i++)
2119
    {
2120
        dasector = dragsectorlist[i];
4555 hendricks2 2121
 
5327 hendricks2 2122
        startwall = sector[dasector].wallptr;
2123
        endwall = startwall+sector[dasector].wallnum;
4555 hendricks2 2124
 
5327 hendricks2 2125
        if (wall[startwall].x+dragxdir[i] < dragx1[i]) dragxdir[i] = 16;
2126
        if (wall[startwall].y+dragydir[i] < dragy1[i]) dragydir[i] = 16;
2127
        if (wall[startwall].x+dragxdir[i] > dragx2[i]) dragxdir[i] = -16;
2128
        if (wall[startwall].y+dragydir[i] > dragy2[i]) dragydir[i] = -16;
4555 hendricks2 2129
 
5327 hendricks2 2130
        for (j=startwall; j<endwall; j++)
2131
            dragpoint(j,wall[j].x+dragxdir[i],wall[j].y+dragydir[i],0);
2132
        j = sector[dasector].floorz;
2133
        sector[dasector].floorz = dragfloorz[i]+(sintable[(lockclock<<4)&2047]>>3);
4555 hendricks2 2134
 
5327 hendricks2 2135
        for (p=connecthead; p>=0; p=connectpoint2[p])
2136
            if (cursectnum[p] == dasector)
2137
            {
2138
                pos[p].x += dragxdir[i];
2139
                pos[p].y += dragydir[i];
2140
                if (p == myconnectindex)
2141
                { my.x += dragxdir[i]; my.y += dragydir[i]; }
2142
                //pos[p].z += (sector[dasector].floorz-j);
4555 hendricks2 2143
 
5327 hendricks2 2144
                //Update sprite representation of player
2145
                setsprite_eyeheight(playersprite[p],&pos[p]);
2146
                sprite[playersprite[p]].ang = ang[p];
2147
            }
2148
    }
4555 hendricks2 2149
 
5327 hendricks2 2150
    for (i=0; i<swingcnt; i++)
2151
    {
2152
        if (swinganginc[i] != 0)
2153
        {
2154
            oldang = swingang[i];
2155
            for (j=0; j<(TICSPERFRAME<<2); j++)
2156
            {
2157
                swingang[i] = ((swingang[i]+swinganginc[i])&2047);
2158
                if (swingang[i] == swingangclosed[i])
2159
                {
2160
                    wsayfollow(