2
Copyright (C) 1994-1995 Apogee Software, Ltd.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
51
#define LIGHTNINGLEVEL 4
52
#define MINLIGHTNINGLEVEL 2
53
#define MAXLIGHTNINGLEVEL 10
56
=============================================================================
60
=============================================================================
64
boolean lightning=false;
73
longword heightnumerator;
85
byte * playermaps[MAXPLAYERCOLORS];
86
short pixelangle[MAXVIEWWIDTH];
87
byte gammatable[GAMMAENTRIES];
89
int focalwidth=FOCALWIDTH;
91
byte uniformcolors[MAXPLAYERCOLORS]={
106
byte mapmasks1[4][9] = {
107
{1 ,3 ,7 ,15,15,15,15,15,15},
108
{2 ,6 ,14,14,14,14,14,14,14},
109
{4 ,12,12,12,12,12,12,12,12},
110
{8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8} };
112
byte mapmasks2[4][9] = {
113
{0 ,0 ,0 ,0 ,1 ,3 ,7 ,15,15},
114
{0 ,0 ,0 ,1 ,3 ,7 ,15,15,15},
115
{0 ,0 ,1 ,3 ,7 ,15,15,15,15},
116
{0 ,1 ,3 ,7 ,15,15,15,15,15} };
118
byte mapmasks3[4][9] = {
119
{0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1},
120
{0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,3},
121
{0 ,0 ,0 ,0 ,0 ,0 ,1 ,3 ,7},
122
{0 ,0 ,0 ,0 ,0 ,1 ,3 ,7 ,15} };
127
=============================================================================
131
=============================================================================
134
static char *YourComputerSucksString = "Buy a 486! :)";
136
static int viewsizes[MAXVIEWSIZES*2]={ 80,48,
148
static int ColorMapLoaded=0;
150
static int lightningtime=0;
151
static int lightningdelta=0;
152
static int lightningdistance=0;
153
static int lightningsoundtime=0;
154
static boolean periodic=false;
155
static int periodictime=0;
157
void SetViewDelta ( void );
158
void UpdatePeriodicLighting (void);
167
void ResetFocalWidth ( void )
169
focalwidth=FOCALWIDTH;
180
void ChangeFocalWidth ( int amount )
182
focalwidth=FOCALWIDTH+amount;
195
void SetViewDelta ( void )
199
// calculate scale value for vertical height calculations
200
// and sprite x calculations
202
scale = (centerx*focalwidth)/160;
205
// divide heightnumerator by a posts distance to get the posts height for
206
// the heightbuffer. The pixel height is height>>HEIGHTFRACTION
208
heightnumerator = (((focalwidth/10)*centerx*4096)<<HEIGHTFRACTION);
219
void CalcProjection ( void )
231
// Already being called in ResetFocalWidth
235
// load in tables file
239
//Hey, isn't this stuff already loaded in?
240
//Why don't we make this a lump?
241
table=W_CacheLumpName("tables",PU_STATIC, CvtFixme, 1);
248
memcpy(&length,ptr,sizeof(int));
249
SwapIntelLong((long *)&length);
251
pangle=SafeMalloc(length*sizeof(int));
252
memcpy(pangle,ptr,length*sizeof(int));
254
frac=((length*65536/centerx))>>1;
255
for (i=0;i<centerx;i++)
257
// start 1/2 pixel over, so viewangle bisects two middle pixels
258
intang=pangle[frac>>16];
259
SwapIntelLong(&intang);
260
pixelangle[centerx-1-i] =(short) intang;
261
pixelangle[centerx+i] =(short) -intang;
262
frac+=(length*65536/centerx);
264
table=W_CacheLumpName("tables",PU_CACHE, CvtFixme, 1);
270
==========================
274
==========================
289
if ((size<0) || (size>=MAXVIEWSIZES))
290
Error("Illegal screen size = %ld\n",size);
292
viewwidth = viewsizes[ size << 1 ]; // must be divisable by 16
293
viewheight = viewsizes[ ( size << 1 ) + 1 ]; // must be even
298
// Only keep the kills flag
299
StatusBar &= ~( BOTTOM_STATUS_BAR | TOP_STATUS_BAR |
300
STATUS_PLAYER_STATS );
304
// Account for height of kill boxes
310
StatusBar |= TOP_STATUS_BAR;
312
// Account for height of top status bar
319
// Turn on health and ammo bar
320
StatusBar |= BOTTOM_STATUS_BAR;
323
else if ( size < 10 )
325
// Turn on transparent health and ammo bar
326
StatusBar |= STATUS_PLAYER_STATS;
332
// Prevent weapon from being scaled too big
336
weaponscale = ( height << 16 ) / 168;
337
centerx = viewwidth >> 1;
338
centery = viewheight >> 1;
339
centeryfrac = (centery << 16);
340
yzangleconverter = ( 0xaf85 * viewheight ) / 200;
342
// Center the view horizontally
343
screenx = ( 320 - viewwidth ) >> 1;
345
if ( viewheight >= maxheight )
348
viewheight = maxheight;
352
// Center the view vertically
353
screeny = ( ( maxheight - viewheight ) >> 1 ) + topy;
356
// Calculate offset of view window
358
screenofs = ( screenx >> 2 ) + ylookup[ screeny ];
360
screenofs = screenx + ylookup[ screeny ];
364
// calculate trace angles and projection constants
370
// Already being called in ResetFocalWidth
377
//******************************************************************************
381
//******************************************************************************
392
CurrentFont = tinyfont;
393
VW_MeasurePropString( YourComputerSucksString, &width, &height );
395
DrawGameString( 160 - width / 2, 100 + 48 / 2 + 2,
396
YourComputerSucksString, true );
401
==========================
405
==========================
408
void SetupScreen ( boolean flip )
412
SetViewSize(viewsize);
415
shape = W_CacheLumpName( "backtile", PU_CACHE, Cvt_pic_t, 1 );
416
DrawTiledRegion( 0, 16, 320, 200 - 32, 0, 16, shape );
424
DrawPlayScreen (true);
428
VL_CopyDisplayToHidden();
434
void LoadColorMap( void )
439
if (ColorMapLoaded==1)
440
Error("Called LoadColorMap twice\n");
443
// load in the light tables
444
// 256 byte align tables
447
lump = W_GetNumForName("colormap");
448
length = W_LumpLength (lump) + 255;
449
colormap = SafeMalloc (length);
450
colormap = (byte *)( ((int)colormap + 255)&~0xff);
451
W_ReadLump (lump,colormap);
453
// Fix fire colors in colormap
456
for (j=0xea;j<0xf9;j++)
457
colormap[i*256+j]=colormap[(((i-16)/4+16))*256+j];
461
lump = W_GetNumForName("specmaps");
462
length = W_LumpLength (lump+1) + 255;
463
redmap = SafeMalloc (length);
464
redmap = (byte *)( ((int)redmap + 255)&~0xff);
465
W_ReadLump (lump+1,redmap);
466
greenmap = redmap+(16*256);
468
// Get player colormaps
470
// if (modemgame==true)
472
lump = W_GetNumForName("playmaps")+1;
473
for (i=0;i<MAXPLAYERCOLORS;i++)
475
length = W_LumpLength (lump+i) + 255;
476
playermaps[i] = SafeMalloc (length);
477
playermaps[i] = (byte *)( ((int)playermaps[i] + 255)&~0xff);
478
W_ReadLump (lump+i,playermaps[i]);
483
printf("RT_VIEW: Colormaps Initialized\n");
488
==========================
492
==========================
494
#define LIGHTRATEBASE 252
495
#define LIGHTRATEEND 267
496
#define LIGHTLEVELBASE 216
497
#define LIGHTLEVELEND 223
498
void SetupLightLevels ( void )
506
// Set up light level for level
508
if (((word)MAPSPOT(2,0,1)>=104) && ((word)MAPSPOT(2,0,1)<=105))
509
fog=(word)MAPSPOT(2,0,1)-104;
511
Error ("There is no Fog icon on map %ld\n",gamestate.mapon);
512
if ((word)MAPSPOT(3,0,1)==139)
517
lights=Z_Malloc(MAPSIZE*MAPSIZE*(sizeof(unsigned long)),PU_LEVEL,NULL);
518
memset (lights,0,MAPSIZE*MAPSIZE*(sizeof(unsigned long)));
521
Error("You cannot use light sourcing on a level with fog on map %ld\n",gamestate.mapon);
523
else if ((word)MAPSPOT(3,0,1))
524
Error("You must use the lightsource icon or nothing at all at (3,0) in plane 1 on map %ld\n",gamestate.mapon);
525
if (((word)MAPSPOT(2,0,0)>=LIGHTLEVELBASE) && ((word)MAPSPOT(2,0,0)<=LIGHTLEVELEND))
526
glevel=(MAPSPOT(2,0,0)-LIGHTLEVELBASE);
528
Error("You must specify a valid darkness level icon at (2,0) on map %ld\n",gamestate.mapon);
530
SetLightLevels ( glevel );
532
if (((word)MAPSPOT(3,0,0)>=LIGHTRATEBASE) && ((word)MAPSPOT(3,0,0)<=LIGHTRATEEND))
533
glevel=(MAPSPOT(3,0,0)-LIGHTRATEBASE);
536
// Error("You must specify a valid darkness rate icon at (3,0) on map %ld\n",gamestate.mapon);
540
SetLightRate ( glevel );
545
lightningsoundtime=0;
549
==========================
553
==========================
555
void SetLightLevels ( int darkness )
559
baseminshade=0x10+((7-darkness)>>1);
560
basemaxshade=0x1f-(darkness>>1);
564
baseminshade=darkness;
567
minshade=baseminshade;
568
maxshade=basemaxshade;
569
darknesslevel=darkness;
573
==========================
577
==========================
579
int GetLightLevelTile ( void )
583
return ((7-((baseminshade-0x10)<<1))+LIGHTLEVELBASE);
587
return (baseminshade+LIGHTLEVELBASE);
593
==========================
597
==========================
599
void SetLightRate ( int rate )
601
normalshade=(HEIGHTFRACTION+8)-rate;
602
if (normalshade>14) normalshade=14;
603
if (normalshade<3) normalshade=3;
607
==========================
611
==========================
613
int GetLightRate ( void )
615
return ((HEIGHTFRACTION+8)-normalshade);
619
==========================
623
==========================
625
int GetLightRateTile ( void )
627
return ((HEIGHTFRACTION+8)-normalshade+LIGHTRATEBASE);
633
==========================
637
==========================
639
void UpdateLightLevel (int area)
649
numtiles=(numareatiles[area]>>5)-2;
650
numlights=(LightsInArea[area]-numtiles)>>1;
654
if (numlights>GENERALNUMLIGHTS)
655
numlights=GENERALNUMLIGHTS;
656
targetmin=baseminshade+(GENERALNUMLIGHTS-numlights);
657
targetmax=basemaxshade-numlights;
658
if (targetmax<baseminshade)
659
targetmax=baseminshade;
660
if (targetmin>targetmax)
663
if (minshade>targetmin)
665
else if (minshade<targetmin)
668
if (maxshade>targetmax)
670
else if (maxshade<targetmax)
674
targetlevel=baseminshade+(GENERALNUMLIGHTS-numlights);
675
if (abs(minshade-targetlevel)==1)
676
minshade=targetlevel;
677
else if (minshade>targetlevel)
679
else if (minshade<targetlevel)
685
==========================
689
= Postive value lightens
690
= Negative value darkens
692
==========================
694
void SetIllumination (int level)
711
==========================
713
= GetIlluminationDelta
715
==========================
717
int GetIlluminationDelta (void)
722
return maxshade-basemaxshade;
726
==========================
730
==========================
732
void UpdateLightning (void)
736
UpdatePeriodicLighting();
739
if ((fog==1) || (lightning==false))
742
if (lightningtime<=0)
744
if (lightningsoundtime>0)
745
SD_Play3D (SD_LIGHTNINGSND, 0, lightningdistance);
746
lightningtime=GameRandomNumber("UpdateLightning",0)<<1;
747
lightningdistance=GameRandomNumber("UpdateLightning",0);
748
lightninglevel=(255-lightningdistance)>>LIGHTNINGLEVEL;
749
if (lightninglevel<MINLIGHTNINGLEVEL)
750
lightninglevel=MINLIGHTNINGLEVEL;
751
if (lightninglevel>MAXLIGHTNINGLEVEL)
752
lightninglevel=MAXLIGHTNINGLEVEL;
753
lightningdelta=lightninglevel>>1;
754
lightningsoundtime=lightningdistance>>1;
755
if (lightningdistance<100)
757
SetIllumination(lightninglevel);
760
else if (lightninglevel>0)
762
lightninglevel-=lightningdelta;
763
if (lightninglevel<=0)
770
if (lightningsoundtime)
772
lightningsoundtime--;
773
if (lightningsoundtime<=0)
777
volume=255-lightningdistance;
778
if (volume>170) volume=170;
779
SD_PlayPitchedSound ( SD_LIGHTNINGSND, volume,-(lightningdistance<<2));
780
lightningsoundtime=0;
786
==========================
788
= UpdatePeriodicLighting
790
==========================
792
#define PERIODICMAG (6)
793
#define PERIODICSTEP (20)
794
#define PERIODICBASE (0x0f)
795
void UpdatePeriodicLighting (void)
799
val=FixedMul(PERIODICMAG,sintable[periodictime]);
800
periodictime=(periodictime+PERIODICSTEP)&(FINEANGLES-1);
801
basemaxshade=PERIODICBASE+(PERIODICMAG)+val;
802
baseminshade=basemaxshade-GENERALNUMLIGHTS-1;
806
==========================
810
==========================
812
void SetModemLightLevel ( int type )
819
MAPSPOT(2,0,0)=(word)216;
820
MAPSPOT(3,0,0)=(word)255;
821
MAPSPOT(3,0,1)=(word)139;
822
MAPSPOT(2,0,1)=(word)104;
825
case bo_light_normal:
827
case bo_light_bright:
828
MAPSPOT(2,0,0)=(word)223;
829
MAPSPOT(3,0,0)=(word)267;
830
MAPSPOT(3,0,1)=(word)0;
831
MAPSPOT(2,0,1)=(word)104;
835
MAPSPOT(2,0,0)=(word)219;
836
MAPSPOT(3,0,0)=(word)259;
837
MAPSPOT(2,0,1)=(word)105;
838
MAPSPOT(3,0,1)=(word)0;
841
case bo_light_periodic:
843
MAPSPOT(2,0,1)=(word)104;
844
MAPSPOT(3,0,1)=(word)139;
848
case bo_light_lightning:
851
MAPSPOT(2,0,0)=(word)222;
852
MAPSPOT(3,0,0)=(word)255;
853
MAPSPOT(3,0,1)=(word)139;
854
MAPSPOT(2,0,1)=(word)104;