//==========================================================================================
//
//  Dingenskirchen (Beta 8)
//
//  Who             When                What
//------------------------------------------------------------------------------------------
//  Mateos          28 March 2020       Adapted from Beta 3 waypoints
//  Mateos          21 September 2019   Initial Script
//
//==========================================================================================

/****************************************************
Path mapping and script by Mateos
Correspondant WAY file size: -
Last update: 29th December 2020
****************************************************/

global Spawns =
{
    VILLAGE = 2,
    RIVER = 3,
};

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

    isCastleWolfensteinBreached = false,
    isConferenceRoomOpen = false,
    mapLoadingFlagForLever = true, // For Conference Room Door closing OnMapLoad

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

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

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

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

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

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

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

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

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

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

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

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

    suitcase_Secured = function( trigger )
    {
        SetAvailableMapGoals( TEAM.ALLIES, false, {
            "CAPPOINT_Suitcase_Bomb_Dropoff",
            "FLAG_suitcase",
        });
        SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Suitcase_Bomb" );

        Util.MapDebugPrint( "suitcase_Secured" );
    },

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

    river_flag_Allies_Captured = function( trigger )
    {
        if ( !Map.isCastleWolfensteinBreached )
        {
            // Move Allies to this spawn
            // TODO: Only during Tank escort phase and if the Tank is there...
            Util.ChangeSpawn( TEAM.ALLIES, Spawns.RIVER );
        }

        Util.MapDebugPrint( "river_flag_Allies_Captured" );
    },

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

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

    Tank_Passed_Barrier = function( trigger )
    {
        SetAvailableMapGoals( TEAM.AXIS, false, {
            "BUILD_Tank_Barrier",
            "DEFEND_Alpha.*",
        });
        SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Bravo.*" );

        SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Tank_Barrier" );

        Util.MapDebugPrint( "Tank_Passed_Barrier" );
    },

    Village_Secured = function( trigger )
    {
        // Move Allies to this spawn
        Util.ChangeSpawn( TEAM.ALLIES, Spawns.VILLAGE );

        SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Bravo.*" );
        SetAvailableMapGoals( TEAM.AXIS, true, {
            "DEFEND_Charlie.*",
            "DEFEND_Delta.*",
        });

        Util.MapDebugPrint( "Village_Secured" );
    },

    Tank_Passed_Tunnel_Doors = function( trigger )
    {
        // TODO: This starting when the Village is secured and River flag reachable
        // (either Water Pump built AND path clear (no water) OR Tunnel Doors destroyed)
        Util.EnableGoal( "CHECKPOINT_river_flag" );

        SetAvailableMapGoals( TEAM.AXIS, false, {
            "DEFEND_Charlie.*",
            "DEFEND_Delta.*",
        });
        SetAvailableMapGoals( TEAM.AXIS, true, {
            "DEFEND_Echo.*",
            "PLANT_Allied_Command_Post",
            "PLANT_Bridge",
        });

        SetAvailableMapGoals( TEAM.ALLIES, true, {
            "BUILD_Allied_Command_Post",
            "BUILD_Bridge",
        });

        Util.MapDebugPrint( "Tank_Passed_Tunnel_Doors" );
    },

    Tank_Across_Bridge = function( trigger )
    {
        SetAvailableMapGoals( TEAM.AXIS, false, {
            "DEFEND_Echo.*",
            "PLANT_Allied_Command_Post",
        });
        SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Foxtrot.*" );

        Util.MapDebugPrint( "Tank_Across_Bridge" );
    },

    Castle_Wolfenstein_Breached = function( trigger )
    {
        Map.isCastleWolfensteinBreached = true;

        SetAvailableMapGoals( TEAM.AXIS, false, {
            "DEFEND_Foxtrot.*",
            "PLANT_Bridge",
        });
        SetAvailableMapGoals( TEAM.AXIS, true, {
            "BUILD_Axis_Command_Post",
            "BUILD_Cellar_Door",
            "DEFEND_Golf.*",
            "PLANT_Axis_Command_Post",
            "PLANT_Castle_Stairs",
        });

        // Allies now spawn next to the Tank
        SetAvailableMapGoals( TEAM.ALLIES, false, {
            "BUILD_Bridge",
            "BUILD_Tank",
            "ESCORT_Tank",
            "MOUNT_Tank",
        });
        SetAvailableMapGoals( TEAM.ALLIES, true, {
            "BUILD_Castle_Stairs",
            "CAPPOINT_Suitcase_Bomb_Dropoff",
            "FLAG_suitcase",
            "PLANT_Cellar_Door",
            "SWITCH_Conference_Room",
        });

        Util.MapDebugPrint( "Castle_Wolfenstein_Breached" );
    },

    Conference_Room_Door_Lever_Dispatch = function( trigger )
    {
        if ( Map.mapLoadingFlagForLever )
        {
            Map.mapLoadingFlagForLever = false;
            return;
        }

        Map.isConferenceRoomOpen = !Map.isConferenceRoomOpen;

        SetAvailableMapGoals( TEAM.AXIS, Map.isConferenceRoomOpen, "SWITCH_Conference_Room" );
        SetAvailableMapGoals( TEAM.ALLIES, !Map.isConferenceRoomOpen, "SWITCH_Conference_Room" );

        Util.MapDebugPrint( "Conference_Room_Door_Lever_Dispatch" );
    },
};

global OnMapLoad = function()
{
    // Register callback functions
    //
    // Notes:
    // Extra-trigger by OB: Tunnel_Doors_Built
    //
    // Other wm_announce's, some to use:
    // Suitcase Bomb dropped!
    // ^5The Allies have armed the Suitcase Bomb!
    // ^5The Allies started arming the Suitcase Bomb!
    // ^5The Allies have destroyed the Side Wall!
    // ^1Axis Command Post constructed. Charge speed increased!
    // ^5The Allies have destroyed the Axis Command Post!
    // ^5The Allies have secured the Village and can now capture the River!
    // ^5The Tank has passed the Tank Barrier!
    // ^5The Tank has passed the Tunnel Doors!
    // ^5The Tank is across the Bridge!
    // ^5The Allies have breached Castle Wolfenstein!
    // ^5+10min Timelimit!
    // ^1The Tank has been damaged!
    OnTrigger( "^5Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
    OnTrigger( "^5The Allies have constructed the Bridge!", Map.Bridge_Built );
    OnTrigger( "^1The Axis have constructed the Cellar Door!", Map.Cellar_Door_Built );
    OnTrigger( "^5The Tank has been repaired!", Map.Tank_Built );
    OnTrigger( "^1Axis team has built the Barrier!", Map.Tank_Barrier_Built );
    OnTrigger( "^1The Axis have destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
    OnTrigger( "^1The Axis have destroyed the Bridge!", Map.Bridge_Destroyed );
    OnTrigger( "^5The Allies have destroyed the Cellar Door!", Map.Cellar_Door_Destroyed );
    OnTrigger( "^5Allied team has destroyed the Barrier!", Map.Tank_Barrier_Destroyed );
    OnTrigger( "^5The Allies have destroyed the Tunnel Doors!", Map.Tunnel_Doors_Destroyed );

    OnTrigger( "^5The Allies have picked up the Suitcase Bomb!", Map.suitcase_Taken );
    OnTrigger( "^1The Axis have returned the Suitcase Bomb!", Map.suitcase_Returned );
    OnTrigger( "Allies captured suitcase_tfm", Map.suitcase_Secured );

    OnTrigger( "^1The Axis have reclaimed the River!", Map.river_flag_Axis_Captured );
    OnTrigger( "^5The Allies have captured the River!", Map.river_flag_Allies_Captured );
    OnTrigger( "^1The Axis have reclaimed the Village!", Map.village_flag_Axis_Captured );
    OnTrigger( "^5The Allies have captured the Village!", Map.village_flag_Allies_Captured );

    // Tank progress triggers
    OnTrigger( "^5The Tank has passed the Tank Barrier!", Map.Tank_Passed_Barrier );
    OnTrigger( "^5The Allies have secured the Village and can now capture the River!", Map.Village_Secured );
    OnTrigger( "^5The Tank has passed the Tunnel Doors!", Map.Tank_Passed_Tunnel_Doors );
    OnTrigger( "^5The Tank is across the Bridge!", Map.Tank_Across_Bridge );
    OnTrigger( "^5The Allies have breached Castle Wolfenstein!", Map.Castle_Wolfenstein_Breached );

    OnTrigger( "cmd_door_lever_Moving", Map.Conference_Room_Door_Lever_Dispatch );

    // *** CLEAR ALL GOALS FOR BOTH TEAMS ***
    Util.DisableGoal( ".*", true ); // All but routes

    Util.EnableGoal( "CHECKPOINT_village_flag" );

    // *** AXIS GOALS ***
    SetAvailableMapGoals( TEAM.AXIS, true, {
        "BUILD_Tank_Barrier",
        "DEFEND_Alpha.*",
    });

    // *** ALLIED GOALS ***
    SetAvailableMapGoals( TEAM.ALLIES, true, {
        "BUILD_Tank",
        "ESCORT_Tank",
        "MOUNT_Tank",
        "PLANT_Tank_Barrier",
        "PLANT_Tunnel_Doors",
    });

    // Misc.
    Util.AddUsePoint( "PLANT_Tunnel_Doors", Vec3( -1230, 2360, 250 ) );

    Util.MapDebugPrint( "Omni-Bot 0.87+ map script for Dingenskirchen (Beta 8) executed." );
};

global OnBotJoin = function( bot )
{
    // For shootable breakables
    bot.TargetBreakableDist = 90.0;
};

global InitializeRoutes = function()
{
    MapRoutes =
    {
        CHECKPOINT_village_flag =
        {
        },
        BUILD_Tank_Barrier =
        {
        },
        PLANT_Tank_Barrier =
        {
        },
        BUILD_Tunnel_Doors =
        {
        },
        PLANT_Tunnel_Doors =
        {
        },
        BUILD_Allied_Command_Post =
        {
        },
        PLANT_Allied_Command_Post =
        {
        },
        CHECKPOINT_river_flag =
        {
        },
        BUILD_Bridge =
        {
        },
        PLANT_Bridge =
        {
        },
        BUILD_Cellar_Door =
        {
        },
        PLANT_Cellar_Door =
        {
        },
        BUILD_Tank =
        {
        },
        FLAG_suitcase =
        {
        },
    };
    Util.Routes(MapRoutes);
};
