//==========================================================================================
//
//	watten.gm
//
//	Who       	When				What
//------------------------------------------------------------------------------------------
//	MickyP		20 May 2009		Initial Waypoints
//	MickyP		29 December 2013	Full Script
//
//==========================================================================================
//

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

	grate1 = false,
	grate2 = false,
	grate3 = false,
	missile_destroyed = false,

	Navigation =
	{
		grate1 =
		{
			navigate = function(_this)
			{
				if ( !Map.grate1 )
				{
					_this.AddWeaponRequest( WEAPON.KNIFE );
					_this.BlockForWeaponChange( WEAPON.KNIFE );

					while( !Map.grate1 )
					{
						_this.Bot.HoldButton(BTN.ATTACK1, 0.25);
 						yield();
					}
				}
				sleep(1);
			},
		},
		grate2 =
		{
			navigate = function(_this)
			{
				if ( !Map.grate2 )
				{
					_this.AddWeaponRequest( WEAPON.KNIFE );
					_this.BlockForWeaponChange( WEAPON.KNIFE );

					while( !Map.grate2 )
					{
						_this.Bot.HoldButton(BTN.ATTACK1, 0.25);
 						yield();
					}
				}
				sleep(1);
			},
		},
		grate3 =
		{
			navigate = function(_this)
			{
				if ( !Map.grate3 )
				{
					_this.AddWeaponRequest( WEAPON.KNIFE );
					_this.BlockForWeaponChange( WEAPON.KNIFE );

					while( !Map.grate3 )
					{
						_this.Bot.HoldButton(BTN.ATTACK1, 0.25);
 						yield();
					}
				}
				sleep(1);
			},
		},
	},
	Command_Post_Built = function( trigger )
	{
		Util.MapDebugPrint( "Command_Post_Built" );
	},

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

	cityflag_Axis_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"ATTACK_Base_Entrance.*",
			"PLANT_base_entrance",
			"PLANT_coach_access",
		});
		Util.MapDebugPrint( "cityflag_Axis_Captured" );
	},

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

	coach_access_Built = function( trigger )
	{
		Util.DisableGoal( "ROUTE_Coach_Access" );
		Util.MapDebugPrint( "coach_access_Built" );
	},

	coach_access_Destroyed = function( trigger )
	{
		Util.EnableGoal( "ROUTE_Coach_Access" );
		Util.MapDebugPrint( "coach_access_Destroyed" );
	},

	base_entrance_Destroyed = function( trigger )
	{
		if ( Map.missile_destroyed == true )
			{ return; }

		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Flag.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAMP_Missile.*" );

		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Base_Entrance.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"CAMP_Missile.*",
			"PLANT_missile",
		});
		Util.MapDebugPrint( "base_entrance_Destroyed" );
	},

	missile_Destroyed = function( trigger )
	{
		Util.EnableGoal( "AMMOCAB.*" );
		Util.EnableGoal( "HEALTHCAB." );

		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_Flag.*",
			"BUILD_coach_access",
			"CAMP_Missile.*",
			"CHECKPOINT_cityflag",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Docs.*" );

		SetAvailableMapGoals( TEAM.AXIS, false, {
			"CAMP_Missile.*",
			"ATTACK_Base_Entrance.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"PLANT_Command_Post",
			"BUILD_Command_Post",
			"PLANT_water_wall",
			"FLAG__maps",
		});

		Map.missile_destroyed = true;
		Util.MapDebugPrint( "missile_Destroyed" );
	},

	water_wall_Destroyed = function( trigger )
	{
		Util.EnableGoal( "ROUTE_Water_Wall" );
		Util.MapDebugPrint( "water_wall_Destroyed" );
	},

	maps_Taken = function( trigger )
	{
		Util.EnableGoal( "CAMP_Truck.*" );
		Util.MapDebugPrint( "maps_Taken" );
	},

	maps_Returned = function( trigger )
	{
		Util.DisableGoal( "CAMP_Truck.*" );
		Util.MapDebugPrint( "maps_Returned" );
	},

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

	Grate_1_Broken = function( trigger )
	{
		Map.grate1 = true;
		//Util.MapDebugPrint( "Grate_1_Broken" );
	},

	Grate_2_Broken = function( trigger )
	{
		Map.grate2 = true;
		//Util.MapDebugPrint( "Grate_1_Broken" );
	},

	Grate_3_Broken = function( trigger )
	{
		Map.grate3 = true;
		//Util.MapDebugPrint( "Grate_3_Broken" );
	},
};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "Axis captured the town!", Map.cityflag_Axis_Captured );
	OnTrigger( "Allies reclaim the town!", Map.cityflag_Allies_Captured );
	OnTrigger( "Coach access has been constructed.", Map.coach_access_Built );
	OnTrigger( "Coach access has been destroyed.", Map.coach_access_Destroyed );
	OnTrigger( "Axis have breached the Main Entrance and secured the Town!", Map.base_entrance_Destroyed );
	OnTrigger( "The missile has been destroyed!", Map.missile_Destroyed );
	OnTrigger( "The Waterwall has been destroyed!", Map.water_wall_Destroyed );
	OnTrigger( "Axis have stolen The Project Maps!", Map.maps_Taken );
	OnTrigger( "Flag returned  maps!", Map.maps_Returned );
	OnTrigger( "Axis escape with Documents!", Map.maps_Secured );

	OnTrigger( "GRENADE_Grate_1 Exploded.", Map.Grate_1_Broken );
	OnTrigger( "GRENADE_Grate_2 Exploded.", Map.Grate_2_Broken );
	OnTrigger( "GRENADE_Grate_3 Exploded.", Map.Grate_3_Broken );

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

	Util.EnableGoal( "CHECKPOINT_cityflag" );
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"DEFEND_Flag.*",
		"BUILD_coach_access",
	});

	SetGoalPriority( "CAMP_Truck.*", 0.59, 0, 0 ); // High incase of sneeky player

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


global InitializeRoutes = function()
{
	MapRoutes =
	{
		CHECKPOINT_cityflag =
		{
			ROUTE_Axis_1st  =
			{
				ROUTE_Axis_Front_Exit  =
				{
					ROUTE_Bridge  =
					{
						ROUTE_Left_Barrier  =
						{
						},
						ROUTE_Right_Barrier  =
						{
						},
					},
					ROUTE_East_Path  =
					{
					},
					ROUTE_East_Path  =
					{
						ROUTE_East_Path_Corner  =
						{
						},
					},
					ROUTE_East_Path  =
					{
						ROUTE_East_Path_Corner  =
						{
							ROUTE_Rear_Flag  =
							{
							},
						},
					},
				},
				ROUTE_Axis_Side_Exit  =
				{
					ROUTE_Bridge  =
					{
						ROUTE_Left_Barrier  =
						{
						},
						ROUTE_Right_Barrier  =
						{
						},
					},
					ROUTE_Upper_Path  =
					{
					},
				},
			},
			ROUTE_Allied_2nd_Spawn  =
			{
				ROUTE_Allied_Side_Door  =
				{
				},
				ROUTE_Coach_Access  =
				{
				},
				ROUTE_Water_Exit  =
				{
				},
			},
		},
		CAPPOINT_Truck =
		{
			ROUTE_Documents  =
			{
				ROUTE_Water_Wall  =
				{
					ROUTE_Truck_Long  =
					{
					},
					ROUTE_Truck_Short  =
					{
					},
					ROUTE_Lower_Truck  =
					{
					},
				},
				ROUTE_Main_Door  =
				{
					ROUTE_Truck_Short  =
					{
					},
					ROUTE_Truck_Long  =
					{
					},
					ROUTE_Lower_Truck  =
					{
					},
				},
			},
		},
		FLAG__maps =
		{
			ROUTE_Spawn_Flag  =
			{
				ROUTE_Main_Door  =
				{
					ROUTE_Left_CP  =
					{
						ROUTE_Short_Path  =
						{
						},
						ROUTE_Beds  =
						{
							ROUTE_Long_Path  =
							{
							},
						},
					},
					ROUTE_Right_CP  =
					{
						ROUTE_Grate_1  =
						{
							ROUTE_Grate_2  =
							{
							},
							ROUTE_Grate_3  =
							{
							},
						},
						ROUTE_Rear_CP  =
						{
							ROUTE_Short_Path  =
							{
							},
							ROUTE_Beds  =
							{
								ROUTE_Long_Path  =
								{
								},
							},
						},
					},
				},
				ROUTE_Coach_Access  =
				{
					ROUTE_Left_CP  =
					{
						ROUTE_Short_Path  =
						{
						},
						ROUTE_Beds  =
						{
							ROUTE_Long_Path  =
							{
							},
						},
					},
					ROUTE_Right_CP  =
					{
						ROUTE_Grate_1  =
						{
							ROUTE_Grate_2  =
							{
							},
							ROUTE_Grate_3  =
							{
							},
						},
						ROUTE_Rear_CP  =
						{
							ROUTE_Short_Path  =
							{
							},
							ROUTE_Beds  =
							{
								ROUTE_Long_Path  =
								{
								},
							},
						},
					},
				},
			},
		},
		PLANT_missile =
		{
			ROUTE_Main_Door  =
			{
			},
			ROUTE_Coach_Access  =
			{
			},
		},
	};
	MapRoutes["CAMP_Missile.*"] = MapRoutes.PLANT_missile;
	Util.Routes(MapRoutes);
};
