//==========================================================================================
//
//	eichsfeld.gm
//
//	Who                    	When		What
//------------------------------------------------------------------------------------------
//	^1{WeB}^7*^4GA^1NG$^4TA^7*	26 June 2015	Initial Script
//
//==========================================================================================
//

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

	Command_Post_Dyno = 0,
	Controls_Dyno = 0,
	Courtyard_Wall_Dyno = 0,
	Main_Entrance_Dyno = 0,
	side_door_Dyno = 0,
	side_gate_Dyno = 0,

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

		Util.MapDebugPrint( "Command_Post_Built" );
	},

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

		Util.MapDebugPrint( "side_gate_Built" );
	},

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

		Map.Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Command_Post_Planted" );
	},

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

		Map.Controls_Dyno += 1;
		Util.MapDebugPrint( "Controls_Planted" );
	},

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

		Map.Courtyard_Wall_Dyno += 1;
		Util.MapDebugPrint( "Courtyard_Wall_Planted" );
	},

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

		Map.Main_Entrance_Dyno += 1;
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},

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

		Map.side_door_Dyno += 1;
		Util.MapDebugPrint( "side_door_Planted" );
	},

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

		Map.side_gate_Dyno += 1;
		Util.MapDebugPrint( "side_gate_Planted" );
	},

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

		Map.Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Command_Post_Defused" );
	},

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

		Map.Controls_Dyno -= 1;
		Util.MapDebugPrint( "Controls_Defused" );
	},

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

		Map.Courtyard_Wall_Dyno -= 1;
		Util.MapDebugPrint( "Courtyard_Wall_Defused" );
	},

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

		Map.Main_Entrance_Dyno -= 1;
		Util.MapDebugPrint( "Main_Entrance_Defused" );
	},

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

		Map.side_door_Dyno -= 1;
		Util.MapDebugPrint( "side_door_Defused" );
	},

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

		Map.side_gate_Dyno -= 1;
		Util.MapDebugPrint( "side_gate_Defused" );
	},

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

		Map.Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

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

		Map.Controls_Dyno = 0;

		Util.MapDebugPrint( "Controls_Destroyed" );
	},

	Courtyard_Wall_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }
			
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_maingate_1" );
	    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_maingate_2" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_maingate_3" );
	    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_maingate_4" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_maingate_5" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_maingate_6" );
	    SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_maingate_7" );			

		Map.Courtyard_Wall_Dyno = 0;

		Util.MapDebugPrint( "Courtyard_Wall_Destroyed" );
	},

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

		Map.Main_Entrance_Dyno = 0;

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

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

		Map.side_door_Dyno = 0;

		Util.MapDebugPrint( "side_door_Destroyed" );
	},

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

		Map.side_gate_Dyno = 0;

		Util.MapDebugPrint( "side_gate_Destroyed" );
	},

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

		Util.MapDebugPrint( "forward_spawn_Axis_Captured" );
	},

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

		Util.MapDebugPrint( "forward_spawn_Allies_Captured" );
	},
	
	Main_Blast_Door_Open = function( trigger )
	{
		if ( TestMap )
			{ return; }
		SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_main_entrance_1" );
		SetAvailableMapGoals( TEAM.AXIS, true, "SWITCH_main_entrance_2" );

		Util.MapDebugPrint( "Main_Blast_Door_Open" );
	},
	
	Main_Blast_Door_Closed = function( trigger )
	{
		if ( TestMap )
			{ return; }
		SetAvailableMapGoals( TEAM.AXIS, false, "SWITCH_main_entrance_2" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_main_entrance_1" );

		Util.MapDebugPrint( "Main_Blast_Door_Closed" );
	},

	Control_Door_Open = function( trigger )
	{
		if ( TestMap )
			{ return; }
		SetAvailableMapGoals( TEAM.AXIS, true, "SWITCH_Ladebucht_1" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_Ladebucht_1" );

		Util.MapDebugPrint( "Control_Door_Open" );
	},
	
	Control_Door_Closed = function( trigger )
	{
		if ( TestMap )
			{ return; }
		SetAvailableMapGoals( TEAM.AXIS, false, "SWITCH_Ladebucht_1" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_Ladebucht_1" );

		Util.MapDebugPrint( "Control_Door_Closed" );
	},
};

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

	// Register callback functions
	OnTrigger( "MISSING_STRING", Map.Command_Post_Built );
	OnTrigger( "The side gate has been built!", Map.side_gate_Built );
	OnTrigger( "^7Control Door opening!", Map.Control_Door_Open );
	OnTrigger( "^7Control Door closing!", Map.Control_Door_Closed );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Command_Post_Planted );
	OnTrigger( "^7Main blast door opening! Map.Main_Blast_Door_Open );
	OnTrigger( "^7Main blast door closing!", Map.Main_Blast_Door_Closed );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Controls_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Courtyard_Wall_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Main_Entrance_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.side_door_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.side_gate_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Command_Post_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Controls_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Courtyard_Wall_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Main_Entrance_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.side_door_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.side_gate_Defused );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Destroyed );
	OnTrigger( "Allies have destroyed the Controls!", Map.Controls_Destroyed );
	OnTrigger( "The Courtyard Wall has been breached!", Map.Courtyard_Wall_Destroyed );
	OnTrigger( "Allies have breached the Main Entrance and secured the Entrance Area!", Map.Main_Entrance_Destroyed );
	OnTrigger( "Allies have destroyed the Side Door!", Map.side_door_Destroyed );
	OnTrigger( "The side gate has been destroyed!", Map.side_gate_Destroyed );
	OnTrigger( "Axis recapture the Entrance Area!", Map.forward_spawn_Axis_Captured );
	OnTrigger( "Allies capture the Entrance Area!", Map.forward_spawn_Allies_Captured );
	
	SetGoalPriority("PLANT_Main_Entrance, 0.91);
	SetGoalPriority("PLANT_side_door", 0.91);
	SetGoalPriority("PLANT_Courtyard_Wall", 0.91);
	SetGoalPriority("PLANT_side_gate", 0.91);
	SetGoalPriority("PLANT_Controls", 0.91);
	

	//~Util.DisableGoal( ".*", true ); // all but routes
	//~SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_.*" );
	//~SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

	// Max users per goal
	//Util.SetMaxUsers( 1, "DEFEND_.*" );
	//Util.SetMaxUsers( 1, "GRENADE_.*" );
	//Util.SetMaxUsers( 1, "MOUNTMG42_.*" );

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


	Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " executed." );
};

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;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_side_gate =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Main_Entrance =
		{
		},
		PLANT_side_door =
		{
		},
		PLANT_side_gate =
		{
		},
		PLANT_Courtyard_Wall =
		{
		},
		PLANT_Command_Post =
		{
		},
		PLANT_Controls =
		{
		},
		CHECKPOINT_forward_spawn =
		{
		},
	};
	Util.Routes(MapRoutes);
};
