//==========================================================================================
//
//	obersalzberg.gm
//
//	Who                   	When		What
//------------------------------------------------------------------------------------------
//	^8=^KF^8|^KA^8=^KBuckwild	02 September 2015	Initial Script
//
//  maker@bigsighstudios.com 28 Feb 2018 - script, waypoints
//==========================================================================================
//

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

	Stage = 1, //stage 2 after first wall blown
	Side_Door_Built = 0,

	Allied_Command_Post_Dyno = 0,
	Axis_Command_Post_Dyno = 0,
	Axis_Construction_Dyno = 0,
	Tank_Barrier_Dyno = 0,

	Axis_Construction_Built = function( trigger )
	{
		Map.Side_Door_Built = 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Axis_Construction" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_Construction" );

		Util.MapDebugPrint( "Axis_Construction_Built" );
	},
	Axis_Construction_Planted = function( trigger )
	{
		Map.Axis_Construction_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_Construction" );

		Util.MapDebugPrint( "Axis_Construction_Planted" );
	},
	Axis_Construction_Defused = function( trigger )
	{
		Map.Axis_Construction_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_Construction" );

		Util.MapDebugPrint( "Axis_Construction_Defused" );
	},
	Axis_Construction_Destroyed = function( trigger )
	{
		Map.Side_Door_Built = 0;
		Map.Axis_Construction_Dyno = 0;
		if ( Map.Stage == 2 )
		{
			SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Axis_Construction" );
		}

		Util.MapDebugPrint( "Axis_Construction_Destroyed" );
	},

	Tank_Built = function( trigger )
	{

		Util.MapDebugPrint( "Tank_Built" );
	},
	Tank_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Tank" );

		Util.MapDebugPrint( "Tank_Destroyed" );
	},

	Tank_Barrier_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Tank_Barrier" );

		Util.MapDebugPrint( "Tank_Barrier_Built" );
	},
	Tank_Barrier_Planted = function( trigger )
	{
		Map.Tank_Barrier_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Tank_Barrier" );

		Util.MapDebugPrint( "Tank_Barrier_Planted" );
	},
	Tank_Barrier_Defused = function( trigger )
	{
		Map.Tank_Barrier_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Tank_Barrier" );

		Util.MapDebugPrint( "Tank_Barrier_Defused" );
	},
	Tank_Barrier_Destroyed = function( trigger )
	{
		Map.Tank_Barrier_Dyno = 0;
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Tank_Barrier" );

		Util.MapDebugPrint( "Tank_Barrier_Destroyed" );
	},

	key_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAPPOINT_Key" );
		Util.MapDebugPrint( "key_Taken" );
	},
	key_Returned = function( trigger )
	{
		Util.MapDebugPrint( "key_Returned" );
	},
	key_Secured = function( trigger )
	{
		Wp.SetWaypointFlag( "Door1", "closed", 0 );
		Wp.SetWaypointFlag( "Door2", "closed", 0 );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "FLAG_secret_serum" );

		Util.MapDebugPrint( "key_Secured - door unlocked" );
	},

	secret_serum_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAPPOINT_Serum" );
		Util.MapDebugPrint( "secret_serum_Taken" );
	},
	secret_serum_Returned = function( trigger )
	{
		Util.MapDebugPrint( "secret_serum_Returned" );
	},

	//allies win
	secret_serum_Secured = function( trigger )
	{
		Util.MapDebugPrint( "secret_serum_Secured" );
	},

	depot_flag_Axis_Captured = function( trigger )
	{

		Util.MapDebugPrint( "depot_flag_Axis_Captured" );
	},

	depot_flag_Allies_Captured = function( trigger )
	{

		Util.MapDebugPrint( "depot_flag_Allies_Captured" );
	},


	// Dual Command Post

	Allied_CP_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Built" );
	},
	Allied_CP_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Allied_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},

	Axis_CP_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Built" );
	},
	Axis_CP_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Axis_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},


	vehicle_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				SetAvailableMapGoals( TEAM.ALLIES, 0, "SNIPE_ATTACK_S1_.*" );

				SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Tank_Barrier" );
				SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Axis_Construction" );

				Util.MapDebugPrint("TEAM.AXIS, 0, BUILD_Tank_Barrier");
			}
			case 2:
			{
				Map.Stage = 2;
				SetAvailableMapGoals( TEAM.ALLIES, 0, {
					"BUILD_Tank",
					"ESCORT_Tank",
				});
				SetAvailableMapGoals( TEAM.ALLIES, 1, {
					"FLAG_key",
					"CHECKPOINT_depot_flag",
				});

				SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Axis_Construction" );
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, 0);
	},

	axis_spawn_back = function( trigger )
	{
		//SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "axis_spawn_back" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "tank at location", Map.vehicle_at_location );
	b1 = OnTriggerRegion( AABB(-2103.027,4048.847,109.551,-1987.157,4258.930,189.504), RegionTrigger.VehicleTrigger );
	b2 = OnTriggerRegion( AABB( 2871.719,-356.592,168.160, 3070.574,-190.976,252.723), RegionTrigger.VehicleTrigger );

	OnTrigger( "Axis Team have built the Side Entrance!", Map.Axis_Construction_Built );
	OnTrigger( "Planted at the Axis Construction.", Map.Axis_Construction_Planted );
	OnTrigger( "Defused at the Axis Construction.", Map.Axis_Construction_Defused );
	OnTrigger( "MISSING_STRING", Map.Axis_Construction_Destroyed );

	OnTrigger( "The tank has been repaired!", Map.Tank_Built );
	OnTrigger( "The tank has been damaged!", Map.Tank_Destroyed );

	OnTrigger( "The Tank Barrier has been constructed.", Map.Tank_Barrier_Built );
	OnTrigger( "Planted at the Tank Barrier.", Map.Tank_Barrier_Planted );
	OnTrigger( "Defused at the Tank Barrier.", Map.Tank_Barrier_Defused );
	OnTrigger( "The Tank Barrier has been destroyed.", Map.Tank_Barrier_Destroyed );

	//tank reached fort on the hill
	OnTrigger( "Setting Axis autospawn to Axis Depot", Map.axis_spawn_back );

	OnTrigger( "Allies have stolen the key!", Map.key_Taken );
	OnTrigger( "Axis have returned the key!", Map.key_Returned );
	OnTrigger( "Allies captured allied_obj1", Map.key_Secured );

	OnTrigger( "Allies have stolen the secret serum!", Map.secret_serum_Taken );
	OnTrigger( "MISSING_STRING", Map.secret_serum_Returned );
	OnTrigger( "MISSING_STRING", Map.secret_serum_Secured );

	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 );

	Util.DisableGoal( ".*", true ); // all but routes
	Util.EnableGoal( ".*CAB.*" );

	Util.LimitToClass( "PLANT_Axis_Command_Post", 2, 5 );
	Util.LimitToClass( "PLANT_Allied_Command_Post", 1, 5 );
	Util.LimitToClass( "PLANT_Axis_Construction", 2, 5 );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"ATTACK_S1_.*",
		"SNIPE_ATTACK_S1_.*",
		"BUILD_Tank",
		"ESCORT_Tank",
		"MOUNT_Tank",
		"BUILD_Allied_Command_Post",
	});
	SetGoalPriority( "BUILD_Allied_Command_Post", 0.95, 2, 3 ); //at start only
	SetGoalPriority( "MOUNT_Tank", 0.92 );
	Util.ExcludeClass( "ESCORT_Tank", 1, 3 );

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"DEFEND_S1_.*",
		"SNIPE_DEFEND_S1_.*",
		"BUILD_Axis_Command_Post",
		"CHECKPOINT_depot_flag",
		"BUILD_Tank_Barrier",
	});
	SetGoalPriority( "CHECKPOINT_depot_flag", 0.95 );
	SetGoalPriority( "BUILD_Axis_Construction", 0.75 );
	SetGoalPriority( "BUILD_Axis_Command_Post", 0.73 );

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

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


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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 90.0;
	team = bot.GetTeam();
	class = bot.GetClass();

	if ( class == CLASS.COVERTOPS )
	{
		if ( team == TEAM.ALLIES )
		{
			bot.ChangePrimaryWeapon( WEAPON.GARAND );
		}
		else if ( team == TEAM.AXIS )
		{
			bot.ChangePrimaryWeapon( WEAPON.K43 );
		}
	}
};
