//==========================================================================================
//
//	2dom1.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	MickyP	21 September 2012	Initial Script
//	MickyP	28 September 2012	Bot Roles/GoalPriority
//	palota	29 October 2012	bots can mount MG42, fixed routes, changed roles, DisableCombatMovement
//
//==========================================================================================
//

global Map =
{

	Roles =
	{
		AXIS = // Team
		{
			AllBots = true, // each bot is considered for a role
			ATTACKER = //A
			{
				numbots = 9,
			},
			ATTACKER1 = //B
			{
				numbots = 7,
			},
		},

		ALLIES =
		{
			AllBots = true, // each bot is considered for a role
			ATTACKER2 = //A
			{
				numbots = 7,
			},
			ATTACKER3 = //B
			{
				numbots = 9,
			},
		},
	},

	Allies_Control_A = function( trigger )
	{
		Util.SetRoleForGoals("ATTACK_Control_Point_B", ROLE.ATTACKER2 );
		Util.ClearRoleForGoals("ATTACK_Control_Point_B", ROLE.ATTACKER );

		Util.MapDebugPrint( "Allies_Control_A" );
	},

	Allies_Control_B = function( trigger )
	{
		Util.SetRoleForGoals("ATTACK_Control_Point_A", ROLE.ATTACKER3 );
		Util.ClearRoleForGoals("ATTACK_Control_Point_A", ROLE.ATTACKER1 );

		Util.MapDebugPrint( "Allies_Control_B" );
	},

	Axis_Control_A = function( trigger )
	{
		Util.SetRoleForGoals("ATTACK_Control_Point_B", ROLE.ATTACKER );
		Util.ClearRoleForGoals("ATTACK_Control_Point_B", ROLE.ATTACKER2 );

		Util.MapDebugPrint( "Axis_Control_A" );
	},

	Axis_Control_B = function( trigger )
	{
		Util.SetRoleForGoals("ATTACK_Control_Point_A", ROLE.ATTACKER1 );
		Util.ClearRoleForGoals("ATTACK_Control_Point_A", ROLE.ATTACKER3 );

		Util.MapDebugPrint( "Axis_Control_B" );
	},

	ClearAttacker = function()
	{
		Util.ClearRoleForGoals("ATTACK_Control_Point_B", ROLE.ATTACKER );
		Util.ClearRoleForGoals("ATTACK_Control_Point_A", ROLE.ATTACKER1 );
		Util.ClearRoleForGoals("ATTACK_Control_Point_B", ROLE.ATTACKER2 );
		Util.ClearRoleForGoals("ATTACK_Control_Point_A", ROLE.ATTACKER3 );
	},

	TeamScores = function( trigger )
	{
		vel = ToVector(trigger.Action);

		if ( vel.y > 0 )
		{
			//does nothing - just stops the same trigger running twice
		}
		else if ( vel.z < 0 )
		{
			Map.ClearAttacker();
			Util.MapDebugPrint( "TeamScores" );
		}
	},

	Allied_Ramp_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "ROUTE_Allied_Ramp" );

		Util.MapDebugPrint( "Allied_Ramp_Built" );
	},

	Allied_Ramp_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "ROUTE_Allied_Ramp" );

		Util.MapDebugPrint( "Allied_Ramp_Destroyed" );
	},

	Axis_Ramp_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "ROUTE_Axis_Ramp" );

		Util.MapDebugPrint( "Axis_Ramp_Built" );
	},

	Axis_Ramp_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "ROUTE_Axis_Ramp" );

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

global OnMapLoad = function()
{
	// Register callback functions

	OnTrigger( "Allies control point ^dA^7.", Map.Allies_Control_A );
	OnTrigger( "Allies control point ^dB^7.", Map.Allies_Control_B );
	OnTrigger( "Axis controls point ^1A^7.", Map.Axis_Control_A );
	OnTrigger( "Axis controls point ^1B^7.", Map.Axis_Control_B );
	OnTrigger( "redProjCull_goto", Map.TeamScores );
	OnTrigger( "blueProjCull_goto", Map.TeamScores );
	OnTrigger( "The Allied Ramp has been ^2constructed^7.", Map.Allied_Ramp_Built );
	OnTrigger( "The Allied Ramp has been ^1destroyed^7.", Map.Allied_Ramp_Destroyed );
	OnTrigger( "The Axis Ramp has been ^2constructed^7.", Map.Axis_Ramp_Built );
	OnTrigger( "The Axis Ramp has been ^1destroyed^7.", Map.Axis_Ramp_Destroyed );
	//OnTrigger( "The Allied MG has been ^2constructed^7.", Map.Allied_Machinegun_Built );
	//OnTrigger( "The Axis MG has been ^2constructed^7.", Map.Axis_Machinegun_Built );
	//OnTrigger( "The Allied MG has been ^1destroyed^7.", Map.Allied_Machinegun_Destroyed );
	//OnTrigger( "The Axis MG has been ^1destroyed^7.", Map.Axis_Machinegun_Destroyed );
	//OnTrigger( "^dAllied Command Post constructed. Charge speed increased!^7", Map.Command_Post_Built );
	//OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	//OnTrigger( "^1Axis Command Post constructed. Charge speed increased!^7", Map.Command_Post_Built );
	//OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Command_Post_Destroyed );

	OnTriggerRegion(AABB(-536.688,-563.136,193.125,585.463,577.533,676.142),RegionTrigger.DisableCombatMovement);

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

	SetAvailableMapGoals( TEAM.AXIS, false, "ROUTE_Axis_Ramp" );
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"ATTACK_Control_Point_.*",
		"AMMOCAB_t8",
		"HEALTHCAB_t10",
		"BUILD_Axis_Machinegun",
		"BUILD_Axis_Ramp",
		"BUILD_Command_Post",
		"MOUNTMG42_Axis_Machinegun",
		"REPAIRMG42_Axis_Machinegun",
		"PLANT_Allied_Ramp",
		"PLANT_Command_Post",
	});

	SetAvailableMapGoals( TEAM.ALLIES, false, "ROUTE_Allied_Ramp" );
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"ATTACK_Control_Point_.*",
		"AMMOCAB_alliedammo",
		"HEALTHCAB_alliedheal",
		"BUILD_Allied_Machinegun",
		"BUILD_Allied_Ramp",
		"BUILD_Command_Post",
		"MOUNTMG42_Allied_Machinegun",
		"REPAIRMG42_Allied_Machinegun",
		"PLANT_Axis_Ramp",
		"PLANT_Command_Post",
	});

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

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

	SetGoalPriority( "MOUNTMG42_.*", 0.51 );
	SetGoalPriority( "REPAIRMG42_.*", 0.89 );

	Util.SetGoalPosition( -385, -34, 120, "PLANT_Allied_Ramp" );
	Util.SetGoalPosition( 385, 34, 120, "PLANT_Axis_Ramp" );

	Map.ClearAttacker();


	MapRoutes =
	{
		ATTACK_Control_Point_B =
		{
			ROUTE_Allies_Spawn  =
			{
				ROUTE_Allied_Ramp  =
				{
					Weight=3,
				},
				ROUTE_CP_East  =
				{
				},
				ROUTE_CP_West  =
				{
				},
			},
		},
		ATTACK_Control_Point_A =
		{
			ROUTE_Axis_Spawn =
			{
				ROUTE_Axis_Ramp  =
				{
					Weight=3,
				},
				ROUTE_CP_East  =
				{
				},
				ROUTE_CP_West  =
				{
				},
			}
		},
	};

	Util.Routes(MapRoutes);


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