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

global Map =
{
	Main_Entrance_Blown = 0,
	Side_Entrance_Blown = 0,
	East_Defense_Built  = 0,
	West_Defense_Built  = 0,

	Main_Entrance_Planted = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Main_Entrance" );
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},

	Main_Entrance_Defused = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Main_Entrance" );
		Util.MapDebugPrint( "Main_Entrance_Defused" );
	},

	Main_Entrance_Destroyed = function()
	{
		Map.Main_Entrance_Blown = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"PLANT_Side_Entrance",
			"CHECKPOINT_depot_flag",
			"BUILD_Command_Post",
			"PLANT_Axis_Rocket"
		});

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Side_Entrance_Planted = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Side_Entrance" );
		Util.MapDebugPrint( "Side_Entrance_Planted" );
	},

	Side_Entrance_Defused = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Side_Entrance" );
		Util.MapDebugPrint( "Side_Entrance_Defused" );
	},

	Side_Entrance_Destroyed = function()
	{
		Map.Side_Entrance_Intact = 0;
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Side_Entrance" );
		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

	//East Defense Is 2-Stage
	East_Rocket_Defense1_Built = function()
	{
		Util.MapDebugPrint( "East_Rocket_Defense1_Built", true );
	},

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

	East_Rocket_Defense2_Built = function()
	{
		Map.East_Defense_Built = 1;
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_East_Rocket_Defense" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_East_Rocket_Defense" );
		Util.MapDebugPrint( "East_Rocket_Defense2_Built" );
	},

	East_Rocket_Defense2_Planted = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_East_Rocket_Defense" );
		Util.MapDebugPrint( "East_Rocket_Defense2_Planted" );
	},

	East_Rocket_Defense2_Defused = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_East_Rocket_Defense" );
		Util.MapDebugPrint( "East_Rocket_Defense2_Defused" );
	},

	East_Rocket_Defense2_Destroyed = function()
	{
		Map.East_Defense_Built = 0;
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_East_Rocket_Defense" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_East_Rocket_Defense" );
		Util.MapDebugPrint( "East_Rocket_Defense2_Destroyed" );
	},

	West_Rocket_Defense_Built = function()
	{
		Map.West_Defense_Built = 1;
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_West_Rocket_Defense" );
		Util.MapDebugPrint( "West_Rocket_Defense_Built" );
	},

	West_Rocket_Defense_Planted = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_West_Rocket_Defense" );
		Util.MapDebugPrint( "West_Rocket_Defense_Planted" );
	},

	West_Rocket_Defense_Defused = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_West_Rocket_Defense" );
		Util.MapDebugPrint( "West_Rocket_Defense_Defused" );
	},

	West_Rocket_Defense_Destroyed = function()
	{
		Map.West_Defense_Built = 0;
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_West_Rocket_Defense" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_West_Rocket_Defense" );
		Util.MapDebugPrint( "West_Rocket_Defense_Destroyed" );
	},

	Axis_Rocket_Planted = function()
	{
		//SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_Rocket" );
		Util.MapDebugPrint( "Axis_Rocket_Planted", true );
	},

	Axis_Rocket_Defused = function()
	{
		//SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Rocket" );
		Util.MapDebugPrint( "Axis_Rocket_Defused", true );
	},

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

	//MG's - satchels

	Allied_Front_MG_Built = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Allied_Front_MG" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_Front_MG" );
		Util.MapDebugPrint( "Allied_Front_MG_Built" );
	},

	Allied_Front_MG_Destroyed = function()
	{
		if ( !Map.Main_Entrance_Blown )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_Front_MG" );
		}
		Util.MapDebugPrint( "Allied_Front_MG_Destroyed" );
	},

	Forward_Bunker_MG_Built = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Forward_Bunker_MG" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Forward_Bunker_MG" );
		Util.MapDebugPrint( "Forward_Bunker_MG_Built" );
	},

	Forward_Bunker_MG_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Forward_Bunker_MG" );
		Util.MapDebugPrint( "Forward_Bunker_MG_Destroyed" );
	},

	MG_Tower_Built = function()
	{
		//SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_MG_Tower" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_MG_Tower" );
		Util.MapDebugPrint( "MG_Tower_Built" );
	},

	MG_Tower_Destroyed = function()
	{
		//SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_MG_Tower" );
		Util.MapDebugPrint( "MG_Tower_Destroyed", true );
	},

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

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

	// 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;
				Util.EnableGoal( "BUILD_Command_Post" );
				Util.DisableGoal( "PLANT_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS  , true , "PLANT_Command_Post" );
				Util.DisableGoal( "BUILD_Command_Post" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, true , "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS  , false, "PLANT_Command_Post" );
				Util.DisableGoal( "BUILD_Command_Post" );
			}
		}
		//Util.MapDebugPrint( "CP Owner: " + Map.CP_Owner );
	},

	Allied_CP_Built = function()
	{
		Map.Set_CP(TEAM.ALLIES);
		Util.MapDebugPrint( "Allied_CP_Built" );
	},

	Allied_CP_Destroyed = function()
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},

	Axis_CP_Built = function()
	{
		Map.Set_CP(TEAM.AXIS);
		Util.MapDebugPrint( "Axis_CP_Built" );
	},

	Axis_CP_Destroyed = function()
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},

	CP_Planted = function()
	{
		Map.CP_Dyno += 1;
		Util.MapDebugPrint( "CP_Planted" );
	},

	CP_Defused = function()
	{
		Map.CP_Dyno -= 1;
		Util.MapDebugPrint( "CP_Defused" );
	}

// Command Post END

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "The Axis Team has constructed the East Rocket Fortification!", Map.East_Rocket_Defense1_Built );
	OnTrigger( "The Allied Team has destroyed the East Rocket Fortification!", Map.East_Rocket_Defense1_Destroyed );

	OnTrigger( "The Axis Team has constructed the East Rocket Defense!", Map.East_Rocket_Defense2_Built );
	OnTrigger( "Planted at East Rocket Defense.", Map.East_Rocket_Defense2_Built );
	OnTrigger( "Defused at the East Rocket Defense.", Map.East_Rocket_Defense2_Destroyed );
	OnTrigger( "The Allied Team has damaged the East Rocket Defense!", Map.East_Rocket_Defense2_Destroyed );

	OnTrigger( "The Axis Team has constructed the West Rocket Fortification!", Map.West_Rocket_Defense_Built );
	OnTrigger( "Planted at West Rocket Defense.", Map.West_Rocket_Defense_Built );
	OnTrigger( "Defused at the West Rocket Defense.", Map.West_Rocket_Defense_Destroyed );
	OnTrigger( "The Allied Team has destroyed the West Rocket Fortification!", Map.West_Rocket_Defense_Destroyed );

	OnTrigger( "Allied MG Tower Ladder constructed!", Map.MG_Tower_Built );
	OnTrigger( "The Axis have destroyed the MG Tower Ladder!", Map.MG_Tower_Destroyed );

	OnTrigger( "Forward Bunker MG Constructed!", Map.Forward_Bunker_MG_Built );
	OnTrigger( "The Allies have destroyed the Forward Bunker MG", Map.Forward_Bunker_MG_Destroyed );

	OnTrigger( "Allied Front MG Constructed!", Map.Allied_Front_MG_Built );
	OnTrigger( "The Allies have destroyed the Allied Front MG", Map.Allied_Front_MG_Destroyed );

	OnTrigger( "Planted at the Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Defused at the Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "The Main Entrance has been breached!", Map.Main_Entrance_Destroyed );

	OnTrigger( "Planted at the Side Entrance.", Map.Side_Entrance_Planted );
	OnTrigger( "Defused at the Side Entrance.", Map.Side_Entrance_Defused );
	OnTrigger( "The Side Entrance has been breached!", Map.Side_Entrance_Destroyed );

	// End game
	OnTrigger( "Allied team has destroyed the Axis Rocket!", Map.Axis_Rocket_Destroyed );

	OnTrigger( "Axis reclaim the Forward Bunker!", Map.depot_flag_Axis_Captured );
	OnTrigger( "Allies capture the Forward Bunker!", Map.depot_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( ".*" );
	Util.ExcludeClass( "CHECKPOINT_depot_flag", 0, CLASS.ENGINEER  );
	Util.LimitToClass( "PLANT_Command_Post"   , 0, CLASS.COVERTOPS );

	// Allies
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		//"ATTACK_.*",
		"BUILD_Allied_Front_MG",
		"PLANT_Main_Entrance"
	});

	Util.LimitToClass( "PLANT_Forward_Bunker_MG"  , TEAM.ALLIES, CLASS.COVERTOPS );
	Util.ExcludeClass( "PLANT_East_Rocket_Defense", TEAM.ALLIES, CLASS.ENGINEER  );
	Util.ExcludeClass( "PLANT_West_Rocket_Defense", TEAM.ALLIES, CLASS.ENGINEER  );

	// Axis
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_A_.*",
		"BUILD_Forward_Bunker_MG",
		"BUILD_Command_Post",
		"BUILD_West_Rocket_Defense",
		"BUILD_East_Rocket_Defense",
		"CHECKPOINT_depot_flag"
	});

	Util.LimitToClass( "PLANT_MG_Tower"         , TEAM.AXIS, CLASS.COVERTOPS );
	Util.LimitToClass( "PLANT_Allied_Front_MG"  , TEAM.AXIS, CLASS.COVERTOPS );
	Util.LimitToClass( "PLANT_Forward_Bunker_MG", TEAM.AXIS, CLASS.COVERTOPS );

	SetGoalPriority( "BUILD_Command_Post", 0.95 );

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

	Util.AddUsePoint( "PLANT_Main_Entrance", Vec3( 1685, -1560, -175 ) );

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