#using scripts\codescripts\struct;
#using scripts\shared\callbacks_shared;
#using scripts\shared\clientfield_shared;
#using scripts\shared\duplicaterender_mgr;
#using scripts\shared\filter_shared;
#using scripts\shared\util_shared;

#using scripts\shared\abilities\_ability_player;
#using scripts\shared\abilities\_ability_power;
#using scripts\shared\abilities\_ability_util;
#using scripts\shared\abilities\gadgets\_gadget_camo_render;

                                                                                
    	   	                                                                                                                                         	                                	                                                                                                                                                                                                                                                                                                                                                                    	        	     	              	    	   	               	                                              	                                                           	                               	                     	                                                                                                           	                                                                 	                                                              	                                                                                                                                             	                            	                                     	                                       	                                                                                                              	   	                  	       	                                                    	                   	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            	                                                                                                 	                                    	                                                                                        	           	                        	                                            	                                             	                                                   	                                                             	                                                         	                                                                    	                                                                                                                                                                                                                                	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  	    	         	                                                              	                                                          	                                   	                                   	                                                    	                                       	                                           	     	                                                                                                                                                                                                                                                      	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         	                                                               	        	                                                                                                                              	                                                                                                                     	                               	                                                      	                          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         	   	                                                                                                                                                                                                                                  	                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                       	   	                                                                      	  	  	

#using scripts\shared\system_shared;

function autoexec __init__sytem__() {     system::register("gadget_camo",&__init__,undefined,undefined);    }

function __init__()
{
	clientfield::register( "allplayers", "camo_shader", 1, 3, "int", &ent_camo_material_callback, !true, true );
}

function ent_camo_material_callback( local_client_num, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
{
	if ( oldVal == newVal && oldVal == 0 && !bWasTimeJump )
	{
		return;
	}

	flags_changed = self duplicate_render::set_dr_flag_not_array( "gadget_camo_friend", util::friend_not_foe( local_client_num, true ) );
	flags_changed |= self duplicate_render::set_dr_flag_not_array( "gadget_camo_flicker", newVal == 2 );
	flags_changed |= self duplicate_render::set_dr_flag_not_array( "gadget_camo_break", newVal == 3 );
	flags_changed |= self duplicate_render::set_dr_flag_not_array( "gadget_camo_reveal", newVal != oldVal );
	flags_changed |= self duplicate_render::set_dr_flag_not_array( "gadget_camo_on", newVal != 0 );
	flags_changed |= self duplicate_render::set_dr_flag_not_array( "hide_model",  newVal == 0 );
	flags_changed |= bNewEnt;

	if ( flags_changed )
	{
		self duplicate_render::update_dr_filters(local_client_num);
	}
	
	self notify( "endtest" );
	
	if ( newVal && ( bWasTimeJump || bNewEnt ) )
	{
		self thread gadget_camo_render::forceOn( local_client_num );
	}
	else if ( newVal != oldVal )
	{
		self thread gadget_camo_render::doReveal( local_client_num, newVal != 0 );
	}
	
	if ( newVal && !oldVal || ( newVal && ( bWasTimeJump || bNewEnt ) ) )
	{
		self GadgetPulseResetReveal();
	}
}
