//==========================================================================================
//
//	alcazaba_assault.gm
//
//	Who                   	When		What
//------------------------------------------------------------------------------------------
//	^1T^3N^1T^4|^1*^8Cinco^1*	08 September 2011	Initial Script
// palota                   	10 September 2015	new script, GRENADE_grate, MOUNT_Tank
//
//==========================================================================================
//

global Map =
{
	// Conditionals
	Command_Post_Status = 0, // 0 = neutral, 1 = Axis, 2 = Allies
	FieldRadio_Destroyed = true,
	Safe_Destroyed = false,

	// Tank Positions
	Tank_Near_BarrierOne = false,
	Tank_Near_BarrierTwo = false,
	Tank_Near_BunkerDoor = false,

	Allied_Command_Post_Built = function()
	{
		Map.Command_Post_Status = 2;

		if ( Map.Tank_Near_BunkerDoor) {
			Util.ChangeSpawn( TEAM.ALLIES, 3 );
		}

		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},

	Axis_Command_Post_Built = function()
	{
		Map.Command_Post_Status = 1;

		Util.ChangeSpawn( TEAM.AXIS, 7 );

		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

	Allied_Command_Post_Destroyed = function()
	{
		Map.Command_Post_Status = 0;
		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},

	Axis_Command_Post_Destroyed = function()
	{
		Map.Command_Post_Status = 0;
		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

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

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

	Tank_At_Barrier_1 = function()
	{
		Map.Tank_Near_BarrierOne = true;

		SetAvailableMapGoals( TEAM.ALLIES, false, ".*Allies_Ambush.*" );

		SetGoalPriority("PLANT_Tank_Barrier_1", 0.95);

		Util.MapDebugPrint( "Tank_At_Barrier_1" );
	},

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

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

	Tank_Barrier_1_Lost = function()
	{
		Util.ChangeSpawn( TEAM.ALLIES, 6 );

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"BUILD_Tank_Barrier_1",
			".*_Allies_BarrierOne.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Tank_Barrier_2",
			".*_Allies_BarrierTwo.*",
			"BUILD_Allied_MG",
			"MOUNTMG42_Allied_MG",
			"REPAIRMG42_Allied_MG",
		});

		SetAvailableMapGoals( TEAM.AXIS, false, ".*_Axis_BarrierOne.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"PLANT_Tank_Barrier_2",
			".*_Axis_BarrierTwo.*",
			"PLANT_Allied_MG",
			".*_Command_Post",
		});

		Util.OnTriggerPosition("MOVER_tank", Vec3(551.415, -4944.015, 952.125), 200.0, Map.Tank_At_Barrier_2);

		Util.MapDebugPrint( "Tank_Barrier_1_Lost" );
	},

	Tank_At_Barrier_2 = function()
	{
		Map.Tank_Near_BarrierTwo = true;

		SetGoalPriority("PLANT_Tank_Barrier_2", 0.95);
		SetGoalPriority("BUILD_Command_Post", 0.95, TEAM.AXIS );
		SetGoalPriority("PLANT_Command_Post", 0.7, TEAM.ALLIES );

		Util.MapDebugPrint( "Tank_At_Barrier_2" );
	},

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

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

	Tank_Barrier_2_Lost = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"BUILD_Tank_Barrier_2",
			"BUILD_Allied_MG",
			"MOUNTMG42_Allied_MG",
			"REPAIRMG42_Allied_MG",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Field_Radio");

		SetAvailableMapGoals( TEAM.AXIS, false, {
			".*_Axis_BarrierTwo.*",
			"PLANT_Allied_MG",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Field_Radio");

		SetGoalPriority("BUILD_Command_Post", 0.9, TEAM.AXIS );
		SetGoalPriority("BUILD_Field_Radio", 0.7);

		Util.MapDebugPrint( "Tank_Barrier_2_Lost" );
	},

	Bunker_Door_Destroyed = function()
	{
		Map.Tank_Near_BunkerDoor = true;

		SetAvailableMapGoals( TEAM.ALLIES, false, ".*_Allies_BarrierTwo.*" );

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"BUILD_Tank",
			"MOUNT_Tank",
			"ESCORT_Tank",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Safe");

		Map.SetCap(false);

		Util.MapDebugPrint( "Bunker_Door_Destroyed" );
	},

	Safe_Destroyed = function()
	{
		Map.Safe_Destroyed = true;

		SetAvailableMapGoals( TEAM.AXIS, true, "FLAG_Das_Kochrezept");
		SetGoalPriority("BUILD_Field_Radio", 0.9);

		Util.MapDebugPrint( "Safe_Destroyed" );
	},

	Field_Radio_Built = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "CAPPOINT_FieldRadio" );

		Util.MapDebugPrint( "Field_Radio_Built" );
	},

	Field_Radio_Destroyed = function()
	{
		Map.FieldRadio_Destroyed = true;

		SetAvailableMapGoals( TEAM.AXIS, false, "CAPPOINT_FieldRadio");

		Util.MapDebugPrint( "Field_Radio_Destroyed" );
	},

	SetCap = function(b)
	{
		SetAvailableMapGoals( TEAM.ALLIES, !b, {
			".*_Allies_Guard.*",
			".*_Allies_Safe.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, b, ".*_Allies_FieldRadio.*" );

		SetAvailableMapGoals( TEAM.AXIS, !b, "DEFEND_Allies_Safe.*" );
		SetAvailableMapGoals( TEAM.AXIS, b, "ATTACK_Axis_FieldRadio" );
	},

	Das_Kochrezept_Taken = function()
	{
		Map.SetCap(true);
		Util.MapDebugPrint( "Das_Kochrezept_Taken" );
	},

	Das_Kochrezept_Returned = function()
	{
		Map.SetCap(false);
		Util.MapDebugPrint( "Das_Kochrezept_Returned" );
	},

	Das_Kochrezept_Secured = function() // Game Over
	{
		ETUtil.WinningChat( TEAM.AXIS );
		ETUtil.LosingChat( TEAM.ALLIES );
		Util.MapDebugPrint( "Das_Kochrezept_Secured" );
	},
};

global OnMapLoad = function()
{
	//OnTrigger( "^3Allied MG nest constructed!", Map.Allied_MG_Built );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!^3 CP Spawn act", Map.Allied_Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!^3 CP Spawn activ", Map.Axis_Command_Post_Built );
	OnTrigger( "^3The Axis Field Radio has been constructed.", Map.Field_Radio_Built );
	OnTrigger( "^3The Tank has been repaired!", Map.Tank_Built );
	//OnTrigger( "Axis team are driving with the Tank !", Map.Axis_Driving_Tank );
	OnTrigger( "^3The Tank has been damaged!", Map.Tank_Destroyed );
	OnTrigger( "^3Tank Barrier #1 has been constructed.", Map.Tank_Barrier_1_Built );
	OnTrigger( "^3Tank Barrier #2 has been constructed.", Map.Tank_Barrier_2_Built );
	//aOnTrigger( "^3Axis team has destroyed the Allied MG nest!", Map.Allied_MG_Destroyed );
	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( "^3Allies have destroyed the Axis Field Radio.", Map.Field_Radio_Destroyed );
	OnTrigger( "Axis have destroyed the ^3Safe Door^1 !", Map.Safe_Destroyed );
	OnTrigger( "^3Tank Barrier #1 has been destroyed.", Map.Tank_Barrier_1_Destroyed );
	OnTrigger( "^3Tank Barrier #2 has been destroyed.", Map.Tank_Barrier_2_Destroyed );
	OnTrigger( "^3The Tank is past the first Barrier!", Map.Tank_Barrier_1_Lost );
	OnTrigger( "^3The Tank is past the second Barrier!", Map.Tank_Barrier_2_Lost );
	OnTrigger( "^3 Axis have Destroyed the Bunker Door !", Map.Bunker_Door_Destroyed );
	OnTrigger( "Axis have stolen Das Kochrezept!", Map.Das_Kochrezept_Taken );
	OnTrigger( "Flag returned Das Kochrezept!", Map.Das_Kochrezept_Returned );
	OnTrigger( "axis_cap", Map.Das_Kochrezept_Secured );

	Util.DisableGoal( ".*", true );
	Util.EnableGoal("AMMOCAB.*");
	Util.EnableGoal("HEALTHCAB.*");

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"BUILD_Tank",
		"ESCORT_Tank",
		"MOUNT_Tank",
		"PLANT_Tank_Barrier_1",
		".*_Axis_BarrierOne.*",
		"GRENADE_grate",
	});

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"BUILD_Tank_Barrier_1",
		".*_Allies_BarrierOne.*",
		".*_Command_Post",
	});

	SetGoalPriority( "BUILD_Tank_Barrier_1", 0.95 );
	SetGoalPriority( "PLANT_Allied_MG", 0.7 );
	SetGoalPriority( "DEFUSE_Command_Post.*", 0.9, TEAM.ALLIES, CLASS.ENGINEER, true );
	SetGoalPriority( "DEFUSE_Tank_Barrier_1.*", 0, TEAM.ALLIES, CLASS.ENGINEER, true );

	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsersInProgress( 9, "ATTACK_Axis_FieldRadio");

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

	Util.OnTriggerPosition("MOVER_tank", Vec3(-3939.172, -2346.723, 17.207), 200.0, Map.Tank_At_Barrier_1);

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