//==========================================================================================
//
//	pipeline.gm
//
//	Who                    	When		What
//------------------------------------------------------------------------------------------
//	^1{WeB}^7*^4GA^1NG$^4TA^7*	17 September 2015	Initial Script
//
//==========================================================================================
//

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

	Axis_tunnel_MG_Nest_Dyno = 0,
	Command_Post_Dyno = 0,
	Main_Entrance_Dyno = 0,
	Side_Entrance_Dyno = 0,

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

		Util.MapDebugPrint( "Axis_tunnel_MG_Nest_Built" );
	},

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

		Util.MapDebugPrint( "Command_Post_Built" );
	},

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

		Map.Axis_tunnel_MG_Nest_Dyno += 1;
		Util.MapDebugPrint( "Axis_tunnel_MG_Nest_Planted" );
	},

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

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

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

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

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

		Map.Side_Entrance_Dyno += 1;
		Util.MapDebugPrint( "Side_Entrance_Planted" );
	},

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

		Map.Axis_tunnel_MG_Nest_Dyno -= 1;
		Util.MapDebugPrint( "Axis_tunnel_MG_Nest_Defused" );
	},

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

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

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

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

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

		Map.Side_Entrance_Dyno -= 1;
		Util.MapDebugPrint( "Side_Entrance_Defused" );
	},

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

		Map.Axis_tunnel_MG_Nest_Dyno = 0;

		Util.MapDebugPrint( "Axis_tunnel_MG_Nest_Destroyed" );
	},

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

		Map.Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

	Main_Entrance_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }
			
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Command_Post" );
	    SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Command_Post" );	
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Command_Post" );
	    SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Command_Post" );

		Map.Main_Entrance_Dyno = 0;

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

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

		Map.Side_Entrance_Dyno = 0;

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

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

		Util.MapDebugPrint( "radarbox1_Taken" );
	},

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

		Util.MapDebugPrint( "radarbox2_Taken" );
	},

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

		Util.MapDebugPrint( "radarbox1_Returned" );
	},

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

		Util.MapDebugPrint( "radarbox2_Returned" );
	},

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

		Util.MapDebugPrint( "radarbox1_Secured" );
	},

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

		Util.MapDebugPrint( "radarbox2_Secured" );
	},

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

		Util.MapDebugPrint( "roadbunker_Axis_Captured" );
	},

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

		Util.MapDebugPrint( "roadbunker_Allies_Captured" );
	},

};

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

	// Register callback functions
	OnTrigger( "MISSING_STRING", Map.Axis_tunnel_MG_Nest_Built );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Axis_tunnel_MG_Nest_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Command_Post_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Main_Entrance_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Side_Entrance_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Axis_tunnel_MG_Nest_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Command_Post_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Main_Entrance_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Side_Entrance_Defused );
	OnTrigger( "MISSING_STRING", Map.Axis_tunnel_MG_Nest_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Destroyed );
	OnTrigger( "Allies have breached the Main Entrance and secured the Forward Bunker!", Map.Main_Entrance_Destroyed );
	OnTrigger( "Allies have breached the Side Entrance!", Map.Side_Entrance_Destroyed );
	OnTrigger( "MISSING_STRING", Map.radarbox1_Taken );
	OnTrigger( "MISSING_STRING", Map.radarbox2_Taken );
	OnTrigger( "MISSING_STRING", Map.radarbox1_Returned );
	OnTrigger( "MISSING_STRING", Map.radarbox2_Returned );
	OnTrigger( "MISSING_STRING", Map.radarbox1_Secured );
	OnTrigger( "MISSING_STRING", Map.radarbox2_Secured );
	OnTrigger( "Axis reclaim the Forward Bunker!", Map.roadbunker_Axis_Captured );
	OnTrigger( "Allies capture the Forward Bunker!", Map.roadbunker_Allies_Captured );
	
	SetGoalPriority( "PLANT_Main_Entrance", 0.91 );
	SetGoalPriority( "PLANT_Side_Entrance", 0.85 );
	
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_radar_1" );
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_radar_2" );
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_truck_1" );
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_truck_2" );
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_truck_3" );
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_truck_4" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_tunnel_MG_Nest" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Main_Entrance" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Side_Entrance" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_roadbunker" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_radarbox1" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_radarbox2" );

	//~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_Axis_tunnel_MG_Nest =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Axis_tunnel_MG_Nest =
		{
		},
		PLANT_Command_Post =
		{
		},
		PLANT_Main_Entrance =
		{
		},
		PLANT_Side_Entrance =
		{
		},
		FLAG_radarbox2 =
		{
		},
		FLAG_radarbox1 =
		{
		},
		CHECKPOINT_roadbunker =
		{
		},
	};
	Util.Routes(MapRoutes);
};
