/********************************************************
Waypoints and Script by BubbaG1, Crapshoot & MickyP

  Filename: italyfp2.gm

  Last Updated: Sunday, 18 July 2010 8:46 CDT
  Updated by: BubbaG1 (Scott Ward)

  Change log:
  - Upgraded ways/script from 0.71
********************************************************************************/

global Map =
{
	ShowMovers = false,
	Ammo_Cabinet_supply = "AMMOCAB_supply",
	Ammo_Cabinet_t14 = "AMMOCAB_t14",
	Health_Cabinet_health = "HEALTHCAB_health",
	Health_Cabinet_t13 = "HEALTHCAB_t13",
	Checkpoint_flag = "CHECKPOINT_flag",
	Flag_jeep_gold = "FLAG_jeep_gold",
	Build_1st_Ramp = "BUILD_1st_Ramp",
	Build_2nd_Ramp = "BUILD_2nd_Ramp",
	Build_Command_Post = "BUILD_Command_Post",
	Build_Jeep = "BUILD_Jeep",
	Build_Jeep_Barrier = "BUILD_Jeep_Barrier",
	Build_Ladder = "BUILD_Ladder",
	Build_Market_Gate = "BUILD_Market_Gate",
	Build_Tower_Wall = "BUILD_Tower_Wall",
	Plant_1st_Ramp = "PLANT_1st_Ramp",
	Plant_2nd_Ramp = "PLANT_2nd_Ramp",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_Jeep = "PLANT_Jeep",
	Plant_Jeep_Barrier = "PLANT_Jeep_Barrier",
	Plant_Ladder = "PLANT_Ladder",
	Plant_Market_Gate = "PLANT_Market_Gate",
	Plant_Tower_Wall = "PLANT_Tower_Wall",
	Mount_Gold_MG = "MOUNTMG42_473",
	Mount_Barrier_MG = "MOUNTMG42_miscmg",
	Repair_Gold_MG = "REPAIRMG42_473",
	Repair_Barrier_MG = "REPAIRMG42_miscmg",
	Mover_jeep_mover = "MOVER_jeep_mover",

	Movers =
	{
		"MOVER_jeep_mover",
	},
	
	// cs: commented out as it does nothing.
	/*JeepAtMarketGate = 
	{
		Name="JeepAtMarketGate",
		TriggerOnEntity = GetGoal("MOVER_jeep_mover").GetEntity(),
		OnEnter = function(ent)
		{
		},
		OnExit = function(ent)
		{
		},
	},*/

	MarketGatePassed =
 	{
 		Name="MarketGatePassed",
 		TriggerOnEntity = GetGoal("MOVER_jeep_mover").GetEntity(),
 		OnEnter = function(ent)
 		{
 			SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Market_Gate" );
			
 			Util.MapDebugPrint("MarketGatePassed");
		},
 		OnExit = function(ent)
 		{
 		},
	},

	BarrierPassed =
 	{
 		Name="BarrierPassed",
 		TriggerOnEntity = GetGoal("MOVER_jeep_mover").GetEntity(),
 		OnEnter = function(ent)
 		{
			SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Jeep_Barrier" );
			
  			Util.MapDebugPrint("BarrierPassed");
		},
 		OnExit = function(ent)
 		{
 		},
	},

	Ramp1Passed =
 	{
 		Name="Ramp1Passed",
 		TriggerOnEntity = GetGoal("MOVER_jeep_mover").GetEntity(),
 		OnEnter = function(ent)
 		{
			SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_1st_Ramp" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_1st_Ramp" );
			
 			Util.MapDebugPrint("Ramp1Passed");
 		},
 		OnExit = function(ent)
 		{
			SetAvailableMapGoals( TEAM.ALLIES, true, Map.Mount_Gold_MG );
			SetAvailableMapGoals( TEAM.AXIS, true, Map.Mount_Gold_MG );
			SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_gold.*" );
			
			Util.MapDebugPrint("exited Ramp1");
		},
	},

	Ramp2Passed =
 	{
 		Name="Ramp2Passed",
 		TriggerOnEntity = GetGoal("MOVER_jeep_mover").GetEntity(),
 		OnEnter = function(ent)
 		{
			SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_2nd_Ramp" );
			SetAvailableMapGoals( TEAM.ALLIES, false, Map.Mount_Barrier_MG );
			SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_2nd_Ramp" );
			SetAvailableMapGoals( TEAM.AXIS, false, Map.Mount_Barrier_MG );
			
 			Util.MapDebugPrint("Ramp2Passed");
 		},
 		OnExit = function(ent)
 		{
 		},
	},

	Escape2 =
 	{
 		TriggerOnEntity = GetGoal("MOVER_jeep_mover").GetEntity(),
 		OnEnter = function(ent)
 		{
 			SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_escape2.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_.*" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_escape2.*" );
			
			Util.MapDebugPrint("Escape2");
 		},
 		OnExit = function(ent)
 		{
 		},
	},

	Escape3 =
 	{
 		TriggerOnEntity = GetGoal("MOVER_jeep_mover").GetEntity(),
 		OnEnter = function(ent)
 		{
 			SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_escape3.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_.*" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_escape3.*" );
			
			Util.MapDebugPrint("Escape3");
 		},
 		OnExit = function(ent)
 		{
 		},
	},

	Escape4 =
 	{
 		TriggerOnEntity = GetGoal("MOVER_jeep_mover").GetEntity(),
 		OnEnter = function(ent)
 		{
			SetAvailableMapGoals( TEAM.AXIS, false, Map.Mount_Barrier_MG );
			SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_.*" );
			SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_escape4.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, Map.Mount_Barrier_MG );
			SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_.*" );
			SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_escape4.*" );
			
 			Util.MapDebugPrint("Escape4");
 		},
 		OnExit = function(ent)
 		{
 		},
	},

	BUILD_1st_Ramp_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "BUILD_1st_Ramp_Built" );
	},

	BUILD_2nd_Ramp_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "BUILD_2nd_Ramp_Built" );
	},


	BUILD_Jeep_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "BUILD_Jeep_Built" );
	},

	BUILD_Jeep_Barrier_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "BUILD_Jeep_Barrier_Built" );
	},

	BUILD_Ladder_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "BUILD_Ladder_Built" );
	},

	BUILD_Market_Gate_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "BUILD_Market_Gate_Built" );
	},

	BUILD_Tower_Wall_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "BUILD_Tower_Wall_Built" );
	},

	PLANT_1st_Ramp_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "PLANT_1st_Ramp_Destroyed" );
	},

	PLANT_2nd_Ramp_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "PLANT_2nd_Ramp_Destroyed" );
	},

	PLANT_Jeep_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "PLANT_Jeep_Destroyed" );
	},

	PLANT_Jeep_Barrier_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "PLANT_Jeep_Barrier_Destroyed" );
	},

	PLANT_Ladder_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "PLANT_Ladder_Destroyed" );
	},

	PLANT_Market_Gate_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "PLANT_Market_Gate_Destroyed" );
	},

	PLANT_Tower_Wall_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }
		// wall isn't repairable
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Tower_Wall" );
		Util.MapDebugPrint( "PLANT_Tower_Wall_Destroyed" );
	},

	FLAG_jeep_gold_Taken = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "FLAG_jeep_gold_Taken" );
	},

	flag_Axis_Captured = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "flag_Axis_Captured" );
	},

	flag_Allies_Captured = function( trigger )
	{
		if ( TestMap )
			{ return; }

		Util.MapDebugPrint( "flag_Allies_Captured" );
	},

	BUILD_Command_Post_Built = function( trigger )
	{
		if ( TestMap )
			{ return; }

		SetAvailableMapGoals( TEAM.ALLIES, true, "AMMOCAB_supply" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "HEALTHCAB_health" );
		SetAvailableMapGoals( TEAM.AXIS, true, "AMMOCAB_supply" );
		SetAvailableMapGoals( TEAM.AXIS, true, "HEALTHCAB_health" );

		Util.MapDebugPrint( "BUILD_Command_Post_Built" );
	},

	PLANT_Command_Post_Destroyed = function( trigger )
	{
		if ( TestMap )
			{ return; }

		SetAvailableMapGoals( TEAM.ALLIES, false, "AMMOCAB_supply" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "HEALTHCAB_health" );
		SetAvailableMapGoals( TEAM.AXIS, false, "AMMOCAB_supply" );
		SetAvailableMapGoals( TEAM.AXIS, false, "HEALTHCAB_health" );

		Util.MapDebugPrint( "PLANT_Command_Post_Destroyed" );
	},

	GoldAccessible = function( trigger )
	{
		if ( TestMap )
			{ return; }

		SetGoalPriority( "CHECKPOINT_flag", 0.5 );
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Ramp" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Ramp_1" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Jeep_Barrier" );
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Jeep_Barrier" );
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Ramp" );
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Ramp_1" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_gold.*" );
		Util.MapDebugPrint( "GoldAccessible" );
	},

	GoldSecured = function( trigger )
	{
		if ( TestMap )
			{ return; }

		//Map.EscortVehicle.Jeep.Enabled = true;
		SetAvailableMapGoals( TEAM.ALLIES, true, Map.Mount_Barrier_MG );
		SetAvailableMapGoals( TEAM.ALLIES, false, Map.Mount_Gold_MG );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_escape1_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, Map.Mount_Barrier_MG );
		SetAvailableMapGoals( TEAM.AXIS, false, Map.Mount_Gold_MG );
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_escape1_.*" );
		escape2 = OnTriggerRegion(AABB(295,920,-210, 435,1075,-136), Map.Escape2); //corner
		escape3 = OnTriggerRegion(AABB(-1175,1240,-210, -988,1390,-136), Map.Escape3); //bridge
		escape4 = OnTriggerRegion(AABB(-1330,-25,-210, -1186,-36,-136), Map.Escape4); //last corner
		Util.MapDebugPrint( "GoldSecured" );
	},
};

global OnMapLoad = function()
{
	if ( TestMapOn )
		{ Util.AutoTestMap(); }

	OnTrigger( "Lower Ramp constructed!", Map.BUILD_1st_Ramp_Built );
	OnTrigger( "Upper Ramp constructed!", Map.BUILD_2nd_Ramp_Built );
	OnTrigger( "Jeep repaired!", Map.BUILD_Jeep_Built );
	OnTrigger( "Jeep Barrier built!", Map.BUILD_Jeep_Barrier_Built );
	OnTrigger( "Ladder to balcony has been built near the Tower!", Map.BUILD_Ladder_Built );
	OnTrigger( "Market Gate built!", Map.BUILD_Market_Gate_Built );
	OnTrigger( "Market Gate destroyed!", Map.BUILD_Tower_Wall_Built );
	OnTrigger( "Lower Ramp destroyed!", Map.PLANT_1st_Ramp_Destroyed );
	OnTrigger( "Lower Ramp destroyed!", Map.PLANT_2nd_Ramp_Destroyed );
	OnTrigger( "Jeep damaged", Map.PLANT_Jeep_Destroyed );
	OnTrigger( "Upper Ramp destroyed!", Map.PLANT_Jeep_Barrier_Destroyed );
	OnTrigger( "Ladder to balcony has been destroyed!", Map.PLANT_Ladder_Destroyed );
	OnTrigger( "Axis Command Post destroyed!", Map.PLANT_Command_Post_Destroyed );
	OnTrigger( "Allied Command Post destroyed!", Map.PLANT_Command_Post_Destroyed );
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.BUILD_Command_Post_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.BUILD_Command_Post_Built );
	OnTrigger( "Market Gate destroyed!", Map.PLANT_Market_Gate_Destroyed );
	OnTrigger( "Allies have made a hole in the Tower Wall", Map.PLANT_Tower_Wall_Destroyed );
	OnTrigger( "Allies have stolen the first goldcrate!", Map.FLAG_jeep_gold_Taken );
	OnTrigger( "Axis have captured the Market Place!", Map.flag_Axis_Captured );
	OnTrigger( "Allies have captured the Market Place!", Map.flag_Allies_Captured );
	OnTrigger( "goldrush_allies_gold_get", Map.GoldAccessible );
	OnTrigger( "Allies have stolen the second goldcrate!", Map.GoldSecured );

	SetAvailableMapGoals( TEAM.ALLIES, false, "AMMOCAB_supply" ); // only enabled when command post is built
	SetAvailableMapGoals( TEAM.ALLIES, false, "HEALTHCAB_health" );
	SetAvailableMapGoals( TEAM.ALLIES, false, Map.Mount_Gold_MG );
	SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_.*" );

	SetAvailableMapGoals( TEAM.AXIS, false, Map.Mount_Gold_MG );
	SetAvailableMapGoals( TEAM.AXIS, false, "AMMOCAB_supply" );
	SetAvailableMapGoals( TEAM.AXIS, false, "HEALTHCAB_health" );
	SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "REPAIRMG42_.*" );
	// Don't plant as position is not updated from mapscript
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Jeep" );

	// cs: was this intended? they would never build the jeep since it is never increased
	//SetGoalPriority( "BUILD_jeep", 0.1, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_1st_Ramp", 1.0, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_2nd_Ramp", 1.1, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "CHECKPOINT_flag", 0.7 );
	SetGoalPriority( "PLANT_Market_Gate", 0.92 );
	SetGoalPriority( "PLANT_Jeep_Barrier", 0.91 );
	// Covert ops can't destroy the ramp:
	SetGoalPriority( "PLANT_1st_Ramp", 0.0, TEAM.AXIS, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_2nd_Ramp", 0.0, TEAM.AXIS, CLASS.COVERTOPS );

	Util.SetGoalOffset( 0,10,-10, "PLANT_Tower_Wall" );

	// cs: commented this one since it is doing nothing.
	//jeep0 = OnTriggerRegion(AABB(-150,-650,-180, 30,-500,-120), Map.JeepAtMarketGate);
	jeep1 = OnTriggerRegion(AABB(123.944,-672.875,-199.875,194.344,-504.221,-125.875), Map.MarketGatePassed);
	jeep2 = OnTriggerRegion(AABB(-273.875,2080.943,-210.875,21.875,2193.165,-125.875), Map.BarrierPassed);
	jeep3 = OnTriggerRegion(AABB(-231.874,3144.365,-84.875,-19.279,3216.411,0.125), Map.Ramp1Passed);
	jeep4 = OnTriggerRegion(AABB(255.253,3112.707,-0.875,338.375,3360.874,73.125), Map.Ramp2Passed);
	
	InitializeMapRoutes();
	
	Util.MapDebugPrint( "Omni-bot map script for Streets of Italy loaded" );
};

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 200.0;
	bot.MaxViewDistance = 2500;
};

global InitializeMapRoutes = function()
{
	// the route tables
	MapRoutes =
	{
		BUILD_Command_Post = 
		{
			ROUTE_allies_start = 
			{
				ROUTE_allies_cp_window =
				{
					Weight = 3,
					ROUTE_allies_cp_window_1 = 
					{
						ROUTE_allies_cp_windows_2 = 
						{
						},
					},
				},
				ROUTE_allies_cp_back = 
				{
					ROUTE_allies_cp_back_1 = 
					{
					},
				},
			},
			ROUTE_axis_start =
			{
				ROUTE_axis_cp =
				{
					Weight = 3,
					ROUTE_axis_cp_2 =
					{
					},
				},
				ROUTE_axis_objladder =
				{
					ROUTE_axis_objroof =
					{
						ROUTE_axis_barrierroof =
						{
							ROUTE_axis_cp_2 = 
							{
							},
						},
					},
				},
			},
		},
		CHECKPOINT_flag = 
		{
			ROUTE_allies_start = 
			{
				ROUTE_allies_market = 
				{
				},
				ROUTE_allies_cp_back = 
				{
					ROUTE_allies_cp_back_1 = 
					{
					},
				},
			},
			ROUTE_axis_start = 
			{
				ROUTE_axis_objladder = 
				{
					ROUTE_axis_market_split =
					{
						Weight = 3,
						ROUTE_axis_market_left =
						{
							Weight = 2,
						},
						ROUTE_axis_market_right =
						{
						},
					},
					ROUTE_axis_objstairs = 
					{
						ROUTE_axis_objroof =
						{
							ROUTE_axis_mgroof =
							{								
							},
							ROUTE_axis_objroof_lower =
							{
								ROUTE_axis_market_left =
								{
									Weight = 3,
								},
								ROUTE_axis_market_right =
								{
								},
							},
						},
					},
				},
				ROUTE_axis_ramps = 
				{
					ROUTE_axis_market_right = 
					{
					},
					ROUTE_axis_market_split = 
					{
						ROUTE_axis_market_left = 
						{
						},
					},
				},
				ROUTE_axis_cp = 
				{
					ROUTE_axis_cp_2 =
					{
					},
				},
			},
		},			
	};

	// copy some routes
	MapRoutes.BUILD_1st_Ramp = MapRoutes.BUILD_Command_Post;
	MapRoutes.BUILD_2nd_Ramp = MapRoutes.BUILD_Command_Post;
	MapRoutes.Plant_Command_Post = MapRoutes.BUILD_Command_Post;
		
	// register the routes
	Util.Routes(MapRoutes);
};