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

global Map =
{
	Drop_Point_Radio_Construction_Dyno = 0,
	Lower_Door_Dyno = 0,
	Upper_Door_Dyno = 0,
	Radio_Built = false,
	obj_taken = false,

	NavDoor = function(_this)
	{
		wpinfo = _this.navigation.wpinfo;
		if(wpinfo==null)
		{
			wpinfo = Util.WpNameInfo(_this.CurrentNavigation);
			_this.navigation.wpinfo = wpinfo;
		}
		pos = wpinfo.position;
		vec = wpinfo.facing.Normalize();
		pos1 = pos - vec * 60;
		pos1 = Vector3(pos1.x, pos1.y, pos.z);
		pos2 = pos + vec * 140;
		pos2 = Vector3(pos2.x, pos2.y, pos.z);

		for(i=0; i<4; i+=1)
		{
		  Util.MapDebugPrint("goto door");
			if(_this.Goto(pos) == EVENT.PATH_FAILED )
			{
			  Util.MapDebugPrint("goto door failed");
				return;
			}
			_this.AddAimRequest(Priority.High, "facing", wpinfo.facing);
			tr = TraceLine(pos, pos2, null, TRACE.SOLID, 0, false);
			if(tr.fraction == 1)
			{
				Util.MapDebugPrint("go through door");
				_this.Bot.MoveTowards(pos2);
				sleep(0.8);
				break;
			}
			sleep(0.1);
			Util.MapDebugPrint("open");
			_this.Bot.PressButton(BTN.USE);
			_this.Bot.MoveTowards(pos1);
			//wait while door opens
			sleep(2);
		}
	},

	Navigation =
	{
		door =
		{
			navigate = function(_this) { Map.NavDoor(_this); },

		},
		// /bot waypoint_setproperty paththrough Navigation_PT:door
		jump =
		{
			navigate = function( _this )
			{
				_this.Bot.PressButton( BTN.JUMP );
				_this.Bot.HoldButton( BTN.FORWARD, 3 );
				sleep( 3 );
			},
		},
		// /bot waypoint_setproperty paththrough Navigation_PT:jump
	},

	Drop_Point_Radio_Construction_Built = function()
	{
		Map.Radio_Built = true;

		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Fake.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Drop_Point_Radio_Construction" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_radio.*" );

		Util.MapDebugPrint( "Drop_Point_Radio_Construction_Built" );
	},

	Drop_Point_Radio_Construction_Planted = function()
	{
		Map.Drop_Point_Radio_Construction_Dyno += 1;
		Util.MapDebugPrint( "Drop_Point_Radio_Construction_Planted" );
	},

	Drop_Point_Radio_Construction_Defused = function()
	{
		Map.Drop_Point_Radio_Construction_Dyno -= 1;
		Util.MapDebugPrint( "Drop_Point_Radio_Construction_Defused" );
	},

	Drop_Point_Radio_Construction_Destroyed = function()
	{
		Map.Drop_Point_Radio_Construction_Dyno = 0;
		Map.Radio_Built = false;

		SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Plane.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_Fake.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_radio.*" );

		Util.MapDebugPrint( "Drop_Point_Radio_Construction_Destroyed" );
	},

	Upper_Door_Planted = function()
	{
		Map.Upper_Door_Dyno += 1;
		Util.MapDebugPrint( "Upper_Door_Planted" );
	},

	Upper_Door_Defused = function()
	{
		Map.Upper_Door_Dyno -= 1;
		Util.MapDebugPrint( "Upper_Door_Defused" );
	},

	Upper_Door_Destroyed = function()
	{
		Map.Upper_Door_Dyno = 0;

		if ( Map.obj_Taken == true )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"MOUNTMG42_BunkerMG",
				"SNIPE_bunker",
				"DEFEND_obj.*",
			});
		}
		else if ( Map.obj_taken == false)
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"MOUNTMG42_BunkerMG",
				"SNIPE_bunker",
				"DEFEND_obj.*",
			});
		}

		Util.MapDebugPrint( "Upper_Door_Destroyed" );
	},

	Lower_Door_Planted = function()
	{
		Map.Lower_Door_Dyno += 1;
		Util.MapDebugPrint( "Lower_Door_Planted" );
	},

	Lower_Door_Defused = function()
	{
		Map.Lower_Door_Dyno -= 1;
		Util.MapDebugPrint( "Lower_Door_Defused" );
	},

	Lower_Door_Destroyed = function()
	{
		Map.Lower_Door_Dyno = 0;

		if ( Map.Radio_Built == true )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_radio.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_plane.*" );
		}
		else if ( Map.Radio_Built == false )
		{
			//SetAvailableMapGoals( TEAM.AXIS, true, "ROUTE_Patrol.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_radio.*" );
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_plane.*",
				"MOBILEMG42_plane",
			});
		}
		if ( Map.obj_Taken == true )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_lower.*",
				"MOBILEMG42_lower",
				"MOUNTMG42_BunkerMG",
				"SNIPE_bunker",
				"DEFEND_obj.*",
			});
		}
		else if ( Map.obj_taken == false)
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"DEFEND_lower.*",
				"MOBILEMG42_lower",
				"MOUNTMG42_BunkerMG",
				"SNIPE_bunker",
				"DEFEND_obj.*",
			});
		}
		Util.MapDebugPrint( "Lower_Door_Destroyed" );
	},

	transmitter_obj_Taken = function()
	{
		Map.obj_taken = true;

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_lower.*",
			"MOBILEMG42_lower",
			"MOUNTMG42_BunkerMG",
			"SNIPE_bunker",
			"DEFEND_obj.*",
		});

		if ( Map.Radio_Built == true )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_radio.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"DEFEND_plane.*",
				"MOBILEMG42_plane",
			});
		}
		else if ( Map.Radio_Built == false )
		{
			//SetAvailableMapGoals( TEAM.AXIS, true, "ROUTE_Patrol.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_radio.*" );
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_plane.*",
				"MOBILEMG42_plane",
			});
		}
		Util.MapDebugPrint( "transmitter_obj_Taken" );
	},

	transmitter_obj_Returned = function()
	{
		Map.obj_taken = false;

		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_lower.*",
			"MOBILEMG42_lower",
			"MOUNTMG42_BunkerMG",
			"SNIPE_bunker",
			"DEFEND_obj.*",
		});

		if ( Map.Radio_Built == true )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_lower.*",
				"MOBILEMG42_lower",
				"DEFEND_radio.*",
			});
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"DEFEND_plane.*",
				"MOBILEMG42_plane",
			});
		}
		else if ( Map.Radio_Built == false )
		{
			//SetAvailableMapGoals( TEAM.AXIS, true, "ROUTE_Patrol.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_radio.*" );
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_lower.*",
				"MOBILEMG42_lower",
				"DEFEND_plane.*",
				"MOBILEMG42_plane",
			});
		}
		Util.MapDebugPrint( "transmitter_obj_Returned" );
	},

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

	forwardspawn1_flag_Axis_Captured = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_.*" );

		Util.MapDebugPrint( "forwardspawn1_flag_Axis_Captured" );
	},

	forwardspawn1_flag_Allies_Captured = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_.*" );

		Util.MapDebugPrint( "forwardspawn1_flag_Allies_Captured" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allies have built the radio!", Map.Drop_Point_Radio_Construction_Built );
	OnTrigger( "Planted at the Drop Point Radio Construction", Map.Drop_Point_Radio_Construction_Planted );
	OnTrigger( "Planted at the Lower Door", Map.Lower_Door_Planted );
	OnTrigger( "Planted at the Upper Door", Map.Upper_Door_Planted );
	OnTrigger( "Defused at the Drop Point Radio Construction", Map.Drop_Point_Radio_Construction_Defused );
	OnTrigger( "Defused at the Lower Door", Map.Lower_Door_Defused );
	OnTrigger( "Defused at the Upper Door", Map.Upper_Door_Defused );
	OnTrigger( "Axis have destroyed the radio", Map.Drop_Point_Radio_Construction_Destroyed );
	OnTrigger( "Allies have destroyed the Lower Door", Map.Lower_Door_Destroyed );
	OnTrigger( "Allies have destroyed the Upper Door", Map.Upper_Door_Destroyed );
	OnTrigger( "Allies have stolen the Secret Weapon!", Map.transmitter_obj_Taken );
	OnTrigger( "Axis have returned the Secret Weapon!", Map.transmitter_obj_Returned );
	OnTrigger( "Allied team has secured the secret weapon!", Map.transmitter_obj_Secured );
	OnTrigger( "Axis reclaim the Forward Spawn!", Map.forwardspawn1_flag_Axis_Captured );
	OnTrigger( "Allies capture the Forward Spawn!", Map.forwardspawn1_flag_Allies_Captured );

	Util.SetGoalOffset( 0, 0, -50, "BUILD_Drop_Point_Radio_Construction" );

	Util.DisableGoal( ".*", true ); // all but routes

	Util.EnableGoal("FLAG.*");
	Util.EnableGoal("BUILD.*");
	Util.EnableGoal("PLANT.*");
	Util.EnableGoal("CHECKPOINT_.*");
	SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"MOUNTMG42_BunkerMG",
		"SNIPE_bunker",
		"DEFEND_radio.*",
		"DEFEND_obj.*",
	});
	Util.AddUseWp("PLANT_Drop_Point_Radio_Construction", "radio");
	Util.AddUseWp("PLANT_Drop_Point_Radio_Construction", "radio1");
	SetGoalPriority( "CHECKPOINT_.*", 0.49, 0, 0 ); //all teams and all classes
	SetGoalPriority( "CAPPOINT_Fake.*", 0.80 );

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

	// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=10, MaxCampTime=60} );
	//Map Routes
	MapRoutes =
	{
		BUILD_Drop_Point_Radio_Construction =
		{
			ROUTE_Allies_Spawn  =
			{
				ROUTE_NorthLD  =
				{
					ROUTE_NorthLD_1  =
					{
						ROUTE_NorthLD_2  =
						{
							ROUTE_NorthLD_3  =
							{
								ROUTE_NorthLD_4  =
								{
									ROUTE_NorthLD_5  =
									{
										ROUTE_NorthLD_6  =
										{
											ROUTE_NorthSplit  =
											{
												ROUTE_NorthWindow  =
												{
													ROUTE_Radio  =
													{
													},
												},
												ROUTE_South  =
												{
													ROUTE_South_1  =
													{
														ROUTE_South_2  =
														{
															ROUTE_South_3  =
															{
																ROUTE_South_4  =
																{
																	ROUTE_Radio  =
																	{
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_North  =
				{
					ROUTE_North_1  =
					{
						ROUTE_North_2  =
						{
							ROUTE_North_3  =
							{
								ROUTE_North_4  =
								{
									ROUTE_SouthStair_1  =
									{
										ROUTE_SouthStair_2  =
										{
											ROUTE_SouthStair_3  =
											{
												ROUTE_South_1  =
												{
													ROUTE_South_2  =
													{
														ROUTE_South_3  =
														{
															ROUTE_South_4  =
															{
																ROUTE_Radio  =
																{
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_West  =
				{
					ROUTE_West_1  =
					{
						ROUTE_WestSplit  =
						{
							ROUTE_NorthSplit  =
							{
								ROUTE_North_4  =
								{
									ROUTE_SouthStair_1  =
									{
										ROUTE_SouthStair_2  =
										{
											ROUTE_SouthStair_3  =
											{
												ROUTE_South_1  =
												{
													ROUTE_South_2  =
													{
														ROUTE_South_3  =
														{
															ROUTE_South_4  =
															{
																ROUTE_Radio  =
																{
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
			ROUTE_Flag  =
			{
				ROUTE_SouthStair  =
				{
					ROUTE_SouthStair_1  =
					{
						ROUTE_SouthStair_2  =
						{
							ROUTE_SouthStair_3  =
							{
								ROUTE_South_1  =
								{
									ROUTE_South_2  =
									{
										ROUTE_South_3  =
										{
											ROUTE_South_4  =
											{
												ROUTE_Radio  =
												{
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
		PLANT_Upper_Door =
		{
			ROUTE_Allies_Spawn  =
			{
				ROUTE_West  =
				{
					ROUTE_West_1  =
					{
						ROUTE_West_2  =
						{
							ROUTE_West_3  =
							{
								ROUTE_ramp  =
								{
									ROUTE_ramp_1  =
									{
										ROUTE_ramp_2  =
										{
											ROUTE_updoor  =
											{
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_WestLD  =
				{
					ROUTE_WestLD_1  =
					{
						ROUTE_WestLD_2  =
						{
							ROUTE_WestLD_3  =
							{
								ROUTE_WestLD_4  =
								{
									ROUTE_WestLD_5  =
									{
										ROUTE_updoor  =
										{
										},
									},
								},
							},
						},
					},
				},
			},
			ROUTE_Flag  =
			{
				ROUTE_SouthStair  =
				{
					ROUTE_SouthStair_1  =
					{
						ROUTE_ramp  =
						{
							ROUTE_ramp_1  =
							{
								ROUTE_ramp_2  =
								{
									ROUTE_updoor  =
									{
									},
								},
							},
						},
					},
				},
			},
		},
		PLANT_Lower_Door =
		{
			ROUTE_Allies_Spawn  =
			{
				ROUTE_North  =
				{
					ROUTE_North_1  =
					{
						ROUTE_North_2  =
						{
							ROUTE_North_3  =
							{
								ROUTE_North_4  =
								{
									ROUTE_North_5  =
									{
										ROUTE_North_6  =
										{
											ROUTE_North_7  =
											{
											},
										},
									},
								},
								ROUTE_NorthSplit  =
								{
									ROUTE_WestSplit  =
									{
										ROUTE_West_2  =
										{
											ROUTE_West_3  =
											{
												ROUTE_West_4  =
												{
												},
											},
										},
										ROUTE_WestLD_4  =
										{
											ROUTE_WestLD_5  =
											{
												ROUTE_updoor  =
												{
													ROUTE_ramp_2  =
													{
														ROUTE_ramp_1  =
														{
															ROUTE_ramp  =
															{
																ROUTE_West_3  =
																{
																	ROUTE_West_4  =
																	{
																	},
																},
																ROUTE_North_6  =
																{
																	ROUTE_North_7  =
																	{
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_NorthLD  =
				{
					ROUTE_NorthLD_1  =
					{
						ROUTE_NorthLD_2  =
						{
							ROUTE_NorthLD_4  =
							{
								ROUTE_NorthLD_5  =
								{
									ROUTE_NorthLD_6  =
									{
										ROUTE_NorthSplit  =
										{
											ROUTE_South  =
											{
												ROUTE_South_1  =
												{
													ROUTE_South_2  =
													{
														ROUTE_South_3  =
														{
															ROUTE_North_5  =
															{
																ROUTE_North_6  =
																{
																	ROUTE_North_7  =
																	{
																	},
																},
															},
														},
													},
												},
											},
										},
									},
									ROUTE_North_4  =
									{
										ROUTE_North_5  =
										{
											ROUTE_North_6  =
											{
												ROUTE_North_7  =
												{
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_West  =
				{
					ROUTE_West_1  =
					{
						ROUTE_West_2  =
						{
							ROUTE_West_3  =
							{
								ROUTE_West_4  =
								{
								},
							},
						},
					},
				},
				ROUTE_WestLD  =
				{
					ROUTE_WestLD_1  =
					{
						ROUTE_WestLD_2  =
						{
							ROUTE_WestLD_3  =
							{
								ROUTE_WestLD_4  =
								{
									ROUTE_WestLD_5  =
									{
										ROUTE_updoor  =
										{
											ROUTE_ramp_2  =
											{
												ROUTE_ramp_1  =
												{
													ROUTE_ramp  =
													{
														ROUTE_West_3  =
														{
															ROUTE_West_4  =
															{
															},
														},
														ROUTE_North_6  =
														{
															ROUTE_North_7  =
															{
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
		CAPPOINT_Plane =
		{
			ROUTE_North_7  =
			{
				ROUTE_North_6  =
				{
					ROUTE_PlaneA  =
					{
						ROUTE_PlaneA_1  =
						{
							ROUTE_PlaneA_2  =
							{
								ROUTE_PlaneA_3  =
								{
									ROUTE_PlaneA_4  =
									{
										ROUTE_PlaneA_5  =
										{
											ROUTE_Plane  =
											{
											},
										},
										ROUTE_PlaneASplit  =
										{
											ROUTE_PlaneASplit_1  =
											{
												ROUTE_PlaneASplit_2  =
												{
													ROUTE_PlaneOps  =
													{
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
			ROUTE_updoor  =
			{
				ROUTE_WestLD_5  =
				{
					ROUTE_WestLD_4  =
					{
						ROUTE_WestSplit  =
						{
							ROUTE_NorthSplit  =
							{
								ROUTE_North_4  =
								{
									ROUTE_SouthStair_1  =
									{
										ROUTE_SouthStair  =
										{
											ROUTE_Flag  =
											{
												ROUTE_PlaneB  =
												{
													ROUTE_PlaneB_1  =
													{
														ROUTE_PlaneB_2  =
														{
															ROUTE_PlaneA_5  =
															{
																ROUTE_Plane  =
																{
																},
															},
														},
													},
												},
											},
										},
									},
								},
								ROUTE_North_3  =
								{
									ROUTE_North_2  =
									{
										ROUTE_North_1  =
										{
											ROUTE_NorthLD_2  =
											{
												ROUTE_PlaneC  =
												{
													ROUTE_PlaneC_1  =
													{
														ROUTE_PlaneC_2  =
														{
															ROUTE_PlaneC_3  =
															{
																ROUTE_PlaneC_4  =
																{
																	ROUTE_PlaneC_5  =
																	{
																		ROUTE_PlaneC_6  =
																		{
																			ROUTE_PlaneC_7  =
																			{
																				ROUTE_PlaneC_8  =
																				{
																					ROUTE_PlaneC_9  =
																					{
																						ROUTE_PlaneOps  =
																						{
																						},
																					},
																				},
																				ROUTE_Plane  =
																				{
																				},
																			},
																		},
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
	};

	MapRoutes.CAPPOINT_Plane_1 = MapRoutes.CAPPOINT_Plane;

	Util.Routes(MapRoutes);

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 90.0;
};
