#using scripts\codescripts\struct;
#using scripts\shared\clientfield_shared;

#using scripts\shared\util_shared;

#using scripts\mp\_load;
#using scripts\mp\_util;

#using scripts\mp\mp_nuketown_x_fx;
#using scripts\mp\mp_nuketown_x_sound;

    	   	                                                                                                                                         	                                	                                                                                                                                                                                                                                                                                                                                                                    	        	     	              	    	   	               	                                              	                                                           	                               	                     	                                                                                                           	                                                                 	                                                              	                                                                                                                                             	                            	                                     	                                       	                                                                                                              	   	                  	       	                                                    	                   	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            	                                                                                                 	                                    	                                                                                        	           	                        	                                            	                                             	                                                   	                                                             	                                                         	                                                                    	                                                                                                                                                                                                                                	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  	    	         	                                                              	                                                          	                                   	                                   	                                                    	                                       	                                           	     	                                                                                                                                                                                                                                                      	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         	                                                               	        	                                                                                                                              	                                                                                                                     	                               	                                                      	                          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         	   	                                                                                                                                                                                                                                  	                                                                                                                                                                                                                                                                                                                                                                                                                                                   

#precache( "client_fx", "ui/fx_dom_cap_indicator_neutral_r120" );
#precache( "client_fx", "ui/fx_dom_cap_indicator_team_r120" );
#precache( "client_fx", "ui/fx_dom_marker_neutral_r120" );
#precache( "client_fx", "ui/fx_dom_marker_team_r120" );

function main()
{
	clientfield::register( "scriptmover", "nuketown_population_ones", 1, 4, "int", &nuketown_population_changed, !true, !true );
	clientfield::register( "scriptmover", "nuketown_population_tens", 1, 4, "int", &nuketown_population_changed, !true, !true );
	clientfield::register( "world", "nuketown_endgame", 1, 1, "int", &nuketown_endgame_changed, !true, !true );
	
	mp_nuketown_x_fx::main();
	mp_nuketown_x_sound::main();
	
	load::main();
	
	level.domFlagBaseFxOverride = &dom_flag_base_fx_override;
	level.domFlagCapFxOverride = &dom_flag_cap_fx_override;

	util::waitforclient( 0 );	// This needs to be called after all systems have been registered.

	level.endGameXCamName = "ui_cam_endgame_mp_nuketown";
}

function nuketown_endgame_changed( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
{
	/#
	if( newVal )
	{
		SetDvar( "player_lens_enabled", false );
		SetDvar( "cg_focalLength", 10.64 );
	}
	else
	{
		SetDvar( "player_lens_enabled", true );
	}
	#/
}

function nuketown_population_changed( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
{
	self MapShaderConstant( localClientNum, 0, "scriptVector0", newVal, 0, 0, 0 );    
}

function dom_flag_base_fx_override( flag, team )
{
	switch ( flag.name )
	{
		case "a":
			if ( team == "neutral" )
			{
				return "ui/fx_dom_marker_neutral_r120";
			}
			else
			{
				return "ui/fx_dom_marker_team_r120";
			}
			break;
		case "b":
			if ( team == "neutral" )
			{
				return "ui/fx_dom_marker_neutral_r120";
			}
			else
			{
				return "ui/fx_dom_marker_team_r120";
			}
			break;
		case "c":
			if ( team == "neutral" )
			{
				return "ui/fx_dom_marker_neutral_r120";
			}
			else
			{
				return "ui/fx_dom_marker_team_r120";
			}
			break;
	};
}

function dom_flag_cap_fx_override( flag, team )
{
	switch ( flag.name )
	{
		case "a":
			if ( team == "neutral" )
			{
				return "ui/fx_dom_cap_indicator_neutral_r120";
			}
			else
			{
				return "ui/fx_dom_cap_indicator_team_r120";
			}
			break;
		case "b":
			if ( team == "neutral" )
			{
				return "ui/fx_dom_cap_indicator_neutral_r120";
			}
			else
			{
				return "ui/fx_dom_cap_indicator_team_r120";
			}
			break;
		case "c":
			if ( team == "neutral" )
			{
				return "ui/fx_dom_cap_indicator_neutral_r120";
			}
			else
			{
				return "ui/fx_dom_cap_indicator_team_r120";
			}
			break;
	};
}