Subversion Repositories eduke32

Rev

Rev 7540 | Rev 7564 | 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";
7537 hendricks2 22
const char *AppTechnicalName = "ekenbuild";
4555 hendricks2 23
 
7537 hendricks2 24
#define SETUPFILENAME "ekenbuild.cfg"
4562 hendricks2 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);
5551 hendricks2 49
void wsayfollow(char const *,int,int,int *,int *,char);
50
void wsay(char const *,int,int,int);
4555 hendricks2 51
void loadwaves(void);
5551 hendricks2 52
void loadsong(char const *);
4555 hendricks2 53
void musicon(void);
54
void musicoff(void);
55
void refreshaudio(void);
56
 
57
// declared in config.c
5739 hendricks2 58
int Ken_loadsetup(const char *);
59
int Ken_writesetup(const char *);
4555 hendricks2 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
 
7540 hendricks2 367
    videoResetMode();
368
    if (videoSetGameMode(fullscreen, xdim, ydim, bpp, upscalefactor))
5327 hendricks2 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
 
7540 hendricks2 399
    if (videoSetGameMode(newfullscreen, newx, newy, newbpp, upscalefactor))
5327 hendricks2 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
 
5345 hendricks2 435
static void Ken_UninitAll(void)
436
{
437
    sendlogoff();         //Signing off
438
    musicoff();
439
    uninitmultiplayers();
7540 hendricks2 440
    timerUninit();
5345 hendricks2 441
    uninitinput();
7540 hendricks2 442
    engineUnInit();
5345 hendricks2 443
    uninitsb();
444
    uninitgroupfile();
445
}
446
 
447
static void Ken_FatalEngineError(void)
448
{
449
    buildprintf("There was a problem initialising the engine: %s.\n", engineerrstr);
450
}
451
 
5552 hendricks2 452
int32_t app_main(int32_t argc, char const * const * argv)
4555 hendricks2 453
{
454
#if defined STARTUP_SETUP_WINDOW
5327 hendricks2 455
    int cmdsetup = 0;
4555 hendricks2 456
#endif
457
    int i, j, k /*, l, fil, waitplayers, x1, y1, x2, y2*/;
5327 hendricks2 458
    int /*other, packleng,*/ netparm;
4555 hendricks2 459
 
7537 hendricks2 460
    OSD_SetLogFile("ekenbuild.log");
461
 
6142 hendricks2 462
    initprintf("%s %s\n", AppProperName, s_buildRev);
463
    PrintBuildInfo();
4555 hendricks2 464
 
465
#ifdef USE_OPENGL
5327 hendricks2 466
    OSD_RegisterFunction("restartvid","restartvid: reinitialise the video mode",osdcmd_restartvid);
467
    OSD_RegisterFunction("vidmode","vidmode [xdim ydim] [bpp] [fullscreen]: immediately change the video mode",osdcmd_vidmode);
468
    OSD_RegisterFunction("map", "map [filename]: load a map", osdcmd_map);
4555 hendricks2 469
#endif
470
 
5327 hendricks2 471
    wm_setapptitle(AppProperName);
4555 hendricks2 472
 
5327 hendricks2 473
    Bstrcpy(boardfilename, "nukeland.map");
474
    j = 0; netparm = argc;
475
    for (i=1; i<argc; i++)
476
    {
477
        if ((!Bstrcasecmp("-net",argv[i])) || (!Bstrcasecmp("/net",argv[i]))) { j = 1; netparm = i; continue; }
478
        if (j)
479
        {
480
            if (argv[i][0] == '-' || argv[i][0] == '/')
4555 hendricks2 481
            {
5327 hendricks2 482
                if (((argv[i][1] == 'n') || (argv[i][1] == 'N')) && (argv[i][2] == '0')) { networkmode = 0; continue; }
483
                if (((argv[i][1] == 'n') || (argv[i][1] == 'N')) && (argv[i][2] == '1')) { networkmode = 1; continue; }
484
            }
485
            if (isvalidipaddress(argv[i])) continue;
486
        }
487
        else
488
        {
489
            if (!Bstrcasecmp(argv[i], "-setup"))
490
            {
4555 hendricks2 491
#if defined STARTUP_SETUP_WINDOW
492
                cmdsetup = 1;
493
#endif
494
            }
5327 hendricks2 495
            else
496
            {
497
                Bstrcpy(boardfilename, argv[i]);
498
                if (!Bstrrchr(boardfilename,'.')) Bstrcat(boardfilename,".map");
499
            }
500
        }
501
    }
4555 hendricks2 502
 
5739 hendricks2 503
    if ((i = Ken_loadsetup(setupfilename)) < 0)
5327 hendricks2 504
        buildputs("Configuration file not found, using defaults.\n");
4562 hendricks2 505
 
506
#if defined STARTUP_SETUP_WINDOW
5327 hendricks2 507
    if (i || forcesetup || cmdsetup)
508
    {
509
        if (quitevent || !startwin_run()) return -1;
510
    }
4562 hendricks2 511
#endif
5739 hendricks2 512
    Ken_writesetup(setupfilename);
4562 hendricks2 513
 
5327 hendricks2 514
    initgroupfile(G_GrpFile());
7540 hendricks2 515
    if (engineInit())
5327 hendricks2 516
    {
5345 hendricks2 517
        Ken_FatalEngineError();
5327 hendricks2 518
        return -1;
519
    }
4555 hendricks2 520
 
4558 hendricks2 521
    Ken_InitMultiPsky();
4555 hendricks2 522
 
5327 hendricks2 523
    initinput();
7540 hendricks2 524
    if (option[3] != 0) mouseInit();
525
    timerInit(TIMERINTSPERSECOND);
4555 hendricks2 526
 
5327 hendricks2 527
    //initmultiplayers(argc-netparm,&argv[netparm],option[4],option[5],0);
528
    if (initmultiplayersparms(argc-netparm,&argv[netparm]))
529
    {
530
        buildputs("Waiting for players...\n");
531
        while (initmultiplayerscycle())
532
        {
533
            handleevents();
534
            if (quitevent)
535
            {
5345 hendricks2 536
                Ken_UninitAll();
5327 hendricks2 537
                return 0;
538
            }
539
        }
540
    }
541
    option[4] = (numplayers >= 2);
4555 hendricks2 542
 
7540 hendricks2 543
    artLoadFiles("tiles000.art",1048576);                      //Load artwork
5327 hendricks2 544
    if (!qloadkvx(nextvoxid,"voxel000.kvx"))
545
        tiletovox[PLAYER] = nextvoxid++;
546
    if (!qloadkvx(nextvoxid,"voxel001.kvx"))
547
        tiletovox[BROWNMONSTER] = nextvoxid++;
548
    if (!loaddefinitionsfile(G_DefFile())) buildputs("Definitions file loaded.\n");
4555 hendricks2 549
 
7540 hendricks2 550
    if (enginePostInit())
5345 hendricks2 551
    {
552
        Ken_UninitAll();
553
        Ken_FatalEngineError();
554
        return -1;
555
    }
556
 
7541 hendricks2 557
    OSD_SetFunctions(
558
        NULL, NULL, NULL, NULL, NULL,
559
        COMMON_clearbackground,
560
        BGetTime,
561
        NULL
562
        );
563
 
564
    OSD_SetParameters(0,2, 0,0, 4,0, 0, 0, 0); // TODO: Add error and red palookup IDs.
565
 
5327 hendricks2 566
    //Here's an example of TRUE ornamented walls
7540 hendricks2 567
    //The tileCreate should be called right after artLoadFiles
5327 hendricks2 568
    //Since it resets the tile cache for each call.
7540 hendricks2 569
    if (tileCreate(SLIME,128,128) == 0)    //If enough memory
5327 hendricks2 570
    {
571
        buildputs("Not enough memory for slime!\n");
572
        exit(0);
573
    }
7540 hendricks2 574
    if (tileCreate(MAXTILES-1,64,64) != 0)    //If enough memory
5327 hendricks2 575
    {
576
        //My face with an explosion written over it
7540 hendricks2 577
        tileCopySection(KENPICTURE,0,0,64,64,MAXTILES-1,0,0);
578
        tileCopySection(EXPLOSION,0,0,64,64,MAXTILES-1,0,0);
5327 hendricks2 579
    }
4555 hendricks2 580
 
5327 hendricks2 581
    initlava();
4555 hendricks2 582
 
5327 hendricks2 583
    for (j=0; j<256; j++)
584
        tempbuf[j] = ((j+32)&255);  //remap colors for screwy palette sectors
7540 hendricks2 585
    paletteMakeLookupTable(16,tempbuf,0,0,0,1);
4555 hendricks2 586
 
5327 hendricks2 587
    for (j=0; j<256; j++) tempbuf[j] = j;
7540 hendricks2 588
    paletteMakeLookupTable(17,tempbuf,96,96,96,1);
4555 hendricks2 589
 
5327 hendricks2 590
    for (j=0; j<256; j++) tempbuf[j] = j; //(j&31)+32;
7540 hendricks2 591
    paletteMakeLookupTable(18,tempbuf,32,32,192,1);
4555 hendricks2 592
 
7540 hendricks2 593
    palettePostLoadLookups();
5346 hendricks2 594
 
5327 hendricks2 595
    prepareboard(boardfilename);                   //Load board
4555 hendricks2 596
 
5327 hendricks2 597
    initsb(option[1],option[2],digihz[option[7]>>4],((option[7]&4)>0)+1,((option[7]&2)>0)+1,60,option[7]&1);
598
    //if (Bstrcmp(boardfilename,"klab.map") == 0)
599
    //   loadsong("klabsong.kdm");
600
    //else
601
    loadsong("neatsong.kdm");
602
    musicon();
4555 hendricks2 603
 
604
#if 0
5327 hendricks2 605
    if (option[4] > 0)
606
    {
607
        x1 = ((xdim-screensize)>>1);
608
        x2 = x1+screensize-1;
609
        y1 = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1);
610
        y2 = y1 + scale(screensize,ydim-32,xdim)-1;
4555 hendricks2 611
 
5327 hendricks2 612
        drawtilebackground(/*0L,0L,*/ BACKGROUND,8,x1,y1,x2,y2,0);
4555 hendricks2 613
 
5327 hendricks2 614
        sendlogon();
4555 hendricks2 615
 
5327 hendricks2 616
        if (option[4] < 5) waitplayers = 2; else waitplayers = option[4]-3;
617
        while (numplayers < waitplayers)
618
        {
619
            sprintf(tempbuf,"%ld of %ld players in...",numplayers,waitplayers);
620
            printext256(68L,84L,31,0,tempbuf,0);
7540 hendricks2 621
            videoNextPage();
4555 hendricks2 622
 
5327 hendricks2 623
            if (getpacket(&other,packbuf) > 0)
624
                if (packbuf[0] == 255)
625
                    keystatus[1] = 1;
4555 hendricks2 626
 
5327 hendricks2 627
            if (handleevents())
628
            {
629
                if (quitevent)
630
                {
631
                    keystatus[1] = 1;
632
                    quitevent = 0;
633
                }
634
            }
4555 hendricks2 635
 
5327 hendricks2 636
            if (keystatus[1])
637
            {
5345 hendricks2 638
                Ken_UninitAll();
639
                return 0;
5327 hendricks2 640
            }
641
        }
642
        screenpeek = myconnectindex;
4555 hendricks2 643
 
5327 hendricks2 644
        if (numplayers <= 3)
645
            networkmode = 1;
646
        else
647
            networkmode = 0;
4555 hendricks2 648
 
5327 hendricks2 649
        j = 1;
650
        for (i=connecthead; i>=0; i=connectpoint2[i])
651
        {
652
            if (myconnectindex == i) break;
653
            j++;
654
        }
655
        sprintf(getmessage,"Player %ld",j);
656
        if (networkmode == 0)
657
        {
658
            if (j == 1) Bstrcat(getmessage," (Master)");
659
            else Bstrcat(getmessage," (Slave)");
660
        }
661
        else
662
            Bstrcat(getmessage," (Even)");
663
        getmessageleng = Bstrlen(getmessage);
664
        getmessagetimeoff = totalclock+120;
665
    }
4555 hendricks2 666
#endif
5327 hendricks2 667
    screenpeek = myconnectindex;
668
    reccnt = 0;
669
    for (i=connecthead; i>=0; i=connectpoint2[i]) initplayersprite((short)i);
4555 hendricks2 670
 
5327 hendricks2 671
    waitforeverybody();
672
    totalclock = ototalclock = 0; gotlastpacketclock = 0; nummoves = 0;
4555 hendricks2 673
 
5327 hendricks2 674
    ready2send = 1;
675
    drawscreen(screenpeek,65536L);
4555 hendricks2 676
 
5327 hendricks2 677
    while (!keystatus[1])       //Main loop starts here
678
    {
679
        if (handleevents())
680
        {
681
            if (quitevent)
682
            {
683
                keystatus[1] = 1;
684
                quitevent = 0;
685
            }
686
        }
4555 hendricks2 687
 
5327 hendricks2 688
        refreshaudio();
689
        OSD_DispatchQueued();
4555 hendricks2 690
 
5327 hendricks2 691
        // backslash (useful only with KDM)
4555 hendricks2 692
//      if (keystatus[0x2b]) { keystatus[0x2b] = 0; preparesndbuf(); }
693
 
5327 hendricks2 694
        if ((networkmode == 1) || (myconnectindex != connecthead))
695
            while (fakemovefifoplc != movefifoend[myconnectindex]) fakedomovethings();
4555 hendricks2 696
 
5327 hendricks2 697
        getpackets();
4555 hendricks2 698
 
5327 hendricks2 699
        if (typemode == 0)           //if normal game keys active
700
        {
701
            if ((keystatus[0x2a]&keystatus[0x36]&keystatus[0x13]) > 0)   //Sh.Sh.R (replay)
702
            {
703
                keystatus[0x13] = 0;
704
                playback();
705
            }
4555 hendricks2 706
 
5327 hendricks2 707
            if (keystatus[0x26]&(keystatus[0x1d]|keystatus[0x9d])) //Load game
708
            {
709
                keystatus[0x26] = 0;
710
                loadgame();
711
                drawstatusbar(screenpeek);   // Andy did this
712
            }
4555 hendricks2 713
 
5327 hendricks2 714
            if (keystatus[0x1f]&(keystatus[0x1d]|keystatus[0x9d])) //Save game
715
            {
716
                keystatus[0x1f] = 0;
717
                savegame();
718
            }
719
        }
4555 hendricks2 720
 
5327 hendricks2 721
        if ((networkmode == 0) || (option[4] == 0))
722
        {
723
            while (movefifoplc != movefifoend[0]) domovethings();
724
        }
725
        else
726
        {
727
            j = connecthead;
728
            if (j == myconnectindex) j = connectpoint2[j];
729
            averagelag[j] = ((averagelag[j]*7+(((movefifoend[myconnectindex]-movefifoend[j]+otherlag[j]+2)&255)<<8))>>3);
730
            j = max(averagelag[j]>>9,1);
731
            while (((movefifoend[myconnectindex]-movefifoplc)&(MOVEFIFOSIZ-1)) > j)
732
            {
733
                for (i=connecthead; i>=0; i=connectpoint2[i])
734
                    if (movefifoplc == movefifoend[i]) break;
735
                if (i >= 0) break;
736
                if (myconnectindex != connecthead)
737
                {
738
                    k = ((movefifoend[myconnectindex]-movefifoend[connecthead]-otherlag[connecthead]+128)&255);
739
                    if (k > 128+1) ototalclock++;
740
                    if (k < 128-1) ototalclock--;
741
                }
742
                domovethings();
743
            }
744
        }
745
        i = (totalclock-gotlastpacketclock)*(65536/(TIMERINTSPERSECOND/MOVESPERSECOND));
4555 hendricks2 746
 
5327 hendricks2 747
        drawscreen(screenpeek,i);
748
    }
4555 hendricks2 749
 
5345 hendricks2 750
    Ken_UninitAll();
4555 hendricks2 751
 
5327 hendricks2 752
    return 0;
4555 hendricks2 753
}
754
 
755
void operatesector(short dasector)
5327 hendricks2 756
{
757
    //Door code
758
    int i, j, /*k, s, nexti, good, cnt,*/ datag;
759
    int /*dax, day,*/ daz, dax2, day2, /*daz2,*/ centx, centy;
760
    short startwall, endwall, wallfind[2];
4555 hendricks2 761
 
5327 hendricks2 762
    datag = sector[dasector].lotag;
4555 hendricks2 763
 
5327 hendricks2 764
    startwall = sector[dasector].wallptr;
765
    endwall = startwall + sector[dasector].wallnum;
766
    centx = 0L, centy = 0L;
767
    for (i=startwall; i<endwall; i++)
768
    {
769
        centx += wall[i].x;
770
        centy += wall[i].y;
771
    }
772
    centx /= (endwall-startwall);
773
    centy /= (endwall-startwall);
4555 hendricks2 774
 
5327 hendricks2 775
    //Simple door that moves up  (tag 8 is a combination of tags 6 & 7)
776
    if ((datag == 6) || (datag == 8))    //If the sector in front is a door
777
    {
778
        i = getanimationgoal(&sector[dasector].ceilingz);
779
        if (i >= 0)      //If door already moving, reverse its direction
780
        {
781
            if (datag == 8)
782
                daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
783
            else
784
                daz = sector[dasector].floorz;
4555 hendricks2 785
 
5327 hendricks2 786
            if (animategoal[i] == daz)
787
                animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;
788
            else
789
                animategoal[i] = daz;
790
            animatevel[i] = 0;
791
        }
792
        else      //else insert the door's ceiling on the animation list
793
        {
794
            if (sector[dasector].ceilingz == sector[dasector].floorz)
795
                daz = sector[nextsectorneighborz(dasector,sector[dasector].floorz,-1,-1)].ceilingz;
796
            else
797
            {
798
                if (datag == 8)
799
                    daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
800
                else
801
                    daz = sector[dasector].floorz;
802
            }
803
            if ((j = setanimation(&sector[dasector].ceilingz,daz,6L,6L)) >= 0)
804
                wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);
805
        }
806
    }
807
    //Simple door that moves down
808
    if ((datag == 7) || (datag == 8)) //If the sector in front's elevator
809
    {
810
        i = getanimationgoal(&sector[dasector].floorz);
811
        if (i >= 0)      //If elevator already moving, reverse its direction
812
        {
813
            if (datag == 8)
814
                daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
815
            else
816
                daz = sector[dasector].ceilingz;
4555 hendricks2 817
 
5327 hendricks2 818
            if (animategoal[i] == daz)
819
                animategoal[i] = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;
820
            else
821
                animategoal[i] = daz;
822
            animatevel[i] = 0;
823
        }
824
        else      //else insert the elevator's ceiling on the animation list
825
        {
826
            if (sector[dasector].floorz == sector[dasector].ceilingz)
827
                daz = sector[nextsectorneighborz(dasector,sector[dasector].ceilingz,1,1)].floorz;
828
            else
829
            {
830
                if (datag == 8)
831
                    daz = ((sector[dasector].ceilingz+sector[dasector].floorz)>>1);
832
                else
833
                    daz = sector[dasector].ceilingz;
834
            }
835
            if ((j = setanimation(&sector[dasector].floorz,daz,6L,6L)) >= 0)
836
                wsayfollow("updowndr.wav",4096L+(krand()&255)-128,256L,&centx,&centy,0);
837
        }
838
    }
4555 hendricks2 839
 
5327 hendricks2 840
    if (datag == 9)   //Smooshy-wall sideways double-door
841
    {
842
        //find any points with either same x or same y coordinate
843
        //  as center (centx, centy) - should be 2 points found.
844
        wallfind[0] = -1;
845
        wallfind[1] = -1;
846
        for (i=startwall; i<endwall; i++)
847
            if ((wall[i].x == centx) || (wall[i].y == centy))
848
            {
849
                if (wallfind[0] == -1)
850
                    wallfind[0] = i;
851
                else
852
                    wallfind[1] = i;
853
            }
4555 hendricks2 854
 
5327 hendricks2 855
        for (j=0; j<2; j++)
856
        {
857
            if ((wall[wallfind[j]].x == centx) && (wall[wallfind[j]].y == centy))
858
            {
859
                //find what direction door should open by averaging the
860
                //  2 neighboring points of wallfind[0] & wallfind[1].
861
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
862
                dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;
863
                day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;
864
                if (dax2 != 0)
865
                {
866
                    dax2 = wall[wall[wall[wallfind[j]].point2].point2].x;
867
                    dax2 -= wall[wall[wallfind[j]].point2].x;
868
                    setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
869
                    setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
870
                    setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
871
                }
872
                else if (day2 != 0)
873
                {
874
                    day2 = wall[wall[wall[wallfind[j]].point2].point2].y;
875
                    day2 -= wall[wall[wallfind[j]].point2].y;
876
                    setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
877
                    setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
878
                    setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
879
                }
880
            }
881
            else
882
            {
883
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
884
                dax2 = ((wall[i].x+wall[wall[wallfind[j]].point2].x)>>1)-wall[wallfind[j]].x;
885
                day2 = ((wall[i].y+wall[wall[wallfind[j]].point2].y)>>1)-wall[wallfind[j]].y;
886
                if (dax2 != 0)
887
                {
888
                    setanimation(&wall[wallfind[j]].x,centx,4L,0L);
889
                    setanimation(&wall[i].x,centx+dax2,4L,0L);
890
                    setanimation(&wall[wall[wallfind[j]].point2].x,centx+dax2,4L,0L);
891
                }
892
                else if (day2 != 0)
893
                {
894
                    setanimation(&wall[wallfind[j]].y,centy,4L,0L);
895
                    setanimation(&wall[i].y,centy+day2,4L,0L);
896
                    setanimation(&wall[wall[wallfind[j]].point2].y,centy+day2,4L,0L);
897
                }
898
            }
899
        }
900
        wsayfollow("updowndr.wav",4096L-256L,256L,&centx,&centy,0);
901
        wsayfollow("updowndr.wav",4096L+256L,256L,&centx,&centy,0);
902
    }
4555 hendricks2 903
 
5327 hendricks2 904
    if (datag == 13)  //Swinging door
905
    {
906
        for (i=0; i<swingcnt; i++)
907
        {
908
            if (swingsector[i] == dasector)
909
            {
910
                if (swinganginc[i] == 0)
911
                {
912
                    if (swingang[i] == swingangclosed[i])
913
                    {
914
                        swinganginc[i] = swingangopendir[i];
915
                        wsayfollow("opendoor.wav",4096L+(krand()&511)-256,256L,&centx,&centy,0);
916
                    }
917
                    else
918
                        swinganginc[i] = -swingangopendir[i];
919
                }
920
                else
921
                    swinganginc[i] = -swinganginc[i];
4555 hendricks2 922
 
5327 hendricks2 923
                for (j=1; j<=3; j++)
924
                {
925
                    setinterpolation(&wall[swingwall[i][j]].x);
926
                    setinterpolation(&wall[swingwall[i][j]].y);
927
                }
928
            }
929
        }
930
    }
4555 hendricks2 931
 
5327 hendricks2 932
    if (datag == 16)  //True sideways double-sliding door
933
    {
934
        //get 2 closest line segments to center (dax, day)
935
        wallfind[0] = -1;
936
        wallfind[1] = -1;
937
        for (i=startwall; i<endwall; i++)
938
            if (wall[i].lotag == 6)
939
            {
940
                if (wallfind[0] == -1)
941
                    wallfind[0] = i;
942
                else
943
                    wallfind[1] = i;
944
            }
4555 hendricks2 945
 
5327 hendricks2 946
        for (j=0; j<2; j++)
947
        {
948
            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))
949
            {
950
                //door was closed
951
                //find what direction door should open
952
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
953
                dax2 = wall[i].x-wall[wallfind[j]].x;
954
                day2 = wall[i].y-wall[wallfind[j]].y;
955
                if (dax2 != 0)
956
                {
957
                    dax2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].x;
958
                    dax2 -= wall[wall[wall[wallfind[j]].point2].point2].x;
959
                    setanimation(&wall[wallfind[j]].x,wall[wallfind[j]].x+dax2,4L,0L);
960
                    setanimation(&wall[i].x,wall[i].x+dax2,4L,0L);
961
                    setanimation(&wall[wall[wallfind[j]].point2].x,wall[wall[wallfind[j]].point2].x+dax2,4L,0L);
962
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,wall[wall[wall[wallfind[j]].point2].point2].x+dax2,4L,0L);
963
                }
964
                else if (day2 != 0)
965
                {
966
                    day2 = wall[wall[wall[wall[wallfind[j]].point2].point2].point2].y;
967
                    day2 -= wall[wall[wall[wallfind[j]].point2].point2].y;
968
                    setanimation(&wall[wallfind[j]].y,wall[wallfind[j]].y+day2,4L,0L);
969
                    setanimation(&wall[i].y,wall[i].y+day2,4L,0L);
970
                    setanimation(&wall[wall[wallfind[j]].point2].y,wall[wall[wallfind[j]].point2].y+day2,4L,0L);
971
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,wall[wall[wall[wallfind[j]].point2].point2].y+day2,4L,0L);
972
                }
973
            }
974
            else
975
            {
976
                //door was not closed
977
                i = wallfind[j]-1; if (i < startwall) i = endwall-1;
978
                dax2 = wall[i].x-wall[wallfind[j]].x;
979
                day2 = wall[i].y-wall[wallfind[j]].y;
980
                if (dax2 != 0)
981
                {
982
                    setanimation(&wall[wallfind[j]].x,centx,4L,0L);
983
                    setanimation(&wall[i].x,centx+dax2,4L,0L);
984
                    setanimation(&wall[wall[wallfind[j]].point2].x,centx,4L,0L);
985
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].x,centx+dax2,4L,0L);
986
                }
987
                else if (day2 != 0)
988
                {
989
                    setanimation(&wall[wallfind[j]].y,centy,4L,0L);
990
                    setanimation(&wall[i].y,centy+day2,4L,0L);
991
                    setanimation(&wall[wall[wallfind[j]].point2].y,centy,4L,0L);
992
                    setanimation(&wall[wall[wall[wallfind[j]].point2].point2].y,centy+day2,4L,0L);
993
                }
994
            }
995
        }
996
        wsayfollow("updowndr.wav",4096L-64L,256L,&centx,&centy,0);
997
        wsayfollow("updowndr.wav",4096L+64L,256L,&centx,&centy,0);
998
    }
4555 hendricks2 999
}
1000
 
1001
void operatesprite(short dasprite)
1002
{
5327 hendricks2 1003
    int datag;
4555 hendricks2 1004
 
5327 hendricks2 1005
    datag = sprite[dasprite].lotag;
4555 hendricks2 1006
 
5327 hendricks2 1007
    if (datag == 2)    //A sprite that shoots a bomb
1008
    {
4555 hendricks2 1009
        vec3_t vector = { sprite[dasprite].x,sprite[dasprite].y,sprite[dasprite].z };
5327 hendricks2 1010
        shootgun(dasprite, &vector,
1011
                 sprite[dasprite].ang,100L,sprite[dasprite].sectnum,2);
1012
    }
4555 hendricks2 1013
}
1014
 
1015
int changehealth(short snum, short deltahealth)
1016
{
5327 hendricks2 1017
    // int dax, day;
1018
    // short good, k, startwall, endwall, s;
4555 hendricks2 1019
 
5327 hendricks2 1020
    if (health[snum] > 0)
1021
    {
1022
        health[snum] += deltahealth;
1023
        if (health[snum] > 999) health[snum] = 999;
4555 hendricks2 1024
 
5327 hendricks2 1025
        if (health[snum] <= 0)
1026
        {
1027
            health[snum] = -1;
1028
            wsayfollow("death.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1029
            sprite[playersprite[snum]].picnum = SKELETON;
1030
        }
4555 hendricks2 1031
 
5327 hendricks2 1032
        if ((snum == screenpeek) && (screensize <= xdim))
1033
        {
1034
            if (health[snum] > 0)
1035
                sprintf((char *)tempbuf,"Health:%3d",health[snum]);
1036
            else
1037
                sprintf((char *)tempbuf,"YOU STINK!");
4555 hendricks2 1038
 
5327 hendricks2 1039
            printext((xdim>>1)-(Bstrlen((char *)tempbuf)<<2),ydim-24,(char *)tempbuf,ALPHABET /*,80*/);
1040
        }
1041
    }
1042
    return health[snum] <= 0;       //You were just injured
4555 hendricks2 1043
}
1044
 
5327 hendricks2 1045
void changenumbombs(short snum, short deltanumbombs)     // Andy did this
1046
{
1047
    numbombs[snum] += deltanumbombs;
1048
    if (numbombs[snum] > 999) numbombs[snum] = 999;
1049
    if (numbombs[snum] <= 0)
1050
    {
1051
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1052
        numbombs[snum] = 0;
1053
    }
4555 hendricks2 1054
 
5327 hendricks2 1055
    if ((snum == screenpeek) && (screensize <= xdim))
1056
    {
1057
        sprintf((char *)tempbuf,"B:%3d",numbombs[snum]);
1058
        printext(8L,(ydim - 28L),(char *)tempbuf,ALPHABET /*,80*/);
1059
    }
4555 hendricks2 1060
}
1061
 
5327 hendricks2 1062
void changenummissiles(short snum, short deltanummissiles)     // Andy did this
1063
{
1064
    nummissiles[snum] += deltanummissiles;
1065
    if (nummissiles[snum] > 999) nummissiles[snum] = 999;
1066
    if (nummissiles[snum] <= 0)
1067
    {
1068
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1069
        nummissiles[snum] = 0;
1070
    }
4555 hendricks2 1071
 
5327 hendricks2 1072
    if ((snum == screenpeek) && (screensize <= xdim))
1073
    {
1074
        sprintf((char *)tempbuf,"M:%3d",nummissiles[snum]);
1075
        printext(8L,(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1076
    }
4555 hendricks2 1077
}
1078
 
5327 hendricks2 1079
void changenumgrabbers(short snum, short deltanumgrabbers)     // Andy did this
1080
{
1081
    numgrabbers[snum] += deltanumgrabbers;
1082
    if (numgrabbers[snum] > 999) numgrabbers[snum] = 999;
1083
    if (numgrabbers[snum] <= 0)
1084
    {
1085
        wsayfollow("doh.wav",4096L+(krand()&127)-64,256L,&pos[snum].x,&pos[snum].y,1);
1086
        numgrabbers[snum] = 0;
1087
    }
4555 hendricks2 1088
 
5327 hendricks2 1089
    if ((snum == screenpeek) && (screensize <= xdim))
1090
    {
1091
        sprintf((char *)tempbuf,"G:%3d",numgrabbers[snum]);
1092
        printext(8L,(ydim - 12L),(char *)tempbuf,ALPHABET /*,80*/);
1093
    }
4555 hendricks2 1094
}
1095
 
1096
static int ostatusflytime = 0x80000000;
5327 hendricks2 1097
void drawstatusflytime(short snum)     // Andy did this
1098
{
1099
    int nstatusflytime;
4555 hendricks2 1100
 
5327 hendricks2 1101
    if ((snum == screenpeek) && (screensize <= xdim))
1102
    {
1103
        nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
1104
        if (nstatusflytime > 1000) nstatusflytime = 1000;
1105
        else if (nstatusflytime < 0) nstatusflytime = 0;
1106
        if (nstatusflytime != ostatusflytime)
1107
        {
1108
            if (nstatusflytime > 999) sprintf((char *)tempbuf,"FT:BIG");
1109
            else sprintf((char *)tempbuf,"FT:%3d",nstatusflytime);
1110
            printext((xdim - 56L),(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1111
            ostatusflytime = nstatusflytime;
1112
        }
1113
    }
4555 hendricks2 1114
}
1115
 
5327 hendricks2 1116
void drawstatusbar(short snum)     // Andy did this
1117
{
1118
    int nstatusflytime;
4555 hendricks2 1119
 
5327 hendricks2 1120
    if ((snum == screenpeek) && (screensize <= xdim))
1121
    {
1122
        sprintf((char *)tempbuf,"Deaths:%d",deaths[snum]);
1123
        printext((xdim>>1)-(strlen((char *)tempbuf)<<2),ydim-16,(char *)tempbuf,ALPHABET /*,80*/);
1124
        sprintf((char *)tempbuf,"Health:%3d",health[snum]);
1125
        printext((xdim>>1)-(strlen((char *)tempbuf)<<2),ydim-24,(char *)tempbuf,ALPHABET /*,80*/);
4555 hendricks2 1126
 
5327 hendricks2 1127
        sprintf((char *)tempbuf,"B:%3d",numbombs[snum]);
1128
        printext(8L,(ydim - 28L),(char *)tempbuf,ALPHABET /*,80*/);
1129
        sprintf((char *)tempbuf,"M:%3d",nummissiles[snum]);
1130
        printext(8L,(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1131
        sprintf((char *)tempbuf,"G:%3d",numgrabbers[snum]);
1132
        printext(8L,(ydim - 12L),(char *)tempbuf,ALPHABET /*,80*/);
4555 hendricks2 1133
 
5327 hendricks2 1134
        nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
1135
        if (nstatusflytime < 0)
1136
        {
1137
            sprintf((char *)tempbuf,"FT:  0");
1138
            ostatusflytime = 0;
1139
        }
1140
        else if (nstatusflytime > 999)
1141
        {
1142
            sprintf((char *)tempbuf,"FT:BIG");
1143
            ostatusflytime = 999;
1144
        }
1145
        else
1146
        {
1147
            sprintf((char *)tempbuf,"FT:%3d",nstatusflytime);
1148
            ostatusflytime = nstatusflytime;
1149
        }
1150
        printext((xdim - 56L),(ydim - 20L),(char *)tempbuf,ALPHABET /*,80*/);
1151
    }
4555 hendricks2 1152
}
1153
 
1154
void prepareboard(char *daboardfilename)
1155
{
5327 hendricks2 1156
    short startwall, endwall, dasector;
1157
    int i, j, k=0, s, dax, day, /*daz,*/ dax2, day2;
4555 hendricks2 1158
 
5327 hendricks2 1159
    getmessageleng = 0;
1160
    typemessageleng = 0;
4555 hendricks2 1161
 
5327 hendricks2 1162
    randomseed = 17L;
4555 hendricks2 1163
 
5327 hendricks2 1164
    //Clear (do)animation's list
1165
    animatecnt = 0;
1166
    typemode = 0;
1167
    locselectedgun = 0;
1168
    locselectedgun2 = 0;
4555 hendricks2 1169
 
7540 hendricks2 1170
    if (engineLoadBoard(daboardfilename,0,&pos[0],&ang[0],&cursectnum[0]) == -1)
5327 hendricks2 1171
    {
1172
        musicoff();
1173
        uninitmultiplayers();
7540 hendricks2 1174
        timerUninit();
5327 hendricks2 1175
        uninitinput();
7540 hendricks2 1176
        engineUnInit();
5327 hendricks2 1177
        uninitsb();
1178
        uninitgroupfile();
1179
        printf("Board not found\n");
1180
        exit(0);
1181
    }
1182
    else
1183
    {
1184
        char tempfn[BMAX_PATH + 1], *fp;
4555 hendricks2 1185
 
5327 hendricks2 1186
        strncpy(tempfn, daboardfilename, BMAX_PATH);
1187
        tempfn[BMAX_PATH] = 0;
4555 hendricks2 1188
 
5327 hendricks2 1189
        fp = strrchr(tempfn,'.');
1190
        if (fp) *fp = 0;
4555 hendricks2 1191
 
5327 hendricks2 1192
        if (strlen(tempfn) <= BMAX_PATH-4)
1193
        {
1194
            strcat(tempfn,".mhk");
7540 hendricks2 1195
            engineLoadMHK(tempfn);
5327 hendricks2 1196
        }
1197
    }
4555 hendricks2 1198
 
5327 hendricks2 1199
    setup3dscreen();
4555 hendricks2 1200
 
5327 hendricks2 1201
    for (i=0; i<MAXPLAYERS; i++)
1202
    {
1203
        pos[i] = pos[0];
1204
        ang[i] = ang[0];
1205
        cursectnum[i] = cursectnum[0];
1206
        ocursectnum[i] = cursectnum[0];
1207
        horiz[i] = 100;
1208
        lastchaingun[i] = 0;
1209
        health[i] = 100;
1210
        dimensionmode[i] = 3;
1211
        numbombs[i] = 0;
1212
        numgrabbers[i] = 0;
1213
        nummissiles[i] = 0;
1214
        flytime[i] = 0L;
1215
        zoom[i] = 768L;
1216
        deaths[i] = 0L;
1217
        playersprite[i] = -1;
1218
        screensize = xdim;
4555 hendricks2 1219
 
5327 hendricks2 1220
        opos[i] = pos[0];
1221
        ohoriz[i] = horiz[0];
1222
        ozoom[i] = zoom[0];
1223
        oang[i] = ang[0];
1224
    }
4555 hendricks2 1225
 
5327 hendricks2 1226
    my = omy = pos[myconnectindex];
1227
    myhoriz = omyhoriz = horiz[myconnectindex];
1228
    myang = omyang = ang[myconnectindex];
1229
    mycursectnum = cursectnum[myconnectindex];
1230
    myzvel = 0;
4555 hendricks2 1231
 
5327 hendricks2 1232
    movefifoplc = fakemovefifoplc = 0;
1233
    syncvalhead = 0L; othersyncvalhead = 0L;
1234
    syncvaltottail = 0L; syncvaltail = 0L;
1235
    numinterpolations = 0;
4555 hendricks2 1236
 
5327 hendricks2 1237
    clearbufbyte(&oloc,sizeof(input),0L);
1238
    for (i=0; i<MAXPLAYERS; i++)
1239
    {
1240
        movefifoend[i] = 0;
1241
        clearbufbyte(&ffsync[i],sizeof(input),0L);
1242
        clearbufbyte(&ssync[i],sizeof(input),0L);
1243
        clearbufbyte(&osync[i],sizeof(input),0L);
1244
    }
4555 hendricks2 1245
 
5327 hendricks2 1246
    //Scan sector tags
4555 hendricks2 1247
 
5327 hendricks2 1248
    for (i=0; i<MAXPLAYERS; i++)
1249
    {
1250
        waterfountainwall[i] = -1;
1251
        waterfountaincnt[i] = 0;
1252
        slimesoundcnt[i] = 0;
1253
    }
1254
    warpsectorcnt = 0;      //Make a list of warping sectors
1255
    xpanningsectorcnt = 0;  //Make a list of wall x-panning sectors
1256
    floorpanningcnt = 0;    //Make a list of slime sectors
1257
    dragsectorcnt = 0;      //Make a list of moving platforms
1258
    swingcnt = 0;           //Make a list of swinging doors
1259
    revolvecnt = 0;         //Make a list of revolving doors
1260
    subwaytrackcnt = 0;     //Make a list of subways
4555 hendricks2 1261
 
5327 hendricks2 1262
    floormirrorcnt = 0;
1263
    tilesiz[FLOORMIRROR].x = 0;
1264
    tilesiz[FLOORMIRROR].y = 0;
4555 hendricks2 1265
 
5327 hendricks2 1266
    for (i=0; i<numsectors; i++)
1267
    {
1268
        switch (sector[i].lotag)
1269
        {
1270
        case 4:
1271
            floorpanninglist[floorpanningcnt++] = i;
1272
            break;
1273
        case 10:
1274
            warpsectorlist[warpsectorcnt++] = i;
1275
            break;
1276
        case 11:
1277
            xpanningsectorlist[xpanningsectorcnt++] = i;
1278
            break;
1279
        case 12:
1280
            dasector = i;
1281
            dax = 0x7fffffff;
1282
            day = 0x7fffffff;
1283
            dax2 = 0x80000000;
1284
            day2 = 0x80000000;
1285
            startwall = sector[i].wallptr;
1286
            endwall = startwall+sector[i].wallnum;
1287
            for (j=startwall; j<endwall; j++)
1288
            {
1289
                if (wall[j].x < dax) dax = wall[j].x;
1290
                if (wall[j].y < day) day = wall[j].y;
1291
                if (wall[j].x > dax2) dax2 = wall[j].x;
1292
                if (wall[j].y > day2) day2 = wall[j].y;
1293
                if (wall[j].lotag == 3) k = j;
1294
            }
1295
            if (wall[k].x == dax) dragxdir[dragsectorcnt] = -16;
1296
            if (wall[k].y == day) dragydir[dragsectorcnt] = -16;
1297
            if (wall[k].x == dax2) dragxdir[dragsectorcnt] = 16;
1298
            if (wall[k].y == day2) dragydir[dragsectorcnt] = 16;
4555 hendricks2 1299
 
5327 hendricks2 1300
            dasector = wall[startwall].nextsector;
1301
            dragx1[dragsectorcnt] = 0x7fffffff;
1302
            dragy1[dragsectorcnt] = 0x7fffffff;
1303
            dragx2[dragsectorcnt] = 0x80000000;
1304
            dragy2[dragsectorcnt] = 0x80000000;
1305
            startwall = sector[dasector].wallptr;
1306
            endwall = startwall+sector[dasector].wallnum;
1307
            for (j=startwall; j<endwall; j++)
1308
            {
1309
                if (wall[j].x < dragx1[dragsectorcnt]) dragx1[dragsectorcnt] = wall[j].x;
1310
                if (wall[j].y < dragy1[dragsectorcnt]) dragy1[dragsectorcnt] = wall[j].y;
1311
                if (wall[j].x > dragx2[dragsectorcnt]) dragx2[dragsectorcnt] = wall[j].x;
1312
                if (wall[j].y > dragy2[dragsectorcnt]) dragy2[dragsectorcnt] = wall[j].y;
4555 hendricks2 1313
 
5327 hendricks2 1314
                setinterpolation(&sector[dasector].floorz);
1315
                setinterpolation(&wall[j].x);
1316
                setinterpolation(&wall[j].y);
7541 hendricks2 1317
                auto const nextwall = wall[j].nextwall;
1318
                if ((unsigned)nextwall < MAXWALLS)
1319
                {
1320
                    setinterpolation(&wall[nextwall].x);
1321
                    setinterpolation(&wall[nextwall].y);
1322
                }
5327 hendricks2 1323
            }
4555 hendricks2 1324
 
5327 hendricks2 1325
            dragx1[dragsectorcnt] += (wall[sector[i].wallptr].x-dax);
1326
            dragy1[dragsectorcnt] += (wall[sector[i].wallptr].y-day);
1327
            dragx2[dragsectorcnt] -= (dax2-wall[sector[i].wallptr].x);
1328
            dragy2[dragsectorcnt] -= (day2-wall[sector[i].wallptr].y);
4555 hendricks2 1329
 
5327 hendricks2 1330
            dragfloorz[dragsectorcnt] = sector[i].floorz;
4555 hendricks2 1331
 
5327 hendricks2 1332
            dragsectorlist[dragsectorcnt++] = i;
1333
            break;
1334
        case 13:
1335
            startwall = sector[i].wallptr;
1336
            endwall = startwall+sector[i].wallnum;
1337
            for (j=startwall; j<endwall; j++)
1338
            {
1339
                if (wall[j].lotag == 4)
1340
                {
1341
                    k = wall[wall[wall[wall[j].point2].point2].point2].point2;
1342
                    if ((wall[j].x == wall[k].x) && (wall[j].y == wall[k].y))
1343
                    {
1344
                        //Door opens counterclockwise
1345
                        swingwall[swingcnt][0] = j;
1346
                        swingwall[swingcnt][1] = wall[j].point2;
1347
                        swingwall[swingcnt][2] = wall[wall[j].point2].point2;
1348
                        swingwall[swingcnt][3] = wall[wall[wall[j].point2].point2].point2;
1349
                        swingangopen[swingcnt] = 1536;
1350
                        swingangclosed[swingcnt] = 0;
1351
                        swingangopendir[swingcnt] = -1;
1352
                    }
1353
                    else
1354
                    {
1355
                        //Door opens clockwise
1356
                        swingwall[swingcnt][0] = wall[j].point2;
1357
                        swingwall[swingcnt][1] = j;
1358
                        swingwall[swingcnt][2] = lastwall(j);
1359
                        swingwall[swingcnt][3] = lastwall(swingwall[swingcnt][2]);
1360
                        swingwall[swingcnt][4] = lastwall(swingwall[swingcnt][3]);
1361
                        swingangopen[swingcnt] = 512;
1362
                        swingangclosed[swingcnt] = 0;
1363
                        swingangopendir[swingcnt] = 1;
1364
                    }
1365
                    for (k=0; k<4; k++)
1366
                    {
1367
                        swingx[swingcnt][k] = wall[swingwall[swingcnt][k]].x;
1368
                        swingy[swingcnt][k] = wall[swingwall[swingcnt][k]].y;
1369
                    }
4555 hendricks2 1370
 
5327 hendricks2 1371
                    swingsector[swingcnt] = i;
1372
                    swingang[swingcnt] = swingangclosed[swingcnt];
1373
                    swinganginc[swingcnt] = 0;
1374
                    swingcnt++;
1375
                }
1376
            }
1377
            break;
1378
        case 14:
1379
            startwall = sector[i].wallptr;
1380
            endwall = startwall+sector[i].wallnum;
1381
            dax = 0L;
1382
            day = 0L;
1383
            for (j=startwall; j<endwall; j++)
1384
            {
1385
                dax += wall[j].x;
1386
                day += wall[j].y;
1387
            }
1388
            revolvepivotx[revolvecnt] = dax / (endwall-startwall);
1389
            revolvepivoty[revolvecnt] = day / (endwall-startwall);
4555 hendricks2 1390
 
5327 hendricks2 1391
            k = 0;
1392
            for (j=startwall; j<endwall; j++)
1393
            {
1394
                revolvex[revolvecnt][k] = wall[j].x;
1395
                revolvey[revolvecnt][k] = wall[j].y;
4555 hendricks2 1396
 
5327 hendricks2 1397
                setinterpolation(&wall[j].x);
1398
                setinterpolation(&wall[j].y);
1399
                setinterpolation(&wall[wall[j].nextwall].x);
1400
                setinterpolation(&wall[wall[j].nextwall].y);
4555 hendricks2 1401
 
5327 hendricks2 1402
                k++;
1403
            }
1404
            revolvesector[revolvecnt] = i;
1405
            revolveang[revolvecnt] = 0;
4555 hendricks2 1406
 
5327 hendricks2 1407
            revolvecnt++;
1408
            break;
1409
        case 15:
1410
            subwaytracksector[subwaytrackcnt][0] = i;
4555 hendricks2 1411
 
5327 hendricks2 1412
            subwaystopcnt[subwaytrackcnt] = 0;
1413
            dax = 0x7fffffff;
1414
            day = 0x7fffffff;
1415
            dax2 = 0x80000000;
1416
            day2 = 0x80000000;
1417
            startwall = sector[i].wallptr;
1418
            endwall = startwall+sector[i].wallnum;
1419
            for (j=startwall; j<endwall; j++)
1420
            {
1421
                if (wall[j].x < dax) dax = wall[j].x;
1422
                if (wall[j].y < day) day = wall[j].y;
1423
                if (wall[j].x > dax2) dax2 = wall[j].x;
1424
                if (wall[j].y > day2) day2 = wall[j].y;
1425
            }
1426
            for (j=startwall; j<endwall; j++)
1427
            {
1428
                if (wall[j].lotag == 5)
1429
                {
1430
                    if ((wall[j].x > dax) && (wall[j].y > day) && (wall[j].x < dax2) && (wall[j].y < day2))
1431
                    {
1432
                        subwayx[subwaytrackcnt] = wall[j].x;
1433
                    }
1434
                    else
1435
                    {
1436
                        subwaystop[subwaytrackcnt][subwaystopcnt[subwaytrackcnt]] = wall[j].x;
1437
                        subwaystopcnt[subwaytrackcnt]++;
1438
                    }
1439
                }
1440
            }
4555 hendricks2 1441
 
5327 hendricks2 1442
            for (j=1; j<subwaystopcnt[subwaytrackcnt]; j++)
1443
                for (k=0; k<j; k++)
1444
                    if (subwaystop[subwaytrackcnt][j] < subwaystop[subwaytrackcnt][k])
1445
                    {
1446
                        s = subwaystop[subwaytrackcnt][j];
1447
                        subwaystop[subwaytrackcnt][j] = subwaystop[subwaytrackcnt][k];
1448
                        subwaystop[subwaytrackcnt][k] = s;
1449
                    }
4555 hendricks2 1450
 
5327 hendricks2 1451
            subwaygoalstop[subwaytrackcnt] = 0;
1452
            for (j=0; j<subwaystopcnt[subwaytrackcnt]; j++)
1453
                if (klabs(subwaystop[subwaytrackcnt][j]-subwayx[subwaytrackcnt]) < klabs(subwaystop[subwaytrackcnt][subwaygoalstop[subwaytrackcnt]]-subwayx[subwaytrackcnt]))
1454
                    subwaygoalstop[subwaytrackcnt] = j;
4555 hendricks2 1455
 
5327 hendricks2 1456
            subwaytrackx1[subwaytrackcnt] = dax;
1457
            subwaytracky1[subwaytrackcnt] = day;
1458
            subwaytrackx2[subwaytrackcnt] = dax2;
1459
            subwaytracky2[subwaytrackcnt] = day2;
4555 hendricks2 1460
 
5327 hendricks2 1461
            subwaynumsectors[subwaytrackcnt] = 1;
1462
            for (j=0; j<numsectors; j++)
1463
                if (j != i)
1464
                {
1465
                    startwall = sector[j].wallptr;
1466
                    if (wall[startwall].x > subwaytrackx1[subwaytrackcnt])
1467
                        if (wall[startwall].y > subwaytracky1[subwaytrackcnt])
1468
                            if (wall[startwall].x < subwaytrackx2[subwaytrackcnt])
1469
                                if (wall[startwall].y < subwaytracky2[subwaytrackcnt])
1470
                                {
1471
                                    if (sector[j].floorz != sector[i].floorz)
1472
                                    {
1473
                                        sector[j].ceilingstat |= 64;
1474
                                        sector[j].floorstat |= 64;
1475
                                    }
1476
                                    subwaytracksector[subwaytrackcnt][subwaynumsectors[subwaytrackcnt]] = j;
1477
                                    subwaynumsectors[subwaytrackcnt]++;
1478
                                }
1479
                }
4555 hendricks2 1480
 
5327 hendricks2 1481
            subwayvel[subwaytrackcnt] = 64;
1482
            subwaypausetime[subwaytrackcnt] = 720;
4555 hendricks2 1483
 
5327 hendricks2 1484
            startwall = sector[i].wallptr;
1485
            endwall = startwall+sector[i].wallnum;
1486
            for (k=startwall; k<endwall; k++)
1487
                if (wall[k].x > subwaytrackx1[subwaytrackcnt])
1488
                    if (wall[k].y > subwaytracky1[subwaytrackcnt])
1489
                        if (wall[k].x < subwaytrackx2[subwaytrackcnt])
1490
                            if (wall[k].y < subwaytracky2[subwaytrackcnt])
1491
                                setinterpolation(&wall[k].x);
4555 hendricks2 1492
 
5327 hendricks2 1493
            for (j=1; j<subwaynumsectors[subwaytrackcnt]; j++)
1494
            {
1495
                dasector = subwaytracksector[subwaytrackcnt][j];
4555 hendricks2 1496
 
5327 hendricks2 1497
                startwall = sector[dasector].wallptr;
1498
                endwall = startwall+sector[dasector].wallnum;
1499
                for (k=startwall; k<endwall; k++)
1500
                    setinterpolation(&wall[k].x);
4555 hendricks2 1501
 
5327 hendricks2 1502
                for (k=headspritesect[dasector]; k>=0; k=nextspritesect[k])
1503
                    if (statrate[sprite[k].statnum] < 0)
1504
                        setinterpolation(&sprite[k].x);
1505
            }
4555 hendricks2 1506
 
1507
 
5327 hendricks2 1508
            subwaytrackcnt++;
1509
            break;
1510
        }
1511
        if (sector[i].floorpicnum == FLOORMIRROR)
1512
            floormirrorsector[mirrorcnt++] = i;
1513
        //if (sector[i].ceilingpicnum == FLOORMIRROR) floormirrorsector[mirrorcnt++] = i; //SOS
1514
    }
4555 hendricks2 1515
 
5327 hendricks2 1516
    //Scan wall tags
4555 hendricks2 1517
 
5327 hendricks2 1518
    mirrorcnt = 0;
1519
    tilesiz[MIRROR].x = 0;
1520
    tilesiz[MIRROR].y = 0;
1521
    for (i=0; i<MAXMIRRORS; i++)
1522
    {
1523
        tilesiz[i+MIRRORLABEL].x = 0;
1524
        tilesiz[i+MIRRORLABEL].y = 0;
1525
    }
4555 hendricks2 1526
 
5327 hendricks2 1527
    ypanningwallcnt = 0;
1528
    for (i=0; i<numwalls; i++)
1529
    {
1530
        if (wall[i].lotag == 1) ypanningwalllist[ypanningwallcnt++] = i;
1531
        s = wall[i].nextsector;
1532
        if ((s >= 0) && (wall[i].overpicnum == MIRROR) && (wall[i].cstat&32))
1533
        {
1534
            if ((sector[s].floorstat&1) == 0)
1535
            {
1536
                wall[i].overpicnum = MIRRORLABEL+mirrorcnt;
1537
                sector[s].ceilingpicnum = MIRRORLABEL+mirrorcnt;
1538
                sector[s].floorpicnum = MIRRORLABEL+mirrorcnt;
1539
                sector[s].floorstat |= 1;
1540
                mirrorwall[mirrorcnt] = i;
1541
                mirrorsector[mirrorcnt] = s;
1542
                mirrorcnt++;
1543
            }
1544
            else
1545
                wall[i].overpicnum = sector[s].ceilingpicnum;
1546
        }
1547
    }
4555 hendricks2 1548
 
5327 hendricks2 1549
    //Invalidate textures in sector behind mirror
1550
    for (i=0; i<mirrorcnt; i++)
1551
    {
1552
        k = mirrorsector[i];
1553
        startwall = sector[k].wallptr;
1554
        endwall = startwall + sector[k].wallnum;
1555
        for (j=startwall; j<endwall; j++)
1556
        {
1557
            wall[j].picnum = MIRROR;
1558
            wall[j].overpicnum = MIRROR;
1559
        }
1560
    }
4555 hendricks2 1561
 
5327 hendricks2 1562
    //Scan sprite tags&picnum's
4555 hendricks2 1563
 
5327 hendricks2 1564
    turnspritecnt = 0;
1565
    for (i=0; i<MAXSPRITES; i++)
1566
    {
1567
        if (sprite[i].lotag == 3) turnspritelist[turnspritecnt++] = i;
4555 hendricks2 1568
 
5327 hendricks2 1569
        if (sprite[i].statnum < MAXSTATUS)    //That is, if sprite exists
1570
            switch (sprite[i].picnum)
1571
            {
1572
            case BROWNMONSTER:              //All cases here put the sprite
1573
                if ((sprite[i].cstat&128) == 0)
1574
                {
1575
                    sprite[i].z -= ((tilesiz[sprite[i].picnum].y*sprite[i].yrepeat)<<1);
1576
                    sprite[i].cstat |= 128;
1577
                }
1578
                sprite[i].extra = sprite[i].ang;
1579
                sprite[i].clipdist = mulscale7(sprite[i].xrepeat,tilesiz[sprite[i].picnum].x);
1580
                if (sprite[i].statnum != 1) changespritestat(i,2);   //on waiting for you (list 2)
1581
                sprite[i].lotag = mulscale5(sprite[i].xrepeat,sprite[i].yrepeat);
1582
                sprite[i].cstat |= 0x101;    //Set the hitscan sensitivity bit
1583
                break;
1584
            case AL:
1585
                sprite[i].cstat |= 0x101;    //Set the hitscan sensitivity bit
1586
                sprite[i].lotag = 0x60;
1587
                changespritestat(i,0);
1588
                break;
1589
            case EVILAL:
1590
                sprite[i].cstat |= 0x101;    //Set the hitscan sensitivity bit
1591
                sprite[i].lotag = 0x60;
1592
                changespritestat(i,10);
1593
                break;
1594
            }
1595
    }
4555 hendricks2 1596
 
5327 hendricks2 1597
    for (i=MAXSPRITES-1; i>=0; i--) copybuf(&sprite[i].x,&osprite[i].x,3);
4555 hendricks2 1598
 
5327 hendricks2 1599
    searchmap(cursectnum[connecthead]);
4555 hendricks2 1600
 
5327 hendricks2 1601
    lockclock = 0;
1602
    ototalclock = 0;
1603
    gotlastpacketclock = 0;
4555 hendricks2 1604
 
5327 hendricks2 1605
    screensize = xdim;
1606
    dax = ((xdim-screensize)>>1);
1607
    dax2 = dax+screensize-1;
1608
    day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1);
1609
    day2 = day + scale(screensize,ydim-32,xdim)-1;
7540 hendricks2 1610
    videoSetViewableArea(dax,day,dax2,day2);
4555 hendricks2 1611
 
5327 hendricks2 1612
    startofdynamicinterpolations = numinterpolations;
4555 hendricks2 1613
 
1614
#if 0
5327 hendricks2 1615
    for (i=connecthead; i>=0; i=connectpoint2[i]) myminlag[i] = 0;
1616
    otherminlag = mymaxlag = 0;
4555 hendricks2 1617
#endif
1618
}
1619
 
1620
void checktouchsprite(short snum, short sectnum)
1621
{
5327 hendricks2 1622
    int i, nexti;
4555 hendricks2 1623
 
5327 hendricks2 1624
    if ((sectnum < 0) || (sectnum >= numsectors)) return;
4555 hendricks2 1625
 
5327 hendricks2 1626
    for (i=headspritesect[sectnum]; i>=0; i=nexti)
1627
    {
1628
        nexti = nextspritesect[i];
1629
        if (sprite[i].cstat&0x8000) continue;
1630
        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))
1631
        {
1632
            switch (sprite[i].picnum)
1633
            {
1634
            case COIN:
1635
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0);
1636
                changehealth(snum,5);
1637
                if (sprite[i].statnum == 12) deletesprite((short)i);
1638
                else
1639
                {
1640
                    sprite[i].cstat |= 0x8000;
1641
                    sprite[i].extra = 120*60;
1642
                    changespritestat((short)i,11);
1643
                }
1644
                break;
1645
            case DIAMONDS:
1646
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1647
                changehealth(snum,15);
1648
                if (sprite[i].statnum == 12) deletesprite((short)i);
1649
                else
1650
                {
1651
                    sprite[i].cstat |= 0x8000;
1652
                    sprite[i].extra = 120*120;
1653
                    changespritestat((short)i,11);
1654
                }
1655
                break;
1656
            case COINSTACK:
1657
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1658
                changehealth(snum,25);
1659
                if (sprite[i].statnum == 12) deletesprite((short)i);
1660
                else
1661
                {
1662
                    sprite[i].cstat |= 0x8000;
1663
                    sprite[i].extra = 120*180;
1664
                    changespritestat((short)i,11);
1665
                }
1666
                break;
1667
            case GIFTBOX:
1668
                wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0);
1669
                changehealth(snum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1));
1670
                if (sprite[i].statnum == 12) deletesprite((short)i);
1671
                else
1672
                {
1673
                    sprite[i].cstat |= 0x8000;
1674
                    sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat);
1675
                    changespritestat((short)i,11);
1676
                }
1677
                break;
1678
            case CANNON:
1679
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1680
                if (snum == myconnectindex) keystatus[4] = 1;
1681
                changenumbombs(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1682
                if (sprite[i].statnum == 12) deletesprite((short)i);
1683
                else
1684
                {
1685
                    sprite[i].cstat |= 0x8000;
1686
                    sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat);
1687
                    changespritestat((short)i,11);
1688
                }
1689
                break;
1690
            case LAUNCHER:
1691
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1692
                if (snum == myconnectindex) keystatus[5] = 1;
1693
                changenummissiles(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1694
                if (sprite[i].statnum == 12) deletesprite((short)i);
1695
                else
1696
                {
1697
                    sprite[i].cstat |= 0x8000;
1698
                    sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat);
1699
                    changespritestat((short)i,11);
1700
                }
1701
                break;
1702
            case GRABCANNON:
1703
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1704
                if (snum == myconnectindex) keystatus[6] = 1;
1705
                changenumgrabbers(snum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1706
                if (sprite[i].statnum == 12) deletesprite((short)i);
1707
                else
1708
                {
1709
                    sprite[i].cstat |= 0x8000;
1710
                    sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat);
1711
                    changespritestat((short)i,11);
1712
                }
1713
                break;
1714
            case AIRPLANE:
1715
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1716
                if (flytime[snum] < lockclock) flytime[snum] = lockclock;
1717
                flytime[snum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat);
1718
                drawstatusflytime(snum);
1719
                if (sprite[i].statnum == 12) deletesprite((short)i);
1720
                else
1721
                {
1722
                    sprite[i].cstat |= 0x8000;
1723
                    sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat);
1724
                    changespritestat((short)i,11);
1725
                }
1726
                break;
1727
            }
1728
        }
1729
    }
4555 hendricks2 1730
}
1731
 
1732
void checkgrabbertouchsprite(short snum, short sectnum)   // Andy did this
1733
{
5327 hendricks2 1734
    int i, nexti;
1735
    short onum;
4555 hendricks2 1736
 
5327 hendricks2 1737
    if ((sectnum < 0) || (sectnum >= numsectors)) return;
1738
    onum = (sprite[snum].owner & (MAXSPRITES - 1));
4555 hendricks2 1739
 
5327 hendricks2 1740
    for (i=headspritesect[sectnum]; i>=0; i=nexti)
1741
    {
1742
        nexti = nextspritesect[i];
1743
        if (sprite[i].cstat&0x8000) continue;
1744
        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))
1745
        {
1746
            switch (sprite[i].picnum)
1747
            {
1748
            case COIN:
1749
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,192L,&sprite[i].x,&sprite[i].y,0);
1750
                changehealth(onum,5);
1751
                if (sprite[i].statnum == 12) deletesprite((short)i);
1752
                else
1753
                {
1754
                    sprite[i].cstat |= 0x8000;
1755
                    sprite[i].extra = 120*60;
1756
                    changespritestat((short)i,11);
1757
                }
1758
                break;
1759
            case DIAMONDS:
1760
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1761
                changehealth(onum,15);
1762
                if (sprite[i].statnum == 12) deletesprite((short)i);
1763
                else
1764
                {
1765
                    sprite[i].cstat |= 0x8000;
1766
                    sprite[i].extra = 120*120;
1767
                    changespritestat((short)i,11);
1768
                }
1769
                break;
1770
            case COINSTACK:
1771
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1772
                changehealth(onum,25);
1773
                if (sprite[i].statnum == 12) deletesprite((short)i);
1774
                else
1775
                {
1776
                    sprite[i].cstat |= 0x8000;
1777
                    sprite[i].extra = 120*180;
1778
                    changespritestat((short)i,11);
1779
                }
1780
                break;
1781
            case GIFTBOX:
1782
                wsayfollow("getstuff.wav",4096L+(krand()&127)+256-mulscale4(sprite[i].xrepeat,sprite[i].yrepeat),208L,&sprite[i].x,&sprite[i].y,0);
1783
                changehealth(onum,max(mulscale8(sprite[i].xrepeat,sprite[i].yrepeat),1));
1784
                if (sprite[i].statnum == 12) deletesprite((short)i);
1785
                else
1786
                {
1787
                    sprite[i].cstat |= 0x8000;
1788
                    sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat);
1789
                    changespritestat((short)i,11);
1790
                }
1791
                break;
1792
            case CANNON:
1793
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1794
                if (onum == myconnectindex) keystatus[4] = 1;
1795
                changenumbombs(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1796
                if (sprite[i].statnum == 12) deletesprite((short)i);
1797
                else
1798
                {
1799
                    sprite[i].cstat |= 0x8000;
1800
                    sprite[i].extra = 60*(sprite[i].xrepeat+sprite[i].yrepeat);
1801
                    changespritestat((short)i,11);
1802
                }
1803
                break;
1804
            case LAUNCHER:
1805
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1806
                if (onum == myconnectindex) keystatus[5] = 1;
1807
                changenummissiles(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1808
                if (sprite[i].statnum == 12) deletesprite((short)i);
1809
                else
1810
                {
1811
                    sprite[i].cstat |= 0x8000;
1812
                    sprite[i].extra = 90*(sprite[i].xrepeat+sprite[i].yrepeat);
1813
                    changespritestat((short)i,11);
1814
                }
1815
                break;
1816
            case GRABCANNON:
1817
                wsayfollow("getstuff.wav",3584L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1818
                if (onum == myconnectindex) keystatus[6] = 1;
1819
                changenumgrabbers(onum,((sprite[i].xrepeat+sprite[i].yrepeat)>>1));
1820
                if (sprite[i].statnum == 12) deletesprite((short)i);
1821
                else
1822
                {
1823
                    sprite[i].cstat |= 0x8000;
1824
                    sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat);
1825
                    changespritestat((short)i,11);
1826
                }
1827
                break;
1828
            case AIRPLANE:
1829
                wsayfollow("getstuff.wav",4096L+(krand()&127)-64,256L,&sprite[i].x,&sprite[i].y,0);
1830
                if (flytime[snum] < lockclock) flytime[snum] = lockclock;
1831
                flytime[onum] += 60*(sprite[i].xrepeat+sprite[i].yrepeat);
1832
                drawstatusflytime(onum);
1833
                if (sprite[i].statnum == 12) deletesprite((short)i);
1834
                else
1835
                {
1836
                    sprite[i].cstat |= 0x8000;
1837
                    sprite[i].extra = 120*(sprite[i].xrepeat+sprite[i].yrepeat);
1838
                    changespritestat((short)i,11);
1839
                }
1840
                break;
1841
            }
1842
        }
1843
    }
4555 hendricks2 1844
}
1845
 
1846
void shootgun(short snum, const vec3_t *vector,
5327 hendricks2 1847
              short daang, int dahoriz, short dasectnum, char guntype)
4555 hendricks2 1848
{
5327 hendricks2 1849
    short daang2;
1850
    int /*i,*/ j, daz2;
4555 hendricks2 1851
    hitdata_t hitinfo;
1852
 
5327 hendricks2 1853
    switch (guntype)
1854
    {
1855
    case 0:    //Shoot chain gun
1856
        daang2 = ((daang + (krand()&31)-16)&2047);
1857
        daz2 = ((100-dahoriz)*2000) + ((krand()-32768)>>1);
4555 hendricks2 1858
 
5327 hendricks2 1859
        hitscan(vector,dasectnum,                   //Start position
1860
                sintable[(daang2+512)&2047],            //X vector of 3D ang
1861
                sintable[daang2&2047],                  //Y vector of 3D ang
1862
                daz2,                                   //Z vector of 3D ang
1863
                &hitinfo,CLIPMASK1);
4555 hendricks2 1864
 
5327 hendricks2 1865
        if (wall[hitinfo.wall].picnum == KENPICTURE)
1866
        {
1867
            if (waloff[MAXTILES-1] != 0) wall[hitinfo.wall].picnum = MAXTILES-1;
1868
            wsayfollow("hello.wav",4096L+(krand()&127)-64,256L,&wall[hitinfo.wall].x,&wall[hitinfo.wall].y,0);
1869
        }
1870
        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)))
1871
        {
1872
            //If you shoot slime, make a splash
1873
            wsayfollow("splash.wav",4096L+(krand()&511)-256,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1874
            spawnsprite(j,hitinfo.pos.x,hitinfo.pos.y,hitinfo.pos.z,2,0,0,32,64,64,0,0,SPLASH,daang,
1875
                        0,0,0,snum+4096,hitinfo.sect,4,63,0,0); //63=time left for splash
1876
        }
1877
        else
1878
        {
1879
            wsayfollow("shoot.wav",4096L+(krand()&127)-64,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
4555 hendricks2 1880
 
5327 hendricks2 1881
            if ((hitinfo.sprite >= 0) && (sprite[hitinfo.sprite].statnum < MAXSTATUS))
1882
                switch (sprite[hitinfo.sprite].picnum)
1883
                {
1884
                case BROWNMONSTER:
1885
                    if (sprite[hitinfo.sprite].lotag > 0) sprite[hitinfo.sprite].lotag -= 10;
1886
                    if (sprite[hitinfo.sprite].lotag > 0)
1887
                    {
1888
                        wsayfollow("hurt.wav",4096L+(krand()&511)-256,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1889
                        if (sprite[hitinfo.sprite].lotag <= 25)
1890
                            sprite[hitinfo.sprite].cstat |= 2;
1891
                    }
1892
                    else
1893
                    {
1894
                        wsayfollow("mondie.wav",4096L+(krand()&127)-64,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1895
                        sprite[hitinfo.sprite].z += ((tilesiz[sprite[hitinfo.sprite].picnum].y*sprite[hitinfo.sprite].yrepeat)<<1);
1896
                        sprite[hitinfo.sprite].picnum = GIFTBOX;
1897
                        sprite[hitinfo.sprite].cstat &= ~0x83;    //Should not clip, foot-z
1898
                        changespritestat(hitinfo.sprite,12);
4555 hendricks2 1899
 
5327 hendricks2 1900
                        spawnsprite(j,hitinfo.pos.x,hitinfo.pos.y,hitinfo.pos.z+(32<<8),0,-4,0,32,64,64,
1901
                                    0,0,EXPLOSION,daang,0,0,0,snum+4096,
1902
                                    hitinfo.sect,5,31,0,0);
1903
                    }
1904
                    break;
1905
                case EVILAL:
1906
                    wsayfollow("blowup.wav",4096L+(krand()&127)-64,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1907
                    sprite[hitinfo.sprite].picnum = EVILALGRAVE;
1908
                    sprite[hitinfo.sprite].cstat = 0;
1909
                    sprite[hitinfo.sprite].xvel = (krand()&255)-128;
1910
                    sprite[hitinfo.sprite].yvel = (krand()&255)-128;
1911
                    sprite[hitinfo.sprite].zvel = (krand()&4095)-3072;
1912
                    changespritestat(hitinfo.sprite,9);
4555 hendricks2 1913
 
5327 hendricks2 1914
                    spawnsprite(j,hitinfo.pos.x,hitinfo.pos.y,hitinfo.pos.z+(32<<8),0,-4,0,32,64,64,0,
1915
                                0,EXPLOSION,daang,0,0,0,snum+4096,hitinfo.sect,5,31,0,0);
1916
                    //31=time left for explosion
4555 hendricks2 1917
 
5327 hendricks2 1918
                    break;
1919
                case PLAYER:
1920
                    for (j=connecthead; j>=0; j=connectpoint2[j])
1921
                        if (playersprite[j] == hitinfo.sprite)
1922
                        {
1923
                            wsayfollow("ouch.wav",4096L+(krand()&127)-64,256L,&hitinfo.pos.x,&hitinfo.pos.y,0);
1924
                            changehealth(j,-10);
1925
                            break;
1926
                        }
1927
                    break;
1928
                }
4555 hendricks2 1929
 
5327 hendricks2 1930
            spawnsprite(j,hitinfo.pos.x,hitinfo.pos.y,hitinfo.pos.z+(8<<8),2,-4,0,32,16,16,0,0,
1931
                        EXPLOSION,daang,0,0,0,snum+4096,hitinfo.sect,3,63,0,0);
4555 hendricks2 1932
 
5327 hendricks2 1933
            //Sprite starts out with center exactly on wall.
1934
            //This moves it back enough to see it at all angles.
1935
            movesprite((short)j,-(((int)sintable[(512+daang)&2047]*TICSPERFRAME)<<4),-(((int)sintable[daang]*TICSPERFRAME)<<4),0L,4L<<8,4L<<8,CLIPMASK1);
1936
        }
1937
        break;
1938
    case 1:    //Shoot silver sphere bullet
1939
        spawnsprite(j,vector->x,vector->y,vector->z,1+128,0,0,16,64,64,0,0,BULLET,daang,
1940
                    sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5,
1941
                    (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0);
1942
        wsayfollow("shoot2.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1);
1943
        break;
1944
    case 2:    //Shoot bomb
1945
        spawnsprite(j,vector->x,vector->y,vector->z,128,0,0,12,16,16,0,0,BOMB,daang,
1946
                    sintable[(daang+512)&2047]*5>>8,sintable[daang&2047]*5>>8,
1947
                    (80-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0);
1948
        wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1);
1949
        break;
1950
    case 3:    //Shoot missile (Andy did this)
1951
        spawnsprite(j,vector->x,vector->y,vector->z,1+128,0,0,16,32,32,0,0,MISSILE,daang,
1952
                    sintable[(daang+512)&2047]>>4,sintable[daang&2047]>>4,
1953
                    (100-dahoriz)<<7,snum+4096,dasectnum,6,0,0,0);
1954
        wsayfollow("shoot3.wav",4096L+(krand()&127)-64,192L,&sprite[j].x,&sprite[j].y,1);
1955
        break;
1956
    case 4:    //Shoot grabber (Andy did this)
1957
        spawnsprite(j,vector->x,vector->y,vector->z,1+128,0,0,16,64,64,0,0,GRABBER,daang,
1958
                    sintable[(daang+512)&2047]>>5,sintable[daang&2047]>>5,
1959
                    (100-dahoriz)<<6,snum+4096,dasectnum,6,0,0,0);
1960
        wsayfollow("shoot4.wav",4096L+(krand()&127)-64,128L,&sprite[j].x,&sprite[j].y,1);
1961
        break;
1962
    }
4555 hendricks2 1963
}
1964
 
1965
#define MAXVOXMIPS 5
1966
extern intptr_t voxoff[][MAXVOXMIPS];
1967
void analyzesprites(int dax, int day)
1968
{
5327 hendricks2 1969
    int i, j=0, k, *intptr;
1970
    vec3_t *ospr;
6001 hendricks2 1971
    uspritetype *tspr;
4555 hendricks2 1972
 
7540 hendricks2 1973
    //This function is called between drawrooms() and renderDrawMasks()
5327 hendricks2 1974
    //It has a list of possible sprites that may be drawn on this frame
4555 hendricks2 1975
 
5327 hendricks2 1976
    for (i=0,tspr=&tsprite[0]; i<spritesortcnt; i++,tspr++)
1977
    {
1978
        if (usevoxels && tiletovox[tspr->picnum] >= 0)
1979
            switch (tspr->picnum)
1980
            {
1981
            case PLAYER:
1982
                //   //Get which of the 8 angles of the sprite to draw (0-7)
1983
                //   //k ranges from 0-7
1984
                //k = getangle(tspr->x-dax,tspr->y-day);
1985
                //k = (((tspr->ang+3072+128-k)&2047)>>8)&7;
1986
                //   //This guy has only 5 pictures for 8 angles (3 are x-flipped)
1987
                //if (k <= 4)
1988
                //{
1989
                //   tspr->picnum += (k<<2);
1990
                //   tspr->cstat &= ~4;   //clear x-flipping bit
1991
                //}
1992
                //else
1993
                //{
1994
                //   tspr->picnum += ((8-k)<<2);
1995
                //   tspr->cstat |= 4;    //set x-flipping bit
1996
                //}
4555 hendricks2 1997
 
5327 hendricks2 1998
                if ((tspr->cstat&2) == 0)
1999
                {
2000
                    //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum];
2001
                    intptr = (int *)voxoff[tiletovox[PLAYER]][0];
2002
                    tspr->xrepeat = scale(tspr->xrepeat,56,intptr[2]);
2003
                    tspr->yrepeat = scale(tspr->yrepeat,56,intptr[2]);
2004
                    tspr->shade -= 6;
2005
                }
2006
                break;
2007
            case BROWNMONSTER:
2008
                //tspr->cstat |= 48; tspr->picnum = tiletovox[tspr->picnum];
2009
                break;
2010
            }
4555 hendricks2 2011
 
5327 hendricks2 2012
        k = statrate[tspr->statnum];
2013
        if (k >= 0)  //Interpolate moving sprite
2014
        {
2015
            ospr = &osprite[tspr->owner];
2016
            switch (k)
2017
            {
2018
            case 0: j = smoothratio; break;
2019
            case 1: j = (smoothratio>>1)+(((nummoves-tspr->owner)&1)<<15); break;
2020
            case 3: j = (smoothratio>>2)+(((nummoves-tspr->owner)&3)<<14); break;
2021
            case 7: j = (smoothratio>>3)+(((nummoves-tspr->owner)&7)<<13); break;
2022
            case 15: j = (smoothratio>>4)+(((nummoves-tspr->owner)&15)<<12); break;
2023
            }
2024
            k = tspr->x-ospr->x; tspr->x = ospr->x;
2025
            if (k != 0) tspr->x += mulscale16(k,j);
2026
            k = tspr->y-ospr->y; tspr->y = ospr->y;
2027
            if (k != 0) tspr->y += mulscale16(k,j);
2028
            k = tspr->z-ospr->z; tspr->z = ospr->z;
2029
            if (k != 0) tspr->z += mulscale16(k,j);
2030
        }
4555 hendricks2 2031
 
5327 hendricks2 2032
        //Don't allow close explosion sprites to be transluscent
2033
        k = tspr->statnum;
2034
        if ((k == 3) || (k == 4) || (k == 5) || (k == 7))
2035
            if (klabs(dax-tspr->x) < 256)
2036
                if (klabs(day-tspr->y) < 256)
2037
                    tspr->cstat &= ~2;
4555 hendricks2 2038
 
5327 hendricks2 2039
        tspr->shade += 6;
2040
        if (sector[tspr->sectnum].ceilingstat&1)
2041
            tspr->shade += sector[tspr->sectnum].ceilingshade;
2042
        else
2043
            tspr->shade += sector[tspr->sectnum].floorshade;
2044
    }
4555 hendricks2 2045
}
2046
 
2047
void tagcode(void)
2048
{
5738 hendricks2 2049
    int i, /*nexti,*/ j, k, l, s, /*daz, dax2, day2,*/ cnt, good;
5327 hendricks2 2050
    short startwall, endwall, dasector, p, oldang;
4555 hendricks2 2051
 
5327 hendricks2 2052
    for (p=connecthead; p>=0; p=connectpoint2[p])
2053
    {
2054
        if (sector[cursectnum[p]].lotag == 1)
2055
        {
2056
            activatehitag(sector[cursectnum[p]].hitag);
2057
            sector[cursectnum[p]].lotag = 0;
2058
            sector[cursectnum[p]].hitag = 0;
2059
        }
2060
        if ((sector[cursectnum[p]].lotag == 2) && (cursectnum[p] != ocursectnum[p]))
2061
            activatehitag(sector[cursectnum[p]].hitag);
2062
    }
4555 hendricks2 2063
 
5327 hendricks2 2064
    for (i=0; i<warpsectorcnt; i++)
2065
    {
2066
        dasector = warpsectorlist[i];
2067
        j = ((lockclock&127)>>2);
2068
        if (j >= 16) j = 31-j;
2069
        {
2070
            sector[dasector].ceilingshade = j;
2071
            sector[dasector].floorshade = j;
2072
            startwall = sector[dasector].wallptr;
2073
            endwall = startwall+sector[dasector].wallnum;
2074
            for (s=startwall; s<endwall; s++)
2075
                wall[s].shade = j;
2076
        }
2077
    }
4555 hendricks2 2078
 
5327 hendricks2 2079
    for (p=connecthead; p>=0; p=connectpoint2[p])
2080
        if (sector[cursectnum[p]].lotag == 10)  //warp sector
2081
        {
2082
            if (cursectnum[p] != ocursectnum[p])
2083
            {
2084
                warpsprite(playersprite[p]);
2085
                pos[p].x = sprite[playersprite[p]].x;
2086
                pos[p].y = sprite[playersprite[p]].y;
2087
                pos[p].z = sprite[playersprite[p]].z;
2088
                ang[p] = sprite[playersprite[p]].ang;
2089
                cursectnum[p] = sprite[playersprite[p]].sectnum;
4555 hendricks2 2090
 
5327 hendricks2 2091
                sprite[playersprite[p]].z += EYEHEIGHT;
4555 hendricks2 2092
 
5327 hendricks2 2093
                //warp(&pos[p].x,&pos[p].y,&pos[p].z,&ang[p],&cursectnum[p]);
2094
                //Update sprite representation of player
2095
                //setsprite_eyeheight(playersprite[p],&pos[p]);
2096
                //sprite[playersprite[p]].ang = ang[p];
2097
            }
2098
        }
4555 hendricks2 2099
 
5327 hendricks2 2100
    for (i=0; i<xpanningsectorcnt; i++) //animate wall x-panning sectors
2101
    {
2102
        dasector = xpanningsectorlist[i];
4555 hendricks2 2103
 
5327 hendricks2 2104
        startwall = sector[dasector].wallptr;
2105
        endwall = startwall+sector[dasector].wallnum;
2106
        for (s=startwall; s<endwall; s++)
2107
            wall[s].xpanning = ((lockclock>>2)&255);
2108
    }
4555 hendricks2 2109
 
5327 hendricks2 2110
    for (i=0; i<ypanningwallcnt; i++)
2111
        wall[ypanningwalllist[i]].ypanning = ~(lockclock&255);
4555 hendricks2 2112
 
5327 hendricks2 2113
    for (i=0; i<turnspritecnt; i++)
2114
    {
2115
        sprite[turnspritelist[i]].ang += (TICSPERFRAME<<2);
2116
        sprite[turnspritelist[i]].ang &= 2047;
2117
    }
4555 hendricks2 2118
 
5327 hendricks2 2119
    for (i=0; i<floorpanningcnt; i++) //animate floor of slime sectors
2120
    {
2121
        sector[floorpanninglist[i]].floorxpanning = ((lockclock>>2)&255);
2122
        sector[floorpanninglist[i]].floorypanning = ((lockclock>>2)&255);
2123
    }
4555 hendricks2 2124
 
5327 hendricks2 2125
    for (i=0; i<dragsectorcnt; i++)
2126
    {
2127
        dasector = dragsectorlist[i];
4555 hendricks2 2128
 
5327 hendricks2 2129
        startwall = sector[dasector].wallptr;
2130
        endwall = startwall+sector[dasector].wallnum;
4555 hendricks2 2131
 
5327 hendricks2 2132
        if (wall[startwall].x+dragxdir[i] < dragx1[i]) dragxdir[i] = 16;
2133
        if (wall[startwall].y+dragydir[i] < dragy1[i]) dragydir[i] = 16;
2134
        if (wall[startwall].x+dragxdir[i] > dragx2[i]) dragxdir[i] = -16;
2135
        if (wall[startwall].y+dragydir[i] > dragy2[i]) dragydir[i] = -16;
4555 hendricks2 2136
 
5327 hendricks2 2137
        for (j=startwall; j<endwall; j++)
2138
            dragpoint(j,wall[j].x+dragxdir[i],wall[j].y+dragydir[i],0);
2139
        j = sector[dasector].floorz;
2140
        sector[dasector].floorz = dragfloorz[i]+(sintable[(lockclock<<4)&2047]>>3);
4555 hendricks2 2141
 
5327 hendricks2 2142
        for (p=connecthead; p>=0; p=connectpoint2[p])
2143
            if (cursectnum[p] == dasector)
2144
            {
2145
                pos[p].x += dragxdir[i];
2146
                pos[p].y += dragydir[i];