Subversion Repositories eduke32

Rev

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