/********************************************************
I found some old waypoints and made a script for them.
Script by Santa Claus a.k.a. :)BOK(: Naerling
Many thanks to the christmas elves d00d and crapshoot for their work on the tram! :D
********************************************************/

global Map =
{
	Debug = false,
	Quiet = true,
	//set Talk to false if you don't want the bots talking ingame:
	Talk = true,
	AxisCapture = false,

	MaxTramRiders = 1,
	Movers =
	{
		"MOVER_cablecar",
	},

	//Goals
	Ammo_Cabinet_alliedhut_ammocabinet = "AMMOCAB_alliedhut_ammocabinet",
	Ammo_Cabinet_t1096 = "AMMOCAB_t1096",
	Health_Cabinet_alliedhut_healthcabinet = "HEALTHCAB_alliedhut_healthcabinet",
	Health_Cabinet_t1095 = "HEALTHCAB_t1095",
	Checkpoint_roadbunker = "CHECKPOINT_roadbunker",
	Flag_star = "FLAG_star",
	Build_Command_Post = "BUILD_Command_Post",
	Build_Guardhouse = "BUILD_Guardhouse",
	Build_Road_MG = "BUILD_Road_MG",
	Build_Town_Door = "BUILD_Town_Door",
	Cappoint_Sleigh = "CAPPOINT_Sleigh",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_Guardhouse = "PLANT_Guardhouse",
	Plant_Road_MG = "PLANT_Road_MG",
	Plant_Town_Door = "PLANT_Town_Door",
	Plant_Tunnel_Entrance = "PLANT_Tunnel_Entrance",
	Mount_36 = "MOUNTMG42_36",
	Mount_Guardhouse = "MOUNTMG42_Guardhouse",
	Mount_Road_MG = "MOUNTMG42_Road_MG",
	Repair_36 = "REPAIRMG42_36",
	Repair_Guardhouse = "REPAIRMG42_Guardhouse",
	Repair_Road_MG = "REPAIRMG42_Road_MG",
	Call_Artillery_ax_callarty_1 = "CALLARTILLERY_ax_callarty_1",
	Call_Artillery_ax_callarty_2 = "CALLARTILLERY_ax_callarty_2",
	Artillery_S_ax_arty_1 = "ARTILLERY_S_ax_arty_1",
	Artillery_S_ax_arty_2 = "ARTILLERY_S_ax_arty_2",
	Artillery_S_ax_arty_2 = "ARTILLERY_S_ax_arty_3",
	Call_Artillery_al_callarty_1 = "CALLARTILLERY_al_callarty_1",
	Artillery_S_al_arty_1 = "ARTILLERY_S_al_arty_1",
	Artillery_S_al_arty_2 = "ARTILLERY_S_al_arty_2",
	Mobile_MG42_d_door_2 = "MOBILEMG42_d_door_2",
	Snipe_al_snipe_1 = "SNIPE_al_snipe_1",

	//Tram Stuff
	TramEntity = GetGoal("MOVER_cablecar").GetEntity(),
	Navigation =
	{
		tramwait =
		{
			navigate = function(_this)
			{
				_this.Bot.HoldButton( BTN.CROUCH, 99 );
				counter = 0;
				readyToExit = false;
				while(!readyToExit)
				{
					counter += 50;
					absPos = GetEntityWorldSpace(Map.TramEntity,Vector3(9,46,-192));

					// change the aim position half way so they are facing the right way
					if ( counter < 8000  )
					{
						aimPos = GetEntityWorldSpace(Map.TramEntity,Vector3(83,0.394, -180));
					}
					else
					{
						aimPos = GetEntityWorldSpace(Map.TramEntity,Vector3(-89,5.5, -180));
					}

					_this.AddAimRequest(Priority.High, "position", aimPos);
					_this.Bot.MoveTowards(absPos);
					_this.GotoAsync(absPos, 1000);

					if ( Map.TramStatus == "arrived" )
					{
						if ( counter >= 16500 )
						{
							readyToExit = true;
						}
					}
					yield();
				}
				_this.ReleaseAimRequest();
				_this.Bot.ReleaseButton(BTN.CROUCH);
			},
		},

		jump_pt =
		{
			navigate = function(_this)
			{
				_this.Bot.PressButton(BTN.JUMP);
				sleep(0.25);
			},
		},
	},

	TramStatus = "waiting",
	Switches =
	{
		tramswitch1 =
		{
			Enabled = true,
			Priority = 0,
			WaypointName = "tram1",
			Timeout = 2000,
			AimPosition = Vector3(2459.875,3478.388,1301.885), // for 0.8
		},

		tramswitch2 =
		{
			Enabled = true,
			Priority = 0,
			WaypointName = "tram2",
			Timeout = 2000,
		},
	},

	Riders = 0,
	Tram_Riders =
	{
		Name = "Tram_Riders",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			Map.Riders += 1;
			if ( Map.Riders >= Map.MaxTramRiders )
			{
				Wp.SetWaypointFlag( "tram2", "closed", true );
			}
		},
		OnExit = function(ent)
		{
			Map.Riders -= 1;
			if ( Map.Riders < Map.MaxTramRiders )
			{
				Wp.SetWaypointFlag( "tram2", "closed", false );
			}
		},
	},

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

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

	//First Stage
	roadbunker_Axis_Captured = function( trigger )
	{
		AxisCapture = true;
		SetAvailableMapGoals( TEAM.AXIS, false, {
			Map.Plant_Tunnel_Entrance,
			Map.Mount_36,
			Map.Repair_36,
			"CALLARTILLERY_ax_callarty_1",
			"CALLARTILLERY_ax_callarty_2",
			"ARTILLERY_S_ax_arty_1",
			"ARTILLERY_S_ax_arty_2",
			"ARTILLERY_S_ax_arty_3",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			Map.Flag_star,
			Map.Plant_Guardhouse,
			Map.Plant_Town_Door,
			Map.Plant_Command_Post,
			Map.Build_Command_Post,
			"ATTACK_a_door_.*",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			Map.Build_Guardhouse,
			Map.Mount_Guardhouse,
			Map.Repair_Guardhouse,
			"DEFEND_d_flag_.*",
			"CALLARTILLERY_al_callarty_1",
			"ARTILLERY_S_al_arty_1",
			"ARTILLERY_S_al_arty_2",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			Map.Build_Road_MG,
			Map.Mount_Road_MG,
			Map.Repair_Road_MG,
			"DEFEND_d_tram_1",
			"DEFEND_d_star_.*",
			"MOBILEMG42_.*",
			"SNIPE_.*",
		});

		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.ExecCommand("vsay_team FTFollowMe");
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.SayVoice(VOICE.REINFORCE_OFF);
					}
				}
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.DEFEND_OBJECTIVE);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.SayVoice("VOICE.NEGATIVE");
					}
				}
			}
		}

		Util.MapDebugPrint( "roadbunker_Axis_Captured" );
	},

	roadbunker_Allies_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, {
			Map.Flag_star,
			Map.Plant_Guardhouse,
			Map.Plant_Road_MG,
			Map.Plant_Town_Door,
			Map.Plant_Command_Post,
			Map.Build_Command_Post,
			"ATTACK_a_door_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"CALLARTILLERY_ax_callarty_1",
			"CALLARTILLERY_ax_callarty_2",
			"ARTILLERY_S_ax_arty_1",
			"ARTILLERY_S_ax_arty_2",
			"ARTILLERY_S_ax_arty_3",
			Map.Plant_Tunnel_Entrance,
			Map.Mount_36,
			Map.Repair_36,
		});

		SetAvailableMapGoals( TEAM.ALLIES, true, {
			Map.Build_Guardhouse,
			Map.Mount_Guardhouse,
			Map.Repair_Guardhouse,
			Map.Build_Road_MG,
			Map.Mount_Road_MG,
			Map.Repair_Road_MG,
			"CALLARTILLERY_al_callarty_1",
			"ARTILLERY_S_al_arty_1",
			"ARTILLERY_S_al_arty_2",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			Map.Build_Road_MG,
			Map.Mount_Road_MG,
			Map.Repair_Road_MG,
			"DEFEND_d_tram_.*",
			"DEFEND_d_star_.*",
			"MOBILEMG42_.*",
			"SNIPE_.*",
		});

		if( Map.AxisCapture )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_d_flag_.*" );
		}

		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.ExecCommand("vsay_team FTFallBack");
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.SayVoice("VOICE.NEGATIVE");
					}
				}
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.DEFEND_OBJECTIVE);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTAttack");
					}
				}
			}
		}

		Util.MapDebugPrint( "roadbunker_Allies_Captured" );
	},

	Tunnel_Entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "ROUTE_Cave" );

		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_d_flag_.*" );

		Util.MapDebugPrint( "Tunnel_Entrance_Destroyed" );
	},

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

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

	//Second Stage
	Town_Door_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "ROUTE_Door" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_a_door_.*" );

		SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_roadbunker" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_d_door_.*",
			"DEFEND_d_star_.*",
		});

		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.ExecCommand("vsay_team FTAttack");
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.SayVoice(VOICE.REINFORCE_OFF);
					}
				}
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.DEFEND_OBJECTIVE);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.SayVoice(VOICE.REINFORCE_OFF);
					}
				}
			}
		}

		Util.MapDebugPrint( "Town_Door_Built" );
	},

	Town_Door_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "ROUTE_Door" );
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_a_door_.*" );

		SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_roadbunker" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"DEFEND_d_door_.*",
			"DEFEND_d_star_.*",
		});

		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.AXIS )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.ExecCommand("vsay_team FTFollowMe");
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.SayVoice(VOICE.REINFORCE_OFF);
					}
				}
				if ( bot.GetTeam() == TEAM.ALLIES )
				{
					r = RandRange(0,10);
					if( r < 2 )
					{
						bot.SayVoice(VOICE.DEFEND_OBJECTIVE);
					}
					else if( r > 8 )
					{
						sleep(1.2);
						bot.ExecCommand("vsay_team FTFallBack");
					}
				}
			}
		}

		Util.MapDebugPrint( "Town_Door_Destroyed" );
	},

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

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

	//Star Stuff
	star_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_a_cap_.*" );

		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_d_cap_.*" );

		Util.MapDebugPrint( "star_Taken" );
	},

	star_Returned = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_a_cap_.*" );

		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_d_cap_.*" );

		Util.MapDebugPrint( "star_Returned" );
	},

	axis_Win = function( trigger )
	{
		ETUtil.WinningChat( TEAM.AXIS );
		ETUtil.LosingChat( TEAM.ALLIES );
		Util.MapDebugPrint( "axis_Win" );
	},

	allies_Win = function( trigger )
	{
		ETUtil.WinningChat( TEAM.ALLIES );
		ETUtil.LosingChat( TEAM.AXIS );
		Util.MapDebugPrint( "allies_Win" );
	},

	//Some more tram stuff
	Tram_Moving = function( trigger )
	{
		if ( trigger.Action == "opening" )
		{
			Map.TramStatus = "moving";
			Map.Switches.tramswitch1.Enabled = false;
			Util.MapDebugPrint("tram moving");
		}
	},

	Tram_Waiting = function( trigger )
	{
		vec = ToVector( trigger.Action );
		if ( vec.x == -100 )
		{
			Map.TramStatus = "waiting";
			Map.Switches.tramswitch1.Enabled = true;
			Util.MapDebugPrint("tram waiting");
		}
		else if ( vec.y == -100 )
		{
			Map.TramStatus = "arrived";
			Util.MapDebugPrint("tram arrived");
		}
	},
};

global OnMapLoad = function()
{
	//Move some goals
	Util.SetGoalOffset( -35, 0, -20, "BUILD_Guardhouse" );
	Util.SetGoalOffset( 0, -35, -20, "BUILD_Town_Door" );
	Util.SetGoalOffset( 0, 20, -80, "PLANT_Town_Door" );

	//Triggers
	OnTrigger( "MISSING_STRING", Map.Command_Post_Built );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Destroyed );

	//First Stage
	OnTrigger( "Axis capture the North Pole!", Map.roadbunker_Axis_Captured );
	OnTrigger( "Allies capture the North Pole!", Map.roadbunker_Allies_Captured );
	OnTrigger( "Axis team have breached the Tunnel Entrance!", Map.Tunnel_Entrance_Destroyed );
	OnTrigger( "The high Guardtower have been built.", Map.Guardhouse_Built );
	OnTrigger( "The high Guardtower have been destroyed!", Map.Guardhouse_Destroyed );

	//Second Stage
	OnTrigger( "The Town Door have been built.", Map.Town_Door_Built );
	OnTrigger( "The Town Door have been destroyed!", Map.Town_Door_Destroyed );
	OnTrigger( "Allied team has constructed the Road MG Nest!", Map.Road_MG_Built );
	OnTrigger( "Axis team has destroyed the Road MG Nest!", Map.Road_MG_Destroyed );

	//Star Stuff
	OnTrigger( "Axis has stolen the Christmas Star!", Map.star_Taken );
	OnTrigger( "Flag returned star!", Map.star_Returned );
	OnTrigger( "The Axis team have escaped with the Christmas Star!", Map.axis_Win );
	OnTrigger( "Allied team has stopped the Axis from stealing the Christmas Star!", Map.allies_Win );

	//Set up triggers for the tram
	OnTrigger( "cablecar_goto", Map.Tram_Waiting );
	OnTrigger( "cable_button_Moving", Map.Tram_Moving );

	//Tram riders
	tr = OnTriggerRegion(AABB(2323.125,3267.125,1267.125,2504.838,3446.658,1385.458), Map.Tram_Riders);

	//Enable Switches
	Util.UpdateSwitchData();

	//Disable Goals
	Util.DisableGoal( ".*", true ); //All but routes

	//Goals at start
	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		Map.Checkpoint_roadbunker,
		Map.Build_Town_Door,
		Map.Build_Command_Post,
		Map.Plant_Command_Post,
		Map.Build_Guardhouse,
		Map.Mount_Guardhouse,
		Map.Repair_Guardhouse,
		"DEFEND_d_flag_.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"DEFEND_d_flag_6",
		"DEFEND_d_flag_7",
		"DEFEND_d_flag_9",
		"DEFEND_d_flag_11",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"CALLARTILLERY_al_callarty_1",
		"ARTILLERY_S_al_arty_1",
		"ARTILLERY_S_al_arty_2",
	});

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, true, {
		Map.Plant_Tunnel_Entrance,
		Map.Checkpoint_roadbunker,
		Map.Mount_36,
		Map.Repair_36,
		"CAPPOINT_Sleigh",
		"CALLARTILLERY_ax_callarty_1",
		"CALLARTILLERY_ax_callarty_2",
		"ARTILLERY_S_ax_arty_1",
		"ARTILLERY_S_ax_arty_2",
		"ARTILLERY_S_ax_arty_3",
	});

	//Set some goal properties
	Util.SetMaxUsersInProgress( 1, "BUILD.*" );
	Util.SetMaxUsersInProgress( 2, "PLANT_.*" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 1, "ATTACK_.*" );
	Util.SetMaxUsersInProgress( 1, "MOUNTMG42_.*" );

	SetMapGoalProperties( "ATTACK_.*", {mincamptime=60, maxcamptime=120} );
	SetMapGoalProperties( "DEFEND_.*", {mincamptime=60, maxcamptime=120} );
	SetMapGoalProperties( "MOUNTMG42_.*", {mincamptime=120, maxcamptime=120} );
	SetMapGoalProperties( "MOBILEMG42_.*", {mincamptime=120, maxcamptime=120} );
	SetMapGoalProperties( "SNIPE_.*", {mincamptime=120, maxcamptime=120} );

	//Priority Main Goals
	SetGoalPriority( "CHECKPOINT.*", 0.55 );
	SetGoalPriority( "MOUNT.*", 0.6 );
	SetGoalPriority( "PLANT_Town_Door", 0.91 );
	SetGoalPriority( "BUILD_Town_Door", 0.91 );
	SetGoalPriority( "DEFEND_d_star_1", 0.7 );
	SetGoalPriority( "DEFEND_d_star_2", 0.7 );
	SetGoalPriority( "DEFEND_d_star_3", 0.7 );
	SetGoalPriority( "DEFEND_d_cap_.*", 0.9 );
	SetGoalPriority( "ATTACK_a_cap_.*", 0.9 );
	SetGoalPriority( "MOBILEMG42_.*", 0.56 );
	SetGoalPriority( "SNIPE_.*", 0.56 );

	//Disable some routes
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"ROUTE_Cave",
		"ROUTE_Door",
	});

	//Routes
	MapRoutes =
	{
		CHECKPOINT_roadbunker =
		{
			ROUTE_Axis_Spawn =
			{
				ROUTE_Hill_Left = {},
				ROUTE_Hill_Right = {},
				ROUTE_Cave = {},
			},
			ROUTE_Allied_Spawn =
			{
				ROUTE_Tram_Lower = {},
				ROUTE_Gate_Upper = {},
			},
		},

		FLAG_star =
		{
			ROUTE_House_Spawn =
			{
				ROUTE_Door = {},
				Weight = 2,
				ROUTE_Door =
				{
					ROUTE_DiningRoom =
					{
						ROUTE_Barrels = {},
						ROUTE_Packages = {},
						ROUTE_Packages2 = {},
					},
				},
				ROUTE_TramRoute = {},
				ROUTE_TramRoute =
				{
					ROUTE_DiningRoom =
					{
						ROUTE_Barrels = {},
						ROUTE_Packages = {},
						ROUTE_Packages2 = {},
					},
				},
			},
		},
	};

	Util.Routes(MapRoutes);
	Util.MapDebugPrint( "Botscript for ^1North Pole ^2by ^0:)^1BOK^0(: ^1Naerling ^2was successfully loaded!" );
};

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