//==================================================================================================
//
//	rs_radars.gm
//
//	Who  		When			What
//--------------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com 13-Aug-18 - Script, Goals and Waypoints.
//
//==================================================================================================

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

	Navigation =
	{
		ladder_1_pt =
		{
			navigate = function(_this)
			{
				_this.Bot.HoldButton(BTN.FORWARD, 4);
				sleep(4);
			},
		},
	},

	power_panel_Planted = function( trigger )
	{
		Util.MapDebugPrint( "power_panel_Planted" );
	},
	power_panel_Defused = function( trigger )
	{
		Util.MapDebugPrint( "power_panel_Defused" );
	},
	power_panel_Destroyed = function( trigger )
	{
		Wp.SetWaypointFlag( "ladder_1_pt", "closed", 0); //open after power panel is blown
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"PLANT_North_Radar",
			"PLANT_South_Radar",
		});
		Util.MapDebugPrint( "power_panel_Destroyed" );
	},

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


	Axis_sewer_barrier_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_sewer_barrier" );

		Util.MapDebugPrint( "Axis_sewer_barrier_Built" );
	},
	Axis_sewer_barrier_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_sewer_barrier" );
		Util.MapDebugPrint( "Axis_sewer_barrier_Destroyed" );
	},


	Farmhouse_Barrier_Built = function( trigger )
	{
		//SetAvailableMapGoals( TEAM.AXIS, 0, "ROUTE_AxisEscape1" );

		Util.MapDebugPrint( "Farmhouse_Barrier_Built" );
	},
	Farmhouse_Barrier_Planted = function( trigger )
	{
		Util.MapDebugPrint( "Farmhouse_Barrier_Planted" );
	},
	Farmhouse_Barrier_Defused = function( trigger )
	{
		Util.MapDebugPrint( "Farmhouse_Barrier_Defused" );
	},
	Farmhouse_Barrier_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Farmhouse_Barrier_Destroyed" );
	},

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

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

	North_Radar_Planted = function( trigger )
	{
		Util.MapDebugPrint( "North_Radar_Planted" );
	},
	North_Radar_Defused = function( trigger )
	{
		Util.MapDebugPrint( "North_Radar_Defused" );
	},
	North_Radar_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "North_Radar_Destroyed" );
	},

	South_Radar_Planted = function( trigger )
	{
		Util.MapDebugPrint( "South_Radar_Planted" );
	},
	South_Radar_Defused = function( trigger )
	{
		Util.MapDebugPrint( "South_Radar_Defused" );
	},
	South_Radar_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "South_Radar_Destroyed" );
	},


	// Dual Command Post
	Allied_CP_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Built" );
	},
	Allied_CP_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Planted" );
	},
	Allied_CP_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Defused" );
	},
	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_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Planted" );
	},
	Axis_CP_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Defused" );
	},
	Axis_CP_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Axis_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},


};

global OnMapLoad = function()
{
	// Register callback functions

	OnTrigger( "Allied team has constructed the MG Tower!", Map.Allied_MG_Tower_Built );
	OnTrigger( ".", Map.Allied_MG_Tower_Destroyed );

	OnTrigger( "Hatch has been constructed.", Map.Axis_sewer_barrier_Built );
	OnTrigger( "Hatch has been destroyed.", Map.Axis_sewer_barrier_Destroyed );

	OnTrigger( "Planted at the Power Panel.", Map.power_panel_Planted );
	OnTrigger( "Defused at the Power Panel.", Map.power_panel_Defused );
	OnTrigger( "The Radar base has been breached!", Map.power_panel_Destroyed );

	OnTrigger( "Farmhouse tunnel barrier has been constructed.", Map.Farmhouse_Barrier_Built );
	OnTrigger( "Planted at the Farmhouse barrier.", Map.Farmhouse_Barrier_Planted );
	OnTrigger( "Defused at the Farmhouse barrier.", Map.Farmhouse_Barrier_Defused );
	OnTrigger( "Farmhouse tunnel barrier has been destroyed.", Map.Farmhouse_Barrier_Destroyed );

	OnTrigger( "Allied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	OnTrigger( "Planted at the Allied Command Post.",                       Map.Allied_CP_Planted );
	OnTrigger( "Defused at the Allied Command Post.",                       Map.Allied_CP_Defused );
	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( "Planted at the Axis Command Post.",                         Map.Axis_CP_Planted );
	OnTrigger( "Defused at the Axis Command Post.",                         Map.Axis_CP_Defused );
	OnTrigger( "Allied team has destroyed the Axis Command Post!",          Map.Axis_CP_Destroyed );


	Util.DisableGoal( ".*", 1 );	// all but Routes

	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"BUILD_Allied_MG_Tower",
		"BUILD_Allied_Command_Post",
		"PLANT_power_panel",
	});

	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"BUILD_Axis_sewer_barrier",
		"BUILD_Axis_Command_Post",
		"BUILD_Farmhouse_Barrier",
	});

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

	//Priorities - Allies
	SetGoalPriority( "PLANT_Farmhouse_Barrier",   0.80);
	SetGoalPriority( "BUILD_Allied_Command_Post", 0.74);
	SetGoalPriority( "BUILD_Allied_MG_Tower",     0.73);
	SetGoalPriority( "PLANT_Axis_Command_Post",   0.72);
	SetGoalPriority( "PLANT_Axis_sewer_barrier",  0.70);

	//Priorities - Axis
	SetGoalPriority( "BUILD_Farmhouse_Barrier",   0.94);
	SetGoalPriority( "BUILD_Axis_sewer_barrier",  0.92);
	SetGoalPriority( "BUILD_Axis_Command_Post",   0.74);
	SetGoalPriority( "PLANT_Allied_Command_Post", 0.72);

	Wp.SetWaypointFlag("ladder_1_pt", "closed", 1); //open after power panel is blown

	Util.SetMaxUsers( 1, "BUILD_.*" );
	Util.SetMaxUsers( 1, "PLANT_.*" );
	Util.SetMaxUsers( 1, "CAMP_.*" );

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

};

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 180.0;

	weaps = { WEAPON.THOMPSON, WEAPON.MP40, WEAPON.SHOTGUN, WEAPON.M97, WEAPON.M7, WEAPON.GARAND, WEAPON.K43, WEAPON.BAR, WEAPON.STEN, WEAPON.MP34, WEAPON.BAR, WEAPON.STG44, WEAPON.FG42};
	foreach( id and weap in weaps )
	{
		w = bot.GetWeapon(weap);
		w.PrimaryFire.SetTargetBias(CLASS.BREAKABLE, 1.2);
	}

	// crapshoot: lower priority of knife at close range so they keep shooting breakables with primary
	w = bot.GetWeapon(WEAPON.KNIFE);
	w.PrimaryFire.SetDesirabilityRange(0, 48, 0.6);
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		PLANT_power_panel =
		{
			ROUTE_AlSp_1 =
			{
				ROUTE_Al_MG =
				{
					ROUTE_Al_Tunnel_Ent =
					{
						ROUTE_Barrier =
						{
							ROUTE_House_Side =
							{
								ROUTE_Power_Panel = {},
							},
						},
					},
				},
			},
		},
		BUILD_Allied_Command_Post =
		{
			ROUTE_AlSp_1 =
			{
				ROUTE_CP_1 =
				{
					ROUTE_Al_CP = {},
				},
			},
			ROUTE_AlSp_2 =
			{
				ROUTE_CP_1 =
				{
					ROUTE_Al_CP = {},
				},
			},
		},
		PLANT_Allied_Command_Post = {},

		BUILD_Farmhouse_Barrier =
		{
			ROUTE_House_1 =
			{
				ROUTE_House_Front =
				{
					ROUTE_Barrier = {},
				},
			},
			ROUTE_House_2 =
			{
				ROUTE_House_Front =
				{
					ROUTE_Barrier = {},
				},
			},
		},

		PLANT_Farmhouse_Barrier =
		{
			ROUTE_AlSp_1 =
			{
				ROUTE_Al_Tunnel_Ent =
				{
					ROUTE_Barrier = {},
				},
			},
			ROUTE_AlSp_2 =
			{
				ROUTE_Al_Tunnel_Ent =
				{
					ROUTE_Barrier = {},
				},
			},
		},

		BUILD_Axis_sewer_barrier = {},
		PLANT_Axis_sewer_barrier = {},

		BUILD_Axis_Command_Post =
		{
			ROUTE_WH_1 =
			{
				ROUTE_Ax_CP = {},
			},
			ROUTE_WH_2 =
			{
				ROUTE_Ax_CP = {},
			},
		},
		PLANT_Axis_Command_Post = {},

		PLANT_North_Radar =
		{
			ROUTE_Main_Ent =
			{
				ROUTE_Centre =
				{
					ROUTE_North_Radar = {},
				},
			},
		},
		PLANT_South_Radar =
		{
			ROUTE_Main_Ent =
			{
				ROUTE_Centre =
				{
					ROUTE_South_Radar = {},
				},
			},
		},
		BUILD_South_MG_nest = {},
		PLANT_South_MG_nest = {},
		BUILD_North_MG_nest = {},
		PLANT_North_MG_nest = {},

		BUILD_Allied_MG_Tower =
		{
			ROUTE_AlSp_1 =
			{
				ROUTE_Al_MG = {},
			},
			ROUTE_AlSp_2 =
			{
				ROUTE_Al_MG = {},
			},
		},
		PLANT_Allied_MG_Tower = {},
	};
	Util.Routes(MapRoutes);

};
