Subversion Repositories eduke32

Rev

Rev 437 | Rev 471 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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