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

init_perks()
{
    init_perks_callback();
    init_perks_from_table();
}

init_perks_from_table()
{
    if ( !isdefined( level.alien_perks_table ) )
        level.alien_perks_table = "mp/alien/perks_tree.csv";

    level.alien_perks = [];
    update_perks_from_table( 0, "perk_0" );
    update_perks_from_table( 100, "perk_1" );
}

init_perks_callback()
{
    level.alien_perk_callbacks = [];
    register_perk_callback( "perk_health", maps\mp\alien\_perkfunctions::set_perk_health_level_0, maps\mp\alien\_perkfunctions::unset_perk_health_level_0 );
    register_perk_callback( "perk_health_1", maps\mp\alien\_perkfunctions::set_perk_health_level_1, maps\mp\alien\_perkfunctions::unset_perk_health_level_1 );
    register_perk_callback( "perk_health_2", maps\mp\alien\_perkfunctions::set_perk_health_level_2, maps\mp\alien\_perkfunctions::unset_perk_health_level_2 );
    register_perk_callback( "perk_health_3", maps\mp\alien\_perkfunctions::set_perk_health_level_3, maps\mp\alien\_perkfunctions::unset_perk_health_level_3 );
    register_perk_callback( "perk_health_4", maps\mp\alien\_perkfunctions::set_perk_health_level_4, maps\mp\alien\_perkfunctions::unset_perk_health_level_4 );
    register_perk_callback( "perk_pistol_p226", maps\mp\alien\_perkfunctions::set_perk_pistol_p226_0, maps\mp\alien\_perkfunctions::unset_perk_pistol_p226_0 );
    register_perk_callback( "perk_pistol_p226_1", maps\mp\alien\_perkfunctions::set_perk_pistol_p226_1, maps\mp\alien\_perkfunctions::unset_perk_pistol_p226_1 );
    register_perk_callback( "perk_pistol_p226_2", maps\mp\alien\_perkfunctions::set_perk_pistol_p226_2, maps\mp\alien\_perkfunctions::unset_perk_pistol_p226_2 );
    register_perk_callback( "perk_pistol_p226_3", maps\mp\alien\_perkfunctions::set_perk_pistol_p226_3, maps\mp\alien\_perkfunctions::unset_perk_pistol_p226_3 );
    register_perk_callback( "perk_pistol_p226_4", maps\mp\alien\_perkfunctions::set_perk_pistol_p226_4, maps\mp\alien\_perkfunctions::unset_perk_pistol_p226_4 );
    register_perk_callback( "perk_pistol_magnum", maps\mp\alien\_perkfunctions::set_perk_pistol_magnum_0, maps\mp\alien\_perkfunctions::unset_perk_pistol_magnum_0 );
    register_perk_callback( "perk_pistol_magnum_1", maps\mp\alien\_perkfunctions::set_perk_pistol_magnum_1, maps\mp\alien\_perkfunctions::unset_perk_pistol_magnum_1 );
    register_perk_callback( "perk_pistol_magnum_2", maps\mp\alien\_perkfunctions::set_perk_pistol_magnum_2, maps\mp\alien\_perkfunctions::unset_perk_pistol_magnum_2 );
    register_perk_callback( "perk_pistol_magnum_3", maps\mp\alien\_perkfunctions::set_perk_pistol_magnum_3, maps\mp\alien\_perkfunctions::unset_perk_pistol_magnum_3 );
    register_perk_callback( "perk_pistol_magnum_4", maps\mp\alien\_perkfunctions::set_perk_pistol_magnum_4, maps\mp\alien\_perkfunctions::unset_perk_pistol_magnum_4 );
    register_perk_callback( "perk_pistol_m9a1", maps\mp\alien\_perkfunctions::set_perk_pistol_m9a1_0, maps\mp\alien\_perkfunctions::unset_perk_pistol_m9a1_0 );
    register_perk_callback( "perk_pistol_m9a1_1", maps\mp\alien\_perkfunctions::set_perk_pistol_m9a1_1, maps\mp\alien\_perkfunctions::unset_perk_pistol_m9a1_1 );
    register_perk_callback( "perk_pistol_m9a1_2", maps\mp\alien\_perkfunctions::set_perk_pistol_m9a1_2, maps\mp\alien\_perkfunctions::unset_perk_pistol_m9a1_2 );
    register_perk_callback( "perk_pistol_m9a1_3", maps\mp\alien\_perkfunctions::set_perk_pistol_m9a1_3, maps\mp\alien\_perkfunctions::unset_perk_pistol_m9a1_3 );
    register_perk_callback( "perk_pistol_m9a1_4", maps\mp\alien\_perkfunctions::set_perk_pistol_m9a1_4, maps\mp\alien\_perkfunctions::unset_perk_pistol_m9a1_4 );
    register_perk_callback( "perk_pistol_mp443", maps\mp\alien\_perkfunctions::set_perk_pistol_mp443_0, maps\mp\alien\_perkfunctions::unset_perk_pistol_mp443_0 );
    register_perk_callback( "perk_pistol_mp443_1", maps\mp\alien\_perkfunctions::set_perk_pistol_mp443_1, maps\mp\alien\_perkfunctions::unset_perk_pistol_mp443_1 );
    register_perk_callback( "perk_pistol_mp443_2", maps\mp\alien\_perkfunctions::set_perk_pistol_mp443_2, maps\mp\alien\_perkfunctions::unset_perk_pistol_mp443_2 );
    register_perk_callback( "perk_pistol_mp443_3", maps\mp\alien\_perkfunctions::set_perk_pistol_mp443_3, maps\mp\alien\_perkfunctions::unset_perk_pistol_mp443_3 );
    register_perk_callback( "perk_pistol_mp443_4", maps\mp\alien\_perkfunctions::set_perk_pistol_mp443_4, maps\mp\alien\_perkfunctions::unset_perk_pistol_mp443_4 );
    register_perk_callback( "perk_bullet_damage", maps\mp\alien\_perkfunctions::set_perk_bullet_damage_0, maps\mp\alien\_perkfunctions::unset_perk_bullet_damage_0 );
    register_perk_callback( "perk_bullet_damage_1", maps\mp\alien\_perkfunctions::set_perk_bullet_damage_1, maps\mp\alien\_perkfunctions::unset_perk_bullet_damage_1 );
    register_perk_callback( "perk_bullet_damage_2", maps\mp\alien\_perkfunctions::set_perk_bullet_damage_2, maps\mp\alien\_perkfunctions::unset_perk_bullet_damage_2 );
    register_perk_callback( "perk_bullet_damage_3", maps\mp\alien\_perkfunctions::set_perk_bullet_damage_3, maps\mp\alien\_perkfunctions::unset_perk_bullet_damage_3 );
    register_perk_callback( "perk_bullet_damage_4", maps\mp\alien\_perkfunctions::set_perk_bullet_damage_4, maps\mp\alien\_perkfunctions::unset_perk_bullet_damage_4 );
    register_perk_callback( "perk_medic", maps\mp\alien\_perkfunctions::set_perk_medic_0, maps\mp\alien\_perkfunctions::unset_perk_medic_0 );
    register_perk_callback( "perk_medic_1", maps\mp\alien\_perkfunctions::set_perk_medic_1, maps\mp\alien\_perkfunctions::unset_perk_medic_1 );
    register_perk_callback( "perk_medic_2", maps\mp\alien\_perkfunctions::set_perk_medic_2, maps\mp\alien\_perkfunctions::unset_perk_medic_2 );
    register_perk_callback( "perk_medic_3", maps\mp\alien\_perkfunctions::set_perk_medic_3, maps\mp\alien\_perkfunctions::unset_perk_medic_3 );
    register_perk_callback( "perk_medic_4", maps\mp\alien\_perkfunctions::set_perk_medic_4, maps\mp\alien\_perkfunctions::unset_perk_medic_4 );
    register_perk_callback( "perk_rigger", maps\mp\alien\_perkfunctions::set_perk_rigger_0, maps\mp\alien\_perkfunctions::unset_perk_rigger_0 );
    register_perk_callback( "perk_rigger_1", maps\mp\alien\_perkfunctions::set_perk_rigger_1, maps\mp\alien\_perkfunctions::unset_perk_rigger_1 );
    register_perk_callback( "perk_rigger_2", maps\mp\alien\_perkfunctions::set_perk_rigger_2, maps\mp\alien\_perkfunctions::unset_perk_rigger_2 );
    register_perk_callback( "perk_rigger_3", maps\mp\alien\_perkfunctions::set_perk_rigger_3, maps\mp\alien\_perkfunctions::unset_perk_rigger_3 );
    register_perk_callback( "perk_rigger_4", maps\mp\alien\_perkfunctions::set_perk_rigger_4, maps\mp\alien\_perkfunctions::unset_perk_rigger_4 );
    register_perk_callback( "perk_none", maps\mp\alien\_perkfunctions::set_perk_none, maps\mp\alien\_perkfunctions::unset_perk_none );
    register_perk_callback( "perk_none_1", maps\mp\alien\_perkfunctions::set_perk_none, maps\mp\alien\_perkfunctions::unset_perk_none );
    register_perk_callback( "perk_none_2", maps\mp\alien\_perkfunctions::set_perk_none, maps\mp\alien\_perkfunctions::unset_perk_none );
    register_perk_callback( "perk_none_3", maps\mp\alien\_perkfunctions::set_perk_none, maps\mp\alien\_perkfunctions::unset_perk_none );
    register_perk_callback( "perk_none_4", maps\mp\alien\_perkfunctions::set_perk_none, maps\mp\alien\_perkfunctions::unset_perk_none );
}

register_perk_callback( var_0, var_1, var_2 )
{
    var_3 = spawnstruct();
    var_3.set = var_1;
    var_3.unset = var_2;
    level.alien_perk_callbacks[var_0] = var_3;
}

update_perks_from_table( var_0, var_1 )
{
    level.alien_perks[var_1] = [];

    for ( var_2 = var_0; var_2 <= var_0 + 100; var_2++ )
    {
        var_3 = get_perk_ref_by_index( var_2 );

        if ( var_3 == "" )
            break;

        if ( !isdefined( level.alien_perks[var_3] ) )
        {
            var_4 = spawnstruct();
            var_4.upgrades = [];
            var_4.unlock = get_unlock_by_ref( var_3 );
            var_4.name = get_name_by_ref( var_3 );
            var_4.icon = get_icon_by_ref( var_3 );
            var_4.ref = var_3;
            var_4.type = var_1;
            var_4.callbacks = level.alien_perk_callbacks[var_3];
            var_4.baseidx = var_2;
            level.alien_perks[var_1][var_3] = var_4;
        }

        for ( var_5 = var_2; var_5 <= var_0 + 100; var_5++ )
        {
            var_6 = get_perk_ref_by_index( var_5 );

            if ( var_6 == "" )
                break;

            if ( var_6 == var_3 || is_perk_set( var_3, var_6 ) )
            {
                var_7 = spawnstruct();
                var_7.ref = var_6;
                var_7.desc = get_desc_by_ref( var_6 );
                var_7.point_cost = get_point_cost_by_ref( var_6 );
                level.alien_perks[var_1][var_3].upgrades[var_5 - var_2] = var_7;
                continue;
            }

            break;
        }

        var_2 = var_5 - 1;
    }
}

is_perk_set( var_0, var_1 )
{
    if ( var_0 == var_1 )
        return 0;

    if ( !issubstr( var_1, var_0 ) )
        return 0;

    var_2 = strtok( var_0, "_" );
    var_3 = strtok( var_1, "_" );

    if ( var_3.size - var_2.size != 1 )
        return 0;

    for ( var_4 = 0; var_4 < var_3.size - 1; var_4++ )
    {
        if ( var_3[var_4] != var_2[var_4] )
            return 0;
    }

    return 1;
}

get_perk_ref_by_index( var_0 )
{
    return tablelookup( level.alien_perks_table, 0, var_0, 1 );
}

get_name_by_ref( var_0 )
{
    return tablelookup( level.alien_perks_table, 1, var_0, 4 );
}

get_icon_by_ref( var_0 )
{
    return tablelookup( level.alien_perks_table, 1, var_0, 6 );
}

get_desc_by_ref( var_0 )
{
    return tablelookup( level.alien_perks_table, 1, var_0, 5 );
}

get_point_cost_by_ref( var_0 )
{
    return int( tablelookup( level.alien_perks_table, 1, var_0, 3 ) );
}

get_unlock_by_ref( var_0 )
{
    return int( tablelookup( level.alien_perks_table, 1, var_0, 2 ) );
}

get_is_upgrade_by_ref( var_0 )
{
    return int( tablelookup( level.alien_perks_table, 1, var_0, 7 ) );
}
