// IW6 GSC SOURCE
// Generated by https://github.com/xensik/gsc-tool

main()
{
    maps\mp\mp_ca_rumble_precache::main();
    maps\createart\mp_ca_rumble_art::main();
    maps\mp\mp_ca_rumble_fx::main();
    level thread update_mortars();
    level.air_raid_active = 0;
    level.mapcustomcratefunc = ::rumblecustomcratefunc;
    level.mapcustomkillstreakfunc = ::rumblecustomkillstreakfunc;
    level.mapcustombotkillstreakfunc = ::rumblecustombotkillstreakfunc;
    maps\mp\_load::main();
    maps\mp\_compass::setupminimap( "compass_map_mp_ca_rumble" );
    setdvar( "r_lightGridEnableTweaks", 1 );
    setdvar( "r_lightGridIntensity", 1.33 );

    if ( level.ps3 )
    {
        setdvar( "sm_sunShadowScale", "0.55" );
        setdvar( "sm_sunsamplesizenear", ".15" );
    }
    else if ( level.xenon )
    {
        setdvar( "sm_sunShadowScale", "0.56" );
        setdvar( "sm_sunsamplesizenear", ".22" );
    }
    else
    {
        setdvar( "sm_sunShadowScale", "0.9" );
        setdvar( "sm_sunsamplesizenear", ".27" );
    }

    maps\mp\_utility::setdvar_cg_ng( "r_specularColorScale", 1.7, 5 );
    game["attackers"] = "allies";
    game["defenders"] = "axis";
    game["allies_outfit"] = "urban";
    game["axis_outfit"] = "woodland";
    fixmlgcameraposition();
    thread setup_fish();
    thread setup_destructibles();
    thread setup_metal_detectors();
    thread setup_watertanks();
    thread setup_bouys();
    thread setup_dock_boats();
    thread setup_monitors();
    thread update_destroyer();
    thread update_trolley();
    thread update_lighthouse_light();
    thread setup_fountain_fx();
    thread update_artillery_fx();
    thread update_heli_fx();
    thread update_flybyjet_fx();
    thread maps\mp\_dlcalienegg::setupeggformap( "alienEasterEgg" );
    level thread initextracollision();
}

initextracollision()
{
    var_0 = getent( "clip128x128x256", "targetname" );
    var_1 = spawn( "script_model", ( -459.25, 1848, 487.75 ) );
    var_1.angles = ( 270, 322.793, 37.2067 );
    var_1 clonebrushmodeltoscriptmodel( var_0 );
    var_2 = getent( "clip256x256x128", "targetname" );
    var_3 = spawn( "script_model", ( -1984, 344, -120 ) );
    var_3.angles = ( 0, 0, 0 );
    var_3 clonebrushmodeltoscriptmodel( var_2 );
}

rumblecustomcratefunc()
{
    if ( !isdefined( game["player_holding_level_killstrek"] ) )
        game["player_holding_level_killstrek"] = 0;

    if ( !maps\mp\_utility::allowlevelkillstreaks() || game["player_holding_level_killstrek"] )
        return;

    maps\mp\killstreaks\_airdrop::addcratetype( "airdrop_assault", "warhawk_mortars", 85, maps\mp\killstreaks\_airdrop::killstreakcratethink, maps\mp\killstreaks\_airdrop::get_friendly_crate_model(), maps\mp\killstreaks\_airdrop::get_enemy_crate_model(), &"KILLSTREAKS_HINTS_WARHAWK_MORTARS" );
    level thread watch_for_rumble_mortars_crate();
}

watch_for_rumble_mortars_crate()
{
    for (;;)
    {
        level waittill( "createAirDropCrate", var_0 );

        if ( isdefined( var_0 ) && isdefined( var_0.cratetype ) && var_0.cratetype == "warhawk_mortars" )
        {
            maps\mp\killstreaks\_airdrop::changecrateweight( "airdrop_assault", "warhawk_mortars", 0 );
            var_1 = wait_for_capture( var_0 );

            if ( !var_1 )
            {
                maps\mp\killstreaks\_airdrop::changecrateweight( "airdrop_assault", "warhawk_mortars", 85 );
                continue;
            }

            game["player_holding_level_killstrek"] = 1;
            break;
        }
    }
}

wait_for_capture( var_0 )
{
    var_1 = watch_for_air_drop_death( var_0 );
    return !isdefined( var_1 );
}

watch_for_air_drop_death( var_0 )
{
    var_0 endon( "captured" );
    var_0 waittill( "death" );
    waittillframeend;
    return 1;
}

rumblecustomkillstreakfunc()
{
    level.killstreakfuncs["warhawk_mortars"] = ::tryuserumblemortars;
    level.killstreakweildweapons["warhawk_mortar_mp"] = "warhawk_mortars";
}

rumblecustombotkillstreakfunc()
{
    maps\mp\bots\_bots_ks::bot_register_killstreak_func( "warhawk_mortars", maps\mp\bots\_bots_ks::bot_killstreak_simple_use );
}

tryuserumblemortars( var_0, var_1 )
{
    if ( level.air_raid_active )
    {
        self iprintlnbold( &"KILLSTREAKS_AIR_SPACE_TOO_CROWDED" );
        return 0;
    }

    game["player_holding_level_killstrek"] = 0;
    level notify( "rumble_mortar_killstreak", self );
    return 1;
}

mortars_activate_at_end_of_match()
{
    level endon( "rumble_mortar_killstreak" );
    level waittill( "spawning_intermission" );
    level.ending_flourish = 1;
    mortar_fire( 0.1, 0.3, 6, level.players[0] );
}

update_mortars()
{
    level endon( "stop_dynamic_events" );
    common_scripts\utility::waitframe();
    level.mortar_sources = common_scripts\utility::getstructarray( "rumble_mortar_source", "targetname" );

    foreach ( var_1 in level.mortar_sources )
    {
        if ( !isdefined( var_1.radius ) )
            var_1.radius = 300;
    }

    level.mortar_targets = common_scripts\utility::getstructarray( "rumble_mortar_target", "targetname" );

    foreach ( var_4 in level.mortar_targets )
    {
        if ( !isdefined( var_4.radius ) )
            var_4.radius = 100;
    }

    for (;;)
    {
        level.air_raid_active = 0;
        level.air_raid_team_called = "none";
        thread mortars_activate_at_end_of_match();
        level waittill( "rumble_mortar_killstreak", var_6 );
        level.air_raid_active = 1;
        level.air_raid_team_called = var_6.team;
        thread mortar_siren( 10 );
        wait 3;
        mortar_fire( 0.5, 0.6, 25, var_6 );
    }
}

mortar_siren( var_0 )
{
    if ( !isdefined( level.mortar_siren_ent ) )
        level.mortar_siren_ent = getent( "mortar_siren", "targetname" );

    if ( isdefined( level.mortar_siren_ent ) )
        level.mortar_siren_ent playsound( "mortar_siren" );

    wait( var_0 );

    if ( isdefined( level.mortar_siren_ent ) )
        level.mortar_siren_ent stopsounds();
}

mortar_fire( var_0, var_1, var_2, var_3 )
{
    var_4 = gettime() + var_2 * 1000;
    var_5 = random_mortars_get_source_structs( level.air_raid_team_called );

    if ( var_5.size <= 0 )
        return;

    var_6 = 0;

    while ( var_4 > gettime() )
    {
        var_7 = 12;
        var_8 = 0;

        foreach ( var_10 in level.players )
        {
            if ( !maps\mp\_utility::isreallyalive( var_10 ) )
                continue;

            if ( level.teambased )
            {
                if ( var_10.team == level.air_raid_team_called )
                    continue;
            }
            else if ( isdefined( var_3 ) && var_10 == var_3 )
                continue;

            if ( var_10.spawntime + 8000 > gettime() )
                continue;

            var_11 = var_10 getvelocity();
            var_12 = randomfloatrange( 3, 4 );
            var_13 = var_10.origin + var_11 * var_12;
            var_14 = getnodesinradiussorted( var_13, 100, 0, 60 );

            foreach ( var_16 in var_14 )
            {
                if ( nodeexposedtosky( var_16 ) )
                {
                    var_17 = common_scripts\utility::random( var_5 );

                    if ( random_mortars_fire( var_17.origin, var_16.origin, undefined, var_3, 1, 1 ) )
                    {
                        wait( randomfloatrange( var_0, var_1 ) );
                        var_8++;
                        break;
                    }
                }
            }
        }

        if ( level.mortar_targets.size > 0 )
        {
            for ( var_5 = common_scripts\utility::array_randomize( var_5 ); var_8 < var_7; var_8++ )
            {
                var_17 = var_5[var_6];
                var_6++;

                if ( var_6 >= var_5.size )
                    var_6 = 0;

                var_20 = common_scripts\utility::random( level.mortar_targets );
                var_21 = random_point_in_circle( var_17.origin, var_17.radius );
                var_22 = random_point_in_circle( var_20.origin, var_20.radius );
                thread random_mortars_fire( var_21, var_22, undefined, var_3, 0, 1 );
                wait( randomfloatrange( var_0, var_1 ) );
            }

            continue;
        }

        break;
    }
}

random_point_in_circle( var_0, var_1 )
{
    if ( var_1 > 0 )
    {
        var_2 = anglestoforward( ( 0, randomfloatrange( 0, 360 ), 0 ) );
        var_3 = randomfloatrange( 0, var_1 );
        var_0 = var_0 + var_2 * var_3;
    }

    return var_0;
}

random_mortars_fire( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    playsoundatpos( var_0, "mortar_launch" );
    var_6 = ( 0, 0, -800 );

    if ( !isdefined( var_2 ) )
    {
        if ( isdefined( level.ending_flourish ) && level.ending_flourish )
            var_2 = 2.5;
        else
            var_2 = randomfloatrange( 10.0, 12.0 );
    }

    var_7 = trajectorycalculateinitialvelocity( var_0, var_1, var_6, var_2 );

    if ( isdefined( var_4 ) && var_4 )
    {
        var_8 = trajectorycomputedeltaheightattime( var_7[2], -1 * var_6[2], var_2 / 2 );
        var_9 = ( var_1 - var_0 ) / 2 + var_0 + ( 0, 0, var_8 );

        if ( bullettracepassed( var_9, var_1, 0, undefined ) )
        {
            thread random_mortars_fire_run( var_0, var_1, var_2, var_3, var_7, var_5 );
            return 1;
        }
        else
            return 0;
    }

    random_mortars_fire_run( var_0, var_1, var_2, var_3, var_7, var_5 );
}

random_mortars_fire_run( var_0, var_1, var_2, var_3, var_4, var_5 )
{
    var_6 = 350;
    var_7 = random_mortars_get_model( var_0 );
    var_7.origin = var_0;
    var_7.in_use = 1;
    common_scripts\utility::waitframe();
    playfxontag( common_scripts\utility::getfx( "random_mortars_trail" ), var_7, "tag_fx" );
    var_7.angles = vectortoangles( var_4 ) * ( -1, 1, 1 );
    maps\mp\_utility::delaythread( var_2 - 2.0, ::random_mortars_incoming_sound, var_1 );
    var_7 movegravity( var_4, var_2 - 0.05 );
    var_7 waittill( "movedone" );

    if ( level.createfx_enabled && !isdefined( level.players ) )
        level.players = [];

    if ( isdefined( var_3 ) )
        var_7 radiusdamage( var_1, 250, 750, 500, var_3, "MOD_EXPLOSIVE", "warhawk_mortar_mp" );
    else
        var_7 radiusdamage( var_1, 140, 5, 5, undefined, "MOD_EXPLOSIVE", "warhawk_mortar_mp" );

    playrumbleonposition( "artillery_rumble", var_1 );
    var_8 = var_6 * var_6;

    foreach ( var_10 in level.players )
    {
        if ( var_10 maps\mp\_utility::isusingremote() )
            continue;

        if ( distancesquared( var_1, var_10.origin ) > var_8 )
            continue;

        if ( var_10 damageconetrace( var_1 ) )
            var_10 thread maps\mp\gametypes\_shellshock::dirteffect( var_1 );
    }

    if ( var_5 )
        playfx( common_scripts\utility::getfx( "mortar_impact_00" ), var_1 );

    var_7 delete();
}

random_mortars_incoming_sound( var_0 )
{
    playsoundatpos( var_0, "mortar_incoming" );
}

random_mortars_get_model( var_0 )
{
    var_1 = spawn( "script_model", var_0 );
    var_1 setmodel( "projectile_rpg7" );
    return var_1;
}

random_mortars_get_source_structs( var_0 )
{
    var_1 = [];

    if ( level.teambased )
    {
        foreach ( var_3 in level.mortar_sources )
        {
            if ( isdefined( var_3.script_team ) && var_3.script_team == var_0 )
                var_1[var_1.size] = var_3;
        }
    }

    if ( var_1.size == 0 )
        var_1 = level.mortar_sources;

    return var_1;
}

setup_destructibles()
{
    var_0 = getentarray( "dest_orca", "targetname" );
    var_1 = getentarray( "dest_shark", "targetname" );

    if ( var_1.size )
    {
        foreach ( var_3 in var_1 )
            var_3 thread update_destructibles( level._effect["vfx_mp_ca_rumble_shark_hit"], level._effect["vfx_mp_ca_rumble_shark_death"] );
    }

    if ( var_0.size )
    {
        foreach ( var_6 in var_0 )
            var_6 thread update_destructibles( level._effect["vfx_mp_ca_rumble_orca_hit"], level._effect["vfx_mp_ca_rumble_orca_death"] );
    }
}

update_destructibles( var_0, var_1 )
{
    self show();
    self setcandamage( 1 );
    var_2 = undefined;
    var_3 = randomintrange( 2, 4 );

    while ( var_3 > 0 )
    {
        self waittill( "damage", var_4, var_5, var_6, var_7, var_8 );
        var_3--;
        var_2 = var_6;
        thread play_hit( var_0, var_7, var_6 );

        if ( issubstr( var_8, "MELEE" ) || issubstr( var_8, "GRENADE" ) )
        {
            var_3 = 0;
            continue;
        }

        if ( issubstr( var_8, "BULLET" ) )
        {
            if ( var_4 > 60.0 )
            {
                var_3 = 0;
                continue;
            }

            if ( isdefined( var_5 ) && isdefined( var_5 getcurrentweapon() ) && weaponclass( var_5 getcurrentweapon() ) == "sniper" )
                var_3 = 0;
        }
    }

    if ( !isdefined( var_2 ) )
        self waittill( "damage", var_4, var_5, var_6, var_7, var_8 );
    else
        var_6 = var_2;

    self hide();
    self setcandamage( 0 );
    thread play_hit( var_1, self getorigin(), var_6 );
}

play_hit( var_0, var_1, var_2 )
{
    var_3 = spawnfx( var_0, var_1, anglestoforward( var_2 ), anglestoup( var_2 ) );
    triggerfx( var_3 );
    wait 5.0;
    var_3 delete();
}

setup_fish()
{
    var_0 = getent( "bannerfish", "targetname" );

    if ( isdefined( var_0 ) )
        var_0 thread update_fish();
}

#using_animtree("mp_ca_rumble_animtree");

update_fish()
{
    for (;;)
    {
        var_0 = randomint( 3 );
        self scriptmodelclearanim();

        if ( var_0 == 0 )
        {
            self scriptmodelplayanim( "mp_ca_rumble_fish_swim_anim" );
            wait( getanimlength( %mp_ca_rumble_fish_swim_anim ) );
            continue;
        }

        if ( var_0 == 1 )
        {
            self scriptmodelplayanim( "mp_ca_rumble_fish_swim_anim_b" );
            wait( getanimlength( %mp_ca_rumble_fish_swim_anim_b ) );
            continue;
        }

        self scriptmodelplayanim( "mp_ca_rumble_fish_swim_anim_c" );
        wait( getanimlength( %mp_ca_rumble_fish_swim_anim_c ) );
    }
}

setup_metal_detectors()
{
    var_0 = getentarray( "metal_detector_trigger", "targetname" );

    if ( var_0.size > 0 )
        common_scripts\utility::array_thread( var_0, ::update_metal_detector );
}

update_metal_detector()
{
    self endon( "detector_destroyed" );
    var_0 = [];
    var_1 = getentarray( "metal_detector_device", "targetname" );

    foreach ( var_3 in var_1 )
    {
        if ( distancesquared( var_3.origin, self.origin ) < 10000.0 )
        {
            var_3.md_health = 100.0;
            var_3.light_on = getent( var_3.target, "targetname" );
            var_3.light_off = getent( var_3.light_on.target, "targetname" );
            var_3.light_broke = getent( var_3.light_off.target, "targetname" );
            var_3 thread metal_detector_damage_monitor( self );
            var_0 = common_scripts\utility::array_add( var_0, var_3 );
        }
    }

    thread metal_detector_monitor_alive( var_0 );

    for (;;)
    {
        foreach ( var_3 in var_0 )
            var_3 thread metal_detector_on();

        self waittill( "trigger" );

        foreach ( var_3 in var_0 )
            var_3 thread metal_detector_off();

        wait 5.0;
    }
}

metal_detector_monitor_alive( var_0 )
{
    self waittill( "detector_damaged" );

    foreach ( var_2 in var_0 )
        var_2 dodamage( 10000, var_2.origin );

    self notify( "detector_destroyed" );
}

metal_detector_damage_monitor( var_0 )
{
    self.light_on thread metal_detectorpart_damage_monitor( self );
    self.light_off thread metal_detectorpart_damage_monitor( self );
    self setcandamage( 1 );

    while ( self.md_health > 0.0 )
    {
        self waittill( "damage", var_1, var_2, var_3, var_4, var_5 );

        if ( isplayer( var_2 ) )
            self.maintain_fx = 1;

        self.md_health = self.md_health - var_1;
    }

    thread metal_detector_broke( var_0 );
}

metal_detectorpart_damage_monitor( var_0 )
{
    var_0 endon( "detector_destroyed" );
    self setcandamage( 1 );

    for (;;)
    {
        self waittill( "damage", var_1, var_2, var_3, var_4, var_5 );
        var_0 dodamage( 10000, var_0.origin );
    }
}

metal_detector_on()
{
    if ( self.md_health <= 0.0 )
        return;

    self.light_on show();
    self.light_off hide();
    self.light_broke hide();
    self playsound( "metaldetector_reset" );
}

metal_detector_off()
{
    if ( self.md_health <= 0.0 )
        return;

    self.light_on hide();
    self.light_off show();
    self.light_broke hide();
    self playsound( "metaldetector_alarm" );
}

metal_detector_broke( var_0 )
{
    var_0 notify( "detector_damaged" );
    self.light_on hide();
    self.light_off hide();
    self.light_broke show();

    if ( isdefined( self.maintain_fx ) && self.maintain_fx == 1 )
    {
        for (;;)
        {
            self.light_broke playsound( "metaldetector_sparks" );
            playfx( level._effect["vfx_metaldetector_explosion"], self.light_broke.origin + ( 0, 0, 7.5 ) );
            wait( randomfloatrange( 45.0, 150.0 ) );
        }
    }
}

setup_bouys()
{
    var_0 = getentarray( "harbor_bouy", "targetname" );

    if ( var_0.size <= 0 )
        return;

    common_scripts\utility::array_thread( var_0, ::update_bouy );
}

update_bouy()
{
    var_0 = self.origin;
    var_1 = self.angles;
    var_2 = 225.0;

    for (;;)
    {
        var_3 = ( 10, 10, 0 ) + common_scripts\utility::randomvector( 10.0 );
        var_3 = var_3 * ( 3, 3, 2 );
        var_4 = var_0 + var_3;
        var_5 = max( 3.0, distancesquared( self.origin, var_4 ) / var_2 );
        self rotateto( vectortoangles( var_4 - var_0 ), var_5, 1.5, 1.5 );
        self moveto( var_4, var_5, 1.5, 1.5 );
        wait( var_5 );
    }
}

setup_dock_boats()
{
    var_0 = getentarray( "dock_boats", "targetname" );

    if ( var_0.size <= 0 )
        return;

    common_scripts\utility::array_thread( var_0, ::update_dock_boat );
}

update_dock_boat()
{
    var_0 = self.angles;
    var_1 = 1;
    var_2 = 1.5;

    for (;;)
    {
        var_3 = ( 0.0, 0.0, randomfloatrange( 6.0, 8.0 ) );
        var_4 = max( 2.0, var_3[2] / var_2 );

        if ( var_1 )
            var_3 = var_3 * -1.0;

        var_1 = !var_1;
        self rotateto( var_0 + var_3, var_4, 1.0, 1.0 );
        wait( var_4 );
    }
}

setup_monitors()
{
    var_0 = getentarray( "rumble_monitor", "targetname" );

    if ( var_0.size <= 0 )
        return;

    common_scripts\utility::array_thread( var_0, ::update_monitor );
}

update_monitor()
{
    var_0 = getent( self.target, "targetname" );

    if ( !isdefined( var_0 ) )
        return;

    self show();
    self setcandamage( 1 );
    var_0 hide();
    self waittill( "damage" );
    self hide();
    var_0 show();
    var_0 playsound( "flatscreen_sparks" );
    playfx( level._effect["vfx_flatscreen_explosion"], var_0.origin );
}

setup_watertanks()
{
    level.tank_hitfx_throttle = 600;
    level.tank_hitfx_throttle_max = 1200;
    level.next_tank_hitfx_time = -1.0;
    var_0 = getentarray( "watertank_glass", "targetname" );

    if ( var_0.size > 0 )
    {
        for ( var_1 = 0; var_1 < var_0.size; var_1++ )
            var_0[var_1] thread update_watertank( var_1 );
    }

    var_0 = getentarray( "watertank_invulnerable", "targetname" );
    common_scripts\utility::array_thread( var_0, ::update_watertank_invulnerable );
}

update_watertank( var_0 )
{
    var_1 = getent( self.target, "targetname" );

    if ( !isdefined( var_1 ) )
        return;

    var_2 = getent( var_1.target, "targetname" );

    if ( !isdefined( var_2 ) )
        return;

    var_3 = getent( var_2.target, "targetname" );

    if ( !isdefined( var_3 ) )
        return;

    var_1 thread update_watertank_fish();
    var_1.destroyexplosiveoncollision = 0;
    var_3 hide();
    self setcandamage( 1 );
    self.tank_damage = 0;
    var_4 = 41.5;
    var_5 = var_1.origin[2] + var_4;
    var_6 = 2.0;
    var_7 = 4.0;
    var_8 = 1.0;
    var_9 = 2.0;

    while ( self.tank_damage < 1200.0 )
    {
        self waittill( "damage", var_10, var_11, var_12, var_13, var_14 );
        self.tank_damage = self.tank_damage + var_10;

        if ( !issubstr( var_14, "BULLET" ) )
            continue;

        if ( !can_allocate_new_tank_crack() )
            continue;

        var_15 = var_1.origin[2] + var_4;

        if ( var_13[2] >= var_15 )
            continue;

        var_16 = get_watertank_hit_angle( var_11, var_12, var_13 );

        if ( !isdefined( var_16 ) )
            continue;

        var_17 = min( var_7 * var_6, var_15 - var_2.origin[2] );
        var_18 = max( var_2.origin[2], max( var_13[2], var_15 - var_17 ) );
        var_19 = var_18 - var_15;
        var_20 = abs( var_19 ) / var_6;
        var_20 = max( var_20, var_8 + var_9 );
        thread spawn_watertank_hit( level._effect["vfx_watertank_bullet_hit"], var_11, var_16, var_13, var_20, var_1, var_4 );

        if ( var_18 >= var_5 )
            continue;

        var_5 = var_18;
        var_1 movez( var_19, var_20, var_8, var_9 );
    }

    self playsound( "water_tank_splash" );
    var_1 notify( "tank_destroyed" );
    wait 0.05;
    var_21 = self getlinkedchildren();

    foreach ( var_23 in var_21 )
        var_23 notify( "detonateExplosive" );

    self delete();
    var_1 delete();
    var_3 show();
    var_3 scriptmodelplayanim( "mp_ca_rumble_glass_anim" );

    if ( var_0 == 0 )
    {
        playfx( level._effect["vfx_glass_shatter_splash"], ( -46.0003, 1409.25, 138.056 ), anglestoforward( ( 0, 0, 0 ) ), anglestoup( ( 0, 0, 0 ) ) );
        playfx( level._effect["vfx_glass_ground_splash"], ( -39.7033, 1414.08, 89 ), anglestoforward( ( 270, 0, 0 ) ), anglestoup( ( 0, 0, 0 ) ) );
    }
    else
    {
        playfx( level._effect["vfx_glass_shatter_splash"], ( -47.9208, 1144.29, 141.575 ), anglestoforward( ( 0, 0, 0 ) ), anglestoup( ( 0, 0, 0 ) ) );
        playfx( level._effect["vfx_glass_ground_splash"], ( -51.5828, 1139.69, 89 ), anglestoforward( ( 270, 0, 0 ) ), anglestoup( ( 0, 0, 0 ) ) );
    }
}

update_watertank_fish()
{
    self endon( "death" );
    wait 2.0;
    var_0 = level._effect["vfx_fish_school"];
    var_1 = spawn( "script_model", self.origin );
    var_1 setmodel( "tag_origin" );
    var_1 linkto( self );
    thread maintain_watertank_fish( var_0, var_1 );
    self waittill( "tank_destroyed" );
    killfxontag( var_0, var_1, "tag_origin" );
    wait 0.05;
    var_1 delete();
}

maintain_watertank_fish( var_0, var_1 )
{
    self endon( "tank_destroyed" );

    for (;;)
    {
        playfxontag( var_0, var_1, "tag_origin" );
        wait 5.0;
        stopfxontag( var_0, var_1, "tag_origin" );
        wait 1.0;
    }
}

spawn_watertank_hit( var_0, var_1, var_2, var_3, var_4, var_5, var_6 )
{
    allocate_new_tank_crack();
    var_7 = spawnfx( var_0, var_3, var_2 );
    triggerfx( var_7 );
    var_7 playsound( "water_tank_hit" );
    var_8 = gettime() + var_4 * 1000.0;
    var_7 monitor_watertank_hit( var_5, var_8, var_6 );
    var_7 stopsounds();
    wait 0.05;
    var_7 delete();
}

monitor_watertank_hit( var_0, var_1, var_2 )
{
    var_0 endon( "tank_destroyed" );

    while ( gettime() < var_1 )
    {
        if ( self.origin[2] >= var_0.origin[2] + var_2 - 1.0 )
            break;

        wait 0.05;
    }
}

update_watertank_invulnerable()
{
    self setcandamage( 1 );

    for (;;)
    {
        self waittill( "damage", var_0, var_1, var_2, var_3, var_4 );

        if ( !issubstr( var_4, "BULLET" ) )
            continue;

        if ( !can_allocate_new_tank_crack() )
            continue;

        var_5 = get_watertank_hit_angle( var_1, var_2, var_3 );

        if ( !isdefined( var_5 ) )
            continue;

        allocate_new_tank_crack();
        var_5 = vectortoangles( var_5 );
        playfx( level._effect["vfx_watertank_bullet_hit"], var_3, anglestoforward( var_5 ), anglestoup( var_5 ) );
        playsoundatpos( var_3, "water_tank_hit" );
    }
}

get_watertank_hit_angle( var_0, var_1, var_2 )
{
    var_3 = var_0.origin;
    var_4 = var_2 - var_3;
    var_5 = bullettrace( var_3, var_3 + 1.5 * var_4, 0, var_0, 0 );

    if ( isdefined( var_5["normal"] ) && isdefined( var_5["entity"] ) && var_5["entity"] == self )
        return var_5["normal"];

    return undefined;
}

can_allocate_new_tank_crack()
{
    if ( gettime() < level.next_tank_hitfx_time )
        return 0;

    return 1;
}

allocate_new_tank_crack()
{
    level.next_tank_hitfx_time = gettime() + randomfloatrange( level.tank_hitfx_throttle, level.tank_hitfx_throttle_max );
}

update_trolley()
{
    common_scripts\utility::waitframe();
    var_0 = getent( "moving_trolley", "targetname" );

    if ( !isdefined( var_0 ) )
        return;

    var_0.destroyairdroponcollision = 1;
    var_0.destroydroneoncollision = 0;
    var_1 = maps\mp\gametypes\_gameobjects::getnextobjid();
    objective_add( var_1, "active", var_0.origin, "waypoint_trolley" );
    objective_onentitywithrotation( var_1, var_0 );
    self.curobjid = var_1;
    var_2 = common_scripts\utility::getstructarray( "trolley_light", "targetname" );
    common_scripts\utility::array_thread( var_2, ::trolley_attach_lights, var_0 );
    var_3 = getent( "moving_trolley_mesh", "targetname" );

    if ( isdefined( var_3 ) )
        var_3 linkto( var_0 );

    var_4 = getentarray( "moving_trolley_extras", "targetname" );

    if ( var_4.size > 0 )
    {
        foreach ( var_6 in var_4 )
            var_6 linkto( var_0 );
    }

    var_8 = getentarray( "moving_trolley_wheel", "targetname" );

    if ( var_8.size <= 0 )
        return;

    var_9 = [];
    var_10 = [];

    for ( var_11 = 0; var_11 < var_8.size; var_11++ )
    {
        var_9[var_11] = var_0.origin - var_8[var_11].origin;
        var_10[var_11] = var_0.angles - var_8[var_11].angles;
    }

    var_12 = getent( "trolley_path_start", "targetname" );

    if ( !isdefined( var_12 ) )
        return;

    var_0.origin = var_12.origin;
    var_0.angles = var_12.angles;

    for ( var_11 = 0; var_11 < var_8.size; var_11++ )
    {
        var_8[var_11].origin = var_12.origin - rotatevector( var_9[var_11], var_12.angles );
        var_8[var_11].angles = var_12.angles + var_10[var_11];
    }

    var_0.enabled = 1;
    var_0 thread monitor_trolley_dvar();
    var_13 = 140.0;
    var_14 = 0.0;
    var_15 = 0.0;

    if ( isdefined( var_12.script_accel ) )
        var_15 = var_12.script_accel;

    var_12 = getent( var_12.target, "targetname" );

    while ( isdefined( var_12 ) )
    {
        if ( !var_0.enabled )
        {
            wait 0.05;
            continue;
        }

        var_14 = 0.0;

        if ( isdefined( var_12.script_decel ) )
            var_14 = var_12.script_decel;

        var_16 = var_13;
        var_16 = var_16 / max( 1, getdvarint( "trolley_throttle", 1 ) );

        if ( isdefined( var_12.script_physics ) )
            var_16 = var_16 * var_12.script_physics;

        var_17 = distance( var_0.origin, var_12.origin ) / var_16;
        var_17 = max( var_17, var_14 + var_15 );
        var_0 moveto( var_12.origin, var_17, var_15, var_14 );
        var_0 rotateto( var_12.angles, var_17, var_15, var_14 );
        var_18 = var_16 * 2.1;

        if ( isdefined( var_12.script_anglevehicle ) && var_12.script_anglevehicle == 1 )
            var_18 = var_18 * -1.0;

        var_19 = var_12.angles[1];

        for ( var_11 = 0; var_11 < var_8.size; var_11++ )
        {
            var_20 = var_12.origin - rotatevector( var_9[var_11], var_12.angles );
            var_8[var_11] moveto( var_20, var_17, var_15, var_14 );
            var_21 = ( var_19 + var_10[var_11][1] - var_8[var_11].angles[1] ) / var_17;
            var_22 = var_18;

            if ( isdefined( var_8[var_11].script_index ) && var_8[var_11].script_index == 1 )
                var_22 = var_22 * -1.0;

            var_8[var_11] rotatevelocity( ( 0, var_21, var_22 ), var_17, var_15, var_14 );
        }

        if ( var_15 > 0.0 )
        {
            var_3 playsoundonmovingent( "trolley_bell" );
            var_3 playsoundonmovingent( "trolley_start" );
            wait( var_15 - 0.2 );
            var_3 playloopsound( "trolley_motor" );
            wait 0.2;
        }

        wait( var_17 - ( var_15 + var_14 ) );

        if ( var_14 > 0.0 )
        {
            var_3 playsoundonmovingent( "trolley_stop" );
            wait 0.2;
            var_3 stoploopsound( "trolley_motor" );
            wait( var_14 - 0.2 );
        }

        if ( isdefined( var_12.script_node_pausetime ) )
            wait( var_12.script_node_pausetime );

        for ( var_11 = 0; var_11 < var_8.size; var_11++ )
            var_8[var_11].angles = ( var_8[var_11].angles[0], var_19 + var_10[var_11][1], var_8[var_11].angles[2] );

        var_15 = 0.0;

        if ( isdefined( var_12.script_accel ) )
            var_15 = var_12.script_accel;

        if ( isdefined( var_12.script_index ) )
            var_3 playsoundonmovingent( "trolley_corner" );

        var_12 = getent( var_12.target, "targetname" );
    }
}

trolley_attach_lights( var_0 )
{
    var_1 = spawn( "script_model", self.origin );
    var_1.angles = self.angles;
    var_1 setmodel( "tag_origin" );
    var_1 linkto( var_0 );

    for (;;)
    {
        playfxontag( level._effect["vfx_pot_lights_trolley"], var_1, "tag_origin" );
        wait( randomfloatrange( 4.0, 6.0 ) );
        stopfxontag( level._effect["vfx_pot_lights_trolley"], var_1, "tag_origin" );
        common_scripts\utility::waitframe();
    }
}

monitor_trolley_dvar()
{
    var_0 = "trolley_toggle";
    var_1 = 0;
    var_2 = "trolley_throttle";
    var_3 = 1;

    for (;;)
    {
        var_4 = getdvarint( var_0, var_1 );

        if ( var_4 == var_1 )
        {
            common_scripts\utility::waitframe();
            continue;
        }

        self.enabled = !self.enabled;
    }
}

update_destroyer()
{
    var_0 = getent( "roaming_destroyer", "targetname" );

    if ( !isdefined( var_0 ) )
        return;

    var_1 = getent( var_0.target, "targetname" );

    if ( !isdefined( var_1 ) )
        return;

    var_0.origin = var_1.origin;
    var_0.angles = var_1.angles;
    var_2 = 500.0;
    var_3 = 0.0;
    var_4 = 0.0;
    var_1 = getent( var_1.target, "targetname" );

    if ( isdefined( var_1.script_decel ) )
        var_4 = var_1.script_decel;

    while ( isdefined( var_1 ) )
    {
        var_5 = var_2;

        if ( isdefined( var_1.script_physics ) )
            var_5 = var_1.script_physics;

        var_3 = 0.0;

        if ( isdefined( var_1.script_accel ) )
            var_3 = var_1.script_accel;

        var_6 = distance( var_0.origin, var_1.origin ) / var_5;
        var_7 = max( var_6, var_3 + var_4 );
        var_0 moveto( var_1.origin, var_7, var_3, var_4 );
        var_0 rotateto( var_1.angles, var_7, var_3, var_4 );
        wait( var_7 );
        var_8 = getent( var_1.target, "targetname" );

        if ( isdefined( var_8 ) )
        {
            if ( isdefined( var_8.script_node_pausetime ) )
                wait( var_8.script_node_pausetime );

            var_4 = 0.0;

            if ( isdefined( var_8.script_decel ) )
                var_4 = var_8.script_decel;
        }

        var_1 = var_8;
    }
}

update_lighthouse_light()
{
    var_0 = getent( "lighthouse_light", "targetname" );

    if ( !isdefined( var_0 ) )
        return;

    if ( !isdefined( var_0.animation ) )
        return;

    var_0 scriptmodelplayanim( "mp_ca_rumble_lighthouse_rotate" );
}

update_artillery_fx()
{
    var_0 = level._effect["vfx_battleship_firing_timing"];
    var_1 = ( 14701.5, -17741.3, 854.587 );
    var_2 = anglestoforward( ( 354.236, 135.865, 13.443 ) );
    var_3 = anglestoup( ( 354.236, 135.865, 13.443 ) );
    var_4 = spawn( "script_model", var_1 );
    var_4 setmodel( "tag_origin" );
    var_5 = "emt_rumb_dist_arty_fire";
    wait( randomfloatrange( 5.0, 20.0 ) );

    for (;;)
    {
        var_6 = 30.0 + randomfloat( 20.0 );
        var_4.origin = var_1 + ( 0, 0, 1000 );
        var_4 moveto( var_4.origin + ( -55000, -60000, 16000 ), lookupsoundlength( var_5 ) * 0.001, 0.2 );
        var_4 playsoundonmovingent( var_5 );
        playfx( var_0, var_1, var_2, var_3 );
        wait( var_6 );
    }
}

update_heli_fx()
{
    var_0 = level._effect["vfx_heli_timing"];
    var_1 = ( 19354.8, -24794.2, 539.564 );
    var_2 = anglestoforward( ( 0, 190, 0 ) );
    var_3 = anglestoup( ( 0, 190, 0 ) );
    var_4 = spawn( "script_model", var_1 );
    var_4 setmodel( "tag_origin" );
    var_5 = "scn_rumb_chopper_by";
    wait( randomfloatrange( 5.0, 20.0 ) );

    for (;;)
    {
        var_6 = 60.0 + randomfloat( 30.0 );
        var_4.origin = var_1 + ( 0, 0, 700 );
        var_4 moveto( var_4.origin + ( -55000, -10000, 3000 ), 40.0, 10.0 );
        var_4 playsoundonmovingent( var_5 );
        playfx( var_0, var_1, var_2, var_3 );
        wait( var_6 );
    }
}

update_flybyjet_fx()
{
    var_0 = level._effect["vfx_jet_flyby_timing"];
    var_1 = ( 22547.9, -308.47, 1440.73 );
    var_2 = anglestoforward( ( 0.855041, 223.034, -0.529352 ) );
    var_3 = anglestoup( ( 0.855041, 223.034, -0.529352 ) );
    var_4 = spawn( "script_model", var_1 );
    var_4 setmodel( "tag_origin" );
    var_5 = "scn_rumb_jets_by";
    wait( randomfloatrange( 5.0, 20.0 ) );

    for (;;)
    {
        var_6 = 90.0 + randomfloat( 30.0 );
        var_4.origin = var_1 + ( 0, 0, 1000 );
        var_4 moveto( var_4.origin + ( -55000, -55000, 0 ), 20.0, 0.6 );
        var_4 playsoundonmovingent( var_5 );
        playfx( var_0, var_1, var_2, var_3 );
        wait( var_6 );
    }
}

setup_fountain_fx()
{
    thread update_fountain_fx( ( 200.517, 631.669, 12 ), 1.1 );
    thread update_fountain_fx( ( -47.933, 575.054, 26 ) );
    thread update_fountain_fx( ( -300.421, 633.173, 8 ), 1.1 );
    wait 1.0;

    for (;;)
    {
        level notify( "spawn_stair_fountain_fx" );
        wait 8.0;
    }
}

update_fountain_fx( var_0, var_1 )
{
    var_2 = level._effect["vfx_water_fountain"];
    var_3 = "emt_rumb_fount_spray";

    for (;;)
    {
        level waittill( "spawn_stair_fountain_fx" );

        if ( isdefined( var_1 ) && var_1 > 0.0 )
            wait( var_1 );

        playfx( var_2, var_0, anglestoforward( ( 0, 0, 0 ) ), anglestoup( ( 0, 0, 0 ) ) );
        playsoundatpos( var_0, var_3 );
        wait 1.1;
        playsoundatpos( var_0 + ( 0, 32, 36 ), var_3 );
        wait 1.1;
        playsoundatpos( var_0 + ( 0, 80, 68 ), var_3 );
        wait 1.1;
        playsoundatpos( var_0 + ( 0, 120, 96 ), var_3 );
    }
}

fixmlgcameraposition()
{
    var_0 = getentarray( "mp_mlg_camera", "classname" );

    if ( isdefined( var_0 ) && var_0.size )
    {
        foreach ( var_2 in var_0 )
        {
            if ( var_2.origin == ( -1064, -224, 272 ) )
            {
                var_2.origin = ( -632, -1712, 368 );
                var_2.angles = ( 10, 113, -1.174 );
                break;
            }
        }
    }
}
