Subversion Repositories eduke32

Rev

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

Rev Author Line No. Line
5 Plagman 1
//-------------------------------------------------------------------------
2
/*
1652 terminx 3
Copyright (C) 2010 EDuke32 developers and contributors
5 Plagman 4
 
1652 terminx 5
This file is part of EDuke32.
5 Plagman 6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
*/
21
//-------------------------------------------------------------------------
22
 
110 terminx 23
#include "duke3d.h"
1346 terminx 24
 
5 Plagman 25
#include "scriplib.h"
26
#include "file_lib.h"
27
#include "mathutil.h"
28
#include "gamedefs.h"
29
#include "keyboard.h"
30
#include "mouse.h"  // JBF 20030809
31
#include "function.h"
32
#include "control.h"
33
#include "fx_man.h"
34
#include "sounds.h"
35
#include "config.h"
36
#include "osd.h"
37
#include "osdfuncs.h"
38
#include "osdcmds.h"
130 terminx 39
#include "scriptfile.h"
241 terminx 40
#include "grpscan.h"
610 terminx 41
#include "gamedef.h"
640 terminx 42
#include "kplib.h"
1552 terminx 43
#include "crc32.h"
1173 terminx 44
#include "hightile.h"
1632 terminx 45
#include "control.h"
1552 terminx 46
#include "quicklz.h"
1677 terminx 47
#include "net.h"
48
#include "premap.h"
49
#include "gameexec.h"
50
#include "menus.h"
51
#include "savegame.h"
52
#include "anim.h"
53
#include "demo.h"
2542 helixhorne 54
#include "common.h"
1552 terminx 55
 
2034 helixhorne 56
#ifdef LUNATIC_ENABLE
57
# include "lunatic.h"
58
#endif
59
 
1658 terminx 60
#define ROTATESPRITE_MAX 2048
61
 
1595 helixhorne 62
#if KRANDDEBUG
63
# define GAME_INLINE
64
# define GAME_STATIC
65
#else
66
# define GAME_INLINE inline
67
# define GAME_STATIC static
68
#endif
69
 
418 terminx 70
#ifdef _WIN32
1672 terminx 71
#include "winlayer.h"
514 terminx 72
#define WIN32_LEAN_AND_MEAN
73
#include <windows.h>
418 terminx 74
#include <shellapi.h>
1205 terminx 75
extern int32_t G_GetVersionFromWebsite(char *buffer);
546 terminx 76
#define UPDATEINTERVAL 604800 // 1w
933 terminx 77
#else
1205 terminx 78
static int32_t usecwd = 0;
1802 terminx 79
#include <sys/ioctl.h>
1008 hnt_ts 80
#endif /* _WIN32 */
1587 terminx 81
 
82
int32_t g_quitDeadline = 0;
418 terminx 83
 
1205 terminx 84
int32_t g_cameraDistance = 0, g_cameraClock = 0;
1587 terminx 85
static int32_t g_quickExit;
1205 terminx 86
static int32_t g_commandSetup = 0;
87
int32_t g_noSetup = 0;
88
static int32_t g_noAutoLoad = 0;
89
static int32_t g_noSound = 0;
90
static int32_t g_noMusic = 0;
5 Plagman 91
static char *CommandMap = NULL;
561 terminx 92
static char *CommandName = NULL;
1587 terminx 93
int32_t g_forceWeaponChoice = 0;
1632 terminx 94
 
1068 terminx 95
char boardfilename[BMAX_PATH] = {0}, currentboardfilename[BMAX_PATH] = {0};
1587 terminx 96
 
97
static char g_rootDir[BMAX_PATH];
98
char g_modDir[BMAX_PATH] = "/";
99
 
1772 plagman 100
 
2516 helixhorne 101
uint8_t water_pal[768],slime_pal[768],title_pal[768],dre_alms[768],ending_pal[768];
1772 plagman 102
 
2516 helixhorne 103
uint8_t *basepaltable[BASEPALCOUNT] = { palette, water_pal, slime_pal, dre_alms, title_pal, ending_pal, NULL /*anim_pal*/ };
1772 plagman 104
 
2518 helixhorne 105
int8_t g_noFloorPal[MAXPALOOKUPS];  // 1 if sprite pal should not be taken over from floor pal
2517 helixhorne 106
 
1587 terminx 107
static int32_t g_skipDefaultCons = 0;
1909 terminx 108
static int32_t g_skipDefaultDefs = 0; // primarily for NAM/WWII GI appeasement
5 Plagman 109
 
1205 terminx 110
int32_t voting = -1;
111
int32_t vote_map = -1, vote_episode = -1;
147 terminx 112
 
1587 terminx 113
static int32_t g_Debug = 0;
1205 terminx 114
static int32_t g_noLogoAnim = 0;
115
static int32_t g_noLogo = 0;
249 terminx 116
 
117
char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp";
1909 terminx 118
char defsfilename[BMAX_PATH] = "duke3d.def";
119
static char defaultconfilename[2][BMAX_PATH] = { "EDUKE.CON", "GAME.CON" };
2420 hendricks2 120
char defaultrtsfilename[128] = "DUKE.RTS";
1205 terminx 121
 
1587 terminx 122
char *g_grpNamePtr = defaultduke3dgrp;
1909 terminx 123
char *g_defNamePtr = defsfilename;
124
char *g_scriptNamePtr = defaultconfilename[0];
1587 terminx 125
char *g_gameNamePtr = NULL;
1915 terminx 126
char *g_rtsNamePtr = NULL;
1205 terminx 127
 
1937 hendricks2 128
char **g_scriptModules = NULL;
2495 hendricks2 129
int32_t g_scriptModulesNum = 0;
1937 hendricks2 130
char **g_defModules = NULL;
2495 hendricks2 131
int32_t g_defModulesNum = 0;
1937 hendricks2 132
 
2495 hendricks2 133
#ifdef HAVE_CLIPSHAPE_FEATURE
134
char **g_clipMapFiles = NULL;
135
int32_t g_clipMapFilesNum = 0;
136
#endif
137
 
2034 helixhorne 138
#ifdef LUNATIC_ENABLE
139
El_State g_ElState;
140
#endif
141
 
1205 terminx 142
extern int32_t lastvisinc;
249 terminx 143
 
1205 terminx 144
int32_t g_Shareware = 0;
145
int32_t g_gameType = 0;
146
 
1037 terminx 147
#define MAXUSERQUOTES 6
1677 terminx 148
int32_t quotebot, quotebotgoal;
1205 terminx 149
static int32_t user_quote_time[MAXUSERQUOTES];
444 terminx 150
static char user_quote[MAXUSERQUOTES][178];
249 terminx 151
// char typebuflen,typebuf[41];
152
 
1658 terminx 153
// This was 32 for a while, but I think lowering it to 24 will help things like the Dingoo.
154
// Ideally, we would look at our memory usage on our most cramped platform and figure out
155
// how much of that is needed for the underlying OS and things like SDL instead of guessing
156
static int32_t MAXCACHE1DSIZE = (24*1048576);
253 terminx 157
 
1205 terminx 158
int32_t tempwallptr;
249 terminx 159
 
1205 terminx 160
static int32_t nonsharedtimer;
249 terminx 161
 
1552 terminx 162
int32_t ticrandomseed;
163
 
1205 terminx 164
static void G_DrawCameraText(int16_t i);
1595 helixhorne 165
GAME_STATIC GAME_INLINE int32_t G_MoveLoop(void);
1143 terminx 166
static void G_DoOrderScreen(void);
395 terminx 167
 
1552 terminx 168
#define quotepulseshade (sintable[(totalclock<<5)&2047]>>11)
169
 
1205 terminx 170
int32_t althud_numbertile = 2930;
171
int32_t althud_numberpal = 0;
172
int32_t althud_shadows = 1;
173
int32_t althud_flashing = 1;
174
int32_t hud_glowingquotes = 1;
175
int32_t hud_showmapname = 1;
937 terminx 176
 
1205 terminx 177
int32_t g_levelTextTime = 0;
1068 terminx 178
 
1205 terminx 179
int32_t r_maxfps = 0;
180
uint32_t g_frameDelay = 0;
1086 terminx 181
 
1176 terminx 182
#if defined(RENDERTYPEWIN) && defined(USE_OPENGL)
1120 terminx 183
extern char forcegl;
184
#endif
185
 
1652 terminx 186
void M32RunScript(const char *s) { UNREFERENCED_PARAMETER(s); };  // needed for linking since it's referenced from build/src/osd.c
1649 helixhorne 187
 
1712 helixhorne 188
int32_t kopen4loadfrommod(const char *filename, char searchfirst)
992 terminx 189
{
190
    static char fn[BMAX_PATH];
1205 terminx 191
    int32_t r;
992 terminx 192
 
1587 terminx 193
    Bsprintf(fn,"%s/%s",g_modDir,filename);
992 terminx 194
    r = kopen4load(fn,searchfirst);
993 terminx 195
    if (r < 0)
992 terminx 196
        r = kopen4load(filename,searchfirst);
1719 helixhorne 197
 
992 terminx 198
    return r;
199
}
200
 
1918 terminx 201
char *defaultconfile(void)
1909 terminx 202
{
203
    int32_t i;
204
 
205
    i = kopen4load(defaultconfilename[0],0);
206
 
207
    if (i >= 0)
208
        return defaultconfilename[0];
209
 
210
    return defaultconfilename[1];
211
}
212
 
1677 terminx 213
enum gametokens
335 terminx 214
{
249 terminx 215
    T_EOF = -2,
216
    T_ERROR = -1,
505 terminx 217
    T_INCLUDE = 0,
249 terminx 218
    T_INTERFACE = 0,
505 terminx 219
    T_LOADGRP = 1,
249 terminx 220
    T_MODE = 1,
505 terminx 221
    T_CACHESIZE = 2,
626 terminx 222
    T_ALLOW = 2,
223
    T_NOAUTOLOAD,
1909 terminx 224
    T_INCLUDEDEFAULT,
634 terminx 225
    T_MUSIC,
226
    T_SOUND,
227
    T_FILE,
2242 helixhorne 228
    T_ANIMSOUNDS,
2517 helixhorne 229
    T_NOFLOORPALRANGE,
634 terminx 230
    T_ID
249 terminx 231
};
232
 
1677 terminx 233
static int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
249 terminx 234
{
235
    char *tok;
1205 terminx 236
    int32_t i;
249 terminx 237
 
238
    if (!sf) return T_ERROR;
239
    tok = scriptfile_gettoken(sf);
240
    if (!tok) return T_EOF;
241
 
1229 terminx 242
    for (i=ntokens-1; i>=0; i--)
335 terminx 243
    {
249 terminx 244
        if (!Bstrcasecmp(tok, tl[i].text))
245
            return tl[i].tokenid;
246
    }
247
    return T_ERROR;
248
}
249
 
1205 terminx 250
inline void G_SetStatusBarScale(int32_t sc)
5 Plagman 251
{
252
    ud.statusbarscale = min(100,max(10,sc));
1143 terminx 253
    G_UpdateScreenArea();
5 Plagman 254
}
255
 
1205 terminx 256
static inline int32_t sbarx(int32_t x)
5 Plagman 257
{
502 terminx 258
    if (ud.screen_size == 4 /*|| ud.statusbarmode == 1*/) return scale(x<<16,ud.statusbarscale,100);
5 Plagman 259
    return (((320l<<16) - scale(320l<<16,ud.statusbarscale,100)) >> 1) + scale(x<<16,ud.statusbarscale,100);
260
}
261
 
1205 terminx 262
static inline int32_t sbarxr(int32_t x)
934 terminx 263
{
264
    if (ud.screen_size == 4 /*|| ud.statusbarmode == 1*/) return (320l<<16) - scale(x<<16,ud.statusbarscale,100);
265
    return (((320l<<16) - scale(320l<<16,ud.statusbarscale,100)) >> 1) + scale(x<<16,ud.statusbarscale,100);
266
}
267
 
1205 terminx 268
static inline int32_t sbary(int32_t y)
5 Plagman 269
{
270
    return ((200l<<16) - scale(200l<<16,ud.statusbarscale,100) + scale(y<<16,ud.statusbarscale,100));
271
}
272
 
1205 terminx 273
static inline int32_t sbarsc(int32_t sc)
5 Plagman 274
{
275
    return scale(sc,ud.statusbarscale,100);
276
}
277
 
1205 terminx 278
static inline int32_t textsc(int32_t sc)
1095 terminx 279
{
1097 terminx 280
    // prevent ridiculousness to a degree
1099 terminx 281
    if (xdim <= 320) return sc;
282
    else if (xdim <= 640) return scale(sc,min(200,ud.textscale),100);
283
    else if (xdim <= 800) return scale(sc,min(300,ud.textscale),100);
284
    else if (xdim <= 1024) return scale(sc,min(350,ud.textscale),100);
1095 terminx 285
    return scale(sc,ud.textscale,100);
286
}
287
 
1205 terminx 288
static void G_PatchStatusBar(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
5 Plagman 289
{
1205 terminx 290
    int32_t scl, tx, ty;
291
    int32_t clx1,cly1,clx2,cly2,clofx,clofy;
5 Plagman 292
 
293
    scl = sbarsc(65536);
335 terminx 294
    tx = sbarx(0);
295
    ty = sbary(200-tilesizy[BOTTOMSTATUSBAR]);
5 Plagman 296
 
297
    clx1 = scale(scale(x1,xdim,320),ud.statusbarscale,100);
298
    cly1 = scale(scale(y1,ydim,200),ud.statusbarscale,100);
299
    clx2 = scale(scale(x2,xdim,320),ud.statusbarscale,100);
300
    cly2 = scale(scale(y2,ydim,200),ud.statusbarscale,100);
301
    clofx = (xdim - scale(xdim,ud.statusbarscale,100)) >> 1;
302
    clofy = (ydim - scale(ydim,ud.statusbarscale,100));
303
 
502 terminx 304
//    if (ud.statusbarmode == 0)
508 terminx 305
    rotatesprite(tx,ty,scl,0,BOTTOMSTATUSBAR,4,0,10+16+64,clx1+clofx,cly1+clofy,clx2+clofx-1,cly2+clofy-1);
502 terminx 306
//    else rotatesprite(tx,ty,scl,0,BOTTOMSTATUSBAR,4,0,10+16+64,clx1,cly1,clx2+clofx-1,cly2+clofy-1);
5 Plagman 307
}
308
 
1772 plagman 309
void P_SetGamePalette(DukePlayer_t *player, uint8_t palid, int32_t set)
5 Plagman 310
{
1772 plagman 311
    if (palid >= BASEPALCOUNT)
312
        palid = BASEPAL;
1604 terminx 313
 
564 terminx 314
    if (player != g_player[screenpeek].ps)
335 terminx 315
    {
1772 plagman 316
        player->palette = palid;
5 Plagman 317
        return;
318
    }
1918 terminx 319
 
1772 plagman 320
    player->palette = palid;
5 Plagman 321
 
1781 plagman 322
    setbrightness(ud.brightness>>2, palid, set);
5 Plagman 323
}
324
 
1604 terminx 325
int32_t G_PrintGameText(int32_t f,  int32_t tile, int32_t x,  int32_t y,  const char *t,
326
                        int32_t s,  int32_t p,    int32_t o,
327
                        int32_t x1, int32_t y1,   int32_t x2, int32_t y2, int32_t z)
587 terminx 328
{
1604 terminx 329
    int32_t ac;
1205 terminx 330
    char centre;
2380 helixhorne 331
    const int32_t squishtext = ((f&2) != 0);
1604 terminx 332
    int32_t shift = 16, widthx = 320;
333
    int32_t ox, oy, origx = x, origy = y;
5 Plagman 334
 
1604 terminx 335
    if (t == NULL)
336
        return -1;
337
 
1658 terminx 338
    if (o & ROTATESPRITE_MAX)
966 hnt_ts 339
    {
340
        widthx = 320<<16;
341
        shift = 0;
342
    }
5 Plagman 343
 
2380 helixhorne 344
    centre = (x == (widthx>>1));
345
    if (centre)
1604 terminx 346
    {
347
        const char *oldt = t;
348
        int32_t newx = 0;
102 terminx 349
 
1019 terminx 350
        do
5 Plagman 351
        {
1604 terminx 352
            int32_t i;
353
 
354
            if (*t == 32)
151 terminx 355
            {
1604 terminx 356
                newx += ((((f & 8) ? 8 : 5) - squishtext) * z)>>16;
266 terminx 357
                continue;
151 terminx 358
            }
1604 terminx 359
 
360
            if (*t == '^' && isdigit(*(t+1)))
335 terminx 361
            {
2380 helixhorne 362
                t++;
363
                if (isdigit(*(t+1)))
364
                    t++;
365
//                t += 1 + isdigit(*(t+2));   // This code is wrong, see C99 6.5.16 #3
335 terminx 366
                continue;
367
            }
5 Plagman 368
 
1604 terminx 369
            ac = *t - '!' + tile;
5 Plagman 370
 
1604 terminx 371
            if (ac < tile || ac > (tile + 93)) break;
372
 
2380 helixhorne 373
            i = ((((f & 8) ? 8 : tilesizx[ac]) - squishtext) * z)>>16;
374
            newx += i;
1604 terminx 375
 
331 terminx 376
            if (*t >= '0' && *t <= '9')
1604 terminx 377
                newx -= i - ((8 * z)>>16);
5 Plagman 378
        }
1019 terminx 379
        while (*(++t));
5 Plagman 380
 
381
        t = oldt;
1604 terminx 382
 
383
        x = (f & 4) ?
384
            (xres>>1)-textsc(newx>>1) :
1677 terminx 385
            (widthx>>1)-((o & ROTATESPRITE_MAX)?newx<<15:newx>>1);
5 Plagman 386
    }
1604 terminx 387
 
388
    ox = x;
389
    oy = y;
390
 
1019 terminx 391
    do
5 Plagman 392
    {
1604 terminx 393
        int32_t i;
394
 
395
        if (*t == 32)
396
        {
397
            x += ((((f & 8) ? 8 : 5) - squishtext) * z)>>16;
398
            continue;
399
        }
400
 
331 terminx 401
        if (*t == '^' && isdigit(*(t+1)))
151 terminx 402
        {
765 terminx 403
            char smallbuf[4];
1604 terminx 404
 
1019 terminx 405
            if (!isdigit(*(++t+1)))
151 terminx 406
            {
1019 terminx 407
                smallbuf[0] = *(t);
151 terminx 408
                smallbuf[1] = '\0';
2374 helixhorne 409
                p = Batoi(smallbuf);
1019 terminx 410
                continue;
151 terminx 411
            }
1604 terminx 412
 
1019 terminx 413
            smallbuf[0] = *(t++);
414
            smallbuf[1] = *(t);
415
            smallbuf[2] = '\0';
2374 helixhorne 416
            p = Batoi(smallbuf);
266 terminx 417
            continue;
151 terminx 418
        }
5 Plagman 419
 
1604 terminx 420
        ac = *t - '!' + tile;
421
 
422
        if (ac < tile || ac > (tile + 93))
5 Plagman 423
            break;
424
 
1658 terminx 425
        if (o&ROTATESPRITE_MAX)
966 hnt_ts 426
        {
1604 terminx 427
            ox = x += (x-ox)<<16;
428
            oy = y += (y-oy)<<16;
966 hnt_ts 429
        }
840 terminx 430
 
1604 terminx 431
        if (f&4)
432
            rotatesprite(textsc(x<<shift),(origy<<shift)+textsc((y-origy)<<shift),textsc(z),
1677 terminx 433
                         0,ac,s,p,(8|16|(o&1)|(o&32)),x1,y1,x2,y2);
1604 terminx 434
        else if (f&1)
435
            rotatesprite(x<<shift,(y<<shift),z,0,ac,s,p,(8|16|(o&1)|(o&32)),x1,y1,x2,y2);
436
        else rotatesprite(x<<shift,(y<<shift),z,0,ac,s,p,(2|o),x1,y1,x2,y2);
1095 terminx 437
 
1604 terminx 438
        x += i = (f & 8) ?
1677 terminx 439
                 ((8 - squishtext) * z)>>16 :
440
                 ((tilesizx[ac] - squishtext) * z)>>16;
1604 terminx 441
 
853 terminx 442
        if ((*t >= '0' && *t <= '9'))
1604 terminx 443
            x -= i - ((8 * z)>>16);
924 terminx 444
 
1658 terminx 445
        if ((o&ROTATESPRITE_MAX) == 0) //  wrapping long strings doesn't work for precise coordinates due to overflow
1095 terminx 446
        {
1604 terminx 447
            if (((f&4) ? textsc(x) : x) > (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET))
448
                x = origx, y += (8 * z)>>16;
1095 terminx 449
        }
5 Plagman 450
    }
1019 terminx 451
    while (*(++t));
1604 terminx 452
 
453
    return x;
5 Plagman 454
}
455
 
1205 terminx 456
int32_t G_GameTextLen(int32_t x,const char *t)
877 terminx 457
{
1205 terminx 458
    int32_t ac;
867 terminx 459
 
877 terminx 460
    if (t == NULL)
461
        return -1;
462
 
1019 terminx 463
    do
877 terminx 464
    {
465
        if (*t == 32)
466
        {
467
            x+=5;
468
            continue;
469
        }
470
 
1625 terminx 471
        ac = *t - '!' + STARTALPHANUM;
472
 
877 terminx 473
        if (ac < STARTALPHANUM || ac > (STARTALPHANUM + 93))
474
            break;
475
 
1625 terminx 476
        x += (*t >= '0' && *t <= '9') ? 8 : tilesizx[ac];
877 terminx 477
    }
1019 terminx 478
    while (*(++t));
1625 terminx 479
 
1095 terminx 480
    return (textsc(x));
877 terminx 481
}
482
 
1677 terminx 483
inline int32_t mpgametext(int32_t y,const char *t,int32_t s,int32_t dabits)
78 terminx 484
{
1604 terminx 485
    return(G_PrintGameText(4,STARTALPHANUM, 5,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536));
78 terminx 486
}
487
 
1205 terminx 488
int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t sb)
5 Plagman 489
{
1205 terminx 490
    int32_t ac;
491
    char ch, cmode;
5 Plagman 492
 
1658 terminx 493
    cmode = (sb&ROTATESPRITE_MAX)!=0;
494
    sb &= ROTATESPRITE_MAX-1;
5 Plagman 495
 
1918 terminx 496
    if (t == NULL)
497
    {
498
        OSD_Printf("minitext: NULL text!\n");
499
        return 0;
500
    }
1884 terminx 501
 
1019 terminx 502
    do
5 Plagman 503
    {
921 terminx 504
        if (*t == '^' && isdigit(*(t+1)))
505
        {
506
            char smallbuf[4];
1019 terminx 507
            if (!isdigit(*(++t+1)))
921 terminx 508
            {
1019 terminx 509
                smallbuf[0] = *(t);
921 terminx 510
                smallbuf[1] = '\0';
2374 helixhorne 511
                p = Batoi(smallbuf);
1019 terminx 512
                continue;
921 terminx 513
            }
1019 terminx 514
            smallbuf[0] = *(t++);
515
            smallbuf[1] = *(t);
516
            smallbuf[2] = '\0';
2374 helixhorne 517
            p = Batoi(smallbuf);
921 terminx 518
            continue;
519
        }
5 Plagman 520
        ch = Btoupper(*t);
335 terminx 521
        if (ch == 32)
522
        {
523
            x+=5;
524
            continue;
525
        }
5 Plagman 526
        else ac = ch - '!' + MINIFONT;
527
 
2308 helixhorne 528
        if (cmode) rotatesprite_fs(sbarx(x),sbary(y),sbarsc(65536L),0,ac,s,p,sb);
529
        else rotatesprite_fs(x<<16,y<<16,65536L,0,ac,s,p,sb);
5 Plagman 530
        x += 4; // tilesizx[ac]+1;
531
 
532
    }
1019 terminx 533
    while (*(++t));
1625 terminx 534
 
5 Plagman 535
    return (x);
536
}
537
 
1143 terminx 538
void G_AddUserQuote(const char *daquote)
5 Plagman 539
{
1205 terminx 540
    int32_t i;
5 Plagman 541
 
1229 terminx 542
    for (i=MAXUSERQUOTES-1; i>0; i--)
5 Plagman 543
    {
232 terminx 544
        Bstrcpy(user_quote[i],user_quote[i-1]);
5 Plagman 545
        user_quote_time[i] = user_quote_time[i-1];
546
    }
232 terminx 547
    Bstrcpy(user_quote[0],daquote);
864 terminx 548
    OSD_Printf("%s\n",daquote);
87 terminx 549
 
88 terminx 550
    user_quote_time[0] = ud.msgdisptime;
5 Plagman 551
    pub = NUMPAGES;
552
}
553
 
1143 terminx 554
void G_HandleSpecialKeys(void)
5 Plagman 555
{
1552 terminx 556
    // we need CONTROL_GetInput in order to pick up joystick button presses
557
    if (CONTROL_Started && !(g_player[myconnectindex].ps->gm & MODE_GAME))
558
    {
559
        ControlInfo noshareinfo;
560
        CONTROL_GetInput(&noshareinfo);
561
    }
562
 
1632 terminx 563
//    CONTROL_ProcessBinds();
808 terminx 564
 
1802 terminx 565
    if (g_networkMode != NET_DEDICATED_SERVER && ALT_IS_PRESSED && KB_KeyPressed(sc_Enter))
114 terminx 566
    {
563 terminx 567
        if (setgamemode(!ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP))
335 terminx 568
        {
909 terminx 569
            OSD_Printf(OSD_ERROR "Failed setting fullscreen video mode.\n");
563 terminx 570
            if (setgamemode(ud.config.ScreenMode, ud.config.ScreenWidth, ud.config.ScreenHeight, ud.config.ScreenBPP))
1143 terminx 571
                G_GameExit("Failed to recover from failure to set fullscreen video mode.\n");
114 terminx 572
        }
563 terminx 573
        else ud.config.ScreenMode = !ud.config.ScreenMode;
114 terminx 574
        KB_ClearKeyDown(sc_Enter);
1143 terminx 575
        g_restorePalette = 1;
576
        G_UpdateScreenArea();
114 terminx 577
    }
578
 
824 terminx 579
    if (KB_UnBoundKeyPressed(sc_F12))
472 terminx 580
    {
1852 helixhorne 581
        char titlebuf[256];
582
        Bsprintf(titlebuf,HEAD2 " %s",s_buildRev);
583
 
472 terminx 584
        KB_ClearKeyDown(sc_F12);
1852 helixhorne 585
        screencapture("duke0000.tga",0,titlebuf);
1802 terminx 586
        P_DoQuote(QUOTE_SCREEN_SAVED,g_player[myconnectindex].ps);
472 terminx 587
    }
588
 
5 Plagman 589
    // only dispatch commands here when not in a game
1574 terminx 590
    if (!(g_player[myconnectindex].ps->gm & MODE_GAME))
335 terminx 591
        OSD_DispatchQueued();
5 Plagman 592
 
1587 terminx 593
    if (g_quickExit == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && (KB_KeyPressed(sc_Delete)||KB_KeyPressed(sc_End)))
5 Plagman 594
    {
1587 terminx 595
        g_quickExit = 1;
1143 terminx 596
        G_GameExit("Quick Exit.");
5 Plagman 597
    }
1143 terminx 598
}
5 Plagman 599
 
1571 terminx 600
void G_GameQuit(void)
1552 terminx 601
{
1574 terminx 602
    if (numplayers < 2)
603
        G_GameExit(" ");
604
 
605
    if (g_gameQuit == 0)
1552 terminx 606
    {
1593 terminx 607
        g_gameQuit = 1;
608
        g_quitDeadline = totalclock+120;
609
        g_netDisconnect = 1;
1552 terminx 610
    }
611
 
1587 terminx 612
    if ((totalclock > g_quitDeadline) && (g_gameQuit == 1))
1552 terminx 613
        G_GameExit("Timed out.");
614
}
615
 
1205 terminx 616
extern int32_t cacnum;
5 Plagman 617
extern cactype cac[];
618
 
1143 terminx 619
static void G_ShowCacheLocks(void)
5 Plagman 620
{
1205 terminx 621
    int16_t i,k;
5 Plagman 622
 
1916 helixhorne 623
    if (offscreenrendering)
624
        return;
625
 
5 Plagman 626
    k = 0;
1229 terminx 627
    for (i=cacnum-1; i>=0; i--)
5 Plagman 628
        if ((*cac[i].lock) >= 200)
629
        {
1916 helixhorne 630
            if (k >= ydim-12)
631
                break;
632
 
584 terminx 633
            Bsprintf(tempbuf,"Locked- %d: Leng:%d, Lock:%d",i,cac[i].leng,*cac[i].lock);
335 terminx 634
            printext256(0L,k,31,-1,tempbuf,1);
635
            k += 6;
5 Plagman 636
        }
637
 
1916 helixhorne 638
    if (k < ydim-12)
639
        k += 6;
5 Plagman 640
 
1229 terminx 641
    for (i=10; i>=0; i--)
1677 terminx 642
        if (rts_lumplockbyte[i] >= 200)
5 Plagman 643
        {
1916 helixhorne 644
            if (k >= ydim-12)
645
                break;
646
 
5 Plagman 647
            Bsprintf(tempbuf,"RTS Locked %d:",i);
2441 helixhorne 648
            printext256(0,k,31,-1,tempbuf,1);
335 terminx 649
            k += 6;
5 Plagman 650
        }
1916 helixhorne 651
 
652
    if (k >= ydim-12 && k<ydim-6)
2441 helixhorne 653
        printext256(0,k,31,-1,"(MORE . . .)",1);
654
 
655
    // sounds
656
    if (xdim < 640)
657
        return;
658
 
659
    k = 18;
660
    for (i=0; i<=g_maxSoundPos; i++)
661
        if (g_sounds[i].num > 0)
662
        {
663
            int32_t j, n=g_sounds[i].num;
664
 
665
            for (j=0; j<n; j++)
666
            {
667
                if (k >= ydim-12)
668
                    break;
669
 
670
                Bsprintf(tempbuf, "snd #%d inst %d: voice %d, ow %d", i, j,
2442 helixhorne 671
                         g_sounds[i].SoundOwner[j].voice, g_sounds[i].SoundOwner[j].ow);
2441 helixhorne 672
                printext256(240,k,31,-1,tempbuf,0);
673
 
674
                k += 9;
675
            }
676
        }
5 Plagman 677
}
678
 
1205 terminx 679
int32_t A_CheckInventorySprite(spritetype *s)
5 Plagman 680
{
2297 helixhorne 681
    switch (DYNAMICTILEMAP(s->picnum))
5 Plagman 682
    {
337 terminx 683
    case FIRSTAID__STATIC:
684
    case STEROIDS__STATIC:
685
    case HEATSENSOR__STATIC:
686
    case BOOTS__STATIC:
687
    case JETPACK__STATIC:
688
    case HOLODUKE__STATIC:
689
    case AIRTANK__STATIC:
690
        return 1;
1672 terminx 691
    default:
692
        return 0;
5 Plagman 693
    }
694
}
695
 
1205 terminx 696
void G_DrawTile(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation)
5 Plagman 697
{
1205 terminx 698
    int32_t p = sector[g_player[screenpeek].ps->cursectnum].floorpal, a = 0;
5 Plagman 699
 
331 terminx 700
    if (orientation&4)
5 Plagman 701
        a = 1024;
702
 
2318 helixhorne 703
    rotatesprite_win((orientation&ROTATESPRITE_MAX)?x:(x<<16),(orientation&ROTATESPRITE_MAX)?y:(y<<16),
704
                     65536L,a,tilenum,shade,p,2|orientation);
5 Plagman 705
}
706
 
1205 terminx 707
void G_DrawTilePal(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation, int32_t p)
5 Plagman 708
{
1205 terminx 709
    int32_t a = 0;
5 Plagman 710
 
331 terminx 711
    if (orientation&4)
5 Plagman 712
        a = 1024;
713
 
2318 helixhorne 714
    rotatesprite_win((orientation&ROTATESPRITE_MAX)?x:(x<<16),(orientation&ROTATESPRITE_MAX)?y:(y<<16),
715
                     65536L,a,tilenum,shade,p,2|orientation);
5 Plagman 716
}
717
 
1205 terminx 718
void G_DrawTileSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation)
5 Plagman 719
{
1205 terminx 720
    int32_t p = sector[g_player[screenpeek].ps->cursectnum].floorpal, a = 0;
5 Plagman 721
 
331 terminx 722
    if (orientation&4)
5 Plagman 723
        a = 1024;
724
 
2318 helixhorne 725
    rotatesprite_win((orientation&ROTATESPRITE_MAX)?x:(x<<16),(orientation&ROTATESPRITE_MAX)?y:(y<<16),
726
                     32768L,a,tilenum,shade,p,2|orientation);
5 Plagman 727
}
728
 
1205 terminx 729
void G_DrawTilePalSmall(int32_t x, int32_t y, int32_t tilenum, int32_t shade, int32_t orientation, int32_t p)
5 Plagman 730
{
1205 terminx 731
    int32_t a = 0;
428 terminx 732
 
331 terminx 733
    if (orientation&4)
5 Plagman 734
        a = 1024;
735
 
2318 helixhorne 736
    rotatesprite_win((orientation&ROTATESPRITE_MAX)?x:(x<<16),(orientation&ROTATESPRITE_MAX)?y:(y<<16),
737
                     32768L,a,tilenum,shade,p,2|orientation);
5 Plagman 738
}
739
 
1148 terminx 740
#define POLYMOSTTRANS (1)
741
#define POLYMOSTTRANS2 (1|32)
742
 
1171 terminx 743
// draws inventory numbers in the HUD for both the full and mini status bars
1658 terminx 744
static void G_DrawInvNum(int32_t x,int32_t y,char num1,char ha,int32_t sbits)
5 Plagman 745
{
746
    char dabuf[80] = {0};
2316 helixhorne 747
    int32_t i, shd = (x < 0);
934 terminx 748
 
946 terminx 749
    if (shd) x = -x;
934 terminx 750
 
5 Plagman 751
    Bsprintf(dabuf,"%d",num1);
331 terminx 752
    if (num1 > 99)
5 Plagman 753
    {
1171 terminx 754
        if (shd && ud.screen_size == 4 && getrendermode() >= 3 && althud_shadows)
934 terminx 755
        {
2316 helixhorne 756
            for (i=0; i<=2; i++)
757
                rotatesprite_fs(sbarx(x+(-4+4*i)+1),sbary(y+1),sbarsc(65536),0,THREEBYFIVE+dabuf[i]-'0',ha, 4, POLYMOSTTRANS|sbits);
934 terminx 758
        }
2316 helixhorne 759
 
760
        for (i=0; i<=2; i++)
761
            rotatesprite_fs(sbarx(x+(-4+4*i)),sbary(y),sbarsc(65536),0,THREEBYFIVE+dabuf[i]-'0',ha, 0, sbits);
425 terminx 762
        return;
5 Plagman 763
    }
425 terminx 764
    if (num1 > 9)
5 Plagman 765
    {
1171 terminx 766
        if (shd && ud.screen_size == 4 && getrendermode() >= 3 && althud_shadows)
934 terminx 767
        {
2308 helixhorne 768
            rotatesprite_fs(sbarx(x+1),sbary(y+1),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,4,POLYMOSTTRANS|sbits);
769
            rotatesprite_fs(sbarx(x+4+1),sbary(y+1),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,4,POLYMOSTTRANS|sbits);
934 terminx 770
        }
771
 
2308 helixhorne 772
        rotatesprite_fs(sbarx(x),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits);
773
        rotatesprite_fs(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,sbits);
425 terminx 774
        return;
5 Plagman 775
    }
2308 helixhorne 776
    rotatesprite_fs(sbarx(x+4+1),sbary(y+1),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,4,sbits);
777
    rotatesprite_fs(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,sbits);
5 Plagman 778
}
779
 
1658 terminx 780
static void G_DrawWeapNum(int16_t ind,int32_t x,int32_t y,int32_t num1, int32_t num2,int32_t ha)
5 Plagman 781
{
782
    char dabuf[80] = {0};
783
 
2308 helixhorne 784
    rotatesprite_fs(sbarx(x-7),sbary(y),sbarsc(65536L),0,THREEBYFIVE+ind+1,ha-10,7,10);
785
    rotatesprite_fs(sbarx(x-3),sbary(y),sbarsc(65536L),0,THREEBYFIVE+10,ha,0,10);
425 terminx 786
 
787
    if (VOLUMEONE && (ind > HANDBOMB_WEAPON || ind < 0))
788
    {
1658 terminx 789
        minitextshade(x+1,y-4,"ORDER",20,11,2+8+16+ROTATESPRITE_MAX);
425 terminx 790
        return;
791
    }
792
 
2308 helixhorne 793
    rotatesprite_fs(sbarx(x+9),sbary(y),sbarsc(65536L),0,THREEBYFIVE+11,ha,0,10);
5 Plagman 794
 
331 terminx 795
    if (num1 > 99) num1 = 99;
796
    if (num2 > 99) num2 = 99;
5 Plagman 797
 
584 terminx 798
    Bsprintf(dabuf,"%d",num1);
331 terminx 799
    if (num1 > 9)
5 Plagman 800
    {
2308 helixhorne 801
        rotatesprite_fs(sbarx(x),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
802
        rotatesprite_fs(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10);
5 Plagman 803
    }
2308 helixhorne 804
    else rotatesprite_fs(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
5 Plagman 805
 
584 terminx 806
    Bsprintf(dabuf,"%d",num2);
331 terminx 807
    if (num2 > 9)
5 Plagman 808
    {
2308 helixhorne 809
        rotatesprite_fs(sbarx(x+13),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
810
        rotatesprite_fs(sbarx(x+17),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10);
425 terminx 811
        return;
5 Plagman 812
    }
2308 helixhorne 813
    rotatesprite_fs(sbarx(x+13),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
5 Plagman 814
}
815
 
1205 terminx 816
static void G_DrawWeapNum2(char ind,int32_t x,int32_t y,int32_t num1, int32_t num2,char ha)
5 Plagman 817
{
818
    char dabuf[80] = {0};
819
 
2308 helixhorne 820
    rotatesprite_fs(sbarx(x-7),sbary(y),sbarsc(65536L),0,THREEBYFIVE+ind+1,ha-10,7,10);
821
    rotatesprite_fs(sbarx(x-4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+10,ha,0,10);
822
    rotatesprite_fs(sbarx(x+13),sbary(y),sbarsc(65536L),0,THREEBYFIVE+11,ha,0,10);
5 Plagman 823
 
584 terminx 824
    Bsprintf(dabuf,"%d",num1);
331 terminx 825
    if (num1 > 99)
5 Plagman 826
    {
2308 helixhorne 827
        rotatesprite_fs(sbarx(x),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
828
        rotatesprite_fs(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10);
829
        rotatesprite_fs(sbarx(x+8),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[2]-'0',ha,0,10);
5 Plagman 830
    }
331 terminx 831
    else if (num1 > 9)
5 Plagman 832
    {
2308 helixhorne 833
        rotatesprite_fs(sbarx(x+4),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
834
        rotatesprite_fs(sbarx(x+8),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10);
5 Plagman 835
    }
2308 helixhorne 836
    else rotatesprite_fs(sbarx(x+8),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
5 Plagman 837
 
584 terminx 838
    Bsprintf(dabuf,"%d",num2);
331 terminx 839
    if (num2 > 99)
5 Plagman 840
    {
2308 helixhorne 841
        rotatesprite_fs(sbarx(x+17),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
842
        rotatesprite_fs(sbarx(x+21),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10);
843
        rotatesprite_fs(sbarx(x+25),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[2]-'0',ha,0,10);
5 Plagman 844
    }
331 terminx 845
    else if (num2 > 9)
5 Plagman 846
    {
2308 helixhorne 847
        rotatesprite_fs(sbarx(x+17),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
848
        rotatesprite_fs(sbarx(x+21),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[1]-'0',ha,0,10);
425 terminx 849
        return;
5 Plagman 850
    }
587 terminx 851
    else
2308 helixhorne 852
        rotatesprite_fs(sbarx(x+25),sbary(y),sbarsc(65536L),0,THREEBYFIVE+dabuf[0]-'0',ha,0,10);
5 Plagman 853
}
854
 
1205 terminx 855
static void G_DrawWeapAmounts(DukePlayer_t *p,int32_t x,int32_t y,int32_t u)
5 Plagman 856
{
1205 terminx 857
    int32_t cw = p->curr_weapon;
5 Plagman 858
 
859
    if (u&4)
860
    {
1144 terminx 861
        if (u != -1) G_PatchStatusBar(88,178,88+37,178+6); //original code: (96,178,96+12,178+6);
1143 terminx 862
        G_DrawWeapNum2(PISTOL_WEAPON,x,y,
863
                       p->ammo_amount[PISTOL_WEAPON],p->max_ammo_amount[PISTOL_WEAPON],
864
                       12-20*(cw == PISTOL_WEAPON));
5 Plagman 865
    }
866
    if (u&8)
867
    {
1144 terminx 868
        if (u != -1) G_PatchStatusBar(88,184,88+37,184+6); //original code: (96,184,96+12,184+6);
1143 terminx 869
        G_DrawWeapNum2(SHOTGUN_WEAPON,x,y+6,
870
                       p->ammo_amount[SHOTGUN_WEAPON],p->max_ammo_amount[SHOTGUN_WEAPON],
1625 terminx 871
                       (((p->gotweapon & (1<<SHOTGUN_WEAPON)) == 0)*9)+12-18*
1143 terminx 872
                       (cw == SHOTGUN_WEAPON));
5 Plagman 873
    }
874
    if (u&16)
875
    {
1144 terminx 876
        if (u != -1) G_PatchStatusBar(88,190,88+37,190+6); //original code: (96,190,96+12,190+6);
1143 terminx 877
        G_DrawWeapNum2(CHAINGUN_WEAPON,x,y+12,
878
                       p->ammo_amount[CHAINGUN_WEAPON],p->max_ammo_amount[CHAINGUN_WEAPON],
1625 terminx 879
                       (((p->gotweapon & (1<<CHAINGUN_WEAPON)) == 0)*9)+12-18*
1143 terminx 880
                       (cw == CHAINGUN_WEAPON));
5 Plagman 881
    }
882
    if (u&32)
883
    {
1144 terminx 884
        if (u != -1) G_PatchStatusBar(127,178,127+29,178+6); //original code: (135,178,135+8,178+6);
1143 terminx 885
        G_DrawWeapNum(RPG_WEAPON,x+39,y,
886
                      p->ammo_amount[RPG_WEAPON],p->max_ammo_amount[RPG_WEAPON],
1625 terminx 887
                      (((p->gotweapon & (1<<RPG_WEAPON)) == 0)*9)+12-19*
1143 terminx 888
                      (cw == RPG_WEAPON));
5 Plagman 889
    }
890
    if (u&64)
891
    {
1144 terminx 892
        if (u != -1) G_PatchStatusBar(127,184,127+29,184+6); //original code: (135,184,135+8,184+6);
1143 terminx 893
        G_DrawWeapNum(HANDBOMB_WEAPON,x+39,y+6,
894
                      p->ammo_amount[HANDBOMB_WEAPON],p->max_ammo_amount[HANDBOMB_WEAPON],
1625 terminx 895
                      (((!p->ammo_amount[HANDBOMB_WEAPON])|((p->gotweapon & (1<<HANDBOMB_WEAPON)) == 0))*9)+12-19*
1143 terminx 896
                      ((cw == HANDBOMB_WEAPON) || (cw == HANDREMOTE_WEAPON)));
5 Plagman 897
    }
898
    if (u&128)
899
    {
1144 terminx 900
        if (u != -1) G_PatchStatusBar(127,190,127+29,190+6); //original code: (135,190,135+8,190+6);
5 Plagman 901
 
425 terminx 902
        if (p->subweapon&(1<<GROW_WEAPON))
1143 terminx 903
            G_DrawWeapNum(SHRINKER_WEAPON,x+39,y+12,
904
                          p->ammo_amount[GROW_WEAPON],p->max_ammo_amount[GROW_WEAPON],
1625 terminx 905
                          (((p->gotweapon & (1<<GROW_WEAPON)) == 0)*9)+12-18*
1143 terminx 906
                          (cw == GROW_WEAPON));
335 terminx 907
        else
1143 terminx 908
            G_DrawWeapNum(SHRINKER_WEAPON,x+39,y+12,
909
                          p->ammo_amount[SHRINKER_WEAPON],p->max_ammo_amount[SHRINKER_WEAPON],
1625 terminx 910
                          (((p->gotweapon & (1<<SHRINKER_WEAPON)) == 0)*9)+12-18*
1143 terminx 911
                          (cw == SHRINKER_WEAPON));
5 Plagman 912
    }
913
    if (u&256)
914
    {
1144 terminx 915
        if (u != -1) G_PatchStatusBar(158,178,162+29,178+6); //original code: (166,178,166+8,178+6);
5 Plagman 916
 
1143 terminx 917
        G_DrawWeapNum(DEVISTATOR_WEAPON,x+70,y,
918
                      p->ammo_amount[DEVISTATOR_WEAPON],p->max_ammo_amount[DEVISTATOR_WEAPON],
1625 terminx 919
                      (((p->gotweapon & (1<<DEVISTATOR_WEAPON)) == 0)*9)+12-18*
1143 terminx 920
                      (cw == DEVISTATOR_WEAPON));
5 Plagman 921
    }
922
    if (u&512)
923
    {
1144 terminx 924
        if (u != -1) G_PatchStatusBar(158,184,162+29,184+6); //original code: (166,184,166+8,184+6);
428 terminx 925
 
1143 terminx 926
        G_DrawWeapNum(TRIPBOMB_WEAPON,x+70,y+6,
927
                      p->ammo_amount[TRIPBOMB_WEAPON],p->max_ammo_amount[TRIPBOMB_WEAPON],
1625 terminx 928
                      (((p->gotweapon & (1<<TRIPBOMB_WEAPON)) == 0)*9)+12-18*
1143 terminx 929
                      (cw == TRIPBOMB_WEAPON));
5 Plagman 930
    }
931
 
932
    if (u&65536L)
933
    {
1144 terminx 934
        if (u != -1) G_PatchStatusBar(158,190,162+29,190+6); //original code: (166,190,166+8,190+6);
425 terminx 935
 
1143 terminx 936
        G_DrawWeapNum(-1,x+70,y+12,
937
                      p->ammo_amount[FREEZE_WEAPON],p->max_ammo_amount[FREEZE_WEAPON],
1625 terminx 938
                      (((p->gotweapon & (1<<FREEZE_WEAPON)) == 0)*9)+12-18*
1143 terminx 939
                      (cw == FREEZE_WEAPON));
5 Plagman 940
    }
941
}
942
 
1658 terminx 943
static void G_DrawDigiNum(int32_t x,int32_t y,int32_t n,char s,int32_t cs)
5 Plagman 944
{
1205 terminx 945
    int32_t i, j = 0, k, p, c;
2086 helixhorne 946
    char b[12];
5 Plagman 947
 
2086 helixhorne 948
    i = Bsprintf(b,"%d",n);
5 Plagman 949
 
1229 terminx 950
    for (k=i-1; k>=0; k--)
5 Plagman 951
    {
952
        p = DIGITALNUM+*(b+k)-'0';
953
        j += tilesizx[p]+1;
954
    }
955
    c = x-(j>>1);
956
 
957
    j = 0;
1229 terminx 958
    for (k=0; k<i; k++)
5 Plagman 959
    {
960
        p = DIGITALNUM+*(b+k)-'0';
2308 helixhorne 961
        rotatesprite_fs(sbarx(c+j),sbary(y),sbarsc(65536L),0,p,s,0,cs);
5 Plagman 962
        j += tilesizx[p]+1;
963
    }
964
}
965
 
1658 terminx 966
void G_DrawTXDigiNumZ(int32_t starttile, int32_t x,int32_t y,int32_t n,int32_t s,int32_t pal,
967
                      int32_t cs,int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z)
5 Plagman 968
{
1205 terminx 969
    int32_t i, j = 0, k, p, c;
2086 helixhorne 970
    char b[12];
1658 terminx 971
    int32_t shift = (cs&ROTATESPRITE_MAX)?0:16;
5 Plagman 972
 
973
    //ltoa(n,b,10);
2086 helixhorne 974
    i = Bsprintf(b,"%d",n);
5 Plagman 975
 
1229 terminx 976
    for (k=i-1; k>=0; k--)
5 Plagman 977
    {
2086 helixhorne 978
        p = starttile + b[k]-'0';
1732 terminx 979
        j += ((1+tilesizx[p])*z)>>16;
5 Plagman 980
    }
1658 terminx 981
    if (cs&ROTATESPRITE_MAX) j<<=16;
5 Plagman 982
    c = x-(j>>1);
983
 
984
    j = 0;
1229 terminx 985
    for (k=0; k<i; k++)
5 Plagman 986
    {
2086 helixhorne 987
        p = starttile + b[k]-'0';
966 hnt_ts 988
        rotatesprite((c+j)<<shift,y<<shift,z,0,p,s,pal,2|cs,x1,y1,x2,y2);
1732 terminx 989
        j += (((1+tilesizx[p])*z)>>((cs&ROTATESPRITE_MAX)?0:16));
5 Plagman 990
    }
991
}
992
 
1658 terminx 993
static void G_DrawAltDigiNum(int32_t x,int32_t y,int32_t n,char s,int32_t cs)
934 terminx 994
{
1205 terminx 995
    int32_t i, j = 0, k, p, c;
2086 helixhorne 996
    char b[12];
1205 terminx 997
    int32_t rev = (x < 0);
998
    int32_t shd = (y < 0);
934 terminx 999
 
1000
    if (rev) x = -x;
946 terminx 1001
    if (shd) y = -y;
934 terminx 1002
 
2086 helixhorne 1003
    i = Bsprintf(b,"%d",n);
934 terminx 1004
 
1229 terminx 1005
    for (k=i-1; k>=0; k--)
934 terminx 1006
    {
937 terminx 1007
        p = althud_numbertile+*(b+k)-'0';
934 terminx 1008
        j += tilesizx[p]+1;
1009
    }
1010
    c = x-(j>>1);
1011
 
1012
    if (rev)
1013
    {
1014
//        j = 0;
1229 terminx 1015
        for (k=0; k<i; k++)
934 terminx 1016
        {
937 terminx 1017
            p = althud_numbertile+*(b+k)-'0';
1148 terminx 1018
            if (shd && getrendermode() >= 3 && althud_shadows)
2308 helixhorne 1019
                rotatesprite_fs(sbarxr(c+j-1),sbary(y+1),sbarsc(65536L),0,p,s,4,cs|POLYMOSTTRANS2);
1020
            rotatesprite_fs(sbarxr(c+j),sbary(y),sbarsc(65536L),0,p,s,althud_numberpal,cs);
934 terminx 1021
            j -= tilesizx[p]+1;
1022
        }
1023
        return;
1024
    }
1025
    j = 0;
1229 terminx 1026
    for (k=0; k<i; k++)
934 terminx 1027
    {
937 terminx 1028
        p = althud_numbertile+*(b+k)-'0';
1148 terminx 1029
        if (shd && getrendermode() >= 3 && althud_shadows)
2308 helixhorne 1030
            rotatesprite_fs(sbarx(c+j+1),sbary(y+1),sbarsc(65536L),0,p,s,4,cs|POLYMOSTTRANS2);
1031
        rotatesprite_fs(sbarx(c+j),sbary(y),sbarsc(65536L),0,p,s,althud_numberpal,cs);
934 terminx 1032
        j += tilesizx[p]+1;
1033
    }
1034
}
1035
 
1143 terminx 1036
static void G_DrawInventory(DukePlayer_t *p)
5 Plagman 1037
{
1205 terminx 1038
    int32_t n, j = 0, xoff = 0, y;
5 Plagman 1039
 
1572 terminx 1040
    n = (p->inv_amount[GET_JETPACK] > 0)<<3;
335 terminx 1041
    if (n&8) j++;
1572 terminx 1042
    n |= (p->inv_amount[GET_SCUBA] > 0)<<5;
335 terminx 1043
    if (n&32) j++;
1572 terminx 1044
    n |= (p->inv_amount[GET_STEROIDS] > 0)<<1;
335 terminx 1045
    if (n&2) j++;
1572 terminx 1046
    n |= (p->inv_amount[GET_HOLODUKE] > 0)<<2;
335 terminx 1047
    if (n&4) j++;
1572 terminx 1048
    n |= (p->inv_amount[GET_FIRSTAID] > 0);
335 terminx 1049
    if (n&1) j++;
1572 terminx 1050
    n |= (p->inv_amount[GET_HEATS] > 0)<<4;
335 terminx 1051
    if (n&16) j++;
1572 terminx 1052
    n |= (p->inv_amount[GET_BOOTS] > 0)<<6;
335 terminx 1053
    if (n&64) j++;
5 Plagman 1054
 
1055
    xoff = 160-(j*11);
1056
 
1057
    j = 0;
1058
 
934 terminx 1059
    y = 154;
5 Plagman 1060
 
333 terminx 1061
    while (j <= 9)
5 Plagman 1062
    {
333 terminx 1063
        if (n&(1<<j))
5 Plagman 1064
        {
333 terminx 1065
            switch (n&(1<<j))
5 Plagman 1066
            {
1632 terminx 1067
            case 1:
2318 helixhorne 1068
                rotatesprite_win(xoff<<16,y<<16,65536L,0,FIRSTAID_ICON,0,0,2+16);
337 terminx 1069
                break;
1632 terminx 1070
            case 2:
2318 helixhorne 1071
                rotatesprite_win((xoff+1)<<16,y<<16,65536L,0,STEROIDS_ICON,0,0,2+16);
337 terminx 1072
                break;
1632 terminx 1073
            case 4:
2318 helixhorne 1074
                rotatesprite_win((xoff+2)<<16,y<<16,65536L,0,HOLODUKE_ICON,0,0,2+16);
337 terminx 1075
                break;
1632 terminx 1076
            case 8:
2318 helixhorne 1077
                rotatesprite_win(xoff<<16,y<<16,65536L,0,JETPACK_ICON,0,0,2+16);
337 terminx 1078
                break;
1632 terminx 1079
            case 16:
2318 helixhorne 1080
                rotatesprite_win(xoff<<16,y<<16,65536L,0,HEAT_ICON,0,0,2+16);
337 terminx 1081
                break;
1632 terminx 1082
            case 32:
2318 helixhorne 1083
                rotatesprite_win(xoff<<16,y<<16,65536L,0,AIRTANK_ICON,0,0,2+16);
337 terminx 1084
                break;
1085
            case 64:
2318 helixhorne 1086
                rotatesprite_win(xoff<<16,(y-1)<<16,65536L,0,BOOT_ICON,0,0,2+16);
337 terminx 1087
                break;
5 Plagman 1088
            }
1089
 
1090
            xoff += 22;
1091
 
331 terminx 1092
            if (p->inven_icon == j+1)
2318 helixhorne 1093
                rotatesprite_win((xoff-2)<<16,(y+19)<<16,65536L,1024,ARROW,-32,0,2+16);
5 Plagman 1094
        }
1095
 
1096
        j++;
1097
    }
1098
}
1099
 
1143 terminx 1100
void G_DrawFrags(void)
5 Plagman 1101
{
1205 terminx 1102
    int32_t i, j = 0;
5 Plagman 1103
 
2379 helixhorne 1104
    for (TRAVERSE_CONNECT(i))
1105
        if (i > j) j = i;
5 Plagman 1106
 
2308 helixhorne 1107
    rotatesprite_fs(0,0,65600L,0,FRAGBAR,0,0,2+8+16+64);
1108
    if (j >= 4) rotatesprite_fs(319,(8)<<16,65600L,0,FRAGBAR,0,0,10+16+64);
1109
    if (j >= 8) rotatesprite_fs(319,(16)<<16,65600L,0,FRAGBAR,0,0,10+16+64);
1110
    if (j >= 12) rotatesprite_fs(319,(24)<<16,65600L,0,FRAGBAR,0,0,10+16+64);
5 Plagman 1111
 
2379 helixhorne 1112
    for (TRAVERSE_CONNECT(i))
5 Plagman 1113
    {
564 terminx 1114
        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);
1115
        Bsprintf(tempbuf,"%d",g_player[i].ps->frag-g_player[i].ps->fraggedself);
1116
        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 1117
    }
1118
}
1119
 
261 terminx 1120
#define SBY (200-tilesizy[BOTTOMSTATUSBAR])
1121
 
1205 terminx 1122
static void G_DrawStatusBar(int32_t snum)
5 Plagman 1123
{
1143 terminx 1124
    DukePlayer_t *p = g_player[snum].ps;
1205 terminx 1125
    int32_t i, j, o, ss = ud.screen_size, u;
1126
    int32_t permbit = 0;
5 Plagman 1127
 
532 terminx 1128
    if (ss < 4) return;
1129
 
966 hnt_ts 1130
    if (getrendermode() >= 3) pus = NUMPAGES;   // JBF 20040101: always redraw in GL
5 Plagman 1131
 
1587 terminx 1132
    if ((g_netServer || (g_netServer || ud.multimode > 1)) && (GametypeFlags[ud.coop] & GAMETYPE_FRAGBAR))
5 Plagman 1133
    {
1134
        if (pus)
1143 terminx 1135
            G_DrawFrags();
5 Plagman 1136
        else
1137
        {
2379 helixhorne 1138
            for (TRAVERSE_CONNECT(i))
1139
                if (g_player[i].ps->frag != sbar.frag[i])
1140
                {
1141
                    G_DrawFrags();
1142
                    break;
1143
                }
331 terminx 1144
 
5 Plagman 1145
        }
2379 helixhorne 1146
        for (TRAVERSE_CONNECT(i))
1147
            if (i != myconnectindex)
1148
                sbar.frag[i] = g_player[i].ps->frag;
5 Plagman 1149
    }
1150
 
1151
    if (ss == 4)   //DRAW MINI STATUS BAR:
1152
    {
934 terminx 1153
        if (ud.althud) // althud
1154
        {
1205 terminx 1155
            static int32_t ammo_sprites[MAX_WEAPONS];
934 terminx 1156
 
1157
            if (!ammo_sprites[0])
1158
            {
1159
                /* this looks stupid but it lets us initialize static memory to dynamic values
1160
                   these values can be changed from the CONs with dynamic tile remapping
1161
                   but we don't want to have to recreate the values in memory every time
1162
                   the HUD is drawn */
1163
 
1205 terminx 1164
                int32_t asprites[MAX_WEAPONS] = { BOOTS, AMMO, SHOTGUNAMMO,
1207 terminx 1165
                                                  BATTERYAMMO, RPGAMMO, HBOMBAMMO, CRYSTALAMMO, DEVISTATORAMMO,
1166
                                                  TRIPBOMBSPRITE, FREEZEAMMO+1, HBOMBAMMO, GROWAMMO
1167
                                                };
934 terminx 1168
                Bmemcpy(ammo_sprites,asprites,sizeof(ammo_sprites));
1169
            }
1170
 
2308 helixhorne 1171
//            rotatesprite_fs(sbarx(5+1),sbary(200-25+1),sbarsc(49152L),0,SIXPAK,0,4,10+16+1+32);
1172
//            rotatesprite_fs(sbarx(5),sbary(200-25),sbarsc(49152L),0,SIXPAK,0,0,10+16);
1148 terminx 1173
            if (getrendermode() >= 3 && althud_shadows)
2308 helixhorne 1174
                rotatesprite_fs(sbarx(2+1),sbary(200-21+1),sbarsc(49152L),0,COLA,0,4,10+16+256+POLYMOSTTRANS2);
1175
            rotatesprite_fs(sbarx(2),sbary(200-21),sbarsc(49152L),0,COLA,0,0,10+16+256);
935 terminx 1176
 
934 terminx 1177
            if (sprite[p->i].pal == 1 && p->last_extra < 2)
1658 terminx 1178
                G_DrawAltDigiNum(40,-(200-22),1,-16,10+16+256);
953 terminx 1179
            else if (!althud_flashing || p->last_extra > (p->max_player_health>>2) || totalclock&32)
1089 terminx 1180
            {
1205 terminx 1181
                int32_t s = -8;
1089 terminx 1182
                if (althud_flashing && p->last_extra > p->max_player_health)
1183
                    s += (sintable[(totalclock<<5)&2047]>>10);
1658 terminx 1184
                G_DrawAltDigiNum(40,-(200-22),p->last_extra,s,10+16+256);
1089 terminx 1185
            }
934 terminx 1186
 
1148 terminx 1187
            if (getrendermode() >= 3 && althud_shadows)
2308 helixhorne 1188
                rotatesprite_fs(sbarx(62+1),sbary(200-25+1),sbarsc(49152L),0,SHIELD,0,4,10+16+POLYMOSTTRANS2+256);
1189
            rotatesprite_fs(sbarx(62),sbary(200-25),sbarsc(49152L),0,SHIELD,0,0,10+16+256);
934 terminx 1190
 
1490 terminx 1191
            {
1192
                int32_t lAmount=Gv_GetVarByLabel("PLR_MORALE",-1, p->i, snum);
1572 terminx 1193
                if (lAmount == -1) lAmount = p->inv_amount[GET_SHIELD];
1658 terminx 1194
                G_DrawAltDigiNum(105,-(200-22),lAmount,-16,10+16+256);
1490 terminx 1195
            }
934 terminx 1196
 
1148 terminx 1197
            if (getrendermode() >= 3 && althud_shadows)
944 terminx 1198
            {
2308 helixhorne 1199
                if (p->got_access&1) rotatesprite_fs(sbarxr(39-1),sbary(200-43+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2+512);
1200
                if (p->got_access&4) rotatesprite_fs(sbarxr(34-1),sbary(200-41+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2+512);
1201
                if (p->got_access&2) rotatesprite_fs(sbarxr(29-1),sbary(200-39+1),sbarsc(32768),0,ACCESSCARD,0,4,10+16+POLYMOSTTRANS2+512);
944 terminx 1202
            }
935 terminx 1203
 
2308 helixhorne 1204
            if (p->got_access&1) rotatesprite_fs(sbarxr(39),sbary(200-43),sbarsc(32768),0,ACCESSCARD,0,0,10+16+512);
1205
            if (p->got_access&4) rotatesprite_fs(sbarxr(34),sbary(200-41),sbarsc(32768),0,ACCESSCARD,0,23,10+16+512);
1206
            if (p->got_access&2) rotatesprite_fs(sbarxr(29),sbary(200-39),sbarsc(32768),0,ACCESSCARD,0,21,10+16+512);
935 terminx 1207
 
1658 terminx 1208
            i = (p->curr_weapon == PISTOL_WEAPON) ? 16384 : 32768;
1209
 
1148 terminx 1210
            if (getrendermode() >= 3 && althud_shadows)
2308 helixhorne 1211
                rotatesprite_fs(sbarxr(57-1),sbary(200-15+1),sbarsc(i),0,ammo_sprites[p->curr_weapon],0,4,10+POLYMOSTTRANS2+512);
1212
            rotatesprite_fs(sbarxr(57),sbary(200-15),sbarsc(i),0,ammo_sprites[p->curr_weapon],0,0,10+512);
934 terminx 1213
 
1214
            if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON;
1215
            else i = p->curr_weapon;
1658 terminx 1216
 
952 terminx 1217
            if (p->curr_weapon != KNEE_WEAPON &&
962 terminx 1218
                    (!althud_flashing || totalclock&32 || p->ammo_amount[i] > (p->max_ammo_amount[i]/10)))
1658 terminx 1219
                G_DrawAltDigiNum(-20,-(200-22),p->ammo_amount[i],-16,10+16+512);
934 terminx 1220
 
941 terminx 1221
            o = 102;
934 terminx 1222
            permbit = 0;
1223
 
1224
            if (p->inven_icon)
1225
            {
1226
                switch (p->inven_icon)
1227
                {
1228
                case 1:
1229
                    i = FIRSTAID_ICON;
1230
                    break;
1231
                case 2:
1232
                    i = STEROIDS_ICON;
1233
                    break;
1234
                case 3:
1235
                    i = HOLODUKE_ICON;
1236
                    break;
1237
                case 4:
1238
                    i = JETPACK_ICON;
1239
                    break;
1240
                case 5:
1241
                    i = HEAT_ICON;
1242
                    break;
1243
                case 6:
1244
                    i = AIRTANK_ICON;
1245
                    break;
1246
                case 7:
1247
                    i = BOOT_ICON;
1248
                    break;
1249
                default:
1250
                    i = -1;
1251
                }
1252
                if (i >= 0)
1253
                {
1148 terminx 1254
                    if (getrendermode() >= 3 && althud_shadows)
2308 helixhorne 1255
                        rotatesprite_fs(sbarx(231-o+1),sbary(200-21-2+1),sbarsc(65536L),0,i,0,4,10+16+permbit+POLYMOSTTRANS2+256);
1256
                    rotatesprite_fs(sbarx(231-o),sbary(200-21-2),sbarsc(65536L),0,i,0,0,10+16+permbit+256);
934 terminx 1257
                }
1258
 
1148 terminx 1259
                if (getrendermode() >= 3 && althud_shadows)
1658 terminx 1260
                    minitext(292-30-o+1,190-3+1,"%",4,POLYMOSTTRANS+10+16+permbit+256 + ROTATESPRITE_MAX);
1261
                minitext(292-30-o,190-3,"%",6,10+16+permbit+256 + ROTATESPRITE_MAX);
934 terminx 1262
 
1263
                j = 0x80000000;
1264
                switch (p->inven_icon)
1265
                {
1266
                case 1:
1572 terminx 1267
                    i = p->inv_amount[GET_FIRSTAID];
934 terminx 1268
                    break;
1269
                case 2:
1572 terminx 1270
                    i = ((p->inv_amount[GET_STEROIDS]+3)>>2);
934 terminx 1271
                    break;
1272
                case 3:
1572 terminx 1273
                    i = ((p->inv_amount[GET_HOLODUKE]+15)/24);
934 terminx 1274
                    j = p->holoduke_on;
1275
                    break;
1276
                case 4:
1572 terminx 1277
                    i = ((p->inv_amount[GET_JETPACK]+15)>>4);
934 terminx 1278
                    j = p->jetpack_on;
1279
                    break;
1280
                case 5:
1572 terminx 1281
                    i = p->inv_amount[GET_HEATS]/12;
934 terminx 1282
                    j = p->heat_on;
1283
                    break;
1284
                case 6:
1572 terminx 1285
                    i = ((p->inv_amount[GET_SCUBA]+63)>>6);
934 terminx 1286
                    break;
1287
                case 7:
1572 terminx 1288
                    i = (p->inv_amount[GET_BOOTS]>>1);
934 terminx 1289
                    break;
1290
                }
1658 terminx 1291
                G_DrawInvNum(-(284-30-o),200-6-3,(uint8_t)i,0,10+permbit+256);
934 terminx 1292
                if (j > 0)
1293
                {
1148 terminx 1294
                    if (getrendermode() >= 3 && althud_shadows)
2540 hendricks2 1295
                        minitext(288-30-o+1,180-3+1,"On",4,POLYMOSTTRANS+10+16+permbit+256 + ROTATESPRITE_MAX);
1296
                    minitext(288-30-o,180-3,"On",0,10+16+permbit+256 + ROTATESPRITE_MAX);
934 terminx 1297
                }
1205 terminx 1298
                else if ((uint32_t)j != 0x80000000)
934 terminx 1299
                {
1148 terminx 1300
                    if (getrendermode() >= 3 && althud_shadows)
2540 hendricks2 1301
                        minitext(284-30-o+1,180-3+1,"Off",4,POLYMOSTTRANS+10+16+permbit+256 + ROTATESPRITE_MAX);
1302
                    minitext(284-30-o,180-3,"Off",2,10+16+permbit+256 + ROTATESPRITE_MAX);
934 terminx 1303
                }
1677 terminx 1304
 
934 terminx 1305
                if (p->inven_icon >= 6)
1306
                {
1148 terminx 1307
                    if (getrendermode() >= 3 && althud_shadows)
2540 hendricks2 1308
                        minitext(284-35-o+1,180-3+1,"Auto",4,POLYMOSTTRANS+10+16+permbit+256 + ROTATESPRITE_MAX);
1309
                    minitext(284-35-o,180-3,"Auto",2,10+16+permbit+256 + ROTATESPRITE_MAX);
934 terminx 1310
                }
1311
            }
1312
            return;
1313
        }
1658 terminx 1314
 
2308 helixhorne 1315
        rotatesprite_fs(sbarx(5),sbary(200-28),sbarsc(65536L),0,HEALTHBOX,0,21,10+16+256);
5 Plagman 1316
        if (p->inven_icon)
2308 helixhorne 1317
            rotatesprite_fs(sbarx(69),sbary(200-30),sbarsc(65536L),0,INVENTORYBOX,0,21,10+16+256);
5 Plagman 1318
 
1179 terminx 1319
        if (sprite[p->i].pal == 1 && p->last_extra < 2) // frozen
1658 terminx 1320
            G_DrawDigiNum(20,200-17,1,-16,10+16+256);
1321
        else G_DrawDigiNum(20,200-17,p->last_extra,-16,10+16+256);
5 Plagman 1322
 
2308 helixhorne 1323
        rotatesprite_fs(sbarx(37),sbary(200-28),sbarsc(65536L),0,AMMOBOX,0,21,10+16+256);
5 Plagman 1324
 
335 terminx 1325
        if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON;
1326
        else i = p->curr_weapon;
1658 terminx 1327
        G_DrawDigiNum(53,200-17,p->ammo_amount[i],-16,10+16+256);
5 Plagman 1328
 
335 terminx 1329
        o = 158;
1330
        permbit = 0;
5 Plagman 1331
        if (p->inven_icon)
1332
        {
331 terminx 1333
            switch (p->inven_icon)
5 Plagman 1334
            {
337 terminx 1335
            case 1:
1336
                i = FIRSTAID_ICON;
1337
                break;
1338
            case 2:
1339
                i = STEROIDS_ICON;
1340
                break;
1341
            case 3:
1342
                i = HOLODUKE_ICON;
1343
                break;
1344
            case 4:
1345
                i = JETPACK_ICON;
1346
                break;
1347
            case 5:
1348
                i = HEAT_ICON;
1349
                break;
1350
            case 6:
1351
                i = AIRTANK_ICON;
1352
                break;
1353
            case 7:
1354
                i = BOOT_ICON;
1355
                break;
1356
            default:
1357
                i = -1;
5 Plagman 1358
            }
2308 helixhorne 1359
            if (i >= 0) rotatesprite_fs(sbarx(231-o),sbary(200-21),sbarsc(65536L),0,i,0,0,10+16+permbit+256);
5 Plagman 1360
 
1658 terminx 1361
            minitext(292-30-o,190,"%",6,10+16+permbit+256 + ROTATESPRITE_MAX);
5 Plagman 1362
 
1363
            j = 0x80000000;
331 terminx 1364
            switch (p->inven_icon)
5 Plagman 1365
            {
337 terminx 1366
            case 1:
1572 terminx 1367
                i = p->inv_amount[GET_FIRSTAID];
337 terminx 1368
                break;
1369
            case 2:
1572 terminx 1370
                i = ((p->inv_amount[GET_STEROIDS]+3)>>2);
337 terminx 1371
                break;
1372
            case 3:
1572 terminx 1373
                i = ((p->inv_amount[GET_HOLODUKE]+15)/24);
337 terminx 1374
                j = p->holoduke_on;
1375
                break;
1376
            case 4:
1572 terminx 1377
                i = ((p->inv_amount[GET_JETPACK]+15)>>4);
337 terminx 1378
                j = p->jetpack_on;
1379
                break;
1380
            case 5:
1572 terminx 1381
                i = p->inv_amount[GET_HEATS]/12;
337 terminx 1382
                j = p->heat_on;
1383
                break;
1384
            case 6:
1572 terminx 1385
                i = ((p->inv_amount[GET_SCUBA]+63)>>6);
337 terminx 1386
                break;
1387
            case 7:
1572 terminx 1388
                i = (p->inv_amount[GET_BOOTS]>>1);
337 terminx 1389
                break;
5 Plagman 1390
            }
1658 terminx 1391
            G_DrawInvNum(284-30-o,200-6,(uint8_t)i,0,10+permbit+256);
2540 hendricks2 1392
            if (j > 0) minitext(288-30-o,180,"On",0,10+16+permbit+256 + ROTATESPRITE_MAX);
1393
            else if ((uint32_t)j != 0x80000000) minitext(284-30-o,180,"Off",2,10+16+permbit+256 + ROTATESPRITE_MAX);
1394
            if (p->inven_icon >= 6) minitext(284-35-o,180,"Auto",2,10+16+permbit+256 + ROTATESPRITE_MAX);
5 Plagman 1395
        }
1396
        return;
1397
    }
1398
 
1399
    //DRAW/UPDATE FULL STATUS BAR:
1400
 
335 terminx 1401
    if (pus)
1402
    {
1403
        pus = 0;
1404
        u = -1;
1405
    }
331 terminx 1406
    else u = 0;
5 Plagman 1407
 
335 terminx 1408
    if (sbar.frag[myconnectindex] != p->frag)
1409
    {
1410
        sbar.frag[myconnectindex] = p->frag;
1411
        u |= 32768;
1412
    }
1413
    if (sbar.got_access != p->got_access)
1414
    {
1415
        sbar.got_access = p->got_access;
1416
        u |= 16384;
1417
    }
261 terminx 1418
 
423 terminx 1419
    if (sbar.last_extra != p->last_extra)
5 Plagman 1420
    {
423 terminx 1421
        sbar.last_extra = p->last_extra;
1422
        u |= 1;
1423
    }
1424
 
1425
    {
1205 terminx 1426
        int32_t lAmount=Gv_GetVarByLabel("PLR_MORALE",-1, p->i, snum);
331 terminx 1427
        if (lAmount == -1)
5 Plagman 1428
        {
1572 terminx 1429
            if (sbar.inv_amount[GET_SHIELD] != p->inv_amount[GET_SHIELD])
335 terminx 1430
            {
1572 terminx 1431
                sbar.inv_amount[GET_SHIELD] = p->inv_amount[GET_SHIELD];
335 terminx 1432
                u |= 2;
1433
            }
331 terminx 1434
 
5 Plagman 1435
        }
1436
        else
1437
        {
1572 terminx 1438
            if (sbar.inv_amount[GET_SHIELD] != lAmount)
335 terminx 1439
            {
1572 terminx 1440
                sbar.inv_amount[GET_SHIELD] = lAmount;
335 terminx 1441
                u |= 2;
1442
            }
331 terminx 1443
 
5 Plagman 1444
        }
1445
    }
261 terminx 1446
 
335 terminx 1447
    if (sbar.curr_weapon != p->curr_weapon)
1448
    {
1449
        sbar.curr_weapon = p->curr_weapon;
1450
        u |= (4+8+16+32+64+128+256+512+1024+65536L);
1451
    }
218 terminx 1452
 
1229 terminx 1453
    for (i=1; i<MAX_WEAPONS; i++)
5 Plagman 1454
    {
1455
        if (sbar.ammo_amount[i] != p->ammo_amount[i])
1456
        {
1457
            sbar.ammo_amount[i] = p->ammo_amount[i];
331 terminx 1458
            if (i < 9)
5 Plagman 1459
                u |= ((2<<i)+1024);
218 terminx 1460
            else u |= 65536L+1024;
5 Plagman 1461
        }
218 terminx 1462
 
1625 terminx 1463
        if ((sbar.gotweapon & (1<<i)) != (p->gotweapon & (1<<i)))
5 Plagman 1464
        {
1625 terminx 1465
            if (p->gotweapon & (1<<i))
1466
                sbar.gotweapon |= 1<<i;
1467
            else sbar.gotweapon &= ~(1<<i);
1468
 
333 terminx 1469
            if (i < 9)
5 Plagman 1470
                u |= ((2<<i)+1024);
218 terminx 1471
            else u |= 65536L+1024;
5 Plagman 1472
        }
1473
    }
335 terminx 1474
    if (sbar.inven_icon != p->inven_icon)
1475
    {
1476
        sbar.inven_icon = p->inven_icon;
1477
        u |= (2048+4096+8192);
1478
    }
1479
    if (sbar.holoduke_on != p->holoduke_on)
1480
    {
1481
        sbar.holoduke_on = p->holoduke_on;
1482
        u |= (4096+8192);
1483
    }
1484
    if (sbar.jetpack_on != p->jetpack_on)
1485
    {
1486
        sbar.jetpack_on = p->jetpack_on;
1487
        u |= (4096+8192);
1488
    }
1489
    if (sbar.heat_on != p->heat_on)
1490
    {
1491
        sbar.heat_on = p->heat_on;
1492
        u |= (4096+8192);
1493
    }
1572 terminx 1494
    if (sbar.inv_amount[GET_FIRSTAID] != p->inv_amount[GET_FIRSTAID])
335 terminx 1495
    {
1572 terminx 1496
        sbar.inv_amount[GET_FIRSTAID] = p->inv_amount[GET_FIRSTAID];
335 terminx 1497
        u |= 8192;
1498
    }
1572 terminx 1499
    if (sbar.inv_amount[GET_STEROIDS] != p->inv_amount[GET_STEROIDS])
335 terminx 1500
    {
1572 terminx 1501
        sbar.inv_amount[GET_STEROIDS] = p->inv_amount[GET_STEROIDS];
335 terminx 1502
        u |= 8192;
1503
    }
1572 terminx 1504
    if (sbar.inv_amount[GET_HOLODUKE] != p->inv_amount[GET_HOLODUKE])
335 terminx 1505
    {
1572 terminx 1506
        sbar.inv_amount[GET_HOLODUKE] = p->inv_amount[GET_HOLODUKE];
335 terminx 1507
        u |= 8192;
1508
    }
1572 terminx 1509
    if (sbar.inv_amount[GET_JETPACK] != p->inv_amount[GET_JETPACK])
335 terminx 1510
    {
1572 terminx 1511
        sbar.inv_amount[GET_JETPACK] = p->inv_amount[GET_JETPACK];
335 terminx 1512
        u |= 8192;
1513
    }
1572 terminx 1514
    if (sbar.inv_amount[GET_HEATS] != p->inv_amount[GET_HEATS])
335 terminx 1515
    {
1572 terminx 1516
        sbar.inv_amount[GET_HEATS] = p->inv_amount[GET_HEATS];
335 terminx 1517
        u |= 8192;
1518
    }
1572 terminx 1519
    if (sbar.inv_amount[GET_SCUBA] != p->inv_amount[GET_SCUBA])
335 terminx 1520
    {
1572 terminx 1521
        sbar.inv_amount[GET_SCUBA] = p->inv_amount[GET_SCUBA];
335 terminx 1522
        u |= 8192;
1523
    }
1572 terminx 1524
    if (sbar.inv_amount[GET_BOOTS] != p->inv_amount[GET_BOOTS])
335 terminx 1525
    {
1572 terminx 1526
        sbar.inv_amount[GET_BOOTS] = p->inv_amount[GET_BOOTS];
335 terminx 1527
        u |= 8192;
1528
    }
5 Plagman 1529
    if (u == 0) return;
1530
 
1531
    //0 - update health
1532
    //1 - update armor
1533
    //2 - update PISTOL_WEAPON ammo
1534
    //3 - update SHOTGUN_WEAPON ammo
1535
    //4 - update CHAINGUN_WEAPON ammo
1536
    //5 - update RPG_WEAPON ammo
1537
    //6 - update HANDBOMB_WEAPON ammo
1538
    //7 - update SHRINKER_WEAPON ammo
1539
    //8 - update DEVISTATOR_WEAPON ammo
1540
    //9 - update TRIPBOMB_WEAPON ammo
1541
    //10 - update ammo display
1542
    //11 - update inventory icon
1543
    //12 - update inventory on/off
1544
    //13 - update inventory %
1545
    //14 - update keys
1546
    //15 - update kills
1547
    //16 - update FREEZE_WEAPON ammo
261 terminx 1548
 
5 Plagman 1549
    if (u == -1)
1550
    {
1144 terminx 1551
        G_PatchStatusBar(0,0,320,200);
1587 terminx 1552
        if ((g_netServer || (g_netServer || ud.multimode > 1)) && (GametypeFlags[ud.coop] & GAMETYPE_FRAGBAR))
2308 helixhorne 1553
            rotatesprite_fs(sbarx(277+1),sbary(SBY+7-1),sbarsc(65536L),0,KILLSICON,0,0,10+16);
5 Plagman 1554
    }
1587 terminx 1555
    if ((g_netServer || (g_netServer || ud.multimode > 1)) && (GametypeFlags[ud.coop] & GAMETYPE_FRAGBAR))
5 Plagman 1556
    {
1557
        if (u&32768)
1558
        {
1144 terminx 1559
            if (u != -1) G_PatchStatusBar(276,SBY+17,299,SBY+17+10);
1143 terminx 1560
            G_DrawDigiNum(287,SBY+17,max(p->frag-p->fraggedself,0),-16,10+16);
5 Plagman 1561
        }
1562
    }
1563
    else
1564
    {
1565
        if (u&16384)
1566
        {
1144 terminx 1567
            if (u != -1) G_PatchStatusBar(275,SBY+18,299,SBY+18+12);
2308 helixhorne 1568
            if (p->got_access&4) rotatesprite_fs(sbarx(275),sbary(SBY+16),sbarsc(65536L),0,ACCESS_ICON,0,23,10+16);
1569
            if (p->got_access&2) rotatesprite_fs(sbarx(288),sbary(SBY+16),sbarsc(65536L),0,ACCESS_ICON,0,21,10+16);
1570
            if (p->got_access&1) rotatesprite_fs(sbarx(281),sbary(SBY+23),sbarsc(65536L),0,ACCESS_ICON,0,0,10+16);
5 Plagman 1571
        }
1572
    }
1143 terminx 1573
    if (u&(4+8+16+32+64+128+256+512+65536L)) G_DrawWeapAmounts(p,96,SBY+16,u);
5 Plagman 1574
 
1575
    if (u&1)
1576
    {
1144 terminx 1577
        if (u != -1) G_PatchStatusBar(20,SBY+17,43,SBY+17+11);
5 Plagman 1578
        if (sprite[p->i].pal == 1 && p->last_extra < 2)
1143 terminx 1579
            G_DrawDigiNum(32,SBY+17,1,-16,10+16);
1580
        else G_DrawDigiNum(32,SBY+17,p->last_extra,-16,10+16);
5 Plagman 1581
    }
1582
    if (u&2)
1583
    {
1205 terminx 1584
        int32_t lAmount=Gv_GetVarByLabel("PLR_MORALE",-1, p->i, snum);
1144 terminx 1585
        if (u != -1) G_PatchStatusBar(52,SBY+17,75,SBY+17+11);
331 terminx 1586
        if (lAmount == -1)
1572 terminx 1587
            G_DrawDigiNum(64,SBY+17,p->inv_amount[GET_SHIELD],-16,10+16);
5 Plagman 1588
        else
1143 terminx 1589
            G_DrawDigiNum(64,SBY+17,lAmount,-16,10+16);
5 Plagman 1590
    }
1591
 
1592
    if (u&1024)
1593
    {
1144 terminx 1594
        if (u != -1) G_PatchStatusBar(196,SBY+17,219,SBY+17+11);
5 Plagman 1595
        if (p->curr_weapon != KNEE_WEAPON)
1596
        {
335 terminx 1597
            if (p->curr_weapon == HANDREMOTE_WEAPON) i = HANDBOMB_WEAPON;
1598
            else i = p->curr_weapon;
1143 terminx 1599
            G_DrawDigiNum(230-22,SBY+17,p->ammo_amount[i],-16,10+16);
5 Plagman 1600
        }
1601
    }
1602
 
1603
    if (u&(2048+4096+8192))
1604
    {
1605
        if (u != -1)
1606
        {
335 terminx 1607
            if (u&(2048+4096))
1608
            {
1144 terminx 1609
                G_PatchStatusBar(231,SBY+13,265,SBY+13+18);
335 terminx 1610
            }
1611
            else
1612
            {
1144 terminx 1613
                G_PatchStatusBar(250,SBY+24,261,SBY+24+6);
335 terminx 1614
            }
331 terminx 1615
 
5 Plagman 1616
        }
1617
        if (p->inven_icon)
1618
        {
335 terminx 1619
            o = 0;
500 terminx 1620
//            permbit = 128;
5 Plagman 1621
 
1622
            if (u&(2048+4096))
1623
            {
331 terminx 1624
                switch (p->inven_icon)
5 Plagman 1625
                {
337 terminx 1626
                case 1:
1627
                    i = FIRSTAID_ICON;
1628
                    break;
1629
                case 2:
1630
                    i = STEROIDS_ICON;
1631
                    break;
1632
                case 3:
1633
                    i = HOLODUKE_ICON;
1634
                    break;
1635
                case 4:
1636
                    i = JETPACK_ICON;
1637
                    break;
1638
                case 5:
1639
                    i = HEAT_ICON;
1640
                    break;
1641
                case 6:
1642
                    i = AIRTANK_ICON;
1643
                    break;
1644
                case 7:
1645
                    i = BOOT_ICON;
1646
                    break;
5 Plagman 1647
                }
2308 helixhorne 1648
                rotatesprite_fs(sbarx(231-o),sbary(SBY+13),sbarsc(65536L),0,i,0,0,10+16+permbit);
1658 terminx 1649
                minitext(292-30-o,SBY+24,"%",6,10+16+permbit + ROTATESPRITE_MAX);
2540 hendricks2 1650
                if (p->inven_icon >= 6) minitext(284-35-o,SBY+14,"Auto",2,10+16+permbit + ROTATESPRITE_MAX);
5 Plagman 1651
            }
1652
            if (u&(2048+4096))
1653
            {
331 terminx 1654
                switch (p->inven_icon)
5 Plagman 1655
                {
337 terminx 1656
                case 3:
1657
                    j = p->holoduke_on;
1658
                    break;
1659
                case 4:
1660
                    j = p->jetpack_on;
1661
                    break;
1662
                case 5:
1663
                    j = p->heat_on;
1664
                    break;
1665
                default:
1666
                    j = 0x80000000;
5 Plagman 1667
                }
2540 hendricks2 1668
                if (j > 0) minitext(288-30-o,SBY+14,"On",0,10+16+permbit  + ROTATESPRITE_MAX);
1669
                else if ((uint32_t)j != 0x80000000) minitext(284-30-o,SBY+14,"Off",2,10+16+permbit + ROTATESPRITE_MAX);
5 Plagman 1670
            }
1671
            if (u&8192)
1672
            {
331 terminx 1673
                switch (p->inven_icon)
5 Plagman 1674
                {
337 terminx 1675
                case 1:
1572 terminx 1676
                    i = p->inv_amount[GET_FIRSTAID];
337 terminx 1677
                    break;
1678
                case 2:
1572 terminx 1679
                    i = ((p->inv_amount[GET_STEROIDS]+3)>>2);
337 terminx 1680
                    break;
1681
                case 3:
1572 terminx 1682
                    i = ((p->inv_amount[GET_HOLODUKE]+15)/24);
337 terminx 1683
                    break;
1684
                case 4:
1572 terminx 1685
                    i = ((p->inv_amount[GET_JETPACK]+15)>>4);
337 terminx 1686
                    break;
1687
                case 5:
1572 terminx 1688
                    i = p->inv_amount[GET_HEATS]/12;
337 terminx 1689
                    break;
1690
                case 6:
1572 terminx 1691
                    i = ((p->inv_amount[GET_SCUBA]+63)>>6);
337 terminx 1692
                    break;
1693
                case 7:
1572 terminx 1694
                    i = (p->inv_amount[GET_BOOTS]>>1);
337 terminx 1695
                    break;
5 Plagman 1696
                }
1205 terminx 1697
                G_DrawInvNum(284-30-o,SBY+28,(uint8_t)i,0,10+permbit);
5 Plagman 1698
            }
1699
        }
1700
    }
1701
}
1702
 
932 terminx 1703
#define COLOR_RED 248
1704
#define COLOR_WHITE 31
1120 terminx 1705
#define LOW_FPS 30
926 terminx 1706
 
1179 terminx 1707
static void G_PrintFPS(void)
933 terminx 1708
{
1062 terminx 1709
    // adapted from ZDoom because I like it better than what we had
1710
    // applicable ZDoom code available under GPL from csDoom
1205 terminx 1711
    static int32_t FrameCount = 0;
1712
    static int32_t LastCount = 0;
1713
    static int32_t LastSec = 0;
1714
    static int32_t LastMS = 0;
1715
    int32_t ms = getticks();
1716
    int32_t howlong = ms - LastMS;
1120 terminx 1717
    if (howlong >= 0)
1062 terminx 1718
    {
1205 terminx 1719
        int32_t thisSec = ms/1000;
1720
        int32_t x = (xdim <= 640);
1673 terminx 1721
 
1120 terminx 1722
        if (ud.tickrate)
1062 terminx 1723
        {
1571 terminx 1724
            int32_t chars = Bsprintf(tempbuf, "%d ms (%3u fps)", howlong, LastCount);
5 Plagman 1725
 
1089 terminx 1726
            printext256(windowx2-(chars<<(3-x))+1,windowy1+2,0,-1,tempbuf,x);
1177 terminx 1727
            printext256(windowx2-(chars<<(3-x)),windowy1+1,
1179 terminx 1728
                        (LastCount < LOW_FPS) ? COLOR_RED : COLOR_WHITE,-1,tempbuf,x);
1062 terminx 1729
 
1177 terminx 1730
            // lag meter
1587 terminx 1731
            if (g_netClientPeer)
1062 terminx 1732
            {
1593 terminx 1733
                chars = Bsprintf(tempbuf, "%d +- %d ms", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2,
1734
                                 (g_netClientPeer->lastRoundTripTimeVariance + g_netClientPeer->roundTripTimeVariance)/2);
1571 terminx 1735
 
1736
                printext256(windowx2-(chars<<(3-x))+1,windowy1+10+2,0,-1,tempbuf,x);
1587 terminx 1737
                printext256(windowx2-(chars<<(3-x)),windowy1+10+1,g_netClientPeer->lastRoundTripTime > 200 ? COLOR_RED : COLOR_WHITE,-1,tempbuf,x);
1062 terminx 1738
            }
1739
        }
1740
 
1673 terminx 1741
        if (thisSec - LastSec)
193 terminx 1742
        {
1143 terminx 1743
            g_currentFrameRate = LastCount = FrameCount / (thisSec - LastSec);
1120 terminx 1744
            LastSec = thisSec;
1745
            FrameCount = 0;
193 terminx 1746
        }
1120 terminx 1747
        FrameCount++;
5 Plagman 1748
    }
1120 terminx 1749
    LastMS = ms;
5 Plagman 1750
}
1751
 
2413 helixhorne 1752
// yxaspect and viewingrange just before the 'main' drawrooms call
1753
static int32_t dr_yxaspect, dr_viewingrange;
1754
 
1205 terminx 1755
static void G_PrintCoords(int32_t snum)
5 Plagman 1756
{
2413 helixhorne 1757
    const int32_t x = 250;
1205 terminx 1758
    int32_t y = 16;
2413 helixhorne 1759
    const int32_t sectnum = g_player[snum].ps->cursectnum;
5 Plagman 1760
 
1143 terminx 1761
    if ((GametypeFlags[ud.coop] & GAMETYPE_FRAGBAR))
5 Plagman 1762
    {
532 terminx 1763
        if (ud.multimode > 4)
1062 terminx 1764
            y = 32;
1587 terminx 1765
        else if (g_netServer || (g_netServer || ud.multimode > 1))
532 terminx 1766
            y = 24;
5 Plagman 1767
    }
1625 terminx 1768
    Bsprintf(tempbuf,"XYZ= (%d,%d,%d)",g_player[snum].ps->pos.x,g_player[snum].ps->pos.y,g_player[snum].ps->pos.z);
2413 helixhorne 1769
    printext256(x,y,31,-1,tempbuf,0);
1770
    Bsprintf(tempbuf,"A/H/HO= %d,%d,%d",g_player[snum].ps->ang,g_player[snum].ps->horiz,g_player[snum].ps->horizoff);
1771
    printext256(x,y+9,31,-1,tempbuf,0);
1802 terminx 1772
    Bsprintf(tempbuf,"ZV= %d",g_player[snum].ps->vel.z);
2413 helixhorne 1773
    printext256(x,y+18,31,-1,tempbuf,0);
1062 terminx 1774
    Bsprintf(tempbuf,"OG= %d",g_player[snum].ps->on_ground);
2413 helixhorne 1775
    printext256(x,y+27,31,-1,tempbuf,0);
1776
    if (sectnum >= 0)
1777
        Bsprintf(tempbuf,"SECT= %d (LO=%d EX=%d)",sectnum,sector[sectnum].lotag,sector[sectnum].extra);
1778
    else
1779
        Bsprintf(tempbuf,"SECT= %d", sectnum);
1780
    printext256(x,y+36,31,-1,tempbuf,0);
1781
//    Bsprintf(tempbuf,"SEED= %d",randomseed);
1782
//    printext256(x,y+45,31,-1,tempbuf,0);
1783
    y -= 9;
1784
 
1785
    y += 7;
564 terminx 1786
    Bsprintf(tempbuf,"THOLD= %d",g_player[snum].ps->transporter_hold);
2413 helixhorne 1787
    printext256(x,y+54,31,-1,tempbuf,0);
1945 helixhorne 1788
    Bsprintf(tempbuf,"GAMETIC= %d",g_moveThingsCount);
2413 helixhorne 1789
    printext256(x,y+63,31,-1,tempbuf,0);
1790
 
1791
    y += 7;
1792
    Bsprintf(tempbuf,"VR=%.03f  YX=%.03f",(double)dr_viewingrange/65536.0,(double)dr_yxaspect/65536.0);
1793
    printext256(x,y+72,31,-1,tempbuf,0);
5 Plagman 1794
}
1795
 
1143 terminx 1796
// this handles both multiplayer and item pickup message type text
1797
// both are passed on to gametext
1798
 
1677 terminx 1799
void G_PrintGameQuotes(void)
5 Plagman 1800
{
1205 terminx 1801
    int32_t i, j, k, l;
5 Plagman 1802
 
1037 terminx 1803
    k = 1;
1587 terminx 1804
    if (GTFLAGS(GAMETYPE_FRAGBAR) && ud.screen_size > 0 && (g_netServer || (g_netServer || ud.multimode > 1)))
1037 terminx 1805
    {
1806
        j = 0;
1807
        k += 8;
2379 helixhorne 1808
        for (TRAVERSE_CONNECT(i))
1809
            if (i > j) j = i;
532 terminx 1810
 
1037 terminx 1811
        if (j >= 4 && j <= 8) k += 8;
1812
        else if (j > 8 && j <= 12) k += 16;
1813
        else if (j > 12) k += 24;
1814
    }
1815
 
1802 terminx 1816
    if (g_player[screenpeek].ps->fta > 1 && (g_player[screenpeek].ps->ftq < QUOTE_RESERVED || g_player[screenpeek].ps->ftq > QUOTE_RESERVED3))
1037 terminx 1817
    {
1097 terminx 1818
        if (g_player[screenpeek].ps->fta > 6)
1819
            k += 7;
1625 terminx 1820
        else k += g_player[screenpeek].ps->fta;
1037 terminx 1821
    }
1822
 
1823
    j = k;
1824
 
1095 terminx 1825
    j = scale(j,ydim,200);
1229 terminx 1826
    for (i=MAXUSERQUOTES-1; i>=0; i--)
5 Plagman 1827
    {
2316 helixhorne 1828
        int32_t sh;
1829
 
1830
        if (user_quote_time[i] <= 0)
1831
            continue;
335 terminx 1832
        k = user_quote_time[i];
2316 helixhorne 1833
 
1834
        sh = hud_glowingquotes ? (sintable[((totalclock+(i<<2))<<5)&2047]>>11) : 0;
1835
 
1836
        if (k > 4) { mpgametext(j,user_quote[i], sh, 2+8+16); j += textsc(8); }
1837
        else if (k > 2) { mpgametext(j,user_quote[i], sh, 2+8+16+1); j += textsc(k<<1); }
1838
        else { mpgametext(j,user_quote[i], sh, 2+8+16+1+32); j += textsc(k<<1); }
1839
 
1625 terminx 1840
        l = G_GameTextLen(USERQUOTE_LEFTOFFSET,OSD_StripColors(tempbuf,user_quote[i]));
867 terminx 1841
        while (l > (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET))
85 terminx 1842
        {
867 terminx 1843
            l -= (ud.config.ScreenWidth-USERQUOTE_RIGHTOFFSET);
1095 terminx 1844
            if (k > 4) j += textsc(8);
1845
            else j += textsc(k<<1);
1037 terminx 1846
 
85 terminx 1847
        }
5 Plagman 1848
    }
1849
 
87 terminx 1850
    if ((klabs(quotebotgoal-quotebot) <= 16) && (ud.screen_size <= 8))
1851
        quotebot += ksgn(quotebotgoal-quotebot);
1852
    else
1853
        quotebot = quotebotgoal;
1854
 
564 terminx 1855
    if (g_player[screenpeek].ps->fta <= 1) return;
5 Plagman 1856
 
1143 terminx 1857
    if (ScriptQuotes[g_player[screenpeek].ps->ftq] == NULL)
437 terminx 1858
    {
909 terminx 1859
        OSD_Printf(OSD_ERROR "%s %d null quote %d\n",__FILE__,__LINE__,g_player[screenpeek].ps->ftq);
437 terminx 1860
        return;
1861
    }
1862
 
1863
    k = 0;
1037 terminx 1864
 
1802 terminx 1865
    if (g_player[screenpeek].ps->ftq >= QUOTE_RESERVED && g_player[screenpeek].ps->ftq <= QUOTE_RESERVED3)
5 Plagman 1866
    {
1037 terminx 1867
        k = 140;//quotebot-8-4;
1868
    }
1587 terminx 1869
    else if (GTFLAGS(GAMETYPE_FRAGBAR) && ud.screen_size > 0 && (g_netServer || ud.multimode > 1))
1037 terminx 1870
    {
335 terminx 1871
        j = 0;
1872
        k = 8;
2379 helixhorne 1873
        for (TRAVERSE_CONNECT(i))
1874
            if (i > j) j = i;
5 Plagman 1875
 
1876
        if (j >= 4 && j <= 8) k += 8;
1877
        else if (j > 8 && j <= 12) k += 16;
1878
        else if (j > 12) k += 24;
1879
    }
1880
 
564 terminx 1881
    j = g_player[screenpeek].ps->fta;
2316 helixhorne 1882
    l = hud_glowingquotes ? quotepulseshade : 0;
1883
    // flags:
1884
    if (j > 4) i = 2+8+16;
1885
    else if (j > 2) i = 2+8+16+1;
1886
    else i = 2+8+16+1+32;
1887
 
1888
    gametext(320>>1,k,ScriptQuotes[g_player[screenpeek].ps->ftq], l, i);
5 Plagman 1889
}
1890
 
1205 terminx 1891
void P_DoQuote(int32_t q, DukePlayer_t *p)
5 Plagman 1892
{
1205 terminx 1893
    int32_t cq = 0;
868 terminx 1894
 
1895
    if (q & MAXQUOTES)
5 Plagman 1896
    {
868 terminx 1897
        cq = 1;
1898
        q &= ~MAXQUOTES;
1899
    }
1900
 
1143 terminx 1901
    if (ScriptQuotes[q] == NULL)
868 terminx 1902
    {
909 terminx 1903
        OSD_Printf(OSD_ERROR "%s %d null quote %d\n",__FILE__,__LINE__,q);
437 terminx 1904
        return;
1905
    }
5 Plagman 1906
 
437 terminx 1907
    if (ud.fta_on == 0)
1908
        return;
465 terminx 1909
 
1802 terminx 1910
    if (p->fta > 0 && q != QUOTE_RESERVED && q != QUOTE_RESERVED2)
1911
        if (p->ftq == QUOTE_RESERVED || p->ftq == QUOTE_RESERVED2) return;
5 Plagman 1912
 
437 terminx 1913
    p->fta = 100;
392 terminx 1914
 
1625 terminx 1915
    if (p->ftq != q)
437 terminx 1916
    {
1989 hendricks2 1917
        if (p == g_player[screenpeek].ps
1918
            && Bstrcmp(ScriptQuotes[q],"")) // avoid printing blank quotes
1625 terminx 1919
        {
1920
            if (cq) OSD_Printf(OSDTEXT_BLUE "%s\n",ScriptQuotes[q]);
1921
            else OSD_Printf("%s\n",ScriptQuotes[q]);
1922
        }
437 terminx 1923
 
1924
        p->ftq = q;
335 terminx 1925
    }
1625 terminx 1926
    pub = NUMPAGES;
1927
    pus = NUMPAGES;
5 Plagman 1928
}
1929
 
1625 terminx 1930
void G_FadePalette(int32_t r,int32_t g,int32_t b,int32_t e)
1931
{
1932
    setpalettefade(r,g,b,e&63);
1933
 
1934
//    if (getrendermode() >= 3) pus = pub = NUMPAGES; // JBF 20040110: redraw the status bar next time
1935
    if ((e&128) == 0)
1936
    {
1937
        int32_t tc;
1969 helixhorne 1938
 
1625 terminx 1939
        nextpage();
1969 helixhorne 1940
        tc = totalclock;
1941
        while (totalclock < tc + 4)
1942
        {
1943
            handleevents();
1944
            Net_GetPackets();
1945
        }
1625 terminx 1946
    }
1947
}
1948
 
1205 terminx 1949
void fadepal(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, int32_t step)
398 terminx 1950
{
1918 terminx 1951
    if (getrendermode() >= 3)
1952
    {
1953
        G_FadePalette(r, g, b, end);
1954
        return;
1955
    }
1909 terminx 1956
 
1625 terminx 1957
    if (step > 0)
1958
    {
1959
        for (; start < end; start += step)
1960
        {
1961
            if (KB_KeyPressed(sc_Space))
1962
            {
1963
                KB_ClearKeyDown(sc_Space);
1964
                return;
1965
            }
1966
            G_FadePalette(r,g,b,start);
1967
        }
1968
    }
1969
    else for (; start >= end; start += step)
1970
        {
1677 terminx 1971
            if (KB_KeyPressed(sc_Space))
1972
            {
1973
                KB_ClearKeyDown(sc_Space);
1974
                return;
1975
            }
1976
            G_FadePalette(r,g,b,start);
1625 terminx 1977
        }
398 terminx 1978
}
1979
 
2265 helixhorne 1980
static void fadepaltile(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, int32_t step, int32_t tile)
1625 terminx 1981
{
1982
    if (step > 0)
1983
    {
1984
        for (; start < end; start += step)
1985
        {