//==========================================================================================
//
//	austriafinal.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	26 December 2017	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 1,

	//Side Tunnel
	Side_Tunnel_Entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Side_Tunnel_Entrance" );
		Util.MapDebugPrint( "Side_Tunnel_Entrance_Planted" );
	},

	Side_Tunnel_Entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Side_Tunnel_Entrance" );
		Util.MapDebugPrint( "Side_Tunnel_Entrance_Defused" );
	},

	Side_Tunnel_Entrance_Destroyed = function( trigger )
	{
		Wp.SetWaypointFlag( "SideTunnelPlant_WP", "closed", 1);
		Util.MapDebugPrint( "Side_Tunnel_Entrance_Destroyed" );
	},

	//Side Barrier
	Side_Barrier_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Side_Barrier" );
		Util.MapDebugPrint( "Side_Barrier_Built" );
	},

	Side_Barrier_Planted = function( trigger )
	{
		//SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Side_Barrier" );
		Util.MapDebugPrint( "Side_Barrier_Planted" );
	},

	Side_Barrier_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Side_Barrier" );
		Util.MapDebugPrint( "Side_Barrier_Defused" );
	},

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

	//Front Door
	Front_Gate_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Front_Gate" );

		Util.MapDebugPrint( "Front_Gate_Planted" );
	},

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

	Front_Gate_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Main_Entrance" );

		Util.MapDebugPrint( "Front_Gate_Destroyed" );
	},

	//Main Entrance
	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 )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Radar_System" );
		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"DEFEND_Ax_.*",
			"MOBILEMG42_Ax_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"DEFEND_Radar_.*",
			"MOBILEMG42_Radar_.*",
		});

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	//Radar System
	Radar_System_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Radar_System" );
		Util.MapDebugPrint( "Radar_System_Planted" );
	},

	Radar_System_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Radar_System" );
		Util.MapDebugPrint( "Radar_System_Defused" );
	},

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

	//River Grate
	River_Grate_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_River_Grate" );
		Util.MapDebugPrint( "River_Grate_Planted" );
	},

	River_Grate_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_River_Grate" );
		Util.MapDebugPrint( "River_Grate_Defused" );
	},

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

	//West MG Nest
	West_MG_Nest_Built = function( trigger )
	{
		Util.MapDebugPrint( "West_MG_Nest_Built" );
	},

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

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

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

	//East MG Nest
	East_MG_Nest_Built = function( trigger )
	{
		Util.MapDebugPrint( "East_MG_Nest_Built" );
	},

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

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

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


// Command Post START ==========================================================

	//CP switch
	CP_Owner = 0,
	CP_Dyno = 0,

	Set_CP = function(_p) // p = TEAM.ALLIES or TEAM.AXIS or 0 (unbuilt)
	{
		if ( typeName(_p) == "int" )
		{
			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" );
				}
				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" );
				}
			}
		}
		else
		{
			Util.MapDebugPrint("Invalid param passed to Set_CP: " + _p );
		}
		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( "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  );

	OnTrigger( "Planted at the Side Tunnel Entrance.", Map.Side_Tunnel_Entrance_Planted );
	OnTrigger( "Defused at the Side Tunnel Entrance.", Map.Side_Tunnel_Entrance_Defused );
	OnTrigger( "The Allies have breached the Side Tunnel Entrance!", Map.Side_Tunnel_Entrance_Destroyed );

	OnTrigger( "Planted at the Front Gate.", Map.Front_Gate_Planted );
	OnTrigger( "Defused at the Front Gate.", Map.Front_Gate_Defused );
	OnTrigger( "The Allies have breached the Stone Barrier!", Map.Front_Gate_Destroyed );

	OnTrigger( "Planted at the Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Defused at the Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "The Allies have breached the Main Entrance!", Map.Main_Entrance_Destroyed );

	OnTrigger( "Axis team have built the Side Barrier!", Map.Side_Barrier_Built );
	OnTrigger( "Planted at the Side Barrier.", Map.Side_Barrier_Planted );
	OnTrigger( "Defused at the Side Barrier.", Map.Side_Barrier_Defused );
	OnTrigger( "The Allies have destroyed the Side Barrier!", Map.Side_Barrier_Destroyed );

	OnTrigger( "Planted at the Radar System.", Map.Radar_System_Planted );
	OnTrigger( "Defused at the Radar System.", Map.Radar_System_Defused );
	OnTrigger( "The Allies have destroyed the Radar System!", Map.Radar_System_Destroyed );

	OnTrigger( "Planted at the River Grate.", Map.River_Grate_Planted );
	OnTrigger( "Planted at the River Grate.", Map.River_Grate_Defused );
	OnTrigger( "The Allies have breached the river grate!", Map.River_Grate_Destroyed );

	OnTrigger( "Axis team has constructed the West MG nest!", Map.West_MG_Nest_Built );
	OnTrigger( "Planted at the West MG nest.", Map.West_MG_Nest_Planted );
	OnTrigger( "Defused at the West MG nest.", Map.West_MG_Nest_Defused );
	OnTrigger( "Allied team has destroyed the West MG nest!", Map.West_MG_Nest_Destroyed );

	OnTrigger( "Axis team has constructed the East MG nest!", Map.East_MG_Nest_Built );
	OnTrigger( "Defused at the East MG nest.", Map.East_MG_Nest_Planted );
	OnTrigger( "Planted at the East MG nest.", Map.East_MG_Nest_Defused );
	OnTrigger( "Allied team has destroyed the East MG nest!", Map.East_MG_Nest_Destroyed );

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

	Util.LimitToClass( "PLANT_Side_Tunnel_Entrance", 2, CLASS.ENGINEER );
	Util.LimitToClass( "PLANT_Command_Post", 0, CLASS.COVERTOPS );
	Util.LimitToClass( "PLANT_East_.*", 2, CLASS.COVERTOPS );
	Util.LimitToClass( "PLANT_West_.*", 2, CLASS.COVERTOPS );
	Util.LimitToClass( "PLANT_Side_.*", 2, CLASS.COVERTOPS );

	Util.SetGoalPosition( -442, 741, -371, "PLANT_Side_Tunnel_Entrance" );
	Util.SetGoalPosition( 1507, -1263, -170, "PLANT_River_Grate" );

	//broken goal > Util.SetGoalOffset( "MOUNTMG42_209", -1378, -160, 214 ); //in roof corner
	
	//Allies
	//SetAvailableMapGoals( TEAM.ALLIES, 1, "ATTACK_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"PLANT_Side_Tunnel_Entrance",
		"PLANT_Side_Barrier",
		"BUILD_Command_Post",
		"PLANT_Front_Gate",
		"SNIPE_Al_.*",
	});
	SetGoalPriority( "PLANT_Side_Tunnel_Entrance"  , 0.95 );
	SetGoalPriority( "BUILD_Command_Post"          , 0.93 );
	SetGoalPriority( "PLANT_Front_Gate"            , 0.91 );

	//Axis 		broken mg > "BUILD_East_MG_Nest",
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"BUILD_West_MG_Nest",
		"BUILD_Command_Post",
		"BUILD_Side_Barrier",
		"PLANTMINE_.*",
		"DEFEND_Ax_.*",
		"MOBILEMG42_.*",
		"MOUNTMG42_.*",
		"SNIPE_Ax_.*",
	});
	SetGoalPriority("BUILD_East_MG_Nest"   , 0.95 );
	SetGoalPriority("BUILD_West_MG_Nest"   , 0.94 );
	SetGoalPriority("BUILD_Side_Barrier"   , 0.93 );
	SetGoalPriority("BUILD_Command_Post"   , 0.92 );
	SetGoalPriority("BUILD_Side_Barrier"	 , 0.91 );
	SetGoalPriority("PLANTMINE_.*"	       , 0.75 );

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

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


	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 =
	{
		PLANT_Front_Gate =
		{
			ROUTE_AlSp = 
			{
				ROUTE_Al_Ladder = 
				{
					ROUTE_Front_Gate = {},
				},
			},
		},

		PLANT_River_Grate = {},

		PLANT_Main_Entrance =
		{
			ROUTE_Front_Gate =
			{
				ROUTE_Main = {},
			},
		},

		PLANT_Radar_System =
		{
			ROUTE_Main = 
			{
				ROUTE_Main_2 =
				{
					ROUTE_Main_3 =
					{
						ROUTE_Radar = {},
					},
				},
			},
		},

		PLANT_Side_Tunnel_Entrance = {},

		BUILD_Side_Barrier = {},
		PLANT_Side_Barrier = {},

		BUILD_Command_Post =
		{
			ROUTE_AlSp = 
			{
				ROUTE_Al_Back = 
				{
					ROUTE_CP = {},
				},
			},
		},

		PLANT_Command_Post =
		{
			ROUTE_AxSp_1 =
			{
				ROUTE_AxSp_1a = 
				{
					ROUTE_Ax_Front_R =
					{
						ROUTE_CP = {},
					},
				},
			},
		},

		BUILD_West_MG_Nest =
		{
		},
		PLANT_West_MG_Nest =
		{
		},
		BUILD_East_MG_Nest =
		{
		},
		PLANT_East_MG_Nest =
		{
		},

	};
	Util.Routes(MapRoutes);
};
