Subversion Repositories eduke32

Rev

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

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