//==========================================================================================
//
//	xlabs1.gm
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	^4Tardis	01 November 2010	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script

	Axis_Command_Post_Dyno = 0,
	Allied_Command_Post_Dyno = 0,
	Control_Panel_Dyno = 0,
	MG_Dyno = 0,
	Main_Gate_Dyno = 0,
	Control_Panel = false,
	Pos = "bottom", //lift at bottom

	Navigation =
	{
//bottom lift
		// /bot waypoint_setproperty paththrough Navigation_PT:wait
		wait =
		{
			navigate = function(_this)
			{
				if ( Map.Pos == "bottom" )
				{
					wpTable = {};
					Wp.GetWaypointByName("bot", wpTable);
					if ( _this.Goto(wpTable.position) == EVENT.PATH_SUCCESS )
					{
						_this.AddAimRequest(Priority.High, "facing", wpTable.facing);
						sleep(4);
					}
					Util.MapDebugPrint( "Ok Lift is here I am off" );
				}
				else if ( Map.Pos == "top" )
				{
					wpTable = {};
					Wp.GetWaypointByName("bot1", wpTable);
					if ( _this.Goto(wpTable.position) == EVENT.PATH_SUCCESS )
					{
						_this.AddAimRequest(Priority.High, "facing", wpTable.facing);
						sleep(4);
					}
					Util.MapDebugPrint( "I am waiting for the Lift" );
				}
				yield();
			},
		},
//top lift
		// /bot waypoint_setproperty paththrough Navigation_PT:wait1
		wait1 =
		{
			navigate = function(_this)
			{
				if ( Map.Pos == "top" )
				{
					wpTable = {};
					Wp.GetWaypointByName("top", wpTable);
					if ( _this.Goto(wpTable.position) == EVENT.PATH_SUCCESS )
					{
						_this.AddAimRequest(Priority.High, "facing", wpTable.facing);
						sleep(4);
					}
					Util.MapDebugPrint( "Ok Lift is here I am off" );
				}
				else if ( Map.Pos == "bottom" )
				{
					wpTable = {};
					Wp.GetWaypointByName("top1", wpTable);
					if ( _this.Goto(wpTable.position) == EVENT.PATH_SUCCESS )
					{
						_this.AddAimRequest(Priority.High, "facing", wpTable.facing);
						sleep(4);
					}
					Util.MapDebugPrint( "I am waiting for the Lift" );
				}
				yield();
			},

		},
	},
//lift
	lift = function(trigger)
	{
		Map.Pos = "moving";
		Wp.SetWaypointFlag("ground","closed",true);
		Wp.SetWaypointFlag("first","closed",true);
		Util.MapDebugPrint("lift moving");
		sleep(4);

		vel = ToVector(trigger.Action);

		if (vel.z < 0)
		{
			Map.Pos = "bottom";
			Wp.SetWaypointFlag("ground","closed",false);
			Util.MapDebugPrint("Lift at bottom");
		}
		else if (vel.z > 0)
		{
			Map.Pos = "top";
			Wp.SetWaypointFlag("first","closed",false);
			Util.MapDebugPrint("Lift at top");
		}
	},
	//OBJ - Going Though Axis door
	AxisDoorTrigger =
	{
		Name = "AxisDoorTrigger",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
		if ( GetEntFlags(ent,ENTFLAG.CARRYINGGOAL) )
			{
				SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_GATE.*" );
				Util.MapDebugPrint(GetEntName(ent) + " ^8 Has Entered Axis Door With The Documents !");
			}
		},
		OnExit = function(ent)
		{
		if ( GetEntFlags(ent,ENTFLAG.CARRYINGGOAL) )
			{
				SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_GATE.*" );
				Util.MapDebugPrint(GetEntName(ent) + " ^3 Has Exited Axis Door With The Documents !");
			}
		},
	},

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

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

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

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

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

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

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

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

	Control_Panel_Built = function( trigger )
	{
		Map.Control_Panel = true;
		Wp.SetWaypointFlag("controldoor","closed",false);
		Wp.SetWaypointFlag("controldoor1","closed",false);
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_gate.*",
			"MOUNTMG42_hill",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"PLANT_Control_Panel",
			"DEFEND_Cran",
			"DEFEND_obj.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Cran" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Fake_Escape.*");
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"FLAG.*",
			"ATTACK_Cran",
		});

		Util.MapDebugPrint( "Control_Panel_Built" );
	},

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

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

	Control_Panel_Destroyed = function( trigger )
	{
		Map.Control_Panel_Dyno = 0;
		Map.Control_Panel = false;
		Wp.SetWaypointFlag("controldoor","closed",true);
		Wp.SetWaypointFlag("controldoor1","closed",true);
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_gate.*",
			"MOUNTMG42_hill",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_Fake_Escape.*");
		Util.MapDebugPrint( "Control_Panel_Destroyed" );
	},

	MG_Built = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "MOUNTMG42_MG" );
		Util.MapDebugPrint( "MG_Built" );
	},

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

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

	MG_Destroyed = function( trigger )
	{
		Map.MG_Dyno = 0;
		Util.MapDebugPrint( "MG_Destroyed" );
	},

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

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

	Main_Gate_Destroyed = function( trigger )
	{
		Map.Main_Gate_Dyno = 0;
		Map.Main_Gate_Destroyed = true;
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Control_Panel" );
		SetAvailableMapGoals( TEAM.AXIS, false, "MOUNTMG42_Gate.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "MOUNTMG42_hill" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"MOUNTMG42_MG",
			"MOUNTMG42_AlliedMG.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Cran" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"GRENADE_hill",
			"CAPPOINT.*",
		});

		Util.MapDebugPrint( "Main_Gate_Destroyed" );
	},

	Very_Secret_Radar_Components_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Cran" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Cran" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_escape.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_obj.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_pannel.*" );

		Util.MapDebugPrint( "Very_Secret_Radar_Components_Taken" );
	},

	Very_Secret_Radar_Components_Returned = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Cran" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Cran" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_escape.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_pannel.*" );

		Util.MapDebugPrint( "Very_Secret_Radar_Components_Returned" );
	},

	Very_Secret_Radar_Components_Secured = function( trigger )
	{
	//Game Over
		Util.MapDebugPrint( "Very_Secret_Radar_Components_Secured" );
	},

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

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

};

global OnMapLoad = function()
{
// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "Allies Team have built the Control Panel!!", Map.Control_Panel_Built );
	OnTrigger( "Allied team has built the mg!", Map.MG_Built );
	OnTrigger( "Planted at the Allied Command Post!", Map.Allied_Command_Post_Planted );
	OnTrigger( "Planted at the Axis Command Post!", Map.Axis_Command_Post_Planted );
	OnTrigger( "Planted at the Control Panel.", Map.Control_Panel_Planted );
	OnTrigger( "Planted at the MG", Map.MG_Planted );
	OnTrigger( "Planted at the Main Gate", Map.Main_Gate_Planted );
	OnTrigger( "Defused at the Control Panel", Map.Control_Panel_Defused );
	OnTrigger( "Defused at the MG Defused", Map.MG_Defused );
	OnTrigger( "Defused at the Main Gate", Map.Main_Gate_Defused );
	OnTrigger( "Axis have destroyed the Control Panel door!!", Map.Control_Panel_Destroyed );
	OnTrigger( "Axis team has destroyed the mg!", Map.MG_Destroyed );
	OnTrigger( "Allies have breached the Main Entrance!", Map.Main_Gate_Destroyed );
	OnTrigger( "Allied team has stolen the very secret Radar Components!", Map.Very_Secret_Radar_Components_Taken );
	OnTrigger( "Allied team has returned the very secret Radar Components!", Map.Very_Secret_Radar_Components_Returned );
	OnTrigger( "Allied team has secured the very secret Radar Components!", Map.Very_Secret_Radar_Components_Secured );
	OnTrigger( "Axis captured the Flag!", Map.flag_flag_Axis_Captured );
	OnTrigger( "Allies captured the Flag!", Map.flag_flag_Allies_Captured );
	OnTrigger( "liftplatte_goto", Map.lift );
	door = OnTriggerRegion(AABB(1719.321,1501.421,-382.875,1824.874,1913.544,-308.875),Map.AxisDoorTrigger);

	Util.DisableGoal( ".*", true ); // all but routes
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"BUILD_MG",
		"PLANT_Main_Gate",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_gate.*",
		"CHECKPOINT.*",
		"MOUNTMG42_Gate.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"MOUNTMG42_AlliedMG.*",
		"GRENADE_gate.*",
	});
	SetGoalPriority( "CHECKPOINT.*", 0.49, 0, 0 ); //all teams and all classes
	SetGoalPriority( "CAPPOINT_Fake_Escape", 0.80 );
	Wp.SetWaypointFlag("controldoor","closed",true); //control pannel doors
	Wp.SetWaypointFlag("controldoor1","closed",true); //control pannel doors
	Wp.SetWaypointFlag("first","closed",true); //fisrt floor lift doors
	Wp.SetWaypointFlag("ground","closed",true); // ground floor lift doors
// Max users per goal
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 3, "CHECKPOINT.*" );
// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=10, MaxCampTime=60} );
	SetMapGoalProperties( "ATTACK_.*", {mincamptime=30, maxcamptime=45});
	SetMapGoalProperties( "DEFEND_.*", {mincamptime=60, maxcamptime=120});
	SetMapGoalProperties( "ATTACK_Cran", {mincamptime=120, maxcamptime=180});
	SetMapGoalProperties( "DEFEND_Cran", {mincamptime=120, maxcamptime=180});

	MapRoutes =
	{
		PLANT_Main_Gate =
		{
			ROUTE_Allies_Spawn  =
			{
				ROUTE_gate  =
				{
					ROUTE_gateA  =
					{
						ROUTE_gateA_1  =
						{
							ROUTE_gateA_2  =
							{
								ROUTE_maingate  =
								{
								},
							},
						},
					},
					ROUTE_gate_B  =
					{
						ROUTE_gate_B_1  =
						{
							ROUTE_gate_B_2  =
							{
								ROUTE_maingate  =
								{
								},
							},
						},
					},
				},
			},
		},
		BUILD_Control_Panel =
		{
			ROUTE_pannel  =
			{
				ROUTE_pannel_1  =
				{
					ROUTE_pannel_2  =
					{
						ROUTE_pannel_3  =
						{
							ROUTE_pannel_4  =
							{
								ROUTE_pannel_5  =
								{
								},
							},
						},
					},
				},
			},
		},
		FLAG_Very_Secret_Radar_Components =
		{
			ROUTE_FLAG  =
			{
				ROUTE_main  =
				{
					ROUTE_alpha  =
					{
						ROUTE_alpha_1  =
						{
							ROUTE_alpha_2  =
							{
								ROUTE_alpha_3  =
								{
									ROUTE_alpha_4  =
									{

										ROUTE_alpha_5  =
										{
											ROUTE_alpha_6  =
											{
												ROUTE_alpha_7  =
												{
													ROUTE_alpha_8  =
													{
														ROUTE_cran  =
														{
															ROUTE_obj  =
															{
															},
														},
													},
												},
											},
										},
										ROUTE_beta_6  =
										{
											ROUTE_beta_7  =
											{
												ROUTE_beta_8  =
												{
													ROUTE_cran  =
													{
														ROUTE_obj  =
														{
														},
													},
												},
												ROUTE_delta  =
												{
													ROUTE_deltaA  =
													{
														ROUTE_deltaB  =
														{
															ROUTE_obj  =
															{
															},
														},
													},
													ROUTE_delta_1  =
													{
														ROUTE_deltaB  =
														{
															ROUTE_obj  =
															{
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
					Weight = 2,
					ROUTE_beta  =
					{
						ROUTE_beta_1  =
						{
							ROUTE_beta_2  =
							{
								ROUTE_beta_3  =
								{
									ROUTE_beta_4  =
									{
										ROUTE_beta_5  =
										{
											ROUTE_beta_6  =
											{
												ROUTE_beta_7  =
												{
													ROUTE_beta_8  =
													{
														ROUTE_cran  =
														{
															ROUTE_obj  =
															{
															},
														},
													},
													ROUTE_delta  =
													{
														ROUTE_deltaA  =
														{
															ROUTE_deltaB  =
															{
																ROUTE_obj  =
																{
																},
															},
														},
														ROUTE_delta_1  =
														{
															ROUTE_deltaB  =
															{
																ROUTE_obj  =
																{
																},
															},
														},
													},
												},
												ROUTE_alpha_5  =
												{
													ROUTE_alpha_6  =
													{
														ROUTE_alpha_7  =
														{
															ROUTE_alpha_8  =
															{
																ROUTE_cran  =
																{
																	ROUTE_obj  =
																	{
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
	};
	MapRoutes.ATTACK_Cran = MapRoutes.FLAG_Very_Secret_Radar_Components;

	Util.Routes(MapRoutes);

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 90.0;
Util.ChangeSpawn(TEAM.ALLIES, 1, 1, CLASS.ENGINEER); //One Allied ENGINEER will spawn at location 1

};
