//==========================================================================================
//
//	uboot.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	02 February 2018	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 1, // please set to zero before distributing your script

	Dock_Door_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Dock_Door" );
		Util.MapDebugPrint( "Dock_Door_Planted" );
	},
	Dock_Door_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Dock_Door" );
		Util.MapDebugPrint( "Dock_Door_Defused" );
	},
	Dock_Door_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Dock_Door" );
		Util.MapDebugPrint( "Dock_Door_Destroyed" );
	},

	Shipping_Gate_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Shipping_Gate" );
		Util.MapDebugPrint( "Shipping_Gate_Planted" );
	},
	Shipping_Gate_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Shipping_Gate" );
		Util.MapDebugPrint( "Shipping_Gate_Defused" );
	},
	Shipping_Gate_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Shipping_Gate" );
		Util.MapDebugPrint( "Shipping_Gate_Destroyed" );
	},

	U_Boot_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CHECKPOINT_forwardspawn1_flag" );
		Util.MapDebugPrint( "U_Boot_Planted" );
	},
	U_Boot_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CHECKPOINT_forwardspawn1_flag" );
		Util.MapDebugPrint( "U_Boot_Defused" );
	},
	U_Boot_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "U_Boot_Destroyed" );
	},

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

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

	// Neutral Command Post
	CP_Owner = 0,
	CP_Dyno = 0,

	Set_CP = function(_p) // p = TEAM.ALLIES or TEAM.AXIS or 0 (unbuilt)
	{
		switch(_p)
		{
			case 0:
			{
				Map.CP_Owner = 0;
				SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Command_Post" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Command_Post" );
			}
		}
		//Util.MapDebugPrint("CP Owner: " + Map.CP_Owner );
	},
	Allied_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.ALLIES);
		Util.MapDebugPrint( "Allied_CP_Built" );
	},
	Allied_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},
	Axis_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.AXIS);
		Util.MapDebugPrint( "Axis_CP_Built" );
	},
	Axis_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},
	CP_Planted = function( trigger )
	{
		Map.CP_Dyno += 1;
		Util.MapDebugPrint( "CP_Planted" );
	},
	CP_Defused = function( trigger )
	{
		Map.CP_Dyno -= 1;
		Util.MapDebugPrint( "CP_Defused" );
	},

// Command Post END

};

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

	OnTrigger( "Allies have destroyed the Dock Door!", Map.Dock_Door_Destroyed );
	OnTrigger( "Allies have destroyed the Dock Door!", Map.Dock_Door_Destroyed );
	OnTrigger( "Allies have destroyed the Dock Door!", Map.Dock_Door_Destroyed );

	OnTrigger( "Planted at the Shipping Gate.", Map.Shipping_Gate_Planted );
	OnTrigger( "Defused at the Shipping Gate.", Map.Shipping_Gate_Defused );
	OnTrigger( "Allies have destroyed the Shipping Gate!", Map.Shipping_Gate_Destroyed );

	OnTrigger( "Allies have destroyed the U-Boot!", Map.U_Boot_Destroyed );

	//"Axis capture the Tower Spawn!"
	//"Allies capture the Tower Spawn!"

	OnTrigger( "Axis captures the Shipping Area!", Map.forwardspawn1_flag_Axis_Captured );
	OnTrigger( "Allies captures the Shipping Area!", Map.forwardspawn1_flag_Allies_Captured );

	OnTrigger( "Allied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!",          Map.Allied_CP_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!",    Map.Axis_CP_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!",          Map.Axis_CP_Destroyed );
	OnTrigger( "Planted at the Command Post.",                              Map.CP_Planted  );
	OnTrigger( "Defused at the Command Post.",                              Map.CP_Defused  );

	//---------------------------------------------------------------------------

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

	//misc
	SetAvailableMapGoals( 0, 0, ".*CAB.*" );
	Util.LimitToClass( "PLANT_Command_Post", 0, 5 );
	ETUtil.SetCabinets();
	Util.AddUsePoint( "PLANT_Dock_Door", Vec3( 1134, 87, -763 ) );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"ATTACK_.*",
		"BUILD_Command_Post",
		"PLANT_Shipping_Gate",
		"PLANT_Dock_Door",
		"CHECKPOINT_forwardspawn1_flag",
	});

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"DEFEND_.*",
		"BUILD_Command_Post",

	});

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

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

	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 =
	{
		PLANT_Shipping_Gate =
		{
		},
		PLANT_Dock_Door =
		{
		},
		PLANT_U_Boot =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		CHECKPOINT_forwardspawn1_flag =
		{
		},
	};
	Util.Routes(MapRoutes);
};
