Subversion Repositories eduke32

Rev

Rev 693 | Rev 762 | Go to most recent revision | 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
 
25
#include "duke3d.h"
26
#include "osd.h"
27
 
514 terminx 28
#ifdef RENDERTYPEWIN
29
#define WIN32_LEAN_AND_MEAN
30
#include <windows.h>
31
#endif
32
 
5 Plagman 33
extern char pow2char[];
34
 
528 terminx 35
extern int everyothertime;
36
static int which_palookup = 9;
564 terminx 37
int g_NumPalettes;
5 Plagman 38
short spritecache[MAXTILES][3];
39
 
40
static char precachehightile[2][MAXTILES>>3];
41
static int  precachecount;
42
 
528 terminx 43
static void tloadtile(int tilenume, int type)
5 Plagman 44
{
423 terminx 45
    if ((picanm[tilenume]&63) < 1)
335 terminx 46
    {
423 terminx 47
        if (!(gotpic[tilenume>>3] & pow2char[tilenume&7])) precachecount++;
48
        gotpic[tilenume>>3] |= pow2char[tilenume&7];
49
        precachehightile[(unsigned char)type][tilenume>>3] |= pow2char[tilenume&7];
50
        return;
51
    }
52
 
53
    {
29 terminx 54
        int i,j;
5 Plagman 55
 
335 terminx 56
        if ((picanm[tilenume]&192)==192)
57
        {
29 terminx 58
            i = tilenume - (picanm[tilenume]&63);
59
            j = tilenume;
335 terminx 60
        }
61
        else
62
        {
29 terminx 63
            i = tilenume;
64
            j = tilenume + (picanm[tilenume]&63);
65
        }
335 terminx 66
        for (;i<=j;i++)
67
        {
29 terminx 68
            if (!(gotpic[i>>3] & pow2char[i&7])) precachecount++;
69
            gotpic[i>>3] |= pow2char[i&7];
352 terminx 70
            precachehightile[(unsigned char)type][i>>3] |= pow2char[i&7];
29 terminx 71
        }
335 terminx 72
    }
5 Plagman 73
}
74
 
528 terminx 75
static void cachespritenum(int i)
5 Plagman 76
{
77
    char maxc;
528 terminx 78
    int j;
5 Plagman 79
 
331 terminx 80
    if (ud.monsters_off && badguy(&sprite[i])) return;
5 Plagman 81
 
82
    maxc = 1;
83
 
331 terminx 84
    if (spritecache[PN][0] == PN)
85
        for (j = PN; j <= spritecache[PN][1]; j++)
5 Plagman 86
            tloadtile(j,1);
87
 
331 terminx 88
    switch (dynamictostatic[PN])
5 Plagman 89
    {
337 terminx 90
    case HYDRENT__STATIC:
91
        tloadtile(BROKEFIREHYDRENT,1);
92
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
93
        break;
94
    case TOILET__STATIC:
95
        tloadtile(TOILETBROKE,1);
96
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
97
        break;
98
    case STALL__STATIC:
99
        tloadtile(STALLBROKE,1);
100
        for (j = TOILETWATER; j < (TOILETWATER+4); j++) tloadtile(j,1);
101
        break;
102
    case RUBBERCAN__STATIC:
103
        maxc = 2;
104
        break;
105
    case TOILETWATER__STATIC:
106
        maxc = 4;
107
        break;
108
    case FEMPIC1__STATIC:
109
        maxc = 44;
110
        break;
111
    case LIZTROOP__STATIC:
112
    case LIZTROOPRUNNING__STATIC:
113
    case LIZTROOPSHOOT__STATIC:
114
    case LIZTROOPJETPACK__STATIC:
115
    case LIZTROOPONTOILET__STATIC:
116
    case LIZTROOPDUCKING__STATIC:
117
        for (j = LIZTROOP; j < (LIZTROOP+72); j++) tloadtile(j,1);
118
        for (j=HEADJIB1;j<LEGJIB1+3;j++) tloadtile(j,1);
119
        maxc = 0;
120
        break;
121
    case WOODENHORSE__STATIC:
122
        maxc = 5;
123
        for (j = HORSEONSIDE; j < (HORSEONSIDE+4); j++) tloadtile(j,1);
124
        break;
125
    case NEWBEAST__STATIC:
126
    case NEWBEASTSTAYPUT__STATIC:
127
        maxc = 90;
128
        break;
129
    case BOSS1__STATIC:
130
    case BOSS2__STATIC:
131
    case BOSS3__STATIC:
132
        maxc = 30;
133
        break;
134
    case OCTABRAIN__STATIC:
135
    case OCTABRAINSTAYPUT__STATIC:
136
    case COMMANDER__STATIC:
137
    case COMMANDERSTAYPUT__STATIC:
138
        maxc = 38;
139
        break;
140
    case RECON__STATIC:
141
        maxc = 13;
142
        break;
143
    case PIGCOP__STATIC:
144
    case PIGCOPDIVE__STATIC:
145
        maxc = 61;
146
        break;
147
    case SHARK__STATIC:
148
        maxc = 30;
149
        break;
150
    case LIZMAN__STATIC:
151
    case LIZMANSPITTING__STATIC:
152
    case LIZMANFEEDING__STATIC:
153
    case LIZMANJUMP__STATIC:
154
        for (j=LIZMANHEAD1;j<LIZMANLEG1+3;j++) tloadtile(j,1);
155
        maxc = 80;
156
        break;
157
    case APLAYER__STATIC:
158
        maxc = 0;
159
        if (ud.multimode > 1)
160
        {
5 Plagman 161
            maxc = 5;
337 terminx 162
            for (j = 1420;j < 1420+106; j++) tloadtile(j,1);
163
        }
164
        break;
165
    case ATOMICHEALTH__STATIC:
166
        maxc = 14;
167
        break;
168
    case DRONE__STATIC:
169
        maxc = 10;
170
        break;
171
    case EXPLODINGBARREL__STATIC:
172
    case SEENINE__STATIC:
173
    case OOZFILTER__STATIC:
174
        maxc = 3;
175
        break;
176
    case NUKEBARREL__STATIC:
177
    case CAMERA1__STATIC:
178
        maxc = 5;
179
        break;
180
        // caching of HUD sprites for weapons that may be in the level
181
    case CHAINGUNSPRITE__STATIC:
182
        for (j=CHAINGUN; j<=CHAINGUN+7; j++) tloadtile(j,1);
183
        break;
184
    case RPGSPRITE__STATIC:
185
        for (j=RPGGUN; j<=RPGGUN+2; j++) tloadtile(j,1);
186
        break;
187
    case FREEZESPRITE__STATIC:
188
        for (j=FREEZE; j<=FREEZE+5; j++) tloadtile(j,1);
189
        break;
190
    case GROWSPRITEICON__STATIC:
191
    case SHRINKERSPRITE__STATIC:
192
        for (j=SHRINKER-2; j<=SHRINKER+5; j++) tloadtile(j,1);
193
        break;
194
    case HBOMBAMMO__STATIC:
195
    case HEAVYHBOMB__STATIC:
196
        for (j=HANDREMOTE; j<=HANDREMOTE+5; j++) tloadtile(j,1);
197
        break;
198
    case TRIPBOMBSPRITE__STATIC:
199
        for (j=HANDHOLDINGLASER; j<=HANDHOLDINGLASER+4; j++) tloadtile(j,1);
200
        break;
201
    case SHOTGUNSPRITE__STATIC:
202
        tloadtile(SHOTGUNSHELL,1);
203
        for (j=SHOTGUN; j<=SHOTGUN+6; j++) tloadtile(j,1);
204
        break;
205
    case DEVISTATORSPRITE__STATIC:
206
        for (j=DEVISTATOR; j<=DEVISTATOR+1; j++) tloadtile(j,1);
207
        break;
5 Plagman 208
 
209
    }
210
 
331 terminx 211
    for (j = PN; j < (PN+maxc); j++) tloadtile(j,1);
5 Plagman 212
}
213
 
395 terminx 214
static void cachegoodsprites(void)
5 Plagman 215
{
528 terminx 216
    int i,j;
5 Plagman 217
 
331 terminx 218
    for (i=0;i<MAXTILES;i++)
5 Plagman 219
    {
331 terminx 220
        if (spriteflags[i] & SPRITE_FLAG_PROJECTILE)
5 Plagman 221
            tloadtile(i,1);
331 terminx 222
        if (spritecache[i][0] == i && spritecache[i][2])
223
            for (j = i; j <= spritecache[i][1]; j++)
5 Plagman 224
                tloadtile(j,1);
225
    }
226
    tloadtile(BOTTOMSTATUSBAR,1);
333 terminx 227
    if (ud.multimode > 1)
5 Plagman 228
        tloadtile(FRAGBAR,1);
229
 
230
    tloadtile(VIEWSCREEN,1);
231
 
331 terminx 232
    for (i=STARTALPHANUM;i<ENDALPHANUM+1;i++) tloadtile(i,1);
233
    for (i=BIGALPHANUM; i<BIGALPHANUM+82; i++) tloadtile(i,1);
234
    for (i=MINIFONT;i<MINIFONT+63;i++) tloadtile(i,1);
5 Plagman 235
 
331 terminx 236
    for (i=FOOTPRINTS;i<FOOTPRINTS+3;i++) tloadtile(i,1);
5 Plagman 237
 
333 terminx 238
    for (i = BURNING; i < BURNING+14; i++) tloadtile(i,1);
239
    for (i = BURNING2; i < BURNING2+14; i++) tloadtile(i,1);
5 Plagman 240
 
333 terminx 241
    for (i = CRACKKNUCKLES; i < CRACKKNUCKLES+4; i++) tloadtile(i,1);
5 Plagman 242
 
333 terminx 243
    for (i = FIRSTGUN; i < FIRSTGUN+3 ; i++) tloadtile(i,1);
244
    for (i = FIRSTGUNRELOAD; i < FIRSTGUNRELOAD+8 ; i++) tloadtile(i,1);
5 Plagman 245
 
333 terminx 246
    for (i = EXPLOSION2; i < EXPLOSION2+21 ; i++) tloadtile(i,1);
5 Plagman 247
 
511 terminx 248
    for (i = COOLEXPLOSION1; i < COOLEXPLOSION1+21 ; i++) tloadtile(i,1);
249
 
5 Plagman 250
    tloadtile(BULLETHOLE,1);
511 terminx 251
    tloadtile(BLOODPOOL,1);
252
    for (i = TRANSPORTERBEAM; i < (TRANSPORTERBEAM+6); i++) tloadtile(i,1);
522 terminx 253
 
333 terminx 254
    for (i = SMALLSMOKE; i < (SMALLSMOKE+4); i++) tloadtile(i,1);
710 terminx 255
    for (i = SHOTSPARK1; i < (SHOTSPARK1+4); i++) tloadtile(i,1);
5 Plagman 256
 
511 terminx 257
    for (i = BLOOD; i < (BLOOD+4); i++) tloadtile(i,1);
333 terminx 258
    for (i = JIBS1; i < (JIBS5+5); i++) tloadtile(i,1);
710 terminx 259
    for (i = JIBS6; i < (JIBS6+8); i++) tloadtile(i,1);
260
 
511 terminx 261
    for (i = SCRAP1; i < (SCRAP1+29); i++) tloadtile(i,1);
5 Plagman 262
 
511 terminx 263
    tloadtile(FIRELASER,1);
264
    for (i=FORCERIPPLE; i<(FORCERIPPLE+9); i++) tloadtile(i,1);
265
 
266
    for (i=MENUSCREEN; i<DUKECAR; i++) tloadtile(i,1);
522 terminx 267
 
5 Plagman 268
    for (i=RPG; i<RPG+7; i++) tloadtile(i,1);
269
    for (i=FREEZEBLAST; i<FREEZEBLAST+3; i++) tloadtile(i,1);
270
    for (i=SHRINKSPARK; i<SHRINKSPARK+4; i++) tloadtile(i,1);
271
    for (i=GROWSPARK; i<GROWSPARK+4; i++) tloadtile(i,1);
272
    for (i=SHRINKEREXPLOSION; i<SHRINKEREXPLOSION+4; i++) tloadtile(i,1);
273
    for (i=MORTER; i<MORTER+4; i++) tloadtile(i,4);
274
}
275
 
528 terminx 276
static int getsound(unsigned int num)
5 Plagman 277
{
634 terminx 278
    short fp = -1;
584 terminx 279
    int   l;
5 Plagman 280
 
581 terminx 281
    if (num >= MAXSOUNDS || ud.config.SoundToggle == 0) return 0;
563 terminx 282
    if (ud.config.FXDevice < 0) return 0;
5 Plagman 283
 
580 terminx 284
    if (!g_sounds[num].filename) return 0;
640 terminx 285
    if (g_sounds[num].filename1)fp = kopen4load(g_sounds[num].filename1,loadfromgrouponly);
634 terminx 286
    if (fp == -1)fp = kopen4load(g_sounds[num].filename,loadfromgrouponly);
331 terminx 287
    if (fp == -1) return 0;
5 Plagman 288
 
333 terminx 289
    l = kfilelength(fp);
580 terminx 290
    g_sounds[num].soundsiz = l;
5 Plagman 291
 
333 terminx 292
    if ((ud.level_number == 0 && ud.volume_number == 0 && (num == 189 || num == 232 || num == 99 || num == 233 || num == 17)) ||
293
            (l < 12288))
5 Plagman 294
    {
580 terminx 295
        g_sounds[num].lock = 199;
584 terminx 296
        allocache((int *)&g_sounds[num].ptr,l,(char *)&g_sounds[num].lock);
580 terminx 297
        if (g_sounds[num].ptr != NULL)
298
            kread(fp, g_sounds[num].ptr , l);
5 Plagman 299
    }
333 terminx 300
    kclose(fp);
5 Plagman 301
    return 1;
302
}
303
 
395 terminx 304
static void precachenecessarysounds(void)
5 Plagman 305
{
528 terminx 306
    int i, j;
5 Plagman 307
 
563 terminx 308
    if (ud.config.FXDevice < 0) return;
5 Plagman 309
    j = 0;
310
 
581 terminx 311
    for (i=0;i<MAXSOUNDS;i++)
580 terminx 312
        if (g_sounds[i].ptr == 0)
5 Plagman 313
        {
314
            j++;
333 terminx 315
            if ((j&7) == 0)
335 terminx 316
            {
317
                handleevents();
318
                getpackets();
319
            }
5 Plagman 320
            getsound(i);
321
        }
322
}
323
 
398 terminx 324
static void dofrontscreens(char *statustext)
325
{
584 terminx 326
    int i=0,j;
398 terminx 327
 
328
    if (ud.recstat != 2)
329
    {
330
        if (!statustext)
331
        {
564 terminx 332
            //g_player[myconnectindex].ps->palette = palette;
333
            setgamepalette(g_player[myconnectindex].ps, palette, 1);    // JBF 20040308
398 terminx 334
            fadepal(0,0,0, 0,64,7);
335
            i = ud.screen_size;
336
            ud.screen_size = 0;
337
            vscrn();
338
            clearview(0L);
339
        }
340
 
341
        SetGameVarID(g_iReturnVarID,LOADSCREEN, -1, -1);
342
        OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1);
343
        j = GetGameVarID(g_iReturnVarID, -1, -1);
344
        rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64,0,0,xdim-1,ydim-1);
345
        if (j > MAXTILES-1)
346
        {
347
            nextpage();
348
            return;
349
        }
350
        if (boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0)
351
        {
352
            menutext(160,90,0,0,"ENTERING USER MAP");
353
            gametextpal(160,90+10,boardfilename,14,2);
354
        }
355
        else
356
        {
357
            menutext(160,90,0,0,"ENTERING");
562 terminx 358
            if (map[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL)
359
                menutext(160,90+16+8,0,0,map[(ud.volume_number*MAXLEVELS) + ud.level_number].name);
398 terminx 360
        }
361
 
362
        if (statustext) gametext(160,180,statustext,0,2+8+16);
363
 
364
        nextpage();
365
 
366
        if (!statustext)
367
        {
368
            fadepal(0,0,0, 63,0,-7);
369
 
370
            KB_FlushKeyboardQueue();
371
            ud.screen_size = i;
372
        }
373
    }
374
    else
375
    {
376
        if (!statustext)
377
        {
378
            clearview(0L);
564 terminx 379
            //g_player[myconnectindex].ps->palette = palette;
398 terminx 380
            //palto(0,0,0,0);
564 terminx 381
            setgamepalette(g_player[myconnectindex].ps, palette, 0);    // JBF 20040308
398 terminx 382
        }
383
        SetGameVarID(g_iReturnVarID,LOADSCREEN, -1, -1);
384
        OnEvent(EVENT_GETLOADTILE, -1, myconnectindex, -1);
385
        j = GetGameVarID(g_iReturnVarID, -1, -1);
386
        rotatesprite(320<<15,200<<15,65536L,0,j > MAXTILES-1?j-MAXTILES:j,0,0,2+8+64,0,0,xdim-1,ydim-1);
387
        if (j > MAXTILES-1)
388
        {
389
            nextpage();
390
            return;
391
        }
392
        menutext(160,105,0,0,"LOADING...");
393
        if (statustext) gametext(160,180,statustext,0,2+8+16);
394
        nextpage();
395
    }
396
}
397
 
5 Plagman 398
void cacheit(void)
399
{
584 terminx 400
    int i,j,k, pc=0;
401
    int tc;
402
    unsigned int starttime, endtime;
5 Plagman 403
 
331 terminx 404
    if (ud.recstat == 2)
29 terminx 405
        return;
406
 
693 terminx 407
    MUSIC_Pause();
408
    if (map[MAXVOLUMES*MAXLEVELS+2].musicfn1)
409
    {
410
        MUSIC_StopSong();
411
        playmusic(&env_music_fn[2][0],MAXVOLUMES*MAXLEVELS+2); // loadmus
412
    }
645 terminx 413
 
29 terminx 414
    starttime = getticks();
415
 
5 Plagman 416
    precachenecessarysounds();
417
 
418
    cachegoodsprites();
419
 
331 terminx 420
    for (i=0;i<numwalls;i++)
5 Plagman 421
    {
422
        tloadtile(wall[i].picnum, 0);
423
 
335 terminx 424
        if (wall[i].overpicnum >= 0)
425
        {
5 Plagman 426
            tloadtile(wall[i].overpicnum, 0);
427
        }
428
    }
429
 
331 terminx 430
    for (i=0;i<numsectors;i++)
5 Plagman 431
    {
333 terminx 432
        tloadtile(sector[i].floorpicnum, 0);
433
        tloadtile(sector[i].ceilingpicnum, 0);
434
        if (sector[i].ceilingpicnum == LA)  // JBF 20040509: if( waloff[sector[i].ceilingpicnum] == LA) WTF??!??!?!?
5 Plagman 435
        {
436
            tloadtile(LA+1, 0);
437
            tloadtile(LA+2, 0);
438
        }
439
 
440
        j = headspritesect[i];
331 terminx 441
        while (j >= 0)
5 Plagman 442
        {
331 terminx 443
            if (sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0)
5 Plagman 444
                cachespritenum(j);
445
            j = nextspritesect[j];
446
        }
447
    }
448
 
29 terminx 449
    tc = totalclock;
5 Plagman 450
    j = 0;
451
 
335 terminx 452
    for (i=0;i<MAXTILES;i++)
453
    {
454
        if (!(i&7) && !gotpic[i>>3])
455
        {
29 terminx 456
            i+=7;
457
            continue;
458
        }
335 terminx 459
        if (gotpic[i>>3] & pow2char[i&7])
460
        {
29 terminx 461
            if (waloff[i] == 0)
462
                loadtile((short)i);
5 Plagman 463
 
263 terminx 464
#if defined(POLYMOST) && defined(USE_OPENGL)
563 terminx 465
            if (ud.config.useprecache)
335 terminx 466
            {
29 terminx 467
                if (precachehightile[0][i>>3] & pow2char[i&7])
521 terminx 468
                    for (k=0; k<MAXPALOOKUPS && !KB_KeyPressed(sc_Space); k++)
29 terminx 469
                        polymost_precache(i,k,0);
5 Plagman 470
 
29 terminx 471
                if (precachehightile[1][i>>3] & pow2char[i&7])
521 terminx 472
                    for (k=0; k<MAXPALOOKUPS && !KB_KeyPressed(sc_Space); k++)
29 terminx 473
                        polymost_precache(i,k,1);
474
            }
259 terminx 475
#endif
29 terminx 476
            j++;
477
            pc++;
335 terminx 478
        }
479
        else continue;
5 Plagman 480
 
335 terminx 481
        if ((j&7) == 0)
482
        {
483
            handleevents();
484
            getpackets();
485
        }
486
        if (totalclock - tc > TICRATE/4)
487
        {
584 terminx 488
            sprintf(tempbuf,"Loading resources... %d%%\n",min(100,100*pc/precachecount));
29 terminx 489
            dofrontscreens(tempbuf);
490
            tc = totalclock;
491
        }
5 Plagman 492
    }
493
 
494
    clearbufbyte(gotpic,sizeof(gotpic),0L);
495
 
29 terminx 496
    endtime = getticks();
497
    OSD_Printf("Cache time: %dms\n", endtime-starttime);
5 Plagman 498
}
499
 
509 terminx 500
void xyzmirror(int i,int wn)
5 Plagman 501
{
502
    //if (waloff[wn] == 0) loadtile(wn);
503
    setviewtotile(wn,tilesizy[wn],tilesizx[wn]);
504
 
505
    drawrooms(SX,SY,SZ,SA,100+sprite[i].shade,SECT);
335 terminx 506
    display_mirror = 1;
507
    animatesprites(SX,SY,SA,65536L);
508
    display_mirror = 0;
5 Plagman 509
    drawmasks();
510
 
511
    setviewback();
512
    squarerotatetile(wn);
513
    invalidatetile(wn,-1,255);
514
}
515
 
516
void vscrn(void)
517
{
584 terminx 518
    int i, j, ss, x1, x2, y1, y2;
5 Plagman 519
 
331 terminx 520
    if (ud.screen_size < 0) ud.screen_size = 0;
423 terminx 521
    if (ud.screen_size > 64) ud.screen_size = 64;
331 terminx 522
    if (ud.screen_size == 0) flushperms();
5 Plagman 523
 
524
    ss = max(ud.screen_size-8,0);
525
 
526
    x1 = scale(ss,xdim,160);
527
    x2 = xdim-x1;
528
 
335 terminx 529
    y1 = ss;
530
    y2 = 200;
333 terminx 531
    if (ud.screen_size > 0 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_FRAGBAR) && ud.multimode > 1)
5 Plagman 532
    {
533
        j = 0;
331 terminx 534
        for (i=connecthead;i>=0;i=connectpoint2[i])
535
            if (i > j) j = i;
5 Plagman 536
 
537
        if (j >= 1) y1 += 8;
538
        if (j >= 4) y1 += 8;
539
        if (j >= 8) y1 += 8;
540
        if (j >= 12) y1 += 8;
541
    }
542
 
423 terminx 543
    if (ud.screen_size >= 8 && !(ud.screen_size == 8 && ud.statusbarmode && bpp > 8))
544
        y2 -= (ss+scale(tilesizy[BOTTOMSTATUSBAR],ud.statusbarscale,100));
5 Plagman 545
 
546
    y1 = scale(y1,ydim,200);
547
    y2 = scale(y2,ydim,200);
548
 
549
    setview(x1,y1,x2-1,y2-1);
550
 
551
    pub = NUMPAGES;
552
    pus = NUMPAGES;
553
}
554
 
432 terminx 555
void pickrandomspot(int snum)
5 Plagman 556
{
564 terminx 557
    player_struct *p = g_player[snum].ps;
432 terminx 558
    int i=snum,j,k;
584 terminx 559
    unsigned int dist,pdist = -1;
5 Plagman 560
 
333 terminx 561
    if (ud.multimode > 1 && !(gametype_flags[ud.coop] & GAMETYPE_FLAG_FIXEDRESPAWN))
268 terminx 562
    {
423 terminx 563
        i = TRAND%numplayersprites;
331 terminx 564
        if (gametype_flags[ud.coop] & GAMETYPE_FLAG_TDMSPAWN)
268 terminx 565
        {
331 terminx 566
            for (j=0;j<ud.multimode;j++)
268 terminx 567
            {
564 terminx 568
                if (j != snum && g_player[j].ps->team == g_player[snum].ps->team && sprite[g_player[j].ps->i].extra > 0)
268 terminx 569
                {
331 terminx 570
                    for (k=0;k<numplayersprites;k++)
268 terminx 571
                    {
564 terminx 572
                        dist = FindDistance2D(g_player[j].ps->posx-g_PlayerSpawnPoints[k].ox,g_player[j].ps->posy-g_PlayerSpawnPoints[k].oy);
331 terminx 573
                        if (dist < pdist)
268 terminx 574
                            i = k, pdist = dist;
575
                    }
576
                    break;
577
                }
578
            }
335 terminx 579
        }
268 terminx 580
    }
5 Plagman 581
 
564 terminx 582
    p->bobposx = p->oposx = p->posx = g_PlayerSpawnPoints[i].ox;
583
    p->bobposy = p->oposy = p->posy = g_PlayerSpawnPoints[i].oy;
584
    p->oposz = p->posz = g_PlayerSpawnPoints[i].oz;
585
    p->ang = g_PlayerSpawnPoints[i].oa;
586
    p->cursectnum = g_PlayerSpawnPoints[i].os;
5 Plagman 587
}
588
 
432 terminx 589
static void resetplayerstats(int snum)
5 Plagman 590
{
564 terminx 591
    player_struct *p = g_player[snum].ps;
5 Plagman 592
 
593
    ud.show_help        = 0;
594
    ud.showallmap       = 0;
595
    p->dead_flag        = 0;
596
    p->wackedbyactor    = -1;
597
    p->falling_counter  = 0;
598
    p->quick_kick       = 0;
599
    p->subweapon        = 0;
600
    p->last_full_weapon = 0;
601
    p->ftq              = 0;
602
    p->fta              = 0;
603
    p->tipincs          = 0;
604
    p->buttonpalette    = 0;
605
    p->actorsqu         =-1;
606
    p->invdisptime      = 0;
607
    p->refresh_inventory= 0;
608
    p->last_pissed_time = 0;
609
    p->holster_weapon   = 0;
610
    p->pycount          = 0;
611
    p->pyoff            = 0;
612
    p->opyoff           = 0;
613
    p->loogcnt          = 0;
614
    p->angvel           = 0;
615
    p->weapon_sway      = 0;
616
    //    p->select_dir       = 0;
617
    p->extra_extra8     = 0;
618
    p->show_empty_weapon= 0;
619
    p->dummyplayersprite=-1;
620
    p->crack_time       = 0;
621
    p->hbomb_hold_delay = 0;
622
    p->transporter_hold = 0;
623
    p->wantweaponfire  = -1;
624
    p->hurt_delay       = 0;
625
    p->footprintcount   = 0;
626
    p->footprintpal     = 0;
627
    p->footprintshade   = 0;
628
    p->jumping_toggle   = 0;
629
    p->ohoriz = p->horiz= 140;
630
    p->horizoff         = 0;
631
    p->bobcounter       = 0;
632
    p->on_ground        = 0;
633
    p->player_par       = 0;
634
    p->return_to_center = 9;
635
    p->airleft          = 15*26;
636
    p->rapid_fire_hold  = 0;
637
    p->toggle_key_flag  = 0;
638
    p->access_spritenum = -1;
331 terminx 639
    if (ud.multimode > 1 && (gametype_flags[ud.coop] & GAMETYPE_FLAG_ACCESSATSTART))
5 Plagman 640
        p->got_access = 7;
641
    else p->got_access      = 0;
642
    p->random_club_frame= 0;
643
    pus = 1;
644
    p->on_warping_sector = 0;
645
    p->spritebridge      = 0;
646
    p->sbs          = 0;
647
    p->palette = (char *) &palette[0];
648
 
333 terminx 649
    if (p->steroids_amount < 400)
5 Plagman 650
    {
651
        p->steroids_amount = 0;
652
        p->inven_icon = 0;
653
    }
654
    p->heat_on =            0;
655
    p->jetpack_on =         0;
656
    p->holoduke_on =       -1;
657
 
658
    p->look_ang          = 512 - ((ud.level_number&1)<<10);
659
 
660
    p->rotscrnang        = 0;
661
    p->orotscrnang       = 1;   // JBF 20031220
662
    p->newowner          =-1;
663
    p->jumping_counter   = 0;
664
    p->hard_landing      = 0;
665
    p->posxv             = 0;
666
    p->posyv             = 0;
667
    p->poszv             = 0;
668
    fricxv            = 0;
669
    fricyv            = 0;
670
    p->somethingonplayer =-1;
671
    p->one_eighty_count  = 0;
672
    p->cheat_phase       = 0;
673
 
674
    p->on_crane          = -1;
675
 
333 terminx 676
    if ((aplWeaponWorksLike[p->curr_weapon][snum] == PISTOL_WEAPON) &&
677
            (aplWeaponReload[p->curr_weapon][snum] > aplWeaponTotalTime[p->curr_weapon][snum]))
5 Plagman 678
        p->kickback_pic  = aplWeaponTotalTime[p->curr_weapon][snum]+1;
679
    else p->kickback_pic = 0;
680
 
681
    p->weapon_pos        = 6;
682
    p->walking_snd_toggle= 0;
683
    p->weapon_ang        = 0;
684
 
685
    p->knuckle_incs      = 1;
686
    p->fist_incs = 0;
687
    p->knee_incs         = 0;
688
    p->jetpack_on        = 0;
689
    p->reloading        = 0;
690
 
172 terminx 691
    p->movement_lock     = 0;
5 Plagman 692
 
693
    setpal(p);
694
    OnEvent(EVENT_RESETPLAYER, p->i, snum, -1);
695
}
696
 
432 terminx 697
void resetweapons(int snum)
5 Plagman 698
{
432 terminx 699
    int weapon;
564 terminx 700
    player_struct *p = g_player[snum].ps;
5 Plagman 701
 
333 terminx 702
    for (weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++)
5 Plagman 703
        p->gotweapon[weapon] = 0;
333 terminx 704
    for (weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++)
5 Plagman 705
        p->ammo_amount[weapon] = 0;
706
 
707
    p->weapon_pos = 6;
708
    p->kickback_pic = 5;
709
    p->curr_weapon = PISTOL_WEAPON;
710
    p->gotweapon[PISTOL_WEAPON] = 1;
711
    p->gotweapon[KNEE_WEAPON] = 1;
712
    p->ammo_amount[PISTOL_WEAPON] = 48;
713
    p->gotweapon[HANDREMOTE_WEAPON] = 1;
714
    p->last_weapon = -1;
715
 
716
    p->show_empty_weapon= 0;
717
    p->last_pissed_time = 0;
718
    p->holster_weapon = 0;
719
    OnEvent(EVENT_RESETWEAPONS, p->i, snum, -1);
720
}
721
 
432 terminx 722
void resetinventory(int snum)
5 Plagman 723
{
564 terminx 724
    player_struct *p = g_player[snum].ps;
5 Plagman 725
 
726
    p->inven_icon       = 0;
727
    p->boot_amount = 0;
335 terminx 728
    p->scuba_on =           0;
729
    p->scuba_amount =         0;
730
    p->heat_amount        = 0;
731
    p->heat_on = 0;
732
    p->jetpack_on =         0;
733
    p->jetpack_amount =       0;
566 terminx 734
    p->shield_amount =      start_armour_amount;
5 Plagman 735
    p->holoduke_on = -1;
736
    p->holoduke_amount =    0;
737
    p->firstaid_amount = 0;
738
    p->steroids_amount = 0;
739
    p->inven_icon = 0;
740
    OnEvent(EVENT_RESETINVENTORY, p->i, snum, -1);
741
}
742
 
432 terminx 743
static void resetprestat(int snum,int g)
5 Plagman 744
{
564 terminx 745
    player_struct *p = g_player[snum].ps;
432 terminx 746
    int i;
5 Plagman 747
 
748
    spriteqloc = 0;
331 terminx 749
    for (i=0;i<spriteqamount;i++) spriteq[i] = -1;
5 Plagman 750
 
751
    p->hbomb_on          = 0;
752
    p->cheat_phase       = 0;
753
    p->pals_time         = 0;
754
    p->toggle_key_flag   = 0;
755
    p->secret_rooms      = 0;
756
    p->max_secret_rooms  = 0;
757
    p->actors_killed     = 0;
758
    p->max_actors_killed = 0;
759
    p->lastrandomspot = 0;
760
    p->weapon_pos = 6;
761
    p->kickback_pic = 5;
762
    p->last_weapon = -1;
763
    p->weapreccnt = 0;
764
    p->interface_toggle_flag = 0;
765
    p->show_empty_weapon= 0;
766
    p->holster_weapon = 0;
767
    p->last_pissed_time = 0;
768
 
769
    p->one_parallax_sectnum = -1;
770
    p->visibility = ud.const_visibility;
771
 
772
    screenpeek              = myconnectindex;
773
    numanimwalls            = 0;
774
    numcyclers              = 0;
775
    animatecnt              = 0;
776
    parallaxtype            = 0;
777
    randomseed              = 17L;
778
    ud.pause_on             = 0;
779
    ud.camerasprite         =-1;
780
    ud.eog                  = 0;
781
    tempwallptr             = 0;
782
    camsprite               =-1;
783
    earthquaketime          = 0;
784
 
785
    numinterpolations = 0;
786
    startofdynamicinterpolations = 0;
787
 
333 terminx 788
    if (((g&MODE_EOL) != MODE_EOL && numplayers < 2) || (!(gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && numplayers > 1))
5 Plagman 789
    {
790
        resetweapons(snum);
791
        resetinventory(snum);
792
    }
331 terminx 793
    else if (p->curr_weapon == HANDREMOTE_WEAPON)
5 Plagman 794
    {
795
        p->ammo_amount[HANDBOMB_WEAPON]++;
796
        p->curr_weapon = HANDBOMB_WEAPON;
797
    }
798
 
799
    p->timebeforeexit   = 0;
800
    p->customexitsound  = 0;
801
 
802
}
803
 
395 terminx 804
static void setupbackdrop(short sky)
5 Plagman 805
{
806
    short i;
807
 
331 terminx 808
    for (i=0;i<MAXPSKYTILES;i++) pskyoff[i]=0;
5 Plagman 809
 
331 terminx 810
    if (parallaxyscale != 65536L)
5 Plagman 811
        parallaxyscale = 32768;
812
 
331 terminx 813
    switch (dynamictostatic[sky])
5 Plagman 814
    {
337 terminx 815
    case CLOUDYOCEAN__STATIC:
816
        parallaxyscale = 65536L;
817
        break;
818
    case MOONSKY1__STATIC :
819
        pskyoff[6]=1;
820
        pskyoff[1]=2;
821
        pskyoff[4]=2;
822
        pskyoff[2]=3;
823
        break;
824
    case BIGORBIT1__STATIC: // orbit
825
        pskyoff[5]=1;
826
        pskyoff[6]=2;
827
        pskyoff[7]=3;
828
        pskyoff[2]=4;
829
        break;
830
    case LA__STATIC:
831
        parallaxyscale = 16384+1024;
832
        pskyoff[0]=1;
833
        pskyoff[1]=2;
834
        pskyoff[2]=1;
835
        pskyoff[3]=3;
836
        pskyoff[4]=4;
837
        pskyoff[5]=0;
838
        pskyoff[6]=2;
839
        pskyoff[7]=3;
840
        break;
5 Plagman 841
    }
842
 
843
    pskybits=3;
844
}
845
 
395 terminx 846
static void prelevel(char g)
5 Plagman 847
{
528 terminx 848
    int i, nexti, j, startwall, endwall, lotaglist;
849
    int lotags[MAXSPRITES];
5 Plagman 850
    int switchpicnum;
851
 
852
 
853
    clearbufbyte(show2dsector,sizeof(show2dsector),0L);
854
    clearbufbyte(show2dwall,sizeof(show2dwall),0L);
855
    clearbufbyte(show2dsprite,sizeof(show2dsprite),0L);
856
 
857
    resetprestat(0,g);
858
    numclouds = 0;
859
 
331 terminx 860
    for (i=0;i<numsectors;i++)
5 Plagman 861
    {
862
        sector[i].extra = 256;
863
 
331 terminx 864
        switch (sector[i].lotag)
5 Plagman 865
        {
337 terminx 866
        case 20:
867
        case 22:
868
            if (sector[i].floorz > sector[i].ceilingz)
869
                sector[i].lotag |= 32768;
870
            continue;
5 Plagman 871
        }
872
 
331 terminx 873
        if (sector[i].ceilingstat&1)
5 Plagman 874
        {
331 terminx 875
            if (waloff[sector[i].ceilingpicnum] == 0)
5 Plagman 876
            {
331 terminx 877
                if (sector[i].ceilingpicnum == LA)
878
                    for (j=0;j<5;j++)
5 Plagman 879
                        tloadtile(sector[i].ceilingpicnum+j, 0);
880
            }
881
            setupbackdrop(sector[i].ceilingpicnum);
882
 
331 terminx 883
            if (sector[i].ceilingpicnum == CLOUDYSKIES && numclouds < 127)
5 Plagman 884
                clouds[numclouds++] = i;
885
 
564 terminx 886
            if (g_player[0].ps->one_parallax_sectnum == -1)
887
                g_player[0].ps->one_parallax_sectnum = i;
5 Plagman 888
        }
889
 
331 terminx 890
        if (sector[i].lotag == 32767) //Found a secret room
5 Plagman 891
        {
564 terminx 892
            g_player[0].ps->max_secret_rooms++;
5 Plagman 893
            continue;
894
        }
895
 
331 terminx 896
        if (sector[i].lotag == -1)
5 Plagman 897
        {
564 terminx 898
            g_player[0].ps->exitx = wall[sector[i].wallptr].x;
899
            g_player[0].ps->exity = wall[sector[i].wallptr].y;
5 Plagman 900
            continue;
901
        }
902
    }
903
 
904
    i = headspritestat[0];
331 terminx 905
    while (i >= 0)
5 Plagman 906
    {
907
        nexti = nextspritestat[i];
299 terminx 908
        ResetActorGameVars(i);
394 terminx 909
        LoadActor(i);
599 terminx 910
        OnEvent(EVENT_LOADACTOR, i, -1, -1);
333 terminx 911
        if (sprite[i].lotag == -1 && (sprite[i].cstat&16))
5 Plagman 912
        {
564 terminx 913
            g_player[0].ps->exitx = SX;
914
            g_player[0].ps->exity = SY;
5 Plagman 915
        }
331 terminx 916
        else switch (dynamictostatic[PN])
5 Plagman 917
            {
337 terminx 918
            case GPSPEED__STATIC:
919
                sector[SECT].extra = SLT;
920
                deletesprite(i);
921
                break;
5 Plagman 922
 
337 terminx 923
            case CYCLER__STATIC:
924
                if (numcyclers >= MAXCYCLERS)
925
                {
926
                    Bsprintf(tempbuf,"\nToo many cycling sectors (%d max).",MAXCYCLERS);
927
                    gameexit(tempbuf);
928
                }
929
                cyclers[numcyclers][0] = SECT;
930
                cyclers[numcyclers][1] = SLT;
931
                cyclers[numcyclers][2] = SS;
932
                cyclers[numcyclers][3] = sector[SECT].floorshade;
933
                cyclers[numcyclers][4] = SHT;
934
                cyclers[numcyclers][5] = (SA == 1536);
935
                numcyclers++;
936
                deletesprite(i);
937
                break;
5 Plagman 938
 
337 terminx 939
            case SECTOREFFECTOR__STATIC:
940
            case ACTIVATOR__STATIC:
941
            case TOUCHPLATE__STATIC:
942
            case ACTIVATORLOCKED__STATIC:
943
            case MUSICANDSFX__STATIC:
944
            case LOCATORS__STATIC:
945
            case MASTERSWITCH__STATIC:
946
            case RESPAWN__STATIC:
947
                sprite[i].cstat = 0;
948
                break;
5 Plagman 949
            }
950
        i = nexti;
951
    }
952
 
331 terminx 953
    for (i=0;i < MAXSPRITES;i++)
5 Plagman 954
    {
331 terminx 955
        if (sprite[i].statnum < MAXSTATUS)
5 Plagman 956
        {
331 terminx 957
            if (PN == SECTOREFFECTOR && SLT == 14)
5 Plagman 958
                continue;
959
            spawn(-1,i);
960
        }
961
    }
962
 
331 terminx 963
    for (i=0;i < MAXSPRITES;i++)
964
        if (sprite[i].statnum < MAXSTATUS)
5 Plagman 965
        {
333 terminx 966
            if (PN == SECTOREFFECTOR && SLT == 14)
5 Plagman 967
                spawn(-1,i);
968
        }
969
 
970
    lotaglist = 0;
971
 
972
    i = headspritestat[0];
331 terminx 973
    while (i >= 0)
5 Plagman 974
    {
331 terminx 975
        switch (dynamictostatic[PN-1])
5 Plagman 976
        {
337 terminx 977
        case DIPSWITCH__STATIC:
978
        case DIPSWITCH2__STATIC:
979
        case PULLSWITCH__STATIC:
980
        case HANDSWITCH__STATIC:
981
        case SLOTDOOR__STATIC:
982
        case LIGHTSWITCH__STATIC:
983
        case SPACELIGHTSWITCH__STATIC:
984
        case SPACEDOORSWITCH__STATIC:
985
        case FRANKENSTINESWITCH__STATIC:
986
        case LIGHTSWITCH2__STATIC:
987
        case POWERSWITCH1__STATIC:
988
        case LOCKSWITCH1__STATIC:
989
        case POWERSWITCH2__STATIC:
990
            for (j=0;j<lotaglist;j++)
991
                if (SLT == lotags[j])
992
                    break;
5 Plagman 993
 
337 terminx 994
            if (j == lotaglist)
995
            {
996
                lotags[lotaglist] = SLT;
997
                lotaglist++;
528 terminx 998
                if (lotaglist > MAXSPRITES-1)
999
                    gameexit("\nToo many switches.");
337 terminx 1000
 
1001
                j = headspritestat[3];
1002
                while (j >= 0)
335 terminx 1003
                {
337 terminx 1004
                    if (sprite[j].lotag == 12 && sprite[j].hitag == SLT)
1005
                        hittype[j].temp_data[0] = 1;
1006
                    j = nextspritestat[j];
5 Plagman 1007
                }
337 terminx 1008
            }
1009
            break;
5 Plagman 1010
        }
1011
        i = nextspritestat[i];
1012
    }
1013
 
1014
    mirrorcnt = 0;
1015
 
333 terminx 1016
    for (i = 0; i < numwalls; i++)
5 Plagman 1017
    {
1018
        walltype *wal;
1019
        wal = &wall[i];
1020
 
331 terminx 1021
        if (wal->overpicnum == MIRROR && (wal->cstat&32) != 0)
5 Plagman 1022
        {
1023
            j = wal->nextsector;
1024
 
331 terminx 1025
            if (mirrorcnt > 63)
5 Plagman 1026
                gameexit("\nToo many mirrors (64 max.)");
333 terminx 1027
            if ((j >= 0) && sector[j].ceilingpicnum != MIRROR)
5 Plagman 1028
            {
1029
                sector[j].ceilingpicnum = MIRROR;
1030
                sector[j].floorpicnum = MIRROR;
1031
                mirrorwall[mirrorcnt] = i;
1032
                mirrorsector[mirrorcnt] = j;
1033
                mirrorcnt++;
1034
                continue;
1035
            }
1036
        }
1037
 
331 terminx 1038
        if (numanimwalls >= MAXANIMWALLS)
5 Plagman 1039
        {
1040
            Bsprintf(tempbuf,"\nToo many 'anim' walls (%d max).",MAXANIMWALLS);
1041
            gameexit(tempbuf);
1042
        }
1043
 
1044
        animwall[numanimwalls].tag = 0;
1045
        animwall[numanimwalls].wallnum = 0;
1046
        switchpicnum = wal->overpicnum;
335 terminx 1047
        if ((wal->overpicnum > W_FORCEFIELD)&&(wal->overpicnum <= W_FORCEFIELD+2))
1048
        {
5 Plagman 1049
            switchpicnum = W_FORCEFIELD;
1050
        }
331 terminx 1051
        switch (dynamictostatic[switchpicnum])
5 Plagman 1052
        {
337 terminx 1053
        case FANSHADOW__STATIC:
1054
        case FANSPRITE__STATIC:
1055
            wall->cstat |= 65;
1056
            animwall[numanimwalls].wallnum = i;
1057
            numanimwalls++;
1058
            break;
5 Plagman 1059
 
337 terminx 1060
        case W_FORCEFIELD__STATIC:
1061
            if (wal->overpicnum==W_FORCEFIELD__STATIC)
1062
                for (j=0;j<3;j++)
1063
                    tloadtile(W_FORCEFIELD+j, 0);
1064
            if (wal->shade > 31)
1065
                wal->cstat = 0;
1066
            else wal->cstat |= 85+256;
5 Plagman 1067
 
1068
 
337 terminx 1069
            if (wal->lotag && wal->nextwall >= 0)
1070
                wall[wal->nextwall].lotag =
1071
                    wal->lotag;
5 Plagman 1072
 
337 terminx 1073
        case BIGFORCE__STATIC:
5 Plagman 1074
 
337 terminx 1075
            animwall[numanimwalls].wallnum = i;
1076
            numanimwalls++;
5 Plagman 1077
 
337 terminx 1078
            continue;
5 Plagman 1079
        }
1080
 
1081
        wal->extra = -1;
1082
 
331 terminx 1083
        switch (dynamictostatic[wal->picnum])
5 Plagman 1084
        {
337 terminx 1085
        case WATERTILE2__STATIC:
1086
            for (j=0;j<3;j++)
1087
                tloadtile(wal->picnum+j, 0);
1088
            break;
5 Plagman 1089
 
337 terminx 1090
        case TECHLIGHT2__STATIC:
1091
        case TECHLIGHT4__STATIC:
1092
            tloadtile(wal->picnum, 0);
1093
            break;
1094
        case W_TECHWALL1__STATIC:
1095
        case W_TECHWALL2__STATIC:
1096
        case W_TECHWALL3__STATIC:
1097
        case W_TECHWALL4__STATIC:
1098
            animwall[numanimwalls].wallnum = i;
1099
            //                animwall[numanimwalls].tag = -1;
1100
            numanimwalls++;
1101
            break;
1102
        case SCREENBREAK6__STATIC:
1103
        case SCREENBREAK7__STATIC:
1104
        case SCREENBREAK8__STATIC:
1105
            for (j=SCREENBREAK6;j<SCREENBREAK9;j++)
1106
                tloadtile(j, 0);
1107
            animwall[numanimwalls].wallnum = i;
1108
            animwall[numanimwalls].tag = -1;
1109
            numanimwalls++;
1110
            break;
5 Plagman 1111
 
337 terminx 1112
        case FEMPIC1__STATIC:
1113
        case FEMPIC2__STATIC:
1114
        case FEMPIC3__STATIC:
5 Plagman 1115
 
337 terminx 1116
            wal->extra = wal->picnum;
1117
            animwall[numanimwalls].tag = -1;
1118
            if (ud.lockout)
1119
            {
1120
                if (wal->picnum == FEMPIC1)
1121
                    wal->picnum = BLANKSCREEN;
1122
                else wal->picnum = SCREENBREAK6;
1123
            }
5 Plagman 1124
 
337 terminx 1125
            animwall[numanimwalls].wallnum = i;
1126
            animwall[numanimwalls].tag = wal->picnum;
1127
            numanimwalls++;
1128
            break;
5 Plagman 1129
 
337 terminx 1130
        case SCREENBREAK1__STATIC:
1131
        case SCREENBREAK2__STATIC:
1132
        case SCREENBREAK3__STATIC:
1133
        case SCREENBREAK4__STATIC:
1134
        case SCREENBREAK5__STATIC:
5 Plagman 1135
 
337 terminx 1136
        case SCREENBREAK9__STATIC:
1137
        case SCREENBREAK10__STATIC:
1138
        case SCREENBREAK11__STATIC:
1139
        case SCREENBREAK12__STATIC:
1140
        case SCREENBREAK13__STATIC:
1141
        case SCREENBREAK14__STATIC:
1142
        case SCREENBREAK15__STATIC:
1143
        case SCREENBREAK16__STATIC:
1144
        case SCREENBREAK17__STATIC:
1145
        case SCREENBREAK18__STATIC:
1146
        case SCREENBREAK19__STATIC:
5 Plagman 1147
 
337 terminx 1148
            animwall[numanimwalls].wallnum = i;
1149
            animwall[numanimwalls].tag = wal->picnum;
1150
            numanimwalls++;
1151
            break;
5 Plagman 1152
        }
1153
    }
1154
 
1155
    //Invalidate textures in sector behind mirror
331 terminx 1156
    for (i=0;i<mirrorcnt;i++)
5 Plagman 1157
    {
1158
        startwall = sector[mirrorsector[i]].wallptr;
1159
        endwall = startwall + sector[mirrorsector[i]].wallnum;
331 terminx 1160
        for (j=startwall;j<endwall;j++)
5 Plagman 1161
        {
1162
            wall[j].picnum = MIRROR;
1163
            wall[j].overpicnum = MIRROR;
1164
        }
1165
    }
1166
}
1167
 
509 terminx 1168
void newgame(int vn,int ln,int sk)
5 Plagman 1169
{
564 terminx 1170
    player_struct *p = g_player[0].ps;
509 terminx 1171
    int i;
5 Plagman 1172
 
423 terminx 1173
    handleevents();
1174
    getpackets();
1175
 
563 terminx 1176
    if (globalskillsound >= 0 && ud.config.FXDevice >= 0 && ud.config.SoundToggle)
423 terminx 1177
    {
335 terminx 1178
        while (issoundplaying(-1,globalskillsound))
1179
        {
1180
            handleevents();
1181
            getpackets();
1182
        }
1183
    }
428 terminx 1184
 
5 Plagman 1185
    globalskillsound = -1;
1186
 
1187
    waitforeverybody();
1188
    ready2send = 0;
1189
 
333 terminx 1190
    if (ud.m_recstat != 2 && ud.last_level >= 0 && ud.multimode > 1 && (ud.coop&GAMETYPE_FLAG_SCORESHEET))
5 Plagman 1191
        dobonus(1);
1192
 
333 terminx 1193
    if (ln == 0 && vn == 3 && ud.multimode < 2 && ud.lockout == 0)
5 Plagman 1194
    {
680 terminx 1195
        playmusic(&env_music_fn[1][0],MAXVOLUMES*MAXLEVELS+1);
5 Plagman 1196
 
1197
        flushperms();
1198
        setview(0,0,xdim-1,ydim-1);
1199
        clearview(0L);
1200
        nextpage();
1201
 
1202
        playanm("vol41a.anm",6);
1203
        clearview(0L);
1204
        nextpage();
1205
 
1206
        playanm("vol42a.anm",7);
1207
        playanm("vol43a.anm",9);
1208
        clearview(0L);
1209
        nextpage();
1210
 
1211
        FX_StopAllSounds();
1212
    }
1213
 
1214
    show_shareware = 26*34;
1215
 
1216
    ud.level_number =   ln;
1217
    ud.volume_number =  vn;
1218
    ud.player_skill =   sk;
1219
    ud.secretlevel =    0;
1220
    ud.from_bonus = 0;
1221
    parallaxyscale = 0;
1222
 
1223
    ud.last_level = -1;
1224
    lastsavedpos = -1;
1225
    p->zoom            = 768;
1226
    p->gm              = 0;
1227
 
423 terminx 1228
    //AddLog("Newgame");
1229
    ResetGameVars();
5 Plagman 1230
 
423 terminx 1231
    InitGameVarPointers();
5 Plagman 1232
 
423 terminx 1233
    ResetSystemDefaults();
5 Plagman 1234
 
423 terminx 1235
    if (ud.m_coop != 1)
1236
    {
1237
        for (i=0;i<MAX_WEAPONS;i++)
5 Plagman 1238
        {
423 terminx 1239
            if (aplWeaponWorksLike[i][0]==PISTOL_WEAPON)
5 Plagman 1240
            {
423 terminx 1241
                p->curr_weapon = i;
1242
                p->gotweapon[i] = 1;
1243
                p->ammo_amount[i] = 48;
5 Plagman 1244
            }
423 terminx 1245
            else if (aplWeaponWorksLike[i][0]==KNEE_WEAPON)
1246
                p->gotweapon[i] = 1;
1247
            else if (aplWeaponWorksLike[i][0]==HANDREMOTE_WEAPON)
1248
                p->gotweapon[i] = 1;
5 Plagman 1249
        }
423 terminx 1250
        p->last_weapon = -1;
5 Plagman 1251
    }
428 terminx 1252
 
5 Plagman 1253
    display_mirror =        0;
1254
 
333 terminx 1255
    if (ud.multimode > 1)
5 Plagman 1256
    {
331 terminx 1257
        if (numplayers < 2)
5 Plagman 1258
        {
1259
            connecthead = 0;
331 terminx 1260
            for (i=0;i<MAXPLAYERS;i++) connectpoint2[i] = i+1;
5 Plagman 1261
            connectpoint2[ud.multimode-1] = -1;
1262
        }
1263
    }
1264
    else
1265
    {
1266
        connecthead = 0;
1267
        connectpoint2[0] = -1;
1268
    }
1269
}
1270
 
471 terminx 1271
int getteampal(int team)
1272
{
1273
    switch (team)
1274
    {
1275
    case 0:
472 terminx 1276
        return 3;
1277
    case 1:
471 terminx 1278
        return 10;
1279
    case 2:
1280
        return 11;
1281
    case 3:
1282
        return 12;
1283
    }
1284
    return 0;
1285
}
1286
 
395 terminx 1287
static void resetpspritevars(char g)
5 Plagman 1288
{
1289
    short i, j, nexti,circ;
584 terminx 1290
    int firstx,firsty;
5 Plagman 1291
    spritetype *s;
1292
    char aimmode[MAXPLAYERS],autoaim[MAXPLAYERS],weaponswitch[MAXPLAYERS];
1293
    STATUSBARTYPE tsbar[MAXPLAYERS];
1294
 
564 terminx 1295
    EGS(g_player[0].ps->cursectnum,g_player[0].ps->posx,g_player[0].ps->posy,g_player[0].ps->posz,
1296
        APLAYER,0,0,0,g_player[0].ps->ang,0,0,0,10);
5 Plagman 1297
 
564 terminx 1298
    if (ud.recstat != 2) for (i=0;i<ud.multimode;i++)
5 Plagman 1299
        {
564 terminx 1300
            aimmode[i] = g_player[i].ps->aim_mode;
1301
            autoaim[i] = g_player[i].ps->auto_aim;
1302
            weaponswitch[i] = g_player[i].ps->weaponswitch;
331 terminx 1303
            if (ud.multimode > 1 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
5 Plagman 1304
            {
331 terminx 1305
                for (j=0;j<MAX_WEAPONS;j++)
5 Plagman 1306
                {
564 terminx 1307
                    tsbar[i].ammo_amount[j] = g_player[i].ps->ammo_amount[j];
1308
                    tsbar[i].gotweapon[j] = g_player[i].ps->gotweapon[j];
5 Plagman 1309
                }
1310
 
564 terminx 1311
                tsbar[i].shield_amount = g_player[i].ps->shield_amount;
1312
                tsbar[i].curr_weapon = g_player[i].ps->curr_weapon;
1313
                tsbar[i].inven_icon = g_player[i].ps->inven_icon;
5 Plagman 1314
 
564 terminx 1315
                tsbar[i].firstaid_amount = g_player[i].ps->firstaid_amount;
1316
                tsbar[i].steroids_amount = g_player[i].ps->steroids_amount;
1317
                tsbar[i].holoduke_amount = g_player[i].ps->holoduke_amount;
1318
                tsbar[i].jetpack_amount = g_player[i].ps->jetpack_amount;
1319
                tsbar[i].heat_amount = g_player[i].ps->heat_amount;
1320
                tsbar[i].scuba_amount = g_player[i].ps->scuba_amount;
1321
                tsbar[i].boot_amount = g_player[i].ps->boot_amount;
5 Plagman 1322
            }
1323
        }
1324
 
1325
    resetplayerstats(0);
1326
 
564 terminx 1327
    for (i=1;i<ud.multimode;i++)
565 terminx 1328
        memcpy(g_player[i].ps,g_player[0].ps,sizeof(player_struct));
5 Plagman 1329
 
514 terminx 1330
    if (ud.recstat != 2)
564 terminx 1331
        for (i=0;i<ud.multimode;i++)
5 Plagman 1332
        {
564 terminx 1333
            g_player[i].ps->aim_mode = aimmode[i];
1334
            g_player[i].ps->auto_aim = autoaim[i];
1335
            g_player[i].ps->weaponswitch = weaponswitch[i];
331 terminx 1336
            if (ud.multimode > 1 && (gametype_flags[ud.coop]&GAMETYPE_FLAG_PRESERVEINVENTORYDEATH) && ud.last_level >= 0)
5 Plagman 1337
            {
331 terminx 1338
                for (j=0;j<MAX_WEAPONS;j++)
5 Plagman 1339
                {
564 terminx 1340
                    g_player[i].ps->ammo_amount[j] = tsbar[i].ammo_amount[j];
1341
                    g_player[i].ps->gotweapon[j] = tsbar[i].gotweapon[j];
5 Plagman 1342
                }
564 terminx 1343
                g_player[i].ps->shield_amount = tsbar[i].shield_amount;
1344
                g_player[i].ps->curr_weapon = tsbar[i].curr_weapon;
1345
                g_player[i].ps->inven_icon = tsbar[i].inven_icon;
5 Plagman 1346
 
564 terminx 1347
                g_player[i].ps->firstaid_amount = tsbar[i].firstaid_amount;
1348
                g_player[i].ps->steroids_amount= tsbar[i].steroids_amount;
1349
                g_player[i].ps->holoduke_amount = tsbar[i].holoduke_amount;
1350
                g_player[i].ps->jetpack_amount = tsbar[i].jetpack_amount;
1351
                g_player[i].ps->heat_amount = tsbar[i].heat_amount;
1352
                g_player[i].ps->scuba_amount= tsbar[i].scuba_amount;
1353
                g_player[i].ps->boot_amount = tsbar[i].boot_amount;
5 Plagman 1354
            }
1355
        }
1356
 
1357
    numplayersprites = 0;
1358
    circ = 2048/ud.multimode;
1359
 
1360
    which_palookup = 9;
1361
    j = connecthead;
1362
    i = headspritestat[10];
331 terminx 1363
    while (i >= 0)
5 Plagman 1364
    {
1365
        nexti = nextspritestat[i];
1366
        s = &sprite[i];
1367
 
333 terminx 1368
        if (numplayersprites == MAXPLAYERS)
5 Plagman 1369
            gameexit("\nToo many player sprites (max 16.)");
1370
 
331 terminx 1371
        if (numplayersprites == 0)
5 Plagman 1372
        {
564 terminx 1373
            firstx = g_player[0].ps->posx;
1374
            firsty = g_player[0].ps->posy;
5 Plagman 1375
        }
1376
 
564 terminx 1377
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].ox = s->x;
1378
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oy = s->y;
1379
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oz = s->z;
1380
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].oa = s->ang;
1381
        g_PlayerSpawnPoints[(unsigned char)numplayersprites].os = s->sectnum;
5 Plagman 1382
 
1383
        numplayersprites++;
331 terminx 1384
        if (j >= 0)
5 Plagman 1385
        {
1386
            s->owner = i;
1387
            s->shade = 0;
1388
            s->xrepeat = 42;
1389
            s->yrepeat = 36;
1390
            s->cstat = 1+256;
1391
            s->xoffset = 0;
1392
            s->clipdist = 64;
1393
 
564 terminx 1394
            if ((g&MODE_EOL) != MODE_EOL || g_player[j].ps->last_extra == 0)
5 Plagman 1395
            {
566 terminx 1396
                g_player[j].ps->last_extra = g_player[j].ps->max_player_health;
1397
                s->extra = g_player[j].ps->max_player_health;
564 terminx 1398
                g_player[j].ps->runspeed = dukefriction;
5 Plagman 1399
            }
564 terminx 1400
            else s->extra = g_player[j].ps->last_extra;
5 Plagman 1401
 
1402
            s->yvel = j;
1403
 
563 terminx 1404
            if (!g_player[j].pcolor && ud.multimode > 1 && !(gametype_flags[ud.coop] & GAMETYPE_FLAG_TDM))
5 Plagman 1405
            {
331 terminx 1406
                if (s->pal == 0)
53 terminx 1407
                {
514 terminx 1408
                    int k = 0;
56 terminx 1409
 
564 terminx 1410
                    for (;k<ud.multimode;k++)
335 terminx 1411
                    {
564 terminx 1412
                        if (which_palookup == g_player[k].ps->palookup)
335 terminx 1413
                        {
56 terminx 1414
                            which_palookup++;
333 terminx 1415
                            if (which_palookup >= 17)
56 terminx 1416
                                which_palookup = 9;
1417
                            k=0;
1418
                        }
1419
                    }
564 terminx 1420
                    g_player[j].pcolor = s->pal = g_player[j].ps->palookup = which_palookup++;
333 terminx 1421
                    if (which_palookup >= 17)
56 terminx 1422
                        which_palookup = 9;
53 terminx 1423
                }
564 terminx 1424
                else g_player[j].pcolor = g_player[j].ps->palookup = s->pal;
268 terminx 1425
            }
1426
            else
1427
            {
563 terminx 1428
                int k = g_player[j].pcolor;
5 Plagman 1429
 
331 terminx 1430
                if (gametype_flags[ud.coop] & GAMETYPE_FLAG_TDM)
268 terminx 1431
                {
563 terminx 1432
                    k = getteampal(g_player[j].pteam);
564 terminx 1433
                    g_player[j].ps->team = g_player[j].pteam;
268 terminx 1434
                }
564 terminx 1435
                s->pal = g_player[j].ps->palookup = k;
268 terminx 1436
            }
1437
 
564 terminx 1438
            g_player[j].ps->i = i;
1439
            g_player[j].ps->frag_ps = j;
5 Plagman 1440
            hittype[i].owner = i;
1441
 
564 terminx 1442
            hittype[i].bposx = g_player[j].ps->bobposx = g_player[j].ps->oposx = g_player[j].ps->posx =        s->x;
1443
            hittype[i].bposy = g_player[j].ps->bobposy = g_player[j].ps->oposy = g_player[j].ps->posy =        s->y;
1444
            hittype[i].bposz = g_player[j].ps->oposz = g_player[j].ps->posz =        s->z;
1445
            g_player[j].ps->oang  = g_player[j].ps->ang  =        s->ang;
5 Plagman 1446
 
564 terminx 1447
            updatesector(s->x,s->y,&g_player[j].ps->cursectnum);
5 Plagman 1448
 
1449
            j = connectpoint2[j];
1450
 
1451
        }
1452
        else deletesprite(i);
1453
        i = nexti;
1454
    }
1455
}
1456
 
400 terminx 1457
static inline void clearfrags(void)
5 Plagman 1458
{
514 terminx 1459
    int i = 0;
5 Plagman 1460
 
564 terminx 1461
    while (i<ud.multimode)
1462
    {
1463
        g_player[i].ps->frag = g_player[i].ps->fraggedself = 0, i++;
1464
        clearbufbyte(&g_player[i].frags[0],MAXPLAYERS<<1,0L);
1465
    }
5 Plagman 1466
}
1467
 
1468
void resettimevars(void)
1469
{
1470
    vel = svel = angvel = horiz = 0;
1471
 
1472
    totalclock = 0L;
1473
    cloudtotalclock = 0L;
1474
    ototalclock = 0L;
1475
    lockclock = 0L;
1476
    ready2send = 1;
1477
}
1478
 
1479
void waitforeverybody()
1480
{
584 terminx 1481
    int i;
5 Plagman 1482
 
1483
    if (numplayers < 2) return;
1484
    packbuf[0] = 250;
331 terminx 1485
    for (i=connecthead;i>=0;i=connectpoint2[i])
5 Plagman 1486
    {
1487
        if (i != myconnectindex) sendpacket(i,packbuf,1);
1488
        if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master
1489
    }
563 terminx 1490
    g_player[myconnectindex].playerreadyflag++;
5 Plagman 1491
 
1492
    while (1)
1493
    {
375 terminx 1494
#ifdef _WIN32
1495
        Sleep(10);
1496
#else
1497
        usleep(10);
363 terminx 1498
#endif
375 terminx 1499
        sampletimer();
5 Plagman 1500
        handleevents();
1501
        AudioUpdate();
1502
 
1503
        if (quitevent || keystatus[1]) gameexit("");
1504
 
1505
        getpackets();
1506
 
331 terminx 1507
        for (i=connecthead;i>=0;i=connectpoint2[i])
5 Plagman 1508
        {
563 terminx 1509
            if (g_player[i].playerreadyflag < g_player[myconnectindex].playerreadyflag) break;
335 terminx 1510
            if ((!networkmode) && (myconnectindex != connecthead))
1511
            {
1512
                i = -1;
1513
                break;
1514
            } //slaves in M/S mode only wait for master
331 terminx 1515
 
5 Plagman 1516
        }
1517
        if (i < 0) return;
1518
    }
1519
}
1520
 
469 terminx 1521
extern int jump_input;
368 terminx 1522
 
5 Plagman 1523
void clearfifo(void)
1524
{
564 terminx 1525
    int i = 0;
563 terminx 1526
 
5 Plagman 1527
    syncvaltail = 0L;
1528
    syncvaltottail = 0L;
1529
    syncstat = 0;
1530
    bufferjitter = 1;
1531
    mymaxlag = otherminlag = 0;
368 terminx 1532
    jump_input = 0;
5 Plagman 1533
 
1534
    movefifoplc = movefifosendplc = fakemovefifoplc = 0;
275 terminx 1535
    avgfvel = avgsvel = avgavel = avghorz = avgbits = avgextbits = 0;
5 Plagman 1536
    otherminlag = mymaxlag = 0;
1537
 
564 terminx 1538
    clearbufbyte(&loc,sizeof(input),0L);
1539
    clearbufbyte(&inputfifo,sizeof(input)*MOVEFIFOSIZ*MAXPLAYERS,0L);
1540
    for (;i<MAXPLAYERS;i++)
1541
    {
1542
//              Bmemset(g_player[i].inputfifo,0,sizeof(g_player[i].inputfifo));
1543
        if (g_player[i].sync != NULL)
1544
            Bmemset(g_player[i].sync,0,sizeof(input));
1545
        Bmemset(&g_player[i].movefifoend,0,sizeof(g_player[i].movefifoend));
1546
        Bmemset(&g_player[i].syncvalhead,0,sizeof(g_player[i].syncvalhead));
1547
        Bmemset(&g_player[i].myminlag,0,sizeof(g_player[i].myminlag));
1548
        g_player[i].vote = 0;
1549
        g_player[i].gotvote = 0;
1550
    }
5 Plagman 1551
    //    clearbufbyte(playerquitflag,MAXPLAYERS,0x01);
1552
}
1553
 
1554
void resetmys(void)
1555
{
564 terminx 1556
    myx = omyx = g_player[myconnectindex].ps->posx;
1557
    myy = omyy = g_player[myconnectindex].ps->posy;
1558
    myz = omyz = g_player[myconnectindex].ps->posz;
5 Plagman 1559
    myxvel = myyvel = myzvel = 0;
564 terminx 1560
    myang = omyang = g_player[myconnectindex].ps->ang;
1561
    myhoriz = omyhoriz = g_player[myconnectindex].ps->horiz;
1562
    myhorizoff = omyhorizoff = g_player[myconnectindex].ps->horizoff;
1563
    mycursectnum = g_player[myconnectindex].ps->cursectnum;
1564
    myjumpingcounter = g_player[myconnectindex].ps->jumping_counter;
1565
    myjumpingtoggle = g_player[myconnectindex].ps->jumping_toggle;
1566
    myonground = g_player[myconnectindex].ps->on_ground;
1567
    myhardlanding = g_player[myconnectindex].ps->hard_landing;
1568
    myreturntocenter = g_player[myconnectindex].ps->return_to_center;
5 Plagman 1569
}
1570
 
564 terminx 1571
extern int voting, vote_map, vote_episode;
147 terminx 1572
 
412 terminx 1573
static void getlevelfromfilename(const char *fn, char *volume, char *level)
398 terminx 1574
{
428 terminx 1575
    for (*volume=0;*volume<MAXVOLUMES;(*volume)++)
398 terminx 1576
    {
428 terminx 1577
        for (*level=0;*level<MAXLEVELS;(*level)++)
398 terminx 1578
        {
562 terminx 1579
            if (map[(*volume*MAXLEVELS)+*level].filename != NULL)
1580
                if (!Bstrcasecmp(fn, map[(*volume*MAXLEVELS)+*level].filename))
398 terminx 1581
                    break;
1582
        }
428 terminx 1583
        if (*level != MAXLEVELS)
398 terminx 1584
            break;
1585
    }
1586
}
1587
 
509 terminx 1588
int enterlevel(int g)
5 Plagman 1589
{
485 terminx 1590
    int i;
5 Plagman 1591
    char levname[BMAX_PATH];
1592
 
371 terminx 1593
    ready2send = 1; // HACK: fetch any leftover p2p sync packets
368 terminx 1594
    KB_ClearKeysDown();
1595
    handleevents();
1596
    getpackets();
369 terminx 1597
    waitforeverybody();
375 terminx 1598
    ready2send = 0;
1599
 
564 terminx 1600
    vote_map = vote_episode = voting = -1;
1601
 
333 terminx 1602
    if ((g&MODE_DEMO) != MODE_DEMO) ud.recstat = ud.m_recstat;
5 Plagman 1603
    ud.respawn_monsters = ud.m_respawn_monsters;
1604
    ud.respawn_items    = ud.m_respawn_items;
1605
    ud.respawn_inventory    = ud.m_respawn_inventory;
1606
    ud.monsters_off = ud.m_monsters_off;
1607
    ud.coop = ud.m_coop;
1608
    ud.marker = ud.m_marker;
1609
    ud.ffire = ud.m_ffire;
147 terminx 1610
    ud.noexits = ud.m_noexits;
5 Plagman 1611
 
333 terminx 1612
    if ((g&MODE_DEMO) == 0 && ud.recstat == 2)
5 Plagman 1613
        ud.recstat = 0;
1614
 
1615
    FX_StopAllSounds();
1616
    clearsoundlocks();
1617
    FX_SetReverb(0);
1618
 
392 terminx 1619
    if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
1620
    {
400 terminx 1621
        char volume, level;
398 terminx 1622
 
412 terminx 1623
        Bcorrectfilename(boardfilename,0);
1624
 
400 terminx 1625
        getlevelfromfilename(boardfilename,&volume,&level);
398 terminx 1626
 
392 terminx 1627
        if (level != MAXLEVELS)
1628
        {
1629
            ud.level_number = ud.m_level_number = level;
1630
            ud.volume_number = ud.m_volume_number = volume;
1631
            boardfilename[0] = 0;
1632
        }
1633
    }
1634
 
562 terminx 1635
    if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].name == NULL || map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename == NULL)
382 terminx 1636
    {
385 terminx 1637
        if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
1638
        {
562 terminx 1639
            if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename == NULL)
1640
                map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename = Bcalloc(BMAX_PATH,sizeof(char));
1641
            if (map[(ud.volume_number*MAXLEVELS)+ud.level_number].name == NULL)
385 terminx 1642
            {
562 terminx 1643
                map[(ud.volume_number*MAXLEVELS)+ud.level_number].name = Bcalloc(9,sizeof(char));
1644
                Bsprintf(map[(ud.volume_number*MAXLEVELS)+ud.level_number].name,"USER MAP");
385 terminx 1645
            }
1646
        }
1647
        else
1648
        {
584 terminx 1649
            initprintf("Map E%dL%d not defined!\n",ud.volume_number+1,ud.level_number+1);
385 terminx 1650
            return 1;
1651
        }
382 terminx 1652
    }
1653
 
5 Plagman 1654
    i = ud.screen_size;
1655
    ud.screen_size = 0;
1656
    dofrontscreens(NULL);
1657
    vscrn();
1658
    ud.screen_size = i;
1659
 
382 terminx 1660
    if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
1661
    {
1662
        Bstrcpy(levname, boardfilename);
1663
        Bsprintf(apptitle," - %s",levname);
1664
    }
562 terminx 1665
    else Bsprintf(apptitle," - %s",map[(ud.volume_number*MAXLEVELS)+ud.level_number].name);
382 terminx 1666
 
385 terminx 1667
    if (VOLUMEALL) Bsprintf(tempbuf,HEAD2);
1668
    else Bsprintf(tempbuf,HEAD);
1669
 
1670
    Bstrcat(tempbuf,apptitle);
1671
    wm_setapptitle(tempbuf);
1672
 
335 terminx 1673
    if (!VOLUMEONE)
1674
    {
333 terminx 1675
        if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
5 Plagman 1676
        {
564 terminx 1677
            if (loadboard(boardfilename,0,&g_player[0].ps->posx, &g_player[0].ps->posy, &g_player[0].ps->posz, &g_player[0].ps->ang,&g_player[0].ps->cursectnum) == -1)
5 Plagman 1678
            {
514 terminx 1679
                initprintf("Map '%s' not found!\n",boardfilename);
5 Plagman 1680
                //gameexit(tempbuf);
1681
                return 1;
335 terminx 1682
            }
423 terminx 1683
 
335 terminx 1684
            {
5 Plagman 1685
                char *p;
1686
                strcpy(levname, boardfilename);
1687
                p = Bstrrchr(levname,'.');
1688
                if (!p) strcat(levname,".mhk");
335 terminx 1689
                else
1690
                {
1691
                    p[1]='m';
1692
                    p[2]='h';
1693
                    p[3]='k';
1694
                    p[4]=0;
1695
                }
514 terminx 1696
                if (!loadmaphack(levname)) initprintf("Loaded map hack file '%s'\n",levname);
5 Plagman 1697
            }
1698
        }
564 terminx 1699
        else if (loadboard(map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename,0,&g_player[0].ps->posx, &g_player[0].ps->posy, &g_player[0].ps->posz, &g_player[0].ps->ang,&g_player[0].ps->cursectnum) == -1)
5 Plagman 1700
        {
562 terminx 1701
            initprintf("Map %s not found!\n",map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename);
5 Plagman 1702
            //gameexit(tempbuf);
1703
            return 1;
335 terminx 1704
        }
1705
        else
1706
        {
5 Plagman 1707
            char *p;
562 terminx 1708
            strcpy(levname, map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename);
5 Plagman 1709
            p = Bstrrchr(levname,'.');
1710
            if (!p) strcat(levname,".mhk");
335 terminx 1711
            else
1712
            {
1713
                p[1]='m';
1714
                p[2]='h';
1715
                p[3]='k';
1716
                p[4]=0;
1717
            }
514 terminx 1718
            if (!loadmaphack(levname)) initprintf("Loaded map hack file '%s'\n",levname);
5 Plagman 1719
        }
1720
 
335 terminx 1721
    }
1722
    else
1723
    {
5 Plagman 1724
 
562 terminx 1725
        i = strlen(map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename);
1726
        copybufbyte(map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename,&levname[0],i);
485 terminx 1727
        levname[i] = 255;
1728
        levname[i+1] = 0;
5 Plagman 1729
 
564 terminx 1730
        if (loadboard(levname,1,&g_player[0].ps->posx, &g_player[0].ps->posy, &g_player[0].ps->posz, &g_player[0].ps->ang,&g_player[0].ps->cursectnum) == -1)
5 Plagman 1731
        {
562 terminx 1732
            initprintf("Map '%s' not found!\n",map[(ud.volume_number*MAXLEVELS)+ud.level_number].filename);
5 Plagman 1733
            //gameexit(tempbuf);
1734
            return 1;
335 terminx 1735
        }
1736
        else
1737
        {
5 Plagman 1738
            char *p;
1739
            p = Bstrrchr(levname,'.');
1740
            if (!p) strcat(levname,".mhk");
335 terminx 1741
            else
1742
            {
1743
                p[1]='m';
1744
                p[2]='h';
1745
                p[3]='k';
1746
                p[4]=0;
1747
            }
514 terminx 1748
            if (!loadmaphack(levname)) initprintf("Loaded map hack file '%s'\n",levname);
5 Plagman 1749
        }
1750
    }
1751
 
1752
    precachecount = 0;
1753
    clearbufbyte(gotpic,sizeof(gotpic),0L);
1754
    clearbufbyte(precachehightile, sizeof(precachehightile), 0l);
1755
    //clearbufbyte(hittype,sizeof(hittype),0l); // JBF 20040531: yes? no?
1756
 
1757
    prelevel(g);
1758
 
1759
    allignwarpelevators();
1760
    resetpspritevars(g);
1761
 
1762
    cachedebug = 0;
1763
    automapping = 0;
1764
 
1765
    cacheit();
1766
 
331 terminx 1767
    if (ud.recstat != 2)
5 Plagman 1768
    {
381 terminx 1769
        music_select = (ud.volume_number*MAXLEVELS) + ud.level_number;
562 terminx 1770
        if (map[(unsigned char)music_select].musicfn != NULL)
680 terminx 1771
            playmusic(&map[(unsigned char)music_select].musicfn[0],music_select);
5 Plagman 1772
    }
1773
 
333 terminx 1774
    if ((g&MODE_GAME) || (g&MODE_EOL))
564 terminx 1775
        g_player[myconnectindex].ps->gm = MODE_GAME;
331 terminx 1776
    else if (g&MODE_RESTART)
5 Plagman 1777
    {
331 terminx 1778
        if (ud.recstat == 2)
564 terminx 1779
            g_player[myconnectindex].ps->gm = MODE_DEMO;
1780
        else g_player[myconnectindex].ps->gm = MODE_GAME;
5 Plagman 1781
    }
1782
 
333 terminx 1783
    if ((ud.recstat == 1) && (g&MODE_RESTART) != MODE_RESTART)
5 Plagman 1784
        opendemowrite();
1785
 
335 terminx 1786
    if (VOLUMEONE)
1787
    {
564 terminx 1788
        if (ud.level_number == 0 && ud.recstat != 2) FTA(40,g_player[myconnectindex].ps);
5 Plagman 1789
    }
1790
 
331 terminx 1791
    for (i=connecthead;i>=0;i=connectpoint2[i])
564 terminx 1792
        switch (dynamictostatic[sector[sprite[g_player[i].ps->i].sectnum].floorpicnum])
5 Plagman 1793
        {
337 terminx 1794
        case HURTRAIL__STATIC:
1795
        case FLOORSLIME__STATIC:
1796
        case FLOORPLASMA__STATIC:
1797
            resetweapons(i);
1798
            resetinventory(i);
564 terminx 1799
            g_player[i].ps->gotweapon[PISTOL_WEAPON] = 0;
1800
            g_player[i].ps->ammo_amount[PISTOL_WEAPON] = 0;
1801
            g_player[i].ps->curr_weapon = KNEE_WEAPON;
1802
            g_player[i].ps->kickback_pic = 0;
337 terminx 1803
            break;
5 Plagman 1804
        }
1805
 
1806
    //PREMAP.C - replace near the my's at the end of the file
1807
 
1808
    resetmys();
1809
 
564 terminx 1810
    //g_player[myconnectindex].ps->palette = palette;
5 Plagman 1811
    //palto(0,0,0,0);
564 terminx 1812
    setgamepalette(g_player[myconnectindex].ps, palette, 0);    // JBF 20040308
5 Plagman 1813
 
564 terminx 1814
    setpal(g_player[myconnectindex].ps);
5 Plagman 1815
    flushperms();
1816
 
1817
    everyothertime = 0;
1818
    global_random = 0;
1819
 
1820
    ud.last_level = ud.level_number+1;
1821
 
1822
    clearfifo();
1823
 
331 terminx 1824
    for (i=numinterpolations-1;i>=0;i--) bakipos[i] = *curipos[i];
5 Plagman 1825
 
1826
    restorepalette = 1;
1827
 
1828
    flushpackets();
1829
    waitforeverybody();
1830
 
1831
    palto(0,0,0,0);
1832
    vscrn();
1833
    clearview(0L);
1834
    drawbackground();
1835
    displayrooms(myconnectindex,65536);
1836
 
564 terminx 1837
    for (i=0;i<ud.multimode;i++)
1838
        clearbufbyte(&g_player[i].playerquitflag,1,0x01010101);
1839
    g_player[myconnectindex].ps->over_shoulder_on = 0;
5 Plagman 1840
 
1841
    clearfrags();
1842
 
1843
    resettimevars();  // Here we go
1844
 
1845
    //Bsprintf(g_szBuf,"ENTERLEVEL L=%d V=%d",ud.level_number, ud.volume_number);
1846
    //AddLog(g_szBuf);
1847
    // variables are set by pointer...
317 terminx 1848
 
5 Plagman 1849
    OnEvent(EVENT_ENTERLEVEL, -1, -1, -1);
584 terminx 1850
    initprintf("E%dL%d: %s\n",ud.volume_number+1,ud.level_number+1,map[(ud.volume_number*MAXLEVELS)+ud.level_number].name);
5 Plagman 1851
    return 0;
1852
}