//==========================================================================================
//
//	sabotage_te.gm
//
//	Who       	When		What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Niek	24 December 2013	Initial Script
//
//  maker@bigsighstudios.com - 6 April 2018 - Full workup
//
//==========================================================================================
//

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

	Main_Entrance_Dyno = 0,
	Neutral_Command_Post_Dyno = 0,
	Radar_1_Dyno = 0,
	Radar_2_Dyno = 0,

	Main_Entrance_Planted = function( trigger )
	{
		Map.Main_Entrance_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Main_Entrance" );

		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},
	Main_Entrance_Defused = function( trigger )
	{
		Map.Main_Entrance_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Main_Entrance" );

		Util.MapDebugPrint( "Main_Entrance_Defused" );
	},
	Main_Entrance_Destroyed = function( trigger )
	{
		Map.Main_Entrance_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Main_Entrance" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CHECKPOINT_forwardspawn1_flag" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Service_Door" );

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Service_Door_Planted = function( trigger )
	{
		Map.Service_Door_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Service_Door" );

		Util.MapDebugPrint( "Service_Door_Planted" );
	},
	Service_Door_Defused = function( trigger )
	{
		Map.Service_Door -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Service_Door" );

		Util.MapDebugPrint( "Service_Door_Defused" );
	},
	Service_Door_Destroyed = function( trigger )
	{
		Map.Service_Door_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CHECKPOINT_forwardspawn1_flag" );
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Service_Door" );

		Util.MapDebugPrint( "Service_Door_Destroyed" );
	},

	Radar_1_Planted = function( trigger )
	{
		Map.Radar_1_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Radar_1" );

		Util.MapDebugPrint( "Radar_1_Planted" );
	},
	Radar_1_Defused = function( trigger )
	{
		Map.Radar_1_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Radar_1" );

		Util.MapDebugPrint( "Radar_1_Defused" );
	},
	Radar_1_Destroyed = function( trigger )
	{
		Map.Radar_1_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Radar_1" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Radar_2" );

		Util.MapDebugPrint( "Radar_1_Destroyed" );
	},

	Radar_2_Planted = function( trigger )
	{
		Map.Radar_2_Dyno += 1;

		Util.MapDebugPrint( "Radar_2_Planted" );
	},
	Radar_2_Defused = function( trigger )
	{
		Map.Radar_2_Dyno -= 1;

		Util.MapDebugPrint( "Radar_2_Defused" );
	},
	Radar_2_Destroyed = function( trigger )
	{
		Map.Radar_2_Dyno = 0;

		Util.MapDebugPrint( "Radar_2_Destroyed" );
	},

	forwardspawn1_flag_Axis_Captured = function( trigger )
	{

		Util.MapDebugPrint( "forwardspawn1_flag_Axis_Captured" );
	},

	forwardspawn1_flag_Allies_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Neutral_Command_Post" );

		Util.MapDebugPrint( "forwardspawn1_flag_Allies_Captured" );
	},

	// Neutral Command Post
	CP_Owner = 0,
	CP_Dyno = 0,

	Set_CP = function(_p) // p = TEAM.ALLIES or TEAM.AXIS or 0 (unbuilt)
	{
		switch(_p)
		{
			case 0:
			{
				Map.CP_Owner = 0;
				SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Neutral_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Neutral_Command_Post" );

				SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Radar_1" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Neutral_Command_Post" );
			}
		}
		//Util.MapDebugPrint("CP Owner: " + Map.CP_Owner );
	},
	Allied_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.ALLIES);
		Util.MapDebugPrint( "Allied_CP_Built" );
	},
	Allied_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},
	Axis_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.AXIS);
		Util.MapDebugPrint( "Axis_CP_Built" );
	},
	Axis_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},
	CP_Planted = function( trigger )
	{
		Map.CP_Dyno += 1;
		Util.MapDebugPrint( "CP_Planted" );
	},
	CP_Defused = function( trigger )
	{
		Map.CP_Dyno -= 1;
		Util.MapDebugPrint( "CP_Defused" );
	},

// Command Post END

};

global OnMapLoad = function()
{
	// Register callback functions

	OnTrigger( "Planted at the Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Defused at the Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "Allies have destroyed the Main Entrance", Map.Main_Entrance_Destroyed );

	OnTrigger( "Planted at the Service Door.", Map.Service_Door_Planted );
	OnTrigger( "Defused at the Service Door.", Map.Service_Door_Defused );
	OnTrigger( "Allies have destroyed the Service Door", Map.Service_Door_Destroyed );

	OnTrigger( "Axis reclaim the Forward Spawn!", Map.forwardspawn1_flag_Axis_Captured );
	OnTrigger( "Allies capture the Forward Spawn!", Map.forwardspawn1_flag_Allies_Captured );

	OnTrigger( "Planted at Radar 1.", Map.Radar_1_Planted );
	OnTrigger( "Defused at Radar 1.", Map.Radar_1_Defused );
	OnTrigger( "Allies have destroyed Radar 1", Map.Radar_1_Destroyed );

	OnTrigger( "Planted at Radar 2.", Map.Radar_2_Planted );
	OnTrigger( "Defused at Radar 2.", Map.Radar_2_Defused );
	OnTrigger( "Allies have destroyed Radar 2", Map.Radar_2_Destroyed );

	OnTrigger( "Allied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!",          Map.Allied_CP_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!",    Map.Axis_CP_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!",          Map.Axis_CP_Destroyed );
	OnTrigger( "Planted at the Command Post.",                              Map.CP_Planted  );
	OnTrigger( "Defused at the Command Post.",                              Map.CP_Defused  );

	Util.DisableGoal( ".*", true ); // all but routes

	Util.AddUsePoint( "PLANT_Main_Entrance", Vec3(1492,-1818,-67) );
	Util.AddUsePoint( "PLANT_Service_Door", Vec3(2121,2834,320) );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"ATTACK_.*",
		"PLANT_Main_Entrance",
		"CHECKPOINT_forwardspawn1_flag",
	});

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"DEFEND_.*",
		"BUILD_Neutral_Command_Post",
		"CHECKPOINT_forwardspawn1_flag",
	});

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

	Util.LimitToClass( "PLANT_Neutral_Command_Post", 0, 5 );

	//SetGoalPriority( "CHECKPOINT_forwardspawn1_flag", 1.0 );

	// 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 =
	{
		PLANT_Main_Entrance =
		{
		},
		PLANT_Service_Door =
		{
		},
		PLANT_Radar_2 =
		{
		},
		PLANT_Radar_1 =
		{
		},
		BUILD_Neutral_Command_Post =
		{
		},
		PLANT_Neutral_Command_Post =
		{
		},
		CHECKPOINT_forwardspawn1_flag =
		{
		},
	};
	Util.Routes(MapRoutes);
};

