Subversion Repositories eduke32

Rev

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