// Map script for Vesuvius by d00d
// Compatible with Omni-bot 0.8

global Map =
{
	ObjectiveSecured = false,

	east_Gate_Breached = function()
	{
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_east_gate.*");
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_east_gate.*");
		SetAvailableMapGoals(TEAM.AXIS, false, "SNIPE_east_gate.*");
		Util.MapDebugPrint("east_Gate_Breached");
	},

	south_Gate_Breached = function()
	{
		SetAvailableMapGoals(TEAM.AXIS, false, {
			"DEFEND_south_gate.*",
			"SNIPE_south_gate.*",
		});
		Util.MapDebugPrint("south_Gate_Breached");
	},

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

	urn_Stolen = function()
	{
		SetAvailableMapGoals(TEAM.AXIS, true, "SNIPE_cappoint.*");
		SetAvailableMapGoals(TEAM.ALLIES, true, "SNIPE_cappoint.*");
		SetAvailableMapGoals(TEAM.AXIS, false, {
			"DEFEND_urn.*",
			"SNIPE_urn.*",
		});
		SetAvailableMapGoals(TEAM.AXIS, true, "ATTACK_cappoint.*");
		SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_cappoint.*");
		Util.MapDebugPrint("urn_Stolen");
	},

	urn_Returned = function()
	{
		SetAvailableMapGoals(TEAM.AXIS, false, "SNIPE_cappoint.*");
		SetAvailableMapGoals(TEAM.ALLIES, false, "SNIPE_cappoint.*");
		SetAvailableMapGoals(TEAM.AXIS, true, {
			"SNIPE_urn.*",
			"DEFEND_urn.*",
		});
		SetAvailableMapGoals(TEAM.AXIS, false, "ATTACK_cappoint.*");
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_cappoint.*");
		Util.MapDebugPrint("urn_Returned");
	},

	urn_Secured = function()
	{
		Map.ObjectiveSecured = true;
		SetGoalPriority("PLANT_south_valley_gate", 0.95);
		SetGoalPriority("PLANT_east_gate", 0.92);
		SetGoalPriority("PLANT_truck_ramp", 0.8);
		SetGoalPriority("DEFEND_urn.*", 0.55);
		SetAvailableMapGoals(TEAM.ALLIES, true, "ESCORT_truck");
		SetAvailableMapGoals(TEAM.AXIS, false, {
			"DEFEND_urn.*",
			"SNIPE_urn.*",
			"ATTACK_cappoint.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_south_gate.*");
		SetAvailableMapGoals(TEAM.AXIS, true, {
			"DEFEND_south_gate.*",
			"SNIPE_south_gate.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, false, {
			"ATTACK_cappoint.*",
			"PLANT_west_ruins_gate",
			"BUILD_ruins_access_rope",
			"PLANT_Axis_Team_Door",
		});
		SetAvailableMapGoals(TEAM.AXIS, false, "PLANT_ruins_access_rope");
		SetAvailableMapGoals(TEAM.AXIS, true, "PLANT_truck_ramp");
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_east_gate.*");
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_east_gate.*");
		SetAvailableMapGoals(TEAM.ALLIES, true, "BUILD_Truck");
		Util.OnTriggerPosition("MOVER_truck", "corner1", 200, Map.truck_at_corner1);
		Util.MapDebugPrint("urn_Secured");
	},

	truck_at_corner1 = function()
	{
		SetGoalPriority("PLANT_truck_ramp", 0.85);
		SetAvailableMapGoals(TEAM.AXIS, false, {
			"MOUNTMG42_.*",
			"REPAIRMG42_.*",
			"SNIPE_cappoint.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, false, "SNIPE_cappoint.*");
		SetAvailableMapGoals(TEAM.ALLIES, true, "BUILD_truck_ramp");
		Util.OnTriggerPosition("MOVER_truck", "corner2", 200, Map.truck_at_corner2);
		Util.MapDebugPrint("truck_at_corner1");
	},

	truck_at_corner2 = function()
	{
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_south_gate.*");
		SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_east_gate.*");
		SetAvailableMapGoals(TEAM.AXIS, true, "MOUNTMG42_mg42_church");
		SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_south_gate.*");
		SetAvailableMapGoals(TEAM.AXIS, true, {
			"DEFEND_east_gate.*",
			"SNIPE_east_gate.*",
		});
		SetAvailableMapGoals(TEAM.AXIS, false, "SNIPE_south_gate.*");
		Util.OnTriggerPosition("MOVER_truck", "east_gate_trigger", 180, Map.truck_past_east_gate);
		Util.MapDebugPrint("truck_at_corner2");
	},

	truck_past_east_gate = function()
	{
		Util.RemoveGoal( "BUILD_east_gate" );
		SetAvailableMapGoals(TEAM.AXIS, true, {
			"SNIPE_showdown.*",
			"DEFEND_showdown.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, true, "MOUNTMG42_mg42_church");
		SetAvailableMapGoals(TEAM.AXIS, true, "REPAIRMG42_mg42_church");
		Util.OnTriggerPosition("MOVER_truck", "corner3", 200, Map.truck_at_corner3);
		Util.MapDebugPrint("truck_past_east_gate");
	},

	truck_at_corner3 = function()
	{
		SetAvailableMapGoals(TEAM.ALLIES, true, {
			"REPAIRMG42_mg42_church",
			"ATTACK_showdown.*",
			"SNIPE_showdown.*",
		});
		SetAvailableMapGoals(TEAM.ALLIES, false, "ATTACK_east_gate.*");
		SetAvailableMapGoals(TEAM.AXIS, false, {
			"DEFEND_east_gate.*",
			"SNIPE_east_gate.*",
			"PLANT_truck_ramp",
		});
		Util.MapDebugPrint("truck_at_corner3");
	},

	Truck_Damaged = function()
	{
		// center it every time it is damaged
		Util.SetPositionGoal( "BUILD_Truck", "MOVER_truck" );
	},

	rope_Built = function()
	{
		Wp.SetWaypointFlag( "rope_dyno", "closed", false );
		Wp.SetWaypointFlag( "urn_snipe1", "closed", true );
		SetAvailableMapGoals(TEAM.AXIS, false, "SNIPE_urn_snipe1");
		SetAvailableMapGoals(TEAM.ALLIES, true, "ROUTE_rope_dyno");
		Util.MapDebugPrint("rope_Built");
	},

	rope_Destroyed = function()
	{
		Wp.SetWaypointFlag( "rope_dyno", "closed", true );
		SetAvailableMapGoals(TEAM.ALLIES, false, "ROUTE_rope_dyno");
		if (!Map.ObjectiveSecured)
		{
			Wp.SetWaypointFlag( "urn_snipe1", "closed", false );
			SetAvailableMapGoals(TEAM.AXIS, true, "SNIPE_urn_snipe1");
		}
		Util.MapDebugPrint("rope_Destroyed");
	},

	forward_Spawn = function()
	{
		SetAvailableMapGoals(TEAM.AXIS, false, {
			"REPAIRMG42_mg42_church",
			"MOUNTMG42_mg42_church",
			"SNIPE_axis_start.*",
			"SNIPE_east_gate.*",
		});
		SetAvailableMapGoals(TEAM.AXIS, true, "SNIPE_urn.*");
		Util.MapDebugPrint("forward_Spawn");
	},
};

global OnMapLoad = function()
{
	// *** TRIGGERS ***
	OnTrigger( "Allied team has breached the east gate", Map.east_Gate_Breached );
	OnTrigger( "Allied team has breached the south valley gate", Map.south_Gate_Breached );
	OnTrigger( "Allied team has breached the west ruins gate", Map.west_Gate_Breached );
	OnTrigger( "Allies have stolen The Urn!", Map.urn_Stolen );
	OnTrigger( "Flag returned Urn!", Map.urn_Returned );
	OnTrigger( "Allied team is escaping with the urn!", Map.urn_Secured );
	OnTrigger( "The Truck has been damaged!", Map.Truck_Damaged );
	OnTrigger( "allies_ropeconstructed", Map.rope_Built );
	OnTrigger( "axis_ropedestroyed", Map.rope_Destroyed );
	OnTrigger( "allies_flagcaptured", Map.forward_Spawn );

	// Move some goals for reachability
	Util.AddUsePtFromWp( "PLANT_east_gate", "eastgate1" );
	Util.AddUsePtFromWp( "PLANT_east_gate", "eastgate2" );
	Util.SetGoalOffset( 0,10,10, "BUILD_Command_Post " );
	Util.SetGoalOffset( 30,-10,-10, "BUILD_truck_ramp" );
	Util.SetGoalOffset( 10,0,0, "PLANT_Axis_Team_Door" );
	rope_target = GetGoal( "PLANT_ruins_access_rope" );
	if (rope_target)
	{
		new_pos = Util.GetWpNamePosition( "rope_dyno" ) + Vector3(0,0,400);
		rope_target.SetPosition( new_pos );
		rope_target.DynamicPosition = false;
	}

	// Some waypoint stuff
	Wp.SetWaypointFlag( "rope_dyno", "closed", true );
	Wp.SetWaypointFlag( "urn_snipe1", "closed", false );

	// Priority and max users
	Util.SetMaxUsersInProgress( 1, "ATTACK_.*" );
	Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsersInProgress( 1, "BUILD_.*" );
	Util.SetMaxUsersInProgress( 2, "BUILD_Truck" );
	Util.SetMaxUsersInProgress( 3, "FLAG_.*" );
	Util.SetMaxUsersInProgress( 2, "CHECKPOINT_.*" );
	Util.SetMaxUsersInProgress( 1, "PLANT_.*" );
	SetGoalPriority("PLANT_.*", 0.9);
	SetGoalPriority("PLANT_truck_ramp", 0.5);
	SetGoalPriority("PLANT_Command_Post", 0.8);
	SetGoalPriority("PLANT_ruins_access_rope", 0.8);
	SetGoalPriority("PLANT_Axis_Team_Door", 0.91);
	SetGoalPriority("PLANT_east_gate", 0.93);
	SetMapGoalProperties( "SNIPE_.*", {MaxCampTime=60} );

	// *** AVAILABILITY AT MAP START ***
	SetAvailableMapGoals(TEAM.ALLIES, false, {
		"MOUNTMG42_.*",
		"REPAIRMG42_.*",
		"BUILD_truck_ramp",
		"BUILD_Truck",
		"ATTACK_.*",
		"DEFEND_.*",
		"SNIPE_.*",
		"ESCORT_truck",
	});
	SetAvailableMapGoals(TEAM.ALLIES, true, "ATTACK_east_gate.*");

	SetAvailableMapGoals(TEAM.AXIS, false, {
		"CHECKPOINT_.*",
		"ATTACK_.*",
		"SNIPE_.*",
	});
	SetAvailableMapGoals(TEAM.AXIS, true, {
		"SNIPE_axis_start.*",
		"SNIPE_east_gate.*",
		"SNIPE_urn_snipe1",
		"DEFEND_.*",
	});
	SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_showdown.*");

	// *** ROUTES ***
	Maproutes =
	{
		CHECKPOINT_forwardspawn =
		{
			ROUTE_allied_spawn =
			{
				ROUTE_left_spawn_exit1 = {},
				ROUTE_left_spawn_exit2 = {},
				ROUTE_right_spawn_exit1 = {},
				ROUTE_right_spawn_exit2 = {},
			},
		},
		FLAG_Urn =
		{
			ROUTE_allied_spawn =
			{
				ROUTE_rope_dyno = {},
				ROUTE_left_spawn_exit1 = { ROUTE_rope_dyno = {} },
				ROUTE_left_spawn_exit2 = { ROUTE_rope_dyno = {} },
				ROUTE_right_spawn_exit1 = {},
				ROUTE_right_spawn_exit2 = {},
			},
			ROUTE_forward_spawn =
			{
				ROUTE_rope_dyno = {},
				ROUTE_wooden_stairs = { ROUTE_wall = {} },
				ROUTE_wall = {},
			},
		},
		ATTACK_east_gate20 = { ROUTE_allied_spawn = {} },
		ATTACK_east_gate21 = { ROUTE_allied_spawn = {} },
		PLANT_east_gate = { ROUTE_allied_spawn = {} },
		PLANT_south_valley_gate = { ROUTE_allied_spawn = {} },
	};
	Maproutes.ATTACK_east_gate20.ROUTE_allied_spawn = Maproutes.CHECKPOINT_forwardspawn.ROUTE_allied_spawn;
	Maproutes.ATTACK_east_gate21.ROUTE_allied_spawn = Maproutes.CHECKPOINT_forwardspawn.ROUTE_allied_spawn;
	Maproutes.PLANT_east_gate.ROUTE_allied_spawn = Maproutes.CHECKPOINT_forwardspawn.ROUTE_allied_spawn;
	Util.Routes(Maproutes);
	SetAvailableMapGoals(TEAM.ALLIES, false, "ROUTE_rope_dyno");

	Util.FixMoverPos("truck", Vec3(-2543.000, 542.500, 2168.500), Vec3(-2544.000, 688.000, 2112.000));

	// *** DONE ***
	Util.MapDebugPrint("Omni-bot map script for Vesuvius loaded.");
};

global OnBotJoin = function( bot )
{
	// Tweak these settings appropriately:
	// bot.MaxViewDistance = 2400.0;
};
