//==========================================================================================
//
//	great_wall_b1.gm
//
//	Who	    	When		         What
//------------------------------------------------------------------------------------------
//	BMW	    	06 December 2012	 Initial Script
//  BubbaG1		15 March 2024		 Attack, Defend, Routes, fixed some stuckage issues
//
//==========================================================================================
//

global Map =
{
	Allied_Command_Post_Dyno = 0,
	Allied_MG42_Construction_Dyno = 0,
	Axis_Command_Post_Dyno = 0,
	Axis_MG42_Construction_Dyno = 0,
	Decoder_Door_Dyno = 0,

	Allied_Command_Post_Built = function()
	{

		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Allied_Command_Post" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_Command_Post" );

		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},

	Allied_MG42_Construction_Built = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Allied_MG42_Construction" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_MG42_Construction" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "MOUNTMG42_Allied_MG42_Construction" );

		Util.MapDebugPrint( "Allied_MG42_Construction_Built" );
	},

	Axis_Command_Post_Built = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Axis_Command_Post" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Command_Post" );

		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

	Axis_MG42_Construction_Built = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Axis_MG42_Construction" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_MG42_Construction" );
		SetAvailableMapGoals( TEAM.AXIS, true, "MOUNTMG42_Allied_MG42_Construction" );

		Util.MapDebugPrint( "Axis_MG42_Construction_Built" );
	},

	Allied_Command_Post_Planted = function()
	{

		Map.Allied_Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Allied_Command_Post_Planted" );
	},

	Allied_MG42_Construction_Planted = function()
	{
		Map.Allied_MG42_Construction_Dyno += 1;
		Util.MapDebugPrint( "Allied_MG42_Construction_Planted" );
	},

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

	Axis_MG42_Construction_Planted = function()
	{
		Map.Axis_MG42_Construction_Dyno += 1;
		Util.MapDebugPrint( "Axis_MG42_Construction_Planted" );
	},

	Decoder_Door_Planted = function()
	{
		Map.Decoder_Door_Dyno += 1;
		Util.MapDebugPrint( "Decoder_Door_Planted" );
	},

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

	Allied_MG42_Construction_Defused = function()
	{
		Map.Allied_MG42_Construction_Dyno -= 1;
		Util.MapDebugPrint( "Allied_MG42_Construction_Defused" );
	},

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

	Axis_MG42_Construction_Defused = function()
	{
		Map.Axis_MG42_Construction_Dyno -= 1;
		Util.MapDebugPrint( "Axis_MG42_Construction_Defused" );
	},

	Decoder_Door_Defused = function()
	{
		Map.Decoder_Door_Dyno -= 1;
		Util.MapDebugPrint( "Decoder_Door_Defused" );
	},

	Allied_Command_Post_Destroyed = function()
	{

		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_Command_Post" );
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Allied_Command_Post" );

		Map.Allied_Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},

	Allied_MG42_Construction_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_MG42_Construction" );
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Allied_MG42_Construction" );

		Map.Allied_MG42_Construction_Dyno = 0;

		Util.MapDebugPrint( "Allied_MG42_Construction_Destroyed" );
	},

	Axis_Command_Post_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_Command_Post" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_Command_Post" );

		Map.Axis_Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

	Axis_MG42_Construction_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_MG42_Construction" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_MG42_Construction" );

		Map.Axis_MG42_Construction_Dyno = 0;

		Util.MapDebugPrint( "Axis_MG42_Construction_Destroyed" );
	},

	Decoder_Door_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Decoder_Door" );
		SetAvailableMapGoals( TEAM.AXIS, true, "FLAG_allied_decoder" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Allied_MG42_Construction",
			"REPAIRMG42_Allied_MG42_Construction",
		});

		Map.Decoder_Door_Dyno = 0;

		Util.MapDebugPrint( "Decoder_Door_Destroyed" );
	},

	allied_decoder_Taken = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"CAPPOINT_truck",
			"ATTACK_Truck.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"FLAG_allied_decoder",
			"ATTACK_DecoderDoor.*",
		});

		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Truck.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_DecoderDoor.*" );

		Util.MapDebugPrint( "allied_decoder_Taken" );
	},

	allied_decoder_Returned = function()
	{

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"CAPPOINT_truck",
			"ATTACK_Truck.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"FLAG_allied_decoder",
			"ATTACK_DecoderDoor.*",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Truck.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_DecoderDoor.*" );

		Util.MapDebugPrint( "allied_decoder_Returned" );
	},

	allied_decoder_Secured = function()
	{

		//Axis win

		Util.MapDebugPrint( "allied_decoder_Secured" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "Allied Team have built the MG42 nest!!", Map.Allied_MG42_Construction_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "Axis Team have built the MG42 nest!!", Map.Axis_MG42_Construction_Built );
	OnTrigger( "Planted at the Allied Command Post.", Map.Allied_Command_Post_Planted );
	OnTrigger( "Planted at the Allied MG42 Construction.", Map.Allied_MG42_Construction_Planted );
	OnTrigger( "Planted at the Axis Command Post.", Map.Axis_Command_Post_Planted );
	OnTrigger( "Planted at the Axis MG42 Construction.", Map.Axis_MG42_Construction_Planted );
	OnTrigger( "Planted at Decoder Door.", Map.Decoder_Door_Planted );
	OnTrigger( "Defused at the Allied Command Post.", Map.Allied_Command_Post_Defused );
	OnTrigger( "Defused at the Allied MG42 Construction.", Map.Allied_MG42_Construction_Defused );
	OnTrigger( "Defused at the Axis Command Post.", Map.Axis_Command_Post_Defused );
	OnTrigger( "Defused at the Axis MG42 Construction.", Map.Axis_MG42_Construction_Defused );
	OnTrigger( "Defused at Decoder Door.", Map.Decoder_Door_Defused );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "Axis have destroyed the MG42 Nest!!", Map.Allied_MG42_Construction_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "Allies have destroyed the MG42 Nest!!", Map.Axis_MG42_Construction_Destroyed );
	OnTrigger( "The axis team have destroyed the decoder door!", Map.Decoder_Door_Destroyed );
	OnTrigger( "The Axis have stolen the Allied decoder", Map.allied_decoder_Taken );
	OnTrigger( "The Allies have retrieved the decoder", Map.allied_decoder_Returned );
	OnTrigger( "The Axis have secured the Allied decoder!", Map.allied_decoder_Secured );

	Util.DisableGoal( ".*", true ); // all but routes
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"ATTACK_DecoderDoor.*",
		"PLANT_Decoder_Door",
		"BUILD_Axis_Command_Post",
		"BUILD_Axis_MG42_Construction",
		"REPAIRMG42_Axis_MG42_Construction",
	});

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"DEFEND_DecoderDoor.*",
		"BUILD_Allied_Command_Post",
	});


	SetAvailableMapGoals( TEAM.AXIS, true, "AMMOCAB_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "HEALTHCAB_.*" );

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

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


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


global InitializeRoutes = function()
{
	MapRoutes =
	{
		ATTACK_DecoderDoor =
		{
			ROUTE_Wall = { Weight = 10, },
			ROUTE_Axis_Stairs_1 =
			{
				ROUTE_Axis_Stairs_2 =
				{
					ROUTE_Allies_Passage_1 = {},
				},
			},
		},
		ATTACK_DecoderDoor_1 = ATTACK_DecoderDoor,
		ATTACK_DecoderDoor_2 = ATTACK_DecoderDoor,
		ATTACK_DecoderDoor_3 = ATTACK_DecoderDoor,
		ATTACK_Truck_1 =
		{
			ROUTE_Axis_Stairs_1 =
			{
				ROUTE_Axis_Stairs_2 =
				{
					ROUTE_Axis_Stairs_3 = {},
					ROUTE_Axis_Stairs_4 = {},
				},
			},
		},
		ATTACK_Truck_2 = ATTACK_Truck_1,
		ATTACK_Truck_3 = ATTACK_Truck_1,
		ATTACK_Truck_4 = ATTACK_Truck_1,
		ATTACK_Truck_5 = ATTACK_Truck_1,
		PLANT_Decoder_Door = ATTACK_DecoderDoor,
		CAPPOINT_truck =
		{
			ROUTE_DecoderRoom =
			{
				ROUTE_Allies_Ladder =
				{
					Weight = 3,
					ROUTE_Allies_Passage_1 =
					{
						ROUTE_Allies_Passage_2 =
						{
							ROUTE_Axis_Stairs_2 =
							{
								ROUTE_Axis_Stairs_4 = {},
								ROUTE_Axis_Stairs_5 = {},
							},
						},
					},
					ROUTE_Axis_Stairs_3 = {},
					ROUTE_Axis_Stairs_4 = {},
				},
				ROUTE_Wall =
				{
					ROUTE_Axis_Stairs_1 =
					{
						ROUTE_Axis_Stairs_3 = {},
						ROUTE_Axis_Stairs_4 = {},
					},
				},
			},
		},
	};
	Util.Routes(MapRoutes);
};
