//==========================================================================================
//
//	uje_forbidden_city.gm
//  uje forbidden city B6
//	Who       	             When		          What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Niek	    14 April 2020	     Initial Script
//  ^1[UJE]^3Captain	18 September 2020	added defense / attack and improvement
//==========================================================================================
//

global Map =
{
   	//set status' for conditionals,
	fountain = true,

    Axis_Command_Post_Built = function()
	{
    SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Axis_Command_Post" );

  	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Command_Post" );

	Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},

    Axis_Command_Post_Destroyed = function()
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_Command_Post" );

	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_Command_Post" );

		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

	Allied_Command_Post_Built = function()
	{
    SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Allied_Command_Post" );

	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_Command_Post" );

		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},

	Allied_Command_Post_Destroyed = function()
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_Command_Post" );

    SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Allied_Command_Post" );

		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},

	first_door_Destroyed = function()
	{
    if ( Map.fountain )
	{
    SetAvailableMapGoals( TEAM.AXIS, true, {
    "PLANT_Fountain",
    "ATTACK_Fountain.*"
    } );
    }
	SetAvailableMapGoals( TEAM.AXIS, false, {
    "PLANT_first_door",
    "ATTACK_first_door.*",
    "ATTACK_flag.*"
    } );

    Wp.SetWaypointFlag( "first_door", "closed", false );

		Util.MapDebugPrint( "First_door_Destroyed" );
	},

	second_door_Destroyed = function()
	{
    if ( Map.fountain )
	{
    SetAvailableMapGoals( TEAM.AXIS, true, {
    "PLANT_Fountain",
    "ATTACK_Fountain.*"
    } );
    }
	SetAvailableMapGoals( TEAM.AXIS, false, {
    "PLANT_second_door",
    "ATTACK_second_door.*",
    "ATTACK_flag.*"
    } );

    Wp.SetWaypointFlag( "second_door", "closed", false );

		Util.MapDebugPrint( "Second_door_Destroyed" );
	},

	oldcityflag_Axis_Captured = function()
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT.*" );
    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_flag.*" );

    SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT.*" );

		Util.MapDebugPrint( "oldcityflag_Axis_Captured" );
	},

	oldcityflag_Allies_Captured = function()
	{
    if ( Map.fountain )
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_flag.*" );
    }
    SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT.*" );

    SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT.*" );

		Util.MapDebugPrint( "oldcityflag_Allies_Captured" );
	},

	allies_capture_oldcityflag = function()
	{
	SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT.*" );

    SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT.*" );

		Util.MapDebugPrint( "Allied Captured The Town!" );
	},

	Fountain_entrance_Destroyed = function()
	{
    Map.fountain = false;
    SetAvailableMapGoals( TEAM.ALLIES, false, {
    "PLANT_Axis_Command_Post",
    "BUILD_Allied_Command_Post",
    "DEFEND_flag.*",
    "DEFEND_Fountain.*"
    } );

    SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Gold.*" );

    SetAvailableMapGoals( TEAM.AXIS, false, {
    "PLANT_Fountain",
    "ATTACK_Fountain.*"
    } );

    SetAvailableMapGoals( TEAM.AXIS, true, {
    "PLANT_Allied_Gold.*",
    "ATTACK_Gold.*"
    } );

    Wp.SetWaypointFlag( "teleport_S", "blockwall", false );

		Util.MapDebugPrint( "Fountain_entrance_Destroyed" );
	},

    Allied_Gold_1_Destroyed = function()
	{
    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Gold_1_.*" );

    SetAvailableMapGoals( TEAM.AXIS, false, {
    "ATTACK_Gold_1_.*",
    "PLANT_Allied_Gold_1"
    } );

		Util.MapDebugPrint( "Allied_Gold_1_Destroyed" );
	},

    Allied_Gold_2_Destroyed = function()
	{
    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Gold_2_.*" );

    SetAvailableMapGoals( TEAM.AXIS, false, {
    "ATTACK_Gold_2_.*",
    "PLANT_Allied_Gold_2"
    } );

		Util.MapDebugPrint( "Allied_Gold_2_Destroyed" );
	},

	Allied_Gold_3_Destroyed = function()
	{
    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Gold_0_.*" );

    SetAvailableMapGoals( TEAM.AXIS, false, {
    "ATTACK_Gold_0_.*",
    "PLANT_Allied_Gold"
    } );

		Util.MapDebugPrint( "Allied_Gold_Destroyed" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );

    OnTrigger( "The first door has been destroyed", Map.first_door_Destroyed );
	OnTrigger( "The second door has been destroyed", Map.second_door_Destroyed );

	OnTrigger( "Axis reclaim the City!", Map.oldcityflag_Axis_Captured );
	OnTrigger( "Allied Captured The Town!", Map.oldcityflag_Allies_Captured );
    OnTrigger( "allies_capture_oldcityflag", Map.allies_capture_oldcityflag );

	OnTrigger( "Axis have gained access to the underground", Map.Fountain_entrance_Destroyed );
	OnTrigger( "Axis have destroyed the first Gold", Map.Allied_Gold_2_Destroyed );
	OnTrigger( "Axis have destroyed the second gold!", Map.Allied_Gold_3_Destroyed );
	OnTrigger( "Axis have destroyed the Thirth Gold!", Map.Allied_Gold_1_Destroyed );


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


	// activation ALLIES
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	"BUILD_Allied_Command_Post",
	"CHECKPOINT.*",
    "DEFEND_Fountain.*",
	"DEFEND_flag.*",
	".*CAB_uje1.*",
	".*CAB_uje4.*",
    ".*CAB_uje7.*"
	} );

	// activation AXIS
	SetAvailableMapGoals( TEAM.AXIS, true, {
	"BUILD_Axis_Command_Post",
    ".*CAB_uje6.*",
    ".*CAB_uje7.*",
	"ATTACK_flag.*",
	"ATTACK_.*door.*",
	"PLANT_first_door",
	"PLANT_second_door",
	"CHECKPOINT.*"
	} );

	// Max users per goal
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND.*" );
	Util.SetMaxUsers( 1, "PLANT.*" );
    Util.SetMaxUsers( 1, "BUILD.*" );
	Util.SetMaxUsers( 1, "CHECKPOINT.*" );
    Util.SetMaxUsers( 1, "DEFUSE.*" );

	//SetPriority
	SetGoalPriority( "PLANT_first_door", 0.95 );
	SetGoalPriority( "PLANT_second_door", 0.95 );
	SetGoalPriority( "PLANT_Fountain", 0.98 );
	SetGoalPriority( "BUILD_Allied_Command_Post", 0.95 );
	SetGoalPriority( "BUILD_Axis_Command_Post", 0.95 );
	SetGoalPriority( "CHECKPOINT.*", 0.95 );
    SetGoalPriority( "PLANT_Allied_Command_Post", 1.0, TEAM.AXIS, CLASS.COVERTOPS );
    SetGoalPriority( "PLANT_Axis_Command_Post", 1.0, TEAM.ALLIES, CLASS.COVERTOPS );

	// Camp times
	SetMapGoalProperties( "ATTACK.*", {MinCampTime=30, MaxCampTime=45});
	SetMapGoalProperties( "DEFEND.*", {MinCampTime=30, MaxCampTime=45});

    //Offset Plant Fix
	Util.SetGoalOffset( -60, 0, 0, "PLANT_Allied_Gold" );
    Util.SetGoalOffset( -50, 0, 0, "PLANT_Allied_Gold_1" );
    Util.SetGoalOffset( -60, 0, 0, "PLANT_Allied_Gold_2" );

    Wp.SetWaypointFlag( "first_door", "closed", true );
    Wp.SetWaypointFlag( "second_door", "closed", true );
    Wp.SetWaypointFlag( "teleport_S", "blockwall", true );

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

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 90.0;
};
