//==========================================================================================
//
//	quickie.gm
//
//	Who	When			What
//------------------------------------------------------------------------------------------
//	MickyP	09 October 2011		Initial Script
//	Scabs	6 November 2011		Script/Waypoint Update
//
//==========================================================================================
//

global Map =
{

	Command_Post_Dyno = 0,
	Front_Gate_Dyno = 0,

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

	Command_Post_Planted = function( trigger )
	{
		Map.Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Command_Post_Planted" );
	},

	Front_Gate_Planted = function( trigger )
	{
		Map.Front_Gate_Dyno += 1;
		Util.MapDebugPrint( "Front_Gate_Planted" );
	},

	Command_Post_Defused = function( trigger )
	{
		Map.Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Command_Post_Defused" );
	},

	Front_Gate_Defused = function( trigger )
	{
		Map.Front_Gate_Dyno -= 1;
		Util.MapDebugPrint( "Front_Gate_Defused" );
	},

	Command_Post_Destroyed = function( trigger )
	{
		Map.Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

	Front_Gate_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_Gate.*",
			"SNIPE_Hill.*",
			"PLANT_Front_Gate",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"DEFEND_Flag.*",
			"CHECKPOINT_castletop_flag",
			"BUILD_Command_Post",
			"PLANT_Command_Post",
		});

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_Gate.*",
			"SNIPE_Gate.*",
			"BUILD_Command_Post",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_Flag.*",
			"DEFEND_Castle.*",
		});

		Map.Front_Gate_Dyno = 0;

		Util.MapDebugPrint( "Front_Gate_Destroyed" );
	},

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

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

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

	if ( vel.y > 0 )
		{
		SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_Door" );
		Util.MapDebugPrint( "door closed" );
		}
         else if ( vel.y < 0 )
		{
		SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_Door" );
		Util.MapDebugPrint( "door open" );
		}
	},
};

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

	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Planted at the Command Post.", Map.Command_Post_Planted );
	OnTrigger( "Planted at the Front Gate.", Map.Front_Gate_Planted );
	OnTrigger( "Defused at the Command Post.", Map.Command_Post_Defused );
	OnTrigger( "Defused at the Front Gate.", Map.Front_Gate_Defused );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "the Front Gate Destroyed.", Map.Front_Gate_Destroyed );
	OnTrigger( "Allies Have Taken Control of the Castle Flag", Map.castletop_flag_Axis_Captured );
	OnTrigger( "Axis Have Control of the Castle Flag", Map.castletop_flag_Allies_Captured );
	OnTrigger( "allied_spawn_door_goto", Map.Allies_Door_Moving );

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

	Util.SetGoalPosition( 823, 1241, 732, "PLANT_Front_Gate" );

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"CHECKPOINT_castletop_flag",
		"DEFEND_Gate.*",
		"SNIPE_Gate.*",
		"BUILD_Command_Post",
	});

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"ATTACK_Gate.*",
		"SWITCH_Door",
		"SNIPE_Hill.*",
		"PLANT_Front_Gate",
	});

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

	SetGoalPriority( "DEFEND_Flag.*", 0.51, 0, 0 );

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

	MapRoutes =
	{
		PLANT_Front_Gate =
		{
			ROUTE_Allied_Spawn  =
			{
				ROUTE_House_Front  =
				{
				},
				ROUTE_House_Back  =
				{
				},
			},

		},
		CHECKPOINT_castletop_flag =
		{
			ROUTE_Hut  =
			{
				ROUTE_Ladder_Top  =
				{
				},
				ROUTE_Stairs_Top  =
				{
				},
			},
		},

	};
	MapRoutes.ATTACK_Gate_1 = MapRoutes.PLANT_Front_Gate;
	MapRoutes.ATTACK_Gate_2 = MapRoutes.PLANT_Front_Gate;
	MapRoutes.ATTACK_Gate_3 = MapRoutes.PLANT_Front_Gate;
	MapRoutes.ATTACK_Gate_4 = MapRoutes.PLANT_Front_Gate;
	MapRoutes.ATTACK_Gate_5 = MapRoutes.PLANT_Front_Gate;
	MapRoutes.ATTACK_Gate_5 = MapRoutes.PLANT_Front_Gate;
	MapRoutes.SNIPE_Hill_1 = MapRoutes.PLANT_Front_Gate;
	MapRoutes.DEFEND_Flag_1 = MapRoutes.CHECKPOINT_castletop_flag;
	MapRoutes.DEFEND_Flag_2 = MapRoutes.CHECKPOINT_castletop_flag;

	Util.Routes(MapRoutes);

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