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

jump( var_0, var_1, var_2, var_3, var_4, var_5, var_6 )
{
    maps\mp\agents\alien\_alien_anim_utils::turntowardsvector( var_2 - var_0 );
    var_7 = self scragentgetmaxturnspeed();
    thread jumpinternal( var_0, var_1, var_2, var_3, var_4, var_5, var_6 );
    self waittill( "jump_finished" );
    jumpcleanup( var_7, var_3 );
}

jumpcleanup( var_0, var_1 )
{
    self scragentsetanimscale( 1.0, 1.0 );
    self scragentsetmaxturnspeed( var_0 );

    if ( maps\mp\alien\_utility::is_normal_upright( anglestoup( var_1 ) ) )
    {
        self scragentsetphysicsmode( "gravity" );
        self.oriented = 0;
        self.ignoreme = 0;
    }
    else
    {
        self scragentsetphysicsmode( "noclip" );
        self.oriented = 1;
        self.ignoreme = 1;
    }
}

jumpinternal( var_0, var_1, var_2, var_3, var_4, var_5, var_6 )
{
    self endon( "death" );
    self endon( "killanimscript" );
    maps\mp\agents\alien\_alien_anim_utils::turntowardsvector( var_2 - var_0 );

    if ( isdefined( var_6 ) )
        maps\mp\agents\alien\_alien_anim_utils::resetscriptable( var_6, var_2 );

    self.trajectoryactive = 0;
    var_7 = spawnstruct();
    var_8 = getjumpinfo( var_0, var_1, var_2, var_3, var_4 );
    getjumpanimstates( var_8, var_7 );

    if ( isdefined( var_5 ) && isdefined( var_5.fnsetanimstates ) )
        self [[ var_5.fnsetanimstates ]]( var_8, var_7 );

    var_9 = getjumpstartangles( var_0, var_1, var_2 );
    self scragentsetphysicsmode( "noclip" );
    self scragentsetorientmode( "face angle abs", var_9 );
    var_10 = 0;
    var_11 = self getanimentry( var_7.launchanimstate, var_7.launchanimentry );
    var_12 = self getanimentry( var_7.landanimstate, var_7.landanimentry );
    var_13 = getnotetracktimes( var_12, "finish" );

    if ( var_13.size > 0 )
        var_14 = var_13[0] * getanimlength( var_12 );
    else
        var_14 = getanimlength( var_12 );

    var_15 = var_14 / var_7.playbackrate;
    var_16 = floor( var_15 * 20.0 );
    var_17 = var_16 / 20.0 / var_15;
    var_18 = getnotetracktimes( var_12, "stop_teleport" );

    if ( var_18.size > 0 )
    {
        var_19 = var_18[0] * var_15;
        var_20 = ceil( var_19 * 20.0 );
        var_21 = var_20 / 20.0 / var_15;
        var_22 = getmovedelta( var_12, var_21, var_17 );
    }
    else
    {
        var_19 = 0.8 * var_15;
        var_20 = ceil( var_19 * 20.0 );
        var_21 = var_20 / 20.0 / var_15;
        var_22 = getmovedelta( var_12, var_21, var_17 );
    }

    var_3 = getjumpendangles( var_0, var_2, var_3 );
    var_23 = rotatevector( var_22, var_3 );
    var_24 = var_2 - var_23;
    self scragentsetanimmode( "anim deltas" );
    self playsoundonmovingent( get_jump_sfx_alias() );

    if ( animhasnotetrack( var_11, "start_teleport" ) )
        maps\mp\agents\_scriptedagents::playanimnatrateuntilnotetrack( var_7.launchanimstate, var_7.launchanimentry, var_7.playbackrate, "jump_launch", "start_teleport" );
    else
        maps\mp\agents\_scriptedagents::playanimnatratefortime( var_7.launchanimstate, var_7.launchanimentry, var_7.playabackrate, 0.5 * getanimlength( var_11 ) / var_7.playbackrate );

    var_25 = gettime();
    var_10 = self scragentdotrajectory( self.origin, var_24, var_8.jumpspeed2d );
    self.trajectoryactive = 1;
    self endon( "jump_pain_interrupt" );
    thread jumppain( var_10, var_2 );
    self notify( "jump_launching" );
    var_26 = self scragentgetmaxturnspeed();
    thread jumporient( var_8, var_3, var_26, var_10 );
    maps\mp\agents\_scriptedagents::waituntilnotetrack( "jump_launch", "end" );
    var_27 = ( gettime() - var_25 ) / 1000;
    var_28 = var_10 - var_27 - var_19;

    if ( var_28 > 0 )
        maps\mp\agents\_scriptedagents::playanimnatratefortime( var_7.inairanimstate, var_7.inairanimentry, var_7.playbackrate, var_28 );

    if ( isdefined( var_5 ) && isdefined( var_5.fnlandanimstatechoice ) )
        self [[ var_5.fnlandanimstatechoice ]]( var_8, var_7 );

    self setanimstate( var_7.landanimstate, var_7.landanimentry, var_7.playbackrate );
    self waittill( "traverse_complete" );
    self.trajectoryactive = 0;

    if ( isdefined( var_6 ) )
        maps\mp\agents\alien\_alien_anim_utils::playanimonscriptable( var_6, var_2 );

    self scragentsetanimscale( 1.0, 0.0 );
    self scragentsetmaxturnspeed( 20.2832 );
    self scragentsetanimmode( "anim deltas" );
    self scragentsetorientmode( "face angle abs", var_3 );
    thread waitforlandimpact( "jump_land" );
    maps\mp\agents\_scriptedagents::waituntilnotetrack( "jump_land", "end" );
    self scragentsetanimscale( 1.0, 1.0 );
    self setorigin( var_2, 0 );
    self notify( "jump_finished" );
}

waitforlandimpact( var_0 )
{
    var_1 = maps\mp\alien\_utility::get_alien_type();

    switch ( var_1 )
    {
        case "elite":
            maps\mp\agents\_scriptedagents::waituntilnotetrack( var_0, "jump_land_impact" );
            maps\mp\agents\alien\_alien_elite::on_jump_impact();
            break;
        default:
            break;
    }
}

jumporient( var_0, var_1, var_2, var_3 )
{
    self endon( "death" );
    var_4 = ( 0, 0, 1 );
    var_5 = 0.85;
    var_6 = maps\mp\alien\_utility::is_normal_upright( var_0.startupvector );
    var_7 = maps\mp\alien\_utility::is_normal_upright( var_0.endupvector );

    if ( var_6 && !var_7 )
    {
        var_8 = 0.5;
        var_9 = 1.0;
    }
    else if ( !var_6 && var_7 )
    {
        var_8 = 0.0;
        var_9 = 0.5;
    }
    else
    {
        var_8 = 0.0;
        var_9 = 1.0;
    }

    var_10 = var_9 - var_8;

    if ( var_8 > 0 )
        wait( var_3 * var_8 );

    var_11 = 1.0;

    if ( distancesquared( self.angles, var_1 ) > var_11 )
    {
        var_12 = anglesdelta( self.angles, var_1 );
        var_13 = var_12 / ( var_3 * var_10 );
        var_13 = var_13 * 3.14159 / 180.0;
        var_13 = var_13 / 20;
        self scragentsetmaxturnspeed( var_13 );
    }

    self scragentsetorientmode( "face angle abs", var_1 );
}

getjumpinfo( var_0, var_1, var_2, var_3, var_4 )
{
    var_5 = spawnstruct();
    var_6 = var_2 - var_0;
    var_7 = var_6 * ( 1, 1, 0 );
    var_7 = vectornormalize( var_7 );
    var_5.launchorigin = var_0 + var_7 * level.alienanimdata.jumplaunchgrounddelta;
    var_5.landorigin = var_2;
    var_5.jumpvector = var_5.landorigin - var_5.launchorigin;
    var_5.jumpvector2d = var_5.jumpvector * ( 1, 1, 0 );
    var_5.jumpdistance2d = length( var_5.jumpvector2d );
    var_5.jumpdirection2d = var_5.jumpvector2d / var_5.jumpdistance2d;

    if ( isdefined( var_4 ) )
        var_5.landvector = var_4 - var_2;
    else if ( isdefined( self.enemy ) )
        var_5.landvector = self.enemy.origin - var_2;
    else
        var_5.landvector = anglestoforward( self.angles );

    var_5.startangles = getjumpangles( var_5.jumpvector, anglestoup( var_1 ) );
    var_5.endangles = getjumpangles( var_5.jumpvector, anglestoup( var_3 ) );
    var_5.startupvector = anglestoup( var_5.startangles );
    var_5.endupvector = anglestoup( var_5.endangles );
    getjumpvelocity( var_5 );
    return var_5;
}

getjumpangles( var_0, var_1 )
{
    var_2 = maps\mp\agents\alien\_alien_anim_utils::projectvectortoplane( var_0, var_1 );
    var_3 = vectorcross( var_2, var_1 );
    var_4 = axistoangles( var_2, var_3, var_1 );
    return var_4;
}

getjumpvelocity( var_0 )
{
    var_1 = var_0.jumpdistance2d;
    var_2 = var_0.jumpvector[2];
    var_3 = !maps\mp\alien\_utility::is_normal_upright( var_0.endupvector );
    var_4 = getjumpgravity( var_3 );
    var_5 = 1.01;
    var_6 = trajectorycalculateminimumvelocity( var_0.launchorigin, var_0.landorigin, var_4 );
    var_7 = getjumpspeedmultiplier( var_3 );
    var_8 = var_6 * var_5 * var_7;
    var_9 = trajectorycalculateexitangle( var_8, var_4, var_1, var_2 );
    var_10 = cos( var_9 );
    var_0.jumptime = var_0.jumpdistance2d / ( var_8 * var_10 );
    var_11 = var_4 * ( 0, 0, -1 );
    var_0.launchvelocity = trajectorycalculateinitialvelocity( var_0.launchorigin, var_0.landorigin, var_11, var_0.jumptime );
    var_0.launchvelocity2d = var_0.launchvelocity * ( 1, 1, 0 );
    var_0.jumpspeed2d = length( var_0.launchvelocity2d );
}

getjumpspeedmultiplier( var_0 )
{
    if ( isdefined( self.melee_jumping ) && self.melee_jumping )
        return level.alien_jump_melee_speed;
    else if ( var_0 )
        return getdvarfloat( "agent_jumpWallSpeed" );
    else
        return getdvarfloat( "agent_jumpSpeed" );
}

getjumpgravity( var_0 )
{
    if ( isdefined( self.melee_jumping ) && self.melee_jumping )
        return level.alien_jump_melee_gravity;
    else if ( var_0 )
        return getdvarfloat( "agent_jumpWallGravity" );
    else
        return getdvarfloat( "agent_jumpGravity" );
}

getjumpplaybackrate( var_0, var_1 )
{
    var_2 = self getanimentry( var_1.launchanimstate, var_1.launchanimentry );
    var_3 = self getanimentry( var_1.inairanimstate, var_1.inairanimentry );
    var_4 = self getanimentry( var_1.landanimstate, var_1.landanimentry );
    var_5 = getanimlength( var_2 );
    var_6 = var_5 * 0.5;
    var_7 = getnotetracktimes( var_2, "start_teleport" );

    if ( isdefined( var_7 ) && var_7.size > 0 )
        var_6 = var_5 - var_7[0] * var_5;

    var_8 = getanimlength( var_4 );
    var_9 = var_8 * 0.5;
    var_10 = getnotetracktimes( var_4, "stop_teleport" );

    if ( isdefined( var_10 ) && var_10.size > 0 )
        var_9 = var_10[0] * var_8;

    var_11 = getanimlength( var_3 );
    var_12 = ceil( var_0.jumptime * 20.0 );
    var_13 = var_12 / 20.0;
    var_14 = var_11 + var_6 + var_9;
    var_15 = var_14 / var_13;
    var_16 = var_11 / var_15 + 0.1;
    var_17 = var_11 / var_16;
    return var_17;
}

getjumpanimstates( var_0, var_1 )
{
    var_1.launchanimstate = getlaunchanimstate( var_0 );
    var_1.launchanimentry = getlaunchanimentry( var_0, var_1.launchanimstate );
    var_1.landanimstate = getlandanimstate( var_0 );
    var_1.landanimentry = getlandanimentry( var_0, var_1.landanimstate );
    var_1.inairanimstate = getinairanimstate( var_0, var_1.launchanimstate, var_1.landanimstate );
    var_1.inairanimentry = getinairanimentry( var_0, var_1.launchanimstate, var_1.landanimstate );
    var_1.playbackrate = getjumpplaybackrate( var_0, var_1 );
}

getjumpstartangles( var_0, var_1, var_2 )
{
    var_3 = anglestoup( var_1 );
    var_4 = vectornormalize( var_2 - var_0 );

    if ( vectordot( var_3, var_4 ) > 0.98 )
        var_4 = ( 0, 0, 1 );

    var_5 = vectorcross( var_3, var_4 );
    var_4 = vectorcross( var_5, var_3 );
    return axistoangles( var_4, -1 * var_5, var_3 );
}

getlaunchanimstate( var_0 )
{
    var_1 = 20;
    var_2 = cos( 90 - var_1 );
    var_3 = vectornormalize( var_0.jumpvector );
    var_4 = vectordot( var_3, var_0.startupvector );

    if ( abs( var_4 ) <= var_2 )
        return "jump_launch_level";
    else if ( var_4 > 0 )
        return "jump_launch_up";
    else if ( var_4 < 0 )
        return "jump_launch_down";
}

getlaunchanimentry( var_0, var_1 )
{
    var_2 = vectornormalize( var_0.launchvelocity );
    var_2 = rotatevector( var_2, var_0.startangles );
    var_3 = self getanimentrycount( var_1 );
    var_4 = 0;
    var_5 = vectordot( level.alienanimdata.jumplaunchdirection[var_1][var_4], var_2 );

    for ( var_6 = 1; var_6 < var_3; var_6++ )
    {
        var_7 = vectordot( level.alienanimdata.jumplaunchdirection[var_1][var_6], var_2 );

        if ( var_7 > var_5 )
        {
            var_4 = var_6;
            var_5 = var_7;
        }
    }

    return var_4;
}

getinairanimstate( var_0, var_1, var_2 )
{
    return "jump_in_air";
}

getinairanimentry( var_0, var_1, var_2 )
{
    return level.alienanimdata.inairanimentry[var_1][var_2];
}

getjumpendangles( var_0, var_1, var_2 )
{
    var_3 = anglestoup( var_2 );
    var_4 = vectornormalize( var_1 - var_0 );

    if ( vectordot( var_3, var_4 ) > 0.98 )
        var_4 = ( 0, 0, 1 );

    var_5 = vectorcross( var_3, var_4 );
    var_4 = vectorcross( var_5, var_3 );
    return axistoangles( var_4, -1 * var_5, var_3 );
}

getlandanimstate( var_0 )
{
    var_1 = length( var_0.jumpvector );
    var_2 = 0.342;

    if ( !maps\mp\alien\_utility::is_normal_upright( var_0.endupvector ) )
    {
        var_3 = ( 0, 0, 1 );
        var_4 = vectordot( var_0.jumpvector, var_3 ) / var_1;

        if ( var_4 > var_2 )
            return "jump_land_sidewall_low";
        else
            return "jump_land_sidewall_high";
    }

    var_4 = vectordot( var_0.jumpvector, var_0.endupvector ) / var_1;

    if ( var_4 > var_2 )
        return "jump_land_down";
    else if ( var_4 < var_2 * -1 )
        return "jump_land_up";
    else
        return "jump_land_level";
}

getlandanimentry( var_0, var_1 )
{
    var_2 = maps\mp\agents\alien\_alien_anim_utils::projectvectortoplane( var_0.jumpvector, var_0.endupvector );
    var_3 = maps\mp\agents\alien\_alien_anim_utils::projectvectortoplane( var_0.landvector, var_0.endupvector );
    var_4 = var_2 - var_3;
    var_5 = vectorcross( var_3, var_0.endupvector );
    var_6 = vectornormalize( maps\mp\agents\alien\_alien_anim_utils::projectvectortoplane( var_5, var_0.endupvector ) ) * 100;
    var_7 = vectordot( var_2 * -1, var_6 );
    var_8 = length( var_2 );
    var_9 = length( var_3 );
    var_10 = length( var_4 );
    var_11 = 0.001;

    if ( var_8 < var_11 || var_9 < var_11 )
        return 1;

    var_12 = ( var_8 * var_8 + var_9 * var_9 - var_10 * var_10 ) / ( 2 * var_8 * var_9 );

    if ( var_12 <= -1 )
        return 6;
    else if ( var_12 >= 1 )
        return 1;
    else
    {
        var_13 = acos( var_12 );

        if ( var_7 > 0 )
        {
            if ( 0 <= var_13 && var_13 < 22.5 )
                return 1;
            else if ( 22.5 <= var_13 && var_13 < 67.5 )
                return 2;
            else if ( 67.5 <= var_13 && var_13 < 112.5 )
                return 4;
            else if ( 112.5 <= var_13 && var_13 < 157.5 )
                return 7;
            else
                return 6;
        }
        else if ( 0 <= var_13 && var_13 < 22.5 )
            return 1;
        else if ( 22.5 <= var_13 && var_13 < 67.5 )
            return 0;
        else if ( 67.5 <= var_13 && var_13 < 112.5 )
            return 3;
        else if ( 112.5 <= var_13 && var_13 < 157.5 )
            return 5;
        else
            return 6;
    }
}

jumppain( var_0, var_1 )
{
    self endon( "death" );
    self endon( "killanimscript" );
    self endon( "jump_finished" );
    var_2 = gettime();
    var_3 = var_0 * 1000;
    self waittill( "jump_pain", var_4, var_5, var_6, var_7 );

    if ( !self.trajectoryactive )
        return;

    self notify( "jump_pain_interrupt" );
    var_8 = maps\mp\agents\alien\_alien_anim_utils::getpainanimstate( "jump_pain", var_6, var_7 );
    var_9 = maps\mp\agents\alien\_alien_anim_utils::getpainanimindex( "jump", var_4, var_5 );
    var_10 = maps\mp\agents\alien\_alien_anim_utils::getdamagedegree( var_6, var_7 );
    var_11 = var_2 * 0.001 + var_0;
    playinairjumppainanims( var_8, var_9, var_11, var_10 );
    self scragentsetanimscale( 1.0, 0.0 );
    self scragentsetanimmode( "anim deltas" );
    self scragentsetorientmode( "face angle abs", self.angles );
    var_12 = getimpactpainanimstate( var_10 );
    var_13 = maps\mp\agents\alien\_alien_anim_utils::getimpactpainanimindex( var_9 );
    self setanimstate( var_12, var_13, 1.0 );
    maps\mp\agents\_scriptedagents::waituntilnotetrack( var_12, "code_move" );
    self notify( "jump_finished" );
}

playinairjumppainanims( var_0, var_1, var_2, var_3 )
{
    self endon( "death" );
    self endon( "killanimscript" );
    self endon( "jump_finished" );
    self setanimstate( var_0, var_1, 1.0 );
    var_4 = common_scripts\utility::waittill_any_return( "jump_pain", "traverse_complete" );

    if ( var_4 == "traverse_complete" )
        return;

    var_5 = var_2 - gettime() * 0.001;

    if ( var_5 > 0 )
    {
        var_6 = 2.0;
        var_7 = getjumppainidleanimstate( var_3 );
        var_8 = self getanimentry( var_7, var_1 );
        var_9 = getanimlength( var_8 );
        var_10 = min( var_6, var_9 / var_5 );
        self setanimstate( var_7, var_1, var_10 );
    }

    self waittill( "traverse_complete" );
}

getjumppainidleanimstate( var_0 )
{
    return "jump_pain_idle_" + var_0;
}

getimpactpainanimstate( var_0 )
{
    return "jump_impact_pain_" + var_0;
}

get_jump_sfx_alias()
{
    switch ( maps\mp\alien\_utility::get_alien_type() )
    {
        case "elite":
            return "null";
        case "spitter":
            return "spitter_jump";
        case "seeder":
            return "seed_jump";
        case "gargoyle":
            return "gg_jump";
        default:
            return "alien_jump";
    }
}
