//==========================================================================================
//
//  1944 Huertgen Forest Final - 1944_huertgen.gm
//
//  Who         When        What
//------------------------------------------------------------------------------------------
//  Mateos      04/12/10    Full script, based on the few things from
//                          jaskot's conversion
//
//  jaskot      02/03/09    Converted old script to new format (Very poor)
//
//==========================================================================================
//

/****************************************************
Pathing updated and script by Mateos
Correspondant WAY file size: 96,1 Ko (98 506 octets)
Last Update: 20th September 2014
****************************************************/

global Map =
{
    Debug = 0,              // Please set to zero before distributing your script
    CPStatus = 0,           // Not Built or Destroyed
    ATGStatus = 0,          // Not Destroyed
    TankStolen = 0,         // Not Stolen
    TruckGateStatus = 0,    // Not Destroyed
    TankNearTruckGate = 0,  // Truck has not reached the Truckyard Gate yet
    TruckAtAxisBunker = 0,  // Truck has not reached the Axis Bunker yet

    ShowMovers = true,
    Movers =
    {
        "MOVER_aagun_1_clip",
        "MOVER_allied_footbridge_debri",
        "MOVER_axis_ammo_room",
        "MOVER_axis_ammo_room_1",
        "MOVER_axis_bunker_wall",
        "MOVER_axispath1",
        "MOVER_axispath1_1",
        "MOVER_axispath1_2",
        "MOVER_bridge_bldg_door",
        "MOVER_neutral_compost_clip",
        "MOVER_neutral_compost_closed_clip",
        "MOVER_north_healthcabinet_clip",
        "MOVER_south_ammocabinet_clip",
        "MOVER_south_ammocabinet_clip_1",
        "MOVER_south_healthcabinet_clip",
        "MOVER_tankbay_commandpost_wires",
        "MOVER_tower",
        "MOVER_tower_base",
        "MOVER_truck_supplies",
        "MOVER_truckwall",
        "MOVER_truckwall_1",
        "MOVER_truckwall_2",
        "MOVER_truckwall_3",
    },

    Roles =
    {
        ALLIES = // Team
        {
            AllBots = false,    // Each bot is considered for a role
            ATTACKER =          // Make 1 or 2 Engis blow the Axis North Path, destroy the AT-Gun then Build CP
            {
                voice = "attack",               // Signals voice chat to randomly announce
                spawnpt = 1,                    // Users of this role will choose spawnpt 1 (Farm Spawn)
                numbots = 2,                    // Maximum of 2 bots
                crucialClass = CLASS.ENGINEER,  // First bot
            },
            ATTACKER1 =         // Make 1 Engi build the Foot Bridge
            {
                voice = "attack",               // Signals voice chat to randomly announce
                spawnpt = 1,                    // Users of this role will choose spawnpt 1 (Farm Spawn)
                numbots = 1,                    // Maximum of 1 bots
                crucialClass = CLASS.ENGINEER,  // First bot
            },
        },
    },

    Allied_Command_Post_Built = function( trigger )
    {
        Map.CPStatus = 2;   // Built by Allies

        Util.ChangeSpawnForRole( TEAM.ALLIES, ROLE.ATTACKER, 3 );

        if ( Map.TankStolen == 1 )
        {
            Util.ChangeSpawn(TEAM.ALLIES, 3);   // Command Post Spawn

            SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Command_Post" );
        }

        Util.MapDebugPrint( "Allied_Command_Post_Built" );
    },

    Allied_Command_Post_Destroyed = function( trigger )
    {
        Map.CPStatus = 0;   // Destroyed by Axis

        if ( Map.TankStolen == 1 )
        {
            Util.EnableGoal( "BUILD_Command_Post" );
        }

        Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
    },

    Axis_Command_Post_Built = function( trigger )
    {
        Map.CPStatus = 1;   // Built by Axis

        if ( Map.TankStolen == 1 )
        {
            Util.ChangeSpawn( TEAM.AXIS, 3 );   // Command Post Spawn

            SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );
        }

        Util.MapDebugPrint( "Axis_Command_Post_Built" );
    },

    Axis_Command_Post_Destroyed = function( trigger )
    {
        Map.CPStatus = 0;   // Destroyed by Allies

        if ( Map.TankStolen == 1 )
        {
            Util.EnableGoal( "BUILD_Command_Post" );
        }

        Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
    },

    Grate_Destroyed = function( trigger )
    {
        if ( Map.CPStatus < 2 )
        {
            SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Grate" );
        }

        // In any case...
        if ( Map.TruckAtAxisBunker == 0 )
        {
            SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Grate" );
        }

        Util.MapDebugPrint( "Grate_Destroyed" );
    },

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

    Tank_Stolen = function( trigger )
    {
        Map.TankStolen = 1; // Stolen by Allies

        if ( Map.CPStatus == 1 )
        {
            Util.ChangeSpawn( TEAM.AXIS, 3 );   // Command Post Spawn
        }

        SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Bravo.*" );
        SetAvailableMapGoals( TEAM.AXIS, false, {
        	"DEFEND_Alpha.*",
        	"PLANT_footbridge",
        });

        SetAvailableMapGoals( TEAM.ALLIES, true, {
        	"PLANT_Grate",
        	"ATTACK_Bravo.*",
        });
        SetAvailableMapGoals (TEAM.ALLIES, true, "BUILD_Command_Post" );
        SetAvailableMapGoals( TEAM.ALLIES, false, {
        	"SNIPE_Alpha.*",
        	"ATTACK_Alpha.*",
        });
        SetAvailableMapGoals (TEAM.ALLIES, false, {
        	"BUILD_footbridge",
        	"GRENADE_Axis_North_Path",
        	"GRENADE_Axis_North_Path2",
        });

        Util.MapDebugPrint( "Tank_Stolen" );
    },

    TankPastFirstHouse = function( trigger )
    {
        if ( Map.CPStatus == 1 )
        {
            Util.ChangeSpawn( TEAM.AXIS, 3 );   // Command Post Spawn
        }

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

        Util.MapDebugPrint( "TankPastFirstHouse" );
    },

    TankNearTruckGate = function( trigger )
    {
        Map.TankNearTruckGate = 1;

        if ( Map.CPStatus == 1 )
        {
            Util.ChangeSpawn( TEAM.AXIS, 3 );   // Command Post Spawn
        }

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

        if ( Map.CPStatus == 2 )
        {
            Util.ChangeSpawn( TEAM.ALLIES, 3 ); // Command Post Spawn
        }
        SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Grate" );

        Util.MapDebugPrint( "TankNearTruckGate" );
    },

    Truck_Gate_Destroyed = function( trigger )
    {
        Map.TruckGateStatus = 1;

        SetAvailableMapGoals( TEAM.AXIS, true, {
        	"BUILD_tower",
        	"MOUNTMG42_tower",
        });

        SetAvailableMapGoals( TEAM.ALLIES, true, {
        	"ESCORT_Truck",
        	"ATTACK_Charlie.*",
        });
        SetAvailableMapGoals( TEAM.ALLIES, false, {
        	"BUILD_Tank",
        	"MOUNT_Tank",
        	"ESCORT_Tank",
        	"ATTACK_Bravo1",
        	"ATTACK_Bravo2",
        	"ATTACK_Bravo3",
        });

        Util.MapDebugPrint( "Truck_Gate_Destroyed" );
    },

    Truck_at_Bridge = function( trigger )
    {
        Util.ChangeSpawn( TEAM.AXIS, 2 );
        SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Echo.*" );
        SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Delta.*" );

        SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Delta.*" );
        SetAvailableMapGoals( TEAM.ALLIES, false, {
        	"ATTACK_Bravo4",
        	"ATTACK_Charlie.*",
        });

        Util.MapDebugPrint( "Truck_at_Bridge" );
    },

    Truck_at_Axis_Bunker = function( trigger )
    {
        Map.TruckAtAxisBunker = 1;

//      Util.ChangeSpawnForRole( TEAM.ALLIES, ROLE.ATTACKER, 1);
//      SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Echo.*" );
        SetAvailableMapGoals( TEAM.ALLIES, true, "GRENADE_Axis_Ammo_Room" );
//      SetAvailableMapGoals( TEAM.ALLIES, true, "GRENADE_Axis_North_Path.*" );

        Util.MapDebugPrint( "Truck_at_Axis_Bunker" );
    },

    Tank_Destroyed = function( trigger )
    {
        // Repair the Tank only if the Truck Gate has not been destroyed
        if ( Map.TruckGateStatus == 0 )
        {
            SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank" );
        }

        Util.MapDebugPrint( "Tank_Destroyed" );
    },

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

    Truck_Destroyed = function( trigger )
    {
        SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Truck" );

        Util.MapDebugPrint( "Truck_Destroyed" );
    },

    footbridge_Built = function( trigger )
    {
        if ( Map.TankStolen == 0 )
        {
            SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_footbridge" );
        }

        Util.MapDebugPrint( "footbridge_Built" );
    },

    footbridge_Destroyed = function( trigger )
    {
        SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_footbridge" );

        if ( Map.TankStolen == 0 )
        {
            SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_footbridge" );
        }

        Util.MapDebugPrint( "footbridge_Destroyed" );
    },

    tower_Built = function( trigger )
    {
        if ( Map.TankNearTruckGate == 1 )
        {
            SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_tower" );
        }

        Util.MapDebugPrint( "tower_Built" );
    },

    tower_Destroyed = function( trigger )
    {
        if ( Map.TruckGateStatus == 1 )
        {
            SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_tower" );
        }

        Util.MapDebugPrint( "tower_Destroyed" );
    },

    Anti_Tank_Gun_Destroyed = function( trigger )
    {
        Map.ATGStatus = 1;  // Destroyed

        SetAvailableMapGoals( TEAM.ALLIES, true, {
        	"BUILD_Command_Post",
        	"PLANT_Command_Post",
        });
        SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATG_Defense" );

        Util.MapDebugPrint( "Anti_Tank_Gun_Destroyed" );
    },

    Axis_Ammo_Bunker_Destroyed = function( trigger )
    {
        SetAvailableMapGoals( TEAM.ALLIES, false, "GRENADE_Axis_Ammo_Room" );

        Util.MapDebugPrint( "Axis_Ammo_Bunker_Destroyed" );
    },

    Axis_North_Path_Built = function( trigger )
    {
        SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATG_Defense" );

        if ( Map.TankStolen == 0 )
        {
            SetAvailableMapGoals( TEAM.ALLIES, true, "GRENADE_Axis_North_Path" );
            SetAvailableMapGoals (TEAM.ALLIES, true, "GRENADE_Axis_North_Path2" );
        }

        if ( Map.CPStatus == 2 )
        {
            SetAvailableMapGoals( TEAM.ALLIES, false, "GRENADE_Axis_North_Path" );
            SetAvailableMapGoals (TEAM.ALLIES, false, "GRENADE_Axis_North_Path2" );
        }

//      if ( Map.TruckAtAxisBunker == 1 )
//      {
//          SetAvailableMapGoals( TEAM.ALLIES, true, "GRENADE_Axis_North_Path" );
//          SetAvailableMapGoals (TEAM.ALLIES, true, "GRENADE_Axis_North_Path2" );
//          SetAvailableMapGoals( TEAM.ALLIES, false, "ATTACK_Echo.*" );
//      }

        Util.MapDebugPrint( "Axis_North_Path_Built" );
    },

    Axis_North_Path_Destroyed = function( trigger )
    {
        SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_North_Path" );

        SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Anti_Tank_Gun" );
        SetAvailableMapGoals( TEAM.ALLIES, false, {
        	"GRENADE_Axis_North_Path",
        	"GRENADE_Axis_North_Path2",
        });

        if ( Map.TankStolen == 0 && Map.ATGStatus == 0 )
        {
            SetAvailableMapGoals( TEAM.ALLIES, true, "CAMP_ATG_Defense" );
        }

//      if ( Map.TruckAtAxisBunker == 1 )
//      {
//          SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_Echo.*" );
//      }

        Util.MapDebugPrint( "Axis_North_Path_Destroyed" );
    },

    vehicle_at_location = function( trigger )
    {
        switch(Map.VehicleLocation)
        {
            case 1:
            {
                Map.Truck_at_Bridge();      // Truck at Bridge
            }
            case 2:
            {
                // Truck exits Case 1
            }
            case 3:
            {
                Map.Truck_at_Axis_Bunker(); // Truck at Axis Bunker
            }
        }

        Util.MapDebugPrint( "vehicle at location " + Map.VehicleLocation, true );
    },
};

global OnMapLoad = function()
{
    // *** TRIGGERS ***
    // The announcements are trimmed to 71 chars, the maximum supported by Omni-Bot.
    OnTrigger( "Allied Command Post constructed. Charge speed increased!, Allies Contro", 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!, Axis Control th", Map.Axis_Command_Post_Built );
    OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
    OnTrigger( "the Grate has been destroyed.", Map.Grate_Destroyed );
    OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
    OnTrigger( "Allied team has stolen the Tank!", Map.Tank_Stolen );
    OnTrigger( "The Tank has been damaged!", Map.Tank_Destroyed );
    OnTrigger( "The Truck has been repaired!", Map.Truck_Built );
    OnTrigger( "The Truck has been damaged!", Map.Truck_Destroyed );
    OnTrigger( "the Allied Footbridge has been constructed.", Map.footbridge_Built );
    OnTrigger( "the Allied Footbridge has been destroyed.", Map.footbridge_Destroyed );
    OnTrigger( "the Axis tower has been constructed.", Map.tower_Built );
    OnTrigger( "the Axis Tower has been destroyed.", Map.tower_Destroyed );

    OnTrigger( "1944_huertgen_allies_truck_steal", Map.Truck_Gate_Destroyed );
    OnTrigger( "Allies have destroyed the Anti Tank Gun!", Map.Anti_Tank_Gun_Destroyed );
    OnTrigger( "the Axis Ammo Bunker has been destroyed, Axis Bunker Spawn disabled.", Map.Axis_Ammo_Bunker_Destroyed );

    OnTrigger( "the Axis North Path has been blockaded.", Map.Axis_North_Path_Built );
    OnTrigger( "the Allies have cleared the Axis North Path.", Map.Axis_North_Path_Destroyed );

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

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

    // *** ALLIED GOALS ***
    SetAvailableMapGoals( TEAM.ALLIES, true, {
    	"BUILD_Tank",
    	"MOUNT_Tank",
    	"ESCORT_Tank",
    	"SNIPE_Alpha.*",
    	"ATTACK_Alpha.*",
    	"BUILD_footbridge",
    	"GRENADE_Axis_North_Path",
    	"GRENADE_Axis_North_Path2",
    });

    // To avoid the bot alone not kwowing what to do...
    if ( Server.Team[ TEAM.ALLIES ].numBots >= 6 )
    {
        Util.SetRoleForGoals( "ATTACK_Echo.*", ROLE.ATTACKER );
        Util.SetRoleForGoals( "CAMP_ATG_Defense", ROLE.ATTACKER );
        Util.SetRoleForGoals( "PLANT_Anti_Tank_Gun", ROLE.ATTACKER );
        Util.SetRoleForGoals( "GRENADE_Axis_Ammo_Room", ROLE.ATTACKER );
        Util.SetRoleForGoals( "GRENADE_Axis_North_Path", ROLE.ATTACKER );
        Util.SetRoleForGoals( "GRENADE_Axis_North_Path2", ROLE.ATTACKER );

        Util.SetRoleForGoals( "BUILD_footbridge", ROLE.ATTACKER1 );
    }

    // *** GOALS PROPERTIES ***
    Util.SetMaxUsers( 1, ".*" );
    Util.SetMaxUsers( 2, "GRENADE_.*" );
    Util.ExcludeClass( "MOUNTMG42_.*", CLASS.MEDIC, CLASS.ENGINEER );
    SetMapGoalProperties( "ATTACK_.*", { mincamptime = 60, maxcamptime = 120 } );
    SetMapGoalProperties( "DEFEND_.*", { mincamptime = 60, maxcamptime = 120 } );

    Util.SetGoalPosition( -955, 310, 145,       "PLANT_tower" );
    Util.SetGoalPosition( -1375, -3300, 110,    "PLANT_Grate" );
    Util.SetGoalPosition( 3700, 700, 0,         "PLANT_footbridge" );
    Util.SetGoalPosition( -2430, 1555, 520,     "PLANT_Anti_Tank_Gun" );
    Util.SetGoalPosition( -3960, -2000, -10,    "PLANT_Command_Post" );

    Util.OnTriggerPosition( "MOVER_tank", "region1", 200.0, Map.TankPastFirstHouse );
    Util.OnTriggerPosition( "MOVER_tank", "region2", 200.0, Map.TankNearTruckGate );

    // *** VEHICLE TRIGGERS ***
    OnTrigger( "tank at location", Map.vehicle_at_location );
    OnTrigger( "truck at location", Map.vehicle_at_location );

    OnTriggerRegion(AABB(-1664.875,-1051.546,105.125,-1407.125,-884.309,179.125),    RegionTrigger.VehicleTrigger);
    OnTriggerRegion(AABB(-1656.225,400.432,105.125,-1409.084,663.498,179.125),       RegionTrigger.VehicleTrigger);

    Util.FixMoverPos("truck", Vec3(-2889.000, -4430.500, 164.500), Vec3(-2888.000, -4576.000, 108.000));

    Util.MapDebugPrint( "Omni-bot 0.8x map script for 1944 Huertgen Forest Final by Mateos" );
};

global OnBotJoin = function( bot )
{
    if ( Map.TankStolen == 1 && Map.CPStatus == 1 )
    {
        Util.ChangeSpawn(TEAM.AXIS, 3);     // Command Post Spawn
    }

    // Make bots stop shooting the Movers like targets
    Util.IgnoreTargetGoalTable(bot, Map.Movers);

    // Recurent Mover targets shooted
    bot.IgnoreTarget( GetGoal("MOVER_tower_base").GetEntity(), 9999 );
    bot.IgnoreTarget( GetGoal("MOVER_aagun_1_clip").GetEntity(), 9999 );
    bot.IgnoreTarget( GetGoal("MOVER_bridge_bldg_door").GetEntity(), 9999 );
};

global InitializeRoutes = function()
{
    MapRoutes =
    {
        PLANT_Command_Post =
        {
            ROUTE_Axis_Bunker_Spawn  =
            {
                ROUTE_Axis_CP_Route1  =
                {
                    ROUTE_Axis_CP_Route2  =
                    {
                        ROUTE_Axis_CP_Route3  =
                        {
                            ROUTE_Axis_CP  = {},
                        },
                    },
                },
            },
        },
    };

    Util.Routes(MapRoutes);
};
