Subversion Repositories eduke32

Rev

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

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