//==========================================================================================
//
//	uje_the_lab.gm
//
//	Who       	When		What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Niek	30 January 2013	Initial Script
//	MickyP		31 January 2013	Sorted so bots can complete - Lots to do still
//
//==========================================================================================
//

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

	Train_Depot_Captured = 0,
	DoorStatus = 0,

	Allied_CP_Built = function( trigger )
	{
		Util.MapDebugPrint( "Allied_CP_Built" );
	},

	Allied_Mine_Ramp_Built = function( trigger )
	{
		Util.MapDebugPrint( "Allied_Mine_Ramp_Built" );
	},

	Axis_CP_Built = function( trigger )
	{
		Util.MapDebugPrint( "Axis_CP_Built" );
	},

	Replacement_Part_1_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Replacement_Part_1" );
		Util.MapDebugPrint( "Replacement_Part_1_Built" );
	},

	Replacement_Part_2_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Replacement_Part_2" );
		Util.MapDebugPrint( "Replacement_Part_2_Built" );
	},

	Allied_CP_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},

	Allied_Mine_Ramp_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Allied_Mine_Ramp_Destroyed" );
	},

	Axis_CP_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},

	Axis_Rocket_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Axis_Rocket_Destroyed" );
	},

	Depotwall_Destroyed= function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Allied_CP",
			"FLAG_Replacement_Part.*",
			"CAPPOINT_Part.*",
		});
		Util.MapDebugPrint( "Depotwall_Destroyed" );
	},

	Replacement_Part_Taken = function( trigger )
	{
/*
		// Testing only
		print(trigger.Entity);
		print(GetGameIdFromEntity(trigger.Entity));

		if ( GetGameIdFromEntity(trigger.Entity) == xxx )
		{
			Util.MapDebugPrint( "Rocket_Part_Taken" );
		}
		else
		{
			Util.MapDebugPrint( "Tank_Part_Taken" );
		}
*/
		Util.MapDebugPrint( "Replacement_Part_Taken" );
	},

	Replacement_Part_Returned = function( trigger )
	{
		Util.MapDebugPrint( "Replacement_Part_Returned" );
	},

	Replacement_Part_1_Secured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Part_1" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Replacement_Part_1" );
		Util.MapDebugPrint( "Replacement_Part_1_Secured" );
	},

	Replacement_Part_2_Secured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Part_2" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Replacement_Part_2" );
		Util.MapDebugPrint( "Replacement_Part_2_Secured" );
	},

	Train_Depot_Captured  = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "RIDE_Train" );

		if ( Map.DoorStatus == 0 )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "SWITCH_gate1" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_gate1" );
		}
		else if( Map.DoorStatus == 1 )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "SWITCH_gate1" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_gate1" );
		}

		Map.Train_Depot_Captured = 1;
		Util.MapDebugPrint( "Train_Depot_Captured" );
	},

	Switch_Used = function( trigger )
	{
		vel = ToVector(trigger.Action);

		if ( vel.y > 0 )
		{
			Map.DoorStatus = 0;
			Util.MapDebugPrint( "Switch_closed" );
			if ( Train_Depot_Captured == 0 )
				{ return; }

			SetAvailableMapGoals( TEAM.AXIS, false, "SWITCH_gate1" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_gate1" );

			Util.MapDebugPrint( "door closed" );
		}
		else if ( vel.y < 0 )
		{
			Map.DoorStatus = 1;
			if ( Train_Depot_Captured == 0 )
				{ return; }

			SetAvailableMapGoals( TEAM.AXIS, true, "SWITCH_gate1" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_gate1" );

			Util.MapDebugPrint( "door open" );
		}

		if ( Train_Depot_Captured == 0 )
			{ return; }

		Util.MapDebugPrint( "Switch_Used" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "^1Axis ^7Command Post constructed. Charge speed increased!", Map.Allied_CP_Built );
	OnTrigger( "Allied Team have built the Mine-Ramp!!", Map.Allied_Mine_Ramp_Built );
	OnTrigger( "^1Axis ^7Command Post constructed. Charge speed increased!", Map.Axis_CP_Built );
	OnTrigger( "Replacement Part 1 has been fixed!!", Map.Replacement_Part_1_Built );
	OnTrigger( "Replacement Part 2 has been fixed!!", Map.Replacement_Part_2_Built );
	OnTrigger( "^1Axis ^7team has destroyed the ^4Allied ^7Command Post!", Map.Allied_CP_Destroyed );
	OnTrigger( "Axis have destroyed the Mine-Ramp!!", Map.Allied_Mine_Ramp_Destroyed );
	OnTrigger( "^4Allied ^7team has destroyed the ^1Axis^7 Command Post!", Map.Axis_CP_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Axis_Rocket_Destroyed );
	OnTrigger( "The Allies breached the Depotwall!", Map.Depotwall_Destroyed );
	OnTrigger( "Allies have stolen The Replacement Part!", Map.Replacement_Part_Taken );
	OnTrigger( "MISSING_STRING", Map.Replacement_Part_Returned );
	OnTrigger( "Allies captured erst1_holder", Map.Replacement_Part_1_Secured );
	OnTrigger( "Allies captured erst2_holder", Map.Replacement_Part_2_Secured );
	OnTrigger( "Allies captured the Depot!", Map.Train_Depot_Captured );
	OnTrigger( "gate_button_start", Map.Switch_Used );

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

	// Max users per goal
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "CAPPOINT_.*" );
	Util.SetMaxUsers( 1, "FLAG_.*" );
	Util.SetMaxUsers( 1, "SWITCH_gate1" );
	Util.SetMaxUsers( 1, "RIDE_Train" );

	// 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 )
{
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_Replacement_Part_1 =
		{
		},
		BUILD_Allied_CP =
		{
		},
		BUILD_Replacement_Part_2 =
		{
		},
		BUILD_Allied_Mine_Ramp =
		{
		},
		BUILD_Axis_CP =
		{
		},
		PLANT_Axis_Rocket =
		{
		},
		PLANT_Replacement_Part_1 =
		{
		},
		PLANT_Allied_Mine_Ramp =
		{
		},
		PLANT_Axis_CP =
		{
		},
		PLANT_Allied_CP =
		{
		},
		PLANT_Replacement_Part_2 =
		{
		},
		FLAG_Replacement_Part_1 =
		{
		},
		FLAG_Replacement_Part =
		{
		},
	};
	Util.Routes(MapRoutes);
};
