Subversion Repositories eduke32

Rev

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