//==========================================================================================
//
//	cherbourg.gm
//
//	Who	When		What
//------------------------------------------------------------------------------------------
//	palota	16 November 2012	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0,
	bankwallDestroyed = false,
	barricadeDestroyed = true,
	factoryTeam = TEAM.AXIS,
	Movers = { "MOVER_tower", "MOVER_roadblock" },

	Roles =
	{
		AXIS =
		{
			AllBots = true, // each bot is considered for a role
			DEFENDER1 =
			{
				numbots = 9,
			},
			DEFENDER2 =
			{
				numbots = 9,
			},
			DEFENDER3 =
			{
				numbots = 9,
			},
			DEFENDER =
			{
				numbots = 9,
			},
		}
	},

	tower_Built = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, true, ".*MG42_tower");
		Util.MapDebugPrint( "tower_Built" );
	},

	tower_Destroyed = function( trigger )
	{
		SetAvailableMapGoals(TEAM.ALLIES, false, ".*MG42_tower");
		Util.MapDebugPrint( "tower_Destroyed" );
	},

	roadblock_Built = function( trigger )
	{
		SetAvailableMapGoals(TEAM.AXIS, false, "BUILD_Axis_Roadblock" );
		SetAvailableMapGoals(TEAM.AXIS, true, ".*MG42_Axis_Roadblock");
		SetAvailableMapGoals(TEAM.ALLIES, true, "PLANT_Axis_Roadblock" );
		Util.MapDebugPrint( "roadblock_Built" );
	},

	roadblock_Destroyed = function( trigger )
	{
		SetAvailableMapGoals(TEAM.AXIS, true, "BUILD_Axis_Roadblock" );
		SetAvailableMapGoals(TEAM.AXIS, false, ".*MG42_Axis_Roadblock");
		SetAvailableMapGoals(TEAM.ALLIES, false, "PLANT_Axis_Roadblock" );
		Util.MapDebugPrint( "roadblock_Destroyed" );
	},

	barricade_Built = function( trigger )
	{
		Map.barricadeDestroyed = false;
		Util.DisableGoal("ROUTE_barricade");
		if(Map.factoryTeam == TEAM.AXIS){
			Util.SetRoleForGoals("CHECKPOINT_factoryflag", ROLE.INFILTRATOR);
		}
		SetGoalPriority("DEFEND_factory[123]", 0.49);
		Util.MapDebugPrint( "barricade_Built" );
	},

	barricade_Destroyed = function( trigger )
	{
		Map.barricadeDestroyed = true;
		Util.EnableGoal("ROUTE_barricade");
		Util.ClearRoleForGoals("CHECKPOINT_factoryflag", ROLE.INFILTRATOR);
		SetGoalPriority("DEFEND_factory[123]", 0.5);
		Util.MapDebugPrint( "barricade_Destroyed" );
	},

	bankwall_Destroyed = function( trigger )
	{
		Map.bankwallDestroyed = true;
		Util.ClearRoleForGoals("CHECKPOINT_bankflag", ROLE.INFILTRATOR);
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_bank.*" );
		Util.MapDebugPrint( "bankwall_Destroyed" );
	},

	yardwall_Destroyed = function( trigger )
	{
		Util.EnableGoal("ROUTE_yard_wall");
		Util.MapDebugPrint( "yardwall_Destroyed" );
	},


	Dam_Flag_Axis = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_dam.*" );
		Util.ClearRoleForGoals("CHECKPOINT_damflag", ROLE.DEFENDER1);
		Util.MapDebugPrint( "Dam_Flag_Axis" );
	},

	Dam_Flag_Allies = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_dam.*" );
		Util.SetRoleForGoals("CHECKPOINT_damflag", ROLE.DEFENDER1);
		Util.MapDebugPrint( "Dam_Flag_Allies" );
	},

	Factory_Flag_Axis = function( trigger )
	{
		Map.factoryTeam = TEAM.AXIS;
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_factory.*" );
		if(!Map.barricadeDestroyed){
			Util.SetRoleForGoals("CHECKPOINT_factoryflag", ROLE.INFILTRATOR);
		}
		Util.ClearRoleForGoals("CHECKPOINT_factoryflag", ROLE.DEFENDER2);
		Util.MapDebugPrint( "Factory_Flag_Axis" );
	},

	Factory_Flag_Allies = function( trigger )
	{
		Map.factoryTeam = TEAM.ALLIES;
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_factory.*" );
		Util.ClearRoleForGoals("CHECKPOINT_factoryflag", ROLE.INFILTRATOR);
		Util.SetRoleForGoals("CHECKPOINT_factoryflag", ROLE.DEFENDER2);
		Util.MapDebugPrint( "Factory_Flag_Allies" );
	},

	Dock_Flag_Axis = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_dock.*" );
		Util.ClearRoleForGoals("CHECKPOINT_dockflag", ROLE.DEFENDER2);
		Util.MapDebugPrint( "Dock_Flag_Axis" );
	},

	Dock_Flag_Allies = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_dock.*" );
		Util.SetRoleForGoals("CHECKPOINT_dockflag", ROLE.DEFENDER2);
		Util.MapDebugPrint( "Dock_Flag_Allies" );
	},

	Courtyard_Flag_Axis = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_yard.*" );
		Util.ClearRoleForGoals("CHECKPOINT_yardflag", ROLE.DEFENDER3);
		Util.MapDebugPrint( "Courtyard_Flag_Axis" );
	},

	Courtyard_Flag_Allies = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_yard.*" );
		Util.SetRoleForGoals("CHECKPOINT_yardflag", ROLE.DEFENDER3);
		Util.MapDebugPrint( "Courtyard_Flag_Allies" );
	},

	Bank_Flag_Axis = function( trigger )
	{
		if(!Map.bankwallDestroyed){
			Util.SetRoleForGoals("CHECKPOINT_bankflag", ROLE.INFILTRATOR);
		}else{
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_bank.*" );
		}
		Util.ClearRoleForGoals("CHECKPOINT_bankflag", ROLE.DEFENDER);
		Util.MapDebugPrint( "Bank_Flag_Axis" );
	},

	Bank_Flag_Allies = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_bank.*" );
		Util.ClearRoleForGoals("CHECKPOINT_bankflag", ROLE.INFILTRATOR);
		Util.SetRoleForGoals("CHECKPOINT_bankflag", ROLE.DEFENDER);
		Util.MapDebugPrint( "Bank_Flag_Allies" );
	},
};

global OnMapLoad = function()
{
	OnTrigger( "Allied Tower has been constructed.", Map.tower_Built );
	OnTrigger( "Allied Tower has been destroyed.", Map.tower_Destroyed );
	OnTrigger( "Axis Roadblock has been constructed.", Map.roadblock_Built );
	OnTrigger( "Axis Roadblock has been destroyed.", Map.roadblock_Destroyed );
	OnTrigger( "Barricade has been constructed.", Map.barricade_Built );
	OnTrigger( "Axis Barricade has been destroyed.", Map.barricade_Destroyed );
	OnTrigger( "bankwall Destroyed.", Map.bankwall_Destroyed );
	OnTrigger( "the Courtyard Wall Destroyed.", Map.yardwall_Destroyed );
	OnTrigger( "Axis capture the Dam Flag!", Map.Dam_Flag_Axis );
	OnTrigger( "Allies capture the Dam Flag!", Map.Dam_Flag_Allies );
	OnTrigger( "Axis capture the Factory Flag!", Map.Factory_Flag_Axis );
	OnTrigger( "Allies capture the Factory Flag!", Map.Factory_Flag_Allies );
	OnTrigger( "Axis capture the Dock Flag!", Map.Dock_Flag_Axis );
	OnTrigger( "Allies capture the Dock Flag!", Map.Dock_Flag_Allies );
	OnTrigger( "Axis capture the Courtyard Flag!", Map.Courtyard_Flag_Axis );
	OnTrigger( "Allies capture the Courtyard Flag!", Map.Courtyard_Flag_Allies );
	OnTrigger( "Axis capture the Bank Flag!", Map.Bank_Flag_Axis );
	OnTrigger( "Allies capture the Bank Flag!", Map.Bank_Flag_Allies );

	Util.DisableGoal("ROUTE_yard_wall");
	Util.DisableGoal(".*MG42_tower");
	Util.DisableGoal(".*MG42_Axis_Roadblock");
	Util.LimitToTeam(TEAM.AXIS, "DEFEND.*");
	Util.LimitToTeam(TEAM.AXIS, "PLANTMINE.*");
	Util.LimitToTeam(TEAM.ALLIES, "ATTACK.*");
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_bank.*" );

	SetGoalPriority("BUILD_Axis_Command_Post", 0.95);
	SetGoalPriority("SNIPE.*", 0.75, TEAM.AXIS);
	SetGoalPriority("SNIPE.*", 0.81, TEAM.ALLIES);
	SetGoalPriority("PLANT_tower", 0.74);
	SetGoalPriority("PLANT_Allied_Command_Post", 0.75);
	SetGoalPriority("PLANT_Axis_Command_Post", 0.7);

	Util.ClearRoleForGoals("CHECKPOINT_.*", {ROLE.INFILTRATOR,ROLE.DEFENDER,ROLE.DEFENDER1,ROLE.DEFENDER2,ROLE.DEFENDER3});
	Util.SetRoleForTable({"CHECKPOINT_bankflag", "PLANT_Axis_Command_Post"}, ROLE.INFILTRATOR);
	Util.SetRoleForGoals("MOUNTMG42_Axis_Roadblock", {ROLE.DEFENDER, ROLE.DEFENDER2} );
	Util.SetRoleForGoals("DEFEND_dam.*", ROLE.DEFENDER1);
	Util.SetRoleForGoals("DEFEND_factory.*", ROLE.DEFENDER2);
	Util.SetRoleForGoals("DEFEND_dock.*", ROLE.DEFENDER2);
	Util.SetRoleForGoals("DEFEND_yard.*", ROLE.DEFENDER3);
	Util.SetRoleForGoals("DEFEND_bank.*", ROLE.DEFENDER);
	Util.SetRoleForGoals("DEFEND_road.*", ROLE.DEFENDER);

	Util.AddUsePoint("PLANT_Courtyard_Wall", Vec3(2336.309, -1019.527, -531.018));
	Util.AddUsePoint("PLANT_Axis_Barricade", Vec3(-964.671, -2420.430, -423.875));
	Util.AddUsePoint("BUILD_Axis_Roadblock", Vec3(118.425, -1150.348, -527.875));
	Util.AddUsePoint("PLANT_Axis_Roadblock", Vec3(11.328, -932.969, -527.875));
	Util.SetGoalOffset(0,20,0, "MOUNTMG42_tower");

	SetMapGoalProperties( "ATTACK_.*", {mincamptime=5, maxcamptime=15} );
	SetMapGoalProperties( "DEFEND_.*", {mincamptime=10, maxcamptime=25} );

	Util.SetMaxUsers(1, "BUILD_.*");
	Util.SetMaxUsers(1, "MOUNTMG42_.*");

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 100.0;
	Util.IgnoreTargetGoalTable( bot, Map.Movers );
};
