//==========================================================================================
//
//	et_depot.gm
//
//	Who                	When		What
//------------------------------------------------------------------------------------------
//	^1-=-[DSK]-=-^5Classic	22 December 2016	Initial Script
//
//  maker@bigsighstudios.com full waypoints + script
//
//==========================================================================================
//

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


	Navigation =
	{
		ladder_1 =
		{
			navigate = function(_this)
			{
				wpTable = {};
				Wp.GetWaypointByName("ladder_1", wpTable);
				if ( _this.Goto(wpTable.position) == EVENT.PATH_SUCCESS )
				{
					_this.AddAimRequest(Priority.High, "facing", wpTable.facing);
					sleep(0.25);
					_this.Bot.HoldButton(BTN.FORWARD, 6);
					sleep(6);
				}
			}
		},
	},


	//get teams to centre then enable end-game goals
	forward_spawn_Axis_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"BUILD_Command_Post",
			"BUILD_Axis_metal_barrier",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"BUILD_Command_Post",
		});
		Util.MapDebugPrint( "forward_spawn_Axis_Captured" );
	},

	forward_spawn_Allies_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"CAMP_Flag_.*",
			"BUILD_Allied_offense_Wall",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Command_Post",
			"BUILD_Allied_offense_Wall",
		});
		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"CAMP_Flag_.*",
			"BUILD_Command_Post",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"MOUNTMG42_Axis_MG",
			"CAMP_Al_Offense_Wall_1",
		});
		Util.MapDebugPrint( "forward_spawn_Allies_Captured" );
	},

	Allied_MG_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_MG" );
		Util.MapDebugPrint( "Allied_MG_Built" );
	},
	Allied_MG_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Allied_MG_Destroyed" );
	},

	//control access to centre flag
	Allied_metal_barrier_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"CHECKPOINT_forward_spawn",
			".*Command_Post",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_metal_barrier" );
		Util.MapDebugPrint( "Allied_metal_barrier_Built" );
	},
	Allied_metal_barrier_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "CHECKPOINT_forward_spawn" );
		Util.MapDebugPrint( "Allied_metal_barrier_Destroyed" );
	},

	Axis_metal_barrier_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"CHECKPOINT_forward_spawn",
			".*Command_Post",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_metal_barrier" );
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"BUILD_Command_Post",
			"BUILD_Axis_Stairs",
		});
		Util.MapDebugPrint( "Axis_metal_barrier_Built" );
	},
	Axis_metal_barrier_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CHECKPOINT_forward_spawn" );
		Util.MapDebugPrint( "Axis_metal_barrier_Destroyed" );
	},

	Allied_offense_Wall_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"MOUNTMG42_393",
			"PLANT_Axis_Radio_Transmitter",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"PLANT_Allied_offense_Wall",
		});
		Util.MapDebugPrint( "Allied_offense_Wall_Built" );
	},
	Allied_offense_Wall_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"MOUNTMG42_Allied_MG",
		});
		Util.MapDebugPrint( "Allied_offense_Wall_Destroyed" );
	},

	Axis_MG_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_MG" );
		Util.MapDebugPrint( "Axis_MG_Built" );
	},
	Axis_MG_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Axis_MG_Destroyed" );
	},

	Axis_Stairs_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"PLANT_Allied_Radio_Transmitter",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"PLANT_Axis_Stairs",
		});
		Util.MapDebugPrint( "Axis_Stairs_Built" );
	},
	Axis_Stairs_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Axis_Stairs_Destroyed" );
	},

	//end game
	Allied_Radio_Transmitter_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Allied_Radio_Transmitter_Destroyed" );
	},

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


	// 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( "Axis capture the forward spawn!", Map.forward_spawn_Axis_Captured );
	OnTrigger( "Allies capture the forward spawn!", Map.forward_spawn_Allies_Captured );

	OnTrigger( "Allied MG nest constructed!", Map.Allied_MG_Built );
	OnTrigger( "Axis team has destroyed the Allied MG nest!", Map.Allied_MG_Destroyed );

	OnTrigger( "Axis MG nest constructed!", Map.Axis_MG_Built );
	OnTrigger( "Allied team has destroyed the Axis MG nest!", Map.Axis_MG_Destroyed );

	OnTrigger( "The Allied Metal Barrier has been built!", Map.Allied_metal_barrier_Built );
	OnTrigger( "Axis have destroyed the Allied Metal Barrier!", Map.Allied_metal_barrier_Destroyed );

	OnTrigger( "The Axis Metal Barrier has been constructed!", Map.Axis_metal_barrier_Built );
	OnTrigger( "Allies destroyed the Axis Metal Barrier!", Map.Axis_metal_barrier_Destroyed );

	OnTrigger( "The Allied Offense Wall has been built!", Map.Allied_offense_Wall_Built );
	OnTrigger( "The Axis have destroyed the Allied Offense Wall!", Map.Allied_offense_Wall_Destroyed );

	OnTrigger( "The secret Axis Stair has been constructed!", Map.Axis_Stairs_Built );
	OnTrigger( "The secret Axis Stair has been destroyed!", Map.Axis_Stairs_Destroyed );

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

	//end game
	OnTrigger( "Axis have blown up the Allied Transmitter!", Map.Allied_Radio_Transmitter_Destroyed );
	OnTrigger( "Allies have blown up the Axis Transmitter!", Map.Axis_Radio_Transmitter_Destroyed );


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

	Util.LimitToClass( "PLANT_Command_Post", 0, 5 );

	Util.LimitToClass( "PLANT_Axis_metal_barrier", 2, 5 );
	Util.LimitToClass( "PLANT_Axis_Stairs", 2, 5 );
	Util.LimitToClass( "PLANT_Axis_MG", 2, 5 );

	Util.LimitToClass( "PLANT_Allied_metal_barrier", 1, 5 );
	Util.LimitToClass( "PLANT_Allied_offense_Wall", 1, 5 );
	Util.LimitToClass( "PLANT_Allied_MG", 1, 5 );

	Util.ExcludeClass( "CAMP_.*", 0, 3 );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"CAMP_Flag_.*",
		"BUILD_Allied_MG",
		"BUILD_Allied_offense_Wall",
		"CHECKPOINT_forward_spawn",
	});

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"CAMP_Flag_.*",
		"BUILD_Axis_MG",
		"CHECKPOINT_forward_spawn",
	});

	SetGoalPriority("CAMP_.*", 0.71);
	SetGoalPriority("CAMP_.*", 0.71);

	SetMapGoalProperties( "CAMP_.*", {MinCampTime=300, MaxCampTime=900} );
	SetMapGoalProperties( "CAMP_.*", {MinCampTime=300, MaxCampTime=900} );

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

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

	Util.AddUsePoint("PLANT_Allied_Radio_Transmitter", Vec3(-6629,1982,-280));
	Util.AddUsePoint("PLANT_Axis_Radio_Transmitter", Vec3(-11582,5986,600));

	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 =
	{
		CHECKPOINT_forward_spawn =
		{
			ROUTE_AlSp =
			{
				ROUTE_AlSp_1 =
				{
					ROUTE_Flag = {},
				},
			},
		},

		BUILD_Allied_MG =
		{
			ROUTE_AlSp_Low =
			{
				ROUTE_Al_MG = {},
			},
		},
		PLANT_Allied_MG =
		{
			ROUTE_Al_MG = {},
		},

		BUILD_Allied_offense_Wall =
		{
		},
		PLANT_Allied_offense_Wall =
		{
		},
		BUILD_Allied_metal_barrier =
		{
		},
		PLANT_Allied_metal_barrier =
		{
		},

		BUILD_Command_Post =
		{
			ROUTE_Flag =
			{
				ROUTE_CP = {},
			},
		},

		PLANT_Command_Post = {},

		BUILD_Axis_Stairs =
		{
		},
		PLANT_Axis_Stairs =
		{
		},
		BUILD_Axis_metal_barrier =
		{
		},
		PLANT_Axis_metal_barrier =
		{
		},
		PLANT_Axis_Radio_Transmitter =
		{
		},
		BUILD_Axis_MG =
		{
		},
		PLANT_Axis_MG =
		{
		},
		PLANT_Allied_Radio_Transmitter =
		{
		},
	};
	Util.Routes(MapRoutes);
};
