//==========================================================================================
//
//	nemo.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	palota	09 January 2011	Initial Script
// palota	02 October 2011	roles, routes, flag priority
//==========================================================================================
//

global Map =
{
	Debug = 0,
	flagCenter = 0,
	flagHarbor = 0,
	flagArchives = 0,
	windowBoxDestroyed = false,

	Roles =
	{
		ALLIES =
		{
			AllBots = true,
			ATTACKER1 =
			{
				numbots = 3,
				spawnpt = 4, //archives
			},
			ATTACKER2 =
			{
				numbots = 2,
				spawnpt = 3, //harbor
			},
			ATTACKER3 =
			{
				numbots = 1,
				spawnpt = 5, //town center
			},
		},
		AXIS =
		{
			AllBots = true,
			ATTACKER1 =
			{
				numbots = 3,
				spawnpt = 4, //archives
			},
			ATTACKER2 =
			{
				numbots = 2,
				spawnpt = 3, //harbor
			},
			ATTACKER3 =
			{
				numbots = 1,
				spawnpt = 5, //town center
			},
		},
	},

	//set higher priority for flags if one team has captured all flags
	checkFlags = function(i)
	{
		if (Map.flagCenter == Map.flagHarbor && Map.flagHarbor == Map.flagArchives)
		{
			SetGoalPriority( "CHECKPOINT_.*", 0.91);
		}
		else
		{
			SetGoalPriority( "CHECKPOINT_.*", 0.71);
		}
	},

	flagHarbor_Axis_Captured = function( trigger )
	{
		Map.flagHarbor = 1;
		Map.checkFlags();
		//mg42 cannot be repaired !
		Util.LimitToTeam(TEAM.AXIS, "MOUNTMG42_mg42_bank");
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Harbor_Barricade");
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_Harbor_Barricade");
		Util.MapDebugPrint("flagHarbor_Axis_Captured" );
	},

	flagHarbor_Allies_Captured = function( trigger )
	{
		Map.flagHarbor = 2;
		Map.checkFlags();
		Util.LimitToTeam(TEAM.ALLIES, "MOUNTMG42_mg42_bank");
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_Harbor_Barricade");
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Axis_Harbor_Barricade");
		Util.MapDebugPrint( "flagHarbor_Allies_Captured" );
	},

	flagArchives_Axis_Captured = function( trigger )
	{
		Map.flagArchives = 1;
		Map.checkFlags();
		Util.LimitToTeam(TEAM.AXIS, "MOUNTMG42_archive");
		Util.MapDebugPrint( "flagArchives_Axis_Captured" );
	},

	flagArchives_Allies_Captured = function( trigger )
	{
		Map.flagArchives = 2;
		Map.checkFlags();
		Util.LimitToTeam(TEAM.ALLIES, "MOUNTMG42_archive");
		Util.MapDebugPrint( "flagArchives_Allies_Captured" );
	},

	flagCenter_Axis_Captured = function( trigger )
	{
		Map.flagCenter = 1;
		Map.checkFlags();
		Util.LimitToTeam(TEAM.AXIS, "MOUNTMG42_center");
		Util.MapDebugPrint( "flagCenter_Axis_Captured" );
	},

	flagCenter_Allies_Captured = function( trigger )
	{
		Map.flagCenter = 2;
		Map.checkFlags();
		Util.LimitToTeam(TEAM.ALLIES, "MOUNTMG42_center");
		Util.MapDebugPrint( "flagCenter_Allies_Captured" );
	},


	window_Grates_Built = function( trigger )
	{
		Util.DisableGoal( "ROUTE_window" );
		Util.DisableGoal( "ROUTE_window2" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DYNAMITE_window");
		Util.MapDebugPrint( "window_Grates_Built" );
	},

	window_Grates_Destroyed = function( trigger )
	{
		Util.EnableGoal( "ROUTE_window" );
		if(!Map.windowBoxDestroyed){
			Util.EnableGoal( "ROUTE_window2" );
		}
		SetAvailableMapGoals( TEAM.ALLIES, false, "DYNAMITE_window");
		Util.MapDebugPrint( "window_Grates_Destroyed" );
	},

	Gates_Destroyed = function( trigger )
	{
		Util.EnableGoal( "ROUTE_gates" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Arhive_Barricade" );
		Util.MapDebugPrint( "Gates_Destroyed" );
	},

	sewer_Entrance_Destroyed = function( trigger )
	{
		Util.EnableGoal( "ROUTE_sewer" );
		Util.MapDebugPrint( "sewer_Entrance_Destroyed" );
	},

	window_Box_Destroyed = function( trigger )
	{
		Map.windowBoxDestroyed = true;
		Util.DisableGoal( "ROUTE_window2" );
		SetGoalPriority( "BUILD_Window_Grate", 0.8, TEAM.AXIS);
		Util.MapDebugPrint( "window_Box_Destroyed" );
	},

	harbor_Barricade_Built = function( trigger )
	{
		Util.DisableGoal( "ROUTE_center4" );
		Util.DisableGoal( "ROUTE_center5" );
		Util.MapDebugPrint( "harbor_Barricade_Built" );
	},

	harbor_Barricade_Destroyed = function( trigger )
	{
		Util.EnableGoal( "ROUTE_center4" );
		Util.EnableGoal( "ROUTE_center5" );
		Util.MapDebugPrint( "harbor_Barricade_Destroyed" );
	},

	axis_Harbor_Barricade_Built = function( trigger )
	{
		Util.DisableGoal( "ROUTE_harbor1" );
		Util.MapDebugPrint( "axis_Harbor_Barricade_Built" );
	},

	axis_Harbor_Barricade_Destroyed = function( trigger )
	{
		Util.EnableGoal( "ROUTE_harbor1" );
		Util.MapDebugPrint( "axis_Harbor_Barricade_Destroyed" );
	},
};

global OnMapLoad = function()
{
	OnTrigger( "The Axis have taken control of the Harbor!", Map.flagHarbor_Axis_Captured );
	OnTrigger( "The Allies have taken control of the Harbor!", Map.flagHarbor_Allies_Captured );
	OnTrigger( "The Axis have taken control of the Archives!", Map.flagArchives_Axis_Captured );
	OnTrigger( "The Allies have taken control of the Archives!", Map.flagArchives_Allies_Captured );
	OnTrigger( "The Axis have taken control of the Town Center!", Map.flagCenter_Axis_Captured );
	OnTrigger( "The Allies have taken control of the Town Center!", Map.flagCenter_Allies_Captured );
	OnTrigger( "The Axis have destroyed the Gates!", Map.Gates_Destroyed );
	OnTrigger( "The Allies have destroyed the Gates!", Map.Gates_Destroyed );
	OnTrigger( "The Axis have built the Window Grates!", Map.window_Grates_Built );
	OnTrigger( "The Allies have destroyed the Window Grates!", Map.window_Grates_Destroyed );
	OnTrigger( "The Allies have built the Harbor Barricade!", Map.harbor_Barricade_Built );
	OnTrigger( "Axis have destroyed the Harbor Barricade!", Map.harbor_Barricade_Destroyed );
	OnTrigger( "The Axis have built the Harbor Barricade!", Map.axis_Harbor_Barricade_Built );
	OnTrigger( "The Allies have destroyed the Harbor Barricade!", Map.axis_Harbor_Barricade_Destroyed );
	OnTrigger( "GRENADE_sewer Exploded.", Map.sewer_Entrance_Destroyed );
	OnTrigger( "GRENADE_window_box Exploded.", Map.window_Box_Destroyed );

	OnTriggerRegion(AABB(8386.991,2727.125,237.125,8732.349,2918.031,404.386),RegionTrigger.DisableCombatMovement); //harbor flag
	OnTriggerRegion(AABB(2739.608,6008.123,186.125,3267.286,6542.666,465.806),RegionTrigger.DisableCombatMovement); //town center flag
	OnTriggerRegion(AABB(450.279,7334.977,140.858,1529.705,8015.840,328.821),RegionTrigger.BreakableDistance); //axis spawn
	OnTriggerRegion(AABB(6569.125,6369.212,70.377,6755.283,6920.895,290.348),RegionTrigger.BreakableDistance); //sewer grate
	OnTriggerRegion(AABB(5952.713,8263.102,179.125,6635.557,8452.875,314.994),RegionTrigger.BreakableDistance); //archives fence
	RegionTrigger.BreakableDistance.MinBreakableDist = 0;
	RegionTrigger.BreakableDistance.MaxBreakableDist = 500;

	Util.DisableGoal(".*MG42_.*");
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"BUILD_Arhive_Barricade",
		"ROUTE_gates",
	});
	Util.LimitToTeam(TEAM.AXIS, "DEFEND_x.*");
	Util.LimitToTeam(TEAM.ALLIES, "DEFEND_l.*");
	Util.DisableGoal("GRENADE_.*");
	Util.DisableGoal("ROUTE_sewer");
	Util.DisableGoal("ROUTE_window");
	Util.DisableGoal("ROUTE_window2");

	SetGoalPriority( "PLANT_Allied_Construction", 0.85, TEAM.AXIS, CLASS.ENGINEER);
	SetGoalPriority( "PLANT_Command_Post", 0.82, TEAM.AXIS, CLASS.COVERTOPS);
	SetGoalPriority( "BUILD_Window_Grate", 0.85, TEAM.AXIS);
	SetGoalPriority( "BUILD_Axis_Checkpoint", 0.85, TEAM.AXIS);
	SetGoalPriority( "PLANT_Sewer_Entreance", 0.85, TEAM.AXIS);

	SetGoalPriority( "BUILD_Arhive_Barricade", 0.85, TEAM.ALLIES);
	SetGoalPriority( "PLANT_Gates", 0.85, TEAM.ALLIES);
	SetGoalPriority( "BUILD_Allied_Construction", 0.8, TEAM.ALLIES);
	SetGoalPriority( "PLANT_Axis_Harbor_Barricade", 0.8, TEAM.ALLIES);

	SetGoalPriority( "MOUNTMG42.*", 0.75);
	SetGoalPriority( "PLANT_Sewer_Entreance", 0.0, 0, CLASS.ENGINEER); //can't arm dynamite underwater
	SetGoalPriority( "PLANT_Window_Grate", 0.0, TEAM.ALLIES, CLASS.ENGINEER); //can't plant near friendly objective

	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=20, MaxCampTime=90} );

	foreach (goal in { "MOUNTMG42_.*", "BUILD_.*", "PLANT_Axis_Harbor_Barricade", "PLANT_Command_Post"}){
		Util.SetMaxUsers(1, goal);
	}

	Util.AddUsePoint("PLANT_Allied_Construction", { Vector3(4737.519, 6009.280, 208.125), Vector3(4714.791, 5707.746, 208.125) }); //cannot be planted from the other side
	Util.AddUsePoint("PLANT_Gates", Vector3(4421.792, 7835.160, 202.125));
	Util.AddUsePoint("PLANT_Axis_Harbor_Barricade", { Vector3(4653.154, 2419.584, 208.125), Vector3(4779.764, 2435.665, 208.125) });
	Util.AddUsePoint("PLANT_Window_Grate", { Vector3(4971.931, 6260.125, 228.125), Vector3(4915.875, 6154.875, 208.125) });
	Util.AddUsePoint("PLANT_Sewer_Entreance", Vector3(6685.592, 6499.386, 196.125));
	Util.SetGoalPosition(6666.898, 6405.055, 200, "PLANT_Sewer_Entreance");

	MapRoutes =
	{
		CHECKPOINT_flag3 = { //harbor
			ROUTE_axis_spawn = {
				ROUTE_center4 = {},
				ROUTE_center5 = {},
				ROUTE_harbor3 = { Weight = 2,
					ROUTE_harbor4 = {},
					ROUTE_harbor5 = {},
				},
				ROUTE_window = {},
			},
			ROUTE_allied_spawn = {
				ROUTE_allied4 = { ROUTE_harbor1 = {}},
				ROUTE_harbor2 = {},
				ROUTE_harbor3 = {},
				ROUTE_harbor4 = {},
			},
			ROUTE_archives = {
				ROUTE_sewer = {},
				ROUTE_window = { ROUTE_harbor5 = {}},
			},
		},
		CHECKPOINT_flag4 = { //archives
			ROUTE_allied_spawn = {
				ROUTE_gates = {},
				ROUTE_window2 = {},
				ROUTE_sewer = {},
			},
		},
		CHECKPOINT_flag5 = { //town center
			ROUTE_axis_spawn = {
				ROUTE_axis1 = {},
				ROUTE_axis2 = {},
				ROUTE_axis3 = {},
				ROUTE_axis4 = {},
			},
			ROUTE_allied_spawn = {
				ROUTE_allied1 = {},
				ROUTE_allied2 = { ROUTE_axis2 = {}},
				ROUTE_allied5 = {},
				ROUTE_allied6 = { ROUTE_center2 = {}},
				ROUTE_center3 = {},
			},
			ROUTE_boat = {
				ROUTE_center3 = {},
				ROUTE_center4 = {},
				ROUTE_center5 = {},
				ROUTE_harbor3 = {},
			},
			ROUTE_archives = {
				ROUTE_gates = {
					ROUTE_axis3 = {},
					ROUTE_center6 = {},
				},
				ROUTE_window = {
					ROUTE_center3 = {},
					ROUTE_center4 = {},
					ROUTE_center5 = {},
				},
			},
		},
	};
	MapRoutes.PLANT_Gates = MapRoutes.CHECKPOINT_flag5;
	MapRoutes.PLANT_Axis_Checkpoint = MapRoutes.PLANT_Gates;
	MapRoutes.BUILD_Arhive_Barricade = MapRoutes.CHECKPOINT_flag4;
	Util.Routes(MapRoutes);

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