//==========================================================================================
//
//	wolfsrudel3_final.gm
//
//	Omni-bot 0.8 script for Wolfsrudel3 final, by d00d
//	15 October 2009
//	Waypoints (mostly) by Blindman
//	Many thanks to BOK Naerling for testing and suggestions
//
//==========================================================================================

global Map =
{
	Debug = false,
	bunker_secured = false,
	box1status = "home", // "home", "taken", "secured"
	box2status = "home", // "home", "taken", "secured"

	Ammo_Cabinet_cabinet_ammo_model = "AMMOCAB_cabinet_ammo_model",
	Ammo_Cabinet_t10000345 = "AMMOCAB_t10000345",
	Health_Cabinet_cabinet_health_model = "HEALTHCAB_cabinet_health_model",
	Health_Cabinet_t10000346 = "HEALTHCAB_t10000346",
	Checkpoint_forwardbunker_flag = "CHECKPOINT_forwardbunker_flag",
	Flag_emitterbox1 = "FLAG_emitterbox1",
	Flag_emitterbox2 = "FLAG_emitterbox2",
	Build_Antenna_Defense = "BUILD_Antenna_Defense",
	Build_Command_Post = "BUILD_Command_Post",
	Build_Woodenbarrier = "BUILD_Woodenbarrier",
	Plant_Antenna_Defense = "PLANT_Antenna_Defense",
	Plant_Bunker_Sidewall = "PLANT_Bunker_Sidewall",
	Plant_Command_Post = "PLANT_Command_Post",
	Plant_Forwardbunkerdoor = "PLANT_Forwardbunkerdoor",
	Plant_Mainbunkergate = "PLANT_Mainbunkergate",
	Plant_Radio_Mast = "PLANT_Radio_Mast",
	Plant_Sidewall = "PLANT_Sidewall",
	Plant_Woodenbarrier = "PLANT_Woodenbarrier",
	Mount_Spawn_MG = "MOUNTMG42_14",
	Mount_Fort_MG = "MOUNTMG42_94",
	Mount_Bunker_MG = "MOUNTMG42_155",
	Repair_Spawn_MG = "REPAIRMG42_14",
	Repair_Fort_MG = "REPAIRMG42_94",
	Repair_Bunker_MG = "REPAIRMG42_155",

	Antenna_Defense_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "AIRSTRIKE_radio" );
		Util.MapDebugPrint( "Antenna_Defense_Built" );
	},

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

	Woodenbarrier_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"ROUTE_woodendoor1",
			"ROUTE_woodendoor2",
		});
		Util.MapDebugPrint( "Woodenbarrier_Built" );
	},

	Antenna_Defense_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "AIRSTRIKE_radio" );
		Util.MapDebugPrint( "Antenna_Defense_Destroyed" );
	},

	Bunker_Sidewall_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "ROUTE_sidewall_left" );

		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_start.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"ROUTE_sidewall_left",
			"DEFEND_fort.*",
			"DEFEND_radiomast.*",
			"DEFEND_radarparts.*",
			Map.Mount_Fort_MG,
			Map.Repair_Fort_MG,
		});

		Util.MapDebugPrint( "Bunker_Sidewall_Destroyed" );
	},

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

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

	Mainbunkergate_Destroyed = function( trigger )
	{
		Map.bunker_secured = true;
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			Repair_Bunker_MG,
			Mount_Bunker_MG,
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_bunkergate.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "SNIPE_allies.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			Map.Mount_Spawn_MG,
			Map.Repair_Spawn_MG,
		});

		SetAvailableMapGoals( TEAM.AXIS, false, {
			Repair_Bunker_MG,
			Mount_Bunker_MG,
			"DEFEND_forwardbunker.*",
			"HEALTHCAB_t10000346",
			"AMMOCAB_t10000345",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"SNIPE_fort.*",
			Map.Mount_Fort_MG,
			Map.Repair_Fort_MG,
		});

		foreach ( bot in BotTable )
		{
			if ( bot.GetTeam() == TEAM.ALLIES )
			{
				bot.ChangeSpawnPoint(0);
			}
		}
		Util.MapDebugPrint( "Mainbunkergate_Destroyed" );
	},

	Radio_Mast_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"SNIPE_fort4",
			"SNIPE_fort5",
			"SNIPE_fort6",
			"DEFEND_radiomast.*",
			"PLANTMINE_radiomast.*",
			"BUILD_Antenna_Defense",
			"AIRSTRIKE_radio",
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Antenna_Defense" );
		Util.MapDebugPrint( "Radio_Mast_Destroyed" );
	},

	Sidewall_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "ROUTE_sidewall_right" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"ROUTE_sidewall_right",
			"DEFEND_fort.*",
			"DEFEND_radiomast.*",
			"DEFEND_radarparts.*",
			Map.Mount_Fort_MG,
			Map.Repair_Fort_MG,
		});
		Util.MapDebugPrint( "Sidewall_Destroyed" );
	},

	Woodenbarrier_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"ROUTE_woodendoor1",
			"ROUTE_woodendoor2",
		});
		Util.MapDebugPrint( "Woodenbarrier_Destroyed" );
	},

	emitterbox1_Taken = function( trigger )
	{
		Map.box1status = "taken";

		if ( Map.box2status != "home" )
		{
			SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_radarpart.*");
		}

		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_cappoint.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_cappoint.*" );
		SetGoalPriority( "DEFEND_cappoint.*", 0.8 );
		Util.MapDebugPrint( "emitterbox1_Taken" );
	},

	emitterbox1_Returned = function( trigger )
	{
		Map.box1status = "home";

		if ( Map.box2status != "taken" )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_cappoint.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_cappoint.*" );
		}
		SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_radarpart.*");

		Util.MapDebugPrint( "emitterbox1_Returned" );
	},

	emitterbox2_Taken = function( trigger )
	{
		Map.box2status = "taken";

		if ( Map.box1status != "home" )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_radarpart.*" );
		}
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_cappoint.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_cappoint.*" );
		SetGoalPriority( "DEFEND_cappoint.*", 0.8 );

		Util.MapDebugPrint( "emitterbox2_Taken" );
	},

	emitterbox2_Returned = function( trigger )
	{
		Map.box2status = "home";

		if ( Map.box1status != "taken" )
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_cappoint.*" );
			SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_cappoint.*" );
		}
		SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_radarpart.*");

		Util.MapDebugPrint( "emitterbox2_Returned" );
	},

	emitterbox1_Secured = function( trigger )
	{
		Map.box1status = "secured";
		if ( Map.box2status == "secured" )
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, "SNIPE_compost" );
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_radarpart.*",
				"DEFEND_cappoint.*",
			});
			SetAvailableMapGoals( TEAM.ALLIES, false, {
				"DEFEND_cappoint.*",
				"PLANT_woodenbarrier",
			});
		}

		Util.MapDebugPrint( "emitterbox_Secured" );
	},

	emitterbox2_Secured = function( trigger )
	{
		Map.box2status = "secured";
		if ( Map.box1status == "secured" )
		{
			SetAvailableMapGoals( TEAM.ALLIES, false, "SNIPE_compost" );
			SetAvailableMapGoals( TEAM.AXIS, false, {
				"DEFEND_radarpart.*",
				"DEFEND_cappoint.*",
			});
			SetAvailableMapGoals( TEAM.ALLIES, false, {
				"DEFEND_cappoint.*",
				"PLANT_woodenbarrier",
			});
		}

		Util.MapDebugPrint( "emitterbox_Secured" );
	},

	forwardbunker_flag_Axis_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			Repair_Bunker_MG,
			Mount_Bunker_MG,
		});
		SetAvailableMapGoals( TEAM.AXIS, true, {
			Repair_Bunker_MG,
			Mount_Bunker_MG,
		});
		Util.MapDebugPrint( "forwardbunker_flag_Axis_Captured" );
	},

	forwardbunker_flag_Allies_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			Repair_Bunker_MG,
			Mount_Bunker_MG,
		});
		SetAvailableMapGoals( TEAM.AXIS, false, {
			Repair_Bunker_MG,
			Mount_Bunker_MG,
		});
		Util.MapDebugPrint( "forwardbunker_flag_Allies_Captured" );
	},

};

global OnMapLoad = function()
{
	/*** TRIGGER REGISTRATION ***/
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Command_Post_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Command_Post_Destroyed );
	OnTrigger( "The Antenna Defense has been constructed.", Map.Antenna_Defense_Built );
	OnTrigger( "The Allies have destroyed the  Antenna defense!", Map.Antenna_Defense_Destroyed );
	OnTrigger( "The Woodenbarrier has been constructed.", Map.Woodenbarrier_Built );
	OnTrigger( "The Allies have destroyed the Woodenbarrier!", Map.Woodenbarrier_Destroyed );
	OnTrigger( "The Allies have breached the Sidewall!", Map.Sidewall_Destroyed );
	OnTrigger( "The Allies have breached the Bunkersidewall!", Map.Bunker_Sidewall_Destroyed );
	OnTrigger( "The Allies breach the Forwardbunkerdoor!", Map.Forwardbunkerdoor_Destroyed );
	OnTrigger( "Allies have breached the Main Entrance and secured the Forward Bunker!", Map.Mainbunkergate_Destroyed );
	OnTrigger( "Allies have destroyed the Main Radio Mast!", Map.Radio_Mast_Destroyed );
	OnTrigger( "Allies have stolen the First Radarparts!", Map.emitterbox1_Taken );
	OnTrigger( "Flag returned emitterbox1!", Map.emitterbox1_Returned );
	OnTrigger( "Allies have stolen the Second Radarparts!", Map.emitterbox2_Taken );
	OnTrigger( "Flag returned emitterbox2!", Map.emitterbox2_Returned );
	OnTrigger( "Allies have secured the First Radar Parts!", Map.emitterbox1_Secured );
	OnTrigger( "Allies have secured the Second Radar Parts!", Map.emitterbox2_Secured );
	OnTrigger( "allies_reclaims_forwardbunker_flag", Map.forwardbunker_flag_Allies_Captured );
	OnTrigger( "axis_reclaims_forwardbunker_flag", Map.forwardbunker_flag_Axis_Captured );

	/*** INITIAL AVAILABILITY OF MAP GOALS ***/
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"AIRSTRIKE_.*",
		"PLANTMINE_.*",
		"DEFEND_.*",
		"MOUNTMG42_.*",
		"REPAIRMG42_.*",
		Map.Mount_Spawn_MG,
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		Map.Mount_Bunker_MG,
		Map.Repair_Bunker_MG,
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, {
		Map.Repair_Spawn_MG,
		"SNIPE_.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, true, "SNIPE_compost" );

	SetAvailableMapGoals( TEAM.AXIS, false, "AIRSTRIKE_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANTMINE_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"SNIPE_.*",
		Map.Mount_Spawn_MG,
		Map.Repair_Spawn_MG,
		Map.Mount_Fort_MG,
		Map.Repair_Fort_MG,
		"ATTACK.*",
		"DEFEND.*",
	});
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_start.*",
		"DEFEND_forwardbunker.*",
	});

	/*** PRIORITY ***/
	SetGoalPriority( "CHECKPOINT_forwardbunker_flag", 0.8 );
	SetGoalPriority( "CHECKPOINT_forwardbunker_flag", 0.7, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Forwardbunkerdoor", 0.82, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Mainbunkergate", 0.81, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Forwardbunkerdoor", 0.0, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "BUILD_Command_Post", 0.8, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "PLANT_Woodenbarrier", 0.8, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "PLANT_Woodenbarrier", 0.0, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "FLAG_emitterbox1", 0.8, TEAM.ALLIES );
	SetGoalPriority( "FLAG_emitterbox2", 0.81, TEAM.ALLIES );

	/*** GOAL POSITIONS ***/
	Util.SetGoalOffset( -10, -20, 0, "PLANT_Radio_Mast" );
	Util.SetGoalOffset( 0, -10, 0, "PLANT_Forwardbunkerdoor" );
	Util.SetGoalOffset( -10, 0, 0, "PLANT_Woodenbarrier" );

	/*** MAX USERS ***/
	Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );
	Util.SetMaxUsersInProgress( 1, "BUILD_.*" );
	Util.SetMaxUsersInProgress( 1, "PLANT_.*" );
	Util.SetMaxUsersInProgress( 1, "MOUNTMG42_.*" );

	/*** ROUTES ***/
	MapRoutes =
	{
		CAPPOINT_cappoint2 =
		{
			ROUTE_objective =
			{
				ROUTE_frontdoor1 =
				{
					ROUTE_sidewall_left = {},
					ROUTE_sidewall_right = {},
					ROUTE_maingate = {},
				},
				ROUTE_woodendoor1 =
				{
					ROUTE_woodendoor2 =
					{
						ROUTE_sidewall_left = {},
						ROUTE_sidewall_right = {},
						ROUTE_maingate = {},
					}
				}
			},
		},
		BUILD_Command_Post =
		{
			ROUTE_cabinspawn =
			{
				ROUTE_backdoor = {},
				ROUTE_frontdoor =	{ ROUTE_logs = {} }
			},
			ROUTE_watertower =
			{
				ROUTE_left = {},
				ROUTE_right = {}
			}
		},
		PLANT_Forwardbunkerdoor =
		{
			ROUTE_cabinspawn =
			{
				ROUTE_hill =
				{
					ROUTE_right = {},
				},
			},
		},
		CHECKPOINT_forwardbunker_flag =
		{
			ROUTE_watertower =
			{
				ROUTE_left =
				{
					ROUTE_bunker = {},
					ROUTE_middle = {},
					ROUTE_logs = {},
				},
				ROUTE_right =
				{
					ROUTE_bunker = {},
					ROUTE_middle = {},
					ROUTE_tunnel = {},
				}
			},
			ROUTE_cabinspawn =
			{
				ROUTE_backdoor =
				{
					ROUTE_logs = {},
				},
				ROUTE_frontdoor =
				{
					ROUTE_bunker = {},
					ROUTE_middle = {},
					ROUTE_bunkerdoor = { ROUTE_tunnel = {} }
				},
				ROUTE_middle = {},
				ROUTE_bunkerdoor = {},
			},
			ROUTE_axisspawn =
			{
				ROUTE_axisdoor = {},
				ROUTE_gate = {},
				ROUTE_ladder = {},
			},
		},
		PLANT_Command_Post =
		{
			ROUTE_axisspawn =
			{
				ROUTE_axisdoor = {},
				ROUTE_gate = {},
				ROUTE_ladder = {},
			},
		},
		PLANT_Woodenbarrier =
		{
			ROUTE_bunkerspawn =
			{
				ROUTE_sidewall_left = {},
				ROUTE_sidewall_right = {},
				ROUTE_maingate = {},
			},
			ROUTE_cabinspawn =
			{
				ROUTE_backdoor =
				{
					ROUTE_logs = {},
					ROUTE_sidewall_left = {},
					ROUTE_sidewall_right = {},
					ROUTE_maingate = {},
				},
				ROUTE_frontdoor =
				{
					ROUTE_bunker = {},
					ROUTE_middle = {},
					ROUTE_bunkerdoor = { ROUTE_tunnel = {} },
					ROUTE_sidewall_left = {},
					ROUTE_sidewall_right = {},
					ROUTE_maingate = {},
				},
				ROUTE_middle = {},
				ROUTE_bunkerdoor = {},
			},
		}
	};
	MapRoutes.PLANT_Sidewall = MapRoutes.CHECKPOINT_forwardbunker_flag;
	MapRoutes.PLANT_Bunker_Sidewall = MapRoutes.CHECKPOINT_forwardbunker_flag;
	MapRoutes.PLANT_Mainbunkergate = MapRoutes.CHECKPOINT_forwardbunker_flag;
	MapRoutes.PLANT_Radio_Mast = MapRoutes.PLANT_Woodenbarrier;
	MapRoutes.PLANT_Antenna_Defense = MapRoutes.PLANT_Woodenbarrier;
	MapRoutes.FLAG_emitterbox1 = MapRoutes.PLANT_Woodenbarrier;
	MapRoutes.FLAG_emitterbox2 = MapRoutes.PLANT_Woodenbarrier;
	MapRoutes.BUILD_Antenna_Defense = MapRoutes.PLANT_Command_Post;
	MapRoutes.BUILD_Woodenbarrier = MapRoutes.PLANT_Command_Post;

	Util.Routes(MapRoutes);

	SetAvailableMapGoals( TEAM.ALLIES, false, {
		"ROUTE_sidewall_left",
		"ROUTE_sidewall_right",
	});
	SetAvailableMapGoals( TEAM.AXIS, false, {
		"ROUTE_sidewall_left",
		"ROUTE_sidewall_right",
	});

	Util.MapDebugPrint( "OnMapLoad" );
};

global OnBotJoin = function( bot )
{
	// half of the allies should spawn at the water tower
	if ( !Map.bunker_secured )
	{
		Util.ChangeBotSpawn( bot, TEAM.ALLIES, 4, 5 );
	}
};
