//==========================================================================================
//
//	UJE_convoy_final.gm
//
//	Who		When			What
//------------------------------------------------------------------------------------------
//	MickyP		14 April 2011		Initial Script
//	MickyP		1 November 2011		Final Version Update
//
//==========================================================================================
//
// To Do
//
// Routing
// Defence Mount goals
//
global Map =
{
	ShowMovers = false,

	MapStart = 1,
	TankAtB1 = 0,
	B1Built = 0,
	TankAtB2 = 0,
	B2Built = 0,
	TankAtB3 = 0,
	B3Built = 0,

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

		Util.MapDebugPrint( "Allied_CP_Built" );
	},

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

		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},

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

		Util.MapDebugPrint( "Axis_CP_Built" );
	},

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

		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},

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

		Util.MapDebugPrint( "Tank_Built" );
	},

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

		if ( Map.MapStart == 1 )
			{
				Map.MapStart = 0;
				return;
			}
			
		Util.MapDebugPrint( "Tank_Destroyed" );
	},

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

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

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

		Map.B1Built = 0;
		
		if ( Map.TankAtB1 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, 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.AXIS, false, "BUILD_Tank" );
			}
			
		Util.MapDebugPrint( "Tank_At_Barrier_1" );
	},

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

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

	},

/*	House_spawn_activated = function( trigger )
	{
		if ( TestMap )
			{ return; }

	
		Util.MapDebugPrint( "House_spawn_activated" );

	},
*/
	TankBarrier_2_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

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

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

		Map.B2Built = 0;
		
		if ( Map.TankAtB2 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, 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.AXIS, false, "BUILD_Tank" );
			}
			
		Util.MapDebugPrint( "Tank_At_Barrier_2" );
	},

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

		Map.TankAtB2 = 0;
		
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Bar.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Yard.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_TankBarrier_2" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Tank_Barrier_3" );
		
		
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_TankBarrier_2" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank_Barrier_3" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Bar.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_CP" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Yard.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Arch.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_factory_side_door" );

		Util.MapDebugPrint( "Tank_Past_Barrier_2" );
	},

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

		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Square.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Bar.*" );
		
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Square.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Bar.*" );

		Util.MapDebugPrint( "Forward_spawn_activated" );

	},

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

		Map.B3Built = 1;
		
		if ( Map.TankAtB3 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Tank" );
			}
		
		Util.MapDebugPrint( "Tank_Barrier_3_Built" );
	},

	Tank_Barrier_3_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }
			
		Map.B3Built = 0;
		
		if ( Map.TankAtB3 == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Tank" );
			}
			
		Util.MapDebugPrint( "Tank_Barrier_3_Destroyed" );
	},

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

		Map.TankAtB3 = 1;		
		
		if ( Map.B3Built == 1 )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Tank" );
			}

		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Yard.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_End.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_factory_side_door" );
		
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Yard.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_End.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_factory_side_door" );
		
		Util.MapDebugPrint( "Tank_At_Barrier_3" );
	},

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

		Map.TankAtB3 = 0;
		
		Util.MapDebugPrint( "Tank_Past_Barrier_3" );

	},
	
	Side_Door_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.EnableGoal( "ROUTE_Side_Door" );
		Util.MapDebugPrint( "Side_Door_Destroyed" );
	},

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

		Util.DisableGoal( "ROUTE_Side_Door" );
		Util.MapDebugPrint( "Side_Door_Built" );
	},

	vehicle_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				Map.Tank_At_Barrier_1();
			}
			case 2:
			{
				Map.Tank_At_Barrier_2();
			}
			case 3:
			{
				Map.Tank_At_Barrier_3();
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},

};

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

	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_CP_Built );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", 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( "^5The tank has been damaged", Map.Tank_Destroyed );
	OnTrigger( "The Tank has been repaired", Map.Tank_Built );
	OnTrigger( "Baricade 1 has been constructed.", Map.TankBarrier_1_Built );
	OnTrigger( "Baricade 1 has been destroyed.", Map.TankBarrier_1_Destroyed );
	OnTrigger( "The tank is past the first baricade.", Map.Tank_Past_Barrier_1 );
//	OnTrigger( "Forward spawns activated", Map.House_spawn_activated );
	OnTrigger( "Baricade 2 has been constructed.", Map.TankBarrier_2_Built );
	OnTrigger( "Baricade 2 has been destroyed.", Map.TankBarrier_2_Destroyed );
	OnTrigger( "The tank is past the second baricade.", Map.Tank_Past_Barrier_2 );
	OnTrigger( "^2Allies spawn back to the Factory!", Map.Forward_spawn_activated );
	OnTrigger( "Baricade 3 has been constructed.", Map.Tank_Barrier_3_Built );
	OnTrigger( "Baricade 3 has been destroyed.", Map.Tank_Barrier_3_Destroyed );
	OnTrigger( "The tank is past the last barrier.", Map.Tank_Past_Barrier_3 );
	OnTrigger( "the side door has been destroyed", Map.Side_Door_Destroyed );
	OnTrigger( "the side door has been contructed", Map.Side_Door_Built );
	OnTrigger( "tank at location", Map.vehicle_at_location );

	AtB1	= OnTriggerRegion(AABB(704.498,-53.113,-210.875,913.125,16.611,-101.875),	RegionTrigger.VehicleTrigger);
	AtB2	= OnTriggerRegion(AABB(1854.185,423.866,-132.009,2060.078,496.671,-32.510),	RegionTrigger.VehicleTrigger);
	AtB3	= OnTriggerRegion(AABB(-672.875,2268.633,105.213,-617.805,2612.659,179.926),	RegionTrigger.VehicleTrigger);


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



	Util.EnableGoal( "AMMOCAB.*" );
	Util.EnableGoal( "HEALTHCAB.*" );
	
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_TankBarrier_1" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_TankBarrier_2" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_CP" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_CP" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Square.*" );
				
	

	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Tank" );
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_TankBarrier_1" );
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_TankBarrier_2" );
	SetAvailableMapGoals( TEAM.AXIS, true, "MOUNT_Tank" );
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_CP" );
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_CP" );
	SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Square.*" );
	
	SetGoalPriority( "PLANT_TankBarrier_1", 0.82, TEAM.AXIS );
	SetGoalPriority( "BUILD_TankBarrier_1", 0.91, TEAM.ALLIES );
	SetGoalPriority( "BUILD_factory_side_door", 0.80, TEAM.ALLIES );
	SetGoalPriority( "BUILD_Allied_CP", 0.79, TEAM.ALLIES );
	SetGoalPriority( "PLANT_Allied_CP", 0.80, TEAM.AXIS, CLASS.ENGINEER, true );
	SetGoalPriority( "BUILD_Axis_CP", 0.80, TEAM.AXIS );
	SetGoalPriority( "PLANT_Axis_CP", 0.80, TEAM.ALLIES, CLASS.ENGINEER, true );

	// 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_.*" );
	Util.SetMaxUsers( 1, "BUILD_Allied_CP" );
	Util.SetMaxUsers( 1, "PLANT_Allied_CP" );
	Util.SetMaxUsers( 1, "BUILD_Axis_CP" );
	Util.SetMaxUsers( 1, "PLANT_Axis_CP" );

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


	MapRoutes =
	{
		BUILD_TankBarrier_1 = 
		{
			ROUTE_Axis_1st_Spawn  = 
			{
				ROUTE_Hotel_Front  = 
				{
				},
				ROUTE_Hotel_Back_Path  = 
				{
				},
			},
		},
	};

	MapRoutes.BUILD_TankBarrier_2 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_2 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_3 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_4 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_5 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_6 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_7 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_8 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_9 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_10 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_11 = MapRoutes.BUILD_TankBarrier_1;
	MapRoutes.ATTACK_Square_12 = MapRoutes.BUILD_TankBarrier_1;
	
	Util.Routes(MapRoutes);

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