Subversion Repositories eduke32

Rev

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