Subversion Repositories eduke32

Rev

Rev 11 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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