//==========================================================================================
//
//	pirates.gm (Final)
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	^4Tardis	24 May 2011	Initial Script
//	^4Tardis	07 Feb 2012	Routes Added
//==========================================================================================
//

global Map =
{
	Main_Entrance_Dyno = 0,
	Side_Entrance_Dyno = 0,
	Axis_Command_Post_Dyno = 0,
	Allied_Command_Post_Dyno = 0,

	Talk = true, //set Talk to false if you don't want the bots to cheer after winning game:

	Navigation =
	{
		jump =
		{
			navigate = function( _this )
			{
				_this.Bot.PressButton(BTN.JUMP);
				_this.Bot.HoldButton(BTN.FORWARD, 2);
				_this.Bot.HoldButton(BTN.SPRINT, 2);
				sleep(2);

				Util.MapDebugPrint("Yee-Ha!");
			},
		},
	},
	// /bot waypoint_setproperty paththrough Navigation_PT:jump

	Allied_Command_Post_Built = function()
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Command_Post" );
		Util.ChangeBotSpawn( bot, TEAM.ALLIES, 4, 3 );
		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},

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

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

	Allied_Command_Post_Destroyed = function()
	{

		Util.ChangeBotSpawn( bot, TEAM.ALLIES, 1);
		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},

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

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

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

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

	Main_Entrance_Planted = function()
	{
		Map.Main_Entrance_Dyno += 1;
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},

	Side_Entrance_Planted = function()
	{
		Map.Side_Entrance_Dyno += 1;
		Util.MapDebugPrint( "Side_Entrance_Planted" );
	},


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

	Side_Entrance_Defused = function()
	{
		Map.Side_Entrance_Dyno -= 1;
		Util.MapDebugPrint( "Side_Entrance_Defused" );
	},

	Main_Entrance_Destroyed = function()
	{
		Map.Main_Entrance_Dyno = 0;

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_main.*",
			"DEFEND_side.*",
			"MOUNTMG42.*",
			"REPAIRMG42.*",
			"PLANTMINE_.*",
		});
		SetGoalPriority( "DEFUSE_Side_Entrance.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, true);
		SetGoalPriority( "DEFUSE_Main_Entrance.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, true);
		SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_gold.*",
			"FLAG.*",
			"BUILD_Command_Post",
		});

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"FLAG.*",
			"CAPPOINT_gold",
			"BUILD_Command_Post",
			"PLANT_Command_Post",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"GRENADE_main",
			"CHECKPOINT.*",
		});

		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Side_Entrance_Destroyed = function()
	{
		Map.Side_Entrance_Dyno = 0;

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"CHECKPOINT.*",
			"DEFEND_main.*",
			"DEFEND_side.*",
			"MOUNTMG42.*",
			"REPAIRMG42.*",
			"PLANTMINE_.*",
		});
		SetGoalPriority( "DEFUSE_Main_Entrance.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, true);
		SetGoalPriority( "DEFUSE_Side_Entrance.*", 0.0, TEAM.AXIS, CLASS.ENGINEER, true);
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Command_Post",
			"DEFEND_gold.*",
			"FLAG.*",
		});

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"FLAG.*",
			"CAPPOINT_gold",
			"BUILD_Command_Post",
			"PLANT_Command_Post",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"GRENADE_main",
			"CHECKPOINT.*",
		});

		Util.MapDebugPrint( "Side_Entrance_Destroyed" );
	},

	goldcrate1_Taken = function()
	{
		//Switch Defend Spot
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_drop.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

		Util.MapDebugPrint( "goldcrate1_Taken" );
	},

	goldcrate2_Taken = function()
	{

		//Switch Defend Spot
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_drop.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

		Util.MapDebugPrint( "goldcrate2_Taken" );
	},

	goldcrate1_Returned = function()
	{

		//Switch Defend Spot
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_drop.*" );

		Util.MapDebugPrint( "goldcrate1_Returned" );
	},

	goldcrate2_Returned = function()
	{

		//Switch Defend Spot
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_drop.*" );

		Util.MapDebugPrint( "goldcrate2_Returned" );
	},

	goldcrate1_Secured = function()
	{
		//Switch Defend Spot Perm
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_drop.*",
			"MOBILEMG42_drop",
		});

		Util.MapDebugPrint( "goldcrate1_Secured" );
	},

	goldcrate2_Secured = function()
	{
		//Switch Defend Spot Perm
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_drop.*",
			"MOBILEMG42_drop",
		});

		Util.MapDebugPrint( "goldcrate2_Secured" );
	},

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

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

	AlliedWin = function()
	{
//Game Over
		if ( Map.Talk && MAP_TALK )
		{
			ETUtil.WinningChat( TEAM.ALLIES );
			ETUtil.LosingChat( TEAM.AXIS );
		}

		Util.MapDebugPrint( "Allies have Won!" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Planted at the Main Entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Planted at the Side Entrance.", Map.Side_Entrance_Planted );
	OnTrigger( "Defused at the Main Entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "Defused at the Side Entrance.", Map.Side_Entrance_Defused );
	OnTrigger( "Allies have breached the Main Entrance and secured the Old City!", Map.Main_Entrance_Destroyed );
	OnTrigger( "Allies have breached the Side Entrance and secured the Old City!", Map.Side_Entrance_Destroyed );
	OnTrigger( "Allies have stolen The Gold Crate!", Map.goldcrate1_Taken );
	OnTrigger( "Allies have stolen The Gold Crate!", Map.goldcrate2_Taken );
	OnTrigger( "Axis have returned The Gold Crate!", Map.goldcrate1_Returned );
	OnTrigger( "Axis have returned The Gold Crate!", Map.goldcrate2_Returned );
	OnTrigger( "Allied team has secured the first Gold Crate!", Map.goldcrate1_Secured );
	OnTrigger( "Allied team has secured the second Gold Crate!", Map.goldcrate2_Secured );
	OnTrigger( "Axis reclaim the Old City!", Map.flag_Axis_Captured );
	OnTrigger( "Allies capture the Old City!", Map.flag_Allies_Captured );
	OnTrigger( "Allied team secured both Gold Crates!", Map.AlliedWin );

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

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_main.*",
		"DEFEND_side.*",
		"PLANTMINE_.*",
		"MOUNTMG42.*",
		"REPAIRMG42.*",
		"CHECKPOINT.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"GRENADE_main",
		"PLANT_Main_Entrance",
		"PLANT_Side_Entrance",
		"CHECKPOINT.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANTMINE_.*" );

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

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

	Util.AddUseWp("PLANT_Main_Entrance", "main1");
	Util.AddUseWp("PLANT_Main_Entrance", "main2");
	Util.AddUseWp("PLANT_Main_Entrance", "main3");
	Util.AddUseWp("PLANT_Side_Entrance", "side");
	Util.AddUseWp("PLANT_Side_Entrance", "side1");
	Util.AddUseWp("PLANT_Side_Entrance", "side2");

	//set up some routing
	MapRoutes =
	{
		CHECKPOINT_flag =
		{
			ROUTE_AlliesSP  =
			{
				ROUTE_tunsplit  =
				{
					ROUTE_tunsplit2  =
					{
						ROUTE_botspilt  =
						{
							ROUTE_top  =
							{
								ROUTE_topA  =
								{
									ROUTE_topB  =
									{
										ROUTE_topC  =
										{
											ROUTE_flagA  =
											{
												ROUTE_flagin  =
												{
													ROUTE_flag  =
													{
													},
												},
												ROUTE_flagB  =
												{
													ROUTE_flag  =
													{
													},
												},
											},
										},
									},
								},
								ROUTE_outcorri  =
								{
									ROUTE_main  =
									{
										ROUTE_flagC  =
										{
											ROUTE_flag  =
											{
											},
										},
										ROUTE_flagB  =
										{
											ROUTE_flag  =
											{
											},
										},
									},
								},
							},
						},
						ROUTE_botmain  =
						{
							ROUTE_mainflag  =
							{
								ROUTE_flagA  =
								{
									ROUTE_flagin  =
									{
										ROUTE_flag  =
										{
										},
									},
									ROUTE_flagB  =
									{
										ROUTE_flag  =
										{
										},
									},
								},
							},
						},
						ROUTE_corrdor1  =
						{
							ROUTE_outcorri  =
							{
								ROUTE_main  =
								{
									ROUTE_flagC  =
									{
										ROUTE_flag  =
										{
										},
									},
								},
							},
							ROUTE_corrdor2  =
							{
								ROUTE_main  =
								{
									ROUTE_flagC  =
									{
										ROUTE_flag  =
										{
										},
									},
								},
							},
						},
					},
				},
			},
		},
		PLANT_Main_Entrance =
		{
			ROUTE_AlliesSP  =
			{
				ROUTE_tunsplit  =
				{
					ROUTE_tunsplit2  =
					{
						ROUTE_corrdor1  =
						{
							ROUTE_corrdor2  =
							{
								ROUTE_main  =
								{
								},
							},
							ROUTE_outcorri  =
							{
								ROUTE_main  =
								{
								},
							},
						},
					},
					ROUTE_botspilt  =
					{
						ROUTE_bot  =
						{
							ROUTE_botmain  =
							{
								ROUTE_mainflag  =
								{
									ROUTE_main  =
									{
									},
									ROUTE_flagA  =
									{
										ROUTE_flagB  =
										{
											ROUTE_main  =
											{
											},
										},
										ROUTE_flagin  =
										{
											ROUTE_flagC  =
											{
												ROUTE_main  =
												{
												},
											},
										},
									},
								},
							},
						},
						ROUTE_top  =
						{
							ROUTE_topA  =
							{
								ROUTE_topB  =
								{
									ROUTE_topC  =
									{
										ROUTE_flagA  =
										{
											ROUTE_flagB  =
											{
												ROUTE_main  =
												{
												},
											},
											ROUTE_flagin  =
											{
												ROUTE_flagC  =
												{
													ROUTE_main  =
													{
													},
												},
											},
										},
									},
								},
							},
							ROUTE_outcorri  =
							{
								ROUTE_main  =
								{
								},
							},
						},
					},
				},
			},
			ROUTE_flag  =
			{
				ROUTE_flagB  =
				{
					ROUTE_main  =
					{
					},
				},
				ROUTE_flagC  =
				{
					ROUTE_main  =
					{
					},
				},
			},
		},
		PLANT_Side_Entrance =
		{
			ROUTE_AlliesSP  =
			{
				ROUTE_tunsplit  =
				{
					ROUTE_tunsplit2  =
					{
					},
					ROUTE_botspilt  =
					{
						ROUTE_bot  =
						{
							ROUTE_botmain  =
							{
								ROUTE_mainflag  =
								{
									ROUTE_flagA  =
									{
										ROUTE_flagin  =
										{
											ROUTE_flag  =
											{
												ROUTE_flagC  =
												{
													ROUTE_side  =
													{
													},
												},
											},
										},
										ROUTE_flagB  =
										{
											ROUTE_flag  =
											{
												ROUTE_flagC  =
												{
													ROUTE_side  =
													{
													},
												},
											},
											ROUTE_flagC  =
											{
												ROUTE_side  =
												{
												},
											},
										},
									},
									ROUTE_main  =
									{
										ROUTE_flagC  =
										{
											ROUTE_side  =
											{
											},
										},
									},
								},
							},
						},
						ROUTE_top  =
						{
							ROUTE_topA  =
							{
								ROUTE_topB  =
								{
									ROUTE_topC  =
									{
										ROUTE_flagA  =
										{
											ROUTE_flagB  =
											{
												ROUTE_flag  =
												{
													ROUTE_flagC  =
													{
														ROUTE_side  =
														{
														},
													},
												},
											},
											ROUTE_flagin  =
											{
												ROUTE_flag  =
												{
													ROUTE_flagC  =
													{
														ROUTE_side  =
														{
														},
													},
												},
											},
										},
									},
								},
							},
							ROUTE_outcorri  =
							{
								ROUTE_main  =
								{
									ROUTE_flagC  =
									{
										ROUTE_side  =
										{
										},
									},
								},
							},
						},
					},
				},
			},
			ROUTE_flag  =
			{
				ROUTE_flagC  =
				{
					ROUTE_side  =
					{
					},
				},
			},
		},
		FLAG_goldcrate1 =
		{
			ROUTE_flag  =
			{
				ROUTE_flagB  =
				{
					ROUTE_main  =
					{
						ROUTE_mainA  =
						{
							ROUTE_rivertop  =
							{
							},
						},
						ROUTE_mainB  =
						{
							ROUTE_mainA  =
							{
								ROUTE_rivertop  =
								{
								},
							},
						},
					},
				},
				ROUTE_flagC  =
				{
					ROUTE_side  =
					{
						ROUTE_sidetop  =
						{
							ROUTE_side2truck  =
							{
								ROUTE_outbot  =
								{
									ROUTE_goldexit  =
									{
										ROUTE_boat  =
										{
										},
									},
								},
							},
						},
					},
				},
			},
		},
		FLAG_goldcrate2 =
		{
			ROUTE_flag  =
			{
				ROUTE_flagB  =
				{
					ROUTE_main  =
					{
						ROUTE_mainA  =
						{
							ROUTE_rivertop  =
							{
								ROUTE_cpboat  =
								{
									ROUTE_boat  =
									{
									},
								},
								ROUTE_boat  =
								{
								},
							},
						},
						ROUTE_mainB  =
						{
							ROUTE_mainA  =
							{
								ROUTE_rivertop  =
								{
									ROUTE_cpboat  =
									{
										ROUTE_boat  =
										{
										},
									},
									ROUTE_boat  =
									{
									},
								},
							},
						},
					},
				},
				ROUTE_flagC  =
				{
					ROUTE_side  =
					{
						ROUTE_sidetop  =
						{
							ROUTE_side2truck  =
							{
								ROUTE_outbot  =
								{
									ROUTE_goldexit  =
									{
										ROUTE_boat  =
										{
										},
									},
								},
							},
						},
					},
				},
			},
		},
		CAPPOINT_gold =
		{
			ROUTE_boat  =
			{
				ROUTE_goldexit  =
				{
				},
				ROUTE_goldexitwater  =
				{
					ROUTE_goldexit1  =
					{
						ROUTE_outbot  =
						{
							ROUTE_trucklow  =
							{
								ROUTE_truckhigh  =
								{
								},
							},
							ROUTE_side2truck  =
							{
							},
						},
					},
					ROUTE_goldexit2  =
					{
						ROUTE_outbot  =
						{
							ROUTE_trucklow  =
							{
								ROUTE_truckhigh  =
								{
								},
							},
							ROUTE_side2truck  =
							{
								ROUTE_sidetop  =
								{
									ROUTE_truckhigh  =
									{
									},
								},
							},
						},
					},
					ROUTE_goldexit3  =
					{
						ROUTE_outbot  =
						{
							ROUTE_trucklow  =
							{
								ROUTE_truckhigh  =
								{
								},
							},
							ROUTE_side2truck  =
							{
								ROUTE_sidetop  =
								{
									ROUTE_truckhigh  =
									{
									},
								},
							},
						},
					},
					ROUTE_goldexitback  =
					{
						ROUTE_cpboat  =
						{
							ROUTE_cpdoor  =
							{
								ROUTE_CP  =
								{
									ROUTE_mainA  =
									{
										ROUTE_main  =
										{
											ROUTE_flagC  =
											{
												ROUTE_side  =
												{
													ROUTE_sidetop  =
													{
														ROUTE_side2truck  =
														{
															ROUTE_trucklow  =
															{
																ROUTE_truckhigh  =
																{
																},
															},
														},
														ROUTE_truckhigh  =
														{
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
				ROUTE_rivertop  =
				{
					ROUTE_riverbot  =
					{
						ROUTE_sidetop  =
						{
							ROUTE_side2truck  =
							{
								ROUTE_trucklow  =
								{
									ROUTE_truckhigh  =
									{
									},
								},
							},
							ROUTE_truckhigh  =
							{
							},
						},
					},
				},
			},
		},
		DEFEND_gold =
		{
			ROUTE_axisSP  =
			{
				ROUTE_outtop  =
				{
					ROUTE_outtopA  =
					{
						ROUTE_goldexit  =
						{
						},
					},
					ROUTE_outtopB  =
					{
						ROUTE_outbot  =
						{
							ROUTE_goldexit  =
							{
							},
						},
					},
					ROUTE_outbot  =
					{
						ROUTE_side2truck  =
						{
							ROUTE_trucklow  =
							{
								ROUTE_truckhigh  =
								{
								},
							},
						},
					},
				},
			},
		},
		DEFEND_drop =
		{
			ROUTE_axisSP  =
			{
				ROUTE_outtop  =
				{
					ROUTE_outtopA  =
					{
						ROUTE_side2truck  =
						{
							ROUTE_trucklow  =
							{
								ROUTE_truckhigh  =
								{
								},
							},
						},
					},
					ROUTE_outtopB  =
					{
						ROUTE_sidetop  =
						{
							ROUTE_truckhigh  =
							{
							},
							ROUTE_side2truck  =
							{
								ROUTE_trucklow  =
								{
									ROUTE_truckhigh  =
									{
									},
								},
							},
						},
					},
					ROUTE_outbot  =
					{
						ROUTE_side2truck  =
						{
							ROUTE_trucklow  =
							{
								ROUTE_truckhigh  =
								{
								},
							},
						},
					},
				},
			},
		},
	};

	//copy some routes
	MapRoutes.DEFEND_drop_1 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_2 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_3 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_4 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_5 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_6 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_7 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_8 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_9 = MapRoutes.DEFEND_drop;
	MapRoutes.DEFEND_drop_10 = MapRoutes.DEFEND_drop;

	MapRoutes.DEFEND_gold_1 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_2 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_3 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_4 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_5 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_6 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_7 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_8 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_9 = MapRoutes.DEFEND_gold;
	MapRoutes.DEFEND_gold_10 = MapRoutes.DEFEND_gold;

	Util.Routes(MapRoutes);

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

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

	// CP spawn
	Util.ChangeBotSpawn( bot, TEAM.ALLIES, 4, 3 );
};
