//==========================================================================================
//
//	intel_center.gm
//	Intelligence Center Beta2
//
//	Who   When           What
//------------------------------------------------------------------------------------------
//	d00d  24 March 2013  Final Script
//	d00d  09 March 2013  Initial Script
//
//==========================================================================================
//

global Map =
{
	Talk = true,
	DefendingTeam = TEAM.AXIS,
	VehicleLocation = 0,

	vehicle_at_location = function()
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				Map.tank_at_corner1();
			}
			case 2:
			{
				Map.tank_at_corner2();
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},

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

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

	Tank_Damaged = function()
	{
		if ( Map.Talk && MAP_TALK )
		{
			rand = Server.Team[TEAM.ALLIES].NumPlayers;
			foreach ( gameId and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.ALLIES && bot.GetClass() != CLASS.ENGINEER && RandInt(1,rand) < 2 )
				{
					sleep(1.0);
					bot.SayVoice( VOICE.REPAIR_VEHICLE );
					break;
				}
			}
		}
		Util.MapDebugPrint( "Tank_Damaged" );
	},

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

	Hotel_Captured = function()
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"PLANT_Axis_MG42",
			".*_allies_phase2.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, ".*_allies_phase1.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, ".*_axis_phase2.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, ".*_axis_phase1.*" );

		Util.MapDebugPrint( "Hotel_Captured" );
	},

	tank_at_corner1 = function()
	{

		SetAvailableMapGoals( TEAM.ALLIES, true, ".*_allies_phase3.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, ".*_allies_phase2.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"MOUNTMG42_Axis_MG42",
			"REPAIRMG42_Axis_MG42",
			"BUILD_Axis_MG42",
			".*_axis_phase3.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, ".*_axis_phase2.*" );
		Util.MapDebugPrint("tank_at_corner1");
	},

	tank_at_corner2 = function()
	{

		SetAvailableMapGoals( TEAM.ALLIES, true, ".*_allies_phase4.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, ".*_allies_phase3.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, ".*_axis_phase4.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, ".*_axis_phase3.*" );
		Util.MapDebugPrint("tank_at_corner2");
	},

	Building_Opened = function()
	{
		Util.SetMaxUsers( 1, "BUILD_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"GRENADE_Axis_MG42",
			"PLANT_Axis_Radio",
			".*_allies_phase5.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, ".*_allies_phase4.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, ".*_axis_phase5.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, ".*_axis_phase4.*" );

		if ( Map.Talk && MAP_TALK )
		{
			timeLeft = GetGameTimeLeft();
			if ( timeLeft < 120 )
				{ return; }

			rand = Server.Team[TEAM.AXIS].NumPlayers * 2;
			rand2 = Server.Team[TEAM.ALLIES].NumPlayers * 2;

			foreach ( gameId and bot in BotTable )
			{
				team = bot.GetTeam();

				if ( team == TEAM.AXIS )
				{
					if ( RandInt(0, rand) < 2 ) {
						sleep( RandRange( 0.7, 2.1 ) );
						bot.SayVoice( VOICE.DEFEND_OBJECTIVE );
					}
					else if ( RandInt(0, rand) < 2 ) {
						sleep( RandRange( 1, 2.0 ) );
						bot.ExecCommand( "vsay_team FTFallBack" );
					}
					else if ( RandInt( 0, rand ) < 2 ) {
						sleep( RandRange( 0.5, 1.5 ) );
						bot.SayVoice( VOICE.REINFORCE_DEF );
					}
				}
				else if ( team == TEAM.ALLIES )
				{
					if ( RandInt(0, rand2) < 2 ) {
						sleep( RandRange( 1, 2.8 ) );
						bot.SayVoice( VOICE.REINFORCE_OFF );
					}
					else if ( RandInt(0,rand2) < 2 ) {
						sleep( 1.5 );
						bot.ExecCommand( "vsay_team FTAttack" );
					}
					else if ( RandInt(1, rand2) < 2
							&& bot.GetClass() != CLASS.ENGINEER
							&& timeLeft > 180 )
					{
						sleep(0.6);
						bot.SayVoice( VOICE.DESTROY_PRIMARY );
					}
				}
			}
		}
		Util.MapDebugPrint( "Building_Opened" );
	},

	Wall_Blown = function()
	{
		SetMapGoalProperties( "MOUNT_tank", { AimMode="random", TeamAvailability=6 } );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ROUTE_entrance_2" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Radio" ); //just in case ...
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"ROUTE_entrance_2",
			"MOUNT_tank",
		});
		Util.MapDebugPrint( "Wall_Blown" );
	},

	Axis_Radio_Planted = function()
	{
		if ( Map.Talk && MAP_TALK )
		{
			foreach ( id and bot in BotTable )
			{
				if ( bot.GetTeam() == TEAM.AXIS &&
				     bot.GetClass() != CLASS.ENGINEER &&
				     bot.DistanceTo( Vec3(-9985,11397,424) ) < 600 )
				{
					ran = RandRange( 0, 10 );

					if ( ran < 4 && !bot.GetNearestAlly( CAT.PLAYER, CLASS.ENGINEER ) )
					{
						sleep(ran);
						bot.SayVoice( VOICE.NEED_ENGINEER );
						break;
					}
					else if ( ran > 6 )
					{
						sleep( 0.5 );
						bot.SayVoice( VOICE.DISARM_DYNAMITE );
						break;
					}
				}
			}
		}
		Util.MapDebugPrint( "Axis_Radio_Planted" );
	},

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

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

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "tank at location", Map.vehicle_at_location );
	OnTrigger( "Axis Team have built the MG42!!", Map.Axis_MG42_Built );
	OnTrigger( "Allies have destroyed the MG42!!", Map.Axis_MG42_Destroyed );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Damaged );
	OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "Allied team has captured the Hotel!", Map.Hotel_Captured );
	OnTrigger( "Allied team has broken into the building!", Map.Building_Opened );
	OnTrigger( "Allied team has blown thru the Wall!", Map.Wall_Blown );
	OnTrigger( "Planted at the Axis Radio.", Map.Axis_Radio_Planted );
	OnTrigger( "Defused at the Axis Radio.", Map.Axis_Radio_Defused );
	OnTrigger( "Allies have destroyed the Axis Radio", Map.Axis_Radio_Destroyed );

	corner1 = OnTriggerRegion( AABB(-8739,4853,0,-8450,5144,120), RegionTrigger.VehicleTrigger );
	corner2 = OnTriggerRegion( AABB(-9783,7485,0,-9470,7788,120), RegionTrigger.VehicleTrigger );
	objective1 = OnTriggerRegion( AABB(-10030,10839,25,-8776,10967,197), RegionTrigger.IntrusionWarning );
	objective2 = OnTriggerRegion( AABB(-10602,10887,384,-9865,11044,552), RegionTrigger.IntrusionWarning );

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

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"MOUNT_tank",
		"PLANT_Axis_Command_Post",
		"BUILD_Allied_Command_Post",
		"BUILD_Tank",
		"HEALTHCAB_.*",
		"AMMOCAB_.*",
		".*_allies_phase1.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, "ROUTE_entrance_2" );

	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFUSE_Axis_Radio.*",
		"PLANT_Allied_Command_Post",
		"BUILD_Axis_Command_Post",
		"HEALTHCAB_.*",
		"AMMOCAB_.*",
		"DEFEND_axis_phase1.*",
		"AIRSTRIKE_axis_phase1.*",
		"MOBILEMORTAR_axis_phase1.*",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, "ROUTE_entrance_2" );

	// Max users per goal
	Util.SetMaxUsers( 2, "HEALTHCAB_.*" );
	Util.SetMaxUsers( 2, "AMMOCAB_.*" );
	Util.SetMaxUsers( 2, "BUILD_.*" );
	Util.SetMaxUsers( 1, ".*_Command_Post.*" );
	Util.SetMaxUsersInProgress( 3, "MOUNT_tank" );
	Util.SetMaxUsersInUse( 1, "MOUNT_tank" );
	Util.SetMaxUsersInUse( 1, "PLANT_.*" );

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

	// Priority
	SetGoalPriority( "PLANT_Axis_Radio", 0.9 );

	Util.MapDebugPrint( "Omni-bot map script for Intel Center Beta2 executed." );
};

global OnBotJoin = function( bot )
{
	bot.MaxViewDistance = 3000;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		ATTACK_allies_phase1_7 =
		{
			ROUTE_allied_spawn =
			{
				ROUTE_archway = {},
				ROUTE_side_alley = {},
				ROUTE_garden = {},
			},
		},
		DEFEND_axis_phase1_1 =
		{
			ROUTE_hotel_spawn_axis =
			{
				ROUTE_hotel_south_exit =
				{
					ROUTE_hotel_alley = {},
					ROUTE_main_street = {},
				},
				ROUTE_hotel_west_exit =
				{
					ROUTE_hotel_alley = {},
					ROUTE_main_street = {},
				},
				ROUTE_hotel_stairs =
				{
					ROUTE_hotel_2nd_floor_exit =
					{
						// ROUTE_hotel_alley = {},
						ROUTE_main_street = {},
					},
				},
				ROUTE_hotel_window =
				{
					ROUTE_hotel_alley = {},
					ROUTE_main_street = {},
				},
			},
		},
		DEFEND_axis_phase2_1 =
		{
			ROUTE_axis_spawn =
			{
				ROUTE_axis_spawn_east_exit = {},
				ROUTE_axis_spawn_west_exit = {},
			},
		},
		DEFEND_axis_phase5_1 =
		{
			ROUTE_axis_spawn =
			{
				ROUTE_entrance_1 = {},
				ROUTE_entrance_2 = {},
				ROUTE_entrance_3 = {},
				ROUTE_entrance_4 = {},
				ROUTE_entrance_5 = {},
			},
		},
		ATTACK_allies_phase5_1 =
		{
			ROUTE_hotel_spawn_axis =
			{
				ROUTE_hotel_south_exit =
				{
					ROUTE_tunnel =
					{
						ROUTE_entrance_1 = {},
						ROUTE_entrance_2 = {},
						ROUTE_entrance_4 = {},
						ROUTE_entrance_5 = {},
					},
					ROUTE_alley_barrels =
					{
						ROUTE_entrance_1 = {},
						ROUTE_entrance_2 = {},
						ROUTE_entrance_4 = {},
						ROUTE_entrance_5 = {},
					},
					ROUTE_main_street_barrels =
					{
						ROUTE_entrance_1 = {},
						ROUTE_entrance_2 = {},
						ROUTE_entrance_4 = {},
						ROUTE_entrance_5 = {},
					},
				},
				ROUTE_hotel_west_exit =
				{
					ROUTE_tunnel =
					{
						ROUTE_entrance_1 = {},
						ROUTE_entrance_2 = {},
						ROUTE_entrance_4 = {},
						ROUTE_entrance_5 = {},
					},
					ROUTE_alley_barrels =
					{
						ROUTE_entrance_1 = {},
						ROUTE_entrance_2 = {},
						ROUTE_entrance_4 = {},
						ROUTE_entrance_5 = {},
					},
					ROUTE_main_street_barrels =
					{
						ROUTE_entrance_1 = {},
						ROUTE_entrance_2 = {},
						ROUTE_entrance_4 = {},
						ROUTE_entrance_5 = {},
					},
				},
			},
		},
		ATTACK_allies_phase2_1 =
		{
			ROUTE_hotel_spawn =
			{
				ROUTE_hotel_south_exit = {},
				ROUTE_hotel_west_exit = {},
				ROUTE_hotel_window = {},
				ROUTE_hotel_stairs =
				{
					ROUTE_hotel_2nd_floor_exit = {},
				},
			},
			ROUTE_hotel_spawn_axis =
			{
				ROUTE_hotel_south_exit = {},
				ROUTE_hotel_west_exit = {},
				ROUTE_hotel_window = {},
				ROUTE_hotel_stairs =
				{
					ROUTE_hotel_2nd_floor_exit = {},
				},
			},
		},
	};
	MapRoutes[".*_axis_phase1_.*"] = MapRoutes.DEFEND_axis_phase1_1;
	MapRoutes[".*_axis_phase[234]_.*"] = MapRoutes.DEFEND_axis_phase2_1;
	MapRoutes[".*_axis_phase5_.*"] = MapRoutes.DEFEND_axis_phase5_1;
	MapRoutes[".*_allies_phase[234]_.*"] = MapRoutes.ATTACK_allies_phase2_1;
	MapRoutes[".*_allies_phase5_.*"] = MapRoutes.ATTACK_allies_phase5_1;
	MapRoutes.PLANT_Axis_Radio = MapRoutes.ATTACK_allies_phase5_1;
	MapRoutes.ATTACK_allies_phase1_8 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_9 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_10 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_11 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_12 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_13 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_14 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_15 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_16 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_17 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_18 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_19 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_20 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_21 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_22 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_23 = MapRoutes.ATTACK_allies_phase1_7;
	MapRoutes.ATTACK_allies_phase1_24 = MapRoutes.ATTACK_allies_phase1_7;
	Util.Routes(MapRoutes);
};
