Subversion Repositories eduke32

Rev

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