Subversion Repositories eduke32

Rev

Rev 239 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 Plagman 1
//-------------------------------------------------------------------------
2
/*
3
Copyright (C) 2005 - EDuke32 team
4
 
5
This file is part of EDuke32
6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
*/
21
//-------------------------------------------------------------------------
22
 
110 terminx 23
#include "duke3d.h"
5 Plagman 24
#include "types.h"
25
#include "develop.h"
26
#include "scriplib.h"
27
#include "file_lib.h"
28
#include "mathutil.h"
29
#include "gamedefs.h"
30
#include "keyboard.h"
31
#include "mouse.h"  // JBF 20030809
32
#include "function.h"
33
#include "control.h"
34
#include "fx_man.h"
35
#include "sounds.h"
36
#include "config.h"
37
 
38
#include "osd.h"
39
#include "osdfuncs.h"
40
#include "osdcmds.h"
130 terminx 41
#include "scriptfile.h"
241 terminx 42
#include "grpscan.h"
5 Plagman 43
 
44
//#include "crc32.h"
45
 
46
#include "util_lib.h"
47
 
226 terminx 48
#define VERSION " 1.4.0svn"
5 Plagman 49
 
50
#define HEAD  "EDuke32"VERSION" (shareware mode)"
51
#define HEAD2 "EDuke32"VERSION
52
 
53
#define IDFSIZE 479985668
54
#define IDFILENAME "DUKE3D.IDF"
55
 
56
#define TIMERUPDATESIZ 32
57
 
58
long cameradist = 0, cameraclock = 0;
59
char playerswhenstarted;
194 terminx 60
char qe,cp,usecwd = 0;
5 Plagman 61
 
194 terminx 62
static int32 CommandSetup = 0;
236 terminx 63
static int32 NoSetup = 0;
5 Plagman 64
static int32 CommandSoundToggleOff = 0;
65
static int32 CommandMusicToggleOff = 0;
66
static char *CommandMap = NULL;
131 terminx 67
static char *CommandName = NULL,*CommandNet = NULL;
113 terminx 68
int32 CommandWeaponChoice = 0;
5 Plagman 69
 
70
char confilename[BMAX_PATH] = {"EDUKE.CON"}, boardfilename[BMAX_PATH] = {0};
71
char waterpal[768], slimepal[768], titlepal[768], drealms[768], endingpal[768];
72
char firstdemofile[80] = { '\0' };
73
int display_bonus_screen = 1, userconfiles = 0;
74
 
75
static int netparamcount = 0;
76
static char **netparam = NULL;
77
 
147 terminx 78
int votes[MAXPLAYERS], gotvote[MAXPLAYERS], voting = -1;
79
 
5 Plagman 80
void setstatusbarscale(long sc)
81
{
82
    ud.statusbarscale = min(100,max(10,sc));
83
    vscrn();
84
}
85
 
86
static inline long sbarx(long x)
87
{
88
    if (ud.screen_size == 4) return scale(x<<16,ud.statusbarscale,100);
89
    return (((320l<<16) - scale(320l<<16,ud.statusbarscale,100)) >> 1) + scale(x<<16,ud.statusbarscale,100);
90
}
91
 
92
static inline long sbary(long y)
93
{
94
    return ((200l<<16) - scale(200l<<16,ud.statusbarscale,100) + scale(y<<16,ud.statusbarscale,100));
95
}
96
 
97
static inline long sbarsc(long sc)
98
{
99
    return scale(sc,ud.statusbarscale,100);
100
}
101
 
102
void patchstatusbar(long x1, long y1, long x2, long y2)
103
{
104
    long scl, tx, ty;
105
    long clx1,cly1,clx2,cly2,clofx,clofy;
106
 
107
    scl = sbarsc(65536);
108
    tx = sbarx(0); ty = sbary(200-tilesizy[BOTTOMSTATUSBAR]);
109
 
110
    clx1 = scale(scale(x1,xdim,320),ud.statusbarscale,100);
111
    cly1 = scale(scale(y1,ydim,200),ud.statusbarscale,100);
112
    clx2 = scale(scale(x2,xdim,320),ud.statusbarscale,100);
113
    cly2 = scale(scale(y2,ydim,200),ud.statusbarscale,100);
114
    clofx = (xdim - scale(xdim,ud.statusbarscale,100)) >> 1;
115
    clofy = (ydim - scale(ydim,ud.statusbarscale,100));
116
 
117
    rotatesprite(tx,ty,scl,0,BOTTOMSTATUSBAR,4,0,10+16+64,clx1+clofx,cly1+clofy,clx2+clofx-1,cly2+clofy-1);
118
}
119
 
120
int recfilep,totalreccnt;
121
char debug_on = 0,actor_tog = 0,*rtsptr,memorycheckoveride=0;
122
 
123
extern char syncstate;
124
extern int32 numlumps;
125
 
126
FILE *frecfilep = (FILE *)NULL;
127
void pitch_test( void );
128
 
129
char restorepalette,screencapt,nomorelogohack;
130
int sendmessagecommand = -1;
131
 
234 terminx 132
char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp";
133
char *duke3dgrp = defaultduke3dgrp;
5 Plagman 134
static char *duke3ddef = "duke3d.def";
135
 
136
extern long lastvisinc;
137
 
138
// JBF 20031221: These ought to disappear when things mature
139
extern int showmultidiags;
140
extern int netmode, nethostplayers;
141
extern char netjoinhost[64];
142
int startupnetworkgame(void);
143
int processnetworkrequests(void);
144
 
145
void setgamepalette(struct player_struct *player, char *pal, int set)
146
{
147
    if (player != &ps[screenpeek]) {
148
        // another head
149
        player->palette = pal;
150
        return;
151
    }
152
 
153
    if (getrendermode() < 3) {
154
        // 8-bit mode
155
        player->palette = pal;
156
        setbrightness(ud.brightness>>2, pal, set);
157
        //pub = pus = NUMPAGES;
158
        return;
159
    }
160
 
161
    if (pal == palette || pal == waterpal || pal == slimepal) {
162
        if (player->palette != palette && player->palette != waterpal && player->palette != slimepal)
163
            setbrightness(ud.brightness>>2, palette, set);
164
        else setpalettefade(0,0,0,0);
165
    } else {
166
        setbrightness(ud.brightness>>2, pal, set);
167
    }
168
    player->palette = pal;
169
}
170
 
87 terminx 171
#define TEXTWRAPLEN (scale(35,ScreenWidth,320))
81 terminx 172
 
151 terminx 173
char colstrip[1024];
174
 
175
char *strip_color_codes(char *t)
5 Plagman 176
{
151 terminx 177
    int i = 0;
178
 
179
    while(*t)
180
    {
181
        if(*t == '^' && isdigit(*(t+1)))
182
        {
183
            t += 2;
184
            if(isdigit(*t))
185
                t++;
186
            if(!(*t)) continue;
187
        }
188
        colstrip[i] = *t;
189
        i++,t++;
190
    }
191
    colstrip[i] = '\0';
192
    return(colstrip);
193
}
194
 
195
int gametext_(int small, int starttile, int x,int y,char *t,char s,char p,short orientation,long x1, long y1, long x2, long y2)
196
{
81 terminx 197
    short ac,newx,oldx=x;
5 Plagman 198
    char centre, *oldt;
199
 
200
    centre = ( x == (320>>1) );
201
    newx = 0;
202
    oldt = t;
203
 
102 terminx 204
    if(t == NULL)
205
        return -1;
206
 
5 Plagman 207
    if(centre)
208
    {
209
        while(*t)
210
        {
151 terminx 211
            if(*t == '^' && isdigit(*(t+1)))
212
            {
213
                t += 2;
214
                if(isdigit(*t)) t++;
215
                if(!(*t)) continue;
216
            }
217
        if(*t == 32) {newx+=5;t++;continue;}
5 Plagman 218
            else ac = *t - '!' + starttile;
219
 
220
            if( ac < starttile || ac > (starttile + 93) ) break;
221
 
160 terminx 222
            if(*t >= '0' && *t <= '9')
85 terminx 223
                newx += 8;
224
            else newx += tilesizx[ac];
5 Plagman 225
            t++;
226
        }
227
 
228
        t = oldt;
229
        x = (320>>1)-(newx>>1);
230
    }
231
 
232
    while(*t)
233
    {
151 terminx 234
        if(*t == '^' && isdigit(*(t+1)))
235
        {
236
            char smallbuf[3];
237
            t += 1;
238
            if(isdigit(*(t+1)))
239
            {
240
                smallbuf[0] = *(t++);
241
                smallbuf[1] = *(t++);
242
                smallbuf[2] = '\0';
243
                p = atol(smallbuf);
244
            } else {
245
                smallbuf[0] = *(t++);
246
                smallbuf[1] = '\0';
247
                p = atol(smallbuf);
248
            }
249
            if(!(*t)) continue;
250
        }
251
    if(*t == 32) {x+=5;t++;continue;}
5 Plagman 252
        else ac = *t - '!' + starttile;
253
 
254
        if( ac < starttile || ac > (starttile + 93) )
255
            break;
256
 
85 terminx 257
        rotatesprite(x<<16,(y<<16)+(small?ScreenHeight<<15:0),65536,0,ac,s,p,small?(8|16):(2|orientation),x1,y1,x2,y2);
258
        if((*t >= '0' && *t <= '9'))
259
            x += 8;
260
        else x += tilesizx[ac];//(tilesizx[ac]>>small);
87 terminx 261
        if(t-oldt >= (signed)TEXTWRAPLEN-!small) oldt = t, x = oldx, y+=8;
5 Plagman 262
        t++;
263
    }
264
 
265
    return (x);
266
}
267
 
151 terminx 268
inline int gametext(int x,int y,char *t,char s,short dabits)
78 terminx 269
{
151 terminx 270
    return(gametext_(0,STARTALPHANUM, x,y,t,s,0,dabits,0, 0, xdim-1, ydim-1));
80 terminx 271
}
78 terminx 272
 
151 terminx 273
inline int gametextpal(int x,int y,char *t,char s,char p)
80 terminx 274
{
151 terminx 275
    return(gametext_(0,STARTALPHANUM, x,y,t,s,p,26,0, 0, xdim-1, ydim-1));
78 terminx 276
}
277
 
91 terminx 278
inline int mpgametext(int y,char *t,char s,short dabits)
78 terminx 279
{
280
    if(xdim >= 640 && ydim >= 480)
151 terminx 281
        return(gametext_(1,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1));
282
    else return(gametext_(0,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1));
78 terminx 283
}
284
 
151 terminx 285
int minitext_(int x,int y,char *t,char s,char p,short sb)
5 Plagman 286
{
287
    short ac;
288
    char ch,cmode;
289
 
290
    cmode = (sb&256)!=0;
291
    sb &= 255;
292
 
293
    while(*t)
294
    {
295
        ch = Btoupper(*t);
296
        if(ch == 32) {x+=5;t++;continue;}
297
        else ac = ch - '!' + MINIFONT;
298
 
299
        if (cmode) rotatesprite(sbarx(x),sbary(y),sbarsc(65536L),0,ac,s,p,sb,0,0,xdim-1,ydim-1);
300
        else rotatesprite(x<<16,y<<16,65536L,0,ac,s,p,sb,0,0,xdim-1,ydim-1);
301
        x += 4; // tilesizx[ac]+1;
302
 
303
        t++;
304
    }
305
    return (x);
306
}
307
 
151 terminx 308
inline int minitextshade(int x,int y,char *t,char s,char p,short sb)
309
{
310
    return (minitext_(x,y,(char *)strip_color_codes(t),s,p,sb));
311
}
312
 
5 Plagman 313
inline int minitext(int x,int y,char *t,char p,short sb)
314
{
151 terminx 315
    return (minitext_(x,y,(char *)strip_color_codes(t),0,p,sb));
5 Plagman 316
}
317
 
318
void gamenumber(long x,long y,long n,char s)
319
{
320
    char b[10];
321
    //ltoa(n,b,10);
322
    Bsnprintf(b,10,"%ld",n);
323
    gametext(x,y,b,s,2+8+16);
324
}
325
 
81 terminx 326
char recbuf[180];
5 Plagman 327
void allowtimetocorrecterrorswhenquitting(void)
328
{
329
    long i, j, oldtotalclock;
330
 
331
    ready2send = 0;
332
 
333
    for(j=0;j<8;j++)
334
    {
335
        oldtotalclock = totalclock;
336
 
337
        while (totalclock < oldtotalclock+TICSPERFRAME) {
338
            handleevents();
339
            getpackets();
340
        }
341
        if(KB_KeyPressed(sc_Escape)) return;
342
 
343
        packbuf[0] = 127;
344
        for(i=connecthead;i>=0;i=connectpoint2[i])
345
        {
346
            if (i != myconnectindex) sendpacket(i,packbuf,1);
347
            if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master
348
        }
349
    }
350
}
351
 
352
#define MAXUSERQUOTES 4
353
long quotebot, quotebotgoal;
354
short user_quote_time[MAXUSERQUOTES];
81 terminx 355
char user_quote[MAXUSERQUOTES][178];
5 Plagman 356
// char typebuflen,typebuf[41];
357
 
358
void adduserquote(char *daquote)
359
{
360
    long i;
361
 
362
    for(i=MAXUSERQUOTES-1;i>0;i--)
363
    {
232 terminx 364
        Bstrcpy(user_quote[i],user_quote[i-1]);
5 Plagman 365
        user_quote_time[i] = user_quote_time[i-1];
366
    }
232 terminx 367
    Bstrcpy(user_quote[0],daquote);
151 terminx 368
    OSD_Printf("%s\n",strip_color_codes(daquote));
87 terminx 369
 
88 terminx 370
    user_quote_time[0] = ud.msgdisptime;
5 Plagman 371
    pub = NUMPAGES;
372
}
373
 
374
void getpackets(void)
375
{
376
    long i, j, k, l;
377
    long other, packbufleng;
378
    input *osyn, *nsyn;
379
 
380
    sampletimer();
381
    AudioUpdate();
382
 
114 terminx 383
    if(ALT_IS_PRESSED && KB_KeyPressed(sc_Enter))
384
    {
385
        if(setgamemode(!ScreenMode,ScreenWidth,ScreenHeight,ScreenBPP)) {
386
            OSD_Printf("Failed setting fullscreen video mode.\n");
387
            if (setgamemode(ScreenMode, ScreenWidth, ScreenHeight, ScreenBPP))
388
                gameexit("Failed to recover from failure to set fullscreen video mode.\n");
389
        }
390
        else ScreenMode = !ScreenMode;
391
        KB_ClearKeyDown(sc_Enter);
392
        restorepalette = 1;
128 terminx 393
        vscrn();
114 terminx 394
    }
395
 
5 Plagman 396
    // only dispatch commands here when not in a game
120 terminx 397
if( !(ps[myconnectindex].gm&MODE_GAME) ) { OSD_DispatchQueued(); }
5 Plagman 398
 
399
    if(qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete))
400
    {
401
        qe = 1;
402
        gameexit("Quick Exit.");
403
    }
404
 
405
    if (numplayers < 2) return;
406
    while ((packbufleng = getpacket(&other,packbuf)) > 0)
407
    {
408
        switch(packbuf[0])
409
        {
77 terminx 410
        case 254:
411
            //slaves in M/S mode only send to master
412
            if (myconnectindex == connecthead)
413
            {
414
                //Master re-transmits message to all others
415
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
416
                    if (i != other)
417
                        sendpacket(i,packbuf,packbufleng);
418
            }
120 terminx 419
            /*
420
                        j = packbuf[1];
421
                        playerquitflag[j] = 0;
77 terminx 422
 
120 terminx 423
                        j = -1;
424
                        for(i=connecthead;i>=0;i=connectpoint2[i])
425
                        {
426
                            if (playerquitflag[i]) { j = i; continue; }
77 terminx 427
 
120 terminx 428
                            if (i == connecthead) connecthead = connectpoint2[connecthead];
429
                            else connectpoint2[j] = connectpoint2[i];
77 terminx 430
 
120 terminx 431
                            numplayers--;
432
                            ud.multimode--;
114 terminx 433
 
120 terminx 434
                            Bsprintf(buf,"%s is history!",ud.user_name[i]);
435
                            adduserquote(buf);
114 terminx 436
 
120 terminx 437
                            if (numplayers < 2)
438
                                sound(GENERIC_AMBIENCE17);
114 terminx 439
 
120 terminx 440
                            if(i == 0 && networkmode == 0 ) */
441
            gameexit( "Game aborted from menu; disconnected.");
442
            //            }
114 terminx 443
 
77 terminx 444
            break;
445
 
76 terminx 446
        case 9:
447
            //slaves in M/S mode only send to master
448
            if (myconnectindex == connecthead)
449
            {
450
                //Master re-transmits message to all others
451
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
452
                    if (i != other)
453
                        sendpacket(i,packbuf,packbufleng);
454
            }
455
 
232 terminx 456
            Bstrcpy(boardfilename,packbuf+1);
76 terminx 457
            boardfilename[packbufleng-1] = 0;
458
            if(boardfilename[0] != 0)
459
            {
460
                if ((i = kopen4load(boardfilename,0)) < 0) {
461
                    Bmemset(boardfilename,0,sizeof(boardfilename));
462
                    sendboardname();
463
                } else kclose(i);
464
            }
465
 
466
            if(ud.m_level_number == 7 && ud.m_volume_number == 0 && boardfilename[0] == 0)
467
                ud.m_level_number = 0;
468
 
469
            break;
470
 
147 terminx 471
        case 18: // map vote
472
 
473
            if (myconnectindex == connecthead)
474
            {
475
                //Master re-transmits message to all others
476
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
477
                    if (i != other)
478
                        sendpacket(i,packbuf,packbufleng);
479
            }
480
 
481
            switch(packbuf[1])
482
            {
483
            case 0:
186 terminx 484
                if(voting == myconnectindex && gotvote[packbuf[2]] == 0)
147 terminx 485
                {
486
                    gotvote[packbuf[2]] = 1;
487
                    votes[packbuf[2]] = packbuf[3];
488
                    Bsprintf(tempbuf,"GOT VOTE FROM %s",ud.user_name[packbuf[2]]);
489
                    adduserquote(tempbuf);
490
                }
491
                break;
492
 
493
            case 1: // call map vote
494
                voting = packbuf[2];
148 terminx 495
                Bsprintf(tempbuf,"%s HAS CALLED A VOTE TO CHANGE MAP TO %s (E%dL%d)",ud.user_name[packbuf[2]],level_names[packbuf[3]*11 + packbuf[4]],packbuf[3]+1,packbuf[4]+1);
147 terminx 496
                adduserquote(tempbuf);
497
                Bsprintf(tempbuf,"PRESS F1 TO VOTE YES, F2 TO VOTE NO");
498
                adduserquote(tempbuf);
499
                Bmemset(votes,0,sizeof(votes));
500
                Bmemset(gotvote,0,sizeof(gotvote));
501
                gotvote[voting] = votes[voting] = 1;
502
                break;
503
 
504
            case 2: // cancel map vote
186 terminx 505
                if(voting == packbuf[2])
147 terminx 506
                {
507
                    voting = -1;
508
                    i = 0;
509
                    for(j=0;j<MAXPLAYERS;j++)
510
                        i += gotvote[j];
511
 
512
                    if(i != numplayers)
513
                        Bsprintf(tempbuf,"%s HAS CANCELED THE VOTE",ud.user_name[packbuf[2]]);
514
                    else Bsprintf(tempbuf,"VOTE FAILED");
515
                    Bmemset(votes,0,sizeof(votes));
516
                    Bmemset(gotvote,0,sizeof(gotvote));
517
                    adduserquote(tempbuf);
518
                }
519
                break;
520
            }
521
            break;
522
 
5 Plagman 523
        case 126:
524
            //Slaves in M/S mode only send to master
525
            //Master re-transmits message to all others
526
            if ((!networkmode) && (myconnectindex == connecthead))
527
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
528
                    if (i != other) sendpacket(i,packbuf,packbufleng);
529
 
530
            multiflag = 2;
531
            multiwhat = 0;
532
            multiwho = packbuf[2]; //other: need to send in m/s mode because of possible re-transmit
533
            multipos = packbuf[1];
534
            loadplayer( multipos );
535
            multiflag = 0;
536
            break;
537
        case 0:  //[0] (receive master sync buffer)
538
            j = 1;
539
 
540
            if ((movefifoend[other]&(TIMERUPDATESIZ-1)) == 0)
541
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
542
                {
543
                    if (playerquitflag[i] == 0) continue;
544
                    if (i == myconnectindex)
545
                        otherminlag = (long)((signed char)packbuf[j]);
546
                    j++;
547
                }
548
 
549
            osyn = (input *)&inputfifo[(movefifoend[connecthead]-1)&(MOVEFIFOSIZ-1)][0];
550
            nsyn = (input *)&inputfifo[(movefifoend[connecthead])&(MOVEFIFOSIZ-1)][0];
551
 
552
            k = j;
553
            for(i=connecthead;i>=0;i=connectpoint2[i])
90 terminx 554
                j += playerquitflag[i]+playerquitflag[i];
5 Plagman 555
            for(i=connecthead;i>=0;i=connectpoint2[i])
556
            {
557
                if (playerquitflag[i] == 0) continue;
558
 
559
                l = packbuf[k++];
141 terminx 560
                l += (long)(packbuf[k++]<<8);
5 Plagman 561
 
562
                if (i == myconnectindex)
563
                { j += ((l&1)<<1)+(l&2)+((l&4)>>2)+((l&8)>>3)+((l&16)>>4)+((l&32)>>5)+((l&64)>>6)+((l&128)>>7)+((l&256)>>8)+((l&512)>>9)+((l&1024)>>10)+((l&2048)>>11); continue; }
564
 
565
                copybufbyte(&osyn[i],&nsyn[i],sizeof(input));
566
                if (l&1)   nsyn[i].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
567
                if (l&2)   nsyn[i].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
568
                if (l&4)   nsyn[i].avel = (signed char)packbuf[j++];
569
                if (l&8)   nsyn[i].bits = ((nsyn[i].bits&0xffffff00)|((long)packbuf[j++]));
570
                if (l&16)  nsyn[i].bits = ((nsyn[i].bits&0xffff00ff)|((long)packbuf[j++])<<8);
571
                if (l&32)  nsyn[i].bits = ((nsyn[i].bits&0xff00ffff)|((long)packbuf[j++])<<16);
572
                if (l&64)  nsyn[i].bits = ((nsyn[i].bits&0x00ffffff)|((long)packbuf[j++])<<24);
573
                if (l&128) nsyn[i].horz = (signed char)packbuf[j++];
574
                if (l&256)  nsyn[i].bits2 = ((nsyn[i].bits2&0xffffff00)|((long)packbuf[j++]));
575
                if (l&512)  nsyn[i].bits2 = ((nsyn[i].bits2&0xffff00ff)|((long)packbuf[j++])<<8);
576
                if (l&1024) nsyn[i].bits2 = ((nsyn[i].bits2&0xff00ffff)|((long)packbuf[j++])<<16);
577
                if (l&2048) nsyn[i].bits2 = ((nsyn[i].bits2&0x00ffffff)|((long)packbuf[j++])<<24);
578
 
579
                if (nsyn[i].bits&(1<<26)) playerquitflag[i] = 0;
580
                movefifoend[i]++;
581
            }
582
 
583
            while (j != packbufleng)
584
            {
585
                for(i=connecthead;i>=0;i=connectpoint2[i])
586
                    if(i != myconnectindex)
587
                    {
588
                        syncval[i][syncvalhead[i]&(MOVEFIFOSIZ-1)] = packbuf[j];
589
                        syncvalhead[i]++;
590
                    }
591
                j++;
592
            }
593
 
594
            for(i=connecthead;i>=0;i=connectpoint2[i])
595
                if (i != myconnectindex)
596
                    for(j=1;j<movesperpacket;j++)
597
                    {
598
                        copybufbyte(&nsyn[i],&inputfifo[movefifoend[i]&(MOVEFIFOSIZ-1)][i],sizeof(input));
599
                        movefifoend[i]++;
600
                    }
601
 
602
            movefifosendplc += movesperpacket;
603
 
604
            break;
605
        case 1:  //[1] (receive slave sync buffer)
141 terminx 606
            j = 3; k = packbuf[1] + (long)(packbuf[2]<<8);
5 Plagman 607
 
608
            osyn = (input *)&inputfifo[(movefifoend[other]-1)&(MOVEFIFOSIZ-1)][0];
609
            nsyn = (input *)&inputfifo[(movefifoend[other])&(MOVEFIFOSIZ-1)][0];
610
 
611
            copybufbyte(&osyn[other],&nsyn[other],sizeof(input));
612
            if (k&1)   nsyn[other].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
613
            if (k&2)   nsyn[other].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
614
            if (k&4)   nsyn[other].avel = (signed char)packbuf[j++];
615
            if (k&8)   nsyn[other].bits = ((nsyn[other].bits&0xffffff00)|((long)packbuf[j++]));
616
            if (k&16)  nsyn[other].bits = ((nsyn[other].bits&0xffff00ff)|((long)packbuf[j++])<<8);
617
            if (k&32)  nsyn[other].bits = ((nsyn[other].bits&0xff00ffff)|((long)packbuf[j++])<<16);
618
            if (k&64)  nsyn[other].bits = ((nsyn[other].bits&0x00ffffff)|((long)packbuf[j++])<<24);
619
            if (k&128) nsyn[other].horz = (signed char)packbuf[j++];
620
            if (k&256)  nsyn[other].bits2 = ((nsyn[other].bits2&0xffffff00)|((long)packbuf[j++]));
621
            if (k&512)  nsyn[other].bits2 = ((nsyn[other].bits2&0xffff00ff)|((long)packbuf[j++])<<8);
622
            if (k&1024) nsyn[other].bits2 = ((nsyn[other].bits2&0xff00ffff)|((long)packbuf[j++])<<16);
623
            if (k&2048) nsyn[other].bits2 = ((nsyn[other].bits2&0x00ffffff)|((long)packbuf[j++])<<24);
624
            movefifoend[other]++;
625
 
626
            while (j != packbufleng)
627
            {
628
                syncval[other][syncvalhead[other]&(MOVEFIFOSIZ-1)] = packbuf[j++];
629
                syncvalhead[other]++;
630
            }
631
 
632
            for(i=1;i<movesperpacket;i++)
633
            {
634
                copybufbyte(&nsyn[other],&inputfifo[movefifoend[other]&(MOVEFIFOSIZ-1)][other],sizeof(input));
635
                movefifoend[other]++;
636
            }
637
 
638
            break;
639
 
640
        case 4:
641
            //slaves in M/S mode only send to master
642
            if ((!networkmode) && (myconnectindex == connecthead))
643
            {
644
                if (packbuf[1] == 255)
645
                {
646
                    //Master re-transmits message to all others
647
                    for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
648
                        if (i != other)
649
                            sendpacket(i,packbuf,packbufleng);
650
                }
651
                else if (((long)packbuf[1]) != myconnectindex)
652
                {
653
                    //Master re-transmits message not intended for master
654
                    sendpacket((long)packbuf[1],packbuf,packbufleng);
655
                    break;
656
                }
657
            }
658
 
232 terminx 659
            Bstrcpy(recbuf,packbuf+2);
5 Plagman 660
            recbuf[packbufleng-2] = 0;
661
 
662
            adduserquote(recbuf);
663
            sound(EXITMENUSOUND);
664
 
665
            pus = NUMPAGES;
666
            pub = NUMPAGES;
667
 
668
            break;
669
 
670
        case 5:
671
            //Slaves in M/S mode only send to master
672
            //Master re-transmits message to all others
673
            if ((!networkmode) && (myconnectindex == connecthead))
674
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
675
                    if (i != other) sendpacket(i,packbuf,packbufleng);
676
 
147 terminx 677
            if(voting != -1)
678
                adduserquote("VOTE SUCCEEDED");
679
 
5 Plagman 680
            ud.m_level_number = ud.level_number = packbuf[1];
681
            ud.m_volume_number = ud.volume_number = packbuf[2];
682
            ud.m_player_skill = ud.player_skill = packbuf[3];
683
            ud.m_monsters_off = ud.monsters_off = packbuf[4];
684
            ud.m_respawn_monsters = ud.respawn_monsters = packbuf[5];
685
            ud.m_respawn_items = ud.respawn_items = packbuf[6];
686
            ud.m_respawn_inventory = ud.respawn_inventory = packbuf[7];
687
            ud.m_coop = packbuf[8];
688
            ud.m_marker = ud.marker = packbuf[9];
689
            ud.m_ffire = ud.ffire = packbuf[10];
147 terminx 690
            ud.m_noexits = ud.noexits = packbuf[11];
5 Plagman 691
 
692
            for(i=connecthead;i>=0;i=connectpoint2[i])
693
            {
694
                resetweapons(i);
695
                resetinventory(i);
696
            }
697
 
698
            newgame(ud.volume_number,ud.level_number,ud.player_skill);
699
            ud.coop = ud.m_coop;
700
 
701
            if (enterlevel(MODE_GAME)) backtomenu();
702
 
703
            break;
29 terminx 704
        case 6:
705
            //slaves in M/S mode only send to master
706
            //Master re-transmits message to all others
707
            if ((!networkmode) && (myconnectindex == connecthead))
708
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
709
                    if (i != other) sendpacket(i,packbuf,packbufleng);
5 Plagman 710
 
29 terminx 711
            if (packbuf[2] != BYTEVERSION)
712
                gameexit("\nYou cannot play Duke with different versions.");
5 Plagman 713
 
29 terminx 714
            other = packbuf[1];
5 Plagman 715
 
29 terminx 716
            for (i=3;packbuf[i];i++)
717
                ud.user_name[other][i-3] = packbuf[i];
718
            ud.user_name[other][i-3] = 0;
719
            i++;
5 Plagman 720
 
29 terminx 721
            j = i; //This used to be Duke packet #9... now concatenated with Duke packet #6
722
            for (;i-j<10;i++) ud.wchoice[other][i-j] = packbuf[i];
5 Plagman 723
 
29 terminx 724
            ps[other].aim_mode = packbuf[i++];
725
            ps[other].auto_aim = packbuf[i++];
726
            ps[other].weaponswitch = packbuf[i++];
53 terminx 727
            ps[other].palookup = ud.pcolor[other] = packbuf[i++];
728
            if(sprite[ps[other].i].picnum == APLAYER)
729
                sprite[ps[other].i].pal = ud.pcolor[other];
29 terminx 730
            break;
5 Plagman 731
        case 7:
732
            //slaves in M/S mode only send to master
733
            //Master re-transmits message to all others
734
            if ((!networkmode) && (myconnectindex == connecthead))
735
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
736
                    if (i != other) sendpacket(i,packbuf,packbufleng);
737
 
738
            if(numlumps == 0) break;
739
 
740
            if (SoundToggle == 0 || ud.lockout == 1 || FXDevice < 0 )
741
                break;
742
            rtsptr = (char *)RTS_GetSound(packbuf[1]-1);
743
            if (*rtsptr == 'C')
744
                FX_PlayVOC3D(rtsptr,0,0,0,255,-packbuf[1]);
745
            else
746
                FX_PlayWAV3D(rtsptr,0,0,0,255,-packbuf[1]);
747
            rtsplaying = 7;
748
            break;
749
 
750
        case 16:
751
            movefifoend[other] = movefifoplc = movefifosendplc = fakemovefifoplc = 0;
752
            syncvalhead[other] = syncvaltottail = 0L;
753
        case 17:
754
            j = 1;
755
 
756
            if ((movefifoend[other]&(TIMERUPDATESIZ-1)) == 0)
757
                if (other == connecthead)
758
                    for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
759
                    {
760
                        if (i == myconnectindex)
761
                            otherminlag = (long)((signed char)packbuf[j]);
762
                        j++;
763
                    }
764
 
765
            osyn = (input *)&inputfifo[(movefifoend[other]-1)&(MOVEFIFOSIZ-1)][0];
766
            nsyn = (input *)&inputfifo[(movefifoend[other])&(MOVEFIFOSIZ-1)][0];
767
 
768
            copybufbyte(&osyn[other],&nsyn[other],sizeof(input));
769
            k = packbuf[j++];
141 terminx 770
            k += (long)(packbuf[j++]<<8);
771
 
5 Plagman 772
            if (k&1)   nsyn[other].fvel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
773
            if (k&2)   nsyn[other].svel = packbuf[j]+((short)packbuf[j+1]<<8), j += 2;
774
            if (k&4)   nsyn[other].avel = (signed char)packbuf[j++];
775
            if (k&8)   nsyn[other].bits = ((nsyn[other].bits&0xffffff00)|((long)packbuf[j++]));
776
            if (k&16)  nsyn[other].bits = ((nsyn[other].bits&0xffff00ff)|((long)packbuf[j++])<<8);
777
            if (k&32)  nsyn[other].bits = ((nsyn[other].bits&0xff00ffff)|((long)packbuf[j++])<<16);
778
            if (k&64)  nsyn[other].bits = ((nsyn[other].bits&0x00ffffff)|((long)packbuf[j++])<<24);
779
            if (k&128) nsyn[other].horz = (signed char)packbuf[j++];
780
            if (k&256)  nsyn[other].bits2 = ((nsyn[other].bits2&0xffffff00)|((long)packbuf[j++]));
781
            if (k&512)  nsyn[other].bits2 = ((nsyn[other].bits2&0xffff00ff)|((long)packbuf[j++])<<8);
782
            if (k&1024) nsyn[other].bits2 = ((nsyn[other].bits2&0xff00ffff)|((long)packbuf[j++])<<16);
783
            if (k&2048) nsyn[other].bits2 = ((nsyn[other].bits2&0x00ffffff)|((long)packbuf[j++])<<24);
784
            movefifoend[other]++;
785
 
786
            for(i=1;i<movesperpacket;i++)
787
            {
788
                copybufbyte(&nsyn[other],&inputfifo[movefifoend[other]&(MOVEFIFOSIZ-1)][other],sizeof(input));
789
                movefifoend[other]++;
790
            }
791
 
792
            if (j > packbufleng)
793
                initprintf("INVALID GAME PACKET!!! (%ld too many bytes)\n",j-packbufleng);
794
 
795
            while (j != packbufleng)
796
            {
797
                syncval[other][syncvalhead[other]&(MOVEFIFOSIZ-1)] = packbuf[j++];
798
                syncvalhead[other]++;
799
            }
800
 
801
            break;
802
        case 127:
803
            break;
804
 
805
        case 250:
806
            playerreadyflag[other]++;
807
            break;
808
        case 255:
90 terminx 809
            gameexit(" ");
5 Plagman 810
            break;
811
        }
812
    }
813
}
814
 
815
extern void computergetinput(long snum, input *syn);
816
 
817
void faketimerhandler()
818
{
91 terminx 819
    long i, j, k;
5 Plagman 820
    //    short who;
821
    input *osyn, *nsyn;
822
 
823
    if(qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete))
824
    {
825
        qe = 1;
826
        gameexit("Quick Exit.");
827
    }
828
 
829
    sampletimer();
830
    AudioUpdate();
831
    if ((totalclock < ototalclock+TICSPERFRAME) || (ready2send == 0)) return;
832
    ototalclock += TICSPERFRAME;
833
 
834
    getpackets(); if (getoutputcirclesize() >= 16) return;
835
 
836
    for(i=connecthead;i>=0;i=connectpoint2[i])
837
        if (i != myconnectindex)
838
            if (movefifoend[i] < movefifoend[myconnectindex]-200) return;
839
 
840
    getinput(myconnectindex);
841
 
842
    avgfvel += loc.fvel;
843
    avgsvel += loc.svel;
844
    avgavel += loc.avel;
845
    avghorz += loc.horz;
846
    avgbits |= loc.bits;
847
    avgbits2 |= loc.bits2;
848
    if (movefifoend[myconnectindex]&(movesperpacket-1))
849
    {
850
        copybufbyte(&inputfifo[(movefifoend[myconnectindex]-1)&(MOVEFIFOSIZ-1)][myconnectindex],
851
                    &inputfifo[movefifoend[myconnectindex]&(MOVEFIFOSIZ-1)][myconnectindex],sizeof(input));
852
        movefifoend[myconnectindex]++;
853
        return;
854
    }
855
    nsyn = &inputfifo[movefifoend[myconnectindex]&(MOVEFIFOSIZ-1)][myconnectindex];
856
    nsyn[0].fvel = avgfvel/movesperpacket;
857
    nsyn[0].svel = avgsvel/movesperpacket;
858
    nsyn[0].avel = avgavel/movesperpacket;
859
    nsyn[0].horz = avghorz/movesperpacket;
860
    nsyn[0].bits = avgbits;
861
    nsyn[0].bits2 = avgbits2;
862
    avgfvel = avgsvel = avgavel = avghorz = avgbits = avgbits2 = 0;
863
    movefifoend[myconnectindex]++;
864
 
865
    if (numplayers < 2)
866
    {
867
        if (ud.multimode > 1) for(i=connecthead;i>=0;i=connectpoint2[i])
868
                if(i != myconnectindex)
869
                {
870
                    //clearbufbyte(&inputfifo[movefifoend[i]&(MOVEFIFOSIZ-1)][i],sizeof(input),0L);
871
                    if(ud.playerai)
872
                        computergetinput(i,&inputfifo[movefifoend[i]&(MOVEFIFOSIZ-1)][i]);
157 terminx 873
                    inputfifo[movefifoend[i]&(MOVEFIFOSIZ-1)][i].svel++;
874
                    inputfifo[movefifoend[i]&(MOVEFIFOSIZ-1)][i].fvel++;
5 Plagman 875
                    movefifoend[i]++;
876
                }
877
        return;
878
    }
879
 
880
    for(i=connecthead;i>=0;i=connectpoint2[i])
881
        if (i != myconnectindex)
882
        {
883
            k = (movefifoend[myconnectindex]-1)-movefifoend[i];
884
            myminlag[i] = min(myminlag[i],k);
885
            mymaxlag = max(mymaxlag,k);
886
        }
887
 
888
    if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0)
889
    {
890
        i = mymaxlag-bufferjitter; mymaxlag = 0;
891
        if (i > 0) bufferjitter += ((3+i)>>2);
892
        else if (i < 0) bufferjitter -= ((1-i)>>2);
893
    }
894
 
895
    if (networkmode == 1)
896
    {
897
        packbuf[0] = 17;
898
        if ((movefifoend[myconnectindex]-1) == 0) packbuf[0] = 16;
899
        j = 1;
900
 
901
        //Fix timers and buffer/jitter value
902
        if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0)
903
        {
904
            if (myconnectindex != connecthead)
905
            {
906
                i = myminlag[connecthead]-otherminlag;
907
                if (klabs(i) > 8) i >>= 1;
908
                else if (klabs(i) > 2) i = ksgn(i);
909
                else i = 0;
910
 
911
                totalclock -= TICSPERFRAME*i;
912
                myminlag[connecthead] -= i; otherminlag += i;
913
            }
914
 
915
            if (myconnectindex == connecthead)
916
                for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
917
                    packbuf[j++] = min(max(myminlag[i],-128),127);
918
 
919
            for(i=connecthead;i>=0;i=connectpoint2[i])
920
                myminlag[i] = 0x7fffffff;
921
        }
922
 
923
        osyn = (input *)&inputfifo[(movefifoend[myconnectindex]-2)&(MOVEFIFOSIZ-1)][myconnectindex];
924
        nsyn = (input *)&inputfifo[(movefifoend[myconnectindex]-1)&(MOVEFIFOSIZ-1)][myconnectindex];
925
 
926
        k = j;
927
        packbuf[j++] = 0;
928
        packbuf[j++] = 0;
929
 
930
        if (nsyn[0].fvel != osyn[0].fvel)
931
        {
932
            packbuf[j++] = (char)nsyn[0].fvel;
933
            packbuf[j++] = (char)(nsyn[0].fvel>>8);
934
            packbuf[k] |= 1;
935
        }
936
        if (nsyn[0].svel != osyn[0].svel)
937
        {
938
            packbuf[j++] = (char)nsyn[0].svel;
939
            packbuf[j++] = (char)(nsyn[0].svel>>8);
940
            packbuf[k] |= 2;
941
        }
942
        if (nsyn[0].avel != osyn[0].avel)
943
        {
944
            packbuf[j++] = (signed char)nsyn[0].avel;
945
            packbuf[k] |= 4;
946
        }
947
        if ((nsyn[0].bits^osyn[0].bits)&0x000000ff) packbuf[j++] = (nsyn[0].bits&255), packbuf[k] |= 8;
948
        if ((nsyn[0].bits^osyn[0].bits)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits>>8)&255), packbuf[k] |= 16;
949
        if ((nsyn[0].bits^osyn[0].bits)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits>>16)&255), packbuf[k] |= 32;
950
        if ((nsyn[0].bits^osyn[0].bits)&0xff000000) packbuf[j++] = ((nsyn[0].bits>>24)&255), packbuf[k] |= 64;
951
        if (nsyn[0].horz != osyn[0].horz)
952
        {
953
            packbuf[j++] = (char)nsyn[0].horz;
954
            packbuf[k] |= 128;
955
        }
956
        k++;
957
        packbuf[k] = 0;
958
        if ((nsyn[0].bits2^osyn[0].bits2)&0x000000ff) packbuf[j++] = (nsyn[0].bits2&255), packbuf[k] |= 1;
959
        if ((nsyn[0].bits2^osyn[0].bits2)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits2>>8)&255), packbuf[k] |= 2;
960
        if ((nsyn[0].bits2^osyn[0].bits2)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits2>>16)&255), packbuf[k] |= 4;
961
        if ((nsyn[0].bits2^osyn[0].bits2)&0xff000000) packbuf[j++] = ((nsyn[0].bits2>>24)&255), packbuf[k] |= 8;
962
 
963
        while (syncvalhead[myconnectindex] != syncvaltail)
964
        {
965
            packbuf[j++] = syncval[myconnectindex][syncvaltail&(MOVEFIFOSIZ-1)];
966
            syncvaltail++;
967
        }
968
 
969
        for(i=connecthead;i>=0;i=connectpoint2[i])
970
            if (i != myconnectindex)
971
                sendpacket(i,packbuf,j);
972
 
973
        return;
974
    }
975
    if (myconnectindex != connecthead)   //Slave
976
    {
977
        //Fix timers and buffer/jitter value
978
        if (((movefifoend[myconnectindex]-1)&(TIMERUPDATESIZ-1)) == 0)
979
        {
980
            i = myminlag[connecthead]-otherminlag;
981
            if (klabs(i) > 8) i >>= 1;
982
            else if (klabs(i) > 2) i = ksgn(i);
983
            else i = 0;
984
 
985
            totalclock -= TICSPERFRAME*i;
986
            myminlag[connecthead] -= i; otherminlag += i;
987
 
988
            for(i=connecthead;i>=0;i=connectpoint2[i])
989
                myminlag[i] = 0x7fffffff;
990
        }
991
 
992
        packbuf[0] = 1; packbuf[1] = 0; packbuf[2] = 0; j = 3;
993
 
994
        osyn = (input *)&inputfifo[(movefifoend[myconnectindex]-2)&(MOVEFIFOSIZ-1)][myconnectindex];
995
        nsyn = (input *)&inputfifo[(movefifoend[myconnectindex]-1)&(MOVEFIFOSIZ-1)][myconnectindex];
996
 
997
        if (nsyn[0].fvel != osyn[0].fvel)
998
        {
999
            packbuf[j++] = (char)nsyn[0].fvel;
1000
            packbuf[j++] = (char)(nsyn[0].fvel>>8);
1001
            packbuf[1] |= 1;
1002
        }
1003
        if (nsyn[0].svel != osyn[0].svel)
1004
        {
1005
            packbuf[j++] = (char)nsyn[0].svel;
1006
            packbuf[j++] = (char)(nsyn[0].svel>>8);
1007
            packbuf[1] |= 2;
1008
        }
1009
        if (nsyn[0].avel != osyn[0].avel)
1010
        {
1011
            packbuf[j++] = (signed char)nsyn[0].avel;
1012
            packbuf[1] |= 4;
1013
        }
1014
        if ((nsyn[0].bits^osyn[0].bits)&0x000000ff) packbuf[j++] = (nsyn[0].bits&255), packbuf[1] |= 8;
1015
        if ((nsyn[0].bits^osyn[0].bits)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits>>8)&255), packbuf[1] |= 16;
1016
        if ((nsyn[0].bits^osyn[0].bits)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits>>16)&255), packbuf[1] |= 32;
1017
        if ((nsyn[0].bits^osyn[0].bits)&0xff000000) packbuf[j++] = ((nsyn[0].bits>>24)&255), packbuf[1] |= 64;
1018
        if (nsyn[0].horz != osyn[0].horz)
1019
        {
1020
            packbuf[j++] = (char)nsyn[0].horz;
1021
            packbuf[1] |= 128;
1022
        }
1023
        packbuf[2] = 0;
1024
        if ((nsyn[0].bits2^osyn[0].bits2)&0x000000ff) packbuf[j++] = (nsyn[0].bits2&255), packbuf[2] |= 1;
1025
        if ((nsyn[0].bits2^osyn[0].bits2)&0x0000ff00) packbuf[j++] = ((nsyn[0].bits2>>8)&255), packbuf[2] |= 2;
1026
        if ((nsyn[0].bits2^osyn[0].bits2)&0x00ff0000) packbuf[j++] = ((nsyn[0].bits2>>16)&255), packbuf[2] |= 4;
1027
        if ((nsyn[0].bits2^osyn[0].bits2)&0xff000000) packbuf[j++] = ((nsyn[0].bits2>>24)&255), packbuf[2] |= 8;
1028
 
1029
        while (syncvalhead[myconnectindex] != syncvaltail)
1030
        {
1031
            packbuf[j++] = syncval[myconnectindex][syncvaltail&(MOVEFIFOSIZ-1)];
1032
            syncvaltail++;
1033
        }
1034
 
1035
        sendpacket(connecthead,packbuf,j);
1036
        return;
1037
    }
1038
 
1039
    //This allows allow packet resends
1040
    for(i=connecthead;i>=0;i=connectpoint2[i])
1041
        if (movefifoend[i] <= movefifosendplc)
1042
        {
1043
            packbuf[0] = 127;
1044
            for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1045
                sendpacket(i,packbuf,1);
1046
            return;
1047
        }
1048
 
1049
    while (1)  //Master
1050
    {
1051
        for(i=connecthead;i>=0;i=connectpoint2[i])
1052
            if (playerquitflag[i] && (movefifoend[i] <= movefifosendplc)) return;
1053
 
1054
        osyn = (input *)&inputfifo[(movefifosendplc-1)&(MOVEFIFOSIZ-1)][0];
1055
        nsyn = (input *)&inputfifo[(movefifosendplc  )&(MOVEFIFOSIZ-1)][0];
1056
 
1057
        //MASTER -> SLAVE packet
1058
        packbuf[0] = 0; j = 1;
1059
 
1060
        //Fix timers and buffer/jitter value
1061
        if ((movefifosendplc&(TIMERUPDATESIZ-1)) == 0)
1062
        {
1063
            for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1064
                if (playerquitflag[i])
1065
                    packbuf[j++] = min(max(myminlag[i],-128),127);
1066
 
1067
            for(i=connecthead;i>=0;i=connectpoint2[i])
1068
                myminlag[i] = 0x7fffffff;
1069
        }
1070
 
1071
        k = j;
1072
        for(i=connecthead;i>=0;i=connectpoint2[i])
1073
            j += playerquitflag[i] + playerquitflag[i];
1074
        for(i=connecthead;i>=0;i=connectpoint2[i])
1075
        {
1076
            if (playerquitflag[i] == 0) continue;
1077
 
1078
            packbuf[k] = 0;
1079
            if (nsyn[i].fvel != osyn[i].fvel)
1080
            {
1081
                packbuf[j++] = (char)nsyn[i].fvel;
1082
                packbuf[j++] = (char)(nsyn[i].fvel>>8);
1083
                packbuf[k] |= 1;
1084
            }
1085
            if (nsyn[i].svel != osyn[i].svel)
1086
            {
1087
                packbuf[j++] = (char)nsyn[i].svel;
1088
                packbuf[j++] = (char)(nsyn[i].svel>>8);
1089
                packbuf[k] |= 2;
1090
            }
1091
            if (nsyn[i].avel != osyn[i].avel)
1092
            {
1093
                packbuf[j++] = (signed char)nsyn[i].avel;
1094
                packbuf[k] |= 4;
1095
            }
1096
            if ((nsyn[i].bits^osyn[i].bits)&0x000000ff) packbuf[j++] = (nsyn[i].bits&255), packbuf[k] |= 8;
1097
            if ((nsyn[i].bits^osyn[i].bits)&0x0000ff00) packbuf[j++] = ((nsyn[i].bits>>8)&255), packbuf[k] |= 16;
1098
            if ((nsyn[i].bits^osyn[i].bits)&0x00ff0000) packbuf[j++] = ((nsyn[i].bits>>16)&255), packbuf[k] |= 32;
1099
            if ((nsyn[i].bits^osyn[i].bits)&0xff000000) packbuf[j++] = ((nsyn[i].bits>>24)&255), packbuf[k] |= 64;
1100
            if (nsyn[i].horz != osyn[i].horz)
1101
            {
1102
                packbuf[j++] = (char)nsyn[i].horz;
1103
                packbuf[k] |= 128;
1104
            }
1105
            k++;
1106
            packbuf[k] = 0;
1107
            if ((nsyn[i].bits2^osyn[i].bits2)&0x000000ff) packbuf[j++] = (nsyn[i].bits2&255), packbuf[k] |= 1;
1108
            if ((nsyn[i].bits2^osyn[i].bits2)&0x0000ff00) packbuf[j++] = ((nsyn[i].bits2>>8)&255), packbuf[k] |= 2;
1109
            if ((nsyn[i].bits2^osyn[i].bits2)&0x00ff0000) packbuf[j++] = ((nsyn[i].bits2>>16)&255), packbuf[k] |= 4;
1110
            if ((nsyn[i].bits2^osyn[i].bits2)&0xff000000) packbuf[j++] = ((nsyn[i].bits2>>24)&255), packbuf[k] |= 8;
1111
            k++;
1112
        }
1113
 
1114
        while (syncvalhead[myconnectindex] != syncvaltail)
1115
        {
1116
            packbuf[j++] = syncval[myconnectindex][syncvaltail&(MOVEFIFOSIZ-1)];
1117
            syncvaltail++;
1118
        }
1119
 
1120
        for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1121
            if (playerquitflag[i])
1122
            {
1123
                sendpacket(i,packbuf,j);
1124
                if (nsyn[i].bits&(1<<26))
1125
                    playerquitflag[i] = 0;
1126
            }
1127
 
1128
        movefifosendplc += movesperpacket;
1129
    }
1130
}
1131
 
1132
extern long cacnum;
1133
typedef struct { long *hand, leng; char *lock; } cactype;
1134
extern cactype cac[];
1135
 
1136
void caches(void)
1137
{
1138
    short i,k;
1139
 
1140
    k = 0;
1141
    for(i=0;i<cacnum;i++)
1142
        if ((*cac[i].lock) >= 200)
1143
        {
1144
            Bsprintf(tempbuf,"Locked- %d: Leng:%ld, Lock:%d",i,cac[i].leng,*cac[i].lock);
1145
            printext256(0L,k,31,-1,tempbuf,1); k += 6;
1146
        }
1147
 
1148
    k += 6;
1149
 
1150
    for(i=1;i<11;i++)
1151
        if (lumplockbyte[i] >= 200)
1152
        {
1153
            Bsprintf(tempbuf,"RTS Locked %d:",i);
1154
            printext256(0L,k,31,-1,tempbuf,1); k += 6;
1155
        }
1156
 
1157
 
1158
}
1159
 
1160
void checksync(void)
1161
{
91 terminx 1162
    long i;
5 Plagman 1163
 
1164
    for(i=connecthead;i>=0;i=connectpoint2[i])
1165
        if (syncvalhead[i] == syncvaltottail) break;
1166
    if (i < 0)
1167
    {
1168
        syncstat = 0;
1169
        do
1170
        {
1171
            for(i=connectpoint2[connecthead];i>=0;i=connectpoint2[i])
1172
                if (syncval[i][syncvaltottail&(MOVEFIFOSIZ-1)] !=
1173
                        syncval[connecthead][syncvaltottail&(MOVEFIFOSIZ-1)])
1174
                    syncstat = 1;
1175
 
1176
            syncvaltottail++;
1177
            for(i=connecthead;i>=0;i=connectpoint2[i])
1178
                if (syncvalhead[i] == syncvaltottail) break;
1179
        } while (i < 0);
1180
    }
1181
    if (connectpoint2[connecthead] < 0) syncstat = 0;
1182
 
1183
    if (syncstat)
1184
    {
1185
        printext256(4L,130L,31,0,"Out Of Sync - Please restart game",0);
1186
        printext256(4L,138L,31,0,"RUN DN3DHELP.EXE for information.",0);
1187
    }
1188
    if (syncstate)
1189
    {
1190
        printext256(4L,160L,31,0,"Missed Network packet!",0);
1191
        printext256(4L,138L,31,0,"RUN DN3DHELP.EXE for information.",0);
1192
    }
1193
}
1194
 
1195
void check_fta_sounds(short i)
1196
{
1197
    if(sprite[i].extra > 0)
1198
        switch(dynamictostatic[PN])
1199
        {
1200
        case LIZTROOPONTOILET__STATIC:
1201
        case LIZTROOPJUSTSIT__STATIC:
1202
        case LIZTROOPSHOOT__STATIC:
1203
        case LIZTROOPJETPACK__STATIC:
1204
        case LIZTROOPDUCKING__STATIC:
1205
        case LIZTROOPRUNNING__STATIC:
1206
        case LIZTROOP__STATIC:
1207
            spritesound(PRED_RECOG,i);
1208
            break;
1209
        case LIZMAN__STATIC:
1210
        case LIZMANSPITTING__STATIC:
1211
        case LIZMANFEEDING__STATIC:
1212
        case LIZMANJUMP__STATIC:
1213
            spritesound(CAPT_RECOG,i);
1214
            break;
1215
        case PIGCOP__STATIC:
1216
        case PIGCOPDIVE__STATIC:
1217
            spritesound(PIG_RECOG,i);
1218
            break;
1219
        case RECON__STATIC:
1220
            spritesound(RECO_RECOG,i);
1221
            break;
1222
        case DRONE__STATIC:
1223
            spritesound(DRON_RECOG,i);
1224
            break;
1225
        case COMMANDER__STATIC:
1226
        case COMMANDERSTAYPUT__STATIC:
1227
            spritesound(COMM_RECOG,i);
1228
            break;
1229
        case ORGANTIC__STATIC:
1230
            spritesound(TURR_RECOG,i);
1231
            break;
1232
        case OCTABRAIN__STATIC:
1233
        case OCTABRAINSTAYPUT__STATIC:
1234
            spritesound(OCTA_RECOG,i);
1235
            break;
1236
        case BOSS1__STATIC:
1237
            sound(BOS1_RECOG);
1238
            break;
1239
        case BOSS2__STATIC:
1240
            if(sprite[i].pal == 1)
1241
                sound(BOS2_RECOG);
1242
            else sound(WHIPYOURASS);
1243
            break;
1244
        case BOSS3__STATIC:
1245
            if(sprite[i].pal == 1)
1246
                sound(BOS3_RECOG);
1247
            else sound(RIPHEADNECK);
1248
            break;
1249
        case BOSS4__STATIC:
1250
        case BOSS4STAYPUT__STATIC:
1251
            if(sprite[i].pal == 1)
1252
                sound(BOS4_RECOG);
1253
            sound(BOSS4_FIRSTSEE);
1254
            break;
1255
        case GREENSLIME__STATIC:
1256
            spritesound(SLIM_RECOG,i);
1257
            break;
1258
        }
1259
}
1260
 
1261
inline short inventory(spritetype *s)
1262
{
1263
    switch(dynamictostatic[s->picnum])
1264
    {
1265
    case FIRSTAID__STATIC:
1266
    case STEROIDS__STATIC:
1267
    case HEATSENSOR__STATIC:
1268
    case BOOTS__STATIC:
1269
    case JETPACK__STATIC:
1270
    case HOLODUKE__STATIC:
1271
    case AIRTANK__STATIC:
1272
        return 1;
1273
    }
1274
    return 0;
1275
}
1276
 
1277
inline int checkspriteflags(short sActor, int iType)
1278
{
1279
    int i;
1280
 
1281
    i = spriteflags[sprite[sActor].picnum]; i ^= actorspriteflags[sActor];
1282
    if(i & iType) return 1;
1283
    else return 0;
1284
}
1285
 
1286
inline int checkspriteflagsp(short sPicnum, int iType)
1287
{
1288
    if(spriteflags[sPicnum] & iType) return 1;
1289
    else return 0;
1290
}
1291
 
1292
inline short badguypic(short pn)
1293
{
1294
    //this case can't be handled by the dynamictostatic system because it adds
1295
    //stuff to the value from names.h so handling separately
1296
    if ((pn >= GREENSLIME) && (pn <= GREENSLIME+7)) return 1;
1297
 
1298
    if(checkspriteflagsp(pn,SPRITE_FLAG_BADGUY)) return 1;
1299
 
1300
    if( actortype[pn] ) return 1;
1301
 
1302
    switch(dynamictostatic[pn])
1303
    {
1304
    case SHARK__STATIC:
1305
    case RECON__STATIC:
1306
    case DRONE__STATIC:
1307
    case LIZTROOPONTOILET__STATIC:
1308
    case LIZTROOPJUSTSIT__STATIC:
1309
    case LIZTROOPSTAYPUT__STATIC:
1310
    case LIZTROOPSHOOT__STATIC:
1311
    case LIZTROOPJETPACK__STATIC:
1312
    case LIZTROOPDUCKING__STATIC:
1313
    case LIZTROOPRUNNING__STATIC:
1314
    case LIZTROOP__STATIC:
1315
    case OCTABRAIN__STATIC:
1316
    case COMMANDER__STATIC:
1317
    case COMMANDERSTAYPUT__STATIC:
1318
    case PIGCOP__STATIC:
1319
    case EGG__STATIC:
1320
    case PIGCOPSTAYPUT__STATIC:
1321
    case PIGCOPDIVE__STATIC:
1322
    case LIZMAN__STATIC:
1323
    case LIZMANSPITTING__STATIC:
1324
    case LIZMANFEEDING__STATIC:
1325
    case LIZMANJUMP__STATIC:
1326
    case ORGANTIC__STATIC:
1327
    case BOSS1__STATIC:
1328
    case BOSS2__STATIC:
1329
    case BOSS3__STATIC:
1330
    case BOSS4__STATIC:
1331
        //case GREENSLIME:
1332
        //case GREENSLIME+1:
1333
        //case GREENSLIME+2:
1334
        //case GREENSLIME+3:
1335
        //case GREENSLIME+4:
1336
        //case GREENSLIME+5:
1337
        //case GREENSLIME+6:
1338
        //case GREENSLIME+7:
1339
    case RAT__STATIC:
1340
    case ROTATEGUN__STATIC:
1341
        return 1;
1342
    }
1343
    return 0;
1344
}
1345
 
1346
inline short badguy(spritetype *s)
1347
{
1348
    return(badguypic(s->picnum));
1349
}
1350
 
1351
void myos(long x, long y, short tilenum, signed char shade, char orientation)
1352
{
1353
    char p;
1354
    short a;
1355
 
1356
    if(orientation&4)
1357
        a = 1024;
1358
    else a = 0;
1359
 
1360
    p = sector[ps[screenpeek].cursectnum].floorpal;
1361
    rotatesprite(x<<16,y<<16,65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
1362
}
1363
 
1364
void myospal(long x, long y, short tilenum, signed char shade, char orientation, char p)
1365
{
1366
    short a;
1367
 
1368
    if(orientation&4)
1369
        a = 1024;
1370
    else a = 0;
1371
 
1372
    rotatesprite(x<<16,y<<16,65536L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
1373
}
1374
 
1375
void myosx(long x, long y, short tilenum, signed char shade, char orientation)
1376
{
1377
    char p;
1378
    short a;
1379
 
1380
    if(orientation&4)
1381
        a = 1024;
1382
    else a = 0;
1383
 
1384
    p = sector[ps[screenpeek].cursectnum].floorpal;
1385
    rotatesprite(x<<16,y<<16,32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
1386
}
1387
 
1388
void myospalx(long x, long y, short tilenum, signed char shade, char orientation, char p)
1389
{
1390
    short a;
1391
 
1392
    if(orientation&4)
1393
        a = 1024;
1394
    else a = 0;
1395
 
1396
    rotatesprite(x<<16,y<<16,32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);
1397
}
1398
 
1399
void invennum(long x,long y,char num1,char ha,char sbits)
1400
{
1401
    char dabuf[80] = {0};
1402
    Bsprintf(dabuf,"%d",num1);
1403
    if(num1 > 99)
1404
    {
1405
        rotatesprite(sbarx(x-4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1406
        rotatesprite(sbarx(x),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1407
        rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[2]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1408
    }
1409
    else if(num1 > 9)
1410
    {
1411
        rotatesprite(sbarx(x),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1412
        rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1413
    }
1414
    else
1415
        rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits,0,0,xdim-1,ydim-1);
1416
}
1417
 
91 terminx 1418
void orderweaponnum(short ind,long x,long y,char ha)
5 Plagman 1419
{
1420
    rotatesprite(sbarx(x-7),sbary(y),sbarsc(65536L),0,THREEBYFIVE+ind+1,ha-10,7,10,0,0,xdim-1,ydim-1);
1421
    rotatesprite(sbarx(x-3),sbary(y),sbarsc(65536L),0,THREEBYFIVE+10,ha,0,10,0,0,xdim-1,ydim-1);
1422
 
129 terminx 1423
    minitextshade(x+1,y-4,"ORDER",26,6,2+8+16);
5 Plagman 1424
}
1425
 
1426
void weaponnum(short ind,long x,long y,long num1, long num2,char ha)
1427
{
1428
    char dabuf[80] = {0};
1429
 
1430
    rotatesprite(sbarx(x-7),sbary(y),sbarsc(65536L),0,THREEBYFIVE+ind+1,ha-10,7,10,0,0,xdim-1,ydim-1);
1431
    rotatesprite(sbarx(x-3),sbary(y),sbarsc(65536L),0,THREEBYFIVE+10,ha,0,10,0,0,xdim-1,ydim-1);
1432
    rotatesprite(sbarx(x+9),sbary(y),sbarsc(65536L),0,THREEBYFIVE+11,ha,0,10,0,0,xdim-1,ydim-1);
1433
 
1434
    if(num1 > 99) num1 = 99;
1435
    if(num2 > 99) num2 = 99;
1436
 
1437
    Bsprintf(dabuf,"%ld",num1);
1438
    if(num1 > 9)
1439
    {
1440
        rotatesprite(sbarx(x),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1441
        rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1442
    }
1443
    else rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1444
 
1445
    Bsprintf(dabuf,"%ld",num2);
1446
    if(num2 > 9)
1447
    {
1448
        rotatesprite(sbarx(x+13),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1449
        rotatesprite(sbarx(x+17),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1450
    }
1451
    else rotatesprite(sbarx(x+13),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1452
}
1453
 
1454
void weaponnum999(char ind,long x,long y,long num1, long num2,char ha)
1455
{
1456
    char dabuf[80] = {0};
1457
 
1458
    rotatesprite(sbarx(x-7),sbary(y),sbarsc(65536L),0,THREEBYFIVE+ind+1,ha-10,7,10,0,0,xdim-1,ydim-1);
1459
    rotatesprite(sbarx(x-4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+10,ha,0,10,0,0,xdim-1,ydim-1);
1460
    rotatesprite(sbarx(x+13),sbary(y),sbarsc(65536L),0,THREEBYFIVE+11,ha,0,10,0,0,xdim-1,ydim-1);
1461
 
1462
    Bsprintf(dabuf,"%ld",num1);
1463
    if(num1 > 99)
1464
    {
1465
        rotatesprite(sbarx(x),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1466
        rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1467
        rotatesprite(sbarx(x+8),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[2]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1468
    }
1469
    else if(num1 > 9)
1470
    {
1471
        rotatesprite(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1472
        rotatesprite(sbarx(x+8),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1473
    }
1474
    else rotatesprite(sbarx(x+8),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1475
 
1476
    Bsprintf(dabuf,"%ld",num2);
1477
    if(num2 > 99)
1478
    {
1479
        rotatesprite(sbarx(x+17),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1480
        rotatesprite(sbarx(x+21),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1481
        rotatesprite(sbarx(x+25),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[2]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1482
    }
1483
    else if(num2 > 9)
1484
    {
1485
        rotatesprite(sbarx(x+17),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1486
        rotatesprite(sbarx(x+21),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1487
    }
1488
    else rotatesprite(sbarx(x+25),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10,0,0,xdim-1,ydim-1);
1489
}
1490
 
1491
void weapon_amounts(struct player_struct *p,long x,long y,long u)
1492
{
1493
    int cw;
1494
 
1495
    cw = p->curr_weapon;
1496
 
1497
    if (u&4)
1498
    {
1499
        if (u != -1) patchstatusbar(88,178,88+37,178+6); //original code: (96,178,96+12,178+6);
1500
        weaponnum999(PISTOL_WEAPON,x,y,
1501
                     p->ammo_amount[PISTOL_WEAPON],max_ammo_amount[PISTOL_WEAPON],
1502
                     12-20*(cw == PISTOL_WEAPON) );
1503
    }
1504
    if (u&8)
1505
    {
1506
        if (u != -1) patchstatusbar(88,184,88+37,184+6); //original code: (96,184,96+12,184+6);
1507
        weaponnum999(SHOTGUN_WEAPON,x,y+6,
1508
                     p->ammo_amount[SHOTGUN_WEAPON],max_ammo_amount[SHOTGUN_WEAPON],
1509
                     (!p->gotweapon[SHOTGUN_WEAPON]*9)+12-18*
1510
                     (cw == SHOTGUN_WEAPON) );
1511
    }
1512
    if (u&16)
1513
    {
1514
        if (u != -1) patchstatusbar(88,190,88+37,190+6); //original code: (96,190,96+12,190+6);
1515
        weaponnum999(CHAINGUN_WEAPON,x,y+12,
1516
                     p->ammo_amount[CHAINGUN_WEAPON],max_ammo_amount[CHAINGUN_WEAPON],
1517
                     (!p->gotweapon[CHAINGUN_WEAPON]*9)+12-18*
1518
                     (cw == CHAINGUN_WEAPON) );
1519
    }
1520
    if (u&32)
1521
    {
1522
        if (u != -1) patchstatusbar(127,178,127+29,178+6); //original code: (135,178,135+8,178+6);
1523
        weaponnum(RPG_WEAPON,x+39,y,
1524
                  p->ammo_amount[RPG_WEAPON],max_ammo_amount[RPG_WEAPON],
1525
                  (!p->gotweapon[RPG_WEAPON]*9)+12-19*
1526
                  (cw == RPG_WEAPON) );
1527
    }
1528
    if (u&64)
1529
    {
1530
        if (u != -1) patchstatusbar(127,184,127+29,184+6); //original code: (135,184,135+8,184+6);
1531
        weaponnum(HANDBOMB_WEAPON,x+39,y+6,
1532
                  p->ammo_amount[HANDBOMB_WEAPON],max_ammo_amount[HANDBOMB_WEAPON],
1533
                  (((!p->ammo_amount[HANDBOMB_WEAPON])|(!p->gotweapon[HANDBOMB_WEAPON]))*9)+12-19*
1534
                  ((cw == HANDBOMB_WEAPON) || (cw == HANDREMOTE_WEAPON)));
1535
    }
1536
    if (u&128)
1537
    {
1538
        if (u != -1) patchstatusbar(127,190,127+29,190+6); //original code: (135,190,135+8,190+6);
1539
 
1540
        if (VOLUMEONE) {
1541
            orderweaponnum(SHRINKER_WEAPON,x+39,y+12,
1542
                           (!p->gotweapon[SHRINKER_WEAPON]*9)+12-18*
1543
                           (cw == SHRINKER_WEAPON) );
1544
        } else {
1545
            if(p->subweapon&(1<<GROW_WEAPON))
1546
                weaponnum(SHRINKER_WEAPON,x+39,y+12,
1547
                          p->ammo_amount[GROW_WEAPON],max_ammo_amount[GROW_WEAPON],
1548
                          (!p->gotweapon[GROW_WEAPON]*9)+12-18*
1549
                          (cw == GROW_WEAPON) );
1550
            else
1551
                weaponnum(SHRINKER_WEAPON,x+39,y+12,
1552
                          p->ammo_amount[SHRINKER_WEAPON],max_ammo_amount[SHRINKER_WEAPON],
1553
                          (!p->gotweapon[SHRINKER_WEAPON]*9)+12-18*
1554
                          (cw == SHRINKER_WEAPON) );
1555
        }
1556
    }
1557
    if (u&256)
1558
    {
1559
        if (u != -1) patchstatusbar(158,178,162+29,178+6); //original code: (166,178,166+8,178+6);
1560
 
1561
        if (VOLUMEONE) {
1562
            orderweaponnum(DEVISTATOR_WEAPON,x+70,y,
1563
                           (!p->gotweapon[DEVISTATOR_WEAPON]*9)+12-18*
1564
                           (cw == DEVISTATOR_WEAPON) );
1565
        } else {
1566
            weaponnum(DEVISTATOR_WEAPON,x+70,y,
1567
                      p->ammo_amount[DEVISTATOR_WEAPON],max_ammo_amount[DEVISTATOR_WEAPON],
1568
                      (!p->gotweapon[DEVISTATOR_WEAPON]*9)+12-18*
1569
                      (cw == DEVISTATOR_WEAPON) );
1570
        }
1571
    }
1572
    if (u&512)
1573
    {
1574
        if (u != -1) patchstatusbar(158,184,162+29,184+6); //original code: (166,184,166+8,184+6);
1575
        if (VOLUMEONE) {
1576
            orderweaponnum(TRIPBOMB_WEAPON,x+70,y+6,
1577
                           (!p->gotweapon[TRIPBOMB_WEAPON]*9)+12-18*
1578
                           (cw == TRIPBOMB_WEAPON) );
1579
        } else {
1580
            weaponnum(TRIPBOMB_WEAPON,x+70,y+6,
1581
                      p->ammo_amount[TRIPBOMB_WEAPON],max_ammo_amount[TRIPBOMB_WEAPON],
1582
                      (!p->gotweapon[TRIPBOMB_WEAPON]*9)+12-18*
1583
                      (cw == TRIPBOMB_WEAPON) );
1584
        }
1585
    }
1586
 
1587
    if (u&65536L)
1588
    {
1589
        if (u != -1) patchstatusbar(158,190,162+29,190+6); //original code: (166,190,166+8,190+6);
1590
        if (VOLUMEONE) {
1591
            orderweaponnum(-1,x+70,y+12,
1592
                           (!p->gotweapon[FREEZE_WEAPON]*9)+12-18*
1593
                           (cw == FREEZE_WEAPON) );
1594
        } else {
1595
            weaponnum(-1,x+70,y+12,
1596
                      p->ammo_amount[FREEZE_WEAPON],max_ammo_amount[FREEZE_WEAPON],
1597
                      (!p->gotweapon[FREEZE_WEAPON]*9)+12-18*
1598
                      (cw == FREEZE_WEAPON) );
1599
        }
1600
    }
1601
}
1602
 
1603
void digitalnumber(long x,long y,long n,char s,char cs)
1604
{
1605
 
1606
    short i, j, k, p, c;
1607
    char b[10];
1608
 
1609
    //ltoa(n,b,10);
1610
    Bsnprintf(b,10,"%ld",n);
232 terminx 1611
    i = Bstrlen(b);
5 Plagman 1612
    j = 0;
1613
 
1614
    for(k=0;k<i;k++)
1615
    {
1616
        p = DIGITALNUM+*(b+k)-'0';
1617
        j += tilesizx[p]+1;
1618
    }
1619
    c = x-(j>>1);
1620
 
1621
    j = 0;
1622
    for(k=0;k<i;k++)
1623
    {
1624
        p = DIGITALNUM+*(b+k)-'0';
1625
        rotatesprite(sbarx(c+j),sbary(y),sbarsc(65536L),0,p,s,0,cs,0,0,xdim-1,ydim-1);
1626
        j += tilesizx[p]+1;
1627
    }
1628
}
1629
 
1630
void txdigitalnumber(short starttile, long x,long y,long n,char s,char pal,char cs,long x1, long y1, long x2, long y2)
1631
{
1632
    short i, j, k, p, c;
1633
    char b[10];
1634
 
1635
    //ltoa(n,b,10);
1636
    Bsnprintf(b,10,"%ld",n);
232 terminx 1637
    i = Bstrlen(b);
5 Plagman 1638
    j = 0;
1639
 
1640
    for(k=0;k<i;k++)
1641
    {
1642
        p = starttile+*(b+k)-'0';
1643
        j += tilesizx[p]+1;
1644
    }
1645
    c = x-(j>>1);
1646
 
1647
    j = 0;
1648
    for(k=0;k<i;k++)
1649
    {
1650
        p = starttile+*(b+k)-'0';
1651
        rotatesprite((c+j)<<16,y<<16,65536L,0,p,s,pal,2|cs,x1,y1,x2,y2);
1652
        /*        rotatesprite((c+j)<<16,y<<16,65536L,0,p,s,pal,cs,0,0,xdim-1,ydim-1);
1653
                rotatesprite(x<<16,y<<16,32768L,a,tilenum,shade,p,2|orientation,windowx1,windowy1,windowx2,windowy2);*/
1654
        j += tilesizx[p]+1;
1655
    }
1656
}
1657
 
1658
/*
1659
 
1660
void scratchmarks(long x,long y,long n,char s,char p)
1661
{
1662
    long i, ni;
1663
 
1664
    ni = n/5;
1665
    for(i=ni;i >= 0;i--)
1666
    {
1667
        overwritesprite(x-2,y,SCRATCH+4,s,0,0);
1668
        x += tilesizx[SCRATCH+4]-1;
1669
    }
1670
 
1671
    ni = n%5;
1672
    if(ni) overwritesprite(x,y,SCRATCH+ni-1,s,p,0);
1673
}
1674
  */
1675
void displayinventory(struct player_struct *p)
1676
{
1677
    short n, j, xoff, y;
1678
 
1679
    j = xoff = 0;
1680
 
1681
    n = (p->jetpack_amount > 0)<<3; if(n&8) j++;
1682
    n |= ( p->scuba_amount > 0 )<<5; if(n&32) j++;
1683
    n |= (p->steroids_amount > 0)<<1; if(n&2) j++;
1684
    n |= ( p->holoduke_amount > 0)<<2; if(n&4) j++;
1685
    n |= (p->firstaid_amount > 0); if(n&1) j++;
1686
    n |= (p->heat_amount > 0)<<4; if(n&16) j++;
1687
    n |= (p->boot_amount > 0)<<6; if(n&64) j++;
1688
 
1689
    xoff = 160-(j*11);
1690
 
1691
    j = 0;
1692
 
1693
    if(ud.screen_size > 4)
1694
        y = 154;
48 terminx 1695
    else y = (ud.drawweapon == 2?150:172);
5 Plagman 1696
 
48 terminx 1697
    if(ud.screen_size == 4 && ud.drawweapon != 2)
5 Plagman 1698
    {
1699
        if(ud.multimode > 1)
1700
            xoff += 56;
1701
        else xoff += 65;
1702
    }
1703
 
1704
    while( j <= 9 )
1705
    {
1706
        if( n&(1<<j) )
1707
        {
1708
            switch( n&(1<<j) )
1709
            {
1710
            case   1:
1711
                rotatesprite(xoff<<16,y<<16,65536L,0,FIRSTAID_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1712
            case   2:
1713
                rotatesprite((xoff+1)<<16,y<<16,65536L,0,STEROIDS_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1714
            case   4:
1715
                rotatesprite((xoff+2)<<16,y<<16,65536L,0,HOLODUKE_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1716
            case   8:
1717
                rotatesprite(xoff<<16,y<<16,65536L,0,JETPACK_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1718
            case  16:
1719
                rotatesprite(xoff<<16,y<<16,65536L,0,HEAT_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1720
            case  32:
1721
                rotatesprite(xoff<<16,y<<16,65536L,0,AIRTANK_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1722
            case 64:
1723
                rotatesprite(xoff<<16,(y-1)<<16,65536L,0,BOOT_ICON,0,0,2+16,windowx1,windowy1,windowx2,windowy2);break;
1724
            }
1725
 
1726
            xoff += 22;
1727
 
1728
            if(p->inven_icon == j+1)
1729
                rotatesprite((xoff-2)<<16,(y+19)<<16,65536L,1024,ARROW,-32,0,2+16,windowx1,windowy1,windowx2,windowy2);
1730
        }
1731
 
1732
        j++;
1733
    }
1734
}
1735
 
1736
void displayfragbar(void)
1737
{
1738
    short i, j;
1739
 
1740
    j = 0;
1741
 
1742
    for(i=connecthead;i>=0;i=connectpoint2[i])
1743
        if(i > j) j = i;
1744
 
1745
    rotatesprite(0,0,65600L,0,FRAGBAR,0,0,2+8+16+64,0,0,xdim-1,ydim-1);
1746
    if(j >= 4) rotatesprite(319,(8)<<16,65600L,0,FRAGBAR,0,0,10+16+64,0,0,xdim-1,ydim-1);
1747
    if(j >= 8) rotatesprite(319,(16)<<16,65600L,0,FRAGBAR,0,0,10+16+64,0,0,xdim-1,ydim-1);
1748
    if(j >= 12) rotatesprite(319,(24)<<16,65600L,0,FRAGBAR,0,0,10+16+64,0,0,xdim-1,ydim-1);
1749
 
1750
    for(i=connecthead;i>=0;i=connectpoint2[i])
1751
    {
57 terminx 1752
        minitext(21+(73*(i&3)),2+((i&28)<<1),&ud.user_name[i][0],/*sprite[ps[i].i].pal*/ps[i].palookup,2+8+16);
5 Plagman 1753
        Bsprintf(tempbuf,"%d",ps[i].frag-ps[i].fraggedself);
57 terminx 1754
        minitext(17+50+(73*(i&3)),2+((i&28)<<1),tempbuf,/*sprite[ps[i].i].pal*/ps[i].palookup,2+8+16);
5 Plagman 1755
    }
1756
}
1757
 
1758
void coolgaugetext(short snum)
1759
{
1760
    struct player_struct *p;
1761
    long i, j, o, ss, u;
91 terminx 1762
    char permbit;
5 Plagman 1763
 
1764
    p = &ps[snum];
1765
 
1766
    if (p->invdisptime > 0) displayinventory(p);
1767
 
1768
 
1769
    if(ps[snum].gm&MODE_MENU)
1770
        if( (current_menu >= 400  && current_menu <= 405) )
1771
            return;
1772
 
1773
    ss = ud.screen_size; if (ss < 4) return;
1774
 
1775
    if (getrendermode() >= 3) pus = NUMPAGES;   // JBF 20040101: always redraw in GL
1776
 
1777
    if ( ud.multimode > 1 && (gametype_flags[ud.coop] & GAMETYPE_FLAG_FRAGBAR))
1778
    {
1779
        if (pus)
1780
        { displayfragbar(); }
1781
        else
1782
        {
1783
            for(i=connecthead;i>=0;i=connectpoint2[i])
1784
            if (ps[i].frag != sbar.frag[i]) { displayfragbar(); break; }
1785
        }
1786
        for(i=connecthead;i>=0;i=connectpoint2[i])
1787
            if (i != myconnectindex)
1788
                sbar.frag[i] = ps[i].frag;
1789
    }
1790
 
1791
    if (ss == 4)   //DRAW MINI STATUS BAR:
1792
    {
1793
        rotatesprite(sbarx(5),sbary(200-28),sbarsc(65536L),0,HEALTHBOX,0,21,10+16,0,0,xdim-1,ydim-1);
1794
        if (p->inven_icon)
1795
            rotatesprite(sbarx(69),sbary(200-30),sbarsc(65536L),0,INVENTORYBOX,0,21,10+16,0,0,xdim-1,ydim-1);
1796
 
1797
        if(sprite[p->i].pal == 1 && p->last_extra < 2)
1798
            digitalnumber(20,200-17,1,-16,10+16);
1799
        else digitalnumber(20,200-17,p->last_extra,-16,10+16);
1800
 
1801
        rotatesprite(sbarx(37),sbary(200-28),sbarsc(65536L),0,AMMOBOX,0,21,10+16,0,0,xdim-1,ydim-1);
1802
 
1803
        if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON; else i = p->curr_weapon;
1804
        digitalnumber(53,200-17,p->ammo_amount[i],-16,10+16);
1805
 
1806
        o = 158; permbit = 0;
1807
        if (p->inven_icon)
1808
        {
1809
            switch(p->inven_icon)
1810
            {
1811
            case 1: i = FIRSTAID_ICON; break;
1812
            case 2: i = STEROIDS_ICON; break;
1813
            case 3: i = HOLODUKE_ICON; break;
1814
            case 4: i = JETPACK_ICON; break;
1815
            case 5: i = HEAT_ICON; break;
1816
            case 6: i = AIRTANK_ICON; break;
1817
            case 7: i = BOOT_ICON; break;
1818
            default: i = -1;
1819
            }
1820
            if (i >= 0) rotatesprite(sbarx(231-o),sbary(200-21),sbarsc(65536L),0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
1821
 
1822
            minitext(292-30-o,190,"%",6,10+16+permbit + 256);
1823
 
1824
            j = 0x80000000;
1825
            switch(p->inven_icon)
1826
            {
1827
            case 1: i = p->firstaid_amount; break;
1828
            case 2: i = ((p->steroids_amount+3)>>2); break;
1829
            case 3: i = ((p->holoduke_amount+15)/24); j = p->holoduke_on; break;
1830
            case 4: i = ((p->jetpack_amount+15)>>4); j = p->jetpack_on; break;
1831
            case 5: i = p->heat_amount/12; j = p->heat_on; break;
1832
            case 6: i = ((p->scuba_amount+63)>>6); break;
1833
            case 7: i = (p->boot_amount>>1); break;
1834
            }
109 terminx 1835
            invennum(284-30-o,200-6,(char)i,0,10+permbit);
1836
            if (j > 0) minitext(288-30-o,180,"ON",0,10+16+permbit + 256);
1837
            else if ((unsigned long)j != 0x80000000) minitext(284-30-o,180,"OFF",2,10+16+permbit + 256);
1838
            if (p->inven_icon >= 6) minitext(284-35-o,180,"AUTO",2,10+16+permbit + 256);
5 Plagman 1839
        }
1840
        return;
1841
    }
1842
 
1843
    //DRAW/UPDATE FULL STATUS BAR:
1844
 
1845
if (pus) { pus = 0; u = -1; } else u = 0;
1846
 
1847
if (sbar.frag[myconnectindex] != p->frag) { sbar.frag[myconnectindex] = p->frag; u |= 32768; }
1848
    if (sbar.got_access != p->got_access) { sbar.got_access = p->got_access; u |= 16384; }
1849
    if (sbar.last_extra != p->last_extra) { sbar.last_extra = p->last_extra; u |= 1; }
1850
    {
1851
        long lAmount=GetGameVar("PLR_MORALE",-1, p->i, snum);
1852
        if(lAmount == -1)
1853
        {
1854
            if (sbar.shield_amount != p->shield_amount) { sbar.shield_amount = p->shield_amount; u |= 2; }
1855
        }
1856
        else
1857
        {
1858
            if (sbar.shield_amount != lAmount) { sbar.shield_amount = lAmount; u |= 2; }
1859
        }
1860
    }
1861
    if (sbar.curr_weapon != p->curr_weapon) { sbar.curr_weapon = p->curr_weapon; u |= (4+8+16+32+64+128+256+512+1024+65536L); }
218 terminx 1862
 
1863
    for(i=1;i<MAX_WEAPONS;i++)
5 Plagman 1864
    {
1865
        if (sbar.ammo_amount[i] != p->ammo_amount[i])
1866
        {
1867
            sbar.ammo_amount[i] = p->ammo_amount[i];
1868
            if(i < 9)
1869
                u |= ((2<<i)+1024);
218 terminx 1870
            else u |= 65536L+1024;
5 Plagman 1871
        }
218 terminx 1872
 
5 Plagman 1873
        if (sbar.gotweapon[i] != p->gotweapon[i])
1874
        {
1875
            sbar.gotweapon[i] = p->gotweapon[i];
1876
            if(i < 9 )
1877
                u |= ((2<<i)+1024);
218 terminx 1878
            else u |= 65536L+1024;
5 Plagman 1879
        }
1880
    }
218 terminx 1881
 
5 Plagman 1882
if (sbar.inven_icon != p->inven_icon) { sbar.inven_icon = p->inven_icon; u |= (2048+4096+8192); }
1883
    if (sbar.holoduke_on != p->holoduke_on) { sbar.holoduke_on = p->holoduke_on; u |= (4096+8192); }
1884
    if (sbar.jetpack_on != p->jetpack_on) { sbar.jetpack_on = p->jetpack_on; u |= (4096+8192); }
1885
    if (sbar.heat_on != p->heat_on) { sbar.heat_on = p->heat_on; u |= (4096+8192); }
1886
    if (sbar.firstaid_amount != p->firstaid_amount) { sbar.firstaid_amount = p->firstaid_amount; u |= 8192; }
1887
    if (sbar.steroids_amount != p->steroids_amount) { sbar.steroids_amount = p->steroids_amount; u |= 8192; }
1888
    if (sbar.holoduke_amount != p->holoduke_amount) { sbar.holoduke_amount = p->holoduke_amount; u |= 8192; }
1889
    if (sbar.jetpack_amount != p->jetpack_amount) { sbar.jetpack_amount = p->jetpack_amount; u |= 8192; }
1890
    if (sbar.heat_amount != p->heat_amount) { sbar.heat_amount = p->heat_amount; u |= 8192; }
1891
    if (sbar.scuba_amount != p->scuba_amount) { sbar.scuba_amount = p->scuba_amount; u |= 8192; }
1892
    if (sbar.boot_amount != p->boot_amount) { sbar.boot_amount = p->boot_amount; u |= 8192; }
1893
    if (u == 0) return;
1894
 
1895
    //0 - update health
1896
    //1 - update armor
1897
    //2 - update PISTOL_WEAPON ammo
1898
    //3 - update SHOTGUN_WEAPON ammo
1899
    //4 - update CHAINGUN_WEAPON ammo
1900
    //5 - update RPG_WEAPON ammo
1901
    //6 - update HANDBOMB_WEAPON ammo
1902
    //7 - update SHRINKER_WEAPON ammo
1903
    //8 - update DEVISTATOR_WEAPON ammo
1904
    //9 - update TRIPBOMB_WEAPON ammo
1905
    //10 - update ammo display
1906
    //11 - update inventory icon
1907
    //12 - update inventory on/off
1908
    //13 - update inventory %
1909
    //14 - update keys
1910
    //15 - update kills
1911
    //16 - update FREEZE_WEAPON ammo
1912
    if (u == -1)
1913
    {
1914
        patchstatusbar(0,0,320,200);
1915
        if (ud.multimode > 1 && (gametype_flags[ud.coop] & GAMETYPE_FLAG_FRAGBAR))
1916
            rotatesprite(sbarx(277+1),sbary(200-27-1),sbarsc(65536L),0,KILLSICON,0,0,10+16,0,0,xdim-1,ydim-1);
1917
    }
1918
    if (ud.multimode > 1 && (gametype_flags[ud.coop] & GAMETYPE_FLAG_FRAGBAR))
1919
    {
1920
        if (u&32768)
1921
        {
1922
            if (u != -1) patchstatusbar(276,183,299,193);
1923
            digitalnumber(287,200-17,max(p->frag-p->fraggedself,0),-16,10+16);
1924
        }
1925
    }
1926
    else
1927
    {
1928
        if (u&16384)
1929
        {
1930
            if (u != -1) patchstatusbar(275,182,299,194);
1931
            if (p->got_access&4) rotatesprite(sbarx(275),sbary(182),sbarsc(65536L),0,ACCESS_ICON,0,23,10+16,0,0,xdim-1,ydim-1);
1932
            if (p->got_access&2) rotatesprite(sbarx(288),sbary(182),sbarsc(65536L),0,ACCESS_ICON,0,21,10+16,0,0,xdim-1,ydim-1);
1933
            if (p->got_access&1) rotatesprite(sbarx(281),sbary(189),sbarsc(65536L),0,ACCESS_ICON,0,0,10+16,0,0,xdim-1,ydim-1);
1934
        }
1935
    }
1936
    if (u&(4+8+16+32+64+128+256+512+65536L)) weapon_amounts(p,96,182,u);
1937
 
1938
    if (u&1)
1939
    {
1940
        if (u != -1) patchstatusbar(20,183,43,194); //Original code:(20,183,43,193);
1941
        if (sprite[p->i].pal == 1 && p->last_extra < 2)
1942
            digitalnumber(32,200-17,1,-16,10+16);
1943
        else digitalnumber(32,200-17,p->last_extra,-16,10+16);
1944
    }
1945
    if (u&2)
1946
    {
1947
        long lAmount=GetGameVar("PLR_MORALE",-1, p->i, snum);
1948
        if (u != -1) patchstatusbar(52,183,75,193);
1949
        if(lAmount == -1)
1950
        {
1951
            digitalnumber(64,200-17,p->shield_amount,-16,10+16);
1952
        }
1953
        else
1954
        {
1955
            digitalnumber(64,200-17,lAmount,-16,10+16);
1956
        }
1957
    }
1958
 
1959
    if (u&1024)
1960
    {
1961
        if (u != -1) patchstatusbar(196,183,219,194); //Original code:(196,183,219,193);
1962
        if (p->curr_weapon != KNEE_WEAPON)
1963
        {
1964
            if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON; else i = p->curr_weapon;
1965
            digitalnumber(230-22,200-17,p->ammo_amount[i],-16,10+16);
1966
        }
1967
    }
1968
 
1969
    if (u&(2048+4096+8192))
1970
    {
1971
        if (u != -1)
1972
        {
1973
            if (u&(2048+4096)) { patchstatusbar(231,179,265,197); }
1974
            else { patchstatusbar(250,190,261,196); } //Original code:(250,190,261,195);
1975
        }
1976
        if (p->inven_icon)
1977
        {
1978
            o = 0; permbit = 0;
1979
 
1980
            if (u&(2048+4096))
1981
            {
1982
                switch(p->inven_icon)
1983
                {
1984
                case 1: i = FIRSTAID_ICON; break;
1985
                case 2: i = STEROIDS_ICON; break;
1986
                case 3: i = HOLODUKE_ICON; break;
1987
                case 4: i = JETPACK_ICON; break;
1988
                case 5: i = HEAT_ICON; break;
1989
                case 6: i = AIRTANK_ICON; break;
1990
                case 7: i = BOOT_ICON; break;
1991
                }
1992
 
1993
                rotatesprite(sbarx(231-o),sbary(200-21),sbarsc(65536L),0,i,0,0,10+16+permbit,0,0,xdim-1,ydim-1);
1994
                minitext(292-30-o,190,"%",6,10+16+permbit + 256);
1995
                if (p->inven_icon >= 6) minitext(284-35-o,180,"AUTO",2,10+16+permbit + 256);
1996
            }
1997
            if (u&(2048+4096))
1998
            {
1999
                switch(p->inven_icon)
2000
                {
2001
                case 3: j = p->holoduke_on; break;
2002
                case 4: j = p->jetpack_on; break;
2003
                case 5: j = p->heat_on; break;
2004
                default: j = 0x80000000;
2005
                }
2006
                if (j > 0) minitext(288-30-o,180,"ON",0,10+16+permbit + 256);
2007
                else if ((unsigned long)j != 0x80000000) minitext(284-30-o,180,"OFF",2,10+16+permbit + 256);
2008
            }
2009
            if (u&8192)
2010
            {
2011
                switch(p->inven_icon)
2012
                {
2013
                case 1: i = p->firstaid_amount; break;
2014
                case 2: i = ((p->steroids_amount+3)>>2); break;
2015
                case 3: i = ((p->holoduke_amount+15)/24); break;
2016
                case 4: i = ((p->jetpack_amount+15)>>4); break;
2017
                case 5: i = p->heat_amount/12; break;
2018
                case 6: i = ((p->scuba_amount+63)>>6); break;
2019
                case 7: i = (p->boot_amount>>1); break;
2020
                }
2021
                invennum(284-30-o,200-6,(char)i,0,10+permbit);
2022
            }
2023
        }
2024
    }
2025
}
2026
 
2027
#define AVERAGEFRAMES 16
2028
static long frameval[AVERAGEFRAMES], framecnt = 0;
2029
 
2030
void tics(void)
2031
{
2032
    long i,j;
2033
    char b[10];
2034
 
2035
    i = totalclock;
2036
    if (i != frameval[framecnt])
2037
    {
29 terminx 2038
        j=(TICRATE*AVERAGEFRAMES)/(i-frameval[framecnt]);
193 terminx 2039
        if (ud.tickrate && !(ps[myconnectindex].gm&MODE_MENU))
2040
        {
2041
            Bsprintf(b,"%ld",j>0?j:0);
2042
            minitext(320-strlen(b)*4,ud.screen_size!=0?(ud.multimode>1&&ud.multimode<5?9:(ud.multimode>4?17:1)):1,b,(TICRATE*AVERAGEFRAMES)/(i-frameval[framecnt]) < 40?2:0,26);
2043
        }
2044
        framerate = j;
5 Plagman 2045
        frameval[framecnt] = i;
2046
    }
2047
    framecnt = ((framecnt+1)&(AVERAGEFRAMES-1));
2048
}
2049
 
2050
void coords(short snum)
2051
{
2052
    short y = 8;
2053
 
2054
    if((gametype_flags[ud.coop] & GAMETYPE_FLAG_FRAGBAR))
2055
    {
2056
        if(ud.multimode > 1 && ud.multimode < 5)
2057
            y = 16;
2058
        else if(ud.multimode > 4)
2059
            y = 24;
2060
    }
2061
    sprintf(tempbuf,"X= %ld",ps[snum].posx);
2062
    printext256(250L,y,31,-1,tempbuf,0);
2063
    sprintf(tempbuf,"Y= %ld",ps[snum].posy);
2064
    printext256(250L,y+9L,31,-1,tempbuf,0);
2065
    Bsprintf(tempbuf,"Z= %ld",ps[snum].posz);
2066
    printext256(250L,y+18L,31,-1,tempbuf,0);
2067
    Bsprintf(tempbuf,"A= %d",ps[snum].ang);
2068
    printext256(250L,y+27L,31,-1,tempbuf,0);
2069
    Bsprintf(tempbuf,"ZV= %ld",ps[snum].poszv);
2070
    printext256(250L,y+36L,31,-1,tempbuf,0);
2071
    Bsprintf(tempbuf,"OG= %d",ps[snum].on_ground);
2072
    printext256(250L,y+45L,31,-1,tempbuf,0);
2073
    Bsprintf(tempbuf,"AM= %d",ps[snum].ammo_amount[GROW_WEAPON]);
2074
    printext256(250L,y+54L,31,-1,tempbuf,0);
2075
    Bsprintf(tempbuf,"LFW= %d",ps[snum].last_full_weapon);
2076
    printext256(250L,y+63L,31,-1,tempbuf,0);
2077
    Bsprintf(tempbuf,"SECTL= %d",sector[ps[snum].cursectnum].lotag);
2078
    printext256(250L,y+72L,31,-1,tempbuf,0);
2079
    Bsprintf(tempbuf,"SEED= %ld",randomseed);
2080
    printext256(250L,y+81L,31,-1,tempbuf,0);
2081
    Bsprintf(tempbuf,"THOLD= %d",ps[snum].transporter_hold);
2082
    printext256(250L,y+90L+7,31,-1,tempbuf,0);
2083
}
2084
 
2085
void operatefta(void)
2086
{
85 terminx 2087
    long i, j, k, l;
5 Plagman 2088
 
2089
    if(ud.screen_size > 0) j = 200-45