//==========================================================================================
//
//	uje_christmas_tank.gm
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	^4Tardis	15 December 2014	Update Script
//
//==========================================================================================
//

global Map =
{
	Debug = 1, // please set to zero before distributing your script
	
	Movers =
	{
		"MOVER_tank",
		"MOVER_truck",
		"MOVER_achtbaan",
	},
	
	Ammo_Cabinet_north_ammocabinet = "AMMOCAB_north_ammocabinet",
	Ammo_Cabinet_north_ammocabinet_1 = "AMMOCAB_north_ammocabinet_1",
	Ammo_Cabinet_north_ammocabinet_2 = "AMMOCAB_north_ammocabinet_2",
	Health_Cabinet_north_healthcabinet = "HEALTHCAB_north_healthcabinet",
	Health_Cabinet_north_healthcabinet_1 = "HEALTHCAB_north_healthcabinet_1",
	Health_Cabinet_north_healthcabinet_2 = "HEALTHCAB_north_healthcabinet_2",
	Build_Allied_Command_Post = "BUILD_Allied_Command_Post",
	Build_Axis_Command_Post = "BUILD_Axis_Command_Post",
	Build_Axis_MG42 = "BUILD_Axis_MG42",
	Build_Tank = "BUILD_Tank",
	Plant_Allied_Command_Post = "PLANT_Allied_Command_Post",
	Plant_Axis_Command_Post = "PLANT_Axis_Command_Post",
	Plant_Axis_MG42 = "PLANT_Axis_MG42",
	Plant_Axis_Presents = "PLANT_Axis_Presents",
	Mount_Axis_MG42 = "MOUNTMG42_Axis_MG42",
	Repair_Axis_MG42 = "REPAIRMG42_Axis_MG42",
	Snipe_194 = "SNIPE_194",
	Snipe_195 = "SNIPE_195",
	Snipe_199 = "SNIPE_199",
	Snipe_201 = "SNIPE_201",
	Snipe_224 = "SNIPE_224",
	Snipe_230 = "SNIPE_230",
	Snipe_248 = "SNIPE_248",
	Snipe_272 = "SNIPE_272",
	Snipe_322 = "SNIPE_322",
	Snipe_401 = "SNIPE_401",
	Snipe_410 = "SNIPE_410",
	Mover_tank = "MOVER_tank",
	Mover_truck = "MOVER_truck",
	
	Allied_Command_Post_Dyno = 0,
	Axis_Command_Post_Dyno = 0,
	Axis_MG42_Dyno = 0,
	Axis_Presents_Dyno = 0,
	r1Pos = 0,

	r1 =
	{
		Name = "r1",
		TriggerOnEntity = GetGoal("MOVER_achtbaan").GetEntity(),
		OnEnter = function(ent)
		{
			Map.r1Pos = 1;
			Map.Switches.ride1.Enabled = false;
			Wp.SetWaypointFlag( "car", "closed", true );
			if ( Map.Debug )
				{ Util.MapDebugPrint( "^3r1 ready" ); }
		},
		OnExit = function(ent) { Map.r1Pos = -1; },

	},

	r2 =
	{
		Name = "r2",
		TriggerOnEntity = GetGoal("MOVER_achtbaan").GetEntity(),
		OnEnter = function(ent)
		{
			Map.r1Pos = 1;
			Map.Switches.ride1.Enabled = true;
			Wp.SetWaypointFlag( "car", "closed", false );
			if ( Map.Debug )
				{ Util.MapDebugPrint( "^8car open" ); }
		},
		OnExit = function(ent) { Map.r1Pos = -1; },

	},

	mg1 =
	{
		Name = "mg1",
		TriggerOnEntity = GetGoal("MOVER_tank").GetEntity(),
		OnEnter = function(ent)
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "MOBILEMG42_.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"MOUNTMG42_Axis_MG42",
				"DEFEND_def.*",
			});
			if ( Map.Debug )
				{ Util.MapDebugPrint( "^8mg spot on" ); }
		},

	},

	Switches =
	{
		ride1 =
		{
			WaypointName = "ride1",
			Enabled = true,
			LimitBots = 1,
			LimitTeam = (1<<TEAM.ALLIES), //only axis can use it
			LimitClass = (1<<CLASS.COVERTOPS) | (1<<CLASS.FIELDOPS), //only engineers can use it
			ExitConditions =
			{
			 someFunc = function(bot)
			 {
				return true; //as soon as they hit switch, return true
			 },
			},
		},
	},
	

	Allied_Command_Post_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_Command_Post");
		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},

	Axis_Command_Post_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Command_Post");
		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

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

	Tank_Built = function( trigger )
	{
		Util.MapDebugPrint( "Tank_Built" );
	},
	
	Tank_damaged = function( trigger )
	{
		Util.SetPositionGoal( Map.Build_Tank, Map.Mover_tank );
		Util.MapDebugPrint( "tank damaged" );
	},
	
	Allied_Command_Post_Planted = function( trigger )
	{
		Map.Allied_Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Allied_Command_Post_Planted" );
	},

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

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

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

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

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

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

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

	Allied_Command_Post_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_Command_Post");
		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},

	Axis_Command_Post_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_Command_Post");
		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

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

	Axis_Presents_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Axis_Presents_Destroyed" );
	},
	
	wall_blown = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_presents.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_MG42" );
		
		Util.EnableGoal("ATTACK_.*"); //enables for both teams

		Util.MapDebugPrint( "wall blown" );
	},

	wall2_blown = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "ESCORT_tank" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_presents.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"DEFEND_presents.*",
			"PLANT_Axis_Presents",
		});
//~		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
//~		SetAvailableMapGoals( TEAM.ALLIES, false, "MOVER_tank" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_def.*" );
		Wp.SetWaypointFlag( "rider", "closed", false );
		Util.ShowActiveGoals ();
		SetAvailableMapGoals( TEAM.AXIS, false, "MOVER_tank.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
		SetAvailableMapGoals( TEAM.AXIS, false, "Allied_Command_Post" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "Axis_Command_Post" );
		Util.MapDebugPrint( "wall2 blown" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "Axis Team have built the MG42!!", Map.Axis_MG42_Built );
	OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "Planted at the Allied Command Post.", Map.Allied_Command_Post_Planted );
	OnTrigger( "Planted at the Axis Command Post.", Map.Axis_Command_Post_Planted );
	OnTrigger( "Planted at the Axis MG42", Map.Axis_MG42_Planted );
	OnTrigger( "Planted at the Axis Presents", Map.Axis_Presents_Planted );
	OnTrigger( "Defused at the Allied Command Post.", Map.Allied_Command_Post_Defused );
	OnTrigger( "Defused at the Axis Command Post.", Map.Axis_Command_Post_Defused );
	OnTrigger( "Defused at the Axis MG42", Map.Axis_MG42_Defused );
	OnTrigger( "Defused at the Axis Presents.", Map.Axis_Presents_Defused );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "Allies have destroyed the MG42!!", Map.Axis_MG42_Destroyed );
	OnTrigger( "Allies have destroyed the Axis Radio", Map.Axis_Presents_Destroyed );
	OnTrigger( "The Tank has been damaged!", Map.Tank_damaged );
	OnTrigger( "Allied team has broken into the building!", Map.wall_blown);
	OnTrigger( "Allied team has blown thru the Wall!", Map.wall2_blown);

	//~Util.DisableGoal( ".*", true ); // all but routes
	//~SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_.*" );
	//~SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );
	
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"SNIPE_.*",
		"PLANT_Allied_Command_Post",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"SNIPE_.*",
		"PLANT_Axis_Presents",
		"MOUNTMG42_Axis_MG42",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, "MOUNTMG42_Axis_MG42" );
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"PLANT_Axis_Command_Post",
		"PLANT_Axis_MG42",
		"PLANT_Axis_Presents",
	});
	Util.DisableGoal("ATTACK_.*"); //enables for both teams
//~	Util.DisableGoal("MOVER_atrein.*"); //enables for both teams
	Util.DisableGoal("MOVER_truck.*"); //enables for both teams
	Util.DisableGoal("MOVER_damage.*"); //enables for both teams
	Util.DisableGoal("MOBILEMG42_.*"); //enables for both teams
	Util.DisableGoal("DEFEND_def.*"); //enables for both teams

	SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_presents.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_presents.*" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 1, "ATTACK_.*" );
	Util.SetMaxUsersInProgress( 1, "MOUNTMG42_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "MOVER_tank.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank" );
//~	Util.LimitToClass("PLANT_Axis_MG42" , TEAM.ALLIES, CLASS.COVERTOPS);
	Wp.SetWaypointFlag( "rider", "closed", true );


	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=45, MaxCampTime=90} );
	SetMapGoalProperties( "MOUNT_.*", {MinCampTime=30, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=90, MaxCampTime=90} );
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=90, MaxCampTime=90} );
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=45, MaxCampTime=90} );
//~	SetGoalPriority( "MOVER_tank", 0.99, TEAM.ALLIES, 0 );

	r1 = OnTriggerRegion(AABB(-9699.497,5837.3,319.125, -9471.125, 5877, 393.125), Map.r1);
	r2 = OnTriggerRegion(AABB(-9467.407,5150.3,303.125, -9346.425, 5418.4, 377.125), Map.r2);
	mg1 = OnTriggerRegion(AABB(-9600.9,8821.6,-0.875, -9160, 8918.6, 73.125), Map.mg1);


	Util.ShowActiveGoals();
	Util.UpdateSwitchData();

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

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


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

global OnBotJoin = function( bot )
{
	// Uncomment for shootable breakables
	bot.TargetBreakableDist = 400;
	// Only set MaxViewDistance on maps with limited sight (e.g. fog)
	//~bot.MaxViewDistance = 2400;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_Allied_Command_Post =
		{
		},
		PLANT_Allied_Command_Post =
		{
		},
		BUILD_Axis_Command_Post =
		{
		},
		PLANT_Axis_Command_Post =
		{
		},
		BUILD_Axis_MG42 =
		{
		},
		PLANT_Axis_MG42 =
		{
		},
		BUILD_Tank =
		{
		},
		PLANT_Axis_Presents =
		{
		},
	};
	Util.Routes(MapRoutes);
};
