//==========================================================================================
//
//	unit_cache_final.gm
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	d-luX	30 January 2021	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script
	ShowMovers = false,

	Backyard_Barrier_Dyno = 0,
	Generator_Dyno = 0,
	House_MG42_Dyno = 0,
	Neutral_Command_Post_Dyno = 0,
	Safe_Dyno = 0,
	Storage_Barrier_Dyno = 0,
	Long_way_gate_Dyno = 0,
	
	DocStatus = 0,
	
	ForwardFlag = "CHECKPOINT_westbunker_flag",
	Build_CP	= "BUILD_Neutral_Command_Post",
	Plant_CP	= "PLANT_Neutral_Command_Post",
	Build_storageb	= "BUILD_Storage_Barrier",
	Plant_storageb	= "PLANT_Storage_Barrier",
	Build_backyardb	= "BUILD_Backyard_Barrier",
	Plant_backyardb	= "PLANT_Backyard_Barrier",
	Build_housemg	= "BUILD_House_MG42",
		

	Safe_Planted = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Safe_Dyno += 1;
		Util.MapDebugPrint( "Safe_Planted" );
		
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_allies_attack_safe_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_safe_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_flag_.*" );	
	},
	
	Safe_Defused = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Safe_Dyno -= 1;
		Util.MapDebugPrint( "Safe_Defused" );
	},

	Safe_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Safe_Dyno = 0;

		Util.MapDebugPrint( "Safe_Destroyed" );
		
		Util.EnableGoal("FLAG_.*");
		
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_keycardcapture_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_flag_.*" );
	},
	
	westbunker_flag_Axis_Captured = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "westbunker_flag_Axis_Captured" );
	},

	westbunker_flag_Allies_Captured = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "westbunker_flag_Allies_Captured" );
	},	
	
	Keycard_Taken = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "Keycard_Taken" );
		
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_keycardcapture_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_axis_defend_flag_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_axis_defend_safe_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_.*" );
	},

	Keycard_Returned = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "Keycard_Returned" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_flag_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_safe_.*" );		
	},

	Keycard_Secured = function( trigger )
	{
		if ( TestMap )
			{ return; }

		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_axis_defend_keycardcapture_.*" );SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_axis_defend_flag_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_allies_attack_safe_.*" );
		
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_allies_attack_generator_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, Build_CP );
		SetAvailableMapGoals( TEAM.ALLIES, true, Plant_CP );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "SNIPE_.*" );
		
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_axis_defend_keycardcapture_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_axis_defend_flag_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_axis_defend_safe_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "CALLARTILLERY_axis_arti_.*" );
		
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_longway_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_axis_defend_generator_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Storage_Barrier" );
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Backyard_Barrier" );
		SetAvailableMapGoals( TEAM.AXIS, true, "MOUNTMG42_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "REPAIRMG42_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "CALLARTILLERY_axis_arti_longway_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "AIRSTRIKE_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANTMINE_.*" );
		
		Util.EnableGoal("BUILD_House_MG42");
		Util.EnableGoal("BUILD_Backyard_Barrier");
		Util.EnableGoal("BUILD_Storage_Barrier");
	},
	
	Neutral_Command_Post_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "Neutral_Command_Post_Built" );
	},
	
	Neutral_Command_Post_Planted = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Neutral_Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Neutral_Command_Post_Planted" );
	},
	
	Neutral_Command_Post_Defused = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Neutral_Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Neutral_Command_Post_Defused" );
	},
	
	Neutral_Command_Post_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Neutral_Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Neutral_Command_Post_Destroyed" );
	},	

	Backyard_Barrier_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "Backyard_Barrier_Built" );
	},
	
	House_MG42_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.House_MG42_Dyno = 0;

		Util.MapDebugPrint( "House_MG42_Destroyed" );
	},
	
	House_MG42_Defused = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.House_MG42_Dyno -= 1;
		Util.MapDebugPrint( "House_MG42_Defused" );
	},
	
	House_MG42_Planted = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.House_MG42_Dyno += 1;
		Util.MapDebugPrint( "House_MG42_Planted" );
	},
	
	House_MG42_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "House_MG42_Built" );
	},	
	
	Backyard_Barrier_Planted = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Backyard_Barrier_Dyno += 1;
		Util.MapDebugPrint( "Backyard_Barrier_Planted" );
	},

	Backyard_Barrier_Defused = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Backyard_Barrier_Dyno -= 1;
		Util.MapDebugPrint( "Backyard_Barrier_Defused" );
	},
	
	Backyard_Barrier_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Backyard_Barrier_Dyno = 0;

		Util.MapDebugPrint( "Backyard_Barrier_Destroyed" );
	},
	
	Long_way_gate_Planted = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Long_way_gate_Dyno += 1;
		Util.MapDebugPrint( "Long_way_gate_Planted" );
	},	

	Storage_Barrier_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "Storage_Barrier_Built" );
	},
	
	Storage_Barrier_Planted = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Storage_Barrier_Dyno += 1;
		Util.MapDebugPrint( "Storage_Barrier_Planted" );
	},
	
	Storage_Barrier_Defused = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Storage_Barrier_Dyno -= 1;
		Util.MapDebugPrint( "Storage_Barrier_Defused" );
	},
	
	Storage_Barrier_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Storage_Barrier_Dyno = 0;

		Util.MapDebugPrint( "Storage_Barrier_Destroyed" );
	},	
	
	Generator_Planted = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Generator_Dyno += 1;
		Util.MapDebugPrint( "Generator_Planted" );
		
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_defend_generator_.*" );
		
		
	},	

	Generator_Defused = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Generator_Dyno -= 1;
		Util.MapDebugPrint( "Generator_Defused" );
	},

	Generator_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Map.Generator_Dyno = 0;

		Util.MapDebugPrint( "Generator_Destroyed" );
	},

};

global OnMapLoad = function()
{
	if ( TestMapOn )
		{ Util.AutoTestMap(); }

	// Register callback functions
	OnTrigger( "MISSING_STRING", Map.Backyard_Barrier_Built );
	OnTrigger( "MISSING_STRING", Map.House_MG42_Built );
	OnTrigger( "Command Post constructed", Map.Neutral_Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.Storage_Barrier_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Backyard_Barrier_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Generator_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.House_MG42_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Neutral_Command_Post_Planted );
	OnTrigger( "Planted at the Safe.", Map.Safe_Planted );
	OnTrigger( "Planted at the Long way gate.", Map.Long_way_gate_Planted );	
	OnTrigger( "Planted at the MISSING_STRING.", Map.Storage_Barrier_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Backyard_Barrier_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Generator_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.House_MG42_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Neutral_Command_Post_Defused );
	OnTrigger( "Defused at the Safe.", Map.Safe_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Storage_Barrier_Defused );
	OnTrigger( "MISSING_STRING", Map.Backyard_Barrier_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Generator_Destroyed );
	OnTrigger( "MISSING_STRING", Map.House_MG42_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Neutral_Command_Post_Destroyed );
	OnTrigger( "Allies have blown the Tresor", Map.Safe_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Storage_Barrier_Destroyed );
	OnTrigger( "Allies have stolen the Keycard!", Map.Keycard_Taken );
	OnTrigger( "Axis have returned the Keycard!", Map.Keycard_Returned );
	OnTrigger( "Allies have open the gates!", Map.Keycard_Secured );
	OnTrigger( "Axis captured the Bunker!", Map.westbunker_flag_Axis_Captured );
	OnTrigger( "Allies captured the Bunker!", Map.westbunker_flag_Allies_Captured );
	
	Util.EnableGoal("CHECKPOINT_.*");
	Util.DisableGoal("FLAG_.*");
	Util.DisableGoal("BUILD_Neutral_Command_Post");
	Util.DisableGoal("PLANTMINE_.*");
	Util.DisableGoal("BUILD_House_MG42");
	Util.DisableGoal("BUILD_Storage_Barrier");
	Util.DisableGoal("BUILD_Backyard_Barrier");
	
    ETUtil.SetPrimaryGoals(1.0);
	ETUtil.LimitToClass( "PLANT_Safe", TEAM.ALLIES, CLASS.ENGINEER);
	ETUtil.LimitToClass( "CHECKPOINT_.*", TEAM.ALLIES, CLASS.MEDIC);
	ETUtil.LimitToClass( "CHECKPOINT_.*", TEAM.AXIS, CLASS.MEDIC);		

	//~Util.DisableGoal( ".*", true ); // all but routes
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "CALLARTILLERY_axis_arti_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Neutral_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_allies_attack_safe_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_allies_attack_generator_.*" );
	
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_axis_defend_keycardcapture_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_axis_defend_longway_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_axis_defend_generator_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "AIRSTRIKE_axis_airstrike_backyard" );
	
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Neutral_Command_Post" );
	
	SetGoalPriority( "PLANT_Safe", 0.9);
	SetGoalPriority( "PLANT_Long_way_gate", 0.6);

	// Max users per goal
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "SNIPE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "MOBILEMG42_.*" );
	Util.SetMaxUsers( 1, "MOBILEMORTAR_.*" );
	Util.SetMaxUsers( 1, "AIRSTRIKE_.*" );
	Util.SetMaxUsers( 1, "CALLARTILLERY_.*" );

	// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=10, MaxCampTime=60} );


};

global OnBotJoin = function( bot )
{
	// Uncomment for shootable breakables
	//~bot.TargetBreakableDist = 90.0;
	// Only set MaxViewDistance on maps with limited sight (e.g. fog)
	//~bot.MaxViewDistance = 2400;
};
