//==========================================================================================
//
//	school.gm
//
//	Who  	When		What
//------------------------------------------------------------------------------------------
//	^4Tardis	29 January 2011	Initial Script
//	^4Tardis 	25 September 2011 - Fixes
//==========================================================================================
//

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

	Assault_ramp_Dyno = 0,
	Tank_Barrier_1_Dyno = 0,
	Truck_Barrier_1_Dyno = 0,
	Allied_Command_Post_Dyno = 0,
	Axis_Command_Post_Dyno = 0,

	Tank_Built = false, // Not Built at Start
	Truck_Built = true, //Built at Start
	Book = false, //Not Secured Record
	Tank_Barrier = false, // Not Built
	Truck_Barrier = false, // Not Built
	Talk = true, //set Talk to false if you don't want the bots to cheer after winning game:

	Movers =
	{
		"MOVER_tank",
		"MOVER_truck",
	},

	Roles =
	{
		AXIS = // Team
		{
			AllBots = true, // each bot is considered for a role
			DEFENDER = // the DEFENDER role
			{
				spawnpt = 1,			// users of this role will choose spawnpt 1
				numbots = 3,			// maximum of 3 bots
				crucialClass = CLASS.MEDIC,	// first bot
			},
		},
	},

	TankTrigger =
	{
		TriggerOnEntity = GetGoal("MOVER_tank").GetEntity(),

		OnEnter = function(ent)
		{
			SetAvailableMapGoals( TEAM.AXIS, true, {
				"MOUNT_AXIS",
				"AIRSTRIKE_barrier",
				"CALLARTILLERY_barrier",
				"ARTILLERY_S_barrier",
			});

			Util.MapDebugPrint( "Tank_Entered" );
		},
		OnExit = function(ent)
		{

			Util.MapDebugPrint( "Tank_Exited" );
		},
	},

	TankBarrierTrigger =
	{
		TriggerOnEntity = GetGoal("MOVER_tank").GetEntity(),

		OnEnter = function(ent)
		{

			if( Map.Tank_Barrier == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, {
					"ESCORT_Tank",
					"BUILD_Tank",
				});
				SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Tank_Barrier_1" );
				Util.MapDebugPrint( "Not Escorting / Building Tank" );
			}
			else if ( Map.Tank_Barrier == false )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"ESCORT_Tank",
					"BUILD_Tank",
				});
				Util.MapDebugPrint( "Escorting / Building Tank" );
			}

			Util.MapDebugPrint( "Tank_Entered_Barrier" );
		},
		OnExit = function(ent)
		{

			Util.MapDebugPrint( "Tank_Exited_Barrier" );
		},
	},

	TruckBarrierTrigger =
	{
		TriggerOnEntity = GetGoal("MOVER_truck").GetEntity(),

		OnEnter = function(ent)
		{
			if( Map.Truck_Barrier == true )
			{
				SetAvailableMapGoals( TEAM.ALLIES, false, {
					"ESCORT_Truck",
					"BUILD_Truck",
				});
				SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Truck_Barrier_1" );

				Util.MapDebugPrint( "Not Escorting / Building Truck" );
			}
			else if ( Map.Truck_Barrier == false )
			{
				SetAvailableMapGoals( TEAM.ALLIES, true, {
					"ESCORT_Truck",
					"BUILD_Truck",
				});
				Util.MapDebugPrint( "Escorting / Building Truck" );
			}

			Util.MapDebugPrint( "Truck_Entered_Barrier" );
		},
		OnExit = function(ent)
		{

			Util.MapDebugPrint( "Truck_Exited_Barrier" );
		},
	},

	Allied_Command_Post_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Command_Post" );
		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 )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );
		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" );
	},

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

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

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

	Assault_ramp_Destroyed = function( trigger )
	{
		Map.Assault_ramp_Dyno = 0;

		Util.MapDebugPrint( "Assault_ramp_Destroyed" );
	},

	Tank_Built = function( trigger )
	{
		Map.Tank_Built = true;
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ESCORT_Tank",
			"MOUNT_Tank",
		});
		Util.MapDebugPrint( "Tank_Built" );
	},

	Tank_Destroyed = function( trigger )
	{
		Map.Tank_Built = false;
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank" );
		Util.MapDebugPrint( "Tank_Destroyed" );
	},

	Tank_Barrier_1_Built = function( trigger )
	{
		Map.Tank_Barrier = true;
		Util.MapDebugPrint( "Tank_Barrier_1_Built" );
	},

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

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

	Tank_Barrier_1_Destroyed = function( trigger )
	{
		Map.Tank_Barrier_1_Dyno = 0;
		Map.Tank_Barrier = false;
		Util.MapDebugPrint( "Tank_Barrier_1_Destroyed" );
	},

	Truck_Built = function( trigger )
	{
		//built at start
		Map.Truck_Built = true;
		Util.MapDebugPrint( "Truck_Built" );
	},

	Truck_Destroyed = function( trigger )
	{
		Map.Truck_Built = false;
		if ( Map.Book == true )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Truck" );
		}
		SetAvailableMapGoals( TEAM.AXIS, false, "GRENADE_truck" );
		Util.MapDebugPrint( "Truck_Destroyed" );
	},

	Truck_Barrier_1_Built = function( trigger )
	{
		Map.Truck_Barrier = true;
		Util.MapDebugPrint( "Truck_Barrier_1_Built" );
	},

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

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

	Truck_Barrier_1_Destroyed = function( trigger )
	{
		Map.Truck_Barrier_1_Dyno = 0;
		Map.Truck_Barrier = false;
		if ( Map.Book == true )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, "ESCORT_truck" );
		}
		Util.MapDebugPrint( "Truck_Barrier_1_Destroyed" );
	},

	School_record_Taken = function( trigger )
	{
		Map.Book = false;
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"MOUNTMG42_Bunker",
			"REPAIRMG42_Bunker",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"MOUNTMG42_School.*",
			"REPAIRMG42_School.*",
			"CAMP_Doc.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_barrier.*" );

		Util.MapDebugPrint( "School_record_Taken" );
	},

	School_record_Returned = function( trigger )
	{
		Map.Book = false;
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"MOUNTMG42_Bunker",
			"REPAIRMG42_Bunker",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"MOUNTMG42_School.*",
			"REPAIRMG42_School.*",
			"CAMP_Doc.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_barrier.*" );

		Util.MapDebugPrint( "School_record_Returned" );
	},

	School_record_Secured = function( trigger )
	{
		Map.Book = true;
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Assault_ramp" );
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Assault_ramp" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ESCORT_truck",
			"BUILD_Truck",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "CAMP_Doc.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_barrier.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"BUILD_Command_Post",
			"PLANT_Command_Post",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_blockade.*" );
		Util.MapDebugPrint( "School_record_Secured" );
	},

	Backdoor_Unlocked = function( trigger )
	{
		Util.DisableGoal( "BUILD_Tank" );
		Util.DisableGoal( "MOUNT_Tank" );
		Util.DisableGoal( "MOUNT_AXIS" );
		Util.DisableGoal( "ESCORT_Tank" );

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_school.*",
			"MOBILEMG42_school",
			"AIRSTRIKE_barrier",
			"CALLARTILLERY_barrier",
			"ARTILLERY_S_barrier",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "ESCORT_Tank" );
		SetAvailableMapGoals( TEAM.AXIS, false, "MOUNT_AXIS" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"MOUNT_Tank",
			"BUILD_Tank",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Assault_ramp",
			"CAPPOINT_Book",
			"BUILD_Truck",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"BUILD_Truck_Barrier_1",
			"PLANT_Assault_ramp",
			"CAMP_Doc.*",
		});

		Util.EnableGoal( "FLAG_School_record" );

		Util.MapDebugPrint( "Backdoor_Unlocked" );
	},

	Tank_passed = function( trigger )
	{
		Util.DisableGoal( "AMMOCAB_t1075b" );
		Util.DisableGoal( "HEALTHCAB_t1074b" );

		Util.MapDebugPrint( "Tank Passed The Barrier!" );
	},

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

		Util.MapDebugPrint( "Allied_Win" );
	},
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Assault ramp has been constructed", Map.Assault_ramp_Built );
	OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "Tank Barrier #1 has been constructed.", Map.Tank_Barrier_1_Built );
	OnTrigger( "The Truck has been repaired!", Map.Truck_Built );
	OnTrigger( "Truck Barrier #1 has been constructed.", Map.Truck_Barrier_1_Built );
	OnTrigger( "Planted at the Assault ramp", Map.Assault_ramp_Planted );
	OnTrigger( "Planted at the Tank Barrier #1", Map.Tank_Barrier_1_Planted );
	OnTrigger( "Planted at the Truck Barrier #1", Map.Truck_Barrier_1_Planted );
	OnTrigger( "Defused at the Assault ramp", Map.Assault_ramp_Defused );
	OnTrigger( "Defused at the Tank Barrier #1", Map.Tank_Barrier_1_Defused );
	OnTrigger( "Defused at the Truck Barrier #1", Map.Truck_Barrier_1_Defused );
	OnTrigger( "Assault ramp has been destroyed", Map.Assault_ramp_Destroyed );
	OnTrigger( "Tank Barrier #1 has been destroyed.", Map.Tank_Barrier_1_Destroyed );
	OnTrigger( "Truck Barrier #1 has been destroyed.", Map.Truck_Barrier_1_Destroyed );
	OnTrigger( "Allies have stolen The School record!", Map.School_record_Taken );
	OnTrigger( "Axis have returned The School record!", Map.School_record_Returned );
	OnTrigger( "Allied team is escaping with the School record!", Map.School_record_Secured );
	OnTrigger( "Backdoor are unlocked!", Map.Backdoor_Unlocked );
	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( "Planted at the Allied Command Post!", Map.Allied_Command_Post_Planted );
	OnTrigger( "Planted at the Axis Command Post!", Map.Axis_Command_Post_Planted );
	OnTrigger( "Defused at the Axis Command Post.", Map.Axis_Command_Post_Defused );
	OnTrigger( "Defused at the Allied Command Post.", Map.Allied_Command_Post_Defused );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Destroyed );
	OnTrigger( "The Truck has been damaged!", Map.Truck_Destroyed );
	OnTrigger( "Tank passed barrier!", Map.Tank_passed );
	OnTrigger( "Allied team escaped with the School record!", Map.Allied_Win );

	Tank = OnTriggerRegion(AABB(-3127.476,-638.873,-146.875,-2937.535,-209.713,-24.523),Map.TankTrigger);
	TankBlock = OnTriggerRegion(AABB(-2148.068,-341.717,-142.840,-1816.318,-43.079,-32.838),Map.TankBarrierTrigger);
	TruckBlock = OnTriggerRegion(AABB(4435.480,4439.756,5.125,4836.792,4792.875,91.125),Map.TruckBarrierTrigger);

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

	Util.EnableGoal( "AMMOCAB_t1075b" );
	Util.EnableGoal( "HEALTHCAB_t1074b" );
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"BUILD_Tank",
		"PLANT_Tank_Barrier_1",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"BUILD_Tank_Barrier_1",
		"BUILD_Command_Post",
		"PLANT_Command_Post",
		"DEFEND_school.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"MOUNTMG42_Bunker",
		"REPAIRMG42_Bunker",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"MOUNTMG42_School.*",
		"REPAIRMG42_School.*",
		"GRENADE_truck",
		"MOBILEMG42_school",
	});

	Util.AddUseWp("PLANT_Assault_ramp", "ramp");
	Util.AddUseWp("PLANT_Assault_ramp", "ramp1");
	Util.AddUseWp("PLANT_Assault_ramp", "ramp2");
	Util.AddUseWp("PLANT_Assault_ramp", "ramp3");
	Util.AddUseWp("PLANT_Assault_ramp", "ramp4");
	Util.AddUseWp("PLANT_Assault_ramp", "ramp5");
	Util.AddUseWp("PLANT_Assault_ramp", "ramp6");

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

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

	//SetGoalPriority
	SetGoalPriority( "MOUNTMG42_.*", 0.0, 0, CLASS.MEDIC, true  );
	SetGoalPriority( "MOUNTMG42_.*", 0.0, 0, CLASS.ENGINEER, true );
	SetGoalPriority( "GRENADE_truck", 0.0, 0, CLASS.ENGINEER, true );
	SetGoalPriority( "GRENADE_truck", 0.0, 0, CLASS.MEDIC, true );
	SetGoalPriority( "BUILD_Tank_Barrier_1", 0.82 );
	SetGoalPriority( "BUILD_Truck_Barrier_1", 0.82 );
	//Routeing
	MapRoutes =
	{
		FLAG_School_record =
		{
			ROUTE_Spawn  =
			{
				ROUTE_indoc  =
				{
					ROUTE_indocA  =
					{
						ROUTE_indocA_1  =
						{
							ROUTE_indocA_2  =
							{
								ROUTE_indocA_3  =
								{
									ROUTE_indocA_4  =
									{
										ROUTE_indocA_5  =
										{
										},
									},
								},
							},
						},
					},
					ROUTE_indocB  =
					{
						ROUTE_indocB_1  =
						{
							ROUTE_indocB_2  =
							{
								ROUTE_indocB_3  =
								{
									ROUTE_indocB_4  =
									{
										ROUTE_indocB_5  =
										{
											ROUTE_indocB_6  =
											{
												ROUTE_indocB_7  =
												{
													ROUTE_indocB_8  =
													{
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
		CAPPOINT_Book =
		{
			ROUTE_indocB_8  =
			{
				ROUTE_indocB_7  =
				{
					ROUTE_indocB_6  =
					{
						ROUTE_indocB_5  =
						{
							ROUTE_indocB_4  =
							{
								ROUTE_outdocwin  =
								{
									ROUTE_outdocwin_1  =
									{
										ROUTE_outdocwin_2  =
										{
											ROUTE_outdocwin_3  =
											{
												ROUTE_outdocwin_4  =
												{
													ROUTE_outdocwin_5  =
													{
													},
												},
											},
										},
									},
								},
							},
						},
						ROUTE_indocB_2  =
						{
							ROUTE_indocB_3  =
							{
								ROUTE_outdocwin  =
								{
									ROUTE_outdocwin_1  =
									{
										ROUTE_outdocwin_2  =
										{
											ROUTE_outdocwin_3  =
											{
												ROUTE_outdocwin_4  =
												{
													ROUTE_outdocwin_5  =
													{
														ROUTE_outdoc  =
														{
															ROUTE_outdoc_1  =
															{
																ROUTE_outdoc_2  =
																{
																	ROUTE_outdoc_3  =
																	{
																		ROUTE_outdoc_4  =
																		{
																		},
																	},
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
							ROUTE_outdocA  =
							{
								ROUTE_outdocA_1  =
								{
									ROUTE_outdocdoor1  =
									{
										ROUTE_outdocdoor1_1  =
										{
											ROUTE_outdocwin_2  =
											{
												ROUTE_outdocwin_3  =
												{
													ROUTE_outdocwin_4  =
													{
														ROUTE_outdocwin_5  =
														{
															ROUTE_outdoc  =
															{
																ROUTE_outdoc_1  =
																{
																	ROUTE_outdoc_2  =
																	{
																		ROUTE_outdoc_3  =
																		{
																			ROUTE_outdoc_4  =
																			{
																			},
																		},
																	},
																},
															},
														},
													},
												},
											},
										},
										ROUTE_outdocA_2  =
										{
											ROUTE_outdocdoor2  =
											{
												ROUTE_outdocA_3  =
												{
													ROUTE_outdocA_4  =
													{
														ROUTE_outdoc  =
														{
															ROUTE_outdoc_1  =
															{
																ROUTE_outdoc_2  =
																{
																	ROUTE_outdoc_3  =
																	{
																		ROUTE_outdoc_4  =
																		{
																		},
																	},
																},
															},
														},
													},
												},
												ROUTE_outdocdoor2_1  =
												{
													ROUTE_outdocdoor2_2  =
													{
														ROUTE_outdocdoor2_3  =
														{
															ROUTE_outdocdoor2_4  =
															{
															},
														},
													},
													ROUTE_outdocdoor2A  =
													{
														ROUTE_outdocdoor2A_1  =
														{
															ROUTE_outdocdoor2_3  =
															{
																ROUTE_outdocdoor2_4  =
																{
																},
															},
														},
													},
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
	};

	Util.Routes(MapRoutes);

	Util.FixMoverPos("truck", Vec3(4104.500, 3228.000, 59.500), Vec3(3954.000, 3227.000, 3.000));

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

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