Subversion Repositories eduke32

Rev

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

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