//==========================================================================================
//
//	uje_castle_xmas.gm
//
//	Who       	                  When		                    What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Niek	         04 December 2016	           Initial Script
//	^1[UJE]^3Captain	     06 December 2016	           ATTACK/DEFENSE 
//
//==========================================================================================
//

global Map =
{
    Gate = false,
	Crown = false,


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

	Broken_Mirror_Built = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Mirror.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Crown.*" );
	
	SetAvailableMapGoals( TEAM.AXIS, true, {"PLANT_Main_entrance", "PLANT_Side_Entrance", "FLAG_Crown"} );
	SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Gate.*" );
	
	
		Util.MapDebugPrint( "Broken_Mirror_Built" );
	},

	Allied_Command_Post_Built = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, {"PLANT_Command_Post", "BUILD_Command_Post"} );
	
	SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Command_Post" );
	
		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},
	
	Allied_Command_Post_Destroyed = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Command_Post" );
	
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Command_Post" );
	
		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},
	
	Axis_Command_Post_Built = function( trigger )
	{
	SetAvailableMapGoals( TEAM.AXIS, false, {"PLANT_Command_Post", "BUILD_Command_Post"} );
	
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );
	
		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},
	
	Axis_Command_Post_Destroyed = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Command_Post" );
	
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Command_Post" );
	
		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},
	
	Gate_Built = function( trigger )
	{
	Map.Gate = true;
	if ( Map.Crown == true )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Gate" );
	SetAvailableMapGoals( TEAM.AXIS, false, "CAPPOINT_crown" );
	}
	
	if ( Map.Crown == false )
	{
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Gate" );
	}
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Gate" );
		
		Util.MapDebugPrint( "Gate_Built" );
	},

	Gate_Destroyed = function( trigger )
	{
	Map.Gate = false;
	if ( Map.Crown == true )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "CAPPOINT_crown" );
	}
	
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Gate" );
	
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Gate" );
	
		Util.MapDebugPrint( "Gate_Destroyed" );
	},

	Crown_Taken = function( trigger )
	{
	
	Map.Crown = true;
	
	if ( Map.Gate == true )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Gate" );
	SetAvailableMapGoals( TEAM.AXIS, false, "CAPPOINT_crown" );
	}
	
	if ( Map.Gate == false )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "CAPPOINT_crown" );
	}
	sleep( 2 );
	SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Gate.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Crown.*" );
	
		Util.MapDebugPrint( "Crown_Taken" );
	},

	Crown_Returned = function( trigger )
	{
	
	Map.Crown = false;
	sleep( 2 );
	SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Crown.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Gate.*" );

	SetAvailableMapGoals( TEAM.AXIS, true, "FLAG_Crown" );
	SetAvailableMapGoals( TEAM.AXIS, false, "CAPPOINT_crown" );

	
		Util.MapDebugPrint( "Crown_Returned" );
	},

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

	roadbunker_Axis_Captured = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_roadbunker" );
	
	SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_roadbunker" );
	
		Util.MapDebugPrint( "roadbunker_Axis_Captured" );
	},

	roadbunker_Allies_Captured = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_roadbunker" );
	
	SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_roadbunker" );
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Broken_Mirror" );
	
		Util.MapDebugPrint( "roadbunker_Allies_Captured" );
	},
	
	allies_capture_roadbunker = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Mirror.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_roadbunker" );
	
		Util.MapDebugPrint( "allies_capture_roadbunker" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "The Broken Mirror have been fixed. Defend the Crown!", Map.Broken_Mirror_Built );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "The Gate has been constructed.", Map.Gate_Built );
	OnTrigger( "The Gate has been destroyed!", Map.Gate_Destroyed );
	OnTrigger( "Axis have stolen The Crown!", Map.Crown_Taken );
	OnTrigger( "Allies have returned The Crown!", Map.Crown_Returned );
	OnTrigger( "The Axis team have escaped with the Crown!", Map.Crown_Secured );
	OnTrigger( "Allies capture the Old Town!", Map.roadbunker_Axis_Captured );
	OnTrigger( "Axis capture the Old Town!", Map.roadbunker_Allies_Captured );
	OnTrigger( "allies_capture_roadbunker", Map.allies_capture_roadbunker );

	Util.DisableGoal( ".*", true ); // all but routes
	
	//Allies goals activation
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	 ".*CAB.*",
	 ".*CAB.*",
	 "DEFEND_mirror.*",
	 "CHECKPOINT.*",
	 "BUILD_Gate",
	 "BUILD_Command_Post",
	});
	
	//Axis goals activation
	SetAvailableMapGoals( TEAM.AXIS, true, {
	 ".*CAB.*",
	 ".*CAB.*",
     "ATTACK_First.*",
	 "CHECKPOINT.*",
	 "BUILD_Command_Post",
	});
	
	//SetMaxUsersInProgress
	Util.SetMaxUsersInProgress( 1, "DEFEND.*" );
	Util.SetMaxUsersInProgress( 1, "ATTACK.*" );
	Util.SetMaxUsersInProgress( 1, "PLANT.*" );
	Util.SetMaxUsersInProgress( 1, "BUILD.*" );
	Util.SetMaxUsersInProgress( 1, "CHECKPOINT.*" );
	Util.SetMaxUsersInProgress( 2, "FLAG_.*" );
	Util.SetMaxUsersInProgress( 1, "CAPPOINT_.*" );

	// Camp times
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=20, MaxCampTime=45} );
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=20, MaxCampTime=45} );


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

global OnBotJoin = function( bot )
{
	// Uncomment for shootable breakables
	bot.TargetBreakableDist = 90.0;
	// Only set MaxViewDistance on maps with limited sight (e.g. fog)
	//~bot.MaxViewDistance = 2400;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_Gate =
		{
		},
		PLANT_Gate =
		{
		},
		FLAG_Crown =
		{
		},
		BUILD_Broken_Mirror =
		{
		},
		PLANT_Broken_Mirror =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		CHECKPOINT_roadbunker =
		{
		},
	};
	Util.Routes(MapRoutes);
};
