//==========================================================================================
//
//	clavier.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	d00d	17 September 2013	Elevator support
//	d00d	14 September 2013	Initial Script
//
//==========================================================================================
//

global Map =
{
	ElevatorFloor = 1,

	Switches =
	{
		elevator1to4 =
		{
			Enabled = true,
			Priority = 0,
			WaypointName = "elevator1to4",
			Timeout = 2000,
			Wait = function()
			{
				if ( Map.ElevatorFloor == 4 )
				{
					sleep(0.5);
					return true;
				}
				return false;
			},
		},
		elevator1to2 =
		{
			Enabled = true,
			Priority = 0,
			WaypointName = "elevator1to2",
			Timeout = 1000,
			Wait = function()
			{
				if ( Map.ElevatorFloor == 2 )
				{
					sleep(1);
					return true;
				}
				return false;
			},
		},
		elevator2to1 =
		{
			Enabled = false,
			Priority = 0,
			WaypointName = "elevator2to1",
			Timeout = 1500,
			Wait = function()
			{
				if ( Map.ElevatorFloor == 1 )
				{
					sleep(0.5);
					return true;
				}
				return false;
			},
		},
		call_elevator_level2 =
		{
			Enabled = false,
			Priority = 0,
			WaypointName = "call_elevator_level2",
			Timeout = 1500,
			Wait = function()
			{
				if ( Map.ElevatorFloor == 2 )
				{
					sleep(0.5);
					return true;
				}
				return false;
			},
		},
		call_elevator_down =
		{
			Enabled = false,
			Priority = 0,
			WaypointName = "call_elevator_down",
			Timeout = 1500,
			Wait = function()
			{
				if ( Map.ElevatorFloor == 1 )
				{
					sleep(0.5);
					return true;
				}
				return false;
			},
		},
	},

	ElevatorOnFloor1 = function( trigger )
	{
		Map.ElevatorFloor = 1;
		Wp.SetWaypointFlag( "call_elevator", "closed", true );
		Wp.SetWaypointFlag( "call_elevator2", "closed", false );
		Map.Switches.elevator2to1.Enabled = false;
		Map.Switches.call_elevator_level2.Enabled = true;
		Map.Switches.call_elevator_down.Enabled = false;
		Util.MapDebugPrint( "Elevator on floor " + Map.ElevatorFloor );
	},

	ElevatorOnFloor2 = function( trigger )
	{
		Map.ElevatorFloor = 2;
		Wp.SetWaypointFlag( "call_elevator", "closed", false );
		Wp.SetWaypointFlag( "call_elevator2", "closed", true );
		Map.Switches.elevator2to1.Enabled = true;
		Map.Switches.call_elevator_down.Enabled = true;
		Map.Switches.call_elevator_level2.Enabled = false;
		Util.MapDebugPrint( "Elevator on floor " + Map.ElevatorFloor );
	},

	ElevatorOnFloor3 = function( trigger )
	{
		Map.ElevatorFloor = 3;
		Wp.SetWaypointFlag( "call_elevator", "closed", false );
		Wp.SetWaypointFlag( "call_elevator2", "closed", false );
		Map.Switches.elevator2to1.Enabled = false;
		Map.Switches.call_elevator_down.Enabled = true;
		Map.Switches.call_elevator_level2.Enabled = true;
		Util.MapDebugPrint( "Elevator on floor " + Map.ElevatorFloor );
	},

	ElevatorOnFloor4 = function( trigger )
	{
		Map.ElevatorFloor = 4;
		Wp.SetWaypointFlag( "call_elevator", "closed", false );
		Wp.SetWaypointFlag( "call_elevator2", "closed", false );
		Map.Switches.elevator2to1.Enabled = false;
		Map.Switches.call_elevator_down.Enabled = true;
		Map.Switches.call_elevator_level2.Enabled = true;
		Util.MapDebugPrint( "Elevator on floor " + Map.ElevatorFloor );
	},

	ElevatorDoorTrigger = function( trigger )
	// stop pressing elevator button when doors are closing
	{
		vec = ToVector( trigger.Action );
		if ( vec.y < 0 )
		{
			Map.Switches.elevator1to2.Enabled = false;
			Map.Switches.elevator2to1.Enabled = false;
			Map.Switches.call_elevator_down.Enabled = false;
			Map.Switches.elevator1to4.Enabled = false;
			Map.Switches.call_elevator_level2.Enabled = false;
			Util.MapDebugPrint( "Elevator door closing." );
		}
		else
		{
			Map.Switches.elevator1to4.Enabled = true;  // Does that make sense? Don't think so.
			Util.MapDebugPrint( "Elevator door opening." );
		}
	},

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	radar_pickup_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_joystick.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_joystick.*" );
		Util.MapDebugPrint( "radar_pickup_Taken" );
	},

	radar_pickup_Returned = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_joystick.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_joystick.*" );
		Util.MapDebugPrint( "radar_pickup_Returned" );
	},

	radar_pickup_Secured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_joystick.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_joystick.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ATTACK_teleport1",
			"ATTACK_teleport2",
			"SWITCH_joystick",
		});

		Util.MapDebugPrint( "radar_pickup_Secured" );
	},

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

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

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

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

	system_Active = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_allied_defense_switch" );
		SetAvailableMapGoals( TEAM.AXIS, true, "SWITCH_allied_defense_switch" );
		Util.MapDebugPrint( "system_Active" );
	},

	system_Shutdown = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_allied_defense_switch" );
		SetAvailableMapGoals( TEAM.AXIS, false, "SWITCH_allied_defense_switch" );
		Util.MapDebugPrint( "system_Shutdown" );
	},

	joystick_Activated = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"SWITCH_joystick",
			"ATTACK_joystick.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_joystick.*" );

		Util.MapDebugPrint( "joystick_Activated" );
	},

};

global OnMapLoad = function()
{
	// More triggers
	// ^3Alert! ^1Axis Player ^3fdetected in ^4Allied Base!
	// ^8Alert! ^1Axis Player ^8detected in ^4Allied Base!
	// ^1Alert! ^1Axis Player ^1detected in ^4Allied Base!
	// ^3Alert! ^4Allied Player ^3detected ^6in ^3The Keyboard!
	// ^8Alert! ^4Allied Player ^8detected ^6in ^8The Keyboard!
	// ^1Alert! ^4Allied Player ^1detected ^6in ^1The Keyboard!
	// ^8Alert! ^4Allied Player ^8detected ^6On Top ^8Of The Keyboard!
	// ^3Alert! ^4Allied Player ^3detected ^6On Top ^3Of The Keyboard!
	// ^1Alert! ^4Allied Player ^1detected ^6On Top ^1Of The Keyboard!

	OnTrigger( "^4Allied Team ^3have build the lego stair to the ^2Cannon Gun.!!", Map.Allied_Cannon_Stair_Built );
	OnTrigger( "^1Axis Team ^3have built the Flak_Panzer_38 on the shelf and ready to u", Map.Axis_Flak_Construction_Built );
	OnTrigger( "^1Axis Team ^3have build the Left Lego Stair/Unlock Left Speaker Telepo", Map.Left_Lego_Stair_Built );
	OnTrigger( "^1Axis Team ^3have build the Right Lego Stair/Unlock Right ^2Speaker Te", Map.Right_Lego_Stair_Built );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Destroyed );
	OnTrigger( "^3The dusts Under desk have been sweep by ^4allied Engenier. ^4Allied T", Map.Dust_Sweeper_center_to_teleporter_Built );
	OnTrigger( "^4Allied Team ^3have clean the corner dust then got enought dust to rea", Map.Left_Sweeper_dust_construct_Built );
	OnTrigger( "^4Allied Team ^3have built the ^2toilet paper right bridge!!", Map.Paper_Roller_Toilet_Bridge_Built );
	OnTrigger( "^4Allied Team ^3has build the small Bridge whit the ruler on MapWorld B", Map.WorldMap_ramp_materials_Built );
	OnTrigger( "^3The Lego Stair For The Cannon has been destroyed by ^1axis team!!", Map.Allied_Cannon_Stair_Destroyed );
	OnTrigger( "^4Allies Team ^3have destroyed the ^1Axis Flak_Panzer_38 ^3on the shelf", Map.Axis_Flak_Construction_Destroyed );
	OnTrigger( "^3The ^1Axis Right Lego Stair and teleporter ^3has been destroyed by ^4", Map.Right_Lego_Stair_Destroyed );
	OnTrigger( "^3The ^1Axis Left Lego Stair and teleporter ^3has been destroyed by ^4A", Map.Left_Lego_Stair_Destroyed );
	OnTrigger( "^4Allies Team ^2 have destroyed the keyboard!", Map.Control_Panel_Keyboard_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Dust_Sweeper_center_to_teleporter_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Left_Sweeper_dust_construct_Destroyed );
	OnTrigger( "^1Axis Team ^3have destroyed the ^2toilet paper bridge!!", Map.Paper_Roller_Toilet_Bridge_Destroyed );
	OnTrigger( "MISSING_STRING", Map.Reinforcement_Allied_Door_Destroyed );
	OnTrigger( "^1Axis Team ^3has Destroy the small Bridge whit the ruler on MapWorld B", Map.WorldMap_ramp_materials_Destroyed );
	OnTrigger( "Allies have stolen the Battery Parts!", Map.radar_pickup_Taken );
	OnTrigger( "Flag returned radar_pickup!", Map.radar_pickup_Returned );
	OnTrigger( "^4Allied Team ^2got the battery parts to the Joystick remote control an", Map.radar_pickup_Secured );
	OnTrigger( " ^1Axis Team ^3(re)capture The ^6Mouse Carpet ^3Flag On to Desk then re", Map.bunker_flag_Axis_Captured );
	OnTrigger( "^4Allies Team ^3capture the ^2Mouse Carpet ^3Flag On Desk to gained a N", Map.bunker_flag_Allies_Captured );
	OnTrigger( "^4The Allies Team ^3Activate Joystick on first shelve to activate telep", Map.joystick_Activated );
	OnTrigger( "MISSING_STRING", Map.rien_du_tout_Axis_Captured ); // What are those for? No idea whatsoever.
	OnTrigger( "MISSING_STRING", Map.rien_du_tout_Allies_Captured ); // What are those for? No idea whatsoever.
	OnTrigger( "^4Allied Tactical Defensive System ^3has been ^1shutdown!", Map.system_Shutdown );
	OnTrigger( "^4Allied Tactical Defensive System ^3has been ^2Activate!", Map.system_Active );
	OnTrigger( "level1_right_door_Moving", Map.ElevatorOnFloor1 );
	OnTrigger( "level2_right_door_Moving", Map.ElevatorOnFloor2 );
	OnTrigger( "level3_right_door_Moving", Map.ElevatorOnFloor3 );
	OnTrigger( "level4_right_door_Moving", Map.ElevatorOnFloor4 );
	OnTrigger( "elevator_left_door_goto", Map.ElevatorDoorTrigger );

	//~Util.DisableGoal( ".*", true ); // all but routes
	//~SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_.*" );
	//~SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"ATTACK_.*",
		"SWITCH_.*",
		"PLANT_Command_Post",
		"BUILD_Command_Post",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"PLANT_Command_Post",
		"BUILD_Command_Post",
		"ATTACK_.*",
		"SWITCH_.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_allied_defense_switch" );

	// Max users per goal
	Util.SetMaxUsers( 1, "BUILD_.*" );
	Util.SetMaxUsers( 1, "PLANT_.*" );
	Util.SetMaxUsers( 1, "SWITCH_.*" );
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );

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

	// Priority
	// (atm, most of these are hacks until I find a better solution)
	SetGoalPriority( "BUILD_Allied_Cannon_Stair", 0.91 );
	SetGoalPriority( "BUILD_Paper_Roller_Toilet_Bridge", 0.92 );
	SetGoalPriority( "PLANT_Control_Panel_Keyboard", 0.89 );

	// Some other stuff
	Wp.SetWaypointFlag( "call_elevator", "closed", true );
	Wp.SetWaypointFlag( "call_elevator2", "closed", true );
	Util.UpdateSwitchData();
	Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " executed." );
};


