//==========================================================================================
//
//	Burg Rabenhorst (Final) - rabenhorst.gm
//
//	Who					When			What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Captain	11 April 2015	Initial Script
//
//==========================================================================================
//

global Map =
{
	Tank_Built = false,
	TankBarrier_Built = false,

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

	Command_Post_Defused = function()
	{
		Util.MapDebugPrint( "Command_Post_Defused", true );
	},

	Command_Post_Destroyed = function()
	{
		Util.MapDebugPrint( "Command_Post_Destroyed", true );
	},

	Command_Post_Planted = function()
	{
		Util.MapDebugPrint( "Command_Post_Planted", true );
	},

	Sturmleiter_Built = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Sturmleiter" );

		Util.MapDebugPrint( "Sturmleiter_Built" );
	},

	Tank_Built = function()
	{
		if ( Map.Tank_Built )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "ESCORT_.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank_.*" );
		}

		Util.MapDebugPrint( "Tank_Built" );
	},

	Tank_Construct_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ESCORT_tank_.*",
			"MOUNT_tank"
		});

		Util.MapDebugPrint( "Tank_Construct_Destroyed" );
	},

	 Allies_Steal_Tank = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Tank_Barrier",
			"AIRSTRIKE_Axis_.*"
		});

		Util.MapDebugPrint( "Allies_Steal_Tank " );
	},

	Tank_Barrier_Built = function()
	{
		Map.TankBarrier_Built = true;

		SetAvailableMapGoals( TEAM.AXIS, true, "PLANTMINE_Mine_1_.*" );

		Util.MapDebugPrint( "Tank_Barrier_Built" );
	},

	Explosive_Crates_Planted = function()
	{
		Util.MapDebugPrint( "Explosive_Crates_Planted", true );
	},

	Sturmleiter_Planted = function()
	{
		Util.MapDebugPrint( "Sturmleiter_Planted", true );
	},

	Tank_Barrier_Planted = function()
	{
		Util.MapDebugPrint( "Tank_Barrier_Planted", true );
	},

	Explosive_Crates_Defused = function()
	{
		Util.MapDebugPrint( "Explosive_Crates_Defused", true );
	},

	Sturmleiter_Defused = function()
	{
		Util.MapDebugPrint( "Sturmleiter_Defused", true );
	},

	Tank_Barrier_Defused = function()
	{
		Util.MapDebugPrint( "Tank_Barrier_Defused", true );
	},

	Explosive_Crates_Destroyed = function()
	{
		// From Explosive_Crates_Planted
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANT_Command_Post",
			"BUILD_Command_Post"
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_flag_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"PLANT_Command_Post",
			"BUILD_Command_Post",
			"ATTACK_castel_.*",
			"PLANT_Generator"
		});

		// ---

		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_castel_.*" );

		Util.MapDebugPrint( "Explosive_Crates_Destroyed" );
	},

	Generator_Built = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_doc_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_castel_.*",
			"MOBILEMG42_.*"
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"FLAG_.*",
			"ATTACK_doc_.*"
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Generator" );

		Util.MapDebugPrint( "Generator_Built" );
	},

	Generator_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "MOBILEMG42_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Generator",
			"DEFEND_doc_.*",
			"DEFEND_castel_.*"
		});

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"FLAG_.*",
			"ATTACK_doc_.*"
		});

		Util.MapDebugPrint( "Generator_Destroyed" );
	},

	Generator_Planted = function()
	{
		Util.MapDebugPrint( "Generator_Planted", true );
	},

	Generator_Defused = function()
	{
		Util.MapDebugPrint( "Generator_Defused", true );
	},

	Sturmleiter_Destroyed = function()
	{
		Util.MapDebugPrint( "Sturmleiter_Destroyed", true );
	},

	Tank_Barrier_Destroyed = function()
	{
		Map.TankBarrier_Built = false;

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_tank",
			"ESCORT_tank",
			"MOVER_tank"
		});

		Util.MapDebugPrint( "Tank_Barrier_Destroyed" );
	},

	secret_Documents_Taken = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_castel_.*",
			"FLAG_.*"
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ATTACK_flag_.*",
			"CAPPOINT_Doc"
		});

		Util.MapDebugPrint( "secret_Documents_Taken" );
	},

	secret_Documents_Returned = function()
	{
		 Util.MapDebugPrint( "secret_Documents_Returned", true );
	},

	secret_Documents_Secured = function()
	{
		Util.MapDebugPrint( "secret_Documents_Secured", true );
	},

	depot_flag_Axis_Captured = function()
	{
		Util.MapDebugPrint( "depot_flag_Axis_Captured", true );
	},

	Blow_Doors = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_flag_.*",
			"CALLARTILLERY_defend_.*",
			"MOUNTMG42_159",
			"REPAIRMG42_159"
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"PLANTMINE_Mine_2_.*",
			"DEFEND_castel_.*",
			"MOBILEMORTAR_.*",
			"MOBILEMG42_.*"
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"BUILD_Tank",
			"ESCORT_tank",
			"MOVER_tank"
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Sturmleiter",
			"PLANT_Explosive_Crates"
		});

		Util.MapDebugPrint( "blow_doors" );
	},

	depot_flag_Allies_Captured = function()
	{
		Util.MapDebugPrint( "depot_flag_Allies_Captured", true );
	},

	tank_middle_barrier = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "AIRSTRIKE_Axis_.*" );

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ATTACK_tank_a.*",
			"SMOKEBOMB_.*"
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_tank_b.*" );

		Util.MapDebugPrint("tank_middle_barrier");
	},

	tank_at_barrier = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "CALLARTILLERY_Tank_.*" );

		if ( Map.TankBarrier_Built )
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, {
				"BUILD_tank",
				"ESCORT_tank",
				"MOVER_tank"
			});
		}

		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Tank_Barrier" );

		Util.MapDebugPrint("tank_at_barrier");
	},

	tank_pass_b = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"CALLARTILLERY_Tank_.*",
			"MOUNTMG42_70",
			"REPAIRMG42_70",
			"DEFEND_barrier_a.*",
			"BUILD_Tank_Barrier",
			"PLANTMINE_Mine_1_.*"
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_flag_.*" );

		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_tank_b.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CHECKPOINT_.*",
			"ATTACK_flag_.*"
		});

		Util.MapDebugPrint("tank_pass_b");
	},

	tank_goto_flag = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "CALLARTILLERY_defend_.*" );

		Util.MapDebugPrint("tank_goto_flag");
	},

	tank_at_castel = function()
	{
		Util.MapDebugPrint( "tank_at_castel", true );
	},

	vehicle_at_location = function()
	{
		switch( Map.VehicleLocation )
		{
			case 1:
			{
				Map.tank_middle_barrier();
			}
			case 2:
			{
				Map.tank_at_barrier();
			}
			case 3:
			{
				Map.tank_pass_b();
			}
			case 4:
			{
				Map.tank_goto_flag();
			}
			case 5:
			{
				Map.tank_at_castel();
			}
		}
	}
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied team has destroyed the Upper Castle Doors!", Map.Blow_Doors );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "Planted at the Command Post.", Map.Command_Post_Planted );
	OnTrigger( "Axis have constructed the Door Controls Generator!", Map.Generator_Built );
	OnTrigger( "MISSING_STRING", Map.Sturmleiter_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Sturmleiter_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Sturmleiter_Defused );
	OnTrigger( "MISSING_STRING", Map.Sturmleiter_Destroyed );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Construct_Destroyed );
	OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "Allied team has stolen the Tank!", Map.Allies_Steal_Tank );
	OnTrigger( "Tank Barrier has been constructed.", Map.Tank_Barrier_Built );
	OnTrigger( "Planted at the Explosive Crates.", Map.Explosive_Crates_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Generator_Planted );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Tank_Barrier_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Explosive_Crates_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Generator_Defused );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Tank_Barrier_Defused );
	OnTrigger( "the Explosive Crates Destroyed.", Map.Explosive_Crates_Destroyed );
	OnTrigger( "Allied team has destroyed the Door Controls Generator!", Map.Generator_Destroyed );
	OnTrigger( "Tank Barrier has been destroyed.", Map.Tank_Barrier_Destroyed );
	OnTrigger( "Allies have stolen The secret Documents!", Map.secret_Documents_Taken );
	OnTrigger( "^5Axis have returned the objective!", Map.secret_Documents_Returned );
	OnTrigger( "Axis reclaim the Forward Bunker!", Map.depot_flag_Axis_Captured );
	OnTrigger( "Allies capture the Forward Bunker!", Map.depot_flag_Allies_Captured );

	OnTrigger( "tank at location", Map.vehicle_at_location );

	Middleb = OnTriggerRegion(AABB(-869.993,-4873.011,489.036,-582.940,-4813.736,570.537), RegionTrigger.VehicleTrigger);
	Tankatbarrier = OnTriggerRegion(AABB(-30.730,-7168.875,641.125,178.147,-6769.316,715.125), RegionTrigger.VehicleTrigger);
	Tankpassb = OnTriggerRegion(AABB(412.619,-7137.944,641.125,450.753,-6841.284,715.125), RegionTrigger.VehicleTrigger);
	Tankatcastel = OnTriggerRegion(AABB(1669.398,-3495.485,953.232,1734.687,-3073.292,1031.233),RegionTrigger.VehicleTrigger);

	//Util.DisableGoal( ".*", true ); // all but routes
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"ATTACK_.*",
		"DEFEND_.*",
		"PLANTMINE_Mine_.*",
		"ESCORT_.*",
		"PLANT_.*",
		"AIRSTRIKE_.*",
		"CALLARTILLERY_.*",
		"MOBILEMORTAR_.*",
		"MOBILEMG42_.*"
	});
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_barrier_a.*" );

	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"DEFEND_.*",
		"ESCORT_.*",
		"BUILD_.*",
		"PLANT_.*",
		"CHECKPOINT_.*",
		"CAPPOINT_.*",
		"ATTACK_.*",
		"FLAG_.*"
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"BUILD_Tank",
		"ATTACK_tank_a.*"
	});

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

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

	// Axis goals
	SetGoalPriority( "BUILD_Tank_Barrier", 0.93, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Command_Post", 0.90, TEAM.AXIS, CLASS.ENGINEER );
	SetGoalPriority( "DEFEND_.*", 0.92, TEAM.AXIS, CLASS.MEDIC, CLASS.COVEROPS, CLASS.FIELDOPS, CLASS.SOLDIER );

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 100.0;
};
