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

init()
{
    precachelocationselector( "map_artillery_selector" );
    var_0 = spawnstruct();
    var_0.modelnames = [];
    var_0.modelnames["allies"] = "vehicle_a10_warthog_iw6_mp";
    var_0.modelnames["axis"] = "vehicle_a10_warthog_iw6_mp";
    var_0.vehicle = "a10_warthog_mp";
    var_0.inboundsfx = "veh_mig29_dist_loop";
    var_0.speed = 3000;
    var_0.halfdistance = 12500;
    var_0.heightrange = 750;
    var_0.choosedirection = 1;
    var_0.selectlocationvo = "KS_hqr_airstrike";
    var_0.inboundvo = "KS_ast_inbound";
    var_0.cannonfirevfx = loadfx( "fx/smoke/smoke_trail_white_heli" );
    var_0.cannonrumble = "ac130_25mm_fire";
    var_0.turretname = "a10_30mm_turret_mp";
    var_0.turretattachpoint = "tag_barrel";
    var_0.rocketmodelname = "maverick_projectile_mp";
    var_0.numrockets = 4;
    var_0.delaybetweenrockets = 0.125;
    var_0.delaybetweenlockon = 0.4;
    var_0.lockonicon = "veh_hud_target_chopperfly";
    var_0.maxhealth = 1000;
    var_0.xppopup = "destroyed_a10_strafe";
    var_0.callout = "callout_destroyed_a10";
    var_0.vodestroyed = undefined;
    var_0.explodevfx = loadfx( "fx/explosions/aerial_explosion" );
    var_0.sfxcannonfireloop_1p = "veh_a10_plr_fire_gatling_lp";
    var_0.sfxcannonfirestop_1p = "veh_a10_plr_fire_gatling_cooldown";
    var_0.sfxcannonfireloop_3p = "veh_a10_npc_fire_gatling_lp";
    var_0.sfxcannonfirestop_3p = "veh_a10_npc_fire_gatling_cooldown";
    var_0.sfxcannonfireburptime = 500;
    var_0.sfxcannonfireburpshort_3p = "veh_a10_npc_fire_gatling_short_burst";
    var_0.sfxcannonfireburplong_3p = "veh_a10_npc_fire_gatling_long_burst";
    var_0.sfxcannonbulletimpact = "veh_a10_bullet_impact_lp";
    var_0.sfxmissilefire_1p = [];
    var_0.sfxmissilefire_1p[0] = "veh_a10_plr_missile_ignition_left";
    var_0.sfxmissilefire_1p[1] = "veh_a10_plr_missile_ignition_right";
    var_0.sfxmissilefire_3p = "veh_a10_npc_missile_fire";
    var_0.sfxmissile = "veh_a10_missile_loop";
    var_0.sfxengine_1p = "veh_a10_plr_engine_lp";
    var_0.sfxengine_3p = "veh_a10_dist_loop";
    level.planeconfigs["a10_strafe"] = var_0;
    level.killstreakfuncs["a10_strafe"] = ::onuse;
    buildallflightpathsdefault();
}

onuse( var_0, var_1 )
{
    if ( isdefined( level.a10strafeactive ) )
    {
        self iprintlnbold( &"KILLSTREAKS_AIR_SPACE_TOO_CROWDED" );
        return 0;
    }
    else if ( maps\mp\_utility::isusingremote() || maps\mp\_utility::iskillstreakdenied() )
        return 0;
    else if ( getcsplinecount() < 2 )
        return 0;
    else
    {
        thread dostrike( var_0, "a10_strafe" );
        return 1;
    }
}

dostrike( var_0, var_1 )
{
    self endon( "end_remote" );
    self endon( "death" );
    level endon( "game_ended" );
    var_2 = getpathindex();
    var_3 = startstrafesequence( var_1, var_0 );

    if ( var_3 )
    {
        var_4 = spawnaircraft( var_1, var_0, level.a10splinesin[var_2] );

        if ( isdefined( var_4 ) )
        {
            var_4 dooneflyby();
            switchaircraft( var_4, var_1 );
            var_4 = spawnaircraft( var_1, var_0, level.a10splinesin[var_2] );

            if ( isdefined( var_4 ) )
            {
                thread maps\mp\killstreaks\_killstreaks::clearrideintro( 1.0, 0.75 );
                var_4 dooneflyby();
                var_4 thread endflyby( var_1 );
                endstrafesequence( var_1 );
            }
        }
    }
}

startstrafesequence( var_0, var_1 )
{
    maps\mp\_utility::setusingremote( "a10_strafe" );

    if ( getdvarint( "camera_thirdPerson" ) )
        maps\mp\_utility::setthirdpersondof( 0 );

    self.restoreangles = self.angles;
    maps\mp\_utility::freezecontrolswrapper( 1 );
    var_2 = maps\mp\killstreaks\_killstreaks::initridekillstreak( "a10_strafe" );

    if ( var_2 != "success" )
    {
        if ( var_2 != "disconnect" )
            maps\mp\_utility::clearusingremote();

        if ( isdefined( self.disabledweapon ) && self.disabledweapon )
            common_scripts\utility::_enableweapon();

        self notify( "death" );
        return 0;
    }

    if ( maps\mp\_utility::isjuggernaut() && isdefined( self.juggernautoverlay ) )
        self.juggernautoverlay.alpha = 0;

    maps\mp\_utility::freezecontrolswrapper( 0 );
    level.a10strafeactive = 1;
    self.using_remote_a10 = 1;
    level thread maps\mp\_utility::teamplayercardsplash( "used_" + var_0, self, self.team );
    return 1;
}

endstrafesequence( var_0 )
{
    maps\mp\_utility::clearusingremote();

    if ( getdvarint( "camera_thirdPerson" ) )
        maps\mp\_utility::setthirdpersondof( 1 );

    if ( maps\mp\_utility::isjuggernaut() && isdefined( self.juggernautoverlay ) )
        self.juggernautoverlay.alpha = 1;

    self setplayerangles( self.restoreangles );
    self.restoreangles = undefined;
    thread a10_freezebuffer();
    level.a10strafeactive = undefined;
    self.using_remote_a10 = undefined;
}

switchaircraft( var_0, var_1 )
{
    self.usingremote = undefined;
    self visionsetnakedforplayer( "black_bw", 0.75 );
    thread maps\mp\_utility::set_visionset_for_watching_players( "black_bw", 0.75, 0.75 );
    wait 0.75;

    if ( isdefined( var_0 ) )
        var_0 thread endflyby( var_1 );
}

spawnaircraft( var_0, var_1, var_2 )
{
    var_3 = createplaneasheli( var_0, var_1, var_2 );

    if ( !isdefined( var_3 ) )
        return undefined;

    var_3.streakname = var_0;
    self remotecontrolvehicle( var_3 );
    var_3 setplanesplineid( self, var_2 );
    thread watchintrocleared( var_0, var_3 );
    var_4 = level.planeconfigs[var_0];
    var_3 playloopsound( var_4.sfxengine_1p );
    var_3 thread a10_handledamage();
    maps\mp\killstreaks\_plane::starttrackingplane( var_3 );
    return var_3;
}

attachturret( var_0 )
{
    var_1 = level.planeconfigs[var_0];
    var_2 = self gettagorigin( var_1.turretattachpoint );
    var_3 = spawnturret( "misc_turret", self.origin + var_2, var_1.turretname, 0 );
    var_3 linkto( self, var_1.turretattachpoint, ( 0, 0, 0 ), ( 0, 0, 0 ) );
    var_3 setmodel( "vehicle_ugv_talon_gun_mp" );
    var_3.angles = self.angles;
    var_3.owner = self.owner;
    var_3 maketurretinoperable();
    var_3 setturretmodechangewait( 0 );
    var_3 setmode( "sentry_offline" );
    var_3 makeunusable();
    var_3 setcandamage( 0 );
    var_3 setsentryowner( self.owner );
    self.owner remotecontrolturret( var_3 );
    self.turret = var_3;
}

cleanupaircraft()
{
    if ( isdefined( self.turret ) )
        self.turret delete();

    foreach ( var_1 in self.targetlist )
    {
        if ( isdefined( var_1["icon"] ) )
        {
            var_1["icon"] destroy();
            var_1["icon"] = undefined;
        }
    }

    self delete();
}

getpathindex()
{
    return randomint( level.a10splinesin.size );
}

dooneflyby()
{
    self endon( "death" );
    level endon( "game_ended" );

    for (;;)
    {
        self waittill( "splinePlaneReachedNode", var_0 );

        if ( isdefined( var_0 ) && var_0 == "End" )
        {
            self notify( "a10_end_strafe" );
            break;
        }
    }
}

endflyby( var_0 )
{
    if ( !isdefined( self ) )
        return;

    self.owner remotecontrolvehicleoff( self );

    if ( isdefined( self.turret ) )
        self.owner remotecontrolturretoff( self.turret );

    self notify( "end_remote" );
    self.owner setclientomnvar( "ui_a10", 0 );
    self.owner thermalvisionfofoverlayoff();
    var_1 = level.planeconfigs[var_0];
    self stoploopsound( var_1.sfxcannonfireloop_1p );
    maps\mp\killstreaks\_plane::stoptrackingplane( self );
    wait 5;

    if ( isdefined( self ) )
    {
        self stoploopsound( var_1.sfxengine_1p );
        cleanupaircraft();
    }
}

createplaneasheli( var_0, var_1, var_2 )
{
    var_3 = level.planeconfigs[var_0];
    var_4 = getcsplinepointposition( var_2, 0 );
    var_5 = getcsplinepointtangent( var_2, 0 );
    var_6 = vectortoangles( var_5 );
    var_7 = spawnhelicopter( self, var_4, var_6, var_3.vehicle, var_3.modelnames[self.team] );

    if ( !isdefined( var_7 ) )
        return undefined;

    var_7 makevehiclesolidcapsule( 18, -9, 18 );
    var_7.owner = self;
    var_7.team = self.team;
    var_7.lifeid = var_1;
    var_7 thread maps\mp\killstreaks\_plane::playplanefx();
    return var_7;
}

handledeath()
{
    level endon( "game_ended" );
    self endon( "delete" );
    self waittill( "death" );
    level.a10strafeactive = undefined;
    self.owner.using_remote_a10 = undefined;
    self delete();
}

a10_freezebuffer()
{
    self endon( "disconnect" );
    self endon( "death" );
    level endon( "game_ended" );
    maps\mp\_utility::freezecontrolswrapper( 1 );
    wait 0.5;
    maps\mp\_utility::freezecontrolswrapper( 0 );
}

monitorrocketfire( var_0, var_1 )
{
    var_1 endon( "end_remote" );
    var_1 endon( "death" );
    self endon( "death" );
    level endon( "game_ended" );
    var_2 = level.planeconfigs[var_0];
    var_1.numrocketsleft = var_2.numrockets;
    self notifyonplayercommand( "rocket_fire_pressed", "+speed_throw" );
    self notifyonplayercommand( "rocket_fire_pressed", "+ads_akimbo_accessible" );

    if ( !level.console )
        self notifyonplayercommand( "rocket_fire_pressed", "+toggleads_throw" );

    self setclientomnvar( "ui_a10_rocket", var_1.numrocketsleft );

    while ( var_1.numrocketsleft > 0 )
    {
        self waittill( "rocket_fire_pressed" );
        var_1 onfirerocket( var_0 );
        wait( var_2.delaybetweenrockets );
    }
}

monitorrocketfire2( var_0, var_1 )
{
    var_1 endon( "end_remote" );
    var_1 endon( "death" );
    self endon( "death" );
    level endon( "game_ended" );
    var_2 = level.planeconfigs[var_0];
    var_1.numrocketsleft = var_2.numrockets;
    self notifyonplayercommand( "rocket_fire_pressed", "+speed_throw" );
    self notifyonplayercommand( "rocket_fire_pressed", "+ads_akimbo_accessible" );

    if ( !level.console )
        self notifyonplayercommand( "rocket_fire_pressed", "+toggleads_throw" );

    var_1.targetlist = [];
    self setclientomnvar( "ui_a10_rocket", var_1.numrocketsleft );

    while ( var_1.numrocketsleft > 0 )
    {
        if ( !self adsbuttonpressed() )
            self waittill( "rocket_fire_pressed" );

        var_1 missileacquiretargets();

        if ( var_1.targetlist.size > 0 )
            var_1 thread firemissiles();
    }
}

missilegetbesttarget()
{
    var_0 = [];

    foreach ( var_2 in level.players )
    {
        if ( missileisgoodtarget( var_2 ) )
            var_0[var_0.size] = var_2;
    }

    foreach ( var_5 in level.uplinks )
    {
        if ( missileisgoodtarget( var_5 ) )
            var_0[var_0.size] = var_5;
    }

    if ( var_0.size > 0 )
    {
        var_7 = sortbydistance( var_0, self.origin );
        return var_7[0];
    }

    return undefined;
}

missileisgoodtarget( var_0 )
{
    return isalive( var_0 ) && var_0.team != self.owner.team && !ismissiletargeted( var_0 ) && ( isplayer( var_0 ) && !var_0 maps\mp\_utility::_hasperk( "specialty_blindeye" ) ) && missiletargetangle( var_0 ) > 0.25;
}

missiletargetangle( var_0 )
{
    var_1 = vectornormalize( var_0.origin - self.origin );
    var_2 = anglestoforward( self.angles );
    return vectordot( var_1, var_2 );
}

missileacquiretargets()
{
    self endon( "death" );
    self endon( "end_remote" );
    level endon( "game_ended" );
    self endon( "a10_missiles_fired" );
    var_0 = level.planeconfigs[self.streakname];
    self.owner setclientomnvar( "ui_a10_rocket_lock", 1 );
    thread missilewaitfortriggerrelease();
    var_1 = undefined;

    while ( self.targetlist.size < self.numrocketsleft )
    {
        if ( !isdefined( var_1 ) )
        {
            var_1 = missilegetbesttarget();

            if ( isdefined( var_1 ) )
            {
                thread missilelocktarget( var_1 );
                wait( var_0.delaybetweenlockon );
                var_1 = undefined;
                continue;
            }
        }

        wait 0.1;
    }

    self.owner setclientomnvar( "ui_a10_rocket_lock", 0 );
    self notify( "a10_missiles_fired" );
}

missilewaitfortriggerrelease()
{
    self endon( "end_remote" );
    self endon( "death" );
    level endon( "game_ended" );
    self endon( "a10_missiles_fired" );
    var_0 = self.owner;
    var_0 notifyonplayercommand( "rocket_fire_released", "-speed_throw" );
    var_0 notifyonplayercommand( "rocket_fire_released", "-ads_akimbo_accessible" );

    if ( !level.console )
        var_0 notifyonplayercommand( "rocket_fire_released", "-toggleads_throw" );

    self.owner waittill( "rocket_fire_released" );
    var_0 setclientomnvar( "ui_a10_rocket_lock", 0 );
    self notify( "a10_missiles_fired" );
}

missilelocktarget( var_0 )
{
    var_1 = level.planeconfigs[self.streakname];
    var_2 = [];
    var_2["icon"] = var_0 maps\mp\_entityheadicons::setheadicon( self.owner, var_1.lockonicon, ( 0, 0, -70 ), 10, 10, 0, 0.05, 1, 0, 0, 0 );
    var_2["target"] = var_0;
    self.targetlist[var_0 getentitynumber()] = var_2;
    self.owner playlocalsound( "recondrone_lockon" );
}

ismissiletargeted( var_0 )
{
    return isdefined( self.targetlist[var_0 getentitynumber()] );
}

firemissiles()
{
    self endon( "death" );
    level endon( "game_ended" );
    var_0 = level.planeconfigs[self.streakname];

    foreach ( var_2 in self.targetlist )
    {
        if ( self.numrocketsleft > 0 )
        {
            var_3 = onfirehomingmissile( self.streakname, var_2["target"], ( 0, 0, -70 ) );

            if ( isdefined( var_2["icon"] ) )
            {
                var_3.icon = var_2["icon"];
                var_2["icon"] = undefined;
            }

            wait( var_0.delaybetweenrockets );
            continue;
        }

        break;
    }

    var_5 = [];
}

onfirehomingmissile( var_0, var_1, var_2 )
{
    var_3 = self.numrocketsleft % 2;
    var_4 = "tag_missile_" + ( var_3 + 1 );
    var_5 = self gettagorigin( var_4 );

    if ( isdefined( var_5 ) )
    {
        var_6 = self.owner;
        var_7 = level.planeconfigs[var_0];
        var_8 = magicbullet( var_7.rocketmodelname, var_5, var_5 + 100 * anglestoforward( self.angles ), self.owner );
        var_8 thread a10_missile_set_target( var_1, var_2 );
        earthquake( 0.25, 0.05, self.origin, 512 );
        self.numrocketsleft--;
        self.owner setclientomnvar( "ui_a10_rocket", self.numrocketsleft );
        var_7 = level.planeconfigs[var_0];
        var_8 playsoundonmovingent( var_7.sfxmissilefire_1p[var_3] );
        var_8 playloopsound( var_7.sfxmissile );
        return var_8;
    }

    return undefined;
}

onfirerocket( var_0 )
{
    var_1 = "tag_missile_" + self.numrocketsleft;
    var_2 = self gettagorigin( var_1 );

    if ( isdefined( var_2 ) )
    {
        var_3 = self.owner;
        var_4 = level.planeconfigs[var_0];
        var_5 = magicbullet( var_4.rocketmodelname, var_2, var_2 + 100 * anglestoforward( self.angles ), self.owner );
        earthquake( 0.25, 0.05, self.origin, 512 );
        self.numrocketsleft--;
        self.owner setclientomnvar( "ui_a10_rocket", self.numrocketsleft );
        var_5 playsoundonmovingent( var_4.sfxmissilefire_1p[self.numrocketsleft] );
        var_5 playloopsound( var_4.sfxmissile );
        self playsoundonmovingent( "a10p_missile_launch" );
    }
}

a10_missile_set_target( var_0, var_1 )
{
    thread a10_missile_cleanup();
    wait 0.2;
    self missile_settargetent( var_0, var_1 );
}

a10_missile_cleanup()
{
    self waittill( "death" );

    if ( isdefined( self.icon ) )
        self.icon destroy();
}

monitorweaponfire( var_0, var_1 )
{
    var_1 endon( "end_remote" );
    var_1 endon( "death" );
    self endon( "death" );
    level endon( "game_ended" );
    var_2 = level.planeconfigs[var_0];
    var_1.ammocount = 1350;
    self setclientomnvar( "ui_a10_cannon", var_1.ammocount );
    self notifyonplayercommand( "a10_cannon_start", "+attack" );
    self notifyonplayercommand( "a10_cannon_stop", "-attack" );

    while ( var_1.ammocount > 0 )
    {
        if ( !self attackbuttonpressed() )
            self waittill( "a10_cannon_start" );

        var_3 = gettime() + var_2.sfxcannonfireburptime;
        var_1 playloopsound( var_2.sfxcannonfireloop_1p );
        var_1 thread updatecannonshake( var_0 );
        self waittill( "a10_cannon_stop" );
        var_1 stoploopsound( var_2.sfxcannonfireloop_1p );
        var_1 playsoundonmovingent( var_2.sfxcannonfirestop_1p );

        if ( gettime() < var_3 )
        {
            playsoundatpos( var_1.origin, var_2.sfxcannonfireburpshort_3p );
            continue;
        }

        playsoundatpos( var_1.origin, var_2.sfxcannonfireburplong_3p );
    }
}

updatecannonshake( var_0 )
{
    self.owner endon( "a10_cannon_stop" );
    self endon( "death" );
    level endon( "game_ended" );
    var_1 = level.planeconfigs[var_0];

    while ( self.ammocount > 0 )
    {
        earthquake( 0.2, 0.5, self.origin, 512 );
        self.ammocount = self.ammocount - 10;
        self.owner setclientomnvar( "ui_a10_cannon", self.ammocount );
        var_2 = self gettagorigin( "tag_flash_attach" ) + 20 * anglestoforward( self.angles );
        playfx( var_1.cannonfirevfx, var_2 );
        self playrumbleonentity( var_1.cannonrumble );
        wait 0.1;
    }

    self.turret turretfiredisable();
}

monitoraltitude( var_0, var_1 )
{
    var_1 endon( "end_remote" );
    var_1 endon( "death" );
    self endon( "death" );
    level endon( "game_ended" );
    self setclientomnvar( "ui_a10_alt_warn", 0 );

    for (;;)
    {
        var_2 = int( clamp( var_1.origin[2], 0, 16383 ) );
        self setclientomnvar( "ui_a10_alt", var_2 );

        if ( var_2 <= 1000 && !isdefined( var_1.altwarning ) )
        {
            var_1.altwarning = 1;
            self setclientomnvar( "ui_a10_alt_warn", 1 );
        }
        else if ( var_2 > 1000 && isdefined( var_1.altwarning ) )
        {
            var_1.altwarning = undefined;
            self setclientomnvar( "ui_a10_alt_warn", 0 );
        }

        wait 0.1;
    }
}

watchintrocleared( var_0, var_1 )
{
    self endon( "disconnect" );
    level endon( "game_ended" );
    self waittill( "intro_cleared" );
    self setclientomnvar( "ui_a10", 1 );
    thread monitoraltitude( var_0, var_1 );
    thread monitorrocketfire2( var_0, var_1 );
    thread monitorweaponfire( var_0, var_1 );
    thread watchroundend( var_1, var_0 );
    self thermalvisionfofoverlayon();
    thread watchearlyexit( var_1 );
}

watchroundend( var_0, var_1 )
{
    var_0 endon( "death" );
    var_0 endon( "leaving" );
    self endon( "disconnect" );
    self endon( "joined_team" );
    self endon( "joined_spectators" );
    level common_scripts\utility::waittill_any( "round_end_finished", "game_ended" );
    var_0 thread endflyby( var_1 );
    endstrafesequence( var_1 );
    a10_explode();
}

buildallflightpathsdefault()
{
    var_0 = [];
    var_0[0] = 1;
    var_0[1] = 2;
    var_0[2] = 3;
    var_0[3] = 4;
    var_0[4] = 1;
    var_0[5] = 2;
    var_0[6] = 4;
    var_0[7] = 3;
    var_1 = [];
    var_1[0] = 2;
    var_1[1] = 1;
    var_1[2] = 4;
    var_1[3] = 3;
    var_1[4] = 1;
    var_1[5] = 4;
    var_1[6] = 3;
    var_1[7] = 2;
    buildallflightpaths( var_0, var_1 );
}

buildallflightpaths( var_0, var_1 )
{
    level.a10splinesin = var_0;
    level.a10splinesout = var_1;
}

a10_cockpit_breathing()
{
    level endon( "remove_player_control" );

    for (;;)
        wait( randomfloatrange( 3.0, 7.0 ) );
}

watchearlyexit( var_0 )
{
    level endon( "game_ended" );
    var_0 endon( "death" );
    var_0 endon( "a10_end_strafe" );
    var_0 thread maps\mp\killstreaks\_killstreaks::allowridekillstreakplayerexit();
    var_0 waittill( "killstreakExit" );
    self notify( "end_remote" );
    var_0 thread endflyby( var_0.streakname );
    endstrafesequence( var_0.streakname );
    var_0 a10_explode();
}

a10_handledamage()
{
    self endon( "end_remote" );
    var_0 = level.planeconfigs[self.streakname];
    maps\mp\gametypes\_damage::monitordamage( var_0.maxhealth, "helicopter", ::handledeathdamage, ::modifydamage, 1 );
}

modifydamage( var_0, var_1, var_2, var_3 )
{
    var_4 = var_3;
    var_4 = maps\mp\gametypes\_damage::handleempdamage( var_1, var_2, var_4 );
    var_4 = maps\mp\gametypes\_damage::handlemissiledamage( var_1, var_2, var_4 );
    var_4 = maps\mp\gametypes\_damage::handleapdamage( var_1, var_2, var_4, var_0 );
    return var_4;
}

handledeathdamage( var_0, var_1, var_2, var_3 )
{
    var_4 = level.planeconfigs[self.streakname];
    maps\mp\gametypes\_damage::onkillstreakkilled( var_0, var_1, var_2, var_3, var_4.vodestroyed, var_4.xppopup, var_4.callout );
    a10_explode();
}

a10_explode()
{
    var_0 = level.planeconfigs[self.streakname];
    maps\mp\killstreaks\_plane::stoptrackingplane( self );
    playfx( var_0.explodevfx, self.origin );
    self delete();
}
