//==========================================================================================
//
//	uje_halloween_d.gm
//
//	Who       	              When		                     What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Niek	    21 October 2016	                 Initial Script
//	^1[UJE]^3Captain	28 October 2016	              Attack/Defense/Improvements
//
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script
    Warehouse = true,
	Truck = true,
	Truckatb = false,
	Truckpasstb = false,
	EscapeCrate = false,

	Axis_Command_Post_Built = function( trigger )
	{
		if ( Map.Warehouse == true )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Axis_cp.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Axis_ware.*" );
	}

	if ( Map.Warehouse == false && Map.Truckatb  == true )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Axis_ware.*" );
	}
	if ( Map.EscapeCrate == true && Map.Truckpasstb  == true )
	{
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Axis_ware.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_Axis_cp.*",
		"DEFEND_Axis_tb.*",
	});
	}
    SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Command_Post" );

    SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Command_Post" );

	Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

	Allied_Command_Post_Built = function( trigger )
	{
		if ( Map.Warehouse == true )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Allies_cp.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"ATTACK_Allies_ware.*",
		"PLANT_warehouse_Entrance",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Axis_ware.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Axis_cp.*" );
	}
	if ( Map.Warehouse == false && Map.Truckatb  == true )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Allies_ware.*" );
	}
	if ( Map.EscapeCrate == true && Map.Truckpasstb  == true )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Allies_ware.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Allies_cp.*" );
	}

    SetAvailableMapGoals( TEAM.ALLIES, false, {
    	"BUILD_Command_Post",
    	"PLANT_Command_Post",
    });

	SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Command_Post" );


	Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},

	Axis_Command_Post_Destroyed = function( trigger )
	{

	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Command_Post" );

	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );

		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

	Allied_Command_Post_Destroyed = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Command_Post" );

	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
	if ( Map.Warehouse == true )
	    {
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"ATTACK_Allies_ware.*",
		"PLANT_warehouse_Entrance",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Allies_cp.*" );
	}

		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},


	Truck_Built = function( trigger )
	{
	Map.Truck = true;
	 SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_truck" );
		if ( Map.EscapeCrate == true )
	    {
	 SetAvailableMapGoals( TEAM.ALLIES, true, "ESCORT_truck" );
	 }

		Util.MapDebugPrint( "Truck_Built" );
	},

	Truck_Destroyed = function( trigger )
	{
	Map.Truck = false;
	 SetAvailableMapGoals( TEAM.ALLIES, false, "ESCORT_truck" );

	if ( Map.EscapeCrate == true )
	    {
     SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_truck" );

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

	Truck_Barrier_Built = function( trigger )
	{
	 SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Truck_Barrier" );
	if ( Map.EscapeCrate == true )
	    {
     SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Truck_Barrier" );
	 }
		Util.MapDebugPrint( "Truck_Barrier_Built" );
	},

	Truck_Barrier_Destroyed = function( trigger )
	{
    SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Truck_Barrier" );
	if ( Map.EscapeCrate == true )
	    {
     SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Truck_Barrier" );
	 }
		Util.MapDebugPrint( "Truck_Barrier_Destroyed" );
	},

	warehouse_Entrance_Destroyed = function( trigger )
	{
	Map.Warehouse = false;
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_Axis_gold.*",
		"BUILD_truck_barrier",
		"BUILD_Truck_Barrier",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Axis_ware.*" );

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"FLAG_gold_crate",
		"ATTACK_Allies_ware.*",
	});

		Util.EnableGoal( "AMMOCAB_uje3.*" );
		Util.EnableGoal( "HEALTHCAB_uje3.*" );
		Util.MapDebugPrint( "warehouse_Entrance_Destroyed" );
	},

	gold_crate1_Taken = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_truck1" );

		Util.MapDebugPrint( "gold_crate1_Taken" );
	},

	gold_crate1_Returned = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_truck1" );

		Util.MapDebugPrint( "gold_crate1_Returned" );
	},

	gold_crate1_Secured = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_truck1" );

		Util.MapDebugPrint( "gold_crate1_Secured" );
	},

	gold_crate2_Taken = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_truck2" );

		Util.MapDebugPrint( "gold_crate2_Taken" );
	},

	gold_crate2_Returned = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_truck2" );

		Util.MapDebugPrint( "gold_crate2_Returned" );
	},

	gold_crate2_Secured = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_truck2" );
		Util.MapDebugPrint( "gold_crate2_Secured" );
	},

	Escape_Part = function( trigger )
	{
	Map.EscapeCrate = true;
		if ( Map.Truck == true )
	    {
    SetAvailableMapGoals( TEAM.ALLIES, true, "ESCORT_truck" );
	 }
    SetAvailableMapGoals( TEAM.AXIS, true, {
    	"DEFEND_Axis_ware.*",
    	"DEFEND_Axis_tb.*",
    });
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Axis_gold.*" );

	SetAvailableMapGoals( TEAM.ALLIES, false, "FLAG_gold_crate" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_truck" );

		Util.MapDebugPrint( "Escape_Part" );
	},

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

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

	truck_at_barrier = function()
	{
	Map.Truckatb = true;
    SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Truck_Barrier" );

		Util.MapDebugPrint("truck_at_barrier");
	},

    truck_pass_tb = function()
	{
	Map.Truckpasstb = true;
	Map.Truckatb = false;
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"DEFEND_Axis_tb.*",
		"DEFEND_Axis_ware.*",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Axis_cp.*" );

	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Allies_cp.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Allies_ware.*" );
        Util.RemoveGoal( "BUILD_Truck_Barrier" );
		Util.MapDebugPrint("truck_pass_tb");
	},

	truck_at_corner = function()
	{
	Map.Truckpasstb = false;
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Axis_tb.*" );

	SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Allies_ware.*" );
		Util.MapDebugPrint("truck_at_corner");
	},

	truck_final = function()
	{
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Axis_cp.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Axis_final.*" );

    SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Allies_final.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Allies_cp.*" );

		Util.MapDebugPrint("truck_final");
	},
 vehicle_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
            Map.truck_at_barrier();
			}
			case 2:
			{
		    Map.truck_pass_tb();
			}
			case 3:
			{
			Map.truck_at_corner();
			}
			case 4:
			{
			Map.truck_final();
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},
};
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( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "The Truck has been repaired!", Map.Truck_Built );
	OnTrigger( "The Truck has been damaged!", Map.Truck_Destroyed );
	OnTrigger( "Truck Barrier #1 has been constructed.", Map.Truck_Barrier_Built );
	OnTrigger( "Truck Barrier #1 has been destroyed.", Map.Truck_Barrier_Destroyed );
	OnTrigger( "^1Allies have destroyed the Ghosthouse Entrance", Map.warehouse_Entrance_Destroyed );
	OnTrigger( "allies_firstradar_taken", Map.gold_crate1_Taken );
	OnTrigger( "allies_hq_radar1ret", Map.gold_crate1_Returned );
	OnTrigger( "Allied team has secured the first Halloween Part!", Map.gold_crate1_Secured );
	OnTrigger( "allies_secondradar_taken", Map.gold_crate2_Taken );
	OnTrigger( "allies_hq_radar2ret", Map.gold_crate2_Returned );
	OnTrigger( "Allied team has secured the second Halloween Part!", Map.gold_crate2_Secured );
	OnTrigger( "Allies capture the rendevezous point!", Map.bunker_flag_Axis_Captured );
	OnTrigger( "Axis capture the Rendevezous point!", Map.bunker_flag_Allies_Captured );
	OnTrigger( "Allied team is escaping with the Halloween Parts!", Map.Escape_Part );

	truckatb = OnTriggerRegion(AABB(-220.628,1628.415,-364.875,-126.434,1670.750,-290.875), RegionTrigger.VehicleTrigger);
	truckpasstb = OnTriggerRegion(AABB(-786.181,1326.807,-369.875,-732.743,1675.204,-290.875), RegionTrigger.VehicleTrigger);
	truckatcorner = OnTriggerRegion(AABB(-1119.946,243.361,-369.875,-831.722,281.437,-295.875), RegionTrigger.VehicleTrigger);
	truckfinal = OnTriggerRegion(AABB(464.461,-1027.611,-369.875,504.560,-884.860,-295.872), RegionTrigger.VehicleTrigger);
	OnTrigger( "truck at location", Map.vehicle_at_location );

	//~Util.DisableGoal( ".*", true ); // all but routes
	//Allies clear all goals
	SetAvailableMapGoals( TEAM.ALLIES, false, ".*" );
	//activation
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	"CHECKPOINT_bunker_flag",
    "BUILD_*_Command_Post",
	"ATTACK_Allies_cp_.*",
	"ROUTE_.*",

	});

	//Axis clear all goals
	SetAvailableMapGoals( TEAM.AXIS, false, ".*" );
	//activation
	SetAvailableMapGoals( TEAM.AXIS, true, {
	"BUILD_*_Command_Post",
	"DEFEND_Axis_cp_.*",
	"CHECKPOINT_Bunker_flag",

	});

	// Max users per goal
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 2, "BUILD_.*" );
	Util.SetMaxUsers( 2, "PLANT_.*" );
	Util.SetMaxUsers( 1, "ESCORT_.*" );
	Util.SetMaxUsers( 1, "CHECKPOINT_.*" );
	Util.SetMaxUsers( 1, "CAPPOINT_truck.*" );
	Util.SetMaxUsers( 4, "FLAG_gold_crate" );

	Util.SetMaxUsersInProgress( 1, "CHECKPOINT_.*" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 2, "PLANT_.*" );
	Util.SetMaxUsersInProgress( 4, "FLAG_gold_crate" );
	Util.SetMaxUsersInProgress( 1, "ATTACK_.*" );
	Util.SetMaxUsersInProgress( 1, "CAPPOINT_truck.*" );
	Util.SetMaxUsersInProgress( 2, "BUILD.*" );
	Util.SetMaxUsersInProgress( 1, "ESCORT_.*" );

	Util.EnableGoal( "AMMOCAB_ujes8_.*" );
	Util.EnableGoal( "HEALTHCAB_ujes8_.*" );
	// Camp times
    SetMapGoalProperties( "ATTACK_.*", {MinCampTime=20, MaxCampTime=60} );
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=20, MaxCampTime=60} );


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

global OnBotJoin = function( bot )
{
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		PLANT_warehouse_Entrance =
		{
		},
		FLAG_gold_crate =
		{
		},
		CHECKPOINT_bunker_flag =
		{
			ROUTE_Spawn_3  =
			{
				ROUTE_cap_flag_1  =
				{
					ROUTE_cp_north_1  =
					{
					},
					ROUTE_cap_flag_2  =
					{
						ROUTE_cap_flag_3  =
						{
						},
						ROUTE_cap_flag_4  =
						{
							ROUTE_cap_flag_5  =
							{
							},
						},
					},
				},
			},
		},
		BUILD_Command_Post =
		{
			ROUTE_Spawn_3  =
			{
				ROUTE_cp_east_1  =
				{
					ROUTE_cp_east_2  =
					{
					},
				},
			},
		},
	};
	Util.Routes(MapRoutes);
};
