1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1996, 2003 - 3D Realms Entertainment
4 Copyright (C) 2017-2019 Nuke.YKT
5 
6 This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
7 
8 Duke Nukem 3D is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
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 Original Source: 1996 - Todd Replogle
24 Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
25 */
26 //-------------------------------------------------------------------------
27 
28 #include "duke3d.h"
29 
30 #include "lava.h"
31 #include "warpfx.h"
32 
33 extern char everyothertime;
34 short which_palookup = 9;
35 
36 short lastlevel = 0;
37 short turdlevel = 0;
38 
39 short ambientlotag[64];
40 short ambientsprite[64];
41 short ambienthitag[64];
42 char shadedsector[MAXSECTORS];
43 short ambientfx;
44 
45 extern int crashcnt;
46 
xyzmirror(short i,short wn)47 void xyzmirror(short i,short wn)
48 {
49     if (waloff[wn] == 0) loadtile(wn);
50 	setviewtotile(wn,tilesizy[wn],tilesizx[wn]);
51 
52 	drawrooms(SX,SY,SZ,SA,100+sprite[i].shade,SECT);
53 	display_mirror = 1; animatesprites(SX,SY,SA,65536L); display_mirror = 0;
54 	drawmasks();
55 
56 	setviewback();
57 	squarerotatetile(wn);
58 }
59 
vscrn(void)60 void vscrn(void)
61 {
62      long i, j, ss, x1, x2, y1, y2, unk;
63 
64 	 if(ud.screen_size < 0) ud.screen_size = 0;
65 	 else if(ud.screen_size > 63) ud.screen_size = 64;
66 
67      if(ud.screen_size == 0) flushperms();
68 
69      if(ud.screen_size == 12)
70      {
71 	    ss = max(ud.screen_size-10,0);
72         unk = 0;
73      }
74      else
75 	    ss = max(ud.screen_size-8,0);
76 
77 
78      if (ud.screen_size == 12)
79          x1 = scale(unk,xdim,160);
80      else
81 	     x1 = scale(ss,xdim,160);
82 	 x2 = xdim-x1;
83 
84      if (ud.screen_size == 12)
85          y1 = ss = 0;
86      else
87          y1 = ss;
88 
89 	 y2 = 200;
90 
91      if ( ud.screen_size > 0 && ud.coop != 1 && ud.multimode > 1)
92 	 {
93          j = 0;
94          for(i=connecthead;i>=0;i=connectpoint2[i])
95              if(i > j) j = i;
96 
97          if (j >= 1) y1 += 8;
98          if (j >= 4) y1 += 8;
99          if (j >= 8) y1 += 8;
100          if (j >= 12) y1 += 8;
101 	 }
102 
103 	 if (ud.screen_size == 8) y2 -= (ss+34);
104      else if (ud.screen_size > 8) y2-= (ss+42);
105 
106 	 y1 = scale(y1,ydim,200);
107 	 y2 = scale(y2,ydim,200);
108 
109 	 setview(x1,y1,x2-1,y2-1);
110 
111      pub = NUMPAGES;
112      pus = NUMPAGES;
113 }
114 
pickrandomspot(short snum)115 void pickrandomspot(short snum)
116 {
117     struct player_struct *p;
118     short i;
119 
120     p = &ps[snum];
121 
122     if( ud.multimode > 1 && ud.coop != 1)
123         i = TRAND%numplayersprites;
124     else i = snum;
125 
126     p->bobposx = p->oposx = p->posx = po[i].ox;
127     p->bobposy = p->oposy = p->posy = po[i].oy;
128     p->oposz = p->posz = po[i].oz;
129     p->ang = po[i].oa;
130     p->cursectnum = po[i].os;
131 }
132 
tloadtile(short tilenume)133 tloadtile(short tilenume)
134 {
135     gotpic[tilenume>>3] |= (1<<(tilenume&7));
136 }
137 
138 
docacheit(void)139 void docacheit(void)
140 {
141     long i,j;
142 
143     j = 0;
144 
145     for(i=0;i<MAXTILES;i++)
146         if( (gotpic[i>>3]&(1<<(i&7))) && waloff[i] == 0)
147     {
148         loadtile((short)i);
149         j++;
150         if((j&7) == 0) getpackets();
151     }
152 
153     clearbufbyte(gotpic,sizeof(gotpic),0L);
154 
155 }
156 
157 extern long wupass;
resetplayerstats(short snum)158 void resetplayerstats(short snum)
159 {
160     struct player_struct *p;
161     short i;
162 
163     p = &ps[snum];
164 
165     ud.show_help        = 0;
166     ud.showallmap       = 0;
167     p->dead_flag        = 0;
168     p->wackedbyactor    = -1;
169     p->falling_counter  = 0;
170     p->quick_kick       = 0;
171     p->subweapon        = 0;
172     p->last_full_weapon = 0;
173     p->ftq              = 0;
174     p->fta              = 0;
175     p->tipincs          = 0;
176     p->buttonpalette    = 0;
177     p->actorsqu         =-1;
178     p->invdisptime      = 0;
179     p->refresh_inventory= 0;
180     p->last_pissed_time = 0;
181     p->holster_weapon   = 0;
182     p->pycount          = 0;
183     p->pyoff            = 0;
184     p->opyoff           = 0;
185     p->loogcnt          = 0;
186     p->angvel           = 0;
187     p->weapon_sway      = 0;
188 //    p->select_dir       = 0;
189     p->extra_extra8     = 0;
190     p->show_empty_weapon= 0;
191     p->dummyplayersprite=-1;
192     p->crack_time       = 0;
193     p->hbomb_hold_delay = 0;
194     p->transporter_hold = 0;
195     p->wantweaponfire  = -1;
196     p->hurt_delay       = 0;
197 #ifdef RRRA
198     p->hurt_delay2      = 0;
199 #endif
200     p->footprintcount   = 0;
201     p->footprintpal     = 0;
202     p->footprintshade   = 0;
203     p->jumping_toggle   = 0;
204     p->ohoriz = p->horiz= 140;
205     p->horizoff         = 0;
206     p->bobcounter       = 0;
207     p->on_ground        = 0;
208     p->player_par       = 0;
209     p->return_to_center = 9;
210     p->airleft          = 15*26;
211     p->rapid_fire_hold  = 0;
212     p->toggle_key_flag  = 0;
213     p->access_spritenum = -1;
214     if(ud.multimode > 1 && ud.coop != 1 )
215         p->got_access = 7;
216     else p->got_access      = 0;
217     p->random_club_frame= 0;
218     pus = 1;
219     p->on_warping_sector = 0;
220     p->spritebridge      = 0;
221     p->palette = (char *) &palette[0];
222 
223     if(p->steroids_amount < 400 )
224     {
225         p->steroids_amount = 0;
226         p->inven_icon = 0;
227     }
228     p->heat_on =            0;
229     p->jetpack_on =         0;
230     p->holoduke_on =       -1;
231 
232     p->look_ang          = 512 - ((ud.level_number&1)<<10);
233 
234     p->rotscrnang        = 0;
235     p->newowner          =-1;
236     p->jumping_counter   = 0;
237     p->hard_landing      = 0;
238     p->posxv             = 0;
239     p->posyv             = 0;
240     p->poszv             = 0;
241     fricxv            = 0;
242     fricyv            = 0;
243     p->somethingonplayer =-1;
244     p->one_eighty_count  = 0;
245     p->cheat_phase       = 0;
246 
247     p->on_crane          = -1;
248 
249     if(p->curr_weapon == PISTOL_WEAPON)
250         p->kickback_pic  = 22;
251     else p->kickback_pic = 0;
252 
253     p->weapon_pos        = 6;
254     p->walking_snd_toggle= 0;
255     p->weapon_ang        = 0;
256 
257     p->knuckle_incs      = 1;
258     p->fist_incs = 0;
259     p->knee_incs         = 0;
260     p->jetpack_on        = 0;
261     setpal(p);
262     p->at280 = 0;
263 #ifndef RRRA
264     p->fogtype = 0;
265 #endif
266     p->at286 = 0;
267     p->at28a = 0;
268     p->at28e = 0;
269     p->at290 = 0;
270     if (ud.multimode > 1 && ud.coop != 1)
271     {
272         p->keys[0] = 1;
273         p->keys[1] = 1;
274         p->keys[2] = 1;
275         p->keys[3] = 1;
276         p->keys[4] = 1;
277     }
278     else
279     {
280         p->keys[0] = 0;
281         p->keys[1] = 0;
282         p->keys[2] = 0;
283         p->keys[3] = 0;
284         p->keys[4] = 0;
285     }
286     wupass = 0;
287     p->at582 = 0;
288     p->drunkang = 1647;
289     p->eatang = 1647;
290     p->drink_amt = 0;
291     p->eat = 0;
292     p->at58e = 4096;
293     p->at592 = 4096;
294     p->at596 = 1;
295     p->at597 = 1;
296     p->at598 = 0;
297     p->at599 = 0;
298     p->at59a = 0;
299     p->at57c = 0;
300     p->at57e = 0;
301     p->at59b = 0;
302     p->at59d = 0;
303 #ifdef RRRA
304     p->raat605 = 0;
305     if (p->OnMotorcycle)
306     {
307         p->OnMotorcycle = 0;
308         p->gotweapon[RA13_WEAPON] = 0;
309         p->curr_weapon = RA15_WEAPON;
310     }
311     p->raat60b = 0;
312     p->raat5b5 = 0;
313     p->MotoOnGround = 1;
314     p->raat5b9 = 0;
315     p->MotoSpeed = 0;
316     p->TiltStatus = 0;
317     p->raat5c1 = 0;
318     p->VBumpTarget = 0;
319     p->VBumpNow  =0;
320     p->raat5c7 = 0;
321     p->TurbCount = 0;
322     p->raat5cd = 0;
323     p->raat5cf = 0;
324     if (p->OnBoat)
325     {
326         p->OnBoat = 0;
327         p->gotweapon[RA14_WEAPON] = 0;
328         p->curr_weapon = RA15_WEAPON;
329     }
330     p->NotOnWater = 0;
331     p->raat5d9 = 0;
332     p->SeaSick = 0;
333     p->raat5e1 = 0;
334     p->nocheat = 0;
335     p->DrugMode = 0;
336     p->raat5f1 = 0;
337     p->raat5f3 = 0;
338     p->raat5f5 = 0;
339     p->raat5f7 = 0;
340 #endif
341     resetlanepics();
342 #ifdef RRRA
343     if (numplayers < 2)
344 #endif
345     cdromtime = 0;
346 #ifdef RRRA
347     if (numplayers < 2)
348     {
349         ufospawn = 3;
350         if (ufospawn > 32)
351             ufospawn = 32;
352         ufocnt = 0;
353         hulkspawn = ud.m_player_skill + 1;
354     }
355     else
356     {
357         ufospawn = 0;
358         ufocnt = 0;
359         hulkspawn = 0;
360     }
361 #else
362     if (numplayers < 2)
363     {
364         ufospawn = ud.m_player_skill*4+1;
365         if (ufospawn > 32)
366             ufospawn = 32;
367         ufocnt = 0;
368         hulkspawn = ud.m_player_skill + 1;
369     }
370     else
371     {
372         ufospawn = 32;
373         ufocnt = 0;
374         hulkspawn = 2;
375     }
376 #endif
377 }
378 
379 
380 
resetweapons(short snum)381 void resetweapons(short snum)
382 {
383     short  weapon;
384     struct player_struct *p;
385 
386     p = &ps[snum];
387 
388     for ( weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++ )
389         p->gotweapon[weapon] = 0;
390     for ( weapon = PISTOL_WEAPON; weapon < MAX_WEAPONS; weapon++ )
391         p->ammo_amount[weapon] = 0;
392 
393 #ifdef RRRA
394     p->raat605 = 0;
395 #endif
396     p->weapon_pos = 6;
397     p->kickback_pic = 5;
398     p->curr_weapon = PISTOL_WEAPON;
399     p->gotweapon[PISTOL_WEAPON] = 1;
400     p->gotweapon[KNEE_WEAPON] = 1;
401     p->ammo_amount[PISTOL_WEAPON] = 48;
402 #ifdef RRRA
403     p->ammo_amount[KNEE_WEAPON] = 1;
404     p->gotweapon[RA15_WEAPON] = 1;
405     p->ammo_amount[RA15_WEAPON] = 1;
406 #endif
407     p->gotweapon[HANDREMOTE_WEAPON] = 1;
408     p->last_weapon = -1;
409 
410     p->show_empty_weapon= 0;
411     p->last_pissed_time = 0;
412     p->holster_weapon = 0;
413 #ifdef RRRA
414     p->OnMotorcycle = 0;
415     p->raat5b9 = 0;
416     p->OnBoat = 0;
417     p->raat60b = 0;
418 #endif
419 }
420 
resetinventory(short snum)421 void resetinventory(short snum)
422 {
423     struct player_struct *p;
424     short i;
425 
426     p = &ps[snum];
427 
428     p->inven_icon       = 0;
429     p->boot_amount = 0;
430     p->scuba_on =           0;p->scuba_amount =         0;
431     p->heat_amount        = 0;p->heat_on = 0;
432     p->jetpack_on =         0;p->jetpack_amount =       0;
433     p->shield_amount =      max_armour_amount;
434     p->holoduke_on = -1;
435     p->holoduke_amount =    0;
436     p->firstaid_amount = 0;
437     p->steroids_amount = 0;
438     p->inven_icon = 0;
439 
440     if (ud.multimode > 1 && ud.coop != 1)
441     {
442         p->keys[0] = 1;
443         p->keys[1] = 1;
444         p->keys[2] = 1;
445         p->keys[3] = 1;
446         p->keys[4] = 1;
447     }
448     else
449     {
450         p->keys[0] = 0;
451         p->keys[1] = 0;
452         p->keys[2] = 0;
453         p->keys[3] = 0;
454         p->keys[4] = 0;
455     }
456 
457     p->at582 = 0;
458     p->drunkang = 1647;
459     p->eatang = 1647;
460     p->drink_amt = 0;
461     p->eat = 0;
462     p->at58e = 0;
463     p->at592 = 0;
464     p->at596 = 1;
465     p->at597 = 1;
466     p->at598 = 0;
467     p->at599 = 0;
468     p->at59a = 0;
469     p->at57c = 0;
470     p->at57e = 0;
471     p->at59b = 0;
472     p->at59d = 0;
473     resetlanepics();
474 
475     if (numplayers < 2)
476     {
477         ufospawn = ud.m_player_skill*4+1;
478         if (ufospawn > 32)
479             ufospawn = 32;
480         ufocnt = 0;
481         hulkspawn = ud.m_player_skill + 1;
482     }
483     else
484     {
485         ufospawn = 32;
486         ufocnt = 0;
487         hulkspawn = 2;
488     }
489 }
490 
491 
resetprestat(short snum,char g)492 void resetprestat(short snum,char g)
493 {
494     struct player_struct *p;
495     short i;
496 
497     p = &ps[snum];
498 
499     spriteqloc = 0;
500     for(i=0;i<spriteqamount;i++) spriteq[i] = -1;
501 
502     p->hbomb_on          = 0;
503     p->cheat_phase       = 0;
504     p->pals_time         = 0;
505     p->toggle_key_flag   = 0;
506     p->secret_rooms      = 0;
507     p->max_secret_rooms  = 0;
508     p->actors_killed     = 0;
509     p->max_actors_killed = 0;
510     p->lastrandomspot = 0;
511     p->weapon_pos = 6;
512     p->kickback_pic = 5;
513     p->last_weapon = -1;
514     p->weapreccnt = 0;
515     p->show_empty_weapon= 0;
516     p->holster_weapon = 0;
517     p->last_pissed_time = 0;
518 
519     p->one_parallax_sectnum = -1;
520     p->visibility = ud.const_visibility;
521 
522     screenpeek              = myconnectindex;
523     numanimwalls            = 0;
524     numcyclers              = 0;
525     animatecnt              = 0;
526     parallaxtype            = 0;
527     randomseed              = 17L;
528     ud.pause_on             = 0;
529     ud.camerasprite         =-1;
530     ud.eog                  = 0;
531     tempwallptr             = 0;
532     camsprite               =-1;
533     earthquaketime          = 0;
534 
535 #ifdef RRRA
536     WindTime = 0;
537     WindDir = 0;
538     word_119BD8 = 0;
539     word_119BE2 = 0;
540     BellTime = 0;
541     word_119BE0 = 0;
542 #endif
543 
544     numinterpolations = 0;
545     startofdynamicinterpolations = 0;
546 
547     if( ( (g&MODE_EOL) != MODE_EOL && numplayers < 2) || (ud.coop != 1 && numplayers > 1) )
548     {
549         resetweapons(snum);
550         resetinventory(snum);
551     }
552     else if(p->curr_weapon == HANDREMOTE_WEAPON)
553     {
554         p->ammo_amount[HANDBOMB_WEAPON]++;
555         p->curr_weapon = HANDBOMB_WEAPON;
556     }
557 
558     p->timebeforeexit   = 0;
559     p->customexitsound  = 0;
560 
561     p->at280 = 0;
562 #ifndef RRRA
563     p->fogtype = 0;
564 #endif
565     p->at286 = 131072;
566     p->at28a = 131072;
567     p->at28e = 0;
568     p->at290 = 0;
569 
570     if (ud.multimode > 1 && ud.coop != 1)
571     {
572         p->keys[0] = 1;
573         p->keys[1] = 1;
574         p->keys[2] = 1;
575         p->keys[3] = 1;
576         p->keys[4] = 1;
577     }
578     else
579     {
580         p->keys[0] = 0;
581         p->keys[1] = 0;
582         p->keys[2] = 0;
583         p->keys[3] = 0;
584         p->keys[4] = 0;
585     }
586 
587     p->at582 = 0;
588     p->drunkang = 1647;
589     p->eatang = 1647;
590     p->drink_amt = 0;
591     p->eat = 0;
592     p->at58e = 0;
593     p->at592 = 0;
594     p->at596 = 1;
595     p->at597 = 1;
596     p->at598 = 0;
597     p->at599 = 0;
598     p->at59a = 0;
599     p->at57c = 0;
600     p->at57e = 0;
601     p->at59b = 0;
602     p->at59d = 0;
603     resetlanepics();
604 
605     if (numplayers < 2)
606     {
607         ufospawn = ud.m_player_skill*4+1;
608         if (ufospawn > 32)
609             ufospawn = 32;
610         ufocnt = 0;
611         hulkspawn = ud.m_player_skill + 1;
612     }
613     else
614     {
615         ufospawn = 32;
616         ufocnt = 0;
617         hulkspawn = 2;
618     }
619 
620 }
621 
setupbackdrop(short backpicnum)622 void setupbackdrop(short backpicnum)
623 {
624     short i,sky;
625 
626     sky = 0;
627     for(i=0;i<8;i++) pskyoff[i]=0;
628 
629     switch(backpicnum)
630     {
631         case MOONSKY1:
632         case BIGORBIT1:
633         case LA:
634             sky = backpicnum;
635             break;
636     }
637 
638     parallaxyscale = 32768;
639 
640     switch(sky)
641     {
642         case MOONSKY1 :
643             pskyoff[6]=1; pskyoff[1]=2; pskyoff[4]=2; pskyoff[2]=3;
644             break;
645         case BIGORBIT1: // orbit
646             pskyoff[5]=1; pskyoff[6]=2; pskyoff[7]=3; pskyoff[2]=4;
647             break;
648         case LA:
649             parallaxyscale = 16384+1024;
650             pskyoff[0]=1; pskyoff[1]=2; pskyoff[2]=1; pskyoff[3]=3;
651             pskyoff[4]=4; pskyoff[5]=0; pskyoff[6]=2; pskyoff[7]=3;
652             break;
653 #ifdef RRRA
654         default:
655             if (tilesizx[backpicnum] == 512)
656             {
657                 pskyoff[0] = 0;
658                 pskyoff[1] = 0;
659                 pskybits = 1;
660                 return;
661             }
662             if (tilesizx[backpicnum] == 1024)
663             {
664                 pskyoff[0] = 0;
665                 pskybits = 0;
666                 return;
667             }
668             break;
669 #endif
670    }
671 
672    pskybits=3;
673 }
674 
cachespritenum(short i)675 void cachespritenum(short i)
676 {
677     char maxc;
678     short j;
679 
680     if(ud.monsters_off && badguy(&sprite[i])) return;
681 
682     maxc = 1;
683 
684     switch(PN)
685     {
686         case HYDRENT:
687             tloadtile(BROKEFIREHYDRENT);
688             for(j = TOILETWATER; j < (TOILETWATER+4); j++)
689                 if(waloff[j] == 0) tloadtile(j);
690             break;
691         case RRTILE2121:
692         case RRTILE2122:
693             if (waloff[j] == 0) tloadtile(j);
694             break;
695         case TOILET:
696             tloadtile(TOILETBROKE);
697             for(j = TOILETWATER; j < (TOILETWATER+4); j++)
698                 if(waloff[j] == 0) tloadtile(j);
699             break;
700         case STALL:
701             tloadtile(STALLBROKE);
702             for(j = TOILETWATER; j < (TOILETWATER+4); j++)
703                 if(waloff[j] == 0) tloadtile(j);
704             break;
705         case FORCERIPPLE:
706             maxc = 9;
707             break;
708         case RUBBERCAN:
709             maxc = 2;
710             break;
711         case TOILETWATER:
712             maxc = 4;
713             break;
714         case BUBBASTAND:
715             for(j = BUBBASCRATCH; j <= (BUBBASCRATCH+47); j++)
716                 if(waloff[j] == 0)
717                     tloadtile(j);
718             maxc = 0;
719             break;
720 #ifdef RRRA
721         case SBSWIPE:
722             for(j = SBSWIPE; j <= (SBSWIPE+29); j++)
723                 if(waloff[j] == 0)
724                     tloadtile(j);
725             maxc = 0;
726             break;
727 
728 #endif
729         case COOT:
730             for(j = COOT; j <= (COOT+217); j++)
731                 if(waloff[j] == 0)
732                     tloadtile(j);
733             for(j=COOTJIBA;j<COOTJIBC+4;j++)
734                 if(waloff[j] == 0)
735                     tloadtile(j);
736             maxc = 0;
737             break;
738         case LTH:
739             maxc = 105;
740             for(j = LTH; j < (LTH+maxc); j++)
741                 if(waloff[j] == 0)
742                     tloadtile(j);
743             maxc = 0;
744             break;
745         case BILLYRAY:
746             maxc = 144;
747             for(j = BILLYWALK; j < (BILLYWALK+maxc); j++)
748                 if(waloff[j] == 0)
749                     tloadtile(j);
750             for(j=BILLYJIBA;j<=BILLYJIBB+4;j++)
751                 if(waloff[j] == 0)
752                     tloadtile(j);
753             maxc = 0;
754             break;
755         case COW:
756             maxc = 56;
757             for(j = PN; j < (PN+maxc); j++)
758                 if(waloff[j] == 0)
759                     tloadtile(j);
760             maxc = 0;
761             break;
762         case DOGRUN:
763             for(j = DOGATTACK; j <= DOGATTACK+35; j++)
764                 if(waloff[j] == 0)
765                     tloadtile(j);
766             for(j = DOGRUN; j <= DOGRUN+80; j++)
767                 if(waloff[j] == 0)
768                     tloadtile(j);
769             maxc = 0;
770             break;
771 #ifdef RRRA
772         case RABBIT:
773             for(j = RABBIT; j <= RABBIT+54; j++)
774                 if(waloff[j] == 0)
775                     tloadtile(j);
776             for(j = RABBIT+56; j <= RABBIT+56+49; j++)
777                 if(waloff[j] == 0)
778                     tloadtile(j);
779             for(j = RABBIT+56; j <= RABBIT+56+49; j++)
780                 if(waloff[j] == 0)
781                     tloadtile(j);
782             maxc = 0;
783             break;
784         case BIKERB:
785         case BIKERBV2:
786             for(j = BIKERB; j <= BIKERB+104; j++)
787                 if(waloff[j] == 0)
788                     tloadtile(j);
789             maxc = 0;
790             break;
791         case BIKER:
792             for(j = BIKER; j <= BIKER+116; j++)
793                 if(waloff[j] == 0)
794                     tloadtile(j);
795             for(j = BIKER+150; j <= BIKER+150+104; j++)
796                 if(waloff[j] == 0)
797                     tloadtile(j);
798             maxc = 0;
799             break;
800         case CHEER:
801             for(j = CHEER; j <= CHEER+44; j++)
802                 if(waloff[j] == 0)
803                     tloadtile(j);
804             for(j = CHEER+47; j <= CHEER+47+211; j++)
805                 if(waloff[j] == 0)
806                     tloadtile(j);
807             for(j = CHEER+262; j <= CHEER+262+72; j++)
808                 if(waloff[j] == 0)
809                     tloadtile(j);
810             maxc = 0;
811             break;
812         case CHEERB:
813             for(j = CHEERB; j <= CHEERB+83; j++)
814                 if(waloff[j] == 0)
815                     tloadtile(j);
816             for(j = CHEERB+157; j <= CHEERB+157+83; j++)
817                 if(waloff[j] == 0)
818                     tloadtile(j);
819             maxc = 0;
820             break;
821         case MAMA:
822             for(j = MAMA; j <= MAMA+78; j++)
823                 if(waloff[j] == 0)
824                     tloadtile(j);
825             for(j = MAMA+80; j <= MAMA+80+7; j++)
826                 if(waloff[j] == 0)
827                     tloadtile(j);
828             for(j = MAMA+90; j <= MAMA+90+94; j++)
829                 if(waloff[j] == 0)
830                     tloadtile(j);
831             maxc = 0;
832             break;
833         case CHEERBOAT:
834             if (waloff[CHEERBOAT] == 0) tloadtile(CHEERBOAT);
835             maxc = 0;
836             break;
837         case HULKBOAT:
838             if (waloff[HULKBOAT] == 0) tloadtile(HULKBOAT);
839             maxc = 0;
840             break;
841         case MINIONBOAT:
842             if (waloff[MINIONBOAT] == 0) tloadtile(MINIONBOAT);
843             maxc = 0;
844             break;
845         case BILLYPLAY:
846             for(j = BILLYPLAY; j <= BILLYPLAY+2; j++)
847                 if(waloff[j] == 0)
848                     tloadtile(j);
849             maxc = 0;
850             break;
851         case COOTPLAY:
852             for(j = COOTPLAY; j <= COOTPLAY+4; j++)
853                 if(waloff[j] == 0)
854                     tloadtile(j);
855             maxc = 0;
856             break;
857 #endif
858         case PIG:
859         case PIGSTAYPUT:
860             maxc = 68;
861             break;
862         case TORNADO:
863             maxc = 7;
864             break;
865         case HEN:
866         case HENSTAND:
867             maxc = 34;
868             break;
869         case APLAYER:
870             maxc = 0;
871             if(ud.multimode > 1)
872             {
873                 maxc = 5;
874                 for(j = APLAYER;j < APLAYER+220; j++)
875                     if(waloff[j] == 0)
876                         tloadtile(j);
877                 for(j = DUKEGUN;j < DUKELEG+4; j++)
878                     if(waloff[j] == 0)
879                         tloadtile(j);
880             }
881             break;
882         case ATOMICHEALTH:
883             maxc = 14;
884             break;
885         case DRONE:
886             maxc = 6;
887             break;
888         case EXPLODINGBARREL:
889         case SEENINE:
890         case OOZFILTER:
891             maxc = 3;
892             break;
893         case NUKEBARREL:
894         case CAMERA1:
895             maxc = 5;
896             break;
897         case VIXEN:
898             maxc = 214;
899             for(j = PN; j < PN+maxc; j++)
900                 if(waloff[j] == 0)
901                     tloadtile(j);
902             maxc = 0;
903             break;
904 #ifndef RRRA
905         case SBMOVE:
906             maxc = 54;
907             for(j = PN; j < PN+maxc; j++)
908                 if(waloff[j] == 0)
909                     tloadtile(j);
910             maxc = 100;
911             for(j = SBMOVE; j < SBMOVE+maxc; j++)
912                 if(waloff[j] == 0)
913                     tloadtile(j);
914             maxc = 0;
915             break;
916 #endif
917         case HULK:
918             maxc = 40;
919             for(j = PN-41; j < PN+maxc-41; j++)
920                 if(waloff[j] == 0)
921                     tloadtile(j);
922             for(j = HULKJIBA; j <= HULKJIBC+4; j++)
923                 if(waloff[j] == 0)
924                     tloadtile(j);
925             maxc = 0;
926             break;
927         case MINION:
928             maxc = 141;
929             for(j = PN; j < PN+maxc; j++)
930                 if(waloff[j] == 0)
931                     tloadtile(j);
932             for(j = MINJIBA; j <= MINJIBC+4; j++)
933                 if(waloff[j] == 0)
934                     tloadtile(j);
935             maxc = 0;
936             break;
937 
938 
939     }
940 
941     for(j = PN; j < (PN+maxc); j++)
942         if(waloff[j] == 0)
943             tloadtile(j);
944 }
945 
cachegoodsprites(void)946 void cachegoodsprites(void)
947 {
948     short i;
949 
950     if(ud.screen_size >= 8)
951     {
952         if(waloff[BOTTOMSTATUSBAR] == 0)
953             tloadtile(BOTTOMSTATUSBAR);
954         if( ud.multimode > 1)
955         {
956             if(waloff[FRAGBAR] == 0)
957                 tloadtile(FRAGBAR);
958             for(i=MINIFONT;i<MINIFONT+63;i++)
959                 if(waloff[i] == 0)
960                     tloadtile(i);
961         }
962     }
963 
964     //tloadtile(VIEWSCREEN);
965 
966     for(i=STARTALPHANUM;i<ENDALPHANUM+1;i++)
967         if (waloff[i] == 0)
968             tloadtile(i);
969 
970     for(i=FOOTPRINTS;i<FOOTPRINTS+3;i++)
971         if (waloff[i] == 0)
972             tloadtile(i);
973 
974     for( i = BIGALPHANUM; i < BIGALPHANUM+82; i++)
975         if(waloff[i] == 0)
976             tloadtile(i);
977 
978     for( i = BURNING; i < BURNING+14; i++)
979         if(waloff[i] == 0)
980             tloadtile(i);
981 
982     for( i = FIRSTGUN; i < FIRSTGUN+10 ; i++ )
983         if(waloff[i] == 0)
984             tloadtile(i);
985 
986     for( i = EXPLOSION2; i < EXPLOSION2+21 ; i++ )
987         if(waloff[i] == 0)
988             tloadtile(i);
989 
990     tloadtile(BULLETHOLE);
991 
992     for( i = SHOTGUN; i < SHOTGUN+8 ; i++ )
993         if(waloff[i] == 0)
994             tloadtile(i);
995 
996     tloadtile(FOOTPRINTS);
997 
998     for( i = JIBS1; i < (JIBS5+5); i++)
999         if(waloff[i] == 0)
1000             tloadtile(i);
1001 
1002     for( i = SCRAP1; i < (SCRAP1+19); i++)
1003         if(waloff[i] == 0)
1004             tloadtile(i);
1005 
1006     for( i = SMALLSMOKE; i < (SMALLSMOKE+4); i++)
1007         if(waloff[i] == 0)
1008             tloadtile(i);
1009 
1010 #ifdef RRRA
1011     if (ud.volume_number == 0 && ud.level_number == 4)
1012     {
1013         if(waloff[RRTILE2577] == 0)
1014             tloadtile(RRTILE2577);
1015     }
1016 #else
1017     if (ud.volume_number == 1 && ud.level_number == 2)
1018     {
1019         if(waloff[RRTILE3190] == 0)
1020             tloadtile(RRTILE3190);
1021         if(waloff[RRTILE3191] == 0)
1022             tloadtile(RRTILE3191);
1023         if(waloff[RRTILE3192] == 0)
1024             tloadtile(RRTILE3192);
1025         if(waloff[RRTILE3144] == 0)
1026             tloadtile(RRTILE3144);
1027         if(waloff[RRTILE3139] == 0)
1028             tloadtile(RRTILE3139);
1029         if(waloff[RRTILE3132] == 0)
1030             tloadtile(RRTILE3132);
1031         if(waloff[RRTILE3120] == 0)
1032             tloadtile(RRTILE3120);
1033         if(waloff[RRTILE3121] == 0)
1034             tloadtile(RRTILE3121);
1035         if(waloff[RRTILE3122] == 0)
1036             tloadtile(RRTILE3122);
1037         if(waloff[RRTILE3123] == 0)
1038             tloadtile(RRTILE3123);
1039         if(waloff[RRTILE3124] == 0)
1040             tloadtile(RRTILE3124);
1041     }
1042 #endif
1043     if (lastlevel)
1044     {
1045         i = UFO1;
1046         if(waloff[i] == 0)
1047             tloadtile(i);
1048         i = UFO2;
1049         if (waloff[i] == 0)
1050             tloadtile(i);
1051         i = UFO3;
1052         if (waloff[i] == 0)
1053             tloadtile(i);
1054         i = UFO4;
1055         if (waloff[i] == 0)
1056             tloadtile(i);
1057         i = UFO5;
1058         if (waloff[i] == 0)
1059             tloadtile(i);
1060     }
1061 }
1062 
prelevel(char g)1063 void prelevel(char g)
1064 {
1065 #if 1
1066     struct player_struct *p;
1067     short i;
1068     short nexti;
1069     short j;
1070     short startwall;
1071     short endwall;
1072     short lotaglist;
1073     short k;
1074     short lotags[65];
1075     int speed;
1076     int dist;
1077     short sound;
1078     sound = 0;
1079 
1080     p = &ps[screenpeek];
1081 #else
1082     short i, nexti, j, startwall, endwall, lotaglist, k;
1083     short lotags[65];
1084     long p2;
1085     struct player_struct *p;
1086     short p3;
1087     long p1;
1088     p3 = 0;
1089 
1090     p = &ps[screenpeek];
1091 #endif
1092 
1093 #ifdef RRRA
1094     sub_86730(0);
1095     p->fogtype = 0;
1096     p->raat5dd = 0;
1097     p->raat5fd = 0;
1098     p->raat601 = 0;
1099     p->SlotWin = 0;
1100     p->raat607 = 0;
1101     p->raat609 = 0;
1102     word_119BDA = 15;
1103     word_119BDC = 0;
1104     word_119BE2 = 0;
1105     if (ud.level_number == 3 && ud.volume_number == 0)
1106         word_119BDA = 5;
1107     else if (ud.level_number == 2 && ud.volume_number == 1)
1108         word_119BDA = 10;
1109     else if (ud.level_number == 6 && ud.volume_number == 1)
1110         word_119BDA = 15;
1111     else if (ud.level_number == 4 && ud.volume_number == 1)
1112         ps[myconnectindex].steroids_amount = 0;
1113 #endif
1114 
1115     clearbufbyte(show2dsector,sizeof(show2dsector),0L);
1116     clearbufbyte(show2dwall,sizeof(show2dwall),0L);
1117     clearbufbyte(show2dsprite,sizeof(show2dsprite),0L);
1118 
1119     for (i = 0; i < MAXSECTORS; i++)
1120         shadedsector[i] = 0;
1121 
1122     for (i = 0; i < 64; i++)
1123     {
1124         geosectorwarp[i] = -1;
1125         geosectorwarp2[i] = -1;
1126     }
1127 
1128     for (i = 0; i < 64; i++)
1129     {
1130         ambienthitag[i] = -1;
1131         ambientlotag[i] = -1;
1132         ambientsprite[i] = -1;
1133     }
1134 
1135     resetprestat(0,g);
1136     lightnincnt = 0;
1137     torchcnt = 0;
1138     geocnt = 0;
1139     jaildoorcnt = 0;
1140     minecartcnt = 0;
1141     ambientfx = 0;
1142     crashcnt = 0;
1143     thunderon = 0;
1144     chickenplant = 0;
1145 #ifdef RRRA
1146     WindTime = 0;
1147     WindDir = 0;
1148     word_119BD8 = 0;
1149     word_119BE2 = 0;
1150     word_119BDA = 15;
1151     BellTime = 0;
1152     word_119BE0 = 0;
1153 
1154     for (j = 0; j < MAXSPRITES; j++)
1155     {
1156         if (sprite[j].pal == 100)
1157         {
1158             if (numplayers > 1)
1159                 deletesprite(j);
1160             else
1161                 sprite[j].pal = 0;
1162         }
1163         else if (sprite[j].pal == 101)
1164         {
1165             sprite[j].extra = 0;
1166             sprite[j].hitag = 1;
1167             sprite[j].pal = 0;
1168             changespritestat(j,118);
1169         }
1170     }
1171 #endif
1172 
1173     for(i=0;i<numsectors;i++)
1174     {
1175         if (sector[i].ceilingpicnum == RRTILE2577)
1176             thunderon = 1;
1177         sector[i].extra = 256;
1178 
1179         switch(sector[i].lotag)
1180         {
1181             case 41:
1182                 k = headspritesect[i];
1183                 while (k != -1)
1184                 {
1185                     nexti = nextspritesect[k];
1186                     if (sprite[k].picnum == RRTILE11)
1187                     {
1188                         dist = sprite[k].lotag<<4;
1189                         speed = sprite[k].hitag;
1190                         deletesprite(k);
1191                     }
1192                     if (sprite[k].picnum == RRTILE38)
1193                     {
1194                         sound = sprite[k].lotag;
1195                         deletesprite(k);
1196                     }
1197                     k = nexti;
1198                 }
1199                 for(j=0;j<numsectors;j++)
1200                 {
1201                     if (sector[i].hitag == sector[j].hitag && j != i)
1202                     {
1203                         if (jaildoorcnt > 32)
1204                             gameexit("\nToo many jaildoor sectors");
1205                         jaildoordist[jaildoorcnt] = dist;
1206                         jaildoorspeed[jaildoorcnt] = speed;
1207                         jaildoorsecthtag[jaildoorcnt] = sector[i].hitag;
1208                         jaildoorsect[jaildoorcnt] = j;
1209                         jaildoordrag[jaildoorcnt] = 0;
1210                         jaildooropen[jaildoorcnt] = 0;
1211                         jaildoordir[jaildoorcnt] = sector[j].lotag;
1212                         jaildoorsound[jaildoorcnt] = sound;
1213                         jaildoorcnt++;
1214                     }
1215                 }
1216                 break;
1217             case 42:
1218             {
1219                 short ii;
1220                 k = headspritesect[i];
1221                 while (k != -1)
1222                 {
1223                     nexti = nextspritesect[k];
1224                     if (sprite[k].picnum == RRTILE64)
1225                     {
1226                         dist = sprite[k].lotag<<4;
1227                         speed = sprite[k].hitag;
1228                         for (ii = 0; ii < MAXSPRITES; ii++)
1229                         {
1230                             if (sprite[ii].picnum == RRTILE66)
1231                                 if (sprite[ii].lotag == sprite[k].sectnum)
1232                                 {
1233                                     minecartchildsect[minecartcnt] = sprite[ii].sectnum;
1234                                     deletesprite(ii);
1235                                 }
1236                         }
1237                         deletesprite(k);
1238                     }
1239                     if (sprite[k].picnum == RRTILE65)
1240                     {
1241                         sound = sprite[k].lotag;
1242                         deletesprite(k);
1243                     }
1244                     k = nexti;
1245                 }
1246                 if (minecartcnt > 16)
1247                     gameexit("\nToo many minecart sectors");
1248                 minecartdist[minecartcnt] = dist;
1249                 minecartspeed[minecartcnt] = speed;
1250                 minecartsect[minecartcnt] = i;
1251                 minecartdir[minecartcnt] = sector[i].hitag;
1252                 minecartdrag[minecartcnt] = dist;
1253                 minecartopen[minecartcnt] = 1;
1254                 minecartsound[minecartcnt] = sound;
1255                 minecartcnt++;
1256                 break;
1257             }
1258             case 20:
1259             case 22:
1260                 if( sector[i].floorz > sector[i].ceilingz)
1261                     sector[i].lotag |= 32768;
1262                 continue;
1263         }
1264 
1265         if(sector[i].ceilingstat&1)
1266         {
1267             if(waloff[sector[i].ceilingpicnum] == 0)
1268             {
1269                 if(sector[i].ceilingpicnum == LA)
1270                     for(j=0;j<5;j++)
1271                         if(waloff[sector[i].ceilingpicnum+j] == 0)
1272                             tloadtile(sector[i].ceilingpicnum+j);
1273             }
1274             setupbackdrop(sector[i].ceilingpicnum);
1275 
1276             if(ps[0].one_parallax_sectnum == -1)
1277                 ps[0].one_parallax_sectnum = i;
1278         }
1279 
1280         if(sector[i].lotag == 32767) //Found a secret room
1281         {
1282             ps[0].max_secret_rooms++;
1283             continue;
1284         }
1285 
1286         if(sector[i].lotag == -1)
1287         {
1288             ps[0].exitx = wall[sector[i].wallptr].x;
1289             ps[0].exity = wall[sector[i].wallptr].y;
1290             continue;
1291         }
1292     }
1293 
1294     i = headspritestat[0];
1295     while(i >= 0)
1296     {
1297         nexti = nextspritestat[i];
1298 
1299         if(sprite[i].lotag == -1 && (sprite[i].cstat&16) )
1300         {
1301             ps[0].exitx = SX;
1302             ps[0].exity = SY;
1303         }
1304         else switch(PN)
1305         {
1306             case NUKEBUTTON:
1307                 chickenplant = 1;
1308                 break;
1309 
1310             case GPSPEED:
1311                 sector[SECT].extra = SLT;
1312                 deletesprite(i);
1313                 break;
1314 
1315             case CYCLER:
1316                 if(numcyclers >= MAXCYCLERS)
1317                     gameexit("\nToo many cycling sectors.");
1318                 cyclers[numcyclers][0] = SECT;
1319                 cyclers[numcyclers][1] = SLT;
1320                 cyclers[numcyclers][2] = SS;
1321                 cyclers[numcyclers][3] = sector[SECT].floorshade;
1322                 cyclers[numcyclers][4] = SHT;
1323                 cyclers[numcyclers][5] = (SA == 1536);
1324                 numcyclers++;
1325                 deletesprite(i);
1326                 break;
1327 
1328             case RRTILE18:
1329                 if (torchcnt > 64)
1330                     gameexit("\nToo many torch effects");
1331                 torchsector[torchcnt] = SECT;
1332                 torchsectorshade[torchcnt] = sector[SECT].floorshade;
1333                 torchtype[torchcnt] = SLT;
1334                 torchcnt++;
1335                 deletesprite(i);
1336                 break;
1337 
1338             case RRTILE35:
1339                 if (lightnincnt > 64)
1340                     gameexit("\nToo many lightnin effects");
1341                 lightninsector[lightnincnt] = SECT;
1342                 lightninsectorshade[lightnincnt] = sector[SECT].floorshade;
1343                 lightnincnt++;
1344                 deletesprite(i);
1345                 break;
1346 
1347             case RRTILE68:
1348                 shadedsector[SECT] = 1;
1349                 deletesprite(i);
1350                 break;
1351 
1352             case RRTILE67:
1353                 sprite[i].cstat |= 32768;
1354                 break;
1355 
1356             case SOUNDFX:
1357                 if (ambientfx >= 64)
1358                     gameexit("\nToo many ambient effects");
1359                 else
1360                 {
1361                     ambienthitag[ambientfx] = SHT;
1362                     ambientlotag[ambientfx] = SLT;
1363                     ambientsprite[ambientfx] = i;
1364                     sprite[i].ang = ambientfx;
1365                     ambientfx++;
1366                     sprite[i].lotag = 0;
1367                     sprite[i].hitag = 0;
1368                 }
1369                 break;
1370         }
1371         i = nexti;
1372     }
1373 
1374     for(i=0;i<MAXSPRITES;i++)
1375     {
1376         if (sprite[i].picnum == RRTILE19)
1377         {
1378             if (geocnt > 64)
1379                 gameexit("\nToo many geometry effects");
1380             if (sprite[i].hitag == 0)
1381             {
1382                 geosector[geocnt] = sprite[i].sectnum;
1383                 for(j=0;j<MAXSPRITES;j++)
1384                 {
1385                     if (sprite[i].lotag == sprite[j].lotag && j != i && sprite[j].picnum == RRTILE19)
1386                     {
1387                         if (sprite[j].hitag == 1)
1388                         {
1389                             geosectorwarp[geocnt] = sprite[j].sectnum;
1390                             geox[geocnt] = sprite[i].x-sprite[j].x;
1391                             geoy[geocnt] = sprite[i].y-sprite[j].y;
1392                             geoz[geocnt] = sprite[i].z-sprite[j].z;
1393                         }
1394                         if (sprite[j].hitag == 2)
1395                         {
1396                             geosectorwarp2[geocnt] = sprite[j].sectnum;
1397                             geox2[geocnt] = sprite[i].x-sprite[j].x;
1398                             geoy2[geocnt] = sprite[i].y-sprite[j].y;
1399                             geoz2[geocnt] = sprite[i].z-sprite[j].z;
1400                         }
1401                     }
1402                 }
1403                 geocnt++;
1404             }
1405         }
1406     }
1407 
1408     for(i=0;i < MAXSPRITES;i++)
1409     {
1410         if(sprite[i].statnum < MAXSTATUS)
1411         {
1412             if(PN == SECTOREFFECTOR && SLT == 14)
1413                 continue;
1414             spawn(-1,i);
1415         }
1416     }
1417 
1418     for(i=0;i < MAXSPRITES;i++)
1419     {
1420         if(sprite[i].statnum < MAXSTATUS)
1421         {
1422             if( PN == SECTOREFFECTOR && SLT == 14 )
1423                 spawn(-1,i);
1424         }
1425         if (sprite[i].picnum == RRTILE19)
1426             deletesprite(i);
1427         if (sprite[i].picnum == RRTILE34)
1428         {
1429             sector[sprite[i].sectnum].filler = sprite[i].lotag;
1430             deletesprite(i);
1431         }
1432     }
1433 
1434     lotaglist = 0;
1435 
1436     i = headspritestat[0];
1437     while(i >= 0)
1438     {
1439         switch(PN)
1440         {
1441             case DIPSWITCH:
1442             case DIPSWITCH2:
1443             case ACCESSSWITCH:
1444             case PULLSWITCH:
1445             case HANDSWITCH:
1446             case SLOTDOOR:
1447             case LIGHTSWITCH:
1448             case SPACELIGHTSWITCH:
1449             case SPACEDOORSWITCH:
1450             case FRANKENSTINESWITCH:
1451             case LIGHTSWITCH2:
1452             case POWERSWITCH1:
1453             case LOCKSWITCH1:
1454             case POWERSWITCH2:
1455 #ifdef RRRA
1456             case RRTILE8464:
1457 #endif
1458                 break;
1459             case DIPSWITCH+1:
1460             case DIPSWITCH2+1:
1461             case PULLSWITCH+1:
1462             case HANDSWITCH+1:
1463             case SLOTDOOR+1:
1464             case LIGHTSWITCH+1:
1465             case SPACELIGHTSWITCH+1:
1466             case SPACEDOORSWITCH+1:
1467             case FRANKENSTINESWITCH+1:
1468             case LIGHTSWITCH2+1:
1469             case POWERSWITCH1+1:
1470             case LOCKSWITCH1+1:
1471             case POWERSWITCH2+1:
1472             case NUKEBUTTON:
1473             case NUKEBUTTON+1:
1474 #ifdef RRRA
1475             case RRTILE8464+1:
1476 #endif
1477                 for(j=0;j<lotaglist;j++)
1478                     if( SLT == lotags[j] )
1479                         break;
1480 
1481                 if( j == lotaglist )
1482                 {
1483                     lotags[lotaglist] = SLT;
1484                     lotaglist++;
1485                     if(lotaglist > 64)
1486                         gameexit("\nToo many switches (64 max).");
1487 
1488                     j = headspritestat[3];
1489                     while(j >= 0)
1490                     {
1491                         if(sprite[j].lotag == 12 && sprite[j].hitag == SLT)
1492                             hittype[j].temp_data[0] = 1;
1493                         j = nextspritestat[j];
1494                     }
1495                 }
1496                 break;
1497         }
1498         i = nextspritestat[i];
1499     }
1500 
1501     mirrorcnt = 0;
1502 
1503     for( i = 0; i < numwalls; i++ )
1504     {
1505         walltype *wal;
1506         wal = &wall[i];
1507 
1508         if(wal->overpicnum == MIRROR && (wal->cstat&32) != 0)
1509         {
1510             j = wal->nextsector;
1511 
1512             if(mirrorcnt > 63)
1513                 gameexit("\nToo many mirrors (64 max.)");
1514             if ( (j >= 0) && sector[j].ceilingpicnum != MIRROR )
1515             {
1516                 sector[j].ceilingpicnum = MIRROR;
1517                 sector[j].floorpicnum = MIRROR;
1518                 mirrorwall[mirrorcnt] = i;
1519                 mirrorsector[mirrorcnt] = j;
1520                 mirrorcnt++;
1521                 continue;
1522             }
1523         }
1524 
1525         if(numanimwalls >= MAXANIMWALLS)
1526             gameexit("\nToo many 'anim' walls (max 512.)");
1527 
1528         animwall[numanimwalls].tag = 0;
1529         animwall[numanimwalls].wallnum = 0;
1530 
1531         switch(wal->overpicnum)
1532         {
1533             case FANSPRITE:
1534                 wall->cstat |= 65;
1535                 animwall[numanimwalls].wallnum = i;
1536                 numanimwalls++;
1537                 break;
1538             case BIGFORCE:
1539                 animwall[numanimwalls].wallnum = i;
1540                 numanimwalls++;
1541                 continue;
1542         }
1543 
1544         wal->extra = -1;
1545 
1546         switch(wal->picnum)
1547         {
1548             case WATERTILE2:
1549                 for(j=0;j<3;j++)
1550                     if(waloff[wal->picnum+j] == 0)
1551                         tloadtile(wal->picnum+j);
1552                 break;
1553 
1554             case RRTILE1814:
1555             case RRTILE1817:
1556                 if(waloff[wal->picnum] == 0)
1557                     tloadtile(wal->picnum);
1558                 break;
1559             case RRTILE1939:
1560             case RRTILE1986:
1561             case RRTILE1987:
1562             case RRTILE1988:
1563             case RRTILE2004:
1564             case RRTILE2005:
1565             case RRTILE2123:
1566             case RRTILE2124:
1567             case RRTILE2125:
1568             case RRTILE2126:
1569             case RRTILE2636:
1570             case RRTILE2637:
1571             case RRTILE2878:
1572             case RRTILE2879:
1573             case RRTILE2898:
1574             case RRTILE2899:
1575                 if(waloff[wal->picnum] == 0)
1576                     tloadtile(wal->picnum);
1577                 break;
1578             case TECHLIGHT2:
1579             case TECHLIGHT4:
1580                 if(waloff[wal->picnum] == 0)
1581                     tloadtile(wal->picnum);
1582                 break;
1583             case SCREENBREAK6:
1584             case SCREENBREAK7:
1585             case SCREENBREAK8:
1586                 if(waloff[SCREENBREAK6] == 0)
1587                     for(j=SCREENBREAK6;j<=SCREENBREAK8;j++)
1588                         tloadtile(j);
1589                 animwall[numanimwalls].wallnum = i;
1590                 animwall[numanimwalls].tag = -1;
1591                 numanimwalls++;
1592                 break;
1593         }
1594     }
1595 
1596     //Invalidate textures in sector behind mirror
1597     for(i=0;i<mirrorcnt;i++)
1598     {
1599         startwall = sector[mirrorsector[i]].wallptr;
1600         endwall = startwall + sector[mirrorsector[i]].wallnum;
1601         for(j=startwall;j<endwall;j++)
1602         {
1603             wall[j].picnum = MIRROR;
1604             wall[j].overpicnum = MIRROR;
1605         }
1606     }
1607     if (!thunderon)
1608     {
1609         char brightness = ud.brightness>>2;
1610         setbrightness(brightness,palette);
1611         visibility = p->visibility;
1612     }
1613     tilesizx[0] = tilesizy[0] = 0;
1614 }
1615 
newgame(char vn,char ln,char sk)1616 void newgame(char vn,char ln,char sk)
1617 {
1618     struct player_struct *p = &ps[0];
1619     short i;
1620 
1621     ready2send = 0;
1622     waitforeverybody();
1623 
1624     if( ud.m_recstat != 2 && ud.last_level >= 0 && ud.multimode > 1 && ud.coop != 1)
1625 #ifdef RRRA
1626     {
1627         if (playerswhenstarted > 1 || numplayers > 1)
1628             dobonus(1);
1629         else
1630             dobonus2(1);
1631     }
1632 #else
1633         dobonus(1);
1634     if (turdlevel && !lastlevel)
1635         dobonus(0);
1636 #endif
1637 
1638     show_shareware = 26*34;
1639 
1640     ud.level_number =   ln;
1641     ud.volume_number =  vn;
1642     ud.player_skill =   sk;
1643     ud.secretlevel =    0;
1644     ud.from_bonus = 0;
1645 
1646     ud.last_level = -1;
1647     lastsavedpos = -1;
1648     p->zoom            = 768;
1649     p->gm              = 0;
1650 
1651     if(ud.m_coop != 1)
1652     {
1653         p->curr_weapon = PISTOL_WEAPON;
1654         p->gotweapon[PISTOL_WEAPON] = 1;
1655         p->gotweapon[KNEE_WEAPON] = 1;
1656         p->ammo_amount[PISTOL_WEAPON] = 48;
1657 #ifdef RRRA
1658         p->gotweapon[RA15_WEAPON] = 1;
1659         p->ammo_amount[RA15_WEAPON] = 1;
1660         p->ammo_amount[KNEE_WEAPON] = 1;
1661 #endif
1662         p->last_weapon = -1;
1663     }
1664 
1665     display_mirror =        0;
1666 
1667     if(ud.multimode > 1 )
1668     {
1669         if(numplayers < 2)
1670         {
1671             connecthead = 0;
1672             for(i=0;i<MAXPLAYERS;i++) connectpoint2[i] = i+1;
1673             connectpoint2[ud.multimode-1] = -1;
1674         }
1675     }
1676     else
1677     {
1678         connecthead = 0;
1679         connectpoint2[0] = -1;
1680     }
1681 }
1682 
1683 
resetpspritevars(char g)1684 void resetpspritevars(char g)
1685 {
1686     short i, j, nexti,circ;
1687     long firstx,firsty;
1688     spritetype *s;
1689     char aimmode[MAXPLAYERS];
1690     STATUSBARTYPE tsbar[MAXPLAYERS];
1691 
1692     EGS(ps[0].cursectnum,ps[0].posx,ps[0].posy,ps[0].posz,
1693         APLAYER,0,0,0,ps[0].ang,0,0,0,10);
1694 
1695     if(ud.recstat != 2) for(i=0;i<MAXPLAYERS;i++)
1696     {
1697         aimmode[i] = ps[i].aim_mode;
1698         if(ud.multimode > 1 && ud.coop == 1 && ud.last_level >= 0)
1699         {
1700             for(j=0;j<MAX_WEAPONS;j++)
1701             {
1702                 tsbar[i].ammo_amount[j] = ps[i].ammo_amount[j];
1703                 tsbar[i].gotweapon[j] = ps[i].gotweapon[j];
1704             }
1705 
1706             tsbar[i].shield_amount = ps[i].shield_amount;
1707             tsbar[i].curr_weapon = ps[i].curr_weapon;
1708             tsbar[i].inven_icon = ps[i].inven_icon;
1709 
1710             tsbar[i].firstaid_amount = ps[i].firstaid_amount;
1711             tsbar[i].steroids_amount = ps[i].steroids_amount;
1712             tsbar[i].holoduke_amount = ps[i].holoduke_amount;
1713             tsbar[i].jetpack_amount = ps[i].jetpack_amount;
1714             tsbar[i].heat_amount = ps[i].heat_amount;
1715             tsbar[i].scuba_amount = ps[i].scuba_amount;
1716             tsbar[i].boot_amount = ps[i].boot_amount;
1717         }
1718     }
1719 
1720     resetplayerstats(0);
1721 
1722     for(i=1;i<MAXPLAYERS;i++)
1723        memcpy(&ps[i],&ps[0],sizeof(ps[0]));
1724 
1725     if(ud.recstat != 2) for(i=0;i<MAXPLAYERS;i++)
1726     {
1727         ps[i].aim_mode = aimmode[i];
1728         if(ud.multimode > 1 && ud.coop == 1 && ud.last_level >= 0)
1729         {
1730             for(j=0;j<MAX_WEAPONS;j++)
1731             {
1732                 ps[i].ammo_amount[j] = tsbar[i].ammo_amount[j];
1733                 ps[i].gotweapon[j] = tsbar[i].gotweapon[j];
1734             }
1735             ps[i].shield_amount = tsbar[i].shield_amount;
1736             ps[i].curr_weapon = tsbar[i].curr_weapon;
1737             ps[i].inven_icon = tsbar[i].inven_icon;
1738 
1739             ps[i].firstaid_amount = tsbar[i].firstaid_amount;
1740             ps[i].steroids_amount= tsbar[i].steroids_amount;
1741             ps[i].holoduke_amount = tsbar[i].holoduke_amount;
1742             ps[i].jetpack_amount = tsbar[i].jetpack_amount;
1743             ps[i].heat_amount = tsbar[i].heat_amount;
1744             ps[i].scuba_amount= tsbar[i].scuba_amount;
1745             ps[i].boot_amount = tsbar[i].boot_amount;
1746         }
1747     }
1748 
1749     numplayersprites = 0;
1750     circ = 2048/ud.multimode;
1751 
1752     which_palookup = 9;
1753     j = connecthead;
1754     i = headspritestat[10];
1755     while(i >= 0)
1756     {
1757         nexti = nextspritestat[i];
1758         s = &sprite[i];
1759 
1760         if( numplayersprites == MAXPLAYERS)
1761             gameexit("\nToo many player sprites (max 8.)");
1762 
1763         if(numplayersprites == 0)
1764         {
1765             firstx = ps[0].posx;
1766             firsty = ps[0].posy;
1767         }
1768 
1769         po[numplayersprites].ox = s->x;
1770         po[numplayersprites].oy = s->y;
1771         po[numplayersprites].oz = s->z;
1772         po[numplayersprites].oa = s->ang;
1773         po[numplayersprites].os = s->sectnum;
1774 
1775         numplayersprites++;
1776         if(j >= 0)
1777         {
1778             s->owner = i;
1779             s->shade = 0;
1780             s->xrepeat = 24;
1781             s->yrepeat = 17;
1782             s->cstat = 1+256;
1783             s->xoffset = 0;
1784             s->clipdist = 64;
1785 
1786             if( (g&MODE_EOL) != MODE_EOL || ps[j].last_extra == 0)
1787             {
1788                 ps[j].last_extra = max_player_health;
1789                 s->extra = max_player_health;
1790             }
1791             else s->extra = ps[j].last_extra;
1792 
1793             s->yvel = j;
1794 
1795             if (ud.last_level == -1)
1796             {
1797                 if(s->pal == 0)
1798                 {
1799                     s->pal = ps[j].palookup = which_palookup;
1800                     ud.user_pals[j] = which_palookup;
1801                     which_palookup++;
1802                     if( which_palookup == 17 ) which_palookup = 9;
1803                 }
1804                 else ud.user_pals[j] = ps[j].palookup = s->pal;
1805             }
1806             else
1807                 s->pal = ps[j].palookup = ud.user_pals[j];
1808 
1809             ps[j].i = i;
1810             ps[j].frag_ps = j;
1811             hittype[i].owner = i;
1812 
1813             hittype[i].bposx = ps[j].bobposx = ps[j].oposx = ps[j].posx =        s->x;
1814             hittype[i].bposy = ps[j].bobposy = ps[j].oposy = ps[j].posy =        s->y;
1815             hittype[i].bposz = ps[j].oposz = ps[j].posz =        s->z;
1816             ps[j].oang  = ps[j].ang  =        s->ang;
1817 
1818             updatesector(s->x,s->y,&ps[j].cursectnum);
1819 
1820             j = connectpoint2[j];
1821 
1822         }
1823         else deletesprite(i);
1824         i = nexti;
1825     }
1826 }
1827 
clearfrags(void)1828 void clearfrags(void)
1829 {
1830     short i;
1831 
1832     for(i = 0;i<MAXPLAYERS;i++)
1833         ps[i].frag = ps[i].fraggedself = 0;
1834      clearbufbyte(&frags[0][0],(MAXPLAYERS*MAXPLAYERS)<<1,0L);
1835 }
1836 
resettimevars(void)1837 void resettimevars(void)
1838 {
1839     vel = svel = angvel = horiz = 0;
1840 
1841     totalclock = 0L;
1842     ototalclock = 0L;
1843     lockclock = 0L;
1844     ready2send = 1;
1845 }
1846 
1847 
genspriteremaps(void)1848 void genspriteremaps(void)
1849 {
1850     long j,fp;
1851     signed char look_pos;
1852     char *lookfn = "lookup.dat";
1853     char numl;
1854     char table[768];
1855     short unk;
1856 
1857     fp = kopen4load(lookfn,loadfromgrouponly);
1858     if(fp != -1)
1859         kread(fp,(char *)&numl,1);
1860     else
1861         gameexit("\nERROR: File 'LOOKUP.DAT' not found.");
1862 
1863     for(j=0;j < numl;j++)
1864     {
1865         kread(fp,(signed char *)&look_pos,1);
1866         kread(fp,tempbuf,256);
1867         makepalookup((long)look_pos,tempbuf,0,0,0,1);
1868 #ifdef RRRA
1869         if (look_pos == 8)
1870             makepalookup(54,tempbuf,32,32,32,1);
1871 #endif
1872     }
1873 
1874     kread(fp,&waterpal[0],768);
1875     kread(fp,&slimepal[0],768);
1876     kread(fp,&titlepal[0],768);
1877     kread(fp,&drealms[0],768);
1878     kread(fp,&endingpal[0],768);
1879 
1880     palette[765] = palette[766] = palette[767] = 0;
1881     slimepal[765] = slimepal[766] = slimepal[767] = 0;
1882     waterpal[765] = waterpal[766] = waterpal[767] = 0;
1883 
1884     kclose(fp);
1885 
1886     for (j = 0; j < 768; j++)
1887         table[j] = j;
1888     for (j = 0; j < 32; j++)
1889         table[j] = j + 32;
1890 
1891     makepalookup(7,table,0,0,0,1);
1892 
1893     for (j = 0; j < 768; j++)
1894         table[j] = j;
1895     makepalookup(30,table,0,0,0,1);
1896     makepalookup(31,table,0,0,0,1);
1897     makepalookup(32,table,0,0,0,1);
1898     makepalookup(33,table,0,0,0,1);
1899 #ifdef RRRA
1900     makepalookup(105,table,0,0,0,1);
1901 #endif
1902     unk = 63;
1903     for (j = 64; j < 80; j++)
1904     {
1905         unk--;
1906         table[j] = unk;
1907         table[j + 16] = j - 24;
1908     }
1909     table[80] = 80;
1910     table[81] = 81;
1911     for (j = 0; j < 32; j++)
1912     {
1913         table[j] = j + 32;
1914     }
1915     makepalookup(34,table,0,0,0,1);
1916 
1917     for (j = 0; j < 768; j++)
1918         table[j] = j;
1919     for (j = 0; j < 16; j++)
1920         table[j] = j + 129;
1921     for (j = 16; j < 32; j++)
1922         table[j] = j + 192;
1923     makepalookup(35,table,0,0,0,1);
1924 }
1925 
1926 char waitabort;
waitforeverybody()1927 void waitforeverybody()
1928 {
1929     long i;
1930 
1931     if (numplayers < 2) return;
1932     waitabort = 0;
1933 
1934     packbuf[0] = 250;
1935     for(i=connecthead;i>=0;i=connectpoint2[i])
1936         if (i != myconnectindex)
1937             sendpacket(i,packbuf,1);
1938 
1939     playerreadyflag[myconnectindex]++;
1940     do
1941     {
1942         if (KB_KeyPressed(sc_Escape)) { waitabort = 1; return; }
1943         getpackets();
1944         for(i=connecthead;i>=0;i=connectpoint2[i])
1945             if (playerreadyflag[i] < playerreadyflag[myconnectindex]) break;
1946     } while (i >= 0);
1947 }
1948 
checksum(long sum)1949 char checksum(long sum)
1950 {
1951 
1952     long i, j, delaytotalclock;
1953 
1954     delaytotalclock = totalclock;
1955 
1956     tempbuf[0] = 9;
1957     tempbuf[1] = sum&0x000000ff;
1958     tempbuf[2] = (sum&0x0000ff00)>>8;
1959     tempbuf[3] = (sum&0x00ff0000)>>16;
1960     tempbuf[4] = (sum&0x7f000000)>>24;
1961 
1962     if(connectpoint2[myconnectindex] < 0)
1963         i = connecthead;
1964     else
1965         i = connectpoint2[myconnectindex];
1966 
1967     sendpacket(i,tempbuf,5);
1968 
1969     checksume = -1;
1970 
1971     while(checksume == -1)
1972         if(totalclock >= delaytotalclock)
1973         {
1974             getpackets();
1975             delaytotalclock = totalclock + 8;
1976         }
1977 
1978     return (sum != checksume);
1979 }
1980 
getsound(unsigned short num)1981 char getsound(unsigned short num)
1982 {
1983     short fp;
1984     long   l;
1985 
1986     if(num >= NUM_SOUNDS || SoundToggle == 0) return 0;
1987     if (FXDevice == NumSoundCards) return 0;
1988 
1989     fp = kopen4load(sounds[num],loadfromgrouponly);
1990     if(fp == -1) return 0;
1991 
1992     l = kfilelength( fp );
1993     soundsiz[num] = l;
1994 
1995     if( (ud.level_number == 0 && ud.volume_number == 0 && (num == 189 || num == 232 || num == 99 || num == 233 || num == 17 ) ) ||
1996         ( l < 12800 ) )
1997     {
1998         Sound[num].lock = 2;
1999         allocache((long *)&Sound[num].ptr,l,&Sound[num].lock);
2000         if(Sound[num].ptr != NULL)
2001             kread( fp, Sound[num].ptr , l);
2002     }
2003     kclose( fp );
2004     return 1;
2005 }
2006 
precachenecessarysounds(void)2007 void precachenecessarysounds(void)
2008 {
2009     short i;
2010 
2011     if (FXDevice == NumSoundCards) return;
2012 
2013     for(i=0;i<NUM_SOUNDS;i++)
2014     {
2015         SoundOwner[i][0].i = -1;
2016         SoundOwner[i][1].i = -1;
2017         SoundOwner[i][2].i = -1;
2018         SoundOwner[i][3].i = -1;
2019         if(Sound[i].ptr == 0)
2020             getsound(i);
2021     }
2022 }
2023 
2024 
cacheit(void)2025 void cacheit(void)
2026 {
2027     short i,j;
2028 
2029     precachenecessarysounds();
2030 
2031     cachegoodsprites();
2032 
2033     for(i=0;i<numwalls;i++)
2034         if( waloff[wall[i].picnum] == 0 )
2035     {
2036         if(waloff[wall[i].picnum] == 0)
2037             tloadtile(wall[i].picnum);
2038         if(wall[i].overpicnum >= 0 && waloff[wall[i].overpicnum] == 0 )
2039             tloadtile(wall[i].overpicnum);
2040     }
2041 
2042     for(i=0;i<numsectors;i++)
2043     {
2044         if( waloff[sector[i].floorpicnum] == 0 )
2045             tloadtile( sector[i].floorpicnum );
2046         if( waloff[sector[i].ceilingpicnum] == 0 )
2047         {
2048             tloadtile( sector[i].ceilingpicnum );
2049             if( waloff[sector[i].ceilingpicnum] == LA)
2050             {
2051                 tloadtile(LA+1);
2052                 tloadtile(LA+2);
2053             }
2054         }
2055 
2056         j = headspritesect[i];
2057         while(j >= 0)
2058         {
2059             if(sprite[j].xrepeat != 0 && sprite[j].yrepeat != 0 && (sprite[j].cstat&32768) == 0)
2060                 if(waloff[sprite[j].picnum] == 0)
2061                     cachespritenum(j);
2062             j = nextspritesect[j];
2063         }
2064     }
2065 
2066 }
2067 
dofrontscreens(void)2068 void dofrontscreens(void)
2069 {
2070     long tincs,i,j;
2071 
2072     if(ud.recstat != 2)
2073     {
2074         ps[myconnectindex].palette = palette;
2075         for(j=0;j<63;j+=7) palto(0,0,0,j);
2076         i = ud.screen_size;
2077         ud.screen_size = 0;
2078         vscrn();
2079         clearview(0L);
2080 
2081         rotatesprite(320<<15,200<<15,65536L,0,LOADSCREEN,2,0,2+8+64,0,0,xdim-1,ydim-1);
2082 
2083         if( boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0 )
2084         {
2085 #ifdef RRRA
2086             menutext(160,140,0,0,"ENTERIN' USER MAP");
2087             menutext(160,140+20,0,0,boardfilename);
2088 #else
2089             menutext(160,90,0,0,"ENTERIN' USER MAP");
2090             menutext(160,90+20,0,0,boardfilename);
2091 #endif
2092         }
2093         else if(lastlevel)
2094         {
2095 #ifdef RRRA
2096             menutext(160,140,0,0,"ENTERIN'");
2097             menutext(160,140+16+8,0,0,"CLOSE ENCOUNTERS");
2098 #else
2099             menutext(160,90,0,0,"ENTERIN'");
2100             menutext(160,90+16+8,0,0,"CLOSE ENCOUNTERS");
2101 #endif
2102         }
2103         else
2104         {
2105 #ifdef RRRA
2106             menutext(160,140,0,0,"ENTERIN'");
2107             menutext(160,140+16+8,0,0,level_names[(ud.volume_number*7) + ud.level_number]);
2108 #else
2109             menutext(160,90,0,0,"ENTERIN'");
2110             menutext(160,90+16+8,0,0,level_names[(ud.volume_number*7) + ud.level_number]);
2111 #endif
2112         }
2113 
2114         nextpage();
2115 
2116         for(j=63;j>0;j-=7) palto(0,0,0,j);
2117 
2118         KB_FlushKeyboardQueue();
2119         ud.screen_size = i;
2120     }
2121     else
2122     {
2123         clearview(0L);
2124         ps[myconnectindex].palette = palette;
2125         palto(0,0,0,0);
2126         rotatesprite(320<<15,200<<15,65536L,0,LOADSCREEN,2,0,2+8+64,0,0,xdim-1,ydim-1);
2127 #ifdef RRRA
2128         menutext(160,155,0,0,"LOADIN'");
2129 #else
2130         menutext(160,105,0,0,"LOADIN'");
2131 #endif
2132         nextpage();
2133     }
2134 }
2135 
clearfifo(void)2136 void clearfifo(void)
2137 {
2138     short i;
2139 
2140     syncvaltail = 0L;
2141     syncvaltottail = 0L;
2142     syncstat = 0;
2143     bufferjitter = 1;
2144     mymaxlag = otherminlag = 0;
2145 
2146     movefifoplc = movefifosendplc = fakemovefifoplc = 0;
2147     avgfvel = avgsvel = avgavel = avghorz = avgbits = 0;
2148     otherminlag = mymaxlag = 0;
2149 
2150     clearbufbyte(myminlag,MAXPLAYERS<<2,0L);
2151     clearbufbyte(&loc,sizeof(input),0L);
2152     clearbufbyte(&sync[0],sizeof(sync),0L);
2153     clearbufbyte(inputfifo,sizeof(input)*MOVEFIFOSIZ*MAXPLAYERS,0L);
2154 
2155     clearbuf(movefifoend,MAXPLAYERS,0L);
2156     clearbuf(syncvalhead,MAXPLAYERS,0L);
2157 
2158     for(i=connecthead;i>=0;i=connectpoint2[i])
2159         myminlag[i] = 0;
2160 }
2161 
enterlevel(char g)2162 void enterlevel(char g)
2163 {
2164     short i,j;
2165     long l;
2166     char levname[256];
2167 
2168     if( (g&MODE_DEMO) != MODE_DEMO ) ud.recstat = ud.m_recstat;
2169     ud.respawn_monsters = ud.m_respawn_monsters;
2170     ud.respawn_items    = ud.m_respawn_items;
2171     ud.respawn_inventory    = ud.m_respawn_inventory;
2172     ud.monsters_off = ud.m_monsters_off;
2173     ud.coop = ud.m_coop;
2174     ud.marker = ud.m_marker;
2175     ud.ffire = ud.m_ffire;
2176 
2177     if( (g&MODE_DEMO) == 0 && ud.recstat == 2)
2178         ud.recstat = 0;
2179 
2180     i = ud.screen_size;
2181     ud.screen_size = 0;
2182     dofrontscreens();
2183     vscrn();
2184     ud.screen_size = i;
2185 
2186     if (lastlevel)
2187     {
2188         if ( loadboard( "endgame.map",&ps[0].posx, &ps[0].posy, &ps[0].posz, &ps[0].ang,&ps[0].cursectnum ) == -1 )
2189         {
2190             sprintf(tempbuf,"Map %s not found!",boardfilename);
2191             gameexit(tempbuf);
2192         }
2193     }
2194     else
2195     {
2196         if( boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0 )
2197         {
2198             if ( loadboard( boardfilename,&ps[0].posx, &ps[0].posy, &ps[0].posz, &ps[0].ang,&ps[0].cursectnum ) == -1 )
2199             {
2200                 sprintf(tempbuf,"Map %s not found!",boardfilename);
2201                 gameexit(tempbuf);
2202             }
2203         }
2204         else if ( loadboard( level_file_names[ (ud.volume_number*7)+ud.level_number],&ps[0].posx, &ps[0].posy, &ps[0].posz, &ps[0].ang,&ps[0].cursectnum ) == -1)
2205         {
2206             sprintf(tempbuf,"Map %s not found!",level_file_names[(ud.volume_number*8)+ud.level_number]);
2207             gameexit(tempbuf);
2208         }
2209     }
2210 
2211 #ifndef RRRA
2212     if (ud.volume_number == 1 && ud.level_number == 1)
2213     {
2214         short ii;
2215         for (ii = PISTOL_WEAPON; ii < MAX_WEAPONS; ii++)
2216             ps[0].gotweapon[ii] = 0;
2217         for (ii = PISTOL_WEAPON; ii < MAX_WEAPONS; ii++)
2218             ps[0].ammo_amount[ii] = 0;
2219     }
2220 #endif
2221 
2222     clearbufbyte(gotpic,sizeof(gotpic),0L);
2223 
2224     prelevel(g);
2225 
2226 #ifdef RRRA
2227     if (ud.level_number == 2 && ud.volume_number == 0)
2228     {
2229         short ii;
2230         for (ii = PISTOL_WEAPON; ii < MAX_WEAPONS; ii++)
2231             ps[0].gotweapon[ii] = 0;
2232         for (ii = PISTOL_WEAPON; ii < MAX_WEAPONS; ii++)
2233             ps[0].ammo_amount[ii] = 0;
2234         ps[0].gotweapon[RA15_WEAPON] = 1;
2235         ps[0].ammo_amount[RA15_WEAPON] = 1;
2236         ps[0].curr_weapon = RA15_WEAPON;
2237     }
2238 #endif
2239 
2240     allignwarpelevators();
2241     resetpspritevars(g);
2242 
2243     cachedebug = 0;
2244     automapping = 0;
2245 
2246     cacheit();
2247     docacheit();
2248 
2249     if (globalskillsound >= 0)
2250     {
2251         while (Sound[globalskillsound].lock >= 200);
2252     }
2253     globalskillsound = -1;
2254 
2255     FX_StopAllSounds();
2256     clearsoundlocks();
2257     FX_SetReverb(0);
2258 
2259     if( (g&MODE_GAME) || (g&MODE_EOL) )
2260         ps[myconnectindex].gm = MODE_GAME;
2261     else if(g&MODE_RESTART)
2262     {
2263         if(ud.recstat == 2)
2264             ps[myconnectindex].gm = MODE_DEMO;
2265         else ps[myconnectindex].gm = MODE_GAME;
2266     }
2267 
2268     if( (ud.recstat == 1) && (g&MODE_RESTART) != MODE_RESTART )
2269         opendemowrite();
2270 
2271     for(i=connecthead;i>=0;i=connectpoint2[i])
2272         switch(sector[sprite[ps[i].i].sectnum].floorpicnum)
2273         {
2274             case HURTRAIL:
2275             case FLOORSLIME:
2276             case FLOORPLASMA:
2277                 resetweapons(i);
2278                 resetinventory(i);
2279                 ps[i].gotweapon[PISTOL_WEAPON] = 0;
2280                 ps[i].ammo_amount[PISTOL_WEAPON] = 0;
2281                 ps[i].curr_weapon = KNEE_WEAPON;
2282                 ps[i].kickback_pic = 0;
2283                 break;
2284         }
2285 
2286       //PREMAP.C - replace near the my's at the end of the file
2287       myx = omyx = ps[myconnectindex].posx;
2288 	  myy = omyy = ps[myconnectindex].posy;
2289 	  myz = omyz = ps[myconnectindex].posz;
2290 	  myxvel = myyvel = myzvel = 0;
2291 	  myang = omyang = ps[myconnectindex].ang;
2292 	  myhoriz = omyhoriz = ps[myconnectindex].horiz;
2293 	  myhorizoff = omyhorizoff = ps[myconnectindex].horizoff;
2294 	  mycursectnum = ps[myconnectindex].cursectnum;
2295 	  myjumpingcounter = ps[myconnectindex].jumping_counter;
2296 	  myjumpingtoggle = ps[myconnectindex].jumping_toggle;
2297       myonground = ps[myconnectindex].on_ground;
2298       myhardlanding = ps[myconnectindex].hard_landing;
2299       myreturntocenter = ps[myconnectindex].return_to_center;
2300 
2301      ps[myconnectindex].palette = palette;
2302      palto(0,0,0,0);
2303 
2304      setpal(&ps[myconnectindex]);
2305      flushperms();
2306 
2307      everyothertime = 0;
2308      global_random = 0;
2309 
2310      ud.last_level = ud.level_number+1;
2311 
2312      clearfifo();
2313 
2314      for(i=numinterpolations-1;i>=0;i--) bakipos[i] = *curipos[i];
2315 
2316      restorepalette = 1;
2317 
2318      flushpackets();
2319      waitforeverybody();
2320 
2321      palto(0,0,0,0);
2322      vscrn();
2323      clearview(0L);
2324      drawbackground();
2325      displayrooms(screenpeek,65536);
2326      displayrest(screenpeek);
2327      nextpage();
2328 
2329      clearbufbyte(playerquitflag,MAXPLAYERS,0x01010101);
2330      if (waitabort == 1)
2331          gameexit(" ");
2332      ps[myconnectindex].over_shoulder_on = 0;
2333 
2334      clearfrags();
2335 
2336      resettimevars();  // Here we go
2337 }
2338 
2339 /*
2340 Duke Nukem V
2341 
2342 Layout:
2343 
2344       Settings:
2345         Suburbs
2346           Duke inflitrating neighborhoods inf. by aliens
2347         Death Valley:
2348           Sorta like a western.  Bull-skulls halb buried in the sand
2349           Military compound:  Aliens take over nuke-missle silo, duke
2350             must destroy.
2351           Abondend Aircraft field
2352         Vegas:
2353           Blast anything bright!  Alien lights camoflauged.
2354           Alien Drug factory. The Blue Liquid
2355         Mountainal Cave:
2356           Interior cave battles.
2357         Jungle:
2358           Trees, canopee, animals, a mysterious hole in the earth
2359         Penetencury:
2360           Good use of spotlights:
2361       Inventory:
2362         Wood,
2363         Metal,
2364         Torch,
2365         Rope,
2366         Plastique,
2367         Cloth,
2368         Wiring,
2369         Glue,
2370         Cigars,
2371         Food,
2372         Duck Tape,
2373         Nails,
2374         Piping,
2375         Petrol,
2376         Uranium,
2377         Gold,
2378         Prism,
2379         Power Cell,
2380 
2381         Hand spikes (Limited usage, they become dull)
2382         Oxygent     (Oxygen mixed with stimulant)
2383 
2384 
2385       Player Skills:
2386         R-Left,R-Right,Foward,Back
2387         Strafe, Jump, Double Flip Jump for distance
2388         Help, Escape
2389         Fire/Use
2390         Use Menu
2391 
2392 Programming:
2393      Images: Polys
2394      Actors:
2395        Multi-Object sections for change (head,arms,legs,torsoe,all change)
2396        Facial expressions.  Pal lookup per poly?
2397 
2398      struct imagetype
2399         {
2400             int *itable; // AngX,AngY,AngZ,Xoff,Yoff,Zoff;
2401             int *idata;
2402             struct imagetype *prev, *next;
2403         }
2404 
2405 */
2406