Subversion Repositories eduke32

Rev

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