//==========================================================================================
//
//	panzerdepot.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	27 January 2018	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 1, // please set to zero before distributing your script
	DefendingTeam = TEAM.AXIS,

	Side_Wall_Blown = 0,

	Sidewall_Ledder_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Sidewall");
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Sidewall_Ledder");
		Util.MapDebugPrint( "Sidewall_Ledder_Built" );
	},
	Sidewall_Ledder_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Sidewall_Ledder");
		Util.MapDebugPrint( "Sidewall_Ledder_Destroyed" );
	},

	Sidewall_Planted = function( trigger )
	{
		sleep(1);
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Sidewall");
		SetAvailableMapGoals( TEAM.AXIS, 0, "DEFUSE_Sidewall.*");
		Util.MapDebugPrint( "Sidewall_Planted" );
	},
	Sidewall_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Sidewall");
		Util.MapDebugPrint( "Sidewall_Defused" );
	},
	Sidewall_Destroyed = function( trigger )
	{
		Map.Side_Wall_Blown = 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Sidewall");
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Escape_.*");
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Tank_Depot_Door");
		SetAvailableMapGoals( TEAM.ALLIES, 1, "ATTACK_Gen_.*");

		SetAvailableMapGoals( TEAM.AXIS, 1, "DEFEND_Gen_.*");
		Util.MapDebugPrint( "Sidewall_Destroyed" );
	},

	Tank_Depot_Door_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Tank_Depot_Door");
		Util.MapDebugPrint( "Tank_Depot_Door_Planted" );
	},
	Tank_Depot_Door_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Tank_Depot_Door");
		Util.MapDebugPrint( "Tank_Depot_Door_Defused" );
	},
	Tank_Depot_Door_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Tank_Depot_Door");
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Tankwall_.*");

		SetAvailableMapGoals( TEAM.AXIS, 0, "DEFEND_.*");
		SetAvailableMapGoals( TEAM.AXIS, 1, "DEFEND_Depot_.*");
		Util.MapDebugPrint( "Tank_Depot_Door_Destroyed" );
	},

	Tankwall_1_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Tankwall_1");
		Util.MapDebugPrint( "Tankwall_1_Built" );
	},
	Tankwall_1_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Tankwall_1");
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Tankwall_1");
		Util.MapDebugPrint( "Tankwall_1_Destroyed" );
	},

	Tankwall_2_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Tankwall_2");
		Util.MapDebugPrint( "Tankwall_2_Built" );
	},
	Tankwall_2_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Tankwall_2");
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Tankwall_2");
		Util.MapDebugPrint( "Tankwall_2_Destroyed" );
	},

	Tankwall_3_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Tankwall_3");
		Util.MapDebugPrint( "Tankwall_3_Built" );
	},
	Tankwall_3_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Tankwall_3");
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Tankwall_3");
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Fuel_Safe");
		Util.MapDebugPrint( "Tankwall_3_Destroyed" );
	},

	Fuel_Safe_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Fuel_Safe");
		Util.MapDebugPrint( "Fuel_Safe_Planted" );
	},
	Fuel_Safe_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Fuel_Safe");
		Util.MapDebugPrint( "Fuel_Safe_Defused" );
	},
	Fuel_Safe_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Fuel_Safe");
		SetAvailableMapGoals( TEAM.ALLIES, 1, "FLAG_allied_obj1");
		Util.MapDebugPrint( "Fuel_Safe_Destroyed" );
	},

	Escape_Voltage_Control_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Escape_.*");
		Util.MapDebugPrint( "Escape_Voltage_Control_Planted" );
	},
	Escape_Voltage_Control_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Escape_.*");
		Util.MapDebugPrint( "Escape_Voltage_Control_Defused" );
	},
	Escape_Voltage_Control_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Escape_.*");
		Wp.SetWaypointFlag("TruckDeath", "closed", 0);
		Util.MapDebugPrint( "Escape_Voltage_Control_Destroyed" );
	},


	allied_obj1_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAPPOINT_Truck");
		Util.MapDebugPrint( "allied_obj1_Taken" );
	},
	allied_obj1_Returned = function( trigger )
	{
		Util.MapDebugPrint( "allied_obj1_Returned" );
	},
	allied_obj1_Secured = function( trigger )
	{
		Util.MapDebugPrint( "allied_obj1_Secured" );
	},

	// Neutral Command Post
	CP_Owner = 0,
	CP_Dyno = 0,

	Set_CP = function(_p) // p = TEAM.ALLIES or TEAM.AXIS or 0 (unbuilt)
	{
		switch(_p)
		{
			case 0:
			{
				Map.CP_Owner = 0;
				SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Neutral_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Neutral_Command_Post" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Neutral_Command_Post" );
			}
		}
		//Util.MapDebugPrint("CP Owner: " + Map.CP_Owner );
	},


	Allied_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.ALLIES);
		Util.MapDebugPrint( "Allied_CP_Built" );
	},

	Allied_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},

	Axis_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.AXIS);
		Util.MapDebugPrint( "Axis_CP_Built" );
	},

	Axis_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},

	CP_Planted = function( trigger )
	{
		Map.CP_Dyno += 1;
		Util.MapDebugPrint( "CP_Planted" );
	},

	CP_Defused = function( trigger )
	{
		Map.CP_Dyno -= 1;
		Util.MapDebugPrint( "CP_Defused" );
	},

// Command Post END

	House_Tunnel_Entry_Exploded = function( trigger )
	{
		Util.DisableGoal( "GRENADE_House_Tunnel_Entry" );
		//Wp.SetWaypointFlag( "House_Tunnel_Entry_WP", "closed", false );
		Util.MapDebugPrint( "House_Tunnel_Entry_Exploded" );
	},

  Ax_Tunnel_Entry_Exploded = function( trigger )
	{
		Util.DisableGoal( "GRENADE_Ax_Tunnel_Entry" );
		//Wp.SetWaypointFlag( "Ax_Tunnel_Entry_WP", "closed", false );
		Util.MapDebugPrint( "Ax_Tunnel_Entry_Exploded" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "GRENADE_House_Tunnel_Entry Exploded", Map.House_Tunnel_Entry_Exploded );
	OnTrigger( "GRENADE_Ax_Tunnel_Entry Exploded", Map.Ax_Tunnel_Entry_Exploded );

	OnTrigger( "The ALlied has build the Sidewall Ladder", Map.Sidewall_Ledder_Built );
	OnTrigger( "The Allied Sidewall Ledder has been destroyed", Map.Sidewall_Ledder_Destroyed );

	OnTrigger( "Planted at Sidewall.", Map.Sidewall_Planted );
	OnTrigger( "Defused at Sidewall.", Map.Sidewall_Defused );
	OnTrigger( "The Sidewall has been breached!", Map.Sidewall_Destroyed );

	OnTrigger( "Planted at Tank Depot Door.", Map.Tank_Depot_Door_Planted );
	OnTrigger( "Defused at Tank Depot Door.", Map.Tank_Depot_Door_Defused );
	OnTrigger( "The Tank Maindoor has been breached!", Map.Tank_Depot_Door_Destroyed );

	OnTrigger( "The Axis Tankwall1 has been build", Map.Tankwall_1_Built );
	OnTrigger( "The Axis Tankwall1 has been destroyed", Map.Tankwall_1_Destroyed );

	OnTrigger( "The Axis Tankwall2 has been build", Map.Tankwall_2_Built );
	OnTrigger( "The Axis Tankwall2 has been destroyed", Map.Tankwall_2_Destroyed );

	OnTrigger( "The Axis Tankwall3 has been build", Map.Tankwall_3_Built );
	OnTrigger( "The Axis Tankwall3 has been destroyed", Map.Tankwall_3_Destroyed );

	OnTrigger( "Planted at Escape Voltage Control.", Map.Escape_Voltage_Control_Planted );
	OnTrigger( "Defused at Escape Voltage Control.", Map.Escape_Voltage_Control_Defused );
	OnTrigger( "The Escape Voltage Control has been breached! ***Voltage Down!***", Map.Escape_Voltage_Control_Destroyed );

	OnTrigger( "Planted at the Fuel Safe.", Map.Fuel_Safe_Planted );
	OnTrigger( "Defused at the Fuel Safe.", Map.Fuel_Safe_Defused );
	OnTrigger( "The Tank Fuel Area  has been breached!", Map.Fuel_Safe_Destroyed );

	OnTrigger( "MISSING_STRING", Map.allied_obj1_Taken );
	OnTrigger( "MISSING_STRING", Map.allied_obj1_Returned );
	OnTrigger( "Allied team escaped with the Tank Document!", Map.allied_obj1_Secured );

	OnTrigger( "Allied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!",          Map.Allied_CP_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!",    Map.Axis_CP_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!",          Map.Axis_CP_Destroyed );
	OnTrigger( "Planted at the Command Post.",                              Map.CP_Planted  );
	OnTrigger( "Defused at the Command Post.",                              Map.CP_Defused  );


	Util.DisableGoal( ".*", true ); // all but routes
	Util.EnableGoal( ".*CAB.*", true );
	ETUtil.SetCabinets();

	Util.SetGoalPosition(   684,  453, 312, "PLANT_Sidewall");
	Util.AddUsePoint( "PLANT_Tank_Depot_Door", Vec3( -1023, 1034, 148) );
	Util.AddUsePoint( "PLANT_Fuel_Safe", Vec3( -632, 1854, 158 ) );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, "GRENADE_House_Tunnel_Entry" ); //just to open tunnel entry

	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"BUILD_Neutral_Command_Post",
		"BUILD_Sidewall_Ledder",
		"SNIPE_Al_.*",
		"PLANTMINE_Al_.*",
	});
	Util.LimitToClass("BUILD_Sidewall_Ledder", 2, CLASS.ENGINEER);
	Util.LimitToClass("PLANT_Sidewall", 2, CLASS.ENGINEER);
	Util.LimitToClass("PLANT_Tankwall_.*", 2, CLASS.COVERTOPS);
	Util.LimitToClass("PLANT_Fuel_Safe", 2, CLASS.ENGINEER);

	//Both
	Util.LimitToClass("BUILD_Neutral_Command_Post", 0, CLASS.ENGINEER);
	Util.LimitToClass("PLANT_Neutral_Command_Post", 0, CLASS.COVERTOPS);

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, "GRENADE_Ax_Tunnel_Entry" ); //just to open tunnel entry

	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"BUILD_Neutral_Command_Post",
		"BUILD_Tankwall.*",
		"SNIPE_Ax_.*",
		"PLANTMINE_Ax_.*",
	});
	Util.LimitToClass("PLANT_Sidewall_Ledder", 1, CLASS.COVERTOPS);

	//Economy
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );

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


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

global OnBotJoin = function( bot )
{
	// Uncomment for shootable breakables
	bot.TargetBreakableDist = 90.0;
	// Only set MaxViewDistance on maps with limited sight (e.g. fog)
	//~bot.MaxViewDistance = 2400;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_Tankwall_1 = { ROUTE_AxSp = { ROUTE_TW_1 = {}, }, },
		BUILD_Tankwall_2 = { ROUTE_AxSp = { ROUTE_TW_2 = {}, }, },
		BUILD_Tankwall_3 = { ROUTE_AxSp = {	ROUTE_TW_3 = {}, }, },

		PLANT_Tankwall_1 = { ROUTE_Side_Wall = { ROUTE_Depot_Door = { ROUTE_TW_1 = {}, }, }, },
		PLANT_Tankwall_2 = { ROUTE_Side_Wall = { ROUTE_Depot_Door = { ROUTE_TW_2 = {}, }, }, },
		PLANT_Tankwall_3 = { ROUTE_Side_Wall = { ROUTE_Depot_Door = {	ROUTE_TW_3 = {}, }, }, },

		FLAG_allied_obj1 =
		{
			ROUTE_Side_Wall =
			{
				ROUTE_Depot_Door =
				{
					ROUTE_Fuel_Safe = {},
				},
			},
		},

		PLANT_Escape_Voltage_Control =
		{
			ROUTE_Side_Wall =
			{
				ROUTE_EVC = {},
			},
		},

		BUILD_Sidewall_Ledder =
		{
			ROUTE_AlSp =
			{
				ROUTE_Build_Ledder = {},
			},
		},
		PLANT_Sidewall_Ledder =
		{
			ROUTE_AxSp =
			{
				ROUTE_Ax_Tunnel =
				{
					ROUTE_CP =
					{
						ROUTE_House_Ladder =
						{
							ROUTE_Build_Ledder = {},
						},
					},
				},
			},
		},
		PLANT_Sidewall =
		{
			ROUTE_AlSp =
			{
				ROUTE_Side_Wall = {},
			},
		},

		BUILD_Neutral_Command_Post =
		{
			ROUTE_AlSp =
			{
				ROUTE_House_Ladder =
				{
					ROUTE_CP = {},
				},
			},
			ROUTE_AxSp =
			{
				ROUTE_Ax_Tunnel =
				{
					ROUTE_CP = {},
				},
			},
		},
		PLANT_Neutral_Command_Post =
		{
		},
		PLANT_Tank_Depot_Door =
		{
			ROUTE_Side_Wall =
			{
				ROUTE_Depot_Door = {},
			},
		},
		PLANT_Fuel_Safe =
		{
			ROUTE_Side_Wall =
			{
				ROUTE_Depot_Door =
				{
					ROUTE_Fuel_Safe = {},
				},
			},
		},

	};
	Util.Routes(MapRoutes);
};
