Subversion Repositories eduke32

Rev

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

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