//==========================================================================================
//
//	rs_deep_beta.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	15 August 2018	Initial Script
//
//==========================================================================================
//

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


	Bridge_Dyno = 0,
	Command_Post_Dyno = 0,
	Main_Gate_Dyno = 0,
	Supply_Crate_Dyno = 0,
	Wood_Barrier_Dyno = 0,

	Wood_Barrier_Planted = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Wood_Barrier_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Wood_Barrier" );

		Util.MapDebugPrint( "Wood_Barrier_Planted" );
	},
	Wood_Barrier_Defused = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Wood_Barrier_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Wood_Barrier" );

		Util.MapDebugPrint( "Wood_Barrier_Defused" );
	},
	Wood_Barrier_Destroyed = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Wood_Barrier_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Main_Gate" );

		Util.MapDebugPrint( "Wood_Barrier_Destroyed" );
	},

	Bridge_Built = function( trigger )
	{
		if ( TestMap ) { return; }

		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Bridge" );

		Util.MapDebugPrint( "Bridge_Built" );
	},
	Bridge_Planted = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Bridge_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Bridge" );

		Util.MapDebugPrint( "Bridge_Planted" );
	},
	Bridge_Defused = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Bridge_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Bridge" );

		Util.MapDebugPrint( "Bridge_Defused" );
	},
	Bridge_Destroyed = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Bridge_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Bridge" );

		Util.MapDebugPrint( "Bridge_Destroyed" );
	},

	Main_Gate_Planted = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Main_Gate_Dyno += 1;
		Util.MapDebugPrint( "Main_Gate_Planted" );
	},
	Main_Gate_Defused = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Main_Gate_Dyno -= 1;
		Util.MapDebugPrint( "Main_Gate_Defused" );
	},
	Main_Gate_Destroyed = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Main_Gate_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CHECKPOINT_forward_spawn" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Supply_Crate" );

		Util.MapDebugPrint( "Main_Gate_Destroyed" );
	},

	Supply_Crate_Planted = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Supply_Crate_Dyno += 1;
		Util.MapDebugPrint( "Supply_Crate_Planted" );
	},
	Supply_Crate_Defused = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Supply_Crate_Dyno -= 1;
		Util.MapDebugPrint( "Supply_Crate_Defused" );
	},
	Supply_Crate_Destroyed = function( trigger )
	{
		if ( TestMap ) { return; }

		Map.Supply_Crate_Dyno = 0;
		Wp.SetWaypointFlag( "gold_wp", "closed", 0);
		SetAvailableMapGoals( TEAM.ALLIES, 1, "FLAG_Gold_Crate" );

		Util.MapDebugPrint( "Supply_Crate_Destroyed" );
	},

	Gold_Crate_Taken = function( trigger )
	{
		if ( TestMap ) { return; }

		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAPPOINT_Gold" );

		Util.MapDebugPrint( "Gold_Crate_Taken" );
	},

	Gold_Crate_Returned = function( trigger )
	{
		if ( TestMap ) { return; }

		Util.MapDebugPrint( "Gold_Crate_Returned" );
	},

	Gold_Crate_Secured = function( trigger )
	{
		if ( TestMap ) { return; }

		Util.MapDebugPrint( "Gold_Crate_Secured" );
	},

	forward_spawn_Axis_Captured = function( trigger )
	{
		if ( TestMap ) { return; }

		Util.MapDebugPrint( "forward_spawn_Axis_Captured" );
	},

	forward_spawn_Allies_Captured = function( trigger )
	{
		if ( TestMap ) { return; }

		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Command_Post" );

		Util.MapDebugPrint( "forward_spawn_Allies_Captured" );
	},

	// 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()
{
	if ( TestMapOn ) { Util.AutoTestMap(); }

	// Register callback functions
	OnTrigger( "Allied team has built the Bridge!", Map.Bridge_Built );
	OnTrigger( "Planted at the Bridge.", Map.Bridge_Planted );
	OnTrigger( "Defused at the Bridge.", Map.Bridge_Defused );
	OnTrigger( "Axis team has destroyed the Bridge!", Map.Bridge_Destroyed );

	OnTrigger( "Planted at the Wood Barrier.", Map.Wood_Barrier_Planted );
	OnTrigger( "Defused at the Wood Barrier.", Map.Wood_Barrier_Defused );
	OnTrigger( "The Allied team has destroyed the Wood Barrier!", Map.Wood_Barrier_Destroyed );

	OnTrigger( "Planted at the Main Gate.", Map.Main_Gate_Planted );
	OnTrigger( "Defused at the Main Gate.", Map.Main_Gate_Defused );
	OnTrigger( "The Allied team has destroyed the Main Gate!", Map.Main_Gate_Destroyed );

	OnTrigger( "Planted at the Supply Crate.", Map.Supply_Crate_Planted );
	OnTrigger( "Defused at the Supply Crate.", Map.Supply_Crate_Defused );
	OnTrigger( "The Allied team has destroyed the Supply Crate!", Map.Supply_Crate_Destroyed );

	OnTrigger( "Allied team has stolen the Gold Crate!", Map.Gold_Crate_Taken );
	OnTrigger( "Axis team has returned the Gold Crate!", Map.Gold_Crate_Returned );
	OnTrigger( "Allied team has escaped with the gold!", Map.Gold_Crate_Secured );

	OnTrigger( "Axis capture the forward bunker!", Map.forward_spawn_Axis_Captured );
	OnTrigger( "Allies capture the forward bunker!", Map.forward_spawn_Allies_Captured );

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

	Wp.SetWaypointFlag( "gold_wp", "closed", 1);

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"CAMP_b1_.*",
		"MOUNTMG42_.*",
		"BUILD_Bridge",
		"PLANT_Wood_Barrier",
	});

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

	Util.AddUsePoint( "PLANT_Wood_Barrier", Vec3(-206,-69,520) );
	Util.LimitToClass( "PLANT_Wood_Barrier", 2, 3 );
	Util.LimitToClass( "PLANT_Command_Post", 0, 5 );

	SetGoalPriority( "PLANT_Wood_Barrier", 0.90 );
	SetGoalPriority( "BUILD_Bridge",       0.85 );

	SetGoalPriority( "DEFUSE_Wood_Barrier_.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, 1 ); //can't get there

	// Max users per goal
	Util.SetMaxUsers( 1, "CAMP_.*" );
/*	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "SNIPE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "MOBILEMG42_.*" );
	Util.SetMaxUsers( 1, "MOBILEMORTAR_.*" );
	Util.SetMaxUsers( 1, "AIRSTRIKE_.*" );
	Util.SetMaxUsers( 1, "CALLARTILLERY_.*" );*/

	// Camp times
	SetMapGoalProperties( "CAMP_.*", {MinCampTime=60, MaxCampTime=600} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=60, MaxCampTime=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 = 1800;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		PLANT_Supply_Crate =
		{
		},
		PLANT_Main_Gate =
		{
		},
		BUILD_Bridge =
		{
		},
		PLANT_Bridge =
		{
		},
		PLANT_Wood_Barrier =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		CHECKPOINT_forward_spawn =
		{
		},
		FLAG_Gold_Crate =
		{
		},
	};
	Util.Routes(MapRoutes);
};
