Subversion Repositories eduke32

Rev

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

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