//==========================================================================================
//
//	spearhead_b1.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	11 March 2018	- waypoints, goals, script
//
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script
	DefendingTeam = TEAM.AXIS,
	Stage = 1,

	Main_Entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Main_Entrance" );
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},
	Main_Entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Main_Entrance" );
		Util.MapDebugPrint( "Main_Entrance_Defused" );
	},
	Main_Entrance_Destroyed = function( trigger )
	{
		Map.Stage = 2;
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"PLANT_Main_Entrance",
			"CAMP_b1_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Command_Post",
			"PLANT_Depot_Gate",
			"PLANT_Back_Door",
		});

		SetAvailableMapGoals( TEAM.AXIS, 1, "CAMP_r2_.*" );

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Side_Entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Side_Entrance" );
		Util.MapDebugPrint( "Side_Entrance_Planted" );
	},
	Side_Entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Side_Entrance" );
		Util.MapDebugPrint( "Side_Entrance_Defused" );
	},
	Side_Entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Side_Entrance" );

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

	Depot_Gate_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Depot_Gate" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "CAMP_r4_.*" ); //mobile mg
		Util.MapDebugPrint( "Depot_Gate_Planted" );
	},
	Depot_Gate_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Depot_Gate" );
		Util.MapDebugPrint( "Depot_Gate_Defused" );
	},
	Depot_Gate_Destroyed = function( trigger )
	{
		Map.Stage = 3;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Depot_Gate" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"PLANT_Back_Door",
			"FLAG_.*",
			"CAP.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, 0, "CAMP_r2_.*" );
		Util.EnableGoal( "CAMP_r3_.*" ); //both

		Util.MapDebugPrint( "Depot_Gate_Destroyed" );
	},

	Back_Door_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Back_Door" );
		Util.MapDebugPrint( "Back_Door_Planted" );
	},
	Back_Door_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Back_Door" );
		Util.MapDebugPrint( "Back_Door_Defused" );
	},
	Back_Door_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Back_Door" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "ESCORT_Truck" );
		Util.MapDebugPrint( "Back_Door_Destroyed" );
	},

	Secret_Documents_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAPPOINT_Docs" );
		Util.MapDebugPrint( "Secret_Documents_Taken" );
	},
	Secret_Documents_Returned = function( trigger )
	{
		Util.MapDebugPrint( "Secret_Documents_Returned" );
	},
	Secret_Documents_Secured = function( trigger )
	{
		Util.MapDebugPrint( "Secret_Documents_Secured" );
	},

	Truck_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Truck" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "ESCORT_Truck" );
		Util.MapDebugPrint( "Truck_Built" );
	},
	Truck_Damaged = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Truck" );
		SetAvailableMapGoals( TEAM.ALLIES, 0, "ESCORT_Truck" );
		Util.MapDebugPrint( "Truck_Damaged" );
	},

	// 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" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_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" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_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( "The Truck has been repaired!", Map.Truck_Built );
	OnTrigger( "The Truck has been damaged!", Map.Truck_Damaged );

	OnTrigger( "Planted at Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Defused at Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "Allies have breached the Main Entrance and secured the Forward Bunker", Map.Main_Entrance_Destroyed );

	OnTrigger( "Planted at the Side Entrance.", Map.Side_Entrance_Planted );
	OnTrigger( "Defused at the Back Door.", Map.Side_Entrance_Defused );
	OnTrigger( "Allies have breached the Side Entrance!", Map.Side_Entrance_Destroyed );

	OnTrigger( "Planted at the Depot Gate.", Map.Depot_Gate_Planted );
	OnTrigger( "Defused at the Depot Gate.", Map.Depot_Gate_Defused );
	OnTrigger( "Allies have Destroyed The Main Depot Gate", Map.Depot_Gate_Destroyed );

	OnTrigger( "Planted at the Back Door.", Map.Back_Door_Planted );
	OnTrigger( "Defused at the Back Door.", Map.Back_Door_Defused );
	OnTrigger( "Allies have Destroyed The Back Depot Gate", Map.Back_Door_Destroyed );

	OnTrigger( "Allied team is escaping with the Secret Doucuments!", Map.Secret_Documents_Taken );
	OnTrigger( "MISSING_STRING", Map.Secret_Documents_Returned );
	OnTrigger( "Allied team escaped with the Secret Document!", Map.Secret_Documents_Secured );

	//auto-set: "Axis reclaim the Forward Spawn!" "Allies capture the Forward Spawn!"

	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( ".*", true ); // all but routes

	Util.LimitToClass( "PLANT_Command_Post", 1, 5 );
	Util.LimitToClass( "PLANT_Command_Post", 2, 5 );

	Util.AddUsePoint( "PLANT_Back_Door", Vec3(-361,2228,-235) );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"CAMP_b1_.*",
		"PLANT_Side_Entrance",
		"PLANT_Main_Entrance",
	});
	SetGoalPriority( "PLANT_Side_Entrance", 0.93, TEAM.ALLIES );
	SetGoalPriority( "PLANT_Main_Entrance", 0.92, TEAM.ALLIES );

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"TRIPMINE_r3_.*",
		"CAMP_r1_.*",
		"BUILD_Command_Post",
	});

	SetGoalPriority( "DEFUSE_Side_Entrance_.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, 1 );
	SetGoalPriority( "DEFUSE_Main_Entrance_.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, 1 );

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

	// Camp times
	SetMapGoalProperties( "CAMP_.*", {MinCampTime=60, MaxCampTime=900} );

	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;

	team = bot.GetTeam();
	class = bot.GetClass();

	if ( team == TEAM.ALLIES ) {
		if ( class == CLASS.COVERTOPS ) {
			bot.ChangePrimaryWeapon( WEAPON.GARAND_SCOPE );
		}
	}
	if ( team == TEAM.AXIS ) {
		if ( class == CLASS.COVERTOPS ) {
			bot.ChangePrimaryWeapon( WEAPON.K43_SCOPE );
		}
		if ( class == CLASS.SOLDIER & Map.Stage > 2 ) {
			bot.ChangePrimaryWeapon( WEAPON.MOBILE_MG42 );
		}
	}

};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		PLANT_Main_Entrance =
		{
		},
		PLANT_Side_Entrance =
		{
		},
		PLANT_Depot_Gate =
		{
		},
		PLANT_Back_Door =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		BUILD_Truck =
		{
		},
		FLAG_Secret_Documents =
		{
		},
	};
	Util.Routes(MapRoutes);
};
