//==========================================================================================
//
//	whoreage_canyon10.gm
//
//	Who            	When		What
//------------------------------------------------------------------------------------------
//	^1[FL]^7Blind^4man	16 October 2010	Initial Script
//
//==========================================================================================
//

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

	Axis_Transmission_Radio_Dyno = 0,
	Axis_base_gate_Dyno = 0,
	Command_Post_Dyno = 0,
	axis_basement_MG_Gun_Dyno = 0,
	beach_bunker_door_Dyno = 0,
	bunker_door_Dyno = 0,
	canyon_bunker_MG42_gun_Dyno = 0,
	power_generator_Dyno = 0,

	Plant_Power_Generator = "PLANT_power_generator",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_beach_bunker = "PLANT_beach_bunker_door",
	Callarty1 = "CALLARTILLERY_axis1",



	TriggerOne =
	{
		Name = "TriggerOne =",
		TriggerOnClass = CLASS.COVERTOPS,
		OnEnter = function(ent)
		{
			if ( GetEntTeam(ent) == TEAM.ALLIES)
			{
				Util.EnableGroup("axis2", TEAM.AXIS);
				Util.EnableGroup("axis3", TEAM.AXIS);
				Util.DisableGroup("axis1", TEAM.AXIS);
				SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_.*" );
				Util.ChangeClass( TEAM.AXIS, CLASS.SOLDIER, CLASS.ENGINEER, false, 1 );
				Util.ChangeSpawn(TEAM.AXIS, 4, 9);
				Util.MapDebugPrint( "Covie shift" );
			}
		},
	},

	TriggerTwo =
	{
		Name = "TriggerTwo =",
		TriggerOnClass = CLASS.COVERTOPS,
		OnEnter = function(ent)
		{
			if ( GetEntTeam(ent) == TEAM.ALLIES)
			{
				Util.EnableGroup("axis2", TEAM.AXIS);
				Util.EnableGroup("axis3", TEAM.AXIS);
				Util.DisableGroup("axis1", TEAM.AXIS);
				SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_.*" );
				Util.ChangeSpawn(TEAM.AXIS, 4, 9);
				Util.MapDebugPrint( "Covie shift_b" );
			}
		},
	},

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

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

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

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

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

	Axis_Transmission_Radio_Planted = function( trigger )
	{
		Map.Axis_Transmission_Radio_Dyno += 1;
		Util.MapDebugPrint( "Axis_Transmission_Radio_Planted" );
	},

	Axis_base_gate_Planted = function( trigger )
	{
		Map.Axis_base_gate_Dyno += 1;
		Util.MapDebugPrint( "Axis_base_gate_Planted" );
	},

	Command_Post_Planted = function( trigger )
	{
		Map.Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Command_Post_Planted" );
	},

	axis_basement_MG_Gun_Planted = function( trigger )
	{
		Map.axis_basement_MG_Gun_Dyno += 1;
		Util.MapDebugPrint( "axis_basement_MG_Gun_Planted" );
	},

	beach_bunker_door_Planted = function( trigger )
	{
		Map.beach_bunker_door_Dyno += 1;
		Util.MapDebugPrint( "beach_bunker_door_Planted" );
	},

	bunker_door_Planted = function( trigger )
	{
		Map.bunker_door_Dyno += 1;
		Util.MapDebugPrint( "bunker_door_Planted" );
	},

	canyon_bunker_MG42_gun_Planted = function( trigger )
	{
		Map.canyon_bunker_MG42_gun_Dyno += 1;
		Util.MapDebugPrint( "canyon_bunker_MG42_gun_Planted" );
	},

	power_generator_Planted = function( trigger )
	{
		Util.DisableGroup( "cp");
		Map.power_generator_Dyno += 1;
		Util.MapDebugPrint( "power_generator_Planted" );
	},

	Axis_Transmission_Radio_Defused = function( trigger )
	{
		Map.Axis_Transmission_Radio_Dyno -= 1;
		Util.MapDebugPrint( "Axis_Transmission_Radio_Defused" );
	},

	Axis_base_gate_Defused = function( trigger )
	{
		Map.Axis_base_gate_Dyno -= 1;
		Util.MapDebugPrint( "Axis_base_gate_Defused" );
	},

	Command_Post_Defused = function( trigger )
	{
		Map.Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Command_Post_Defused" );
	},

	axis_basement_MG_Gun_Defused = function( trigger )
	{
		Map.axis_basement_MG_Gun_Dyno -= 1;
		Util.MapDebugPrint( "axis_basement_MG_Gun_Defused" );
	},

	beach_bunker_door_Defused = function( trigger )
	{
		Map.beach_bunker_door_Dyno -= 1;
		Util.MapDebugPrint( "beach_bunker_door_Defused" );
	},

	bunker_door_Defused = function( trigger )
	{
		Map.bunker_door_Dyno -= 1;
		Util.MapDebugPrint( "bunker_door_Defused" );
	},

	canyon_bunker_MG42_gun_Defused = function( trigger )
	{
		Map.canyon_bunker_MG42_gun_Dyno -= 1;
		Util.MapDebugPrint( "canyon_bunker_MG42_gun_Defused" );
	},

	power_generator_Defused = function( trigger )
	{
		Map.power_generator_Dyno -= 1;
		Util.MapDebugPrint( "power_generator_Defused" );
	},

	Axis_Transmission_Radio_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "MOBILEMG42_radio1" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_radio.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_radio.*" );

		Map.Axis_Transmission_Radio_Dyno = 0;

		Util.MapDebugPrint( "Axis_Transmission_Radio_Destroyed" );
	},

	Axis_base_gate_Destroyed = function( trigger )
	{
		Util.DisableGroup( "allies1", TEAM.ALLIES);
		Util.DisableGroup( "axis1", TEAM.AXIS);
		Util.EnableGroup( "allies2", TEAM.ALLIES);
		Util.EnableGroup( "axis2", TEAM.AXIS);
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"PLANT_power_generator",
			"PLANT_Axis_Transmission_Radio",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_beach_bunker_door" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"PLANT_bunker_door",
			"BUILD_Command_Post",
		});

		Map.Axis_base_gate_Dyno = 0;

		Util.MapDebugPrint( "Axis_base_gate_Destroyed" );
	},

	Command_Post_Destroyed = function( trigger )
	{
		Map.Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

	axis_basement_MG_Gun_Destroyed = function( trigger )
	{
		Map.axis_basement_MG_Gun_Dyno = 0;

		Util.MapDebugPrint( "axis_basement_MG_Gun_Destroyed" );
	},

	beach_bunker_door_Destroyed = function( trigger )
	{
		Map.beach_bunker_door_Dyno = 0;

		Util.MapDebugPrint( "beach_bunker_door_Destroyed" );
	},

	bunker_door_Destroyed = function( trigger )
	{
		Util.DisableGroup( "allies1", TEAM.ALLIES);
		Util.DisableGroup( "axis1", TEAM.AXIS);
		Util.EnableGroup( "allies2", TEAM.ALLIES);
		Util.EnableGroup( "axis2", TEAM.AXIS);
		Util.EnableGroup( "cp");
		//	Server.MinClassCount[TEAM.AXIS][CLASS.ENGINEER] = 3;
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"PLANT_power_generator",
			"PLANT_Axis_Transmission_Radio",
			"BUILD_Command_Post",
			"PLANT_Axis_base_gate",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_beach_bunker_door" );

		Map.bunker_door_Dyno = 0;

		Util.MapDebugPrint( "bunker_door_Destroyed" );
	},

	canyon_bunker_MG42_gun_Destroyed = function( trigger )
	{
		Map.canyon_bunker_MG42_gun_Dyno = 0;

		Util.MapDebugPrint( "canyon_bunker_MG42_gun_Destroyed" );
	},

	power_generator_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOBILEMG42_gen.*",
			"DEFEND_gen.*",
			"PLANTMINE_.*",
		});
		Util.EnableGroup( "axis55", TEAM.AXIS);
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_gen.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOUNTMG42_mg2gun",
			"BUILD_axis_basement_MG_Gun",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "EXPLODE_axis_basement_MG_Gun" );
		Util.ChangeSpawn(TEAM.AXIS, 2, 4);
		Util.ChangeSpawn(TEAM.AXIS, 1, 5);

		Map.power_generator_Dyno = 0;

		Util.MapDebugPrint( "power_generator_Destroyed" );
	},

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

	oldcityflag_Allies_Captured = function( trigger )
	{
		Util.ChangeSpawn(TEAM.AXIS, 4, 3);

		rnd = RandInt(1,4);
		if ( rnd == 1 )
		{
			Util.SetGoalPosition( 6187.5, 1763.04, 1096.125, Map.Plant_Power_Generator );
		}
		else if ( rnd == 2 )
		{
			Util.SetGoalPosition( 6135.93, 1971.6, 912.125, Map.Plant_Power_Generator );
		}
		else if ( rnd == 3 )
		{
			Util.SetGoalPosition( 6239.6, 1677.87, 912.125, Map.Plant_Power_Generator );
		}
		else
		{
			Util.SetGoalPosition( 6418.128, 1852.05, 912.125, Map.Plant_Power_Generator );
		}

		Util.MapDebugPrint( "oldcityflag_Allies_Captured" );
	},
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "MISSING_STRING", Map.Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.axis_basement_MG_Gun_Built );
	OnTrigger( "MISSING_STRING", Map.axis_basement_MG_Gun_1_Built );
	OnTrigger( "MISSING_STRING", Map.canyon_bunker_MG42_gun_Built );
	OnTrigger( "MISSING_STRING", Map.main_bunker_MG42_gun_Built );
	OnTrigger( "Planted at the Axis base gate.", Map.Axis_base_gate_Planted );
	OnTrigger( "Planted at the beach bunker door.", Map.beach_bunker_door_Planted );
	OnTrigger( "Planted at the bunker door.", Map.bunker_door_Planted );
	OnTrigger( "Planted at the power generator.", Map.power_generator_Planted );
	OnTrigger( "Defused at the Axis base gate.", Map.Axis_base_gate_Defused );
	OnTrigger( "Defused at the bunker door.", Map.bunker_door_Defused );
	OnTrigger( "Defused at the power generator.", Map.power_generator_Defused );
	OnTrigger( "Axis have destroyed the radio equipment", Map.Axis_Transmission_Radio_Destroyed );
	OnTrigger( "Allies have breached axis base main gate!", Map.Axis_base_gate_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Destroyed );
	OnTrigger( "MISSING_STRING", Map.axis_basement_MG_Gun_Destroyed );
	OnTrigger( "Allies have blown the lower beach bunker door!", Map.beach_bunker_door_Destroyed );
	OnTrigger( "Allies have blown the main beach bunker door!", Map.bunker_door_Destroyed );
	OnTrigger( "MISSING_STRING", Map.canyon_bunker_MG42_gun_Destroyed );
	OnTrigger( "Allies have destroyed the power generator", Map.power_generator_Destroyed );
	OnTrigger( "Axis reclaim the forward spawn!", Map.oldcityflag_Axis_Captured );
	OnTrigger( "Allies capture the forward spawn!", Map.oldcityflag_Allies_Captured );

	cellar = OnTriggerRegion(AABB(2140.69,-528.873,609.125,2280.875,-319.127,683.125), Map.TriggerOne);
	backdoor = OnTriggerRegion(AABB(2959.126,1766.493,937.125,3115.884,1952.875,1011.125), Map.TriggerTwo);

	// cs: these can be removed after the goals have been saved once ...
	Util.SetGroup( "ATTACK_flag1", "allies1");
	Util.SetGroup( "ATTACK_flag10", "allies1");
	Util.SetGroup( "ATTACK_flag2", "allies1");
	Util.SetGroup( "ATTACK_flag3", "allies1");
	Util.SetGroup( "ATTACK_flag9", "allies1");
	Util.SetGroup( "PLANT_Axis_base_gate", "allies1");
	Util.SetGroup( "PLANT_bunker_door", "allies1");
	Util.SetGroup( "PLANT_beachdoor", "allies1");
	Util.SetGroup( "MOBILEMORTAR_al1", "");
	Util.SetGroup( "MOBILEMORTAR_al4", "");
	Util.SetGroup( "MOBILEMORTAR_al5", "allies1");
	Util.SetGroup( "MOBILEMORTAR_al6", "allies1");
	Util.SetGroup( "SNIPE_tower1", "allies1");
	Util.SetGroup( "PLANT_Axis_Transmission_Radio", "allies2");
	Util.SetGroup( "PLANT_power_generator", "allies2");
	Util.SetGroup( "ATTACK_gen2", "allies2");
	Util.SetGroup( "ATTACK_gen3", "allies2");
	Util.SetGroup( "AIRSTRIKE_allies1", "allies2");
	Util.SetGroup( "AIRSTRIKE_axis2", "axis1");
	Util.SetGroup( "CALLARTILLERY_axis1", "axis1");
	Util.SetGroup( "CALLARTILLERY_axis2", "axis1");
	Util.SetGroup( "ARTILLERY_S_axis1", "axis1");
	Util.SetGroup( "DEFEND_flag1", "axis1");
	Util.SetGroup( "DEFEND_flag2", "axis1");
	Util.SetGroup( "DEFEND_flag3", "axis1");
	Util.SetGroup( "DEFEND_flag4", "axis1");
	Util.SetGroup( "DEFEND_flag6", "axis1");
	Util.SetGroup( "DEFEND_gen1", "axis2");
	Util.SetGroup( "DEFEND_gen2", "axis2");
	Util.SetGroup( "DEFEND_gen3", "axis2");
	Util.SetGroup( "DEFEND_gen4", "axis2");
	Util.SetGroup( "DEFEND_radio3", "axis2");
	Util.SetGroup( "DEFEND_radio4", "axis2");
	Util.SetGroup( "DEFEND_radio5", "axis2");
	Util.SetGroup( "DEFEND_radio6", "axis2");
	Util.SetGroup( "DEFEND_radio98", "axis2");
	Util.SetGroup( "DEFEND_radio99", "axis2");
	Util.SetGroup( "MOBILEMG42_gen1", "axis2");
	Util.SetGroup( "MOBILEMG42_gen2", "axis2");
	Util.SetGroup( "MOBILEMG42_radio1", "axis2");
	Util.SetGroup( "MOBILEMG42_axis44", "axis2");
	Util.SetGroup( "PLANTMINE_g3", "axis55");
	Util.SetGroup( "PLANTMINE_g4", "axis55");
	Util.SetGroup( "PLANTMINE_g5", "axis55");
	Util.SetGroup( "CHECKPOINT_oldcityflag", "flag");
//	Util.SetGroup( "PLANTMINE_g6", "axis55");

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

	Util.EnableGroup( "allies1", TEAM.ALLIES);
	Util.EnableGroup( "axis1", TEAM.AXIS);
	Util.EnableGroup( "axis_cab", TEAM.AXIS);
	Util.EnableGroup( "cabs1");
	Util.EnableGroup( "flag");

	Util.LimitToClass("PLANT_Command_Post", 0, CLASS.COVERTOPS);
	Util.LimitToClass("PLANT_beachdoor", TEAM.ALLIES, CLASS.COVERTOPS);
	SetGoalPriority( "PLANT_beachdoor", 0.99, 0, CLASS.COVERTOPS );

	// Max users per goal
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "BUILD_.*" );
	Util.SetMaxUsers( 1, "REPAIR.*" );
	Util.SetMaxUsers( 1, "PLANT_Command_Post" );
	Util.SetMaxUsers( 1, "PLANT_beach_bunker_door" );
	Util.SetGoalPosition( 4416.66, -893.874, 1072.125, Map.Plant_Command_Post );
	Util.SetGoalPosition( -583.4, -2006.5, 696.125, Map.Plant_beach_bunker );
//	Util.SetGoalPosition( 1883.749, -277.636, 1048.125, Map.Callarty1 );


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

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 300.0;
	bot.MaxViewDistance = 2400;
};
