#include common_scripts\utility;

setfogsliders()
{
	/$
	// The read-only vars are set each time a call to SetExpFog is made, so they should contain the 'fog dest' params
	SetDevDvar( "scr_fog_exp_halfplane", 					GetDvar( 		"g_fogHalfDistReadOnly", 							0.0 ) );
	SetDevDvar( "scr_fog_nearplane", 						GetDvar( 		"g_fogStartDistReadOnly", 							0.1 ) );
	SetDevDvar( "scr_fog_color", 							GetDvar( 		"g_fogColorReadOnly", 								( 1, 0, 0 ) ) );
	SetDevDvar( "scr_fog_color_intensity",					GetDvar( 		"g_fogColorIntensityReadOnly", 						1.0 ) );
	SetDevDvar( "scr_fog_max_opacity", 						GetDvar( 		"g_fogMaxOpacityReadOnly", 							1.0 ) );
	SetDevDvar( "scr_sunFogEnabled", 						GetDvar( 		"g_sunFogEnabledReadOnly", 							0 ) );
	SetDevDvar( "scr_sunFogColor", 							GetDvar( 		"g_sunFogColorReadOnly", 							( 1, 0, 0 ) ) );
	SetDevDvar( "scr_sunfogColorIntensity",					GetDvar( 		"g_sunFogColorIntensityReadOnly", 					1.0 ) );
	SetDevDvar( "scr_sunFogDir", 							GetDvarVector( 	"g_sunFogDirReadOnly", 								( 1, 0, 0 ) ) );
	SetDevDvar( "scr_sunFogBeginFadeAngle",					GetDvar( 		"g_sunFogBeginFadeAngleReadOnly",					0.0 ) );
	SetDevDvar( "scr_sunFogEndFadeAngle", 					GetDvar( 		"g_sunFogEndFadeAngleReadOnly",						180.0 ) );
	SetDevDvar( "scr_sunFogScale", 							GetDvar( 		"g_sunFogScaleReadOnly", 							1.0 ) );
	SetDevDvar( "scr_heightFogEnabled",						GetDvar(		"g_heightFogEnabledReadOnly",						0 ) );
	SetDevDvar( "scr_heightFogBaseHeight",					GetDvar(		"g_heightFogBaseHeightReadOnly",					0 ) );
	SetDevDvar( "scr_heightFogHalfPlaneDistance",			GetDvar(		"g_heightFogHalfPlaneDistanceReadOnly",				1000 ) );

	// The r_sky_fog vars are only active if tweaks on them are enabled, which is a little strange...
	SetDevDvar( "scr_skyFogIntensity", 						GetDvar(		"r_sky_fog_intensity",								0.0 ) );
	SetDevDvar( "scr_skyFogMinAngle", 						GetDvar(		"r_sky_fog_min_angle",								0.0 ) );
	SetDevDvar( "scr_skyFogMaxAngle", 						GetDvar(		"r_sky_fog_max_angle",								90.0 ) );

	SetDevDvar( "scr_atmosFogEnabled",						GetDvar(		"g_atmosFogEnabledReadOnly",						0 ) );
	SetDevDvar( "scr_atmosFogSunFogColor",					GetDvar(		"g_atmosFogSunFogColorReadOnly",					(.5, .5, .5 ) ) );
	SetDevDvar( "scr_atmosFogHazeColor",					GetDvar(		"g_atmosFogHazeColorReadOnly",						(.5, .5, .5 ) ) );
	SetDevDvar( "scr_atmosFogHazeStrength",					GetDvar(		"g_atmosFogHazeStrengthReadOnly",					.5 ) );
	SetDevDvar( "scr_atmosFogHazeSpread",					GetDvar(		"g_atmosFogHazeSpreadReadOnly",						.75 ) );
	SetDevDvar( "scr_atmosFogExtinctionStrength",			GetDvar(		"g_atmosFogExtinctionStrengthReadOnly",				1 ) );
	SetDevDvar( "scr_atmosFogInScatterStrength",			GetDvar(		"g_atmosFogInScatterStrengthReadOnly",				0 ) );
	SetDevDvar( "scr_atmosFogHalfPlaneDistance",			GetDvar(		"g_atmosFogHalfPlaneDistanceReadOnly",				5000 ) );
	SetDevDvar( "scr_atmosFogStartDistance",				GetDvar(		"g_atmosFogStartDistanceReadOnly",					0 ) );
	SetDevDvar( "scr_atmosFogDistanceScale",				GetDvar(		"g_atmosFogDistanceScaleReadOnly",					1 ) );
	SetDevDvar( "scr_atmosFogSkyDistance",					int( GetDvar(	"g_atmosFogSkyDistanceReadOnly",				100000 ) ) );
	SetDevDvar( "scr_atmosFogSkyAngularFalloffEnabled",		GetDvar(		"g_atmosFogSkyAngularFalloffEnabledReadOnly",		0 ) );
	SetDevDvar( "scr_atmosFogSkyFalloffStartAngle",			GetDvar(		"g_atmosFogSkyFalloffStartAngleReadOnly",			0 ) );
	SetDevDvar( "scr_atmosFogSkyFalloffAngleRange",			GetDvar(		"g_atmosFogSkyFalloffAngleRangeReadOnly",			90 ) );
	SetDevDvar( "scr_atmosFogSunDirection",					GetDvarVector(	"g_atmosFogSunDirectionReadOnly",					(0, 0, 1) ) );
	SetDevDvar( "scr_atmosFogHeightFogEnabled",				GetDvar(		"g_atmosFogHeightFogEnabledReadOnly",				0 ) );
	SetDevDvar( "scr_atmosFogHeightFogBaseHeight",			GetDvar(		"g_atmosFogHeightFogBaseHeightReadOnly",			0 ) );
	SetDevDvar( "scr_atmosFogHeightFogHalfPlaneDistance",	GetDvar(		"g_atmosFogHeightFogHalfPlaneDistanceReadOnly",		1000 ) );
	$/
}

/$
translateFogSlidersToScript()
{
	level.fogexphalfplane				= limit( GetDvarFloat( "scr_fog_exp_halfplane" ) );
	level.fognearplane					= limit( GetDvarFloat( "scr_fog_nearplane" ) );
	level.fogHDRColorIntensity			= limit( GetDvarFloat( "scr_fog_color_intensity" ) );
	level.fogmaxopacity					= limit( GetDvarFloat( "scr_fog_max_opacity" ) );
	level.sunFogEnabled					= GetDvarInt( "scr_sunFogEnabled" );
	level.sunFogHDRColorIntensity		= limit( GetDvarFloat( "scr_sunFogColorIntensity" ) );
	level.sunFogBeginFadeAngle			= limit( GetDvarFloat( "scr_sunFogBeginFadeAngle" ) );
	level.sunFogEndFadeAngle			= limit( GetDvarFloat( "scr_sunFogEndFadeAngle" ) );
	level.sunFogScale					= limit( GetDvarFloat( "scr_sunFogScale" ) );
	level.skyFogIntensity				= limit( GetDvarFloat( "scr_skyFogIntensity" ) );
	level.skyFogMinAngle				= limit( GetDvarFloat( "scr_skyFogMinAngle" ) );
	level.skyFogMaxAngle				= limit( GetDvarFloat( "scr_skyFogMaxAngle" ) );
	level.heightFogEnabled				= GetDvarInt( "scr_heightFogEnabled" );
	level.heightFogBaseHeight			= limit( GetDvarFloat( "scr_heightFogBaseHeight" ) );
	level.heightFogHalfPlaneDistance	= limit( GetDvarFloat( "scr_heightFogHalfPlaneDistance" ) );
	
	fogColor						= GetDvarVector( "scr_fog_color" );
	r = limit( fogColor[0] );
	g = limit( fogColor[1] );
	b = limit( fogColor[2] );
	level.fogcolor = ( r, g , b );

	sunFogColor						= GetDvarVector( "scr_sunFogColor" );
	r = limit( sunFogColor[0] );
	g = limit( sunFogColor[1] );
	b = limit( sunFogColor[2] );
	level.sunFogColor =( r, g , b );
	
	sunFogDir						= GetDvarVector( "scr_sunFogDir" );
	x = limit( sunFogDir[0]);
	y = limit( sunFogDir[1]);
	z = limit( sunFogDir[2]);
	level.sunFogDir = (x,y,z);

	level.atmosFogEnabled = GetDvarInt( "scr_atmosFogEnabled" );
	vec3 = GetDvarVector( "scr_atmosFogSunFogColor" );
	x = limit( vec3[0] );
	y = limit( vec3[1] );
	z = limit( vec3[2] );
	level.atmosFogSunFogColor = ( x, y, z );
	vec3 = GetDvarVector( "scr_atmosFogHazeColor" );
	x = limit( vec3[0] );
	y = limit( vec3[1] );
	z = limit( vec3[2] );
	level.atmosFogHazeColor = ( x, y, z );
	level.atmosFogHazeStrength = limit( GetDvarFloat( "scr_atmosFogHazeStrength" ) );
	level.atmosFogHazeSpread = limit( GetDvarFloat( "scr_atmosFogHazeSpread" ) );
	level.atmosFogExtinctionStrength = limit( GetDvarFloat( "scr_atmosFogExtinctionStrength" ) );
	level.atmosFogInScatterStrength = limit( GetDvarFloat( "scr_atmosFogInScatterStrength" ) );
	level.atmosFogHalfPlaneDistance = limit( GetDvarFloat( "scr_atmosFogHalfPlaneDistance" ) );
	level.atmosFogStartDistance = limit( GetDvarFloat( "scr_atmosFogStartDistance" ) );
	level.atmosFogDistanceScale = limit( GetDvarFloat( "scr_atmosFogDistanceScale" ) );
	level.atmosFogSkyDistance = GetDvarInt( "scr_atmosFogSkyDistance" );
	level.atmosFogSkyAngularFalloffEnabled = GetDvarInt( "scr_atmosFogSkyAngularFalloffEnabled" );
	level.atmosFogSkyFalloffStartAngle = limit( GetDvarFloat( "scr_atmosFogSkyFalloffStartAngle" ) );
	level.atmosFogSkyFalloffAngleRange = limit( GetDvarFloat( "scr_atmosFogSkyFalloffAngleRange" ) );
	vec3 = GetDvarVector( "scr_atmosFogSunDirection" );
	x = limit( vec3[0] );
	y = limit( vec3[1] );
	z = limit( vec3[2] );
	level.atmosFogSunDirection = ( x, y, z );
	level.atmosFogHeightFogEnabled = GetDvarInt( "scr_atmosFogHeightFogEnabled" );
	level.atmosFogHeightFogBaseHeight = limit( GetDvarFloat( "scr_atmosFogHeightFogBaseHeight" ) );
	level.atmosFogHeightFogHalfPlaneDistance = limit( GetDvarFloat( "scr_atmosFogHeightFogHalfPlaneDistance" ) );
}

limit( i)
{
	limit = 0.001;
	if ( ( i < limit ) && ( i > ( limit * -1 ) ) )
		 i  = 0;
	return i;
}

updateFogEntFromScript()
{
	if ( GetDvarInt( "scr_cmd_plr_sun" ) )
	{
		SetDevDvar( "scr_sunFogDir", AnglesToForward( level.player GetPlayerAngles() ) );
		SetDevDvar( "scr_cmd_plr_sun", 0 );
	}
	if ( GetDvarInt( "scr_cmd_plr_sun_atmos_fog" ) )
	{
		SetDevDvar( "scr_atmosFogSunDirection", AnglesToForward( level.player GetPlayerAngles() ) );
		SetDevDvar( "scr_cmd_plr_sun_atmos_fog", 0 );
	}
	vision_set_name = ToLower(level.vision_set_transition_ent.vision_set);
	if ( level.currentgen )
	{
		vision_set_name_cg = vision_set_name + "_cg";
		if ( IsDefined( level.vision_set_fog[ vision_set_name_cg ] ) )
			vision_set_name = vision_set_name_cg;
	}
	ent = level.vision_set_fog[ vision_set_name ];

	if ( isdefined( ent ) && isdefined( ent.HDROverride ) && isdefined( level.vision_set_fog[ ToLower(ent.HDROverride) ] ) )
	{
		ent = level.vision_set_fog[ ToLower(ent.HDROverride) ];
	}
	
	if( IsDefined( ent ) && isdefined( ent.name ) )
	{
		ent.startDist 					= level.fognearplane;
		ent.halfwayDist 				= level.fogexphalfplane;
		ent.red 						= level.fogcolor[ 0 ];
		ent.green 						= level.fogcolor[ 1 ];
		ent.blue 						= level.fogcolor[ 2 ];
		ent.HDRColorIntensity 			= level.fogHDRColorIntensity;
		ent.maxOpacity 					= level.fogmaxopacity;
		ent.sunFogEnabled 				= level.sunFogEnabled;
		ent.sunRed 						= level.sunFogColor[ 0 ];
		ent.sunGreen 					= level.sunFogColor[ 1 ];
		ent.sunBlue 					= level.sunFogColor[ 2 ];
		ent.HDRSunColorIntensity 		= level.sunFogHDRColorIntensity;
		ent.sunDir 						= level.sunFogDir;
		ent.sunBeginFadeAngle 			= level.sunFogBeginFadeAngle;
		ent.sunEndFadeAngle 			= level.sunFogEndFadeAngle;
		ent.normalFogScale 				= level.sunFogScale;
		ent.skyFogIntensity 			= level.skyFogIntensity;
		ent.skyFogMinAngle 				= level.skyFogMinAngle;
		ent.skyFogMaxAngle 				= level.skyFogMaxAngle;

		if ( IsDefined( level.heightFogEnabled ) && IsDefined( level.heightFogBaseHeight ) && IsDefined( level.heightFogHalfPlaneDistance ) )
		{
			ent.heightFogEnabled			= level.heightFogEnabled;
			ent.heightFogBaseHeight			= level.heightFogBaseHeight;
			ent.heightFogHalfPlaneDistance	= level.heightFogHalfPlaneDistance;
		}
		else
		{
			ent.heightFogEnabled			= 0;
			ent.heightFogBaseHeight			= 0;
			ent.heightFogHalfPlaneDistance	= 1000;
		}

		if ( IsDefined( level.atmosFogEnabled ) )
		{
			Assert( IsDefined( level.atmosFogSunFogColor ) );
			Assert( IsDefined( level.atmosFogHazeColor ) );
			Assert( IsDefined( level.atmosFogHazeStrength ) );
			Assert( IsDefined( level.atmosFogHazeSpread ) );
			Assert( IsDefined( level.atmosFogExtinctionStrength ) );
			Assert( IsDefined( level.atmosFogInScatterStrength ) );
			Assert( IsDefined( level.atmosFogHalfPlaneDistance ) );
			Assert( IsDefined( level.atmosFogStartDistance ) );
			Assert( IsDefined( level.atmosFogDistanceScale ) );
			Assert( IsDefined( level.atmosFogSkyDistance ) );
			Assert( IsDefined( level.atmosFogSkyAngularFalloffEnabled ) );
			Assert( IsDefined( level.atmosFogSkyFalloffStartAngle ) );
			Assert( IsDefined( level.atmosFogSkyFalloffAngleRange ) );
			Assert( IsDefined( level.atmosFogSunDirection ) );
			Assert( IsDefined( level.atmosFogHeightFogEnabled ) );
			Assert( IsDefined( level.atmosFogHeightFogBaseHeight ) );
			Assert( IsDefined( level.atmosFogHeightFogHalfPlaneDistance ) );

			ent.atmosFogEnabled						= level.atmosFogEnabled;
			ent.atmosFogSunFogColor					= level.atmosFogSunFogColor;
			ent.atmosFogHazeColor					= level.atmosFogHazeColor;
			ent.atmosFogHazeStrength				= level.atmosFogHazeStrength;
			ent.atmosFogHazeSpread					= level.atmosFogHazeSpread;
			ent.atmosFogExtinctionStrength			= level.atmosFogExtinctionStrength;
			ent.atmosFogInScatterStrength			= level.atmosFogInScatterStrength;
			ent.atmosFogHalfPlaneDistance			= level.atmosFogHalfPlaneDistance;
			ent.atmosFogStartDistance				= level.atmosFogStartDistance;
			ent.atmosFogDistanceScale				= level.atmosFogDistanceScale;
			ent.atmosFogSkyDistance					= level.atmosFogSkyDistance;
			ent.atmosFogSkyAngularFalloffEnabled	= level.atmosFogSkyAngularFalloffEnabled;
			ent.atmosFogSkyFalloffStartAngle		= level.atmosFogSkyFalloffStartAngle;
			ent.atmosFogSkyFalloffAngleRange		= level.atmosFogSkyFalloffAngleRange;
			ent.atmosFogSunDirection				= level.atmosFogSunDirection;
			ent.atmosFogHeightFogEnabled			= level.atmosFogHeightFogEnabled;
			ent.atmosFogHeightFogBaseHeight			= level.atmosFogHeightFogBaseHeight;
			ent.atmosFogHeightFogHalfPlaneDistance	= level.atmosFogHeightFogHalfPlaneDistance;
		}
		else 
		{
			if ( IsDefined( ent.atmosFogEnabled ) )
			{
				ent.atmosFogEnabled					= 0;
			}
		}

		if ( GetDvarInt( "scr_fog_disable" ) )
		{
			ent.startDist 					= 2000000000;
			ent.halfwayDist 				= 2000000001;
			ent.red 						= 0;
			ent.green 						= 0;
			ent.blue 						= 0;
			ent.HDRColorIntensity 			= 1;
			ent.HDRSunColorIntensity 		= 1;
			ent.maxOpacity 					= 0;
			ent.skyFogIntensity 			= 0;
			ent.heightFogEnabled			= 0;
			ent.heightFogBaseHeight			= 0;
			ent.heightFogHalfPlaneDistance	= 1000;

			if ( IsDefined( ent.atmosFogEnabled ) )
			{
				ent.atmosFogEnabled		= 0;
			}
		}		
		
		set_fog_to_ent_values( ent, 0 );
	}
}

fogslidercheck()
{
	// catch all those cases where a slider can be pushed to a place of conflict
	if ( level.sunFogBeginFadeAngle >= level.sunFogEndFadeAngle )
	{
		level.sunFogBeginFadeAngle = level.sunFogEndFadeAngle - 1;
		SetDvar( "scr_sunFogBeginFadeAngle", level.sunFogBeginFadeAngle );
	}
	
	if ( level.sunFogEndFadeAngle <= level.sunFogBeginFadeAngle )
	{
		level.sunFogEndFadeAngle = level.sunFogBeginFadeAngle + 1;
		SetDvar( "scr_sunFogEndFadeAngle", level.sunFogEndFadeAngle );
	}
}

add_vision_set_to_list( vision_set_name )
{
	assert( IsDefined( level.vision_set_names ) );
	
	found = array_find( level.vision_set_names, vision_set_name );
	if ( IsDefined( found ) )
		return;
	
	level.vision_set_names = array_add( level.vision_set_names, vision_set_name );
}

print_vision( vision_set )
{
	found = array_find( level.vision_set_names, vision_set );
	if ( !IsDefined( found ) )
		return;
	
	fileprint_launcher_start_file();
	
	// Glow
	fileprint_launcher( "r_glow                   \"" + GetDvar( "r_glowTweakEnable" ) + "\"" );
	fileprint_launcher( "r_glowRadius0            \"" + GetDvar( "r_glowTweakRadius0" ) + "\"" );
	fileprint_launcher( "r_glowBloomPinch         \"" + GetDvar( "r_glowTweakBloomPinch" ) + "\"" );
	fileprint_launcher( "r_glowBloomCutoff        \"" + GetDvar( "r_glowTweakBloomCutoff" ) + "\"" );
	fileprint_launcher( "r_glowBloomDesaturation  \"" + GetDvar( "r_glowTweakBloomDesaturation" ) + "\"" );
	fileprint_launcher( "r_glowBloomIntensity0    \"" + GetDvar( "r_glowTweakBloomIntensity0" ) + "\"" );
	fileprint_launcher( "r_glowUseAltCutoff       \"" + GetDvar( "r_glowTweakUseAltCutoff" ) + "\"" );
	fileprint_launcher( "" );

	// Film
	fileprint_launcher( "r_filmEnable            \"" + GetDvar( "r_filmTweakEnable" ) + "\"" );
	fileprint_launcher( "r_filmContrast          \"" + GetDvar( "r_filmTweakContrast" ) + "\"" );
	if( level.currentgen )
		fileprint_launcher( "r_filmIntensity         \"" + GetDvar( "r_filmTweakIntensity" ) + "\"" );
	fileprint_launcher( "r_filmBrightness        \"" + GetDvar( "r_filmTweakBrightness" ) + "\"" );
	fileprint_launcher( "r_filmDesaturation      \"" + GetDvar( "r_filmTweakDesaturation" ) + "\"" );
	fileprint_launcher( "r_filmDesaturationDark  \"" + GetDvar( "r_filmTweakDesaturationDark" ) + "\"" );
	fileprint_launcher( "r_filmInvert            \"" + GetDvar( "r_filmTweakInvert" ) + "\"" );
	fileprint_launcher( "r_filmLightTint         \"" + GetDvar( "r_filmTweakLightTint" ) + "\"" );
	fileprint_launcher( "r_filmMediumTint        \"" + GetDvar( "r_filmTweakMediumTint" ) + "\"" );
	fileprint_launcher( "r_filmDarkTint          \"" + GetDvar( "r_filmTweakDarkTint" ) + "\"" );
	fileprint_launcher( " " );
	
	// Character Light
	fileprint_launcher( "r_primaryLightUseTweaks                \"" + GetDvar( "r_primaryLightUseTweaks" ) + "\"" );
	fileprint_launcher( "r_primaryLightTweakDiffuseStrength     \"" + GetDvar( "r_primaryLightTweakDiffuseStrength" ) + "\"" );
	fileprint_launcher( "r_primaryLightTweakSpecularStrength    \"" + GetDvar( "r_primaryLightTweakSpecularStrength" ) + "\"" );
	fileprint_launcher( "r_charLightAmbient                     \"" + GetDvar( "r_charLightAmbient" ) + "\"" );
	fileprint_launcher( " " );

	// Viewmodel Light
	fileprint_launcher( "r_viewModelPrimaryLightUseTweaks                \"" + GetDvar( "r_viewModelPrimaryLightUseTweaks" ) + "\"" );
	fileprint_launcher( "r_viewModelPrimaryLightTweakDiffuseStrength     \"" + GetDvar( "r_viewModelPrimaryLightTweakDiffuseStrength" ) + "\"" );
	fileprint_launcher( "r_viewModelPrimaryLightTweakSpecularStrength    \"" + GetDvar( "r_viewModelPrimaryLightTweakSpecularStrength" ) + "\"" );
	fileprint_launcher( "r_viewModelLightAmbient                         \"" + GetDvar( "r_viewModelLightAmbient" ) + "\"" );
	fileprint_launcher( " " );

	// Volume Light Scatter
	fileprint_launcher( "r_volumeLightScatter                   \"" + GetDvar( "r_volumeLightScatterUseTweaks" ) + "\"" );
	fileprint_launcher( "r_volumeLightScatterLinearAtten        \"" + GetDvar( "r_volumeLightScatterLinearAtten" ) + "\"" );
	fileprint_launcher( "r_volumeLightScatterQuadraticAtten     \"" + GetDvar( "r_volumeLightScatterQuadraticAtten" ) + "\"" );
	fileprint_launcher( "r_volumeLightScatterAngularAtten       \"" + GetDvar( "r_volumeLightScatterAngularAtten" ) + "\"" );
	fileprint_launcher( "r_volumeLightScatterDepthAttenNear     \"" + GetDvar( "r_volumeLightScatterDepthAttenNear" ) + "\"" );
	fileprint_launcher( "r_volumeLightScatterDepthAttenFar      \"" + GetDvar( "r_volumeLightScatterDepthAttenFar" ) + "\"" );
	fileprint_launcher( "r_volumeLightScatterBackgroundDistance \"" + GetDvar( "r_volumeLightScatterBackgroundDistance" ) + "\"" );
	fileprint_launcher( "r_volumeLightScatterColor              \"" + GetDvar( "r_volumeLightScatterColor" ) + "\"" );
	fileprint_launcher( "r_volumeLightScatterEv                 \"" + GetDvar( "r_volumeLightScatterEv" ) + "\"" );
	fileprint_launcher( " " );

	// Rim Light (keep in sync with #define RIM_LIGHTING in platform_defines.h)
	fileprint_launcher( "r_rimLightUseTweaks           \"" + GetDvar( "r_rimLightUseTweaks" ) + "\"" );
	fileprint_launcher( "r_rimLight0Pitch              \"" + GetDvar( "r_rimLight0Pitch" ) + "\"" );
	fileprint_launcher( "r_rimLight0Heading            \"" + GetDvar( "r_rimLight0Heading" ) + "\"" );
	fileprint_launcher( "r_rimLightDiffuseIntensity    \"" + GetDvar( "r_rimLightDiffuseIntensity" ) + "\"" );
	fileprint_launcher( "r_rimLightSpecIntensity       \"" + GetDvar( "r_rimLightSpecIntensity" ) + "\"" );
	fileprint_launcher( "r_rimLightBias                \"" + GetDvar( "r_rimLightBias" ) + "\"" );
	fileprint_launcher( "r_rimLightPower               \"" + GetDvar( "r_rimLightPower" ) + "\"" );
	fileprint_launcher( "r_rimLight0Color              \"" + GetDvar( "r_rimLight0Color" ) + "\"" );
	fileprint_launcher( "r_rimLightFalloffMaxDistance  \"" + GetDvar( "r_rimLightFalloffMaxDistance" ) + "\"" );
	fileprint_launcher( "r_rimLightFalloffMinDistance  \"" + GetDvar( "r_rimLightFalloffMinDistance" ) + "\"" );
	fileprint_launcher( "r_rimLightFalloffMinIntensity \"" + GetDvar( "r_rimLightFalloffMinIntensity" ) + "\"" );
	fileprint_launcher( " " );

	// Unlit Surface
	fileprint_launcher( "r_unlitSurfaceHDRScalar \"" + GetDvar( "r_unlitSurfaceHDRScalar" ) + "\"" );
	fileprint_launcher( "" );
	
	// Chromatic Aberration
	fileprint_launcher( "r_chromaticAberrationMode \"" + GetDvar( "r_chromaticAberration" ) + "\"" );
	fileprint_launcher( "r_chromaticSeparation \"" + GetDvar( "r_chromaticSeparationR" ) + " " + GetDvar( "r_chromaticSeparationG" ) + " " + GetDvar( "r_chromaticSeparationB" ) + "\"" );
	fileprint_launcher( "r_chromaticAberrationAlpha \"" + GetDvar( "r_chromaticAberrationAlpha" ) + "\"" );

	visionFileName = "\\share\\raw\\vision\\" + vision_set + ".vision";
	
    return fileprint_launcher_end_file( visionFileName, true );
}

get_lightset_filename()
{
	if ( level.nextgen )
	{
		// [nextgen-begin]
		return "\\share\\raw\\maps\\createart\\" + get_template_level() + "_lightsets_hdr.csv";
		// [nextgen-end]
	}
	else
	{
		return "\\share\\raw\\maps\\createart\\" + get_template_level() + "_lightsets.csv";
	}
}

print_lightset( lightset_filename )
{
	fileprint_launcher_start_file();
	
	PrintLightSetSettings();
		
    return fileprint_launcher_end_file( lightset_filename, true );
	
}


print_fog_ents( forMP )
{
	foreach( ent in level.vision_set_fog )
	{
		if( !isdefined( ent.name ) )
			continue;

		ConvertLegacyFog( ent );
		
		if ( forMP )
			fileprint_launcher( "\tent = maps\\mp\\_art::create_vision_set_fog( \"" + ent.name + "\" );");
		else
			fileprint_launcher( "\tent = maps\\_utility::create_vision_set_fog( \"" + ent.name + "\" );");
		
		if( isdefined( ent.startDist ) )
			fileprint_launcher( "\tent.startDist = "+ent.startDist + ";" );
		if( isdefined( ent.halfwayDist ) )
			fileprint_launcher( "\tent.halfwayDist = "+ent.halfwayDist + ";" );
		if( isdefined( ent.red ) )
			fileprint_launcher( "\tent.red = "+ent.red + ";" );
		if( isdefined( ent.green ) )
			fileprint_launcher( "\tent.green = "+ent.green + ";" );
		if( isdefined( ent.blue ) )
			fileprint_launcher( "\tent.blue = "+ent.blue + ";" );
		if( isdefined( ent.HDRColorIntensity ) )
			fileprint_launcher( "\tent.HDRColorIntensity = "+ent.HDRColorIntensity + ";" );
		if( isdefined( ent.maxOpacity ) )
			fileprint_launcher( "\tent.maxOpacity = "+ent.maxOpacity + ";" );
		if( isdefined( ent.transitionTime ) )
			fileprint_launcher( "\tent.transitionTime = "+ent.transitionTime + ";" );
		if( isdefined( ent.sunFogEnabled ) )
			fileprint_launcher( "\tent.sunFogEnabled = "+ent.sunFogEnabled + ";" );
		if( isdefined( ent.sunRed ) )
			fileprint_launcher( "\tent.sunRed = "+ent.sunRed + ";" );
		if( isdefined( ent.sunGreen ) )
			fileprint_launcher( "\tent.sunGreen = "+ent.sunGreen + ";" );
		if( isdefined( ent.sunBlue ) )
			fileprint_launcher( "\tent.sunBlue = "+ent.sunBlue + ";" );
		if( isdefined( ent.HDRSunColorIntensity ) )
			fileprint_launcher( "\tent.HDRSunColorIntensity = "+ent.HDRSunColorIntensity + ";" );
		if( isdefined( ent.sunDir ) )
			fileprint_launcher( "\tent.sunDir = "+ent.sunDir + ";" );
		if( isdefined( ent.sunBeginFadeAngle ) )
			fileprint_launcher( "\tent.sunBeginFadeAngle = "+ent.sunBeginFadeAngle + ";" );
		if( isdefined( ent.sunEndFadeAngle ) )
			fileprint_launcher( "\tent.sunEndFadeAngle = "+ent.sunEndFadeAngle + ";" );
		if( isdefined( ent.normalFogScale ) )
			fileprint_launcher( "\tent.normalFogScale = "+ent.normalFogScale + ";" );
		if( isdefined( ent.skyFogIntensity ) )
			fileprint_launcher( "\tent.skyFogIntensity = "+ent.skyFogIntensity + ";" );
		if( isdefined( ent.skyFogMinAngle ) )
			fileprint_launcher( "\tent.skyFogMinAngle = "+ent.skyFogMinAngle + ";" );
		if( isdefined( ent.skyFogMaxAngle ) )
			fileprint_launcher( "\tent.skyFogMaxAngle = "+ent.skyFogMaxAngle + ";" );
		if ( IsDefined( ent.HDROverride ) )
			fileprint_launcher( "\tent.HDROverride = \"" + ent.HDROverride + "\";" );
		if ( IsDefined( ent.heightFogEnabled ) )
			fileprint_launcher( "\tent.heightFogEnabled = " + ent.heightFogEnabled + ";" );
		if ( IsDefined( ent.heightFogBaseHeight ) )
			fileprint_launcher( "\tent.heightFogBaseHeight = " + ent.heightFogBaseHeight + ";" );
		if ( IsDefined( ent.heightFogHalfPlaneDistance ) )
			fileprint_launcher( "\tent.heightFogHalfPlaneDistance = " + ent.heightFogHalfPlaneDistance + ";" );
	
		if ( IsDefined( ent.atmosFogEnabled ) )
			fileprint_launcher( "\tent.atmosFogEnabled = " + ent.atmosFogEnabled + ";" );
		if ( IsDefined( ent.atmosFogSunFogColor ) )
			fileprint_launcher( "\tent.atmosFogSunFogColor = " + ent.atmosFogSunFogColor + ";" );
		if ( IsDefined( ent.atmosFogHazeColor ) )
			fileprint_launcher( "\tent.atmosFogHazeColor = " + ent.atmosFogHazeColor + ";" );
		if ( IsDefined( ent.atmosFogHazeStrength ) )
			fileprint_launcher( "\tent.atmosFogHazeStrength = " + ent.atmosFogHazeStrength + ";" );
		if ( IsDefined( ent.atmosFogHazeSpread ) )
			fileprint_launcher( "\tent.atmosFogHazeSpread = " + ent.atmosFogHazeSpread + ";" );
		if ( IsDefined( ent.atmosFogExtinctionStrength ) )
			fileprint_launcher( "\tent.atmosFogExtinctionStrength = " + ent.atmosFogExtinctionStrength + ";" );
		if ( IsDefined( ent.atmosFogInScatterStrength ) )
			fileprint_launcher( "\tent.atmosFogInScatterStrength = " + ent.atmosFogInScatterStrength + ";" );
		if ( IsDefined( ent.atmosFogHalfPlaneDistance ) )
			fileprint_launcher( "\tent.atmosFogHalfPlaneDistance = " + ent.atmosFogHalfPlaneDistance + ";" );
		if ( IsDefined( ent.atmosFogStartDistance ) )
			fileprint_launcher( "\tent.atmosFogStartDistance = " + ent.atmosFogStartDistance + ";" );
		if ( IsDefined( ent.atmosFogDistanceScale ) )
			fileprint_launcher( "\tent.atmosFogDistanceScale = " + ent.atmosFogDistanceScale + ";" );
		if ( IsDefined( ent.atmosFogSkyDistance ) )
			fileprint_launcher( "\tent.atmosFogSkyDistance = " + int( ent.atmosFogSkyDistance ) + ";" );
		if ( IsDefined( ent.atmosFogSkyAngularFalloffEnabled ) )
			fileprint_launcher( "\tent.atmosFogSkyAngularFalloffEnabled = " + ent.atmosFogSkyAngularFalloffEnabled + ";" );
		if ( IsDefined( ent.atmosFogSkyFalloffStartAngle ) )
			fileprint_launcher( "\tent.atmosFogSkyFalloffStartAngle = " + ent.atmosFogSkyFalloffStartAngle + ";" );
		if ( IsDefined( ent.atmosFogSkyFalloffAngleRange ) )
			fileprint_launcher( "\tent.atmosFogSkyFalloffAngleRange = " + ent.atmosFogSkyFalloffAngleRange + ";" );
		if ( IsDefined( ent.atmosFogSunDirection ) )
			fileprint_launcher( "\tent.atmosFogSunDirection = " + ent.atmosFogSunDirection + ";" );
		if ( IsDefined( ent.atmosFogHeightFogEnabled ) )
			fileprint_launcher( "\tent.atmosFogHeightFogEnabled = " + ent.atmosFogHeightFogEnabled + ";" );
		if ( IsDefined( ent.atmosFogHeightFogBaseHeight ) )
			fileprint_launcher( "\tent.atmosFogHeightFogBaseHeight = " + ent.atmosFogHeightFogBaseHeight + ";" );
		if ( IsDefined( ent.atmosFogHeightFogHalfPlaneDistance ) )
			fileprint_launcher( "\tent.atmosFogHeightFogHalfPlaneDistance = " + ent.atmosFogHeightFogHalfPlaneDistance + ";" );
	
		if( isDefined( ent.stagedVisionSets ) )
		{
			string = " ";
			for( i = 0; i < ent.stagedVisionSets.size; i++ )
			{
				string = string + "\""+ ent.stagedVisionSets[i] + "\"";
				if ( i < ent.stagedVisionSets.size - 1 )
					string = string + ",";
				string = string + " ";
			}

			fileprint_launcher( "\tent.stagedVisionSets =     [" + string + "];" );
		}

		fileprint_launcher ( " " );
	}
	
	if ( !forMP )
	{	// MP holds this script in the setup_fog() function.
		// put out our dev only call to our fog file (normally code will parse it and apply it clientside)
		fileprint_launcher( "\t/$" );
		if ( IsUsingHDR() )
			fileprint_launcher( "\tlevel._art_fog_setup = maps\\createart\\" + level.script + "_fog_hdr::main;" );
		else
			fileprint_launcher( "\tlevel._art_fog_setup = maps\\createart\\" + level.script + "_fog::main;" );
		fileprint_launcher( "\t$/" );
	}
}

print_fog_ents_csv()
{
	foreach( ent in level.vision_set_fog )
	{
		if( !isdefined( ent.name ) )
			continue;

		targettedByHDROverride = false;
		foreach( ent2 in level.vision_set_fog )
		{
			if ( isdefined(ent2.HDROverride) && ent2.HDROverride == ent.name )
			{
				targettedByHDROverride = true;
				break;
			}
		}

		if ( !targettedByHDROverride )
			fileprint_launcher( "rawfile,vision/"+ent.name+".vision");
	}	
}
$/
