//==========================================================================================
//
//	castellum_final.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	d00d	10 January 2011	Attack/defend management
//	d00d	08 January 2011	Initial script
//
//==========================================================================================
//

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

	iw1 = 0,
	iw2 = 0,
	iw3 = 0,
	ac1 = 0,

	Navigation =
	{
		quickjump =
		{
			// better response time than nav flags
			navigate = function(_this)
			{
				_this.Bot.PressButton(BTN.JUMP);
				yield();
				_this.Bot.PressButton(BTN.JUMP);
				yield();
				_this.Bot.PressButton(BTN.JUMP);
				yield();
			},
		},
	},

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

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

	side_gate_Planted = function( trigger )
	{
		sleep( 0.5 );
		Util.RemoveGoal( "DEFUSE_side_gate_.*" );
		Util.MapDebugPrint( "side_gate_Planted" );
	},

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

	side_door_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_start.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ATTACK_gold.*",
			"FLAG_gold_crate",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"PLANTMINE_sidedoor.*",
			"MOBILEMORTAR_axis_start.*",
			"ATTACK_start.*",
			"AIRSTRIKE_axis_start.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_gold.*" );
		if ( Map.iw1 == 0 )
		{
			Map.iw1 = OnTriggerRegion( AABB(-1785.219,1869.630,1234.552,-1446.091,1968.322,1428.081), RegionTrigger.IntrusionWarning );
			Map.iw3 = OnTriggerRegion( AABB(-1678.186,916.244,1250.219,-1474.362,1122.929,1388.368), RegionTrigger.IntrusionWarning );
			Map.ac1 = OnTriggerRegion( AABB(-1679.683,727.618,1233.572,-1518.660,895.307,1378.508), RegionTrigger.AllClear );
		}
		Util.MapDebugPrint( "side_door_Destroyed" );
	},

	side_gate_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Command_Post",
			"ATTACK_gold.*",
			"FLAG_gold_crate",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_sidegate.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"ATTACK_sidegate.*",
			"ATTACK_start.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_gold.*" );
		if ( Map.iw1 == 0 )
		{
			Map.iw1 = OnTriggerRegion( AABB(-1785.219,1869.630,1234.552,-1446.091,1968.322,1428.081), RegionTrigger.IntrusionWarning );
			Map.iw2 = OnTriggerRegion( AABB(-779.926,1766.552,1153.835,-622.004,1946.652,1395.313), RegionTrigger.IntrusionWarning );
			Map.ac1 = OnTriggerRegion( AABB(-1679.683,727.618,1233.572,-1518.660,895.307,1378.508), RegionTrigger.AllClear );
		}
		Util.MapDebugPrint( "side_gate_Destroyed" );
	},

	gold_crate_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_cappoint.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"PLANTMINE_cappoint.*",
			"ATTACK_cappoint.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_gold.*" );

		Util.MapDebugPrint( "gold_crate_Taken" );
	},

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

	gold_crate_Returned = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_cappoint.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_gold.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_cappoint.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_gold.*" );

		Util.MapDebugPrint( "gold_crate_Returned" );
	},

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

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "The side gate has been repaired!", Map.side_gate_Built );
	OnTrigger( "Planted at the side gate.", Map.side_gate_Planted );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "The Main Entrance has been destroyed!", Map.side_door_Destroyed );
	OnTrigger( "Allies have breached the side gate!", Map.side_gate_Destroyed );
	OnTrigger( "Allies have stolen The Gold Bars!", Map.gold_crate_Taken );
	OnTrigger( "Allied team has dropped the Gold Crate!", Map.gold_crate_Dropped );
	OnTrigger( "Flag returned gold_crate!", Map.gold_crate_Returned );
	OnTrigger( "Allied team has secured the Gold Crate!", Map.gold_crate_Secured );

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

	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"PLANTMINE_.*",
		"MOBILEMORTAR_axis_.*",
		"ATTACK_cappoint.*",
		"ATTACK_gold.*",
		"FLAG_gold_crate",
		"BUILD_Command_Post",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"ATTACK_cappoint.*",
		"ATTACK_gold.*",
		"PLANTMINE_cappoint.*",
	});

	// Priorities
	SetGoalPriority( "BUILD_Command_Post", 0.8 );
	SetGoalPriority( "PLANT_Command_Post", 0.7 );

	// Max users per goal
	Util.SetMaxUsers( 1, "BUILD_Command_Post" );
	Util.SetMaxUsers( 1, "PLANT_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 3, "FLAG_gold_crate" );

	// Use points
	Util.AddUsePoint( "PLANT_side_door", { Vec3(-1888,-14,900), Vec3(-1824,20,900) } );
	Util.AddUsePoint( "PLANT_side_gate", { Vec3(1676,360,780), Vec3(1707,337,780) } );

	MapRoutes =
	{
		FLAG_gold_crate = {
			ROUTE_allied_spawn = {
				ROUTE_outside = {},
			},
			ROUTE_hall = {
				ROUTE_outside = {},
				ROUTE_fountain = {},
				ROUTE_tower = {}
				// TODO: add more routes here
			},
			ROUTE_upper_hall = {
				ROUTE_exit_right = {},
				ROUTE_stairs = {}
			}
		},
		PLANT_side_gate = {
			ROUTE_allied_spawn = {
				ROUTE_water = {},
				ROUTE_hilltop = {}
			},
			ROUTE_sidedoor = {
				ROUTE_water = {},
				ROUTE_hilltop = {}
			}
		},
		CAPPOINT_boat = {
			ROUTE_gold = {
				ROUTE_balcony = {},
				ROUTE_fountain = {},
				ROUTE_tower = {}
			}
		},
		ATTACK_sidegate_1 = {
			ROUTE_allied_spawn = {
				ROUTE_hilltop = {}, // test
				ROUTE_trees = {}
			},
			ROUTE_sidedoor = {
				ROUTE_hilltop = {}, // test
				ROUTE_trees = {}
			}
		},
		ATTACK_start_1 = {
			ROUTE_river_area = {
				ROUTE_trees = {}
			}
		},
	};
	MapRoutes.ATTACK_cappoint_1 = MapRoutes.CAPPOINT_boat;
	MapRoutes.ATTACK_cappoint_2 = MapRoutes.CAPPOINT_boat;
	MapRoutes.ATTACK_cappoint_3 = MapRoutes.CAPPOINT_boat;
	MapRoutes.ATTACK_cappoint_4 = MapRoutes.CAPPOINT_boat;
	MapRoutes.ATTACK_cappoint_5 = MapRoutes.CAPPOINT_boat;
	MapRoutes.ATTACK_cappoint_6 = MapRoutes.CAPPOINT_boat;
	MapRoutes.ATTACK_cappoint_7 = MapRoutes.CAPPOINT_boat;
	MapRoutes.ATTACK_cappoint_8 = MapRoutes.CAPPOINT_boat;
	MapRoutes.ATTACK_sidegate_2 = MapRoutes.ATTACK_sidegate_1;
	MapRoutes.ATTACK_sidegate_3 = MapRoutes.ATTACK_sidegate_1;
	MapRoutes.ATTACK_sidegate_4 = MapRoutes.ATTACK_sidegate_1;
	MapRoutes.ATTACK_start_2 = MapRoutes.ATTACK_start_1;
	MapRoutes.ATTACK_start_3 = MapRoutes.ATTACK_start_1;
	MapRoutes.ATTACK_start_4 = MapRoutes.ATTACK_start_1;
	MapRoutes.ATTACK_start_5 = MapRoutes.ATTACK_start_1;
	MapRoutes.ATTACK_start_6 = MapRoutes.ATTACK_start_1;
	MapRoutes.ATTACK_start_7 = MapRoutes.ATTACK_start_1;
	MapRoutes.ATTACK_start_8 = MapRoutes.ATTACK_start_1;
	MapRoutes.ATTACK_start_9 = MapRoutes.ATTACK_start_1;
	MapRoutes.ATTACK_gold_1 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_2 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_3 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_4 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_5 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_6 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_7 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_8 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_9 = MapRoutes.FLAG_gold_crate;
	MapRoutes.ATTACK_gold_10 = MapRoutes.FLAG_gold_crate;
	Util.Routes(MapRoutes);

	Util.MapDebugPrint( "Omni-bot map script for Castellum (final) executed." );
};

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