//==========================================================================================
//
//	wolken3_final.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	MickyP	18 April 2010	Initial Script
//
//==========================================================================================
//

global Map =
{
	Command_Post_Dyno = 0,
	Main_Entrance_Dyno = 0,
	Side_Entrance_Dyno = 0,
	documents_safe_Dyno = 0,
	Main_Entry_Destroyed = false,
	Fuel_Taken = false,
	Fuel_Secured = false,
	Docs_Taken = false,
	Docs_Secured = false,

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

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

	Main_Entrance_Planted = function()
	{
		Map.Main_Entrance_Dyno += 1;
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},

	Main_Entrance_Defused = function()
	{
		Map.Main_Entrance_Dyno -= 1;
		Util.MapDebugPrint( "Main_Entrance_Defused" );
	},

	Main_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Command_Post",
			"PLANT_Command_Post",
			"DEFEND_fuel.*",
			"DEFEND_Docs.*",
			"DEFEND_Obj_def.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_Main_def.*",
			"DEFEND_Side_def.*",
			"CHECKPOINT_forwardspawn1_flag",
			"AMMOCAB_north_ammocabinet",
			"HEALTHCAB_north_healthcabinet",
			"DEFUSE_Main_Entrance.*",
		});

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"ATTACK_Flag.*",
			"CHECKPOINT_forwardspawn1_flag",
		});
		sleep(2.1);
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"ATTACK_planefuel",
			"ATTACK_Docs.*",
			"FLAG_fuel_can",
			"PLANT_documents_safe",
			"AMMOCAB_north_ammocabinet",
			"HEALTHCAB_north_healthcabinet",
		});

		Map.Main_Entrance_Dyno = 0;
		Map.Main_Entry_Destroyed = true;

		Util.MapDebugPrint( "Main_Destroyed" );
	},

	Side_Entrance_Planted = function()
	{
		Map.Side_Entrance_Dyno += 1;
		Util.MapDebugPrint( "Side_Entrance_Planted" );
	},

	Side_Entrance_Defused = function()
	{
		Map.Side_Entrance_Dyno -= 1;
		Util.MapDebugPrint( "Side_Entrance_Defused" );
	},

	Side_Entrance_Destroyed = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Command_Post",
			"PLANT_Command_Post",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFUSE_Side_Entrance.*" );
		sleep(2.1);
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Command_Post",
			"PLANT_Command_Post",
		});
		Util.EnableGoal( "ROUTE_CP_Spawn", true );
		Map.Side_Entrance_Dyno = 0;

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

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

	Axis_Command_Post_Built = function()
	{
		Util.RandomSpawn(TEAM.AXIS, 2);

		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

	Command_Post_Planted = function()
	{
		Map.Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Command_Post_Planted" );
	},

	Command_Post_Defused = function()
	{
		Map.Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Command_Post_Defused" );
	},

	Allied_Command_Post_Destroyed = function()
	{
		Map.Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},

	Axis_Command_Post_Destroyed = function()
	{
		Map.Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

	documents_safe_Planted = function()
	{
		if ( Map.Docs_Secured == true )
		{
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFUSE_documents_safe.*" );
		}

		Map.documents_safe_Dyno += 1;
		Util.MapDebugPrint( "documents_safe_Planted" );
	},

	documents_safe_Defused = function()
	{
		Map.documents_safe_Dyno -= 1;
		Util.MapDebugPrint( "documents_safe_Defused" );
	},

	documents_safe_Destroyed = function()
	{
		if ( Map.Docs_Secured == true )
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_documents_safe" );
			SetAvailableMapGoals( TEAM.AXIS, false, "FLAG_documents" );
		}
		else if ( Map.Docs_Secured == false )
		{
			SetAvailableMapGoals( TEAM.AXIS, true, "FLAG_documents" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_documents_safe" );
		}
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFUSE_documents_safe.*" );
		Map.documents_safe_Dyno = 0;

		Util.MapDebugPrint( "documents_safe_Destroyed" );
	},

	documents_safe_Built = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "FLAG_documents" );

		Util.MapDebugPrint( "documents_safe_Built" );
	},

	documents_Taken = function()
	{
		if ( Map.Fuel_Taken == true || Map.Fuel_Secured == true )
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Obj_def.*" );
		}
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Docs.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Docs.*" );

		Map.Docs_Taken = true;
		Util.MapDebugPrint( "documents_Taken" );
	},

	documents_Returned = function()
	{
		if ( Map.Main_Entry_Destroyed == false )
		{
			if ( Map.Fuel_Taken == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" ); // Keep Active
			}
			else if ( Map.Fuel_Taken == false )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Plane.*" );
			}
		}
		else if ( Map.Main_Entry_Destroyed == true )
		{
			if ( Map.Fuel_Taken == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" ); // Keep Active
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Docs.*" );
			}
			else if ( Map.Fuel_Taken == false )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Plane.*" );
				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"DEFEND_Obj_def.*",
					"DEFEND_Docs.*",
				});
			}
		}

		Map.Docs_Taken = false;
		Util.MapDebugPrint( "documents_Returned" );
	},

	documents_Secured = function()
	{
		if ( Map.Main_Entry_Destroyed == false )
		{
			if ( Map.Fuel_Taken == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" ); // Keep Active
				Util.MapDebugPrint( "documents_Secured1" );
			}
			else if ( Map.Fuel_Taken == false )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Plane.*" );
				Util.MapDebugPrint( "documents_Secured2" );
			}
		}
		else if ( Map.Main_Entry_Destroyed == true )
		{
			if ( Map.Fuel_Taken == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" ); // Keep Active

				Util.MapDebugPrint( "documents_Secured3" );
			}
			else
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Plane.*" );
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Obj_def.*" );
				Util.MapDebugPrint( "documents_Secured4" );
			}
		}
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANT_documents_safe",
			"FLAG_documents",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_documents_safe.*" );
		Map.Docs_Taken = false;
		Map.Docs_Secured = true;
		Util.MapDebugPrint( "documents_Secured" );
	},

	fuel_can_Taken = function()
	{
		if ( Map.Docs_Taken == true || Map.Docs_Secured == true )
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Obj_def.*" );
		}
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_fuel.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_planefuel" );
		Map.Fuel_Taken = true;


		Util.MapDebugPrint( "fuel_can_Taken" );
	},

	fuel_can_Returned = function()
	{
		if ( Map.Main_Entry_Destroyed == false )
		{
			if ( Map.Docs_Taken == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" ); // Keep Active
			}
			else
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Plane.*" );
			}
		}
		else if ( Map.Main_Entry_Destroyed == true )
		{
			if ( Map.Docs_Taken == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" ); // Keep Active
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_fuel.*" );
				SetAvailableMapGoals( TEAM.AXIS, true, {
					"ATTACK_planefuel",
					"FLAG_fuel_can",
				});
			}
			else
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Plane.*" );
				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"DEFEND_Obj_def.*",
					"DEFEND_fuel.*",
				});
				SetAvailableMapGoals( TEAM.AXIS, true, {
					"ATTACK_planefuel",
					"FLAG_fuel_can",
				});
			}
		}
		Map.Fuel_Taken = false;
		Util.MapDebugPrint( "fuel_can_Returned" );
	},

	fuel_can_Secured = function()
	{
		else if ( Map.Main_Entry_Destroyed == false )
		{
			if ( Map.Docs_Taken == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" ); // Keep Active
				Util.MapDebugPrint( "fuel_can_Secured1" );
			}
			else if ( Map.Docs_Taken == false )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Plane.*" );
				Util.MapDebugPrint( "fuel_can_Secured2" );
			}
		}
		else if ( Map.Main_Entry_Destroyed == true )
		{
			if ( Map.Docs_Taken == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Plane.*" ); // Keep Active
				Util.MapDebugPrint( "fuel_can_Secured3" );
			}
			else if ( Map.Docs_Taken == false )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Plane.*" );
				SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Obj_def.*" );
				Util.MapDebugPrint( "fuel_can_Secured4" );
			}
		}
		SetAvailableMapGoals( TEAM.AXIS, false, "FLAG_fuel_can" );
		Map.Fuel_Taken = false;
		Map.Fuel_Secured = true;
		Util.MapDebugPrint( "fuel_can_Secured" );
	},
};

global OnMapLoad = function()
{
	// Register callback functions

	OnTrigger( "Axis have captured the Forward Spawn!", Map.forwardspawn1_flag_Axis_Captured );
	OnTrigger( "Allies have reclaimed the Forward Spawn!", Map.forwardspawn1_flag_Allies_Captured );
	OnTrigger( "Planted at the Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Defused at the Main Entrance!", Map.Main_Entrance_Defused );
	OnTrigger( "Allies have destroyed the Main Entrance!", Map.Main_Destroyed ); //~ Error in map script it should be Axis not Allies
	OnTrigger( "Axis have destroyed the Main Entrance!", Map.Main_Destroyed ); //~ Correction to above if script is corrected
	OnTrigger( "Planted at the Side Entrance.", Map.Side_Entrance_Planted );
	OnTrigger( "Defused at the Side Entrance!", Map.Side_Entrance_Defused );
	OnTrigger( "Axis have destroyed the Side Entrance!", Map.Side_Entrance_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "Planted at the Command Post.", Map.Command_Post_Planted );
	OnTrigger( "Defused at the Command Post.", Map.Command_Post_Defused );
	OnTrigger( "Allies 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( "Planted at the document's safe.", Map.documents_safe_Planted );
	OnTrigger( "Defused at the document's safe.", Map.documents_safe_Defused );
	OnTrigger( "Axis have destroyed the safe!", Map.documents_safe_Destroyed );
	OnTrigger( "Allies have rebuilt the safe!", Map.documents_safe_Built );
	OnTrigger( "The Axis have stolen the documents!", Map.documents_Taken );
	OnTrigger( "The Allies have returned the documents", Map.documents_Returned );
	OnTrigger( "The Axis have secured the documents!", Map.documents_Secured );
	OnTrigger( "The Axis have stolen the fuel!", Map.fuel_can_Taken );
	OnTrigger( "The Allies have returned the fuel!", Map.fuel_can_Returned );
	OnTrigger( "The Axis have refueled the plane!", Map.fuel_can_Secured );


	Util.DisableGoal( ".*", true ); // all but routes
	Util.DisableGoal( "ROUTE_CP_Spawn", true );

	// 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} );

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"DEFEND_Main_def.*",
		"DEFEND_Side_def.*",
		"CHECKPOINT_forwardspawn1_flag",
	});

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"CHECKPOINT_forwardspawn1_flag",
		"PLANT_Main_Entrance",
		"PLANT_Side_Entrance",
		"ATTACK_Flag.*",
		"CAPPOINT_Plane",
	});

	SetGoalPriority("PLANT_Main_Entrance", 0.84);
	SetGoalPriority("PLANT_Side_Entrance", 0.83);
	SetGoalPriority("PLANT_Command_Post", 0.82);
	SetGoalPriority("BUILD_documents_safe", 0.83);
	SetGoalPriority("DEFEND_Plane_1", 0.51); // Make sure that at least 2 capoint defence are active
	SetGoalPriority("DEFEND_Plane_2", 0.51);

	Util.AddUseWp("PLANT_documents_safe", "safe"); // Fix to rare issue where bots sometimes plant at the ground floor & not the 1st

	MapRoutes =
	{
		CHECKPOINT_forwardspawn1_flag =
		{
			ROUTE_AxisSpawn  =
			{
				ROUTE_AT_Gun  =
				{
					ROUTE_side  =
					{
					},
					ROUTE_Side_minor  =
					{
					},
				},
				ROUTE_Tank  =
				{
					ROUTE_flag  =
					{
					},
					ROUTE_main  =
					{
					},
				},
				ROUTE_Main_long  =
				{
					ROUTE_flag  =
					{
					},
					ROUTE_main  =
					{
					},
				},
			},
			ROUTE_Aliies_Spawn_4  =
			{
				ROUTE_Slipway  =
				{
					ROUTE_Main_large  =
					{
					},
					ROUTE_Main_Small  =
					{
					},
				},
				ROUTE_Slipway_ladder  =
				{
					ROUTE_Main_large  =
					{
					},
					ROUTE_Main_Small  =
					{
					},
				},
			},
			ROUTE_Allies_Spawn_5  =
			{
				ROUTE_Slipway  =
				{
				},
				ROUTE_sidedoor  =
				{
					ROUTE_Main_large  =
					{
					},
					ROUTE_Main_Small  =
					{
					},
				},
			},
		},
		PLANT_documents_safe =
		{
			ROUTE_Flag_Spawn  =
			{
				ROUTE_Main_Small  =
				{
					ROUTE_Slipway  =
					{
						ROUTE_House_Entry  =
						{
						},
						ROUTE_Wooden_Ladder  =
						{
						},
					},
					ROUTE_Main_Side  =
					{
						ROUTE_Wooden_Ladder  =
						{
						},
						ROUTE_House_Entry  =
						{
							ROUTE_Stairs_North  =
							{
							},
							ROUTE_Stairs_South  =
							{
							},
						},
					},
				},
				ROUTE_Main_large  =
				{
					ROUTE_Slipway  =
					{
						ROUTE_House_Entry  =
						{
							ROUTE_Stairs_South  =
							{
							},
							ROUTE_Stairs_North  =
							{
							},
						},
						ROUTE_Wooden_Ladder  =
						{
						},
					},
					ROUTE_Main_Side  =
					{
						ROUTE_Wooden_Ladder  =
						{
						},
						ROUTE_House_Entry  =
						{
							ROUTE_Stairs_North  =
							{
							},
							ROUTE_Stairs_South  =
							{
							},
						},
					},
				},
				ROUTE_CP_Spawn  =
				{
					ROUTE_House_Entry  =
					{
						ROUTE_Stairs_South  =
						{
						},
						ROUTE_Stairs_North  =
						{
						},
					},
				},
			},
			ROUTE_CP_Spawn  =
			{
				ROUTE_House_Entry  =
				{
					ROUTE_Stairs_North  =
					{
					},
					ROUTE_Stairs_South  =
					{
					},
				},
			},
		},
		FLAG_fuel_can =
		{
			ROUTE_Flag_Spawn  =
			{
				ROUTE_CP_Spawn  =
				{
					ROUTE_Tower_South  =
					{
					},
					ROUTE_Tower_North  =
					{
					},
				},
				ROUTE_Main_large  =
				{
					ROUTE_Slipway  =
					{
						ROUTE_Tower_North  =
						{
						},
						ROUTE_Tower_South  =
						{
						},
					},
					ROUTE_Main_Side  =
					{
						ROUTE_Tower_North  =
						{
						},
						ROUTE_Tower_South  =
						{
						},
					},
				},
				ROUTE_Main_Small  =
				{
					ROUTE_Slipway  =
					{
						ROUTE_Tower_North  =
						{
						},
						ROUTE_Tower_South  =
						{
						},
					},
					ROUTE_Main_Side  =
					{
						ROUTE_Tower_North  =
						{
						},
						ROUTE_Tower_South  =
						{
						},
					},
				},
			},
			ROUTE_CP_Spawn  =
			{
				ROUTE_Tower_North  =
				{
				},
				ROUTE_Tower_South  =
				{
				},
			},
		},
		CAPPOINT_Plane =
		{
			ROUTE_Docs  =
			{
				ROUTE_Slipway  =
				{
					ROUTE_Tank  =
					{
						ROUTE_AT_Gun  =
						{
						},
					},
				},
				ROUTE_sidedoor  =
				{
					ROUTE_side  =
					{
					},
					ROUTE_Side_minor  =
					{
					},
				},
			},
			ROUTE_Fuel  =
			{
				ROUTE_Tower_North  =
				{
					ROUTE_sidedoor  =
					{
						ROUTE_side  =
						{
						},
						ROUTE_Side_minor  =
						{
						},
					},
				},
				ROUTE_Tower_South  =
				{
					ROUTE_sidedoor  =
					{
						ROUTE_side  =
						{
						},
						ROUTE_Side_minor  =
						{
						},
					},
				},
			},
		},
		DEFEND_Docs_1 =
		{
			ROUTE_Aliies_Spawn_4  =
			{
				ROUTE_House_Entry  =
				{
					ROUTE_Stairs_North  =
					{
					},
					ROUTE_Stairs_South  =
					{
					},
				},
				ROUTE_Wooden_Ladder  =
				{
				},
			},
			ROUTE_Allies_Spawn_5  =
			{
				ROUTE_House_Entry  =
				{
					ROUTE_Stairs_North  =
					{
					},
					ROUTE_Stairs_South  =
					{
					},
				},
				ROUTE_Wooden_Ladder  =
				{
				},
			},
		},
		PLANT_Main_Entrance =
		{
			ROUTE_AxisSpawn  =
			{
				ROUTE_Main_Small  =
				{
				},
				ROUTE_Main_large  =
				{
				},
			},
			ROUTE_CP_Spawn  =
			{
				ROUTE_Main_large  =
				{
				},
				ROUTE_Main_Small  =
				{
				},
			},
		},
	};

	MapRoutes.ATTACK_Flag_1 = MapRoutes.CHECKPOINT_forwardspawn1_flag;
	MapRoutes.ATTACK_Flag_2 = MapRoutes.CHECKPOINT_forwardspawn1_flag;
	MapRoutes.ATTACK_Flag_3 = MapRoutes.CHECKPOINT_forwardspawn1_flag;
	MapRoutes.ATTACK_Flag_4 = MapRoutes.CHECKPOINT_forwardspawn1_flag;
	MapRoutes.ATTACK_Flag_5 = MapRoutes.CHECKPOINT_forwardspawn1_flag;
	MapRoutes.ATTACK_Flag_6 = MapRoutes.CHECKPOINT_forwardspawn1_flag;
	MapRoutes.ATTACK_Docs_1 = MapRoutes.PLANT_documents_safe;
	MapRoutes.ATTACK_Docs_2 = MapRoutes.PLANT_documents_safe;
	MapRoutes.ATTACK_planefuel = MapRoutes.PLANT_documents_safe;

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