//==========================================================================================
//
//	holy_grail.gm
//
//	Who			When				What
//------------------------------------------------------------------------------------------
//	Mateos		27 November 2023	Initial Script
//
//==========================================================================================
//

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

	SecondAreaAvailable = false,

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

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

	EastWall_Destroyed = function( trigger )
	{
		Map.Second_Area_Available( trigger );

		Util.MapDebugPrint( "EastWall_Destroyed" );
	},

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

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

	WestWall_Destroyed = function( trigger )
	{
		Map.Second_Area_Available( trigger );

		Util.MapDebugPrint( "WestWall_Destroyed" );
	},

	gold_Taken = function( trigger )
	{
		Util.EnableGoal( ".*MG42_Truck" );

		Util.MapDebugPrint( "gold_Taken" );
	},

	gold_Returned = function( trigger )
	{
		Util.DisableGoal( ".*MG42_Truck" );

		Util.MapDebugPrint( "gold_Returned" );
	},

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

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

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

	Second_Area_Available = function( trigger )
	{
		if ( Map.SecondAreaAvailable ) { return; }

		Map.SecondAreaAvailable = true;

		sleep( 0.1 );
		Wp.CheckBlockable();

		Util.EnableGoal( ".*_Neutral_Command_Post" );

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CAPPOINT_Truck",
			"FLAG_gold"
		});
	}
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "Allies have breached the east wall!", Map.EastWall_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "Allies have breached the west wall!", Map.WestWall_Destroyed );
	OnTrigger( "Allies have stolen the Grail!!!!", Map.gold_Taken );
	OnTrigger( "The Grail has been returned!!!!", Map.gold_Returned );
	OnTrigger( "Allied team escaped with the Holy Grail!", Map.gold_Secured );
	OnTrigger( "Axis reclaim the Forward Spawn!", Map.forwardspawn1_flag_Axis_Captured );
	OnTrigger( "Allies capture the Forward Spawn!", Map.forwardspawn1_flag_Allies_Captured );

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

	Util.EnableGoal( "CHECKPOINT_forwardspawn1_flag" );

	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_.*Wall" );

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

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

	SetGoalPriority( "CHECKPOINT_forwardspawn1_flag", 0.8 ); // Like FLAG_gold

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

global OnBotJoin = function( bot )
{
	bot.MaxViewDistance = 3175;
};
