//==========================================================================================
//
//	nkcomplex_b3.gm
//
//	Who          	When		What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Captain	05 February 2016	Initial Script
//
//==========================================================================================
//

global Map =
{
	MainGateDestroyed = false,
	SideWallDestroyed = false,

	Allies_CP_Built = function()
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allies_CP" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Allies_CP" );
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"HEALTHCAB_healthcabcp",
		"AMMOCAB_ammocabcp",
		"HEALTHCAB_healthcab",
		"AMMOCAB_ammocab",
	});
		Util.MapDebugPrint( "Allies_CP_Built" );
	},

	Axis_CP_Built = function()
	{
	SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Axis_CP" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_CP" );
		Util.MapDebugPrint( "Axis_CP_Built" );
	},

	Killing_Mg42_Built = function()
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Killing_Mg42" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Killing_Mg42" );
		Util.MapDebugPrint( "Killing_Mg42_Built" );
	},

	Side_Wood_Wall_Built = function()
	{
	SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Side_Wood_Wall" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Side_Wood_Wall" );
		Util.MapDebugPrint( "Side_Wood_Wall_Built" );
	},

	Allies_CP_Destroyed = function()
	{
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Allies_CP" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allies_CP" );
		Util.MapDebugPrint( "Allies_CP_Destroyed" );
	},

	Axis_CP_Destroyed = function()
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_CP" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_CP" );
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},

	Garage_Door_Destroyed = function()
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	"FLAG_docs",
	"ROUTE_.*",
	});

	SetAvailableMapGoals( TEAM.ALLIES, false, {
	"ATTACK_Main_Bunker_.*",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
	"BUILD_Axis_CP",
	"BUILD_Side_Wood_Wall",
	"DEFEND_Flag_docs_.*",
	});

	SetAvailableMapGoals( TEAM.AXIS, false, {
	"CHECKPOINT_forwardspawn_flag",
	"DEFEND_Main_Bunker_.*",
	"DEFEND_Garage_.*",
    "MOUNTMG42_653",
	});
	Util.MapDebugPrint( "Garage_Door_Destroyed" );
	},

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

	Main_Gate_Destroyed = function()
	{
	sleep(2);
	Map.MainGateDestroyed = true;

	if ( Map.SideWallDestroyed == false )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, {
	"CHECKPOINT_forwardspawn_flag",
	"BUILD_Allies_CP",
	"BUILD_Killing_Mg42",
	"PLANT_Garage_Door",
	});
	}
	if ( Map.SideWallDestroyed == true )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	"CHECKPOINT_forwardspawn_flag",
	"BUILD_Allies_CP",
	"BUILD_Killing_Mg42",
	"PLANT_Garage_Door",
	"ATTACK_Main_Bunker_.*",
	});
	}
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"ATTACK_Main_Gate_.*",
		"MOUNTMG42_126",
	});

	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Main_Gate_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"MOUNTMG42_653",
		"DEFEND_Main_Bunker_.*",
	});

	Util.MapDebugPrint( "Main_Gate_Destroyed" );
	},

	Side_Wall_Destroyed = function()
	{
	Map.SideWallDestroyed = true;

	if ( Map.MainGateDestroyed == false )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, {
	"CHECKPOINT_forwardspawn_flag",
	"BUILD_Allies_CP",
	"BUILD_Killing_Mg42",
	"PLANT_Garage_Door",
	});
	}
	if ( Map.MainGateDestroyed == true )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	"CHECKPOINT_forwardspawn_flag",
	"BUILD_Allies_CP",
	"BUILD_Killing_Mg42",
	"PLANT_Garage_Door",
	"ATTACK_Main_Bunker_.*",
	});
	}
	SetAvailableMapGoals( TEAM.ALLIES, false, {
	"ATTACK_Side_Wall_.*",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Side_Wall_.*" );

		Util.MapDebugPrint( "Side_Wall_Destroyed" );
	},

	Side_Wood_Wall_Destroyed = function()
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Side_Wood_Wall" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Side_Wood_Wall" );
		Util.MapDebugPrint( "Side_Wood_Wall_Destroyed" );
	},

	docs_Taken = function()
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"CAPPOINT_Flag",
		"ATTACK_Main_Bunker_.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, "FLAG_docs" );


	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_Radio_.*",
		"FLAG_docs",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"DEFEND_Flag_docs_.*",
		"MOUNTMG42_653",
	});
		Util.MapDebugPrint( "docs_Taken" );
	},

	docs_Returned = function()
	{

	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"CAPPOINT_Flag",
		"ATTACK_Main_Bunker_.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_docs" );

	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Radio_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Flag_docs_.*" );
		Util.MapDebugPrint( "docs_Returned" );
	},

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

	forwardspawn_flag_Axis_Captured = function()
	{

	SetAvailableMapGoals( TEAM.AXIS, false, {
	"CHECKPOINT_forwardspawn_flag",
	"DEFEND_Garage_.*",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
	"DEFEND_Main_Bunker_.*",
	});

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

    Util.MapDebugPrint( "forwardspawn_flag_Axis_Captured" );
	},

	forwardspawn_flag_Allies_Captured = function()
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, {
	"CHECKPOINT_forwardspawn_flag",
	});

	SetAvailableMapGoals( TEAM.AXIS, false, {
	"DEFEND_Main_Bunker_.*",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
	"DEFEND_Garage_.*",
	"CHECKPOINT_forwardspawn_flag",
	});
		Util.MapDebugPrint( "forwardspawn_flag_Allies_Captured" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allies Command Post constructed. Charge speed increased!", Map.Allies_CP_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_CP_Built );
	OnTrigger( "Axis team has destroyed the Allies Command Post!", Map.Allies_CP_Destroyed );
	OnTrigger( "Allied team has destroyed the Allies Command Post!", Map.Axis_CP_Destroyed );
	OnTrigger( "Allied team has built the Killing Mg42!", Map.Killing_Mg42_Built );
	OnTrigger( "Axis team has destroyed the Killing Mg42!", Map.Killing_Mg42_Destroyed );
	OnTrigger( "Axis team has built the Side Wood Wall!", Map.Side_Wood_Wall_Built );
	OnTrigger( "Allied team has destroyed the Side Wood Wall!", Map.Side_Wood_Wall_Destroyed );
	OnTrigger( "Allies have breached the Garage Door", Map.Garage_Door_Destroyed );
	OnTrigger( "Allies have breached the Main Gate", Map.Main_Gate_Destroyed );
	OnTrigger( "Allies have breached the Side Entrance!", Map.Side_Wall_Destroyed );
	OnTrigger( "Allies Have taken the Documments!", Map.docs_Taken );
	OnTrigger( "Allies have stolen (null)!", Map.docs_Taken );
	OnTrigger( "Flag returned docs!", Map.docs_Returned );
	OnTrigger( "Allies Have transmitted the Documments!", Map.docs_Secured );
	OnTrigger( "Axis captured the Forward Bunker!", Map.forwardspawn_flag_Axis_Captured );
	OnTrigger( "Allies captured the Forward Bunker!", Map.forwardspawn_flag_Allies_Captured );

	//~Util.DisableGoal( ".*", true ); // all but routes
	//Allies clear all goals
	SetAvailableMapGoals( TEAM.ALLIES, false, ".*" );
	//activation
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"MOUNTMG42_126",
        "PLANT_Side_Wall",
		"PLANT_Main_Gate",
		"HEALTHCAB_healthcabcp_1",
		"AMMOCAB_ammocabcp_1",
		"ATTACK_Side_Wall_.*",
		"ATTACK_Main_Gate_.*",
	});

	//Axis clear all goals
	SetAvailableMapGoals( TEAM.AXIS, false, ".*" );
	//activation
	SetAvailableMapGoals( TEAM.AXIS, true, {
	"DEFEND_Main_Gate_.*",
	"DEFEND_Side_Wall_.*",
	"CHECKPOINT_forwardspawn_flag",
	"HEALTHCAB_healthcabcp",
	"AMMOCAB_ammocabcp",
	"HEALTHCAB_healthcab",
	"AMMOCAB_ammocab",
	});

	// Max users per goal
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "BUILD_.*" );
	Util.SetMaxUsers( 1, "PLANT_.*" );
	Util.SetMaxUsers( 2, "CHECKPOINT_forwardspawn_flag" );
	Util.SetMaxUsers( 6, "FLAG_docs" );


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

    //Priority Main Goals
	SetGoalPriority( "MOUNTMG42_.*", 0.6 );
	SetGoalPriority( "DEFEND_Flag_docs_.*", 0.91 );
	SetGoalPriority( "DEFEND_Radio_.*", 0.91 );
	SetGoalPriority( "PLANT_Allies_CP", 0.6 );
	SetGoalPriority( "PLANT_Axis_CP", 0.6 );
	SetGoalPriority( "BUILD_Allies_CP", 0.81 );
	SetGoalPriority( "BUILD_Axis_CP", 0.91 );
	SetGoalPriority( "BUILD_Side_Wood_Wall", 0.92 );

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 90.0;
	Util.ChangeSpawn( TEAM.ALLIES, 6, 3 );
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
 		FLAG_docs =
		{
			ROUTE_CP_spawn  =
			{
				ROUTE_Right_a  =
				{
					ROUTE_Right_a_1  =
					{
						ROUTE_Right_a_2  =
						{
						},
						ROUTE_Right_a_3  =
						{
						},
					},
					ROUTE_Right_b  =
					{
					    Weight = 2,
						ROUTE_Right_b_1  =
						{
						},
					},
				},
				ROUTE_Left_a  =
				{
					ROUTE_Left_a_1  =
					{
						ROUTE_Left_a_2  =
						{
							ROUTE_Left_a_3  =
							{
							},
						},
					},
				},
			},
			ROUTE_Flag_Spawn  =
			{
				ROUTE_Left_a  =
				{
					ROUTE_Left_a_1  =
					{
						ROUTE_Left_a_2  =
						{
							ROUTE_Left_a_3  =
							{
							},
						},
					},
				},
			},
		},
	};
	Util.Routes(MapRoutes);
};
