Subversion Repositories eduke32

Rev

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