//==========================================================================================
//
//	rocketrun_final.gm
//
//	Who                      	When		What
//------------------------------------------------------------------------------------------
//	MickyP	24 January 2013	Initial Script
//
//==========================================================================================
//

global Map =
{
	ShowMovers = false,
	TankAtB1 = 0,
	B1Built = 0,
	TankAtB2 = 0,
	B2Built = 0,


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

		Util.MapDebugPrint( "Allied_Command_Center_Built" );
	},

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

		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

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

		Util.MapDebugPrint( "Tank_Built" );
	},

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

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

		Map.B1Built = 1;
		
		if ( Map.TankAtB1 == 1 )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
			}
		
		Util.MapDebugPrint( "Tank_Barrier_1_Built" );
	},

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

		Map.B1Built = 0;
		
		if ( Map.TankAtB1 == 1 )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank" );
			}
			
		Util.MapDebugPrint( "TankBarrier_1_Destroyed" );
	},

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

		Map.TankAtB1 = 1;
		
		if ( Map.B1Built == 1 )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
			}
			
		Util.MapDebugPrint( "Tank_At_Barrier_1" );
	},

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

		Map.TankAtB1 = 0;
		
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_TankBarrier_1" );
		
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_TankBarrier_1" );
		
		Util.MapDebugPrint( "Tank_Past_Barrier_1" );

	},

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

		Map.B2Built = 1;
		
		if ( Map.TankAtB2 == 1 )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
			}
			
		Util.MapDebugPrint( "Tank_Barrier_2_Built" );
	},

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

		Map.B2Built = 0;
		
		if ( Map.TankAtB2 == 1 )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank" );
			}

		Util.MapDebugPrint( "TankBarrier_2_Destroyed" );
	},

	Tank_At_Barrier_2 = function( trigger )
	{
		if ( TestMap )
			{ return; }
		
		Map.TankAtB2 = 1;		
		
		if ( Map.B2Built == 1 )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
			}
			
		Util.MapDebugPrint( "Tank_At_Barrier_2" );
	},

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

		Map.TankAtB2 = 0;
		

		Util.MapDebugPrint( "Tank_Past_Barrier_2" );
	},

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

		Map.Allied_Command_Center_Dyno = 0;

		Util.MapDebugPrint( "Allied_Command_Center_Destroyed" );
	},

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

		Map.Axis_Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

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

		Map.Axis_Rockets_Dyno = 0;

		Util.MapDebugPrint( "Axis_Rockets_Destroyed" );
	},

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

		Map.Tank_Barrier_Dyno = 0;

		Util.MapDebugPrint( "Tank_Barrier_1_Destroyed" );
	},

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

		Map.Tank_Barrier_1_Dyno = 0;

		Util.MapDebugPrint( "Tank_Barrier_2_Destroyed" );
	},

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

		Map.rocket_fence_Dyno = 0;

		Util.MapDebugPrint( "rocket_fence_Destroyed" );
	},

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

		Util.MapDebugPrint( "oldcityflag_Axis_Captured" );
	},

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

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

		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "MOVER_tank" );
		Util.MapDebugPrint( "Gate_Destroyed" );
	},
	
	vehicle_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				Map.Tank_At_Barrier_1();
			}
			case 2:
			{
				Map.Tank_At_Barrier_2();
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},

};

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

	// Register callback functions
	OnTrigger( "The Allies have built the field command post!", Map.Allied_Command_Center_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Repaired );
	OnTrigger( "Tank Barrier #1 has been constructed.", Map.Tank_Barrier_1_Built );
	OnTrigger( "Tank Barrier #1 has been destroyed.", Map.Tank_Barrier_1_Destroyed );
	OnTrigger( "the tank has passed the first barrier", Map.Tank_Past_Barrier_1 );
	OnTrigger( "Tank Barrier #2 has been constructed.", Map.Tank_Barrier_2_Built );
	OnTrigger( "Tank Barrier #2 has been destroyed.", Map.Tank_Barrier_2_Destroyed );
	OnTrigger( "the tank has passed the second barrier", Map.Tank_Past_Barrier_2 );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Center_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "The tank has destroyed the entrance gate", Map.Gate_Destroyed );
	OnTrigger( "^1The Allies have destroyed a part of the Rocket protection Fence!", Map.rocket_fence_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Axis_Rockets_Destroyed );
	OnTrigger( "MISSING_STRING", Map.oldcityflag_Axis_Captured );
	OnTrigger( "MISSING_STRING", Map.oldcityflag_Allies_Captured );
	OnTrigger( "tank at location", Map.vehicle_at_location );

	AtB1	= OnTriggerRegion(AABB(4750.768,1149.065,17.125,4858.837,1487.440,136.451),	RegionTrigger.VehicleTrigger);
	AtB2	= OnTriggerRegion(AABB(5405.992,2667.494,17.125,5675.933,2721.985,91.125),	RegionTrigger.VehicleTrigger);

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

	// 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_.*" );
	
	SetGoalPriority( "PLANT_TankBarrier_1", 0.82, TEAM.ALLIES );
	SetGoalPriority( "BUILD_TankBarrier_1", 0.91, TEAM.AXIS );
	SetGoalPriority( "BUILD_Allied_Command_Center", 0.79, TEAM.ALLIES );
	SetGoalPriority( "PLANT_Allied_Command_Post", 0.80, TEAM.AXIS, CLASS.ENGINEER, true );
	SetGoalPriority( "BUILD_Axis_Command_Post", 0.80, TEAM.AXIS );
	SetGoalPriority( "PLANT_Axis_Command_Center", 0.80, TEAM.ALLIES, CLASS.ENGINEER, true );

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


	SetAvailableMapGoals( TEAM.ALLIES, false, "MOUNTMG42_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "MOUNTMG42_.*" );
	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;
};

