//==========================================================================================
//
//	bastogne.gm
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	10 November 2017   Initial Script
//
//==========================================================================================
//

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

	//map vars -----------------------------------------------------------------

	Allied_MG_Dyno = 0,
	Command_Post_Dyno = 0,
	Generator_Dyno = 0,
	Side_Entrance_Dyno = 0,
	DoorIsOpen = 0,

	//switches  ----------------------------------------------------------------
	Switches =
	{
		SWITCH_Door_1 = {
			Enabled = false,
			Priority = 0, // leave for paththrough
			WaypointName = "Door_1_WP",
			LimitTeam = 0, // disabled initially.
		},
		SWITCH_Door_2 = {
			Enabled = false,
			Priority = 0, // leave for paththrough
			WaypointName = "Door_2_WP",
			LimitTeam = 0, // disabled initially.
		},
	},

	//door to obj's
	lever1_goto = function( trigger )
	{
		vel = ToVector(trigger.Action);
		if ( vel.y < 0 )
		{
			//sleep(1.5);
			Map.DoorIsOpen = 1;

			Util.LimitGoal( TEAM.ALLIES, "SWITCH_Door_1" );
			Util.LimitGoal( TEAM.ALLIES, "SWITCH_Door_2" );

			Map.Switches.SWITCH_Door_1.LimitTeam = (1<<TEAM.ALLIES);
			Map.Switches.SWITCH_Door_2.LimitTeam = (1<<TEAM.ALLIES);

			Util.MapDebugPrint( "door open" );
		}
		else if ( vel.y > 0 )
		{
			//sleep(1.5);
			Map.DoorIsOpen = 0;

			Util.LimitGoal( TEAM.AXIS, "SWITCH_Door_1" );
			Util.LimitGoal( TEAM.AXIS, "SWITCH_Door_2" );

			Map.Switches.SWITCH_Door_1.LimitTeam = (1<<TEAM.AXIS);
			Map.Switches.SWITCH_Door_2.LimitTeam = (1<<TEAM.AXIS);

			Util.MapDebugPrint( "door closed" );
		}
	},

	//map roles ----------------------------------------------------------------

	Roles =
	{
		AXIS = // Team
		{
			AllBots = true, // each bot is considered for a role
			DEFENDER = // the DEFENDER role
			{
				spawnpt = 2,			// users of this role will choose spawnpt 2
				numbots = 3,			// maximum of 3 bots
				crucialClass = CLASS.ENGINEER,	// first bot
			},
		},

		ALLIES =
		{
			AllBots = true, // default: every other bot
			DEFENDER =
			{
				spawnpt = 1,
				numbots = 3,
				crucialClass = CLASS.ENGINEER,	// first bot
			},
		},
	},

	//callbacks -----------------------------------------------------------------

	Allied_MG_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Allied_MG" );
		SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Allied_MG" );
		Util.MapDebugPrint( "Allied_MG_Built" );
	},
	Allied_MG_Planted = function( trigger )
	{
		Map.Allied_MG_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Allied_MG" );
		Util.MapDebugPrint( "Allied_MG_Planted" );
	},
	Allied_MG_Defused = function( trigger )
	{
		Map.Allied_MG_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Generator" );
		Util.MapDebugPrint( "Allied_MG_Defused" );
	},
	Allied_MG_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Allied_MG" );
		Util.MapDebugPrint( "Allied_MG_Destroyed" );
	},

	Generator_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Generator" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Generator" );
		Util.MapDebugPrint( "Generator_Built" );
	},
	Generator_Planted = function( trigger )
	{
		Map.Generator_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Generator" );
		Util.MapDebugPrint( "Generator_Planted" );
	},
	Generator_Defused = function( trigger )
	{
		Map.Generator_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Generator" );
		Util.MapDebugPrint( "Generator_Defused" );
	},
	Generator_Destroyed = function( trigger )
	{
		Map.Generator_Dyno = 0;
		SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Generator" );
		Util.MapDebugPrint( "Generator_Destroyed" );
	},

	Main_Entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Main_Entrance" );
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},
	Main_Entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Main_Entrance" );
		Util.MapDebugPrint( "Main_Entrance_Defused" );
	},
	Main_Entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Main_Entrance" );

		SetAvailableMapGoals( TEAM.ALLIES, 0, "DEFEND_Hall_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "DEFEND_Docs_.*" );

		SetAvailableMapGoals( TEAM.AXIS,   1, {
			"FLAG_.*",
			"CAPPOINT_Trans_.*",
			"ATTACK_Docs_.*",
			"SWITCH_Door_1",
		});
		Map.Switches.SWITCH_Door_1.LimitTeam = (1<<TEAM.AXIS);

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Side_Entrance_Planted = function( trigger )
	{
		Map.Side_Entrance_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Side_Entrance" );
		Util.MapDebugPrint( "Side_Entrance_Planted" );
	},
	Side_Entrance_Defused = function( trigger )
	{
		Map.Side_Entrance_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Side_Entrance" );

		Util.MapDebugPrint( "Side_Entrance_Defused" );
	},
	Side_Entrance_Destroyed = function( trigger )
	{
		Map.Side_Entrance_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "DEFEND_Hall_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "DEFEND_Docs_.*" );

		SetAvailableMapGoals( TEAM.AXIS,   1, {
			"ATTACK_Docs_.*",
			"FLAG_.*",
			"CAPPOINT_Trans_.*",
		});

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},


	allied_docs_West_Taken = function( trigger )
	{
		Util.MapDebugPrint( "allied_docs_West_Taken" );
	},
	allied_docs_West_Returned = function( trigger )
	{
		Util.MapDebugPrint( "allied_docs_West_Returned" );
	},
	allied_docs_West_Secured = function( trigger )
	{
		Util.MapDebugPrint( "allied_docs_West_Secured" );
	},

	allied_docs_East_Taken = function( trigger )
	{
		Util.MapDebugPrint( "allied_docs_East_Taken" );
	},
	allied_docs_East_Returned = function( trigger )
	{
		Util.MapDebugPrint( "allied_docs_East_Returned" );
	},
	allied_docs_East_Secured = function( trigger )
	{
		Util.MapDebugPrint( "allied_docs_East_Secured" );
	},

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


// Neutral Command Post

	CP_Owner = 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_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Command_Post" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_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.Command_Post_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.Command_Post_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},
	CP_Planted = function( trigger )
	{
		Map.Command_Post_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
		Util.MapDebugPrint( "CP_Planted" );
	},
	CP_Defused = function( trigger )
	{
		Map.Command_Post_Dyno -= 1;
		if ( Map.CP_Owner == TEAM.ALLIES ) {
			SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Command_Post" );
		} else {
			SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Command_Post" );
		}
		Util.MapDebugPrint( "CP_Defused" );
	},
// Command Post END


};

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

	OnTrigger( "lever1_goto", Map.lever1_goto );

	OnTrigger( "Allied MG-42 nest constructed!", Map.Allied_MG_Built );
	OnTrigger( "Planted at the Allied MG42 nest.", Map.Allied_MG_Planted );
	OnTrigger( "Defused at the Allied MG42.", Map.Allied_MG_Defused );
	OnTrigger( "Axis team has destroyed the Allied MG-42 nest!", Map.Allied_MG_Destroyed );

	OnTrigger( "The Generator has been constructed! Transmitter Enabled!", Map.Generator_Built );
	OnTrigger( "Planted at the Generator.", Map.Generator_Planted );
	OnTrigger( "Defused at the Generator.", Map.Generator_Defused );
	OnTrigger( "The Generator has been destroyed! Transmitter Disabled!", Map.Generator_Destroyed );

	OnTrigger( "Planted at Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Defused at Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "Axis have destroyed the Main Entrance!", Map.Main_Entrance_Destroyed );

	OnTrigger( "Planted at Side Entrance.", Map.Side_Entrance_Planted );
	OnTrigger( "Defused at Side Entrance.", Map.Side_Entrance_Defused );
	OnTrigger( "Axis have destroyed the Side Entrance!", Map.Side_Entrance_Destroyed );

	OnTrigger( "Axis capture the City Hall!", Map.forward_spawn_Axis_Captured );
	OnTrigger( "Allies reclaim the City Hall!", Map.forward_spawn_Allies_Captured );

	OnTrigger( "Axis have stolen Fuel dumps Map East!", Map.allied_docs_East_Taken );
	OnTrigger( "Axis have stolen West Fuel dumps Maps!", Map.allied_docs_West_Taken );//no announce

	OnTrigger( "Allies have returned Fuel dumps Map East!", Map.allied_docs_East_Returned );
	OnTrigger( "Allies have returned West Fuel dumps Maps!", Map.allied_docs_West_Returned );

	OnTrigger( "The Axis has Transmitted the East FuelDump's coordinates!", Map.allied_docs_East_Secured );
	OnTrigger( "The Axis has Transmitted the West FuelDump's coordinates!", Map.allied_docs_West_Secured );
	//"Axis has transmitted both Documents" //endgame

	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

	//both teams
	Util.EnableGoal( "CHECK.*" );
	SetGoalPriority( "CHECK.*", 0.80 );
	Util.EnableGoal( "MOUNTMG42_.*" );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"DEFEND_Main_.*",
		"DEFEND_Hall_.*",
		"BUILD_Allied_MG",
		"BUILD_Command_Post",
	});
	Util.LimitToClass( "PLANT_Generator", 2, CLASS.ENGINEER );
	Util.ExcludeClass( "DEFEND_Main_.*", 2, CLASS.ENGINEER );

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"ATTACK_.*",
		"BUILD_Generator",
		"BUILD_Command_Post",
		"PLANT_Side_Entrance",
		"PLANT_Main_Entrance",
		"PLANT_Side_Entrance",
	});
	Util.LimitToClass( "PLANT_Allied_MG", 1, CLASS.COVERTOPS );
	Util.LimitToClass( "PLANT_Command_Post", 0, CLASS.COVERTOPS );
	Util.LimitToClass( "PLANT_Main_Entrance", 1, CLASS.ENGINEER );

	// Max users per goal
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );

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

	Util.AddUsePoint( "PLANT_Side_Entrance", Vec3( 781, 850, -293 ) );

	Util.UpdateSwitchData();

	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 =
	{
		PLANT_Side_Entrance =
		{
			ROUTE_Axis_Side_Door = {},
		},

		PLANT_Main_Entrance =
		{
			ROUTE_Axis_Spawn_SE =
			{
				ROUTE_Main_St_2 =
				{
					ROUTE_Main_St_3 =
					{
						ROUTE_Main_St_4 =
						{
							ROUTE_Main_Door = {},
						},
					},
				},
			},
			ROUTE_Axis_Spawn_SW =
			{
				ROUTE_Main_St_1 =
				{
					ROUTE_Main_St_2 =
					{
						ROUTE_Main_St_3 =
						{
							ROUTE_Main_St_4 =
							{
								ROUTE_Main_Door = {},
							},
						},
					},
				},
			},
		},

		CHECKPOINT_forward_spawn =
		{
			ROUTE_Axis_Spawn_SW =
			{
				ROUTE_West_Path =
				{
					ROUTE_Forward_Spawn = {},
				},
			},
		},

		FLAG_allied_docs_West =
		{
			ROUTE_Door_Switch_Ext = {},
		},

		FLAG_allied_docs_East =
		{
			ROUTE_Door_Switch_Ext = {},
		},

		CAPPOINT_Trans_1 = {},
		CAPPOINT_Trans_2 = {},

		BUILD_Command_Post =
		{
			ROUTE_Forward_Spawn =
			{
				ROUTE_CP = {},
			},
		},

		PLANT_Command_Post =
		{
			ROUTE_Forward_Spawn =
			{
				ROUTE_CP = {},
			},
		},

		BUILD_Allied_MG =
		{
			ROUTE_Forward_Spawn = {},
		},

		PLANT_Allied_MG =
		{
		},

		BUILD_Generator =
		{
			ROUTE_Gen = {},
		},

		PLANT_Generator =
		{
		},

/*
	FLAG_allied_docs_East =
	FLAG_allied_docs_West =
	ROUTE_Allied_Spawn =
	ROUTE_Axis_CP =
	ROUTE_Axis_Forward_Spawn =
	ROUTE_Axis_Side_Door =
	ROUTE_Axis_Spawn =
	ROUTE_Cabs1 =
	ROUTE_Forward_Spawn =
	ROUTE_Docs_East =
	ROUTE_Docs_West =
	ROUTE_Door_Switch_Ext =
	ROUTE_Door_Switch_Int =
	ROUTE_Gen =
	ROUTE_MG =
	ROUTE_Main_Door =
	SWITCH_Door_1 =
	SWITCH_Door_2 =
*/

	};
	Util.Routes(MapRoutes);
};
