//==========================================================================================
//
//	ouessant.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	07 September 2018	Initial Script
//
//==========================================================================================
//

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

	Roles =
	{
		ALLIES =
		{
			AllBots = true, // each bot is considered for a role
			ATTACKER =
			{
				numbots = 2,
				crucialClass = CLASS.ENGINEER, CLASS.MEDIC,
			},
			ATTACKER1 =
			{
				numbots = 3,
				crucialClass = CLASS.FIELDOPS, CLASS.SOLDIER,
			},
		},

		AXIS =
		{
			AllBots = true, // each bot is considered for a role
			DEFENDER =
			{
				numbots = 2,
				crucialClass = CLASS.ENGINEER,
			},
			DEFENDER1 =
			{
				numbots = 3,
				crucialClass = CLASS.SOLDIER, CLASS.FIELDOPS,
			},
		},
	},

	westbunker_flag_Axis_Captured = function( trigger )
	{
		Util.MapDebugPrint( "westbunker_flag_Axis_Captured" );
	},
	westbunker_flag_Allies_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"PLANT_axis_roadblock",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"CHECKPOINT_westbunker_flag",
		});
		Util.MapDebugPrint( "westbunker_flag_Allies_Captured" );
	},

	Road_Gate_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Command_Post",
		});
		Util.MapDebugPrint( "Road_Gate_Planted" );
	},
	Road_Gate_Defused = function( trigger )
	{
		Util.MapDebugPrint( "Road_Gate_Defused" );
	},
	Road_Gate_Destroyed = function( trigger )
	{
		Util.DisableGoal( "CAMP_Def_S1_.*" );
		Util.DisableGoal("CHECKPOINT_westbunker_flag");
		Util.EnableGoal( "CAMP_Att_S2_.*" );
		Util.EnableGoal( "CAMP_Def_S2_.*" );

		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Bridge_Controls",
		});
		Util.MapDebugPrint( "Road_Gate_Destroyed" );
	},

	Software_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"PLANT_Axis_Restoring_Software",
		});
		Util.MapDebugPrint( "Software_Built" );
	},
	Software_Planted = function( trigger )
	{
		Util.MapDebugPrint( "Software_Planted" );
	},
	Software_Defused = function( trigger )
	{
		Util.MapDebugPrint( "Software_Defused" );
	},
	Software_Destroyed = function( trigger )
	{
		Util.DisableGoal( "CAMP_Def_S2_.*" );
		Util.MapDebugPrint( "Software_Destroyed" );
	},

	Bridge_Controls_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Waterside_Ladder",
			"PLANT_LightHouse",
			"CAMP_Att_S3_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"CAMP_Def_S3_.*",
			"BUILD_Axis_Restoring_Software",
		});
		Util.MapDebugPrint( "Bridge_Controls_Built" );
	},
	Bridge_Controls_Planted = function( trigger )
	{
		Util.MapDebugPrint( "Bridge_Controls_Planted" );
	},
	Bridge_Controls_Defused = function( trigger )
	{
		Util.MapDebugPrint( "Bridge_Controls_Defused" );
	},
	Bridge_Controls_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Bridge_Controls_Destroyed" );
	},

	Waterside_Ladder_Built = function( trigger )
	{
		Wp.SetWaypointFlag("wsl_top", "closed", 0);
		Util.MapDebugPrint( "Waterside_Ladder_Built" );
	},
	Waterside_Ladder_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Waterside_Ladder_Destroyed" );
	},


	LightHouse_Planted = function( trigger )
	{
		Util.MapDebugPrint( "LightHouse_Planted" );
	},
	LightHouse_Defused = function( trigger )
	{
		Util.MapDebugPrint( "LightHouse_Defused" );
	},
	LightHouse_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "LightHouse_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" );
	},


};

global OnMapLoad = function()
{
	// Register callback functions
	//"Computer software restored!"

	OnTrigger( "Planted at The axis roadblock.", Map.Road_Gate_Planted );
	OnTrigger( "Defused at The axis roadblock.", Map.Road_Gate_Defused );
	OnTrigger( "Allies have destroyed the road gate!", Map.Road_Gate_Destroyed );

	OnTrigger( "Computer software restored!", Map.Software_Built );
	OnTrigger( "Planted at Axis Restoring Software.", Map.Software_Planted );
	OnTrigger( "Defused at Axis Restoring Software.", Map.Software_Defused );
	OnTrigger( "death test axis", Map.Software_Destroyed );

	OnTrigger( "The lighthouse bridge is rising!", Map.Bridge_Controls_Built );
	OnTrigger( "Planted at The Bridge Controls.", Map.Bridge_Controls_Planted );
	OnTrigger( "Defused at The Bridge Controls.", Map.Bridge_Controls_Defused );
	OnTrigger( "Lighthouse bridge is lowering!", Map.Bridge_Controls_Destroyed );

	OnTrigger( "Allied ladder access constructed!", Map.Waterside_Ladder_Built );
	OnTrigger( "Allied ladder access destroyed!", Map.Waterside_Ladder_Destroyed );

	OnTrigger( "Axis capture the Barracks!", Map.westbunker_flag_Axis_Captured );
	OnTrigger( "We've captured the Garage!  Bomb the road gates!", Map.westbunker_flag_Allies_Captured );
	//"Bagadooosh!  Allied escape route cleared!"

	//allies win
	OnTrigger( "Planted at The Lighthouse.", Map.LightHouse_Planted );
	OnTrigger( "Defused at The Lighthouse.", Map.LightHouse_Defused );
	OnTrigger( "Allies have crippled the German port!", Map.LightHouse_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  );

//-----------------------------------------------------------------------------------------------

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

	Util.AddUsePoint( "PLANT_Bridge_Controls", Vec3(-2221,5661,136) );

	//Util.AddUsePoint( "BUILD_Command_Post", Vec3(1387,2916,-39) );
	Util.SetGoalPosition( 1395, 2921, -40, "BUILD_Command_Post" );

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


	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"CAMP_Def_S1_.*",
		"CHECKPOINT_westbunker_flag",
		"PLANT_axis_roadblock",
	});
	Util.ExcludeClass( "CHECKPOINT_westbunker_flag", 2, 3 );
	SetGoalRole( "CAMP_Def_S1_.*", ROLE.ATTACKER1 );

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"CAMP_Def_S1_.*",
		"CHECKPOINT_westbunker_flag",
		"BUILD_Command_Post",
	});
	Util.ExcludeClass( "CAMP_Def_S1_.*", 1, 3 );
	SetGoalRole( "CAMP_Def_S1_.*", ROLE.DEFENDER1 );

	//SetGoalPriority( "CAMP_.*", 0.80 );

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

	// Camp times
	SetMapGoalProperties( "CAMP_.*", {MinCampTime=30, MaxCampTime=300} );
	Wp.SetWaypointFlag("wsl_top", "closed", 1);

	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_axis_roadblock= {},

		CHECKPOINT_westbunker_flag =
		{
		},
		BUILD_Waterside_Ladder =
		{
		},
		PLANT_Waterside_Ladder =
		{
		},
		BUILD_Bridge_Controls =
		{
		},
		PLANT_Bridge_Controls =
		{
		},
		BUILD_Axis_Restoring_Software =
		{
		},
		PLANT_Axis_Restoring_Software =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},

		PLANT_LightHouse =
		{
		},

	};
	Util.Routes(MapRoutes);
};
