//==========================================================================================
//
//	uje_parking.gm
//
//	Who       	When		What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Niek	31 January 2014	Initial Script
//
//==========================================================================================
//

global Map =
{
	Allied_CP_Dyno = 0,
	Axis_CP_Dyno = 0,
	TankBarrier_1_Dyno = 0,
	TankBarrier_2_Dyno = 0,
	Tank_Barrier_3_Dyno = 0,
	factory_side_door_Dyno = 0,

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

	Allied_CP_Destroyed = function()
	{
		Map.Allied_CP_Dyno = 0;

		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},



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

	Axis_CP_Planted = function()
	{
		Map.Axis_CP_Dyno += 1;
		Util.MapDebugPrint( "Axis_CP_Planted" );
	},

	Axis_CP_Defused = function()
	{
		Map.Axis_CP_Dyno -= 1;
		Util.MapDebugPrint( "Axis_CP_Defused" );
	},

	Axis_CP_Destroyed = function()
	{
		Map.Axis_CP_Dyno = 0;

		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},

	Tank_Built = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "ESCORT_Tank" );
		Util.MapDebugPrint( "Tank_Built" );
	},

	Tank_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "ESCORT_Tank" );
		Util.MapDebugPrint( "Tank_Destroyed" );
	},

	Tank_At_Level_0 = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "MOUNT_Tank_Allies" );
		Util.MapDebugPrint( "Tank_At_Level_0" );
	},

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

	TankBarrier_1_Planted = function()
	{
		Map.TankBarrier_1_Dyno += 1;
	//	Util.MapDebugPrint( "TankBarrier_1_Planted" );
	},

	TankBarrier_1_Defused = function()
	{
		Map.TankBarrier_1_Dyno -= 1;
	//	Util.MapDebugPrint( "TankBarrier_1_Defused" );
	},

	TankBarrier_1_Destroyed = function()
	{
		Map.TankBarrier_1_Dyno = 0;

		Util.MapDebugPrint( "TankBarrier_1_Destroyed" );
	},

	Tank_At_Barrier_1 = function()
	{
		SetGoalPriority( "PLANT_TankBarrier_1", 0.85, TEAM.AXIS, CLASS.ENGINEER );
		ETUtil.SetExcludeIndexes( "BUILD_Tank", { 2, 3 } );
		ETUtil.SetExcludeIndexes( "ESCORT_Tank", { 2, 3 } );
		Util.MapDebugPrint( "Tank_At_Barrier_1" );
	},

	Tank_Past_Barrier_1 = function()
	{

		SetGoalPriority( "BUILD_TankBarrier_2", 0.92, TEAM.ALLIES, CLASS.ENGINEER );

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"BUILD_factory_side_door",
			"PLANT_Axis_CP",
			"BUILD_TankBarrier_1",
			"DEFEND_TB1_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank_Barrier_3" );
		//SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_.*" ); // Points after barrier

		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_TB1_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"PLANT_TankBarrier_2",
			"BUILD_Axis_CP",
		});
		//SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_.*" );;

		ETUtil.SetExcludeIndexes( "BUILD_Tank", {} );
		ETUtil.SetExcludeIndexes( "ESCORT_Tank", {} );
		Util.MapDebugPrint( "Tank_Past_Barrier_1" );
	},

	Tank_At_Level_1 = function()
	{
		// Allies get Spawn 4
		// Axis should get spawn 2 (still spawning at bottom)
		Util.MapDebugPrint( "Tank_At_Level_1" );
	},

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

	TankBarrier_2_Planted = function()
	{
		Map.TankBarrier_2_Dyno += 1;
	//	Util.MapDebugPrint( "TankBarrier_2_Planted" );
	},

	TankBarrier_2_Defused = function()
	{
		Map.TankBarrier_2_Dyno -= 1;
	//	Util.MapDebugPrint( "TankBarrier_2_Defused" );
	},

	TankBarrier_2_Destroyed = function()
	{
		Map.TankBarrier_2_Dyno = 0;

		Util.MapDebugPrint( "TankBarrier_2_Destroyed" );
	},

	Tank_At_Barrier_2 = function()
	{
		SetGoalPriority( "PLANT_TankBarrier_2", 0.85, TEAM.AXIS, CLASS.ENGINEER );
		ETUtil.SetExcludeIndexes( "BUILD_Tank", { 2, 3 } );
		ETUtil.SetExcludeIndexes( "ESCORT_Tank", { 2, 3 } );
		Util.MapDebugPrint( "Tank_At_Barrier_2" );
	},

	Tank_Past_Barrier_2 = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Tank_Barrier_3" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_TankBarrier_2" );
		SetGoalPriority( "BUILD_Tank_Barrier_3", 0.92, TEAM.AXIS, CLASS.ENGINEER );
		ETUtil.SetExcludeIndexes( "BUILD_Tank", {} );
		ETUtil.SetExcludeIndexes( "ESCORT_Tank", {} );
		Util.MapDebugPrint( "Tank_Past_Barrier_2" );
	},

	Tank_At_Level_2 = function()
	{
		// Axis get spawn 3 aka Allies 2
		Util.MapDebugPrint( "Tank_At_Level_2" );
	},

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

	Tank_Barrier_3_Planted = function()
	{
		Map.Tank_Barrier_3_Dyno += 1;
	//	Util.MapDebugPrint( "Tank_Barrier_3_Planted" );
	},

	Tank_Barrier_3_Defused = function()
	{
		Map.Tank_Barrier_3_Dyno -= 1;
	//	Util.MapDebugPrint( "Tank_Barrier_3_Defused" );
	},


	Tank_Barrier_3_Destroyed = function()
	{
		Map.Tank_Barrier_3_Dyno = 0;

		Util.MapDebugPrint( "Tank_Barrier_3_Destroyed" );
	},

	Tank_At_Barrier_3 = function()
	{
		SetGoalPriority( "PLANT_TankBarrier_3", 0.85, TEAM.AXIS, CLASS.ENGINEER );
		ETUtil.SetExcludeIndexes( "BUILD_Tank", { 2, 3 } );
		ETUtil.SetExcludeIndexes( "ESCORT_Tank", { 2, 3 } );
		Util.MapDebugPrint( "Tank_At_Barrier_3" );
	},

	Tank_Past_Barrier_3 = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank_Barrier_3" );
		ETUtil.SetExcludeIndexes( "BUILD_Tank", {} );
		ETUtil.SetExcludeIndexes( "ESCORT_Tank", {} );
		Util.MapDebugPrint( "Tank_Past_Barrier_3" );
	},

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

	factory_side_door_Planted = function()
	{
		Map.factory_side_door_Dyno += 1;
		Util.MapDebugPrint( "factory_side_door_Planted" );
	},

	factory_side_door_Defused = function()
	{
		Map.factory_side_door_Dyno -= 1;
		Util.MapDebugPrint( "factory_side_door_Defused" );
	},

	factory_side_door_Destroyed = function()
	{
		Map.factory_side_door_Dyno = 0;
		Util.MapDebugPrint( "factory_side_door_Destroyed" );
	},

	SidesBlocked =
	{
		TriggerOnEntity = GetGoal("MOVER_tank").GetEntity(),
		OnEnter = function(ent)
		{
			// Stop bots building/escorting the sides where there is no assess
			ETUtil.SetExcludeIndexes( "BUILD_Tank", { 4, 5 } );
			ETUtil.SetExcludeIndexes( "ESCORT_Tank", { 4, 5 } );
			ETUtil.SetExcludeIndexes( "MOUNT_Tank.*", { 4, 5 } );
		//	Util.MapDebugPrint( "Entering blocked sides" );
		},
		OnExit = function(ent)
		{
			ETUtil.SetExcludeIndexes( "BUILD_Tank", {} );
			ETUtil.SetExcludeIndexes( "ESCORT_Tank", {} );
			ETUtil.SetExcludeIndexes( "MOUNT_Tank.*", {} );
		//	Util.MapDebugPrint( "Leaving blocked sides" );
		},
	},

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

global OnMapLoad = function()
{
	// Register callback functions
	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( "The Tank has been repaired", Map.Tank_Built );
	OnTrigger( "^5The tank has been damaged", Map.Tank_Destroyed );
	Level0 = OnTriggerRegion(AABB(-47.771,1239.451,-472.358,283.620,1291.939,-393.901), RegionTrigger.VehicleTrigger );
	OnTrigger( "Baricade 1 has been constructed.", Map.TankBarrier_1_Built );
	OnTrigger( "Planted at TankBarrier #1.", Map.TankBarrier_1_Planted );
	OnTrigger( "Defused at TankBarrier #1.", Map.TankBarrier_1_Defused );
	OnTrigger( "Baricade 1 has been destroyed.", Map.TankBarrier_1_Destroyed );
	Barrier1 = OnTriggerRegion(AABB(25.990,1818.319,-446.875,264.719,1866.136,-372.875), RegionTrigger.VehicleTrigger );
	OnTrigger( "The tank is past the first baricade.", Map.Tank_Past_Barrier_1 );
	OnTrigger( "^7Allies spawn at the top of the Building!", Map.Tank_At_Level_1 );
	OnTrigger( "Baricade 2 has been constructed.", Map.TankBarrier_2_Built );
	OnTrigger( "Planted at TankBarrier #2.", Map.TankBarrier_2_Planted );
	OnTrigger( "Defused at TankBarrier #2.", Map.TankBarrier_2_Defused );
	OnTrigger( "Baricade 2 has been destroyed.", Map.TankBarrier_2_Destroyed );
	Barrier2 = OnTriggerRegion(AABB(-34.078,2411.845,-62.875,202.872,2449.908,11.125), RegionTrigger.VehicleTrigger );
	OnTrigger( "The tank is past the second baricade.", Map.Tank_Past_Barrier_2 );
	OnTrigger( "7Axis spawn at the first floor!", Map.Tank_At_Level_2 );
	OnTrigger( "Baricade 3 has been constructed.", Map.Tank_Barrier_3_Built );
	OnTrigger( "Planted at TankBarrier #3.", Map.Tank_Barrier_3_Planted );
	OnTrigger( "Defused at TankBarrier #3.", Map.Tank_Barrier_3_Defused );
	OnTrigger( "Baricade 3 has been destroyed.", Map.Tank_Barrier_3_Destroyed );
	Barrier3 = OnTriggerRegion(AABB(770.449,1878.171,129.125,813.630,2113.958,203.125), RegionTrigger.VehicleTrigger );
	OnTrigger( "The tank is past the last barrier.", Map.Tank_Past_Barrier_3 );
	OnTrigger( "the side door has been contructed", Map.factory_side_door_Built );
	OnTrigger( "Planted at the factory side door.", Map.factory_side_door_Planted );
	OnTrigger( "Defused at the factory side door.", Map.factory_side_door_Defused );
	OnTrigger( "the side door has been destroyed", Map.factory_side_door_Destroyed );
	OnTrigger( "tank at location", Map.vehicle_at_location );
	//There are some areas where the sides of the tank cannot be reached
	Block1 = OnTriggerRegion(AABB(-1155.388,2815.125,-446.875,-120.900,3010.974,-180.875), Map.SidesBlocked);
	Block2 = OnTriggerRegion(AABB(1343.125,1791.575,-248.816,1568.875,2435.764,11.125), Map.SidesBlocked);
	Block3 = OnTriggerRegion(AABB(276.713,2751.126,-62.875,1153.969,2946.250,203.125), Map.SidesBlocked);

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

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"BUILD_Tank",
		"MOUNT_Tank_Axis",
		"PLANT_TankBarrier_1",
		"PLANT_factory_side_door",
		"ATTACK_TB1_.*",
	});

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"BUILD_TankBarrier_1",
		"BUILD_TankBarrier_2",
		"BUILD_Allied_CP",
		"BUILD_factory_side_door",
		"DEFEND_TB1_.*",
	});


	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"MOUNT_Tank_Axis",
		"ESCORT_Tank",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, "ESCORT_Tank" );

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


	SetGoalPriority( "BUILD_TankBarrier_1", 0.92, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Allied_CP", 	0.89, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_TankBarrier_1", 0.82, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "ESCORT_Tank", 0.78, TEAM.AXIS );

	Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " executed." );
};
