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

main()
{
    self endon( "killanimscript" );
    init_alien_idle();

    for (;;)
    {
        if ( isdefined( self.attractor_flare ) )
        {
            play_attractor_idle();
            continue;
        }

        if ( isdefined( self.enemy_downed ) && self.enemy_downed )
        {
            play_enemy_downed_idle();

            if ( level.gameended )
                self.enemy_downed = 0;

            continue;
        }

        play_idle();
    }
}

init_alien_idle()
{
    self.idle_anim_counter = 0;
    self.consecutive_posture_counter = 0;

    if ( isdefined( self.xyanimscale ) )
        self scragentsetanimscale( self.xyanimscale, 1.0 );

    if ( isdefined( self.idle_state_locked ) && self.idle_state_locked )
        self.statelocked = 1;
}

end_script()
{
    self.previousanimstate = "idle";

    if ( isdefined( self.idle_state_locked ) && self.idle_state_locked )
    {
        self.statelocked = 0;
        self.idle_state_locked = 0;
    }
}

play_enemy_downed_idle()
{
    facetarget();
    self scragentsetorientmode( "face angle abs", self.angles );
    maps\mp\agents\_scriptedagents::playanimuntilnotetrack( "posture", "posture", "end" );
}

play_attractor_idle()
{
    var_0 = vectortoangles( self.attractor_flare.origin - self.origin );
    var_0 = ( self.angles[0], var_0[1], self.angles[2] );
    self scragentsetanimmode( "anim deltas" );
    self scragentsetorientmode( "face angle abs", var_0 );
    var_1 = maps\mp\agents\_scriptedagents::getrandomanimentry( "idle_flare" );
    maps\mp\agents\_scriptedagents::playanimnuntilnotetrack( "idle_flare", var_1, "idle_flare", "end" );
}

play_idle()
{
    facetarget();
    var_0 = selectidleanimstate();
    self scragentsetanimmode( "anim deltas" );
    self scragentsetorientmode( "face angle abs", self.angles );
    maps\mp\agents\_scriptedagents::playanimnuntilnotetrack( var_0, undefined, var_0, "end" );
}

selectidleanimstate()
{
    if ( isdefined( level.dlc_idle_anim_state_override_func ) )
    {
        var_0 = self [[ level.dlc_idle_anim_state_override_func ]]( self.enemy );

        if ( isdefined( var_0 ) )
            return var_0;
    }

    if ( isalive( self.enemy ) )
    {
        if ( common_scripts\utility::cointoss() && self.consecutive_posture_counter < 2 )
        {
            self.consecutive_posture_counter++;
            return "idle_posture";
        }
    }

    self.consecutive_posture_counter = 0;

    if ( self.idle_anim_counter < 2 + randomintrange( 0, 1 ) )
    {
        var_1 = "idle_default";
        self.idle_anim_counter = self.idle_anim_counter + 1;
    }
    else
    {
        var_1 = "idle";
        self.idle_anim_counter = 0;
    }

    return var_1;
}

facetarget()
{
    var_0 = undefined;

    if ( isalive( self.enemy ) && distancesquared( self.enemy.origin, self.origin ) < 2560000 )
        var_0 = self.enemy;
    else if ( isdefined( self.owner ) )
        var_0 = self.owner;

    if ( isdefined( var_0 ) )
        maps\mp\agents\alien\_alien_anim_utils::turntowardsentity( var_0 );
}

ondamage( var_0, var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8, var_9 )
{
    if ( isdefined( level.dlc_can_do_pain_override_func ) )
    {
        var_10 = [[ level.dlc_can_do_pain_override_func ]]( "idle" );

        if ( !var_10 )
            return;
    }

    if ( maps\mp\alien\_utility::is_pain_available( var_1, var_4 ) )
        dopain( var_3, var_7, var_8, var_2, var_4 );
}

dopain( var_0, var_1, var_2, var_3, var_4 )
{
    self endon( "killanimscript" );
    var_5 = var_0 & level.idflags_stun;

    if ( var_4 == "MOD_MELEE" || var_5 )
    {
        var_6 = "pain_pushback";
        var_7 = maps\mp\agents\alien\_alien_anim_utils::getpainanimindex( "push_back", var_1 );
        var_8 = "pain_pushback";
    }
    else
    {
        var_9 = getbasepainanimstate();
        var_6 = maps\mp\agents\alien\_alien_anim_utils::getpainanimstate( var_9, var_3, var_5 );
        var_7 = maps\mp\agents\alien\_alien_anim_utils::getpainanimindex( "idle", var_1, var_2 );
        var_8 = "idle_pain";
    }

    var_10 = self getanimentry( var_6, var_7 );
    maps\mp\alien\_utility::always_play_pain_sound( var_10 );
    maps\mp\alien\_utility::register_pain( var_10 );
    self.statelocked = 1;

    if ( isdefined( self.oriented ) && self.oriented )
        self scragentsetanimmode( "code_move" );
    else
    {
        self scragentsetanimmode( "anim deltas" );
        self scragentsetorientmode( "face angle abs", self.angles );
    }

    maps\mp\agents\_scriptedagents::playanimnuntilnotetrack( var_6, var_7, var_8 );

    if ( !isdefined( self.idle_state_locked ) || !self.idle_state_locked )
        self.statelocked = 0;

    self setanimstate( "idle" );
}

getbasepainanimstate()
{
    if ( isdefined( level.dlc_alien_pain_anim_state_override_func ) )
    {
        var_0 = [[ level.dlc_alien_pain_anim_state_override_func ]]( "idle" );

        if ( isdefined( var_0 ) )
            return var_0;
    }

    return "idle_pain";
}
