//==========================================================================================
//
//	midnight_b3.gm
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	^4Tardis	12 December 2013	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script
	// Dyno counters
	Broken_Wall_Dyno = 0,
	Cave_Entrance_Dyno = 0,
	Command_Post_Dyno = 0,
	Foot_Bridge_Dyno = 0,
	Main_Entrance_Dyno = 0,
	// Objective status
	CPStatus = 0, // nobody owns it. 1 = axis, 2 = allied
	Bridge = 0, // close jump on bridge

	Navigation =
	{
		jump =
		{
			navigate = function( _this )
			{
				_this.Bot.PressButton( BTN.JUMP );
				_this.Bot.HoldButton( BTN.FORWARD, 6 );
				_this.Bot.HoldButton( BTN.SPRINT, 6 );
				sleep( 6 );
			},
		},
		// /bot waypoint_setproperty paththrough Navigation_PT:jump
		// needs some work value's or waypoints -.-
	},

	Command_Post_Built_Allied = function( trigger )
	{
		// mark the cp as owned by allies
		Map.CPStatus = 2;

		// and spawn at the cp
		Util.ChangeSpawn( TEAM.ALLIES, 3 );

		Util.MapDebugPrint( "Command_Post_Built" );
	},

	Command_Post_Built_Axis = function( trigger )
	{
		// mark the cp as owned by axis
		Map.CPStatus = 1;

		Util.MapDebugPrint( "Command_Post_Built" );
	},

	Command_Post_Destroyed_Allied = function( trigger )
	{
		// nobody owns the cp when it's not constructed
		Map.CPStatus = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

	Command_Post_Destroyed_Axis = function( trigger )
	{
		// nobody owns the cp when it's not constructed
		Map.CPStatus = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

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

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

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

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

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

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

	Main_Entrance_Planted = function( trigger )
	{
		Map.Main_Entrance_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_gate.*" );
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},

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

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

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

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

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

	Broken_Wall_Destroyed = function( trigger )
	{
		Map.Broken_Wall_Dyno = 0;

		Util.MapDebugPrint( "Broken_Wall_Destroyed" );
	},

	Cave_Entrance_Destroyed = function( trigger )
	{
		Map.Cave_Entrance_Dyno = 0;

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CAPPOINT.*",
			"FLAG.*",
			"BUILD.*",
			"PLANT_Broken_Wall.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"FLAG.*",
			"BUILD.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_gate.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT.*" );

		Util.MapDebugPrint( "Cave_Entrance_Destroyed" );
	},


	Foot_Bridge_Destroyed = function( trigger )
	{
		Map.Foot_Bridge_Dyno = 0;

		Util.MapDebugPrint( "Foot_Bridge_Destroyed" );
	},

	Main_Entrance_Destroyed = function( trigger )
	{
		Map.Main_Entrance_Dyno = 0;
		//open jump on bridge
		Map.Bridge = 1;

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CAPPOINT.*",
			"FLAG.*",
			"BUILD.*",
			"PLANT_Broken_Wall.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"FLAG.*",
			"BUILD.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_gate.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT.*" );
		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Bridge = function( trigger )
	{

		if ( Map.Bridge == 0 )
		{
		//close jump on bridge
		Wp.SetWaypointFlag( "bridge1", "close", true );
		Wp.SetWaypointFlag( "bridge2", "close", true );
		}
		if ( Map.Bridge == 1 )
		{
		//open jump on bridge
		Wp.SetWaypointFlag( "bridge1", "open", true );
		Wp.SetWaypointFlag( "bridge2", "open", true );
		}
		Util.MapDebugPrint( "Bridge" );
	},

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

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

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

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

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

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

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

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

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

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

	Town = function( trigger )
	{
		//sanity
		if ( Map.Bridge == 1 )
		{
		//open jump on bridge
		Wp.SetWaypointFlag( "bridge1", "open", true );
		Wp.SetWaypointFlag( "bridge2", "open", true );
		}

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"CAPPOINT.*",
			"FLAG.*",
			"BUILD.*",
			"PLANT_Broken_Wall.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"FLAG.*",
			"BUILD.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_gate.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT.*" );

		Util.MapDebugPrint( "Town" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "^1Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built_Allied );
	OnTrigger( "^1Axis Command Post constructed. Charge speed increased!", Map.Command_Post_Built_Axis );
	OnTrigger( "^1Allied team has constructed the Foot Bridge!", Map.Foot_Bridge_Built );
	OnTrigger( "Planted at the Broken Wall.", Map.Broken_Wall_Planted );
	OnTrigger( "Planted at the Cave Entrance.", Map.Cave_Entrance_Planted );
	OnTrigger( "Planted at the Command Post.", Map.Command_Post_Planted );
	OnTrigger( "Planted at the Foot Bridge.", Map.Foot_Bridge_Planted );
	OnTrigger( "Planted at the Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Defused at the Broken Wall.", Map.Broken_Wall_Defused );
	OnTrigger( "Defused at the Cave Entrance.", Map.Cave_Entrance_Defused );
	OnTrigger( "Defused at the Command Post.", Map.Command_Post_Defused );
	OnTrigger( "Defused at the Foot Bridge.", Map.Foot_Bridge_Defused );
	OnTrigger( "Defused at the Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "^1Allies have destroyed the Broken Wall!", Map.Broken_Wall_Destroyed );
	OnTrigger( "^1Allies have destroyed the Cave Entrance!", Map.Cave_Entrance_Destroyed );
	OnTrigger( "^1Allied team has destroyed the Axis Command Post!", Map.Command_Post_Destroyed_Allied );
	OnTrigger( "^1Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed_Axis );
	OnTrigger( "^1Axis team has destroyed the Foot Bridge!", Map.Foot_Bridge_Destroyed );
	OnTrigger( "^1Allies have destroyed the Main Entrance!", Map.Main_Entrance_Destroyed );
	OnTrigger( "^1The Allies have stolen the explosives!", Map.dyno_Taken );
	OnTrigger( "^1The Allies have stolen the explosives!", Map.dyno2_Taken );
	OnTrigger( "^1The Axis have returned the explosives!", Map.dyno_Returned );
	OnTrigger( "^1The Axis have returned the explosives!", Map.dyno2_Returned );
	OnTrigger( "^1The Allies have planted the explosives!", Map.dyno_Secured );
	OnTrigger( "^1The Allies have planted the explosives!", Map.dyno2_Secured );
	OnTrigger( "^1Axis have reclaimed the Forward Spawn!", Map.forwardspawn1_flag_Axis_Captured );
	OnTrigger( "^1Allies have captured the Forward Spawn!", Map.forwardspawn1_flag_Allies_Captured );
	OnTrigger("^1The Allies have destroyed the East Flak Cannon!", Map.EastFlack );
	OnTrigger("^1The Allies have destroyed the West Flak Cannon!", Map.WestFlack );
	OnTrigger("^1Allies have secured the Town!", Map.Town );

	Util.DisableGoal( ".*", true ); // all but routes
	//AddUseWp
	Util.AddUseWp("PLANT_Broken_Wall", "wall");
	//Goals
	Util.EnableGoal( "PLANT.*" );
	Util.EnableGoal( "CHECKPOINT.*" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Broken_Wall.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Broken_Wall.*" );
	//~SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_.*" );
	//~SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

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


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

global OnBotJoin = function( bot )
{
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_Command_Post =
		{
		},
		BUILD_Foot_Bridge =
		{
		},
		PLANT_Cave_Entrance =
		{
		},
		PLANT_Broken_Wall =
		{
		},
		PLANT_Foot_Bridge =
		{
		},
		PLANT_Command_Post =
		{
		},
		PLANT_Main_Entrance =
		{
		},
		FLAG_dyno =
		{
		},
		FLAG_dyno2 =
		{
		},
		CHECKPOINT_forwardspawn1_flag =
		{
		},
	};
	Util.Routes(MapRoutes);
};
