//==========================================================================================
//
//	radar_phx.gm
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	Phoenix	20 August 2012	Initial Script
//
//==========================================================================================
//

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

	MainDoorStatus = 0, //intact
	DocumentsStatus = 0,

	Axis_Road_MG_Nest_Built = function( trigger )
	{

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"MOUNTMG42_Axis_Road_MG_Nest",
			"REPAIRMG42_Axis_Road_MG_Nest",
		});

		if ( Map.MainDoorStatus == 1 ) {
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"MOUNTMG42_Axis_Road_MG_Nest",
				"REPAIRMG42_Axis_Road_MG_Nest",
			});
		}

		else if ( Map.DocumentsStatus == 2 ) {
			SetAvailableMapGoals( TEAM.ALLIES, true, {
				"MOUNTMG42_Axis_Road_MG_Nest",
				"REPAIRMG42_Axis_Road_MG_Nest",
			});

			SetAvailableMapGoals( TEAM.AXIS, false, {
				"REPAIRMG42_Axis_Road_MG_Nest",
				"MOUNTMG42_Axis_Road_MG_Nest",
			});
		}

		Util.MapDebugPrint( "Axis_Road_MG_Nest_Built" );
	},

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

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

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

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

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

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

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

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

	Bunker_Door_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"FLAG_documents",
			"CAPPOINT_Documents",
		});

		Util.MapDebugPrint( "Bunker_Door_Destroyed" );
	},

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

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

	Main_Entrance_Destroyed = function( trigger )
	{
		Map.MainDoorStatus = 1;

		Util.EnableGoal("ROUTE_SideDoorFront");

		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_BunkerDoor.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Bunker.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_MainDoor.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_MainDoor.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_rBunkerDoor.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_roadbunker" );
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_roadbunker" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"PLANT_Main_Entrance",
			"BUILD_Bunker_MG_Nest",
			"MOUNTMG42_Bunker_MG_Nest",
			"REPAIRMG42_Bunker_MG_Nest",
			"PLANT_Bunker_MG_Nest",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"PLANT_Bunker_Door",
			"PLANT_Side_Entrance",
		});

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Side_Entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Side_Entrance" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Command_Post" );
		SetGoalPriority( "PLANT_Command_Post_*", 0.9, 0, CLASS.COVERTOPS );
		SetGoalPriority( "BUILD_Command_Post_*", 0.85, TEAM.ALLIES, CLASS.ENGINEER );

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

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

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

	documents_Taken = function( trigger )
	{
		Map.DocumentsStatus = 1;

		Util.MapDebugPrint( "documents_Taken" );
	},

	documents_Returned = function( trigger )
	{
		Map.DocumentsStatus = 0;

		Util.MapDebugPrint( "documents_Returned" );
	},

	documents_Secured = function( trigger )
	{
		Map.DocumentsStatus = 2;

		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_BunkerDoor.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_rBunkerDoor.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"MOVER_truck",
			"BUILD_Truck",
			"ESCORT_Truck",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Truck_Barrier_1",
			"BUILD_Truck_Barrier_2",
		});
		SetGoalPriority( "BUILD_Truck_Barrier_.*", 0.90 );

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"PLANT_Truck_Barrier_1",
			"PLANT_Truck_Barrier_2",
		});

		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_barrier.*",
			"REPAIRMG42_Allied_Spawn_MG",
			"MOUNTMG42_Allied_Spawn_MG",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"MOUNTMG42_Allied_Spawn_MG",
			"REPAIRMG42_Allied_Spawn_MG",
			"REPAIRMG42_CP_Bunker_MG",
			"MOUNTMG42_CP_Bunker_MG",
			"PLANT_Axis_Watchtower_MG_Nest",
			"MOUNTMG42_Axis_Watchtower_MG_Nest",
		});

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOUNTMG42_Axis_Watchtower_MG_Nest",
			"REPAIRMG42_Axis_Watchtower_MG_Nest",
			"REPAIRMG42_CP_Bunker_MG",
			"MOUNTMG42_CP_Bunker_MG",
		});

		Util.MapDebugPrint( "documents_Secured" );
	},

	roadbunker_Axis_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Bunker.*" );

		Util.MapDebugPrint( "roadbunker_Axis_Captured" );
	},

	roadbunker_Allies_Captured = function( trigger )
	{
		if ( Map.MainDoorStatus == 0 ) {
			SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Main_Entrance" );
		}

		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_MainDoor.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Bunker.*" );

		Util.MapDebugPrint( "roadbunker_Allies_Captured" );
	},
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "The Axis Road MG Nest has been constructed.", Map.Axis_Road_MG_Nest_Built );
	OnTrigger( "The Axis Watchtower MG Nest has been constructed.", Map.Axis_Watchtower_MG_Nest_Built );
	OnTrigger( "The Bunker MG Nest has been constructed.", Map.Bunker_MG_Nest_Built );
	OnTrigger( "Command Post constructed", Map.Command_Post_Built );
	OnTrigger( "The Truck has been constructed.", Map.Truck_Built );
	OnTrigger( "Truck Barrier #1 has been constructed.", Map.Truck_Barrier_1_Built );
	OnTrigger( "Truck Barrier #2 has been constructed.", Map.Truck_Barrier_2_Built );
	OnTrigger( "The Axis Road MG Nest has been destroyed.", Map.Axis_Road_MG_Nest_Destroyed );
	OnTrigger( "The Axis Watchtower MG Nest has been destroyed.", Map.Axis_Watchtower_MG_Nest_Destroyed );
	OnTrigger( "Allies breach the Bunker Door!", Map.Bunker_Door_Destroyed );
	OnTrigger( "The Bunker MG Nest has been destroyed.", Map.Bunker_MG_Nest_Destroyed );
	OnTrigger( "Command Post destroyed", Map.Command_Post_Destroyed );
	OnTrigger( "Allies have breached the Main Entrance and secured the Forward Bunker!", Map.Main_Entrance_Destroyed );
	OnTrigger( "Allies have breached the Side Entrance!", Map.Side_Entrance_Destroyed );
	OnTrigger( "Truck Barrier #1 has been destroyed.", Map.Truck_Barrier_1_Destroyed );
	OnTrigger( "Truck Barrier #2 has been destroyed.", Map.Truck_Barrier_2_Destroyed );
	OnTrigger( "Allies have stolen Axis Documents!", Map.documents_Taken );
	OnTrigger( "Axis have returned Axis Documents!", Map.documents_Returned );
	OnTrigger( "Allies have secured the Documents!", Map.documents_Secured );
	OnTrigger( "Axis reclaim the Forward Bunker!", Map.roadbunker_Axis_Captured );
	OnTrigger( "Allies capture the Forward Bunker!", Map.roadbunker_Allies_Captured );

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

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"ATTACK_MainDoor.*",
		"PLANT_Main_Entrance",
		"REPAIRMG42_Bunker_MG_Nest",
		"REPAIRMG42_Axis_Road_MG_Nest",
		"BUILD_Bunker_MG_Nest",
		"PLANT_Axis_Road_MG_Nest",
		"PLANT_Axis_Watchtower_MG_Nest",
		"MOUNTMG42_Axis_Road_MG_Nest",
		"CHECKPOINT_roadbunker",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_Bunker.*",
		"REPAIRMG42_Bunker_MG_Nest",
		"REPAIRMG42_Axis_Road_MG_Nest",
		"BUILD_Bunker_MG_Nest",
		"BUILD_Axis_Road_MG_Nest",
		"MOUNTMG42_Bunker_MG_Nest",
		"MOUNTMG42_Axis_Road_MG_Nest",
		"CHECKPOINT_roadbunker",
		"BUILD_Command_Post",
	});

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

	SetGoalPriority( "PLANT_Command_Post_*", 0.0, 0, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Bunker_MG_Nest_*", 0.0, 0, CLASS.ENGINEER );

	// Allied goals
	SetGoalPriority( "PLANT_Main_Entrance_*", 0.82, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Axis_Road_MG_Nest_*", 0.0, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Axis_Watchtower_MG_Nest_*", 0.0, TEAM.ALLIES, CLASS.ENGINEER );

	// Axis goals
	SetGoalPriority( "BUILD_Bunker_MG_Nest_*", 0.79, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "CHECKPOINT.*", 0.9, TEAM.AXIS ); // always recapture!

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

	Util.DisableGoal("ROUTE_SideDoorFront");


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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 160.0;
	bot.MaxViewDistance = 3000;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		CHECKPOINT_roadbunker =
		{
			ROUTE_AllySpawn1 =
			{
				ROUTE_MainGate =
				{
					ROUTE_Flag1 = { Weight = 2, },
					ROUTE_Road1 =
					{
						ROUTE_RoadHouse =
						{
							ROUTE_Road2 = {},
							ROUTE_Flag3 = {},
						},
						ROUTE_Flag2 = {},
					},
				},
			},
		},
		PLANT_Main_Entrance =
		{
			ROUTE_AllySpawn1 =
			{
				ROUTE_MainGate =
				{
					ROUTE_Road1 =
					{
						ROUTE_RoadHouse =
						{
							ROUTE_MainDoorFront = {},
						},
					},
				},
			},
		},
		PLANT_Side_Entrance =
		{
			ROUTE_FlagSpawn =
			{
				ROUTE_Flag1 =
				{
					ROUTE_SideDoorFront = {},
				},
			},
		},
		PLANT_Bunker_Door =
		{
			ROUTE_FlagSpawn =
			{
				ROUTE_BunkerDoorFront = { Weight = 2, },
				ROUTE_MainCentral = {},
			},
		},
		FLAG_documents =
		{
			ROUTE_FlagSpawn =
			{
				ROUTE_BunkerDoorFront =
				{
					ROUTE_DocumentsArea = {},
				},
			},
		},
		BUILD_Truck =
		{
			ROUTE_FlagSpawn =
			{
				ROUTE_BunkerDoorFront =
				{
					ROUTE_Truck1 = {},
				},
			},
		},
		BUILD_Truck_Barrier_2 =
		{
			ROUTE_AxisSpawn3 =
			{
				ROUTE_Tunnel =
				{
					ROUTE_Defense2 = {},
				},
			},
		},
		BUILD_Truck_Barrier_1 =
		{
			ROUTE_AxisSpawn3 =
			{
				ROUTE_MainGate =
				{
					ROUTE_Road1 =
					{
						ROUTE_RoadHouse = {},
					},
				},
			},
		},
	};

	//copy some routes
	MapRoutes.CHECKPOINT_roadbunker.ROUTE_AllySpawn2 = MapRoutes.CHECKPOINT_roadbunker.ROUTE_AllySpawn1;
	MapRoutes.CHECKPOINT_roadbunker.ROUTE_AllySpawn3 = MapRoutes.CHECKPOINT_roadbunker.ROUTE_AllySpawn1;

	Util.Routes(MapRoutes);
};
